]>
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. * |
50611577 | 4 | * Copyright (C) 2004-2016 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> | |
acf3368f | 27 | #include <linux/module.h> |
dea3101e JB |
28 | #include <linux/kthread.h> |
29 | #include <linux/pci.h> | |
30 | #include <linux/spinlock.h> | |
92d7f7b0 | 31 | #include <linux/ctype.h> |
0d878419 | 32 | #include <linux/aer.h> |
5a0e3ad6 | 33 | #include <linux/slab.h> |
52d52440 | 34 | #include <linux/firmware.h> |
3ef6d24c | 35 | #include <linux/miscdevice.h> |
7bb03bbf | 36 | #include <linux/percpu.h> |
895427bd | 37 | #include <linux/msi.h> |
dea3101e | 38 | |
91886523 | 39 | #include <scsi/scsi.h> |
dea3101e JB |
40 | #include <scsi/scsi_device.h> |
41 | #include <scsi/scsi_host.h> | |
42 | #include <scsi/scsi_transport_fc.h> | |
43 | ||
da0436e9 | 44 | #include "lpfc_hw4.h" |
dea3101e JB |
45 | #include "lpfc_hw.h" |
46 | #include "lpfc_sli.h" | |
da0436e9 | 47 | #include "lpfc_sli4.h" |
ea2151b4 | 48 | #include "lpfc_nl.h" |
dea3101e | 49 | #include "lpfc_disc.h" |
dea3101e | 50 | #include "lpfc.h" |
895427bd JS |
51 | #include "lpfc_scsi.h" |
52 | #include "lpfc_nvme.h" | |
dea3101e JB |
53 | #include "lpfc_logmsg.h" |
54 | #include "lpfc_crtn.h" | |
92d7f7b0 | 55 | #include "lpfc_vport.h" |
dea3101e | 56 | #include "lpfc_version.h" |
12f44457 | 57 | #include "lpfc_ids.h" |
dea3101e | 58 | |
81301a9b JS |
59 | char *_dump_buf_data; |
60 | unsigned long _dump_buf_data_order; | |
61 | char *_dump_buf_dif; | |
62 | unsigned long _dump_buf_dif_order; | |
63 | spinlock_t _dump_buf_lock; | |
64 | ||
7bb03bbf | 65 | /* Used when mapping IRQ vectors in a driver centric manner */ |
b246de17 JS |
66 | uint16_t *lpfc_used_cpu; |
67 | uint32_t lpfc_present_cpu; | |
7bb03bbf | 68 | |
dea3101e JB |
69 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
70 | static int lpfc_post_rcv_buf(struct lpfc_hba *); | |
5350d872 | 71 | static int lpfc_sli4_queue_verify(struct lpfc_hba *); |
da0436e9 JS |
72 | static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); |
73 | static int lpfc_setup_endian_order(struct lpfc_hba *); | |
da0436e9 | 74 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); |
8a9d2e80 | 75 | static void lpfc_free_els_sgl_list(struct lpfc_hba *); |
f358dd0c | 76 | static void lpfc_free_nvmet_sgl_list(struct lpfc_hba *); |
8a9d2e80 | 77 | static void lpfc_init_sgl_list(struct lpfc_hba *); |
da0436e9 JS |
78 | static int lpfc_init_active_sgl_array(struct lpfc_hba *); |
79 | static void lpfc_free_active_sgl(struct lpfc_hba *); | |
80 | static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); | |
81 | static int lpfc_hba_down_post_s4(struct lpfc_hba *phba); | |
82 | static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *); | |
83 | static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *); | |
84 | static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *); | |
618a5230 JS |
85 | static void lpfc_sli4_disable_intr(struct lpfc_hba *); |
86 | static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t); | |
1ba981fd | 87 | static void lpfc_sli4_oas_verify(struct lpfc_hba *phba); |
dea3101e JB |
88 | |
89 | static struct scsi_transport_template *lpfc_transport_template = NULL; | |
92d7f7b0 | 90 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
dea3101e | 91 | static DEFINE_IDR(lpfc_hba_index); |
f358dd0c | 92 | #define LPFC_NVMET_BUF_POST 254 |
dea3101e | 93 | |
e59058c4 | 94 | /** |
3621a710 | 95 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
e59058c4 JS |
96 | * @phba: pointer to lpfc hba data structure. |
97 | * | |
98 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT | |
99 | * mailbox command. It retrieves the revision information from the HBA and | |
100 | * collects the Vital Product Data (VPD) about the HBA for preparing the | |
101 | * configuration of the HBA. | |
102 | * | |
103 | * Return codes: | |
104 | * 0 - success. | |
105 | * -ERESTART - requests the SLI layer to reset the HBA and try again. | |
106 | * Any other value - indicates an error. | |
107 | **/ | |
dea3101e | 108 | int |
2e0fef85 | 109 | lpfc_config_port_prep(struct lpfc_hba *phba) |
dea3101e JB |
110 | { |
111 | lpfc_vpd_t *vp = &phba->vpd; | |
112 | int i = 0, rc; | |
113 | LPFC_MBOXQ_t *pmb; | |
114 | MAILBOX_t *mb; | |
115 | char *lpfc_vpd_data = NULL; | |
116 | uint16_t offset = 0; | |
117 | static char licensed[56] = | |
118 | "key unlock for use with gnu public licensed code only\0"; | |
65a29c16 | 119 | static int init_key = 1; |
dea3101e JB |
120 | |
121 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
122 | if (!pmb) { | |
2e0fef85 | 123 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
124 | return -ENOMEM; |
125 | } | |
126 | ||
04c68496 | 127 | mb = &pmb->u.mb; |
2e0fef85 | 128 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e JB |
129 | |
130 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { | |
65a29c16 JS |
131 | if (init_key) { |
132 | uint32_t *ptext = (uint32_t *) licensed; | |
dea3101e | 133 | |
65a29c16 JS |
134 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
135 | *ptext = cpu_to_be32(*ptext); | |
136 | init_key = 0; | |
137 | } | |
dea3101e JB |
138 | |
139 | lpfc_read_nv(phba, pmb); | |
140 | memset((char*)mb->un.varRDnvp.rsvd3, 0, | |
141 | sizeof (mb->un.varRDnvp.rsvd3)); | |
142 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, | |
143 | sizeof (licensed)); | |
144 | ||
145 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
146 | ||
147 | if (rc != MBX_SUCCESS) { | |
ed957684 | 148 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
e8b62011 | 149 | "0324 Config Port initialization " |
dea3101e JB |
150 | "error, mbxCmd x%x READ_NVPARM, " |
151 | "mbxStatus x%x\n", | |
dea3101e JB |
152 | mb->mbxCommand, mb->mbxStatus); |
153 | mempool_free(pmb, phba->mbox_mem_pool); | |
154 | return -ERESTART; | |
155 | } | |
156 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, | |
2e0fef85 JS |
157 | sizeof(phba->wwnn)); |
158 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, | |
159 | sizeof(phba->wwpn)); | |
dea3101e JB |
160 | } |
161 | ||
92d7f7b0 JS |
162 | phba->sli3_options = 0x0; |
163 | ||
dea3101e JB |
164 | /* Setup and issue mailbox READ REV command */ |
165 | lpfc_read_rev(phba, pmb); | |
166 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
167 | if (rc != MBX_SUCCESS) { | |
ed957684 | 168 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 169 | "0439 Adapter failed to init, mbxCmd x%x " |
dea3101e | 170 | "READ_REV, mbxStatus x%x\n", |
dea3101e JB |
171 | mb->mbxCommand, mb->mbxStatus); |
172 | mempool_free( pmb, phba->mbox_mem_pool); | |
173 | return -ERESTART; | |
174 | } | |
175 | ||
92d7f7b0 | 176 | |
1de933f3 JSEC |
177 | /* |
178 | * The value of rr must be 1 since the driver set the cv field to 1. | |
179 | * This setting requires the FW to set all revision fields. | |
dea3101e | 180 | */ |
1de933f3 | 181 | if (mb->un.varRdRev.rr == 0) { |
dea3101e | 182 | vp->rev.rBit = 0; |
1de933f3 | 183 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 JS |
184 | "0440 Adapter failed to init, READ_REV has " |
185 | "missing revision information.\n"); | |
dea3101e JB |
186 | mempool_free(pmb, phba->mbox_mem_pool); |
187 | return -ERESTART; | |
dea3101e JB |
188 | } |
189 | ||
495a714c JS |
190 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
191 | mempool_free(pmb, phba->mbox_mem_pool); | |
ed957684 | 192 | return -EINVAL; |
495a714c | 193 | } |
ed957684 | 194 | |
dea3101e | 195 | /* Save information as VPD data */ |
1de933f3 | 196 | vp->rev.rBit = 1; |
92d7f7b0 | 197 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
1de933f3 JSEC |
198 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
199 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); | |
200 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; | |
201 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); | |
dea3101e JB |
202 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
203 | vp->rev.smRev = mb->un.varRdRev.smRev; | |
204 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; | |
205 | vp->rev.endecRev = mb->un.varRdRev.endecRev; | |
206 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; | |
207 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; | |
208 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; | |
209 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; | |
210 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; | |
211 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; | |
212 | ||
92d7f7b0 JS |
213 | /* If the sli feature level is less then 9, we must |
214 | * tear down all RPIs and VPIs on link down if NPIV | |
215 | * is enabled. | |
216 | */ | |
217 | if (vp->rev.feaLevelHigh < 9) | |
218 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; | |
219 | ||
dea3101e JB |
220 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
221 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], | |
222 | sizeof (phba->RandomData)); | |
223 | ||
dea3101e | 224 | /* Get adapter VPD information */ |
dea3101e JB |
225 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
226 | if (!lpfc_vpd_data) | |
d7c255b2 | 227 | goto out_free_mbox; |
dea3101e | 228 | do { |
a0c87cbd | 229 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
dea3101e JB |
230 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
231 | ||
232 | if (rc != MBX_SUCCESS) { | |
233 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 | 234 | "0441 VPD not present on adapter, " |
dea3101e | 235 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
dea3101e | 236 | mb->mbxCommand, mb->mbxStatus); |
74b72a59 | 237 | mb->un.varDmp.word_cnt = 0; |
dea3101e | 238 | } |
04c68496 JS |
239 | /* dump mem may return a zero when finished or we got a |
240 | * mailbox error, either way we are done. | |
241 | */ | |
242 | if (mb->un.varDmp.word_cnt == 0) | |
243 | break; | |
74b72a59 JW |
244 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
245 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; | |
d7c255b2 JS |
246 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
247 | lpfc_vpd_data + offset, | |
92d7f7b0 | 248 | mb->un.varDmp.word_cnt); |
dea3101e | 249 | offset += mb->un.varDmp.word_cnt; |
74b72a59 JW |
250 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
251 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); | |
dea3101e JB |
252 | |
253 | kfree(lpfc_vpd_data); | |
dea3101e JB |
254 | out_free_mbox: |
255 | mempool_free(pmb, phba->mbox_mem_pool); | |
256 | return 0; | |
257 | } | |
258 | ||
e59058c4 | 259 | /** |
3621a710 | 260 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
e59058c4 JS |
261 | * @phba: pointer to lpfc hba data structure. |
262 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
263 | * | |
264 | * This is the completion handler for driver's configuring asynchronous event | |
265 | * mailbox command to the device. If the mailbox command returns successfully, | |
266 | * it will set internal async event support flag to 1; otherwise, it will | |
267 | * set internal async event support flag to 0. | |
268 | **/ | |
57127f15 JS |
269 | static void |
270 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
271 | { | |
04c68496 | 272 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
57127f15 JS |
273 | phba->temp_sensor_support = 1; |
274 | else | |
275 | phba->temp_sensor_support = 0; | |
276 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
277 | return; | |
278 | } | |
279 | ||
97207482 | 280 | /** |
3621a710 | 281 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
97207482 JS |
282 | * @phba: pointer to lpfc hba data structure. |
283 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
284 | * | |
285 | * This is the completion handler for dump mailbox command for getting | |
286 | * wake up parameters. When this command complete, the response contain | |
287 | * Option rom version of the HBA. This function translate the version number | |
288 | * into a human readable string and store it in OptionROMVersion. | |
289 | **/ | |
290 | static void | |
291 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) | |
292 | { | |
293 | struct prog_id *prg; | |
294 | uint32_t prog_id_word; | |
295 | char dist = ' '; | |
296 | /* character array used for decoding dist type. */ | |
297 | char dist_char[] = "nabx"; | |
298 | ||
04c68496 | 299 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
9f1e1b50 | 300 | mempool_free(pmboxq, phba->mbox_mem_pool); |
97207482 | 301 | return; |
9f1e1b50 | 302 | } |
97207482 JS |
303 | |
304 | prg = (struct prog_id *) &prog_id_word; | |
305 | ||
306 | /* word 7 contain option rom version */ | |
04c68496 | 307 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
97207482 JS |
308 | |
309 | /* Decode the Option rom version word to a readable string */ | |
310 | if (prg->dist < 4) | |
311 | dist = dist_char[prg->dist]; | |
312 | ||
313 | if ((prg->dist == 3) && (prg->num == 0)) | |
a2fc4aef | 314 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d", |
97207482 JS |
315 | prg->ver, prg->rev, prg->lev); |
316 | else | |
a2fc4aef | 317 | snprintf(phba->OptionROMVersion, 32, "%d.%d%d%c%d", |
97207482 JS |
318 | prg->ver, prg->rev, prg->lev, |
319 | dist, prg->num); | |
9f1e1b50 | 320 | mempool_free(pmboxq, phba->mbox_mem_pool); |
97207482 JS |
321 | return; |
322 | } | |
323 | ||
0558056c JS |
324 | /** |
325 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, | |
326 | * cfg_soft_wwnn, cfg_soft_wwpn | |
327 | * @vport: pointer to lpfc vport data structure. | |
328 | * | |
329 | * | |
330 | * Return codes | |
331 | * None. | |
332 | **/ | |
333 | void | |
334 | lpfc_update_vport_wwn(struct lpfc_vport *vport) | |
335 | { | |
336 | /* If the soft name exists then update it using the service params */ | |
337 | if (vport->phba->cfg_soft_wwnn) | |
338 | u64_to_wwn(vport->phba->cfg_soft_wwnn, | |
339 | vport->fc_sparam.nodeName.u.wwn); | |
340 | if (vport->phba->cfg_soft_wwpn) | |
341 | u64_to_wwn(vport->phba->cfg_soft_wwpn, | |
342 | vport->fc_sparam.portName.u.wwn); | |
343 | ||
344 | /* | |
345 | * If the name is empty or there exists a soft name | |
346 | * then copy the service params name, otherwise use the fc name | |
347 | */ | |
348 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) | |
349 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, | |
350 | sizeof(struct lpfc_name)); | |
351 | else | |
352 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, | |
353 | sizeof(struct lpfc_name)); | |
354 | ||
355 | if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn) | |
356 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, | |
357 | sizeof(struct lpfc_name)); | |
358 | else | |
359 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, | |
360 | sizeof(struct lpfc_name)); | |
361 | } | |
362 | ||
e59058c4 | 363 | /** |
3621a710 | 364 | * lpfc_config_port_post - Perform lpfc initialization after config port |
e59058c4 JS |
365 | * @phba: pointer to lpfc hba data structure. |
366 | * | |
367 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox | |
368 | * command call. It performs all internal resource and state setups on the | |
369 | * port: post IOCB buffers, enable appropriate host interrupt attentions, | |
370 | * ELS ring timers, etc. | |
371 | * | |
372 | * Return codes | |
373 | * 0 - success. | |
374 | * Any other value - error. | |
375 | **/ | |
dea3101e | 376 | int |
2e0fef85 | 377 | lpfc_config_port_post(struct lpfc_hba *phba) |
dea3101e | 378 | { |
2e0fef85 | 379 | struct lpfc_vport *vport = phba->pport; |
a257bf90 | 380 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e JB |
381 | LPFC_MBOXQ_t *pmb; |
382 | MAILBOX_t *mb; | |
383 | struct lpfc_dmabuf *mp; | |
384 | struct lpfc_sli *psli = &phba->sli; | |
385 | uint32_t status, timeout; | |
2e0fef85 JS |
386 | int i, j; |
387 | int rc; | |
dea3101e | 388 | |
7af67051 JS |
389 | spin_lock_irq(&phba->hbalock); |
390 | /* | |
391 | * If the Config port completed correctly the HBA is not | |
392 | * over heated any more. | |
393 | */ | |
394 | if (phba->over_temp_state == HBA_OVER_TEMP) | |
395 | phba->over_temp_state = HBA_NORMAL_TEMP; | |
396 | spin_unlock_irq(&phba->hbalock); | |
397 | ||
dea3101e JB |
398 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
399 | if (!pmb) { | |
2e0fef85 | 400 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
401 | return -ENOMEM; |
402 | } | |
04c68496 | 403 | mb = &pmb->u.mb; |
dea3101e | 404 | |
dea3101e | 405 | /* Get login parameters for NID. */ |
9f1177a3 JS |
406 | rc = lpfc_read_sparam(phba, pmb, 0); |
407 | if (rc) { | |
408 | mempool_free(pmb, phba->mbox_mem_pool); | |
409 | return -ENOMEM; | |
410 | } | |
411 | ||
ed957684 | 412 | pmb->vport = vport; |
dea3101e | 413 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 414 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 415 | "0448 Adapter failed init, mbxCmd x%x " |
dea3101e | 416 | "READ_SPARM mbxStatus x%x\n", |
dea3101e | 417 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 418 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 419 | mp = (struct lpfc_dmabuf *) pmb->context1; |
9f1177a3 | 420 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e JB |
421 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
422 | kfree(mp); | |
423 | return -EIO; | |
424 | } | |
425 | ||
426 | mp = (struct lpfc_dmabuf *) pmb->context1; | |
427 | ||
2e0fef85 | 428 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
dea3101e JB |
429 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
430 | kfree(mp); | |
431 | pmb->context1 = NULL; | |
0558056c | 432 | lpfc_update_vport_wwn(vport); |
a257bf90 JS |
433 | |
434 | /* Update the fc_host data structures with new wwn. */ | |
435 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
436 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
21e9a0a5 | 437 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
a257bf90 | 438 | |
dea3101e JB |
439 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
440 | /* This should be consolidated into parse_vpd ? - mr */ | |
441 | if (phba->SerialNumber[0] == 0) { | |
442 | uint8_t *outptr; | |
443 | ||
2e0fef85 | 444 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
dea3101e JB |
445 | for (i = 0; i < 12; i++) { |
446 | status = *outptr++; | |
447 | j = ((status & 0xf0) >> 4); | |
448 | if (j <= 9) | |
449 | phba->SerialNumber[i] = | |
450 | (char)((uint8_t) 0x30 + (uint8_t) j); | |
451 | else | |
452 | phba->SerialNumber[i] = | |
453 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | |
454 | i++; | |
455 | j = (status & 0xf); | |
456 | if (j <= 9) | |
457 | phba->SerialNumber[i] = | |
458 | (char)((uint8_t) 0x30 + (uint8_t) j); | |
459 | else | |
460 | phba->SerialNumber[i] = | |
461 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | |
462 | } | |
463 | } | |
464 | ||
dea3101e | 465 | lpfc_read_config(phba, pmb); |
ed957684 | 466 | pmb->vport = vport; |
dea3101e | 467 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 468 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 469 | "0453 Adapter failed to init, mbxCmd x%x " |
dea3101e | 470 | "READ_CONFIG, mbxStatus x%x\n", |
dea3101e | 471 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 472 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
473 | mempool_free( pmb, phba->mbox_mem_pool); |
474 | return -EIO; | |
475 | } | |
476 | ||
a0c87cbd JS |
477 | /* Check if the port is disabled */ |
478 | lpfc_sli_read_link_ste(phba); | |
479 | ||
dea3101e | 480 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
572709e2 JS |
481 | i = (mb->un.varRdConfig.max_xri + 1); |
482 | if (phba->cfg_hba_queue_depth > i) { | |
483 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
484 | "3359 HBA queue depth changed from %d to %d\n", | |
485 | phba->cfg_hba_queue_depth, i); | |
486 | phba->cfg_hba_queue_depth = i; | |
487 | } | |
488 | ||
489 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ | |
490 | i = (mb->un.varRdConfig.max_xri >> 3); | |
491 | if (phba->pport->cfg_lun_queue_depth > i) { | |
492 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
493 | "3360 LUN queue depth changed from %d to %d\n", | |
494 | phba->pport->cfg_lun_queue_depth, i); | |
495 | phba->pport->cfg_lun_queue_depth = i; | |
496 | } | |
dea3101e JB |
497 | |
498 | phba->lmt = mb->un.varRdConfig.lmt; | |
74b72a59 JW |
499 | |
500 | /* Get the default values for Model Name and Description */ | |
501 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
502 | ||
2e0fef85 | 503 | phba->link_state = LPFC_LINK_DOWN; |
dea3101e | 504 | |
0b727fea | 505 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
895427bd JS |
506 | if (psli->sli3_ring[LPFC_EXTRA_RING].sli.sli3.cmdringaddr) |
507 | psli->sli3_ring[LPFC_EXTRA_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
508 | if (psli->sli3_ring[LPFC_FCP_RING].sli.sli3.cmdringaddr) | |
509 | psli->sli3_ring[LPFC_FCP_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
dea3101e JB |
510 | |
511 | /* Post receive buffers for desired rings */ | |
ed957684 JS |
512 | if (phba->sli_rev != 3) |
513 | lpfc_post_rcv_buf(phba); | |
dea3101e | 514 | |
9399627f JS |
515 | /* |
516 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode | |
517 | */ | |
518 | if (phba->intr_type == MSIX) { | |
519 | rc = lpfc_config_msi(phba, pmb); | |
520 | if (rc) { | |
521 | mempool_free(pmb, phba->mbox_mem_pool); | |
522 | return -EIO; | |
523 | } | |
524 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
525 | if (rc != MBX_SUCCESS) { | |
526 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
527 | "0352 Config MSI mailbox command " | |
528 | "failed, mbxCmd x%x, mbxStatus x%x\n", | |
04c68496 JS |
529 | pmb->u.mb.mbxCommand, |
530 | pmb->u.mb.mbxStatus); | |
9399627f JS |
531 | mempool_free(pmb, phba->mbox_mem_pool); |
532 | return -EIO; | |
533 | } | |
534 | } | |
535 | ||
04c68496 | 536 | spin_lock_irq(&phba->hbalock); |
9399627f JS |
537 | /* Initialize ERATT handling flag */ |
538 | phba->hba_flag &= ~HBA_ERATT_HANDLED; | |
539 | ||
dea3101e | 540 | /* Enable appropriate host interrupts */ |
9940b97b JS |
541 | if (lpfc_readl(phba->HCregaddr, &status)) { |
542 | spin_unlock_irq(&phba->hbalock); | |
543 | return -EIO; | |
544 | } | |
dea3101e JB |
545 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
546 | if (psli->num_rings > 0) | |
547 | status |= HC_R0INT_ENA; | |
548 | if (psli->num_rings > 1) | |
549 | status |= HC_R1INT_ENA; | |
550 | if (psli->num_rings > 2) | |
551 | status |= HC_R2INT_ENA; | |
552 | if (psli->num_rings > 3) | |
553 | status |= HC_R3INT_ENA; | |
554 | ||
875fbdfe JSEC |
555 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
556 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) | |
9399627f | 557 | status &= ~(HC_R0INT_ENA); |
875fbdfe | 558 | |
dea3101e JB |
559 | writel(status, phba->HCregaddr); |
560 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 561 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 562 | |
9399627f JS |
563 | /* Set up ring-0 (ELS) timer */ |
564 | timeout = phba->fc_ratov * 2; | |
256ec0d0 JS |
565 | mod_timer(&vport->els_tmofunc, |
566 | jiffies + msecs_to_jiffies(1000 * timeout)); | |
9399627f | 567 | /* Set up heart beat (HB) timer */ |
256ec0d0 JS |
568 | mod_timer(&phba->hb_tmofunc, |
569 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); | |
858c9f6c JS |
570 | phba->hb_outstanding = 0; |
571 | phba->last_completion_time = jiffies; | |
9399627f | 572 | /* Set up error attention (ERATT) polling timer */ |
256ec0d0 | 573 | mod_timer(&phba->eratt_poll, |
65791f1f | 574 | jiffies + msecs_to_jiffies(1000 * phba->eratt_poll_interval)); |
dea3101e | 575 | |
a0c87cbd JS |
576 | if (phba->hba_flag & LINK_DISABLED) { |
577 | lpfc_printf_log(phba, | |
578 | KERN_ERR, LOG_INIT, | |
579 | "2598 Adapter Link is disabled.\n"); | |
580 | lpfc_down_link(phba, pmb); | |
581 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
582 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
583 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { | |
584 | lpfc_printf_log(phba, | |
585 | KERN_ERR, LOG_INIT, | |
586 | "2599 Adapter failed to issue DOWN_LINK" | |
587 | " mbox command rc 0x%x\n", rc); | |
588 | ||
589 | mempool_free(pmb, phba->mbox_mem_pool); | |
590 | return -EIO; | |
591 | } | |
e40a02c1 | 592 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
026abb87 JS |
593 | mempool_free(pmb, phba->mbox_mem_pool); |
594 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); | |
595 | if (rc) | |
596 | return rc; | |
dea3101e JB |
597 | } |
598 | /* MBOX buffer will be freed in mbox compl */ | |
57127f15 | 599 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
9f1177a3 JS |
600 | if (!pmb) { |
601 | phba->link_state = LPFC_HBA_ERROR; | |
602 | return -ENOMEM; | |
603 | } | |
604 | ||
57127f15 JS |
605 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
606 | pmb->mbox_cmpl = lpfc_config_async_cmpl; | |
607 | pmb->vport = phba->pport; | |
608 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
dea3101e | 609 | |
57127f15 JS |
610 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
611 | lpfc_printf_log(phba, | |
612 | KERN_ERR, | |
613 | LOG_INIT, | |
614 | "0456 Adapter failed to issue " | |
e4e74273 | 615 | "ASYNCEVT_ENABLE mbox status x%x\n", |
57127f15 JS |
616 | rc); |
617 | mempool_free(pmb, phba->mbox_mem_pool); | |
618 | } | |
97207482 JS |
619 | |
620 | /* Get Option rom version */ | |
621 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
9f1177a3 JS |
622 | if (!pmb) { |
623 | phba->link_state = LPFC_HBA_ERROR; | |
624 | return -ENOMEM; | |
625 | } | |
626 | ||
97207482 JS |
627 | lpfc_dump_wakeup_param(phba, pmb); |
628 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; | |
629 | pmb->vport = phba->pport; | |
630 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
631 | ||
632 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { | |
633 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " | |
e4e74273 | 634 | "to get Option ROM version status x%x\n", rc); |
97207482 JS |
635 | mempool_free(pmb, phba->mbox_mem_pool); |
636 | } | |
637 | ||
d7c255b2 | 638 | return 0; |
ce8b3ce5 JS |
639 | } |
640 | ||
84d1b006 JS |
641 | /** |
642 | * lpfc_hba_init_link - Initialize the FC link | |
643 | * @phba: pointer to lpfc hba data structure. | |
6e7288d9 | 644 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
84d1b006 JS |
645 | * |
646 | * This routine will issue the INIT_LINK mailbox command call. | |
647 | * It is available to other drivers through the lpfc_hba data | |
648 | * structure for use as a delayed link up mechanism with the | |
649 | * module parameter lpfc_suppress_link_up. | |
650 | * | |
651 | * Return code | |
652 | * 0 - success | |
653 | * Any other value - error | |
654 | **/ | |
e399b228 | 655 | static int |
6e7288d9 | 656 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
1b51197d JS |
657 | { |
658 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); | |
659 | } | |
660 | ||
661 | /** | |
662 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology | |
663 | * @phba: pointer to lpfc hba data structure. | |
664 | * @fc_topology: desired fc topology. | |
665 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT | |
666 | * | |
667 | * This routine will issue the INIT_LINK mailbox command call. | |
668 | * It is available to other drivers through the lpfc_hba data | |
669 | * structure for use as a delayed link up mechanism with the | |
670 | * module parameter lpfc_suppress_link_up. | |
671 | * | |
672 | * Return code | |
673 | * 0 - success | |
674 | * Any other value - error | |
675 | **/ | |
676 | int | |
677 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, | |
678 | uint32_t flag) | |
84d1b006 JS |
679 | { |
680 | struct lpfc_vport *vport = phba->pport; | |
681 | LPFC_MBOXQ_t *pmb; | |
682 | MAILBOX_t *mb; | |
683 | int rc; | |
684 | ||
685 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
686 | if (!pmb) { | |
687 | phba->link_state = LPFC_HBA_ERROR; | |
688 | return -ENOMEM; | |
689 | } | |
690 | mb = &pmb->u.mb; | |
691 | pmb->vport = vport; | |
692 | ||
026abb87 JS |
693 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
694 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && | |
695 | !(phba->lmt & LMT_1Gb)) || | |
696 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && | |
697 | !(phba->lmt & LMT_2Gb)) || | |
698 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && | |
699 | !(phba->lmt & LMT_4Gb)) || | |
700 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && | |
701 | !(phba->lmt & LMT_8Gb)) || | |
702 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && | |
703 | !(phba->lmt & LMT_10Gb)) || | |
704 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && | |
d38dd52c JS |
705 | !(phba->lmt & LMT_16Gb)) || |
706 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_32G) && | |
707 | !(phba->lmt & LMT_32Gb))) { | |
026abb87 JS |
708 | /* Reset link speed to auto */ |
709 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, | |
710 | "1302 Invalid speed for this board:%d " | |
711 | "Reset link speed to auto.\n", | |
712 | phba->cfg_link_speed); | |
713 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; | |
714 | } | |
1b51197d | 715 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
84d1b006 | 716 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
1b51197d JS |
717 | if (phba->sli_rev < LPFC_SLI_REV4) |
718 | lpfc_set_loopback_flag(phba); | |
6e7288d9 | 719 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
76a95d75 | 720 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
84d1b006 JS |
721 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
722 | "0498 Adapter failed to init, mbxCmd x%x " | |
723 | "INIT_LINK, mbxStatus x%x\n", | |
724 | mb->mbxCommand, mb->mbxStatus); | |
76a95d75 JS |
725 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
726 | /* Clear all interrupt enable conditions */ | |
727 | writel(0, phba->HCregaddr); | |
728 | readl(phba->HCregaddr); /* flush */ | |
729 | /* Clear all pending interrupts */ | |
730 | writel(0xffffffff, phba->HAregaddr); | |
731 | readl(phba->HAregaddr); /* flush */ | |
732 | } | |
84d1b006 | 733 | phba->link_state = LPFC_HBA_ERROR; |
6e7288d9 | 734 | if (rc != MBX_BUSY || flag == MBX_POLL) |
84d1b006 JS |
735 | mempool_free(pmb, phba->mbox_mem_pool); |
736 | return -EIO; | |
737 | } | |
e40a02c1 | 738 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
6e7288d9 JS |
739 | if (flag == MBX_POLL) |
740 | mempool_free(pmb, phba->mbox_mem_pool); | |
84d1b006 JS |
741 | |
742 | return 0; | |
743 | } | |
744 | ||
745 | /** | |
746 | * lpfc_hba_down_link - this routine downs the FC link | |
6e7288d9 JS |
747 | * @phba: pointer to lpfc hba data structure. |
748 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT | |
84d1b006 JS |
749 | * |
750 | * This routine will issue the DOWN_LINK mailbox command call. | |
751 | * It is available to other drivers through the lpfc_hba data | |
752 | * structure for use to stop the link. | |
753 | * | |
754 | * Return code | |
755 | * 0 - success | |
756 | * Any other value - error | |
757 | **/ | |
e399b228 | 758 | static int |
6e7288d9 | 759 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
84d1b006 JS |
760 | { |
761 | LPFC_MBOXQ_t *pmb; | |
762 | int rc; | |
763 | ||
764 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
765 | if (!pmb) { | |
766 | phba->link_state = LPFC_HBA_ERROR; | |
767 | return -ENOMEM; | |
768 | } | |
769 | ||
770 | lpfc_printf_log(phba, | |
771 | KERN_ERR, LOG_INIT, | |
772 | "0491 Adapter Link is disabled.\n"); | |
773 | lpfc_down_link(phba, pmb); | |
774 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
6e7288d9 | 775 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
84d1b006 JS |
776 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
777 | lpfc_printf_log(phba, | |
778 | KERN_ERR, LOG_INIT, | |
779 | "2522 Adapter failed to issue DOWN_LINK" | |
780 | " mbox command rc 0x%x\n", rc); | |
781 | ||
782 | mempool_free(pmb, phba->mbox_mem_pool); | |
783 | return -EIO; | |
784 | } | |
6e7288d9 JS |
785 | if (flag == MBX_POLL) |
786 | mempool_free(pmb, phba->mbox_mem_pool); | |
787 | ||
84d1b006 JS |
788 | return 0; |
789 | } | |
790 | ||
e59058c4 | 791 | /** |
3621a710 | 792 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
e59058c4 JS |
793 | * @phba: pointer to lpfc HBA data structure. |
794 | * | |
795 | * This routine will do LPFC uninitialization before the HBA is reset when | |
796 | * bringing down the SLI Layer. | |
797 | * | |
798 | * Return codes | |
799 | * 0 - success. | |
800 | * Any other value - error. | |
801 | **/ | |
dea3101e | 802 | int |
2e0fef85 | 803 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
dea3101e | 804 | { |
1b32f6aa JS |
805 | struct lpfc_vport **vports; |
806 | int i; | |
3772a991 JS |
807 | |
808 | if (phba->sli_rev <= LPFC_SLI_REV3) { | |
809 | /* Disable interrupts */ | |
810 | writel(0, phba->HCregaddr); | |
811 | readl(phba->HCregaddr); /* flush */ | |
812 | } | |
dea3101e | 813 | |
1b32f6aa JS |
814 | if (phba->pport->load_flag & FC_UNLOADING) |
815 | lpfc_cleanup_discovery_resources(phba->pport); | |
816 | else { | |
817 | vports = lpfc_create_vport_work_array(phba); | |
818 | if (vports != NULL) | |
3772a991 JS |
819 | for (i = 0; i <= phba->max_vports && |
820 | vports[i] != NULL; i++) | |
1b32f6aa JS |
821 | lpfc_cleanup_discovery_resources(vports[i]); |
822 | lpfc_destroy_vport_work_array(phba, vports); | |
7f5f3d0d JS |
823 | } |
824 | return 0; | |
dea3101e JB |
825 | } |
826 | ||
68e814f5 JS |
827 | /** |
828 | * lpfc_sli4_free_sp_events - Cleanup sp_queue_events to free | |
829 | * rspiocb which got deferred | |
830 | * | |
831 | * @phba: pointer to lpfc HBA data structure. | |
832 | * | |
833 | * This routine will cleanup completed slow path events after HBA is reset | |
834 | * when bringing down the SLI Layer. | |
835 | * | |
836 | * | |
837 | * Return codes | |
838 | * void. | |
839 | **/ | |
840 | static void | |
841 | lpfc_sli4_free_sp_events(struct lpfc_hba *phba) | |
842 | { | |
843 | struct lpfc_iocbq *rspiocbq; | |
844 | struct hbq_dmabuf *dmabuf; | |
845 | struct lpfc_cq_event *cq_event; | |
846 | ||
847 | spin_lock_irq(&phba->hbalock); | |
848 | phba->hba_flag &= ~HBA_SP_QUEUE_EVT; | |
849 | spin_unlock_irq(&phba->hbalock); | |
850 | ||
851 | while (!list_empty(&phba->sli4_hba.sp_queue_event)) { | |
852 | /* Get the response iocb from the head of work queue */ | |
853 | spin_lock_irq(&phba->hbalock); | |
854 | list_remove_head(&phba->sli4_hba.sp_queue_event, | |
855 | cq_event, struct lpfc_cq_event, list); | |
856 | spin_unlock_irq(&phba->hbalock); | |
857 | ||
858 | switch (bf_get(lpfc_wcqe_c_code, &cq_event->cqe.wcqe_cmpl)) { | |
859 | case CQE_CODE_COMPL_WQE: | |
860 | rspiocbq = container_of(cq_event, struct lpfc_iocbq, | |
861 | cq_event); | |
862 | lpfc_sli_release_iocbq(phba, rspiocbq); | |
863 | break; | |
864 | case CQE_CODE_RECEIVE: | |
865 | case CQE_CODE_RECEIVE_V1: | |
866 | dmabuf = container_of(cq_event, struct hbq_dmabuf, | |
867 | cq_event); | |
868 | lpfc_in_buf_free(phba, &dmabuf->dbuf); | |
869 | } | |
870 | } | |
871 | } | |
872 | ||
e59058c4 | 873 | /** |
bcece5f5 | 874 | * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset |
e59058c4 JS |
875 | * @phba: pointer to lpfc HBA data structure. |
876 | * | |
bcece5f5 JS |
877 | * This routine will cleanup posted ELS buffers after the HBA is reset |
878 | * when bringing down the SLI Layer. | |
879 | * | |
e59058c4 JS |
880 | * |
881 | * Return codes | |
bcece5f5 | 882 | * void. |
e59058c4 | 883 | **/ |
bcece5f5 JS |
884 | static void |
885 | lpfc_hba_free_post_buf(struct lpfc_hba *phba) | |
41415862 JW |
886 | { |
887 | struct lpfc_sli *psli = &phba->sli; | |
888 | struct lpfc_sli_ring *pring; | |
889 | struct lpfc_dmabuf *mp, *next_mp; | |
07eab624 JS |
890 | LIST_HEAD(buflist); |
891 | int count; | |
41415862 | 892 | |
92d7f7b0 JS |
893 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
894 | lpfc_sli_hbqbuf_free_all(phba); | |
895 | else { | |
896 | /* Cleanup preposted buffers on the ELS ring */ | |
895427bd | 897 | pring = &psli->sli3_ring[LPFC_ELS_RING]; |
07eab624 JS |
898 | spin_lock_irq(&phba->hbalock); |
899 | list_splice_init(&pring->postbufq, &buflist); | |
900 | spin_unlock_irq(&phba->hbalock); | |
901 | ||
902 | count = 0; | |
903 | list_for_each_entry_safe(mp, next_mp, &buflist, list) { | |
92d7f7b0 | 904 | list_del(&mp->list); |
07eab624 | 905 | count++; |
92d7f7b0 JS |
906 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
907 | kfree(mp); | |
908 | } | |
07eab624 JS |
909 | |
910 | spin_lock_irq(&phba->hbalock); | |
911 | pring->postbufq_cnt -= count; | |
bcece5f5 | 912 | spin_unlock_irq(&phba->hbalock); |
41415862 | 913 | } |
bcece5f5 JS |
914 | } |
915 | ||
916 | /** | |
917 | * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset | |
918 | * @phba: pointer to lpfc HBA data structure. | |
919 | * | |
920 | * This routine will cleanup the txcmplq after the HBA is reset when bringing | |
921 | * down the SLI Layer. | |
922 | * | |
923 | * Return codes | |
924 | * void | |
925 | **/ | |
926 | static void | |
927 | lpfc_hba_clean_txcmplq(struct lpfc_hba *phba) | |
928 | { | |
929 | struct lpfc_sli *psli = &phba->sli; | |
895427bd | 930 | struct lpfc_queue *qp = NULL; |
bcece5f5 JS |
931 | struct lpfc_sli_ring *pring; |
932 | LIST_HEAD(completions); | |
933 | int i; | |
934 | ||
895427bd JS |
935 | if (phba->sli_rev != LPFC_SLI_REV4) { |
936 | for (i = 0; i < psli->num_rings; i++) { | |
937 | pring = &psli->sli3_ring[i]; | |
bcece5f5 | 938 | spin_lock_irq(&phba->hbalock); |
895427bd JS |
939 | /* At this point in time the HBA is either reset or DOA |
940 | * Nothing should be on txcmplq as it will | |
941 | * NEVER complete. | |
942 | */ | |
943 | list_splice_init(&pring->txcmplq, &completions); | |
944 | pring->txcmplq_cnt = 0; | |
bcece5f5 | 945 | spin_unlock_irq(&phba->hbalock); |
09372820 | 946 | |
895427bd JS |
947 | lpfc_sli_abort_iocb_ring(phba, pring); |
948 | } | |
a257bf90 | 949 | /* Cancel all the IOCBs from the completions list */ |
895427bd JS |
950 | lpfc_sli_cancel_iocbs(phba, &completions, |
951 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); | |
952 | return; | |
953 | } | |
954 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { | |
955 | pring = qp->pring; | |
956 | if (!pring) | |
957 | continue; | |
958 | spin_lock_irq(&pring->ring_lock); | |
959 | list_splice_init(&pring->txcmplq, &completions); | |
960 | pring->txcmplq_cnt = 0; | |
961 | spin_unlock_irq(&pring->ring_lock); | |
41415862 JW |
962 | lpfc_sli_abort_iocb_ring(phba, pring); |
963 | } | |
895427bd JS |
964 | /* Cancel all the IOCBs from the completions list */ |
965 | lpfc_sli_cancel_iocbs(phba, &completions, | |
966 | IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED); | |
bcece5f5 | 967 | } |
41415862 | 968 | |
bcece5f5 JS |
969 | /** |
970 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset | |
971 | int i; | |
972 | * @phba: pointer to lpfc HBA data structure. | |
973 | * | |
974 | * This routine will do uninitialization after the HBA is reset when bring | |
975 | * down the SLI Layer. | |
976 | * | |
977 | * Return codes | |
978 | * 0 - success. | |
979 | * Any other value - error. | |
980 | **/ | |
981 | static int | |
982 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) | |
983 | { | |
984 | lpfc_hba_free_post_buf(phba); | |
985 | lpfc_hba_clean_txcmplq(phba); | |
41415862 JW |
986 | return 0; |
987 | } | |
5af5eee7 | 988 | |
da0436e9 JS |
989 | /** |
990 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset | |
991 | * @phba: pointer to lpfc HBA data structure. | |
992 | * | |
993 | * This routine will do uninitialization after the HBA is reset when bring | |
994 | * down the SLI Layer. | |
995 | * | |
996 | * Return codes | |
af901ca1 | 997 | * 0 - success. |
da0436e9 JS |
998 | * Any other value - error. |
999 | **/ | |
1000 | static int | |
1001 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) | |
1002 | { | |
1003 | struct lpfc_scsi_buf *psb, *psb_next; | |
1004 | LIST_HEAD(aborts); | |
895427bd | 1005 | LIST_HEAD(nvme_aborts); |
da0436e9 | 1006 | unsigned long iflag = 0; |
0f65ff68 JS |
1007 | struct lpfc_sglq *sglq_entry = NULL; |
1008 | ||
895427bd JS |
1009 | |
1010 | lpfc_sli_hbqbuf_free_all(phba); | |
bcece5f5 JS |
1011 | lpfc_hba_clean_txcmplq(phba); |
1012 | ||
da0436e9 JS |
1013 | /* At this point in time the HBA is either reset or DOA. Either |
1014 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be | |
895427bd | 1015 | * on the lpfc_els_sgl_list so that it can either be freed if the |
da0436e9 JS |
1016 | * driver is unloading or reposted if the driver is restarting |
1017 | * the port. | |
1018 | */ | |
895427bd | 1019 | spin_lock_irq(&phba->hbalock); /* required for lpfc_els_sgl_list and */ |
da0436e9 | 1020 | /* scsl_buf_list */ |
895427bd | 1021 | /* sgl_list_lock required because worker thread uses this |
da0436e9 JS |
1022 | * list. |
1023 | */ | |
895427bd | 1024 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
0f65ff68 JS |
1025 | list_for_each_entry(sglq_entry, |
1026 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) | |
1027 | sglq_entry->state = SGL_FREED; | |
f358dd0c JS |
1028 | list_for_each_entry(sglq_entry, |
1029 | &phba->sli4_hba.lpfc_abts_nvmet_sgl_list, list) | |
1030 | sglq_entry->state = SGL_FREED; | |
0f65ff68 | 1031 | |
da0436e9 | 1032 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
895427bd JS |
1033 | &phba->sli4_hba.lpfc_els_sgl_list); |
1034 | ||
f358dd0c JS |
1035 | if (phba->sli4_hba.nvme_wq) |
1036 | list_splice_init(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list, | |
1037 | &phba->sli4_hba.lpfc_nvmet_sgl_list); | |
1038 | ||
895427bd | 1039 | spin_unlock(&phba->sli4_hba.sgl_list_lock); |
da0436e9 JS |
1040 | /* abts_scsi_buf_list_lock required because worker thread uses this |
1041 | * list. | |
1042 | */ | |
895427bd JS |
1043 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
1044 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
1045 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, | |
1046 | &aborts); | |
1047 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
1048 | } | |
1049 | ||
1050 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { | |
1051 | spin_lock(&phba->sli4_hba.abts_nvme_buf_list_lock); | |
1052 | list_splice_init(&phba->sli4_hba.lpfc_abts_nvme_buf_list, | |
1053 | &nvme_aborts); | |
1054 | spin_unlock(&phba->sli4_hba.abts_nvme_buf_list_lock); | |
1055 | } | |
1056 | ||
da0436e9 JS |
1057 | spin_unlock_irq(&phba->hbalock); |
1058 | ||
1059 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { | |
1060 | psb->pCmd = NULL; | |
1061 | psb->status = IOSTAT_SUCCESS; | |
1062 | } | |
a40fc5f0 JS |
1063 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
1064 | list_splice(&aborts, &phba->lpfc_scsi_buf_list_put); | |
1065 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); | |
68e814f5 | 1066 | |
895427bd JS |
1067 | list_for_each_entry_safe(psb, psb_next, &nvme_aborts, list) { |
1068 | psb->pCmd = NULL; | |
1069 | psb->status = IOSTAT_SUCCESS; | |
1070 | } | |
1071 | spin_lock_irqsave(&phba->nvme_buf_list_put_lock, iflag); | |
1072 | list_splice(&nvme_aborts, &phba->lpfc_nvme_buf_list_put); | |
1073 | spin_unlock_irqrestore(&phba->nvme_buf_list_put_lock, iflag); | |
1074 | ||
68e814f5 | 1075 | lpfc_sli4_free_sp_events(phba); |
da0436e9 JS |
1076 | return 0; |
1077 | } | |
1078 | ||
1079 | /** | |
1080 | * lpfc_hba_down_post - Wrapper func for hba down post routine | |
1081 | * @phba: pointer to lpfc HBA data structure. | |
1082 | * | |
1083 | * This routine wraps the actual SLI3 or SLI4 routine for performing | |
1084 | * uninitialization after the HBA is reset when bring down the SLI Layer. | |
1085 | * | |
1086 | * Return codes | |
af901ca1 | 1087 | * 0 - success. |
da0436e9 JS |
1088 | * Any other value - error. |
1089 | **/ | |
1090 | int | |
1091 | lpfc_hba_down_post(struct lpfc_hba *phba) | |
1092 | { | |
1093 | return (*phba->lpfc_hba_down_post)(phba); | |
1094 | } | |
41415862 | 1095 | |
e59058c4 | 1096 | /** |
3621a710 | 1097 | * lpfc_hb_timeout - The HBA-timer timeout handler |
e59058c4 JS |
1098 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
1099 | * | |
1100 | * This is the HBA-timer timeout handler registered to the lpfc driver. When | |
1101 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver | |
1102 | * work-port-events bitmap and the worker thread is notified. This timeout | |
1103 | * event will be used by the worker thread to invoke the actual timeout | |
1104 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will | |
1105 | * be performed in the timeout handler and the HBA timeout event bit shall | |
1106 | * be cleared by the worker thread after it has taken the event bitmap out. | |
1107 | **/ | |
a6ababd2 | 1108 | static void |
858c9f6c JS |
1109 | lpfc_hb_timeout(unsigned long ptr) |
1110 | { | |
1111 | struct lpfc_hba *phba; | |
5e9d9b82 | 1112 | uint32_t tmo_posted; |
858c9f6c JS |
1113 | unsigned long iflag; |
1114 | ||
1115 | phba = (struct lpfc_hba *)ptr; | |
9399627f JS |
1116 | |
1117 | /* Check for heart beat timeout conditions */ | |
858c9f6c | 1118 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
5e9d9b82 JS |
1119 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
1120 | if (!tmo_posted) | |
858c9f6c JS |
1121 | phba->pport->work_port_events |= WORKER_HB_TMO; |
1122 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
1123 | ||
9399627f | 1124 | /* Tell the worker thread there is work to do */ |
5e9d9b82 JS |
1125 | if (!tmo_posted) |
1126 | lpfc_worker_wake_up(phba); | |
858c9f6c JS |
1127 | return; |
1128 | } | |
1129 | ||
19ca7609 JS |
1130 | /** |
1131 | * lpfc_rrq_timeout - The RRQ-timer timeout handler | |
1132 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. | |
1133 | * | |
1134 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When | |
1135 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver | |
1136 | * work-port-events bitmap and the worker thread is notified. This timeout | |
1137 | * event will be used by the worker thread to invoke the actual timeout | |
1138 | * handler routine, lpfc_rrq_handler. Any periodical operations will | |
1139 | * be performed in the timeout handler and the RRQ timeout event bit shall | |
1140 | * be cleared by the worker thread after it has taken the event bitmap out. | |
1141 | **/ | |
1142 | static void | |
1143 | lpfc_rrq_timeout(unsigned long ptr) | |
1144 | { | |
1145 | struct lpfc_hba *phba; | |
19ca7609 JS |
1146 | unsigned long iflag; |
1147 | ||
1148 | phba = (struct lpfc_hba *)ptr; | |
1149 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
06918ac5 JS |
1150 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
1151 | phba->hba_flag |= HBA_RRQ_ACTIVE; | |
1152 | else | |
1153 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
19ca7609 | 1154 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
06918ac5 JS |
1155 | |
1156 | if (!(phba->pport->load_flag & FC_UNLOADING)) | |
1157 | lpfc_worker_wake_up(phba); | |
19ca7609 JS |
1158 | } |
1159 | ||
e59058c4 | 1160 | /** |
3621a710 | 1161 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
e59058c4 JS |
1162 | * @phba: pointer to lpfc hba data structure. |
1163 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
1164 | * | |
1165 | * This is the callback function to the lpfc heart-beat mailbox command. | |
1166 | * If configured, the lpfc driver issues the heart-beat mailbox command to | |
1167 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the | |
1168 | * heart-beat mailbox command is issued, the driver shall set up heart-beat | |
1169 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks | |
1170 | * heart-beat outstanding state. Once the mailbox command comes back and | |
1171 | * no error conditions detected, the heart-beat mailbox command timer is | |
1172 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding | |
1173 | * state is cleared for the next heart-beat. If the timer expired with the | |
1174 | * heart-beat outstanding state set, the driver will put the HBA offline. | |
1175 | **/ | |
858c9f6c JS |
1176 | static void |
1177 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
1178 | { | |
1179 | unsigned long drvr_flag; | |
1180 | ||
1181 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
1182 | phba->hb_outstanding = 0; | |
1183 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
1184 | ||
9399627f | 1185 | /* Check and reset heart-beat timer is necessary */ |
858c9f6c JS |
1186 | mempool_free(pmboxq, phba->mbox_mem_pool); |
1187 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && | |
1188 | !(phba->link_state == LPFC_HBA_ERROR) && | |
51ef4c26 | 1189 | !(phba->pport->load_flag & FC_UNLOADING)) |
858c9f6c | 1190 | mod_timer(&phba->hb_tmofunc, |
256ec0d0 JS |
1191 | jiffies + |
1192 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); | |
858c9f6c JS |
1193 | return; |
1194 | } | |
1195 | ||
e59058c4 | 1196 | /** |
3621a710 | 1197 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
e59058c4 JS |
1198 | * @phba: pointer to lpfc hba data structure. |
1199 | * | |
1200 | * This is the actual HBA-timer timeout handler to be invoked by the worker | |
1201 | * thread whenever the HBA timer fired and HBA-timeout event posted. This | |
1202 | * handler performs any periodic operations needed for the device. If such | |
1203 | * periodic event has already been attended to either in the interrupt handler | |
1204 | * or by processing slow-ring or fast-ring events within the HBA-timer | |
1205 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets | |
1206 | * the timer for the next timeout period. If lpfc heart-beat mailbox command | |
1207 | * is configured and there is no heart-beat mailbox command outstanding, a | |
1208 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there | |
1209 | * has been a heart-beat mailbox command outstanding, the HBA shall be put | |
1210 | * to offline. | |
1211 | **/ | |
858c9f6c JS |
1212 | void |
1213 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) | |
1214 | { | |
45ed1190 | 1215 | struct lpfc_vport **vports; |
858c9f6c | 1216 | LPFC_MBOXQ_t *pmboxq; |
0ff10d46 | 1217 | struct lpfc_dmabuf *buf_ptr; |
45ed1190 | 1218 | int retval, i; |
858c9f6c | 1219 | struct lpfc_sli *psli = &phba->sli; |
0ff10d46 | 1220 | LIST_HEAD(completions); |
858c9f6c | 1221 | |
45ed1190 JS |
1222 | vports = lpfc_create_vport_work_array(phba); |
1223 | if (vports != NULL) | |
4258e98e | 1224 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
45ed1190 | 1225 | lpfc_rcv_seq_check_edtov(vports[i]); |
4258e98e JS |
1226 | lpfc_fdmi_num_disc_check(vports[i]); |
1227 | } | |
45ed1190 JS |
1228 | lpfc_destroy_vport_work_array(phba, vports); |
1229 | ||
858c9f6c | 1230 | if ((phba->link_state == LPFC_HBA_ERROR) || |
51ef4c26 | 1231 | (phba->pport->load_flag & FC_UNLOADING) || |
858c9f6c JS |
1232 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
1233 | return; | |
1234 | ||
1235 | spin_lock_irq(&phba->pport->work_port_lock); | |
858c9f6c | 1236 | |
256ec0d0 JS |
1237 | if (time_after(phba->last_completion_time + |
1238 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), | |
1239 | jiffies)) { | |
858c9f6c JS |
1240 | spin_unlock_irq(&phba->pport->work_port_lock); |
1241 | if (!phba->hb_outstanding) | |
1242 | mod_timer(&phba->hb_tmofunc, | |
256ec0d0 JS |
1243 | jiffies + |
1244 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); | |
858c9f6c JS |
1245 | else |
1246 | mod_timer(&phba->hb_tmofunc, | |
256ec0d0 JS |
1247 | jiffies + |
1248 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); | |
858c9f6c JS |
1249 | return; |
1250 | } | |
1251 | spin_unlock_irq(&phba->pport->work_port_lock); | |
1252 | ||
0ff10d46 JS |
1253 | if (phba->elsbuf_cnt && |
1254 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { | |
1255 | spin_lock_irq(&phba->hbalock); | |
1256 | list_splice_init(&phba->elsbuf, &completions); | |
1257 | phba->elsbuf_cnt = 0; | |
1258 | phba->elsbuf_prev_cnt = 0; | |
1259 | spin_unlock_irq(&phba->hbalock); | |
1260 | ||
1261 | while (!list_empty(&completions)) { | |
1262 | list_remove_head(&completions, buf_ptr, | |
1263 | struct lpfc_dmabuf, list); | |
1264 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
1265 | kfree(buf_ptr); | |
1266 | } | |
1267 | } | |
1268 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; | |
1269 | ||
858c9f6c | 1270 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
13815c83 JS |
1271 | if (phba->cfg_enable_hba_heartbeat) { |
1272 | if (!phba->hb_outstanding) { | |
bc73905a JS |
1273 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
1274 | (list_empty(&psli->mboxq))) { | |
1275 | pmboxq = mempool_alloc(phba->mbox_mem_pool, | |
1276 | GFP_KERNEL); | |
1277 | if (!pmboxq) { | |
1278 | mod_timer(&phba->hb_tmofunc, | |
1279 | jiffies + | |
256ec0d0 JS |
1280 | msecs_to_jiffies(1000 * |
1281 | LPFC_HB_MBOX_INTERVAL)); | |
bc73905a JS |
1282 | return; |
1283 | } | |
1284 | ||
1285 | lpfc_heart_beat(phba, pmboxq); | |
1286 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; | |
1287 | pmboxq->vport = phba->pport; | |
1288 | retval = lpfc_sli_issue_mbox(phba, pmboxq, | |
1289 | MBX_NOWAIT); | |
1290 | ||
1291 | if (retval != MBX_BUSY && | |
1292 | retval != MBX_SUCCESS) { | |
1293 | mempool_free(pmboxq, | |
1294 | phba->mbox_mem_pool); | |
1295 | mod_timer(&phba->hb_tmofunc, | |
1296 | jiffies + | |
256ec0d0 JS |
1297 | msecs_to_jiffies(1000 * |
1298 | LPFC_HB_MBOX_INTERVAL)); | |
bc73905a JS |
1299 | return; |
1300 | } | |
1301 | phba->skipped_hb = 0; | |
1302 | phba->hb_outstanding = 1; | |
1303 | } else if (time_before_eq(phba->last_completion_time, | |
1304 | phba->skipped_hb)) { | |
1305 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
1306 | "2857 Last completion time not " | |
1307 | " updated in %d ms\n", | |
1308 | jiffies_to_msecs(jiffies | |
1309 | - phba->last_completion_time)); | |
1310 | } else | |
1311 | phba->skipped_hb = jiffies; | |
1312 | ||
858c9f6c | 1313 | mod_timer(&phba->hb_tmofunc, |
256ec0d0 JS |
1314 | jiffies + |
1315 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); | |
858c9f6c | 1316 | return; |
13815c83 JS |
1317 | } else { |
1318 | /* | |
1319 | * If heart beat timeout called with hb_outstanding set | |
dcf2a4e0 JS |
1320 | * we need to give the hb mailbox cmd a chance to |
1321 | * complete or TMO. | |
13815c83 | 1322 | */ |
dcf2a4e0 JS |
1323 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
1324 | "0459 Adapter heartbeat still out" | |
1325 | "standing:last compl time was %d ms.\n", | |
1326 | jiffies_to_msecs(jiffies | |
1327 | - phba->last_completion_time)); | |
1328 | mod_timer(&phba->hb_tmofunc, | |
256ec0d0 JS |
1329 | jiffies + |
1330 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); | |
858c9f6c | 1331 | } |
4258e98e JS |
1332 | } else { |
1333 | mod_timer(&phba->hb_tmofunc, | |
1334 | jiffies + | |
1335 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); | |
858c9f6c JS |
1336 | } |
1337 | } | |
1338 | ||
e59058c4 | 1339 | /** |
3621a710 | 1340 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
e59058c4 JS |
1341 | * @phba: pointer to lpfc hba data structure. |
1342 | * | |
1343 | * This routine is called to bring the HBA offline when HBA hardware error | |
1344 | * other than Port Error 6 has been detected. | |
1345 | **/ | |
09372820 JS |
1346 | static void |
1347 | lpfc_offline_eratt(struct lpfc_hba *phba) | |
1348 | { | |
1349 | struct lpfc_sli *psli = &phba->sli; | |
1350 | ||
1351 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1352 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
09372820 | 1353 | spin_unlock_irq(&phba->hbalock); |
618a5230 | 1354 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
09372820 JS |
1355 | |
1356 | lpfc_offline(phba); | |
1357 | lpfc_reset_barrier(phba); | |
f4b4c68f | 1358 | spin_lock_irq(&phba->hbalock); |
09372820 | 1359 | lpfc_sli_brdreset(phba); |
f4b4c68f | 1360 | spin_unlock_irq(&phba->hbalock); |
09372820 JS |
1361 | lpfc_hba_down_post(phba); |
1362 | lpfc_sli_brdready(phba, HS_MBRDY); | |
1363 | lpfc_unblock_mgmt_io(phba); | |
1364 | phba->link_state = LPFC_HBA_ERROR; | |
1365 | return; | |
1366 | } | |
1367 | ||
da0436e9 JS |
1368 | /** |
1369 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention | |
1370 | * @phba: pointer to lpfc hba data structure. | |
1371 | * | |
1372 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error | |
1373 | * other than Port Error 6 has been detected. | |
1374 | **/ | |
a88dbb6a | 1375 | void |
da0436e9 JS |
1376 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
1377 | { | |
946727dc JS |
1378 | spin_lock_irq(&phba->hbalock); |
1379 | phba->link_state = LPFC_HBA_ERROR; | |
1380 | spin_unlock_irq(&phba->hbalock); | |
1381 | ||
618a5230 | 1382 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
da0436e9 | 1383 | lpfc_offline(phba); |
da0436e9 | 1384 | lpfc_hba_down_post(phba); |
da0436e9 | 1385 | lpfc_unblock_mgmt_io(phba); |
da0436e9 JS |
1386 | } |
1387 | ||
a257bf90 JS |
1388 | /** |
1389 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler | |
1390 | * @phba: pointer to lpfc hba data structure. | |
1391 | * | |
1392 | * This routine is invoked to handle the deferred HBA hardware error | |
1393 | * conditions. This type of error is indicated by HBA by setting ER1 | |
1394 | * and another ER bit in the host status register. The driver will | |
1395 | * wait until the ER1 bit clears before handling the error condition. | |
1396 | **/ | |
1397 | static void | |
1398 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) | |
1399 | { | |
1400 | uint32_t old_host_status = phba->work_hs; | |
a257bf90 JS |
1401 | struct lpfc_sli *psli = &phba->sli; |
1402 | ||
f4b4c68f JS |
1403 | /* If the pci channel is offline, ignore possible errors, |
1404 | * since we cannot communicate with the pci card anyway. | |
1405 | */ | |
1406 | if (pci_channel_offline(phba->pcidev)) { | |
1407 | spin_lock_irq(&phba->hbalock); | |
1408 | phba->hba_flag &= ~DEFER_ERATT; | |
1409 | spin_unlock_irq(&phba->hbalock); | |
1410 | return; | |
1411 | } | |
1412 | ||
a257bf90 JS |
1413 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
1414 | "0479 Deferred Adapter Hardware Error " | |
1415 | "Data: x%x x%x x%x\n", | |
1416 | phba->work_hs, | |
1417 | phba->work_status[0], phba->work_status[1]); | |
1418 | ||
1419 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1420 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
a257bf90 JS |
1421 | spin_unlock_irq(&phba->hbalock); |
1422 | ||
1423 | ||
1424 | /* | |
1425 | * Firmware stops when it triggred erratt. That could cause the I/Os | |
1426 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the | |
1427 | * SCSI layer retry it after re-establishing link. | |
1428 | */ | |
db55fba8 | 1429 | lpfc_sli_abort_fcp_rings(phba); |
a257bf90 JS |
1430 | |
1431 | /* | |
1432 | * There was a firmware error. Take the hba offline and then | |
1433 | * attempt to restart it. | |
1434 | */ | |
618a5230 | 1435 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
a257bf90 JS |
1436 | lpfc_offline(phba); |
1437 | ||
1438 | /* Wait for the ER1 bit to clear.*/ | |
1439 | while (phba->work_hs & HS_FFER1) { | |
1440 | msleep(100); | |
9940b97b JS |
1441 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
1442 | phba->work_hs = UNPLUG_ERR ; | |
1443 | break; | |
1444 | } | |
a257bf90 JS |
1445 | /* If driver is unloading let the worker thread continue */ |
1446 | if (phba->pport->load_flag & FC_UNLOADING) { | |
1447 | phba->work_hs = 0; | |
1448 | break; | |
1449 | } | |
1450 | } | |
1451 | ||
1452 | /* | |
1453 | * This is to ptrotect against a race condition in which | |
1454 | * first write to the host attention register clear the | |
1455 | * host status register. | |
1456 | */ | |
1457 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) | |
1458 | phba->work_hs = old_host_status & ~HS_FFER1; | |
1459 | ||
3772a991 | 1460 | spin_lock_irq(&phba->hbalock); |
a257bf90 | 1461 | phba->hba_flag &= ~DEFER_ERATT; |
3772a991 | 1462 | spin_unlock_irq(&phba->hbalock); |
a257bf90 JS |
1463 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
1464 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); | |
1465 | } | |
1466 | ||
3772a991 JS |
1467 | static void |
1468 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) | |
1469 | { | |
1470 | struct lpfc_board_event_header board_event; | |
1471 | struct Scsi_Host *shost; | |
1472 | ||
1473 | board_event.event_type = FC_REG_BOARD_EVENT; | |
1474 | board_event.subcategory = LPFC_EVENT_PORTINTERR; | |
1475 | shost = lpfc_shost_from_vport(phba->pport); | |
1476 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1477 | sizeof(board_event), | |
1478 | (char *) &board_event, | |
1479 | LPFC_NL_VENDOR_ID); | |
1480 | } | |
1481 | ||
e59058c4 | 1482 | /** |
3772a991 | 1483 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
e59058c4 JS |
1484 | * @phba: pointer to lpfc hba data structure. |
1485 | * | |
1486 | * This routine is invoked to handle the following HBA hardware error | |
1487 | * conditions: | |
1488 | * 1 - HBA error attention interrupt | |
1489 | * 2 - DMA ring index out of range | |
1490 | * 3 - Mailbox command came back as unknown | |
1491 | **/ | |
3772a991 JS |
1492 | static void |
1493 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) | |
dea3101e | 1494 | { |
2e0fef85 | 1495 | struct lpfc_vport *vport = phba->pport; |
2e0fef85 | 1496 | struct lpfc_sli *psli = &phba->sli; |
d2873e4c | 1497 | uint32_t event_data; |
57127f15 JS |
1498 | unsigned long temperature; |
1499 | struct temp_event temp_event_data; | |
92d7f7b0 | 1500 | struct Scsi_Host *shost; |
2e0fef85 | 1501 | |
8d63f375 | 1502 | /* If the pci channel is offline, ignore possible errors, |
3772a991 JS |
1503 | * since we cannot communicate with the pci card anyway. |
1504 | */ | |
1505 | if (pci_channel_offline(phba->pcidev)) { | |
1506 | spin_lock_irq(&phba->hbalock); | |
1507 | phba->hba_flag &= ~DEFER_ERATT; | |
1508 | spin_unlock_irq(&phba->hbalock); | |
8d63f375 | 1509 | return; |
3772a991 JS |
1510 | } |
1511 | ||
13815c83 JS |
1512 | /* If resets are disabled then leave the HBA alone and return */ |
1513 | if (!phba->cfg_enable_hba_reset) | |
1514 | return; | |
dea3101e | 1515 | |
ea2151b4 | 1516 | /* Send an internal error event to mgmt application */ |
3772a991 | 1517 | lpfc_board_errevt_to_mgmt(phba); |
ea2151b4 | 1518 | |
a257bf90 JS |
1519 | if (phba->hba_flag & DEFER_ERATT) |
1520 | lpfc_handle_deferred_eratt(phba); | |
1521 | ||
dcf2a4e0 JS |
1522 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
1523 | if (phba->work_hs & HS_FFER6) | |
1524 | /* Re-establishing Link */ | |
1525 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
1526 | "1301 Re-establishing Link " | |
1527 | "Data: x%x x%x x%x\n", | |
1528 | phba->work_hs, phba->work_status[0], | |
1529 | phba->work_status[1]); | |
1530 | if (phba->work_hs & HS_FFER8) | |
1531 | /* Device Zeroization */ | |
1532 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
1533 | "2861 Host Authentication device " | |
1534 | "zeroization Data:x%x x%x x%x\n", | |
1535 | phba->work_hs, phba->work_status[0], | |
1536 | phba->work_status[1]); | |
58da1ffb | 1537 | |
92d7f7b0 | 1538 | spin_lock_irq(&phba->hbalock); |
f4b4c68f | 1539 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
92d7f7b0 | 1540 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1541 | |
1542 | /* | |
1543 | * Firmware stops when it triggled erratt with HS_FFER6. | |
1544 | * That could cause the I/Os dropped by the firmware. | |
1545 | * Error iocb (I/O) on txcmplq and let the SCSI layer | |
1546 | * retry it after re-establishing link. | |
1547 | */ | |
db55fba8 | 1548 | lpfc_sli_abort_fcp_rings(phba); |
dea3101e | 1549 | |
dea3101e JB |
1550 | /* |
1551 | * There was a firmware error. Take the hba offline and then | |
1552 | * attempt to restart it. | |
1553 | */ | |
618a5230 | 1554 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
dea3101e | 1555 | lpfc_offline(phba); |
41415862 | 1556 | lpfc_sli_brdrestart(phba); |
dea3101e | 1557 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
46fa311e | 1558 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
1559 | return; |
1560 | } | |
46fa311e | 1561 | lpfc_unblock_mgmt_io(phba); |
57127f15 JS |
1562 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
1563 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); | |
1564 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
1565 | temp_event_data.event_code = LPFC_CRIT_TEMP; | |
1566 | temp_event_data.data = (uint32_t)temperature; | |
1567 | ||
1568 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 1569 | "0406 Adapter maximum temperature exceeded " |
57127f15 JS |
1570 | "(%ld), taking this port offline " |
1571 | "Data: x%x x%x x%x\n", | |
1572 | temperature, phba->work_hs, | |
1573 | phba->work_status[0], phba->work_status[1]); | |
1574 | ||
1575 | shost = lpfc_shost_from_vport(phba->pport); | |
1576 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1577 | sizeof(temp_event_data), | |
1578 | (char *) &temp_event_data, | |
1579 | SCSI_NL_VID_TYPE_PCI | |
1580 | | PCI_VENDOR_ID_EMULEX); | |
1581 | ||
7af67051 | 1582 | spin_lock_irq(&phba->hbalock); |
7af67051 JS |
1583 | phba->over_temp_state = HBA_OVER_TEMP; |
1584 | spin_unlock_irq(&phba->hbalock); | |
09372820 | 1585 | lpfc_offline_eratt(phba); |
57127f15 | 1586 | |
dea3101e JB |
1587 | } else { |
1588 | /* The if clause above forces this code path when the status | |
9399627f JS |
1589 | * failure is a value other than FFER6. Do not call the offline |
1590 | * twice. This is the adapter hardware error path. | |
dea3101e JB |
1591 | */ |
1592 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 | 1593 | "0457 Adapter Hardware Error " |
dea3101e | 1594 | "Data: x%x x%x x%x\n", |
e8b62011 | 1595 | phba->work_hs, |
dea3101e JB |
1596 | phba->work_status[0], phba->work_status[1]); |
1597 | ||
d2873e4c | 1598 | event_data = FC_REG_DUMP_EVENT; |
92d7f7b0 | 1599 | shost = lpfc_shost_from_vport(vport); |
2e0fef85 | 1600 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
d2873e4c JS |
1601 | sizeof(event_data), (char *) &event_data, |
1602 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
1603 | ||
09372820 | 1604 | lpfc_offline_eratt(phba); |
dea3101e | 1605 | } |
9399627f | 1606 | return; |
dea3101e JB |
1607 | } |
1608 | ||
618a5230 JS |
1609 | /** |
1610 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg | |
1611 | * @phba: pointer to lpfc hba data structure. | |
1612 | * @mbx_action: flag for mailbox shutdown action. | |
1613 | * | |
1614 | * This routine is invoked to perform an SLI4 port PCI function reset in | |
1615 | * response to port status register polling attention. It waits for port | |
1616 | * status register (ERR, RDY, RN) bits before proceeding with function reset. | |
1617 | * During this process, interrupt vectors are freed and later requested | |
1618 | * for handling possible port resource change. | |
1619 | **/ | |
1620 | static int | |
e10b2022 JS |
1621 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action, |
1622 | bool en_rn_msg) | |
618a5230 JS |
1623 | { |
1624 | int rc; | |
1625 | uint32_t intr_mode; | |
1626 | ||
65791f1f JS |
1627 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == |
1628 | LPFC_SLI_INTF_IF_TYPE_2) { | |
1629 | /* | |
1630 | * On error status condition, driver need to wait for port | |
1631 | * ready before performing reset. | |
1632 | */ | |
1633 | rc = lpfc_sli4_pdev_status_reg_wait(phba); | |
0e916ee7 | 1634 | if (rc) |
65791f1f JS |
1635 | return rc; |
1636 | } | |
0e916ee7 | 1637 | |
65791f1f JS |
1638 | /* need reset: attempt for port recovery */ |
1639 | if (en_rn_msg) | |
1640 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1641 | "2887 Reset Needed: Attempting Port " | |
1642 | "Recovery...\n"); | |
1643 | lpfc_offline_prep(phba, mbx_action); | |
1644 | lpfc_offline(phba); | |
1645 | /* release interrupt for possible resource change */ | |
1646 | lpfc_sli4_disable_intr(phba); | |
1647 | lpfc_sli_brdrestart(phba); | |
1648 | /* request and enable interrupt */ | |
1649 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); | |
1650 | if (intr_mode == LPFC_INTR_ERROR) { | |
1651 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1652 | "3175 Failed to enable interrupt\n"); | |
1653 | return -EIO; | |
618a5230 | 1654 | } |
65791f1f JS |
1655 | phba->intr_mode = intr_mode; |
1656 | rc = lpfc_online(phba); | |
1657 | if (rc == 0) | |
1658 | lpfc_unblock_mgmt_io(phba); | |
1659 | ||
618a5230 JS |
1660 | return rc; |
1661 | } | |
1662 | ||
da0436e9 JS |
1663 | /** |
1664 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler | |
1665 | * @phba: pointer to lpfc hba data structure. | |
1666 | * | |
1667 | * This routine is invoked to handle the SLI4 HBA hardware error attention | |
1668 | * conditions. | |
1669 | **/ | |
1670 | static void | |
1671 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) | |
1672 | { | |
1673 | struct lpfc_vport *vport = phba->pport; | |
1674 | uint32_t event_data; | |
1675 | struct Scsi_Host *shost; | |
2fcee4bf | 1676 | uint32_t if_type; |
2e90f4b5 JS |
1677 | struct lpfc_register portstat_reg = {0}; |
1678 | uint32_t reg_err1, reg_err2; | |
1679 | uint32_t uerrlo_reg, uemasklo_reg; | |
65791f1f | 1680 | uint32_t smphr_port_status = 0, pci_rd_rc1, pci_rd_rc2; |
e10b2022 | 1681 | bool en_rn_msg = true; |
946727dc | 1682 | struct temp_event temp_event_data; |
65791f1f JS |
1683 | struct lpfc_register portsmphr_reg; |
1684 | int rc, i; | |
da0436e9 JS |
1685 | |
1686 | /* If the pci channel is offline, ignore possible errors, since | |
1687 | * we cannot communicate with the pci card anyway. | |
1688 | */ | |
1689 | if (pci_channel_offline(phba->pcidev)) | |
1690 | return; | |
da0436e9 | 1691 | |
65791f1f | 1692 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
2fcee4bf JS |
1693 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
1694 | switch (if_type) { | |
1695 | case LPFC_SLI_INTF_IF_TYPE_0: | |
2e90f4b5 JS |
1696 | pci_rd_rc1 = lpfc_readl( |
1697 | phba->sli4_hba.u.if_type0.UERRLOregaddr, | |
1698 | &uerrlo_reg); | |
1699 | pci_rd_rc2 = lpfc_readl( | |
1700 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, | |
1701 | &uemasklo_reg); | |
1702 | /* consider PCI bus read error as pci_channel_offline */ | |
1703 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) | |
1704 | return; | |
65791f1f JS |
1705 | if (!(phba->hba_flag & HBA_RECOVERABLE_UE)) { |
1706 | lpfc_sli4_offline_eratt(phba); | |
1707 | return; | |
1708 | } | |
1709 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1710 | "7623 Checking UE recoverable"); | |
1711 | ||
1712 | for (i = 0; i < phba->sli4_hba.ue_to_sr / 1000; i++) { | |
1713 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, | |
1714 | &portsmphr_reg.word0)) | |
1715 | continue; | |
1716 | ||
1717 | smphr_port_status = bf_get(lpfc_port_smphr_port_status, | |
1718 | &portsmphr_reg); | |
1719 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == | |
1720 | LPFC_PORT_SEM_UE_RECOVERABLE) | |
1721 | break; | |
1722 | /*Sleep for 1Sec, before checking SEMAPHORE */ | |
1723 | msleep(1000); | |
1724 | } | |
1725 | ||
1726 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1727 | "4827 smphr_port_status x%x : Waited %dSec", | |
1728 | smphr_port_status, i); | |
1729 | ||
1730 | /* Recoverable UE, reset the HBA device */ | |
1731 | if ((smphr_port_status & LPFC_PORT_SEM_MASK) == | |
1732 | LPFC_PORT_SEM_UE_RECOVERABLE) { | |
1733 | for (i = 0; i < 20; i++) { | |
1734 | msleep(1000); | |
1735 | if (!lpfc_readl(phba->sli4_hba.PSMPHRregaddr, | |
1736 | &portsmphr_reg.word0) && | |
1737 | (LPFC_POST_STAGE_PORT_READY == | |
1738 | bf_get(lpfc_port_smphr_port_status, | |
1739 | &portsmphr_reg))) { | |
1740 | rc = lpfc_sli4_port_sta_fn_reset(phba, | |
1741 | LPFC_MBX_NO_WAIT, en_rn_msg); | |
1742 | if (rc == 0) | |
1743 | return; | |
1744 | lpfc_printf_log(phba, | |
1745 | KERN_ERR, LOG_INIT, | |
1746 | "4215 Failed to recover UE"); | |
1747 | break; | |
1748 | } | |
1749 | } | |
1750 | } | |
1751 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1752 | "7624 Firmware not ready: Failing UE recovery," | |
1753 | " waited %dSec", i); | |
2fcee4bf JS |
1754 | lpfc_sli4_offline_eratt(phba); |
1755 | break; | |
946727dc | 1756 | |
2fcee4bf | 1757 | case LPFC_SLI_INTF_IF_TYPE_2: |
2e90f4b5 JS |
1758 | pci_rd_rc1 = lpfc_readl( |
1759 | phba->sli4_hba.u.if_type2.STATUSregaddr, | |
1760 | &portstat_reg.word0); | |
1761 | /* consider PCI bus read error as pci_channel_offline */ | |
6b5151fd JS |
1762 | if (pci_rd_rc1 == -EIO) { |
1763 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1764 | "3151 PCI bus read access failure: x%x\n", | |
1765 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); | |
2e90f4b5 | 1766 | return; |
6b5151fd | 1767 | } |
2e90f4b5 JS |
1768 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
1769 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); | |
2fcee4bf | 1770 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
2fcee4bf JS |
1771 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
1772 | "2889 Port Overtemperature event, " | |
946727dc JS |
1773 | "taking port offline Data: x%x x%x\n", |
1774 | reg_err1, reg_err2); | |
1775 | ||
310429ef | 1776 | phba->sfp_alarm |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
946727dc JS |
1777 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; |
1778 | temp_event_data.event_code = LPFC_CRIT_TEMP; | |
1779 | temp_event_data.data = 0xFFFFFFFF; | |
1780 | ||
1781 | shost = lpfc_shost_from_vport(phba->pport); | |
1782 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1783 | sizeof(temp_event_data), | |
1784 | (char *)&temp_event_data, | |
1785 | SCSI_NL_VID_TYPE_PCI | |
1786 | | PCI_VENDOR_ID_EMULEX); | |
1787 | ||
2fcee4bf JS |
1788 | spin_lock_irq(&phba->hbalock); |
1789 | phba->over_temp_state = HBA_OVER_TEMP; | |
1790 | spin_unlock_irq(&phba->hbalock); | |
1791 | lpfc_sli4_offline_eratt(phba); | |
946727dc | 1792 | return; |
2fcee4bf | 1793 | } |
2e90f4b5 | 1794 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
e10b2022 | 1795 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) { |
2e90f4b5 | 1796 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e10b2022 JS |
1797 | "3143 Port Down: Firmware Update " |
1798 | "Detected\n"); | |
1799 | en_rn_msg = false; | |
1800 | } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && | |
2e90f4b5 JS |
1801 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
1802 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1803 | "3144 Port Down: Debug Dump\n"); | |
1804 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && | |
1805 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) | |
1806 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1807 | "3145 Port Down: Provisioning\n"); | |
618a5230 | 1808 | |
946727dc JS |
1809 | /* If resets are disabled then leave the HBA alone and return */ |
1810 | if (!phba->cfg_enable_hba_reset) | |
1811 | return; | |
1812 | ||
618a5230 | 1813 | /* Check port status register for function reset */ |
e10b2022 JS |
1814 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT, |
1815 | en_rn_msg); | |
618a5230 JS |
1816 | if (rc == 0) { |
1817 | /* don't report event on forced debug dump */ | |
1818 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && | |
1819 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) | |
1820 | return; | |
1821 | else | |
1822 | break; | |
2fcee4bf | 1823 | } |
618a5230 | 1824 | /* fall through for not able to recover */ |
6b5151fd JS |
1825 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
1826 | "3152 Unrecoverable error, bring the port " | |
1827 | "offline\n"); | |
2fcee4bf JS |
1828 | lpfc_sli4_offline_eratt(phba); |
1829 | break; | |
1830 | case LPFC_SLI_INTF_IF_TYPE_1: | |
1831 | default: | |
1832 | break; | |
1833 | } | |
2e90f4b5 JS |
1834 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
1835 | "3123 Report dump event to upper layer\n"); | |
1836 | /* Send an internal error event to mgmt application */ | |
1837 | lpfc_board_errevt_to_mgmt(phba); | |
1838 | ||
1839 | event_data = FC_REG_DUMP_EVENT; | |
1840 | shost = lpfc_shost_from_vport(vport); | |
1841 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1842 | sizeof(event_data), (char *) &event_data, | |
1843 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
da0436e9 JS |
1844 | } |
1845 | ||
1846 | /** | |
1847 | * lpfc_handle_eratt - Wrapper func for handling hba error attention | |
1848 | * @phba: pointer to lpfc HBA data structure. | |
1849 | * | |
1850 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling | |
1851 | * routine from the API jump table function pointer from the lpfc_hba struct. | |
1852 | * | |
1853 | * Return codes | |
af901ca1 | 1854 | * 0 - success. |
da0436e9 JS |
1855 | * Any other value - error. |
1856 | **/ | |
1857 | void | |
1858 | lpfc_handle_eratt(struct lpfc_hba *phba) | |
1859 | { | |
1860 | (*phba->lpfc_handle_eratt)(phba); | |
1861 | } | |
1862 | ||
e59058c4 | 1863 | /** |
3621a710 | 1864 | * lpfc_handle_latt - The HBA link event handler |
e59058c4 JS |
1865 | * @phba: pointer to lpfc hba data structure. |
1866 | * | |
1867 | * This routine is invoked from the worker thread to handle a HBA host | |
895427bd | 1868 | * attention link event. SLI3 only. |
e59058c4 | 1869 | **/ |
dea3101e | 1870 | void |
2e0fef85 | 1871 | lpfc_handle_latt(struct lpfc_hba *phba) |
dea3101e | 1872 | { |
2e0fef85 JS |
1873 | struct lpfc_vport *vport = phba->pport; |
1874 | struct lpfc_sli *psli = &phba->sli; | |
dea3101e JB |
1875 | LPFC_MBOXQ_t *pmb; |
1876 | volatile uint32_t control; | |
1877 | struct lpfc_dmabuf *mp; | |
09372820 | 1878 | int rc = 0; |
dea3101e JB |
1879 | |
1880 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
09372820 JS |
1881 | if (!pmb) { |
1882 | rc = 1; | |
dea3101e | 1883 | goto lpfc_handle_latt_err_exit; |
09372820 | 1884 | } |
dea3101e JB |
1885 | |
1886 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
09372820 JS |
1887 | if (!mp) { |
1888 | rc = 2; | |
dea3101e | 1889 | goto lpfc_handle_latt_free_pmb; |
09372820 | 1890 | } |
dea3101e JB |
1891 | |
1892 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
09372820 JS |
1893 | if (!mp->virt) { |
1894 | rc = 3; | |
dea3101e | 1895 | goto lpfc_handle_latt_free_mp; |
09372820 | 1896 | } |
dea3101e | 1897 | |
6281bfe0 | 1898 | /* Cleanup any outstanding ELS commands */ |
549e55cd | 1899 | lpfc_els_flush_all_cmd(phba); |
dea3101e JB |
1900 | |
1901 | psli->slistat.link_event++; | |
76a95d75 JS |
1902 | lpfc_read_topology(phba, pmb, mp); |
1903 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
2e0fef85 | 1904 | pmb->vport = vport; |
0d2b6b83 | 1905 | /* Block ELS IOCBs until we have processed this mbox command */ |
895427bd | 1906 | phba->sli.sli3_ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; |
0b727fea | 1907 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
09372820 JS |
1908 | if (rc == MBX_NOT_FINISHED) { |
1909 | rc = 4; | |
14691150 | 1910 | goto lpfc_handle_latt_free_mbuf; |
09372820 | 1911 | } |
dea3101e JB |
1912 | |
1913 | /* Clear Link Attention in HA REG */ | |
2e0fef85 | 1914 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1915 | writel(HA_LATT, phba->HAregaddr); |
1916 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1917 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1918 | |
1919 | return; | |
1920 | ||
14691150 | 1921 | lpfc_handle_latt_free_mbuf: |
895427bd | 1922 | phba->sli.sli3_ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
14691150 | 1923 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
dea3101e JB |
1924 | lpfc_handle_latt_free_mp: |
1925 | kfree(mp); | |
1926 | lpfc_handle_latt_free_pmb: | |
1dcb58e5 | 1927 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e JB |
1928 | lpfc_handle_latt_err_exit: |
1929 | /* Enable Link attention interrupts */ | |
2e0fef85 | 1930 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1931 | psli->sli_flag |= LPFC_PROCESS_LA; |
1932 | control = readl(phba->HCregaddr); | |
1933 | control |= HC_LAINT_ENA; | |
1934 | writel(control, phba->HCregaddr); | |
1935 | readl(phba->HCregaddr); /* flush */ | |
1936 | ||
1937 | /* Clear Link Attention in HA REG */ | |
1938 | writel(HA_LATT, phba->HAregaddr); | |
1939 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1940 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1941 | lpfc_linkdown(phba); |
2e0fef85 | 1942 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 1943 | |
09372820 JS |
1944 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
1945 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); | |
dea3101e JB |
1946 | |
1947 | return; | |
1948 | } | |
1949 | ||
e59058c4 | 1950 | /** |
3621a710 | 1951 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
e59058c4 JS |
1952 | * @phba: pointer to lpfc hba data structure. |
1953 | * @vpd: pointer to the vital product data. | |
1954 | * @len: length of the vital product data in bytes. | |
1955 | * | |
1956 | * This routine parses the Vital Product Data (VPD). The VPD is treated as | |
1957 | * an array of characters. In this routine, the ModelName, ProgramType, and | |
1958 | * ModelDesc, etc. fields of the phba data structure will be populated. | |
1959 | * | |
1960 | * Return codes | |
1961 | * 0 - pointer to the VPD passed in is NULL | |
1962 | * 1 - success | |
1963 | **/ | |
3772a991 | 1964 | int |
2e0fef85 | 1965 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
dea3101e JB |
1966 | { |
1967 | uint8_t lenlo, lenhi; | |
07da60c1 | 1968 | int Length; |
dea3101e JB |
1969 | int i, j; |
1970 | int finished = 0; | |
1971 | int index = 0; | |
1972 | ||
1973 | if (!vpd) | |
1974 | return 0; | |
1975 | ||
1976 | /* Vital Product */ | |
ed957684 | 1977 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
e8b62011 | 1978 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
dea3101e JB |
1979 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
1980 | (uint32_t) vpd[3]); | |
74b72a59 | 1981 | while (!finished && (index < (len - 4))) { |
dea3101e JB |
1982 | switch (vpd[index]) { |
1983 | case 0x82: | |
74b72a59 | 1984 | case 0x91: |
dea3101e JB |
1985 | index += 1; |
1986 | lenlo = vpd[index]; | |
1987 | index += 1; | |
1988 | lenhi = vpd[index]; | |
1989 | index += 1; | |
1990 | i = ((((unsigned short)lenhi) << 8) + lenlo); | |
1991 | index += i; | |
1992 | break; | |
1993 | case 0x90: | |
1994 | index += 1; | |
1995 | lenlo = vpd[index]; | |
1996 | index += 1; | |
1997 | lenhi = vpd[index]; | |
1998 | index += 1; | |
1999 | Length = ((((unsigned short)lenhi) << 8) + lenlo); | |
74b72a59 JW |
2000 | if (Length > len - index) |
2001 | Length = len - index; | |
dea3101e JB |
2002 | while (Length > 0) { |
2003 | /* Look for Serial Number */ | |
2004 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { | |
2005 | index += 2; | |
2006 | i = vpd[index]; | |
2007 | index += 1; | |
2008 | j = 0; | |
2009 | Length -= (3+i); | |
2010 | while(i--) { | |
2011 | phba->SerialNumber[j++] = vpd[index++]; | |
2012 | if (j == 31) | |
2013 | break; | |
2014 | } | |
2015 | phba->SerialNumber[j] = 0; | |
2016 | continue; | |
2017 | } | |
2018 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { | |
2019 | phba->vpd_flag |= VPD_MODEL_DESC; | |
2020 | index += 2; | |
2021 | i = vpd[index]; | |
2022 | index += 1; | |
2023 | j = 0; | |
2024 | Length -= (3+i); | |
2025 | while(i--) { | |
2026 | phba->ModelDesc[j++] = vpd[index++]; | |
2027 | if (j == 255) | |
2028 | break; | |
2029 | } | |
2030 | phba->ModelDesc[j] = 0; | |
2031 | continue; | |
2032 | } | |
2033 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { | |
2034 | phba->vpd_flag |= VPD_MODEL_NAME; | |
2035 | index += 2; | |
2036 | i = vpd[index]; | |
2037 | index += 1; | |
2038 | j = 0; | |
2039 | Length -= (3+i); | |
2040 | while(i--) { | |
2041 | phba->ModelName[j++] = vpd[index++]; | |
2042 | if (j == 79) | |
2043 | break; | |
2044 | } | |
2045 | phba->ModelName[j] = 0; | |
2046 | continue; | |
2047 | } | |
2048 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { | |
2049 | phba->vpd_flag |= VPD_PROGRAM_TYPE; | |
2050 | index += 2; | |
2051 | i = vpd[index]; | |
2052 | index += 1; | |
2053 | j = 0; | |
2054 | Length -= (3+i); | |
2055 | while(i--) { | |
2056 | phba->ProgramType[j++] = vpd[index++]; | |
2057 | if (j == 255) | |
2058 | break; | |
2059 | } | |
2060 | phba->ProgramType[j] = 0; | |
2061 | continue; | |
2062 | } | |
2063 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { | |
2064 | phba->vpd_flag |= VPD_PORT; | |
2065 | index += 2; | |
2066 | i = vpd[index]; | |
2067 | index += 1; | |
2068 | j = 0; | |
2069 | Length -= (3+i); | |
2070 | while(i--) { | |
cd1c8301 JS |
2071 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
2072 | (phba->sli4_hba.pport_name_sta == | |
2073 | LPFC_SLI4_PPNAME_GET)) { | |
2074 | j++; | |
2075 | index++; | |
2076 | } else | |
2077 | phba->Port[j++] = vpd[index++]; | |
2078 | if (j == 19) | |
2079 | break; | |
dea3101e | 2080 | } |
cd1c8301 JS |
2081 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
2082 | (phba->sli4_hba.pport_name_sta == | |
2083 | LPFC_SLI4_PPNAME_NON)) | |
2084 | phba->Port[j] = 0; | |
dea3101e JB |
2085 | continue; |
2086 | } | |
2087 | else { | |
2088 | index += 2; | |
2089 | i = vpd[index]; | |
2090 | index += 1; | |
2091 | index += i; | |
2092 | Length -= (3 + i); | |
2093 | } | |
2094 | } | |
2095 | finished = 0; | |
2096 | break; | |
2097 | case 0x78: | |
2098 | finished = 1; | |
2099 | break; | |
2100 | default: | |
2101 | index ++; | |
2102 | break; | |
2103 | } | |
74b72a59 | 2104 | } |
dea3101e JB |
2105 | |
2106 | return(1); | |
2107 | } | |
2108 | ||
e59058c4 | 2109 | /** |
3621a710 | 2110 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
e59058c4 JS |
2111 | * @phba: pointer to lpfc hba data structure. |
2112 | * @mdp: pointer to the data structure to hold the derived model name. | |
2113 | * @descp: pointer to the data structure to hold the derived description. | |
2114 | * | |
2115 | * This routine retrieves HBA's description based on its registered PCI device | |
2116 | * ID. The @descp passed into this function points to an array of 256 chars. It | |
2117 | * shall be returned with the model name, maximum speed, and the host bus type. | |
2118 | * The @mdp passed into this function points to an array of 80 chars. When the | |
2119 | * function returns, the @mdp will be filled with the model name. | |
2120 | **/ | |
dea3101e | 2121 | static void |
2e0fef85 | 2122 | lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) |
dea3101e JB |
2123 | { |
2124 | lpfc_vpd_t *vp; | |
fefcb2b6 | 2125 | uint16_t dev_id = phba->pcidev->device; |
74b72a59 | 2126 | int max_speed; |
84774a4d | 2127 | int GE = 0; |
da0436e9 | 2128 | int oneConnect = 0; /* default is not a oneConnect */ |
74b72a59 | 2129 | struct { |
a747c9ce JS |
2130 | char *name; |
2131 | char *bus; | |
2132 | char *function; | |
2133 | } m = {"<Unknown>", "", ""}; | |
74b72a59 JW |
2134 | |
2135 | if (mdp && mdp[0] != '\0' | |
2136 | && descp && descp[0] != '\0') | |
2137 | return; | |
2138 | ||
d38dd52c JS |
2139 | if (phba->lmt & LMT_32Gb) |
2140 | max_speed = 32; | |
2141 | else if (phba->lmt & LMT_16Gb) | |
c0c11512 JS |
2142 | max_speed = 16; |
2143 | else if (phba->lmt & LMT_10Gb) | |
74b72a59 JW |
2144 | max_speed = 10; |
2145 | else if (phba->lmt & LMT_8Gb) | |
2146 | max_speed = 8; | |
2147 | else if (phba->lmt & LMT_4Gb) | |
2148 | max_speed = 4; | |
2149 | else if (phba->lmt & LMT_2Gb) | |
2150 | max_speed = 2; | |
4169d868 | 2151 | else if (phba->lmt & LMT_1Gb) |
74b72a59 | 2152 | max_speed = 1; |
4169d868 JS |
2153 | else |
2154 | max_speed = 0; | |
dea3101e JB |
2155 | |
2156 | vp = &phba->vpd; | |
dea3101e | 2157 | |
e4adb204 | 2158 | switch (dev_id) { |
06325e74 | 2159 | case PCI_DEVICE_ID_FIREFLY: |
12222f4f JS |
2160 | m = (typeof(m)){"LP6000", "PCI", |
2161 | "Obsolete, Unsupported Fibre Channel Adapter"}; | |
06325e74 | 2162 | break; |
dea3101e JB |
2163 | case PCI_DEVICE_ID_SUPERFLY: |
2164 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) | |
12222f4f | 2165 | m = (typeof(m)){"LP7000", "PCI", ""}; |
dea3101e | 2166 | else |
12222f4f JS |
2167 | m = (typeof(m)){"LP7000E", "PCI", ""}; |
2168 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; | |
dea3101e JB |
2169 | break; |
2170 | case PCI_DEVICE_ID_DRAGONFLY: | |
a747c9ce | 2171 | m = (typeof(m)){"LP8000", "PCI", |
12222f4f | 2172 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
dea3101e JB |
2173 | break; |
2174 | case PCI_DEVICE_ID_CENTAUR: | |
2175 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) | |
12222f4f | 2176 | m = (typeof(m)){"LP9002", "PCI", ""}; |
dea3101e | 2177 | else |
12222f4f JS |
2178 | m = (typeof(m)){"LP9000", "PCI", ""}; |
2179 | m.function = "Obsolete, Unsupported Fibre Channel Adapter"; | |
dea3101e JB |
2180 | break; |
2181 | case PCI_DEVICE_ID_RFLY: | |
a747c9ce | 2182 | m = (typeof(m)){"LP952", "PCI", |
12222f4f | 2183 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
dea3101e JB |
2184 | break; |
2185 | case PCI_DEVICE_ID_PEGASUS: | |
a747c9ce | 2186 | m = (typeof(m)){"LP9802", "PCI-X", |
12222f4f | 2187 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
dea3101e JB |
2188 | break; |
2189 | case PCI_DEVICE_ID_THOR: | |
a747c9ce | 2190 | m = (typeof(m)){"LP10000", "PCI-X", |
12222f4f | 2191 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
dea3101e JB |
2192 | break; |
2193 | case PCI_DEVICE_ID_VIPER: | |
a747c9ce | 2194 | m = (typeof(m)){"LPX1000", "PCI-X", |
12222f4f | 2195 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
dea3101e JB |
2196 | break; |
2197 | case PCI_DEVICE_ID_PFLY: | |
a747c9ce | 2198 | m = (typeof(m)){"LP982", "PCI-X", |
12222f4f | 2199 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
dea3101e JB |
2200 | break; |
2201 | case PCI_DEVICE_ID_TFLY: | |
a747c9ce | 2202 | m = (typeof(m)){"LP1050", "PCI-X", |
12222f4f | 2203 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
dea3101e JB |
2204 | break; |
2205 | case PCI_DEVICE_ID_HELIOS: | |
a747c9ce | 2206 | m = (typeof(m)){"LP11000", "PCI-X2", |
12222f4f | 2207 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
dea3101e | 2208 | break; |
e4adb204 | 2209 | case PCI_DEVICE_ID_HELIOS_SCSP: |
a747c9ce | 2210 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
12222f4f | 2211 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
e4adb204 JSEC |
2212 | break; |
2213 | case PCI_DEVICE_ID_HELIOS_DCSP: | |
a747c9ce | 2214 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
12222f4f | 2215 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
e4adb204 JSEC |
2216 | break; |
2217 | case PCI_DEVICE_ID_NEPTUNE: | |
12222f4f JS |
2218 | m = (typeof(m)){"LPe1000", "PCIe", |
2219 | "Obsolete, Unsupported Fibre Channel Adapter"}; | |
e4adb204 JSEC |
2220 | break; |
2221 | case PCI_DEVICE_ID_NEPTUNE_SCSP: | |
12222f4f JS |
2222 | m = (typeof(m)){"LPe1000-SP", "PCIe", |
2223 | "Obsolete, Unsupported Fibre Channel Adapter"}; | |
e4adb204 JSEC |
2224 | break; |
2225 | case PCI_DEVICE_ID_NEPTUNE_DCSP: | |
12222f4f JS |
2226 | m = (typeof(m)){"LPe1002-SP", "PCIe", |
2227 | "Obsolete, Unsupported Fibre Channel Adapter"}; | |
e4adb204 | 2228 | break; |
dea3101e | 2229 | case PCI_DEVICE_ID_BMID: |
a747c9ce | 2230 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
dea3101e JB |
2231 | break; |
2232 | case PCI_DEVICE_ID_BSMB: | |
12222f4f JS |
2233 | m = (typeof(m)){"LP111", "PCI-X2", |
2234 | "Obsolete, Unsupported Fibre Channel Adapter"}; | |
dea3101e JB |
2235 | break; |
2236 | case PCI_DEVICE_ID_ZEPHYR: | |
a747c9ce | 2237 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
dea3101e | 2238 | break; |
e4adb204 | 2239 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
a747c9ce | 2240 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
2241 | break; |
2242 | case PCI_DEVICE_ID_ZEPHYR_DCSP: | |
a747c9ce | 2243 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
a257bf90 | 2244 | GE = 1; |
e4adb204 | 2245 | break; |
dea3101e | 2246 | case PCI_DEVICE_ID_ZMID: |
a747c9ce | 2247 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
dea3101e JB |
2248 | break; |
2249 | case PCI_DEVICE_ID_ZSMB: | |
a747c9ce | 2250 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
dea3101e JB |
2251 | break; |
2252 | case PCI_DEVICE_ID_LP101: | |
12222f4f JS |
2253 | m = (typeof(m)){"LP101", "PCI-X", |
2254 | "Obsolete, Unsupported Fibre Channel Adapter"}; | |
dea3101e JB |
2255 | break; |
2256 | case PCI_DEVICE_ID_LP10000S: | |
12222f4f JS |
2257 | m = (typeof(m)){"LP10000-S", "PCI", |
2258 | "Obsolete, Unsupported Fibre Channel Adapter"}; | |
06325e74 | 2259 | break; |
e4adb204 | 2260 | case PCI_DEVICE_ID_LP11000S: |
12222f4f JS |
2261 | m = (typeof(m)){"LP11000-S", "PCI-X2", |
2262 | "Obsolete, Unsupported Fibre Channel Adapter"}; | |
18a3b596 | 2263 | break; |
e4adb204 | 2264 | case PCI_DEVICE_ID_LPE11000S: |
12222f4f JS |
2265 | m = (typeof(m)){"LPe11000-S", "PCIe", |
2266 | "Obsolete, Unsupported Fibre Channel Adapter"}; | |
5cc36b3c | 2267 | break; |
b87eab38 | 2268 | case PCI_DEVICE_ID_SAT: |
a747c9ce | 2269 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
2270 | break; |
2271 | case PCI_DEVICE_ID_SAT_MID: | |
a747c9ce | 2272 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
2273 | break; |
2274 | case PCI_DEVICE_ID_SAT_SMB: | |
a747c9ce | 2275 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
2276 | break; |
2277 | case PCI_DEVICE_ID_SAT_DCSP: | |
a747c9ce | 2278 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
2279 | break; |
2280 | case PCI_DEVICE_ID_SAT_SCSP: | |
a747c9ce | 2281 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
2282 | break; |
2283 | case PCI_DEVICE_ID_SAT_S: | |
a747c9ce | 2284 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 | 2285 | break; |
84774a4d | 2286 | case PCI_DEVICE_ID_HORNET: |
12222f4f JS |
2287 | m = (typeof(m)){"LP21000", "PCIe", |
2288 | "Obsolete, Unsupported FCoE Adapter"}; | |
84774a4d JS |
2289 | GE = 1; |
2290 | break; | |
2291 | case PCI_DEVICE_ID_PROTEUS_VF: | |
a747c9ce | 2292 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
12222f4f | 2293 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
84774a4d JS |
2294 | break; |
2295 | case PCI_DEVICE_ID_PROTEUS_PF: | |
a747c9ce | 2296 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
12222f4f | 2297 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
84774a4d JS |
2298 | break; |
2299 | case PCI_DEVICE_ID_PROTEUS_S: | |
a747c9ce | 2300 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
12222f4f | 2301 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
84774a4d | 2302 | break; |
da0436e9 JS |
2303 | case PCI_DEVICE_ID_TIGERSHARK: |
2304 | oneConnect = 1; | |
a747c9ce | 2305 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
da0436e9 | 2306 | break; |
a747c9ce | 2307 | case PCI_DEVICE_ID_TOMCAT: |
6669f9bb | 2308 | oneConnect = 1; |
a747c9ce JS |
2309 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
2310 | break; | |
2311 | case PCI_DEVICE_ID_FALCON: | |
2312 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", | |
2313 | "EmulexSecure Fibre"}; | |
6669f9bb | 2314 | break; |
98fc5dd9 JS |
2315 | case PCI_DEVICE_ID_BALIUS: |
2316 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", | |
12222f4f | 2317 | "Obsolete, Unsupported Fibre Channel Adapter"}; |
98fc5dd9 | 2318 | break; |
085c647c | 2319 | case PCI_DEVICE_ID_LANCER_FC: |
c0c11512 | 2320 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; |
085c647c | 2321 | break; |
12222f4f JS |
2322 | case PCI_DEVICE_ID_LANCER_FC_VF: |
2323 | m = (typeof(m)){"LPe16000", "PCIe", | |
2324 | "Obsolete, Unsupported Fibre Channel Adapter"}; | |
2325 | break; | |
085c647c JS |
2326 | case PCI_DEVICE_ID_LANCER_FCOE: |
2327 | oneConnect = 1; | |
079b5c91 | 2328 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
085c647c | 2329 | break; |
12222f4f JS |
2330 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
2331 | oneConnect = 1; | |
2332 | m = (typeof(m)){"OCe15100", "PCIe", | |
2333 | "Obsolete, Unsupported FCoE"}; | |
2334 | break; | |
d38dd52c JS |
2335 | case PCI_DEVICE_ID_LANCER_G6_FC: |
2336 | m = (typeof(m)){"LPe32000", "PCIe", "Fibre Channel Adapter"}; | |
2337 | break; | |
f8cafd38 JS |
2338 | case PCI_DEVICE_ID_SKYHAWK: |
2339 | case PCI_DEVICE_ID_SKYHAWK_VF: | |
2340 | oneConnect = 1; | |
2341 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; | |
2342 | break; | |
5cc36b3c | 2343 | default: |
a747c9ce | 2344 | m = (typeof(m)){"Unknown", "", ""}; |
e4adb204 | 2345 | break; |
dea3101e | 2346 | } |
74b72a59 JW |
2347 | |
2348 | if (mdp && mdp[0] == '\0') | |
2349 | snprintf(mdp, 79,"%s", m.name); | |
c0c11512 JS |
2350 | /* |
2351 | * oneConnect hba requires special processing, they are all initiators | |
da0436e9 JS |
2352 | * and we put the port number on the end |
2353 | */ | |
2354 | if (descp && descp[0] == '\0') { | |
2355 | if (oneConnect) | |
2356 | snprintf(descp, 255, | |
4169d868 | 2357 | "Emulex OneConnect %s, %s Initiator %s", |
a747c9ce | 2358 | m.name, m.function, |
da0436e9 | 2359 | phba->Port); |
4169d868 JS |
2360 | else if (max_speed == 0) |
2361 | snprintf(descp, 255, | |
290237d2 | 2362 | "Emulex %s %s %s", |
4169d868 | 2363 | m.name, m.bus, m.function); |
da0436e9 JS |
2364 | else |
2365 | snprintf(descp, 255, | |
2366 | "Emulex %s %d%s %s %s", | |
a747c9ce JS |
2367 | m.name, max_speed, (GE) ? "GE" : "Gb", |
2368 | m.bus, m.function); | |
da0436e9 | 2369 | } |
dea3101e JB |
2370 | } |
2371 | ||
e59058c4 | 2372 | /** |
3621a710 | 2373 | * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring |
e59058c4 JS |
2374 | * @phba: pointer to lpfc hba data structure. |
2375 | * @pring: pointer to a IOCB ring. | |
2376 | * @cnt: the number of IOCBs to be posted to the IOCB ring. | |
2377 | * | |
2378 | * This routine posts a given number of IOCBs with the associated DMA buffer | |
2379 | * descriptors specified by the cnt argument to the given IOCB ring. | |
2380 | * | |
2381 | * Return codes | |
2382 | * The number of IOCBs NOT able to be posted to the IOCB ring. | |
2383 | **/ | |
dea3101e | 2384 | int |
495a714c | 2385 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
dea3101e JB |
2386 | { |
2387 | IOCB_t *icmd; | |
0bd4ca25 | 2388 | struct lpfc_iocbq *iocb; |
dea3101e JB |
2389 | struct lpfc_dmabuf *mp1, *mp2; |
2390 | ||
2391 | cnt += pring->missbufcnt; | |
2392 | ||
2393 | /* While there are buffers to post */ | |
2394 | while (cnt > 0) { | |
2395 | /* Allocate buffer for command iocb */ | |
0bd4ca25 | 2396 | iocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
2397 | if (iocb == NULL) { |
2398 | pring->missbufcnt = cnt; | |
2399 | return cnt; | |
2400 | } | |
dea3101e JB |
2401 | icmd = &iocb->iocb; |
2402 | ||
2403 | /* 2 buffers can be posted per command */ | |
2404 | /* Allocate buffer to post */ | |
2405 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
2406 | if (mp1) | |
98c9ea5c JS |
2407 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
2408 | if (!mp1 || !mp1->virt) { | |
c9475cb0 | 2409 | kfree(mp1); |
604a3e30 | 2410 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
2411 | pring->missbufcnt = cnt; |
2412 | return cnt; | |
2413 | } | |
2414 | ||
2415 | INIT_LIST_HEAD(&mp1->list); | |
2416 | /* Allocate buffer to post */ | |
2417 | if (cnt > 1) { | |
2418 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
2419 | if (mp2) | |
2420 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | |
2421 | &mp2->phys); | |
98c9ea5c | 2422 | if (!mp2 || !mp2->virt) { |
c9475cb0 | 2423 | kfree(mp2); |
dea3101e JB |
2424 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
2425 | kfree(mp1); | |
604a3e30 | 2426 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
2427 | pring->missbufcnt = cnt; |
2428 | return cnt; | |
2429 | } | |
2430 | ||
2431 | INIT_LIST_HEAD(&mp2->list); | |
2432 | } else { | |
2433 | mp2 = NULL; | |
2434 | } | |
2435 | ||
2436 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); | |
2437 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); | |
2438 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; | |
2439 | icmd->ulpBdeCount = 1; | |
2440 | cnt--; | |
2441 | if (mp2) { | |
2442 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); | |
2443 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); | |
2444 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; | |
2445 | cnt--; | |
2446 | icmd->ulpBdeCount = 2; | |
2447 | } | |
2448 | ||
2449 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; | |
2450 | icmd->ulpLe = 1; | |
2451 | ||
3772a991 JS |
2452 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
2453 | IOCB_ERROR) { | |
dea3101e JB |
2454 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
2455 | kfree(mp1); | |
2456 | cnt++; | |
2457 | if (mp2) { | |
2458 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); | |
2459 | kfree(mp2); | |
2460 | cnt++; | |
2461 | } | |
604a3e30 | 2462 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e | 2463 | pring->missbufcnt = cnt; |
dea3101e JB |
2464 | return cnt; |
2465 | } | |
dea3101e | 2466 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
92d7f7b0 | 2467 | if (mp2) |
dea3101e | 2468 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
dea3101e JB |
2469 | } |
2470 | pring->missbufcnt = 0; | |
2471 | return 0; | |
2472 | } | |
2473 | ||
e59058c4 | 2474 | /** |
3621a710 | 2475 | * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring |
e59058c4 JS |
2476 | * @phba: pointer to lpfc hba data structure. |
2477 | * | |
2478 | * This routine posts initial receive IOCB buffers to the ELS ring. The | |
2479 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is | |
895427bd | 2480 | * set to 64 IOCBs. SLI3 only. |
e59058c4 JS |
2481 | * |
2482 | * Return codes | |
2483 | * 0 - success (currently always success) | |
2484 | **/ | |
dea3101e | 2485 | static int |
2e0fef85 | 2486 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
dea3101e JB |
2487 | { |
2488 | struct lpfc_sli *psli = &phba->sli; | |
2489 | ||
2490 | /* Ring 0, ELS / CT buffers */ | |
895427bd | 2491 | lpfc_post_buffer(phba, &psli->sli3_ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
dea3101e JB |
2492 | /* Ring 2 - FCP no buffers needed */ |
2493 | ||
2494 | return 0; | |
2495 | } | |
2496 | ||
2497 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) | |
2498 | ||
e59058c4 | 2499 | /** |
3621a710 | 2500 | * lpfc_sha_init - Set up initial array of hash table entries |
e59058c4 JS |
2501 | * @HashResultPointer: pointer to an array as hash table. |
2502 | * | |
2503 | * This routine sets up the initial values to the array of hash table entries | |
2504 | * for the LC HBAs. | |
2505 | **/ | |
dea3101e JB |
2506 | static void |
2507 | lpfc_sha_init(uint32_t * HashResultPointer) | |
2508 | { | |
2509 | HashResultPointer[0] = 0x67452301; | |
2510 | HashResultPointer[1] = 0xEFCDAB89; | |
2511 | HashResultPointer[2] = 0x98BADCFE; | |
2512 | HashResultPointer[3] = 0x10325476; | |
2513 | HashResultPointer[4] = 0xC3D2E1F0; | |
2514 | } | |
2515 | ||
e59058c4 | 2516 | /** |
3621a710 | 2517 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
e59058c4 JS |
2518 | * @HashResultPointer: pointer to an initial/result hash table. |
2519 | * @HashWorkingPointer: pointer to an working hash table. | |
2520 | * | |
2521 | * This routine iterates an initial hash table pointed by @HashResultPointer | |
2522 | * with the values from the working hash table pointeed by @HashWorkingPointer. | |
2523 | * The results are putting back to the initial hash table, returned through | |
2524 | * the @HashResultPointer as the result hash table. | |
2525 | **/ | |
dea3101e JB |
2526 | static void |
2527 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) | |
2528 | { | |
2529 | int t; | |
2530 | uint32_t TEMP; | |
2531 | uint32_t A, B, C, D, E; | |
2532 | t = 16; | |
2533 | do { | |
2534 | HashWorkingPointer[t] = | |
2535 | S(1, | |
2536 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - | |
2537 | 8] ^ | |
2538 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); | |
2539 | } while (++t <= 79); | |
2540 | t = 0; | |
2541 | A = HashResultPointer[0]; | |
2542 | B = HashResultPointer[1]; | |
2543 | C = HashResultPointer[2]; | |
2544 | D = HashResultPointer[3]; | |
2545 | E = HashResultPointer[4]; | |
2546 | ||
2547 | do { | |
2548 | if (t < 20) { | |
2549 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; | |
2550 | } else if (t < 40) { | |
2551 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; | |
2552 | } else if (t < 60) { | |
2553 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; | |
2554 | } else { | |
2555 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; | |
2556 | } | |
2557 | TEMP += S(5, A) + E + HashWorkingPointer[t]; | |
2558 | E = D; | |
2559 | D = C; | |
2560 | C = S(30, B); | |
2561 | B = A; | |
2562 | A = TEMP; | |
2563 | } while (++t <= 79); | |
2564 | ||
2565 | HashResultPointer[0] += A; | |
2566 | HashResultPointer[1] += B; | |
2567 | HashResultPointer[2] += C; | |
2568 | HashResultPointer[3] += D; | |
2569 | HashResultPointer[4] += E; | |
2570 | ||
2571 | } | |
2572 | ||
e59058c4 | 2573 | /** |
3621a710 | 2574 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
e59058c4 JS |
2575 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
2576 | * @HashWorking: pointer to the entry of the working hash array. | |
2577 | * | |
2578 | * This routine calculates the working hash array referred by @HashWorking | |
2579 | * from the challenge random numbers associated with the host, referred by | |
2580 | * @RandomChallenge. The result is put into the entry of the working hash | |
2581 | * array and returned by reference through @HashWorking. | |
2582 | **/ | |
dea3101e JB |
2583 | static void |
2584 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) | |
2585 | { | |
2586 | *HashWorking = (*RandomChallenge ^ *HashWorking); | |
2587 | } | |
2588 | ||
e59058c4 | 2589 | /** |
3621a710 | 2590 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
e59058c4 JS |
2591 | * @phba: pointer to lpfc hba data structure. |
2592 | * @hbainit: pointer to an array of unsigned 32-bit integers. | |
2593 | * | |
2594 | * This routine performs the special handling for LC HBA initialization. | |
2595 | **/ | |
dea3101e JB |
2596 | void |
2597 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) | |
2598 | { | |
2599 | int t; | |
2600 | uint32_t *HashWorking; | |
2e0fef85 | 2601 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
dea3101e | 2602 | |
bbfbbbc1 | 2603 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
dea3101e JB |
2604 | if (!HashWorking) |
2605 | return; | |
2606 | ||
dea3101e JB |
2607 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
2608 | HashWorking[1] = HashWorking[79] = *pwwnn; | |
2609 | ||
2610 | for (t = 0; t < 7; t++) | |
2611 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); | |
2612 | ||
2613 | lpfc_sha_init(hbainit); | |
2614 | lpfc_sha_iterate(hbainit, HashWorking); | |
2615 | kfree(HashWorking); | |
2616 | } | |
2617 | ||
e59058c4 | 2618 | /** |
3621a710 | 2619 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
e59058c4 JS |
2620 | * @vport: pointer to a virtual N_Port data structure. |
2621 | * | |
2622 | * This routine performs the necessary cleanups before deleting the @vport. | |
2623 | * It invokes the discovery state machine to perform necessary state | |
2624 | * transitions and to release the ndlps associated with the @vport. Note, | |
2625 | * the physical port is treated as @vport 0. | |
2626 | **/ | |
87af33fe | 2627 | void |
2e0fef85 | 2628 | lpfc_cleanup(struct lpfc_vport *vport) |
dea3101e | 2629 | { |
87af33fe | 2630 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2631 | struct lpfc_nodelist *ndlp, *next_ndlp; |
a8adb832 | 2632 | int i = 0; |
dea3101e | 2633 | |
87af33fe JS |
2634 | if (phba->link_state > LPFC_LINK_DOWN) |
2635 | lpfc_port_link_failure(vport); | |
2636 | ||
2637 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
2638 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
2639 | ndlp = lpfc_enable_node(vport, ndlp, | |
2640 | NLP_STE_UNUSED_NODE); | |
2641 | if (!ndlp) | |
2642 | continue; | |
2643 | spin_lock_irq(&phba->ndlp_lock); | |
2644 | NLP_SET_FREE_REQ(ndlp); | |
2645 | spin_unlock_irq(&phba->ndlp_lock); | |
2646 | /* Trigger the release of the ndlp memory */ | |
2647 | lpfc_nlp_put(ndlp); | |
2648 | continue; | |
2649 | } | |
2650 | spin_lock_irq(&phba->ndlp_lock); | |
2651 | if (NLP_CHK_FREE_REQ(ndlp)) { | |
2652 | /* The ndlp should not be in memory free mode already */ | |
2653 | spin_unlock_irq(&phba->ndlp_lock); | |
2654 | continue; | |
2655 | } else | |
2656 | /* Indicate request for freeing ndlp memory */ | |
2657 | NLP_SET_FREE_REQ(ndlp); | |
2658 | spin_unlock_irq(&phba->ndlp_lock); | |
2659 | ||
58da1ffb JS |
2660 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
2661 | ndlp->nlp_DID == Fabric_DID) { | |
2662 | /* Just free up ndlp with Fabric_DID for vports */ | |
2663 | lpfc_nlp_put(ndlp); | |
2664 | continue; | |
2665 | } | |
2666 | ||
eff4a01b JS |
2667 | /* take care of nodes in unused state before the state |
2668 | * machine taking action. | |
2669 | */ | |
2670 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { | |
2671 | lpfc_nlp_put(ndlp); | |
2672 | continue; | |
2673 | } | |
2674 | ||
87af33fe JS |
2675 | if (ndlp->nlp_type & NLP_FABRIC) |
2676 | lpfc_disc_state_machine(vport, ndlp, NULL, | |
2677 | NLP_EVT_DEVICE_RECOVERY); | |
e47c9093 | 2678 | |
a0f2d3ef JS |
2679 | if (ndlp->nlp_fc4_type & NLP_FC4_NVME) { |
2680 | /* Remove the NVME transport reference now and | |
2681 | * continue to remove the node. | |
2682 | */ | |
2683 | lpfc_nlp_put(ndlp); | |
2684 | } | |
2685 | ||
87af33fe JS |
2686 | lpfc_disc_state_machine(vport, ndlp, NULL, |
2687 | NLP_EVT_DEVICE_RM); | |
2688 | } | |
2689 | ||
a8adb832 JS |
2690 | /* At this point, ALL ndlp's should be gone |
2691 | * because of the previous NLP_EVT_DEVICE_RM. | |
2692 | * Lets wait for this to happen, if needed. | |
2693 | */ | |
87af33fe | 2694 | while (!list_empty(&vport->fc_nodes)) { |
a8adb832 | 2695 | if (i++ > 3000) { |
87af33fe | 2696 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
a8adb832 | 2697 | "0233 Nodelist not empty\n"); |
e47c9093 JS |
2698 | list_for_each_entry_safe(ndlp, next_ndlp, |
2699 | &vport->fc_nodes, nlp_listp) { | |
2700 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, | |
2701 | LOG_NODE, | |
d7c255b2 | 2702 | "0282 did:x%x ndlp:x%p " |
e47c9093 JS |
2703 | "usgmap:x%x refcnt:%d\n", |
2704 | ndlp->nlp_DID, (void *)ndlp, | |
2705 | ndlp->nlp_usg_map, | |
2c935bc5 | 2706 | kref_read(&ndlp->kref)); |
e47c9093 | 2707 | } |
a8adb832 | 2708 | break; |
87af33fe | 2709 | } |
a8adb832 JS |
2710 | |
2711 | /* Wait for any activity on ndlps to settle */ | |
2712 | msleep(10); | |
87af33fe | 2713 | } |
1151e3ec | 2714 | lpfc_cleanup_vports_rrqs(vport, NULL); |
dea3101e JB |
2715 | } |
2716 | ||
e59058c4 | 2717 | /** |
3621a710 | 2718 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
e59058c4 JS |
2719 | * @vport: pointer to a virtual N_Port data structure. |
2720 | * | |
2721 | * This routine stops all the timers associated with a @vport. This function | |
2722 | * is invoked before disabling or deleting a @vport. Note that the physical | |
2723 | * port is treated as @vport 0. | |
2724 | **/ | |
92d7f7b0 JS |
2725 | void |
2726 | lpfc_stop_vport_timers(struct lpfc_vport *vport) | |
dea3101e | 2727 | { |
92d7f7b0 | 2728 | del_timer_sync(&vport->els_tmofunc); |
92494144 | 2729 | del_timer_sync(&vport->delayed_disc_tmo); |
92d7f7b0 JS |
2730 | lpfc_can_disctmo(vport); |
2731 | return; | |
dea3101e JB |
2732 | } |
2733 | ||
ecfd03c6 JS |
2734 | /** |
2735 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2736 | * @phba: pointer to lpfc hba data structure. | |
2737 | * | |
2738 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The | |
2739 | * caller of this routine should already hold the host lock. | |
2740 | **/ | |
2741 | void | |
2742 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2743 | { | |
5ac6b303 JS |
2744 | /* Clear pending FCF rediscovery wait flag */ |
2745 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; | |
2746 | ||
ecfd03c6 JS |
2747 | /* Now, try to stop the timer */ |
2748 | del_timer(&phba->fcf.redisc_wait); | |
2749 | } | |
2750 | ||
2751 | /** | |
2752 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2753 | * @phba: pointer to lpfc hba data structure. | |
2754 | * | |
2755 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It | |
2756 | * checks whether the FCF rediscovery wait timer is pending with the host | |
2757 | * lock held before proceeding with disabling the timer and clearing the | |
2758 | * wait timer pendig flag. | |
2759 | **/ | |
2760 | void | |
2761 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2762 | { | |
2763 | spin_lock_irq(&phba->hbalock); | |
2764 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
2765 | /* FCF rediscovery timer already fired or stopped */ | |
2766 | spin_unlock_irq(&phba->hbalock); | |
2767 | return; | |
2768 | } | |
2769 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); | |
5ac6b303 JS |
2770 | /* Clear failover in progress flags */ |
2771 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); | |
ecfd03c6 JS |
2772 | spin_unlock_irq(&phba->hbalock); |
2773 | } | |
2774 | ||
e59058c4 | 2775 | /** |
3772a991 | 2776 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
e59058c4 JS |
2777 | * @phba: pointer to lpfc hba data structure. |
2778 | * | |
2779 | * This routine stops all the timers associated with a HBA. This function is | |
2780 | * invoked before either putting a HBA offline or unloading the driver. | |
2781 | **/ | |
3772a991 JS |
2782 | void |
2783 | lpfc_stop_hba_timers(struct lpfc_hba *phba) | |
dea3101e | 2784 | { |
51ef4c26 | 2785 | lpfc_stop_vport_timers(phba->pport); |
2e0fef85 | 2786 | del_timer_sync(&phba->sli.mbox_tmo); |
92d7f7b0 | 2787 | del_timer_sync(&phba->fabric_block_timer); |
9399627f | 2788 | del_timer_sync(&phba->eratt_poll); |
3772a991 | 2789 | del_timer_sync(&phba->hb_tmofunc); |
1151e3ec JS |
2790 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2791 | del_timer_sync(&phba->rrq_tmr); | |
2792 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
2793 | } | |
3772a991 JS |
2794 | phba->hb_outstanding = 0; |
2795 | ||
2796 | switch (phba->pci_dev_grp) { | |
2797 | case LPFC_PCI_DEV_LP: | |
2798 | /* Stop any LightPulse device specific driver timers */ | |
2799 | del_timer_sync(&phba->fcp_poll_timer); | |
2800 | break; | |
2801 | case LPFC_PCI_DEV_OC: | |
2802 | /* Stop any OneConnect device sepcific driver timers */ | |
ecfd03c6 | 2803 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
3772a991 JS |
2804 | break; |
2805 | default: | |
2806 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2807 | "0297 Invalid device group (x%x)\n", | |
2808 | phba->pci_dev_grp); | |
2809 | break; | |
2810 | } | |
2e0fef85 | 2811 | return; |
dea3101e JB |
2812 | } |
2813 | ||
e59058c4 | 2814 | /** |
3621a710 | 2815 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
e59058c4 JS |
2816 | * @phba: pointer to lpfc hba data structure. |
2817 | * | |
2818 | * This routine marks a HBA's management interface as blocked. Once the HBA's | |
2819 | * management interface is marked as blocked, all the user space access to | |
2820 | * the HBA, whether they are from sysfs interface or libdfc interface will | |
2821 | * all be blocked. The HBA is set to block the management interface when the | |
2822 | * driver prepares the HBA interface for online or offline. | |
2823 | **/ | |
a6ababd2 | 2824 | static void |
618a5230 | 2825 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
a6ababd2 AB |
2826 | { |
2827 | unsigned long iflag; | |
6e7288d9 JS |
2828 | uint8_t actcmd = MBX_HEARTBEAT; |
2829 | unsigned long timeout; | |
2830 | ||
a6ababd2 AB |
2831 | spin_lock_irqsave(&phba->hbalock, iflag); |
2832 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; | |
618a5230 JS |
2833 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2834 | if (mbx_action == LPFC_MBX_NO_WAIT) | |
2835 | return; | |
2836 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; | |
2837 | spin_lock_irqsave(&phba->hbalock, iflag); | |
a183a15f | 2838 | if (phba->sli.mbox_active) { |
6e7288d9 | 2839 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
a183a15f JS |
2840 | /* Determine how long we might wait for the active mailbox |
2841 | * command to be gracefully completed by firmware. | |
2842 | */ | |
2843 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
2844 | phba->sli.mbox_active) * 1000) + jiffies; | |
2845 | } | |
a6ababd2 | 2846 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a183a15f | 2847 | |
6e7288d9 JS |
2848 | /* Wait for the outstnading mailbox command to complete */ |
2849 | while (phba->sli.mbox_active) { | |
2850 | /* Check active mailbox complete status every 2ms */ | |
2851 | msleep(2); | |
2852 | if (time_after(jiffies, timeout)) { | |
2853 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2854 | "2813 Mgmt IO is Blocked %x " | |
2855 | "- mbox cmd %x still active\n", | |
2856 | phba->sli.sli_flag, actcmd); | |
2857 | break; | |
2858 | } | |
2859 | } | |
a6ababd2 AB |
2860 | } |
2861 | ||
6b5151fd JS |
2862 | /** |
2863 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. | |
2864 | * @phba: pointer to lpfc hba data structure. | |
2865 | * | |
2866 | * Allocate RPIs for all active remote nodes. This is needed whenever | |
2867 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose | |
2868 | * is to fixup the temporary rpi assignments. | |
2869 | **/ | |
2870 | void | |
2871 | lpfc_sli4_node_prep(struct lpfc_hba *phba) | |
2872 | { | |
2873 | struct lpfc_nodelist *ndlp, *next_ndlp; | |
2874 | struct lpfc_vport **vports; | |
2875 | int i; | |
2876 | ||
2877 | if (phba->sli_rev != LPFC_SLI_REV4) | |
2878 | return; | |
2879 | ||
2880 | vports = lpfc_create_vport_work_array(phba); | |
2881 | if (vports != NULL) { | |
2882 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { | |
2883 | if (vports[i]->load_flag & FC_UNLOADING) | |
2884 | continue; | |
2885 | ||
2886 | list_for_each_entry_safe(ndlp, next_ndlp, | |
2887 | &vports[i]->fc_nodes, | |
2888 | nlp_listp) { | |
be6bb941 | 2889 | if (NLP_CHK_NODE_ACT(ndlp)) { |
6b5151fd JS |
2890 | ndlp->nlp_rpi = |
2891 | lpfc_sli4_alloc_rpi(phba); | |
be6bb941 JS |
2892 | lpfc_printf_vlog(ndlp->vport, KERN_INFO, |
2893 | LOG_NODE, | |
2894 | "0009 rpi:%x DID:%x " | |
2895 | "flg:%x map:%x %p\n", | |
2896 | ndlp->nlp_rpi, | |
2897 | ndlp->nlp_DID, | |
2898 | ndlp->nlp_flag, | |
2899 | ndlp->nlp_usg_map, | |
2900 | ndlp); | |
2901 | } | |
6b5151fd JS |
2902 | } |
2903 | } | |
2904 | } | |
2905 | lpfc_destroy_vport_work_array(phba, vports); | |
2906 | } | |
2907 | ||
e59058c4 | 2908 | /** |
3621a710 | 2909 | * lpfc_online - Initialize and bring a HBA online |
e59058c4 JS |
2910 | * @phba: pointer to lpfc hba data structure. |
2911 | * | |
2912 | * This routine initializes the HBA and brings a HBA online. During this | |
2913 | * process, the management interface is blocked to prevent user space access | |
2914 | * to the HBA interfering with the driver initialization. | |
2915 | * | |
2916 | * Return codes | |
2917 | * 0 - successful | |
2918 | * 1 - failed | |
2919 | **/ | |
dea3101e | 2920 | int |
2e0fef85 | 2921 | lpfc_online(struct lpfc_hba *phba) |
dea3101e | 2922 | { |
372bd282 | 2923 | struct lpfc_vport *vport; |
549e55cd JS |
2924 | struct lpfc_vport **vports; |
2925 | int i; | |
16a3a208 | 2926 | bool vpis_cleared = false; |
2e0fef85 | 2927 | |
dea3101e JB |
2928 | if (!phba) |
2929 | return 0; | |
372bd282 | 2930 | vport = phba->pport; |
dea3101e | 2931 | |
2e0fef85 | 2932 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
dea3101e JB |
2933 | return 0; |
2934 | ||
ed957684 | 2935 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 2936 | "0458 Bring Adapter online\n"); |
dea3101e | 2937 | |
618a5230 | 2938 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
46fa311e | 2939 | |
da0436e9 JS |
2940 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2941 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ | |
2942 | lpfc_unblock_mgmt_io(phba); | |
2943 | return 1; | |
2944 | } | |
16a3a208 JS |
2945 | spin_lock_irq(&phba->hbalock); |
2946 | if (!phba->sli4_hba.max_cfg_param.vpi_used) | |
2947 | vpis_cleared = true; | |
2948 | spin_unlock_irq(&phba->hbalock); | |
da0436e9 | 2949 | } else { |
895427bd | 2950 | lpfc_sli_queue_init(phba); |
da0436e9 JS |
2951 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ |
2952 | lpfc_unblock_mgmt_io(phba); | |
2953 | return 1; | |
2954 | } | |
46fa311e | 2955 | } |
dea3101e | 2956 | |
549e55cd | 2957 | vports = lpfc_create_vport_work_array(phba); |
aeb6641f | 2958 | if (vports != NULL) { |
da0436e9 | 2959 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd JS |
2960 | struct Scsi_Host *shost; |
2961 | shost = lpfc_shost_from_vport(vports[i]); | |
2962 | spin_lock_irq(shost->host_lock); | |
2963 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; | |
2964 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) | |
2965 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
16a3a208 | 2966 | if (phba->sli_rev == LPFC_SLI_REV4) { |
1c6834a7 | 2967 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
16a3a208 JS |
2968 | if ((vpis_cleared) && |
2969 | (vports[i]->port_type != | |
2970 | LPFC_PHYSICAL_PORT)) | |
2971 | vports[i]->vpi = 0; | |
2972 | } | |
549e55cd JS |
2973 | spin_unlock_irq(shost->host_lock); |
2974 | } | |
aeb6641f AB |
2975 | } |
2976 | lpfc_destroy_vport_work_array(phba, vports); | |
dea3101e | 2977 | |
46fa311e | 2978 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
2979 | return 0; |
2980 | } | |
2981 | ||
e59058c4 | 2982 | /** |
3621a710 | 2983 | * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked |
e59058c4 JS |
2984 | * @phba: pointer to lpfc hba data structure. |
2985 | * | |
2986 | * This routine marks a HBA's management interface as not blocked. Once the | |
2987 | * HBA's management interface is marked as not blocked, all the user space | |
2988 | * access to the HBA, whether they are from sysfs interface or libdfc | |
2989 | * interface will be allowed. The HBA is set to block the management interface | |
2990 | * when the driver prepares the HBA interface for online or offline and then | |
2991 | * set to unblock the management interface afterwards. | |
2992 | **/ | |
46fa311e JS |
2993 | void |
2994 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) | |
2995 | { | |
2996 | unsigned long iflag; | |
2997 | ||
2e0fef85 JS |
2998 | spin_lock_irqsave(&phba->hbalock, iflag); |
2999 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; | |
3000 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
46fa311e JS |
3001 | } |
3002 | ||
e59058c4 | 3003 | /** |
3621a710 | 3004 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
e59058c4 JS |
3005 | * @phba: pointer to lpfc hba data structure. |
3006 | * | |
3007 | * This routine is invoked to prepare a HBA to be brought offline. It performs | |
3008 | * unregistration login to all the nodes on all vports and flushes the mailbox | |
3009 | * queue to make it ready to be brought offline. | |
3010 | **/ | |
46fa311e | 3011 | void |
618a5230 | 3012 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
46fa311e | 3013 | { |
2e0fef85 | 3014 | struct lpfc_vport *vport = phba->pport; |
46fa311e | 3015 | struct lpfc_nodelist *ndlp, *next_ndlp; |
87af33fe | 3016 | struct lpfc_vport **vports; |
72100cc4 | 3017 | struct Scsi_Host *shost; |
87af33fe | 3018 | int i; |
dea3101e | 3019 | |
2e0fef85 | 3020 | if (vport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 3021 | return; |
dea3101e | 3022 | |
618a5230 | 3023 | lpfc_block_mgmt_io(phba, mbx_action); |
dea3101e JB |
3024 | |
3025 | lpfc_linkdown(phba); | |
3026 | ||
87af33fe JS |
3027 | /* Issue an unreg_login to all nodes on all vports */ |
3028 | vports = lpfc_create_vport_work_array(phba); | |
3029 | if (vports != NULL) { | |
da0436e9 | 3030 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
a8adb832 JS |
3031 | if (vports[i]->load_flag & FC_UNLOADING) |
3032 | continue; | |
72100cc4 JS |
3033 | shost = lpfc_shost_from_vport(vports[i]); |
3034 | spin_lock_irq(shost->host_lock); | |
c868595d | 3035 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
695a814e JS |
3036 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
3037 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; | |
72100cc4 | 3038 | spin_unlock_irq(shost->host_lock); |
695a814e | 3039 | |
87af33fe JS |
3040 | shost = lpfc_shost_from_vport(vports[i]); |
3041 | list_for_each_entry_safe(ndlp, next_ndlp, | |
3042 | &vports[i]->fc_nodes, | |
3043 | nlp_listp) { | |
e47c9093 JS |
3044 | if (!NLP_CHK_NODE_ACT(ndlp)) |
3045 | continue; | |
87af33fe JS |
3046 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
3047 | continue; | |
3048 | if (ndlp->nlp_type & NLP_FABRIC) { | |
3049 | lpfc_disc_state_machine(vports[i], ndlp, | |
3050 | NULL, NLP_EVT_DEVICE_RECOVERY); | |
3051 | lpfc_disc_state_machine(vports[i], ndlp, | |
3052 | NULL, NLP_EVT_DEVICE_RM); | |
3053 | } | |
3054 | spin_lock_irq(shost->host_lock); | |
3055 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | |
401ee0c1 | 3056 | spin_unlock_irq(shost->host_lock); |
6b5151fd JS |
3057 | /* |
3058 | * Whenever an SLI4 port goes offline, free the | |
401ee0c1 JS |
3059 | * RPI. Get a new RPI when the adapter port |
3060 | * comes back online. | |
6b5151fd | 3061 | */ |
be6bb941 JS |
3062 | if (phba->sli_rev == LPFC_SLI_REV4) { |
3063 | lpfc_printf_vlog(ndlp->vport, | |
3064 | KERN_INFO, LOG_NODE, | |
3065 | "0011 lpfc_offline: " | |
3066 | "ndlp:x%p did %x " | |
3067 | "usgmap:x%x rpi:%x\n", | |
3068 | ndlp, ndlp->nlp_DID, | |
3069 | ndlp->nlp_usg_map, | |
3070 | ndlp->nlp_rpi); | |
3071 | ||
6b5151fd | 3072 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); |
be6bb941 | 3073 | } |
87af33fe JS |
3074 | lpfc_unreg_rpi(vports[i], ndlp); |
3075 | } | |
3076 | } | |
3077 | } | |
09372820 | 3078 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 3079 | |
618a5230 | 3080 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
46fa311e JS |
3081 | } |
3082 | ||
e59058c4 | 3083 | /** |
3621a710 | 3084 | * lpfc_offline - Bring a HBA offline |
e59058c4 JS |
3085 | * @phba: pointer to lpfc hba data structure. |
3086 | * | |
3087 | * This routine actually brings a HBA offline. It stops all the timers | |
3088 | * associated with the HBA, brings down the SLI layer, and eventually | |
3089 | * marks the HBA as in offline state for the upper layer protocol. | |
3090 | **/ | |
46fa311e | 3091 | void |
2e0fef85 | 3092 | lpfc_offline(struct lpfc_hba *phba) |
46fa311e | 3093 | { |
549e55cd JS |
3094 | struct Scsi_Host *shost; |
3095 | struct lpfc_vport **vports; | |
3096 | int i; | |
46fa311e | 3097 | |
549e55cd | 3098 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 3099 | return; |
688a8863 | 3100 | |
da0436e9 JS |
3101 | /* stop port and all timers associated with this hba */ |
3102 | lpfc_stop_port(phba); | |
51ef4c26 JS |
3103 | vports = lpfc_create_vport_work_array(phba); |
3104 | if (vports != NULL) | |
da0436e9 | 3105 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
51ef4c26 | 3106 | lpfc_stop_vport_timers(vports[i]); |
09372820 | 3107 | lpfc_destroy_vport_work_array(phba, vports); |
92d7f7b0 | 3108 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 3109 | "0460 Bring Adapter offline\n"); |
dea3101e JB |
3110 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
3111 | now. */ | |
3112 | lpfc_sli_hba_down(phba); | |
92d7f7b0 | 3113 | spin_lock_irq(&phba->hbalock); |
7054a606 | 3114 | phba->work_ha = 0; |
92d7f7b0 | 3115 | spin_unlock_irq(&phba->hbalock); |
549e55cd JS |
3116 | vports = lpfc_create_vport_work_array(phba); |
3117 | if (vports != NULL) | |
da0436e9 | 3118 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd | 3119 | shost = lpfc_shost_from_vport(vports[i]); |
549e55cd JS |
3120 | spin_lock_irq(shost->host_lock); |
3121 | vports[i]->work_port_events = 0; | |
3122 | vports[i]->fc_flag |= FC_OFFLINE_MODE; | |
3123 | spin_unlock_irq(shost->host_lock); | |
3124 | } | |
09372820 | 3125 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e JB |
3126 | } |
3127 | ||
e59058c4 | 3128 | /** |
3621a710 | 3129 | * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists |
e59058c4 JS |
3130 | * @phba: pointer to lpfc hba data structure. |
3131 | * | |
3132 | * This routine is to free all the SCSI buffers and IOCBs from the driver | |
3133 | * list back to kernel. It is called from lpfc_pci_remove_one to free | |
3134 | * the internal resources before the device is removed from the system. | |
e59058c4 | 3135 | **/ |
8a9d2e80 | 3136 | static void |
2e0fef85 | 3137 | lpfc_scsi_free(struct lpfc_hba *phba) |
dea3101e JB |
3138 | { |
3139 | struct lpfc_scsi_buf *sb, *sb_next; | |
dea3101e | 3140 | |
895427bd JS |
3141 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
3142 | return; | |
3143 | ||
2e0fef85 | 3144 | spin_lock_irq(&phba->hbalock); |
a40fc5f0 | 3145 | |
dea3101e | 3146 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
a40fc5f0 JS |
3147 | |
3148 | spin_lock(&phba->scsi_buf_list_put_lock); | |
3149 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, | |
3150 | list) { | |
dea3101e | 3151 | list_del(&sb->list); |
895427bd | 3152 | pci_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
92d7f7b0 | 3153 | sb->dma_handle); |
dea3101e JB |
3154 | kfree(sb); |
3155 | phba->total_scsi_bufs--; | |
3156 | } | |
a40fc5f0 JS |
3157 | spin_unlock(&phba->scsi_buf_list_put_lock); |
3158 | ||
3159 | spin_lock(&phba->scsi_buf_list_get_lock); | |
3160 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, | |
3161 | list) { | |
dea3101e | 3162 | list_del(&sb->list); |
895427bd | 3163 | pci_pool_free(phba->lpfc_sg_dma_buf_pool, sb->data, |
92d7f7b0 | 3164 | sb->dma_handle); |
dea3101e JB |
3165 | kfree(sb); |
3166 | phba->total_scsi_bufs--; | |
3167 | } | |
a40fc5f0 | 3168 | spin_unlock(&phba->scsi_buf_list_get_lock); |
2e0fef85 | 3169 | spin_unlock_irq(&phba->hbalock); |
8a9d2e80 | 3170 | } |
895427bd JS |
3171 | /** |
3172 | * lpfc_nvme_free - Free all the NVME buffers and IOCBs from driver lists | |
3173 | * @phba: pointer to lpfc hba data structure. | |
3174 | * | |
3175 | * This routine is to free all the NVME buffers and IOCBs from the driver | |
3176 | * list back to kernel. It is called from lpfc_pci_remove_one to free | |
3177 | * the internal resources before the device is removed from the system. | |
3178 | **/ | |
3179 | static void | |
3180 | lpfc_nvme_free(struct lpfc_hba *phba) | |
3181 | { | |
3182 | struct lpfc_nvme_buf *lpfc_ncmd, *lpfc_ncmd_next; | |
895427bd JS |
3183 | |
3184 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) | |
3185 | return; | |
3186 | ||
3187 | spin_lock_irq(&phba->hbalock); | |
3188 | ||
3189 | /* Release all the lpfc_nvme_bufs maintained by this host. */ | |
3190 | spin_lock(&phba->nvme_buf_list_put_lock); | |
3191 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, | |
3192 | &phba->lpfc_nvme_buf_list_put, list) { | |
3193 | list_del(&lpfc_ncmd->list); | |
3194 | pci_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data, | |
3195 | lpfc_ncmd->dma_handle); | |
3196 | kfree(lpfc_ncmd); | |
3197 | phba->total_nvme_bufs--; | |
3198 | } | |
3199 | spin_unlock(&phba->nvme_buf_list_put_lock); | |
3200 | ||
3201 | spin_lock(&phba->nvme_buf_list_get_lock); | |
3202 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, | |
3203 | &phba->lpfc_nvme_buf_list_get, list) { | |
3204 | list_del(&lpfc_ncmd->list); | |
3205 | pci_pool_free(phba->lpfc_sg_dma_buf_pool, lpfc_ncmd->data, | |
3206 | lpfc_ncmd->dma_handle); | |
3207 | kfree(lpfc_ncmd); | |
3208 | phba->total_nvme_bufs--; | |
3209 | } | |
3210 | spin_unlock(&phba->nvme_buf_list_get_lock); | |
895427bd JS |
3211 | spin_unlock_irq(&phba->hbalock); |
3212 | } | |
8a9d2e80 | 3213 | /** |
895427bd | 3214 | * lpfc_sli4_els_sgl_update - update ELS xri-sgl sizing and mapping |
8a9d2e80 JS |
3215 | * @phba: pointer to lpfc hba data structure. |
3216 | * | |
3217 | * This routine first calculates the sizes of the current els and allocated | |
3218 | * scsi sgl lists, and then goes through all sgls to updates the physical | |
3219 | * XRIs assigned due to port function reset. During port initialization, the | |
3220 | * current els and allocated scsi sgl lists are 0s. | |
3221 | * | |
3222 | * Return codes | |
3223 | * 0 - successful (for now, it always returns 0) | |
3224 | **/ | |
3225 | int | |
895427bd | 3226 | lpfc_sli4_els_sgl_update(struct lpfc_hba *phba) |
8a9d2e80 JS |
3227 | { |
3228 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; | |
895427bd | 3229 | uint16_t i, lxri, xri_cnt, els_xri_cnt; |
8a9d2e80 | 3230 | LIST_HEAD(els_sgl_list); |
8a9d2e80 JS |
3231 | int rc; |
3232 | ||
3233 | /* | |
3234 | * update on pci function's els xri-sgl list | |
3235 | */ | |
3236 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
895427bd | 3237 | |
8a9d2e80 JS |
3238 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { |
3239 | /* els xri-sgl expanded */ | |
3240 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; | |
3241 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3242 | "3157 ELS xri-sgl count increased from " | |
3243 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, | |
3244 | els_xri_cnt); | |
3245 | /* allocate the additional els sgls */ | |
3246 | for (i = 0; i < xri_cnt; i++) { | |
3247 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), | |
3248 | GFP_KERNEL); | |
3249 | if (sglq_entry == NULL) { | |
3250 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3251 | "2562 Failure to allocate an " | |
3252 | "ELS sgl entry:%d\n", i); | |
3253 | rc = -ENOMEM; | |
3254 | goto out_free_mem; | |
3255 | } | |
3256 | sglq_entry->buff_type = GEN_BUFF_TYPE; | |
3257 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, | |
3258 | &sglq_entry->phys); | |
3259 | if (sglq_entry->virt == NULL) { | |
3260 | kfree(sglq_entry); | |
3261 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3262 | "2563 Failure to allocate an " | |
3263 | "ELS mbuf:%d\n", i); | |
3264 | rc = -ENOMEM; | |
3265 | goto out_free_mem; | |
3266 | } | |
3267 | sglq_entry->sgl = sglq_entry->virt; | |
3268 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); | |
3269 | sglq_entry->state = SGL_FREED; | |
3270 | list_add_tail(&sglq_entry->list, &els_sgl_list); | |
3271 | } | |
38c20673 | 3272 | spin_lock_irq(&phba->hbalock); |
895427bd JS |
3273 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
3274 | list_splice_init(&els_sgl_list, | |
3275 | &phba->sli4_hba.lpfc_els_sgl_list); | |
3276 | spin_unlock(&phba->sli4_hba.sgl_list_lock); | |
38c20673 | 3277 | spin_unlock_irq(&phba->hbalock); |
8a9d2e80 JS |
3278 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
3279 | /* els xri-sgl shrinked */ | |
3280 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; | |
3281 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3282 | "3158 ELS xri-sgl count decreased from " | |
3283 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, | |
3284 | els_xri_cnt); | |
3285 | spin_lock_irq(&phba->hbalock); | |
895427bd JS |
3286 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
3287 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, | |
3288 | &els_sgl_list); | |
8a9d2e80 JS |
3289 | /* release extra els sgls from list */ |
3290 | for (i = 0; i < xri_cnt; i++) { | |
3291 | list_remove_head(&els_sgl_list, | |
3292 | sglq_entry, struct lpfc_sglq, list); | |
3293 | if (sglq_entry) { | |
895427bd JS |
3294 | __lpfc_mbuf_free(phba, sglq_entry->virt, |
3295 | sglq_entry->phys); | |
8a9d2e80 JS |
3296 | kfree(sglq_entry); |
3297 | } | |
3298 | } | |
895427bd JS |
3299 | list_splice_init(&els_sgl_list, |
3300 | &phba->sli4_hba.lpfc_els_sgl_list); | |
3301 | spin_unlock(&phba->sli4_hba.sgl_list_lock); | |
8a9d2e80 JS |
3302 | spin_unlock_irq(&phba->hbalock); |
3303 | } else | |
3304 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3305 | "3163 ELS xri-sgl count unchanged: %d\n", | |
3306 | els_xri_cnt); | |
3307 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; | |
3308 | ||
3309 | /* update xris to els sgls on the list */ | |
3310 | sglq_entry = NULL; | |
3311 | sglq_entry_next = NULL; | |
3312 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, | |
895427bd | 3313 | &phba->sli4_hba.lpfc_els_sgl_list, list) { |
8a9d2e80 JS |
3314 | lxri = lpfc_sli4_next_xritag(phba); |
3315 | if (lxri == NO_XRI) { | |
3316 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3317 | "2400 Failed to allocate xri for " | |
3318 | "ELS sgl\n"); | |
3319 | rc = -ENOMEM; | |
3320 | goto out_free_mem; | |
3321 | } | |
3322 | sglq_entry->sli4_lxritag = lxri; | |
3323 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; | |
3324 | } | |
895427bd JS |
3325 | return 0; |
3326 | ||
3327 | out_free_mem: | |
3328 | lpfc_free_els_sgl_list(phba); | |
3329 | return rc; | |
3330 | } | |
3331 | ||
f358dd0c JS |
3332 | /** |
3333 | * lpfc_sli4_nvmet_sgl_update - update xri-sgl sizing and mapping | |
3334 | * @phba: pointer to lpfc hba data structure. | |
3335 | * | |
3336 | * This routine first calculates the sizes of the current els and allocated | |
3337 | * scsi sgl lists, and then goes through all sgls to updates the physical | |
3338 | * XRIs assigned due to port function reset. During port initialization, the | |
3339 | * current els and allocated scsi sgl lists are 0s. | |
3340 | * | |
3341 | * Return codes | |
3342 | * 0 - successful (for now, it always returns 0) | |
3343 | **/ | |
3344 | int | |
3345 | lpfc_sli4_nvmet_sgl_update(struct lpfc_hba *phba) | |
3346 | { | |
3347 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; | |
3348 | uint16_t i, lxri, xri_cnt, els_xri_cnt; | |
3349 | uint16_t nvmet_xri_cnt, tot_cnt; | |
3350 | LIST_HEAD(nvmet_sgl_list); | |
3351 | int rc; | |
3352 | ||
3353 | /* | |
3354 | * update on pci function's nvmet xri-sgl list | |
3355 | */ | |
3356 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
3357 | nvmet_xri_cnt = 0; | |
3358 | tot_cnt = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; | |
3359 | ||
3360 | if (nvmet_xri_cnt > phba->sli4_hba.nvmet_xri_cnt) { | |
3361 | /* els xri-sgl expanded */ | |
3362 | xri_cnt = nvmet_xri_cnt - phba->sli4_hba.nvmet_xri_cnt; | |
3363 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3364 | "6302 NVMET xri-sgl cnt grew from %d to %d\n", | |
3365 | phba->sli4_hba.nvmet_xri_cnt, nvmet_xri_cnt); | |
3366 | /* allocate the additional nvmet sgls */ | |
3367 | for (i = 0; i < xri_cnt; i++) { | |
3368 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), | |
3369 | GFP_KERNEL); | |
3370 | if (sglq_entry == NULL) { | |
3371 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3372 | "6303 Failure to allocate an " | |
3373 | "NVMET sgl entry:%d\n", i); | |
3374 | rc = -ENOMEM; | |
3375 | goto out_free_mem; | |
3376 | } | |
3377 | sglq_entry->buff_type = NVMET_BUFF_TYPE; | |
3378 | sglq_entry->virt = lpfc_nvmet_buf_alloc(phba, 0, | |
3379 | &sglq_entry->phys); | |
3380 | if (sglq_entry->virt == NULL) { | |
3381 | kfree(sglq_entry); | |
3382 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3383 | "6304 Failure to allocate an " | |
3384 | "NVMET buf:%d\n", i); | |
3385 | rc = -ENOMEM; | |
3386 | goto out_free_mem; | |
3387 | } | |
3388 | sglq_entry->sgl = sglq_entry->virt; | |
3389 | memset(sglq_entry->sgl, 0, | |
3390 | phba->cfg_sg_dma_buf_size); | |
3391 | sglq_entry->state = SGL_FREED; | |
3392 | list_add_tail(&sglq_entry->list, &nvmet_sgl_list); | |
3393 | } | |
3394 | spin_lock_irq(&phba->hbalock); | |
3395 | spin_lock(&phba->sli4_hba.sgl_list_lock); | |
3396 | list_splice_init(&nvmet_sgl_list, | |
3397 | &phba->sli4_hba.lpfc_nvmet_sgl_list); | |
3398 | spin_unlock(&phba->sli4_hba.sgl_list_lock); | |
3399 | spin_unlock_irq(&phba->hbalock); | |
3400 | } else if (nvmet_xri_cnt < phba->sli4_hba.nvmet_xri_cnt) { | |
3401 | /* nvmet xri-sgl shrunk */ | |
3402 | xri_cnt = phba->sli4_hba.nvmet_xri_cnt - nvmet_xri_cnt; | |
3403 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3404 | "6305 NVMET xri-sgl count decreased from " | |
3405 | "%d to %d\n", phba->sli4_hba.nvmet_xri_cnt, | |
3406 | nvmet_xri_cnt); | |
3407 | spin_lock_irq(&phba->hbalock); | |
3408 | spin_lock(&phba->sli4_hba.sgl_list_lock); | |
3409 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, | |
3410 | &nvmet_sgl_list); | |
3411 | /* release extra nvmet sgls from list */ | |
3412 | for (i = 0; i < xri_cnt; i++) { | |
3413 | list_remove_head(&nvmet_sgl_list, | |
3414 | sglq_entry, struct lpfc_sglq, list); | |
3415 | if (sglq_entry) { | |
3416 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, | |
3417 | sglq_entry->phys); | |
3418 | kfree(sglq_entry); | |
3419 | } | |
3420 | } | |
3421 | list_splice_init(&nvmet_sgl_list, | |
3422 | &phba->sli4_hba.lpfc_nvmet_sgl_list); | |
3423 | spin_unlock(&phba->sli4_hba.sgl_list_lock); | |
3424 | spin_unlock_irq(&phba->hbalock); | |
3425 | } else | |
3426 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3427 | "6306 NVMET xri-sgl count unchanged: %d\n", | |
3428 | nvmet_xri_cnt); | |
3429 | phba->sli4_hba.nvmet_xri_cnt = nvmet_xri_cnt; | |
3430 | ||
3431 | /* update xris to nvmet sgls on the list */ | |
3432 | sglq_entry = NULL; | |
3433 | sglq_entry_next = NULL; | |
3434 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, | |
3435 | &phba->sli4_hba.lpfc_nvmet_sgl_list, list) { | |
3436 | lxri = lpfc_sli4_next_xritag(phba); | |
3437 | if (lxri == NO_XRI) { | |
3438 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3439 | "6307 Failed to allocate xri for " | |
3440 | "NVMET sgl\n"); | |
3441 | rc = -ENOMEM; | |
3442 | goto out_free_mem; | |
3443 | } | |
3444 | sglq_entry->sli4_lxritag = lxri; | |
3445 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; | |
3446 | } | |
3447 | return 0; | |
3448 | ||
3449 | out_free_mem: | |
3450 | lpfc_free_nvmet_sgl_list(phba); | |
3451 | return rc; | |
3452 | } | |
3453 | ||
895427bd JS |
3454 | /** |
3455 | * lpfc_sli4_scsi_sgl_update - update xri-sgl sizing and mapping | |
3456 | * @phba: pointer to lpfc hba data structure. | |
3457 | * | |
3458 | * This routine first calculates the sizes of the current els and allocated | |
3459 | * scsi sgl lists, and then goes through all sgls to updates the physical | |
3460 | * XRIs assigned due to port function reset. During port initialization, the | |
3461 | * current els and allocated scsi sgl lists are 0s. | |
3462 | * | |
3463 | * Return codes | |
3464 | * 0 - successful (for now, it always returns 0) | |
3465 | **/ | |
3466 | int | |
3467 | lpfc_sli4_scsi_sgl_update(struct lpfc_hba *phba) | |
3468 | { | |
3469 | struct lpfc_scsi_buf *psb, *psb_next; | |
3470 | uint16_t i, lxri, els_xri_cnt, scsi_xri_cnt; | |
3471 | LIST_HEAD(scsi_sgl_list); | |
3472 | int rc; | |
8a9d2e80 JS |
3473 | |
3474 | /* | |
895427bd | 3475 | * update on pci function's els xri-sgl list |
8a9d2e80 | 3476 | */ |
895427bd | 3477 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); |
8a9d2e80 JS |
3478 | phba->total_scsi_bufs = 0; |
3479 | ||
895427bd JS |
3480 | /* |
3481 | * update on pci function's allocated scsi xri-sgl list | |
3482 | */ | |
8a9d2e80 JS |
3483 | /* maximum number of xris available for scsi buffers */ |
3484 | phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri - | |
3485 | els_xri_cnt; | |
3486 | ||
895427bd JS |
3487 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) |
3488 | return 0; | |
3489 | ||
3490 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) | |
3491 | phba->sli4_hba.scsi_xri_max = /* Split them up */ | |
3492 | (phba->sli4_hba.scsi_xri_max * | |
3493 | phba->cfg_xri_split) / 100; | |
8a9d2e80 | 3494 | |
a40fc5f0 | 3495 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
164cecd1 | 3496 | spin_lock(&phba->scsi_buf_list_put_lock); |
a40fc5f0 JS |
3497 | list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list); |
3498 | list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list); | |
164cecd1 | 3499 | spin_unlock(&phba->scsi_buf_list_put_lock); |
a40fc5f0 | 3500 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
8a9d2e80 JS |
3501 | |
3502 | if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) { | |
3503 | /* max scsi xri shrinked below the allocated scsi buffers */ | |
3504 | scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt - | |
3505 | phba->sli4_hba.scsi_xri_max; | |
3506 | /* release the extra allocated scsi buffers */ | |
3507 | for (i = 0; i < scsi_xri_cnt; i++) { | |
3508 | list_remove_head(&scsi_sgl_list, psb, | |
3509 | struct lpfc_scsi_buf, list); | |
a2fc4aef | 3510 | if (psb) { |
895427bd | 3511 | pci_pool_free(phba->lpfc_sg_dma_buf_pool, |
a2fc4aef JS |
3512 | psb->data, psb->dma_handle); |
3513 | kfree(psb); | |
3514 | } | |
8a9d2e80 | 3515 | } |
a40fc5f0 | 3516 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
8a9d2e80 | 3517 | phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt; |
a40fc5f0 | 3518 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
8a9d2e80 JS |
3519 | } |
3520 | ||
3521 | /* update xris associated to remaining allocated scsi buffers */ | |
3522 | psb = NULL; | |
3523 | psb_next = NULL; | |
3524 | list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) { | |
3525 | lxri = lpfc_sli4_next_xritag(phba); | |
3526 | if (lxri == NO_XRI) { | |
3527 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3528 | "2560 Failed to allocate xri for " | |
3529 | "scsi buffer\n"); | |
3530 | rc = -ENOMEM; | |
3531 | goto out_free_mem; | |
3532 | } | |
3533 | psb->cur_iocbq.sli4_lxritag = lxri; | |
3534 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; | |
3535 | } | |
a40fc5f0 | 3536 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
164cecd1 | 3537 | spin_lock(&phba->scsi_buf_list_put_lock); |
a40fc5f0 JS |
3538 | list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get); |
3539 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); | |
164cecd1 | 3540 | spin_unlock(&phba->scsi_buf_list_put_lock); |
a40fc5f0 | 3541 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
dea3101e | 3542 | return 0; |
8a9d2e80 JS |
3543 | |
3544 | out_free_mem: | |
8a9d2e80 JS |
3545 | lpfc_scsi_free(phba); |
3546 | return rc; | |
dea3101e JB |
3547 | } |
3548 | ||
895427bd JS |
3549 | /** |
3550 | * lpfc_sli4_nvme_sgl_update - update xri-sgl sizing and mapping | |
3551 | * @phba: pointer to lpfc hba data structure. | |
3552 | * | |
3553 | * This routine first calculates the sizes of the current els and allocated | |
3554 | * scsi sgl lists, and then goes through all sgls to updates the physical | |
3555 | * XRIs assigned due to port function reset. During port initialization, the | |
3556 | * current els and allocated scsi sgl lists are 0s. | |
3557 | * | |
3558 | * Return codes | |
3559 | * 0 - successful (for now, it always returns 0) | |
3560 | **/ | |
3561 | int | |
3562 | lpfc_sli4_nvme_sgl_update(struct lpfc_hba *phba) | |
3563 | { | |
3564 | struct lpfc_nvme_buf *lpfc_ncmd = NULL, *lpfc_ncmd_next = NULL; | |
3565 | uint16_t i, lxri, els_xri_cnt; | |
3566 | uint16_t nvme_xri_cnt, nvme_xri_max; | |
3567 | LIST_HEAD(nvme_sgl_list); | |
3568 | int rc; | |
3569 | ||
3570 | phba->total_nvme_bufs = 0; | |
3571 | ||
3572 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) | |
3573 | return 0; | |
3574 | /* | |
3575 | * update on pci function's allocated nvme xri-sgl list | |
3576 | */ | |
3577 | ||
3578 | /* maximum number of xris available for nvme buffers */ | |
3579 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
3580 | nvme_xri_max = phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; | |
3581 | phba->sli4_hba.nvme_xri_max = nvme_xri_max; | |
3582 | phba->sli4_hba.nvme_xri_max -= phba->sli4_hba.scsi_xri_max; | |
3583 | ||
3584 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3585 | "6074 Current allocated NVME xri-sgl count:%d, " | |
3586 | "maximum NVME xri count:%d\n", | |
3587 | phba->sli4_hba.nvme_xri_cnt, | |
3588 | phba->sli4_hba.nvme_xri_max); | |
3589 | ||
3590 | spin_lock_irq(&phba->nvme_buf_list_get_lock); | |
3591 | spin_lock(&phba->nvme_buf_list_put_lock); | |
3592 | list_splice_init(&phba->lpfc_nvme_buf_list_get, &nvme_sgl_list); | |
3593 | list_splice(&phba->lpfc_nvme_buf_list_put, &nvme_sgl_list); | |
3594 | spin_unlock(&phba->nvme_buf_list_put_lock); | |
3595 | spin_unlock_irq(&phba->nvme_buf_list_get_lock); | |
3596 | ||
3597 | if (phba->sli4_hba.nvme_xri_cnt > phba->sli4_hba.nvme_xri_max) { | |
3598 | /* max nvme xri shrunk below the allocated nvme buffers */ | |
3599 | spin_lock_irq(&phba->nvme_buf_list_get_lock); | |
3600 | nvme_xri_cnt = phba->sli4_hba.nvme_xri_cnt - | |
3601 | phba->sli4_hba.nvme_xri_max; | |
3602 | spin_unlock_irq(&phba->nvme_buf_list_get_lock); | |
3603 | /* release the extra allocated nvme buffers */ | |
3604 | for (i = 0; i < nvme_xri_cnt; i++) { | |
3605 | list_remove_head(&nvme_sgl_list, lpfc_ncmd, | |
3606 | struct lpfc_nvme_buf, list); | |
3607 | if (lpfc_ncmd) { | |
3608 | pci_pool_free(phba->lpfc_sg_dma_buf_pool, | |
3609 | lpfc_ncmd->data, | |
3610 | lpfc_ncmd->dma_handle); | |
3611 | kfree(lpfc_ncmd); | |
3612 | } | |
3613 | } | |
3614 | spin_lock_irq(&phba->nvme_buf_list_get_lock); | |
3615 | phba->sli4_hba.nvme_xri_cnt -= nvme_xri_cnt; | |
3616 | spin_unlock_irq(&phba->nvme_buf_list_get_lock); | |
3617 | } | |
3618 | ||
3619 | /* update xris associated to remaining allocated nvme buffers */ | |
3620 | lpfc_ncmd = NULL; | |
3621 | lpfc_ncmd_next = NULL; | |
3622 | list_for_each_entry_safe(lpfc_ncmd, lpfc_ncmd_next, | |
3623 | &nvme_sgl_list, list) { | |
3624 | lxri = lpfc_sli4_next_xritag(phba); | |
3625 | if (lxri == NO_XRI) { | |
3626 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3627 | "6075 Failed to allocate xri for " | |
3628 | "nvme buffer\n"); | |
3629 | rc = -ENOMEM; | |
3630 | goto out_free_mem; | |
3631 | } | |
3632 | lpfc_ncmd->cur_iocbq.sli4_lxritag = lxri; | |
3633 | lpfc_ncmd->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; | |
3634 | } | |
3635 | spin_lock_irq(&phba->nvme_buf_list_get_lock); | |
3636 | spin_lock(&phba->nvme_buf_list_put_lock); | |
3637 | list_splice_init(&nvme_sgl_list, &phba->lpfc_nvme_buf_list_get); | |
3638 | INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put); | |
3639 | spin_unlock(&phba->nvme_buf_list_put_lock); | |
3640 | spin_unlock_irq(&phba->nvme_buf_list_get_lock); | |
3641 | return 0; | |
3642 | ||
3643 | out_free_mem: | |
3644 | lpfc_nvme_free(phba); | |
3645 | return rc; | |
3646 | } | |
3647 | ||
e59058c4 | 3648 | /** |
3621a710 | 3649 | * lpfc_create_port - Create an FC port |
e59058c4 JS |
3650 | * @phba: pointer to lpfc hba data structure. |
3651 | * @instance: a unique integer ID to this FC port. | |
3652 | * @dev: pointer to the device data structure. | |
3653 | * | |
3654 | * This routine creates a FC port for the upper layer protocol. The FC port | |
3655 | * can be created on top of either a physical port or a virtual port provided | |
3656 | * by the HBA. This routine also allocates a SCSI host data structure (shost) | |
3657 | * and associates the FC port created before adding the shost into the SCSI | |
3658 | * layer. | |
3659 | * | |
3660 | * Return codes | |
3661 | * @vport - pointer to the virtual N_Port data structure. | |
3662 | * NULL - port create failed. | |
3663 | **/ | |
2e0fef85 | 3664 | struct lpfc_vport * |
3de2a653 | 3665 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
47a8617c | 3666 | { |
2e0fef85 | 3667 | struct lpfc_vport *vport; |
895427bd | 3668 | struct Scsi_Host *shost = NULL; |
2e0fef85 | 3669 | int error = 0; |
47a8617c | 3670 | |
895427bd JS |
3671 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
3672 | if (dev != &phba->pcidev->dev) { | |
3673 | shost = scsi_host_alloc(&lpfc_vport_template, | |
3674 | sizeof(struct lpfc_vport)); | |
3675 | } else { | |
3676 | if (phba->sli_rev == LPFC_SLI_REV4) | |
3677 | shost = scsi_host_alloc(&lpfc_template, | |
3678 | sizeof(struct lpfc_vport)); | |
3679 | else | |
3680 | shost = scsi_host_alloc(&lpfc_template_s3, | |
3681 | sizeof(struct lpfc_vport)); | |
3682 | } | |
3683 | } else if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { | |
3684 | shost = scsi_host_alloc(&lpfc_template_nvme, | |
ea4142f6 JS |
3685 | sizeof(struct lpfc_vport)); |
3686 | } | |
2e0fef85 JS |
3687 | if (!shost) |
3688 | goto out; | |
47a8617c | 3689 | |
2e0fef85 JS |
3690 | vport = (struct lpfc_vport *) shost->hostdata; |
3691 | vport->phba = phba; | |
2e0fef85 | 3692 | vport->load_flag |= FC_LOADING; |
92d7f7b0 | 3693 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
7f5f3d0d | 3694 | vport->fc_rscn_flush = 0; |
3de2a653 | 3695 | lpfc_get_vport_cfgparam(vport); |
895427bd | 3696 | |
2e0fef85 JS |
3697 | shost->unique_id = instance; |
3698 | shost->max_id = LPFC_MAX_TARGET; | |
3de2a653 | 3699 | shost->max_lun = vport->cfg_max_luns; |
2e0fef85 JS |
3700 | shost->this_id = -1; |
3701 | shost->max_cmd_len = 16; | |
8b0dff14 | 3702 | shost->nr_hw_queues = phba->cfg_fcp_io_channel; |
da0436e9 | 3703 | if (phba->sli_rev == LPFC_SLI_REV4) { |
28baac74 | 3704 | shost->dma_boundary = |
cb5172ea | 3705 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
da0436e9 JS |
3706 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
3707 | } | |
81301a9b | 3708 | |
47a8617c | 3709 | /* |
2e0fef85 JS |
3710 | * Set initial can_queue value since 0 is no longer supported and |
3711 | * scsi_add_host will fail. This will be adjusted later based on the | |
3712 | * max xri value determined in hba setup. | |
47a8617c | 3713 | */ |
2e0fef85 | 3714 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
3de2a653 | 3715 | if (dev != &phba->pcidev->dev) { |
92d7f7b0 JS |
3716 | shost->transportt = lpfc_vport_transport_template; |
3717 | vport->port_type = LPFC_NPIV_PORT; | |
3718 | } else { | |
3719 | shost->transportt = lpfc_transport_template; | |
3720 | vport->port_type = LPFC_PHYSICAL_PORT; | |
3721 | } | |
47a8617c | 3722 | |
2e0fef85 JS |
3723 | /* Initialize all internally managed lists. */ |
3724 | INIT_LIST_HEAD(&vport->fc_nodes); | |
da0436e9 | 3725 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
2e0fef85 | 3726 | spin_lock_init(&vport->work_port_lock); |
47a8617c | 3727 | |
2e0fef85 JS |
3728 | init_timer(&vport->fc_disctmo); |
3729 | vport->fc_disctmo.function = lpfc_disc_timeout; | |
92d7f7b0 | 3730 | vport->fc_disctmo.data = (unsigned long)vport; |
47a8617c | 3731 | |
2e0fef85 JS |
3732 | init_timer(&vport->els_tmofunc); |
3733 | vport->els_tmofunc.function = lpfc_els_timeout; | |
92d7f7b0 | 3734 | vport->els_tmofunc.data = (unsigned long)vport; |
92494144 JS |
3735 | |
3736 | init_timer(&vport->delayed_disc_tmo); | |
3737 | vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo; | |
3738 | vport->delayed_disc_tmo.data = (unsigned long)vport; | |
3739 | ||
d139b9bd | 3740 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
2e0fef85 JS |
3741 | if (error) |
3742 | goto out_put_shost; | |
47a8617c | 3743 | |
549e55cd | 3744 | spin_lock_irq(&phba->hbalock); |
2e0fef85 | 3745 | list_add_tail(&vport->listentry, &phba->port_list); |
549e55cd | 3746 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 3747 | return vport; |
47a8617c | 3748 | |
2e0fef85 JS |
3749 | out_put_shost: |
3750 | scsi_host_put(shost); | |
3751 | out: | |
3752 | return NULL; | |
47a8617c JS |
3753 | } |
3754 | ||
e59058c4 | 3755 | /** |
3621a710 | 3756 | * destroy_port - destroy an FC port |
e59058c4 JS |
3757 | * @vport: pointer to an lpfc virtual N_Port data structure. |
3758 | * | |
3759 | * This routine destroys a FC port from the upper layer protocol. All the | |
3760 | * resources associated with the port are released. | |
3761 | **/ | |
2e0fef85 JS |
3762 | void |
3763 | destroy_port(struct lpfc_vport *vport) | |
47a8617c | 3764 | { |
92d7f7b0 JS |
3765 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
3766 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 3767 | |
858c9f6c | 3768 | lpfc_debugfs_terminate(vport); |
92d7f7b0 JS |
3769 | fc_remove_host(shost); |
3770 | scsi_remove_host(shost); | |
47a8617c | 3771 | |
92d7f7b0 JS |
3772 | spin_lock_irq(&phba->hbalock); |
3773 | list_del_init(&vport->listentry); | |
3774 | spin_unlock_irq(&phba->hbalock); | |
47a8617c | 3775 | |
92d7f7b0 | 3776 | lpfc_cleanup(vport); |
47a8617c | 3777 | return; |
47a8617c JS |
3778 | } |
3779 | ||
e59058c4 | 3780 | /** |
3621a710 | 3781 | * lpfc_get_instance - Get a unique integer ID |
e59058c4 JS |
3782 | * |
3783 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It | |
3784 | * uses the kernel idr facility to perform the task. | |
3785 | * | |
3786 | * Return codes: | |
3787 | * instance - a unique integer ID allocated as the new instance. | |
3788 | * -1 - lpfc get instance failed. | |
3789 | **/ | |
92d7f7b0 JS |
3790 | int |
3791 | lpfc_get_instance(void) | |
3792 | { | |
ab516036 TH |
3793 | int ret; |
3794 | ||
3795 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); | |
3796 | return ret < 0 ? -1 : ret; | |
47a8617c JS |
3797 | } |
3798 | ||
e59058c4 | 3799 | /** |
3621a710 | 3800 | * lpfc_scan_finished - method for SCSI layer to detect whether scan is done |
e59058c4 JS |
3801 | * @shost: pointer to SCSI host data structure. |
3802 | * @time: elapsed time of the scan in jiffies. | |
3803 | * | |
3804 | * This routine is called by the SCSI layer with a SCSI host to determine | |
3805 | * whether the scan host is finished. | |
3806 | * | |
3807 | * Note: there is no scan_start function as adapter initialization will have | |
3808 | * asynchronously kicked off the link initialization. | |
3809 | * | |
3810 | * Return codes | |
3811 | * 0 - SCSI host scan is not over yet. | |
3812 | * 1 - SCSI host scan is over. | |
3813 | **/ | |
47a8617c JS |
3814 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
3815 | { | |
2e0fef85 JS |
3816 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
3817 | struct lpfc_hba *phba = vport->phba; | |
858c9f6c | 3818 | int stat = 0; |
47a8617c | 3819 | |
858c9f6c JS |
3820 | spin_lock_irq(shost->host_lock); |
3821 | ||
51ef4c26 | 3822 | if (vport->load_flag & FC_UNLOADING) { |
858c9f6c JS |
3823 | stat = 1; |
3824 | goto finished; | |
3825 | } | |
256ec0d0 | 3826 | if (time >= msecs_to_jiffies(30 * 1000)) { |
2e0fef85 | 3827 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
e8b62011 JS |
3828 | "0461 Scanning longer than 30 " |
3829 | "seconds. Continuing initialization\n"); | |
858c9f6c | 3830 | stat = 1; |
47a8617c | 3831 | goto finished; |
2e0fef85 | 3832 | } |
256ec0d0 JS |
3833 | if (time >= msecs_to_jiffies(15 * 1000) && |
3834 | phba->link_state <= LPFC_LINK_DOWN) { | |
2e0fef85 | 3835 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
e8b62011 JS |
3836 | "0465 Link down longer than 15 " |
3837 | "seconds. Continuing initialization\n"); | |
858c9f6c | 3838 | stat = 1; |
47a8617c | 3839 | goto finished; |
2e0fef85 | 3840 | } |
47a8617c | 3841 | |
2e0fef85 | 3842 | if (vport->port_state != LPFC_VPORT_READY) |
858c9f6c | 3843 | goto finished; |
2e0fef85 | 3844 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
858c9f6c | 3845 | goto finished; |
256ec0d0 | 3846 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
858c9f6c | 3847 | goto finished; |
2e0fef85 | 3848 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
858c9f6c JS |
3849 | goto finished; |
3850 | ||
3851 | stat = 1; | |
47a8617c JS |
3852 | |
3853 | finished: | |
858c9f6c JS |
3854 | spin_unlock_irq(shost->host_lock); |
3855 | return stat; | |
92d7f7b0 | 3856 | } |
47a8617c | 3857 | |
e59058c4 | 3858 | /** |
3621a710 | 3859 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
e59058c4 JS |
3860 | * @shost: pointer to SCSI host data structure. |
3861 | * | |
3862 | * This routine initializes a given SCSI host attributes on a FC port. The | |
3863 | * SCSI host can be either on top of a physical port or a virtual port. | |
3864 | **/ | |
92d7f7b0 JS |
3865 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
3866 | { | |
3867 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3868 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 3869 | /* |
2e0fef85 | 3870 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
47a8617c JS |
3871 | */ |
3872 | ||
2e0fef85 JS |
3873 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
3874 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
47a8617c JS |
3875 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
3876 | ||
3877 | memset(fc_host_supported_fc4s(shost), 0, | |
2e0fef85 | 3878 | sizeof(fc_host_supported_fc4s(shost))); |
47a8617c JS |
3879 | fc_host_supported_fc4s(shost)[2] = 1; |
3880 | fc_host_supported_fc4s(shost)[7] = 1; | |
3881 | ||
92d7f7b0 JS |
3882 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
3883 | sizeof fc_host_symbolic_name(shost)); | |
47a8617c JS |
3884 | |
3885 | fc_host_supported_speeds(shost) = 0; | |
d38dd52c JS |
3886 | if (phba->lmt & LMT_32Gb) |
3887 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_32GBIT; | |
88a2cfbb JS |
3888 | if (phba->lmt & LMT_16Gb) |
3889 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; | |
47a8617c JS |
3890 | if (phba->lmt & LMT_10Gb) |
3891 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; | |
a8adb832 JS |
3892 | if (phba->lmt & LMT_8Gb) |
3893 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; | |
47a8617c JS |
3894 | if (phba->lmt & LMT_4Gb) |
3895 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; | |
3896 | if (phba->lmt & LMT_2Gb) | |
3897 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; | |
3898 | if (phba->lmt & LMT_1Gb) | |
3899 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; | |
3900 | ||
3901 | fc_host_maxframe_size(shost) = | |
2e0fef85 JS |
3902 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
3903 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; | |
47a8617c | 3904 | |
0af5d708 MC |
3905 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
3906 | ||
47a8617c JS |
3907 | /* This value is also unchanging */ |
3908 | memset(fc_host_active_fc4s(shost), 0, | |
2e0fef85 | 3909 | sizeof(fc_host_active_fc4s(shost))); |
47a8617c JS |
3910 | fc_host_active_fc4s(shost)[2] = 1; |
3911 | fc_host_active_fc4s(shost)[7] = 1; | |
3912 | ||
92d7f7b0 | 3913 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
47a8617c | 3914 | spin_lock_irq(shost->host_lock); |
51ef4c26 | 3915 | vport->load_flag &= ~FC_LOADING; |
47a8617c | 3916 | spin_unlock_irq(shost->host_lock); |
47a8617c | 3917 | } |
dea3101e | 3918 | |
e59058c4 | 3919 | /** |
da0436e9 | 3920 | * lpfc_stop_port_s3 - Stop SLI3 device port |
e59058c4 JS |
3921 | * @phba: pointer to lpfc hba data structure. |
3922 | * | |
da0436e9 JS |
3923 | * This routine is invoked to stop an SLI3 device port, it stops the device |
3924 | * from generating interrupts and stops the device driver's timers for the | |
3925 | * device. | |
e59058c4 | 3926 | **/ |
da0436e9 JS |
3927 | static void |
3928 | lpfc_stop_port_s3(struct lpfc_hba *phba) | |
db2378e0 | 3929 | { |
da0436e9 JS |
3930 | /* Clear all interrupt enable conditions */ |
3931 | writel(0, phba->HCregaddr); | |
3932 | readl(phba->HCregaddr); /* flush */ | |
3933 | /* Clear all pending interrupts */ | |
3934 | writel(0xffffffff, phba->HAregaddr); | |
3935 | readl(phba->HAregaddr); /* flush */ | |
db2378e0 | 3936 | |
da0436e9 JS |
3937 | /* Reset some HBA SLI setup states */ |
3938 | lpfc_stop_hba_timers(phba); | |
3939 | phba->pport->work_port_events = 0; | |
3940 | } | |
db2378e0 | 3941 | |
da0436e9 JS |
3942 | /** |
3943 | * lpfc_stop_port_s4 - Stop SLI4 device port | |
3944 | * @phba: pointer to lpfc hba data structure. | |
3945 | * | |
3946 | * This routine is invoked to stop an SLI4 device port, it stops the device | |
3947 | * from generating interrupts and stops the device driver's timers for the | |
3948 | * device. | |
3949 | **/ | |
3950 | static void | |
3951 | lpfc_stop_port_s4(struct lpfc_hba *phba) | |
3952 | { | |
3953 | /* Reset some HBA SLI4 setup states */ | |
3954 | lpfc_stop_hba_timers(phba); | |
3955 | phba->pport->work_port_events = 0; | |
3956 | phba->sli4_hba.intr_enable = 0; | |
da0436e9 | 3957 | } |
9399627f | 3958 | |
da0436e9 JS |
3959 | /** |
3960 | * lpfc_stop_port - Wrapper function for stopping hba port | |
3961 | * @phba: Pointer to HBA context object. | |
3962 | * | |
3963 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from | |
3964 | * the API jump table function pointer from the lpfc_hba struct. | |
3965 | **/ | |
3966 | void | |
3967 | lpfc_stop_port(struct lpfc_hba *phba) | |
3968 | { | |
3969 | phba->lpfc_stop_port(phba); | |
3970 | } | |
db2378e0 | 3971 | |
ecfd03c6 JS |
3972 | /** |
3973 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer | |
3974 | * @phba: Pointer to hba for which this call is being executed. | |
3975 | * | |
3976 | * This routine starts the timer waiting for the FCF rediscovery to complete. | |
3977 | **/ | |
3978 | void | |
3979 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) | |
3980 | { | |
3981 | unsigned long fcf_redisc_wait_tmo = | |
3982 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); | |
3983 | /* Start fcf rediscovery wait period timer */ | |
3984 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); | |
3985 | spin_lock_irq(&phba->hbalock); | |
3986 | /* Allow action to new fcf asynchronous event */ | |
3987 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); | |
3988 | /* Mark the FCF rediscovery pending state */ | |
3989 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; | |
3990 | spin_unlock_irq(&phba->hbalock); | |
3991 | } | |
3992 | ||
3993 | /** | |
3994 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout | |
3995 | * @ptr: Map to lpfc_hba data structure pointer. | |
3996 | * | |
3997 | * This routine is invoked when waiting for FCF table rediscover has been | |
3998 | * timed out. If new FCF record(s) has (have) been discovered during the | |
3999 | * wait period, a new FCF event shall be added to the FCOE async event | |
4000 | * list, and then worker thread shall be waked up for processing from the | |
4001 | * worker thread context. | |
4002 | **/ | |
e399b228 | 4003 | static void |
ecfd03c6 JS |
4004 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) |
4005 | { | |
4006 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; | |
4007 | ||
4008 | /* Don't send FCF rediscovery event if timer cancelled */ | |
4009 | spin_lock_irq(&phba->hbalock); | |
4010 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
4011 | spin_unlock_irq(&phba->hbalock); | |
4012 | return; | |
4013 | } | |
4014 | /* Clear FCF rediscovery timer pending flag */ | |
4015 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; | |
4016 | /* FCF rediscovery event to worker thread */ | |
4017 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; | |
4018 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 | 4019 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 4020 | "2776 FCF rediscover quiescent timer expired\n"); |
ecfd03c6 JS |
4021 | /* wake up worker thread */ |
4022 | lpfc_worker_wake_up(phba); | |
4023 | } | |
4024 | ||
e59058c4 | 4025 | /** |
da0436e9 | 4026 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
e59058c4 | 4027 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 4028 | * @acqe_link: pointer to the async link completion queue entry. |
e59058c4 | 4029 | * |
da0436e9 JS |
4030 | * This routine is to parse the SLI4 link-attention link fault code and |
4031 | * translate it into the base driver's read link attention mailbox command | |
4032 | * status. | |
4033 | * | |
4034 | * Return: Link-attention status in terms of base driver's coding. | |
e59058c4 | 4035 | **/ |
da0436e9 JS |
4036 | static uint16_t |
4037 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, | |
4038 | struct lpfc_acqe_link *acqe_link) | |
db2378e0 | 4039 | { |
da0436e9 | 4040 | uint16_t latt_fault; |
9399627f | 4041 | |
da0436e9 JS |
4042 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
4043 | case LPFC_ASYNC_LINK_FAULT_NONE: | |
4044 | case LPFC_ASYNC_LINK_FAULT_LOCAL: | |
4045 | case LPFC_ASYNC_LINK_FAULT_REMOTE: | |
4046 | latt_fault = 0; | |
4047 | break; | |
4048 | default: | |
4049 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4050 | "0398 Invalid link fault code: x%x\n", | |
4051 | bf_get(lpfc_acqe_link_fault, acqe_link)); | |
4052 | latt_fault = MBXERR_ERROR; | |
4053 | break; | |
4054 | } | |
4055 | return latt_fault; | |
db2378e0 JS |
4056 | } |
4057 | ||
5b75da2f | 4058 | /** |
da0436e9 | 4059 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
5b75da2f | 4060 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 4061 | * @acqe_link: pointer to the async link completion queue entry. |
5b75da2f | 4062 | * |
da0436e9 JS |
4063 | * This routine is to parse the SLI4 link attention type and translate it |
4064 | * into the base driver's link attention type coding. | |
5b75da2f | 4065 | * |
da0436e9 JS |
4066 | * Return: Link attention type in terms of base driver's coding. |
4067 | **/ | |
4068 | static uint8_t | |
4069 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, | |
4070 | struct lpfc_acqe_link *acqe_link) | |
5b75da2f | 4071 | { |
da0436e9 | 4072 | uint8_t att_type; |
5b75da2f | 4073 | |
da0436e9 JS |
4074 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
4075 | case LPFC_ASYNC_LINK_STATUS_DOWN: | |
4076 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: | |
76a95d75 | 4077 | att_type = LPFC_ATT_LINK_DOWN; |
da0436e9 JS |
4078 | break; |
4079 | case LPFC_ASYNC_LINK_STATUS_UP: | |
4080 | /* Ignore physical link up events - wait for logical link up */ | |
76a95d75 | 4081 | att_type = LPFC_ATT_RESERVED; |
da0436e9 JS |
4082 | break; |
4083 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: | |
76a95d75 | 4084 | att_type = LPFC_ATT_LINK_UP; |
da0436e9 JS |
4085 | break; |
4086 | default: | |
4087 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4088 | "0399 Invalid link attention type: x%x\n", | |
4089 | bf_get(lpfc_acqe_link_status, acqe_link)); | |
76a95d75 | 4090 | att_type = LPFC_ATT_RESERVED; |
da0436e9 | 4091 | break; |
5b75da2f | 4092 | } |
da0436e9 | 4093 | return att_type; |
5b75da2f JS |
4094 | } |
4095 | ||
8b68cd52 JS |
4096 | /** |
4097 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed | |
4098 | * @phba: pointer to lpfc hba data structure. | |
4099 | * | |
4100 | * This routine is to get an SLI3 FC port's link speed in Mbps. | |
4101 | * | |
4102 | * Return: link speed in terms of Mbps. | |
4103 | **/ | |
4104 | uint32_t | |
4105 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) | |
4106 | { | |
4107 | uint32_t link_speed; | |
4108 | ||
4109 | if (!lpfc_is_link_up(phba)) | |
4110 | return 0; | |
4111 | ||
a085e87c JS |
4112 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
4113 | switch (phba->fc_linkspeed) { | |
4114 | case LPFC_LINK_SPEED_1GHZ: | |
4115 | link_speed = 1000; | |
4116 | break; | |
4117 | case LPFC_LINK_SPEED_2GHZ: | |
4118 | link_speed = 2000; | |
4119 | break; | |
4120 | case LPFC_LINK_SPEED_4GHZ: | |
4121 | link_speed = 4000; | |
4122 | break; | |
4123 | case LPFC_LINK_SPEED_8GHZ: | |
4124 | link_speed = 8000; | |
4125 | break; | |
4126 | case LPFC_LINK_SPEED_10GHZ: | |
4127 | link_speed = 10000; | |
4128 | break; | |
4129 | case LPFC_LINK_SPEED_16GHZ: | |
4130 | link_speed = 16000; | |
4131 | break; | |
4132 | default: | |
4133 | link_speed = 0; | |
4134 | } | |
4135 | } else { | |
4136 | if (phba->sli4_hba.link_state.logical_speed) | |
4137 | link_speed = | |
4138 | phba->sli4_hba.link_state.logical_speed; | |
4139 | else | |
4140 | link_speed = phba->sli4_hba.link_state.speed; | |
8b68cd52 JS |
4141 | } |
4142 | return link_speed; | |
4143 | } | |
4144 | ||
4145 | /** | |
4146 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed | |
4147 | * @phba: pointer to lpfc hba data structure. | |
4148 | * @evt_code: asynchronous event code. | |
4149 | * @speed_code: asynchronous event link speed code. | |
4150 | * | |
4151 | * This routine is to parse the giving SLI4 async event link speed code into | |
4152 | * value of Mbps for the link speed. | |
4153 | * | |
4154 | * Return: link speed in terms of Mbps. | |
4155 | **/ | |
4156 | static uint32_t | |
4157 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, | |
4158 | uint8_t speed_code) | |
4159 | { | |
4160 | uint32_t port_speed; | |
4161 | ||
4162 | switch (evt_code) { | |
4163 | case LPFC_TRAILER_CODE_LINK: | |
4164 | switch (speed_code) { | |
26d830ec | 4165 | case LPFC_ASYNC_LINK_SPEED_ZERO: |
8b68cd52 JS |
4166 | port_speed = 0; |
4167 | break; | |
26d830ec | 4168 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
8b68cd52 JS |
4169 | port_speed = 10; |
4170 | break; | |
26d830ec | 4171 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
8b68cd52 JS |
4172 | port_speed = 100; |
4173 | break; | |
26d830ec | 4174 | case LPFC_ASYNC_LINK_SPEED_1GBPS: |
8b68cd52 JS |
4175 | port_speed = 1000; |
4176 | break; | |
26d830ec | 4177 | case LPFC_ASYNC_LINK_SPEED_10GBPS: |
8b68cd52 JS |
4178 | port_speed = 10000; |
4179 | break; | |
26d830ec JS |
4180 | case LPFC_ASYNC_LINK_SPEED_20GBPS: |
4181 | port_speed = 20000; | |
4182 | break; | |
4183 | case LPFC_ASYNC_LINK_SPEED_25GBPS: | |
4184 | port_speed = 25000; | |
4185 | break; | |
4186 | case LPFC_ASYNC_LINK_SPEED_40GBPS: | |
4187 | port_speed = 40000; | |
4188 | break; | |
8b68cd52 JS |
4189 | default: |
4190 | port_speed = 0; | |
4191 | } | |
4192 | break; | |
4193 | case LPFC_TRAILER_CODE_FC: | |
4194 | switch (speed_code) { | |
26d830ec | 4195 | case LPFC_FC_LA_SPEED_UNKNOWN: |
8b68cd52 JS |
4196 | port_speed = 0; |
4197 | break; | |
26d830ec | 4198 | case LPFC_FC_LA_SPEED_1G: |
8b68cd52 JS |
4199 | port_speed = 1000; |
4200 | break; | |
26d830ec | 4201 | case LPFC_FC_LA_SPEED_2G: |
8b68cd52 JS |
4202 | port_speed = 2000; |
4203 | break; | |
26d830ec | 4204 | case LPFC_FC_LA_SPEED_4G: |
8b68cd52 JS |
4205 | port_speed = 4000; |
4206 | break; | |
26d830ec | 4207 | case LPFC_FC_LA_SPEED_8G: |
8b68cd52 JS |
4208 | port_speed = 8000; |
4209 | break; | |
26d830ec | 4210 | case LPFC_FC_LA_SPEED_10G: |
8b68cd52 JS |
4211 | port_speed = 10000; |
4212 | break; | |
26d830ec | 4213 | case LPFC_FC_LA_SPEED_16G: |
8b68cd52 JS |
4214 | port_speed = 16000; |
4215 | break; | |
d38dd52c JS |
4216 | case LPFC_FC_LA_SPEED_32G: |
4217 | port_speed = 32000; | |
4218 | break; | |
8b68cd52 JS |
4219 | default: |
4220 | port_speed = 0; | |
4221 | } | |
4222 | break; | |
4223 | default: | |
4224 | port_speed = 0; | |
4225 | } | |
4226 | return port_speed; | |
4227 | } | |
4228 | ||
da0436e9 | 4229 | /** |
70f3c073 | 4230 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
da0436e9 JS |
4231 | * @phba: pointer to lpfc hba data structure. |
4232 | * @acqe_link: pointer to the async link completion queue entry. | |
4233 | * | |
70f3c073 | 4234 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
da0436e9 JS |
4235 | **/ |
4236 | static void | |
4237 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, | |
4238 | struct lpfc_acqe_link *acqe_link) | |
4239 | { | |
4240 | struct lpfc_dmabuf *mp; | |
4241 | LPFC_MBOXQ_t *pmb; | |
4242 | MAILBOX_t *mb; | |
76a95d75 | 4243 | struct lpfc_mbx_read_top *la; |
da0436e9 | 4244 | uint8_t att_type; |
76a95d75 | 4245 | int rc; |
da0436e9 JS |
4246 | |
4247 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); | |
76a95d75 | 4248 | if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP) |
da0436e9 | 4249 | return; |
32b9793f | 4250 | phba->fcoe_eventtag = acqe_link->event_tag; |
da0436e9 JS |
4251 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
4252 | if (!pmb) { | |
4253 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4254 | "0395 The mboxq allocation failed\n"); | |
4255 | return; | |
4256 | } | |
4257 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
4258 | if (!mp) { | |
4259 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4260 | "0396 The lpfc_dmabuf allocation failed\n"); | |
4261 | goto out_free_pmb; | |
4262 | } | |
4263 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
4264 | if (!mp->virt) { | |
4265 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4266 | "0397 The mbuf allocation failed\n"); | |
4267 | goto out_free_dmabuf; | |
4268 | } | |
4269 | ||
4270 | /* Cleanup any outstanding ELS commands */ | |
4271 | lpfc_els_flush_all_cmd(phba); | |
4272 | ||
4273 | /* Block ELS IOCBs until we have done process link event */ | |
895427bd | 4274 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
da0436e9 JS |
4275 | |
4276 | /* Update link event statistics */ | |
4277 | phba->sli.slistat.link_event++; | |
4278 | ||
76a95d75 JS |
4279 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
4280 | lpfc_read_topology(phba, pmb, mp); | |
4281 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
da0436e9 JS |
4282 | pmb->vport = phba->pport; |
4283 | ||
da0436e9 JS |
4284 | /* Keep the link status for extra SLI4 state machine reference */ |
4285 | phba->sli4_hba.link_state.speed = | |
8b68cd52 JS |
4286 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
4287 | bf_get(lpfc_acqe_link_speed, acqe_link)); | |
da0436e9 JS |
4288 | phba->sli4_hba.link_state.duplex = |
4289 | bf_get(lpfc_acqe_link_duplex, acqe_link); | |
4290 | phba->sli4_hba.link_state.status = | |
4291 | bf_get(lpfc_acqe_link_status, acqe_link); | |
70f3c073 JS |
4292 | phba->sli4_hba.link_state.type = |
4293 | bf_get(lpfc_acqe_link_type, acqe_link); | |
4294 | phba->sli4_hba.link_state.number = | |
4295 | bf_get(lpfc_acqe_link_number, acqe_link); | |
da0436e9 JS |
4296 | phba->sli4_hba.link_state.fault = |
4297 | bf_get(lpfc_acqe_link_fault, acqe_link); | |
65467b6b | 4298 | phba->sli4_hba.link_state.logical_speed = |
8b68cd52 JS |
4299 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
4300 | ||
70f3c073 | 4301 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
c31098ce JS |
4302 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
4303 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " | |
4304 | "Logical speed:%dMbps Fault:%d\n", | |
70f3c073 JS |
4305 | phba->sli4_hba.link_state.speed, |
4306 | phba->sli4_hba.link_state.topology, | |
4307 | phba->sli4_hba.link_state.status, | |
4308 | phba->sli4_hba.link_state.type, | |
4309 | phba->sli4_hba.link_state.number, | |
8b68cd52 | 4310 | phba->sli4_hba.link_state.logical_speed, |
70f3c073 | 4311 | phba->sli4_hba.link_state.fault); |
76a95d75 JS |
4312 | /* |
4313 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch | |
4314 | * topology info. Note: Optional for non FC-AL ports. | |
4315 | */ | |
4316 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { | |
4317 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
4318 | if (rc == MBX_NOT_FINISHED) | |
4319 | goto out_free_dmabuf; | |
4320 | return; | |
4321 | } | |
4322 | /* | |
4323 | * For FCoE Mode: fill in all the topology information we need and call | |
4324 | * the READ_TOPOLOGY completion routine to continue without actually | |
4325 | * sending the READ_TOPOLOGY mailbox command to the port. | |
4326 | */ | |
4327 | /* Parse and translate status field */ | |
4328 | mb = &pmb->u.mb; | |
4329 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); | |
4330 | ||
4331 | /* Parse and translate link attention fields */ | |
4332 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; | |
4333 | la->eventTag = acqe_link->event_tag; | |
4334 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); | |
4335 | bf_set(lpfc_mbx_read_top_link_spd, la, | |
a085e87c | 4336 | (bf_get(lpfc_acqe_link_speed, acqe_link))); |
76a95d75 JS |
4337 | |
4338 | /* Fake the the following irrelvant fields */ | |
4339 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); | |
4340 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); | |
4341 | bf_set(lpfc_mbx_read_top_il, la, 0); | |
4342 | bf_set(lpfc_mbx_read_top_pb, la, 0); | |
4343 | bf_set(lpfc_mbx_read_top_fa, la, 0); | |
4344 | bf_set(lpfc_mbx_read_top_mm, la, 0); | |
da0436e9 JS |
4345 | |
4346 | /* Invoke the lpfc_handle_latt mailbox command callback function */ | |
76a95d75 | 4347 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
da0436e9 | 4348 | |
5b75da2f | 4349 | return; |
da0436e9 JS |
4350 | |
4351 | out_free_dmabuf: | |
4352 | kfree(mp); | |
4353 | out_free_pmb: | |
4354 | mempool_free(pmb, phba->mbox_mem_pool); | |
4355 | } | |
4356 | ||
70f3c073 JS |
4357 | /** |
4358 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event | |
4359 | * @phba: pointer to lpfc hba data structure. | |
4360 | * @acqe_fc: pointer to the async fc completion queue entry. | |
4361 | * | |
4362 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log | |
4363 | * that the event was received and then issue a read_topology mailbox command so | |
4364 | * that the rest of the driver will treat it the same as SLI3. | |
4365 | **/ | |
4366 | static void | |
4367 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) | |
4368 | { | |
4369 | struct lpfc_dmabuf *mp; | |
4370 | LPFC_MBOXQ_t *pmb; | |
7bdedb34 JS |
4371 | MAILBOX_t *mb; |
4372 | struct lpfc_mbx_read_top *la; | |
70f3c073 JS |
4373 | int rc; |
4374 | ||
4375 | if (bf_get(lpfc_trailer_type, acqe_fc) != | |
4376 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { | |
4377 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4378 | "2895 Non FC link Event detected.(%d)\n", | |
4379 | bf_get(lpfc_trailer_type, acqe_fc)); | |
4380 | return; | |
4381 | } | |
4382 | /* Keep the link status for extra SLI4 state machine reference */ | |
4383 | phba->sli4_hba.link_state.speed = | |
8b68cd52 JS |
4384 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
4385 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); | |
70f3c073 JS |
4386 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
4387 | phba->sli4_hba.link_state.topology = | |
4388 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); | |
4389 | phba->sli4_hba.link_state.status = | |
4390 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); | |
4391 | phba->sli4_hba.link_state.type = | |
4392 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); | |
4393 | phba->sli4_hba.link_state.number = | |
4394 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); | |
4395 | phba->sli4_hba.link_state.fault = | |
4396 | bf_get(lpfc_acqe_link_fault, acqe_fc); | |
4397 | phba->sli4_hba.link_state.logical_speed = | |
8b68cd52 | 4398 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
70f3c073 JS |
4399 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
4400 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " | |
4401 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" | |
4402 | "%dMbps Fault:%d\n", | |
4403 | phba->sli4_hba.link_state.speed, | |
4404 | phba->sli4_hba.link_state.topology, | |
4405 | phba->sli4_hba.link_state.status, | |
4406 | phba->sli4_hba.link_state.type, | |
4407 | phba->sli4_hba.link_state.number, | |
8b68cd52 | 4408 | phba->sli4_hba.link_state.logical_speed, |
70f3c073 JS |
4409 | phba->sli4_hba.link_state.fault); |
4410 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
4411 | if (!pmb) { | |
4412 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4413 | "2897 The mboxq allocation failed\n"); | |
4414 | return; | |
4415 | } | |
4416 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
4417 | if (!mp) { | |
4418 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4419 | "2898 The lpfc_dmabuf allocation failed\n"); | |
4420 | goto out_free_pmb; | |
4421 | } | |
4422 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
4423 | if (!mp->virt) { | |
4424 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4425 | "2899 The mbuf allocation failed\n"); | |
4426 | goto out_free_dmabuf; | |
4427 | } | |
4428 | ||
4429 | /* Cleanup any outstanding ELS commands */ | |
4430 | lpfc_els_flush_all_cmd(phba); | |
4431 | ||
4432 | /* Block ELS IOCBs until we have done process link event */ | |
895427bd | 4433 | phba->sli4_hba.els_wq->pring->flag |= LPFC_STOP_IOCB_EVENT; |
70f3c073 JS |
4434 | |
4435 | /* Update link event statistics */ | |
4436 | phba->sli.slistat.link_event++; | |
4437 | ||
4438 | /* Create lpfc_handle_latt mailbox command from link ACQE */ | |
4439 | lpfc_read_topology(phba, pmb, mp); | |
4440 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
4441 | pmb->vport = phba->pport; | |
4442 | ||
7bdedb34 JS |
4443 | if (phba->sli4_hba.link_state.status != LPFC_FC_LA_TYPE_LINK_UP) { |
4444 | /* Parse and translate status field */ | |
4445 | mb = &pmb->u.mb; | |
4446 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, | |
4447 | (void *)acqe_fc); | |
4448 | ||
4449 | /* Parse and translate link attention fields */ | |
4450 | la = (struct lpfc_mbx_read_top *)&pmb->u.mb.un.varReadTop; | |
4451 | la->eventTag = acqe_fc->event_tag; | |
4452 | bf_set(lpfc_mbx_read_top_att_type, la, | |
4453 | LPFC_FC_LA_TYPE_LINK_DOWN); | |
4454 | ||
4455 | /* Invoke the mailbox command callback function */ | |
4456 | lpfc_mbx_cmpl_read_topology(phba, pmb); | |
4457 | ||
4458 | return; | |
4459 | } | |
4460 | ||
70f3c073 JS |
4461 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); |
4462 | if (rc == MBX_NOT_FINISHED) | |
4463 | goto out_free_dmabuf; | |
4464 | return; | |
4465 | ||
4466 | out_free_dmabuf: | |
4467 | kfree(mp); | |
4468 | out_free_pmb: | |
4469 | mempool_free(pmb, phba->mbox_mem_pool); | |
4470 | } | |
4471 | ||
4472 | /** | |
4473 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event | |
4474 | * @phba: pointer to lpfc hba data structure. | |
4475 | * @acqe_fc: pointer to the async SLI completion queue entry. | |
4476 | * | |
4477 | * This routine is to handle the SLI4 asynchronous SLI events. | |
4478 | **/ | |
4479 | static void | |
4480 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) | |
4481 | { | |
4b8bae08 | 4482 | char port_name; |
8c1312e1 | 4483 | char message[128]; |
4b8bae08 | 4484 | uint8_t status; |
946727dc | 4485 | uint8_t evt_type; |
448193b5 | 4486 | uint8_t operational = 0; |
946727dc | 4487 | struct temp_event temp_event_data; |
4b8bae08 | 4488 | struct lpfc_acqe_misconfigured_event *misconfigured; |
946727dc JS |
4489 | struct Scsi_Host *shost; |
4490 | ||
4491 | evt_type = bf_get(lpfc_trailer_type, acqe_sli); | |
4b8bae08 | 4492 | |
448193b5 JS |
4493 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
4494 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" | |
4495 | "x%08x SLI Event Type:%d\n", | |
4496 | acqe_sli->event_data1, acqe_sli->event_data2, | |
4497 | evt_type); | |
4b8bae08 JS |
4498 | |
4499 | port_name = phba->Port[0]; | |
4500 | if (port_name == 0x00) | |
4501 | port_name = '?'; /* get port name is empty */ | |
4502 | ||
946727dc JS |
4503 | switch (evt_type) { |
4504 | case LPFC_SLI_EVENT_TYPE_OVER_TEMP: | |
4505 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
4506 | temp_event_data.event_code = LPFC_THRESHOLD_TEMP; | |
4507 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; | |
4508 | ||
4509 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
4510 | "3190 Over Temperature:%d Celsius- Port Name %c\n", | |
4511 | acqe_sli->event_data1, port_name); | |
4512 | ||
310429ef | 4513 | phba->sfp_warning |= LPFC_TRANSGRESSION_HIGH_TEMPERATURE; |
946727dc JS |
4514 | shost = lpfc_shost_from_vport(phba->pport); |
4515 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
4516 | sizeof(temp_event_data), | |
4517 | (char *)&temp_event_data, | |
4518 | SCSI_NL_VID_TYPE_PCI | |
4519 | | PCI_VENDOR_ID_EMULEX); | |
4520 | break; | |
4521 | case LPFC_SLI_EVENT_TYPE_NORM_TEMP: | |
4522 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
4523 | temp_event_data.event_code = LPFC_NORMAL_TEMP; | |
4524 | temp_event_data.data = (uint32_t)acqe_sli->event_data1; | |
4525 | ||
4526 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4527 | "3191 Normal Temperature:%d Celsius - Port Name %c\n", | |
4528 | acqe_sli->event_data1, port_name); | |
4529 | ||
4530 | shost = lpfc_shost_from_vport(phba->pport); | |
4531 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
4532 | sizeof(temp_event_data), | |
4533 | (char *)&temp_event_data, | |
4534 | SCSI_NL_VID_TYPE_PCI | |
4535 | | PCI_VENDOR_ID_EMULEX); | |
4536 | break; | |
4537 | case LPFC_SLI_EVENT_TYPE_MISCONFIGURED: | |
4538 | misconfigured = (struct lpfc_acqe_misconfigured_event *) | |
4b8bae08 JS |
4539 | &acqe_sli->event_data1; |
4540 | ||
946727dc JS |
4541 | /* fetch the status for this port */ |
4542 | switch (phba->sli4_hba.lnk_info.lnk_no) { | |
4543 | case LPFC_LINK_NUMBER_0: | |
448193b5 JS |
4544 | status = bf_get(lpfc_sli_misconfigured_port0_state, |
4545 | &misconfigured->theEvent); | |
4546 | operational = bf_get(lpfc_sli_misconfigured_port0_op, | |
4b8bae08 | 4547 | &misconfigured->theEvent); |
946727dc JS |
4548 | break; |
4549 | case LPFC_LINK_NUMBER_1: | |
448193b5 JS |
4550 | status = bf_get(lpfc_sli_misconfigured_port1_state, |
4551 | &misconfigured->theEvent); | |
4552 | operational = bf_get(lpfc_sli_misconfigured_port1_op, | |
4b8bae08 | 4553 | &misconfigured->theEvent); |
946727dc JS |
4554 | break; |
4555 | case LPFC_LINK_NUMBER_2: | |
448193b5 JS |
4556 | status = bf_get(lpfc_sli_misconfigured_port2_state, |
4557 | &misconfigured->theEvent); | |
4558 | operational = bf_get(lpfc_sli_misconfigured_port2_op, | |
4b8bae08 | 4559 | &misconfigured->theEvent); |
946727dc JS |
4560 | break; |
4561 | case LPFC_LINK_NUMBER_3: | |
448193b5 JS |
4562 | status = bf_get(lpfc_sli_misconfigured_port3_state, |
4563 | &misconfigured->theEvent); | |
4564 | operational = bf_get(lpfc_sli_misconfigured_port3_op, | |
4b8bae08 | 4565 | &misconfigured->theEvent); |
946727dc JS |
4566 | break; |
4567 | default: | |
448193b5 JS |
4568 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
4569 | "3296 " | |
4570 | "LPFC_SLI_EVENT_TYPE_MISCONFIGURED " | |
4571 | "event: Invalid link %d", | |
4572 | phba->sli4_hba.lnk_info.lnk_no); | |
4573 | return; | |
946727dc | 4574 | } |
4b8bae08 | 4575 | |
448193b5 JS |
4576 | /* Skip if optic state unchanged */ |
4577 | if (phba->sli4_hba.lnk_info.optic_state == status) | |
4578 | return; | |
4579 | ||
946727dc JS |
4580 | switch (status) { |
4581 | case LPFC_SLI_EVENT_STATUS_VALID: | |
448193b5 JS |
4582 | sprintf(message, "Physical Link is functional"); |
4583 | break; | |
946727dc JS |
4584 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: |
4585 | sprintf(message, "Optics faulted/incorrectly " | |
4586 | "installed/not installed - Reseat optics, " | |
4587 | "if issue not resolved, replace."); | |
4588 | break; | |
4589 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: | |
4590 | sprintf(message, | |
4591 | "Optics of two types installed - Remove one " | |
4592 | "optic or install matching pair of optics."); | |
4593 | break; | |
4594 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: | |
4595 | sprintf(message, "Incompatible optics - Replace with " | |
292098be | 4596 | "compatible optics for card to function."); |
946727dc | 4597 | break; |
448193b5 JS |
4598 | case LPFC_SLI_EVENT_STATUS_UNQUALIFIED: |
4599 | sprintf(message, "Unqualified optics - Replace with " | |
4600 | "Avago optics for Warranty and Technical " | |
4601 | "Support - Link is%s operational", | |
2ea259ee | 4602 | (operational) ? " not" : ""); |
448193b5 JS |
4603 | break; |
4604 | case LPFC_SLI_EVENT_STATUS_UNCERTIFIED: | |
4605 | sprintf(message, "Uncertified optics - Replace with " | |
4606 | "Avago-certified optics to enable link " | |
4607 | "operation - Link is%s operational", | |
2ea259ee | 4608 | (operational) ? " not" : ""); |
448193b5 | 4609 | break; |
946727dc JS |
4610 | default: |
4611 | /* firmware is reporting a status we don't know about */ | |
4612 | sprintf(message, "Unknown event status x%02x", status); | |
4613 | break; | |
4614 | } | |
448193b5 | 4615 | phba->sli4_hba.lnk_info.optic_state = status; |
946727dc | 4616 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
448193b5 | 4617 | "3176 Port Name %c %s\n", port_name, message); |
946727dc JS |
4618 | break; |
4619 | case LPFC_SLI_EVENT_TYPE_REMOTE_DPORT: | |
4620 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4621 | "3192 Remote DPort Test Initiated - " | |
4622 | "Event Data1:x%08x Event Data2: x%08x\n", | |
4623 | acqe_sli->event_data1, acqe_sli->event_data2); | |
4b8bae08 JS |
4624 | break; |
4625 | default: | |
946727dc JS |
4626 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
4627 | "3193 Async SLI event - Event Data1:x%08x Event Data2:" | |
4628 | "x%08x SLI Event Type:%d\n", | |
4629 | acqe_sli->event_data1, acqe_sli->event_data2, | |
4630 | evt_type); | |
4b8bae08 JS |
4631 | break; |
4632 | } | |
70f3c073 JS |
4633 | } |
4634 | ||
fc2b989b JS |
4635 | /** |
4636 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport | |
4637 | * @vport: pointer to vport data structure. | |
4638 | * | |
4639 | * This routine is to perform Clear Virtual Link (CVL) on a vport in | |
4640 | * response to a CVL event. | |
4641 | * | |
4642 | * Return the pointer to the ndlp with the vport if successful, otherwise | |
4643 | * return NULL. | |
4644 | **/ | |
4645 | static struct lpfc_nodelist * | |
4646 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) | |
4647 | { | |
4648 | struct lpfc_nodelist *ndlp; | |
4649 | struct Scsi_Host *shost; | |
4650 | struct lpfc_hba *phba; | |
4651 | ||
4652 | if (!vport) | |
4653 | return NULL; | |
fc2b989b JS |
4654 | phba = vport->phba; |
4655 | if (!phba) | |
4656 | return NULL; | |
78730cfe JS |
4657 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
4658 | if (!ndlp) { | |
4659 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | |
4660 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
4661 | if (!ndlp) | |
4662 | return 0; | |
4663 | lpfc_nlp_init(vport, ndlp, Fabric_DID); | |
4664 | /* Set the node type */ | |
4665 | ndlp->nlp_type |= NLP_FABRIC; | |
4666 | /* Put ndlp onto node list */ | |
4667 | lpfc_enqueue_node(vport, ndlp); | |
4668 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
4669 | /* re-setup ndlp without removing from node list */ | |
4670 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
4671 | if (!ndlp) | |
4672 | return 0; | |
4673 | } | |
63e801ce JS |
4674 | if ((phba->pport->port_state < LPFC_FLOGI) && |
4675 | (phba->pport->port_state != LPFC_VPORT_FAILED)) | |
fc2b989b JS |
4676 | return NULL; |
4677 | /* If virtual link is not yet instantiated ignore CVL */ | |
63e801ce JS |
4678 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
4679 | && (vport->port_state != LPFC_VPORT_FAILED)) | |
fc2b989b JS |
4680 | return NULL; |
4681 | shost = lpfc_shost_from_vport(vport); | |
4682 | if (!shost) | |
4683 | return NULL; | |
4684 | lpfc_linkdown_port(vport); | |
4685 | lpfc_cleanup_pending_mbox(vport); | |
4686 | spin_lock_irq(shost->host_lock); | |
4687 | vport->fc_flag |= FC_VPORT_CVL_RCVD; | |
4688 | spin_unlock_irq(shost->host_lock); | |
4689 | ||
4690 | return ndlp; | |
4691 | } | |
4692 | ||
4693 | /** | |
4694 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports | |
4695 | * @vport: pointer to lpfc hba data structure. | |
4696 | * | |
4697 | * This routine is to perform Clear Virtual Link (CVL) on all vports in | |
4698 | * response to a FCF dead event. | |
4699 | **/ | |
4700 | static void | |
4701 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) | |
4702 | { | |
4703 | struct lpfc_vport **vports; | |
4704 | int i; | |
4705 | ||
4706 | vports = lpfc_create_vport_work_array(phba); | |
4707 | if (vports) | |
4708 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) | |
4709 | lpfc_sli4_perform_vport_cvl(vports[i]); | |
4710 | lpfc_destroy_vport_work_array(phba, vports); | |
4711 | } | |
4712 | ||
da0436e9 | 4713 | /** |
76a95d75 | 4714 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
da0436e9 JS |
4715 | * @phba: pointer to lpfc hba data structure. |
4716 | * @acqe_link: pointer to the async fcoe completion queue entry. | |
4717 | * | |
4718 | * This routine is to handle the SLI4 asynchronous fcoe event. | |
4719 | **/ | |
4720 | static void | |
76a95d75 | 4721 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
70f3c073 | 4722 | struct lpfc_acqe_fip *acqe_fip) |
da0436e9 | 4723 | { |
70f3c073 | 4724 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
da0436e9 | 4725 | int rc; |
6669f9bb JS |
4726 | struct lpfc_vport *vport; |
4727 | struct lpfc_nodelist *ndlp; | |
4728 | struct Scsi_Host *shost; | |
695a814e JS |
4729 | int active_vlink_present; |
4730 | struct lpfc_vport **vports; | |
4731 | int i; | |
da0436e9 | 4732 | |
70f3c073 JS |
4733 | phba->fc_eventTag = acqe_fip->event_tag; |
4734 | phba->fcoe_eventtag = acqe_fip->event_tag; | |
da0436e9 | 4735 | switch (event_type) { |
70f3c073 JS |
4736 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
4737 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: | |
4738 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) | |
999d813f JS |
4739 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
4740 | LOG_DISCOVERY, | |
a93ff37a JS |
4741 | "2546 New FCF event, evt_tag:x%x, " |
4742 | "index:x%x\n", | |
70f3c073 JS |
4743 | acqe_fip->event_tag, |
4744 | acqe_fip->index); | |
999d813f JS |
4745 | else |
4746 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | | |
4747 | LOG_DISCOVERY, | |
a93ff37a JS |
4748 | "2788 FCF param modified event, " |
4749 | "evt_tag:x%x, index:x%x\n", | |
70f3c073 JS |
4750 | acqe_fip->event_tag, |
4751 | acqe_fip->index); | |
38b92ef8 | 4752 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
0c9ab6f5 JS |
4753 | /* |
4754 | * During period of FCF discovery, read the FCF | |
4755 | * table record indexed by the event to update | |
a93ff37a | 4756 | * FCF roundrobin failover eligible FCF bmask. |
0c9ab6f5 JS |
4757 | */ |
4758 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | | |
4759 | LOG_DISCOVERY, | |
a93ff37a JS |
4760 | "2779 Read FCF (x%x) for updating " |
4761 | "roundrobin FCF failover bmask\n", | |
70f3c073 JS |
4762 | acqe_fip->index); |
4763 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); | |
0c9ab6f5 | 4764 | } |
38b92ef8 JS |
4765 | |
4766 | /* If the FCF discovery is in progress, do nothing. */ | |
3804dc84 | 4767 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 4768 | if (phba->hba_flag & FCF_TS_INPROG) { |
38b92ef8 JS |
4769 | spin_unlock_irq(&phba->hbalock); |
4770 | break; | |
4771 | } | |
4772 | /* If fast FCF failover rescan event is pending, do nothing */ | |
4773 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { | |
4774 | spin_unlock_irq(&phba->hbalock); | |
4775 | break; | |
4776 | } | |
4777 | ||
c2b9712e JS |
4778 | /* If the FCF has been in discovered state, do nothing. */ |
4779 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { | |
3804dc84 JS |
4780 | spin_unlock_irq(&phba->hbalock); |
4781 | break; | |
4782 | } | |
4783 | spin_unlock_irq(&phba->hbalock); | |
38b92ef8 | 4784 | |
0c9ab6f5 JS |
4785 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
4786 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, | |
a93ff37a JS |
4787 | "2770 Start FCF table scan per async FCF " |
4788 | "event, evt_tag:x%x, index:x%x\n", | |
70f3c073 | 4789 | acqe_fip->event_tag, acqe_fip->index); |
0c9ab6f5 JS |
4790 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
4791 | LPFC_FCOE_FCF_GET_FIRST); | |
da0436e9 | 4792 | if (rc) |
0c9ab6f5 JS |
4793 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
4794 | "2547 Issue FCF scan read FCF mailbox " | |
a93ff37a | 4795 | "command failed (x%x)\n", rc); |
da0436e9 JS |
4796 | break; |
4797 | ||
70f3c073 | 4798 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
da0436e9 | 4799 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e4e74273 | 4800 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
70f3c073 JS |
4801 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
4802 | acqe_fip->event_tag); | |
da0436e9 JS |
4803 | break; |
4804 | ||
70f3c073 | 4805 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
80c17849 | 4806 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
0c9ab6f5 | 4807 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
a93ff37a | 4808 | "2549 FCF (x%x) disconnected from network, " |
70f3c073 | 4809 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
38b92ef8 JS |
4810 | /* |
4811 | * If we are in the middle of FCF failover process, clear | |
4812 | * the corresponding FCF bit in the roundrobin bitmap. | |
da0436e9 | 4813 | */ |
fc2b989b | 4814 | spin_lock_irq(&phba->hbalock); |
a1cadfef JS |
4815 | if ((phba->fcf.fcf_flag & FCF_DISCOVERY) && |
4816 | (phba->fcf.current_rec.fcf_indx != acqe_fip->index)) { | |
fc2b989b | 4817 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 | 4818 | /* Update FLOGI FCF failover eligible FCF bmask */ |
70f3c073 | 4819 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
fc2b989b JS |
4820 | break; |
4821 | } | |
38b92ef8 JS |
4822 | spin_unlock_irq(&phba->hbalock); |
4823 | ||
4824 | /* If the event is not for currently used fcf do nothing */ | |
70f3c073 | 4825 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
38b92ef8 JS |
4826 | break; |
4827 | ||
4828 | /* | |
4829 | * Otherwise, request the port to rediscover the entire FCF | |
4830 | * table for a fast recovery from case that the current FCF | |
4831 | * is no longer valid as we are not in the middle of FCF | |
4832 | * failover process already. | |
4833 | */ | |
c2b9712e JS |
4834 | spin_lock_irq(&phba->hbalock); |
4835 | /* Mark the fast failover process in progress */ | |
4836 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; | |
4837 | spin_unlock_irq(&phba->hbalock); | |
4838 | ||
4839 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, | |
4840 | "2771 Start FCF fast failover process due to " | |
4841 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " | |
4842 | "\n", acqe_fip->event_tag, acqe_fip->index); | |
4843 | rc = lpfc_sli4_redisc_fcf_table(phba); | |
4844 | if (rc) { | |
4845 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | | |
4846 | LOG_DISCOVERY, | |
4847 | "2772 Issue FCF rediscover mabilbox " | |
4848 | "command failed, fail through to FCF " | |
4849 | "dead event\n"); | |
4850 | spin_lock_irq(&phba->hbalock); | |
4851 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; | |
4852 | spin_unlock_irq(&phba->hbalock); | |
4853 | /* | |
4854 | * Last resort will fail over by treating this | |
4855 | * as a link down to FCF registration. | |
4856 | */ | |
4857 | lpfc_sli4_fcf_dead_failthrough(phba); | |
4858 | } else { | |
4859 | /* Reset FCF roundrobin bmask for new discovery */ | |
4860 | lpfc_sli4_clear_fcf_rr_bmask(phba); | |
4861 | /* | |
4862 | * Handling fast FCF failover to a DEAD FCF event is | |
4863 | * considered equalivant to receiving CVL to all vports. | |
4864 | */ | |
4865 | lpfc_sli4_perform_all_vport_cvl(phba); | |
4866 | } | |
da0436e9 | 4867 | break; |
70f3c073 | 4868 | case LPFC_FIP_EVENT_TYPE_CVL: |
80c17849 | 4869 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
0c9ab6f5 | 4870 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
6669f9bb | 4871 | "2718 Clear Virtual Link Received for VPI 0x%x" |
70f3c073 | 4872 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
6d368e53 | 4873 | |
6669f9bb | 4874 | vport = lpfc_find_vport_by_vpid(phba, |
5248a749 | 4875 | acqe_fip->index); |
fc2b989b | 4876 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
6669f9bb JS |
4877 | if (!ndlp) |
4878 | break; | |
695a814e JS |
4879 | active_vlink_present = 0; |
4880 | ||
4881 | vports = lpfc_create_vport_work_array(phba); | |
4882 | if (vports) { | |
4883 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; | |
4884 | i++) { | |
4885 | if ((!(vports[i]->fc_flag & | |
4886 | FC_VPORT_CVL_RCVD)) && | |
4887 | (vports[i]->port_state > LPFC_FDISC)) { | |
4888 | active_vlink_present = 1; | |
4889 | break; | |
4890 | } | |
4891 | } | |
4892 | lpfc_destroy_vport_work_array(phba, vports); | |
4893 | } | |
4894 | ||
cc82355a JS |
4895 | /* |
4896 | * Don't re-instantiate if vport is marked for deletion. | |
4897 | * If we are here first then vport_delete is going to wait | |
4898 | * for discovery to complete. | |
4899 | */ | |
4900 | if (!(vport->load_flag & FC_UNLOADING) && | |
4901 | active_vlink_present) { | |
695a814e JS |
4902 | /* |
4903 | * If there are other active VLinks present, | |
4904 | * re-instantiate the Vlink using FDISC. | |
4905 | */ | |
256ec0d0 JS |
4906 | mod_timer(&ndlp->nlp_delayfunc, |
4907 | jiffies + msecs_to_jiffies(1000)); | |
fc2b989b | 4908 | shost = lpfc_shost_from_vport(vport); |
6669f9bb JS |
4909 | spin_lock_irq(shost->host_lock); |
4910 | ndlp->nlp_flag |= NLP_DELAY_TMO; | |
4911 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
4912 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
4913 | vport->port_state = LPFC_FDISC; | |
4914 | } else { | |
ecfd03c6 JS |
4915 | /* |
4916 | * Otherwise, we request port to rediscover | |
4917 | * the entire FCF table for a fast recovery | |
4918 | * from possible case that the current FCF | |
0c9ab6f5 JS |
4919 | * is no longer valid if we are not already |
4920 | * in the FCF failover process. | |
ecfd03c6 | 4921 | */ |
fc2b989b | 4922 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 4923 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
fc2b989b JS |
4924 | spin_unlock_irq(&phba->hbalock); |
4925 | break; | |
4926 | } | |
4927 | /* Mark the fast failover process in progress */ | |
0c9ab6f5 | 4928 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
fc2b989b | 4929 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 JS |
4930 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
4931 | LOG_DISCOVERY, | |
a93ff37a | 4932 | "2773 Start FCF failover per CVL, " |
70f3c073 | 4933 | "evt_tag:x%x\n", acqe_fip->event_tag); |
ecfd03c6 | 4934 | rc = lpfc_sli4_redisc_fcf_table(phba); |
fc2b989b | 4935 | if (rc) { |
0c9ab6f5 JS |
4936 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
4937 | LOG_DISCOVERY, | |
4938 | "2774 Issue FCF rediscover " | |
4939 | "mabilbox command failed, " | |
4940 | "through to CVL event\n"); | |
fc2b989b | 4941 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 4942 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b | 4943 | spin_unlock_irq(&phba->hbalock); |
ecfd03c6 JS |
4944 | /* |
4945 | * Last resort will be re-try on the | |
4946 | * the current registered FCF entry. | |
4947 | */ | |
4948 | lpfc_retry_pport_discovery(phba); | |
38b92ef8 JS |
4949 | } else |
4950 | /* | |
4951 | * Reset FCF roundrobin bmask for new | |
4952 | * discovery. | |
4953 | */ | |
7d791df7 | 4954 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
6669f9bb JS |
4955 | } |
4956 | break; | |
da0436e9 JS |
4957 | default: |
4958 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4959 | "0288 Unknown FCoE event type 0x%x event tag " | |
70f3c073 | 4960 | "0x%x\n", event_type, acqe_fip->event_tag); |
da0436e9 JS |
4961 | break; |
4962 | } | |
4963 | } | |
4964 | ||
4965 | /** | |
4966 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event | |
4967 | * @phba: pointer to lpfc hba data structure. | |
4968 | * @acqe_link: pointer to the async dcbx completion queue entry. | |
4969 | * | |
4970 | * This routine is to handle the SLI4 asynchronous dcbx event. | |
4971 | **/ | |
4972 | static void | |
4973 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, | |
4974 | struct lpfc_acqe_dcbx *acqe_dcbx) | |
4975 | { | |
4d9ab994 | 4976 | phba->fc_eventTag = acqe_dcbx->event_tag; |
da0436e9 JS |
4977 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
4978 | "0290 The SLI4 DCBX asynchronous event is not " | |
4979 | "handled yet\n"); | |
4980 | } | |
4981 | ||
b19a061a JS |
4982 | /** |
4983 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event | |
4984 | * @phba: pointer to lpfc hba data structure. | |
4985 | * @acqe_link: pointer to the async grp5 completion queue entry. | |
4986 | * | |
4987 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event | |
4988 | * is an asynchronous notified of a logical link speed change. The Port | |
4989 | * reports the logical link speed in units of 10Mbps. | |
4990 | **/ | |
4991 | static void | |
4992 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, | |
4993 | struct lpfc_acqe_grp5 *acqe_grp5) | |
4994 | { | |
4995 | uint16_t prev_ll_spd; | |
4996 | ||
4997 | phba->fc_eventTag = acqe_grp5->event_tag; | |
4998 | phba->fcoe_eventtag = acqe_grp5->event_tag; | |
4999 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; | |
5000 | phba->sli4_hba.link_state.logical_speed = | |
8b68cd52 | 5001 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
b19a061a JS |
5002 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
5003 | "2789 GRP5 Async Event: Updating logical link speed " | |
8b68cd52 JS |
5004 | "from %dMbps to %dMbps\n", prev_ll_spd, |
5005 | phba->sli4_hba.link_state.logical_speed); | |
b19a061a JS |
5006 | } |
5007 | ||
da0436e9 JS |
5008 | /** |
5009 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event | |
5010 | * @phba: pointer to lpfc hba data structure. | |
5011 | * | |
5012 | * This routine is invoked by the worker thread to process all the pending | |
5013 | * SLI4 asynchronous events. | |
5014 | **/ | |
5015 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) | |
5016 | { | |
5017 | struct lpfc_cq_event *cq_event; | |
5018 | ||
5019 | /* First, declare the async event has been handled */ | |
5020 | spin_lock_irq(&phba->hbalock); | |
5021 | phba->hba_flag &= ~ASYNC_EVENT; | |
5022 | spin_unlock_irq(&phba->hbalock); | |
5023 | /* Now, handle all the async events */ | |
5024 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { | |
5025 | /* Get the first event from the head of the event queue */ | |
5026 | spin_lock_irq(&phba->hbalock); | |
5027 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, | |
5028 | cq_event, struct lpfc_cq_event, list); | |
5029 | spin_unlock_irq(&phba->hbalock); | |
5030 | /* Process the asynchronous event */ | |
5031 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { | |
5032 | case LPFC_TRAILER_CODE_LINK: | |
5033 | lpfc_sli4_async_link_evt(phba, | |
5034 | &cq_event->cqe.acqe_link); | |
5035 | break; | |
5036 | case LPFC_TRAILER_CODE_FCOE: | |
70f3c073 | 5037 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
da0436e9 JS |
5038 | break; |
5039 | case LPFC_TRAILER_CODE_DCBX: | |
5040 | lpfc_sli4_async_dcbx_evt(phba, | |
5041 | &cq_event->cqe.acqe_dcbx); | |
5042 | break; | |
b19a061a JS |
5043 | case LPFC_TRAILER_CODE_GRP5: |
5044 | lpfc_sli4_async_grp5_evt(phba, | |
5045 | &cq_event->cqe.acqe_grp5); | |
5046 | break; | |
70f3c073 JS |
5047 | case LPFC_TRAILER_CODE_FC: |
5048 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); | |
5049 | break; | |
5050 | case LPFC_TRAILER_CODE_SLI: | |
5051 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); | |
5052 | break; | |
da0436e9 JS |
5053 | default: |
5054 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5055 | "1804 Invalid asynchrous event code: " | |
5056 | "x%x\n", bf_get(lpfc_trailer_code, | |
5057 | &cq_event->cqe.mcqe_cmpl)); | |
5058 | break; | |
5059 | } | |
5060 | /* Free the completion event processed to the free pool */ | |
5061 | lpfc_sli4_cq_event_release(phba, cq_event); | |
5062 | } | |
5063 | } | |
5064 | ||
ecfd03c6 JS |
5065 | /** |
5066 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event | |
5067 | * @phba: pointer to lpfc hba data structure. | |
5068 | * | |
5069 | * This routine is invoked by the worker thread to process FCF table | |
5070 | * rediscovery pending completion event. | |
5071 | **/ | |
5072 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) | |
5073 | { | |
5074 | int rc; | |
5075 | ||
5076 | spin_lock_irq(&phba->hbalock); | |
5077 | /* Clear FCF rediscovery timeout event */ | |
5078 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; | |
5079 | /* Clear driver fast failover FCF record flag */ | |
5080 | phba->fcf.failover_rec.flag = 0; | |
5081 | /* Set state for FCF fast failover */ | |
5082 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; | |
5083 | spin_unlock_irq(&phba->hbalock); | |
5084 | ||
5085 | /* Scan FCF table from the first entry to re-discover SAN */ | |
0c9ab6f5 | 5086 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
a93ff37a | 5087 | "2777 Start post-quiescent FCF table scan\n"); |
0c9ab6f5 | 5088 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
ecfd03c6 | 5089 | if (rc) |
0c9ab6f5 JS |
5090 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
5091 | "2747 Issue FCF scan read FCF mailbox " | |
5092 | "command failed 0x%x\n", rc); | |
ecfd03c6 JS |
5093 | } |
5094 | ||
da0436e9 JS |
5095 | /** |
5096 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table | |
5097 | * @phba: pointer to lpfc hba data structure. | |
5098 | * @dev_grp: The HBA PCI-Device group number. | |
5099 | * | |
5100 | * This routine is invoked to set up the per HBA PCI-Device group function | |
5101 | * API jump table entries. | |
5102 | * | |
5103 | * Return: 0 if success, otherwise -ENODEV | |
5104 | **/ | |
5105 | int | |
5106 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
5107 | { | |
5108 | int rc; | |
5109 | ||
5110 | /* Set up lpfc PCI-device group */ | |
5111 | phba->pci_dev_grp = dev_grp; | |
5112 | ||
5113 | /* The LPFC_PCI_DEV_OC uses SLI4 */ | |
5114 | if (dev_grp == LPFC_PCI_DEV_OC) | |
5115 | phba->sli_rev = LPFC_SLI_REV4; | |
5116 | ||
5117 | /* Set up device INIT API function jump table */ | |
5118 | rc = lpfc_init_api_table_setup(phba, dev_grp); | |
5119 | if (rc) | |
5120 | return -ENODEV; | |
5121 | /* Set up SCSI API function jump table */ | |
5122 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); | |
5123 | if (rc) | |
5124 | return -ENODEV; | |
5125 | /* Set up SLI API function jump table */ | |
5126 | rc = lpfc_sli_api_table_setup(phba, dev_grp); | |
5127 | if (rc) | |
5128 | return -ENODEV; | |
5129 | /* Set up MBOX API function jump table */ | |
5130 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); | |
5131 | if (rc) | |
5132 | return -ENODEV; | |
5133 | ||
5134 | return 0; | |
5b75da2f JS |
5135 | } |
5136 | ||
5137 | /** | |
3621a710 | 5138 | * lpfc_log_intr_mode - Log the active interrupt mode |
5b75da2f JS |
5139 | * @phba: pointer to lpfc hba data structure. |
5140 | * @intr_mode: active interrupt mode adopted. | |
5141 | * | |
5142 | * This routine it invoked to log the currently used active interrupt mode | |
5143 | * to the device. | |
3772a991 JS |
5144 | **/ |
5145 | static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode) | |
5b75da2f JS |
5146 | { |
5147 | switch (intr_mode) { | |
5148 | case 0: | |
5149 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5150 | "0470 Enable INTx interrupt mode.\n"); | |
5151 | break; | |
5152 | case 1: | |
5153 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5154 | "0481 Enabled MSI interrupt mode.\n"); | |
5155 | break; | |
5156 | case 2: | |
5157 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5158 | "0480 Enabled MSI-X interrupt mode.\n"); | |
5159 | break; | |
5160 | default: | |
5161 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5162 | "0482 Illegal interrupt mode.\n"); | |
5163 | break; | |
5164 | } | |
5165 | return; | |
5166 | } | |
5167 | ||
5b75da2f | 5168 | /** |
3772a991 | 5169 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
5b75da2f JS |
5170 | * @phba: pointer to lpfc hba data structure. |
5171 | * | |
3772a991 JS |
5172 | * This routine is invoked to enable the PCI device that is common to all |
5173 | * PCI devices. | |
5b75da2f JS |
5174 | * |
5175 | * Return codes | |
af901ca1 | 5176 | * 0 - successful |
3772a991 | 5177 | * other values - error |
5b75da2f | 5178 | **/ |
3772a991 JS |
5179 | static int |
5180 | lpfc_enable_pci_dev(struct lpfc_hba *phba) | |
5b75da2f | 5181 | { |
3772a991 | 5182 | struct pci_dev *pdev; |
5b75da2f | 5183 | |
3772a991 JS |
5184 | /* Obtain PCI device reference */ |
5185 | if (!phba->pcidev) | |
5186 | goto out_error; | |
5187 | else | |
5188 | pdev = phba->pcidev; | |
3772a991 JS |
5189 | /* Enable PCI device */ |
5190 | if (pci_enable_device_mem(pdev)) | |
5191 | goto out_error; | |
5192 | /* Request PCI resource for the device */ | |
e0c0483c | 5193 | if (pci_request_mem_regions(pdev, LPFC_DRIVER_NAME)) |
3772a991 JS |
5194 | goto out_disable_device; |
5195 | /* Set up device as PCI master and save state for EEH */ | |
5196 | pci_set_master(pdev); | |
5197 | pci_try_set_mwi(pdev); | |
5198 | pci_save_state(pdev); | |
5b75da2f | 5199 | |
0558056c | 5200 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
453193e0 | 5201 | if (pci_is_pcie(pdev)) |
0558056c JS |
5202 | pdev->needs_freset = 1; |
5203 | ||
3772a991 | 5204 | return 0; |
5b75da2f | 5205 | |
3772a991 JS |
5206 | out_disable_device: |
5207 | pci_disable_device(pdev); | |
5208 | out_error: | |
079b5c91 | 5209 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e0c0483c | 5210 | "1401 Failed to enable pci device\n"); |
3772a991 | 5211 | return -ENODEV; |
5b75da2f JS |
5212 | } |
5213 | ||
5214 | /** | |
3772a991 | 5215 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
5b75da2f JS |
5216 | * @phba: pointer to lpfc hba data structure. |
5217 | * | |
3772a991 JS |
5218 | * This routine is invoked to disable the PCI device that is common to all |
5219 | * PCI devices. | |
5b75da2f JS |
5220 | **/ |
5221 | static void | |
3772a991 | 5222 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
5b75da2f | 5223 | { |
3772a991 | 5224 | struct pci_dev *pdev; |
5b75da2f | 5225 | |
3772a991 JS |
5226 | /* Obtain PCI device reference */ |
5227 | if (!phba->pcidev) | |
5228 | return; | |
5229 | else | |
5230 | pdev = phba->pcidev; | |
3772a991 | 5231 | /* Release PCI resource and disable PCI device */ |
e0c0483c | 5232 | pci_release_mem_regions(pdev); |
3772a991 | 5233 | pci_disable_device(pdev); |
5b75da2f JS |
5234 | |
5235 | return; | |
5236 | } | |
5237 | ||
e59058c4 | 5238 | /** |
3772a991 JS |
5239 | * lpfc_reset_hba - Reset a hba |
5240 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 5241 | * |
3772a991 JS |
5242 | * This routine is invoked to reset a hba device. It brings the HBA |
5243 | * offline, performs a board restart, and then brings the board back | |
5244 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up | |
5245 | * on outstanding mailbox commands. | |
e59058c4 | 5246 | **/ |
3772a991 JS |
5247 | void |
5248 | lpfc_reset_hba(struct lpfc_hba *phba) | |
dea3101e | 5249 | { |
3772a991 JS |
5250 | /* If resets are disabled then set error state and return. */ |
5251 | if (!phba->cfg_enable_hba_reset) { | |
5252 | phba->link_state = LPFC_HBA_ERROR; | |
5253 | return; | |
5254 | } | |
ee62021a JS |
5255 | if (phba->sli.sli_flag & LPFC_SLI_ACTIVE) |
5256 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); | |
5257 | else | |
5258 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); | |
3772a991 JS |
5259 | lpfc_offline(phba); |
5260 | lpfc_sli_brdrestart(phba); | |
5261 | lpfc_online(phba); | |
5262 | lpfc_unblock_mgmt_io(phba); | |
5263 | } | |
dea3101e | 5264 | |
0a96e975 JS |
5265 | /** |
5266 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions | |
5267 | * @phba: pointer to lpfc hba data structure. | |
5268 | * | |
5269 | * This function enables the PCI SR-IOV virtual functions to a physical | |
5270 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to | |
5271 | * enable the number of virtual functions to the physical function. As | |
5272 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() | |
5273 | * API call does not considered as an error condition for most of the device. | |
5274 | **/ | |
5275 | uint16_t | |
5276 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) | |
5277 | { | |
5278 | struct pci_dev *pdev = phba->pcidev; | |
5279 | uint16_t nr_virtfn; | |
5280 | int pos; | |
5281 | ||
0a96e975 JS |
5282 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
5283 | if (pos == 0) | |
5284 | return 0; | |
5285 | ||
5286 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); | |
5287 | return nr_virtfn; | |
5288 | } | |
5289 | ||
912e3acd JS |
5290 | /** |
5291 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions | |
5292 | * @phba: pointer to lpfc hba data structure. | |
5293 | * @nr_vfn: number of virtual functions to be enabled. | |
5294 | * | |
5295 | * This function enables the PCI SR-IOV virtual functions to a physical | |
5296 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to | |
5297 | * enable the number of virtual functions to the physical function. As | |
5298 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() | |
5299 | * API call does not considered as an error condition for most of the device. | |
5300 | **/ | |
5301 | int | |
5302 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) | |
5303 | { | |
5304 | struct pci_dev *pdev = phba->pcidev; | |
0a96e975 | 5305 | uint16_t max_nr_vfn; |
912e3acd JS |
5306 | int rc; |
5307 | ||
0a96e975 JS |
5308 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
5309 | if (nr_vfn > max_nr_vfn) { | |
5310 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5311 | "3057 Requested vfs (%d) greater than " | |
5312 | "supported vfs (%d)", nr_vfn, max_nr_vfn); | |
5313 | return -EINVAL; | |
5314 | } | |
5315 | ||
912e3acd JS |
5316 | rc = pci_enable_sriov(pdev, nr_vfn); |
5317 | if (rc) { | |
5318 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
5319 | "2806 Failed to enable sriov on this device " | |
5320 | "with vfn number nr_vf:%d, rc:%d\n", | |
5321 | nr_vfn, rc); | |
5322 | } else | |
5323 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
5324 | "2807 Successful enable sriov on this device " | |
5325 | "with vfn number nr_vf:%d\n", nr_vfn); | |
5326 | return rc; | |
5327 | } | |
5328 | ||
3772a991 | 5329 | /** |
895427bd | 5330 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. |
3772a991 JS |
5331 | * @phba: pointer to lpfc hba data structure. |
5332 | * | |
895427bd JS |
5333 | * This routine is invoked to set up the driver internal resources before the |
5334 | * device specific resource setup to support the HBA device it attached to. | |
3772a991 JS |
5335 | * |
5336 | * Return codes | |
895427bd JS |
5337 | * 0 - successful |
5338 | * other values - error | |
3772a991 JS |
5339 | **/ |
5340 | static int | |
895427bd | 5341 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) |
3772a991 | 5342 | { |
895427bd | 5343 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 5344 | |
2e0fef85 | 5345 | /* |
895427bd | 5346 | * Driver resources common to all SLI revisions |
2e0fef85 | 5347 | */ |
895427bd JS |
5348 | atomic_set(&phba->fast_event_count, 0); |
5349 | spin_lock_init(&phba->hbalock); | |
dea3101e | 5350 | |
895427bd JS |
5351 | /* Initialize ndlp management spinlock */ |
5352 | spin_lock_init(&phba->ndlp_lock); | |
5353 | ||
5354 | INIT_LIST_HEAD(&phba->port_list); | |
5355 | INIT_LIST_HEAD(&phba->work_list); | |
5356 | init_waitqueue_head(&phba->wait_4_mlo_m_q); | |
5357 | ||
5358 | /* Initialize the wait queue head for the kernel thread */ | |
5359 | init_waitqueue_head(&phba->work_waitq); | |
5360 | ||
5361 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
f358dd0c | 5362 | "1403 Protocols supported %s %s %s\n", |
895427bd JS |
5363 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) ? |
5364 | "SCSI" : " "), | |
5365 | ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) ? | |
f358dd0c JS |
5366 | "NVME" : " "), |
5367 | (phba->nvmet_support ? "NVMET" : " ")); | |
895427bd JS |
5368 | |
5369 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { | |
5370 | /* Initialize the scsi buffer list used by driver for scsi IO */ | |
5371 | spin_lock_init(&phba->scsi_buf_list_get_lock); | |
5372 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); | |
5373 | spin_lock_init(&phba->scsi_buf_list_put_lock); | |
5374 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); | |
5375 | } | |
5376 | ||
5377 | if ((phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) && | |
5378 | (phba->nvmet_support == 0)) { | |
5379 | /* Initialize the NVME buffer list used by driver for NVME IO */ | |
5380 | spin_lock_init(&phba->nvme_buf_list_get_lock); | |
5381 | INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_get); | |
5382 | spin_lock_init(&phba->nvme_buf_list_put_lock); | |
5383 | INIT_LIST_HEAD(&phba->lpfc_nvme_buf_list_put); | |
5384 | } | |
5385 | ||
5386 | /* Initialize the fabric iocb list */ | |
5387 | INIT_LIST_HEAD(&phba->fabric_iocb_list); | |
5388 | ||
5389 | /* Initialize list to save ELS buffers */ | |
5390 | INIT_LIST_HEAD(&phba->elsbuf); | |
5391 | ||
5392 | /* Initialize FCF connection rec list */ | |
5393 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); | |
5394 | ||
5395 | /* Initialize OAS configuration list */ | |
5396 | spin_lock_init(&phba->devicelock); | |
5397 | INIT_LIST_HEAD(&phba->luns); | |
858c9f6c | 5398 | |
3772a991 | 5399 | /* MBOX heartbeat timer */ |
dea3101e JB |
5400 | init_timer(&psli->mbox_tmo); |
5401 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
2e0fef85 | 5402 | psli->mbox_tmo.data = (unsigned long) phba; |
3772a991 | 5403 | /* Fabric block timer */ |
92d7f7b0 JS |
5404 | init_timer(&phba->fabric_block_timer); |
5405 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
5406 | phba->fabric_block_timer.data = (unsigned long) phba; | |
3772a991 | 5407 | /* EA polling mode timer */ |
9399627f JS |
5408 | init_timer(&phba->eratt_poll); |
5409 | phba->eratt_poll.function = lpfc_poll_eratt; | |
5410 | phba->eratt_poll.data = (unsigned long) phba; | |
895427bd JS |
5411 | /* Heartbeat timer */ |
5412 | init_timer(&phba->hb_tmofunc); | |
5413 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
5414 | phba->hb_tmofunc.data = (unsigned long)phba; | |
5415 | ||
5416 | return 0; | |
5417 | } | |
5418 | ||
5419 | /** | |
5420 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev | |
5421 | * @phba: pointer to lpfc hba data structure. | |
5422 | * | |
5423 | * This routine is invoked to set up the driver internal resources specific to | |
5424 | * support the SLI-3 HBA device it attached to. | |
5425 | * | |
5426 | * Return codes | |
5427 | * 0 - successful | |
5428 | * other values - error | |
5429 | **/ | |
5430 | static int | |
5431 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) | |
5432 | { | |
5433 | int rc; | |
5434 | ||
5435 | /* | |
5436 | * Initialize timers used by driver | |
5437 | */ | |
5438 | ||
5439 | /* FCP polling mode timer */ | |
5440 | init_timer(&phba->fcp_poll_timer); | |
5441 | phba->fcp_poll_timer.function = lpfc_poll_timeout; | |
5442 | phba->fcp_poll_timer.data = (unsigned long) phba; | |
dea3101e | 5443 | |
3772a991 JS |
5444 | /* Host attention work mask setup */ |
5445 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); | |
5446 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); | |
dea3101e | 5447 | |
3772a991 JS |
5448 | /* Get all the module params for configuring this host */ |
5449 | lpfc_get_cfgparam(phba); | |
895427bd JS |
5450 | /* Set up phase-1 common device driver resources */ |
5451 | ||
5452 | rc = lpfc_setup_driver_resource_phase1(phba); | |
5453 | if (rc) | |
5454 | return -ENODEV; | |
5455 | ||
49198b37 JS |
5456 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
5457 | phba->menlo_flag |= HBA_MENLO_SUPPORT; | |
5458 | /* check for menlo minimum sg count */ | |
5459 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) | |
5460 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; | |
5461 | } | |
5462 | ||
895427bd JS |
5463 | if (!phba->sli.sli3_ring) |
5464 | phba->sli.sli3_ring = kzalloc(LPFC_SLI3_MAX_RING * | |
2a76a283 | 5465 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
895427bd | 5466 | if (!phba->sli.sli3_ring) |
2a76a283 JS |
5467 | return -ENOMEM; |
5468 | ||
dea3101e | 5469 | /* |
96f7077f | 5470 | * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size |
3772a991 | 5471 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
dea3101e | 5472 | */ |
3772a991 | 5473 | |
96f7077f JS |
5474 | /* Initialize the host templates the configured values. */ |
5475 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
5f406fae | 5476 | lpfc_template_s3.sg_tablesize = phba->cfg_sg_seg_cnt; |
96f7077f JS |
5477 | |
5478 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ | |
3772a991 | 5479 | if (phba->cfg_enable_bg) { |
96f7077f JS |
5480 | /* |
5481 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, | |
5482 | * the FCP rsp, and a BDE for each. Sice we have no control | |
5483 | * over how many protection data segments the SCSI Layer | |
5484 | * will hand us (ie: there could be one for every block | |
5485 | * in the IO), we just allocate enough BDEs to accomidate | |
5486 | * our max amount and we need to limit lpfc_sg_seg_cnt to | |
5487 | * minimize the risk of running out. | |
5488 | */ | |
5489 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + | |
5490 | sizeof(struct fcp_rsp) + | |
5491 | (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64)); | |
5492 | ||
5493 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) | |
5494 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; | |
5495 | ||
5496 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ | |
5497 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; | |
5498 | } else { | |
5499 | /* | |
5500 | * The scsi_buf for a regular I/O will hold the FCP cmnd, | |
5501 | * the FCP rsp, a BDE for each, and a BDE for up to | |
5502 | * cfg_sg_seg_cnt data segments. | |
5503 | */ | |
5504 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + | |
5505 | sizeof(struct fcp_rsp) + | |
5506 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); | |
5507 | ||
5508 | /* Total BDEs in BPL for scsi_sg_list */ | |
5509 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; | |
901a920f | 5510 | } |
dea3101e | 5511 | |
96f7077f JS |
5512 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
5513 | "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", | |
5514 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, | |
5515 | phba->cfg_total_seg_cnt); | |
dea3101e | 5516 | |
3772a991 JS |
5517 | phba->max_vpi = LPFC_MAX_VPI; |
5518 | /* This will be set to correct value after config_port mbox */ | |
5519 | phba->max_vports = 0; | |
dea3101e | 5520 | |
3772a991 JS |
5521 | /* |
5522 | * Initialize the SLI Layer to run with lpfc HBAs. | |
5523 | */ | |
5524 | lpfc_sli_setup(phba); | |
895427bd | 5525 | lpfc_sli_queue_init(phba); |
ed957684 | 5526 | |
3772a991 JS |
5527 | /* Allocate device driver memory */ |
5528 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) | |
5529 | return -ENOMEM; | |
51ef4c26 | 5530 | |
912e3acd JS |
5531 | /* |
5532 | * Enable sr-iov virtual functions if supported and configured | |
5533 | * through the module parameter. | |
5534 | */ | |
5535 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
5536 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, | |
5537 | phba->cfg_sriov_nr_virtfn); | |
5538 | if (rc) { | |
5539 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
5540 | "2808 Requested number of SR-IOV " | |
5541 | "virtual functions (%d) is not " | |
5542 | "supported\n", | |
5543 | phba->cfg_sriov_nr_virtfn); | |
5544 | phba->cfg_sriov_nr_virtfn = 0; | |
5545 | } | |
5546 | } | |
5547 | ||
3772a991 JS |
5548 | return 0; |
5549 | } | |
ed957684 | 5550 | |
3772a991 JS |
5551 | /** |
5552 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev | |
5553 | * @phba: pointer to lpfc hba data structure. | |
5554 | * | |
5555 | * This routine is invoked to unset the driver internal resources set up | |
5556 | * specific for supporting the SLI-3 HBA device it attached to. | |
5557 | **/ | |
5558 | static void | |
5559 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) | |
5560 | { | |
5561 | /* Free device driver memory allocated */ | |
5562 | lpfc_mem_free_all(phba); | |
3163f725 | 5563 | |
3772a991 JS |
5564 | return; |
5565 | } | |
dea3101e | 5566 | |
3772a991 | 5567 | /** |
da0436e9 | 5568 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
3772a991 JS |
5569 | * @phba: pointer to lpfc hba data structure. |
5570 | * | |
da0436e9 JS |
5571 | * This routine is invoked to set up the driver internal resources specific to |
5572 | * support the SLI-4 HBA device it attached to. | |
3772a991 JS |
5573 | * |
5574 | * Return codes | |
af901ca1 | 5575 | * 0 - successful |
da0436e9 | 5576 | * other values - error |
3772a991 JS |
5577 | **/ |
5578 | static int | |
da0436e9 | 5579 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
3772a991 | 5580 | { |
28baac74 | 5581 | LPFC_MBOXQ_t *mboxq; |
f358dd0c | 5582 | MAILBOX_t *mb; |
895427bd | 5583 | int rc, i, max_buf_size; |
28baac74 JS |
5584 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
5585 | struct lpfc_mqe *mqe; | |
09294d46 | 5586 | int longs; |
1ba981fd | 5587 | int fof_vectors = 0; |
f358dd0c | 5588 | uint64_t wwn; |
da0436e9 | 5589 | |
895427bd JS |
5590 | phba->sli4_hba.num_online_cpu = num_online_cpus(); |
5591 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; | |
5592 | phba->sli4_hba.curr_disp_cpu = 0; | |
5593 | ||
716d3bc5 JS |
5594 | /* Get all the module params for configuring this host */ |
5595 | lpfc_get_cfgparam(phba); | |
5596 | ||
895427bd JS |
5597 | /* Set up phase-1 common device driver resources */ |
5598 | rc = lpfc_setup_driver_resource_phase1(phba); | |
5599 | if (rc) | |
5600 | return -ENODEV; | |
5601 | ||
da0436e9 JS |
5602 | /* Before proceed, wait for POST done and device ready */ |
5603 | rc = lpfc_sli4_post_status_check(phba); | |
5604 | if (rc) | |
5605 | return -ENODEV; | |
5606 | ||
3772a991 | 5607 | /* |
da0436e9 | 5608 | * Initialize timers used by driver |
3772a991 | 5609 | */ |
3772a991 | 5610 | |
19ca7609 JS |
5611 | init_timer(&phba->rrq_tmr); |
5612 | phba->rrq_tmr.function = lpfc_rrq_timeout; | |
5613 | phba->rrq_tmr.data = (unsigned long)phba; | |
3772a991 | 5614 | |
ecfd03c6 JS |
5615 | /* FCF rediscover timer */ |
5616 | init_timer(&phba->fcf.redisc_wait); | |
5617 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; | |
5618 | phba->fcf.redisc_wait.data = (unsigned long)phba; | |
5619 | ||
7ad20aa9 JS |
5620 | /* |
5621 | * Control structure for handling external multi-buffer mailbox | |
5622 | * command pass-through. | |
5623 | */ | |
5624 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, | |
5625 | sizeof(struct lpfc_mbox_ext_buf_ctx)); | |
5626 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); | |
5627 | ||
da0436e9 | 5628 | phba->max_vpi = LPFC_MAX_VPI; |
67d12733 | 5629 | |
da0436e9 JS |
5630 | /* This will be set to correct value after the read_config mbox */ |
5631 | phba->max_vports = 0; | |
3772a991 | 5632 | |
da0436e9 JS |
5633 | /* Program the default value of vlan_id and fc_map */ |
5634 | phba->valid_vlan = 0; | |
5635 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
5636 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
5637 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
3772a991 | 5638 | |
2a76a283 JS |
5639 | /* |
5640 | * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands | |
895427bd JS |
5641 | * we will associate a new ring, for each EQ/CQ/WQ tuple. |
5642 | * The WQ create will allocate the ring. | |
2a76a283 | 5643 | */ |
09294d46 | 5644 | |
da0436e9 | 5645 | /* |
09294d46 JS |
5646 | * It doesn't matter what family our adapter is in, we are |
5647 | * limited to 2 Pages, 512 SGEs, for our SGL. | |
5648 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp | |
5649 | */ | |
5650 | max_buf_size = (2 * SLI4_PAGE_SIZE); | |
5651 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2) | |
5652 | phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2; | |
09294d46 | 5653 | |
da0436e9 | 5654 | /* |
895427bd JS |
5655 | * Since lpfc_sg_seg_cnt is module param, the sg_dma_buf_size |
5656 | * used to create the sg_dma_buf_pool must be calculated. | |
da0436e9 | 5657 | */ |
96f7077f JS |
5658 | if (phba->cfg_enable_bg) { |
5659 | /* | |
895427bd JS |
5660 | * The scsi_buf for a T10-DIF I/O holds the FCP cmnd, |
5661 | * the FCP rsp, and a SGE. Sice we have no control | |
5662 | * over how many protection segments the SCSI Layer | |
96f7077f | 5663 | * will hand us (ie: there could be one for every block |
895427bd JS |
5664 | * in the IO), just allocate enough SGEs to accomidate |
5665 | * our max amount and we need to limit lpfc_sg_seg_cnt | |
5666 | * to minimize the risk of running out. | |
96f7077f JS |
5667 | */ |
5668 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + | |
895427bd | 5669 | sizeof(struct fcp_rsp) + max_buf_size; |
96f7077f JS |
5670 | |
5671 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ | |
5672 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; | |
5673 | ||
5674 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF) | |
895427bd JS |
5675 | phba->cfg_sg_seg_cnt = |
5676 | LPFC_MAX_SG_SLI4_SEG_CNT_DIF; | |
96f7077f JS |
5677 | } else { |
5678 | /* | |
895427bd | 5679 | * The scsi_buf for a regular I/O holds the FCP cmnd, |
96f7077f JS |
5680 | * the FCP rsp, a SGE for each, and a SGE for up to |
5681 | * cfg_sg_seg_cnt data segments. | |
5682 | */ | |
5683 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + | |
895427bd JS |
5684 | sizeof(struct fcp_rsp) + |
5685 | ((phba->cfg_sg_seg_cnt + 2) * | |
5686 | sizeof(struct sli4_sge)); | |
96f7077f JS |
5687 | |
5688 | /* Total SGEs for scsi_sg_list */ | |
5689 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; | |
895427bd | 5690 | |
96f7077f | 5691 | /* |
895427bd JS |
5692 | * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only |
5693 | * need to post 1 page for the SGL. | |
96f7077f | 5694 | */ |
085c647c | 5695 | } |
acd6859b | 5696 | |
96f7077f JS |
5697 | /* Initialize the host templates with the updated values. */ |
5698 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
5699 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
5700 | ||
5701 | if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) | |
5702 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; | |
5703 | else | |
5704 | phba->cfg_sg_dma_buf_size = | |
5705 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); | |
5706 | ||
5707 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, | |
5708 | "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n", | |
5709 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, | |
5710 | phba->cfg_total_seg_cnt); | |
3772a991 | 5711 | |
da0436e9 | 5712 | /* Initialize buffer queue management fields */ |
895427bd | 5713 | INIT_LIST_HEAD(&phba->hbqs[LPFC_ELS_HBQ].hbq_buffer_list); |
da0436e9 JS |
5714 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; |
5715 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; | |
3772a991 | 5716 | |
da0436e9 JS |
5717 | /* |
5718 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. | |
5719 | */ | |
895427bd JS |
5720 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) { |
5721 | /* Initialize the Abort scsi buffer list used by driver */ | |
5722 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
5723 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
5724 | } | |
5725 | ||
5726 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { | |
5727 | /* Initialize the Abort nvme buffer list used by driver */ | |
5728 | spin_lock_init(&phba->sli4_hba.abts_nvme_buf_list_lock); | |
5729 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvme_buf_list); | |
5730 | } | |
5731 | ||
da0436e9 | 5732 | /* This abort list used by worker thread */ |
895427bd | 5733 | spin_lock_init(&phba->sli4_hba.sgl_list_lock); |
f358dd0c | 5734 | spin_lock_init(&phba->sli4_hba.nvmet_io_lock); |
3772a991 | 5735 | |
da0436e9 | 5736 | /* |
6d368e53 | 5737 | * Initialize driver internal slow-path work queues |
da0436e9 | 5738 | */ |
3772a991 | 5739 | |
da0436e9 JS |
5740 | /* Driver internel slow-path CQ Event pool */ |
5741 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); | |
5742 | /* Response IOCB work queue list */ | |
45ed1190 | 5743 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
da0436e9 JS |
5744 | /* Asynchronous event CQ Event work queue list */ |
5745 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); | |
5746 | /* Fast-path XRI aborted CQ Event work queue list */ | |
5747 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
5748 | /* Slow-path XRI aborted CQ Event work queue list */ | |
5749 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
5750 | /* Receive queue CQ Event work queue list */ | |
5751 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); | |
5752 | ||
6d368e53 JS |
5753 | /* Initialize extent block lists. */ |
5754 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); | |
5755 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); | |
5756 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); | |
5757 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); | |
5758 | ||
448193b5 JS |
5759 | /* initialize optic_state to 0xFF */ |
5760 | phba->sli4_hba.lnk_info.optic_state = 0xff; | |
5761 | ||
da0436e9 JS |
5762 | /* Allocate device driver memory */ |
5763 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); | |
5764 | if (rc) | |
5765 | return -ENOMEM; | |
5766 | ||
2fcee4bf JS |
5767 | /* IF Type 2 ports get initialized now. */ |
5768 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
5769 | LPFC_SLI_INTF_IF_TYPE_2) { | |
5770 | rc = lpfc_pci_function_reset(phba); | |
895427bd JS |
5771 | if (unlikely(rc)) { |
5772 | rc = -ENODEV; | |
5773 | goto out_free_mem; | |
5774 | } | |
946727dc | 5775 | phba->temp_sensor_support = 1; |
2fcee4bf JS |
5776 | } |
5777 | ||
da0436e9 JS |
5778 | /* Create the bootstrap mailbox command */ |
5779 | rc = lpfc_create_bootstrap_mbox(phba); | |
5780 | if (unlikely(rc)) | |
5781 | goto out_free_mem; | |
5782 | ||
5783 | /* Set up the host's endian order with the device. */ | |
5784 | rc = lpfc_setup_endian_order(phba); | |
5785 | if (unlikely(rc)) | |
5786 | goto out_free_bsmbx; | |
5787 | ||
5788 | /* Set up the hba's configuration parameters. */ | |
5789 | rc = lpfc_sli4_read_config(phba); | |
cff261f6 JS |
5790 | if (unlikely(rc)) |
5791 | goto out_free_bsmbx; | |
5792 | rc = lpfc_mem_alloc_active_rrq_pool_s4(phba); | |
da0436e9 JS |
5793 | if (unlikely(rc)) |
5794 | goto out_free_bsmbx; | |
5795 | ||
2fcee4bf JS |
5796 | /* IF Type 0 ports get initialized now. */ |
5797 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
5798 | LPFC_SLI_INTF_IF_TYPE_0) { | |
5799 | rc = lpfc_pci_function_reset(phba); | |
5800 | if (unlikely(rc)) | |
5801 | goto out_free_bsmbx; | |
5802 | } | |
da0436e9 | 5803 | |
cb5172ea JS |
5804 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
5805 | GFP_KERNEL); | |
5806 | if (!mboxq) { | |
5807 | rc = -ENOMEM; | |
5808 | goto out_free_bsmbx; | |
5809 | } | |
5810 | ||
f358dd0c | 5811 | /* Check for NVMET being configured */ |
895427bd | 5812 | phba->nvmet_support = 0; |
f358dd0c JS |
5813 | if (lpfc_enable_nvmet_cnt) { |
5814 | ||
5815 | /* First get WWN of HBA instance */ | |
5816 | lpfc_read_nv(phba, mboxq); | |
5817 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
5818 | if (rc != MBX_SUCCESS) { | |
5819 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5820 | "6016 Mailbox failed , mbxCmd x%x " | |
5821 | "READ_NV, mbxStatus x%x\n", | |
5822 | bf_get(lpfc_mqe_command, &mboxq->u.mqe), | |
5823 | bf_get(lpfc_mqe_status, &mboxq->u.mqe)); | |
5824 | rc = -EIO; | |
5825 | goto out_free_bsmbx; | |
5826 | } | |
5827 | mb = &mboxq->u.mb; | |
5828 | memcpy(&wwn, (char *)mb->un.varRDnvp.nodename, | |
5829 | sizeof(uint64_t)); | |
5830 | wwn = cpu_to_be64(wwn); | |
5831 | phba->sli4_hba.wwnn.u.name = wwn; | |
5832 | memcpy(&wwn, (char *)mb->un.varRDnvp.portname, | |
5833 | sizeof(uint64_t)); | |
5834 | /* wwn is WWPN of HBA instance */ | |
5835 | wwn = cpu_to_be64(wwn); | |
5836 | phba->sli4_hba.wwpn.u.name = wwn; | |
5837 | ||
5838 | /* Check to see if it matches any module parameter */ | |
5839 | for (i = 0; i < lpfc_enable_nvmet_cnt; i++) { | |
5840 | if (wwn == lpfc_enable_nvmet[i]) { | |
5841 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5842 | "6017 NVME Target %016llx\n", | |
5843 | wwn); | |
5844 | phba->nvmet_support = 1; /* a match */ | |
5845 | } | |
5846 | } | |
5847 | } | |
895427bd JS |
5848 | |
5849 | lpfc_nvme_mod_param_dep(phba); | |
5850 | ||
fedd3b7b | 5851 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
cb5172ea JS |
5852 | lpfc_supported_pages(mboxq); |
5853 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
fedd3b7b JS |
5854 | if (!rc) { |
5855 | mqe = &mboxq->u.mqe; | |
5856 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), | |
5857 | LPFC_MAX_SUPPORTED_PAGES); | |
5858 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { | |
5859 | switch (pn_page[i]) { | |
5860 | case LPFC_SLI4_PARAMETERS: | |
5861 | phba->sli4_hba.pc_sli4_params.supported = 1; | |
5862 | break; | |
5863 | default: | |
5864 | break; | |
5865 | } | |
5866 | } | |
5867 | /* Read the port's SLI4 Parameters capabilities if supported. */ | |
5868 | if (phba->sli4_hba.pc_sli4_params.supported) | |
5869 | rc = lpfc_pc_sli4_params_get(phba, mboxq); | |
5870 | if (rc) { | |
5871 | mempool_free(mboxq, phba->mbox_mem_pool); | |
5872 | rc = -EIO; | |
5873 | goto out_free_bsmbx; | |
cb5172ea JS |
5874 | } |
5875 | } | |
65791f1f | 5876 | |
fedd3b7b JS |
5877 | /* |
5878 | * Get sli4 parameters that override parameters from Port capabilities. | |
6d368e53 JS |
5879 | * If this call fails, it isn't critical unless the SLI4 parameters come |
5880 | * back in conflict. | |
fedd3b7b | 5881 | */ |
6d368e53 JS |
5882 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
5883 | if (rc) { | |
5884 | if (phba->sli4_hba.extents_in_use && | |
5885 | phba->sli4_hba.rpi_hdrs_in_use) { | |
5886 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5887 | "2999 Unsupported SLI4 Parameters " | |
5888 | "Extents and RPI headers enabled.\n"); | |
6d368e53 | 5889 | } |
895427bd JS |
5890 | mempool_free(mboxq, phba->mbox_mem_pool); |
5891 | goto out_free_bsmbx; | |
6d368e53 | 5892 | } |
895427bd | 5893 | |
cb5172ea | 5894 | mempool_free(mboxq, phba->mbox_mem_pool); |
1ba981fd JS |
5895 | |
5896 | /* Verify OAS is supported */ | |
5897 | lpfc_sli4_oas_verify(phba); | |
5898 | if (phba->cfg_fof) | |
5899 | fof_vectors = 1; | |
5900 | ||
5350d872 JS |
5901 | /* Verify all the SLI4 queues */ |
5902 | rc = lpfc_sli4_queue_verify(phba); | |
da0436e9 JS |
5903 | if (rc) |
5904 | goto out_free_bsmbx; | |
5905 | ||
5906 | /* Create driver internal CQE event pool */ | |
5907 | rc = lpfc_sli4_cq_event_pool_create(phba); | |
5908 | if (rc) | |
5350d872 | 5909 | goto out_free_bsmbx; |
da0436e9 | 5910 | |
8a9d2e80 JS |
5911 | /* Initialize sgl lists per host */ |
5912 | lpfc_init_sgl_list(phba); | |
5913 | ||
5914 | /* Allocate and initialize active sgl array */ | |
da0436e9 JS |
5915 | rc = lpfc_init_active_sgl_array(phba); |
5916 | if (rc) { | |
5917 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5918 | "1430 Failed to initialize sgl list.\n"); | |
8a9d2e80 | 5919 | goto out_destroy_cq_event_pool; |
da0436e9 | 5920 | } |
da0436e9 JS |
5921 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
5922 | if (rc) { | |
5923 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5924 | "1432 Failed to initialize rpi headers.\n"); | |
5925 | goto out_free_active_sgl; | |
5926 | } | |
5927 | ||
a93ff37a | 5928 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
0c9ab6f5 JS |
5929 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
5930 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), | |
5931 | GFP_KERNEL); | |
5932 | if (!phba->fcf.fcf_rr_bmask) { | |
5933 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5934 | "2759 Failed allocate memory for FCF round " | |
5935 | "robin failover bmask\n"); | |
0558056c | 5936 | rc = -ENOMEM; |
0c9ab6f5 JS |
5937 | goto out_remove_rpi_hdrs; |
5938 | } | |
5939 | ||
895427bd JS |
5940 | phba->sli4_hba.hba_eq_hdl = kcalloc(fof_vectors + phba->io_channel_irqs, |
5941 | sizeof(struct lpfc_hba_eq_hdl), | |
5942 | GFP_KERNEL); | |
5943 | if (!phba->sli4_hba.hba_eq_hdl) { | |
67d12733 JS |
5944 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
5945 | "2572 Failed allocate memory for " | |
5946 | "fast-path per-EQ handle array\n"); | |
5947 | rc = -ENOMEM; | |
5948 | goto out_free_fcf_rr_bmask; | |
da0436e9 JS |
5949 | } |
5950 | ||
895427bd JS |
5951 | phba->sli4_hba.cpu_map = kcalloc(phba->sli4_hba.num_present_cpu, |
5952 | sizeof(struct lpfc_vector_map_info), | |
5953 | GFP_KERNEL); | |
7bb03bbf JS |
5954 | if (!phba->sli4_hba.cpu_map) { |
5955 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5956 | "3327 Failed allocate memory for msi-x " | |
5957 | "interrupt vector mapping\n"); | |
5958 | rc = -ENOMEM; | |
895427bd | 5959 | goto out_free_hba_eq_hdl; |
7bb03bbf | 5960 | } |
b246de17 | 5961 | if (lpfc_used_cpu == NULL) { |
895427bd JS |
5962 | lpfc_used_cpu = kcalloc(lpfc_present_cpu, sizeof(uint16_t), |
5963 | GFP_KERNEL); | |
b246de17 JS |
5964 | if (!lpfc_used_cpu) { |
5965 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5966 | "3335 Failed allocate memory for msi-x " | |
5967 | "interrupt vector mapping\n"); | |
5968 | kfree(phba->sli4_hba.cpu_map); | |
5969 | rc = -ENOMEM; | |
895427bd | 5970 | goto out_free_hba_eq_hdl; |
b246de17 JS |
5971 | } |
5972 | for (i = 0; i < lpfc_present_cpu; i++) | |
5973 | lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY; | |
5974 | } | |
5975 | ||
912e3acd JS |
5976 | /* |
5977 | * Enable sr-iov virtual functions if supported and configured | |
5978 | * through the module parameter. | |
5979 | */ | |
5980 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
5981 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, | |
5982 | phba->cfg_sriov_nr_virtfn); | |
5983 | if (rc) { | |
5984 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
5985 | "3020 Requested number of SR-IOV " | |
5986 | "virtual functions (%d) is not " | |
5987 | "supported\n", | |
5988 | phba->cfg_sriov_nr_virtfn); | |
5989 | phba->cfg_sriov_nr_virtfn = 0; | |
5990 | } | |
5991 | } | |
5992 | ||
5248a749 | 5993 | return 0; |
da0436e9 | 5994 | |
895427bd JS |
5995 | out_free_hba_eq_hdl: |
5996 | kfree(phba->sli4_hba.hba_eq_hdl); | |
0c9ab6f5 JS |
5997 | out_free_fcf_rr_bmask: |
5998 | kfree(phba->fcf.fcf_rr_bmask); | |
da0436e9 JS |
5999 | out_remove_rpi_hdrs: |
6000 | lpfc_sli4_remove_rpi_hdrs(phba); | |
6001 | out_free_active_sgl: | |
6002 | lpfc_free_active_sgl(phba); | |
da0436e9 JS |
6003 | out_destroy_cq_event_pool: |
6004 | lpfc_sli4_cq_event_pool_destroy(phba); | |
da0436e9 JS |
6005 | out_free_bsmbx: |
6006 | lpfc_destroy_bootstrap_mbox(phba); | |
6007 | out_free_mem: | |
6008 | lpfc_mem_free(phba); | |
6009 | return rc; | |
6010 | } | |
6011 | ||
6012 | /** | |
6013 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev | |
6014 | * @phba: pointer to lpfc hba data structure. | |
6015 | * | |
6016 | * This routine is invoked to unset the driver internal resources set up | |
6017 | * specific for supporting the SLI-4 HBA device it attached to. | |
6018 | **/ | |
6019 | static void | |
6020 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) | |
6021 | { | |
6022 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; | |
6023 | ||
7bb03bbf JS |
6024 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
6025 | kfree(phba->sli4_hba.cpu_map); | |
6026 | phba->sli4_hba.num_present_cpu = 0; | |
6027 | phba->sli4_hba.num_online_cpu = 0; | |
76fd07a6 | 6028 | phba->sli4_hba.curr_disp_cpu = 0; |
7bb03bbf | 6029 | |
da0436e9 | 6030 | /* Free memory allocated for fast-path work queue handles */ |
895427bd | 6031 | kfree(phba->sli4_hba.hba_eq_hdl); |
da0436e9 JS |
6032 | |
6033 | /* Free the allocated rpi headers. */ | |
6034 | lpfc_sli4_remove_rpi_hdrs(phba); | |
d11e31dd | 6035 | lpfc_sli4_remove_rpis(phba); |
da0436e9 | 6036 | |
0c9ab6f5 JS |
6037 | /* Free eligible FCF index bmask */ |
6038 | kfree(phba->fcf.fcf_rr_bmask); | |
6039 | ||
da0436e9 JS |
6040 | /* Free the ELS sgl list */ |
6041 | lpfc_free_active_sgl(phba); | |
8a9d2e80 | 6042 | lpfc_free_els_sgl_list(phba); |
f358dd0c | 6043 | lpfc_free_nvmet_sgl_list(phba); |
da0436e9 | 6044 | |
da0436e9 JS |
6045 | /* Free the completion queue EQ event pool */ |
6046 | lpfc_sli4_cq_event_release_all(phba); | |
6047 | lpfc_sli4_cq_event_pool_destroy(phba); | |
6048 | ||
6d368e53 JS |
6049 | /* Release resource identifiers. */ |
6050 | lpfc_sli4_dealloc_resource_identifiers(phba); | |
6051 | ||
da0436e9 JS |
6052 | /* Free the bsmbx region. */ |
6053 | lpfc_destroy_bootstrap_mbox(phba); | |
6054 | ||
6055 | /* Free the SLI Layer memory with SLI4 HBAs */ | |
6056 | lpfc_mem_free_all(phba); | |
6057 | ||
6058 | /* Free the current connect table */ | |
6059 | list_for_each_entry_safe(conn_entry, next_conn_entry, | |
4d9ab994 JS |
6060 | &phba->fcf_conn_rec_list, list) { |
6061 | list_del_init(&conn_entry->list); | |
da0436e9 | 6062 | kfree(conn_entry); |
4d9ab994 | 6063 | } |
da0436e9 JS |
6064 | |
6065 | return; | |
6066 | } | |
6067 | ||
6068 | /** | |
25985edc | 6069 | * lpfc_init_api_table_setup - Set up init api function jump table |
da0436e9 JS |
6070 | * @phba: The hba struct for which this call is being executed. |
6071 | * @dev_grp: The HBA PCI-Device group number. | |
6072 | * | |
6073 | * This routine sets up the device INIT interface API function jump table | |
6074 | * in @phba struct. | |
6075 | * | |
6076 | * Returns: 0 - success, -ENODEV - failure. | |
6077 | **/ | |
6078 | int | |
6079 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
6080 | { | |
84d1b006 JS |
6081 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
6082 | phba->lpfc_hba_down_link = lpfc_hba_down_link; | |
7f86059a | 6083 | phba->lpfc_selective_reset = lpfc_selective_reset; |
da0436e9 JS |
6084 | switch (dev_grp) { |
6085 | case LPFC_PCI_DEV_LP: | |
6086 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; | |
6087 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; | |
6088 | phba->lpfc_stop_port = lpfc_stop_port_s3; | |
6089 | break; | |
6090 | case LPFC_PCI_DEV_OC: | |
6091 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; | |
6092 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; | |
6093 | phba->lpfc_stop_port = lpfc_stop_port_s4; | |
6094 | break; | |
6095 | default: | |
6096 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6097 | "1431 Invalid HBA PCI-device group: 0x%x\n", | |
6098 | dev_grp); | |
6099 | return -ENODEV; | |
6100 | break; | |
6101 | } | |
6102 | return 0; | |
6103 | } | |
6104 | ||
da0436e9 JS |
6105 | /** |
6106 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. | |
6107 | * @phba: pointer to lpfc hba data structure. | |
6108 | * | |
6109 | * This routine is invoked to set up the driver internal resources after the | |
6110 | * device specific resource setup to support the HBA device it attached to. | |
6111 | * | |
6112 | * Return codes | |
af901ca1 | 6113 | * 0 - successful |
da0436e9 JS |
6114 | * other values - error |
6115 | **/ | |
6116 | static int | |
6117 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) | |
6118 | { | |
6119 | int error; | |
6120 | ||
6121 | /* Startup the kernel thread for this host adapter. */ | |
6122 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
6123 | "lpfc_worker_%d", phba->brd_no); | |
6124 | if (IS_ERR(phba->worker_thread)) { | |
6125 | error = PTR_ERR(phba->worker_thread); | |
6126 | return error; | |
3772a991 JS |
6127 | } |
6128 | ||
6129 | return 0; | |
6130 | } | |
6131 | ||
6132 | /** | |
6133 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. | |
6134 | * @phba: pointer to lpfc hba data structure. | |
6135 | * | |
6136 | * This routine is invoked to unset the driver internal resources set up after | |
6137 | * the device specific resource setup for supporting the HBA device it | |
6138 | * attached to. | |
6139 | **/ | |
6140 | static void | |
6141 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) | |
6142 | { | |
6143 | /* Stop kernel worker thread */ | |
6144 | kthread_stop(phba->worker_thread); | |
6145 | } | |
6146 | ||
6147 | /** | |
6148 | * lpfc_free_iocb_list - Free iocb list. | |
6149 | * @phba: pointer to lpfc hba data structure. | |
6150 | * | |
6151 | * This routine is invoked to free the driver's IOCB list and memory. | |
6152 | **/ | |
6153 | static void | |
6154 | lpfc_free_iocb_list(struct lpfc_hba *phba) | |
6155 | { | |
6156 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; | |
6157 | ||
6158 | spin_lock_irq(&phba->hbalock); | |
6159 | list_for_each_entry_safe(iocbq_entry, iocbq_next, | |
6160 | &phba->lpfc_iocb_list, list) { | |
6161 | list_del(&iocbq_entry->list); | |
6162 | kfree(iocbq_entry); | |
6163 | phba->total_iocbq_bufs--; | |
98c9ea5c | 6164 | } |
3772a991 JS |
6165 | spin_unlock_irq(&phba->hbalock); |
6166 | ||
6167 | return; | |
6168 | } | |
6169 | ||
6170 | /** | |
6171 | * lpfc_init_iocb_list - Allocate and initialize iocb list. | |
6172 | * @phba: pointer to lpfc hba data structure. | |
6173 | * | |
6174 | * This routine is invoked to allocate and initizlize the driver's IOCB | |
6175 | * list and set up the IOCB tag array accordingly. | |
6176 | * | |
6177 | * Return codes | |
af901ca1 | 6178 | * 0 - successful |
3772a991 JS |
6179 | * other values - error |
6180 | **/ | |
6181 | static int | |
6182 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) | |
6183 | { | |
6184 | struct lpfc_iocbq *iocbq_entry = NULL; | |
6185 | uint16_t iotag; | |
6186 | int i; | |
dea3101e JB |
6187 | |
6188 | /* Initialize and populate the iocb list per host. */ | |
6189 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); | |
3772a991 | 6190 | for (i = 0; i < iocb_count; i++) { |
dd00cc48 | 6191 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
dea3101e JB |
6192 | if (iocbq_entry == NULL) { |
6193 | printk(KERN_ERR "%s: only allocated %d iocbs of " | |
6194 | "expected %d count. Unloading driver.\n", | |
cadbd4a5 | 6195 | __func__, i, LPFC_IOCB_LIST_CNT); |
dea3101e JB |
6196 | goto out_free_iocbq; |
6197 | } | |
6198 | ||
604a3e30 JB |
6199 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
6200 | if (iotag == 0) { | |
3772a991 | 6201 | kfree(iocbq_entry); |
604a3e30 | 6202 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
3772a991 | 6203 | "Unloading driver.\n", __func__); |
604a3e30 JB |
6204 | goto out_free_iocbq; |
6205 | } | |
6d368e53 | 6206 | iocbq_entry->sli4_lxritag = NO_XRI; |
3772a991 | 6207 | iocbq_entry->sli4_xritag = NO_XRI; |
2e0fef85 JS |
6208 | |
6209 | spin_lock_irq(&phba->hbalock); | |
dea3101e JB |
6210 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
6211 | phba->total_iocbq_bufs++; | |
2e0fef85 | 6212 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
6213 | } |
6214 | ||
3772a991 | 6215 | return 0; |
dea3101e | 6216 | |
3772a991 JS |
6217 | out_free_iocbq: |
6218 | lpfc_free_iocb_list(phba); | |
dea3101e | 6219 | |
3772a991 JS |
6220 | return -ENOMEM; |
6221 | } | |
5e9d9b82 | 6222 | |
3772a991 | 6223 | /** |
8a9d2e80 | 6224 | * lpfc_free_sgl_list - Free a given sgl list. |
da0436e9 | 6225 | * @phba: pointer to lpfc hba data structure. |
8a9d2e80 | 6226 | * @sglq_list: pointer to the head of sgl list. |
3772a991 | 6227 | * |
8a9d2e80 | 6228 | * This routine is invoked to free a give sgl list and memory. |
3772a991 | 6229 | **/ |
8a9d2e80 JS |
6230 | void |
6231 | lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list) | |
3772a991 | 6232 | { |
da0436e9 | 6233 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
8a9d2e80 JS |
6234 | |
6235 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { | |
6236 | list_del(&sglq_entry->list); | |
6237 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); | |
6238 | kfree(sglq_entry); | |
6239 | } | |
6240 | } | |
6241 | ||
6242 | /** | |
6243 | * lpfc_free_els_sgl_list - Free els sgl list. | |
6244 | * @phba: pointer to lpfc hba data structure. | |
6245 | * | |
6246 | * This routine is invoked to free the driver's els sgl list and memory. | |
6247 | **/ | |
6248 | static void | |
6249 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) | |
6250 | { | |
da0436e9 | 6251 | LIST_HEAD(sglq_list); |
dea3101e | 6252 | |
8a9d2e80 | 6253 | /* Retrieve all els sgls from driver list */ |
da0436e9 | 6254 | spin_lock_irq(&phba->hbalock); |
895427bd JS |
6255 | spin_lock(&phba->sli4_hba.sgl_list_lock); |
6256 | list_splice_init(&phba->sli4_hba.lpfc_els_sgl_list, &sglq_list); | |
6257 | spin_unlock(&phba->sli4_hba.sgl_list_lock); | |
da0436e9 | 6258 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 6259 | |
8a9d2e80 JS |
6260 | /* Now free the sgl list */ |
6261 | lpfc_free_sgl_list(phba, &sglq_list); | |
da0436e9 | 6262 | } |
92d7f7b0 | 6263 | |
f358dd0c JS |
6264 | /** |
6265 | * lpfc_free_nvmet_sgl_list - Free nvmet sgl list. | |
6266 | * @phba: pointer to lpfc hba data structure. | |
6267 | * | |
6268 | * This routine is invoked to free the driver's nvmet sgl list and memory. | |
6269 | **/ | |
6270 | static void | |
6271 | lpfc_free_nvmet_sgl_list(struct lpfc_hba *phba) | |
6272 | { | |
6273 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; | |
6274 | LIST_HEAD(sglq_list); | |
6275 | ||
6276 | /* Retrieve all nvmet sgls from driver list */ | |
6277 | spin_lock_irq(&phba->hbalock); | |
6278 | spin_lock(&phba->sli4_hba.sgl_list_lock); | |
6279 | list_splice_init(&phba->sli4_hba.lpfc_nvmet_sgl_list, &sglq_list); | |
6280 | spin_unlock(&phba->sli4_hba.sgl_list_lock); | |
6281 | spin_unlock_irq(&phba->hbalock); | |
6282 | ||
6283 | /* Now free the sgl list */ | |
6284 | list_for_each_entry_safe(sglq_entry, sglq_next, &sglq_list, list) { | |
6285 | list_del(&sglq_entry->list); | |
6286 | lpfc_nvmet_buf_free(phba, sglq_entry->virt, sglq_entry->phys); | |
6287 | kfree(sglq_entry); | |
6288 | } | |
6289 | } | |
6290 | ||
da0436e9 JS |
6291 | /** |
6292 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. | |
6293 | * @phba: pointer to lpfc hba data structure. | |
6294 | * | |
6295 | * This routine is invoked to allocate the driver's active sgl memory. | |
6296 | * This array will hold the sglq_entry's for active IOs. | |
6297 | **/ | |
6298 | static int | |
6299 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) | |
6300 | { | |
6301 | int size; | |
6302 | size = sizeof(struct lpfc_sglq *); | |
6303 | size *= phba->sli4_hba.max_cfg_param.max_xri; | |
6304 | ||
6305 | phba->sli4_hba.lpfc_sglq_active_list = | |
6306 | kzalloc(size, GFP_KERNEL); | |
6307 | if (!phba->sli4_hba.lpfc_sglq_active_list) | |
6308 | return -ENOMEM; | |
6309 | return 0; | |
3772a991 JS |
6310 | } |
6311 | ||
6312 | /** | |
da0436e9 | 6313 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
3772a991 JS |
6314 | * @phba: pointer to lpfc hba data structure. |
6315 | * | |
da0436e9 JS |
6316 | * This routine is invoked to walk through the array of active sglq entries |
6317 | * and free all of the resources. | |
6318 | * This is just a place holder for now. | |
3772a991 JS |
6319 | **/ |
6320 | static void | |
da0436e9 | 6321 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
3772a991 | 6322 | { |
da0436e9 | 6323 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
3772a991 JS |
6324 | } |
6325 | ||
6326 | /** | |
da0436e9 | 6327 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
3772a991 JS |
6328 | * @phba: pointer to lpfc hba data structure. |
6329 | * | |
da0436e9 JS |
6330 | * This routine is invoked to allocate and initizlize the driver's sgl |
6331 | * list and set up the sgl xritag tag array accordingly. | |
3772a991 | 6332 | * |
3772a991 | 6333 | **/ |
8a9d2e80 | 6334 | static void |
da0436e9 | 6335 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
3772a991 | 6336 | { |
da0436e9 | 6337 | /* Initialize and populate the sglq list per host/VF. */ |
895427bd | 6338 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_els_sgl_list); |
da0436e9 | 6339 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
f358dd0c JS |
6340 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_nvmet_sgl_list); |
6341 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list); | |
da0436e9 | 6342 | |
8a9d2e80 JS |
6343 | /* els xri-sgl book keeping */ |
6344 | phba->sli4_hba.els_xri_cnt = 0; | |
0ff10d46 | 6345 | |
8a9d2e80 | 6346 | /* scsi xri-buffer book keeping */ |
da0436e9 | 6347 | phba->sli4_hba.scsi_xri_cnt = 0; |
895427bd JS |
6348 | |
6349 | /* nvme xri-buffer book keeping */ | |
6350 | phba->sli4_hba.nvme_xri_cnt = 0; | |
da0436e9 JS |
6351 | } |
6352 | ||
6353 | /** | |
6354 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port | |
6355 | * @phba: pointer to lpfc hba data structure. | |
6356 | * | |
6357 | * This routine is invoked to post rpi header templates to the | |
88a2cfbb | 6358 | * port for those SLI4 ports that do not support extents. This routine |
da0436e9 | 6359 | * posts a PAGE_SIZE memory region to the port to hold up to |
88a2cfbb JS |
6360 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
6361 | * and should be called only when interrupts are disabled. | |
da0436e9 JS |
6362 | * |
6363 | * Return codes | |
af901ca1 | 6364 | * 0 - successful |
88a2cfbb | 6365 | * -ERROR - otherwise. |
da0436e9 JS |
6366 | **/ |
6367 | int | |
6368 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) | |
6369 | { | |
6370 | int rc = 0; | |
da0436e9 JS |
6371 | struct lpfc_rpi_hdr *rpi_hdr; |
6372 | ||
6373 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); | |
ff78d8f9 | 6374 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
6d368e53 | 6375 | return rc; |
6d368e53 JS |
6376 | if (phba->sli4_hba.extents_in_use) |
6377 | return -EIO; | |
da0436e9 JS |
6378 | |
6379 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
6380 | if (!rpi_hdr) { | |
6381 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
6382 | "0391 Error during rpi post operation\n"); | |
6383 | lpfc_sli4_remove_rpis(phba); | |
6384 | rc = -ENODEV; | |
6385 | } | |
6386 | ||
6387 | return rc; | |
6388 | } | |
6389 | ||
6390 | /** | |
6391 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region | |
6392 | * @phba: pointer to lpfc hba data structure. | |
6393 | * | |
6394 | * This routine is invoked to allocate a single 4KB memory region to | |
6395 | * support rpis and stores them in the phba. This single region | |
6396 | * provides support for up to 64 rpis. The region is used globally | |
6397 | * by the device. | |
6398 | * | |
6399 | * Returns: | |
6400 | * A valid rpi hdr on success. | |
6401 | * A NULL pointer on any failure. | |
6402 | **/ | |
6403 | struct lpfc_rpi_hdr * | |
6404 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) | |
6405 | { | |
6406 | uint16_t rpi_limit, curr_rpi_range; | |
6407 | struct lpfc_dmabuf *dmabuf; | |
6408 | struct lpfc_rpi_hdr *rpi_hdr; | |
9589b062 | 6409 | uint32_t rpi_count; |
da0436e9 | 6410 | |
6d368e53 JS |
6411 | /* |
6412 | * If the SLI4 port supports extents, posting the rpi header isn't | |
6413 | * required. Set the expected maximum count and let the actual value | |
6414 | * get set when extents are fully allocated. | |
6415 | */ | |
6416 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
6417 | return NULL; | |
6418 | if (phba->sli4_hba.extents_in_use) | |
6419 | return NULL; | |
6420 | ||
6421 | /* The limit on the logical index is just the max_rpi count. */ | |
da0436e9 | 6422 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + |
6d368e53 | 6423 | phba->sli4_hba.max_cfg_param.max_rpi - 1; |
da0436e9 JS |
6424 | |
6425 | spin_lock_irq(&phba->hbalock); | |
6d368e53 JS |
6426 | /* |
6427 | * Establish the starting RPI in this header block. The starting | |
6428 | * rpi is normalized to a zero base because the physical rpi is | |
6429 | * port based. | |
6430 | */ | |
97f2ecf1 | 6431 | curr_rpi_range = phba->sli4_hba.next_rpi; |
da0436e9 JS |
6432 | spin_unlock_irq(&phba->hbalock); |
6433 | ||
6434 | /* | |
6435 | * The port has a limited number of rpis. The increment here | |
6436 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value | |
6437 | * and to allow the full max_rpi range per port. | |
6438 | */ | |
6439 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) | |
9589b062 JS |
6440 | rpi_count = rpi_limit - curr_rpi_range; |
6441 | else | |
6442 | rpi_count = LPFC_RPI_HDR_COUNT; | |
da0436e9 | 6443 | |
6d368e53 JS |
6444 | if (!rpi_count) |
6445 | return NULL; | |
da0436e9 JS |
6446 | /* |
6447 | * First allocate the protocol header region for the port. The | |
6448 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. | |
6449 | */ | |
6450 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
6451 | if (!dmabuf) | |
6452 | return NULL; | |
6453 | ||
1aee383d JP |
6454 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, |
6455 | LPFC_HDR_TEMPLATE_SIZE, | |
6456 | &dmabuf->phys, GFP_KERNEL); | |
da0436e9 JS |
6457 | if (!dmabuf->virt) { |
6458 | rpi_hdr = NULL; | |
6459 | goto err_free_dmabuf; | |
6460 | } | |
6461 | ||
da0436e9 JS |
6462 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { |
6463 | rpi_hdr = NULL; | |
6464 | goto err_free_coherent; | |
6465 | } | |
6466 | ||
6467 | /* Save the rpi header data for cleanup later. */ | |
6468 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); | |
6469 | if (!rpi_hdr) | |
6470 | goto err_free_coherent; | |
6471 | ||
6472 | rpi_hdr->dmabuf = dmabuf; | |
6473 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; | |
6474 | rpi_hdr->page_count = 1; | |
6475 | spin_lock_irq(&phba->hbalock); | |
6d368e53 JS |
6476 | |
6477 | /* The rpi_hdr stores the logical index only. */ | |
6478 | rpi_hdr->start_rpi = curr_rpi_range; | |
da0436e9 JS |
6479 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
6480 | ||
6481 | /* | |
6d368e53 JS |
6482 | * The next_rpi stores the next logical module-64 rpi value used |
6483 | * to post physical rpis in subsequent rpi postings. | |
da0436e9 | 6484 | */ |
9589b062 | 6485 | phba->sli4_hba.next_rpi += rpi_count; |
da0436e9 JS |
6486 | spin_unlock_irq(&phba->hbalock); |
6487 | return rpi_hdr; | |
6488 | ||
6489 | err_free_coherent: | |
6490 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, | |
6491 | dmabuf->virt, dmabuf->phys); | |
6492 | err_free_dmabuf: | |
6493 | kfree(dmabuf); | |
6494 | return NULL; | |
6495 | } | |
6496 | ||
6497 | /** | |
6498 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions | |
6499 | * @phba: pointer to lpfc hba data structure. | |
6500 | * | |
6501 | * This routine is invoked to remove all memory resources allocated | |
6d368e53 JS |
6502 | * to support rpis for SLI4 ports not supporting extents. This routine |
6503 | * presumes the caller has released all rpis consumed by fabric or port | |
6504 | * logins and is prepared to have the header pages removed. | |
da0436e9 JS |
6505 | **/ |
6506 | void | |
6507 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) | |
6508 | { | |
6509 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; | |
6510 | ||
6d368e53 JS |
6511 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
6512 | goto exit; | |
6513 | ||
da0436e9 JS |
6514 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
6515 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { | |
6516 | list_del(&rpi_hdr->list); | |
6517 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, | |
6518 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); | |
6519 | kfree(rpi_hdr->dmabuf); | |
6520 | kfree(rpi_hdr); | |
6521 | } | |
6d368e53 JS |
6522 | exit: |
6523 | /* There are no rpis available to the port now. */ | |
6524 | phba->sli4_hba.next_rpi = 0; | |
da0436e9 JS |
6525 | } |
6526 | ||
6527 | /** | |
6528 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. | |
6529 | * @pdev: pointer to pci device data structure. | |
6530 | * | |
6531 | * This routine is invoked to allocate the driver hba data structure for an | |
6532 | * HBA device. If the allocation is successful, the phba reference to the | |
6533 | * PCI device data structure is set. | |
6534 | * | |
6535 | * Return codes | |
af901ca1 | 6536 | * pointer to @phba - successful |
da0436e9 JS |
6537 | * NULL - error |
6538 | **/ | |
6539 | static struct lpfc_hba * | |
6540 | lpfc_hba_alloc(struct pci_dev *pdev) | |
6541 | { | |
6542 | struct lpfc_hba *phba; | |
6543 | ||
6544 | /* Allocate memory for HBA structure */ | |
6545 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); | |
6546 | if (!phba) { | |
e34ccdfe | 6547 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
da0436e9 JS |
6548 | return NULL; |
6549 | } | |
6550 | ||
6551 | /* Set reference to PCI device in HBA structure */ | |
6552 | phba->pcidev = pdev; | |
6553 | ||
6554 | /* Assign an unused board number */ | |
6555 | phba->brd_no = lpfc_get_instance(); | |
6556 | if (phba->brd_no < 0) { | |
6557 | kfree(phba); | |
6558 | return NULL; | |
6559 | } | |
65791f1f | 6560 | phba->eratt_poll_interval = LPFC_ERATT_POLL_INTERVAL; |
da0436e9 | 6561 | |
4fede78f | 6562 | spin_lock_init(&phba->ct_ev_lock); |
f1c3b0fc JS |
6563 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
6564 | ||
da0436e9 JS |
6565 | return phba; |
6566 | } | |
6567 | ||
6568 | /** | |
6569 | * lpfc_hba_free - Free driver hba data structure with a device. | |
6570 | * @phba: pointer to lpfc hba data structure. | |
6571 | * | |
6572 | * This routine is invoked to free the driver hba data structure with an | |
6573 | * HBA device. | |
6574 | **/ | |
6575 | static void | |
6576 | lpfc_hba_free(struct lpfc_hba *phba) | |
6577 | { | |
6578 | /* Release the driver assigned board number */ | |
6579 | idr_remove(&lpfc_hba_index, phba->brd_no); | |
6580 | ||
895427bd JS |
6581 | /* Free memory allocated with sli3 rings */ |
6582 | kfree(phba->sli.sli3_ring); | |
6583 | phba->sli.sli3_ring = NULL; | |
2a76a283 | 6584 | |
da0436e9 JS |
6585 | kfree(phba); |
6586 | return; | |
6587 | } | |
6588 | ||
6589 | /** | |
6590 | * lpfc_create_shost - Create hba physical port with associated scsi host. | |
6591 | * @phba: pointer to lpfc hba data structure. | |
6592 | * | |
6593 | * This routine is invoked to create HBA physical port and associate a SCSI | |
6594 | * host with it. | |
6595 | * | |
6596 | * Return codes | |
af901ca1 | 6597 | * 0 - successful |
da0436e9 JS |
6598 | * other values - error |
6599 | **/ | |
6600 | static int | |
6601 | lpfc_create_shost(struct lpfc_hba *phba) | |
6602 | { | |
6603 | struct lpfc_vport *vport; | |
6604 | struct Scsi_Host *shost; | |
6605 | ||
6606 | /* Initialize HBA FC structure */ | |
6607 | phba->fc_edtov = FF_DEF_EDTOV; | |
6608 | phba->fc_ratov = FF_DEF_RATOV; | |
6609 | phba->fc_altov = FF_DEF_ALTOV; | |
6610 | phba->fc_arbtov = FF_DEF_ARBTOV; | |
6611 | ||
d7c47992 | 6612 | atomic_set(&phba->sdev_cnt, 0); |
da0436e9 JS |
6613 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
6614 | if (!vport) | |
6615 | return -ENODEV; | |
6616 | ||
6617 | shost = lpfc_shost_from_vport(vport); | |
6618 | phba->pport = vport; | |
2ea259ee | 6619 | |
f358dd0c JS |
6620 | if (phba->nvmet_support) { |
6621 | /* Only 1 vport (pport) will support NVME target */ | |
6622 | if (phba->txrdy_payload_pool == NULL) { | |
6623 | phba->txrdy_payload_pool = pci_pool_create( | |
6624 | "txrdy_pool", phba->pcidev, | |
6625 | TXRDY_PAYLOAD_LEN, 16, 0); | |
6626 | if (phba->txrdy_payload_pool) { | |
6627 | phba->targetport = NULL; | |
6628 | phba->cfg_enable_fc4_type = LPFC_ENABLE_NVME; | |
6629 | lpfc_printf_log(phba, KERN_INFO, | |
6630 | LOG_INIT | LOG_NVME_DISC, | |
6631 | "6076 NVME Target Found\n"); | |
6632 | } | |
6633 | } | |
6634 | } | |
6635 | ||
da0436e9 JS |
6636 | lpfc_debugfs_initialize(vport); |
6637 | /* Put reference to SCSI host to driver's device private data */ | |
6638 | pci_set_drvdata(phba->pcidev, shost); | |
2e0fef85 | 6639 | |
4258e98e JS |
6640 | /* |
6641 | * At this point we are fully registered with PSA. In addition, | |
6642 | * any initial discovery should be completed. | |
6643 | */ | |
6644 | vport->load_flag |= FC_ALLOW_FDMI; | |
8663cbbe JS |
6645 | if (phba->cfg_enable_SmartSAN || |
6646 | (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) { | |
4258e98e JS |
6647 | |
6648 | /* Setup appropriate attribute masks */ | |
6649 | vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR; | |
8663cbbe | 6650 | if (phba->cfg_enable_SmartSAN) |
4258e98e JS |
6651 | vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR; |
6652 | else | |
6653 | vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR; | |
6654 | } | |
3772a991 JS |
6655 | return 0; |
6656 | } | |
db2378e0 | 6657 | |
3772a991 JS |
6658 | /** |
6659 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. | |
6660 | * @phba: pointer to lpfc hba data structure. | |
6661 | * | |
6662 | * This routine is invoked to destroy HBA physical port and the associated | |
6663 | * SCSI host. | |
6664 | **/ | |
6665 | static void | |
6666 | lpfc_destroy_shost(struct lpfc_hba *phba) | |
6667 | { | |
6668 | struct lpfc_vport *vport = phba->pport; | |
6669 | ||
6670 | /* Destroy physical port that associated with the SCSI host */ | |
6671 | destroy_port(vport); | |
6672 | ||
6673 | return; | |
6674 | } | |
6675 | ||
6676 | /** | |
6677 | * lpfc_setup_bg - Setup Block guard structures and debug areas. | |
6678 | * @phba: pointer to lpfc hba data structure. | |
6679 | * @shost: the shost to be used to detect Block guard settings. | |
6680 | * | |
6681 | * This routine sets up the local Block guard protocol settings for @shost. | |
6682 | * This routine also allocates memory for debugging bg buffers. | |
6683 | **/ | |
6684 | static void | |
6685 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) | |
6686 | { | |
bbeb79b9 JS |
6687 | uint32_t old_mask; |
6688 | uint32_t old_guard; | |
6689 | ||
3772a991 | 6690 | int pagecnt = 10; |
b3b98b74 | 6691 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
3772a991 JS |
6692 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
6693 | "1478 Registering BlockGuard with the " | |
6694 | "SCSI layer\n"); | |
bbeb79b9 | 6695 | |
b3b98b74 JS |
6696 | old_mask = phba->cfg_prot_mask; |
6697 | old_guard = phba->cfg_prot_guard; | |
bbeb79b9 JS |
6698 | |
6699 | /* Only allow supported values */ | |
b3b98b74 | 6700 | phba->cfg_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | |
bbeb79b9 JS |
6701 | SHOST_DIX_TYPE0_PROTECTION | |
6702 | SHOST_DIX_TYPE1_PROTECTION); | |
b3b98b74 JS |
6703 | phba->cfg_prot_guard &= (SHOST_DIX_GUARD_IP | |
6704 | SHOST_DIX_GUARD_CRC); | |
bbeb79b9 JS |
6705 | |
6706 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ | |
b3b98b74 JS |
6707 | if (phba->cfg_prot_mask == SHOST_DIX_TYPE1_PROTECTION) |
6708 | phba->cfg_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; | |
bbeb79b9 | 6709 | |
b3b98b74 JS |
6710 | if (phba->cfg_prot_mask && phba->cfg_prot_guard) { |
6711 | if ((old_mask != phba->cfg_prot_mask) || | |
6712 | (old_guard != phba->cfg_prot_guard)) | |
bbeb79b9 JS |
6713 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
6714 | "1475 Registering BlockGuard with the " | |
6715 | "SCSI layer: mask %d guard %d\n", | |
b3b98b74 JS |
6716 | phba->cfg_prot_mask, |
6717 | phba->cfg_prot_guard); | |
bbeb79b9 | 6718 | |
b3b98b74 JS |
6719 | scsi_host_set_prot(shost, phba->cfg_prot_mask); |
6720 | scsi_host_set_guard(shost, phba->cfg_prot_guard); | |
bbeb79b9 JS |
6721 | } else |
6722 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6723 | "1479 Not Registering BlockGuard with the SCSI " | |
6724 | "layer, Bad protection parameters: %d %d\n", | |
6725 | old_mask, old_guard); | |
3772a991 | 6726 | } |
bbeb79b9 | 6727 | |
3772a991 JS |
6728 | if (!_dump_buf_data) { |
6729 | while (pagecnt) { | |
6730 | spin_lock_init(&_dump_buf_lock); | |
6731 | _dump_buf_data = | |
6732 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
6733 | if (_dump_buf_data) { | |
6a9c52cf JS |
6734 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
6735 | "9043 BLKGRD: allocated %d pages for " | |
3772a991 JS |
6736 | "_dump_buf_data at 0x%p\n", |
6737 | (1 << pagecnt), _dump_buf_data); | |
6738 | _dump_buf_data_order = pagecnt; | |
6739 | memset(_dump_buf_data, 0, | |
6740 | ((1 << PAGE_SHIFT) << pagecnt)); | |
6741 | break; | |
6742 | } else | |
6743 | --pagecnt; | |
6744 | } | |
6745 | if (!_dump_buf_data_order) | |
6a9c52cf JS |
6746 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
6747 | "9044 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
6748 | "memory for hexdump\n"); |
6749 | } else | |
6a9c52cf JS |
6750 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
6751 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" | |
3772a991 JS |
6752 | "\n", _dump_buf_data); |
6753 | if (!_dump_buf_dif) { | |
6754 | while (pagecnt) { | |
6755 | _dump_buf_dif = | |
6756 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
6757 | if (_dump_buf_dif) { | |
6a9c52cf JS |
6758 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
6759 | "9046 BLKGRD: allocated %d pages for " | |
3772a991 JS |
6760 | "_dump_buf_dif at 0x%p\n", |
6761 | (1 << pagecnt), _dump_buf_dif); | |
6762 | _dump_buf_dif_order = pagecnt; | |
6763 | memset(_dump_buf_dif, 0, | |
6764 | ((1 << PAGE_SHIFT) << pagecnt)); | |
6765 | break; | |
6766 | } else | |
6767 | --pagecnt; | |
6768 | } | |
6769 | if (!_dump_buf_dif_order) | |
6a9c52cf JS |
6770 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
6771 | "9047 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
6772 | "memory for hexdump\n"); |
6773 | } else | |
6a9c52cf JS |
6774 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
6775 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", | |
3772a991 JS |
6776 | _dump_buf_dif); |
6777 | } | |
6778 | ||
6779 | /** | |
6780 | * lpfc_post_init_setup - Perform necessary device post initialization setup. | |
6781 | * @phba: pointer to lpfc hba data structure. | |
6782 | * | |
6783 | * This routine is invoked to perform all the necessary post initialization | |
6784 | * setup for the device. | |
6785 | **/ | |
6786 | static void | |
6787 | lpfc_post_init_setup(struct lpfc_hba *phba) | |
6788 | { | |
6789 | struct Scsi_Host *shost; | |
6790 | struct lpfc_adapter_event_header adapter_event; | |
6791 | ||
6792 | /* Get the default values for Model Name and Description */ | |
6793 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
6794 | ||
6795 | /* | |
6796 | * hba setup may have changed the hba_queue_depth so we need to | |
6797 | * adjust the value of can_queue. | |
6798 | */ | |
6799 | shost = pci_get_drvdata(phba->pcidev); | |
6800 | shost->can_queue = phba->cfg_hba_queue_depth - 10; | |
6801 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) | |
6802 | lpfc_setup_bg(phba, shost); | |
6803 | ||
6804 | lpfc_host_attrib_init(shost); | |
6805 | ||
6806 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | |
6807 | spin_lock_irq(shost->host_lock); | |
6808 | lpfc_poll_start_timer(phba); | |
6809 | spin_unlock_irq(shost->host_lock); | |
6810 | } | |
6811 | ||
6812 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6813 | "0428 Perform SCSI scan\n"); | |
6814 | /* Send board arrival event to upper layer */ | |
6815 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; | |
6816 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; | |
6817 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
6818 | sizeof(adapter_event), | |
6819 | (char *) &adapter_event, | |
6820 | LPFC_NL_VENDOR_ID); | |
6821 | return; | |
6822 | } | |
6823 | ||
6824 | /** | |
6825 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. | |
6826 | * @phba: pointer to lpfc hba data structure. | |
6827 | * | |
6828 | * This routine is invoked to set up the PCI device memory space for device | |
6829 | * with SLI-3 interface spec. | |
6830 | * | |
6831 | * Return codes | |
af901ca1 | 6832 | * 0 - successful |
3772a991 JS |
6833 | * other values - error |
6834 | **/ | |
6835 | static int | |
6836 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) | |
6837 | { | |
6838 | struct pci_dev *pdev; | |
6839 | unsigned long bar0map_len, bar2map_len; | |
6840 | int i, hbq_count; | |
6841 | void *ptr; | |
6842 | int error = -ENODEV; | |
6843 | ||
6844 | /* Obtain PCI device reference */ | |
6845 | if (!phba->pcidev) | |
6846 | return error; | |
6847 | else | |
6848 | pdev = phba->pcidev; | |
6849 | ||
6850 | /* Set the device DMA mask size */ | |
8e68597d MR |
6851 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
6852 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
6853 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
6854 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
3772a991 | 6855 | return error; |
8e68597d MR |
6856 | } |
6857 | } | |
3772a991 JS |
6858 | |
6859 | /* Get the bus address of Bar0 and Bar2 and the number of bytes | |
6860 | * required by each mapping. | |
6861 | */ | |
6862 | phba->pci_bar0_map = pci_resource_start(pdev, 0); | |
6863 | bar0map_len = pci_resource_len(pdev, 0); | |
6864 | ||
6865 | phba->pci_bar2_map = pci_resource_start(pdev, 2); | |
6866 | bar2map_len = pci_resource_len(pdev, 2); | |
6867 | ||
6868 | /* Map HBA SLIM to a kernel virtual address. */ | |
6869 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); | |
6870 | if (!phba->slim_memmap_p) { | |
6871 | dev_printk(KERN_ERR, &pdev->dev, | |
6872 | "ioremap failed for SLIM memory.\n"); | |
6873 | goto out; | |
6874 | } | |
6875 | ||
6876 | /* Map HBA Control Registers to a kernel virtual address. */ | |
6877 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); | |
6878 | if (!phba->ctrl_regs_memmap_p) { | |
6879 | dev_printk(KERN_ERR, &pdev->dev, | |
6880 | "ioremap failed for HBA control registers.\n"); | |
6881 | goto out_iounmap_slim; | |
6882 | } | |
6883 | ||
6884 | /* Allocate memory for SLI-2 structures */ | |
1aee383d JP |
6885 | phba->slim2p.virt = dma_zalloc_coherent(&pdev->dev, SLI2_SLIM_SIZE, |
6886 | &phba->slim2p.phys, GFP_KERNEL); | |
3772a991 JS |
6887 | if (!phba->slim2p.virt) |
6888 | goto out_iounmap; | |
6889 | ||
3772a991 | 6890 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); |
7a470277 JS |
6891 | phba->mbox_ext = (phba->slim2p.virt + |
6892 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); | |
3772a991 JS |
6893 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
6894 | phba->IOCBs = (phba->slim2p.virt + | |
6895 | offsetof(struct lpfc_sli2_slim, IOCBs)); | |
6896 | ||
6897 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, | |
6898 | lpfc_sli_hbq_size(), | |
6899 | &phba->hbqslimp.phys, | |
6900 | GFP_KERNEL); | |
6901 | if (!phba->hbqslimp.virt) | |
6902 | goto out_free_slim; | |
6903 | ||
6904 | hbq_count = lpfc_sli_hbq_count(); | |
6905 | ptr = phba->hbqslimp.virt; | |
6906 | for (i = 0; i < hbq_count; ++i) { | |
6907 | phba->hbqs[i].hbq_virt = ptr; | |
6908 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
6909 | ptr += (lpfc_hbq_defs[i]->entry_count * | |
6910 | sizeof(struct lpfc_hbq_entry)); | |
6911 | } | |
6912 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; | |
6913 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; | |
6914 | ||
6915 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); | |
6916 | ||
3772a991 JS |
6917 | phba->MBslimaddr = phba->slim_memmap_p; |
6918 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; | |
6919 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; | |
6920 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; | |
6921 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; | |
6922 | ||
6923 | return 0; | |
6924 | ||
6925 | out_free_slim: | |
6926 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
6927 | phba->slim2p.virt, phba->slim2p.phys); | |
6928 | out_iounmap: | |
6929 | iounmap(phba->ctrl_regs_memmap_p); | |
6930 | out_iounmap_slim: | |
6931 | iounmap(phba->slim_memmap_p); | |
6932 | out: | |
6933 | return error; | |
6934 | } | |
6935 | ||
6936 | /** | |
6937 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. | |
6938 | * @phba: pointer to lpfc hba data structure. | |
6939 | * | |
6940 | * This routine is invoked to unset the PCI device memory space for device | |
6941 | * with SLI-3 interface spec. | |
6942 | **/ | |
6943 | static void | |
6944 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) | |
6945 | { | |
6946 | struct pci_dev *pdev; | |
6947 | ||
6948 | /* Obtain PCI device reference */ | |
6949 | if (!phba->pcidev) | |
6950 | return; | |
6951 | else | |
6952 | pdev = phba->pcidev; | |
6953 | ||
6954 | /* Free coherent DMA memory allocated */ | |
6955 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
6956 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
6957 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
6958 | phba->slim2p.virt, phba->slim2p.phys); | |
6959 | ||
6960 | /* I/O memory unmap */ | |
6961 | iounmap(phba->ctrl_regs_memmap_p); | |
6962 | iounmap(phba->slim_memmap_p); | |
6963 | ||
6964 | return; | |
6965 | } | |
6966 | ||
6967 | /** | |
da0436e9 | 6968 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
3772a991 JS |
6969 | * @phba: pointer to lpfc hba data structure. |
6970 | * | |
da0436e9 JS |
6971 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
6972 | * done and check status. | |
3772a991 | 6973 | * |
da0436e9 | 6974 | * Return 0 if successful, otherwise -ENODEV. |
3772a991 | 6975 | **/ |
da0436e9 JS |
6976 | int |
6977 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) | |
3772a991 | 6978 | { |
2fcee4bf JS |
6979 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
6980 | struct lpfc_register reg_data; | |
6981 | int i, port_error = 0; | |
6982 | uint32_t if_type; | |
3772a991 | 6983 | |
9940b97b JS |
6984 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
6985 | memset(®_data, 0, sizeof(reg_data)); | |
2fcee4bf | 6986 | if (!phba->sli4_hba.PSMPHRregaddr) |
da0436e9 | 6987 | return -ENODEV; |
3772a991 | 6988 | |
da0436e9 JS |
6989 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
6990 | for (i = 0; i < 3000; i++) { | |
9940b97b JS |
6991 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
6992 | &portsmphr_reg.word0) || | |
6993 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { | |
2fcee4bf | 6994 | /* Port has a fatal POST error, break out */ |
da0436e9 JS |
6995 | port_error = -ENODEV; |
6996 | break; | |
6997 | } | |
2fcee4bf JS |
6998 | if (LPFC_POST_STAGE_PORT_READY == |
6999 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) | |
da0436e9 | 7000 | break; |
da0436e9 | 7001 | msleep(10); |
3772a991 JS |
7002 | } |
7003 | ||
2fcee4bf JS |
7004 | /* |
7005 | * If there was a port error during POST, then don't proceed with | |
7006 | * other register reads as the data may not be valid. Just exit. | |
7007 | */ | |
7008 | if (port_error) { | |
da0436e9 | 7009 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2fcee4bf JS |
7010 | "1408 Port Failed POST - portsmphr=0x%x, " |
7011 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " | |
7012 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", | |
7013 | portsmphr_reg.word0, | |
7014 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), | |
7015 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), | |
7016 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), | |
7017 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), | |
7018 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), | |
7019 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), | |
7020 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), | |
7021 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); | |
7022 | } else { | |
28baac74 | 7023 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2fcee4bf JS |
7024 | "2534 Device Info: SLIFamily=0x%x, " |
7025 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " | |
7026 | "SLIHint_2=0x%x, FT=0x%x\n", | |
28baac74 JS |
7027 | bf_get(lpfc_sli_intf_sli_family, |
7028 | &phba->sli4_hba.sli_intf), | |
7029 | bf_get(lpfc_sli_intf_slirev, | |
7030 | &phba->sli4_hba.sli_intf), | |
085c647c JS |
7031 | bf_get(lpfc_sli_intf_if_type, |
7032 | &phba->sli4_hba.sli_intf), | |
7033 | bf_get(lpfc_sli_intf_sli_hint1, | |
28baac74 | 7034 | &phba->sli4_hba.sli_intf), |
085c647c JS |
7035 | bf_get(lpfc_sli_intf_sli_hint2, |
7036 | &phba->sli4_hba.sli_intf), | |
7037 | bf_get(lpfc_sli_intf_func_type, | |
28baac74 | 7038 | &phba->sli4_hba.sli_intf)); |
2fcee4bf JS |
7039 | /* |
7040 | * Check for other Port errors during the initialization | |
7041 | * process. Fail the load if the port did not come up | |
7042 | * correctly. | |
7043 | */ | |
7044 | if_type = bf_get(lpfc_sli_intf_if_type, | |
7045 | &phba->sli4_hba.sli_intf); | |
7046 | switch (if_type) { | |
7047 | case LPFC_SLI_INTF_IF_TYPE_0: | |
7048 | phba->sli4_hba.ue_mask_lo = | |
7049 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); | |
7050 | phba->sli4_hba.ue_mask_hi = | |
7051 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); | |
7052 | uerrlo_reg.word0 = | |
7053 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); | |
7054 | uerrhi_reg.word0 = | |
7055 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); | |
7056 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || | |
7057 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { | |
7058 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7059 | "1422 Unrecoverable Error " | |
7060 | "Detected during POST " | |
7061 | "uerr_lo_reg=0x%x, " | |
7062 | "uerr_hi_reg=0x%x, " | |
7063 | "ue_mask_lo_reg=0x%x, " | |
7064 | "ue_mask_hi_reg=0x%x\n", | |
7065 | uerrlo_reg.word0, | |
7066 | uerrhi_reg.word0, | |
7067 | phba->sli4_hba.ue_mask_lo, | |
7068 | phba->sli4_hba.ue_mask_hi); | |
7069 | port_error = -ENODEV; | |
7070 | } | |
7071 | break; | |
7072 | case LPFC_SLI_INTF_IF_TYPE_2: | |
7073 | /* Final checks. The port status should be clean. */ | |
9940b97b JS |
7074 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
7075 | ®_data.word0) || | |
0558056c JS |
7076 | (bf_get(lpfc_sliport_status_err, ®_data) && |
7077 | !bf_get(lpfc_sliport_status_rn, ®_data))) { | |
2fcee4bf JS |
7078 | phba->work_status[0] = |
7079 | readl(phba->sli4_hba.u.if_type2. | |
7080 | ERR1regaddr); | |
7081 | phba->work_status[1] = | |
7082 | readl(phba->sli4_hba.u.if_type2. | |
7083 | ERR2regaddr); | |
7084 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8fcb8acd JS |
7085 | "2888 Unrecoverable port error " |
7086 | "following POST: port status reg " | |
7087 | "0x%x, port_smphr reg 0x%x, " | |
2fcee4bf JS |
7088 | "error 1=0x%x, error 2=0x%x\n", |
7089 | reg_data.word0, | |
7090 | portsmphr_reg.word0, | |
7091 | phba->work_status[0], | |
7092 | phba->work_status[1]); | |
7093 | port_error = -ENODEV; | |
7094 | } | |
7095 | break; | |
7096 | case LPFC_SLI_INTF_IF_TYPE_1: | |
7097 | default: | |
7098 | break; | |
7099 | } | |
28baac74 | 7100 | } |
da0436e9 JS |
7101 | return port_error; |
7102 | } | |
3772a991 | 7103 | |
da0436e9 JS |
7104 | /** |
7105 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. | |
7106 | * @phba: pointer to lpfc hba data structure. | |
2fcee4bf | 7107 | * @if_type: The SLI4 interface type getting configured. |
da0436e9 JS |
7108 | * |
7109 | * This routine is invoked to set up SLI4 BAR0 PCI config space register | |
7110 | * memory map. | |
7111 | **/ | |
7112 | static void | |
2fcee4bf JS |
7113 | lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type) |
7114 | { | |
7115 | switch (if_type) { | |
7116 | case LPFC_SLI_INTF_IF_TYPE_0: | |
7117 | phba->sli4_hba.u.if_type0.UERRLOregaddr = | |
7118 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; | |
7119 | phba->sli4_hba.u.if_type0.UERRHIregaddr = | |
7120 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; | |
7121 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = | |
7122 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; | |
7123 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = | |
7124 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; | |
7125 | phba->sli4_hba.SLIINTFregaddr = | |
7126 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; | |
7127 | break; | |
7128 | case LPFC_SLI_INTF_IF_TYPE_2: | |
7129 | phba->sli4_hba.u.if_type2.ERR1regaddr = | |
88a2cfbb JS |
7130 | phba->sli4_hba.conf_regs_memmap_p + |
7131 | LPFC_CTL_PORT_ER1_OFFSET; | |
2fcee4bf | 7132 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
88a2cfbb JS |
7133 | phba->sli4_hba.conf_regs_memmap_p + |
7134 | LPFC_CTL_PORT_ER2_OFFSET; | |
2fcee4bf | 7135 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
88a2cfbb JS |
7136 | phba->sli4_hba.conf_regs_memmap_p + |
7137 | LPFC_CTL_PORT_CTL_OFFSET; | |
2fcee4bf | 7138 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
88a2cfbb JS |
7139 | phba->sli4_hba.conf_regs_memmap_p + |
7140 | LPFC_CTL_PORT_STA_OFFSET; | |
2fcee4bf JS |
7141 | phba->sli4_hba.SLIINTFregaddr = |
7142 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; | |
7143 | phba->sli4_hba.PSMPHRregaddr = | |
88a2cfbb JS |
7144 | phba->sli4_hba.conf_regs_memmap_p + |
7145 | LPFC_CTL_PORT_SEM_OFFSET; | |
2fcee4bf | 7146 | phba->sli4_hba.RQDBregaddr = |
962bc51b JS |
7147 | phba->sli4_hba.conf_regs_memmap_p + |
7148 | LPFC_ULP0_RQ_DOORBELL; | |
2fcee4bf | 7149 | phba->sli4_hba.WQDBregaddr = |
962bc51b JS |
7150 | phba->sli4_hba.conf_regs_memmap_p + |
7151 | LPFC_ULP0_WQ_DOORBELL; | |
2fcee4bf JS |
7152 | phba->sli4_hba.EQCQDBregaddr = |
7153 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; | |
7154 | phba->sli4_hba.MQDBregaddr = | |
7155 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; | |
7156 | phba->sli4_hba.BMBXregaddr = | |
7157 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; | |
7158 | break; | |
7159 | case LPFC_SLI_INTF_IF_TYPE_1: | |
7160 | default: | |
7161 | dev_printk(KERN_ERR, &phba->pcidev->dev, | |
7162 | "FATAL - unsupported SLI4 interface type - %d\n", | |
7163 | if_type); | |
7164 | break; | |
7165 | } | |
da0436e9 | 7166 | } |
3772a991 | 7167 | |
da0436e9 JS |
7168 | /** |
7169 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. | |
7170 | * @phba: pointer to lpfc hba data structure. | |
7171 | * | |
7172 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) | |
7173 | * memory map. | |
7174 | **/ | |
7175 | static void | |
7176 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) | |
7177 | { | |
2fcee4bf JS |
7178 | phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
7179 | LPFC_SLIPORT_IF0_SMPHR; | |
da0436e9 | 7180 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 7181 | LPFC_HST_ISR0; |
da0436e9 | 7182 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 7183 | LPFC_HST_IMR0; |
da0436e9 | 7184 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 7185 | LPFC_HST_ISCR0; |
3772a991 JS |
7186 | } |
7187 | ||
7188 | /** | |
da0436e9 | 7189 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
3772a991 | 7190 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 7191 | * @vf: virtual function number |
3772a991 | 7192 | * |
da0436e9 JS |
7193 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
7194 | * based on the given viftual function number, @vf. | |
7195 | * | |
7196 | * Return 0 if successful, otherwise -ENODEV. | |
3772a991 | 7197 | **/ |
da0436e9 JS |
7198 | static int |
7199 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) | |
3772a991 | 7200 | { |
da0436e9 JS |
7201 | if (vf > LPFC_VIR_FUNC_MAX) |
7202 | return -ENODEV; | |
3772a991 | 7203 | |
da0436e9 | 7204 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
962bc51b JS |
7205 | vf * LPFC_VFR_PAGE_SIZE + |
7206 | LPFC_ULP0_RQ_DOORBELL); | |
da0436e9 | 7207 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
962bc51b JS |
7208 | vf * LPFC_VFR_PAGE_SIZE + |
7209 | LPFC_ULP0_WQ_DOORBELL); | |
da0436e9 JS |
7210 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
7211 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); | |
7212 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
7213 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); | |
7214 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
7215 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); | |
7216 | return 0; | |
3772a991 JS |
7217 | } |
7218 | ||
7219 | /** | |
da0436e9 | 7220 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
3772a991 JS |
7221 | * @phba: pointer to lpfc hba data structure. |
7222 | * | |
da0436e9 JS |
7223 | * This routine is invoked to create the bootstrap mailbox |
7224 | * region consistent with the SLI-4 interface spec. This | |
7225 | * routine allocates all memory necessary to communicate | |
7226 | * mailbox commands to the port and sets up all alignment | |
7227 | * needs. No locks are expected to be held when calling | |
7228 | * this routine. | |
3772a991 JS |
7229 | * |
7230 | * Return codes | |
af901ca1 | 7231 | * 0 - successful |
d439d286 | 7232 | * -ENOMEM - could not allocated memory. |
da0436e9 | 7233 | **/ |
3772a991 | 7234 | static int |
da0436e9 | 7235 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 7236 | { |
da0436e9 JS |
7237 | uint32_t bmbx_size; |
7238 | struct lpfc_dmabuf *dmabuf; | |
7239 | struct dma_address *dma_address; | |
7240 | uint32_t pa_addr; | |
7241 | uint64_t phys_addr; | |
7242 | ||
7243 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
7244 | if (!dmabuf) | |
7245 | return -ENOMEM; | |
3772a991 | 7246 | |
da0436e9 JS |
7247 | /* |
7248 | * The bootstrap mailbox region is comprised of 2 parts | |
7249 | * plus an alignment restriction of 16 bytes. | |
7250 | */ | |
7251 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); | |
1aee383d JP |
7252 | dmabuf->virt = dma_zalloc_coherent(&phba->pcidev->dev, bmbx_size, |
7253 | &dmabuf->phys, GFP_KERNEL); | |
da0436e9 JS |
7254 | if (!dmabuf->virt) { |
7255 | kfree(dmabuf); | |
7256 | return -ENOMEM; | |
3772a991 JS |
7257 | } |
7258 | ||
da0436e9 JS |
7259 | /* |
7260 | * Initialize the bootstrap mailbox pointers now so that the register | |
7261 | * operations are simple later. The mailbox dma address is required | |
7262 | * to be 16-byte aligned. Also align the virtual memory as each | |
7263 | * maibox is copied into the bmbx mailbox region before issuing the | |
7264 | * command to the port. | |
7265 | */ | |
7266 | phba->sli4_hba.bmbx.dmabuf = dmabuf; | |
7267 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; | |
7268 | ||
7269 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, | |
7270 | LPFC_ALIGN_16_BYTE); | |
7271 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, | |
7272 | LPFC_ALIGN_16_BYTE); | |
7273 | ||
7274 | /* | |
7275 | * Set the high and low physical addresses now. The SLI4 alignment | |
7276 | * requirement is 16 bytes and the mailbox is posted to the port | |
7277 | * as two 30-bit addresses. The other data is a bit marking whether | |
7278 | * the 30-bit address is the high or low address. | |
7279 | * Upcast bmbx aphys to 64bits so shift instruction compiles | |
7280 | * clean on 32 bit machines. | |
7281 | */ | |
7282 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
7283 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; | |
7284 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); | |
7285 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | | |
7286 | LPFC_BMBX_BIT1_ADDR_HI); | |
7287 | ||
7288 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); | |
7289 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | | |
7290 | LPFC_BMBX_BIT1_ADDR_LO); | |
7291 | return 0; | |
3772a991 JS |
7292 | } |
7293 | ||
7294 | /** | |
da0436e9 | 7295 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
3772a991 JS |
7296 | * @phba: pointer to lpfc hba data structure. |
7297 | * | |
da0436e9 JS |
7298 | * This routine is invoked to teardown the bootstrap mailbox |
7299 | * region and release all host resources. This routine requires | |
7300 | * the caller to ensure all mailbox commands recovered, no | |
7301 | * additional mailbox comands are sent, and interrupts are disabled | |
7302 | * before calling this routine. | |
7303 | * | |
7304 | **/ | |
3772a991 | 7305 | static void |
da0436e9 | 7306 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 7307 | { |
da0436e9 JS |
7308 | dma_free_coherent(&phba->pcidev->dev, |
7309 | phba->sli4_hba.bmbx.bmbx_size, | |
7310 | phba->sli4_hba.bmbx.dmabuf->virt, | |
7311 | phba->sli4_hba.bmbx.dmabuf->phys); | |
7312 | ||
7313 | kfree(phba->sli4_hba.bmbx.dmabuf); | |
7314 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); | |
3772a991 JS |
7315 | } |
7316 | ||
7317 | /** | |
da0436e9 | 7318 | * lpfc_sli4_read_config - Get the config parameters. |
3772a991 JS |
7319 | * @phba: pointer to lpfc hba data structure. |
7320 | * | |
da0436e9 JS |
7321 | * This routine is invoked to read the configuration parameters from the HBA. |
7322 | * The configuration parameters are used to set the base and maximum values | |
7323 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource | |
7324 | * allocation for the port. | |
3772a991 JS |
7325 | * |
7326 | * Return codes | |
af901ca1 | 7327 | * 0 - successful |
25985edc | 7328 | * -ENOMEM - No available memory |
d439d286 | 7329 | * -EIO - The mailbox failed to complete successfully. |
3772a991 | 7330 | **/ |
ff78d8f9 | 7331 | int |
da0436e9 | 7332 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
3772a991 | 7333 | { |
da0436e9 JS |
7334 | LPFC_MBOXQ_t *pmb; |
7335 | struct lpfc_mbx_read_config *rd_config; | |
912e3acd JS |
7336 | union lpfc_sli4_cfg_shdr *shdr; |
7337 | uint32_t shdr_status, shdr_add_status; | |
7338 | struct lpfc_mbx_get_func_cfg *get_func_cfg; | |
7339 | struct lpfc_rsrc_desc_fcfcoe *desc; | |
8aa134a8 | 7340 | char *pdesc_0; |
c691816e JS |
7341 | uint16_t forced_link_speed; |
7342 | uint32_t if_type; | |
8aa134a8 | 7343 | int length, i, rc = 0, rc2; |
3772a991 | 7344 | |
da0436e9 JS |
7345 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
7346 | if (!pmb) { | |
7347 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
7348 | "2011 Unable to allocate memory for issuing " | |
7349 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
7350 | return -ENOMEM; | |
3772a991 JS |
7351 | } |
7352 | ||
da0436e9 | 7353 | lpfc_read_config(phba, pmb); |
3772a991 | 7354 | |
da0436e9 JS |
7355 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
7356 | if (rc != MBX_SUCCESS) { | |
7357 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
7358 | "2012 Mailbox failed , mbxCmd x%x " | |
7359 | "READ_CONFIG, mbxStatus x%x\n", | |
7360 | bf_get(lpfc_mqe_command, &pmb->u.mqe), | |
7361 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); | |
7362 | rc = -EIO; | |
7363 | } else { | |
7364 | rd_config = &pmb->u.mqe.un.rd_config; | |
ff78d8f9 JS |
7365 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
7366 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; | |
7367 | phba->sli4_hba.lnk_info.lnk_tp = | |
7368 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); | |
7369 | phba->sli4_hba.lnk_info.lnk_no = | |
7370 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); | |
7371 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
7372 | "3081 lnk_type:%d, lnk_numb:%d\n", | |
7373 | phba->sli4_hba.lnk_info.lnk_tp, | |
7374 | phba->sli4_hba.lnk_info.lnk_no); | |
7375 | } else | |
7376 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
7377 | "3082 Mailbox (x%x) returned ldv:x0\n", | |
7378 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); | |
6d368e53 JS |
7379 | phba->sli4_hba.extents_in_use = |
7380 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); | |
da0436e9 JS |
7381 | phba->sli4_hba.max_cfg_param.max_xri = |
7382 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); | |
7383 | phba->sli4_hba.max_cfg_param.xri_base = | |
7384 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); | |
7385 | phba->sli4_hba.max_cfg_param.max_vpi = | |
7386 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); | |
7387 | phba->sli4_hba.max_cfg_param.vpi_base = | |
7388 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); | |
7389 | phba->sli4_hba.max_cfg_param.max_rpi = | |
7390 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); | |
7391 | phba->sli4_hba.max_cfg_param.rpi_base = | |
7392 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); | |
7393 | phba->sli4_hba.max_cfg_param.max_vfi = | |
7394 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); | |
7395 | phba->sli4_hba.max_cfg_param.vfi_base = | |
7396 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); | |
7397 | phba->sli4_hba.max_cfg_param.max_fcfi = | |
7398 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); | |
da0436e9 JS |
7399 | phba->sli4_hba.max_cfg_param.max_eq = |
7400 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); | |
7401 | phba->sli4_hba.max_cfg_param.max_rq = | |
7402 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); | |
7403 | phba->sli4_hba.max_cfg_param.max_wq = | |
7404 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); | |
7405 | phba->sli4_hba.max_cfg_param.max_cq = | |
7406 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); | |
7407 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); | |
7408 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; | |
7409 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; | |
7410 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; | |
5ffc266e JS |
7411 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
7412 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; | |
da0436e9 JS |
7413 | phba->max_vports = phba->max_vpi; |
7414 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
6d368e53 JS |
7415 | "2003 cfg params Extents? %d " |
7416 | "XRI(B:%d M:%d), " | |
da0436e9 JS |
7417 | "VPI(B:%d M:%d) " |
7418 | "VFI(B:%d M:%d) " | |
7419 | "RPI(B:%d M:%d) " | |
2ea259ee | 7420 | "FCFI:%d EQ:%d CQ:%d WQ:%d RQ:%d\n", |
6d368e53 | 7421 | phba->sli4_hba.extents_in_use, |
da0436e9 JS |
7422 | phba->sli4_hba.max_cfg_param.xri_base, |
7423 | phba->sli4_hba.max_cfg_param.max_xri, | |
7424 | phba->sli4_hba.max_cfg_param.vpi_base, | |
7425 | phba->sli4_hba.max_cfg_param.max_vpi, | |
7426 | phba->sli4_hba.max_cfg_param.vfi_base, | |
7427 | phba->sli4_hba.max_cfg_param.max_vfi, | |
7428 | phba->sli4_hba.max_cfg_param.rpi_base, | |
7429 | phba->sli4_hba.max_cfg_param.max_rpi, | |
2ea259ee JS |
7430 | phba->sli4_hba.max_cfg_param.max_fcfi, |
7431 | phba->sli4_hba.max_cfg_param.max_eq, | |
7432 | phba->sli4_hba.max_cfg_param.max_cq, | |
7433 | phba->sli4_hba.max_cfg_param.max_wq, | |
7434 | phba->sli4_hba.max_cfg_param.max_rq); | |
7435 | ||
3772a991 | 7436 | } |
912e3acd JS |
7437 | |
7438 | if (rc) | |
7439 | goto read_cfg_out; | |
da0436e9 | 7440 | |
c691816e JS |
7441 | /* Update link speed if forced link speed is supported */ |
7442 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); | |
7443 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { | |
7444 | forced_link_speed = | |
7445 | bf_get(lpfc_mbx_rd_conf_link_speed, rd_config); | |
7446 | if (forced_link_speed) { | |
7447 | phba->hba_flag |= HBA_FORCED_LINK_SPEED; | |
7448 | ||
7449 | switch (forced_link_speed) { | |
7450 | case LINK_SPEED_1G: | |
7451 | phba->cfg_link_speed = | |
7452 | LPFC_USER_LINK_SPEED_1G; | |
7453 | break; | |
7454 | case LINK_SPEED_2G: | |
7455 | phba->cfg_link_speed = | |
7456 | LPFC_USER_LINK_SPEED_2G; | |
7457 | break; | |
7458 | case LINK_SPEED_4G: | |
7459 | phba->cfg_link_speed = | |
7460 | LPFC_USER_LINK_SPEED_4G; | |
7461 | break; | |
7462 | case LINK_SPEED_8G: | |
7463 | phba->cfg_link_speed = | |
7464 | LPFC_USER_LINK_SPEED_8G; | |
7465 | break; | |
7466 | case LINK_SPEED_10G: | |
7467 | phba->cfg_link_speed = | |
7468 | LPFC_USER_LINK_SPEED_10G; | |
7469 | break; | |
7470 | case LINK_SPEED_16G: | |
7471 | phba->cfg_link_speed = | |
7472 | LPFC_USER_LINK_SPEED_16G; | |
7473 | break; | |
7474 | case LINK_SPEED_32G: | |
7475 | phba->cfg_link_speed = | |
7476 | LPFC_USER_LINK_SPEED_32G; | |
7477 | break; | |
7478 | case 0xffff: | |
7479 | phba->cfg_link_speed = | |
7480 | LPFC_USER_LINK_SPEED_AUTO; | |
7481 | break; | |
7482 | default: | |
7483 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
7484 | "0047 Unrecognized link " | |
7485 | "speed : %d\n", | |
7486 | forced_link_speed); | |
7487 | phba->cfg_link_speed = | |
7488 | LPFC_USER_LINK_SPEED_AUTO; | |
7489 | } | |
7490 | } | |
7491 | } | |
7492 | ||
da0436e9 | 7493 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
572709e2 JS |
7494 | length = phba->sli4_hba.max_cfg_param.max_xri - |
7495 | lpfc_sli4_get_els_iocb_cnt(phba); | |
7496 | if (phba->cfg_hba_queue_depth > length) { | |
7497 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7498 | "3361 HBA queue depth changed from %d to %d\n", | |
7499 | phba->cfg_hba_queue_depth, length); | |
7500 | phba->cfg_hba_queue_depth = length; | |
7501 | } | |
912e3acd JS |
7502 | |
7503 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
7504 | LPFC_SLI_INTF_IF_TYPE_2) | |
7505 | goto read_cfg_out; | |
7506 | ||
7507 | /* get the pf# and vf# for SLI4 if_type 2 port */ | |
7508 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - | |
7509 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
7510 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, | |
7511 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, | |
7512 | length, LPFC_SLI4_MBX_EMBED); | |
7513 | ||
8aa134a8 | 7514 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
912e3acd JS |
7515 | shdr = (union lpfc_sli4_cfg_shdr *) |
7516 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; | |
7517 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
7518 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
8aa134a8 | 7519 | if (rc2 || shdr_status || shdr_add_status) { |
912e3acd JS |
7520 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
7521 | "3026 Mailbox failed , mbxCmd x%x " | |
7522 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", | |
7523 | bf_get(lpfc_mqe_command, &pmb->u.mqe), | |
7524 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); | |
912e3acd JS |
7525 | goto read_cfg_out; |
7526 | } | |
7527 | ||
7528 | /* search for fc_fcoe resrouce descriptor */ | |
7529 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; | |
912e3acd | 7530 | |
8aa134a8 JS |
7531 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
7532 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; | |
7533 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); | |
7534 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) | |
7535 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; | |
7536 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) | |
7537 | goto read_cfg_out; | |
7538 | ||
912e3acd | 7539 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
8aa134a8 | 7540 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
912e3acd | 7541 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
8aa134a8 | 7542 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
912e3acd JS |
7543 | phba->sli4_hba.iov.pf_number = |
7544 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); | |
7545 | phba->sli4_hba.iov.vf_number = | |
7546 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); | |
7547 | break; | |
7548 | } | |
7549 | } | |
7550 | ||
7551 | if (i < LPFC_RSRC_DESC_MAX_NUM) | |
7552 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
7553 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " | |
7554 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, | |
7555 | phba->sli4_hba.iov.vf_number); | |
8aa134a8 | 7556 | else |
912e3acd JS |
7557 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
7558 | "3028 GET_FUNCTION_CONFIG: failed to find " | |
7559 | "Resrouce Descriptor:x%x\n", | |
7560 | LPFC_RSRC_DESC_TYPE_FCFCOE); | |
912e3acd JS |
7561 | |
7562 | read_cfg_out: | |
7563 | mempool_free(pmb, phba->mbox_mem_pool); | |
da0436e9 | 7564 | return rc; |
3772a991 JS |
7565 | } |
7566 | ||
7567 | /** | |
2fcee4bf | 7568 | * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port. |
3772a991 JS |
7569 | * @phba: pointer to lpfc hba data structure. |
7570 | * | |
2fcee4bf JS |
7571 | * This routine is invoked to setup the port-side endian order when |
7572 | * the port if_type is 0. This routine has no function for other | |
7573 | * if_types. | |
da0436e9 JS |
7574 | * |
7575 | * Return codes | |
af901ca1 | 7576 | * 0 - successful |
25985edc | 7577 | * -ENOMEM - No available memory |
d439d286 | 7578 | * -EIO - The mailbox failed to complete successfully. |
3772a991 | 7579 | **/ |
da0436e9 JS |
7580 | static int |
7581 | lpfc_setup_endian_order(struct lpfc_hba *phba) | |
3772a991 | 7582 | { |
da0436e9 | 7583 | LPFC_MBOXQ_t *mboxq; |
2fcee4bf | 7584 | uint32_t if_type, rc = 0; |
da0436e9 JS |
7585 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
7586 | HOST_ENDIAN_HIGH_WORD1}; | |
3772a991 | 7587 | |
2fcee4bf JS |
7588 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
7589 | switch (if_type) { | |
7590 | case LPFC_SLI_INTF_IF_TYPE_0: | |
7591 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, | |
7592 | GFP_KERNEL); | |
7593 | if (!mboxq) { | |
7594 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7595 | "0492 Unable to allocate memory for " | |
7596 | "issuing SLI_CONFIG_SPECIAL mailbox " | |
7597 | "command\n"); | |
7598 | return -ENOMEM; | |
7599 | } | |
3772a991 | 7600 | |
2fcee4bf JS |
7601 | /* |
7602 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first | |
7603 | * two words to contain special data values and no other data. | |
7604 | */ | |
7605 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
7606 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); | |
7607 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7608 | if (rc != MBX_SUCCESS) { | |
7609 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7610 | "0493 SLI_CONFIG_SPECIAL mailbox " | |
7611 | "failed with status x%x\n", | |
7612 | rc); | |
7613 | rc = -EIO; | |
7614 | } | |
7615 | mempool_free(mboxq, phba->mbox_mem_pool); | |
7616 | break; | |
7617 | case LPFC_SLI_INTF_IF_TYPE_2: | |
7618 | case LPFC_SLI_INTF_IF_TYPE_1: | |
7619 | default: | |
7620 | break; | |
da0436e9 | 7621 | } |
da0436e9 | 7622 | return rc; |
3772a991 JS |
7623 | } |
7624 | ||
7625 | /** | |
895427bd | 7626 | * lpfc_sli4_queue_verify - Verify and update EQ counts |
3772a991 JS |
7627 | * @phba: pointer to lpfc hba data structure. |
7628 | * | |
895427bd JS |
7629 | * This routine is invoked to check the user settable queue counts for EQs. |
7630 | * After this routine is called the counts will be set to valid values that | |
5350d872 JS |
7631 | * adhere to the constraints of the system's interrupt vectors and the port's |
7632 | * queue resources. | |
da0436e9 JS |
7633 | * |
7634 | * Return codes | |
af901ca1 | 7635 | * 0 - successful |
25985edc | 7636 | * -ENOMEM - No available memory |
3772a991 | 7637 | **/ |
da0436e9 | 7638 | static int |
5350d872 | 7639 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
3772a991 | 7640 | { |
895427bd | 7641 | int io_channel; |
1ba981fd | 7642 | int fof_vectors = phba->cfg_fof ? 1 : 0; |
3772a991 | 7643 | |
da0436e9 | 7644 | /* |
67d12733 | 7645 | * Sanity check for configured queue parameters against the run-time |
da0436e9 JS |
7646 | * device parameters |
7647 | */ | |
3772a991 | 7648 | |
67d12733 | 7649 | /* Sanity check on HBA EQ parameters */ |
895427bd | 7650 | io_channel = phba->io_channel_irqs; |
67d12733 | 7651 | |
895427bd | 7652 | if (phba->sli4_hba.num_online_cpu < io_channel) { |
82c3e9ba JS |
7653 | lpfc_printf_log(phba, |
7654 | KERN_ERR, LOG_INIT, | |
90695ee0 | 7655 | "3188 Reducing IO channels to match number of " |
7bb03bbf | 7656 | "online CPUs: from %d to %d\n", |
895427bd JS |
7657 | io_channel, phba->sli4_hba.num_online_cpu); |
7658 | io_channel = phba->sli4_hba.num_online_cpu; | |
90695ee0 JS |
7659 | } |
7660 | ||
895427bd | 7661 | if (io_channel + fof_vectors > phba->sli4_hba.max_cfg_param.max_eq) { |
82c3e9ba JS |
7662 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
7663 | "2575 Reducing IO channels to match number of " | |
7664 | "available EQs: from %d to %d\n", | |
895427bd | 7665 | io_channel, |
82c3e9ba | 7666 | phba->sli4_hba.max_cfg_param.max_eq); |
895427bd | 7667 | io_channel = phba->sli4_hba.max_cfg_param.max_eq - fof_vectors; |
da0436e9 | 7668 | } |
67d12733 | 7669 | |
895427bd JS |
7670 | /* The actual number of FCP / NVME event queues adopted */ |
7671 | if (io_channel != phba->io_channel_irqs) | |
7672 | phba->io_channel_irqs = io_channel; | |
7673 | if (phba->cfg_fcp_io_channel > io_channel) | |
7674 | phba->cfg_fcp_io_channel = io_channel; | |
7675 | if (phba->cfg_nvme_io_channel > io_channel) | |
7676 | phba->cfg_nvme_io_channel = io_channel; | |
7677 | ||
7678 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
f358dd0c | 7679 | "2574 IO channels: irqs %d fcp %d nvme %d\n", |
895427bd JS |
7680 | phba->io_channel_irqs, phba->cfg_fcp_io_channel, |
7681 | phba->cfg_nvme_io_channel); | |
3772a991 | 7682 | |
da0436e9 JS |
7683 | /* Get EQ depth from module parameter, fake the default for now */ |
7684 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; | |
7685 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; | |
3772a991 | 7686 | |
5350d872 JS |
7687 | /* Get CQ depth from module parameter, fake the default for now */ |
7688 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; | |
7689 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; | |
895427bd JS |
7690 | return 0; |
7691 | } | |
7692 | ||
7693 | static int | |
7694 | lpfc_alloc_nvme_wq_cq(struct lpfc_hba *phba, int wqidx) | |
7695 | { | |
7696 | struct lpfc_queue *qdesc; | |
7697 | int cnt; | |
5350d872 | 7698 | |
895427bd JS |
7699 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
7700 | phba->sli4_hba.cq_ecount); | |
7701 | if (!qdesc) { | |
7702 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7703 | "0508 Failed allocate fast-path NVME CQ (%d)\n", | |
7704 | wqidx); | |
7705 | return 1; | |
7706 | } | |
7707 | phba->sli4_hba.nvme_cq[wqidx] = qdesc; | |
7708 | ||
7709 | cnt = LPFC_NVME_WQSIZE; | |
7710 | qdesc = lpfc_sli4_queue_alloc(phba, LPFC_WQE128_SIZE, cnt); | |
7711 | if (!qdesc) { | |
7712 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7713 | "0509 Failed allocate fast-path NVME WQ (%d)\n", | |
7714 | wqidx); | |
7715 | return 1; | |
7716 | } | |
7717 | phba->sli4_hba.nvme_wq[wqidx] = qdesc; | |
7718 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); | |
7719 | return 0; | |
7720 | } | |
7721 | ||
7722 | static int | |
7723 | lpfc_alloc_fcp_wq_cq(struct lpfc_hba *phba, int wqidx) | |
7724 | { | |
7725 | struct lpfc_queue *qdesc; | |
7726 | uint32_t wqesize; | |
7727 | ||
7728 | /* Create Fast Path FCP CQs */ | |
7729 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
7730 | phba->sli4_hba.cq_ecount); | |
7731 | if (!qdesc) { | |
7732 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7733 | "0499 Failed allocate fast-path FCP CQ (%d)\n", wqidx); | |
7734 | return 1; | |
7735 | } | |
7736 | phba->sli4_hba.fcp_cq[wqidx] = qdesc; | |
7737 | ||
7738 | /* Create Fast Path FCP WQs */ | |
7739 | wqesize = (phba->fcp_embed_io) ? | |
7740 | LPFC_WQE128_SIZE : phba->sli4_hba.wq_esize; | |
7741 | qdesc = lpfc_sli4_queue_alloc(phba, wqesize, phba->sli4_hba.wq_ecount); | |
7742 | if (!qdesc) { | |
7743 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7744 | "0503 Failed allocate fast-path FCP WQ (%d)\n", | |
7745 | wqidx); | |
7746 | return 1; | |
7747 | } | |
7748 | phba->sli4_hba.fcp_wq[wqidx] = qdesc; | |
7749 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); | |
5350d872 | 7750 | return 0; |
5350d872 JS |
7751 | } |
7752 | ||
7753 | /** | |
7754 | * lpfc_sli4_queue_create - Create all the SLI4 queues | |
7755 | * @phba: pointer to lpfc hba data structure. | |
7756 | * | |
7757 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA | |
7758 | * operation. For each SLI4 queue type, the parameters such as queue entry | |
7759 | * count (queue depth) shall be taken from the module parameter. For now, | |
7760 | * we just use some constant number as place holder. | |
7761 | * | |
7762 | * Return codes | |
4907cb7b | 7763 | * 0 - successful |
5350d872 JS |
7764 | * -ENOMEM - No availble memory |
7765 | * -EIO - The mailbox failed to complete successfully. | |
7766 | **/ | |
7767 | int | |
7768 | lpfc_sli4_queue_create(struct lpfc_hba *phba) | |
7769 | { | |
7770 | struct lpfc_queue *qdesc; | |
895427bd | 7771 | int idx, io_channel; |
5350d872 JS |
7772 | |
7773 | /* | |
67d12733 | 7774 | * Create HBA Record arrays. |
895427bd | 7775 | * Both NVME and FCP will share that same vectors / EQs |
5350d872 | 7776 | */ |
895427bd JS |
7777 | io_channel = phba->io_channel_irqs; |
7778 | if (!io_channel) | |
67d12733 | 7779 | return -ERANGE; |
5350d872 | 7780 | |
67d12733 JS |
7781 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
7782 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; | |
7783 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; | |
7784 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; | |
7785 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; | |
7786 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; | |
895427bd JS |
7787 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; |
7788 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; | |
7789 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; | |
7790 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; | |
67d12733 | 7791 | |
895427bd JS |
7792 | phba->sli4_hba.hba_eq = kcalloc(io_channel, |
7793 | sizeof(struct lpfc_queue *), | |
7794 | GFP_KERNEL); | |
67d12733 JS |
7795 | if (!phba->sli4_hba.hba_eq) { |
7796 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7797 | "2576 Failed allocate memory for " | |
7798 | "fast-path EQ record array\n"); | |
7799 | goto out_error; | |
7800 | } | |
7801 | ||
895427bd JS |
7802 | if (phba->cfg_fcp_io_channel) { |
7803 | phba->sli4_hba.fcp_cq = kcalloc(phba->cfg_fcp_io_channel, | |
7804 | sizeof(struct lpfc_queue *), | |
7805 | GFP_KERNEL); | |
7806 | if (!phba->sli4_hba.fcp_cq) { | |
7807 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7808 | "2577 Failed allocate memory for " | |
7809 | "fast-path CQ record array\n"); | |
7810 | goto out_error; | |
7811 | } | |
7812 | phba->sli4_hba.fcp_wq = kcalloc(phba->cfg_fcp_io_channel, | |
7813 | sizeof(struct lpfc_queue *), | |
7814 | GFP_KERNEL); | |
7815 | if (!phba->sli4_hba.fcp_wq) { | |
7816 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7817 | "2578 Failed allocate memory for " | |
7818 | "fast-path FCP WQ record array\n"); | |
7819 | goto out_error; | |
7820 | } | |
7821 | /* | |
7822 | * Since the first EQ can have multiple CQs associated with it, | |
7823 | * this array is used to quickly see if we have a FCP fast-path | |
7824 | * CQ match. | |
7825 | */ | |
7826 | phba->sli4_hba.fcp_cq_map = kcalloc(phba->cfg_fcp_io_channel, | |
7827 | sizeof(uint16_t), | |
7828 | GFP_KERNEL); | |
7829 | if (!phba->sli4_hba.fcp_cq_map) { | |
7830 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7831 | "2545 Failed allocate memory for " | |
7832 | "fast-path CQ map\n"); | |
7833 | goto out_error; | |
7834 | } | |
67d12733 JS |
7835 | } |
7836 | ||
895427bd JS |
7837 | if (phba->cfg_nvme_io_channel) { |
7838 | phba->sli4_hba.nvme_cq = kcalloc(phba->cfg_nvme_io_channel, | |
7839 | sizeof(struct lpfc_queue *), | |
7840 | GFP_KERNEL); | |
7841 | if (!phba->sli4_hba.nvme_cq) { | |
7842 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7843 | "6077 Failed allocate memory for " | |
7844 | "fast-path CQ record array\n"); | |
7845 | goto out_error; | |
7846 | } | |
da0436e9 | 7847 | |
895427bd JS |
7848 | |
7849 | phba->sli4_hba.nvme_wq = kcalloc(phba->cfg_nvme_io_channel, | |
7850 | sizeof(struct lpfc_queue *), | |
7851 | GFP_KERNEL); | |
7852 | if (!phba->sli4_hba.nvme_wq) { | |
7853 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7854 | "2581 Failed allocate memory for " | |
7855 | "fast-path NVME WQ record array\n"); | |
7856 | goto out_error; | |
7857 | } | |
7858 | ||
7859 | /* | |
7860 | * Since the first EQ can have multiple CQs associated with it, | |
7861 | * this array is used to quickly see if we have a NVME fast-path | |
7862 | * CQ match. | |
7863 | */ | |
7864 | phba->sli4_hba.nvme_cq_map = kcalloc(phba->cfg_nvme_io_channel, | |
7865 | sizeof(uint16_t), | |
7866 | GFP_KERNEL); | |
7867 | if (!phba->sli4_hba.nvme_cq_map) { | |
7868 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7869 | "6078 Failed allocate memory for " | |
7870 | "fast-path CQ map\n"); | |
7871 | goto out_error; | |
7872 | } | |
da0436e9 | 7873 | } |
67d12733 | 7874 | |
895427bd | 7875 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); |
67d12733 | 7876 | |
895427bd JS |
7877 | /* Create HBA Event Queues (EQs) */ |
7878 | for (idx = 0; idx < io_channel; idx++) { | |
67d12733 | 7879 | /* Create EQs */ |
da0436e9 JS |
7880 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, |
7881 | phba->sli4_hba.eq_ecount); | |
7882 | if (!qdesc) { | |
7883 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
67d12733 JS |
7884 | "0497 Failed allocate EQ (%d)\n", idx); |
7885 | goto out_error; | |
da0436e9 | 7886 | } |
67d12733 | 7887 | phba->sli4_hba.hba_eq[idx] = qdesc; |
895427bd | 7888 | } |
67d12733 | 7889 | |
895427bd | 7890 | /* FCP and NVME io channels are not required to be balanced */ |
67d12733 | 7891 | |
895427bd JS |
7892 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) |
7893 | if (lpfc_alloc_fcp_wq_cq(phba, idx)) | |
67d12733 | 7894 | goto out_error; |
da0436e9 | 7895 | |
895427bd JS |
7896 | for (idx = 0; idx < phba->cfg_nvme_io_channel; idx++) |
7897 | if (lpfc_alloc_nvme_wq_cq(phba, idx)) | |
7898 | goto out_error; | |
67d12733 | 7899 | |
da0436e9 | 7900 | /* |
67d12733 | 7901 | * Create Slow Path Completion Queues (CQs) |
da0436e9 JS |
7902 | */ |
7903 | ||
da0436e9 JS |
7904 | /* Create slow-path Mailbox Command Complete Queue */ |
7905 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
7906 | phba->sli4_hba.cq_ecount); | |
7907 | if (!qdesc) { | |
7908 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7909 | "0500 Failed allocate slow-path mailbox CQ\n"); | |
67d12733 | 7910 | goto out_error; |
da0436e9 JS |
7911 | } |
7912 | phba->sli4_hba.mbx_cq = qdesc; | |
7913 | ||
7914 | /* Create slow-path ELS Complete Queue */ | |
7915 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
7916 | phba->sli4_hba.cq_ecount); | |
7917 | if (!qdesc) { | |
7918 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7919 | "0501 Failed allocate slow-path ELS CQ\n"); | |
67d12733 | 7920 | goto out_error; |
da0436e9 JS |
7921 | } |
7922 | phba->sli4_hba.els_cq = qdesc; | |
7923 | ||
da0436e9 | 7924 | |
5350d872 | 7925 | /* |
67d12733 | 7926 | * Create Slow Path Work Queues (WQs) |
5350d872 | 7927 | */ |
da0436e9 JS |
7928 | |
7929 | /* Create Mailbox Command Queue */ | |
da0436e9 JS |
7930 | |
7931 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, | |
7932 | phba->sli4_hba.mq_ecount); | |
7933 | if (!qdesc) { | |
7934 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7935 | "0505 Failed allocate slow-path MQ\n"); | |
67d12733 | 7936 | goto out_error; |
da0436e9 JS |
7937 | } |
7938 | phba->sli4_hba.mbx_wq = qdesc; | |
7939 | ||
7940 | /* | |
67d12733 | 7941 | * Create ELS Work Queues |
da0436e9 | 7942 | */ |
da0436e9 JS |
7943 | |
7944 | /* Create slow-path ELS Work Queue */ | |
7945 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
7946 | phba->sli4_hba.wq_ecount); | |
7947 | if (!qdesc) { | |
7948 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7949 | "0504 Failed allocate slow-path ELS WQ\n"); | |
67d12733 | 7950 | goto out_error; |
da0436e9 JS |
7951 | } |
7952 | phba->sli4_hba.els_wq = qdesc; | |
895427bd JS |
7953 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
7954 | ||
7955 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) { | |
7956 | /* Create NVME LS Complete Queue */ | |
7957 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
7958 | phba->sli4_hba.cq_ecount); | |
7959 | if (!qdesc) { | |
7960 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7961 | "6079 Failed allocate NVME LS CQ\n"); | |
7962 | goto out_error; | |
7963 | } | |
7964 | phba->sli4_hba.nvmels_cq = qdesc; | |
7965 | ||
7966 | /* Create NVME LS Work Queue */ | |
7967 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
7968 | phba->sli4_hba.wq_ecount); | |
7969 | if (!qdesc) { | |
7970 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7971 | "6080 Failed allocate NVME LS WQ\n"); | |
7972 | goto out_error; | |
7973 | } | |
7974 | phba->sli4_hba.nvmels_wq = qdesc; | |
7975 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); | |
7976 | } | |
da0436e9 | 7977 | |
da0436e9 JS |
7978 | /* |
7979 | * Create Receive Queue (RQ) | |
7980 | */ | |
da0436e9 JS |
7981 | |
7982 | /* Create Receive Queue for header */ | |
7983 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
7984 | phba->sli4_hba.rq_ecount); | |
7985 | if (!qdesc) { | |
7986 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7987 | "0506 Failed allocate receive HRQ\n"); | |
67d12733 | 7988 | goto out_error; |
da0436e9 JS |
7989 | } |
7990 | phba->sli4_hba.hdr_rq = qdesc; | |
7991 | ||
7992 | /* Create Receive Queue for data */ | |
7993 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
7994 | phba->sli4_hba.rq_ecount); | |
7995 | if (!qdesc) { | |
7996 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7997 | "0507 Failed allocate receive DRQ\n"); | |
67d12733 | 7998 | goto out_error; |
da0436e9 JS |
7999 | } |
8000 | phba->sli4_hba.dat_rq = qdesc; | |
8001 | ||
1ba981fd JS |
8002 | /* Create the Queues needed for Flash Optimized Fabric operations */ |
8003 | if (phba->cfg_fof) | |
8004 | lpfc_fof_queue_create(phba); | |
da0436e9 JS |
8005 | return 0; |
8006 | ||
da0436e9 | 8007 | out_error: |
67d12733 | 8008 | lpfc_sli4_queue_destroy(phba); |
da0436e9 JS |
8009 | return -ENOMEM; |
8010 | } | |
8011 | ||
895427bd JS |
8012 | static inline void |
8013 | __lpfc_sli4_release_queue(struct lpfc_queue **qp) | |
8014 | { | |
8015 | if (*qp != NULL) { | |
8016 | lpfc_sli4_queue_free(*qp); | |
8017 | *qp = NULL; | |
8018 | } | |
8019 | } | |
8020 | ||
8021 | static inline void | |
8022 | lpfc_sli4_release_queues(struct lpfc_queue ***qs, int max) | |
8023 | { | |
8024 | int idx; | |
8025 | ||
8026 | if (*qs == NULL) | |
8027 | return; | |
8028 | ||
8029 | for (idx = 0; idx < max; idx++) | |
8030 | __lpfc_sli4_release_queue(&(*qs)[idx]); | |
8031 | ||
8032 | kfree(*qs); | |
8033 | *qs = NULL; | |
8034 | } | |
8035 | ||
8036 | static inline void | |
8037 | lpfc_sli4_release_queue_map(uint16_t **qmap) | |
8038 | { | |
8039 | if (*qmap != NULL) { | |
8040 | kfree(*qmap); | |
8041 | *qmap = NULL; | |
8042 | } | |
8043 | } | |
8044 | ||
da0436e9 JS |
8045 | /** |
8046 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues | |
8047 | * @phba: pointer to lpfc hba data structure. | |
8048 | * | |
8049 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA | |
8050 | * operation. | |
8051 | * | |
8052 | * Return codes | |
af901ca1 | 8053 | * 0 - successful |
25985edc | 8054 | * -ENOMEM - No available memory |
d439d286 | 8055 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 | 8056 | **/ |
5350d872 | 8057 | void |
da0436e9 JS |
8058 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
8059 | { | |
1ba981fd JS |
8060 | if (phba->cfg_fof) |
8061 | lpfc_fof_queue_destroy(phba); | |
8062 | ||
895427bd JS |
8063 | /* Release HBA eqs */ |
8064 | lpfc_sli4_release_queues(&phba->sli4_hba.hba_eq, phba->io_channel_irqs); | |
8065 | ||
8066 | /* Release FCP cqs */ | |
8067 | lpfc_sli4_release_queues(&phba->sli4_hba.fcp_cq, | |
8068 | phba->cfg_fcp_io_channel); | |
8069 | ||
8070 | /* Release FCP wqs */ | |
8071 | lpfc_sli4_release_queues(&phba->sli4_hba.fcp_wq, | |
8072 | phba->cfg_fcp_io_channel); | |
8073 | ||
8074 | /* Release FCP CQ mapping array */ | |
8075 | lpfc_sli4_release_queue_map(&phba->sli4_hba.fcp_cq_map); | |
8076 | ||
8077 | /* Release NVME cqs */ | |
8078 | lpfc_sli4_release_queues(&phba->sli4_hba.nvme_cq, | |
8079 | phba->cfg_nvme_io_channel); | |
8080 | ||
8081 | /* Release NVME wqs */ | |
8082 | lpfc_sli4_release_queues(&phba->sli4_hba.nvme_wq, | |
8083 | phba->cfg_nvme_io_channel); | |
8084 | ||
8085 | /* Release NVME CQ mapping array */ | |
8086 | lpfc_sli4_release_queue_map(&phba->sli4_hba.nvme_cq_map); | |
8087 | ||
8088 | /* Release mailbox command work queue */ | |
8089 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_wq); | |
8090 | ||
8091 | /* Release ELS work queue */ | |
8092 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_wq); | |
8093 | ||
8094 | /* Release ELS work queue */ | |
8095 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_wq); | |
8096 | ||
8097 | /* Release unsolicited receive queue */ | |
8098 | __lpfc_sli4_release_queue(&phba->sli4_hba.hdr_rq); | |
8099 | __lpfc_sli4_release_queue(&phba->sli4_hba.dat_rq); | |
8100 | ||
8101 | /* Release ELS complete queue */ | |
8102 | __lpfc_sli4_release_queue(&phba->sli4_hba.els_cq); | |
8103 | ||
8104 | /* Release NVME LS complete queue */ | |
8105 | __lpfc_sli4_release_queue(&phba->sli4_hba.nvmels_cq); | |
8106 | ||
8107 | /* Release mailbox command complete queue */ | |
8108 | __lpfc_sli4_release_queue(&phba->sli4_hba.mbx_cq); | |
8109 | ||
8110 | /* Everything on this list has been freed */ | |
8111 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_wq_list); | |
8112 | } | |
8113 | ||
8114 | int | |
8115 | lpfc_post_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *hrq, | |
8116 | struct lpfc_queue *drq, int count) | |
8117 | { | |
8118 | int rc, i; | |
8119 | struct lpfc_rqe hrqe; | |
8120 | struct lpfc_rqe drqe; | |
8121 | struct lpfc_rqb *rqbp; | |
8122 | struct rqb_dmabuf *rqb_buffer; | |
8123 | LIST_HEAD(rqb_buf_list); | |
8124 | ||
8125 | rqbp = hrq->rqbp; | |
8126 | for (i = 0; i < count; i++) { | |
8127 | rqb_buffer = (rqbp->rqb_alloc_buffer)(phba); | |
8128 | if (!rqb_buffer) | |
8129 | break; | |
8130 | rqb_buffer->hrq = hrq; | |
8131 | rqb_buffer->drq = drq; | |
8132 | list_add_tail(&rqb_buffer->hbuf.list, &rqb_buf_list); | |
8133 | } | |
8134 | while (!list_empty(&rqb_buf_list)) { | |
8135 | list_remove_head(&rqb_buf_list, rqb_buffer, struct rqb_dmabuf, | |
8136 | hbuf.list); | |
8137 | ||
8138 | hrqe.address_lo = putPaddrLow(rqb_buffer->hbuf.phys); | |
8139 | hrqe.address_hi = putPaddrHigh(rqb_buffer->hbuf.phys); | |
8140 | drqe.address_lo = putPaddrLow(rqb_buffer->dbuf.phys); | |
8141 | drqe.address_hi = putPaddrHigh(rqb_buffer->dbuf.phys); | |
8142 | rc = lpfc_sli4_rq_put(hrq, drq, &hrqe, &drqe); | |
8143 | if (rc < 0) { | |
8144 | (rqbp->rqb_free_buffer)(phba, rqb_buffer); | |
8145 | } else { | |
8146 | list_add_tail(&rqb_buffer->hbuf.list, | |
8147 | &rqbp->rqb_buffer_list); | |
8148 | rqbp->buffer_count++; | |
67d12733 | 8149 | } |
67d12733 | 8150 | } |
895427bd JS |
8151 | return 1; |
8152 | } | |
67d12733 | 8153 | |
895427bd JS |
8154 | int |
8155 | lpfc_free_rq_buffer(struct lpfc_hba *phba, struct lpfc_queue *rq) | |
8156 | { | |
8157 | struct lpfc_rqb *rqbp; | |
8158 | struct lpfc_dmabuf *h_buf; | |
8159 | struct rqb_dmabuf *rqb_buffer; | |
8160 | ||
8161 | rqbp = rq->rqbp; | |
8162 | while (!list_empty(&rqbp->rqb_buffer_list)) { | |
8163 | list_remove_head(&rqbp->rqb_buffer_list, h_buf, | |
8164 | struct lpfc_dmabuf, list); | |
8165 | ||
8166 | rqb_buffer = container_of(h_buf, struct rqb_dmabuf, hbuf); | |
8167 | (rqbp->rqb_free_buffer)(phba, rqb_buffer); | |
8168 | rqbp->buffer_count--; | |
67d12733 | 8169 | } |
895427bd JS |
8170 | return 1; |
8171 | } | |
67d12733 | 8172 | |
895427bd JS |
8173 | static int |
8174 | lpfc_create_wq_cq(struct lpfc_hba *phba, struct lpfc_queue *eq, | |
8175 | struct lpfc_queue *cq, struct lpfc_queue *wq, uint16_t *cq_map, | |
8176 | int qidx, uint32_t qtype) | |
8177 | { | |
8178 | struct lpfc_sli_ring *pring; | |
8179 | int rc; | |
8180 | ||
8181 | if (!eq || !cq || !wq) { | |
8182 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8183 | "6085 Fast-path %s (%d) not allocated\n", | |
8184 | ((eq) ? ((cq) ? "WQ" : "CQ") : "EQ"), qidx); | |
8185 | return -ENOMEM; | |
8186 | } | |
8187 | ||
8188 | /* create the Cq first */ | |
8189 | rc = lpfc_cq_create(phba, cq, eq, | |
8190 | (qtype == LPFC_MBOX) ? LPFC_MCQ : LPFC_WCQ, qtype); | |
8191 | if (rc) { | |
8192 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8193 | "6086 Failed setup of CQ (%d), rc = 0x%x\n", | |
8194 | qidx, (uint32_t)rc); | |
8195 | return rc; | |
67d12733 JS |
8196 | } |
8197 | ||
895427bd JS |
8198 | if (qtype != LPFC_MBOX) { |
8199 | /* Setup nvme_cq_map for fast lookup */ | |
8200 | if (cq_map) | |
8201 | *cq_map = cq->queue_id; | |
da0436e9 | 8202 | |
895427bd JS |
8203 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
8204 | "6087 CQ setup: cq[%d]-id=%d, parent eq[%d]-id=%d\n", | |
8205 | qidx, cq->queue_id, qidx, eq->queue_id); | |
da0436e9 | 8206 | |
895427bd JS |
8207 | /* create the wq */ |
8208 | rc = lpfc_wq_create(phba, wq, cq, qtype); | |
8209 | if (rc) { | |
8210 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8211 | "6123 Fail setup fastpath WQ (%d), rc = 0x%x\n", | |
8212 | qidx, (uint32_t)rc); | |
8213 | /* no need to tear down cq - caller will do so */ | |
8214 | return rc; | |
8215 | } | |
da0436e9 | 8216 | |
895427bd JS |
8217 | /* Bind this CQ/WQ to the NVME ring */ |
8218 | pring = wq->pring; | |
8219 | pring->sli.sli4.wqp = (void *)wq; | |
8220 | cq->pring = pring; | |
da0436e9 | 8221 | |
895427bd JS |
8222 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
8223 | "2593 WQ setup: wq[%d]-id=%d assoc=%d, cq[%d]-id=%d\n", | |
8224 | qidx, wq->queue_id, wq->assoc_qid, qidx, cq->queue_id); | |
8225 | } else { | |
8226 | rc = lpfc_mq_create(phba, wq, cq, LPFC_MBOX); | |
8227 | if (rc) { | |
8228 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8229 | "0539 Failed setup of slow-path MQ: " | |
8230 | "rc = 0x%x\n", rc); | |
8231 | /* no need to tear down cq - caller will do so */ | |
8232 | return rc; | |
8233 | } | |
da0436e9 | 8234 | |
895427bd JS |
8235 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
8236 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", | |
8237 | phba->sli4_hba.mbx_wq->queue_id, | |
8238 | phba->sli4_hba.mbx_cq->queue_id); | |
67d12733 | 8239 | } |
da0436e9 | 8240 | |
895427bd | 8241 | return 0; |
da0436e9 JS |
8242 | } |
8243 | ||
8244 | /** | |
8245 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues | |
8246 | * @phba: pointer to lpfc hba data structure. | |
8247 | * | |
8248 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA | |
8249 | * operation. | |
8250 | * | |
8251 | * Return codes | |
af901ca1 | 8252 | * 0 - successful |
25985edc | 8253 | * -ENOMEM - No available memory |
d439d286 | 8254 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
8255 | **/ |
8256 | int | |
8257 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) | |
8258 | { | |
962bc51b JS |
8259 | uint32_t shdr_status, shdr_add_status; |
8260 | union lpfc_sli4_cfg_shdr *shdr; | |
8261 | LPFC_MBOXQ_t *mboxq; | |
895427bd JS |
8262 | int qidx; |
8263 | uint32_t length, io_channel; | |
8264 | int rc = -ENOMEM; | |
962bc51b JS |
8265 | |
8266 | /* Check for dual-ULP support */ | |
8267 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
8268 | if (!mboxq) { | |
8269 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8270 | "3249 Unable to allocate memory for " | |
8271 | "QUERY_FW_CFG mailbox command\n"); | |
8272 | return -ENOMEM; | |
8273 | } | |
8274 | length = (sizeof(struct lpfc_mbx_query_fw_config) - | |
8275 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
8276 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
8277 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, | |
8278 | length, LPFC_SLI4_MBX_EMBED); | |
8279 | ||
8280 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
8281 | ||
8282 | shdr = (union lpfc_sli4_cfg_shdr *) | |
8283 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
8284 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
8285 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
8286 | if (shdr_status || shdr_add_status || rc) { | |
8287 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8288 | "3250 QUERY_FW_CFG mailbox failed with status " | |
8289 | "x%x add_status x%x, mbx status x%x\n", | |
8290 | shdr_status, shdr_add_status, rc); | |
8291 | if (rc != MBX_TIMEOUT) | |
8292 | mempool_free(mboxq, phba->mbox_mem_pool); | |
8293 | rc = -ENXIO; | |
8294 | goto out_error; | |
8295 | } | |
8296 | ||
8297 | phba->sli4_hba.fw_func_mode = | |
8298 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; | |
8299 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; | |
8300 | phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode; | |
8b017a30 JS |
8301 | phba->sli4_hba.physical_port = |
8302 | mboxq->u.mqe.un.query_fw_cfg.rsp.physical_port; | |
962bc51b JS |
8303 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
8304 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " | |
8305 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, | |
8306 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); | |
8307 | ||
8308 | if (rc != MBX_TIMEOUT) | |
8309 | mempool_free(mboxq, phba->mbox_mem_pool); | |
da0436e9 JS |
8310 | |
8311 | /* | |
67d12733 | 8312 | * Set up HBA Event Queues (EQs) |
da0436e9 | 8313 | */ |
895427bd | 8314 | io_channel = phba->io_channel_irqs; |
da0436e9 | 8315 | |
67d12733 | 8316 | /* Set up HBA event queue */ |
895427bd | 8317 | if (io_channel && !phba->sli4_hba.hba_eq) { |
2e90f4b5 JS |
8318 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
8319 | "3147 Fast-path EQs not allocated\n"); | |
1b51197d | 8320 | rc = -ENOMEM; |
67d12733 | 8321 | goto out_error; |
2e90f4b5 | 8322 | } |
895427bd JS |
8323 | for (qidx = 0; qidx < io_channel; qidx++) { |
8324 | if (!phba->sli4_hba.hba_eq[qidx]) { | |
da0436e9 JS |
8325 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
8326 | "0522 Fast-path EQ (%d) not " | |
895427bd | 8327 | "allocated\n", qidx); |
1b51197d | 8328 | rc = -ENOMEM; |
895427bd | 8329 | goto out_destroy; |
da0436e9 | 8330 | } |
895427bd JS |
8331 | rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[qidx], |
8332 | phba->cfg_fcp_imax); | |
da0436e9 JS |
8333 | if (rc) { |
8334 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8335 | "0523 Failed setup of fast-path EQ " | |
895427bd | 8336 | "(%d), rc = 0x%x\n", qidx, |
a2fc4aef | 8337 | (uint32_t)rc); |
895427bd | 8338 | goto out_destroy; |
da0436e9 JS |
8339 | } |
8340 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
895427bd JS |
8341 | "2584 HBA EQ setup: queue[%d]-id=%d\n", |
8342 | qidx, phba->sli4_hba.hba_eq[qidx]->queue_id); | |
67d12733 JS |
8343 | } |
8344 | ||
895427bd JS |
8345 | if (phba->cfg_nvme_io_channel) { |
8346 | if (!phba->sli4_hba.nvme_cq || !phba->sli4_hba.nvme_wq) { | |
67d12733 | 8347 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
895427bd JS |
8348 | "6084 Fast-path NVME %s array not allocated\n", |
8349 | (phba->sli4_hba.nvme_cq) ? "CQ" : "WQ"); | |
67d12733 | 8350 | rc = -ENOMEM; |
895427bd | 8351 | goto out_destroy; |
67d12733 JS |
8352 | } |
8353 | ||
895427bd JS |
8354 | for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) { |
8355 | rc = lpfc_create_wq_cq(phba, | |
8356 | phba->sli4_hba.hba_eq[ | |
8357 | qidx % io_channel], | |
8358 | phba->sli4_hba.nvme_cq[qidx], | |
8359 | phba->sli4_hba.nvme_wq[qidx], | |
8360 | &phba->sli4_hba.nvme_cq_map[qidx], | |
8361 | qidx, LPFC_NVME); | |
8362 | if (rc) { | |
8363 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8364 | "6123 Failed to setup fastpath " | |
8365 | "NVME WQ/CQ (%d), rc = 0x%x\n", | |
8366 | qidx, (uint32_t)rc); | |
8367 | goto out_destroy; | |
8368 | } | |
8369 | } | |
67d12733 JS |
8370 | } |
8371 | ||
895427bd JS |
8372 | if (phba->cfg_fcp_io_channel) { |
8373 | /* Set up fast-path FCP Response Complete Queue */ | |
8374 | if (!phba->sli4_hba.fcp_cq || !phba->sli4_hba.fcp_wq) { | |
67d12733 | 8375 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
895427bd JS |
8376 | "3148 Fast-path FCP %s array not allocated\n", |
8377 | phba->sli4_hba.fcp_cq ? "WQ" : "CQ"); | |
67d12733 | 8378 | rc = -ENOMEM; |
895427bd | 8379 | goto out_destroy; |
67d12733 JS |
8380 | } |
8381 | ||
895427bd JS |
8382 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) { |
8383 | rc = lpfc_create_wq_cq(phba, | |
8384 | phba->sli4_hba.hba_eq[ | |
8385 | qidx % io_channel], | |
8386 | phba->sli4_hba.fcp_cq[qidx], | |
8387 | phba->sli4_hba.fcp_wq[qidx], | |
8388 | &phba->sli4_hba.fcp_cq_map[qidx], | |
8389 | qidx, LPFC_FCP); | |
8390 | if (rc) { | |
8391 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8392 | "0535 Failed to setup fastpath " | |
8393 | "FCP WQ/CQ (%d), rc = 0x%x\n", | |
8394 | qidx, (uint32_t)rc); | |
8395 | goto out_destroy; | |
8396 | } | |
8397 | } | |
67d12733 | 8398 | } |
895427bd | 8399 | |
da0436e9 | 8400 | /* |
895427bd | 8401 | * Set up Slow Path Complete Queues (CQs) |
da0436e9 JS |
8402 | */ |
8403 | ||
895427bd | 8404 | /* Set up slow-path MBOX CQ/MQ */ |
da0436e9 | 8405 | |
895427bd | 8406 | if (!phba->sli4_hba.mbx_cq || !phba->sli4_hba.mbx_wq) { |
da0436e9 | 8407 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
895427bd JS |
8408 | "0528 %s not allocated\n", |
8409 | phba->sli4_hba.mbx_cq ? | |
8410 | "Mailbox WQ" : "Mailbox CQ"); | |
1b51197d | 8411 | rc = -ENOMEM; |
895427bd | 8412 | goto out_destroy; |
da0436e9 | 8413 | } |
da0436e9 | 8414 | |
895427bd JS |
8415 | rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0], |
8416 | phba->sli4_hba.mbx_cq, | |
8417 | phba->sli4_hba.mbx_wq, | |
8418 | NULL, 0, LPFC_MBOX); | |
da0436e9 JS |
8419 | if (rc) { |
8420 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
895427bd JS |
8421 | "0529 Failed setup of mailbox WQ/CQ: rc = 0x%x\n", |
8422 | (uint32_t)rc); | |
8423 | goto out_destroy; | |
da0436e9 | 8424 | } |
da0436e9 | 8425 | |
895427bd JS |
8426 | /* Set up slow-path ELS WQ/CQ */ |
8427 | if (!phba->sli4_hba.els_cq || !phba->sli4_hba.els_wq) { | |
da0436e9 | 8428 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
895427bd JS |
8429 | "0530 ELS %s not allocated\n", |
8430 | phba->sli4_hba.els_cq ? "WQ" : "CQ"); | |
1b51197d | 8431 | rc = -ENOMEM; |
895427bd | 8432 | goto out_destroy; |
da0436e9 | 8433 | } |
895427bd JS |
8434 | rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0], |
8435 | phba->sli4_hba.els_cq, | |
8436 | phba->sli4_hba.els_wq, | |
8437 | NULL, 0, LPFC_ELS); | |
da0436e9 JS |
8438 | if (rc) { |
8439 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
895427bd JS |
8440 | "0529 Failed setup of ELS WQ/CQ: rc = 0x%x\n", |
8441 | (uint32_t)rc); | |
8442 | goto out_destroy; | |
da0436e9 JS |
8443 | } |
8444 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8445 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", | |
8446 | phba->sli4_hba.els_wq->queue_id, | |
8447 | phba->sli4_hba.els_cq->queue_id); | |
8448 | ||
895427bd JS |
8449 | if (phba->cfg_nvme_io_channel) { |
8450 | /* Set up NVME LS Complete Queue */ | |
8451 | if (!phba->sli4_hba.nvmels_cq || !phba->sli4_hba.nvmels_wq) { | |
8452 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8453 | "6091 LS %s not allocated\n", | |
8454 | phba->sli4_hba.nvmels_cq ? "WQ" : "CQ"); | |
8455 | rc = -ENOMEM; | |
8456 | goto out_destroy; | |
8457 | } | |
8458 | rc = lpfc_create_wq_cq(phba, phba->sli4_hba.hba_eq[0], | |
8459 | phba->sli4_hba.nvmels_cq, | |
8460 | phba->sli4_hba.nvmels_wq, | |
8461 | NULL, 0, LPFC_NVME_LS); | |
8462 | if (rc) { | |
8463 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8464 | "0529 Failed setup of NVVME LS WQ/CQ: " | |
8465 | "rc = 0x%x\n", (uint32_t)rc); | |
8466 | goto out_destroy; | |
8467 | } | |
8468 | ||
8469 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8470 | "6096 ELS WQ setup: wq-id=%d, " | |
8471 | "parent cq-id=%d\n", | |
8472 | phba->sli4_hba.nvmels_wq->queue_id, | |
8473 | phba->sli4_hba.nvmels_cq->queue_id); | |
8474 | } | |
8475 | ||
da0436e9 JS |
8476 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { |
8477 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8478 | "0540 Receive Queue not allocated\n"); | |
1b51197d | 8479 | rc = -ENOMEM; |
895427bd | 8480 | goto out_destroy; |
da0436e9 | 8481 | } |
73d91e50 JS |
8482 | |
8483 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ); | |
8484 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ); | |
8485 | ||
da0436e9 | 8486 | rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, |
4d9ab994 | 8487 | phba->sli4_hba.els_cq, LPFC_USOL); |
da0436e9 JS |
8488 | if (rc) { |
8489 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8490 | "0541 Failed setup of Receive Queue: " | |
a2fc4aef | 8491 | "rc = 0x%x\n", (uint32_t)rc); |
895427bd | 8492 | goto out_destroy; |
da0436e9 | 8493 | } |
73d91e50 | 8494 | |
da0436e9 JS |
8495 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
8496 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " | |
8497 | "parent cq-id=%d\n", | |
8498 | phba->sli4_hba.hdr_rq->queue_id, | |
8499 | phba->sli4_hba.dat_rq->queue_id, | |
4d9ab994 | 8500 | phba->sli4_hba.els_cq->queue_id); |
1ba981fd JS |
8501 | |
8502 | if (phba->cfg_fof) { | |
8503 | rc = lpfc_fof_queue_setup(phba); | |
8504 | if (rc) { | |
8505 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8506 | "0549 Failed setup of FOF Queues: " | |
8507 | "rc = 0x%x\n", rc); | |
895427bd | 8508 | goto out_destroy; |
1ba981fd JS |
8509 | } |
8510 | } | |
2c9c5a00 JS |
8511 | |
8512 | /* | |
8513 | * Configure EQ delay multipier for interrupt coalescing using | |
8514 | * MODIFY_EQ_DELAY for all EQs created, LPFC_MAX_EQ_DELAY at a time. | |
8515 | */ | |
895427bd JS |
8516 | for (qidx = 0; qidx < io_channel; qidx += LPFC_MAX_EQ_DELAY) |
8517 | lpfc_modify_hba_eq_delay(phba, qidx); | |
da0436e9 JS |
8518 | return 0; |
8519 | ||
895427bd JS |
8520 | out_destroy: |
8521 | lpfc_sli4_queue_unset(phba); | |
da0436e9 JS |
8522 | out_error: |
8523 | return rc; | |
8524 | } | |
8525 | ||
8526 | /** | |
8527 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues | |
8528 | * @phba: pointer to lpfc hba data structure. | |
8529 | * | |
8530 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA | |
8531 | * operation. | |
8532 | * | |
8533 | * Return codes | |
af901ca1 | 8534 | * 0 - successful |
25985edc | 8535 | * -ENOMEM - No available memory |
d439d286 | 8536 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
8537 | **/ |
8538 | void | |
8539 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) | |
8540 | { | |
895427bd | 8541 | int qidx; |
da0436e9 | 8542 | |
1ba981fd JS |
8543 | /* Unset the queues created for Flash Optimized Fabric operations */ |
8544 | if (phba->cfg_fof) | |
8545 | lpfc_fof_queue_destroy(phba); | |
895427bd | 8546 | |
da0436e9 | 8547 | /* Unset mailbox command work queue */ |
895427bd JS |
8548 | if (phba->sli4_hba.mbx_wq) |
8549 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | |
8550 | ||
8551 | /* Unset NVME LS work queue */ | |
8552 | if (phba->sli4_hba.nvmels_wq) | |
8553 | lpfc_wq_destroy(phba, phba->sli4_hba.nvmels_wq); | |
8554 | ||
da0436e9 | 8555 | /* Unset ELS work queue */ |
895427bd JS |
8556 | if (phba->sli4_hba.els_cq) |
8557 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); | |
8558 | ||
da0436e9 | 8559 | /* Unset unsolicited receive queue */ |
895427bd JS |
8560 | if (phba->sli4_hba.hdr_rq) |
8561 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, | |
8562 | phba->sli4_hba.dat_rq); | |
8563 | ||
da0436e9 | 8564 | /* Unset FCP work queue */ |
895427bd JS |
8565 | if (phba->sli4_hba.fcp_wq) |
8566 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) | |
8567 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[qidx]); | |
8568 | ||
8569 | /* Unset NVME work queue */ | |
8570 | if (phba->sli4_hba.nvme_wq) { | |
8571 | for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) | |
8572 | lpfc_wq_destroy(phba, phba->sli4_hba.nvme_wq[qidx]); | |
67d12733 | 8573 | } |
895427bd | 8574 | |
da0436e9 | 8575 | /* Unset mailbox command complete queue */ |
895427bd JS |
8576 | if (phba->sli4_hba.mbx_cq) |
8577 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | |
8578 | ||
da0436e9 | 8579 | /* Unset ELS complete queue */ |
895427bd JS |
8580 | if (phba->sli4_hba.els_cq) |
8581 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); | |
8582 | ||
8583 | /* Unset NVME LS complete queue */ | |
8584 | if (phba->sli4_hba.nvmels_cq) | |
8585 | lpfc_cq_destroy(phba, phba->sli4_hba.nvmels_cq); | |
8586 | ||
8587 | /* Unset NVME response complete queue */ | |
8588 | if (phba->sli4_hba.nvme_cq) | |
8589 | for (qidx = 0; qidx < phba->cfg_nvme_io_channel; qidx++) | |
8590 | lpfc_cq_destroy(phba, phba->sli4_hba.nvme_cq[qidx]); | |
8591 | ||
da0436e9 | 8592 | /* Unset FCP response complete queue */ |
895427bd JS |
8593 | if (phba->sli4_hba.fcp_cq) |
8594 | for (qidx = 0; qidx < phba->cfg_fcp_io_channel; qidx++) | |
8595 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[qidx]); | |
8596 | ||
da0436e9 | 8597 | /* Unset fast-path event queue */ |
895427bd JS |
8598 | if (phba->sli4_hba.hba_eq) |
8599 | for (qidx = 0; qidx < phba->io_channel_irqs; qidx++) | |
8600 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[qidx]); | |
da0436e9 JS |
8601 | } |
8602 | ||
8603 | /** | |
8604 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool | |
8605 | * @phba: pointer to lpfc hba data structure. | |
8606 | * | |
8607 | * This routine is invoked to allocate and set up a pool of completion queue | |
8608 | * events. The body of the completion queue event is a completion queue entry | |
8609 | * CQE. For now, this pool is used for the interrupt service routine to queue | |
8610 | * the following HBA completion queue events for the worker thread to process: | |
8611 | * - Mailbox asynchronous events | |
8612 | * - Receive queue completion unsolicited events | |
8613 | * Later, this can be used for all the slow-path events. | |
8614 | * | |
8615 | * Return codes | |
af901ca1 | 8616 | * 0 - successful |
25985edc | 8617 | * -ENOMEM - No available memory |
da0436e9 JS |
8618 | **/ |
8619 | static int | |
8620 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) | |
8621 | { | |
8622 | struct lpfc_cq_event *cq_event; | |
8623 | int i; | |
8624 | ||
8625 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { | |
8626 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); | |
8627 | if (!cq_event) | |
8628 | goto out_pool_create_fail; | |
8629 | list_add_tail(&cq_event->list, | |
8630 | &phba->sli4_hba.sp_cqe_event_pool); | |
8631 | } | |
8632 | return 0; | |
8633 | ||
8634 | out_pool_create_fail: | |
8635 | lpfc_sli4_cq_event_pool_destroy(phba); | |
8636 | return -ENOMEM; | |
8637 | } | |
8638 | ||
8639 | /** | |
8640 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool | |
8641 | * @phba: pointer to lpfc hba data structure. | |
8642 | * | |
8643 | * This routine is invoked to free the pool of completion queue events at | |
8644 | * driver unload time. Note that, it is the responsibility of the driver | |
8645 | * cleanup routine to free all the outstanding completion-queue events | |
8646 | * allocated from this pool back into the pool before invoking this routine | |
8647 | * to destroy the pool. | |
8648 | **/ | |
8649 | static void | |
8650 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) | |
8651 | { | |
8652 | struct lpfc_cq_event *cq_event, *next_cq_event; | |
8653 | ||
8654 | list_for_each_entry_safe(cq_event, next_cq_event, | |
8655 | &phba->sli4_hba.sp_cqe_event_pool, list) { | |
8656 | list_del(&cq_event->list); | |
8657 | kfree(cq_event); | |
8658 | } | |
8659 | } | |
8660 | ||
8661 | /** | |
8662 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
8663 | * @phba: pointer to lpfc hba data structure. | |
8664 | * | |
8665 | * This routine is the lock free version of the API invoked to allocate a | |
8666 | * completion-queue event from the free pool. | |
8667 | * | |
8668 | * Return: Pointer to the newly allocated completion-queue event if successful | |
8669 | * NULL otherwise. | |
8670 | **/ | |
8671 | struct lpfc_cq_event * | |
8672 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
8673 | { | |
8674 | struct lpfc_cq_event *cq_event = NULL; | |
8675 | ||
8676 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, | |
8677 | struct lpfc_cq_event, list); | |
8678 | return cq_event; | |
8679 | } | |
8680 | ||
8681 | /** | |
8682 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
8683 | * @phba: pointer to lpfc hba data structure. | |
8684 | * | |
8685 | * This routine is the lock version of the API invoked to allocate a | |
8686 | * completion-queue event from the free pool. | |
8687 | * | |
8688 | * Return: Pointer to the newly allocated completion-queue event if successful | |
8689 | * NULL otherwise. | |
8690 | **/ | |
8691 | struct lpfc_cq_event * | |
8692 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
8693 | { | |
8694 | struct lpfc_cq_event *cq_event; | |
8695 | unsigned long iflags; | |
8696 | ||
8697 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8698 | cq_event = __lpfc_sli4_cq_event_alloc(phba); | |
8699 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8700 | return cq_event; | |
8701 | } | |
8702 | ||
8703 | /** | |
8704 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
8705 | * @phba: pointer to lpfc hba data structure. | |
8706 | * @cq_event: pointer to the completion queue event to be freed. | |
8707 | * | |
8708 | * This routine is the lock free version of the API invoked to release a | |
8709 | * completion-queue event back into the free pool. | |
8710 | **/ | |
8711 | void | |
8712 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
8713 | struct lpfc_cq_event *cq_event) | |
8714 | { | |
8715 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); | |
8716 | } | |
8717 | ||
8718 | /** | |
8719 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
8720 | * @phba: pointer to lpfc hba data structure. | |
8721 | * @cq_event: pointer to the completion queue event to be freed. | |
8722 | * | |
8723 | * This routine is the lock version of the API invoked to release a | |
8724 | * completion-queue event back into the free pool. | |
8725 | **/ | |
8726 | void | |
8727 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
8728 | struct lpfc_cq_event *cq_event) | |
8729 | { | |
8730 | unsigned long iflags; | |
8731 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8732 | __lpfc_sli4_cq_event_release(phba, cq_event); | |
8733 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8734 | } | |
8735 | ||
8736 | /** | |
8737 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool | |
8738 | * @phba: pointer to lpfc hba data structure. | |
8739 | * | |
8740 | * This routine is to free all the pending completion-queue events to the | |
8741 | * back into the free pool for device reset. | |
8742 | **/ | |
8743 | static void | |
8744 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) | |
8745 | { | |
8746 | LIST_HEAD(cqelist); | |
8747 | struct lpfc_cq_event *cqe; | |
8748 | unsigned long iflags; | |
8749 | ||
8750 | /* Retrieve all the pending WCQEs from pending WCQE lists */ | |
8751 | spin_lock_irqsave(&phba->hbalock, iflags); | |
8752 | /* Pending FCP XRI abort events */ | |
8753 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
8754 | &cqelist); | |
8755 | /* Pending ELS XRI abort events */ | |
8756 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
8757 | &cqelist); | |
8758 | /* Pending asynnc events */ | |
8759 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, | |
8760 | &cqelist); | |
8761 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
8762 | ||
8763 | while (!list_empty(&cqelist)) { | |
8764 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); | |
8765 | lpfc_sli4_cq_event_release(phba, cqe); | |
8766 | } | |
8767 | } | |
8768 | ||
8769 | /** | |
8770 | * lpfc_pci_function_reset - Reset pci function. | |
8771 | * @phba: pointer to lpfc hba data structure. | |
8772 | * | |
8773 | * This routine is invoked to request a PCI function reset. It will destroys | |
8774 | * all resources assigned to the PCI function which originates this request. | |
8775 | * | |
8776 | * Return codes | |
af901ca1 | 8777 | * 0 - successful |
25985edc | 8778 | * -ENOMEM - No available memory |
d439d286 | 8779 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
8780 | **/ |
8781 | int | |
8782 | lpfc_pci_function_reset(struct lpfc_hba *phba) | |
8783 | { | |
8784 | LPFC_MBOXQ_t *mboxq; | |
2fcee4bf | 8785 | uint32_t rc = 0, if_type; |
da0436e9 | 8786 | uint32_t shdr_status, shdr_add_status; |
2f6fa2c9 JS |
8787 | uint32_t rdy_chk; |
8788 | uint32_t port_reset = 0; | |
da0436e9 | 8789 | union lpfc_sli4_cfg_shdr *shdr; |
2fcee4bf | 8790 | struct lpfc_register reg_data; |
2b81f942 | 8791 | uint16_t devid; |
da0436e9 | 8792 | |
2fcee4bf JS |
8793 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
8794 | switch (if_type) { | |
8795 | case LPFC_SLI_INTF_IF_TYPE_0: | |
8796 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, | |
8797 | GFP_KERNEL); | |
8798 | if (!mboxq) { | |
8799 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8800 | "0494 Unable to allocate memory for " | |
8801 | "issuing SLI_FUNCTION_RESET mailbox " | |
8802 | "command\n"); | |
8803 | return -ENOMEM; | |
8804 | } | |
da0436e9 | 8805 | |
2fcee4bf JS |
8806 | /* Setup PCI function reset mailbox-ioctl command */ |
8807 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
8808 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, | |
8809 | LPFC_SLI4_MBX_EMBED); | |
8810 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
8811 | shdr = (union lpfc_sli4_cfg_shdr *) | |
8812 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
8813 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
8814 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
8815 | &shdr->response); | |
8816 | if (rc != MBX_TIMEOUT) | |
8817 | mempool_free(mboxq, phba->mbox_mem_pool); | |
8818 | if (shdr_status || shdr_add_status || rc) { | |
8819 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8820 | "0495 SLI_FUNCTION_RESET mailbox " | |
8821 | "failed with status x%x add_status x%x," | |
8822 | " mbx status x%x\n", | |
8823 | shdr_status, shdr_add_status, rc); | |
8824 | rc = -ENXIO; | |
8825 | } | |
8826 | break; | |
8827 | case LPFC_SLI_INTF_IF_TYPE_2: | |
2f6fa2c9 JS |
8828 | wait: |
8829 | /* | |
8830 | * Poll the Port Status Register and wait for RDY for | |
8831 | * up to 30 seconds. If the port doesn't respond, treat | |
8832 | * it as an error. | |
8833 | */ | |
77d093fb | 8834 | for (rdy_chk = 0; rdy_chk < 1500; rdy_chk++) { |
2f6fa2c9 JS |
8835 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
8836 | STATUSregaddr, ®_data.word0)) { | |
8837 | rc = -ENODEV; | |
8838 | goto out; | |
8839 | } | |
8840 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) | |
8841 | break; | |
8842 | msleep(20); | |
8843 | } | |
8844 | ||
8845 | if (!bf_get(lpfc_sliport_status_rdy, ®_data)) { | |
8846 | phba->work_status[0] = readl( | |
8847 | phba->sli4_hba.u.if_type2.ERR1regaddr); | |
8848 | phba->work_status[1] = readl( | |
8849 | phba->sli4_hba.u.if_type2.ERR2regaddr); | |
8850 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8851 | "2890 Port not ready, port status reg " | |
8852 | "0x%x error 1=0x%x, error 2=0x%x\n", | |
8853 | reg_data.word0, | |
8854 | phba->work_status[0], | |
8855 | phba->work_status[1]); | |
8856 | rc = -ENODEV; | |
8857 | goto out; | |
8858 | } | |
8859 | ||
8860 | if (!port_reset) { | |
8861 | /* | |
8862 | * Reset the port now | |
8863 | */ | |
2fcee4bf JS |
8864 | reg_data.word0 = 0; |
8865 | bf_set(lpfc_sliport_ctrl_end, ®_data, | |
8866 | LPFC_SLIPORT_LITTLE_ENDIAN); | |
8867 | bf_set(lpfc_sliport_ctrl_ip, ®_data, | |
8868 | LPFC_SLIPORT_INIT_PORT); | |
8869 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. | |
8870 | CTRLregaddr); | |
8fcb8acd | 8871 | /* flush */ |
2b81f942 JS |
8872 | pci_read_config_word(phba->pcidev, |
8873 | PCI_DEVICE_ID, &devid); | |
2fcee4bf | 8874 | |
2f6fa2c9 JS |
8875 | port_reset = 1; |
8876 | msleep(20); | |
8877 | goto wait; | |
8878 | } else if (bf_get(lpfc_sliport_status_rn, ®_data)) { | |
8879 | rc = -ENODEV; | |
8880 | goto out; | |
2fcee4bf JS |
8881 | } |
8882 | break; | |
2f6fa2c9 | 8883 | |
2fcee4bf JS |
8884 | case LPFC_SLI_INTF_IF_TYPE_1: |
8885 | default: | |
8886 | break; | |
da0436e9 | 8887 | } |
2fcee4bf | 8888 | |
73d91e50 | 8889 | out: |
2fcee4bf | 8890 | /* Catch the not-ready port failure after a port reset. */ |
2f6fa2c9 | 8891 | if (rc) { |
229adb0e JS |
8892 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
8893 | "3317 HBA not functional: IP Reset Failed " | |
2f6fa2c9 | 8894 | "try: echo fw_reset > board_mode\n"); |
2fcee4bf | 8895 | rc = -ENODEV; |
229adb0e | 8896 | } |
2fcee4bf | 8897 | |
da0436e9 JS |
8898 | return rc; |
8899 | } | |
8900 | ||
da0436e9 JS |
8901 | /** |
8902 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. | |
8903 | * @phba: pointer to lpfc hba data structure. | |
8904 | * | |
8905 | * This routine is invoked to set up the PCI device memory space for device | |
8906 | * with SLI-4 interface spec. | |
8907 | * | |
8908 | * Return codes | |
af901ca1 | 8909 | * 0 - successful |
da0436e9 JS |
8910 | * other values - error |
8911 | **/ | |
8912 | static int | |
8913 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) | |
8914 | { | |
8915 | struct pci_dev *pdev; | |
8916 | unsigned long bar0map_len, bar1map_len, bar2map_len; | |
8917 | int error = -ENODEV; | |
2fcee4bf | 8918 | uint32_t if_type; |
da0436e9 JS |
8919 | |
8920 | /* Obtain PCI device reference */ | |
8921 | if (!phba->pcidev) | |
8922 | return error; | |
8923 | else | |
8924 | pdev = phba->pcidev; | |
8925 | ||
8926 | /* Set the device DMA mask size */ | |
8e68597d MR |
8927 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
8928 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
8929 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
8930 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
da0436e9 | 8931 | return error; |
8e68597d MR |
8932 | } |
8933 | } | |
da0436e9 | 8934 | |
2fcee4bf JS |
8935 | /* |
8936 | * The BARs and register set definitions and offset locations are | |
8937 | * dependent on the if_type. | |
8938 | */ | |
8939 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, | |
8940 | &phba->sli4_hba.sli_intf.word0)) { | |
8941 | return error; | |
8942 | } | |
8943 | ||
8944 | /* There is no SLI3 failback for SLI4 devices. */ | |
8945 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != | |
8946 | LPFC_SLI_INTF_VALID) { | |
8947 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8948 | "2894 SLI_INTF reg contents invalid " | |
8949 | "sli_intf reg 0x%x\n", | |
8950 | phba->sli4_hba.sli_intf.word0); | |
8951 | return error; | |
8952 | } | |
8953 | ||
8954 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); | |
8955 | /* | |
8956 | * Get the bus address of SLI4 device Bar regions and the | |
8957 | * number of bytes required by each mapping. The mapping of the | |
8958 | * particular PCI BARs regions is dependent on the type of | |
8959 | * SLI4 device. | |
da0436e9 | 8960 | */ |
f5ca6f2e JS |
8961 | if (pci_resource_start(pdev, PCI_64BIT_BAR0)) { |
8962 | phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0); | |
8963 | bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); | |
2fcee4bf JS |
8964 | |
8965 | /* | |
8966 | * Map SLI4 PCI Config Space Register base to a kernel virtual | |
8967 | * addr | |
8968 | */ | |
8969 | phba->sli4_hba.conf_regs_memmap_p = | |
8970 | ioremap(phba->pci_bar0_map, bar0map_len); | |
8971 | if (!phba->sli4_hba.conf_regs_memmap_p) { | |
8972 | dev_printk(KERN_ERR, &pdev->dev, | |
8973 | "ioremap failed for SLI4 PCI config " | |
8974 | "registers.\n"); | |
8975 | goto out; | |
8976 | } | |
f5ca6f2e | 8977 | phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; |
2fcee4bf JS |
8978 | /* Set up BAR0 PCI config space register memory map */ |
8979 | lpfc_sli4_bar0_register_memmap(phba, if_type); | |
1dfb5a47 JS |
8980 | } else { |
8981 | phba->pci_bar0_map = pci_resource_start(pdev, 1); | |
8982 | bar0map_len = pci_resource_len(pdev, 1); | |
2fcee4bf JS |
8983 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
8984 | dev_printk(KERN_ERR, &pdev->dev, | |
8985 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); | |
8986 | goto out; | |
8987 | } | |
8988 | phba->sli4_hba.conf_regs_memmap_p = | |
da0436e9 | 8989 | ioremap(phba->pci_bar0_map, bar0map_len); |
2fcee4bf JS |
8990 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
8991 | dev_printk(KERN_ERR, &pdev->dev, | |
8992 | "ioremap failed for SLI4 PCI config " | |
8993 | "registers.\n"); | |
8994 | goto out; | |
8995 | } | |
8996 | lpfc_sli4_bar0_register_memmap(phba, if_type); | |
da0436e9 JS |
8997 | } |
8998 | ||
c31098ce | 8999 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
f5ca6f2e | 9000 | (pci_resource_start(pdev, PCI_64BIT_BAR2))) { |
2fcee4bf JS |
9001 | /* |
9002 | * Map SLI4 if type 0 HBA Control Register base to a kernel | |
9003 | * virtual address and setup the registers. | |
9004 | */ | |
f5ca6f2e JS |
9005 | phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2); |
9006 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); | |
2fcee4bf | 9007 | phba->sli4_hba.ctrl_regs_memmap_p = |
da0436e9 | 9008 | ioremap(phba->pci_bar1_map, bar1map_len); |
2fcee4bf JS |
9009 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
9010 | dev_printk(KERN_ERR, &pdev->dev, | |
da0436e9 | 9011 | "ioremap failed for SLI4 HBA control registers.\n"); |
2fcee4bf JS |
9012 | goto out_iounmap_conf; |
9013 | } | |
f5ca6f2e | 9014 | phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p; |
2fcee4bf | 9015 | lpfc_sli4_bar1_register_memmap(phba); |
da0436e9 JS |
9016 | } |
9017 | ||
c31098ce | 9018 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
f5ca6f2e | 9019 | (pci_resource_start(pdev, PCI_64BIT_BAR4))) { |
2fcee4bf JS |
9020 | /* |
9021 | * Map SLI4 if type 0 HBA Doorbell Register base to a kernel | |
9022 | * virtual address and setup the registers. | |
9023 | */ | |
f5ca6f2e JS |
9024 | phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4); |
9025 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); | |
2fcee4bf | 9026 | phba->sli4_hba.drbl_regs_memmap_p = |
da0436e9 | 9027 | ioremap(phba->pci_bar2_map, bar2map_len); |
2fcee4bf JS |
9028 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
9029 | dev_printk(KERN_ERR, &pdev->dev, | |
da0436e9 | 9030 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
2fcee4bf JS |
9031 | goto out_iounmap_ctrl; |
9032 | } | |
f5ca6f2e | 9033 | phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; |
2fcee4bf JS |
9034 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
9035 | if (error) | |
9036 | goto out_iounmap_all; | |
da0436e9 JS |
9037 | } |
9038 | ||
da0436e9 JS |
9039 | return 0; |
9040 | ||
9041 | out_iounmap_all: | |
9042 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
9043 | out_iounmap_ctrl: | |
9044 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
9045 | out_iounmap_conf: | |
9046 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
9047 | out: | |
9048 | return error; | |
9049 | } | |
9050 | ||
9051 | /** | |
9052 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. | |
9053 | * @phba: pointer to lpfc hba data structure. | |
9054 | * | |
9055 | * This routine is invoked to unset the PCI device memory space for device | |
9056 | * with SLI-4 interface spec. | |
9057 | **/ | |
9058 | static void | |
9059 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) | |
9060 | { | |
2e90f4b5 JS |
9061 | uint32_t if_type; |
9062 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); | |
da0436e9 | 9063 | |
2e90f4b5 JS |
9064 | switch (if_type) { |
9065 | case LPFC_SLI_INTF_IF_TYPE_0: | |
9066 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
9067 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
9068 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
9069 | break; | |
9070 | case LPFC_SLI_INTF_IF_TYPE_2: | |
9071 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
9072 | break; | |
9073 | case LPFC_SLI_INTF_IF_TYPE_1: | |
9074 | default: | |
9075 | dev_printk(KERN_ERR, &phba->pcidev->dev, | |
9076 | "FATAL - unsupported SLI4 interface type - %d\n", | |
9077 | if_type); | |
9078 | break; | |
9079 | } | |
da0436e9 JS |
9080 | } |
9081 | ||
9082 | /** | |
9083 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device | |
9084 | * @phba: pointer to lpfc hba data structure. | |
9085 | * | |
9086 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
45ffac19 | 9087 | * with SLI-3 interface specs. |
da0436e9 JS |
9088 | * |
9089 | * Return codes | |
af901ca1 | 9090 | * 0 - successful |
da0436e9 JS |
9091 | * other values - error |
9092 | **/ | |
9093 | static int | |
9094 | lpfc_sli_enable_msix(struct lpfc_hba *phba) | |
9095 | { | |
45ffac19 | 9096 | int rc; |
da0436e9 JS |
9097 | LPFC_MBOXQ_t *pmb; |
9098 | ||
9099 | /* Set up MSI-X multi-message vectors */ | |
45ffac19 CH |
9100 | rc = pci_alloc_irq_vectors(phba->pcidev, |
9101 | LPFC_MSIX_VECTORS, LPFC_MSIX_VECTORS, PCI_IRQ_MSIX); | |
9102 | if (rc < 0) { | |
da0436e9 JS |
9103 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
9104 | "0420 PCI enable MSI-X failed (%d)\n", rc); | |
029165ac | 9105 | goto vec_fail_out; |
da0436e9 | 9106 | } |
45ffac19 | 9107 | |
da0436e9 JS |
9108 | /* |
9109 | * Assign MSI-X vectors to interrupt handlers | |
9110 | */ | |
9111 | ||
9112 | /* vector-0 is associated to slow-path handler */ | |
45ffac19 | 9113 | rc = request_irq(pci_irq_vector(phba->pcidev, 0), |
ed243d37 | 9114 | &lpfc_sli_sp_intr_handler, 0, |
da0436e9 JS |
9115 | LPFC_SP_DRIVER_HANDLER_NAME, phba); |
9116 | if (rc) { | |
9117 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
9118 | "0421 MSI-X slow-path request_irq failed " | |
9119 | "(%d)\n", rc); | |
9120 | goto msi_fail_out; | |
9121 | } | |
9122 | ||
9123 | /* vector-1 is associated to fast-path handler */ | |
45ffac19 | 9124 | rc = request_irq(pci_irq_vector(phba->pcidev, 1), |
ed243d37 | 9125 | &lpfc_sli_fp_intr_handler, 0, |
da0436e9 JS |
9126 | LPFC_FP_DRIVER_HANDLER_NAME, phba); |
9127 | ||
9128 | if (rc) { | |
9129 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
9130 | "0429 MSI-X fast-path request_irq failed " | |
9131 | "(%d)\n", rc); | |
9132 | goto irq_fail_out; | |
9133 | } | |
9134 | ||
9135 | /* | |
9136 | * Configure HBA MSI-X attention conditions to messages | |
9137 | */ | |
9138 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
9139 | ||
9140 | if (!pmb) { | |
9141 | rc = -ENOMEM; | |
9142 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9143 | "0474 Unable to allocate memory for issuing " | |
9144 | "MBOX_CONFIG_MSI command\n"); | |
9145 | goto mem_fail_out; | |
9146 | } | |
9147 | rc = lpfc_config_msi(phba, pmb); | |
9148 | if (rc) | |
9149 | goto mbx_fail_out; | |
9150 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
9151 | if (rc != MBX_SUCCESS) { | |
9152 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | |
9153 | "0351 Config MSI mailbox command failed, " | |
9154 | "mbxCmd x%x, mbxStatus x%x\n", | |
9155 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); | |
9156 | goto mbx_fail_out; | |
9157 | } | |
9158 | ||
9159 | /* Free memory allocated for mailbox command */ | |
9160 | mempool_free(pmb, phba->mbox_mem_pool); | |
9161 | return rc; | |
9162 | ||
9163 | mbx_fail_out: | |
9164 | /* Free memory allocated for mailbox command */ | |
9165 | mempool_free(pmb, phba->mbox_mem_pool); | |
9166 | ||
9167 | mem_fail_out: | |
9168 | /* free the irq already requested */ | |
45ffac19 | 9169 | free_irq(pci_irq_vector(phba->pcidev, 1), phba); |
da0436e9 JS |
9170 | |
9171 | irq_fail_out: | |
9172 | /* free the irq already requested */ | |
45ffac19 | 9173 | free_irq(pci_irq_vector(phba->pcidev, 0), phba); |
da0436e9 JS |
9174 | |
9175 | msi_fail_out: | |
9176 | /* Unconfigure MSI-X capability structure */ | |
45ffac19 | 9177 | pci_free_irq_vectors(phba->pcidev); |
029165ac AG |
9178 | |
9179 | vec_fail_out: | |
da0436e9 JS |
9180 | return rc; |
9181 | } | |
9182 | ||
da0436e9 JS |
9183 | /** |
9184 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. | |
9185 | * @phba: pointer to lpfc hba data structure. | |
9186 | * | |
9187 | * This routine is invoked to enable the MSI interrupt mode to device with | |
9188 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to | |
9189 | * enable the MSI vector. The device driver is responsible for calling the | |
9190 | * request_irq() to register MSI vector with a interrupt the handler, which | |
9191 | * is done in this function. | |
9192 | * | |
9193 | * Return codes | |
af901ca1 | 9194 | * 0 - successful |
da0436e9 JS |
9195 | * other values - error |
9196 | */ | |
9197 | static int | |
9198 | lpfc_sli_enable_msi(struct lpfc_hba *phba) | |
9199 | { | |
9200 | int rc; | |
9201 | ||
9202 | rc = pci_enable_msi(phba->pcidev); | |
9203 | if (!rc) | |
9204 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
9205 | "0462 PCI enable MSI mode success.\n"); | |
9206 | else { | |
9207 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
9208 | "0471 PCI enable MSI mode failed (%d)\n", rc); | |
9209 | return rc; | |
9210 | } | |
9211 | ||
9212 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
ed243d37 | 9213 | 0, LPFC_DRIVER_NAME, phba); |
da0436e9 JS |
9214 | if (rc) { |
9215 | pci_disable_msi(phba->pcidev); | |
9216 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
9217 | "0478 MSI request_irq failed (%d)\n", rc); | |
9218 | } | |
9219 | return rc; | |
9220 | } | |
9221 | ||
da0436e9 JS |
9222 | /** |
9223 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. | |
9224 | * @phba: pointer to lpfc hba data structure. | |
9225 | * | |
9226 | * This routine is invoked to enable device interrupt and associate driver's | |
9227 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface | |
9228 | * spec. Depends on the interrupt mode configured to the driver, the driver | |
9229 | * will try to fallback from the configured interrupt mode to an interrupt | |
9230 | * mode which is supported by the platform, kernel, and device in the order | |
9231 | * of: | |
9232 | * MSI-X -> MSI -> IRQ. | |
9233 | * | |
9234 | * Return codes | |
af901ca1 | 9235 | * 0 - successful |
da0436e9 JS |
9236 | * other values - error |
9237 | **/ | |
9238 | static uint32_t | |
9239 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
9240 | { | |
9241 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
9242 | int retval; | |
9243 | ||
9244 | if (cfg_mode == 2) { | |
9245 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ | |
9246 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); | |
9247 | if (!retval) { | |
9248 | /* Now, try to enable MSI-X interrupt mode */ | |
9249 | retval = lpfc_sli_enable_msix(phba); | |
9250 | if (!retval) { | |
9251 | /* Indicate initialization to MSI-X mode */ | |
9252 | phba->intr_type = MSIX; | |
9253 | intr_mode = 2; | |
9254 | } | |
9255 | } | |
9256 | } | |
9257 | ||
9258 | /* Fallback to MSI if MSI-X initialization failed */ | |
9259 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
9260 | retval = lpfc_sli_enable_msi(phba); | |
9261 | if (!retval) { | |
9262 | /* Indicate initialization to MSI mode */ | |
9263 | phba->intr_type = MSI; | |
9264 | intr_mode = 1; | |
9265 | } | |
9266 | } | |
9267 | ||
9268 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
9269 | if (phba->intr_type == NONE) { | |
9270 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
9271 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
9272 | if (!retval) { | |
9273 | /* Indicate initialization to INTx mode */ | |
9274 | phba->intr_type = INTx; | |
9275 | intr_mode = 0; | |
9276 | } | |
9277 | } | |
9278 | return intr_mode; | |
9279 | } | |
9280 | ||
9281 | /** | |
9282 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. | |
9283 | * @phba: pointer to lpfc hba data structure. | |
9284 | * | |
9285 | * This routine is invoked to disable device interrupt and disassociate the | |
9286 | * driver's interrupt handler(s) from interrupt vector(s) to device with | |
9287 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will | |
9288 | * release the interrupt vector(s) for the message signaled interrupt. | |
9289 | **/ | |
9290 | static void | |
9291 | lpfc_sli_disable_intr(struct lpfc_hba *phba) | |
9292 | { | |
45ffac19 CH |
9293 | int nr_irqs, i; |
9294 | ||
da0436e9 | 9295 | if (phba->intr_type == MSIX) |
45ffac19 CH |
9296 | nr_irqs = LPFC_MSIX_VECTORS; |
9297 | else | |
9298 | nr_irqs = 1; | |
9299 | ||
9300 | for (i = 0; i < nr_irqs; i++) | |
9301 | free_irq(pci_irq_vector(phba->pcidev, i), phba); | |
9302 | pci_free_irq_vectors(phba->pcidev); | |
da0436e9 JS |
9303 | |
9304 | /* Reset interrupt management states */ | |
9305 | phba->intr_type = NONE; | |
9306 | phba->sli.slistat.sli_intr = 0; | |
da0436e9 JS |
9307 | } |
9308 | ||
7bb03bbf | 9309 | /** |
895427bd | 9310 | * lpfc_cpu_affinity_check - Check vector CPU affinity mappings |
7bb03bbf | 9311 | * @phba: pointer to lpfc hba data structure. |
895427bd JS |
9312 | * @vectors: number of msix vectors allocated. |
9313 | * | |
9314 | * The routine will figure out the CPU affinity assignment for every | |
9315 | * MSI-X vector allocated for the HBA. The hba_eq_hdl will be updated | |
9316 | * with a pointer to the CPU mask that defines ALL the CPUs this vector | |
9317 | * can be associated with. If the vector can be unquely associated with | |
9318 | * a single CPU, that CPU will be recorded in hba_eq_hdl[index].cpu. | |
9319 | * In addition, the CPU to IO channel mapping will be calculated | |
9320 | * and the phba->sli4_hba.cpu_map array will reflect this. | |
7bb03bbf | 9321 | */ |
895427bd JS |
9322 | static void |
9323 | lpfc_cpu_affinity_check(struct lpfc_hba *phba, int vectors) | |
7bb03bbf JS |
9324 | { |
9325 | struct lpfc_vector_map_info *cpup; | |
895427bd JS |
9326 | int index = 0; |
9327 | int vec = 0; | |
7bb03bbf | 9328 | int cpu; |
7bb03bbf JS |
9329 | #ifdef CONFIG_X86 |
9330 | struct cpuinfo_x86 *cpuinfo; | |
9331 | #endif | |
7bb03bbf JS |
9332 | |
9333 | /* Init cpu_map array */ | |
9334 | memset(phba->sli4_hba.cpu_map, 0xff, | |
9335 | (sizeof(struct lpfc_vector_map_info) * | |
895427bd | 9336 | phba->sli4_hba.num_present_cpu)); |
7bb03bbf JS |
9337 | |
9338 | /* Update CPU map with physical id and core id of each CPU */ | |
9339 | cpup = phba->sli4_hba.cpu_map; | |
9340 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { | |
9341 | #ifdef CONFIG_X86 | |
9342 | cpuinfo = &cpu_data(cpu); | |
9343 | cpup->phys_id = cpuinfo->phys_proc_id; | |
9344 | cpup->core_id = cpuinfo->cpu_core_id; | |
9345 | #else | |
9346 | /* No distinction between CPUs for other platforms */ | |
9347 | cpup->phys_id = 0; | |
9348 | cpup->core_id = 0; | |
9349 | #endif | |
895427bd JS |
9350 | cpup->channel_id = index; /* For now round robin */ |
9351 | cpup->irq = pci_irq_vector(phba->pcidev, vec); | |
9352 | vec++; | |
9353 | if (vec >= vectors) | |
9354 | vec = 0; | |
9355 | index++; | |
9356 | if (index >= phba->cfg_fcp_io_channel) | |
9357 | index = 0; | |
7bb03bbf JS |
9358 | cpup++; |
9359 | } | |
7bb03bbf JS |
9360 | } |
9361 | ||
9362 | ||
da0436e9 JS |
9363 | /** |
9364 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device | |
9365 | * @phba: pointer to lpfc hba data structure. | |
9366 | * | |
9367 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
45ffac19 | 9368 | * with SLI-4 interface spec. |
da0436e9 JS |
9369 | * |
9370 | * Return codes | |
af901ca1 | 9371 | * 0 - successful |
da0436e9 JS |
9372 | * other values - error |
9373 | **/ | |
9374 | static int | |
9375 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) | |
9376 | { | |
75baf696 | 9377 | int vectors, rc, index; |
da0436e9 JS |
9378 | |
9379 | /* Set up MSI-X multi-message vectors */ | |
895427bd | 9380 | vectors = phba->io_channel_irqs; |
45ffac19 | 9381 | if (phba->cfg_fof) |
1ba981fd | 9382 | vectors++; |
45ffac19 | 9383 | |
f358dd0c JS |
9384 | rc = pci_alloc_irq_vectors(phba->pcidev, |
9385 | (phba->nvmet_support) ? 1 : 2, | |
9386 | vectors, PCI_IRQ_MSIX | PCI_IRQ_AFFINITY); | |
4f871e1b | 9387 | if (rc < 0) { |
da0436e9 JS |
9388 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
9389 | "0484 PCI enable MSI-X failed (%d)\n", rc); | |
029165ac | 9390 | goto vec_fail_out; |
da0436e9 | 9391 | } |
4f871e1b | 9392 | vectors = rc; |
75baf696 | 9393 | |
7bb03bbf | 9394 | /* Assign MSI-X vectors to interrupt handlers */ |
67d12733 | 9395 | for (index = 0; index < vectors; index++) { |
4305f183 | 9396 | memset(&phba->sli4_hba.handler_name[index], 0, 16); |
a2fc4aef JS |
9397 | snprintf((char *)&phba->sli4_hba.handler_name[index], |
9398 | LPFC_SLI4_HANDLER_NAME_SZ, | |
4305f183 | 9399 | LPFC_DRIVER_HANDLER_NAME"%d", index); |
da0436e9 | 9400 | |
895427bd JS |
9401 | phba->sli4_hba.hba_eq_hdl[index].idx = index; |
9402 | phba->sli4_hba.hba_eq_hdl[index].phba = phba; | |
9403 | atomic_set(&phba->sli4_hba.hba_eq_hdl[index].hba_eq_in_use, 1); | |
1ba981fd | 9404 | if (phba->cfg_fof && (index == (vectors - 1))) |
45ffac19 | 9405 | rc = request_irq(pci_irq_vector(phba->pcidev, index), |
ed243d37 | 9406 | &lpfc_sli4_fof_intr_handler, 0, |
1ba981fd | 9407 | (char *)&phba->sli4_hba.handler_name[index], |
895427bd | 9408 | &phba->sli4_hba.hba_eq_hdl[index]); |
1ba981fd | 9409 | else |
45ffac19 | 9410 | rc = request_irq(pci_irq_vector(phba->pcidev, index), |
ed243d37 | 9411 | &lpfc_sli4_hba_intr_handler, 0, |
4305f183 | 9412 | (char *)&phba->sli4_hba.handler_name[index], |
895427bd | 9413 | &phba->sli4_hba.hba_eq_hdl[index]); |
da0436e9 JS |
9414 | if (rc) { |
9415 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
9416 | "0486 MSI-X fast-path (%d) " | |
9417 | "request_irq failed (%d)\n", index, rc); | |
9418 | goto cfg_fail_out; | |
9419 | } | |
9420 | } | |
9421 | ||
1ba981fd JS |
9422 | if (phba->cfg_fof) |
9423 | vectors--; | |
9424 | ||
895427bd | 9425 | if (vectors != phba->io_channel_irqs) { |
82c3e9ba JS |
9426 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
9427 | "3238 Reducing IO channels to match number of " | |
9428 | "MSI-X vectors, requested %d got %d\n", | |
895427bd JS |
9429 | phba->io_channel_irqs, vectors); |
9430 | if (phba->cfg_fcp_io_channel > vectors) | |
9431 | phba->cfg_fcp_io_channel = vectors; | |
9432 | if (phba->cfg_nvme_io_channel > vectors) | |
9433 | phba->cfg_nvme_io_channel = vectors; | |
9434 | if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel) | |
9435 | phba->io_channel_irqs = phba->cfg_fcp_io_channel; | |
9436 | else | |
9437 | phba->io_channel_irqs = phba->cfg_nvme_io_channel; | |
82c3e9ba | 9438 | } |
895427bd | 9439 | lpfc_cpu_affinity_check(phba, vectors); |
7bb03bbf | 9440 | |
da0436e9 JS |
9441 | return rc; |
9442 | ||
9443 | cfg_fail_out: | |
9444 | /* free the irq already requested */ | |
895427bd JS |
9445 | for (--index; index >= 0; index--) |
9446 | free_irq(pci_irq_vector(phba->pcidev, index), | |
9447 | &phba->sli4_hba.hba_eq_hdl[index]); | |
da0436e9 | 9448 | |
da0436e9 | 9449 | /* Unconfigure MSI-X capability structure */ |
45ffac19 | 9450 | pci_free_irq_vectors(phba->pcidev); |
029165ac AG |
9451 | |
9452 | vec_fail_out: | |
da0436e9 JS |
9453 | return rc; |
9454 | } | |
9455 | ||
da0436e9 JS |
9456 | /** |
9457 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device | |
9458 | * @phba: pointer to lpfc hba data structure. | |
9459 | * | |
9460 | * This routine is invoked to enable the MSI interrupt mode to device with | |
9461 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called | |
9462 | * to enable the MSI vector. The device driver is responsible for calling | |
9463 | * the request_irq() to register MSI vector with a interrupt the handler, | |
9464 | * which is done in this function. | |
9465 | * | |
9466 | * Return codes | |
af901ca1 | 9467 | * 0 - successful |
da0436e9 JS |
9468 | * other values - error |
9469 | **/ | |
9470 | static int | |
9471 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) | |
9472 | { | |
9473 | int rc, index; | |
9474 | ||
9475 | rc = pci_enable_msi(phba->pcidev); | |
9476 | if (!rc) | |
9477 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
9478 | "0487 PCI enable MSI mode success.\n"); | |
9479 | else { | |
9480 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
9481 | "0488 PCI enable MSI mode failed (%d)\n", rc); | |
9482 | return rc; | |
9483 | } | |
9484 | ||
9485 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
ed243d37 | 9486 | 0, LPFC_DRIVER_NAME, phba); |
da0436e9 JS |
9487 | if (rc) { |
9488 | pci_disable_msi(phba->pcidev); | |
9489 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
9490 | "0490 MSI request_irq failed (%d)\n", rc); | |
75baf696 | 9491 | return rc; |
da0436e9 JS |
9492 | } |
9493 | ||
895427bd JS |
9494 | for (index = 0; index < phba->io_channel_irqs; index++) { |
9495 | phba->sli4_hba.hba_eq_hdl[index].idx = index; | |
9496 | phba->sli4_hba.hba_eq_hdl[index].phba = phba; | |
da0436e9 JS |
9497 | } |
9498 | ||
1ba981fd | 9499 | if (phba->cfg_fof) { |
895427bd JS |
9500 | phba->sli4_hba.hba_eq_hdl[index].idx = index; |
9501 | phba->sli4_hba.hba_eq_hdl[index].phba = phba; | |
1ba981fd | 9502 | } |
75baf696 | 9503 | return 0; |
da0436e9 JS |
9504 | } |
9505 | ||
da0436e9 JS |
9506 | /** |
9507 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device | |
9508 | * @phba: pointer to lpfc hba data structure. | |
9509 | * | |
9510 | * This routine is invoked to enable device interrupt and associate driver's | |
9511 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 | |
9512 | * interface spec. Depends on the interrupt mode configured to the driver, | |
9513 | * the driver will try to fallback from the configured interrupt mode to an | |
9514 | * interrupt mode which is supported by the platform, kernel, and device in | |
9515 | * the order of: | |
9516 | * MSI-X -> MSI -> IRQ. | |
9517 | * | |
9518 | * Return codes | |
af901ca1 | 9519 | * 0 - successful |
da0436e9 JS |
9520 | * other values - error |
9521 | **/ | |
9522 | static uint32_t | |
9523 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
9524 | { | |
9525 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
895427bd | 9526 | int retval, idx; |
da0436e9 JS |
9527 | |
9528 | if (cfg_mode == 2) { | |
9529 | /* Preparation before conf_msi mbox cmd */ | |
9530 | retval = 0; | |
9531 | if (!retval) { | |
9532 | /* Now, try to enable MSI-X interrupt mode */ | |
9533 | retval = lpfc_sli4_enable_msix(phba); | |
9534 | if (!retval) { | |
9535 | /* Indicate initialization to MSI-X mode */ | |
9536 | phba->intr_type = MSIX; | |
9537 | intr_mode = 2; | |
9538 | } | |
9539 | } | |
9540 | } | |
9541 | ||
9542 | /* Fallback to MSI if MSI-X initialization failed */ | |
9543 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
9544 | retval = lpfc_sli4_enable_msi(phba); | |
9545 | if (!retval) { | |
9546 | /* Indicate initialization to MSI mode */ | |
9547 | phba->intr_type = MSI; | |
9548 | intr_mode = 1; | |
9549 | } | |
9550 | } | |
9551 | ||
9552 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
9553 | if (phba->intr_type == NONE) { | |
9554 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
9555 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
9556 | if (!retval) { | |
895427bd JS |
9557 | struct lpfc_hba_eq_hdl *eqhdl; |
9558 | ||
da0436e9 JS |
9559 | /* Indicate initialization to INTx mode */ |
9560 | phba->intr_type = INTx; | |
9561 | intr_mode = 0; | |
895427bd JS |
9562 | |
9563 | for (idx = 0; idx < phba->io_channel_irqs; idx++) { | |
9564 | eqhdl = &phba->sli4_hba.hba_eq_hdl[idx]; | |
9565 | eqhdl->idx = idx; | |
9566 | eqhdl->phba = phba; | |
9567 | atomic_set(&eqhdl->hba_eq_in_use, 1); | |
da0436e9 | 9568 | } |
1ba981fd | 9569 | if (phba->cfg_fof) { |
895427bd JS |
9570 | eqhdl = &phba->sli4_hba.hba_eq_hdl[idx]; |
9571 | eqhdl->idx = idx; | |
9572 | eqhdl->phba = phba; | |
9573 | atomic_set(&eqhdl->hba_eq_in_use, 1); | |
1ba981fd | 9574 | } |
da0436e9 JS |
9575 | } |
9576 | } | |
9577 | return intr_mode; | |
9578 | } | |
9579 | ||
9580 | /** | |
9581 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device | |
9582 | * @phba: pointer to lpfc hba data structure. | |
9583 | * | |
9584 | * This routine is invoked to disable device interrupt and disassociate | |
9585 | * the driver's interrupt handler(s) from interrupt vector(s) to device | |
9586 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver | |
9587 | * will release the interrupt vector(s) for the message signaled interrupt. | |
9588 | **/ | |
9589 | static void | |
9590 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) | |
9591 | { | |
9592 | /* Disable the currently initialized interrupt mode */ | |
45ffac19 CH |
9593 | if (phba->intr_type == MSIX) { |
9594 | int index; | |
9595 | ||
9596 | /* Free up MSI-X multi-message vectors */ | |
895427bd JS |
9597 | for (index = 0; index < phba->io_channel_irqs; index++) |
9598 | free_irq(pci_irq_vector(phba->pcidev, index), | |
9599 | &phba->sli4_hba.hba_eq_hdl[index]); | |
45ffac19 CH |
9600 | |
9601 | if (phba->cfg_fof) | |
895427bd JS |
9602 | free_irq(pci_irq_vector(phba->pcidev, index), |
9603 | &phba->sli4_hba.hba_eq_hdl[index]); | |
45ffac19 | 9604 | } else { |
da0436e9 | 9605 | free_irq(phba->pcidev->irq, phba); |
45ffac19 CH |
9606 | } |
9607 | ||
9608 | pci_free_irq_vectors(phba->pcidev); | |
da0436e9 JS |
9609 | |
9610 | /* Reset interrupt management states */ | |
9611 | phba->intr_type = NONE; | |
9612 | phba->sli.slistat.sli_intr = 0; | |
da0436e9 JS |
9613 | } |
9614 | ||
9615 | /** | |
9616 | * lpfc_unset_hba - Unset SLI3 hba device initialization | |
9617 | * @phba: pointer to lpfc hba data structure. | |
9618 | * | |
9619 | * This routine is invoked to unset the HBA device initialization steps to | |
9620 | * a device with SLI-3 interface spec. | |
9621 | **/ | |
9622 | static void | |
9623 | lpfc_unset_hba(struct lpfc_hba *phba) | |
9624 | { | |
9625 | struct lpfc_vport *vport = phba->pport; | |
9626 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
9627 | ||
9628 | spin_lock_irq(shost->host_lock); | |
9629 | vport->load_flag |= FC_UNLOADING; | |
9630 | spin_unlock_irq(shost->host_lock); | |
9631 | ||
72859909 JS |
9632 | kfree(phba->vpi_bmask); |
9633 | kfree(phba->vpi_ids); | |
9634 | ||
da0436e9 JS |
9635 | lpfc_stop_hba_timers(phba); |
9636 | ||
9637 | phba->pport->work_port_events = 0; | |
9638 | ||
9639 | lpfc_sli_hba_down(phba); | |
9640 | ||
9641 | lpfc_sli_brdrestart(phba); | |
9642 | ||
9643 | lpfc_sli_disable_intr(phba); | |
9644 | ||
9645 | return; | |
9646 | } | |
9647 | ||
5af5eee7 JS |
9648 | /** |
9649 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy | |
9650 | * @phba: Pointer to HBA context object. | |
9651 | * | |
9652 | * This function is called in the SLI4 code path to wait for completion | |
9653 | * of device's XRIs exchange busy. It will check the XRI exchange busy | |
9654 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after | |
9655 | * that, it will check the XRI exchange busy on outstanding FCP and ELS | |
9656 | * I/Os every 30 seconds, log error message, and wait forever. Only when | |
9657 | * all XRI exchange busy complete, the driver unload shall proceed with | |
9658 | * invoking the function reset ioctl mailbox command to the CNA and the | |
9659 | * the rest of the driver unload resource release. | |
9660 | **/ | |
9661 | static void | |
9662 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) | |
9663 | { | |
9664 | int wait_time = 0; | |
895427bd JS |
9665 | int nvme_xri_cmpl = 1; |
9666 | int fcp_xri_cmpl = 1; | |
5af5eee7 | 9667 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); |
f358dd0c JS |
9668 | int nvmet_xri_cmpl = |
9669 | list_empty(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list); | |
5af5eee7 | 9670 | |
895427bd JS |
9671 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) |
9672 | fcp_xri_cmpl = | |
9673 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
9674 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) | |
9675 | nvme_xri_cmpl = | |
9676 | list_empty(&phba->sli4_hba.lpfc_abts_nvme_buf_list); | |
9677 | ||
f358dd0c JS |
9678 | while (!fcp_xri_cmpl || !els_xri_cmpl || !nvme_xri_cmpl || |
9679 | !nvmet_xri_cmpl) { | |
5af5eee7 | 9680 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { |
895427bd JS |
9681 | if (!nvme_xri_cmpl) |
9682 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9683 | "6100 NVME XRI exchange busy " | |
9684 | "wait time: %d seconds.\n", | |
9685 | wait_time/1000); | |
5af5eee7 JS |
9686 | if (!fcp_xri_cmpl) |
9687 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9688 | "2877 FCP XRI exchange busy " | |
9689 | "wait time: %d seconds.\n", | |
9690 | wait_time/1000); | |
9691 | if (!els_xri_cmpl) | |
9692 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9693 | "2878 ELS XRI exchange busy " | |
9694 | "wait time: %d seconds.\n", | |
9695 | wait_time/1000); | |
9696 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); | |
9697 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; | |
9698 | } else { | |
9699 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); | |
9700 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; | |
9701 | } | |
895427bd JS |
9702 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) |
9703 | nvme_xri_cmpl = list_empty( | |
9704 | &phba->sli4_hba.lpfc_abts_nvme_buf_list); | |
9705 | ||
9706 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) | |
9707 | fcp_xri_cmpl = list_empty( | |
9708 | &phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
9709 | ||
5af5eee7 JS |
9710 | els_xri_cmpl = |
9711 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
f358dd0c JS |
9712 | |
9713 | nvmet_xri_cmpl = | |
9714 | list_empty(&phba->sli4_hba.lpfc_abts_nvmet_sgl_list); | |
5af5eee7 JS |
9715 | } |
9716 | } | |
9717 | ||
da0436e9 JS |
9718 | /** |
9719 | * lpfc_sli4_hba_unset - Unset the fcoe hba | |
9720 | * @phba: Pointer to HBA context object. | |
9721 | * | |
9722 | * This function is called in the SLI4 code path to reset the HBA's FCoE | |
9723 | * function. The caller is not required to hold any lock. This routine | |
9724 | * issues PCI function reset mailbox command to reset the FCoE function. | |
9725 | * At the end of the function, it calls lpfc_hba_down_post function to | |
9726 | * free any pending commands. | |
9727 | **/ | |
9728 | static void | |
9729 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) | |
9730 | { | |
9731 | int wait_cnt = 0; | |
9732 | LPFC_MBOXQ_t *mboxq; | |
912e3acd | 9733 | struct pci_dev *pdev = phba->pcidev; |
da0436e9 JS |
9734 | |
9735 | lpfc_stop_hba_timers(phba); | |
9736 | phba->sli4_hba.intr_enable = 0; | |
9737 | ||
9738 | /* | |
9739 | * Gracefully wait out the potential current outstanding asynchronous | |
9740 | * mailbox command. | |
9741 | */ | |
9742 | ||
9743 | /* First, block any pending async mailbox command from posted */ | |
9744 | spin_lock_irq(&phba->hbalock); | |
9745 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
9746 | spin_unlock_irq(&phba->hbalock); | |
9747 | /* Now, trying to wait it out if we can */ | |
9748 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
9749 | msleep(10); | |
9750 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) | |
9751 | break; | |
9752 | } | |
9753 | /* Forcefully release the outstanding mailbox command if timed out */ | |
9754 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
9755 | spin_lock_irq(&phba->hbalock); | |
9756 | mboxq = phba->sli.mbox_active; | |
9757 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
9758 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
9759 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
9760 | phba->sli.mbox_active = NULL; | |
9761 | spin_unlock_irq(&phba->hbalock); | |
9762 | } | |
9763 | ||
5af5eee7 JS |
9764 | /* Abort all iocbs associated with the hba */ |
9765 | lpfc_sli_hba_iocb_abort(phba); | |
9766 | ||
9767 | /* Wait for completion of device XRI exchange busy */ | |
9768 | lpfc_sli4_xri_exchange_busy_wait(phba); | |
9769 | ||
da0436e9 JS |
9770 | /* Disable PCI subsystem interrupt */ |
9771 | lpfc_sli4_disable_intr(phba); | |
9772 | ||
912e3acd JS |
9773 | /* Disable SR-IOV if enabled */ |
9774 | if (phba->cfg_sriov_nr_virtfn) | |
9775 | pci_disable_sriov(pdev); | |
9776 | ||
da0436e9 JS |
9777 | /* Stop kthread signal shall trigger work_done one more time */ |
9778 | kthread_stop(phba->worker_thread); | |
9779 | ||
3677a3a7 JS |
9780 | /* Reset SLI4 HBA FCoE function */ |
9781 | lpfc_pci_function_reset(phba); | |
5350d872 | 9782 | lpfc_sli4_queue_destroy(phba); |
3677a3a7 | 9783 | |
da0436e9 JS |
9784 | /* Stop the SLI4 device port */ |
9785 | phba->pport->work_port_events = 0; | |
9786 | } | |
9787 | ||
28baac74 JS |
9788 | /** |
9789 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. | |
9790 | * @phba: Pointer to HBA context object. | |
9791 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. | |
9792 | * | |
9793 | * This function is called in the SLI4 code path to read the port's | |
9794 | * sli4 capabilities. | |
9795 | * | |
9796 | * This function may be be called from any context that can block-wait | |
9797 | * for the completion. The expectation is that this routine is called | |
9798 | * typically from probe_one or from the online routine. | |
9799 | **/ | |
9800 | int | |
9801 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
9802 | { | |
9803 | int rc; | |
9804 | struct lpfc_mqe *mqe; | |
9805 | struct lpfc_pc_sli4_params *sli4_params; | |
9806 | uint32_t mbox_tmo; | |
9807 | ||
9808 | rc = 0; | |
9809 | mqe = &mboxq->u.mqe; | |
9810 | ||
9811 | /* Read the port's SLI4 Parameters port capabilities */ | |
fedd3b7b | 9812 | lpfc_pc_sli4_params(mboxq); |
28baac74 JS |
9813 | if (!phba->sli4_hba.intr_enable) |
9814 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
9815 | else { | |
a183a15f | 9816 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
28baac74 JS |
9817 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
9818 | } | |
9819 | ||
9820 | if (unlikely(rc)) | |
9821 | return 1; | |
9822 | ||
9823 | sli4_params = &phba->sli4_hba.pc_sli4_params; | |
9824 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); | |
9825 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); | |
9826 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); | |
9827 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, | |
9828 | &mqe->un.sli4_params); | |
9829 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, | |
9830 | &mqe->un.sli4_params); | |
9831 | sli4_params->proto_types = mqe->un.sli4_params.word3; | |
9832 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; | |
9833 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); | |
9834 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); | |
9835 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); | |
9836 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); | |
9837 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); | |
9838 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); | |
9839 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); | |
9840 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); | |
9841 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); | |
9842 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); | |
9843 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); | |
9844 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); | |
9845 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); | |
9846 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); | |
9847 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); | |
9848 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); | |
9849 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); | |
9850 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); | |
9851 | sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params); | |
0558056c JS |
9852 | |
9853 | /* Make sure that sge_supp_len can be handled by the driver */ | |
9854 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) | |
9855 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; | |
9856 | ||
28baac74 JS |
9857 | return rc; |
9858 | } | |
9859 | ||
fedd3b7b JS |
9860 | /** |
9861 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. | |
9862 | * @phba: Pointer to HBA context object. | |
9863 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. | |
9864 | * | |
9865 | * This function is called in the SLI4 code path to read the port's | |
9866 | * sli4 capabilities. | |
9867 | * | |
9868 | * This function may be be called from any context that can block-wait | |
9869 | * for the completion. The expectation is that this routine is called | |
9870 | * typically from probe_one or from the online routine. | |
9871 | **/ | |
9872 | int | |
9873 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
9874 | { | |
9875 | int rc; | |
9876 | struct lpfc_mqe *mqe = &mboxq->u.mqe; | |
9877 | struct lpfc_pc_sli4_params *sli4_params; | |
a183a15f | 9878 | uint32_t mbox_tmo; |
fedd3b7b JS |
9879 | int length; |
9880 | struct lpfc_sli4_parameters *mbx_sli4_parameters; | |
9881 | ||
6d368e53 JS |
9882 | /* |
9883 | * By default, the driver assumes the SLI4 port requires RPI | |
9884 | * header postings. The SLI4_PARAM response will correct this | |
9885 | * assumption. | |
9886 | */ | |
9887 | phba->sli4_hba.rpi_hdrs_in_use = 1; | |
9888 | ||
fedd3b7b JS |
9889 | /* Read the port's SLI4 Config Parameters */ |
9890 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - | |
9891 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
9892 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
9893 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, | |
9894 | length, LPFC_SLI4_MBX_EMBED); | |
9895 | if (!phba->sli4_hba.intr_enable) | |
9896 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
a183a15f JS |
9897 | else { |
9898 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); | |
9899 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
9900 | } | |
fedd3b7b JS |
9901 | if (unlikely(rc)) |
9902 | return rc; | |
9903 | sli4_params = &phba->sli4_hba.pc_sli4_params; | |
9904 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; | |
9905 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); | |
9906 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); | |
9907 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); | |
9908 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, | |
9909 | mbx_sli4_parameters); | |
9910 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, | |
9911 | mbx_sli4_parameters); | |
9912 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) | |
9913 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; | |
9914 | else | |
9915 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; | |
9916 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; | |
9917 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); | |
1ba981fd | 9918 | sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters); |
fedd3b7b JS |
9919 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
9920 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); | |
9921 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); | |
9922 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); | |
0c651878 | 9923 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
fedd3b7b JS |
9924 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
9925 | mbx_sli4_parameters); | |
895427bd | 9926 | sli4_params->wqpcnt = bf_get(cfg_wqpcnt, mbx_sli4_parameters); |
fedd3b7b JS |
9927 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, |
9928 | mbx_sli4_parameters); | |
6d368e53 JS |
9929 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
9930 | phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters); | |
895427bd JS |
9931 | phba->nvme_support = (bf_get(cfg_nvme, mbx_sli4_parameters) && |
9932 | bf_get(cfg_xib, mbx_sli4_parameters)); | |
9933 | ||
9934 | if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) || | |
9935 | !phba->nvme_support) { | |
9936 | phba->nvme_support = 0; | |
9937 | phba->nvmet_support = 0; | |
9938 | phba->cfg_nvme_io_channel = 0; | |
9939 | phba->io_channel_irqs = phba->cfg_fcp_io_channel; | |
9940 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_NVME, | |
9941 | "6101 Disabling NVME support: " | |
9942 | "Not supported by firmware: %d %d\n", | |
9943 | bf_get(cfg_nvme, mbx_sli4_parameters), | |
9944 | bf_get(cfg_xib, mbx_sli4_parameters)); | |
9945 | ||
9946 | /* If firmware doesn't support NVME, just use SCSI support */ | |
9947 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) | |
9948 | return -ENODEV; | |
9949 | phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP; | |
9950 | } | |
0558056c | 9951 | |
f358dd0c JS |
9952 | if (bf_get(cfg_xib, mbx_sli4_parameters) && phba->cfg_suppress_rsp) |
9953 | phba->sli.sli_flag |= LPFC_SLI_SUPPRESS_RSP; | |
9954 | ||
0558056c JS |
9955 | /* Make sure that sge_supp_len can be handled by the driver */ |
9956 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) | |
9957 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; | |
9958 | ||
b5c53958 JS |
9959 | /* |
9960 | * Issue IOs with CDB embedded in WQE to minimized the number | |
9961 | * of DMAs the firmware has to do. Setting this to 1 also forces | |
9962 | * the driver to use 128 bytes WQEs for FCP IOs. | |
9963 | */ | |
9964 | if (bf_get(cfg_ext_embed_cb, mbx_sli4_parameters)) | |
9965 | phba->fcp_embed_io = 1; | |
9966 | else | |
9967 | phba->fcp_embed_io = 0; | |
7bdedb34 JS |
9968 | |
9969 | /* | |
9970 | * Check if the SLI port supports MDS Diagnostics | |
9971 | */ | |
9972 | if (bf_get(cfg_mds_diags, mbx_sli4_parameters)) | |
9973 | phba->mds_diags_support = 1; | |
9974 | else | |
9975 | phba->mds_diags_support = 0; | |
fedd3b7b JS |
9976 | return 0; |
9977 | } | |
9978 | ||
da0436e9 JS |
9979 | /** |
9980 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. | |
9981 | * @pdev: pointer to PCI device | |
9982 | * @pid: pointer to PCI device identifier | |
9983 | * | |
9984 | * This routine is to be called to attach a device with SLI-3 interface spec | |
9985 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
9986 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific | |
9987 | * information of the device and driver to see if the driver state that it can | |
9988 | * support this kind of device. If the match is successful, the driver core | |
9989 | * invokes this routine. If this routine determines it can claim the HBA, it | |
9990 | * does all the initialization that it needs to do to handle the HBA properly. | |
9991 | * | |
9992 | * Return code | |
9993 | * 0 - driver can claim the device | |
9994 | * negative value - driver can not claim the device | |
9995 | **/ | |
6f039790 | 9996 | static int |
da0436e9 JS |
9997 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
9998 | { | |
9999 | struct lpfc_hba *phba; | |
10000 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 10001 | struct Scsi_Host *shost = NULL; |
da0436e9 JS |
10002 | int error; |
10003 | uint32_t cfg_mode, intr_mode; | |
10004 | ||
10005 | /* Allocate memory for HBA structure */ | |
10006 | phba = lpfc_hba_alloc(pdev); | |
10007 | if (!phba) | |
10008 | return -ENOMEM; | |
10009 | ||
10010 | /* Perform generic PCI device enabling operation */ | |
10011 | error = lpfc_enable_pci_dev(phba); | |
079b5c91 | 10012 | if (error) |
da0436e9 | 10013 | goto out_free_phba; |
da0436e9 JS |
10014 | |
10015 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ | |
10016 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); | |
10017 | if (error) | |
10018 | goto out_disable_pci_dev; | |
10019 | ||
10020 | /* Set up SLI-3 specific device PCI memory space */ | |
10021 | error = lpfc_sli_pci_mem_setup(phba); | |
10022 | if (error) { | |
10023 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10024 | "1402 Failed to set up pci memory space.\n"); | |
10025 | goto out_disable_pci_dev; | |
10026 | } | |
10027 | ||
da0436e9 JS |
10028 | /* Set up SLI-3 specific device driver resources */ |
10029 | error = lpfc_sli_driver_resource_setup(phba); | |
10030 | if (error) { | |
10031 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10032 | "1404 Failed to set up driver resource.\n"); | |
10033 | goto out_unset_pci_mem_s3; | |
10034 | } | |
10035 | ||
10036 | /* Initialize and populate the iocb list per host */ | |
10037 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); | |
10038 | if (error) { | |
10039 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10040 | "1405 Failed to initialize iocb list.\n"); | |
10041 | goto out_unset_driver_resource_s3; | |
10042 | } | |
10043 | ||
10044 | /* Set up common device driver resources */ | |
10045 | error = lpfc_setup_driver_resource_phase2(phba); | |
10046 | if (error) { | |
10047 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10048 | "1406 Failed to set up driver resource.\n"); | |
10049 | goto out_free_iocb_list; | |
10050 | } | |
10051 | ||
079b5c91 JS |
10052 | /* Get the default values for Model Name and Description */ |
10053 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
10054 | ||
da0436e9 JS |
10055 | /* Create SCSI host to the physical port */ |
10056 | error = lpfc_create_shost(phba); | |
10057 | if (error) { | |
10058 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10059 | "1407 Failed to create scsi host.\n"); | |
10060 | goto out_unset_driver_resource; | |
10061 | } | |
10062 | ||
10063 | /* Configure sysfs attributes */ | |
10064 | vport = phba->pport; | |
10065 | error = lpfc_alloc_sysfs_attr(vport); | |
10066 | if (error) { | |
10067 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10068 | "1476 Failed to allocate sysfs attr\n"); | |
10069 | goto out_destroy_shost; | |
10070 | } | |
10071 | ||
6669f9bb | 10072 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
da0436e9 JS |
10073 | /* Now, trying to enable interrupt and bring up the device */ |
10074 | cfg_mode = phba->cfg_use_msi; | |
10075 | while (true) { | |
10076 | /* Put device to a known state before enabling interrupt */ | |
10077 | lpfc_stop_port(phba); | |
10078 | /* Configure and enable interrupt */ | |
10079 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); | |
10080 | if (intr_mode == LPFC_INTR_ERROR) { | |
10081 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10082 | "0431 Failed to enable interrupt.\n"); | |
10083 | error = -ENODEV; | |
10084 | goto out_free_sysfs_attr; | |
10085 | } | |
10086 | /* SLI-3 HBA setup */ | |
10087 | if (lpfc_sli_hba_setup(phba)) { | |
10088 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10089 | "1477 Failed to set up hba\n"); | |
10090 | error = -ENODEV; | |
10091 | goto out_remove_device; | |
10092 | } | |
10093 | ||
10094 | /* Wait 50ms for the interrupts of previous mailbox commands */ | |
10095 | msleep(50); | |
10096 | /* Check active interrupts on message signaled interrupts */ | |
10097 | if (intr_mode == 0 || | |
10098 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { | |
10099 | /* Log the current active interrupt mode */ | |
10100 | phba->intr_mode = intr_mode; | |
10101 | lpfc_log_intr_mode(phba, intr_mode); | |
10102 | break; | |
10103 | } else { | |
10104 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
10105 | "0447 Configure interrupt mode (%d) " | |
10106 | "failed active interrupt test.\n", | |
10107 | intr_mode); | |
10108 | /* Disable the current interrupt mode */ | |
10109 | lpfc_sli_disable_intr(phba); | |
10110 | /* Try next level of interrupt mode */ | |
10111 | cfg_mode = --intr_mode; | |
10112 | } | |
10113 | } | |
10114 | ||
10115 | /* Perform post initialization setup */ | |
10116 | lpfc_post_init_setup(phba); | |
10117 | ||
10118 | /* Check if there are static vports to be created. */ | |
10119 | lpfc_create_static_vport(phba); | |
10120 | ||
10121 | return 0; | |
10122 | ||
10123 | out_remove_device: | |
10124 | lpfc_unset_hba(phba); | |
10125 | out_free_sysfs_attr: | |
10126 | lpfc_free_sysfs_attr(vport); | |
10127 | out_destroy_shost: | |
10128 | lpfc_destroy_shost(phba); | |
10129 | out_unset_driver_resource: | |
10130 | lpfc_unset_driver_resource_phase2(phba); | |
10131 | out_free_iocb_list: | |
10132 | lpfc_free_iocb_list(phba); | |
10133 | out_unset_driver_resource_s3: | |
10134 | lpfc_sli_driver_resource_unset(phba); | |
10135 | out_unset_pci_mem_s3: | |
10136 | lpfc_sli_pci_mem_unset(phba); | |
10137 | out_disable_pci_dev: | |
10138 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
10139 | if (shost) |
10140 | scsi_host_put(shost); | |
da0436e9 JS |
10141 | out_free_phba: |
10142 | lpfc_hba_free(phba); | |
10143 | return error; | |
10144 | } | |
10145 | ||
10146 | /** | |
10147 | * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem. | |
10148 | * @pdev: pointer to PCI device | |
10149 | * | |
10150 | * This routine is to be called to disattach a device with SLI-3 interface | |
10151 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
10152 | * removed from PCI bus, it performs all the necessary cleanup for the HBA | |
10153 | * device to be removed from the PCI subsystem properly. | |
10154 | **/ | |
6f039790 | 10155 | static void |
da0436e9 JS |
10156 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
10157 | { | |
10158 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10159 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
10160 | struct lpfc_vport **vports; | |
10161 | struct lpfc_hba *phba = vport->phba; | |
10162 | int i; | |
da0436e9 JS |
10163 | |
10164 | spin_lock_irq(&phba->hbalock); | |
10165 | vport->load_flag |= FC_UNLOADING; | |
10166 | spin_unlock_irq(&phba->hbalock); | |
10167 | ||
10168 | lpfc_free_sysfs_attr(vport); | |
10169 | ||
10170 | /* Release all the vports against this physical port */ | |
10171 | vports = lpfc_create_vport_work_array(phba); | |
10172 | if (vports != NULL) | |
587a37f6 JS |
10173 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
10174 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) | |
10175 | continue; | |
da0436e9 | 10176 | fc_vport_terminate(vports[i]->fc_vport); |
587a37f6 | 10177 | } |
da0436e9 JS |
10178 | lpfc_destroy_vport_work_array(phba, vports); |
10179 | ||
10180 | /* Remove FC host and then SCSI host with the physical port */ | |
10181 | fc_remove_host(shost); | |
10182 | scsi_remove_host(shost); | |
10183 | lpfc_cleanup(vport); | |
10184 | ||
10185 | /* | |
10186 | * Bring down the SLI Layer. This step disable all interrupts, | |
10187 | * clears the rings, discards all mailbox commands, and resets | |
10188 | * the HBA. | |
10189 | */ | |
10190 | ||
48e34d0f | 10191 | /* HBA interrupt will be disabled after this call */ |
da0436e9 JS |
10192 | lpfc_sli_hba_down(phba); |
10193 | /* Stop kthread signal shall trigger work_done one more time */ | |
10194 | kthread_stop(phba->worker_thread); | |
10195 | /* Final cleanup of txcmplq and reset the HBA */ | |
10196 | lpfc_sli_brdrestart(phba); | |
10197 | ||
72859909 JS |
10198 | kfree(phba->vpi_bmask); |
10199 | kfree(phba->vpi_ids); | |
10200 | ||
da0436e9 JS |
10201 | lpfc_stop_hba_timers(phba); |
10202 | spin_lock_irq(&phba->hbalock); | |
10203 | list_del_init(&vport->listentry); | |
10204 | spin_unlock_irq(&phba->hbalock); | |
10205 | ||
10206 | lpfc_debugfs_terminate(vport); | |
10207 | ||
912e3acd JS |
10208 | /* Disable SR-IOV if enabled */ |
10209 | if (phba->cfg_sriov_nr_virtfn) | |
10210 | pci_disable_sriov(pdev); | |
10211 | ||
da0436e9 JS |
10212 | /* Disable interrupt */ |
10213 | lpfc_sli_disable_intr(phba); | |
10214 | ||
da0436e9 JS |
10215 | scsi_host_put(shost); |
10216 | ||
10217 | /* | |
10218 | * Call scsi_free before mem_free since scsi bufs are released to their | |
10219 | * corresponding pools here. | |
10220 | */ | |
10221 | lpfc_scsi_free(phba); | |
10222 | lpfc_mem_free_all(phba); | |
10223 | ||
10224 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
10225 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
10226 | ||
10227 | /* Free resources associated with SLI2 interface */ | |
10228 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
10229 | phba->slim2p.virt, phba->slim2p.phys); | |
10230 | ||
10231 | /* unmap adapter SLIM and Control Registers */ | |
10232 | iounmap(phba->ctrl_regs_memmap_p); | |
10233 | iounmap(phba->slim_memmap_p); | |
10234 | ||
10235 | lpfc_hba_free(phba); | |
10236 | ||
e0c0483c | 10237 | pci_release_mem_regions(pdev); |
da0436e9 JS |
10238 | pci_disable_device(pdev); |
10239 | } | |
10240 | ||
10241 | /** | |
10242 | * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt | |
10243 | * @pdev: pointer to PCI device | |
10244 | * @msg: power management message | |
10245 | * | |
10246 | * This routine is to be called from the kernel's PCI subsystem to support | |
10247 | * system Power Management (PM) to device with SLI-3 interface spec. When | |
10248 | * PM invokes this method, it quiesces the device by stopping the driver's | |
10249 | * worker thread for the device, turning off device's interrupt and DMA, | |
10250 | * and bring the device offline. Note that as the driver implements the | |
10251 | * minimum PM requirements to a power-aware driver's PM support for the | |
10252 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
10253 | * to the suspend() method call will be treated as SUSPEND and the driver will | |
10254 | * fully reinitialize its device during resume() method call, the driver will | |
10255 | * set device to PCI_D3hot state in PCI config space instead of setting it | |
10256 | * according to the @msg provided by the PM. | |
10257 | * | |
10258 | * Return code | |
10259 | * 0 - driver suspended the device | |
10260 | * Error otherwise | |
10261 | **/ | |
10262 | static int | |
10263 | lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg) | |
10264 | { | |
10265 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10266 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10267 | ||
10268 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
10269 | "0473 PCI device Power Management suspend.\n"); | |
10270 | ||
10271 | /* Bring down the device */ | |
618a5230 | 10272 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
da0436e9 JS |
10273 | lpfc_offline(phba); |
10274 | kthread_stop(phba->worker_thread); | |
10275 | ||
10276 | /* Disable interrupt from device */ | |
10277 | lpfc_sli_disable_intr(phba); | |
10278 | ||
10279 | /* Save device state to PCI config space */ | |
10280 | pci_save_state(pdev); | |
10281 | pci_set_power_state(pdev, PCI_D3hot); | |
10282 | ||
10283 | return 0; | |
10284 | } | |
10285 | ||
10286 | /** | |
10287 | * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt | |
10288 | * @pdev: pointer to PCI device | |
10289 | * | |
10290 | * This routine is to be called from the kernel's PCI subsystem to support | |
10291 | * system Power Management (PM) to device with SLI-3 interface spec. When PM | |
10292 | * invokes this method, it restores the device's PCI config space state and | |
10293 | * fully reinitializes the device and brings it online. Note that as the | |
10294 | * driver implements the minimum PM requirements to a power-aware driver's | |
10295 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, | |
10296 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the | |
10297 | * driver will fully reinitialize its device during resume() method call, | |
10298 | * the device will be set to PCI_D0 directly in PCI config space before | |
10299 | * restoring the state. | |
10300 | * | |
10301 | * Return code | |
10302 | * 0 - driver suspended the device | |
10303 | * Error otherwise | |
10304 | **/ | |
10305 | static int | |
10306 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) | |
10307 | { | |
10308 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10309 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10310 | uint32_t intr_mode; | |
10311 | int error; | |
10312 | ||
10313 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
10314 | "0452 PCI device Power Management resume.\n"); | |
10315 | ||
10316 | /* Restore device state from PCI config space */ | |
10317 | pci_set_power_state(pdev, PCI_D0); | |
10318 | pci_restore_state(pdev); | |
0d878419 | 10319 | |
1dfb5a47 JS |
10320 | /* |
10321 | * As the new kernel behavior of pci_restore_state() API call clears | |
10322 | * device saved_state flag, need to save the restored state again. | |
10323 | */ | |
10324 | pci_save_state(pdev); | |
10325 | ||
da0436e9 JS |
10326 | if (pdev->is_busmaster) |
10327 | pci_set_master(pdev); | |
10328 | ||
10329 | /* Startup the kernel thread for this host adapter. */ | |
10330 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
10331 | "lpfc_worker_%d", phba->brd_no); | |
10332 | if (IS_ERR(phba->worker_thread)) { | |
10333 | error = PTR_ERR(phba->worker_thread); | |
10334 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10335 | "0434 PM resume failed to start worker " | |
10336 | "thread: error=x%x.\n", error); | |
10337 | return error; | |
10338 | } | |
10339 | ||
10340 | /* Configure and enable interrupt */ | |
10341 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
10342 | if (intr_mode == LPFC_INTR_ERROR) { | |
10343 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10344 | "0430 PM resume Failed to enable interrupt\n"); | |
10345 | return -EIO; | |
10346 | } else | |
10347 | phba->intr_mode = intr_mode; | |
10348 | ||
10349 | /* Restart HBA and bring it online */ | |
10350 | lpfc_sli_brdrestart(phba); | |
10351 | lpfc_online(phba); | |
10352 | ||
10353 | /* Log the current active interrupt mode */ | |
10354 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
10355 | ||
10356 | return 0; | |
10357 | } | |
10358 | ||
891478a2 JS |
10359 | /** |
10360 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover | |
10361 | * @phba: pointer to lpfc hba data structure. | |
10362 | * | |
10363 | * This routine is called to prepare the SLI3 device for PCI slot recover. It | |
e2af0d2e | 10364 | * aborts all the outstanding SCSI I/Os to the pci device. |
891478a2 JS |
10365 | **/ |
10366 | static void | |
10367 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) | |
10368 | { | |
10369 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10370 | "2723 PCI channel I/O abort preparing for recovery\n"); | |
e2af0d2e JS |
10371 | |
10372 | /* | |
10373 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
10374 | * and let the SCSI mid-layer to retry them to recover. | |
10375 | */ | |
db55fba8 | 10376 | lpfc_sli_abort_fcp_rings(phba); |
891478a2 JS |
10377 | } |
10378 | ||
0d878419 JS |
10379 | /** |
10380 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset | |
10381 | * @phba: pointer to lpfc hba data structure. | |
10382 | * | |
10383 | * This routine is called to prepare the SLI3 device for PCI slot reset. It | |
10384 | * disables the device interrupt and pci device, and aborts the internal FCP | |
10385 | * pending I/Os. | |
10386 | **/ | |
10387 | static void | |
10388 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) | |
10389 | { | |
0d878419 | 10390 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
891478a2 | 10391 | "2710 PCI channel disable preparing for reset\n"); |
e2af0d2e | 10392 | |
75baf696 | 10393 | /* Block any management I/Os to the device */ |
618a5230 | 10394 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
75baf696 | 10395 | |
e2af0d2e JS |
10396 | /* Block all SCSI devices' I/Os on the host */ |
10397 | lpfc_scsi_dev_block(phba); | |
10398 | ||
ea714f3d JS |
10399 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
10400 | lpfc_sli_flush_fcp_rings(phba); | |
10401 | ||
e2af0d2e JS |
10402 | /* stop all timers */ |
10403 | lpfc_stop_hba_timers(phba); | |
10404 | ||
0d878419 JS |
10405 | /* Disable interrupt and pci device */ |
10406 | lpfc_sli_disable_intr(phba); | |
10407 | pci_disable_device(phba->pcidev); | |
0d878419 JS |
10408 | } |
10409 | ||
10410 | /** | |
10411 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable | |
10412 | * @phba: pointer to lpfc hba data structure. | |
10413 | * | |
10414 | * This routine is called to prepare the SLI3 device for PCI slot permanently | |
10415 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
10416 | * pending I/Os. | |
10417 | **/ | |
10418 | static void | |
75baf696 | 10419 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
0d878419 JS |
10420 | { |
10421 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
891478a2 | 10422 | "2711 PCI channel permanent disable for failure\n"); |
e2af0d2e JS |
10423 | /* Block all SCSI devices' I/Os on the host */ |
10424 | lpfc_scsi_dev_block(phba); | |
10425 | ||
10426 | /* stop all timers */ | |
10427 | lpfc_stop_hba_timers(phba); | |
10428 | ||
0d878419 JS |
10429 | /* Clean up all driver's outstanding SCSI I/Os */ |
10430 | lpfc_sli_flush_fcp_rings(phba); | |
10431 | } | |
10432 | ||
da0436e9 JS |
10433 | /** |
10434 | * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error | |
10435 | * @pdev: pointer to PCI device. | |
10436 | * @state: the current PCI connection state. | |
10437 | * | |
10438 | * This routine is called from the PCI subsystem for I/O error handling to | |
10439 | * device with SLI-3 interface spec. This function is called by the PCI | |
10440 | * subsystem after a PCI bus error affecting this device has been detected. | |
10441 | * When this function is invoked, it will need to stop all the I/Os and | |
10442 | * interrupt(s) to the device. Once that is done, it will return | |
10443 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery | |
10444 | * as desired. | |
10445 | * | |
10446 | * Return codes | |
0d878419 | 10447 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
da0436e9 JS |
10448 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
10449 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
10450 | **/ | |
10451 | static pci_ers_result_t | |
10452 | lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state) | |
10453 | { | |
10454 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10455 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
da0436e9 | 10456 | |
0d878419 JS |
10457 | switch (state) { |
10458 | case pci_channel_io_normal: | |
891478a2 JS |
10459 | /* Non-fatal error, prepare for recovery */ |
10460 | lpfc_sli_prep_dev_for_recover(phba); | |
0d878419 JS |
10461 | return PCI_ERS_RESULT_CAN_RECOVER; |
10462 | case pci_channel_io_frozen: | |
10463 | /* Fatal error, prepare for slot reset */ | |
10464 | lpfc_sli_prep_dev_for_reset(phba); | |
10465 | return PCI_ERS_RESULT_NEED_RESET; | |
10466 | case pci_channel_io_perm_failure: | |
10467 | /* Permanent failure, prepare for device down */ | |
75baf696 | 10468 | lpfc_sli_prep_dev_for_perm_failure(phba); |
da0436e9 | 10469 | return PCI_ERS_RESULT_DISCONNECT; |
0d878419 JS |
10470 | default: |
10471 | /* Unknown state, prepare and request slot reset */ | |
10472 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10473 | "0472 Unknown PCI error state: x%x\n", state); | |
10474 | lpfc_sli_prep_dev_for_reset(phba); | |
10475 | return PCI_ERS_RESULT_NEED_RESET; | |
da0436e9 | 10476 | } |
da0436e9 JS |
10477 | } |
10478 | ||
10479 | /** | |
10480 | * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch. | |
10481 | * @pdev: pointer to PCI device. | |
10482 | * | |
10483 | * This routine is called from the PCI subsystem for error handling to | |
10484 | * device with SLI-3 interface spec. This is called after PCI bus has been | |
10485 | * reset to restart the PCI card from scratch, as if from a cold-boot. | |
10486 | * During the PCI subsystem error recovery, after driver returns | |
10487 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error | |
10488 | * recovery and then call this routine before calling the .resume method | |
10489 | * to recover the device. This function will initialize the HBA device, | |
10490 | * enable the interrupt, but it will just put the HBA to offline state | |
10491 | * without passing any I/O traffic. | |
10492 | * | |
10493 | * Return codes | |
10494 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
10495 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
10496 | */ | |
10497 | static pci_ers_result_t | |
10498 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) | |
10499 | { | |
10500 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10501 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10502 | struct lpfc_sli *psli = &phba->sli; | |
10503 | uint32_t intr_mode; | |
10504 | ||
10505 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
10506 | if (pci_enable_device_mem(pdev)) { | |
10507 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
10508 | "PCI device after reset.\n"); | |
10509 | return PCI_ERS_RESULT_DISCONNECT; | |
10510 | } | |
10511 | ||
10512 | pci_restore_state(pdev); | |
1dfb5a47 JS |
10513 | |
10514 | /* | |
10515 | * As the new kernel behavior of pci_restore_state() API call clears | |
10516 | * device saved_state flag, need to save the restored state again. | |
10517 | */ | |
10518 | pci_save_state(pdev); | |
10519 | ||
da0436e9 JS |
10520 | if (pdev->is_busmaster) |
10521 | pci_set_master(pdev); | |
10522 | ||
10523 | spin_lock_irq(&phba->hbalock); | |
10524 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
10525 | spin_unlock_irq(&phba->hbalock); | |
10526 | ||
10527 | /* Configure and enable interrupt */ | |
10528 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
10529 | if (intr_mode == LPFC_INTR_ERROR) { | |
10530 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10531 | "0427 Cannot re-enable interrupt after " | |
10532 | "slot reset.\n"); | |
10533 | return PCI_ERS_RESULT_DISCONNECT; | |
10534 | } else | |
10535 | phba->intr_mode = intr_mode; | |
10536 | ||
75baf696 | 10537 | /* Take device offline, it will perform cleanup */ |
618a5230 | 10538 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
da0436e9 JS |
10539 | lpfc_offline(phba); |
10540 | lpfc_sli_brdrestart(phba); | |
10541 | ||
10542 | /* Log the current active interrupt mode */ | |
10543 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
10544 | ||
10545 | return PCI_ERS_RESULT_RECOVERED; | |
10546 | } | |
10547 | ||
10548 | /** | |
10549 | * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device. | |
10550 | * @pdev: pointer to PCI device | |
10551 | * | |
10552 | * This routine is called from the PCI subsystem for error handling to device | |
10553 | * with SLI-3 interface spec. It is called when kernel error recovery tells | |
10554 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus | |
10555 | * error recovery. After this call, traffic can start to flow from this device | |
10556 | * again. | |
10557 | */ | |
10558 | static void | |
10559 | lpfc_io_resume_s3(struct pci_dev *pdev) | |
10560 | { | |
10561 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10562 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
3772a991 | 10563 | |
e2af0d2e | 10564 | /* Bring device online, it will be no-op for non-fatal error resume */ |
da0436e9 | 10565 | lpfc_online(phba); |
0d878419 JS |
10566 | |
10567 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
10568 | if (phba->hba_flag & HBA_AER_ENABLED) | |
10569 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
da0436e9 | 10570 | } |
3772a991 | 10571 | |
da0436e9 JS |
10572 | /** |
10573 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve | |
10574 | * @phba: pointer to lpfc hba data structure. | |
10575 | * | |
10576 | * returns the number of ELS/CT IOCBs to reserve | |
10577 | **/ | |
10578 | int | |
10579 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) | |
10580 | { | |
10581 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; | |
10582 | ||
f1126688 JS |
10583 | if (phba->sli_rev == LPFC_SLI_REV4) { |
10584 | if (max_xri <= 100) | |
6a9c52cf | 10585 | return 10; |
f1126688 | 10586 | else if (max_xri <= 256) |
6a9c52cf | 10587 | return 25; |
f1126688 | 10588 | else if (max_xri <= 512) |
6a9c52cf | 10589 | return 50; |
f1126688 | 10590 | else if (max_xri <= 1024) |
6a9c52cf | 10591 | return 100; |
8a9d2e80 | 10592 | else if (max_xri <= 1536) |
6a9c52cf | 10593 | return 150; |
8a9d2e80 JS |
10594 | else if (max_xri <= 2048) |
10595 | return 200; | |
10596 | else | |
10597 | return 250; | |
f1126688 JS |
10598 | } else |
10599 | return 0; | |
3772a991 JS |
10600 | } |
10601 | ||
895427bd JS |
10602 | /** |
10603 | * lpfc_sli4_get_iocb_cnt - Calculate the # of total IOCBs to reserve | |
10604 | * @phba: pointer to lpfc hba data structure. | |
10605 | * | |
f358dd0c | 10606 | * returns the number of ELS/CT + NVMET IOCBs to reserve |
895427bd JS |
10607 | **/ |
10608 | int | |
10609 | lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba) | |
10610 | { | |
10611 | int max_xri = lpfc_sli4_get_els_iocb_cnt(phba); | |
10612 | ||
f358dd0c JS |
10613 | if (phba->nvmet_support) |
10614 | max_xri += LPFC_NVMET_BUF_POST; | |
895427bd JS |
10615 | return max_xri; |
10616 | } | |
10617 | ||
10618 | ||
52d52440 JS |
10619 | /** |
10620 | * lpfc_write_firmware - attempt to write a firmware image to the port | |
52d52440 | 10621 | * @fw: pointer to firmware image returned from request_firmware. |
ce396282 | 10622 | * @phba: pointer to lpfc hba data structure. |
52d52440 | 10623 | * |
52d52440 | 10624 | **/ |
ce396282 JS |
10625 | static void |
10626 | lpfc_write_firmware(const struct firmware *fw, void *context) | |
52d52440 | 10627 | { |
ce396282 | 10628 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
6b5151fd | 10629 | char fwrev[FW_REV_STR_SIZE]; |
ce396282 | 10630 | struct lpfc_grp_hdr *image; |
52d52440 JS |
10631 | struct list_head dma_buffer_list; |
10632 | int i, rc = 0; | |
10633 | struct lpfc_dmabuf *dmabuf, *next; | |
10634 | uint32_t offset = 0, temp_offset = 0; | |
6b6ef5db | 10635 | uint32_t magic_number, ftype, fid, fsize; |
52d52440 | 10636 | |
c71ab861 | 10637 | /* It can be null in no-wait mode, sanity check */ |
ce396282 JS |
10638 | if (!fw) { |
10639 | rc = -ENXIO; | |
10640 | goto out; | |
10641 | } | |
10642 | image = (struct lpfc_grp_hdr *)fw->data; | |
10643 | ||
6b6ef5db JS |
10644 | magic_number = be32_to_cpu(image->magic_number); |
10645 | ftype = bf_get_be32(lpfc_grp_hdr_file_type, image); | |
10646 | fid = bf_get_be32(lpfc_grp_hdr_id, image), | |
10647 | fsize = be32_to_cpu(image->size); | |
10648 | ||
52d52440 | 10649 | INIT_LIST_HEAD(&dma_buffer_list); |
6b6ef5db JS |
10650 | if ((magic_number != LPFC_GROUP_OJECT_MAGIC_G5 && |
10651 | magic_number != LPFC_GROUP_OJECT_MAGIC_G6) || | |
10652 | ftype != LPFC_FILE_TYPE_GROUP || fsize != fw->size) { | |
52d52440 JS |
10653 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
10654 | "3022 Invalid FW image found. " | |
efe583c6 | 10655 | "Magic:%x Type:%x ID:%x Size %d %zd\n", |
6b6ef5db | 10656 | magic_number, ftype, fid, fsize, fw->size); |
ce396282 JS |
10657 | rc = -EINVAL; |
10658 | goto release_out; | |
52d52440 JS |
10659 | } |
10660 | lpfc_decode_firmware_rev(phba, fwrev, 1); | |
88a2cfbb | 10661 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
52d52440 | 10662 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
ce396282 | 10663 | "3023 Updating Firmware, Current Version:%s " |
52d52440 | 10664 | "New Version:%s\n", |
88a2cfbb | 10665 | fwrev, image->revision); |
52d52440 JS |
10666 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
10667 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), | |
10668 | GFP_KERNEL); | |
10669 | if (!dmabuf) { | |
10670 | rc = -ENOMEM; | |
ce396282 | 10671 | goto release_out; |
52d52440 JS |
10672 | } |
10673 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
10674 | SLI4_PAGE_SIZE, | |
10675 | &dmabuf->phys, | |
10676 | GFP_KERNEL); | |
10677 | if (!dmabuf->virt) { | |
10678 | kfree(dmabuf); | |
10679 | rc = -ENOMEM; | |
ce396282 | 10680 | goto release_out; |
52d52440 JS |
10681 | } |
10682 | list_add_tail(&dmabuf->list, &dma_buffer_list); | |
10683 | } | |
10684 | while (offset < fw->size) { | |
10685 | temp_offset = offset; | |
10686 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { | |
079b5c91 | 10687 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
52d52440 JS |
10688 | memcpy(dmabuf->virt, |
10689 | fw->data + temp_offset, | |
079b5c91 JS |
10690 | fw->size - temp_offset); |
10691 | temp_offset = fw->size; | |
52d52440 JS |
10692 | break; |
10693 | } | |
52d52440 JS |
10694 | memcpy(dmabuf->virt, fw->data + temp_offset, |
10695 | SLI4_PAGE_SIZE); | |
88a2cfbb | 10696 | temp_offset += SLI4_PAGE_SIZE; |
52d52440 JS |
10697 | } |
10698 | rc = lpfc_wr_object(phba, &dma_buffer_list, | |
10699 | (fw->size - offset), &offset); | |
ce396282 JS |
10700 | if (rc) |
10701 | goto release_out; | |
52d52440 JS |
10702 | } |
10703 | rc = offset; | |
10704 | } | |
ce396282 JS |
10705 | |
10706 | release_out: | |
52d52440 JS |
10707 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
10708 | list_del(&dmabuf->list); | |
10709 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, | |
10710 | dmabuf->virt, dmabuf->phys); | |
10711 | kfree(dmabuf); | |
10712 | } | |
ce396282 JS |
10713 | release_firmware(fw); |
10714 | out: | |
10715 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
c71ab861 | 10716 | "3024 Firmware update done: %d.\n", rc); |
ce396282 | 10717 | return; |
52d52440 JS |
10718 | } |
10719 | ||
c71ab861 JS |
10720 | /** |
10721 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade | |
10722 | * @phba: pointer to lpfc hba data structure. | |
10723 | * | |
10724 | * This routine is called to perform Linux generic firmware upgrade on device | |
10725 | * that supports such feature. | |
10726 | **/ | |
10727 | int | |
10728 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) | |
10729 | { | |
10730 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; | |
10731 | int ret; | |
10732 | const struct firmware *fw; | |
10733 | ||
10734 | /* Only supported on SLI4 interface type 2 for now */ | |
10735 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
10736 | LPFC_SLI_INTF_IF_TYPE_2) | |
10737 | return -EPERM; | |
10738 | ||
10739 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); | |
10740 | ||
10741 | if (fw_upgrade == INT_FW_UPGRADE) { | |
10742 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, | |
10743 | file_name, &phba->pcidev->dev, | |
10744 | GFP_KERNEL, (void *)phba, | |
10745 | lpfc_write_firmware); | |
10746 | } else if (fw_upgrade == RUN_FW_UPGRADE) { | |
10747 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); | |
10748 | if (!ret) | |
10749 | lpfc_write_firmware(fw, (void *)phba); | |
10750 | } else { | |
10751 | ret = -EINVAL; | |
10752 | } | |
10753 | ||
10754 | return ret; | |
10755 | } | |
10756 | ||
3772a991 | 10757 | /** |
da0436e9 | 10758 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
3772a991 JS |
10759 | * @pdev: pointer to PCI device |
10760 | * @pid: pointer to PCI device identifier | |
10761 | * | |
da0436e9 JS |
10762 | * This routine is called from the kernel's PCI subsystem to device with |
10763 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 | 10764 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
da0436e9 JS |
10765 | * information of the device and driver to see if the driver state that it |
10766 | * can support this kind of device. If the match is successful, the driver | |
10767 | * core invokes this routine. If this routine determines it can claim the HBA, | |
10768 | * it does all the initialization that it needs to do to handle the HBA | |
10769 | * properly. | |
3772a991 JS |
10770 | * |
10771 | * Return code | |
10772 | * 0 - driver can claim the device | |
10773 | * negative value - driver can not claim the device | |
10774 | **/ | |
6f039790 | 10775 | static int |
da0436e9 | 10776 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
3772a991 JS |
10777 | { |
10778 | struct lpfc_hba *phba; | |
10779 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 10780 | struct Scsi_Host *shost = NULL; |
db6f1c2f | 10781 | int error; |
3772a991 JS |
10782 | uint32_t cfg_mode, intr_mode; |
10783 | ||
10784 | /* Allocate memory for HBA structure */ | |
10785 | phba = lpfc_hba_alloc(pdev); | |
10786 | if (!phba) | |
10787 | return -ENOMEM; | |
10788 | ||
10789 | /* Perform generic PCI device enabling operation */ | |
10790 | error = lpfc_enable_pci_dev(phba); | |
079b5c91 | 10791 | if (error) |
3772a991 | 10792 | goto out_free_phba; |
3772a991 | 10793 | |
da0436e9 JS |
10794 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
10795 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); | |
3772a991 JS |
10796 | if (error) |
10797 | goto out_disable_pci_dev; | |
10798 | ||
da0436e9 JS |
10799 | /* Set up SLI-4 specific device PCI memory space */ |
10800 | error = lpfc_sli4_pci_mem_setup(phba); | |
3772a991 JS |
10801 | if (error) { |
10802 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 10803 | "1410 Failed to set up pci memory space.\n"); |
3772a991 JS |
10804 | goto out_disable_pci_dev; |
10805 | } | |
10806 | ||
da0436e9 JS |
10807 | /* Set up SLI-4 Specific device driver resources */ |
10808 | error = lpfc_sli4_driver_resource_setup(phba); | |
3772a991 JS |
10809 | if (error) { |
10810 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
10811 | "1412 Failed to set up driver resource.\n"); |
10812 | goto out_unset_pci_mem_s4; | |
3772a991 JS |
10813 | } |
10814 | ||
10815 | /* Initialize and populate the iocb list per host */ | |
2a9bf3d0 JS |
10816 | |
10817 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
10818 | "2821 initialize iocb list %d.\n", | |
10819 | phba->cfg_iocb_cnt*1024); | |
10820 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); | |
10821 | ||
3772a991 JS |
10822 | if (error) { |
10823 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
10824 | "1413 Failed to initialize iocb list.\n"); |
10825 | goto out_unset_driver_resource_s4; | |
3772a991 JS |
10826 | } |
10827 | ||
19ca7609 | 10828 | INIT_LIST_HEAD(&phba->active_rrq_list); |
7d791df7 | 10829 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
19ca7609 | 10830 | |
3772a991 JS |
10831 | /* Set up common device driver resources */ |
10832 | error = lpfc_setup_driver_resource_phase2(phba); | |
10833 | if (error) { | |
10834 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 10835 | "1414 Failed to set up driver resource.\n"); |
3772a991 JS |
10836 | goto out_free_iocb_list; |
10837 | } | |
10838 | ||
079b5c91 JS |
10839 | /* Get the default values for Model Name and Description */ |
10840 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
10841 | ||
3772a991 JS |
10842 | /* Create SCSI host to the physical port */ |
10843 | error = lpfc_create_shost(phba); | |
10844 | if (error) { | |
10845 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 10846 | "1415 Failed to create scsi host.\n"); |
3772a991 JS |
10847 | goto out_unset_driver_resource; |
10848 | } | |
9399627f | 10849 | |
5b75da2f | 10850 | /* Configure sysfs attributes */ |
3772a991 JS |
10851 | vport = phba->pport; |
10852 | error = lpfc_alloc_sysfs_attr(vport); | |
10853 | if (error) { | |
9399627f | 10854 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 10855 | "1416 Failed to allocate sysfs attr\n"); |
3772a991 | 10856 | goto out_destroy_shost; |
98c9ea5c | 10857 | } |
875fbdfe | 10858 | |
6669f9bb | 10859 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
3772a991 | 10860 | /* Now, trying to enable interrupt and bring up the device */ |
5b75da2f | 10861 | cfg_mode = phba->cfg_use_msi; |
5b75da2f | 10862 | |
7b15db32 JS |
10863 | /* Put device to a known state before enabling interrupt */ |
10864 | lpfc_stop_port(phba); | |
895427bd | 10865 | |
7b15db32 JS |
10866 | /* Configure and enable interrupt */ |
10867 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); | |
10868 | if (intr_mode == LPFC_INTR_ERROR) { | |
10869 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10870 | "0426 Failed to enable interrupt.\n"); | |
10871 | error = -ENODEV; | |
10872 | goto out_free_sysfs_attr; | |
10873 | } | |
10874 | /* Default to single EQ for non-MSI-X */ | |
895427bd JS |
10875 | if (phba->intr_type != MSIX) { |
10876 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP) | |
10877 | phba->cfg_fcp_io_channel = 1; | |
10878 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME) | |
10879 | phba->cfg_nvme_io_channel = 1; | |
10880 | phba->io_channel_irqs = 1; | |
10881 | } | |
10882 | ||
10883 | ||
7b15db32 JS |
10884 | /* Set up SLI-4 HBA */ |
10885 | if (lpfc_sli4_hba_setup(phba)) { | |
10886 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10887 | "1421 Failed to set up hba\n"); | |
10888 | error = -ENODEV; | |
10889 | goto out_disable_intr; | |
98c9ea5c | 10890 | } |
858c9f6c | 10891 | |
7b15db32 JS |
10892 | /* Log the current active interrupt mode */ |
10893 | phba->intr_mode = intr_mode; | |
10894 | lpfc_log_intr_mode(phba, intr_mode); | |
10895 | ||
3772a991 JS |
10896 | /* Perform post initialization setup */ |
10897 | lpfc_post_init_setup(phba); | |
dea3101e | 10898 | |
01649561 JS |
10899 | /* NVME support in FW earlier in the driver load corrects the |
10900 | * FC4 type making a check for nvme_support unnecessary. | |
10901 | */ | |
10902 | if ((phba->nvmet_support == 0) && | |
10903 | (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) { | |
10904 | /* Create NVME binding with nvme_fc_transport. This | |
10905 | * ensures the vport is initialized. | |
10906 | */ | |
10907 | error = lpfc_nvme_create_localport(vport); | |
10908 | if (error) { | |
10909 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10910 | "6004 NVME registration failed, " | |
10911 | "error x%x\n", | |
10912 | error); | |
10913 | goto out_disable_intr; | |
10914 | } | |
10915 | } | |
895427bd | 10916 | |
c71ab861 JS |
10917 | /* check for firmware upgrade or downgrade */ |
10918 | if (phba->cfg_request_firmware_upgrade) | |
db6f1c2f | 10919 | lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); |
52d52440 | 10920 | |
1c6834a7 JS |
10921 | /* Check if there are static vports to be created. */ |
10922 | lpfc_create_static_vport(phba); | |
dea3101e JB |
10923 | return 0; |
10924 | ||
da0436e9 JS |
10925 | out_disable_intr: |
10926 | lpfc_sli4_disable_intr(phba); | |
5b75da2f JS |
10927 | out_free_sysfs_attr: |
10928 | lpfc_free_sysfs_attr(vport); | |
3772a991 JS |
10929 | out_destroy_shost: |
10930 | lpfc_destroy_shost(phba); | |
10931 | out_unset_driver_resource: | |
10932 | lpfc_unset_driver_resource_phase2(phba); | |
10933 | out_free_iocb_list: | |
10934 | lpfc_free_iocb_list(phba); | |
da0436e9 JS |
10935 | out_unset_driver_resource_s4: |
10936 | lpfc_sli4_driver_resource_unset(phba); | |
10937 | out_unset_pci_mem_s4: | |
10938 | lpfc_sli4_pci_mem_unset(phba); | |
3772a991 JS |
10939 | out_disable_pci_dev: |
10940 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
10941 | if (shost) |
10942 | scsi_host_put(shost); | |
2e0fef85 | 10943 | out_free_phba: |
3772a991 | 10944 | lpfc_hba_free(phba); |
dea3101e JB |
10945 | return error; |
10946 | } | |
10947 | ||
e59058c4 | 10948 | /** |
da0436e9 | 10949 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
e59058c4 JS |
10950 | * @pdev: pointer to PCI device |
10951 | * | |
da0436e9 JS |
10952 | * This routine is called from the kernel's PCI subsystem to device with |
10953 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 JS |
10954 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
10955 | * device to be removed from the PCI subsystem properly. | |
e59058c4 | 10956 | **/ |
6f039790 | 10957 | static void |
da0436e9 | 10958 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
dea3101e | 10959 | { |
da0436e9 | 10960 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2e0fef85 | 10961 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
eada272d | 10962 | struct lpfc_vport **vports; |
da0436e9 | 10963 | struct lpfc_hba *phba = vport->phba; |
eada272d | 10964 | int i; |
8a4df120 | 10965 | |
da0436e9 | 10966 | /* Mark the device unloading flag */ |
549e55cd | 10967 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 10968 | vport->load_flag |= FC_UNLOADING; |
549e55cd | 10969 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 10970 | |
da0436e9 | 10971 | /* Free the HBA sysfs attributes */ |
858c9f6c JS |
10972 | lpfc_free_sysfs_attr(vport); |
10973 | ||
eada272d JS |
10974 | /* Release all the vports against this physical port */ |
10975 | vports = lpfc_create_vport_work_array(phba); | |
10976 | if (vports != NULL) | |
587a37f6 JS |
10977 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
10978 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) | |
10979 | continue; | |
eada272d | 10980 | fc_vport_terminate(vports[i]->fc_vport); |
587a37f6 | 10981 | } |
eada272d JS |
10982 | lpfc_destroy_vport_work_array(phba, vports); |
10983 | ||
10984 | /* Remove FC host and then SCSI host with the physical port */ | |
858c9f6c JS |
10985 | fc_remove_host(shost); |
10986 | scsi_remove_host(shost); | |
f358dd0c | 10987 | /* todo: tgt: remove targetport */ |
da0436e9 | 10988 | |
895427bd JS |
10989 | /* Perform ndlp cleanup on the physical port. The nvme localport |
10990 | * is destroyed after to ensure all rports are io-disabled. | |
10991 | */ | |
01649561 | 10992 | lpfc_nvme_destroy_localport(vport); |
87af33fe JS |
10993 | lpfc_cleanup(vport); |
10994 | ||
2e0fef85 | 10995 | /* |
da0436e9 | 10996 | * Bring down the SLI Layer. This step disables all interrupts, |
2e0fef85 | 10997 | * clears the rings, discards all mailbox commands, and resets |
da0436e9 | 10998 | * the HBA FCoE function. |
2e0fef85 | 10999 | */ |
da0436e9 JS |
11000 | lpfc_debugfs_terminate(vport); |
11001 | lpfc_sli4_hba_unset(phba); | |
a257bf90 | 11002 | |
858c9f6c JS |
11003 | spin_lock_irq(&phba->hbalock); |
11004 | list_del_init(&vport->listentry); | |
11005 | spin_unlock_irq(&phba->hbalock); | |
11006 | ||
3677a3a7 | 11007 | /* Perform scsi free before driver resource_unset since scsi |
da0436e9 | 11008 | * buffers are released to their corresponding pools here. |
2e0fef85 JS |
11009 | */ |
11010 | lpfc_scsi_free(phba); | |
895427bd | 11011 | lpfc_nvme_free(phba); |
01649561 | 11012 | lpfc_free_iocb_list(phba); |
67d12733 | 11013 | |
da0436e9 | 11014 | lpfc_sli4_driver_resource_unset(phba); |
ed957684 | 11015 | |
da0436e9 JS |
11016 | /* Unmap adapter Control and Doorbell registers */ |
11017 | lpfc_sli4_pci_mem_unset(phba); | |
2e0fef85 | 11018 | |
da0436e9 JS |
11019 | /* Release PCI resources and disable device's PCI function */ |
11020 | scsi_host_put(shost); | |
11021 | lpfc_disable_pci_dev(phba); | |
2e0fef85 | 11022 | |
da0436e9 | 11023 | /* Finally, free the driver's device data structure */ |
3772a991 | 11024 | lpfc_hba_free(phba); |
2e0fef85 | 11025 | |
da0436e9 | 11026 | return; |
dea3101e JB |
11027 | } |
11028 | ||
3a55b532 | 11029 | /** |
da0436e9 | 11030 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
3a55b532 JS |
11031 | * @pdev: pointer to PCI device |
11032 | * @msg: power management message | |
11033 | * | |
da0436e9 JS |
11034 | * This routine is called from the kernel's PCI subsystem to support system |
11035 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes | |
11036 | * this method, it quiesces the device by stopping the driver's worker | |
11037 | * thread for the device, turning off device's interrupt and DMA, and bring | |
11038 | * the device offline. Note that as the driver implements the minimum PM | |
11039 | * requirements to a power-aware driver's PM support for suspend/resume -- all | |
11040 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() | |
11041 | * method call will be treated as SUSPEND and the driver will fully | |
11042 | * reinitialize its device during resume() method call, the driver will set | |
11043 | * device to PCI_D3hot state in PCI config space instead of setting it | |
3772a991 | 11044 | * according to the @msg provided by the PM. |
3a55b532 JS |
11045 | * |
11046 | * Return code | |
3772a991 JS |
11047 | * 0 - driver suspended the device |
11048 | * Error otherwise | |
3a55b532 JS |
11049 | **/ |
11050 | static int | |
da0436e9 | 11051 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
3a55b532 JS |
11052 | { |
11053 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
11054 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
11055 | ||
11056 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
75baf696 | 11057 | "2843 PCI device Power Management suspend.\n"); |
3a55b532 JS |
11058 | |
11059 | /* Bring down the device */ | |
618a5230 | 11060 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
3a55b532 JS |
11061 | lpfc_offline(phba); |
11062 | kthread_stop(phba->worker_thread); | |
11063 | ||
11064 | /* Disable interrupt from device */ | |
da0436e9 | 11065 | lpfc_sli4_disable_intr(phba); |
5350d872 | 11066 | lpfc_sli4_queue_destroy(phba); |
3a55b532 JS |
11067 | |
11068 | /* Save device state to PCI config space */ | |
11069 | pci_save_state(pdev); | |
11070 | pci_set_power_state(pdev, PCI_D3hot); | |
11071 | ||
11072 | return 0; | |
11073 | } | |
11074 | ||
11075 | /** | |
da0436e9 | 11076 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
3a55b532 JS |
11077 | * @pdev: pointer to PCI device |
11078 | * | |
da0436e9 JS |
11079 | * This routine is called from the kernel's PCI subsystem to support system |
11080 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes | |
11081 | * this method, it restores the device's PCI config space state and fully | |
11082 | * reinitializes the device and brings it online. Note that as the driver | |
11083 | * implements the minimum PM requirements to a power-aware driver's PM for | |
11084 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
11085 | * to the suspend() method call will be treated as SUSPEND and the driver | |
11086 | * will fully reinitialize its device during resume() method call, the device | |
11087 | * will be set to PCI_D0 directly in PCI config space before restoring the | |
11088 | * state. | |
3a55b532 JS |
11089 | * |
11090 | * Return code | |
3772a991 JS |
11091 | * 0 - driver suspended the device |
11092 | * Error otherwise | |
3a55b532 JS |
11093 | **/ |
11094 | static int | |
da0436e9 | 11095 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
3a55b532 JS |
11096 | { |
11097 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
11098 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
5b75da2f | 11099 | uint32_t intr_mode; |
3a55b532 JS |
11100 | int error; |
11101 | ||
11102 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
da0436e9 | 11103 | "0292 PCI device Power Management resume.\n"); |
3a55b532 JS |
11104 | |
11105 | /* Restore device state from PCI config space */ | |
11106 | pci_set_power_state(pdev, PCI_D0); | |
11107 | pci_restore_state(pdev); | |
1dfb5a47 JS |
11108 | |
11109 | /* | |
11110 | * As the new kernel behavior of pci_restore_state() API call clears | |
11111 | * device saved_state flag, need to save the restored state again. | |
11112 | */ | |
11113 | pci_save_state(pdev); | |
11114 | ||
3a55b532 JS |
11115 | if (pdev->is_busmaster) |
11116 | pci_set_master(pdev); | |
11117 | ||
da0436e9 | 11118 | /* Startup the kernel thread for this host adapter. */ |
3a55b532 JS |
11119 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
11120 | "lpfc_worker_%d", phba->brd_no); | |
11121 | if (IS_ERR(phba->worker_thread)) { | |
11122 | error = PTR_ERR(phba->worker_thread); | |
11123 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 11124 | "0293 PM resume failed to start worker " |
3a55b532 JS |
11125 | "thread: error=x%x.\n", error); |
11126 | return error; | |
11127 | } | |
11128 | ||
5b75da2f | 11129 | /* Configure and enable interrupt */ |
da0436e9 | 11130 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
5b75da2f | 11131 | if (intr_mode == LPFC_INTR_ERROR) { |
3a55b532 | 11132 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 11133 | "0294 PM resume Failed to enable interrupt\n"); |
5b75da2f JS |
11134 | return -EIO; |
11135 | } else | |
11136 | phba->intr_mode = intr_mode; | |
3a55b532 JS |
11137 | |
11138 | /* Restart HBA and bring it online */ | |
11139 | lpfc_sli_brdrestart(phba); | |
11140 | lpfc_online(phba); | |
11141 | ||
5b75da2f JS |
11142 | /* Log the current active interrupt mode */ |
11143 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
11144 | ||
3a55b532 JS |
11145 | return 0; |
11146 | } | |
11147 | ||
75baf696 JS |
11148 | /** |
11149 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover | |
11150 | * @phba: pointer to lpfc hba data structure. | |
11151 | * | |
11152 | * This routine is called to prepare the SLI4 device for PCI slot recover. It | |
11153 | * aborts all the outstanding SCSI I/Os to the pci device. | |
11154 | **/ | |
11155 | static void | |
11156 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) | |
11157 | { | |
75baf696 JS |
11158 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
11159 | "2828 PCI channel I/O abort preparing for recovery\n"); | |
11160 | /* | |
11161 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
11162 | * and let the SCSI mid-layer to retry them to recover. | |
11163 | */ | |
db55fba8 | 11164 | lpfc_sli_abort_fcp_rings(phba); |
75baf696 JS |
11165 | } |
11166 | ||
11167 | /** | |
11168 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset | |
11169 | * @phba: pointer to lpfc hba data structure. | |
11170 | * | |
11171 | * This routine is called to prepare the SLI4 device for PCI slot reset. It | |
11172 | * disables the device interrupt and pci device, and aborts the internal FCP | |
11173 | * pending I/Os. | |
11174 | **/ | |
11175 | static void | |
11176 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) | |
11177 | { | |
11178 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11179 | "2826 PCI channel disable preparing for reset\n"); | |
11180 | ||
11181 | /* Block any management I/Os to the device */ | |
618a5230 | 11182 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
75baf696 JS |
11183 | |
11184 | /* Block all SCSI devices' I/Os on the host */ | |
11185 | lpfc_scsi_dev_block(phba); | |
11186 | ||
ea714f3d JS |
11187 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
11188 | lpfc_sli_flush_fcp_rings(phba); | |
11189 | ||
75baf696 JS |
11190 | /* stop all timers */ |
11191 | lpfc_stop_hba_timers(phba); | |
11192 | ||
11193 | /* Disable interrupt and pci device */ | |
11194 | lpfc_sli4_disable_intr(phba); | |
5350d872 | 11195 | lpfc_sli4_queue_destroy(phba); |
75baf696 | 11196 | pci_disable_device(phba->pcidev); |
75baf696 JS |
11197 | } |
11198 | ||
11199 | /** | |
11200 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable | |
11201 | * @phba: pointer to lpfc hba data structure. | |
11202 | * | |
11203 | * This routine is called to prepare the SLI4 device for PCI slot permanently | |
11204 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
11205 | * pending I/Os. | |
11206 | **/ | |
11207 | static void | |
11208 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) | |
11209 | { | |
11210 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11211 | "2827 PCI channel permanent disable for failure\n"); | |
11212 | ||
11213 | /* Block all SCSI devices' I/Os on the host */ | |
11214 | lpfc_scsi_dev_block(phba); | |
11215 | ||
11216 | /* stop all timers */ | |
11217 | lpfc_stop_hba_timers(phba); | |
11218 | ||
11219 | /* Clean up all driver's outstanding SCSI I/Os */ | |
11220 | lpfc_sli_flush_fcp_rings(phba); | |
11221 | } | |
11222 | ||
8d63f375 | 11223 | /** |
da0436e9 | 11224 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
e59058c4 JS |
11225 | * @pdev: pointer to PCI device. |
11226 | * @state: the current PCI connection state. | |
8d63f375 | 11227 | * |
da0436e9 JS |
11228 | * This routine is called from the PCI subsystem for error handling to device |
11229 | * with SLI-4 interface spec. This function is called by the PCI subsystem | |
11230 | * after a PCI bus error affecting this device has been detected. When this | |
11231 | * function is invoked, it will need to stop all the I/Os and interrupt(s) | |
11232 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET | |
11233 | * for the PCI subsystem to perform proper recovery as desired. | |
e59058c4 JS |
11234 | * |
11235 | * Return codes | |
3772a991 JS |
11236 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
11237 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
e59058c4 | 11238 | **/ |
3772a991 | 11239 | static pci_ers_result_t |
da0436e9 | 11240 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
8d63f375 | 11241 | { |
75baf696 JS |
11242 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
11243 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
11244 | ||
11245 | switch (state) { | |
11246 | case pci_channel_io_normal: | |
11247 | /* Non-fatal error, prepare for recovery */ | |
11248 | lpfc_sli4_prep_dev_for_recover(phba); | |
11249 | return PCI_ERS_RESULT_CAN_RECOVER; | |
11250 | case pci_channel_io_frozen: | |
11251 | /* Fatal error, prepare for slot reset */ | |
11252 | lpfc_sli4_prep_dev_for_reset(phba); | |
11253 | return PCI_ERS_RESULT_NEED_RESET; | |
11254 | case pci_channel_io_perm_failure: | |
11255 | /* Permanent failure, prepare for device down */ | |
11256 | lpfc_sli4_prep_dev_for_perm_failure(phba); | |
11257 | return PCI_ERS_RESULT_DISCONNECT; | |
11258 | default: | |
11259 | /* Unknown state, prepare and request slot reset */ | |
11260 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11261 | "2825 Unknown PCI error state: x%x\n", state); | |
11262 | lpfc_sli4_prep_dev_for_reset(phba); | |
11263 | return PCI_ERS_RESULT_NEED_RESET; | |
11264 | } | |
8d63f375 LV |
11265 | } |
11266 | ||
11267 | /** | |
da0436e9 | 11268 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
e59058c4 JS |
11269 | * @pdev: pointer to PCI device. |
11270 | * | |
da0436e9 JS |
11271 | * This routine is called from the PCI subsystem for error handling to device |
11272 | * with SLI-4 interface spec. It is called after PCI bus has been reset to | |
11273 | * restart the PCI card from scratch, as if from a cold-boot. During the | |
11274 | * PCI subsystem error recovery, after the driver returns | |
3772a991 | 11275 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
da0436e9 JS |
11276 | * recovery and then call this routine before calling the .resume method to |
11277 | * recover the device. This function will initialize the HBA device, enable | |
11278 | * the interrupt, but it will just put the HBA to offline state without | |
11279 | * passing any I/O traffic. | |
8d63f375 | 11280 | * |
e59058c4 | 11281 | * Return codes |
3772a991 JS |
11282 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
11283 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8d63f375 | 11284 | */ |
3772a991 | 11285 | static pci_ers_result_t |
da0436e9 | 11286 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
8d63f375 | 11287 | { |
75baf696 JS |
11288 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
11289 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
11290 | struct lpfc_sli *psli = &phba->sli; | |
11291 | uint32_t intr_mode; | |
11292 | ||
11293 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
11294 | if (pci_enable_device_mem(pdev)) { | |
11295 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
11296 | "PCI device after reset.\n"); | |
11297 | return PCI_ERS_RESULT_DISCONNECT; | |
11298 | } | |
11299 | ||
11300 | pci_restore_state(pdev); | |
0a96e975 JS |
11301 | |
11302 | /* | |
11303 | * As the new kernel behavior of pci_restore_state() API call clears | |
11304 | * device saved_state flag, need to save the restored state again. | |
11305 | */ | |
11306 | pci_save_state(pdev); | |
11307 | ||
75baf696 JS |
11308 | if (pdev->is_busmaster) |
11309 | pci_set_master(pdev); | |
11310 | ||
11311 | spin_lock_irq(&phba->hbalock); | |
11312 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
11313 | spin_unlock_irq(&phba->hbalock); | |
11314 | ||
11315 | /* Configure and enable interrupt */ | |
11316 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); | |
11317 | if (intr_mode == LPFC_INTR_ERROR) { | |
11318 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11319 | "2824 Cannot re-enable interrupt after " | |
11320 | "slot reset.\n"); | |
11321 | return PCI_ERS_RESULT_DISCONNECT; | |
11322 | } else | |
11323 | phba->intr_mode = intr_mode; | |
11324 | ||
11325 | /* Log the current active interrupt mode */ | |
11326 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
11327 | ||
8d63f375 LV |
11328 | return PCI_ERS_RESULT_RECOVERED; |
11329 | } | |
11330 | ||
11331 | /** | |
da0436e9 | 11332 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
e59058c4 | 11333 | * @pdev: pointer to PCI device |
8d63f375 | 11334 | * |
3772a991 | 11335 | * This routine is called from the PCI subsystem for error handling to device |
da0436e9 | 11336 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
3772a991 JS |
11337 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
11338 | * error recovery. After this call, traffic can start to flow from this device | |
11339 | * again. | |
da0436e9 | 11340 | **/ |
3772a991 | 11341 | static void |
da0436e9 | 11342 | lpfc_io_resume_s4(struct pci_dev *pdev) |
8d63f375 | 11343 | { |
75baf696 JS |
11344 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
11345 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
11346 | ||
11347 | /* | |
11348 | * In case of slot reset, as function reset is performed through | |
11349 | * mailbox command which needs DMA to be enabled, this operation | |
11350 | * has to be moved to the io resume phase. Taking device offline | |
11351 | * will perform the necessary cleanup. | |
11352 | */ | |
11353 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { | |
11354 | /* Perform device reset */ | |
618a5230 | 11355 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
75baf696 JS |
11356 | lpfc_offline(phba); |
11357 | lpfc_sli_brdrestart(phba); | |
11358 | /* Bring the device back online */ | |
11359 | lpfc_online(phba); | |
11360 | } | |
11361 | ||
11362 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
11363 | if (phba->hba_flag & HBA_AER_ENABLED) | |
11364 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
8d63f375 LV |
11365 | } |
11366 | ||
3772a991 JS |
11367 | /** |
11368 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem | |
11369 | * @pdev: pointer to PCI device | |
11370 | * @pid: pointer to PCI device identifier | |
11371 | * | |
11372 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
11373 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks | |
11374 | * at PCI device-specific information of the device and driver to see if the | |
11375 | * driver state that it can support this kind of device. If the match is | |
11376 | * successful, the driver core invokes this routine. This routine dispatches | |
11377 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will | |
11378 | * do all the initialization that it needs to do to handle the HBA device | |
11379 | * properly. | |
11380 | * | |
11381 | * Return code | |
11382 | * 0 - driver can claim the device | |
11383 | * negative value - driver can not claim the device | |
11384 | **/ | |
6f039790 | 11385 | static int |
3772a991 JS |
11386 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
11387 | { | |
11388 | int rc; | |
8fa38513 | 11389 | struct lpfc_sli_intf intf; |
3772a991 | 11390 | |
28baac74 | 11391 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
3772a991 JS |
11392 | return -ENODEV; |
11393 | ||
8fa38513 | 11394 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
28baac74 | 11395 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
da0436e9 | 11396 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
8fa38513 | 11397 | else |
3772a991 | 11398 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
8fa38513 | 11399 | |
3772a991 JS |
11400 | return rc; |
11401 | } | |
11402 | ||
11403 | /** | |
11404 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem | |
11405 | * @pdev: pointer to PCI device | |
11406 | * | |
11407 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
11408 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. | |
11409 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device | |
11410 | * remove routine, which will perform all the necessary cleanup for the | |
11411 | * device to be removed from the PCI subsystem properly. | |
11412 | **/ | |
6f039790 | 11413 | static void |
3772a991 JS |
11414 | lpfc_pci_remove_one(struct pci_dev *pdev) |
11415 | { | |
11416 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
11417 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
11418 | ||
11419 | switch (phba->pci_dev_grp) { | |
11420 | case LPFC_PCI_DEV_LP: | |
11421 | lpfc_pci_remove_one_s3(pdev); | |
11422 | break; | |
da0436e9 JS |
11423 | case LPFC_PCI_DEV_OC: |
11424 | lpfc_pci_remove_one_s4(pdev); | |
11425 | break; | |
3772a991 JS |
11426 | default: |
11427 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11428 | "1424 Invalid PCI device group: 0x%x\n", | |
11429 | phba->pci_dev_grp); | |
11430 | break; | |
11431 | } | |
11432 | return; | |
11433 | } | |
11434 | ||
11435 | /** | |
11436 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management | |
11437 | * @pdev: pointer to PCI device | |
11438 | * @msg: power management message | |
11439 | * | |
11440 | * This routine is to be registered to the kernel's PCI subsystem to support | |
11441 | * system Power Management (PM). When PM invokes this method, it dispatches | |
11442 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will | |
11443 | * suspend the device. | |
11444 | * | |
11445 | * Return code | |
11446 | * 0 - driver suspended the device | |
11447 | * Error otherwise | |
11448 | **/ | |
11449 | static int | |
11450 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | |
11451 | { | |
11452 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
11453 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
11454 | int rc = -ENODEV; | |
11455 | ||
11456 | switch (phba->pci_dev_grp) { | |
11457 | case LPFC_PCI_DEV_LP: | |
11458 | rc = lpfc_pci_suspend_one_s3(pdev, msg); | |
11459 | break; | |
da0436e9 JS |
11460 | case LPFC_PCI_DEV_OC: |
11461 | rc = lpfc_pci_suspend_one_s4(pdev, msg); | |
11462 | break; | |
3772a991 JS |
11463 | default: |
11464 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11465 | "1425 Invalid PCI device group: 0x%x\n", | |
11466 | phba->pci_dev_grp); | |
11467 | break; | |
11468 | } | |
11469 | return rc; | |
11470 | } | |
11471 | ||
11472 | /** | |
11473 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management | |
11474 | * @pdev: pointer to PCI device | |
11475 | * | |
11476 | * This routine is to be registered to the kernel's PCI subsystem to support | |
11477 | * system Power Management (PM). When PM invokes this method, it dispatches | |
11478 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will | |
11479 | * resume the device. | |
11480 | * | |
11481 | * Return code | |
11482 | * 0 - driver suspended the device | |
11483 | * Error otherwise | |
11484 | **/ | |
11485 | static int | |
11486 | lpfc_pci_resume_one(struct pci_dev *pdev) | |
11487 | { | |
11488 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
11489 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
11490 | int rc = -ENODEV; | |
11491 | ||
11492 | switch (phba->pci_dev_grp) { | |
11493 | case LPFC_PCI_DEV_LP: | |
11494 | rc = lpfc_pci_resume_one_s3(pdev); | |
11495 | break; | |
da0436e9 JS |
11496 | case LPFC_PCI_DEV_OC: |
11497 | rc = lpfc_pci_resume_one_s4(pdev); | |
11498 | break; | |
3772a991 JS |
11499 | default: |
11500 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11501 | "1426 Invalid PCI device group: 0x%x\n", | |
11502 | phba->pci_dev_grp); | |
11503 | break; | |
11504 | } | |
11505 | return rc; | |
11506 | } | |
11507 | ||
11508 | /** | |
11509 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error | |
11510 | * @pdev: pointer to PCI device. | |
11511 | * @state: the current PCI connection state. | |
11512 | * | |
11513 | * This routine is registered to the PCI subsystem for error handling. This | |
11514 | * function is called by the PCI subsystem after a PCI bus error affecting | |
11515 | * this device has been detected. When this routine is invoked, it dispatches | |
11516 | * the action to the proper SLI-3 or SLI-4 device error detected handling | |
11517 | * routine, which will perform the proper error detected operation. | |
11518 | * | |
11519 | * Return codes | |
11520 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery | |
11521 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
11522 | **/ | |
11523 | static pci_ers_result_t | |
11524 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | |
11525 | { | |
11526 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
11527 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
11528 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
11529 | ||
11530 | switch (phba->pci_dev_grp) { | |
11531 | case LPFC_PCI_DEV_LP: | |
11532 | rc = lpfc_io_error_detected_s3(pdev, state); | |
11533 | break; | |
da0436e9 JS |
11534 | case LPFC_PCI_DEV_OC: |
11535 | rc = lpfc_io_error_detected_s4(pdev, state); | |
11536 | break; | |
3772a991 JS |
11537 | default: |
11538 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11539 | "1427 Invalid PCI device group: 0x%x\n", | |
11540 | phba->pci_dev_grp); | |
11541 | break; | |
11542 | } | |
11543 | return rc; | |
11544 | } | |
11545 | ||
11546 | /** | |
11547 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch | |
11548 | * @pdev: pointer to PCI device. | |
11549 | * | |
11550 | * This routine is registered to the PCI subsystem for error handling. This | |
11551 | * function is called after PCI bus has been reset to restart the PCI card | |
11552 | * from scratch, as if from a cold-boot. When this routine is invoked, it | |
11553 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling | |
11554 | * routine, which will perform the proper device reset. | |
11555 | * | |
11556 | * Return codes | |
11557 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
11558 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
11559 | **/ | |
11560 | static pci_ers_result_t | |
11561 | lpfc_io_slot_reset(struct pci_dev *pdev) | |
11562 | { | |
11563 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
11564 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
11565 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
11566 | ||
11567 | switch (phba->pci_dev_grp) { | |
11568 | case LPFC_PCI_DEV_LP: | |
11569 | rc = lpfc_io_slot_reset_s3(pdev); | |
11570 | break; | |
da0436e9 JS |
11571 | case LPFC_PCI_DEV_OC: |
11572 | rc = lpfc_io_slot_reset_s4(pdev); | |
11573 | break; | |
3772a991 JS |
11574 | default: |
11575 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11576 | "1428 Invalid PCI device group: 0x%x\n", | |
11577 | phba->pci_dev_grp); | |
11578 | break; | |
11579 | } | |
11580 | return rc; | |
11581 | } | |
11582 | ||
11583 | /** | |
11584 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation | |
11585 | * @pdev: pointer to PCI device | |
11586 | * | |
11587 | * This routine is registered to the PCI subsystem for error handling. It | |
11588 | * is called when kernel error recovery tells the lpfc driver that it is | |
11589 | * OK to resume normal PCI operation after PCI bus error recovery. When | |
11590 | * this routine is invoked, it dispatches the action to the proper SLI-3 | |
11591 | * or SLI-4 device io_resume routine, which will resume the device operation. | |
11592 | **/ | |
11593 | static void | |
11594 | lpfc_io_resume(struct pci_dev *pdev) | |
11595 | { | |
11596 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
11597 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
11598 | ||
11599 | switch (phba->pci_dev_grp) { | |
11600 | case LPFC_PCI_DEV_LP: | |
11601 | lpfc_io_resume_s3(pdev); | |
11602 | break; | |
da0436e9 JS |
11603 | case LPFC_PCI_DEV_OC: |
11604 | lpfc_io_resume_s4(pdev); | |
11605 | break; | |
3772a991 JS |
11606 | default: |
11607 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
11608 | "1429 Invalid PCI device group: 0x%x\n", | |
11609 | phba->pci_dev_grp); | |
11610 | break; | |
11611 | } | |
11612 | return; | |
11613 | } | |
11614 | ||
1ba981fd JS |
11615 | /** |
11616 | * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter | |
11617 | * @phba: pointer to lpfc hba data structure. | |
11618 | * | |
11619 | * This routine checks to see if OAS is supported for this adapter. If | |
11620 | * supported, the configure Flash Optimized Fabric flag is set. Otherwise, | |
11621 | * the enable oas flag is cleared and the pool created for OAS device data | |
11622 | * is destroyed. | |
11623 | * | |
11624 | **/ | |
11625 | void | |
11626 | lpfc_sli4_oas_verify(struct lpfc_hba *phba) | |
11627 | { | |
11628 | ||
11629 | if (!phba->cfg_EnableXLane) | |
11630 | return; | |
11631 | ||
11632 | if (phba->sli4_hba.pc_sli4_params.oas_supported) { | |
11633 | phba->cfg_fof = 1; | |
11634 | } else { | |
f38fa0bb | 11635 | phba->cfg_fof = 0; |
1ba981fd JS |
11636 | if (phba->device_data_mem_pool) |
11637 | mempool_destroy(phba->device_data_mem_pool); | |
11638 | phba->device_data_mem_pool = NULL; | |
11639 | } | |
11640 | ||
11641 | return; | |
11642 | } | |
11643 | ||
11644 | /** | |
11645 | * lpfc_fof_queue_setup - Set up all the fof queues | |
11646 | * @phba: pointer to lpfc hba data structure. | |
11647 | * | |
11648 | * This routine is invoked to set up all the fof queues for the FC HBA | |
11649 | * operation. | |
11650 | * | |
11651 | * Return codes | |
11652 | * 0 - successful | |
11653 | * -ENOMEM - No available memory | |
11654 | **/ | |
11655 | int | |
11656 | lpfc_fof_queue_setup(struct lpfc_hba *phba) | |
11657 | { | |
895427bd | 11658 | struct lpfc_sli_ring *pring; |
1ba981fd JS |
11659 | int rc; |
11660 | ||
11661 | rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX); | |
11662 | if (rc) | |
11663 | return -ENOMEM; | |
11664 | ||
f38fa0bb | 11665 | if (phba->cfg_fof) { |
1ba981fd JS |
11666 | |
11667 | rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq, | |
11668 | phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP); | |
11669 | if (rc) | |
11670 | goto out_oas_cq; | |
11671 | ||
11672 | rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq, | |
11673 | phba->sli4_hba.oas_cq, LPFC_FCP); | |
11674 | if (rc) | |
11675 | goto out_oas_wq; | |
11676 | ||
895427bd JS |
11677 | /* Bind this CQ/WQ to the NVME ring */ |
11678 | pring = phba->sli4_hba.oas_wq->pring; | |
11679 | pring->sli.sli4.wqp = | |
11680 | (void *)phba->sli4_hba.oas_wq; | |
11681 | phba->sli4_hba.oas_cq->pring = pring; | |
1ba981fd JS |
11682 | } |
11683 | ||
11684 | return 0; | |
11685 | ||
11686 | out_oas_wq: | |
f38fa0bb | 11687 | lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq); |
1ba981fd JS |
11688 | out_oas_cq: |
11689 | lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq); | |
11690 | return rc; | |
11691 | ||
11692 | } | |
11693 | ||
11694 | /** | |
11695 | * lpfc_fof_queue_create - Create all the fof queues | |
11696 | * @phba: pointer to lpfc hba data structure. | |
11697 | * | |
11698 | * This routine is invoked to allocate all the fof queues for the FC HBA | |
11699 | * operation. For each SLI4 queue type, the parameters such as queue entry | |
11700 | * count (queue depth) shall be taken from the module parameter. For now, | |
11701 | * we just use some constant number as place holder. | |
11702 | * | |
11703 | * Return codes | |
11704 | * 0 - successful | |
11705 | * -ENOMEM - No availble memory | |
11706 | * -EIO - The mailbox failed to complete successfully. | |
11707 | **/ | |
11708 | int | |
11709 | lpfc_fof_queue_create(struct lpfc_hba *phba) | |
11710 | { | |
11711 | struct lpfc_queue *qdesc; | |
11712 | ||
11713 | /* Create FOF EQ */ | |
11714 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | |
11715 | phba->sli4_hba.eq_ecount); | |
11716 | if (!qdesc) | |
11717 | goto out_error; | |
11718 | ||
11719 | phba->sli4_hba.fof_eq = qdesc; | |
11720 | ||
f38fa0bb | 11721 | if (phba->cfg_fof) { |
1ba981fd JS |
11722 | |
11723 | /* Create OAS CQ */ | |
11724 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
11725 | phba->sli4_hba.cq_ecount); | |
11726 | if (!qdesc) | |
11727 | goto out_error; | |
11728 | ||
11729 | phba->sli4_hba.oas_cq = qdesc; | |
11730 | ||
11731 | /* Create OAS WQ */ | |
11732 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
11733 | phba->sli4_hba.wq_ecount); | |
11734 | if (!qdesc) | |
11735 | goto out_error; | |
11736 | ||
11737 | phba->sli4_hba.oas_wq = qdesc; | |
895427bd | 11738 | list_add_tail(&qdesc->wq_list, &phba->sli4_hba.lpfc_wq_list); |
1ba981fd JS |
11739 | |
11740 | } | |
11741 | return 0; | |
11742 | ||
11743 | out_error: | |
11744 | lpfc_fof_queue_destroy(phba); | |
11745 | return -ENOMEM; | |
11746 | } | |
11747 | ||
11748 | /** | |
11749 | * lpfc_fof_queue_destroy - Destroy all the fof queues | |
11750 | * @phba: pointer to lpfc hba data structure. | |
11751 | * | |
11752 | * This routine is invoked to release all the SLI4 queues with the FC HBA | |
11753 | * operation. | |
11754 | * | |
11755 | * Return codes | |
11756 | * 0 - successful | |
11757 | **/ | |
11758 | int | |
11759 | lpfc_fof_queue_destroy(struct lpfc_hba *phba) | |
11760 | { | |
11761 | /* Release FOF Event queue */ | |
11762 | if (phba->sli4_hba.fof_eq != NULL) { | |
11763 | lpfc_sli4_queue_free(phba->sli4_hba.fof_eq); | |
11764 | phba->sli4_hba.fof_eq = NULL; | |
11765 | } | |
11766 | ||
11767 | /* Release OAS Completion queue */ | |
11768 | if (phba->sli4_hba.oas_cq != NULL) { | |
11769 | lpfc_sli4_queue_free(phba->sli4_hba.oas_cq); | |
11770 | phba->sli4_hba.oas_cq = NULL; | |
11771 | } | |
11772 | ||
11773 | /* Release OAS Work queue */ | |
11774 | if (phba->sli4_hba.oas_wq != NULL) { | |
11775 | lpfc_sli4_queue_free(phba->sli4_hba.oas_wq); | |
11776 | phba->sli4_hba.oas_wq = NULL; | |
11777 | } | |
11778 | return 0; | |
11779 | } | |
11780 | ||
dea3101e JB |
11781 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); |
11782 | ||
a55b2d21 | 11783 | static const struct pci_error_handlers lpfc_err_handler = { |
8d63f375 LV |
11784 | .error_detected = lpfc_io_error_detected, |
11785 | .slot_reset = lpfc_io_slot_reset, | |
11786 | .resume = lpfc_io_resume, | |
11787 | }; | |
11788 | ||
dea3101e JB |
11789 | static struct pci_driver lpfc_driver = { |
11790 | .name = LPFC_DRIVER_NAME, | |
11791 | .id_table = lpfc_id_table, | |
11792 | .probe = lpfc_pci_probe_one, | |
6f039790 | 11793 | .remove = lpfc_pci_remove_one, |
3a55b532 | 11794 | .suspend = lpfc_pci_suspend_one, |
3772a991 | 11795 | .resume = lpfc_pci_resume_one, |
2e0fef85 | 11796 | .err_handler = &lpfc_err_handler, |
dea3101e JB |
11797 | }; |
11798 | ||
3ef6d24c | 11799 | static const struct file_operations lpfc_mgmt_fop = { |
858feacd | 11800 | .owner = THIS_MODULE, |
3ef6d24c JS |
11801 | }; |
11802 | ||
11803 | static struct miscdevice lpfc_mgmt_dev = { | |
11804 | .minor = MISC_DYNAMIC_MINOR, | |
11805 | .name = "lpfcmgmt", | |
11806 | .fops = &lpfc_mgmt_fop, | |
11807 | }; | |
11808 | ||
e59058c4 | 11809 | /** |
3621a710 | 11810 | * lpfc_init - lpfc module initialization routine |
e59058c4 JS |
11811 | * |
11812 | * This routine is to be invoked when the lpfc module is loaded into the | |
11813 | * kernel. The special kernel macro module_init() is used to indicate the | |
11814 | * role of this routine to the kernel as lpfc module entry point. | |
11815 | * | |
11816 | * Return codes | |
11817 | * 0 - successful | |
11818 | * -ENOMEM - FC attach transport failed | |
11819 | * all others - failed | |
11820 | */ | |
dea3101e JB |
11821 | static int __init |
11822 | lpfc_init(void) | |
11823 | { | |
11824 | int error = 0; | |
11825 | ||
11826 | printk(LPFC_MODULE_DESC "\n"); | |
c44ce173 | 11827 | printk(LPFC_COPYRIGHT "\n"); |
dea3101e | 11828 | |
3ef6d24c JS |
11829 | error = misc_register(&lpfc_mgmt_dev); |
11830 | if (error) | |
11831 | printk(KERN_ERR "Could not register lpfcmgmt device, " | |
11832 | "misc_register returned with status %d", error); | |
11833 | ||
458c083e JS |
11834 | lpfc_transport_functions.vport_create = lpfc_vport_create; |
11835 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; | |
dea3101e JB |
11836 | lpfc_transport_template = |
11837 | fc_attach_transport(&lpfc_transport_functions); | |
7ee5d43e | 11838 | if (lpfc_transport_template == NULL) |
dea3101e | 11839 | return -ENOMEM; |
458c083e JS |
11840 | lpfc_vport_transport_template = |
11841 | fc_attach_transport(&lpfc_vport_transport_functions); | |
11842 | if (lpfc_vport_transport_template == NULL) { | |
11843 | fc_release_transport(lpfc_transport_template); | |
11844 | return -ENOMEM; | |
7ee5d43e | 11845 | } |
7bb03bbf JS |
11846 | |
11847 | /* Initialize in case vector mapping is needed */ | |
b246de17 | 11848 | lpfc_used_cpu = NULL; |
2ea259ee | 11849 | lpfc_present_cpu = num_present_cpus(); |
7bb03bbf | 11850 | |
dea3101e | 11851 | error = pci_register_driver(&lpfc_driver); |
92d7f7b0 | 11852 | if (error) { |
dea3101e | 11853 | fc_release_transport(lpfc_transport_template); |
458c083e | 11854 | fc_release_transport(lpfc_vport_transport_template); |
92d7f7b0 | 11855 | } |
dea3101e JB |
11856 | |
11857 | return error; | |
11858 | } | |
11859 | ||
e59058c4 | 11860 | /** |
3621a710 | 11861 | * lpfc_exit - lpfc module removal routine |
e59058c4 JS |
11862 | * |
11863 | * This routine is invoked when the lpfc module is removed from the kernel. | |
11864 | * The special kernel macro module_exit() is used to indicate the role of | |
11865 | * this routine to the kernel as lpfc module exit point. | |
11866 | */ | |
dea3101e JB |
11867 | static void __exit |
11868 | lpfc_exit(void) | |
11869 | { | |
3ef6d24c | 11870 | misc_deregister(&lpfc_mgmt_dev); |
dea3101e JB |
11871 | pci_unregister_driver(&lpfc_driver); |
11872 | fc_release_transport(lpfc_transport_template); | |
458c083e | 11873 | fc_release_transport(lpfc_vport_transport_template); |
81301a9b | 11874 | if (_dump_buf_data) { |
6a9c52cf JS |
11875 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
11876 | "_dump_buf_data at 0x%p\n", | |
81301a9b JS |
11877 | (1L << _dump_buf_data_order), _dump_buf_data); |
11878 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); | |
11879 | } | |
11880 | ||
11881 | if (_dump_buf_dif) { | |
6a9c52cf JS |
11882 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
11883 | "_dump_buf_dif at 0x%p\n", | |
81301a9b JS |
11884 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
11885 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); | |
11886 | } | |
b246de17 | 11887 | kfree(lpfc_used_cpu); |
7973967f | 11888 | idr_destroy(&lpfc_hba_index); |
dea3101e JB |
11889 | } |
11890 | ||
11891 | module_init(lpfc_init); | |
11892 | module_exit(lpfc_exit); | |
11893 | MODULE_LICENSE("GPL"); | |
11894 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); | |
11895 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); | |
11896 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |