]>
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. * |
92c13f29 | 4 | * Copyright (C) 2004-2013 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> |
dea3101e | 37 | |
91886523 | 38 | #include <scsi/scsi.h> |
dea3101e JB |
39 | #include <scsi/scsi_device.h> |
40 | #include <scsi/scsi_host.h> | |
41 | #include <scsi/scsi_transport_fc.h> | |
42 | ||
da0436e9 | 43 | #include "lpfc_hw4.h" |
dea3101e JB |
44 | #include "lpfc_hw.h" |
45 | #include "lpfc_sli.h" | |
da0436e9 | 46 | #include "lpfc_sli4.h" |
ea2151b4 | 47 | #include "lpfc_nl.h" |
dea3101e JB |
48 | #include "lpfc_disc.h" |
49 | #include "lpfc_scsi.h" | |
50 | #include "lpfc.h" | |
51 | #include "lpfc_logmsg.h" | |
52 | #include "lpfc_crtn.h" | |
92d7f7b0 | 53 | #include "lpfc_vport.h" |
dea3101e JB |
54 | #include "lpfc_version.h" |
55 | ||
81301a9b JS |
56 | char *_dump_buf_data; |
57 | unsigned long _dump_buf_data_order; | |
58 | char *_dump_buf_dif; | |
59 | unsigned long _dump_buf_dif_order; | |
60 | spinlock_t _dump_buf_lock; | |
61 | ||
7bb03bbf | 62 | /* Used when mapping IRQ vectors in a driver centric manner */ |
b246de17 JS |
63 | uint16_t *lpfc_used_cpu; |
64 | uint32_t lpfc_present_cpu; | |
7bb03bbf | 65 | |
dea3101e JB |
66 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
67 | static int lpfc_post_rcv_buf(struct lpfc_hba *); | |
5350d872 | 68 | static int lpfc_sli4_queue_verify(struct lpfc_hba *); |
da0436e9 JS |
69 | static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); |
70 | static int lpfc_setup_endian_order(struct lpfc_hba *); | |
da0436e9 | 71 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); |
8a9d2e80 JS |
72 | static void lpfc_free_els_sgl_list(struct lpfc_hba *); |
73 | static void lpfc_init_sgl_list(struct lpfc_hba *); | |
da0436e9 JS |
74 | static int lpfc_init_active_sgl_array(struct lpfc_hba *); |
75 | static void lpfc_free_active_sgl(struct lpfc_hba *); | |
76 | static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); | |
77 | static int lpfc_hba_down_post_s4(struct lpfc_hba *phba); | |
78 | static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *); | |
79 | static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *); | |
80 | static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *); | |
618a5230 JS |
81 | static void lpfc_sli4_disable_intr(struct lpfc_hba *); |
82 | static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t); | |
1ba981fd | 83 | static void lpfc_sli4_oas_verify(struct lpfc_hba *phba); |
dea3101e JB |
84 | |
85 | static struct scsi_transport_template *lpfc_transport_template = NULL; | |
92d7f7b0 | 86 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
dea3101e JB |
87 | static DEFINE_IDR(lpfc_hba_index); |
88 | ||
e59058c4 | 89 | /** |
3621a710 | 90 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
e59058c4 JS |
91 | * @phba: pointer to lpfc hba data structure. |
92 | * | |
93 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT | |
94 | * mailbox command. It retrieves the revision information from the HBA and | |
95 | * collects the Vital Product Data (VPD) about the HBA for preparing the | |
96 | * configuration of the HBA. | |
97 | * | |
98 | * Return codes: | |
99 | * 0 - success. | |
100 | * -ERESTART - requests the SLI layer to reset the HBA and try again. | |
101 | * Any other value - indicates an error. | |
102 | **/ | |
dea3101e | 103 | int |
2e0fef85 | 104 | lpfc_config_port_prep(struct lpfc_hba *phba) |
dea3101e JB |
105 | { |
106 | lpfc_vpd_t *vp = &phba->vpd; | |
107 | int i = 0, rc; | |
108 | LPFC_MBOXQ_t *pmb; | |
109 | MAILBOX_t *mb; | |
110 | char *lpfc_vpd_data = NULL; | |
111 | uint16_t offset = 0; | |
112 | static char licensed[56] = | |
113 | "key unlock for use with gnu public licensed code only\0"; | |
65a29c16 | 114 | static int init_key = 1; |
dea3101e JB |
115 | |
116 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
117 | if (!pmb) { | |
2e0fef85 | 118 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
119 | return -ENOMEM; |
120 | } | |
121 | ||
04c68496 | 122 | mb = &pmb->u.mb; |
2e0fef85 | 123 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e JB |
124 | |
125 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { | |
65a29c16 JS |
126 | if (init_key) { |
127 | uint32_t *ptext = (uint32_t *) licensed; | |
dea3101e | 128 | |
65a29c16 JS |
129 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
130 | *ptext = cpu_to_be32(*ptext); | |
131 | init_key = 0; | |
132 | } | |
dea3101e JB |
133 | |
134 | lpfc_read_nv(phba, pmb); | |
135 | memset((char*)mb->un.varRDnvp.rsvd3, 0, | |
136 | sizeof (mb->un.varRDnvp.rsvd3)); | |
137 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, | |
138 | sizeof (licensed)); | |
139 | ||
140 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
141 | ||
142 | if (rc != MBX_SUCCESS) { | |
ed957684 | 143 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
e8b62011 | 144 | "0324 Config Port initialization " |
dea3101e JB |
145 | "error, mbxCmd x%x READ_NVPARM, " |
146 | "mbxStatus x%x\n", | |
dea3101e JB |
147 | mb->mbxCommand, mb->mbxStatus); |
148 | mempool_free(pmb, phba->mbox_mem_pool); | |
149 | return -ERESTART; | |
150 | } | |
151 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, | |
2e0fef85 JS |
152 | sizeof(phba->wwnn)); |
153 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, | |
154 | sizeof(phba->wwpn)); | |
dea3101e JB |
155 | } |
156 | ||
92d7f7b0 JS |
157 | phba->sli3_options = 0x0; |
158 | ||
dea3101e JB |
159 | /* Setup and issue mailbox READ REV command */ |
160 | lpfc_read_rev(phba, pmb); | |
161 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
162 | if (rc != MBX_SUCCESS) { | |
ed957684 | 163 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 164 | "0439 Adapter failed to init, mbxCmd x%x " |
dea3101e | 165 | "READ_REV, mbxStatus x%x\n", |
dea3101e JB |
166 | mb->mbxCommand, mb->mbxStatus); |
167 | mempool_free( pmb, phba->mbox_mem_pool); | |
168 | return -ERESTART; | |
169 | } | |
170 | ||
92d7f7b0 | 171 | |
1de933f3 JSEC |
172 | /* |
173 | * The value of rr must be 1 since the driver set the cv field to 1. | |
174 | * This setting requires the FW to set all revision fields. | |
dea3101e | 175 | */ |
1de933f3 | 176 | if (mb->un.varRdRev.rr == 0) { |
dea3101e | 177 | vp->rev.rBit = 0; |
1de933f3 | 178 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 JS |
179 | "0440 Adapter failed to init, READ_REV has " |
180 | "missing revision information.\n"); | |
dea3101e JB |
181 | mempool_free(pmb, phba->mbox_mem_pool); |
182 | return -ERESTART; | |
dea3101e JB |
183 | } |
184 | ||
495a714c JS |
185 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
186 | mempool_free(pmb, phba->mbox_mem_pool); | |
ed957684 | 187 | return -EINVAL; |
495a714c | 188 | } |
ed957684 | 189 | |
dea3101e | 190 | /* Save information as VPD data */ |
1de933f3 | 191 | vp->rev.rBit = 1; |
92d7f7b0 | 192 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
1de933f3 JSEC |
193 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
194 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); | |
195 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; | |
196 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); | |
dea3101e JB |
197 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
198 | vp->rev.smRev = mb->un.varRdRev.smRev; | |
199 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; | |
200 | vp->rev.endecRev = mb->un.varRdRev.endecRev; | |
201 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; | |
202 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; | |
203 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; | |
204 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; | |
205 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; | |
206 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; | |
207 | ||
92d7f7b0 JS |
208 | /* If the sli feature level is less then 9, we must |
209 | * tear down all RPIs and VPIs on link down if NPIV | |
210 | * is enabled. | |
211 | */ | |
212 | if (vp->rev.feaLevelHigh < 9) | |
213 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; | |
214 | ||
dea3101e JB |
215 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
216 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], | |
217 | sizeof (phba->RandomData)); | |
218 | ||
dea3101e | 219 | /* Get adapter VPD information */ |
dea3101e JB |
220 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
221 | if (!lpfc_vpd_data) | |
d7c255b2 | 222 | goto out_free_mbox; |
dea3101e | 223 | do { |
a0c87cbd | 224 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
dea3101e JB |
225 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
226 | ||
227 | if (rc != MBX_SUCCESS) { | |
228 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 | 229 | "0441 VPD not present on adapter, " |
dea3101e | 230 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
dea3101e | 231 | mb->mbxCommand, mb->mbxStatus); |
74b72a59 | 232 | mb->un.varDmp.word_cnt = 0; |
dea3101e | 233 | } |
04c68496 JS |
234 | /* dump mem may return a zero when finished or we got a |
235 | * mailbox error, either way we are done. | |
236 | */ | |
237 | if (mb->un.varDmp.word_cnt == 0) | |
238 | break; | |
74b72a59 JW |
239 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
240 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; | |
d7c255b2 JS |
241 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
242 | lpfc_vpd_data + offset, | |
92d7f7b0 | 243 | mb->un.varDmp.word_cnt); |
dea3101e | 244 | offset += mb->un.varDmp.word_cnt; |
74b72a59 JW |
245 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
246 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); | |
dea3101e JB |
247 | |
248 | kfree(lpfc_vpd_data); | |
dea3101e JB |
249 | out_free_mbox: |
250 | mempool_free(pmb, phba->mbox_mem_pool); | |
251 | return 0; | |
252 | } | |
253 | ||
e59058c4 | 254 | /** |
3621a710 | 255 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
e59058c4 JS |
256 | * @phba: pointer to lpfc hba data structure. |
257 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
258 | * | |
259 | * This is the completion handler for driver's configuring asynchronous event | |
260 | * mailbox command to the device. If the mailbox command returns successfully, | |
261 | * it will set internal async event support flag to 1; otherwise, it will | |
262 | * set internal async event support flag to 0. | |
263 | **/ | |
57127f15 JS |
264 | static void |
265 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
266 | { | |
04c68496 | 267 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
57127f15 JS |
268 | phba->temp_sensor_support = 1; |
269 | else | |
270 | phba->temp_sensor_support = 0; | |
271 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
272 | return; | |
273 | } | |
274 | ||
97207482 | 275 | /** |
3621a710 | 276 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
97207482 JS |
277 | * @phba: pointer to lpfc hba data structure. |
278 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
279 | * | |
280 | * This is the completion handler for dump mailbox command for getting | |
281 | * wake up parameters. When this command complete, the response contain | |
282 | * Option rom version of the HBA. This function translate the version number | |
283 | * into a human readable string and store it in OptionROMVersion. | |
284 | **/ | |
285 | static void | |
286 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) | |
287 | { | |
288 | struct prog_id *prg; | |
289 | uint32_t prog_id_word; | |
290 | char dist = ' '; | |
291 | /* character array used for decoding dist type. */ | |
292 | char dist_char[] = "nabx"; | |
293 | ||
04c68496 | 294 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
9f1e1b50 | 295 | mempool_free(pmboxq, phba->mbox_mem_pool); |
97207482 | 296 | return; |
9f1e1b50 | 297 | } |
97207482 JS |
298 | |
299 | prg = (struct prog_id *) &prog_id_word; | |
300 | ||
301 | /* word 7 contain option rom version */ | |
04c68496 | 302 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
97207482 JS |
303 | |
304 | /* Decode the Option rom version word to a readable string */ | |
305 | if (prg->dist < 4) | |
306 | dist = dist_char[prg->dist]; | |
307 | ||
308 | if ((prg->dist == 3) && (prg->num == 0)) | |
309 | sprintf(phba->OptionROMVersion, "%d.%d%d", | |
310 | prg->ver, prg->rev, prg->lev); | |
311 | else | |
312 | sprintf(phba->OptionROMVersion, "%d.%d%d%c%d", | |
313 | prg->ver, prg->rev, prg->lev, | |
314 | dist, prg->num); | |
9f1e1b50 | 315 | mempool_free(pmboxq, phba->mbox_mem_pool); |
97207482 JS |
316 | return; |
317 | } | |
318 | ||
0558056c JS |
319 | /** |
320 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, | |
321 | * cfg_soft_wwnn, cfg_soft_wwpn | |
322 | * @vport: pointer to lpfc vport data structure. | |
323 | * | |
324 | * | |
325 | * Return codes | |
326 | * None. | |
327 | **/ | |
328 | void | |
329 | lpfc_update_vport_wwn(struct lpfc_vport *vport) | |
330 | { | |
331 | /* If the soft name exists then update it using the service params */ | |
332 | if (vport->phba->cfg_soft_wwnn) | |
333 | u64_to_wwn(vport->phba->cfg_soft_wwnn, | |
334 | vport->fc_sparam.nodeName.u.wwn); | |
335 | if (vport->phba->cfg_soft_wwpn) | |
336 | u64_to_wwn(vport->phba->cfg_soft_wwpn, | |
337 | vport->fc_sparam.portName.u.wwn); | |
338 | ||
339 | /* | |
340 | * If the name is empty or there exists a soft name | |
341 | * then copy the service params name, otherwise use the fc name | |
342 | */ | |
343 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) | |
344 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, | |
345 | sizeof(struct lpfc_name)); | |
346 | else | |
347 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, | |
348 | sizeof(struct lpfc_name)); | |
349 | ||
350 | if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn) | |
351 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, | |
352 | sizeof(struct lpfc_name)); | |
353 | else | |
354 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, | |
355 | sizeof(struct lpfc_name)); | |
356 | } | |
357 | ||
e59058c4 | 358 | /** |
3621a710 | 359 | * lpfc_config_port_post - Perform lpfc initialization after config port |
e59058c4 JS |
360 | * @phba: pointer to lpfc hba data structure. |
361 | * | |
362 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox | |
363 | * command call. It performs all internal resource and state setups on the | |
364 | * port: post IOCB buffers, enable appropriate host interrupt attentions, | |
365 | * ELS ring timers, etc. | |
366 | * | |
367 | * Return codes | |
368 | * 0 - success. | |
369 | * Any other value - error. | |
370 | **/ | |
dea3101e | 371 | int |
2e0fef85 | 372 | lpfc_config_port_post(struct lpfc_hba *phba) |
dea3101e | 373 | { |
2e0fef85 | 374 | struct lpfc_vport *vport = phba->pport; |
a257bf90 | 375 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e JB |
376 | LPFC_MBOXQ_t *pmb; |
377 | MAILBOX_t *mb; | |
378 | struct lpfc_dmabuf *mp; | |
379 | struct lpfc_sli *psli = &phba->sli; | |
380 | uint32_t status, timeout; | |
2e0fef85 JS |
381 | int i, j; |
382 | int rc; | |
dea3101e | 383 | |
7af67051 JS |
384 | spin_lock_irq(&phba->hbalock); |
385 | /* | |
386 | * If the Config port completed correctly the HBA is not | |
387 | * over heated any more. | |
388 | */ | |
389 | if (phba->over_temp_state == HBA_OVER_TEMP) | |
390 | phba->over_temp_state = HBA_NORMAL_TEMP; | |
391 | spin_unlock_irq(&phba->hbalock); | |
392 | ||
dea3101e JB |
393 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
394 | if (!pmb) { | |
2e0fef85 | 395 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
396 | return -ENOMEM; |
397 | } | |
04c68496 | 398 | mb = &pmb->u.mb; |
dea3101e | 399 | |
dea3101e | 400 | /* Get login parameters for NID. */ |
9f1177a3 JS |
401 | rc = lpfc_read_sparam(phba, pmb, 0); |
402 | if (rc) { | |
403 | mempool_free(pmb, phba->mbox_mem_pool); | |
404 | return -ENOMEM; | |
405 | } | |
406 | ||
ed957684 | 407 | pmb->vport = vport; |
dea3101e | 408 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 409 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 410 | "0448 Adapter failed init, mbxCmd x%x " |
dea3101e | 411 | "READ_SPARM mbxStatus x%x\n", |
dea3101e | 412 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 413 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 414 | mp = (struct lpfc_dmabuf *) pmb->context1; |
9f1177a3 | 415 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e JB |
416 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
417 | kfree(mp); | |
418 | return -EIO; | |
419 | } | |
420 | ||
421 | mp = (struct lpfc_dmabuf *) pmb->context1; | |
422 | ||
2e0fef85 | 423 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
dea3101e JB |
424 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
425 | kfree(mp); | |
426 | pmb->context1 = NULL; | |
0558056c | 427 | lpfc_update_vport_wwn(vport); |
a257bf90 JS |
428 | |
429 | /* Update the fc_host data structures with new wwn. */ | |
430 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
431 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
21e9a0a5 | 432 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
a257bf90 | 433 | |
dea3101e JB |
434 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
435 | /* This should be consolidated into parse_vpd ? - mr */ | |
436 | if (phba->SerialNumber[0] == 0) { | |
437 | uint8_t *outptr; | |
438 | ||
2e0fef85 | 439 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
dea3101e JB |
440 | for (i = 0; i < 12; i++) { |
441 | status = *outptr++; | |
442 | j = ((status & 0xf0) >> 4); | |
443 | if (j <= 9) | |
444 | phba->SerialNumber[i] = | |
445 | (char)((uint8_t) 0x30 + (uint8_t) j); | |
446 | else | |
447 | phba->SerialNumber[i] = | |
448 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | |
449 | i++; | |
450 | j = (status & 0xf); | |
451 | if (j <= 9) | |
452 | phba->SerialNumber[i] = | |
453 | (char)((uint8_t) 0x30 + (uint8_t) j); | |
454 | else | |
455 | phba->SerialNumber[i] = | |
456 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | |
457 | } | |
458 | } | |
459 | ||
dea3101e | 460 | lpfc_read_config(phba, pmb); |
ed957684 | 461 | pmb->vport = vport; |
dea3101e | 462 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 463 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 464 | "0453 Adapter failed to init, mbxCmd x%x " |
dea3101e | 465 | "READ_CONFIG, mbxStatus x%x\n", |
dea3101e | 466 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 467 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
468 | mempool_free( pmb, phba->mbox_mem_pool); |
469 | return -EIO; | |
470 | } | |
471 | ||
a0c87cbd JS |
472 | /* Check if the port is disabled */ |
473 | lpfc_sli_read_link_ste(phba); | |
474 | ||
dea3101e | 475 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
572709e2 JS |
476 | i = (mb->un.varRdConfig.max_xri + 1); |
477 | if (phba->cfg_hba_queue_depth > i) { | |
478 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
479 | "3359 HBA queue depth changed from %d to %d\n", | |
480 | phba->cfg_hba_queue_depth, i); | |
481 | phba->cfg_hba_queue_depth = i; | |
482 | } | |
483 | ||
484 | /* Reset the DFT_LUN_Q_DEPTH to (max xri >> 3) */ | |
485 | i = (mb->un.varRdConfig.max_xri >> 3); | |
486 | if (phba->pport->cfg_lun_queue_depth > i) { | |
487 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
488 | "3360 LUN queue depth changed from %d to %d\n", | |
489 | phba->pport->cfg_lun_queue_depth, i); | |
490 | phba->pport->cfg_lun_queue_depth = i; | |
491 | } | |
dea3101e JB |
492 | |
493 | phba->lmt = mb->un.varRdConfig.lmt; | |
74b72a59 JW |
494 | |
495 | /* Get the default values for Model Name and Description */ | |
496 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
497 | ||
2e0fef85 | 498 | phba->link_state = LPFC_LINK_DOWN; |
dea3101e | 499 | |
0b727fea | 500 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
7e56aa25 | 501 | if (psli->ring[psli->extra_ring].sli.sli3.cmdringaddr) |
a4bc3379 | 502 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; |
7e56aa25 | 503 | if (psli->ring[psli->fcp_ring].sli.sli3.cmdringaddr) |
dea3101e | 504 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; |
7e56aa25 | 505 | if (psli->ring[psli->next_ring].sli.sli3.cmdringaddr) |
dea3101e JB |
506 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; |
507 | ||
508 | /* Post receive buffers for desired rings */ | |
ed957684 JS |
509 | if (phba->sli_rev != 3) |
510 | lpfc_post_rcv_buf(phba); | |
dea3101e | 511 | |
9399627f JS |
512 | /* |
513 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode | |
514 | */ | |
515 | if (phba->intr_type == MSIX) { | |
516 | rc = lpfc_config_msi(phba, pmb); | |
517 | if (rc) { | |
518 | mempool_free(pmb, phba->mbox_mem_pool); | |
519 | return -EIO; | |
520 | } | |
521 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
522 | if (rc != MBX_SUCCESS) { | |
523 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
524 | "0352 Config MSI mailbox command " | |
525 | "failed, mbxCmd x%x, mbxStatus x%x\n", | |
04c68496 JS |
526 | pmb->u.mb.mbxCommand, |
527 | pmb->u.mb.mbxStatus); | |
9399627f JS |
528 | mempool_free(pmb, phba->mbox_mem_pool); |
529 | return -EIO; | |
530 | } | |
531 | } | |
532 | ||
04c68496 | 533 | spin_lock_irq(&phba->hbalock); |
9399627f JS |
534 | /* Initialize ERATT handling flag */ |
535 | phba->hba_flag &= ~HBA_ERATT_HANDLED; | |
536 | ||
dea3101e | 537 | /* Enable appropriate host interrupts */ |
9940b97b JS |
538 | if (lpfc_readl(phba->HCregaddr, &status)) { |
539 | spin_unlock_irq(&phba->hbalock); | |
540 | return -EIO; | |
541 | } | |
dea3101e JB |
542 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
543 | if (psli->num_rings > 0) | |
544 | status |= HC_R0INT_ENA; | |
545 | if (psli->num_rings > 1) | |
546 | status |= HC_R1INT_ENA; | |
547 | if (psli->num_rings > 2) | |
548 | status |= HC_R2INT_ENA; | |
549 | if (psli->num_rings > 3) | |
550 | status |= HC_R3INT_ENA; | |
551 | ||
875fbdfe JSEC |
552 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
553 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) | |
9399627f | 554 | status &= ~(HC_R0INT_ENA); |
875fbdfe | 555 | |
dea3101e JB |
556 | writel(status, phba->HCregaddr); |
557 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 558 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 559 | |
9399627f JS |
560 | /* Set up ring-0 (ELS) timer */ |
561 | timeout = phba->fc_ratov * 2; | |
256ec0d0 JS |
562 | mod_timer(&vport->els_tmofunc, |
563 | jiffies + msecs_to_jiffies(1000 * timeout)); | |
9399627f | 564 | /* Set up heart beat (HB) timer */ |
256ec0d0 JS |
565 | mod_timer(&phba->hb_tmofunc, |
566 | jiffies + msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); | |
858c9f6c JS |
567 | phba->hb_outstanding = 0; |
568 | phba->last_completion_time = jiffies; | |
9399627f | 569 | /* Set up error attention (ERATT) polling timer */ |
256ec0d0 JS |
570 | mod_timer(&phba->eratt_poll, |
571 | jiffies + msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL)); | |
dea3101e | 572 | |
a0c87cbd JS |
573 | if (phba->hba_flag & LINK_DISABLED) { |
574 | lpfc_printf_log(phba, | |
575 | KERN_ERR, LOG_INIT, | |
576 | "2598 Adapter Link is disabled.\n"); | |
577 | lpfc_down_link(phba, pmb); | |
578 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
579 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
580 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { | |
581 | lpfc_printf_log(phba, | |
582 | KERN_ERR, LOG_INIT, | |
583 | "2599 Adapter failed to issue DOWN_LINK" | |
584 | " mbox command rc 0x%x\n", rc); | |
585 | ||
586 | mempool_free(pmb, phba->mbox_mem_pool); | |
587 | return -EIO; | |
588 | } | |
e40a02c1 | 589 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
026abb87 JS |
590 | mempool_free(pmb, phba->mbox_mem_pool); |
591 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); | |
592 | if (rc) | |
593 | return rc; | |
dea3101e JB |
594 | } |
595 | /* MBOX buffer will be freed in mbox compl */ | |
57127f15 | 596 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
9f1177a3 JS |
597 | if (!pmb) { |
598 | phba->link_state = LPFC_HBA_ERROR; | |
599 | return -ENOMEM; | |
600 | } | |
601 | ||
57127f15 JS |
602 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
603 | pmb->mbox_cmpl = lpfc_config_async_cmpl; | |
604 | pmb->vport = phba->pport; | |
605 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
dea3101e | 606 | |
57127f15 JS |
607 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
608 | lpfc_printf_log(phba, | |
609 | KERN_ERR, | |
610 | LOG_INIT, | |
611 | "0456 Adapter failed to issue " | |
e4e74273 | 612 | "ASYNCEVT_ENABLE mbox status x%x\n", |
57127f15 JS |
613 | rc); |
614 | mempool_free(pmb, phba->mbox_mem_pool); | |
615 | } | |
97207482 JS |
616 | |
617 | /* Get Option rom version */ | |
618 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
9f1177a3 JS |
619 | if (!pmb) { |
620 | phba->link_state = LPFC_HBA_ERROR; | |
621 | return -ENOMEM; | |
622 | } | |
623 | ||
97207482 JS |
624 | lpfc_dump_wakeup_param(phba, pmb); |
625 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; | |
626 | pmb->vport = phba->pport; | |
627 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
628 | ||
629 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { | |
630 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " | |
e4e74273 | 631 | "to get Option ROM version status x%x\n", rc); |
97207482 JS |
632 | mempool_free(pmb, phba->mbox_mem_pool); |
633 | } | |
634 | ||
d7c255b2 | 635 | return 0; |
ce8b3ce5 JS |
636 | } |
637 | ||
84d1b006 JS |
638 | /** |
639 | * lpfc_hba_init_link - Initialize the FC link | |
640 | * @phba: pointer to lpfc hba data structure. | |
6e7288d9 | 641 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
84d1b006 JS |
642 | * |
643 | * This routine will issue the INIT_LINK mailbox command call. | |
644 | * It is available to other drivers through the lpfc_hba data | |
645 | * structure for use as a delayed link up mechanism with the | |
646 | * module parameter lpfc_suppress_link_up. | |
647 | * | |
648 | * Return code | |
649 | * 0 - success | |
650 | * Any other value - error | |
651 | **/ | |
652 | int | |
6e7288d9 | 653 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
1b51197d JS |
654 | { |
655 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); | |
656 | } | |
657 | ||
658 | /** | |
659 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology | |
660 | * @phba: pointer to lpfc hba data structure. | |
661 | * @fc_topology: desired fc topology. | |
662 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT | |
663 | * | |
664 | * This routine will issue the INIT_LINK mailbox command call. | |
665 | * It is available to other drivers through the lpfc_hba data | |
666 | * structure for use as a delayed link up mechanism with the | |
667 | * module parameter lpfc_suppress_link_up. | |
668 | * | |
669 | * Return code | |
670 | * 0 - success | |
671 | * Any other value - error | |
672 | **/ | |
673 | int | |
674 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, | |
675 | uint32_t flag) | |
84d1b006 JS |
676 | { |
677 | struct lpfc_vport *vport = phba->pport; | |
678 | LPFC_MBOXQ_t *pmb; | |
679 | MAILBOX_t *mb; | |
680 | int rc; | |
681 | ||
682 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
683 | if (!pmb) { | |
684 | phba->link_state = LPFC_HBA_ERROR; | |
685 | return -ENOMEM; | |
686 | } | |
687 | mb = &pmb->u.mb; | |
688 | pmb->vport = vport; | |
689 | ||
026abb87 JS |
690 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
691 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && | |
692 | !(phba->lmt & LMT_1Gb)) || | |
693 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && | |
694 | !(phba->lmt & LMT_2Gb)) || | |
695 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && | |
696 | !(phba->lmt & LMT_4Gb)) || | |
697 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && | |
698 | !(phba->lmt & LMT_8Gb)) || | |
699 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && | |
700 | !(phba->lmt & LMT_10Gb)) || | |
701 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && | |
702 | !(phba->lmt & LMT_16Gb))) { | |
703 | /* Reset link speed to auto */ | |
704 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, | |
705 | "1302 Invalid speed for this board:%d " | |
706 | "Reset link speed to auto.\n", | |
707 | phba->cfg_link_speed); | |
708 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; | |
709 | } | |
1b51197d | 710 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
84d1b006 | 711 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
1b51197d JS |
712 | if (phba->sli_rev < LPFC_SLI_REV4) |
713 | lpfc_set_loopback_flag(phba); | |
6e7288d9 | 714 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
76a95d75 | 715 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
84d1b006 JS |
716 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
717 | "0498 Adapter failed to init, mbxCmd x%x " | |
718 | "INIT_LINK, mbxStatus x%x\n", | |
719 | mb->mbxCommand, mb->mbxStatus); | |
76a95d75 JS |
720 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
721 | /* Clear all interrupt enable conditions */ | |
722 | writel(0, phba->HCregaddr); | |
723 | readl(phba->HCregaddr); /* flush */ | |
724 | /* Clear all pending interrupts */ | |
725 | writel(0xffffffff, phba->HAregaddr); | |
726 | readl(phba->HAregaddr); /* flush */ | |
727 | } | |
84d1b006 | 728 | phba->link_state = LPFC_HBA_ERROR; |
6e7288d9 | 729 | if (rc != MBX_BUSY || flag == MBX_POLL) |
84d1b006 JS |
730 | mempool_free(pmb, phba->mbox_mem_pool); |
731 | return -EIO; | |
732 | } | |
e40a02c1 | 733 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
6e7288d9 JS |
734 | if (flag == MBX_POLL) |
735 | mempool_free(pmb, phba->mbox_mem_pool); | |
84d1b006 JS |
736 | |
737 | return 0; | |
738 | } | |
739 | ||
740 | /** | |
741 | * lpfc_hba_down_link - this routine downs the FC link | |
6e7288d9 JS |
742 | * @phba: pointer to lpfc hba data structure. |
743 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT | |
84d1b006 JS |
744 | * |
745 | * This routine will issue the DOWN_LINK mailbox command call. | |
746 | * It is available to other drivers through the lpfc_hba data | |
747 | * structure for use to stop the link. | |
748 | * | |
749 | * Return code | |
750 | * 0 - success | |
751 | * Any other value - error | |
752 | **/ | |
753 | int | |
6e7288d9 | 754 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
84d1b006 JS |
755 | { |
756 | LPFC_MBOXQ_t *pmb; | |
757 | int rc; | |
758 | ||
759 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
760 | if (!pmb) { | |
761 | phba->link_state = LPFC_HBA_ERROR; | |
762 | return -ENOMEM; | |
763 | } | |
764 | ||
765 | lpfc_printf_log(phba, | |
766 | KERN_ERR, LOG_INIT, | |
767 | "0491 Adapter Link is disabled.\n"); | |
768 | lpfc_down_link(phba, pmb); | |
769 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
6e7288d9 | 770 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
84d1b006 JS |
771 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
772 | lpfc_printf_log(phba, | |
773 | KERN_ERR, LOG_INIT, | |
774 | "2522 Adapter failed to issue DOWN_LINK" | |
775 | " mbox command rc 0x%x\n", rc); | |
776 | ||
777 | mempool_free(pmb, phba->mbox_mem_pool); | |
778 | return -EIO; | |
779 | } | |
6e7288d9 JS |
780 | if (flag == MBX_POLL) |
781 | mempool_free(pmb, phba->mbox_mem_pool); | |
782 | ||
84d1b006 JS |
783 | return 0; |
784 | } | |
785 | ||
e59058c4 | 786 | /** |
3621a710 | 787 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
e59058c4 JS |
788 | * @phba: pointer to lpfc HBA data structure. |
789 | * | |
790 | * This routine will do LPFC uninitialization before the HBA is reset when | |
791 | * bringing down the SLI Layer. | |
792 | * | |
793 | * Return codes | |
794 | * 0 - success. | |
795 | * Any other value - error. | |
796 | **/ | |
dea3101e | 797 | int |
2e0fef85 | 798 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
dea3101e | 799 | { |
1b32f6aa JS |
800 | struct lpfc_vport **vports; |
801 | int i; | |
3772a991 JS |
802 | |
803 | if (phba->sli_rev <= LPFC_SLI_REV3) { | |
804 | /* Disable interrupts */ | |
805 | writel(0, phba->HCregaddr); | |
806 | readl(phba->HCregaddr); /* flush */ | |
807 | } | |
dea3101e | 808 | |
1b32f6aa JS |
809 | if (phba->pport->load_flag & FC_UNLOADING) |
810 | lpfc_cleanup_discovery_resources(phba->pport); | |
811 | else { | |
812 | vports = lpfc_create_vport_work_array(phba); | |
813 | if (vports != NULL) | |
3772a991 JS |
814 | for (i = 0; i <= phba->max_vports && |
815 | vports[i] != NULL; i++) | |
1b32f6aa JS |
816 | lpfc_cleanup_discovery_resources(vports[i]); |
817 | lpfc_destroy_vport_work_array(phba, vports); | |
7f5f3d0d JS |
818 | } |
819 | return 0; | |
dea3101e JB |
820 | } |
821 | ||
e59058c4 | 822 | /** |
bcece5f5 | 823 | * lpfc_hba_free_post_buf - Perform lpfc uninitialization after HBA reset |
e59058c4 JS |
824 | * @phba: pointer to lpfc HBA data structure. |
825 | * | |
bcece5f5 JS |
826 | * This routine will cleanup posted ELS buffers after the HBA is reset |
827 | * when bringing down the SLI Layer. | |
828 | * | |
e59058c4 JS |
829 | * |
830 | * Return codes | |
bcece5f5 | 831 | * void. |
e59058c4 | 832 | **/ |
bcece5f5 JS |
833 | static void |
834 | lpfc_hba_free_post_buf(struct lpfc_hba *phba) | |
41415862 JW |
835 | { |
836 | struct lpfc_sli *psli = &phba->sli; | |
837 | struct lpfc_sli_ring *pring; | |
838 | struct lpfc_dmabuf *mp, *next_mp; | |
41415862 | 839 | |
92d7f7b0 JS |
840 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
841 | lpfc_sli_hbqbuf_free_all(phba); | |
842 | else { | |
843 | /* Cleanup preposted buffers on the ELS ring */ | |
bcece5f5 | 844 | spin_lock_irq(&phba->hbalock); |
92d7f7b0 JS |
845 | pring = &psli->ring[LPFC_ELS_RING]; |
846 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
847 | list_del(&mp->list); | |
848 | pring->postbufq_cnt--; | |
849 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
850 | kfree(mp); | |
851 | } | |
bcece5f5 | 852 | spin_unlock_irq(&phba->hbalock); |
41415862 | 853 | } |
bcece5f5 JS |
854 | } |
855 | ||
856 | /** | |
857 | * lpfc_hba_clean_txcmplq - Perform lpfc uninitialization after HBA reset | |
858 | * @phba: pointer to lpfc HBA data structure. | |
859 | * | |
860 | * This routine will cleanup the txcmplq after the HBA is reset when bringing | |
861 | * down the SLI Layer. | |
862 | * | |
863 | * Return codes | |
864 | * void | |
865 | **/ | |
866 | static void | |
867 | lpfc_hba_clean_txcmplq(struct lpfc_hba *phba) | |
868 | { | |
869 | struct lpfc_sli *psli = &phba->sli; | |
870 | struct lpfc_sli_ring *pring; | |
871 | LIST_HEAD(completions); | |
872 | int i; | |
873 | ||
874 | ||
41415862 JW |
875 | |
876 | for (i = 0; i < psli->num_rings; i++) { | |
877 | pring = &psli->ring[i]; | |
bcece5f5 JS |
878 | if (phba->sli_rev >= LPFC_SLI_REV4) |
879 | spin_lock_irq(&pring->ring_lock); | |
880 | else | |
881 | spin_lock_irq(&phba->hbalock); | |
09372820 JS |
882 | /* At this point in time the HBA is either reset or DOA. Either |
883 | * way, nothing should be on txcmplq as it will NEVER complete. | |
884 | */ | |
885 | list_splice_init(&pring->txcmplq, &completions); | |
bcece5f5 JS |
886 | |
887 | if (phba->sli_rev >= LPFC_SLI_REV4) | |
888 | spin_unlock_irq(&pring->ring_lock); | |
889 | else | |
890 | spin_unlock_irq(&phba->hbalock); | |
09372820 | 891 | |
a257bf90 JS |
892 | /* Cancel all the IOCBs from the completions list */ |
893 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
894 | IOERR_SLI_ABORTED); | |
41415862 JW |
895 | lpfc_sli_abort_iocb_ring(phba, pring); |
896 | } | |
bcece5f5 | 897 | } |
41415862 | 898 | |
bcece5f5 JS |
899 | /** |
900 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset | |
901 | int i; | |
902 | * @phba: pointer to lpfc HBA data structure. | |
903 | * | |
904 | * This routine will do uninitialization after the HBA is reset when bring | |
905 | * down the SLI Layer. | |
906 | * | |
907 | * Return codes | |
908 | * 0 - success. | |
909 | * Any other value - error. | |
910 | **/ | |
911 | static int | |
912 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) | |
913 | { | |
914 | lpfc_hba_free_post_buf(phba); | |
915 | lpfc_hba_clean_txcmplq(phba); | |
41415862 JW |
916 | return 0; |
917 | } | |
5af5eee7 | 918 | |
da0436e9 JS |
919 | /** |
920 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset | |
921 | * @phba: pointer to lpfc HBA data structure. | |
922 | * | |
923 | * This routine will do uninitialization after the HBA is reset when bring | |
924 | * down the SLI Layer. | |
925 | * | |
926 | * Return codes | |
af901ca1 | 927 | * 0 - success. |
da0436e9 JS |
928 | * Any other value - error. |
929 | **/ | |
930 | static int | |
931 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) | |
932 | { | |
933 | struct lpfc_scsi_buf *psb, *psb_next; | |
934 | LIST_HEAD(aborts); | |
da0436e9 | 935 | unsigned long iflag = 0; |
0f65ff68 JS |
936 | struct lpfc_sglq *sglq_entry = NULL; |
937 | ||
bcece5f5 JS |
938 | lpfc_hba_free_post_buf(phba); |
939 | lpfc_hba_clean_txcmplq(phba); | |
940 | ||
da0436e9 JS |
941 | /* At this point in time the HBA is either reset or DOA. Either |
942 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be | |
943 | * on the lpfc_sgl_list so that it can either be freed if the | |
944 | * driver is unloading or reposted if the driver is restarting | |
945 | * the port. | |
946 | */ | |
947 | spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */ | |
948 | /* scsl_buf_list */ | |
949 | /* abts_sgl_list_lock required because worker thread uses this | |
950 | * list. | |
951 | */ | |
952 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); | |
0f65ff68 JS |
953 | list_for_each_entry(sglq_entry, |
954 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) | |
955 | sglq_entry->state = SGL_FREED; | |
956 | ||
da0436e9 JS |
957 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
958 | &phba->sli4_hba.lpfc_sgl_list); | |
959 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); | |
960 | /* abts_scsi_buf_list_lock required because worker thread uses this | |
961 | * list. | |
962 | */ | |
963 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
964 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, | |
965 | &aborts); | |
966 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
967 | spin_unlock_irq(&phba->hbalock); | |
968 | ||
969 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { | |
970 | psb->pCmd = NULL; | |
971 | psb->status = IOSTAT_SUCCESS; | |
972 | } | |
a40fc5f0 JS |
973 | spin_lock_irqsave(&phba->scsi_buf_list_put_lock, iflag); |
974 | list_splice(&aborts, &phba->lpfc_scsi_buf_list_put); | |
975 | spin_unlock_irqrestore(&phba->scsi_buf_list_put_lock, iflag); | |
da0436e9 JS |
976 | return 0; |
977 | } | |
978 | ||
979 | /** | |
980 | * lpfc_hba_down_post - Wrapper func for hba down post routine | |
981 | * @phba: pointer to lpfc HBA data structure. | |
982 | * | |
983 | * This routine wraps the actual SLI3 or SLI4 routine for performing | |
984 | * uninitialization after the HBA is reset when bring down the SLI Layer. | |
985 | * | |
986 | * Return codes | |
af901ca1 | 987 | * 0 - success. |
da0436e9 JS |
988 | * Any other value - error. |
989 | **/ | |
990 | int | |
991 | lpfc_hba_down_post(struct lpfc_hba *phba) | |
992 | { | |
993 | return (*phba->lpfc_hba_down_post)(phba); | |
994 | } | |
41415862 | 995 | |
e59058c4 | 996 | /** |
3621a710 | 997 | * lpfc_hb_timeout - The HBA-timer timeout handler |
e59058c4 JS |
998 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
999 | * | |
1000 | * This is the HBA-timer timeout handler registered to the lpfc driver. When | |
1001 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver | |
1002 | * work-port-events bitmap and the worker thread is notified. This timeout | |
1003 | * event will be used by the worker thread to invoke the actual timeout | |
1004 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will | |
1005 | * be performed in the timeout handler and the HBA timeout event bit shall | |
1006 | * be cleared by the worker thread after it has taken the event bitmap out. | |
1007 | **/ | |
a6ababd2 | 1008 | static void |
858c9f6c JS |
1009 | lpfc_hb_timeout(unsigned long ptr) |
1010 | { | |
1011 | struct lpfc_hba *phba; | |
5e9d9b82 | 1012 | uint32_t tmo_posted; |
858c9f6c JS |
1013 | unsigned long iflag; |
1014 | ||
1015 | phba = (struct lpfc_hba *)ptr; | |
9399627f JS |
1016 | |
1017 | /* Check for heart beat timeout conditions */ | |
858c9f6c | 1018 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
5e9d9b82 JS |
1019 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
1020 | if (!tmo_posted) | |
858c9f6c JS |
1021 | phba->pport->work_port_events |= WORKER_HB_TMO; |
1022 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
1023 | ||
9399627f | 1024 | /* Tell the worker thread there is work to do */ |
5e9d9b82 JS |
1025 | if (!tmo_posted) |
1026 | lpfc_worker_wake_up(phba); | |
858c9f6c JS |
1027 | return; |
1028 | } | |
1029 | ||
19ca7609 JS |
1030 | /** |
1031 | * lpfc_rrq_timeout - The RRQ-timer timeout handler | |
1032 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. | |
1033 | * | |
1034 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When | |
1035 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver | |
1036 | * work-port-events bitmap and the worker thread is notified. This timeout | |
1037 | * event will be used by the worker thread to invoke the actual timeout | |
1038 | * handler routine, lpfc_rrq_handler. Any periodical operations will | |
1039 | * be performed in the timeout handler and the RRQ timeout event bit shall | |
1040 | * be cleared by the worker thread after it has taken the event bitmap out. | |
1041 | **/ | |
1042 | static void | |
1043 | lpfc_rrq_timeout(unsigned long ptr) | |
1044 | { | |
1045 | struct lpfc_hba *phba; | |
19ca7609 JS |
1046 | unsigned long iflag; |
1047 | ||
1048 | phba = (struct lpfc_hba *)ptr; | |
1049 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
06918ac5 JS |
1050 | if (!(phba->pport->load_flag & FC_UNLOADING)) |
1051 | phba->hba_flag |= HBA_RRQ_ACTIVE; | |
1052 | else | |
1053 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
19ca7609 | 1054 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
06918ac5 JS |
1055 | |
1056 | if (!(phba->pport->load_flag & FC_UNLOADING)) | |
1057 | lpfc_worker_wake_up(phba); | |
19ca7609 JS |
1058 | } |
1059 | ||
e59058c4 | 1060 | /** |
3621a710 | 1061 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
e59058c4 JS |
1062 | * @phba: pointer to lpfc hba data structure. |
1063 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
1064 | * | |
1065 | * This is the callback function to the lpfc heart-beat mailbox command. | |
1066 | * If configured, the lpfc driver issues the heart-beat mailbox command to | |
1067 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the | |
1068 | * heart-beat mailbox command is issued, the driver shall set up heart-beat | |
1069 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks | |
1070 | * heart-beat outstanding state. Once the mailbox command comes back and | |
1071 | * no error conditions detected, the heart-beat mailbox command timer is | |
1072 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding | |
1073 | * state is cleared for the next heart-beat. If the timer expired with the | |
1074 | * heart-beat outstanding state set, the driver will put the HBA offline. | |
1075 | **/ | |
858c9f6c JS |
1076 | static void |
1077 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
1078 | { | |
1079 | unsigned long drvr_flag; | |
1080 | ||
1081 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
1082 | phba->hb_outstanding = 0; | |
1083 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
1084 | ||
9399627f | 1085 | /* Check and reset heart-beat timer is necessary */ |
858c9f6c JS |
1086 | mempool_free(pmboxq, phba->mbox_mem_pool); |
1087 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && | |
1088 | !(phba->link_state == LPFC_HBA_ERROR) && | |
51ef4c26 | 1089 | !(phba->pport->load_flag & FC_UNLOADING)) |
858c9f6c | 1090 | mod_timer(&phba->hb_tmofunc, |
256ec0d0 JS |
1091 | jiffies + |
1092 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); | |
858c9f6c JS |
1093 | return; |
1094 | } | |
1095 | ||
e59058c4 | 1096 | /** |
3621a710 | 1097 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
e59058c4 JS |
1098 | * @phba: pointer to lpfc hba data structure. |
1099 | * | |
1100 | * This is the actual HBA-timer timeout handler to be invoked by the worker | |
1101 | * thread whenever the HBA timer fired and HBA-timeout event posted. This | |
1102 | * handler performs any periodic operations needed for the device. If such | |
1103 | * periodic event has already been attended to either in the interrupt handler | |
1104 | * or by processing slow-ring or fast-ring events within the HBA-timer | |
1105 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets | |
1106 | * the timer for the next timeout period. If lpfc heart-beat mailbox command | |
1107 | * is configured and there is no heart-beat mailbox command outstanding, a | |
1108 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there | |
1109 | * has been a heart-beat mailbox command outstanding, the HBA shall be put | |
1110 | * to offline. | |
1111 | **/ | |
858c9f6c JS |
1112 | void |
1113 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) | |
1114 | { | |
45ed1190 | 1115 | struct lpfc_vport **vports; |
858c9f6c | 1116 | LPFC_MBOXQ_t *pmboxq; |
0ff10d46 | 1117 | struct lpfc_dmabuf *buf_ptr; |
45ed1190 | 1118 | int retval, i; |
858c9f6c | 1119 | struct lpfc_sli *psli = &phba->sli; |
0ff10d46 | 1120 | LIST_HEAD(completions); |
858c9f6c | 1121 | |
45ed1190 JS |
1122 | vports = lpfc_create_vport_work_array(phba); |
1123 | if (vports != NULL) | |
1124 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) | |
1125 | lpfc_rcv_seq_check_edtov(vports[i]); | |
1126 | lpfc_destroy_vport_work_array(phba, vports); | |
1127 | ||
858c9f6c | 1128 | if ((phba->link_state == LPFC_HBA_ERROR) || |
51ef4c26 | 1129 | (phba->pport->load_flag & FC_UNLOADING) || |
858c9f6c JS |
1130 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
1131 | return; | |
1132 | ||
1133 | spin_lock_irq(&phba->pport->work_port_lock); | |
858c9f6c | 1134 | |
256ec0d0 JS |
1135 | if (time_after(phba->last_completion_time + |
1136 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL), | |
1137 | jiffies)) { | |
858c9f6c JS |
1138 | spin_unlock_irq(&phba->pport->work_port_lock); |
1139 | if (!phba->hb_outstanding) | |
1140 | mod_timer(&phba->hb_tmofunc, | |
256ec0d0 JS |
1141 | jiffies + |
1142 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL)); | |
858c9f6c JS |
1143 | else |
1144 | mod_timer(&phba->hb_tmofunc, | |
256ec0d0 JS |
1145 | jiffies + |
1146 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); | |
858c9f6c JS |
1147 | return; |
1148 | } | |
1149 | spin_unlock_irq(&phba->pport->work_port_lock); | |
1150 | ||
0ff10d46 JS |
1151 | if (phba->elsbuf_cnt && |
1152 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { | |
1153 | spin_lock_irq(&phba->hbalock); | |
1154 | list_splice_init(&phba->elsbuf, &completions); | |
1155 | phba->elsbuf_cnt = 0; | |
1156 | phba->elsbuf_prev_cnt = 0; | |
1157 | spin_unlock_irq(&phba->hbalock); | |
1158 | ||
1159 | while (!list_empty(&completions)) { | |
1160 | list_remove_head(&completions, buf_ptr, | |
1161 | struct lpfc_dmabuf, list); | |
1162 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
1163 | kfree(buf_ptr); | |
1164 | } | |
1165 | } | |
1166 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; | |
1167 | ||
858c9f6c | 1168 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
13815c83 JS |
1169 | if (phba->cfg_enable_hba_heartbeat) { |
1170 | if (!phba->hb_outstanding) { | |
bc73905a JS |
1171 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
1172 | (list_empty(&psli->mboxq))) { | |
1173 | pmboxq = mempool_alloc(phba->mbox_mem_pool, | |
1174 | GFP_KERNEL); | |
1175 | if (!pmboxq) { | |
1176 | mod_timer(&phba->hb_tmofunc, | |
1177 | jiffies + | |
256ec0d0 JS |
1178 | msecs_to_jiffies(1000 * |
1179 | LPFC_HB_MBOX_INTERVAL)); | |
bc73905a JS |
1180 | return; |
1181 | } | |
1182 | ||
1183 | lpfc_heart_beat(phba, pmboxq); | |
1184 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; | |
1185 | pmboxq->vport = phba->pport; | |
1186 | retval = lpfc_sli_issue_mbox(phba, pmboxq, | |
1187 | MBX_NOWAIT); | |
1188 | ||
1189 | if (retval != MBX_BUSY && | |
1190 | retval != MBX_SUCCESS) { | |
1191 | mempool_free(pmboxq, | |
1192 | phba->mbox_mem_pool); | |
1193 | mod_timer(&phba->hb_tmofunc, | |
1194 | jiffies + | |
256ec0d0 JS |
1195 | msecs_to_jiffies(1000 * |
1196 | LPFC_HB_MBOX_INTERVAL)); | |
bc73905a JS |
1197 | return; |
1198 | } | |
1199 | phba->skipped_hb = 0; | |
1200 | phba->hb_outstanding = 1; | |
1201 | } else if (time_before_eq(phba->last_completion_time, | |
1202 | phba->skipped_hb)) { | |
1203 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
1204 | "2857 Last completion time not " | |
1205 | " updated in %d ms\n", | |
1206 | jiffies_to_msecs(jiffies | |
1207 | - phba->last_completion_time)); | |
1208 | } else | |
1209 | phba->skipped_hb = jiffies; | |
1210 | ||
858c9f6c | 1211 | mod_timer(&phba->hb_tmofunc, |
256ec0d0 JS |
1212 | jiffies + |
1213 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); | |
858c9f6c | 1214 | return; |
13815c83 JS |
1215 | } else { |
1216 | /* | |
1217 | * If heart beat timeout called with hb_outstanding set | |
dcf2a4e0 JS |
1218 | * we need to give the hb mailbox cmd a chance to |
1219 | * complete or TMO. | |
13815c83 | 1220 | */ |
dcf2a4e0 JS |
1221 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
1222 | "0459 Adapter heartbeat still out" | |
1223 | "standing:last compl time was %d ms.\n", | |
1224 | jiffies_to_msecs(jiffies | |
1225 | - phba->last_completion_time)); | |
1226 | mod_timer(&phba->hb_tmofunc, | |
256ec0d0 JS |
1227 | jiffies + |
1228 | msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT)); | |
858c9f6c | 1229 | } |
858c9f6c JS |
1230 | } |
1231 | } | |
1232 | ||
e59058c4 | 1233 | /** |
3621a710 | 1234 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
e59058c4 JS |
1235 | * @phba: pointer to lpfc hba data structure. |
1236 | * | |
1237 | * This routine is called to bring the HBA offline when HBA hardware error | |
1238 | * other than Port Error 6 has been detected. | |
1239 | **/ | |
09372820 JS |
1240 | static void |
1241 | lpfc_offline_eratt(struct lpfc_hba *phba) | |
1242 | { | |
1243 | struct lpfc_sli *psli = &phba->sli; | |
1244 | ||
1245 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1246 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
09372820 | 1247 | spin_unlock_irq(&phba->hbalock); |
618a5230 | 1248 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
09372820 JS |
1249 | |
1250 | lpfc_offline(phba); | |
1251 | lpfc_reset_barrier(phba); | |
f4b4c68f | 1252 | spin_lock_irq(&phba->hbalock); |
09372820 | 1253 | lpfc_sli_brdreset(phba); |
f4b4c68f | 1254 | spin_unlock_irq(&phba->hbalock); |
09372820 JS |
1255 | lpfc_hba_down_post(phba); |
1256 | lpfc_sli_brdready(phba, HS_MBRDY); | |
1257 | lpfc_unblock_mgmt_io(phba); | |
1258 | phba->link_state = LPFC_HBA_ERROR; | |
1259 | return; | |
1260 | } | |
1261 | ||
da0436e9 JS |
1262 | /** |
1263 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention | |
1264 | * @phba: pointer to lpfc hba data structure. | |
1265 | * | |
1266 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error | |
1267 | * other than Port Error 6 has been detected. | |
1268 | **/ | |
a88dbb6a | 1269 | void |
da0436e9 JS |
1270 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) |
1271 | { | |
618a5230 | 1272 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
da0436e9 JS |
1273 | lpfc_offline(phba); |
1274 | lpfc_sli4_brdreset(phba); | |
1275 | lpfc_hba_down_post(phba); | |
1276 | lpfc_sli4_post_status_check(phba); | |
1277 | lpfc_unblock_mgmt_io(phba); | |
1278 | phba->link_state = LPFC_HBA_ERROR; | |
1279 | } | |
1280 | ||
a257bf90 JS |
1281 | /** |
1282 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler | |
1283 | * @phba: pointer to lpfc hba data structure. | |
1284 | * | |
1285 | * This routine is invoked to handle the deferred HBA hardware error | |
1286 | * conditions. This type of error is indicated by HBA by setting ER1 | |
1287 | * and another ER bit in the host status register. The driver will | |
1288 | * wait until the ER1 bit clears before handling the error condition. | |
1289 | **/ | |
1290 | static void | |
1291 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) | |
1292 | { | |
1293 | uint32_t old_host_status = phba->work_hs; | |
1294 | struct lpfc_sli_ring *pring; | |
1295 | struct lpfc_sli *psli = &phba->sli; | |
1296 | ||
f4b4c68f JS |
1297 | /* If the pci channel is offline, ignore possible errors, |
1298 | * since we cannot communicate with the pci card anyway. | |
1299 | */ | |
1300 | if (pci_channel_offline(phba->pcidev)) { | |
1301 | spin_lock_irq(&phba->hbalock); | |
1302 | phba->hba_flag &= ~DEFER_ERATT; | |
1303 | spin_unlock_irq(&phba->hbalock); | |
1304 | return; | |
1305 | } | |
1306 | ||
a257bf90 JS |
1307 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
1308 | "0479 Deferred Adapter Hardware Error " | |
1309 | "Data: x%x x%x x%x\n", | |
1310 | phba->work_hs, | |
1311 | phba->work_status[0], phba->work_status[1]); | |
1312 | ||
1313 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1314 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
a257bf90 JS |
1315 | spin_unlock_irq(&phba->hbalock); |
1316 | ||
1317 | ||
1318 | /* | |
1319 | * Firmware stops when it triggred erratt. That could cause the I/Os | |
1320 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the | |
1321 | * SCSI layer retry it after re-establishing link. | |
1322 | */ | |
1323 | pring = &psli->ring[psli->fcp_ring]; | |
1324 | lpfc_sli_abort_iocb_ring(phba, pring); | |
1325 | ||
1326 | /* | |
1327 | * There was a firmware error. Take the hba offline and then | |
1328 | * attempt to restart it. | |
1329 | */ | |
618a5230 | 1330 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
a257bf90 JS |
1331 | lpfc_offline(phba); |
1332 | ||
1333 | /* Wait for the ER1 bit to clear.*/ | |
1334 | while (phba->work_hs & HS_FFER1) { | |
1335 | msleep(100); | |
9940b97b JS |
1336 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
1337 | phba->work_hs = UNPLUG_ERR ; | |
1338 | break; | |
1339 | } | |
a257bf90 JS |
1340 | /* If driver is unloading let the worker thread continue */ |
1341 | if (phba->pport->load_flag & FC_UNLOADING) { | |
1342 | phba->work_hs = 0; | |
1343 | break; | |
1344 | } | |
1345 | } | |
1346 | ||
1347 | /* | |
1348 | * This is to ptrotect against a race condition in which | |
1349 | * first write to the host attention register clear the | |
1350 | * host status register. | |
1351 | */ | |
1352 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) | |
1353 | phba->work_hs = old_host_status & ~HS_FFER1; | |
1354 | ||
3772a991 | 1355 | spin_lock_irq(&phba->hbalock); |
a257bf90 | 1356 | phba->hba_flag &= ~DEFER_ERATT; |
3772a991 | 1357 | spin_unlock_irq(&phba->hbalock); |
a257bf90 JS |
1358 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
1359 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); | |
1360 | } | |
1361 | ||
3772a991 JS |
1362 | static void |
1363 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) | |
1364 | { | |
1365 | struct lpfc_board_event_header board_event; | |
1366 | struct Scsi_Host *shost; | |
1367 | ||
1368 | board_event.event_type = FC_REG_BOARD_EVENT; | |
1369 | board_event.subcategory = LPFC_EVENT_PORTINTERR; | |
1370 | shost = lpfc_shost_from_vport(phba->pport); | |
1371 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1372 | sizeof(board_event), | |
1373 | (char *) &board_event, | |
1374 | LPFC_NL_VENDOR_ID); | |
1375 | } | |
1376 | ||
e59058c4 | 1377 | /** |
3772a991 | 1378 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
e59058c4 JS |
1379 | * @phba: pointer to lpfc hba data structure. |
1380 | * | |
1381 | * This routine is invoked to handle the following HBA hardware error | |
1382 | * conditions: | |
1383 | * 1 - HBA error attention interrupt | |
1384 | * 2 - DMA ring index out of range | |
1385 | * 3 - Mailbox command came back as unknown | |
1386 | **/ | |
3772a991 JS |
1387 | static void |
1388 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) | |
dea3101e | 1389 | { |
2e0fef85 | 1390 | struct lpfc_vport *vport = phba->pport; |
2e0fef85 | 1391 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 1392 | struct lpfc_sli_ring *pring; |
d2873e4c | 1393 | uint32_t event_data; |
57127f15 JS |
1394 | unsigned long temperature; |
1395 | struct temp_event temp_event_data; | |
92d7f7b0 | 1396 | struct Scsi_Host *shost; |
2e0fef85 | 1397 | |
8d63f375 | 1398 | /* If the pci channel is offline, ignore possible errors, |
3772a991 JS |
1399 | * since we cannot communicate with the pci card anyway. |
1400 | */ | |
1401 | if (pci_channel_offline(phba->pcidev)) { | |
1402 | spin_lock_irq(&phba->hbalock); | |
1403 | phba->hba_flag &= ~DEFER_ERATT; | |
1404 | spin_unlock_irq(&phba->hbalock); | |
8d63f375 | 1405 | return; |
3772a991 JS |
1406 | } |
1407 | ||
13815c83 JS |
1408 | /* If resets are disabled then leave the HBA alone and return */ |
1409 | if (!phba->cfg_enable_hba_reset) | |
1410 | return; | |
dea3101e | 1411 | |
ea2151b4 | 1412 | /* Send an internal error event to mgmt application */ |
3772a991 | 1413 | lpfc_board_errevt_to_mgmt(phba); |
ea2151b4 | 1414 | |
a257bf90 JS |
1415 | if (phba->hba_flag & DEFER_ERATT) |
1416 | lpfc_handle_deferred_eratt(phba); | |
1417 | ||
dcf2a4e0 JS |
1418 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
1419 | if (phba->work_hs & HS_FFER6) | |
1420 | /* Re-establishing Link */ | |
1421 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
1422 | "1301 Re-establishing Link " | |
1423 | "Data: x%x x%x x%x\n", | |
1424 | phba->work_hs, phba->work_status[0], | |
1425 | phba->work_status[1]); | |
1426 | if (phba->work_hs & HS_FFER8) | |
1427 | /* Device Zeroization */ | |
1428 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
1429 | "2861 Host Authentication device " | |
1430 | "zeroization Data:x%x x%x x%x\n", | |
1431 | phba->work_hs, phba->work_status[0], | |
1432 | phba->work_status[1]); | |
58da1ffb | 1433 | |
92d7f7b0 | 1434 | spin_lock_irq(&phba->hbalock); |
f4b4c68f | 1435 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
92d7f7b0 | 1436 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1437 | |
1438 | /* | |
1439 | * Firmware stops when it triggled erratt with HS_FFER6. | |
1440 | * That could cause the I/Os dropped by the firmware. | |
1441 | * Error iocb (I/O) on txcmplq and let the SCSI layer | |
1442 | * retry it after re-establishing link. | |
1443 | */ | |
1444 | pring = &psli->ring[psli->fcp_ring]; | |
1445 | lpfc_sli_abort_iocb_ring(phba, pring); | |
1446 | ||
dea3101e JB |
1447 | /* |
1448 | * There was a firmware error. Take the hba offline and then | |
1449 | * attempt to restart it. | |
1450 | */ | |
618a5230 | 1451 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
dea3101e | 1452 | lpfc_offline(phba); |
41415862 | 1453 | lpfc_sli_brdrestart(phba); |
dea3101e | 1454 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
46fa311e | 1455 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
1456 | return; |
1457 | } | |
46fa311e | 1458 | lpfc_unblock_mgmt_io(phba); |
57127f15 JS |
1459 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
1460 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); | |
1461 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
1462 | temp_event_data.event_code = LPFC_CRIT_TEMP; | |
1463 | temp_event_data.data = (uint32_t)temperature; | |
1464 | ||
1465 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 1466 | "0406 Adapter maximum temperature exceeded " |
57127f15 JS |
1467 | "(%ld), taking this port offline " |
1468 | "Data: x%x x%x x%x\n", | |
1469 | temperature, phba->work_hs, | |
1470 | phba->work_status[0], phba->work_status[1]); | |
1471 | ||
1472 | shost = lpfc_shost_from_vport(phba->pport); | |
1473 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1474 | sizeof(temp_event_data), | |
1475 | (char *) &temp_event_data, | |
1476 | SCSI_NL_VID_TYPE_PCI | |
1477 | | PCI_VENDOR_ID_EMULEX); | |
1478 | ||
7af67051 | 1479 | spin_lock_irq(&phba->hbalock); |
7af67051 JS |
1480 | phba->over_temp_state = HBA_OVER_TEMP; |
1481 | spin_unlock_irq(&phba->hbalock); | |
09372820 | 1482 | lpfc_offline_eratt(phba); |
57127f15 | 1483 | |
dea3101e JB |
1484 | } else { |
1485 | /* The if clause above forces this code path when the status | |
9399627f JS |
1486 | * failure is a value other than FFER6. Do not call the offline |
1487 | * twice. This is the adapter hardware error path. | |
dea3101e JB |
1488 | */ |
1489 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 | 1490 | "0457 Adapter Hardware Error " |
dea3101e | 1491 | "Data: x%x x%x x%x\n", |
e8b62011 | 1492 | phba->work_hs, |
dea3101e JB |
1493 | phba->work_status[0], phba->work_status[1]); |
1494 | ||
d2873e4c | 1495 | event_data = FC_REG_DUMP_EVENT; |
92d7f7b0 | 1496 | shost = lpfc_shost_from_vport(vport); |
2e0fef85 | 1497 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
d2873e4c JS |
1498 | sizeof(event_data), (char *) &event_data, |
1499 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
1500 | ||
09372820 | 1501 | lpfc_offline_eratt(phba); |
dea3101e | 1502 | } |
9399627f | 1503 | return; |
dea3101e JB |
1504 | } |
1505 | ||
618a5230 JS |
1506 | /** |
1507 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg | |
1508 | * @phba: pointer to lpfc hba data structure. | |
1509 | * @mbx_action: flag for mailbox shutdown action. | |
1510 | * | |
1511 | * This routine is invoked to perform an SLI4 port PCI function reset in | |
1512 | * response to port status register polling attention. It waits for port | |
1513 | * status register (ERR, RDY, RN) bits before proceeding with function reset. | |
1514 | * During this process, interrupt vectors are freed and later requested | |
1515 | * for handling possible port resource change. | |
1516 | **/ | |
1517 | static int | |
e10b2022 JS |
1518 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action, |
1519 | bool en_rn_msg) | |
618a5230 JS |
1520 | { |
1521 | int rc; | |
1522 | uint32_t intr_mode; | |
1523 | ||
1524 | /* | |
1525 | * On error status condition, driver need to wait for port | |
1526 | * ready before performing reset. | |
1527 | */ | |
1528 | rc = lpfc_sli4_pdev_status_reg_wait(phba); | |
1529 | if (!rc) { | |
1530 | /* need reset: attempt for port recovery */ | |
e10b2022 JS |
1531 | if (en_rn_msg) |
1532 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1533 | "2887 Reset Needed: Attempting Port " | |
1534 | "Recovery...\n"); | |
618a5230 JS |
1535 | lpfc_offline_prep(phba, mbx_action); |
1536 | lpfc_offline(phba); | |
1537 | /* release interrupt for possible resource change */ | |
1538 | lpfc_sli4_disable_intr(phba); | |
1539 | lpfc_sli_brdrestart(phba); | |
1540 | /* request and enable interrupt */ | |
1541 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); | |
1542 | if (intr_mode == LPFC_INTR_ERROR) { | |
1543 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1544 | "3175 Failed to enable interrupt\n"); | |
1545 | return -EIO; | |
1546 | } else { | |
1547 | phba->intr_mode = intr_mode; | |
1548 | } | |
1549 | rc = lpfc_online(phba); | |
1550 | if (rc == 0) | |
1551 | lpfc_unblock_mgmt_io(phba); | |
1552 | } | |
1553 | return rc; | |
1554 | } | |
1555 | ||
da0436e9 JS |
1556 | /** |
1557 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler | |
1558 | * @phba: pointer to lpfc hba data structure. | |
1559 | * | |
1560 | * This routine is invoked to handle the SLI4 HBA hardware error attention | |
1561 | * conditions. | |
1562 | **/ | |
1563 | static void | |
1564 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) | |
1565 | { | |
1566 | struct lpfc_vport *vport = phba->pport; | |
1567 | uint32_t event_data; | |
1568 | struct Scsi_Host *shost; | |
2fcee4bf | 1569 | uint32_t if_type; |
2e90f4b5 JS |
1570 | struct lpfc_register portstat_reg = {0}; |
1571 | uint32_t reg_err1, reg_err2; | |
1572 | uint32_t uerrlo_reg, uemasklo_reg; | |
1573 | uint32_t pci_rd_rc1, pci_rd_rc2; | |
e10b2022 | 1574 | bool en_rn_msg = true; |
73d91e50 | 1575 | int rc; |
da0436e9 JS |
1576 | |
1577 | /* If the pci channel is offline, ignore possible errors, since | |
1578 | * we cannot communicate with the pci card anyway. | |
1579 | */ | |
1580 | if (pci_channel_offline(phba->pcidev)) | |
1581 | return; | |
1582 | /* If resets are disabled then leave the HBA alone and return */ | |
1583 | if (!phba->cfg_enable_hba_reset) | |
1584 | return; | |
1585 | ||
2fcee4bf JS |
1586 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
1587 | switch (if_type) { | |
1588 | case LPFC_SLI_INTF_IF_TYPE_0: | |
2e90f4b5 JS |
1589 | pci_rd_rc1 = lpfc_readl( |
1590 | phba->sli4_hba.u.if_type0.UERRLOregaddr, | |
1591 | &uerrlo_reg); | |
1592 | pci_rd_rc2 = lpfc_readl( | |
1593 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, | |
1594 | &uemasklo_reg); | |
1595 | /* consider PCI bus read error as pci_channel_offline */ | |
1596 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) | |
1597 | return; | |
2fcee4bf JS |
1598 | lpfc_sli4_offline_eratt(phba); |
1599 | break; | |
1600 | case LPFC_SLI_INTF_IF_TYPE_2: | |
2e90f4b5 JS |
1601 | pci_rd_rc1 = lpfc_readl( |
1602 | phba->sli4_hba.u.if_type2.STATUSregaddr, | |
1603 | &portstat_reg.word0); | |
1604 | /* consider PCI bus read error as pci_channel_offline */ | |
6b5151fd JS |
1605 | if (pci_rd_rc1 == -EIO) { |
1606 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1607 | "3151 PCI bus read access failure: x%x\n", | |
1608 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); | |
2e90f4b5 | 1609 | return; |
6b5151fd | 1610 | } |
2e90f4b5 JS |
1611 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
1612 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); | |
2fcee4bf JS |
1613 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
1614 | /* TODO: Register for Overtemp async events. */ | |
1615 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1616 | "2889 Port Overtemperature event, " | |
026abb87 | 1617 | "taking port offline\n"); |
2fcee4bf JS |
1618 | spin_lock_irq(&phba->hbalock); |
1619 | phba->over_temp_state = HBA_OVER_TEMP; | |
1620 | spin_unlock_irq(&phba->hbalock); | |
1621 | lpfc_sli4_offline_eratt(phba); | |
2e90f4b5 | 1622 | break; |
2fcee4bf | 1623 | } |
2e90f4b5 | 1624 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
e10b2022 | 1625 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) { |
2e90f4b5 | 1626 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e10b2022 JS |
1627 | "3143 Port Down: Firmware Update " |
1628 | "Detected\n"); | |
1629 | en_rn_msg = false; | |
1630 | } else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && | |
2e90f4b5 JS |
1631 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) |
1632 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1633 | "3144 Port Down: Debug Dump\n"); | |
1634 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && | |
1635 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) | |
1636 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1637 | "3145 Port Down: Provisioning\n"); | |
618a5230 JS |
1638 | |
1639 | /* Check port status register for function reset */ | |
e10b2022 JS |
1640 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT, |
1641 | en_rn_msg); | |
618a5230 JS |
1642 | if (rc == 0) { |
1643 | /* don't report event on forced debug dump */ | |
1644 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && | |
1645 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) | |
1646 | return; | |
1647 | else | |
1648 | break; | |
2fcee4bf | 1649 | } |
618a5230 | 1650 | /* fall through for not able to recover */ |
6b5151fd JS |
1651 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
1652 | "3152 Unrecoverable error, bring the port " | |
1653 | "offline\n"); | |
2fcee4bf JS |
1654 | lpfc_sli4_offline_eratt(phba); |
1655 | break; | |
1656 | case LPFC_SLI_INTF_IF_TYPE_1: | |
1657 | default: | |
1658 | break; | |
1659 | } | |
2e90f4b5 JS |
1660 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
1661 | "3123 Report dump event to upper layer\n"); | |
1662 | /* Send an internal error event to mgmt application */ | |
1663 | lpfc_board_errevt_to_mgmt(phba); | |
1664 | ||
1665 | event_data = FC_REG_DUMP_EVENT; | |
1666 | shost = lpfc_shost_from_vport(vport); | |
1667 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1668 | sizeof(event_data), (char *) &event_data, | |
1669 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
da0436e9 JS |
1670 | } |
1671 | ||
1672 | /** | |
1673 | * lpfc_handle_eratt - Wrapper func for handling hba error attention | |
1674 | * @phba: pointer to lpfc HBA data structure. | |
1675 | * | |
1676 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling | |
1677 | * routine from the API jump table function pointer from the lpfc_hba struct. | |
1678 | * | |
1679 | * Return codes | |
af901ca1 | 1680 | * 0 - success. |
da0436e9 JS |
1681 | * Any other value - error. |
1682 | **/ | |
1683 | void | |
1684 | lpfc_handle_eratt(struct lpfc_hba *phba) | |
1685 | { | |
1686 | (*phba->lpfc_handle_eratt)(phba); | |
1687 | } | |
1688 | ||
e59058c4 | 1689 | /** |
3621a710 | 1690 | * lpfc_handle_latt - The HBA link event handler |
e59058c4 JS |
1691 | * @phba: pointer to lpfc hba data structure. |
1692 | * | |
1693 | * This routine is invoked from the worker thread to handle a HBA host | |
1694 | * attention link event. | |
1695 | **/ | |
dea3101e | 1696 | void |
2e0fef85 | 1697 | lpfc_handle_latt(struct lpfc_hba *phba) |
dea3101e | 1698 | { |
2e0fef85 JS |
1699 | struct lpfc_vport *vport = phba->pport; |
1700 | struct lpfc_sli *psli = &phba->sli; | |
dea3101e JB |
1701 | LPFC_MBOXQ_t *pmb; |
1702 | volatile uint32_t control; | |
1703 | struct lpfc_dmabuf *mp; | |
09372820 | 1704 | int rc = 0; |
dea3101e JB |
1705 | |
1706 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
09372820 JS |
1707 | if (!pmb) { |
1708 | rc = 1; | |
dea3101e | 1709 | goto lpfc_handle_latt_err_exit; |
09372820 | 1710 | } |
dea3101e JB |
1711 | |
1712 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
09372820 JS |
1713 | if (!mp) { |
1714 | rc = 2; | |
dea3101e | 1715 | goto lpfc_handle_latt_free_pmb; |
09372820 | 1716 | } |
dea3101e JB |
1717 | |
1718 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
09372820 JS |
1719 | if (!mp->virt) { |
1720 | rc = 3; | |
dea3101e | 1721 | goto lpfc_handle_latt_free_mp; |
09372820 | 1722 | } |
dea3101e | 1723 | |
6281bfe0 | 1724 | /* Cleanup any outstanding ELS commands */ |
549e55cd | 1725 | lpfc_els_flush_all_cmd(phba); |
dea3101e JB |
1726 | |
1727 | psli->slistat.link_event++; | |
76a95d75 JS |
1728 | lpfc_read_topology(phba, pmb, mp); |
1729 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
2e0fef85 | 1730 | pmb->vport = vport; |
0d2b6b83 JS |
1731 | /* Block ELS IOCBs until we have processed this mbox command */ |
1732 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
0b727fea | 1733 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
09372820 JS |
1734 | if (rc == MBX_NOT_FINISHED) { |
1735 | rc = 4; | |
14691150 | 1736 | goto lpfc_handle_latt_free_mbuf; |
09372820 | 1737 | } |
dea3101e JB |
1738 | |
1739 | /* Clear Link Attention in HA REG */ | |
2e0fef85 | 1740 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1741 | writel(HA_LATT, phba->HAregaddr); |
1742 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1743 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1744 | |
1745 | return; | |
1746 | ||
14691150 | 1747 | lpfc_handle_latt_free_mbuf: |
0d2b6b83 | 1748 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
14691150 | 1749 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
dea3101e JB |
1750 | lpfc_handle_latt_free_mp: |
1751 | kfree(mp); | |
1752 | lpfc_handle_latt_free_pmb: | |
1dcb58e5 | 1753 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e JB |
1754 | lpfc_handle_latt_err_exit: |
1755 | /* Enable Link attention interrupts */ | |
2e0fef85 | 1756 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1757 | psli->sli_flag |= LPFC_PROCESS_LA; |
1758 | control = readl(phba->HCregaddr); | |
1759 | control |= HC_LAINT_ENA; | |
1760 | writel(control, phba->HCregaddr); | |
1761 | readl(phba->HCregaddr); /* flush */ | |
1762 | ||
1763 | /* Clear Link Attention in HA REG */ | |
1764 | writel(HA_LATT, phba->HAregaddr); | |
1765 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1766 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1767 | lpfc_linkdown(phba); |
2e0fef85 | 1768 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 1769 | |
09372820 JS |
1770 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
1771 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); | |
dea3101e JB |
1772 | |
1773 | return; | |
1774 | } | |
1775 | ||
e59058c4 | 1776 | /** |
3621a710 | 1777 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
e59058c4 JS |
1778 | * @phba: pointer to lpfc hba data structure. |
1779 | * @vpd: pointer to the vital product data. | |
1780 | * @len: length of the vital product data in bytes. | |
1781 | * | |
1782 | * This routine parses the Vital Product Data (VPD). The VPD is treated as | |
1783 | * an array of characters. In this routine, the ModelName, ProgramType, and | |
1784 | * ModelDesc, etc. fields of the phba data structure will be populated. | |
1785 | * | |
1786 | * Return codes | |
1787 | * 0 - pointer to the VPD passed in is NULL | |
1788 | * 1 - success | |
1789 | **/ | |
3772a991 | 1790 | int |
2e0fef85 | 1791 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
dea3101e JB |
1792 | { |
1793 | uint8_t lenlo, lenhi; | |
07da60c1 | 1794 | int Length; |
dea3101e JB |
1795 | int i, j; |
1796 | int finished = 0; | |
1797 | int index = 0; | |
1798 | ||
1799 | if (!vpd) | |
1800 | return 0; | |
1801 | ||
1802 | /* Vital Product */ | |
ed957684 | 1803 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
e8b62011 | 1804 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
dea3101e JB |
1805 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
1806 | (uint32_t) vpd[3]); | |
74b72a59 | 1807 | while (!finished && (index < (len - 4))) { |
dea3101e JB |
1808 | switch (vpd[index]) { |
1809 | case 0x82: | |
74b72a59 | 1810 | case 0x91: |
dea3101e JB |
1811 | index += 1; |
1812 | lenlo = vpd[index]; | |
1813 | index += 1; | |
1814 | lenhi = vpd[index]; | |
1815 | index += 1; | |
1816 | i = ((((unsigned short)lenhi) << 8) + lenlo); | |
1817 | index += i; | |
1818 | break; | |
1819 | case 0x90: | |
1820 | index += 1; | |
1821 | lenlo = vpd[index]; | |
1822 | index += 1; | |
1823 | lenhi = vpd[index]; | |
1824 | index += 1; | |
1825 | Length = ((((unsigned short)lenhi) << 8) + lenlo); | |
74b72a59 JW |
1826 | if (Length > len - index) |
1827 | Length = len - index; | |
dea3101e JB |
1828 | while (Length > 0) { |
1829 | /* Look for Serial Number */ | |
1830 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { | |
1831 | index += 2; | |
1832 | i = vpd[index]; | |
1833 | index += 1; | |
1834 | j = 0; | |
1835 | Length -= (3+i); | |
1836 | while(i--) { | |
1837 | phba->SerialNumber[j++] = vpd[index++]; | |
1838 | if (j == 31) | |
1839 | break; | |
1840 | } | |
1841 | phba->SerialNumber[j] = 0; | |
1842 | continue; | |
1843 | } | |
1844 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { | |
1845 | phba->vpd_flag |= VPD_MODEL_DESC; | |
1846 | index += 2; | |
1847 | i = vpd[index]; | |
1848 | index += 1; | |
1849 | j = 0; | |
1850 | Length -= (3+i); | |
1851 | while(i--) { | |
1852 | phba->ModelDesc[j++] = vpd[index++]; | |
1853 | if (j == 255) | |
1854 | break; | |
1855 | } | |
1856 | phba->ModelDesc[j] = 0; | |
1857 | continue; | |
1858 | } | |
1859 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { | |
1860 | phba->vpd_flag |= VPD_MODEL_NAME; | |
1861 | index += 2; | |
1862 | i = vpd[index]; | |
1863 | index += 1; | |
1864 | j = 0; | |
1865 | Length -= (3+i); | |
1866 | while(i--) { | |
1867 | phba->ModelName[j++] = vpd[index++]; | |
1868 | if (j == 79) | |
1869 | break; | |
1870 | } | |
1871 | phba->ModelName[j] = 0; | |
1872 | continue; | |
1873 | } | |
1874 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { | |
1875 | phba->vpd_flag |= VPD_PROGRAM_TYPE; | |
1876 | index += 2; | |
1877 | i = vpd[index]; | |
1878 | index += 1; | |
1879 | j = 0; | |
1880 | Length -= (3+i); | |
1881 | while(i--) { | |
1882 | phba->ProgramType[j++] = vpd[index++]; | |
1883 | if (j == 255) | |
1884 | break; | |
1885 | } | |
1886 | phba->ProgramType[j] = 0; | |
1887 | continue; | |
1888 | } | |
1889 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { | |
1890 | phba->vpd_flag |= VPD_PORT; | |
1891 | index += 2; | |
1892 | i = vpd[index]; | |
1893 | index += 1; | |
1894 | j = 0; | |
1895 | Length -= (3+i); | |
1896 | while(i--) { | |
cd1c8301 JS |
1897 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
1898 | (phba->sli4_hba.pport_name_sta == | |
1899 | LPFC_SLI4_PPNAME_GET)) { | |
1900 | j++; | |
1901 | index++; | |
1902 | } else | |
1903 | phba->Port[j++] = vpd[index++]; | |
1904 | if (j == 19) | |
1905 | break; | |
dea3101e | 1906 | } |
cd1c8301 JS |
1907 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
1908 | (phba->sli4_hba.pport_name_sta == | |
1909 | LPFC_SLI4_PPNAME_NON)) | |
1910 | phba->Port[j] = 0; | |
dea3101e JB |
1911 | continue; |
1912 | } | |
1913 | else { | |
1914 | index += 2; | |
1915 | i = vpd[index]; | |
1916 | index += 1; | |
1917 | index += i; | |
1918 | Length -= (3 + i); | |
1919 | } | |
1920 | } | |
1921 | finished = 0; | |
1922 | break; | |
1923 | case 0x78: | |
1924 | finished = 1; | |
1925 | break; | |
1926 | default: | |
1927 | index ++; | |
1928 | break; | |
1929 | } | |
74b72a59 | 1930 | } |
dea3101e JB |
1931 | |
1932 | return(1); | |
1933 | } | |
1934 | ||
e59058c4 | 1935 | /** |
3621a710 | 1936 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
e59058c4 JS |
1937 | * @phba: pointer to lpfc hba data structure. |
1938 | * @mdp: pointer to the data structure to hold the derived model name. | |
1939 | * @descp: pointer to the data structure to hold the derived description. | |
1940 | * | |
1941 | * This routine retrieves HBA's description based on its registered PCI device | |
1942 | * ID. The @descp passed into this function points to an array of 256 chars. It | |
1943 | * shall be returned with the model name, maximum speed, and the host bus type. | |
1944 | * The @mdp passed into this function points to an array of 80 chars. When the | |
1945 | * function returns, the @mdp will be filled with the model name. | |
1946 | **/ | |
dea3101e | 1947 | static void |
2e0fef85 | 1948 | lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) |
dea3101e JB |
1949 | { |
1950 | lpfc_vpd_t *vp; | |
fefcb2b6 | 1951 | uint16_t dev_id = phba->pcidev->device; |
74b72a59 | 1952 | int max_speed; |
84774a4d | 1953 | int GE = 0; |
da0436e9 | 1954 | int oneConnect = 0; /* default is not a oneConnect */ |
74b72a59 | 1955 | struct { |
a747c9ce JS |
1956 | char *name; |
1957 | char *bus; | |
1958 | char *function; | |
1959 | } m = {"<Unknown>", "", ""}; | |
74b72a59 JW |
1960 | |
1961 | if (mdp && mdp[0] != '\0' | |
1962 | && descp && descp[0] != '\0') | |
1963 | return; | |
1964 | ||
c0c11512 JS |
1965 | if (phba->lmt & LMT_16Gb) |
1966 | max_speed = 16; | |
1967 | else if (phba->lmt & LMT_10Gb) | |
74b72a59 JW |
1968 | max_speed = 10; |
1969 | else if (phba->lmt & LMT_8Gb) | |
1970 | max_speed = 8; | |
1971 | else if (phba->lmt & LMT_4Gb) | |
1972 | max_speed = 4; | |
1973 | else if (phba->lmt & LMT_2Gb) | |
1974 | max_speed = 2; | |
4169d868 | 1975 | else if (phba->lmt & LMT_1Gb) |
74b72a59 | 1976 | max_speed = 1; |
4169d868 JS |
1977 | else |
1978 | max_speed = 0; | |
dea3101e JB |
1979 | |
1980 | vp = &phba->vpd; | |
dea3101e | 1981 | |
e4adb204 | 1982 | switch (dev_id) { |
06325e74 | 1983 | case PCI_DEVICE_ID_FIREFLY: |
a747c9ce | 1984 | m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"}; |
06325e74 | 1985 | break; |
dea3101e JB |
1986 | case PCI_DEVICE_ID_SUPERFLY: |
1987 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) | |
a747c9ce JS |
1988 | m = (typeof(m)){"LP7000", "PCI", |
1989 | "Fibre Channel Adapter"}; | |
dea3101e | 1990 | else |
a747c9ce JS |
1991 | m = (typeof(m)){"LP7000E", "PCI", |
1992 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1993 | break; |
1994 | case PCI_DEVICE_ID_DRAGONFLY: | |
a747c9ce JS |
1995 | m = (typeof(m)){"LP8000", "PCI", |
1996 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1997 | break; |
1998 | case PCI_DEVICE_ID_CENTAUR: | |
1999 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) | |
a747c9ce JS |
2000 | m = (typeof(m)){"LP9002", "PCI", |
2001 | "Fibre Channel Adapter"}; | |
dea3101e | 2002 | else |
a747c9ce JS |
2003 | m = (typeof(m)){"LP9000", "PCI", |
2004 | "Fibre Channel Adapter"}; | |
dea3101e JB |
2005 | break; |
2006 | case PCI_DEVICE_ID_RFLY: | |
a747c9ce JS |
2007 | m = (typeof(m)){"LP952", "PCI", |
2008 | "Fibre Channel Adapter"}; | |
dea3101e JB |
2009 | break; |
2010 | case PCI_DEVICE_ID_PEGASUS: | |
a747c9ce JS |
2011 | m = (typeof(m)){"LP9802", "PCI-X", |
2012 | "Fibre Channel Adapter"}; | |
dea3101e JB |
2013 | break; |
2014 | case PCI_DEVICE_ID_THOR: | |
a747c9ce JS |
2015 | m = (typeof(m)){"LP10000", "PCI-X", |
2016 | "Fibre Channel Adapter"}; | |
dea3101e JB |
2017 | break; |
2018 | case PCI_DEVICE_ID_VIPER: | |
a747c9ce JS |
2019 | m = (typeof(m)){"LPX1000", "PCI-X", |
2020 | "Fibre Channel Adapter"}; | |
dea3101e JB |
2021 | break; |
2022 | case PCI_DEVICE_ID_PFLY: | |
a747c9ce JS |
2023 | m = (typeof(m)){"LP982", "PCI-X", |
2024 | "Fibre Channel Adapter"}; | |
dea3101e JB |
2025 | break; |
2026 | case PCI_DEVICE_ID_TFLY: | |
a747c9ce JS |
2027 | m = (typeof(m)){"LP1050", "PCI-X", |
2028 | "Fibre Channel Adapter"}; | |
dea3101e JB |
2029 | break; |
2030 | case PCI_DEVICE_ID_HELIOS: | |
a747c9ce JS |
2031 | m = (typeof(m)){"LP11000", "PCI-X2", |
2032 | "Fibre Channel Adapter"}; | |
dea3101e | 2033 | break; |
e4adb204 | 2034 | case PCI_DEVICE_ID_HELIOS_SCSP: |
a747c9ce JS |
2035 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
2036 | "Fibre Channel Adapter"}; | |
e4adb204 JSEC |
2037 | break; |
2038 | case PCI_DEVICE_ID_HELIOS_DCSP: | |
a747c9ce JS |
2039 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
2040 | "Fibre Channel Adapter"}; | |
e4adb204 JSEC |
2041 | break; |
2042 | case PCI_DEVICE_ID_NEPTUNE: | |
a747c9ce | 2043 | m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
2044 | break; |
2045 | case PCI_DEVICE_ID_NEPTUNE_SCSP: | |
a747c9ce | 2046 | m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
2047 | break; |
2048 | case PCI_DEVICE_ID_NEPTUNE_DCSP: | |
a747c9ce | 2049 | m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 | 2050 | break; |
dea3101e | 2051 | case PCI_DEVICE_ID_BMID: |
a747c9ce | 2052 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
dea3101e JB |
2053 | break; |
2054 | case PCI_DEVICE_ID_BSMB: | |
a747c9ce | 2055 | m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"}; |
dea3101e JB |
2056 | break; |
2057 | case PCI_DEVICE_ID_ZEPHYR: | |
a747c9ce | 2058 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
dea3101e | 2059 | break; |
e4adb204 | 2060 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
a747c9ce | 2061 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
2062 | break; |
2063 | case PCI_DEVICE_ID_ZEPHYR_DCSP: | |
a747c9ce | 2064 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
a257bf90 | 2065 | GE = 1; |
e4adb204 | 2066 | break; |
dea3101e | 2067 | case PCI_DEVICE_ID_ZMID: |
a747c9ce | 2068 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
dea3101e JB |
2069 | break; |
2070 | case PCI_DEVICE_ID_ZSMB: | |
a747c9ce | 2071 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
dea3101e JB |
2072 | break; |
2073 | case PCI_DEVICE_ID_LP101: | |
a747c9ce | 2074 | m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"}; |
dea3101e JB |
2075 | break; |
2076 | case PCI_DEVICE_ID_LP10000S: | |
a747c9ce | 2077 | m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"}; |
06325e74 | 2078 | break; |
e4adb204 | 2079 | case PCI_DEVICE_ID_LP11000S: |
a747c9ce | 2080 | m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"}; |
18a3b596 | 2081 | break; |
e4adb204 | 2082 | case PCI_DEVICE_ID_LPE11000S: |
a747c9ce | 2083 | m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"}; |
5cc36b3c | 2084 | break; |
b87eab38 | 2085 | case PCI_DEVICE_ID_SAT: |
a747c9ce | 2086 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
2087 | break; |
2088 | case PCI_DEVICE_ID_SAT_MID: | |
a747c9ce | 2089 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
2090 | break; |
2091 | case PCI_DEVICE_ID_SAT_SMB: | |
a747c9ce | 2092 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
2093 | break; |
2094 | case PCI_DEVICE_ID_SAT_DCSP: | |
a747c9ce | 2095 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
2096 | break; |
2097 | case PCI_DEVICE_ID_SAT_SCSP: | |
a747c9ce | 2098 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
2099 | break; |
2100 | case PCI_DEVICE_ID_SAT_S: | |
a747c9ce | 2101 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 | 2102 | break; |
84774a4d | 2103 | case PCI_DEVICE_ID_HORNET: |
a747c9ce | 2104 | m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"}; |
84774a4d JS |
2105 | GE = 1; |
2106 | break; | |
2107 | case PCI_DEVICE_ID_PROTEUS_VF: | |
a747c9ce JS |
2108 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
2109 | "Fibre Channel Adapter"}; | |
84774a4d JS |
2110 | break; |
2111 | case PCI_DEVICE_ID_PROTEUS_PF: | |
a747c9ce JS |
2112 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
2113 | "Fibre Channel Adapter"}; | |
84774a4d JS |
2114 | break; |
2115 | case PCI_DEVICE_ID_PROTEUS_S: | |
a747c9ce JS |
2116 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
2117 | "Fibre Channel Adapter"}; | |
84774a4d | 2118 | break; |
da0436e9 JS |
2119 | case PCI_DEVICE_ID_TIGERSHARK: |
2120 | oneConnect = 1; | |
a747c9ce | 2121 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
da0436e9 | 2122 | break; |
a747c9ce | 2123 | case PCI_DEVICE_ID_TOMCAT: |
6669f9bb | 2124 | oneConnect = 1; |
a747c9ce JS |
2125 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
2126 | break; | |
2127 | case PCI_DEVICE_ID_FALCON: | |
2128 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", | |
2129 | "EmulexSecure Fibre"}; | |
6669f9bb | 2130 | break; |
98fc5dd9 JS |
2131 | case PCI_DEVICE_ID_BALIUS: |
2132 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", | |
2133 | "Fibre Channel Adapter"}; | |
2134 | break; | |
085c647c | 2135 | case PCI_DEVICE_ID_LANCER_FC: |
c0c11512 JS |
2136 | case PCI_DEVICE_ID_LANCER_FC_VF: |
2137 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; | |
085c647c JS |
2138 | break; |
2139 | case PCI_DEVICE_ID_LANCER_FCOE: | |
c0c11512 | 2140 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
085c647c | 2141 | oneConnect = 1; |
079b5c91 | 2142 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
085c647c | 2143 | break; |
f8cafd38 JS |
2144 | case PCI_DEVICE_ID_SKYHAWK: |
2145 | case PCI_DEVICE_ID_SKYHAWK_VF: | |
2146 | oneConnect = 1; | |
2147 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; | |
2148 | break; | |
5cc36b3c | 2149 | default: |
a747c9ce | 2150 | m = (typeof(m)){"Unknown", "", ""}; |
e4adb204 | 2151 | break; |
dea3101e | 2152 | } |
74b72a59 JW |
2153 | |
2154 | if (mdp && mdp[0] == '\0') | |
2155 | snprintf(mdp, 79,"%s", m.name); | |
c0c11512 JS |
2156 | /* |
2157 | * oneConnect hba requires special processing, they are all initiators | |
da0436e9 JS |
2158 | * and we put the port number on the end |
2159 | */ | |
2160 | if (descp && descp[0] == '\0') { | |
2161 | if (oneConnect) | |
2162 | snprintf(descp, 255, | |
4169d868 | 2163 | "Emulex OneConnect %s, %s Initiator %s", |
a747c9ce | 2164 | m.name, m.function, |
da0436e9 | 2165 | phba->Port); |
4169d868 JS |
2166 | else if (max_speed == 0) |
2167 | snprintf(descp, 255, | |
2168 | "Emulex %s %s %s ", | |
2169 | m.name, m.bus, m.function); | |
da0436e9 JS |
2170 | else |
2171 | snprintf(descp, 255, | |
2172 | "Emulex %s %d%s %s %s", | |
a747c9ce JS |
2173 | m.name, max_speed, (GE) ? "GE" : "Gb", |
2174 | m.bus, m.function); | |
da0436e9 | 2175 | } |
dea3101e JB |
2176 | } |
2177 | ||
e59058c4 | 2178 | /** |
3621a710 | 2179 | * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring |
e59058c4 JS |
2180 | * @phba: pointer to lpfc hba data structure. |
2181 | * @pring: pointer to a IOCB ring. | |
2182 | * @cnt: the number of IOCBs to be posted to the IOCB ring. | |
2183 | * | |
2184 | * This routine posts a given number of IOCBs with the associated DMA buffer | |
2185 | * descriptors specified by the cnt argument to the given IOCB ring. | |
2186 | * | |
2187 | * Return codes | |
2188 | * The number of IOCBs NOT able to be posted to the IOCB ring. | |
2189 | **/ | |
dea3101e | 2190 | int |
495a714c | 2191 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
dea3101e JB |
2192 | { |
2193 | IOCB_t *icmd; | |
0bd4ca25 | 2194 | struct lpfc_iocbq *iocb; |
dea3101e JB |
2195 | struct lpfc_dmabuf *mp1, *mp2; |
2196 | ||
2197 | cnt += pring->missbufcnt; | |
2198 | ||
2199 | /* While there are buffers to post */ | |
2200 | while (cnt > 0) { | |
2201 | /* Allocate buffer for command iocb */ | |
0bd4ca25 | 2202 | iocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
2203 | if (iocb == NULL) { |
2204 | pring->missbufcnt = cnt; | |
2205 | return cnt; | |
2206 | } | |
dea3101e JB |
2207 | icmd = &iocb->iocb; |
2208 | ||
2209 | /* 2 buffers can be posted per command */ | |
2210 | /* Allocate buffer to post */ | |
2211 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
2212 | if (mp1) | |
98c9ea5c JS |
2213 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
2214 | if (!mp1 || !mp1->virt) { | |
c9475cb0 | 2215 | kfree(mp1); |
604a3e30 | 2216 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
2217 | pring->missbufcnt = cnt; |
2218 | return cnt; | |
2219 | } | |
2220 | ||
2221 | INIT_LIST_HEAD(&mp1->list); | |
2222 | /* Allocate buffer to post */ | |
2223 | if (cnt > 1) { | |
2224 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
2225 | if (mp2) | |
2226 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | |
2227 | &mp2->phys); | |
98c9ea5c | 2228 | if (!mp2 || !mp2->virt) { |
c9475cb0 | 2229 | kfree(mp2); |
dea3101e JB |
2230 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
2231 | kfree(mp1); | |
604a3e30 | 2232 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
2233 | pring->missbufcnt = cnt; |
2234 | return cnt; | |
2235 | } | |
2236 | ||
2237 | INIT_LIST_HEAD(&mp2->list); | |
2238 | } else { | |
2239 | mp2 = NULL; | |
2240 | } | |
2241 | ||
2242 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); | |
2243 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); | |
2244 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; | |
2245 | icmd->ulpBdeCount = 1; | |
2246 | cnt--; | |
2247 | if (mp2) { | |
2248 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); | |
2249 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); | |
2250 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; | |
2251 | cnt--; | |
2252 | icmd->ulpBdeCount = 2; | |
2253 | } | |
2254 | ||
2255 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; | |
2256 | icmd->ulpLe = 1; | |
2257 | ||
3772a991 JS |
2258 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
2259 | IOCB_ERROR) { | |
dea3101e JB |
2260 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
2261 | kfree(mp1); | |
2262 | cnt++; | |
2263 | if (mp2) { | |
2264 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); | |
2265 | kfree(mp2); | |
2266 | cnt++; | |
2267 | } | |
604a3e30 | 2268 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e | 2269 | pring->missbufcnt = cnt; |
dea3101e JB |
2270 | return cnt; |
2271 | } | |
dea3101e | 2272 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
92d7f7b0 | 2273 | if (mp2) |
dea3101e | 2274 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
dea3101e JB |
2275 | } |
2276 | pring->missbufcnt = 0; | |
2277 | return 0; | |
2278 | } | |
2279 | ||
e59058c4 | 2280 | /** |
3621a710 | 2281 | * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring |
e59058c4 JS |
2282 | * @phba: pointer to lpfc hba data structure. |
2283 | * | |
2284 | * This routine posts initial receive IOCB buffers to the ELS ring. The | |
2285 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is | |
2286 | * set to 64 IOCBs. | |
2287 | * | |
2288 | * Return codes | |
2289 | * 0 - success (currently always success) | |
2290 | **/ | |
dea3101e | 2291 | static int |
2e0fef85 | 2292 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
dea3101e JB |
2293 | { |
2294 | struct lpfc_sli *psli = &phba->sli; | |
2295 | ||
2296 | /* Ring 0, ELS / CT buffers */ | |
495a714c | 2297 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
dea3101e JB |
2298 | /* Ring 2 - FCP no buffers needed */ |
2299 | ||
2300 | return 0; | |
2301 | } | |
2302 | ||
2303 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) | |
2304 | ||
e59058c4 | 2305 | /** |
3621a710 | 2306 | * lpfc_sha_init - Set up initial array of hash table entries |
e59058c4 JS |
2307 | * @HashResultPointer: pointer to an array as hash table. |
2308 | * | |
2309 | * This routine sets up the initial values to the array of hash table entries | |
2310 | * for the LC HBAs. | |
2311 | **/ | |
dea3101e JB |
2312 | static void |
2313 | lpfc_sha_init(uint32_t * HashResultPointer) | |
2314 | { | |
2315 | HashResultPointer[0] = 0x67452301; | |
2316 | HashResultPointer[1] = 0xEFCDAB89; | |
2317 | HashResultPointer[2] = 0x98BADCFE; | |
2318 | HashResultPointer[3] = 0x10325476; | |
2319 | HashResultPointer[4] = 0xC3D2E1F0; | |
2320 | } | |
2321 | ||
e59058c4 | 2322 | /** |
3621a710 | 2323 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
e59058c4 JS |
2324 | * @HashResultPointer: pointer to an initial/result hash table. |
2325 | * @HashWorkingPointer: pointer to an working hash table. | |
2326 | * | |
2327 | * This routine iterates an initial hash table pointed by @HashResultPointer | |
2328 | * with the values from the working hash table pointeed by @HashWorkingPointer. | |
2329 | * The results are putting back to the initial hash table, returned through | |
2330 | * the @HashResultPointer as the result hash table. | |
2331 | **/ | |
dea3101e JB |
2332 | static void |
2333 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) | |
2334 | { | |
2335 | int t; | |
2336 | uint32_t TEMP; | |
2337 | uint32_t A, B, C, D, E; | |
2338 | t = 16; | |
2339 | do { | |
2340 | HashWorkingPointer[t] = | |
2341 | S(1, | |
2342 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - | |
2343 | 8] ^ | |
2344 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); | |
2345 | } while (++t <= 79); | |
2346 | t = 0; | |
2347 | A = HashResultPointer[0]; | |
2348 | B = HashResultPointer[1]; | |
2349 | C = HashResultPointer[2]; | |
2350 | D = HashResultPointer[3]; | |
2351 | E = HashResultPointer[4]; | |
2352 | ||
2353 | do { | |
2354 | if (t < 20) { | |
2355 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; | |
2356 | } else if (t < 40) { | |
2357 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; | |
2358 | } else if (t < 60) { | |
2359 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; | |
2360 | } else { | |
2361 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; | |
2362 | } | |
2363 | TEMP += S(5, A) + E + HashWorkingPointer[t]; | |
2364 | E = D; | |
2365 | D = C; | |
2366 | C = S(30, B); | |
2367 | B = A; | |
2368 | A = TEMP; | |
2369 | } while (++t <= 79); | |
2370 | ||
2371 | HashResultPointer[0] += A; | |
2372 | HashResultPointer[1] += B; | |
2373 | HashResultPointer[2] += C; | |
2374 | HashResultPointer[3] += D; | |
2375 | HashResultPointer[4] += E; | |
2376 | ||
2377 | } | |
2378 | ||
e59058c4 | 2379 | /** |
3621a710 | 2380 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
e59058c4 JS |
2381 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
2382 | * @HashWorking: pointer to the entry of the working hash array. | |
2383 | * | |
2384 | * This routine calculates the working hash array referred by @HashWorking | |
2385 | * from the challenge random numbers associated with the host, referred by | |
2386 | * @RandomChallenge. The result is put into the entry of the working hash | |
2387 | * array and returned by reference through @HashWorking. | |
2388 | **/ | |
dea3101e JB |
2389 | static void |
2390 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) | |
2391 | { | |
2392 | *HashWorking = (*RandomChallenge ^ *HashWorking); | |
2393 | } | |
2394 | ||
e59058c4 | 2395 | /** |
3621a710 | 2396 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
e59058c4 JS |
2397 | * @phba: pointer to lpfc hba data structure. |
2398 | * @hbainit: pointer to an array of unsigned 32-bit integers. | |
2399 | * | |
2400 | * This routine performs the special handling for LC HBA initialization. | |
2401 | **/ | |
dea3101e JB |
2402 | void |
2403 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) | |
2404 | { | |
2405 | int t; | |
2406 | uint32_t *HashWorking; | |
2e0fef85 | 2407 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
dea3101e | 2408 | |
bbfbbbc1 | 2409 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
dea3101e JB |
2410 | if (!HashWorking) |
2411 | return; | |
2412 | ||
dea3101e JB |
2413 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
2414 | HashWorking[1] = HashWorking[79] = *pwwnn; | |
2415 | ||
2416 | for (t = 0; t < 7; t++) | |
2417 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); | |
2418 | ||
2419 | lpfc_sha_init(hbainit); | |
2420 | lpfc_sha_iterate(hbainit, HashWorking); | |
2421 | kfree(HashWorking); | |
2422 | } | |
2423 | ||
e59058c4 | 2424 | /** |
3621a710 | 2425 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
e59058c4 JS |
2426 | * @vport: pointer to a virtual N_Port data structure. |
2427 | * | |
2428 | * This routine performs the necessary cleanups before deleting the @vport. | |
2429 | * It invokes the discovery state machine to perform necessary state | |
2430 | * transitions and to release the ndlps associated with the @vport. Note, | |
2431 | * the physical port is treated as @vport 0. | |
2432 | **/ | |
87af33fe | 2433 | void |
2e0fef85 | 2434 | lpfc_cleanup(struct lpfc_vport *vport) |
dea3101e | 2435 | { |
87af33fe | 2436 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2437 | struct lpfc_nodelist *ndlp, *next_ndlp; |
a8adb832 | 2438 | int i = 0; |
dea3101e | 2439 | |
87af33fe JS |
2440 | if (phba->link_state > LPFC_LINK_DOWN) |
2441 | lpfc_port_link_failure(vport); | |
2442 | ||
2443 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
2444 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
2445 | ndlp = lpfc_enable_node(vport, ndlp, | |
2446 | NLP_STE_UNUSED_NODE); | |
2447 | if (!ndlp) | |
2448 | continue; | |
2449 | spin_lock_irq(&phba->ndlp_lock); | |
2450 | NLP_SET_FREE_REQ(ndlp); | |
2451 | spin_unlock_irq(&phba->ndlp_lock); | |
2452 | /* Trigger the release of the ndlp memory */ | |
2453 | lpfc_nlp_put(ndlp); | |
2454 | continue; | |
2455 | } | |
2456 | spin_lock_irq(&phba->ndlp_lock); | |
2457 | if (NLP_CHK_FREE_REQ(ndlp)) { | |
2458 | /* The ndlp should not be in memory free mode already */ | |
2459 | spin_unlock_irq(&phba->ndlp_lock); | |
2460 | continue; | |
2461 | } else | |
2462 | /* Indicate request for freeing ndlp memory */ | |
2463 | NLP_SET_FREE_REQ(ndlp); | |
2464 | spin_unlock_irq(&phba->ndlp_lock); | |
2465 | ||
58da1ffb JS |
2466 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
2467 | ndlp->nlp_DID == Fabric_DID) { | |
2468 | /* Just free up ndlp with Fabric_DID for vports */ | |
2469 | lpfc_nlp_put(ndlp); | |
2470 | continue; | |
2471 | } | |
2472 | ||
eff4a01b JS |
2473 | /* take care of nodes in unused state before the state |
2474 | * machine taking action. | |
2475 | */ | |
2476 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { | |
2477 | lpfc_nlp_put(ndlp); | |
2478 | continue; | |
2479 | } | |
2480 | ||
87af33fe JS |
2481 | if (ndlp->nlp_type & NLP_FABRIC) |
2482 | lpfc_disc_state_machine(vport, ndlp, NULL, | |
2483 | NLP_EVT_DEVICE_RECOVERY); | |
e47c9093 | 2484 | |
87af33fe JS |
2485 | lpfc_disc_state_machine(vport, ndlp, NULL, |
2486 | NLP_EVT_DEVICE_RM); | |
2487 | } | |
2488 | ||
a8adb832 JS |
2489 | /* At this point, ALL ndlp's should be gone |
2490 | * because of the previous NLP_EVT_DEVICE_RM. | |
2491 | * Lets wait for this to happen, if needed. | |
2492 | */ | |
87af33fe | 2493 | while (!list_empty(&vport->fc_nodes)) { |
a8adb832 | 2494 | if (i++ > 3000) { |
87af33fe | 2495 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
a8adb832 | 2496 | "0233 Nodelist not empty\n"); |
e47c9093 JS |
2497 | list_for_each_entry_safe(ndlp, next_ndlp, |
2498 | &vport->fc_nodes, nlp_listp) { | |
2499 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, | |
2500 | LOG_NODE, | |
d7c255b2 | 2501 | "0282 did:x%x ndlp:x%p " |
e47c9093 JS |
2502 | "usgmap:x%x refcnt:%d\n", |
2503 | ndlp->nlp_DID, (void *)ndlp, | |
2504 | ndlp->nlp_usg_map, | |
2505 | atomic_read( | |
2506 | &ndlp->kref.refcount)); | |
2507 | } | |
a8adb832 | 2508 | break; |
87af33fe | 2509 | } |
a8adb832 JS |
2510 | |
2511 | /* Wait for any activity on ndlps to settle */ | |
2512 | msleep(10); | |
87af33fe | 2513 | } |
1151e3ec | 2514 | lpfc_cleanup_vports_rrqs(vport, NULL); |
dea3101e JB |
2515 | } |
2516 | ||
e59058c4 | 2517 | /** |
3621a710 | 2518 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
e59058c4 JS |
2519 | * @vport: pointer to a virtual N_Port data structure. |
2520 | * | |
2521 | * This routine stops all the timers associated with a @vport. This function | |
2522 | * is invoked before disabling or deleting a @vport. Note that the physical | |
2523 | * port is treated as @vport 0. | |
2524 | **/ | |
92d7f7b0 JS |
2525 | void |
2526 | lpfc_stop_vport_timers(struct lpfc_vport *vport) | |
dea3101e | 2527 | { |
92d7f7b0 JS |
2528 | del_timer_sync(&vport->els_tmofunc); |
2529 | del_timer_sync(&vport->fc_fdmitmo); | |
92494144 | 2530 | del_timer_sync(&vport->delayed_disc_tmo); |
92d7f7b0 JS |
2531 | lpfc_can_disctmo(vport); |
2532 | return; | |
dea3101e JB |
2533 | } |
2534 | ||
ecfd03c6 JS |
2535 | /** |
2536 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2537 | * @phba: pointer to lpfc hba data structure. | |
2538 | * | |
2539 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The | |
2540 | * caller of this routine should already hold the host lock. | |
2541 | **/ | |
2542 | void | |
2543 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2544 | { | |
5ac6b303 JS |
2545 | /* Clear pending FCF rediscovery wait flag */ |
2546 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; | |
2547 | ||
ecfd03c6 JS |
2548 | /* Now, try to stop the timer */ |
2549 | del_timer(&phba->fcf.redisc_wait); | |
2550 | } | |
2551 | ||
2552 | /** | |
2553 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2554 | * @phba: pointer to lpfc hba data structure. | |
2555 | * | |
2556 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It | |
2557 | * checks whether the FCF rediscovery wait timer is pending with the host | |
2558 | * lock held before proceeding with disabling the timer and clearing the | |
2559 | * wait timer pendig flag. | |
2560 | **/ | |
2561 | void | |
2562 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2563 | { | |
2564 | spin_lock_irq(&phba->hbalock); | |
2565 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
2566 | /* FCF rediscovery timer already fired or stopped */ | |
2567 | spin_unlock_irq(&phba->hbalock); | |
2568 | return; | |
2569 | } | |
2570 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); | |
5ac6b303 JS |
2571 | /* Clear failover in progress flags */ |
2572 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); | |
ecfd03c6 JS |
2573 | spin_unlock_irq(&phba->hbalock); |
2574 | } | |
2575 | ||
e59058c4 | 2576 | /** |
3772a991 | 2577 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
e59058c4 JS |
2578 | * @phba: pointer to lpfc hba data structure. |
2579 | * | |
2580 | * This routine stops all the timers associated with a HBA. This function is | |
2581 | * invoked before either putting a HBA offline or unloading the driver. | |
2582 | **/ | |
3772a991 JS |
2583 | void |
2584 | lpfc_stop_hba_timers(struct lpfc_hba *phba) | |
dea3101e | 2585 | { |
51ef4c26 | 2586 | lpfc_stop_vport_timers(phba->pport); |
2e0fef85 | 2587 | del_timer_sync(&phba->sli.mbox_tmo); |
92d7f7b0 | 2588 | del_timer_sync(&phba->fabric_block_timer); |
9399627f | 2589 | del_timer_sync(&phba->eratt_poll); |
3772a991 | 2590 | del_timer_sync(&phba->hb_tmofunc); |
1151e3ec JS |
2591 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2592 | del_timer_sync(&phba->rrq_tmr); | |
2593 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
2594 | } | |
3772a991 JS |
2595 | phba->hb_outstanding = 0; |
2596 | ||
2597 | switch (phba->pci_dev_grp) { | |
2598 | case LPFC_PCI_DEV_LP: | |
2599 | /* Stop any LightPulse device specific driver timers */ | |
2600 | del_timer_sync(&phba->fcp_poll_timer); | |
2601 | break; | |
2602 | case LPFC_PCI_DEV_OC: | |
2603 | /* Stop any OneConnect device sepcific driver timers */ | |
ecfd03c6 | 2604 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
3772a991 JS |
2605 | break; |
2606 | default: | |
2607 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2608 | "0297 Invalid device group (x%x)\n", | |
2609 | phba->pci_dev_grp); | |
2610 | break; | |
2611 | } | |
2e0fef85 | 2612 | return; |
dea3101e JB |
2613 | } |
2614 | ||
e59058c4 | 2615 | /** |
3621a710 | 2616 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
e59058c4 JS |
2617 | * @phba: pointer to lpfc hba data structure. |
2618 | * | |
2619 | * This routine marks a HBA's management interface as blocked. Once the HBA's | |
2620 | * management interface is marked as blocked, all the user space access to | |
2621 | * the HBA, whether they are from sysfs interface or libdfc interface will | |
2622 | * all be blocked. The HBA is set to block the management interface when the | |
2623 | * driver prepares the HBA interface for online or offline. | |
2624 | **/ | |
a6ababd2 | 2625 | static void |
618a5230 | 2626 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
a6ababd2 AB |
2627 | { |
2628 | unsigned long iflag; | |
6e7288d9 JS |
2629 | uint8_t actcmd = MBX_HEARTBEAT; |
2630 | unsigned long timeout; | |
2631 | ||
a6ababd2 AB |
2632 | spin_lock_irqsave(&phba->hbalock, iflag); |
2633 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; | |
618a5230 JS |
2634 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2635 | if (mbx_action == LPFC_MBX_NO_WAIT) | |
2636 | return; | |
2637 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; | |
2638 | spin_lock_irqsave(&phba->hbalock, iflag); | |
a183a15f | 2639 | if (phba->sli.mbox_active) { |
6e7288d9 | 2640 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
a183a15f JS |
2641 | /* Determine how long we might wait for the active mailbox |
2642 | * command to be gracefully completed by firmware. | |
2643 | */ | |
2644 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
2645 | phba->sli.mbox_active) * 1000) + jiffies; | |
2646 | } | |
a6ababd2 | 2647 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a183a15f | 2648 | |
6e7288d9 JS |
2649 | /* Wait for the outstnading mailbox command to complete */ |
2650 | while (phba->sli.mbox_active) { | |
2651 | /* Check active mailbox complete status every 2ms */ | |
2652 | msleep(2); | |
2653 | if (time_after(jiffies, timeout)) { | |
2654 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2655 | "2813 Mgmt IO is Blocked %x " | |
2656 | "- mbox cmd %x still active\n", | |
2657 | phba->sli.sli_flag, actcmd); | |
2658 | break; | |
2659 | } | |
2660 | } | |
a6ababd2 AB |
2661 | } |
2662 | ||
6b5151fd JS |
2663 | /** |
2664 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. | |
2665 | * @phba: pointer to lpfc hba data structure. | |
2666 | * | |
2667 | * Allocate RPIs for all active remote nodes. This is needed whenever | |
2668 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose | |
2669 | * is to fixup the temporary rpi assignments. | |
2670 | **/ | |
2671 | void | |
2672 | lpfc_sli4_node_prep(struct lpfc_hba *phba) | |
2673 | { | |
2674 | struct lpfc_nodelist *ndlp, *next_ndlp; | |
2675 | struct lpfc_vport **vports; | |
2676 | int i; | |
2677 | ||
2678 | if (phba->sli_rev != LPFC_SLI_REV4) | |
2679 | return; | |
2680 | ||
2681 | vports = lpfc_create_vport_work_array(phba); | |
2682 | if (vports != NULL) { | |
2683 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { | |
2684 | if (vports[i]->load_flag & FC_UNLOADING) | |
2685 | continue; | |
2686 | ||
2687 | list_for_each_entry_safe(ndlp, next_ndlp, | |
2688 | &vports[i]->fc_nodes, | |
2689 | nlp_listp) { | |
2690 | if (NLP_CHK_NODE_ACT(ndlp)) | |
2691 | ndlp->nlp_rpi = | |
2692 | lpfc_sli4_alloc_rpi(phba); | |
2693 | } | |
2694 | } | |
2695 | } | |
2696 | lpfc_destroy_vport_work_array(phba, vports); | |
2697 | } | |
2698 | ||
e59058c4 | 2699 | /** |
3621a710 | 2700 | * lpfc_online - Initialize and bring a HBA online |
e59058c4 JS |
2701 | * @phba: pointer to lpfc hba data structure. |
2702 | * | |
2703 | * This routine initializes the HBA and brings a HBA online. During this | |
2704 | * process, the management interface is blocked to prevent user space access | |
2705 | * to the HBA interfering with the driver initialization. | |
2706 | * | |
2707 | * Return codes | |
2708 | * 0 - successful | |
2709 | * 1 - failed | |
2710 | **/ | |
dea3101e | 2711 | int |
2e0fef85 | 2712 | lpfc_online(struct lpfc_hba *phba) |
dea3101e | 2713 | { |
372bd282 | 2714 | struct lpfc_vport *vport; |
549e55cd JS |
2715 | struct lpfc_vport **vports; |
2716 | int i; | |
16a3a208 | 2717 | bool vpis_cleared = false; |
2e0fef85 | 2718 | |
dea3101e JB |
2719 | if (!phba) |
2720 | return 0; | |
372bd282 | 2721 | vport = phba->pport; |
dea3101e | 2722 | |
2e0fef85 | 2723 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
dea3101e JB |
2724 | return 0; |
2725 | ||
ed957684 | 2726 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 2727 | "0458 Bring Adapter online\n"); |
dea3101e | 2728 | |
618a5230 | 2729 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
46fa311e JS |
2730 | |
2731 | if (!lpfc_sli_queue_setup(phba)) { | |
2732 | lpfc_unblock_mgmt_io(phba); | |
dea3101e | 2733 | return 1; |
46fa311e | 2734 | } |
dea3101e | 2735 | |
da0436e9 JS |
2736 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2737 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ | |
2738 | lpfc_unblock_mgmt_io(phba); | |
2739 | return 1; | |
2740 | } | |
16a3a208 JS |
2741 | spin_lock_irq(&phba->hbalock); |
2742 | if (!phba->sli4_hba.max_cfg_param.vpi_used) | |
2743 | vpis_cleared = true; | |
2744 | spin_unlock_irq(&phba->hbalock); | |
da0436e9 JS |
2745 | } else { |
2746 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ | |
2747 | lpfc_unblock_mgmt_io(phba); | |
2748 | return 1; | |
2749 | } | |
46fa311e | 2750 | } |
dea3101e | 2751 | |
549e55cd JS |
2752 | vports = lpfc_create_vport_work_array(phba); |
2753 | if (vports != NULL) | |
da0436e9 | 2754 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd JS |
2755 | struct Scsi_Host *shost; |
2756 | shost = lpfc_shost_from_vport(vports[i]); | |
2757 | spin_lock_irq(shost->host_lock); | |
2758 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; | |
2759 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) | |
2760 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
16a3a208 | 2761 | if (phba->sli_rev == LPFC_SLI_REV4) { |
1c6834a7 | 2762 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; |
16a3a208 JS |
2763 | if ((vpis_cleared) && |
2764 | (vports[i]->port_type != | |
2765 | LPFC_PHYSICAL_PORT)) | |
2766 | vports[i]->vpi = 0; | |
2767 | } | |
549e55cd JS |
2768 | spin_unlock_irq(shost->host_lock); |
2769 | } | |
09372820 | 2770 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2771 | |
46fa311e | 2772 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
2773 | return 0; |
2774 | } | |
2775 | ||
e59058c4 | 2776 | /** |
3621a710 | 2777 | * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked |
e59058c4 JS |
2778 | * @phba: pointer to lpfc hba data structure. |
2779 | * | |
2780 | * This routine marks a HBA's management interface as not blocked. Once the | |
2781 | * HBA's management interface is marked as not blocked, all the user space | |
2782 | * access to the HBA, whether they are from sysfs interface or libdfc | |
2783 | * interface will be allowed. The HBA is set to block the management interface | |
2784 | * when the driver prepares the HBA interface for online or offline and then | |
2785 | * set to unblock the management interface afterwards. | |
2786 | **/ | |
46fa311e JS |
2787 | void |
2788 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) | |
2789 | { | |
2790 | unsigned long iflag; | |
2791 | ||
2e0fef85 JS |
2792 | spin_lock_irqsave(&phba->hbalock, iflag); |
2793 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; | |
2794 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
46fa311e JS |
2795 | } |
2796 | ||
e59058c4 | 2797 | /** |
3621a710 | 2798 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
e59058c4 JS |
2799 | * @phba: pointer to lpfc hba data structure. |
2800 | * | |
2801 | * This routine is invoked to prepare a HBA to be brought offline. It performs | |
2802 | * unregistration login to all the nodes on all vports and flushes the mailbox | |
2803 | * queue to make it ready to be brought offline. | |
2804 | **/ | |
46fa311e | 2805 | void |
618a5230 | 2806 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
46fa311e | 2807 | { |
2e0fef85 | 2808 | struct lpfc_vport *vport = phba->pport; |
46fa311e | 2809 | struct lpfc_nodelist *ndlp, *next_ndlp; |
87af33fe | 2810 | struct lpfc_vport **vports; |
72100cc4 | 2811 | struct Scsi_Host *shost; |
87af33fe | 2812 | int i; |
dea3101e | 2813 | |
2e0fef85 | 2814 | if (vport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 2815 | return; |
dea3101e | 2816 | |
618a5230 | 2817 | lpfc_block_mgmt_io(phba, mbx_action); |
dea3101e JB |
2818 | |
2819 | lpfc_linkdown(phba); | |
2820 | ||
87af33fe JS |
2821 | /* Issue an unreg_login to all nodes on all vports */ |
2822 | vports = lpfc_create_vport_work_array(phba); | |
2823 | if (vports != NULL) { | |
da0436e9 | 2824 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
a8adb832 JS |
2825 | if (vports[i]->load_flag & FC_UNLOADING) |
2826 | continue; | |
72100cc4 JS |
2827 | shost = lpfc_shost_from_vport(vports[i]); |
2828 | spin_lock_irq(shost->host_lock); | |
c868595d | 2829 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
695a814e JS |
2830 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
2831 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; | |
72100cc4 | 2832 | spin_unlock_irq(shost->host_lock); |
695a814e | 2833 | |
87af33fe JS |
2834 | shost = lpfc_shost_from_vport(vports[i]); |
2835 | list_for_each_entry_safe(ndlp, next_ndlp, | |
2836 | &vports[i]->fc_nodes, | |
2837 | nlp_listp) { | |
e47c9093 JS |
2838 | if (!NLP_CHK_NODE_ACT(ndlp)) |
2839 | continue; | |
87af33fe JS |
2840 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
2841 | continue; | |
2842 | if (ndlp->nlp_type & NLP_FABRIC) { | |
2843 | lpfc_disc_state_machine(vports[i], ndlp, | |
2844 | NULL, NLP_EVT_DEVICE_RECOVERY); | |
2845 | lpfc_disc_state_machine(vports[i], ndlp, | |
2846 | NULL, NLP_EVT_DEVICE_RM); | |
2847 | } | |
2848 | spin_lock_irq(shost->host_lock); | |
2849 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | |
401ee0c1 | 2850 | spin_unlock_irq(shost->host_lock); |
6b5151fd JS |
2851 | /* |
2852 | * Whenever an SLI4 port goes offline, free the | |
401ee0c1 JS |
2853 | * RPI. Get a new RPI when the adapter port |
2854 | * comes back online. | |
6b5151fd JS |
2855 | */ |
2856 | if (phba->sli_rev == LPFC_SLI_REV4) | |
2857 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); | |
87af33fe JS |
2858 | lpfc_unreg_rpi(vports[i], ndlp); |
2859 | } | |
2860 | } | |
2861 | } | |
09372820 | 2862 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2863 | |
618a5230 | 2864 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
46fa311e JS |
2865 | } |
2866 | ||
e59058c4 | 2867 | /** |
3621a710 | 2868 | * lpfc_offline - Bring a HBA offline |
e59058c4 JS |
2869 | * @phba: pointer to lpfc hba data structure. |
2870 | * | |
2871 | * This routine actually brings a HBA offline. It stops all the timers | |
2872 | * associated with the HBA, brings down the SLI layer, and eventually | |
2873 | * marks the HBA as in offline state for the upper layer protocol. | |
2874 | **/ | |
46fa311e | 2875 | void |
2e0fef85 | 2876 | lpfc_offline(struct lpfc_hba *phba) |
46fa311e | 2877 | { |
549e55cd JS |
2878 | struct Scsi_Host *shost; |
2879 | struct lpfc_vport **vports; | |
2880 | int i; | |
46fa311e | 2881 | |
549e55cd | 2882 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 2883 | return; |
688a8863 | 2884 | |
da0436e9 JS |
2885 | /* stop port and all timers associated with this hba */ |
2886 | lpfc_stop_port(phba); | |
51ef4c26 JS |
2887 | vports = lpfc_create_vport_work_array(phba); |
2888 | if (vports != NULL) | |
da0436e9 | 2889 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
51ef4c26 | 2890 | lpfc_stop_vport_timers(vports[i]); |
09372820 | 2891 | lpfc_destroy_vport_work_array(phba, vports); |
92d7f7b0 | 2892 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 2893 | "0460 Bring Adapter offline\n"); |
dea3101e JB |
2894 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
2895 | now. */ | |
2896 | lpfc_sli_hba_down(phba); | |
92d7f7b0 | 2897 | spin_lock_irq(&phba->hbalock); |
7054a606 | 2898 | phba->work_ha = 0; |
92d7f7b0 | 2899 | spin_unlock_irq(&phba->hbalock); |
549e55cd JS |
2900 | vports = lpfc_create_vport_work_array(phba); |
2901 | if (vports != NULL) | |
da0436e9 | 2902 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd | 2903 | shost = lpfc_shost_from_vport(vports[i]); |
549e55cd JS |
2904 | spin_lock_irq(shost->host_lock); |
2905 | vports[i]->work_port_events = 0; | |
2906 | vports[i]->fc_flag |= FC_OFFLINE_MODE; | |
2907 | spin_unlock_irq(shost->host_lock); | |
2908 | } | |
09372820 | 2909 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e JB |
2910 | } |
2911 | ||
e59058c4 | 2912 | /** |
3621a710 | 2913 | * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists |
e59058c4 JS |
2914 | * @phba: pointer to lpfc hba data structure. |
2915 | * | |
2916 | * This routine is to free all the SCSI buffers and IOCBs from the driver | |
2917 | * list back to kernel. It is called from lpfc_pci_remove_one to free | |
2918 | * the internal resources before the device is removed from the system. | |
e59058c4 | 2919 | **/ |
8a9d2e80 | 2920 | static void |
2e0fef85 | 2921 | lpfc_scsi_free(struct lpfc_hba *phba) |
dea3101e JB |
2922 | { |
2923 | struct lpfc_scsi_buf *sb, *sb_next; | |
2924 | struct lpfc_iocbq *io, *io_next; | |
2925 | ||
2e0fef85 | 2926 | spin_lock_irq(&phba->hbalock); |
a40fc5f0 | 2927 | |
dea3101e | 2928 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
a40fc5f0 JS |
2929 | |
2930 | spin_lock(&phba->scsi_buf_list_put_lock); | |
2931 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_put, | |
2932 | list) { | |
dea3101e JB |
2933 | list_del(&sb->list); |
2934 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, | |
92d7f7b0 | 2935 | sb->dma_handle); |
dea3101e JB |
2936 | kfree(sb); |
2937 | phba->total_scsi_bufs--; | |
2938 | } | |
a40fc5f0 JS |
2939 | spin_unlock(&phba->scsi_buf_list_put_lock); |
2940 | ||
2941 | spin_lock(&phba->scsi_buf_list_get_lock); | |
2942 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list_get, | |
2943 | list) { | |
dea3101e JB |
2944 | list_del(&sb->list); |
2945 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, | |
92d7f7b0 | 2946 | sb->dma_handle); |
dea3101e JB |
2947 | kfree(sb); |
2948 | phba->total_scsi_bufs--; | |
2949 | } | |
a40fc5f0 | 2950 | spin_unlock(&phba->scsi_buf_list_get_lock); |
dea3101e JB |
2951 | |
2952 | /* Release all the lpfc_iocbq entries maintained by this host. */ | |
2953 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { | |
2954 | list_del(&io->list); | |
2955 | kfree(io); | |
2956 | phba->total_iocbq_bufs--; | |
2957 | } | |
6d368e53 | 2958 | |
2e0fef85 | 2959 | spin_unlock_irq(&phba->hbalock); |
8a9d2e80 JS |
2960 | } |
2961 | ||
2962 | /** | |
2963 | * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping | |
2964 | * @phba: pointer to lpfc hba data structure. | |
2965 | * | |
2966 | * This routine first calculates the sizes of the current els and allocated | |
2967 | * scsi sgl lists, and then goes through all sgls to updates the physical | |
2968 | * XRIs assigned due to port function reset. During port initialization, the | |
2969 | * current els and allocated scsi sgl lists are 0s. | |
2970 | * | |
2971 | * Return codes | |
2972 | * 0 - successful (for now, it always returns 0) | |
2973 | **/ | |
2974 | int | |
2975 | lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba) | |
2976 | { | |
2977 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; | |
2978 | struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL; | |
2979 | uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt; | |
2980 | LIST_HEAD(els_sgl_list); | |
2981 | LIST_HEAD(scsi_sgl_list); | |
2982 | int rc; | |
2983 | ||
2984 | /* | |
2985 | * update on pci function's els xri-sgl list | |
2986 | */ | |
2987 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
2988 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { | |
2989 | /* els xri-sgl expanded */ | |
2990 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; | |
2991 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
2992 | "3157 ELS xri-sgl count increased from " | |
2993 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, | |
2994 | els_xri_cnt); | |
2995 | /* allocate the additional els sgls */ | |
2996 | for (i = 0; i < xri_cnt; i++) { | |
2997 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), | |
2998 | GFP_KERNEL); | |
2999 | if (sglq_entry == NULL) { | |
3000 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3001 | "2562 Failure to allocate an " | |
3002 | "ELS sgl entry:%d\n", i); | |
3003 | rc = -ENOMEM; | |
3004 | goto out_free_mem; | |
3005 | } | |
3006 | sglq_entry->buff_type = GEN_BUFF_TYPE; | |
3007 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, | |
3008 | &sglq_entry->phys); | |
3009 | if (sglq_entry->virt == NULL) { | |
3010 | kfree(sglq_entry); | |
3011 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3012 | "2563 Failure to allocate an " | |
3013 | "ELS mbuf:%d\n", i); | |
3014 | rc = -ENOMEM; | |
3015 | goto out_free_mem; | |
3016 | } | |
3017 | sglq_entry->sgl = sglq_entry->virt; | |
3018 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); | |
3019 | sglq_entry->state = SGL_FREED; | |
3020 | list_add_tail(&sglq_entry->list, &els_sgl_list); | |
3021 | } | |
38c20673 | 3022 | spin_lock_irq(&phba->hbalock); |
8a9d2e80 | 3023 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); |
38c20673 | 3024 | spin_unlock_irq(&phba->hbalock); |
8a9d2e80 JS |
3025 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { |
3026 | /* els xri-sgl shrinked */ | |
3027 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; | |
3028 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3029 | "3158 ELS xri-sgl count decreased from " | |
3030 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, | |
3031 | els_xri_cnt); | |
3032 | spin_lock_irq(&phba->hbalock); | |
3033 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list); | |
3034 | spin_unlock_irq(&phba->hbalock); | |
3035 | /* release extra els sgls from list */ | |
3036 | for (i = 0; i < xri_cnt; i++) { | |
3037 | list_remove_head(&els_sgl_list, | |
3038 | sglq_entry, struct lpfc_sglq, list); | |
3039 | if (sglq_entry) { | |
3040 | lpfc_mbuf_free(phba, sglq_entry->virt, | |
3041 | sglq_entry->phys); | |
3042 | kfree(sglq_entry); | |
3043 | } | |
3044 | } | |
3045 | spin_lock_irq(&phba->hbalock); | |
3046 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); | |
3047 | spin_unlock_irq(&phba->hbalock); | |
3048 | } else | |
3049 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3050 | "3163 ELS xri-sgl count unchanged: %d\n", | |
3051 | els_xri_cnt); | |
3052 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; | |
3053 | ||
3054 | /* update xris to els sgls on the list */ | |
3055 | sglq_entry = NULL; | |
3056 | sglq_entry_next = NULL; | |
3057 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, | |
3058 | &phba->sli4_hba.lpfc_sgl_list, list) { | |
3059 | lxri = lpfc_sli4_next_xritag(phba); | |
3060 | if (lxri == NO_XRI) { | |
3061 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3062 | "2400 Failed to allocate xri for " | |
3063 | "ELS sgl\n"); | |
3064 | rc = -ENOMEM; | |
3065 | goto out_free_mem; | |
3066 | } | |
3067 | sglq_entry->sli4_lxritag = lxri; | |
3068 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; | |
3069 | } | |
3070 | ||
3071 | /* | |
3072 | * update on pci function's allocated scsi xri-sgl list | |
3073 | */ | |
3074 | phba->total_scsi_bufs = 0; | |
3075 | ||
3076 | /* maximum number of xris available for scsi buffers */ | |
3077 | phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri - | |
3078 | els_xri_cnt; | |
3079 | ||
3080 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3081 | "2401 Current allocated SCSI xri-sgl count:%d, " | |
3082 | "maximum SCSI xri count:%d\n", | |
3083 | phba->sli4_hba.scsi_xri_cnt, | |
3084 | phba->sli4_hba.scsi_xri_max); | |
3085 | ||
a40fc5f0 | 3086 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
164cecd1 | 3087 | spin_lock(&phba->scsi_buf_list_put_lock); |
a40fc5f0 JS |
3088 | list_splice_init(&phba->lpfc_scsi_buf_list_get, &scsi_sgl_list); |
3089 | list_splice(&phba->lpfc_scsi_buf_list_put, &scsi_sgl_list); | |
164cecd1 | 3090 | spin_unlock(&phba->scsi_buf_list_put_lock); |
a40fc5f0 | 3091 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
8a9d2e80 JS |
3092 | |
3093 | if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) { | |
3094 | /* max scsi xri shrinked below the allocated scsi buffers */ | |
3095 | scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt - | |
3096 | phba->sli4_hba.scsi_xri_max; | |
3097 | /* release the extra allocated scsi buffers */ | |
3098 | for (i = 0; i < scsi_xri_cnt; i++) { | |
3099 | list_remove_head(&scsi_sgl_list, psb, | |
3100 | struct lpfc_scsi_buf, list); | |
3101 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, psb->data, | |
3102 | psb->dma_handle); | |
3103 | kfree(psb); | |
3104 | } | |
a40fc5f0 | 3105 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
8a9d2e80 | 3106 | phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt; |
a40fc5f0 | 3107 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
8a9d2e80 JS |
3108 | } |
3109 | ||
3110 | /* update xris associated to remaining allocated scsi buffers */ | |
3111 | psb = NULL; | |
3112 | psb_next = NULL; | |
3113 | list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) { | |
3114 | lxri = lpfc_sli4_next_xritag(phba); | |
3115 | if (lxri == NO_XRI) { | |
3116 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3117 | "2560 Failed to allocate xri for " | |
3118 | "scsi buffer\n"); | |
3119 | rc = -ENOMEM; | |
3120 | goto out_free_mem; | |
3121 | } | |
3122 | psb->cur_iocbq.sli4_lxritag = lxri; | |
3123 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; | |
3124 | } | |
a40fc5f0 | 3125 | spin_lock_irq(&phba->scsi_buf_list_get_lock); |
164cecd1 | 3126 | spin_lock(&phba->scsi_buf_list_put_lock); |
a40fc5f0 JS |
3127 | list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list_get); |
3128 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); | |
164cecd1 | 3129 | spin_unlock(&phba->scsi_buf_list_put_lock); |
a40fc5f0 | 3130 | spin_unlock_irq(&phba->scsi_buf_list_get_lock); |
8a9d2e80 | 3131 | |
dea3101e | 3132 | return 0; |
8a9d2e80 JS |
3133 | |
3134 | out_free_mem: | |
3135 | lpfc_free_els_sgl_list(phba); | |
3136 | lpfc_scsi_free(phba); | |
3137 | return rc; | |
dea3101e JB |
3138 | } |
3139 | ||
e59058c4 | 3140 | /** |
3621a710 | 3141 | * lpfc_create_port - Create an FC port |
e59058c4 JS |
3142 | * @phba: pointer to lpfc hba data structure. |
3143 | * @instance: a unique integer ID to this FC port. | |
3144 | * @dev: pointer to the device data structure. | |
3145 | * | |
3146 | * This routine creates a FC port for the upper layer protocol. The FC port | |
3147 | * can be created on top of either a physical port or a virtual port provided | |
3148 | * by the HBA. This routine also allocates a SCSI host data structure (shost) | |
3149 | * and associates the FC port created before adding the shost into the SCSI | |
3150 | * layer. | |
3151 | * | |
3152 | * Return codes | |
3153 | * @vport - pointer to the virtual N_Port data structure. | |
3154 | * NULL - port create failed. | |
3155 | **/ | |
2e0fef85 | 3156 | struct lpfc_vport * |
3de2a653 | 3157 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
47a8617c | 3158 | { |
2e0fef85 JS |
3159 | struct lpfc_vport *vport; |
3160 | struct Scsi_Host *shost; | |
3161 | int error = 0; | |
47a8617c | 3162 | |
3de2a653 JS |
3163 | if (dev != &phba->pcidev->dev) |
3164 | shost = scsi_host_alloc(&lpfc_vport_template, | |
3165 | sizeof(struct lpfc_vport)); | |
3166 | else | |
3167 | shost = scsi_host_alloc(&lpfc_template, | |
3168 | sizeof(struct lpfc_vport)); | |
2e0fef85 JS |
3169 | if (!shost) |
3170 | goto out; | |
47a8617c | 3171 | |
2e0fef85 JS |
3172 | vport = (struct lpfc_vport *) shost->hostdata; |
3173 | vport->phba = phba; | |
2e0fef85 | 3174 | vport->load_flag |= FC_LOADING; |
92d7f7b0 | 3175 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
7f5f3d0d | 3176 | vport->fc_rscn_flush = 0; |
47a8617c | 3177 | |
3de2a653 | 3178 | lpfc_get_vport_cfgparam(vport); |
2e0fef85 JS |
3179 | shost->unique_id = instance; |
3180 | shost->max_id = LPFC_MAX_TARGET; | |
3de2a653 | 3181 | shost->max_lun = vport->cfg_max_luns; |
2e0fef85 JS |
3182 | shost->this_id = -1; |
3183 | shost->max_cmd_len = 16; | |
da0436e9 | 3184 | if (phba->sli_rev == LPFC_SLI_REV4) { |
28baac74 | 3185 | shost->dma_boundary = |
cb5172ea | 3186 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
da0436e9 JS |
3187 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
3188 | } | |
81301a9b | 3189 | |
47a8617c | 3190 | /* |
2e0fef85 JS |
3191 | * Set initial can_queue value since 0 is no longer supported and |
3192 | * scsi_add_host will fail. This will be adjusted later based on the | |
3193 | * max xri value determined in hba setup. | |
47a8617c | 3194 | */ |
2e0fef85 | 3195 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
3de2a653 | 3196 | if (dev != &phba->pcidev->dev) { |
92d7f7b0 JS |
3197 | shost->transportt = lpfc_vport_transport_template; |
3198 | vport->port_type = LPFC_NPIV_PORT; | |
3199 | } else { | |
3200 | shost->transportt = lpfc_transport_template; | |
3201 | vport->port_type = LPFC_PHYSICAL_PORT; | |
3202 | } | |
47a8617c | 3203 | |
2e0fef85 JS |
3204 | /* Initialize all internally managed lists. */ |
3205 | INIT_LIST_HEAD(&vport->fc_nodes); | |
da0436e9 | 3206 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
2e0fef85 | 3207 | spin_lock_init(&vport->work_port_lock); |
47a8617c | 3208 | |
2e0fef85 JS |
3209 | init_timer(&vport->fc_disctmo); |
3210 | vport->fc_disctmo.function = lpfc_disc_timeout; | |
92d7f7b0 | 3211 | vport->fc_disctmo.data = (unsigned long)vport; |
47a8617c | 3212 | |
2e0fef85 JS |
3213 | init_timer(&vport->fc_fdmitmo); |
3214 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; | |
92d7f7b0 | 3215 | vport->fc_fdmitmo.data = (unsigned long)vport; |
47a8617c | 3216 | |
2e0fef85 JS |
3217 | init_timer(&vport->els_tmofunc); |
3218 | vport->els_tmofunc.function = lpfc_els_timeout; | |
92d7f7b0 | 3219 | vport->els_tmofunc.data = (unsigned long)vport; |
92494144 JS |
3220 | |
3221 | init_timer(&vport->delayed_disc_tmo); | |
3222 | vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo; | |
3223 | vport->delayed_disc_tmo.data = (unsigned long)vport; | |
3224 | ||
d139b9bd | 3225 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
2e0fef85 JS |
3226 | if (error) |
3227 | goto out_put_shost; | |
47a8617c | 3228 | |
549e55cd | 3229 | spin_lock_irq(&phba->hbalock); |
2e0fef85 | 3230 | list_add_tail(&vport->listentry, &phba->port_list); |
549e55cd | 3231 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 3232 | return vport; |
47a8617c | 3233 | |
2e0fef85 JS |
3234 | out_put_shost: |
3235 | scsi_host_put(shost); | |
3236 | out: | |
3237 | return NULL; | |
47a8617c JS |
3238 | } |
3239 | ||
e59058c4 | 3240 | /** |
3621a710 | 3241 | * destroy_port - destroy an FC port |
e59058c4 JS |
3242 | * @vport: pointer to an lpfc virtual N_Port data structure. |
3243 | * | |
3244 | * This routine destroys a FC port from the upper layer protocol. All the | |
3245 | * resources associated with the port are released. | |
3246 | **/ | |
2e0fef85 JS |
3247 | void |
3248 | destroy_port(struct lpfc_vport *vport) | |
47a8617c | 3249 | { |
92d7f7b0 JS |
3250 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
3251 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 3252 | |
858c9f6c | 3253 | lpfc_debugfs_terminate(vport); |
92d7f7b0 JS |
3254 | fc_remove_host(shost); |
3255 | scsi_remove_host(shost); | |
47a8617c | 3256 | |
92d7f7b0 JS |
3257 | spin_lock_irq(&phba->hbalock); |
3258 | list_del_init(&vport->listentry); | |
3259 | spin_unlock_irq(&phba->hbalock); | |
47a8617c | 3260 | |
92d7f7b0 | 3261 | lpfc_cleanup(vport); |
47a8617c | 3262 | return; |
47a8617c JS |
3263 | } |
3264 | ||
e59058c4 | 3265 | /** |
3621a710 | 3266 | * lpfc_get_instance - Get a unique integer ID |
e59058c4 JS |
3267 | * |
3268 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It | |
3269 | * uses the kernel idr facility to perform the task. | |
3270 | * | |
3271 | * Return codes: | |
3272 | * instance - a unique integer ID allocated as the new instance. | |
3273 | * -1 - lpfc get instance failed. | |
3274 | **/ | |
92d7f7b0 JS |
3275 | int |
3276 | lpfc_get_instance(void) | |
3277 | { | |
ab516036 TH |
3278 | int ret; |
3279 | ||
3280 | ret = idr_alloc(&lpfc_hba_index, NULL, 0, 0, GFP_KERNEL); | |
3281 | return ret < 0 ? -1 : ret; | |
47a8617c JS |
3282 | } |
3283 | ||
e59058c4 | 3284 | /** |
3621a710 | 3285 | * lpfc_scan_finished - method for SCSI layer to detect whether scan is done |
e59058c4 JS |
3286 | * @shost: pointer to SCSI host data structure. |
3287 | * @time: elapsed time of the scan in jiffies. | |
3288 | * | |
3289 | * This routine is called by the SCSI layer with a SCSI host to determine | |
3290 | * whether the scan host is finished. | |
3291 | * | |
3292 | * Note: there is no scan_start function as adapter initialization will have | |
3293 | * asynchronously kicked off the link initialization. | |
3294 | * | |
3295 | * Return codes | |
3296 | * 0 - SCSI host scan is not over yet. | |
3297 | * 1 - SCSI host scan is over. | |
3298 | **/ | |
47a8617c JS |
3299 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
3300 | { | |
2e0fef85 JS |
3301 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
3302 | struct lpfc_hba *phba = vport->phba; | |
858c9f6c | 3303 | int stat = 0; |
47a8617c | 3304 | |
858c9f6c JS |
3305 | spin_lock_irq(shost->host_lock); |
3306 | ||
51ef4c26 | 3307 | if (vport->load_flag & FC_UNLOADING) { |
858c9f6c JS |
3308 | stat = 1; |
3309 | goto finished; | |
3310 | } | |
256ec0d0 | 3311 | if (time >= msecs_to_jiffies(30 * 1000)) { |
2e0fef85 | 3312 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
e8b62011 JS |
3313 | "0461 Scanning longer than 30 " |
3314 | "seconds. Continuing initialization\n"); | |
858c9f6c | 3315 | stat = 1; |
47a8617c | 3316 | goto finished; |
2e0fef85 | 3317 | } |
256ec0d0 JS |
3318 | if (time >= msecs_to_jiffies(15 * 1000) && |
3319 | phba->link_state <= LPFC_LINK_DOWN) { | |
2e0fef85 | 3320 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
e8b62011 JS |
3321 | "0465 Link down longer than 15 " |
3322 | "seconds. Continuing initialization\n"); | |
858c9f6c | 3323 | stat = 1; |
47a8617c | 3324 | goto finished; |
2e0fef85 | 3325 | } |
47a8617c | 3326 | |
2e0fef85 | 3327 | if (vport->port_state != LPFC_VPORT_READY) |
858c9f6c | 3328 | goto finished; |
2e0fef85 | 3329 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
858c9f6c | 3330 | goto finished; |
256ec0d0 | 3331 | if (vport->fc_map_cnt == 0 && time < msecs_to_jiffies(2 * 1000)) |
858c9f6c | 3332 | goto finished; |
2e0fef85 | 3333 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
858c9f6c JS |
3334 | goto finished; |
3335 | ||
3336 | stat = 1; | |
47a8617c JS |
3337 | |
3338 | finished: | |
858c9f6c JS |
3339 | spin_unlock_irq(shost->host_lock); |
3340 | return stat; | |
92d7f7b0 | 3341 | } |
47a8617c | 3342 | |
e59058c4 | 3343 | /** |
3621a710 | 3344 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
e59058c4 JS |
3345 | * @shost: pointer to SCSI host data structure. |
3346 | * | |
3347 | * This routine initializes a given SCSI host attributes on a FC port. The | |
3348 | * SCSI host can be either on top of a physical port or a virtual port. | |
3349 | **/ | |
92d7f7b0 JS |
3350 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
3351 | { | |
3352 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3353 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 3354 | /* |
2e0fef85 | 3355 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
47a8617c JS |
3356 | */ |
3357 | ||
2e0fef85 JS |
3358 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
3359 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
47a8617c JS |
3360 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
3361 | ||
3362 | memset(fc_host_supported_fc4s(shost), 0, | |
2e0fef85 | 3363 | sizeof(fc_host_supported_fc4s(shost))); |
47a8617c JS |
3364 | fc_host_supported_fc4s(shost)[2] = 1; |
3365 | fc_host_supported_fc4s(shost)[7] = 1; | |
3366 | ||
92d7f7b0 JS |
3367 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
3368 | sizeof fc_host_symbolic_name(shost)); | |
47a8617c JS |
3369 | |
3370 | fc_host_supported_speeds(shost) = 0; | |
88a2cfbb JS |
3371 | if (phba->lmt & LMT_16Gb) |
3372 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; | |
47a8617c JS |
3373 | if (phba->lmt & LMT_10Gb) |
3374 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; | |
a8adb832 JS |
3375 | if (phba->lmt & LMT_8Gb) |
3376 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; | |
47a8617c JS |
3377 | if (phba->lmt & LMT_4Gb) |
3378 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; | |
3379 | if (phba->lmt & LMT_2Gb) | |
3380 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; | |
3381 | if (phba->lmt & LMT_1Gb) | |
3382 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; | |
3383 | ||
3384 | fc_host_maxframe_size(shost) = | |
2e0fef85 JS |
3385 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
3386 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; | |
47a8617c | 3387 | |
0af5d708 MC |
3388 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
3389 | ||
47a8617c JS |
3390 | /* This value is also unchanging */ |
3391 | memset(fc_host_active_fc4s(shost), 0, | |
2e0fef85 | 3392 | sizeof(fc_host_active_fc4s(shost))); |
47a8617c JS |
3393 | fc_host_active_fc4s(shost)[2] = 1; |
3394 | fc_host_active_fc4s(shost)[7] = 1; | |
3395 | ||
92d7f7b0 | 3396 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
47a8617c | 3397 | spin_lock_irq(shost->host_lock); |
51ef4c26 | 3398 | vport->load_flag &= ~FC_LOADING; |
47a8617c | 3399 | spin_unlock_irq(shost->host_lock); |
47a8617c | 3400 | } |
dea3101e | 3401 | |
e59058c4 | 3402 | /** |
da0436e9 | 3403 | * lpfc_stop_port_s3 - Stop SLI3 device port |
e59058c4 JS |
3404 | * @phba: pointer to lpfc hba data structure. |
3405 | * | |
da0436e9 JS |
3406 | * This routine is invoked to stop an SLI3 device port, it stops the device |
3407 | * from generating interrupts and stops the device driver's timers for the | |
3408 | * device. | |
e59058c4 | 3409 | **/ |
da0436e9 JS |
3410 | static void |
3411 | lpfc_stop_port_s3(struct lpfc_hba *phba) | |
db2378e0 | 3412 | { |
da0436e9 JS |
3413 | /* Clear all interrupt enable conditions */ |
3414 | writel(0, phba->HCregaddr); | |
3415 | readl(phba->HCregaddr); /* flush */ | |
3416 | /* Clear all pending interrupts */ | |
3417 | writel(0xffffffff, phba->HAregaddr); | |
3418 | readl(phba->HAregaddr); /* flush */ | |
db2378e0 | 3419 | |
da0436e9 JS |
3420 | /* Reset some HBA SLI setup states */ |
3421 | lpfc_stop_hba_timers(phba); | |
3422 | phba->pport->work_port_events = 0; | |
3423 | } | |
db2378e0 | 3424 | |
da0436e9 JS |
3425 | /** |
3426 | * lpfc_stop_port_s4 - Stop SLI4 device port | |
3427 | * @phba: pointer to lpfc hba data structure. | |
3428 | * | |
3429 | * This routine is invoked to stop an SLI4 device port, it stops the device | |
3430 | * from generating interrupts and stops the device driver's timers for the | |
3431 | * device. | |
3432 | **/ | |
3433 | static void | |
3434 | lpfc_stop_port_s4(struct lpfc_hba *phba) | |
3435 | { | |
3436 | /* Reset some HBA SLI4 setup states */ | |
3437 | lpfc_stop_hba_timers(phba); | |
3438 | phba->pport->work_port_events = 0; | |
3439 | phba->sli4_hba.intr_enable = 0; | |
da0436e9 | 3440 | } |
9399627f | 3441 | |
da0436e9 JS |
3442 | /** |
3443 | * lpfc_stop_port - Wrapper function for stopping hba port | |
3444 | * @phba: Pointer to HBA context object. | |
3445 | * | |
3446 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from | |
3447 | * the API jump table function pointer from the lpfc_hba struct. | |
3448 | **/ | |
3449 | void | |
3450 | lpfc_stop_port(struct lpfc_hba *phba) | |
3451 | { | |
3452 | phba->lpfc_stop_port(phba); | |
3453 | } | |
db2378e0 | 3454 | |
ecfd03c6 JS |
3455 | /** |
3456 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer | |
3457 | * @phba: Pointer to hba for which this call is being executed. | |
3458 | * | |
3459 | * This routine starts the timer waiting for the FCF rediscovery to complete. | |
3460 | **/ | |
3461 | void | |
3462 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) | |
3463 | { | |
3464 | unsigned long fcf_redisc_wait_tmo = | |
3465 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); | |
3466 | /* Start fcf rediscovery wait period timer */ | |
3467 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); | |
3468 | spin_lock_irq(&phba->hbalock); | |
3469 | /* Allow action to new fcf asynchronous event */ | |
3470 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); | |
3471 | /* Mark the FCF rediscovery pending state */ | |
3472 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; | |
3473 | spin_unlock_irq(&phba->hbalock); | |
3474 | } | |
3475 | ||
3476 | /** | |
3477 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout | |
3478 | * @ptr: Map to lpfc_hba data structure pointer. | |
3479 | * | |
3480 | * This routine is invoked when waiting for FCF table rediscover has been | |
3481 | * timed out. If new FCF record(s) has (have) been discovered during the | |
3482 | * wait period, a new FCF event shall be added to the FCOE async event | |
3483 | * list, and then worker thread shall be waked up for processing from the | |
3484 | * worker thread context. | |
3485 | **/ | |
3486 | void | |
3487 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) | |
3488 | { | |
3489 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; | |
3490 | ||
3491 | /* Don't send FCF rediscovery event if timer cancelled */ | |
3492 | spin_lock_irq(&phba->hbalock); | |
3493 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
3494 | spin_unlock_irq(&phba->hbalock); | |
3495 | return; | |
3496 | } | |
3497 | /* Clear FCF rediscovery timer pending flag */ | |
3498 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; | |
3499 | /* FCF rediscovery event to worker thread */ | |
3500 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; | |
3501 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 | 3502 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 3503 | "2776 FCF rediscover quiescent timer expired\n"); |
ecfd03c6 JS |
3504 | /* wake up worker thread */ |
3505 | lpfc_worker_wake_up(phba); | |
3506 | } | |
3507 | ||
e59058c4 | 3508 | /** |
da0436e9 | 3509 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
e59058c4 | 3510 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3511 | * @acqe_link: pointer to the async link completion queue entry. |
e59058c4 | 3512 | * |
da0436e9 JS |
3513 | * This routine is to parse the SLI4 link-attention link fault code and |
3514 | * translate it into the base driver's read link attention mailbox command | |
3515 | * status. | |
3516 | * | |
3517 | * Return: Link-attention status in terms of base driver's coding. | |
e59058c4 | 3518 | **/ |
da0436e9 JS |
3519 | static uint16_t |
3520 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, | |
3521 | struct lpfc_acqe_link *acqe_link) | |
db2378e0 | 3522 | { |
da0436e9 | 3523 | uint16_t latt_fault; |
9399627f | 3524 | |
da0436e9 JS |
3525 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
3526 | case LPFC_ASYNC_LINK_FAULT_NONE: | |
3527 | case LPFC_ASYNC_LINK_FAULT_LOCAL: | |
3528 | case LPFC_ASYNC_LINK_FAULT_REMOTE: | |
3529 | latt_fault = 0; | |
3530 | break; | |
3531 | default: | |
3532 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3533 | "0398 Invalid link fault code: x%x\n", | |
3534 | bf_get(lpfc_acqe_link_fault, acqe_link)); | |
3535 | latt_fault = MBXERR_ERROR; | |
3536 | break; | |
3537 | } | |
3538 | return latt_fault; | |
db2378e0 JS |
3539 | } |
3540 | ||
5b75da2f | 3541 | /** |
da0436e9 | 3542 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
5b75da2f | 3543 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3544 | * @acqe_link: pointer to the async link completion queue entry. |
5b75da2f | 3545 | * |
da0436e9 JS |
3546 | * This routine is to parse the SLI4 link attention type and translate it |
3547 | * into the base driver's link attention type coding. | |
5b75da2f | 3548 | * |
da0436e9 JS |
3549 | * Return: Link attention type in terms of base driver's coding. |
3550 | **/ | |
3551 | static uint8_t | |
3552 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, | |
3553 | struct lpfc_acqe_link *acqe_link) | |
5b75da2f | 3554 | { |
da0436e9 | 3555 | uint8_t att_type; |
5b75da2f | 3556 | |
da0436e9 JS |
3557 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
3558 | case LPFC_ASYNC_LINK_STATUS_DOWN: | |
3559 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: | |
76a95d75 | 3560 | att_type = LPFC_ATT_LINK_DOWN; |
da0436e9 JS |
3561 | break; |
3562 | case LPFC_ASYNC_LINK_STATUS_UP: | |
3563 | /* Ignore physical link up events - wait for logical link up */ | |
76a95d75 | 3564 | att_type = LPFC_ATT_RESERVED; |
da0436e9 JS |
3565 | break; |
3566 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: | |
76a95d75 | 3567 | att_type = LPFC_ATT_LINK_UP; |
da0436e9 JS |
3568 | break; |
3569 | default: | |
3570 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3571 | "0399 Invalid link attention type: x%x\n", | |
3572 | bf_get(lpfc_acqe_link_status, acqe_link)); | |
76a95d75 | 3573 | att_type = LPFC_ATT_RESERVED; |
da0436e9 | 3574 | break; |
5b75da2f | 3575 | } |
da0436e9 | 3576 | return att_type; |
5b75da2f JS |
3577 | } |
3578 | ||
3579 | /** | |
da0436e9 | 3580 | * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed |
5b75da2f | 3581 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3582 | * @acqe_link: pointer to the async link completion queue entry. |
5b75da2f | 3583 | * |
da0436e9 JS |
3584 | * This routine is to parse the SLI4 link-attention link speed and translate |
3585 | * it into the base driver's link-attention link speed coding. | |
3586 | * | |
3587 | * Return: Link-attention link speed in terms of base driver's coding. | |
3588 | **/ | |
3589 | static uint8_t | |
3590 | lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba, | |
3591 | struct lpfc_acqe_link *acqe_link) | |
5b75da2f | 3592 | { |
da0436e9 JS |
3593 | uint8_t link_speed; |
3594 | ||
3595 | switch (bf_get(lpfc_acqe_link_speed, acqe_link)) { | |
3596 | case LPFC_ASYNC_LINK_SPEED_ZERO: | |
da0436e9 | 3597 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
da0436e9 | 3598 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
76a95d75 | 3599 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
da0436e9 JS |
3600 | break; |
3601 | case LPFC_ASYNC_LINK_SPEED_1GBPS: | |
76a95d75 | 3602 | link_speed = LPFC_LINK_SPEED_1GHZ; |
da0436e9 JS |
3603 | break; |
3604 | case LPFC_ASYNC_LINK_SPEED_10GBPS: | |
76a95d75 | 3605 | link_speed = LPFC_LINK_SPEED_10GHZ; |
da0436e9 JS |
3606 | break; |
3607 | default: | |
3608 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3609 | "0483 Invalid link-attention link speed: x%x\n", | |
3610 | bf_get(lpfc_acqe_link_speed, acqe_link)); | |
76a95d75 | 3611 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
da0436e9 JS |
3612 | break; |
3613 | } | |
3614 | return link_speed; | |
3615 | } | |
3616 | ||
8b68cd52 JS |
3617 | /** |
3618 | * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed | |
3619 | * @phba: pointer to lpfc hba data structure. | |
3620 | * | |
3621 | * This routine is to get an SLI3 FC port's link speed in Mbps. | |
3622 | * | |
3623 | * Return: link speed in terms of Mbps. | |
3624 | **/ | |
3625 | uint32_t | |
3626 | lpfc_sli_port_speed_get(struct lpfc_hba *phba) | |
3627 | { | |
3628 | uint32_t link_speed; | |
3629 | ||
3630 | if (!lpfc_is_link_up(phba)) | |
3631 | return 0; | |
3632 | ||
3633 | switch (phba->fc_linkspeed) { | |
3634 | case LPFC_LINK_SPEED_1GHZ: | |
3635 | link_speed = 1000; | |
3636 | break; | |
3637 | case LPFC_LINK_SPEED_2GHZ: | |
3638 | link_speed = 2000; | |
3639 | break; | |
3640 | case LPFC_LINK_SPEED_4GHZ: | |
3641 | link_speed = 4000; | |
3642 | break; | |
3643 | case LPFC_LINK_SPEED_8GHZ: | |
3644 | link_speed = 8000; | |
3645 | break; | |
3646 | case LPFC_LINK_SPEED_10GHZ: | |
3647 | link_speed = 10000; | |
3648 | break; | |
3649 | case LPFC_LINK_SPEED_16GHZ: | |
3650 | link_speed = 16000; | |
3651 | break; | |
3652 | default: | |
3653 | link_speed = 0; | |
3654 | } | |
3655 | return link_speed; | |
3656 | } | |
3657 | ||
3658 | /** | |
3659 | * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed | |
3660 | * @phba: pointer to lpfc hba data structure. | |
3661 | * @evt_code: asynchronous event code. | |
3662 | * @speed_code: asynchronous event link speed code. | |
3663 | * | |
3664 | * This routine is to parse the giving SLI4 async event link speed code into | |
3665 | * value of Mbps for the link speed. | |
3666 | * | |
3667 | * Return: link speed in terms of Mbps. | |
3668 | **/ | |
3669 | static uint32_t | |
3670 | lpfc_sli4_port_speed_parse(struct lpfc_hba *phba, uint32_t evt_code, | |
3671 | uint8_t speed_code) | |
3672 | { | |
3673 | uint32_t port_speed; | |
3674 | ||
3675 | switch (evt_code) { | |
3676 | case LPFC_TRAILER_CODE_LINK: | |
3677 | switch (speed_code) { | |
3678 | case LPFC_EVT_CODE_LINK_NO_LINK: | |
3679 | port_speed = 0; | |
3680 | break; | |
3681 | case LPFC_EVT_CODE_LINK_10_MBIT: | |
3682 | port_speed = 10; | |
3683 | break; | |
3684 | case LPFC_EVT_CODE_LINK_100_MBIT: | |
3685 | port_speed = 100; | |
3686 | break; | |
3687 | case LPFC_EVT_CODE_LINK_1_GBIT: | |
3688 | port_speed = 1000; | |
3689 | break; | |
3690 | case LPFC_EVT_CODE_LINK_10_GBIT: | |
3691 | port_speed = 10000; | |
3692 | break; | |
3693 | default: | |
3694 | port_speed = 0; | |
3695 | } | |
3696 | break; | |
3697 | case LPFC_TRAILER_CODE_FC: | |
3698 | switch (speed_code) { | |
3699 | case LPFC_EVT_CODE_FC_NO_LINK: | |
3700 | port_speed = 0; | |
3701 | break; | |
3702 | case LPFC_EVT_CODE_FC_1_GBAUD: | |
3703 | port_speed = 1000; | |
3704 | break; | |
3705 | case LPFC_EVT_CODE_FC_2_GBAUD: | |
3706 | port_speed = 2000; | |
3707 | break; | |
3708 | case LPFC_EVT_CODE_FC_4_GBAUD: | |
3709 | port_speed = 4000; | |
3710 | break; | |
3711 | case LPFC_EVT_CODE_FC_8_GBAUD: | |
3712 | port_speed = 8000; | |
3713 | break; | |
3714 | case LPFC_EVT_CODE_FC_10_GBAUD: | |
3715 | port_speed = 10000; | |
3716 | break; | |
3717 | case LPFC_EVT_CODE_FC_16_GBAUD: | |
3718 | port_speed = 16000; | |
3719 | break; | |
3720 | default: | |
3721 | port_speed = 0; | |
3722 | } | |
3723 | break; | |
3724 | default: | |
3725 | port_speed = 0; | |
3726 | } | |
3727 | return port_speed; | |
3728 | } | |
3729 | ||
da0436e9 | 3730 | /** |
70f3c073 | 3731 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
da0436e9 JS |
3732 | * @phba: pointer to lpfc hba data structure. |
3733 | * @acqe_link: pointer to the async link completion queue entry. | |
3734 | * | |
70f3c073 | 3735 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
da0436e9 JS |
3736 | **/ |
3737 | static void | |
3738 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, | |
3739 | struct lpfc_acqe_link *acqe_link) | |
3740 | { | |
3741 | struct lpfc_dmabuf *mp; | |
3742 | LPFC_MBOXQ_t *pmb; | |
3743 | MAILBOX_t *mb; | |
76a95d75 | 3744 | struct lpfc_mbx_read_top *la; |
da0436e9 | 3745 | uint8_t att_type; |
76a95d75 | 3746 | int rc; |
da0436e9 JS |
3747 | |
3748 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); | |
76a95d75 | 3749 | if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP) |
da0436e9 | 3750 | return; |
32b9793f | 3751 | phba->fcoe_eventtag = acqe_link->event_tag; |
da0436e9 JS |
3752 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3753 | if (!pmb) { | |
3754 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3755 | "0395 The mboxq allocation failed\n"); | |
3756 | return; | |
3757 | } | |
3758 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
3759 | if (!mp) { | |
3760 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3761 | "0396 The lpfc_dmabuf allocation failed\n"); | |
3762 | goto out_free_pmb; | |
3763 | } | |
3764 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
3765 | if (!mp->virt) { | |
3766 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3767 | "0397 The mbuf allocation failed\n"); | |
3768 | goto out_free_dmabuf; | |
3769 | } | |
3770 | ||
3771 | /* Cleanup any outstanding ELS commands */ | |
3772 | lpfc_els_flush_all_cmd(phba); | |
3773 | ||
3774 | /* Block ELS IOCBs until we have done process link event */ | |
3775 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
3776 | ||
3777 | /* Update link event statistics */ | |
3778 | phba->sli.slistat.link_event++; | |
3779 | ||
76a95d75 JS |
3780 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
3781 | lpfc_read_topology(phba, pmb, mp); | |
3782 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
da0436e9 JS |
3783 | pmb->vport = phba->pport; |
3784 | ||
da0436e9 JS |
3785 | /* Keep the link status for extra SLI4 state machine reference */ |
3786 | phba->sli4_hba.link_state.speed = | |
8b68cd52 JS |
3787 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_LINK, |
3788 | bf_get(lpfc_acqe_link_speed, acqe_link)); | |
da0436e9 JS |
3789 | phba->sli4_hba.link_state.duplex = |
3790 | bf_get(lpfc_acqe_link_duplex, acqe_link); | |
3791 | phba->sli4_hba.link_state.status = | |
3792 | bf_get(lpfc_acqe_link_status, acqe_link); | |
70f3c073 JS |
3793 | phba->sli4_hba.link_state.type = |
3794 | bf_get(lpfc_acqe_link_type, acqe_link); | |
3795 | phba->sli4_hba.link_state.number = | |
3796 | bf_get(lpfc_acqe_link_number, acqe_link); | |
da0436e9 JS |
3797 | phba->sli4_hba.link_state.fault = |
3798 | bf_get(lpfc_acqe_link_fault, acqe_link); | |
65467b6b | 3799 | phba->sli4_hba.link_state.logical_speed = |
8b68cd52 JS |
3800 | bf_get(lpfc_acqe_logical_link_speed, acqe_link) * 10; |
3801 | ||
70f3c073 | 3802 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
c31098ce JS |
3803 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
3804 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " | |
3805 | "Logical speed:%dMbps Fault:%d\n", | |
70f3c073 JS |
3806 | phba->sli4_hba.link_state.speed, |
3807 | phba->sli4_hba.link_state.topology, | |
3808 | phba->sli4_hba.link_state.status, | |
3809 | phba->sli4_hba.link_state.type, | |
3810 | phba->sli4_hba.link_state.number, | |
8b68cd52 | 3811 | phba->sli4_hba.link_state.logical_speed, |
70f3c073 | 3812 | phba->sli4_hba.link_state.fault); |
76a95d75 JS |
3813 | /* |
3814 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch | |
3815 | * topology info. Note: Optional for non FC-AL ports. | |
3816 | */ | |
3817 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { | |
3818 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3819 | if (rc == MBX_NOT_FINISHED) | |
3820 | goto out_free_dmabuf; | |
3821 | return; | |
3822 | } | |
3823 | /* | |
3824 | * For FCoE Mode: fill in all the topology information we need and call | |
3825 | * the READ_TOPOLOGY completion routine to continue without actually | |
3826 | * sending the READ_TOPOLOGY mailbox command to the port. | |
3827 | */ | |
3828 | /* Parse and translate status field */ | |
3829 | mb = &pmb->u.mb; | |
3830 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); | |
3831 | ||
3832 | /* Parse and translate link attention fields */ | |
3833 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; | |
3834 | la->eventTag = acqe_link->event_tag; | |
3835 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); | |
3836 | bf_set(lpfc_mbx_read_top_link_spd, la, | |
3837 | lpfc_sli4_parse_latt_link_speed(phba, acqe_link)); | |
3838 | ||
3839 | /* Fake the the following irrelvant fields */ | |
3840 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); | |
3841 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); | |
3842 | bf_set(lpfc_mbx_read_top_il, la, 0); | |
3843 | bf_set(lpfc_mbx_read_top_pb, la, 0); | |
3844 | bf_set(lpfc_mbx_read_top_fa, la, 0); | |
3845 | bf_set(lpfc_mbx_read_top_mm, la, 0); | |
da0436e9 JS |
3846 | |
3847 | /* Invoke the lpfc_handle_latt mailbox command callback function */ | |
76a95d75 | 3848 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
da0436e9 | 3849 | |
5b75da2f | 3850 | return; |
da0436e9 JS |
3851 | |
3852 | out_free_dmabuf: | |
3853 | kfree(mp); | |
3854 | out_free_pmb: | |
3855 | mempool_free(pmb, phba->mbox_mem_pool); | |
3856 | } | |
3857 | ||
70f3c073 JS |
3858 | /** |
3859 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event | |
3860 | * @phba: pointer to lpfc hba data structure. | |
3861 | * @acqe_fc: pointer to the async fc completion queue entry. | |
3862 | * | |
3863 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log | |
3864 | * that the event was received and then issue a read_topology mailbox command so | |
3865 | * that the rest of the driver will treat it the same as SLI3. | |
3866 | **/ | |
3867 | static void | |
3868 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) | |
3869 | { | |
3870 | struct lpfc_dmabuf *mp; | |
3871 | LPFC_MBOXQ_t *pmb; | |
3872 | int rc; | |
3873 | ||
3874 | if (bf_get(lpfc_trailer_type, acqe_fc) != | |
3875 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { | |
3876 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3877 | "2895 Non FC link Event detected.(%d)\n", | |
3878 | bf_get(lpfc_trailer_type, acqe_fc)); | |
3879 | return; | |
3880 | } | |
3881 | /* Keep the link status for extra SLI4 state machine reference */ | |
3882 | phba->sli4_hba.link_state.speed = | |
8b68cd52 JS |
3883 | lpfc_sli4_port_speed_parse(phba, LPFC_TRAILER_CODE_FC, |
3884 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc)); | |
70f3c073 JS |
3885 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; |
3886 | phba->sli4_hba.link_state.topology = | |
3887 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); | |
3888 | phba->sli4_hba.link_state.status = | |
3889 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); | |
3890 | phba->sli4_hba.link_state.type = | |
3891 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); | |
3892 | phba->sli4_hba.link_state.number = | |
3893 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); | |
3894 | phba->sli4_hba.link_state.fault = | |
3895 | bf_get(lpfc_acqe_link_fault, acqe_fc); | |
3896 | phba->sli4_hba.link_state.logical_speed = | |
8b68cd52 | 3897 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc) * 10; |
70f3c073 JS |
3898 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
3899 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " | |
3900 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" | |
3901 | "%dMbps Fault:%d\n", | |
3902 | phba->sli4_hba.link_state.speed, | |
3903 | phba->sli4_hba.link_state.topology, | |
3904 | phba->sli4_hba.link_state.status, | |
3905 | phba->sli4_hba.link_state.type, | |
3906 | phba->sli4_hba.link_state.number, | |
8b68cd52 | 3907 | phba->sli4_hba.link_state.logical_speed, |
70f3c073 JS |
3908 | phba->sli4_hba.link_state.fault); |
3909 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
3910 | if (!pmb) { | |
3911 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3912 | "2897 The mboxq allocation failed\n"); | |
3913 | return; | |
3914 | } | |
3915 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
3916 | if (!mp) { | |
3917 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3918 | "2898 The lpfc_dmabuf allocation failed\n"); | |
3919 | goto out_free_pmb; | |
3920 | } | |
3921 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
3922 | if (!mp->virt) { | |
3923 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3924 | "2899 The mbuf allocation failed\n"); | |
3925 | goto out_free_dmabuf; | |
3926 | } | |
3927 | ||
3928 | /* Cleanup any outstanding ELS commands */ | |
3929 | lpfc_els_flush_all_cmd(phba); | |
3930 | ||
3931 | /* Block ELS IOCBs until we have done process link event */ | |
3932 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
3933 | ||
3934 | /* Update link event statistics */ | |
3935 | phba->sli.slistat.link_event++; | |
3936 | ||
3937 | /* Create lpfc_handle_latt mailbox command from link ACQE */ | |
3938 | lpfc_read_topology(phba, pmb, mp); | |
3939 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
3940 | pmb->vport = phba->pport; | |
3941 | ||
3942 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3943 | if (rc == MBX_NOT_FINISHED) | |
3944 | goto out_free_dmabuf; | |
3945 | return; | |
3946 | ||
3947 | out_free_dmabuf: | |
3948 | kfree(mp); | |
3949 | out_free_pmb: | |
3950 | mempool_free(pmb, phba->mbox_mem_pool); | |
3951 | } | |
3952 | ||
3953 | /** | |
3954 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event | |
3955 | * @phba: pointer to lpfc hba data structure. | |
3956 | * @acqe_fc: pointer to the async SLI completion queue entry. | |
3957 | * | |
3958 | * This routine is to handle the SLI4 asynchronous SLI events. | |
3959 | **/ | |
3960 | static void | |
3961 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) | |
3962 | { | |
4b8bae08 | 3963 | char port_name; |
8c1312e1 | 3964 | char message[128]; |
4b8bae08 JS |
3965 | uint8_t status; |
3966 | struct lpfc_acqe_misconfigured_event *misconfigured; | |
3967 | ||
3968 | /* special case misconfigured event as it contains data for all ports */ | |
3969 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
3970 | LPFC_SLI_INTF_IF_TYPE_2) || | |
3971 | (bf_get(lpfc_trailer_type, acqe_sli) != | |
3972 | LPFC_SLI_EVENT_TYPE_MISCONFIGURED)) { | |
3973 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3974 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" | |
3975 | "x%08x SLI Event Type:%d\n", | |
3976 | acqe_sli->event_data1, acqe_sli->event_data2, | |
3977 | bf_get(lpfc_trailer_type, acqe_sli)); | |
3978 | return; | |
3979 | } | |
3980 | ||
3981 | port_name = phba->Port[0]; | |
3982 | if (port_name == 0x00) | |
3983 | port_name = '?'; /* get port name is empty */ | |
3984 | ||
3985 | misconfigured = (struct lpfc_acqe_misconfigured_event *) | |
3986 | &acqe_sli->event_data1; | |
3987 | ||
3988 | /* fetch the status for this port */ | |
3989 | switch (phba->sli4_hba.lnk_info.lnk_no) { | |
3990 | case LPFC_LINK_NUMBER_0: | |
3991 | status = bf_get(lpfc_sli_misconfigured_port0, | |
3992 | &misconfigured->theEvent); | |
3993 | break; | |
3994 | case LPFC_LINK_NUMBER_1: | |
3995 | status = bf_get(lpfc_sli_misconfigured_port1, | |
3996 | &misconfigured->theEvent); | |
3997 | break; | |
3998 | case LPFC_LINK_NUMBER_2: | |
3999 | status = bf_get(lpfc_sli_misconfigured_port2, | |
4000 | &misconfigured->theEvent); | |
4001 | break; | |
4002 | case LPFC_LINK_NUMBER_3: | |
4003 | status = bf_get(lpfc_sli_misconfigured_port3, | |
4004 | &misconfigured->theEvent); | |
4005 | break; | |
4006 | default: | |
4007 | status = ~LPFC_SLI_EVENT_STATUS_VALID; | |
4008 | break; | |
4009 | } | |
4010 | ||
4011 | switch (status) { | |
4012 | case LPFC_SLI_EVENT_STATUS_VALID: | |
4013 | return; /* no message if the sfp is okay */ | |
4014 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: | |
292098be JS |
4015 | sprintf(message, "Optics faulted/incorrectly installed/not " \ |
4016 | "installed - Reseat optics, if issue not " | |
4017 | "resolved, replace."); | |
4b8bae08 JS |
4018 | break; |
4019 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: | |
4020 | sprintf(message, | |
292098be JS |
4021 | "Optics of two types installed - Remove one optic or " \ |
4022 | "install matching pair of optics."); | |
4b8bae08 JS |
4023 | break; |
4024 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: | |
292098be JS |
4025 | sprintf(message, "Incompatible optics - Replace with " \ |
4026 | "compatible optics for card to function."); | |
4b8bae08 JS |
4027 | break; |
4028 | default: | |
4029 | /* firmware is reporting a status we don't know about */ | |
4030 | sprintf(message, "Unknown event status x%02x", status); | |
4031 | break; | |
4032 | } | |
4033 | ||
4034 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4035 | "3176 Misconfigured Physical Port - " | |
4036 | "Port Name %c %s\n", port_name, message); | |
70f3c073 JS |
4037 | } |
4038 | ||
fc2b989b JS |
4039 | /** |
4040 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport | |
4041 | * @vport: pointer to vport data structure. | |
4042 | * | |
4043 | * This routine is to perform Clear Virtual Link (CVL) on a vport in | |
4044 | * response to a CVL event. | |
4045 | * | |
4046 | * Return the pointer to the ndlp with the vport if successful, otherwise | |
4047 | * return NULL. | |
4048 | **/ | |
4049 | static struct lpfc_nodelist * | |
4050 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) | |
4051 | { | |
4052 | struct lpfc_nodelist *ndlp; | |
4053 | struct Scsi_Host *shost; | |
4054 | struct lpfc_hba *phba; | |
4055 | ||
4056 | if (!vport) | |
4057 | return NULL; | |
fc2b989b JS |
4058 | phba = vport->phba; |
4059 | if (!phba) | |
4060 | return NULL; | |
78730cfe JS |
4061 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
4062 | if (!ndlp) { | |
4063 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | |
4064 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
4065 | if (!ndlp) | |
4066 | return 0; | |
4067 | lpfc_nlp_init(vport, ndlp, Fabric_DID); | |
4068 | /* Set the node type */ | |
4069 | ndlp->nlp_type |= NLP_FABRIC; | |
4070 | /* Put ndlp onto node list */ | |
4071 | lpfc_enqueue_node(vport, ndlp); | |
4072 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
4073 | /* re-setup ndlp without removing from node list */ | |
4074 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
4075 | if (!ndlp) | |
4076 | return 0; | |
4077 | } | |
63e801ce JS |
4078 | if ((phba->pport->port_state < LPFC_FLOGI) && |
4079 | (phba->pport->port_state != LPFC_VPORT_FAILED)) | |
fc2b989b JS |
4080 | return NULL; |
4081 | /* If virtual link is not yet instantiated ignore CVL */ | |
63e801ce JS |
4082 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
4083 | && (vport->port_state != LPFC_VPORT_FAILED)) | |
fc2b989b JS |
4084 | return NULL; |
4085 | shost = lpfc_shost_from_vport(vport); | |
4086 | if (!shost) | |
4087 | return NULL; | |
4088 | lpfc_linkdown_port(vport); | |
4089 | lpfc_cleanup_pending_mbox(vport); | |
4090 | spin_lock_irq(shost->host_lock); | |
4091 | vport->fc_flag |= FC_VPORT_CVL_RCVD; | |
4092 | spin_unlock_irq(shost->host_lock); | |
4093 | ||
4094 | return ndlp; | |
4095 | } | |
4096 | ||
4097 | /** | |
4098 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports | |
4099 | * @vport: pointer to lpfc hba data structure. | |
4100 | * | |
4101 | * This routine is to perform Clear Virtual Link (CVL) on all vports in | |
4102 | * response to a FCF dead event. | |
4103 | **/ | |
4104 | static void | |
4105 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) | |
4106 | { | |
4107 | struct lpfc_vport **vports; | |
4108 | int i; | |
4109 | ||
4110 | vports = lpfc_create_vport_work_array(phba); | |
4111 | if (vports) | |
4112 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) | |
4113 | lpfc_sli4_perform_vport_cvl(vports[i]); | |
4114 | lpfc_destroy_vport_work_array(phba, vports); | |
4115 | } | |
4116 | ||
da0436e9 | 4117 | /** |
76a95d75 | 4118 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
da0436e9 JS |
4119 | * @phba: pointer to lpfc hba data structure. |
4120 | * @acqe_link: pointer to the async fcoe completion queue entry. | |
4121 | * | |
4122 | * This routine is to handle the SLI4 asynchronous fcoe event. | |
4123 | **/ | |
4124 | static void | |
76a95d75 | 4125 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
70f3c073 | 4126 | struct lpfc_acqe_fip *acqe_fip) |
da0436e9 | 4127 | { |
70f3c073 | 4128 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
da0436e9 | 4129 | int rc; |
6669f9bb JS |
4130 | struct lpfc_vport *vport; |
4131 | struct lpfc_nodelist *ndlp; | |
4132 | struct Scsi_Host *shost; | |
695a814e JS |
4133 | int active_vlink_present; |
4134 | struct lpfc_vport **vports; | |
4135 | int i; | |
da0436e9 | 4136 | |
70f3c073 JS |
4137 | phba->fc_eventTag = acqe_fip->event_tag; |
4138 | phba->fcoe_eventtag = acqe_fip->event_tag; | |
da0436e9 | 4139 | switch (event_type) { |
70f3c073 JS |
4140 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
4141 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: | |
4142 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) | |
999d813f JS |
4143 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
4144 | LOG_DISCOVERY, | |
a93ff37a JS |
4145 | "2546 New FCF event, evt_tag:x%x, " |
4146 | "index:x%x\n", | |
70f3c073 JS |
4147 | acqe_fip->event_tag, |
4148 | acqe_fip->index); | |
999d813f JS |
4149 | else |
4150 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | | |
4151 | LOG_DISCOVERY, | |
a93ff37a JS |
4152 | "2788 FCF param modified event, " |
4153 | "evt_tag:x%x, index:x%x\n", | |
70f3c073 JS |
4154 | acqe_fip->event_tag, |
4155 | acqe_fip->index); | |
38b92ef8 | 4156 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
0c9ab6f5 JS |
4157 | /* |
4158 | * During period of FCF discovery, read the FCF | |
4159 | * table record indexed by the event to update | |
a93ff37a | 4160 | * FCF roundrobin failover eligible FCF bmask. |
0c9ab6f5 JS |
4161 | */ |
4162 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | | |
4163 | LOG_DISCOVERY, | |
a93ff37a JS |
4164 | "2779 Read FCF (x%x) for updating " |
4165 | "roundrobin FCF failover bmask\n", | |
70f3c073 JS |
4166 | acqe_fip->index); |
4167 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); | |
0c9ab6f5 | 4168 | } |
38b92ef8 JS |
4169 | |
4170 | /* If the FCF discovery is in progress, do nothing. */ | |
3804dc84 | 4171 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 4172 | if (phba->hba_flag & FCF_TS_INPROG) { |
38b92ef8 JS |
4173 | spin_unlock_irq(&phba->hbalock); |
4174 | break; | |
4175 | } | |
4176 | /* If fast FCF failover rescan event is pending, do nothing */ | |
4177 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { | |
4178 | spin_unlock_irq(&phba->hbalock); | |
4179 | break; | |
4180 | } | |
4181 | ||
c2b9712e JS |
4182 | /* If the FCF has been in discovered state, do nothing. */ |
4183 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { | |
3804dc84 JS |
4184 | spin_unlock_irq(&phba->hbalock); |
4185 | break; | |
4186 | } | |
4187 | spin_unlock_irq(&phba->hbalock); | |
38b92ef8 | 4188 | |
0c9ab6f5 JS |
4189 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
4190 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, | |
a93ff37a JS |
4191 | "2770 Start FCF table scan per async FCF " |
4192 | "event, evt_tag:x%x, index:x%x\n", | |
70f3c073 | 4193 | acqe_fip->event_tag, acqe_fip->index); |
0c9ab6f5 JS |
4194 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
4195 | LPFC_FCOE_FCF_GET_FIRST); | |
da0436e9 | 4196 | if (rc) |
0c9ab6f5 JS |
4197 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
4198 | "2547 Issue FCF scan read FCF mailbox " | |
a93ff37a | 4199 | "command failed (x%x)\n", rc); |
da0436e9 JS |
4200 | break; |
4201 | ||
70f3c073 | 4202 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
da0436e9 | 4203 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e4e74273 | 4204 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
70f3c073 JS |
4205 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
4206 | acqe_fip->event_tag); | |
da0436e9 JS |
4207 | break; |
4208 | ||
70f3c073 | 4209 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
80c17849 | 4210 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
0c9ab6f5 | 4211 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
a93ff37a | 4212 | "2549 FCF (x%x) disconnected from network, " |
70f3c073 | 4213 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
38b92ef8 JS |
4214 | /* |
4215 | * If we are in the middle of FCF failover process, clear | |
4216 | * the corresponding FCF bit in the roundrobin bitmap. | |
da0436e9 | 4217 | */ |
fc2b989b | 4218 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 4219 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
fc2b989b | 4220 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 | 4221 | /* Update FLOGI FCF failover eligible FCF bmask */ |
70f3c073 | 4222 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
fc2b989b JS |
4223 | break; |
4224 | } | |
38b92ef8 JS |
4225 | spin_unlock_irq(&phba->hbalock); |
4226 | ||
4227 | /* If the event is not for currently used fcf do nothing */ | |
70f3c073 | 4228 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
38b92ef8 JS |
4229 | break; |
4230 | ||
4231 | /* | |
4232 | * Otherwise, request the port to rediscover the entire FCF | |
4233 | * table for a fast recovery from case that the current FCF | |
4234 | * is no longer valid as we are not in the middle of FCF | |
4235 | * failover process already. | |
4236 | */ | |
c2b9712e JS |
4237 | spin_lock_irq(&phba->hbalock); |
4238 | /* Mark the fast failover process in progress */ | |
4239 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; | |
4240 | spin_unlock_irq(&phba->hbalock); | |
4241 | ||
4242 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, | |
4243 | "2771 Start FCF fast failover process due to " | |
4244 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " | |
4245 | "\n", acqe_fip->event_tag, acqe_fip->index); | |
4246 | rc = lpfc_sli4_redisc_fcf_table(phba); | |
4247 | if (rc) { | |
4248 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | | |
4249 | LOG_DISCOVERY, | |
4250 | "2772 Issue FCF rediscover mabilbox " | |
4251 | "command failed, fail through to FCF " | |
4252 | "dead event\n"); | |
4253 | spin_lock_irq(&phba->hbalock); | |
4254 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; | |
4255 | spin_unlock_irq(&phba->hbalock); | |
4256 | /* | |
4257 | * Last resort will fail over by treating this | |
4258 | * as a link down to FCF registration. | |
4259 | */ | |
4260 | lpfc_sli4_fcf_dead_failthrough(phba); | |
4261 | } else { | |
4262 | /* Reset FCF roundrobin bmask for new discovery */ | |
4263 | lpfc_sli4_clear_fcf_rr_bmask(phba); | |
4264 | /* | |
4265 | * Handling fast FCF failover to a DEAD FCF event is | |
4266 | * considered equalivant to receiving CVL to all vports. | |
4267 | */ | |
4268 | lpfc_sli4_perform_all_vport_cvl(phba); | |
4269 | } | |
da0436e9 | 4270 | break; |
70f3c073 | 4271 | case LPFC_FIP_EVENT_TYPE_CVL: |
80c17849 | 4272 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
0c9ab6f5 | 4273 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
6669f9bb | 4274 | "2718 Clear Virtual Link Received for VPI 0x%x" |
70f3c073 | 4275 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
6d368e53 | 4276 | |
6669f9bb | 4277 | vport = lpfc_find_vport_by_vpid(phba, |
5248a749 | 4278 | acqe_fip->index); |
fc2b989b | 4279 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
6669f9bb JS |
4280 | if (!ndlp) |
4281 | break; | |
695a814e JS |
4282 | active_vlink_present = 0; |
4283 | ||
4284 | vports = lpfc_create_vport_work_array(phba); | |
4285 | if (vports) { | |
4286 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; | |
4287 | i++) { | |
4288 | if ((!(vports[i]->fc_flag & | |
4289 | FC_VPORT_CVL_RCVD)) && | |
4290 | (vports[i]->port_state > LPFC_FDISC)) { | |
4291 | active_vlink_present = 1; | |
4292 | break; | |
4293 | } | |
4294 | } | |
4295 | lpfc_destroy_vport_work_array(phba, vports); | |
4296 | } | |
4297 | ||
4298 | if (active_vlink_present) { | |
4299 | /* | |
4300 | * If there are other active VLinks present, | |
4301 | * re-instantiate the Vlink using FDISC. | |
4302 | */ | |
256ec0d0 JS |
4303 | mod_timer(&ndlp->nlp_delayfunc, |
4304 | jiffies + msecs_to_jiffies(1000)); | |
fc2b989b | 4305 | shost = lpfc_shost_from_vport(vport); |
6669f9bb JS |
4306 | spin_lock_irq(shost->host_lock); |
4307 | ndlp->nlp_flag |= NLP_DELAY_TMO; | |
4308 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
4309 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
4310 | vport->port_state = LPFC_FDISC; | |
4311 | } else { | |
ecfd03c6 JS |
4312 | /* |
4313 | * Otherwise, we request port to rediscover | |
4314 | * the entire FCF table for a fast recovery | |
4315 | * from possible case that the current FCF | |
0c9ab6f5 JS |
4316 | * is no longer valid if we are not already |
4317 | * in the FCF failover process. | |
ecfd03c6 | 4318 | */ |
fc2b989b | 4319 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 4320 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
fc2b989b JS |
4321 | spin_unlock_irq(&phba->hbalock); |
4322 | break; | |
4323 | } | |
4324 | /* Mark the fast failover process in progress */ | |
0c9ab6f5 | 4325 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
fc2b989b | 4326 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 JS |
4327 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
4328 | LOG_DISCOVERY, | |
a93ff37a | 4329 | "2773 Start FCF failover per CVL, " |
70f3c073 | 4330 | "evt_tag:x%x\n", acqe_fip->event_tag); |
ecfd03c6 | 4331 | rc = lpfc_sli4_redisc_fcf_table(phba); |
fc2b989b | 4332 | if (rc) { |
0c9ab6f5 JS |
4333 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
4334 | LOG_DISCOVERY, | |
4335 | "2774 Issue FCF rediscover " | |
4336 | "mabilbox command failed, " | |
4337 | "through to CVL event\n"); | |
fc2b989b | 4338 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 4339 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b | 4340 | spin_unlock_irq(&phba->hbalock); |
ecfd03c6 JS |
4341 | /* |
4342 | * Last resort will be re-try on the | |
4343 | * the current registered FCF entry. | |
4344 | */ | |
4345 | lpfc_retry_pport_discovery(phba); | |
38b92ef8 JS |
4346 | } else |
4347 | /* | |
4348 | * Reset FCF roundrobin bmask for new | |
4349 | * discovery. | |
4350 | */ | |
7d791df7 | 4351 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
6669f9bb JS |
4352 | } |
4353 | break; | |
da0436e9 JS |
4354 | default: |
4355 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4356 | "0288 Unknown FCoE event type 0x%x event tag " | |
70f3c073 | 4357 | "0x%x\n", event_type, acqe_fip->event_tag); |
da0436e9 JS |
4358 | break; |
4359 | } | |
4360 | } | |
4361 | ||
4362 | /** | |
4363 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event | |
4364 | * @phba: pointer to lpfc hba data structure. | |
4365 | * @acqe_link: pointer to the async dcbx completion queue entry. | |
4366 | * | |
4367 | * This routine is to handle the SLI4 asynchronous dcbx event. | |
4368 | **/ | |
4369 | static void | |
4370 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, | |
4371 | struct lpfc_acqe_dcbx *acqe_dcbx) | |
4372 | { | |
4d9ab994 | 4373 | phba->fc_eventTag = acqe_dcbx->event_tag; |
da0436e9 JS |
4374 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
4375 | "0290 The SLI4 DCBX asynchronous event is not " | |
4376 | "handled yet\n"); | |
4377 | } | |
4378 | ||
b19a061a JS |
4379 | /** |
4380 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event | |
4381 | * @phba: pointer to lpfc hba data structure. | |
4382 | * @acqe_link: pointer to the async grp5 completion queue entry. | |
4383 | * | |
4384 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event | |
4385 | * is an asynchronous notified of a logical link speed change. The Port | |
4386 | * reports the logical link speed in units of 10Mbps. | |
4387 | **/ | |
4388 | static void | |
4389 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, | |
4390 | struct lpfc_acqe_grp5 *acqe_grp5) | |
4391 | { | |
4392 | uint16_t prev_ll_spd; | |
4393 | ||
4394 | phba->fc_eventTag = acqe_grp5->event_tag; | |
4395 | phba->fcoe_eventtag = acqe_grp5->event_tag; | |
4396 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; | |
4397 | phba->sli4_hba.link_state.logical_speed = | |
8b68cd52 | 4398 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)) * 10; |
b19a061a JS |
4399 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, |
4400 | "2789 GRP5 Async Event: Updating logical link speed " | |
8b68cd52 JS |
4401 | "from %dMbps to %dMbps\n", prev_ll_spd, |
4402 | phba->sli4_hba.link_state.logical_speed); | |
b19a061a JS |
4403 | } |
4404 | ||
da0436e9 JS |
4405 | /** |
4406 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event | |
4407 | * @phba: pointer to lpfc hba data structure. | |
4408 | * | |
4409 | * This routine is invoked by the worker thread to process all the pending | |
4410 | * SLI4 asynchronous events. | |
4411 | **/ | |
4412 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) | |
4413 | { | |
4414 | struct lpfc_cq_event *cq_event; | |
4415 | ||
4416 | /* First, declare the async event has been handled */ | |
4417 | spin_lock_irq(&phba->hbalock); | |
4418 | phba->hba_flag &= ~ASYNC_EVENT; | |
4419 | spin_unlock_irq(&phba->hbalock); | |
4420 | /* Now, handle all the async events */ | |
4421 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { | |
4422 | /* Get the first event from the head of the event queue */ | |
4423 | spin_lock_irq(&phba->hbalock); | |
4424 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, | |
4425 | cq_event, struct lpfc_cq_event, list); | |
4426 | spin_unlock_irq(&phba->hbalock); | |
4427 | /* Process the asynchronous event */ | |
4428 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { | |
4429 | case LPFC_TRAILER_CODE_LINK: | |
4430 | lpfc_sli4_async_link_evt(phba, | |
4431 | &cq_event->cqe.acqe_link); | |
4432 | break; | |
4433 | case LPFC_TRAILER_CODE_FCOE: | |
70f3c073 | 4434 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
da0436e9 JS |
4435 | break; |
4436 | case LPFC_TRAILER_CODE_DCBX: | |
4437 | lpfc_sli4_async_dcbx_evt(phba, | |
4438 | &cq_event->cqe.acqe_dcbx); | |
4439 | break; | |
b19a061a JS |
4440 | case LPFC_TRAILER_CODE_GRP5: |
4441 | lpfc_sli4_async_grp5_evt(phba, | |
4442 | &cq_event->cqe.acqe_grp5); | |
4443 | break; | |
70f3c073 JS |
4444 | case LPFC_TRAILER_CODE_FC: |
4445 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); | |
4446 | break; | |
4447 | case LPFC_TRAILER_CODE_SLI: | |
4448 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); | |
4449 | break; | |
da0436e9 JS |
4450 | default: |
4451 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4452 | "1804 Invalid asynchrous event code: " | |
4453 | "x%x\n", bf_get(lpfc_trailer_code, | |
4454 | &cq_event->cqe.mcqe_cmpl)); | |
4455 | break; | |
4456 | } | |
4457 | /* Free the completion event processed to the free pool */ | |
4458 | lpfc_sli4_cq_event_release(phba, cq_event); | |
4459 | } | |
4460 | } | |
4461 | ||
ecfd03c6 JS |
4462 | /** |
4463 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event | |
4464 | * @phba: pointer to lpfc hba data structure. | |
4465 | * | |
4466 | * This routine is invoked by the worker thread to process FCF table | |
4467 | * rediscovery pending completion event. | |
4468 | **/ | |
4469 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) | |
4470 | { | |
4471 | int rc; | |
4472 | ||
4473 | spin_lock_irq(&phba->hbalock); | |
4474 | /* Clear FCF rediscovery timeout event */ | |
4475 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; | |
4476 | /* Clear driver fast failover FCF record flag */ | |
4477 | phba->fcf.failover_rec.flag = 0; | |
4478 | /* Set state for FCF fast failover */ | |
4479 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; | |
4480 | spin_unlock_irq(&phba->hbalock); | |
4481 | ||
4482 | /* Scan FCF table from the first entry to re-discover SAN */ | |
0c9ab6f5 | 4483 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
a93ff37a | 4484 | "2777 Start post-quiescent FCF table scan\n"); |
0c9ab6f5 | 4485 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
ecfd03c6 | 4486 | if (rc) |
0c9ab6f5 JS |
4487 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
4488 | "2747 Issue FCF scan read FCF mailbox " | |
4489 | "command failed 0x%x\n", rc); | |
ecfd03c6 JS |
4490 | } |
4491 | ||
da0436e9 JS |
4492 | /** |
4493 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table | |
4494 | * @phba: pointer to lpfc hba data structure. | |
4495 | * @dev_grp: The HBA PCI-Device group number. | |
4496 | * | |
4497 | * This routine is invoked to set up the per HBA PCI-Device group function | |
4498 | * API jump table entries. | |
4499 | * | |
4500 | * Return: 0 if success, otherwise -ENODEV | |
4501 | **/ | |
4502 | int | |
4503 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
4504 | { | |
4505 | int rc; | |
4506 | ||
4507 | /* Set up lpfc PCI-device group */ | |
4508 | phba->pci_dev_grp = dev_grp; | |
4509 | ||
4510 | /* The LPFC_PCI_DEV_OC uses SLI4 */ | |
4511 | if (dev_grp == LPFC_PCI_DEV_OC) | |
4512 | phba->sli_rev = LPFC_SLI_REV4; | |
4513 | ||
4514 | /* Set up device INIT API function jump table */ | |
4515 | rc = lpfc_init_api_table_setup(phba, dev_grp); | |
4516 | if (rc) | |
4517 | return -ENODEV; | |
4518 | /* Set up SCSI API function jump table */ | |
4519 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); | |
4520 | if (rc) | |
4521 | return -ENODEV; | |
4522 | /* Set up SLI API function jump table */ | |
4523 | rc = lpfc_sli_api_table_setup(phba, dev_grp); | |
4524 | if (rc) | |
4525 | return -ENODEV; | |
4526 | /* Set up MBOX API function jump table */ | |
4527 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); | |
4528 | if (rc) | |
4529 | return -ENODEV; | |
4530 | ||
4531 | return 0; | |
5b75da2f JS |
4532 | } |
4533 | ||
4534 | /** | |
3621a710 | 4535 | * lpfc_log_intr_mode - Log the active interrupt mode |
5b75da2f JS |
4536 | * @phba: pointer to lpfc hba data structure. |
4537 | * @intr_mode: active interrupt mode adopted. | |
4538 | * | |
4539 | * This routine it invoked to log the currently used active interrupt mode | |
4540 | * to the device. | |
3772a991 JS |
4541 | **/ |
4542 | static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode) | |
5b75da2f JS |
4543 | { |
4544 | switch (intr_mode) { | |
4545 | case 0: | |
4546 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4547 | "0470 Enable INTx interrupt mode.\n"); | |
4548 | break; | |
4549 | case 1: | |
4550 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4551 | "0481 Enabled MSI interrupt mode.\n"); | |
4552 | break; | |
4553 | case 2: | |
4554 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4555 | "0480 Enabled MSI-X interrupt mode.\n"); | |
4556 | break; | |
4557 | default: | |
4558 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4559 | "0482 Illegal interrupt mode.\n"); | |
4560 | break; | |
4561 | } | |
4562 | return; | |
4563 | } | |
4564 | ||
5b75da2f | 4565 | /** |
3772a991 | 4566 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
5b75da2f JS |
4567 | * @phba: pointer to lpfc hba data structure. |
4568 | * | |
3772a991 JS |
4569 | * This routine is invoked to enable the PCI device that is common to all |
4570 | * PCI devices. | |
5b75da2f JS |
4571 | * |
4572 | * Return codes | |
af901ca1 | 4573 | * 0 - successful |
3772a991 | 4574 | * other values - error |
5b75da2f | 4575 | **/ |
3772a991 JS |
4576 | static int |
4577 | lpfc_enable_pci_dev(struct lpfc_hba *phba) | |
5b75da2f | 4578 | { |
3772a991 | 4579 | struct pci_dev *pdev; |
079b5c91 | 4580 | int bars = 0; |
5b75da2f | 4581 | |
3772a991 JS |
4582 | /* Obtain PCI device reference */ |
4583 | if (!phba->pcidev) | |
4584 | goto out_error; | |
4585 | else | |
4586 | pdev = phba->pcidev; | |
4587 | /* Select PCI BARs */ | |
4588 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
4589 | /* Enable PCI device */ | |
4590 | if (pci_enable_device_mem(pdev)) | |
4591 | goto out_error; | |
4592 | /* Request PCI resource for the device */ | |
4593 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) | |
4594 | goto out_disable_device; | |
4595 | /* Set up device as PCI master and save state for EEH */ | |
4596 | pci_set_master(pdev); | |
4597 | pci_try_set_mwi(pdev); | |
4598 | pci_save_state(pdev); | |
5b75da2f | 4599 | |
0558056c | 4600 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
453193e0 | 4601 | if (pci_is_pcie(pdev)) |
0558056c JS |
4602 | pdev->needs_freset = 1; |
4603 | ||
3772a991 | 4604 | return 0; |
5b75da2f | 4605 | |
3772a991 JS |
4606 | out_disable_device: |
4607 | pci_disable_device(pdev); | |
4608 | out_error: | |
079b5c91 JS |
4609 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
4610 | "1401 Failed to enable pci device, bars:x%x\n", bars); | |
3772a991 | 4611 | return -ENODEV; |
5b75da2f JS |
4612 | } |
4613 | ||
4614 | /** | |
3772a991 | 4615 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
5b75da2f JS |
4616 | * @phba: pointer to lpfc hba data structure. |
4617 | * | |
3772a991 JS |
4618 | * This routine is invoked to disable the PCI device that is common to all |
4619 | * PCI devices. | |
5b75da2f JS |
4620 | **/ |
4621 | static void | |
3772a991 | 4622 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
5b75da2f | 4623 | { |
3772a991 JS |
4624 | struct pci_dev *pdev; |
4625 | int bars; | |
5b75da2f | 4626 | |
3772a991 JS |
4627 | /* Obtain PCI device reference */ |
4628 | if (!phba->pcidev) | |
4629 | return; | |
4630 | else | |
4631 | pdev = phba->pcidev; | |
4632 | /* Select PCI BARs */ | |
4633 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
4634 | /* Release PCI resource and disable PCI device */ | |
4635 | pci_release_selected_regions(pdev, bars); | |
4636 | pci_disable_device(pdev); | |
5b75da2f JS |
4637 | |
4638 | return; | |
4639 | } | |
4640 | ||
e59058c4 | 4641 | /** |
3772a991 JS |
4642 | * lpfc_reset_hba - Reset a hba |
4643 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 4644 | * |
3772a991 JS |
4645 | * This routine is invoked to reset a hba device. It brings the HBA |
4646 | * offline, performs a board restart, and then brings the board back | |
4647 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up | |
4648 | * on outstanding mailbox commands. | |
e59058c4 | 4649 | **/ |
3772a991 JS |
4650 | void |
4651 | lpfc_reset_hba(struct lpfc_hba *phba) | |
dea3101e | 4652 | { |
3772a991 JS |
4653 | /* If resets are disabled then set error state and return. */ |
4654 | if (!phba->cfg_enable_hba_reset) { | |
4655 | phba->link_state = LPFC_HBA_ERROR; | |
4656 | return; | |
4657 | } | |
618a5230 | 4658 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
3772a991 JS |
4659 | lpfc_offline(phba); |
4660 | lpfc_sli_brdrestart(phba); | |
4661 | lpfc_online(phba); | |
4662 | lpfc_unblock_mgmt_io(phba); | |
4663 | } | |
dea3101e | 4664 | |
0a96e975 JS |
4665 | /** |
4666 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions | |
4667 | * @phba: pointer to lpfc hba data structure. | |
4668 | * | |
4669 | * This function enables the PCI SR-IOV virtual functions to a physical | |
4670 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to | |
4671 | * enable the number of virtual functions to the physical function. As | |
4672 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() | |
4673 | * API call does not considered as an error condition for most of the device. | |
4674 | **/ | |
4675 | uint16_t | |
4676 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) | |
4677 | { | |
4678 | struct pci_dev *pdev = phba->pcidev; | |
4679 | uint16_t nr_virtfn; | |
4680 | int pos; | |
4681 | ||
0a96e975 JS |
4682 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
4683 | if (pos == 0) | |
4684 | return 0; | |
4685 | ||
4686 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); | |
4687 | return nr_virtfn; | |
4688 | } | |
4689 | ||
912e3acd JS |
4690 | /** |
4691 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions | |
4692 | * @phba: pointer to lpfc hba data structure. | |
4693 | * @nr_vfn: number of virtual functions to be enabled. | |
4694 | * | |
4695 | * This function enables the PCI SR-IOV virtual functions to a physical | |
4696 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to | |
4697 | * enable the number of virtual functions to the physical function. As | |
4698 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() | |
4699 | * API call does not considered as an error condition for most of the device. | |
4700 | **/ | |
4701 | int | |
4702 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) | |
4703 | { | |
4704 | struct pci_dev *pdev = phba->pcidev; | |
0a96e975 | 4705 | uint16_t max_nr_vfn; |
912e3acd JS |
4706 | int rc; |
4707 | ||
0a96e975 JS |
4708 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
4709 | if (nr_vfn > max_nr_vfn) { | |
4710 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4711 | "3057 Requested vfs (%d) greater than " | |
4712 | "supported vfs (%d)", nr_vfn, max_nr_vfn); | |
4713 | return -EINVAL; | |
4714 | } | |
4715 | ||
912e3acd JS |
4716 | rc = pci_enable_sriov(pdev, nr_vfn); |
4717 | if (rc) { | |
4718 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4719 | "2806 Failed to enable sriov on this device " | |
4720 | "with vfn number nr_vf:%d, rc:%d\n", | |
4721 | nr_vfn, rc); | |
4722 | } else | |
4723 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4724 | "2807 Successful enable sriov on this device " | |
4725 | "with vfn number nr_vf:%d\n", nr_vfn); | |
4726 | return rc; | |
4727 | } | |
4728 | ||
3772a991 JS |
4729 | /** |
4730 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. | |
4731 | * @phba: pointer to lpfc hba data structure. | |
4732 | * | |
4733 | * This routine is invoked to set up the driver internal resources specific to | |
4734 | * support the SLI-3 HBA device it attached to. | |
4735 | * | |
4736 | * Return codes | |
af901ca1 | 4737 | * 0 - successful |
3772a991 JS |
4738 | * other values - error |
4739 | **/ | |
4740 | static int | |
4741 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) | |
4742 | { | |
4743 | struct lpfc_sli *psli; | |
912e3acd | 4744 | int rc; |
dea3101e | 4745 | |
2e0fef85 | 4746 | /* |
3772a991 | 4747 | * Initialize timers used by driver |
2e0fef85 | 4748 | */ |
dea3101e | 4749 | |
3772a991 | 4750 | /* Heartbeat timer */ |
858c9f6c JS |
4751 | init_timer(&phba->hb_tmofunc); |
4752 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
4753 | phba->hb_tmofunc.data = (unsigned long)phba; | |
4754 | ||
dea3101e | 4755 | psli = &phba->sli; |
3772a991 | 4756 | /* MBOX heartbeat timer */ |
dea3101e JB |
4757 | init_timer(&psli->mbox_tmo); |
4758 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
2e0fef85 | 4759 | psli->mbox_tmo.data = (unsigned long) phba; |
3772a991 | 4760 | /* FCP polling mode timer */ |
875fbdfe JSEC |
4761 | init_timer(&phba->fcp_poll_timer); |
4762 | phba->fcp_poll_timer.function = lpfc_poll_timeout; | |
2e0fef85 | 4763 | phba->fcp_poll_timer.data = (unsigned long) phba; |
3772a991 | 4764 | /* Fabric block timer */ |
92d7f7b0 JS |
4765 | init_timer(&phba->fabric_block_timer); |
4766 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
4767 | phba->fabric_block_timer.data = (unsigned long) phba; | |
3772a991 | 4768 | /* EA polling mode timer */ |
9399627f JS |
4769 | init_timer(&phba->eratt_poll); |
4770 | phba->eratt_poll.function = lpfc_poll_eratt; | |
4771 | phba->eratt_poll.data = (unsigned long) phba; | |
dea3101e | 4772 | |
3772a991 JS |
4773 | /* Host attention work mask setup */ |
4774 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); | |
4775 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); | |
dea3101e | 4776 | |
3772a991 JS |
4777 | /* Get all the module params for configuring this host */ |
4778 | lpfc_get_cfgparam(phba); | |
49198b37 JS |
4779 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
4780 | phba->menlo_flag |= HBA_MENLO_SUPPORT; | |
4781 | /* check for menlo minimum sg count */ | |
4782 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) | |
4783 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; | |
4784 | } | |
4785 | ||
2a76a283 JS |
4786 | if (!phba->sli.ring) |
4787 | phba->sli.ring = (struct lpfc_sli_ring *) | |
4788 | kzalloc(LPFC_SLI3_MAX_RING * | |
4789 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); | |
4790 | if (!phba->sli.ring) | |
4791 | return -ENOMEM; | |
4792 | ||
dea3101e | 4793 | /* |
96f7077f | 4794 | * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size |
3772a991 | 4795 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
dea3101e | 4796 | */ |
3772a991 | 4797 | |
96f7077f JS |
4798 | /* Initialize the host templates the configured values. */ |
4799 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
4800 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
4801 | ||
4802 | /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */ | |
3772a991 | 4803 | if (phba->cfg_enable_bg) { |
96f7077f JS |
4804 | /* |
4805 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, | |
4806 | * the FCP rsp, and a BDE for each. Sice we have no control | |
4807 | * over how many protection data segments the SCSI Layer | |
4808 | * will hand us (ie: there could be one for every block | |
4809 | * in the IO), we just allocate enough BDEs to accomidate | |
4810 | * our max amount and we need to limit lpfc_sg_seg_cnt to | |
4811 | * minimize the risk of running out. | |
4812 | */ | |
4813 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + | |
4814 | sizeof(struct fcp_rsp) + | |
4815 | (LPFC_MAX_SG_SEG_CNT * sizeof(struct ulp_bde64)); | |
4816 | ||
4817 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SEG_CNT_DIF) | |
4818 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT_DIF; | |
4819 | ||
4820 | /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */ | |
4821 | phba->cfg_total_seg_cnt = LPFC_MAX_SG_SEG_CNT; | |
4822 | } else { | |
4823 | /* | |
4824 | * The scsi_buf for a regular I/O will hold the FCP cmnd, | |
4825 | * the FCP rsp, a BDE for each, and a BDE for up to | |
4826 | * cfg_sg_seg_cnt data segments. | |
4827 | */ | |
4828 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + | |
4829 | sizeof(struct fcp_rsp) + | |
4830 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); | |
4831 | ||
4832 | /* Total BDEs in BPL for scsi_sg_list */ | |
4833 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; | |
901a920f | 4834 | } |
dea3101e | 4835 | |
96f7077f JS |
4836 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, |
4837 | "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n", | |
4838 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, | |
4839 | phba->cfg_total_seg_cnt); | |
dea3101e | 4840 | |
3772a991 JS |
4841 | phba->max_vpi = LPFC_MAX_VPI; |
4842 | /* This will be set to correct value after config_port mbox */ | |
4843 | phba->max_vports = 0; | |
dea3101e | 4844 | |
3772a991 JS |
4845 | /* |
4846 | * Initialize the SLI Layer to run with lpfc HBAs. | |
4847 | */ | |
4848 | lpfc_sli_setup(phba); | |
4849 | lpfc_sli_queue_setup(phba); | |
ed957684 | 4850 | |
3772a991 JS |
4851 | /* Allocate device driver memory */ |
4852 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) | |
4853 | return -ENOMEM; | |
51ef4c26 | 4854 | |
912e3acd JS |
4855 | /* |
4856 | * Enable sr-iov virtual functions if supported and configured | |
4857 | * through the module parameter. | |
4858 | */ | |
4859 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
4860 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, | |
4861 | phba->cfg_sriov_nr_virtfn); | |
4862 | if (rc) { | |
4863 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4864 | "2808 Requested number of SR-IOV " | |
4865 | "virtual functions (%d) is not " | |
4866 | "supported\n", | |
4867 | phba->cfg_sriov_nr_virtfn); | |
4868 | phba->cfg_sriov_nr_virtfn = 0; | |
4869 | } | |
4870 | } | |
4871 | ||
3772a991 JS |
4872 | return 0; |
4873 | } | |
ed957684 | 4874 | |
3772a991 JS |
4875 | /** |
4876 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev | |
4877 | * @phba: pointer to lpfc hba data structure. | |
4878 | * | |
4879 | * This routine is invoked to unset the driver internal resources set up | |
4880 | * specific for supporting the SLI-3 HBA device it attached to. | |
4881 | **/ | |
4882 | static void | |
4883 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) | |
4884 | { | |
4885 | /* Free device driver memory allocated */ | |
4886 | lpfc_mem_free_all(phba); | |
3163f725 | 4887 | |
3772a991 JS |
4888 | return; |
4889 | } | |
dea3101e | 4890 | |
3772a991 | 4891 | /** |
da0436e9 | 4892 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
3772a991 JS |
4893 | * @phba: pointer to lpfc hba data structure. |
4894 | * | |
da0436e9 JS |
4895 | * This routine is invoked to set up the driver internal resources specific to |
4896 | * support the SLI-4 HBA device it attached to. | |
3772a991 JS |
4897 | * |
4898 | * Return codes | |
af901ca1 | 4899 | * 0 - successful |
da0436e9 | 4900 | * other values - error |
3772a991 JS |
4901 | **/ |
4902 | static int | |
da0436e9 | 4903 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
3772a991 | 4904 | { |
7bb03bbf | 4905 | struct lpfc_vector_map_info *cpup; |
da0436e9 | 4906 | struct lpfc_sli *psli; |
28baac74 | 4907 | LPFC_MBOXQ_t *mboxq; |
96f7077f | 4908 | int rc, i, hbq_count, max_buf_size; |
28baac74 JS |
4909 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; |
4910 | struct lpfc_mqe *mqe; | |
09294d46 | 4911 | int longs; |
1ba981fd | 4912 | int fof_vectors = 0; |
da0436e9 | 4913 | |
716d3bc5 JS |
4914 | /* Get all the module params for configuring this host */ |
4915 | lpfc_get_cfgparam(phba); | |
4916 | ||
da0436e9 JS |
4917 | /* Before proceed, wait for POST done and device ready */ |
4918 | rc = lpfc_sli4_post_status_check(phba); | |
4919 | if (rc) | |
4920 | return -ENODEV; | |
4921 | ||
3772a991 | 4922 | /* |
da0436e9 | 4923 | * Initialize timers used by driver |
3772a991 | 4924 | */ |
3772a991 | 4925 | |
da0436e9 JS |
4926 | /* Heartbeat timer */ |
4927 | init_timer(&phba->hb_tmofunc); | |
4928 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
4929 | phba->hb_tmofunc.data = (unsigned long)phba; | |
19ca7609 JS |
4930 | init_timer(&phba->rrq_tmr); |
4931 | phba->rrq_tmr.function = lpfc_rrq_timeout; | |
4932 | phba->rrq_tmr.data = (unsigned long)phba; | |
3772a991 | 4933 | |
da0436e9 JS |
4934 | psli = &phba->sli; |
4935 | /* MBOX heartbeat timer */ | |
4936 | init_timer(&psli->mbox_tmo); | |
4937 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
4938 | psli->mbox_tmo.data = (unsigned long) phba; | |
4939 | /* Fabric block timer */ | |
4940 | init_timer(&phba->fabric_block_timer); | |
4941 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
4942 | phba->fabric_block_timer.data = (unsigned long) phba; | |
4943 | /* EA polling mode timer */ | |
4944 | init_timer(&phba->eratt_poll); | |
4945 | phba->eratt_poll.function = lpfc_poll_eratt; | |
4946 | phba->eratt_poll.data = (unsigned long) phba; | |
ecfd03c6 JS |
4947 | /* FCF rediscover timer */ |
4948 | init_timer(&phba->fcf.redisc_wait); | |
4949 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; | |
4950 | phba->fcf.redisc_wait.data = (unsigned long)phba; | |
4951 | ||
7ad20aa9 JS |
4952 | /* |
4953 | * Control structure for handling external multi-buffer mailbox | |
4954 | * command pass-through. | |
4955 | */ | |
4956 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, | |
4957 | sizeof(struct lpfc_mbox_ext_buf_ctx)); | |
4958 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); | |
4959 | ||
da0436e9 | 4960 | phba->max_vpi = LPFC_MAX_VPI; |
67d12733 | 4961 | |
da0436e9 JS |
4962 | /* This will be set to correct value after the read_config mbox */ |
4963 | phba->max_vports = 0; | |
3772a991 | 4964 | |
da0436e9 JS |
4965 | /* Program the default value of vlan_id and fc_map */ |
4966 | phba->valid_vlan = 0; | |
4967 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4968 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4969 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
3772a991 | 4970 | |
2a76a283 JS |
4971 | /* |
4972 | * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands | |
4973 | * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple. | |
4974 | */ | |
4975 | if (!phba->sli.ring) | |
4976 | phba->sli.ring = kzalloc( | |
67d12733 | 4977 | (LPFC_SLI3_MAX_RING + phba->cfg_fcp_io_channel) * |
2a76a283 JS |
4978 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); |
4979 | if (!phba->sli.ring) | |
4980 | return -ENOMEM; | |
09294d46 | 4981 | |
da0436e9 | 4982 | /* |
09294d46 JS |
4983 | * It doesn't matter what family our adapter is in, we are |
4984 | * limited to 2 Pages, 512 SGEs, for our SGL. | |
4985 | * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp | |
4986 | */ | |
4987 | max_buf_size = (2 * SLI4_PAGE_SIZE); | |
4988 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SGL_SEG_CNT - 2) | |
4989 | phba->cfg_sg_seg_cnt = LPFC_MAX_SGL_SEG_CNT - 2; | |
09294d46 | 4990 | |
da0436e9 | 4991 | /* |
96f7077f | 4992 | * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size |
da0436e9 | 4993 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
da0436e9 | 4994 | */ |
96f7077f JS |
4995 | |
4996 | if (phba->cfg_enable_bg) { | |
4997 | /* | |
4998 | * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd, | |
4999 | * the FCP rsp, and a SGE for each. Sice we have no control | |
5000 | * over how many protection data segments the SCSI Layer | |
5001 | * will hand us (ie: there could be one for every block | |
5002 | * in the IO), we just allocate enough SGEs to accomidate | |
5003 | * our max amount and we need to limit lpfc_sg_seg_cnt to | |
5004 | * minimize the risk of running out. | |
5005 | */ | |
5006 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + | |
5007 | sizeof(struct fcp_rsp) + max_buf_size; | |
5008 | ||
5009 | /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */ | |
5010 | phba->cfg_total_seg_cnt = LPFC_MAX_SGL_SEG_CNT; | |
5011 | ||
5012 | if (phba->cfg_sg_seg_cnt > LPFC_MAX_SG_SLI4_SEG_CNT_DIF) | |
5013 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SLI4_SEG_CNT_DIF; | |
5014 | } else { | |
5015 | /* | |
5016 | * The scsi_buf for a regular I/O will hold the FCP cmnd, | |
5017 | * the FCP rsp, a SGE for each, and a SGE for up to | |
5018 | * cfg_sg_seg_cnt data segments. | |
5019 | */ | |
5020 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + | |
5021 | sizeof(struct fcp_rsp) + | |
5022 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge)); | |
5023 | ||
5024 | /* Total SGEs for scsi_sg_list */ | |
5025 | phba->cfg_total_seg_cnt = phba->cfg_sg_seg_cnt + 2; | |
5026 | /* | |
5027 | * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need | |
5028 | * to post 1 page for the SGL. | |
5029 | */ | |
085c647c | 5030 | } |
acd6859b | 5031 | |
96f7077f JS |
5032 | /* Initialize the host templates with the updated values. */ |
5033 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
5034 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
5035 | ||
5036 | if (phba->cfg_sg_dma_buf_size <= LPFC_MIN_SG_SLI4_BUF_SZ) | |
5037 | phba->cfg_sg_dma_buf_size = LPFC_MIN_SG_SLI4_BUF_SZ; | |
5038 | else | |
5039 | phba->cfg_sg_dma_buf_size = | |
5040 | SLI4_PAGE_ALIGN(phba->cfg_sg_dma_buf_size); | |
5041 | ||
5042 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT | LOG_FCP, | |
5043 | "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n", | |
5044 | phba->cfg_sg_seg_cnt, phba->cfg_sg_dma_buf_size, | |
5045 | phba->cfg_total_seg_cnt); | |
3772a991 | 5046 | |
da0436e9 JS |
5047 | /* Initialize buffer queue management fields */ |
5048 | hbq_count = lpfc_sli_hbq_count(); | |
5049 | for (i = 0; i < hbq_count; ++i) | |
5050 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
5051 | INIT_LIST_HEAD(&phba->rb_pend_list); | |
5052 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; | |
5053 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; | |
3772a991 | 5054 | |
da0436e9 JS |
5055 | /* |
5056 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. | |
5057 | */ | |
5058 | /* Initialize the Abort scsi buffer list used by driver */ | |
5059 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
5060 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
5061 | /* This abort list used by worker thread */ | |
5062 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); | |
3772a991 | 5063 | |
da0436e9 | 5064 | /* |
6d368e53 | 5065 | * Initialize driver internal slow-path work queues |
da0436e9 | 5066 | */ |
3772a991 | 5067 | |
da0436e9 JS |
5068 | /* Driver internel slow-path CQ Event pool */ |
5069 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); | |
5070 | /* Response IOCB work queue list */ | |
45ed1190 | 5071 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
da0436e9 JS |
5072 | /* Asynchronous event CQ Event work queue list */ |
5073 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); | |
5074 | /* Fast-path XRI aborted CQ Event work queue list */ | |
5075 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
5076 | /* Slow-path XRI aborted CQ Event work queue list */ | |
5077 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
5078 | /* Receive queue CQ Event work queue list */ | |
5079 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); | |
5080 | ||
6d368e53 JS |
5081 | /* Initialize extent block lists. */ |
5082 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); | |
5083 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); | |
5084 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); | |
5085 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); | |
5086 | ||
da0436e9 JS |
5087 | /* Initialize the driver internal SLI layer lists. */ |
5088 | lpfc_sli_setup(phba); | |
5089 | lpfc_sli_queue_setup(phba); | |
3772a991 | 5090 | |
da0436e9 JS |
5091 | /* Allocate device driver memory */ |
5092 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); | |
5093 | if (rc) | |
5094 | return -ENOMEM; | |
5095 | ||
2fcee4bf JS |
5096 | /* IF Type 2 ports get initialized now. */ |
5097 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
5098 | LPFC_SLI_INTF_IF_TYPE_2) { | |
5099 | rc = lpfc_pci_function_reset(phba); | |
5100 | if (unlikely(rc)) | |
5101 | return -ENODEV; | |
5102 | } | |
5103 | ||
da0436e9 JS |
5104 | /* Create the bootstrap mailbox command */ |
5105 | rc = lpfc_create_bootstrap_mbox(phba); | |
5106 | if (unlikely(rc)) | |
5107 | goto out_free_mem; | |
5108 | ||
5109 | /* Set up the host's endian order with the device. */ | |
5110 | rc = lpfc_setup_endian_order(phba); | |
5111 | if (unlikely(rc)) | |
5112 | goto out_free_bsmbx; | |
5113 | ||
5114 | /* Set up the hba's configuration parameters. */ | |
5115 | rc = lpfc_sli4_read_config(phba); | |
cff261f6 JS |
5116 | if (unlikely(rc)) |
5117 | goto out_free_bsmbx; | |
5118 | rc = lpfc_mem_alloc_active_rrq_pool_s4(phba); | |
da0436e9 JS |
5119 | if (unlikely(rc)) |
5120 | goto out_free_bsmbx; | |
5121 | ||
2fcee4bf JS |
5122 | /* IF Type 0 ports get initialized now. */ |
5123 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
5124 | LPFC_SLI_INTF_IF_TYPE_0) { | |
5125 | rc = lpfc_pci_function_reset(phba); | |
5126 | if (unlikely(rc)) | |
5127 | goto out_free_bsmbx; | |
5128 | } | |
da0436e9 | 5129 | |
cb5172ea JS |
5130 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
5131 | GFP_KERNEL); | |
5132 | if (!mboxq) { | |
5133 | rc = -ENOMEM; | |
5134 | goto out_free_bsmbx; | |
5135 | } | |
5136 | ||
fedd3b7b | 5137 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
cb5172ea JS |
5138 | lpfc_supported_pages(mboxq); |
5139 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
fedd3b7b JS |
5140 | if (!rc) { |
5141 | mqe = &mboxq->u.mqe; | |
5142 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), | |
5143 | LPFC_MAX_SUPPORTED_PAGES); | |
5144 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { | |
5145 | switch (pn_page[i]) { | |
5146 | case LPFC_SLI4_PARAMETERS: | |
5147 | phba->sli4_hba.pc_sli4_params.supported = 1; | |
5148 | break; | |
5149 | default: | |
5150 | break; | |
5151 | } | |
5152 | } | |
5153 | /* Read the port's SLI4 Parameters capabilities if supported. */ | |
5154 | if (phba->sli4_hba.pc_sli4_params.supported) | |
5155 | rc = lpfc_pc_sli4_params_get(phba, mboxq); | |
5156 | if (rc) { | |
5157 | mempool_free(mboxq, phba->mbox_mem_pool); | |
5158 | rc = -EIO; | |
5159 | goto out_free_bsmbx; | |
cb5172ea JS |
5160 | } |
5161 | } | |
fedd3b7b JS |
5162 | /* |
5163 | * Get sli4 parameters that override parameters from Port capabilities. | |
6d368e53 JS |
5164 | * If this call fails, it isn't critical unless the SLI4 parameters come |
5165 | * back in conflict. | |
fedd3b7b | 5166 | */ |
6d368e53 JS |
5167 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
5168 | if (rc) { | |
5169 | if (phba->sli4_hba.extents_in_use && | |
5170 | phba->sli4_hba.rpi_hdrs_in_use) { | |
5171 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5172 | "2999 Unsupported SLI4 Parameters " | |
5173 | "Extents and RPI headers enabled.\n"); | |
5174 | goto out_free_bsmbx; | |
5175 | } | |
5176 | } | |
cb5172ea | 5177 | mempool_free(mboxq, phba->mbox_mem_pool); |
1ba981fd JS |
5178 | |
5179 | /* Verify OAS is supported */ | |
5180 | lpfc_sli4_oas_verify(phba); | |
5181 | if (phba->cfg_fof) | |
5182 | fof_vectors = 1; | |
5183 | ||
5350d872 JS |
5184 | /* Verify all the SLI4 queues */ |
5185 | rc = lpfc_sli4_queue_verify(phba); | |
da0436e9 JS |
5186 | if (rc) |
5187 | goto out_free_bsmbx; | |
5188 | ||
5189 | /* Create driver internal CQE event pool */ | |
5190 | rc = lpfc_sli4_cq_event_pool_create(phba); | |
5191 | if (rc) | |
5350d872 | 5192 | goto out_free_bsmbx; |
da0436e9 | 5193 | |
8a9d2e80 JS |
5194 | /* Initialize sgl lists per host */ |
5195 | lpfc_init_sgl_list(phba); | |
5196 | ||
5197 | /* Allocate and initialize active sgl array */ | |
da0436e9 JS |
5198 | rc = lpfc_init_active_sgl_array(phba); |
5199 | if (rc) { | |
5200 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5201 | "1430 Failed to initialize sgl list.\n"); | |
8a9d2e80 | 5202 | goto out_destroy_cq_event_pool; |
da0436e9 | 5203 | } |
da0436e9 JS |
5204 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
5205 | if (rc) { | |
5206 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5207 | "1432 Failed to initialize rpi headers.\n"); | |
5208 | goto out_free_active_sgl; | |
5209 | } | |
5210 | ||
a93ff37a | 5211 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
0c9ab6f5 JS |
5212 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
5213 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), | |
5214 | GFP_KERNEL); | |
5215 | if (!phba->fcf.fcf_rr_bmask) { | |
5216 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5217 | "2759 Failed allocate memory for FCF round " | |
5218 | "robin failover bmask\n"); | |
0558056c | 5219 | rc = -ENOMEM; |
0c9ab6f5 JS |
5220 | goto out_remove_rpi_hdrs; |
5221 | } | |
5222 | ||
67d12733 JS |
5223 | phba->sli4_hba.fcp_eq_hdl = |
5224 | kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * | |
1ba981fd JS |
5225 | (fof_vectors + phba->cfg_fcp_io_channel)), |
5226 | GFP_KERNEL); | |
67d12733 JS |
5227 | if (!phba->sli4_hba.fcp_eq_hdl) { |
5228 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5229 | "2572 Failed allocate memory for " | |
5230 | "fast-path per-EQ handle array\n"); | |
5231 | rc = -ENOMEM; | |
5232 | goto out_free_fcf_rr_bmask; | |
da0436e9 JS |
5233 | } |
5234 | ||
5235 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * | |
1ba981fd JS |
5236 | (fof_vectors + |
5237 | phba->cfg_fcp_io_channel)), GFP_KERNEL); | |
da0436e9 JS |
5238 | if (!phba->sli4_hba.msix_entries) { |
5239 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5240 | "2573 Failed allocate memory for msi-x " | |
5241 | "interrupt vector entries\n"); | |
0558056c | 5242 | rc = -ENOMEM; |
da0436e9 JS |
5243 | goto out_free_fcp_eq_hdl; |
5244 | } | |
5245 | ||
7bb03bbf JS |
5246 | phba->sli4_hba.cpu_map = kzalloc((sizeof(struct lpfc_vector_map_info) * |
5247 | phba->sli4_hba.num_present_cpu), | |
5248 | GFP_KERNEL); | |
5249 | if (!phba->sli4_hba.cpu_map) { | |
5250 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5251 | "3327 Failed allocate memory for msi-x " | |
5252 | "interrupt vector mapping\n"); | |
5253 | rc = -ENOMEM; | |
5254 | goto out_free_msix; | |
5255 | } | |
b246de17 JS |
5256 | if (lpfc_used_cpu == NULL) { |
5257 | lpfc_used_cpu = kzalloc((sizeof(uint16_t) * lpfc_present_cpu), | |
5258 | GFP_KERNEL); | |
5259 | if (!lpfc_used_cpu) { | |
5260 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5261 | "3335 Failed allocate memory for msi-x " | |
5262 | "interrupt vector mapping\n"); | |
5263 | kfree(phba->sli4_hba.cpu_map); | |
5264 | rc = -ENOMEM; | |
5265 | goto out_free_msix; | |
5266 | } | |
5267 | for (i = 0; i < lpfc_present_cpu; i++) | |
5268 | lpfc_used_cpu[i] = LPFC_VECTOR_MAP_EMPTY; | |
5269 | } | |
5270 | ||
7bb03bbf JS |
5271 | /* Initialize io channels for round robin */ |
5272 | cpup = phba->sli4_hba.cpu_map; | |
5273 | rc = 0; | |
5274 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { | |
5275 | cpup->channel_id = rc; | |
5276 | rc++; | |
5277 | if (rc >= phba->cfg_fcp_io_channel) | |
5278 | rc = 0; | |
5279 | } | |
5280 | ||
912e3acd JS |
5281 | /* |
5282 | * Enable sr-iov virtual functions if supported and configured | |
5283 | * through the module parameter. | |
5284 | */ | |
5285 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
5286 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, | |
5287 | phba->cfg_sriov_nr_virtfn); | |
5288 | if (rc) { | |
5289 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
5290 | "3020 Requested number of SR-IOV " | |
5291 | "virtual functions (%d) is not " | |
5292 | "supported\n", | |
5293 | phba->cfg_sriov_nr_virtfn); | |
5294 | phba->cfg_sriov_nr_virtfn = 0; | |
5295 | } | |
5296 | } | |
5297 | ||
5248a749 | 5298 | return 0; |
da0436e9 | 5299 | |
7bb03bbf JS |
5300 | out_free_msix: |
5301 | kfree(phba->sli4_hba.msix_entries); | |
da0436e9 JS |
5302 | out_free_fcp_eq_hdl: |
5303 | kfree(phba->sli4_hba.fcp_eq_hdl); | |
0c9ab6f5 JS |
5304 | out_free_fcf_rr_bmask: |
5305 | kfree(phba->fcf.fcf_rr_bmask); | |
da0436e9 JS |
5306 | out_remove_rpi_hdrs: |
5307 | lpfc_sli4_remove_rpi_hdrs(phba); | |
5308 | out_free_active_sgl: | |
5309 | lpfc_free_active_sgl(phba); | |
da0436e9 JS |
5310 | out_destroy_cq_event_pool: |
5311 | lpfc_sli4_cq_event_pool_destroy(phba); | |
da0436e9 JS |
5312 | out_free_bsmbx: |
5313 | lpfc_destroy_bootstrap_mbox(phba); | |
5314 | out_free_mem: | |
5315 | lpfc_mem_free(phba); | |
5316 | return rc; | |
5317 | } | |
5318 | ||
5319 | /** | |
5320 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev | |
5321 | * @phba: pointer to lpfc hba data structure. | |
5322 | * | |
5323 | * This routine is invoked to unset the driver internal resources set up | |
5324 | * specific for supporting the SLI-4 HBA device it attached to. | |
5325 | **/ | |
5326 | static void | |
5327 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) | |
5328 | { | |
5329 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; | |
5330 | ||
7bb03bbf JS |
5331 | /* Free memory allocated for msi-x interrupt vector to CPU mapping */ |
5332 | kfree(phba->sli4_hba.cpu_map); | |
5333 | phba->sli4_hba.num_present_cpu = 0; | |
5334 | phba->sli4_hba.num_online_cpu = 0; | |
76fd07a6 | 5335 | phba->sli4_hba.curr_disp_cpu = 0; |
7bb03bbf | 5336 | |
da0436e9 JS |
5337 | /* Free memory allocated for msi-x interrupt vector entries */ |
5338 | kfree(phba->sli4_hba.msix_entries); | |
5339 | ||
5340 | /* Free memory allocated for fast-path work queue handles */ | |
5341 | kfree(phba->sli4_hba.fcp_eq_hdl); | |
5342 | ||
5343 | /* Free the allocated rpi headers. */ | |
5344 | lpfc_sli4_remove_rpi_hdrs(phba); | |
d11e31dd | 5345 | lpfc_sli4_remove_rpis(phba); |
da0436e9 | 5346 | |
0c9ab6f5 JS |
5347 | /* Free eligible FCF index bmask */ |
5348 | kfree(phba->fcf.fcf_rr_bmask); | |
5349 | ||
da0436e9 JS |
5350 | /* Free the ELS sgl list */ |
5351 | lpfc_free_active_sgl(phba); | |
8a9d2e80 | 5352 | lpfc_free_els_sgl_list(phba); |
da0436e9 | 5353 | |
da0436e9 JS |
5354 | /* Free the completion queue EQ event pool */ |
5355 | lpfc_sli4_cq_event_release_all(phba); | |
5356 | lpfc_sli4_cq_event_pool_destroy(phba); | |
5357 | ||
6d368e53 JS |
5358 | /* Release resource identifiers. */ |
5359 | lpfc_sli4_dealloc_resource_identifiers(phba); | |
5360 | ||
da0436e9 JS |
5361 | /* Free the bsmbx region. */ |
5362 | lpfc_destroy_bootstrap_mbox(phba); | |
5363 | ||
5364 | /* Free the SLI Layer memory with SLI4 HBAs */ | |
5365 | lpfc_mem_free_all(phba); | |
5366 | ||
5367 | /* Free the current connect table */ | |
5368 | list_for_each_entry_safe(conn_entry, next_conn_entry, | |
4d9ab994 JS |
5369 | &phba->fcf_conn_rec_list, list) { |
5370 | list_del_init(&conn_entry->list); | |
da0436e9 | 5371 | kfree(conn_entry); |
4d9ab994 | 5372 | } |
da0436e9 JS |
5373 | |
5374 | return; | |
5375 | } | |
5376 | ||
5377 | /** | |
25985edc | 5378 | * lpfc_init_api_table_setup - Set up init api function jump table |
da0436e9 JS |
5379 | * @phba: The hba struct for which this call is being executed. |
5380 | * @dev_grp: The HBA PCI-Device group number. | |
5381 | * | |
5382 | * This routine sets up the device INIT interface API function jump table | |
5383 | * in @phba struct. | |
5384 | * | |
5385 | * Returns: 0 - success, -ENODEV - failure. | |
5386 | **/ | |
5387 | int | |
5388 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
5389 | { | |
84d1b006 JS |
5390 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
5391 | phba->lpfc_hba_down_link = lpfc_hba_down_link; | |
7f86059a | 5392 | phba->lpfc_selective_reset = lpfc_selective_reset; |
da0436e9 JS |
5393 | switch (dev_grp) { |
5394 | case LPFC_PCI_DEV_LP: | |
5395 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; | |
5396 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; | |
5397 | phba->lpfc_stop_port = lpfc_stop_port_s3; | |
5398 | break; | |
5399 | case LPFC_PCI_DEV_OC: | |
5400 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; | |
5401 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; | |
5402 | phba->lpfc_stop_port = lpfc_stop_port_s4; | |
5403 | break; | |
5404 | default: | |
5405 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5406 | "1431 Invalid HBA PCI-device group: 0x%x\n", | |
5407 | dev_grp); | |
5408 | return -ENODEV; | |
5409 | break; | |
5410 | } | |
5411 | return 0; | |
5412 | } | |
5413 | ||
5414 | /** | |
5415 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. | |
5416 | * @phba: pointer to lpfc hba data structure. | |
5417 | * | |
5418 | * This routine is invoked to set up the driver internal resources before the | |
5419 | * device specific resource setup to support the HBA device it attached to. | |
5420 | * | |
5421 | * Return codes | |
af901ca1 | 5422 | * 0 - successful |
da0436e9 JS |
5423 | * other values - error |
5424 | **/ | |
5425 | static int | |
5426 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) | |
5427 | { | |
5428 | /* | |
5429 | * Driver resources common to all SLI revisions | |
5430 | */ | |
5431 | atomic_set(&phba->fast_event_count, 0); | |
5432 | spin_lock_init(&phba->hbalock); | |
5433 | ||
5434 | /* Initialize ndlp management spinlock */ | |
5435 | spin_lock_init(&phba->ndlp_lock); | |
5436 | ||
5437 | INIT_LIST_HEAD(&phba->port_list); | |
5438 | INIT_LIST_HEAD(&phba->work_list); | |
5439 | init_waitqueue_head(&phba->wait_4_mlo_m_q); | |
5440 | ||
5441 | /* Initialize the wait queue head for the kernel thread */ | |
5442 | init_waitqueue_head(&phba->work_waitq); | |
5443 | ||
5444 | /* Initialize the scsi buffer list used by driver for scsi IO */ | |
a40fc5f0 JS |
5445 | spin_lock_init(&phba->scsi_buf_list_get_lock); |
5446 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_get); | |
5447 | spin_lock_init(&phba->scsi_buf_list_put_lock); | |
5448 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list_put); | |
da0436e9 JS |
5449 | |
5450 | /* Initialize the fabric iocb list */ | |
5451 | INIT_LIST_HEAD(&phba->fabric_iocb_list); | |
5452 | ||
5453 | /* Initialize list to save ELS buffers */ | |
5454 | INIT_LIST_HEAD(&phba->elsbuf); | |
5455 | ||
5456 | /* Initialize FCF connection rec list */ | |
5457 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); | |
5458 | ||
1ba981fd JS |
5459 | /* Initialize OAS configuration list */ |
5460 | spin_lock_init(&phba->devicelock); | |
5461 | INIT_LIST_HEAD(&phba->luns); | |
5462 | ||
da0436e9 JS |
5463 | return 0; |
5464 | } | |
5465 | ||
5466 | /** | |
5467 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. | |
5468 | * @phba: pointer to lpfc hba data structure. | |
5469 | * | |
5470 | * This routine is invoked to set up the driver internal resources after the | |
5471 | * device specific resource setup to support the HBA device it attached to. | |
5472 | * | |
5473 | * Return codes | |
af901ca1 | 5474 | * 0 - successful |
da0436e9 JS |
5475 | * other values - error |
5476 | **/ | |
5477 | static int | |
5478 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) | |
5479 | { | |
5480 | int error; | |
5481 | ||
5482 | /* Startup the kernel thread for this host adapter. */ | |
5483 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
5484 | "lpfc_worker_%d", phba->brd_no); | |
5485 | if (IS_ERR(phba->worker_thread)) { | |
5486 | error = PTR_ERR(phba->worker_thread); | |
5487 | return error; | |
3772a991 JS |
5488 | } |
5489 | ||
5490 | return 0; | |
5491 | } | |
5492 | ||
5493 | /** | |
5494 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. | |
5495 | * @phba: pointer to lpfc hba data structure. | |
5496 | * | |
5497 | * This routine is invoked to unset the driver internal resources set up after | |
5498 | * the device specific resource setup for supporting the HBA device it | |
5499 | * attached to. | |
5500 | **/ | |
5501 | static void | |
5502 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) | |
5503 | { | |
5504 | /* Stop kernel worker thread */ | |
5505 | kthread_stop(phba->worker_thread); | |
5506 | } | |
5507 | ||
5508 | /** | |
5509 | * lpfc_free_iocb_list - Free iocb list. | |
5510 | * @phba: pointer to lpfc hba data structure. | |
5511 | * | |
5512 | * This routine is invoked to free the driver's IOCB list and memory. | |
5513 | **/ | |
5514 | static void | |
5515 | lpfc_free_iocb_list(struct lpfc_hba *phba) | |
5516 | { | |
5517 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; | |
5518 | ||
5519 | spin_lock_irq(&phba->hbalock); | |
5520 | list_for_each_entry_safe(iocbq_entry, iocbq_next, | |
5521 | &phba->lpfc_iocb_list, list) { | |
5522 | list_del(&iocbq_entry->list); | |
5523 | kfree(iocbq_entry); | |
5524 | phba->total_iocbq_bufs--; | |
98c9ea5c | 5525 | } |
3772a991 JS |
5526 | spin_unlock_irq(&phba->hbalock); |
5527 | ||
5528 | return; | |
5529 | } | |
5530 | ||
5531 | /** | |
5532 | * lpfc_init_iocb_list - Allocate and initialize iocb list. | |
5533 | * @phba: pointer to lpfc hba data structure. | |
5534 | * | |
5535 | * This routine is invoked to allocate and initizlize the driver's IOCB | |
5536 | * list and set up the IOCB tag array accordingly. | |
5537 | * | |
5538 | * Return codes | |
af901ca1 | 5539 | * 0 - successful |
3772a991 JS |
5540 | * other values - error |
5541 | **/ | |
5542 | static int | |
5543 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) | |
5544 | { | |
5545 | struct lpfc_iocbq *iocbq_entry = NULL; | |
5546 | uint16_t iotag; | |
5547 | int i; | |
dea3101e JB |
5548 | |
5549 | /* Initialize and populate the iocb list per host. */ | |
5550 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); | |
3772a991 | 5551 | for (i = 0; i < iocb_count; i++) { |
dd00cc48 | 5552 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
dea3101e JB |
5553 | if (iocbq_entry == NULL) { |
5554 | printk(KERN_ERR "%s: only allocated %d iocbs of " | |
5555 | "expected %d count. Unloading driver.\n", | |
cadbd4a5 | 5556 | __func__, i, LPFC_IOCB_LIST_CNT); |
dea3101e JB |
5557 | goto out_free_iocbq; |
5558 | } | |
5559 | ||
604a3e30 JB |
5560 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
5561 | if (iotag == 0) { | |
3772a991 | 5562 | kfree(iocbq_entry); |
604a3e30 | 5563 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
3772a991 | 5564 | "Unloading driver.\n", __func__); |
604a3e30 JB |
5565 | goto out_free_iocbq; |
5566 | } | |
6d368e53 | 5567 | iocbq_entry->sli4_lxritag = NO_XRI; |
3772a991 | 5568 | iocbq_entry->sli4_xritag = NO_XRI; |
2e0fef85 JS |
5569 | |
5570 | spin_lock_irq(&phba->hbalock); | |
dea3101e JB |
5571 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
5572 | phba->total_iocbq_bufs++; | |
2e0fef85 | 5573 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
5574 | } |
5575 | ||
3772a991 | 5576 | return 0; |
dea3101e | 5577 | |
3772a991 JS |
5578 | out_free_iocbq: |
5579 | lpfc_free_iocb_list(phba); | |
dea3101e | 5580 | |
3772a991 JS |
5581 | return -ENOMEM; |
5582 | } | |
5e9d9b82 | 5583 | |
3772a991 | 5584 | /** |
8a9d2e80 | 5585 | * lpfc_free_sgl_list - Free a given sgl list. |
da0436e9 | 5586 | * @phba: pointer to lpfc hba data structure. |
8a9d2e80 | 5587 | * @sglq_list: pointer to the head of sgl list. |
3772a991 | 5588 | * |
8a9d2e80 | 5589 | * This routine is invoked to free a give sgl list and memory. |
3772a991 | 5590 | **/ |
8a9d2e80 JS |
5591 | void |
5592 | lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list) | |
3772a991 | 5593 | { |
da0436e9 | 5594 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
8a9d2e80 JS |
5595 | |
5596 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { | |
5597 | list_del(&sglq_entry->list); | |
5598 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); | |
5599 | kfree(sglq_entry); | |
5600 | } | |
5601 | } | |
5602 | ||
5603 | /** | |
5604 | * lpfc_free_els_sgl_list - Free els sgl list. | |
5605 | * @phba: pointer to lpfc hba data structure. | |
5606 | * | |
5607 | * This routine is invoked to free the driver's els sgl list and memory. | |
5608 | **/ | |
5609 | static void | |
5610 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) | |
5611 | { | |
da0436e9 | 5612 | LIST_HEAD(sglq_list); |
dea3101e | 5613 | |
8a9d2e80 | 5614 | /* Retrieve all els sgls from driver list */ |
da0436e9 JS |
5615 | spin_lock_irq(&phba->hbalock); |
5616 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); | |
5617 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 5618 | |
8a9d2e80 JS |
5619 | /* Now free the sgl list */ |
5620 | lpfc_free_sgl_list(phba, &sglq_list); | |
da0436e9 | 5621 | } |
92d7f7b0 | 5622 | |
da0436e9 JS |
5623 | /** |
5624 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. | |
5625 | * @phba: pointer to lpfc hba data structure. | |
5626 | * | |
5627 | * This routine is invoked to allocate the driver's active sgl memory. | |
5628 | * This array will hold the sglq_entry's for active IOs. | |
5629 | **/ | |
5630 | static int | |
5631 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) | |
5632 | { | |
5633 | int size; | |
5634 | size = sizeof(struct lpfc_sglq *); | |
5635 | size *= phba->sli4_hba.max_cfg_param.max_xri; | |
5636 | ||
5637 | phba->sli4_hba.lpfc_sglq_active_list = | |
5638 | kzalloc(size, GFP_KERNEL); | |
5639 | if (!phba->sli4_hba.lpfc_sglq_active_list) | |
5640 | return -ENOMEM; | |
5641 | return 0; | |
3772a991 JS |
5642 | } |
5643 | ||
5644 | /** | |
da0436e9 | 5645 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
3772a991 JS |
5646 | * @phba: pointer to lpfc hba data structure. |
5647 | * | |
da0436e9 JS |
5648 | * This routine is invoked to walk through the array of active sglq entries |
5649 | * and free all of the resources. | |
5650 | * This is just a place holder for now. | |
3772a991 JS |
5651 | **/ |
5652 | static void | |
da0436e9 | 5653 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
3772a991 | 5654 | { |
da0436e9 | 5655 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
3772a991 JS |
5656 | } |
5657 | ||
5658 | /** | |
da0436e9 | 5659 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
3772a991 JS |
5660 | * @phba: pointer to lpfc hba data structure. |
5661 | * | |
da0436e9 JS |
5662 | * This routine is invoked to allocate and initizlize the driver's sgl |
5663 | * list and set up the sgl xritag tag array accordingly. | |
3772a991 | 5664 | * |
3772a991 | 5665 | **/ |
8a9d2e80 | 5666 | static void |
da0436e9 | 5667 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
3772a991 | 5668 | { |
da0436e9 JS |
5669 | /* Initialize and populate the sglq list per host/VF. */ |
5670 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); | |
5671 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
5672 | ||
8a9d2e80 JS |
5673 | /* els xri-sgl book keeping */ |
5674 | phba->sli4_hba.els_xri_cnt = 0; | |
0ff10d46 | 5675 | |
8a9d2e80 | 5676 | /* scsi xri-buffer book keeping */ |
da0436e9 | 5677 | phba->sli4_hba.scsi_xri_cnt = 0; |
da0436e9 JS |
5678 | } |
5679 | ||
5680 | /** | |
5681 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port | |
5682 | * @phba: pointer to lpfc hba data structure. | |
5683 | * | |
5684 | * This routine is invoked to post rpi header templates to the | |
88a2cfbb | 5685 | * port for those SLI4 ports that do not support extents. This routine |
da0436e9 | 5686 | * posts a PAGE_SIZE memory region to the port to hold up to |
88a2cfbb JS |
5687 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
5688 | * and should be called only when interrupts are disabled. | |
da0436e9 JS |
5689 | * |
5690 | * Return codes | |
af901ca1 | 5691 | * 0 - successful |
88a2cfbb | 5692 | * -ERROR - otherwise. |
da0436e9 JS |
5693 | **/ |
5694 | int | |
5695 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) | |
5696 | { | |
5697 | int rc = 0; | |
da0436e9 JS |
5698 | struct lpfc_rpi_hdr *rpi_hdr; |
5699 | ||
5700 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); | |
ff78d8f9 | 5701 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
6d368e53 | 5702 | return rc; |
6d368e53 JS |
5703 | if (phba->sli4_hba.extents_in_use) |
5704 | return -EIO; | |
da0436e9 JS |
5705 | |
5706 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
5707 | if (!rpi_hdr) { | |
5708 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5709 | "0391 Error during rpi post operation\n"); | |
5710 | lpfc_sli4_remove_rpis(phba); | |
5711 | rc = -ENODEV; | |
5712 | } | |
5713 | ||
5714 | return rc; | |
5715 | } | |
5716 | ||
5717 | /** | |
5718 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region | |
5719 | * @phba: pointer to lpfc hba data structure. | |
5720 | * | |
5721 | * This routine is invoked to allocate a single 4KB memory region to | |
5722 | * support rpis and stores them in the phba. This single region | |
5723 | * provides support for up to 64 rpis. The region is used globally | |
5724 | * by the device. | |
5725 | * | |
5726 | * Returns: | |
5727 | * A valid rpi hdr on success. | |
5728 | * A NULL pointer on any failure. | |
5729 | **/ | |
5730 | struct lpfc_rpi_hdr * | |
5731 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) | |
5732 | { | |
5733 | uint16_t rpi_limit, curr_rpi_range; | |
5734 | struct lpfc_dmabuf *dmabuf; | |
5735 | struct lpfc_rpi_hdr *rpi_hdr; | |
9589b062 | 5736 | uint32_t rpi_count; |
da0436e9 | 5737 | |
6d368e53 JS |
5738 | /* |
5739 | * If the SLI4 port supports extents, posting the rpi header isn't | |
5740 | * required. Set the expected maximum count and let the actual value | |
5741 | * get set when extents are fully allocated. | |
5742 | */ | |
5743 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
5744 | return NULL; | |
5745 | if (phba->sli4_hba.extents_in_use) | |
5746 | return NULL; | |
5747 | ||
5748 | /* The limit on the logical index is just the max_rpi count. */ | |
da0436e9 | 5749 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + |
6d368e53 | 5750 | phba->sli4_hba.max_cfg_param.max_rpi - 1; |
da0436e9 JS |
5751 | |
5752 | spin_lock_irq(&phba->hbalock); | |
6d368e53 JS |
5753 | /* |
5754 | * Establish the starting RPI in this header block. The starting | |
5755 | * rpi is normalized to a zero base because the physical rpi is | |
5756 | * port based. | |
5757 | */ | |
97f2ecf1 | 5758 | curr_rpi_range = phba->sli4_hba.next_rpi; |
da0436e9 JS |
5759 | spin_unlock_irq(&phba->hbalock); |
5760 | ||
5761 | /* | |
5762 | * The port has a limited number of rpis. The increment here | |
5763 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value | |
5764 | * and to allow the full max_rpi range per port. | |
5765 | */ | |
5766 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) | |
9589b062 JS |
5767 | rpi_count = rpi_limit - curr_rpi_range; |
5768 | else | |
5769 | rpi_count = LPFC_RPI_HDR_COUNT; | |
da0436e9 | 5770 | |
6d368e53 JS |
5771 | if (!rpi_count) |
5772 | return NULL; | |
da0436e9 JS |
5773 | /* |
5774 | * First allocate the protocol header region for the port. The | |
5775 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. | |
5776 | */ | |
5777 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
5778 | if (!dmabuf) | |
5779 | return NULL; | |
5780 | ||
5781 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
5782 | LPFC_HDR_TEMPLATE_SIZE, | |
5783 | &dmabuf->phys, | |
5784 | GFP_KERNEL); | |
5785 | if (!dmabuf->virt) { | |
5786 | rpi_hdr = NULL; | |
5787 | goto err_free_dmabuf; | |
5788 | } | |
5789 | ||
5790 | memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE); | |
5791 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { | |
5792 | rpi_hdr = NULL; | |
5793 | goto err_free_coherent; | |
5794 | } | |
5795 | ||
5796 | /* Save the rpi header data for cleanup later. */ | |
5797 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); | |
5798 | if (!rpi_hdr) | |
5799 | goto err_free_coherent; | |
5800 | ||
5801 | rpi_hdr->dmabuf = dmabuf; | |
5802 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; | |
5803 | rpi_hdr->page_count = 1; | |
5804 | spin_lock_irq(&phba->hbalock); | |
6d368e53 JS |
5805 | |
5806 | /* The rpi_hdr stores the logical index only. */ | |
5807 | rpi_hdr->start_rpi = curr_rpi_range; | |
da0436e9 JS |
5808 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
5809 | ||
5810 | /* | |
6d368e53 JS |
5811 | * The next_rpi stores the next logical module-64 rpi value used |
5812 | * to post physical rpis in subsequent rpi postings. | |
da0436e9 | 5813 | */ |
9589b062 | 5814 | phba->sli4_hba.next_rpi += rpi_count; |
da0436e9 JS |
5815 | spin_unlock_irq(&phba->hbalock); |
5816 | return rpi_hdr; | |
5817 | ||
5818 | err_free_coherent: | |
5819 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, | |
5820 | dmabuf->virt, dmabuf->phys); | |
5821 | err_free_dmabuf: | |
5822 | kfree(dmabuf); | |
5823 | return NULL; | |
5824 | } | |
5825 | ||
5826 | /** | |
5827 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions | |
5828 | * @phba: pointer to lpfc hba data structure. | |
5829 | * | |
5830 | * This routine is invoked to remove all memory resources allocated | |
6d368e53 JS |
5831 | * to support rpis for SLI4 ports not supporting extents. This routine |
5832 | * presumes the caller has released all rpis consumed by fabric or port | |
5833 | * logins and is prepared to have the header pages removed. | |
da0436e9 JS |
5834 | **/ |
5835 | void | |
5836 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) | |
5837 | { | |
5838 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; | |
5839 | ||
6d368e53 JS |
5840 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
5841 | goto exit; | |
5842 | ||
da0436e9 JS |
5843 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
5844 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { | |
5845 | list_del(&rpi_hdr->list); | |
5846 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, | |
5847 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); | |
5848 | kfree(rpi_hdr->dmabuf); | |
5849 | kfree(rpi_hdr); | |
5850 | } | |
6d368e53 JS |
5851 | exit: |
5852 | /* There are no rpis available to the port now. */ | |
5853 | phba->sli4_hba.next_rpi = 0; | |
da0436e9 JS |
5854 | } |
5855 | ||
5856 | /** | |
5857 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. | |
5858 | * @pdev: pointer to pci device data structure. | |
5859 | * | |
5860 | * This routine is invoked to allocate the driver hba data structure for an | |
5861 | * HBA device. If the allocation is successful, the phba reference to the | |
5862 | * PCI device data structure is set. | |
5863 | * | |
5864 | * Return codes | |
af901ca1 | 5865 | * pointer to @phba - successful |
da0436e9 JS |
5866 | * NULL - error |
5867 | **/ | |
5868 | static struct lpfc_hba * | |
5869 | lpfc_hba_alloc(struct pci_dev *pdev) | |
5870 | { | |
5871 | struct lpfc_hba *phba; | |
5872 | ||
5873 | /* Allocate memory for HBA structure */ | |
5874 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); | |
5875 | if (!phba) { | |
e34ccdfe | 5876 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
da0436e9 JS |
5877 | return NULL; |
5878 | } | |
5879 | ||
5880 | /* Set reference to PCI device in HBA structure */ | |
5881 | phba->pcidev = pdev; | |
5882 | ||
5883 | /* Assign an unused board number */ | |
5884 | phba->brd_no = lpfc_get_instance(); | |
5885 | if (phba->brd_no < 0) { | |
5886 | kfree(phba); | |
5887 | return NULL; | |
5888 | } | |
5889 | ||
4fede78f | 5890 | spin_lock_init(&phba->ct_ev_lock); |
f1c3b0fc JS |
5891 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
5892 | ||
da0436e9 JS |
5893 | return phba; |
5894 | } | |
5895 | ||
5896 | /** | |
5897 | * lpfc_hba_free - Free driver hba data structure with a device. | |
5898 | * @phba: pointer to lpfc hba data structure. | |
5899 | * | |
5900 | * This routine is invoked to free the driver hba data structure with an | |
5901 | * HBA device. | |
5902 | **/ | |
5903 | static void | |
5904 | lpfc_hba_free(struct lpfc_hba *phba) | |
5905 | { | |
5906 | /* Release the driver assigned board number */ | |
5907 | idr_remove(&lpfc_hba_index, phba->brd_no); | |
5908 | ||
2a76a283 JS |
5909 | /* Free memory allocated with sli rings */ |
5910 | kfree(phba->sli.ring); | |
5911 | phba->sli.ring = NULL; | |
5912 | ||
da0436e9 JS |
5913 | kfree(phba); |
5914 | return; | |
5915 | } | |
5916 | ||
5917 | /** | |
5918 | * lpfc_create_shost - Create hba physical port with associated scsi host. | |
5919 | * @phba: pointer to lpfc hba data structure. | |
5920 | * | |
5921 | * This routine is invoked to create HBA physical port and associate a SCSI | |
5922 | * host with it. | |
5923 | * | |
5924 | * Return codes | |
af901ca1 | 5925 | * 0 - successful |
da0436e9 JS |
5926 | * other values - error |
5927 | **/ | |
5928 | static int | |
5929 | lpfc_create_shost(struct lpfc_hba *phba) | |
5930 | { | |
5931 | struct lpfc_vport *vport; | |
5932 | struct Scsi_Host *shost; | |
5933 | ||
5934 | /* Initialize HBA FC structure */ | |
5935 | phba->fc_edtov = FF_DEF_EDTOV; | |
5936 | phba->fc_ratov = FF_DEF_RATOV; | |
5937 | phba->fc_altov = FF_DEF_ALTOV; | |
5938 | phba->fc_arbtov = FF_DEF_ARBTOV; | |
5939 | ||
d7c47992 | 5940 | atomic_set(&phba->sdev_cnt, 0); |
da0436e9 JS |
5941 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
5942 | if (!vport) | |
5943 | return -ENODEV; | |
5944 | ||
5945 | shost = lpfc_shost_from_vport(vport); | |
5946 | phba->pport = vport; | |
5947 | lpfc_debugfs_initialize(vport); | |
5948 | /* Put reference to SCSI host to driver's device private data */ | |
5949 | pci_set_drvdata(phba->pcidev, shost); | |
2e0fef85 | 5950 | |
3772a991 JS |
5951 | return 0; |
5952 | } | |
db2378e0 | 5953 | |
3772a991 JS |
5954 | /** |
5955 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. | |
5956 | * @phba: pointer to lpfc hba data structure. | |
5957 | * | |
5958 | * This routine is invoked to destroy HBA physical port and the associated | |
5959 | * SCSI host. | |
5960 | **/ | |
5961 | static void | |
5962 | lpfc_destroy_shost(struct lpfc_hba *phba) | |
5963 | { | |
5964 | struct lpfc_vport *vport = phba->pport; | |
5965 | ||
5966 | /* Destroy physical port that associated with the SCSI host */ | |
5967 | destroy_port(vport); | |
5968 | ||
5969 | return; | |
5970 | } | |
5971 | ||
5972 | /** | |
5973 | * lpfc_setup_bg - Setup Block guard structures and debug areas. | |
5974 | * @phba: pointer to lpfc hba data structure. | |
5975 | * @shost: the shost to be used to detect Block guard settings. | |
5976 | * | |
5977 | * This routine sets up the local Block guard protocol settings for @shost. | |
5978 | * This routine also allocates memory for debugging bg buffers. | |
5979 | **/ | |
5980 | static void | |
5981 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) | |
5982 | { | |
bbeb79b9 JS |
5983 | uint32_t old_mask; |
5984 | uint32_t old_guard; | |
5985 | ||
3772a991 JS |
5986 | int pagecnt = 10; |
5987 | if (lpfc_prot_mask && lpfc_prot_guard) { | |
5988 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5989 | "1478 Registering BlockGuard with the " | |
5990 | "SCSI layer\n"); | |
bbeb79b9 JS |
5991 | |
5992 | old_mask = lpfc_prot_mask; | |
5993 | old_guard = lpfc_prot_guard; | |
5994 | ||
5995 | /* Only allow supported values */ | |
5996 | lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | | |
5997 | SHOST_DIX_TYPE0_PROTECTION | | |
5998 | SHOST_DIX_TYPE1_PROTECTION); | |
5999 | lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC); | |
6000 | ||
6001 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ | |
6002 | if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION) | |
6003 | lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; | |
6004 | ||
6005 | if (lpfc_prot_mask && lpfc_prot_guard) { | |
6006 | if ((old_mask != lpfc_prot_mask) || | |
6007 | (old_guard != lpfc_prot_guard)) | |
6008 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6009 | "1475 Registering BlockGuard with the " | |
6010 | "SCSI layer: mask %d guard %d\n", | |
6011 | lpfc_prot_mask, lpfc_prot_guard); | |
6012 | ||
6013 | scsi_host_set_prot(shost, lpfc_prot_mask); | |
6014 | scsi_host_set_guard(shost, lpfc_prot_guard); | |
6015 | } else | |
6016 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6017 | "1479 Not Registering BlockGuard with the SCSI " | |
6018 | "layer, Bad protection parameters: %d %d\n", | |
6019 | old_mask, old_guard); | |
3772a991 | 6020 | } |
bbeb79b9 | 6021 | |
3772a991 JS |
6022 | if (!_dump_buf_data) { |
6023 | while (pagecnt) { | |
6024 | spin_lock_init(&_dump_buf_lock); | |
6025 | _dump_buf_data = | |
6026 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
6027 | if (_dump_buf_data) { | |
6a9c52cf JS |
6028 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
6029 | "9043 BLKGRD: allocated %d pages for " | |
3772a991 JS |
6030 | "_dump_buf_data at 0x%p\n", |
6031 | (1 << pagecnt), _dump_buf_data); | |
6032 | _dump_buf_data_order = pagecnt; | |
6033 | memset(_dump_buf_data, 0, | |
6034 | ((1 << PAGE_SHIFT) << pagecnt)); | |
6035 | break; | |
6036 | } else | |
6037 | --pagecnt; | |
6038 | } | |
6039 | if (!_dump_buf_data_order) | |
6a9c52cf JS |
6040 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
6041 | "9044 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
6042 | "memory for hexdump\n"); |
6043 | } else | |
6a9c52cf JS |
6044 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
6045 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" | |
3772a991 JS |
6046 | "\n", _dump_buf_data); |
6047 | if (!_dump_buf_dif) { | |
6048 | while (pagecnt) { | |
6049 | _dump_buf_dif = | |
6050 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
6051 | if (_dump_buf_dif) { | |
6a9c52cf JS |
6052 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
6053 | "9046 BLKGRD: allocated %d pages for " | |
3772a991 JS |
6054 | "_dump_buf_dif at 0x%p\n", |
6055 | (1 << pagecnt), _dump_buf_dif); | |
6056 | _dump_buf_dif_order = pagecnt; | |
6057 | memset(_dump_buf_dif, 0, | |
6058 | ((1 << PAGE_SHIFT) << pagecnt)); | |
6059 | break; | |
6060 | } else | |
6061 | --pagecnt; | |
6062 | } | |
6063 | if (!_dump_buf_dif_order) | |
6a9c52cf JS |
6064 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
6065 | "9047 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
6066 | "memory for hexdump\n"); |
6067 | } else | |
6a9c52cf JS |
6068 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
6069 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", | |
3772a991 JS |
6070 | _dump_buf_dif); |
6071 | } | |
6072 | ||
6073 | /** | |
6074 | * lpfc_post_init_setup - Perform necessary device post initialization setup. | |
6075 | * @phba: pointer to lpfc hba data structure. | |
6076 | * | |
6077 | * This routine is invoked to perform all the necessary post initialization | |
6078 | * setup for the device. | |
6079 | **/ | |
6080 | static void | |
6081 | lpfc_post_init_setup(struct lpfc_hba *phba) | |
6082 | { | |
6083 | struct Scsi_Host *shost; | |
6084 | struct lpfc_adapter_event_header adapter_event; | |
6085 | ||
6086 | /* Get the default values for Model Name and Description */ | |
6087 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
6088 | ||
6089 | /* | |
6090 | * hba setup may have changed the hba_queue_depth so we need to | |
6091 | * adjust the value of can_queue. | |
6092 | */ | |
6093 | shost = pci_get_drvdata(phba->pcidev); | |
6094 | shost->can_queue = phba->cfg_hba_queue_depth - 10; | |
6095 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) | |
6096 | lpfc_setup_bg(phba, shost); | |
6097 | ||
6098 | lpfc_host_attrib_init(shost); | |
6099 | ||
6100 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | |
6101 | spin_lock_irq(shost->host_lock); | |
6102 | lpfc_poll_start_timer(phba); | |
6103 | spin_unlock_irq(shost->host_lock); | |
6104 | } | |
6105 | ||
6106 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6107 | "0428 Perform SCSI scan\n"); | |
6108 | /* Send board arrival event to upper layer */ | |
6109 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; | |
6110 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; | |
6111 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
6112 | sizeof(adapter_event), | |
6113 | (char *) &adapter_event, | |
6114 | LPFC_NL_VENDOR_ID); | |
6115 | return; | |
6116 | } | |
6117 | ||
6118 | /** | |
6119 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. | |
6120 | * @phba: pointer to lpfc hba data structure. | |
6121 | * | |
6122 | * This routine is invoked to set up the PCI device memory space for device | |
6123 | * with SLI-3 interface spec. | |
6124 | * | |
6125 | * Return codes | |
af901ca1 | 6126 | * 0 - successful |
3772a991 JS |
6127 | * other values - error |
6128 | **/ | |
6129 | static int | |
6130 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) | |
6131 | { | |
6132 | struct pci_dev *pdev; | |
6133 | unsigned long bar0map_len, bar2map_len; | |
6134 | int i, hbq_count; | |
6135 | void *ptr; | |
6136 | int error = -ENODEV; | |
6137 | ||
6138 | /* Obtain PCI device reference */ | |
6139 | if (!phba->pcidev) | |
6140 | return error; | |
6141 | else | |
6142 | pdev = phba->pcidev; | |
6143 | ||
6144 | /* Set the device DMA mask size */ | |
8e68597d MR |
6145 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
6146 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
6147 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
6148 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
3772a991 | 6149 | return error; |
8e68597d MR |
6150 | } |
6151 | } | |
3772a991 JS |
6152 | |
6153 | /* Get the bus address of Bar0 and Bar2 and the number of bytes | |
6154 | * required by each mapping. | |
6155 | */ | |
6156 | phba->pci_bar0_map = pci_resource_start(pdev, 0); | |
6157 | bar0map_len = pci_resource_len(pdev, 0); | |
6158 | ||
6159 | phba->pci_bar2_map = pci_resource_start(pdev, 2); | |
6160 | bar2map_len = pci_resource_len(pdev, 2); | |
6161 | ||
6162 | /* Map HBA SLIM to a kernel virtual address. */ | |
6163 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); | |
6164 | if (!phba->slim_memmap_p) { | |
6165 | dev_printk(KERN_ERR, &pdev->dev, | |
6166 | "ioremap failed for SLIM memory.\n"); | |
6167 | goto out; | |
6168 | } | |
6169 | ||
6170 | /* Map HBA Control Registers to a kernel virtual address. */ | |
6171 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); | |
6172 | if (!phba->ctrl_regs_memmap_p) { | |
6173 | dev_printk(KERN_ERR, &pdev->dev, | |
6174 | "ioremap failed for HBA control registers.\n"); | |
6175 | goto out_iounmap_slim; | |
6176 | } | |
6177 | ||
6178 | /* Allocate memory for SLI-2 structures */ | |
6179 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, | |
6180 | SLI2_SLIM_SIZE, | |
6181 | &phba->slim2p.phys, | |
6182 | GFP_KERNEL); | |
6183 | if (!phba->slim2p.virt) | |
6184 | goto out_iounmap; | |
6185 | ||
6186 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); | |
6187 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); | |
7a470277 JS |
6188 | phba->mbox_ext = (phba->slim2p.virt + |
6189 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); | |
3772a991 JS |
6190 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
6191 | phba->IOCBs = (phba->slim2p.virt + | |
6192 | offsetof(struct lpfc_sli2_slim, IOCBs)); | |
6193 | ||
6194 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, | |
6195 | lpfc_sli_hbq_size(), | |
6196 | &phba->hbqslimp.phys, | |
6197 | GFP_KERNEL); | |
6198 | if (!phba->hbqslimp.virt) | |
6199 | goto out_free_slim; | |
6200 | ||
6201 | hbq_count = lpfc_sli_hbq_count(); | |
6202 | ptr = phba->hbqslimp.virt; | |
6203 | for (i = 0; i < hbq_count; ++i) { | |
6204 | phba->hbqs[i].hbq_virt = ptr; | |
6205 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
6206 | ptr += (lpfc_hbq_defs[i]->entry_count * | |
6207 | sizeof(struct lpfc_hbq_entry)); | |
6208 | } | |
6209 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; | |
6210 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; | |
6211 | ||
6212 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); | |
6213 | ||
6214 | INIT_LIST_HEAD(&phba->rb_pend_list); | |
6215 | ||
6216 | phba->MBslimaddr = phba->slim_memmap_p; | |
6217 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; | |
6218 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; | |
6219 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; | |
6220 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; | |
6221 | ||
6222 | return 0; | |
6223 | ||
6224 | out_free_slim: | |
6225 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
6226 | phba->slim2p.virt, phba->slim2p.phys); | |
6227 | out_iounmap: | |
6228 | iounmap(phba->ctrl_regs_memmap_p); | |
6229 | out_iounmap_slim: | |
6230 | iounmap(phba->slim_memmap_p); | |
6231 | out: | |
6232 | return error; | |
6233 | } | |
6234 | ||
6235 | /** | |
6236 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. | |
6237 | * @phba: pointer to lpfc hba data structure. | |
6238 | * | |
6239 | * This routine is invoked to unset the PCI device memory space for device | |
6240 | * with SLI-3 interface spec. | |
6241 | **/ | |
6242 | static void | |
6243 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) | |
6244 | { | |
6245 | struct pci_dev *pdev; | |
6246 | ||
6247 | /* Obtain PCI device reference */ | |
6248 | if (!phba->pcidev) | |
6249 | return; | |
6250 | else | |
6251 | pdev = phba->pcidev; | |
6252 | ||
6253 | /* Free coherent DMA memory allocated */ | |
6254 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
6255 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
6256 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
6257 | phba->slim2p.virt, phba->slim2p.phys); | |
6258 | ||
6259 | /* I/O memory unmap */ | |
6260 | iounmap(phba->ctrl_regs_memmap_p); | |
6261 | iounmap(phba->slim_memmap_p); | |
6262 | ||
6263 | return; | |
6264 | } | |
6265 | ||
6266 | /** | |
da0436e9 | 6267 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
3772a991 JS |
6268 | * @phba: pointer to lpfc hba data structure. |
6269 | * | |
da0436e9 JS |
6270 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
6271 | * done and check status. | |
3772a991 | 6272 | * |
da0436e9 | 6273 | * Return 0 if successful, otherwise -ENODEV. |
3772a991 | 6274 | **/ |
da0436e9 JS |
6275 | int |
6276 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) | |
3772a991 | 6277 | { |
2fcee4bf JS |
6278 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
6279 | struct lpfc_register reg_data; | |
6280 | int i, port_error = 0; | |
6281 | uint32_t if_type; | |
3772a991 | 6282 | |
9940b97b JS |
6283 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
6284 | memset(®_data, 0, sizeof(reg_data)); | |
2fcee4bf | 6285 | if (!phba->sli4_hba.PSMPHRregaddr) |
da0436e9 | 6286 | return -ENODEV; |
3772a991 | 6287 | |
da0436e9 JS |
6288 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
6289 | for (i = 0; i < 3000; i++) { | |
9940b97b JS |
6290 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
6291 | &portsmphr_reg.word0) || | |
6292 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { | |
2fcee4bf | 6293 | /* Port has a fatal POST error, break out */ |
da0436e9 JS |
6294 | port_error = -ENODEV; |
6295 | break; | |
6296 | } | |
2fcee4bf JS |
6297 | if (LPFC_POST_STAGE_PORT_READY == |
6298 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) | |
da0436e9 | 6299 | break; |
da0436e9 | 6300 | msleep(10); |
3772a991 JS |
6301 | } |
6302 | ||
2fcee4bf JS |
6303 | /* |
6304 | * If there was a port error during POST, then don't proceed with | |
6305 | * other register reads as the data may not be valid. Just exit. | |
6306 | */ | |
6307 | if (port_error) { | |
da0436e9 | 6308 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2fcee4bf JS |
6309 | "1408 Port Failed POST - portsmphr=0x%x, " |
6310 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " | |
6311 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", | |
6312 | portsmphr_reg.word0, | |
6313 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), | |
6314 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), | |
6315 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), | |
6316 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), | |
6317 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), | |
6318 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), | |
6319 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), | |
6320 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); | |
6321 | } else { | |
28baac74 | 6322 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2fcee4bf JS |
6323 | "2534 Device Info: SLIFamily=0x%x, " |
6324 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " | |
6325 | "SLIHint_2=0x%x, FT=0x%x\n", | |
28baac74 JS |
6326 | bf_get(lpfc_sli_intf_sli_family, |
6327 | &phba->sli4_hba.sli_intf), | |
6328 | bf_get(lpfc_sli_intf_slirev, | |
6329 | &phba->sli4_hba.sli_intf), | |
085c647c JS |
6330 | bf_get(lpfc_sli_intf_if_type, |
6331 | &phba->sli4_hba.sli_intf), | |
6332 | bf_get(lpfc_sli_intf_sli_hint1, | |
28baac74 | 6333 | &phba->sli4_hba.sli_intf), |
085c647c JS |
6334 | bf_get(lpfc_sli_intf_sli_hint2, |
6335 | &phba->sli4_hba.sli_intf), | |
6336 | bf_get(lpfc_sli_intf_func_type, | |
28baac74 | 6337 | &phba->sli4_hba.sli_intf)); |
2fcee4bf JS |
6338 | /* |
6339 | * Check for other Port errors during the initialization | |
6340 | * process. Fail the load if the port did not come up | |
6341 | * correctly. | |
6342 | */ | |
6343 | if_type = bf_get(lpfc_sli_intf_if_type, | |
6344 | &phba->sli4_hba.sli_intf); | |
6345 | switch (if_type) { | |
6346 | case LPFC_SLI_INTF_IF_TYPE_0: | |
6347 | phba->sli4_hba.ue_mask_lo = | |
6348 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); | |
6349 | phba->sli4_hba.ue_mask_hi = | |
6350 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); | |
6351 | uerrlo_reg.word0 = | |
6352 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); | |
6353 | uerrhi_reg.word0 = | |
6354 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); | |
6355 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || | |
6356 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { | |
6357 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6358 | "1422 Unrecoverable Error " | |
6359 | "Detected during POST " | |
6360 | "uerr_lo_reg=0x%x, " | |
6361 | "uerr_hi_reg=0x%x, " | |
6362 | "ue_mask_lo_reg=0x%x, " | |
6363 | "ue_mask_hi_reg=0x%x\n", | |
6364 | uerrlo_reg.word0, | |
6365 | uerrhi_reg.word0, | |
6366 | phba->sli4_hba.ue_mask_lo, | |
6367 | phba->sli4_hba.ue_mask_hi); | |
6368 | port_error = -ENODEV; | |
6369 | } | |
6370 | break; | |
6371 | case LPFC_SLI_INTF_IF_TYPE_2: | |
6372 | /* Final checks. The port status should be clean. */ | |
9940b97b JS |
6373 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
6374 | ®_data.word0) || | |
0558056c JS |
6375 | (bf_get(lpfc_sliport_status_err, ®_data) && |
6376 | !bf_get(lpfc_sliport_status_rn, ®_data))) { | |
2fcee4bf JS |
6377 | phba->work_status[0] = |
6378 | readl(phba->sli4_hba.u.if_type2. | |
6379 | ERR1regaddr); | |
6380 | phba->work_status[1] = | |
6381 | readl(phba->sli4_hba.u.if_type2. | |
6382 | ERR2regaddr); | |
6383 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8fcb8acd JS |
6384 | "2888 Unrecoverable port error " |
6385 | "following POST: port status reg " | |
6386 | "0x%x, port_smphr reg 0x%x, " | |
2fcee4bf JS |
6387 | "error 1=0x%x, error 2=0x%x\n", |
6388 | reg_data.word0, | |
6389 | portsmphr_reg.word0, | |
6390 | phba->work_status[0], | |
6391 | phba->work_status[1]); | |
6392 | port_error = -ENODEV; | |
6393 | } | |
6394 | break; | |
6395 | case LPFC_SLI_INTF_IF_TYPE_1: | |
6396 | default: | |
6397 | break; | |
6398 | } | |
28baac74 | 6399 | } |
da0436e9 JS |
6400 | return port_error; |
6401 | } | |
3772a991 | 6402 | |
da0436e9 JS |
6403 | /** |
6404 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. | |
6405 | * @phba: pointer to lpfc hba data structure. | |
2fcee4bf | 6406 | * @if_type: The SLI4 interface type getting configured. |
da0436e9 JS |
6407 | * |
6408 | * This routine is invoked to set up SLI4 BAR0 PCI config space register | |
6409 | * memory map. | |
6410 | **/ | |
6411 | static void | |
2fcee4bf JS |
6412 | lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type) |
6413 | { | |
6414 | switch (if_type) { | |
6415 | case LPFC_SLI_INTF_IF_TYPE_0: | |
6416 | phba->sli4_hba.u.if_type0.UERRLOregaddr = | |
6417 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; | |
6418 | phba->sli4_hba.u.if_type0.UERRHIregaddr = | |
6419 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; | |
6420 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = | |
6421 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; | |
6422 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = | |
6423 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; | |
6424 | phba->sli4_hba.SLIINTFregaddr = | |
6425 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; | |
6426 | break; | |
6427 | case LPFC_SLI_INTF_IF_TYPE_2: | |
6428 | phba->sli4_hba.u.if_type2.ERR1regaddr = | |
88a2cfbb JS |
6429 | phba->sli4_hba.conf_regs_memmap_p + |
6430 | LPFC_CTL_PORT_ER1_OFFSET; | |
2fcee4bf | 6431 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
88a2cfbb JS |
6432 | phba->sli4_hba.conf_regs_memmap_p + |
6433 | LPFC_CTL_PORT_ER2_OFFSET; | |
2fcee4bf | 6434 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
88a2cfbb JS |
6435 | phba->sli4_hba.conf_regs_memmap_p + |
6436 | LPFC_CTL_PORT_CTL_OFFSET; | |
2fcee4bf | 6437 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
88a2cfbb JS |
6438 | phba->sli4_hba.conf_regs_memmap_p + |
6439 | LPFC_CTL_PORT_STA_OFFSET; | |
2fcee4bf JS |
6440 | phba->sli4_hba.SLIINTFregaddr = |
6441 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; | |
6442 | phba->sli4_hba.PSMPHRregaddr = | |
88a2cfbb JS |
6443 | phba->sli4_hba.conf_regs_memmap_p + |
6444 | LPFC_CTL_PORT_SEM_OFFSET; | |
2fcee4bf | 6445 | phba->sli4_hba.RQDBregaddr = |
962bc51b JS |
6446 | phba->sli4_hba.conf_regs_memmap_p + |
6447 | LPFC_ULP0_RQ_DOORBELL; | |
2fcee4bf | 6448 | phba->sli4_hba.WQDBregaddr = |
962bc51b JS |
6449 | phba->sli4_hba.conf_regs_memmap_p + |
6450 | LPFC_ULP0_WQ_DOORBELL; | |
2fcee4bf JS |
6451 | phba->sli4_hba.EQCQDBregaddr = |
6452 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; | |
6453 | phba->sli4_hba.MQDBregaddr = | |
6454 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; | |
6455 | phba->sli4_hba.BMBXregaddr = | |
6456 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; | |
6457 | break; | |
6458 | case LPFC_SLI_INTF_IF_TYPE_1: | |
6459 | default: | |
6460 | dev_printk(KERN_ERR, &phba->pcidev->dev, | |
6461 | "FATAL - unsupported SLI4 interface type - %d\n", | |
6462 | if_type); | |
6463 | break; | |
6464 | } | |
da0436e9 | 6465 | } |
3772a991 | 6466 | |
da0436e9 JS |
6467 | /** |
6468 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. | |
6469 | * @phba: pointer to lpfc hba data structure. | |
6470 | * | |
6471 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) | |
6472 | * memory map. | |
6473 | **/ | |
6474 | static void | |
6475 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) | |
6476 | { | |
2fcee4bf JS |
6477 | phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
6478 | LPFC_SLIPORT_IF0_SMPHR; | |
da0436e9 | 6479 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 6480 | LPFC_HST_ISR0; |
da0436e9 | 6481 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 6482 | LPFC_HST_IMR0; |
da0436e9 | 6483 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 6484 | LPFC_HST_ISCR0; |
3772a991 JS |
6485 | } |
6486 | ||
6487 | /** | |
da0436e9 | 6488 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
3772a991 | 6489 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 6490 | * @vf: virtual function number |
3772a991 | 6491 | * |
da0436e9 JS |
6492 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
6493 | * based on the given viftual function number, @vf. | |
6494 | * | |
6495 | * Return 0 if successful, otherwise -ENODEV. | |
3772a991 | 6496 | **/ |
da0436e9 JS |
6497 | static int |
6498 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) | |
3772a991 | 6499 | { |
da0436e9 JS |
6500 | if (vf > LPFC_VIR_FUNC_MAX) |
6501 | return -ENODEV; | |
3772a991 | 6502 | |
da0436e9 | 6503 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
962bc51b JS |
6504 | vf * LPFC_VFR_PAGE_SIZE + |
6505 | LPFC_ULP0_RQ_DOORBELL); | |
da0436e9 | 6506 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
962bc51b JS |
6507 | vf * LPFC_VFR_PAGE_SIZE + |
6508 | LPFC_ULP0_WQ_DOORBELL); | |
da0436e9 JS |
6509 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
6510 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); | |
6511 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
6512 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); | |
6513 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
6514 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); | |
6515 | return 0; | |
3772a991 JS |
6516 | } |
6517 | ||
6518 | /** | |
da0436e9 | 6519 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
3772a991 JS |
6520 | * @phba: pointer to lpfc hba data structure. |
6521 | * | |
da0436e9 JS |
6522 | * This routine is invoked to create the bootstrap mailbox |
6523 | * region consistent with the SLI-4 interface spec. This | |
6524 | * routine allocates all memory necessary to communicate | |
6525 | * mailbox commands to the port and sets up all alignment | |
6526 | * needs. No locks are expected to be held when calling | |
6527 | * this routine. | |
3772a991 JS |
6528 | * |
6529 | * Return codes | |
af901ca1 | 6530 | * 0 - successful |
d439d286 | 6531 | * -ENOMEM - could not allocated memory. |
da0436e9 | 6532 | **/ |
3772a991 | 6533 | static int |
da0436e9 | 6534 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 6535 | { |
da0436e9 JS |
6536 | uint32_t bmbx_size; |
6537 | struct lpfc_dmabuf *dmabuf; | |
6538 | struct dma_address *dma_address; | |
6539 | uint32_t pa_addr; | |
6540 | uint64_t phys_addr; | |
6541 | ||
6542 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
6543 | if (!dmabuf) | |
6544 | return -ENOMEM; | |
3772a991 | 6545 | |
da0436e9 JS |
6546 | /* |
6547 | * The bootstrap mailbox region is comprised of 2 parts | |
6548 | * plus an alignment restriction of 16 bytes. | |
6549 | */ | |
6550 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); | |
6551 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
6552 | bmbx_size, | |
6553 | &dmabuf->phys, | |
6554 | GFP_KERNEL); | |
6555 | if (!dmabuf->virt) { | |
6556 | kfree(dmabuf); | |
6557 | return -ENOMEM; | |
3772a991 | 6558 | } |
da0436e9 | 6559 | memset(dmabuf->virt, 0, bmbx_size); |
3772a991 | 6560 | |
da0436e9 JS |
6561 | /* |
6562 | * Initialize the bootstrap mailbox pointers now so that the register | |
6563 | * operations are simple later. The mailbox dma address is required | |
6564 | * to be 16-byte aligned. Also align the virtual memory as each | |
6565 | * maibox is copied into the bmbx mailbox region before issuing the | |
6566 | * command to the port. | |
6567 | */ | |
6568 | phba->sli4_hba.bmbx.dmabuf = dmabuf; | |
6569 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; | |
6570 | ||
6571 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, | |
6572 | LPFC_ALIGN_16_BYTE); | |
6573 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, | |
6574 | LPFC_ALIGN_16_BYTE); | |
6575 | ||
6576 | /* | |
6577 | * Set the high and low physical addresses now. The SLI4 alignment | |
6578 | * requirement is 16 bytes and the mailbox is posted to the port | |
6579 | * as two 30-bit addresses. The other data is a bit marking whether | |
6580 | * the 30-bit address is the high or low address. | |
6581 | * Upcast bmbx aphys to 64bits so shift instruction compiles | |
6582 | * clean on 32 bit machines. | |
6583 | */ | |
6584 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
6585 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; | |
6586 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); | |
6587 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | | |
6588 | LPFC_BMBX_BIT1_ADDR_HI); | |
6589 | ||
6590 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); | |
6591 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | | |
6592 | LPFC_BMBX_BIT1_ADDR_LO); | |
6593 | return 0; | |
3772a991 JS |
6594 | } |
6595 | ||
6596 | /** | |
da0436e9 | 6597 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
3772a991 JS |
6598 | * @phba: pointer to lpfc hba data structure. |
6599 | * | |
da0436e9 JS |
6600 | * This routine is invoked to teardown the bootstrap mailbox |
6601 | * region and release all host resources. This routine requires | |
6602 | * the caller to ensure all mailbox commands recovered, no | |
6603 | * additional mailbox comands are sent, and interrupts are disabled | |
6604 | * before calling this routine. | |
6605 | * | |
6606 | **/ | |
3772a991 | 6607 | static void |
da0436e9 | 6608 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 6609 | { |
da0436e9 JS |
6610 | dma_free_coherent(&phba->pcidev->dev, |
6611 | phba->sli4_hba.bmbx.bmbx_size, | |
6612 | phba->sli4_hba.bmbx.dmabuf->virt, | |
6613 | phba->sli4_hba.bmbx.dmabuf->phys); | |
6614 | ||
6615 | kfree(phba->sli4_hba.bmbx.dmabuf); | |
6616 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); | |
3772a991 JS |
6617 | } |
6618 | ||
6619 | /** | |
da0436e9 | 6620 | * lpfc_sli4_read_config - Get the config parameters. |
3772a991 JS |
6621 | * @phba: pointer to lpfc hba data structure. |
6622 | * | |
da0436e9 JS |
6623 | * This routine is invoked to read the configuration parameters from the HBA. |
6624 | * The configuration parameters are used to set the base and maximum values | |
6625 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource | |
6626 | * allocation for the port. | |
3772a991 JS |
6627 | * |
6628 | * Return codes | |
af901ca1 | 6629 | * 0 - successful |
25985edc | 6630 | * -ENOMEM - No available memory |
d439d286 | 6631 | * -EIO - The mailbox failed to complete successfully. |
3772a991 | 6632 | **/ |
ff78d8f9 | 6633 | int |
da0436e9 | 6634 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
3772a991 | 6635 | { |
da0436e9 JS |
6636 | LPFC_MBOXQ_t *pmb; |
6637 | struct lpfc_mbx_read_config *rd_config; | |
912e3acd JS |
6638 | union lpfc_sli4_cfg_shdr *shdr; |
6639 | uint32_t shdr_status, shdr_add_status; | |
6640 | struct lpfc_mbx_get_func_cfg *get_func_cfg; | |
6641 | struct lpfc_rsrc_desc_fcfcoe *desc; | |
8aa134a8 | 6642 | char *pdesc_0; |
912e3acd | 6643 | uint32_t desc_count; |
8aa134a8 | 6644 | int length, i, rc = 0, rc2; |
3772a991 | 6645 | |
da0436e9 JS |
6646 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
6647 | if (!pmb) { | |
6648 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6649 | "2011 Unable to allocate memory for issuing " | |
6650 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
6651 | return -ENOMEM; | |
3772a991 JS |
6652 | } |
6653 | ||
da0436e9 | 6654 | lpfc_read_config(phba, pmb); |
3772a991 | 6655 | |
da0436e9 JS |
6656 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
6657 | if (rc != MBX_SUCCESS) { | |
6658 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6659 | "2012 Mailbox failed , mbxCmd x%x " | |
6660 | "READ_CONFIG, mbxStatus x%x\n", | |
6661 | bf_get(lpfc_mqe_command, &pmb->u.mqe), | |
6662 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); | |
6663 | rc = -EIO; | |
6664 | } else { | |
6665 | rd_config = &pmb->u.mqe.un.rd_config; | |
ff78d8f9 JS |
6666 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
6667 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; | |
6668 | phba->sli4_hba.lnk_info.lnk_tp = | |
6669 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); | |
6670 | phba->sli4_hba.lnk_info.lnk_no = | |
6671 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); | |
6672 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
6673 | "3081 lnk_type:%d, lnk_numb:%d\n", | |
6674 | phba->sli4_hba.lnk_info.lnk_tp, | |
6675 | phba->sli4_hba.lnk_info.lnk_no); | |
6676 | } else | |
6677 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
6678 | "3082 Mailbox (x%x) returned ldv:x0\n", | |
6679 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); | |
6d368e53 JS |
6680 | phba->sli4_hba.extents_in_use = |
6681 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); | |
da0436e9 JS |
6682 | phba->sli4_hba.max_cfg_param.max_xri = |
6683 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); | |
6684 | phba->sli4_hba.max_cfg_param.xri_base = | |
6685 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); | |
6686 | phba->sli4_hba.max_cfg_param.max_vpi = | |
6687 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); | |
6688 | phba->sli4_hba.max_cfg_param.vpi_base = | |
6689 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); | |
6690 | phba->sli4_hba.max_cfg_param.max_rpi = | |
6691 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); | |
6692 | phba->sli4_hba.max_cfg_param.rpi_base = | |
6693 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); | |
6694 | phba->sli4_hba.max_cfg_param.max_vfi = | |
6695 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); | |
6696 | phba->sli4_hba.max_cfg_param.vfi_base = | |
6697 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); | |
6698 | phba->sli4_hba.max_cfg_param.max_fcfi = | |
6699 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); | |
da0436e9 JS |
6700 | phba->sli4_hba.max_cfg_param.max_eq = |
6701 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); | |
6702 | phba->sli4_hba.max_cfg_param.max_rq = | |
6703 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); | |
6704 | phba->sli4_hba.max_cfg_param.max_wq = | |
6705 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); | |
6706 | phba->sli4_hba.max_cfg_param.max_cq = | |
6707 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); | |
6708 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); | |
6709 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; | |
6710 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; | |
6711 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; | |
5ffc266e JS |
6712 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
6713 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; | |
da0436e9 JS |
6714 | phba->max_vports = phba->max_vpi; |
6715 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
6d368e53 JS |
6716 | "2003 cfg params Extents? %d " |
6717 | "XRI(B:%d M:%d), " | |
da0436e9 JS |
6718 | "VPI(B:%d M:%d) " |
6719 | "VFI(B:%d M:%d) " | |
6720 | "RPI(B:%d M:%d) " | |
6d368e53 JS |
6721 | "FCFI(Count:%d)\n", |
6722 | phba->sli4_hba.extents_in_use, | |
da0436e9 JS |
6723 | phba->sli4_hba.max_cfg_param.xri_base, |
6724 | phba->sli4_hba.max_cfg_param.max_xri, | |
6725 | phba->sli4_hba.max_cfg_param.vpi_base, | |
6726 | phba->sli4_hba.max_cfg_param.max_vpi, | |
6727 | phba->sli4_hba.max_cfg_param.vfi_base, | |
6728 | phba->sli4_hba.max_cfg_param.max_vfi, | |
6729 | phba->sli4_hba.max_cfg_param.rpi_base, | |
6730 | phba->sli4_hba.max_cfg_param.max_rpi, | |
da0436e9 | 6731 | phba->sli4_hba.max_cfg_param.max_fcfi); |
3772a991 | 6732 | } |
912e3acd JS |
6733 | |
6734 | if (rc) | |
6735 | goto read_cfg_out; | |
da0436e9 JS |
6736 | |
6737 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ | |
572709e2 JS |
6738 | length = phba->sli4_hba.max_cfg_param.max_xri - |
6739 | lpfc_sli4_get_els_iocb_cnt(phba); | |
6740 | if (phba->cfg_hba_queue_depth > length) { | |
6741 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6742 | "3361 HBA queue depth changed from %d to %d\n", | |
6743 | phba->cfg_hba_queue_depth, length); | |
6744 | phba->cfg_hba_queue_depth = length; | |
6745 | } | |
912e3acd JS |
6746 | |
6747 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
6748 | LPFC_SLI_INTF_IF_TYPE_2) | |
6749 | goto read_cfg_out; | |
6750 | ||
6751 | /* get the pf# and vf# for SLI4 if_type 2 port */ | |
6752 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - | |
6753 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
6754 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, | |
6755 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, | |
6756 | length, LPFC_SLI4_MBX_EMBED); | |
6757 | ||
8aa134a8 | 6758 | rc2 = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
912e3acd JS |
6759 | shdr = (union lpfc_sli4_cfg_shdr *) |
6760 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; | |
6761 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
6762 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
8aa134a8 | 6763 | if (rc2 || shdr_status || shdr_add_status) { |
912e3acd JS |
6764 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
6765 | "3026 Mailbox failed , mbxCmd x%x " | |
6766 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", | |
6767 | bf_get(lpfc_mqe_command, &pmb->u.mqe), | |
6768 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); | |
912e3acd JS |
6769 | goto read_cfg_out; |
6770 | } | |
6771 | ||
6772 | /* search for fc_fcoe resrouce descriptor */ | |
6773 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; | |
6774 | desc_count = get_func_cfg->func_cfg.rsrc_desc_count; | |
6775 | ||
8aa134a8 JS |
6776 | pdesc_0 = (char *)&get_func_cfg->func_cfg.desc[0]; |
6777 | desc = (struct lpfc_rsrc_desc_fcfcoe *)pdesc_0; | |
6778 | length = bf_get(lpfc_rsrc_desc_fcfcoe_length, desc); | |
6779 | if (length == LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD) | |
6780 | length = LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH; | |
6781 | else if (length != LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH) | |
6782 | goto read_cfg_out; | |
6783 | ||
912e3acd | 6784 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { |
8aa134a8 | 6785 | desc = (struct lpfc_rsrc_desc_fcfcoe *)(pdesc_0 + length * i); |
912e3acd | 6786 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == |
8aa134a8 | 6787 | bf_get(lpfc_rsrc_desc_fcfcoe_type, desc)) { |
912e3acd JS |
6788 | phba->sli4_hba.iov.pf_number = |
6789 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); | |
6790 | phba->sli4_hba.iov.vf_number = | |
6791 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); | |
6792 | break; | |
6793 | } | |
6794 | } | |
6795 | ||
6796 | if (i < LPFC_RSRC_DESC_MAX_NUM) | |
6797 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
6798 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " | |
6799 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, | |
6800 | phba->sli4_hba.iov.vf_number); | |
8aa134a8 | 6801 | else |
912e3acd JS |
6802 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
6803 | "3028 GET_FUNCTION_CONFIG: failed to find " | |
6804 | "Resrouce Descriptor:x%x\n", | |
6805 | LPFC_RSRC_DESC_TYPE_FCFCOE); | |
912e3acd JS |
6806 | |
6807 | read_cfg_out: | |
6808 | mempool_free(pmb, phba->mbox_mem_pool); | |
da0436e9 | 6809 | return rc; |
3772a991 JS |
6810 | } |
6811 | ||
6812 | /** | |
2fcee4bf | 6813 | * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port. |
3772a991 JS |
6814 | * @phba: pointer to lpfc hba data structure. |
6815 | * | |
2fcee4bf JS |
6816 | * This routine is invoked to setup the port-side endian order when |
6817 | * the port if_type is 0. This routine has no function for other | |
6818 | * if_types. | |
da0436e9 JS |
6819 | * |
6820 | * Return codes | |
af901ca1 | 6821 | * 0 - successful |
25985edc | 6822 | * -ENOMEM - No available memory |
d439d286 | 6823 | * -EIO - The mailbox failed to complete successfully. |
3772a991 | 6824 | **/ |
da0436e9 JS |
6825 | static int |
6826 | lpfc_setup_endian_order(struct lpfc_hba *phba) | |
3772a991 | 6827 | { |
da0436e9 | 6828 | LPFC_MBOXQ_t *mboxq; |
2fcee4bf | 6829 | uint32_t if_type, rc = 0; |
da0436e9 JS |
6830 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
6831 | HOST_ENDIAN_HIGH_WORD1}; | |
3772a991 | 6832 | |
2fcee4bf JS |
6833 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
6834 | switch (if_type) { | |
6835 | case LPFC_SLI_INTF_IF_TYPE_0: | |
6836 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, | |
6837 | GFP_KERNEL); | |
6838 | if (!mboxq) { | |
6839 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6840 | "0492 Unable to allocate memory for " | |
6841 | "issuing SLI_CONFIG_SPECIAL mailbox " | |
6842 | "command\n"); | |
6843 | return -ENOMEM; | |
6844 | } | |
3772a991 | 6845 | |
2fcee4bf JS |
6846 | /* |
6847 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first | |
6848 | * two words to contain special data values and no other data. | |
6849 | */ | |
6850 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
6851 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); | |
6852 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6853 | if (rc != MBX_SUCCESS) { | |
6854 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6855 | "0493 SLI_CONFIG_SPECIAL mailbox " | |
6856 | "failed with status x%x\n", | |
6857 | rc); | |
6858 | rc = -EIO; | |
6859 | } | |
6860 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6861 | break; | |
6862 | case LPFC_SLI_INTF_IF_TYPE_2: | |
6863 | case LPFC_SLI_INTF_IF_TYPE_1: | |
6864 | default: | |
6865 | break; | |
da0436e9 | 6866 | } |
da0436e9 | 6867 | return rc; |
3772a991 JS |
6868 | } |
6869 | ||
6870 | /** | |
5350d872 | 6871 | * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts |
3772a991 JS |
6872 | * @phba: pointer to lpfc hba data structure. |
6873 | * | |
5350d872 JS |
6874 | * This routine is invoked to check the user settable queue counts for EQs and |
6875 | * CQs. after this routine is called the counts will be set to valid values that | |
6876 | * adhere to the constraints of the system's interrupt vectors and the port's | |
6877 | * queue resources. | |
da0436e9 JS |
6878 | * |
6879 | * Return codes | |
af901ca1 | 6880 | * 0 - successful |
25985edc | 6881 | * -ENOMEM - No available memory |
3772a991 | 6882 | **/ |
da0436e9 | 6883 | static int |
5350d872 | 6884 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
3772a991 | 6885 | { |
67d12733 | 6886 | int cfg_fcp_io_channel; |
90695ee0 JS |
6887 | uint32_t cpu; |
6888 | uint32_t i = 0; | |
1ba981fd | 6889 | int fof_vectors = phba->cfg_fof ? 1 : 0; |
3772a991 | 6890 | |
da0436e9 | 6891 | /* |
67d12733 | 6892 | * Sanity check for configured queue parameters against the run-time |
da0436e9 JS |
6893 | * device parameters |
6894 | */ | |
3772a991 | 6895 | |
67d12733 JS |
6896 | /* Sanity check on HBA EQ parameters */ |
6897 | cfg_fcp_io_channel = phba->cfg_fcp_io_channel; | |
6898 | ||
7bb03bbf JS |
6899 | /* It doesn't make sense to have more io channels then online CPUs */ |
6900 | for_each_present_cpu(cpu) { | |
6901 | if (cpu_online(cpu)) | |
6902 | i++; | |
90695ee0 | 6903 | } |
7bb03bbf | 6904 | phba->sli4_hba.num_online_cpu = i; |
b246de17 | 6905 | phba->sli4_hba.num_present_cpu = lpfc_present_cpu; |
76fd07a6 | 6906 | phba->sli4_hba.curr_disp_cpu = 0; |
7bb03bbf | 6907 | |
90695ee0 | 6908 | if (i < cfg_fcp_io_channel) { |
82c3e9ba JS |
6909 | lpfc_printf_log(phba, |
6910 | KERN_ERR, LOG_INIT, | |
90695ee0 | 6911 | "3188 Reducing IO channels to match number of " |
7bb03bbf JS |
6912 | "online CPUs: from %d to %d\n", |
6913 | cfg_fcp_io_channel, i); | |
90695ee0 JS |
6914 | cfg_fcp_io_channel = i; |
6915 | } | |
6916 | ||
1ba981fd | 6917 | if (cfg_fcp_io_channel + fof_vectors > |
67d12733 | 6918 | phba->sli4_hba.max_cfg_param.max_eq) { |
82c3e9ba JS |
6919 | if (phba->sli4_hba.max_cfg_param.max_eq < |
6920 | LPFC_FCP_IO_CHAN_MIN) { | |
da0436e9 JS |
6921 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
6922 | "2574 Not enough EQs (%d) from the " | |
6923 | "pci function for supporting FCP " | |
6924 | "EQs (%d)\n", | |
6925 | phba->sli4_hba.max_cfg_param.max_eq, | |
67d12733 | 6926 | phba->cfg_fcp_io_channel); |
da0436e9 JS |
6927 | goto out_error; |
6928 | } | |
82c3e9ba JS |
6929 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
6930 | "2575 Reducing IO channels to match number of " | |
6931 | "available EQs: from %d to %d\n", | |
6932 | cfg_fcp_io_channel, | |
6933 | phba->sli4_hba.max_cfg_param.max_eq); | |
1ba981fd JS |
6934 | cfg_fcp_io_channel = phba->sli4_hba.max_cfg_param.max_eq - |
6935 | fof_vectors; | |
da0436e9 | 6936 | } |
67d12733 | 6937 | |
da0436e9 | 6938 | /* The actual number of FCP event queues adopted */ |
67d12733 | 6939 | phba->cfg_fcp_io_channel = cfg_fcp_io_channel; |
3772a991 | 6940 | |
da0436e9 JS |
6941 | /* Get EQ depth from module parameter, fake the default for now */ |
6942 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; | |
6943 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; | |
3772a991 | 6944 | |
5350d872 JS |
6945 | /* Get CQ depth from module parameter, fake the default for now */ |
6946 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; | |
6947 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; | |
6948 | ||
6949 | return 0; | |
6950 | out_error: | |
6951 | return -ENOMEM; | |
6952 | } | |
6953 | ||
6954 | /** | |
6955 | * lpfc_sli4_queue_create - Create all the SLI4 queues | |
6956 | * @phba: pointer to lpfc hba data structure. | |
6957 | * | |
6958 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA | |
6959 | * operation. For each SLI4 queue type, the parameters such as queue entry | |
6960 | * count (queue depth) shall be taken from the module parameter. For now, | |
6961 | * we just use some constant number as place holder. | |
6962 | * | |
6963 | * Return codes | |
4907cb7b | 6964 | * 0 - successful |
5350d872 JS |
6965 | * -ENOMEM - No availble memory |
6966 | * -EIO - The mailbox failed to complete successfully. | |
6967 | **/ | |
6968 | int | |
6969 | lpfc_sli4_queue_create(struct lpfc_hba *phba) | |
6970 | { | |
6971 | struct lpfc_queue *qdesc; | |
67d12733 | 6972 | int idx; |
5350d872 JS |
6973 | |
6974 | /* | |
67d12733 | 6975 | * Create HBA Record arrays. |
5350d872 | 6976 | */ |
67d12733 JS |
6977 | if (!phba->cfg_fcp_io_channel) |
6978 | return -ERANGE; | |
5350d872 | 6979 | |
67d12733 JS |
6980 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; |
6981 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; | |
6982 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; | |
6983 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; | |
6984 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; | |
6985 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; | |
6986 | ||
6987 | phba->sli4_hba.hba_eq = kzalloc((sizeof(struct lpfc_queue *) * | |
6988 | phba->cfg_fcp_io_channel), GFP_KERNEL); | |
6989 | if (!phba->sli4_hba.hba_eq) { | |
6990 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6991 | "2576 Failed allocate memory for " | |
6992 | "fast-path EQ record array\n"); | |
6993 | goto out_error; | |
6994 | } | |
6995 | ||
6996 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * | |
6997 | phba->cfg_fcp_io_channel), GFP_KERNEL); | |
6998 | if (!phba->sli4_hba.fcp_cq) { | |
da0436e9 | 6999 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
67d12733 JS |
7000 | "2577 Failed allocate memory for fast-path " |
7001 | "CQ record array\n"); | |
7002 | goto out_error; | |
7003 | } | |
7004 | ||
7005 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * | |
7006 | phba->cfg_fcp_io_channel), GFP_KERNEL); | |
7007 | if (!phba->sli4_hba.fcp_wq) { | |
7008 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7009 | "2578 Failed allocate memory for fast-path " | |
7010 | "WQ record array\n"); | |
da0436e9 JS |
7011 | goto out_error; |
7012 | } | |
da0436e9 | 7013 | |
5350d872 | 7014 | /* |
67d12733 JS |
7015 | * Since the first EQ can have multiple CQs associated with it, |
7016 | * this array is used to quickly see if we have a FCP fast-path | |
7017 | * CQ match. | |
5350d872 | 7018 | */ |
67d12733 JS |
7019 | phba->sli4_hba.fcp_cq_map = kzalloc((sizeof(uint16_t) * |
7020 | phba->cfg_fcp_io_channel), GFP_KERNEL); | |
7021 | if (!phba->sli4_hba.fcp_cq_map) { | |
7022 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7023 | "2545 Failed allocate memory for fast-path " | |
7024 | "CQ map\n"); | |
7025 | goto out_error; | |
da0436e9 | 7026 | } |
67d12733 JS |
7027 | |
7028 | /* | |
7029 | * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies | |
7030 | * how many EQs to create. | |
7031 | */ | |
7032 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { | |
7033 | ||
7034 | /* Create EQs */ | |
da0436e9 JS |
7035 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, |
7036 | phba->sli4_hba.eq_ecount); | |
7037 | if (!qdesc) { | |
7038 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
67d12733 JS |
7039 | "0497 Failed allocate EQ (%d)\n", idx); |
7040 | goto out_error; | |
da0436e9 | 7041 | } |
67d12733 JS |
7042 | phba->sli4_hba.hba_eq[idx] = qdesc; |
7043 | ||
7044 | /* Create Fast Path FCP CQs */ | |
7045 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
7046 | phba->sli4_hba.cq_ecount); | |
7047 | if (!qdesc) { | |
7048 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7049 | "0499 Failed allocate fast-path FCP " | |
7050 | "CQ (%d)\n", idx); | |
7051 | goto out_error; | |
7052 | } | |
7053 | phba->sli4_hba.fcp_cq[idx] = qdesc; | |
7054 | ||
7055 | /* Create Fast Path FCP WQs */ | |
7056 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
7057 | phba->sli4_hba.wq_ecount); | |
7058 | if (!qdesc) { | |
7059 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7060 | "0503 Failed allocate fast-path FCP " | |
7061 | "WQ (%d)\n", idx); | |
7062 | goto out_error; | |
7063 | } | |
7064 | phba->sli4_hba.fcp_wq[idx] = qdesc; | |
da0436e9 JS |
7065 | } |
7066 | ||
67d12733 | 7067 | |
da0436e9 | 7068 | /* |
67d12733 | 7069 | * Create Slow Path Completion Queues (CQs) |
da0436e9 JS |
7070 | */ |
7071 | ||
da0436e9 JS |
7072 | /* Create slow-path Mailbox Command Complete Queue */ |
7073 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
7074 | phba->sli4_hba.cq_ecount); | |
7075 | if (!qdesc) { | |
7076 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7077 | "0500 Failed allocate slow-path mailbox CQ\n"); | |
67d12733 | 7078 | goto out_error; |
da0436e9 JS |
7079 | } |
7080 | phba->sli4_hba.mbx_cq = qdesc; | |
7081 | ||
7082 | /* Create slow-path ELS Complete Queue */ | |
7083 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
7084 | phba->sli4_hba.cq_ecount); | |
7085 | if (!qdesc) { | |
7086 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7087 | "0501 Failed allocate slow-path ELS CQ\n"); | |
67d12733 | 7088 | goto out_error; |
da0436e9 JS |
7089 | } |
7090 | phba->sli4_hba.els_cq = qdesc; | |
7091 | ||
da0436e9 | 7092 | |
5350d872 | 7093 | /* |
67d12733 | 7094 | * Create Slow Path Work Queues (WQs) |
5350d872 | 7095 | */ |
da0436e9 JS |
7096 | |
7097 | /* Create Mailbox Command Queue */ | |
da0436e9 JS |
7098 | |
7099 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, | |
7100 | phba->sli4_hba.mq_ecount); | |
7101 | if (!qdesc) { | |
7102 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7103 | "0505 Failed allocate slow-path MQ\n"); | |
67d12733 | 7104 | goto out_error; |
da0436e9 JS |
7105 | } |
7106 | phba->sli4_hba.mbx_wq = qdesc; | |
7107 | ||
7108 | /* | |
67d12733 | 7109 | * Create ELS Work Queues |
da0436e9 | 7110 | */ |
da0436e9 JS |
7111 | |
7112 | /* Create slow-path ELS Work Queue */ | |
7113 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
7114 | phba->sli4_hba.wq_ecount); | |
7115 | if (!qdesc) { | |
7116 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7117 | "0504 Failed allocate slow-path ELS WQ\n"); | |
67d12733 | 7118 | goto out_error; |
da0436e9 JS |
7119 | } |
7120 | phba->sli4_hba.els_wq = qdesc; | |
7121 | ||
da0436e9 JS |
7122 | /* |
7123 | * Create Receive Queue (RQ) | |
7124 | */ | |
da0436e9 JS |
7125 | |
7126 | /* Create Receive Queue for header */ | |
7127 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
7128 | phba->sli4_hba.rq_ecount); | |
7129 | if (!qdesc) { | |
7130 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7131 | "0506 Failed allocate receive HRQ\n"); | |
67d12733 | 7132 | goto out_error; |
da0436e9 JS |
7133 | } |
7134 | phba->sli4_hba.hdr_rq = qdesc; | |
7135 | ||
7136 | /* Create Receive Queue for data */ | |
7137 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
7138 | phba->sli4_hba.rq_ecount); | |
7139 | if (!qdesc) { | |
7140 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7141 | "0507 Failed allocate receive DRQ\n"); | |
67d12733 | 7142 | goto out_error; |
da0436e9 JS |
7143 | } |
7144 | phba->sli4_hba.dat_rq = qdesc; | |
7145 | ||
1ba981fd JS |
7146 | /* Create the Queues needed for Flash Optimized Fabric operations */ |
7147 | if (phba->cfg_fof) | |
7148 | lpfc_fof_queue_create(phba); | |
da0436e9 JS |
7149 | return 0; |
7150 | ||
da0436e9 | 7151 | out_error: |
67d12733 | 7152 | lpfc_sli4_queue_destroy(phba); |
da0436e9 JS |
7153 | return -ENOMEM; |
7154 | } | |
7155 | ||
7156 | /** | |
7157 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues | |
7158 | * @phba: pointer to lpfc hba data structure. | |
7159 | * | |
7160 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA | |
7161 | * operation. | |
7162 | * | |
7163 | * Return codes | |
af901ca1 | 7164 | * 0 - successful |
25985edc | 7165 | * -ENOMEM - No available memory |
d439d286 | 7166 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 | 7167 | **/ |
5350d872 | 7168 | void |
da0436e9 JS |
7169 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
7170 | { | |
67d12733 JS |
7171 | int idx; |
7172 | ||
1ba981fd JS |
7173 | if (phba->cfg_fof) |
7174 | lpfc_fof_queue_destroy(phba); | |
7175 | ||
67d12733 JS |
7176 | if (phba->sli4_hba.hba_eq != NULL) { |
7177 | /* Release HBA event queue */ | |
7178 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { | |
7179 | if (phba->sli4_hba.hba_eq[idx] != NULL) { | |
7180 | lpfc_sli4_queue_free( | |
7181 | phba->sli4_hba.hba_eq[idx]); | |
7182 | phba->sli4_hba.hba_eq[idx] = NULL; | |
7183 | } | |
7184 | } | |
7185 | kfree(phba->sli4_hba.hba_eq); | |
7186 | phba->sli4_hba.hba_eq = NULL; | |
7187 | } | |
7188 | ||
7189 | if (phba->sli4_hba.fcp_cq != NULL) { | |
7190 | /* Release FCP completion queue */ | |
7191 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { | |
7192 | if (phba->sli4_hba.fcp_cq[idx] != NULL) { | |
7193 | lpfc_sli4_queue_free( | |
7194 | phba->sli4_hba.fcp_cq[idx]); | |
7195 | phba->sli4_hba.fcp_cq[idx] = NULL; | |
7196 | } | |
7197 | } | |
7198 | kfree(phba->sli4_hba.fcp_cq); | |
7199 | phba->sli4_hba.fcp_cq = NULL; | |
7200 | } | |
7201 | ||
7202 | if (phba->sli4_hba.fcp_wq != NULL) { | |
7203 | /* Release FCP work queue */ | |
7204 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) { | |
7205 | if (phba->sli4_hba.fcp_wq[idx] != NULL) { | |
7206 | lpfc_sli4_queue_free( | |
7207 | phba->sli4_hba.fcp_wq[idx]); | |
7208 | phba->sli4_hba.fcp_wq[idx] = NULL; | |
7209 | } | |
7210 | } | |
7211 | kfree(phba->sli4_hba.fcp_wq); | |
7212 | phba->sli4_hba.fcp_wq = NULL; | |
7213 | } | |
7214 | ||
7215 | /* Release FCP CQ mapping array */ | |
7216 | if (phba->sli4_hba.fcp_cq_map != NULL) { | |
7217 | kfree(phba->sli4_hba.fcp_cq_map); | |
7218 | phba->sli4_hba.fcp_cq_map = NULL; | |
7219 | } | |
da0436e9 JS |
7220 | |
7221 | /* Release mailbox command work queue */ | |
67d12733 JS |
7222 | if (phba->sli4_hba.mbx_wq != NULL) { |
7223 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); | |
7224 | phba->sli4_hba.mbx_wq = NULL; | |
7225 | } | |
da0436e9 JS |
7226 | |
7227 | /* Release ELS work queue */ | |
67d12733 JS |
7228 | if (phba->sli4_hba.els_wq != NULL) { |
7229 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); | |
7230 | phba->sli4_hba.els_wq = NULL; | |
7231 | } | |
da0436e9 JS |
7232 | |
7233 | /* Release unsolicited receive queue */ | |
67d12733 JS |
7234 | if (phba->sli4_hba.hdr_rq != NULL) { |
7235 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); | |
7236 | phba->sli4_hba.hdr_rq = NULL; | |
7237 | } | |
7238 | if (phba->sli4_hba.dat_rq != NULL) { | |
7239 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); | |
7240 | phba->sli4_hba.dat_rq = NULL; | |
7241 | } | |
da0436e9 | 7242 | |
da0436e9 | 7243 | /* Release ELS complete queue */ |
67d12733 JS |
7244 | if (phba->sli4_hba.els_cq != NULL) { |
7245 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); | |
7246 | phba->sli4_hba.els_cq = NULL; | |
7247 | } | |
da0436e9 JS |
7248 | |
7249 | /* Release mailbox command complete queue */ | |
67d12733 JS |
7250 | if (phba->sli4_hba.mbx_cq != NULL) { |
7251 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); | |
7252 | phba->sli4_hba.mbx_cq = NULL; | |
7253 | } | |
da0436e9 JS |
7254 | |
7255 | return; | |
7256 | } | |
7257 | ||
7258 | /** | |
7259 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues | |
7260 | * @phba: pointer to lpfc hba data structure. | |
7261 | * | |
7262 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA | |
7263 | * operation. | |
7264 | * | |
7265 | * Return codes | |
af901ca1 | 7266 | * 0 - successful |
25985edc | 7267 | * -ENOMEM - No available memory |
d439d286 | 7268 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
7269 | **/ |
7270 | int | |
7271 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) | |
7272 | { | |
2a76a283 JS |
7273 | struct lpfc_sli *psli = &phba->sli; |
7274 | struct lpfc_sli_ring *pring; | |
da0436e9 JS |
7275 | int rc = -ENOMEM; |
7276 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; | |
7277 | int fcp_cq_index = 0; | |
962bc51b JS |
7278 | uint32_t shdr_status, shdr_add_status; |
7279 | union lpfc_sli4_cfg_shdr *shdr; | |
7280 | LPFC_MBOXQ_t *mboxq; | |
7281 | uint32_t length; | |
7282 | ||
7283 | /* Check for dual-ULP support */ | |
7284 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
7285 | if (!mboxq) { | |
7286 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7287 | "3249 Unable to allocate memory for " | |
7288 | "QUERY_FW_CFG mailbox command\n"); | |
7289 | return -ENOMEM; | |
7290 | } | |
7291 | length = (sizeof(struct lpfc_mbx_query_fw_config) - | |
7292 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
7293 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
7294 | LPFC_MBOX_OPCODE_QUERY_FW_CFG, | |
7295 | length, LPFC_SLI4_MBX_EMBED); | |
7296 | ||
7297 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7298 | ||
7299 | shdr = (union lpfc_sli4_cfg_shdr *) | |
7300 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
7301 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
7302 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
7303 | if (shdr_status || shdr_add_status || rc) { | |
7304 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7305 | "3250 QUERY_FW_CFG mailbox failed with status " | |
7306 | "x%x add_status x%x, mbx status x%x\n", | |
7307 | shdr_status, shdr_add_status, rc); | |
7308 | if (rc != MBX_TIMEOUT) | |
7309 | mempool_free(mboxq, phba->mbox_mem_pool); | |
7310 | rc = -ENXIO; | |
7311 | goto out_error; | |
7312 | } | |
7313 | ||
7314 | phba->sli4_hba.fw_func_mode = | |
7315 | mboxq->u.mqe.un.query_fw_cfg.rsp.function_mode; | |
7316 | phba->sli4_hba.ulp0_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp0_mode; | |
7317 | phba->sli4_hba.ulp1_mode = mboxq->u.mqe.un.query_fw_cfg.rsp.ulp1_mode; | |
7318 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7319 | "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, " | |
7320 | "ulp1_mode:x%x\n", phba->sli4_hba.fw_func_mode, | |
7321 | phba->sli4_hba.ulp0_mode, phba->sli4_hba.ulp1_mode); | |
7322 | ||
7323 | if (rc != MBX_TIMEOUT) | |
7324 | mempool_free(mboxq, phba->mbox_mem_pool); | |
da0436e9 JS |
7325 | |
7326 | /* | |
67d12733 | 7327 | * Set up HBA Event Queues (EQs) |
da0436e9 JS |
7328 | */ |
7329 | ||
67d12733 JS |
7330 | /* Set up HBA event queue */ |
7331 | if (phba->cfg_fcp_io_channel && !phba->sli4_hba.hba_eq) { | |
2e90f4b5 JS |
7332 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
7333 | "3147 Fast-path EQs not allocated\n"); | |
1b51197d | 7334 | rc = -ENOMEM; |
67d12733 | 7335 | goto out_error; |
2e90f4b5 | 7336 | } |
67d12733 JS |
7337 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_io_channel; fcp_eqidx++) { |
7338 | if (!phba->sli4_hba.hba_eq[fcp_eqidx]) { | |
da0436e9 JS |
7339 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
7340 | "0522 Fast-path EQ (%d) not " | |
7341 | "allocated\n", fcp_eqidx); | |
1b51197d | 7342 | rc = -ENOMEM; |
67d12733 | 7343 | goto out_destroy_hba_eq; |
da0436e9 | 7344 | } |
67d12733 | 7345 | rc = lpfc_eq_create(phba, phba->sli4_hba.hba_eq[fcp_eqidx], |
bf8dae83 | 7346 | (phba->cfg_fcp_imax / phba->cfg_fcp_io_channel)); |
da0436e9 JS |
7347 | if (rc) { |
7348 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7349 | "0523 Failed setup of fast-path EQ " | |
7350 | "(%d), rc = 0x%x\n", fcp_eqidx, rc); | |
67d12733 | 7351 | goto out_destroy_hba_eq; |
da0436e9 JS |
7352 | } |
7353 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
67d12733 | 7354 | "2584 HBA EQ setup: " |
da0436e9 | 7355 | "queue[%d]-id=%d\n", fcp_eqidx, |
67d12733 | 7356 | phba->sli4_hba.hba_eq[fcp_eqidx]->queue_id); |
da0436e9 JS |
7357 | } |
7358 | ||
67d12733 JS |
7359 | /* Set up fast-path FCP Response Complete Queue */ |
7360 | if (!phba->sli4_hba.fcp_cq) { | |
7361 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7362 | "3148 Fast-path FCP CQ array not " | |
7363 | "allocated\n"); | |
7364 | rc = -ENOMEM; | |
7365 | goto out_destroy_hba_eq; | |
7366 | } | |
7367 | ||
7368 | for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_io_channel; fcp_cqidx++) { | |
7369 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { | |
7370 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7371 | "0526 Fast-path FCP CQ (%d) not " | |
7372 | "allocated\n", fcp_cqidx); | |
7373 | rc = -ENOMEM; | |
7374 | goto out_destroy_fcp_cq; | |
7375 | } | |
7376 | rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx], | |
7377 | phba->sli4_hba.hba_eq[fcp_cqidx], LPFC_WCQ, LPFC_FCP); | |
7378 | if (rc) { | |
7379 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7380 | "0527 Failed setup of fast-path FCP " | |
7381 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc); | |
7382 | goto out_destroy_fcp_cq; | |
7383 | } | |
7384 | ||
7385 | /* Setup fcp_cq_map for fast lookup */ | |
7386 | phba->sli4_hba.fcp_cq_map[fcp_cqidx] = | |
7387 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id; | |
7388 | ||
7389 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7390 | "2588 FCP CQ setup: cq[%d]-id=%d, " | |
7391 | "parent seq[%d]-id=%d\n", | |
7392 | fcp_cqidx, | |
7393 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, | |
7394 | fcp_cqidx, | |
7395 | phba->sli4_hba.hba_eq[fcp_cqidx]->queue_id); | |
7396 | } | |
7397 | ||
7398 | /* Set up fast-path FCP Work Queue */ | |
7399 | if (!phba->sli4_hba.fcp_wq) { | |
7400 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7401 | "3149 Fast-path FCP WQ array not " | |
7402 | "allocated\n"); | |
7403 | rc = -ENOMEM; | |
7404 | goto out_destroy_fcp_cq; | |
7405 | } | |
7406 | ||
7407 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_io_channel; fcp_wqidx++) { | |
7408 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { | |
7409 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7410 | "0534 Fast-path FCP WQ (%d) not " | |
7411 | "allocated\n", fcp_wqidx); | |
7412 | rc = -ENOMEM; | |
7413 | goto out_destroy_fcp_wq; | |
7414 | } | |
7415 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], | |
7416 | phba->sli4_hba.fcp_cq[fcp_wqidx], | |
7417 | LPFC_FCP); | |
7418 | if (rc) { | |
7419 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7420 | "0535 Failed setup of fast-path FCP " | |
7421 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc); | |
7422 | goto out_destroy_fcp_wq; | |
7423 | } | |
7424 | ||
7425 | /* Bind this WQ to the next FCP ring */ | |
7426 | pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx]; | |
7427 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx]; | |
7428 | phba->sli4_hba.fcp_cq[fcp_wqidx]->pring = pring; | |
7429 | ||
7430 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7431 | "2591 FCP WQ setup: wq[%d]-id=%d, " | |
7432 | "parent cq[%d]-id=%d\n", | |
7433 | fcp_wqidx, | |
7434 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, | |
7435 | fcp_cq_index, | |
7436 | phba->sli4_hba.fcp_cq[fcp_wqidx]->queue_id); | |
7437 | } | |
da0436e9 JS |
7438 | /* |
7439 | * Set up Complete Queues (CQs) | |
7440 | */ | |
7441 | ||
7442 | /* Set up slow-path MBOX Complete Queue as the first CQ */ | |
7443 | if (!phba->sli4_hba.mbx_cq) { | |
7444 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7445 | "0528 Mailbox CQ not allocated\n"); | |
1b51197d | 7446 | rc = -ENOMEM; |
67d12733 | 7447 | goto out_destroy_fcp_wq; |
da0436e9 | 7448 | } |
67d12733 JS |
7449 | rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, |
7450 | phba->sli4_hba.hba_eq[0], LPFC_MCQ, LPFC_MBOX); | |
da0436e9 JS |
7451 | if (rc) { |
7452 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7453 | "0529 Failed setup of slow-path mailbox CQ: " | |
7454 | "rc = 0x%x\n", rc); | |
67d12733 | 7455 | goto out_destroy_fcp_wq; |
da0436e9 JS |
7456 | } |
7457 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7458 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", | |
7459 | phba->sli4_hba.mbx_cq->queue_id, | |
67d12733 | 7460 | phba->sli4_hba.hba_eq[0]->queue_id); |
da0436e9 JS |
7461 | |
7462 | /* Set up slow-path ELS Complete Queue */ | |
7463 | if (!phba->sli4_hba.els_cq) { | |
7464 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7465 | "0530 ELS CQ not allocated\n"); | |
1b51197d | 7466 | rc = -ENOMEM; |
da0436e9 JS |
7467 | goto out_destroy_mbx_cq; |
7468 | } | |
67d12733 JS |
7469 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, |
7470 | phba->sli4_hba.hba_eq[0], LPFC_WCQ, LPFC_ELS); | |
da0436e9 JS |
7471 | if (rc) { |
7472 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7473 | "0531 Failed setup of slow-path ELS CQ: " | |
7474 | "rc = 0x%x\n", rc); | |
7475 | goto out_destroy_mbx_cq; | |
7476 | } | |
7477 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7478 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", | |
7479 | phba->sli4_hba.els_cq->queue_id, | |
67d12733 | 7480 | phba->sli4_hba.hba_eq[0]->queue_id); |
da0436e9 JS |
7481 | |
7482 | /* | |
7483 | * Set up all the Work Queues (WQs) | |
7484 | */ | |
7485 | ||
7486 | /* Set up Mailbox Command Queue */ | |
7487 | if (!phba->sli4_hba.mbx_wq) { | |
7488 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7489 | "0538 Slow-path MQ not allocated\n"); | |
1b51197d | 7490 | rc = -ENOMEM; |
67d12733 | 7491 | goto out_destroy_els_cq; |
da0436e9 JS |
7492 | } |
7493 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, | |
7494 | phba->sli4_hba.mbx_cq, LPFC_MBOX); | |
7495 | if (rc) { | |
7496 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7497 | "0539 Failed setup of slow-path MQ: " | |
7498 | "rc = 0x%x\n", rc); | |
67d12733 | 7499 | goto out_destroy_els_cq; |
da0436e9 JS |
7500 | } |
7501 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7502 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", | |
7503 | phba->sli4_hba.mbx_wq->queue_id, | |
7504 | phba->sli4_hba.mbx_cq->queue_id); | |
7505 | ||
7506 | /* Set up slow-path ELS Work Queue */ | |
7507 | if (!phba->sli4_hba.els_wq) { | |
7508 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7509 | "0536 Slow-path ELS WQ not allocated\n"); | |
1b51197d | 7510 | rc = -ENOMEM; |
da0436e9 JS |
7511 | goto out_destroy_mbx_wq; |
7512 | } | |
7513 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, | |
7514 | phba->sli4_hba.els_cq, LPFC_ELS); | |
7515 | if (rc) { | |
7516 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7517 | "0537 Failed setup of slow-path ELS WQ: " | |
7518 | "rc = 0x%x\n", rc); | |
7519 | goto out_destroy_mbx_wq; | |
7520 | } | |
2a76a283 JS |
7521 | |
7522 | /* Bind this WQ to the ELS ring */ | |
7523 | pring = &psli->ring[LPFC_ELS_RING]; | |
7524 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq; | |
7525 | phba->sli4_hba.els_cq->pring = pring; | |
7526 | ||
da0436e9 JS |
7527 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
7528 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", | |
7529 | phba->sli4_hba.els_wq->queue_id, | |
7530 | phba->sli4_hba.els_cq->queue_id); | |
7531 | ||
da0436e9 JS |
7532 | /* |
7533 | * Create Receive Queue (RQ) | |
7534 | */ | |
7535 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { | |
7536 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7537 | "0540 Receive Queue not allocated\n"); | |
1b51197d | 7538 | rc = -ENOMEM; |
67d12733 | 7539 | goto out_destroy_els_wq; |
da0436e9 | 7540 | } |
73d91e50 JS |
7541 | |
7542 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ); | |
7543 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ); | |
7544 | ||
da0436e9 | 7545 | rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, |
4d9ab994 | 7546 | phba->sli4_hba.els_cq, LPFC_USOL); |
da0436e9 JS |
7547 | if (rc) { |
7548 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7549 | "0541 Failed setup of Receive Queue: " | |
7550 | "rc = 0x%x\n", rc); | |
7551 | goto out_destroy_fcp_wq; | |
7552 | } | |
73d91e50 | 7553 | |
da0436e9 JS |
7554 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
7555 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " | |
7556 | "parent cq-id=%d\n", | |
7557 | phba->sli4_hba.hdr_rq->queue_id, | |
7558 | phba->sli4_hba.dat_rq->queue_id, | |
4d9ab994 | 7559 | phba->sli4_hba.els_cq->queue_id); |
1ba981fd JS |
7560 | |
7561 | if (phba->cfg_fof) { | |
7562 | rc = lpfc_fof_queue_setup(phba); | |
7563 | if (rc) { | |
7564 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7565 | "0549 Failed setup of FOF Queues: " | |
7566 | "rc = 0x%x\n", rc); | |
7567 | goto out_destroy_els_rq; | |
7568 | } | |
7569 | } | |
da0436e9 JS |
7570 | return 0; |
7571 | ||
1ba981fd JS |
7572 | out_destroy_els_rq: |
7573 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); | |
2e90f4b5 | 7574 | out_destroy_els_wq: |
da0436e9 JS |
7575 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
7576 | out_destroy_mbx_wq: | |
7577 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | |
2e90f4b5 | 7578 | out_destroy_els_cq: |
da0436e9 JS |
7579 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
7580 | out_destroy_mbx_cq: | |
7581 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | |
67d12733 JS |
7582 | out_destroy_fcp_wq: |
7583 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) | |
7584 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); | |
7585 | out_destroy_fcp_cq: | |
7586 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) | |
7587 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); | |
7588 | out_destroy_hba_eq: | |
da0436e9 | 7589 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) |
67d12733 | 7590 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_eqidx]); |
da0436e9 JS |
7591 | out_error: |
7592 | return rc; | |
7593 | } | |
7594 | ||
7595 | /** | |
7596 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues | |
7597 | * @phba: pointer to lpfc hba data structure. | |
7598 | * | |
7599 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA | |
7600 | * operation. | |
7601 | * | |
7602 | * Return codes | |
af901ca1 | 7603 | * 0 - successful |
25985edc | 7604 | * -ENOMEM - No available memory |
d439d286 | 7605 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
7606 | **/ |
7607 | void | |
7608 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) | |
7609 | { | |
7610 | int fcp_qidx; | |
7611 | ||
1ba981fd JS |
7612 | /* Unset the queues created for Flash Optimized Fabric operations */ |
7613 | if (phba->cfg_fof) | |
7614 | lpfc_fof_queue_destroy(phba); | |
da0436e9 JS |
7615 | /* Unset mailbox command work queue */ |
7616 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | |
7617 | /* Unset ELS work queue */ | |
7618 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); | |
7619 | /* Unset unsolicited receive queue */ | |
7620 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); | |
7621 | /* Unset FCP work queue */ | |
67d12733 JS |
7622 | if (phba->sli4_hba.fcp_wq) { |
7623 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; | |
7624 | fcp_qidx++) | |
7625 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); | |
7626 | } | |
da0436e9 JS |
7627 | /* Unset mailbox command complete queue */ |
7628 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | |
7629 | /* Unset ELS complete queue */ | |
7630 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); | |
da0436e9 | 7631 | /* Unset FCP response complete queue */ |
2e90f4b5 | 7632 | if (phba->sli4_hba.fcp_cq) { |
67d12733 JS |
7633 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; |
7634 | fcp_qidx++) | |
2e90f4b5 | 7635 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); |
2e90f4b5 | 7636 | } |
da0436e9 | 7637 | /* Unset fast-path event queue */ |
67d12733 JS |
7638 | if (phba->sli4_hba.hba_eq) { |
7639 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_io_channel; | |
2e90f4b5 | 7640 | fcp_qidx++) |
67d12733 | 7641 | lpfc_eq_destroy(phba, phba->sli4_hba.hba_eq[fcp_qidx]); |
2e90f4b5 | 7642 | } |
da0436e9 JS |
7643 | } |
7644 | ||
7645 | /** | |
7646 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool | |
7647 | * @phba: pointer to lpfc hba data structure. | |
7648 | * | |
7649 | * This routine is invoked to allocate and set up a pool of completion queue | |
7650 | * events. The body of the completion queue event is a completion queue entry | |
7651 | * CQE. For now, this pool is used for the interrupt service routine to queue | |
7652 | * the following HBA completion queue events for the worker thread to process: | |
7653 | * - Mailbox asynchronous events | |
7654 | * - Receive queue completion unsolicited events | |
7655 | * Later, this can be used for all the slow-path events. | |
7656 | * | |
7657 | * Return codes | |
af901ca1 | 7658 | * 0 - successful |
25985edc | 7659 | * -ENOMEM - No available memory |
da0436e9 JS |
7660 | **/ |
7661 | static int | |
7662 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) | |
7663 | { | |
7664 | struct lpfc_cq_event *cq_event; | |
7665 | int i; | |
7666 | ||
7667 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { | |
7668 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); | |
7669 | if (!cq_event) | |
7670 | goto out_pool_create_fail; | |
7671 | list_add_tail(&cq_event->list, | |
7672 | &phba->sli4_hba.sp_cqe_event_pool); | |
7673 | } | |
7674 | return 0; | |
7675 | ||
7676 | out_pool_create_fail: | |
7677 | lpfc_sli4_cq_event_pool_destroy(phba); | |
7678 | return -ENOMEM; | |
7679 | } | |
7680 | ||
7681 | /** | |
7682 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool | |
7683 | * @phba: pointer to lpfc hba data structure. | |
7684 | * | |
7685 | * This routine is invoked to free the pool of completion queue events at | |
7686 | * driver unload time. Note that, it is the responsibility of the driver | |
7687 | * cleanup routine to free all the outstanding completion-queue events | |
7688 | * allocated from this pool back into the pool before invoking this routine | |
7689 | * to destroy the pool. | |
7690 | **/ | |
7691 | static void | |
7692 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) | |
7693 | { | |
7694 | struct lpfc_cq_event *cq_event, *next_cq_event; | |
7695 | ||
7696 | list_for_each_entry_safe(cq_event, next_cq_event, | |
7697 | &phba->sli4_hba.sp_cqe_event_pool, list) { | |
7698 | list_del(&cq_event->list); | |
7699 | kfree(cq_event); | |
7700 | } | |
7701 | } | |
7702 | ||
7703 | /** | |
7704 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
7705 | * @phba: pointer to lpfc hba data structure. | |
7706 | * | |
7707 | * This routine is the lock free version of the API invoked to allocate a | |
7708 | * completion-queue event from the free pool. | |
7709 | * | |
7710 | * Return: Pointer to the newly allocated completion-queue event if successful | |
7711 | * NULL otherwise. | |
7712 | **/ | |
7713 | struct lpfc_cq_event * | |
7714 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
7715 | { | |
7716 | struct lpfc_cq_event *cq_event = NULL; | |
7717 | ||
7718 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, | |
7719 | struct lpfc_cq_event, list); | |
7720 | return cq_event; | |
7721 | } | |
7722 | ||
7723 | /** | |
7724 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
7725 | * @phba: pointer to lpfc hba data structure. | |
7726 | * | |
7727 | * This routine is the lock version of the API invoked to allocate a | |
7728 | * completion-queue event from the free pool. | |
7729 | * | |
7730 | * Return: Pointer to the newly allocated completion-queue event if successful | |
7731 | * NULL otherwise. | |
7732 | **/ | |
7733 | struct lpfc_cq_event * | |
7734 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
7735 | { | |
7736 | struct lpfc_cq_event *cq_event; | |
7737 | unsigned long iflags; | |
7738 | ||
7739 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7740 | cq_event = __lpfc_sli4_cq_event_alloc(phba); | |
7741 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7742 | return cq_event; | |
7743 | } | |
7744 | ||
7745 | /** | |
7746 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
7747 | * @phba: pointer to lpfc hba data structure. | |
7748 | * @cq_event: pointer to the completion queue event to be freed. | |
7749 | * | |
7750 | * This routine is the lock free version of the API invoked to release a | |
7751 | * completion-queue event back into the free pool. | |
7752 | **/ | |
7753 | void | |
7754 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
7755 | struct lpfc_cq_event *cq_event) | |
7756 | { | |
7757 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); | |
7758 | } | |
7759 | ||
7760 | /** | |
7761 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
7762 | * @phba: pointer to lpfc hba data structure. | |
7763 | * @cq_event: pointer to the completion queue event to be freed. | |
7764 | * | |
7765 | * This routine is the lock version of the API invoked to release a | |
7766 | * completion-queue event back into the free pool. | |
7767 | **/ | |
7768 | void | |
7769 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
7770 | struct lpfc_cq_event *cq_event) | |
7771 | { | |
7772 | unsigned long iflags; | |
7773 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7774 | __lpfc_sli4_cq_event_release(phba, cq_event); | |
7775 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7776 | } | |
7777 | ||
7778 | /** | |
7779 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool | |
7780 | * @phba: pointer to lpfc hba data structure. | |
7781 | * | |
7782 | * This routine is to free all the pending completion-queue events to the | |
7783 | * back into the free pool for device reset. | |
7784 | **/ | |
7785 | static void | |
7786 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) | |
7787 | { | |
7788 | LIST_HEAD(cqelist); | |
7789 | struct lpfc_cq_event *cqe; | |
7790 | unsigned long iflags; | |
7791 | ||
7792 | /* Retrieve all the pending WCQEs from pending WCQE lists */ | |
7793 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7794 | /* Pending FCP XRI abort events */ | |
7795 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
7796 | &cqelist); | |
7797 | /* Pending ELS XRI abort events */ | |
7798 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
7799 | &cqelist); | |
7800 | /* Pending asynnc events */ | |
7801 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, | |
7802 | &cqelist); | |
7803 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7804 | ||
7805 | while (!list_empty(&cqelist)) { | |
7806 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); | |
7807 | lpfc_sli4_cq_event_release(phba, cqe); | |
7808 | } | |
7809 | } | |
7810 | ||
7811 | /** | |
7812 | * lpfc_pci_function_reset - Reset pci function. | |
7813 | * @phba: pointer to lpfc hba data structure. | |
7814 | * | |
7815 | * This routine is invoked to request a PCI function reset. It will destroys | |
7816 | * all resources assigned to the PCI function which originates this request. | |
7817 | * | |
7818 | * Return codes | |
af901ca1 | 7819 | * 0 - successful |
25985edc | 7820 | * -ENOMEM - No available memory |
d439d286 | 7821 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
7822 | **/ |
7823 | int | |
7824 | lpfc_pci_function_reset(struct lpfc_hba *phba) | |
7825 | { | |
7826 | LPFC_MBOXQ_t *mboxq; | |
2fcee4bf | 7827 | uint32_t rc = 0, if_type; |
da0436e9 | 7828 | uint32_t shdr_status, shdr_add_status; |
2fcee4bf | 7829 | uint32_t rdy_chk, num_resets = 0, reset_again = 0; |
da0436e9 | 7830 | union lpfc_sli4_cfg_shdr *shdr; |
2fcee4bf | 7831 | struct lpfc_register reg_data; |
2b81f942 | 7832 | uint16_t devid; |
da0436e9 | 7833 | |
2fcee4bf JS |
7834 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
7835 | switch (if_type) { | |
7836 | case LPFC_SLI_INTF_IF_TYPE_0: | |
7837 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, | |
7838 | GFP_KERNEL); | |
7839 | if (!mboxq) { | |
7840 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7841 | "0494 Unable to allocate memory for " | |
7842 | "issuing SLI_FUNCTION_RESET mailbox " | |
7843 | "command\n"); | |
7844 | return -ENOMEM; | |
7845 | } | |
da0436e9 | 7846 | |
2fcee4bf JS |
7847 | /* Setup PCI function reset mailbox-ioctl command */ |
7848 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
7849 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, | |
7850 | LPFC_SLI4_MBX_EMBED); | |
7851 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7852 | shdr = (union lpfc_sli4_cfg_shdr *) | |
7853 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
7854 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
7855 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
7856 | &shdr->response); | |
7857 | if (rc != MBX_TIMEOUT) | |
7858 | mempool_free(mboxq, phba->mbox_mem_pool); | |
7859 | if (shdr_status || shdr_add_status || rc) { | |
7860 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7861 | "0495 SLI_FUNCTION_RESET mailbox " | |
7862 | "failed with status x%x add_status x%x," | |
7863 | " mbx status x%x\n", | |
7864 | shdr_status, shdr_add_status, rc); | |
7865 | rc = -ENXIO; | |
7866 | } | |
7867 | break; | |
7868 | case LPFC_SLI_INTF_IF_TYPE_2: | |
7869 | for (num_resets = 0; | |
7870 | num_resets < MAX_IF_TYPE_2_RESETS; | |
7871 | num_resets++) { | |
7872 | reg_data.word0 = 0; | |
7873 | bf_set(lpfc_sliport_ctrl_end, ®_data, | |
7874 | LPFC_SLIPORT_LITTLE_ENDIAN); | |
7875 | bf_set(lpfc_sliport_ctrl_ip, ®_data, | |
7876 | LPFC_SLIPORT_INIT_PORT); | |
7877 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. | |
7878 | CTRLregaddr); | |
8fcb8acd | 7879 | /* flush */ |
2b81f942 JS |
7880 | pci_read_config_word(phba->pcidev, |
7881 | PCI_DEVICE_ID, &devid); | |
2fcee4bf JS |
7882 | /* |
7883 | * Poll the Port Status Register and wait for RDY for | |
7884 | * up to 10 seconds. If the port doesn't respond, treat | |
7885 | * it as an error. If the port responds with RN, start | |
7886 | * the loop again. | |
7887 | */ | |
7888 | for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) { | |
73d91e50 | 7889 | msleep(10); |
9940b97b JS |
7890 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
7891 | STATUSregaddr, ®_data.word0)) { | |
7892 | rc = -ENODEV; | |
73d91e50 | 7893 | goto out; |
9940b97b | 7894 | } |
6b5151fd | 7895 | if (bf_get(lpfc_sliport_status_rn, ®_data)) |
2fcee4bf | 7896 | reset_again++; |
6b5151fd | 7897 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
2fcee4bf | 7898 | break; |
2fcee4bf JS |
7899 | } |
7900 | ||
7901 | /* | |
7902 | * If the port responds to the init request with | |
7903 | * reset needed, delay for a bit and restart the loop. | |
7904 | */ | |
6b5151fd | 7905 | if (reset_again && (rdy_chk < 1000)) { |
2fcee4bf JS |
7906 | msleep(10); |
7907 | reset_again = 0; | |
7908 | continue; | |
7909 | } | |
7910 | ||
7911 | /* Detect any port errors. */ | |
2fcee4bf JS |
7912 | if ((bf_get(lpfc_sliport_status_err, ®_data)) || |
7913 | (rdy_chk >= 1000)) { | |
7914 | phba->work_status[0] = readl( | |
7915 | phba->sli4_hba.u.if_type2.ERR1regaddr); | |
7916 | phba->work_status[1] = readl( | |
7917 | phba->sli4_hba.u.if_type2.ERR2regaddr); | |
7918 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8fcb8acd | 7919 | "2890 Port error detected during port " |
8a9d2e80 JS |
7920 | "reset(%d): wait_tmo:%d ms, " |
7921 | "port status reg 0x%x, " | |
2fcee4bf | 7922 | "error 1=0x%x, error 2=0x%x\n", |
8a9d2e80 JS |
7923 | num_resets, rdy_chk*10, |
7924 | reg_data.word0, | |
2fcee4bf JS |
7925 | phba->work_status[0], |
7926 | phba->work_status[1]); | |
7927 | rc = -ENODEV; | |
7928 | } | |
7929 | ||
7930 | /* | |
7931 | * Terminate the outer loop provided the Port indicated | |
7932 | * ready within 10 seconds. | |
7933 | */ | |
7934 | if (rdy_chk < 1000) | |
7935 | break; | |
7936 | } | |
0558056c JS |
7937 | /* delay driver action following IF_TYPE_2 function reset */ |
7938 | msleep(100); | |
2fcee4bf JS |
7939 | break; |
7940 | case LPFC_SLI_INTF_IF_TYPE_1: | |
7941 | default: | |
7942 | break; | |
da0436e9 | 7943 | } |
2fcee4bf | 7944 | |
73d91e50 | 7945 | out: |
2fcee4bf | 7946 | /* Catch the not-ready port failure after a port reset. */ |
229adb0e JS |
7947 | if (num_resets >= MAX_IF_TYPE_2_RESETS) { |
7948 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7949 | "3317 HBA not functional: IP Reset Failed " | |
7950 | "after (%d) retries, try: " | |
7951 | "echo fw_reset > board_mode\n", num_resets); | |
2fcee4bf | 7952 | rc = -ENODEV; |
229adb0e | 7953 | } |
2fcee4bf | 7954 | |
da0436e9 JS |
7955 | return rc; |
7956 | } | |
7957 | ||
da0436e9 JS |
7958 | /** |
7959 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. | |
7960 | * @phba: pointer to lpfc hba data structure. | |
7961 | * | |
7962 | * This routine is invoked to set up the PCI device memory space for device | |
7963 | * with SLI-4 interface spec. | |
7964 | * | |
7965 | * Return codes | |
af901ca1 | 7966 | * 0 - successful |
da0436e9 JS |
7967 | * other values - error |
7968 | **/ | |
7969 | static int | |
7970 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) | |
7971 | { | |
7972 | struct pci_dev *pdev; | |
7973 | unsigned long bar0map_len, bar1map_len, bar2map_len; | |
7974 | int error = -ENODEV; | |
2fcee4bf | 7975 | uint32_t if_type; |
da0436e9 JS |
7976 | |
7977 | /* Obtain PCI device reference */ | |
7978 | if (!phba->pcidev) | |
7979 | return error; | |
7980 | else | |
7981 | pdev = phba->pcidev; | |
7982 | ||
7983 | /* Set the device DMA mask size */ | |
8e68597d MR |
7984 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
7985 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
7986 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
7987 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
da0436e9 | 7988 | return error; |
8e68597d MR |
7989 | } |
7990 | } | |
da0436e9 | 7991 | |
2fcee4bf JS |
7992 | /* |
7993 | * The BARs and register set definitions and offset locations are | |
7994 | * dependent on the if_type. | |
7995 | */ | |
7996 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, | |
7997 | &phba->sli4_hba.sli_intf.word0)) { | |
7998 | return error; | |
7999 | } | |
8000 | ||
8001 | /* There is no SLI3 failback for SLI4 devices. */ | |
8002 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != | |
8003 | LPFC_SLI_INTF_VALID) { | |
8004 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8005 | "2894 SLI_INTF reg contents invalid " | |
8006 | "sli_intf reg 0x%x\n", | |
8007 | phba->sli4_hba.sli_intf.word0); | |
8008 | return error; | |
8009 | } | |
8010 | ||
8011 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); | |
8012 | /* | |
8013 | * Get the bus address of SLI4 device Bar regions and the | |
8014 | * number of bytes required by each mapping. The mapping of the | |
8015 | * particular PCI BARs regions is dependent on the type of | |
8016 | * SLI4 device. | |
da0436e9 | 8017 | */ |
f5ca6f2e JS |
8018 | if (pci_resource_start(pdev, PCI_64BIT_BAR0)) { |
8019 | phba->pci_bar0_map = pci_resource_start(pdev, PCI_64BIT_BAR0); | |
8020 | bar0map_len = pci_resource_len(pdev, PCI_64BIT_BAR0); | |
2fcee4bf JS |
8021 | |
8022 | /* | |
8023 | * Map SLI4 PCI Config Space Register base to a kernel virtual | |
8024 | * addr | |
8025 | */ | |
8026 | phba->sli4_hba.conf_regs_memmap_p = | |
8027 | ioremap(phba->pci_bar0_map, bar0map_len); | |
8028 | if (!phba->sli4_hba.conf_regs_memmap_p) { | |
8029 | dev_printk(KERN_ERR, &pdev->dev, | |
8030 | "ioremap failed for SLI4 PCI config " | |
8031 | "registers.\n"); | |
8032 | goto out; | |
8033 | } | |
f5ca6f2e | 8034 | phba->pci_bar0_memmap_p = phba->sli4_hba.conf_regs_memmap_p; |
2fcee4bf JS |
8035 | /* Set up BAR0 PCI config space register memory map */ |
8036 | lpfc_sli4_bar0_register_memmap(phba, if_type); | |
1dfb5a47 JS |
8037 | } else { |
8038 | phba->pci_bar0_map = pci_resource_start(pdev, 1); | |
8039 | bar0map_len = pci_resource_len(pdev, 1); | |
2fcee4bf JS |
8040 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
8041 | dev_printk(KERN_ERR, &pdev->dev, | |
8042 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); | |
8043 | goto out; | |
8044 | } | |
8045 | phba->sli4_hba.conf_regs_memmap_p = | |
da0436e9 | 8046 | ioremap(phba->pci_bar0_map, bar0map_len); |
2fcee4bf JS |
8047 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
8048 | dev_printk(KERN_ERR, &pdev->dev, | |
8049 | "ioremap failed for SLI4 PCI config " | |
8050 | "registers.\n"); | |
8051 | goto out; | |
8052 | } | |
8053 | lpfc_sli4_bar0_register_memmap(phba, if_type); | |
da0436e9 JS |
8054 | } |
8055 | ||
c31098ce | 8056 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
f5ca6f2e | 8057 | (pci_resource_start(pdev, PCI_64BIT_BAR2))) { |
2fcee4bf JS |
8058 | /* |
8059 | * Map SLI4 if type 0 HBA Control Register base to a kernel | |
8060 | * virtual address and setup the registers. | |
8061 | */ | |
f5ca6f2e JS |
8062 | phba->pci_bar1_map = pci_resource_start(pdev, PCI_64BIT_BAR2); |
8063 | bar1map_len = pci_resource_len(pdev, PCI_64BIT_BAR2); | |
2fcee4bf | 8064 | phba->sli4_hba.ctrl_regs_memmap_p = |
da0436e9 | 8065 | ioremap(phba->pci_bar1_map, bar1map_len); |
2fcee4bf JS |
8066 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
8067 | dev_printk(KERN_ERR, &pdev->dev, | |
da0436e9 | 8068 | "ioremap failed for SLI4 HBA control registers.\n"); |
2fcee4bf JS |
8069 | goto out_iounmap_conf; |
8070 | } | |
f5ca6f2e | 8071 | phba->pci_bar2_memmap_p = phba->sli4_hba.ctrl_regs_memmap_p; |
2fcee4bf | 8072 | lpfc_sli4_bar1_register_memmap(phba); |
da0436e9 JS |
8073 | } |
8074 | ||
c31098ce | 8075 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
f5ca6f2e | 8076 | (pci_resource_start(pdev, PCI_64BIT_BAR4))) { |
2fcee4bf JS |
8077 | /* |
8078 | * Map SLI4 if type 0 HBA Doorbell Register base to a kernel | |
8079 | * virtual address and setup the registers. | |
8080 | */ | |
f5ca6f2e JS |
8081 | phba->pci_bar2_map = pci_resource_start(pdev, PCI_64BIT_BAR4); |
8082 | bar2map_len = pci_resource_len(pdev, PCI_64BIT_BAR4); | |
2fcee4bf | 8083 | phba->sli4_hba.drbl_regs_memmap_p = |
da0436e9 | 8084 | ioremap(phba->pci_bar2_map, bar2map_len); |
2fcee4bf JS |
8085 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
8086 | dev_printk(KERN_ERR, &pdev->dev, | |
da0436e9 | 8087 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
2fcee4bf JS |
8088 | goto out_iounmap_ctrl; |
8089 | } | |
f5ca6f2e | 8090 | phba->pci_bar4_memmap_p = phba->sli4_hba.drbl_regs_memmap_p; |
2fcee4bf JS |
8091 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); |
8092 | if (error) | |
8093 | goto out_iounmap_all; | |
da0436e9 JS |
8094 | } |
8095 | ||
da0436e9 JS |
8096 | return 0; |
8097 | ||
8098 | out_iounmap_all: | |
8099 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
8100 | out_iounmap_ctrl: | |
8101 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
8102 | out_iounmap_conf: | |
8103 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
8104 | out: | |
8105 | return error; | |
8106 | } | |
8107 | ||
8108 | /** | |
8109 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. | |
8110 | * @phba: pointer to lpfc hba data structure. | |
8111 | * | |
8112 | * This routine is invoked to unset the PCI device memory space for device | |
8113 | * with SLI-4 interface spec. | |
8114 | **/ | |
8115 | static void | |
8116 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) | |
8117 | { | |
2e90f4b5 JS |
8118 | uint32_t if_type; |
8119 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); | |
da0436e9 | 8120 | |
2e90f4b5 JS |
8121 | switch (if_type) { |
8122 | case LPFC_SLI_INTF_IF_TYPE_0: | |
8123 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
8124 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
8125 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
8126 | break; | |
8127 | case LPFC_SLI_INTF_IF_TYPE_2: | |
8128 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
8129 | break; | |
8130 | case LPFC_SLI_INTF_IF_TYPE_1: | |
8131 | default: | |
8132 | dev_printk(KERN_ERR, &phba->pcidev->dev, | |
8133 | "FATAL - unsupported SLI4 interface type - %d\n", | |
8134 | if_type); | |
8135 | break; | |
8136 | } | |
da0436e9 JS |
8137 | } |
8138 | ||
8139 | /** | |
8140 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device | |
8141 | * @phba: pointer to lpfc hba data structure. | |
8142 | * | |
8143 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
8144 | * with SLI-3 interface specs. The kernel function pci_enable_msix() is | |
8145 | * called to enable the MSI-X vectors. Note that pci_enable_msix(), once | |
8146 | * invoked, enables either all or nothing, depending on the current | |
8147 | * availability of PCI vector resources. The device driver is responsible | |
8148 | * for calling the individual request_irq() to register each MSI-X vector | |
8149 | * with a interrupt handler, which is done in this function. Note that | |
8150 | * later when device is unloading, the driver should always call free_irq() | |
8151 | * on all MSI-X vectors it has done request_irq() on before calling | |
8152 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device | |
8153 | * will be left with MSI-X enabled and leaks its vectors. | |
8154 | * | |
8155 | * Return codes | |
af901ca1 | 8156 | * 0 - successful |
da0436e9 JS |
8157 | * other values - error |
8158 | **/ | |
8159 | static int | |
8160 | lpfc_sli_enable_msix(struct lpfc_hba *phba) | |
8161 | { | |
8162 | int rc, i; | |
8163 | LPFC_MBOXQ_t *pmb; | |
8164 | ||
8165 | /* Set up MSI-X multi-message vectors */ | |
8166 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
8167 | phba->msix_entries[i].entry = i; | |
8168 | ||
8169 | /* Configure MSI-X capability structure */ | |
8170 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, | |
8171 | ARRAY_SIZE(phba->msix_entries)); | |
8172 | if (rc) { | |
8173 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8174 | "0420 PCI enable MSI-X failed (%d)\n", rc); | |
8175 | goto msi_fail_out; | |
8176 | } | |
8177 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
8178 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8179 | "0477 MSI-X entry[%d]: vector=x%x " | |
8180 | "message=%d\n", i, | |
8181 | phba->msix_entries[i].vector, | |
8182 | phba->msix_entries[i].entry); | |
8183 | /* | |
8184 | * Assign MSI-X vectors to interrupt handlers | |
8185 | */ | |
8186 | ||
8187 | /* vector-0 is associated to slow-path handler */ | |
8188 | rc = request_irq(phba->msix_entries[0].vector, | |
8189 | &lpfc_sli_sp_intr_handler, IRQF_SHARED, | |
8190 | LPFC_SP_DRIVER_HANDLER_NAME, phba); | |
8191 | if (rc) { | |
8192 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
8193 | "0421 MSI-X slow-path request_irq failed " | |
8194 | "(%d)\n", rc); | |
8195 | goto msi_fail_out; | |
8196 | } | |
8197 | ||
8198 | /* vector-1 is associated to fast-path handler */ | |
8199 | rc = request_irq(phba->msix_entries[1].vector, | |
8200 | &lpfc_sli_fp_intr_handler, IRQF_SHARED, | |
8201 | LPFC_FP_DRIVER_HANDLER_NAME, phba); | |
8202 | ||
8203 | if (rc) { | |
8204 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
8205 | "0429 MSI-X fast-path request_irq failed " | |
8206 | "(%d)\n", rc); | |
8207 | goto irq_fail_out; | |
8208 | } | |
8209 | ||
8210 | /* | |
8211 | * Configure HBA MSI-X attention conditions to messages | |
8212 | */ | |
8213 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
8214 | ||
8215 | if (!pmb) { | |
8216 | rc = -ENOMEM; | |
8217 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8218 | "0474 Unable to allocate memory for issuing " | |
8219 | "MBOX_CONFIG_MSI command\n"); | |
8220 | goto mem_fail_out; | |
8221 | } | |
8222 | rc = lpfc_config_msi(phba, pmb); | |
8223 | if (rc) | |
8224 | goto mbx_fail_out; | |
8225 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
8226 | if (rc != MBX_SUCCESS) { | |
8227 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | |
8228 | "0351 Config MSI mailbox command failed, " | |
8229 | "mbxCmd x%x, mbxStatus x%x\n", | |
8230 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); | |
8231 | goto mbx_fail_out; | |
8232 | } | |
8233 | ||
8234 | /* Free memory allocated for mailbox command */ | |
8235 | mempool_free(pmb, phba->mbox_mem_pool); | |
8236 | return rc; | |
8237 | ||
8238 | mbx_fail_out: | |
8239 | /* Free memory allocated for mailbox command */ | |
8240 | mempool_free(pmb, phba->mbox_mem_pool); | |
8241 | ||
8242 | mem_fail_out: | |
8243 | /* free the irq already requested */ | |
8244 | free_irq(phba->msix_entries[1].vector, phba); | |
8245 | ||
8246 | irq_fail_out: | |
8247 | /* free the irq already requested */ | |
8248 | free_irq(phba->msix_entries[0].vector, phba); | |
8249 | ||
8250 | msi_fail_out: | |
8251 | /* Unconfigure MSI-X capability structure */ | |
8252 | pci_disable_msix(phba->pcidev); | |
8253 | return rc; | |
8254 | } | |
8255 | ||
8256 | /** | |
8257 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. | |
8258 | * @phba: pointer to lpfc hba data structure. | |
8259 | * | |
8260 | * This routine is invoked to release the MSI-X vectors and then disable the | |
8261 | * MSI-X interrupt mode to device with SLI-3 interface spec. | |
8262 | **/ | |
8263 | static void | |
8264 | lpfc_sli_disable_msix(struct lpfc_hba *phba) | |
8265 | { | |
8266 | int i; | |
8267 | ||
8268 | /* Free up MSI-X multi-message vectors */ | |
8269 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
8270 | free_irq(phba->msix_entries[i].vector, phba); | |
8271 | /* Disable MSI-X */ | |
8272 | pci_disable_msix(phba->pcidev); | |
8273 | ||
8274 | return; | |
8275 | } | |
8276 | ||
8277 | /** | |
8278 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. | |
8279 | * @phba: pointer to lpfc hba data structure. | |
8280 | * | |
8281 | * This routine is invoked to enable the MSI interrupt mode to device with | |
8282 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to | |
8283 | * enable the MSI vector. The device driver is responsible for calling the | |
8284 | * request_irq() to register MSI vector with a interrupt the handler, which | |
8285 | * is done in this function. | |
8286 | * | |
8287 | * Return codes | |
af901ca1 | 8288 | * 0 - successful |
da0436e9 JS |
8289 | * other values - error |
8290 | */ | |
8291 | static int | |
8292 | lpfc_sli_enable_msi(struct lpfc_hba *phba) | |
8293 | { | |
8294 | int rc; | |
8295 | ||
8296 | rc = pci_enable_msi(phba->pcidev); | |
8297 | if (!rc) | |
8298 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8299 | "0462 PCI enable MSI mode success.\n"); | |
8300 | else { | |
8301 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8302 | "0471 PCI enable MSI mode failed (%d)\n", rc); | |
8303 | return rc; | |
8304 | } | |
8305 | ||
8306 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
8307 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
8308 | if (rc) { | |
8309 | pci_disable_msi(phba->pcidev); | |
8310 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
8311 | "0478 MSI request_irq failed (%d)\n", rc); | |
8312 | } | |
8313 | return rc; | |
8314 | } | |
8315 | ||
8316 | /** | |
8317 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. | |
8318 | * @phba: pointer to lpfc hba data structure. | |
8319 | * | |
8320 | * This routine is invoked to disable the MSI interrupt mode to device with | |
8321 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has | |
8322 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | |
8323 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | |
8324 | * its vector. | |
8325 | */ | |
8326 | static void | |
8327 | lpfc_sli_disable_msi(struct lpfc_hba *phba) | |
8328 | { | |
8329 | free_irq(phba->pcidev->irq, phba); | |
8330 | pci_disable_msi(phba->pcidev); | |
8331 | return; | |
8332 | } | |
8333 | ||
8334 | /** | |
8335 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. | |
8336 | * @phba: pointer to lpfc hba data structure. | |
8337 | * | |
8338 | * This routine is invoked to enable device interrupt and associate driver's | |
8339 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface | |
8340 | * spec. Depends on the interrupt mode configured to the driver, the driver | |
8341 | * will try to fallback from the configured interrupt mode to an interrupt | |
8342 | * mode which is supported by the platform, kernel, and device in the order | |
8343 | * of: | |
8344 | * MSI-X -> MSI -> IRQ. | |
8345 | * | |
8346 | * Return codes | |
af901ca1 | 8347 | * 0 - successful |
da0436e9 JS |
8348 | * other values - error |
8349 | **/ | |
8350 | static uint32_t | |
8351 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
8352 | { | |
8353 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
8354 | int retval; | |
8355 | ||
8356 | if (cfg_mode == 2) { | |
8357 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ | |
8358 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); | |
8359 | if (!retval) { | |
8360 | /* Now, try to enable MSI-X interrupt mode */ | |
8361 | retval = lpfc_sli_enable_msix(phba); | |
8362 | if (!retval) { | |
8363 | /* Indicate initialization to MSI-X mode */ | |
8364 | phba->intr_type = MSIX; | |
8365 | intr_mode = 2; | |
8366 | } | |
8367 | } | |
8368 | } | |
8369 | ||
8370 | /* Fallback to MSI if MSI-X initialization failed */ | |
8371 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
8372 | retval = lpfc_sli_enable_msi(phba); | |
8373 | if (!retval) { | |
8374 | /* Indicate initialization to MSI mode */ | |
8375 | phba->intr_type = MSI; | |
8376 | intr_mode = 1; | |
8377 | } | |
8378 | } | |
8379 | ||
8380 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
8381 | if (phba->intr_type == NONE) { | |
8382 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
8383 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
8384 | if (!retval) { | |
8385 | /* Indicate initialization to INTx mode */ | |
8386 | phba->intr_type = INTx; | |
8387 | intr_mode = 0; | |
8388 | } | |
8389 | } | |
8390 | return intr_mode; | |
8391 | } | |
8392 | ||
8393 | /** | |
8394 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. | |
8395 | * @phba: pointer to lpfc hba data structure. | |
8396 | * | |
8397 | * This routine is invoked to disable device interrupt and disassociate the | |
8398 | * driver's interrupt handler(s) from interrupt vector(s) to device with | |
8399 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will | |
8400 | * release the interrupt vector(s) for the message signaled interrupt. | |
8401 | **/ | |
8402 | static void | |
8403 | lpfc_sli_disable_intr(struct lpfc_hba *phba) | |
8404 | { | |
8405 | /* Disable the currently initialized interrupt mode */ | |
8406 | if (phba->intr_type == MSIX) | |
8407 | lpfc_sli_disable_msix(phba); | |
8408 | else if (phba->intr_type == MSI) | |
8409 | lpfc_sli_disable_msi(phba); | |
8410 | else if (phba->intr_type == INTx) | |
8411 | free_irq(phba->pcidev->irq, phba); | |
8412 | ||
8413 | /* Reset interrupt management states */ | |
8414 | phba->intr_type = NONE; | |
8415 | phba->sli.slistat.sli_intr = 0; | |
8416 | ||
8417 | return; | |
8418 | } | |
8419 | ||
7bb03bbf JS |
8420 | /** |
8421 | * lpfc_find_next_cpu - Find next available CPU that matches the phys_id | |
8422 | * @phba: pointer to lpfc hba data structure. | |
8423 | * | |
8424 | * Find next available CPU to use for IRQ to CPU affinity. | |
8425 | */ | |
8426 | static int | |
8427 | lpfc_find_next_cpu(struct lpfc_hba *phba, uint32_t phys_id) | |
8428 | { | |
8429 | struct lpfc_vector_map_info *cpup; | |
8430 | int cpu; | |
8431 | ||
8432 | cpup = phba->sli4_hba.cpu_map; | |
8433 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { | |
8434 | /* CPU must be online */ | |
8435 | if (cpu_online(cpu)) { | |
8436 | if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) && | |
8437 | (lpfc_used_cpu[cpu] == LPFC_VECTOR_MAP_EMPTY) && | |
8438 | (cpup->phys_id == phys_id)) { | |
8439 | return cpu; | |
8440 | } | |
8441 | } | |
8442 | cpup++; | |
8443 | } | |
8444 | ||
8445 | /* | |
8446 | * If we get here, we have used ALL CPUs for the specific | |
8447 | * phys_id. Now we need to clear out lpfc_used_cpu and start | |
8448 | * reusing CPUs. | |
8449 | */ | |
8450 | ||
8451 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { | |
8452 | if (lpfc_used_cpu[cpu] == phys_id) | |
8453 | lpfc_used_cpu[cpu] = LPFC_VECTOR_MAP_EMPTY; | |
8454 | } | |
8455 | ||
8456 | cpup = phba->sli4_hba.cpu_map; | |
8457 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { | |
8458 | /* CPU must be online */ | |
8459 | if (cpu_online(cpu)) { | |
8460 | if ((cpup->irq == LPFC_VECTOR_MAP_EMPTY) && | |
8461 | (cpup->phys_id == phys_id)) { | |
8462 | return cpu; | |
8463 | } | |
8464 | } | |
8465 | cpup++; | |
8466 | } | |
8467 | return LPFC_VECTOR_MAP_EMPTY; | |
8468 | } | |
8469 | ||
8470 | /** | |
8471 | * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors | |
8472 | * @phba: pointer to lpfc hba data structure. | |
8473 | * @vectors: number of HBA vectors | |
8474 | * | |
8475 | * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector | |
8476 | * affinization across multple physical CPUs (numa nodes). | |
8477 | * In addition, this routine will assign an IO channel for each CPU | |
8478 | * to use when issuing I/Os. | |
8479 | */ | |
8480 | static int | |
8481 | lpfc_sli4_set_affinity(struct lpfc_hba *phba, int vectors) | |
8482 | { | |
8483 | int i, idx, saved_chann, used_chann, cpu, phys_id; | |
ec2087a7 JS |
8484 | int max_phys_id, min_phys_id; |
8485 | int num_io_channel, first_cpu, chan; | |
7bb03bbf JS |
8486 | struct lpfc_vector_map_info *cpup; |
8487 | #ifdef CONFIG_X86 | |
8488 | struct cpuinfo_x86 *cpuinfo; | |
8489 | #endif | |
8490 | struct cpumask *mask; | |
8491 | uint8_t chann[LPFC_FCP_IO_CHAN_MAX+1]; | |
8492 | ||
8493 | /* If there is no mapping, just return */ | |
8494 | if (!phba->cfg_fcp_cpu_map) | |
8495 | return 1; | |
8496 | ||
8497 | /* Init cpu_map array */ | |
8498 | memset(phba->sli4_hba.cpu_map, 0xff, | |
8499 | (sizeof(struct lpfc_vector_map_info) * | |
8500 | phba->sli4_hba.num_present_cpu)); | |
8501 | ||
8502 | max_phys_id = 0; | |
ec2087a7 | 8503 | min_phys_id = 0xff; |
7bb03bbf JS |
8504 | phys_id = 0; |
8505 | num_io_channel = 0; | |
8506 | first_cpu = LPFC_VECTOR_MAP_EMPTY; | |
8507 | ||
8508 | /* Update CPU map with physical id and core id of each CPU */ | |
8509 | cpup = phba->sli4_hba.cpu_map; | |
8510 | for (cpu = 0; cpu < phba->sli4_hba.num_present_cpu; cpu++) { | |
8511 | #ifdef CONFIG_X86 | |
8512 | cpuinfo = &cpu_data(cpu); | |
8513 | cpup->phys_id = cpuinfo->phys_proc_id; | |
8514 | cpup->core_id = cpuinfo->cpu_core_id; | |
8515 | #else | |
8516 | /* No distinction between CPUs for other platforms */ | |
8517 | cpup->phys_id = 0; | |
8518 | cpup->core_id = 0; | |
8519 | #endif | |
8520 | ||
8521 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8522 | "3328 CPU physid %d coreid %d\n", | |
8523 | cpup->phys_id, cpup->core_id); | |
8524 | ||
8525 | if (cpup->phys_id > max_phys_id) | |
8526 | max_phys_id = cpup->phys_id; | |
ec2087a7 JS |
8527 | if (cpup->phys_id < min_phys_id) |
8528 | min_phys_id = cpup->phys_id; | |
7bb03bbf JS |
8529 | cpup++; |
8530 | } | |
8531 | ||
ec2087a7 | 8532 | phys_id = min_phys_id; |
7bb03bbf JS |
8533 | /* Now associate the HBA vectors with specific CPUs */ |
8534 | for (idx = 0; idx < vectors; idx++) { | |
8535 | cpup = phba->sli4_hba.cpu_map; | |
8536 | cpu = lpfc_find_next_cpu(phba, phys_id); | |
8537 | if (cpu == LPFC_VECTOR_MAP_EMPTY) { | |
8538 | ||
8539 | /* Try for all phys_id's */ | |
8540 | for (i = 1; i < max_phys_id; i++) { | |
8541 | phys_id++; | |
8542 | if (phys_id > max_phys_id) | |
ec2087a7 | 8543 | phys_id = min_phys_id; |
7bb03bbf JS |
8544 | cpu = lpfc_find_next_cpu(phba, phys_id); |
8545 | if (cpu == LPFC_VECTOR_MAP_EMPTY) | |
8546 | continue; | |
8547 | goto found; | |
8548 | } | |
8549 | ||
ec2087a7 JS |
8550 | /* Use round robin for scheduling */ |
8551 | phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_ROUND_ROBIN; | |
8552 | chan = 0; | |
8553 | cpup = phba->sli4_hba.cpu_map; | |
8554 | for (i = 0; i < phba->sli4_hba.num_present_cpu; i++) { | |
8555 | cpup->channel_id = chan; | |
8556 | cpup++; | |
8557 | chan++; | |
8558 | if (chan >= phba->cfg_fcp_io_channel) | |
8559 | chan = 0; | |
8560 | } | |
8561 | ||
7bb03bbf JS |
8562 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
8563 | "3329 Cannot set affinity:" | |
8564 | "Error mapping vector %d (%d)\n", | |
8565 | idx, vectors); | |
8566 | return 0; | |
8567 | } | |
8568 | found: | |
8569 | cpup += cpu; | |
8570 | if (phba->cfg_fcp_cpu_map == LPFC_DRIVER_CPU_MAP) | |
8571 | lpfc_used_cpu[cpu] = phys_id; | |
8572 | ||
8573 | /* Associate vector with selected CPU */ | |
8574 | cpup->irq = phba->sli4_hba.msix_entries[idx].vector; | |
8575 | ||
8576 | /* Associate IO channel with selected CPU */ | |
8577 | cpup->channel_id = idx; | |
8578 | num_io_channel++; | |
8579 | ||
8580 | if (first_cpu == LPFC_VECTOR_MAP_EMPTY) | |
8581 | first_cpu = cpu; | |
8582 | ||
8583 | /* Now affinitize to the selected CPU */ | |
8584 | mask = &cpup->maskbits; | |
8585 | cpumask_clear(mask); | |
8586 | cpumask_set_cpu(cpu, mask); | |
8587 | i = irq_set_affinity_hint(phba->sli4_hba.msix_entries[idx]. | |
8588 | vector, mask); | |
8589 | ||
8590 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8591 | "3330 Set Affinity: CPU %d channel %d " | |
8592 | "irq %d (%x)\n", | |
8593 | cpu, cpup->channel_id, | |
8594 | phba->sli4_hba.msix_entries[idx].vector, i); | |
8595 | ||
8596 | /* Spread vector mapping across multple physical CPU nodes */ | |
8597 | phys_id++; | |
8598 | if (phys_id > max_phys_id) | |
ec2087a7 | 8599 | phys_id = min_phys_id; |
7bb03bbf JS |
8600 | } |
8601 | ||
8602 | /* | |
8603 | * Finally fill in the IO channel for any remaining CPUs. | |
8604 | * At this point, all IO channels have been assigned to a specific | |
8605 | * MSIx vector, mapped to a specific CPU. | |
8606 | * Base the remaining IO channel assigned, to IO channels already | |
8607 | * assigned to other CPUs on the same phys_id. | |
8608 | */ | |
ec2087a7 | 8609 | for (i = min_phys_id; i <= max_phys_id; i++) { |
7bb03bbf JS |
8610 | /* |
8611 | * If there are no io channels already mapped to | |
8612 | * this phys_id, just round robin thru the io_channels. | |
8613 | * Setup chann[] for round robin. | |
8614 | */ | |
8615 | for (idx = 0; idx < phba->cfg_fcp_io_channel; idx++) | |
8616 | chann[idx] = idx; | |
8617 | ||
8618 | saved_chann = 0; | |
8619 | used_chann = 0; | |
8620 | ||
8621 | /* | |
8622 | * First build a list of IO channels already assigned | |
8623 | * to this phys_id before reassigning the same IO | |
8624 | * channels to the remaining CPUs. | |
8625 | */ | |
8626 | cpup = phba->sli4_hba.cpu_map; | |
8627 | cpu = first_cpu; | |
8628 | cpup += cpu; | |
8629 | for (idx = 0; idx < phba->sli4_hba.num_present_cpu; | |
8630 | idx++) { | |
8631 | if (cpup->phys_id == i) { | |
8632 | /* | |
8633 | * Save any IO channels that are | |
8634 | * already mapped to this phys_id. | |
8635 | */ | |
8636 | if (cpup->irq != LPFC_VECTOR_MAP_EMPTY) { | |
8637 | chann[saved_chann] = | |
8638 | cpup->channel_id; | |
8639 | saved_chann++; | |
8640 | goto out; | |
8641 | } | |
8642 | ||
8643 | /* See if we are using round-robin */ | |
8644 | if (saved_chann == 0) | |
8645 | saved_chann = | |
8646 | phba->cfg_fcp_io_channel; | |
8647 | ||
8648 | /* Associate next IO channel with CPU */ | |
8649 | cpup->channel_id = chann[used_chann]; | |
8650 | num_io_channel++; | |
8651 | used_chann++; | |
8652 | if (used_chann == saved_chann) | |
8653 | used_chann = 0; | |
8654 | ||
8655 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8656 | "3331 Set IO_CHANN " | |
8657 | "CPU %d channel %d\n", | |
8658 | idx, cpup->channel_id); | |
8659 | } | |
8660 | out: | |
8661 | cpu++; | |
8662 | if (cpu >= phba->sli4_hba.num_present_cpu) { | |
8663 | cpup = phba->sli4_hba.cpu_map; | |
8664 | cpu = 0; | |
8665 | } else { | |
8666 | cpup++; | |
8667 | } | |
8668 | } | |
8669 | } | |
8670 | ||
8671 | if (phba->sli4_hba.num_online_cpu != phba->sli4_hba.num_present_cpu) { | |
8672 | cpup = phba->sli4_hba.cpu_map; | |
8673 | for (idx = 0; idx < phba->sli4_hba.num_present_cpu; idx++) { | |
8674 | if (cpup->channel_id == LPFC_VECTOR_MAP_EMPTY) { | |
8675 | cpup->channel_id = 0; | |
8676 | num_io_channel++; | |
8677 | ||
8678 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8679 | "3332 Assign IO_CHANN " | |
8680 | "CPU %d channel %d\n", | |
8681 | idx, cpup->channel_id); | |
8682 | } | |
8683 | cpup++; | |
8684 | } | |
8685 | } | |
8686 | ||
8687 | /* Sanity check */ | |
8688 | if (num_io_channel != phba->sli4_hba.num_present_cpu) | |
8689 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8690 | "3333 Set affinity mismatch:" | |
ec2087a7 | 8691 | "%d chann != %d cpus: %d vectors\n", |
7bb03bbf JS |
8692 | num_io_channel, phba->sli4_hba.num_present_cpu, |
8693 | vectors); | |
8694 | ||
ec2087a7 | 8695 | /* Enable using cpu affinity for scheduling */ |
7bb03bbf JS |
8696 | phba->cfg_fcp_io_sched = LPFC_FCP_SCHED_BY_CPU; |
8697 | return 1; | |
8698 | } | |
8699 | ||
8700 | ||
da0436e9 JS |
8701 | /** |
8702 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device | |
8703 | * @phba: pointer to lpfc hba data structure. | |
8704 | * | |
8705 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
8706 | * with SLI-4 interface spec. The kernel function pci_enable_msix() is called | |
8707 | * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked, | |
8708 | * enables either all or nothing, depending on the current availability of | |
8709 | * PCI vector resources. The device driver is responsible for calling the | |
8710 | * individual request_irq() to register each MSI-X vector with a interrupt | |
8711 | * handler, which is done in this function. Note that later when device is | |
8712 | * unloading, the driver should always call free_irq() on all MSI-X vectors | |
8713 | * it has done request_irq() on before calling pci_disable_msix(). Failure | |
8714 | * to do so results in a BUG_ON() and a device will be left with MSI-X | |
8715 | * enabled and leaks its vectors. | |
8716 | * | |
8717 | * Return codes | |
af901ca1 | 8718 | * 0 - successful |
da0436e9 JS |
8719 | * other values - error |
8720 | **/ | |
8721 | static int | |
8722 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) | |
8723 | { | |
75baf696 | 8724 | int vectors, rc, index; |
da0436e9 JS |
8725 | |
8726 | /* Set up MSI-X multi-message vectors */ | |
82c3e9ba | 8727 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) |
da0436e9 JS |
8728 | phba->sli4_hba.msix_entries[index].entry = index; |
8729 | ||
8730 | /* Configure MSI-X capability structure */ | |
82c3e9ba | 8731 | vectors = phba->cfg_fcp_io_channel; |
1ba981fd JS |
8732 | if (phba->cfg_fof) { |
8733 | phba->sli4_hba.msix_entries[index].entry = index; | |
8734 | vectors++; | |
8735 | } | |
75baf696 | 8736 | enable_msix_vectors: |
da0436e9 | 8737 | rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries, |
75baf696 JS |
8738 | vectors); |
8739 | if (rc > 1) { | |
8740 | vectors = rc; | |
8741 | goto enable_msix_vectors; | |
8742 | } else if (rc) { | |
da0436e9 JS |
8743 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
8744 | "0484 PCI enable MSI-X failed (%d)\n", rc); | |
8745 | goto msi_fail_out; | |
8746 | } | |
75baf696 | 8747 | |
da0436e9 | 8748 | /* Log MSI-X vector assignment */ |
75baf696 | 8749 | for (index = 0; index < vectors; index++) |
da0436e9 JS |
8750 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
8751 | "0489 MSI-X entry[%d]: vector=x%x " | |
8752 | "message=%d\n", index, | |
8753 | phba->sli4_hba.msix_entries[index].vector, | |
8754 | phba->sli4_hba.msix_entries[index].entry); | |
67d12733 | 8755 | |
7bb03bbf | 8756 | /* Assign MSI-X vectors to interrupt handlers */ |
67d12733 | 8757 | for (index = 0; index < vectors; index++) { |
4305f183 JS |
8758 | memset(&phba->sli4_hba.handler_name[index], 0, 16); |
8759 | sprintf((char *)&phba->sli4_hba.handler_name[index], | |
8760 | LPFC_DRIVER_HANDLER_NAME"%d", index); | |
da0436e9 | 8761 | |
67d12733 JS |
8762 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
8763 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
ba20c853 | 8764 | atomic_set(&phba->sli4_hba.fcp_eq_hdl[index].fcp_eq_in_use, 1); |
1ba981fd JS |
8765 | if (phba->cfg_fof && (index == (vectors - 1))) |
8766 | rc = request_irq( | |
8767 | phba->sli4_hba.msix_entries[index].vector, | |
8768 | &lpfc_sli4_fof_intr_handler, IRQF_SHARED, | |
8769 | (char *)&phba->sli4_hba.handler_name[index], | |
8770 | &phba->sli4_hba.fcp_eq_hdl[index]); | |
8771 | else | |
8772 | rc = request_irq( | |
8773 | phba->sli4_hba.msix_entries[index].vector, | |
67d12733 | 8774 | &lpfc_sli4_hba_intr_handler, IRQF_SHARED, |
4305f183 | 8775 | (char *)&phba->sli4_hba.handler_name[index], |
67d12733 | 8776 | &phba->sli4_hba.fcp_eq_hdl[index]); |
da0436e9 JS |
8777 | if (rc) { |
8778 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
8779 | "0486 MSI-X fast-path (%d) " | |
8780 | "request_irq failed (%d)\n", index, rc); | |
8781 | goto cfg_fail_out; | |
8782 | } | |
8783 | } | |
8784 | ||
1ba981fd JS |
8785 | if (phba->cfg_fof) |
8786 | vectors--; | |
8787 | ||
82c3e9ba JS |
8788 | if (vectors != phba->cfg_fcp_io_channel) { |
8789 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8790 | "3238 Reducing IO channels to match number of " | |
8791 | "MSI-X vectors, requested %d got %d\n", | |
8792 | phba->cfg_fcp_io_channel, vectors); | |
8793 | phba->cfg_fcp_io_channel = vectors; | |
8794 | } | |
7bb03bbf JS |
8795 | |
8796 | lpfc_sli4_set_affinity(phba, vectors); | |
da0436e9 JS |
8797 | return rc; |
8798 | ||
8799 | cfg_fail_out: | |
8800 | /* free the irq already requested */ | |
acbd8616 JS |
8801 | for (--index; index >= 0; index--) { |
8802 | irq_set_affinity_hint(phba->sli4_hba.msix_entries[index]. | |
8803 | vector, NULL); | |
67d12733 JS |
8804 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
8805 | &phba->sli4_hba.fcp_eq_hdl[index]); | |
acbd8616 | 8806 | } |
da0436e9 JS |
8807 | |
8808 | msi_fail_out: | |
8809 | /* Unconfigure MSI-X capability structure */ | |
8810 | pci_disable_msix(phba->pcidev); | |
8811 | return rc; | |
8812 | } | |
8813 | ||
8814 | /** | |
8815 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device | |
8816 | * @phba: pointer to lpfc hba data structure. | |
8817 | * | |
8818 | * This routine is invoked to release the MSI-X vectors and then disable the | |
8819 | * MSI-X interrupt mode to device with SLI-4 interface spec. | |
8820 | **/ | |
8821 | static void | |
8822 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) | |
8823 | { | |
8824 | int index; | |
8825 | ||
8826 | /* Free up MSI-X multi-message vectors */ | |
acbd8616 JS |
8827 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) { |
8828 | irq_set_affinity_hint(phba->sli4_hba.msix_entries[index]. | |
8829 | vector, NULL); | |
da0436e9 | 8830 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
67d12733 | 8831 | &phba->sli4_hba.fcp_eq_hdl[index]); |
acbd8616 | 8832 | } |
1ba981fd JS |
8833 | if (phba->cfg_fof) { |
8834 | free_irq(phba->sli4_hba.msix_entries[index].vector, | |
8835 | &phba->sli4_hba.fcp_eq_hdl[index]); | |
8836 | } | |
da0436e9 JS |
8837 | /* Disable MSI-X */ |
8838 | pci_disable_msix(phba->pcidev); | |
8839 | ||
8840 | return; | |
8841 | } | |
8842 | ||
8843 | /** | |
8844 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device | |
8845 | * @phba: pointer to lpfc hba data structure. | |
8846 | * | |
8847 | * This routine is invoked to enable the MSI interrupt mode to device with | |
8848 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called | |
8849 | * to enable the MSI vector. The device driver is responsible for calling | |
8850 | * the request_irq() to register MSI vector with a interrupt the handler, | |
8851 | * which is done in this function. | |
8852 | * | |
8853 | * Return codes | |
af901ca1 | 8854 | * 0 - successful |
da0436e9 JS |
8855 | * other values - error |
8856 | **/ | |
8857 | static int | |
8858 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) | |
8859 | { | |
8860 | int rc, index; | |
8861 | ||
8862 | rc = pci_enable_msi(phba->pcidev); | |
8863 | if (!rc) | |
8864 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8865 | "0487 PCI enable MSI mode success.\n"); | |
8866 | else { | |
8867 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8868 | "0488 PCI enable MSI mode failed (%d)\n", rc); | |
8869 | return rc; | |
8870 | } | |
8871 | ||
8872 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
8873 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
8874 | if (rc) { | |
8875 | pci_disable_msi(phba->pcidev); | |
8876 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
8877 | "0490 MSI request_irq failed (%d)\n", rc); | |
75baf696 | 8878 | return rc; |
da0436e9 JS |
8879 | } |
8880 | ||
67d12733 | 8881 | for (index = 0; index < phba->cfg_fcp_io_channel; index++) { |
da0436e9 JS |
8882 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; |
8883 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
8884 | } | |
8885 | ||
1ba981fd JS |
8886 | if (phba->cfg_fof) { |
8887 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | |
8888 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
8889 | } | |
75baf696 | 8890 | return 0; |
da0436e9 JS |
8891 | } |
8892 | ||
8893 | /** | |
8894 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device | |
8895 | * @phba: pointer to lpfc hba data structure. | |
8896 | * | |
8897 | * This routine is invoked to disable the MSI interrupt mode to device with | |
8898 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has | |
8899 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | |
8900 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | |
8901 | * its vector. | |
8902 | **/ | |
8903 | static void | |
8904 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) | |
8905 | { | |
8906 | free_irq(phba->pcidev->irq, phba); | |
8907 | pci_disable_msi(phba->pcidev); | |
8908 | return; | |
8909 | } | |
8910 | ||
8911 | /** | |
8912 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device | |
8913 | * @phba: pointer to lpfc hba data structure. | |
8914 | * | |
8915 | * This routine is invoked to enable device interrupt and associate driver's | |
8916 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 | |
8917 | * interface spec. Depends on the interrupt mode configured to the driver, | |
8918 | * the driver will try to fallback from the configured interrupt mode to an | |
8919 | * interrupt mode which is supported by the platform, kernel, and device in | |
8920 | * the order of: | |
8921 | * MSI-X -> MSI -> IRQ. | |
8922 | * | |
8923 | * Return codes | |
af901ca1 | 8924 | * 0 - successful |
da0436e9 JS |
8925 | * other values - error |
8926 | **/ | |
8927 | static uint32_t | |
8928 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
8929 | { | |
8930 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
8931 | int retval, index; | |
8932 | ||
8933 | if (cfg_mode == 2) { | |
8934 | /* Preparation before conf_msi mbox cmd */ | |
8935 | retval = 0; | |
8936 | if (!retval) { | |
8937 | /* Now, try to enable MSI-X interrupt mode */ | |
8938 | retval = lpfc_sli4_enable_msix(phba); | |
8939 | if (!retval) { | |
8940 | /* Indicate initialization to MSI-X mode */ | |
8941 | phba->intr_type = MSIX; | |
8942 | intr_mode = 2; | |
8943 | } | |
8944 | } | |
8945 | } | |
8946 | ||
8947 | /* Fallback to MSI if MSI-X initialization failed */ | |
8948 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
8949 | retval = lpfc_sli4_enable_msi(phba); | |
8950 | if (!retval) { | |
8951 | /* Indicate initialization to MSI mode */ | |
8952 | phba->intr_type = MSI; | |
8953 | intr_mode = 1; | |
8954 | } | |
8955 | } | |
8956 | ||
8957 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
8958 | if (phba->intr_type == NONE) { | |
8959 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
8960 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
8961 | if (!retval) { | |
8962 | /* Indicate initialization to INTx mode */ | |
8963 | phba->intr_type = INTx; | |
8964 | intr_mode = 0; | |
67d12733 | 8965 | for (index = 0; index < phba->cfg_fcp_io_channel; |
da0436e9 JS |
8966 | index++) { |
8967 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | |
8968 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
ba20c853 JS |
8969 | atomic_set(&phba->sli4_hba.fcp_eq_hdl[index]. |
8970 | fcp_eq_in_use, 1); | |
da0436e9 | 8971 | } |
1ba981fd JS |
8972 | if (phba->cfg_fof) { |
8973 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | |
8974 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
8975 | atomic_set(&phba->sli4_hba.fcp_eq_hdl[index]. | |
8976 | fcp_eq_in_use, 1); | |
8977 | } | |
da0436e9 JS |
8978 | } |
8979 | } | |
8980 | return intr_mode; | |
8981 | } | |
8982 | ||
8983 | /** | |
8984 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device | |
8985 | * @phba: pointer to lpfc hba data structure. | |
8986 | * | |
8987 | * This routine is invoked to disable device interrupt and disassociate | |
8988 | * the driver's interrupt handler(s) from interrupt vector(s) to device | |
8989 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver | |
8990 | * will release the interrupt vector(s) for the message signaled interrupt. | |
8991 | **/ | |
8992 | static void | |
8993 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) | |
8994 | { | |
8995 | /* Disable the currently initialized interrupt mode */ | |
8996 | if (phba->intr_type == MSIX) | |
8997 | lpfc_sli4_disable_msix(phba); | |
8998 | else if (phba->intr_type == MSI) | |
8999 | lpfc_sli4_disable_msi(phba); | |
9000 | else if (phba->intr_type == INTx) | |
9001 | free_irq(phba->pcidev->irq, phba); | |
9002 | ||
9003 | /* Reset interrupt management states */ | |
9004 | phba->intr_type = NONE; | |
9005 | phba->sli.slistat.sli_intr = 0; | |
9006 | ||
9007 | return; | |
9008 | } | |
9009 | ||
9010 | /** | |
9011 | * lpfc_unset_hba - Unset SLI3 hba device initialization | |
9012 | * @phba: pointer to lpfc hba data structure. | |
9013 | * | |
9014 | * This routine is invoked to unset the HBA device initialization steps to | |
9015 | * a device with SLI-3 interface spec. | |
9016 | **/ | |
9017 | static void | |
9018 | lpfc_unset_hba(struct lpfc_hba *phba) | |
9019 | { | |
9020 | struct lpfc_vport *vport = phba->pport; | |
9021 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
9022 | ||
9023 | spin_lock_irq(shost->host_lock); | |
9024 | vport->load_flag |= FC_UNLOADING; | |
9025 | spin_unlock_irq(shost->host_lock); | |
9026 | ||
72859909 JS |
9027 | kfree(phba->vpi_bmask); |
9028 | kfree(phba->vpi_ids); | |
9029 | ||
da0436e9 JS |
9030 | lpfc_stop_hba_timers(phba); |
9031 | ||
9032 | phba->pport->work_port_events = 0; | |
9033 | ||
9034 | lpfc_sli_hba_down(phba); | |
9035 | ||
9036 | lpfc_sli_brdrestart(phba); | |
9037 | ||
9038 | lpfc_sli_disable_intr(phba); | |
9039 | ||
9040 | return; | |
9041 | } | |
9042 | ||
5af5eee7 JS |
9043 | /** |
9044 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy | |
9045 | * @phba: Pointer to HBA context object. | |
9046 | * | |
9047 | * This function is called in the SLI4 code path to wait for completion | |
9048 | * of device's XRIs exchange busy. It will check the XRI exchange busy | |
9049 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after | |
9050 | * that, it will check the XRI exchange busy on outstanding FCP and ELS | |
9051 | * I/Os every 30 seconds, log error message, and wait forever. Only when | |
9052 | * all XRI exchange busy complete, the driver unload shall proceed with | |
9053 | * invoking the function reset ioctl mailbox command to the CNA and the | |
9054 | * the rest of the driver unload resource release. | |
9055 | **/ | |
9056 | static void | |
9057 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) | |
9058 | { | |
9059 | int wait_time = 0; | |
9060 | int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
9061 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
9062 | ||
9063 | while (!fcp_xri_cmpl || !els_xri_cmpl) { | |
9064 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { | |
9065 | if (!fcp_xri_cmpl) | |
9066 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9067 | "2877 FCP XRI exchange busy " | |
9068 | "wait time: %d seconds.\n", | |
9069 | wait_time/1000); | |
9070 | if (!els_xri_cmpl) | |
9071 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9072 | "2878 ELS XRI exchange busy " | |
9073 | "wait time: %d seconds.\n", | |
9074 | wait_time/1000); | |
9075 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); | |
9076 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; | |
9077 | } else { | |
9078 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); | |
9079 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; | |
9080 | } | |
9081 | fcp_xri_cmpl = | |
9082 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
9083 | els_xri_cmpl = | |
9084 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
9085 | } | |
9086 | } | |
9087 | ||
da0436e9 JS |
9088 | /** |
9089 | * lpfc_sli4_hba_unset - Unset the fcoe hba | |
9090 | * @phba: Pointer to HBA context object. | |
9091 | * | |
9092 | * This function is called in the SLI4 code path to reset the HBA's FCoE | |
9093 | * function. The caller is not required to hold any lock. This routine | |
9094 | * issues PCI function reset mailbox command to reset the FCoE function. | |
9095 | * At the end of the function, it calls lpfc_hba_down_post function to | |
9096 | * free any pending commands. | |
9097 | **/ | |
9098 | static void | |
9099 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) | |
9100 | { | |
9101 | int wait_cnt = 0; | |
9102 | LPFC_MBOXQ_t *mboxq; | |
912e3acd | 9103 | struct pci_dev *pdev = phba->pcidev; |
da0436e9 JS |
9104 | |
9105 | lpfc_stop_hba_timers(phba); | |
9106 | phba->sli4_hba.intr_enable = 0; | |
9107 | ||
9108 | /* | |
9109 | * Gracefully wait out the potential current outstanding asynchronous | |
9110 | * mailbox command. | |
9111 | */ | |
9112 | ||
9113 | /* First, block any pending async mailbox command from posted */ | |
9114 | spin_lock_irq(&phba->hbalock); | |
9115 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
9116 | spin_unlock_irq(&phba->hbalock); | |
9117 | /* Now, trying to wait it out if we can */ | |
9118 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
9119 | msleep(10); | |
9120 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) | |
9121 | break; | |
9122 | } | |
9123 | /* Forcefully release the outstanding mailbox command if timed out */ | |
9124 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
9125 | spin_lock_irq(&phba->hbalock); | |
9126 | mboxq = phba->sli.mbox_active; | |
9127 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
9128 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
9129 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
9130 | phba->sli.mbox_active = NULL; | |
9131 | spin_unlock_irq(&phba->hbalock); | |
9132 | } | |
9133 | ||
5af5eee7 JS |
9134 | /* Abort all iocbs associated with the hba */ |
9135 | lpfc_sli_hba_iocb_abort(phba); | |
9136 | ||
9137 | /* Wait for completion of device XRI exchange busy */ | |
9138 | lpfc_sli4_xri_exchange_busy_wait(phba); | |
9139 | ||
da0436e9 JS |
9140 | /* Disable PCI subsystem interrupt */ |
9141 | lpfc_sli4_disable_intr(phba); | |
9142 | ||
912e3acd JS |
9143 | /* Disable SR-IOV if enabled */ |
9144 | if (phba->cfg_sriov_nr_virtfn) | |
9145 | pci_disable_sriov(pdev); | |
9146 | ||
da0436e9 JS |
9147 | /* Stop kthread signal shall trigger work_done one more time */ |
9148 | kthread_stop(phba->worker_thread); | |
9149 | ||
3677a3a7 JS |
9150 | /* Reset SLI4 HBA FCoE function */ |
9151 | lpfc_pci_function_reset(phba); | |
5350d872 | 9152 | lpfc_sli4_queue_destroy(phba); |
3677a3a7 | 9153 | |
da0436e9 JS |
9154 | /* Stop the SLI4 device port */ |
9155 | phba->pport->work_port_events = 0; | |
9156 | } | |
9157 | ||
28baac74 JS |
9158 | /** |
9159 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. | |
9160 | * @phba: Pointer to HBA context object. | |
9161 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. | |
9162 | * | |
9163 | * This function is called in the SLI4 code path to read the port's | |
9164 | * sli4 capabilities. | |
9165 | * | |
9166 | * This function may be be called from any context that can block-wait | |
9167 | * for the completion. The expectation is that this routine is called | |
9168 | * typically from probe_one or from the online routine. | |
9169 | **/ | |
9170 | int | |
9171 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
9172 | { | |
9173 | int rc; | |
9174 | struct lpfc_mqe *mqe; | |
9175 | struct lpfc_pc_sli4_params *sli4_params; | |
9176 | uint32_t mbox_tmo; | |
9177 | ||
9178 | rc = 0; | |
9179 | mqe = &mboxq->u.mqe; | |
9180 | ||
9181 | /* Read the port's SLI4 Parameters port capabilities */ | |
fedd3b7b | 9182 | lpfc_pc_sli4_params(mboxq); |
28baac74 JS |
9183 | if (!phba->sli4_hba.intr_enable) |
9184 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
9185 | else { | |
a183a15f | 9186 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
28baac74 JS |
9187 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
9188 | } | |
9189 | ||
9190 | if (unlikely(rc)) | |
9191 | return 1; | |
9192 | ||
9193 | sli4_params = &phba->sli4_hba.pc_sli4_params; | |
9194 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); | |
9195 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); | |
9196 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); | |
9197 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, | |
9198 | &mqe->un.sli4_params); | |
9199 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, | |
9200 | &mqe->un.sli4_params); | |
9201 | sli4_params->proto_types = mqe->un.sli4_params.word3; | |
9202 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; | |
9203 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); | |
9204 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); | |
9205 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); | |
9206 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); | |
9207 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); | |
9208 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); | |
9209 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); | |
9210 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); | |
9211 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); | |
9212 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); | |
9213 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); | |
9214 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); | |
9215 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); | |
9216 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); | |
9217 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); | |
9218 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); | |
9219 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); | |
9220 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); | |
9221 | sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params); | |
0558056c JS |
9222 | |
9223 | /* Make sure that sge_supp_len can be handled by the driver */ | |
9224 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) | |
9225 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; | |
9226 | ||
28baac74 JS |
9227 | return rc; |
9228 | } | |
9229 | ||
fedd3b7b JS |
9230 | /** |
9231 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. | |
9232 | * @phba: Pointer to HBA context object. | |
9233 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. | |
9234 | * | |
9235 | * This function is called in the SLI4 code path to read the port's | |
9236 | * sli4 capabilities. | |
9237 | * | |
9238 | * This function may be be called from any context that can block-wait | |
9239 | * for the completion. The expectation is that this routine is called | |
9240 | * typically from probe_one or from the online routine. | |
9241 | **/ | |
9242 | int | |
9243 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
9244 | { | |
9245 | int rc; | |
9246 | struct lpfc_mqe *mqe = &mboxq->u.mqe; | |
9247 | struct lpfc_pc_sli4_params *sli4_params; | |
a183a15f | 9248 | uint32_t mbox_tmo; |
fedd3b7b JS |
9249 | int length; |
9250 | struct lpfc_sli4_parameters *mbx_sli4_parameters; | |
9251 | ||
6d368e53 JS |
9252 | /* |
9253 | * By default, the driver assumes the SLI4 port requires RPI | |
9254 | * header postings. The SLI4_PARAM response will correct this | |
9255 | * assumption. | |
9256 | */ | |
9257 | phba->sli4_hba.rpi_hdrs_in_use = 1; | |
9258 | ||
fedd3b7b JS |
9259 | /* Read the port's SLI4 Config Parameters */ |
9260 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - | |
9261 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
9262 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
9263 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, | |
9264 | length, LPFC_SLI4_MBX_EMBED); | |
9265 | if (!phba->sli4_hba.intr_enable) | |
9266 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
a183a15f JS |
9267 | else { |
9268 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); | |
9269 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
9270 | } | |
fedd3b7b JS |
9271 | if (unlikely(rc)) |
9272 | return rc; | |
9273 | sli4_params = &phba->sli4_hba.pc_sli4_params; | |
9274 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; | |
9275 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); | |
9276 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); | |
9277 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); | |
9278 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, | |
9279 | mbx_sli4_parameters); | |
9280 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, | |
9281 | mbx_sli4_parameters); | |
9282 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) | |
9283 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; | |
9284 | else | |
9285 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; | |
9286 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; | |
9287 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); | |
1ba981fd | 9288 | sli4_params->oas_supported = bf_get(cfg_oas, mbx_sli4_parameters); |
fedd3b7b JS |
9289 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); |
9290 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); | |
9291 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); | |
9292 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); | |
0c651878 | 9293 | sli4_params->wqsize = bf_get(cfg_wqsize, mbx_sli4_parameters); |
fedd3b7b JS |
9294 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, |
9295 | mbx_sli4_parameters); | |
9296 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, | |
9297 | mbx_sli4_parameters); | |
6d368e53 JS |
9298 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
9299 | phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters); | |
0558056c JS |
9300 | |
9301 | /* Make sure that sge_supp_len can be handled by the driver */ | |
9302 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) | |
9303 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; | |
9304 | ||
fedd3b7b JS |
9305 | return 0; |
9306 | } | |
9307 | ||
da0436e9 JS |
9308 | /** |
9309 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. | |
9310 | * @pdev: pointer to PCI device | |
9311 | * @pid: pointer to PCI device identifier | |
9312 | * | |
9313 | * This routine is to be called to attach a device with SLI-3 interface spec | |
9314 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
9315 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific | |
9316 | * information of the device and driver to see if the driver state that it can | |
9317 | * support this kind of device. If the match is successful, the driver core | |
9318 | * invokes this routine. If this routine determines it can claim the HBA, it | |
9319 | * does all the initialization that it needs to do to handle the HBA properly. | |
9320 | * | |
9321 | * Return code | |
9322 | * 0 - driver can claim the device | |
9323 | * negative value - driver can not claim the device | |
9324 | **/ | |
6f039790 | 9325 | static int |
da0436e9 JS |
9326 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) |
9327 | { | |
9328 | struct lpfc_hba *phba; | |
9329 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 9330 | struct Scsi_Host *shost = NULL; |
da0436e9 JS |
9331 | int error; |
9332 | uint32_t cfg_mode, intr_mode; | |
9333 | ||
9334 | /* Allocate memory for HBA structure */ | |
9335 | phba = lpfc_hba_alloc(pdev); | |
9336 | if (!phba) | |
9337 | return -ENOMEM; | |
9338 | ||
9339 | /* Perform generic PCI device enabling operation */ | |
9340 | error = lpfc_enable_pci_dev(phba); | |
079b5c91 | 9341 | if (error) |
da0436e9 | 9342 | goto out_free_phba; |
da0436e9 JS |
9343 | |
9344 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ | |
9345 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); | |
9346 | if (error) | |
9347 | goto out_disable_pci_dev; | |
9348 | ||
9349 | /* Set up SLI-3 specific device PCI memory space */ | |
9350 | error = lpfc_sli_pci_mem_setup(phba); | |
9351 | if (error) { | |
9352 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9353 | "1402 Failed to set up pci memory space.\n"); | |
9354 | goto out_disable_pci_dev; | |
9355 | } | |
9356 | ||
9357 | /* Set up phase-1 common device driver resources */ | |
9358 | error = lpfc_setup_driver_resource_phase1(phba); | |
9359 | if (error) { | |
9360 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9361 | "1403 Failed to set up driver resource.\n"); | |
9362 | goto out_unset_pci_mem_s3; | |
9363 | } | |
9364 | ||
9365 | /* Set up SLI-3 specific device driver resources */ | |
9366 | error = lpfc_sli_driver_resource_setup(phba); | |
9367 | if (error) { | |
9368 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9369 | "1404 Failed to set up driver resource.\n"); | |
9370 | goto out_unset_pci_mem_s3; | |
9371 | } | |
9372 | ||
9373 | /* Initialize and populate the iocb list per host */ | |
9374 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); | |
9375 | if (error) { | |
9376 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9377 | "1405 Failed to initialize iocb list.\n"); | |
9378 | goto out_unset_driver_resource_s3; | |
9379 | } | |
9380 | ||
9381 | /* Set up common device driver resources */ | |
9382 | error = lpfc_setup_driver_resource_phase2(phba); | |
9383 | if (error) { | |
9384 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9385 | "1406 Failed to set up driver resource.\n"); | |
9386 | goto out_free_iocb_list; | |
9387 | } | |
9388 | ||
079b5c91 JS |
9389 | /* Get the default values for Model Name and Description */ |
9390 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
9391 | ||
da0436e9 JS |
9392 | /* Create SCSI host to the physical port */ |
9393 | error = lpfc_create_shost(phba); | |
9394 | if (error) { | |
9395 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9396 | "1407 Failed to create scsi host.\n"); | |
9397 | goto out_unset_driver_resource; | |
9398 | } | |
9399 | ||
9400 | /* Configure sysfs attributes */ | |
9401 | vport = phba->pport; | |
9402 | error = lpfc_alloc_sysfs_attr(vport); | |
9403 | if (error) { | |
9404 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9405 | "1476 Failed to allocate sysfs attr\n"); | |
9406 | goto out_destroy_shost; | |
9407 | } | |
9408 | ||
6669f9bb | 9409 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
da0436e9 JS |
9410 | /* Now, trying to enable interrupt and bring up the device */ |
9411 | cfg_mode = phba->cfg_use_msi; | |
9412 | while (true) { | |
9413 | /* Put device to a known state before enabling interrupt */ | |
9414 | lpfc_stop_port(phba); | |
9415 | /* Configure and enable interrupt */ | |
9416 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); | |
9417 | if (intr_mode == LPFC_INTR_ERROR) { | |
9418 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9419 | "0431 Failed to enable interrupt.\n"); | |
9420 | error = -ENODEV; | |
9421 | goto out_free_sysfs_attr; | |
9422 | } | |
9423 | /* SLI-3 HBA setup */ | |
9424 | if (lpfc_sli_hba_setup(phba)) { | |
9425 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9426 | "1477 Failed to set up hba\n"); | |
9427 | error = -ENODEV; | |
9428 | goto out_remove_device; | |
9429 | } | |
9430 | ||
9431 | /* Wait 50ms for the interrupts of previous mailbox commands */ | |
9432 | msleep(50); | |
9433 | /* Check active interrupts on message signaled interrupts */ | |
9434 | if (intr_mode == 0 || | |
9435 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { | |
9436 | /* Log the current active interrupt mode */ | |
9437 | phba->intr_mode = intr_mode; | |
9438 | lpfc_log_intr_mode(phba, intr_mode); | |
9439 | break; | |
9440 | } else { | |
9441 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
9442 | "0447 Configure interrupt mode (%d) " | |
9443 | "failed active interrupt test.\n", | |
9444 | intr_mode); | |
9445 | /* Disable the current interrupt mode */ | |
9446 | lpfc_sli_disable_intr(phba); | |
9447 | /* Try next level of interrupt mode */ | |
9448 | cfg_mode = --intr_mode; | |
9449 | } | |
9450 | } | |
9451 | ||
9452 | /* Perform post initialization setup */ | |
9453 | lpfc_post_init_setup(phba); | |
9454 | ||
9455 | /* Check if there are static vports to be created. */ | |
9456 | lpfc_create_static_vport(phba); | |
9457 | ||
9458 | return 0; | |
9459 | ||
9460 | out_remove_device: | |
9461 | lpfc_unset_hba(phba); | |
9462 | out_free_sysfs_attr: | |
9463 | lpfc_free_sysfs_attr(vport); | |
9464 | out_destroy_shost: | |
9465 | lpfc_destroy_shost(phba); | |
9466 | out_unset_driver_resource: | |
9467 | lpfc_unset_driver_resource_phase2(phba); | |
9468 | out_free_iocb_list: | |
9469 | lpfc_free_iocb_list(phba); | |
9470 | out_unset_driver_resource_s3: | |
9471 | lpfc_sli_driver_resource_unset(phba); | |
9472 | out_unset_pci_mem_s3: | |
9473 | lpfc_sli_pci_mem_unset(phba); | |
9474 | out_disable_pci_dev: | |
9475 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
9476 | if (shost) |
9477 | scsi_host_put(shost); | |
da0436e9 JS |
9478 | out_free_phba: |
9479 | lpfc_hba_free(phba); | |
9480 | return error; | |
9481 | } | |
9482 | ||
9483 | /** | |
9484 | * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem. | |
9485 | * @pdev: pointer to PCI device | |
9486 | * | |
9487 | * This routine is to be called to disattach a device with SLI-3 interface | |
9488 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
9489 | * removed from PCI bus, it performs all the necessary cleanup for the HBA | |
9490 | * device to be removed from the PCI subsystem properly. | |
9491 | **/ | |
6f039790 | 9492 | static void |
da0436e9 JS |
9493 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) |
9494 | { | |
9495 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9496 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
9497 | struct lpfc_vport **vports; | |
9498 | struct lpfc_hba *phba = vport->phba; | |
9499 | int i; | |
9500 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
9501 | ||
9502 | spin_lock_irq(&phba->hbalock); | |
9503 | vport->load_flag |= FC_UNLOADING; | |
9504 | spin_unlock_irq(&phba->hbalock); | |
9505 | ||
9506 | lpfc_free_sysfs_attr(vport); | |
9507 | ||
9508 | /* Release all the vports against this physical port */ | |
9509 | vports = lpfc_create_vport_work_array(phba); | |
9510 | if (vports != NULL) | |
587a37f6 JS |
9511 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
9512 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) | |
9513 | continue; | |
da0436e9 | 9514 | fc_vport_terminate(vports[i]->fc_vport); |
587a37f6 | 9515 | } |
da0436e9 JS |
9516 | lpfc_destroy_vport_work_array(phba, vports); |
9517 | ||
9518 | /* Remove FC host and then SCSI host with the physical port */ | |
9519 | fc_remove_host(shost); | |
9520 | scsi_remove_host(shost); | |
9521 | lpfc_cleanup(vport); | |
9522 | ||
9523 | /* | |
9524 | * Bring down the SLI Layer. This step disable all interrupts, | |
9525 | * clears the rings, discards all mailbox commands, and resets | |
9526 | * the HBA. | |
9527 | */ | |
9528 | ||
48e34d0f | 9529 | /* HBA interrupt will be disabled after this call */ |
da0436e9 JS |
9530 | lpfc_sli_hba_down(phba); |
9531 | /* Stop kthread signal shall trigger work_done one more time */ | |
9532 | kthread_stop(phba->worker_thread); | |
9533 | /* Final cleanup of txcmplq and reset the HBA */ | |
9534 | lpfc_sli_brdrestart(phba); | |
9535 | ||
72859909 JS |
9536 | kfree(phba->vpi_bmask); |
9537 | kfree(phba->vpi_ids); | |
9538 | ||
da0436e9 JS |
9539 | lpfc_stop_hba_timers(phba); |
9540 | spin_lock_irq(&phba->hbalock); | |
9541 | list_del_init(&vport->listentry); | |
9542 | spin_unlock_irq(&phba->hbalock); | |
9543 | ||
9544 | lpfc_debugfs_terminate(vport); | |
9545 | ||
912e3acd JS |
9546 | /* Disable SR-IOV if enabled */ |
9547 | if (phba->cfg_sriov_nr_virtfn) | |
9548 | pci_disable_sriov(pdev); | |
9549 | ||
da0436e9 JS |
9550 | /* Disable interrupt */ |
9551 | lpfc_sli_disable_intr(phba); | |
9552 | ||
da0436e9 JS |
9553 | scsi_host_put(shost); |
9554 | ||
9555 | /* | |
9556 | * Call scsi_free before mem_free since scsi bufs are released to their | |
9557 | * corresponding pools here. | |
9558 | */ | |
9559 | lpfc_scsi_free(phba); | |
9560 | lpfc_mem_free_all(phba); | |
9561 | ||
9562 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
9563 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
9564 | ||
9565 | /* Free resources associated with SLI2 interface */ | |
9566 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
9567 | phba->slim2p.virt, phba->slim2p.phys); | |
9568 | ||
9569 | /* unmap adapter SLIM and Control Registers */ | |
9570 | iounmap(phba->ctrl_regs_memmap_p); | |
9571 | iounmap(phba->slim_memmap_p); | |
9572 | ||
9573 | lpfc_hba_free(phba); | |
9574 | ||
9575 | pci_release_selected_regions(pdev, bars); | |
9576 | pci_disable_device(pdev); | |
9577 | } | |
9578 | ||
9579 | /** | |
9580 | * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt | |
9581 | * @pdev: pointer to PCI device | |
9582 | * @msg: power management message | |
9583 | * | |
9584 | * This routine is to be called from the kernel's PCI subsystem to support | |
9585 | * system Power Management (PM) to device with SLI-3 interface spec. When | |
9586 | * PM invokes this method, it quiesces the device by stopping the driver's | |
9587 | * worker thread for the device, turning off device's interrupt and DMA, | |
9588 | * and bring the device offline. Note that as the driver implements the | |
9589 | * minimum PM requirements to a power-aware driver's PM support for the | |
9590 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
9591 | * to the suspend() method call will be treated as SUSPEND and the driver will | |
9592 | * fully reinitialize its device during resume() method call, the driver will | |
9593 | * set device to PCI_D3hot state in PCI config space instead of setting it | |
9594 | * according to the @msg provided by the PM. | |
9595 | * | |
9596 | * Return code | |
9597 | * 0 - driver suspended the device | |
9598 | * Error otherwise | |
9599 | **/ | |
9600 | static int | |
9601 | lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg) | |
9602 | { | |
9603 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9604 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9605 | ||
9606 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
9607 | "0473 PCI device Power Management suspend.\n"); | |
9608 | ||
9609 | /* Bring down the device */ | |
618a5230 | 9610 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
da0436e9 JS |
9611 | lpfc_offline(phba); |
9612 | kthread_stop(phba->worker_thread); | |
9613 | ||
9614 | /* Disable interrupt from device */ | |
9615 | lpfc_sli_disable_intr(phba); | |
9616 | ||
9617 | /* Save device state to PCI config space */ | |
9618 | pci_save_state(pdev); | |
9619 | pci_set_power_state(pdev, PCI_D3hot); | |
9620 | ||
9621 | return 0; | |
9622 | } | |
9623 | ||
9624 | /** | |
9625 | * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt | |
9626 | * @pdev: pointer to PCI device | |
9627 | * | |
9628 | * This routine is to be called from the kernel's PCI subsystem to support | |
9629 | * system Power Management (PM) to device with SLI-3 interface spec. When PM | |
9630 | * invokes this method, it restores the device's PCI config space state and | |
9631 | * fully reinitializes the device and brings it online. Note that as the | |
9632 | * driver implements the minimum PM requirements to a power-aware driver's | |
9633 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, | |
9634 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the | |
9635 | * driver will fully reinitialize its device during resume() method call, | |
9636 | * the device will be set to PCI_D0 directly in PCI config space before | |
9637 | * restoring the state. | |
9638 | * | |
9639 | * Return code | |
9640 | * 0 - driver suspended the device | |
9641 | * Error otherwise | |
9642 | **/ | |
9643 | static int | |
9644 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) | |
9645 | { | |
9646 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9647 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9648 | uint32_t intr_mode; | |
9649 | int error; | |
9650 | ||
9651 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
9652 | "0452 PCI device Power Management resume.\n"); | |
9653 | ||
9654 | /* Restore device state from PCI config space */ | |
9655 | pci_set_power_state(pdev, PCI_D0); | |
9656 | pci_restore_state(pdev); | |
0d878419 | 9657 | |
1dfb5a47 JS |
9658 | /* |
9659 | * As the new kernel behavior of pci_restore_state() API call clears | |
9660 | * device saved_state flag, need to save the restored state again. | |
9661 | */ | |
9662 | pci_save_state(pdev); | |
9663 | ||
da0436e9 JS |
9664 | if (pdev->is_busmaster) |
9665 | pci_set_master(pdev); | |
9666 | ||
9667 | /* Startup the kernel thread for this host adapter. */ | |
9668 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
9669 | "lpfc_worker_%d", phba->brd_no); | |
9670 | if (IS_ERR(phba->worker_thread)) { | |
9671 | error = PTR_ERR(phba->worker_thread); | |
9672 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9673 | "0434 PM resume failed to start worker " | |
9674 | "thread: error=x%x.\n", error); | |
9675 | return error; | |
9676 | } | |
9677 | ||
9678 | /* Configure and enable interrupt */ | |
9679 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
9680 | if (intr_mode == LPFC_INTR_ERROR) { | |
9681 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9682 | "0430 PM resume Failed to enable interrupt\n"); | |
9683 | return -EIO; | |
9684 | } else | |
9685 | phba->intr_mode = intr_mode; | |
9686 | ||
9687 | /* Restart HBA and bring it online */ | |
9688 | lpfc_sli_brdrestart(phba); | |
9689 | lpfc_online(phba); | |
9690 | ||
9691 | /* Log the current active interrupt mode */ | |
9692 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
9693 | ||
9694 | return 0; | |
9695 | } | |
9696 | ||
891478a2 JS |
9697 | /** |
9698 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover | |
9699 | * @phba: pointer to lpfc hba data structure. | |
9700 | * | |
9701 | * This routine is called to prepare the SLI3 device for PCI slot recover. It | |
e2af0d2e | 9702 | * aborts all the outstanding SCSI I/Os to the pci device. |
891478a2 JS |
9703 | **/ |
9704 | static void | |
9705 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) | |
9706 | { | |
e2af0d2e JS |
9707 | struct lpfc_sli *psli = &phba->sli; |
9708 | struct lpfc_sli_ring *pring; | |
9709 | ||
891478a2 JS |
9710 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
9711 | "2723 PCI channel I/O abort preparing for recovery\n"); | |
e2af0d2e JS |
9712 | |
9713 | /* | |
9714 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
9715 | * and let the SCSI mid-layer to retry them to recover. | |
9716 | */ | |
9717 | pring = &psli->ring[psli->fcp_ring]; | |
9718 | lpfc_sli_abort_iocb_ring(phba, pring); | |
891478a2 JS |
9719 | } |
9720 | ||
0d878419 JS |
9721 | /** |
9722 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset | |
9723 | * @phba: pointer to lpfc hba data structure. | |
9724 | * | |
9725 | * This routine is called to prepare the SLI3 device for PCI slot reset. It | |
9726 | * disables the device interrupt and pci device, and aborts the internal FCP | |
9727 | * pending I/Os. | |
9728 | **/ | |
9729 | static void | |
9730 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) | |
9731 | { | |
0d878419 | 9732 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
891478a2 | 9733 | "2710 PCI channel disable preparing for reset\n"); |
e2af0d2e | 9734 | |
75baf696 | 9735 | /* Block any management I/Os to the device */ |
618a5230 | 9736 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
75baf696 | 9737 | |
e2af0d2e JS |
9738 | /* Block all SCSI devices' I/Os on the host */ |
9739 | lpfc_scsi_dev_block(phba); | |
9740 | ||
ea714f3d JS |
9741 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
9742 | lpfc_sli_flush_fcp_rings(phba); | |
9743 | ||
e2af0d2e JS |
9744 | /* stop all timers */ |
9745 | lpfc_stop_hba_timers(phba); | |
9746 | ||
0d878419 JS |
9747 | /* Disable interrupt and pci device */ |
9748 | lpfc_sli_disable_intr(phba); | |
9749 | pci_disable_device(phba->pcidev); | |
0d878419 JS |
9750 | } |
9751 | ||
9752 | /** | |
9753 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable | |
9754 | * @phba: pointer to lpfc hba data structure. | |
9755 | * | |
9756 | * This routine is called to prepare the SLI3 device for PCI slot permanently | |
9757 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
9758 | * pending I/Os. | |
9759 | **/ | |
9760 | static void | |
75baf696 | 9761 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
0d878419 JS |
9762 | { |
9763 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
891478a2 | 9764 | "2711 PCI channel permanent disable for failure\n"); |
e2af0d2e JS |
9765 | /* Block all SCSI devices' I/Os on the host */ |
9766 | lpfc_scsi_dev_block(phba); | |
9767 | ||
9768 | /* stop all timers */ | |
9769 | lpfc_stop_hba_timers(phba); | |
9770 | ||
0d878419 JS |
9771 | /* Clean up all driver's outstanding SCSI I/Os */ |
9772 | lpfc_sli_flush_fcp_rings(phba); | |
9773 | } | |
9774 | ||
da0436e9 JS |
9775 | /** |
9776 | * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error | |
9777 | * @pdev: pointer to PCI device. | |
9778 | * @state: the current PCI connection state. | |
9779 | * | |
9780 | * This routine is called from the PCI subsystem for I/O error handling to | |
9781 | * device with SLI-3 interface spec. This function is called by the PCI | |
9782 | * subsystem after a PCI bus error affecting this device has been detected. | |
9783 | * When this function is invoked, it will need to stop all the I/Os and | |
9784 | * interrupt(s) to the device. Once that is done, it will return | |
9785 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery | |
9786 | * as desired. | |
9787 | * | |
9788 | * Return codes | |
0d878419 | 9789 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
da0436e9 JS |
9790 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
9791 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
9792 | **/ | |
9793 | static pci_ers_result_t | |
9794 | lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state) | |
9795 | { | |
9796 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9797 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
da0436e9 | 9798 | |
0d878419 JS |
9799 | switch (state) { |
9800 | case pci_channel_io_normal: | |
891478a2 JS |
9801 | /* Non-fatal error, prepare for recovery */ |
9802 | lpfc_sli_prep_dev_for_recover(phba); | |
0d878419 JS |
9803 | return PCI_ERS_RESULT_CAN_RECOVER; |
9804 | case pci_channel_io_frozen: | |
9805 | /* Fatal error, prepare for slot reset */ | |
9806 | lpfc_sli_prep_dev_for_reset(phba); | |
9807 | return PCI_ERS_RESULT_NEED_RESET; | |
9808 | case pci_channel_io_perm_failure: | |
9809 | /* Permanent failure, prepare for device down */ | |
75baf696 | 9810 | lpfc_sli_prep_dev_for_perm_failure(phba); |
da0436e9 | 9811 | return PCI_ERS_RESULT_DISCONNECT; |
0d878419 JS |
9812 | default: |
9813 | /* Unknown state, prepare and request slot reset */ | |
9814 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9815 | "0472 Unknown PCI error state: x%x\n", state); | |
9816 | lpfc_sli_prep_dev_for_reset(phba); | |
9817 | return PCI_ERS_RESULT_NEED_RESET; | |
da0436e9 | 9818 | } |
da0436e9 JS |
9819 | } |
9820 | ||
9821 | /** | |
9822 | * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch. | |
9823 | * @pdev: pointer to PCI device. | |
9824 | * | |
9825 | * This routine is called from the PCI subsystem for error handling to | |
9826 | * device with SLI-3 interface spec. This is called after PCI bus has been | |
9827 | * reset to restart the PCI card from scratch, as if from a cold-boot. | |
9828 | * During the PCI subsystem error recovery, after driver returns | |
9829 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error | |
9830 | * recovery and then call this routine before calling the .resume method | |
9831 | * to recover the device. This function will initialize the HBA device, | |
9832 | * enable the interrupt, but it will just put the HBA to offline state | |
9833 | * without passing any I/O traffic. | |
9834 | * | |
9835 | * Return codes | |
9836 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
9837 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
9838 | */ | |
9839 | static pci_ers_result_t | |
9840 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) | |
9841 | { | |
9842 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9843 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9844 | struct lpfc_sli *psli = &phba->sli; | |
9845 | uint32_t intr_mode; | |
9846 | ||
9847 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
9848 | if (pci_enable_device_mem(pdev)) { | |
9849 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
9850 | "PCI device after reset.\n"); | |
9851 | return PCI_ERS_RESULT_DISCONNECT; | |
9852 | } | |
9853 | ||
9854 | pci_restore_state(pdev); | |
1dfb5a47 JS |
9855 | |
9856 | /* | |
9857 | * As the new kernel behavior of pci_restore_state() API call clears | |
9858 | * device saved_state flag, need to save the restored state again. | |
9859 | */ | |
9860 | pci_save_state(pdev); | |
9861 | ||
da0436e9 JS |
9862 | if (pdev->is_busmaster) |
9863 | pci_set_master(pdev); | |
9864 | ||
9865 | spin_lock_irq(&phba->hbalock); | |
9866 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
9867 | spin_unlock_irq(&phba->hbalock); | |
9868 | ||
9869 | /* Configure and enable interrupt */ | |
9870 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
9871 | if (intr_mode == LPFC_INTR_ERROR) { | |
9872 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9873 | "0427 Cannot re-enable interrupt after " | |
9874 | "slot reset.\n"); | |
9875 | return PCI_ERS_RESULT_DISCONNECT; | |
9876 | } else | |
9877 | phba->intr_mode = intr_mode; | |
9878 | ||
75baf696 | 9879 | /* Take device offline, it will perform cleanup */ |
618a5230 | 9880 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
da0436e9 JS |
9881 | lpfc_offline(phba); |
9882 | lpfc_sli_brdrestart(phba); | |
9883 | ||
9884 | /* Log the current active interrupt mode */ | |
9885 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
9886 | ||
9887 | return PCI_ERS_RESULT_RECOVERED; | |
9888 | } | |
9889 | ||
9890 | /** | |
9891 | * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device. | |
9892 | * @pdev: pointer to PCI device | |
9893 | * | |
9894 | * This routine is called from the PCI subsystem for error handling to device | |
9895 | * with SLI-3 interface spec. It is called when kernel error recovery tells | |
9896 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus | |
9897 | * error recovery. After this call, traffic can start to flow from this device | |
9898 | * again. | |
9899 | */ | |
9900 | static void | |
9901 | lpfc_io_resume_s3(struct pci_dev *pdev) | |
9902 | { | |
9903 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9904 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
3772a991 | 9905 | |
e2af0d2e | 9906 | /* Bring device online, it will be no-op for non-fatal error resume */ |
da0436e9 | 9907 | lpfc_online(phba); |
0d878419 JS |
9908 | |
9909 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
9910 | if (phba->hba_flag & HBA_AER_ENABLED) | |
9911 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
da0436e9 | 9912 | } |
3772a991 | 9913 | |
da0436e9 JS |
9914 | /** |
9915 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve | |
9916 | * @phba: pointer to lpfc hba data structure. | |
9917 | * | |
9918 | * returns the number of ELS/CT IOCBs to reserve | |
9919 | **/ | |
9920 | int | |
9921 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) | |
9922 | { | |
9923 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; | |
9924 | ||
f1126688 JS |
9925 | if (phba->sli_rev == LPFC_SLI_REV4) { |
9926 | if (max_xri <= 100) | |
6a9c52cf | 9927 | return 10; |
f1126688 | 9928 | else if (max_xri <= 256) |
6a9c52cf | 9929 | return 25; |
f1126688 | 9930 | else if (max_xri <= 512) |
6a9c52cf | 9931 | return 50; |
f1126688 | 9932 | else if (max_xri <= 1024) |
6a9c52cf | 9933 | return 100; |
8a9d2e80 | 9934 | else if (max_xri <= 1536) |
6a9c52cf | 9935 | return 150; |
8a9d2e80 JS |
9936 | else if (max_xri <= 2048) |
9937 | return 200; | |
9938 | else | |
9939 | return 250; | |
f1126688 JS |
9940 | } else |
9941 | return 0; | |
3772a991 JS |
9942 | } |
9943 | ||
52d52440 JS |
9944 | /** |
9945 | * lpfc_write_firmware - attempt to write a firmware image to the port | |
52d52440 | 9946 | * @fw: pointer to firmware image returned from request_firmware. |
ce396282 | 9947 | * @phba: pointer to lpfc hba data structure. |
52d52440 | 9948 | * |
52d52440 | 9949 | **/ |
ce396282 JS |
9950 | static void |
9951 | lpfc_write_firmware(const struct firmware *fw, void *context) | |
52d52440 | 9952 | { |
ce396282 | 9953 | struct lpfc_hba *phba = (struct lpfc_hba *)context; |
6b5151fd | 9954 | char fwrev[FW_REV_STR_SIZE]; |
ce396282 | 9955 | struct lpfc_grp_hdr *image; |
52d52440 JS |
9956 | struct list_head dma_buffer_list; |
9957 | int i, rc = 0; | |
9958 | struct lpfc_dmabuf *dmabuf, *next; | |
9959 | uint32_t offset = 0, temp_offset = 0; | |
9960 | ||
c71ab861 | 9961 | /* It can be null in no-wait mode, sanity check */ |
ce396282 JS |
9962 | if (!fw) { |
9963 | rc = -ENXIO; | |
9964 | goto out; | |
9965 | } | |
9966 | image = (struct lpfc_grp_hdr *)fw->data; | |
9967 | ||
52d52440 | 9968 | INIT_LIST_HEAD(&dma_buffer_list); |
079b5c91 JS |
9969 | if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) || |
9970 | (bf_get_be32(lpfc_grp_hdr_file_type, image) != | |
9971 | LPFC_FILE_TYPE_GROUP) || | |
9972 | (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) || | |
9973 | (be32_to_cpu(image->size) != fw->size)) { | |
52d52440 JS |
9974 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
9975 | "3022 Invalid FW image found. " | |
079b5c91 JS |
9976 | "Magic:%x Type:%x ID:%x\n", |
9977 | be32_to_cpu(image->magic_number), | |
9978 | bf_get_be32(lpfc_grp_hdr_file_type, image), | |
9979 | bf_get_be32(lpfc_grp_hdr_id, image)); | |
ce396282 JS |
9980 | rc = -EINVAL; |
9981 | goto release_out; | |
52d52440 JS |
9982 | } |
9983 | lpfc_decode_firmware_rev(phba, fwrev, 1); | |
88a2cfbb | 9984 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
52d52440 | 9985 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
ce396282 | 9986 | "3023 Updating Firmware, Current Version:%s " |
52d52440 | 9987 | "New Version:%s\n", |
88a2cfbb | 9988 | fwrev, image->revision); |
52d52440 JS |
9989 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
9990 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), | |
9991 | GFP_KERNEL); | |
9992 | if (!dmabuf) { | |
9993 | rc = -ENOMEM; | |
ce396282 | 9994 | goto release_out; |
52d52440 JS |
9995 | } |
9996 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
9997 | SLI4_PAGE_SIZE, | |
9998 | &dmabuf->phys, | |
9999 | GFP_KERNEL); | |
10000 | if (!dmabuf->virt) { | |
10001 | kfree(dmabuf); | |
10002 | rc = -ENOMEM; | |
ce396282 | 10003 | goto release_out; |
52d52440 JS |
10004 | } |
10005 | list_add_tail(&dmabuf->list, &dma_buffer_list); | |
10006 | } | |
10007 | while (offset < fw->size) { | |
10008 | temp_offset = offset; | |
10009 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { | |
079b5c91 | 10010 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
52d52440 JS |
10011 | memcpy(dmabuf->virt, |
10012 | fw->data + temp_offset, | |
079b5c91 JS |
10013 | fw->size - temp_offset); |
10014 | temp_offset = fw->size; | |
52d52440 JS |
10015 | break; |
10016 | } | |
52d52440 JS |
10017 | memcpy(dmabuf->virt, fw->data + temp_offset, |
10018 | SLI4_PAGE_SIZE); | |
88a2cfbb | 10019 | temp_offset += SLI4_PAGE_SIZE; |
52d52440 JS |
10020 | } |
10021 | rc = lpfc_wr_object(phba, &dma_buffer_list, | |
10022 | (fw->size - offset), &offset); | |
ce396282 JS |
10023 | if (rc) |
10024 | goto release_out; | |
52d52440 JS |
10025 | } |
10026 | rc = offset; | |
10027 | } | |
ce396282 JS |
10028 | |
10029 | release_out: | |
52d52440 JS |
10030 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { |
10031 | list_del(&dmabuf->list); | |
10032 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, | |
10033 | dmabuf->virt, dmabuf->phys); | |
10034 | kfree(dmabuf); | |
10035 | } | |
ce396282 JS |
10036 | release_firmware(fw); |
10037 | out: | |
10038 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
c71ab861 | 10039 | "3024 Firmware update done: %d.\n", rc); |
ce396282 | 10040 | return; |
52d52440 JS |
10041 | } |
10042 | ||
c71ab861 JS |
10043 | /** |
10044 | * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade | |
10045 | * @phba: pointer to lpfc hba data structure. | |
10046 | * | |
10047 | * This routine is called to perform Linux generic firmware upgrade on device | |
10048 | * that supports such feature. | |
10049 | **/ | |
10050 | int | |
10051 | lpfc_sli4_request_firmware_update(struct lpfc_hba *phba, uint8_t fw_upgrade) | |
10052 | { | |
10053 | uint8_t file_name[ELX_MODEL_NAME_SIZE]; | |
10054 | int ret; | |
10055 | const struct firmware *fw; | |
10056 | ||
10057 | /* Only supported on SLI4 interface type 2 for now */ | |
10058 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
10059 | LPFC_SLI_INTF_IF_TYPE_2) | |
10060 | return -EPERM; | |
10061 | ||
10062 | snprintf(file_name, ELX_MODEL_NAME_SIZE, "%s.grp", phba->ModelName); | |
10063 | ||
10064 | if (fw_upgrade == INT_FW_UPGRADE) { | |
10065 | ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG, | |
10066 | file_name, &phba->pcidev->dev, | |
10067 | GFP_KERNEL, (void *)phba, | |
10068 | lpfc_write_firmware); | |
10069 | } else if (fw_upgrade == RUN_FW_UPGRADE) { | |
10070 | ret = request_firmware(&fw, file_name, &phba->pcidev->dev); | |
10071 | if (!ret) | |
10072 | lpfc_write_firmware(fw, (void *)phba); | |
10073 | } else { | |
10074 | ret = -EINVAL; | |
10075 | } | |
10076 | ||
10077 | return ret; | |
10078 | } | |
10079 | ||
3772a991 | 10080 | /** |
da0436e9 | 10081 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
3772a991 JS |
10082 | * @pdev: pointer to PCI device |
10083 | * @pid: pointer to PCI device identifier | |
10084 | * | |
da0436e9 JS |
10085 | * This routine is called from the kernel's PCI subsystem to device with |
10086 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 | 10087 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
da0436e9 JS |
10088 | * information of the device and driver to see if the driver state that it |
10089 | * can support this kind of device. If the match is successful, the driver | |
10090 | * core invokes this routine. If this routine determines it can claim the HBA, | |
10091 | * it does all the initialization that it needs to do to handle the HBA | |
10092 | * properly. | |
3772a991 JS |
10093 | * |
10094 | * Return code | |
10095 | * 0 - driver can claim the device | |
10096 | * negative value - driver can not claim the device | |
10097 | **/ | |
6f039790 | 10098 | static int |
da0436e9 | 10099 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
3772a991 JS |
10100 | { |
10101 | struct lpfc_hba *phba; | |
10102 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 10103 | struct Scsi_Host *shost = NULL; |
ce396282 | 10104 | int error, ret; |
3772a991 | 10105 | uint32_t cfg_mode, intr_mode; |
67d12733 | 10106 | int adjusted_fcp_io_channel; |
3772a991 JS |
10107 | |
10108 | /* Allocate memory for HBA structure */ | |
10109 | phba = lpfc_hba_alloc(pdev); | |
10110 | if (!phba) | |
10111 | return -ENOMEM; | |
10112 | ||
10113 | /* Perform generic PCI device enabling operation */ | |
10114 | error = lpfc_enable_pci_dev(phba); | |
079b5c91 | 10115 | if (error) |
3772a991 | 10116 | goto out_free_phba; |
3772a991 | 10117 | |
da0436e9 JS |
10118 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
10119 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); | |
3772a991 JS |
10120 | if (error) |
10121 | goto out_disable_pci_dev; | |
10122 | ||
da0436e9 JS |
10123 | /* Set up SLI-4 specific device PCI memory space */ |
10124 | error = lpfc_sli4_pci_mem_setup(phba); | |
3772a991 JS |
10125 | if (error) { |
10126 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 10127 | "1410 Failed to set up pci memory space.\n"); |
3772a991 JS |
10128 | goto out_disable_pci_dev; |
10129 | } | |
10130 | ||
10131 | /* Set up phase-1 common device driver resources */ | |
10132 | error = lpfc_setup_driver_resource_phase1(phba); | |
10133 | if (error) { | |
10134 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
10135 | "1411 Failed to set up driver resource.\n"); |
10136 | goto out_unset_pci_mem_s4; | |
3772a991 JS |
10137 | } |
10138 | ||
da0436e9 JS |
10139 | /* Set up SLI-4 Specific device driver resources */ |
10140 | error = lpfc_sli4_driver_resource_setup(phba); | |
3772a991 JS |
10141 | if (error) { |
10142 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
10143 | "1412 Failed to set up driver resource.\n"); |
10144 | goto out_unset_pci_mem_s4; | |
3772a991 JS |
10145 | } |
10146 | ||
10147 | /* Initialize and populate the iocb list per host */ | |
2a9bf3d0 JS |
10148 | |
10149 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
10150 | "2821 initialize iocb list %d.\n", | |
10151 | phba->cfg_iocb_cnt*1024); | |
10152 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); | |
10153 | ||
3772a991 JS |
10154 | if (error) { |
10155 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
10156 | "1413 Failed to initialize iocb list.\n"); |
10157 | goto out_unset_driver_resource_s4; | |
3772a991 JS |
10158 | } |
10159 | ||
19ca7609 | 10160 | INIT_LIST_HEAD(&phba->active_rrq_list); |
7d791df7 | 10161 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
19ca7609 | 10162 | |
3772a991 JS |
10163 | /* Set up common device driver resources */ |
10164 | error = lpfc_setup_driver_resource_phase2(phba); | |
10165 | if (error) { | |
10166 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 10167 | "1414 Failed to set up driver resource.\n"); |
3772a991 JS |
10168 | goto out_free_iocb_list; |
10169 | } | |
10170 | ||
079b5c91 JS |
10171 | /* Get the default values for Model Name and Description */ |
10172 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
10173 | ||
3772a991 JS |
10174 | /* Create SCSI host to the physical port */ |
10175 | error = lpfc_create_shost(phba); | |
10176 | if (error) { | |
10177 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 10178 | "1415 Failed to create scsi host.\n"); |
3772a991 JS |
10179 | goto out_unset_driver_resource; |
10180 | } | |
9399627f | 10181 | |
5b75da2f | 10182 | /* Configure sysfs attributes */ |
3772a991 JS |
10183 | vport = phba->pport; |
10184 | error = lpfc_alloc_sysfs_attr(vport); | |
10185 | if (error) { | |
9399627f | 10186 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 10187 | "1416 Failed to allocate sysfs attr\n"); |
3772a991 | 10188 | goto out_destroy_shost; |
98c9ea5c | 10189 | } |
875fbdfe | 10190 | |
6669f9bb | 10191 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
3772a991 | 10192 | /* Now, trying to enable interrupt and bring up the device */ |
5b75da2f | 10193 | cfg_mode = phba->cfg_use_msi; |
5b75da2f | 10194 | |
7b15db32 JS |
10195 | /* Put device to a known state before enabling interrupt */ |
10196 | lpfc_stop_port(phba); | |
10197 | /* Configure and enable interrupt */ | |
10198 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); | |
10199 | if (intr_mode == LPFC_INTR_ERROR) { | |
10200 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10201 | "0426 Failed to enable interrupt.\n"); | |
10202 | error = -ENODEV; | |
10203 | goto out_free_sysfs_attr; | |
10204 | } | |
10205 | /* Default to single EQ for non-MSI-X */ | |
10206 | if (phba->intr_type != MSIX) | |
10207 | adjusted_fcp_io_channel = 1; | |
10208 | else | |
10209 | adjusted_fcp_io_channel = phba->cfg_fcp_io_channel; | |
10210 | phba->cfg_fcp_io_channel = adjusted_fcp_io_channel; | |
10211 | /* Set up SLI-4 HBA */ | |
10212 | if (lpfc_sli4_hba_setup(phba)) { | |
10213 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10214 | "1421 Failed to set up hba\n"); | |
10215 | error = -ENODEV; | |
10216 | goto out_disable_intr; | |
98c9ea5c | 10217 | } |
858c9f6c | 10218 | |
7b15db32 JS |
10219 | /* Log the current active interrupt mode */ |
10220 | phba->intr_mode = intr_mode; | |
10221 | lpfc_log_intr_mode(phba, intr_mode); | |
10222 | ||
3772a991 JS |
10223 | /* Perform post initialization setup */ |
10224 | lpfc_post_init_setup(phba); | |
dea3101e | 10225 | |
c71ab861 JS |
10226 | /* check for firmware upgrade or downgrade */ |
10227 | if (phba->cfg_request_firmware_upgrade) | |
10228 | ret = lpfc_sli4_request_firmware_update(phba, INT_FW_UPGRADE); | |
52d52440 | 10229 | |
1c6834a7 JS |
10230 | /* Check if there are static vports to be created. */ |
10231 | lpfc_create_static_vport(phba); | |
dea3101e JB |
10232 | return 0; |
10233 | ||
da0436e9 JS |
10234 | out_disable_intr: |
10235 | lpfc_sli4_disable_intr(phba); | |
5b75da2f JS |
10236 | out_free_sysfs_attr: |
10237 | lpfc_free_sysfs_attr(vport); | |
3772a991 JS |
10238 | out_destroy_shost: |
10239 | lpfc_destroy_shost(phba); | |
10240 | out_unset_driver_resource: | |
10241 | lpfc_unset_driver_resource_phase2(phba); | |
10242 | out_free_iocb_list: | |
10243 | lpfc_free_iocb_list(phba); | |
da0436e9 JS |
10244 | out_unset_driver_resource_s4: |
10245 | lpfc_sli4_driver_resource_unset(phba); | |
10246 | out_unset_pci_mem_s4: | |
10247 | lpfc_sli4_pci_mem_unset(phba); | |
3772a991 JS |
10248 | out_disable_pci_dev: |
10249 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
10250 | if (shost) |
10251 | scsi_host_put(shost); | |
2e0fef85 | 10252 | out_free_phba: |
3772a991 | 10253 | lpfc_hba_free(phba); |
dea3101e JB |
10254 | return error; |
10255 | } | |
10256 | ||
e59058c4 | 10257 | /** |
da0436e9 | 10258 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
e59058c4 JS |
10259 | * @pdev: pointer to PCI device |
10260 | * | |
da0436e9 JS |
10261 | * This routine is called from the kernel's PCI subsystem to device with |
10262 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 JS |
10263 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
10264 | * device to be removed from the PCI subsystem properly. | |
e59058c4 | 10265 | **/ |
6f039790 | 10266 | static void |
da0436e9 | 10267 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
dea3101e | 10268 | { |
da0436e9 | 10269 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2e0fef85 | 10270 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
eada272d | 10271 | struct lpfc_vport **vports; |
da0436e9 | 10272 | struct lpfc_hba *phba = vport->phba; |
eada272d | 10273 | int i; |
8a4df120 | 10274 | |
da0436e9 | 10275 | /* Mark the device unloading flag */ |
549e55cd | 10276 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 10277 | vport->load_flag |= FC_UNLOADING; |
549e55cd | 10278 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 10279 | |
da0436e9 | 10280 | /* Free the HBA sysfs attributes */ |
858c9f6c JS |
10281 | lpfc_free_sysfs_attr(vport); |
10282 | ||
eada272d JS |
10283 | /* Release all the vports against this physical port */ |
10284 | vports = lpfc_create_vport_work_array(phba); | |
10285 | if (vports != NULL) | |
587a37f6 JS |
10286 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
10287 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) | |
10288 | continue; | |
eada272d | 10289 | fc_vport_terminate(vports[i]->fc_vport); |
587a37f6 | 10290 | } |
eada272d JS |
10291 | lpfc_destroy_vport_work_array(phba, vports); |
10292 | ||
10293 | /* Remove FC host and then SCSI host with the physical port */ | |
858c9f6c JS |
10294 | fc_remove_host(shost); |
10295 | scsi_remove_host(shost); | |
da0436e9 JS |
10296 | |
10297 | /* Perform cleanup on the physical port */ | |
87af33fe JS |
10298 | lpfc_cleanup(vport); |
10299 | ||
2e0fef85 | 10300 | /* |
da0436e9 | 10301 | * Bring down the SLI Layer. This step disables all interrupts, |
2e0fef85 | 10302 | * clears the rings, discards all mailbox commands, and resets |
da0436e9 | 10303 | * the HBA FCoE function. |
2e0fef85 | 10304 | */ |
da0436e9 JS |
10305 | lpfc_debugfs_terminate(vport); |
10306 | lpfc_sli4_hba_unset(phba); | |
a257bf90 | 10307 | |
858c9f6c JS |
10308 | spin_lock_irq(&phba->hbalock); |
10309 | list_del_init(&vport->listentry); | |
10310 | spin_unlock_irq(&phba->hbalock); | |
10311 | ||
3677a3a7 | 10312 | /* Perform scsi free before driver resource_unset since scsi |
da0436e9 | 10313 | * buffers are released to their corresponding pools here. |
2e0fef85 JS |
10314 | */ |
10315 | lpfc_scsi_free(phba); | |
67d12733 | 10316 | |
da0436e9 | 10317 | lpfc_sli4_driver_resource_unset(phba); |
ed957684 | 10318 | |
da0436e9 JS |
10319 | /* Unmap adapter Control and Doorbell registers */ |
10320 | lpfc_sli4_pci_mem_unset(phba); | |
2e0fef85 | 10321 | |
da0436e9 JS |
10322 | /* Release PCI resources and disable device's PCI function */ |
10323 | scsi_host_put(shost); | |
10324 | lpfc_disable_pci_dev(phba); | |
2e0fef85 | 10325 | |
da0436e9 | 10326 | /* Finally, free the driver's device data structure */ |
3772a991 | 10327 | lpfc_hba_free(phba); |
2e0fef85 | 10328 | |
da0436e9 | 10329 | return; |
dea3101e JB |
10330 | } |
10331 | ||
3a55b532 | 10332 | /** |
da0436e9 | 10333 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
3a55b532 JS |
10334 | * @pdev: pointer to PCI device |
10335 | * @msg: power management message | |
10336 | * | |
da0436e9 JS |
10337 | * This routine is called from the kernel's PCI subsystem to support system |
10338 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes | |
10339 | * this method, it quiesces the device by stopping the driver's worker | |
10340 | * thread for the device, turning off device's interrupt and DMA, and bring | |
10341 | * the device offline. Note that as the driver implements the minimum PM | |
10342 | * requirements to a power-aware driver's PM support for suspend/resume -- all | |
10343 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() | |
10344 | * method call will be treated as SUSPEND and the driver will fully | |
10345 | * reinitialize its device during resume() method call, the driver will set | |
10346 | * device to PCI_D3hot state in PCI config space instead of setting it | |
3772a991 | 10347 | * according to the @msg provided by the PM. |
3a55b532 JS |
10348 | * |
10349 | * Return code | |
3772a991 JS |
10350 | * 0 - driver suspended the device |
10351 | * Error otherwise | |
3a55b532 JS |
10352 | **/ |
10353 | static int | |
da0436e9 | 10354 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
3a55b532 JS |
10355 | { |
10356 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10357 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10358 | ||
10359 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
75baf696 | 10360 | "2843 PCI device Power Management suspend.\n"); |
3a55b532 JS |
10361 | |
10362 | /* Bring down the device */ | |
618a5230 | 10363 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
3a55b532 JS |
10364 | lpfc_offline(phba); |
10365 | kthread_stop(phba->worker_thread); | |
10366 | ||
10367 | /* Disable interrupt from device */ | |
da0436e9 | 10368 | lpfc_sli4_disable_intr(phba); |
5350d872 | 10369 | lpfc_sli4_queue_destroy(phba); |
3a55b532 JS |
10370 | |
10371 | /* Save device state to PCI config space */ | |
10372 | pci_save_state(pdev); | |
10373 | pci_set_power_state(pdev, PCI_D3hot); | |
10374 | ||
10375 | return 0; | |
10376 | } | |
10377 | ||
10378 | /** | |
da0436e9 | 10379 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
3a55b532 JS |
10380 | * @pdev: pointer to PCI device |
10381 | * | |
da0436e9 JS |
10382 | * This routine is called from the kernel's PCI subsystem to support system |
10383 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes | |
10384 | * this method, it restores the device's PCI config space state and fully | |
10385 | * reinitializes the device and brings it online. Note that as the driver | |
10386 | * implements the minimum PM requirements to a power-aware driver's PM for | |
10387 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
10388 | * to the suspend() method call will be treated as SUSPEND and the driver | |
10389 | * will fully reinitialize its device during resume() method call, the device | |
10390 | * will be set to PCI_D0 directly in PCI config space before restoring the | |
10391 | * state. | |
3a55b532 JS |
10392 | * |
10393 | * Return code | |
3772a991 JS |
10394 | * 0 - driver suspended the device |
10395 | * Error otherwise | |
3a55b532 JS |
10396 | **/ |
10397 | static int | |
da0436e9 | 10398 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
3a55b532 JS |
10399 | { |
10400 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10401 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
5b75da2f | 10402 | uint32_t intr_mode; |
3a55b532 JS |
10403 | int error; |
10404 | ||
10405 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
da0436e9 | 10406 | "0292 PCI device Power Management resume.\n"); |
3a55b532 JS |
10407 | |
10408 | /* Restore device state from PCI config space */ | |
10409 | pci_set_power_state(pdev, PCI_D0); | |
10410 | pci_restore_state(pdev); | |
1dfb5a47 JS |
10411 | |
10412 | /* | |
10413 | * As the new kernel behavior of pci_restore_state() API call clears | |
10414 | * device saved_state flag, need to save the restored state again. | |
10415 | */ | |
10416 | pci_save_state(pdev); | |
10417 | ||
3a55b532 JS |
10418 | if (pdev->is_busmaster) |
10419 | pci_set_master(pdev); | |
10420 | ||
da0436e9 | 10421 | /* Startup the kernel thread for this host adapter. */ |
3a55b532 JS |
10422 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
10423 | "lpfc_worker_%d", phba->brd_no); | |
10424 | if (IS_ERR(phba->worker_thread)) { | |
10425 | error = PTR_ERR(phba->worker_thread); | |
10426 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 10427 | "0293 PM resume failed to start worker " |
3a55b532 JS |
10428 | "thread: error=x%x.\n", error); |
10429 | return error; | |
10430 | } | |
10431 | ||
5b75da2f | 10432 | /* Configure and enable interrupt */ |
da0436e9 | 10433 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
5b75da2f | 10434 | if (intr_mode == LPFC_INTR_ERROR) { |
3a55b532 | 10435 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 10436 | "0294 PM resume Failed to enable interrupt\n"); |
5b75da2f JS |
10437 | return -EIO; |
10438 | } else | |
10439 | phba->intr_mode = intr_mode; | |
3a55b532 JS |
10440 | |
10441 | /* Restart HBA and bring it online */ | |
10442 | lpfc_sli_brdrestart(phba); | |
10443 | lpfc_online(phba); | |
10444 | ||
5b75da2f JS |
10445 | /* Log the current active interrupt mode */ |
10446 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
10447 | ||
3a55b532 JS |
10448 | return 0; |
10449 | } | |
10450 | ||
75baf696 JS |
10451 | /** |
10452 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover | |
10453 | * @phba: pointer to lpfc hba data structure. | |
10454 | * | |
10455 | * This routine is called to prepare the SLI4 device for PCI slot recover. It | |
10456 | * aborts all the outstanding SCSI I/Os to the pci device. | |
10457 | **/ | |
10458 | static void | |
10459 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) | |
10460 | { | |
10461 | struct lpfc_sli *psli = &phba->sli; | |
10462 | struct lpfc_sli_ring *pring; | |
10463 | ||
10464 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10465 | "2828 PCI channel I/O abort preparing for recovery\n"); | |
10466 | /* | |
10467 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
10468 | * and let the SCSI mid-layer to retry them to recover. | |
10469 | */ | |
10470 | pring = &psli->ring[psli->fcp_ring]; | |
10471 | lpfc_sli_abort_iocb_ring(phba, pring); | |
10472 | } | |
10473 | ||
10474 | /** | |
10475 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset | |
10476 | * @phba: pointer to lpfc hba data structure. | |
10477 | * | |
10478 | * This routine is called to prepare the SLI4 device for PCI slot reset. It | |
10479 | * disables the device interrupt and pci device, and aborts the internal FCP | |
10480 | * pending I/Os. | |
10481 | **/ | |
10482 | static void | |
10483 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) | |
10484 | { | |
10485 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10486 | "2826 PCI channel disable preparing for reset\n"); | |
10487 | ||
10488 | /* Block any management I/Os to the device */ | |
618a5230 | 10489 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
75baf696 JS |
10490 | |
10491 | /* Block all SCSI devices' I/Os on the host */ | |
10492 | lpfc_scsi_dev_block(phba); | |
10493 | ||
ea714f3d JS |
10494 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
10495 | lpfc_sli_flush_fcp_rings(phba); | |
10496 | ||
75baf696 JS |
10497 | /* stop all timers */ |
10498 | lpfc_stop_hba_timers(phba); | |
10499 | ||
10500 | /* Disable interrupt and pci device */ | |
10501 | lpfc_sli4_disable_intr(phba); | |
5350d872 | 10502 | lpfc_sli4_queue_destroy(phba); |
75baf696 | 10503 | pci_disable_device(phba->pcidev); |
75baf696 JS |
10504 | } |
10505 | ||
10506 | /** | |
10507 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable | |
10508 | * @phba: pointer to lpfc hba data structure. | |
10509 | * | |
10510 | * This routine is called to prepare the SLI4 device for PCI slot permanently | |
10511 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
10512 | * pending I/Os. | |
10513 | **/ | |
10514 | static void | |
10515 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) | |
10516 | { | |
10517 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10518 | "2827 PCI channel permanent disable for failure\n"); | |
10519 | ||
10520 | /* Block all SCSI devices' I/Os on the host */ | |
10521 | lpfc_scsi_dev_block(phba); | |
10522 | ||
10523 | /* stop all timers */ | |
10524 | lpfc_stop_hba_timers(phba); | |
10525 | ||
10526 | /* Clean up all driver's outstanding SCSI I/Os */ | |
10527 | lpfc_sli_flush_fcp_rings(phba); | |
10528 | } | |
10529 | ||
8d63f375 | 10530 | /** |
da0436e9 | 10531 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
e59058c4 JS |
10532 | * @pdev: pointer to PCI device. |
10533 | * @state: the current PCI connection state. | |
8d63f375 | 10534 | * |
da0436e9 JS |
10535 | * This routine is called from the PCI subsystem for error handling to device |
10536 | * with SLI-4 interface spec. This function is called by the PCI subsystem | |
10537 | * after a PCI bus error affecting this device has been detected. When this | |
10538 | * function is invoked, it will need to stop all the I/Os and interrupt(s) | |
10539 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET | |
10540 | * for the PCI subsystem to perform proper recovery as desired. | |
e59058c4 JS |
10541 | * |
10542 | * Return codes | |
3772a991 JS |
10543 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
10544 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
e59058c4 | 10545 | **/ |
3772a991 | 10546 | static pci_ers_result_t |
da0436e9 | 10547 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
8d63f375 | 10548 | { |
75baf696 JS |
10549 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
10550 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10551 | ||
10552 | switch (state) { | |
10553 | case pci_channel_io_normal: | |
10554 | /* Non-fatal error, prepare for recovery */ | |
10555 | lpfc_sli4_prep_dev_for_recover(phba); | |
10556 | return PCI_ERS_RESULT_CAN_RECOVER; | |
10557 | case pci_channel_io_frozen: | |
10558 | /* Fatal error, prepare for slot reset */ | |
10559 | lpfc_sli4_prep_dev_for_reset(phba); | |
10560 | return PCI_ERS_RESULT_NEED_RESET; | |
10561 | case pci_channel_io_perm_failure: | |
10562 | /* Permanent failure, prepare for device down */ | |
10563 | lpfc_sli4_prep_dev_for_perm_failure(phba); | |
10564 | return PCI_ERS_RESULT_DISCONNECT; | |
10565 | default: | |
10566 | /* Unknown state, prepare and request slot reset */ | |
10567 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10568 | "2825 Unknown PCI error state: x%x\n", state); | |
10569 | lpfc_sli4_prep_dev_for_reset(phba); | |
10570 | return PCI_ERS_RESULT_NEED_RESET; | |
10571 | } | |
8d63f375 LV |
10572 | } |
10573 | ||
10574 | /** | |
da0436e9 | 10575 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
e59058c4 JS |
10576 | * @pdev: pointer to PCI device. |
10577 | * | |
da0436e9 JS |
10578 | * This routine is called from the PCI subsystem for error handling to device |
10579 | * with SLI-4 interface spec. It is called after PCI bus has been reset to | |
10580 | * restart the PCI card from scratch, as if from a cold-boot. During the | |
10581 | * PCI subsystem error recovery, after the driver returns | |
3772a991 | 10582 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
da0436e9 JS |
10583 | * recovery and then call this routine before calling the .resume method to |
10584 | * recover the device. This function will initialize the HBA device, enable | |
10585 | * the interrupt, but it will just put the HBA to offline state without | |
10586 | * passing any I/O traffic. | |
8d63f375 | 10587 | * |
e59058c4 | 10588 | * Return codes |
3772a991 JS |
10589 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
10590 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8d63f375 | 10591 | */ |
3772a991 | 10592 | static pci_ers_result_t |
da0436e9 | 10593 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
8d63f375 | 10594 | { |
75baf696 JS |
10595 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
10596 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10597 | struct lpfc_sli *psli = &phba->sli; | |
10598 | uint32_t intr_mode; | |
10599 | ||
10600 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
10601 | if (pci_enable_device_mem(pdev)) { | |
10602 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
10603 | "PCI device after reset.\n"); | |
10604 | return PCI_ERS_RESULT_DISCONNECT; | |
10605 | } | |
10606 | ||
10607 | pci_restore_state(pdev); | |
0a96e975 JS |
10608 | |
10609 | /* | |
10610 | * As the new kernel behavior of pci_restore_state() API call clears | |
10611 | * device saved_state flag, need to save the restored state again. | |
10612 | */ | |
10613 | pci_save_state(pdev); | |
10614 | ||
75baf696 JS |
10615 | if (pdev->is_busmaster) |
10616 | pci_set_master(pdev); | |
10617 | ||
10618 | spin_lock_irq(&phba->hbalock); | |
10619 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
10620 | spin_unlock_irq(&phba->hbalock); | |
10621 | ||
10622 | /* Configure and enable interrupt */ | |
10623 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); | |
10624 | if (intr_mode == LPFC_INTR_ERROR) { | |
10625 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10626 | "2824 Cannot re-enable interrupt after " | |
10627 | "slot reset.\n"); | |
10628 | return PCI_ERS_RESULT_DISCONNECT; | |
10629 | } else | |
10630 | phba->intr_mode = intr_mode; | |
10631 | ||
10632 | /* Log the current active interrupt mode */ | |
10633 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
10634 | ||
8d63f375 LV |
10635 | return PCI_ERS_RESULT_RECOVERED; |
10636 | } | |
10637 | ||
10638 | /** | |
da0436e9 | 10639 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
e59058c4 | 10640 | * @pdev: pointer to PCI device |
8d63f375 | 10641 | * |
3772a991 | 10642 | * This routine is called from the PCI subsystem for error handling to device |
da0436e9 | 10643 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
3772a991 JS |
10644 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
10645 | * error recovery. After this call, traffic can start to flow from this device | |
10646 | * again. | |
da0436e9 | 10647 | **/ |
3772a991 | 10648 | static void |
da0436e9 | 10649 | lpfc_io_resume_s4(struct pci_dev *pdev) |
8d63f375 | 10650 | { |
75baf696 JS |
10651 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
10652 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10653 | ||
10654 | /* | |
10655 | * In case of slot reset, as function reset is performed through | |
10656 | * mailbox command which needs DMA to be enabled, this operation | |
10657 | * has to be moved to the io resume phase. Taking device offline | |
10658 | * will perform the necessary cleanup. | |
10659 | */ | |
10660 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { | |
10661 | /* Perform device reset */ | |
618a5230 | 10662 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
75baf696 JS |
10663 | lpfc_offline(phba); |
10664 | lpfc_sli_brdrestart(phba); | |
10665 | /* Bring the device back online */ | |
10666 | lpfc_online(phba); | |
10667 | } | |
10668 | ||
10669 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
10670 | if (phba->hba_flag & HBA_AER_ENABLED) | |
10671 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
8d63f375 LV |
10672 | } |
10673 | ||
3772a991 JS |
10674 | /** |
10675 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem | |
10676 | * @pdev: pointer to PCI device | |
10677 | * @pid: pointer to PCI device identifier | |
10678 | * | |
10679 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
10680 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks | |
10681 | * at PCI device-specific information of the device and driver to see if the | |
10682 | * driver state that it can support this kind of device. If the match is | |
10683 | * successful, the driver core invokes this routine. This routine dispatches | |
10684 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will | |
10685 | * do all the initialization that it needs to do to handle the HBA device | |
10686 | * properly. | |
10687 | * | |
10688 | * Return code | |
10689 | * 0 - driver can claim the device | |
10690 | * negative value - driver can not claim the device | |
10691 | **/ | |
6f039790 | 10692 | static int |
3772a991 JS |
10693 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) |
10694 | { | |
10695 | int rc; | |
8fa38513 | 10696 | struct lpfc_sli_intf intf; |
3772a991 | 10697 | |
28baac74 | 10698 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
3772a991 JS |
10699 | return -ENODEV; |
10700 | ||
8fa38513 | 10701 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
28baac74 | 10702 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
da0436e9 | 10703 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
8fa38513 | 10704 | else |
3772a991 | 10705 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
8fa38513 | 10706 | |
3772a991 JS |
10707 | return rc; |
10708 | } | |
10709 | ||
10710 | /** | |
10711 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem | |
10712 | * @pdev: pointer to PCI device | |
10713 | * | |
10714 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
10715 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. | |
10716 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device | |
10717 | * remove routine, which will perform all the necessary cleanup for the | |
10718 | * device to be removed from the PCI subsystem properly. | |
10719 | **/ | |
6f039790 | 10720 | static void |
3772a991 JS |
10721 | lpfc_pci_remove_one(struct pci_dev *pdev) |
10722 | { | |
10723 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10724 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10725 | ||
10726 | switch (phba->pci_dev_grp) { | |
10727 | case LPFC_PCI_DEV_LP: | |
10728 | lpfc_pci_remove_one_s3(pdev); | |
10729 | break; | |
da0436e9 JS |
10730 | case LPFC_PCI_DEV_OC: |
10731 | lpfc_pci_remove_one_s4(pdev); | |
10732 | break; | |
3772a991 JS |
10733 | default: |
10734 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10735 | "1424 Invalid PCI device group: 0x%x\n", | |
10736 | phba->pci_dev_grp); | |
10737 | break; | |
10738 | } | |
10739 | return; | |
10740 | } | |
10741 | ||
10742 | /** | |
10743 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management | |
10744 | * @pdev: pointer to PCI device | |
10745 | * @msg: power management message | |
10746 | * | |
10747 | * This routine is to be registered to the kernel's PCI subsystem to support | |
10748 | * system Power Management (PM). When PM invokes this method, it dispatches | |
10749 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will | |
10750 | * suspend the device. | |
10751 | * | |
10752 | * Return code | |
10753 | * 0 - driver suspended the device | |
10754 | * Error otherwise | |
10755 | **/ | |
10756 | static int | |
10757 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | |
10758 | { | |
10759 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10760 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10761 | int rc = -ENODEV; | |
10762 | ||
10763 | switch (phba->pci_dev_grp) { | |
10764 | case LPFC_PCI_DEV_LP: | |
10765 | rc = lpfc_pci_suspend_one_s3(pdev, msg); | |
10766 | break; | |
da0436e9 JS |
10767 | case LPFC_PCI_DEV_OC: |
10768 | rc = lpfc_pci_suspend_one_s4(pdev, msg); | |
10769 | break; | |
3772a991 JS |
10770 | default: |
10771 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10772 | "1425 Invalid PCI device group: 0x%x\n", | |
10773 | phba->pci_dev_grp); | |
10774 | break; | |
10775 | } | |
10776 | return rc; | |
10777 | } | |
10778 | ||
10779 | /** | |
10780 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management | |
10781 | * @pdev: pointer to PCI device | |
10782 | * | |
10783 | * This routine is to be registered to the kernel's PCI subsystem to support | |
10784 | * system Power Management (PM). When PM invokes this method, it dispatches | |
10785 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will | |
10786 | * resume the device. | |
10787 | * | |
10788 | * Return code | |
10789 | * 0 - driver suspended the device | |
10790 | * Error otherwise | |
10791 | **/ | |
10792 | static int | |
10793 | lpfc_pci_resume_one(struct pci_dev *pdev) | |
10794 | { | |
10795 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10796 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10797 | int rc = -ENODEV; | |
10798 | ||
10799 | switch (phba->pci_dev_grp) { | |
10800 | case LPFC_PCI_DEV_LP: | |
10801 | rc = lpfc_pci_resume_one_s3(pdev); | |
10802 | break; | |
da0436e9 JS |
10803 | case LPFC_PCI_DEV_OC: |
10804 | rc = lpfc_pci_resume_one_s4(pdev); | |
10805 | break; | |
3772a991 JS |
10806 | default: |
10807 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10808 | "1426 Invalid PCI device group: 0x%x\n", | |
10809 | phba->pci_dev_grp); | |
10810 | break; | |
10811 | } | |
10812 | return rc; | |
10813 | } | |
10814 | ||
10815 | /** | |
10816 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error | |
10817 | * @pdev: pointer to PCI device. | |
10818 | * @state: the current PCI connection state. | |
10819 | * | |
10820 | * This routine is registered to the PCI subsystem for error handling. This | |
10821 | * function is called by the PCI subsystem after a PCI bus error affecting | |
10822 | * this device has been detected. When this routine is invoked, it dispatches | |
10823 | * the action to the proper SLI-3 or SLI-4 device error detected handling | |
10824 | * routine, which will perform the proper error detected operation. | |
10825 | * | |
10826 | * Return codes | |
10827 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery | |
10828 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
10829 | **/ | |
10830 | static pci_ers_result_t | |
10831 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | |
10832 | { | |
10833 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10834 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10835 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
10836 | ||
10837 | switch (phba->pci_dev_grp) { | |
10838 | case LPFC_PCI_DEV_LP: | |
10839 | rc = lpfc_io_error_detected_s3(pdev, state); | |
10840 | break; | |
da0436e9 JS |
10841 | case LPFC_PCI_DEV_OC: |
10842 | rc = lpfc_io_error_detected_s4(pdev, state); | |
10843 | break; | |
3772a991 JS |
10844 | default: |
10845 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10846 | "1427 Invalid PCI device group: 0x%x\n", | |
10847 | phba->pci_dev_grp); | |
10848 | break; | |
10849 | } | |
10850 | return rc; | |
10851 | } | |
10852 | ||
10853 | /** | |
10854 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch | |
10855 | * @pdev: pointer to PCI device. | |
10856 | * | |
10857 | * This routine is registered to the PCI subsystem for error handling. This | |
10858 | * function is called after PCI bus has been reset to restart the PCI card | |
10859 | * from scratch, as if from a cold-boot. When this routine is invoked, it | |
10860 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling | |
10861 | * routine, which will perform the proper device reset. | |
10862 | * | |
10863 | * Return codes | |
10864 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
10865 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
10866 | **/ | |
10867 | static pci_ers_result_t | |
10868 | lpfc_io_slot_reset(struct pci_dev *pdev) | |
10869 | { | |
10870 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10871 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10872 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
10873 | ||
10874 | switch (phba->pci_dev_grp) { | |
10875 | case LPFC_PCI_DEV_LP: | |
10876 | rc = lpfc_io_slot_reset_s3(pdev); | |
10877 | break; | |
da0436e9 JS |
10878 | case LPFC_PCI_DEV_OC: |
10879 | rc = lpfc_io_slot_reset_s4(pdev); | |
10880 | break; | |
3772a991 JS |
10881 | default: |
10882 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10883 | "1428 Invalid PCI device group: 0x%x\n", | |
10884 | phba->pci_dev_grp); | |
10885 | break; | |
10886 | } | |
10887 | return rc; | |
10888 | } | |
10889 | ||
10890 | /** | |
10891 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation | |
10892 | * @pdev: pointer to PCI device | |
10893 | * | |
10894 | * This routine is registered to the PCI subsystem for error handling. It | |
10895 | * is called when kernel error recovery tells the lpfc driver that it is | |
10896 | * OK to resume normal PCI operation after PCI bus error recovery. When | |
10897 | * this routine is invoked, it dispatches the action to the proper SLI-3 | |
10898 | * or SLI-4 device io_resume routine, which will resume the device operation. | |
10899 | **/ | |
10900 | static void | |
10901 | lpfc_io_resume(struct pci_dev *pdev) | |
10902 | { | |
10903 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10904 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10905 | ||
10906 | switch (phba->pci_dev_grp) { | |
10907 | case LPFC_PCI_DEV_LP: | |
10908 | lpfc_io_resume_s3(pdev); | |
10909 | break; | |
da0436e9 JS |
10910 | case LPFC_PCI_DEV_OC: |
10911 | lpfc_io_resume_s4(pdev); | |
10912 | break; | |
3772a991 JS |
10913 | default: |
10914 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10915 | "1429 Invalid PCI device group: 0x%x\n", | |
10916 | phba->pci_dev_grp); | |
10917 | break; | |
10918 | } | |
10919 | return; | |
10920 | } | |
10921 | ||
1ba981fd JS |
10922 | /** |
10923 | * lpfc_sli4_oas_verify - Verify OAS is supported by this adapter | |
10924 | * @phba: pointer to lpfc hba data structure. | |
10925 | * | |
10926 | * This routine checks to see if OAS is supported for this adapter. If | |
10927 | * supported, the configure Flash Optimized Fabric flag is set. Otherwise, | |
10928 | * the enable oas flag is cleared and the pool created for OAS device data | |
10929 | * is destroyed. | |
10930 | * | |
10931 | **/ | |
10932 | void | |
10933 | lpfc_sli4_oas_verify(struct lpfc_hba *phba) | |
10934 | { | |
10935 | ||
10936 | if (!phba->cfg_EnableXLane) | |
10937 | return; | |
10938 | ||
10939 | if (phba->sli4_hba.pc_sli4_params.oas_supported) { | |
10940 | phba->cfg_fof = 1; | |
10941 | } else { | |
10942 | phba->cfg_EnableXLane = 0; | |
10943 | if (phba->device_data_mem_pool) | |
10944 | mempool_destroy(phba->device_data_mem_pool); | |
10945 | phba->device_data_mem_pool = NULL; | |
10946 | } | |
10947 | ||
10948 | return; | |
10949 | } | |
10950 | ||
10951 | /** | |
10952 | * lpfc_fof_queue_setup - Set up all the fof queues | |
10953 | * @phba: pointer to lpfc hba data structure. | |
10954 | * | |
10955 | * This routine is invoked to set up all the fof queues for the FC HBA | |
10956 | * operation. | |
10957 | * | |
10958 | * Return codes | |
10959 | * 0 - successful | |
10960 | * -ENOMEM - No available memory | |
10961 | **/ | |
10962 | int | |
10963 | lpfc_fof_queue_setup(struct lpfc_hba *phba) | |
10964 | { | |
10965 | struct lpfc_sli *psli = &phba->sli; | |
10966 | int rc; | |
10967 | ||
10968 | rc = lpfc_eq_create(phba, phba->sli4_hba.fof_eq, LPFC_MAX_IMAX); | |
10969 | if (rc) | |
10970 | return -ENOMEM; | |
10971 | ||
10972 | if (phba->cfg_EnableXLane) { | |
10973 | ||
10974 | rc = lpfc_cq_create(phba, phba->sli4_hba.oas_cq, | |
10975 | phba->sli4_hba.fof_eq, LPFC_WCQ, LPFC_FCP); | |
10976 | if (rc) | |
10977 | goto out_oas_cq; | |
10978 | ||
10979 | rc = lpfc_wq_create(phba, phba->sli4_hba.oas_wq, | |
10980 | phba->sli4_hba.oas_cq, LPFC_FCP); | |
10981 | if (rc) | |
10982 | goto out_oas_wq; | |
10983 | ||
10984 | phba->sli4_hba.oas_cq->pring = &psli->ring[LPFC_FCP_OAS_RING]; | |
10985 | phba->sli4_hba.oas_ring = &psli->ring[LPFC_FCP_OAS_RING]; | |
10986 | } | |
10987 | ||
10988 | return 0; | |
10989 | ||
10990 | out_oas_wq: | |
10991 | if (phba->cfg_EnableXLane) | |
10992 | lpfc_cq_destroy(phba, phba->sli4_hba.oas_cq); | |
10993 | out_oas_cq: | |
10994 | lpfc_eq_destroy(phba, phba->sli4_hba.fof_eq); | |
10995 | return rc; | |
10996 | ||
10997 | } | |
10998 | ||
10999 | /** | |
11000 | * lpfc_fof_queue_create - Create all the fof queues | |
11001 | * @phba: pointer to lpfc hba data structure. | |
11002 | * | |
11003 | * This routine is invoked to allocate all the fof queues for the FC HBA | |
11004 | * operation. For each SLI4 queue type, the parameters such as queue entry | |
11005 | * count (queue depth) shall be taken from the module parameter. For now, | |
11006 | * we just use some constant number as place holder. | |
11007 | * | |
11008 | * Return codes | |
11009 | * 0 - successful | |
11010 | * -ENOMEM - No availble memory | |
11011 | * -EIO - The mailbox failed to complete successfully. | |
11012 | **/ | |
11013 | int | |
11014 | lpfc_fof_queue_create(struct lpfc_hba *phba) | |
11015 | { | |
11016 | struct lpfc_queue *qdesc; | |
11017 | ||
11018 | /* Create FOF EQ */ | |
11019 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | |
11020 | phba->sli4_hba.eq_ecount); | |
11021 | if (!qdesc) | |
11022 | goto out_error; | |
11023 | ||
11024 | phba->sli4_hba.fof_eq = qdesc; | |
11025 | ||
11026 | if (phba->cfg_EnableXLane) { | |
11027 | ||
11028 | /* Create OAS CQ */ | |
11029 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
11030 | phba->sli4_hba.cq_ecount); | |
11031 | if (!qdesc) | |
11032 | goto out_error; | |
11033 | ||
11034 | phba->sli4_hba.oas_cq = qdesc; | |
11035 | ||
11036 | /* Create OAS WQ */ | |
11037 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
11038 | phba->sli4_hba.wq_ecount); | |
11039 | if (!qdesc) | |
11040 | goto out_error; | |
11041 | ||
11042 | phba->sli4_hba.oas_wq = qdesc; | |
11043 | ||
11044 | } | |
11045 | return 0; | |
11046 | ||
11047 | out_error: | |
11048 | lpfc_fof_queue_destroy(phba); | |
11049 | return -ENOMEM; | |
11050 | } | |
11051 | ||
11052 | /** | |
11053 | * lpfc_fof_queue_destroy - Destroy all the fof queues | |
11054 | * @phba: pointer to lpfc hba data structure. | |
11055 | * | |
11056 | * This routine is invoked to release all the SLI4 queues with the FC HBA | |
11057 | * operation. | |
11058 | * | |
11059 | * Return codes | |
11060 | * 0 - successful | |
11061 | **/ | |
11062 | int | |
11063 | lpfc_fof_queue_destroy(struct lpfc_hba *phba) | |
11064 | { | |
11065 | /* Release FOF Event queue */ | |
11066 | if (phba->sli4_hba.fof_eq != NULL) { | |
11067 | lpfc_sli4_queue_free(phba->sli4_hba.fof_eq); | |
11068 | phba->sli4_hba.fof_eq = NULL; | |
11069 | } | |
11070 | ||
11071 | /* Release OAS Completion queue */ | |
11072 | if (phba->sli4_hba.oas_cq != NULL) { | |
11073 | lpfc_sli4_queue_free(phba->sli4_hba.oas_cq); | |
11074 | phba->sli4_hba.oas_cq = NULL; | |
11075 | } | |
11076 | ||
11077 | /* Release OAS Work queue */ | |
11078 | if (phba->sli4_hba.oas_wq != NULL) { | |
11079 | lpfc_sli4_queue_free(phba->sli4_hba.oas_wq); | |
11080 | phba->sli4_hba.oas_wq = NULL; | |
11081 | } | |
11082 | return 0; | |
11083 | } | |
11084 | ||
dea3101e JB |
11085 | static struct pci_device_id lpfc_id_table[] = { |
11086 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, | |
11087 | PCI_ANY_ID, PCI_ANY_ID, }, | |
06325e74 JSEC |
11088 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
11089 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
11090 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
11091 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11092 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, | |
11093 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11094 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, | |
11095 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11096 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, | |
11097 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11098 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, | |
11099 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11100 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, | |
11101 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11102 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, | |
11103 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
11104 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
11105 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11106 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, | |
11107 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11108 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, | |
11109 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
11110 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
11111 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
11112 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
11113 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11114 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, | |
11115 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
11116 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
11117 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11118 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, | |
11119 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11120 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, | |
11121 | PCI_ANY_ID, PCI_ANY_ID, }, | |
84774a4d JS |
11122 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
11123 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
11124 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
11125 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11126 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, | |
11127 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
11128 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
11129 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11130 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, | |
11131 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11132 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, | |
11133 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11134 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, | |
11135 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11136 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, | |
11137 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
11138 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
11139 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11140 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, | |
11141 | PCI_ANY_ID, PCI_ANY_ID, }, | |
b87eab38 JS |
11142 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
11143 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11144 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, | |
11145 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11146 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, | |
11147 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11148 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, | |
11149 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11150 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, | |
11151 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11152 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, | |
11153 | PCI_ANY_ID, PCI_ANY_ID, }, | |
84774a4d JS |
11154 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
11155 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11156 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, | |
11157 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11158 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, | |
11159 | PCI_ANY_ID, PCI_ANY_ID, }, | |
3772a991 JS |
11160 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, |
11161 | PCI_ANY_ID, PCI_ANY_ID, }, | |
a747c9ce JS |
11162 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT, |
11163 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11164 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON, | |
6669f9bb | 11165 | PCI_ANY_ID, PCI_ANY_ID, }, |
98fc5dd9 JS |
11166 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS, |
11167 | PCI_ANY_ID, PCI_ANY_ID, }, | |
085c647c JS |
11168 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC, |
11169 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11170 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE, | |
11171 | PCI_ANY_ID, PCI_ANY_ID, }, | |
c0c11512 JS |
11172 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF, |
11173 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11174 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF, | |
11175 | PCI_ANY_ID, PCI_ANY_ID, }, | |
f8cafd38 JS |
11176 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK, |
11177 | PCI_ANY_ID, PCI_ANY_ID, }, | |
11178 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF, | |
11179 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
11180 | { 0 } |
11181 | }; | |
11182 | ||
11183 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); | |
11184 | ||
a55b2d21 | 11185 | static const struct pci_error_handlers lpfc_err_handler = { |
8d63f375 LV |
11186 | .error_detected = lpfc_io_error_detected, |
11187 | .slot_reset = lpfc_io_slot_reset, | |
11188 | .resume = lpfc_io_resume, | |
11189 | }; | |
11190 | ||
dea3101e JB |
11191 | static struct pci_driver lpfc_driver = { |
11192 | .name = LPFC_DRIVER_NAME, | |
11193 | .id_table = lpfc_id_table, | |
11194 | .probe = lpfc_pci_probe_one, | |
6f039790 | 11195 | .remove = lpfc_pci_remove_one, |
3a55b532 | 11196 | .suspend = lpfc_pci_suspend_one, |
3772a991 | 11197 | .resume = lpfc_pci_resume_one, |
2e0fef85 | 11198 | .err_handler = &lpfc_err_handler, |
dea3101e JB |
11199 | }; |
11200 | ||
3ef6d24c | 11201 | static const struct file_operations lpfc_mgmt_fop = { |
858feacd | 11202 | .owner = THIS_MODULE, |
3ef6d24c JS |
11203 | }; |
11204 | ||
11205 | static struct miscdevice lpfc_mgmt_dev = { | |
11206 | .minor = MISC_DYNAMIC_MINOR, | |
11207 | .name = "lpfcmgmt", | |
11208 | .fops = &lpfc_mgmt_fop, | |
11209 | }; | |
11210 | ||
e59058c4 | 11211 | /** |
3621a710 | 11212 | * lpfc_init - lpfc module initialization routine |
e59058c4 JS |
11213 | * |
11214 | * This routine is to be invoked when the lpfc module is loaded into the | |
11215 | * kernel. The special kernel macro module_init() is used to indicate the | |
11216 | * role of this routine to the kernel as lpfc module entry point. | |
11217 | * | |
11218 | * Return codes | |
11219 | * 0 - successful | |
11220 | * -ENOMEM - FC attach transport failed | |
11221 | * all others - failed | |
11222 | */ | |
dea3101e JB |
11223 | static int __init |
11224 | lpfc_init(void) | |
11225 | { | |
7bb03bbf | 11226 | int cpu; |
dea3101e JB |
11227 | int error = 0; |
11228 | ||
11229 | printk(LPFC_MODULE_DESC "\n"); | |
c44ce173 | 11230 | printk(LPFC_COPYRIGHT "\n"); |
dea3101e | 11231 | |
3ef6d24c JS |
11232 | error = misc_register(&lpfc_mgmt_dev); |
11233 | if (error) | |
11234 | printk(KERN_ERR "Could not register lpfcmgmt device, " | |
11235 | "misc_register returned with status %d", error); | |
11236 | ||
7ee5d43e JS |
11237 | if (lpfc_enable_npiv) { |
11238 | lpfc_transport_functions.vport_create = lpfc_vport_create; | |
11239 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; | |
11240 | } | |
dea3101e JB |
11241 | lpfc_transport_template = |
11242 | fc_attach_transport(&lpfc_transport_functions); | |
7ee5d43e | 11243 | if (lpfc_transport_template == NULL) |
dea3101e | 11244 | return -ENOMEM; |
7ee5d43e | 11245 | if (lpfc_enable_npiv) { |
7ee5d43e | 11246 | lpfc_vport_transport_template = |
98c9ea5c JS |
11247 | fc_attach_transport(&lpfc_vport_transport_functions); |
11248 | if (lpfc_vport_transport_template == NULL) { | |
11249 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e | 11250 | return -ENOMEM; |
98c9ea5c | 11251 | } |
7ee5d43e | 11252 | } |
7bb03bbf JS |
11253 | |
11254 | /* Initialize in case vector mapping is needed */ | |
b246de17 JS |
11255 | lpfc_used_cpu = NULL; |
11256 | lpfc_present_cpu = 0; | |
11257 | for_each_present_cpu(cpu) | |
11258 | lpfc_present_cpu++; | |
7bb03bbf | 11259 | |
dea3101e | 11260 | error = pci_register_driver(&lpfc_driver); |
92d7f7b0 | 11261 | if (error) { |
dea3101e | 11262 | fc_release_transport(lpfc_transport_template); |
d7c255b2 JS |
11263 | if (lpfc_enable_npiv) |
11264 | fc_release_transport(lpfc_vport_transport_template); | |
92d7f7b0 | 11265 | } |
dea3101e JB |
11266 | |
11267 | return error; | |
11268 | } | |
11269 | ||
e59058c4 | 11270 | /** |
3621a710 | 11271 | * lpfc_exit - lpfc module removal routine |
e59058c4 JS |
11272 | * |
11273 | * This routine is invoked when the lpfc module is removed from the kernel. | |
11274 | * The special kernel macro module_exit() is used to indicate the role of | |
11275 | * this routine to the kernel as lpfc module exit point. | |
11276 | */ | |
dea3101e JB |
11277 | static void __exit |
11278 | lpfc_exit(void) | |
11279 | { | |
3ef6d24c | 11280 | misc_deregister(&lpfc_mgmt_dev); |
dea3101e JB |
11281 | pci_unregister_driver(&lpfc_driver); |
11282 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e JS |
11283 | if (lpfc_enable_npiv) |
11284 | fc_release_transport(lpfc_vport_transport_template); | |
81301a9b | 11285 | if (_dump_buf_data) { |
6a9c52cf JS |
11286 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
11287 | "_dump_buf_data at 0x%p\n", | |
81301a9b JS |
11288 | (1L << _dump_buf_data_order), _dump_buf_data); |
11289 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); | |
11290 | } | |
11291 | ||
11292 | if (_dump_buf_dif) { | |
6a9c52cf JS |
11293 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
11294 | "_dump_buf_dif at 0x%p\n", | |
81301a9b JS |
11295 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
11296 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); | |
11297 | } | |
b246de17 | 11298 | kfree(lpfc_used_cpu); |
dea3101e JB |
11299 | } |
11300 | ||
11301 | module_init(lpfc_init); | |
11302 | module_exit(lpfc_exit); | |
11303 | MODULE_LICENSE("GPL"); | |
11304 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); | |
11305 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); | |
11306 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |