]>
Commit | Line | Data |
---|---|---|
dea3101e JB |
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 JB |
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 JB |
20 | *******************************************************************/ |
21 | ||
dea3101e JB |
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 JB |
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 JB |
40 | #include "lpfc_hw.h" |
41 | #include "lpfc_sli.h" | |
da0436e9 | 42 | #include "lpfc_sli4.h" |
ea2151b4 | 43 | #include "lpfc_nl.h" |
dea3101e JB |
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 JB |
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 JB |
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 JB |
75 | |
76 | static struct scsi_transport_template *lpfc_transport_template = NULL; | |
92d7f7b0 | 77 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
dea3101e JB |
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 JB |
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 JB |
106 | |
107 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
108 | if (!pmb) { | |
2e0fef85 | 109 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
110 | return -ENOMEM; |
111 | } | |
112 | ||
04c68496 | 113 | mb = &pmb->u.mb; |
2e0fef85 | 114 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e JB |
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 JB |
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 JB |
136 | "error, mbxCmd x%x READ_NVPARM, " |
137 | "mbxStatus x%x\n", | |
dea3101e JB |
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 JB |
146 | } |
147 | ||
92d7f7b0 JS |
148 | phba->sli3_options = 0x0; |
149 | ||
dea3101e JB |
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 JB |
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 JB |
172 | mempool_free(pmb, phba->mbox_mem_pool); |
173 | return -ERESTART; | |
dea3101e JB |
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 JB |
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 JB |
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 JB |
211 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
212 | if (!lpfc_vpd_data) | |
d7c255b2 | 213 | goto out_free_mbox; |
dea3101e JB |
214 | |
215 | do { | |
a0c87cbd | 216 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
dea3101e JB |
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 JB |
239 | |
240 | kfree(lpfc_vpd_data); | |
dea3101e JB |
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 JB |
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 JB |
346 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
347 | if (!pmb) { | |
2e0fef85 | 348 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
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 JB |
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 JB |
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 JB |
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 JB |
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 JB |
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 JB |
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 JB |
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 JB |
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 JB |
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 JB |
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 JB |
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 JB |
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 JB |
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 JB |
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 | } | |
da0436e9 JS |
816 | /** |
817 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset | |
818 | * @phba: pointer to lpfc HBA data structure. | |
819 | * | |
820 | * This routine will do uninitialization after the HBA is reset when bring | |
821 | * down the SLI Layer. | |
822 | * | |
823 | * Return codes | |
af901ca1 | 824 | * 0 - success. |
da0436e9 JS |
825 | * Any other value - error. |
826 | **/ | |
827 | static int | |
828 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) | |
829 | { | |
830 | struct lpfc_scsi_buf *psb, *psb_next; | |
831 | LIST_HEAD(aborts); | |
832 | int ret; | |
833 | unsigned long iflag = 0; | |
0f65ff68 JS |
834 | struct lpfc_sglq *sglq_entry = NULL; |
835 | ||
da0436e9 JS |
836 | ret = lpfc_hba_down_post_s3(phba); |
837 | if (ret) | |
838 | return ret; | |
839 | /* At this point in time the HBA is either reset or DOA. Either | |
840 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be | |
841 | * on the lpfc_sgl_list so that it can either be freed if the | |
842 | * driver is unloading or reposted if the driver is restarting | |
843 | * the port. | |
844 | */ | |
845 | spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */ | |
846 | /* scsl_buf_list */ | |
847 | /* abts_sgl_list_lock required because worker thread uses this | |
848 | * list. | |
849 | */ | |
850 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); | |
0f65ff68 JS |
851 | list_for_each_entry(sglq_entry, |
852 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) | |
853 | sglq_entry->state = SGL_FREED; | |
854 | ||
da0436e9 JS |
855 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
856 | &phba->sli4_hba.lpfc_sgl_list); | |
857 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); | |
858 | /* abts_scsi_buf_list_lock required because worker thread uses this | |
859 | * list. | |
860 | */ | |
861 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
862 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, | |
863 | &aborts); | |
864 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
865 | spin_unlock_irq(&phba->hbalock); | |
866 | ||
867 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { | |
868 | psb->pCmd = NULL; | |
869 | psb->status = IOSTAT_SUCCESS; | |
870 | } | |
871 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); | |
872 | list_splice(&aborts, &phba->lpfc_scsi_buf_list); | |
873 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); | |
874 | return 0; | |
875 | } | |
876 | ||
877 | /** | |
878 | * lpfc_hba_down_post - Wrapper func for hba down post routine | |
879 | * @phba: pointer to lpfc HBA data structure. | |
880 | * | |
881 | * This routine wraps the actual SLI3 or SLI4 routine for performing | |
882 | * uninitialization after the HBA is reset when bring down the SLI Layer. | |
883 | * | |
884 | * Return codes | |
af901ca1 | 885 | * 0 - success. |
da0436e9 JS |
886 | * Any other value - error. |
887 | **/ | |
888 | int | |
889 | lpfc_hba_down_post(struct lpfc_hba *phba) | |
890 | { | |
891 | return (*phba->lpfc_hba_down_post)(phba); | |
892 | } | |
41415862 | 893 | |
e59058c4 | 894 | /** |
3621a710 | 895 | * lpfc_hb_timeout - The HBA-timer timeout handler |
e59058c4 JS |
896 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
897 | * | |
898 | * This is the HBA-timer timeout handler registered to the lpfc driver. When | |
899 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver | |
900 | * work-port-events bitmap and the worker thread is notified. This timeout | |
901 | * event will be used by the worker thread to invoke the actual timeout | |
902 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will | |
903 | * be performed in the timeout handler and the HBA timeout event bit shall | |
904 | * be cleared by the worker thread after it has taken the event bitmap out. | |
905 | **/ | |
a6ababd2 | 906 | static void |
858c9f6c JS |
907 | lpfc_hb_timeout(unsigned long ptr) |
908 | { | |
909 | struct lpfc_hba *phba; | |
5e9d9b82 | 910 | uint32_t tmo_posted; |
858c9f6c JS |
911 | unsigned long iflag; |
912 | ||
913 | phba = (struct lpfc_hba *)ptr; | |
9399627f JS |
914 | |
915 | /* Check for heart beat timeout conditions */ | |
858c9f6c | 916 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
5e9d9b82 JS |
917 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
918 | if (!tmo_posted) | |
858c9f6c JS |
919 | phba->pport->work_port_events |= WORKER_HB_TMO; |
920 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
921 | ||
9399627f | 922 | /* Tell the worker thread there is work to do */ |
5e9d9b82 JS |
923 | if (!tmo_posted) |
924 | lpfc_worker_wake_up(phba); | |
858c9f6c JS |
925 | return; |
926 | } | |
927 | ||
e59058c4 | 928 | /** |
3621a710 | 929 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
e59058c4 JS |
930 | * @phba: pointer to lpfc hba data structure. |
931 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
932 | * | |
933 | * This is the callback function to the lpfc heart-beat mailbox command. | |
934 | * If configured, the lpfc driver issues the heart-beat mailbox command to | |
935 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the | |
936 | * heart-beat mailbox command is issued, the driver shall set up heart-beat | |
937 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks | |
938 | * heart-beat outstanding state. Once the mailbox command comes back and | |
939 | * no error conditions detected, the heart-beat mailbox command timer is | |
940 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding | |
941 | * state is cleared for the next heart-beat. If the timer expired with the | |
942 | * heart-beat outstanding state set, the driver will put the HBA offline. | |
943 | **/ | |
858c9f6c JS |
944 | static void |
945 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
946 | { | |
947 | unsigned long drvr_flag; | |
948 | ||
949 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
950 | phba->hb_outstanding = 0; | |
951 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
952 | ||
9399627f | 953 | /* Check and reset heart-beat timer is necessary */ |
858c9f6c JS |
954 | mempool_free(pmboxq, phba->mbox_mem_pool); |
955 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && | |
956 | !(phba->link_state == LPFC_HBA_ERROR) && | |
51ef4c26 | 957 | !(phba->pport->load_flag & FC_UNLOADING)) |
858c9f6c JS |
958 | mod_timer(&phba->hb_tmofunc, |
959 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
960 | return; | |
961 | } | |
962 | ||
e59058c4 | 963 | /** |
3621a710 | 964 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
e59058c4 JS |
965 | * @phba: pointer to lpfc hba data structure. |
966 | * | |
967 | * This is the actual HBA-timer timeout handler to be invoked by the worker | |
968 | * thread whenever the HBA timer fired and HBA-timeout event posted. This | |
969 | * handler performs any periodic operations needed for the device. If such | |
970 | * periodic event has already been attended to either in the interrupt handler | |
971 | * or by processing slow-ring or fast-ring events within the HBA-timer | |
972 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets | |
973 | * the timer for the next timeout period. If lpfc heart-beat mailbox command | |
974 | * is configured and there is no heart-beat mailbox command outstanding, a | |
975 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there | |
976 | * has been a heart-beat mailbox command outstanding, the HBA shall be put | |
977 | * to offline. | |
978 | **/ | |
858c9f6c JS |
979 | void |
980 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) | |
981 | { | |
45ed1190 | 982 | struct lpfc_vport **vports; |
858c9f6c | 983 | LPFC_MBOXQ_t *pmboxq; |
0ff10d46 | 984 | struct lpfc_dmabuf *buf_ptr; |
45ed1190 | 985 | int retval, i; |
858c9f6c | 986 | struct lpfc_sli *psli = &phba->sli; |
0ff10d46 | 987 | LIST_HEAD(completions); |
858c9f6c | 988 | |
45ed1190 JS |
989 | vports = lpfc_create_vport_work_array(phba); |
990 | if (vports != NULL) | |
991 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) | |
992 | lpfc_rcv_seq_check_edtov(vports[i]); | |
993 | lpfc_destroy_vport_work_array(phba, vports); | |
994 | ||
858c9f6c | 995 | if ((phba->link_state == LPFC_HBA_ERROR) || |
51ef4c26 | 996 | (phba->pport->load_flag & FC_UNLOADING) || |
858c9f6c JS |
997 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
998 | return; | |
999 | ||
1000 | spin_lock_irq(&phba->pport->work_port_lock); | |
858c9f6c JS |
1001 | |
1002 | if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, | |
1003 | jiffies)) { | |
1004 | spin_unlock_irq(&phba->pport->work_port_lock); | |
1005 | if (!phba->hb_outstanding) | |
1006 | mod_timer(&phba->hb_tmofunc, | |
1007 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
1008 | else | |
1009 | mod_timer(&phba->hb_tmofunc, | |
1010 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | |
1011 | return; | |
1012 | } | |
1013 | spin_unlock_irq(&phba->pport->work_port_lock); | |
1014 | ||
0ff10d46 JS |
1015 | if (phba->elsbuf_cnt && |
1016 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { | |
1017 | spin_lock_irq(&phba->hbalock); | |
1018 | list_splice_init(&phba->elsbuf, &completions); | |
1019 | phba->elsbuf_cnt = 0; | |
1020 | phba->elsbuf_prev_cnt = 0; | |
1021 | spin_unlock_irq(&phba->hbalock); | |
1022 | ||
1023 | while (!list_empty(&completions)) { | |
1024 | list_remove_head(&completions, buf_ptr, | |
1025 | struct lpfc_dmabuf, list); | |
1026 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
1027 | kfree(buf_ptr); | |
1028 | } | |
1029 | } | |
1030 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; | |
1031 | ||
858c9f6c | 1032 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
13815c83 JS |
1033 | if (phba->cfg_enable_hba_heartbeat) { |
1034 | if (!phba->hb_outstanding) { | |
1035 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); | |
1036 | if (!pmboxq) { | |
1037 | mod_timer(&phba->hb_tmofunc, | |
1038 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
1039 | return; | |
1040 | } | |
858c9f6c | 1041 | |
13815c83 JS |
1042 | lpfc_heart_beat(phba, pmboxq); |
1043 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; | |
1044 | pmboxq->vport = phba->pport; | |
1045 | retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); | |
858c9f6c | 1046 | |
13815c83 JS |
1047 | if (retval != MBX_BUSY && retval != MBX_SUCCESS) { |
1048 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
1049 | mod_timer(&phba->hb_tmofunc, | |
1050 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
1051 | return; | |
1052 | } | |
858c9f6c | 1053 | mod_timer(&phba->hb_tmofunc, |
13815c83 JS |
1054 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
1055 | phba->hb_outstanding = 1; | |
858c9f6c | 1056 | return; |
13815c83 JS |
1057 | } else { |
1058 | /* | |
1059 | * If heart beat timeout called with hb_outstanding set | |
1060 | * we need to take the HBA offline. | |
1061 | */ | |
1062 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1063 | "0459 Adapter heartbeat failure, " | |
1064 | "taking this port offline.\n"); | |
1065 | ||
1066 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1067 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
13815c83 JS |
1068 | spin_unlock_irq(&phba->hbalock); |
1069 | ||
1070 | lpfc_offline_prep(phba); | |
1071 | lpfc_offline(phba); | |
1072 | lpfc_unblock_mgmt_io(phba); | |
1073 | phba->link_state = LPFC_HBA_ERROR; | |
1074 | lpfc_hba_down_post(phba); | |
858c9f6c | 1075 | } |
858c9f6c JS |
1076 | } |
1077 | } | |
1078 | ||
e59058c4 | 1079 | /** |
3621a710 | 1080 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
e59058c4 JS |
1081 | * @phba: pointer to lpfc hba data structure. |
1082 | * | |
1083 | * This routine is called to bring the HBA offline when HBA hardware error | |
1084 | * other than Port Error 6 has been detected. | |
1085 | **/ | |
09372820 JS |
1086 | static void |
1087 | lpfc_offline_eratt(struct lpfc_hba *phba) | |
1088 | { | |
1089 | struct lpfc_sli *psli = &phba->sli; | |
1090 | ||
1091 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1092 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
09372820 JS |
1093 | spin_unlock_irq(&phba->hbalock); |
1094 | lpfc_offline_prep(phba); | |
1095 | ||
1096 | lpfc_offline(phba); | |
1097 | lpfc_reset_barrier(phba); | |
f4b4c68f | 1098 | spin_lock_irq(&phba->hbalock); |
09372820 | 1099 | lpfc_sli_brdreset(phba); |
f4b4c68f | 1100 | spin_unlock_irq(&phba->hbalock); |
09372820 JS |
1101 | lpfc_hba_down_post(phba); |
1102 | lpfc_sli_brdready(phba, HS_MBRDY); | |
1103 | lpfc_unblock_mgmt_io(phba); | |
1104 | phba->link_state = LPFC_HBA_ERROR; | |
1105 | return; | |
1106 | } | |
1107 | ||
da0436e9 JS |
1108 | /** |
1109 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention | |
1110 | * @phba: pointer to lpfc hba data structure. | |
1111 | * | |
1112 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error | |
1113 | * other than Port Error 6 has been detected. | |
1114 | **/ | |
1115 | static void | |
1116 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) | |
1117 | { | |
1118 | lpfc_offline_prep(phba); | |
1119 | lpfc_offline(phba); | |
1120 | lpfc_sli4_brdreset(phba); | |
1121 | lpfc_hba_down_post(phba); | |
1122 | lpfc_sli4_post_status_check(phba); | |
1123 | lpfc_unblock_mgmt_io(phba); | |
1124 | phba->link_state = LPFC_HBA_ERROR; | |
1125 | } | |
1126 | ||
a257bf90 JS |
1127 | /** |
1128 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler | |
1129 | * @phba: pointer to lpfc hba data structure. | |
1130 | * | |
1131 | * This routine is invoked to handle the deferred HBA hardware error | |
1132 | * conditions. This type of error is indicated by HBA by setting ER1 | |
1133 | * and another ER bit in the host status register. The driver will | |
1134 | * wait until the ER1 bit clears before handling the error condition. | |
1135 | **/ | |
1136 | static void | |
1137 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) | |
1138 | { | |
1139 | uint32_t old_host_status = phba->work_hs; | |
1140 | struct lpfc_sli_ring *pring; | |
1141 | struct lpfc_sli *psli = &phba->sli; | |
1142 | ||
f4b4c68f JS |
1143 | /* If the pci channel is offline, ignore possible errors, |
1144 | * since we cannot communicate with the pci card anyway. | |
1145 | */ | |
1146 | if (pci_channel_offline(phba->pcidev)) { | |
1147 | spin_lock_irq(&phba->hbalock); | |
1148 | phba->hba_flag &= ~DEFER_ERATT; | |
1149 | spin_unlock_irq(&phba->hbalock); | |
1150 | return; | |
1151 | } | |
1152 | ||
a257bf90 JS |
1153 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
1154 | "0479 Deferred Adapter Hardware Error " | |
1155 | "Data: x%x x%x x%x\n", | |
1156 | phba->work_hs, | |
1157 | phba->work_status[0], phba->work_status[1]); | |
1158 | ||
1159 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1160 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
a257bf90 JS |
1161 | spin_unlock_irq(&phba->hbalock); |
1162 | ||
1163 | ||
1164 | /* | |
1165 | * Firmware stops when it triggred erratt. That could cause the I/Os | |
1166 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the | |
1167 | * SCSI layer retry it after re-establishing link. | |
1168 | */ | |
1169 | pring = &psli->ring[psli->fcp_ring]; | |
1170 | lpfc_sli_abort_iocb_ring(phba, pring); | |
1171 | ||
1172 | /* | |
1173 | * There was a firmware error. Take the hba offline and then | |
1174 | * attempt to restart it. | |
1175 | */ | |
1176 | lpfc_offline_prep(phba); | |
1177 | lpfc_offline(phba); | |
1178 | ||
1179 | /* Wait for the ER1 bit to clear.*/ | |
1180 | while (phba->work_hs & HS_FFER1) { | |
1181 | msleep(100); | |
1182 | phba->work_hs = readl(phba->HSregaddr); | |
1183 | /* If driver is unloading let the worker thread continue */ | |
1184 | if (phba->pport->load_flag & FC_UNLOADING) { | |
1185 | phba->work_hs = 0; | |
1186 | break; | |
1187 | } | |
1188 | } | |
1189 | ||
1190 | /* | |
1191 | * This is to ptrotect against a race condition in which | |
1192 | * first write to the host attention register clear the | |
1193 | * host status register. | |
1194 | */ | |
1195 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) | |
1196 | phba->work_hs = old_host_status & ~HS_FFER1; | |
1197 | ||
3772a991 | 1198 | spin_lock_irq(&phba->hbalock); |
a257bf90 | 1199 | phba->hba_flag &= ~DEFER_ERATT; |
3772a991 | 1200 | spin_unlock_irq(&phba->hbalock); |
a257bf90 JS |
1201 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
1202 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); | |
1203 | } | |
1204 | ||
3772a991 JS |
1205 | static void |
1206 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) | |
1207 | { | |
1208 | struct lpfc_board_event_header board_event; | |
1209 | struct Scsi_Host *shost; | |
1210 | ||
1211 | board_event.event_type = FC_REG_BOARD_EVENT; | |
1212 | board_event.subcategory = LPFC_EVENT_PORTINTERR; | |
1213 | shost = lpfc_shost_from_vport(phba->pport); | |
1214 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1215 | sizeof(board_event), | |
1216 | (char *) &board_event, | |
1217 | LPFC_NL_VENDOR_ID); | |
1218 | } | |
1219 | ||
e59058c4 | 1220 | /** |
3772a991 | 1221 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
e59058c4 JS |
1222 | * @phba: pointer to lpfc hba data structure. |
1223 | * | |
1224 | * This routine is invoked to handle the following HBA hardware error | |
1225 | * conditions: | |
1226 | * 1 - HBA error attention interrupt | |
1227 | * 2 - DMA ring index out of range | |
1228 | * 3 - Mailbox command came back as unknown | |
1229 | **/ | |
3772a991 JS |
1230 | static void |
1231 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) | |
dea3101e | 1232 | { |
2e0fef85 | 1233 | struct lpfc_vport *vport = phba->pport; |
2e0fef85 | 1234 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 1235 | struct lpfc_sli_ring *pring; |
d2873e4c | 1236 | uint32_t event_data; |
57127f15 JS |
1237 | unsigned long temperature; |
1238 | struct temp_event temp_event_data; | |
92d7f7b0 | 1239 | struct Scsi_Host *shost; |
2e0fef85 | 1240 | |
8d63f375 | 1241 | /* If the pci channel is offline, ignore possible errors, |
3772a991 JS |
1242 | * since we cannot communicate with the pci card anyway. |
1243 | */ | |
1244 | if (pci_channel_offline(phba->pcidev)) { | |
1245 | spin_lock_irq(&phba->hbalock); | |
1246 | phba->hba_flag &= ~DEFER_ERATT; | |
1247 | spin_unlock_irq(&phba->hbalock); | |
8d63f375 | 1248 | return; |
3772a991 JS |
1249 | } |
1250 | ||
13815c83 JS |
1251 | /* If resets are disabled then leave the HBA alone and return */ |
1252 | if (!phba->cfg_enable_hba_reset) | |
1253 | return; | |
dea3101e | 1254 | |
ea2151b4 | 1255 | /* Send an internal error event to mgmt application */ |
3772a991 | 1256 | lpfc_board_errevt_to_mgmt(phba); |
ea2151b4 | 1257 | |
a257bf90 JS |
1258 | if (phba->hba_flag & DEFER_ERATT) |
1259 | lpfc_handle_deferred_eratt(phba); | |
1260 | ||
97eab634 | 1261 | if (phba->work_hs & HS_FFER6) { |
dea3101e JB |
1262 | /* Re-establishing Link */ |
1263 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
e8b62011 | 1264 | "1301 Re-establishing Link " |
dea3101e | 1265 | "Data: x%x x%x x%x\n", |
e8b62011 | 1266 | phba->work_hs, |
dea3101e | 1267 | phba->work_status[0], phba->work_status[1]); |
58da1ffb | 1268 | |
92d7f7b0 | 1269 | spin_lock_irq(&phba->hbalock); |
f4b4c68f | 1270 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
92d7f7b0 | 1271 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1272 | |
1273 | /* | |
1274 | * Firmware stops when it triggled erratt with HS_FFER6. | |
1275 | * That could cause the I/Os dropped by the firmware. | |
1276 | * Error iocb (I/O) on txcmplq and let the SCSI layer | |
1277 | * retry it after re-establishing link. | |
1278 | */ | |
1279 | pring = &psli->ring[psli->fcp_ring]; | |
1280 | lpfc_sli_abort_iocb_ring(phba, pring); | |
1281 | ||
dea3101e JB |
1282 | /* |
1283 | * There was a firmware error. Take the hba offline and then | |
1284 | * attempt to restart it. | |
1285 | */ | |
46fa311e | 1286 | lpfc_offline_prep(phba); |
dea3101e | 1287 | lpfc_offline(phba); |
41415862 | 1288 | lpfc_sli_brdrestart(phba); |
dea3101e | 1289 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
46fa311e | 1290 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
1291 | return; |
1292 | } | |
46fa311e | 1293 | lpfc_unblock_mgmt_io(phba); |
57127f15 JS |
1294 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
1295 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); | |
1296 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
1297 | temp_event_data.event_code = LPFC_CRIT_TEMP; | |
1298 | temp_event_data.data = (uint32_t)temperature; | |
1299 | ||
1300 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 1301 | "0406 Adapter maximum temperature exceeded " |
57127f15 JS |
1302 | "(%ld), taking this port offline " |
1303 | "Data: x%x x%x x%x\n", | |
1304 | temperature, phba->work_hs, | |
1305 | phba->work_status[0], phba->work_status[1]); | |
1306 | ||
1307 | shost = lpfc_shost_from_vport(phba->pport); | |
1308 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1309 | sizeof(temp_event_data), | |
1310 | (char *) &temp_event_data, | |
1311 | SCSI_NL_VID_TYPE_PCI | |
1312 | | PCI_VENDOR_ID_EMULEX); | |
1313 | ||
7af67051 | 1314 | spin_lock_irq(&phba->hbalock); |
7af67051 JS |
1315 | phba->over_temp_state = HBA_OVER_TEMP; |
1316 | spin_unlock_irq(&phba->hbalock); | |
09372820 | 1317 | lpfc_offline_eratt(phba); |
57127f15 | 1318 | |
dea3101e JB |
1319 | } else { |
1320 | /* The if clause above forces this code path when the status | |
9399627f JS |
1321 | * failure is a value other than FFER6. Do not call the offline |
1322 | * twice. This is the adapter hardware error path. | |
dea3101e JB |
1323 | */ |
1324 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 | 1325 | "0457 Adapter Hardware Error " |
dea3101e | 1326 | "Data: x%x x%x x%x\n", |
e8b62011 | 1327 | phba->work_hs, |
dea3101e JB |
1328 | phba->work_status[0], phba->work_status[1]); |
1329 | ||
d2873e4c | 1330 | event_data = FC_REG_DUMP_EVENT; |
92d7f7b0 | 1331 | shost = lpfc_shost_from_vport(vport); |
2e0fef85 | 1332 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
d2873e4c JS |
1333 | sizeof(event_data), (char *) &event_data, |
1334 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
1335 | ||
09372820 | 1336 | lpfc_offline_eratt(phba); |
dea3101e | 1337 | } |
9399627f | 1338 | return; |
dea3101e JB |
1339 | } |
1340 | ||
da0436e9 JS |
1341 | /** |
1342 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler | |
1343 | * @phba: pointer to lpfc hba data structure. | |
1344 | * | |
1345 | * This routine is invoked to handle the SLI4 HBA hardware error attention | |
1346 | * conditions. | |
1347 | **/ | |
1348 | static void | |
1349 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) | |
1350 | { | |
1351 | struct lpfc_vport *vport = phba->pport; | |
1352 | uint32_t event_data; | |
1353 | struct Scsi_Host *shost; | |
1354 | ||
1355 | /* If the pci channel is offline, ignore possible errors, since | |
1356 | * we cannot communicate with the pci card anyway. | |
1357 | */ | |
1358 | if (pci_channel_offline(phba->pcidev)) | |
1359 | return; | |
1360 | /* If resets are disabled then leave the HBA alone and return */ | |
1361 | if (!phba->cfg_enable_hba_reset) | |
1362 | return; | |
1363 | ||
1364 | /* Send an internal error event to mgmt application */ | |
1365 | lpfc_board_errevt_to_mgmt(phba); | |
1366 | ||
1367 | /* For now, the actual action for SLI4 device handling is not | |
1368 | * specified yet, just treated it as adaptor hardware failure | |
1369 | */ | |
1370 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1371 | "0143 SLI4 Adapter Hardware Error Data: x%x x%x\n", | |
1372 | phba->work_status[0], phba->work_status[1]); | |
1373 | ||
1374 | event_data = FC_REG_DUMP_EVENT; | |
1375 | shost = lpfc_shost_from_vport(vport); | |
1376 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1377 | sizeof(event_data), (char *) &event_data, | |
1378 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
1379 | ||
1380 | lpfc_sli4_offline_eratt(phba); | |
1381 | } | |
1382 | ||
1383 | /** | |
1384 | * lpfc_handle_eratt - Wrapper func for handling hba error attention | |
1385 | * @phba: pointer to lpfc HBA data structure. | |
1386 | * | |
1387 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling | |
1388 | * routine from the API jump table function pointer from the lpfc_hba struct. | |
1389 | * | |
1390 | * Return codes | |
af901ca1 | 1391 | * 0 - success. |
da0436e9 JS |
1392 | * Any other value - error. |
1393 | **/ | |
1394 | void | |
1395 | lpfc_handle_eratt(struct lpfc_hba *phba) | |
1396 | { | |
1397 | (*phba->lpfc_handle_eratt)(phba); | |
1398 | } | |
1399 | ||
e59058c4 | 1400 | /** |
3621a710 | 1401 | * lpfc_handle_latt - The HBA link event handler |
e59058c4 JS |
1402 | * @phba: pointer to lpfc hba data structure. |
1403 | * | |
1404 | * This routine is invoked from the worker thread to handle a HBA host | |
1405 | * attention link event. | |
1406 | **/ | |
dea3101e | 1407 | void |
2e0fef85 | 1408 | lpfc_handle_latt(struct lpfc_hba *phba) |
dea3101e | 1409 | { |
2e0fef85 JS |
1410 | struct lpfc_vport *vport = phba->pport; |
1411 | struct lpfc_sli *psli = &phba->sli; | |
dea3101e JB |
1412 | LPFC_MBOXQ_t *pmb; |
1413 | volatile uint32_t control; | |
1414 | struct lpfc_dmabuf *mp; | |
09372820 | 1415 | int rc = 0; |
dea3101e JB |
1416 | |
1417 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
09372820 JS |
1418 | if (!pmb) { |
1419 | rc = 1; | |
dea3101e | 1420 | goto lpfc_handle_latt_err_exit; |
09372820 | 1421 | } |
dea3101e JB |
1422 | |
1423 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
09372820 JS |
1424 | if (!mp) { |
1425 | rc = 2; | |
dea3101e | 1426 | goto lpfc_handle_latt_free_pmb; |
09372820 | 1427 | } |
dea3101e JB |
1428 | |
1429 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
09372820 JS |
1430 | if (!mp->virt) { |
1431 | rc = 3; | |
dea3101e | 1432 | goto lpfc_handle_latt_free_mp; |
09372820 | 1433 | } |
dea3101e | 1434 | |
6281bfe0 | 1435 | /* Cleanup any outstanding ELS commands */ |
549e55cd | 1436 | lpfc_els_flush_all_cmd(phba); |
dea3101e JB |
1437 | |
1438 | psli->slistat.link_event++; | |
1439 | lpfc_read_la(phba, pmb, mp); | |
1440 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la; | |
2e0fef85 | 1441 | pmb->vport = vport; |
0d2b6b83 JS |
1442 | /* Block ELS IOCBs until we have processed this mbox command */ |
1443 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
0b727fea | 1444 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
09372820 JS |
1445 | if (rc == MBX_NOT_FINISHED) { |
1446 | rc = 4; | |
14691150 | 1447 | goto lpfc_handle_latt_free_mbuf; |
09372820 | 1448 | } |
dea3101e JB |
1449 | |
1450 | /* Clear Link Attention in HA REG */ | |
2e0fef85 | 1451 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1452 | writel(HA_LATT, phba->HAregaddr); |
1453 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1454 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1455 | |
1456 | return; | |
1457 | ||
14691150 | 1458 | lpfc_handle_latt_free_mbuf: |
0d2b6b83 | 1459 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
14691150 | 1460 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
dea3101e JB |
1461 | lpfc_handle_latt_free_mp: |
1462 | kfree(mp); | |
1463 | lpfc_handle_latt_free_pmb: | |
1dcb58e5 | 1464 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e JB |
1465 | lpfc_handle_latt_err_exit: |
1466 | /* Enable Link attention interrupts */ | |
2e0fef85 | 1467 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1468 | psli->sli_flag |= LPFC_PROCESS_LA; |
1469 | control = readl(phba->HCregaddr); | |
1470 | control |= HC_LAINT_ENA; | |
1471 | writel(control, phba->HCregaddr); | |
1472 | readl(phba->HCregaddr); /* flush */ | |
1473 | ||
1474 | /* Clear Link Attention in HA REG */ | |
1475 | writel(HA_LATT, phba->HAregaddr); | |
1476 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1477 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1478 | lpfc_linkdown(phba); |
2e0fef85 | 1479 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 1480 | |
09372820 JS |
1481 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
1482 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); | |
dea3101e JB |
1483 | |
1484 | return; | |
1485 | } | |
1486 | ||
e59058c4 | 1487 | /** |
3621a710 | 1488 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
e59058c4 JS |
1489 | * @phba: pointer to lpfc hba data structure. |
1490 | * @vpd: pointer to the vital product data. | |
1491 | * @len: length of the vital product data in bytes. | |
1492 | * | |
1493 | * This routine parses the Vital Product Data (VPD). The VPD is treated as | |
1494 | * an array of characters. In this routine, the ModelName, ProgramType, and | |
1495 | * ModelDesc, etc. fields of the phba data structure will be populated. | |
1496 | * | |
1497 | * Return codes | |
1498 | * 0 - pointer to the VPD passed in is NULL | |
1499 | * 1 - success | |
1500 | **/ | |
3772a991 | 1501 | int |
2e0fef85 | 1502 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
dea3101e JB |
1503 | { |
1504 | uint8_t lenlo, lenhi; | |
07da60c1 | 1505 | int Length; |
dea3101e JB |
1506 | int i, j; |
1507 | int finished = 0; | |
1508 | int index = 0; | |
1509 | ||
1510 | if (!vpd) | |
1511 | return 0; | |
1512 | ||
1513 | /* Vital Product */ | |
ed957684 | 1514 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
e8b62011 | 1515 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
dea3101e JB |
1516 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
1517 | (uint32_t) vpd[3]); | |
74b72a59 | 1518 | while (!finished && (index < (len - 4))) { |
dea3101e JB |
1519 | switch (vpd[index]) { |
1520 | case 0x82: | |
74b72a59 | 1521 | case 0x91: |
dea3101e JB |
1522 | index += 1; |
1523 | lenlo = vpd[index]; | |
1524 | index += 1; | |
1525 | lenhi = vpd[index]; | |
1526 | index += 1; | |
1527 | i = ((((unsigned short)lenhi) << 8) + lenlo); | |
1528 | index += i; | |
1529 | break; | |
1530 | case 0x90: | |
1531 | index += 1; | |
1532 | lenlo = vpd[index]; | |
1533 | index += 1; | |
1534 | lenhi = vpd[index]; | |
1535 | index += 1; | |
1536 | Length = ((((unsigned short)lenhi) << 8) + lenlo); | |
74b72a59 JW |
1537 | if (Length > len - index) |
1538 | Length = len - index; | |
dea3101e JB |
1539 | while (Length > 0) { |
1540 | /* Look for Serial Number */ | |
1541 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { | |
1542 | index += 2; | |
1543 | i = vpd[index]; | |
1544 | index += 1; | |
1545 | j = 0; | |
1546 | Length -= (3+i); | |
1547 | while(i--) { | |
1548 | phba->SerialNumber[j++] = vpd[index++]; | |
1549 | if (j == 31) | |
1550 | break; | |
1551 | } | |
1552 | phba->SerialNumber[j] = 0; | |
1553 | continue; | |
1554 | } | |
1555 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { | |
1556 | phba->vpd_flag |= VPD_MODEL_DESC; | |
1557 | index += 2; | |
1558 | i = vpd[index]; | |
1559 | index += 1; | |
1560 | j = 0; | |
1561 | Length -= (3+i); | |
1562 | while(i--) { | |
1563 | phba->ModelDesc[j++] = vpd[index++]; | |
1564 | if (j == 255) | |
1565 | break; | |
1566 | } | |
1567 | phba->ModelDesc[j] = 0; | |
1568 | continue; | |
1569 | } | |
1570 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { | |
1571 | phba->vpd_flag |= VPD_MODEL_NAME; | |
1572 | index += 2; | |
1573 | i = vpd[index]; | |
1574 | index += 1; | |
1575 | j = 0; | |
1576 | Length -= (3+i); | |
1577 | while(i--) { | |
1578 | phba->ModelName[j++] = vpd[index++]; | |
1579 | if (j == 79) | |
1580 | break; | |
1581 | } | |
1582 | phba->ModelName[j] = 0; | |
1583 | continue; | |
1584 | } | |
1585 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { | |
1586 | phba->vpd_flag |= VPD_PROGRAM_TYPE; | |
1587 | index += 2; | |
1588 | i = vpd[index]; | |
1589 | index += 1; | |
1590 | j = 0; | |
1591 | Length -= (3+i); | |
1592 | while(i--) { | |
1593 | phba->ProgramType[j++] = vpd[index++]; | |
1594 | if (j == 255) | |
1595 | break; | |
1596 | } | |
1597 | phba->ProgramType[j] = 0; | |
1598 | continue; | |
1599 | } | |
1600 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { | |
1601 | phba->vpd_flag |= VPD_PORT; | |
1602 | index += 2; | |
1603 | i = vpd[index]; | |
1604 | index += 1; | |
1605 | j = 0; | |
1606 | Length -= (3+i); | |
1607 | while(i--) { | |
1608 | phba->Port[j++] = vpd[index++]; | |
1609 | if (j == 19) | |
1610 | break; | |
1611 | } | |
1612 | phba->Port[j] = 0; | |
1613 | continue; | |
1614 | } | |
1615 | else { | |
1616 | index += 2; | |
1617 | i = vpd[index]; | |
1618 | index += 1; | |
1619 | index += i; | |
1620 | Length -= (3 + i); | |
1621 | } | |
1622 | } | |
1623 | finished = 0; | |
1624 | break; | |
1625 | case 0x78: | |
1626 | finished = 1; | |
1627 | break; | |
1628 | default: | |
1629 | index ++; | |
1630 | break; | |
1631 | } | |
74b72a59 | 1632 | } |
dea3101e JB |
1633 | |
1634 | return(1); | |
1635 | } | |
1636 | ||
e59058c4 | 1637 | /** |
3621a710 | 1638 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
e59058c4 JS |
1639 | * @phba: pointer to lpfc hba data structure. |
1640 | * @mdp: pointer to the data structure to hold the derived model name. | |
1641 | * @descp: pointer to the data structure to hold the derived description. | |
1642 | * | |
1643 | * This routine retrieves HBA's description based on its registered PCI device | |
1644 | * ID. The @descp passed into this function points to an array of 256 chars. It | |
1645 | * shall be returned with the model name, maximum speed, and the host bus type. | |
1646 | * The @mdp passed into this function points to an array of 80 chars. When the | |
1647 | * function returns, the @mdp will be filled with the model name. | |
1648 | **/ | |
dea3101e | 1649 | static void |
2e0fef85 | 1650 | lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) |
dea3101e JB |
1651 | { |
1652 | lpfc_vpd_t *vp; | |
fefcb2b6 | 1653 | uint16_t dev_id = phba->pcidev->device; |
74b72a59 | 1654 | int max_speed; |
84774a4d | 1655 | int GE = 0; |
da0436e9 | 1656 | int oneConnect = 0; /* default is not a oneConnect */ |
74b72a59 | 1657 | struct { |
a747c9ce JS |
1658 | char *name; |
1659 | char *bus; | |
1660 | char *function; | |
1661 | } m = {"<Unknown>", "", ""}; | |
74b72a59 JW |
1662 | |
1663 | if (mdp && mdp[0] != '\0' | |
1664 | && descp && descp[0] != '\0') | |
1665 | return; | |
1666 | ||
1667 | if (phba->lmt & LMT_10Gb) | |
1668 | max_speed = 10; | |
1669 | else if (phba->lmt & LMT_8Gb) | |
1670 | max_speed = 8; | |
1671 | else if (phba->lmt & LMT_4Gb) | |
1672 | max_speed = 4; | |
1673 | else if (phba->lmt & LMT_2Gb) | |
1674 | max_speed = 2; | |
1675 | else | |
1676 | max_speed = 1; | |
dea3101e JB |
1677 | |
1678 | vp = &phba->vpd; | |
dea3101e | 1679 | |
e4adb204 | 1680 | switch (dev_id) { |
06325e74 | 1681 | case PCI_DEVICE_ID_FIREFLY: |
a747c9ce | 1682 | m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"}; |
06325e74 | 1683 | break; |
dea3101e JB |
1684 | case PCI_DEVICE_ID_SUPERFLY: |
1685 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) | |
a747c9ce JS |
1686 | m = (typeof(m)){"LP7000", "PCI", |
1687 | "Fibre Channel Adapter"}; | |
dea3101e | 1688 | else |
a747c9ce JS |
1689 | m = (typeof(m)){"LP7000E", "PCI", |
1690 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1691 | break; |
1692 | case PCI_DEVICE_ID_DRAGONFLY: | |
a747c9ce JS |
1693 | m = (typeof(m)){"LP8000", "PCI", |
1694 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1695 | break; |
1696 | case PCI_DEVICE_ID_CENTAUR: | |
1697 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) | |
a747c9ce JS |
1698 | m = (typeof(m)){"LP9002", "PCI", |
1699 | "Fibre Channel Adapter"}; | |
dea3101e | 1700 | else |
a747c9ce JS |
1701 | m = (typeof(m)){"LP9000", "PCI", |
1702 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1703 | break; |
1704 | case PCI_DEVICE_ID_RFLY: | |
a747c9ce JS |
1705 | m = (typeof(m)){"LP952", "PCI", |
1706 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1707 | break; |
1708 | case PCI_DEVICE_ID_PEGASUS: | |
a747c9ce JS |
1709 | m = (typeof(m)){"LP9802", "PCI-X", |
1710 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1711 | break; |
1712 | case PCI_DEVICE_ID_THOR: | |
a747c9ce JS |
1713 | m = (typeof(m)){"LP10000", "PCI-X", |
1714 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1715 | break; |
1716 | case PCI_DEVICE_ID_VIPER: | |
a747c9ce JS |
1717 | m = (typeof(m)){"LPX1000", "PCI-X", |
1718 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1719 | break; |
1720 | case PCI_DEVICE_ID_PFLY: | |
a747c9ce JS |
1721 | m = (typeof(m)){"LP982", "PCI-X", |
1722 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1723 | break; |
1724 | case PCI_DEVICE_ID_TFLY: | |
a747c9ce JS |
1725 | m = (typeof(m)){"LP1050", "PCI-X", |
1726 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1727 | break; |
1728 | case PCI_DEVICE_ID_HELIOS: | |
a747c9ce JS |
1729 | m = (typeof(m)){"LP11000", "PCI-X2", |
1730 | "Fibre Channel Adapter"}; | |
dea3101e | 1731 | break; |
e4adb204 | 1732 | case PCI_DEVICE_ID_HELIOS_SCSP: |
a747c9ce JS |
1733 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
1734 | "Fibre Channel Adapter"}; | |
e4adb204 JSEC |
1735 | break; |
1736 | case PCI_DEVICE_ID_HELIOS_DCSP: | |
a747c9ce JS |
1737 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
1738 | "Fibre Channel Adapter"}; | |
e4adb204 JSEC |
1739 | break; |
1740 | case PCI_DEVICE_ID_NEPTUNE: | |
a747c9ce | 1741 | m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1742 | break; |
1743 | case PCI_DEVICE_ID_NEPTUNE_SCSP: | |
a747c9ce | 1744 | m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1745 | break; |
1746 | case PCI_DEVICE_ID_NEPTUNE_DCSP: | |
a747c9ce | 1747 | m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 | 1748 | break; |
dea3101e | 1749 | case PCI_DEVICE_ID_BMID: |
a747c9ce | 1750 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
dea3101e JB |
1751 | break; |
1752 | case PCI_DEVICE_ID_BSMB: | |
a747c9ce | 1753 | m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"}; |
dea3101e JB |
1754 | break; |
1755 | case PCI_DEVICE_ID_ZEPHYR: | |
a747c9ce | 1756 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
dea3101e | 1757 | break; |
e4adb204 | 1758 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
a747c9ce | 1759 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1760 | break; |
1761 | case PCI_DEVICE_ID_ZEPHYR_DCSP: | |
a747c9ce | 1762 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
a257bf90 | 1763 | GE = 1; |
e4adb204 | 1764 | break; |
dea3101e | 1765 | case PCI_DEVICE_ID_ZMID: |
a747c9ce | 1766 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
dea3101e JB |
1767 | break; |
1768 | case PCI_DEVICE_ID_ZSMB: | |
a747c9ce | 1769 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
dea3101e JB |
1770 | break; |
1771 | case PCI_DEVICE_ID_LP101: | |
a747c9ce | 1772 | m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"}; |
dea3101e JB |
1773 | break; |
1774 | case PCI_DEVICE_ID_LP10000S: | |
a747c9ce | 1775 | m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"}; |
06325e74 | 1776 | break; |
e4adb204 | 1777 | case PCI_DEVICE_ID_LP11000S: |
a747c9ce | 1778 | m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"}; |
18a3b596 | 1779 | break; |
e4adb204 | 1780 | case PCI_DEVICE_ID_LPE11000S: |
a747c9ce | 1781 | m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"}; |
5cc36b3c | 1782 | break; |
b87eab38 | 1783 | case PCI_DEVICE_ID_SAT: |
a747c9ce | 1784 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1785 | break; |
1786 | case PCI_DEVICE_ID_SAT_MID: | |
a747c9ce | 1787 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1788 | break; |
1789 | case PCI_DEVICE_ID_SAT_SMB: | |
a747c9ce | 1790 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1791 | break; |
1792 | case PCI_DEVICE_ID_SAT_DCSP: | |
a747c9ce | 1793 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1794 | break; |
1795 | case PCI_DEVICE_ID_SAT_SCSP: | |
a747c9ce | 1796 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1797 | break; |
1798 | case PCI_DEVICE_ID_SAT_S: | |
a747c9ce | 1799 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 | 1800 | break; |
84774a4d | 1801 | case PCI_DEVICE_ID_HORNET: |
a747c9ce | 1802 | m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"}; |
84774a4d JS |
1803 | GE = 1; |
1804 | break; | |
1805 | case PCI_DEVICE_ID_PROTEUS_VF: | |
a747c9ce JS |
1806 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
1807 | "Fibre Channel Adapter"}; | |
84774a4d JS |
1808 | break; |
1809 | case PCI_DEVICE_ID_PROTEUS_PF: | |
a747c9ce JS |
1810 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
1811 | "Fibre Channel Adapter"}; | |
84774a4d JS |
1812 | break; |
1813 | case PCI_DEVICE_ID_PROTEUS_S: | |
a747c9ce JS |
1814 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
1815 | "Fibre Channel Adapter"}; | |
84774a4d | 1816 | break; |
da0436e9 JS |
1817 | case PCI_DEVICE_ID_TIGERSHARK: |
1818 | oneConnect = 1; | |
a747c9ce | 1819 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
da0436e9 | 1820 | break; |
a747c9ce | 1821 | case PCI_DEVICE_ID_TOMCAT: |
6669f9bb | 1822 | oneConnect = 1; |
a747c9ce JS |
1823 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
1824 | break; | |
1825 | case PCI_DEVICE_ID_FALCON: | |
1826 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", | |
1827 | "EmulexSecure Fibre"}; | |
6669f9bb | 1828 | break; |
98fc5dd9 JS |
1829 | case PCI_DEVICE_ID_BALIUS: |
1830 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", | |
1831 | "Fibre Channel Adapter"}; | |
1832 | break; | |
5cc36b3c | 1833 | default: |
a747c9ce | 1834 | m = (typeof(m)){"Unknown", "", ""}; |
e4adb204 | 1835 | break; |
dea3101e | 1836 | } |
74b72a59 JW |
1837 | |
1838 | if (mdp && mdp[0] == '\0') | |
1839 | snprintf(mdp, 79,"%s", m.name); | |
da0436e9 JS |
1840 | /* oneConnect hba requires special processing, they are all initiators |
1841 | * and we put the port number on the end | |
1842 | */ | |
1843 | if (descp && descp[0] == '\0') { | |
1844 | if (oneConnect) | |
1845 | snprintf(descp, 255, | |
a747c9ce JS |
1846 | "Emulex OneConnect %s, %s Initiator, Port %s", |
1847 | m.name, m.function, | |
da0436e9 JS |
1848 | phba->Port); |
1849 | else | |
1850 | snprintf(descp, 255, | |
1851 | "Emulex %s %d%s %s %s", | |
a747c9ce JS |
1852 | m.name, max_speed, (GE) ? "GE" : "Gb", |
1853 | m.bus, m.function); | |
da0436e9 | 1854 | } |
dea3101e JB |
1855 | } |
1856 | ||
e59058c4 | 1857 | /** |
3621a710 | 1858 | * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring |
e59058c4 JS |
1859 | * @phba: pointer to lpfc hba data structure. |
1860 | * @pring: pointer to a IOCB ring. | |
1861 | * @cnt: the number of IOCBs to be posted to the IOCB ring. | |
1862 | * | |
1863 | * This routine posts a given number of IOCBs with the associated DMA buffer | |
1864 | * descriptors specified by the cnt argument to the given IOCB ring. | |
1865 | * | |
1866 | * Return codes | |
1867 | * The number of IOCBs NOT able to be posted to the IOCB ring. | |
1868 | **/ | |
dea3101e | 1869 | int |
495a714c | 1870 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
dea3101e JB |
1871 | { |
1872 | IOCB_t *icmd; | |
0bd4ca25 | 1873 | struct lpfc_iocbq *iocb; |
dea3101e JB |
1874 | struct lpfc_dmabuf *mp1, *mp2; |
1875 | ||
1876 | cnt += pring->missbufcnt; | |
1877 | ||
1878 | /* While there are buffers to post */ | |
1879 | while (cnt > 0) { | |
1880 | /* Allocate buffer for command iocb */ | |
0bd4ca25 | 1881 | iocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
1882 | if (iocb == NULL) { |
1883 | pring->missbufcnt = cnt; | |
1884 | return cnt; | |
1885 | } | |
dea3101e JB |
1886 | icmd = &iocb->iocb; |
1887 | ||
1888 | /* 2 buffers can be posted per command */ | |
1889 | /* Allocate buffer to post */ | |
1890 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
1891 | if (mp1) | |
98c9ea5c JS |
1892 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
1893 | if (!mp1 || !mp1->virt) { | |
c9475cb0 | 1894 | kfree(mp1); |
604a3e30 | 1895 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
1896 | pring->missbufcnt = cnt; |
1897 | return cnt; | |
1898 | } | |
1899 | ||
1900 | INIT_LIST_HEAD(&mp1->list); | |
1901 | /* Allocate buffer to post */ | |
1902 | if (cnt > 1) { | |
1903 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
1904 | if (mp2) | |
1905 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | |
1906 | &mp2->phys); | |
98c9ea5c | 1907 | if (!mp2 || !mp2->virt) { |
c9475cb0 | 1908 | kfree(mp2); |
dea3101e JB |
1909 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
1910 | kfree(mp1); | |
604a3e30 | 1911 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
1912 | pring->missbufcnt = cnt; |
1913 | return cnt; | |
1914 | } | |
1915 | ||
1916 | INIT_LIST_HEAD(&mp2->list); | |
1917 | } else { | |
1918 | mp2 = NULL; | |
1919 | } | |
1920 | ||
1921 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); | |
1922 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); | |
1923 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; | |
1924 | icmd->ulpBdeCount = 1; | |
1925 | cnt--; | |
1926 | if (mp2) { | |
1927 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); | |
1928 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); | |
1929 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; | |
1930 | cnt--; | |
1931 | icmd->ulpBdeCount = 2; | |
1932 | } | |
1933 | ||
1934 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; | |
1935 | icmd->ulpLe = 1; | |
1936 | ||
3772a991 JS |
1937 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
1938 | IOCB_ERROR) { | |
dea3101e JB |
1939 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
1940 | kfree(mp1); | |
1941 | cnt++; | |
1942 | if (mp2) { | |
1943 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); | |
1944 | kfree(mp2); | |
1945 | cnt++; | |
1946 | } | |
604a3e30 | 1947 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e | 1948 | pring->missbufcnt = cnt; |
dea3101e JB |
1949 | return cnt; |
1950 | } | |
dea3101e | 1951 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
92d7f7b0 | 1952 | if (mp2) |
dea3101e | 1953 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
dea3101e JB |
1954 | } |
1955 | pring->missbufcnt = 0; | |
1956 | return 0; | |
1957 | } | |
1958 | ||
e59058c4 | 1959 | /** |
3621a710 | 1960 | * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring |
e59058c4 JS |
1961 | * @phba: pointer to lpfc hba data structure. |
1962 | * | |
1963 | * This routine posts initial receive IOCB buffers to the ELS ring. The | |
1964 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is | |
1965 | * set to 64 IOCBs. | |
1966 | * | |
1967 | * Return codes | |
1968 | * 0 - success (currently always success) | |
1969 | **/ | |
dea3101e | 1970 | static int |
2e0fef85 | 1971 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
dea3101e JB |
1972 | { |
1973 | struct lpfc_sli *psli = &phba->sli; | |
1974 | ||
1975 | /* Ring 0, ELS / CT buffers */ | |
495a714c | 1976 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
dea3101e JB |
1977 | /* Ring 2 - FCP no buffers needed */ |
1978 | ||
1979 | return 0; | |
1980 | } | |
1981 | ||
1982 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) | |
1983 | ||
e59058c4 | 1984 | /** |
3621a710 | 1985 | * lpfc_sha_init - Set up initial array of hash table entries |
e59058c4 JS |
1986 | * @HashResultPointer: pointer to an array as hash table. |
1987 | * | |
1988 | * This routine sets up the initial values to the array of hash table entries | |
1989 | * for the LC HBAs. | |
1990 | **/ | |
dea3101e JB |
1991 | static void |
1992 | lpfc_sha_init(uint32_t * HashResultPointer) | |
1993 | { | |
1994 | HashResultPointer[0] = 0x67452301; | |
1995 | HashResultPointer[1] = 0xEFCDAB89; | |
1996 | HashResultPointer[2] = 0x98BADCFE; | |
1997 | HashResultPointer[3] = 0x10325476; | |
1998 | HashResultPointer[4] = 0xC3D2E1F0; | |
1999 | } | |
2000 | ||
e59058c4 | 2001 | /** |
3621a710 | 2002 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
e59058c4 JS |
2003 | * @HashResultPointer: pointer to an initial/result hash table. |
2004 | * @HashWorkingPointer: pointer to an working hash table. | |
2005 | * | |
2006 | * This routine iterates an initial hash table pointed by @HashResultPointer | |
2007 | * with the values from the working hash table pointeed by @HashWorkingPointer. | |
2008 | * The results are putting back to the initial hash table, returned through | |
2009 | * the @HashResultPointer as the result hash table. | |
2010 | **/ | |
dea3101e JB |
2011 | static void |
2012 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) | |
2013 | { | |
2014 | int t; | |
2015 | uint32_t TEMP; | |
2016 | uint32_t A, B, C, D, E; | |
2017 | t = 16; | |
2018 | do { | |
2019 | HashWorkingPointer[t] = | |
2020 | S(1, | |
2021 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - | |
2022 | 8] ^ | |
2023 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); | |
2024 | } while (++t <= 79); | |
2025 | t = 0; | |
2026 | A = HashResultPointer[0]; | |
2027 | B = HashResultPointer[1]; | |
2028 | C = HashResultPointer[2]; | |
2029 | D = HashResultPointer[3]; | |
2030 | E = HashResultPointer[4]; | |
2031 | ||
2032 | do { | |
2033 | if (t < 20) { | |
2034 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; | |
2035 | } else if (t < 40) { | |
2036 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; | |
2037 | } else if (t < 60) { | |
2038 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; | |
2039 | } else { | |
2040 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; | |
2041 | } | |
2042 | TEMP += S(5, A) + E + HashWorkingPointer[t]; | |
2043 | E = D; | |
2044 | D = C; | |
2045 | C = S(30, B); | |
2046 | B = A; | |
2047 | A = TEMP; | |
2048 | } while (++t <= 79); | |
2049 | ||
2050 | HashResultPointer[0] += A; | |
2051 | HashResultPointer[1] += B; | |
2052 | HashResultPointer[2] += C; | |
2053 | HashResultPointer[3] += D; | |
2054 | HashResultPointer[4] += E; | |
2055 | ||
2056 | } | |
2057 | ||
e59058c4 | 2058 | /** |
3621a710 | 2059 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
e59058c4 JS |
2060 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
2061 | * @HashWorking: pointer to the entry of the working hash array. | |
2062 | * | |
2063 | * This routine calculates the working hash array referred by @HashWorking | |
2064 | * from the challenge random numbers associated with the host, referred by | |
2065 | * @RandomChallenge. The result is put into the entry of the working hash | |
2066 | * array and returned by reference through @HashWorking. | |
2067 | **/ | |
dea3101e JB |
2068 | static void |
2069 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) | |
2070 | { | |
2071 | *HashWorking = (*RandomChallenge ^ *HashWorking); | |
2072 | } | |
2073 | ||
e59058c4 | 2074 | /** |
3621a710 | 2075 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
e59058c4 JS |
2076 | * @phba: pointer to lpfc hba data structure. |
2077 | * @hbainit: pointer to an array of unsigned 32-bit integers. | |
2078 | * | |
2079 | * This routine performs the special handling for LC HBA initialization. | |
2080 | **/ | |
dea3101e JB |
2081 | void |
2082 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) | |
2083 | { | |
2084 | int t; | |
2085 | uint32_t *HashWorking; | |
2e0fef85 | 2086 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
dea3101e | 2087 | |
bbfbbbc1 | 2088 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
dea3101e JB |
2089 | if (!HashWorking) |
2090 | return; | |
2091 | ||
dea3101e JB |
2092 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
2093 | HashWorking[1] = HashWorking[79] = *pwwnn; | |
2094 | ||
2095 | for (t = 0; t < 7; t++) | |
2096 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); | |
2097 | ||
2098 | lpfc_sha_init(hbainit); | |
2099 | lpfc_sha_iterate(hbainit, HashWorking); | |
2100 | kfree(HashWorking); | |
2101 | } | |
2102 | ||
e59058c4 | 2103 | /** |
3621a710 | 2104 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
e59058c4 JS |
2105 | * @vport: pointer to a virtual N_Port data structure. |
2106 | * | |
2107 | * This routine performs the necessary cleanups before deleting the @vport. | |
2108 | * It invokes the discovery state machine to perform necessary state | |
2109 | * transitions and to release the ndlps associated with the @vport. Note, | |
2110 | * the physical port is treated as @vport 0. | |
2111 | **/ | |
87af33fe | 2112 | void |
2e0fef85 | 2113 | lpfc_cleanup(struct lpfc_vport *vport) |
dea3101e | 2114 | { |
87af33fe | 2115 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2116 | struct lpfc_nodelist *ndlp, *next_ndlp; |
a8adb832 | 2117 | int i = 0; |
dea3101e | 2118 | |
87af33fe JS |
2119 | if (phba->link_state > LPFC_LINK_DOWN) |
2120 | lpfc_port_link_failure(vport); | |
2121 | ||
2122 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
2123 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
2124 | ndlp = lpfc_enable_node(vport, ndlp, | |
2125 | NLP_STE_UNUSED_NODE); | |
2126 | if (!ndlp) | |
2127 | continue; | |
2128 | spin_lock_irq(&phba->ndlp_lock); | |
2129 | NLP_SET_FREE_REQ(ndlp); | |
2130 | spin_unlock_irq(&phba->ndlp_lock); | |
2131 | /* Trigger the release of the ndlp memory */ | |
2132 | lpfc_nlp_put(ndlp); | |
2133 | continue; | |
2134 | } | |
2135 | spin_lock_irq(&phba->ndlp_lock); | |
2136 | if (NLP_CHK_FREE_REQ(ndlp)) { | |
2137 | /* The ndlp should not be in memory free mode already */ | |
2138 | spin_unlock_irq(&phba->ndlp_lock); | |
2139 | continue; | |
2140 | } else | |
2141 | /* Indicate request for freeing ndlp memory */ | |
2142 | NLP_SET_FREE_REQ(ndlp); | |
2143 | spin_unlock_irq(&phba->ndlp_lock); | |
2144 | ||
58da1ffb JS |
2145 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
2146 | ndlp->nlp_DID == Fabric_DID) { | |
2147 | /* Just free up ndlp with Fabric_DID for vports */ | |
2148 | lpfc_nlp_put(ndlp); | |
2149 | continue; | |
2150 | } | |
2151 | ||
87af33fe JS |
2152 | if (ndlp->nlp_type & NLP_FABRIC) |
2153 | lpfc_disc_state_machine(vport, ndlp, NULL, | |
2154 | NLP_EVT_DEVICE_RECOVERY); | |
e47c9093 | 2155 | |
87af33fe JS |
2156 | lpfc_disc_state_machine(vport, ndlp, NULL, |
2157 | NLP_EVT_DEVICE_RM); | |
495a714c | 2158 | |
87af33fe JS |
2159 | } |
2160 | ||
a8adb832 JS |
2161 | /* At this point, ALL ndlp's should be gone |
2162 | * because of the previous NLP_EVT_DEVICE_RM. | |
2163 | * Lets wait for this to happen, if needed. | |
2164 | */ | |
87af33fe | 2165 | while (!list_empty(&vport->fc_nodes)) { |
a8adb832 | 2166 | if (i++ > 3000) { |
87af33fe | 2167 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
a8adb832 | 2168 | "0233 Nodelist not empty\n"); |
e47c9093 JS |
2169 | list_for_each_entry_safe(ndlp, next_ndlp, |
2170 | &vport->fc_nodes, nlp_listp) { | |
2171 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, | |
2172 | LOG_NODE, | |
d7c255b2 | 2173 | "0282 did:x%x ndlp:x%p " |
e47c9093 JS |
2174 | "usgmap:x%x refcnt:%d\n", |
2175 | ndlp->nlp_DID, (void *)ndlp, | |
2176 | ndlp->nlp_usg_map, | |
2177 | atomic_read( | |
2178 | &ndlp->kref.refcount)); | |
2179 | } | |
a8adb832 | 2180 | break; |
87af33fe | 2181 | } |
a8adb832 JS |
2182 | |
2183 | /* Wait for any activity on ndlps to settle */ | |
2184 | msleep(10); | |
87af33fe | 2185 | } |
dea3101e JB |
2186 | } |
2187 | ||
e59058c4 | 2188 | /** |
3621a710 | 2189 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
e59058c4 JS |
2190 | * @vport: pointer to a virtual N_Port data structure. |
2191 | * | |
2192 | * This routine stops all the timers associated with a @vport. This function | |
2193 | * is invoked before disabling or deleting a @vport. Note that the physical | |
2194 | * port is treated as @vport 0. | |
2195 | **/ | |
92d7f7b0 JS |
2196 | void |
2197 | lpfc_stop_vport_timers(struct lpfc_vport *vport) | |
dea3101e | 2198 | { |
92d7f7b0 JS |
2199 | del_timer_sync(&vport->els_tmofunc); |
2200 | del_timer_sync(&vport->fc_fdmitmo); | |
2201 | lpfc_can_disctmo(vport); | |
2202 | return; | |
dea3101e JB |
2203 | } |
2204 | ||
ecfd03c6 JS |
2205 | /** |
2206 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2207 | * @phba: pointer to lpfc hba data structure. | |
2208 | * | |
2209 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The | |
2210 | * caller of this routine should already hold the host lock. | |
2211 | **/ | |
2212 | void | |
2213 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2214 | { | |
fc2b989b JS |
2215 | /* Clear pending FCF rediscovery wait and failover in progress flags */ |
2216 | phba->fcf.fcf_flag &= ~(FCF_REDISC_PEND | | |
0c9ab6f5 JS |
2217 | FCF_DEAD_DISC | |
2218 | FCF_ACVL_DISC); | |
ecfd03c6 JS |
2219 | /* Now, try to stop the timer */ |
2220 | del_timer(&phba->fcf.redisc_wait); | |
2221 | } | |
2222 | ||
2223 | /** | |
2224 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2225 | * @phba: pointer to lpfc hba data structure. | |
2226 | * | |
2227 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It | |
2228 | * checks whether the FCF rediscovery wait timer is pending with the host | |
2229 | * lock held before proceeding with disabling the timer and clearing the | |
2230 | * wait timer pendig flag. | |
2231 | **/ | |
2232 | void | |
2233 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2234 | { | |
2235 | spin_lock_irq(&phba->hbalock); | |
2236 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
2237 | /* FCF rediscovery timer already fired or stopped */ | |
2238 | spin_unlock_irq(&phba->hbalock); | |
2239 | return; | |
2240 | } | |
2241 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); | |
2242 | spin_unlock_irq(&phba->hbalock); | |
2243 | } | |
2244 | ||
e59058c4 | 2245 | /** |
3772a991 | 2246 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
e59058c4 JS |
2247 | * @phba: pointer to lpfc hba data structure. |
2248 | * | |
2249 | * This routine stops all the timers associated with a HBA. This function is | |
2250 | * invoked before either putting a HBA offline or unloading the driver. | |
2251 | **/ | |
3772a991 JS |
2252 | void |
2253 | lpfc_stop_hba_timers(struct lpfc_hba *phba) | |
dea3101e | 2254 | { |
51ef4c26 | 2255 | lpfc_stop_vport_timers(phba->pport); |
2e0fef85 | 2256 | del_timer_sync(&phba->sli.mbox_tmo); |
92d7f7b0 | 2257 | del_timer_sync(&phba->fabric_block_timer); |
9399627f | 2258 | del_timer_sync(&phba->eratt_poll); |
3772a991 JS |
2259 | del_timer_sync(&phba->hb_tmofunc); |
2260 | phba->hb_outstanding = 0; | |
2261 | ||
2262 | switch (phba->pci_dev_grp) { | |
2263 | case LPFC_PCI_DEV_LP: | |
2264 | /* Stop any LightPulse device specific driver timers */ | |
2265 | del_timer_sync(&phba->fcp_poll_timer); | |
2266 | break; | |
2267 | case LPFC_PCI_DEV_OC: | |
2268 | /* Stop any OneConnect device sepcific driver timers */ | |
ecfd03c6 | 2269 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
3772a991 JS |
2270 | break; |
2271 | default: | |
2272 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2273 | "0297 Invalid device group (x%x)\n", | |
2274 | phba->pci_dev_grp); | |
2275 | break; | |
2276 | } | |
2e0fef85 | 2277 | return; |
dea3101e JB |
2278 | } |
2279 | ||
e59058c4 | 2280 | /** |
3621a710 | 2281 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
e59058c4 JS |
2282 | * @phba: pointer to lpfc hba data structure. |
2283 | * | |
2284 | * This routine marks a HBA's management interface as blocked. Once the HBA's | |
2285 | * management interface is marked as blocked, all the user space access to | |
2286 | * the HBA, whether they are from sysfs interface or libdfc interface will | |
2287 | * all be blocked. The HBA is set to block the management interface when the | |
2288 | * driver prepares the HBA interface for online or offline. | |
2289 | **/ | |
a6ababd2 AB |
2290 | static void |
2291 | lpfc_block_mgmt_io(struct lpfc_hba * phba) | |
2292 | { | |
2293 | unsigned long iflag; | |
6e7288d9 JS |
2294 | uint8_t actcmd = MBX_HEARTBEAT; |
2295 | unsigned long timeout; | |
2296 | ||
a6ababd2 AB |
2297 | |
2298 | spin_lock_irqsave(&phba->hbalock, iflag); | |
2299 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; | |
6e7288d9 JS |
2300 | if (phba->sli.mbox_active) |
2301 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; | |
a6ababd2 | 2302 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
6e7288d9 JS |
2303 | /* Determine how long we might wait for the active mailbox |
2304 | * command to be gracefully completed by firmware. | |
2305 | */ | |
2306 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) + | |
2307 | jiffies; | |
2308 | /* Wait for the outstnading mailbox command to complete */ | |
2309 | while (phba->sli.mbox_active) { | |
2310 | /* Check active mailbox complete status every 2ms */ | |
2311 | msleep(2); | |
2312 | if (time_after(jiffies, timeout)) { | |
2313 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2314 | "2813 Mgmt IO is Blocked %x " | |
2315 | "- mbox cmd %x still active\n", | |
2316 | phba->sli.sli_flag, actcmd); | |
2317 | break; | |
2318 | } | |
2319 | } | |
a6ababd2 AB |
2320 | } |
2321 | ||
e59058c4 | 2322 | /** |
3621a710 | 2323 | * lpfc_online - Initialize and bring a HBA online |
e59058c4 JS |
2324 | * @phba: pointer to lpfc hba data structure. |
2325 | * | |
2326 | * This routine initializes the HBA and brings a HBA online. During this | |
2327 | * process, the management interface is blocked to prevent user space access | |
2328 | * to the HBA interfering with the driver initialization. | |
2329 | * | |
2330 | * Return codes | |
2331 | * 0 - successful | |
2332 | * 1 - failed | |
2333 | **/ | |
dea3101e | 2334 | int |
2e0fef85 | 2335 | lpfc_online(struct lpfc_hba *phba) |
dea3101e | 2336 | { |
372bd282 | 2337 | struct lpfc_vport *vport; |
549e55cd JS |
2338 | struct lpfc_vport **vports; |
2339 | int i; | |
2e0fef85 | 2340 | |
dea3101e JB |
2341 | if (!phba) |
2342 | return 0; | |
372bd282 | 2343 | vport = phba->pport; |
dea3101e | 2344 | |
2e0fef85 | 2345 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
dea3101e JB |
2346 | return 0; |
2347 | ||
ed957684 | 2348 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 2349 | "0458 Bring Adapter online\n"); |
dea3101e | 2350 | |
46fa311e JS |
2351 | lpfc_block_mgmt_io(phba); |
2352 | ||
2353 | if (!lpfc_sli_queue_setup(phba)) { | |
2354 | lpfc_unblock_mgmt_io(phba); | |
dea3101e | 2355 | return 1; |
46fa311e | 2356 | } |
dea3101e | 2357 | |
da0436e9 JS |
2358 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2359 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ | |
2360 | lpfc_unblock_mgmt_io(phba); | |
2361 | return 1; | |
2362 | } | |
2363 | } else { | |
2364 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ | |
2365 | lpfc_unblock_mgmt_io(phba); | |
2366 | return 1; | |
2367 | } | |
46fa311e | 2368 | } |
dea3101e | 2369 | |
549e55cd JS |
2370 | vports = lpfc_create_vport_work_array(phba); |
2371 | if (vports != NULL) | |
da0436e9 | 2372 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd JS |
2373 | struct Scsi_Host *shost; |
2374 | shost = lpfc_shost_from_vport(vports[i]); | |
2375 | spin_lock_irq(shost->host_lock); | |
2376 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; | |
2377 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) | |
2378 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
1c6834a7 JS |
2379 | if (phba->sli_rev == LPFC_SLI_REV4) |
2380 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; | |
549e55cd JS |
2381 | spin_unlock_irq(shost->host_lock); |
2382 | } | |
09372820 | 2383 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2384 | |
46fa311e | 2385 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
2386 | return 0; |
2387 | } | |
2388 | ||
e59058c4 | 2389 | /** |
3621a710 | 2390 | * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked |
e59058c4 JS |
2391 | * @phba: pointer to lpfc hba data structure. |
2392 | * | |
2393 | * This routine marks a HBA's management interface as not blocked. Once the | |
2394 | * HBA's management interface is marked as not blocked, all the user space | |
2395 | * access to the HBA, whether they are from sysfs interface or libdfc | |
2396 | * interface will be allowed. The HBA is set to block the management interface | |
2397 | * when the driver prepares the HBA interface for online or offline and then | |
2398 | * set to unblock the management interface afterwards. | |
2399 | **/ | |
46fa311e JS |
2400 | void |
2401 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) | |
2402 | { | |
2403 | unsigned long iflag; | |
2404 | ||
2e0fef85 JS |
2405 | spin_lock_irqsave(&phba->hbalock, iflag); |
2406 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; | |
2407 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
46fa311e JS |
2408 | } |
2409 | ||
e59058c4 | 2410 | /** |
3621a710 | 2411 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
e59058c4 JS |
2412 | * @phba: pointer to lpfc hba data structure. |
2413 | * | |
2414 | * This routine is invoked to prepare a HBA to be brought offline. It performs | |
2415 | * unregistration login to all the nodes on all vports and flushes the mailbox | |
2416 | * queue to make it ready to be brought offline. | |
2417 | **/ | |
46fa311e JS |
2418 | void |
2419 | lpfc_offline_prep(struct lpfc_hba * phba) | |
2420 | { | |
2e0fef85 | 2421 | struct lpfc_vport *vport = phba->pport; |
46fa311e | 2422 | struct lpfc_nodelist *ndlp, *next_ndlp; |
87af33fe | 2423 | struct lpfc_vport **vports; |
72100cc4 | 2424 | struct Scsi_Host *shost; |
87af33fe | 2425 | int i; |
dea3101e | 2426 | |
2e0fef85 | 2427 | if (vport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 2428 | return; |
dea3101e | 2429 | |
46fa311e | 2430 | lpfc_block_mgmt_io(phba); |
dea3101e JB |
2431 | |
2432 | lpfc_linkdown(phba); | |
2433 | ||
87af33fe JS |
2434 | /* Issue an unreg_login to all nodes on all vports */ |
2435 | vports = lpfc_create_vport_work_array(phba); | |
2436 | if (vports != NULL) { | |
da0436e9 | 2437 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
a8adb832 JS |
2438 | if (vports[i]->load_flag & FC_UNLOADING) |
2439 | continue; | |
72100cc4 JS |
2440 | shost = lpfc_shost_from_vport(vports[i]); |
2441 | spin_lock_irq(shost->host_lock); | |
c868595d | 2442 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
695a814e JS |
2443 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
2444 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; | |
72100cc4 | 2445 | spin_unlock_irq(shost->host_lock); |
695a814e | 2446 | |
87af33fe JS |
2447 | shost = lpfc_shost_from_vport(vports[i]); |
2448 | list_for_each_entry_safe(ndlp, next_ndlp, | |
2449 | &vports[i]->fc_nodes, | |
2450 | nlp_listp) { | |
e47c9093 JS |
2451 | if (!NLP_CHK_NODE_ACT(ndlp)) |
2452 | continue; | |
87af33fe JS |
2453 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
2454 | continue; | |
2455 | if (ndlp->nlp_type & NLP_FABRIC) { | |
2456 | lpfc_disc_state_machine(vports[i], ndlp, | |
2457 | NULL, NLP_EVT_DEVICE_RECOVERY); | |
2458 | lpfc_disc_state_machine(vports[i], ndlp, | |
2459 | NULL, NLP_EVT_DEVICE_RM); | |
2460 | } | |
2461 | spin_lock_irq(shost->host_lock); | |
2462 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | |
2463 | spin_unlock_irq(shost->host_lock); | |
2464 | lpfc_unreg_rpi(vports[i], ndlp); | |
2465 | } | |
2466 | } | |
2467 | } | |
09372820 | 2468 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2469 | |
04c68496 | 2470 | lpfc_sli_mbox_sys_shutdown(phba); |
46fa311e JS |
2471 | } |
2472 | ||
e59058c4 | 2473 | /** |
3621a710 | 2474 | * lpfc_offline - Bring a HBA offline |
e59058c4 JS |
2475 | * @phba: pointer to lpfc hba data structure. |
2476 | * | |
2477 | * This routine actually brings a HBA offline. It stops all the timers | |
2478 | * associated with the HBA, brings down the SLI layer, and eventually | |
2479 | * marks the HBA as in offline state for the upper layer protocol. | |
2480 | **/ | |
46fa311e | 2481 | void |
2e0fef85 | 2482 | lpfc_offline(struct lpfc_hba *phba) |
46fa311e | 2483 | { |
549e55cd JS |
2484 | struct Scsi_Host *shost; |
2485 | struct lpfc_vport **vports; | |
2486 | int i; | |
46fa311e | 2487 | |
549e55cd | 2488 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 2489 | return; |
688a8863 | 2490 | |
da0436e9 JS |
2491 | /* stop port and all timers associated with this hba */ |
2492 | lpfc_stop_port(phba); | |
51ef4c26 JS |
2493 | vports = lpfc_create_vport_work_array(phba); |
2494 | if (vports != NULL) | |
da0436e9 | 2495 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
51ef4c26 | 2496 | lpfc_stop_vport_timers(vports[i]); |
09372820 | 2497 | lpfc_destroy_vport_work_array(phba, vports); |
92d7f7b0 | 2498 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 2499 | "0460 Bring Adapter offline\n"); |
dea3101e JB |
2500 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
2501 | now. */ | |
2502 | lpfc_sli_hba_down(phba); | |
92d7f7b0 | 2503 | spin_lock_irq(&phba->hbalock); |
7054a606 | 2504 | phba->work_ha = 0; |
92d7f7b0 | 2505 | spin_unlock_irq(&phba->hbalock); |
549e55cd JS |
2506 | vports = lpfc_create_vport_work_array(phba); |
2507 | if (vports != NULL) | |
da0436e9 | 2508 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd | 2509 | shost = lpfc_shost_from_vport(vports[i]); |
549e55cd JS |
2510 | spin_lock_irq(shost->host_lock); |
2511 | vports[i]->work_port_events = 0; | |
2512 | vports[i]->fc_flag |= FC_OFFLINE_MODE; | |
2513 | spin_unlock_irq(shost->host_lock); | |
2514 | } | |
09372820 | 2515 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e JB |
2516 | } |
2517 | ||
e59058c4 | 2518 | /** |
3621a710 | 2519 | * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists |
e59058c4 JS |
2520 | * @phba: pointer to lpfc hba data structure. |
2521 | * | |
2522 | * This routine is to free all the SCSI buffers and IOCBs from the driver | |
2523 | * list back to kernel. It is called from lpfc_pci_remove_one to free | |
2524 | * the internal resources before the device is removed from the system. | |
2525 | * | |
2526 | * Return codes | |
2527 | * 0 - successful (for now, it always returns 0) | |
2528 | **/ | |
dea3101e | 2529 | static int |
2e0fef85 | 2530 | lpfc_scsi_free(struct lpfc_hba *phba) |
dea3101e JB |
2531 | { |
2532 | struct lpfc_scsi_buf *sb, *sb_next; | |
2533 | struct lpfc_iocbq *io, *io_next; | |
2534 | ||
2e0fef85 | 2535 | spin_lock_irq(&phba->hbalock); |
dea3101e | 2536 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
1c6f4ef5 | 2537 | spin_lock(&phba->scsi_buf_list_lock); |
dea3101e JB |
2538 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { |
2539 | list_del(&sb->list); | |
2540 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, | |
92d7f7b0 | 2541 | sb->dma_handle); |
dea3101e JB |
2542 | kfree(sb); |
2543 | phba->total_scsi_bufs--; | |
2544 | } | |
1c6f4ef5 | 2545 | spin_unlock(&phba->scsi_buf_list_lock); |
dea3101e JB |
2546 | |
2547 | /* Release all the lpfc_iocbq entries maintained by this host. */ | |
2548 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { | |
2549 | list_del(&io->list); | |
2550 | kfree(io); | |
2551 | phba->total_iocbq_bufs--; | |
2552 | } | |
2e0fef85 | 2553 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
2554 | return 0; |
2555 | } | |
2556 | ||
e59058c4 | 2557 | /** |
3621a710 | 2558 | * lpfc_create_port - Create an FC port |
e59058c4 JS |
2559 | * @phba: pointer to lpfc hba data structure. |
2560 | * @instance: a unique integer ID to this FC port. | |
2561 | * @dev: pointer to the device data structure. | |
2562 | * | |
2563 | * This routine creates a FC port for the upper layer protocol. The FC port | |
2564 | * can be created on top of either a physical port or a virtual port provided | |
2565 | * by the HBA. This routine also allocates a SCSI host data structure (shost) | |
2566 | * and associates the FC port created before adding the shost into the SCSI | |
2567 | * layer. | |
2568 | * | |
2569 | * Return codes | |
2570 | * @vport - pointer to the virtual N_Port data structure. | |
2571 | * NULL - port create failed. | |
2572 | **/ | |
2e0fef85 | 2573 | struct lpfc_vport * |
3de2a653 | 2574 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
47a8617c | 2575 | { |
2e0fef85 JS |
2576 | struct lpfc_vport *vport; |
2577 | struct Scsi_Host *shost; | |
2578 | int error = 0; | |
47a8617c | 2579 | |
3de2a653 JS |
2580 | if (dev != &phba->pcidev->dev) |
2581 | shost = scsi_host_alloc(&lpfc_vport_template, | |
2582 | sizeof(struct lpfc_vport)); | |
2583 | else | |
2584 | shost = scsi_host_alloc(&lpfc_template, | |
2585 | sizeof(struct lpfc_vport)); | |
2e0fef85 JS |
2586 | if (!shost) |
2587 | goto out; | |
47a8617c | 2588 | |
2e0fef85 JS |
2589 | vport = (struct lpfc_vport *) shost->hostdata; |
2590 | vport->phba = phba; | |
2e0fef85 | 2591 | vport->load_flag |= FC_LOADING; |
92d7f7b0 | 2592 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
7f5f3d0d | 2593 | vport->fc_rscn_flush = 0; |
47a8617c | 2594 | |
3de2a653 | 2595 | lpfc_get_vport_cfgparam(vport); |
2e0fef85 JS |
2596 | shost->unique_id = instance; |
2597 | shost->max_id = LPFC_MAX_TARGET; | |
3de2a653 | 2598 | shost->max_lun = vport->cfg_max_luns; |
2e0fef85 JS |
2599 | shost->this_id = -1; |
2600 | shost->max_cmd_len = 16; | |
da0436e9 | 2601 | if (phba->sli_rev == LPFC_SLI_REV4) { |
28baac74 | 2602 | shost->dma_boundary = |
cb5172ea | 2603 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
da0436e9 JS |
2604 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
2605 | } | |
81301a9b | 2606 | |
47a8617c | 2607 | /* |
2e0fef85 JS |
2608 | * Set initial can_queue value since 0 is no longer supported and |
2609 | * scsi_add_host will fail. This will be adjusted later based on the | |
2610 | * max xri value determined in hba setup. | |
47a8617c | 2611 | */ |
2e0fef85 | 2612 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
3de2a653 | 2613 | if (dev != &phba->pcidev->dev) { |
92d7f7b0 JS |
2614 | shost->transportt = lpfc_vport_transport_template; |
2615 | vport->port_type = LPFC_NPIV_PORT; | |
2616 | } else { | |
2617 | shost->transportt = lpfc_transport_template; | |
2618 | vport->port_type = LPFC_PHYSICAL_PORT; | |
2619 | } | |
47a8617c | 2620 | |
2e0fef85 JS |
2621 | /* Initialize all internally managed lists. */ |
2622 | INIT_LIST_HEAD(&vport->fc_nodes); | |
da0436e9 | 2623 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
2e0fef85 | 2624 | spin_lock_init(&vport->work_port_lock); |
47a8617c | 2625 | |
2e0fef85 JS |
2626 | init_timer(&vport->fc_disctmo); |
2627 | vport->fc_disctmo.function = lpfc_disc_timeout; | |
92d7f7b0 | 2628 | vport->fc_disctmo.data = (unsigned long)vport; |
47a8617c | 2629 | |
2e0fef85 JS |
2630 | init_timer(&vport->fc_fdmitmo); |
2631 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; | |
92d7f7b0 | 2632 | vport->fc_fdmitmo.data = (unsigned long)vport; |
47a8617c | 2633 | |
2e0fef85 JS |
2634 | init_timer(&vport->els_tmofunc); |
2635 | vport->els_tmofunc.function = lpfc_els_timeout; | |
92d7f7b0 | 2636 | vport->els_tmofunc.data = (unsigned long)vport; |
d139b9bd | 2637 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
2e0fef85 JS |
2638 | if (error) |
2639 | goto out_put_shost; | |
47a8617c | 2640 | |
549e55cd | 2641 | spin_lock_irq(&phba->hbalock); |
2e0fef85 | 2642 | list_add_tail(&vport->listentry, &phba->port_list); |
549e55cd | 2643 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 2644 | return vport; |
47a8617c | 2645 | |
2e0fef85 JS |
2646 | out_put_shost: |
2647 | scsi_host_put(shost); | |
2648 | out: | |
2649 | return NULL; | |
47a8617c JS |
2650 | } |
2651 | ||
e59058c4 | 2652 | /** |
3621a710 | 2653 | * destroy_port - destroy an FC port |
e59058c4 JS |
2654 | * @vport: pointer to an lpfc virtual N_Port data structure. |
2655 | * | |
2656 | * This routine destroys a FC port from the upper layer protocol. All the | |
2657 | * resources associated with the port are released. | |
2658 | **/ | |
2e0fef85 JS |
2659 | void |
2660 | destroy_port(struct lpfc_vport *vport) | |
47a8617c | 2661 | { |
92d7f7b0 JS |
2662 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2663 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 2664 | |
858c9f6c | 2665 | lpfc_debugfs_terminate(vport); |
92d7f7b0 JS |
2666 | fc_remove_host(shost); |
2667 | scsi_remove_host(shost); | |
47a8617c | 2668 | |
92d7f7b0 JS |
2669 | spin_lock_irq(&phba->hbalock); |
2670 | list_del_init(&vport->listentry); | |
2671 | spin_unlock_irq(&phba->hbalock); | |
47a8617c | 2672 | |
92d7f7b0 | 2673 | lpfc_cleanup(vport); |
47a8617c | 2674 | return; |
47a8617c JS |
2675 | } |
2676 | ||
e59058c4 | 2677 | /** |
3621a710 | 2678 | * lpfc_get_instance - Get a unique integer ID |
e59058c4 JS |
2679 | * |
2680 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It | |
2681 | * uses the kernel idr facility to perform the task. | |
2682 | * | |
2683 | * Return codes: | |
2684 | * instance - a unique integer ID allocated as the new instance. | |
2685 | * -1 - lpfc get instance failed. | |
2686 | **/ | |
92d7f7b0 JS |
2687 | int |
2688 | lpfc_get_instance(void) | |
2689 | { | |
2690 | int instance = 0; | |
47a8617c | 2691 | |
92d7f7b0 JS |
2692 | /* Assign an unused number */ |
2693 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) | |
2694 | return -1; | |
2695 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) | |
2696 | return -1; | |
2697 | return instance; | |
47a8617c JS |
2698 | } |
2699 | ||
e59058c4 | 2700 | /** |
3621a710 | 2701 | * lpfc_scan_finished - method for SCSI layer to detect whether scan is done |
e59058c4 JS |
2702 | * @shost: pointer to SCSI host data structure. |
2703 | * @time: elapsed time of the scan in jiffies. | |
2704 | * | |
2705 | * This routine is called by the SCSI layer with a SCSI host to determine | |
2706 | * whether the scan host is finished. | |
2707 | * | |
2708 | * Note: there is no scan_start function as adapter initialization will have | |
2709 | * asynchronously kicked off the link initialization. | |
2710 | * | |
2711 | * Return codes | |
2712 | * 0 - SCSI host scan is not over yet. | |
2713 | * 1 - SCSI host scan is over. | |
2714 | **/ | |
47a8617c JS |
2715 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
2716 | { | |
2e0fef85 JS |
2717 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
2718 | struct lpfc_hba *phba = vport->phba; | |
858c9f6c | 2719 | int stat = 0; |
47a8617c | 2720 | |
858c9f6c JS |
2721 | spin_lock_irq(shost->host_lock); |
2722 | ||
51ef4c26 | 2723 | if (vport->load_flag & FC_UNLOADING) { |
858c9f6c JS |
2724 | stat = 1; |
2725 | goto finished; | |
2726 | } | |
2e0fef85 JS |
2727 | if (time >= 30 * HZ) { |
2728 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
2729 | "0461 Scanning longer than 30 " |
2730 | "seconds. Continuing initialization\n"); | |
858c9f6c | 2731 | stat = 1; |
47a8617c | 2732 | goto finished; |
2e0fef85 JS |
2733 | } |
2734 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { | |
2735 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
2736 | "0465 Link down longer than 15 " |
2737 | "seconds. Continuing initialization\n"); | |
858c9f6c | 2738 | stat = 1; |
47a8617c | 2739 | goto finished; |
2e0fef85 | 2740 | } |
47a8617c | 2741 | |
2e0fef85 | 2742 | if (vport->port_state != LPFC_VPORT_READY) |
858c9f6c | 2743 | goto finished; |
2e0fef85 | 2744 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
858c9f6c | 2745 | goto finished; |
2e0fef85 | 2746 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
858c9f6c | 2747 | goto finished; |
2e0fef85 | 2748 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
858c9f6c JS |
2749 | goto finished; |
2750 | ||
2751 | stat = 1; | |
47a8617c JS |
2752 | |
2753 | finished: | |
858c9f6c JS |
2754 | spin_unlock_irq(shost->host_lock); |
2755 | return stat; | |
92d7f7b0 | 2756 | } |
47a8617c | 2757 | |
e59058c4 | 2758 | /** |
3621a710 | 2759 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
e59058c4 JS |
2760 | * @shost: pointer to SCSI host data structure. |
2761 | * | |
2762 | * This routine initializes a given SCSI host attributes on a FC port. The | |
2763 | * SCSI host can be either on top of a physical port or a virtual port. | |
2764 | **/ | |
92d7f7b0 JS |
2765 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
2766 | { | |
2767 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2768 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 2769 | /* |
2e0fef85 | 2770 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
47a8617c JS |
2771 | */ |
2772 | ||
2e0fef85 JS |
2773 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
2774 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
47a8617c JS |
2775 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
2776 | ||
2777 | memset(fc_host_supported_fc4s(shost), 0, | |
2e0fef85 | 2778 | sizeof(fc_host_supported_fc4s(shost))); |
47a8617c JS |
2779 | fc_host_supported_fc4s(shost)[2] = 1; |
2780 | fc_host_supported_fc4s(shost)[7] = 1; | |
2781 | ||
92d7f7b0 JS |
2782 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
2783 | sizeof fc_host_symbolic_name(shost)); | |
47a8617c JS |
2784 | |
2785 | fc_host_supported_speeds(shost) = 0; | |
2786 | if (phba->lmt & LMT_10Gb) | |
2787 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; | |
a8adb832 JS |
2788 | if (phba->lmt & LMT_8Gb) |
2789 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; | |
47a8617c JS |
2790 | if (phba->lmt & LMT_4Gb) |
2791 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; | |
2792 | if (phba->lmt & LMT_2Gb) | |
2793 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; | |
2794 | if (phba->lmt & LMT_1Gb) | |
2795 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; | |
2796 | ||
2797 | fc_host_maxframe_size(shost) = | |
2e0fef85 JS |
2798 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
2799 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; | |
47a8617c JS |
2800 | |
2801 | /* This value is also unchanging */ | |
2802 | memset(fc_host_active_fc4s(shost), 0, | |
2e0fef85 | 2803 | sizeof(fc_host_active_fc4s(shost))); |
47a8617c JS |
2804 | fc_host_active_fc4s(shost)[2] = 1; |
2805 | fc_host_active_fc4s(shost)[7] = 1; | |
2806 | ||
92d7f7b0 | 2807 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
47a8617c | 2808 | spin_lock_irq(shost->host_lock); |
51ef4c26 | 2809 | vport->load_flag &= ~FC_LOADING; |
47a8617c | 2810 | spin_unlock_irq(shost->host_lock); |
47a8617c | 2811 | } |
dea3101e | 2812 | |
e59058c4 | 2813 | /** |
da0436e9 | 2814 | * lpfc_stop_port_s3 - Stop SLI3 device port |
e59058c4 JS |
2815 | * @phba: pointer to lpfc hba data structure. |
2816 | * | |
da0436e9 JS |
2817 | * This routine is invoked to stop an SLI3 device port, it stops the device |
2818 | * from generating interrupts and stops the device driver's timers for the | |
2819 | * device. | |
e59058c4 | 2820 | **/ |
da0436e9 JS |
2821 | static void |
2822 | lpfc_stop_port_s3(struct lpfc_hba *phba) | |
db2378e0 | 2823 | { |
da0436e9 JS |
2824 | /* Clear all interrupt enable conditions */ |
2825 | writel(0, phba->HCregaddr); | |
2826 | readl(phba->HCregaddr); /* flush */ | |
2827 | /* Clear all pending interrupts */ | |
2828 | writel(0xffffffff, phba->HAregaddr); | |
2829 | readl(phba->HAregaddr); /* flush */ | |
db2378e0 | 2830 | |
da0436e9 JS |
2831 | /* Reset some HBA SLI setup states */ |
2832 | lpfc_stop_hba_timers(phba); | |
2833 | phba->pport->work_port_events = 0; | |
2834 | } | |
db2378e0 | 2835 | |
da0436e9 JS |
2836 | /** |
2837 | * lpfc_stop_port_s4 - Stop SLI4 device port | |
2838 | * @phba: pointer to lpfc hba data structure. | |
2839 | * | |
2840 | * This routine is invoked to stop an SLI4 device port, it stops the device | |
2841 | * from generating interrupts and stops the device driver's timers for the | |
2842 | * device. | |
2843 | **/ | |
2844 | static void | |
2845 | lpfc_stop_port_s4(struct lpfc_hba *phba) | |
2846 | { | |
2847 | /* Reset some HBA SLI4 setup states */ | |
2848 | lpfc_stop_hba_timers(phba); | |
2849 | phba->pport->work_port_events = 0; | |
2850 | phba->sli4_hba.intr_enable = 0; | |
da0436e9 | 2851 | } |
9399627f | 2852 | |
da0436e9 JS |
2853 | /** |
2854 | * lpfc_stop_port - Wrapper function for stopping hba port | |
2855 | * @phba: Pointer to HBA context object. | |
2856 | * | |
2857 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from | |
2858 | * the API jump table function pointer from the lpfc_hba struct. | |
2859 | **/ | |
2860 | void | |
2861 | lpfc_stop_port(struct lpfc_hba *phba) | |
2862 | { | |
2863 | phba->lpfc_stop_port(phba); | |
2864 | } | |
db2378e0 | 2865 | |
da0436e9 JS |
2866 | /** |
2867 | * lpfc_sli4_remove_dflt_fcf - Remove the driver default fcf record from the port. | |
2868 | * @phba: pointer to lpfc hba data structure. | |
2869 | * | |
2870 | * This routine is invoked to remove the driver default fcf record from | |
2871 | * the port. This routine currently acts on FCF Index 0. | |
2872 | * | |
2873 | **/ | |
2874 | void | |
2875 | lpfc_sli_remove_dflt_fcf(struct lpfc_hba *phba) | |
2876 | { | |
2877 | int rc = 0; | |
2878 | LPFC_MBOXQ_t *mboxq; | |
2879 | struct lpfc_mbx_del_fcf_tbl_entry *del_fcf_record; | |
2880 | uint32_t mbox_tmo, req_len; | |
2881 | uint32_t shdr_status, shdr_add_status; | |
9399627f | 2882 | |
da0436e9 JS |
2883 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
2884 | if (!mboxq) { | |
2885 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2886 | "2020 Failed to allocate mbox for ADD_FCF cmd\n"); | |
2887 | return; | |
db2378e0 | 2888 | } |
9399627f | 2889 | |
da0436e9 JS |
2890 | req_len = sizeof(struct lpfc_mbx_del_fcf_tbl_entry) - |
2891 | sizeof(struct lpfc_sli4_cfg_mhdr); | |
2892 | rc = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, | |
2893 | LPFC_MBOX_OPCODE_FCOE_DELETE_FCF, | |
2894 | req_len, LPFC_SLI4_MBX_EMBED); | |
9399627f | 2895 | /* |
da0436e9 JS |
2896 | * In phase 1, there is a single FCF index, 0. In phase2, the driver |
2897 | * supports multiple FCF indices. | |
9399627f | 2898 | */ |
da0436e9 JS |
2899 | del_fcf_record = &mboxq->u.mqe.un.del_fcf_entry; |
2900 | bf_set(lpfc_mbx_del_fcf_tbl_count, del_fcf_record, 1); | |
2901 | bf_set(lpfc_mbx_del_fcf_tbl_index, del_fcf_record, | |
ecfd03c6 | 2902 | phba->fcf.current_rec.fcf_indx); |
9399627f | 2903 | |
da0436e9 JS |
2904 | if (!phba->sli4_hba.intr_enable) |
2905 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
2906 | else { | |
2907 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
2908 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
9399627f | 2909 | } |
da0436e9 JS |
2910 | /* The IOCTL status is embedded in the mailbox subheader. */ |
2911 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
2912 | &del_fcf_record->header.cfg_shdr.response); | |
2913 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
2914 | &del_fcf_record->header.cfg_shdr.response); | |
2915 | if (shdr_status || shdr_add_status || rc != MBX_SUCCESS) { | |
2916 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2917 | "2516 DEL FCF of default FCF Index failed " | |
2918 | "mbx status x%x, status x%x add_status x%x\n", | |
2919 | rc, shdr_status, shdr_add_status); | |
9399627f | 2920 | } |
da0436e9 JS |
2921 | if (rc != MBX_TIMEOUT) |
2922 | mempool_free(mboxq, phba->mbox_mem_pool); | |
db2378e0 JS |
2923 | } |
2924 | ||
ecfd03c6 JS |
2925 | /** |
2926 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer | |
2927 | * @phba: Pointer to hba for which this call is being executed. | |
2928 | * | |
2929 | * This routine starts the timer waiting for the FCF rediscovery to complete. | |
2930 | **/ | |
2931 | void | |
2932 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) | |
2933 | { | |
2934 | unsigned long fcf_redisc_wait_tmo = | |
2935 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); | |
2936 | /* Start fcf rediscovery wait period timer */ | |
2937 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); | |
2938 | spin_lock_irq(&phba->hbalock); | |
2939 | /* Allow action to new fcf asynchronous event */ | |
2940 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); | |
2941 | /* Mark the FCF rediscovery pending state */ | |
2942 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; | |
2943 | spin_unlock_irq(&phba->hbalock); | |
2944 | } | |
2945 | ||
2946 | /** | |
2947 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout | |
2948 | * @ptr: Map to lpfc_hba data structure pointer. | |
2949 | * | |
2950 | * This routine is invoked when waiting for FCF table rediscover has been | |
2951 | * timed out. If new FCF record(s) has (have) been discovered during the | |
2952 | * wait period, a new FCF event shall be added to the FCOE async event | |
2953 | * list, and then worker thread shall be waked up for processing from the | |
2954 | * worker thread context. | |
2955 | **/ | |
2956 | void | |
2957 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) | |
2958 | { | |
2959 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; | |
2960 | ||
2961 | /* Don't send FCF rediscovery event if timer cancelled */ | |
2962 | spin_lock_irq(&phba->hbalock); | |
2963 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
2964 | spin_unlock_irq(&phba->hbalock); | |
2965 | return; | |
2966 | } | |
2967 | /* Clear FCF rediscovery timer pending flag */ | |
2968 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; | |
2969 | /* FCF rediscovery event to worker thread */ | |
2970 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; | |
2971 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 JS |
2972 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
2973 | "2776 FCF rediscover wait timer expired, post " | |
2974 | "a worker thread event for FCF table scan\n"); | |
ecfd03c6 JS |
2975 | /* wake up worker thread */ |
2976 | lpfc_worker_wake_up(phba); | |
2977 | } | |
2978 | ||
6669f9bb JS |
2979 | /** |
2980 | * lpfc_sli4_fw_cfg_check - Read the firmware config and verify FCoE support | |
2981 | * @phba: pointer to lpfc hba data structure. | |
2982 | * | |
2983 | * This function uses the QUERY_FW_CFG mailbox command to determine if the | |
2984 | * firmware loaded supports FCoE. A return of zero indicates that the mailbox | |
2985 | * was successful and the firmware supports FCoE. Any other return indicates | |
2986 | * a error. It is assumed that this function will be called before interrupts | |
2987 | * are enabled. | |
2988 | **/ | |
2989 | static int | |
2990 | lpfc_sli4_fw_cfg_check(struct lpfc_hba *phba) | |
2991 | { | |
2992 | int rc = 0; | |
2993 | LPFC_MBOXQ_t *mboxq; | |
2994 | struct lpfc_mbx_query_fw_cfg *query_fw_cfg; | |
2995 | uint32_t length; | |
2996 | uint32_t shdr_status, shdr_add_status; | |
2997 | ||
2998 | mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
2999 | if (!mboxq) { | |
3000 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3001 | "2621 Failed to allocate mbox for " | |
3002 | "query firmware config cmd\n"); | |
3003 | return -ENOMEM; | |
3004 | } | |
3005 | query_fw_cfg = &mboxq->u.mqe.un.query_fw_cfg; | |
3006 | length = (sizeof(struct lpfc_mbx_query_fw_cfg) - | |
3007 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
3008 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
3009 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, | |
3010 | length, LPFC_SLI4_MBX_EMBED); | |
3011 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
3012 | /* The IOCTL status is embedded in the mailbox subheader. */ | |
3013 | shdr_status = bf_get(lpfc_mbox_hdr_status, | |
3014 | &query_fw_cfg->header.cfg_shdr.response); | |
3015 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
3016 | &query_fw_cfg->header.cfg_shdr.response); | |
3017 | if (shdr_status || shdr_add_status || rc != MBX_SUCCESS) { | |
3018 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3019 | "2622 Query Firmware Config failed " | |
3020 | "mbx status x%x, status x%x add_status x%x\n", | |
3021 | rc, shdr_status, shdr_add_status); | |
3022 | return -EINVAL; | |
3023 | } | |
3024 | if (!bf_get(lpfc_function_mode_fcoe_i, query_fw_cfg)) { | |
3025 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3026 | "2623 FCoE Function not supported by firmware. " | |
3027 | "Function mode = %08x\n", | |
3028 | query_fw_cfg->function_mode); | |
3029 | return -EINVAL; | |
3030 | } | |
3031 | if (rc != MBX_TIMEOUT) | |
3032 | mempool_free(mboxq, phba->mbox_mem_pool); | |
3033 | return 0; | |
3034 | } | |
3035 | ||
e59058c4 | 3036 | /** |
da0436e9 | 3037 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
e59058c4 | 3038 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3039 | * @acqe_link: pointer to the async link completion queue entry. |
e59058c4 | 3040 | * |
da0436e9 JS |
3041 | * This routine is to parse the SLI4 link-attention link fault code and |
3042 | * translate it into the base driver's read link attention mailbox command | |
3043 | * status. | |
3044 | * | |
3045 | * Return: Link-attention status in terms of base driver's coding. | |
e59058c4 | 3046 | **/ |
da0436e9 JS |
3047 | static uint16_t |
3048 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, | |
3049 | struct lpfc_acqe_link *acqe_link) | |
db2378e0 | 3050 | { |
da0436e9 | 3051 | uint16_t latt_fault; |
9399627f | 3052 | |
da0436e9 JS |
3053 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
3054 | case LPFC_ASYNC_LINK_FAULT_NONE: | |
3055 | case LPFC_ASYNC_LINK_FAULT_LOCAL: | |
3056 | case LPFC_ASYNC_LINK_FAULT_REMOTE: | |
3057 | latt_fault = 0; | |
3058 | break; | |
3059 | default: | |
3060 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3061 | "0398 Invalid link fault code: x%x\n", | |
3062 | bf_get(lpfc_acqe_link_fault, acqe_link)); | |
3063 | latt_fault = MBXERR_ERROR; | |
3064 | break; | |
3065 | } | |
3066 | return latt_fault; | |
db2378e0 JS |
3067 | } |
3068 | ||
5b75da2f | 3069 | /** |
da0436e9 | 3070 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
5b75da2f | 3071 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3072 | * @acqe_link: pointer to the async link completion queue entry. |
5b75da2f | 3073 | * |
da0436e9 JS |
3074 | * This routine is to parse the SLI4 link attention type and translate it |
3075 | * into the base driver's link attention type coding. | |
5b75da2f | 3076 | * |
da0436e9 JS |
3077 | * Return: Link attention type in terms of base driver's coding. |
3078 | **/ | |
3079 | static uint8_t | |
3080 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, | |
3081 | struct lpfc_acqe_link *acqe_link) | |
5b75da2f | 3082 | { |
da0436e9 | 3083 | uint8_t att_type; |
5b75da2f | 3084 | |
da0436e9 JS |
3085 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
3086 | case LPFC_ASYNC_LINK_STATUS_DOWN: | |
3087 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: | |
3088 | att_type = AT_LINK_DOWN; | |
3089 | break; | |
3090 | case LPFC_ASYNC_LINK_STATUS_UP: | |
3091 | /* Ignore physical link up events - wait for logical link up */ | |
3092 | att_type = AT_RESERVED; | |
3093 | break; | |
3094 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: | |
3095 | att_type = AT_LINK_UP; | |
3096 | break; | |
3097 | default: | |
3098 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3099 | "0399 Invalid link attention type: x%x\n", | |
3100 | bf_get(lpfc_acqe_link_status, acqe_link)); | |
3101 | att_type = AT_RESERVED; | |
3102 | break; | |
5b75da2f | 3103 | } |
da0436e9 | 3104 | return att_type; |
5b75da2f JS |
3105 | } |
3106 | ||
3107 | /** | |
da0436e9 | 3108 | * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed |
5b75da2f | 3109 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3110 | * @acqe_link: pointer to the async link completion queue entry. |
5b75da2f | 3111 | * |
da0436e9 JS |
3112 | * This routine is to parse the SLI4 link-attention link speed and translate |
3113 | * it into the base driver's link-attention link speed coding. | |
3114 | * | |
3115 | * Return: Link-attention link speed in terms of base driver's coding. | |
3116 | **/ | |
3117 | static uint8_t | |
3118 | lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba, | |
3119 | struct lpfc_acqe_link *acqe_link) | |
5b75da2f | 3120 | { |
da0436e9 JS |
3121 | uint8_t link_speed; |
3122 | ||
3123 | switch (bf_get(lpfc_acqe_link_speed, acqe_link)) { | |
3124 | case LPFC_ASYNC_LINK_SPEED_ZERO: | |
3125 | link_speed = LA_UNKNW_LINK; | |
3126 | break; | |
3127 | case LPFC_ASYNC_LINK_SPEED_10MBPS: | |
3128 | link_speed = LA_UNKNW_LINK; | |
3129 | break; | |
3130 | case LPFC_ASYNC_LINK_SPEED_100MBPS: | |
3131 | link_speed = LA_UNKNW_LINK; | |
3132 | break; | |
3133 | case LPFC_ASYNC_LINK_SPEED_1GBPS: | |
3134 | link_speed = LA_1GHZ_LINK; | |
3135 | break; | |
3136 | case LPFC_ASYNC_LINK_SPEED_10GBPS: | |
3137 | link_speed = LA_10GHZ_LINK; | |
3138 | break; | |
3139 | default: | |
3140 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3141 | "0483 Invalid link-attention link speed: x%x\n", | |
3142 | bf_get(lpfc_acqe_link_speed, acqe_link)); | |
3143 | link_speed = LA_UNKNW_LINK; | |
3144 | break; | |
3145 | } | |
3146 | return link_speed; | |
3147 | } | |
3148 | ||
3149 | /** | |
3150 | * lpfc_sli4_async_link_evt - Process the asynchronous link event | |
3151 | * @phba: pointer to lpfc hba data structure. | |
3152 | * @acqe_link: pointer to the async link completion queue entry. | |
3153 | * | |
3154 | * This routine is to handle the SLI4 asynchronous link event. | |
3155 | **/ | |
3156 | static void | |
3157 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, | |
3158 | struct lpfc_acqe_link *acqe_link) | |
3159 | { | |
3160 | struct lpfc_dmabuf *mp; | |
3161 | LPFC_MBOXQ_t *pmb; | |
3162 | MAILBOX_t *mb; | |
3163 | READ_LA_VAR *la; | |
3164 | uint8_t att_type; | |
3165 | ||
3166 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); | |
3167 | if (att_type != AT_LINK_DOWN && att_type != AT_LINK_UP) | |
3168 | return; | |
32b9793f | 3169 | phba->fcoe_eventtag = acqe_link->event_tag; |
da0436e9 JS |
3170 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3171 | if (!pmb) { | |
3172 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3173 | "0395 The mboxq allocation failed\n"); | |
3174 | return; | |
3175 | } | |
3176 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
3177 | if (!mp) { | |
3178 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3179 | "0396 The lpfc_dmabuf allocation failed\n"); | |
3180 | goto out_free_pmb; | |
3181 | } | |
3182 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
3183 | if (!mp->virt) { | |
3184 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3185 | "0397 The mbuf allocation failed\n"); | |
3186 | goto out_free_dmabuf; | |
3187 | } | |
3188 | ||
3189 | /* Cleanup any outstanding ELS commands */ | |
3190 | lpfc_els_flush_all_cmd(phba); | |
3191 | ||
3192 | /* Block ELS IOCBs until we have done process link event */ | |
3193 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
3194 | ||
3195 | /* Update link event statistics */ | |
3196 | phba->sli.slistat.link_event++; | |
3197 | ||
3198 | /* Create pseudo lpfc_handle_latt mailbox command from link ACQE */ | |
3199 | lpfc_read_la(phba, pmb, mp); | |
3200 | pmb->vport = phba->pport; | |
3201 | ||
3202 | /* Parse and translate status field */ | |
3203 | mb = &pmb->u.mb; | |
3204 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); | |
3205 | ||
3206 | /* Parse and translate link attention fields */ | |
3207 | la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA; | |
3208 | la->eventTag = acqe_link->event_tag; | |
3209 | la->attType = att_type; | |
3210 | la->UlnkSpeed = lpfc_sli4_parse_latt_link_speed(phba, acqe_link); | |
3211 | ||
3212 | /* Fake the the following irrelvant fields */ | |
3213 | la->topology = TOPOLOGY_PT_PT; | |
3214 | la->granted_AL_PA = 0; | |
3215 | la->il = 0; | |
3216 | la->pb = 0; | |
3217 | la->fa = 0; | |
3218 | la->mm = 0; | |
3219 | ||
3220 | /* Keep the link status for extra SLI4 state machine reference */ | |
3221 | phba->sli4_hba.link_state.speed = | |
3222 | bf_get(lpfc_acqe_link_speed, acqe_link); | |
3223 | phba->sli4_hba.link_state.duplex = | |
3224 | bf_get(lpfc_acqe_link_duplex, acqe_link); | |
3225 | phba->sli4_hba.link_state.status = | |
3226 | bf_get(lpfc_acqe_link_status, acqe_link); | |
3227 | phba->sli4_hba.link_state.physical = | |
3228 | bf_get(lpfc_acqe_link_physical, acqe_link); | |
3229 | phba->sli4_hba.link_state.fault = | |
3230 | bf_get(lpfc_acqe_link_fault, acqe_link); | |
65467b6b JS |
3231 | phba->sli4_hba.link_state.logical_speed = |
3232 | bf_get(lpfc_acqe_qos_link_speed, acqe_link); | |
da0436e9 JS |
3233 | |
3234 | /* Invoke the lpfc_handle_latt mailbox command callback function */ | |
3235 | lpfc_mbx_cmpl_read_la(phba, pmb); | |
3236 | ||
5b75da2f | 3237 | return; |
da0436e9 JS |
3238 | |
3239 | out_free_dmabuf: | |
3240 | kfree(mp); | |
3241 | out_free_pmb: | |
3242 | mempool_free(pmb, phba->mbox_mem_pool); | |
3243 | } | |
3244 | ||
fc2b989b JS |
3245 | /** |
3246 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport | |
3247 | * @vport: pointer to vport data structure. | |
3248 | * | |
3249 | * This routine is to perform Clear Virtual Link (CVL) on a vport in | |
3250 | * response to a CVL event. | |
3251 | * | |
3252 | * Return the pointer to the ndlp with the vport if successful, otherwise | |
3253 | * return NULL. | |
3254 | **/ | |
3255 | static struct lpfc_nodelist * | |
3256 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) | |
3257 | { | |
3258 | struct lpfc_nodelist *ndlp; | |
3259 | struct Scsi_Host *shost; | |
3260 | struct lpfc_hba *phba; | |
3261 | ||
3262 | if (!vport) | |
3263 | return NULL; | |
fc2b989b JS |
3264 | phba = vport->phba; |
3265 | if (!phba) | |
3266 | return NULL; | |
78730cfe JS |
3267 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
3268 | if (!ndlp) { | |
3269 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | |
3270 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
3271 | if (!ndlp) | |
3272 | return 0; | |
3273 | lpfc_nlp_init(vport, ndlp, Fabric_DID); | |
3274 | /* Set the node type */ | |
3275 | ndlp->nlp_type |= NLP_FABRIC; | |
3276 | /* Put ndlp onto node list */ | |
3277 | lpfc_enqueue_node(vport, ndlp); | |
3278 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
3279 | /* re-setup ndlp without removing from node list */ | |
3280 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
3281 | if (!ndlp) | |
3282 | return 0; | |
3283 | } | |
fc2b989b JS |
3284 | if (phba->pport->port_state <= LPFC_FLOGI) |
3285 | return NULL; | |
3286 | /* If virtual link is not yet instantiated ignore CVL */ | |
3287 | if (vport->port_state <= LPFC_FDISC) | |
3288 | return NULL; | |
3289 | shost = lpfc_shost_from_vport(vport); | |
3290 | if (!shost) | |
3291 | return NULL; | |
3292 | lpfc_linkdown_port(vport); | |
3293 | lpfc_cleanup_pending_mbox(vport); | |
3294 | spin_lock_irq(shost->host_lock); | |
3295 | vport->fc_flag |= FC_VPORT_CVL_RCVD; | |
3296 | spin_unlock_irq(shost->host_lock); | |
3297 | ||
3298 | return ndlp; | |
3299 | } | |
3300 | ||
3301 | /** | |
3302 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports | |
3303 | * @vport: pointer to lpfc hba data structure. | |
3304 | * | |
3305 | * This routine is to perform Clear Virtual Link (CVL) on all vports in | |
3306 | * response to a FCF dead event. | |
3307 | **/ | |
3308 | static void | |
3309 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) | |
3310 | { | |
3311 | struct lpfc_vport **vports; | |
3312 | int i; | |
3313 | ||
3314 | vports = lpfc_create_vport_work_array(phba); | |
3315 | if (vports) | |
3316 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) | |
3317 | lpfc_sli4_perform_vport_cvl(vports[i]); | |
3318 | lpfc_destroy_vport_work_array(phba, vports); | |
3319 | } | |
3320 | ||
da0436e9 JS |
3321 | /** |
3322 | * lpfc_sli4_async_fcoe_evt - Process the asynchronous fcoe event | |
3323 | * @phba: pointer to lpfc hba data structure. | |
3324 | * @acqe_link: pointer to the async fcoe completion queue entry. | |
3325 | * | |
3326 | * This routine is to handle the SLI4 asynchronous fcoe event. | |
3327 | **/ | |
3328 | static void | |
3329 | lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba, | |
3330 | struct lpfc_acqe_fcoe *acqe_fcoe) | |
3331 | { | |
3332 | uint8_t event_type = bf_get(lpfc_acqe_fcoe_event_type, acqe_fcoe); | |
3333 | int rc; | |
6669f9bb JS |
3334 | struct lpfc_vport *vport; |
3335 | struct lpfc_nodelist *ndlp; | |
3336 | struct Scsi_Host *shost; | |
695a814e JS |
3337 | int active_vlink_present; |
3338 | struct lpfc_vport **vports; | |
3339 | int i; | |
da0436e9 | 3340 | |
4d9ab994 | 3341 | phba->fc_eventTag = acqe_fcoe->event_tag; |
32b9793f | 3342 | phba->fcoe_eventtag = acqe_fcoe->event_tag; |
da0436e9 JS |
3343 | switch (event_type) { |
3344 | case LPFC_FCOE_EVENT_TYPE_NEW_FCF: | |
ecfd03c6 | 3345 | case LPFC_FCOE_EVENT_TYPE_FCF_PARAM_MOD: |
999d813f JS |
3346 | if (event_type == LPFC_FCOE_EVENT_TYPE_NEW_FCF) |
3347 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | | |
3348 | LOG_DISCOVERY, | |
3349 | "2546 New FCF found event: " | |
3350 | "evt_tag:x%x, fcf_index:x%x\n", | |
3351 | acqe_fcoe->event_tag, | |
3352 | acqe_fcoe->index); | |
3353 | else | |
3354 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | | |
3355 | LOG_DISCOVERY, | |
3356 | "2788 FCF parameter modified event: " | |
3357 | "evt_tag:x%x, fcf_index:x%x\n", | |
3358 | acqe_fcoe->event_tag, | |
3359 | acqe_fcoe->index); | |
da0436e9 | 3360 | spin_lock_irq(&phba->hbalock); |
ecfd03c6 JS |
3361 | if ((phba->fcf.fcf_flag & FCF_SCAN_DONE) || |
3362 | (phba->hba_flag & FCF_DISC_INPROGRESS)) { | |
3363 | /* | |
3364 | * If the current FCF is in discovered state or | |
3365 | * FCF discovery is in progress, do nothing. | |
3366 | */ | |
3367 | spin_unlock_irq(&phba->hbalock); | |
3368 | break; | |
3369 | } | |
0c9ab6f5 | 3370 | |
ecfd03c6 JS |
3371 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { |
3372 | /* | |
3373 | * If fast FCF failover rescan event is pending, | |
3374 | * do nothing. | |
3375 | */ | |
da0436e9 JS |
3376 | spin_unlock_irq(&phba->hbalock); |
3377 | break; | |
3378 | } | |
3379 | spin_unlock_irq(&phba->hbalock); | |
3380 | ||
0c9ab6f5 JS |
3381 | if ((phba->fcf.fcf_flag & FCF_DISCOVERY) && |
3382 | !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) { | |
3383 | /* | |
3384 | * During period of FCF discovery, read the FCF | |
3385 | * table record indexed by the event to update | |
3386 | * FCF round robin failover eligible FCF bmask. | |
3387 | */ | |
3388 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | | |
3389 | LOG_DISCOVERY, | |
3390 | "2779 Read new FCF record with " | |
3391 | "fcf_index:x%x for updating FCF " | |
3392 | "round robin failover bmask\n", | |
3393 | acqe_fcoe->index); | |
3394 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fcoe->index); | |
3395 | } | |
3396 | ||
3397 | /* Otherwise, scan the entire FCF table and re-discover SAN */ | |
3398 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, | |
3399 | "2770 Start FCF table scan due to new FCF " | |
3400 | "event: evt_tag:x%x, fcf_index:x%x\n", | |
3401 | acqe_fcoe->event_tag, acqe_fcoe->index); | |
3402 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, | |
3403 | LPFC_FCOE_FCF_GET_FIRST); | |
da0436e9 | 3404 | if (rc) |
0c9ab6f5 JS |
3405 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
3406 | "2547 Issue FCF scan read FCF mailbox " | |
3407 | "command failed 0x%x\n", rc); | |
da0436e9 JS |
3408 | break; |
3409 | ||
3410 | case LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL: | |
3411 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
e4e74273 | 3412 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
da0436e9 JS |
3413 | bf_get(lpfc_acqe_fcoe_fcf_count, acqe_fcoe), |
3414 | acqe_fcoe->event_tag); | |
3415 | break; | |
3416 | ||
3417 | case LPFC_FCOE_EVENT_TYPE_FCF_DEAD: | |
0c9ab6f5 | 3418 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
6a9c52cf | 3419 | "2549 FCF disconnected from network index 0x%x" |
6669f9bb | 3420 | " tag 0x%x\n", acqe_fcoe->index, |
da0436e9 JS |
3421 | acqe_fcoe->event_tag); |
3422 | /* If the event is not for currently used fcf do nothing */ | |
ecfd03c6 | 3423 | if (phba->fcf.current_rec.fcf_indx != acqe_fcoe->index) |
da0436e9 | 3424 | break; |
fc2b989b JS |
3425 | /* We request port to rediscover the entire FCF table for |
3426 | * a fast recovery from case that the current FCF record | |
0c9ab6f5 JS |
3427 | * is no longer valid if we are not in the middle of FCF |
3428 | * failover process already. | |
da0436e9 | 3429 | */ |
fc2b989b | 3430 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3431 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
fc2b989b | 3432 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 JS |
3433 | /* Update FLOGI FCF failover eligible FCF bmask */ |
3434 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fcoe->index); | |
fc2b989b JS |
3435 | break; |
3436 | } | |
3437 | /* Mark the fast failover process in progress */ | |
0c9ab6f5 | 3438 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
fc2b989b | 3439 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 JS |
3440 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
3441 | "2771 Start FCF fast failover process due to " | |
3442 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " | |
3443 | "\n", acqe_fcoe->event_tag, acqe_fcoe->index); | |
fc2b989b JS |
3444 | rc = lpfc_sli4_redisc_fcf_table(phba); |
3445 | if (rc) { | |
0c9ab6f5 JS |
3446 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
3447 | LOG_DISCOVERY, | |
3448 | "2772 Issue FCF rediscover mabilbox " | |
3449 | "command failed, fail through to FCF " | |
3450 | "dead event\n"); | |
fc2b989b | 3451 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3452 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
3453 | spin_unlock_irq(&phba->hbalock); |
3454 | /* | |
3455 | * Last resort will fail over by treating this | |
3456 | * as a link down to FCF registration. | |
3457 | */ | |
3458 | lpfc_sli4_fcf_dead_failthrough(phba); | |
3459 | } else | |
3460 | /* Handling fast FCF failover to a DEAD FCF event | |
3461 | * is considered equalivant to receiving CVL to all | |
3462 | * vports. | |
3463 | */ | |
3464 | lpfc_sli4_perform_all_vport_cvl(phba); | |
da0436e9 | 3465 | break; |
6669f9bb | 3466 | case LPFC_FCOE_EVENT_TYPE_CVL: |
0c9ab6f5 | 3467 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
6669f9bb JS |
3468 | "2718 Clear Virtual Link Received for VPI 0x%x" |
3469 | " tag 0x%x\n", acqe_fcoe->index, acqe_fcoe->event_tag); | |
3470 | vport = lpfc_find_vport_by_vpid(phba, | |
c868595d | 3471 | acqe_fcoe->index - phba->vpi_base); |
fc2b989b | 3472 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
6669f9bb JS |
3473 | if (!ndlp) |
3474 | break; | |
695a814e JS |
3475 | active_vlink_present = 0; |
3476 | ||
3477 | vports = lpfc_create_vport_work_array(phba); | |
3478 | if (vports) { | |
3479 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; | |
3480 | i++) { | |
3481 | if ((!(vports[i]->fc_flag & | |
3482 | FC_VPORT_CVL_RCVD)) && | |
3483 | (vports[i]->port_state > LPFC_FDISC)) { | |
3484 | active_vlink_present = 1; | |
3485 | break; | |
3486 | } | |
3487 | } | |
3488 | lpfc_destroy_vport_work_array(phba, vports); | |
3489 | } | |
3490 | ||
3491 | if (active_vlink_present) { | |
3492 | /* | |
3493 | * If there are other active VLinks present, | |
3494 | * re-instantiate the Vlink using FDISC. | |
3495 | */ | |
6669f9bb | 3496 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
fc2b989b | 3497 | shost = lpfc_shost_from_vport(vport); |
6669f9bb JS |
3498 | spin_lock_irq(shost->host_lock); |
3499 | ndlp->nlp_flag |= NLP_DELAY_TMO; | |
3500 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
3501 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
3502 | vport->port_state = LPFC_FDISC; | |
3503 | } else { | |
ecfd03c6 JS |
3504 | /* |
3505 | * Otherwise, we request port to rediscover | |
3506 | * the entire FCF table for a fast recovery | |
3507 | * from possible case that the current FCF | |
0c9ab6f5 JS |
3508 | * is no longer valid if we are not already |
3509 | * in the FCF failover process. | |
ecfd03c6 | 3510 | */ |
fc2b989b | 3511 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3512 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
fc2b989b JS |
3513 | spin_unlock_irq(&phba->hbalock); |
3514 | break; | |
3515 | } | |
3516 | /* Mark the fast failover process in progress */ | |
0c9ab6f5 | 3517 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
fc2b989b | 3518 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 JS |
3519 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
3520 | LOG_DISCOVERY, | |
3521 | "2773 Start FCF fast failover due " | |
3522 | "to CVL event: evt_tag:x%x\n", | |
3523 | acqe_fcoe->event_tag); | |
ecfd03c6 | 3524 | rc = lpfc_sli4_redisc_fcf_table(phba); |
fc2b989b | 3525 | if (rc) { |
0c9ab6f5 JS |
3526 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
3527 | LOG_DISCOVERY, | |
3528 | "2774 Issue FCF rediscover " | |
3529 | "mabilbox command failed, " | |
3530 | "through to CVL event\n"); | |
fc2b989b | 3531 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3532 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b | 3533 | spin_unlock_irq(&phba->hbalock); |
ecfd03c6 JS |
3534 | /* |
3535 | * Last resort will be re-try on the | |
3536 | * the current registered FCF entry. | |
3537 | */ | |
3538 | lpfc_retry_pport_discovery(phba); | |
fc2b989b | 3539 | } |
6669f9bb JS |
3540 | } |
3541 | break; | |
da0436e9 JS |
3542 | default: |
3543 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3544 | "0288 Unknown FCoE event type 0x%x event tag " | |
3545 | "0x%x\n", event_type, acqe_fcoe->event_tag); | |
3546 | break; | |
3547 | } | |
3548 | } | |
3549 | ||
3550 | /** | |
3551 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event | |
3552 | * @phba: pointer to lpfc hba data structure. | |
3553 | * @acqe_link: pointer to the async dcbx completion queue entry. | |
3554 | * | |
3555 | * This routine is to handle the SLI4 asynchronous dcbx event. | |
3556 | **/ | |
3557 | static void | |
3558 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, | |
3559 | struct lpfc_acqe_dcbx *acqe_dcbx) | |
3560 | { | |
4d9ab994 | 3561 | phba->fc_eventTag = acqe_dcbx->event_tag; |
da0436e9 JS |
3562 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
3563 | "0290 The SLI4 DCBX asynchronous event is not " | |
3564 | "handled yet\n"); | |
3565 | } | |
3566 | ||
b19a061a JS |
3567 | /** |
3568 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event | |
3569 | * @phba: pointer to lpfc hba data structure. | |
3570 | * @acqe_link: pointer to the async grp5 completion queue entry. | |
3571 | * | |
3572 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event | |
3573 | * is an asynchronous notified of a logical link speed change. The Port | |
3574 | * reports the logical link speed in units of 10Mbps. | |
3575 | **/ | |
3576 | static void | |
3577 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, | |
3578 | struct lpfc_acqe_grp5 *acqe_grp5) | |
3579 | { | |
3580 | uint16_t prev_ll_spd; | |
3581 | ||
3582 | phba->fc_eventTag = acqe_grp5->event_tag; | |
3583 | phba->fcoe_eventtag = acqe_grp5->event_tag; | |
3584 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; | |
3585 | phba->sli4_hba.link_state.logical_speed = | |
3586 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)); | |
3587 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3588 | "2789 GRP5 Async Event: Updating logical link speed " | |
3589 | "from %dMbps to %dMbps\n", (prev_ll_spd * 10), | |
3590 | (phba->sli4_hba.link_state.logical_speed*10)); | |
3591 | } | |
3592 | ||
da0436e9 JS |
3593 | /** |
3594 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event | |
3595 | * @phba: pointer to lpfc hba data structure. | |
3596 | * | |
3597 | * This routine is invoked by the worker thread to process all the pending | |
3598 | * SLI4 asynchronous events. | |
3599 | **/ | |
3600 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) | |
3601 | { | |
3602 | struct lpfc_cq_event *cq_event; | |
3603 | ||
3604 | /* First, declare the async event has been handled */ | |
3605 | spin_lock_irq(&phba->hbalock); | |
3606 | phba->hba_flag &= ~ASYNC_EVENT; | |
3607 | spin_unlock_irq(&phba->hbalock); | |
3608 | /* Now, handle all the async events */ | |
3609 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { | |
3610 | /* Get the first event from the head of the event queue */ | |
3611 | spin_lock_irq(&phba->hbalock); | |
3612 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, | |
3613 | cq_event, struct lpfc_cq_event, list); | |
3614 | spin_unlock_irq(&phba->hbalock); | |
3615 | /* Process the asynchronous event */ | |
3616 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { | |
3617 | case LPFC_TRAILER_CODE_LINK: | |
3618 | lpfc_sli4_async_link_evt(phba, | |
3619 | &cq_event->cqe.acqe_link); | |
3620 | break; | |
3621 | case LPFC_TRAILER_CODE_FCOE: | |
3622 | lpfc_sli4_async_fcoe_evt(phba, | |
3623 | &cq_event->cqe.acqe_fcoe); | |
3624 | break; | |
3625 | case LPFC_TRAILER_CODE_DCBX: | |
3626 | lpfc_sli4_async_dcbx_evt(phba, | |
3627 | &cq_event->cqe.acqe_dcbx); | |
3628 | break; | |
b19a061a JS |
3629 | case LPFC_TRAILER_CODE_GRP5: |
3630 | lpfc_sli4_async_grp5_evt(phba, | |
3631 | &cq_event->cqe.acqe_grp5); | |
3632 | break; | |
da0436e9 JS |
3633 | default: |
3634 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3635 | "1804 Invalid asynchrous event code: " | |
3636 | "x%x\n", bf_get(lpfc_trailer_code, | |
3637 | &cq_event->cqe.mcqe_cmpl)); | |
3638 | break; | |
3639 | } | |
3640 | /* Free the completion event processed to the free pool */ | |
3641 | lpfc_sli4_cq_event_release(phba, cq_event); | |
3642 | } | |
3643 | } | |
3644 | ||
ecfd03c6 JS |
3645 | /** |
3646 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event | |
3647 | * @phba: pointer to lpfc hba data structure. | |
3648 | * | |
3649 | * This routine is invoked by the worker thread to process FCF table | |
3650 | * rediscovery pending completion event. | |
3651 | **/ | |
3652 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) | |
3653 | { | |
3654 | int rc; | |
3655 | ||
3656 | spin_lock_irq(&phba->hbalock); | |
3657 | /* Clear FCF rediscovery timeout event */ | |
3658 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; | |
3659 | /* Clear driver fast failover FCF record flag */ | |
3660 | phba->fcf.failover_rec.flag = 0; | |
3661 | /* Set state for FCF fast failover */ | |
3662 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; | |
3663 | spin_unlock_irq(&phba->hbalock); | |
3664 | ||
3665 | /* Scan FCF table from the first entry to re-discover SAN */ | |
0c9ab6f5 JS |
3666 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
3667 | "2777 Start FCF table scan after FCF " | |
3668 | "rediscovery quiescent period over\n"); | |
3669 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); | |
ecfd03c6 | 3670 | if (rc) |
0c9ab6f5 JS |
3671 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
3672 | "2747 Issue FCF scan read FCF mailbox " | |
3673 | "command failed 0x%x\n", rc); | |
ecfd03c6 JS |
3674 | } |
3675 | ||
da0436e9 JS |
3676 | /** |
3677 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table | |
3678 | * @phba: pointer to lpfc hba data structure. | |
3679 | * @dev_grp: The HBA PCI-Device group number. | |
3680 | * | |
3681 | * This routine is invoked to set up the per HBA PCI-Device group function | |
3682 | * API jump table entries. | |
3683 | * | |
3684 | * Return: 0 if success, otherwise -ENODEV | |
3685 | **/ | |
3686 | int | |
3687 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
3688 | { | |
3689 | int rc; | |
3690 | ||
3691 | /* Set up lpfc PCI-device group */ | |
3692 | phba->pci_dev_grp = dev_grp; | |
3693 | ||
3694 | /* The LPFC_PCI_DEV_OC uses SLI4 */ | |
3695 | if (dev_grp == LPFC_PCI_DEV_OC) | |
3696 | phba->sli_rev = LPFC_SLI_REV4; | |
3697 | ||
3698 | /* Set up device INIT API function jump table */ | |
3699 | rc = lpfc_init_api_table_setup(phba, dev_grp); | |
3700 | if (rc) | |
3701 | return -ENODEV; | |
3702 | /* Set up SCSI API function jump table */ | |
3703 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); | |
3704 | if (rc) | |
3705 | return -ENODEV; | |
3706 | /* Set up SLI API function jump table */ | |
3707 | rc = lpfc_sli_api_table_setup(phba, dev_grp); | |
3708 | if (rc) | |
3709 | return -ENODEV; | |
3710 | /* Set up MBOX API function jump table */ | |
3711 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); | |
3712 | if (rc) | |
3713 | return -ENODEV; | |
3714 | ||
3715 | return 0; | |
5b75da2f JS |
3716 | } |
3717 | ||
3718 | /** | |
3621a710 | 3719 | * lpfc_log_intr_mode - Log the active interrupt mode |
5b75da2f JS |
3720 | * @phba: pointer to lpfc hba data structure. |
3721 | * @intr_mode: active interrupt mode adopted. | |
3722 | * | |
3723 | * This routine it invoked to log the currently used active interrupt mode | |
3724 | * to the device. | |
3772a991 JS |
3725 | **/ |
3726 | static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode) | |
5b75da2f JS |
3727 | { |
3728 | switch (intr_mode) { | |
3729 | case 0: | |
3730 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3731 | "0470 Enable INTx interrupt mode.\n"); | |
3732 | break; | |
3733 | case 1: | |
3734 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3735 | "0481 Enabled MSI interrupt mode.\n"); | |
3736 | break; | |
3737 | case 2: | |
3738 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3739 | "0480 Enabled MSI-X interrupt mode.\n"); | |
3740 | break; | |
3741 | default: | |
3742 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3743 | "0482 Illegal interrupt mode.\n"); | |
3744 | break; | |
3745 | } | |
3746 | return; | |
3747 | } | |
3748 | ||
5b75da2f | 3749 | /** |
3772a991 | 3750 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
5b75da2f JS |
3751 | * @phba: pointer to lpfc hba data structure. |
3752 | * | |
3772a991 JS |
3753 | * This routine is invoked to enable the PCI device that is common to all |
3754 | * PCI devices. | |
5b75da2f JS |
3755 | * |
3756 | * Return codes | |
af901ca1 | 3757 | * 0 - successful |
3772a991 | 3758 | * other values - error |
5b75da2f | 3759 | **/ |
3772a991 JS |
3760 | static int |
3761 | lpfc_enable_pci_dev(struct lpfc_hba *phba) | |
5b75da2f | 3762 | { |
3772a991 JS |
3763 | struct pci_dev *pdev; |
3764 | int bars; | |
5b75da2f | 3765 | |
3772a991 JS |
3766 | /* Obtain PCI device reference */ |
3767 | if (!phba->pcidev) | |
3768 | goto out_error; | |
3769 | else | |
3770 | pdev = phba->pcidev; | |
3771 | /* Select PCI BARs */ | |
3772 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
3773 | /* Enable PCI device */ | |
3774 | if (pci_enable_device_mem(pdev)) | |
3775 | goto out_error; | |
3776 | /* Request PCI resource for the device */ | |
3777 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) | |
3778 | goto out_disable_device; | |
3779 | /* Set up device as PCI master and save state for EEH */ | |
3780 | pci_set_master(pdev); | |
3781 | pci_try_set_mwi(pdev); | |
3782 | pci_save_state(pdev); | |
5b75da2f | 3783 | |
3772a991 | 3784 | return 0; |
5b75da2f | 3785 | |
3772a991 JS |
3786 | out_disable_device: |
3787 | pci_disable_device(pdev); | |
3788 | out_error: | |
3789 | return -ENODEV; | |
5b75da2f JS |
3790 | } |
3791 | ||
3792 | /** | |
3772a991 | 3793 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
5b75da2f JS |
3794 | * @phba: pointer to lpfc hba data structure. |
3795 | * | |
3772a991 JS |
3796 | * This routine is invoked to disable the PCI device that is common to all |
3797 | * PCI devices. | |
5b75da2f JS |
3798 | **/ |
3799 | static void | |
3772a991 | 3800 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
5b75da2f | 3801 | { |
3772a991 JS |
3802 | struct pci_dev *pdev; |
3803 | int bars; | |
5b75da2f | 3804 | |
3772a991 JS |
3805 | /* Obtain PCI device reference */ |
3806 | if (!phba->pcidev) | |
3807 | return; | |
3808 | else | |
3809 | pdev = phba->pcidev; | |
3810 | /* Select PCI BARs */ | |
3811 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
3812 | /* Release PCI resource and disable PCI device */ | |
3813 | pci_release_selected_regions(pdev, bars); | |
3814 | pci_disable_device(pdev); | |
3815 | /* Null out PCI private reference to driver */ | |
3816 | pci_set_drvdata(pdev, NULL); | |
5b75da2f JS |
3817 | |
3818 | return; | |
3819 | } | |
3820 | ||
e59058c4 | 3821 | /** |
3772a991 JS |
3822 | * lpfc_reset_hba - Reset a hba |
3823 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 3824 | * |
3772a991 JS |
3825 | * This routine is invoked to reset a hba device. It brings the HBA |
3826 | * offline, performs a board restart, and then brings the board back | |
3827 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up | |
3828 | * on outstanding mailbox commands. | |
e59058c4 | 3829 | **/ |
3772a991 JS |
3830 | void |
3831 | lpfc_reset_hba(struct lpfc_hba *phba) | |
dea3101e | 3832 | { |
3772a991 JS |
3833 | /* If resets are disabled then set error state and return. */ |
3834 | if (!phba->cfg_enable_hba_reset) { | |
3835 | phba->link_state = LPFC_HBA_ERROR; | |
3836 | return; | |
3837 | } | |
3838 | lpfc_offline_prep(phba); | |
3839 | lpfc_offline(phba); | |
3840 | lpfc_sli_brdrestart(phba); | |
3841 | lpfc_online(phba); | |
3842 | lpfc_unblock_mgmt_io(phba); | |
3843 | } | |
dea3101e | 3844 | |
3772a991 JS |
3845 | /** |
3846 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. | |
3847 | * @phba: pointer to lpfc hba data structure. | |
3848 | * | |
3849 | * This routine is invoked to set up the driver internal resources specific to | |
3850 | * support the SLI-3 HBA device it attached to. | |
3851 | * | |
3852 | * Return codes | |
af901ca1 | 3853 | * 0 - successful |
3772a991 JS |
3854 | * other values - error |
3855 | **/ | |
3856 | static int | |
3857 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) | |
3858 | { | |
3859 | struct lpfc_sli *psli; | |
dea3101e | 3860 | |
2e0fef85 | 3861 | /* |
3772a991 | 3862 | * Initialize timers used by driver |
2e0fef85 | 3863 | */ |
dea3101e | 3864 | |
3772a991 | 3865 | /* Heartbeat timer */ |
858c9f6c JS |
3866 | init_timer(&phba->hb_tmofunc); |
3867 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
3868 | phba->hb_tmofunc.data = (unsigned long)phba; | |
3869 | ||
dea3101e | 3870 | psli = &phba->sli; |
3772a991 | 3871 | /* MBOX heartbeat timer */ |
dea3101e JB |
3872 | init_timer(&psli->mbox_tmo); |
3873 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
2e0fef85 | 3874 | psli->mbox_tmo.data = (unsigned long) phba; |
3772a991 | 3875 | /* FCP polling mode timer */ |
875fbdfe JSEC |
3876 | init_timer(&phba->fcp_poll_timer); |
3877 | phba->fcp_poll_timer.function = lpfc_poll_timeout; | |
2e0fef85 | 3878 | phba->fcp_poll_timer.data = (unsigned long) phba; |
3772a991 | 3879 | /* Fabric block timer */ |
92d7f7b0 JS |
3880 | init_timer(&phba->fabric_block_timer); |
3881 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
3882 | phba->fabric_block_timer.data = (unsigned long) phba; | |
3772a991 | 3883 | /* EA polling mode timer */ |
9399627f JS |
3884 | init_timer(&phba->eratt_poll); |
3885 | phba->eratt_poll.function = lpfc_poll_eratt; | |
3886 | phba->eratt_poll.data = (unsigned long) phba; | |
dea3101e | 3887 | |
3772a991 JS |
3888 | /* Host attention work mask setup */ |
3889 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); | |
3890 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); | |
dea3101e | 3891 | |
3772a991 JS |
3892 | /* Get all the module params for configuring this host */ |
3893 | lpfc_get_cfgparam(phba); | |
49198b37 JS |
3894 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
3895 | phba->menlo_flag |= HBA_MENLO_SUPPORT; | |
3896 | /* check for menlo minimum sg count */ | |
3897 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) | |
3898 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; | |
3899 | } | |
3900 | ||
dea3101e | 3901 | /* |
3772a991 JS |
3902 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size |
3903 | * used to create the sg_dma_buf_pool must be dynamically calculated. | |
3904 | * 2 segments are added since the IOCB needs a command and response bde. | |
dea3101e | 3905 | */ |
3772a991 JS |
3906 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
3907 | sizeof(struct fcp_rsp) + | |
3908 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); | |
3909 | ||
3910 | if (phba->cfg_enable_bg) { | |
3911 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT; | |
3912 | phba->cfg_sg_dma_buf_size += | |
3913 | phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64); | |
901a920f | 3914 | } |
dea3101e | 3915 | |
3772a991 JS |
3916 | /* Also reinitialize the host templates with new values. */ |
3917 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
3918 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
dea3101e | 3919 | |
3772a991 JS |
3920 | phba->max_vpi = LPFC_MAX_VPI; |
3921 | /* This will be set to correct value after config_port mbox */ | |
3922 | phba->max_vports = 0; | |
dea3101e | 3923 | |
3772a991 JS |
3924 | /* |
3925 | * Initialize the SLI Layer to run with lpfc HBAs. | |
3926 | */ | |
3927 | lpfc_sli_setup(phba); | |
3928 | lpfc_sli_queue_setup(phba); | |
ed957684 | 3929 | |
3772a991 JS |
3930 | /* Allocate device driver memory */ |
3931 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) | |
3932 | return -ENOMEM; | |
51ef4c26 | 3933 | |
3772a991 JS |
3934 | return 0; |
3935 | } | |
ed957684 | 3936 | |
3772a991 JS |
3937 | /** |
3938 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev | |
3939 | * @phba: pointer to lpfc hba data structure. | |
3940 | * | |
3941 | * This routine is invoked to unset the driver internal resources set up | |
3942 | * specific for supporting the SLI-3 HBA device it attached to. | |
3943 | **/ | |
3944 | static void | |
3945 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) | |
3946 | { | |
3947 | /* Free device driver memory allocated */ | |
3948 | lpfc_mem_free_all(phba); | |
3163f725 | 3949 | |
3772a991 JS |
3950 | return; |
3951 | } | |
dea3101e | 3952 | |
3772a991 | 3953 | /** |
da0436e9 | 3954 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
3772a991 JS |
3955 | * @phba: pointer to lpfc hba data structure. |
3956 | * | |
da0436e9 JS |
3957 | * This routine is invoked to set up the driver internal resources specific to |
3958 | * support the SLI-4 HBA device it attached to. | |
3772a991 JS |
3959 | * |
3960 | * Return codes | |
af901ca1 | 3961 | * 0 - successful |
da0436e9 | 3962 | * other values - error |
3772a991 JS |
3963 | **/ |
3964 | static int | |
da0436e9 | 3965 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
3772a991 | 3966 | { |
da0436e9 | 3967 | struct lpfc_sli *psli; |
28baac74 JS |
3968 | LPFC_MBOXQ_t *mboxq; |
3969 | int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size; | |
3970 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; | |
3971 | struct lpfc_mqe *mqe; | |
0c9ab6f5 | 3972 | int longs; |
da0436e9 JS |
3973 | |
3974 | /* Before proceed, wait for POST done and device ready */ | |
3975 | rc = lpfc_sli4_post_status_check(phba); | |
3976 | if (rc) | |
3977 | return -ENODEV; | |
3978 | ||
3772a991 | 3979 | /* |
da0436e9 | 3980 | * Initialize timers used by driver |
3772a991 | 3981 | */ |
3772a991 | 3982 | |
da0436e9 JS |
3983 | /* Heartbeat timer */ |
3984 | init_timer(&phba->hb_tmofunc); | |
3985 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
3986 | phba->hb_tmofunc.data = (unsigned long)phba; | |
3772a991 | 3987 | |
da0436e9 JS |
3988 | psli = &phba->sli; |
3989 | /* MBOX heartbeat timer */ | |
3990 | init_timer(&psli->mbox_tmo); | |
3991 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
3992 | psli->mbox_tmo.data = (unsigned long) phba; | |
3993 | /* Fabric block timer */ | |
3994 | init_timer(&phba->fabric_block_timer); | |
3995 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
3996 | phba->fabric_block_timer.data = (unsigned long) phba; | |
3997 | /* EA polling mode timer */ | |
3998 | init_timer(&phba->eratt_poll); | |
3999 | phba->eratt_poll.function = lpfc_poll_eratt; | |
4000 | phba->eratt_poll.data = (unsigned long) phba; | |
ecfd03c6 JS |
4001 | /* FCF rediscover timer */ |
4002 | init_timer(&phba->fcf.redisc_wait); | |
4003 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; | |
4004 | phba->fcf.redisc_wait.data = (unsigned long)phba; | |
4005 | ||
da0436e9 JS |
4006 | /* |
4007 | * We need to do a READ_CONFIG mailbox command here before | |
4008 | * calling lpfc_get_cfgparam. For VFs this will report the | |
4009 | * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings. | |
4010 | * All of the resources allocated | |
4011 | * for this Port are tied to these values. | |
4012 | */ | |
4013 | /* Get all the module params for configuring this host */ | |
4014 | lpfc_get_cfgparam(phba); | |
4015 | phba->max_vpi = LPFC_MAX_VPI; | |
4016 | /* This will be set to correct value after the read_config mbox */ | |
4017 | phba->max_vports = 0; | |
3772a991 | 4018 | |
da0436e9 JS |
4019 | /* Program the default value of vlan_id and fc_map */ |
4020 | phba->valid_vlan = 0; | |
4021 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4022 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4023 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
3772a991 | 4024 | |
da0436e9 JS |
4025 | /* |
4026 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size | |
4027 | * used to create the sg_dma_buf_pool must be dynamically calculated. | |
4028 | * 2 segments are added since the IOCB needs a command and response bde. | |
4029 | * To insure that the scsi sgl does not cross a 4k page boundary only | |
28baac74 | 4030 | * sgl sizes of must be a power of 2. |
da0436e9 | 4031 | */ |
28baac74 JS |
4032 | buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) + |
4033 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge))); | |
4034 | /* Feature Level 1 hardware is limited to 2 pages */ | |
4035 | if ((bf_get(lpfc_sli_intf_featurelevel1, &phba->sli4_hba.sli_intf) == | |
4036 | LPFC_SLI_INTF_FEATURELEVEL1_1)) | |
4037 | max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE; | |
da0436e9 | 4038 | else |
28baac74 JS |
4039 | max_buf_size = LPFC_SLI4_MAX_BUF_SIZE; |
4040 | for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE; | |
4041 | dma_buf_size < max_buf_size && buf_size > dma_buf_size; | |
4042 | dma_buf_size = dma_buf_size << 1) | |
4043 | ; | |
4044 | if (dma_buf_size == max_buf_size) | |
4045 | phba->cfg_sg_seg_cnt = (dma_buf_size - | |
4046 | sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) - | |
4047 | (2 * sizeof(struct sli4_sge))) / | |
4048 | sizeof(struct sli4_sge); | |
4049 | phba->cfg_sg_dma_buf_size = dma_buf_size; | |
3772a991 | 4050 | |
da0436e9 JS |
4051 | /* Initialize buffer queue management fields */ |
4052 | hbq_count = lpfc_sli_hbq_count(); | |
4053 | for (i = 0; i < hbq_count; ++i) | |
4054 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
4055 | INIT_LIST_HEAD(&phba->rb_pend_list); | |
4056 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; | |
4057 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; | |
3772a991 | 4058 | |
da0436e9 JS |
4059 | /* |
4060 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. | |
4061 | */ | |
4062 | /* Initialize the Abort scsi buffer list used by driver */ | |
4063 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
4064 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
4065 | /* This abort list used by worker thread */ | |
4066 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); | |
3772a991 | 4067 | |
da0436e9 JS |
4068 | /* |
4069 | * Initialize dirver internal slow-path work queues | |
4070 | */ | |
3772a991 | 4071 | |
da0436e9 JS |
4072 | /* Driver internel slow-path CQ Event pool */ |
4073 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); | |
4074 | /* Response IOCB work queue list */ | |
45ed1190 | 4075 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
da0436e9 JS |
4076 | /* Asynchronous event CQ Event work queue list */ |
4077 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); | |
4078 | /* Fast-path XRI aborted CQ Event work queue list */ | |
4079 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
4080 | /* Slow-path XRI aborted CQ Event work queue list */ | |
4081 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
4082 | /* Receive queue CQ Event work queue list */ | |
4083 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); | |
4084 | ||
4085 | /* Initialize the driver internal SLI layer lists. */ | |
4086 | lpfc_sli_setup(phba); | |
4087 | lpfc_sli_queue_setup(phba); | |
3772a991 | 4088 | |
da0436e9 JS |
4089 | /* Allocate device driver memory */ |
4090 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); | |
4091 | if (rc) | |
4092 | return -ENOMEM; | |
4093 | ||
4094 | /* Create the bootstrap mailbox command */ | |
4095 | rc = lpfc_create_bootstrap_mbox(phba); | |
4096 | if (unlikely(rc)) | |
4097 | goto out_free_mem; | |
4098 | ||
4099 | /* Set up the host's endian order with the device. */ | |
4100 | rc = lpfc_setup_endian_order(phba); | |
4101 | if (unlikely(rc)) | |
4102 | goto out_free_bsmbx; | |
4103 | ||
6669f9bb JS |
4104 | rc = lpfc_sli4_fw_cfg_check(phba); |
4105 | if (unlikely(rc)) | |
4106 | goto out_free_bsmbx; | |
4107 | ||
da0436e9 JS |
4108 | /* Set up the hba's configuration parameters. */ |
4109 | rc = lpfc_sli4_read_config(phba); | |
4110 | if (unlikely(rc)) | |
4111 | goto out_free_bsmbx; | |
4112 | ||
4113 | /* Perform a function reset */ | |
4114 | rc = lpfc_pci_function_reset(phba); | |
4115 | if (unlikely(rc)) | |
4116 | goto out_free_bsmbx; | |
4117 | ||
cb5172ea JS |
4118 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
4119 | GFP_KERNEL); | |
4120 | if (!mboxq) { | |
4121 | rc = -ENOMEM; | |
4122 | goto out_free_bsmbx; | |
4123 | } | |
4124 | ||
4125 | /* Get the Supported Pages. It is always available. */ | |
4126 | lpfc_supported_pages(mboxq); | |
4127 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
4128 | if (unlikely(rc)) { | |
4129 | rc = -EIO; | |
4130 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4131 | goto out_free_bsmbx; | |
4132 | } | |
4133 | ||
4134 | mqe = &mboxq->u.mqe; | |
4135 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), | |
4136 | LPFC_MAX_SUPPORTED_PAGES); | |
4137 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { | |
4138 | switch (pn_page[i]) { | |
4139 | case LPFC_SLI4_PARAMETERS: | |
4140 | phba->sli4_hba.pc_sli4_params.supported = 1; | |
4141 | break; | |
4142 | default: | |
4143 | break; | |
4144 | } | |
4145 | } | |
4146 | ||
4147 | /* Read the port's SLI4 Parameters capabilities if supported. */ | |
4148 | if (phba->sli4_hba.pc_sli4_params.supported) | |
4149 | rc = lpfc_pc_sli4_params_get(phba, mboxq); | |
4150 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4151 | if (rc) { | |
4152 | rc = -EIO; | |
4153 | goto out_free_bsmbx; | |
4154 | } | |
da0436e9 JS |
4155 | /* Create all the SLI4 queues */ |
4156 | rc = lpfc_sli4_queue_create(phba); | |
4157 | if (rc) | |
4158 | goto out_free_bsmbx; | |
4159 | ||
4160 | /* Create driver internal CQE event pool */ | |
4161 | rc = lpfc_sli4_cq_event_pool_create(phba); | |
4162 | if (rc) | |
4163 | goto out_destroy_queue; | |
4164 | ||
4165 | /* Initialize and populate the iocb list per host */ | |
4166 | rc = lpfc_init_sgl_list(phba); | |
4167 | if (rc) { | |
4168 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4169 | "1400 Failed to initialize sgl list.\n"); | |
4170 | goto out_destroy_cq_event_pool; | |
4171 | } | |
4172 | rc = lpfc_init_active_sgl_array(phba); | |
4173 | if (rc) { | |
4174 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4175 | "1430 Failed to initialize sgl list.\n"); | |
4176 | goto out_free_sgl_list; | |
4177 | } | |
4178 | ||
4179 | rc = lpfc_sli4_init_rpi_hdrs(phba); | |
4180 | if (rc) { | |
4181 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4182 | "1432 Failed to initialize rpi headers.\n"); | |
4183 | goto out_free_active_sgl; | |
4184 | } | |
4185 | ||
0c9ab6f5 JS |
4186 | /* Allocate eligible FCF bmask memory for FCF round robin failover */ |
4187 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; | |
4188 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), | |
4189 | GFP_KERNEL); | |
4190 | if (!phba->fcf.fcf_rr_bmask) { | |
4191 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4192 | "2759 Failed allocate memory for FCF round " | |
4193 | "robin failover bmask\n"); | |
4194 | goto out_remove_rpi_hdrs; | |
4195 | } | |
4196 | ||
da0436e9 JS |
4197 | phba->sli4_hba.fcp_eq_hdl = kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * |
4198 | phba->cfg_fcp_eq_count), GFP_KERNEL); | |
4199 | if (!phba->sli4_hba.fcp_eq_hdl) { | |
4200 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4201 | "2572 Failed allocate memory for fast-path " | |
4202 | "per-EQ handle array\n"); | |
0c9ab6f5 | 4203 | goto out_free_fcf_rr_bmask; |
da0436e9 JS |
4204 | } |
4205 | ||
4206 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * | |
4207 | phba->sli4_hba.cfg_eqn), GFP_KERNEL); | |
4208 | if (!phba->sli4_hba.msix_entries) { | |
4209 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4210 | "2573 Failed allocate memory for msi-x " | |
4211 | "interrupt vector entries\n"); | |
4212 | goto out_free_fcp_eq_hdl; | |
4213 | } | |
4214 | ||
4215 | return rc; | |
4216 | ||
4217 | out_free_fcp_eq_hdl: | |
4218 | kfree(phba->sli4_hba.fcp_eq_hdl); | |
0c9ab6f5 JS |
4219 | out_free_fcf_rr_bmask: |
4220 | kfree(phba->fcf.fcf_rr_bmask); | |
da0436e9 JS |
4221 | out_remove_rpi_hdrs: |
4222 | lpfc_sli4_remove_rpi_hdrs(phba); | |
4223 | out_free_active_sgl: | |
4224 | lpfc_free_active_sgl(phba); | |
4225 | out_free_sgl_list: | |
4226 | lpfc_free_sgl_list(phba); | |
4227 | out_destroy_cq_event_pool: | |
4228 | lpfc_sli4_cq_event_pool_destroy(phba); | |
4229 | out_destroy_queue: | |
4230 | lpfc_sli4_queue_destroy(phba); | |
4231 | out_free_bsmbx: | |
4232 | lpfc_destroy_bootstrap_mbox(phba); | |
4233 | out_free_mem: | |
4234 | lpfc_mem_free(phba); | |
4235 | return rc; | |
4236 | } | |
4237 | ||
4238 | /** | |
4239 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev | |
4240 | * @phba: pointer to lpfc hba data structure. | |
4241 | * | |
4242 | * This routine is invoked to unset the driver internal resources set up | |
4243 | * specific for supporting the SLI-4 HBA device it attached to. | |
4244 | **/ | |
4245 | static void | |
4246 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) | |
4247 | { | |
4248 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; | |
4249 | ||
4250 | /* unregister default FCFI from the HBA */ | |
4251 | lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi); | |
4252 | ||
4253 | /* Free the default FCR table */ | |
4254 | lpfc_sli_remove_dflt_fcf(phba); | |
4255 | ||
4256 | /* Free memory allocated for msi-x interrupt vector entries */ | |
4257 | kfree(phba->sli4_hba.msix_entries); | |
4258 | ||
4259 | /* Free memory allocated for fast-path work queue handles */ | |
4260 | kfree(phba->sli4_hba.fcp_eq_hdl); | |
4261 | ||
4262 | /* Free the allocated rpi headers. */ | |
4263 | lpfc_sli4_remove_rpi_hdrs(phba); | |
d11e31dd | 4264 | lpfc_sli4_remove_rpis(phba); |
da0436e9 | 4265 | |
0c9ab6f5 JS |
4266 | /* Free eligible FCF index bmask */ |
4267 | kfree(phba->fcf.fcf_rr_bmask); | |
4268 | ||
da0436e9 JS |
4269 | /* Free the ELS sgl list */ |
4270 | lpfc_free_active_sgl(phba); | |
4271 | lpfc_free_sgl_list(phba); | |
4272 | ||
4273 | /* Free the SCSI sgl management array */ | |
4274 | kfree(phba->sli4_hba.lpfc_scsi_psb_array); | |
4275 | ||
4276 | /* Free the SLI4 queues */ | |
4277 | lpfc_sli4_queue_destroy(phba); | |
4278 | ||
4279 | /* Free the completion queue EQ event pool */ | |
4280 | lpfc_sli4_cq_event_release_all(phba); | |
4281 | lpfc_sli4_cq_event_pool_destroy(phba); | |
4282 | ||
4283 | /* Reset SLI4 HBA FCoE function */ | |
4284 | lpfc_pci_function_reset(phba); | |
4285 | ||
4286 | /* Free the bsmbx region. */ | |
4287 | lpfc_destroy_bootstrap_mbox(phba); | |
4288 | ||
4289 | /* Free the SLI Layer memory with SLI4 HBAs */ | |
4290 | lpfc_mem_free_all(phba); | |
4291 | ||
4292 | /* Free the current connect table */ | |
4293 | list_for_each_entry_safe(conn_entry, next_conn_entry, | |
4d9ab994 JS |
4294 | &phba->fcf_conn_rec_list, list) { |
4295 | list_del_init(&conn_entry->list); | |
da0436e9 | 4296 | kfree(conn_entry); |
4d9ab994 | 4297 | } |
da0436e9 JS |
4298 | |
4299 | return; | |
4300 | } | |
4301 | ||
4302 | /** | |
4303 | * lpfc_init_api_table_setup - Set up init api fucntion jump table | |
4304 | * @phba: The hba struct for which this call is being executed. | |
4305 | * @dev_grp: The HBA PCI-Device group number. | |
4306 | * | |
4307 | * This routine sets up the device INIT interface API function jump table | |
4308 | * in @phba struct. | |
4309 | * | |
4310 | * Returns: 0 - success, -ENODEV - failure. | |
4311 | **/ | |
4312 | int | |
4313 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
4314 | { | |
84d1b006 JS |
4315 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
4316 | phba->lpfc_hba_down_link = lpfc_hba_down_link; | |
da0436e9 JS |
4317 | switch (dev_grp) { |
4318 | case LPFC_PCI_DEV_LP: | |
4319 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; | |
4320 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; | |
4321 | phba->lpfc_stop_port = lpfc_stop_port_s3; | |
4322 | break; | |
4323 | case LPFC_PCI_DEV_OC: | |
4324 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; | |
4325 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; | |
4326 | phba->lpfc_stop_port = lpfc_stop_port_s4; | |
4327 | break; | |
4328 | default: | |
4329 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4330 | "1431 Invalid HBA PCI-device group: 0x%x\n", | |
4331 | dev_grp); | |
4332 | return -ENODEV; | |
4333 | break; | |
4334 | } | |
4335 | return 0; | |
4336 | } | |
4337 | ||
4338 | /** | |
4339 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. | |
4340 | * @phba: pointer to lpfc hba data structure. | |
4341 | * | |
4342 | * This routine is invoked to set up the driver internal resources before the | |
4343 | * device specific resource setup to support the HBA device it attached to. | |
4344 | * | |
4345 | * Return codes | |
af901ca1 | 4346 | * 0 - successful |
da0436e9 JS |
4347 | * other values - error |
4348 | **/ | |
4349 | static int | |
4350 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) | |
4351 | { | |
4352 | /* | |
4353 | * Driver resources common to all SLI revisions | |
4354 | */ | |
4355 | atomic_set(&phba->fast_event_count, 0); | |
4356 | spin_lock_init(&phba->hbalock); | |
4357 | ||
4358 | /* Initialize ndlp management spinlock */ | |
4359 | spin_lock_init(&phba->ndlp_lock); | |
4360 | ||
4361 | INIT_LIST_HEAD(&phba->port_list); | |
4362 | INIT_LIST_HEAD(&phba->work_list); | |
4363 | init_waitqueue_head(&phba->wait_4_mlo_m_q); | |
4364 | ||
4365 | /* Initialize the wait queue head for the kernel thread */ | |
4366 | init_waitqueue_head(&phba->work_waitq); | |
4367 | ||
4368 | /* Initialize the scsi buffer list used by driver for scsi IO */ | |
4369 | spin_lock_init(&phba->scsi_buf_list_lock); | |
4370 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); | |
4371 | ||
4372 | /* Initialize the fabric iocb list */ | |
4373 | INIT_LIST_HEAD(&phba->fabric_iocb_list); | |
4374 | ||
4375 | /* Initialize list to save ELS buffers */ | |
4376 | INIT_LIST_HEAD(&phba->elsbuf); | |
4377 | ||
4378 | /* Initialize FCF connection rec list */ | |
4379 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); | |
4380 | ||
4381 | return 0; | |
4382 | } | |
4383 | ||
4384 | /** | |
4385 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. | |
4386 | * @phba: pointer to lpfc hba data structure. | |
4387 | * | |
4388 | * This routine is invoked to set up the driver internal resources after the | |
4389 | * device specific resource setup to support the HBA device it attached to. | |
4390 | * | |
4391 | * Return codes | |
af901ca1 | 4392 | * 0 - successful |
da0436e9 JS |
4393 | * other values - error |
4394 | **/ | |
4395 | static int | |
4396 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) | |
4397 | { | |
4398 | int error; | |
4399 | ||
4400 | /* Startup the kernel thread for this host adapter. */ | |
4401 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
4402 | "lpfc_worker_%d", phba->brd_no); | |
4403 | if (IS_ERR(phba->worker_thread)) { | |
4404 | error = PTR_ERR(phba->worker_thread); | |
4405 | return error; | |
3772a991 JS |
4406 | } |
4407 | ||
4408 | return 0; | |
4409 | } | |
4410 | ||
4411 | /** | |
4412 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. | |
4413 | * @phba: pointer to lpfc hba data structure. | |
4414 | * | |
4415 | * This routine is invoked to unset the driver internal resources set up after | |
4416 | * the device specific resource setup for supporting the HBA device it | |
4417 | * attached to. | |
4418 | **/ | |
4419 | static void | |
4420 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) | |
4421 | { | |
4422 | /* Stop kernel worker thread */ | |
4423 | kthread_stop(phba->worker_thread); | |
4424 | } | |
4425 | ||
4426 | /** | |
4427 | * lpfc_free_iocb_list - Free iocb list. | |
4428 | * @phba: pointer to lpfc hba data structure. | |
4429 | * | |
4430 | * This routine is invoked to free the driver's IOCB list and memory. | |
4431 | **/ | |
4432 | static void | |
4433 | lpfc_free_iocb_list(struct lpfc_hba *phba) | |
4434 | { | |
4435 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; | |
4436 | ||
4437 | spin_lock_irq(&phba->hbalock); | |
4438 | list_for_each_entry_safe(iocbq_entry, iocbq_next, | |
4439 | &phba->lpfc_iocb_list, list) { | |
4440 | list_del(&iocbq_entry->list); | |
4441 | kfree(iocbq_entry); | |
4442 | phba->total_iocbq_bufs--; | |
98c9ea5c | 4443 | } |
3772a991 JS |
4444 | spin_unlock_irq(&phba->hbalock); |
4445 | ||
4446 | return; | |
4447 | } | |
4448 | ||
4449 | /** | |
4450 | * lpfc_init_iocb_list - Allocate and initialize iocb list. | |
4451 | * @phba: pointer to lpfc hba data structure. | |
4452 | * | |
4453 | * This routine is invoked to allocate and initizlize the driver's IOCB | |
4454 | * list and set up the IOCB tag array accordingly. | |
4455 | * | |
4456 | * Return codes | |
af901ca1 | 4457 | * 0 - successful |
3772a991 JS |
4458 | * other values - error |
4459 | **/ | |
4460 | static int | |
4461 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) | |
4462 | { | |
4463 | struct lpfc_iocbq *iocbq_entry = NULL; | |
4464 | uint16_t iotag; | |
4465 | int i; | |
dea3101e JB |
4466 | |
4467 | /* Initialize and populate the iocb list per host. */ | |
4468 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); | |
3772a991 | 4469 | for (i = 0; i < iocb_count; i++) { |
dd00cc48 | 4470 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
dea3101e JB |
4471 | if (iocbq_entry == NULL) { |
4472 | printk(KERN_ERR "%s: only allocated %d iocbs of " | |
4473 | "expected %d count. Unloading driver.\n", | |
cadbd4a5 | 4474 | __func__, i, LPFC_IOCB_LIST_CNT); |
dea3101e JB |
4475 | goto out_free_iocbq; |
4476 | } | |
4477 | ||
604a3e30 JB |
4478 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
4479 | if (iotag == 0) { | |
3772a991 | 4480 | kfree(iocbq_entry); |
604a3e30 | 4481 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
3772a991 | 4482 | "Unloading driver.\n", __func__); |
604a3e30 JB |
4483 | goto out_free_iocbq; |
4484 | } | |
3772a991 | 4485 | iocbq_entry->sli4_xritag = NO_XRI; |
2e0fef85 JS |
4486 | |
4487 | spin_lock_irq(&phba->hbalock); | |
dea3101e JB |
4488 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
4489 | phba->total_iocbq_bufs++; | |
2e0fef85 | 4490 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4491 | } |
4492 | ||
3772a991 | 4493 | return 0; |
dea3101e | 4494 | |
3772a991 JS |
4495 | out_free_iocbq: |
4496 | lpfc_free_iocb_list(phba); | |
dea3101e | 4497 | |
3772a991 JS |
4498 | return -ENOMEM; |
4499 | } | |
5e9d9b82 | 4500 | |
3772a991 | 4501 | /** |
da0436e9 JS |
4502 | * lpfc_free_sgl_list - Free sgl list. |
4503 | * @phba: pointer to lpfc hba data structure. | |
3772a991 | 4504 | * |
da0436e9 | 4505 | * This routine is invoked to free the driver's sgl list and memory. |
3772a991 | 4506 | **/ |
da0436e9 JS |
4507 | static void |
4508 | lpfc_free_sgl_list(struct lpfc_hba *phba) | |
3772a991 | 4509 | { |
da0436e9 JS |
4510 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
4511 | LIST_HEAD(sglq_list); | |
4512 | int rc = 0; | |
dea3101e | 4513 | |
da0436e9 JS |
4514 | spin_lock_irq(&phba->hbalock); |
4515 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); | |
4516 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 4517 | |
da0436e9 JS |
4518 | list_for_each_entry_safe(sglq_entry, sglq_next, |
4519 | &sglq_list, list) { | |
4520 | list_del(&sglq_entry->list); | |
4521 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); | |
4522 | kfree(sglq_entry); | |
4523 | phba->sli4_hba.total_sglq_bufs--; | |
4524 | } | |
4525 | rc = lpfc_sli4_remove_all_sgl_pages(phba); | |
4526 | if (rc) { | |
4527 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6a9c52cf | 4528 | "2005 Unable to deregister pages from HBA: %x\n", rc); |
3772a991 | 4529 | } |
da0436e9 JS |
4530 | kfree(phba->sli4_hba.lpfc_els_sgl_array); |
4531 | } | |
92d7f7b0 | 4532 | |
da0436e9 JS |
4533 | /** |
4534 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. | |
4535 | * @phba: pointer to lpfc hba data structure. | |
4536 | * | |
4537 | * This routine is invoked to allocate the driver's active sgl memory. | |
4538 | * This array will hold the sglq_entry's for active IOs. | |
4539 | **/ | |
4540 | static int | |
4541 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) | |
4542 | { | |
4543 | int size; | |
4544 | size = sizeof(struct lpfc_sglq *); | |
4545 | size *= phba->sli4_hba.max_cfg_param.max_xri; | |
4546 | ||
4547 | phba->sli4_hba.lpfc_sglq_active_list = | |
4548 | kzalloc(size, GFP_KERNEL); | |
4549 | if (!phba->sli4_hba.lpfc_sglq_active_list) | |
4550 | return -ENOMEM; | |
4551 | return 0; | |
3772a991 JS |
4552 | } |
4553 | ||
4554 | /** | |
da0436e9 | 4555 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
3772a991 JS |
4556 | * @phba: pointer to lpfc hba data structure. |
4557 | * | |
da0436e9 JS |
4558 | * This routine is invoked to walk through the array of active sglq entries |
4559 | * and free all of the resources. | |
4560 | * This is just a place holder for now. | |
3772a991 JS |
4561 | **/ |
4562 | static void | |
da0436e9 | 4563 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
3772a991 | 4564 | { |
da0436e9 | 4565 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
3772a991 JS |
4566 | } |
4567 | ||
4568 | /** | |
da0436e9 | 4569 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
3772a991 JS |
4570 | * @phba: pointer to lpfc hba data structure. |
4571 | * | |
da0436e9 JS |
4572 | * This routine is invoked to allocate and initizlize the driver's sgl |
4573 | * list and set up the sgl xritag tag array accordingly. | |
3772a991 JS |
4574 | * |
4575 | * Return codes | |
af901ca1 | 4576 | * 0 - successful |
da0436e9 | 4577 | * other values - error |
3772a991 JS |
4578 | **/ |
4579 | static int | |
da0436e9 | 4580 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
3772a991 | 4581 | { |
da0436e9 JS |
4582 | struct lpfc_sglq *sglq_entry = NULL; |
4583 | int i; | |
4584 | int els_xri_cnt; | |
4585 | ||
4586 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
4587 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4588 | "2400 lpfc_init_sgl_list els %d.\n", | |
4589 | els_xri_cnt); | |
4590 | /* Initialize and populate the sglq list per host/VF. */ | |
4591 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); | |
4592 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
4593 | ||
4594 | /* Sanity check on XRI management */ | |
4595 | if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) { | |
4596 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4597 | "2562 No room left for SCSI XRI allocation: " | |
4598 | "max_xri=%d, els_xri=%d\n", | |
4599 | phba->sli4_hba.max_cfg_param.max_xri, | |
4600 | els_xri_cnt); | |
4601 | return -ENOMEM; | |
4602 | } | |
3772a991 | 4603 | |
da0436e9 JS |
4604 | /* Allocate memory for the ELS XRI management array */ |
4605 | phba->sli4_hba.lpfc_els_sgl_array = | |
4606 | kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt), | |
4607 | GFP_KERNEL); | |
0ff10d46 | 4608 | |
da0436e9 JS |
4609 | if (!phba->sli4_hba.lpfc_els_sgl_array) { |
4610 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4611 | "2401 Failed to allocate memory for ELS " | |
4612 | "XRI management array of size %d.\n", | |
4613 | els_xri_cnt); | |
4614 | return -ENOMEM; | |
4615 | } | |
2e0fef85 | 4616 | |
da0436e9 JS |
4617 | /* Keep the SCSI XRI into the XRI management array */ |
4618 | phba->sli4_hba.scsi_xri_max = | |
4619 | phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; | |
4620 | phba->sli4_hba.scsi_xri_cnt = 0; | |
4621 | ||
4622 | phba->sli4_hba.lpfc_scsi_psb_array = | |
4623 | kzalloc((sizeof(struct lpfc_scsi_buf *) * | |
4624 | phba->sli4_hba.scsi_xri_max), GFP_KERNEL); | |
4625 | ||
4626 | if (!phba->sli4_hba.lpfc_scsi_psb_array) { | |
4627 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4628 | "2563 Failed to allocate memory for SCSI " | |
4629 | "XRI management array of size %d.\n", | |
4630 | phba->sli4_hba.scsi_xri_max); | |
4631 | kfree(phba->sli4_hba.lpfc_els_sgl_array); | |
4632 | return -ENOMEM; | |
4633 | } | |
4634 | ||
4635 | for (i = 0; i < els_xri_cnt; i++) { | |
4636 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL); | |
4637 | if (sglq_entry == NULL) { | |
4638 | printk(KERN_ERR "%s: only allocated %d sgls of " | |
4639 | "expected %d count. Unloading driver.\n", | |
4640 | __func__, i, els_xri_cnt); | |
4641 | goto out_free_mem; | |
4642 | } | |
4643 | ||
4644 | sglq_entry->sli4_xritag = lpfc_sli4_next_xritag(phba); | |
4645 | if (sglq_entry->sli4_xritag == NO_XRI) { | |
4646 | kfree(sglq_entry); | |
4647 | printk(KERN_ERR "%s: failed to allocate XRI.\n" | |
4648 | "Unloading driver.\n", __func__); | |
4649 | goto out_free_mem; | |
4650 | } | |
4651 | sglq_entry->buff_type = GEN_BUFF_TYPE; | |
4652 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys); | |
4653 | if (sglq_entry->virt == NULL) { | |
4654 | kfree(sglq_entry); | |
4655 | printk(KERN_ERR "%s: failed to allocate mbuf.\n" | |
4656 | "Unloading driver.\n", __func__); | |
4657 | goto out_free_mem; | |
4658 | } | |
4659 | sglq_entry->sgl = sglq_entry->virt; | |
4660 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); | |
4661 | ||
4662 | /* The list order is used by later block SGL registraton */ | |
4663 | spin_lock_irq(&phba->hbalock); | |
0f65ff68 | 4664 | sglq_entry->state = SGL_FREED; |
da0436e9 JS |
4665 | list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list); |
4666 | phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry; | |
4667 | phba->sli4_hba.total_sglq_bufs++; | |
4668 | spin_unlock_irq(&phba->hbalock); | |
4669 | } | |
4670 | return 0; | |
4671 | ||
4672 | out_free_mem: | |
4673 | kfree(phba->sli4_hba.lpfc_scsi_psb_array); | |
4674 | lpfc_free_sgl_list(phba); | |
4675 | return -ENOMEM; | |
4676 | } | |
4677 | ||
4678 | /** | |
4679 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port | |
4680 | * @phba: pointer to lpfc hba data structure. | |
4681 | * | |
4682 | * This routine is invoked to post rpi header templates to the | |
4683 | * HBA consistent with the SLI-4 interface spec. This routine | |
4684 | * posts a PAGE_SIZE memory region to the port to hold up to | |
4685 | * PAGE_SIZE modulo 64 rpi context headers. | |
4686 | * No locks are held here because this is an initialization routine | |
4687 | * called only from probe or lpfc_online when interrupts are not | |
4688 | * enabled and the driver is reinitializing the device. | |
4689 | * | |
4690 | * Return codes | |
af901ca1 | 4691 | * 0 - successful |
da0436e9 JS |
4692 | * ENOMEM - No availble memory |
4693 | * EIO - The mailbox failed to complete successfully. | |
4694 | **/ | |
4695 | int | |
4696 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) | |
4697 | { | |
4698 | int rc = 0; | |
4699 | int longs; | |
4700 | uint16_t rpi_count; | |
4701 | struct lpfc_rpi_hdr *rpi_hdr; | |
4702 | ||
4703 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); | |
4704 | ||
4705 | /* | |
4706 | * Provision an rpi bitmask range for discovery. The total count | |
4707 | * is the difference between max and base + 1. | |
4708 | */ | |
4709 | rpi_count = phba->sli4_hba.max_cfg_param.rpi_base + | |
4710 | phba->sli4_hba.max_cfg_param.max_rpi - 1; | |
4711 | ||
4712 | longs = ((rpi_count) + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
4713 | phba->sli4_hba.rpi_bmask = kzalloc(longs * sizeof(unsigned long), | |
4714 | GFP_KERNEL); | |
4715 | if (!phba->sli4_hba.rpi_bmask) | |
4716 | return -ENOMEM; | |
4717 | ||
4718 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
4719 | if (!rpi_hdr) { | |
4720 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4721 | "0391 Error during rpi post operation\n"); | |
4722 | lpfc_sli4_remove_rpis(phba); | |
4723 | rc = -ENODEV; | |
4724 | } | |
4725 | ||
4726 | return rc; | |
4727 | } | |
4728 | ||
4729 | /** | |
4730 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region | |
4731 | * @phba: pointer to lpfc hba data structure. | |
4732 | * | |
4733 | * This routine is invoked to allocate a single 4KB memory region to | |
4734 | * support rpis and stores them in the phba. This single region | |
4735 | * provides support for up to 64 rpis. The region is used globally | |
4736 | * by the device. | |
4737 | * | |
4738 | * Returns: | |
4739 | * A valid rpi hdr on success. | |
4740 | * A NULL pointer on any failure. | |
4741 | **/ | |
4742 | struct lpfc_rpi_hdr * | |
4743 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) | |
4744 | { | |
4745 | uint16_t rpi_limit, curr_rpi_range; | |
4746 | struct lpfc_dmabuf *dmabuf; | |
4747 | struct lpfc_rpi_hdr *rpi_hdr; | |
4748 | ||
4749 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + | |
4750 | phba->sli4_hba.max_cfg_param.max_rpi - 1; | |
4751 | ||
4752 | spin_lock_irq(&phba->hbalock); | |
4753 | curr_rpi_range = phba->sli4_hba.next_rpi; | |
4754 | spin_unlock_irq(&phba->hbalock); | |
4755 | ||
4756 | /* | |
4757 | * The port has a limited number of rpis. The increment here | |
4758 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value | |
4759 | * and to allow the full max_rpi range per port. | |
4760 | */ | |
4761 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) | |
4762 | return NULL; | |
4763 | ||
4764 | /* | |
4765 | * First allocate the protocol header region for the port. The | |
4766 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. | |
4767 | */ | |
4768 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
4769 | if (!dmabuf) | |
4770 | return NULL; | |
4771 | ||
4772 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
4773 | LPFC_HDR_TEMPLATE_SIZE, | |
4774 | &dmabuf->phys, | |
4775 | GFP_KERNEL); | |
4776 | if (!dmabuf->virt) { | |
4777 | rpi_hdr = NULL; | |
4778 | goto err_free_dmabuf; | |
4779 | } | |
4780 | ||
4781 | memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE); | |
4782 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { | |
4783 | rpi_hdr = NULL; | |
4784 | goto err_free_coherent; | |
4785 | } | |
4786 | ||
4787 | /* Save the rpi header data for cleanup later. */ | |
4788 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); | |
4789 | if (!rpi_hdr) | |
4790 | goto err_free_coherent; | |
4791 | ||
4792 | rpi_hdr->dmabuf = dmabuf; | |
4793 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; | |
4794 | rpi_hdr->page_count = 1; | |
4795 | spin_lock_irq(&phba->hbalock); | |
4796 | rpi_hdr->start_rpi = phba->sli4_hba.next_rpi; | |
4797 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); | |
4798 | ||
4799 | /* | |
4800 | * The next_rpi stores the next module-64 rpi value to post | |
4801 | * in any subsequent rpi memory region postings. | |
4802 | */ | |
4803 | phba->sli4_hba.next_rpi += LPFC_RPI_HDR_COUNT; | |
4804 | spin_unlock_irq(&phba->hbalock); | |
4805 | return rpi_hdr; | |
4806 | ||
4807 | err_free_coherent: | |
4808 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, | |
4809 | dmabuf->virt, dmabuf->phys); | |
4810 | err_free_dmabuf: | |
4811 | kfree(dmabuf); | |
4812 | return NULL; | |
4813 | } | |
4814 | ||
4815 | /** | |
4816 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions | |
4817 | * @phba: pointer to lpfc hba data structure. | |
4818 | * | |
4819 | * This routine is invoked to remove all memory resources allocated | |
4820 | * to support rpis. This routine presumes the caller has released all | |
4821 | * rpis consumed by fabric or port logins and is prepared to have | |
4822 | * the header pages removed. | |
4823 | **/ | |
4824 | void | |
4825 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) | |
4826 | { | |
4827 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; | |
4828 | ||
4829 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, | |
4830 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { | |
4831 | list_del(&rpi_hdr->list); | |
4832 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, | |
4833 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); | |
4834 | kfree(rpi_hdr->dmabuf); | |
4835 | kfree(rpi_hdr); | |
4836 | } | |
4837 | ||
4838 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base; | |
4839 | memset(phba->sli4_hba.rpi_bmask, 0, sizeof(*phba->sli4_hba.rpi_bmask)); | |
4840 | } | |
4841 | ||
4842 | /** | |
4843 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. | |
4844 | * @pdev: pointer to pci device data structure. | |
4845 | * | |
4846 | * This routine is invoked to allocate the driver hba data structure for an | |
4847 | * HBA device. If the allocation is successful, the phba reference to the | |
4848 | * PCI device data structure is set. | |
4849 | * | |
4850 | * Return codes | |
af901ca1 | 4851 | * pointer to @phba - successful |
da0436e9 JS |
4852 | * NULL - error |
4853 | **/ | |
4854 | static struct lpfc_hba * | |
4855 | lpfc_hba_alloc(struct pci_dev *pdev) | |
4856 | { | |
4857 | struct lpfc_hba *phba; | |
4858 | ||
4859 | /* Allocate memory for HBA structure */ | |
4860 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); | |
4861 | if (!phba) { | |
e34ccdfe | 4862 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
da0436e9 JS |
4863 | return NULL; |
4864 | } | |
4865 | ||
4866 | /* Set reference to PCI device in HBA structure */ | |
4867 | phba->pcidev = pdev; | |
4868 | ||
4869 | /* Assign an unused board number */ | |
4870 | phba->brd_no = lpfc_get_instance(); | |
4871 | if (phba->brd_no < 0) { | |
4872 | kfree(phba); | |
4873 | return NULL; | |
4874 | } | |
4875 | ||
4fede78f | 4876 | spin_lock_init(&phba->ct_ev_lock); |
f1c3b0fc JS |
4877 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
4878 | ||
da0436e9 JS |
4879 | return phba; |
4880 | } | |
4881 | ||
4882 | /** | |
4883 | * lpfc_hba_free - Free driver hba data structure with a device. | |
4884 | * @phba: pointer to lpfc hba data structure. | |
4885 | * | |
4886 | * This routine is invoked to free the driver hba data structure with an | |
4887 | * HBA device. | |
4888 | **/ | |
4889 | static void | |
4890 | lpfc_hba_free(struct lpfc_hba *phba) | |
4891 | { | |
4892 | /* Release the driver assigned board number */ | |
4893 | idr_remove(&lpfc_hba_index, phba->brd_no); | |
4894 | ||
4895 | kfree(phba); | |
4896 | return; | |
4897 | } | |
4898 | ||
4899 | /** | |
4900 | * lpfc_create_shost - Create hba physical port with associated scsi host. | |
4901 | * @phba: pointer to lpfc hba data structure. | |
4902 | * | |
4903 | * This routine is invoked to create HBA physical port and associate a SCSI | |
4904 | * host with it. | |
4905 | * | |
4906 | * Return codes | |
af901ca1 | 4907 | * 0 - successful |
da0436e9 JS |
4908 | * other values - error |
4909 | **/ | |
4910 | static int | |
4911 | lpfc_create_shost(struct lpfc_hba *phba) | |
4912 | { | |
4913 | struct lpfc_vport *vport; | |
4914 | struct Scsi_Host *shost; | |
4915 | ||
4916 | /* Initialize HBA FC structure */ | |
4917 | phba->fc_edtov = FF_DEF_EDTOV; | |
4918 | phba->fc_ratov = FF_DEF_RATOV; | |
4919 | phba->fc_altov = FF_DEF_ALTOV; | |
4920 | phba->fc_arbtov = FF_DEF_ARBTOV; | |
4921 | ||
4922 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); | |
4923 | if (!vport) | |
4924 | return -ENODEV; | |
4925 | ||
4926 | shost = lpfc_shost_from_vport(vport); | |
4927 | phba->pport = vport; | |
4928 | lpfc_debugfs_initialize(vport); | |
4929 | /* Put reference to SCSI host to driver's device private data */ | |
4930 | pci_set_drvdata(phba->pcidev, shost); | |
2e0fef85 | 4931 | |
3772a991 JS |
4932 | return 0; |
4933 | } | |
db2378e0 | 4934 | |
3772a991 JS |
4935 | /** |
4936 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. | |
4937 | * @phba: pointer to lpfc hba data structure. | |
4938 | * | |
4939 | * This routine is invoked to destroy HBA physical port and the associated | |
4940 | * SCSI host. | |
4941 | **/ | |
4942 | static void | |
4943 | lpfc_destroy_shost(struct lpfc_hba *phba) | |
4944 | { | |
4945 | struct lpfc_vport *vport = phba->pport; | |
4946 | ||
4947 | /* Destroy physical port that associated with the SCSI host */ | |
4948 | destroy_port(vport); | |
4949 | ||
4950 | return; | |
4951 | } | |
4952 | ||
4953 | /** | |
4954 | * lpfc_setup_bg - Setup Block guard structures and debug areas. | |
4955 | * @phba: pointer to lpfc hba data structure. | |
4956 | * @shost: the shost to be used to detect Block guard settings. | |
4957 | * | |
4958 | * This routine sets up the local Block guard protocol settings for @shost. | |
4959 | * This routine also allocates memory for debugging bg buffers. | |
4960 | **/ | |
4961 | static void | |
4962 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) | |
4963 | { | |
4964 | int pagecnt = 10; | |
4965 | if (lpfc_prot_mask && lpfc_prot_guard) { | |
4966 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4967 | "1478 Registering BlockGuard with the " | |
4968 | "SCSI layer\n"); | |
4969 | scsi_host_set_prot(shost, lpfc_prot_mask); | |
4970 | scsi_host_set_guard(shost, lpfc_prot_guard); | |
4971 | } | |
4972 | if (!_dump_buf_data) { | |
4973 | while (pagecnt) { | |
4974 | spin_lock_init(&_dump_buf_lock); | |
4975 | _dump_buf_data = | |
4976 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
4977 | if (_dump_buf_data) { | |
6a9c52cf JS |
4978 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
4979 | "9043 BLKGRD: allocated %d pages for " | |
3772a991 JS |
4980 | "_dump_buf_data at 0x%p\n", |
4981 | (1 << pagecnt), _dump_buf_data); | |
4982 | _dump_buf_data_order = pagecnt; | |
4983 | memset(_dump_buf_data, 0, | |
4984 | ((1 << PAGE_SHIFT) << pagecnt)); | |
4985 | break; | |
4986 | } else | |
4987 | --pagecnt; | |
4988 | } | |
4989 | if (!_dump_buf_data_order) | |
6a9c52cf JS |
4990 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
4991 | "9044 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
4992 | "memory for hexdump\n"); |
4993 | } else | |
6a9c52cf JS |
4994 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
4995 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" | |
3772a991 JS |
4996 | "\n", _dump_buf_data); |
4997 | if (!_dump_buf_dif) { | |
4998 | while (pagecnt) { | |
4999 | _dump_buf_dif = | |
5000 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
5001 | if (_dump_buf_dif) { | |
6a9c52cf JS |
5002 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5003 | "9046 BLKGRD: allocated %d pages for " | |
3772a991 JS |
5004 | "_dump_buf_dif at 0x%p\n", |
5005 | (1 << pagecnt), _dump_buf_dif); | |
5006 | _dump_buf_dif_order = pagecnt; | |
5007 | memset(_dump_buf_dif, 0, | |
5008 | ((1 << PAGE_SHIFT) << pagecnt)); | |
5009 | break; | |
5010 | } else | |
5011 | --pagecnt; | |
5012 | } | |
5013 | if (!_dump_buf_dif_order) | |
6a9c52cf JS |
5014 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5015 | "9047 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
5016 | "memory for hexdump\n"); |
5017 | } else | |
6a9c52cf JS |
5018 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5019 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", | |
3772a991 JS |
5020 | _dump_buf_dif); |
5021 | } | |
5022 | ||
5023 | /** | |
5024 | * lpfc_post_init_setup - Perform necessary device post initialization setup. | |
5025 | * @phba: pointer to lpfc hba data structure. | |
5026 | * | |
5027 | * This routine is invoked to perform all the necessary post initialization | |
5028 | * setup for the device. | |
5029 | **/ | |
5030 | static void | |
5031 | lpfc_post_init_setup(struct lpfc_hba *phba) | |
5032 | { | |
5033 | struct Scsi_Host *shost; | |
5034 | struct lpfc_adapter_event_header adapter_event; | |
5035 | ||
5036 | /* Get the default values for Model Name and Description */ | |
5037 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
5038 | ||
5039 | /* | |
5040 | * hba setup may have changed the hba_queue_depth so we need to | |
5041 | * adjust the value of can_queue. | |
5042 | */ | |
5043 | shost = pci_get_drvdata(phba->pcidev); | |
5044 | shost->can_queue = phba->cfg_hba_queue_depth - 10; | |
5045 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) | |
5046 | lpfc_setup_bg(phba, shost); | |
5047 | ||
5048 | lpfc_host_attrib_init(shost); | |
5049 | ||
5050 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | |
5051 | spin_lock_irq(shost->host_lock); | |
5052 | lpfc_poll_start_timer(phba); | |
5053 | spin_unlock_irq(shost->host_lock); | |
5054 | } | |
5055 | ||
5056 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5057 | "0428 Perform SCSI scan\n"); | |
5058 | /* Send board arrival event to upper layer */ | |
5059 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; | |
5060 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; | |
5061 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
5062 | sizeof(adapter_event), | |
5063 | (char *) &adapter_event, | |
5064 | LPFC_NL_VENDOR_ID); | |
5065 | return; | |
5066 | } | |
5067 | ||
5068 | /** | |
5069 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. | |
5070 | * @phba: pointer to lpfc hba data structure. | |
5071 | * | |
5072 | * This routine is invoked to set up the PCI device memory space for device | |
5073 | * with SLI-3 interface spec. | |
5074 | * | |
5075 | * Return codes | |
af901ca1 | 5076 | * 0 - successful |
3772a991 JS |
5077 | * other values - error |
5078 | **/ | |
5079 | static int | |
5080 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) | |
5081 | { | |
5082 | struct pci_dev *pdev; | |
5083 | unsigned long bar0map_len, bar2map_len; | |
5084 | int i, hbq_count; | |
5085 | void *ptr; | |
5086 | int error = -ENODEV; | |
5087 | ||
5088 | /* Obtain PCI device reference */ | |
5089 | if (!phba->pcidev) | |
5090 | return error; | |
5091 | else | |
5092 | pdev = phba->pcidev; | |
5093 | ||
5094 | /* Set the device DMA mask size */ | |
8e68597d MR |
5095 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
5096 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
5097 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
5098 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
3772a991 | 5099 | return error; |
8e68597d MR |
5100 | } |
5101 | } | |
3772a991 JS |
5102 | |
5103 | /* Get the bus address of Bar0 and Bar2 and the number of bytes | |
5104 | * required by each mapping. | |
5105 | */ | |
5106 | phba->pci_bar0_map = pci_resource_start(pdev, 0); | |
5107 | bar0map_len = pci_resource_len(pdev, 0); | |
5108 | ||
5109 | phba->pci_bar2_map = pci_resource_start(pdev, 2); | |
5110 | bar2map_len = pci_resource_len(pdev, 2); | |
5111 | ||
5112 | /* Map HBA SLIM to a kernel virtual address. */ | |
5113 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); | |
5114 | if (!phba->slim_memmap_p) { | |
5115 | dev_printk(KERN_ERR, &pdev->dev, | |
5116 | "ioremap failed for SLIM memory.\n"); | |
5117 | goto out; | |
5118 | } | |
5119 | ||
5120 | /* Map HBA Control Registers to a kernel virtual address. */ | |
5121 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); | |
5122 | if (!phba->ctrl_regs_memmap_p) { | |
5123 | dev_printk(KERN_ERR, &pdev->dev, | |
5124 | "ioremap failed for HBA control registers.\n"); | |
5125 | goto out_iounmap_slim; | |
5126 | } | |
5127 | ||
5128 | /* Allocate memory for SLI-2 structures */ | |
5129 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, | |
5130 | SLI2_SLIM_SIZE, | |
5131 | &phba->slim2p.phys, | |
5132 | GFP_KERNEL); | |
5133 | if (!phba->slim2p.virt) | |
5134 | goto out_iounmap; | |
5135 | ||
5136 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); | |
5137 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); | |
7a470277 JS |
5138 | phba->mbox_ext = (phba->slim2p.virt + |
5139 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); | |
3772a991 JS |
5140 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
5141 | phba->IOCBs = (phba->slim2p.virt + | |
5142 | offsetof(struct lpfc_sli2_slim, IOCBs)); | |
5143 | ||
5144 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, | |
5145 | lpfc_sli_hbq_size(), | |
5146 | &phba->hbqslimp.phys, | |
5147 | GFP_KERNEL); | |
5148 | if (!phba->hbqslimp.virt) | |
5149 | goto out_free_slim; | |
5150 | ||
5151 | hbq_count = lpfc_sli_hbq_count(); | |
5152 | ptr = phba->hbqslimp.virt; | |
5153 | for (i = 0; i < hbq_count; ++i) { | |
5154 | phba->hbqs[i].hbq_virt = ptr; | |
5155 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
5156 | ptr += (lpfc_hbq_defs[i]->entry_count * | |
5157 | sizeof(struct lpfc_hbq_entry)); | |
5158 | } | |
5159 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; | |
5160 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; | |
5161 | ||
5162 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); | |
5163 | ||
5164 | INIT_LIST_HEAD(&phba->rb_pend_list); | |
5165 | ||
5166 | phba->MBslimaddr = phba->slim_memmap_p; | |
5167 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; | |
5168 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; | |
5169 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; | |
5170 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; | |
5171 | ||
5172 | return 0; | |
5173 | ||
5174 | out_free_slim: | |
5175 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
5176 | phba->slim2p.virt, phba->slim2p.phys); | |
5177 | out_iounmap: | |
5178 | iounmap(phba->ctrl_regs_memmap_p); | |
5179 | out_iounmap_slim: | |
5180 | iounmap(phba->slim_memmap_p); | |
5181 | out: | |
5182 | return error; | |
5183 | } | |
5184 | ||
5185 | /** | |
5186 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. | |
5187 | * @phba: pointer to lpfc hba data structure. | |
5188 | * | |
5189 | * This routine is invoked to unset the PCI device memory space for device | |
5190 | * with SLI-3 interface spec. | |
5191 | **/ | |
5192 | static void | |
5193 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) | |
5194 | { | |
5195 | struct pci_dev *pdev; | |
5196 | ||
5197 | /* Obtain PCI device reference */ | |
5198 | if (!phba->pcidev) | |
5199 | return; | |
5200 | else | |
5201 | pdev = phba->pcidev; | |
5202 | ||
5203 | /* Free coherent DMA memory allocated */ | |
5204 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
5205 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
5206 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
5207 | phba->slim2p.virt, phba->slim2p.phys); | |
5208 | ||
5209 | /* I/O memory unmap */ | |
5210 | iounmap(phba->ctrl_regs_memmap_p); | |
5211 | iounmap(phba->slim_memmap_p); | |
5212 | ||
5213 | return; | |
5214 | } | |
5215 | ||
5216 | /** | |
da0436e9 | 5217 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
3772a991 JS |
5218 | * @phba: pointer to lpfc hba data structure. |
5219 | * | |
da0436e9 JS |
5220 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
5221 | * done and check status. | |
3772a991 | 5222 | * |
da0436e9 | 5223 | * Return 0 if successful, otherwise -ENODEV. |
3772a991 | 5224 | **/ |
da0436e9 JS |
5225 | int |
5226 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) | |
3772a991 | 5227 | { |
28baac74 | 5228 | struct lpfc_register sta_reg, uerrlo_reg, uerrhi_reg; |
da0436e9 | 5229 | int i, port_error = -ENODEV; |
3772a991 | 5230 | |
da0436e9 JS |
5231 | if (!phba->sli4_hba.STAregaddr) |
5232 | return -ENODEV; | |
3772a991 | 5233 | |
da0436e9 JS |
5234 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
5235 | for (i = 0; i < 3000; i++) { | |
5236 | sta_reg.word0 = readl(phba->sli4_hba.STAregaddr); | |
5237 | /* Encounter fatal POST error, break out */ | |
5238 | if (bf_get(lpfc_hst_state_perr, &sta_reg)) { | |
5239 | port_error = -ENODEV; | |
5240 | break; | |
5241 | } | |
5242 | if (LPFC_POST_STAGE_ARMFW_READY == | |
5243 | bf_get(lpfc_hst_state_port_status, &sta_reg)) { | |
5244 | port_error = 0; | |
5245 | break; | |
5246 | } | |
5247 | msleep(10); | |
3772a991 JS |
5248 | } |
5249 | ||
da0436e9 JS |
5250 | if (port_error) |
5251 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5252 | "1408 Failure HBA POST Status: sta_reg=0x%x, " | |
5253 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, xrom=x%x, " | |
5254 | "dl=x%x, pstatus=x%x\n", sta_reg.word0, | |
5255 | bf_get(lpfc_hst_state_perr, &sta_reg), | |
5256 | bf_get(lpfc_hst_state_sfi, &sta_reg), | |
5257 | bf_get(lpfc_hst_state_nip, &sta_reg), | |
5258 | bf_get(lpfc_hst_state_ipc, &sta_reg), | |
5259 | bf_get(lpfc_hst_state_xrom, &sta_reg), | |
5260 | bf_get(lpfc_hst_state_dl, &sta_reg), | |
5261 | bf_get(lpfc_hst_state_port_status, &sta_reg)); | |
5262 | ||
5263 | /* Log device information */ | |
28baac74 JS |
5264 | phba->sli4_hba.sli_intf.word0 = readl(phba->sli4_hba.SLIINTFregaddr); |
5265 | if (bf_get(lpfc_sli_intf_valid, | |
5266 | &phba->sli4_hba.sli_intf) == LPFC_SLI_INTF_VALID) { | |
5267 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5268 | "2534 Device Info: ChipType=0x%x, SliRev=0x%x, " | |
5269 | "FeatureL1=0x%x, FeatureL2=0x%x\n", | |
5270 | bf_get(lpfc_sli_intf_sli_family, | |
5271 | &phba->sli4_hba.sli_intf), | |
5272 | bf_get(lpfc_sli_intf_slirev, | |
5273 | &phba->sli4_hba.sli_intf), | |
5274 | bf_get(lpfc_sli_intf_featurelevel1, | |
5275 | &phba->sli4_hba.sli_intf), | |
5276 | bf_get(lpfc_sli_intf_featurelevel2, | |
5277 | &phba->sli4_hba.sli_intf)); | |
5278 | } | |
a747c9ce JS |
5279 | phba->sli4_hba.ue_mask_lo = readl(phba->sli4_hba.UEMASKLOregaddr); |
5280 | phba->sli4_hba.ue_mask_hi = readl(phba->sli4_hba.UEMASKHIregaddr); | |
8fa38513 | 5281 | /* With uncoverable error, log the error message and return error */ |
a747c9ce JS |
5282 | uerrlo_reg.word0 = readl(phba->sli4_hba.UERRLOregaddr); |
5283 | uerrhi_reg.word0 = readl(phba->sli4_hba.UERRHIregaddr); | |
5284 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || | |
5285 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { | |
5286 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5287 | "1422 HBA Unrecoverable error: " | |
5288 | "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, " | |
5289 | "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n", | |
5290 | uerrlo_reg.word0, uerrhi_reg.word0, | |
5291 | phba->sli4_hba.ue_mask_lo, | |
5292 | phba->sli4_hba.ue_mask_hi); | |
8fa38513 JS |
5293 | return -ENODEV; |
5294 | } | |
5295 | ||
da0436e9 JS |
5296 | return port_error; |
5297 | } | |
3772a991 | 5298 | |
da0436e9 JS |
5299 | /** |
5300 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. | |
5301 | * @phba: pointer to lpfc hba data structure. | |
5302 | * | |
5303 | * This routine is invoked to set up SLI4 BAR0 PCI config space register | |
5304 | * memory map. | |
5305 | **/ | |
5306 | static void | |
5307 | lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba) | |
5308 | { | |
5309 | phba->sli4_hba.UERRLOregaddr = phba->sli4_hba.conf_regs_memmap_p + | |
5310 | LPFC_UERR_STATUS_LO; | |
5311 | phba->sli4_hba.UERRHIregaddr = phba->sli4_hba.conf_regs_memmap_p + | |
5312 | LPFC_UERR_STATUS_HI; | |
a747c9ce JS |
5313 | phba->sli4_hba.UEMASKLOregaddr = phba->sli4_hba.conf_regs_memmap_p + |
5314 | LPFC_UE_MASK_LO; | |
5315 | phba->sli4_hba.UEMASKHIregaddr = phba->sli4_hba.conf_regs_memmap_p + | |
5316 | LPFC_UE_MASK_HI; | |
28baac74 JS |
5317 | phba->sli4_hba.SLIINTFregaddr = phba->sli4_hba.conf_regs_memmap_p + |
5318 | LPFC_SLI_INTF; | |
da0436e9 | 5319 | } |
3772a991 | 5320 | |
da0436e9 JS |
5321 | /** |
5322 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. | |
5323 | * @phba: pointer to lpfc hba data structure. | |
5324 | * | |
5325 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) | |
5326 | * memory map. | |
5327 | **/ | |
5328 | static void | |
5329 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) | |
5330 | { | |
3772a991 | 5331 | |
da0436e9 JS |
5332 | phba->sli4_hba.STAregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
5333 | LPFC_HST_STATE; | |
5334 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + | |
5335 | LPFC_HST_ISR0; | |
5336 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + | |
5337 | LPFC_HST_IMR0; | |
5338 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + | |
5339 | LPFC_HST_ISCR0; | |
5340 | return; | |
3772a991 JS |
5341 | } |
5342 | ||
5343 | /** | |
da0436e9 | 5344 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
3772a991 | 5345 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 5346 | * @vf: virtual function number |
3772a991 | 5347 | * |
da0436e9 JS |
5348 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
5349 | * based on the given viftual function number, @vf. | |
5350 | * | |
5351 | * Return 0 if successful, otherwise -ENODEV. | |
3772a991 | 5352 | **/ |
da0436e9 JS |
5353 | static int |
5354 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) | |
3772a991 | 5355 | { |
da0436e9 JS |
5356 | if (vf > LPFC_VIR_FUNC_MAX) |
5357 | return -ENODEV; | |
3772a991 | 5358 | |
da0436e9 JS |
5359 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
5360 | vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL); | |
5361 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5362 | vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL); | |
5363 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5364 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); | |
5365 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5366 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); | |
5367 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5368 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); | |
5369 | return 0; | |
3772a991 JS |
5370 | } |
5371 | ||
5372 | /** | |
da0436e9 | 5373 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
3772a991 JS |
5374 | * @phba: pointer to lpfc hba data structure. |
5375 | * | |
da0436e9 JS |
5376 | * This routine is invoked to create the bootstrap mailbox |
5377 | * region consistent with the SLI-4 interface spec. This | |
5378 | * routine allocates all memory necessary to communicate | |
5379 | * mailbox commands to the port and sets up all alignment | |
5380 | * needs. No locks are expected to be held when calling | |
5381 | * this routine. | |
3772a991 JS |
5382 | * |
5383 | * Return codes | |
af901ca1 | 5384 | * 0 - successful |
da0436e9 JS |
5385 | * ENOMEM - could not allocated memory. |
5386 | **/ | |
3772a991 | 5387 | static int |
da0436e9 | 5388 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 5389 | { |
da0436e9 JS |
5390 | uint32_t bmbx_size; |
5391 | struct lpfc_dmabuf *dmabuf; | |
5392 | struct dma_address *dma_address; | |
5393 | uint32_t pa_addr; | |
5394 | uint64_t phys_addr; | |
5395 | ||
5396 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
5397 | if (!dmabuf) | |
5398 | return -ENOMEM; | |
3772a991 | 5399 | |
da0436e9 JS |
5400 | /* |
5401 | * The bootstrap mailbox region is comprised of 2 parts | |
5402 | * plus an alignment restriction of 16 bytes. | |
5403 | */ | |
5404 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); | |
5405 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
5406 | bmbx_size, | |
5407 | &dmabuf->phys, | |
5408 | GFP_KERNEL); | |
5409 | if (!dmabuf->virt) { | |
5410 | kfree(dmabuf); | |
5411 | return -ENOMEM; | |
3772a991 | 5412 | } |
da0436e9 | 5413 | memset(dmabuf->virt, 0, bmbx_size); |
3772a991 | 5414 | |
da0436e9 JS |
5415 | /* |
5416 | * Initialize the bootstrap mailbox pointers now so that the register | |
5417 | * operations are simple later. The mailbox dma address is required | |
5418 | * to be 16-byte aligned. Also align the virtual memory as each | |
5419 | * maibox is copied into the bmbx mailbox region before issuing the | |
5420 | * command to the port. | |
5421 | */ | |
5422 | phba->sli4_hba.bmbx.dmabuf = dmabuf; | |
5423 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; | |
5424 | ||
5425 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, | |
5426 | LPFC_ALIGN_16_BYTE); | |
5427 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, | |
5428 | LPFC_ALIGN_16_BYTE); | |
5429 | ||
5430 | /* | |
5431 | * Set the high and low physical addresses now. The SLI4 alignment | |
5432 | * requirement is 16 bytes and the mailbox is posted to the port | |
5433 | * as two 30-bit addresses. The other data is a bit marking whether | |
5434 | * the 30-bit address is the high or low address. | |
5435 | * Upcast bmbx aphys to 64bits so shift instruction compiles | |
5436 | * clean on 32 bit machines. | |
5437 | */ | |
5438 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
5439 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; | |
5440 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); | |
5441 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | | |
5442 | LPFC_BMBX_BIT1_ADDR_HI); | |
5443 | ||
5444 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); | |
5445 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | | |
5446 | LPFC_BMBX_BIT1_ADDR_LO); | |
5447 | return 0; | |
3772a991 JS |
5448 | } |
5449 | ||
5450 | /** | |
da0436e9 | 5451 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
3772a991 JS |
5452 | * @phba: pointer to lpfc hba data structure. |
5453 | * | |
da0436e9 JS |
5454 | * This routine is invoked to teardown the bootstrap mailbox |
5455 | * region and release all host resources. This routine requires | |
5456 | * the caller to ensure all mailbox commands recovered, no | |
5457 | * additional mailbox comands are sent, and interrupts are disabled | |
5458 | * before calling this routine. | |
5459 | * | |
5460 | **/ | |
3772a991 | 5461 | static void |
da0436e9 | 5462 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 5463 | { |
da0436e9 JS |
5464 | dma_free_coherent(&phba->pcidev->dev, |
5465 | phba->sli4_hba.bmbx.bmbx_size, | |
5466 | phba->sli4_hba.bmbx.dmabuf->virt, | |
5467 | phba->sli4_hba.bmbx.dmabuf->phys); | |
5468 | ||
5469 | kfree(phba->sli4_hba.bmbx.dmabuf); | |
5470 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); | |
3772a991 JS |
5471 | } |
5472 | ||
5473 | /** | |
da0436e9 | 5474 | * lpfc_sli4_read_config - Get the config parameters. |
3772a991 JS |
5475 | * @phba: pointer to lpfc hba data structure. |
5476 | * | |
da0436e9 JS |
5477 | * This routine is invoked to read the configuration parameters from the HBA. |
5478 | * The configuration parameters are used to set the base and maximum values | |
5479 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource | |
5480 | * allocation for the port. | |
3772a991 JS |
5481 | * |
5482 | * Return codes | |
af901ca1 | 5483 | * 0 - successful |
da0436e9 JS |
5484 | * ENOMEM - No availble memory |
5485 | * EIO - The mailbox failed to complete successfully. | |
3772a991 | 5486 | **/ |
da0436e9 JS |
5487 | static int |
5488 | lpfc_sli4_read_config(struct lpfc_hba *phba) | |
3772a991 | 5489 | { |
da0436e9 JS |
5490 | LPFC_MBOXQ_t *pmb; |
5491 | struct lpfc_mbx_read_config *rd_config; | |
5492 | uint32_t rc = 0; | |
3772a991 | 5493 | |
da0436e9 JS |
5494 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
5495 | if (!pmb) { | |
5496 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5497 | "2011 Unable to allocate memory for issuing " | |
5498 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
5499 | return -ENOMEM; | |
3772a991 JS |
5500 | } |
5501 | ||
da0436e9 | 5502 | lpfc_read_config(phba, pmb); |
3772a991 | 5503 | |
da0436e9 JS |
5504 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
5505 | if (rc != MBX_SUCCESS) { | |
5506 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5507 | "2012 Mailbox failed , mbxCmd x%x " | |
5508 | "READ_CONFIG, mbxStatus x%x\n", | |
5509 | bf_get(lpfc_mqe_command, &pmb->u.mqe), | |
5510 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); | |
5511 | rc = -EIO; | |
5512 | } else { | |
5513 | rd_config = &pmb->u.mqe.un.rd_config; | |
5514 | phba->sli4_hba.max_cfg_param.max_xri = | |
5515 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); | |
5516 | phba->sli4_hba.max_cfg_param.xri_base = | |
5517 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); | |
5518 | phba->sli4_hba.max_cfg_param.max_vpi = | |
5519 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); | |
5520 | phba->sli4_hba.max_cfg_param.vpi_base = | |
5521 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); | |
5522 | phba->sli4_hba.max_cfg_param.max_rpi = | |
5523 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); | |
5524 | phba->sli4_hba.max_cfg_param.rpi_base = | |
5525 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); | |
5526 | phba->sli4_hba.max_cfg_param.max_vfi = | |
5527 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); | |
5528 | phba->sli4_hba.max_cfg_param.vfi_base = | |
5529 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); | |
5530 | phba->sli4_hba.max_cfg_param.max_fcfi = | |
5531 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); | |
5532 | phba->sli4_hba.max_cfg_param.fcfi_base = | |
5533 | bf_get(lpfc_mbx_rd_conf_fcfi_base, rd_config); | |
5534 | phba->sli4_hba.max_cfg_param.max_eq = | |
5535 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); | |
5536 | phba->sli4_hba.max_cfg_param.max_rq = | |
5537 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); | |
5538 | phba->sli4_hba.max_cfg_param.max_wq = | |
5539 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); | |
5540 | phba->sli4_hba.max_cfg_param.max_cq = | |
5541 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); | |
5542 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); | |
5543 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; | |
5544 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; | |
5545 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; | |
5546 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base; | |
5ffc266e JS |
5547 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
5548 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; | |
da0436e9 JS |
5549 | phba->max_vports = phba->max_vpi; |
5550 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
5551 | "2003 cfg params XRI(B:%d M:%d), " | |
5552 | "VPI(B:%d M:%d) " | |
5553 | "VFI(B:%d M:%d) " | |
5554 | "RPI(B:%d M:%d) " | |
5555 | "FCFI(B:%d M:%d)\n", | |
5556 | phba->sli4_hba.max_cfg_param.xri_base, | |
5557 | phba->sli4_hba.max_cfg_param.max_xri, | |
5558 | phba->sli4_hba.max_cfg_param.vpi_base, | |
5559 | phba->sli4_hba.max_cfg_param.max_vpi, | |
5560 | phba->sli4_hba.max_cfg_param.vfi_base, | |
5561 | phba->sli4_hba.max_cfg_param.max_vfi, | |
5562 | phba->sli4_hba.max_cfg_param.rpi_base, | |
5563 | phba->sli4_hba.max_cfg_param.max_rpi, | |
5564 | phba->sli4_hba.max_cfg_param.fcfi_base, | |
5565 | phba->sli4_hba.max_cfg_param.max_fcfi); | |
3772a991 | 5566 | } |
da0436e9 JS |
5567 | mempool_free(pmb, phba->mbox_mem_pool); |
5568 | ||
5569 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ | |
b92938b4 JS |
5570 | if (phba->cfg_hba_queue_depth > |
5571 | (phba->sli4_hba.max_cfg_param.max_xri - | |
5572 | lpfc_sli4_get_els_iocb_cnt(phba))) | |
da0436e9 | 5573 | phba->cfg_hba_queue_depth = |
b92938b4 JS |
5574 | phba->sli4_hba.max_cfg_param.max_xri - |
5575 | lpfc_sli4_get_els_iocb_cnt(phba); | |
da0436e9 | 5576 | return rc; |
3772a991 JS |
5577 | } |
5578 | ||
5579 | /** | |
da0436e9 | 5580 | * lpfc_dev_endian_order_setup - Notify the port of the host's endian order. |
3772a991 JS |
5581 | * @phba: pointer to lpfc hba data structure. |
5582 | * | |
da0436e9 JS |
5583 | * This routine is invoked to setup the host-side endian order to the |
5584 | * HBA consistent with the SLI-4 interface spec. | |
5585 | * | |
5586 | * Return codes | |
af901ca1 | 5587 | * 0 - successful |
da0436e9 JS |
5588 | * ENOMEM - No availble memory |
5589 | * EIO - The mailbox failed to complete successfully. | |
3772a991 | 5590 | **/ |
da0436e9 JS |
5591 | static int |
5592 | lpfc_setup_endian_order(struct lpfc_hba *phba) | |
3772a991 | 5593 | { |
da0436e9 JS |
5594 | LPFC_MBOXQ_t *mboxq; |
5595 | uint32_t rc = 0; | |
5596 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, | |
5597 | HOST_ENDIAN_HIGH_WORD1}; | |
3772a991 | 5598 | |
da0436e9 JS |
5599 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
5600 | if (!mboxq) { | |
5601 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5602 | "0492 Unable to allocate memory for issuing " | |
5603 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
5604 | return -ENOMEM; | |
5605 | } | |
3772a991 | 5606 | |
da0436e9 JS |
5607 | /* |
5608 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first two | |
5609 | * words to contain special data values and no other data. | |
5610 | */ | |
5611 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
5612 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); | |
5613 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
5614 | if (rc != MBX_SUCCESS) { | |
5615 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5616 | "0493 SLI_CONFIG_SPECIAL mailbox failed with " | |
5617 | "status x%x\n", | |
5618 | rc); | |
5619 | rc = -EIO; | |
5620 | } | |
5621 | ||
5622 | mempool_free(mboxq, phba->mbox_mem_pool); | |
5623 | return rc; | |
3772a991 JS |
5624 | } |
5625 | ||
5626 | /** | |
da0436e9 | 5627 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
3772a991 JS |
5628 | * @phba: pointer to lpfc hba data structure. |
5629 | * | |
da0436e9 JS |
5630 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
5631 | * operation. For each SLI4 queue type, the parameters such as queue entry | |
5632 | * count (queue depth) shall be taken from the module parameter. For now, | |
5633 | * we just use some constant number as place holder. | |
5634 | * | |
5635 | * Return codes | |
af901ca1 | 5636 | * 0 - successful |
da0436e9 JS |
5637 | * ENOMEM - No availble memory |
5638 | * EIO - The mailbox failed to complete successfully. | |
3772a991 | 5639 | **/ |
da0436e9 JS |
5640 | static int |
5641 | lpfc_sli4_queue_create(struct lpfc_hba *phba) | |
3772a991 | 5642 | { |
da0436e9 JS |
5643 | struct lpfc_queue *qdesc; |
5644 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; | |
5645 | int cfg_fcp_wq_count; | |
5646 | int cfg_fcp_eq_count; | |
3772a991 | 5647 | |
da0436e9 JS |
5648 | /* |
5649 | * Sanity check for confiugred queue parameters against the run-time | |
5650 | * device parameters | |
5651 | */ | |
3772a991 | 5652 | |
da0436e9 JS |
5653 | /* Sanity check on FCP fast-path WQ parameters */ |
5654 | cfg_fcp_wq_count = phba->cfg_fcp_wq_count; | |
5655 | if (cfg_fcp_wq_count > | |
5656 | (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) { | |
5657 | cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq - | |
5658 | LPFC_SP_WQN_DEF; | |
5659 | if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) { | |
5660 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5661 | "2581 Not enough WQs (%d) from " | |
5662 | "the pci function for supporting " | |
5663 | "FCP WQs (%d)\n", | |
5664 | phba->sli4_hba.max_cfg_param.max_wq, | |
5665 | phba->cfg_fcp_wq_count); | |
5666 | goto out_error; | |
5667 | } | |
5668 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
5669 | "2582 Not enough WQs (%d) from the pci " | |
5670 | "function for supporting the requested " | |
5671 | "FCP WQs (%d), the actual FCP WQs can " | |
5672 | "be supported: %d\n", | |
5673 | phba->sli4_hba.max_cfg_param.max_wq, | |
5674 | phba->cfg_fcp_wq_count, cfg_fcp_wq_count); | |
5675 | } | |
5676 | /* The actual number of FCP work queues adopted */ | |
5677 | phba->cfg_fcp_wq_count = cfg_fcp_wq_count; | |
5678 | ||
5679 | /* Sanity check on FCP fast-path EQ parameters */ | |
5680 | cfg_fcp_eq_count = phba->cfg_fcp_eq_count; | |
5681 | if (cfg_fcp_eq_count > | |
5682 | (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) { | |
5683 | cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq - | |
5684 | LPFC_SP_EQN_DEF; | |
5685 | if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) { | |
5686 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5687 | "2574 Not enough EQs (%d) from the " | |
5688 | "pci function for supporting FCP " | |
5689 | "EQs (%d)\n", | |
5690 | phba->sli4_hba.max_cfg_param.max_eq, | |
5691 | phba->cfg_fcp_eq_count); | |
5692 | goto out_error; | |
5693 | } | |
5694 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
5695 | "2575 Not enough EQs (%d) from the pci " | |
5696 | "function for supporting the requested " | |
5697 | "FCP EQs (%d), the actual FCP EQs can " | |
5698 | "be supported: %d\n", | |
5699 | phba->sli4_hba.max_cfg_param.max_eq, | |
5700 | phba->cfg_fcp_eq_count, cfg_fcp_eq_count); | |
5701 | } | |
5702 | /* It does not make sense to have more EQs than WQs */ | |
5703 | if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) { | |
5704 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6a9c52cf JS |
5705 | "2593 The FCP EQ count(%d) cannot be greater " |
5706 | "than the FCP WQ count(%d), limiting the " | |
5707 | "FCP EQ count to %d\n", cfg_fcp_eq_count, | |
da0436e9 JS |
5708 | phba->cfg_fcp_wq_count, |
5709 | phba->cfg_fcp_wq_count); | |
5710 | cfg_fcp_eq_count = phba->cfg_fcp_wq_count; | |
5711 | } | |
5712 | /* The actual number of FCP event queues adopted */ | |
5713 | phba->cfg_fcp_eq_count = cfg_fcp_eq_count; | |
5714 | /* The overall number of event queues used */ | |
5715 | phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF; | |
3772a991 | 5716 | |
da0436e9 JS |
5717 | /* |
5718 | * Create Event Queues (EQs) | |
5719 | */ | |
3772a991 | 5720 | |
da0436e9 JS |
5721 | /* Get EQ depth from module parameter, fake the default for now */ |
5722 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; | |
5723 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; | |
3772a991 | 5724 | |
da0436e9 JS |
5725 | /* Create slow path event queue */ |
5726 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | |
5727 | phba->sli4_hba.eq_ecount); | |
5728 | if (!qdesc) { | |
5729 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5730 | "0496 Failed allocate slow-path EQ\n"); | |
5731 | goto out_error; | |
5732 | } | |
5733 | phba->sli4_hba.sp_eq = qdesc; | |
5734 | ||
5735 | /* Create fast-path FCP Event Queue(s) */ | |
5736 | phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) * | |
5737 | phba->cfg_fcp_eq_count), GFP_KERNEL); | |
5738 | if (!phba->sli4_hba.fp_eq) { | |
5739 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5740 | "2576 Failed allocate memory for fast-path " | |
5741 | "EQ record array\n"); | |
5742 | goto out_free_sp_eq; | |
5743 | } | |
5744 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
5745 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | |
5746 | phba->sli4_hba.eq_ecount); | |
5747 | if (!qdesc) { | |
5748 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5749 | "0497 Failed allocate fast-path EQ\n"); | |
5750 | goto out_free_fp_eq; | |
5751 | } | |
5752 | phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc; | |
5753 | } | |
5754 | ||
5755 | /* | |
5756 | * Create Complete Queues (CQs) | |
5757 | */ | |
5758 | ||
5759 | /* Get CQ depth from module parameter, fake the default for now */ | |
5760 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; | |
5761 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; | |
5762 | ||
5763 | /* Create slow-path Mailbox Command Complete Queue */ | |
5764 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
5765 | phba->sli4_hba.cq_ecount); | |
5766 | if (!qdesc) { | |
5767 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5768 | "0500 Failed allocate slow-path mailbox CQ\n"); | |
5769 | goto out_free_fp_eq; | |
5770 | } | |
5771 | phba->sli4_hba.mbx_cq = qdesc; | |
5772 | ||
5773 | /* Create slow-path ELS Complete Queue */ | |
5774 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
5775 | phba->sli4_hba.cq_ecount); | |
5776 | if (!qdesc) { | |
5777 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5778 | "0501 Failed allocate slow-path ELS CQ\n"); | |
5779 | goto out_free_mbx_cq; | |
5780 | } | |
5781 | phba->sli4_hba.els_cq = qdesc; | |
5782 | ||
da0436e9 JS |
5783 | |
5784 | /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */ | |
5785 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * | |
5786 | phba->cfg_fcp_eq_count), GFP_KERNEL); | |
5787 | if (!phba->sli4_hba.fcp_cq) { | |
5788 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5789 | "2577 Failed allocate memory for fast-path " | |
5790 | "CQ record array\n"); | |
4d9ab994 | 5791 | goto out_free_els_cq; |
da0436e9 JS |
5792 | } |
5793 | for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) { | |
5794 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
5795 | phba->sli4_hba.cq_ecount); | |
5796 | if (!qdesc) { | |
5797 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5798 | "0499 Failed allocate fast-path FCP " | |
5799 | "CQ (%d)\n", fcp_cqidx); | |
5800 | goto out_free_fcp_cq; | |
5801 | } | |
5802 | phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc; | |
5803 | } | |
5804 | ||
5805 | /* Create Mailbox Command Queue */ | |
5806 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; | |
5807 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; | |
5808 | ||
5809 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, | |
5810 | phba->sli4_hba.mq_ecount); | |
5811 | if (!qdesc) { | |
5812 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5813 | "0505 Failed allocate slow-path MQ\n"); | |
5814 | goto out_free_fcp_cq; | |
5815 | } | |
5816 | phba->sli4_hba.mbx_wq = qdesc; | |
5817 | ||
5818 | /* | |
5819 | * Create all the Work Queues (WQs) | |
5820 | */ | |
5821 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; | |
5822 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; | |
5823 | ||
5824 | /* Create slow-path ELS Work Queue */ | |
5825 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
5826 | phba->sli4_hba.wq_ecount); | |
5827 | if (!qdesc) { | |
5828 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5829 | "0504 Failed allocate slow-path ELS WQ\n"); | |
5830 | goto out_free_mbx_wq; | |
5831 | } | |
5832 | phba->sli4_hba.els_wq = qdesc; | |
5833 | ||
5834 | /* Create fast-path FCP Work Queue(s) */ | |
5835 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * | |
5836 | phba->cfg_fcp_wq_count), GFP_KERNEL); | |
5837 | if (!phba->sli4_hba.fcp_wq) { | |
5838 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5839 | "2578 Failed allocate memory for fast-path " | |
5840 | "WQ record array\n"); | |
5841 | goto out_free_els_wq; | |
5842 | } | |
5843 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { | |
5844 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
5845 | phba->sli4_hba.wq_ecount); | |
5846 | if (!qdesc) { | |
5847 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5848 | "0503 Failed allocate fast-path FCP " | |
5849 | "WQ (%d)\n", fcp_wqidx); | |
5850 | goto out_free_fcp_wq; | |
5851 | } | |
5852 | phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc; | |
5853 | } | |
5854 | ||
5855 | /* | |
5856 | * Create Receive Queue (RQ) | |
5857 | */ | |
5858 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; | |
5859 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; | |
5860 | ||
5861 | /* Create Receive Queue for header */ | |
5862 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
5863 | phba->sli4_hba.rq_ecount); | |
5864 | if (!qdesc) { | |
5865 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5866 | "0506 Failed allocate receive HRQ\n"); | |
5867 | goto out_free_fcp_wq; | |
5868 | } | |
5869 | phba->sli4_hba.hdr_rq = qdesc; | |
5870 | ||
5871 | /* Create Receive Queue for data */ | |
5872 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
5873 | phba->sli4_hba.rq_ecount); | |
5874 | if (!qdesc) { | |
5875 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5876 | "0507 Failed allocate receive DRQ\n"); | |
5877 | goto out_free_hdr_rq; | |
5878 | } | |
5879 | phba->sli4_hba.dat_rq = qdesc; | |
5880 | ||
5881 | return 0; | |
5882 | ||
5883 | out_free_hdr_rq: | |
5884 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); | |
5885 | phba->sli4_hba.hdr_rq = NULL; | |
5886 | out_free_fcp_wq: | |
5887 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) { | |
5888 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]); | |
5889 | phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL; | |
5890 | } | |
5891 | kfree(phba->sli4_hba.fcp_wq); | |
5892 | out_free_els_wq: | |
5893 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); | |
5894 | phba->sli4_hba.els_wq = NULL; | |
5895 | out_free_mbx_wq: | |
5896 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); | |
5897 | phba->sli4_hba.mbx_wq = NULL; | |
5898 | out_free_fcp_cq: | |
5899 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) { | |
5900 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]); | |
5901 | phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL; | |
5902 | } | |
5903 | kfree(phba->sli4_hba.fcp_cq); | |
da0436e9 JS |
5904 | out_free_els_cq: |
5905 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); | |
5906 | phba->sli4_hba.els_cq = NULL; | |
5907 | out_free_mbx_cq: | |
5908 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); | |
5909 | phba->sli4_hba.mbx_cq = NULL; | |
5910 | out_free_fp_eq: | |
5911 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) { | |
5912 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]); | |
5913 | phba->sli4_hba.fp_eq[fcp_eqidx] = NULL; | |
5914 | } | |
5915 | kfree(phba->sli4_hba.fp_eq); | |
5916 | out_free_sp_eq: | |
5917 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); | |
5918 | phba->sli4_hba.sp_eq = NULL; | |
5919 | out_error: | |
5920 | return -ENOMEM; | |
5921 | } | |
5922 | ||
5923 | /** | |
5924 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues | |
5925 | * @phba: pointer to lpfc hba data structure. | |
5926 | * | |
5927 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA | |
5928 | * operation. | |
5929 | * | |
5930 | * Return codes | |
af901ca1 | 5931 | * 0 - successful |
da0436e9 JS |
5932 | * ENOMEM - No availble memory |
5933 | * EIO - The mailbox failed to complete successfully. | |
5934 | **/ | |
5935 | static void | |
5936 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) | |
5937 | { | |
5938 | int fcp_qidx; | |
5939 | ||
5940 | /* Release mailbox command work queue */ | |
5941 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); | |
5942 | phba->sli4_hba.mbx_wq = NULL; | |
5943 | ||
5944 | /* Release ELS work queue */ | |
5945 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); | |
5946 | phba->sli4_hba.els_wq = NULL; | |
5947 | ||
5948 | /* Release FCP work queue */ | |
5949 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) | |
5950 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]); | |
5951 | kfree(phba->sli4_hba.fcp_wq); | |
5952 | phba->sli4_hba.fcp_wq = NULL; | |
5953 | ||
5954 | /* Release unsolicited receive queue */ | |
5955 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); | |
5956 | phba->sli4_hba.hdr_rq = NULL; | |
5957 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); | |
5958 | phba->sli4_hba.dat_rq = NULL; | |
5959 | ||
da0436e9 JS |
5960 | /* Release ELS complete queue */ |
5961 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); | |
5962 | phba->sli4_hba.els_cq = NULL; | |
5963 | ||
5964 | /* Release mailbox command complete queue */ | |
5965 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); | |
5966 | phba->sli4_hba.mbx_cq = NULL; | |
5967 | ||
5968 | /* Release FCP response complete queue */ | |
5969 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | |
5970 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]); | |
5971 | kfree(phba->sli4_hba.fcp_cq); | |
5972 | phba->sli4_hba.fcp_cq = NULL; | |
5973 | ||
5974 | /* Release fast-path event queue */ | |
5975 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | |
5976 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]); | |
5977 | kfree(phba->sli4_hba.fp_eq); | |
5978 | phba->sli4_hba.fp_eq = NULL; | |
5979 | ||
5980 | /* Release slow-path event queue */ | |
5981 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); | |
5982 | phba->sli4_hba.sp_eq = NULL; | |
5983 | ||
5984 | return; | |
5985 | } | |
5986 | ||
5987 | /** | |
5988 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues | |
5989 | * @phba: pointer to lpfc hba data structure. | |
5990 | * | |
5991 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA | |
5992 | * operation. | |
5993 | * | |
5994 | * Return codes | |
af901ca1 | 5995 | * 0 - successful |
da0436e9 JS |
5996 | * ENOMEM - No availble memory |
5997 | * EIO - The mailbox failed to complete successfully. | |
5998 | **/ | |
5999 | int | |
6000 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) | |
6001 | { | |
6002 | int rc = -ENOMEM; | |
6003 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; | |
6004 | int fcp_cq_index = 0; | |
6005 | ||
6006 | /* | |
6007 | * Set up Event Queues (EQs) | |
6008 | */ | |
6009 | ||
6010 | /* Set up slow-path event queue */ | |
6011 | if (!phba->sli4_hba.sp_eq) { | |
6012 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6013 | "0520 Slow-path EQ not allocated\n"); | |
6014 | goto out_error; | |
6015 | } | |
6016 | rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq, | |
6017 | LPFC_SP_DEF_IMAX); | |
6018 | if (rc) { | |
6019 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6020 | "0521 Failed setup of slow-path EQ: " | |
6021 | "rc = 0x%x\n", rc); | |
6022 | goto out_error; | |
6023 | } | |
6024 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6025 | "2583 Slow-path EQ setup: queue-id=%d\n", | |
6026 | phba->sli4_hba.sp_eq->queue_id); | |
6027 | ||
6028 | /* Set up fast-path event queue */ | |
6029 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
6030 | if (!phba->sli4_hba.fp_eq[fcp_eqidx]) { | |
6031 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6032 | "0522 Fast-path EQ (%d) not " | |
6033 | "allocated\n", fcp_eqidx); | |
6034 | goto out_destroy_fp_eq; | |
6035 | } | |
6036 | rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx], | |
6037 | phba->cfg_fcp_imax); | |
6038 | if (rc) { | |
6039 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6040 | "0523 Failed setup of fast-path EQ " | |
6041 | "(%d), rc = 0x%x\n", fcp_eqidx, rc); | |
6042 | goto out_destroy_fp_eq; | |
6043 | } | |
6044 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6045 | "2584 Fast-path EQ setup: " | |
6046 | "queue[%d]-id=%d\n", fcp_eqidx, | |
6047 | phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id); | |
6048 | } | |
6049 | ||
6050 | /* | |
6051 | * Set up Complete Queues (CQs) | |
6052 | */ | |
6053 | ||
6054 | /* Set up slow-path MBOX Complete Queue as the first CQ */ | |
6055 | if (!phba->sli4_hba.mbx_cq) { | |
6056 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6057 | "0528 Mailbox CQ not allocated\n"); | |
6058 | goto out_destroy_fp_eq; | |
6059 | } | |
6060 | rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq, | |
6061 | LPFC_MCQ, LPFC_MBOX); | |
6062 | if (rc) { | |
6063 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6064 | "0529 Failed setup of slow-path mailbox CQ: " | |
6065 | "rc = 0x%x\n", rc); | |
6066 | goto out_destroy_fp_eq; | |
6067 | } | |
6068 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6069 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", | |
6070 | phba->sli4_hba.mbx_cq->queue_id, | |
6071 | phba->sli4_hba.sp_eq->queue_id); | |
6072 | ||
6073 | /* Set up slow-path ELS Complete Queue */ | |
6074 | if (!phba->sli4_hba.els_cq) { | |
6075 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6076 | "0530 ELS CQ not allocated\n"); | |
6077 | goto out_destroy_mbx_cq; | |
6078 | } | |
6079 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq, | |
6080 | LPFC_WCQ, LPFC_ELS); | |
6081 | if (rc) { | |
6082 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6083 | "0531 Failed setup of slow-path ELS CQ: " | |
6084 | "rc = 0x%x\n", rc); | |
6085 | goto out_destroy_mbx_cq; | |
6086 | } | |
6087 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6088 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", | |
6089 | phba->sli4_hba.els_cq->queue_id, | |
6090 | phba->sli4_hba.sp_eq->queue_id); | |
6091 | ||
da0436e9 JS |
6092 | /* Set up fast-path FCP Response Complete Queue */ |
6093 | for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) { | |
6094 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { | |
6095 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6096 | "0526 Fast-path FCP CQ (%d) not " | |
6097 | "allocated\n", fcp_cqidx); | |
6098 | goto out_destroy_fcp_cq; | |
6099 | } | |
6100 | rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx], | |
6101 | phba->sli4_hba.fp_eq[fcp_cqidx], | |
6102 | LPFC_WCQ, LPFC_FCP); | |
6103 | if (rc) { | |
6104 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6105 | "0527 Failed setup of fast-path FCP " | |
6106 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc); | |
6107 | goto out_destroy_fcp_cq; | |
6108 | } | |
6109 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6110 | "2588 FCP CQ setup: cq[%d]-id=%d, " | |
6111 | "parent eq[%d]-id=%d\n", | |
6112 | fcp_cqidx, | |
6113 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, | |
6114 | fcp_cqidx, | |
6115 | phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id); | |
6116 | } | |
6117 | ||
6118 | /* | |
6119 | * Set up all the Work Queues (WQs) | |
6120 | */ | |
6121 | ||
6122 | /* Set up Mailbox Command Queue */ | |
6123 | if (!phba->sli4_hba.mbx_wq) { | |
6124 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6125 | "0538 Slow-path MQ not allocated\n"); | |
6126 | goto out_destroy_fcp_cq; | |
6127 | } | |
6128 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, | |
6129 | phba->sli4_hba.mbx_cq, LPFC_MBOX); | |
6130 | if (rc) { | |
6131 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6132 | "0539 Failed setup of slow-path MQ: " | |
6133 | "rc = 0x%x\n", rc); | |
6134 | goto out_destroy_fcp_cq; | |
6135 | } | |
6136 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6137 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", | |
6138 | phba->sli4_hba.mbx_wq->queue_id, | |
6139 | phba->sli4_hba.mbx_cq->queue_id); | |
6140 | ||
6141 | /* Set up slow-path ELS Work Queue */ | |
6142 | if (!phba->sli4_hba.els_wq) { | |
6143 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6144 | "0536 Slow-path ELS WQ not allocated\n"); | |
6145 | goto out_destroy_mbx_wq; | |
6146 | } | |
6147 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, | |
6148 | phba->sli4_hba.els_cq, LPFC_ELS); | |
6149 | if (rc) { | |
6150 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6151 | "0537 Failed setup of slow-path ELS WQ: " | |
6152 | "rc = 0x%x\n", rc); | |
6153 | goto out_destroy_mbx_wq; | |
6154 | } | |
6155 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6156 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", | |
6157 | phba->sli4_hba.els_wq->queue_id, | |
6158 | phba->sli4_hba.els_cq->queue_id); | |
6159 | ||
6160 | /* Set up fast-path FCP Work Queue */ | |
6161 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { | |
6162 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { | |
6163 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6164 | "0534 Fast-path FCP WQ (%d) not " | |
6165 | "allocated\n", fcp_wqidx); | |
6166 | goto out_destroy_fcp_wq; | |
6167 | } | |
6168 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], | |
6169 | phba->sli4_hba.fcp_cq[fcp_cq_index], | |
6170 | LPFC_FCP); | |
6171 | if (rc) { | |
6172 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6173 | "0535 Failed setup of fast-path FCP " | |
6174 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc); | |
6175 | goto out_destroy_fcp_wq; | |
6176 | } | |
6177 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6178 | "2591 FCP WQ setup: wq[%d]-id=%d, " | |
6179 | "parent cq[%d]-id=%d\n", | |
6180 | fcp_wqidx, | |
6181 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, | |
6182 | fcp_cq_index, | |
6183 | phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id); | |
6184 | /* Round robin FCP Work Queue's Completion Queue assignment */ | |
6185 | fcp_cq_index = ((fcp_cq_index + 1) % phba->cfg_fcp_eq_count); | |
6186 | } | |
6187 | ||
6188 | /* | |
6189 | * Create Receive Queue (RQ) | |
6190 | */ | |
6191 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { | |
6192 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6193 | "0540 Receive Queue not allocated\n"); | |
6194 | goto out_destroy_fcp_wq; | |
6195 | } | |
6196 | rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, | |
4d9ab994 | 6197 | phba->sli4_hba.els_cq, LPFC_USOL); |
da0436e9 JS |
6198 | if (rc) { |
6199 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6200 | "0541 Failed setup of Receive Queue: " | |
6201 | "rc = 0x%x\n", rc); | |
6202 | goto out_destroy_fcp_wq; | |
6203 | } | |
6204 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6205 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " | |
6206 | "parent cq-id=%d\n", | |
6207 | phba->sli4_hba.hdr_rq->queue_id, | |
6208 | phba->sli4_hba.dat_rq->queue_id, | |
4d9ab994 | 6209 | phba->sli4_hba.els_cq->queue_id); |
da0436e9 JS |
6210 | return 0; |
6211 | ||
6212 | out_destroy_fcp_wq: | |
6213 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) | |
6214 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); | |
6215 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); | |
6216 | out_destroy_mbx_wq: | |
6217 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | |
6218 | out_destroy_fcp_cq: | |
6219 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) | |
6220 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); | |
da0436e9 JS |
6221 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
6222 | out_destroy_mbx_cq: | |
6223 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | |
6224 | out_destroy_fp_eq: | |
6225 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) | |
6226 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]); | |
6227 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); | |
6228 | out_error: | |
6229 | return rc; | |
6230 | } | |
6231 | ||
6232 | /** | |
6233 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues | |
6234 | * @phba: pointer to lpfc hba data structure. | |
6235 | * | |
6236 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA | |
6237 | * operation. | |
6238 | * | |
6239 | * Return codes | |
af901ca1 | 6240 | * 0 - successful |
da0436e9 JS |
6241 | * ENOMEM - No availble memory |
6242 | * EIO - The mailbox failed to complete successfully. | |
6243 | **/ | |
6244 | void | |
6245 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) | |
6246 | { | |
6247 | int fcp_qidx; | |
6248 | ||
6249 | /* Unset mailbox command work queue */ | |
6250 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | |
6251 | /* Unset ELS work queue */ | |
6252 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); | |
6253 | /* Unset unsolicited receive queue */ | |
6254 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); | |
6255 | /* Unset FCP work queue */ | |
6256 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) | |
6257 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); | |
6258 | /* Unset mailbox command complete queue */ | |
6259 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | |
6260 | /* Unset ELS complete queue */ | |
6261 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); | |
da0436e9 JS |
6262 | /* Unset FCP response complete queue */ |
6263 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | |
6264 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); | |
6265 | /* Unset fast-path event queue */ | |
6266 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | |
6267 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]); | |
6268 | /* Unset slow-path event queue */ | |
6269 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); | |
6270 | } | |
6271 | ||
6272 | /** | |
6273 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool | |
6274 | * @phba: pointer to lpfc hba data structure. | |
6275 | * | |
6276 | * This routine is invoked to allocate and set up a pool of completion queue | |
6277 | * events. The body of the completion queue event is a completion queue entry | |
6278 | * CQE. For now, this pool is used for the interrupt service routine to queue | |
6279 | * the following HBA completion queue events for the worker thread to process: | |
6280 | * - Mailbox asynchronous events | |
6281 | * - Receive queue completion unsolicited events | |
6282 | * Later, this can be used for all the slow-path events. | |
6283 | * | |
6284 | * Return codes | |
af901ca1 | 6285 | * 0 - successful |
da0436e9 JS |
6286 | * -ENOMEM - No availble memory |
6287 | **/ | |
6288 | static int | |
6289 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) | |
6290 | { | |
6291 | struct lpfc_cq_event *cq_event; | |
6292 | int i; | |
6293 | ||
6294 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { | |
6295 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); | |
6296 | if (!cq_event) | |
6297 | goto out_pool_create_fail; | |
6298 | list_add_tail(&cq_event->list, | |
6299 | &phba->sli4_hba.sp_cqe_event_pool); | |
6300 | } | |
6301 | return 0; | |
6302 | ||
6303 | out_pool_create_fail: | |
6304 | lpfc_sli4_cq_event_pool_destroy(phba); | |
6305 | return -ENOMEM; | |
6306 | } | |
6307 | ||
6308 | /** | |
6309 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool | |
6310 | * @phba: pointer to lpfc hba data structure. | |
6311 | * | |
6312 | * This routine is invoked to free the pool of completion queue events at | |
6313 | * driver unload time. Note that, it is the responsibility of the driver | |
6314 | * cleanup routine to free all the outstanding completion-queue events | |
6315 | * allocated from this pool back into the pool before invoking this routine | |
6316 | * to destroy the pool. | |
6317 | **/ | |
6318 | static void | |
6319 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) | |
6320 | { | |
6321 | struct lpfc_cq_event *cq_event, *next_cq_event; | |
6322 | ||
6323 | list_for_each_entry_safe(cq_event, next_cq_event, | |
6324 | &phba->sli4_hba.sp_cqe_event_pool, list) { | |
6325 | list_del(&cq_event->list); | |
6326 | kfree(cq_event); | |
6327 | } | |
6328 | } | |
6329 | ||
6330 | /** | |
6331 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
6332 | * @phba: pointer to lpfc hba data structure. | |
6333 | * | |
6334 | * This routine is the lock free version of the API invoked to allocate a | |
6335 | * completion-queue event from the free pool. | |
6336 | * | |
6337 | * Return: Pointer to the newly allocated completion-queue event if successful | |
6338 | * NULL otherwise. | |
6339 | **/ | |
6340 | struct lpfc_cq_event * | |
6341 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
6342 | { | |
6343 | struct lpfc_cq_event *cq_event = NULL; | |
6344 | ||
6345 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, | |
6346 | struct lpfc_cq_event, list); | |
6347 | return cq_event; | |
6348 | } | |
6349 | ||
6350 | /** | |
6351 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
6352 | * @phba: pointer to lpfc hba data structure. | |
6353 | * | |
6354 | * This routine is the lock version of the API invoked to allocate a | |
6355 | * completion-queue event from the free pool. | |
6356 | * | |
6357 | * Return: Pointer to the newly allocated completion-queue event if successful | |
6358 | * NULL otherwise. | |
6359 | **/ | |
6360 | struct lpfc_cq_event * | |
6361 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
6362 | { | |
6363 | struct lpfc_cq_event *cq_event; | |
6364 | unsigned long iflags; | |
6365 | ||
6366 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6367 | cq_event = __lpfc_sli4_cq_event_alloc(phba); | |
6368 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6369 | return cq_event; | |
6370 | } | |
6371 | ||
6372 | /** | |
6373 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
6374 | * @phba: pointer to lpfc hba data structure. | |
6375 | * @cq_event: pointer to the completion queue event to be freed. | |
6376 | * | |
6377 | * This routine is the lock free version of the API invoked to release a | |
6378 | * completion-queue event back into the free pool. | |
6379 | **/ | |
6380 | void | |
6381 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
6382 | struct lpfc_cq_event *cq_event) | |
6383 | { | |
6384 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); | |
6385 | } | |
6386 | ||
6387 | /** | |
6388 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
6389 | * @phba: pointer to lpfc hba data structure. | |
6390 | * @cq_event: pointer to the completion queue event to be freed. | |
6391 | * | |
6392 | * This routine is the lock version of the API invoked to release a | |
6393 | * completion-queue event back into the free pool. | |
6394 | **/ | |
6395 | void | |
6396 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
6397 | struct lpfc_cq_event *cq_event) | |
6398 | { | |
6399 | unsigned long iflags; | |
6400 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6401 | __lpfc_sli4_cq_event_release(phba, cq_event); | |
6402 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6403 | } | |
6404 | ||
6405 | /** | |
6406 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool | |
6407 | * @phba: pointer to lpfc hba data structure. | |
6408 | * | |
6409 | * This routine is to free all the pending completion-queue events to the | |
6410 | * back into the free pool for device reset. | |
6411 | **/ | |
6412 | static void | |
6413 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) | |
6414 | { | |
6415 | LIST_HEAD(cqelist); | |
6416 | struct lpfc_cq_event *cqe; | |
6417 | unsigned long iflags; | |
6418 | ||
6419 | /* Retrieve all the pending WCQEs from pending WCQE lists */ | |
6420 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6421 | /* Pending FCP XRI abort events */ | |
6422 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
6423 | &cqelist); | |
6424 | /* Pending ELS XRI abort events */ | |
6425 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
6426 | &cqelist); | |
6427 | /* Pending asynnc events */ | |
6428 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, | |
6429 | &cqelist); | |
6430 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6431 | ||
6432 | while (!list_empty(&cqelist)) { | |
6433 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); | |
6434 | lpfc_sli4_cq_event_release(phba, cqe); | |
6435 | } | |
6436 | } | |
6437 | ||
6438 | /** | |
6439 | * lpfc_pci_function_reset - Reset pci function. | |
6440 | * @phba: pointer to lpfc hba data structure. | |
6441 | * | |
6442 | * This routine is invoked to request a PCI function reset. It will destroys | |
6443 | * all resources assigned to the PCI function which originates this request. | |
6444 | * | |
6445 | * Return codes | |
af901ca1 | 6446 | * 0 - successful |
da0436e9 JS |
6447 | * ENOMEM - No availble memory |
6448 | * EIO - The mailbox failed to complete successfully. | |
6449 | **/ | |
6450 | int | |
6451 | lpfc_pci_function_reset(struct lpfc_hba *phba) | |
6452 | { | |
6453 | LPFC_MBOXQ_t *mboxq; | |
6454 | uint32_t rc = 0; | |
6455 | uint32_t shdr_status, shdr_add_status; | |
6456 | union lpfc_sli4_cfg_shdr *shdr; | |
6457 | ||
6458 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6459 | if (!mboxq) { | |
6460 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6461 | "0494 Unable to allocate memory for issuing " | |
6462 | "SLI_FUNCTION_RESET mailbox command\n"); | |
6463 | return -ENOMEM; | |
6464 | } | |
6465 | ||
6466 | /* Set up PCI function reset SLI4_CONFIG mailbox-ioctl command */ | |
6467 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
6468 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, | |
6469 | LPFC_SLI4_MBX_EMBED); | |
6470 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6471 | shdr = (union lpfc_sli4_cfg_shdr *) | |
6472 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
6473 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
6474 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
6475 | if (rc != MBX_TIMEOUT) | |
6476 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6477 | if (shdr_status || shdr_add_status || rc) { | |
6478 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6479 | "0495 SLI_FUNCTION_RESET mailbox failed with " | |
6480 | "status x%x add_status x%x, mbx status x%x\n", | |
6481 | shdr_status, shdr_add_status, rc); | |
6482 | rc = -ENXIO; | |
6483 | } | |
6484 | return rc; | |
6485 | } | |
6486 | ||
6487 | /** | |
6488 | * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands | |
6489 | * @phba: pointer to lpfc hba data structure. | |
6490 | * @cnt: number of nop mailbox commands to send. | |
6491 | * | |
6492 | * This routine is invoked to send a number @cnt of NOP mailbox command and | |
6493 | * wait for each command to complete. | |
6494 | * | |
6495 | * Return: the number of NOP mailbox command completed. | |
6496 | **/ | |
6497 | static int | |
6498 | lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt) | |
6499 | { | |
6500 | LPFC_MBOXQ_t *mboxq; | |
6501 | int length, cmdsent; | |
6502 | uint32_t mbox_tmo; | |
6503 | uint32_t rc = 0; | |
6504 | uint32_t shdr_status, shdr_add_status; | |
6505 | union lpfc_sli4_cfg_shdr *shdr; | |
6506 | ||
6507 | if (cnt == 0) { | |
6508 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6509 | "2518 Requested to send 0 NOP mailbox cmd\n"); | |
6510 | return cnt; | |
6511 | } | |
6512 | ||
6513 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6514 | if (!mboxq) { | |
6515 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6516 | "2519 Unable to allocate memory for issuing " | |
6517 | "NOP mailbox command\n"); | |
6518 | return 0; | |
6519 | } | |
6520 | ||
6521 | /* Set up NOP SLI4_CONFIG mailbox-ioctl command */ | |
6522 | length = (sizeof(struct lpfc_mbx_nop) - | |
6523 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
6524 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
6525 | LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED); | |
6526 | ||
6527 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
6528 | for (cmdsent = 0; cmdsent < cnt; cmdsent++) { | |
6529 | if (!phba->sli4_hba.intr_enable) | |
6530 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6531 | else | |
6532 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
6533 | if (rc == MBX_TIMEOUT) | |
6534 | break; | |
6535 | /* Check return status */ | |
6536 | shdr = (union lpfc_sli4_cfg_shdr *) | |
6537 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
6538 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
6539 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
6540 | &shdr->response); | |
6541 | if (shdr_status || shdr_add_status || rc) { | |
6542 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6543 | "2520 NOP mailbox command failed " | |
6544 | "status x%x add_status x%x mbx " | |
6545 | "status x%x\n", shdr_status, | |
6546 | shdr_add_status, rc); | |
6547 | break; | |
6548 | } | |
6549 | } | |
6550 | ||
6551 | if (rc != MBX_TIMEOUT) | |
6552 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6553 | ||
6554 | return cmdsent; | |
6555 | } | |
6556 | ||
6557 | /** | |
6558 | * lpfc_sli4_fcfi_unreg - Unregister fcfi to device | |
6559 | * @phba: pointer to lpfc hba data structure. | |
6560 | * @fcfi: fcf index. | |
6561 | * | |
6562 | * This routine is invoked to unregister a FCFI from device. | |
6563 | **/ | |
6564 | void | |
6565 | lpfc_sli4_fcfi_unreg(struct lpfc_hba *phba, uint16_t fcfi) | |
6566 | { | |
6567 | LPFC_MBOXQ_t *mbox; | |
6568 | uint32_t mbox_tmo; | |
6569 | int rc; | |
6570 | unsigned long flags; | |
6571 | ||
6572 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6573 | ||
6574 | if (!mbox) | |
6575 | return; | |
6576 | ||
6577 | lpfc_unreg_fcfi(mbox, fcfi); | |
6578 | ||
6579 | if (!phba->sli4_hba.intr_enable) | |
6580 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL); | |
6581 | else { | |
6582 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
6583 | rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo); | |
6584 | } | |
6585 | if (rc != MBX_TIMEOUT) | |
6586 | mempool_free(mbox, phba->mbox_mem_pool); | |
6587 | if (rc != MBX_SUCCESS) | |
6588 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6589 | "2517 Unregister FCFI command failed " | |
6590 | "status %d, mbxStatus x%x\n", rc, | |
6591 | bf_get(lpfc_mqe_status, &mbox->u.mqe)); | |
6592 | else { | |
6593 | spin_lock_irqsave(&phba->hbalock, flags); | |
6594 | /* Mark the FCFI is no longer registered */ | |
6595 | phba->fcf.fcf_flag &= | |
ecfd03c6 | 6596 | ~(FCF_AVAILABLE | FCF_REGISTERED | FCF_SCAN_DONE); |
da0436e9 JS |
6597 | spin_unlock_irqrestore(&phba->hbalock, flags); |
6598 | } | |
6599 | } | |
6600 | ||
6601 | /** | |
6602 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. | |
6603 | * @phba: pointer to lpfc hba data structure. | |
6604 | * | |
6605 | * This routine is invoked to set up the PCI device memory space for device | |
6606 | * with SLI-4 interface spec. | |
6607 | * | |
6608 | * Return codes | |
af901ca1 | 6609 | * 0 - successful |
da0436e9 JS |
6610 | * other values - error |
6611 | **/ | |
6612 | static int | |
6613 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) | |
6614 | { | |
6615 | struct pci_dev *pdev; | |
6616 | unsigned long bar0map_len, bar1map_len, bar2map_len; | |
6617 | int error = -ENODEV; | |
6618 | ||
6619 | /* Obtain PCI device reference */ | |
6620 | if (!phba->pcidev) | |
6621 | return error; | |
6622 | else | |
6623 | pdev = phba->pcidev; | |
6624 | ||
6625 | /* Set the device DMA mask size */ | |
8e68597d MR |
6626 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
6627 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
6628 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
6629 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
da0436e9 | 6630 | return error; |
8e68597d MR |
6631 | } |
6632 | } | |
da0436e9 JS |
6633 | |
6634 | /* Get the bus address of SLI4 device Bar0, Bar1, and Bar2 and the | |
6635 | * number of bytes required by each mapping. They are actually | |
1dfb5a47 | 6636 | * mapping to the PCI BAR regions 0 or 1, 2, and 4 by the SLI4 device. |
da0436e9 | 6637 | */ |
1dfb5a47 JS |
6638 | if (pci_resource_start(pdev, 0)) { |
6639 | phba->pci_bar0_map = pci_resource_start(pdev, 0); | |
6640 | bar0map_len = pci_resource_len(pdev, 0); | |
6641 | } else { | |
6642 | phba->pci_bar0_map = pci_resource_start(pdev, 1); | |
6643 | bar0map_len = pci_resource_len(pdev, 1); | |
6644 | } | |
6645 | phba->pci_bar1_map = pci_resource_start(pdev, 2); | |
6646 | bar1map_len = pci_resource_len(pdev, 2); | |
da0436e9 | 6647 | |
1dfb5a47 JS |
6648 | phba->pci_bar2_map = pci_resource_start(pdev, 4); |
6649 | bar2map_len = pci_resource_len(pdev, 4); | |
da0436e9 JS |
6650 | |
6651 | /* Map SLI4 PCI Config Space Register base to a kernel virtual addr */ | |
6652 | phba->sli4_hba.conf_regs_memmap_p = | |
6653 | ioremap(phba->pci_bar0_map, bar0map_len); | |
6654 | if (!phba->sli4_hba.conf_regs_memmap_p) { | |
6655 | dev_printk(KERN_ERR, &pdev->dev, | |
6656 | "ioremap failed for SLI4 PCI config registers.\n"); | |
6657 | goto out; | |
6658 | } | |
6659 | ||
6660 | /* Map SLI4 HBA Control Register base to a kernel virtual address. */ | |
6661 | phba->sli4_hba.ctrl_regs_memmap_p = | |
6662 | ioremap(phba->pci_bar1_map, bar1map_len); | |
6663 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { | |
6664 | dev_printk(KERN_ERR, &pdev->dev, | |
6665 | "ioremap failed for SLI4 HBA control registers.\n"); | |
6666 | goto out_iounmap_conf; | |
6667 | } | |
6668 | ||
6669 | /* Map SLI4 HBA Doorbell Register base to a kernel virtual address. */ | |
6670 | phba->sli4_hba.drbl_regs_memmap_p = | |
6671 | ioremap(phba->pci_bar2_map, bar2map_len); | |
6672 | if (!phba->sli4_hba.drbl_regs_memmap_p) { | |
6673 | dev_printk(KERN_ERR, &pdev->dev, | |
6674 | "ioremap failed for SLI4 HBA doorbell registers.\n"); | |
6675 | goto out_iounmap_ctrl; | |
6676 | } | |
6677 | ||
6678 | /* Set up BAR0 PCI config space register memory map */ | |
6679 | lpfc_sli4_bar0_register_memmap(phba); | |
6680 | ||
6681 | /* Set up BAR1 register memory map */ | |
6682 | lpfc_sli4_bar1_register_memmap(phba); | |
6683 | ||
6684 | /* Set up BAR2 register memory map */ | |
6685 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); | |
6686 | if (error) | |
6687 | goto out_iounmap_all; | |
6688 | ||
6689 | return 0; | |
6690 | ||
6691 | out_iounmap_all: | |
6692 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
6693 | out_iounmap_ctrl: | |
6694 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
6695 | out_iounmap_conf: | |
6696 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
6697 | out: | |
6698 | return error; | |
6699 | } | |
6700 | ||
6701 | /** | |
6702 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. | |
6703 | * @phba: pointer to lpfc hba data structure. | |
6704 | * | |
6705 | * This routine is invoked to unset the PCI device memory space for device | |
6706 | * with SLI-4 interface spec. | |
6707 | **/ | |
6708 | static void | |
6709 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) | |
6710 | { | |
6711 | struct pci_dev *pdev; | |
6712 | ||
6713 | /* Obtain PCI device reference */ | |
6714 | if (!phba->pcidev) | |
6715 | return; | |
6716 | else | |
6717 | pdev = phba->pcidev; | |
6718 | ||
6719 | /* Free coherent DMA memory allocated */ | |
6720 | ||
6721 | /* Unmap I/O memory space */ | |
6722 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
6723 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
6724 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
6725 | ||
6726 | return; | |
6727 | } | |
6728 | ||
6729 | /** | |
6730 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device | |
6731 | * @phba: pointer to lpfc hba data structure. | |
6732 | * | |
6733 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
6734 | * with SLI-3 interface specs. The kernel function pci_enable_msix() is | |
6735 | * called to enable the MSI-X vectors. Note that pci_enable_msix(), once | |
6736 | * invoked, enables either all or nothing, depending on the current | |
6737 | * availability of PCI vector resources. The device driver is responsible | |
6738 | * for calling the individual request_irq() to register each MSI-X vector | |
6739 | * with a interrupt handler, which is done in this function. Note that | |
6740 | * later when device is unloading, the driver should always call free_irq() | |
6741 | * on all MSI-X vectors it has done request_irq() on before calling | |
6742 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device | |
6743 | * will be left with MSI-X enabled and leaks its vectors. | |
6744 | * | |
6745 | * Return codes | |
af901ca1 | 6746 | * 0 - successful |
da0436e9 JS |
6747 | * other values - error |
6748 | **/ | |
6749 | static int | |
6750 | lpfc_sli_enable_msix(struct lpfc_hba *phba) | |
6751 | { | |
6752 | int rc, i; | |
6753 | LPFC_MBOXQ_t *pmb; | |
6754 | ||
6755 | /* Set up MSI-X multi-message vectors */ | |
6756 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
6757 | phba->msix_entries[i].entry = i; | |
6758 | ||
6759 | /* Configure MSI-X capability structure */ | |
6760 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, | |
6761 | ARRAY_SIZE(phba->msix_entries)); | |
6762 | if (rc) { | |
6763 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6764 | "0420 PCI enable MSI-X failed (%d)\n", rc); | |
6765 | goto msi_fail_out; | |
6766 | } | |
6767 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
6768 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6769 | "0477 MSI-X entry[%d]: vector=x%x " | |
6770 | "message=%d\n", i, | |
6771 | phba->msix_entries[i].vector, | |
6772 | phba->msix_entries[i].entry); | |
6773 | /* | |
6774 | * Assign MSI-X vectors to interrupt handlers | |
6775 | */ | |
6776 | ||
6777 | /* vector-0 is associated to slow-path handler */ | |
6778 | rc = request_irq(phba->msix_entries[0].vector, | |
6779 | &lpfc_sli_sp_intr_handler, IRQF_SHARED, | |
6780 | LPFC_SP_DRIVER_HANDLER_NAME, phba); | |
6781 | if (rc) { | |
6782 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6783 | "0421 MSI-X slow-path request_irq failed " | |
6784 | "(%d)\n", rc); | |
6785 | goto msi_fail_out; | |
6786 | } | |
6787 | ||
6788 | /* vector-1 is associated to fast-path handler */ | |
6789 | rc = request_irq(phba->msix_entries[1].vector, | |
6790 | &lpfc_sli_fp_intr_handler, IRQF_SHARED, | |
6791 | LPFC_FP_DRIVER_HANDLER_NAME, phba); | |
6792 | ||
6793 | if (rc) { | |
6794 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6795 | "0429 MSI-X fast-path request_irq failed " | |
6796 | "(%d)\n", rc); | |
6797 | goto irq_fail_out; | |
6798 | } | |
6799 | ||
6800 | /* | |
6801 | * Configure HBA MSI-X attention conditions to messages | |
6802 | */ | |
6803 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6804 | ||
6805 | if (!pmb) { | |
6806 | rc = -ENOMEM; | |
6807 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6808 | "0474 Unable to allocate memory for issuing " | |
6809 | "MBOX_CONFIG_MSI command\n"); | |
6810 | goto mem_fail_out; | |
6811 | } | |
6812 | rc = lpfc_config_msi(phba, pmb); | |
6813 | if (rc) | |
6814 | goto mbx_fail_out; | |
6815 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
6816 | if (rc != MBX_SUCCESS) { | |
6817 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | |
6818 | "0351 Config MSI mailbox command failed, " | |
6819 | "mbxCmd x%x, mbxStatus x%x\n", | |
6820 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); | |
6821 | goto mbx_fail_out; | |
6822 | } | |
6823 | ||
6824 | /* Free memory allocated for mailbox command */ | |
6825 | mempool_free(pmb, phba->mbox_mem_pool); | |
6826 | return rc; | |
6827 | ||
6828 | mbx_fail_out: | |
6829 | /* Free memory allocated for mailbox command */ | |
6830 | mempool_free(pmb, phba->mbox_mem_pool); | |
6831 | ||
6832 | mem_fail_out: | |
6833 | /* free the irq already requested */ | |
6834 | free_irq(phba->msix_entries[1].vector, phba); | |
6835 | ||
6836 | irq_fail_out: | |
6837 | /* free the irq already requested */ | |
6838 | free_irq(phba->msix_entries[0].vector, phba); | |
6839 | ||
6840 | msi_fail_out: | |
6841 | /* Unconfigure MSI-X capability structure */ | |
6842 | pci_disable_msix(phba->pcidev); | |
6843 | return rc; | |
6844 | } | |
6845 | ||
6846 | /** | |
6847 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. | |
6848 | * @phba: pointer to lpfc hba data structure. | |
6849 | * | |
6850 | * This routine is invoked to release the MSI-X vectors and then disable the | |
6851 | * MSI-X interrupt mode to device with SLI-3 interface spec. | |
6852 | **/ | |
6853 | static void | |
6854 | lpfc_sli_disable_msix(struct lpfc_hba *phba) | |
6855 | { | |
6856 | int i; | |
6857 | ||
6858 | /* Free up MSI-X multi-message vectors */ | |
6859 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
6860 | free_irq(phba->msix_entries[i].vector, phba); | |
6861 | /* Disable MSI-X */ | |
6862 | pci_disable_msix(phba->pcidev); | |
6863 | ||
6864 | return; | |
6865 | } | |
6866 | ||
6867 | /** | |
6868 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. | |
6869 | * @phba: pointer to lpfc hba data structure. | |
6870 | * | |
6871 | * This routine is invoked to enable the MSI interrupt mode to device with | |
6872 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to | |
6873 | * enable the MSI vector. The device driver is responsible for calling the | |
6874 | * request_irq() to register MSI vector with a interrupt the handler, which | |
6875 | * is done in this function. | |
6876 | * | |
6877 | * Return codes | |
af901ca1 | 6878 | * 0 - successful |
da0436e9 JS |
6879 | * other values - error |
6880 | */ | |
6881 | static int | |
6882 | lpfc_sli_enable_msi(struct lpfc_hba *phba) | |
6883 | { | |
6884 | int rc; | |
6885 | ||
6886 | rc = pci_enable_msi(phba->pcidev); | |
6887 | if (!rc) | |
6888 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6889 | "0462 PCI enable MSI mode success.\n"); | |
6890 | else { | |
6891 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6892 | "0471 PCI enable MSI mode failed (%d)\n", rc); | |
6893 | return rc; | |
6894 | } | |
6895 | ||
6896 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
6897 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
6898 | if (rc) { | |
6899 | pci_disable_msi(phba->pcidev); | |
6900 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6901 | "0478 MSI request_irq failed (%d)\n", rc); | |
6902 | } | |
6903 | return rc; | |
6904 | } | |
6905 | ||
6906 | /** | |
6907 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. | |
6908 | * @phba: pointer to lpfc hba data structure. | |
6909 | * | |
6910 | * This routine is invoked to disable the MSI interrupt mode to device with | |
6911 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has | |
6912 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | |
6913 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | |
6914 | * its vector. | |
6915 | */ | |
6916 | static void | |
6917 | lpfc_sli_disable_msi(struct lpfc_hba *phba) | |
6918 | { | |
6919 | free_irq(phba->pcidev->irq, phba); | |
6920 | pci_disable_msi(phba->pcidev); | |
6921 | return; | |
6922 | } | |
6923 | ||
6924 | /** | |
6925 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. | |
6926 | * @phba: pointer to lpfc hba data structure. | |
6927 | * | |
6928 | * This routine is invoked to enable device interrupt and associate driver's | |
6929 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface | |
6930 | * spec. Depends on the interrupt mode configured to the driver, the driver | |
6931 | * will try to fallback from the configured interrupt mode to an interrupt | |
6932 | * mode which is supported by the platform, kernel, and device in the order | |
6933 | * of: | |
6934 | * MSI-X -> MSI -> IRQ. | |
6935 | * | |
6936 | * Return codes | |
af901ca1 | 6937 | * 0 - successful |
da0436e9 JS |
6938 | * other values - error |
6939 | **/ | |
6940 | static uint32_t | |
6941 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
6942 | { | |
6943 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
6944 | int retval; | |
6945 | ||
6946 | if (cfg_mode == 2) { | |
6947 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ | |
6948 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); | |
6949 | if (!retval) { | |
6950 | /* Now, try to enable MSI-X interrupt mode */ | |
6951 | retval = lpfc_sli_enable_msix(phba); | |
6952 | if (!retval) { | |
6953 | /* Indicate initialization to MSI-X mode */ | |
6954 | phba->intr_type = MSIX; | |
6955 | intr_mode = 2; | |
6956 | } | |
6957 | } | |
6958 | } | |
6959 | ||
6960 | /* Fallback to MSI if MSI-X initialization failed */ | |
6961 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
6962 | retval = lpfc_sli_enable_msi(phba); | |
6963 | if (!retval) { | |
6964 | /* Indicate initialization to MSI mode */ | |
6965 | phba->intr_type = MSI; | |
6966 | intr_mode = 1; | |
6967 | } | |
6968 | } | |
6969 | ||
6970 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
6971 | if (phba->intr_type == NONE) { | |
6972 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
6973 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
6974 | if (!retval) { | |
6975 | /* Indicate initialization to INTx mode */ | |
6976 | phba->intr_type = INTx; | |
6977 | intr_mode = 0; | |
6978 | } | |
6979 | } | |
6980 | return intr_mode; | |
6981 | } | |
6982 | ||
6983 | /** | |
6984 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. | |
6985 | * @phba: pointer to lpfc hba data structure. | |
6986 | * | |
6987 | * This routine is invoked to disable device interrupt and disassociate the | |
6988 | * driver's interrupt handler(s) from interrupt vector(s) to device with | |
6989 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will | |
6990 | * release the interrupt vector(s) for the message signaled interrupt. | |
6991 | **/ | |
6992 | static void | |
6993 | lpfc_sli_disable_intr(struct lpfc_hba *phba) | |
6994 | { | |
6995 | /* Disable the currently initialized interrupt mode */ | |
6996 | if (phba->intr_type == MSIX) | |
6997 | lpfc_sli_disable_msix(phba); | |
6998 | else if (phba->intr_type == MSI) | |
6999 | lpfc_sli_disable_msi(phba); | |
7000 | else if (phba->intr_type == INTx) | |
7001 | free_irq(phba->pcidev->irq, phba); | |
7002 | ||
7003 | /* Reset interrupt management states */ | |
7004 | phba->intr_type = NONE; | |
7005 | phba->sli.slistat.sli_intr = 0; | |
7006 | ||
7007 | return; | |
7008 | } | |
7009 | ||
7010 | /** | |
7011 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device | |
7012 | * @phba: pointer to lpfc hba data structure. | |
7013 | * | |
7014 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
7015 | * with SLI-4 interface spec. The kernel function pci_enable_msix() is called | |
7016 | * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked, | |
7017 | * enables either all or nothing, depending on the current availability of | |
7018 | * PCI vector resources. The device driver is responsible for calling the | |
7019 | * individual request_irq() to register each MSI-X vector with a interrupt | |
7020 | * handler, which is done in this function. Note that later when device is | |
7021 | * unloading, the driver should always call free_irq() on all MSI-X vectors | |
7022 | * it has done request_irq() on before calling pci_disable_msix(). Failure | |
7023 | * to do so results in a BUG_ON() and a device will be left with MSI-X | |
7024 | * enabled and leaks its vectors. | |
7025 | * | |
7026 | * Return codes | |
af901ca1 | 7027 | * 0 - successful |
da0436e9 JS |
7028 | * other values - error |
7029 | **/ | |
7030 | static int | |
7031 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) | |
7032 | { | |
75baf696 | 7033 | int vectors, rc, index; |
da0436e9 JS |
7034 | |
7035 | /* Set up MSI-X multi-message vectors */ | |
7036 | for (index = 0; index < phba->sli4_hba.cfg_eqn; index++) | |
7037 | phba->sli4_hba.msix_entries[index].entry = index; | |
7038 | ||
7039 | /* Configure MSI-X capability structure */ | |
75baf696 JS |
7040 | vectors = phba->sli4_hba.cfg_eqn; |
7041 | enable_msix_vectors: | |
da0436e9 | 7042 | rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries, |
75baf696 JS |
7043 | vectors); |
7044 | if (rc > 1) { | |
7045 | vectors = rc; | |
7046 | goto enable_msix_vectors; | |
7047 | } else if (rc) { | |
da0436e9 JS |
7048 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
7049 | "0484 PCI enable MSI-X failed (%d)\n", rc); | |
7050 | goto msi_fail_out; | |
7051 | } | |
75baf696 | 7052 | |
da0436e9 | 7053 | /* Log MSI-X vector assignment */ |
75baf696 | 7054 | for (index = 0; index < vectors; index++) |
da0436e9 JS |
7055 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
7056 | "0489 MSI-X entry[%d]: vector=x%x " | |
7057 | "message=%d\n", index, | |
7058 | phba->sli4_hba.msix_entries[index].vector, | |
7059 | phba->sli4_hba.msix_entries[index].entry); | |
7060 | /* | |
7061 | * Assign MSI-X vectors to interrupt handlers | |
7062 | */ | |
7063 | ||
7064 | /* The first vector must associated to slow-path handler for MQ */ | |
7065 | rc = request_irq(phba->sli4_hba.msix_entries[0].vector, | |
7066 | &lpfc_sli4_sp_intr_handler, IRQF_SHARED, | |
7067 | LPFC_SP_DRIVER_HANDLER_NAME, phba); | |
7068 | if (rc) { | |
7069 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7070 | "0485 MSI-X slow-path request_irq failed " | |
7071 | "(%d)\n", rc); | |
7072 | goto msi_fail_out; | |
7073 | } | |
7074 | ||
7075 | /* The rest of the vector(s) are associated to fast-path handler(s) */ | |
75baf696 | 7076 | for (index = 1; index < vectors; index++) { |
da0436e9 JS |
7077 | phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1; |
7078 | phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba; | |
7079 | rc = request_irq(phba->sli4_hba.msix_entries[index].vector, | |
7080 | &lpfc_sli4_fp_intr_handler, IRQF_SHARED, | |
7081 | LPFC_FP_DRIVER_HANDLER_NAME, | |
7082 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
7083 | if (rc) { | |
7084 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7085 | "0486 MSI-X fast-path (%d) " | |
7086 | "request_irq failed (%d)\n", index, rc); | |
7087 | goto cfg_fail_out; | |
7088 | } | |
7089 | } | |
75baf696 | 7090 | phba->sli4_hba.msix_vec_nr = vectors; |
da0436e9 JS |
7091 | |
7092 | return rc; | |
7093 | ||
7094 | cfg_fail_out: | |
7095 | /* free the irq already requested */ | |
7096 | for (--index; index >= 1; index--) | |
7097 | free_irq(phba->sli4_hba.msix_entries[index - 1].vector, | |
7098 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
7099 | ||
7100 | /* free the irq already requested */ | |
7101 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); | |
7102 | ||
7103 | msi_fail_out: | |
7104 | /* Unconfigure MSI-X capability structure */ | |
7105 | pci_disable_msix(phba->pcidev); | |
7106 | return rc; | |
7107 | } | |
7108 | ||
7109 | /** | |
7110 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device | |
7111 | * @phba: pointer to lpfc hba data structure. | |
7112 | * | |
7113 | * This routine is invoked to release the MSI-X vectors and then disable the | |
7114 | * MSI-X interrupt mode to device with SLI-4 interface spec. | |
7115 | **/ | |
7116 | static void | |
7117 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) | |
7118 | { | |
7119 | int index; | |
7120 | ||
7121 | /* Free up MSI-X multi-message vectors */ | |
7122 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); | |
7123 | ||
75baf696 | 7124 | for (index = 1; index < phba->sli4_hba.msix_vec_nr; index++) |
da0436e9 JS |
7125 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
7126 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
75baf696 | 7127 | |
da0436e9 JS |
7128 | /* Disable MSI-X */ |
7129 | pci_disable_msix(phba->pcidev); | |
7130 | ||
7131 | return; | |
7132 | } | |
7133 | ||
7134 | /** | |
7135 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device | |
7136 | * @phba: pointer to lpfc hba data structure. | |
7137 | * | |
7138 | * This routine is invoked to enable the MSI interrupt mode to device with | |
7139 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called | |
7140 | * to enable the MSI vector. The device driver is responsible for calling | |
7141 | * the request_irq() to register MSI vector with a interrupt the handler, | |
7142 | * which is done in this function. | |
7143 | * | |
7144 | * Return codes | |
af901ca1 | 7145 | * 0 - successful |
da0436e9 JS |
7146 | * other values - error |
7147 | **/ | |
7148 | static int | |
7149 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) | |
7150 | { | |
7151 | int rc, index; | |
7152 | ||
7153 | rc = pci_enable_msi(phba->pcidev); | |
7154 | if (!rc) | |
7155 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7156 | "0487 PCI enable MSI mode success.\n"); | |
7157 | else { | |
7158 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7159 | "0488 PCI enable MSI mode failed (%d)\n", rc); | |
7160 | return rc; | |
7161 | } | |
7162 | ||
7163 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
7164 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
7165 | if (rc) { | |
7166 | pci_disable_msi(phba->pcidev); | |
7167 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7168 | "0490 MSI request_irq failed (%d)\n", rc); | |
75baf696 | 7169 | return rc; |
da0436e9 JS |
7170 | } |
7171 | ||
7172 | for (index = 0; index < phba->cfg_fcp_eq_count; index++) { | |
7173 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | |
7174 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
7175 | } | |
7176 | ||
75baf696 | 7177 | return 0; |
da0436e9 JS |
7178 | } |
7179 | ||
7180 | /** | |
7181 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device | |
7182 | * @phba: pointer to lpfc hba data structure. | |
7183 | * | |
7184 | * This routine is invoked to disable the MSI interrupt mode to device with | |
7185 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has | |
7186 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | |
7187 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | |
7188 | * its vector. | |
7189 | **/ | |
7190 | static void | |
7191 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) | |
7192 | { | |
7193 | free_irq(phba->pcidev->irq, phba); | |
7194 | pci_disable_msi(phba->pcidev); | |
7195 | return; | |
7196 | } | |
7197 | ||
7198 | /** | |
7199 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device | |
7200 | * @phba: pointer to lpfc hba data structure. | |
7201 | * | |
7202 | * This routine is invoked to enable device interrupt and associate driver's | |
7203 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 | |
7204 | * interface spec. Depends on the interrupt mode configured to the driver, | |
7205 | * the driver will try to fallback from the configured interrupt mode to an | |
7206 | * interrupt mode which is supported by the platform, kernel, and device in | |
7207 | * the order of: | |
7208 | * MSI-X -> MSI -> IRQ. | |
7209 | * | |
7210 | * Return codes | |
af901ca1 | 7211 | * 0 - successful |
da0436e9 JS |
7212 | * other values - error |
7213 | **/ | |
7214 | static uint32_t | |
7215 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
7216 | { | |
7217 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
7218 | int retval, index; | |
7219 | ||
7220 | if (cfg_mode == 2) { | |
7221 | /* Preparation before conf_msi mbox cmd */ | |
7222 | retval = 0; | |
7223 | if (!retval) { | |
7224 | /* Now, try to enable MSI-X interrupt mode */ | |
7225 | retval = lpfc_sli4_enable_msix(phba); | |
7226 | if (!retval) { | |
7227 | /* Indicate initialization to MSI-X mode */ | |
7228 | phba->intr_type = MSIX; | |
7229 | intr_mode = 2; | |
7230 | } | |
7231 | } | |
7232 | } | |
7233 | ||
7234 | /* Fallback to MSI if MSI-X initialization failed */ | |
7235 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
7236 | retval = lpfc_sli4_enable_msi(phba); | |
7237 | if (!retval) { | |
7238 | /* Indicate initialization to MSI mode */ | |
7239 | phba->intr_type = MSI; | |
7240 | intr_mode = 1; | |
7241 | } | |
7242 | } | |
7243 | ||
7244 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
7245 | if (phba->intr_type == NONE) { | |
7246 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
7247 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
7248 | if (!retval) { | |
7249 | /* Indicate initialization to INTx mode */ | |
7250 | phba->intr_type = INTx; | |
7251 | intr_mode = 0; | |
7252 | for (index = 0; index < phba->cfg_fcp_eq_count; | |
7253 | index++) { | |
7254 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | |
7255 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
7256 | } | |
7257 | } | |
7258 | } | |
7259 | return intr_mode; | |
7260 | } | |
7261 | ||
7262 | /** | |
7263 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device | |
7264 | * @phba: pointer to lpfc hba data structure. | |
7265 | * | |
7266 | * This routine is invoked to disable device interrupt and disassociate | |
7267 | * the driver's interrupt handler(s) from interrupt vector(s) to device | |
7268 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver | |
7269 | * will release the interrupt vector(s) for the message signaled interrupt. | |
7270 | **/ | |
7271 | static void | |
7272 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) | |
7273 | { | |
7274 | /* Disable the currently initialized interrupt mode */ | |
7275 | if (phba->intr_type == MSIX) | |
7276 | lpfc_sli4_disable_msix(phba); | |
7277 | else if (phba->intr_type == MSI) | |
7278 | lpfc_sli4_disable_msi(phba); | |
7279 | else if (phba->intr_type == INTx) | |
7280 | free_irq(phba->pcidev->irq, phba); | |
7281 | ||
7282 | /* Reset interrupt management states */ | |
7283 | phba->intr_type = NONE; | |
7284 | phba->sli.slistat.sli_intr = 0; | |
7285 | ||
7286 | return; | |
7287 | } | |
7288 | ||
7289 | /** | |
7290 | * lpfc_unset_hba - Unset SLI3 hba device initialization | |
7291 | * @phba: pointer to lpfc hba data structure. | |
7292 | * | |
7293 | * This routine is invoked to unset the HBA device initialization steps to | |
7294 | * a device with SLI-3 interface spec. | |
7295 | **/ | |
7296 | static void | |
7297 | lpfc_unset_hba(struct lpfc_hba *phba) | |
7298 | { | |
7299 | struct lpfc_vport *vport = phba->pport; | |
7300 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
7301 | ||
7302 | spin_lock_irq(shost->host_lock); | |
7303 | vport->load_flag |= FC_UNLOADING; | |
7304 | spin_unlock_irq(shost->host_lock); | |
7305 | ||
7306 | lpfc_stop_hba_timers(phba); | |
7307 | ||
7308 | phba->pport->work_port_events = 0; | |
7309 | ||
7310 | lpfc_sli_hba_down(phba); | |
7311 | ||
7312 | lpfc_sli_brdrestart(phba); | |
7313 | ||
7314 | lpfc_sli_disable_intr(phba); | |
7315 | ||
7316 | return; | |
7317 | } | |
7318 | ||
7319 | /** | |
7320 | * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization. | |
7321 | * @phba: pointer to lpfc hba data structure. | |
7322 | * | |
7323 | * This routine is invoked to unset the HBA device initialization steps to | |
7324 | * a device with SLI-4 interface spec. | |
7325 | **/ | |
7326 | static void | |
7327 | lpfc_sli4_unset_hba(struct lpfc_hba *phba) | |
7328 | { | |
7329 | struct lpfc_vport *vport = phba->pport; | |
7330 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
7331 | ||
7332 | spin_lock_irq(shost->host_lock); | |
7333 | vport->load_flag |= FC_UNLOADING; | |
7334 | spin_unlock_irq(shost->host_lock); | |
7335 | ||
7336 | phba->pport->work_port_events = 0; | |
7337 | ||
7338 | lpfc_sli4_hba_down(phba); | |
7339 | ||
7340 | lpfc_sli4_disable_intr(phba); | |
7341 | ||
7342 | return; | |
7343 | } | |
7344 | ||
7345 | /** | |
7346 | * lpfc_sli4_hba_unset - Unset the fcoe hba | |
7347 | * @phba: Pointer to HBA context object. | |
7348 | * | |
7349 | * This function is called in the SLI4 code path to reset the HBA's FCoE | |
7350 | * function. The caller is not required to hold any lock. This routine | |
7351 | * issues PCI function reset mailbox command to reset the FCoE function. | |
7352 | * At the end of the function, it calls lpfc_hba_down_post function to | |
7353 | * free any pending commands. | |
7354 | **/ | |
7355 | static void | |
7356 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) | |
7357 | { | |
7358 | int wait_cnt = 0; | |
7359 | LPFC_MBOXQ_t *mboxq; | |
7360 | ||
7361 | lpfc_stop_hba_timers(phba); | |
7362 | phba->sli4_hba.intr_enable = 0; | |
7363 | ||
7364 | /* | |
7365 | * Gracefully wait out the potential current outstanding asynchronous | |
7366 | * mailbox command. | |
7367 | */ | |
7368 | ||
7369 | /* First, block any pending async mailbox command from posted */ | |
7370 | spin_lock_irq(&phba->hbalock); | |
7371 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
7372 | spin_unlock_irq(&phba->hbalock); | |
7373 | /* Now, trying to wait it out if we can */ | |
7374 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
7375 | msleep(10); | |
7376 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) | |
7377 | break; | |
7378 | } | |
7379 | /* Forcefully release the outstanding mailbox command if timed out */ | |
7380 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
7381 | spin_lock_irq(&phba->hbalock); | |
7382 | mboxq = phba->sli.mbox_active; | |
7383 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
7384 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
7385 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7386 | phba->sli.mbox_active = NULL; | |
7387 | spin_unlock_irq(&phba->hbalock); | |
7388 | } | |
7389 | ||
7390 | /* Tear down the queues in the HBA */ | |
7391 | lpfc_sli4_queue_unset(phba); | |
7392 | ||
7393 | /* Disable PCI subsystem interrupt */ | |
7394 | lpfc_sli4_disable_intr(phba); | |
7395 | ||
7396 | /* Stop kthread signal shall trigger work_done one more time */ | |
7397 | kthread_stop(phba->worker_thread); | |
7398 | ||
7399 | /* Stop the SLI4 device port */ | |
7400 | phba->pport->work_port_events = 0; | |
7401 | } | |
7402 | ||
28baac74 JS |
7403 | /** |
7404 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. | |
7405 | * @phba: Pointer to HBA context object. | |
7406 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. | |
7407 | * | |
7408 | * This function is called in the SLI4 code path to read the port's | |
7409 | * sli4 capabilities. | |
7410 | * | |
7411 | * This function may be be called from any context that can block-wait | |
7412 | * for the completion. The expectation is that this routine is called | |
7413 | * typically from probe_one or from the online routine. | |
7414 | **/ | |
7415 | int | |
7416 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
7417 | { | |
7418 | int rc; | |
7419 | struct lpfc_mqe *mqe; | |
7420 | struct lpfc_pc_sli4_params *sli4_params; | |
7421 | uint32_t mbox_tmo; | |
7422 | ||
7423 | rc = 0; | |
7424 | mqe = &mboxq->u.mqe; | |
7425 | ||
7426 | /* Read the port's SLI4 Parameters port capabilities */ | |
7427 | lpfc_sli4_params(mboxq); | |
7428 | if (!phba->sli4_hba.intr_enable) | |
7429 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7430 | else { | |
7431 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_PORT_CAPABILITIES); | |
7432 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
7433 | } | |
7434 | ||
7435 | if (unlikely(rc)) | |
7436 | return 1; | |
7437 | ||
7438 | sli4_params = &phba->sli4_hba.pc_sli4_params; | |
7439 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); | |
7440 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); | |
7441 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); | |
7442 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, | |
7443 | &mqe->un.sli4_params); | |
7444 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, | |
7445 | &mqe->un.sli4_params); | |
7446 | sli4_params->proto_types = mqe->un.sli4_params.word3; | |
7447 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; | |
7448 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); | |
7449 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); | |
7450 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); | |
7451 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); | |
7452 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); | |
7453 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); | |
7454 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); | |
7455 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); | |
7456 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); | |
7457 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); | |
7458 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); | |
7459 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); | |
7460 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); | |
7461 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); | |
7462 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); | |
7463 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); | |
7464 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); | |
7465 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); | |
7466 | sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params); | |
7467 | return rc; | |
7468 | } | |
7469 | ||
da0436e9 JS |
7470 | /** |
7471 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. | |
7472 | * @pdev: pointer to PCI device | |
7473 | * @pid: pointer to PCI device identifier | |
7474 | * | |
7475 | * This routine is to be called to attach a device with SLI-3 interface spec | |
7476 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
7477 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific | |
7478 | * information of the device and driver to see if the driver state that it can | |
7479 | * support this kind of device. If the match is successful, the driver core | |
7480 | * invokes this routine. If this routine determines it can claim the HBA, it | |
7481 | * does all the initialization that it needs to do to handle the HBA properly. | |
7482 | * | |
7483 | * Return code | |
7484 | * 0 - driver can claim the device | |
7485 | * negative value - driver can not claim the device | |
7486 | **/ | |
7487 | static int __devinit | |
7488 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) | |
7489 | { | |
7490 | struct lpfc_hba *phba; | |
7491 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 7492 | struct Scsi_Host *shost = NULL; |
da0436e9 JS |
7493 | int error; |
7494 | uint32_t cfg_mode, intr_mode; | |
7495 | ||
7496 | /* Allocate memory for HBA structure */ | |
7497 | phba = lpfc_hba_alloc(pdev); | |
7498 | if (!phba) | |
7499 | return -ENOMEM; | |
7500 | ||
7501 | /* Perform generic PCI device enabling operation */ | |
7502 | error = lpfc_enable_pci_dev(phba); | |
7503 | if (error) { | |
7504 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7505 | "1401 Failed to enable pci device.\n"); | |
7506 | goto out_free_phba; | |
7507 | } | |
7508 | ||
7509 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ | |
7510 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); | |
7511 | if (error) | |
7512 | goto out_disable_pci_dev; | |
7513 | ||
7514 | /* Set up SLI-3 specific device PCI memory space */ | |
7515 | error = lpfc_sli_pci_mem_setup(phba); | |
7516 | if (error) { | |
7517 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7518 | "1402 Failed to set up pci memory space.\n"); | |
7519 | goto out_disable_pci_dev; | |
7520 | } | |
7521 | ||
7522 | /* Set up phase-1 common device driver resources */ | |
7523 | error = lpfc_setup_driver_resource_phase1(phba); | |
7524 | if (error) { | |
7525 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7526 | "1403 Failed to set up driver resource.\n"); | |
7527 | goto out_unset_pci_mem_s3; | |
7528 | } | |
7529 | ||
7530 | /* Set up SLI-3 specific device driver resources */ | |
7531 | error = lpfc_sli_driver_resource_setup(phba); | |
7532 | if (error) { | |
7533 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7534 | "1404 Failed to set up driver resource.\n"); | |
7535 | goto out_unset_pci_mem_s3; | |
7536 | } | |
7537 | ||
7538 | /* Initialize and populate the iocb list per host */ | |
7539 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); | |
7540 | if (error) { | |
7541 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7542 | "1405 Failed to initialize iocb list.\n"); | |
7543 | goto out_unset_driver_resource_s3; | |
7544 | } | |
7545 | ||
7546 | /* Set up common device driver resources */ | |
7547 | error = lpfc_setup_driver_resource_phase2(phba); | |
7548 | if (error) { | |
7549 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7550 | "1406 Failed to set up driver resource.\n"); | |
7551 | goto out_free_iocb_list; | |
7552 | } | |
7553 | ||
7554 | /* Create SCSI host to the physical port */ | |
7555 | error = lpfc_create_shost(phba); | |
7556 | if (error) { | |
7557 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7558 | "1407 Failed to create scsi host.\n"); | |
7559 | goto out_unset_driver_resource; | |
7560 | } | |
7561 | ||
7562 | /* Configure sysfs attributes */ | |
7563 | vport = phba->pport; | |
7564 | error = lpfc_alloc_sysfs_attr(vport); | |
7565 | if (error) { | |
7566 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7567 | "1476 Failed to allocate sysfs attr\n"); | |
7568 | goto out_destroy_shost; | |
7569 | } | |
7570 | ||
6669f9bb | 7571 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
da0436e9 JS |
7572 | /* Now, trying to enable interrupt and bring up the device */ |
7573 | cfg_mode = phba->cfg_use_msi; | |
7574 | while (true) { | |
7575 | /* Put device to a known state before enabling interrupt */ | |
7576 | lpfc_stop_port(phba); | |
7577 | /* Configure and enable interrupt */ | |
7578 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); | |
7579 | if (intr_mode == LPFC_INTR_ERROR) { | |
7580 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7581 | "0431 Failed to enable interrupt.\n"); | |
7582 | error = -ENODEV; | |
7583 | goto out_free_sysfs_attr; | |
7584 | } | |
7585 | /* SLI-3 HBA setup */ | |
7586 | if (lpfc_sli_hba_setup(phba)) { | |
7587 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7588 | "1477 Failed to set up hba\n"); | |
7589 | error = -ENODEV; | |
7590 | goto out_remove_device; | |
7591 | } | |
7592 | ||
7593 | /* Wait 50ms for the interrupts of previous mailbox commands */ | |
7594 | msleep(50); | |
7595 | /* Check active interrupts on message signaled interrupts */ | |
7596 | if (intr_mode == 0 || | |
7597 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { | |
7598 | /* Log the current active interrupt mode */ | |
7599 | phba->intr_mode = intr_mode; | |
7600 | lpfc_log_intr_mode(phba, intr_mode); | |
7601 | break; | |
7602 | } else { | |
7603 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7604 | "0447 Configure interrupt mode (%d) " | |
7605 | "failed active interrupt test.\n", | |
7606 | intr_mode); | |
7607 | /* Disable the current interrupt mode */ | |
7608 | lpfc_sli_disable_intr(phba); | |
7609 | /* Try next level of interrupt mode */ | |
7610 | cfg_mode = --intr_mode; | |
7611 | } | |
7612 | } | |
7613 | ||
7614 | /* Perform post initialization setup */ | |
7615 | lpfc_post_init_setup(phba); | |
7616 | ||
7617 | /* Check if there are static vports to be created. */ | |
7618 | lpfc_create_static_vport(phba); | |
7619 | ||
7620 | return 0; | |
7621 | ||
7622 | out_remove_device: | |
7623 | lpfc_unset_hba(phba); | |
7624 | out_free_sysfs_attr: | |
7625 | lpfc_free_sysfs_attr(vport); | |
7626 | out_destroy_shost: | |
7627 | lpfc_destroy_shost(phba); | |
7628 | out_unset_driver_resource: | |
7629 | lpfc_unset_driver_resource_phase2(phba); | |
7630 | out_free_iocb_list: | |
7631 | lpfc_free_iocb_list(phba); | |
7632 | out_unset_driver_resource_s3: | |
7633 | lpfc_sli_driver_resource_unset(phba); | |
7634 | out_unset_pci_mem_s3: | |
7635 | lpfc_sli_pci_mem_unset(phba); | |
7636 | out_disable_pci_dev: | |
7637 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
7638 | if (shost) |
7639 | scsi_host_put(shost); | |
da0436e9 JS |
7640 | out_free_phba: |
7641 | lpfc_hba_free(phba); | |
7642 | return error; | |
7643 | } | |
7644 | ||
7645 | /** | |
7646 | * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem. | |
7647 | * @pdev: pointer to PCI device | |
7648 | * | |
7649 | * This routine is to be called to disattach a device with SLI-3 interface | |
7650 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
7651 | * removed from PCI bus, it performs all the necessary cleanup for the HBA | |
7652 | * device to be removed from the PCI subsystem properly. | |
7653 | **/ | |
7654 | static void __devexit | |
7655 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) | |
7656 | { | |
7657 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7658 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
7659 | struct lpfc_vport **vports; | |
7660 | struct lpfc_hba *phba = vport->phba; | |
7661 | int i; | |
7662 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
7663 | ||
7664 | spin_lock_irq(&phba->hbalock); | |
7665 | vport->load_flag |= FC_UNLOADING; | |
7666 | spin_unlock_irq(&phba->hbalock); | |
7667 | ||
7668 | lpfc_free_sysfs_attr(vport); | |
7669 | ||
7670 | /* Release all the vports against this physical port */ | |
7671 | vports = lpfc_create_vport_work_array(phba); | |
7672 | if (vports != NULL) | |
7673 | for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) | |
7674 | fc_vport_terminate(vports[i]->fc_vport); | |
7675 | lpfc_destroy_vport_work_array(phba, vports); | |
7676 | ||
7677 | /* Remove FC host and then SCSI host with the physical port */ | |
7678 | fc_remove_host(shost); | |
7679 | scsi_remove_host(shost); | |
7680 | lpfc_cleanup(vport); | |
7681 | ||
7682 | /* | |
7683 | * Bring down the SLI Layer. This step disable all interrupts, | |
7684 | * clears the rings, discards all mailbox commands, and resets | |
7685 | * the HBA. | |
7686 | */ | |
7687 | ||
7688 | /* HBA interrupt will be diabled after this call */ | |
7689 | lpfc_sli_hba_down(phba); | |
7690 | /* Stop kthread signal shall trigger work_done one more time */ | |
7691 | kthread_stop(phba->worker_thread); | |
7692 | /* Final cleanup of txcmplq and reset the HBA */ | |
7693 | lpfc_sli_brdrestart(phba); | |
7694 | ||
7695 | lpfc_stop_hba_timers(phba); | |
7696 | spin_lock_irq(&phba->hbalock); | |
7697 | list_del_init(&vport->listentry); | |
7698 | spin_unlock_irq(&phba->hbalock); | |
7699 | ||
7700 | lpfc_debugfs_terminate(vport); | |
7701 | ||
7702 | /* Disable interrupt */ | |
7703 | lpfc_sli_disable_intr(phba); | |
7704 | ||
7705 | pci_set_drvdata(pdev, NULL); | |
7706 | scsi_host_put(shost); | |
7707 | ||
7708 | /* | |
7709 | * Call scsi_free before mem_free since scsi bufs are released to their | |
7710 | * corresponding pools here. | |
7711 | */ | |
7712 | lpfc_scsi_free(phba); | |
7713 | lpfc_mem_free_all(phba); | |
7714 | ||
7715 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
7716 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
7717 | ||
7718 | /* Free resources associated with SLI2 interface */ | |
7719 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
7720 | phba->slim2p.virt, phba->slim2p.phys); | |
7721 | ||
7722 | /* unmap adapter SLIM and Control Registers */ | |
7723 | iounmap(phba->ctrl_regs_memmap_p); | |
7724 | iounmap(phba->slim_memmap_p); | |
7725 | ||
7726 | lpfc_hba_free(phba); | |
7727 | ||
7728 | pci_release_selected_regions(pdev, bars); | |
7729 | pci_disable_device(pdev); | |
7730 | } | |
7731 | ||
7732 | /** | |
7733 | * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt | |
7734 | * @pdev: pointer to PCI device | |
7735 | * @msg: power management message | |
7736 | * | |
7737 | * This routine is to be called from the kernel's PCI subsystem to support | |
7738 | * system Power Management (PM) to device with SLI-3 interface spec. When | |
7739 | * PM invokes this method, it quiesces the device by stopping the driver's | |
7740 | * worker thread for the device, turning off device's interrupt and DMA, | |
7741 | * and bring the device offline. Note that as the driver implements the | |
7742 | * minimum PM requirements to a power-aware driver's PM support for the | |
7743 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
7744 | * to the suspend() method call will be treated as SUSPEND and the driver will | |
7745 | * fully reinitialize its device during resume() method call, the driver will | |
7746 | * set device to PCI_D3hot state in PCI config space instead of setting it | |
7747 | * according to the @msg provided by the PM. | |
7748 | * | |
7749 | * Return code | |
7750 | * 0 - driver suspended the device | |
7751 | * Error otherwise | |
7752 | **/ | |
7753 | static int | |
7754 | lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg) | |
7755 | { | |
7756 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7757 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
7758 | ||
7759 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7760 | "0473 PCI device Power Management suspend.\n"); | |
7761 | ||
7762 | /* Bring down the device */ | |
7763 | lpfc_offline_prep(phba); | |
7764 | lpfc_offline(phba); | |
7765 | kthread_stop(phba->worker_thread); | |
7766 | ||
7767 | /* Disable interrupt from device */ | |
7768 | lpfc_sli_disable_intr(phba); | |
7769 | ||
7770 | /* Save device state to PCI config space */ | |
7771 | pci_save_state(pdev); | |
7772 | pci_set_power_state(pdev, PCI_D3hot); | |
7773 | ||
7774 | return 0; | |
7775 | } | |
7776 | ||
7777 | /** | |
7778 | * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt | |
7779 | * @pdev: pointer to PCI device | |
7780 | * | |
7781 | * This routine is to be called from the kernel's PCI subsystem to support | |
7782 | * system Power Management (PM) to device with SLI-3 interface spec. When PM | |
7783 | * invokes this method, it restores the device's PCI config space state and | |
7784 | * fully reinitializes the device and brings it online. Note that as the | |
7785 | * driver implements the minimum PM requirements to a power-aware driver's | |
7786 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, | |
7787 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the | |
7788 | * driver will fully reinitialize its device during resume() method call, | |
7789 | * the device will be set to PCI_D0 directly in PCI config space before | |
7790 | * restoring the state. | |
7791 | * | |
7792 | * Return code | |
7793 | * 0 - driver suspended the device | |
7794 | * Error otherwise | |
7795 | **/ | |
7796 | static int | |
7797 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) | |
7798 | { | |
7799 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7800 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
7801 | uint32_t intr_mode; | |
7802 | int error; | |
7803 | ||
7804 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7805 | "0452 PCI device Power Management resume.\n"); | |
7806 | ||
7807 | /* Restore device state from PCI config space */ | |
7808 | pci_set_power_state(pdev, PCI_D0); | |
7809 | pci_restore_state(pdev); | |
0d878419 | 7810 | |
1dfb5a47 JS |
7811 | /* |
7812 | * As the new kernel behavior of pci_restore_state() API call clears | |
7813 | * device saved_state flag, need to save the restored state again. | |
7814 | */ | |
7815 | pci_save_state(pdev); | |
7816 | ||
da0436e9 JS |
7817 | if (pdev->is_busmaster) |
7818 | pci_set_master(pdev); | |
7819 | ||
7820 | /* Startup the kernel thread for this host adapter. */ | |
7821 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
7822 | "lpfc_worker_%d", phba->brd_no); | |
7823 | if (IS_ERR(phba->worker_thread)) { | |
7824 | error = PTR_ERR(phba->worker_thread); | |
7825 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7826 | "0434 PM resume failed to start worker " | |
7827 | "thread: error=x%x.\n", error); | |
7828 | return error; | |
7829 | } | |
7830 | ||
7831 | /* Configure and enable interrupt */ | |
7832 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
7833 | if (intr_mode == LPFC_INTR_ERROR) { | |
7834 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7835 | "0430 PM resume Failed to enable interrupt\n"); | |
7836 | return -EIO; | |
7837 | } else | |
7838 | phba->intr_mode = intr_mode; | |
7839 | ||
7840 | /* Restart HBA and bring it online */ | |
7841 | lpfc_sli_brdrestart(phba); | |
7842 | lpfc_online(phba); | |
7843 | ||
7844 | /* Log the current active interrupt mode */ | |
7845 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
7846 | ||
7847 | return 0; | |
7848 | } | |
7849 | ||
891478a2 JS |
7850 | /** |
7851 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover | |
7852 | * @phba: pointer to lpfc hba data structure. | |
7853 | * | |
7854 | * This routine is called to prepare the SLI3 device for PCI slot recover. It | |
e2af0d2e | 7855 | * aborts all the outstanding SCSI I/Os to the pci device. |
891478a2 JS |
7856 | **/ |
7857 | static void | |
7858 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) | |
7859 | { | |
e2af0d2e JS |
7860 | struct lpfc_sli *psli = &phba->sli; |
7861 | struct lpfc_sli_ring *pring; | |
7862 | ||
891478a2 JS |
7863 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
7864 | "2723 PCI channel I/O abort preparing for recovery\n"); | |
e2af0d2e JS |
7865 | |
7866 | /* | |
7867 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
7868 | * and let the SCSI mid-layer to retry them to recover. | |
7869 | */ | |
7870 | pring = &psli->ring[psli->fcp_ring]; | |
7871 | lpfc_sli_abort_iocb_ring(phba, pring); | |
891478a2 JS |
7872 | } |
7873 | ||
0d878419 JS |
7874 | /** |
7875 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset | |
7876 | * @phba: pointer to lpfc hba data structure. | |
7877 | * | |
7878 | * This routine is called to prepare the SLI3 device for PCI slot reset. It | |
7879 | * disables the device interrupt and pci device, and aborts the internal FCP | |
7880 | * pending I/Os. | |
7881 | **/ | |
7882 | static void | |
7883 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) | |
7884 | { | |
0d878419 | 7885 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
891478a2 | 7886 | "2710 PCI channel disable preparing for reset\n"); |
e2af0d2e | 7887 | |
75baf696 JS |
7888 | /* Block any management I/Os to the device */ |
7889 | lpfc_block_mgmt_io(phba); | |
7890 | ||
e2af0d2e JS |
7891 | /* Block all SCSI devices' I/Os on the host */ |
7892 | lpfc_scsi_dev_block(phba); | |
7893 | ||
7894 | /* stop all timers */ | |
7895 | lpfc_stop_hba_timers(phba); | |
7896 | ||
0d878419 JS |
7897 | /* Disable interrupt and pci device */ |
7898 | lpfc_sli_disable_intr(phba); | |
7899 | pci_disable_device(phba->pcidev); | |
75baf696 | 7900 | |
e2af0d2e JS |
7901 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
7902 | lpfc_sli_flush_fcp_rings(phba); | |
0d878419 JS |
7903 | } |
7904 | ||
7905 | /** | |
7906 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable | |
7907 | * @phba: pointer to lpfc hba data structure. | |
7908 | * | |
7909 | * This routine is called to prepare the SLI3 device for PCI slot permanently | |
7910 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
7911 | * pending I/Os. | |
7912 | **/ | |
7913 | static void | |
75baf696 | 7914 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
0d878419 JS |
7915 | { |
7916 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
891478a2 | 7917 | "2711 PCI channel permanent disable for failure\n"); |
e2af0d2e JS |
7918 | /* Block all SCSI devices' I/Os on the host */ |
7919 | lpfc_scsi_dev_block(phba); | |
7920 | ||
7921 | /* stop all timers */ | |
7922 | lpfc_stop_hba_timers(phba); | |
7923 | ||
0d878419 JS |
7924 | /* Clean up all driver's outstanding SCSI I/Os */ |
7925 | lpfc_sli_flush_fcp_rings(phba); | |
7926 | } | |
7927 | ||
da0436e9 JS |
7928 | /** |
7929 | * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error | |
7930 | * @pdev: pointer to PCI device. | |
7931 | * @state: the current PCI connection state. | |
7932 | * | |
7933 | * This routine is called from the PCI subsystem for I/O error handling to | |
7934 | * device with SLI-3 interface spec. This function is called by the PCI | |
7935 | * subsystem after a PCI bus error affecting this device has been detected. | |
7936 | * When this function is invoked, it will need to stop all the I/Os and | |
7937 | * interrupt(s) to the device. Once that is done, it will return | |
7938 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery | |
7939 | * as desired. | |
7940 | * | |
7941 | * Return codes | |
0d878419 | 7942 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
da0436e9 JS |
7943 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
7944 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
7945 | **/ | |
7946 | static pci_ers_result_t | |
7947 | lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state) | |
7948 | { | |
7949 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7950 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
da0436e9 | 7951 | |
0d878419 JS |
7952 | switch (state) { |
7953 | case pci_channel_io_normal: | |
891478a2 JS |
7954 | /* Non-fatal error, prepare for recovery */ |
7955 | lpfc_sli_prep_dev_for_recover(phba); | |
0d878419 JS |
7956 | return PCI_ERS_RESULT_CAN_RECOVER; |
7957 | case pci_channel_io_frozen: | |
7958 | /* Fatal error, prepare for slot reset */ | |
7959 | lpfc_sli_prep_dev_for_reset(phba); | |
7960 | return PCI_ERS_RESULT_NEED_RESET; | |
7961 | case pci_channel_io_perm_failure: | |
7962 | /* Permanent failure, prepare for device down */ | |
75baf696 | 7963 | lpfc_sli_prep_dev_for_perm_failure(phba); |
da0436e9 | 7964 | return PCI_ERS_RESULT_DISCONNECT; |
0d878419 JS |
7965 | default: |
7966 | /* Unknown state, prepare and request slot reset */ | |
7967 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7968 | "0472 Unknown PCI error state: x%x\n", state); | |
7969 | lpfc_sli_prep_dev_for_reset(phba); | |
7970 | return PCI_ERS_RESULT_NEED_RESET; | |
da0436e9 | 7971 | } |
da0436e9 JS |
7972 | } |
7973 | ||
7974 | /** | |
7975 | * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch. | |
7976 | * @pdev: pointer to PCI device. | |
7977 | * | |
7978 | * This routine is called from the PCI subsystem for error handling to | |
7979 | * device with SLI-3 interface spec. This is called after PCI bus has been | |
7980 | * reset to restart the PCI card from scratch, as if from a cold-boot. | |
7981 | * During the PCI subsystem error recovery, after driver returns | |
7982 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error | |
7983 | * recovery and then call this routine before calling the .resume method | |
7984 | * to recover the device. This function will initialize the HBA device, | |
7985 | * enable the interrupt, but it will just put the HBA to offline state | |
7986 | * without passing any I/O traffic. | |
7987 | * | |
7988 | * Return codes | |
7989 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
7990 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
7991 | */ | |
7992 | static pci_ers_result_t | |
7993 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) | |
7994 | { | |
7995 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
7996 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
7997 | struct lpfc_sli *psli = &phba->sli; | |
7998 | uint32_t intr_mode; | |
7999 | ||
8000 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
8001 | if (pci_enable_device_mem(pdev)) { | |
8002 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
8003 | "PCI device after reset.\n"); | |
8004 | return PCI_ERS_RESULT_DISCONNECT; | |
8005 | } | |
8006 | ||
8007 | pci_restore_state(pdev); | |
1dfb5a47 JS |
8008 | |
8009 | /* | |
8010 | * As the new kernel behavior of pci_restore_state() API call clears | |
8011 | * device saved_state flag, need to save the restored state again. | |
8012 | */ | |
8013 | pci_save_state(pdev); | |
8014 | ||
da0436e9 JS |
8015 | if (pdev->is_busmaster) |
8016 | pci_set_master(pdev); | |
8017 | ||
8018 | spin_lock_irq(&phba->hbalock); | |
8019 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
8020 | spin_unlock_irq(&phba->hbalock); | |
8021 | ||
8022 | /* Configure and enable interrupt */ | |
8023 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
8024 | if (intr_mode == LPFC_INTR_ERROR) { | |
8025 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8026 | "0427 Cannot re-enable interrupt after " | |
8027 | "slot reset.\n"); | |
8028 | return PCI_ERS_RESULT_DISCONNECT; | |
8029 | } else | |
8030 | phba->intr_mode = intr_mode; | |
8031 | ||
75baf696 JS |
8032 | /* Take device offline, it will perform cleanup */ |
8033 | lpfc_offline_prep(phba); | |
da0436e9 JS |
8034 | lpfc_offline(phba); |
8035 | lpfc_sli_brdrestart(phba); | |
8036 | ||
8037 | /* Log the current active interrupt mode */ | |
8038 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
8039 | ||
8040 | return PCI_ERS_RESULT_RECOVERED; | |
8041 | } | |
8042 | ||
8043 | /** | |
8044 | * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device. | |
8045 | * @pdev: pointer to PCI device | |
8046 | * | |
8047 | * This routine is called from the PCI subsystem for error handling to device | |
8048 | * with SLI-3 interface spec. It is called when kernel error recovery tells | |
8049 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus | |
8050 | * error recovery. After this call, traffic can start to flow from this device | |
8051 | * again. | |
8052 | */ | |
8053 | static void | |
8054 | lpfc_io_resume_s3(struct pci_dev *pdev) | |
8055 | { | |
8056 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8057 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
3772a991 | 8058 | |
e2af0d2e | 8059 | /* Bring device online, it will be no-op for non-fatal error resume */ |
da0436e9 | 8060 | lpfc_online(phba); |
0d878419 JS |
8061 | |
8062 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
8063 | if (phba->hba_flag & HBA_AER_ENABLED) | |
8064 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
da0436e9 | 8065 | } |
3772a991 | 8066 | |
da0436e9 JS |
8067 | /** |
8068 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve | |
8069 | * @phba: pointer to lpfc hba data structure. | |
8070 | * | |
8071 | * returns the number of ELS/CT IOCBs to reserve | |
8072 | **/ | |
8073 | int | |
8074 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) | |
8075 | { | |
8076 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; | |
8077 | ||
f1126688 JS |
8078 | if (phba->sli_rev == LPFC_SLI_REV4) { |
8079 | if (max_xri <= 100) | |
6a9c52cf | 8080 | return 10; |
f1126688 | 8081 | else if (max_xri <= 256) |
6a9c52cf | 8082 | return 25; |
f1126688 | 8083 | else if (max_xri <= 512) |
6a9c52cf | 8084 | return 50; |
f1126688 | 8085 | else if (max_xri <= 1024) |
6a9c52cf | 8086 | return 100; |
f1126688 | 8087 | else |
6a9c52cf | 8088 | return 150; |
f1126688 JS |
8089 | } else |
8090 | return 0; | |
3772a991 JS |
8091 | } |
8092 | ||
8093 | /** | |
da0436e9 | 8094 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
3772a991 JS |
8095 | * @pdev: pointer to PCI device |
8096 | * @pid: pointer to PCI device identifier | |
8097 | * | |
da0436e9 JS |
8098 | * This routine is called from the kernel's PCI subsystem to device with |
8099 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 | 8100 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
da0436e9 JS |
8101 | * information of the device and driver to see if the driver state that it |
8102 | * can support this kind of device. If the match is successful, the driver | |
8103 | * core invokes this routine. If this routine determines it can claim the HBA, | |
8104 | * it does all the initialization that it needs to do to handle the HBA | |
8105 | * properly. | |
3772a991 JS |
8106 | * |
8107 | * Return code | |
8108 | * 0 - driver can claim the device | |
8109 | * negative value - driver can not claim the device | |
8110 | **/ | |
8111 | static int __devinit | |
da0436e9 | 8112 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
3772a991 JS |
8113 | { |
8114 | struct lpfc_hba *phba; | |
8115 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 8116 | struct Scsi_Host *shost = NULL; |
3772a991 JS |
8117 | int error; |
8118 | uint32_t cfg_mode, intr_mode; | |
da0436e9 | 8119 | int mcnt; |
3772a991 JS |
8120 | |
8121 | /* Allocate memory for HBA structure */ | |
8122 | phba = lpfc_hba_alloc(pdev); | |
8123 | if (!phba) | |
8124 | return -ENOMEM; | |
8125 | ||
8126 | /* Perform generic PCI device enabling operation */ | |
8127 | error = lpfc_enable_pci_dev(phba); | |
8128 | if (error) { | |
8129 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8130 | "1409 Failed to enable pci device.\n"); |
3772a991 JS |
8131 | goto out_free_phba; |
8132 | } | |
8133 | ||
da0436e9 JS |
8134 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
8135 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); | |
3772a991 JS |
8136 | if (error) |
8137 | goto out_disable_pci_dev; | |
8138 | ||
da0436e9 JS |
8139 | /* Set up SLI-4 specific device PCI memory space */ |
8140 | error = lpfc_sli4_pci_mem_setup(phba); | |
3772a991 JS |
8141 | if (error) { |
8142 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8143 | "1410 Failed to set up pci memory space.\n"); |
3772a991 JS |
8144 | goto out_disable_pci_dev; |
8145 | } | |
8146 | ||
8147 | /* Set up phase-1 common device driver resources */ | |
8148 | error = lpfc_setup_driver_resource_phase1(phba); | |
8149 | if (error) { | |
8150 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
8151 | "1411 Failed to set up driver resource.\n"); |
8152 | goto out_unset_pci_mem_s4; | |
3772a991 JS |
8153 | } |
8154 | ||
da0436e9 JS |
8155 | /* Set up SLI-4 Specific device driver resources */ |
8156 | error = lpfc_sli4_driver_resource_setup(phba); | |
3772a991 JS |
8157 | if (error) { |
8158 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
8159 | "1412 Failed to set up driver resource.\n"); |
8160 | goto out_unset_pci_mem_s4; | |
3772a991 JS |
8161 | } |
8162 | ||
8163 | /* Initialize and populate the iocb list per host */ | |
2a9bf3d0 JS |
8164 | |
8165 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8166 | "2821 initialize iocb list %d.\n", | |
8167 | phba->cfg_iocb_cnt*1024); | |
8168 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); | |
8169 | ||
3772a991 JS |
8170 | if (error) { |
8171 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
8172 | "1413 Failed to initialize iocb list.\n"); |
8173 | goto out_unset_driver_resource_s4; | |
3772a991 JS |
8174 | } |
8175 | ||
8176 | /* Set up common device driver resources */ | |
8177 | error = lpfc_setup_driver_resource_phase2(phba); | |
8178 | if (error) { | |
8179 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8180 | "1414 Failed to set up driver resource.\n"); |
3772a991 JS |
8181 | goto out_free_iocb_list; |
8182 | } | |
8183 | ||
8184 | /* Create SCSI host to the physical port */ | |
8185 | error = lpfc_create_shost(phba); | |
8186 | if (error) { | |
8187 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8188 | "1415 Failed to create scsi host.\n"); |
3772a991 JS |
8189 | goto out_unset_driver_resource; |
8190 | } | |
9399627f | 8191 | |
5b75da2f | 8192 | /* Configure sysfs attributes */ |
3772a991 JS |
8193 | vport = phba->pport; |
8194 | error = lpfc_alloc_sysfs_attr(vport); | |
8195 | if (error) { | |
9399627f | 8196 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 8197 | "1416 Failed to allocate sysfs attr\n"); |
3772a991 | 8198 | goto out_destroy_shost; |
98c9ea5c | 8199 | } |
875fbdfe | 8200 | |
6669f9bb | 8201 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
3772a991 | 8202 | /* Now, trying to enable interrupt and bring up the device */ |
5b75da2f JS |
8203 | cfg_mode = phba->cfg_use_msi; |
8204 | while (true) { | |
3772a991 JS |
8205 | /* Put device to a known state before enabling interrupt */ |
8206 | lpfc_stop_port(phba); | |
5b75da2f | 8207 | /* Configure and enable interrupt */ |
da0436e9 | 8208 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
5b75da2f JS |
8209 | if (intr_mode == LPFC_INTR_ERROR) { |
8210 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8211 | "0426 Failed to enable interrupt.\n"); |
3772a991 | 8212 | error = -ENODEV; |
5b75da2f JS |
8213 | goto out_free_sysfs_attr; |
8214 | } | |
def9c7a9 JS |
8215 | /* Default to single FCP EQ for non-MSI-X */ |
8216 | if (phba->intr_type != MSIX) | |
8217 | phba->cfg_fcp_eq_count = 1; | |
75baf696 JS |
8218 | else if (phba->sli4_hba.msix_vec_nr < phba->cfg_fcp_eq_count) |
8219 | phba->cfg_fcp_eq_count = phba->sli4_hba.msix_vec_nr - 1; | |
da0436e9 JS |
8220 | /* Set up SLI-4 HBA */ |
8221 | if (lpfc_sli4_hba_setup(phba)) { | |
5b75da2f | 8222 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 8223 | "1421 Failed to set up hba\n"); |
5b75da2f | 8224 | error = -ENODEV; |
da0436e9 | 8225 | goto out_disable_intr; |
5b75da2f JS |
8226 | } |
8227 | ||
da0436e9 JS |
8228 | /* Send NOP mbx cmds for non-INTx mode active interrupt test */ |
8229 | if (intr_mode != 0) | |
8230 | mcnt = lpfc_sli4_send_nop_mbox_cmds(phba, | |
8231 | LPFC_ACT_INTR_CNT); | |
8232 | ||
8233 | /* Check active interrupts received only for MSI/MSI-X */ | |
3772a991 | 8234 | if (intr_mode == 0 || |
da0436e9 | 8235 | phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) { |
5b75da2f JS |
8236 | /* Log the current active interrupt mode */ |
8237 | phba->intr_mode = intr_mode; | |
8238 | lpfc_log_intr_mode(phba, intr_mode); | |
8239 | break; | |
5b75da2f | 8240 | } |
da0436e9 JS |
8241 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
8242 | "0451 Configure interrupt mode (%d) " | |
8243 | "failed active interrupt test.\n", | |
8244 | intr_mode); | |
8245 | /* Unset the preivous SLI-4 HBA setup */ | |
8246 | lpfc_sli4_unset_hba(phba); | |
8247 | /* Try next level of interrupt mode */ | |
8248 | cfg_mode = --intr_mode; | |
98c9ea5c | 8249 | } |
858c9f6c | 8250 | |
3772a991 JS |
8251 | /* Perform post initialization setup */ |
8252 | lpfc_post_init_setup(phba); | |
dea3101e | 8253 | |
1c6834a7 JS |
8254 | /* Check if there are static vports to be created. */ |
8255 | lpfc_create_static_vport(phba); | |
8256 | ||
dea3101e JB |
8257 | return 0; |
8258 | ||
da0436e9 JS |
8259 | out_disable_intr: |
8260 | lpfc_sli4_disable_intr(phba); | |
5b75da2f JS |
8261 | out_free_sysfs_attr: |
8262 | lpfc_free_sysfs_attr(vport); | |
3772a991 JS |
8263 | out_destroy_shost: |
8264 | lpfc_destroy_shost(phba); | |
8265 | out_unset_driver_resource: | |
8266 | lpfc_unset_driver_resource_phase2(phba); | |
8267 | out_free_iocb_list: | |
8268 | lpfc_free_iocb_list(phba); | |
da0436e9 JS |
8269 | out_unset_driver_resource_s4: |
8270 | lpfc_sli4_driver_resource_unset(phba); | |
8271 | out_unset_pci_mem_s4: | |
8272 | lpfc_sli4_pci_mem_unset(phba); | |
3772a991 JS |
8273 | out_disable_pci_dev: |
8274 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
8275 | if (shost) |
8276 | scsi_host_put(shost); | |
2e0fef85 | 8277 | out_free_phba: |
3772a991 | 8278 | lpfc_hba_free(phba); |
dea3101e JB |
8279 | return error; |
8280 | } | |
8281 | ||
e59058c4 | 8282 | /** |
da0436e9 | 8283 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
e59058c4 JS |
8284 | * @pdev: pointer to PCI device |
8285 | * | |
da0436e9 JS |
8286 | * This routine is called from the kernel's PCI subsystem to device with |
8287 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 JS |
8288 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
8289 | * device to be removed from the PCI subsystem properly. | |
e59058c4 | 8290 | **/ |
dea3101e | 8291 | static void __devexit |
da0436e9 | 8292 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
dea3101e | 8293 | { |
da0436e9 | 8294 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2e0fef85 | 8295 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
eada272d | 8296 | struct lpfc_vport **vports; |
da0436e9 | 8297 | struct lpfc_hba *phba = vport->phba; |
eada272d | 8298 | int i; |
8a4df120 | 8299 | |
da0436e9 | 8300 | /* Mark the device unloading flag */ |
549e55cd | 8301 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 8302 | vport->load_flag |= FC_UNLOADING; |
549e55cd | 8303 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 8304 | |
da0436e9 | 8305 | /* Free the HBA sysfs attributes */ |
858c9f6c JS |
8306 | lpfc_free_sysfs_attr(vport); |
8307 | ||
eada272d JS |
8308 | /* Release all the vports against this physical port */ |
8309 | vports = lpfc_create_vport_work_array(phba); | |
8310 | if (vports != NULL) | |
3772a991 | 8311 | for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) |
eada272d JS |
8312 | fc_vport_terminate(vports[i]->fc_vport); |
8313 | lpfc_destroy_vport_work_array(phba, vports); | |
8314 | ||
8315 | /* Remove FC host and then SCSI host with the physical port */ | |
858c9f6c JS |
8316 | fc_remove_host(shost); |
8317 | scsi_remove_host(shost); | |
da0436e9 JS |
8318 | |
8319 | /* Perform cleanup on the physical port */ | |
87af33fe JS |
8320 | lpfc_cleanup(vport); |
8321 | ||
2e0fef85 | 8322 | /* |
da0436e9 | 8323 | * Bring down the SLI Layer. This step disables all interrupts, |
2e0fef85 | 8324 | * clears the rings, discards all mailbox commands, and resets |
da0436e9 | 8325 | * the HBA FCoE function. |
2e0fef85 | 8326 | */ |
da0436e9 JS |
8327 | lpfc_debugfs_terminate(vport); |
8328 | lpfc_sli4_hba_unset(phba); | |
a257bf90 | 8329 | |
858c9f6c JS |
8330 | spin_lock_irq(&phba->hbalock); |
8331 | list_del_init(&vport->listentry); | |
8332 | spin_unlock_irq(&phba->hbalock); | |
8333 | ||
da0436e9 JS |
8334 | /* Call scsi_free before lpfc_sli4_driver_resource_unset since scsi |
8335 | * buffers are released to their corresponding pools here. | |
2e0fef85 JS |
8336 | */ |
8337 | lpfc_scsi_free(phba); | |
da0436e9 | 8338 | lpfc_sli4_driver_resource_unset(phba); |
ed957684 | 8339 | |
da0436e9 JS |
8340 | /* Unmap adapter Control and Doorbell registers */ |
8341 | lpfc_sli4_pci_mem_unset(phba); | |
2e0fef85 | 8342 | |
da0436e9 JS |
8343 | /* Release PCI resources and disable device's PCI function */ |
8344 | scsi_host_put(shost); | |
8345 | lpfc_disable_pci_dev(phba); | |
2e0fef85 | 8346 | |
da0436e9 | 8347 | /* Finally, free the driver's device data structure */ |
3772a991 | 8348 | lpfc_hba_free(phba); |
2e0fef85 | 8349 | |
da0436e9 | 8350 | return; |
dea3101e JB |
8351 | } |
8352 | ||
3a55b532 | 8353 | /** |
da0436e9 | 8354 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
3a55b532 JS |
8355 | * @pdev: pointer to PCI device |
8356 | * @msg: power management message | |
8357 | * | |
da0436e9 JS |
8358 | * This routine is called from the kernel's PCI subsystem to support system |
8359 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes | |
8360 | * this method, it quiesces the device by stopping the driver's worker | |
8361 | * thread for the device, turning off device's interrupt and DMA, and bring | |
8362 | * the device offline. Note that as the driver implements the minimum PM | |
8363 | * requirements to a power-aware driver's PM support for suspend/resume -- all | |
8364 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() | |
8365 | * method call will be treated as SUSPEND and the driver will fully | |
8366 | * reinitialize its device during resume() method call, the driver will set | |
8367 | * device to PCI_D3hot state in PCI config space instead of setting it | |
3772a991 | 8368 | * according to the @msg provided by the PM. |
3a55b532 JS |
8369 | * |
8370 | * Return code | |
3772a991 JS |
8371 | * 0 - driver suspended the device |
8372 | * Error otherwise | |
3a55b532 JS |
8373 | **/ |
8374 | static int | |
da0436e9 | 8375 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
3a55b532 JS |
8376 | { |
8377 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8378 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8379 | ||
8380 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
75baf696 | 8381 | "2843 PCI device Power Management suspend.\n"); |
3a55b532 JS |
8382 | |
8383 | /* Bring down the device */ | |
8384 | lpfc_offline_prep(phba); | |
8385 | lpfc_offline(phba); | |
8386 | kthread_stop(phba->worker_thread); | |
8387 | ||
8388 | /* Disable interrupt from device */ | |
da0436e9 | 8389 | lpfc_sli4_disable_intr(phba); |
3a55b532 JS |
8390 | |
8391 | /* Save device state to PCI config space */ | |
8392 | pci_save_state(pdev); | |
8393 | pci_set_power_state(pdev, PCI_D3hot); | |
8394 | ||
8395 | return 0; | |
8396 | } | |
8397 | ||
8398 | /** | |
da0436e9 | 8399 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
3a55b532 JS |
8400 | * @pdev: pointer to PCI device |
8401 | * | |
da0436e9 JS |
8402 | * This routine is called from the kernel's PCI subsystem to support system |
8403 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes | |
8404 | * this method, it restores the device's PCI config space state and fully | |
8405 | * reinitializes the device and brings it online. Note that as the driver | |
8406 | * implements the minimum PM requirements to a power-aware driver's PM for | |
8407 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
8408 | * to the suspend() method call will be treated as SUSPEND and the driver | |
8409 | * will fully reinitialize its device during resume() method call, the device | |
8410 | * will be set to PCI_D0 directly in PCI config space before restoring the | |
8411 | * state. | |
3a55b532 JS |
8412 | * |
8413 | * Return code | |
3772a991 JS |
8414 | * 0 - driver suspended the device |
8415 | * Error otherwise | |
3a55b532 JS |
8416 | **/ |
8417 | static int | |
da0436e9 | 8418 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
3a55b532 JS |
8419 | { |
8420 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8421 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
5b75da2f | 8422 | uint32_t intr_mode; |
3a55b532 JS |
8423 | int error; |
8424 | ||
8425 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
da0436e9 | 8426 | "0292 PCI device Power Management resume.\n"); |
3a55b532 JS |
8427 | |
8428 | /* Restore device state from PCI config space */ | |
8429 | pci_set_power_state(pdev, PCI_D0); | |
8430 | pci_restore_state(pdev); | |
1dfb5a47 JS |
8431 | |
8432 | /* | |
8433 | * As the new kernel behavior of pci_restore_state() API call clears | |
8434 | * device saved_state flag, need to save the restored state again. | |
8435 | */ | |
8436 | pci_save_state(pdev); | |
8437 | ||
3a55b532 JS |
8438 | if (pdev->is_busmaster) |
8439 | pci_set_master(pdev); | |
8440 | ||
da0436e9 | 8441 | /* Startup the kernel thread for this host adapter. */ |
3a55b532 JS |
8442 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
8443 | "lpfc_worker_%d", phba->brd_no); | |
8444 | if (IS_ERR(phba->worker_thread)) { | |
8445 | error = PTR_ERR(phba->worker_thread); | |
8446 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8447 | "0293 PM resume failed to start worker " |
3a55b532 JS |
8448 | "thread: error=x%x.\n", error); |
8449 | return error; | |
8450 | } | |
8451 | ||
5b75da2f | 8452 | /* Configure and enable interrupt */ |
da0436e9 | 8453 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
5b75da2f | 8454 | if (intr_mode == LPFC_INTR_ERROR) { |
3a55b532 | 8455 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 8456 | "0294 PM resume Failed to enable interrupt\n"); |
5b75da2f JS |
8457 | return -EIO; |
8458 | } else | |
8459 | phba->intr_mode = intr_mode; | |
3a55b532 JS |
8460 | |
8461 | /* Restart HBA and bring it online */ | |
8462 | lpfc_sli_brdrestart(phba); | |
8463 | lpfc_online(phba); | |
8464 | ||
5b75da2f JS |
8465 | /* Log the current active interrupt mode */ |
8466 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
8467 | ||
3a55b532 JS |
8468 | return 0; |
8469 | } | |
8470 | ||
75baf696 JS |
8471 | /** |
8472 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover | |
8473 | * @phba: pointer to lpfc hba data structure. | |
8474 | * | |
8475 | * This routine is called to prepare the SLI4 device for PCI slot recover. It | |
8476 | * aborts all the outstanding SCSI I/Os to the pci device. | |
8477 | **/ | |
8478 | static void | |
8479 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) | |
8480 | { | |
8481 | struct lpfc_sli *psli = &phba->sli; | |
8482 | struct lpfc_sli_ring *pring; | |
8483 | ||
8484 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8485 | "2828 PCI channel I/O abort preparing for recovery\n"); | |
8486 | /* | |
8487 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
8488 | * and let the SCSI mid-layer to retry them to recover. | |
8489 | */ | |
8490 | pring = &psli->ring[psli->fcp_ring]; | |
8491 | lpfc_sli_abort_iocb_ring(phba, pring); | |
8492 | } | |
8493 | ||
8494 | /** | |
8495 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset | |
8496 | * @phba: pointer to lpfc hba data structure. | |
8497 | * | |
8498 | * This routine is called to prepare the SLI4 device for PCI slot reset. It | |
8499 | * disables the device interrupt and pci device, and aborts the internal FCP | |
8500 | * pending I/Os. | |
8501 | **/ | |
8502 | static void | |
8503 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) | |
8504 | { | |
8505 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8506 | "2826 PCI channel disable preparing for reset\n"); | |
8507 | ||
8508 | /* Block any management I/Os to the device */ | |
8509 | lpfc_block_mgmt_io(phba); | |
8510 | ||
8511 | /* Block all SCSI devices' I/Os on the host */ | |
8512 | lpfc_scsi_dev_block(phba); | |
8513 | ||
8514 | /* stop all timers */ | |
8515 | lpfc_stop_hba_timers(phba); | |
8516 | ||
8517 | /* Disable interrupt and pci device */ | |
8518 | lpfc_sli4_disable_intr(phba); | |
8519 | pci_disable_device(phba->pcidev); | |
8520 | ||
8521 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ | |
8522 | lpfc_sli_flush_fcp_rings(phba); | |
8523 | } | |
8524 | ||
8525 | /** | |
8526 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable | |
8527 | * @phba: pointer to lpfc hba data structure. | |
8528 | * | |
8529 | * This routine is called to prepare the SLI4 device for PCI slot permanently | |
8530 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
8531 | * pending I/Os. | |
8532 | **/ | |
8533 | static void | |
8534 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) | |
8535 | { | |
8536 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8537 | "2827 PCI channel permanent disable for failure\n"); | |
8538 | ||
8539 | /* Block all SCSI devices' I/Os on the host */ | |
8540 | lpfc_scsi_dev_block(phba); | |
8541 | ||
8542 | /* stop all timers */ | |
8543 | lpfc_stop_hba_timers(phba); | |
8544 | ||
8545 | /* Clean up all driver's outstanding SCSI I/Os */ | |
8546 | lpfc_sli_flush_fcp_rings(phba); | |
8547 | } | |
8548 | ||
8d63f375 | 8549 | /** |
da0436e9 | 8550 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
e59058c4 JS |
8551 | * @pdev: pointer to PCI device. |
8552 | * @state: the current PCI connection state. | |
8d63f375 | 8553 | * |
da0436e9 JS |
8554 | * This routine is called from the PCI subsystem for error handling to device |
8555 | * with SLI-4 interface spec. This function is called by the PCI subsystem | |
8556 | * after a PCI bus error affecting this device has been detected. When this | |
8557 | * function is invoked, it will need to stop all the I/Os and interrupt(s) | |
8558 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET | |
8559 | * for the PCI subsystem to perform proper recovery as desired. | |
e59058c4 JS |
8560 | * |
8561 | * Return codes | |
3772a991 JS |
8562 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
8563 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
e59058c4 | 8564 | **/ |
3772a991 | 8565 | static pci_ers_result_t |
da0436e9 | 8566 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
8d63f375 | 8567 | { |
75baf696 JS |
8568 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
8569 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8570 | ||
8571 | switch (state) { | |
8572 | case pci_channel_io_normal: | |
8573 | /* Non-fatal error, prepare for recovery */ | |
8574 | lpfc_sli4_prep_dev_for_recover(phba); | |
8575 | return PCI_ERS_RESULT_CAN_RECOVER; | |
8576 | case pci_channel_io_frozen: | |
8577 | /* Fatal error, prepare for slot reset */ | |
8578 | lpfc_sli4_prep_dev_for_reset(phba); | |
8579 | return PCI_ERS_RESULT_NEED_RESET; | |
8580 | case pci_channel_io_perm_failure: | |
8581 | /* Permanent failure, prepare for device down */ | |
8582 | lpfc_sli4_prep_dev_for_perm_failure(phba); | |
8583 | return PCI_ERS_RESULT_DISCONNECT; | |
8584 | default: | |
8585 | /* Unknown state, prepare and request slot reset */ | |
8586 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8587 | "2825 Unknown PCI error state: x%x\n", state); | |
8588 | lpfc_sli4_prep_dev_for_reset(phba); | |
8589 | return PCI_ERS_RESULT_NEED_RESET; | |
8590 | } | |
8d63f375 LV |
8591 | } |
8592 | ||
8593 | /** | |
da0436e9 | 8594 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
e59058c4 JS |
8595 | * @pdev: pointer to PCI device. |
8596 | * | |
da0436e9 JS |
8597 | * This routine is called from the PCI subsystem for error handling to device |
8598 | * with SLI-4 interface spec. It is called after PCI bus has been reset to | |
8599 | * restart the PCI card from scratch, as if from a cold-boot. During the | |
8600 | * PCI subsystem error recovery, after the driver returns | |
3772a991 | 8601 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
da0436e9 JS |
8602 | * recovery and then call this routine before calling the .resume method to |
8603 | * recover the device. This function will initialize the HBA device, enable | |
8604 | * the interrupt, but it will just put the HBA to offline state without | |
8605 | * passing any I/O traffic. | |
8d63f375 | 8606 | * |
e59058c4 | 8607 | * Return codes |
3772a991 JS |
8608 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
8609 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8d63f375 | 8610 | */ |
3772a991 | 8611 | static pci_ers_result_t |
da0436e9 | 8612 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
8d63f375 | 8613 | { |
75baf696 JS |
8614 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
8615 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8616 | struct lpfc_sli *psli = &phba->sli; | |
8617 | uint32_t intr_mode; | |
8618 | ||
8619 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
8620 | if (pci_enable_device_mem(pdev)) { | |
8621 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
8622 | "PCI device after reset.\n"); | |
8623 | return PCI_ERS_RESULT_DISCONNECT; | |
8624 | } | |
8625 | ||
8626 | pci_restore_state(pdev); | |
8627 | if (pdev->is_busmaster) | |
8628 | pci_set_master(pdev); | |
8629 | ||
8630 | spin_lock_irq(&phba->hbalock); | |
8631 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
8632 | spin_unlock_irq(&phba->hbalock); | |
8633 | ||
8634 | /* Configure and enable interrupt */ | |
8635 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); | |
8636 | if (intr_mode == LPFC_INTR_ERROR) { | |
8637 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8638 | "2824 Cannot re-enable interrupt after " | |
8639 | "slot reset.\n"); | |
8640 | return PCI_ERS_RESULT_DISCONNECT; | |
8641 | } else | |
8642 | phba->intr_mode = intr_mode; | |
8643 | ||
8644 | /* Log the current active interrupt mode */ | |
8645 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
8646 | ||
8d63f375 LV |
8647 | return PCI_ERS_RESULT_RECOVERED; |
8648 | } | |
8649 | ||
8650 | /** | |
da0436e9 | 8651 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
e59058c4 | 8652 | * @pdev: pointer to PCI device |
8d63f375 | 8653 | * |
3772a991 | 8654 | * This routine is called from the PCI subsystem for error handling to device |
da0436e9 | 8655 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
3772a991 JS |
8656 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
8657 | * error recovery. After this call, traffic can start to flow from this device | |
8658 | * again. | |
da0436e9 | 8659 | **/ |
3772a991 | 8660 | static void |
da0436e9 | 8661 | lpfc_io_resume_s4(struct pci_dev *pdev) |
8d63f375 | 8662 | { |
75baf696 JS |
8663 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
8664 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8665 | ||
8666 | /* | |
8667 | * In case of slot reset, as function reset is performed through | |
8668 | * mailbox command which needs DMA to be enabled, this operation | |
8669 | * has to be moved to the io resume phase. Taking device offline | |
8670 | * will perform the necessary cleanup. | |
8671 | */ | |
8672 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { | |
8673 | /* Perform device reset */ | |
8674 | lpfc_offline_prep(phba); | |
8675 | lpfc_offline(phba); | |
8676 | lpfc_sli_brdrestart(phba); | |
8677 | /* Bring the device back online */ | |
8678 | lpfc_online(phba); | |
8679 | } | |
8680 | ||
8681 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
8682 | if (phba->hba_flag & HBA_AER_ENABLED) | |
8683 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
8d63f375 LV |
8684 | } |
8685 | ||
3772a991 JS |
8686 | /** |
8687 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem | |
8688 | * @pdev: pointer to PCI device | |
8689 | * @pid: pointer to PCI device identifier | |
8690 | * | |
8691 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
8692 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks | |
8693 | * at PCI device-specific information of the device and driver to see if the | |
8694 | * driver state that it can support this kind of device. If the match is | |
8695 | * successful, the driver core invokes this routine. This routine dispatches | |
8696 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will | |
8697 | * do all the initialization that it needs to do to handle the HBA device | |
8698 | * properly. | |
8699 | * | |
8700 | * Return code | |
8701 | * 0 - driver can claim the device | |
8702 | * negative value - driver can not claim the device | |
8703 | **/ | |
8704 | static int __devinit | |
8705 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | |
8706 | { | |
8707 | int rc; | |
8fa38513 | 8708 | struct lpfc_sli_intf intf; |
3772a991 | 8709 | |
28baac74 | 8710 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
3772a991 JS |
8711 | return -ENODEV; |
8712 | ||
8fa38513 | 8713 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
28baac74 | 8714 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
da0436e9 | 8715 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
8fa38513 | 8716 | else |
3772a991 | 8717 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
8fa38513 | 8718 | |
3772a991 JS |
8719 | return rc; |
8720 | } | |
8721 | ||
8722 | /** | |
8723 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem | |
8724 | * @pdev: pointer to PCI device | |
8725 | * | |
8726 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
8727 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. | |
8728 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device | |
8729 | * remove routine, which will perform all the necessary cleanup for the | |
8730 | * device to be removed from the PCI subsystem properly. | |
8731 | **/ | |
8732 | static void __devexit | |
8733 | lpfc_pci_remove_one(struct pci_dev *pdev) | |
8734 | { | |
8735 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8736 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8737 | ||
8738 | switch (phba->pci_dev_grp) { | |
8739 | case LPFC_PCI_DEV_LP: | |
8740 | lpfc_pci_remove_one_s3(pdev); | |
8741 | break; | |
da0436e9 JS |
8742 | case LPFC_PCI_DEV_OC: |
8743 | lpfc_pci_remove_one_s4(pdev); | |
8744 | break; | |
3772a991 JS |
8745 | default: |
8746 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8747 | "1424 Invalid PCI device group: 0x%x\n", | |
8748 | phba->pci_dev_grp); | |
8749 | break; | |
8750 | } | |
8751 | return; | |
8752 | } | |
8753 | ||
8754 | /** | |
8755 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management | |
8756 | * @pdev: pointer to PCI device | |
8757 | * @msg: power management message | |
8758 | * | |
8759 | * This routine is to be registered to the kernel's PCI subsystem to support | |
8760 | * system Power Management (PM). When PM invokes this method, it dispatches | |
8761 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will | |
8762 | * suspend the device. | |
8763 | * | |
8764 | * Return code | |
8765 | * 0 - driver suspended the device | |
8766 | * Error otherwise | |
8767 | **/ | |
8768 | static int | |
8769 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | |
8770 | { | |
8771 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8772 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8773 | int rc = -ENODEV; | |
8774 | ||
8775 | switch (phba->pci_dev_grp) { | |
8776 | case LPFC_PCI_DEV_LP: | |
8777 | rc = lpfc_pci_suspend_one_s3(pdev, msg); | |
8778 | break; | |
da0436e9 JS |
8779 | case LPFC_PCI_DEV_OC: |
8780 | rc = lpfc_pci_suspend_one_s4(pdev, msg); | |
8781 | break; | |
3772a991 JS |
8782 | default: |
8783 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8784 | "1425 Invalid PCI device group: 0x%x\n", | |
8785 | phba->pci_dev_grp); | |
8786 | break; | |
8787 | } | |
8788 | return rc; | |
8789 | } | |
8790 | ||
8791 | /** | |
8792 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management | |
8793 | * @pdev: pointer to PCI device | |
8794 | * | |
8795 | * This routine is to be registered to the kernel's PCI subsystem to support | |
8796 | * system Power Management (PM). When PM invokes this method, it dispatches | |
8797 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will | |
8798 | * resume the device. | |
8799 | * | |
8800 | * Return code | |
8801 | * 0 - driver suspended the device | |
8802 | * Error otherwise | |
8803 | **/ | |
8804 | static int | |
8805 | lpfc_pci_resume_one(struct pci_dev *pdev) | |
8806 | { | |
8807 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8808 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8809 | int rc = -ENODEV; | |
8810 | ||
8811 | switch (phba->pci_dev_grp) { | |
8812 | case LPFC_PCI_DEV_LP: | |
8813 | rc = lpfc_pci_resume_one_s3(pdev); | |
8814 | break; | |
da0436e9 JS |
8815 | case LPFC_PCI_DEV_OC: |
8816 | rc = lpfc_pci_resume_one_s4(pdev); | |
8817 | break; | |
3772a991 JS |
8818 | default: |
8819 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8820 | "1426 Invalid PCI device group: 0x%x\n", | |
8821 | phba->pci_dev_grp); | |
8822 | break; | |
8823 | } | |
8824 | return rc; | |
8825 | } | |
8826 | ||
8827 | /** | |
8828 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error | |
8829 | * @pdev: pointer to PCI device. | |
8830 | * @state: the current PCI connection state. | |
8831 | * | |
8832 | * This routine is registered to the PCI subsystem for error handling. This | |
8833 | * function is called by the PCI subsystem after a PCI bus error affecting | |
8834 | * this device has been detected. When this routine is invoked, it dispatches | |
8835 | * the action to the proper SLI-3 or SLI-4 device error detected handling | |
8836 | * routine, which will perform the proper error detected operation. | |
8837 | * | |
8838 | * Return codes | |
8839 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery | |
8840 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8841 | **/ | |
8842 | static pci_ers_result_t | |
8843 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | |
8844 | { | |
8845 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8846 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8847 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
8848 | ||
8849 | switch (phba->pci_dev_grp) { | |
8850 | case LPFC_PCI_DEV_LP: | |
8851 | rc = lpfc_io_error_detected_s3(pdev, state); | |
8852 | break; | |
da0436e9 JS |
8853 | case LPFC_PCI_DEV_OC: |
8854 | rc = lpfc_io_error_detected_s4(pdev, state); | |
8855 | break; | |
3772a991 JS |
8856 | default: |
8857 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8858 | "1427 Invalid PCI device group: 0x%x\n", | |
8859 | phba->pci_dev_grp); | |
8860 | break; | |
8861 | } | |
8862 | return rc; | |
8863 | } | |
8864 | ||
8865 | /** | |
8866 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch | |
8867 | * @pdev: pointer to PCI device. | |
8868 | * | |
8869 | * This routine is registered to the PCI subsystem for error handling. This | |
8870 | * function is called after PCI bus has been reset to restart the PCI card | |
8871 | * from scratch, as if from a cold-boot. When this routine is invoked, it | |
8872 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling | |
8873 | * routine, which will perform the proper device reset. | |
8874 | * | |
8875 | * Return codes | |
8876 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
8877 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8878 | **/ | |
8879 | static pci_ers_result_t | |
8880 | lpfc_io_slot_reset(struct pci_dev *pdev) | |
8881 | { | |
8882 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8883 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8884 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
8885 | ||
8886 | switch (phba->pci_dev_grp) { | |
8887 | case LPFC_PCI_DEV_LP: | |
8888 | rc = lpfc_io_slot_reset_s3(pdev); | |
8889 | break; | |
da0436e9 JS |
8890 | case LPFC_PCI_DEV_OC: |
8891 | rc = lpfc_io_slot_reset_s4(pdev); | |
8892 | break; | |
3772a991 JS |
8893 | default: |
8894 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8895 | "1428 Invalid PCI device group: 0x%x\n", | |
8896 | phba->pci_dev_grp); | |
8897 | break; | |
8898 | } | |
8899 | return rc; | |
8900 | } | |
8901 | ||
8902 | /** | |
8903 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation | |
8904 | * @pdev: pointer to PCI device | |
8905 | * | |
8906 | * This routine is registered to the PCI subsystem for error handling. It | |
8907 | * is called when kernel error recovery tells the lpfc driver that it is | |
8908 | * OK to resume normal PCI operation after PCI bus error recovery. When | |
8909 | * this routine is invoked, it dispatches the action to the proper SLI-3 | |
8910 | * or SLI-4 device io_resume routine, which will resume the device operation. | |
8911 | **/ | |
8912 | static void | |
8913 | lpfc_io_resume(struct pci_dev *pdev) | |
8914 | { | |
8915 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8916 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8917 | ||
8918 | switch (phba->pci_dev_grp) { | |
8919 | case LPFC_PCI_DEV_LP: | |
8920 | lpfc_io_resume_s3(pdev); | |
8921 | break; | |
da0436e9 JS |
8922 | case LPFC_PCI_DEV_OC: |
8923 | lpfc_io_resume_s4(pdev); | |
8924 | break; | |
3772a991 JS |
8925 | default: |
8926 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8927 | "1429 Invalid PCI device group: 0x%x\n", | |
8928 | phba->pci_dev_grp); | |
8929 | break; | |
8930 | } | |
8931 | return; | |
8932 | } | |
8933 | ||
dea3101e JB |
8934 | static struct pci_device_id lpfc_id_table[] = { |
8935 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, | |
8936 | PCI_ANY_ID, PCI_ANY_ID, }, | |
06325e74 JSEC |
8937 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
8938 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
8939 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
8940 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8941 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, | |
8942 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8943 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, | |
8944 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8945 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, | |
8946 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8947 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, | |
8948 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8949 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, | |
8950 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8951 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, | |
8952 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
8953 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
8954 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8955 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, | |
8956 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8957 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, | |
8958 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
8959 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
8960 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
8961 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
8962 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8963 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, | |
8964 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
8965 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
8966 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8967 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, | |
8968 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8969 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, | |
8970 | PCI_ANY_ID, PCI_ANY_ID, }, | |
84774a4d JS |
8971 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
8972 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
8973 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
8974 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8975 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, | |
8976 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
8977 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
8978 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8979 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, | |
8980 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8981 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, | |
8982 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8983 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, | |
8984 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8985 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, | |
8986 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
8987 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
8988 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8989 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, | |
8990 | PCI_ANY_ID, PCI_ANY_ID, }, | |
b87eab38 JS |
8991 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
8992 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8993 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, | |
8994 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8995 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, | |
8996 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8997 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, | |
8998 | PCI_ANY_ID, PCI_ANY_ID, }, | |
8999 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, | |
9000 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9001 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, | |
9002 | PCI_ANY_ID, PCI_ANY_ID, }, | |
84774a4d JS |
9003 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
9004 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9005 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, | |
9006 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9007 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, | |
9008 | PCI_ANY_ID, PCI_ANY_ID, }, | |
3772a991 JS |
9009 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, |
9010 | PCI_ANY_ID, PCI_ANY_ID, }, | |
a747c9ce JS |
9011 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT, |
9012 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9013 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON, | |
6669f9bb | 9014 | PCI_ANY_ID, PCI_ANY_ID, }, |
98fc5dd9 JS |
9015 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS, |
9016 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
9017 | { 0 } |
9018 | }; | |
9019 | ||
9020 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); | |
9021 | ||
8d63f375 LV |
9022 | static struct pci_error_handlers lpfc_err_handler = { |
9023 | .error_detected = lpfc_io_error_detected, | |
9024 | .slot_reset = lpfc_io_slot_reset, | |
9025 | .resume = lpfc_io_resume, | |
9026 | }; | |
9027 | ||
dea3101e JB |
9028 | static struct pci_driver lpfc_driver = { |
9029 | .name = LPFC_DRIVER_NAME, | |
9030 | .id_table = lpfc_id_table, | |
9031 | .probe = lpfc_pci_probe_one, | |
9032 | .remove = __devexit_p(lpfc_pci_remove_one), | |
3a55b532 | 9033 | .suspend = lpfc_pci_suspend_one, |
3772a991 | 9034 | .resume = lpfc_pci_resume_one, |
2e0fef85 | 9035 | .err_handler = &lpfc_err_handler, |
dea3101e JB |
9036 | }; |
9037 | ||
e59058c4 | 9038 | /** |
3621a710 | 9039 | * lpfc_init - lpfc module initialization routine |
e59058c4 JS |
9040 | * |
9041 | * This routine is to be invoked when the lpfc module is loaded into the | |
9042 | * kernel. The special kernel macro module_init() is used to indicate the | |
9043 | * role of this routine to the kernel as lpfc module entry point. | |
9044 | * | |
9045 | * Return codes | |
9046 | * 0 - successful | |
9047 | * -ENOMEM - FC attach transport failed | |
9048 | * all others - failed | |
9049 | */ | |
dea3101e JB |
9050 | static int __init |
9051 | lpfc_init(void) | |
9052 | { | |
9053 | int error = 0; | |
9054 | ||
9055 | printk(LPFC_MODULE_DESC "\n"); | |
c44ce173 | 9056 | printk(LPFC_COPYRIGHT "\n"); |
dea3101e | 9057 | |
7ee5d43e JS |
9058 | if (lpfc_enable_npiv) { |
9059 | lpfc_transport_functions.vport_create = lpfc_vport_create; | |
9060 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; | |
9061 | } | |
dea3101e JB |
9062 | lpfc_transport_template = |
9063 | fc_attach_transport(&lpfc_transport_functions); | |
7ee5d43e | 9064 | if (lpfc_transport_template == NULL) |
dea3101e | 9065 | return -ENOMEM; |
7ee5d43e | 9066 | if (lpfc_enable_npiv) { |
7ee5d43e | 9067 | lpfc_vport_transport_template = |
98c9ea5c JS |
9068 | fc_attach_transport(&lpfc_vport_transport_functions); |
9069 | if (lpfc_vport_transport_template == NULL) { | |
9070 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e | 9071 | return -ENOMEM; |
98c9ea5c | 9072 | } |
7ee5d43e | 9073 | } |
dea3101e | 9074 | error = pci_register_driver(&lpfc_driver); |
92d7f7b0 | 9075 | if (error) { |
dea3101e | 9076 | fc_release_transport(lpfc_transport_template); |
d7c255b2 JS |
9077 | if (lpfc_enable_npiv) |
9078 | fc_release_transport(lpfc_vport_transport_template); | |
92d7f7b0 | 9079 | } |
dea3101e JB |
9080 | |
9081 | return error; | |
9082 | } | |
9083 | ||
e59058c4 | 9084 | /** |
3621a710 | 9085 | * lpfc_exit - lpfc module removal routine |
e59058c4 JS |
9086 | * |
9087 | * This routine is invoked when the lpfc module is removed from the kernel. | |
9088 | * The special kernel macro module_exit() is used to indicate the role of | |
9089 | * this routine to the kernel as lpfc module exit point. | |
9090 | */ | |
dea3101e JB |
9091 | static void __exit |
9092 | lpfc_exit(void) | |
9093 | { | |
9094 | pci_unregister_driver(&lpfc_driver); | |
9095 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e JS |
9096 | if (lpfc_enable_npiv) |
9097 | fc_release_transport(lpfc_vport_transport_template); | |
81301a9b | 9098 | if (_dump_buf_data) { |
6a9c52cf JS |
9099 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
9100 | "_dump_buf_data at 0x%p\n", | |
81301a9b JS |
9101 | (1L << _dump_buf_data_order), _dump_buf_data); |
9102 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); | |
9103 | } | |
9104 | ||
9105 | if (_dump_buf_dif) { | |
6a9c52cf JS |
9106 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
9107 | "_dump_buf_dif at 0x%p\n", | |
81301a9b JS |
9108 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
9109 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); | |
9110 | } | |
dea3101e JB |
9111 | } |
9112 | ||
9113 | module_init(lpfc_init); | |
9114 | module_exit(lpfc_exit); | |
9115 | MODULE_LICENSE("GPL"); | |
9116 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); | |
9117 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); | |
9118 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |