Commit | Line | Data |
---|---|---|
dea3101e | 1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
4fede78f | 4 | * Copyright (C) 2004-2010 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e | 8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
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. * | |
dea3101e | 20 | *******************************************************************/ |
21 | ||
dea3101e | 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> | |
92d7f7b0 | 30 | #include <linux/ctype.h> |
0d878419 | 31 | #include <linux/aer.h> |
5a0e3ad6 | 32 | #include <linux/slab.h> |
dea3101e | 33 | |
91886523 | 34 | #include <scsi/scsi.h> |
dea3101e | 35 | #include <scsi/scsi_device.h> |
36 | #include <scsi/scsi_host.h> | |
37 | #include <scsi/scsi_transport_fc.h> | |
38 | ||
da0436e9 | 39 | #include "lpfc_hw4.h" |
dea3101e | 40 | #include "lpfc_hw.h" |
41 | #include "lpfc_sli.h" | |
da0436e9 | 42 | #include "lpfc_sli4.h" |
ea2151b4 | 43 | #include "lpfc_nl.h" |
dea3101e | 44 | #include "lpfc_disc.h" |
45 | #include "lpfc_scsi.h" | |
46 | #include "lpfc.h" | |
47 | #include "lpfc_logmsg.h" | |
48 | #include "lpfc_crtn.h" | |
92d7f7b0 | 49 | #include "lpfc_vport.h" |
dea3101e | 50 | #include "lpfc_version.h" |
51 | ||
81301a9b JS |
52 | char *_dump_buf_data; |
53 | unsigned long _dump_buf_data_order; | |
54 | char *_dump_buf_dif; | |
55 | unsigned long _dump_buf_dif_order; | |
56 | spinlock_t _dump_buf_lock; | |
57 | ||
dea3101e | 58 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
59 | static int lpfc_post_rcv_buf(struct lpfc_hba *); | |
da0436e9 JS |
60 | static int lpfc_sli4_queue_create(struct lpfc_hba *); |
61 | static void lpfc_sli4_queue_destroy(struct lpfc_hba *); | |
62 | static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); | |
63 | static int lpfc_setup_endian_order(struct lpfc_hba *); | |
64 | static int lpfc_sli4_read_config(struct lpfc_hba *); | |
65 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); | |
66 | static void lpfc_free_sgl_list(struct lpfc_hba *); | |
67 | static int lpfc_init_sgl_list(struct lpfc_hba *); | |
68 | static int lpfc_init_active_sgl_array(struct lpfc_hba *); | |
69 | static void lpfc_free_active_sgl(struct lpfc_hba *); | |
70 | static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); | |
71 | static int lpfc_hba_down_post_s4(struct lpfc_hba *phba); | |
72 | static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *); | |
73 | static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *); | |
74 | static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *); | |
dea3101e | 75 | |
76 | static struct scsi_transport_template *lpfc_transport_template = NULL; | |
92d7f7b0 | 77 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
dea3101e | 78 | static DEFINE_IDR(lpfc_hba_index); |
79 | ||
e59058c4 | 80 | /** |
3621a710 | 81 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
e59058c4 JS |
82 | * @phba: pointer to lpfc hba data structure. |
83 | * | |
84 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT | |
85 | * mailbox command. It retrieves the revision information from the HBA and | |
86 | * collects the Vital Product Data (VPD) about the HBA for preparing the | |
87 | * configuration of the HBA. | |
88 | * | |
89 | * Return codes: | |
90 | * 0 - success. | |
91 | * -ERESTART - requests the SLI layer to reset the HBA and try again. | |
92 | * Any other value - indicates an error. | |
93 | **/ | |
dea3101e | 94 | int |
2e0fef85 | 95 | lpfc_config_port_prep(struct lpfc_hba *phba) |
dea3101e | 96 | { |
97 | lpfc_vpd_t *vp = &phba->vpd; | |
98 | int i = 0, rc; | |
99 | LPFC_MBOXQ_t *pmb; | |
100 | MAILBOX_t *mb; | |
101 | char *lpfc_vpd_data = NULL; | |
102 | uint16_t offset = 0; | |
103 | static char licensed[56] = | |
104 | "key unlock for use with gnu public licensed code only\0"; | |
65a29c16 | 105 | static int init_key = 1; |
dea3101e | 106 | |
107 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
108 | if (!pmb) { | |
2e0fef85 | 109 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 110 | return -ENOMEM; |
111 | } | |
112 | ||
04c68496 | 113 | mb = &pmb->u.mb; |
2e0fef85 | 114 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 115 | |
116 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { | |
65a29c16 JS |
117 | if (init_key) { |
118 | uint32_t *ptext = (uint32_t *) licensed; | |
dea3101e | 119 | |
65a29c16 JS |
120 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
121 | *ptext = cpu_to_be32(*ptext); | |
122 | init_key = 0; | |
123 | } | |
dea3101e | 124 | |
125 | lpfc_read_nv(phba, pmb); | |
126 | memset((char*)mb->un.varRDnvp.rsvd3, 0, | |
127 | sizeof (mb->un.varRDnvp.rsvd3)); | |
128 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, | |
129 | sizeof (licensed)); | |
130 | ||
131 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
132 | ||
133 | if (rc != MBX_SUCCESS) { | |
ed957684 | 134 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
e8b62011 | 135 | "0324 Config Port initialization " |
dea3101e | 136 | "error, mbxCmd x%x READ_NVPARM, " |
137 | "mbxStatus x%x\n", | |
dea3101e | 138 | mb->mbxCommand, mb->mbxStatus); |
139 | mempool_free(pmb, phba->mbox_mem_pool); | |
140 | return -ERESTART; | |
141 | } | |
142 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, | |
2e0fef85 JS |
143 | sizeof(phba->wwnn)); |
144 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, | |
145 | sizeof(phba->wwpn)); | |
dea3101e | 146 | } |
147 | ||
92d7f7b0 JS |
148 | phba->sli3_options = 0x0; |
149 | ||
dea3101e | 150 | /* Setup and issue mailbox READ REV command */ |
151 | lpfc_read_rev(phba, pmb); | |
152 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
153 | if (rc != MBX_SUCCESS) { | |
ed957684 | 154 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 155 | "0439 Adapter failed to init, mbxCmd x%x " |
dea3101e | 156 | "READ_REV, mbxStatus x%x\n", |
dea3101e | 157 | mb->mbxCommand, mb->mbxStatus); |
158 | mempool_free( pmb, phba->mbox_mem_pool); | |
159 | return -ERESTART; | |
160 | } | |
161 | ||
92d7f7b0 | 162 | |
1de933f3 JSEC |
163 | /* |
164 | * The value of rr must be 1 since the driver set the cv field to 1. | |
165 | * This setting requires the FW to set all revision fields. | |
dea3101e | 166 | */ |
1de933f3 | 167 | if (mb->un.varRdRev.rr == 0) { |
dea3101e | 168 | vp->rev.rBit = 0; |
1de933f3 | 169 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 JS |
170 | "0440 Adapter failed to init, READ_REV has " |
171 | "missing revision information.\n"); | |
dea3101e | 172 | mempool_free(pmb, phba->mbox_mem_pool); |
173 | return -ERESTART; | |
dea3101e | 174 | } |
175 | ||
495a714c JS |
176 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
177 | mempool_free(pmb, phba->mbox_mem_pool); | |
ed957684 | 178 | return -EINVAL; |
495a714c | 179 | } |
ed957684 | 180 | |
dea3101e | 181 | /* Save information as VPD data */ |
1de933f3 | 182 | vp->rev.rBit = 1; |
92d7f7b0 | 183 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
1de933f3 JSEC |
184 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
185 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); | |
186 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; | |
187 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); | |
dea3101e | 188 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
189 | vp->rev.smRev = mb->un.varRdRev.smRev; | |
190 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; | |
191 | vp->rev.endecRev = mb->un.varRdRev.endecRev; | |
192 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; | |
193 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; | |
194 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; | |
195 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; | |
196 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; | |
197 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; | |
198 | ||
92d7f7b0 JS |
199 | /* If the sli feature level is less then 9, we must |
200 | * tear down all RPIs and VPIs on link down if NPIV | |
201 | * is enabled. | |
202 | */ | |
203 | if (vp->rev.feaLevelHigh < 9) | |
204 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; | |
205 | ||
dea3101e | 206 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
207 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], | |
208 | sizeof (phba->RandomData)); | |
209 | ||
dea3101e | 210 | /* Get adapter VPD information */ |
dea3101e | 211 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
212 | if (!lpfc_vpd_data) | |
d7c255b2 | 213 | goto out_free_mbox; |
dea3101e | 214 | |
215 | do { | |
a0c87cbd | 216 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
dea3101e | 217 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
218 | ||
219 | if (rc != MBX_SUCCESS) { | |
220 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 | 221 | "0441 VPD not present on adapter, " |
dea3101e | 222 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
dea3101e | 223 | mb->mbxCommand, mb->mbxStatus); |
74b72a59 | 224 | mb->un.varDmp.word_cnt = 0; |
dea3101e | 225 | } |
04c68496 JS |
226 | /* dump mem may return a zero when finished or we got a |
227 | * mailbox error, either way we are done. | |
228 | */ | |
229 | if (mb->un.varDmp.word_cnt == 0) | |
230 | break; | |
74b72a59 JW |
231 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
232 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; | |
d7c255b2 JS |
233 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
234 | lpfc_vpd_data + offset, | |
92d7f7b0 | 235 | mb->un.varDmp.word_cnt); |
dea3101e | 236 | offset += mb->un.varDmp.word_cnt; |
74b72a59 JW |
237 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
238 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); | |
dea3101e | 239 | |
240 | kfree(lpfc_vpd_data); | |
dea3101e | 241 | out_free_mbox: |
242 | mempool_free(pmb, phba->mbox_mem_pool); | |
243 | return 0; | |
244 | } | |
245 | ||
e59058c4 | 246 | /** |
3621a710 | 247 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
e59058c4 JS |
248 | * @phba: pointer to lpfc hba data structure. |
249 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
250 | * | |
251 | * This is the completion handler for driver's configuring asynchronous event | |
252 | * mailbox command to the device. If the mailbox command returns successfully, | |
253 | * it will set internal async event support flag to 1; otherwise, it will | |
254 | * set internal async event support flag to 0. | |
255 | **/ | |
57127f15 JS |
256 | static void |
257 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
258 | { | |
04c68496 | 259 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
57127f15 JS |
260 | phba->temp_sensor_support = 1; |
261 | else | |
262 | phba->temp_sensor_support = 0; | |
263 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
264 | return; | |
265 | } | |
266 | ||
97207482 | 267 | /** |
3621a710 | 268 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
97207482 JS |
269 | * @phba: pointer to lpfc hba data structure. |
270 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
271 | * | |
272 | * This is the completion handler for dump mailbox command for getting | |
273 | * wake up parameters. When this command complete, the response contain | |
274 | * Option rom version of the HBA. This function translate the version number | |
275 | * into a human readable string and store it in OptionROMVersion. | |
276 | **/ | |
277 | static void | |
278 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) | |
279 | { | |
280 | struct prog_id *prg; | |
281 | uint32_t prog_id_word; | |
282 | char dist = ' '; | |
283 | /* character array used for decoding dist type. */ | |
284 | char dist_char[] = "nabx"; | |
285 | ||
04c68496 | 286 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
9f1e1b50 | 287 | mempool_free(pmboxq, phba->mbox_mem_pool); |
97207482 | 288 | return; |
9f1e1b50 | 289 | } |
97207482 JS |
290 | |
291 | prg = (struct prog_id *) &prog_id_word; | |
292 | ||
293 | /* word 7 contain option rom version */ | |
04c68496 | 294 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
97207482 JS |
295 | |
296 | /* Decode the Option rom version word to a readable string */ | |
297 | if (prg->dist < 4) | |
298 | dist = dist_char[prg->dist]; | |
299 | ||
300 | if ((prg->dist == 3) && (prg->num == 0)) | |
301 | sprintf(phba->OptionROMVersion, "%d.%d%d", | |
302 | prg->ver, prg->rev, prg->lev); | |
303 | else | |
304 | sprintf(phba->OptionROMVersion, "%d.%d%d%c%d", | |
305 | prg->ver, prg->rev, prg->lev, | |
306 | dist, prg->num); | |
9f1e1b50 | 307 | mempool_free(pmboxq, phba->mbox_mem_pool); |
97207482 JS |
308 | return; |
309 | } | |
310 | ||
e59058c4 | 311 | /** |
3621a710 | 312 | * lpfc_config_port_post - Perform lpfc initialization after config port |
e59058c4 JS |
313 | * @phba: pointer to lpfc hba data structure. |
314 | * | |
315 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox | |
316 | * command call. It performs all internal resource and state setups on the | |
317 | * port: post IOCB buffers, enable appropriate host interrupt attentions, | |
318 | * ELS ring timers, etc. | |
319 | * | |
320 | * Return codes | |
321 | * 0 - success. | |
322 | * Any other value - error. | |
323 | **/ | |
dea3101e | 324 | int |
2e0fef85 | 325 | lpfc_config_port_post(struct lpfc_hba *phba) |
dea3101e | 326 | { |
2e0fef85 | 327 | struct lpfc_vport *vport = phba->pport; |
a257bf90 | 328 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 329 | LPFC_MBOXQ_t *pmb; |
330 | MAILBOX_t *mb; | |
331 | struct lpfc_dmabuf *mp; | |
332 | struct lpfc_sli *psli = &phba->sli; | |
333 | uint32_t status, timeout; | |
2e0fef85 JS |
334 | int i, j; |
335 | int rc; | |
dea3101e | 336 | |
7af67051 JS |
337 | spin_lock_irq(&phba->hbalock); |
338 | /* | |
339 | * If the Config port completed correctly the HBA is not | |
340 | * over heated any more. | |
341 | */ | |
342 | if (phba->over_temp_state == HBA_OVER_TEMP) | |
343 | phba->over_temp_state = HBA_NORMAL_TEMP; | |
344 | spin_unlock_irq(&phba->hbalock); | |
345 | ||
dea3101e | 346 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
347 | if (!pmb) { | |
2e0fef85 | 348 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 349 | return -ENOMEM; |
350 | } | |
04c68496 | 351 | mb = &pmb->u.mb; |
dea3101e | 352 | |
dea3101e | 353 | /* Get login parameters for NID. */ |
9f1177a3 JS |
354 | rc = lpfc_read_sparam(phba, pmb, 0); |
355 | if (rc) { | |
356 | mempool_free(pmb, phba->mbox_mem_pool); | |
357 | return -ENOMEM; | |
358 | } | |
359 | ||
ed957684 | 360 | pmb->vport = vport; |
dea3101e | 361 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 362 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 363 | "0448 Adapter failed init, mbxCmd x%x " |
dea3101e | 364 | "READ_SPARM mbxStatus x%x\n", |
dea3101e | 365 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 366 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 367 | mp = (struct lpfc_dmabuf *) pmb->context1; |
9f1177a3 | 368 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e | 369 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
370 | kfree(mp); | |
371 | return -EIO; | |
372 | } | |
373 | ||
374 | mp = (struct lpfc_dmabuf *) pmb->context1; | |
375 | ||
2e0fef85 | 376 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
dea3101e | 377 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
378 | kfree(mp); | |
379 | pmb->context1 = NULL; | |
380 | ||
a12e07bc | 381 | if (phba->cfg_soft_wwnn) |
2e0fef85 JS |
382 | u64_to_wwn(phba->cfg_soft_wwnn, |
383 | vport->fc_sparam.nodeName.u.wwn); | |
c3f28afa | 384 | if (phba->cfg_soft_wwpn) |
2e0fef85 JS |
385 | u64_to_wwn(phba->cfg_soft_wwpn, |
386 | vport->fc_sparam.portName.u.wwn); | |
387 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, | |
dea3101e | 388 | sizeof (struct lpfc_name)); |
2e0fef85 | 389 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, |
dea3101e | 390 | sizeof (struct lpfc_name)); |
a257bf90 JS |
391 | |
392 | /* Update the fc_host data structures with new wwn. */ | |
393 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
394 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
21e9a0a5 | 395 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
a257bf90 | 396 | |
dea3101e | 397 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
398 | /* This should be consolidated into parse_vpd ? - mr */ | |
399 | if (phba->SerialNumber[0] == 0) { | |
400 | uint8_t *outptr; | |
401 | ||
2e0fef85 | 402 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
dea3101e | 403 | for (i = 0; i < 12; i++) { |
404 | status = *outptr++; | |
405 | j = ((status & 0xf0) >> 4); | |
406 | if (j <= 9) | |
407 | phba->SerialNumber[i] = | |
408 | (char)((uint8_t) 0x30 + (uint8_t) j); | |
409 | else | |
410 | phba->SerialNumber[i] = | |
411 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | |
412 | i++; | |
413 | j = (status & 0xf); | |
414 | if (j <= 9) | |
415 | phba->SerialNumber[i] = | |
416 | (char)((uint8_t) 0x30 + (uint8_t) j); | |
417 | else | |
418 | phba->SerialNumber[i] = | |
419 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | |
420 | } | |
421 | } | |
422 | ||
dea3101e | 423 | lpfc_read_config(phba, pmb); |
ed957684 | 424 | pmb->vport = vport; |
dea3101e | 425 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 426 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 427 | "0453 Adapter failed to init, mbxCmd x%x " |
dea3101e | 428 | "READ_CONFIG, mbxStatus x%x\n", |
dea3101e | 429 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 430 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 431 | mempool_free( pmb, phba->mbox_mem_pool); |
432 | return -EIO; | |
433 | } | |
434 | ||
a0c87cbd JS |
435 | /* Check if the port is disabled */ |
436 | lpfc_sli_read_link_ste(phba); | |
437 | ||
dea3101e | 438 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
439 | if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1)) | |
440 | phba->cfg_hba_queue_depth = | |
f1126688 JS |
441 | (mb->un.varRdConfig.max_xri + 1) - |
442 | lpfc_sli4_get_els_iocb_cnt(phba); | |
dea3101e | 443 | |
444 | phba->lmt = mb->un.varRdConfig.lmt; | |
74b72a59 JW |
445 | |
446 | /* Get the default values for Model Name and Description */ | |
447 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
448 | ||
449 | if ((phba->cfg_link_speed > LINK_SPEED_10G) | |
450 | || ((phba->cfg_link_speed == LINK_SPEED_1G) | |
451 | && !(phba->lmt & LMT_1Gb)) | |
452 | || ((phba->cfg_link_speed == LINK_SPEED_2G) | |
453 | && !(phba->lmt & LMT_2Gb)) | |
454 | || ((phba->cfg_link_speed == LINK_SPEED_4G) | |
455 | && !(phba->lmt & LMT_4Gb)) | |
456 | || ((phba->cfg_link_speed == LINK_SPEED_8G) | |
457 | && !(phba->lmt & LMT_8Gb)) | |
458 | || ((phba->cfg_link_speed == LINK_SPEED_10G) | |
459 | && !(phba->lmt & LMT_10Gb))) { | |
460 | /* Reset link speed to auto */ | |
ed957684 | 461 | lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT, |
e8b62011 | 462 | "1302 Invalid speed for this board: " |
dea3101e | 463 | "Reset link speed to auto: x%x\n", |
dea3101e | 464 | phba->cfg_link_speed); |
465 | phba->cfg_link_speed = LINK_SPEED_AUTO; | |
466 | } | |
467 | ||
2e0fef85 | 468 | phba->link_state = LPFC_LINK_DOWN; |
dea3101e | 469 | |
0b727fea | 470 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
a4bc3379 JS |
471 | if (psli->ring[psli->extra_ring].cmdringaddr) |
472 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; | |
dea3101e | 473 | if (psli->ring[psli->fcp_ring].cmdringaddr) |
474 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; | |
475 | if (psli->ring[psli->next_ring].cmdringaddr) | |
476 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; | |
477 | ||
478 | /* Post receive buffers for desired rings */ | |
ed957684 JS |
479 | if (phba->sli_rev != 3) |
480 | lpfc_post_rcv_buf(phba); | |
dea3101e | 481 | |
9399627f JS |
482 | /* |
483 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode | |
484 | */ | |
485 | if (phba->intr_type == MSIX) { | |
486 | rc = lpfc_config_msi(phba, pmb); | |
487 | if (rc) { | |
488 | mempool_free(pmb, phba->mbox_mem_pool); | |
489 | return -EIO; | |
490 | } | |
491 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
492 | if (rc != MBX_SUCCESS) { | |
493 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
494 | "0352 Config MSI mailbox command " | |
495 | "failed, mbxCmd x%x, mbxStatus x%x\n", | |
04c68496 JS |
496 | pmb->u.mb.mbxCommand, |
497 | pmb->u.mb.mbxStatus); | |
9399627f JS |
498 | mempool_free(pmb, phba->mbox_mem_pool); |
499 | return -EIO; | |
500 | } | |
501 | } | |
502 | ||
04c68496 | 503 | spin_lock_irq(&phba->hbalock); |
9399627f JS |
504 | /* Initialize ERATT handling flag */ |
505 | phba->hba_flag &= ~HBA_ERATT_HANDLED; | |
506 | ||
dea3101e | 507 | /* Enable appropriate host interrupts */ |
dea3101e | 508 | status = readl(phba->HCregaddr); |
509 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; | |
510 | if (psli->num_rings > 0) | |
511 | status |= HC_R0INT_ENA; | |
512 | if (psli->num_rings > 1) | |
513 | status |= HC_R1INT_ENA; | |
514 | if (psli->num_rings > 2) | |
515 | status |= HC_R2INT_ENA; | |
516 | if (psli->num_rings > 3) | |
517 | status |= HC_R3INT_ENA; | |
518 | ||
875fbdfe JSEC |
519 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
520 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) | |
9399627f | 521 | status &= ~(HC_R0INT_ENA); |
875fbdfe | 522 | |
dea3101e | 523 | writel(status, phba->HCregaddr); |
524 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 525 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 526 | |
9399627f JS |
527 | /* Set up ring-0 (ELS) timer */ |
528 | timeout = phba->fc_ratov * 2; | |
2e0fef85 | 529 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
9399627f | 530 | /* Set up heart beat (HB) timer */ |
858c9f6c JS |
531 | mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
532 | phba->hb_outstanding = 0; | |
533 | phba->last_completion_time = jiffies; | |
9399627f JS |
534 | /* Set up error attention (ERATT) polling timer */ |
535 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); | |
dea3101e | 536 | |
a0c87cbd JS |
537 | if (phba->hba_flag & LINK_DISABLED) { |
538 | lpfc_printf_log(phba, | |
539 | KERN_ERR, LOG_INIT, | |
540 | "2598 Adapter Link is disabled.\n"); | |
541 | lpfc_down_link(phba, pmb); | |
542 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
543 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
544 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { | |
545 | lpfc_printf_log(phba, | |
546 | KERN_ERR, LOG_INIT, | |
547 | "2599 Adapter failed to issue DOWN_LINK" | |
548 | " mbox command rc 0x%x\n", rc); | |
549 | ||
550 | mempool_free(pmb, phba->mbox_mem_pool); | |
551 | return -EIO; | |
552 | } | |
e40a02c1 | 553 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
a0c87cbd JS |
554 | lpfc_init_link(phba, pmb, phba->cfg_topology, |
555 | phba->cfg_link_speed); | |
556 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
557 | lpfc_set_loopback_flag(phba); | |
558 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
559 | if (rc != MBX_SUCCESS) { | |
560 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 | 561 | "0454 Adapter failed to init, mbxCmd x%x " |
dea3101e | 562 | "INIT_LINK, mbxStatus x%x\n", |
dea3101e | 563 | mb->mbxCommand, mb->mbxStatus); |
564 | ||
a0c87cbd JS |
565 | /* Clear all interrupt enable conditions */ |
566 | writel(0, phba->HCregaddr); | |
567 | readl(phba->HCregaddr); /* flush */ | |
568 | /* Clear all pending interrupts */ | |
569 | writel(0xffffffff, phba->HAregaddr); | |
570 | readl(phba->HAregaddr); /* flush */ | |
dea3101e | 571 | |
a0c87cbd JS |
572 | phba->link_state = LPFC_HBA_ERROR; |
573 | if (rc != MBX_BUSY) | |
574 | mempool_free(pmb, phba->mbox_mem_pool); | |
575 | return -EIO; | |
576 | } | |
dea3101e | 577 | } |
578 | /* MBOX buffer will be freed in mbox compl */ | |
57127f15 | 579 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
9f1177a3 JS |
580 | if (!pmb) { |
581 | phba->link_state = LPFC_HBA_ERROR; | |
582 | return -ENOMEM; | |
583 | } | |
584 | ||
57127f15 JS |
585 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
586 | pmb->mbox_cmpl = lpfc_config_async_cmpl; | |
587 | pmb->vport = phba->pport; | |
588 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
dea3101e | 589 | |
57127f15 JS |
590 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
591 | lpfc_printf_log(phba, | |
592 | KERN_ERR, | |
593 | LOG_INIT, | |
594 | "0456 Adapter failed to issue " | |
e4e74273 | 595 | "ASYNCEVT_ENABLE mbox status x%x\n", |
57127f15 JS |
596 | rc); |
597 | mempool_free(pmb, phba->mbox_mem_pool); | |
598 | } | |
97207482 JS |
599 | |
600 | /* Get Option rom version */ | |
601 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
9f1177a3 JS |
602 | if (!pmb) { |
603 | phba->link_state = LPFC_HBA_ERROR; | |
604 | return -ENOMEM; | |
605 | } | |
606 | ||
97207482 JS |
607 | lpfc_dump_wakeup_param(phba, pmb); |
608 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; | |
609 | pmb->vport = phba->pport; | |
610 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
611 | ||
612 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { | |
613 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " | |
e4e74273 | 614 | "to get Option ROM version status x%x\n", rc); |
97207482 JS |
615 | mempool_free(pmb, phba->mbox_mem_pool); |
616 | } | |
617 | ||
d7c255b2 | 618 | return 0; |
ce8b3ce5 JS |
619 | } |
620 | ||
84d1b006 JS |
621 | /** |
622 | * lpfc_hba_init_link - Initialize the FC link | |
623 | * @phba: pointer to lpfc hba data structure. | |
6e7288d9 | 624 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
84d1b006 JS |
625 | * |
626 | * This routine will issue the INIT_LINK mailbox command call. | |
627 | * It is available to other drivers through the lpfc_hba data | |
628 | * structure for use as a delayed link up mechanism with the | |
629 | * module parameter lpfc_suppress_link_up. | |
630 | * | |
631 | * Return code | |
632 | * 0 - success | |
633 | * Any other value - error | |
634 | **/ | |
635 | int | |
6e7288d9 | 636 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
84d1b006 JS |
637 | { |
638 | struct lpfc_vport *vport = phba->pport; | |
639 | LPFC_MBOXQ_t *pmb; | |
640 | MAILBOX_t *mb; | |
641 | int rc; | |
642 | ||
643 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
644 | if (!pmb) { | |
645 | phba->link_state = LPFC_HBA_ERROR; | |
646 | return -ENOMEM; | |
647 | } | |
648 | mb = &pmb->u.mb; | |
649 | pmb->vport = vport; | |
650 | ||
651 | lpfc_init_link(phba, pmb, phba->cfg_topology, | |
652 | phba->cfg_link_speed); | |
653 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
654 | lpfc_set_loopback_flag(phba); | |
6e7288d9 | 655 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
84d1b006 JS |
656 | if (rc != MBX_SUCCESS) { |
657 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
658 | "0498 Adapter failed to init, mbxCmd x%x " | |
659 | "INIT_LINK, mbxStatus x%x\n", | |
660 | mb->mbxCommand, mb->mbxStatus); | |
661 | /* Clear all interrupt enable conditions */ | |
662 | writel(0, phba->HCregaddr); | |
663 | readl(phba->HCregaddr); /* flush */ | |
664 | /* Clear all pending interrupts */ | |
665 | writel(0xffffffff, phba->HAregaddr); | |
666 | readl(phba->HAregaddr); /* flush */ | |
667 | phba->link_state = LPFC_HBA_ERROR; | |
6e7288d9 | 668 | if (rc != MBX_BUSY || flag == MBX_POLL) |
84d1b006 JS |
669 | mempool_free(pmb, phba->mbox_mem_pool); |
670 | return -EIO; | |
671 | } | |
e40a02c1 | 672 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
6e7288d9 JS |
673 | if (flag == MBX_POLL) |
674 | mempool_free(pmb, phba->mbox_mem_pool); | |
84d1b006 JS |
675 | |
676 | return 0; | |
677 | } | |
678 | ||
679 | /** | |
680 | * lpfc_hba_down_link - this routine downs the FC link | |
6e7288d9 JS |
681 | * @phba: pointer to lpfc hba data structure. |
682 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT | |
84d1b006 JS |
683 | * |
684 | * This routine will issue the DOWN_LINK mailbox command call. | |
685 | * It is available to other drivers through the lpfc_hba data | |
686 | * structure for use to stop the link. | |
687 | * | |
688 | * Return code | |
689 | * 0 - success | |
690 | * Any other value - error | |
691 | **/ | |
692 | int | |
6e7288d9 | 693 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
84d1b006 JS |
694 | { |
695 | LPFC_MBOXQ_t *pmb; | |
696 | int rc; | |
697 | ||
698 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
699 | if (!pmb) { | |
700 | phba->link_state = LPFC_HBA_ERROR; | |
701 | return -ENOMEM; | |
702 | } | |
703 | ||
704 | lpfc_printf_log(phba, | |
705 | KERN_ERR, LOG_INIT, | |
706 | "0491 Adapter Link is disabled.\n"); | |
707 | lpfc_down_link(phba, pmb); | |
708 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
6e7288d9 | 709 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
84d1b006 JS |
710 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
711 | lpfc_printf_log(phba, | |
712 | KERN_ERR, LOG_INIT, | |
713 | "2522 Adapter failed to issue DOWN_LINK" | |
714 | " mbox command rc 0x%x\n", rc); | |
715 | ||
716 | mempool_free(pmb, phba->mbox_mem_pool); | |
717 | return -EIO; | |
718 | } | |
6e7288d9 JS |
719 | if (flag == MBX_POLL) |
720 | mempool_free(pmb, phba->mbox_mem_pool); | |
721 | ||
84d1b006 JS |
722 | return 0; |
723 | } | |
724 | ||
e59058c4 | 725 | /** |
3621a710 | 726 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
e59058c4 JS |
727 | * @phba: pointer to lpfc HBA data structure. |
728 | * | |
729 | * This routine will do LPFC uninitialization before the HBA is reset when | |
730 | * bringing down the SLI Layer. | |
731 | * | |
732 | * Return codes | |
733 | * 0 - success. | |
734 | * Any other value - error. | |
735 | **/ | |
dea3101e | 736 | int |
2e0fef85 | 737 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
dea3101e | 738 | { |
1b32f6aa JS |
739 | struct lpfc_vport **vports; |
740 | int i; | |
3772a991 JS |
741 | |
742 | if (phba->sli_rev <= LPFC_SLI_REV3) { | |
743 | /* Disable interrupts */ | |
744 | writel(0, phba->HCregaddr); | |
745 | readl(phba->HCregaddr); /* flush */ | |
746 | } | |
dea3101e | 747 | |
1b32f6aa JS |
748 | if (phba->pport->load_flag & FC_UNLOADING) |
749 | lpfc_cleanup_discovery_resources(phba->pport); | |
750 | else { | |
751 | vports = lpfc_create_vport_work_array(phba); | |
752 | if (vports != NULL) | |
3772a991 JS |
753 | for (i = 0; i <= phba->max_vports && |
754 | vports[i] != NULL; i++) | |
1b32f6aa JS |
755 | lpfc_cleanup_discovery_resources(vports[i]); |
756 | lpfc_destroy_vport_work_array(phba, vports); | |
7f5f3d0d JS |
757 | } |
758 | return 0; | |
dea3101e | 759 | } |
760 | ||
e59058c4 | 761 | /** |
3772a991 | 762 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
e59058c4 JS |
763 | * @phba: pointer to lpfc HBA data structure. |
764 | * | |
765 | * This routine will do uninitialization after the HBA is reset when bring | |
766 | * down the SLI Layer. | |
767 | * | |
768 | * Return codes | |
af901ca1 | 769 | * 0 - success. |
e59058c4 JS |
770 | * Any other value - error. |
771 | **/ | |
3772a991 JS |
772 | static int |
773 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) | |
41415862 JW |
774 | { |
775 | struct lpfc_sli *psli = &phba->sli; | |
776 | struct lpfc_sli_ring *pring; | |
777 | struct lpfc_dmabuf *mp, *next_mp; | |
09372820 | 778 | LIST_HEAD(completions); |
41415862 JW |
779 | int i; |
780 | ||
92d7f7b0 JS |
781 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
782 | lpfc_sli_hbqbuf_free_all(phba); | |
783 | else { | |
784 | /* Cleanup preposted buffers on the ELS ring */ | |
785 | pring = &psli->ring[LPFC_ELS_RING]; | |
786 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
787 | list_del(&mp->list); | |
788 | pring->postbufq_cnt--; | |
789 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
790 | kfree(mp); | |
791 | } | |
41415862 JW |
792 | } |
793 | ||
09372820 | 794 | spin_lock_irq(&phba->hbalock); |
41415862 JW |
795 | for (i = 0; i < psli->num_rings; i++) { |
796 | pring = &psli->ring[i]; | |
09372820 JS |
797 | |
798 | /* At this point in time the HBA is either reset or DOA. Either | |
799 | * way, nothing should be on txcmplq as it will NEVER complete. | |
800 | */ | |
801 | list_splice_init(&pring->txcmplq, &completions); | |
802 | pring->txcmplq_cnt = 0; | |
803 | spin_unlock_irq(&phba->hbalock); | |
804 | ||
a257bf90 JS |
805 | /* Cancel all the IOCBs from the completions list */ |
806 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
807 | IOERR_SLI_ABORTED); | |
09372820 | 808 | |
41415862 | 809 | lpfc_sli_abort_iocb_ring(phba, pring); |
09372820 | 810 | spin_lock_irq(&phba->hbalock); |
41415862 | 811 | } |
09372820 | 812 | spin_unlock_irq(&phba->hbalock); |
41415862 JW |
813 | |
814 | return 0; | |
815 | } | |
5af5eee7 | 816 | |
da0436e9 JS |
817 | /** |
818 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset | |
819 | * @phba: pointer to lpfc HBA data structure. | |
820 | * | |
821 | * This routine will do uninitialization after the HBA is reset when bring | |
822 | * down the SLI Layer. | |
823 | * | |
824 | * Return codes | |
af901ca1 | 825 | * 0 - success. |
da0436e9 JS |
826 | * Any other value - error. |
827 | **/ | |
828 | static int | |
829 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) | |
830 | { | |
831 | struct lpfc_scsi_buf *psb, *psb_next; | |
832 | LIST_HEAD(aborts); | |
833 | int ret; | |
834 | unsigned long iflag = 0; | |
0f65ff68 JS |
835 | struct lpfc_sglq *sglq_entry = NULL; |
836 | ||
da0436e9 JS |
837 | ret = lpfc_hba_down_post_s3(phba); |
838 | if (ret) | |
839 | return ret; | |
840 | /* At this point in time the HBA is either reset or DOA. Either | |
841 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be | |
842 | * on the lpfc_sgl_list so that it can either be freed if the | |
843 | * driver is unloading or reposted if the driver is restarting | |
844 | * the port. | |
845 | */ | |
846 | spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */ | |
847 | /* scsl_buf_list */ | |
848 | /* abts_sgl_list_lock required because worker thread uses this | |
849 | * list. | |
850 | */ | |
851 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); | |
0f65ff68 JS |
852 | list_for_each_entry(sglq_entry, |
853 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) | |
854 | sglq_entry->state = SGL_FREED; | |
855 | ||
da0436e9 JS |
856 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
857 | &phba->sli4_hba.lpfc_sgl_list); | |
858 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); | |
859 | /* abts_scsi_buf_list_lock required because worker thread uses this | |
860 | * list. | |
861 | */ | |
862 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
863 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, | |
864 | &aborts); | |
865 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
866 | spin_unlock_irq(&phba->hbalock); | |
867 | ||
868 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { | |
869 | psb->pCmd = NULL; | |
870 | psb->status = IOSTAT_SUCCESS; | |
871 | } | |
872 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); | |
873 | list_splice(&aborts, &phba->lpfc_scsi_buf_list); | |
874 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); | |
875 | return 0; | |
876 | } | |
877 | ||
878 | /** | |
879 | * lpfc_hba_down_post - Wrapper func for hba down post routine | |
880 | * @phba: pointer to lpfc HBA data structure. | |
881 | * | |
882 | * This routine wraps the actual SLI3 or SLI4 routine for performing | |
883 | * uninitialization after the HBA is reset when bring down the SLI Layer. | |
884 | * | |
885 | * Return codes | |
af901ca1 | 886 | * 0 - success. |
da0436e9 JS |
887 | * Any other value - error. |
888 | **/ | |
889 | int | |
890 | lpfc_hba_down_post(struct lpfc_hba *phba) | |
891 | { | |
892 | return (*phba->lpfc_hba_down_post)(phba); | |
893 | } | |
41415862 | 894 | |
e59058c4 | 895 | /** |
3621a710 | 896 | * lpfc_hb_timeout - The HBA-timer timeout handler |
e59058c4 JS |
897 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
898 | * | |
899 | * This is the HBA-timer timeout handler registered to the lpfc driver. When | |
900 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver | |
901 | * work-port-events bitmap and the worker thread is notified. This timeout | |
902 | * event will be used by the worker thread to invoke the actual timeout | |
903 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will | |
904 | * be performed in the timeout handler and the HBA timeout event bit shall | |
905 | * be cleared by the worker thread after it has taken the event bitmap out. | |
906 | **/ | |
a6ababd2 | 907 | static void |
858c9f6c JS |
908 | lpfc_hb_timeout(unsigned long ptr) |
909 | { | |
910 | struct lpfc_hba *phba; | |
5e9d9b82 | 911 | uint32_t tmo_posted; |
858c9f6c JS |
912 | unsigned long iflag; |
913 | ||
914 | phba = (struct lpfc_hba *)ptr; | |
9399627f JS |
915 | |
916 | /* Check for heart beat timeout conditions */ | |
858c9f6c | 917 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
5e9d9b82 JS |
918 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
919 | if (!tmo_posted) | |
858c9f6c JS |
920 | phba->pport->work_port_events |= WORKER_HB_TMO; |
921 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
922 | ||
9399627f | 923 | /* Tell the worker thread there is work to do */ |
5e9d9b82 JS |
924 | if (!tmo_posted) |
925 | lpfc_worker_wake_up(phba); | |
858c9f6c JS |
926 | return; |
927 | } | |
928 | ||
e59058c4 | 929 | /** |
3621a710 | 930 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
e59058c4 JS |
931 | * @phba: pointer to lpfc hba data structure. |
932 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
933 | * | |
934 | * This is the callback function to the lpfc heart-beat mailbox command. | |
935 | * If configured, the lpfc driver issues the heart-beat mailbox command to | |
936 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the | |
937 | * heart-beat mailbox command is issued, the driver shall set up heart-beat | |
938 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks | |
939 | * heart-beat outstanding state. Once the mailbox command comes back and | |
940 | * no error conditions detected, the heart-beat mailbox command timer is | |
941 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding | |
942 | * state is cleared for the next heart-beat. If the timer expired with the | |
943 | * heart-beat outstanding state set, the driver will put the HBA offline. | |
944 | **/ | |
858c9f6c JS |
945 | static void |
946 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
947 | { | |
948 | unsigned long drvr_flag; | |
949 | ||
950 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
951 | phba->hb_outstanding = 0; | |
952 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
953 | ||
9399627f | 954 | /* Check and reset heart-beat timer is necessary */ |
858c9f6c JS |
955 | mempool_free(pmboxq, phba->mbox_mem_pool); |
956 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && | |
957 | !(phba->link_state == LPFC_HBA_ERROR) && | |
51ef4c26 | 958 | !(phba->pport->load_flag & FC_UNLOADING)) |
858c9f6c JS |
959 | mod_timer(&phba->hb_tmofunc, |
960 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
961 | return; | |
962 | } | |
963 | ||
e59058c4 | 964 | /** |
3621a710 | 965 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
e59058c4 JS |
966 | * @phba: pointer to lpfc hba data structure. |
967 | * | |
968 | * This is the actual HBA-timer timeout handler to be invoked by the worker | |
969 | * thread whenever the HBA timer fired and HBA-timeout event posted. This | |
970 | * handler performs any periodic operations needed for the device. If such | |
971 | * periodic event has already been attended to either in the interrupt handler | |
972 | * or by processing slow-ring or fast-ring events within the HBA-timer | |
973 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets | |
974 | * the timer for the next timeout period. If lpfc heart-beat mailbox command | |
975 | * is configured and there is no heart-beat mailbox command outstanding, a | |
976 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there | |
977 | * has been a heart-beat mailbox command outstanding, the HBA shall be put | |
978 | * to offline. | |
979 | **/ | |
858c9f6c JS |
980 | void |
981 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) | |
982 | { | |
45ed1190 | 983 | struct lpfc_vport **vports; |
858c9f6c | 984 | LPFC_MBOXQ_t *pmboxq; |
0ff10d46 | 985 | struct lpfc_dmabuf *buf_ptr; |
45ed1190 | 986 | int retval, i; |
858c9f6c | 987 | struct lpfc_sli *psli = &phba->sli; |
0ff10d46 | 988 | LIST_HEAD(completions); |
858c9f6c | 989 | |
45ed1190 JS |
990 | vports = lpfc_create_vport_work_array(phba); |
991 | if (vports != NULL) | |
992 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) | |
993 | lpfc_rcv_seq_check_edtov(vports[i]); | |
994 | lpfc_destroy_vport_work_array(phba, vports); | |
995 | ||
858c9f6c | 996 | if ((phba->link_state == LPFC_HBA_ERROR) || |
51ef4c26 | 997 | (phba->pport->load_flag & FC_UNLOADING) || |
858c9f6c JS |
998 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
999 | return; | |
1000 | ||
1001 | spin_lock_irq(&phba->pport->work_port_lock); | |
858c9f6c JS |
1002 | |
1003 | if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, | |
1004 | jiffies)) { | |
1005 | spin_unlock_irq(&phba->pport->work_port_lock); | |
1006 | if (!phba->hb_outstanding) | |
1007 | mod_timer(&phba->hb_tmofunc, | |
1008 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
1009 | else | |
1010 | mod_timer(&phba->hb_tmofunc, | |
1011 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | |
1012 | return; | |
1013 | } | |
1014 | spin_unlock_irq(&phba->pport->work_port_lock); | |
1015 | ||
0ff10d46 JS |
1016 | if (phba->elsbuf_cnt && |
1017 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { | |
1018 | spin_lock_irq(&phba->hbalock); | |
1019 | list_splice_init(&phba->elsbuf, &completions); | |
1020 | phba->elsbuf_cnt = 0; | |
1021 | phba->elsbuf_prev_cnt = 0; | |
1022 | spin_unlock_irq(&phba->hbalock); | |
1023 | ||
1024 | while (!list_empty(&completions)) { | |
1025 | list_remove_head(&completions, buf_ptr, | |
1026 | struct lpfc_dmabuf, list); | |
1027 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
1028 | kfree(buf_ptr); | |
1029 | } | |
1030 | } | |
1031 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; | |
1032 | ||
858c9f6c | 1033 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
13815c83 JS |
1034 | if (phba->cfg_enable_hba_heartbeat) { |
1035 | if (!phba->hb_outstanding) { | |
bc73905a JS |
1036 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
1037 | (list_empty(&psli->mboxq))) { | |
1038 | pmboxq = mempool_alloc(phba->mbox_mem_pool, | |
1039 | GFP_KERNEL); | |
1040 | if (!pmboxq) { | |
1041 | mod_timer(&phba->hb_tmofunc, | |
1042 | jiffies + | |
1043 | HZ * LPFC_HB_MBOX_INTERVAL); | |
1044 | return; | |
1045 | } | |
1046 | ||
1047 | lpfc_heart_beat(phba, pmboxq); | |
1048 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; | |
1049 | pmboxq->vport = phba->pport; | |
1050 | retval = lpfc_sli_issue_mbox(phba, pmboxq, | |
1051 | MBX_NOWAIT); | |
1052 | ||
1053 | if (retval != MBX_BUSY && | |
1054 | retval != MBX_SUCCESS) { | |
1055 | mempool_free(pmboxq, | |
1056 | phba->mbox_mem_pool); | |
1057 | mod_timer(&phba->hb_tmofunc, | |
1058 | jiffies + | |
1059 | HZ * LPFC_HB_MBOX_INTERVAL); | |
1060 | return; | |
1061 | } | |
1062 | phba->skipped_hb = 0; | |
1063 | phba->hb_outstanding = 1; | |
1064 | } else if (time_before_eq(phba->last_completion_time, | |
1065 | phba->skipped_hb)) { | |
1066 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
1067 | "2857 Last completion time not " | |
1068 | " updated in %d ms\n", | |
1069 | jiffies_to_msecs(jiffies | |
1070 | - phba->last_completion_time)); | |
1071 | } else | |
1072 | phba->skipped_hb = jiffies; | |
1073 | ||
858c9f6c | 1074 | mod_timer(&phba->hb_tmofunc, |
13815c83 | 1075 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
858c9f6c | 1076 | return; |
13815c83 JS |
1077 | } else { |
1078 | /* | |
1079 | * If heart beat timeout called with hb_outstanding set | |
dcf2a4e0 JS |
1080 | * we need to give the hb mailbox cmd a chance to |
1081 | * complete or TMO. | |
13815c83 | 1082 | */ |
dcf2a4e0 JS |
1083 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
1084 | "0459 Adapter heartbeat still out" | |
1085 | "standing:last compl time was %d ms.\n", | |
1086 | jiffies_to_msecs(jiffies | |
1087 | - phba->last_completion_time)); | |
1088 | mod_timer(&phba->hb_tmofunc, | |
1089 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | |
858c9f6c | 1090 | } |
858c9f6c JS |
1091 | } |
1092 | } | |
1093 | ||
e59058c4 | 1094 | /** |
3621a710 | 1095 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
e59058c4 JS |
1096 | * @phba: pointer to lpfc hba data structure. |
1097 | * | |
1098 | * This routine is called to bring the HBA offline when HBA hardware error | |
1099 | * other than Port Error 6 has been detected. | |
1100 | **/ | |
09372820 JS |
1101 | static void |
1102 | lpfc_offline_eratt(struct lpfc_hba *phba) | |
1103 | { | |
1104 | struct lpfc_sli *psli = &phba->sli; | |
1105 | ||
1106 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1107 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
09372820 JS |
1108 | spin_unlock_irq(&phba->hbalock); |
1109 | lpfc_offline_prep(phba); | |
1110 | ||
1111 | lpfc_offline(phba); | |
1112 | lpfc_reset_barrier(phba); | |
f4b4c68f | 1113 | spin_lock_irq(&phba->hbalock); |
09372820 | 1114 | lpfc_sli_brdreset(phba); |
f4b4c68f | 1115 | spin_unlock_irq(&phba->hbalock); |
09372820 JS |
1116 | lpfc_hba_down_post(phba); |
1117 | lpfc_sli_brdready(phba, HS_MBRDY); | |
1118 | lpfc_unblock_mgmt_io(phba); | |
1119 | phba->link_state = LPFC_HBA_ERROR; | |
1120 | return; | |
1121 | } | |
1122 | ||
da0436e9 JS |
1123 | /** |
1124 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention | |
1125 | * @phba: pointer to lpfc hba data structure. | |
1126 | * | |
1127 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error | |
1128 | * other than Port Error 6 has been detected. | |
1129 | **/ | |
1130 | static void | |
1131 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) | |
1132 | { | |
1133 | lpfc_offline_prep(phba); | |
1134 | lpfc_offline(phba); | |
1135 | lpfc_sli4_brdreset(phba); | |
1136 | lpfc_hba_down_post(phba); | |
1137 | lpfc_sli4_post_status_check(phba); | |
1138 | lpfc_unblock_mgmt_io(phba); | |
1139 | phba->link_state = LPFC_HBA_ERROR; | |
1140 | } | |
1141 | ||
a257bf90 JS |
1142 | /** |
1143 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler | |
1144 | * @phba: pointer to lpfc hba data structure. | |
1145 | * | |
1146 | * This routine is invoked to handle the deferred HBA hardware error | |
1147 | * conditions. This type of error is indicated by HBA by setting ER1 | |
1148 | * and another ER bit in the host status register. The driver will | |
1149 | * wait until the ER1 bit clears before handling the error condition. | |
1150 | **/ | |
1151 | static void | |
1152 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) | |
1153 | { | |
1154 | uint32_t old_host_status = phba->work_hs; | |
1155 | struct lpfc_sli_ring *pring; | |
1156 | struct lpfc_sli *psli = &phba->sli; | |
1157 | ||
f4b4c68f JS |
1158 | /* If the pci channel is offline, ignore possible errors, |
1159 | * since we cannot communicate with the pci card anyway. | |
1160 | */ | |
1161 | if (pci_channel_offline(phba->pcidev)) { | |
1162 | spin_lock_irq(&phba->hbalock); | |
1163 | phba->hba_flag &= ~DEFER_ERATT; | |
1164 | spin_unlock_irq(&phba->hbalock); | |
1165 | return; | |
1166 | } | |
1167 | ||
a257bf90 JS |
1168 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
1169 | "0479 Deferred Adapter Hardware Error " | |
1170 | "Data: x%x x%x x%x\n", | |
1171 | phba->work_hs, | |
1172 | phba->work_status[0], phba->work_status[1]); | |
1173 | ||
1174 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1175 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
a257bf90 JS |
1176 | spin_unlock_irq(&phba->hbalock); |
1177 | ||
1178 | ||
1179 | /* | |
1180 | * Firmware stops when it triggred erratt. That could cause the I/Os | |
1181 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the | |
1182 | * SCSI layer retry it after re-establishing link. | |
1183 | */ | |
1184 | pring = &psli->ring[psli->fcp_ring]; | |
1185 | lpfc_sli_abort_iocb_ring(phba, pring); | |
1186 | ||
1187 | /* | |
1188 | * There was a firmware error. Take the hba offline and then | |
1189 | * attempt to restart it. | |
1190 | */ | |
1191 | lpfc_offline_prep(phba); | |
1192 | lpfc_offline(phba); | |
1193 | ||
1194 | /* Wait for the ER1 bit to clear.*/ | |
1195 | while (phba->work_hs & HS_FFER1) { | |
1196 | msleep(100); | |
1197 | phba->work_hs = readl(phba->HSregaddr); | |
1198 | /* If driver is unloading let the worker thread continue */ | |
1199 | if (phba->pport->load_flag & FC_UNLOADING) { | |
1200 | phba->work_hs = 0; | |
1201 | break; | |
1202 | } | |
1203 | } | |
1204 | ||
1205 | /* | |
1206 | * This is to ptrotect against a race condition in which | |
1207 | * first write to the host attention register clear the | |
1208 | * host status register. | |
1209 | */ | |
1210 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) | |
1211 | phba->work_hs = old_host_status & ~HS_FFER1; | |
1212 | ||
3772a991 | 1213 | spin_lock_irq(&phba->hbalock); |
a257bf90 | 1214 | phba->hba_flag &= ~DEFER_ERATT; |
3772a991 | 1215 | spin_unlock_irq(&phba->hbalock); |
a257bf90 JS |
1216 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
1217 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); | |
1218 | } | |
1219 | ||
3772a991 JS |
1220 | static void |
1221 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) | |
1222 | { | |
1223 | struct lpfc_board_event_header board_event; | |
1224 | struct Scsi_Host *shost; | |
1225 | ||
1226 | board_event.event_type = FC_REG_BOARD_EVENT; | |
1227 | board_event.subcategory = LPFC_EVENT_PORTINTERR; | |
1228 | shost = lpfc_shost_from_vport(phba->pport); | |
1229 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1230 | sizeof(board_event), | |
1231 | (char *) &board_event, | |
1232 | LPFC_NL_VENDOR_ID); | |
1233 | } | |
1234 | ||
e59058c4 | 1235 | /** |
3772a991 | 1236 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
e59058c4 JS |
1237 | * @phba: pointer to lpfc hba data structure. |
1238 | * | |
1239 | * This routine is invoked to handle the following HBA hardware error | |
1240 | * conditions: | |
1241 | * 1 - HBA error attention interrupt | |
1242 | * 2 - DMA ring index out of range | |
1243 | * 3 - Mailbox command came back as unknown | |
1244 | **/ | |
3772a991 JS |
1245 | static void |
1246 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) | |
dea3101e | 1247 | { |
2e0fef85 | 1248 | struct lpfc_vport *vport = phba->pport; |
2e0fef85 | 1249 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 1250 | struct lpfc_sli_ring *pring; |
d2873e4c | 1251 | uint32_t event_data; |
57127f15 JS |
1252 | unsigned long temperature; |
1253 | struct temp_event temp_event_data; | |
92d7f7b0 | 1254 | struct Scsi_Host *shost; |
2e0fef85 | 1255 | |
8d63f375 | 1256 | /* If the pci channel is offline, ignore possible errors, |
3772a991 JS |
1257 | * since we cannot communicate with the pci card anyway. |
1258 | */ | |
1259 | if (pci_channel_offline(phba->pcidev)) { | |
1260 | spin_lock_irq(&phba->hbalock); | |
1261 | phba->hba_flag &= ~DEFER_ERATT; | |
1262 | spin_unlock_irq(&phba->hbalock); | |
8d63f375 | 1263 | return; |
3772a991 JS |
1264 | } |
1265 | ||
13815c83 JS |
1266 | /* If resets are disabled then leave the HBA alone and return */ |
1267 | if (!phba->cfg_enable_hba_reset) | |
1268 | return; | |
dea3101e | 1269 | |
ea2151b4 | 1270 | /* Send an internal error event to mgmt application */ |
3772a991 | 1271 | lpfc_board_errevt_to_mgmt(phba); |
ea2151b4 | 1272 | |
a257bf90 JS |
1273 | if (phba->hba_flag & DEFER_ERATT) |
1274 | lpfc_handle_deferred_eratt(phba); | |
1275 | ||
dcf2a4e0 JS |
1276 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
1277 | if (phba->work_hs & HS_FFER6) | |
1278 | /* Re-establishing Link */ | |
1279 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
1280 | "1301 Re-establishing Link " | |
1281 | "Data: x%x x%x x%x\n", | |
1282 | phba->work_hs, phba->work_status[0], | |
1283 | phba->work_status[1]); | |
1284 | if (phba->work_hs & HS_FFER8) | |
1285 | /* Device Zeroization */ | |
1286 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
1287 | "2861 Host Authentication device " | |
1288 | "zeroization Data:x%x x%x x%x\n", | |
1289 | phba->work_hs, phba->work_status[0], | |
1290 | phba->work_status[1]); | |
58da1ffb | 1291 | |
92d7f7b0 | 1292 | spin_lock_irq(&phba->hbalock); |
f4b4c68f | 1293 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
92d7f7b0 | 1294 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1295 | |
1296 | /* | |
1297 | * Firmware stops when it triggled erratt with HS_FFER6. | |
1298 | * That could cause the I/Os dropped by the firmware. | |
1299 | * Error iocb (I/O) on txcmplq and let the SCSI layer | |
1300 | * retry it after re-establishing link. | |
1301 | */ | |
1302 | pring = &psli->ring[psli->fcp_ring]; | |
1303 | lpfc_sli_abort_iocb_ring(phba, pring); | |
1304 | ||
dea3101e | 1305 | /* |
1306 | * There was a firmware error. Take the hba offline and then | |
1307 | * attempt to restart it. | |
1308 | */ | |
46fa311e | 1309 | lpfc_offline_prep(phba); |
dea3101e | 1310 | lpfc_offline(phba); |
41415862 | 1311 | lpfc_sli_brdrestart(phba); |
dea3101e | 1312 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
46fa311e | 1313 | lpfc_unblock_mgmt_io(phba); |
dea3101e | 1314 | return; |
1315 | } | |
46fa311e | 1316 | lpfc_unblock_mgmt_io(phba); |
57127f15 JS |
1317 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
1318 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); | |
1319 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
1320 | temp_event_data.event_code = LPFC_CRIT_TEMP; | |
1321 | temp_event_data.data = (uint32_t)temperature; | |
1322 | ||
1323 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 1324 | "0406 Adapter maximum temperature exceeded " |
57127f15 JS |
1325 | "(%ld), taking this port offline " |
1326 | "Data: x%x x%x x%x\n", | |
1327 | temperature, phba->work_hs, | |
1328 | phba->work_status[0], phba->work_status[1]); | |
1329 | ||
1330 | shost = lpfc_shost_from_vport(phba->pport); | |
1331 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1332 | sizeof(temp_event_data), | |
1333 | (char *) &temp_event_data, | |
1334 | SCSI_NL_VID_TYPE_PCI | |
1335 | | PCI_VENDOR_ID_EMULEX); | |
1336 | ||
7af67051 | 1337 | spin_lock_irq(&phba->hbalock); |
7af67051 JS |
1338 | phba->over_temp_state = HBA_OVER_TEMP; |
1339 | spin_unlock_irq(&phba->hbalock); | |
09372820 | 1340 | lpfc_offline_eratt(phba); |
57127f15 | 1341 | |
dea3101e | 1342 | } else { |
1343 | /* The if clause above forces this code path when the status | |
9399627f JS |
1344 | * failure is a value other than FFER6. Do not call the offline |
1345 | * twice. This is the adapter hardware error path. | |
dea3101e | 1346 | */ |
1347 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 | 1348 | "0457 Adapter Hardware Error " |
dea3101e | 1349 | "Data: x%x x%x x%x\n", |
e8b62011 | 1350 | phba->work_hs, |
dea3101e | 1351 | phba->work_status[0], phba->work_status[1]); |
1352 | ||
d2873e4c | 1353 | event_data = FC_REG_DUMP_EVENT; |
92d7f7b0 | 1354 | shost = lpfc_shost_from_vport(vport); |
2e0fef85 | 1355 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
d2873e4c JS |
1356 | sizeof(event_data), (char *) &event_data, |
1357 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
1358 | ||
09372820 | 1359 | lpfc_offline_eratt(phba); |
dea3101e | 1360 | } |
9399627f | 1361 | return; |
dea3101e | 1362 | } |
1363 | ||
da0436e9 JS |
1364 | /** |
1365 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler | |
1366 | * @phba: pointer to lpfc hba data structure. | |
1367 | * | |
1368 | * This routine is invoked to handle the SLI4 HBA hardware error attention | |
1369 | * conditions. | |
1370 | **/ | |
1371 | static void | |
1372 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) | |
1373 | { | |
1374 | struct lpfc_vport *vport = phba->pport; | |
1375 | uint32_t event_data; | |
1376 | struct Scsi_Host *shost; | |
1377 | ||
1378 | /* If the pci channel is offline, ignore possible errors, since | |
1379 | * we cannot communicate with the pci card anyway. | |
1380 | */ | |
1381 | if (pci_channel_offline(phba->pcidev)) | |
1382 | return; | |
1383 | /* If resets are disabled then leave the HBA alone and return */ | |
1384 | if (!phba->cfg_enable_hba_reset) | |
1385 | return; | |
1386 | ||
1387 | /* Send an internal error event to mgmt application */ | |
1388 | lpfc_board_errevt_to_mgmt(phba); | |
1389 | ||
1390 | /* For now, the actual action for SLI4 device handling is not | |
1391 | * specified yet, just treated it as adaptor hardware failure | |
1392 | */ | |
1393 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1394 | "0143 SLI4 Adapter Hardware Error Data: x%x x%x\n", | |
1395 | phba->work_status[0], phba->work_status[1]); | |
1396 | ||
1397 | event_data = FC_REG_DUMP_EVENT; | |
1398 | shost = lpfc_shost_from_vport(vport); | |
1399 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1400 | sizeof(event_data), (char *) &event_data, | |
1401 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
1402 | ||
1403 | lpfc_sli4_offline_eratt(phba); | |
1404 | } | |
1405 | ||
1406 | /** | |
1407 | * lpfc_handle_eratt - Wrapper func for handling hba error attention | |
1408 | * @phba: pointer to lpfc HBA data structure. | |
1409 | * | |
1410 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling | |
1411 | * routine from the API jump table function pointer from the lpfc_hba struct. | |
1412 | * | |
1413 | * Return codes | |
af901ca1 | 1414 | * 0 - success. |
da0436e9 JS |
1415 | * Any other value - error. |
1416 | **/ | |
1417 | void | |
1418 | lpfc_handle_eratt(struct lpfc_hba *phba) | |
1419 | { | |
1420 | (*phba->lpfc_handle_eratt)(phba); | |
1421 | } | |
1422 | ||
e59058c4 | 1423 | /** |
3621a710 | 1424 | * lpfc_handle_latt - The HBA link event handler |
e59058c4 JS |
1425 | * @phba: pointer to lpfc hba data structure. |
1426 | * | |
1427 | * This routine is invoked from the worker thread to handle a HBA host | |
1428 | * attention link event. | |
1429 | **/ | |
dea3101e | 1430 | void |
2e0fef85 | 1431 | lpfc_handle_latt(struct lpfc_hba *phba) |
dea3101e | 1432 | { |
2e0fef85 JS |
1433 | struct lpfc_vport *vport = phba->pport; |
1434 | struct lpfc_sli *psli = &phba->sli; | |
dea3101e | 1435 | LPFC_MBOXQ_t *pmb; |
1436 | volatile uint32_t control; | |
1437 | struct lpfc_dmabuf *mp; | |
09372820 | 1438 | int rc = 0; |
dea3101e | 1439 | |
1440 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
09372820 JS |
1441 | if (!pmb) { |
1442 | rc = 1; | |
dea3101e | 1443 | goto lpfc_handle_latt_err_exit; |
09372820 | 1444 | } |
dea3101e | 1445 | |
1446 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
09372820 JS |
1447 | if (!mp) { |
1448 | rc = 2; | |
dea3101e | 1449 | goto lpfc_handle_latt_free_pmb; |
09372820 | 1450 | } |
dea3101e | 1451 | |
1452 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
09372820 JS |
1453 | if (!mp->virt) { |
1454 | rc = 3; | |
dea3101e | 1455 | goto lpfc_handle_latt_free_mp; |
09372820 | 1456 | } |
dea3101e | 1457 | |
6281bfe0 | 1458 | /* Cleanup any outstanding ELS commands */ |
549e55cd | 1459 | lpfc_els_flush_all_cmd(phba); |
dea3101e | 1460 | |
1461 | psli->slistat.link_event++; | |
1462 | lpfc_read_la(phba, pmb, mp); | |
1463 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la; | |
2e0fef85 | 1464 | pmb->vport = vport; |
0d2b6b83 JS |
1465 | /* Block ELS IOCBs until we have processed this mbox command */ |
1466 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
0b727fea | 1467 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
09372820 JS |
1468 | if (rc == MBX_NOT_FINISHED) { |
1469 | rc = 4; | |
14691150 | 1470 | goto lpfc_handle_latt_free_mbuf; |
09372820 | 1471 | } |
dea3101e | 1472 | |
1473 | /* Clear Link Attention in HA REG */ | |
2e0fef85 | 1474 | spin_lock_irq(&phba->hbalock); |
dea3101e | 1475 | writel(HA_LATT, phba->HAregaddr); |
1476 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1477 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1478 | |
1479 | return; | |
1480 | ||
14691150 | 1481 | lpfc_handle_latt_free_mbuf: |
0d2b6b83 | 1482 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
14691150 | 1483 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
dea3101e | 1484 | lpfc_handle_latt_free_mp: |
1485 | kfree(mp); | |
1486 | lpfc_handle_latt_free_pmb: | |
1dcb58e5 | 1487 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e | 1488 | lpfc_handle_latt_err_exit: |
1489 | /* Enable Link attention interrupts */ | |
2e0fef85 | 1490 | spin_lock_irq(&phba->hbalock); |
dea3101e | 1491 | psli->sli_flag |= LPFC_PROCESS_LA; |
1492 | control = readl(phba->HCregaddr); | |
1493 | control |= HC_LAINT_ENA; | |
1494 | writel(control, phba->HCregaddr); | |
1495 | readl(phba->HCregaddr); /* flush */ | |
1496 | ||
1497 | /* Clear Link Attention in HA REG */ | |
1498 | writel(HA_LATT, phba->HAregaddr); | |
1499 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1500 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1501 | lpfc_linkdown(phba); |
2e0fef85 | 1502 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 1503 | |
09372820 JS |
1504 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
1505 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); | |
dea3101e | 1506 | |
1507 | return; | |
1508 | } | |
1509 | ||
e59058c4 | 1510 | /** |
3621a710 | 1511 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
e59058c4 JS |
1512 | * @phba: pointer to lpfc hba data structure. |
1513 | * @vpd: pointer to the vital product data. | |
1514 | * @len: length of the vital product data in bytes. | |
1515 | * | |
1516 | * This routine parses the Vital Product Data (VPD). The VPD is treated as | |
1517 | * an array of characters. In this routine, the ModelName, ProgramType, and | |
1518 | * ModelDesc, etc. fields of the phba data structure will be populated. | |
1519 | * | |
1520 | * Return codes | |
1521 | * 0 - pointer to the VPD passed in is NULL | |
1522 | * 1 - success | |
1523 | **/ | |
3772a991 | 1524 | int |
2e0fef85 | 1525 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
dea3101e | 1526 | { |
1527 | uint8_t lenlo, lenhi; | |
07da60c1 | 1528 | int Length; |
dea3101e | 1529 | int i, j; |
1530 | int finished = 0; | |
1531 | int index = 0; | |
1532 | ||
1533 | if (!vpd) | |
1534 | return 0; | |
1535 | ||
1536 | /* Vital Product */ | |
ed957684 | 1537 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
e8b62011 | 1538 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
dea3101e | 1539 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
1540 | (uint32_t) vpd[3]); | |
74b72a59 | 1541 | while (!finished && (index < (len - 4))) { |
dea3101e | 1542 | switch (vpd[index]) { |
1543 | case 0x82: | |
74b72a59 | 1544 | case 0x91: |
dea3101e | 1545 | index += 1; |
1546 | lenlo = vpd[index]; | |
1547 | index += 1; | |
1548 | lenhi = vpd[index]; | |
1549 | index += 1; | |
1550 | i = ((((unsigned short)lenhi) << 8) + lenlo); | |
1551 | index += i; | |
1552 | break; | |
1553 | case 0x90: | |
1554 | index += 1; | |
1555 | lenlo = vpd[index]; | |
1556 | index += 1; | |
1557 | lenhi = vpd[index]; | |
1558 | index += 1; | |
1559 | Length = ((((unsigned short)lenhi) << 8) + lenlo); | |
74b72a59 JW |
1560 | if (Length > len - index) |
1561 | Length = len - index; | |
dea3101e | 1562 | while (Length > 0) { |
1563 | /* Look for Serial Number */ | |
1564 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { | |
1565 | index += 2; | |
1566 | i = vpd[index]; | |
1567 | index += 1; | |
1568 | j = 0; | |
1569 | Length -= (3+i); | |
1570 | while(i--) { | |
1571 | phba->SerialNumber[j++] = vpd[index++]; | |
1572 | if (j == 31) | |
1573 | break; | |
1574 | } | |
1575 | phba->SerialNumber[j] = 0; | |
1576 | continue; | |
1577 | } | |
1578 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { | |
1579 | phba->vpd_flag |= VPD_MODEL_DESC; | |
1580 | index += 2; | |
1581 | i = vpd[index]; | |
1582 | index += 1; | |
1583 | j = 0; | |
1584 | Length -= (3+i); | |
1585 | while(i--) { | |
1586 | phba->ModelDesc[j++] = vpd[index++]; | |
1587 | if (j == 255) | |
1588 | break; | |
1589 | } | |
1590 | phba->ModelDesc[j] = 0; | |
1591 | continue; | |
1592 | } | |
1593 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { | |
1594 | phba->vpd_flag |= VPD_MODEL_NAME; | |
1595 | index += 2; | |
1596 | i = vpd[index]; | |
1597 | index += 1; | |
1598 | j = 0; | |
1599 | Length -= (3+i); | |
1600 | while(i--) { | |
1601 | phba->ModelName[j++] = vpd[index++]; | |
1602 | if (j == 79) | |
1603 | break; | |
1604 | } | |
1605 | phba->ModelName[j] = 0; | |
1606 | continue; | |
1607 | } | |
1608 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { | |
1609 | phba->vpd_flag |= VPD_PROGRAM_TYPE; | |
1610 | index += 2; | |
1611 | i = vpd[index]; | |
1612 | index += 1; | |
1613 | j = 0; | |
1614 | Length -= (3+i); | |
1615 | while(i--) { | |
1616 | phba->ProgramType[j++] = vpd[index++]; | |
1617 | if (j == 255) | |
1618 | break; | |
1619 | } | |
1620 | phba->ProgramType[j] = 0; | |
1621 | continue; | |
1622 | } | |
1623 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { | |
1624 | phba->vpd_flag |= VPD_PORT; | |
1625 | index += 2; | |
1626 | i = vpd[index]; | |
1627 | index += 1; | |
1628 | j = 0; | |
1629 | Length -= (3+i); | |
1630 | while(i--) { | |
1631 | phba->Port[j++] = vpd[index++]; | |
1632 | if (j == 19) | |
1633 | break; | |
1634 | } | |
1635 | phba->Port[j] = 0; | |
1636 | continue; | |
1637 | } | |
1638 | else { | |
1639 | index += 2; | |
1640 | i = vpd[index]; | |
1641 | index += 1; | |
1642 | index += i; | |
1643 | Length -= (3 + i); | |
1644 | } | |
1645 | } | |
1646 | finished = 0; | |
1647 | break; | |
1648 | case 0x78: | |
1649 | finished = 1; | |
1650 | break; | |
1651 | default: | |
1652 | index ++; | |
1653 | break; | |
1654 | } | |
74b72a59 | 1655 | } |
dea3101e | 1656 | |
1657 | return(1); | |
1658 | } | |
1659 | ||
e59058c4 | 1660 | /** |
3621a710 | 1661 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
e59058c4 JS |
1662 | * @phba: pointer to lpfc hba data structure. |
1663 | * @mdp: pointer to the data structure to hold the derived model name. | |
1664 | * @descp: pointer to the data structure to hold the derived description. | |
1665 | * | |
1666 | * This routine retrieves HBA's description based on its registered PCI device | |
1667 | * ID. The @descp passed into this function points to an array of 256 chars. It | |
1668 | * shall be returned with the model name, maximum speed, and the host bus type. | |
1669 | * The @mdp passed into this function points to an array of 80 chars. When the | |
1670 | * function returns, the @mdp will be filled with the model name. | |
1671 | **/ | |
dea3101e | 1672 | static void |
2e0fef85 | 1673 | lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) |
dea3101e | 1674 | { |
1675 | lpfc_vpd_t *vp; | |
fefcb2b6 | 1676 | uint16_t dev_id = phba->pcidev->device; |
74b72a59 | 1677 | int max_speed; |
84774a4d | 1678 | int GE = 0; |
da0436e9 | 1679 | int oneConnect = 0; /* default is not a oneConnect */ |
74b72a59 | 1680 | struct { |
a747c9ce JS |
1681 | char *name; |
1682 | char *bus; | |
1683 | char *function; | |
1684 | } m = {"<Unknown>", "", ""}; | |
74b72a59 JW |
1685 | |
1686 | if (mdp && mdp[0] != '\0' | |
1687 | && descp && descp[0] != '\0') | |
1688 | return; | |
1689 | ||
1690 | if (phba->lmt & LMT_10Gb) | |
1691 | max_speed = 10; | |
1692 | else if (phba->lmt & LMT_8Gb) | |
1693 | max_speed = 8; | |
1694 | else if (phba->lmt & LMT_4Gb) | |
1695 | max_speed = 4; | |
1696 | else if (phba->lmt & LMT_2Gb) | |
1697 | max_speed = 2; | |
1698 | else | |
1699 | max_speed = 1; | |
dea3101e | 1700 | |
1701 | vp = &phba->vpd; | |
dea3101e | 1702 | |
e4adb204 | 1703 | switch (dev_id) { |
06325e74 | 1704 | case PCI_DEVICE_ID_FIREFLY: |
a747c9ce | 1705 | m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"}; |
06325e74 | 1706 | break; |
dea3101e | 1707 | case PCI_DEVICE_ID_SUPERFLY: |
1708 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) | |
a747c9ce JS |
1709 | m = (typeof(m)){"LP7000", "PCI", |
1710 | "Fibre Channel Adapter"}; | |
dea3101e | 1711 | else |
a747c9ce JS |
1712 | m = (typeof(m)){"LP7000E", "PCI", |
1713 | "Fibre Channel Adapter"}; | |
dea3101e | 1714 | break; |
1715 | case PCI_DEVICE_ID_DRAGONFLY: | |
a747c9ce JS |
1716 | m = (typeof(m)){"LP8000", "PCI", |
1717 | "Fibre Channel Adapter"}; | |
dea3101e | 1718 | break; |
1719 | case PCI_DEVICE_ID_CENTAUR: | |
1720 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) | |
a747c9ce JS |
1721 | m = (typeof(m)){"LP9002", "PCI", |
1722 | "Fibre Channel Adapter"}; | |
dea3101e | 1723 | else |
a747c9ce JS |
1724 | m = (typeof(m)){"LP9000", "PCI", |
1725 | "Fibre Channel Adapter"}; | |
dea3101e | 1726 | break; |
1727 | case PCI_DEVICE_ID_RFLY: | |
a747c9ce JS |
1728 | m = (typeof(m)){"LP952", "PCI", |
1729 | "Fibre Channel Adapter"}; | |
dea3101e | 1730 | break; |
1731 | case PCI_DEVICE_ID_PEGASUS: | |
a747c9ce JS |
1732 | m = (typeof(m)){"LP9802", "PCI-X", |
1733 | "Fibre Channel Adapter"}; | |
dea3101e | 1734 | break; |
1735 | case PCI_DEVICE_ID_THOR: | |
a747c9ce JS |
1736 | m = (typeof(m)){"LP10000", "PCI-X", |
1737 | "Fibre Channel Adapter"}; | |
dea3101e | 1738 | break; |
1739 | case PCI_DEVICE_ID_VIPER: | |
a747c9ce JS |
1740 | m = (typeof(m)){"LPX1000", "PCI-X", |
1741 | "Fibre Channel Adapter"}; | |
dea3101e | 1742 | break; |
1743 | case PCI_DEVICE_ID_PFLY: | |
a747c9ce JS |
1744 | m = (typeof(m)){"LP982", "PCI-X", |
1745 | "Fibre Channel Adapter"}; | |
dea3101e | 1746 | break; |
1747 | case PCI_DEVICE_ID_TFLY: | |
a747c9ce JS |
1748 | m = (typeof(m)){"LP1050", "PCI-X", |
1749 | "Fibre Channel Adapter"}; | |
dea3101e | 1750 | break; |
1751 | case PCI_DEVICE_ID_HELIOS: | |
a747c9ce JS |
1752 | m = (typeof(m)){"LP11000", "PCI-X2", |
1753 | "Fibre Channel Adapter"}; | |
dea3101e | 1754 | break; |
e4adb204 | 1755 | case PCI_DEVICE_ID_HELIOS_SCSP: |
a747c9ce JS |
1756 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
1757 | "Fibre Channel Adapter"}; | |
e4adb204 JSEC |
1758 | break; |
1759 | case PCI_DEVICE_ID_HELIOS_DCSP: | |
a747c9ce JS |
1760 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
1761 | "Fibre Channel Adapter"}; | |
e4adb204 JSEC |
1762 | break; |
1763 | case PCI_DEVICE_ID_NEPTUNE: | |
a747c9ce | 1764 | m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1765 | break; |
1766 | case PCI_DEVICE_ID_NEPTUNE_SCSP: | |
a747c9ce | 1767 | m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1768 | break; |
1769 | case PCI_DEVICE_ID_NEPTUNE_DCSP: | |
a747c9ce | 1770 | m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 | 1771 | break; |
dea3101e | 1772 | case PCI_DEVICE_ID_BMID: |
a747c9ce | 1773 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
dea3101e | 1774 | break; |
1775 | case PCI_DEVICE_ID_BSMB: | |
a747c9ce | 1776 | m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"}; |
dea3101e | 1777 | break; |
1778 | case PCI_DEVICE_ID_ZEPHYR: | |
a747c9ce | 1779 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
dea3101e | 1780 | break; |
e4adb204 | 1781 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
a747c9ce | 1782 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1783 | break; |
1784 | case PCI_DEVICE_ID_ZEPHYR_DCSP: | |
a747c9ce | 1785 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
a257bf90 | 1786 | GE = 1; |
e4adb204 | 1787 | break; |
dea3101e | 1788 | case PCI_DEVICE_ID_ZMID: |
a747c9ce | 1789 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
dea3101e | 1790 | break; |
1791 | case PCI_DEVICE_ID_ZSMB: | |
a747c9ce | 1792 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
dea3101e | 1793 | break; |
1794 | case PCI_DEVICE_ID_LP101: | |
a747c9ce | 1795 | m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"}; |
dea3101e | 1796 | break; |
1797 | case PCI_DEVICE_ID_LP10000S: | |
a747c9ce | 1798 | m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"}; |
06325e74 | 1799 | break; |
e4adb204 | 1800 | case PCI_DEVICE_ID_LP11000S: |
a747c9ce | 1801 | m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"}; |
18a3b596 | 1802 | break; |
e4adb204 | 1803 | case PCI_DEVICE_ID_LPE11000S: |
a747c9ce | 1804 | m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"}; |
5cc36b3c | 1805 | break; |
b87eab38 | 1806 | case PCI_DEVICE_ID_SAT: |
a747c9ce | 1807 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1808 | break; |
1809 | case PCI_DEVICE_ID_SAT_MID: | |
a747c9ce | 1810 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1811 | break; |
1812 | case PCI_DEVICE_ID_SAT_SMB: | |
a747c9ce | 1813 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1814 | break; |
1815 | case PCI_DEVICE_ID_SAT_DCSP: | |
a747c9ce | 1816 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1817 | break; |
1818 | case PCI_DEVICE_ID_SAT_SCSP: | |
a747c9ce | 1819 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1820 | break; |
1821 | case PCI_DEVICE_ID_SAT_S: | |
a747c9ce | 1822 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 | 1823 | break; |
84774a4d | 1824 | case PCI_DEVICE_ID_HORNET: |
a747c9ce | 1825 | m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"}; |
84774a4d JS |
1826 | GE = 1; |
1827 | break; | |
1828 | case PCI_DEVICE_ID_PROTEUS_VF: | |
a747c9ce JS |
1829 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
1830 | "Fibre Channel Adapter"}; | |
84774a4d JS |
1831 | break; |
1832 | case PCI_DEVICE_ID_PROTEUS_PF: | |
a747c9ce JS |
1833 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
1834 | "Fibre Channel Adapter"}; | |
84774a4d JS |
1835 | break; |
1836 | case PCI_DEVICE_ID_PROTEUS_S: | |
a747c9ce JS |
1837 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
1838 | "Fibre Channel Adapter"}; | |
84774a4d | 1839 | break; |
da0436e9 JS |
1840 | case PCI_DEVICE_ID_TIGERSHARK: |
1841 | oneConnect = 1; | |
a747c9ce | 1842 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
da0436e9 | 1843 | break; |
a747c9ce | 1844 | case PCI_DEVICE_ID_TOMCAT: |
6669f9bb | 1845 | oneConnect = 1; |
a747c9ce JS |
1846 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
1847 | break; | |
1848 | case PCI_DEVICE_ID_FALCON: | |
1849 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", | |
1850 | "EmulexSecure Fibre"}; | |
6669f9bb | 1851 | break; |
98fc5dd9 JS |
1852 | case PCI_DEVICE_ID_BALIUS: |
1853 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", | |
1854 | "Fibre Channel Adapter"}; | |
1855 | break; | |
085c647c JS |
1856 | case PCI_DEVICE_ID_LANCER_FC: |
1857 | oneConnect = 1; | |
1858 | m = (typeof(m)){"Undefined", "PCIe", "Fibre Channel Adapter"}; | |
1859 | break; | |
1860 | case PCI_DEVICE_ID_LANCER_FCOE: | |
1861 | oneConnect = 1; | |
1862 | m = (typeof(m)){"Undefined", "PCIe", "FCoE"}; | |
1863 | break; | |
5cc36b3c | 1864 | default: |
a747c9ce | 1865 | m = (typeof(m)){"Unknown", "", ""}; |
e4adb204 | 1866 | break; |
dea3101e | 1867 | } |
74b72a59 JW |
1868 | |
1869 | if (mdp && mdp[0] == '\0') | |
1870 | snprintf(mdp, 79,"%s", m.name); | |
da0436e9 JS |
1871 | /* oneConnect hba requires special processing, they are all initiators |
1872 | * and we put the port number on the end | |
1873 | */ | |
1874 | if (descp && descp[0] == '\0') { | |
1875 | if (oneConnect) | |
1876 | snprintf(descp, 255, | |
a747c9ce JS |
1877 | "Emulex OneConnect %s, %s Initiator, Port %s", |
1878 | m.name, m.function, | |
da0436e9 JS |
1879 | phba->Port); |
1880 | else | |
1881 | snprintf(descp, 255, | |
1882 | "Emulex %s %d%s %s %s", | |
a747c9ce JS |
1883 | m.name, max_speed, (GE) ? "GE" : "Gb", |
1884 | m.bus, m.function); | |
da0436e9 | 1885 | } |
dea3101e | 1886 | } |
1887 | ||
e59058c4 | 1888 | /** |
3621a710 | 1889 | * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring |
e59058c4 JS |
1890 | * @phba: pointer to lpfc hba data structure. |
1891 | * @pring: pointer to a IOCB ring. | |
1892 | * @cnt: the number of IOCBs to be posted to the IOCB ring. | |
1893 | * | |
1894 | * This routine posts a given number of IOCBs with the associated DMA buffer | |
1895 | * descriptors specified by the cnt argument to the given IOCB ring. | |
1896 | * | |
1897 | * Return codes | |
1898 | * The number of IOCBs NOT able to be posted to the IOCB ring. | |
1899 | **/ | |
dea3101e | 1900 | int |
495a714c | 1901 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
dea3101e | 1902 | { |
1903 | IOCB_t *icmd; | |
0bd4ca25 | 1904 | struct lpfc_iocbq *iocb; |
dea3101e | 1905 | struct lpfc_dmabuf *mp1, *mp2; |
1906 | ||
1907 | cnt += pring->missbufcnt; | |
1908 | ||
1909 | /* While there are buffers to post */ | |
1910 | while (cnt > 0) { | |
1911 | /* Allocate buffer for command iocb */ | |
0bd4ca25 | 1912 | iocb = lpfc_sli_get_iocbq(phba); |
dea3101e | 1913 | if (iocb == NULL) { |
1914 | pring->missbufcnt = cnt; | |
1915 | return cnt; | |
1916 | } | |
dea3101e | 1917 | icmd = &iocb->iocb; |
1918 | ||
1919 | /* 2 buffers can be posted per command */ | |
1920 | /* Allocate buffer to post */ | |
1921 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
1922 | if (mp1) | |
98c9ea5c JS |
1923 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
1924 | if (!mp1 || !mp1->virt) { | |
c9475cb0 | 1925 | kfree(mp1); |
604a3e30 | 1926 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e | 1927 | pring->missbufcnt = cnt; |
1928 | return cnt; | |
1929 | } | |
1930 | ||
1931 | INIT_LIST_HEAD(&mp1->list); | |
1932 | /* Allocate buffer to post */ | |
1933 | if (cnt > 1) { | |
1934 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
1935 | if (mp2) | |
1936 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | |
1937 | &mp2->phys); | |
98c9ea5c | 1938 | if (!mp2 || !mp2->virt) { |
c9475cb0 | 1939 | kfree(mp2); |
dea3101e | 1940 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
1941 | kfree(mp1); | |
604a3e30 | 1942 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e | 1943 | pring->missbufcnt = cnt; |
1944 | return cnt; | |
1945 | } | |
1946 | ||
1947 | INIT_LIST_HEAD(&mp2->list); | |
1948 | } else { | |
1949 | mp2 = NULL; | |
1950 | } | |
1951 | ||
1952 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); | |
1953 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); | |
1954 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; | |
1955 | icmd->ulpBdeCount = 1; | |
1956 | cnt--; | |
1957 | if (mp2) { | |
1958 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); | |
1959 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); | |
1960 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; | |
1961 | cnt--; | |
1962 | icmd->ulpBdeCount = 2; | |
1963 | } | |
1964 | ||
1965 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; | |
1966 | icmd->ulpLe = 1; | |
1967 | ||
3772a991 JS |
1968 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
1969 | IOCB_ERROR) { | |
dea3101e | 1970 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
1971 | kfree(mp1); | |
1972 | cnt++; | |
1973 | if (mp2) { | |
1974 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); | |
1975 | kfree(mp2); | |
1976 | cnt++; | |
1977 | } | |
604a3e30 | 1978 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e | 1979 | pring->missbufcnt = cnt; |
dea3101e | 1980 | return cnt; |
1981 | } | |
dea3101e | 1982 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
92d7f7b0 | 1983 | if (mp2) |
dea3101e | 1984 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
dea3101e | 1985 | } |
1986 | pring->missbufcnt = 0; | |
1987 | return 0; | |
1988 | } | |
1989 | ||
e59058c4 | 1990 | /** |
3621a710 | 1991 | * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring |
e59058c4 JS |
1992 | * @phba: pointer to lpfc hba data structure. |
1993 | * | |
1994 | * This routine posts initial receive IOCB buffers to the ELS ring. The | |
1995 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is | |
1996 | * set to 64 IOCBs. | |
1997 | * | |
1998 | * Return codes | |
1999 | * 0 - success (currently always success) | |
2000 | **/ | |
dea3101e | 2001 | static int |
2e0fef85 | 2002 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
dea3101e | 2003 | { |
2004 | struct lpfc_sli *psli = &phba->sli; | |
2005 | ||
2006 | /* Ring 0, ELS / CT buffers */ | |
495a714c | 2007 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
dea3101e | 2008 | /* Ring 2 - FCP no buffers needed */ |
2009 | ||
2010 | return 0; | |
2011 | } | |
2012 | ||
2013 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) | |
2014 | ||
e59058c4 | 2015 | /** |
3621a710 | 2016 | * lpfc_sha_init - Set up initial array of hash table entries |
e59058c4 JS |
2017 | * @HashResultPointer: pointer to an array as hash table. |
2018 | * | |
2019 | * This routine sets up the initial values to the array of hash table entries | |
2020 | * for the LC HBAs. | |
2021 | **/ | |
dea3101e | 2022 | static void |
2023 | lpfc_sha_init(uint32_t * HashResultPointer) | |
2024 | { | |
2025 | HashResultPointer[0] = 0x67452301; | |
2026 | HashResultPointer[1] = 0xEFCDAB89; | |
2027 | HashResultPointer[2] = 0x98BADCFE; | |
2028 | HashResultPointer[3] = 0x10325476; | |
2029 | HashResultPointer[4] = 0xC3D2E1F0; | |
2030 | } | |
2031 | ||
e59058c4 | 2032 | /** |
3621a710 | 2033 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
e59058c4 JS |
2034 | * @HashResultPointer: pointer to an initial/result hash table. |
2035 | * @HashWorkingPointer: pointer to an working hash table. | |
2036 | * | |
2037 | * This routine iterates an initial hash table pointed by @HashResultPointer | |
2038 | * with the values from the working hash table pointeed by @HashWorkingPointer. | |
2039 | * The results are putting back to the initial hash table, returned through | |
2040 | * the @HashResultPointer as the result hash table. | |
2041 | **/ | |
dea3101e | 2042 | static void |
2043 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) | |
2044 | { | |
2045 | int t; | |
2046 | uint32_t TEMP; | |
2047 | uint32_t A, B, C, D, E; | |
2048 | t = 16; | |
2049 | do { | |
2050 | HashWorkingPointer[t] = | |
2051 | S(1, | |
2052 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - | |
2053 | 8] ^ | |
2054 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); | |
2055 | } while (++t <= 79); | |
2056 | t = 0; | |
2057 | A = HashResultPointer[0]; | |
2058 | B = HashResultPointer[1]; | |
2059 | C = HashResultPointer[2]; | |
2060 | D = HashResultPointer[3]; | |
2061 | E = HashResultPointer[4]; | |
2062 | ||
2063 | do { | |
2064 | if (t < 20) { | |
2065 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; | |
2066 | } else if (t < 40) { | |
2067 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; | |
2068 | } else if (t < 60) { | |
2069 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; | |
2070 | } else { | |
2071 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; | |
2072 | } | |
2073 | TEMP += S(5, A) + E + HashWorkingPointer[t]; | |
2074 | E = D; | |
2075 | D = C; | |
2076 | C = S(30, B); | |
2077 | B = A; | |
2078 | A = TEMP; | |
2079 | } while (++t <= 79); | |
2080 | ||
2081 | HashResultPointer[0] += A; | |
2082 | HashResultPointer[1] += B; | |
2083 | HashResultPointer[2] += C; | |
2084 | HashResultPointer[3] += D; | |
2085 | HashResultPointer[4] += E; | |
2086 | ||
2087 | } | |
2088 | ||
e59058c4 | 2089 | /** |
3621a710 | 2090 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
e59058c4 JS |
2091 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
2092 | * @HashWorking: pointer to the entry of the working hash array. | |
2093 | * | |
2094 | * This routine calculates the working hash array referred by @HashWorking | |
2095 | * from the challenge random numbers associated with the host, referred by | |
2096 | * @RandomChallenge. The result is put into the entry of the working hash | |
2097 | * array and returned by reference through @HashWorking. | |
2098 | **/ | |
dea3101e | 2099 | static void |
2100 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) | |
2101 | { | |
2102 | *HashWorking = (*RandomChallenge ^ *HashWorking); | |
2103 | } | |
2104 | ||
e59058c4 | 2105 | /** |
3621a710 | 2106 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
e59058c4 JS |
2107 | * @phba: pointer to lpfc hba data structure. |
2108 | * @hbainit: pointer to an array of unsigned 32-bit integers. | |
2109 | * | |
2110 | * This routine performs the special handling for LC HBA initialization. | |
2111 | **/ | |
dea3101e | 2112 | void |
2113 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) | |
2114 | { | |
2115 | int t; | |
2116 | uint32_t *HashWorking; | |
2e0fef85 | 2117 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
dea3101e | 2118 | |
bbfbbbc1 | 2119 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
dea3101e | 2120 | if (!HashWorking) |
2121 | return; | |
2122 | ||
dea3101e | 2123 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
2124 | HashWorking[1] = HashWorking[79] = *pwwnn; | |
2125 | ||
2126 | for (t = 0; t < 7; t++) | |
2127 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); | |
2128 | ||
2129 | lpfc_sha_init(hbainit); | |
2130 | lpfc_sha_iterate(hbainit, HashWorking); | |
2131 | kfree(HashWorking); | |
2132 | } | |
2133 | ||
e59058c4 | 2134 | /** |
3621a710 | 2135 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
e59058c4 JS |
2136 | * @vport: pointer to a virtual N_Port data structure. |
2137 | * | |
2138 | * This routine performs the necessary cleanups before deleting the @vport. | |
2139 | * It invokes the discovery state machine to perform necessary state | |
2140 | * transitions and to release the ndlps associated with the @vport. Note, | |
2141 | * the physical port is treated as @vport 0. | |
2142 | **/ | |
87af33fe | 2143 | void |
2e0fef85 | 2144 | lpfc_cleanup(struct lpfc_vport *vport) |
dea3101e | 2145 | { |
87af33fe | 2146 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2147 | struct lpfc_nodelist *ndlp, *next_ndlp; |
a8adb832 | 2148 | int i = 0; |
dea3101e | 2149 | |
87af33fe JS |
2150 | if (phba->link_state > LPFC_LINK_DOWN) |
2151 | lpfc_port_link_failure(vport); | |
2152 | ||
2153 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
2154 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
2155 | ndlp = lpfc_enable_node(vport, ndlp, | |
2156 | NLP_STE_UNUSED_NODE); | |
2157 | if (!ndlp) | |
2158 | continue; | |
2159 | spin_lock_irq(&phba->ndlp_lock); | |
2160 | NLP_SET_FREE_REQ(ndlp); | |
2161 | spin_unlock_irq(&phba->ndlp_lock); | |
2162 | /* Trigger the release of the ndlp memory */ | |
2163 | lpfc_nlp_put(ndlp); | |
2164 | continue; | |
2165 | } | |
2166 | spin_lock_irq(&phba->ndlp_lock); | |
2167 | if (NLP_CHK_FREE_REQ(ndlp)) { | |
2168 | /* The ndlp should not be in memory free mode already */ | |
2169 | spin_unlock_irq(&phba->ndlp_lock); | |
2170 | continue; | |
2171 | } else | |
2172 | /* Indicate request for freeing ndlp memory */ | |
2173 | NLP_SET_FREE_REQ(ndlp); | |
2174 | spin_unlock_irq(&phba->ndlp_lock); | |
2175 | ||
58da1ffb JS |
2176 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
2177 | ndlp->nlp_DID == Fabric_DID) { | |
2178 | /* Just free up ndlp with Fabric_DID for vports */ | |
2179 | lpfc_nlp_put(ndlp); | |
2180 | continue; | |
2181 | } | |
2182 | ||
87af33fe JS |
2183 | if (ndlp->nlp_type & NLP_FABRIC) |
2184 | lpfc_disc_state_machine(vport, ndlp, NULL, | |
2185 | NLP_EVT_DEVICE_RECOVERY); | |
e47c9093 | 2186 | |
87af33fe JS |
2187 | lpfc_disc_state_machine(vport, ndlp, NULL, |
2188 | NLP_EVT_DEVICE_RM); | |
495a714c | 2189 | |
87af33fe JS |
2190 | } |
2191 | ||
a8adb832 JS |
2192 | /* At this point, ALL ndlp's should be gone |
2193 | * because of the previous NLP_EVT_DEVICE_RM. | |
2194 | * Lets wait for this to happen, if needed. | |
2195 | */ | |
87af33fe | 2196 | while (!list_empty(&vport->fc_nodes)) { |
a8adb832 | 2197 | if (i++ > 3000) { |
87af33fe | 2198 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
a8adb832 | 2199 | "0233 Nodelist not empty\n"); |
e47c9093 JS |
2200 | list_for_each_entry_safe(ndlp, next_ndlp, |
2201 | &vport->fc_nodes, nlp_listp) { | |
2202 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, | |
2203 | LOG_NODE, | |
d7c255b2 | 2204 | "0282 did:x%x ndlp:x%p " |
e47c9093 JS |
2205 | "usgmap:x%x refcnt:%d\n", |
2206 | ndlp->nlp_DID, (void *)ndlp, | |
2207 | ndlp->nlp_usg_map, | |
2208 | atomic_read( | |
2209 | &ndlp->kref.refcount)); | |
2210 | } | |
a8adb832 | 2211 | break; |
87af33fe | 2212 | } |
a8adb832 JS |
2213 | |
2214 | /* Wait for any activity on ndlps to settle */ | |
2215 | msleep(10); | |
87af33fe | 2216 | } |
dea3101e | 2217 | } |
2218 | ||
e59058c4 | 2219 | /** |
3621a710 | 2220 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
e59058c4 JS |
2221 | * @vport: pointer to a virtual N_Port data structure. |
2222 | * | |
2223 | * This routine stops all the timers associated with a @vport. This function | |
2224 | * is invoked before disabling or deleting a @vport. Note that the physical | |
2225 | * port is treated as @vport 0. | |
2226 | **/ | |
92d7f7b0 JS |
2227 | void |
2228 | lpfc_stop_vport_timers(struct lpfc_vport *vport) | |
dea3101e | 2229 | { |
92d7f7b0 JS |
2230 | del_timer_sync(&vport->els_tmofunc); |
2231 | del_timer_sync(&vport->fc_fdmitmo); | |
2232 | lpfc_can_disctmo(vport); | |
2233 | return; | |
dea3101e | 2234 | } |
2235 | ||
ecfd03c6 JS |
2236 | /** |
2237 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2238 | * @phba: pointer to lpfc hba data structure. | |
2239 | * | |
2240 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The | |
2241 | * caller of this routine should already hold the host lock. | |
2242 | **/ | |
2243 | void | |
2244 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2245 | { | |
5ac6b303 JS |
2246 | /* Clear pending FCF rediscovery wait flag */ |
2247 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; | |
2248 | ||
ecfd03c6 JS |
2249 | /* Now, try to stop the timer */ |
2250 | del_timer(&phba->fcf.redisc_wait); | |
2251 | } | |
2252 | ||
2253 | /** | |
2254 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2255 | * @phba: pointer to lpfc hba data structure. | |
2256 | * | |
2257 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It | |
2258 | * checks whether the FCF rediscovery wait timer is pending with the host | |
2259 | * lock held before proceeding with disabling the timer and clearing the | |
2260 | * wait timer pendig flag. | |
2261 | **/ | |
2262 | void | |
2263 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2264 | { | |
2265 | spin_lock_irq(&phba->hbalock); | |
2266 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
2267 | /* FCF rediscovery timer already fired or stopped */ | |
2268 | spin_unlock_irq(&phba->hbalock); | |
2269 | return; | |
2270 | } | |
2271 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); | |
5ac6b303 JS |
2272 | /* Clear failover in progress flags */ |
2273 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); | |
ecfd03c6 JS |
2274 | spin_unlock_irq(&phba->hbalock); |
2275 | } | |
2276 | ||
e59058c4 | 2277 | /** |
3772a991 | 2278 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
e59058c4 JS |
2279 | * @phba: pointer to lpfc hba data structure. |
2280 | * | |
2281 | * This routine stops all the timers associated with a HBA. This function is | |
2282 | * invoked before either putting a HBA offline or unloading the driver. | |
2283 | **/ | |
3772a991 JS |
2284 | void |
2285 | lpfc_stop_hba_timers(struct lpfc_hba *phba) | |
dea3101e | 2286 | { |
51ef4c26 | 2287 | lpfc_stop_vport_timers(phba->pport); |
2e0fef85 | 2288 | del_timer_sync(&phba->sli.mbox_tmo); |
92d7f7b0 | 2289 | del_timer_sync(&phba->fabric_block_timer); |
9399627f | 2290 | del_timer_sync(&phba->eratt_poll); |
3772a991 JS |
2291 | del_timer_sync(&phba->hb_tmofunc); |
2292 | phba->hb_outstanding = 0; | |
2293 | ||
2294 | switch (phba->pci_dev_grp) { | |
2295 | case LPFC_PCI_DEV_LP: | |
2296 | /* Stop any LightPulse device specific driver timers */ | |
2297 | del_timer_sync(&phba->fcp_poll_timer); | |
2298 | break; | |
2299 | case LPFC_PCI_DEV_OC: | |
2300 | /* Stop any OneConnect device sepcific driver timers */ | |
ecfd03c6 | 2301 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
3772a991 JS |
2302 | break; |
2303 | default: | |
2304 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2305 | "0297 Invalid device group (x%x)\n", | |
2306 | phba->pci_dev_grp); | |
2307 | break; | |
2308 | } | |
2e0fef85 | 2309 | return; |
dea3101e | 2310 | } |
2311 | ||
e59058c4 | 2312 | /** |
3621a710 | 2313 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
e59058c4 JS |
2314 | * @phba: pointer to lpfc hba data structure. |
2315 | * | |
2316 | * This routine marks a HBA's management interface as blocked. Once the HBA's | |
2317 | * management interface is marked as blocked, all the user space access to | |
2318 | * the HBA, whether they are from sysfs interface or libdfc interface will | |
2319 | * all be blocked. The HBA is set to block the management interface when the | |
2320 | * driver prepares the HBA interface for online or offline. | |
2321 | **/ | |
a6ababd2 AB |
2322 | static void |
2323 | lpfc_block_mgmt_io(struct lpfc_hba * phba) | |
2324 | { | |
2325 | unsigned long iflag; | |
6e7288d9 JS |
2326 | uint8_t actcmd = MBX_HEARTBEAT; |
2327 | unsigned long timeout; | |
2328 | ||
a6ababd2 AB |
2329 | |
2330 | spin_lock_irqsave(&phba->hbalock, iflag); | |
2331 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; | |
6e7288d9 JS |
2332 | if (phba->sli.mbox_active) |
2333 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; | |
a6ababd2 | 2334 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
6e7288d9 JS |
2335 | /* Determine how long we might wait for the active mailbox |
2336 | * command to be gracefully completed by firmware. | |
2337 | */ | |
2338 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) + | |
2339 | jiffies; | |
2340 | /* Wait for the outstnading mailbox command to complete */ | |
2341 | while (phba->sli.mbox_active) { | |
2342 | /* Check active mailbox complete status every 2ms */ | |
2343 | msleep(2); | |
2344 | if (time_after(jiffies, timeout)) { | |
2345 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2346 | "2813 Mgmt IO is Blocked %x " | |
2347 | "- mbox cmd %x still active\n", | |
2348 | phba->sli.sli_flag, actcmd); | |
2349 | break; | |
2350 | } | |
2351 | } | |
a6ababd2 AB |
2352 | } |
2353 | ||
e59058c4 | 2354 | /** |
3621a710 | 2355 | * lpfc_online - Initialize and bring a HBA online |
e59058c4 JS |
2356 | * @phba: pointer to lpfc hba data structure. |
2357 | * | |
2358 | * This routine initializes the HBA and brings a HBA online. During this | |
2359 | * process, the management interface is blocked to prevent user space access | |
2360 | * to the HBA interfering with the driver initialization. | |
2361 | * | |
2362 | * Return codes | |
2363 | * 0 - successful | |
2364 | * 1 - failed | |
2365 | **/ | |
dea3101e | 2366 | int |
2e0fef85 | 2367 | lpfc_online(struct lpfc_hba *phba) |
dea3101e | 2368 | { |
372bd282 | 2369 | struct lpfc_vport *vport; |
549e55cd JS |
2370 | struct lpfc_vport **vports; |
2371 | int i; | |
2e0fef85 | 2372 | |
dea3101e | 2373 | if (!phba) |
2374 | return 0; | |
372bd282 | 2375 | vport = phba->pport; |
dea3101e | 2376 | |
2e0fef85 | 2377 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
dea3101e | 2378 | return 0; |
2379 | ||
ed957684 | 2380 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 2381 | "0458 Bring Adapter online\n"); |
dea3101e | 2382 | |
46fa311e JS |
2383 | lpfc_block_mgmt_io(phba); |
2384 | ||
2385 | if (!lpfc_sli_queue_setup(phba)) { | |
2386 | lpfc_unblock_mgmt_io(phba); | |
dea3101e | 2387 | return 1; |
46fa311e | 2388 | } |
dea3101e | 2389 | |
da0436e9 JS |
2390 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2391 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ | |
2392 | lpfc_unblock_mgmt_io(phba); | |
2393 | return 1; | |
2394 | } | |
2395 | } else { | |
2396 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ | |
2397 | lpfc_unblock_mgmt_io(phba); | |
2398 | return 1; | |
2399 | } | |
46fa311e | 2400 | } |
dea3101e | 2401 | |
549e55cd JS |
2402 | vports = lpfc_create_vport_work_array(phba); |
2403 | if (vports != NULL) | |
da0436e9 | 2404 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd JS |
2405 | struct Scsi_Host *shost; |
2406 | shost = lpfc_shost_from_vport(vports[i]); | |
2407 | spin_lock_irq(shost->host_lock); | |
2408 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; | |
2409 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) | |
2410 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
1c6834a7 JS |
2411 | if (phba->sli_rev == LPFC_SLI_REV4) |
2412 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; | |
549e55cd JS |
2413 | spin_unlock_irq(shost->host_lock); |
2414 | } | |
09372820 | 2415 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2416 | |
46fa311e | 2417 | lpfc_unblock_mgmt_io(phba); |
dea3101e | 2418 | return 0; |
2419 | } | |
2420 | ||
e59058c4 | 2421 | /** |
3621a710 | 2422 | * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked |
e59058c4 JS |
2423 | * @phba: pointer to lpfc hba data structure. |
2424 | * | |
2425 | * This routine marks a HBA's management interface as not blocked. Once the | |
2426 | * HBA's management interface is marked as not blocked, all the user space | |
2427 | * access to the HBA, whether they are from sysfs interface or libdfc | |
2428 | * interface will be allowed. The HBA is set to block the management interface | |
2429 | * when the driver prepares the HBA interface for online or offline and then | |
2430 | * set to unblock the management interface afterwards. | |
2431 | **/ | |
46fa311e JS |
2432 | void |
2433 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) | |
2434 | { | |
2435 | unsigned long iflag; | |
2436 | ||
2e0fef85 JS |
2437 | spin_lock_irqsave(&phba->hbalock, iflag); |
2438 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; | |
2439 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
46fa311e JS |
2440 | } |
2441 | ||
e59058c4 | 2442 | /** |
3621a710 | 2443 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
e59058c4 JS |
2444 | * @phba: pointer to lpfc hba data structure. |
2445 | * | |
2446 | * This routine is invoked to prepare a HBA to be brought offline. It performs | |
2447 | * unregistration login to all the nodes on all vports and flushes the mailbox | |
2448 | * queue to make it ready to be brought offline. | |
2449 | **/ | |
46fa311e JS |
2450 | void |
2451 | lpfc_offline_prep(struct lpfc_hba * phba) | |
2452 | { | |
2e0fef85 | 2453 | struct lpfc_vport *vport = phba->pport; |
46fa311e | 2454 | struct lpfc_nodelist *ndlp, *next_ndlp; |
87af33fe | 2455 | struct lpfc_vport **vports; |
72100cc4 | 2456 | struct Scsi_Host *shost; |
87af33fe | 2457 | int i; |
dea3101e | 2458 | |
2e0fef85 | 2459 | if (vport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 2460 | return; |
dea3101e | 2461 | |
46fa311e | 2462 | lpfc_block_mgmt_io(phba); |
dea3101e | 2463 | |
2464 | lpfc_linkdown(phba); | |
2465 | ||
87af33fe JS |
2466 | /* Issue an unreg_login to all nodes on all vports */ |
2467 | vports = lpfc_create_vport_work_array(phba); | |
2468 | if (vports != NULL) { | |
da0436e9 | 2469 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
a8adb832 JS |
2470 | if (vports[i]->load_flag & FC_UNLOADING) |
2471 | continue; | |
72100cc4 JS |
2472 | shost = lpfc_shost_from_vport(vports[i]); |
2473 | spin_lock_irq(shost->host_lock); | |
c868595d | 2474 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
695a814e JS |
2475 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
2476 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; | |
72100cc4 | 2477 | spin_unlock_irq(shost->host_lock); |
695a814e | 2478 | |
87af33fe JS |
2479 | shost = lpfc_shost_from_vport(vports[i]); |
2480 | list_for_each_entry_safe(ndlp, next_ndlp, | |
2481 | &vports[i]->fc_nodes, | |
2482 | nlp_listp) { | |
e47c9093 JS |
2483 | if (!NLP_CHK_NODE_ACT(ndlp)) |
2484 | continue; | |
87af33fe JS |
2485 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
2486 | continue; | |
2487 | if (ndlp->nlp_type & NLP_FABRIC) { | |
2488 | lpfc_disc_state_machine(vports[i], ndlp, | |
2489 | NULL, NLP_EVT_DEVICE_RECOVERY); | |
2490 | lpfc_disc_state_machine(vports[i], ndlp, | |
2491 | NULL, NLP_EVT_DEVICE_RM); | |
2492 | } | |
2493 | spin_lock_irq(shost->host_lock); | |
2494 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | |
2495 | spin_unlock_irq(shost->host_lock); | |
2496 | lpfc_unreg_rpi(vports[i], ndlp); | |
2497 | } | |
2498 | } | |
2499 | } | |
09372820 | 2500 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2501 | |
04c68496 | 2502 | lpfc_sli_mbox_sys_shutdown(phba); |
46fa311e JS |
2503 | } |
2504 | ||
e59058c4 | 2505 | /** |
3621a710 | 2506 | * lpfc_offline - Bring a HBA offline |
e59058c4 JS |
2507 | * @phba: pointer to lpfc hba data structure. |
2508 | * | |
2509 | * This routine actually brings a HBA offline. It stops all the timers | |
2510 | * associated with the HBA, brings down the SLI layer, and eventually | |
2511 | * marks the HBA as in offline state for the upper layer protocol. | |
2512 | **/ | |
46fa311e | 2513 | void |
2e0fef85 | 2514 | lpfc_offline(struct lpfc_hba *phba) |
46fa311e | 2515 | { |
549e55cd JS |
2516 | struct Scsi_Host *shost; |
2517 | struct lpfc_vport **vports; | |
2518 | int i; | |
46fa311e | 2519 | |
549e55cd | 2520 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 2521 | return; |
688a8863 | 2522 | |
da0436e9 JS |
2523 | /* stop port and all timers associated with this hba */ |
2524 | lpfc_stop_port(phba); | |
51ef4c26 JS |
2525 | vports = lpfc_create_vport_work_array(phba); |
2526 | if (vports != NULL) | |
da0436e9 | 2527 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
51ef4c26 | 2528 | lpfc_stop_vport_timers(vports[i]); |
09372820 | 2529 | lpfc_destroy_vport_work_array(phba, vports); |
92d7f7b0 | 2530 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 2531 | "0460 Bring Adapter offline\n"); |
dea3101e | 2532 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
2533 | now. */ | |
2534 | lpfc_sli_hba_down(phba); | |
92d7f7b0 | 2535 | spin_lock_irq(&phba->hbalock); |
7054a606 | 2536 | phba->work_ha = 0; |
92d7f7b0 | 2537 | spin_unlock_irq(&phba->hbalock); |
549e55cd JS |
2538 | vports = lpfc_create_vport_work_array(phba); |
2539 | if (vports != NULL) | |
da0436e9 | 2540 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd | 2541 | shost = lpfc_shost_from_vport(vports[i]); |
549e55cd JS |
2542 | spin_lock_irq(shost->host_lock); |
2543 | vports[i]->work_port_events = 0; | |
2544 | vports[i]->fc_flag |= FC_OFFLINE_MODE; | |
2545 | spin_unlock_irq(shost->host_lock); | |
2546 | } | |
09372820 | 2547 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2548 | } |
2549 | ||
e59058c4 | 2550 | /** |
3621a710 | 2551 | * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists |
e59058c4 JS |
2552 | * @phba: pointer to lpfc hba data structure. |
2553 | * | |
2554 | * This routine is to free all the SCSI buffers and IOCBs from the driver | |
2555 | * list back to kernel. It is called from lpfc_pci_remove_one to free | |
2556 | * the internal resources before the device is removed from the system. | |
2557 | * | |
2558 | * Return codes | |
2559 | * 0 - successful (for now, it always returns 0) | |
2560 | **/ | |
dea3101e | 2561 | static int |
2e0fef85 | 2562 | lpfc_scsi_free(struct lpfc_hba *phba) |
dea3101e | 2563 | { |
2564 | struct lpfc_scsi_buf *sb, *sb_next; | |
2565 | struct lpfc_iocbq *io, *io_next; | |
2566 | ||
2e0fef85 | 2567 | spin_lock_irq(&phba->hbalock); |
dea3101e | 2568 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
1c6f4ef5 | 2569 | spin_lock(&phba->scsi_buf_list_lock); |
dea3101e | 2570 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { |
2571 | list_del(&sb->list); | |
2572 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, | |
92d7f7b0 | 2573 | sb->dma_handle); |
dea3101e | 2574 | kfree(sb); |
2575 | phba->total_scsi_bufs--; | |
2576 | } | |
1c6f4ef5 | 2577 | spin_unlock(&phba->scsi_buf_list_lock); |
dea3101e | 2578 | |
2579 | /* Release all the lpfc_iocbq entries maintained by this host. */ | |
2580 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { | |
2581 | list_del(&io->list); | |
2582 | kfree(io); | |
2583 | phba->total_iocbq_bufs--; | |
2584 | } | |
2e0fef85 | 2585 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 2586 | return 0; |
2587 | } | |
2588 | ||
e59058c4 | 2589 | /** |
3621a710 | 2590 | * lpfc_create_port - Create an FC port |
e59058c4 JS |
2591 | * @phba: pointer to lpfc hba data structure. |
2592 | * @instance: a unique integer ID to this FC port. | |
2593 | * @dev: pointer to the device data structure. | |
2594 | * | |
2595 | * This routine creates a FC port for the upper layer protocol. The FC port | |
2596 | * can be created on top of either a physical port or a virtual port provided | |
2597 | * by the HBA. This routine also allocates a SCSI host data structure (shost) | |
2598 | * and associates the FC port created before adding the shost into the SCSI | |
2599 | * layer. | |
2600 | * | |
2601 | * Return codes | |
2602 | * @vport - pointer to the virtual N_Port data structure. | |
2603 | * NULL - port create failed. | |
2604 | **/ | |
2e0fef85 | 2605 | struct lpfc_vport * |
3de2a653 | 2606 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
47a8617c | 2607 | { |
2e0fef85 JS |
2608 | struct lpfc_vport *vport; |
2609 | struct Scsi_Host *shost; | |
2610 | int error = 0; | |
47a8617c | 2611 | |
3de2a653 JS |
2612 | if (dev != &phba->pcidev->dev) |
2613 | shost = scsi_host_alloc(&lpfc_vport_template, | |
2614 | sizeof(struct lpfc_vport)); | |
2615 | else | |
2616 | shost = scsi_host_alloc(&lpfc_template, | |
2617 | sizeof(struct lpfc_vport)); | |
2e0fef85 JS |
2618 | if (!shost) |
2619 | goto out; | |
47a8617c | 2620 | |
2e0fef85 JS |
2621 | vport = (struct lpfc_vport *) shost->hostdata; |
2622 | vport->phba = phba; | |
2e0fef85 | 2623 | vport->load_flag |= FC_LOADING; |
92d7f7b0 | 2624 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
7f5f3d0d | 2625 | vport->fc_rscn_flush = 0; |
47a8617c | 2626 | |
3de2a653 | 2627 | lpfc_get_vport_cfgparam(vport); |
2e0fef85 JS |
2628 | shost->unique_id = instance; |
2629 | shost->max_id = LPFC_MAX_TARGET; | |
3de2a653 | 2630 | shost->max_lun = vport->cfg_max_luns; |
2e0fef85 JS |
2631 | shost->this_id = -1; |
2632 | shost->max_cmd_len = 16; | |
da0436e9 | 2633 | if (phba->sli_rev == LPFC_SLI_REV4) { |
28baac74 | 2634 | shost->dma_boundary = |
cb5172ea | 2635 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
da0436e9 JS |
2636 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
2637 | } | |
81301a9b | 2638 | |
47a8617c | 2639 | /* |
2e0fef85 JS |
2640 | * Set initial can_queue value since 0 is no longer supported and |
2641 | * scsi_add_host will fail. This will be adjusted later based on the | |
2642 | * max xri value determined in hba setup. | |
47a8617c | 2643 | */ |
2e0fef85 | 2644 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
3de2a653 | 2645 | if (dev != &phba->pcidev->dev) { |
92d7f7b0 JS |
2646 | shost->transportt = lpfc_vport_transport_template; |
2647 | vport->port_type = LPFC_NPIV_PORT; | |
2648 | } else { | |
2649 | shost->transportt = lpfc_transport_template; | |
2650 | vport->port_type = LPFC_PHYSICAL_PORT; | |
2651 | } | |
47a8617c | 2652 | |
2e0fef85 JS |
2653 | /* Initialize all internally managed lists. */ |
2654 | INIT_LIST_HEAD(&vport->fc_nodes); | |
da0436e9 | 2655 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
2e0fef85 | 2656 | spin_lock_init(&vport->work_port_lock); |
47a8617c | 2657 | |
2e0fef85 JS |
2658 | init_timer(&vport->fc_disctmo); |
2659 | vport->fc_disctmo.function = lpfc_disc_timeout; | |
92d7f7b0 | 2660 | vport->fc_disctmo.data = (unsigned long)vport; |
47a8617c | 2661 | |
2e0fef85 JS |
2662 | init_timer(&vport->fc_fdmitmo); |
2663 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; | |
92d7f7b0 | 2664 | vport->fc_fdmitmo.data = (unsigned long)vport; |
47a8617c | 2665 | |
2e0fef85 JS |
2666 | init_timer(&vport->els_tmofunc); |
2667 | vport->els_tmofunc.function = lpfc_els_timeout; | |
92d7f7b0 | 2668 | vport->els_tmofunc.data = (unsigned long)vport; |
d139b9bd | 2669 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
2e0fef85 JS |
2670 | if (error) |
2671 | goto out_put_shost; | |
47a8617c | 2672 | |
549e55cd | 2673 | spin_lock_irq(&phba->hbalock); |
2e0fef85 | 2674 | list_add_tail(&vport->listentry, &phba->port_list); |
549e55cd | 2675 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 2676 | return vport; |
47a8617c | 2677 | |
2e0fef85 JS |
2678 | out_put_shost: |
2679 | scsi_host_put(shost); | |
2680 | out: | |
2681 | return NULL; | |
47a8617c JS |
2682 | } |
2683 | ||
e59058c4 | 2684 | /** |
3621a710 | 2685 | * destroy_port - destroy an FC port |
e59058c4 JS |
2686 | * @vport: pointer to an lpfc virtual N_Port data structure. |
2687 | * | |
2688 | * This routine destroys a FC port from the upper layer protocol. All the | |
2689 | * resources associated with the port are released. | |
2690 | **/ | |
2e0fef85 JS |
2691 | void |
2692 | destroy_port(struct lpfc_vport *vport) | |
47a8617c | 2693 | { |
92d7f7b0 JS |
2694 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2695 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 2696 | |
858c9f6c | 2697 | lpfc_debugfs_terminate(vport); |
92d7f7b0 JS |
2698 | fc_remove_host(shost); |
2699 | scsi_remove_host(shost); | |
47a8617c | 2700 | |
92d7f7b0 JS |
2701 | spin_lock_irq(&phba->hbalock); |
2702 | list_del_init(&vport->listentry); | |
2703 | spin_unlock_irq(&phba->hbalock); | |
47a8617c | 2704 | |
92d7f7b0 | 2705 | lpfc_cleanup(vport); |
47a8617c | 2706 | return; |
47a8617c JS |
2707 | } |
2708 | ||
e59058c4 | 2709 | /** |
3621a710 | 2710 | * lpfc_get_instance - Get a unique integer ID |
e59058c4 JS |
2711 | * |
2712 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It | |
2713 | * uses the kernel idr facility to perform the task. | |
2714 | * | |
2715 | * Return codes: | |
2716 | * instance - a unique integer ID allocated as the new instance. | |
2717 | * -1 - lpfc get instance failed. | |
2718 | **/ | |
92d7f7b0 JS |
2719 | int |
2720 | lpfc_get_instance(void) | |
2721 | { | |
2722 | int instance = 0; | |
47a8617c | 2723 | |
92d7f7b0 JS |
2724 | /* Assign an unused number */ |
2725 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) | |
2726 | return -1; | |
2727 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) | |
2728 | return -1; | |
2729 | return instance; | |
47a8617c JS |
2730 | } |
2731 | ||
e59058c4 | 2732 | /** |
3621a710 | 2733 | * lpfc_scan_finished - method for SCSI layer to detect whether scan is done |
e59058c4 JS |
2734 | * @shost: pointer to SCSI host data structure. |
2735 | * @time: elapsed time of the scan in jiffies. | |
2736 | * | |
2737 | * This routine is called by the SCSI layer with a SCSI host to determine | |
2738 | * whether the scan host is finished. | |
2739 | * | |
2740 | * Note: there is no scan_start function as adapter initialization will have | |
2741 | * asynchronously kicked off the link initialization. | |
2742 | * | |
2743 | * Return codes | |
2744 | * 0 - SCSI host scan is not over yet. | |
2745 | * 1 - SCSI host scan is over. | |
2746 | **/ | |
47a8617c JS |
2747 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
2748 | { | |
2e0fef85 JS |
2749 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
2750 | struct lpfc_hba *phba = vport->phba; | |
858c9f6c | 2751 | int stat = 0; |
47a8617c | 2752 | |
858c9f6c JS |
2753 | spin_lock_irq(shost->host_lock); |
2754 | ||
51ef4c26 | 2755 | if (vport->load_flag & FC_UNLOADING) { |
858c9f6c JS |
2756 | stat = 1; |
2757 | goto finished; | |
2758 | } | |
2e0fef85 JS |
2759 | if (time >= 30 * HZ) { |
2760 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
2761 | "0461 Scanning longer than 30 " |
2762 | "seconds. Continuing initialization\n"); | |
858c9f6c | 2763 | stat = 1; |
47a8617c | 2764 | goto finished; |
2e0fef85 JS |
2765 | } |
2766 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { | |
2767 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
2768 | "0465 Link down longer than 15 " |
2769 | "seconds. Continuing initialization\n"); | |
858c9f6c | 2770 | stat = 1; |
47a8617c | 2771 | goto finished; |
2e0fef85 | 2772 | } |
47a8617c | 2773 | |
2e0fef85 | 2774 | if (vport->port_state != LPFC_VPORT_READY) |
858c9f6c | 2775 | goto finished; |
2e0fef85 | 2776 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
858c9f6c | 2777 | goto finished; |
2e0fef85 | 2778 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
858c9f6c | 2779 | goto finished; |
2e0fef85 | 2780 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
858c9f6c JS |
2781 | goto finished; |
2782 | ||
2783 | stat = 1; | |
47a8617c JS |
2784 | |
2785 | finished: | |
858c9f6c JS |
2786 | spin_unlock_irq(shost->host_lock); |
2787 | return stat; | |
92d7f7b0 | 2788 | } |
47a8617c | 2789 | |
e59058c4 | 2790 | /** |
3621a710 | 2791 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
e59058c4 JS |
2792 | * @shost: pointer to SCSI host data structure. |
2793 | * | |
2794 | * This routine initializes a given SCSI host attributes on a FC port. The | |
2795 | * SCSI host can be either on top of a physical port or a virtual port. | |
2796 | **/ | |
92d7f7b0 JS |
2797 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
2798 | { | |
2799 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2800 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 2801 | /* |
2e0fef85 | 2802 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
47a8617c JS |
2803 | */ |
2804 | ||
2e0fef85 JS |
2805 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
2806 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
47a8617c JS |
2807 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
2808 | ||
2809 | memset(fc_host_supported_fc4s(shost), 0, | |
2e0fef85 | 2810 | sizeof(fc_host_supported_fc4s(shost))); |
47a8617c JS |
2811 | fc_host_supported_fc4s(shost)[2] = 1; |
2812 | fc_host_supported_fc4s(shost)[7] = 1; | |
2813 | ||
92d7f7b0 JS |
2814 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
2815 | sizeof fc_host_symbolic_name(shost)); | |
47a8617c JS |
2816 | |
2817 | fc_host_supported_speeds(shost) = 0; | |
2818 | if (phba->lmt & LMT_10Gb) | |
2819 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; | |
a8adb832 JS |
2820 | if (phba->lmt & LMT_8Gb) |
2821 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; | |
47a8617c JS |
2822 | if (phba->lmt & LMT_4Gb) |
2823 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; | |
2824 | if (phba->lmt & LMT_2Gb) | |
2825 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; | |
2826 | if (phba->lmt & LMT_1Gb) | |
2827 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; | |
2828 | ||
2829 | fc_host_maxframe_size(shost) = | |
2e0fef85 JS |
2830 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
2831 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; | |
47a8617c | 2832 | |
0af5d708 MC |
2833 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
2834 | ||
47a8617c JS |
2835 | /* This value is also unchanging */ |
2836 | memset(fc_host_active_fc4s(shost), 0, | |
2e0fef85 | 2837 | sizeof(fc_host_active_fc4s(shost))); |
47a8617c JS |
2838 | fc_host_active_fc4s(shost)[2] = 1; |
2839 | fc_host_active_fc4s(shost)[7] = 1; | |
2840 | ||
92d7f7b0 | 2841 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
47a8617c | 2842 | spin_lock_irq(shost->host_lock); |
51ef4c26 | 2843 | vport->load_flag &= ~FC_LOADING; |
47a8617c | 2844 | spin_unlock_irq(shost->host_lock); |
47a8617c | 2845 | } |
dea3101e | 2846 | |
e59058c4 | 2847 | /** |
da0436e9 | 2848 | * lpfc_stop_port_s3 - Stop SLI3 device port |
e59058c4 JS |
2849 | * @phba: pointer to lpfc hba data structure. |
2850 | * | |
da0436e9 JS |
2851 | * This routine is invoked to stop an SLI3 device port, it stops the device |
2852 | * from generating interrupts and stops the device driver's timers for the | |
2853 | * device. | |
e59058c4 | 2854 | **/ |
da0436e9 JS |
2855 | static void |
2856 | lpfc_stop_port_s3(struct lpfc_hba *phba) | |
db2378e0 | 2857 | { |
da0436e9 JS |
2858 | /* Clear all interrupt enable conditions */ |
2859 | writel(0, phba->HCregaddr); | |
2860 | readl(phba->HCregaddr); /* flush */ | |
2861 | /* Clear all pending interrupts */ | |
2862 | writel(0xffffffff, phba->HAregaddr); | |
2863 | readl(phba->HAregaddr); /* flush */ | |
db2378e0 | 2864 | |
da0436e9 JS |
2865 | /* Reset some HBA SLI setup states */ |
2866 | lpfc_stop_hba_timers(phba); | |
2867 | phba->pport->work_port_events = 0; | |
2868 | } | |
db2378e0 | 2869 | |
da0436e9 JS |
2870 | /** |
2871 | * lpfc_stop_port_s4 - Stop SLI4 device port | |
2872 | * @phba: pointer to lpfc hba data structure. | |
2873 | * | |
2874 | * This routine is invoked to stop an SLI4 device port, it stops the device | |
2875 | * from generating interrupts and stops the device driver's timers for the | |
2876 | * device. | |
2877 | **/ | |
2878 | static void | |
2879 | lpfc_stop_port_s4(struct lpfc_hba *phba) | |
2880 | { | |
2881 | /* Reset some HBA SLI4 setup states */ | |
2882 | lpfc_stop_hba_timers(phba); | |
2883 | phba->pport->work_port_events = 0; | |
2884 | phba->sli4_hba.intr_enable = 0; | |
da0436e9 | 2885 | } |
9399627f | 2886 | |
da0436e9 JS |
2887 | /** |
2888 | * lpfc_stop_port - Wrapper function for stopping hba port | |
2889 | * @phba: Pointer to HBA context object. | |
2890 | * | |
2891 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from | |
2892 | * the API jump table function pointer from the lpfc_hba struct. | |
2893 | **/ | |
2894 | void | |
2895 | lpfc_stop_port(struct lpfc_hba *phba) | |
2896 | { | |
2897 | phba->lpfc_stop_port(phba); | |
2898 | } | |
db2378e0 | 2899 | |
ecfd03c6 JS |
2900 | /** |
2901 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer | |
2902 | * @phba: Pointer to hba for which this call is being executed. | |
2903 | * | |
2904 | * This routine starts the timer waiting for the FCF rediscovery to complete. | |
2905 | **/ | |
2906 | void | |
2907 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) | |
2908 | { | |
2909 | unsigned long fcf_redisc_wait_tmo = | |
2910 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); | |
2911 | /* Start fcf rediscovery wait period timer */ | |
2912 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); | |
2913 | spin_lock_irq(&phba->hbalock); | |
2914 | /* Allow action to new fcf asynchronous event */ | |
2915 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); | |
2916 | /* Mark the FCF rediscovery pending state */ | |
2917 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; | |
2918 | spin_unlock_irq(&phba->hbalock); | |
2919 | } | |
2920 | ||
2921 | /** | |
2922 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout | |
2923 | * @ptr: Map to lpfc_hba data structure pointer. | |
2924 | * | |
2925 | * This routine is invoked when waiting for FCF table rediscover has been | |
2926 | * timed out. If new FCF record(s) has (have) been discovered during the | |
2927 | * wait period, a new FCF event shall be added to the FCOE async event | |
2928 | * list, and then worker thread shall be waked up for processing from the | |
2929 | * worker thread context. | |
2930 | **/ | |
2931 | void | |
2932 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) | |
2933 | { | |
2934 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; | |
2935 | ||
2936 | /* Don't send FCF rediscovery event if timer cancelled */ | |
2937 | spin_lock_irq(&phba->hbalock); | |
2938 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
2939 | spin_unlock_irq(&phba->hbalock); | |
2940 | return; | |
2941 | } | |
2942 | /* Clear FCF rediscovery timer pending flag */ | |
2943 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; | |
2944 | /* FCF rediscovery event to worker thread */ | |
2945 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; | |
2946 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 | 2947 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 2948 | "2776 FCF rediscover quiescent timer expired\n"); |
ecfd03c6 JS |
2949 | /* wake up worker thread */ |
2950 | lpfc_worker_wake_up(phba); | |
2951 | } | |
2952 | ||
6669f9bb JS |
2953 | /** |
2954 | * lpfc_sli4_fw_cfg_check - Read the firmware config and verify FCoE support | |
2955 | * @phba: pointer to lpfc hba data structure. | |
2956 | * | |
2957 | * This function uses the QUERY_FW_CFG mailbox command to determine if the | |
2958 | * firmware loaded supports FCoE. A return of zero indicates that the mailbox | |
2959 | * was successful and the firmware supports FCoE. Any other return indicates | |
2960 | * a error. It is assumed that this function will be called before interrupts | |
2961 | * are enabled. | |
2962 | **/ | |
2963 | static int | |
2964 | lpfc_sli4_fw_cfg_check(struct lpfc_hba *phba) | |
2965 | { | |
2966 | int rc = 0; | |
2967 | LPFC_MBOXQ_t *mboxq; | |
2968 | struct lpfc_mbx_query_fw_cfg *query_fw_cfg; | |
2969 | uint32_t length; | |
2970 | uint32_t shdr_status, shdr_add_status; | |
2971 | ||
2972 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
2973 | if (!mboxq) { | |
2974 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2975 | "2621 Failed to allocate mbox for " | |
2976 | "query firmware config cmd\n"); | |
2977 | return -ENOMEM; | |
2978 | } | |
2979 | query_fw_cfg = &mboxq->u.mqe.un.query_fw_cfg; | |
2980 | length = (sizeof(struct lpfc_mbx_query_fw_cfg) - | |
2981 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
2982 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
2983 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, | |
2984 | length, LPFC_SLI4_MBX_EMBED); | |
2985 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
2986 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
2987 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
2988 | &query_fw_cfg->header.cfg_shdr.response); | |
2989 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
2990 | &query_fw_cfg->header.cfg_shdr.response); | |
2991 | if (shdr_status || shdr_add_status || rc != MBX_SUCCESS) { | |
2992 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2993 | "2622 Query Firmware Config failed " | |
2994 | "mbx status x%x, status x%x add_status x%x\n", | |
2995 | rc, shdr_status, shdr_add_status); | |
2996 | return -EINVAL; | |
2997 | } | |
2998 | if (!bf_get(lpfc_function_mode_fcoe_i, query_fw_cfg)) { | |
2999 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3000 | "2623 FCoE Function not supported by firmware. " | |
3001 | "Function mode = %08x\n", | |
3002 | query_fw_cfg->function_mode); | |
3003 | return -EINVAL; | |
3004 | } | |
3005 | if (rc != MBX_TIMEOUT) | |
3006 | mempool_free(mboxq, phba->mbox_mem_pool); | |
3007 | return 0; | |
3008 | } | |
3009 | ||
e59058c4 | 3010 | /** |
da0436e9 | 3011 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
e59058c4 | 3012 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3013 | * @acqe_link: pointer to the async link completion queue entry. |
e59058c4 | 3014 | * |
da0436e9 JS |
3015 | * This routine is to parse the SLI4 link-attention link fault code and |
3016 | * translate it into the base driver's read link attention mailbox command | |
3017 | * status. | |
3018 | * | |
3019 | * Return: Link-attention status in terms of base driver's coding. | |
e59058c4 | 3020 | **/ |
da0436e9 JS |
3021 | static uint16_t |
3022 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, | |
3023 | struct lpfc_acqe_link *acqe_link) | |
db2378e0 | 3024 | { |
da0436e9 | 3025 | uint16_t latt_fault; |
9399627f | 3026 | |
da0436e9 JS |
3027 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
3028 | case LPFC_ASYNC_LINK_FAULT_NONE: | |
3029 | case LPFC_ASYNC_LINK_FAULT_LOCAL: | |
3030 | case LPFC_ASYNC_LINK_FAULT_REMOTE: | |
3031 | latt_fault = 0; | |
3032 | break; | |
3033 | default: | |
3034 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3035 | "0398 Invalid link fault code: x%x\n", | |
3036 | bf_get(lpfc_acqe_link_fault, acqe_link)); | |
3037 | latt_fault = MBXERR_ERROR; | |
3038 | break; | |
3039 | } | |
3040 | return latt_fault; | |
db2378e0 JS |
3041 | } |
3042 | ||
5b75da2f | 3043 | /** |
da0436e9 | 3044 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
5b75da2f | 3045 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3046 | * @acqe_link: pointer to the async link completion queue entry. |
5b75da2f | 3047 | * |
da0436e9 JS |
3048 | * This routine is to parse the SLI4 link attention type and translate it |
3049 | * into the base driver's link attention type coding. | |
5b75da2f | 3050 | * |
da0436e9 JS |
3051 | * Return: Link attention type in terms of base driver's coding. |
3052 | **/ | |
3053 | static uint8_t | |
3054 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, | |
3055 | struct lpfc_acqe_link *acqe_link) | |
5b75da2f | 3056 | { |
da0436e9 | 3057 | uint8_t att_type; |
5b75da2f | 3058 | |
da0436e9 JS |
3059 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
3060 | case LPFC_ASYNC_LINK_STATUS_DOWN: | |
3061 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: | |
3062 | att_type = AT_LINK_DOWN; | |
3063 | break; | |
3064 | case LPFC_ASYNC_LINK_STATUS_UP: | |
3065 | /* Ignore physical link up events - wait for logical link up */ | |
3066 | att_type = AT_RESERVED; | |
3067 | break; | |
3068 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: | |
3069 | att_type = AT_LINK_UP; | |
3070 | break; | |
3071 | default: | |
3072 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3073 | "0399 Invalid link attention type: x%x\n", | |
3074 | bf_get(lpfc_acqe_link_status, acqe_link)); | |
3075 | att_type = AT_RESERVED; | |
3076 | break; | |
5b75da2f | 3077 | } |
da0436e9 | 3078 | return att_type; |
5b75da2f JS |
3079 | } |
3080 | ||
3081 | /** | |
da0436e9 | 3082 | * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed |
5b75da2f | 3083 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3084 | * @acqe_link: pointer to the async link completion queue entry. |
5b75da2f | 3085 | * |
da0436e9 JS |
3086 | * This routine is to parse the SLI4 link-attention link speed and translate |
3087 | * it into the base driver's link-attention link speed coding. | |
3088 | * | |
3089 | * Return: Link-attention link speed in terms of base driver's coding. | |
3090 | **/ | |
3091 | static uint8_t | |
3092 | lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba, | |
3093 | struct lpfc_acqe_link *acqe_link) | |
5b75da2f | 3094 | { |
da0436e9 JS |
3095 | uint8_t link_speed; |
3096 | ||
3097 | switch (bf_get(lpfc_acqe_link_speed, acqe_link)) { | |
3098 | case LPFC_ASYNC_LINK_SPEED_ZERO: | |
3099 | link_speed = LA_UNKNW_LINK; | |
3100 | break; | |
3101 | case LPFC_ASYNC_LINK_SPEED_10MBPS: | |
3102 | link_speed = LA_UNKNW_LINK; | |
3103 | break; | |
3104 | case LPFC_ASYNC_LINK_SPEED_100MBPS: | |
3105 | link_speed = LA_UNKNW_LINK; | |
3106 | break; | |
3107 | case LPFC_ASYNC_LINK_SPEED_1GBPS: | |
3108 | link_speed = LA_1GHZ_LINK; | |
3109 | break; | |
3110 | case LPFC_ASYNC_LINK_SPEED_10GBPS: | |
3111 | link_speed = LA_10GHZ_LINK; | |
3112 | break; | |
3113 | default: | |
3114 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3115 | "0483 Invalid link-attention link speed: x%x\n", | |
3116 | bf_get(lpfc_acqe_link_speed, acqe_link)); | |
3117 | link_speed = LA_UNKNW_LINK; | |
3118 | break; | |
3119 | } | |
3120 | return link_speed; | |
3121 | } | |
3122 | ||
3123 | /** | |
3124 | * lpfc_sli4_async_link_evt - Process the asynchronous link event | |
3125 | * @phba: pointer to lpfc hba data structure. | |
3126 | * @acqe_link: pointer to the async link completion queue entry. | |
3127 | * | |
3128 | * This routine is to handle the SLI4 asynchronous link event. | |
3129 | **/ | |
3130 | static void | |
3131 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, | |
3132 | struct lpfc_acqe_link *acqe_link) | |
3133 | { | |
3134 | struct lpfc_dmabuf *mp; | |
3135 | LPFC_MBOXQ_t *pmb; | |
3136 | MAILBOX_t *mb; | |
3137 | READ_LA_VAR *la; | |
3138 | uint8_t att_type; | |
3139 | ||
3140 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); | |
3141 | if (att_type != AT_LINK_DOWN && att_type != AT_LINK_UP) | |
3142 | return; | |
32b9793f | 3143 | phba->fcoe_eventtag = acqe_link->event_tag; |
da0436e9 JS |
3144 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3145 | if (!pmb) { | |
3146 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3147 | "0395 The mboxq allocation failed\n"); | |
3148 | return; | |
3149 | } | |
3150 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
3151 | if (!mp) { | |
3152 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3153 | "0396 The lpfc_dmabuf allocation failed\n"); | |
3154 | goto out_free_pmb; | |
3155 | } | |
3156 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
3157 | if (!mp->virt) { | |
3158 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3159 | "0397 The mbuf allocation failed\n"); | |
3160 | goto out_free_dmabuf; | |
3161 | } | |
3162 | ||
3163 | /* Cleanup any outstanding ELS commands */ | |
3164 | lpfc_els_flush_all_cmd(phba); | |
3165 | ||
3166 | /* Block ELS IOCBs until we have done process link event */ | |
3167 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
3168 | ||
3169 | /* Update link event statistics */ | |
3170 | phba->sli.slistat.link_event++; | |
3171 | ||
3172 | /* Create pseudo lpfc_handle_latt mailbox command from link ACQE */ | |
3173 | lpfc_read_la(phba, pmb, mp); | |
3174 | pmb->vport = phba->pport; | |
3175 | ||
3176 | /* Parse and translate status field */ | |
3177 | mb = &pmb->u.mb; | |
3178 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); | |
3179 | ||
3180 | /* Parse and translate link attention fields */ | |
3181 | la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA; | |
3182 | la->eventTag = acqe_link->event_tag; | |
3183 | la->attType = att_type; | |
3184 | la->UlnkSpeed = lpfc_sli4_parse_latt_link_speed(phba, acqe_link); | |
3185 | ||
3186 | /* Fake the the following irrelvant fields */ | |
3187 | la->topology = TOPOLOGY_PT_PT; | |
3188 | la->granted_AL_PA = 0; | |
3189 | la->il = 0; | |
3190 | la->pb = 0; | |
3191 | la->fa = 0; | |
3192 | la->mm = 0; | |
3193 | ||
3194 | /* Keep the link status for extra SLI4 state machine reference */ | |
3195 | phba->sli4_hba.link_state.speed = | |
3196 | bf_get(lpfc_acqe_link_speed, acqe_link); | |
3197 | phba->sli4_hba.link_state.duplex = | |
3198 | bf_get(lpfc_acqe_link_duplex, acqe_link); | |
3199 | phba->sli4_hba.link_state.status = | |
3200 | bf_get(lpfc_acqe_link_status, acqe_link); | |
3201 | phba->sli4_hba.link_state.physical = | |
3202 | bf_get(lpfc_acqe_link_physical, acqe_link); | |
3203 | phba->sli4_hba.link_state.fault = | |
3204 | bf_get(lpfc_acqe_link_fault, acqe_link); | |
65467b6b JS |
3205 | phba->sli4_hba.link_state.logical_speed = |
3206 | bf_get(lpfc_acqe_qos_link_speed, acqe_link); | |
da0436e9 JS |
3207 | |
3208 | /* Invoke the lpfc_handle_latt mailbox command callback function */ | |
3209 | lpfc_mbx_cmpl_read_la(phba, pmb); | |
3210 | ||
5b75da2f | 3211 | return; |
da0436e9 JS |
3212 | |
3213 | out_free_dmabuf: | |
3214 | kfree(mp); | |
3215 | out_free_pmb: | |
3216 | mempool_free(pmb, phba->mbox_mem_pool); | |
3217 | } | |
3218 | ||
fc2b989b JS |
3219 | /** |
3220 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport | |
3221 | * @vport: pointer to vport data structure. | |
3222 | * | |
3223 | * This routine is to perform Clear Virtual Link (CVL) on a vport in | |
3224 | * response to a CVL event. | |
3225 | * | |
3226 | * Return the pointer to the ndlp with the vport if successful, otherwise | |
3227 | * return NULL. | |
3228 | **/ | |
3229 | static struct lpfc_nodelist * | |
3230 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) | |
3231 | { | |
3232 | struct lpfc_nodelist *ndlp; | |
3233 | struct Scsi_Host *shost; | |
3234 | struct lpfc_hba *phba; | |
3235 | ||
3236 | if (!vport) | |
3237 | return NULL; | |
fc2b989b JS |
3238 | phba = vport->phba; |
3239 | if (!phba) | |
3240 | return NULL; | |
78730cfe JS |
3241 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
3242 | if (!ndlp) { | |
3243 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | |
3244 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
3245 | if (!ndlp) | |
3246 | return 0; | |
3247 | lpfc_nlp_init(vport, ndlp, Fabric_DID); | |
3248 | /* Set the node type */ | |
3249 | ndlp->nlp_type |= NLP_FABRIC; | |
3250 | /* Put ndlp onto node list */ | |
3251 | lpfc_enqueue_node(vport, ndlp); | |
3252 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
3253 | /* re-setup ndlp without removing from node list */ | |
3254 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
3255 | if (!ndlp) | |
3256 | return 0; | |
3257 | } | |
63e801ce JS |
3258 | if ((phba->pport->port_state < LPFC_FLOGI) && |
3259 | (phba->pport->port_state != LPFC_VPORT_FAILED)) | |
fc2b989b JS |
3260 | return NULL; |
3261 | /* If virtual link is not yet instantiated ignore CVL */ | |
63e801ce JS |
3262 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
3263 | && (vport->port_state != LPFC_VPORT_FAILED)) | |
fc2b989b JS |
3264 | return NULL; |
3265 | shost = lpfc_shost_from_vport(vport); | |
3266 | if (!shost) | |
3267 | return NULL; | |
3268 | lpfc_linkdown_port(vport); | |
3269 | lpfc_cleanup_pending_mbox(vport); | |
3270 | spin_lock_irq(shost->host_lock); | |
3271 | vport->fc_flag |= FC_VPORT_CVL_RCVD; | |
3272 | spin_unlock_irq(shost->host_lock); | |
3273 | ||
3274 | return ndlp; | |
3275 | } | |
3276 | ||
3277 | /** | |
3278 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports | |
3279 | * @vport: pointer to lpfc hba data structure. | |
3280 | * | |
3281 | * This routine is to perform Clear Virtual Link (CVL) on all vports in | |
3282 | * response to a FCF dead event. | |
3283 | **/ | |
3284 | static void | |
3285 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) | |
3286 | { | |
3287 | struct lpfc_vport **vports; | |
3288 | int i; | |
3289 | ||
3290 | vports = lpfc_create_vport_work_array(phba); | |
3291 | if (vports) | |
3292 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) | |
3293 | lpfc_sli4_perform_vport_cvl(vports[i]); | |
3294 | lpfc_destroy_vport_work_array(phba, vports); | |
3295 | } | |
3296 | ||
da0436e9 JS |
3297 | /** |
3298 | * lpfc_sli4_async_fcoe_evt - Process the asynchronous fcoe event | |
3299 | * @phba: pointer to lpfc hba data structure. | |
3300 | * @acqe_link: pointer to the async fcoe completion queue entry. | |
3301 | * | |
3302 | * This routine is to handle the SLI4 asynchronous fcoe event. | |
3303 | **/ | |
3304 | static void | |
3305 | lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba, | |
3306 | struct lpfc_acqe_fcoe *acqe_fcoe) | |
3307 | { | |
3308 | uint8_t event_type = bf_get(lpfc_acqe_fcoe_event_type, acqe_fcoe); | |
3309 | int rc; | |
6669f9bb JS |
3310 | struct lpfc_vport *vport; |
3311 | struct lpfc_nodelist *ndlp; | |
3312 | struct Scsi_Host *shost; | |
695a814e JS |
3313 | int active_vlink_present; |
3314 | struct lpfc_vport **vports; | |
3315 | int i; | |
da0436e9 | 3316 | |
4d9ab994 | 3317 | phba->fc_eventTag = acqe_fcoe->event_tag; |
32b9793f | 3318 | phba->fcoe_eventtag = acqe_fcoe->event_tag; |
da0436e9 JS |
3319 | switch (event_type) { |
3320 | case LPFC_FCOE_EVENT_TYPE_NEW_FCF: | |
ecfd03c6 | 3321 | case LPFC_FCOE_EVENT_TYPE_FCF_PARAM_MOD: |
999d813f JS |
3322 | if (event_type == LPFC_FCOE_EVENT_TYPE_NEW_FCF) |
3323 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | | |
3324 | LOG_DISCOVERY, | |
a93ff37a JS |
3325 | "2546 New FCF event, evt_tag:x%x, " |
3326 | "index:x%x\n", | |
999d813f JS |
3327 | acqe_fcoe->event_tag, |
3328 | acqe_fcoe->index); | |
3329 | else | |
3330 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | | |
3331 | LOG_DISCOVERY, | |
a93ff37a JS |
3332 | "2788 FCF param modified event, " |
3333 | "evt_tag:x%x, index:x%x\n", | |
999d813f JS |
3334 | acqe_fcoe->event_tag, |
3335 | acqe_fcoe->index); | |
38b92ef8 | 3336 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
0c9ab6f5 JS |
3337 | /* |
3338 | * During period of FCF discovery, read the FCF | |
3339 | * table record indexed by the event to update | |
a93ff37a | 3340 | * FCF roundrobin failover eligible FCF bmask. |
0c9ab6f5 JS |
3341 | */ |
3342 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | | |
3343 | LOG_DISCOVERY, | |
a93ff37a JS |
3344 | "2779 Read FCF (x%x) for updating " |
3345 | "roundrobin FCF failover bmask\n", | |
0c9ab6f5 JS |
3346 | acqe_fcoe->index); |
3347 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fcoe->index); | |
3348 | } | |
38b92ef8 JS |
3349 | |
3350 | /* If the FCF discovery is in progress, do nothing. */ | |
3804dc84 | 3351 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 3352 | if (phba->hba_flag & FCF_TS_INPROG) { |
38b92ef8 JS |
3353 | spin_unlock_irq(&phba->hbalock); |
3354 | break; | |
3355 | } | |
3356 | /* If fast FCF failover rescan event is pending, do nothing */ | |
3357 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { | |
3358 | spin_unlock_irq(&phba->hbalock); | |
3359 | break; | |
3360 | } | |
3361 | ||
3362 | /* If the FCF has been in discovered state, do nothing. */ | |
3804dc84 JS |
3363 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
3364 | spin_unlock_irq(&phba->hbalock); | |
3365 | break; | |
3366 | } | |
3367 | spin_unlock_irq(&phba->hbalock); | |
38b92ef8 | 3368 | |
0c9ab6f5 JS |
3369 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
3370 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, | |
a93ff37a JS |
3371 | "2770 Start FCF table scan per async FCF " |
3372 | "event, evt_tag:x%x, index:x%x\n", | |
0c9ab6f5 JS |
3373 | acqe_fcoe->event_tag, acqe_fcoe->index); |
3374 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, | |
3375 | LPFC_FCOE_FCF_GET_FIRST); | |
da0436e9 | 3376 | if (rc) |
0c9ab6f5 JS |
3377 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
3378 | "2547 Issue FCF scan read FCF mailbox " | |
a93ff37a | 3379 | "command failed (x%x)\n", rc); |
da0436e9 JS |
3380 | break; |
3381 | ||
3382 | case LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL: | |
3383 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e4e74273 | 3384 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
da0436e9 JS |
3385 | bf_get(lpfc_acqe_fcoe_fcf_count, acqe_fcoe), |
3386 | acqe_fcoe->event_tag); | |
3387 | break; | |
3388 | ||
3389 | case LPFC_FCOE_EVENT_TYPE_FCF_DEAD: | |
0c9ab6f5 | 3390 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
a93ff37a JS |
3391 | "2549 FCF (x%x) disconnected from network, " |
3392 | "tag:x%x\n", acqe_fcoe->index, acqe_fcoe->event_tag); | |
38b92ef8 JS |
3393 | /* |
3394 | * If we are in the middle of FCF failover process, clear | |
3395 | * the corresponding FCF bit in the roundrobin bitmap. | |
da0436e9 | 3396 | */ |
fc2b989b | 3397 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3398 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
fc2b989b | 3399 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 JS |
3400 | /* Update FLOGI FCF failover eligible FCF bmask */ |
3401 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fcoe->index); | |
fc2b989b JS |
3402 | break; |
3403 | } | |
38b92ef8 JS |
3404 | spin_unlock_irq(&phba->hbalock); |
3405 | ||
3406 | /* If the event is not for currently used fcf do nothing */ | |
3407 | if (phba->fcf.current_rec.fcf_indx != acqe_fcoe->index) | |
3408 | break; | |
3409 | ||
3410 | /* | |
3411 | * Otherwise, request the port to rediscover the entire FCF | |
3412 | * table for a fast recovery from case that the current FCF | |
3413 | * is no longer valid as we are not in the middle of FCF | |
3414 | * failover process already. | |
3415 | */ | |
3416 | spin_lock_irq(&phba->hbalock); | |
fc2b989b | 3417 | /* Mark the fast failover process in progress */ |
0c9ab6f5 | 3418 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
fc2b989b | 3419 | spin_unlock_irq(&phba->hbalock); |
38b92ef8 | 3420 | |
0c9ab6f5 JS |
3421 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
3422 | "2771 Start FCF fast failover process due to " | |
3423 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " | |
3424 | "\n", acqe_fcoe->event_tag, acqe_fcoe->index); | |
fc2b989b JS |
3425 | rc = lpfc_sli4_redisc_fcf_table(phba); |
3426 | if (rc) { | |
0c9ab6f5 JS |
3427 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
3428 | LOG_DISCOVERY, | |
3429 | "2772 Issue FCF rediscover mabilbox " | |
3430 | "command failed, fail through to FCF " | |
3431 | "dead event\n"); | |
fc2b989b | 3432 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3433 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
3434 | spin_unlock_irq(&phba->hbalock); |
3435 | /* | |
3436 | * Last resort will fail over by treating this | |
3437 | * as a link down to FCF registration. | |
3438 | */ | |
3439 | lpfc_sli4_fcf_dead_failthrough(phba); | |
38b92ef8 JS |
3440 | } else { |
3441 | /* Reset FCF roundrobin bmask for new discovery */ | |
3442 | memset(phba->fcf.fcf_rr_bmask, 0, | |
3443 | sizeof(*phba->fcf.fcf_rr_bmask)); | |
3444 | /* | |
3445 | * Handling fast FCF failover to a DEAD FCF event is | |
3446 | * considered equalivant to receiving CVL to all vports. | |
fc2b989b JS |
3447 | */ |
3448 | lpfc_sli4_perform_all_vport_cvl(phba); | |
38b92ef8 | 3449 | } |
da0436e9 | 3450 | break; |
6669f9bb | 3451 | case LPFC_FCOE_EVENT_TYPE_CVL: |
0c9ab6f5 | 3452 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
6669f9bb JS |
3453 | "2718 Clear Virtual Link Received for VPI 0x%x" |
3454 | " tag 0x%x\n", acqe_fcoe->index, acqe_fcoe->event_tag); | |
3455 | vport = lpfc_find_vport_by_vpid(phba, | |
c868595d | 3456 | acqe_fcoe->index - phba->vpi_base); |
fc2b989b | 3457 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
6669f9bb JS |
3458 | if (!ndlp) |
3459 | break; | |
695a814e JS |
3460 | active_vlink_present = 0; |
3461 | ||
3462 | vports = lpfc_create_vport_work_array(phba); | |
3463 | if (vports) { | |
3464 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; | |
3465 | i++) { | |
3466 | if ((!(vports[i]->fc_flag & | |
3467 | FC_VPORT_CVL_RCVD)) && | |
3468 | (vports[i]->port_state > LPFC_FDISC)) { | |
3469 | active_vlink_present = 1; | |
3470 | break; | |
3471 | } | |
3472 | } | |
3473 | lpfc_destroy_vport_work_array(phba, vports); | |
3474 | } | |
3475 | ||
3476 | if (active_vlink_present) { | |
3477 | /* | |
3478 | * If there are other active VLinks present, | |
3479 | * re-instantiate the Vlink using FDISC. | |
3480 | */ | |
6669f9bb | 3481 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
fc2b989b | 3482 | shost = lpfc_shost_from_vport(vport); |
6669f9bb JS |
3483 | spin_lock_irq(shost->host_lock); |
3484 | ndlp->nlp_flag |= NLP_DELAY_TMO; | |
3485 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
3486 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
3487 | vport->port_state = LPFC_FDISC; | |
3488 | } else { | |
ecfd03c6 JS |
3489 | /* |
3490 | * Otherwise, we request port to rediscover | |
3491 | * the entire FCF table for a fast recovery | |
3492 | * from possible case that the current FCF | |
0c9ab6f5 JS |
3493 | * is no longer valid if we are not already |
3494 | * in the FCF failover process. | |
ecfd03c6 | 3495 | */ |
fc2b989b | 3496 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3497 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
fc2b989b JS |
3498 | spin_unlock_irq(&phba->hbalock); |
3499 | break; | |
3500 | } | |
3501 | /* Mark the fast failover process in progress */ | |
0c9ab6f5 | 3502 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
fc2b989b | 3503 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 JS |
3504 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
3505 | LOG_DISCOVERY, | |
a93ff37a JS |
3506 | "2773 Start FCF failover per CVL, " |
3507 | "evt_tag:x%x\n", acqe_fcoe->event_tag); | |
ecfd03c6 | 3508 | rc = lpfc_sli4_redisc_fcf_table(phba); |
fc2b989b | 3509 | if (rc) { |
0c9ab6f5 JS |
3510 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
3511 | LOG_DISCOVERY, | |
3512 | "2774 Issue FCF rediscover " | |
3513 | "mabilbox command failed, " | |
3514 | "through to CVL event\n"); | |
fc2b989b | 3515 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3516 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b | 3517 | spin_unlock_irq(&phba->hbalock); |
ecfd03c6 JS |
3518 | /* |
3519 | * Last resort will be re-try on the | |
3520 | * the current registered FCF entry. | |
3521 | */ | |
3522 | lpfc_retry_pport_discovery(phba); | |
38b92ef8 JS |
3523 | } else |
3524 | /* | |
3525 | * Reset FCF roundrobin bmask for new | |
3526 | * discovery. | |
3527 | */ | |
3528 | memset(phba->fcf.fcf_rr_bmask, 0, | |
3529 | sizeof(*phba->fcf.fcf_rr_bmask)); | |
6669f9bb JS |
3530 | } |
3531 | break; | |
da0436e9 JS |
3532 | default: |
3533 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3534 | "0288 Unknown FCoE event type 0x%x event tag " | |
3535 | "0x%x\n", event_type, acqe_fcoe->event_tag); | |
3536 | break; | |
3537 | } | |
3538 | } | |
3539 | ||
3540 | /** | |
3541 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event | |
3542 | * @phba: pointer to lpfc hba data structure. | |
3543 | * @acqe_link: pointer to the async dcbx completion queue entry. | |
3544 | * | |
3545 | * This routine is to handle the SLI4 asynchronous dcbx event. | |
3546 | **/ | |
3547 | static void | |
3548 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, | |
3549 | struct lpfc_acqe_dcbx *acqe_dcbx) | |
3550 | { | |
4d9ab994 | 3551 | phba->fc_eventTag = acqe_dcbx->event_tag; |
da0436e9 JS |
3552 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
3553 | "0290 The SLI4 DCBX asynchronous event is not " | |
3554 | "handled yet\n"); | |
3555 | } | |
3556 | ||
b19a061a JS |
3557 | /** |
3558 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event | |
3559 | * @phba: pointer to lpfc hba data structure. | |
3560 | * @acqe_link: pointer to the async grp5 completion queue entry. | |
3561 | * | |
3562 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event | |
3563 | * is an asynchronous notified of a logical link speed change. The Port | |
3564 | * reports the logical link speed in units of 10Mbps. | |
3565 | **/ | |
3566 | static void | |
3567 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, | |
3568 | struct lpfc_acqe_grp5 *acqe_grp5) | |
3569 | { | |
3570 | uint16_t prev_ll_spd; | |
3571 | ||
3572 | phba->fc_eventTag = acqe_grp5->event_tag; | |
3573 | phba->fcoe_eventtag = acqe_grp5->event_tag; | |
3574 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; | |
3575 | phba->sli4_hba.link_state.logical_speed = | |
3576 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)); | |
3577 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3578 | "2789 GRP5 Async Event: Updating logical link speed " | |
3579 | "from %dMbps to %dMbps\n", (prev_ll_spd * 10), | |
3580 | (phba->sli4_hba.link_state.logical_speed*10)); | |
3581 | } | |
3582 | ||
da0436e9 JS |
3583 | /** |
3584 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event | |
3585 | * @phba: pointer to lpfc hba data structure. | |
3586 | * | |
3587 | * This routine is invoked by the worker thread to process all the pending | |
3588 | * SLI4 asynchronous events. | |
3589 | **/ | |
3590 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) | |
3591 | { | |
3592 | struct lpfc_cq_event *cq_event; | |
3593 | ||
3594 | /* First, declare the async event has been handled */ | |
3595 | spin_lock_irq(&phba->hbalock); | |
3596 | phba->hba_flag &= ~ASYNC_EVENT; | |
3597 | spin_unlock_irq(&phba->hbalock); | |
3598 | /* Now, handle all the async events */ | |
3599 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { | |
3600 | /* Get the first event from the head of the event queue */ | |
3601 | spin_lock_irq(&phba->hbalock); | |
3602 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, | |
3603 | cq_event, struct lpfc_cq_event, list); | |
3604 | spin_unlock_irq(&phba->hbalock); | |
3605 | /* Process the asynchronous event */ | |
3606 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { | |
3607 | case LPFC_TRAILER_CODE_LINK: | |
3608 | lpfc_sli4_async_link_evt(phba, | |
3609 | &cq_event->cqe.acqe_link); | |
3610 | break; | |
3611 | case LPFC_TRAILER_CODE_FCOE: | |
3612 | lpfc_sli4_async_fcoe_evt(phba, | |
3613 | &cq_event->cqe.acqe_fcoe); | |
3614 | break; | |
3615 | case LPFC_TRAILER_CODE_DCBX: | |
3616 | lpfc_sli4_async_dcbx_evt(phba, | |
3617 | &cq_event->cqe.acqe_dcbx); | |
3618 | break; | |
b19a061a JS |
3619 | case LPFC_TRAILER_CODE_GRP5: |
3620 | lpfc_sli4_async_grp5_evt(phba, | |
3621 | &cq_event->cqe.acqe_grp5); | |
3622 | break; | |
da0436e9 JS |
3623 | default: |
3624 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3625 | "1804 Invalid asynchrous event code: " | |
3626 | "x%x\n", bf_get(lpfc_trailer_code, | |
3627 | &cq_event->cqe.mcqe_cmpl)); | |
3628 | break; | |
3629 | } | |
3630 | /* Free the completion event processed to the free pool */ | |
3631 | lpfc_sli4_cq_event_release(phba, cq_event); | |
3632 | } | |
3633 | } | |
3634 | ||
ecfd03c6 JS |
3635 | /** |
3636 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event | |
3637 | * @phba: pointer to lpfc hba data structure. | |
3638 | * | |
3639 | * This routine is invoked by the worker thread to process FCF table | |
3640 | * rediscovery pending completion event. | |
3641 | **/ | |
3642 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) | |
3643 | { | |
3644 | int rc; | |
3645 | ||
3646 | spin_lock_irq(&phba->hbalock); | |
3647 | /* Clear FCF rediscovery timeout event */ | |
3648 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; | |
3649 | /* Clear driver fast failover FCF record flag */ | |
3650 | phba->fcf.failover_rec.flag = 0; | |
3651 | /* Set state for FCF fast failover */ | |
3652 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; | |
3653 | spin_unlock_irq(&phba->hbalock); | |
3654 | ||
3655 | /* Scan FCF table from the first entry to re-discover SAN */ | |
0c9ab6f5 | 3656 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
a93ff37a | 3657 | "2777 Start post-quiescent FCF table scan\n"); |
0c9ab6f5 | 3658 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
ecfd03c6 | 3659 | if (rc) |
0c9ab6f5 JS |
3660 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
3661 | "2747 Issue FCF scan read FCF mailbox " | |
3662 | "command failed 0x%x\n", rc); | |
ecfd03c6 JS |
3663 | } |
3664 | ||
da0436e9 JS |
3665 | /** |
3666 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table | |
3667 | * @phba: pointer to lpfc hba data structure. | |
3668 | * @dev_grp: The HBA PCI-Device group number. | |
3669 | * | |
3670 | * This routine is invoked to set up the per HBA PCI-Device group function | |
3671 | * API jump table entries. | |
3672 | * | |
3673 | * Return: 0 if success, otherwise -ENODEV | |
3674 | **/ | |
3675 | int | |
3676 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
3677 | { | |
3678 | int rc; | |
3679 | ||
3680 | /* Set up lpfc PCI-device group */ | |
3681 | phba->pci_dev_grp = dev_grp; | |
3682 | ||
3683 | /* The LPFC_PCI_DEV_OC uses SLI4 */ | |
3684 | if (dev_grp == LPFC_PCI_DEV_OC) | |
3685 | phba->sli_rev = LPFC_SLI_REV4; | |
3686 | ||
3687 | /* Set up device INIT API function jump table */ | |
3688 | rc = lpfc_init_api_table_setup(phba, dev_grp); | |
3689 | if (rc) | |
3690 | return -ENODEV; | |
3691 | /* Set up SCSI API function jump table */ | |
3692 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); | |
3693 | if (rc) | |
3694 | return -ENODEV; | |
3695 | /* Set up SLI API function jump table */ | |
3696 | rc = lpfc_sli_api_table_setup(phba, dev_grp); | |
3697 | if (rc) | |
3698 | return -ENODEV; | |
3699 | /* Set up MBOX API function jump table */ | |
3700 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); | |
3701 | if (rc) | |
3702 | return -ENODEV; | |
3703 | ||
3704 | return 0; | |
5b75da2f JS |
3705 | } |
3706 | ||
3707 | /** | |
3621a710 | 3708 | * lpfc_log_intr_mode - Log the active interrupt mode |
5b75da2f JS |
3709 | * @phba: pointer to lpfc hba data structure. |
3710 | * @intr_mode: active interrupt mode adopted. | |
3711 | * | |
3712 | * This routine it invoked to log the currently used active interrupt mode | |
3713 | * to the device. | |
3772a991 JS |
3714 | **/ |
3715 | static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode) | |
5b75da2f JS |
3716 | { |
3717 | switch (intr_mode) { | |
3718 | case 0: | |
3719 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3720 | "0470 Enable INTx interrupt mode.\n"); | |
3721 | break; | |
3722 | case 1: | |
3723 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3724 | "0481 Enabled MSI interrupt mode.\n"); | |
3725 | break; | |
3726 | case 2: | |
3727 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3728 | "0480 Enabled MSI-X interrupt mode.\n"); | |
3729 | break; | |
3730 | default: | |
3731 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3732 | "0482 Illegal interrupt mode.\n"); | |
3733 | break; | |
3734 | } | |
3735 | return; | |
3736 | } | |
3737 | ||
5b75da2f | 3738 | /** |
3772a991 | 3739 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
5b75da2f JS |
3740 | * @phba: pointer to lpfc hba data structure. |
3741 | * | |
3772a991 JS |
3742 | * This routine is invoked to enable the PCI device that is common to all |
3743 | * PCI devices. | |
5b75da2f JS |
3744 | * |
3745 | * Return codes | |
af901ca1 | 3746 | * 0 - successful |
3772a991 | 3747 | * other values - error |
5b75da2f | 3748 | **/ |
3772a991 JS |
3749 | static int |
3750 | lpfc_enable_pci_dev(struct lpfc_hba *phba) | |
5b75da2f | 3751 | { |
3772a991 JS |
3752 | struct pci_dev *pdev; |
3753 | int bars; | |
5b75da2f | 3754 | |
3772a991 JS |
3755 | /* Obtain PCI device reference */ |
3756 | if (!phba->pcidev) | |
3757 | goto out_error; | |
3758 | else | |
3759 | pdev = phba->pcidev; | |
3760 | /* Select PCI BARs */ | |
3761 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
3762 | /* Enable PCI device */ | |
3763 | if (pci_enable_device_mem(pdev)) | |
3764 | goto out_error; | |
3765 | /* Request PCI resource for the device */ | |
3766 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) | |
3767 | goto out_disable_device; | |
3768 | /* Set up device as PCI master and save state for EEH */ | |
3769 | pci_set_master(pdev); | |
3770 | pci_try_set_mwi(pdev); | |
3771 | pci_save_state(pdev); | |
5b75da2f | 3772 | |
3772a991 | 3773 | return 0; |
5b75da2f | 3774 | |
3772a991 JS |
3775 | out_disable_device: |
3776 | pci_disable_device(pdev); | |
3777 | out_error: | |
3778 | return -ENODEV; | |
5b75da2f JS |
3779 | } |
3780 | ||
3781 | /** | |
3772a991 | 3782 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
5b75da2f JS |
3783 | * @phba: pointer to lpfc hba data structure. |
3784 | * | |
3772a991 JS |
3785 | * This routine is invoked to disable the PCI device that is common to all |
3786 | * PCI devices. | |
5b75da2f JS |
3787 | **/ |
3788 | static void | |
3772a991 | 3789 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
5b75da2f | 3790 | { |
3772a991 JS |
3791 | struct pci_dev *pdev; |
3792 | int bars; | |
5b75da2f | 3793 | |
3772a991 JS |
3794 | /* Obtain PCI device reference */ |
3795 | if (!phba->pcidev) | |
3796 | return; | |
3797 | else | |
3798 | pdev = phba->pcidev; | |
3799 | /* Select PCI BARs */ | |
3800 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
3801 | /* Release PCI resource and disable PCI device */ | |
3802 | pci_release_selected_regions(pdev, bars); | |
3803 | pci_disable_device(pdev); | |
3804 | /* Null out PCI private reference to driver */ | |
3805 | pci_set_drvdata(pdev, NULL); | |
5b75da2f JS |
3806 | |
3807 | return; | |
3808 | } | |
3809 | ||
e59058c4 | 3810 | /** |
3772a991 JS |
3811 | * lpfc_reset_hba - Reset a hba |
3812 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 3813 | * |
3772a991 JS |
3814 | * This routine is invoked to reset a hba device. It brings the HBA |
3815 | * offline, performs a board restart, and then brings the board back | |
3816 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up | |
3817 | * on outstanding mailbox commands. | |
e59058c4 | 3818 | **/ |
3772a991 JS |
3819 | void |
3820 | lpfc_reset_hba(struct lpfc_hba *phba) | |
dea3101e | 3821 | { |
3772a991 JS |
3822 | /* If resets are disabled then set error state and return. */ |
3823 | if (!phba->cfg_enable_hba_reset) { | |
3824 | phba->link_state = LPFC_HBA_ERROR; | |
3825 | return; | |
3826 | } | |
3827 | lpfc_offline_prep(phba); | |
3828 | lpfc_offline(phba); | |
3829 | lpfc_sli_brdrestart(phba); | |
3830 | lpfc_online(phba); | |
3831 | lpfc_unblock_mgmt_io(phba); | |
3832 | } | |
dea3101e | 3833 | |
3772a991 JS |
3834 | /** |
3835 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. | |
3836 | * @phba: pointer to lpfc hba data structure. | |
3837 | * | |
3838 | * This routine is invoked to set up the driver internal resources specific to | |
3839 | * support the SLI-3 HBA device it attached to. | |
3840 | * | |
3841 | * Return codes | |
af901ca1 | 3842 | * 0 - successful |
3772a991 JS |
3843 | * other values - error |
3844 | **/ | |
3845 | static int | |
3846 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) | |
3847 | { | |
3848 | struct lpfc_sli *psli; | |
dea3101e | 3849 | |
2e0fef85 | 3850 | /* |
3772a991 | 3851 | * Initialize timers used by driver |
2e0fef85 | 3852 | */ |
dea3101e | 3853 | |
3772a991 | 3854 | /* Heartbeat timer */ |
858c9f6c JS |
3855 | init_timer(&phba->hb_tmofunc); |
3856 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
3857 | phba->hb_tmofunc.data = (unsigned long)phba; | |
3858 | ||
dea3101e | 3859 | psli = &phba->sli; |
3772a991 | 3860 | /* MBOX heartbeat timer */ |
dea3101e | 3861 | init_timer(&psli->mbox_tmo); |
3862 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
2e0fef85 | 3863 | psli->mbox_tmo.data = (unsigned long) phba; |
3772a991 | 3864 | /* FCP polling mode timer */ |
875fbdfe JSEC |
3865 | init_timer(&phba->fcp_poll_timer); |
3866 | phba->fcp_poll_timer.function = lpfc_poll_timeout; | |
2e0fef85 | 3867 | phba->fcp_poll_timer.data = (unsigned long) phba; |
3772a991 | 3868 | /* Fabric block timer */ |
92d7f7b0 JS |
3869 | init_timer(&phba->fabric_block_timer); |
3870 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
3871 | phba->fabric_block_timer.data = (unsigned long) phba; | |
3772a991 | 3872 | /* EA polling mode timer */ |
9399627f JS |
3873 | init_timer(&phba->eratt_poll); |
3874 | phba->eratt_poll.function = lpfc_poll_eratt; | |
3875 | phba->eratt_poll.data = (unsigned long) phba; | |
dea3101e | 3876 | |
3772a991 JS |
3877 | /* Host attention work mask setup */ |
3878 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); | |
3879 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); | |
dea3101e | 3880 | |
3772a991 JS |
3881 | /* Get all the module params for configuring this host */ |
3882 | lpfc_get_cfgparam(phba); | |
49198b37 JS |
3883 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
3884 | phba->menlo_flag |= HBA_MENLO_SUPPORT; | |
3885 | /* check for menlo minimum sg count */ | |
3886 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) | |
3887 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; | |
3888 | } | |
3889 | ||
dea3101e | 3890 | /* |
3772a991 JS |
3891 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size |
3892 | * used to create the sg_dma_buf_pool must be dynamically calculated. | |
3893 | * 2 segments are added since the IOCB needs a command and response bde. | |
dea3101e | 3894 | */ |
3772a991 JS |
3895 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
3896 | sizeof(struct fcp_rsp) + | |
3897 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); | |
3898 | ||
3899 | if (phba->cfg_enable_bg) { | |
3900 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT; | |
3901 | phba->cfg_sg_dma_buf_size += | |
3902 | phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64); | |
901a920f | 3903 | } |
dea3101e | 3904 | |
3772a991 JS |
3905 | /* Also reinitialize the host templates with new values. */ |
3906 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
3907 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
dea3101e | 3908 | |
3772a991 JS |
3909 | phba->max_vpi = LPFC_MAX_VPI; |
3910 | /* This will be set to correct value after config_port mbox */ | |
3911 | phba->max_vports = 0; | |
dea3101e | 3912 | |
3772a991 JS |
3913 | /* |
3914 | * Initialize the SLI Layer to run with lpfc HBAs. | |
3915 | */ | |
3916 | lpfc_sli_setup(phba); | |
3917 | lpfc_sli_queue_setup(phba); | |
ed957684 | 3918 | |
3772a991 JS |
3919 | /* Allocate device driver memory */ |
3920 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) | |
3921 | return -ENOMEM; | |
51ef4c26 | 3922 | |
3772a991 JS |
3923 | return 0; |
3924 | } | |
ed957684 | 3925 | |
3772a991 JS |
3926 | /** |
3927 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev | |
3928 | * @phba: pointer to lpfc hba data structure. | |
3929 | * | |
3930 | * This routine is invoked to unset the driver internal resources set up | |
3931 | * specific for supporting the SLI-3 HBA device it attached to. | |
3932 | **/ | |
3933 | static void | |
3934 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) | |
3935 | { | |
3936 | /* Free device driver memory allocated */ | |
3937 | lpfc_mem_free_all(phba); | |
3163f725 | 3938 | |
3772a991 JS |
3939 | return; |
3940 | } | |
dea3101e | 3941 | |
3772a991 | 3942 | /** |
da0436e9 | 3943 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
3772a991 JS |
3944 | * @phba: pointer to lpfc hba data structure. |
3945 | * | |
da0436e9 JS |
3946 | * This routine is invoked to set up the driver internal resources specific to |
3947 | * support the SLI-4 HBA device it attached to. | |
3772a991 JS |
3948 | * |
3949 | * Return codes | |
af901ca1 | 3950 | * 0 - successful |
da0436e9 | 3951 | * other values - error |
3772a991 JS |
3952 | **/ |
3953 | static int | |
da0436e9 | 3954 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
3772a991 | 3955 | { |
da0436e9 | 3956 | struct lpfc_sli *psli; |
28baac74 JS |
3957 | LPFC_MBOXQ_t *mboxq; |
3958 | int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size; | |
3959 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; | |
3960 | struct lpfc_mqe *mqe; | |
085c647c | 3961 | int longs, sli_family; |
da0436e9 JS |
3962 | |
3963 | /* Before proceed, wait for POST done and device ready */ | |
3964 | rc = lpfc_sli4_post_status_check(phba); | |
3965 | if (rc) | |
3966 | return -ENODEV; | |
3967 | ||
3772a991 | 3968 | /* |
da0436e9 | 3969 | * Initialize timers used by driver |
3772a991 | 3970 | */ |
3772a991 | 3971 | |
da0436e9 JS |
3972 | /* Heartbeat timer */ |
3973 | init_timer(&phba->hb_tmofunc); | |
3974 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
3975 | phba->hb_tmofunc.data = (unsigned long)phba; | |
3772a991 | 3976 | |
da0436e9 JS |
3977 | psli = &phba->sli; |
3978 | /* MBOX heartbeat timer */ | |
3979 | init_timer(&psli->mbox_tmo); | |
3980 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
3981 | psli->mbox_tmo.data = (unsigned long) phba; | |
3982 | /* Fabric block timer */ | |
3983 | init_timer(&phba->fabric_block_timer); | |
3984 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
3985 | phba->fabric_block_timer.data = (unsigned long) phba; | |
3986 | /* EA polling mode timer */ | |
3987 | init_timer(&phba->eratt_poll); | |
3988 | phba->eratt_poll.function = lpfc_poll_eratt; | |
3989 | phba->eratt_poll.data = (unsigned long) phba; | |
ecfd03c6 JS |
3990 | /* FCF rediscover timer */ |
3991 | init_timer(&phba->fcf.redisc_wait); | |
3992 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; | |
3993 | phba->fcf.redisc_wait.data = (unsigned long)phba; | |
3994 | ||
da0436e9 JS |
3995 | /* |
3996 | * We need to do a READ_CONFIG mailbox command here before | |
3997 | * calling lpfc_get_cfgparam. For VFs this will report the | |
3998 | * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings. | |
3999 | * All of the resources allocated | |
4000 | * for this Port are tied to these values. | |
4001 | */ | |
4002 | /* Get all the module params for configuring this host */ | |
4003 | lpfc_get_cfgparam(phba); | |
4004 | phba->max_vpi = LPFC_MAX_VPI; | |
4005 | /* This will be set to correct value after the read_config mbox */ | |
4006 | phba->max_vports = 0; | |
3772a991 | 4007 | |
da0436e9 JS |
4008 | /* Program the default value of vlan_id and fc_map */ |
4009 | phba->valid_vlan = 0; | |
4010 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4011 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4012 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
3772a991 | 4013 | |
da0436e9 JS |
4014 | /* |
4015 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size | |
4016 | * used to create the sg_dma_buf_pool must be dynamically calculated. | |
4017 | * 2 segments are added since the IOCB needs a command and response bde. | |
4018 | * To insure that the scsi sgl does not cross a 4k page boundary only | |
28baac74 | 4019 | * sgl sizes of must be a power of 2. |
da0436e9 | 4020 | */ |
28baac74 JS |
4021 | buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) + |
4022 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge))); | |
085c647c JS |
4023 | |
4024 | sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf); | |
4025 | max_buf_size = LPFC_SLI4_MAX_BUF_SIZE; | |
4026 | switch (sli_family) { | |
4027 | case LPFC_SLI_INTF_FAMILY_BE2: | |
4028 | case LPFC_SLI_INTF_FAMILY_BE3: | |
4029 | /* There is a single hint for BE - 2 pages per BPL. */ | |
4030 | if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) == | |
4031 | LPFC_SLI_INTF_SLI_HINT1_1) | |
4032 | max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE; | |
4033 | break; | |
4034 | case LPFC_SLI_INTF_FAMILY_LNCR_A0: | |
4035 | case LPFC_SLI_INTF_FAMILY_LNCR_B0: | |
4036 | default: | |
4037 | break; | |
4038 | } | |
28baac74 JS |
4039 | for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE; |
4040 | dma_buf_size < max_buf_size && buf_size > dma_buf_size; | |
4041 | dma_buf_size = dma_buf_size << 1) | |
4042 | ; | |
4043 | if (dma_buf_size == max_buf_size) | |
4044 | phba->cfg_sg_seg_cnt = (dma_buf_size - | |
4045 | sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) - | |
4046 | (2 * sizeof(struct sli4_sge))) / | |
4047 | sizeof(struct sli4_sge); | |
4048 | phba->cfg_sg_dma_buf_size = dma_buf_size; | |
3772a991 | 4049 | |
da0436e9 JS |
4050 | /* Initialize buffer queue management fields */ |
4051 | hbq_count = lpfc_sli_hbq_count(); | |
4052 | for (i = 0; i < hbq_count; ++i) | |
4053 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
4054 | INIT_LIST_HEAD(&phba->rb_pend_list); | |
4055 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; | |
4056 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; | |
3772a991 | 4057 | |
da0436e9 JS |
4058 | /* |
4059 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. | |
4060 | */ | |
4061 | /* Initialize the Abort scsi buffer list used by driver */ | |
4062 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
4063 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
4064 | /* This abort list used by worker thread */ | |
4065 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); | |
3772a991 | 4066 | |
da0436e9 JS |
4067 | /* |
4068 | * Initialize dirver internal slow-path work queues | |
4069 | */ | |
3772a991 | 4070 | |
da0436e9 JS |
4071 | /* Driver internel slow-path CQ Event pool */ |
4072 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); | |
4073 | /* Response IOCB work queue list */ | |
45ed1190 | 4074 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
da0436e9 JS |
4075 | /* Asynchronous event CQ Event work queue list */ |
4076 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); | |
4077 | /* Fast-path XRI aborted CQ Event work queue list */ | |
4078 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
4079 | /* Slow-path XRI aborted CQ Event work queue list */ | |
4080 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
4081 | /* Receive queue CQ Event work queue list */ | |
4082 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); | |
4083 | ||
4084 | /* Initialize the driver internal SLI layer lists. */ | |
4085 | lpfc_sli_setup(phba); | |
4086 | lpfc_sli_queue_setup(phba); | |
3772a991 | 4087 | |
da0436e9 JS |
4088 | /* Allocate device driver memory */ |
4089 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); | |
4090 | if (rc) | |
4091 | return -ENOMEM; | |
4092 | ||
4093 | /* Create the bootstrap mailbox command */ | |
4094 | rc = lpfc_create_bootstrap_mbox(phba); | |
4095 | if (unlikely(rc)) | |
4096 | goto out_free_mem; | |
4097 | ||
4098 | /* Set up the host's endian order with the device. */ | |
4099 | rc = lpfc_setup_endian_order(phba); | |
4100 | if (unlikely(rc)) | |
4101 | goto out_free_bsmbx; | |
4102 | ||
6669f9bb JS |
4103 | rc = lpfc_sli4_fw_cfg_check(phba); |
4104 | if (unlikely(rc)) | |
4105 | goto out_free_bsmbx; | |
4106 | ||
da0436e9 JS |
4107 | /* Set up the hba's configuration parameters. */ |
4108 | rc = lpfc_sli4_read_config(phba); | |
4109 | if (unlikely(rc)) | |
4110 | goto out_free_bsmbx; | |
4111 | ||
4112 | /* Perform a function reset */ | |
4113 | rc = lpfc_pci_function_reset(phba); | |
4114 | if (unlikely(rc)) | |
4115 | goto out_free_bsmbx; | |
4116 | ||
cb5172ea JS |
4117 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
4118 | GFP_KERNEL); | |
4119 | if (!mboxq) { | |
4120 | rc = -ENOMEM; | |
4121 | goto out_free_bsmbx; | |
4122 | } | |
4123 | ||
4124 | /* Get the Supported Pages. It is always available. */ | |
4125 | lpfc_supported_pages(mboxq); | |
4126 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4127 | if (unlikely(rc)) { | |
4128 | rc = -EIO; | |
4129 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4130 | goto out_free_bsmbx; | |
4131 | } | |
4132 | ||
4133 | mqe = &mboxq->u.mqe; | |
4134 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), | |
4135 | LPFC_MAX_SUPPORTED_PAGES); | |
4136 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { | |
4137 | switch (pn_page[i]) { | |
4138 | case LPFC_SLI4_PARAMETERS: | |
4139 | phba->sli4_hba.pc_sli4_params.supported = 1; | |
4140 | break; | |
4141 | default: | |
4142 | break; | |
4143 | } | |
4144 | } | |
4145 | ||
4146 | /* Read the port's SLI4 Parameters capabilities if supported. */ | |
4147 | if (phba->sli4_hba.pc_sli4_params.supported) | |
4148 | rc = lpfc_pc_sli4_params_get(phba, mboxq); | |
4149 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4150 | if (rc) { | |
4151 | rc = -EIO; | |
4152 | goto out_free_bsmbx; | |
4153 | } | |
da0436e9 JS |
4154 | /* Create all the SLI4 queues */ |
4155 | rc = lpfc_sli4_queue_create(phba); | |
4156 | if (rc) | |
4157 | goto out_free_bsmbx; | |
4158 | ||
4159 | /* Create driver internal CQE event pool */ | |
4160 | rc = lpfc_sli4_cq_event_pool_create(phba); | |
4161 | if (rc) | |
4162 | goto out_destroy_queue; | |
4163 | ||
4164 | /* Initialize and populate the iocb list per host */ | |
4165 | rc = lpfc_init_sgl_list(phba); | |
4166 | if (rc) { | |
4167 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4168 | "1400 Failed to initialize sgl list.\n"); | |
4169 | goto out_destroy_cq_event_pool; | |
4170 | } | |
4171 | rc = lpfc_init_active_sgl_array(phba); | |
4172 | if (rc) { | |
4173 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4174 | "1430 Failed to initialize sgl list.\n"); | |
4175 | goto out_free_sgl_list; | |
4176 | } | |
4177 | ||
4178 | rc = lpfc_sli4_init_rpi_hdrs(phba); | |
4179 | if (rc) { | |
4180 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4181 | "1432 Failed to initialize rpi headers.\n"); | |
4182 | goto out_free_active_sgl; | |
4183 | } | |
4184 | ||
a93ff37a | 4185 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
0c9ab6f5 JS |
4186 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
4187 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), | |
4188 | GFP_KERNEL); | |
4189 | if (!phba->fcf.fcf_rr_bmask) { | |
4190 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4191 | "2759 Failed allocate memory for FCF round " | |
4192 | "robin failover bmask\n"); | |
4193 | goto out_remove_rpi_hdrs; | |
4194 | } | |
4195 | ||
da0436e9 JS |
4196 | phba->sli4_hba.fcp_eq_hdl = kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * |
4197 | phba->cfg_fcp_eq_count), GFP_KERNEL); | |
4198 | if (!phba->sli4_hba.fcp_eq_hdl) { | |
4199 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4200 | "2572 Failed allocate memory for fast-path " | |
4201 | "per-EQ handle array\n"); | |
0c9ab6f5 | 4202 | goto out_free_fcf_rr_bmask; |
da0436e9 JS |
4203 | } |
4204 | ||
4205 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * | |
4206 | phba->sli4_hba.cfg_eqn), GFP_KERNEL); | |
4207 | if (!phba->sli4_hba.msix_entries) { | |
4208 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4209 | "2573 Failed allocate memory for msi-x " | |
4210 | "interrupt vector entries\n"); | |
4211 | goto out_free_fcp_eq_hdl; | |
4212 | } | |
4213 | ||
4214 | return rc; | |
4215 | ||
4216 | out_free_fcp_eq_hdl: | |
4217 | kfree(phba->sli4_hba.fcp_eq_hdl); | |
0c9ab6f5 JS |
4218 | out_free_fcf_rr_bmask: |
4219 | kfree(phba->fcf.fcf_rr_bmask); | |
da0436e9 JS |
4220 | out_remove_rpi_hdrs: |
4221 | lpfc_sli4_remove_rpi_hdrs(phba); | |
4222 | out_free_active_sgl: | |
4223 | lpfc_free_active_sgl(phba); | |
4224 | out_free_sgl_list: | |
4225 | lpfc_free_sgl_list(phba); | |
4226 | out_destroy_cq_event_pool: | |
4227 | lpfc_sli4_cq_event_pool_destroy(phba); | |
4228 | out_destroy_queue: | |
4229 | lpfc_sli4_queue_destroy(phba); | |
4230 | out_free_bsmbx: | |
4231 | lpfc_destroy_bootstrap_mbox(phba); | |
4232 | out_free_mem: | |
4233 | lpfc_mem_free(phba); | |
4234 | return rc; | |
4235 | } | |
4236 | ||
4237 | /** | |
4238 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev | |
4239 | * @phba: pointer to lpfc hba data structure. | |
4240 | * | |
4241 | * This routine is invoked to unset the driver internal resources set up | |
4242 | * specific for supporting the SLI-4 HBA device it attached to. | |
4243 | **/ | |
4244 | static void | |
4245 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) | |
4246 | { | |
4247 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; | |
4248 | ||
da0436e9 JS |
4249 | /* Free memory allocated for msi-x interrupt vector entries */ |
4250 | kfree(phba->sli4_hba.msix_entries); | |
4251 | ||
4252 | /* Free memory allocated for fast-path work queue handles */ | |
4253 | kfree(phba->sli4_hba.fcp_eq_hdl); | |
4254 | ||
4255 | /* Free the allocated rpi headers. */ | |
4256 | lpfc_sli4_remove_rpi_hdrs(phba); | |
d11e31dd | 4257 | lpfc_sli4_remove_rpis(phba); |
da0436e9 | 4258 | |
0c9ab6f5 JS |
4259 | /* Free eligible FCF index bmask */ |
4260 | kfree(phba->fcf.fcf_rr_bmask); | |
4261 | ||
da0436e9 JS |
4262 | /* Free the ELS sgl list */ |
4263 | lpfc_free_active_sgl(phba); | |
4264 | lpfc_free_sgl_list(phba); | |
4265 | ||
4266 | /* Free the SCSI sgl management array */ | |
4267 | kfree(phba->sli4_hba.lpfc_scsi_psb_array); | |
4268 | ||
4269 | /* Free the SLI4 queues */ | |
4270 | lpfc_sli4_queue_destroy(phba); | |
4271 | ||
4272 | /* Free the completion queue EQ event pool */ | |
4273 | lpfc_sli4_cq_event_release_all(phba); | |
4274 | lpfc_sli4_cq_event_pool_destroy(phba); | |
4275 | ||
da0436e9 JS |
4276 | /* Free the bsmbx region. */ |
4277 | lpfc_destroy_bootstrap_mbox(phba); | |
4278 | ||
4279 | /* Free the SLI Layer memory with SLI4 HBAs */ | |
4280 | lpfc_mem_free_all(phba); | |
4281 | ||
4282 | /* Free the current connect table */ | |
4283 | list_for_each_entry_safe(conn_entry, next_conn_entry, | |
4d9ab994 JS |
4284 | &phba->fcf_conn_rec_list, list) { |
4285 | list_del_init(&conn_entry->list); | |
da0436e9 | 4286 | kfree(conn_entry); |
4d9ab994 | 4287 | } |
da0436e9 JS |
4288 | |
4289 | return; | |
4290 | } | |
4291 | ||
4292 | /** | |
4293 | * lpfc_init_api_table_setup - Set up init api fucntion jump table | |
4294 | * @phba: The hba struct for which this call is being executed. | |
4295 | * @dev_grp: The HBA PCI-Device group number. | |
4296 | * | |
4297 | * This routine sets up the device INIT interface API function jump table | |
4298 | * in @phba struct. | |
4299 | * | |
4300 | * Returns: 0 - success, -ENODEV - failure. | |
4301 | **/ | |
4302 | int | |
4303 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
4304 | { | |
84d1b006 JS |
4305 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
4306 | phba->lpfc_hba_down_link = lpfc_hba_down_link; | |
da0436e9 JS |
4307 | switch (dev_grp) { |
4308 | case LPFC_PCI_DEV_LP: | |
4309 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; | |
4310 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; | |
4311 | phba->lpfc_stop_port = lpfc_stop_port_s3; | |
4312 | break; | |
4313 | case LPFC_PCI_DEV_OC: | |
4314 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; | |
4315 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; | |
4316 | phba->lpfc_stop_port = lpfc_stop_port_s4; | |
4317 | break; | |
4318 | default: | |
4319 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4320 | "1431 Invalid HBA PCI-device group: 0x%x\n", | |
4321 | dev_grp); | |
4322 | return -ENODEV; | |
4323 | break; | |
4324 | } | |
4325 | return 0; | |
4326 | } | |
4327 | ||
4328 | /** | |
4329 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. | |
4330 | * @phba: pointer to lpfc hba data structure. | |
4331 | * | |
4332 | * This routine is invoked to set up the driver internal resources before the | |
4333 | * device specific resource setup to support the HBA device it attached to. | |
4334 | * | |
4335 | * Return codes | |
af901ca1 | 4336 | * 0 - successful |
da0436e9 JS |
4337 | * other values - error |
4338 | **/ | |
4339 | static int | |
4340 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) | |
4341 | { | |
4342 | /* | |
4343 | * Driver resources common to all SLI revisions | |
4344 | */ | |
4345 | atomic_set(&phba->fast_event_count, 0); | |
4346 | spin_lock_init(&phba->hbalock); | |
4347 | ||
4348 | /* Initialize ndlp management spinlock */ | |
4349 | spin_lock_init(&phba->ndlp_lock); | |
4350 | ||
4351 | INIT_LIST_HEAD(&phba->port_list); | |
4352 | INIT_LIST_HEAD(&phba->work_list); | |
4353 | init_waitqueue_head(&phba->wait_4_mlo_m_q); | |
4354 | ||
4355 | /* Initialize the wait queue head for the kernel thread */ | |
4356 | init_waitqueue_head(&phba->work_waitq); | |
4357 | ||
4358 | /* Initialize the scsi buffer list used by driver for scsi IO */ | |
4359 | spin_lock_init(&phba->scsi_buf_list_lock); | |
4360 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); | |
4361 | ||
4362 | /* Initialize the fabric iocb list */ | |
4363 | INIT_LIST_HEAD(&phba->fabric_iocb_list); | |
4364 | ||
4365 | /* Initialize list to save ELS buffers */ | |
4366 | INIT_LIST_HEAD(&phba->elsbuf); | |
4367 | ||
4368 | /* Initialize FCF connection rec list */ | |
4369 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); | |
4370 | ||
4371 | return 0; | |
4372 | } | |
4373 | ||
4374 | /** | |
4375 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. | |
4376 | * @phba: pointer to lpfc hba data structure. | |
4377 | * | |
4378 | * This routine is invoked to set up the driver internal resources after the | |
4379 | * device specific resource setup to support the HBA device it attached to. | |
4380 | * | |
4381 | * Return codes | |
af901ca1 | 4382 | * 0 - successful |
da0436e9 JS |
4383 | * other values - error |
4384 | **/ | |
4385 | static int | |
4386 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) | |
4387 | { | |
4388 | int error; | |
4389 | ||
4390 | /* Startup the kernel thread for this host adapter. */ | |
4391 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
4392 | "lpfc_worker_%d", phba->brd_no); | |
4393 | if (IS_ERR(phba->worker_thread)) { | |
4394 | error = PTR_ERR(phba->worker_thread); | |
4395 | return error; | |
3772a991 JS |
4396 | } |
4397 | ||
4398 | return 0; | |
4399 | } | |
4400 | ||
4401 | /** | |
4402 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. | |
4403 | * @phba: pointer to lpfc hba data structure. | |
4404 | * | |
4405 | * This routine is invoked to unset the driver internal resources set up after | |
4406 | * the device specific resource setup for supporting the HBA device it | |
4407 | * attached to. | |
4408 | **/ | |
4409 | static void | |
4410 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) | |
4411 | { | |
4412 | /* Stop kernel worker thread */ | |
4413 | kthread_stop(phba->worker_thread); | |
4414 | } | |
4415 | ||
4416 | /** | |
4417 | * lpfc_free_iocb_list - Free iocb list. | |
4418 | * @phba: pointer to lpfc hba data structure. | |
4419 | * | |
4420 | * This routine is invoked to free the driver's IOCB list and memory. | |
4421 | **/ | |
4422 | static void | |
4423 | lpfc_free_iocb_list(struct lpfc_hba *phba) | |
4424 | { | |
4425 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; | |
4426 | ||
4427 | spin_lock_irq(&phba->hbalock); | |
4428 | list_for_each_entry_safe(iocbq_entry, iocbq_next, | |
4429 | &phba->lpfc_iocb_list, list) { | |
4430 | list_del(&iocbq_entry->list); | |
4431 | kfree(iocbq_entry); | |
4432 | phba->total_iocbq_bufs--; | |
98c9ea5c | 4433 | } |
3772a991 JS |
4434 | spin_unlock_irq(&phba->hbalock); |
4435 | ||
4436 | return; | |
4437 | } | |
4438 | ||
4439 | /** | |
4440 | * lpfc_init_iocb_list - Allocate and initialize iocb list. | |
4441 | * @phba: pointer to lpfc hba data structure. | |
4442 | * | |
4443 | * This routine is invoked to allocate and initizlize the driver's IOCB | |
4444 | * list and set up the IOCB tag array accordingly. | |
4445 | * | |
4446 | * Return codes | |
af901ca1 | 4447 | * 0 - successful |
3772a991 JS |
4448 | * other values - error |
4449 | **/ | |
4450 | static int | |
4451 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) | |
4452 | { | |
4453 | struct lpfc_iocbq *iocbq_entry = NULL; | |
4454 | uint16_t iotag; | |
4455 | int i; | |
dea3101e | 4456 | |
4457 | /* Initialize and populate the iocb list per host. */ | |
4458 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); | |
3772a991 | 4459 | for (i = 0; i < iocb_count; i++) { |
dd00cc48 | 4460 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
dea3101e | 4461 | if (iocbq_entry == NULL) { |
4462 | printk(KERN_ERR "%s: only allocated %d iocbs of " | |
4463 | "expected %d count. Unloading driver.\n", | |
cadbd4a5 | 4464 | __func__, i, LPFC_IOCB_LIST_CNT); |
dea3101e | 4465 | goto out_free_iocbq; |
4466 | } | |
4467 | ||
604a3e30 JB |
4468 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
4469 | if (iotag == 0) { | |
3772a991 | 4470 | kfree(iocbq_entry); |
604a3e30 | 4471 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
3772a991 | 4472 | "Unloading driver.\n", __func__); |
604a3e30 JB |
4473 | goto out_free_iocbq; |
4474 | } | |
3772a991 | 4475 | iocbq_entry->sli4_xritag = NO_XRI; |
2e0fef85 JS |
4476 | |
4477 | spin_lock_irq(&phba->hbalock); | |
dea3101e | 4478 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
4479 | phba->total_iocbq_bufs++; | |
2e0fef85 | 4480 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4481 | } |
4482 | ||
3772a991 | 4483 | return 0; |
dea3101e | 4484 | |
3772a991 JS |
4485 | out_free_iocbq: |
4486 | lpfc_free_iocb_list(phba); | |
dea3101e | 4487 | |
3772a991 JS |
4488 | return -ENOMEM; |
4489 | } | |
5e9d9b82 | 4490 | |
3772a991 | 4491 | /** |
da0436e9 JS |
4492 | * lpfc_free_sgl_list - Free sgl list. |
4493 | * @phba: pointer to lpfc hba data structure. | |
3772a991 | 4494 | * |
da0436e9 | 4495 | * This routine is invoked to free the driver's sgl list and memory. |
3772a991 | 4496 | **/ |
da0436e9 JS |
4497 | static void |
4498 | lpfc_free_sgl_list(struct lpfc_hba *phba) | |
3772a991 | 4499 | { |
da0436e9 JS |
4500 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
4501 | LIST_HEAD(sglq_list); | |
dea3101e | 4502 | |
da0436e9 JS |
4503 | spin_lock_irq(&phba->hbalock); |
4504 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); | |
4505 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 4506 | |
da0436e9 JS |
4507 | list_for_each_entry_safe(sglq_entry, sglq_next, |
4508 | &sglq_list, list) { | |
4509 | list_del(&sglq_entry->list); | |
4510 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); | |
4511 | kfree(sglq_entry); | |
4512 | phba->sli4_hba.total_sglq_bufs--; | |
4513 | } | |
da0436e9 JS |
4514 | kfree(phba->sli4_hba.lpfc_els_sgl_array); |
4515 | } | |
92d7f7b0 | 4516 | |
da0436e9 JS |
4517 | /** |
4518 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. | |
4519 | * @phba: pointer to lpfc hba data structure. | |
4520 | * | |
4521 | * This routine is invoked to allocate the driver's active sgl memory. | |
4522 | * This array will hold the sglq_entry's for active IOs. | |
4523 | **/ | |
4524 | static int | |
4525 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) | |
4526 | { | |
4527 | int size; | |
4528 | size = sizeof(struct lpfc_sglq *); | |
4529 | size *= phba->sli4_hba.max_cfg_param.max_xri; | |
4530 | ||
4531 | phba->sli4_hba.lpfc_sglq_active_list = | |
4532 | kzalloc(size, GFP_KERNEL); | |
4533 | if (!phba->sli4_hba.lpfc_sglq_active_list) | |
4534 | return -ENOMEM; | |
4535 | return 0; | |
3772a991 JS |
4536 | } |
4537 | ||
4538 | /** | |
da0436e9 | 4539 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
3772a991 JS |
4540 | * @phba: pointer to lpfc hba data structure. |
4541 | * | |
da0436e9 JS |
4542 | * This routine is invoked to walk through the array of active sglq entries |
4543 | * and free all of the resources. | |
4544 | * This is just a place holder for now. | |
3772a991 JS |
4545 | **/ |
4546 | static void | |
da0436e9 | 4547 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
3772a991 | 4548 | { |
da0436e9 | 4549 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
3772a991 JS |
4550 | } |
4551 | ||
4552 | /** | |
da0436e9 | 4553 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
3772a991 JS |
4554 | * @phba: pointer to lpfc hba data structure. |
4555 | * | |
da0436e9 JS |
4556 | * This routine is invoked to allocate and initizlize the driver's sgl |
4557 | * list and set up the sgl xritag tag array accordingly. | |
3772a991 JS |
4558 | * |
4559 | * Return codes | |
af901ca1 | 4560 | * 0 - successful |
da0436e9 | 4561 | * other values - error |
3772a991 JS |
4562 | **/ |
4563 | static int | |
da0436e9 | 4564 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
3772a991 | 4565 | { |
da0436e9 JS |
4566 | struct lpfc_sglq *sglq_entry = NULL; |
4567 | int i; | |
4568 | int els_xri_cnt; | |
4569 | ||
4570 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
4571 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4572 | "2400 lpfc_init_sgl_list els %d.\n", | |
4573 | els_xri_cnt); | |
4574 | /* Initialize and populate the sglq list per host/VF. */ | |
4575 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); | |
4576 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
4577 | ||
4578 | /* Sanity check on XRI management */ | |
4579 | if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) { | |
4580 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4581 | "2562 No room left for SCSI XRI allocation: " | |
4582 | "max_xri=%d, els_xri=%d\n", | |
4583 | phba->sli4_hba.max_cfg_param.max_xri, | |
4584 | els_xri_cnt); | |
4585 | return -ENOMEM; | |
4586 | } | |
3772a991 | 4587 | |
da0436e9 JS |
4588 | /* Allocate memory for the ELS XRI management array */ |
4589 | phba->sli4_hba.lpfc_els_sgl_array = | |
4590 | kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt), | |
4591 | GFP_KERNEL); | |
0ff10d46 | 4592 | |
da0436e9 JS |
4593 | if (!phba->sli4_hba.lpfc_els_sgl_array) { |
4594 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4595 | "2401 Failed to allocate memory for ELS " | |
4596 | "XRI management array of size %d.\n", | |
4597 | els_xri_cnt); | |
4598 | return -ENOMEM; | |
4599 | } | |
2e0fef85 | 4600 | |
da0436e9 JS |
4601 | /* Keep the SCSI XRI into the XRI management array */ |
4602 | phba->sli4_hba.scsi_xri_max = | |
4603 | phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; | |
4604 | phba->sli4_hba.scsi_xri_cnt = 0; | |
4605 | ||
4606 | phba->sli4_hba.lpfc_scsi_psb_array = | |
4607 | kzalloc((sizeof(struct lpfc_scsi_buf *) * | |
4608 | phba->sli4_hba.scsi_xri_max), GFP_KERNEL); | |
4609 | ||
4610 | if (!phba->sli4_hba.lpfc_scsi_psb_array) { | |
4611 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4612 | "2563 Failed to allocate memory for SCSI " | |
4613 | "XRI management array of size %d.\n", | |
4614 | phba->sli4_hba.scsi_xri_max); | |
4615 | kfree(phba->sli4_hba.lpfc_els_sgl_array); | |
4616 | return -ENOMEM; | |
4617 | } | |
4618 | ||
4619 | for (i = 0; i < els_xri_cnt; i++) { | |
4620 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL); | |
4621 | if (sglq_entry == NULL) { | |
4622 | printk(KERN_ERR "%s: only allocated %d sgls of " | |
4623 | "expected %d count. Unloading driver.\n", | |
4624 | __func__, i, els_xri_cnt); | |
4625 | goto out_free_mem; | |
4626 | } | |
4627 | ||
4628 | sglq_entry->sli4_xritag = lpfc_sli4_next_xritag(phba); | |
4629 | if (sglq_entry->sli4_xritag == NO_XRI) { | |
4630 | kfree(sglq_entry); | |
4631 | printk(KERN_ERR "%s: failed to allocate XRI.\n" | |
4632 | "Unloading driver.\n", __func__); | |
4633 | goto out_free_mem; | |
4634 | } | |
4635 | sglq_entry->buff_type = GEN_BUFF_TYPE; | |
4636 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys); | |
4637 | if (sglq_entry->virt == NULL) { | |
4638 | kfree(sglq_entry); | |
4639 | printk(KERN_ERR "%s: failed to allocate mbuf.\n" | |
4640 | "Unloading driver.\n", __func__); | |
4641 | goto out_free_mem; | |
4642 | } | |
4643 | sglq_entry->sgl = sglq_entry->virt; | |
4644 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); | |
4645 | ||
4646 | /* The list order is used by later block SGL registraton */ | |
4647 | spin_lock_irq(&phba->hbalock); | |
0f65ff68 | 4648 | sglq_entry->state = SGL_FREED; |
da0436e9 JS |
4649 | list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list); |
4650 | phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry; | |
4651 | phba->sli4_hba.total_sglq_bufs++; | |
4652 | spin_unlock_irq(&phba->hbalock); | |
4653 | } | |
4654 | return 0; | |
4655 | ||
4656 | out_free_mem: | |
4657 | kfree(phba->sli4_hba.lpfc_scsi_psb_array); | |
4658 | lpfc_free_sgl_list(phba); | |
4659 | return -ENOMEM; | |
4660 | } | |
4661 | ||
4662 | /** | |
4663 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port | |
4664 | * @phba: pointer to lpfc hba data structure. | |
4665 | * | |
4666 | * This routine is invoked to post rpi header templates to the | |
4667 | * HBA consistent with the SLI-4 interface spec. This routine | |
4668 | * posts a PAGE_SIZE memory region to the port to hold up to | |
4669 | * PAGE_SIZE modulo 64 rpi context headers. | |
4670 | * No locks are held here because this is an initialization routine | |
4671 | * called only from probe or lpfc_online when interrupts are not | |
4672 | * enabled and the driver is reinitializing the device. | |
4673 | * | |
4674 | * Return codes | |
af901ca1 | 4675 | * 0 - successful |
d439d286 JS |
4676 | * -ENOMEM - No availble memory |
4677 | * -EIO - The mailbox failed to complete successfully. | |
da0436e9 JS |
4678 | **/ |
4679 | int | |
4680 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) | |
4681 | { | |
4682 | int rc = 0; | |
4683 | int longs; | |
4684 | uint16_t rpi_count; | |
4685 | struct lpfc_rpi_hdr *rpi_hdr; | |
4686 | ||
4687 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); | |
4688 | ||
4689 | /* | |
4690 | * Provision an rpi bitmask range for discovery. The total count | |
4691 | * is the difference between max and base + 1. | |
4692 | */ | |
4693 | rpi_count = phba->sli4_hba.max_cfg_param.rpi_base + | |
4694 | phba->sli4_hba.max_cfg_param.max_rpi - 1; | |
4695 | ||
4696 | longs = ((rpi_count) + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
4697 | phba->sli4_hba.rpi_bmask = kzalloc(longs * sizeof(unsigned long), | |
4698 | GFP_KERNEL); | |
4699 | if (!phba->sli4_hba.rpi_bmask) | |
4700 | return -ENOMEM; | |
4701 | ||
4702 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
4703 | if (!rpi_hdr) { | |
4704 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4705 | "0391 Error during rpi post operation\n"); | |
4706 | lpfc_sli4_remove_rpis(phba); | |
4707 | rc = -ENODEV; | |
4708 | } | |
4709 | ||
4710 | return rc; | |
4711 | } | |
4712 | ||
4713 | /** | |
4714 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region | |
4715 | * @phba: pointer to lpfc hba data structure. | |
4716 | * | |
4717 | * This routine is invoked to allocate a single 4KB memory region to | |
4718 | * support rpis and stores them in the phba. This single region | |
4719 | * provides support for up to 64 rpis. The region is used globally | |
4720 | * by the device. | |
4721 | * | |
4722 | * Returns: | |
4723 | * A valid rpi hdr on success. | |
4724 | * A NULL pointer on any failure. | |
4725 | **/ | |
4726 | struct lpfc_rpi_hdr * | |
4727 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) | |
4728 | { | |
4729 | uint16_t rpi_limit, curr_rpi_range; | |
4730 | struct lpfc_dmabuf *dmabuf; | |
4731 | struct lpfc_rpi_hdr *rpi_hdr; | |
4732 | ||
4733 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + | |
4734 | phba->sli4_hba.max_cfg_param.max_rpi - 1; | |
4735 | ||
4736 | spin_lock_irq(&phba->hbalock); | |
4737 | curr_rpi_range = phba->sli4_hba.next_rpi; | |
4738 | spin_unlock_irq(&phba->hbalock); | |
4739 | ||
4740 | /* | |
4741 | * The port has a limited number of rpis. The increment here | |
4742 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value | |
4743 | * and to allow the full max_rpi range per port. | |
4744 | */ | |
4745 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) | |
4746 | return NULL; | |
4747 | ||
4748 | /* | |
4749 | * First allocate the protocol header region for the port. The | |
4750 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. | |
4751 | */ | |
4752 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
4753 | if (!dmabuf) | |
4754 | return NULL; | |
4755 | ||
4756 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
4757 | LPFC_HDR_TEMPLATE_SIZE, | |
4758 | &dmabuf->phys, | |
4759 | GFP_KERNEL); | |
4760 | if (!dmabuf->virt) { | |
4761 | rpi_hdr = NULL; | |
4762 | goto err_free_dmabuf; | |
4763 | } | |
4764 | ||
4765 | memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE); | |
4766 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { | |
4767 | rpi_hdr = NULL; | |
4768 | goto err_free_coherent; | |
4769 | } | |
4770 | ||
4771 | /* Save the rpi header data for cleanup later. */ | |
4772 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); | |
4773 | if (!rpi_hdr) | |
4774 | goto err_free_coherent; | |
4775 | ||
4776 | rpi_hdr->dmabuf = dmabuf; | |
4777 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; | |
4778 | rpi_hdr->page_count = 1; | |
4779 | spin_lock_irq(&phba->hbalock); | |
4780 | rpi_hdr->start_rpi = phba->sli4_hba.next_rpi; | |
4781 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); | |
4782 | ||
4783 | /* | |
4784 | * The next_rpi stores the next module-64 rpi value to post | |
4785 | * in any subsequent rpi memory region postings. | |
4786 | */ | |
4787 | phba->sli4_hba.next_rpi += LPFC_RPI_HDR_COUNT; | |
4788 | spin_unlock_irq(&phba->hbalock); | |
4789 | return rpi_hdr; | |
4790 | ||
4791 | err_free_coherent: | |
4792 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, | |
4793 | dmabuf->virt, dmabuf->phys); | |
4794 | err_free_dmabuf: | |
4795 | kfree(dmabuf); | |
4796 | return NULL; | |
4797 | } | |
4798 | ||
4799 | /** | |
4800 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions | |
4801 | * @phba: pointer to lpfc hba data structure. | |
4802 | * | |
4803 | * This routine is invoked to remove all memory resources allocated | |
4804 | * to support rpis. This routine presumes the caller has released all | |
4805 | * rpis consumed by fabric or port logins and is prepared to have | |
4806 | * the header pages removed. | |
4807 | **/ | |
4808 | void | |
4809 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) | |
4810 | { | |
4811 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; | |
4812 | ||
4813 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, | |
4814 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { | |
4815 | list_del(&rpi_hdr->list); | |
4816 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, | |
4817 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); | |
4818 | kfree(rpi_hdr->dmabuf); | |
4819 | kfree(rpi_hdr); | |
4820 | } | |
4821 | ||
4822 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base; | |
4823 | memset(phba->sli4_hba.rpi_bmask, 0, sizeof(*phba->sli4_hba.rpi_bmask)); | |
4824 | } | |
4825 | ||
4826 | /** | |
4827 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. | |
4828 | * @pdev: pointer to pci device data structure. | |
4829 | * | |
4830 | * This routine is invoked to allocate the driver hba data structure for an | |
4831 | * HBA device. If the allocation is successful, the phba reference to the | |
4832 | * PCI device data structure is set. | |
4833 | * | |
4834 | * Return codes | |
af901ca1 | 4835 | * pointer to @phba - successful |
da0436e9 JS |
4836 | * NULL - error |
4837 | **/ | |
4838 | static struct lpfc_hba * | |
4839 | lpfc_hba_alloc(struct pci_dev *pdev) | |
4840 | { | |
4841 | struct lpfc_hba *phba; | |
4842 | ||
4843 | /* Allocate memory for HBA structure */ | |
4844 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); | |
4845 | if (!phba) { | |
e34ccdfe | 4846 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
da0436e9 JS |
4847 | return NULL; |
4848 | } | |
4849 | ||
4850 | /* Set reference to PCI device in HBA structure */ | |
4851 | phba->pcidev = pdev; | |
4852 | ||
4853 | /* Assign an unused board number */ | |
4854 | phba->brd_no = lpfc_get_instance(); | |
4855 | if (phba->brd_no < 0) { | |
4856 | kfree(phba); | |
4857 | return NULL; | |
4858 | } | |
4859 | ||
4fede78f | 4860 | spin_lock_init(&phba->ct_ev_lock); |
f1c3b0fc JS |
4861 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
4862 | ||
da0436e9 JS |
4863 | return phba; |
4864 | } | |
4865 | ||
4866 | /** | |
4867 | * lpfc_hba_free - Free driver hba data structure with a device. | |
4868 | * @phba: pointer to lpfc hba data structure. | |
4869 | * | |
4870 | * This routine is invoked to free the driver hba data structure with an | |
4871 | * HBA device. | |
4872 | **/ | |
4873 | static void | |
4874 | lpfc_hba_free(struct lpfc_hba *phba) | |
4875 | { | |
4876 | /* Release the driver assigned board number */ | |
4877 | idr_remove(&lpfc_hba_index, phba->brd_no); | |
4878 | ||
4879 | kfree(phba); | |
4880 | return; | |
4881 | } | |
4882 | ||
4883 | /** | |
4884 | * lpfc_create_shost - Create hba physical port with associated scsi host. | |
4885 | * @phba: pointer to lpfc hba data structure. | |
4886 | * | |
4887 | * This routine is invoked to create HBA physical port and associate a SCSI | |
4888 | * host with it. | |
4889 | * | |
4890 | * Return codes | |
af901ca1 | 4891 | * 0 - successful |
da0436e9 JS |
4892 | * other values - error |
4893 | **/ | |
4894 | static int | |
4895 | lpfc_create_shost(struct lpfc_hba *phba) | |
4896 | { | |
4897 | struct lpfc_vport *vport; | |
4898 | struct Scsi_Host *shost; | |
4899 | ||
4900 | /* Initialize HBA FC structure */ | |
4901 | phba->fc_edtov = FF_DEF_EDTOV; | |
4902 | phba->fc_ratov = FF_DEF_RATOV; | |
4903 | phba->fc_altov = FF_DEF_ALTOV; | |
4904 | phba->fc_arbtov = FF_DEF_ARBTOV; | |
4905 | ||
d7c47992 | 4906 | atomic_set(&phba->sdev_cnt, 0); |
da0436e9 JS |
4907 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
4908 | if (!vport) | |
4909 | return -ENODEV; | |
4910 | ||
4911 | shost = lpfc_shost_from_vport(vport); | |
4912 | phba->pport = vport; | |
4913 | lpfc_debugfs_initialize(vport); | |
4914 | /* Put reference to SCSI host to driver's device private data */ | |
4915 | pci_set_drvdata(phba->pcidev, shost); | |
2e0fef85 | 4916 | |
3772a991 JS |
4917 | return 0; |
4918 | } | |
db2378e0 | 4919 | |
3772a991 JS |
4920 | /** |
4921 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. | |
4922 | * @phba: pointer to lpfc hba data structure. | |
4923 | * | |
4924 | * This routine is invoked to destroy HBA physical port and the associated | |
4925 | * SCSI host. | |
4926 | **/ | |
4927 | static void | |
4928 | lpfc_destroy_shost(struct lpfc_hba *phba) | |
4929 | { | |
4930 | struct lpfc_vport *vport = phba->pport; | |
4931 | ||
4932 | /* Destroy physical port that associated with the SCSI host */ | |
4933 | destroy_port(vport); | |
4934 | ||
4935 | return; | |
4936 | } | |
4937 | ||
4938 | /** | |
4939 | * lpfc_setup_bg - Setup Block guard structures and debug areas. | |
4940 | * @phba: pointer to lpfc hba data structure. | |
4941 | * @shost: the shost to be used to detect Block guard settings. | |
4942 | * | |
4943 | * This routine sets up the local Block guard protocol settings for @shost. | |
4944 | * This routine also allocates memory for debugging bg buffers. | |
4945 | **/ | |
4946 | static void | |
4947 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) | |
4948 | { | |
4949 | int pagecnt = 10; | |
4950 | if (lpfc_prot_mask && lpfc_prot_guard) { | |
4951 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4952 | "1478 Registering BlockGuard with the " | |
4953 | "SCSI layer\n"); | |
4954 | scsi_host_set_prot(shost, lpfc_prot_mask); | |
4955 | scsi_host_set_guard(shost, lpfc_prot_guard); | |
4956 | } | |
4957 | if (!_dump_buf_data) { | |
4958 | while (pagecnt) { | |
4959 | spin_lock_init(&_dump_buf_lock); | |
4960 | _dump_buf_data = | |
4961 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
4962 | if (_dump_buf_data) { | |
6a9c52cf JS |
4963 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
4964 | "9043 BLKGRD: allocated %d pages for " | |
3772a991 JS |
4965 | "_dump_buf_data at 0x%p\n", |
4966 | (1 << pagecnt), _dump_buf_data); | |
4967 | _dump_buf_data_order = pagecnt; | |
4968 | memset(_dump_buf_data, 0, | |
4969 | ((1 << PAGE_SHIFT) << pagecnt)); | |
4970 | break; | |
4971 | } else | |
4972 | --pagecnt; | |
4973 | } | |
4974 | if (!_dump_buf_data_order) | |
6a9c52cf JS |
4975 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
4976 | "9044 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
4977 | "memory for hexdump\n"); |
4978 | } else | |
6a9c52cf JS |
4979 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
4980 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" | |
3772a991 JS |
4981 | "\n", _dump_buf_data); |
4982 | if (!_dump_buf_dif) { | |
4983 | while (pagecnt) { | |
4984 | _dump_buf_dif = | |
4985 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
4986 | if (_dump_buf_dif) { | |
6a9c52cf JS |
4987 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
4988 | "9046 BLKGRD: allocated %d pages for " | |
3772a991 JS |
4989 | "_dump_buf_dif at 0x%p\n", |
4990 | (1 << pagecnt), _dump_buf_dif); | |
4991 | _dump_buf_dif_order = pagecnt; | |
4992 | memset(_dump_buf_dif, 0, | |
4993 | ((1 << PAGE_SHIFT) << pagecnt)); | |
4994 | break; | |
4995 | } else | |
4996 | --pagecnt; | |
4997 | } | |
4998 | if (!_dump_buf_dif_order) | |
6a9c52cf JS |
4999 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5000 | "9047 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
5001 | "memory for hexdump\n"); |
5002 | } else | |
6a9c52cf JS |
5003 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5004 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", | |
3772a991 JS |
5005 | _dump_buf_dif); |
5006 | } | |
5007 | ||
5008 | /** | |
5009 | * lpfc_post_init_setup - Perform necessary device post initialization setup. | |
5010 | * @phba: pointer to lpfc hba data structure. | |
5011 | * | |
5012 | * This routine is invoked to perform all the necessary post initialization | |
5013 | * setup for the device. | |
5014 | **/ | |
5015 | static void | |
5016 | lpfc_post_init_setup(struct lpfc_hba *phba) | |
5017 | { | |
5018 | struct Scsi_Host *shost; | |
5019 | struct lpfc_adapter_event_header adapter_event; | |
5020 | ||
5021 | /* Get the default values for Model Name and Description */ | |
5022 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
5023 | ||
5024 | /* | |
5025 | * hba setup may have changed the hba_queue_depth so we need to | |
5026 | * adjust the value of can_queue. | |
5027 | */ | |
5028 | shost = pci_get_drvdata(phba->pcidev); | |
5029 | shost->can_queue = phba->cfg_hba_queue_depth - 10; | |
5030 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) | |
5031 | lpfc_setup_bg(phba, shost); | |
5032 | ||
5033 | lpfc_host_attrib_init(shost); | |
5034 | ||
5035 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | |
5036 | spin_lock_irq(shost->host_lock); | |
5037 | lpfc_poll_start_timer(phba); | |
5038 | spin_unlock_irq(shost->host_lock); | |
5039 | } | |
5040 | ||
5041 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5042 | "0428 Perform SCSI scan\n"); | |
5043 | /* Send board arrival event to upper layer */ | |
5044 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; | |
5045 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; | |
5046 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
5047 | sizeof(adapter_event), | |
5048 | (char *) &adapter_event, | |
5049 | LPFC_NL_VENDOR_ID); | |
5050 | return; | |
5051 | } | |
5052 | ||
5053 | /** | |
5054 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. | |
5055 | * @phba: pointer to lpfc hba data structure. | |
5056 | * | |
5057 | * This routine is invoked to set up the PCI device memory space for device | |
5058 | * with SLI-3 interface spec. | |
5059 | * | |
5060 | * Return codes | |
af901ca1 | 5061 | * 0 - successful |
3772a991 JS |
5062 | * other values - error |
5063 | **/ | |
5064 | static int | |
5065 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) | |
5066 | { | |
5067 | struct pci_dev *pdev; | |
5068 | unsigned long bar0map_len, bar2map_len; | |
5069 | int i, hbq_count; | |
5070 | void *ptr; | |
5071 | int error = -ENODEV; | |
5072 | ||
5073 | /* Obtain PCI device reference */ | |
5074 | if (!phba->pcidev) | |
5075 | return error; | |
5076 | else | |
5077 | pdev = phba->pcidev; | |
5078 | ||
5079 | /* Set the device DMA mask size */ | |
8e68597d MR |
5080 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
5081 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
5082 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
5083 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
3772a991 | 5084 | return error; |
8e68597d MR |
5085 | } |
5086 | } | |
3772a991 JS |
5087 | |
5088 | /* Get the bus address of Bar0 and Bar2 and the number of bytes | |
5089 | * required by each mapping. | |
5090 | */ | |
5091 | phba->pci_bar0_map = pci_resource_start(pdev, 0); | |
5092 | bar0map_len = pci_resource_len(pdev, 0); | |
5093 | ||
5094 | phba->pci_bar2_map = pci_resource_start(pdev, 2); | |
5095 | bar2map_len = pci_resource_len(pdev, 2); | |
5096 | ||
5097 | /* Map HBA SLIM to a kernel virtual address. */ | |
5098 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); | |
5099 | if (!phba->slim_memmap_p) { | |
5100 | dev_printk(KERN_ERR, &pdev->dev, | |
5101 | "ioremap failed for SLIM memory.\n"); | |
5102 | goto out; | |
5103 | } | |
5104 | ||
5105 | /* Map HBA Control Registers to a kernel virtual address. */ | |
5106 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); | |
5107 | if (!phba->ctrl_regs_memmap_p) { | |
5108 | dev_printk(KERN_ERR, &pdev->dev, | |
5109 | "ioremap failed for HBA control registers.\n"); | |
5110 | goto out_iounmap_slim; | |
5111 | } | |
5112 | ||
5113 | /* Allocate memory for SLI-2 structures */ | |
5114 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, | |
5115 | SLI2_SLIM_SIZE, | |
5116 | &phba->slim2p.phys, | |
5117 | GFP_KERNEL); | |
5118 | if (!phba->slim2p.virt) | |
5119 | goto out_iounmap; | |
5120 | ||
5121 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); | |
5122 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); | |
7a470277 JS |
5123 | phba->mbox_ext = (phba->slim2p.virt + |
5124 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); | |
3772a991 JS |
5125 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
5126 | phba->IOCBs = (phba->slim2p.virt + | |
5127 | offsetof(struct lpfc_sli2_slim, IOCBs)); | |
5128 | ||
5129 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, | |
5130 | lpfc_sli_hbq_size(), | |
5131 | &phba->hbqslimp.phys, | |
5132 | GFP_KERNEL); | |
5133 | if (!phba->hbqslimp.virt) | |
5134 | goto out_free_slim; | |
5135 | ||
5136 | hbq_count = lpfc_sli_hbq_count(); | |
5137 | ptr = phba->hbqslimp.virt; | |
5138 | for (i = 0; i < hbq_count; ++i) { | |
5139 | phba->hbqs[i].hbq_virt = ptr; | |
5140 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
5141 | ptr += (lpfc_hbq_defs[i]->entry_count * | |
5142 | sizeof(struct lpfc_hbq_entry)); | |
5143 | } | |
5144 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; | |
5145 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; | |
5146 | ||
5147 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); | |
5148 | ||
5149 | INIT_LIST_HEAD(&phba->rb_pend_list); | |
5150 | ||
5151 | phba->MBslimaddr = phba->slim_memmap_p; | |
5152 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; | |
5153 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; | |
5154 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; | |
5155 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; | |
5156 | ||
5157 | return 0; | |
5158 | ||
5159 | out_free_slim: | |
5160 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
5161 | phba->slim2p.virt, phba->slim2p.phys); | |
5162 | out_iounmap: | |
5163 | iounmap(phba->ctrl_regs_memmap_p); | |
5164 | out_iounmap_slim: | |
5165 | iounmap(phba->slim_memmap_p); | |
5166 | out: | |
5167 | return error; | |
5168 | } | |
5169 | ||
5170 | /** | |
5171 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. | |
5172 | * @phba: pointer to lpfc hba data structure. | |
5173 | * | |
5174 | * This routine is invoked to unset the PCI device memory space for device | |
5175 | * with SLI-3 interface spec. | |
5176 | **/ | |
5177 | static void | |
5178 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) | |
5179 | { | |
5180 | struct pci_dev *pdev; | |
5181 | ||
5182 | /* Obtain PCI device reference */ | |
5183 | if (!phba->pcidev) | |
5184 | return; | |
5185 | else | |
5186 | pdev = phba->pcidev; | |
5187 | ||
5188 | /* Free coherent DMA memory allocated */ | |
5189 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
5190 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
5191 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
5192 | phba->slim2p.virt, phba->slim2p.phys); | |
5193 | ||
5194 | /* I/O memory unmap */ | |
5195 | iounmap(phba->ctrl_regs_memmap_p); | |
5196 | iounmap(phba->slim_memmap_p); | |
5197 | ||
5198 | return; | |
5199 | } | |
5200 | ||
5201 | /** | |
da0436e9 | 5202 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
3772a991 JS |
5203 | * @phba: pointer to lpfc hba data structure. |
5204 | * | |
da0436e9 JS |
5205 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
5206 | * done and check status. | |
3772a991 | 5207 | * |
da0436e9 | 5208 | * Return 0 if successful, otherwise -ENODEV. |
3772a991 | 5209 | **/ |
da0436e9 JS |
5210 | int |
5211 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) | |
3772a991 | 5212 | { |
28baac74 | 5213 | struct lpfc_register sta_reg, uerrlo_reg, uerrhi_reg; |
da0436e9 | 5214 | int i, port_error = -ENODEV; |
3772a991 | 5215 | |
da0436e9 JS |
5216 | if (!phba->sli4_hba.STAregaddr) |
5217 | return -ENODEV; | |
3772a991 | 5218 | |
da0436e9 JS |
5219 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
5220 | for (i = 0; i < 3000; i++) { | |
5221 | sta_reg.word0 = readl(phba->sli4_hba.STAregaddr); | |
5222 | /* Encounter fatal POST error, break out */ | |
5223 | if (bf_get(lpfc_hst_state_perr, &sta_reg)) { | |
5224 | port_error = -ENODEV; | |
5225 | break; | |
5226 | } | |
5227 | if (LPFC_POST_STAGE_ARMFW_READY == | |
5228 | bf_get(lpfc_hst_state_port_status, &sta_reg)) { | |
5229 | port_error = 0; | |
5230 | break; | |
5231 | } | |
5232 | msleep(10); | |
3772a991 JS |
5233 | } |
5234 | ||
da0436e9 JS |
5235 | if (port_error) |
5236 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5237 | "1408 Failure HBA POST Status: sta_reg=0x%x, " | |
5238 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, xrom=x%x, " | |
5239 | "dl=x%x, pstatus=x%x\n", sta_reg.word0, | |
5240 | bf_get(lpfc_hst_state_perr, &sta_reg), | |
5241 | bf_get(lpfc_hst_state_sfi, &sta_reg), | |
5242 | bf_get(lpfc_hst_state_nip, &sta_reg), | |
5243 | bf_get(lpfc_hst_state_ipc, &sta_reg), | |
5244 | bf_get(lpfc_hst_state_xrom, &sta_reg), | |
5245 | bf_get(lpfc_hst_state_dl, &sta_reg), | |
5246 | bf_get(lpfc_hst_state_port_status, &sta_reg)); | |
5247 | ||
5248 | /* Log device information */ | |
28baac74 JS |
5249 | phba->sli4_hba.sli_intf.word0 = readl(phba->sli4_hba.SLIINTFregaddr); |
5250 | if (bf_get(lpfc_sli_intf_valid, | |
5251 | &phba->sli4_hba.sli_intf) == LPFC_SLI_INTF_VALID) { | |
5252 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5253 | "2534 Device Info: ChipType=0x%x, SliRev=0x%x, " | |
085c647c JS |
5254 | "IFType=0x%x, SLIHint_1=0x%x, SLIHint_2=0x%x, " |
5255 | "FT=0x%x\n", | |
28baac74 JS |
5256 | bf_get(lpfc_sli_intf_sli_family, |
5257 | &phba->sli4_hba.sli_intf), | |
5258 | bf_get(lpfc_sli_intf_slirev, | |
5259 | &phba->sli4_hba.sli_intf), | |
085c647c JS |
5260 | bf_get(lpfc_sli_intf_if_type, |
5261 | &phba->sli4_hba.sli_intf), | |
5262 | bf_get(lpfc_sli_intf_sli_hint1, | |
28baac74 | 5263 | &phba->sli4_hba.sli_intf), |
085c647c JS |
5264 | bf_get(lpfc_sli_intf_sli_hint2, |
5265 | &phba->sli4_hba.sli_intf), | |
5266 | bf_get(lpfc_sli_intf_func_type, | |
28baac74 JS |
5267 | &phba->sli4_hba.sli_intf)); |
5268 | } | |
085c647c | 5269 | |
a747c9ce JS |
5270 | phba->sli4_hba.ue_mask_lo = readl(phba->sli4_hba.UEMASKLOregaddr); |
5271 | phba->sli4_hba.ue_mask_hi = readl(phba->sli4_hba.UEMASKHIregaddr); | |
8fa38513 | 5272 | /* With uncoverable error, log the error message and return error */ |
a747c9ce JS |
5273 | uerrlo_reg.word0 = readl(phba->sli4_hba.UERRLOregaddr); |
5274 | uerrhi_reg.word0 = readl(phba->sli4_hba.UERRHIregaddr); | |
5275 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || | |
5276 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { | |
5277 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5278 | "1422 HBA Unrecoverable error: " | |
5279 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " | |
5280 | "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n", | |
5281 | uerrlo_reg.word0, uerrhi_reg.word0, | |
5282 | phba->sli4_hba.ue_mask_lo, | |
5283 | phba->sli4_hba.ue_mask_hi); | |
8fa38513 JS |
5284 | return -ENODEV; |
5285 | } | |
5286 | ||
da0436e9 JS |
5287 | return port_error; |
5288 | } | |
3772a991 | 5289 | |
da0436e9 JS |
5290 | /** |
5291 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. | |
5292 | * @phba: pointer to lpfc hba data structure. | |
5293 | * | |
5294 | * This routine is invoked to set up SLI4 BAR0 PCI config space register | |
5295 | * memory map. | |
5296 | **/ | |
5297 | static void | |
5298 | lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba) | |
5299 | { | |
5300 | phba->sli4_hba.UERRLOregaddr = phba->sli4_hba.conf_regs_memmap_p + | |
5301 | LPFC_UERR_STATUS_LO; | |
5302 | phba->sli4_hba.UERRHIregaddr = phba->sli4_hba.conf_regs_memmap_p + | |
5303 | LPFC_UERR_STATUS_HI; | |
a747c9ce JS |
5304 | phba->sli4_hba.UEMASKLOregaddr = phba->sli4_hba.conf_regs_memmap_p + |
5305 | LPFC_UE_MASK_LO; | |
5306 | phba->sli4_hba.UEMASKHIregaddr = phba->sli4_hba.conf_regs_memmap_p + | |
5307 | LPFC_UE_MASK_HI; | |
28baac74 JS |
5308 | phba->sli4_hba.SLIINTFregaddr = phba->sli4_hba.conf_regs_memmap_p + |
5309 | LPFC_SLI_INTF; | |
da0436e9 | 5310 | } |
3772a991 | 5311 | |
da0436e9 JS |
5312 | /** |
5313 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. | |
5314 | * @phba: pointer to lpfc hba data structure. | |
5315 | * | |
5316 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) | |
5317 | * memory map. | |
5318 | **/ | |
5319 | static void | |
5320 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) | |
5321 | { | |
3772a991 | 5322 | |
da0436e9 JS |
5323 | phba->sli4_hba.STAregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
5324 | LPFC_HST_STATE; | |
5325 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + | |
5326 | LPFC_HST_ISR0; | |
5327 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + | |
5328 | LPFC_HST_IMR0; | |
5329 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + | |
5330 | LPFC_HST_ISCR0; | |
5331 | return; | |
3772a991 JS |
5332 | } |
5333 | ||
5334 | /** | |
da0436e9 | 5335 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
3772a991 | 5336 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 5337 | * @vf: virtual function number |
3772a991 | 5338 | * |
da0436e9 JS |
5339 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
5340 | * based on the given viftual function number, @vf. | |
5341 | * | |
5342 | * Return 0 if successful, otherwise -ENODEV. | |
3772a991 | 5343 | **/ |
da0436e9 JS |
5344 | static int |
5345 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) | |
3772a991 | 5346 | { |
da0436e9 JS |
5347 | if (vf > LPFC_VIR_FUNC_MAX) |
5348 | return -ENODEV; | |
3772a991 | 5349 | |
da0436e9 JS |
5350 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
5351 | vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL); | |
5352 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5353 | vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL); | |
5354 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5355 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); | |
5356 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5357 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); | |
5358 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5359 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); | |
5360 | return 0; | |
3772a991 JS |
5361 | } |
5362 | ||
5363 | /** | |
da0436e9 | 5364 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
3772a991 JS |
5365 | * @phba: pointer to lpfc hba data structure. |
5366 | * | |
da0436e9 JS |
5367 | * This routine is invoked to create the bootstrap mailbox |
5368 | * region consistent with the SLI-4 interface spec. This | |
5369 | * routine allocates all memory necessary to communicate | |
5370 | * mailbox commands to the port and sets up all alignment | |
5371 | * needs. No locks are expected to be held when calling | |
5372 | * this routine. | |
3772a991 JS |
5373 | * |
5374 | * Return codes | |
af901ca1 | 5375 | * 0 - successful |
d439d286 | 5376 | * -ENOMEM - could not allocated memory. |
da0436e9 | 5377 | **/ |
3772a991 | 5378 | static int |
da0436e9 | 5379 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 5380 | { |
da0436e9 JS |
5381 | uint32_t bmbx_size; |
5382 | struct lpfc_dmabuf *dmabuf; | |
5383 | struct dma_address *dma_address; | |
5384 | uint32_t pa_addr; | |
5385 | uint64_t phys_addr; | |
5386 | ||
5387 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
5388 | if (!dmabuf) | |
5389 | return -ENOMEM; | |
3772a991 | 5390 | |
da0436e9 JS |
5391 | /* |
5392 | * The bootstrap mailbox region is comprised of 2 parts | |
5393 | * plus an alignment restriction of 16 bytes. | |
5394 | */ | |
5395 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); | |
5396 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
5397 | bmbx_size, | |
5398 | &dmabuf->phys, | |
5399 | GFP_KERNEL); | |
5400 | if (!dmabuf->virt) { | |
5401 | kfree(dmabuf); | |
5402 | return -ENOMEM; | |
3772a991 | 5403 | } |
da0436e9 | 5404 | memset(dmabuf->virt, 0, bmbx_size); |
3772a991 | 5405 | |
da0436e9 JS |
5406 | /* |
5407 | * Initialize the bootstrap mailbox pointers now so that the register | |
5408 | * operations are simple later. The mailbox dma address is required | |
5409 | * to be 16-byte aligned. Also align the virtual memory as each | |
5410 | * maibox is copied into the bmbx mailbox region before issuing the | |
5411 | * command to the port. | |
5412 | */ | |
5413 | phba->sli4_hba.bmbx.dmabuf = dmabuf; | |
5414 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; | |
5415 | ||
5416 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, | |
5417 | LPFC_ALIGN_16_BYTE); | |
5418 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, | |
5419 | LPFC_ALIGN_16_BYTE); | |
5420 | ||
5421 | /* | |
5422 | * Set the high and low physical addresses now. The SLI4 alignment | |
5423 | * requirement is 16 bytes and the mailbox is posted to the port | |
5424 | * as two 30-bit addresses. The other data is a bit marking whether | |
5425 | * the 30-bit address is the high or low address. | |
5426 | * Upcast bmbx aphys to 64bits so shift instruction compiles | |
5427 | * clean on 32 bit machines. | |
5428 | */ | |
5429 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
5430 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; | |
5431 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); | |
5432 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | | |
5433 | LPFC_BMBX_BIT1_ADDR_HI); | |
5434 | ||
5435 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); | |
5436 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | | |
5437 | LPFC_BMBX_BIT1_ADDR_LO); | |
5438 | return 0; | |
3772a991 JS |
5439 | } |
5440 | ||
5441 | /** | |
da0436e9 | 5442 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
3772a991 JS |
5443 | * @phba: pointer to lpfc hba data structure. |
5444 | * | |
da0436e9 JS |
5445 | * This routine is invoked to teardown the bootstrap mailbox |
5446 | * region and release all host resources. This routine requires | |
5447 | * the caller to ensure all mailbox commands recovered, no | |
5448 | * additional mailbox comands are sent, and interrupts are disabled | |
5449 | * before calling this routine. | |
5450 | * | |
5451 | **/ | |
3772a991 | 5452 | static void |
da0436e9 | 5453 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 5454 | { |
da0436e9 JS |
5455 | dma_free_coherent(&phba->pcidev->dev, |
5456 | phba->sli4_hba.bmbx.bmbx_size, | |
5457 | phba->sli4_hba.bmbx.dmabuf->virt, | |
5458 | phba->sli4_hba.bmbx.dmabuf->phys); | |
5459 | ||
5460 | kfree(phba->sli4_hba.bmbx.dmabuf); | |
5461 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); | |
3772a991 JS |
5462 | } |
5463 | ||
5464 | /** | |
da0436e9 | 5465 | * lpfc_sli4_read_config - Get the config parameters. |
3772a991 JS |
5466 | * @phba: pointer to lpfc hba data structure. |
5467 | * | |
da0436e9 JS |
5468 | * This routine is invoked to read the configuration parameters from the HBA. |
5469 | * The configuration parameters are used to set the base and maximum values | |
5470 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource | |
5471 | * allocation for the port. | |
3772a991 JS |
5472 | * |
5473 | * Return codes | |
af901ca1 | 5474 | * 0 - successful |
d439d286 JS |
5475 | * -ENOMEM - No availble memory |
5476 | * -EIO - The mailbox failed to complete successfully. | |
3772a991 | 5477 | **/ |
da0436e9 JS |
5478 | static int |
5479 | lpfc_sli4_read_config(struct lpfc_hba *phba) | |
3772a991 | 5480 | { |
da0436e9 JS |
5481 | LPFC_MBOXQ_t *pmb; |
5482 | struct lpfc_mbx_read_config *rd_config; | |
5483 | uint32_t rc = 0; | |
3772a991 | 5484 | |
da0436e9 JS |
5485 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
5486 | if (!pmb) { | |
5487 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5488 | "2011 Unable to allocate memory for issuing " | |
5489 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
5490 | return -ENOMEM; | |
3772a991 JS |
5491 | } |
5492 | ||
da0436e9 | 5493 | lpfc_read_config(phba, pmb); |
3772a991 | 5494 | |
da0436e9 JS |
5495 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
5496 | if (rc != MBX_SUCCESS) { | |
5497 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5498 | "2012 Mailbox failed , mbxCmd x%x " | |
5499 | "READ_CONFIG, mbxStatus x%x\n", | |
5500 | bf_get(lpfc_mqe_command, &pmb->u.mqe), | |
5501 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); | |
5502 | rc = -EIO; | |
5503 | } else { | |
5504 | rd_config = &pmb->u.mqe.un.rd_config; | |
5505 | phba->sli4_hba.max_cfg_param.max_xri = | |
5506 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); | |
5507 | phba->sli4_hba.max_cfg_param.xri_base = | |
5508 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); | |
5509 | phba->sli4_hba.max_cfg_param.max_vpi = | |
5510 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); | |
5511 | phba->sli4_hba.max_cfg_param.vpi_base = | |
5512 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); | |
5513 | phba->sli4_hba.max_cfg_param.max_rpi = | |
5514 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); | |
5515 | phba->sli4_hba.max_cfg_param.rpi_base = | |
5516 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); | |
5517 | phba->sli4_hba.max_cfg_param.max_vfi = | |
5518 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); | |
5519 | phba->sli4_hba.max_cfg_param.vfi_base = | |
5520 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); | |
5521 | phba->sli4_hba.max_cfg_param.max_fcfi = | |
5522 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); | |
5523 | phba->sli4_hba.max_cfg_param.fcfi_base = | |
5524 | bf_get(lpfc_mbx_rd_conf_fcfi_base, rd_config); | |
5525 | phba->sli4_hba.max_cfg_param.max_eq = | |
5526 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); | |
5527 | phba->sli4_hba.max_cfg_param.max_rq = | |
5528 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); | |
5529 | phba->sli4_hba.max_cfg_param.max_wq = | |
5530 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); | |
5531 | phba->sli4_hba.max_cfg_param.max_cq = | |
5532 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); | |
5533 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); | |
5534 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; | |
5535 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; | |
5536 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; | |
5537 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base; | |
5ffc266e JS |
5538 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
5539 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; | |
da0436e9 JS |
5540 | phba->max_vports = phba->max_vpi; |
5541 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
5542 | "2003 cfg params XRI(B:%d M:%d), " | |
5543 | "VPI(B:%d M:%d) " | |
5544 | "VFI(B:%d M:%d) " | |
5545 | "RPI(B:%d M:%d) " | |
5546 | "FCFI(B:%d M:%d)\n", | |
5547 | phba->sli4_hba.max_cfg_param.xri_base, | |
5548 | phba->sli4_hba.max_cfg_param.max_xri, | |
5549 | phba->sli4_hba.max_cfg_param.vpi_base, | |
5550 | phba->sli4_hba.max_cfg_param.max_vpi, | |
5551 | phba->sli4_hba.max_cfg_param.vfi_base, | |
5552 | phba->sli4_hba.max_cfg_param.max_vfi, | |
5553 | phba->sli4_hba.max_cfg_param.rpi_base, | |
5554 | phba->sli4_hba.max_cfg_param.max_rpi, | |
5555 | phba->sli4_hba.max_cfg_param.fcfi_base, | |
5556 | phba->sli4_hba.max_cfg_param.max_fcfi); | |
3772a991 | 5557 | } |
da0436e9 JS |
5558 | mempool_free(pmb, phba->mbox_mem_pool); |
5559 | ||
5560 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ | |
b92938b4 JS |
5561 | if (phba->cfg_hba_queue_depth > |
5562 | (phba->sli4_hba.max_cfg_param.max_xri - | |
5563 | lpfc_sli4_get_els_iocb_cnt(phba))) | |
da0436e9 | 5564 | phba->cfg_hba_queue_depth = |
b92938b4 JS |
5565 | phba->sli4_hba.max_cfg_param.max_xri - |
5566 | lpfc_sli4_get_els_iocb_cnt(phba); | |
da0436e9 | 5567 | return rc; |
3772a991 JS |
5568 | } |
5569 | ||
5570 | /** | |
da0436e9 | 5571 | * lpfc_dev_endian_order_setup - Notify the port of the host's endian order. |
3772a991 JS |
5572 | * @phba: pointer to lpfc hba data structure. |
5573 | * | |
da0436e9 JS |
5574 | * This routine is invoked to setup the host-side endian order to the |
5575 | * HBA consistent with the SLI-4 interface spec. | |
5576 | * | |
5577 | * Return codes | |
af901ca1 | 5578 | * 0 - successful |
d439d286 JS |
5579 | * -ENOMEM - No availble memory |
5580 | * -EIO - The mailbox failed to complete successfully. | |
3772a991 | 5581 | **/ |
da0436e9 JS |
5582 | static int |
5583 | lpfc_setup_endian_order(struct lpfc_hba *phba) | |
3772a991 | 5584 | { |
da0436e9 JS |
5585 | LPFC_MBOXQ_t *mboxq; |
5586 | uint32_t rc = 0; | |
5587 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, | |
5588 | HOST_ENDIAN_HIGH_WORD1}; | |
3772a991 | 5589 | |
da0436e9 JS |
5590 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
5591 | if (!mboxq) { | |
5592 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5593 | "0492 Unable to allocate memory for issuing " | |
5594 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
5595 | return -ENOMEM; | |
5596 | } | |
3772a991 | 5597 | |
da0436e9 JS |
5598 | /* |
5599 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first two | |
5600 | * words to contain special data values and no other data. | |
5601 | */ | |
5602 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
5603 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); | |
5604 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
5605 | if (rc != MBX_SUCCESS) { | |
5606 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5607 | "0493 SLI_CONFIG_SPECIAL mailbox failed with " | |
5608 | "status x%x\n", | |
5609 | rc); | |
5610 | rc = -EIO; | |
5611 | } | |
5612 | ||
5613 | mempool_free(mboxq, phba->mbox_mem_pool); | |
5614 | return rc; | |
3772a991 JS |
5615 | } |
5616 | ||
5617 | /** | |
da0436e9 | 5618 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
3772a991 JS |
5619 | * @phba: pointer to lpfc hba data structure. |
5620 | * | |
da0436e9 JS |
5621 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
5622 | * operation. For each SLI4 queue type, the parameters such as queue entry | |
5623 | * count (queue depth) shall be taken from the module parameter. For now, | |
5624 | * we just use some constant number as place holder. | |
5625 | * | |
5626 | * Return codes | |
af901ca1 | 5627 | * 0 - successful |
d439d286 JS |
5628 | * -ENOMEM - No availble memory |
5629 | * -EIO - The mailbox failed to complete successfully. | |
3772a991 | 5630 | **/ |
da0436e9 JS |
5631 | static int |
5632 | lpfc_sli4_queue_create(struct lpfc_hba *phba) | |
3772a991 | 5633 | { |
da0436e9 JS |
5634 | struct lpfc_queue *qdesc; |
5635 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; | |
5636 | int cfg_fcp_wq_count; | |
5637 | int cfg_fcp_eq_count; | |
3772a991 | 5638 | |
da0436e9 JS |
5639 | /* |
5640 | * Sanity check for confiugred queue parameters against the run-time | |
5641 | * device parameters | |
5642 | */ | |
3772a991 | 5643 | |
da0436e9 JS |
5644 | /* Sanity check on FCP fast-path WQ parameters */ |
5645 | cfg_fcp_wq_count = phba->cfg_fcp_wq_count; | |
5646 | if (cfg_fcp_wq_count > | |
5647 | (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) { | |
5648 | cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq - | |
5649 | LPFC_SP_WQN_DEF; | |
5650 | if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) { | |
5651 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5652 | "2581 Not enough WQs (%d) from " | |
5653 | "the pci function for supporting " | |
5654 | "FCP WQs (%d)\n", | |
5655 | phba->sli4_hba.max_cfg_param.max_wq, | |
5656 | phba->cfg_fcp_wq_count); | |
5657 | goto out_error; | |
5658 | } | |
5659 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
5660 | "2582 Not enough WQs (%d) from the pci " | |
5661 | "function for supporting the requested " | |
5662 | "FCP WQs (%d), the actual FCP WQs can " | |
5663 | "be supported: %d\n", | |
5664 | phba->sli4_hba.max_cfg_param.max_wq, | |
5665 | phba->cfg_fcp_wq_count, cfg_fcp_wq_count); | |
5666 | } | |
5667 | /* The actual number of FCP work queues adopted */ | |
5668 | phba->cfg_fcp_wq_count = cfg_fcp_wq_count; | |
5669 | ||
5670 | /* Sanity check on FCP fast-path EQ parameters */ | |
5671 | cfg_fcp_eq_count = phba->cfg_fcp_eq_count; | |
5672 | if (cfg_fcp_eq_count > | |
5673 | (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) { | |
5674 | cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq - | |
5675 | LPFC_SP_EQN_DEF; | |
5676 | if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) { | |
5677 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5678 | "2574 Not enough EQs (%d) from the " | |
5679 | "pci function for supporting FCP " | |
5680 | "EQs (%d)\n", | |
5681 | phba->sli4_hba.max_cfg_param.max_eq, | |
5682 | phba->cfg_fcp_eq_count); | |
5683 | goto out_error; | |
5684 | } | |
5685 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
5686 | "2575 Not enough EQs (%d) from the pci " | |
5687 | "function for supporting the requested " | |
5688 | "FCP EQs (%d), the actual FCP EQs can " | |
5689 | "be supported: %d\n", | |
5690 | phba->sli4_hba.max_cfg_param.max_eq, | |
5691 | phba->cfg_fcp_eq_count, cfg_fcp_eq_count); | |
5692 | } | |
5693 | /* It does not make sense to have more EQs than WQs */ | |
5694 | if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) { | |
5695 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6a9c52cf JS |
5696 | "2593 The FCP EQ count(%d) cannot be greater " |
5697 | "than the FCP WQ count(%d), limiting the " | |
5698 | "FCP EQ count to %d\n", cfg_fcp_eq_count, | |
da0436e9 JS |
5699 | phba->cfg_fcp_wq_count, |
5700 | phba->cfg_fcp_wq_count); | |
5701 | cfg_fcp_eq_count = phba->cfg_fcp_wq_count; | |
5702 | } | |
5703 | /* The actual number of FCP event queues adopted */ | |
5704 | phba->cfg_fcp_eq_count = cfg_fcp_eq_count; | |
5705 | /* The overall number of event queues used */ | |
5706 | phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF; | |
3772a991 | 5707 | |
da0436e9 JS |
5708 | /* |
5709 | * Create Event Queues (EQs) | |
5710 | */ | |
3772a991 | 5711 | |
da0436e9 JS |
5712 | /* Get EQ depth from module parameter, fake the default for now */ |
5713 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; | |
5714 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; | |
3772a991 | 5715 | |
da0436e9 JS |
5716 | /* Create slow path event queue */ |
5717 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | |
5718 | phba->sli4_hba.eq_ecount); | |
5719 | if (!qdesc) { | |
5720 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5721 | "0496 Failed allocate slow-path EQ\n"); | |
5722 | goto out_error; | |
5723 | } | |
5724 | phba->sli4_hba.sp_eq = qdesc; | |
5725 | ||
5726 | /* Create fast-path FCP Event Queue(s) */ | |
5727 | phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) * | |
5728 | phba->cfg_fcp_eq_count), GFP_KERNEL); | |
5729 | if (!phba->sli4_hba.fp_eq) { | |
5730 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5731 | "2576 Failed allocate memory for fast-path " | |
5732 | "EQ record array\n"); | |
5733 | goto out_free_sp_eq; | |
5734 | } | |
5735 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
5736 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | |
5737 | phba->sli4_hba.eq_ecount); | |
5738 | if (!qdesc) { | |
5739 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5740 | "0497 Failed allocate fast-path EQ\n"); | |
5741 | goto out_free_fp_eq; | |
5742 | } | |
5743 | phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc; | |
5744 | } | |
5745 | ||
5746 | /* | |
5747 | * Create Complete Queues (CQs) | |
5748 | */ | |
5749 | ||
5750 | /* Get CQ depth from module parameter, fake the default for now */ | |
5751 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; | |
5752 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; | |
5753 | ||
5754 | /* Create slow-path Mailbox Command Complete Queue */ | |
5755 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
5756 | phba->sli4_hba.cq_ecount); | |
5757 | if (!qdesc) { | |
5758 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5759 | "0500 Failed allocate slow-path mailbox CQ\n"); | |
5760 | goto out_free_fp_eq; | |
5761 | } | |
5762 | phba->sli4_hba.mbx_cq = qdesc; | |
5763 | ||
5764 | /* Create slow-path ELS Complete Queue */ | |
5765 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
5766 | phba->sli4_hba.cq_ecount); | |
5767 | if (!qdesc) { | |
5768 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5769 | "0501 Failed allocate slow-path ELS CQ\n"); | |
5770 | goto out_free_mbx_cq; | |
5771 | } | |
5772 | phba->sli4_hba.els_cq = qdesc; | |
5773 | ||
da0436e9 JS |
5774 | |
5775 | /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */ | |
5776 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * | |
5777 | phba->cfg_fcp_eq_count), GFP_KERNEL); | |
5778 | if (!phba->sli4_hba.fcp_cq) { | |
5779 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5780 | "2577 Failed allocate memory for fast-path " | |
5781 | "CQ record array\n"); | |
4d9ab994 | 5782 | goto out_free_els_cq; |
da0436e9 JS |
5783 | } |
5784 | for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) { | |
5785 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
5786 | phba->sli4_hba.cq_ecount); | |
5787 | if (!qdesc) { | |
5788 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5789 | "0499 Failed allocate fast-path FCP " | |
5790 | "CQ (%d)\n", fcp_cqidx); | |
5791 | goto out_free_fcp_cq; | |
5792 | } | |
5793 | phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc; | |
5794 | } | |
5795 | ||
5796 | /* Create Mailbox Command Queue */ | |
5797 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; | |
5798 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; | |
5799 | ||
5800 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, | |
5801 | phba->sli4_hba.mq_ecount); | |
5802 | if (!qdesc) { | |
5803 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5804 | "0505 Failed allocate slow-path MQ\n"); | |
5805 | goto out_free_fcp_cq; | |
5806 | } | |
5807 | phba->sli4_hba.mbx_wq = qdesc; | |
5808 | ||
5809 | /* | |
5810 | * Create all the Work Queues (WQs) | |
5811 | */ | |
5812 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; | |
5813 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; | |
5814 | ||
5815 | /* Create slow-path ELS Work Queue */ | |
5816 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
5817 | phba->sli4_hba.wq_ecount); | |
5818 | if (!qdesc) { | |
5819 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5820 | "0504 Failed allocate slow-path ELS WQ\n"); | |
5821 | goto out_free_mbx_wq; | |
5822 | } | |
5823 | phba->sli4_hba.els_wq = qdesc; | |
5824 | ||
5825 | /* Create fast-path FCP Work Queue(s) */ | |
5826 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * | |
5827 | phba->cfg_fcp_wq_count), GFP_KERNEL); | |
5828 | if (!phba->sli4_hba.fcp_wq) { | |
5829 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5830 | "2578 Failed allocate memory for fast-path " | |
5831 | "WQ record array\n"); | |
5832 | goto out_free_els_wq; | |
5833 | } | |
5834 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { | |
5835 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
5836 | phba->sli4_hba.wq_ecount); | |
5837 | if (!qdesc) { | |
5838 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5839 | "0503 Failed allocate fast-path FCP " | |
5840 | "WQ (%d)\n", fcp_wqidx); | |
5841 | goto out_free_fcp_wq; | |
5842 | } | |
5843 | phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc; | |
5844 | } | |
5845 | ||
5846 | /* | |
5847 | * Create Receive Queue (RQ) | |
5848 | */ | |
5849 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; | |
5850 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; | |
5851 | ||
5852 | /* Create Receive Queue for header */ | |
5853 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
5854 | phba->sli4_hba.rq_ecount); | |
5855 | if (!qdesc) { | |
5856 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5857 | "0506 Failed allocate receive HRQ\n"); | |
5858 | goto out_free_fcp_wq; | |
5859 | } | |
5860 | phba->sli4_hba.hdr_rq = qdesc; | |
5861 | ||
5862 | /* Create Receive Queue for data */ | |
5863 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
5864 | phba->sli4_hba.rq_ecount); | |
5865 | if (!qdesc) { | |
5866 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5867 | "0507 Failed allocate receive DRQ\n"); | |
5868 | goto out_free_hdr_rq; | |
5869 | } | |
5870 | phba->sli4_hba.dat_rq = qdesc; | |
5871 | ||
5872 | return 0; | |
5873 | ||
5874 | out_free_hdr_rq: | |
5875 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); | |
5876 | phba->sli4_hba.hdr_rq = NULL; | |
5877 | out_free_fcp_wq: | |
5878 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) { | |
5879 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]); | |
5880 | phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL; | |
5881 | } | |
5882 | kfree(phba->sli4_hba.fcp_wq); | |
5883 | out_free_els_wq: | |
5884 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); | |
5885 | phba->sli4_hba.els_wq = NULL; | |
5886 | out_free_mbx_wq: | |
5887 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); | |
5888 | phba->sli4_hba.mbx_wq = NULL; | |
5889 | out_free_fcp_cq: | |
5890 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) { | |
5891 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]); | |
5892 | phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL; | |
5893 | } | |
5894 | kfree(phba->sli4_hba.fcp_cq); | |
da0436e9 JS |
5895 | out_free_els_cq: |
5896 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); | |
5897 | phba->sli4_hba.els_cq = NULL; | |
5898 | out_free_mbx_cq: | |
5899 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); | |
5900 | phba->sli4_hba.mbx_cq = NULL; | |
5901 | out_free_fp_eq: | |
5902 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) { | |
5903 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]); | |
5904 | phba->sli4_hba.fp_eq[fcp_eqidx] = NULL; | |
5905 | } | |
5906 | kfree(phba->sli4_hba.fp_eq); | |
5907 | out_free_sp_eq: | |
5908 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); | |
5909 | phba->sli4_hba.sp_eq = NULL; | |
5910 | out_error: | |
5911 | return -ENOMEM; | |
5912 | } | |
5913 | ||
5914 | /** | |
5915 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues | |
5916 | * @phba: pointer to lpfc hba data structure. | |
5917 | * | |
5918 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA | |
5919 | * operation. | |
5920 | * | |
5921 | * Return codes | |
af901ca1 | 5922 | * 0 - successful |
d439d286 JS |
5923 | * -ENOMEM - No availble memory |
5924 | * -EIO - The mailbox failed to complete successfully. | |
da0436e9 JS |
5925 | **/ |
5926 | static void | |
5927 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) | |
5928 | { | |
5929 | int fcp_qidx; | |
5930 | ||
5931 | /* Release mailbox command work queue */ | |
5932 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); | |
5933 | phba->sli4_hba.mbx_wq = NULL; | |
5934 | ||
5935 | /* Release ELS work queue */ | |
5936 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); | |
5937 | phba->sli4_hba.els_wq = NULL; | |
5938 | ||
5939 | /* Release FCP work queue */ | |
5940 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) | |
5941 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]); | |
5942 | kfree(phba->sli4_hba.fcp_wq); | |
5943 | phba->sli4_hba.fcp_wq = NULL; | |
5944 | ||
5945 | /* Release unsolicited receive queue */ | |
5946 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); | |
5947 | phba->sli4_hba.hdr_rq = NULL; | |
5948 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); | |
5949 | phba->sli4_hba.dat_rq = NULL; | |
5950 | ||
da0436e9 JS |
5951 | /* Release ELS complete queue */ |
5952 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); | |
5953 | phba->sli4_hba.els_cq = NULL; | |
5954 | ||
5955 | /* Release mailbox command complete queue */ | |
5956 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); | |
5957 | phba->sli4_hba.mbx_cq = NULL; | |
5958 | ||
5959 | /* Release FCP response complete queue */ | |
5960 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | |
5961 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]); | |
5962 | kfree(phba->sli4_hba.fcp_cq); | |
5963 | phba->sli4_hba.fcp_cq = NULL; | |
5964 | ||
5965 | /* Release fast-path event queue */ | |
5966 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | |
5967 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]); | |
5968 | kfree(phba->sli4_hba.fp_eq); | |
5969 | phba->sli4_hba.fp_eq = NULL; | |
5970 | ||
5971 | /* Release slow-path event queue */ | |
5972 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); | |
5973 | phba->sli4_hba.sp_eq = NULL; | |
5974 | ||
5975 | return; | |
5976 | } | |
5977 | ||
5978 | /** | |
5979 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues | |
5980 | * @phba: pointer to lpfc hba data structure. | |
5981 | * | |
5982 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA | |
5983 | * operation. | |
5984 | * | |
5985 | * Return codes | |
af901ca1 | 5986 | * 0 - successful |
d439d286 JS |
5987 | * -ENOMEM - No availble memory |
5988 | * -EIO - The mailbox failed to complete successfully. | |
da0436e9 JS |
5989 | **/ |
5990 | int | |
5991 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) | |
5992 | { | |
5993 | int rc = -ENOMEM; | |
5994 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; | |
5995 | int fcp_cq_index = 0; | |
5996 | ||
5997 | /* | |
5998 | * Set up Event Queues (EQs) | |
5999 | */ | |
6000 | ||
6001 | /* Set up slow-path event queue */ | |
6002 | if (!phba->sli4_hba.sp_eq) { | |
6003 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6004 | "0520 Slow-path EQ not allocated\n"); | |
6005 | goto out_error; | |
6006 | } | |
6007 | rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq, | |
6008 | LPFC_SP_DEF_IMAX); | |
6009 | if (rc) { | |
6010 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6011 | "0521 Failed setup of slow-path EQ: " | |
6012 | "rc = 0x%x\n", rc); | |
6013 | goto out_error; | |
6014 | } | |
6015 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6016 | "2583 Slow-path EQ setup: queue-id=%d\n", | |
6017 | phba->sli4_hba.sp_eq->queue_id); | |
6018 | ||
6019 | /* Set up fast-path event queue */ | |
6020 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
6021 | if (!phba->sli4_hba.fp_eq[fcp_eqidx]) { | |
6022 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6023 | "0522 Fast-path EQ (%d) not " | |
6024 | "allocated\n", fcp_eqidx); | |
6025 | goto out_destroy_fp_eq; | |
6026 | } | |
6027 | rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx], | |
6028 | phba->cfg_fcp_imax); | |
6029 | if (rc) { | |
6030 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6031 | "0523 Failed setup of fast-path EQ " | |
6032 | "(%d), rc = 0x%x\n", fcp_eqidx, rc); | |
6033 | goto out_destroy_fp_eq; | |
6034 | } | |
6035 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6036 | "2584 Fast-path EQ setup: " | |
6037 | "queue[%d]-id=%d\n", fcp_eqidx, | |
6038 | phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id); | |
6039 | } | |
6040 | ||
6041 | /* | |
6042 | * Set up Complete Queues (CQs) | |
6043 | */ | |
6044 | ||
6045 | /* Set up slow-path MBOX Complete Queue as the first CQ */ | |
6046 | if (!phba->sli4_hba.mbx_cq) { | |
6047 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6048 | "0528 Mailbox CQ not allocated\n"); | |
6049 | goto out_destroy_fp_eq; | |
6050 | } | |
6051 | rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq, | |
6052 | LPFC_MCQ, LPFC_MBOX); | |
6053 | if (rc) { | |
6054 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6055 | "0529 Failed setup of slow-path mailbox CQ: " | |
6056 | "rc = 0x%x\n", rc); | |
6057 | goto out_destroy_fp_eq; | |
6058 | } | |
6059 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6060 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", | |
6061 | phba->sli4_hba.mbx_cq->queue_id, | |
6062 | phba->sli4_hba.sp_eq->queue_id); | |
6063 | ||
6064 | /* Set up slow-path ELS Complete Queue */ | |
6065 | if (!phba->sli4_hba.els_cq) { | |
6066 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6067 | "0530 ELS CQ not allocated\n"); | |
6068 | goto out_destroy_mbx_cq; | |
6069 | } | |
6070 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq, | |
6071 | LPFC_WCQ, LPFC_ELS); | |
6072 | if (rc) { | |
6073 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6074 | "0531 Failed setup of slow-path ELS CQ: " | |
6075 | "rc = 0x%x\n", rc); | |
6076 | goto out_destroy_mbx_cq; | |
6077 | } | |
6078 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6079 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", | |
6080 | phba->sli4_hba.els_cq->queue_id, | |
6081 | phba->sli4_hba.sp_eq->queue_id); | |
6082 | ||
da0436e9 JS |
6083 | /* Set up fast-path FCP Response Complete Queue */ |
6084 | for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) { | |
6085 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { | |
6086 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6087 | "0526 Fast-path FCP CQ (%d) not " | |
6088 | "allocated\n", fcp_cqidx); | |
6089 | goto out_destroy_fcp_cq; | |
6090 | } | |
6091 | rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx], | |
6092 | phba->sli4_hba.fp_eq[fcp_cqidx], | |
6093 | LPFC_WCQ, LPFC_FCP); | |
6094 | if (rc) { | |
6095 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6096 | "0527 Failed setup of fast-path FCP " | |
6097 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc); | |
6098 | goto out_destroy_fcp_cq; | |
6099 | } | |
6100 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6101 | "2588 FCP CQ setup: cq[%d]-id=%d, " | |
6102 | "parent eq[%d]-id=%d\n", | |
6103 | fcp_cqidx, | |
6104 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, | |
6105 | fcp_cqidx, | |
6106 | phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id); | |
6107 | } | |
6108 | ||
6109 | /* | |
6110 | * Set up all the Work Queues (WQs) | |
6111 | */ | |
6112 | ||
6113 | /* Set up Mailbox Command Queue */ | |
6114 | if (!phba->sli4_hba.mbx_wq) { | |
6115 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6116 | "0538 Slow-path MQ not allocated\n"); | |
6117 | goto out_destroy_fcp_cq; | |
6118 | } | |
6119 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, | |
6120 | phba->sli4_hba.mbx_cq, LPFC_MBOX); | |
6121 | if (rc) { | |
6122 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6123 | "0539 Failed setup of slow-path MQ: " | |
6124 | "rc = 0x%x\n", rc); | |
6125 | goto out_destroy_fcp_cq; | |
6126 | } | |
6127 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6128 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", | |
6129 | phba->sli4_hba.mbx_wq->queue_id, | |
6130 | phba->sli4_hba.mbx_cq->queue_id); | |
6131 | ||
6132 | /* Set up slow-path ELS Work Queue */ | |
6133 | if (!phba->sli4_hba.els_wq) { | |
6134 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6135 | "0536 Slow-path ELS WQ not allocated\n"); | |
6136 | goto out_destroy_mbx_wq; | |
6137 | } | |
6138 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, | |
6139 | phba->sli4_hba.els_cq, LPFC_ELS); | |
6140 | if (rc) { | |
6141 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6142 | "0537 Failed setup of slow-path ELS WQ: " | |
6143 | "rc = 0x%x\n", rc); | |
6144 | goto out_destroy_mbx_wq; | |
6145 | } | |
6146 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6147 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", | |
6148 | phba->sli4_hba.els_wq->queue_id, | |
6149 | phba->sli4_hba.els_cq->queue_id); | |
6150 | ||
6151 | /* Set up fast-path FCP Work Queue */ | |
6152 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { | |
6153 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { | |
6154 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6155 | "0534 Fast-path FCP WQ (%d) not " | |
6156 | "allocated\n", fcp_wqidx); | |
6157 | goto out_destroy_fcp_wq; | |
6158 | } | |
6159 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], | |
6160 | phba->sli4_hba.fcp_cq[fcp_cq_index], | |
6161 | LPFC_FCP); | |
6162 | if (rc) { | |
6163 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6164 | "0535 Failed setup of fast-path FCP " | |
6165 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc); | |
6166 | goto out_destroy_fcp_wq; | |
6167 | } | |
6168 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6169 | "2591 FCP WQ setup: wq[%d]-id=%d, " | |
6170 | "parent cq[%d]-id=%d\n", | |
6171 | fcp_wqidx, | |
6172 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, | |
6173 | fcp_cq_index, | |
6174 | phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id); | |
6175 | /* Round robin FCP Work Queue's Completion Queue assignment */ | |
6176 | fcp_cq_index = ((fcp_cq_index + 1) % phba->cfg_fcp_eq_count); | |
6177 | } | |
6178 | ||
6179 | /* | |
6180 | * Create Receive Queue (RQ) | |
6181 | */ | |
6182 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { | |
6183 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6184 | "0540 Receive Queue not allocated\n"); | |
6185 | goto out_destroy_fcp_wq; | |
6186 | } | |
6187 | rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, | |
4d9ab994 | 6188 | phba->sli4_hba.els_cq, LPFC_USOL); |
da0436e9 JS |
6189 | if (rc) { |
6190 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6191 | "0541 Failed setup of Receive Queue: " | |
6192 | "rc = 0x%x\n", rc); | |
6193 | goto out_destroy_fcp_wq; | |
6194 | } | |
6195 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6196 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " | |
6197 | "parent cq-id=%d\n", | |
6198 | phba->sli4_hba.hdr_rq->queue_id, | |
6199 | phba->sli4_hba.dat_rq->queue_id, | |
4d9ab994 | 6200 | phba->sli4_hba.els_cq->queue_id); |
da0436e9 JS |
6201 | return 0; |
6202 | ||
6203 | out_destroy_fcp_wq: | |
6204 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) | |
6205 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); | |
6206 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); | |
6207 | out_destroy_mbx_wq: | |
6208 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | |
6209 | out_destroy_fcp_cq: | |
6210 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) | |
6211 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); | |
da0436e9 JS |
6212 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
6213 | out_destroy_mbx_cq: | |
6214 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | |
6215 | out_destroy_fp_eq: | |
6216 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) | |
6217 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]); | |
6218 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); | |
6219 | out_error: | |
6220 | return rc; | |
6221 | } | |
6222 | ||
6223 | /** | |
6224 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues | |
6225 | * @phba: pointer to lpfc hba data structure. | |
6226 | * | |
6227 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA | |
6228 | * operation. | |
6229 | * | |
6230 | * Return codes | |
af901ca1 | 6231 | * 0 - successful |
d439d286 JS |
6232 | * -ENOMEM - No availble memory |
6233 | * -EIO - The mailbox failed to complete successfully. | |
da0436e9 JS |
6234 | **/ |
6235 | void | |
6236 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) | |
6237 | { | |
6238 | int fcp_qidx; | |
6239 | ||
6240 | /* Unset mailbox command work queue */ | |
6241 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | |
6242 | /* Unset ELS work queue */ | |
6243 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); | |
6244 | /* Unset unsolicited receive queue */ | |
6245 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); | |
6246 | /* Unset FCP work queue */ | |
6247 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) | |
6248 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); | |
6249 | /* Unset mailbox command complete queue */ | |
6250 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | |
6251 | /* Unset ELS complete queue */ | |
6252 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); | |
da0436e9 JS |
6253 | /* Unset FCP response complete queue */ |
6254 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | |
6255 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); | |
6256 | /* Unset fast-path event queue */ | |
6257 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | |
6258 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]); | |
6259 | /* Unset slow-path event queue */ | |
6260 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); | |
6261 | } | |
6262 | ||
6263 | /** | |
6264 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool | |
6265 | * @phba: pointer to lpfc hba data structure. | |
6266 | * | |
6267 | * This routine is invoked to allocate and set up a pool of completion queue | |
6268 | * events. The body of the completion queue event is a completion queue entry | |
6269 | * CQE. For now, this pool is used for the interrupt service routine to queue | |
6270 | * the following HBA completion queue events for the worker thread to process: | |
6271 | * - Mailbox asynchronous events | |
6272 | * - Receive queue completion unsolicited events | |
6273 | * Later, this can be used for all the slow-path events. | |
6274 | * | |
6275 | * Return codes | |
af901ca1 | 6276 | * 0 - successful |
da0436e9 JS |
6277 | * -ENOMEM - No availble memory |
6278 | **/ | |
6279 | static int | |
6280 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) | |
6281 | { | |
6282 | struct lpfc_cq_event *cq_event; | |
6283 | int i; | |
6284 | ||
6285 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { | |
6286 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); | |
6287 | if (!cq_event) | |
6288 | goto out_pool_create_fail; | |
6289 | list_add_tail(&cq_event->list, | |
6290 | &phba->sli4_hba.sp_cqe_event_pool); | |
6291 | } | |
6292 | return 0; | |
6293 | ||
6294 | out_pool_create_fail: | |
6295 | lpfc_sli4_cq_event_pool_destroy(phba); | |
6296 | return -ENOMEM; | |
6297 | } | |
6298 | ||
6299 | /** | |
6300 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool | |
6301 | * @phba: pointer to lpfc hba data structure. | |
6302 | * | |
6303 | * This routine is invoked to free the pool of completion queue events at | |
6304 | * driver unload time. Note that, it is the responsibility of the driver | |
6305 | * cleanup routine to free all the outstanding completion-queue events | |
6306 | * allocated from this pool back into the pool before invoking this routine | |
6307 | * to destroy the pool. | |
6308 | **/ | |
6309 | static void | |
6310 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) | |
6311 | { | |
6312 | struct lpfc_cq_event *cq_event, *next_cq_event; | |
6313 | ||
6314 | list_for_each_entry_safe(cq_event, next_cq_event, | |
6315 | &phba->sli4_hba.sp_cqe_event_pool, list) { | |
6316 | list_del(&cq_event->list); | |
6317 | kfree(cq_event); | |
6318 | } | |
6319 | } | |
6320 | ||
6321 | /** | |
6322 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
6323 | * @phba: pointer to lpfc hba data structure. | |
6324 | * | |
6325 | * This routine is the lock free version of the API invoked to allocate a | |
6326 | * completion-queue event from the free pool. | |
6327 | * | |
6328 | * Return: Pointer to the newly allocated completion-queue event if successful | |
6329 | * NULL otherwise. | |
6330 | **/ | |
6331 | struct lpfc_cq_event * | |
6332 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
6333 | { | |
6334 | struct lpfc_cq_event *cq_event = NULL; | |
6335 | ||
6336 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, | |
6337 | struct lpfc_cq_event, list); | |
6338 | return cq_event; | |
6339 | } | |
6340 | ||
6341 | /** | |
6342 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
6343 | * @phba: pointer to lpfc hba data structure. | |
6344 | * | |
6345 | * This routine is the lock version of the API invoked to allocate a | |
6346 | * completion-queue event from the free pool. | |
6347 | * | |
6348 | * Return: Pointer to the newly allocated completion-queue event if successful | |
6349 | * NULL otherwise. | |
6350 | **/ | |
6351 | struct lpfc_cq_event * | |
6352 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
6353 | { | |
6354 | struct lpfc_cq_event *cq_event; | |
6355 | unsigned long iflags; | |
6356 | ||
6357 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6358 | cq_event = __lpfc_sli4_cq_event_alloc(phba); | |
6359 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6360 | return cq_event; | |
6361 | } | |
6362 | ||
6363 | /** | |
6364 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
6365 | * @phba: pointer to lpfc hba data structure. | |
6366 | * @cq_event: pointer to the completion queue event to be freed. | |
6367 | * | |
6368 | * This routine is the lock free version of the API invoked to release a | |
6369 | * completion-queue event back into the free pool. | |
6370 | **/ | |
6371 | void | |
6372 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
6373 | struct lpfc_cq_event *cq_event) | |
6374 | { | |
6375 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); | |
6376 | } | |
6377 | ||
6378 | /** | |
6379 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
6380 | * @phba: pointer to lpfc hba data structure. | |
6381 | * @cq_event: pointer to the completion queue event to be freed. | |
6382 | * | |
6383 | * This routine is the lock version of the API invoked to release a | |
6384 | * completion-queue event back into the free pool. | |
6385 | **/ | |
6386 | void | |
6387 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
6388 | struct lpfc_cq_event *cq_event) | |
6389 | { | |
6390 | unsigned long iflags; | |
6391 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6392 | __lpfc_sli4_cq_event_release(phba, cq_event); | |
6393 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6394 | } | |
6395 | ||
6396 | /** | |
6397 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool | |
6398 | * @phba: pointer to lpfc hba data structure. | |
6399 | * | |
6400 | * This routine is to free all the pending completion-queue events to the | |
6401 | * back into the free pool for device reset. | |
6402 | **/ | |
6403 | static void | |
6404 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) | |
6405 | { | |
6406 | LIST_HEAD(cqelist); | |
6407 | struct lpfc_cq_event *cqe; | |
6408 | unsigned long iflags; | |
6409 | ||
6410 | /* Retrieve all the pending WCQEs from pending WCQE lists */ | |
6411 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6412 | /* Pending FCP XRI abort events */ | |
6413 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
6414 | &cqelist); | |
6415 | /* Pending ELS XRI abort events */ | |
6416 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
6417 | &cqelist); | |
6418 | /* Pending asynnc events */ | |
6419 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, | |
6420 | &cqelist); | |
6421 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6422 | ||
6423 | while (!list_empty(&cqelist)) { | |
6424 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); | |
6425 | lpfc_sli4_cq_event_release(phba, cqe); | |
6426 | } | |
6427 | } | |
6428 | ||
6429 | /** | |
6430 | * lpfc_pci_function_reset - Reset pci function. | |
6431 | * @phba: pointer to lpfc hba data structure. | |
6432 | * | |
6433 | * This routine is invoked to request a PCI function reset. It will destroys | |
6434 | * all resources assigned to the PCI function which originates this request. | |
6435 | * | |
6436 | * Return codes | |
af901ca1 | 6437 | * 0 - successful |
d439d286 JS |
6438 | * -ENOMEM - No availble memory |
6439 | * -EIO - The mailbox failed to complete successfully. | |
da0436e9 JS |
6440 | **/ |
6441 | int | |
6442 | lpfc_pci_function_reset(struct lpfc_hba *phba) | |
6443 | { | |
6444 | LPFC_MBOXQ_t *mboxq; | |
6445 | uint32_t rc = 0; | |
6446 | uint32_t shdr_status, shdr_add_status; | |
6447 | union lpfc_sli4_cfg_shdr *shdr; | |
6448 | ||
6449 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6450 | if (!mboxq) { | |
6451 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6452 | "0494 Unable to allocate memory for issuing " | |
6453 | "SLI_FUNCTION_RESET mailbox command\n"); | |
6454 | return -ENOMEM; | |
6455 | } | |
6456 | ||
6457 | /* Set up PCI function reset SLI4_CONFIG mailbox-ioctl command */ | |
6458 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
6459 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, | |
6460 | LPFC_SLI4_MBX_EMBED); | |
6461 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6462 | shdr = (union lpfc_sli4_cfg_shdr *) | |
6463 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
6464 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
6465 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
6466 | if (rc != MBX_TIMEOUT) | |
6467 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6468 | if (shdr_status || shdr_add_status || rc) { | |
6469 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6470 | "0495 SLI_FUNCTION_RESET mailbox failed with " | |
6471 | "status x%x add_status x%x, mbx status x%x\n", | |
6472 | shdr_status, shdr_add_status, rc); | |
6473 | rc = -ENXIO; | |
6474 | } | |
6475 | return rc; | |
6476 | } | |
6477 | ||
6478 | /** | |
6479 | * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands | |
6480 | * @phba: pointer to lpfc hba data structure. | |
6481 | * @cnt: number of nop mailbox commands to send. | |
6482 | * | |
6483 | * This routine is invoked to send a number @cnt of NOP mailbox command and | |
6484 | * wait for each command to complete. | |
6485 | * | |
6486 | * Return: the number of NOP mailbox command completed. | |
6487 | **/ | |
6488 | static int | |
6489 | lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt) | |
6490 | { | |
6491 | LPFC_MBOXQ_t *mboxq; | |
6492 | int length, cmdsent; | |
6493 | uint32_t mbox_tmo; | |
6494 | uint32_t rc = 0; | |
6495 | uint32_t shdr_status, shdr_add_status; | |
6496 | union lpfc_sli4_cfg_shdr *shdr; | |
6497 | ||
6498 | if (cnt == 0) { | |
6499 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6500 | "2518 Requested to send 0 NOP mailbox cmd\n"); | |
6501 | return cnt; | |
6502 | } | |
6503 | ||
6504 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6505 | if (!mboxq) { | |
6506 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6507 | "2519 Unable to allocate memory for issuing " | |
6508 | "NOP mailbox command\n"); | |
6509 | return 0; | |
6510 | } | |
6511 | ||
6512 | /* Set up NOP SLI4_CONFIG mailbox-ioctl command */ | |
6513 | length = (sizeof(struct lpfc_mbx_nop) - | |
6514 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
6515 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
6516 | LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED); | |
6517 | ||
6518 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
6519 | for (cmdsent = 0; cmdsent < cnt; cmdsent++) { | |
6520 | if (!phba->sli4_hba.intr_enable) | |
6521 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6522 | else | |
6523 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
6524 | if (rc == MBX_TIMEOUT) | |
6525 | break; | |
6526 | /* Check return status */ | |
6527 | shdr = (union lpfc_sli4_cfg_shdr *) | |
6528 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
6529 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
6530 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
6531 | &shdr->response); | |
6532 | if (shdr_status || shdr_add_status || rc) { | |
6533 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6534 | "2520 NOP mailbox command failed " | |
6535 | "status x%x add_status x%x mbx " | |
6536 | "status x%x\n", shdr_status, | |
6537 | shdr_add_status, rc); | |
6538 | break; | |
6539 | } | |
6540 | } | |
6541 | ||
6542 | if (rc != MBX_TIMEOUT) | |
6543 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6544 | ||
6545 | return cmdsent; | |
6546 | } | |
6547 | ||
da0436e9 JS |
6548 | /** |
6549 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. | |
6550 | * @phba: pointer to lpfc hba data structure. | |
6551 | * | |
6552 | * This routine is invoked to set up the PCI device memory space for device | |
6553 | * with SLI-4 interface spec. | |
6554 | * | |
6555 | * Return codes | |
af901ca1 | 6556 | * 0 - successful |
da0436e9 JS |
6557 | * other values - error |
6558 | **/ | |
6559 | static int | |
6560 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) | |
6561 | { | |
6562 | struct pci_dev *pdev; | |
6563 | unsigned long bar0map_len, bar1map_len, bar2map_len; | |
6564 | int error = -ENODEV; | |
6565 | ||
6566 | /* Obtain PCI device reference */ | |
6567 | if (!phba->pcidev) | |
6568 | return error; | |
6569 | else | |
6570 | pdev = phba->pcidev; | |
6571 | ||
6572 | /* Set the device DMA mask size */ | |
8e68597d MR |
6573 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
6574 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
6575 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
6576 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
da0436e9 | 6577 | return error; |
8e68597d MR |
6578 | } |
6579 | } | |
da0436e9 JS |
6580 | |
6581 | /* Get the bus address of SLI4 device Bar0, Bar1, and Bar2 and the | |
6582 | * number of bytes required by each mapping. They are actually | |
1dfb5a47 | 6583 | * mapping to the PCI BAR regions 0 or 1, 2, and 4 by the SLI4 device. |
da0436e9 | 6584 | */ |
1dfb5a47 JS |
6585 | if (pci_resource_start(pdev, 0)) { |
6586 | phba->pci_bar0_map = pci_resource_start(pdev, 0); | |
6587 | bar0map_len = pci_resource_len(pdev, 0); | |
6588 | } else { | |
6589 | phba->pci_bar0_map = pci_resource_start(pdev, 1); | |
6590 | bar0map_len = pci_resource_len(pdev, 1); | |
6591 | } | |
6592 | phba->pci_bar1_map = pci_resource_start(pdev, 2); | |
6593 | bar1map_len = pci_resource_len(pdev, 2); | |
da0436e9 | 6594 | |
1dfb5a47 JS |
6595 | phba->pci_bar2_map = pci_resource_start(pdev, 4); |
6596 | bar2map_len = pci_resource_len(pdev, 4); | |
da0436e9 JS |
6597 | |
6598 | /* Map SLI4 PCI Config Space Register base to a kernel virtual addr */ | |
6599 | phba->sli4_hba.conf_regs_memmap_p = | |
6600 | ioremap(phba->pci_bar0_map, bar0map_len); | |
6601 | if (!phba->sli4_hba.conf_regs_memmap_p) { | |
6602 | dev_printk(KERN_ERR, &pdev->dev, | |
6603 | "ioremap failed for SLI4 PCI config registers.\n"); | |
6604 | goto out; | |
6605 | } | |
6606 | ||
6607 | /* Map SLI4 HBA Control Register base to a kernel virtual address. */ | |
6608 | phba->sli4_hba.ctrl_regs_memmap_p = | |
6609 | ioremap(phba->pci_bar1_map, bar1map_len); | |
6610 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { | |
6611 | dev_printk(KERN_ERR, &pdev->dev, | |
6612 | "ioremap failed for SLI4 HBA control registers.\n"); | |
6613 | goto out_iounmap_conf; | |
6614 | } | |
6615 | ||
6616 | /* Map SLI4 HBA Doorbell Register base to a kernel virtual address. */ | |
6617 | phba->sli4_hba.drbl_regs_memmap_p = | |
6618 | ioremap(phba->pci_bar2_map, bar2map_len); | |
6619 | if (!phba->sli4_hba.drbl_regs_memmap_p) { | |
6620 | dev_printk(KERN_ERR, &pdev->dev, | |
6621 | "ioremap failed for SLI4 HBA doorbell registers.\n"); | |
6622 | goto out_iounmap_ctrl; | |
6623 | } | |
6624 | ||
6625 | /* Set up BAR0 PCI config space register memory map */ | |
6626 | lpfc_sli4_bar0_register_memmap(phba); | |
6627 | ||
6628 | /* Set up BAR1 register memory map */ | |
6629 | lpfc_sli4_bar1_register_memmap(phba); | |
6630 | ||
6631 | /* Set up BAR2 register memory map */ | |
6632 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); | |
6633 | if (error) | |
6634 | goto out_iounmap_all; | |
6635 | ||
6636 | return 0; | |
6637 | ||
6638 | out_iounmap_all: | |
6639 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
6640 | out_iounmap_ctrl: | |
6641 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
6642 | out_iounmap_conf: | |
6643 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
6644 | out: | |
6645 | return error; | |
6646 | } | |
6647 | ||
6648 | /** | |
6649 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. | |
6650 | * @phba: pointer to lpfc hba data structure. | |
6651 | * | |
6652 | * This routine is invoked to unset the PCI device memory space for device | |
6653 | * with SLI-4 interface spec. | |
6654 | **/ | |
6655 | static void | |
6656 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) | |
6657 | { | |
6658 | struct pci_dev *pdev; | |
6659 | ||
6660 | /* Obtain PCI device reference */ | |
6661 | if (!phba->pcidev) | |
6662 | return; | |
6663 | else | |
6664 | pdev = phba->pcidev; | |
6665 | ||
6666 | /* Free coherent DMA memory allocated */ | |
6667 | ||
6668 | /* Unmap I/O memory space */ | |
6669 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
6670 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
6671 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
6672 | ||
6673 | return; | |
6674 | } | |
6675 | ||
6676 | /** | |
6677 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device | |
6678 | * @phba: pointer to lpfc hba data structure. | |
6679 | * | |
6680 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
6681 | * with SLI-3 interface specs. The kernel function pci_enable_msix() is | |
6682 | * called to enable the MSI-X vectors. Note that pci_enable_msix(), once | |
6683 | * invoked, enables either all or nothing, depending on the current | |
6684 | * availability of PCI vector resources. The device driver is responsible | |
6685 | * for calling the individual request_irq() to register each MSI-X vector | |
6686 | * with a interrupt handler, which is done in this function. Note that | |
6687 | * later when device is unloading, the driver should always call free_irq() | |
6688 | * on all MSI-X vectors it has done request_irq() on before calling | |
6689 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device | |
6690 | * will be left with MSI-X enabled and leaks its vectors. | |
6691 | * | |
6692 | * Return codes | |
af901ca1 | 6693 | * 0 - successful |
da0436e9 JS |
6694 | * other values - error |
6695 | **/ | |
6696 | static int | |
6697 | lpfc_sli_enable_msix(struct lpfc_hba *phba) | |
6698 | { | |
6699 | int rc, i; | |
6700 | LPFC_MBOXQ_t *pmb; | |
6701 | ||
6702 | /* Set up MSI-X multi-message vectors */ | |
6703 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
6704 | phba->msix_entries[i].entry = i; | |
6705 | ||
6706 | /* Configure MSI-X capability structure */ | |
6707 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, | |
6708 | ARRAY_SIZE(phba->msix_entries)); | |
6709 | if (rc) { | |
6710 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6711 | "0420 PCI enable MSI-X failed (%d)\n", rc); | |
6712 | goto msi_fail_out; | |
6713 | } | |
6714 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
6715 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6716 | "0477 MSI-X entry[%d]: vector=x%x " | |
6717 | "message=%d\n", i, | |
6718 | phba->msix_entries[i].vector, | |
6719 | phba->msix_entries[i].entry); | |
6720 | /* | |
6721 | * Assign MSI-X vectors to interrupt handlers | |
6722 | */ | |
6723 | ||
6724 | /* vector-0 is associated to slow-path handler */ | |
6725 | rc = request_irq(phba->msix_entries[0].vector, | |
6726 | &lpfc_sli_sp_intr_handler, IRQF_SHARED, | |
6727 | LPFC_SP_DRIVER_HANDLER_NAME, phba); | |
6728 | if (rc) { | |
6729 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6730 | "0421 MSI-X slow-path request_irq failed " | |
6731 | "(%d)\n", rc); | |
6732 | goto msi_fail_out; | |
6733 | } | |
6734 | ||
6735 | /* vector-1 is associated to fast-path handler */ | |
6736 | rc = request_irq(phba->msix_entries[1].vector, | |
6737 | &lpfc_sli_fp_intr_handler, IRQF_SHARED, | |
6738 | LPFC_FP_DRIVER_HANDLER_NAME, phba); | |
6739 | ||
6740 | if (rc) { | |
6741 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6742 | "0429 MSI-X fast-path request_irq failed " | |
6743 | "(%d)\n", rc); | |
6744 | goto irq_fail_out; | |
6745 | } | |
6746 | ||
6747 | /* | |
6748 | * Configure HBA MSI-X attention conditions to messages | |
6749 | */ | |
6750 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6751 | ||
6752 | if (!pmb) { | |
6753 | rc = -ENOMEM; | |
6754 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6755 | "0474 Unable to allocate memory for issuing " | |
6756 | "MBOX_CONFIG_MSI command\n"); | |
6757 | goto mem_fail_out; | |
6758 | } | |
6759 | rc = lpfc_config_msi(phba, pmb); | |
6760 | if (rc) | |
6761 | goto mbx_fail_out; | |
6762 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
6763 | if (rc != MBX_SUCCESS) { | |
6764 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | |
6765 | "0351 Config MSI mailbox command failed, " | |
6766 | "mbxCmd x%x, mbxStatus x%x\n", | |
6767 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); | |
6768 | goto mbx_fail_out; | |
6769 | } | |
6770 | ||
6771 | /* Free memory allocated for mailbox command */ | |
6772 | mempool_free(pmb, phba->mbox_mem_pool); | |
6773 | return rc; | |
6774 | ||
6775 | mbx_fail_out: | |
6776 | /* Free memory allocated for mailbox command */ | |
6777 | mempool_free(pmb, phba->mbox_mem_pool); | |
6778 | ||
6779 | mem_fail_out: | |
6780 | /* free the irq already requested */ | |
6781 | free_irq(phba->msix_entries[1].vector, phba); | |
6782 | ||
6783 | irq_fail_out: | |
6784 | /* free the irq already requested */ | |
6785 | free_irq(phba->msix_entries[0].vector, phba); | |
6786 | ||
6787 | msi_fail_out: | |
6788 | /* Unconfigure MSI-X capability structure */ | |
6789 | pci_disable_msix(phba->pcidev); | |
6790 | return rc; | |
6791 | } | |
6792 | ||
6793 | /** | |
6794 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. | |
6795 | * @phba: pointer to lpfc hba data structure. | |
6796 | * | |
6797 | * This routine is invoked to release the MSI-X vectors and then disable the | |
6798 | * MSI-X interrupt mode to device with SLI-3 interface spec. | |
6799 | **/ | |
6800 | static void | |
6801 | lpfc_sli_disable_msix(struct lpfc_hba *phba) | |
6802 | { | |
6803 | int i; | |
6804 | ||
6805 | /* Free up MSI-X multi-message vectors */ | |
6806 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
6807 | free_irq(phba->msix_entries[i].vector, phba); | |
6808 | /* Disable MSI-X */ | |
6809 | pci_disable_msix(phba->pcidev); | |
6810 | ||
6811 | return; | |
6812 | } | |
6813 | ||
6814 | /** | |
6815 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. | |
6816 | * @phba: pointer to lpfc hba data structure. | |
6817 | * | |
6818 | * This routine is invoked to enable the MSI interrupt mode to device with | |
6819 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to | |
6820 | * enable the MSI vector. The device driver is responsible for calling the | |
6821 | * request_irq() to register MSI vector with a interrupt the handler, which | |
6822 | * is done in this function. | |
6823 | * | |
6824 | * Return codes | |
af901ca1 | 6825 | * 0 - successful |
da0436e9 JS |
6826 | * other values - error |
6827 | */ | |
6828 | static int | |
6829 | lpfc_sli_enable_msi(struct lpfc_hba *phba) | |
6830 | { | |
6831 | int rc; | |
6832 | ||
6833 | rc = pci_enable_msi(phba->pcidev); | |
6834 | if (!rc) | |
6835 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6836 | "0462 PCI enable MSI mode success.\n"); | |
6837 | else { | |
6838 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6839 | "0471 PCI enable MSI mode failed (%d)\n", rc); | |
6840 | return rc; | |
6841 | } | |
6842 | ||
6843 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
6844 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
6845 | if (rc) { | |
6846 | pci_disable_msi(phba->pcidev); | |
6847 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6848 | "0478 MSI request_irq failed (%d)\n", rc); | |
6849 | } | |
6850 | return rc; | |
6851 | } | |
6852 | ||
6853 | /** | |
6854 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. | |
6855 | * @phba: pointer to lpfc hba data structure. | |
6856 | * | |
6857 | * This routine is invoked to disable the MSI interrupt mode to device with | |
6858 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has | |
6859 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | |
6860 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | |
6861 | * its vector. | |
6862 | */ | |
6863 | static void | |
6864 | lpfc_sli_disable_msi(struct lpfc_hba *phba) | |
6865 | { | |
6866 | free_irq(phba->pcidev->irq, phba); | |
6867 | pci_disable_msi(phba->pcidev); | |
6868 | return; | |
6869 | } | |
6870 | ||
6871 | /** | |
6872 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. | |
6873 | * @phba: pointer to lpfc hba data structure. | |
6874 | * | |
6875 | * This routine is invoked to enable device interrupt and associate driver's | |
6876 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface | |
6877 | * spec. Depends on the interrupt mode configured to the driver, the driver | |
6878 | * will try to fallback from the configured interrupt mode to an interrupt | |
6879 | * mode which is supported by the platform, kernel, and device in the order | |
6880 | * of: | |
6881 | * MSI-X -> MSI -> IRQ. | |
6882 | * | |
6883 | * Return codes | |
af901ca1 | 6884 | * 0 - successful |
da0436e9 JS |
6885 | * other values - error |
6886 | **/ | |
6887 | static uint32_t | |
6888 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
6889 | { | |
6890 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
6891 | int retval; | |
6892 | ||
6893 | if (cfg_mode == 2) { | |
6894 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ | |
6895 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); | |
6896 | if (!retval) { | |
6897 | /* Now, try to enable MSI-X interrupt mode */ | |
6898 | retval = lpfc_sli_enable_msix(phba); | |
6899 | if (!retval) { | |
6900 | /* Indicate initialization to MSI-X mode */ | |
6901 | phba->intr_type = MSIX; | |
6902 | intr_mode = 2; | |
6903 | } | |
6904 | } | |
6905 | } | |
6906 | ||
6907 | /* Fallback to MSI if MSI-X initialization failed */ | |
6908 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
6909 | retval = lpfc_sli_enable_msi(phba); | |
6910 | if (!retval) { | |
6911 | /* Indicate initialization to MSI mode */ | |
6912 | phba->intr_type = MSI; | |
6913 | intr_mode = 1; | |
6914 | } | |
6915 | } | |
6916 | ||
6917 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
6918 | if (phba->intr_type == NONE) { | |
6919 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
6920 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
6921 | if (!retval) { | |
6922 | /* Indicate initialization to INTx mode */ | |
6923 | phba->intr_type = INTx; | |
6924 | intr_mode = 0; | |
6925 | } | |
6926 | } | |
6927 | return intr_mode; | |
6928 | } | |
6929 | ||
6930 | /** | |
6931 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. | |
6932 | * @phba: pointer to lpfc hba data structure. | |
6933 | * | |
6934 | * This routine is invoked to disable device interrupt and disassociate the | |
6935 | * driver's interrupt handler(s) from interrupt vector(s) to device with | |
6936 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will | |
6937 | * release the interrupt vector(s) for the message signaled interrupt. | |
6938 | **/ | |
6939 | static void | |
6940 | lpfc_sli_disable_intr(struct lpfc_hba *phba) | |
6941 | { | |
6942 | /* Disable the currently initialized interrupt mode */ | |
6943 | if (phba->intr_type == MSIX) | |
6944 | lpfc_sli_disable_msix(phba); | |
6945 | else if (phba->intr_type == MSI) | |
6946 | lpfc_sli_disable_msi(phba); | |
6947 | else if (phba->intr_type == INTx) | |
6948 | free_irq(phba->pcidev->irq, phba); | |
6949 | ||
6950 | /* Reset interrupt management states */ | |
6951 | phba->intr_type = NONE; | |
6952 | phba->sli.slistat.sli_intr = 0; | |
6953 | ||
6954 | return; | |
6955 | } | |
6956 | ||
6957 | /** | |
6958 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device | |
6959 | * @phba: pointer to lpfc hba data structure. | |
6960 | * | |
6961 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
6962 | * with SLI-4 interface spec. The kernel function pci_enable_msix() is called | |
6963 | * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked, | |
6964 | * enables either all or nothing, depending on the current availability of | |
6965 | * PCI vector resources. The device driver is responsible for calling the | |
6966 | * individual request_irq() to register each MSI-X vector with a interrupt | |
6967 | * handler, which is done in this function. Note that later when device is | |
6968 | * unloading, the driver should always call free_irq() on all MSI-X vectors | |
6969 | * it has done request_irq() on before calling pci_disable_msix(). Failure | |
6970 | * to do so results in a BUG_ON() and a device will be left with MSI-X | |
6971 | * enabled and leaks its vectors. | |
6972 | * | |
6973 | * Return codes | |
af901ca1 | 6974 | * 0 - successful |
da0436e9 JS |
6975 | * other values - error |
6976 | **/ | |
6977 | static int | |
6978 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) | |
6979 | { | |
75baf696 | 6980 | int vectors, rc, index; |
da0436e9 JS |
6981 | |
6982 | /* Set up MSI-X multi-message vectors */ | |
6983 | for (index = 0; index < phba->sli4_hba.cfg_eqn; index++) | |
6984 | phba->sli4_hba.msix_entries[index].entry = index; | |
6985 | ||
6986 | /* Configure MSI-X capability structure */ | |
75baf696 JS |
6987 | vectors = phba->sli4_hba.cfg_eqn; |
6988 | enable_msix_vectors: | |
da0436e9 | 6989 | rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries, |
75baf696 JS |
6990 | vectors); |
6991 | if (rc > 1) { | |
6992 | vectors = rc; | |
6993 | goto enable_msix_vectors; | |
6994 | } else if (rc) { | |
da0436e9 JS |
6995 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
6996 | "0484 PCI enable MSI-X failed (%d)\n", rc); | |
6997 | goto msi_fail_out; | |
6998 | } | |
75baf696 | 6999 | |
da0436e9 | 7000 | /* Log MSI-X vector assignment */ |
75baf696 | 7001 | for (index = 0; index < vectors; index++) |
da0436e9 JS |
7002 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
7003 | "0489 MSI-X entry[%d]: vector=x%x " | |
7004 | "message=%d\n", index, | |
7005 | phba->sli4_hba.msix_entries[index].vector, | |
7006 | phba->sli4_hba.msix_entries[index].entry); | |
7007 | /* | |
7008 | * Assign MSI-X vectors to interrupt handlers | |
7009 | */ | |
7010 | ||
7011 | /* The first vector must associated to slow-path handler for MQ */ | |
7012 | rc = request_irq(phba->sli4_hba.msix_entries[0].vector, | |
7013 | &lpfc_sli4_sp_intr_handler, IRQF_SHARED, | |
7014 | LPFC_SP_DRIVER_HANDLER_NAME, phba); | |
7015 | if (rc) { | |
7016 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7017 | "0485 MSI-X slow-path request_irq failed " | |
7018 | "(%d)\n", rc); | |
7019 | goto msi_fail_out; | |
7020 | } | |
7021 | ||
7022 | /* The rest of the vector(s) are associated to fast-path handler(s) */ | |
75baf696 | 7023 | for (index = 1; index < vectors; index++) { |
da0436e9 JS |
7024 | phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1; |
7025 | phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba; | |
7026 | rc = request_irq(phba->sli4_hba.msix_entries[index].vector, | |
7027 | &lpfc_sli4_fp_intr_handler, IRQF_SHARED, | |
7028 | LPFC_FP_DRIVER_HANDLER_NAME, | |
7029 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
7030 | if (rc) { | |
7031 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7032 | "0486 MSI-X fast-path (%d) " | |
7033 | "request_irq failed (%d)\n", index, rc); | |
7034 | goto cfg_fail_out; | |
7035 | } | |
7036 | } | |
75baf696 | 7037 | phba->sli4_hba.msix_vec_nr = vectors; |
da0436e9 JS |
7038 | |
7039 | return rc; | |
7040 | ||
7041 | cfg_fail_out: | |
7042 | /* free the irq already requested */ | |
7043 | for (--index; index >= 1; index--) | |
7044 | free_irq(phba->sli4_hba.msix_entries[index - 1].vector, | |
7045 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
7046 | ||
7047 | /* free the irq already requested */ | |
7048 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); | |
7049 | ||
7050 | msi_fail_out: | |
7051 | /* Unconfigure MSI-X capability structure */ | |
7052 | pci_disable_msix(phba->pcidev); | |
7053 | return rc; | |
7054 | } | |
7055 | ||
7056 | /** | |
7057 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device | |
7058 | * @phba: pointer to lpfc hba data structure. | |
7059 | * | |
7060 | * This routine is invoked to release the MSI-X vectors and then disable the | |
7061 | * MSI-X interrupt mode to device with SLI-4 interface spec. | |
7062 | **/ | |
7063 | static void | |
7064 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) | |
7065 | { | |
7066 | int index; | |
7067 | ||
7068 | /* Free up MSI-X multi-message vectors */ | |
7069 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); | |
7070 | ||
75baf696 | 7071 | for (index = 1; index < phba->sli4_hba.msix_vec_nr; index++) |
da0436e9 JS |
7072 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
7073 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
75baf696 | 7074 | |
da0436e9 JS |
7075 | /* Disable MSI-X */ |
7076 | pci_disable_msix(phba->pcidev); | |
7077 | ||
7078 | return; | |
7079 | } | |
7080 | ||
7081 | /** | |
7082 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device | |
7083 | * @phba: pointer to lpfc hba data structure. | |
7084 | * | |
7085 | * This routine is invoked to enable the MSI interrupt mode to device with | |
7086 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called | |
7087 | * to enable the MSI vector. The device driver is responsible for calling | |
7088 | * the request_irq() to register MSI vector with a interrupt the handler, | |
7089 | * which is done in this function. | |
7090 | * | |
7091 | * Return codes | |
af901ca1 | 7092 | * 0 - successful |
da0436e9 JS |
7093 | * other values - error |
7094 | **/ | |
7095 | static int | |
7096 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) | |
7097 | { | |
7098 | int rc, index; | |
7099 | ||
7100 | rc = pci_enable_msi(phba->pcidev); | |
7101 | if (!rc) | |
7102 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7103 | "0487 PCI enable MSI mode success.\n"); | |
7104 | else { | |
7105 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7106 | "0488 PCI enable MSI mode failed (%d)\n", rc); | |
7107 | return rc; | |
7108 | } | |
7109 | ||
7110 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
7111 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
7112 | if (rc) { | |
7113 | pci_disable_msi(phba->pcidev); | |
7114 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7115 | "0490 MSI request_irq failed (%d)\n", rc); | |
75baf696 | 7116 | return rc; |
da0436e9 JS |
7117 | } |
7118 | ||
7119 | for (index = 0; index < phba->cfg_fcp_eq_count; index++) { | |
7120 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | |
7121 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
7122 | } | |
7123 | ||
75baf696 | 7124 | return 0; |
da0436e9 JS |
7125 | } |
7126 | ||
7127 | /** | |
7128 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device | |
7129 | * @phba: pointer to lpfc hba data structure. | |
7130 | * | |
7131 | * This routine is invoked to disable the MSI interrupt mode to device with | |
7132 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has | |
7133 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | |
7134 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | |
7135 | * its vector. | |
7136 | **/ | |
7137 | static void | |
7138 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) | |
7139 | { | |
7140 | free_irq(phba->pcidev->irq, phba); | |
7141 | pci_disable_msi(phba->pcidev); | |
7142 | return; | |
7143 | } | |
7144 | ||
7145 | /** | |
7146 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device | |
7147 | * @phba: pointer to lpfc hba data structure. | |
7148 | * | |
7149 | * This routine is invoked to enable device interrupt and associate driver's | |
7150 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 | |
7151 | * interface spec. Depends on the interrupt mode configured to the driver, | |
7152 | * the driver will try to fallback from the configured interrupt mode to an | |
7153 | * interrupt mode which is supported by the platform, kernel, and device in | |
7154 | * the order of: | |
7155 | * MSI-X -> MSI -> IRQ. | |
7156 | * | |
7157 | * Return codes | |
af901ca1 | 7158 | * 0 - successful |
da0436e9 JS |
7159 | * other values - error |
7160 | **/ | |
7161 | static uint32_t | |
7162 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
7163 | { | |
7164 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
7165 | int retval, index; | |
7166 | ||
7167 | if (cfg_mode == 2) { | |
7168 | /* Preparation before conf_msi mbox cmd */ | |
7169 | retval = 0; | |
7170 | if (!retval) { | |
7171 | /* Now, try to enable MSI-X interrupt mode */ | |
7172 | retval = lpfc_sli4_enable_msix(phba); | |
7173 | if (!retval) { | |
7174 | /* Indicate initialization to MSI-X mode */ | |
7175 | phba->intr_type = MSIX; | |
7176 | intr_mode = 2; | |
7177 | } | |
7178 | } | |
7179 | } | |
7180 | ||
7181 | /* Fallback to MSI if MSI-X initialization failed */ | |
7182 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
7183 | retval = lpfc_sli4_enable_msi(phba); | |
7184 | if (!retval) { | |
7185 | /* Indicate initialization to MSI mode */ | |
7186 | phba->intr_type = MSI; | |
7187 | intr_mode = 1; | |
7188 | } | |
7189 | } | |
7190 | ||
7191 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
7192 | if (phba->intr_type == NONE) { | |
7193 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
7194 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
7195 | if (!retval) { | |
7196 | /* Indicate initialization to INTx mode */ | |
7197 | phba->intr_type = INTx; | |
7198 | intr_mode = 0; | |
7199 | for (index = 0; index < phba->cfg_fcp_eq_count; | |
7200 | index++) { | |
7201 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | |
7202 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
7203 | } | |
7204 | } | |
7205 | } | |
7206 | return intr_mode; | |
7207 | } | |
7208 | ||
7209 | /** | |
7210 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device | |
7211 | * @phba: pointer to lpfc hba data structure. | |
7212 | * | |
7213 | * This routine is invoked to disable device interrupt and disassociate | |
7214 | * the driver's interrupt handler(s) from interrupt vector(s) to device | |
7215 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver | |
7216 | * will release the interrupt vector(s) for the message signaled interrupt. | |
7217 | **/ | |
7218 | static void | |
7219 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) | |
7220 | { | |
7221 | /* Disable the currently initialized interrupt mode */ | |
7222 | if (phba->intr_type == MSIX) | |
7223 | lpfc_sli4_disable_msix(phba); | |
7224 | else if (phba->intr_type == MSI) | |
7225 | lpfc_sli4_disable_msi(phba); | |
7226 | else if (phba->intr_type == INTx) | |
7227 | free_irq(phba->pcidev->irq, phba); | |
7228 | ||
7229 | /* Reset interrupt management states */ | |
7230 | phba->intr_type = NONE; | |
7231 | phba->sli.slistat.sli_intr = 0; | |
7232 | ||
7233 | return; | |
7234 | } | |
7235 | ||
7236 | /** | |
7237 | * lpfc_unset_hba - Unset SLI3 hba device initialization | |
7238 | * @phba: pointer to lpfc hba data structure. | |
7239 | * | |
7240 | * This routine is invoked to unset the HBA device initialization steps to | |
7241 | * a device with SLI-3 interface spec. | |
7242 | **/ | |
7243 | static void | |
7244 | lpfc_unset_hba(struct lpfc_hba *phba) | |
7245 | { | |
7246 | struct lpfc_vport *vport = phba->pport; | |
7247 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
7248 | ||
7249 | spin_lock_irq(shost->host_lock); | |
7250 | vport->load_flag |= FC_UNLOADING; | |
7251 | spin_unlock_irq(shost->host_lock); | |
7252 | ||
7253 | lpfc_stop_hba_timers(phba); | |
7254 | ||
7255 | phba->pport->work_port_events = 0; | |
7256 | ||
7257 | lpfc_sli_hba_down(phba); | |
7258 | ||
7259 | lpfc_sli_brdrestart(phba); | |
7260 | ||
7261 | lpfc_sli_disable_intr(phba); | |
7262 | ||
7263 | return; | |
7264 | } | |
7265 | ||
7266 | /** | |
7267 | * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization. | |
7268 | * @phba: pointer to lpfc hba data structure. | |
7269 | * | |
7270 | * This routine is invoked to unset the HBA device initialization steps to | |
7271 | * a device with SLI-4 interface spec. | |
7272 | **/ | |
7273 | static void | |
7274 | lpfc_sli4_unset_hba(struct lpfc_hba *phba) | |
7275 | { | |
7276 | struct lpfc_vport *vport = phba->pport; | |
7277 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
7278 | ||
7279 | spin_lock_irq(shost->host_lock); | |
7280 | vport->load_flag |= FC_UNLOADING; | |
7281 | spin_unlock_irq(shost->host_lock); | |
7282 | ||
7283 | phba->pport->work_port_events = 0; | |
7284 | ||
3677a3a7 JS |
7285 | /* Stop the SLI4 device port */ |
7286 | lpfc_stop_port(phba); | |
da0436e9 JS |
7287 | |
7288 | lpfc_sli4_disable_intr(phba); | |
7289 | ||
3677a3a7 JS |
7290 | /* Reset SLI4 HBA FCoE function */ |
7291 | lpfc_pci_function_reset(phba); | |
7292 | ||
da0436e9 JS |
7293 | return; |
7294 | } | |
7295 | ||
5af5eee7 JS |
7296 | /** |
7297 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy | |
7298 | * @phba: Pointer to HBA context object. | |
7299 | * | |
7300 | * This function is called in the SLI4 code path to wait for completion | |
7301 | * of device's XRIs exchange busy. It will check the XRI exchange busy | |
7302 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after | |
7303 | * that, it will check the XRI exchange busy on outstanding FCP and ELS | |
7304 | * I/Os every 30 seconds, log error message, and wait forever. Only when | |
7305 | * all XRI exchange busy complete, the driver unload shall proceed with | |
7306 | * invoking the function reset ioctl mailbox command to the CNA and the | |
7307 | * the rest of the driver unload resource release. | |
7308 | **/ | |
7309 | static void | |
7310 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) | |
7311 | { | |
7312 | int wait_time = 0; | |
7313 | int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
7314 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
7315 | ||
7316 | while (!fcp_xri_cmpl || !els_xri_cmpl) { | |
7317 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { | |
7318 | if (!fcp_xri_cmpl) | |
7319 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7320 | "2877 FCP XRI exchange busy " | |
7321 | "wait time: %d seconds.\n", | |
7322 | wait_time/1000); | |
7323 | if (!els_xri_cmpl) | |
7324 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7325 | "2878 ELS XRI exchange busy " | |
7326 | "wait time: %d seconds.\n", | |
7327 | wait_time/1000); | |
7328 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); | |
7329 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; | |
7330 | } else { | |
7331 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); | |
7332 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; | |
7333 | } | |
7334 | fcp_xri_cmpl = | |
7335 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
7336 | els_xri_cmpl = | |
7337 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
7338 | } | |
7339 | } | |
7340 | ||
da0436e9 JS |
7341 | /** |
7342 | * lpfc_sli4_hba_unset - Unset the fcoe hba | |
7343 | * @phba: Pointer to HBA context object. | |
7344 | * | |
7345 | * This function is called in the SLI4 code path to reset the HBA's FCoE | |
7346 | * function. The caller is not required to hold any lock. This routine | |
7347 | * issues PCI function reset mailbox command to reset the FCoE function. | |
7348 | * At the end of the function, it calls lpfc_hba_down_post function to | |
7349 | * free any pending commands. | |
7350 | **/ | |
7351 | static void | |
7352 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) | |
7353 | { | |
7354 | int wait_cnt = 0; | |
7355 | LPFC_MBOXQ_t *mboxq; | |
7356 | ||
7357 | lpfc_stop_hba_timers(phba); | |
7358 | phba->sli4_hba.intr_enable = 0; | |
7359 | ||
7360 | /* | |
7361 | * Gracefully wait out the potential current outstanding asynchronous | |
7362 | * mailbox command. | |
7363 | */ | |
7364 | ||
7365 | /* First, block any pending async mailbox command from posted */ | |
7366 | spin_lock_irq(&phba->hbalock); | |
7367 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
7368 | spin_unlock_irq(&phba->hbalock); | |
7369 | /* Now, trying to wait it out if we can */ | |
7370 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
7371 | msleep(10); | |
7372 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) | |
7373 | break; | |
7374 | } | |
7375 | /* Forcefully release the outstanding mailbox command if timed out */ | |
7376 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
7377 | spin_lock_irq(&phba->hbalock); | |
7378 | mboxq = phba->sli.mbox_active; | |
7379 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
7380 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
7381 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7382 | phba->sli.mbox_active = NULL; | |
7383 | spin_unlock_irq(&phba->hbalock); | |
7384 | } | |
7385 | ||
5af5eee7 JS |
7386 | /* Abort all iocbs associated with the hba */ |
7387 | lpfc_sli_hba_iocb_abort(phba); | |
7388 | ||
7389 | /* Wait for completion of device XRI exchange busy */ | |
7390 | lpfc_sli4_xri_exchange_busy_wait(phba); | |
7391 | ||
da0436e9 JS |
7392 | /* Disable PCI subsystem interrupt */ |
7393 | lpfc_sli4_disable_intr(phba); | |
7394 | ||
7395 | /* Stop kthread signal shall trigger work_done one more time */ | |
7396 | kthread_stop(phba->worker_thread); | |
7397 | ||
3677a3a7 JS |
7398 | /* Reset SLI4 HBA FCoE function */ |
7399 | lpfc_pci_function_reset(phba); | |
7400 | ||
da0436e9 JS |
7401 | /* Stop the SLI4 device port */ |
7402 | phba->pport->work_port_events = 0; | |
7403 | } | |
7404 | ||
28baac74 JS |
7405 | /** |
7406 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. | |
7407 | * @phba: Pointer to HBA context object. | |
7408 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. | |
7409 | * | |
7410 | * This function is called in the SLI4 code path to read the port's | |
7411 | * sli4 capabilities. | |
7412 | * | |
7413 | * This function may be be called from any context that can block-wait | |
7414 | * for the completion. The expectation is that this routine is called | |
7415 | * typically from probe_one or from the online routine. | |
7416 | **/ | |
7417 | int | |
7418 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
7419 | { | |
7420 | int rc; | |
7421 | struct lpfc_mqe *mqe; | |
7422 | struct lpfc_pc_sli4_params *sli4_params; | |
7423 | uint32_t mbox_tmo; | |
7424 | ||
7425 | rc = 0; | |
7426 | mqe = &mboxq->u.mqe; | |
7427 | ||
7428 | /* Read the port's SLI4 Parameters port capabilities */ | |
7429 | lpfc_sli4_params(mboxq); | |
7430 | if (!phba->sli4_hba.intr_enable) | |
7431 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7432 | else { | |
7433 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_PORT_CAPABILITIES); | |
7434 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
7435 | } | |
7436 | ||
7437 | if (unlikely(rc)) | |
7438 | return 1; | |
7439 | ||
7440 | sli4_params = &phba->sli4_hba.pc_sli4_params; | |
7441 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); | |
7442 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); | |
7443 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); | |
7444 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, | |
7445 | &mqe->un.sli4_params); | |
7446 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, | |
7447 | &mqe->un.sli4_params); | |
7448 | sli4_params->proto_types = mqe->un.sli4_params.word3; | |
7449 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; | |
7450 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); | |
7451 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); | |
7452 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); | |
7453 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); | |
7454 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); | |
7455 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); | |
7456 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); | |
7457 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); | |
7458 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); | |
7459 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); | |
7460 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); | |
7461 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); | |
7462 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); | |
7463 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); | |
7464 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); | |
7465 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); | |
7466 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); | |
7467 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); | |
7468 | sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params); | |
7469 | return rc; | |
7470 | } | |
7471 | ||
da0436e9 JS |
7472 | /** |
7473 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. | |
7474 | * @pdev: pointer to PCI device | |
7475 | * @pid: pointer to PCI device identifier | |
7476 | * | |
7477 | * This routine is to be called to attach a device with SLI-3 interface spec | |
7478 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
7479 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific | |
7480 | * information of the device and driver to see if the driver state that it can | |
7481 | * support this kind of device. If the match is successful, the driver core | |
7482 | * invokes this routine. If this routine determines it can claim the HBA, it | |
7483 | * does all the initialization that it needs to do to handle the HBA properly. | |
7484 | * | |
7485 | * Return code | |
7486 | * 0 - driver can claim the device | |
7487 | * negative value - driver can not claim the device | |
7488 | **/ | |
7489 | static int __devinit | |
7490 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) | |
7491 | { | |
7492 | struct lpfc_hba *phba; | |
7493 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 7494 | struct Scsi_Host *shost = NULL; |
da0436e9 JS |
7495 | int error; |
7496 | uint32_t cfg_mode, intr_mode; | |
7497 | ||
7498 | /* Allocate memory for HBA structure */ | |
7499 | phba = lpfc_hba_alloc(pdev); | |
7500 | if (!phba) | |
7501 | return -ENOMEM; | |
7502 | ||
7503 | /* Perform generic PCI device enabling operation */ | |
7504 | error = lpfc_enable_pci_dev(phba); | |
7505 | if (error) { | |
7506 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7507 | "1401 Failed to enable pci device.\n"); | |
7508 | goto out_free_phba; | |
7509 | } | |
7510 | ||
7511 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ | |
7512 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); | |
7513 | if (error) | |
7514 | goto out_disable_pci_dev; | |
7515 | ||
7516 | /* Set up SLI-3 specific device PCI memory space */ | |
7517 | error = lpfc_sli_pci_mem_setup(phba); | |
7518 | if (error) { | |
7519 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7520 | "1402 Failed to set up pci memory space.\n"); | |
7521 | goto out_disable_pci_dev; | |
7522 | } | |
7523 | ||
7524 | /* Set up phase-1 common device driver resources */ | |
7525 | error = lpfc_setup_driver_resource_phase1(phba); | |
7526 | if (error) { | |
7527 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7528 | "1403 Failed to set up driver resource.\n"); | |
7529 | goto out_unset_pci_mem_s3; | |
7530 | } | |
7531 | ||
7532 | /* Set up SLI-3 specific device driver resources */ | |
7533 | error = lpfc_sli_driver_resource_setup(phba); | |
7534 | if (error) { | |
7535 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7536 | "1404 Failed to set up driver resource.\n"); | |
7537 | goto out_unset_pci_mem_s3; | |
7538 | } | |
7539 | ||
7540 | /* Initialize and populate the iocb list per host */ | |
7541 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); | |
7542 | if (error) { | |
7543 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7544 | "1405 Failed to initialize iocb list.\n"); | |
7545 | goto out_unset_driver_resource_s3; | |
7546 | } | |
7547 | ||
7548 | /* Set up common device driver resources */ | |
7549 | error = lpfc_setup_driver_resource_phase2(phba); | |
7550 | if (error) { | |
7551 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7552 | "1406 Failed to set up driver resource.\n"); | |
7553 | goto out_free_iocb_list; | |
7554 | } | |
7555 | ||
7556 | /* Create SCSI host to the physical port */ | |
7557 | error = lpfc_create_shost(phba); | |
7558 | if (error) { | |
7559 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7560 | "1407 Failed to create scsi host.\n"); | |
7561 | goto out_unset_driver_resource; | |
7562 | } | |
7563 | ||
7564 | /* Configure sysfs attributes */ | |
7565 | vport = phba->pport; | |
7566 | error = lpfc_alloc_sysfs_attr(vport); | |
7567 | if (error) { | |
7568 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7569 | "1476 Failed to allocate sysfs attr\n"); | |
7570 | goto out_destroy_shost; | |
7571 | } | |
7572 | ||
6669f9bb | 7573 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
da0436e9 JS |
7574 | /* Now, trying to enable interrupt and bring up the device */ |
7575 | cfg_mode = phba->cfg_use_msi; | |
7576 | while (true) { | |
7577 | /* Put device to a known state before enabling interrupt */ | |
7578 | lpfc_stop_port(phba); | |
7579 | /* Configure and enable interrupt */ | |
7580 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); | |
7581 | if (intr_mode == LPFC_INTR_ERROR) { | |
7582 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7583 | "0431 Failed to enable interrupt.\n"); | |
7584 | error = -ENODEV; | |
7585 | goto out_free_sysfs_attr; | |
7586 | } | |
7587 | /* SLI-3 HBA setup */ | |
7588 | if (lpfc_sli_hba_setup(phba)) { | |
7589 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7590 | "1477 Failed to set up hba\n"); | |
7591 | error = -ENODEV; | |
7592 | goto out_remove_device; | |
7593 | } | |
7594 | ||
7595 | /* Wait 50ms for the interrupts of previous mailbox commands */ | |
7596 | msleep(50); | |
7597 | /* Check active interrupts on message signaled interrupts */ | |
7598 | if (intr_mode == 0 || | |
7599 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { | |
7600 | /* Log the current active interrupt mode */ | |
7601 | phba->intr_mode = intr_mode; | |
7602 | lpfc_log_intr_mode(phba, intr_mode); | |
7603 | break; | |
7604 | } else { | |
7605 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7606 | "0447 Configure interrupt mode (%d) " | |
7607 | "failed active interrupt test.\n", | |
7608 | intr_mode); | |
7609 | /* Disable the current interrupt mode */ | |
7610 | lpfc_sli_disable_intr(phba); | |
7611 | /* Try next level of interrupt mode */ | |
7612 | cfg_mode = --intr_mode; | |
7613 | } | |
7614 | } | |
7615 | ||
7616 | /* Perform post initialization setup */ | |
7617 | lpfc_post_init_setup(phba); | |
7618 | ||
7619 | /* Check if there are static vports to be created. */ | |
7620 | lpfc_create_static_vport(phba); | |
7621 | ||
7622 | return 0; | |
7623 | ||
7624 | out_remove_device: | |
7625 | lpfc_unset_hba(phba); | |
7626 | out_free_sysfs_attr: | |
7627 | lpfc_free_sysfs_attr(vport); | |
7628 | out_destroy_shost: | |
7629 | lpfc_destroy_shost(phba); | |
7630 | out_unset_driver_resource: | |
7631 | lpfc_unset_driver_resource_phase2(phba); | |
7632 | out_free_iocb_list: | |
7633 | lpfc_free_iocb_list(phba); | |
7634 | out_unset_driver_resource_s3: | |
7635 | lpfc_sli_driver_resource_unset(phba); | |
7636 | out_unset_pci_mem_s3: | |
7637 | lpfc_sli_pci_mem_unset(phba); | |
7638 | out_disable_pci_dev: | |
7639 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
7640 | if (shost) |
7641 | scsi_host_put(shost); | |
da0436e9 JS |
7642 | out_free_phba: |
7643 | lpfc_hba_free(phba); | |
7644 | return error; | |
7645 | } | |
7646 | ||
7647 | /** | |
7648 | * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem. | |
7649 | * @pdev: pointer to PCI device | |
7650 | * | |
7651 | * This routine is to be called to disattach a device with SLI-3 interface | |
7652 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
7653 | * removed from PCI bus, it performs all the necessary cleanup for the HBA | |
7654 | * device to be removed from the PCI subsystem properly. | |
7655 | **/ | |
7656 | static void __devexit | |
7657 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) | |
7658 | { | |
7659 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7660 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
7661 | struct lpfc_vport **vports; | |
7662 | struct lpfc_hba *phba = vport->phba; | |
7663 | int i; | |
7664 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
7665 | ||
7666 | spin_lock_irq(&phba->hbalock); | |
7667 | vport->load_flag |= FC_UNLOADING; | |
7668 | spin_unlock_irq(&phba->hbalock); | |
7669 | ||
7670 | lpfc_free_sysfs_attr(vport); | |
7671 | ||
7672 | /* Release all the vports against this physical port */ | |
7673 | vports = lpfc_create_vport_work_array(phba); | |
7674 | if (vports != NULL) | |
7675 | for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) | |
7676 | fc_vport_terminate(vports[i]->fc_vport); | |
7677 | lpfc_destroy_vport_work_array(phba, vports); | |
7678 | ||
7679 | /* Remove FC host and then SCSI host with the physical port */ | |
7680 | fc_remove_host(shost); | |
7681 | scsi_remove_host(shost); | |
7682 | lpfc_cleanup(vport); | |
7683 | ||
7684 | /* | |
7685 | * Bring down the SLI Layer. This step disable all interrupts, | |
7686 | * clears the rings, discards all mailbox commands, and resets | |
7687 | * the HBA. | |
7688 | */ | |
7689 | ||
7690 | /* HBA interrupt will be diabled after this call */ | |
7691 | lpfc_sli_hba_down(phba); | |
7692 | /* Stop kthread signal shall trigger work_done one more time */ | |
7693 | kthread_stop(phba->worker_thread); | |
7694 | /* Final cleanup of txcmplq and reset the HBA */ | |
7695 | lpfc_sli_brdrestart(phba); | |
7696 | ||
7697 | lpfc_stop_hba_timers(phba); | |
7698 | spin_lock_irq(&phba->hbalock); | |
7699 | list_del_init(&vport->listentry); | |
7700 | spin_unlock_irq(&phba->hbalock); | |
7701 | ||
7702 | lpfc_debugfs_terminate(vport); | |
7703 | ||
7704 | /* Disable interrupt */ | |
7705 | lpfc_sli_disable_intr(phba); | |
7706 | ||
7707 | pci_set_drvdata(pdev, NULL); | |
7708 | scsi_host_put(shost); | |
7709 | ||
7710 | /* | |
7711 | * Call scsi_free before mem_free since scsi bufs are released to their | |
7712 | * corresponding pools here. | |
7713 | */ | |
7714 | lpfc_scsi_free(phba); | |
7715 | lpfc_mem_free_all(phba); | |
7716 | ||
7717 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
7718 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
7719 | ||
7720 | /* Free resources associated with SLI2 interface */ | |
7721 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
7722 | phba->slim2p.virt, phba->slim2p.phys); | |
7723 | ||
7724 | /* unmap adapter SLIM and Control Registers */ | |
7725 | iounmap(phba->ctrl_regs_memmap_p); | |
7726 | iounmap(phba->slim_memmap_p); | |
7727 | ||
7728 | lpfc_hba_free(phba); | |
7729 | ||
7730 | pci_release_selected_regions(pdev, bars); | |
7731 | pci_disable_device(pdev); | |
7732 | } | |
7733 | ||
7734 | /** | |
7735 | * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt | |
7736 | * @pdev: pointer to PCI device | |
7737 | * @msg: power management message | |
7738 | * | |
7739 | * This routine is to be called from the kernel's PCI subsystem to support | |
7740 | * system Power Management (PM) to device with SLI-3 interface spec. When | |
7741 | * PM invokes this method, it quiesces the device by stopping the driver's | |
7742 | * worker thread for the device, turning off device's interrupt and DMA, | |
7743 | * and bring the device offline. Note that as the driver implements the | |
7744 | * minimum PM requirements to a power-aware driver's PM support for the | |
7745 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
7746 | * to the suspend() method call will be treated as SUSPEND and the driver will | |
7747 | * fully reinitialize its device during resume() method call, the driver will | |
7748 | * set device to PCI_D3hot state in PCI config space instead of setting it | |
7749 | * according to the @msg provided by the PM. | |
7750 | * | |
7751 | * Return code | |
7752 | * 0 - driver suspended the device | |
7753 | * Error otherwise | |
7754 | **/ | |
7755 | static int | |
7756 | lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg) | |
7757 | { | |
7758 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7759 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
7760 | ||
7761 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7762 | "0473 PCI device Power Management suspend.\n"); | |
7763 | ||
7764 | /* Bring down the device */ | |
7765 | lpfc_offline_prep(phba); | |
7766 | lpfc_offline(phba); | |
7767 | kthread_stop(phba->worker_thread); | |
7768 | ||
7769 | /* Disable interrupt from device */ | |
7770 | lpfc_sli_disable_intr(phba); | |
7771 | ||
7772 | /* Save device state to PCI config space */ | |
7773 | pci_save_state(pdev); | |
7774 | pci_set_power_state(pdev, PCI_D3hot); | |
7775 | ||
7776 | return 0; | |
7777 | } | |
7778 | ||
7779 | /** | |
7780 | * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt | |
7781 | * @pdev: pointer to PCI device | |
7782 | * | |
7783 | * This routine is to be called from the kernel's PCI subsystem to support | |
7784 | * system Power Management (PM) to device with SLI-3 interface spec. When PM | |
7785 | * invokes this method, it restores the device's PCI config space state and | |
7786 | * fully reinitializes the device and brings it online. Note that as the | |
7787 | * driver implements the minimum PM requirements to a power-aware driver's | |
7788 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, | |
7789 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the | |
7790 | * driver will fully reinitialize its device during resume() method call, | |
7791 | * the device will be set to PCI_D0 directly in PCI config space before | |
7792 | * restoring the state. | |
7793 | * | |
7794 | * Return code | |
7795 | * 0 - driver suspended the device | |
7796 | * Error otherwise | |
7797 | **/ | |
7798 | static int | |
7799 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) | |
7800 | { | |
7801 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7802 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
7803 | uint32_t intr_mode; | |
7804 | int error; | |
7805 | ||
7806 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7807 | "0452 PCI device Power Management resume.\n"); | |
7808 | ||
7809 | /* Restore device state from PCI config space */ | |
7810 | pci_set_power_state(pdev, PCI_D0); | |
7811 | pci_restore_state(pdev); | |
0d878419 | 7812 | |
1dfb5a47 JS |
7813 | /* |
7814 | * As the new kernel behavior of pci_restore_state() API call clears | |
7815 | * device saved_state flag, need to save the restored state again. | |
7816 | */ | |
7817 | pci_save_state(pdev); | |
7818 | ||
da0436e9 JS |
7819 | if (pdev->is_busmaster) |
7820 | pci_set_master(pdev); | |
7821 | ||
7822 | /* Startup the kernel thread for this host adapter. */ | |
7823 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
7824 | "lpfc_worker_%d", phba->brd_no); | |
7825 | if (IS_ERR(phba->worker_thread)) { | |
7826 | error = PTR_ERR(phba->worker_thread); | |
7827 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7828 | "0434 PM resume failed to start worker " | |
7829 | "thread: error=x%x.\n", error); | |
7830 | return error; | |
7831 | } | |
7832 | ||
7833 | /* Configure and enable interrupt */ | |
7834 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
7835 | if (intr_mode == LPFC_INTR_ERROR) { | |
7836 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7837 | "0430 PM resume Failed to enable interrupt\n"); | |
7838 | return -EIO; | |
7839 | } else | |
7840 | phba->intr_mode = intr_mode; | |
7841 | ||
7842 | /* Restart HBA and bring it online */ | |
7843 | lpfc_sli_brdrestart(phba); | |
7844 | lpfc_online(phba); | |
7845 | ||
7846 | /* Log the current active interrupt mode */ | |
7847 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
7848 | ||
7849 | return 0; | |
7850 | } | |
7851 | ||
891478a2 JS |
7852 | /** |
7853 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover | |
7854 | * @phba: pointer to lpfc hba data structure. | |
7855 | * | |
7856 | * This routine is called to prepare the SLI3 device for PCI slot recover. It | |
e2af0d2e | 7857 | * aborts all the outstanding SCSI I/Os to the pci device. |
891478a2 JS |
7858 | **/ |
7859 | static void | |
7860 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) | |
7861 | { | |
e2af0d2e JS |
7862 | struct lpfc_sli *psli = &phba->sli; |
7863 | struct lpfc_sli_ring *pring; | |
7864 | ||
891478a2 JS |
7865 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
7866 | "2723 PCI channel I/O abort preparing for recovery\n"); | |
e2af0d2e JS |
7867 | |
7868 | /* | |
7869 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
7870 | * and let the SCSI mid-layer to retry them to recover. | |
7871 | */ | |
7872 | pring = &psli->ring[psli->fcp_ring]; | |
7873 | lpfc_sli_abort_iocb_ring(phba, pring); | |
891478a2 JS |
7874 | } |
7875 | ||
0d878419 JS |
7876 | /** |
7877 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset | |
7878 | * @phba: pointer to lpfc hba data structure. | |
7879 | * | |
7880 | * This routine is called to prepare the SLI3 device for PCI slot reset. It | |
7881 | * disables the device interrupt and pci device, and aborts the internal FCP | |
7882 | * pending I/Os. | |
7883 | **/ | |
7884 | static void | |
7885 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) | |
7886 | { | |
0d878419 | 7887 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
891478a2 | 7888 | "2710 PCI channel disable preparing for reset\n"); |
e2af0d2e | 7889 | |
75baf696 JS |
7890 | /* Block any management I/Os to the device */ |
7891 | lpfc_block_mgmt_io(phba); | |
7892 | ||
e2af0d2e JS |
7893 | /* Block all SCSI devices' I/Os on the host */ |
7894 | lpfc_scsi_dev_block(phba); | |
7895 | ||
7896 | /* stop all timers */ | |
7897 | lpfc_stop_hba_timers(phba); | |
7898 | ||
0d878419 JS |
7899 | /* Disable interrupt and pci device */ |
7900 | lpfc_sli_disable_intr(phba); | |
7901 | pci_disable_device(phba->pcidev); | |
75baf696 | 7902 | |
e2af0d2e JS |
7903 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
7904 | lpfc_sli_flush_fcp_rings(phba); | |
0d878419 JS |
7905 | } |
7906 | ||
7907 | /** | |
7908 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable | |
7909 | * @phba: pointer to lpfc hba data structure. | |
7910 | * | |
7911 | * This routine is called to prepare the SLI3 device for PCI slot permanently | |
7912 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
7913 | * pending I/Os. | |
7914 | **/ | |
7915 | static void | |
75baf696 | 7916 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
0d878419 JS |
7917 | { |
7918 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
891478a2 | 7919 | "2711 PCI channel permanent disable for failure\n"); |
e2af0d2e JS |
7920 | /* Block all SCSI devices' I/Os on the host */ |
7921 | lpfc_scsi_dev_block(phba); | |
7922 | ||
7923 | /* stop all timers */ | |
7924 | lpfc_stop_hba_timers(phba); | |
7925 | ||
0d878419 JS |
7926 | /* Clean up all driver's outstanding SCSI I/Os */ |
7927 | lpfc_sli_flush_fcp_rings(phba); | |
7928 | } | |
7929 | ||
da0436e9 JS |
7930 | /** |
7931 | * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error | |
7932 | * @pdev: pointer to PCI device. | |
7933 | * @state: the current PCI connection state. | |
7934 | * | |
7935 | * This routine is called from the PCI subsystem for I/O error handling to | |
7936 | * device with SLI-3 interface spec. This function is called by the PCI | |
7937 | * subsystem after a PCI bus error affecting this device has been detected. | |
7938 | * When this function is invoked, it will need to stop all the I/Os and | |
7939 | * interrupt(s) to the device. Once that is done, it will return | |
7940 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery | |
7941 | * as desired. | |
7942 | * | |
7943 | * Return codes | |
0d878419 | 7944 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
da0436e9 JS |
7945 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
7946 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
7947 | **/ | |
7948 | static pci_ers_result_t | |
7949 | lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state) | |
7950 | { | |
7951 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7952 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
da0436e9 | 7953 | |
0d878419 JS |
7954 | switch (state) { |
7955 | case pci_channel_io_normal: | |
891478a2 JS |
7956 | /* Non-fatal error, prepare for recovery */ |
7957 | lpfc_sli_prep_dev_for_recover(phba); | |
0d878419 JS |
7958 | return PCI_ERS_RESULT_CAN_RECOVER; |
7959 | case pci_channel_io_frozen: | |
7960 | /* Fatal error, prepare for slot reset */ | |
7961 | lpfc_sli_prep_dev_for_reset(phba); | |
7962 | return PCI_ERS_RESULT_NEED_RESET; | |
7963 | case pci_channel_io_perm_failure: | |
7964 | /* Permanent failure, prepare for device down */ | |
75baf696 | 7965 | lpfc_sli_prep_dev_for_perm_failure(phba); |
da0436e9 | 7966 | return PCI_ERS_RESULT_DISCONNECT; |
0d878419 JS |
7967 | default: |
7968 | /* Unknown state, prepare and request slot reset */ | |
7969 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7970 | "0472 Unknown PCI error state: x%x\n", state); | |
7971 | lpfc_sli_prep_dev_for_reset(phba); | |
7972 | return PCI_ERS_RESULT_NEED_RESET; | |
da0436e9 | 7973 | } |
da0436e9 JS |
7974 | } |
7975 | ||
7976 | /** | |
7977 | * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch. | |
7978 | * @pdev: pointer to PCI device. | |
7979 | * | |
7980 | * This routine is called from the PCI subsystem for error handling to | |
7981 | * device with SLI-3 interface spec. This is called after PCI bus has been | |
7982 | * reset to restart the PCI card from scratch, as if from a cold-boot. | |
7983 | * During the PCI subsystem error recovery, after driver returns | |
7984 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error | |
7985 | * recovery and then call this routine before calling the .resume method | |
7986 | * to recover the device. This function will initialize the HBA device, | |
7987 | * enable the interrupt, but it will just put the HBA to offline state | |
7988 | * without passing any I/O traffic. | |
7989 | * | |
7990 | * Return codes | |
7991 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
7992 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
7993 | */ | |
7994 | static pci_ers_result_t | |
7995 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) | |
7996 | { | |
7997 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7998 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
7999 | struct lpfc_sli *psli = &phba->sli; | |
8000 | uint32_t intr_mode; | |
8001 | ||
8002 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
8003 | if (pci_enable_device_mem(pdev)) { | |
8004 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
8005 | "PCI device after reset.\n"); | |
8006 | return PCI_ERS_RESULT_DISCONNECT; | |
8007 | } | |
8008 | ||
8009 | pci_restore_state(pdev); | |
1dfb5a47 JS |
8010 | |
8011 | /* | |
8012 | * As the new kernel behavior of pci_restore_state() API call clears | |
8013 | * device saved_state flag, need to save the restored state again. | |
8014 | */ | |
8015 | pci_save_state(pdev); | |
8016 | ||
da0436e9 JS |
8017 | if (pdev->is_busmaster) |
8018 | pci_set_master(pdev); | |
8019 | ||
8020 | spin_lock_irq(&phba->hbalock); | |
8021 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
8022 | spin_unlock_irq(&phba->hbalock); | |
8023 | ||
8024 | /* Configure and enable interrupt */ | |
8025 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
8026 | if (intr_mode == LPFC_INTR_ERROR) { | |
8027 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8028 | "0427 Cannot re-enable interrupt after " | |
8029 | "slot reset.\n"); | |
8030 | return PCI_ERS_RESULT_DISCONNECT; | |
8031 | } else | |
8032 | phba->intr_mode = intr_mode; | |
8033 | ||
75baf696 JS |
8034 | /* Take device offline, it will perform cleanup */ |
8035 | lpfc_offline_prep(phba); | |
da0436e9 JS |
8036 | lpfc_offline(phba); |
8037 | lpfc_sli_brdrestart(phba); | |
8038 | ||
8039 | /* Log the current active interrupt mode */ | |
8040 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
8041 | ||
8042 | return PCI_ERS_RESULT_RECOVERED; | |
8043 | } | |
8044 | ||
8045 | /** | |
8046 | * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device. | |
8047 | * @pdev: pointer to PCI device | |
8048 | * | |
8049 | * This routine is called from the PCI subsystem for error handling to device | |
8050 | * with SLI-3 interface spec. It is called when kernel error recovery tells | |
8051 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus | |
8052 | * error recovery. After this call, traffic can start to flow from this device | |
8053 | * again. | |
8054 | */ | |
8055 | static void | |
8056 | lpfc_io_resume_s3(struct pci_dev *pdev) | |
8057 | { | |
8058 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8059 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
3772a991 | 8060 | |
e2af0d2e | 8061 | /* Bring device online, it will be no-op for non-fatal error resume */ |
da0436e9 | 8062 | lpfc_online(phba); |
0d878419 JS |
8063 | |
8064 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
8065 | if (phba->hba_flag & HBA_AER_ENABLED) | |
8066 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
da0436e9 | 8067 | } |
3772a991 | 8068 | |
da0436e9 JS |
8069 | /** |
8070 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve | |
8071 | * @phba: pointer to lpfc hba data structure. | |
8072 | * | |
8073 | * returns the number of ELS/CT IOCBs to reserve | |
8074 | **/ | |
8075 | int | |
8076 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) | |
8077 | { | |
8078 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; | |
8079 | ||
f1126688 JS |
8080 | if (phba->sli_rev == LPFC_SLI_REV4) { |
8081 | if (max_xri <= 100) | |
6a9c52cf | 8082 | return 10; |
f1126688 | 8083 | else if (max_xri <= 256) |
6a9c52cf | 8084 | return 25; |
f1126688 | 8085 | else if (max_xri <= 512) |
6a9c52cf | 8086 | return 50; |
f1126688 | 8087 | else if (max_xri <= 1024) |
6a9c52cf | 8088 | return 100; |
f1126688 | 8089 | else |
6a9c52cf | 8090 | return 150; |
f1126688 JS |
8091 | } else |
8092 | return 0; | |
3772a991 JS |
8093 | } |
8094 | ||
8095 | /** | |
da0436e9 | 8096 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
3772a991 JS |
8097 | * @pdev: pointer to PCI device |
8098 | * @pid: pointer to PCI device identifier | |
8099 | * | |
da0436e9 JS |
8100 | * This routine is called from the kernel's PCI subsystem to device with |
8101 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 | 8102 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
da0436e9 JS |
8103 | * information of the device and driver to see if the driver state that it |
8104 | * can support this kind of device. If the match is successful, the driver | |
8105 | * core invokes this routine. If this routine determines it can claim the HBA, | |
8106 | * it does all the initialization that it needs to do to handle the HBA | |
8107 | * properly. | |
3772a991 JS |
8108 | * |
8109 | * Return code | |
8110 | * 0 - driver can claim the device | |
8111 | * negative value - driver can not claim the device | |
8112 | **/ | |
8113 | static int __devinit | |
da0436e9 | 8114 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
3772a991 JS |
8115 | { |
8116 | struct lpfc_hba *phba; | |
8117 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 8118 | struct Scsi_Host *shost = NULL; |
3772a991 JS |
8119 | int error; |
8120 | uint32_t cfg_mode, intr_mode; | |
da0436e9 | 8121 | int mcnt; |
3772a991 JS |
8122 | |
8123 | /* Allocate memory for HBA structure */ | |
8124 | phba = lpfc_hba_alloc(pdev); | |
8125 | if (!phba) | |
8126 | return -ENOMEM; | |
8127 | ||
8128 | /* Perform generic PCI device enabling operation */ | |
8129 | error = lpfc_enable_pci_dev(phba); | |
8130 | if (error) { | |
8131 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8132 | "1409 Failed to enable pci device.\n"); |
3772a991 JS |
8133 | goto out_free_phba; |
8134 | } | |
8135 | ||
da0436e9 JS |
8136 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
8137 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); | |
3772a991 JS |
8138 | if (error) |
8139 | goto out_disable_pci_dev; | |
8140 | ||
da0436e9 JS |
8141 | /* Set up SLI-4 specific device PCI memory space */ |
8142 | error = lpfc_sli4_pci_mem_setup(phba); | |
3772a991 JS |
8143 | if (error) { |
8144 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8145 | "1410 Failed to set up pci memory space.\n"); |
3772a991 JS |
8146 | goto out_disable_pci_dev; |
8147 | } | |
8148 | ||
8149 | /* Set up phase-1 common device driver resources */ | |
8150 | error = lpfc_setup_driver_resource_phase1(phba); | |
8151 | if (error) { | |
8152 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
8153 | "1411 Failed to set up driver resource.\n"); |
8154 | goto out_unset_pci_mem_s4; | |
3772a991 JS |
8155 | } |
8156 | ||
da0436e9 JS |
8157 | /* Set up SLI-4 Specific device driver resources */ |
8158 | error = lpfc_sli4_driver_resource_setup(phba); | |
3772a991 JS |
8159 | if (error) { |
8160 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
8161 | "1412 Failed to set up driver resource.\n"); |
8162 | goto out_unset_pci_mem_s4; | |
3772a991 JS |
8163 | } |
8164 | ||
8165 | /* Initialize and populate the iocb list per host */ | |
2a9bf3d0 JS |
8166 | |
8167 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8168 | "2821 initialize iocb list %d.\n", | |
8169 | phba->cfg_iocb_cnt*1024); | |
8170 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); | |
8171 | ||
3772a991 JS |
8172 | if (error) { |
8173 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
8174 | "1413 Failed to initialize iocb list.\n"); |
8175 | goto out_unset_driver_resource_s4; | |
3772a991 JS |
8176 | } |
8177 | ||
8178 | /* Set up common device driver resources */ | |
8179 | error = lpfc_setup_driver_resource_phase2(phba); | |
8180 | if (error) { | |
8181 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8182 | "1414 Failed to set up driver resource.\n"); |
3772a991 JS |
8183 | goto out_free_iocb_list; |
8184 | } | |
8185 | ||
8186 | /* Create SCSI host to the physical port */ | |
8187 | error = lpfc_create_shost(phba); | |
8188 | if (error) { | |
8189 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8190 | "1415 Failed to create scsi host.\n"); |
3772a991 JS |
8191 | goto out_unset_driver_resource; |
8192 | } | |
9399627f | 8193 | |
5b75da2f | 8194 | /* Configure sysfs attributes */ |
3772a991 JS |
8195 | vport = phba->pport; |
8196 | error = lpfc_alloc_sysfs_attr(vport); | |
8197 | if (error) { | |
9399627f | 8198 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 8199 | "1416 Failed to allocate sysfs attr\n"); |
3772a991 | 8200 | goto out_destroy_shost; |
98c9ea5c | 8201 | } |
875fbdfe | 8202 | |
6669f9bb | 8203 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
3772a991 | 8204 | /* Now, trying to enable interrupt and bring up the device */ |
5b75da2f JS |
8205 | cfg_mode = phba->cfg_use_msi; |
8206 | while (true) { | |
3772a991 JS |
8207 | /* Put device to a known state before enabling interrupt */ |
8208 | lpfc_stop_port(phba); | |
5b75da2f | 8209 | /* Configure and enable interrupt */ |
da0436e9 | 8210 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
5b75da2f JS |
8211 | if (intr_mode == LPFC_INTR_ERROR) { |
8212 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8213 | "0426 Failed to enable interrupt.\n"); |
3772a991 | 8214 | error = -ENODEV; |
5b75da2f JS |
8215 | goto out_free_sysfs_attr; |
8216 | } | |
def9c7a9 JS |
8217 | /* Default to single FCP EQ for non-MSI-X */ |
8218 | if (phba->intr_type != MSIX) | |
8219 | phba->cfg_fcp_eq_count = 1; | |
75baf696 JS |
8220 | else if (phba->sli4_hba.msix_vec_nr < phba->cfg_fcp_eq_count) |
8221 | phba->cfg_fcp_eq_count = phba->sli4_hba.msix_vec_nr - 1; | |
da0436e9 JS |
8222 | /* Set up SLI-4 HBA */ |
8223 | if (lpfc_sli4_hba_setup(phba)) { | |
5b75da2f | 8224 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 8225 | "1421 Failed to set up hba\n"); |
5b75da2f | 8226 | error = -ENODEV; |
da0436e9 | 8227 | goto out_disable_intr; |
5b75da2f JS |
8228 | } |
8229 | ||
da0436e9 JS |
8230 | /* Send NOP mbx cmds for non-INTx mode active interrupt test */ |
8231 | if (intr_mode != 0) | |
8232 | mcnt = lpfc_sli4_send_nop_mbox_cmds(phba, | |
8233 | LPFC_ACT_INTR_CNT); | |
8234 | ||
8235 | /* Check active interrupts received only for MSI/MSI-X */ | |
3772a991 | 8236 | if (intr_mode == 0 || |
da0436e9 | 8237 | phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) { |
5b75da2f JS |
8238 | /* Log the current active interrupt mode */ |
8239 | phba->intr_mode = intr_mode; | |
8240 | lpfc_log_intr_mode(phba, intr_mode); | |
8241 | break; | |
5b75da2f | 8242 | } |
da0436e9 JS |
8243 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
8244 | "0451 Configure interrupt mode (%d) " | |
8245 | "failed active interrupt test.\n", | |
8246 | intr_mode); | |
8247 | /* Unset the preivous SLI-4 HBA setup */ | |
8248 | lpfc_sli4_unset_hba(phba); | |
8249 | /* Try next level of interrupt mode */ | |
8250 | cfg_mode = --intr_mode; | |
98c9ea5c | 8251 | } |
858c9f6c | 8252 | |
3772a991 JS |
8253 | /* Perform post initialization setup */ |
8254 | lpfc_post_init_setup(phba); | |
dea3101e | 8255 | |
1c6834a7 JS |
8256 | /* Check if there are static vports to be created. */ |
8257 | lpfc_create_static_vport(phba); | |
8258 | ||
dea3101e | 8259 | return 0; |
8260 | ||
da0436e9 JS |
8261 | out_disable_intr: |
8262 | lpfc_sli4_disable_intr(phba); | |
5b75da2f JS |
8263 | out_free_sysfs_attr: |
8264 | lpfc_free_sysfs_attr(vport); | |
3772a991 JS |
8265 | out_destroy_shost: |
8266 | lpfc_destroy_shost(phba); | |
8267 | out_unset_driver_resource: | |
8268 | lpfc_unset_driver_resource_phase2(phba); | |
8269 | out_free_iocb_list: | |
8270 | lpfc_free_iocb_list(phba); | |
da0436e9 JS |
8271 | out_unset_driver_resource_s4: |
8272 | lpfc_sli4_driver_resource_unset(phba); | |
8273 | out_unset_pci_mem_s4: | |
8274 | lpfc_sli4_pci_mem_unset(phba); | |
3772a991 JS |
8275 | out_disable_pci_dev: |
8276 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
8277 | if (shost) |
8278 | scsi_host_put(shost); | |
2e0fef85 | 8279 | out_free_phba: |
3772a991 | 8280 | lpfc_hba_free(phba); |
dea3101e | 8281 | return error; |
8282 | } | |
8283 | ||
e59058c4 | 8284 | /** |
da0436e9 | 8285 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
e59058c4 JS |
8286 | * @pdev: pointer to PCI device |
8287 | * | |
da0436e9 JS |
8288 | * This routine is called from the kernel's PCI subsystem to device with |
8289 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 JS |
8290 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
8291 | * device to be removed from the PCI subsystem properly. | |
e59058c4 | 8292 | **/ |
dea3101e | 8293 | static void __devexit |
da0436e9 | 8294 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
dea3101e | 8295 | { |
da0436e9 | 8296 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2e0fef85 | 8297 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
eada272d | 8298 | struct lpfc_vport **vports; |
da0436e9 | 8299 | struct lpfc_hba *phba = vport->phba; |
eada272d | 8300 | int i; |
8a4df120 | 8301 | |
da0436e9 | 8302 | /* Mark the device unloading flag */ |
549e55cd | 8303 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 8304 | vport->load_flag |= FC_UNLOADING; |
549e55cd | 8305 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 8306 | |
da0436e9 | 8307 | /* Free the HBA sysfs attributes */ |
858c9f6c JS |
8308 | lpfc_free_sysfs_attr(vport); |
8309 | ||
eada272d JS |
8310 | /* Release all the vports against this physical port */ |
8311 | vports = lpfc_create_vport_work_array(phba); | |
8312 | if (vports != NULL) | |
3772a991 | 8313 | for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) |
eada272d JS |
8314 | fc_vport_terminate(vports[i]->fc_vport); |
8315 | lpfc_destroy_vport_work_array(phba, vports); | |
8316 | ||
8317 | /* Remove FC host and then SCSI host with the physical port */ | |
858c9f6c JS |
8318 | fc_remove_host(shost); |
8319 | scsi_remove_host(shost); | |
da0436e9 JS |
8320 | |
8321 | /* Perform cleanup on the physical port */ | |
87af33fe JS |
8322 | lpfc_cleanup(vport); |
8323 | ||
2e0fef85 | 8324 | /* |
da0436e9 | 8325 | * Bring down the SLI Layer. This step disables all interrupts, |
2e0fef85 | 8326 | * clears the rings, discards all mailbox commands, and resets |
da0436e9 | 8327 | * the HBA FCoE function. |
2e0fef85 | 8328 | */ |
da0436e9 JS |
8329 | lpfc_debugfs_terminate(vport); |
8330 | lpfc_sli4_hba_unset(phba); | |
a257bf90 | 8331 | |
858c9f6c JS |
8332 | spin_lock_irq(&phba->hbalock); |
8333 | list_del_init(&vport->listentry); | |
8334 | spin_unlock_irq(&phba->hbalock); | |
8335 | ||
3677a3a7 | 8336 | /* Perform scsi free before driver resource_unset since scsi |
da0436e9 | 8337 | * buffers are released to their corresponding pools here. |
2e0fef85 JS |
8338 | */ |
8339 | lpfc_scsi_free(phba); | |
da0436e9 | 8340 | lpfc_sli4_driver_resource_unset(phba); |
ed957684 | 8341 | |
da0436e9 JS |
8342 | /* Unmap adapter Control and Doorbell registers */ |
8343 | lpfc_sli4_pci_mem_unset(phba); | |
2e0fef85 | 8344 | |
da0436e9 JS |
8345 | /* Release PCI resources and disable device's PCI function */ |
8346 | scsi_host_put(shost); | |
8347 | lpfc_disable_pci_dev(phba); | |
2e0fef85 | 8348 | |
da0436e9 | 8349 | /* Finally, free the driver's device data structure */ |
3772a991 | 8350 | lpfc_hba_free(phba); |
2e0fef85 | 8351 | |
da0436e9 | 8352 | return; |
dea3101e | 8353 | } |
8354 | ||
3a55b532 | 8355 | /** |
da0436e9 | 8356 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
3a55b532 JS |
8357 | * @pdev: pointer to PCI device |
8358 | * @msg: power management message | |
8359 | * | |
da0436e9 JS |
8360 | * This routine is called from the kernel's PCI subsystem to support system |
8361 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes | |
8362 | * this method, it quiesces the device by stopping the driver's worker | |
8363 | * thread for the device, turning off device's interrupt and DMA, and bring | |
8364 | * the device offline. Note that as the driver implements the minimum PM | |
8365 | * requirements to a power-aware driver's PM support for suspend/resume -- all | |
8366 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() | |
8367 | * method call will be treated as SUSPEND and the driver will fully | |
8368 | * reinitialize its device during resume() method call, the driver will set | |
8369 | * device to PCI_D3hot state in PCI config space instead of setting it | |
3772a991 | 8370 | * according to the @msg provided by the PM. |
3a55b532 JS |
8371 | * |
8372 | * Return code | |
3772a991 JS |
8373 | * 0 - driver suspended the device |
8374 | * Error otherwise | |
3a55b532 JS |
8375 | **/ |
8376 | static int | |
da0436e9 | 8377 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
3a55b532 JS |
8378 | { |
8379 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8380 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8381 | ||
8382 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
75baf696 | 8383 | "2843 PCI device Power Management suspend.\n"); |
3a55b532 JS |
8384 | |
8385 | /* Bring down the device */ | |
8386 | lpfc_offline_prep(phba); | |
8387 | lpfc_offline(phba); | |
8388 | kthread_stop(phba->worker_thread); | |
8389 | ||
8390 | /* Disable interrupt from device */ | |
da0436e9 | 8391 | lpfc_sli4_disable_intr(phba); |
3a55b532 JS |
8392 | |
8393 | /* Save device state to PCI config space */ | |
8394 | pci_save_state(pdev); | |
8395 | pci_set_power_state(pdev, PCI_D3hot); | |
8396 | ||
8397 | return 0; | |
8398 | } | |
8399 | ||
8400 | /** | |
da0436e9 | 8401 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
3a55b532 JS |
8402 | * @pdev: pointer to PCI device |
8403 | * | |
da0436e9 JS |
8404 | * This routine is called from the kernel's PCI subsystem to support system |
8405 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes | |
8406 | * this method, it restores the device's PCI config space state and fully | |
8407 | * reinitializes the device and brings it online. Note that as the driver | |
8408 | * implements the minimum PM requirements to a power-aware driver's PM for | |
8409 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
8410 | * to the suspend() method call will be treated as SUSPEND and the driver | |
8411 | * will fully reinitialize its device during resume() method call, the device | |
8412 | * will be set to PCI_D0 directly in PCI config space before restoring the | |
8413 | * state. | |
3a55b532 JS |
8414 | * |
8415 | * Return code | |
3772a991 JS |
8416 | * 0 - driver suspended the device |
8417 | * Error otherwise | |
3a55b532 JS |
8418 | **/ |
8419 | static int | |
da0436e9 | 8420 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
3a55b532 JS |
8421 | { |
8422 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8423 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
5b75da2f | 8424 | uint32_t intr_mode; |
3a55b532 JS |
8425 | int error; |
8426 | ||
8427 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
da0436e9 | 8428 | "0292 PCI device Power Management resume.\n"); |
3a55b532 JS |
8429 | |
8430 | /* Restore device state from PCI config space */ | |
8431 | pci_set_power_state(pdev, PCI_D0); | |
8432 | pci_restore_state(pdev); | |
1dfb5a47 JS |
8433 | |
8434 | /* | |
8435 | * As the new kernel behavior of pci_restore_state() API call clears | |
8436 | * device saved_state flag, need to save the restored state again. | |
8437 | */ | |
8438 | pci_save_state(pdev); | |
8439 | ||
3a55b532 JS |
8440 | if (pdev->is_busmaster) |
8441 | pci_set_master(pdev); | |
8442 | ||
da0436e9 | 8443 | /* Startup the kernel thread for this host adapter. */ |
3a55b532 JS |
8444 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
8445 | "lpfc_worker_%d", phba->brd_no); | |
8446 | if (IS_ERR(phba->worker_thread)) { | |
8447 | error = PTR_ERR(phba->worker_thread); | |
8448 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8449 | "0293 PM resume failed to start worker " |
3a55b532 JS |
8450 | "thread: error=x%x.\n", error); |
8451 | return error; | |
8452 | } | |
8453 | ||
5b75da2f | 8454 | /* Configure and enable interrupt */ |
da0436e9 | 8455 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
5b75da2f | 8456 | if (intr_mode == LPFC_INTR_ERROR) { |
3a55b532 | 8457 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 8458 | "0294 PM resume Failed to enable interrupt\n"); |
5b75da2f JS |
8459 | return -EIO; |
8460 | } else | |
8461 | phba->intr_mode = intr_mode; | |
3a55b532 JS |
8462 | |
8463 | /* Restart HBA and bring it online */ | |
8464 | lpfc_sli_brdrestart(phba); | |
8465 | lpfc_online(phba); | |
8466 | ||
5b75da2f JS |
8467 | /* Log the current active interrupt mode */ |
8468 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
8469 | ||
3a55b532 JS |
8470 | return 0; |
8471 | } | |
8472 | ||
75baf696 JS |
8473 | /** |
8474 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover | |
8475 | * @phba: pointer to lpfc hba data structure. | |
8476 | * | |
8477 | * This routine is called to prepare the SLI4 device for PCI slot recover. It | |
8478 | * aborts all the outstanding SCSI I/Os to the pci device. | |
8479 | **/ | |
8480 | static void | |
8481 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) | |
8482 | { | |
8483 | struct lpfc_sli *psli = &phba->sli; | |
8484 | struct lpfc_sli_ring *pring; | |
8485 | ||
8486 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8487 | "2828 PCI channel I/O abort preparing for recovery\n"); | |
8488 | /* | |
8489 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
8490 | * and let the SCSI mid-layer to retry them to recover. | |
8491 | */ | |
8492 | pring = &psli->ring[psli->fcp_ring]; | |
8493 | lpfc_sli_abort_iocb_ring(phba, pring); | |
8494 | } | |
8495 | ||
8496 | /** | |
8497 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset | |
8498 | * @phba: pointer to lpfc hba data structure. | |
8499 | * | |
8500 | * This routine is called to prepare the SLI4 device for PCI slot reset. It | |
8501 | * disables the device interrupt and pci device, and aborts the internal FCP | |
8502 | * pending I/Os. | |
8503 | **/ | |
8504 | static void | |
8505 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) | |
8506 | { | |
8507 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8508 | "2826 PCI channel disable preparing for reset\n"); | |
8509 | ||
8510 | /* Block any management I/Os to the device */ | |
8511 | lpfc_block_mgmt_io(phba); | |
8512 | ||
8513 | /* Block all SCSI devices' I/Os on the host */ | |
8514 | lpfc_scsi_dev_block(phba); | |
8515 | ||
8516 | /* stop all timers */ | |
8517 | lpfc_stop_hba_timers(phba); | |
8518 | ||
8519 | /* Disable interrupt and pci device */ | |
8520 | lpfc_sli4_disable_intr(phba); | |
8521 | pci_disable_device(phba->pcidev); | |
8522 | ||
8523 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ | |
8524 | lpfc_sli_flush_fcp_rings(phba); | |
8525 | } | |
8526 | ||
8527 | /** | |
8528 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable | |
8529 | * @phba: pointer to lpfc hba data structure. | |
8530 | * | |
8531 | * This routine is called to prepare the SLI4 device for PCI slot permanently | |
8532 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
8533 | * pending I/Os. | |
8534 | **/ | |
8535 | static void | |
8536 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) | |
8537 | { | |
8538 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8539 | "2827 PCI channel permanent disable for failure\n"); | |
8540 | ||
8541 | /* Block all SCSI devices' I/Os on the host */ | |
8542 | lpfc_scsi_dev_block(phba); | |
8543 | ||
8544 | /* stop all timers */ | |
8545 | lpfc_stop_hba_timers(phba); | |
8546 | ||
8547 | /* Clean up all driver's outstanding SCSI I/Os */ | |
8548 | lpfc_sli_flush_fcp_rings(phba); | |
8549 | } | |
8550 | ||
8d63f375 | 8551 | /** |
da0436e9 | 8552 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
e59058c4 JS |
8553 | * @pdev: pointer to PCI device. |
8554 | * @state: the current PCI connection state. | |
8d63f375 | 8555 | * |
da0436e9 JS |
8556 | * This routine is called from the PCI subsystem for error handling to device |
8557 | * with SLI-4 interface spec. This function is called by the PCI subsystem | |
8558 | * after a PCI bus error affecting this device has been detected. When this | |
8559 | * function is invoked, it will need to stop all the I/Os and interrupt(s) | |
8560 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET | |
8561 | * for the PCI subsystem to perform proper recovery as desired. | |
e59058c4 JS |
8562 | * |
8563 | * Return codes | |
3772a991 JS |
8564 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
8565 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
e59058c4 | 8566 | **/ |
3772a991 | 8567 | static pci_ers_result_t |
da0436e9 | 8568 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
8d63f375 | 8569 | { |
75baf696 JS |
8570 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
8571 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8572 | ||
8573 | switch (state) { | |
8574 | case pci_channel_io_normal: | |
8575 | /* Non-fatal error, prepare for recovery */ | |
8576 | lpfc_sli4_prep_dev_for_recover(phba); | |
8577 | return PCI_ERS_RESULT_CAN_RECOVER; | |
8578 | case pci_channel_io_frozen: | |
8579 | /* Fatal error, prepare for slot reset */ | |
8580 | lpfc_sli4_prep_dev_for_reset(phba); | |
8581 | return PCI_ERS_RESULT_NEED_RESET; | |
8582 | case pci_channel_io_perm_failure: | |
8583 | /* Permanent failure, prepare for device down */ | |
8584 | lpfc_sli4_prep_dev_for_perm_failure(phba); | |
8585 | return PCI_ERS_RESULT_DISCONNECT; | |
8586 | default: | |
8587 | /* Unknown state, prepare and request slot reset */ | |
8588 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8589 | "2825 Unknown PCI error state: x%x\n", state); | |
8590 | lpfc_sli4_prep_dev_for_reset(phba); | |
8591 | return PCI_ERS_RESULT_NEED_RESET; | |
8592 | } | |
8d63f375 LV |
8593 | } |
8594 | ||
8595 | /** | |
da0436e9 | 8596 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
e59058c4 JS |
8597 | * @pdev: pointer to PCI device. |
8598 | * | |
da0436e9 JS |
8599 | * This routine is called from the PCI subsystem for error handling to device |
8600 | * with SLI-4 interface spec. It is called after PCI bus has been reset to | |
8601 | * restart the PCI card from scratch, as if from a cold-boot. During the | |
8602 | * PCI subsystem error recovery, after the driver returns | |
3772a991 | 8603 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
da0436e9 JS |
8604 | * recovery and then call this routine before calling the .resume method to |
8605 | * recover the device. This function will initialize the HBA device, enable | |
8606 | * the interrupt, but it will just put the HBA to offline state without | |
8607 | * passing any I/O traffic. | |
8d63f375 | 8608 | * |
e59058c4 | 8609 | * Return codes |
3772a991 JS |
8610 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
8611 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8d63f375 | 8612 | */ |
3772a991 | 8613 | static pci_ers_result_t |
da0436e9 | 8614 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
8d63f375 | 8615 | { |
75baf696 JS |
8616 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
8617 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8618 | struct lpfc_sli *psli = &phba->sli; | |
8619 | uint32_t intr_mode; | |
8620 | ||
8621 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
8622 | if (pci_enable_device_mem(pdev)) { | |
8623 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
8624 | "PCI device after reset.\n"); | |
8625 | return PCI_ERS_RESULT_DISCONNECT; | |
8626 | } | |
8627 | ||
8628 | pci_restore_state(pdev); | |
8629 | if (pdev->is_busmaster) | |
8630 | pci_set_master(pdev); | |
8631 | ||
8632 | spin_lock_irq(&phba->hbalock); | |
8633 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
8634 | spin_unlock_irq(&phba->hbalock); | |
8635 | ||
8636 | /* Configure and enable interrupt */ | |
8637 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); | |
8638 | if (intr_mode == LPFC_INTR_ERROR) { | |
8639 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8640 | "2824 Cannot re-enable interrupt after " | |
8641 | "slot reset.\n"); | |
8642 | return PCI_ERS_RESULT_DISCONNECT; | |
8643 | } else | |
8644 | phba->intr_mode = intr_mode; | |
8645 | ||
8646 | /* Log the current active interrupt mode */ | |
8647 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
8648 | ||
8d63f375 LV |
8649 | return PCI_ERS_RESULT_RECOVERED; |
8650 | } | |
8651 | ||
8652 | /** | |
da0436e9 | 8653 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
e59058c4 | 8654 | * @pdev: pointer to PCI device |
8d63f375 | 8655 | * |
3772a991 | 8656 | * This routine is called from the PCI subsystem for error handling to device |
da0436e9 | 8657 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
3772a991 JS |
8658 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
8659 | * error recovery. After this call, traffic can start to flow from this device | |
8660 | * again. | |
da0436e9 | 8661 | **/ |
3772a991 | 8662 | static void |
da0436e9 | 8663 | lpfc_io_resume_s4(struct pci_dev *pdev) |
8d63f375 | 8664 | { |
75baf696 JS |
8665 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
8666 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8667 | ||
8668 | /* | |
8669 | * In case of slot reset, as function reset is performed through | |
8670 | * mailbox command which needs DMA to be enabled, this operation | |
8671 | * has to be moved to the io resume phase. Taking device offline | |
8672 | * will perform the necessary cleanup. | |
8673 | */ | |
8674 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { | |
8675 | /* Perform device reset */ | |
8676 | lpfc_offline_prep(phba); | |
8677 | lpfc_offline(phba); | |
8678 | lpfc_sli_brdrestart(phba); | |
8679 | /* Bring the device back online */ | |
8680 | lpfc_online(phba); | |
8681 | } | |
8682 | ||
8683 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
8684 | if (phba->hba_flag & HBA_AER_ENABLED) | |
8685 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
8d63f375 LV |
8686 | } |
8687 | ||
3772a991 JS |
8688 | /** |
8689 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem | |
8690 | * @pdev: pointer to PCI device | |
8691 | * @pid: pointer to PCI device identifier | |
8692 | * | |
8693 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
8694 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks | |
8695 | * at PCI device-specific information of the device and driver to see if the | |
8696 | * driver state that it can support this kind of device. If the match is | |
8697 | * successful, the driver core invokes this routine. This routine dispatches | |
8698 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will | |
8699 | * do all the initialization that it needs to do to handle the HBA device | |
8700 | * properly. | |
8701 | * | |
8702 | * Return code | |
8703 | * 0 - driver can claim the device | |
8704 | * negative value - driver can not claim the device | |
8705 | **/ | |
8706 | static int __devinit | |
8707 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | |
8708 | { | |
8709 | int rc; | |
8fa38513 | 8710 | struct lpfc_sli_intf intf; |
3772a991 | 8711 | |
28baac74 | 8712 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
3772a991 JS |
8713 | return -ENODEV; |
8714 | ||
8fa38513 | 8715 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
28baac74 | 8716 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
da0436e9 | 8717 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
8fa38513 | 8718 | else |
3772a991 | 8719 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
8fa38513 | 8720 | |
3772a991 JS |
8721 | return rc; |
8722 | } | |
8723 | ||
8724 | /** | |
8725 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem | |
8726 | * @pdev: pointer to PCI device | |
8727 | * | |
8728 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
8729 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. | |
8730 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device | |
8731 | * remove routine, which will perform all the necessary cleanup for the | |
8732 | * device to be removed from the PCI subsystem properly. | |
8733 | **/ | |
8734 | static void __devexit | |
8735 | lpfc_pci_remove_one(struct pci_dev *pdev) | |
8736 | { | |
8737 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8738 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8739 | ||
8740 | switch (phba->pci_dev_grp) { | |
8741 | case LPFC_PCI_DEV_LP: | |
8742 | lpfc_pci_remove_one_s3(pdev); | |
8743 | break; | |
da0436e9 JS |
8744 | case LPFC_PCI_DEV_OC: |
8745 | lpfc_pci_remove_one_s4(pdev); | |
8746 | break; | |
3772a991 JS |
8747 | default: |
8748 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8749 | "1424 Invalid PCI device group: 0x%x\n", | |
8750 | phba->pci_dev_grp); | |
8751 | break; | |
8752 | } | |
8753 | return; | |
8754 | } | |
8755 | ||
8756 | /** | |
8757 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management | |
8758 | * @pdev: pointer to PCI device | |
8759 | * @msg: power management message | |
8760 | * | |
8761 | * This routine is to be registered to the kernel's PCI subsystem to support | |
8762 | * system Power Management (PM). When PM invokes this method, it dispatches | |
8763 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will | |
8764 | * suspend the device. | |
8765 | * | |
8766 | * Return code | |
8767 | * 0 - driver suspended the device | |
8768 | * Error otherwise | |
8769 | **/ | |
8770 | static int | |
8771 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | |
8772 | { | |
8773 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8774 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8775 | int rc = -ENODEV; | |
8776 | ||
8777 | switch (phba->pci_dev_grp) { | |
8778 | case LPFC_PCI_DEV_LP: | |
8779 | rc = lpfc_pci_suspend_one_s3(pdev, msg); | |
8780 | break; | |
da0436e9 JS |
8781 | case LPFC_PCI_DEV_OC: |
8782 | rc = lpfc_pci_suspend_one_s4(pdev, msg); | |
8783 | break; | |
3772a991 JS |
8784 | default: |
8785 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8786 | "1425 Invalid PCI device group: 0x%x\n", | |
8787 | phba->pci_dev_grp); | |
8788 | break; | |
8789 | } | |
8790 | return rc; | |
8791 | } | |
8792 | ||
8793 | /** | |
8794 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management | |
8795 | * @pdev: pointer to PCI device | |
8796 | * | |
8797 | * This routine is to be registered to the kernel's PCI subsystem to support | |
8798 | * system Power Management (PM). When PM invokes this method, it dispatches | |
8799 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will | |
8800 | * resume the device. | |
8801 | * | |
8802 | * Return code | |
8803 | * 0 - driver suspended the device | |
8804 | * Error otherwise | |
8805 | **/ | |
8806 | static int | |
8807 | lpfc_pci_resume_one(struct pci_dev *pdev) | |
8808 | { | |
8809 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8810 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8811 | int rc = -ENODEV; | |
8812 | ||
8813 | switch (phba->pci_dev_grp) { | |
8814 | case LPFC_PCI_DEV_LP: | |
8815 | rc = lpfc_pci_resume_one_s3(pdev); | |
8816 | break; | |
da0436e9 JS |
8817 | case LPFC_PCI_DEV_OC: |
8818 | rc = lpfc_pci_resume_one_s4(pdev); | |
8819 | break; | |
3772a991 JS |
8820 | default: |
8821 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8822 | "1426 Invalid PCI device group: 0x%x\n", | |
8823 | phba->pci_dev_grp); | |
8824 | break; | |
8825 | } | |
8826 | return rc; | |
8827 | } | |
8828 | ||
8829 | /** | |
8830 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error | |
8831 | * @pdev: pointer to PCI device. | |
8832 | * @state: the current PCI connection state. | |
8833 | * | |
8834 | * This routine is registered to the PCI subsystem for error handling. This | |
8835 | * function is called by the PCI subsystem after a PCI bus error affecting | |
8836 | * this device has been detected. When this routine is invoked, it dispatches | |
8837 | * the action to the proper SLI-3 or SLI-4 device error detected handling | |
8838 | * routine, which will perform the proper error detected operation. | |
8839 | * | |
8840 | * Return codes | |
8841 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery | |
8842 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8843 | **/ | |
8844 | static pci_ers_result_t | |
8845 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | |
8846 | { | |
8847 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8848 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8849 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
8850 | ||
8851 | switch (phba->pci_dev_grp) { | |
8852 | case LPFC_PCI_DEV_LP: | |
8853 | rc = lpfc_io_error_detected_s3(pdev, state); | |
8854 | break; | |
da0436e9 JS |
8855 | case LPFC_PCI_DEV_OC: |
8856 | rc = lpfc_io_error_detected_s4(pdev, state); | |
8857 | break; | |
3772a991 JS |
8858 | default: |
8859 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8860 | "1427 Invalid PCI device group: 0x%x\n", | |
8861 | phba->pci_dev_grp); | |
8862 | break; | |
8863 | } | |
8864 | return rc; | |
8865 | } | |
8866 | ||
8867 | /** | |
8868 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch | |
8869 | * @pdev: pointer to PCI device. | |
8870 | * | |
8871 | * This routine is registered to the PCI subsystem for error handling. This | |
8872 | * function is called after PCI bus has been reset to restart the PCI card | |
8873 | * from scratch, as if from a cold-boot. When this routine is invoked, it | |
8874 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling | |
8875 | * routine, which will perform the proper device reset. | |
8876 | * | |
8877 | * Return codes | |
8878 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
8879 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8880 | **/ | |
8881 | static pci_ers_result_t | |
8882 | lpfc_io_slot_reset(struct pci_dev *pdev) | |
8883 | { | |
8884 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8885 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8886 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
8887 | ||
8888 | switch (phba->pci_dev_grp) { | |
8889 | case LPFC_PCI_DEV_LP: | |
8890 | rc = lpfc_io_slot_reset_s3(pdev); | |
8891 | break; | |
da0436e9 JS |
8892 | case LPFC_PCI_DEV_OC: |
8893 | rc = lpfc_io_slot_reset_s4(pdev); | |
8894 | break; | |
3772a991 JS |
8895 | default: |
8896 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8897 | "1428 Invalid PCI device group: 0x%x\n", | |
8898 | phba->pci_dev_grp); | |
8899 | break; | |
8900 | } | |
8901 | return rc; | |
8902 | } | |
8903 | ||
8904 | /** | |
8905 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation | |
8906 | * @pdev: pointer to PCI device | |
8907 | * | |
8908 | * This routine is registered to the PCI subsystem for error handling. It | |
8909 | * is called when kernel error recovery tells the lpfc driver that it is | |
8910 | * OK to resume normal PCI operation after PCI bus error recovery. When | |
8911 | * this routine is invoked, it dispatches the action to the proper SLI-3 | |
8912 | * or SLI-4 device io_resume routine, which will resume the device operation. | |
8913 | **/ | |
8914 | static void | |
8915 | lpfc_io_resume(struct pci_dev *pdev) | |
8916 | { | |
8917 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8918 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8919 | ||
8920 | switch (phba->pci_dev_grp) { | |
8921 | case LPFC_PCI_DEV_LP: | |
8922 | lpfc_io_resume_s3(pdev); | |
8923 | break; | |
da0436e9 JS |
8924 | case LPFC_PCI_DEV_OC: |
8925 | lpfc_io_resume_s4(pdev); | |
8926 | break; | |
3772a991 JS |
8927 | default: |
8928 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8929 | "1429 Invalid PCI device group: 0x%x\n", | |
8930 | phba->pci_dev_grp); | |
8931 | break; | |
8932 | } | |
8933 | return; | |
8934 | } | |
8935 | ||
dea3101e | 8936 | static struct pci_device_id lpfc_id_table[] = { |
8937 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, | |
8938 | PCI_ANY_ID, PCI_ANY_ID, }, | |
06325e74 JSEC |
8939 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
8940 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e | 8941 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
8942 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8943 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, | |
8944 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8945 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, | |
8946 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8947 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, | |
8948 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8949 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, | |
8950 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8951 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, | |
8952 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8953 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, | |
8954 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
8955 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
8956 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8957 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, | |
8958 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8959 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, | |
8960 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e | 8961 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
8962 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
8963 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
8964 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8965 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, | |
8966 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e | 8967 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
8968 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8969 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, | |
8970 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8971 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, | |
8972 | PCI_ANY_ID, PCI_ANY_ID, }, | |
84774a4d JS |
8973 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
8974 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
8975 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
8976 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8977 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, | |
8978 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e | 8979 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
8980 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8981 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, | |
8982 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8983 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, | |
8984 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8985 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, | |
8986 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8987 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, | |
8988 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
8989 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
8990 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8991 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, | |
8992 | PCI_ANY_ID, PCI_ANY_ID, }, | |
b87eab38 JS |
8993 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
8994 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8995 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, | |
8996 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8997 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, | |
8998 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8999 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, | |
9000 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9001 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, | |
9002 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9003 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, | |
9004 | PCI_ANY_ID, PCI_ANY_ID, }, | |
84774a4d JS |
9005 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
9006 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9007 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, | |
9008 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9009 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, | |
9010 | PCI_ANY_ID, PCI_ANY_ID, }, | |
3772a991 JS |
9011 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, |
9012 | PCI_ANY_ID, PCI_ANY_ID, }, | |
a747c9ce JS |
9013 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT, |
9014 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9015 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON, | |
6669f9bb | 9016 | PCI_ANY_ID, PCI_ANY_ID, }, |
98fc5dd9 JS |
9017 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS, |
9018 | PCI_ANY_ID, PCI_ANY_ID, }, | |
085c647c JS |
9019 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC, |
9020 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9021 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE, | |
9022 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e | 9023 | { 0 } |
9024 | }; | |
9025 | ||
9026 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); | |
9027 | ||
8d63f375 LV |
9028 | static struct pci_error_handlers lpfc_err_handler = { |
9029 | .error_detected = lpfc_io_error_detected, | |
9030 | .slot_reset = lpfc_io_slot_reset, | |
9031 | .resume = lpfc_io_resume, | |
9032 | }; | |
9033 | ||
dea3101e | 9034 | static struct pci_driver lpfc_driver = { |
9035 | .name = LPFC_DRIVER_NAME, | |
9036 | .id_table = lpfc_id_table, | |
9037 | .probe = lpfc_pci_probe_one, | |
9038 | .remove = __devexit_p(lpfc_pci_remove_one), | |
3a55b532 | 9039 | .suspend = lpfc_pci_suspend_one, |
3772a991 | 9040 | .resume = lpfc_pci_resume_one, |
2e0fef85 | 9041 | .err_handler = &lpfc_err_handler, |
dea3101e | 9042 | }; |
9043 | ||
e59058c4 | 9044 | /** |
3621a710 | 9045 | * lpfc_init - lpfc module initialization routine |
e59058c4 JS |
9046 | * |
9047 | * This routine is to be invoked when the lpfc module is loaded into the | |
9048 | * kernel. The special kernel macro module_init() is used to indicate the | |
9049 | * role of this routine to the kernel as lpfc module entry point. | |
9050 | * | |
9051 | * Return codes | |
9052 | * 0 - successful | |
9053 | * -ENOMEM - FC attach transport failed | |
9054 | * all others - failed | |
9055 | */ | |
dea3101e | 9056 | static int __init |
9057 | lpfc_init(void) | |
9058 | { | |
9059 | int error = 0; | |
9060 | ||
9061 | printk(LPFC_MODULE_DESC "\n"); | |
c44ce173 | 9062 | printk(LPFC_COPYRIGHT "\n"); |
dea3101e | 9063 | |
7ee5d43e JS |
9064 | if (lpfc_enable_npiv) { |
9065 | lpfc_transport_functions.vport_create = lpfc_vport_create; | |
9066 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; | |
9067 | } | |
dea3101e | 9068 | lpfc_transport_template = |
9069 | fc_attach_transport(&lpfc_transport_functions); | |
7ee5d43e | 9070 | if (lpfc_transport_template == NULL) |
dea3101e | 9071 | return -ENOMEM; |
7ee5d43e | 9072 | if (lpfc_enable_npiv) { |
7ee5d43e | 9073 | lpfc_vport_transport_template = |
98c9ea5c JS |
9074 | fc_attach_transport(&lpfc_vport_transport_functions); |
9075 | if (lpfc_vport_transport_template == NULL) { | |
9076 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e | 9077 | return -ENOMEM; |
98c9ea5c | 9078 | } |
7ee5d43e | 9079 | } |
dea3101e | 9080 | error = pci_register_driver(&lpfc_driver); |
92d7f7b0 | 9081 | if (error) { |
dea3101e | 9082 | fc_release_transport(lpfc_transport_template); |
d7c255b2 JS |
9083 | if (lpfc_enable_npiv) |
9084 | fc_release_transport(lpfc_vport_transport_template); | |
92d7f7b0 | 9085 | } |
dea3101e | 9086 | |
9087 | return error; | |
9088 | } | |
9089 | ||
e59058c4 | 9090 | /** |
3621a710 | 9091 | * lpfc_exit - lpfc module removal routine |
e59058c4 JS |
9092 | * |
9093 | * This routine is invoked when the lpfc module is removed from the kernel. | |
9094 | * The special kernel macro module_exit() is used to indicate the role of | |
9095 | * this routine to the kernel as lpfc module exit point. | |
9096 | */ | |
dea3101e | 9097 | static void __exit |
9098 | lpfc_exit(void) | |
9099 | { | |
9100 | pci_unregister_driver(&lpfc_driver); | |
9101 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e JS |
9102 | if (lpfc_enable_npiv) |
9103 | fc_release_transport(lpfc_vport_transport_template); | |
81301a9b | 9104 | if (_dump_buf_data) { |
6a9c52cf JS |
9105 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
9106 | "_dump_buf_data at 0x%p\n", | |
81301a9b JS |
9107 | (1L << _dump_buf_data_order), _dump_buf_data); |
9108 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); | |
9109 | } | |
9110 | ||
9111 | if (_dump_buf_dif) { | |
6a9c52cf JS |
9112 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
9113 | "_dump_buf_dif at 0x%p\n", | |
81301a9b JS |
9114 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
9115 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); | |
9116 | } | |
dea3101e | 9117 | } |
9118 | ||
9119 | module_init(lpfc_init); | |
9120 | module_exit(lpfc_exit); | |
9121 | MODULE_LICENSE("GPL"); | |
9122 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); | |
9123 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); | |
9124 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |