| 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 | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 4 | * Copyright (C) 2004-2008 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> |
| 27 | #include <linux/kthread.h> |
| 28 | #include <linux/pci.h> |
| 29 | #include <linux/spinlock.h> |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 30 | #include <linux/ctype.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 31 | |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 32 | #include <scsi/scsi.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | #include <scsi/scsi_device.h> |
| 34 | #include <scsi/scsi_host.h> |
| 35 | #include <scsi/scsi_transport_fc.h> |
| 36 | |
| 37 | #include "lpfc_hw.h" |
| 38 | #include "lpfc_sli.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 39 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 40 | #include "lpfc_disc.h" |
| 41 | #include "lpfc_scsi.h" |
| 42 | #include "lpfc.h" |
| 43 | #include "lpfc_logmsg.h" |
| 44 | #include "lpfc_crtn.h" |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 45 | #include "lpfc_vport.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 46 | #include "lpfc_version.h" |
| 47 | |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 48 | static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 49 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
| 50 | static int lpfc_post_rcv_buf(struct lpfc_hba *); |
| 51 | |
| 52 | static struct scsi_transport_template *lpfc_transport_template = NULL; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 53 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 54 | static DEFINE_IDR(lpfc_hba_index); |
| 55 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 56 | /** |
| 57 | * lpfc_config_port_prep: Perform lpfc initialization prior to config port. |
| 58 | * @phba: pointer to lpfc hba data structure. |
| 59 | * |
| 60 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT |
| 61 | * mailbox command. It retrieves the revision information from the HBA and |
| 62 | * collects the Vital Product Data (VPD) about the HBA for preparing the |
| 63 | * configuration of the HBA. |
| 64 | * |
| 65 | * Return codes: |
| 66 | * 0 - success. |
| 67 | * -ERESTART - requests the SLI layer to reset the HBA and try again. |
| 68 | * Any other value - indicates an error. |
| 69 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 70 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 71 | lpfc_config_port_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 72 | { |
| 73 | lpfc_vpd_t *vp = &phba->vpd; |
| 74 | int i = 0, rc; |
| 75 | LPFC_MBOXQ_t *pmb; |
| 76 | MAILBOX_t *mb; |
| 77 | char *lpfc_vpd_data = NULL; |
| 78 | uint16_t offset = 0; |
| 79 | static char licensed[56] = |
| 80 | "key unlock for use with gnu public licensed code only\0"; |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 81 | static int init_key = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 82 | |
| 83 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 84 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 85 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 86 | return -ENOMEM; |
| 87 | } |
| 88 | |
| 89 | mb = &pmb->mb; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 90 | phba->link_state = LPFC_INIT_MBX_CMDS; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 91 | |
| 92 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 93 | if (init_key) { |
| 94 | uint32_t *ptext = (uint32_t *) licensed; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 95 | |
James Smart | 65a29c1 | 2006-07-06 15:50:50 -0400 | [diff] [blame] | 96 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
| 97 | *ptext = cpu_to_be32(*ptext); |
| 98 | init_key = 0; |
| 99 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 100 | |
| 101 | lpfc_read_nv(phba, pmb); |
| 102 | memset((char*)mb->un.varRDnvp.rsvd3, 0, |
| 103 | sizeof (mb->un.varRDnvp.rsvd3)); |
| 104 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, |
| 105 | sizeof (licensed)); |
| 106 | |
| 107 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 108 | |
| 109 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 110 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 111 | "0324 Config Port initialization " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 112 | "error, mbxCmd x%x READ_NVPARM, " |
| 113 | "mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 114 | mb->mbxCommand, mb->mbxStatus); |
| 115 | mempool_free(pmb, phba->mbox_mem_pool); |
| 116 | return -ERESTART; |
| 117 | } |
| 118 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 119 | sizeof(phba->wwnn)); |
| 120 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, |
| 121 | sizeof(phba->wwpn)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 122 | } |
| 123 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 124 | phba->sli3_options = 0x0; |
| 125 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 126 | /* Setup and issue mailbox READ REV command */ |
| 127 | lpfc_read_rev(phba, pmb); |
| 128 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 129 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 130 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 131 | "0439 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 132 | "READ_REV, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 133 | mb->mbxCommand, mb->mbxStatus); |
| 134 | mempool_free( pmb, phba->mbox_mem_pool); |
| 135 | return -ERESTART; |
| 136 | } |
| 137 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 138 | |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 139 | /* |
| 140 | * The value of rr must be 1 since the driver set the cv field to 1. |
| 141 | * This setting requires the FW to set all revision fields. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 142 | */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 143 | if (mb->un.varRdRev.rr == 0) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 144 | vp->rev.rBit = 0; |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 145 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 146 | "0440 Adapter failed to init, READ_REV has " |
| 147 | "missing revision information.\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 148 | mempool_free(pmb, phba->mbox_mem_pool); |
| 149 | return -ERESTART; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 150 | } |
| 151 | |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 152 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
| 153 | mempool_free(pmb, phba->mbox_mem_pool); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 154 | return -EINVAL; |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 155 | } |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 156 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 157 | /* Save information as VPD data */ |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 158 | vp->rev.rBit = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 159 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
James.Smart@Emulex.Com | 1de933f | 2005-11-28 11:41:15 -0500 | [diff] [blame] | 160 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
| 161 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); |
| 162 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; |
| 163 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 164 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
| 165 | vp->rev.smRev = mb->un.varRdRev.smRev; |
| 166 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; |
| 167 | vp->rev.endecRev = mb->un.varRdRev.endecRev; |
| 168 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; |
| 169 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; |
| 170 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; |
| 171 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; |
| 172 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; |
| 173 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; |
| 174 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 175 | /* If the sli feature level is less then 9, we must |
| 176 | * tear down all RPIs and VPIs on link down if NPIV |
| 177 | * is enabled. |
| 178 | */ |
| 179 | if (vp->rev.feaLevelHigh < 9) |
| 180 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; |
| 181 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 182 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
| 183 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], |
| 184 | sizeof (phba->RandomData)); |
| 185 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 186 | /* Get adapter VPD information */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 187 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
| 188 | if (!lpfc_vpd_data) |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 189 | goto out_free_mbox; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 190 | |
| 191 | do { |
| 192 | lpfc_dump_mem(phba, pmb, offset); |
| 193 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 194 | |
| 195 | if (rc != MBX_SUCCESS) { |
| 196 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 197 | "0441 VPD not present on adapter, " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 198 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 199 | mb->mbxCommand, mb->mbxStatus); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 200 | mb->un.varDmp.word_cnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 201 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 202 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
| 203 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 204 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
| 205 | lpfc_vpd_data + offset, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 206 | mb->un.varDmp.word_cnt); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 207 | offset += mb->un.varDmp.word_cnt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 208 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
| 209 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 210 | |
| 211 | kfree(lpfc_vpd_data); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 212 | out_free_mbox: |
| 213 | mempool_free(pmb, phba->mbox_mem_pool); |
| 214 | return 0; |
| 215 | } |
| 216 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 217 | /** |
| 218 | * lpfc_config_async_cmpl: Completion handler for config async event mbox cmd. |
| 219 | * @phba: pointer to lpfc hba data structure. |
| 220 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 221 | * |
| 222 | * This is the completion handler for driver's configuring asynchronous event |
| 223 | * mailbox command to the device. If the mailbox command returns successfully, |
| 224 | * it will set internal async event support flag to 1; otherwise, it will |
| 225 | * set internal async event support flag to 0. |
| 226 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 227 | static void |
| 228 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 229 | { |
| 230 | if (pmboxq->mb.mbxStatus == MBX_SUCCESS) |
| 231 | phba->temp_sensor_support = 1; |
| 232 | else |
| 233 | phba->temp_sensor_support = 0; |
| 234 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 235 | return; |
| 236 | } |
| 237 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 238 | /** |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame^] | 239 | * lpfc_dump_wakeup_param_cmpl: Completion handler for dump memory mailbox |
| 240 | * command used for getting wake up parameters. |
| 241 | * @phba: pointer to lpfc hba data structure. |
| 242 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 243 | * |
| 244 | * This is the completion handler for dump mailbox command for getting |
| 245 | * wake up parameters. When this command complete, the response contain |
| 246 | * Option rom version of the HBA. This function translate the version number |
| 247 | * into a human readable string and store it in OptionROMVersion. |
| 248 | **/ |
| 249 | static void |
| 250 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) |
| 251 | { |
| 252 | struct prog_id *prg; |
| 253 | uint32_t prog_id_word; |
| 254 | char dist = ' '; |
| 255 | /* character array used for decoding dist type. */ |
| 256 | char dist_char[] = "nabx"; |
| 257 | |
| 258 | if (pmboxq->mb.mbxStatus != MBX_SUCCESS) |
| 259 | return; |
| 260 | |
| 261 | prg = (struct prog_id *) &prog_id_word; |
| 262 | |
| 263 | /* word 7 contain option rom version */ |
| 264 | prog_id_word = pmboxq->mb.un.varWords[7]; |
| 265 | |
| 266 | /* Decode the Option rom version word to a readable string */ |
| 267 | if (prg->dist < 4) |
| 268 | dist = dist_char[prg->dist]; |
| 269 | |
| 270 | if ((prg->dist == 3) && (prg->num == 0)) |
| 271 | sprintf(phba->OptionROMVersion, "%d.%d%d", |
| 272 | prg->ver, prg->rev, prg->lev); |
| 273 | else |
| 274 | sprintf(phba->OptionROMVersion, "%d.%d%d%c%d", |
| 275 | prg->ver, prg->rev, prg->lev, |
| 276 | dist, prg->num); |
| 277 | return; |
| 278 | } |
| 279 | |
| 280 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 281 | * lpfc_config_port_post: Perform lpfc initialization after config port. |
| 282 | * @phba: pointer to lpfc hba data structure. |
| 283 | * |
| 284 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox |
| 285 | * command call. It performs all internal resource and state setups on the |
| 286 | * port: post IOCB buffers, enable appropriate host interrupt attentions, |
| 287 | * ELS ring timers, etc. |
| 288 | * |
| 289 | * Return codes |
| 290 | * 0 - success. |
| 291 | * Any other value - error. |
| 292 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 293 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 294 | lpfc_config_port_post(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 295 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 296 | struct lpfc_vport *vport = phba->pport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 297 | LPFC_MBOXQ_t *pmb; |
| 298 | MAILBOX_t *mb; |
| 299 | struct lpfc_dmabuf *mp; |
| 300 | struct lpfc_sli *psli = &phba->sli; |
| 301 | uint32_t status, timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 302 | int i, j; |
| 303 | int rc; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 304 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 305 | spin_lock_irq(&phba->hbalock); |
| 306 | /* |
| 307 | * If the Config port completed correctly the HBA is not |
| 308 | * over heated any more. |
| 309 | */ |
| 310 | if (phba->over_temp_state == HBA_OVER_TEMP) |
| 311 | phba->over_temp_state = HBA_NORMAL_TEMP; |
| 312 | spin_unlock_irq(&phba->hbalock); |
| 313 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 314 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 315 | if (!pmb) { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 316 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 317 | return -ENOMEM; |
| 318 | } |
| 319 | mb = &pmb->mb; |
| 320 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 321 | /* Get login parameters for NID. */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 322 | lpfc_read_sparam(phba, pmb, 0); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 323 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 324 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 325 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 326 | "0448 Adapter failed init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 327 | "READ_SPARM mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 328 | mb->mbxCommand, mb->mbxStatus); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 329 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 330 | mp = (struct lpfc_dmabuf *) pmb->context1; |
| 331 | mempool_free( pmb, phba->mbox_mem_pool); |
| 332 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 333 | kfree(mp); |
| 334 | return -EIO; |
| 335 | } |
| 336 | |
| 337 | mp = (struct lpfc_dmabuf *) pmb->context1; |
| 338 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 339 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 340 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 341 | kfree(mp); |
| 342 | pmb->context1 = NULL; |
| 343 | |
James Smart | a12e07b | 2006-12-02 13:35:30 -0500 | [diff] [blame] | 344 | if (phba->cfg_soft_wwnn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 345 | u64_to_wwn(phba->cfg_soft_wwnn, |
| 346 | vport->fc_sparam.nodeName.u.wwn); |
James Smart | c3f28af | 2006-08-18 17:47:18 -0400 | [diff] [blame] | 347 | if (phba->cfg_soft_wwpn) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 348 | u64_to_wwn(phba->cfg_soft_wwpn, |
| 349 | vport->fc_sparam.portName.u.wwn); |
| 350 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 351 | sizeof (struct lpfc_name)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 352 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 353 | sizeof (struct lpfc_name)); |
| 354 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
| 355 | /* This should be consolidated into parse_vpd ? - mr */ |
| 356 | if (phba->SerialNumber[0] == 0) { |
| 357 | uint8_t *outptr; |
| 358 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 359 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 360 | for (i = 0; i < 12; i++) { |
| 361 | status = *outptr++; |
| 362 | j = ((status & 0xf0) >> 4); |
| 363 | if (j <= 9) |
| 364 | phba->SerialNumber[i] = |
| 365 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 366 | else |
| 367 | phba->SerialNumber[i] = |
| 368 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 369 | i++; |
| 370 | j = (status & 0xf); |
| 371 | if (j <= 9) |
| 372 | phba->SerialNumber[i] = |
| 373 | (char)((uint8_t) 0x30 + (uint8_t) j); |
| 374 | else |
| 375 | phba->SerialNumber[i] = |
| 376 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); |
| 377 | } |
| 378 | } |
| 379 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 380 | lpfc_read_config(phba, pmb); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 381 | pmb->vport = vport; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 382 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 383 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 384 | "0453 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 385 | "READ_CONFIG, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 386 | mb->mbxCommand, mb->mbxStatus); |
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 | mempool_free( pmb, phba->mbox_mem_pool); |
| 389 | return -EIO; |
| 390 | } |
| 391 | |
| 392 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
| 393 | if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1)) |
| 394 | phba->cfg_hba_queue_depth = |
| 395 | mb->un.varRdConfig.max_xri + 1; |
| 396 | |
| 397 | phba->lmt = mb->un.varRdConfig.lmt; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 398 | |
| 399 | /* Get the default values for Model Name and Description */ |
| 400 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); |
| 401 | |
| 402 | if ((phba->cfg_link_speed > LINK_SPEED_10G) |
| 403 | || ((phba->cfg_link_speed == LINK_SPEED_1G) |
| 404 | && !(phba->lmt & LMT_1Gb)) |
| 405 | || ((phba->cfg_link_speed == LINK_SPEED_2G) |
| 406 | && !(phba->lmt & LMT_2Gb)) |
| 407 | || ((phba->cfg_link_speed == LINK_SPEED_4G) |
| 408 | && !(phba->lmt & LMT_4Gb)) |
| 409 | || ((phba->cfg_link_speed == LINK_SPEED_8G) |
| 410 | && !(phba->lmt & LMT_8Gb)) |
| 411 | || ((phba->cfg_link_speed == LINK_SPEED_10G) |
| 412 | && !(phba->lmt & LMT_10Gb))) { |
| 413 | /* Reset link speed to auto */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 414 | lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 415 | "1302 Invalid speed for this board: " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 416 | "Reset link speed to auto: x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 417 | phba->cfg_link_speed); |
| 418 | phba->cfg_link_speed = LINK_SPEED_AUTO; |
| 419 | } |
| 420 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 421 | phba->link_state = LPFC_LINK_DOWN; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 422 | |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 423 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
James Smart | a4bc337 | 2006-12-02 13:34:16 -0500 | [diff] [blame] | 424 | if (psli->ring[psli->extra_ring].cmdringaddr) |
| 425 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 426 | if (psli->ring[psli->fcp_ring].cmdringaddr) |
| 427 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| 428 | if (psli->ring[psli->next_ring].cmdringaddr) |
| 429 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; |
| 430 | |
| 431 | /* Post receive buffers for desired rings */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 432 | if (phba->sli_rev != 3) |
| 433 | lpfc_post_rcv_buf(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 434 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 435 | /* |
| 436 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode |
| 437 | */ |
| 438 | if (phba->intr_type == MSIX) { |
| 439 | rc = lpfc_config_msi(phba, pmb); |
| 440 | if (rc) { |
| 441 | mempool_free(pmb, phba->mbox_mem_pool); |
| 442 | return -EIO; |
| 443 | } |
| 444 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 445 | if (rc != MBX_SUCCESS) { |
| 446 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 447 | "0352 Config MSI mailbox command " |
| 448 | "failed, mbxCmd x%x, mbxStatus x%x\n", |
| 449 | pmb->mb.mbxCommand, pmb->mb.mbxStatus); |
| 450 | mempool_free(pmb, phba->mbox_mem_pool); |
| 451 | return -EIO; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | /* Initialize ERATT handling flag */ |
| 456 | phba->hba_flag &= ~HBA_ERATT_HANDLED; |
| 457 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 458 | /* Enable appropriate host interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 459 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 460 | status = readl(phba->HCregaddr); |
| 461 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
| 462 | if (psli->num_rings > 0) |
| 463 | status |= HC_R0INT_ENA; |
| 464 | if (psli->num_rings > 1) |
| 465 | status |= HC_R1INT_ENA; |
| 466 | if (psli->num_rings > 2) |
| 467 | status |= HC_R2INT_ENA; |
| 468 | if (psli->num_rings > 3) |
| 469 | status |= HC_R3INT_ENA; |
| 470 | |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 471 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
| 472 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 473 | status &= ~(HC_R0INT_ENA); |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 474 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 475 | writel(status, phba->HCregaddr); |
| 476 | readl(phba->HCregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 477 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 478 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 479 | /* Set up ring-0 (ELS) timer */ |
| 480 | timeout = phba->fc_ratov * 2; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 481 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 482 | /* Set up heart beat (HB) timer */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 483 | mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 484 | phba->hb_outstanding = 0; |
| 485 | phba->last_completion_time = jiffies; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 486 | /* Set up error attention (ERATT) polling timer */ |
| 487 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 488 | |
| 489 | lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed); |
| 490 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
James Smart | 5b8bd0c | 2007-04-25 09:52:49 -0400 | [diff] [blame] | 491 | lpfc_set_loopback_flag(phba); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 492 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
James Smart | 8aee918 | 2006-08-31 12:27:57 -0400 | [diff] [blame] | 493 | if (rc != MBX_SUCCESS) { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 494 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 495 | "0454 Adapter failed to init, mbxCmd x%x " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 496 | "INIT_LINK, mbxStatus x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 497 | mb->mbxCommand, mb->mbxStatus); |
| 498 | |
| 499 | /* Clear all interrupt enable conditions */ |
| 500 | writel(0, phba->HCregaddr); |
| 501 | readl(phba->HCregaddr); /* flush */ |
| 502 | /* Clear all pending interrupts */ |
| 503 | writel(0xffffffff, phba->HAregaddr); |
| 504 | readl(phba->HAregaddr); /* flush */ |
| 505 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 506 | phba->link_state = LPFC_HBA_ERROR; |
James Smart | 8aee918 | 2006-08-31 12:27:57 -0400 | [diff] [blame] | 507 | if (rc != MBX_BUSY) |
| 508 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 509 | return -EIO; |
| 510 | } |
| 511 | /* MBOX buffer will be freed in mbox compl */ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 512 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 513 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
| 514 | pmb->mbox_cmpl = lpfc_config_async_cmpl; |
| 515 | pmb->vport = phba->pport; |
| 516 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 517 | |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 518 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 519 | lpfc_printf_log(phba, |
| 520 | KERN_ERR, |
| 521 | LOG_INIT, |
| 522 | "0456 Adapter failed to issue " |
| 523 | "ASYNCEVT_ENABLE mbox status x%x \n.", |
| 524 | rc); |
| 525 | mempool_free(pmb, phba->mbox_mem_pool); |
| 526 | } |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame^] | 527 | |
| 528 | /* Get Option rom version */ |
| 529 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 530 | lpfc_dump_wakeup_param(phba, pmb); |
| 531 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; |
| 532 | pmb->vport = phba->pport; |
| 533 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
| 534 | |
| 535 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
| 536 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " |
| 537 | "to get Option ROM version status x%x\n.", rc); |
| 538 | mempool_free(pmb, phba->mbox_mem_pool); |
| 539 | } |
| 540 | |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 541 | return 0; |
James Smart | ce8b3ce | 2006-07-06 15:50:36 -0400 | [diff] [blame] | 542 | } |
| 543 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 544 | /** |
| 545 | * lpfc_hba_down_prep: Perform lpfc uninitialization prior to HBA reset. |
| 546 | * @phba: pointer to lpfc HBA data structure. |
| 547 | * |
| 548 | * This routine will do LPFC uninitialization before the HBA is reset when |
| 549 | * bringing down the SLI Layer. |
| 550 | * |
| 551 | * Return codes |
| 552 | * 0 - success. |
| 553 | * Any other value - error. |
| 554 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 555 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 556 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 557 | { |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 558 | struct lpfc_vport **vports; |
| 559 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 560 | /* Disable interrupts */ |
| 561 | writel(0, phba->HCregaddr); |
| 562 | readl(phba->HCregaddr); /* flush */ |
| 563 | |
James Smart | 1b32f6a | 2008-02-08 18:49:39 -0500 | [diff] [blame] | 564 | if (phba->pport->load_flag & FC_UNLOADING) |
| 565 | lpfc_cleanup_discovery_resources(phba->pport); |
| 566 | else { |
| 567 | vports = lpfc_create_vport_work_array(phba); |
| 568 | if (vports != NULL) |
| 569 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) |
| 570 | lpfc_cleanup_discovery_resources(vports[i]); |
| 571 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 572 | } |
| 573 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 574 | } |
| 575 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 576 | /** |
| 577 | * lpfc_hba_down_post: Perform lpfc uninitialization after HBA reset. |
| 578 | * @phba: pointer to lpfc HBA data structure. |
| 579 | * |
| 580 | * This routine will do uninitialization after the HBA is reset when bring |
| 581 | * down the SLI Layer. |
| 582 | * |
| 583 | * Return codes |
| 584 | * 0 - sucess. |
| 585 | * Any other value - error. |
| 586 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 587 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 588 | lpfc_hba_down_post(struct lpfc_hba *phba) |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 589 | { |
| 590 | struct lpfc_sli *psli = &phba->sli; |
| 591 | struct lpfc_sli_ring *pring; |
| 592 | struct lpfc_dmabuf *mp, *next_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 593 | struct lpfc_iocbq *iocb; |
| 594 | IOCB_t *cmd = NULL; |
| 595 | LIST_HEAD(completions); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 596 | int i; |
| 597 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 598 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
| 599 | lpfc_sli_hbqbuf_free_all(phba); |
| 600 | else { |
| 601 | /* Cleanup preposted buffers on the ELS ring */ |
| 602 | pring = &psli->ring[LPFC_ELS_RING]; |
| 603 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { |
| 604 | list_del(&mp->list); |
| 605 | pring->postbufq_cnt--; |
| 606 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| 607 | kfree(mp); |
| 608 | } |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 609 | } |
| 610 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 611 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 612 | for (i = 0; i < psli->num_rings; i++) { |
| 613 | pring = &psli->ring[i]; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 614 | |
| 615 | /* At this point in time the HBA is either reset or DOA. Either |
| 616 | * way, nothing should be on txcmplq as it will NEVER complete. |
| 617 | */ |
| 618 | list_splice_init(&pring->txcmplq, &completions); |
| 619 | pring->txcmplq_cnt = 0; |
| 620 | spin_unlock_irq(&phba->hbalock); |
| 621 | |
| 622 | while (!list_empty(&completions)) { |
| 623 | iocb = list_get_first(&completions, struct lpfc_iocbq, |
| 624 | list); |
| 625 | cmd = &iocb->iocb; |
| 626 | list_del_init(&iocb->list); |
| 627 | |
| 628 | if (!iocb->iocb_cmpl) |
| 629 | lpfc_sli_release_iocbq(phba, iocb); |
| 630 | else { |
| 631 | cmd->ulpStatus = IOSTAT_LOCAL_REJECT; |
| 632 | cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; |
| 633 | (iocb->iocb_cmpl) (phba, iocb, iocb); |
| 634 | } |
| 635 | } |
| 636 | |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 637 | lpfc_sli_abort_iocb_ring(phba, pring); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 638 | spin_lock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 639 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 640 | spin_unlock_irq(&phba->hbalock); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 641 | |
| 642 | return 0; |
| 643 | } |
| 644 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 645 | /** |
| 646 | * lpfc_hb_timeout: The HBA-timer timeout handler. |
| 647 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
| 648 | * |
| 649 | * This is the HBA-timer timeout handler registered to the lpfc driver. When |
| 650 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver |
| 651 | * work-port-events bitmap and the worker thread is notified. This timeout |
| 652 | * event will be used by the worker thread to invoke the actual timeout |
| 653 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will |
| 654 | * be performed in the timeout handler and the HBA timeout event bit shall |
| 655 | * be cleared by the worker thread after it has taken the event bitmap out. |
| 656 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 657 | static void |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 658 | lpfc_hb_timeout(unsigned long ptr) |
| 659 | { |
| 660 | struct lpfc_hba *phba; |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 661 | uint32_t tmo_posted; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 662 | unsigned long iflag; |
| 663 | |
| 664 | phba = (struct lpfc_hba *)ptr; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 665 | |
| 666 | /* Check for heart beat timeout conditions */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 667 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 668 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
| 669 | if (!tmo_posted) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 670 | phba->pport->work_port_events |= WORKER_HB_TMO; |
| 671 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
| 672 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 673 | /* Tell the worker thread there is work to do */ |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 674 | if (!tmo_posted) |
| 675 | lpfc_worker_wake_up(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 676 | return; |
| 677 | } |
| 678 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 679 | /** |
| 680 | * lpfc_hb_mbox_cmpl: The lpfc heart-beat mailbox command callback function. |
| 681 | * @phba: pointer to lpfc hba data structure. |
| 682 | * @pmboxq: pointer to the driver internal queue element for mailbox command. |
| 683 | * |
| 684 | * This is the callback function to the lpfc heart-beat mailbox command. |
| 685 | * If configured, the lpfc driver issues the heart-beat mailbox command to |
| 686 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the |
| 687 | * heart-beat mailbox command is issued, the driver shall set up heart-beat |
| 688 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks |
| 689 | * heart-beat outstanding state. Once the mailbox command comes back and |
| 690 | * no error conditions detected, the heart-beat mailbox command timer is |
| 691 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding |
| 692 | * state is cleared for the next heart-beat. If the timer expired with the |
| 693 | * heart-beat outstanding state set, the driver will put the HBA offline. |
| 694 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 695 | static void |
| 696 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) |
| 697 | { |
| 698 | unsigned long drvr_flag; |
| 699 | |
| 700 | spin_lock_irqsave(&phba->hbalock, drvr_flag); |
| 701 | phba->hb_outstanding = 0; |
| 702 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); |
| 703 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 704 | /* Check and reset heart-beat timer is necessary */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 705 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 706 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && |
| 707 | !(phba->link_state == LPFC_HBA_ERROR) && |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 708 | !(phba->pport->load_flag & FC_UNLOADING)) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 709 | mod_timer(&phba->hb_tmofunc, |
| 710 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 711 | return; |
| 712 | } |
| 713 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 714 | /** |
| 715 | * lpfc_hb_timeout_handler: The HBA-timer timeout handler. |
| 716 | * @phba: pointer to lpfc hba data structure. |
| 717 | * |
| 718 | * This is the actual HBA-timer timeout handler to be invoked by the worker |
| 719 | * thread whenever the HBA timer fired and HBA-timeout event posted. This |
| 720 | * handler performs any periodic operations needed for the device. If such |
| 721 | * periodic event has already been attended to either in the interrupt handler |
| 722 | * or by processing slow-ring or fast-ring events within the HBA-timer |
| 723 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets |
| 724 | * the timer for the next timeout period. If lpfc heart-beat mailbox command |
| 725 | * is configured and there is no heart-beat mailbox command outstanding, a |
| 726 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there |
| 727 | * has been a heart-beat mailbox command outstanding, the HBA shall be put |
| 728 | * to offline. |
| 729 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 730 | void |
| 731 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) |
| 732 | { |
| 733 | LPFC_MBOXQ_t *pmboxq; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 734 | struct lpfc_dmabuf *buf_ptr; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 735 | int retval; |
| 736 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 737 | LIST_HEAD(completions); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 738 | |
| 739 | if ((phba->link_state == LPFC_HBA_ERROR) || |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 740 | (phba->pport->load_flag & FC_UNLOADING) || |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 741 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
| 742 | return; |
| 743 | |
| 744 | spin_lock_irq(&phba->pport->work_port_lock); |
| 745 | /* If the timer is already canceled do nothing */ |
| 746 | if (!(phba->pport->work_port_events & WORKER_HB_TMO)) { |
| 747 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 748 | return; |
| 749 | } |
| 750 | |
| 751 | if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, |
| 752 | jiffies)) { |
| 753 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 754 | if (!phba->hb_outstanding) |
| 755 | mod_timer(&phba->hb_tmofunc, |
| 756 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 757 | else |
| 758 | mod_timer(&phba->hb_tmofunc, |
| 759 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
| 760 | return; |
| 761 | } |
| 762 | spin_unlock_irq(&phba->pport->work_port_lock); |
| 763 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 764 | if (phba->elsbuf_cnt && |
| 765 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { |
| 766 | spin_lock_irq(&phba->hbalock); |
| 767 | list_splice_init(&phba->elsbuf, &completions); |
| 768 | phba->elsbuf_cnt = 0; |
| 769 | phba->elsbuf_prev_cnt = 0; |
| 770 | spin_unlock_irq(&phba->hbalock); |
| 771 | |
| 772 | while (!list_empty(&completions)) { |
| 773 | list_remove_head(&completions, buf_ptr, |
| 774 | struct lpfc_dmabuf, list); |
| 775 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); |
| 776 | kfree(buf_ptr); |
| 777 | } |
| 778 | } |
| 779 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; |
| 780 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 781 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 782 | if (phba->cfg_enable_hba_heartbeat) { |
| 783 | if (!phba->hb_outstanding) { |
| 784 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); |
| 785 | if (!pmboxq) { |
| 786 | mod_timer(&phba->hb_tmofunc, |
| 787 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 788 | return; |
| 789 | } |
| 790 | |
| 791 | lpfc_heart_beat(phba, pmboxq); |
| 792 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; |
| 793 | pmboxq->vport = phba->pport; |
| 794 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); |
| 795 | |
| 796 | if (retval != MBX_BUSY && retval != MBX_SUCCESS) { |
| 797 | mempool_free(pmboxq, phba->mbox_mem_pool); |
| 798 | mod_timer(&phba->hb_tmofunc, |
| 799 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
| 800 | return; |
| 801 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 802 | mod_timer(&phba->hb_tmofunc, |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 803 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
| 804 | phba->hb_outstanding = 1; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 805 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 806 | } else { |
| 807 | /* |
| 808 | * If heart beat timeout called with hb_outstanding set |
| 809 | * we need to take the HBA offline. |
| 810 | */ |
| 811 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 812 | "0459 Adapter heartbeat failure, " |
| 813 | "taking this port offline.\n"); |
| 814 | |
| 815 | spin_lock_irq(&phba->hbalock); |
| 816 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 817 | spin_unlock_irq(&phba->hbalock); |
| 818 | |
| 819 | lpfc_offline_prep(phba); |
| 820 | lpfc_offline(phba); |
| 821 | lpfc_unblock_mgmt_io(phba); |
| 822 | phba->link_state = LPFC_HBA_ERROR; |
| 823 | lpfc_hba_down_post(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 824 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 825 | } |
| 826 | } |
| 827 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 828 | /** |
| 829 | * lpfc_offline_eratt: Bring lpfc offline on hardware error attention. |
| 830 | * @phba: pointer to lpfc hba data structure. |
| 831 | * |
| 832 | * This routine is called to bring the HBA offline when HBA hardware error |
| 833 | * other than Port Error 6 has been detected. |
| 834 | **/ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 835 | static void |
| 836 | lpfc_offline_eratt(struct lpfc_hba *phba) |
| 837 | { |
| 838 | struct lpfc_sli *psli = &phba->sli; |
| 839 | |
| 840 | spin_lock_irq(&phba->hbalock); |
| 841 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
| 842 | spin_unlock_irq(&phba->hbalock); |
| 843 | lpfc_offline_prep(phba); |
| 844 | |
| 845 | lpfc_offline(phba); |
| 846 | lpfc_reset_barrier(phba); |
| 847 | lpfc_sli_brdreset(phba); |
| 848 | lpfc_hba_down_post(phba); |
| 849 | lpfc_sli_brdready(phba, HS_MBRDY); |
| 850 | lpfc_unblock_mgmt_io(phba); |
| 851 | phba->link_state = LPFC_HBA_ERROR; |
| 852 | return; |
| 853 | } |
| 854 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 855 | /** |
| 856 | * lpfc_handle_eratt: The HBA hardware error handler. |
| 857 | * @phba: pointer to lpfc hba data structure. |
| 858 | * |
| 859 | * This routine is invoked to handle the following HBA hardware error |
| 860 | * conditions: |
| 861 | * 1 - HBA error attention interrupt |
| 862 | * 2 - DMA ring index out of range |
| 863 | * 3 - Mailbox command came back as unknown |
| 864 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 865 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 866 | lpfc_handle_eratt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 867 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 868 | struct lpfc_vport *vport = phba->pport; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 869 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 870 | struct lpfc_sli_ring *pring; |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 871 | uint32_t event_data; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 872 | unsigned long temperature; |
| 873 | struct temp_event temp_event_data; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 874 | struct Scsi_Host *shost; |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 875 | struct lpfc_board_event_header board_event; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 876 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 877 | /* If the pci channel is offline, ignore possible errors, |
| 878 | * since we cannot communicate with the pci card anyway. */ |
| 879 | if (pci_channel_offline(phba->pcidev)) |
| 880 | return; |
James Smart | 13815c8 | 2008-01-11 01:52:48 -0500 | [diff] [blame] | 881 | /* If resets are disabled then leave the HBA alone and return */ |
| 882 | if (!phba->cfg_enable_hba_reset) |
| 883 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 884 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 885 | /* Send an internal error event to mgmt application */ |
| 886 | board_event.event_type = FC_REG_BOARD_EVENT; |
| 887 | board_event.subcategory = LPFC_EVENT_PORTINTERR; |
| 888 | shost = lpfc_shost_from_vport(phba->pport); |
| 889 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 890 | sizeof(board_event), |
| 891 | (char *) &board_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 892 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 893 | |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 894 | if (phba->work_hs & HS_FFER6) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 895 | /* Re-establishing Link */ |
| 896 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 897 | "1301 Re-establishing Link " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 898 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 899 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 900 | phba->work_status[0], phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 901 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 902 | spin_lock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 903 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 904 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 905 | |
| 906 | /* |
| 907 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 908 | * That could cause the I/Os dropped by the firmware. |
| 909 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 910 | * retry it after re-establishing link. |
| 911 | */ |
| 912 | pring = &psli->ring[psli->fcp_ring]; |
| 913 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 914 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 915 | /* |
| 916 | * There was a firmware error. Take the hba offline and then |
| 917 | * attempt to restart it. |
| 918 | */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 919 | lpfc_offline_prep(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 920 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 921 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 922 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 923 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 924 | return; |
| 925 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 926 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 927 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 928 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 929 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 930 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 931 | temp_event_data.data = (uint32_t)temperature; |
| 932 | |
| 933 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 934 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 935 | "(%ld), taking this port offline " |
| 936 | "Data: x%x x%x x%x\n", |
| 937 | temperature, phba->work_hs, |
| 938 | phba->work_status[0], phba->work_status[1]); |
| 939 | |
| 940 | shost = lpfc_shost_from_vport(phba->pport); |
| 941 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 942 | sizeof(temp_event_data), |
| 943 | (char *) &temp_event_data, |
| 944 | SCSI_NL_VID_TYPE_PCI |
| 945 | | PCI_VENDOR_ID_EMULEX); |
| 946 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 947 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 948 | phba->over_temp_state = HBA_OVER_TEMP; |
| 949 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 950 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 951 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 952 | } else { |
| 953 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 954 | * failure is a value other than FFER6. Do not call the offline |
| 955 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 956 | */ |
| 957 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 958 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 959 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 960 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 961 | phba->work_status[0], phba->work_status[1]); |
| 962 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 963 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 964 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 965 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 966 | sizeof(event_data), (char *) &event_data, |
| 967 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 968 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 969 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 970 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 971 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 972 | } |
| 973 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 974 | /** |
| 975 | * lpfc_handle_latt: The HBA link event handler. |
| 976 | * @phba: pointer to lpfc hba data structure. |
| 977 | * |
| 978 | * This routine is invoked from the worker thread to handle a HBA host |
| 979 | * attention link event. |
| 980 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 981 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 982 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 983 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 984 | struct lpfc_vport *vport = phba->pport; |
| 985 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 986 | LPFC_MBOXQ_t *pmb; |
| 987 | volatile uint32_t control; |
| 988 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 989 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 990 | |
| 991 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 992 | if (!pmb) { |
| 993 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 994 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 995 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 996 | |
| 997 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 998 | if (!mp) { |
| 999 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1000 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1001 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1002 | |
| 1003 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1004 | if (!mp->virt) { |
| 1005 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1006 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1007 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1008 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 1009 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1010 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1011 | |
| 1012 | psli->slistat.link_event++; |
| 1013 | lpfc_read_la(phba, pmb, mp); |
| 1014 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1015 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1016 | /* Block ELS IOCBs until we have processed this mbox command */ |
| 1017 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 1018 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1019 | if (rc == MBX_NOT_FINISHED) { |
| 1020 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1021 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1022 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1023 | |
| 1024 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1025 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1026 | writel(HA_LATT, phba->HAregaddr); |
| 1027 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1028 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1029 | |
| 1030 | return; |
| 1031 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1032 | lpfc_handle_latt_free_mbuf: |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 1033 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 1034 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1035 | lpfc_handle_latt_free_mp: |
| 1036 | kfree(mp); |
| 1037 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 1038 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1039 | lpfc_handle_latt_err_exit: |
| 1040 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1041 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1042 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 1043 | control = readl(phba->HCregaddr); |
| 1044 | control |= HC_LAINT_ENA; |
| 1045 | writel(control, phba->HCregaddr); |
| 1046 | readl(phba->HCregaddr); /* flush */ |
| 1047 | |
| 1048 | /* Clear Link Attention in HA REG */ |
| 1049 | writel(HA_LATT, phba->HAregaddr); |
| 1050 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1051 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1052 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1053 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1054 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1055 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1056 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1057 | |
| 1058 | return; |
| 1059 | } |
| 1060 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1061 | /** |
| 1062 | * lpfc_parse_vpd: Parse VPD (Vital Product Data). |
| 1063 | * @phba: pointer to lpfc hba data structure. |
| 1064 | * @vpd: pointer to the vital product data. |
| 1065 | * @len: length of the vital product data in bytes. |
| 1066 | * |
| 1067 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 1068 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 1069 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 1070 | * |
| 1071 | * Return codes |
| 1072 | * 0 - pointer to the VPD passed in is NULL |
| 1073 | * 1 - success |
| 1074 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1075 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1076 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1077 | { |
| 1078 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 1079 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1080 | int i, j; |
| 1081 | int finished = 0; |
| 1082 | int index = 0; |
| 1083 | |
| 1084 | if (!vpd) |
| 1085 | return 0; |
| 1086 | |
| 1087 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1088 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1089 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1090 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 1091 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1092 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1093 | switch (vpd[index]) { |
| 1094 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1095 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1096 | index += 1; |
| 1097 | lenlo = vpd[index]; |
| 1098 | index += 1; |
| 1099 | lenhi = vpd[index]; |
| 1100 | index += 1; |
| 1101 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 1102 | index += i; |
| 1103 | break; |
| 1104 | case 0x90: |
| 1105 | index += 1; |
| 1106 | lenlo = vpd[index]; |
| 1107 | index += 1; |
| 1108 | lenhi = vpd[index]; |
| 1109 | index += 1; |
| 1110 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1111 | if (Length > len - index) |
| 1112 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1113 | while (Length > 0) { |
| 1114 | /* Look for Serial Number */ |
| 1115 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 1116 | index += 2; |
| 1117 | i = vpd[index]; |
| 1118 | index += 1; |
| 1119 | j = 0; |
| 1120 | Length -= (3+i); |
| 1121 | while(i--) { |
| 1122 | phba->SerialNumber[j++] = vpd[index++]; |
| 1123 | if (j == 31) |
| 1124 | break; |
| 1125 | } |
| 1126 | phba->SerialNumber[j] = 0; |
| 1127 | continue; |
| 1128 | } |
| 1129 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 1130 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 1131 | index += 2; |
| 1132 | i = vpd[index]; |
| 1133 | index += 1; |
| 1134 | j = 0; |
| 1135 | Length -= (3+i); |
| 1136 | while(i--) { |
| 1137 | phba->ModelDesc[j++] = vpd[index++]; |
| 1138 | if (j == 255) |
| 1139 | break; |
| 1140 | } |
| 1141 | phba->ModelDesc[j] = 0; |
| 1142 | continue; |
| 1143 | } |
| 1144 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 1145 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 1146 | index += 2; |
| 1147 | i = vpd[index]; |
| 1148 | index += 1; |
| 1149 | j = 0; |
| 1150 | Length -= (3+i); |
| 1151 | while(i--) { |
| 1152 | phba->ModelName[j++] = vpd[index++]; |
| 1153 | if (j == 79) |
| 1154 | break; |
| 1155 | } |
| 1156 | phba->ModelName[j] = 0; |
| 1157 | continue; |
| 1158 | } |
| 1159 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 1160 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 1161 | index += 2; |
| 1162 | i = vpd[index]; |
| 1163 | index += 1; |
| 1164 | j = 0; |
| 1165 | Length -= (3+i); |
| 1166 | while(i--) { |
| 1167 | phba->ProgramType[j++] = vpd[index++]; |
| 1168 | if (j == 255) |
| 1169 | break; |
| 1170 | } |
| 1171 | phba->ProgramType[j] = 0; |
| 1172 | continue; |
| 1173 | } |
| 1174 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 1175 | phba->vpd_flag |= VPD_PORT; |
| 1176 | index += 2; |
| 1177 | i = vpd[index]; |
| 1178 | index += 1; |
| 1179 | j = 0; |
| 1180 | Length -= (3+i); |
| 1181 | while(i--) { |
| 1182 | phba->Port[j++] = vpd[index++]; |
| 1183 | if (j == 19) |
| 1184 | break; |
| 1185 | } |
| 1186 | phba->Port[j] = 0; |
| 1187 | continue; |
| 1188 | } |
| 1189 | else { |
| 1190 | index += 2; |
| 1191 | i = vpd[index]; |
| 1192 | index += 1; |
| 1193 | index += i; |
| 1194 | Length -= (3 + i); |
| 1195 | } |
| 1196 | } |
| 1197 | finished = 0; |
| 1198 | break; |
| 1199 | case 0x78: |
| 1200 | finished = 1; |
| 1201 | break; |
| 1202 | default: |
| 1203 | index ++; |
| 1204 | break; |
| 1205 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1206 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1207 | |
| 1208 | return(1); |
| 1209 | } |
| 1210 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1211 | /** |
| 1212 | * lpfc_get_hba_model_desc: Retrieve HBA device model name and description. |
| 1213 | * @phba: pointer to lpfc hba data structure. |
| 1214 | * @mdp: pointer to the data structure to hold the derived model name. |
| 1215 | * @descp: pointer to the data structure to hold the derived description. |
| 1216 | * |
| 1217 | * This routine retrieves HBA's description based on its registered PCI device |
| 1218 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 1219 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 1220 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 1221 | * function returns, the @mdp will be filled with the model name. |
| 1222 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1223 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1224 | 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] | 1225 | { |
| 1226 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 1227 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1228 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1229 | int GE = 0; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1230 | struct { |
| 1231 | char * name; |
| 1232 | int max_speed; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1233 | char * bus; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1234 | } m = {"<Unknown>", 0, ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1235 | |
| 1236 | if (mdp && mdp[0] != '\0' |
| 1237 | && descp && descp[0] != '\0') |
| 1238 | return; |
| 1239 | |
| 1240 | if (phba->lmt & LMT_10Gb) |
| 1241 | max_speed = 10; |
| 1242 | else if (phba->lmt & LMT_8Gb) |
| 1243 | max_speed = 8; |
| 1244 | else if (phba->lmt & LMT_4Gb) |
| 1245 | max_speed = 4; |
| 1246 | else if (phba->lmt & LMT_2Gb) |
| 1247 | max_speed = 2; |
| 1248 | else |
| 1249 | max_speed = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1250 | |
| 1251 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1252 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1253 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1254 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1255 | m = (typeof(m)){"LP6000", max_speed, "PCI"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1256 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1257 | case PCI_DEVICE_ID_SUPERFLY: |
| 1258 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1259 | m = (typeof(m)){"LP7000", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1260 | else |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1261 | m = (typeof(m)){"LP7000E", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1262 | break; |
| 1263 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1264 | m = (typeof(m)){"LP8000", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1265 | break; |
| 1266 | case PCI_DEVICE_ID_CENTAUR: |
| 1267 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1268 | m = (typeof(m)){"LP9002", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1269 | else |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1270 | m = (typeof(m)){"LP9000", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1271 | break; |
| 1272 | case PCI_DEVICE_ID_RFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1273 | m = (typeof(m)){"LP952", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1274 | break; |
| 1275 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1276 | m = (typeof(m)){"LP9802", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1277 | break; |
| 1278 | case PCI_DEVICE_ID_THOR: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1279 | m = (typeof(m)){"LP10000", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1280 | break; |
| 1281 | case PCI_DEVICE_ID_VIPER: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1282 | m = (typeof(m)){"LPX1000", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1283 | break; |
| 1284 | case PCI_DEVICE_ID_PFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1285 | m = (typeof(m)){"LP982", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1286 | break; |
| 1287 | case PCI_DEVICE_ID_TFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1288 | m = (typeof(m)){"LP1050", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1289 | break; |
| 1290 | case PCI_DEVICE_ID_HELIOS: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1291 | m = (typeof(m)){"LP11000", max_speed, "PCI-X2"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1292 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1293 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1294 | m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1295 | break; |
| 1296 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1297 | m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1298 | break; |
| 1299 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1300 | m = (typeof(m)){"LPe1000", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1301 | break; |
| 1302 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1303 | m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1304 | break; |
| 1305 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1306 | m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1307 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1308 | case PCI_DEVICE_ID_BMID: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1309 | m = (typeof(m)){"LP1150", max_speed, "PCI-X2"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1310 | break; |
| 1311 | case PCI_DEVICE_ID_BSMB: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1312 | m = (typeof(m)){"LP111", max_speed, "PCI-X2"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1313 | break; |
| 1314 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1315 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1316 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1317 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1318 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1319 | break; |
| 1320 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1321 | m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1322 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1323 | case PCI_DEVICE_ID_ZMID: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1324 | m = (typeof(m)){"LPe1150", max_speed, "PCIe"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1325 | break; |
| 1326 | case PCI_DEVICE_ID_ZSMB: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1327 | m = (typeof(m)){"LPe111", max_speed, "PCIe"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1328 | break; |
| 1329 | case PCI_DEVICE_ID_LP101: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1330 | m = (typeof(m)){"LP101", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1331 | break; |
| 1332 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1333 | m = (typeof(m)){"LP10000-S", max_speed, "PCI"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1334 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1335 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1336 | m = (typeof(m)){"LP11000-S", max_speed, |
| 1337 | "PCI-X2"}; |
| 1338 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1339 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1340 | m = (typeof(m)){"LPe11000-S", max_speed, |
| 1341 | "PCIe"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 1342 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 1343 | case PCI_DEVICE_ID_SAT: |
| 1344 | m = (typeof(m)){"LPe12000", max_speed, "PCIe"}; |
| 1345 | break; |
| 1346 | case PCI_DEVICE_ID_SAT_MID: |
| 1347 | m = (typeof(m)){"LPe1250", max_speed, "PCIe"}; |
| 1348 | break; |
| 1349 | case PCI_DEVICE_ID_SAT_SMB: |
| 1350 | m = (typeof(m)){"LPe121", max_speed, "PCIe"}; |
| 1351 | break; |
| 1352 | case PCI_DEVICE_ID_SAT_DCSP: |
| 1353 | m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"}; |
| 1354 | break; |
| 1355 | case PCI_DEVICE_ID_SAT_SCSP: |
| 1356 | m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"}; |
| 1357 | break; |
| 1358 | case PCI_DEVICE_ID_SAT_S: |
| 1359 | m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"}; |
| 1360 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1361 | case PCI_DEVICE_ID_HORNET: |
| 1362 | m = (typeof(m)){"LP21000", max_speed, "PCIe"}; |
| 1363 | GE = 1; |
| 1364 | break; |
| 1365 | case PCI_DEVICE_ID_PROTEUS_VF: |
| 1366 | m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"}; |
| 1367 | break; |
| 1368 | case PCI_DEVICE_ID_PROTEUS_PF: |
| 1369 | m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"}; |
| 1370 | break; |
| 1371 | case PCI_DEVICE_ID_PROTEUS_S: |
| 1372 | m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"}; |
| 1373 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 1374 | default: |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 1375 | m = (typeof(m)){ NULL }; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1376 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1377 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1378 | |
| 1379 | if (mdp && mdp[0] == '\0') |
| 1380 | snprintf(mdp, 79,"%s", m.name); |
| 1381 | if (descp && descp[0] == '\0') |
| 1382 | snprintf(descp, 255, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1383 | "Emulex %s %d%s %s %s", |
| 1384 | m.name, m.max_speed, |
| 1385 | (GE) ? "GE" : "Gb", |
| 1386 | m.bus, |
| 1387 | (GE) ? "FCoE Adapter" : "Fibre Channel Adapter"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1388 | } |
| 1389 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1390 | /** |
| 1391 | * lpfc_post_buffer: Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring. |
| 1392 | * @phba: pointer to lpfc hba data structure. |
| 1393 | * @pring: pointer to a IOCB ring. |
| 1394 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 1395 | * |
| 1396 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 1397 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 1398 | * |
| 1399 | * Return codes |
| 1400 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 1401 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1402 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1403 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1404 | { |
| 1405 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1406 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1407 | struct lpfc_dmabuf *mp1, *mp2; |
| 1408 | |
| 1409 | cnt += pring->missbufcnt; |
| 1410 | |
| 1411 | /* While there are buffers to post */ |
| 1412 | while (cnt > 0) { |
| 1413 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1414 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1415 | if (iocb == NULL) { |
| 1416 | pring->missbufcnt = cnt; |
| 1417 | return cnt; |
| 1418 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1419 | icmd = &iocb->iocb; |
| 1420 | |
| 1421 | /* 2 buffers can be posted per command */ |
| 1422 | /* Allocate buffer to post */ |
| 1423 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 1424 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1425 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 1426 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1427 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1428 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1429 | pring->missbufcnt = cnt; |
| 1430 | return cnt; |
| 1431 | } |
| 1432 | |
| 1433 | INIT_LIST_HEAD(&mp1->list); |
| 1434 | /* Allocate buffer to post */ |
| 1435 | if (cnt > 1) { |
| 1436 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 1437 | if (mp2) |
| 1438 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 1439 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1440 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1441 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1442 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 1443 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1444 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1445 | pring->missbufcnt = cnt; |
| 1446 | return cnt; |
| 1447 | } |
| 1448 | |
| 1449 | INIT_LIST_HEAD(&mp2->list); |
| 1450 | } else { |
| 1451 | mp2 = NULL; |
| 1452 | } |
| 1453 | |
| 1454 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 1455 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 1456 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 1457 | icmd->ulpBdeCount = 1; |
| 1458 | cnt--; |
| 1459 | if (mp2) { |
| 1460 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 1461 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 1462 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 1463 | cnt--; |
| 1464 | icmd->ulpBdeCount = 2; |
| 1465 | } |
| 1466 | |
| 1467 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 1468 | icmd->ulpLe = 1; |
| 1469 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1470 | if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) { |
| 1471 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 1472 | kfree(mp1); |
| 1473 | cnt++; |
| 1474 | if (mp2) { |
| 1475 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 1476 | kfree(mp2); |
| 1477 | cnt++; |
| 1478 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1479 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1480 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1481 | return cnt; |
| 1482 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1483 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1484 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1485 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1486 | } |
| 1487 | pring->missbufcnt = 0; |
| 1488 | return 0; |
| 1489 | } |
| 1490 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1491 | /** |
| 1492 | * lpfc_post_rcv_buf: Post the initial receive IOCB buffers to ELS ring. |
| 1493 | * @phba: pointer to lpfc hba data structure. |
| 1494 | * |
| 1495 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 1496 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
| 1497 | * set to 64 IOCBs. |
| 1498 | * |
| 1499 | * Return codes |
| 1500 | * 0 - success (currently always success) |
| 1501 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1502 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1503 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1504 | { |
| 1505 | struct lpfc_sli *psli = &phba->sli; |
| 1506 | |
| 1507 | /* Ring 0, ELS / CT buffers */ |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1508 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1509 | /* Ring 2 - FCP no buffers needed */ |
| 1510 | |
| 1511 | return 0; |
| 1512 | } |
| 1513 | |
| 1514 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 1515 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1516 | /** |
| 1517 | * lpfc_sha_init: Set up initial array of hash table entries. |
| 1518 | * @HashResultPointer: pointer to an array as hash table. |
| 1519 | * |
| 1520 | * This routine sets up the initial values to the array of hash table entries |
| 1521 | * for the LC HBAs. |
| 1522 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1523 | static void |
| 1524 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 1525 | { |
| 1526 | HashResultPointer[0] = 0x67452301; |
| 1527 | HashResultPointer[1] = 0xEFCDAB89; |
| 1528 | HashResultPointer[2] = 0x98BADCFE; |
| 1529 | HashResultPointer[3] = 0x10325476; |
| 1530 | HashResultPointer[4] = 0xC3D2E1F0; |
| 1531 | } |
| 1532 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1533 | /** |
| 1534 | * lpfc_sha_iterate: Iterate initial hash table with the working hash table. |
| 1535 | * @HashResultPointer: pointer to an initial/result hash table. |
| 1536 | * @HashWorkingPointer: pointer to an working hash table. |
| 1537 | * |
| 1538 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 1539 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 1540 | * The results are putting back to the initial hash table, returned through |
| 1541 | * the @HashResultPointer as the result hash table. |
| 1542 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1543 | static void |
| 1544 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 1545 | { |
| 1546 | int t; |
| 1547 | uint32_t TEMP; |
| 1548 | uint32_t A, B, C, D, E; |
| 1549 | t = 16; |
| 1550 | do { |
| 1551 | HashWorkingPointer[t] = |
| 1552 | S(1, |
| 1553 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 1554 | 8] ^ |
| 1555 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 1556 | } while (++t <= 79); |
| 1557 | t = 0; |
| 1558 | A = HashResultPointer[0]; |
| 1559 | B = HashResultPointer[1]; |
| 1560 | C = HashResultPointer[2]; |
| 1561 | D = HashResultPointer[3]; |
| 1562 | E = HashResultPointer[4]; |
| 1563 | |
| 1564 | do { |
| 1565 | if (t < 20) { |
| 1566 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 1567 | } else if (t < 40) { |
| 1568 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 1569 | } else if (t < 60) { |
| 1570 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 1571 | } else { |
| 1572 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 1573 | } |
| 1574 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 1575 | E = D; |
| 1576 | D = C; |
| 1577 | C = S(30, B); |
| 1578 | B = A; |
| 1579 | A = TEMP; |
| 1580 | } while (++t <= 79); |
| 1581 | |
| 1582 | HashResultPointer[0] += A; |
| 1583 | HashResultPointer[1] += B; |
| 1584 | HashResultPointer[2] += C; |
| 1585 | HashResultPointer[3] += D; |
| 1586 | HashResultPointer[4] += E; |
| 1587 | |
| 1588 | } |
| 1589 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1590 | /** |
| 1591 | * lpfc_challenge_key: Create challenge key based on WWPN of the HBA. |
| 1592 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 1593 | * @HashWorking: pointer to the entry of the working hash array. |
| 1594 | * |
| 1595 | * This routine calculates the working hash array referred by @HashWorking |
| 1596 | * from the challenge random numbers associated with the host, referred by |
| 1597 | * @RandomChallenge. The result is put into the entry of the working hash |
| 1598 | * array and returned by reference through @HashWorking. |
| 1599 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1600 | static void |
| 1601 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 1602 | { |
| 1603 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 1604 | } |
| 1605 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1606 | /** |
| 1607 | * lpfc_hba_init: Perform special handling for LC HBA initialization. |
| 1608 | * @phba: pointer to lpfc hba data structure. |
| 1609 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 1610 | * |
| 1611 | * This routine performs the special handling for LC HBA initialization. |
| 1612 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1613 | void |
| 1614 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 1615 | { |
| 1616 | int t; |
| 1617 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1618 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1619 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 1620 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1621 | if (!HashWorking) |
| 1622 | return; |
| 1623 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1624 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 1625 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 1626 | |
| 1627 | for (t = 0; t < 7; t++) |
| 1628 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 1629 | |
| 1630 | lpfc_sha_init(hbainit); |
| 1631 | lpfc_sha_iterate(hbainit, HashWorking); |
| 1632 | kfree(HashWorking); |
| 1633 | } |
| 1634 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1635 | /** |
| 1636 | * lpfc_cleanup: Performs vport cleanups before deleting a vport. |
| 1637 | * @vport: pointer to a virtual N_Port data structure. |
| 1638 | * |
| 1639 | * This routine performs the necessary cleanups before deleting the @vport. |
| 1640 | * It invokes the discovery state machine to perform necessary state |
| 1641 | * transitions and to release the ndlps associated with the @vport. Note, |
| 1642 | * the physical port is treated as @vport 0. |
| 1643 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1644 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1645 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1646 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1647 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1648 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1649 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1650 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1651 | if (phba->link_state > LPFC_LINK_DOWN) |
| 1652 | lpfc_port_link_failure(vport); |
| 1653 | |
| 1654 | 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] | 1655 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1656 | ndlp = lpfc_enable_node(vport, ndlp, |
| 1657 | NLP_STE_UNUSED_NODE); |
| 1658 | if (!ndlp) |
| 1659 | continue; |
| 1660 | spin_lock_irq(&phba->ndlp_lock); |
| 1661 | NLP_SET_FREE_REQ(ndlp); |
| 1662 | spin_unlock_irq(&phba->ndlp_lock); |
| 1663 | /* Trigger the release of the ndlp memory */ |
| 1664 | lpfc_nlp_put(ndlp); |
| 1665 | continue; |
| 1666 | } |
| 1667 | spin_lock_irq(&phba->ndlp_lock); |
| 1668 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 1669 | /* The ndlp should not be in memory free mode already */ |
| 1670 | spin_unlock_irq(&phba->ndlp_lock); |
| 1671 | continue; |
| 1672 | } else |
| 1673 | /* Indicate request for freeing ndlp memory */ |
| 1674 | NLP_SET_FREE_REQ(ndlp); |
| 1675 | spin_unlock_irq(&phba->ndlp_lock); |
| 1676 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1677 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 1678 | ndlp->nlp_DID == Fabric_DID) { |
| 1679 | /* Just free up ndlp with Fabric_DID for vports */ |
| 1680 | lpfc_nlp_put(ndlp); |
| 1681 | continue; |
| 1682 | } |
| 1683 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1684 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1685 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 1686 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1687 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1688 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 1689 | NLP_EVT_DEVICE_RM); |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1690 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1691 | } |
| 1692 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1693 | /* At this point, ALL ndlp's should be gone |
| 1694 | * because of the previous NLP_EVT_DEVICE_RM. |
| 1695 | * Lets wait for this to happen, if needed. |
| 1696 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1697 | while (!list_empty(&vport->fc_nodes)) { |
| 1698 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1699 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1700 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1701 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1702 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 1703 | &vport->fc_nodes, nlp_listp) { |
| 1704 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 1705 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1706 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1707 | "usgmap:x%x refcnt:%d\n", |
| 1708 | ndlp->nlp_DID, (void *)ndlp, |
| 1709 | ndlp->nlp_usg_map, |
| 1710 | atomic_read( |
| 1711 | &ndlp->kref.refcount)); |
| 1712 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1713 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1714 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1715 | |
| 1716 | /* Wait for any activity on ndlps to settle */ |
| 1717 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1718 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1719 | return; |
| 1720 | } |
| 1721 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1722 | /** |
| 1723 | * lpfc_stop_vport_timers: Stop all the timers associated with a vport. |
| 1724 | * @vport: pointer to a virtual N_Port data structure. |
| 1725 | * |
| 1726 | * This routine stops all the timers associated with a @vport. This function |
| 1727 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 1728 | * port is treated as @vport 0. |
| 1729 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1730 | void |
| 1731 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1732 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1733 | del_timer_sync(&vport->els_tmofunc); |
| 1734 | del_timer_sync(&vport->fc_fdmitmo); |
| 1735 | lpfc_can_disctmo(vport); |
| 1736 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1737 | } |
| 1738 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1739 | /** |
| 1740 | * lpfc_stop_phba_timers: Stop all the timers associated with an HBA. |
| 1741 | * @phba: pointer to lpfc hba data structure. |
| 1742 | * |
| 1743 | * This routine stops all the timers associated with a HBA. This function is |
| 1744 | * invoked before either putting a HBA offline or unloading the driver. |
| 1745 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1746 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1747 | lpfc_stop_phba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1748 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1749 | del_timer_sync(&phba->fcp_poll_timer); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1750 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1751 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1752 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1753 | phba->hb_outstanding = 0; |
| 1754 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1755 | del_timer_sync(&phba->eratt_poll); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1756 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1757 | } |
| 1758 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1759 | /** |
| 1760 | * lpfc_block_mgmt_io: Mark a HBA's management interface as blocked. |
| 1761 | * @phba: pointer to lpfc hba data structure. |
| 1762 | * |
| 1763 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 1764 | * management interface is marked as blocked, all the user space access to |
| 1765 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 1766 | * all be blocked. The HBA is set to block the management interface when the |
| 1767 | * driver prepares the HBA interface for online or offline. |
| 1768 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1769 | static void |
| 1770 | lpfc_block_mgmt_io(struct lpfc_hba * phba) |
| 1771 | { |
| 1772 | unsigned long iflag; |
| 1773 | |
| 1774 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1775 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
| 1776 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1777 | } |
| 1778 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1779 | /** |
| 1780 | * lpfc_online: Initialize and bring a HBA online. |
| 1781 | * @phba: pointer to lpfc hba data structure. |
| 1782 | * |
| 1783 | * This routine initializes the HBA and brings a HBA online. During this |
| 1784 | * process, the management interface is blocked to prevent user space access |
| 1785 | * to the HBA interfering with the driver initialization. |
| 1786 | * |
| 1787 | * Return codes |
| 1788 | * 0 - successful |
| 1789 | * 1 - failed |
| 1790 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1791 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1792 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1793 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1794 | struct lpfc_vport *vport = phba->pport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1795 | struct lpfc_vport **vports; |
| 1796 | int i; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1797 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1798 | if (!phba) |
| 1799 | return 0; |
| 1800 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1801 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1802 | return 0; |
| 1803 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1804 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1805 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1806 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1807 | lpfc_block_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1808 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1809 | if (!lpfc_sli_queue_setup(phba)) { |
| 1810 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1811 | return 1; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */ |
| 1815 | lpfc_unblock_mgmt_io(phba); |
| 1816 | return 1; |
| 1817 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1818 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1819 | vports = lpfc_create_vport_work_array(phba); |
| 1820 | if (vports != NULL) |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1821 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1822 | struct Scsi_Host *shost; |
| 1823 | shost = lpfc_shost_from_vport(vports[i]); |
| 1824 | spin_lock_irq(shost->host_lock); |
| 1825 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 1826 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 1827 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 1828 | spin_unlock_irq(shost->host_lock); |
| 1829 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1830 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1831 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1832 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1833 | return 0; |
| 1834 | } |
| 1835 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1836 | /** |
| 1837 | * lpfc_unblock_mgmt_io: Mark a HBA's management interface to be not blocked. |
| 1838 | * @phba: pointer to lpfc hba data structure. |
| 1839 | * |
| 1840 | * This routine marks a HBA's management interface as not blocked. Once the |
| 1841 | * HBA's management interface is marked as not blocked, all the user space |
| 1842 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 1843 | * interface will be allowed. The HBA is set to block the management interface |
| 1844 | * when the driver prepares the HBA interface for online or offline and then |
| 1845 | * set to unblock the management interface afterwards. |
| 1846 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1847 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1848 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 1849 | { |
| 1850 | unsigned long iflag; |
| 1851 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1852 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1853 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 1854 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1855 | } |
| 1856 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1857 | /** |
| 1858 | * lpfc_offline_prep: Prepare a HBA to be brought offline. |
| 1859 | * @phba: pointer to lpfc hba data structure. |
| 1860 | * |
| 1861 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 1862 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 1863 | * queue to make it ready to be brought offline. |
| 1864 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1865 | void |
| 1866 | lpfc_offline_prep(struct lpfc_hba * phba) |
| 1867 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1868 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1869 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1870 | struct lpfc_vport **vports; |
| 1871 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1872 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1873 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1874 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1875 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1876 | lpfc_block_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1877 | |
| 1878 | lpfc_linkdown(phba); |
| 1879 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1880 | /* Issue an unreg_login to all nodes on all vports */ |
| 1881 | vports = lpfc_create_vport_work_array(phba); |
| 1882 | if (vports != NULL) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1883 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1884 | struct Scsi_Host *shost; |
| 1885 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1886 | if (vports[i]->load_flag & FC_UNLOADING) |
| 1887 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1888 | shost = lpfc_shost_from_vport(vports[i]); |
| 1889 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 1890 | &vports[i]->fc_nodes, |
| 1891 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1892 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 1893 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1894 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 1895 | continue; |
| 1896 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 1897 | lpfc_disc_state_machine(vports[i], ndlp, |
| 1898 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 1899 | lpfc_disc_state_machine(vports[i], ndlp, |
| 1900 | NULL, NLP_EVT_DEVICE_RM); |
| 1901 | } |
| 1902 | spin_lock_irq(shost->host_lock); |
| 1903 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
| 1904 | spin_unlock_irq(shost->host_lock); |
| 1905 | lpfc_unreg_rpi(vports[i], ndlp); |
| 1906 | } |
| 1907 | } |
| 1908 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1909 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1910 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1911 | lpfc_sli_flush_mbox_queue(phba); |
| 1912 | } |
| 1913 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1914 | /** |
| 1915 | * lpfc_offline: Bring a HBA offline. |
| 1916 | * @phba: pointer to lpfc hba data structure. |
| 1917 | * |
| 1918 | * This routine actually brings a HBA offline. It stops all the timers |
| 1919 | * associated with the HBA, brings down the SLI layer, and eventually |
| 1920 | * marks the HBA as in offline state for the upper layer protocol. |
| 1921 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1922 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1923 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1924 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1925 | struct Scsi_Host *shost; |
| 1926 | struct lpfc_vport **vports; |
| 1927 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1928 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1929 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1930 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 1931 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1932 | /* stop all timers associated with this hba */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1933 | lpfc_stop_phba_timers(phba); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1934 | vports = lpfc_create_vport_work_array(phba); |
| 1935 | if (vports != NULL) |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1936 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1937 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1938 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1939 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1940 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1941 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 1942 | now. */ |
| 1943 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1944 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1945 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1946 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1947 | vports = lpfc_create_vport_work_array(phba); |
| 1948 | if (vports != NULL) |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1949 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1950 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1951 | spin_lock_irq(shost->host_lock); |
| 1952 | vports[i]->work_port_events = 0; |
| 1953 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 1954 | spin_unlock_irq(shost->host_lock); |
| 1955 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1956 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1957 | } |
| 1958 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1959 | /** |
| 1960 | * lpfc_scsi_free: Free all the SCSI buffers and IOCBs from driver lists. |
| 1961 | * @phba: pointer to lpfc hba data structure. |
| 1962 | * |
| 1963 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 1964 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 1965 | * the internal resources before the device is removed from the system. |
| 1966 | * |
| 1967 | * Return codes |
| 1968 | * 0 - successful (for now, it always returns 0) |
| 1969 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1970 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1971 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1972 | { |
| 1973 | struct lpfc_scsi_buf *sb, *sb_next; |
| 1974 | struct lpfc_iocbq *io, *io_next; |
| 1975 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1976 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1977 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
| 1978 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { |
| 1979 | list_del(&sb->list); |
| 1980 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1981 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1982 | kfree(sb); |
| 1983 | phba->total_scsi_bufs--; |
| 1984 | } |
| 1985 | |
| 1986 | /* Release all the lpfc_iocbq entries maintained by this host. */ |
| 1987 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { |
| 1988 | list_del(&io->list); |
| 1989 | kfree(io); |
| 1990 | phba->total_iocbq_bufs--; |
| 1991 | } |
| 1992 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1993 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1994 | |
| 1995 | return 0; |
| 1996 | } |
| 1997 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1998 | /** |
| 1999 | * lpfc_create_port: Create an FC port. |
| 2000 | * @phba: pointer to lpfc hba data structure. |
| 2001 | * @instance: a unique integer ID to this FC port. |
| 2002 | * @dev: pointer to the device data structure. |
| 2003 | * |
| 2004 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 2005 | * can be created on top of either a physical port or a virtual port provided |
| 2006 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 2007 | * and associates the FC port created before adding the shost into the SCSI |
| 2008 | * layer. |
| 2009 | * |
| 2010 | * Return codes |
| 2011 | * @vport - pointer to the virtual N_Port data structure. |
| 2012 | * NULL - port create failed. |
| 2013 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2014 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2015 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2016 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2017 | struct lpfc_vport *vport; |
| 2018 | struct Scsi_Host *shost; |
| 2019 | int error = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2020 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2021 | if (dev != &phba->pcidev->dev) |
| 2022 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 2023 | sizeof(struct lpfc_vport)); |
| 2024 | else |
| 2025 | shost = scsi_host_alloc(&lpfc_template, |
| 2026 | sizeof(struct lpfc_vport)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2027 | if (!shost) |
| 2028 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2029 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2030 | vport = (struct lpfc_vport *) shost->hostdata; |
| 2031 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2032 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2033 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 2034 | vport->fc_rscn_flush = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2035 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2036 | lpfc_get_vport_cfgparam(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2037 | shost->unique_id = instance; |
| 2038 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2039 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2040 | shost->this_id = -1; |
| 2041 | shost->max_cmd_len = 16; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2042 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2043 | * Set initial can_queue value since 0 is no longer supported and |
| 2044 | * scsi_add_host will fail. This will be adjusted later based on the |
| 2045 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2046 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2047 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2048 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2049 | shost->transportt = lpfc_vport_transport_template; |
| 2050 | vport->port_type = LPFC_NPIV_PORT; |
| 2051 | } else { |
| 2052 | shost->transportt = lpfc_transport_template; |
| 2053 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 2054 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2055 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2056 | /* Initialize all internally managed lists. */ |
| 2057 | INIT_LIST_HEAD(&vport->fc_nodes); |
| 2058 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2059 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2060 | init_timer(&vport->fc_disctmo); |
| 2061 | vport->fc_disctmo.function = lpfc_disc_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2062 | vport->fc_disctmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2063 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2064 | init_timer(&vport->fc_fdmitmo); |
| 2065 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2066 | vport->fc_fdmitmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2067 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2068 | init_timer(&vport->els_tmofunc); |
| 2069 | vport->els_tmofunc.function = lpfc_els_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2070 | vport->els_tmofunc.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2071 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2072 | error = scsi_add_host(shost, dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2073 | if (error) |
| 2074 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2075 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2076 | spin_lock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2077 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2078 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2079 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2080 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2081 | out_put_shost: |
| 2082 | scsi_host_put(shost); |
| 2083 | out: |
| 2084 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2085 | } |
| 2086 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2087 | /** |
| 2088 | * destroy_port: Destroy an FC port. |
| 2089 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 2090 | * |
| 2091 | * This routine destroys a FC port from the upper layer protocol. All the |
| 2092 | * resources associated with the port are released. |
| 2093 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2094 | void |
| 2095 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2096 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2097 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2098 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2099 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2100 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2101 | fc_remove_host(shost); |
| 2102 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2103 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2104 | spin_lock_irq(&phba->hbalock); |
| 2105 | list_del_init(&vport->listentry); |
| 2106 | spin_unlock_irq(&phba->hbalock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2107 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2108 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2109 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2110 | } |
| 2111 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2112 | /** |
| 2113 | * lpfc_get_instance: Get a unique integer ID. |
| 2114 | * |
| 2115 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 2116 | * uses the kernel idr facility to perform the task. |
| 2117 | * |
| 2118 | * Return codes: |
| 2119 | * instance - a unique integer ID allocated as the new instance. |
| 2120 | * -1 - lpfc get instance failed. |
| 2121 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2122 | int |
| 2123 | lpfc_get_instance(void) |
| 2124 | { |
| 2125 | int instance = 0; |
| 2126 | |
| 2127 | /* Assign an unused number */ |
| 2128 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) |
| 2129 | return -1; |
| 2130 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) |
| 2131 | return -1; |
| 2132 | return instance; |
| 2133 | } |
| 2134 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2135 | /** |
| 2136 | * lpfc_scan_finished: method for SCSI layer to detect whether scan is done. |
| 2137 | * @shost: pointer to SCSI host data structure. |
| 2138 | * @time: elapsed time of the scan in jiffies. |
| 2139 | * |
| 2140 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 2141 | * whether the scan host is finished. |
| 2142 | * |
| 2143 | * Note: there is no scan_start function as adapter initialization will have |
| 2144 | * asynchronously kicked off the link initialization. |
| 2145 | * |
| 2146 | * Return codes |
| 2147 | * 0 - SCSI host scan is not over yet. |
| 2148 | * 1 - SCSI host scan is over. |
| 2149 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2150 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 2151 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2152 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2153 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2154 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2155 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2156 | spin_lock_irq(shost->host_lock); |
| 2157 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2158 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2159 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2160 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2161 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2162 | if (time >= 30 * HZ) { |
| 2163 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2164 | "0461 Scanning longer than 30 " |
| 2165 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2166 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2167 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2168 | } |
| 2169 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { |
| 2170 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2171 | "0465 Link down longer than 15 " |
| 2172 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2173 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2174 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2175 | } |
| 2176 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2177 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2178 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2179 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2180 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2181 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2182 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2183 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2184 | goto finished; |
| 2185 | |
| 2186 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2187 | |
| 2188 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2189 | spin_unlock_irq(shost->host_lock); |
| 2190 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2191 | } |
| 2192 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2193 | /** |
| 2194 | * lpfc_host_attrib_init: Initialize SCSI host attributes on a FC port. |
| 2195 | * @shost: pointer to SCSI host data structure. |
| 2196 | * |
| 2197 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 2198 | * SCSI host can be either on top of a physical port or a virtual port. |
| 2199 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2200 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 2201 | { |
| 2202 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2203 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2204 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2205 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2206 | */ |
| 2207 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2208 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 2209 | 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] | 2210 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 2211 | |
| 2212 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2213 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2214 | fc_host_supported_fc4s(shost)[2] = 1; |
| 2215 | fc_host_supported_fc4s(shost)[7] = 1; |
| 2216 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2217 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 2218 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2219 | |
| 2220 | fc_host_supported_speeds(shost) = 0; |
| 2221 | if (phba->lmt & LMT_10Gb) |
| 2222 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2223 | if (phba->lmt & LMT_8Gb) |
| 2224 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2225 | if (phba->lmt & LMT_4Gb) |
| 2226 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 2227 | if (phba->lmt & LMT_2Gb) |
| 2228 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 2229 | if (phba->lmt & LMT_1Gb) |
| 2230 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 2231 | |
| 2232 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2233 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 2234 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2235 | |
| 2236 | /* This value is also unchanging */ |
| 2237 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2238 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2239 | fc_host_active_fc4s(shost)[2] = 1; |
| 2240 | fc_host_active_fc4s(shost)[7] = 1; |
| 2241 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2242 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2243 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2244 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2245 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2246 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2247 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2248 | /** |
| 2249 | * lpfc_enable_msix: Enable MSI-X interrupt mode. |
| 2250 | * @phba: pointer to lpfc hba data structure. |
| 2251 | * |
| 2252 | * This routine is invoked to enable the MSI-X interrupt vectors. The kernel |
| 2253 | * function pci_enable_msix() is called to enable the MSI-X vectors. Note that |
| 2254 | * pci_enable_msix(), once invoked, enables either all or nothing, depending |
| 2255 | * on the current availability of PCI vector resources. The device driver is |
| 2256 | * responsible for calling the individual request_irq() to register each MSI-X |
| 2257 | * vector with a interrupt handler, which is done in this function. Note that |
| 2258 | * later when device is unloading, the driver should always call free_irq() |
| 2259 | * on all MSI-X vectors it has done request_irq() on before calling |
| 2260 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device |
| 2261 | * will be left with MSI-X enabled and leaks its vectors. |
| 2262 | * |
| 2263 | * Return codes |
| 2264 | * 0 - sucessful |
| 2265 | * other values - error |
| 2266 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2267 | static int |
| 2268 | lpfc_enable_msix(struct lpfc_hba *phba) |
| 2269 | { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2270 | int rc, i; |
| 2271 | LPFC_MBOXQ_t *pmb; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2272 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2273 | /* Set up MSI-X multi-message vectors */ |
| 2274 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 2275 | phba->msix_entries[i].entry = i; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2276 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2277 | /* Configure MSI-X capability structure */ |
| 2278 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2279 | ARRAY_SIZE(phba->msix_entries)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2280 | if (rc) { |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2281 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2282 | "0420 Enable MSI-X failed (%d), continuing " |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2283 | "with MSI\n", rc); |
| 2284 | goto msi_fail_out; |
| 2285 | } else |
| 2286 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 2287 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2288 | "0477 MSI-X entry[%d]: vector=x%x " |
| 2289 | "message=%d\n", i, |
| 2290 | phba->msix_entries[i].vector, |
| 2291 | phba->msix_entries[i].entry); |
| 2292 | /* |
| 2293 | * Assign MSI-X vectors to interrupt handlers |
| 2294 | */ |
| 2295 | |
| 2296 | /* vector-0 is associated to slow-path handler */ |
| 2297 | rc = request_irq(phba->msix_entries[0].vector, &lpfc_sp_intr_handler, |
| 2298 | IRQF_SHARED, LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 2299 | if (rc) { |
| 2300 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2301 | "0421 MSI-X slow-path request_irq failed " |
| 2302 | "(%d), continuing with MSI\n", rc); |
| 2303 | goto msi_fail_out; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2304 | } |
| 2305 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2306 | /* vector-1 is associated to fast-path handler */ |
| 2307 | rc = request_irq(phba->msix_entries[1].vector, &lpfc_fp_intr_handler, |
| 2308 | IRQF_SHARED, LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 2309 | |
| 2310 | if (rc) { |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2311 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2312 | "0429 MSI-X fast-path request_irq failed " |
| 2313 | "(%d), continuing with MSI\n", rc); |
| 2314 | goto irq_fail_out; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2315 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2316 | |
| 2317 | /* |
| 2318 | * Configure HBA MSI-X attention conditions to messages |
| 2319 | */ |
| 2320 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2321 | |
| 2322 | if (!pmb) { |
| 2323 | rc = -ENOMEM; |
| 2324 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2325 | "0474 Unable to allocate memory for issuing " |
| 2326 | "MBOX_CONFIG_MSI command\n"); |
| 2327 | goto mem_fail_out; |
| 2328 | } |
| 2329 | rc = lpfc_config_msi(phba, pmb); |
| 2330 | if (rc) |
| 2331 | goto mbx_fail_out; |
| 2332 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 2333 | if (rc != MBX_SUCCESS) { |
| 2334 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 2335 | "0351 Config MSI mailbox command failed, " |
| 2336 | "mbxCmd x%x, mbxStatus x%x\n", |
| 2337 | pmb->mb.mbxCommand, pmb->mb.mbxStatus); |
| 2338 | goto mbx_fail_out; |
| 2339 | } |
| 2340 | |
| 2341 | /* Free memory allocated for mailbox command */ |
| 2342 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2343 | return rc; |
| 2344 | |
| 2345 | mbx_fail_out: |
| 2346 | /* Free memory allocated for mailbox command */ |
| 2347 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2348 | |
| 2349 | mem_fail_out: |
| 2350 | /* free the irq already requested */ |
| 2351 | free_irq(phba->msix_entries[1].vector, phba); |
| 2352 | |
| 2353 | irq_fail_out: |
| 2354 | /* free the irq already requested */ |
| 2355 | free_irq(phba->msix_entries[0].vector, phba); |
| 2356 | |
| 2357 | msi_fail_out: |
| 2358 | /* Unconfigure MSI-X capability structure */ |
| 2359 | pci_disable_msix(phba->pcidev); |
| 2360 | return rc; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2361 | } |
| 2362 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2363 | /** |
| 2364 | * lpfc_disable_msix: Disable MSI-X interrupt mode. |
| 2365 | * @phba: pointer to lpfc hba data structure. |
| 2366 | * |
| 2367 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 2368 | * MSI-X interrupt mode. |
| 2369 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2370 | static void |
| 2371 | lpfc_disable_msix(struct lpfc_hba *phba) |
| 2372 | { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2373 | int i; |
| 2374 | |
| 2375 | /* Free up MSI-X multi-message vectors */ |
| 2376 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 2377 | free_irq(phba->msix_entries[i].vector, phba); |
| 2378 | /* Disable MSI-X */ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2379 | pci_disable_msix(phba->pcidev); |
| 2380 | } |
| 2381 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2382 | /** |
| 2383 | * lpfc_pci_probe_one: lpfc PCI probe func to register device to PCI subsystem. |
| 2384 | * @pdev: pointer to PCI device |
| 2385 | * @pid: pointer to PCI device identifier |
| 2386 | * |
| 2387 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 2388 | * Emulex HBA is presented in PCI bus, the kernel PCI subsystem looks at |
| 2389 | * PCI device-specific information of the device and driver to see if the |
| 2390 | * driver state that it can support this kind of device. If the match is |
| 2391 | * successful, the driver core invokes this routine. If this routine |
| 2392 | * determines it can claim the HBA, it does all the initialization that it |
| 2393 | * needs to do to handle the HBA properly. |
| 2394 | * |
| 2395 | * Return code |
| 2396 | * 0 - driver can claim the device |
| 2397 | * negative value - driver can not claim the device |
| 2398 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2399 | static int __devinit |
| 2400 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 2401 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2402 | struct lpfc_vport *vport = NULL; |
| 2403 | struct lpfc_hba *phba; |
| 2404 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2405 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2406 | struct Scsi_Host *shost = NULL; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2407 | void *ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2408 | unsigned long bar0map_len, bar2map_len; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2409 | int error = -ENODEV, retval; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2410 | int i, hbq_count; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2411 | uint16_t iotag; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2412 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2413 | struct lpfc_adapter_event_header adapter_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2414 | |
Greg Kroah-Hartman | d5f78fb | 2008-02-02 12:13:22 +0100 | [diff] [blame] | 2415 | if (pci_enable_device_mem(pdev)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2416 | goto out; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2417 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2418 | goto out_disable_device; |
| 2419 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2420 | phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL); |
| 2421 | if (!phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2422 | goto out_release_regions; |
| 2423 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2424 | atomic_set(&phba->fast_event_count, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2425 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2426 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2427 | /* Initialize ndlp management spinlock */ |
| 2428 | spin_lock_init(&phba->ndlp_lock); |
| 2429 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2430 | phba->pcidev = pdev; |
| 2431 | |
| 2432 | /* Assign an unused board number */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2433 | if ((phba->brd_no = lpfc_get_instance()) < 0) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2434 | goto out_free_phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2435 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2436 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2437 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2438 | /* |
| 2439 | * Get all the module params for configuring this host and then |
| 2440 | * establish the host. |
| 2441 | */ |
| 2442 | lpfc_get_cfgparam(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2443 | phba->max_vpi = LPFC_MAX_VPI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2444 | |
| 2445 | /* Initialize timers used by driver */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2446 | init_timer(&phba->hb_tmofunc); |
| 2447 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 2448 | phba->hb_tmofunc.data = (unsigned long)phba; |
| 2449 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2450 | psli = &phba->sli; |
| 2451 | init_timer(&psli->mbox_tmo); |
| 2452 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2453 | psli->mbox_tmo.data = (unsigned long) phba; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2454 | init_timer(&phba->fcp_poll_timer); |
| 2455 | phba->fcp_poll_timer.function = lpfc_poll_timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2456 | phba->fcp_poll_timer.data = (unsigned long) phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2457 | init_timer(&phba->fabric_block_timer); |
| 2458 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 2459 | phba->fabric_block_timer.data = (unsigned long) phba; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2460 | init_timer(&phba->eratt_poll); |
| 2461 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 2462 | phba->eratt_poll.data = (unsigned long) phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2463 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2464 | pci_set_master(pdev); |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame^] | 2465 | pci_save_state(pdev); |
Randy Dunlap | 694625c | 2007-07-09 11:55:54 -0700 | [diff] [blame] | 2466 | pci_try_set_mwi(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2467 | |
| 2468 | if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0) |
| 2469 | if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0) |
| 2470 | goto out_idr_remove; |
| 2471 | |
| 2472 | /* |
| 2473 | * Get the bus address of Bar0 and Bar2 and the number of bytes |
| 2474 | * required by each mapping. |
| 2475 | */ |
| 2476 | phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0); |
| 2477 | bar0map_len = pci_resource_len(phba->pcidev, 0); |
| 2478 | |
| 2479 | phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2); |
| 2480 | bar2map_len = pci_resource_len(phba->pcidev, 2); |
| 2481 | |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2482 | /* Map HBA SLIM to a kernel virtual address. */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2483 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2484 | if (!phba->slim_memmap_p) { |
| 2485 | error = -ENODEV; |
| 2486 | dev_printk(KERN_ERR, &pdev->dev, |
| 2487 | "ioremap failed for SLIM memory.\n"); |
| 2488 | goto out_idr_remove; |
| 2489 | } |
| 2490 | |
| 2491 | /* Map HBA Control Registers to a kernel virtual address. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2492 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2493 | if (!phba->ctrl_regs_memmap_p) { |
| 2494 | error = -ENODEV; |
| 2495 | dev_printk(KERN_ERR, &pdev->dev, |
| 2496 | "ioremap failed for HBA control registers.\n"); |
| 2497 | goto out_iounmap_slim; |
| 2498 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2499 | |
| 2500 | /* Allocate memory for SLI-2 structures */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2501 | phba->slim2p.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 2502 | SLI2_SLIM_SIZE, |
| 2503 | &phba->slim2p.phys, |
| 2504 | GFP_KERNEL); |
| 2505 | if (!phba->slim2p.virt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2506 | goto out_iounmap; |
| 2507 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2508 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2509 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
| 2510 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 2511 | phba->IOCBs = (phba->slim2p.virt + |
| 2512 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2513 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2514 | phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 2515 | lpfc_sli_hbq_size(), |
| 2516 | &phba->hbqslimp.phys, |
| 2517 | GFP_KERNEL); |
| 2518 | if (!phba->hbqslimp.virt) |
| 2519 | goto out_free_slim; |
| 2520 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2521 | hbq_count = lpfc_sli_hbq_count(); |
| 2522 | ptr = phba->hbqslimp.virt; |
| 2523 | for (i = 0; i < hbq_count; ++i) { |
| 2524 | phba->hbqs[i].hbq_virt = ptr; |
| 2525 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 2526 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 2527 | sizeof(struct lpfc_hbq_entry)); |
| 2528 | } |
| 2529 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 2530 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 2531 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2532 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 2533 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2534 | INIT_LIST_HEAD(&phba->hbqbuf_in_list); |
| 2535 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2536 | /* Initialize the SLI Layer to run with lpfc HBAs. */ |
| 2537 | lpfc_sli_setup(phba); |
| 2538 | lpfc_sli_queue_setup(phba); |
| 2539 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2540 | retval = lpfc_mem_alloc(phba); |
| 2541 | if (retval) { |
| 2542 | error = retval; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2543 | goto out_free_hbqslimp; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2544 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2545 | |
| 2546 | /* Initialize and populate the iocb list per host. */ |
| 2547 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
| 2548 | for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 2549 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2550 | if (iocbq_entry == NULL) { |
| 2551 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 2552 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2553 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2554 | error = -ENOMEM; |
| 2555 | goto out_free_iocbq; |
| 2556 | } |
| 2557 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2558 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 2559 | if (iotag == 0) { |
| 2560 | kfree (iocbq_entry); |
| 2561 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
| 2562 | "Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2563 | __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2564 | error = -ENOMEM; |
| 2565 | goto out_free_iocbq; |
| 2566 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2567 | |
| 2568 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2569 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 2570 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2571 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | /* Initialize HBA structure */ |
| 2575 | phba->fc_edtov = FF_DEF_EDTOV; |
| 2576 | phba->fc_ratov = FF_DEF_RATOV; |
| 2577 | phba->fc_altov = FF_DEF_ALTOV; |
| 2578 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 2579 | |
| 2580 | INIT_LIST_HEAD(&phba->work_list); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2581 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2582 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 2583 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2584 | /* Initialize the wait queue head for the kernel thread */ |
| 2585 | init_waitqueue_head(&phba->work_waitq); |
| 2586 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2587 | /* Startup the kernel thread for this host adapter. */ |
| 2588 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 2589 | "lpfc_worker_%d", phba->brd_no); |
| 2590 | if (IS_ERR(phba->worker_thread)) { |
| 2591 | error = PTR_ERR(phba->worker_thread); |
| 2592 | goto out_free_iocbq; |
| 2593 | } |
| 2594 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2595 | /* Initialize the list of scsi buffers used by driver for scsi IO. */ |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2596 | spin_lock_init(&phba->scsi_buf_list_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2597 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); |
| 2598 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2599 | /* Initialize list of fabric iocbs */ |
| 2600 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| 2601 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2602 | /* Initialize list to save ELS buffers */ |
| 2603 | INIT_LIST_HEAD(&phba->elsbuf); |
| 2604 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2605 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2606 | if (!vport) |
| 2607 | goto out_kthread_stop; |
| 2608 | |
| 2609 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2610 | phba->pport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2611 | lpfc_debugfs_initialize(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2612 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2613 | pci_set_drvdata(pdev, shost); |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2614 | phba->intr_type = NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2615 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2616 | phba->MBslimaddr = phba->slim_memmap_p; |
| 2617 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 2618 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 2619 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 2620 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
| 2621 | |
| 2622 | /* Configure and enable interrupt */ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2623 | if (phba->cfg_use_msi == 2) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2624 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 2625 | error = lpfc_sli_config_port(phba, 3); |
| 2626 | if (error) |
| 2627 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2628 | "0427 Firmware not capable of SLI 3 mode.\n"); |
| 2629 | else { |
| 2630 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2631 | "0426 Firmware capable of SLI 3 mode.\n"); |
| 2632 | /* Now, try to enable MSI-X interrupt mode */ |
| 2633 | error = lpfc_enable_msix(phba); |
| 2634 | if (!error) { |
| 2635 | phba->intr_type = MSIX; |
| 2636 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2637 | "0430 enable MSI-X mode.\n"); |
| 2638 | } |
| 2639 | } |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2640 | } |
| 2641 | |
| 2642 | /* Fallback to MSI if MSI-X initialization failed */ |
| 2643 | if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2644 | retval = pci_enable_msi(phba->pcidev); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2645 | if (!retval) { |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2646 | phba->intr_type = MSI; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2647 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2648 | "0473 enable MSI mode.\n"); |
| 2649 | } else |
| 2650 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2651 | "0452 enable IRQ mode.\n"); |
James Smart | 4ff4324 | 2006-12-02 13:34:56 -0500 | [diff] [blame] | 2652 | } |
| 2653 | |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2654 | /* MSI-X is the only case the doesn't need to call request_irq */ |
| 2655 | if (phba->intr_type != MSIX) { |
| 2656 | retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, |
| 2657 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 2658 | if (retval) { |
| 2659 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0451 Enable " |
| 2660 | "interrupt handler failed\n"); |
| 2661 | error = retval; |
| 2662 | goto out_disable_msi; |
| 2663 | } else if (phba->intr_type != MSI) |
| 2664 | phba->intr_type = INTx; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2665 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2666 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2667 | if (lpfc_alloc_sysfs_attr(vport)) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2668 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2669 | "1476 Failed to allocate sysfs attr\n"); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2670 | error = -ENOMEM; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2671 | goto out_free_irq; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2672 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2673 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2674 | if (lpfc_sli_hba_setup(phba)) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2675 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2676 | "1477 Failed to set up hba\n"); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2677 | error = -ENODEV; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2678 | goto out_remove_device; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2679 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2680 | |
| 2681 | /* |
| 2682 | * hba setup may have changed the hba_queue_depth so we need to adjust |
| 2683 | * the value of can_queue. |
| 2684 | */ |
| 2685 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 2686 | |
| 2687 | lpfc_host_attrib_init(shost); |
| 2688 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2689 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 2690 | spin_lock_irq(shost->host_lock); |
| 2691 | lpfc_poll_start_timer(phba); |
| 2692 | spin_unlock_irq(shost->host_lock); |
| 2693 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 2694 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2695 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2696 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2697 | /* Send board arrival event to upper layer */ |
| 2698 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 2699 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 2700 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 2701 | sizeof(adapter_event), |
| 2702 | (char *) &adapter_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 2703 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2704 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2705 | scsi_scan_host(shost); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2706 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2707 | return 0; |
| 2708 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2709 | out_remove_device: |
| 2710 | lpfc_free_sysfs_attr(vport); |
| 2711 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2712 | vport->load_flag |= FC_UNLOADING; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2713 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2714 | out_free_irq: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2715 | lpfc_stop_phba_timers(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2716 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2717 | |
| 2718 | if (phba->intr_type == MSIX) |
| 2719 | lpfc_disable_msix(phba); |
| 2720 | else |
| 2721 | free_irq(phba->pcidev->irq, phba); |
| 2722 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2723 | out_disable_msi: |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2724 | if (phba->intr_type == MSI) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2725 | pci_disable_msi(phba->pcidev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2726 | destroy_port(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2727 | out_kthread_stop: |
| 2728 | kthread_stop(phba->worker_thread); |
| 2729 | out_free_iocbq: |
| 2730 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 2731 | &phba->lpfc_iocb_list, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2732 | kfree(iocbq_entry); |
| 2733 | phba->total_iocbq_bufs--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2734 | } |
| 2735 | lpfc_mem_free(phba); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2736 | out_free_hbqslimp: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2737 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 2738 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2739 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2740 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 2741 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2742 | out_iounmap: |
| 2743 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2744 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2745 | iounmap(phba->slim_memmap_p); |
| 2746 | out_idr_remove: |
| 2747 | idr_remove(&lpfc_hba_index, phba->brd_no); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2748 | out_free_phba: |
| 2749 | kfree(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2750 | out_release_regions: |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2751 | pci_release_selected_regions(pdev, bars); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2752 | out_disable_device: |
| 2753 | pci_disable_device(pdev); |
| 2754 | out: |
James Smart | defbcf1 | 2006-04-16 22:26:50 -0400 | [diff] [blame] | 2755 | pci_set_drvdata(pdev, NULL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2756 | if (shost) |
| 2757 | scsi_host_put(shost); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2758 | return error; |
| 2759 | } |
| 2760 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2761 | /** |
| 2762 | * lpfc_pci_remove_one: lpfc PCI func to unregister device from PCI subsystem. |
| 2763 | * @pdev: pointer to PCI device |
| 2764 | * |
| 2765 | * This routine is to be registered to the kernel's PCI subsystem. When an |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 2766 | * Emulex HBA is removed from PCI bus, it performs all the necessary cleanup |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2767 | * for the HBA device to be removed from the PCI subsystem properly. |
| 2768 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2769 | static void __devexit |
| 2770 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 2771 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2772 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2773 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 2774 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2775 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 2776 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2777 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 2778 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2779 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2780 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2781 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2782 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2783 | lpfc_free_sysfs_attr(vport); |
| 2784 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2785 | kthread_stop(phba->worker_thread); |
| 2786 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame] | 2787 | /* Release all the vports against this physical port */ |
| 2788 | vports = lpfc_create_vport_work_array(phba); |
| 2789 | if (vports != NULL) |
| 2790 | for (i = 1; i <= phba->max_vpi && vports[i] != NULL; i++) |
| 2791 | fc_vport_terminate(vports[i]->fc_vport); |
| 2792 | lpfc_destroy_vport_work_array(phba, vports); |
| 2793 | |
| 2794 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2795 | fc_remove_host(shost); |
| 2796 | scsi_remove_host(shost); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2797 | lpfc_cleanup(vport); |
| 2798 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2799 | /* |
| 2800 | * Bring down the SLI Layer. This step disable all interrupts, |
| 2801 | * clears the rings, discards all mailbox commands, and resets |
| 2802 | * the HBA. |
| 2803 | */ |
| 2804 | lpfc_sli_hba_down(phba); |
| 2805 | lpfc_sli_brdrestart(phba); |
| 2806 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2807 | lpfc_stop_phba_timers(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2808 | spin_lock_irq(&phba->hbalock); |
| 2809 | list_del_init(&vport->listentry); |
| 2810 | spin_unlock_irq(&phba->hbalock); |
| 2811 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2812 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2813 | |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2814 | if (phba->intr_type == MSIX) |
| 2815 | lpfc_disable_msix(phba); |
| 2816 | else { |
| 2817 | free_irq(phba->pcidev->irq, phba); |
| 2818 | if (phba->intr_type == MSI) |
| 2819 | pci_disable_msi(phba->pcidev); |
| 2820 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2821 | |
| 2822 | pci_set_drvdata(pdev, NULL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2823 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2824 | |
| 2825 | /* |
| 2826 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 2827 | * corresponding pools here. |
| 2828 | */ |
| 2829 | lpfc_scsi_free(phba); |
| 2830 | lpfc_mem_free(phba); |
| 2831 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2832 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 2833 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2834 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2835 | /* Free resources associated with SLI2 interface */ |
| 2836 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2837 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2838 | |
| 2839 | /* unmap adapter SLIM and Control Registers */ |
| 2840 | iounmap(phba->ctrl_regs_memmap_p); |
| 2841 | iounmap(phba->slim_memmap_p); |
| 2842 | |
| 2843 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 2844 | |
| 2845 | kfree(phba); |
| 2846 | |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2847 | pci_release_selected_regions(pdev, bars); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2848 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2849 | } |
| 2850 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2851 | /** |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 2852 | * lpfc_pci_suspend_one: lpfc PCI func to suspend device for power management. |
| 2853 | * @pdev: pointer to PCI device |
| 2854 | * @msg: power management message |
| 2855 | * |
| 2856 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 2857 | * system Power Management (PM). When PM invokes this method, it quiesces the |
| 2858 | * device by stopping the driver's worker thread for the device, turning off |
| 2859 | * device's interrupt and DMA, and bring the device offline. Note that as the |
| 2860 | * driver implements the minimum PM requirements to a power-aware driver's PM |
| 2861 | * support for suspend/resume -- all the possible PM messages (SUSPEND, |
| 2862 | * HIBERNATE, FREEZE) to the suspend() method call will be treated as SUSPEND |
| 2863 | * and the driver will fully reinitialize its device during resume() method |
| 2864 | * call, the driver will set device to PCI_D3hot state in PCI config space |
| 2865 | * instead of setting it according to the @msg provided by the PM. |
| 2866 | * |
| 2867 | * Return code |
| 2868 | * 0 - driver suspended the device |
| 2869 | * Error otherwise |
| 2870 | **/ |
| 2871 | static int |
| 2872 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 2873 | { |
| 2874 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2875 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 2876 | |
| 2877 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2878 | "0473 PCI device Power Management suspend.\n"); |
| 2879 | |
| 2880 | /* Bring down the device */ |
| 2881 | lpfc_offline_prep(phba); |
| 2882 | lpfc_offline(phba); |
| 2883 | kthread_stop(phba->worker_thread); |
| 2884 | |
| 2885 | /* Disable interrupt from device */ |
| 2886 | lpfc_disable_intr(phba); |
| 2887 | |
| 2888 | /* Save device state to PCI config space */ |
| 2889 | pci_save_state(pdev); |
| 2890 | pci_set_power_state(pdev, PCI_D3hot); |
| 2891 | |
| 2892 | return 0; |
| 2893 | } |
| 2894 | |
| 2895 | /** |
| 2896 | * lpfc_pci_resume_one: lpfc PCI func to resume device for power management. |
| 2897 | * @pdev: pointer to PCI device |
| 2898 | * |
| 2899 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 2900 | * system Power Management (PM). When PM invokes this method, it restores |
| 2901 | * the device's PCI config space state and fully reinitializes the device |
| 2902 | * and brings it online. Note that as the driver implements the minimum PM |
| 2903 | * requirements to a power-aware driver's PM for suspend/resume -- all |
| 2904 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 2905 | * method call will be treated as SUSPEND and the driver will fully |
| 2906 | * reinitialize its device during resume() method call, the device will be |
| 2907 | * set to PCI_D0 directly in PCI config space before restoring the state. |
| 2908 | * |
| 2909 | * Return code |
| 2910 | * 0 - driver suspended the device |
| 2911 | * Error otherwise |
| 2912 | **/ |
| 2913 | static int |
| 2914 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 2915 | { |
| 2916 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2917 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 2918 | int error; |
| 2919 | |
| 2920 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2921 | "0452 PCI device Power Management resume.\n"); |
| 2922 | |
| 2923 | /* Restore device state from PCI config space */ |
| 2924 | pci_set_power_state(pdev, PCI_D0); |
| 2925 | pci_restore_state(pdev); |
| 2926 | if (pdev->is_busmaster) |
| 2927 | pci_set_master(pdev); |
| 2928 | |
| 2929 | /* Startup the kernel thread for this host adapter. */ |
| 2930 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 2931 | "lpfc_worker_%d", phba->brd_no); |
| 2932 | if (IS_ERR(phba->worker_thread)) { |
| 2933 | error = PTR_ERR(phba->worker_thread); |
| 2934 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2935 | "0434 PM resume failed to start worker " |
| 2936 | "thread: error=x%x.\n", error); |
| 2937 | return error; |
| 2938 | } |
| 2939 | |
| 2940 | /* Enable interrupt from device */ |
| 2941 | error = lpfc_enable_intr(phba); |
| 2942 | if (error) { |
| 2943 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2944 | "0430 PM resume Failed to enable interrupt: " |
| 2945 | "error=x%x.\n", error); |
| 2946 | return error; |
| 2947 | } |
| 2948 | |
| 2949 | /* Restart HBA and bring it online */ |
| 2950 | lpfc_sli_brdrestart(phba); |
| 2951 | lpfc_online(phba); |
| 2952 | |
| 2953 | return 0; |
| 2954 | } |
| 2955 | |
| 2956 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2957 | * lpfc_io_error_detected: Driver method for handling PCI I/O error detected. |
| 2958 | * @pdev: pointer to PCI device. |
| 2959 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2960 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2961 | * This routine is registered to the PCI subsystem for error handling. This |
| 2962 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 2963 | * this device has been detected. When this function is invoked, it will |
| 2964 | * need to stop all the I/Os and interrupt(s) to the device. Once that is |
| 2965 | * done, it will return PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to |
| 2966 | * perform proper recovery as desired. |
| 2967 | * |
| 2968 | * Return codes |
| 2969 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 2970 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 2971 | **/ |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2972 | static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev, |
| 2973 | pci_channel_state_t state) |
| 2974 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2975 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2976 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2977 | struct lpfc_sli *psli = &phba->sli; |
| 2978 | struct lpfc_sli_ring *pring; |
| 2979 | |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2980 | if (state == pci_channel_io_perm_failure) { |
| 2981 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2982 | "0472 PCI channel I/O permanent failure\n"); |
| 2983 | /* Block all SCSI devices' I/Os on the host */ |
| 2984 | lpfc_scsi_dev_block(phba); |
| 2985 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 2986 | lpfc_sli_flush_fcp_rings(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2987 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2988 | } |
Linas Vepstas | 5daa49e | 2007-03-08 16:19:11 -0600 | [diff] [blame] | 2989 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2990 | pci_disable_device(pdev); |
| 2991 | /* |
| 2992 | * There may be I/Os dropped by the firmware. |
| 2993 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 2994 | * retry it after re-establishing link. |
| 2995 | */ |
| 2996 | pring = &psli->ring[psli->fcp_ring]; |
| 2997 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 2998 | |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2999 | if (phba->intr_type == MSIX) |
| 3000 | lpfc_disable_msix(phba); |
| 3001 | else { |
| 3002 | free_irq(phba->pcidev->irq, phba); |
| 3003 | if (phba->intr_type == MSI) |
| 3004 | pci_disable_msi(phba->pcidev); |
| 3005 | } |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3006 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3007 | /* Request a slot reset. */ |
| 3008 | return PCI_ERS_RESULT_NEED_RESET; |
| 3009 | } |
| 3010 | |
| 3011 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3012 | * lpfc_io_slot_reset: Restart a PCI device from scratch. |
| 3013 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3014 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3015 | * This routine is registered to the PCI subsystem for error handling. This is |
| 3016 | * called after PCI bus has been reset to restart the PCI card from scratch, |
| 3017 | * as if from a cold-boot. During the PCI subsystem error recovery, after the |
| 3018 | * driver returns PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform |
| 3019 | * proper error recovery and then call this routine before calling the .resume |
| 3020 | * method to recover the device. This function will initialize the HBA device, |
| 3021 | * enable the interrupt, but it will just put the HBA to offline state without |
| 3022 | * passing any I/O traffic. |
| 3023 | * |
| 3024 | * Return codes |
| 3025 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 3026 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3027 | */ |
| 3028 | static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev) |
| 3029 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3030 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 3031 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3032 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 3033 | int error, retval; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3034 | |
| 3035 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 3036 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3037 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 3038 | "PCI device after reset.\n"); |
| 3039 | return PCI_ERS_RESULT_DISCONNECT; |
| 3040 | } |
| 3041 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame^] | 3042 | pci_restore_state(pdev); |
| 3043 | if (pdev->is_busmaster) |
| 3044 | pci_set_master(pdev); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3045 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3046 | spin_lock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3047 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3048 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3049 | |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 3050 | /* Enable configured interrupt method */ |
| 3051 | phba->intr_type = NONE; |
| 3052 | if (phba->cfg_use_msi == 2) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3053 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 3054 | error = lpfc_sli_config_port(phba, 3); |
| 3055 | if (error) |
| 3056 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3057 | "0478 Firmware not capable of SLI 3 mode.\n"); |
| 3058 | else { |
| 3059 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3060 | "0479 Firmware capable of SLI 3 mode.\n"); |
| 3061 | /* Now, try to enable MSI-X interrupt mode */ |
| 3062 | error = lpfc_enable_msix(phba); |
| 3063 | if (!error) { |
| 3064 | phba->intr_type = MSIX; |
| 3065 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3066 | "0480 enable MSI-X mode.\n"); |
| 3067 | } |
| 3068 | } |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 3069 | } |
| 3070 | |
| 3071 | /* Fallback to MSI if MSI-X initialization failed */ |
| 3072 | if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) { |
| 3073 | retval = pci_enable_msi(phba->pcidev); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3074 | if (!retval) { |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 3075 | phba->intr_type = MSI; |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 3076 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3077 | "0481 enable MSI mode.\n"); |
| 3078 | } else |
| 3079 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3080 | "0470 enable IRQ mode.\n"); |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 3081 | } |
| 3082 | |
| 3083 | /* MSI-X is the only case the doesn't need to call request_irq */ |
| 3084 | if (phba->intr_type != MSIX) { |
| 3085 | retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, |
| 3086 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 3087 | if (retval) { |
| 3088 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3089 | "0471 Enable interrupt handler " |
| 3090 | "failed\n"); |
| 3091 | } else if (phba->intr_type != MSI) |
| 3092 | phba->intr_type = INTx; |
| 3093 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3094 | |
| 3095 | /* Take device offline; this will perform cleanup */ |
| 3096 | lpfc_offline(phba); |
| 3097 | lpfc_sli_brdrestart(phba); |
| 3098 | |
| 3099 | return PCI_ERS_RESULT_RECOVERED; |
| 3100 | } |
| 3101 | |
| 3102 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3103 | * lpfc_io_resume: Resume PCI I/O operation. |
| 3104 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3105 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3106 | * This routine is registered to the PCI subsystem for error handling. It is |
| 3107 | * called when kernel error recovery tells the lpfc driver that it is ok to |
| 3108 | * resume normal PCI operation after PCI bus error recovery. After this call, |
| 3109 | * traffic can start to flow from this device again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3110 | */ |
| 3111 | static void lpfc_io_resume(struct pci_dev *pdev) |
| 3112 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3113 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 3114 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3115 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3116 | lpfc_online(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3117 | } |
| 3118 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3119 | static struct pci_device_id lpfc_id_table[] = { |
| 3120 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, |
| 3121 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 3122 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
| 3123 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3124 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
| 3125 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3126 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, |
| 3127 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3128 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, |
| 3129 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3130 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, |
| 3131 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3132 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, |
| 3133 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3134 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, |
| 3135 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3136 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, |
| 3137 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 3138 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
| 3139 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3140 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, |
| 3141 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3142 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, |
| 3143 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3144 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
| 3145 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 3146 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
| 3147 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3148 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, |
| 3149 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3150 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
| 3151 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3152 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, |
| 3153 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3154 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, |
| 3155 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3156 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
| 3157 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 3158 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
| 3159 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3160 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, |
| 3161 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3162 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
| 3163 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3164 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, |
| 3165 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3166 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, |
| 3167 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3168 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, |
| 3169 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3170 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, |
| 3171 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 3172 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
| 3173 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3174 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, |
| 3175 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 3176 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
| 3177 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3178 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, |
| 3179 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3180 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, |
| 3181 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3182 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, |
| 3183 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3184 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, |
| 3185 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3186 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, |
| 3187 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3188 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
| 3189 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3190 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, |
| 3191 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3192 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, |
| 3193 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3194 | { 0 } |
| 3195 | }; |
| 3196 | |
| 3197 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 3198 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3199 | static struct pci_error_handlers lpfc_err_handler = { |
| 3200 | .error_detected = lpfc_io_error_detected, |
| 3201 | .slot_reset = lpfc_io_slot_reset, |
| 3202 | .resume = lpfc_io_resume, |
| 3203 | }; |
| 3204 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3205 | static struct pci_driver lpfc_driver = { |
| 3206 | .name = LPFC_DRIVER_NAME, |
| 3207 | .id_table = lpfc_id_table, |
| 3208 | .probe = lpfc_pci_probe_one, |
| 3209 | .remove = __devexit_p(lpfc_pci_remove_one), |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 3210 | .suspend = lpfc_pci_suspend_one, |
| 3211 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3212 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3213 | }; |
| 3214 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3215 | /** |
| 3216 | * lpfc_init: lpfc module initialization routine. |
| 3217 | * |
| 3218 | * This routine is to be invoked when the lpfc module is loaded into the |
| 3219 | * kernel. The special kernel macro module_init() is used to indicate the |
| 3220 | * role of this routine to the kernel as lpfc module entry point. |
| 3221 | * |
| 3222 | * Return codes |
| 3223 | * 0 - successful |
| 3224 | * -ENOMEM - FC attach transport failed |
| 3225 | * all others - failed |
| 3226 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3227 | static int __init |
| 3228 | lpfc_init(void) |
| 3229 | { |
| 3230 | int error = 0; |
| 3231 | |
| 3232 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3233 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3234 | |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3235 | if (lpfc_enable_npiv) { |
| 3236 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 3237 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| 3238 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3239 | lpfc_transport_template = |
| 3240 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3241 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3242 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3243 | if (lpfc_enable_npiv) { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3244 | lpfc_vport_transport_template = |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3245 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 3246 | if (lpfc_vport_transport_template == NULL) { |
| 3247 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3248 | return -ENOMEM; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3249 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3250 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3251 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3252 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3253 | fc_release_transport(lpfc_transport_template); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3254 | if (lpfc_enable_npiv) |
| 3255 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3256 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3257 | |
| 3258 | return error; |
| 3259 | } |
| 3260 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3261 | /** |
| 3262 | * lpfc_exit: lpfc module removal routine. |
| 3263 | * |
| 3264 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 3265 | * The special kernel macro module_exit() is used to indicate the role of |
| 3266 | * this routine to the kernel as lpfc module exit point. |
| 3267 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3268 | static void __exit |
| 3269 | lpfc_exit(void) |
| 3270 | { |
| 3271 | pci_unregister_driver(&lpfc_driver); |
| 3272 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3273 | if (lpfc_enable_npiv) |
| 3274 | fc_release_transport(lpfc_vport_transport_template); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | module_init(lpfc_init); |
| 3278 | module_exit(lpfc_exit); |
| 3279 | MODULE_LICENSE("GPL"); |
| 3280 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
| 3281 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); |
| 3282 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |