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