| 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, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 836 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 837 | |
James Smart | 97eab63 | 2008-04-07 10:16:05 -0400 | [diff] [blame] | 838 | if (phba->work_hs & HS_FFER6) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 839 | /* Re-establishing Link */ |
| 840 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 841 | "1301 Re-establishing Link " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 842 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 843 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 844 | phba->work_status[0], phba->work_status[1]); |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 845 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 846 | spin_lock_irq(&phba->hbalock); |
James Smart | 9290831 | 2006-03-07 15:04:13 -0500 | [diff] [blame] | 847 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 848 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 849 | |
| 850 | /* |
| 851 | * Firmware stops when it triggled erratt with HS_FFER6. |
| 852 | * That could cause the I/Os dropped by the firmware. |
| 853 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 854 | * retry it after re-establishing link. |
| 855 | */ |
| 856 | pring = &psli->ring[psli->fcp_ring]; |
| 857 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 858 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 859 | /* |
| 860 | * There was a firmware error. Take the hba offline and then |
| 861 | * attempt to restart it. |
| 862 | */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 863 | lpfc_offline_prep(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 864 | lpfc_offline(phba); |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 865 | lpfc_sli_brdrestart(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 866 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 867 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 868 | return; |
| 869 | } |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 870 | lpfc_unblock_mgmt_io(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 871 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
| 872 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); |
| 873 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
| 874 | temp_event_data.event_code = LPFC_CRIT_TEMP; |
| 875 | temp_event_data.data = (uint32_t)temperature; |
| 876 | |
| 877 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 878 | "0406 Adapter maximum temperature exceeded " |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 879 | "(%ld), taking this port offline " |
| 880 | "Data: x%x x%x x%x\n", |
| 881 | temperature, phba->work_hs, |
| 882 | phba->work_status[0], phba->work_status[1]); |
| 883 | |
| 884 | shost = lpfc_shost_from_vport(phba->pport); |
| 885 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 886 | sizeof(temp_event_data), |
| 887 | (char *) &temp_event_data, |
| 888 | SCSI_NL_VID_TYPE_PCI |
| 889 | | PCI_VENDOR_ID_EMULEX); |
| 890 | |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 891 | spin_lock_irq(&phba->hbalock); |
James Smart | 7af6705 | 2007-10-27 13:38:11 -0400 | [diff] [blame] | 892 | phba->over_temp_state = HBA_OVER_TEMP; |
| 893 | spin_unlock_irq(&phba->hbalock); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 894 | lpfc_offline_eratt(phba); |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 895 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 896 | } else { |
| 897 | /* The if clause above forces this code path when the status |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 898 | * failure is a value other than FFER6. Do not call the offline |
| 899 | * twice. This is the adapter hardware error path. |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 900 | */ |
| 901 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 902 | "0457 Adapter Hardware Error " |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 903 | "Data: x%x x%x x%x\n", |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 904 | phba->work_hs, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 905 | phba->work_status[0], phba->work_status[1]); |
| 906 | |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 907 | event_data = FC_REG_DUMP_EVENT; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 908 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 909 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
James Smart | d2873e4 | 2006-08-18 17:46:43 -0400 | [diff] [blame] | 910 | sizeof(event_data), (char *) &event_data, |
| 911 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); |
| 912 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 913 | lpfc_offline_eratt(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 914 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 915 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 916 | } |
| 917 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 918 | /** |
| 919 | * lpfc_handle_latt: The HBA link event handler. |
| 920 | * @phba: pointer to lpfc hba data structure. |
| 921 | * |
| 922 | * This routine is invoked from the worker thread to handle a HBA host |
| 923 | * attention link event. |
| 924 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 925 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 926 | lpfc_handle_latt(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 927 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 928 | struct lpfc_vport *vport = phba->pport; |
| 929 | struct lpfc_sli *psli = &phba->sli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 930 | LPFC_MBOXQ_t *pmb; |
| 931 | volatile uint32_t control; |
| 932 | struct lpfc_dmabuf *mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 933 | int rc = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 934 | |
| 935 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 936 | if (!pmb) { |
| 937 | rc = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 938 | goto lpfc_handle_latt_err_exit; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 939 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 940 | |
| 941 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 942 | if (!mp) { |
| 943 | rc = 2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 944 | goto lpfc_handle_latt_free_pmb; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 945 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 946 | |
| 947 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 948 | if (!mp->virt) { |
| 949 | rc = 3; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 950 | goto lpfc_handle_latt_free_mp; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 951 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 952 | |
James.Smart@Emulex.Com | 6281bfe | 2005-11-28 11:41:33 -0500 | [diff] [blame] | 953 | /* Cleanup any outstanding ELS commands */ |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 954 | lpfc_els_flush_all_cmd(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 955 | |
| 956 | psli->slistat.link_event++; |
| 957 | lpfc_read_la(phba, pmb, mp); |
| 958 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 959 | pmb->vport = vport; |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 960 | /* Block ELS IOCBs until we have processed this mbox command */ |
| 961 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
James Smart | 0b727fe | 2007-10-27 13:37:25 -0400 | [diff] [blame] | 962 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 963 | if (rc == MBX_NOT_FINISHED) { |
| 964 | rc = 4; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 965 | goto lpfc_handle_latt_free_mbuf; |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 966 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 967 | |
| 968 | /* Clear Link Attention in HA REG */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 969 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 970 | writel(HA_LATT, phba->HAregaddr); |
| 971 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 972 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 973 | |
| 974 | return; |
| 975 | |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 976 | lpfc_handle_latt_free_mbuf: |
James Smart | 0d2b6b8 | 2008-06-14 22:52:47 -0400 | [diff] [blame] | 977 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
James Smart | 1469115 | 2006-12-02 13:34:28 -0500 | [diff] [blame] | 978 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 979 | lpfc_handle_latt_free_mp: |
| 980 | kfree(mp); |
| 981 | lpfc_handle_latt_free_pmb: |
James Smart | 1dcb58e | 2007-04-25 09:51:30 -0400 | [diff] [blame] | 982 | mempool_free(pmb, phba->mbox_mem_pool); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 983 | lpfc_handle_latt_err_exit: |
| 984 | /* Enable Link attention interrupts */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 985 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 986 | psli->sli_flag |= LPFC_PROCESS_LA; |
| 987 | control = readl(phba->HCregaddr); |
| 988 | control |= HC_LAINT_ENA; |
| 989 | writel(control, phba->HCregaddr); |
| 990 | readl(phba->HCregaddr); /* flush */ |
| 991 | |
| 992 | /* Clear Link Attention in HA REG */ |
| 993 | writel(HA_LATT, phba->HAregaddr); |
| 994 | readl(phba->HAregaddr); /* flush */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 995 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 996 | lpfc_linkdown(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 997 | phba->link_state = LPFC_HBA_ERROR; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 998 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 999 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1000 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1001 | |
| 1002 | return; |
| 1003 | } |
| 1004 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1005 | /** |
| 1006 | * lpfc_parse_vpd: Parse VPD (Vital Product Data). |
| 1007 | * @phba: pointer to lpfc hba data structure. |
| 1008 | * @vpd: pointer to the vital product data. |
| 1009 | * @len: length of the vital product data in bytes. |
| 1010 | * |
| 1011 | * This routine parses the Vital Product Data (VPD). The VPD is treated as |
| 1012 | * an array of characters. In this routine, the ModelName, ProgramType, and |
| 1013 | * ModelDesc, etc. fields of the phba data structure will be populated. |
| 1014 | * |
| 1015 | * Return codes |
| 1016 | * 0 - pointer to the VPD passed in is NULL |
| 1017 | * 1 - success |
| 1018 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1019 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1020 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1021 | { |
| 1022 | uint8_t lenlo, lenhi; |
Anton Blanchard | 07da60c | 2007-03-21 08:41:47 -0500 | [diff] [blame] | 1023 | int Length; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1024 | int i, j; |
| 1025 | int finished = 0; |
| 1026 | int index = 0; |
| 1027 | |
| 1028 | if (!vpd) |
| 1029 | return 0; |
| 1030 | |
| 1031 | /* Vital Product */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1032 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1033 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1034 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
| 1035 | (uint32_t) vpd[3]); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1036 | while (!finished && (index < (len - 4))) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1037 | switch (vpd[index]) { |
| 1038 | case 0x82: |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1039 | case 0x91: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1040 | index += 1; |
| 1041 | lenlo = vpd[index]; |
| 1042 | index += 1; |
| 1043 | lenhi = vpd[index]; |
| 1044 | index += 1; |
| 1045 | i = ((((unsigned short)lenhi) << 8) + lenlo); |
| 1046 | index += i; |
| 1047 | break; |
| 1048 | case 0x90: |
| 1049 | index += 1; |
| 1050 | lenlo = vpd[index]; |
| 1051 | index += 1; |
| 1052 | lenhi = vpd[index]; |
| 1053 | index += 1; |
| 1054 | Length = ((((unsigned short)lenhi) << 8) + lenlo); |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1055 | if (Length > len - index) |
| 1056 | Length = len - index; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1057 | while (Length > 0) { |
| 1058 | /* Look for Serial Number */ |
| 1059 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { |
| 1060 | index += 2; |
| 1061 | i = vpd[index]; |
| 1062 | index += 1; |
| 1063 | j = 0; |
| 1064 | Length -= (3+i); |
| 1065 | while(i--) { |
| 1066 | phba->SerialNumber[j++] = vpd[index++]; |
| 1067 | if (j == 31) |
| 1068 | break; |
| 1069 | } |
| 1070 | phba->SerialNumber[j] = 0; |
| 1071 | continue; |
| 1072 | } |
| 1073 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { |
| 1074 | phba->vpd_flag |= VPD_MODEL_DESC; |
| 1075 | index += 2; |
| 1076 | i = vpd[index]; |
| 1077 | index += 1; |
| 1078 | j = 0; |
| 1079 | Length -= (3+i); |
| 1080 | while(i--) { |
| 1081 | phba->ModelDesc[j++] = vpd[index++]; |
| 1082 | if (j == 255) |
| 1083 | break; |
| 1084 | } |
| 1085 | phba->ModelDesc[j] = 0; |
| 1086 | continue; |
| 1087 | } |
| 1088 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { |
| 1089 | phba->vpd_flag |= VPD_MODEL_NAME; |
| 1090 | index += 2; |
| 1091 | i = vpd[index]; |
| 1092 | index += 1; |
| 1093 | j = 0; |
| 1094 | Length -= (3+i); |
| 1095 | while(i--) { |
| 1096 | phba->ModelName[j++] = vpd[index++]; |
| 1097 | if (j == 79) |
| 1098 | break; |
| 1099 | } |
| 1100 | phba->ModelName[j] = 0; |
| 1101 | continue; |
| 1102 | } |
| 1103 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { |
| 1104 | phba->vpd_flag |= VPD_PROGRAM_TYPE; |
| 1105 | index += 2; |
| 1106 | i = vpd[index]; |
| 1107 | index += 1; |
| 1108 | j = 0; |
| 1109 | Length -= (3+i); |
| 1110 | while(i--) { |
| 1111 | phba->ProgramType[j++] = vpd[index++]; |
| 1112 | if (j == 255) |
| 1113 | break; |
| 1114 | } |
| 1115 | phba->ProgramType[j] = 0; |
| 1116 | continue; |
| 1117 | } |
| 1118 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { |
| 1119 | phba->vpd_flag |= VPD_PORT; |
| 1120 | index += 2; |
| 1121 | i = vpd[index]; |
| 1122 | index += 1; |
| 1123 | j = 0; |
| 1124 | Length -= (3+i); |
| 1125 | while(i--) { |
| 1126 | phba->Port[j++] = vpd[index++]; |
| 1127 | if (j == 19) |
| 1128 | break; |
| 1129 | } |
| 1130 | phba->Port[j] = 0; |
| 1131 | continue; |
| 1132 | } |
| 1133 | else { |
| 1134 | index += 2; |
| 1135 | i = vpd[index]; |
| 1136 | index += 1; |
| 1137 | index += i; |
| 1138 | Length -= (3 + i); |
| 1139 | } |
| 1140 | } |
| 1141 | finished = 0; |
| 1142 | break; |
| 1143 | case 0x78: |
| 1144 | finished = 1; |
| 1145 | break; |
| 1146 | default: |
| 1147 | index ++; |
| 1148 | break; |
| 1149 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1150 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1151 | |
| 1152 | return(1); |
| 1153 | } |
| 1154 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1155 | /** |
| 1156 | * lpfc_get_hba_model_desc: Retrieve HBA device model name and description. |
| 1157 | * @phba: pointer to lpfc hba data structure. |
| 1158 | * @mdp: pointer to the data structure to hold the derived model name. |
| 1159 | * @descp: pointer to the data structure to hold the derived description. |
| 1160 | * |
| 1161 | * This routine retrieves HBA's description based on its registered PCI device |
| 1162 | * ID. The @descp passed into this function points to an array of 256 chars. It |
| 1163 | * shall be returned with the model name, maximum speed, and the host bus type. |
| 1164 | * The @mdp passed into this function points to an array of 80 chars. When the |
| 1165 | * function returns, the @mdp will be filled with the model name. |
| 1166 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1167 | static void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1168 | 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] | 1169 | { |
| 1170 | lpfc_vpd_t *vp; |
James.Smart@Emulex.Com | fefcb2b | 2005-11-28 15:08:56 -0500 | [diff] [blame] | 1171 | uint16_t dev_id = phba->pcidev->device; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1172 | int max_speed; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1173 | int GE = 0; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1174 | struct { |
| 1175 | char * name; |
| 1176 | int max_speed; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1177 | char * bus; |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1178 | } m = {"<Unknown>", 0, ""}; |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1179 | |
| 1180 | if (mdp && mdp[0] != '\0' |
| 1181 | && descp && descp[0] != '\0') |
| 1182 | return; |
| 1183 | |
| 1184 | if (phba->lmt & LMT_10Gb) |
| 1185 | max_speed = 10; |
| 1186 | else if (phba->lmt & LMT_8Gb) |
| 1187 | max_speed = 8; |
| 1188 | else if (phba->lmt & LMT_4Gb) |
| 1189 | max_speed = 4; |
| 1190 | else if (phba->lmt & LMT_2Gb) |
| 1191 | max_speed = 2; |
| 1192 | else |
| 1193 | max_speed = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1194 | |
| 1195 | vp = &phba->vpd; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1196 | |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1197 | switch (dev_id) { |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1198 | case PCI_DEVICE_ID_FIREFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1199 | m = (typeof(m)){"LP6000", max_speed, "PCI"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1200 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1201 | case PCI_DEVICE_ID_SUPERFLY: |
| 1202 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1203 | m = (typeof(m)){"LP7000", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1204 | else |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1205 | m = (typeof(m)){"LP7000E", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1206 | break; |
| 1207 | case PCI_DEVICE_ID_DRAGONFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1208 | m = (typeof(m)){"LP8000", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1209 | break; |
| 1210 | case PCI_DEVICE_ID_CENTAUR: |
| 1211 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1212 | m = (typeof(m)){"LP9002", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1213 | else |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1214 | m = (typeof(m)){"LP9000", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1215 | break; |
| 1216 | case PCI_DEVICE_ID_RFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1217 | m = (typeof(m)){"LP952", max_speed, "PCI"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1218 | break; |
| 1219 | case PCI_DEVICE_ID_PEGASUS: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1220 | m = (typeof(m)){"LP9802", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1221 | break; |
| 1222 | case PCI_DEVICE_ID_THOR: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1223 | m = (typeof(m)){"LP10000", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1224 | break; |
| 1225 | case PCI_DEVICE_ID_VIPER: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1226 | m = (typeof(m)){"LPX1000", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1227 | break; |
| 1228 | case PCI_DEVICE_ID_PFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1229 | m = (typeof(m)){"LP982", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1230 | break; |
| 1231 | case PCI_DEVICE_ID_TFLY: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1232 | m = (typeof(m)){"LP1050", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1233 | break; |
| 1234 | case PCI_DEVICE_ID_HELIOS: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1235 | m = (typeof(m)){"LP11000", max_speed, "PCI-X2"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1236 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1237 | case PCI_DEVICE_ID_HELIOS_SCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1238 | m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1239 | break; |
| 1240 | case PCI_DEVICE_ID_HELIOS_DCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1241 | m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1242 | break; |
| 1243 | case PCI_DEVICE_ID_NEPTUNE: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1244 | m = (typeof(m)){"LPe1000", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1245 | break; |
| 1246 | case PCI_DEVICE_ID_NEPTUNE_SCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1247 | m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1248 | break; |
| 1249 | case PCI_DEVICE_ID_NEPTUNE_DCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1250 | m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1251 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1252 | case PCI_DEVICE_ID_BMID: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1253 | m = (typeof(m)){"LP1150", max_speed, "PCI-X2"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1254 | break; |
| 1255 | case PCI_DEVICE_ID_BSMB: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1256 | m = (typeof(m)){"LP111", max_speed, "PCI-X2"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1257 | break; |
| 1258 | case PCI_DEVICE_ID_ZEPHYR: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1259 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1260 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1261 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1262 | m = (typeof(m)){"LPe11000", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1263 | break; |
| 1264 | case PCI_DEVICE_ID_ZEPHYR_DCSP: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1265 | m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"}; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1266 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1267 | case PCI_DEVICE_ID_ZMID: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1268 | m = (typeof(m)){"LPe1150", max_speed, "PCIe"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1269 | break; |
| 1270 | case PCI_DEVICE_ID_ZSMB: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1271 | m = (typeof(m)){"LPe111", max_speed, "PCIe"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1272 | break; |
| 1273 | case PCI_DEVICE_ID_LP101: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1274 | m = (typeof(m)){"LP101", max_speed, "PCI-X"}; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1275 | break; |
| 1276 | case PCI_DEVICE_ID_LP10000S: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1277 | m = (typeof(m)){"LP10000-S", max_speed, "PCI"}; |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 1278 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1279 | case PCI_DEVICE_ID_LP11000S: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1280 | m = (typeof(m)){"LP11000-S", max_speed, |
| 1281 | "PCI-X2"}; |
| 1282 | break; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1283 | case PCI_DEVICE_ID_LPE11000S: |
James Smart | 18a3b59 | 2006-12-02 13:35:08 -0500 | [diff] [blame] | 1284 | m = (typeof(m)){"LPe11000-S", max_speed, |
| 1285 | "PCIe"}; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 1286 | break; |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 1287 | case PCI_DEVICE_ID_SAT: |
| 1288 | m = (typeof(m)){"LPe12000", max_speed, "PCIe"}; |
| 1289 | break; |
| 1290 | case PCI_DEVICE_ID_SAT_MID: |
| 1291 | m = (typeof(m)){"LPe1250", max_speed, "PCIe"}; |
| 1292 | break; |
| 1293 | case PCI_DEVICE_ID_SAT_SMB: |
| 1294 | m = (typeof(m)){"LPe121", max_speed, "PCIe"}; |
| 1295 | break; |
| 1296 | case PCI_DEVICE_ID_SAT_DCSP: |
| 1297 | m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"}; |
| 1298 | break; |
| 1299 | case PCI_DEVICE_ID_SAT_SCSP: |
| 1300 | m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"}; |
| 1301 | break; |
| 1302 | case PCI_DEVICE_ID_SAT_S: |
| 1303 | m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"}; |
| 1304 | break; |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1305 | case PCI_DEVICE_ID_HORNET: |
| 1306 | m = (typeof(m)){"LP21000", max_speed, "PCIe"}; |
| 1307 | GE = 1; |
| 1308 | break; |
| 1309 | case PCI_DEVICE_ID_PROTEUS_VF: |
| 1310 | m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"}; |
| 1311 | break; |
| 1312 | case PCI_DEVICE_ID_PROTEUS_PF: |
| 1313 | m = (typeof(m)) {"LPev12000", max_speed, "PCIe IOV"}; |
| 1314 | break; |
| 1315 | case PCI_DEVICE_ID_PROTEUS_S: |
| 1316 | m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"}; |
| 1317 | break; |
James.Smart@Emulex.Com | 5cc36b3 | 2005-11-28 11:42:19 -0500 | [diff] [blame] | 1318 | default: |
Randy Dunlap | 041976f | 2006-06-25 01:58:51 -0700 | [diff] [blame] | 1319 | m = (typeof(m)){ NULL }; |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 1320 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1321 | } |
Jamie Wellnitz | 74b72a5 | 2006-02-28 22:33:04 -0500 | [diff] [blame] | 1322 | |
| 1323 | if (mdp && mdp[0] == '\0') |
| 1324 | snprintf(mdp, 79,"%s", m.name); |
| 1325 | if (descp && descp[0] == '\0') |
| 1326 | snprintf(descp, 255, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 1327 | "Emulex %s %d%s %s %s", |
| 1328 | m.name, m.max_speed, |
| 1329 | (GE) ? "GE" : "Gb", |
| 1330 | m.bus, |
| 1331 | (GE) ? "FCoE Adapter" : "Fibre Channel Adapter"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1332 | } |
| 1333 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1334 | /** |
| 1335 | * lpfc_post_buffer: Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring. |
| 1336 | * @phba: pointer to lpfc hba data structure. |
| 1337 | * @pring: pointer to a IOCB ring. |
| 1338 | * @cnt: the number of IOCBs to be posted to the IOCB ring. |
| 1339 | * |
| 1340 | * This routine posts a given number of IOCBs with the associated DMA buffer |
| 1341 | * descriptors specified by the cnt argument to the given IOCB ring. |
| 1342 | * |
| 1343 | * Return codes |
| 1344 | * The number of IOCBs NOT able to be posted to the IOCB ring. |
| 1345 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1346 | int |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1347 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1348 | { |
| 1349 | IOCB_t *icmd; |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1350 | struct lpfc_iocbq *iocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1351 | struct lpfc_dmabuf *mp1, *mp2; |
| 1352 | |
| 1353 | cnt += pring->missbufcnt; |
| 1354 | |
| 1355 | /* While there are buffers to post */ |
| 1356 | while (cnt > 0) { |
| 1357 | /* Allocate buffer for command iocb */ |
James.Smart@Emulex.Com | 0bd4ca2 | 2005-10-28 20:30:02 -0400 | [diff] [blame] | 1358 | iocb = lpfc_sli_get_iocbq(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1359 | if (iocb == NULL) { |
| 1360 | pring->missbufcnt = cnt; |
| 1361 | return cnt; |
| 1362 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1363 | icmd = &iocb->iocb; |
| 1364 | |
| 1365 | /* 2 buffers can be posted per command */ |
| 1366 | /* Allocate buffer to post */ |
| 1367 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 1368 | if (mp1) |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1369 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
| 1370 | if (!mp1 || !mp1->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1371 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1372 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1373 | pring->missbufcnt = cnt; |
| 1374 | return cnt; |
| 1375 | } |
| 1376 | |
| 1377 | INIT_LIST_HEAD(&mp1->list); |
| 1378 | /* Allocate buffer to post */ |
| 1379 | if (cnt > 1) { |
| 1380 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 1381 | if (mp2) |
| 1382 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, |
| 1383 | &mp2->phys); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 1384 | if (!mp2 || !mp2->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 1385 | kfree(mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1386 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 1387 | kfree(mp1); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1388 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1389 | pring->missbufcnt = cnt; |
| 1390 | return cnt; |
| 1391 | } |
| 1392 | |
| 1393 | INIT_LIST_HEAD(&mp2->list); |
| 1394 | } else { |
| 1395 | mp2 = NULL; |
| 1396 | } |
| 1397 | |
| 1398 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); |
| 1399 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); |
| 1400 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; |
| 1401 | icmd->ulpBdeCount = 1; |
| 1402 | cnt--; |
| 1403 | if (mp2) { |
| 1404 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); |
| 1405 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); |
| 1406 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; |
| 1407 | cnt--; |
| 1408 | icmd->ulpBdeCount = 2; |
| 1409 | } |
| 1410 | |
| 1411 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; |
| 1412 | icmd->ulpLe = 1; |
| 1413 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1414 | if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) { |
| 1415 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
| 1416 | kfree(mp1); |
| 1417 | cnt++; |
| 1418 | if (mp2) { |
| 1419 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); |
| 1420 | kfree(mp2); |
| 1421 | cnt++; |
| 1422 | } |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 1423 | lpfc_sli_release_iocbq(phba, iocb); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1424 | pring->missbufcnt = cnt; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1425 | return cnt; |
| 1426 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1427 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1428 | if (mp2) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1429 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1430 | } |
| 1431 | pring->missbufcnt = 0; |
| 1432 | return 0; |
| 1433 | } |
| 1434 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1435 | /** |
| 1436 | * lpfc_post_rcv_buf: Post the initial receive IOCB buffers to ELS ring. |
| 1437 | * @phba: pointer to lpfc hba data structure. |
| 1438 | * |
| 1439 | * This routine posts initial receive IOCB buffers to the ELS ring. The |
| 1440 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is |
| 1441 | * set to 64 IOCBs. |
| 1442 | * |
| 1443 | * Return codes |
| 1444 | * 0 - success (currently always success) |
| 1445 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1446 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1447 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1448 | { |
| 1449 | struct lpfc_sli *psli = &phba->sli; |
| 1450 | |
| 1451 | /* Ring 0, ELS / CT buffers */ |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1452 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1453 | /* Ring 2 - FCP no buffers needed */ |
| 1454 | |
| 1455 | return 0; |
| 1456 | } |
| 1457 | |
| 1458 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) |
| 1459 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1460 | /** |
| 1461 | * lpfc_sha_init: Set up initial array of hash table entries. |
| 1462 | * @HashResultPointer: pointer to an array as hash table. |
| 1463 | * |
| 1464 | * This routine sets up the initial values to the array of hash table entries |
| 1465 | * for the LC HBAs. |
| 1466 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1467 | static void |
| 1468 | lpfc_sha_init(uint32_t * HashResultPointer) |
| 1469 | { |
| 1470 | HashResultPointer[0] = 0x67452301; |
| 1471 | HashResultPointer[1] = 0xEFCDAB89; |
| 1472 | HashResultPointer[2] = 0x98BADCFE; |
| 1473 | HashResultPointer[3] = 0x10325476; |
| 1474 | HashResultPointer[4] = 0xC3D2E1F0; |
| 1475 | } |
| 1476 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1477 | /** |
| 1478 | * lpfc_sha_iterate: Iterate initial hash table with the working hash table. |
| 1479 | * @HashResultPointer: pointer to an initial/result hash table. |
| 1480 | * @HashWorkingPointer: pointer to an working hash table. |
| 1481 | * |
| 1482 | * This routine iterates an initial hash table pointed by @HashResultPointer |
| 1483 | * with the values from the working hash table pointeed by @HashWorkingPointer. |
| 1484 | * The results are putting back to the initial hash table, returned through |
| 1485 | * the @HashResultPointer as the result hash table. |
| 1486 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1487 | static void |
| 1488 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) |
| 1489 | { |
| 1490 | int t; |
| 1491 | uint32_t TEMP; |
| 1492 | uint32_t A, B, C, D, E; |
| 1493 | t = 16; |
| 1494 | do { |
| 1495 | HashWorkingPointer[t] = |
| 1496 | S(1, |
| 1497 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - |
| 1498 | 8] ^ |
| 1499 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); |
| 1500 | } while (++t <= 79); |
| 1501 | t = 0; |
| 1502 | A = HashResultPointer[0]; |
| 1503 | B = HashResultPointer[1]; |
| 1504 | C = HashResultPointer[2]; |
| 1505 | D = HashResultPointer[3]; |
| 1506 | E = HashResultPointer[4]; |
| 1507 | |
| 1508 | do { |
| 1509 | if (t < 20) { |
| 1510 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; |
| 1511 | } else if (t < 40) { |
| 1512 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; |
| 1513 | } else if (t < 60) { |
| 1514 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; |
| 1515 | } else { |
| 1516 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; |
| 1517 | } |
| 1518 | TEMP += S(5, A) + E + HashWorkingPointer[t]; |
| 1519 | E = D; |
| 1520 | D = C; |
| 1521 | C = S(30, B); |
| 1522 | B = A; |
| 1523 | A = TEMP; |
| 1524 | } while (++t <= 79); |
| 1525 | |
| 1526 | HashResultPointer[0] += A; |
| 1527 | HashResultPointer[1] += B; |
| 1528 | HashResultPointer[2] += C; |
| 1529 | HashResultPointer[3] += D; |
| 1530 | HashResultPointer[4] += E; |
| 1531 | |
| 1532 | } |
| 1533 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1534 | /** |
| 1535 | * lpfc_challenge_key: Create challenge key based on WWPN of the HBA. |
| 1536 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
| 1537 | * @HashWorking: pointer to the entry of the working hash array. |
| 1538 | * |
| 1539 | * This routine calculates the working hash array referred by @HashWorking |
| 1540 | * from the challenge random numbers associated with the host, referred by |
| 1541 | * @RandomChallenge. The result is put into the entry of the working hash |
| 1542 | * array and returned by reference through @HashWorking. |
| 1543 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1544 | static void |
| 1545 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) |
| 1546 | { |
| 1547 | *HashWorking = (*RandomChallenge ^ *HashWorking); |
| 1548 | } |
| 1549 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1550 | /** |
| 1551 | * lpfc_hba_init: Perform special handling for LC HBA initialization. |
| 1552 | * @phba: pointer to lpfc hba data structure. |
| 1553 | * @hbainit: pointer to an array of unsigned 32-bit integers. |
| 1554 | * |
| 1555 | * This routine performs the special handling for LC HBA initialization. |
| 1556 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1557 | void |
| 1558 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) |
| 1559 | { |
| 1560 | int t; |
| 1561 | uint32_t *HashWorking; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1562 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1563 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 1564 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1565 | if (!HashWorking) |
| 1566 | return; |
| 1567 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1568 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
| 1569 | HashWorking[1] = HashWorking[79] = *pwwnn; |
| 1570 | |
| 1571 | for (t = 0; t < 7; t++) |
| 1572 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); |
| 1573 | |
| 1574 | lpfc_sha_init(hbainit); |
| 1575 | lpfc_sha_iterate(hbainit, HashWorking); |
| 1576 | kfree(HashWorking); |
| 1577 | } |
| 1578 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1579 | /** |
| 1580 | * lpfc_cleanup: Performs vport cleanups before deleting a vport. |
| 1581 | * @vport: pointer to a virtual N_Port data structure. |
| 1582 | * |
| 1583 | * This routine performs the necessary cleanups before deleting the @vport. |
| 1584 | * It invokes the discovery state machine to perform necessary state |
| 1585 | * transitions and to release the ndlps associated with the @vport. Note, |
| 1586 | * the physical port is treated as @vport 0. |
| 1587 | **/ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1588 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1589 | lpfc_cleanup(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1590 | { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1591 | struct lpfc_hba *phba = vport->phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1592 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1593 | int i = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1594 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1595 | if (phba->link_state > LPFC_LINK_DOWN) |
| 1596 | lpfc_port_link_failure(vport); |
| 1597 | |
| 1598 | 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] | 1599 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
| 1600 | ndlp = lpfc_enable_node(vport, ndlp, |
| 1601 | NLP_STE_UNUSED_NODE); |
| 1602 | if (!ndlp) |
| 1603 | continue; |
| 1604 | spin_lock_irq(&phba->ndlp_lock); |
| 1605 | NLP_SET_FREE_REQ(ndlp); |
| 1606 | spin_unlock_irq(&phba->ndlp_lock); |
| 1607 | /* Trigger the release of the ndlp memory */ |
| 1608 | lpfc_nlp_put(ndlp); |
| 1609 | continue; |
| 1610 | } |
| 1611 | spin_lock_irq(&phba->ndlp_lock); |
| 1612 | if (NLP_CHK_FREE_REQ(ndlp)) { |
| 1613 | /* The ndlp should not be in memory free mode already */ |
| 1614 | spin_unlock_irq(&phba->ndlp_lock); |
| 1615 | continue; |
| 1616 | } else |
| 1617 | /* Indicate request for freeing ndlp memory */ |
| 1618 | NLP_SET_FREE_REQ(ndlp); |
| 1619 | spin_unlock_irq(&phba->ndlp_lock); |
| 1620 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 1621 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
| 1622 | ndlp->nlp_DID == Fabric_DID) { |
| 1623 | /* Just free up ndlp with Fabric_DID for vports */ |
| 1624 | lpfc_nlp_put(ndlp); |
| 1625 | continue; |
| 1626 | } |
| 1627 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1628 | if (ndlp->nlp_type & NLP_FABRIC) |
| 1629 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 1630 | NLP_EVT_DEVICE_RECOVERY); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1631 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1632 | lpfc_disc_state_machine(vport, ndlp, NULL, |
| 1633 | NLP_EVT_DEVICE_RM); |
James Smart | 495a714 | 2008-06-14 22:52:59 -0400 | [diff] [blame] | 1634 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1635 | } |
| 1636 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1637 | /* At this point, ALL ndlp's should be gone |
| 1638 | * because of the previous NLP_EVT_DEVICE_RM. |
| 1639 | * Lets wait for this to happen, if needed. |
| 1640 | */ |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1641 | while (!list_empty(&vport->fc_nodes)) { |
| 1642 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1643 | if (i++ > 3000) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1644 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1645 | "0233 Nodelist not empty\n"); |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1646 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 1647 | &vport->fc_nodes, nlp_listp) { |
| 1648 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, |
| 1649 | LOG_NODE, |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 1650 | "0282 did:x%x ndlp:x%p " |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1651 | "usgmap:x%x refcnt:%d\n", |
| 1652 | ndlp->nlp_DID, (void *)ndlp, |
| 1653 | ndlp->nlp_usg_map, |
| 1654 | atomic_read( |
| 1655 | &ndlp->kref.refcount)); |
| 1656 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1657 | break; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1658 | } |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1659 | |
| 1660 | /* Wait for any activity on ndlps to settle */ |
| 1661 | msleep(10); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1662 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1663 | return; |
| 1664 | } |
| 1665 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1666 | /** |
| 1667 | * lpfc_stop_vport_timers: Stop all the timers associated with a vport. |
| 1668 | * @vport: pointer to a virtual N_Port data structure. |
| 1669 | * |
| 1670 | * This routine stops all the timers associated with a @vport. This function |
| 1671 | * is invoked before disabling or deleting a @vport. Note that the physical |
| 1672 | * port is treated as @vport 0. |
| 1673 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1674 | void |
| 1675 | lpfc_stop_vport_timers(struct lpfc_vport *vport) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1676 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1677 | del_timer_sync(&vport->els_tmofunc); |
| 1678 | del_timer_sync(&vport->fc_fdmitmo); |
| 1679 | lpfc_can_disctmo(vport); |
| 1680 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1681 | } |
| 1682 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1683 | /** |
| 1684 | * lpfc_stop_phba_timers: Stop all the timers associated with an HBA. |
| 1685 | * @phba: pointer to lpfc hba data structure. |
| 1686 | * |
| 1687 | * This routine stops all the timers associated with a HBA. This function is |
| 1688 | * invoked before either putting a HBA offline or unloading the driver. |
| 1689 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1690 | static void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1691 | lpfc_stop_phba_timers(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1692 | { |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 1693 | del_timer_sync(&phba->fcp_poll_timer); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1694 | lpfc_stop_vport_timers(phba->pport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1695 | del_timer_sync(&phba->sli.mbox_tmo); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1696 | del_timer_sync(&phba->fabric_block_timer); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 1697 | phba->hb_outstanding = 0; |
| 1698 | del_timer_sync(&phba->hb_tmofunc); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 1699 | del_timer_sync(&phba->eratt_poll); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1700 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1701 | } |
| 1702 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1703 | /** |
| 1704 | * lpfc_block_mgmt_io: Mark a HBA's management interface as blocked. |
| 1705 | * @phba: pointer to lpfc hba data structure. |
| 1706 | * |
| 1707 | * This routine marks a HBA's management interface as blocked. Once the HBA's |
| 1708 | * management interface is marked as blocked, all the user space access to |
| 1709 | * the HBA, whether they are from sysfs interface or libdfc interface will |
| 1710 | * all be blocked. The HBA is set to block the management interface when the |
| 1711 | * driver prepares the HBA interface for online or offline. |
| 1712 | **/ |
Adrian Bunk | a6ababd | 2007-11-05 18:07:33 +0100 | [diff] [blame] | 1713 | static void |
| 1714 | lpfc_block_mgmt_io(struct lpfc_hba * phba) |
| 1715 | { |
| 1716 | unsigned long iflag; |
| 1717 | |
| 1718 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1719 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; |
| 1720 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
| 1721 | } |
| 1722 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1723 | /** |
| 1724 | * lpfc_online: Initialize and bring a HBA online. |
| 1725 | * @phba: pointer to lpfc hba data structure. |
| 1726 | * |
| 1727 | * This routine initializes the HBA and brings a HBA online. During this |
| 1728 | * process, the management interface is blocked to prevent user space access |
| 1729 | * to the HBA interfering with the driver initialization. |
| 1730 | * |
| 1731 | * Return codes |
| 1732 | * 0 - successful |
| 1733 | * 1 - failed |
| 1734 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1735 | int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1736 | lpfc_online(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1737 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1738 | struct lpfc_vport *vport = phba->pport; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1739 | struct lpfc_vport **vports; |
| 1740 | int i; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1741 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1742 | if (!phba) |
| 1743 | return 0; |
| 1744 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1745 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1746 | return 0; |
| 1747 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1748 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1749 | "0458 Bring Adapter online\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1750 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1751 | lpfc_block_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1752 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1753 | if (!lpfc_sli_queue_setup(phba)) { |
| 1754 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1755 | return 1; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */ |
| 1759 | lpfc_unblock_mgmt_io(phba); |
| 1760 | return 1; |
| 1761 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1762 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1763 | vports = lpfc_create_vport_work_array(phba); |
| 1764 | if (vports != NULL) |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1765 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1766 | struct Scsi_Host *shost; |
| 1767 | shost = lpfc_shost_from_vport(vports[i]); |
| 1768 | spin_lock_irq(shost->host_lock); |
| 1769 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; |
| 1770 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) |
| 1771 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
| 1772 | spin_unlock_irq(shost->host_lock); |
| 1773 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1774 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1775 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1776 | lpfc_unblock_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1777 | return 0; |
| 1778 | } |
| 1779 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1780 | /** |
| 1781 | * lpfc_unblock_mgmt_io: Mark a HBA's management interface to be not blocked. |
| 1782 | * @phba: pointer to lpfc hba data structure. |
| 1783 | * |
| 1784 | * This routine marks a HBA's management interface as not blocked. Once the |
| 1785 | * HBA's management interface is marked as not blocked, all the user space |
| 1786 | * access to the HBA, whether they are from sysfs interface or libdfc |
| 1787 | * interface will be allowed. The HBA is set to block the management interface |
| 1788 | * when the driver prepares the HBA interface for online or offline and then |
| 1789 | * set to unblock the management interface afterwards. |
| 1790 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1791 | void |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1792 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) |
| 1793 | { |
| 1794 | unsigned long iflag; |
| 1795 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1796 | spin_lock_irqsave(&phba->hbalock, iflag); |
| 1797 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; |
| 1798 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1799 | } |
| 1800 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1801 | /** |
| 1802 | * lpfc_offline_prep: Prepare a HBA to be brought offline. |
| 1803 | * @phba: pointer to lpfc hba data structure. |
| 1804 | * |
| 1805 | * This routine is invoked to prepare a HBA to be brought offline. It performs |
| 1806 | * unregistration login to all the nodes on all vports and flushes the mailbox |
| 1807 | * queue to make it ready to be brought offline. |
| 1808 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1809 | void |
| 1810 | lpfc_offline_prep(struct lpfc_hba * phba) |
| 1811 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1812 | struct lpfc_vport *vport = phba->pport; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1813 | struct lpfc_nodelist *ndlp, *next_ndlp; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1814 | struct lpfc_vport **vports; |
| 1815 | int i; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1816 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1817 | if (vport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1818 | return; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1819 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1820 | lpfc_block_mgmt_io(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1821 | |
| 1822 | lpfc_linkdown(phba); |
| 1823 | |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1824 | /* Issue an unreg_login to all nodes on all vports */ |
| 1825 | vports = lpfc_create_vport_work_array(phba); |
| 1826 | if (vports != NULL) { |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1827 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1828 | struct Scsi_Host *shost; |
| 1829 | |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 1830 | if (vports[i]->load_flag & FC_UNLOADING) |
| 1831 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1832 | shost = lpfc_shost_from_vport(vports[i]); |
| 1833 | list_for_each_entry_safe(ndlp, next_ndlp, |
| 1834 | &vports[i]->fc_nodes, |
| 1835 | nlp_listp) { |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 1836 | if (!NLP_CHK_NODE_ACT(ndlp)) |
| 1837 | continue; |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 1838 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
| 1839 | continue; |
| 1840 | if (ndlp->nlp_type & NLP_FABRIC) { |
| 1841 | lpfc_disc_state_machine(vports[i], ndlp, |
| 1842 | NULL, NLP_EVT_DEVICE_RECOVERY); |
| 1843 | lpfc_disc_state_machine(vports[i], ndlp, |
| 1844 | NULL, NLP_EVT_DEVICE_RM); |
| 1845 | } |
| 1846 | spin_lock_irq(shost->host_lock); |
| 1847 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; |
| 1848 | spin_unlock_irq(shost->host_lock); |
| 1849 | lpfc_unreg_rpi(vports[i], ndlp); |
| 1850 | } |
| 1851 | } |
| 1852 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1853 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1854 | |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1855 | lpfc_sli_flush_mbox_queue(phba); |
| 1856 | } |
| 1857 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1858 | /** |
| 1859 | * lpfc_offline: Bring a HBA offline. |
| 1860 | * @phba: pointer to lpfc hba data structure. |
| 1861 | * |
| 1862 | * This routine actually brings a HBA offline. It stops all the timers |
| 1863 | * associated with the HBA, brings down the SLI layer, and eventually |
| 1864 | * marks the HBA as in offline state for the upper layer protocol. |
| 1865 | **/ |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1866 | void |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1867 | lpfc_offline(struct lpfc_hba *phba) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1868 | { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1869 | struct Scsi_Host *shost; |
| 1870 | struct lpfc_vport **vports; |
| 1871 | int i; |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1872 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1873 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
James Smart | 46fa311 | 2007-04-25 09:51:45 -0400 | [diff] [blame] | 1874 | return; |
James Smart | 688a886 | 2006-07-06 15:49:56 -0400 | [diff] [blame] | 1875 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1876 | /* stop all timers associated with this hba */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1877 | lpfc_stop_phba_timers(phba); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1878 | vports = lpfc_create_vport_work_array(phba); |
| 1879 | if (vports != NULL) |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1880 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1881 | lpfc_stop_vport_timers(vports[i]); |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1882 | lpfc_destroy_vport_work_array(phba, vports); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1883 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 1884 | "0460 Bring Adapter offline\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1885 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
| 1886 | now. */ |
| 1887 | lpfc_sli_hba_down(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1888 | spin_lock_irq(&phba->hbalock); |
James Smart | 7054a60 | 2007-04-25 09:52:34 -0400 | [diff] [blame] | 1889 | phba->work_ha = 0; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1890 | spin_unlock_irq(&phba->hbalock); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1891 | vports = lpfc_create_vport_work_array(phba); |
| 1892 | if (vports != NULL) |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1893 | for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1894 | shost = lpfc_shost_from_vport(vports[i]); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 1895 | spin_lock_irq(shost->host_lock); |
| 1896 | vports[i]->work_port_events = 0; |
| 1897 | vports[i]->fc_flag |= FC_OFFLINE_MODE; |
| 1898 | spin_unlock_irq(shost->host_lock); |
| 1899 | } |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1900 | lpfc_destroy_vport_work_array(phba, vports); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1901 | } |
| 1902 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1903 | /** |
| 1904 | * lpfc_scsi_free: Free all the SCSI buffers and IOCBs from driver lists. |
| 1905 | * @phba: pointer to lpfc hba data structure. |
| 1906 | * |
| 1907 | * This routine is to free all the SCSI buffers and IOCBs from the driver |
| 1908 | * list back to kernel. It is called from lpfc_pci_remove_one to free |
| 1909 | * the internal resources before the device is removed from the system. |
| 1910 | * |
| 1911 | * Return codes |
| 1912 | * 0 - successful (for now, it always returns 0) |
| 1913 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1914 | static int |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1915 | lpfc_scsi_free(struct lpfc_hba *phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1916 | { |
| 1917 | struct lpfc_scsi_buf *sb, *sb_next; |
| 1918 | struct lpfc_iocbq *io, *io_next; |
| 1919 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1920 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1921 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
| 1922 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { |
| 1923 | list_del(&sb->list); |
| 1924 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1925 | sb->dma_handle); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1926 | kfree(sb); |
| 1927 | phba->total_scsi_bufs--; |
| 1928 | } |
| 1929 | |
| 1930 | /* Release all the lpfc_iocbq entries maintained by this host. */ |
| 1931 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { |
| 1932 | list_del(&io->list); |
| 1933 | kfree(io); |
| 1934 | phba->total_iocbq_bufs--; |
| 1935 | } |
| 1936 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1937 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1938 | |
| 1939 | return 0; |
| 1940 | } |
| 1941 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1942 | /** |
| 1943 | * lpfc_create_port: Create an FC port. |
| 1944 | * @phba: pointer to lpfc hba data structure. |
| 1945 | * @instance: a unique integer ID to this FC port. |
| 1946 | * @dev: pointer to the device data structure. |
| 1947 | * |
| 1948 | * This routine creates a FC port for the upper layer protocol. The FC port |
| 1949 | * can be created on top of either a physical port or a virtual port provided |
| 1950 | * by the HBA. This routine also allocates a SCSI host data structure (shost) |
| 1951 | * and associates the FC port created before adding the shost into the SCSI |
| 1952 | * layer. |
| 1953 | * |
| 1954 | * Return codes |
| 1955 | * @vport - pointer to the virtual N_Port data structure. |
| 1956 | * NULL - port create failed. |
| 1957 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1958 | struct lpfc_vport * |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1959 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1960 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1961 | struct lpfc_vport *vport; |
| 1962 | struct Scsi_Host *shost; |
| 1963 | int error = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1964 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1965 | if (dev != &phba->pcidev->dev) |
| 1966 | shost = scsi_host_alloc(&lpfc_vport_template, |
| 1967 | sizeof(struct lpfc_vport)); |
| 1968 | else |
| 1969 | shost = scsi_host_alloc(&lpfc_template, |
| 1970 | sizeof(struct lpfc_vport)); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1971 | if (!shost) |
| 1972 | goto out; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1973 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1974 | vport = (struct lpfc_vport *) shost->hostdata; |
| 1975 | vport->phba = phba; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1976 | vport->load_flag |= FC_LOADING; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1977 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
James Smart | 7f5f3d0 | 2008-02-08 18:50:14 -0500 | [diff] [blame] | 1978 | vport->fc_rscn_flush = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1979 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1980 | lpfc_get_vport_cfgparam(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1981 | shost->unique_id = instance; |
| 1982 | shost->max_id = LPFC_MAX_TARGET; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1983 | shost->max_lun = vport->cfg_max_luns; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1984 | shost->this_id = -1; |
| 1985 | shost->max_cmd_len = 16; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1986 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1987 | * Set initial can_queue value since 0 is no longer supported and |
| 1988 | * scsi_add_host will fail. This will be adjusted later based on the |
| 1989 | * max xri value determined in hba setup. |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1990 | */ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1991 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 1992 | if (dev != &phba->pcidev->dev) { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1993 | shost->transportt = lpfc_vport_transport_template; |
| 1994 | vport->port_type = LPFC_NPIV_PORT; |
| 1995 | } else { |
| 1996 | shost->transportt = lpfc_transport_template; |
| 1997 | vport->port_type = LPFC_PHYSICAL_PORT; |
| 1998 | } |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 1999 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2000 | /* Initialize all internally managed lists. */ |
| 2001 | INIT_LIST_HEAD(&vport->fc_nodes); |
| 2002 | spin_lock_init(&vport->work_port_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2003 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2004 | init_timer(&vport->fc_disctmo); |
| 2005 | vport->fc_disctmo.function = lpfc_disc_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2006 | vport->fc_disctmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2007 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2008 | init_timer(&vport->fc_fdmitmo); |
| 2009 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2010 | vport->fc_fdmitmo.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2011 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2012 | init_timer(&vport->els_tmofunc); |
| 2013 | vport->els_tmofunc.function = lpfc_els_timeout; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2014 | vport->els_tmofunc.data = (unsigned long)vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2015 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2016 | error = scsi_add_host(shost, dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2017 | if (error) |
| 2018 | goto out_put_shost; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2019 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2020 | spin_lock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2021 | list_add_tail(&vport->listentry, &phba->port_list); |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2022 | spin_unlock_irq(&phba->hbalock); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2023 | return vport; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2024 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2025 | out_put_shost: |
| 2026 | scsi_host_put(shost); |
| 2027 | out: |
| 2028 | return NULL; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2029 | } |
| 2030 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2031 | /** |
| 2032 | * destroy_port: Destroy an FC port. |
| 2033 | * @vport: pointer to an lpfc virtual N_Port data structure. |
| 2034 | * |
| 2035 | * This routine destroys a FC port from the upper layer protocol. All the |
| 2036 | * resources associated with the port are released. |
| 2037 | **/ |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2038 | void |
| 2039 | destroy_port(struct lpfc_vport *vport) |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2040 | { |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2041 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
| 2042 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2043 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2044 | lpfc_debugfs_terminate(vport); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2045 | fc_remove_host(shost); |
| 2046 | scsi_remove_host(shost); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2047 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2048 | spin_lock_irq(&phba->hbalock); |
| 2049 | list_del_init(&vport->listentry); |
| 2050 | spin_unlock_irq(&phba->hbalock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2051 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2052 | lpfc_cleanup(vport); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2053 | return; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2054 | } |
| 2055 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2056 | /** |
| 2057 | * lpfc_get_instance: Get a unique integer ID. |
| 2058 | * |
| 2059 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It |
| 2060 | * uses the kernel idr facility to perform the task. |
| 2061 | * |
| 2062 | * Return codes: |
| 2063 | * instance - a unique integer ID allocated as the new instance. |
| 2064 | * -1 - lpfc get instance failed. |
| 2065 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2066 | int |
| 2067 | lpfc_get_instance(void) |
| 2068 | { |
| 2069 | int instance = 0; |
| 2070 | |
| 2071 | /* Assign an unused number */ |
| 2072 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) |
| 2073 | return -1; |
| 2074 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) |
| 2075 | return -1; |
| 2076 | return instance; |
| 2077 | } |
| 2078 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2079 | /** |
| 2080 | * lpfc_scan_finished: method for SCSI layer to detect whether scan is done. |
| 2081 | * @shost: pointer to SCSI host data structure. |
| 2082 | * @time: elapsed time of the scan in jiffies. |
| 2083 | * |
| 2084 | * This routine is called by the SCSI layer with a SCSI host to determine |
| 2085 | * whether the scan host is finished. |
| 2086 | * |
| 2087 | * Note: there is no scan_start function as adapter initialization will have |
| 2088 | * asynchronously kicked off the link initialization. |
| 2089 | * |
| 2090 | * Return codes |
| 2091 | * 0 - SCSI host scan is not over yet. |
| 2092 | * 1 - SCSI host scan is over. |
| 2093 | **/ |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2094 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 2095 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2096 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2097 | struct lpfc_hba *phba = vport->phba; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2098 | int stat = 0; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2099 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2100 | spin_lock_irq(shost->host_lock); |
| 2101 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2102 | if (vport->load_flag & FC_UNLOADING) { |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2103 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2104 | goto finished; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2105 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2106 | if (time >= 30 * HZ) { |
| 2107 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2108 | "0461 Scanning longer than 30 " |
| 2109 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2110 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2111 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2112 | } |
| 2113 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { |
| 2114 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2115 | "0465 Link down longer than 15 " |
| 2116 | "seconds. Continuing initialization\n"); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2117 | stat = 1; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2118 | goto finished; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2119 | } |
| 2120 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2121 | if (vport->port_state != LPFC_VPORT_READY) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2122 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2123 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2124 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2125 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2126 | goto finished; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2127 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2128 | goto finished; |
| 2129 | |
| 2130 | stat = 1; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2131 | |
| 2132 | finished: |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2133 | spin_unlock_irq(shost->host_lock); |
| 2134 | return stat; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2135 | } |
| 2136 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2137 | /** |
| 2138 | * lpfc_host_attrib_init: Initialize SCSI host attributes on a FC port. |
| 2139 | * @shost: pointer to SCSI host data structure. |
| 2140 | * |
| 2141 | * This routine initializes a given SCSI host attributes on a FC port. The |
| 2142 | * SCSI host can be either on top of a physical port or a virtual port. |
| 2143 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2144 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
| 2145 | { |
| 2146 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
| 2147 | struct lpfc_hba *phba = vport->phba; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2148 | /* |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2149 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2150 | */ |
| 2151 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2152 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
| 2153 | 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] | 2154 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
| 2155 | |
| 2156 | memset(fc_host_supported_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2157 | sizeof(fc_host_supported_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2158 | fc_host_supported_fc4s(shost)[2] = 1; |
| 2159 | fc_host_supported_fc4s(shost)[7] = 1; |
| 2160 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2161 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
| 2162 | sizeof fc_host_symbolic_name(shost)); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2163 | |
| 2164 | fc_host_supported_speeds(shost) = 0; |
| 2165 | if (phba->lmt & LMT_10Gb) |
| 2166 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; |
James Smart | a8adb83 | 2007-10-27 13:37:53 -0400 | [diff] [blame] | 2167 | if (phba->lmt & LMT_8Gb) |
| 2168 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2169 | if (phba->lmt & LMT_4Gb) |
| 2170 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; |
| 2171 | if (phba->lmt & LMT_2Gb) |
| 2172 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; |
| 2173 | if (phba->lmt & LMT_1Gb) |
| 2174 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; |
| 2175 | |
| 2176 | fc_host_maxframe_size(shost) = |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2177 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
| 2178 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2179 | |
| 2180 | /* This value is also unchanging */ |
| 2181 | memset(fc_host_active_fc4s(shost), 0, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2182 | sizeof(fc_host_active_fc4s(shost))); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2183 | fc_host_active_fc4s(shost)[2] = 1; |
| 2184 | fc_host_active_fc4s(shost)[7] = 1; |
| 2185 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2186 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2187 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2188 | vport->load_flag &= ~FC_LOADING; |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2189 | spin_unlock_irq(shost->host_lock); |
James Smart | 47a8617 | 2007-04-25 09:53:22 -0400 | [diff] [blame] | 2190 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2191 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2192 | /** |
| 2193 | * lpfc_enable_msix: Enable MSI-X interrupt mode. |
| 2194 | * @phba: pointer to lpfc hba data structure. |
| 2195 | * |
| 2196 | * This routine is invoked to enable the MSI-X interrupt vectors. The kernel |
| 2197 | * function pci_enable_msix() is called to enable the MSI-X vectors. Note that |
| 2198 | * pci_enable_msix(), once invoked, enables either all or nothing, depending |
| 2199 | * on the current availability of PCI vector resources. The device driver is |
| 2200 | * responsible for calling the individual request_irq() to register each MSI-X |
| 2201 | * vector with a interrupt handler, which is done in this function. Note that |
| 2202 | * later when device is unloading, the driver should always call free_irq() |
| 2203 | * on all MSI-X vectors it has done request_irq() on before calling |
| 2204 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device |
| 2205 | * will be left with MSI-X enabled and leaks its vectors. |
| 2206 | * |
| 2207 | * Return codes |
| 2208 | * 0 - sucessful |
| 2209 | * other values - error |
| 2210 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2211 | static int |
| 2212 | lpfc_enable_msix(struct lpfc_hba *phba) |
| 2213 | { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2214 | int rc, i; |
| 2215 | LPFC_MBOXQ_t *pmb; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2216 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2217 | /* Set up MSI-X multi-message vectors */ |
| 2218 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 2219 | phba->msix_entries[i].entry = i; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2220 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2221 | /* Configure MSI-X capability structure */ |
| 2222 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2223 | ARRAY_SIZE(phba->msix_entries)); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2224 | if (rc) { |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2225 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2226 | "0420 Enable MSI-X failed (%d), continuing " |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2227 | "with MSI\n", rc); |
| 2228 | goto msi_fail_out; |
| 2229 | } else |
| 2230 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 2231 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2232 | "0477 MSI-X entry[%d]: vector=x%x " |
| 2233 | "message=%d\n", i, |
| 2234 | phba->msix_entries[i].vector, |
| 2235 | phba->msix_entries[i].entry); |
| 2236 | /* |
| 2237 | * Assign MSI-X vectors to interrupt handlers |
| 2238 | */ |
| 2239 | |
| 2240 | /* vector-0 is associated to slow-path handler */ |
| 2241 | rc = request_irq(phba->msix_entries[0].vector, &lpfc_sp_intr_handler, |
| 2242 | IRQF_SHARED, LPFC_SP_DRIVER_HANDLER_NAME, phba); |
| 2243 | if (rc) { |
| 2244 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2245 | "0421 MSI-X slow-path request_irq failed " |
| 2246 | "(%d), continuing with MSI\n", rc); |
| 2247 | goto msi_fail_out; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2248 | } |
| 2249 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2250 | /* vector-1 is associated to fast-path handler */ |
| 2251 | rc = request_irq(phba->msix_entries[1].vector, &lpfc_fp_intr_handler, |
| 2252 | IRQF_SHARED, LPFC_FP_DRIVER_HANDLER_NAME, phba); |
| 2253 | |
| 2254 | if (rc) { |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2255 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2256 | "0429 MSI-X fast-path request_irq failed " |
| 2257 | "(%d), continuing with MSI\n", rc); |
| 2258 | goto irq_fail_out; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2259 | } |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2260 | |
| 2261 | /* |
| 2262 | * Configure HBA MSI-X attention conditions to messages |
| 2263 | */ |
| 2264 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 2265 | |
| 2266 | if (!pmb) { |
| 2267 | rc = -ENOMEM; |
| 2268 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2269 | "0474 Unable to allocate memory for issuing " |
| 2270 | "MBOX_CONFIG_MSI command\n"); |
| 2271 | goto mem_fail_out; |
| 2272 | } |
| 2273 | rc = lpfc_config_msi(phba, pmb); |
| 2274 | if (rc) |
| 2275 | goto mbx_fail_out; |
| 2276 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
| 2277 | if (rc != MBX_SUCCESS) { |
| 2278 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 2279 | "0351 Config MSI mailbox command failed, " |
| 2280 | "mbxCmd x%x, mbxStatus x%x\n", |
| 2281 | pmb->mb.mbxCommand, pmb->mb.mbxStatus); |
| 2282 | goto mbx_fail_out; |
| 2283 | } |
| 2284 | |
| 2285 | /* Free memory allocated for mailbox command */ |
| 2286 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2287 | return rc; |
| 2288 | |
| 2289 | mbx_fail_out: |
| 2290 | /* Free memory allocated for mailbox command */ |
| 2291 | mempool_free(pmb, phba->mbox_mem_pool); |
| 2292 | |
| 2293 | mem_fail_out: |
| 2294 | /* free the irq already requested */ |
| 2295 | free_irq(phba->msix_entries[1].vector, phba); |
| 2296 | |
| 2297 | irq_fail_out: |
| 2298 | /* free the irq already requested */ |
| 2299 | free_irq(phba->msix_entries[0].vector, phba); |
| 2300 | |
| 2301 | msi_fail_out: |
| 2302 | /* Unconfigure MSI-X capability structure */ |
| 2303 | pci_disable_msix(phba->pcidev); |
| 2304 | return rc; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2305 | } |
| 2306 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2307 | /** |
| 2308 | * lpfc_disable_msix: Disable MSI-X interrupt mode. |
| 2309 | * @phba: pointer to lpfc hba data structure. |
| 2310 | * |
| 2311 | * This routine is invoked to release the MSI-X vectors and then disable the |
| 2312 | * MSI-X interrupt mode. |
| 2313 | **/ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2314 | static void |
| 2315 | lpfc_disable_msix(struct lpfc_hba *phba) |
| 2316 | { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2317 | int i; |
| 2318 | |
| 2319 | /* Free up MSI-X multi-message vectors */ |
| 2320 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) |
| 2321 | free_irq(phba->msix_entries[i].vector, phba); |
| 2322 | /* Disable MSI-X */ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2323 | pci_disable_msix(phba->pcidev); |
| 2324 | } |
| 2325 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2326 | /** |
| 2327 | * lpfc_pci_probe_one: lpfc PCI probe func to register device to PCI subsystem. |
| 2328 | * @pdev: pointer to PCI device |
| 2329 | * @pid: pointer to PCI device identifier |
| 2330 | * |
| 2331 | * This routine is to be registered to the kernel's PCI subsystem. When an |
| 2332 | * Emulex HBA is presented in PCI bus, the kernel PCI subsystem looks at |
| 2333 | * PCI device-specific information of the device and driver to see if the |
| 2334 | * driver state that it can support this kind of device. If the match is |
| 2335 | * successful, the driver core invokes this routine. If this routine |
| 2336 | * determines it can claim the HBA, it does all the initialization that it |
| 2337 | * needs to do to handle the HBA properly. |
| 2338 | * |
| 2339 | * Return code |
| 2340 | * 0 - driver can claim the device |
| 2341 | * negative value - driver can not claim the device |
| 2342 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2343 | static int __devinit |
| 2344 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 2345 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2346 | struct lpfc_vport *vport = NULL; |
| 2347 | struct lpfc_hba *phba; |
| 2348 | struct lpfc_sli *psli; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2349 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2350 | struct Scsi_Host *shost = NULL; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2351 | void *ptr; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2352 | unsigned long bar0map_len, bar2map_len; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2353 | int error = -ENODEV, retval; |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2354 | int i, hbq_count; |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2355 | uint16_t iotag; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2356 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2357 | struct lpfc_adapter_event_header adapter_event; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2358 | |
Greg Kroah-Hartman | d5f78fb | 2008-02-02 12:13:22 +0100 | [diff] [blame] | 2359 | if (pci_enable_device_mem(pdev)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2360 | goto out; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2361 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2362 | goto out_disable_device; |
| 2363 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2364 | phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL); |
| 2365 | if (!phba) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2366 | goto out_release_regions; |
| 2367 | |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2368 | atomic_set(&phba->fast_event_count, 0); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2369 | spin_lock_init(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2370 | |
James Smart | e47c909 | 2008-02-08 18:49:26 -0500 | [diff] [blame] | 2371 | /* Initialize ndlp management spinlock */ |
| 2372 | spin_lock_init(&phba->ndlp_lock); |
| 2373 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2374 | phba->pcidev = pdev; |
| 2375 | |
| 2376 | /* Assign an unused board number */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2377 | if ((phba->brd_no = lpfc_get_instance()) < 0) |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2378 | goto out_free_phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2379 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2380 | INIT_LIST_HEAD(&phba->port_list); |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 2381 | init_waitqueue_head(&phba->wait_4_mlo_m_q); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2382 | /* |
| 2383 | * Get all the module params for configuring this host and then |
| 2384 | * establish the host. |
| 2385 | */ |
| 2386 | lpfc_get_cfgparam(phba); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2387 | phba->max_vpi = LPFC_MAX_VPI; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2388 | |
| 2389 | /* Initialize timers used by driver */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2390 | init_timer(&phba->hb_tmofunc); |
| 2391 | phba->hb_tmofunc.function = lpfc_hb_timeout; |
| 2392 | phba->hb_tmofunc.data = (unsigned long)phba; |
| 2393 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2394 | psli = &phba->sli; |
| 2395 | init_timer(&psli->mbox_tmo); |
| 2396 | psli->mbox_tmo.function = lpfc_mbox_timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2397 | psli->mbox_tmo.data = (unsigned long) phba; |
James.Smart@Emulex.Com | 875fbdf | 2005-11-29 16:32:13 -0500 | [diff] [blame] | 2398 | init_timer(&phba->fcp_poll_timer); |
| 2399 | phba->fcp_poll_timer.function = lpfc_poll_timeout; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2400 | phba->fcp_poll_timer.data = (unsigned long) phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2401 | init_timer(&phba->fabric_block_timer); |
| 2402 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; |
| 2403 | phba->fabric_block_timer.data = (unsigned long) phba; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2404 | init_timer(&phba->eratt_poll); |
| 2405 | phba->eratt_poll.function = lpfc_poll_eratt; |
| 2406 | phba->eratt_poll.data = (unsigned long) phba; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2407 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2408 | pci_set_master(pdev); |
Randy Dunlap | 694625c | 2007-07-09 11:55:54 -0700 | [diff] [blame] | 2409 | pci_try_set_mwi(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2410 | |
| 2411 | if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0) |
| 2412 | if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0) |
| 2413 | goto out_idr_remove; |
| 2414 | |
| 2415 | /* |
| 2416 | * Get the bus address of Bar0 and Bar2 and the number of bytes |
| 2417 | * required by each mapping. |
| 2418 | */ |
| 2419 | phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0); |
| 2420 | bar0map_len = pci_resource_len(phba->pcidev, 0); |
| 2421 | |
| 2422 | phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2); |
| 2423 | bar2map_len = pci_resource_len(phba->pcidev, 2); |
| 2424 | |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2425 | /* Map HBA SLIM to a kernel virtual address. */ |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2426 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2427 | if (!phba->slim_memmap_p) { |
| 2428 | error = -ENODEV; |
| 2429 | dev_printk(KERN_ERR, &pdev->dev, |
| 2430 | "ioremap failed for SLIM memory.\n"); |
| 2431 | goto out_idr_remove; |
| 2432 | } |
| 2433 | |
| 2434 | /* Map HBA Control Registers to a kernel virtual address. */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2435 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2436 | if (!phba->ctrl_regs_memmap_p) { |
| 2437 | error = -ENODEV; |
| 2438 | dev_printk(KERN_ERR, &pdev->dev, |
| 2439 | "ioremap failed for HBA control registers.\n"); |
| 2440 | goto out_iounmap_slim; |
| 2441 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2442 | |
| 2443 | /* Allocate memory for SLI-2 structures */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2444 | phba->slim2p.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 2445 | SLI2_SLIM_SIZE, |
| 2446 | &phba->slim2p.phys, |
| 2447 | GFP_KERNEL); |
| 2448 | if (!phba->slim2p.virt) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2449 | goto out_iounmap; |
| 2450 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2451 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 2452 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
| 2453 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
| 2454 | phba->IOCBs = (phba->slim2p.virt + |
| 2455 | offsetof(struct lpfc_sli2_slim, IOCBs)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2456 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2457 | phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev, |
| 2458 | lpfc_sli_hbq_size(), |
| 2459 | &phba->hbqslimp.phys, |
| 2460 | GFP_KERNEL); |
| 2461 | if (!phba->hbqslimp.virt) |
| 2462 | goto out_free_slim; |
| 2463 | |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2464 | hbq_count = lpfc_sli_hbq_count(); |
| 2465 | ptr = phba->hbqslimp.virt; |
| 2466 | for (i = 0; i < hbq_count; ++i) { |
| 2467 | phba->hbqs[i].hbq_virt = ptr; |
| 2468 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); |
| 2469 | ptr += (lpfc_hbq_defs[i]->entry_count * |
| 2470 | sizeof(struct lpfc_hbq_entry)); |
| 2471 | } |
| 2472 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; |
| 2473 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; |
| 2474 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2475 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); |
| 2476 | |
James Smart | 3163f72 | 2008-02-08 18:50:25 -0500 | [diff] [blame] | 2477 | INIT_LIST_HEAD(&phba->hbqbuf_in_list); |
| 2478 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2479 | /* Initialize the SLI Layer to run with lpfc HBAs. */ |
| 2480 | lpfc_sli_setup(phba); |
| 2481 | lpfc_sli_queue_setup(phba); |
| 2482 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2483 | retval = lpfc_mem_alloc(phba); |
| 2484 | if (retval) { |
| 2485 | error = retval; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2486 | goto out_free_hbqslimp; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2487 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2488 | |
| 2489 | /* Initialize and populate the iocb list per host. */ |
| 2490 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); |
| 2491 | for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) { |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 2492 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2493 | if (iocbq_entry == NULL) { |
| 2494 | printk(KERN_ERR "%s: only allocated %d iocbs of " |
| 2495 | "expected %d count. Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2496 | __func__, i, LPFC_IOCB_LIST_CNT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2497 | error = -ENOMEM; |
| 2498 | goto out_free_iocbq; |
| 2499 | } |
| 2500 | |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2501 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
| 2502 | if (iotag == 0) { |
| 2503 | kfree (iocbq_entry); |
| 2504 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
| 2505 | "Unloading driver.\n", |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 2506 | __func__); |
James Bottomley | 604a3e3 | 2005-10-29 10:28:33 -0500 | [diff] [blame] | 2507 | error = -ENOMEM; |
| 2508 | goto out_free_iocbq; |
| 2509 | } |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2510 | |
| 2511 | spin_lock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2512 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
| 2513 | phba->total_iocbq_bufs++; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2514 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | /* Initialize HBA structure */ |
| 2518 | phba->fc_edtov = FF_DEF_EDTOV; |
| 2519 | phba->fc_ratov = FF_DEF_RATOV; |
| 2520 | phba->fc_altov = FF_DEF_ALTOV; |
| 2521 | phba->fc_arbtov = FF_DEF_ARBTOV; |
| 2522 | |
| 2523 | INIT_LIST_HEAD(&phba->work_list); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2524 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2525 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); |
| 2526 | |
James Smart | 5e9d9b8 | 2008-06-14 22:52:53 -0400 | [diff] [blame] | 2527 | /* Initialize the wait queue head for the kernel thread */ |
| 2528 | init_waitqueue_head(&phba->work_waitq); |
| 2529 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2530 | /* Startup the kernel thread for this host adapter. */ |
| 2531 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 2532 | "lpfc_worker_%d", phba->brd_no); |
| 2533 | if (IS_ERR(phba->worker_thread)) { |
| 2534 | error = PTR_ERR(phba->worker_thread); |
| 2535 | goto out_free_iocbq; |
| 2536 | } |
| 2537 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2538 | /* 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] | 2539 | spin_lock_init(&phba->scsi_buf_list_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2540 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); |
| 2541 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2542 | /* Initialize list of fabric iocbs */ |
| 2543 | INIT_LIST_HEAD(&phba->fabric_iocb_list); |
| 2544 | |
James Smart | 0ff10d4 | 2008-01-11 01:52:36 -0500 | [diff] [blame] | 2545 | /* Initialize list to save ELS buffers */ |
| 2546 | INIT_LIST_HEAD(&phba->elsbuf); |
| 2547 | |
James Smart | 3de2a65 | 2007-08-02 11:09:59 -0400 | [diff] [blame] | 2548 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2549 | if (!vport) |
| 2550 | goto out_kthread_stop; |
| 2551 | |
| 2552 | shost = lpfc_shost_from_vport(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2553 | phba->pport = vport; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2554 | lpfc_debugfs_initialize(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2555 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2556 | pci_set_drvdata(pdev, shost); |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2557 | phba->intr_type = NONE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2558 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2559 | phba->MBslimaddr = phba->slim_memmap_p; |
| 2560 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; |
| 2561 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; |
| 2562 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; |
| 2563 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; |
| 2564 | |
| 2565 | /* Configure and enable interrupt */ |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2566 | if (phba->cfg_use_msi == 2) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2567 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 2568 | error = lpfc_sli_config_port(phba, 3); |
| 2569 | if (error) |
| 2570 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2571 | "0427 Firmware not capable of SLI 3 mode.\n"); |
| 2572 | else { |
| 2573 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2574 | "0426 Firmware capable of SLI 3 mode.\n"); |
| 2575 | /* Now, try to enable MSI-X interrupt mode */ |
| 2576 | error = lpfc_enable_msix(phba); |
| 2577 | if (!error) { |
| 2578 | phba->intr_type = MSIX; |
| 2579 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2580 | "0430 enable MSI-X mode.\n"); |
| 2581 | } |
| 2582 | } |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2583 | } |
| 2584 | |
| 2585 | /* Fallback to MSI if MSI-X initialization failed */ |
| 2586 | if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) { |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2587 | retval = pci_enable_msi(phba->pcidev); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2588 | if (!retval) { |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2589 | phba->intr_type = MSI; |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 2590 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2591 | "0473 enable MSI mode.\n"); |
| 2592 | } else |
| 2593 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2594 | "0452 enable IRQ mode.\n"); |
James Smart | 4ff4324 | 2006-12-02 13:34:56 -0500 | [diff] [blame] | 2595 | } |
| 2596 | |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2597 | /* MSI-X is the only case the doesn't need to call request_irq */ |
| 2598 | if (phba->intr_type != MSIX) { |
| 2599 | retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, |
| 2600 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 2601 | if (retval) { |
| 2602 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0451 Enable " |
| 2603 | "interrupt handler failed\n"); |
| 2604 | error = retval; |
| 2605 | goto out_disable_msi; |
| 2606 | } else if (phba->intr_type != MSI) |
| 2607 | phba->intr_type = INTx; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2608 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2609 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2610 | if (lpfc_alloc_sysfs_attr(vport)) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2611 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2612 | "1476 Failed to allocate sysfs attr\n"); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2613 | error = -ENOMEM; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2614 | goto out_free_irq; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2615 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2616 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2617 | if (lpfc_sli_hba_setup(phba)) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2618 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2619 | "1477 Failed to set up hba\n"); |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2620 | error = -ENODEV; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2621 | goto out_remove_device; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 2622 | } |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2623 | |
| 2624 | /* |
| 2625 | * hba setup may have changed the hba_queue_depth so we need to adjust |
| 2626 | * the value of can_queue. |
| 2627 | */ |
| 2628 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
| 2629 | |
| 2630 | lpfc_host_attrib_init(shost); |
| 2631 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2632 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { |
| 2633 | spin_lock_irq(shost->host_lock); |
| 2634 | lpfc_poll_start_timer(phba); |
| 2635 | spin_unlock_irq(shost->host_lock); |
| 2636 | } |
James Smart | 8f6d98d | 2006-08-01 07:34:00 -0400 | [diff] [blame] | 2637 | |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2638 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2639 | "0428 Perform SCSI scan\n"); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2640 | /* Send board arrival event to upper layer */ |
| 2641 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; |
| 2642 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; |
| 2643 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
| 2644 | sizeof(adapter_event), |
| 2645 | (char *) &adapter_event, |
James Smart | ddcc50f | 2008-12-04 22:38:46 -0500 | [diff] [blame] | 2646 | LPFC_NL_VENDOR_ID); |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 2647 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2648 | scsi_scan_host(shost); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2649 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2650 | return 0; |
| 2651 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2652 | out_remove_device: |
| 2653 | lpfc_free_sysfs_attr(vport); |
| 2654 | spin_lock_irq(shost->host_lock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2655 | vport->load_flag |= FC_UNLOADING; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2656 | spin_unlock_irq(shost->host_lock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2657 | out_free_irq: |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2658 | lpfc_stop_phba_timers(phba); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2659 | phba->pport->work_port_events = 0; |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2660 | |
| 2661 | if (phba->intr_type == MSIX) |
| 2662 | lpfc_disable_msix(phba); |
| 2663 | else |
| 2664 | free_irq(phba->pcidev->irq, phba); |
| 2665 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2666 | out_disable_msi: |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2667 | if (phba->intr_type == MSI) |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2668 | pci_disable_msi(phba->pcidev); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2669 | destroy_port(vport); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2670 | out_kthread_stop: |
| 2671 | kthread_stop(phba->worker_thread); |
| 2672 | out_free_iocbq: |
| 2673 | list_for_each_entry_safe(iocbq_entry, iocbq_next, |
| 2674 | &phba->lpfc_iocb_list, list) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2675 | kfree(iocbq_entry); |
| 2676 | phba->total_iocbq_bufs--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2677 | } |
| 2678 | lpfc_mem_free(phba); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2679 | out_free_hbqslimp: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2680 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 2681 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2682 | out_free_slim: |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2683 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
| 2684 | phba->slim2p.virt, phba->slim2p.phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2685 | out_iounmap: |
| 2686 | iounmap(phba->ctrl_regs_memmap_p); |
Jamie Wellnitz | 901a920 | 2006-02-28 19:25:19 -0500 | [diff] [blame] | 2687 | out_iounmap_slim: |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2688 | iounmap(phba->slim_memmap_p); |
| 2689 | out_idr_remove: |
| 2690 | idr_remove(&lpfc_hba_index, phba->brd_no); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2691 | out_free_phba: |
| 2692 | kfree(phba); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2693 | out_release_regions: |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2694 | pci_release_selected_regions(pdev, bars); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2695 | out_disable_device: |
| 2696 | pci_disable_device(pdev); |
| 2697 | out: |
James Smart | defbcf1 | 2006-04-16 22:26:50 -0400 | [diff] [blame] | 2698 | pci_set_drvdata(pdev, NULL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2699 | if (shost) |
| 2700 | scsi_host_put(shost); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2701 | return error; |
| 2702 | } |
| 2703 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2704 | /** |
| 2705 | * lpfc_pci_remove_one: lpfc PCI func to unregister device from PCI subsystem. |
| 2706 | * @pdev: pointer to PCI device |
| 2707 | * |
| 2708 | * This routine is to be registered to the kernel's PCI subsystem. When an |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 2709 | * Emulex HBA is removed from PCI bus, it performs all the necessary cleanup |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2710 | * for the HBA device to be removed from the PCI subsystem properly. |
| 2711 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2712 | static void __devexit |
| 2713 | lpfc_pci_remove_one(struct pci_dev *pdev) |
| 2714 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2715 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2716 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame^] | 2717 | struct lpfc_vport **vports; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2718 | struct lpfc_hba *phba = vport->phba; |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame^] | 2719 | int i; |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2720 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); |
| 2721 | |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2722 | spin_lock_irq(&phba->hbalock); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2723 | vport->load_flag |= FC_UNLOADING; |
James Smart | 549e55c | 2007-08-02 11:09:51 -0400 | [diff] [blame] | 2724 | spin_unlock_irq(&phba->hbalock); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2725 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2726 | lpfc_free_sysfs_attr(vport); |
| 2727 | |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 2728 | kthread_stop(phba->worker_thread); |
| 2729 | |
James Smart | eada272 | 2008-12-04 22:39:13 -0500 | [diff] [blame^] | 2730 | /* Release all the vports against this physical port */ |
| 2731 | vports = lpfc_create_vport_work_array(phba); |
| 2732 | if (vports != NULL) |
| 2733 | for (i = 1; i <= phba->max_vpi && vports[i] != NULL; i++) |
| 2734 | fc_vport_terminate(vports[i]->fc_vport); |
| 2735 | lpfc_destroy_vport_work_array(phba, vports); |
| 2736 | |
| 2737 | /* Remove FC host and then SCSI host with the physical port */ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2738 | fc_remove_host(shost); |
| 2739 | scsi_remove_host(shost); |
James Smart | 87af33f | 2007-10-27 13:37:43 -0400 | [diff] [blame] | 2740 | lpfc_cleanup(vport); |
| 2741 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2742 | /* |
| 2743 | * Bring down the SLI Layer. This step disable all interrupts, |
| 2744 | * clears the rings, discards all mailbox commands, and resets |
| 2745 | * the HBA. |
| 2746 | */ |
| 2747 | lpfc_sli_hba_down(phba); |
| 2748 | lpfc_sli_brdrestart(phba); |
| 2749 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2750 | lpfc_stop_phba_timers(phba); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2751 | spin_lock_irq(&phba->hbalock); |
| 2752 | list_del_init(&vport->listentry); |
| 2753 | spin_unlock_irq(&phba->hbalock); |
| 2754 | |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2755 | lpfc_debugfs_terminate(vport); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2756 | |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2757 | if (phba->intr_type == MSIX) |
| 2758 | lpfc_disable_msix(phba); |
| 2759 | else { |
| 2760 | free_irq(phba->pcidev->irq, phba); |
| 2761 | if (phba->intr_type == MSI) |
| 2762 | pci_disable_msi(phba->pcidev); |
| 2763 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2764 | |
| 2765 | pci_set_drvdata(pdev, NULL); |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 2766 | scsi_host_put(shost); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2767 | |
| 2768 | /* |
| 2769 | * Call scsi_free before mem_free since scsi bufs are released to their |
| 2770 | * corresponding pools here. |
| 2771 | */ |
| 2772 | lpfc_scsi_free(phba); |
| 2773 | lpfc_mem_free(phba); |
| 2774 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2775 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), |
| 2776 | phba->hbqslimp.virt, phba->hbqslimp.phys); |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 2777 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2778 | /* Free resources associated with SLI2 interface */ |
| 2779 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 2780 | phba->slim2p.virt, phba->slim2p.phys); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2781 | |
| 2782 | /* unmap adapter SLIM and Control Registers */ |
| 2783 | iounmap(phba->ctrl_regs_memmap_p); |
| 2784 | iounmap(phba->slim_memmap_p); |
| 2785 | |
| 2786 | idr_remove(&lpfc_hba_index, phba->brd_no); |
| 2787 | |
| 2788 | kfree(phba); |
| 2789 | |
Tomohiro Kusumi | 8a4df120 | 2008-01-11 01:53:00 -0500 | [diff] [blame] | 2790 | pci_release_selected_regions(pdev, bars); |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 2791 | pci_disable_device(pdev); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 2792 | } |
| 2793 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2794 | /** |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 2795 | * lpfc_pci_suspend_one: lpfc PCI func to suspend device for power management. |
| 2796 | * @pdev: pointer to PCI device |
| 2797 | * @msg: power management message |
| 2798 | * |
| 2799 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 2800 | * system Power Management (PM). When PM invokes this method, it quiesces the |
| 2801 | * device by stopping the driver's worker thread for the device, turning off |
| 2802 | * device's interrupt and DMA, and bring the device offline. Note that as the |
| 2803 | * driver implements the minimum PM requirements to a power-aware driver's PM |
| 2804 | * support for suspend/resume -- all the possible PM messages (SUSPEND, |
| 2805 | * HIBERNATE, FREEZE) to the suspend() method call will be treated as SUSPEND |
| 2806 | * and the driver will fully reinitialize its device during resume() method |
| 2807 | * call, the driver will set device to PCI_D3hot state in PCI config space |
| 2808 | * instead of setting it according to the @msg provided by the PM. |
| 2809 | * |
| 2810 | * Return code |
| 2811 | * 0 - driver suspended the device |
| 2812 | * Error otherwise |
| 2813 | **/ |
| 2814 | static int |
| 2815 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) |
| 2816 | { |
| 2817 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2818 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 2819 | |
| 2820 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2821 | "0473 PCI device Power Management suspend.\n"); |
| 2822 | |
| 2823 | /* Bring down the device */ |
| 2824 | lpfc_offline_prep(phba); |
| 2825 | lpfc_offline(phba); |
| 2826 | kthread_stop(phba->worker_thread); |
| 2827 | |
| 2828 | /* Disable interrupt from device */ |
| 2829 | lpfc_disable_intr(phba); |
| 2830 | |
| 2831 | /* Save device state to PCI config space */ |
| 2832 | pci_save_state(pdev); |
| 2833 | pci_set_power_state(pdev, PCI_D3hot); |
| 2834 | |
| 2835 | return 0; |
| 2836 | } |
| 2837 | |
| 2838 | /** |
| 2839 | * lpfc_pci_resume_one: lpfc PCI func to resume device for power management. |
| 2840 | * @pdev: pointer to PCI device |
| 2841 | * |
| 2842 | * This routine is to be registered to the kernel's PCI subsystem to support |
| 2843 | * system Power Management (PM). When PM invokes this method, it restores |
| 2844 | * the device's PCI config space state and fully reinitializes the device |
| 2845 | * and brings it online. Note that as the driver implements the minimum PM |
| 2846 | * requirements to a power-aware driver's PM for suspend/resume -- all |
| 2847 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() |
| 2848 | * method call will be treated as SUSPEND and the driver will fully |
| 2849 | * reinitialize its device during resume() method call, the device will be |
| 2850 | * set to PCI_D0 directly in PCI config space before restoring the state. |
| 2851 | * |
| 2852 | * Return code |
| 2853 | * 0 - driver suspended the device |
| 2854 | * Error otherwise |
| 2855 | **/ |
| 2856 | static int |
| 2857 | lpfc_pci_resume_one(struct pci_dev *pdev) |
| 2858 | { |
| 2859 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2860 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
| 2861 | int error; |
| 2862 | |
| 2863 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2864 | "0452 PCI device Power Management resume.\n"); |
| 2865 | |
| 2866 | /* Restore device state from PCI config space */ |
| 2867 | pci_set_power_state(pdev, PCI_D0); |
| 2868 | pci_restore_state(pdev); |
| 2869 | if (pdev->is_busmaster) |
| 2870 | pci_set_master(pdev); |
| 2871 | |
| 2872 | /* Startup the kernel thread for this host adapter. */ |
| 2873 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
| 2874 | "lpfc_worker_%d", phba->brd_no); |
| 2875 | if (IS_ERR(phba->worker_thread)) { |
| 2876 | error = PTR_ERR(phba->worker_thread); |
| 2877 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2878 | "0434 PM resume failed to start worker " |
| 2879 | "thread: error=x%x.\n", error); |
| 2880 | return error; |
| 2881 | } |
| 2882 | |
| 2883 | /* Enable interrupt from device */ |
| 2884 | error = lpfc_enable_intr(phba); |
| 2885 | if (error) { |
| 2886 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2887 | "0430 PM resume Failed to enable interrupt: " |
| 2888 | "error=x%x.\n", error); |
| 2889 | return error; |
| 2890 | } |
| 2891 | |
| 2892 | /* Restart HBA and bring it online */ |
| 2893 | lpfc_sli_brdrestart(phba); |
| 2894 | lpfc_online(phba); |
| 2895 | |
| 2896 | return 0; |
| 2897 | } |
| 2898 | |
| 2899 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2900 | * lpfc_io_error_detected: Driver method for handling PCI I/O error detected. |
| 2901 | * @pdev: pointer to PCI device. |
| 2902 | * @state: the current PCI connection state. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2903 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2904 | * This routine is registered to the PCI subsystem for error handling. This |
| 2905 | * function is called by the PCI subsystem after a PCI bus error affecting |
| 2906 | * this device has been detected. When this function is invoked, it will |
| 2907 | * need to stop all the I/Os and interrupt(s) to the device. Once that is |
| 2908 | * done, it will return PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to |
| 2909 | * perform proper recovery as desired. |
| 2910 | * |
| 2911 | * Return codes |
| 2912 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
| 2913 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
| 2914 | **/ |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2915 | static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev, |
| 2916 | pci_channel_state_t state) |
| 2917 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2918 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2919 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2920 | struct lpfc_sli *psli = &phba->sli; |
| 2921 | struct lpfc_sli_ring *pring; |
| 2922 | |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2923 | if (state == pci_channel_io_perm_failure) { |
| 2924 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 2925 | "0472 PCI channel I/O permanent failure\n"); |
| 2926 | /* Block all SCSI devices' I/Os on the host */ |
| 2927 | lpfc_scsi_dev_block(phba); |
| 2928 | /* Clean up all driver's outstanding SCSI I/Os */ |
| 2929 | lpfc_sli_flush_fcp_rings(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2930 | return PCI_ERS_RESULT_DISCONNECT; |
James Smart | a8e497d | 2008-08-24 21:50:11 -0400 | [diff] [blame] | 2931 | } |
Linas Vepstas | 5daa49e | 2007-03-08 16:19:11 -0600 | [diff] [blame] | 2932 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2933 | pci_disable_device(pdev); |
| 2934 | /* |
| 2935 | * There may be I/Os dropped by the firmware. |
| 2936 | * Error iocb (I/O) on txcmplq and let the SCSI layer |
| 2937 | * retry it after re-establishing link. |
| 2938 | */ |
| 2939 | pring = &psli->ring[psli->fcp_ring]; |
| 2940 | lpfc_sli_abort_iocb_ring(phba, pring); |
| 2941 | |
James Smart | db2378e | 2008-02-08 18:49:51 -0500 | [diff] [blame] | 2942 | if (phba->intr_type == MSIX) |
| 2943 | lpfc_disable_msix(phba); |
| 2944 | else { |
| 2945 | free_irq(phba->pcidev->irq, phba); |
| 2946 | if (phba->intr_type == MSI) |
| 2947 | pci_disable_msi(phba->pcidev); |
| 2948 | } |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2949 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2950 | /* Request a slot reset. */ |
| 2951 | return PCI_ERS_RESULT_NEED_RESET; |
| 2952 | } |
| 2953 | |
| 2954 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2955 | * lpfc_io_slot_reset: Restart a PCI device from scratch. |
| 2956 | * @pdev: pointer to PCI device. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2957 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 2958 | * This routine is registered to the PCI subsystem for error handling. This is |
| 2959 | * called after PCI bus has been reset to restart the PCI card from scratch, |
| 2960 | * as if from a cold-boot. During the PCI subsystem error recovery, after the |
| 2961 | * driver returns PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform |
| 2962 | * proper error recovery and then call this routine before calling the .resume |
| 2963 | * method to recover the device. This function will initialize the HBA device, |
| 2964 | * enable the interrupt, but it will just put the HBA to offline state without |
| 2965 | * passing any I/O traffic. |
| 2966 | * |
| 2967 | * Return codes |
| 2968 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
| 2969 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2970 | */ |
| 2971 | static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev) |
| 2972 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 2973 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 2974 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2975 | struct lpfc_sli *psli = &phba->sli; |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 2976 | int error, retval; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2977 | |
| 2978 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); |
Benjamin Herrenschmidt | 0948391 | 2007-12-20 15:28:09 +1100 | [diff] [blame] | 2979 | if (pci_enable_device_mem(pdev)) { |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2980 | printk(KERN_ERR "lpfc: Cannot re-enable " |
| 2981 | "PCI device after reset.\n"); |
| 2982 | return PCI_ERS_RESULT_DISCONNECT; |
| 2983 | } |
| 2984 | |
| 2985 | pci_set_master(pdev); |
| 2986 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2987 | spin_lock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2988 | psli->sli_flag &= ~LPFC_SLI2_ACTIVE; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 2989 | spin_unlock_irq(&phba->hbalock); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 2990 | |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 2991 | /* Enable configured interrupt method */ |
| 2992 | phba->intr_type = NONE; |
| 2993 | if (phba->cfg_use_msi == 2) { |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 2994 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ |
| 2995 | error = lpfc_sli_config_port(phba, 3); |
| 2996 | if (error) |
| 2997 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 2998 | "0478 Firmware not capable of SLI 3 mode.\n"); |
| 2999 | else { |
| 3000 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3001 | "0479 Firmware capable of SLI 3 mode.\n"); |
| 3002 | /* Now, try to enable MSI-X interrupt mode */ |
| 3003 | error = lpfc_enable_msix(phba); |
| 3004 | if (!error) { |
| 3005 | phba->intr_type = MSIX; |
| 3006 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3007 | "0480 enable MSI-X mode.\n"); |
| 3008 | } |
| 3009 | } |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 3010 | } |
| 3011 | |
| 3012 | /* Fallback to MSI if MSI-X initialization failed */ |
| 3013 | if (phba->cfg_use_msi >= 1 && phba->intr_type == NONE) { |
| 3014 | retval = pci_enable_msi(phba->pcidev); |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3015 | if (!retval) { |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 3016 | phba->intr_type = MSI; |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 3017 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 3018 | "0481 enable MSI mode.\n"); |
| 3019 | } else |
| 3020 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
| 3021 | "0470 enable IRQ mode.\n"); |
James Smart | 9b37960 | 2008-04-07 10:16:00 -0400 | [diff] [blame] | 3022 | } |
| 3023 | |
| 3024 | /* MSI-X is the only case the doesn't need to call request_irq */ |
| 3025 | if (phba->intr_type != MSIX) { |
| 3026 | retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, |
| 3027 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); |
| 3028 | if (retval) { |
| 3029 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 3030 | "0471 Enable interrupt handler " |
| 3031 | "failed\n"); |
| 3032 | } else if (phba->intr_type != MSI) |
| 3033 | phba->intr_type = INTx; |
| 3034 | } |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3035 | |
| 3036 | /* Take device offline; this will perform cleanup */ |
| 3037 | lpfc_offline(phba); |
| 3038 | lpfc_sli_brdrestart(phba); |
| 3039 | |
| 3040 | return PCI_ERS_RESULT_RECOVERED; |
| 3041 | } |
| 3042 | |
| 3043 | /** |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3044 | * lpfc_io_resume: Resume PCI I/O operation. |
| 3045 | * @pdev: pointer to PCI device |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3046 | * |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3047 | * This routine is registered to the PCI subsystem for error handling. It is |
| 3048 | * called when kernel error recovery tells the lpfc driver that it is ok to |
| 3049 | * resume normal PCI operation after PCI bus error recovery. After this call, |
| 3050 | * traffic can start to flow from this device again. |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3051 | */ |
| 3052 | static void lpfc_io_resume(struct pci_dev *pdev) |
| 3053 | { |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 3054 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
| 3055 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3056 | |
James Smart | 58da1ff | 2008-04-07 10:15:56 -0400 | [diff] [blame] | 3057 | lpfc_online(phba); |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3058 | } |
| 3059 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3060 | static struct pci_device_id lpfc_id_table[] = { |
| 3061 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, |
| 3062 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | 06325e7 | 2005-06-25 10:34:22 -0400 | [diff] [blame] | 3063 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
| 3064 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3065 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
| 3066 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3067 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, |
| 3068 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3069 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, |
| 3070 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3071 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, |
| 3072 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3073 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, |
| 3074 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3075 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, |
| 3076 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3077 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, |
| 3078 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 3079 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
| 3080 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3081 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, |
| 3082 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3083 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, |
| 3084 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3085 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
| 3086 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 3087 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
| 3088 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3089 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, |
| 3090 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3091 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
| 3092 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3093 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, |
| 3094 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3095 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, |
| 3096 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3097 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
| 3098 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 3099 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
| 3100 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3101 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, |
| 3102 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3103 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
| 3104 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3105 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, |
| 3106 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3107 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, |
| 3108 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3109 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, |
| 3110 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3111 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, |
| 3112 | PCI_ANY_ID, PCI_ANY_ID, }, |
James.Smart@Emulex.Com | e4adb20 | 2005-11-28 11:42:12 -0500 | [diff] [blame] | 3113 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
| 3114 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3115 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, |
| 3116 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | b87eab3 | 2007-04-25 09:53:28 -0400 | [diff] [blame] | 3117 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
| 3118 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3119 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, |
| 3120 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3121 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, |
| 3122 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3123 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, |
| 3124 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3125 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, |
| 3126 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3127 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, |
| 3128 | PCI_ANY_ID, PCI_ANY_ID, }, |
James Smart | 84774a4 | 2008-08-24 21:50:06 -0400 | [diff] [blame] | 3129 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
| 3130 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3131 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, |
| 3132 | PCI_ANY_ID, PCI_ANY_ID, }, |
| 3133 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, |
| 3134 | PCI_ANY_ID, PCI_ANY_ID, }, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3135 | { 0 } |
| 3136 | }; |
| 3137 | |
| 3138 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
| 3139 | |
Linas Vepstas | 8d63f37 | 2007-02-14 14:28:36 -0600 | [diff] [blame] | 3140 | static struct pci_error_handlers lpfc_err_handler = { |
| 3141 | .error_detected = lpfc_io_error_detected, |
| 3142 | .slot_reset = lpfc_io_slot_reset, |
| 3143 | .resume = lpfc_io_resume, |
| 3144 | }; |
| 3145 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3146 | static struct pci_driver lpfc_driver = { |
| 3147 | .name = LPFC_DRIVER_NAME, |
| 3148 | .id_table = lpfc_id_table, |
| 3149 | .probe = lpfc_pci_probe_one, |
| 3150 | .remove = __devexit_p(lpfc_pci_remove_one), |
James Smart | 3a55b53 | 2008-12-04 22:38:54 -0500 | [diff] [blame] | 3151 | .suspend = lpfc_pci_suspend_one, |
| 3152 | .resume = lpfc_pci_resume_one, |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 3153 | .err_handler = &lpfc_err_handler, |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3154 | }; |
| 3155 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3156 | /** |
| 3157 | * lpfc_init: lpfc module initialization routine. |
| 3158 | * |
| 3159 | * This routine is to be invoked when the lpfc module is loaded into the |
| 3160 | * kernel. The special kernel macro module_init() is used to indicate the |
| 3161 | * role of this routine to the kernel as lpfc module entry point. |
| 3162 | * |
| 3163 | * Return codes |
| 3164 | * 0 - successful |
| 3165 | * -ENOMEM - FC attach transport failed |
| 3166 | * all others - failed |
| 3167 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3168 | static int __init |
| 3169 | lpfc_init(void) |
| 3170 | { |
| 3171 | int error = 0; |
| 3172 | |
| 3173 | printk(LPFC_MODULE_DESC "\n"); |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3174 | printk(LPFC_COPYRIGHT "\n"); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3175 | |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3176 | if (lpfc_enable_npiv) { |
| 3177 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
| 3178 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; |
| 3179 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3180 | lpfc_transport_template = |
| 3181 | fc_attach_transport(&lpfc_transport_functions); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3182 | if (lpfc_transport_template == NULL) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3183 | return -ENOMEM; |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3184 | if (lpfc_enable_npiv) { |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3185 | lpfc_vport_transport_template = |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3186 | fc_attach_transport(&lpfc_vport_transport_functions); |
| 3187 | if (lpfc_vport_transport_template == NULL) { |
| 3188 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3189 | return -ENOMEM; |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 3190 | } |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3191 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3192 | error = pci_register_driver(&lpfc_driver); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3193 | if (error) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3194 | fc_release_transport(lpfc_transport_template); |
James Smart | d7c255b | 2008-08-24 21:50:00 -0400 | [diff] [blame] | 3195 | if (lpfc_enable_npiv) |
| 3196 | fc_release_transport(lpfc_vport_transport_template); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 3197 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3198 | |
| 3199 | return error; |
| 3200 | } |
| 3201 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 3202 | /** |
| 3203 | * lpfc_exit: lpfc module removal routine. |
| 3204 | * |
| 3205 | * This routine is invoked when the lpfc module is removed from the kernel. |
| 3206 | * The special kernel macro module_exit() is used to indicate the role of |
| 3207 | * this routine to the kernel as lpfc module exit point. |
| 3208 | */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3209 | static void __exit |
| 3210 | lpfc_exit(void) |
| 3211 | { |
| 3212 | pci_unregister_driver(&lpfc_driver); |
| 3213 | fc_release_transport(lpfc_transport_template); |
James Smart | 7ee5d43 | 2007-10-27 13:37:17 -0400 | [diff] [blame] | 3214 | if (lpfc_enable_npiv) |
| 3215 | fc_release_transport(lpfc_vport_transport_template); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | module_init(lpfc_init); |
| 3219 | module_exit(lpfc_exit); |
| 3220 | MODULE_LICENSE("GPL"); |
| 3221 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); |
| 3222 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); |
| 3223 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |