]>
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. * |
792581de | 4 | * Copyright (C) 2004-2011 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e JB |
8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
10 | * modify it under the terms of version 2 of the GNU General * |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
dea3101e JB |
20 | *******************************************************************/ |
21 | ||
dea3101e JB |
22 | #include <linux/blkdev.h> |
23 | #include <linux/delay.h> | |
24 | #include <linux/dma-mapping.h> | |
25 | #include <linux/idr.h> | |
26 | #include <linux/interrupt.h> | |
27 | #include <linux/kthread.h> | |
28 | #include <linux/pci.h> | |
29 | #include <linux/spinlock.h> | |
92d7f7b0 | 30 | #include <linux/ctype.h> |
0d878419 | 31 | #include <linux/aer.h> |
5a0e3ad6 | 32 | #include <linux/slab.h> |
dea3101e | 33 | |
91886523 | 34 | #include <scsi/scsi.h> |
dea3101e JB |
35 | #include <scsi/scsi_device.h> |
36 | #include <scsi/scsi_host.h> | |
37 | #include <scsi/scsi_transport_fc.h> | |
38 | ||
da0436e9 | 39 | #include "lpfc_hw4.h" |
dea3101e JB |
40 | #include "lpfc_hw.h" |
41 | #include "lpfc_sli.h" | |
da0436e9 | 42 | #include "lpfc_sli4.h" |
ea2151b4 | 43 | #include "lpfc_nl.h" |
dea3101e JB |
44 | #include "lpfc_disc.h" |
45 | #include "lpfc_scsi.h" | |
46 | #include "lpfc.h" | |
47 | #include "lpfc_logmsg.h" | |
48 | #include "lpfc_crtn.h" | |
92d7f7b0 | 49 | #include "lpfc_vport.h" |
dea3101e JB |
50 | #include "lpfc_version.h" |
51 | ||
81301a9b JS |
52 | char *_dump_buf_data; |
53 | unsigned long _dump_buf_data_order; | |
54 | char *_dump_buf_dif; | |
55 | unsigned long _dump_buf_dif_order; | |
56 | spinlock_t _dump_buf_lock; | |
57 | ||
dea3101e JB |
58 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
59 | static int lpfc_post_rcv_buf(struct lpfc_hba *); | |
da0436e9 JS |
60 | static int lpfc_sli4_queue_create(struct lpfc_hba *); |
61 | static void lpfc_sli4_queue_destroy(struct lpfc_hba *); | |
62 | static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); | |
63 | static int lpfc_setup_endian_order(struct lpfc_hba *); | |
64 | static int lpfc_sli4_read_config(struct lpfc_hba *); | |
65 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); | |
66 | static void lpfc_free_sgl_list(struct lpfc_hba *); | |
67 | static int lpfc_init_sgl_list(struct lpfc_hba *); | |
68 | static int lpfc_init_active_sgl_array(struct lpfc_hba *); | |
69 | static void lpfc_free_active_sgl(struct lpfc_hba *); | |
70 | static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); | |
71 | static int lpfc_hba_down_post_s4(struct lpfc_hba *phba); | |
72 | static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *); | |
73 | static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *); | |
74 | static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *); | |
dea3101e JB |
75 | |
76 | static struct scsi_transport_template *lpfc_transport_template = NULL; | |
92d7f7b0 | 77 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
dea3101e JB |
78 | static DEFINE_IDR(lpfc_hba_index); |
79 | ||
e59058c4 | 80 | /** |
3621a710 | 81 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
e59058c4 JS |
82 | * @phba: pointer to lpfc hba data structure. |
83 | * | |
84 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT | |
85 | * mailbox command. It retrieves the revision information from the HBA and | |
86 | * collects the Vital Product Data (VPD) about the HBA for preparing the | |
87 | * configuration of the HBA. | |
88 | * | |
89 | * Return codes: | |
90 | * 0 - success. | |
91 | * -ERESTART - requests the SLI layer to reset the HBA and try again. | |
92 | * Any other value - indicates an error. | |
93 | **/ | |
dea3101e | 94 | int |
2e0fef85 | 95 | lpfc_config_port_prep(struct lpfc_hba *phba) |
dea3101e JB |
96 | { |
97 | lpfc_vpd_t *vp = &phba->vpd; | |
98 | int i = 0, rc; | |
99 | LPFC_MBOXQ_t *pmb; | |
100 | MAILBOX_t *mb; | |
101 | char *lpfc_vpd_data = NULL; | |
102 | uint16_t offset = 0; | |
103 | static char licensed[56] = | |
104 | "key unlock for use with gnu public licensed code only\0"; | |
65a29c16 | 105 | static int init_key = 1; |
dea3101e JB |
106 | |
107 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
108 | if (!pmb) { | |
2e0fef85 | 109 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
110 | return -ENOMEM; |
111 | } | |
112 | ||
04c68496 | 113 | mb = &pmb->u.mb; |
2e0fef85 | 114 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e JB |
115 | |
116 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { | |
65a29c16 JS |
117 | if (init_key) { |
118 | uint32_t *ptext = (uint32_t *) licensed; | |
dea3101e | 119 | |
65a29c16 JS |
120 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
121 | *ptext = cpu_to_be32(*ptext); | |
122 | init_key = 0; | |
123 | } | |
dea3101e JB |
124 | |
125 | lpfc_read_nv(phba, pmb); | |
126 | memset((char*)mb->un.varRDnvp.rsvd3, 0, | |
127 | sizeof (mb->un.varRDnvp.rsvd3)); | |
128 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, | |
129 | sizeof (licensed)); | |
130 | ||
131 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
132 | ||
133 | if (rc != MBX_SUCCESS) { | |
ed957684 | 134 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
e8b62011 | 135 | "0324 Config Port initialization " |
dea3101e JB |
136 | "error, mbxCmd x%x READ_NVPARM, " |
137 | "mbxStatus x%x\n", | |
dea3101e JB |
138 | mb->mbxCommand, mb->mbxStatus); |
139 | mempool_free(pmb, phba->mbox_mem_pool); | |
140 | return -ERESTART; | |
141 | } | |
142 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, | |
2e0fef85 JS |
143 | sizeof(phba->wwnn)); |
144 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, | |
145 | sizeof(phba->wwpn)); | |
dea3101e JB |
146 | } |
147 | ||
92d7f7b0 JS |
148 | phba->sli3_options = 0x0; |
149 | ||
dea3101e JB |
150 | /* Setup and issue mailbox READ REV command */ |
151 | lpfc_read_rev(phba, pmb); | |
152 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
153 | if (rc != MBX_SUCCESS) { | |
ed957684 | 154 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 155 | "0439 Adapter failed to init, mbxCmd x%x " |
dea3101e | 156 | "READ_REV, mbxStatus x%x\n", |
dea3101e JB |
157 | mb->mbxCommand, mb->mbxStatus); |
158 | mempool_free( pmb, phba->mbox_mem_pool); | |
159 | return -ERESTART; | |
160 | } | |
161 | ||
92d7f7b0 | 162 | |
1de933f3 JSEC |
163 | /* |
164 | * The value of rr must be 1 since the driver set the cv field to 1. | |
165 | * This setting requires the FW to set all revision fields. | |
dea3101e | 166 | */ |
1de933f3 | 167 | if (mb->un.varRdRev.rr == 0) { |
dea3101e | 168 | vp->rev.rBit = 0; |
1de933f3 | 169 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 JS |
170 | "0440 Adapter failed to init, READ_REV has " |
171 | "missing revision information.\n"); | |
dea3101e JB |
172 | mempool_free(pmb, phba->mbox_mem_pool); |
173 | return -ERESTART; | |
dea3101e JB |
174 | } |
175 | ||
495a714c JS |
176 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
177 | mempool_free(pmb, phba->mbox_mem_pool); | |
ed957684 | 178 | return -EINVAL; |
495a714c | 179 | } |
ed957684 | 180 | |
dea3101e | 181 | /* Save information as VPD data */ |
1de933f3 | 182 | vp->rev.rBit = 1; |
92d7f7b0 | 183 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
1de933f3 JSEC |
184 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
185 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); | |
186 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; | |
187 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); | |
dea3101e JB |
188 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
189 | vp->rev.smRev = mb->un.varRdRev.smRev; | |
190 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; | |
191 | vp->rev.endecRev = mb->un.varRdRev.endecRev; | |
192 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; | |
193 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; | |
194 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; | |
195 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; | |
196 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; | |
197 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; | |
198 | ||
92d7f7b0 JS |
199 | /* If the sli feature level is less then 9, we must |
200 | * tear down all RPIs and VPIs on link down if NPIV | |
201 | * is enabled. | |
202 | */ | |
203 | if (vp->rev.feaLevelHigh < 9) | |
204 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; | |
205 | ||
dea3101e JB |
206 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
207 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], | |
208 | sizeof (phba->RandomData)); | |
209 | ||
dea3101e | 210 | /* Get adapter VPD information */ |
dea3101e JB |
211 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
212 | if (!lpfc_vpd_data) | |
d7c255b2 | 213 | goto out_free_mbox; |
dea3101e JB |
214 | |
215 | do { | |
a0c87cbd | 216 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
dea3101e JB |
217 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
218 | ||
219 | if (rc != MBX_SUCCESS) { | |
220 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 | 221 | "0441 VPD not present on adapter, " |
dea3101e | 222 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
dea3101e | 223 | mb->mbxCommand, mb->mbxStatus); |
74b72a59 | 224 | mb->un.varDmp.word_cnt = 0; |
dea3101e | 225 | } |
04c68496 JS |
226 | /* dump mem may return a zero when finished or we got a |
227 | * mailbox error, either way we are done. | |
228 | */ | |
229 | if (mb->un.varDmp.word_cnt == 0) | |
230 | break; | |
74b72a59 JW |
231 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
232 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; | |
d7c255b2 JS |
233 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
234 | lpfc_vpd_data + offset, | |
92d7f7b0 | 235 | mb->un.varDmp.word_cnt); |
dea3101e | 236 | offset += mb->un.varDmp.word_cnt; |
74b72a59 JW |
237 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
238 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); | |
dea3101e JB |
239 | |
240 | kfree(lpfc_vpd_data); | |
dea3101e JB |
241 | out_free_mbox: |
242 | mempool_free(pmb, phba->mbox_mem_pool); | |
243 | return 0; | |
244 | } | |
245 | ||
e59058c4 | 246 | /** |
3621a710 | 247 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
e59058c4 JS |
248 | * @phba: pointer to lpfc hba data structure. |
249 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
250 | * | |
251 | * This is the completion handler for driver's configuring asynchronous event | |
252 | * mailbox command to the device. If the mailbox command returns successfully, | |
253 | * it will set internal async event support flag to 1; otherwise, it will | |
254 | * set internal async event support flag to 0. | |
255 | **/ | |
57127f15 JS |
256 | static void |
257 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
258 | { | |
04c68496 | 259 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
57127f15 JS |
260 | phba->temp_sensor_support = 1; |
261 | else | |
262 | phba->temp_sensor_support = 0; | |
263 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
264 | return; | |
265 | } | |
266 | ||
97207482 | 267 | /** |
3621a710 | 268 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
97207482 JS |
269 | * @phba: pointer to lpfc hba data structure. |
270 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
271 | * | |
272 | * This is the completion handler for dump mailbox command for getting | |
273 | * wake up parameters. When this command complete, the response contain | |
274 | * Option rom version of the HBA. This function translate the version number | |
275 | * into a human readable string and store it in OptionROMVersion. | |
276 | **/ | |
277 | static void | |
278 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) | |
279 | { | |
280 | struct prog_id *prg; | |
281 | uint32_t prog_id_word; | |
282 | char dist = ' '; | |
283 | /* character array used for decoding dist type. */ | |
284 | char dist_char[] = "nabx"; | |
285 | ||
04c68496 | 286 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
9f1e1b50 | 287 | mempool_free(pmboxq, phba->mbox_mem_pool); |
97207482 | 288 | return; |
9f1e1b50 | 289 | } |
97207482 JS |
290 | |
291 | prg = (struct prog_id *) &prog_id_word; | |
292 | ||
293 | /* word 7 contain option rom version */ | |
04c68496 | 294 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
97207482 JS |
295 | |
296 | /* Decode the Option rom version word to a readable string */ | |
297 | if (prg->dist < 4) | |
298 | dist = dist_char[prg->dist]; | |
299 | ||
300 | if ((prg->dist == 3) && (prg->num == 0)) | |
301 | sprintf(phba->OptionROMVersion, "%d.%d%d", | |
302 | prg->ver, prg->rev, prg->lev); | |
303 | else | |
304 | sprintf(phba->OptionROMVersion, "%d.%d%d%c%d", | |
305 | prg->ver, prg->rev, prg->lev, | |
306 | dist, prg->num); | |
9f1e1b50 | 307 | mempool_free(pmboxq, phba->mbox_mem_pool); |
97207482 JS |
308 | return; |
309 | } | |
310 | ||
0558056c JS |
311 | /** |
312 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, | |
313 | * cfg_soft_wwnn, cfg_soft_wwpn | |
314 | * @vport: pointer to lpfc vport data structure. | |
315 | * | |
316 | * | |
317 | * Return codes | |
318 | * None. | |
319 | **/ | |
320 | void | |
321 | lpfc_update_vport_wwn(struct lpfc_vport *vport) | |
322 | { | |
323 | /* If the soft name exists then update it using the service params */ | |
324 | if (vport->phba->cfg_soft_wwnn) | |
325 | u64_to_wwn(vport->phba->cfg_soft_wwnn, | |
326 | vport->fc_sparam.nodeName.u.wwn); | |
327 | if (vport->phba->cfg_soft_wwpn) | |
328 | u64_to_wwn(vport->phba->cfg_soft_wwpn, | |
329 | vport->fc_sparam.portName.u.wwn); | |
330 | ||
331 | /* | |
332 | * If the name is empty or there exists a soft name | |
333 | * then copy the service params name, otherwise use the fc name | |
334 | */ | |
335 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) | |
336 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, | |
337 | sizeof(struct lpfc_name)); | |
338 | else | |
339 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, | |
340 | sizeof(struct lpfc_name)); | |
341 | ||
342 | if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn) | |
343 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, | |
344 | sizeof(struct lpfc_name)); | |
345 | else | |
346 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, | |
347 | sizeof(struct lpfc_name)); | |
348 | } | |
349 | ||
e59058c4 | 350 | /** |
3621a710 | 351 | * lpfc_config_port_post - Perform lpfc initialization after config port |
e59058c4 JS |
352 | * @phba: pointer to lpfc hba data structure. |
353 | * | |
354 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox | |
355 | * command call. It performs all internal resource and state setups on the | |
356 | * port: post IOCB buffers, enable appropriate host interrupt attentions, | |
357 | * ELS ring timers, etc. | |
358 | * | |
359 | * Return codes | |
360 | * 0 - success. | |
361 | * Any other value - error. | |
362 | **/ | |
dea3101e | 363 | int |
2e0fef85 | 364 | lpfc_config_port_post(struct lpfc_hba *phba) |
dea3101e | 365 | { |
2e0fef85 | 366 | struct lpfc_vport *vport = phba->pport; |
a257bf90 | 367 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e JB |
368 | LPFC_MBOXQ_t *pmb; |
369 | MAILBOX_t *mb; | |
370 | struct lpfc_dmabuf *mp; | |
371 | struct lpfc_sli *psli = &phba->sli; | |
372 | uint32_t status, timeout; | |
2e0fef85 JS |
373 | int i, j; |
374 | int rc; | |
dea3101e | 375 | |
7af67051 JS |
376 | spin_lock_irq(&phba->hbalock); |
377 | /* | |
378 | * If the Config port completed correctly the HBA is not | |
379 | * over heated any more. | |
380 | */ | |
381 | if (phba->over_temp_state == HBA_OVER_TEMP) | |
382 | phba->over_temp_state = HBA_NORMAL_TEMP; | |
383 | spin_unlock_irq(&phba->hbalock); | |
384 | ||
dea3101e JB |
385 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
386 | if (!pmb) { | |
2e0fef85 | 387 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
388 | return -ENOMEM; |
389 | } | |
04c68496 | 390 | mb = &pmb->u.mb; |
dea3101e | 391 | |
dea3101e | 392 | /* Get login parameters for NID. */ |
9f1177a3 JS |
393 | rc = lpfc_read_sparam(phba, pmb, 0); |
394 | if (rc) { | |
395 | mempool_free(pmb, phba->mbox_mem_pool); | |
396 | return -ENOMEM; | |
397 | } | |
398 | ||
ed957684 | 399 | pmb->vport = vport; |
dea3101e | 400 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 401 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 402 | "0448 Adapter failed init, mbxCmd x%x " |
dea3101e | 403 | "READ_SPARM mbxStatus x%x\n", |
dea3101e | 404 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 405 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 406 | mp = (struct lpfc_dmabuf *) pmb->context1; |
9f1177a3 | 407 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e JB |
408 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
409 | kfree(mp); | |
410 | return -EIO; | |
411 | } | |
412 | ||
413 | mp = (struct lpfc_dmabuf *) pmb->context1; | |
414 | ||
2e0fef85 | 415 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
dea3101e JB |
416 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
417 | kfree(mp); | |
418 | pmb->context1 = NULL; | |
0558056c | 419 | lpfc_update_vport_wwn(vport); |
a257bf90 JS |
420 | |
421 | /* Update the fc_host data structures with new wwn. */ | |
422 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
423 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
21e9a0a5 | 424 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
a257bf90 | 425 | |
dea3101e JB |
426 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
427 | /* This should be consolidated into parse_vpd ? - mr */ | |
428 | if (phba->SerialNumber[0] == 0) { | |
429 | uint8_t *outptr; | |
430 | ||
2e0fef85 | 431 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
dea3101e JB |
432 | for (i = 0; i < 12; i++) { |
433 | status = *outptr++; | |
434 | j = ((status & 0xf0) >> 4); | |
435 | if (j <= 9) | |
436 | phba->SerialNumber[i] = | |
437 | (char)((uint8_t) 0x30 + (uint8_t) j); | |
438 | else | |
439 | phba->SerialNumber[i] = | |
440 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | |
441 | i++; | |
442 | j = (status & 0xf); | |
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 | } | |
450 | } | |
451 | ||
dea3101e | 452 | lpfc_read_config(phba, pmb); |
ed957684 | 453 | pmb->vport = vport; |
dea3101e | 454 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 455 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 456 | "0453 Adapter failed to init, mbxCmd x%x " |
dea3101e | 457 | "READ_CONFIG, mbxStatus x%x\n", |
dea3101e | 458 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 459 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
460 | mempool_free( pmb, phba->mbox_mem_pool); |
461 | return -EIO; | |
462 | } | |
463 | ||
a0c87cbd JS |
464 | /* Check if the port is disabled */ |
465 | lpfc_sli_read_link_ste(phba); | |
466 | ||
dea3101e JB |
467 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
468 | if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1)) | |
469 | phba->cfg_hba_queue_depth = | |
f1126688 JS |
470 | (mb->un.varRdConfig.max_xri + 1) - |
471 | lpfc_sli4_get_els_iocb_cnt(phba); | |
dea3101e JB |
472 | |
473 | phba->lmt = mb->un.varRdConfig.lmt; | |
74b72a59 JW |
474 | |
475 | /* Get the default values for Model Name and Description */ | |
476 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
477 | ||
76a95d75 JS |
478 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_16G) |
479 | || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) | |
74b72a59 | 480 | && !(phba->lmt & LMT_1Gb)) |
76a95d75 | 481 | || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) |
74b72a59 | 482 | && !(phba->lmt & LMT_2Gb)) |
76a95d75 | 483 | || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) |
74b72a59 | 484 | && !(phba->lmt & LMT_4Gb)) |
76a95d75 | 485 | || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) |
74b72a59 | 486 | && !(phba->lmt & LMT_8Gb)) |
76a95d75 JS |
487 | || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) |
488 | && !(phba->lmt & LMT_10Gb)) | |
489 | || ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) | |
490 | && !(phba->lmt & LMT_16Gb))) { | |
74b72a59 | 491 | /* Reset link speed to auto */ |
ab56dc2e | 492 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, |
e8b62011 | 493 | "1302 Invalid speed for this board: " |
dea3101e | 494 | "Reset link speed to auto: x%x\n", |
dea3101e | 495 | phba->cfg_link_speed); |
76a95d75 | 496 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
dea3101e JB |
497 | } |
498 | ||
2e0fef85 | 499 | phba->link_state = LPFC_LINK_DOWN; |
dea3101e | 500 | |
0b727fea | 501 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
a4bc3379 JS |
502 | if (psli->ring[psli->extra_ring].cmdringaddr) |
503 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; | |
dea3101e JB |
504 | if (psli->ring[psli->fcp_ring].cmdringaddr) |
505 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; | |
506 | if (psli->ring[psli->next_ring].cmdringaddr) | |
507 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; | |
508 | ||
509 | /* Post receive buffers for desired rings */ | |
ed957684 JS |
510 | if (phba->sli_rev != 3) |
511 | lpfc_post_rcv_buf(phba); | |
dea3101e | 512 | |
9399627f JS |
513 | /* |
514 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode | |
515 | */ | |
516 | if (phba->intr_type == MSIX) { | |
517 | rc = lpfc_config_msi(phba, pmb); | |
518 | if (rc) { | |
519 | mempool_free(pmb, phba->mbox_mem_pool); | |
520 | return -EIO; | |
521 | } | |
522 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
523 | if (rc != MBX_SUCCESS) { | |
524 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
525 | "0352 Config MSI mailbox command " | |
526 | "failed, mbxCmd x%x, mbxStatus x%x\n", | |
04c68496 JS |
527 | pmb->u.mb.mbxCommand, |
528 | pmb->u.mb.mbxStatus); | |
9399627f JS |
529 | mempool_free(pmb, phba->mbox_mem_pool); |
530 | return -EIO; | |
531 | } | |
532 | } | |
533 | ||
04c68496 | 534 | spin_lock_irq(&phba->hbalock); |
9399627f JS |
535 | /* Initialize ERATT handling flag */ |
536 | phba->hba_flag &= ~HBA_ERATT_HANDLED; | |
537 | ||
dea3101e | 538 | /* Enable appropriate host interrupts */ |
9940b97b JS |
539 | if (lpfc_readl(phba->HCregaddr, &status)) { |
540 | spin_unlock_irq(&phba->hbalock); | |
541 | return -EIO; | |
542 | } | |
dea3101e JB |
543 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
544 | if (psli->num_rings > 0) | |
545 | status |= HC_R0INT_ENA; | |
546 | if (psli->num_rings > 1) | |
547 | status |= HC_R1INT_ENA; | |
548 | if (psli->num_rings > 2) | |
549 | status |= HC_R2INT_ENA; | |
550 | if (psli->num_rings > 3) | |
551 | status |= HC_R3INT_ENA; | |
552 | ||
875fbdfe JSEC |
553 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
554 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) | |
9399627f | 555 | status &= ~(HC_R0INT_ENA); |
875fbdfe | 556 | |
dea3101e JB |
557 | writel(status, phba->HCregaddr); |
558 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 559 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 560 | |
9399627f JS |
561 | /* Set up ring-0 (ELS) timer */ |
562 | timeout = phba->fc_ratov * 2; | |
2e0fef85 | 563 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
9399627f | 564 | /* Set up heart beat (HB) timer */ |
858c9f6c JS |
565 | mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
566 | phba->hb_outstanding = 0; | |
567 | phba->last_completion_time = jiffies; | |
9399627f JS |
568 | /* Set up error attention (ERATT) polling timer */ |
569 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); | |
dea3101e | 570 | |
a0c87cbd JS |
571 | if (phba->hba_flag & LINK_DISABLED) { |
572 | lpfc_printf_log(phba, | |
573 | KERN_ERR, LOG_INIT, | |
574 | "2598 Adapter Link is disabled.\n"); | |
575 | lpfc_down_link(phba, pmb); | |
576 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
577 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
578 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { | |
579 | lpfc_printf_log(phba, | |
580 | KERN_ERR, LOG_INIT, | |
581 | "2599 Adapter failed to issue DOWN_LINK" | |
582 | " mbox command rc 0x%x\n", rc); | |
583 | ||
584 | mempool_free(pmb, phba->mbox_mem_pool); | |
585 | return -EIO; | |
586 | } | |
e40a02c1 | 587 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
a0c87cbd JS |
588 | lpfc_init_link(phba, pmb, phba->cfg_topology, |
589 | phba->cfg_link_speed); | |
590 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
591 | lpfc_set_loopback_flag(phba); | |
592 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
593 | if (rc != MBX_SUCCESS) { | |
594 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 | 595 | "0454 Adapter failed to init, mbxCmd x%x " |
dea3101e | 596 | "INIT_LINK, mbxStatus x%x\n", |
dea3101e JB |
597 | mb->mbxCommand, mb->mbxStatus); |
598 | ||
a0c87cbd JS |
599 | /* Clear all interrupt enable conditions */ |
600 | writel(0, phba->HCregaddr); | |
601 | readl(phba->HCregaddr); /* flush */ | |
602 | /* Clear all pending interrupts */ | |
603 | writel(0xffffffff, phba->HAregaddr); | |
604 | readl(phba->HAregaddr); /* flush */ | |
dea3101e | 605 | |
a0c87cbd JS |
606 | phba->link_state = LPFC_HBA_ERROR; |
607 | if (rc != MBX_BUSY) | |
608 | mempool_free(pmb, phba->mbox_mem_pool); | |
609 | return -EIO; | |
610 | } | |
dea3101e JB |
611 | } |
612 | /* MBOX buffer will be freed in mbox compl */ | |
57127f15 | 613 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
9f1177a3 JS |
614 | if (!pmb) { |
615 | phba->link_state = LPFC_HBA_ERROR; | |
616 | return -ENOMEM; | |
617 | } | |
618 | ||
57127f15 JS |
619 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
620 | pmb->mbox_cmpl = lpfc_config_async_cmpl; | |
621 | pmb->vport = phba->pport; | |
622 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
dea3101e | 623 | |
57127f15 JS |
624 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
625 | lpfc_printf_log(phba, | |
626 | KERN_ERR, | |
627 | LOG_INIT, | |
628 | "0456 Adapter failed to issue " | |
e4e74273 | 629 | "ASYNCEVT_ENABLE mbox status x%x\n", |
57127f15 JS |
630 | rc); |
631 | mempool_free(pmb, phba->mbox_mem_pool); | |
632 | } | |
97207482 JS |
633 | |
634 | /* Get Option rom version */ | |
635 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
9f1177a3 JS |
636 | if (!pmb) { |
637 | phba->link_state = LPFC_HBA_ERROR; | |
638 | return -ENOMEM; | |
639 | } | |
640 | ||
97207482 JS |
641 | lpfc_dump_wakeup_param(phba, pmb); |
642 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; | |
643 | pmb->vport = phba->pport; | |
644 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
645 | ||
646 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { | |
647 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " | |
e4e74273 | 648 | "to get Option ROM version status x%x\n", rc); |
97207482 JS |
649 | mempool_free(pmb, phba->mbox_mem_pool); |
650 | } | |
651 | ||
d7c255b2 | 652 | return 0; |
ce8b3ce5 JS |
653 | } |
654 | ||
84d1b006 JS |
655 | /** |
656 | * lpfc_hba_init_link - Initialize the FC link | |
657 | * @phba: pointer to lpfc hba data structure. | |
6e7288d9 | 658 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
84d1b006 JS |
659 | * |
660 | * This routine will issue the INIT_LINK mailbox command call. | |
661 | * It is available to other drivers through the lpfc_hba data | |
662 | * structure for use as a delayed link up mechanism with the | |
663 | * module parameter lpfc_suppress_link_up. | |
664 | * | |
665 | * Return code | |
666 | * 0 - success | |
667 | * Any other value - error | |
668 | **/ | |
669 | int | |
6e7288d9 | 670 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
84d1b006 JS |
671 | { |
672 | struct lpfc_vport *vport = phba->pport; | |
673 | LPFC_MBOXQ_t *pmb; | |
674 | MAILBOX_t *mb; | |
675 | int rc; | |
676 | ||
677 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
678 | if (!pmb) { | |
679 | phba->link_state = LPFC_HBA_ERROR; | |
680 | return -ENOMEM; | |
681 | } | |
682 | mb = &pmb->u.mb; | |
683 | pmb->vport = vport; | |
684 | ||
76a95d75 | 685 | lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed); |
84d1b006 JS |
686 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
687 | lpfc_set_loopback_flag(phba); | |
6e7288d9 | 688 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
76a95d75 | 689 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
84d1b006 JS |
690 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
691 | "0498 Adapter failed to init, mbxCmd x%x " | |
692 | "INIT_LINK, mbxStatus x%x\n", | |
693 | mb->mbxCommand, mb->mbxStatus); | |
76a95d75 JS |
694 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
695 | /* Clear all interrupt enable conditions */ | |
696 | writel(0, phba->HCregaddr); | |
697 | readl(phba->HCregaddr); /* flush */ | |
698 | /* Clear all pending interrupts */ | |
699 | writel(0xffffffff, phba->HAregaddr); | |
700 | readl(phba->HAregaddr); /* flush */ | |
701 | } | |
84d1b006 | 702 | phba->link_state = LPFC_HBA_ERROR; |
6e7288d9 | 703 | if (rc != MBX_BUSY || flag == MBX_POLL) |
84d1b006 JS |
704 | mempool_free(pmb, phba->mbox_mem_pool); |
705 | return -EIO; | |
706 | } | |
e40a02c1 | 707 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
6e7288d9 JS |
708 | if (flag == MBX_POLL) |
709 | mempool_free(pmb, phba->mbox_mem_pool); | |
84d1b006 JS |
710 | |
711 | return 0; | |
712 | } | |
713 | ||
714 | /** | |
715 | * lpfc_hba_down_link - this routine downs the FC link | |
6e7288d9 JS |
716 | * @phba: pointer to lpfc hba data structure. |
717 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT | |
84d1b006 JS |
718 | * |
719 | * This routine will issue the DOWN_LINK mailbox command call. | |
720 | * It is available to other drivers through the lpfc_hba data | |
721 | * structure for use to stop the link. | |
722 | * | |
723 | * Return code | |
724 | * 0 - success | |
725 | * Any other value - error | |
726 | **/ | |
727 | int | |
6e7288d9 | 728 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
84d1b006 JS |
729 | { |
730 | LPFC_MBOXQ_t *pmb; | |
731 | int rc; | |
732 | ||
733 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
734 | if (!pmb) { | |
735 | phba->link_state = LPFC_HBA_ERROR; | |
736 | return -ENOMEM; | |
737 | } | |
738 | ||
739 | lpfc_printf_log(phba, | |
740 | KERN_ERR, LOG_INIT, | |
741 | "0491 Adapter Link is disabled.\n"); | |
742 | lpfc_down_link(phba, pmb); | |
743 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
6e7288d9 | 744 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
84d1b006 JS |
745 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
746 | lpfc_printf_log(phba, | |
747 | KERN_ERR, LOG_INIT, | |
748 | "2522 Adapter failed to issue DOWN_LINK" | |
749 | " mbox command rc 0x%x\n", rc); | |
750 | ||
751 | mempool_free(pmb, phba->mbox_mem_pool); | |
752 | return -EIO; | |
753 | } | |
6e7288d9 JS |
754 | if (flag == MBX_POLL) |
755 | mempool_free(pmb, phba->mbox_mem_pool); | |
756 | ||
84d1b006 JS |
757 | return 0; |
758 | } | |
759 | ||
e59058c4 | 760 | /** |
3621a710 | 761 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
e59058c4 JS |
762 | * @phba: pointer to lpfc HBA data structure. |
763 | * | |
764 | * This routine will do LPFC uninitialization before the HBA is reset when | |
765 | * bringing down the SLI Layer. | |
766 | * | |
767 | * Return codes | |
768 | * 0 - success. | |
769 | * Any other value - error. | |
770 | **/ | |
dea3101e | 771 | int |
2e0fef85 | 772 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
dea3101e | 773 | { |
1b32f6aa JS |
774 | struct lpfc_vport **vports; |
775 | int i; | |
3772a991 JS |
776 | |
777 | if (phba->sli_rev <= LPFC_SLI_REV3) { | |
778 | /* Disable interrupts */ | |
779 | writel(0, phba->HCregaddr); | |
780 | readl(phba->HCregaddr); /* flush */ | |
781 | } | |
dea3101e | 782 | |
1b32f6aa JS |
783 | if (phba->pport->load_flag & FC_UNLOADING) |
784 | lpfc_cleanup_discovery_resources(phba->pport); | |
785 | else { | |
786 | vports = lpfc_create_vport_work_array(phba); | |
787 | if (vports != NULL) | |
3772a991 JS |
788 | for (i = 0; i <= phba->max_vports && |
789 | vports[i] != NULL; i++) | |
1b32f6aa JS |
790 | lpfc_cleanup_discovery_resources(vports[i]); |
791 | lpfc_destroy_vport_work_array(phba, vports); | |
7f5f3d0d JS |
792 | } |
793 | return 0; | |
dea3101e JB |
794 | } |
795 | ||
e59058c4 | 796 | /** |
3772a991 | 797 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
e59058c4 JS |
798 | * @phba: pointer to lpfc HBA data structure. |
799 | * | |
800 | * This routine will do uninitialization after the HBA is reset when bring | |
801 | * down the SLI Layer. | |
802 | * | |
803 | * Return codes | |
af901ca1 | 804 | * 0 - success. |
e59058c4 JS |
805 | * Any other value - error. |
806 | **/ | |
3772a991 JS |
807 | static int |
808 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) | |
41415862 JW |
809 | { |
810 | struct lpfc_sli *psli = &phba->sli; | |
811 | struct lpfc_sli_ring *pring; | |
812 | struct lpfc_dmabuf *mp, *next_mp; | |
09372820 | 813 | LIST_HEAD(completions); |
41415862 JW |
814 | int i; |
815 | ||
92d7f7b0 JS |
816 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
817 | lpfc_sli_hbqbuf_free_all(phba); | |
818 | else { | |
819 | /* Cleanup preposted buffers on the ELS ring */ | |
820 | pring = &psli->ring[LPFC_ELS_RING]; | |
821 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
822 | list_del(&mp->list); | |
823 | pring->postbufq_cnt--; | |
824 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
825 | kfree(mp); | |
826 | } | |
41415862 JW |
827 | } |
828 | ||
09372820 | 829 | spin_lock_irq(&phba->hbalock); |
41415862 JW |
830 | for (i = 0; i < psli->num_rings; i++) { |
831 | pring = &psli->ring[i]; | |
09372820 JS |
832 | |
833 | /* At this point in time the HBA is either reset or DOA. Either | |
834 | * way, nothing should be on txcmplq as it will NEVER complete. | |
835 | */ | |
836 | list_splice_init(&pring->txcmplq, &completions); | |
837 | pring->txcmplq_cnt = 0; | |
838 | spin_unlock_irq(&phba->hbalock); | |
839 | ||
a257bf90 JS |
840 | /* Cancel all the IOCBs from the completions list */ |
841 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
842 | IOERR_SLI_ABORTED); | |
09372820 | 843 | |
41415862 | 844 | lpfc_sli_abort_iocb_ring(phba, pring); |
09372820 | 845 | spin_lock_irq(&phba->hbalock); |
41415862 | 846 | } |
09372820 | 847 | spin_unlock_irq(&phba->hbalock); |
41415862 JW |
848 | |
849 | return 0; | |
850 | } | |
5af5eee7 | 851 | |
da0436e9 JS |
852 | /** |
853 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset | |
854 | * @phba: pointer to lpfc HBA data structure. | |
855 | * | |
856 | * This routine will do uninitialization after the HBA is reset when bring | |
857 | * down the SLI Layer. | |
858 | * | |
859 | * Return codes | |
af901ca1 | 860 | * 0 - success. |
da0436e9 JS |
861 | * Any other value - error. |
862 | **/ | |
863 | static int | |
864 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) | |
865 | { | |
866 | struct lpfc_scsi_buf *psb, *psb_next; | |
867 | LIST_HEAD(aborts); | |
868 | int ret; | |
869 | unsigned long iflag = 0; | |
0f65ff68 JS |
870 | struct lpfc_sglq *sglq_entry = NULL; |
871 | ||
da0436e9 JS |
872 | ret = lpfc_hba_down_post_s3(phba); |
873 | if (ret) | |
874 | return ret; | |
875 | /* At this point in time the HBA is either reset or DOA. Either | |
876 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be | |
877 | * on the lpfc_sgl_list so that it can either be freed if the | |
878 | * driver is unloading or reposted if the driver is restarting | |
879 | * the port. | |
880 | */ | |
881 | spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */ | |
882 | /* scsl_buf_list */ | |
883 | /* abts_sgl_list_lock required because worker thread uses this | |
884 | * list. | |
885 | */ | |
886 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); | |
0f65ff68 JS |
887 | list_for_each_entry(sglq_entry, |
888 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) | |
889 | sglq_entry->state = SGL_FREED; | |
890 | ||
da0436e9 JS |
891 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
892 | &phba->sli4_hba.lpfc_sgl_list); | |
893 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); | |
894 | /* abts_scsi_buf_list_lock required because worker thread uses this | |
895 | * list. | |
896 | */ | |
897 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
898 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, | |
899 | &aborts); | |
900 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
901 | spin_unlock_irq(&phba->hbalock); | |
902 | ||
903 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { | |
904 | psb->pCmd = NULL; | |
905 | psb->status = IOSTAT_SUCCESS; | |
906 | } | |
907 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); | |
908 | list_splice(&aborts, &phba->lpfc_scsi_buf_list); | |
909 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); | |
910 | return 0; | |
911 | } | |
912 | ||
913 | /** | |
914 | * lpfc_hba_down_post - Wrapper func for hba down post routine | |
915 | * @phba: pointer to lpfc HBA data structure. | |
916 | * | |
917 | * This routine wraps the actual SLI3 or SLI4 routine for performing | |
918 | * uninitialization after the HBA is reset when bring down the SLI Layer. | |
919 | * | |
920 | * Return codes | |
af901ca1 | 921 | * 0 - success. |
da0436e9 JS |
922 | * Any other value - error. |
923 | **/ | |
924 | int | |
925 | lpfc_hba_down_post(struct lpfc_hba *phba) | |
926 | { | |
927 | return (*phba->lpfc_hba_down_post)(phba); | |
928 | } | |
41415862 | 929 | |
e59058c4 | 930 | /** |
3621a710 | 931 | * lpfc_hb_timeout - The HBA-timer timeout handler |
e59058c4 JS |
932 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
933 | * | |
934 | * This is the HBA-timer timeout handler registered to the lpfc driver. When | |
935 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver | |
936 | * work-port-events bitmap and the worker thread is notified. This timeout | |
937 | * event will be used by the worker thread to invoke the actual timeout | |
938 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will | |
939 | * be performed in the timeout handler and the HBA timeout event bit shall | |
940 | * be cleared by the worker thread after it has taken the event bitmap out. | |
941 | **/ | |
a6ababd2 | 942 | static void |
858c9f6c JS |
943 | lpfc_hb_timeout(unsigned long ptr) |
944 | { | |
945 | struct lpfc_hba *phba; | |
5e9d9b82 | 946 | uint32_t tmo_posted; |
858c9f6c JS |
947 | unsigned long iflag; |
948 | ||
949 | phba = (struct lpfc_hba *)ptr; | |
9399627f JS |
950 | |
951 | /* Check for heart beat timeout conditions */ | |
858c9f6c | 952 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
5e9d9b82 JS |
953 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
954 | if (!tmo_posted) | |
858c9f6c JS |
955 | phba->pport->work_port_events |= WORKER_HB_TMO; |
956 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
957 | ||
9399627f | 958 | /* Tell the worker thread there is work to do */ |
5e9d9b82 JS |
959 | if (!tmo_posted) |
960 | lpfc_worker_wake_up(phba); | |
858c9f6c JS |
961 | return; |
962 | } | |
963 | ||
19ca7609 JS |
964 | /** |
965 | * lpfc_rrq_timeout - The RRQ-timer timeout handler | |
966 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. | |
967 | * | |
968 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When | |
969 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver | |
970 | * work-port-events bitmap and the worker thread is notified. This timeout | |
971 | * event will be used by the worker thread to invoke the actual timeout | |
972 | * handler routine, lpfc_rrq_handler. Any periodical operations will | |
973 | * be performed in the timeout handler and the RRQ timeout event bit shall | |
974 | * be cleared by the worker thread after it has taken the event bitmap out. | |
975 | **/ | |
976 | static void | |
977 | lpfc_rrq_timeout(unsigned long ptr) | |
978 | { | |
979 | struct lpfc_hba *phba; | |
19ca7609 JS |
980 | unsigned long iflag; |
981 | ||
982 | phba = (struct lpfc_hba *)ptr; | |
983 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
1151e3ec | 984 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
19ca7609 | 985 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
1151e3ec | 986 | lpfc_worker_wake_up(phba); |
19ca7609 JS |
987 | } |
988 | ||
e59058c4 | 989 | /** |
3621a710 | 990 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
e59058c4 JS |
991 | * @phba: pointer to lpfc hba data structure. |
992 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
993 | * | |
994 | * This is the callback function to the lpfc heart-beat mailbox command. | |
995 | * If configured, the lpfc driver issues the heart-beat mailbox command to | |
996 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the | |
997 | * heart-beat mailbox command is issued, the driver shall set up heart-beat | |
998 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks | |
999 | * heart-beat outstanding state. Once the mailbox command comes back and | |
1000 | * no error conditions detected, the heart-beat mailbox command timer is | |
1001 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding | |
1002 | * state is cleared for the next heart-beat. If the timer expired with the | |
1003 | * heart-beat outstanding state set, the driver will put the HBA offline. | |
1004 | **/ | |
858c9f6c JS |
1005 | static void |
1006 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
1007 | { | |
1008 | unsigned long drvr_flag; | |
1009 | ||
1010 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
1011 | phba->hb_outstanding = 0; | |
1012 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
1013 | ||
9399627f | 1014 | /* Check and reset heart-beat timer is necessary */ |
858c9f6c JS |
1015 | mempool_free(pmboxq, phba->mbox_mem_pool); |
1016 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && | |
1017 | !(phba->link_state == LPFC_HBA_ERROR) && | |
51ef4c26 | 1018 | !(phba->pport->load_flag & FC_UNLOADING)) |
858c9f6c JS |
1019 | mod_timer(&phba->hb_tmofunc, |
1020 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
1021 | return; | |
1022 | } | |
1023 | ||
e59058c4 | 1024 | /** |
3621a710 | 1025 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
e59058c4 JS |
1026 | * @phba: pointer to lpfc hba data structure. |
1027 | * | |
1028 | * This is the actual HBA-timer timeout handler to be invoked by the worker | |
1029 | * thread whenever the HBA timer fired and HBA-timeout event posted. This | |
1030 | * handler performs any periodic operations needed for the device. If such | |
1031 | * periodic event has already been attended to either in the interrupt handler | |
1032 | * or by processing slow-ring or fast-ring events within the HBA-timer | |
1033 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets | |
1034 | * the timer for the next timeout period. If lpfc heart-beat mailbox command | |
1035 | * is configured and there is no heart-beat mailbox command outstanding, a | |
1036 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there | |
1037 | * has been a heart-beat mailbox command outstanding, the HBA shall be put | |
1038 | * to offline. | |
1039 | **/ | |
858c9f6c JS |
1040 | void |
1041 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) | |
1042 | { | |
45ed1190 | 1043 | struct lpfc_vport **vports; |
858c9f6c | 1044 | LPFC_MBOXQ_t *pmboxq; |
0ff10d46 | 1045 | struct lpfc_dmabuf *buf_ptr; |
45ed1190 | 1046 | int retval, i; |
858c9f6c | 1047 | struct lpfc_sli *psli = &phba->sli; |
0ff10d46 | 1048 | LIST_HEAD(completions); |
858c9f6c | 1049 | |
45ed1190 JS |
1050 | vports = lpfc_create_vport_work_array(phba); |
1051 | if (vports != NULL) | |
1052 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) | |
1053 | lpfc_rcv_seq_check_edtov(vports[i]); | |
1054 | lpfc_destroy_vport_work_array(phba, vports); | |
1055 | ||
858c9f6c | 1056 | if ((phba->link_state == LPFC_HBA_ERROR) || |
51ef4c26 | 1057 | (phba->pport->load_flag & FC_UNLOADING) || |
858c9f6c JS |
1058 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
1059 | return; | |
1060 | ||
1061 | spin_lock_irq(&phba->pport->work_port_lock); | |
858c9f6c JS |
1062 | |
1063 | if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, | |
1064 | jiffies)) { | |
1065 | spin_unlock_irq(&phba->pport->work_port_lock); | |
1066 | if (!phba->hb_outstanding) | |
1067 | mod_timer(&phba->hb_tmofunc, | |
1068 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
1069 | else | |
1070 | mod_timer(&phba->hb_tmofunc, | |
1071 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | |
1072 | return; | |
1073 | } | |
1074 | spin_unlock_irq(&phba->pport->work_port_lock); | |
1075 | ||
0ff10d46 JS |
1076 | if (phba->elsbuf_cnt && |
1077 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { | |
1078 | spin_lock_irq(&phba->hbalock); | |
1079 | list_splice_init(&phba->elsbuf, &completions); | |
1080 | phba->elsbuf_cnt = 0; | |
1081 | phba->elsbuf_prev_cnt = 0; | |
1082 | spin_unlock_irq(&phba->hbalock); | |
1083 | ||
1084 | while (!list_empty(&completions)) { | |
1085 | list_remove_head(&completions, buf_ptr, | |
1086 | struct lpfc_dmabuf, list); | |
1087 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
1088 | kfree(buf_ptr); | |
1089 | } | |
1090 | } | |
1091 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; | |
1092 | ||
858c9f6c | 1093 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
13815c83 JS |
1094 | if (phba->cfg_enable_hba_heartbeat) { |
1095 | if (!phba->hb_outstanding) { | |
bc73905a JS |
1096 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
1097 | (list_empty(&psli->mboxq))) { | |
1098 | pmboxq = mempool_alloc(phba->mbox_mem_pool, | |
1099 | GFP_KERNEL); | |
1100 | if (!pmboxq) { | |
1101 | mod_timer(&phba->hb_tmofunc, | |
1102 | jiffies + | |
1103 | HZ * LPFC_HB_MBOX_INTERVAL); | |
1104 | return; | |
1105 | } | |
1106 | ||
1107 | lpfc_heart_beat(phba, pmboxq); | |
1108 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; | |
1109 | pmboxq->vport = phba->pport; | |
1110 | retval = lpfc_sli_issue_mbox(phba, pmboxq, | |
1111 | MBX_NOWAIT); | |
1112 | ||
1113 | if (retval != MBX_BUSY && | |
1114 | retval != MBX_SUCCESS) { | |
1115 | mempool_free(pmboxq, | |
1116 | phba->mbox_mem_pool); | |
1117 | mod_timer(&phba->hb_tmofunc, | |
1118 | jiffies + | |
1119 | HZ * LPFC_HB_MBOX_INTERVAL); | |
1120 | return; | |
1121 | } | |
1122 | phba->skipped_hb = 0; | |
1123 | phba->hb_outstanding = 1; | |
1124 | } else if (time_before_eq(phba->last_completion_time, | |
1125 | phba->skipped_hb)) { | |
1126 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
1127 | "2857 Last completion time not " | |
1128 | " updated in %d ms\n", | |
1129 | jiffies_to_msecs(jiffies | |
1130 | - phba->last_completion_time)); | |
1131 | } else | |
1132 | phba->skipped_hb = jiffies; | |
1133 | ||
858c9f6c | 1134 | mod_timer(&phba->hb_tmofunc, |
13815c83 | 1135 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
858c9f6c | 1136 | return; |
13815c83 JS |
1137 | } else { |
1138 | /* | |
1139 | * If heart beat timeout called with hb_outstanding set | |
dcf2a4e0 JS |
1140 | * we need to give the hb mailbox cmd a chance to |
1141 | * complete or TMO. | |
13815c83 | 1142 | */ |
dcf2a4e0 JS |
1143 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
1144 | "0459 Adapter heartbeat still out" | |
1145 | "standing:last compl time was %d ms.\n", | |
1146 | jiffies_to_msecs(jiffies | |
1147 | - phba->last_completion_time)); | |
1148 | mod_timer(&phba->hb_tmofunc, | |
1149 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | |
858c9f6c | 1150 | } |
858c9f6c JS |
1151 | } |
1152 | } | |
1153 | ||
e59058c4 | 1154 | /** |
3621a710 | 1155 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
e59058c4 JS |
1156 | * @phba: pointer to lpfc hba data structure. |
1157 | * | |
1158 | * This routine is called to bring the HBA offline when HBA hardware error | |
1159 | * other than Port Error 6 has been detected. | |
1160 | **/ | |
09372820 JS |
1161 | static void |
1162 | lpfc_offline_eratt(struct lpfc_hba *phba) | |
1163 | { | |
1164 | struct lpfc_sli *psli = &phba->sli; | |
1165 | ||
1166 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1167 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
09372820 JS |
1168 | spin_unlock_irq(&phba->hbalock); |
1169 | lpfc_offline_prep(phba); | |
1170 | ||
1171 | lpfc_offline(phba); | |
1172 | lpfc_reset_barrier(phba); | |
f4b4c68f | 1173 | spin_lock_irq(&phba->hbalock); |
09372820 | 1174 | lpfc_sli_brdreset(phba); |
f4b4c68f | 1175 | spin_unlock_irq(&phba->hbalock); |
09372820 JS |
1176 | lpfc_hba_down_post(phba); |
1177 | lpfc_sli_brdready(phba, HS_MBRDY); | |
1178 | lpfc_unblock_mgmt_io(phba); | |
1179 | phba->link_state = LPFC_HBA_ERROR; | |
1180 | return; | |
1181 | } | |
1182 | ||
da0436e9 JS |
1183 | /** |
1184 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention | |
1185 | * @phba: pointer to lpfc hba data structure. | |
1186 | * | |
1187 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error | |
1188 | * other than Port Error 6 has been detected. | |
1189 | **/ | |
1190 | static void | |
1191 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) | |
1192 | { | |
1193 | lpfc_offline_prep(phba); | |
1194 | lpfc_offline(phba); | |
1195 | lpfc_sli4_brdreset(phba); | |
1196 | lpfc_hba_down_post(phba); | |
1197 | lpfc_sli4_post_status_check(phba); | |
1198 | lpfc_unblock_mgmt_io(phba); | |
1199 | phba->link_state = LPFC_HBA_ERROR; | |
1200 | } | |
1201 | ||
a257bf90 JS |
1202 | /** |
1203 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler | |
1204 | * @phba: pointer to lpfc hba data structure. | |
1205 | * | |
1206 | * This routine is invoked to handle the deferred HBA hardware error | |
1207 | * conditions. This type of error is indicated by HBA by setting ER1 | |
1208 | * and another ER bit in the host status register. The driver will | |
1209 | * wait until the ER1 bit clears before handling the error condition. | |
1210 | **/ | |
1211 | static void | |
1212 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) | |
1213 | { | |
1214 | uint32_t old_host_status = phba->work_hs; | |
1215 | struct lpfc_sli_ring *pring; | |
1216 | struct lpfc_sli *psli = &phba->sli; | |
1217 | ||
f4b4c68f JS |
1218 | /* If the pci channel is offline, ignore possible errors, |
1219 | * since we cannot communicate with the pci card anyway. | |
1220 | */ | |
1221 | if (pci_channel_offline(phba->pcidev)) { | |
1222 | spin_lock_irq(&phba->hbalock); | |
1223 | phba->hba_flag &= ~DEFER_ERATT; | |
1224 | spin_unlock_irq(&phba->hbalock); | |
1225 | return; | |
1226 | } | |
1227 | ||
a257bf90 JS |
1228 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
1229 | "0479 Deferred Adapter Hardware Error " | |
1230 | "Data: x%x x%x x%x\n", | |
1231 | phba->work_hs, | |
1232 | phba->work_status[0], phba->work_status[1]); | |
1233 | ||
1234 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1235 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
a257bf90 JS |
1236 | spin_unlock_irq(&phba->hbalock); |
1237 | ||
1238 | ||
1239 | /* | |
1240 | * Firmware stops when it triggred erratt. That could cause the I/Os | |
1241 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the | |
1242 | * SCSI layer retry it after re-establishing link. | |
1243 | */ | |
1244 | pring = &psli->ring[psli->fcp_ring]; | |
1245 | lpfc_sli_abort_iocb_ring(phba, pring); | |
1246 | ||
1247 | /* | |
1248 | * There was a firmware error. Take the hba offline and then | |
1249 | * attempt to restart it. | |
1250 | */ | |
1251 | lpfc_offline_prep(phba); | |
1252 | lpfc_offline(phba); | |
1253 | ||
1254 | /* Wait for the ER1 bit to clear.*/ | |
1255 | while (phba->work_hs & HS_FFER1) { | |
1256 | msleep(100); | |
9940b97b JS |
1257 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
1258 | phba->work_hs = UNPLUG_ERR ; | |
1259 | break; | |
1260 | } | |
a257bf90 JS |
1261 | /* If driver is unloading let the worker thread continue */ |
1262 | if (phba->pport->load_flag & FC_UNLOADING) { | |
1263 | phba->work_hs = 0; | |
1264 | break; | |
1265 | } | |
1266 | } | |
1267 | ||
1268 | /* | |
1269 | * This is to ptrotect against a race condition in which | |
1270 | * first write to the host attention register clear the | |
1271 | * host status register. | |
1272 | */ | |
1273 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) | |
1274 | phba->work_hs = old_host_status & ~HS_FFER1; | |
1275 | ||
3772a991 | 1276 | spin_lock_irq(&phba->hbalock); |
a257bf90 | 1277 | phba->hba_flag &= ~DEFER_ERATT; |
3772a991 | 1278 | spin_unlock_irq(&phba->hbalock); |
a257bf90 JS |
1279 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
1280 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); | |
1281 | } | |
1282 | ||
3772a991 JS |
1283 | static void |
1284 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) | |
1285 | { | |
1286 | struct lpfc_board_event_header board_event; | |
1287 | struct Scsi_Host *shost; | |
1288 | ||
1289 | board_event.event_type = FC_REG_BOARD_EVENT; | |
1290 | board_event.subcategory = LPFC_EVENT_PORTINTERR; | |
1291 | shost = lpfc_shost_from_vport(phba->pport); | |
1292 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1293 | sizeof(board_event), | |
1294 | (char *) &board_event, | |
1295 | LPFC_NL_VENDOR_ID); | |
1296 | } | |
1297 | ||
e59058c4 | 1298 | /** |
3772a991 | 1299 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
e59058c4 JS |
1300 | * @phba: pointer to lpfc hba data structure. |
1301 | * | |
1302 | * This routine is invoked to handle the following HBA hardware error | |
1303 | * conditions: | |
1304 | * 1 - HBA error attention interrupt | |
1305 | * 2 - DMA ring index out of range | |
1306 | * 3 - Mailbox command came back as unknown | |
1307 | **/ | |
3772a991 JS |
1308 | static void |
1309 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) | |
dea3101e | 1310 | { |
2e0fef85 | 1311 | struct lpfc_vport *vport = phba->pport; |
2e0fef85 | 1312 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 1313 | struct lpfc_sli_ring *pring; |
d2873e4c | 1314 | uint32_t event_data; |
57127f15 JS |
1315 | unsigned long temperature; |
1316 | struct temp_event temp_event_data; | |
92d7f7b0 | 1317 | struct Scsi_Host *shost; |
2e0fef85 | 1318 | |
8d63f375 | 1319 | /* If the pci channel is offline, ignore possible errors, |
3772a991 JS |
1320 | * since we cannot communicate with the pci card anyway. |
1321 | */ | |
1322 | if (pci_channel_offline(phba->pcidev)) { | |
1323 | spin_lock_irq(&phba->hbalock); | |
1324 | phba->hba_flag &= ~DEFER_ERATT; | |
1325 | spin_unlock_irq(&phba->hbalock); | |
8d63f375 | 1326 | return; |
3772a991 JS |
1327 | } |
1328 | ||
13815c83 JS |
1329 | /* If resets are disabled then leave the HBA alone and return */ |
1330 | if (!phba->cfg_enable_hba_reset) | |
1331 | return; | |
dea3101e | 1332 | |
ea2151b4 | 1333 | /* Send an internal error event to mgmt application */ |
3772a991 | 1334 | lpfc_board_errevt_to_mgmt(phba); |
ea2151b4 | 1335 | |
a257bf90 JS |
1336 | if (phba->hba_flag & DEFER_ERATT) |
1337 | lpfc_handle_deferred_eratt(phba); | |
1338 | ||
dcf2a4e0 JS |
1339 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
1340 | if (phba->work_hs & HS_FFER6) | |
1341 | /* Re-establishing Link */ | |
1342 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
1343 | "1301 Re-establishing Link " | |
1344 | "Data: x%x x%x x%x\n", | |
1345 | phba->work_hs, phba->work_status[0], | |
1346 | phba->work_status[1]); | |
1347 | if (phba->work_hs & HS_FFER8) | |
1348 | /* Device Zeroization */ | |
1349 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
1350 | "2861 Host Authentication device " | |
1351 | "zeroization Data:x%x x%x x%x\n", | |
1352 | phba->work_hs, phba->work_status[0], | |
1353 | phba->work_status[1]); | |
58da1ffb | 1354 | |
92d7f7b0 | 1355 | spin_lock_irq(&phba->hbalock); |
f4b4c68f | 1356 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
92d7f7b0 | 1357 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1358 | |
1359 | /* | |
1360 | * Firmware stops when it triggled erratt with HS_FFER6. | |
1361 | * That could cause the I/Os dropped by the firmware. | |
1362 | * Error iocb (I/O) on txcmplq and let the SCSI layer | |
1363 | * retry it after re-establishing link. | |
1364 | */ | |
1365 | pring = &psli->ring[psli->fcp_ring]; | |
1366 | lpfc_sli_abort_iocb_ring(phba, pring); | |
1367 | ||
dea3101e JB |
1368 | /* |
1369 | * There was a firmware error. Take the hba offline and then | |
1370 | * attempt to restart it. | |
1371 | */ | |
46fa311e | 1372 | lpfc_offline_prep(phba); |
dea3101e | 1373 | lpfc_offline(phba); |
41415862 | 1374 | lpfc_sli_brdrestart(phba); |
dea3101e | 1375 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
46fa311e | 1376 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
1377 | return; |
1378 | } | |
46fa311e | 1379 | lpfc_unblock_mgmt_io(phba); |
57127f15 JS |
1380 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
1381 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); | |
1382 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
1383 | temp_event_data.event_code = LPFC_CRIT_TEMP; | |
1384 | temp_event_data.data = (uint32_t)temperature; | |
1385 | ||
1386 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 1387 | "0406 Adapter maximum temperature exceeded " |
57127f15 JS |
1388 | "(%ld), taking this port offline " |
1389 | "Data: x%x x%x x%x\n", | |
1390 | temperature, phba->work_hs, | |
1391 | phba->work_status[0], phba->work_status[1]); | |
1392 | ||
1393 | shost = lpfc_shost_from_vport(phba->pport); | |
1394 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1395 | sizeof(temp_event_data), | |
1396 | (char *) &temp_event_data, | |
1397 | SCSI_NL_VID_TYPE_PCI | |
1398 | | PCI_VENDOR_ID_EMULEX); | |
1399 | ||
7af67051 | 1400 | spin_lock_irq(&phba->hbalock); |
7af67051 JS |
1401 | phba->over_temp_state = HBA_OVER_TEMP; |
1402 | spin_unlock_irq(&phba->hbalock); | |
09372820 | 1403 | lpfc_offline_eratt(phba); |
57127f15 | 1404 | |
dea3101e JB |
1405 | } else { |
1406 | /* The if clause above forces this code path when the status | |
9399627f JS |
1407 | * failure is a value other than FFER6. Do not call the offline |
1408 | * twice. This is the adapter hardware error path. | |
dea3101e JB |
1409 | */ |
1410 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 | 1411 | "0457 Adapter Hardware Error " |
dea3101e | 1412 | "Data: x%x x%x x%x\n", |
e8b62011 | 1413 | phba->work_hs, |
dea3101e JB |
1414 | phba->work_status[0], phba->work_status[1]); |
1415 | ||
d2873e4c | 1416 | event_data = FC_REG_DUMP_EVENT; |
92d7f7b0 | 1417 | shost = lpfc_shost_from_vport(vport); |
2e0fef85 | 1418 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
d2873e4c JS |
1419 | sizeof(event_data), (char *) &event_data, |
1420 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
1421 | ||
09372820 | 1422 | lpfc_offline_eratt(phba); |
dea3101e | 1423 | } |
9399627f | 1424 | return; |
dea3101e JB |
1425 | } |
1426 | ||
da0436e9 JS |
1427 | /** |
1428 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler | |
1429 | * @phba: pointer to lpfc hba data structure. | |
1430 | * | |
1431 | * This routine is invoked to handle the SLI4 HBA hardware error attention | |
1432 | * conditions. | |
1433 | **/ | |
1434 | static void | |
1435 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) | |
1436 | { | |
1437 | struct lpfc_vport *vport = phba->pport; | |
1438 | uint32_t event_data; | |
1439 | struct Scsi_Host *shost; | |
2fcee4bf JS |
1440 | uint32_t if_type; |
1441 | struct lpfc_register portstat_reg; | |
da0436e9 JS |
1442 | |
1443 | /* If the pci channel is offline, ignore possible errors, since | |
1444 | * we cannot communicate with the pci card anyway. | |
1445 | */ | |
1446 | if (pci_channel_offline(phba->pcidev)) | |
1447 | return; | |
1448 | /* If resets are disabled then leave the HBA alone and return */ | |
1449 | if (!phba->cfg_enable_hba_reset) | |
1450 | return; | |
1451 | ||
1452 | /* Send an internal error event to mgmt application */ | |
1453 | lpfc_board_errevt_to_mgmt(phba); | |
1454 | ||
1455 | /* For now, the actual action for SLI4 device handling is not | |
1456 | * specified yet, just treated it as adaptor hardware failure | |
1457 | */ | |
da0436e9 JS |
1458 | event_data = FC_REG_DUMP_EVENT; |
1459 | shost = lpfc_shost_from_vport(vport); | |
1460 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1461 | sizeof(event_data), (char *) &event_data, | |
1462 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
1463 | ||
2fcee4bf JS |
1464 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
1465 | switch (if_type) { | |
1466 | case LPFC_SLI_INTF_IF_TYPE_0: | |
1467 | lpfc_sli4_offline_eratt(phba); | |
1468 | break; | |
1469 | case LPFC_SLI_INTF_IF_TYPE_2: | |
1470 | portstat_reg.word0 = | |
1471 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr); | |
1472 | ||
1473 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { | |
1474 | /* TODO: Register for Overtemp async events. */ | |
1475 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1476 | "2889 Port Overtemperature event, " | |
1477 | "taking port\n"); | |
1478 | spin_lock_irq(&phba->hbalock); | |
1479 | phba->over_temp_state = HBA_OVER_TEMP; | |
1480 | spin_unlock_irq(&phba->hbalock); | |
1481 | lpfc_sli4_offline_eratt(phba); | |
1482 | return; | |
1483 | } | |
1484 | if (bf_get(lpfc_sliport_status_rn, &portstat_reg)) { | |
1485 | /* | |
1486 | * TODO: Attempt port recovery via a port reset. | |
1487 | * When fully implemented, the driver should | |
1488 | * attempt to recover the port here and return. | |
1489 | * For now, log an error and take the port offline. | |
1490 | */ | |
1491 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1492 | "2887 Port Error: Attempting " | |
1493 | "Port Recovery\n"); | |
1494 | } | |
1495 | lpfc_sli4_offline_eratt(phba); | |
1496 | break; | |
1497 | case LPFC_SLI_INTF_IF_TYPE_1: | |
1498 | default: | |
1499 | break; | |
1500 | } | |
da0436e9 JS |
1501 | } |
1502 | ||
1503 | /** | |
1504 | * lpfc_handle_eratt - Wrapper func for handling hba error attention | |
1505 | * @phba: pointer to lpfc HBA data structure. | |
1506 | * | |
1507 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling | |
1508 | * routine from the API jump table function pointer from the lpfc_hba struct. | |
1509 | * | |
1510 | * Return codes | |
af901ca1 | 1511 | * 0 - success. |
da0436e9 JS |
1512 | * Any other value - error. |
1513 | **/ | |
1514 | void | |
1515 | lpfc_handle_eratt(struct lpfc_hba *phba) | |
1516 | { | |
1517 | (*phba->lpfc_handle_eratt)(phba); | |
1518 | } | |
1519 | ||
e59058c4 | 1520 | /** |
3621a710 | 1521 | * lpfc_handle_latt - The HBA link event handler |
e59058c4 JS |
1522 | * @phba: pointer to lpfc hba data structure. |
1523 | * | |
1524 | * This routine is invoked from the worker thread to handle a HBA host | |
1525 | * attention link event. | |
1526 | **/ | |
dea3101e | 1527 | void |
2e0fef85 | 1528 | lpfc_handle_latt(struct lpfc_hba *phba) |
dea3101e | 1529 | { |
2e0fef85 JS |
1530 | struct lpfc_vport *vport = phba->pport; |
1531 | struct lpfc_sli *psli = &phba->sli; | |
dea3101e JB |
1532 | LPFC_MBOXQ_t *pmb; |
1533 | volatile uint32_t control; | |
1534 | struct lpfc_dmabuf *mp; | |
09372820 | 1535 | int rc = 0; |
dea3101e JB |
1536 | |
1537 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
09372820 JS |
1538 | if (!pmb) { |
1539 | rc = 1; | |
dea3101e | 1540 | goto lpfc_handle_latt_err_exit; |
09372820 | 1541 | } |
dea3101e JB |
1542 | |
1543 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
09372820 JS |
1544 | if (!mp) { |
1545 | rc = 2; | |
dea3101e | 1546 | goto lpfc_handle_latt_free_pmb; |
09372820 | 1547 | } |
dea3101e JB |
1548 | |
1549 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
09372820 JS |
1550 | if (!mp->virt) { |
1551 | rc = 3; | |
dea3101e | 1552 | goto lpfc_handle_latt_free_mp; |
09372820 | 1553 | } |
dea3101e | 1554 | |
6281bfe0 | 1555 | /* Cleanup any outstanding ELS commands */ |
549e55cd | 1556 | lpfc_els_flush_all_cmd(phba); |
dea3101e JB |
1557 | |
1558 | psli->slistat.link_event++; | |
76a95d75 JS |
1559 | lpfc_read_topology(phba, pmb, mp); |
1560 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
2e0fef85 | 1561 | pmb->vport = vport; |
0d2b6b83 JS |
1562 | /* Block ELS IOCBs until we have processed this mbox command */ |
1563 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
0b727fea | 1564 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
09372820 JS |
1565 | if (rc == MBX_NOT_FINISHED) { |
1566 | rc = 4; | |
14691150 | 1567 | goto lpfc_handle_latt_free_mbuf; |
09372820 | 1568 | } |
dea3101e JB |
1569 | |
1570 | /* Clear Link Attention in HA REG */ | |
2e0fef85 | 1571 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1572 | writel(HA_LATT, phba->HAregaddr); |
1573 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1574 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1575 | |
1576 | return; | |
1577 | ||
14691150 | 1578 | lpfc_handle_latt_free_mbuf: |
0d2b6b83 | 1579 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
14691150 | 1580 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
dea3101e JB |
1581 | lpfc_handle_latt_free_mp: |
1582 | kfree(mp); | |
1583 | lpfc_handle_latt_free_pmb: | |
1dcb58e5 | 1584 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e JB |
1585 | lpfc_handle_latt_err_exit: |
1586 | /* Enable Link attention interrupts */ | |
2e0fef85 | 1587 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1588 | psli->sli_flag |= LPFC_PROCESS_LA; |
1589 | control = readl(phba->HCregaddr); | |
1590 | control |= HC_LAINT_ENA; | |
1591 | writel(control, phba->HCregaddr); | |
1592 | readl(phba->HCregaddr); /* flush */ | |
1593 | ||
1594 | /* Clear Link Attention in HA REG */ | |
1595 | writel(HA_LATT, phba->HAregaddr); | |
1596 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1597 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1598 | lpfc_linkdown(phba); |
2e0fef85 | 1599 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 1600 | |
09372820 JS |
1601 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
1602 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); | |
dea3101e JB |
1603 | |
1604 | return; | |
1605 | } | |
1606 | ||
e59058c4 | 1607 | /** |
3621a710 | 1608 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
e59058c4 JS |
1609 | * @phba: pointer to lpfc hba data structure. |
1610 | * @vpd: pointer to the vital product data. | |
1611 | * @len: length of the vital product data in bytes. | |
1612 | * | |
1613 | * This routine parses the Vital Product Data (VPD). The VPD is treated as | |
1614 | * an array of characters. In this routine, the ModelName, ProgramType, and | |
1615 | * ModelDesc, etc. fields of the phba data structure will be populated. | |
1616 | * | |
1617 | * Return codes | |
1618 | * 0 - pointer to the VPD passed in is NULL | |
1619 | * 1 - success | |
1620 | **/ | |
3772a991 | 1621 | int |
2e0fef85 | 1622 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
dea3101e JB |
1623 | { |
1624 | uint8_t lenlo, lenhi; | |
07da60c1 | 1625 | int Length; |
dea3101e JB |
1626 | int i, j; |
1627 | int finished = 0; | |
1628 | int index = 0; | |
1629 | ||
1630 | if (!vpd) | |
1631 | return 0; | |
1632 | ||
1633 | /* Vital Product */ | |
ed957684 | 1634 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
e8b62011 | 1635 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
dea3101e JB |
1636 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
1637 | (uint32_t) vpd[3]); | |
74b72a59 | 1638 | while (!finished && (index < (len - 4))) { |
dea3101e JB |
1639 | switch (vpd[index]) { |
1640 | case 0x82: | |
74b72a59 | 1641 | case 0x91: |
dea3101e JB |
1642 | index += 1; |
1643 | lenlo = vpd[index]; | |
1644 | index += 1; | |
1645 | lenhi = vpd[index]; | |
1646 | index += 1; | |
1647 | i = ((((unsigned short)lenhi) << 8) + lenlo); | |
1648 | index += i; | |
1649 | break; | |
1650 | case 0x90: | |
1651 | index += 1; | |
1652 | lenlo = vpd[index]; | |
1653 | index += 1; | |
1654 | lenhi = vpd[index]; | |
1655 | index += 1; | |
1656 | Length = ((((unsigned short)lenhi) << 8) + lenlo); | |
74b72a59 JW |
1657 | if (Length > len - index) |
1658 | Length = len - index; | |
dea3101e JB |
1659 | while (Length > 0) { |
1660 | /* Look for Serial Number */ | |
1661 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { | |
1662 | index += 2; | |
1663 | i = vpd[index]; | |
1664 | index += 1; | |
1665 | j = 0; | |
1666 | Length -= (3+i); | |
1667 | while(i--) { | |
1668 | phba->SerialNumber[j++] = vpd[index++]; | |
1669 | if (j == 31) | |
1670 | break; | |
1671 | } | |
1672 | phba->SerialNumber[j] = 0; | |
1673 | continue; | |
1674 | } | |
1675 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { | |
1676 | phba->vpd_flag |= VPD_MODEL_DESC; | |
1677 | index += 2; | |
1678 | i = vpd[index]; | |
1679 | index += 1; | |
1680 | j = 0; | |
1681 | Length -= (3+i); | |
1682 | while(i--) { | |
1683 | phba->ModelDesc[j++] = vpd[index++]; | |
1684 | if (j == 255) | |
1685 | break; | |
1686 | } | |
1687 | phba->ModelDesc[j] = 0; | |
1688 | continue; | |
1689 | } | |
1690 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { | |
1691 | phba->vpd_flag |= VPD_MODEL_NAME; | |
1692 | index += 2; | |
1693 | i = vpd[index]; | |
1694 | index += 1; | |
1695 | j = 0; | |
1696 | Length -= (3+i); | |
1697 | while(i--) { | |
1698 | phba->ModelName[j++] = vpd[index++]; | |
1699 | if (j == 79) | |
1700 | break; | |
1701 | } | |
1702 | phba->ModelName[j] = 0; | |
1703 | continue; | |
1704 | } | |
1705 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { | |
1706 | phba->vpd_flag |= VPD_PROGRAM_TYPE; | |
1707 | index += 2; | |
1708 | i = vpd[index]; | |
1709 | index += 1; | |
1710 | j = 0; | |
1711 | Length -= (3+i); | |
1712 | while(i--) { | |
1713 | phba->ProgramType[j++] = vpd[index++]; | |
1714 | if (j == 255) | |
1715 | break; | |
1716 | } | |
1717 | phba->ProgramType[j] = 0; | |
1718 | continue; | |
1719 | } | |
1720 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { | |
1721 | phba->vpd_flag |= VPD_PORT; | |
1722 | index += 2; | |
1723 | i = vpd[index]; | |
1724 | index += 1; | |
1725 | j = 0; | |
1726 | Length -= (3+i); | |
1727 | while(i--) { | |
1728 | phba->Port[j++] = vpd[index++]; | |
1729 | if (j == 19) | |
1730 | break; | |
1731 | } | |
1732 | phba->Port[j] = 0; | |
1733 | continue; | |
1734 | } | |
1735 | else { | |
1736 | index += 2; | |
1737 | i = vpd[index]; | |
1738 | index += 1; | |
1739 | index += i; | |
1740 | Length -= (3 + i); | |
1741 | } | |
1742 | } | |
1743 | finished = 0; | |
1744 | break; | |
1745 | case 0x78: | |
1746 | finished = 1; | |
1747 | break; | |
1748 | default: | |
1749 | index ++; | |
1750 | break; | |
1751 | } | |
74b72a59 | 1752 | } |
dea3101e JB |
1753 | |
1754 | return(1); | |
1755 | } | |
1756 | ||
e59058c4 | 1757 | /** |
3621a710 | 1758 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
e59058c4 JS |
1759 | * @phba: pointer to lpfc hba data structure. |
1760 | * @mdp: pointer to the data structure to hold the derived model name. | |
1761 | * @descp: pointer to the data structure to hold the derived description. | |
1762 | * | |
1763 | * This routine retrieves HBA's description based on its registered PCI device | |
1764 | * ID. The @descp passed into this function points to an array of 256 chars. It | |
1765 | * shall be returned with the model name, maximum speed, and the host bus type. | |
1766 | * The @mdp passed into this function points to an array of 80 chars. When the | |
1767 | * function returns, the @mdp will be filled with the model name. | |
1768 | **/ | |
dea3101e | 1769 | static void |
2e0fef85 | 1770 | lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) |
dea3101e JB |
1771 | { |
1772 | lpfc_vpd_t *vp; | |
fefcb2b6 | 1773 | uint16_t dev_id = phba->pcidev->device; |
74b72a59 | 1774 | int max_speed; |
84774a4d | 1775 | int GE = 0; |
da0436e9 | 1776 | int oneConnect = 0; /* default is not a oneConnect */ |
74b72a59 | 1777 | struct { |
a747c9ce JS |
1778 | char *name; |
1779 | char *bus; | |
1780 | char *function; | |
1781 | } m = {"<Unknown>", "", ""}; | |
74b72a59 JW |
1782 | |
1783 | if (mdp && mdp[0] != '\0' | |
1784 | && descp && descp[0] != '\0') | |
1785 | return; | |
1786 | ||
1787 | if (phba->lmt & LMT_10Gb) | |
1788 | max_speed = 10; | |
1789 | else if (phba->lmt & LMT_8Gb) | |
1790 | max_speed = 8; | |
1791 | else if (phba->lmt & LMT_4Gb) | |
1792 | max_speed = 4; | |
1793 | else if (phba->lmt & LMT_2Gb) | |
1794 | max_speed = 2; | |
1795 | else | |
1796 | max_speed = 1; | |
dea3101e JB |
1797 | |
1798 | vp = &phba->vpd; | |
dea3101e | 1799 | |
e4adb204 | 1800 | switch (dev_id) { |
06325e74 | 1801 | case PCI_DEVICE_ID_FIREFLY: |
a747c9ce | 1802 | m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"}; |
06325e74 | 1803 | break; |
dea3101e JB |
1804 | case PCI_DEVICE_ID_SUPERFLY: |
1805 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) | |
a747c9ce JS |
1806 | m = (typeof(m)){"LP7000", "PCI", |
1807 | "Fibre Channel Adapter"}; | |
dea3101e | 1808 | else |
a747c9ce JS |
1809 | m = (typeof(m)){"LP7000E", "PCI", |
1810 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1811 | break; |
1812 | case PCI_DEVICE_ID_DRAGONFLY: | |
a747c9ce JS |
1813 | m = (typeof(m)){"LP8000", "PCI", |
1814 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1815 | break; |
1816 | case PCI_DEVICE_ID_CENTAUR: | |
1817 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) | |
a747c9ce JS |
1818 | m = (typeof(m)){"LP9002", "PCI", |
1819 | "Fibre Channel Adapter"}; | |
dea3101e | 1820 | else |
a747c9ce JS |
1821 | m = (typeof(m)){"LP9000", "PCI", |
1822 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1823 | break; |
1824 | case PCI_DEVICE_ID_RFLY: | |
a747c9ce JS |
1825 | m = (typeof(m)){"LP952", "PCI", |
1826 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1827 | break; |
1828 | case PCI_DEVICE_ID_PEGASUS: | |
a747c9ce JS |
1829 | m = (typeof(m)){"LP9802", "PCI-X", |
1830 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1831 | break; |
1832 | case PCI_DEVICE_ID_THOR: | |
a747c9ce JS |
1833 | m = (typeof(m)){"LP10000", "PCI-X", |
1834 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1835 | break; |
1836 | case PCI_DEVICE_ID_VIPER: | |
a747c9ce JS |
1837 | m = (typeof(m)){"LPX1000", "PCI-X", |
1838 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1839 | break; |
1840 | case PCI_DEVICE_ID_PFLY: | |
a747c9ce JS |
1841 | m = (typeof(m)){"LP982", "PCI-X", |
1842 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1843 | break; |
1844 | case PCI_DEVICE_ID_TFLY: | |
a747c9ce JS |
1845 | m = (typeof(m)){"LP1050", "PCI-X", |
1846 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1847 | break; |
1848 | case PCI_DEVICE_ID_HELIOS: | |
a747c9ce JS |
1849 | m = (typeof(m)){"LP11000", "PCI-X2", |
1850 | "Fibre Channel Adapter"}; | |
dea3101e | 1851 | break; |
e4adb204 | 1852 | case PCI_DEVICE_ID_HELIOS_SCSP: |
a747c9ce JS |
1853 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
1854 | "Fibre Channel Adapter"}; | |
e4adb204 JSEC |
1855 | break; |
1856 | case PCI_DEVICE_ID_HELIOS_DCSP: | |
a747c9ce JS |
1857 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
1858 | "Fibre Channel Adapter"}; | |
e4adb204 JSEC |
1859 | break; |
1860 | case PCI_DEVICE_ID_NEPTUNE: | |
a747c9ce | 1861 | m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1862 | break; |
1863 | case PCI_DEVICE_ID_NEPTUNE_SCSP: | |
a747c9ce | 1864 | m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1865 | break; |
1866 | case PCI_DEVICE_ID_NEPTUNE_DCSP: | |
a747c9ce | 1867 | m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 | 1868 | break; |
dea3101e | 1869 | case PCI_DEVICE_ID_BMID: |
a747c9ce | 1870 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
dea3101e JB |
1871 | break; |
1872 | case PCI_DEVICE_ID_BSMB: | |
a747c9ce | 1873 | m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"}; |
dea3101e JB |
1874 | break; |
1875 | case PCI_DEVICE_ID_ZEPHYR: | |
a747c9ce | 1876 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
dea3101e | 1877 | break; |
e4adb204 | 1878 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
a747c9ce | 1879 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1880 | break; |
1881 | case PCI_DEVICE_ID_ZEPHYR_DCSP: | |
a747c9ce | 1882 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
a257bf90 | 1883 | GE = 1; |
e4adb204 | 1884 | break; |
dea3101e | 1885 | case PCI_DEVICE_ID_ZMID: |
a747c9ce | 1886 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
dea3101e JB |
1887 | break; |
1888 | case PCI_DEVICE_ID_ZSMB: | |
a747c9ce | 1889 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
dea3101e JB |
1890 | break; |
1891 | case PCI_DEVICE_ID_LP101: | |
a747c9ce | 1892 | m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"}; |
dea3101e JB |
1893 | break; |
1894 | case PCI_DEVICE_ID_LP10000S: | |
a747c9ce | 1895 | m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"}; |
06325e74 | 1896 | break; |
e4adb204 | 1897 | case PCI_DEVICE_ID_LP11000S: |
a747c9ce | 1898 | m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"}; |
18a3b596 | 1899 | break; |
e4adb204 | 1900 | case PCI_DEVICE_ID_LPE11000S: |
a747c9ce | 1901 | m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"}; |
5cc36b3c | 1902 | break; |
b87eab38 | 1903 | case PCI_DEVICE_ID_SAT: |
a747c9ce | 1904 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1905 | break; |
1906 | case PCI_DEVICE_ID_SAT_MID: | |
a747c9ce | 1907 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1908 | break; |
1909 | case PCI_DEVICE_ID_SAT_SMB: | |
a747c9ce | 1910 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1911 | break; |
1912 | case PCI_DEVICE_ID_SAT_DCSP: | |
a747c9ce | 1913 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1914 | break; |
1915 | case PCI_DEVICE_ID_SAT_SCSP: | |
a747c9ce | 1916 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1917 | break; |
1918 | case PCI_DEVICE_ID_SAT_S: | |
a747c9ce | 1919 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 | 1920 | break; |
84774a4d | 1921 | case PCI_DEVICE_ID_HORNET: |
a747c9ce | 1922 | m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"}; |
84774a4d JS |
1923 | GE = 1; |
1924 | break; | |
1925 | case PCI_DEVICE_ID_PROTEUS_VF: | |
a747c9ce JS |
1926 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
1927 | "Fibre Channel Adapter"}; | |
84774a4d JS |
1928 | break; |
1929 | case PCI_DEVICE_ID_PROTEUS_PF: | |
a747c9ce JS |
1930 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
1931 | "Fibre Channel Adapter"}; | |
84774a4d JS |
1932 | break; |
1933 | case PCI_DEVICE_ID_PROTEUS_S: | |
a747c9ce JS |
1934 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
1935 | "Fibre Channel Adapter"}; | |
84774a4d | 1936 | break; |
da0436e9 JS |
1937 | case PCI_DEVICE_ID_TIGERSHARK: |
1938 | oneConnect = 1; | |
a747c9ce | 1939 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
da0436e9 | 1940 | break; |
a747c9ce | 1941 | case PCI_DEVICE_ID_TOMCAT: |
6669f9bb | 1942 | oneConnect = 1; |
a747c9ce JS |
1943 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
1944 | break; | |
1945 | case PCI_DEVICE_ID_FALCON: | |
1946 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", | |
1947 | "EmulexSecure Fibre"}; | |
6669f9bb | 1948 | break; |
98fc5dd9 JS |
1949 | case PCI_DEVICE_ID_BALIUS: |
1950 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", | |
1951 | "Fibre Channel Adapter"}; | |
1952 | break; | |
085c647c JS |
1953 | case PCI_DEVICE_ID_LANCER_FC: |
1954 | oneConnect = 1; | |
1955 | m = (typeof(m)){"Undefined", "PCIe", "Fibre Channel Adapter"}; | |
1956 | break; | |
1957 | case PCI_DEVICE_ID_LANCER_FCOE: | |
1958 | oneConnect = 1; | |
1959 | m = (typeof(m)){"Undefined", "PCIe", "FCoE"}; | |
1960 | break; | |
5cc36b3c | 1961 | default: |
a747c9ce | 1962 | m = (typeof(m)){"Unknown", "", ""}; |
e4adb204 | 1963 | break; |
dea3101e | 1964 | } |
74b72a59 JW |
1965 | |
1966 | if (mdp && mdp[0] == '\0') | |
1967 | snprintf(mdp, 79,"%s", m.name); | |
da0436e9 JS |
1968 | /* oneConnect hba requires special processing, they are all initiators |
1969 | * and we put the port number on the end | |
1970 | */ | |
1971 | if (descp && descp[0] == '\0') { | |
1972 | if (oneConnect) | |
1973 | snprintf(descp, 255, | |
a747c9ce JS |
1974 | "Emulex OneConnect %s, %s Initiator, Port %s", |
1975 | m.name, m.function, | |
da0436e9 JS |
1976 | phba->Port); |
1977 | else | |
1978 | snprintf(descp, 255, | |
1979 | "Emulex %s %d%s %s %s", | |
a747c9ce JS |
1980 | m.name, max_speed, (GE) ? "GE" : "Gb", |
1981 | m.bus, m.function); | |
da0436e9 | 1982 | } |
dea3101e JB |
1983 | } |
1984 | ||
e59058c4 | 1985 | /** |
3621a710 | 1986 | * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring |
e59058c4 JS |
1987 | * @phba: pointer to lpfc hba data structure. |
1988 | * @pring: pointer to a IOCB ring. | |
1989 | * @cnt: the number of IOCBs to be posted to the IOCB ring. | |
1990 | * | |
1991 | * This routine posts a given number of IOCBs with the associated DMA buffer | |
1992 | * descriptors specified by the cnt argument to the given IOCB ring. | |
1993 | * | |
1994 | * Return codes | |
1995 | * The number of IOCBs NOT able to be posted to the IOCB ring. | |
1996 | **/ | |
dea3101e | 1997 | int |
495a714c | 1998 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
dea3101e JB |
1999 | { |
2000 | IOCB_t *icmd; | |
0bd4ca25 | 2001 | struct lpfc_iocbq *iocb; |
dea3101e JB |
2002 | struct lpfc_dmabuf *mp1, *mp2; |
2003 | ||
2004 | cnt += pring->missbufcnt; | |
2005 | ||
2006 | /* While there are buffers to post */ | |
2007 | while (cnt > 0) { | |
2008 | /* Allocate buffer for command iocb */ | |
0bd4ca25 | 2009 | iocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
2010 | if (iocb == NULL) { |
2011 | pring->missbufcnt = cnt; | |
2012 | return cnt; | |
2013 | } | |
dea3101e JB |
2014 | icmd = &iocb->iocb; |
2015 | ||
2016 | /* 2 buffers can be posted per command */ | |
2017 | /* Allocate buffer to post */ | |
2018 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
2019 | if (mp1) | |
98c9ea5c JS |
2020 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
2021 | if (!mp1 || !mp1->virt) { | |
c9475cb0 | 2022 | kfree(mp1); |
604a3e30 | 2023 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
2024 | pring->missbufcnt = cnt; |
2025 | return cnt; | |
2026 | } | |
2027 | ||
2028 | INIT_LIST_HEAD(&mp1->list); | |
2029 | /* Allocate buffer to post */ | |
2030 | if (cnt > 1) { | |
2031 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
2032 | if (mp2) | |
2033 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | |
2034 | &mp2->phys); | |
98c9ea5c | 2035 | if (!mp2 || !mp2->virt) { |
c9475cb0 | 2036 | kfree(mp2); |
dea3101e JB |
2037 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
2038 | kfree(mp1); | |
604a3e30 | 2039 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
2040 | pring->missbufcnt = cnt; |
2041 | return cnt; | |
2042 | } | |
2043 | ||
2044 | INIT_LIST_HEAD(&mp2->list); | |
2045 | } else { | |
2046 | mp2 = NULL; | |
2047 | } | |
2048 | ||
2049 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); | |
2050 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); | |
2051 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; | |
2052 | icmd->ulpBdeCount = 1; | |
2053 | cnt--; | |
2054 | if (mp2) { | |
2055 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); | |
2056 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); | |
2057 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; | |
2058 | cnt--; | |
2059 | icmd->ulpBdeCount = 2; | |
2060 | } | |
2061 | ||
2062 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; | |
2063 | icmd->ulpLe = 1; | |
2064 | ||
3772a991 JS |
2065 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
2066 | IOCB_ERROR) { | |
dea3101e JB |
2067 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
2068 | kfree(mp1); | |
2069 | cnt++; | |
2070 | if (mp2) { | |
2071 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); | |
2072 | kfree(mp2); | |
2073 | cnt++; | |
2074 | } | |
604a3e30 | 2075 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e | 2076 | pring->missbufcnt = cnt; |
dea3101e JB |
2077 | return cnt; |
2078 | } | |
dea3101e | 2079 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
92d7f7b0 | 2080 | if (mp2) |
dea3101e | 2081 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
dea3101e JB |
2082 | } |
2083 | pring->missbufcnt = 0; | |
2084 | return 0; | |
2085 | } | |
2086 | ||
e59058c4 | 2087 | /** |
3621a710 | 2088 | * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring |
e59058c4 JS |
2089 | * @phba: pointer to lpfc hba data structure. |
2090 | * | |
2091 | * This routine posts initial receive IOCB buffers to the ELS ring. The | |
2092 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is | |
2093 | * set to 64 IOCBs. | |
2094 | * | |
2095 | * Return codes | |
2096 | * 0 - success (currently always success) | |
2097 | **/ | |
dea3101e | 2098 | static int |
2e0fef85 | 2099 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
dea3101e JB |
2100 | { |
2101 | struct lpfc_sli *psli = &phba->sli; | |
2102 | ||
2103 | /* Ring 0, ELS / CT buffers */ | |
495a714c | 2104 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
dea3101e JB |
2105 | /* Ring 2 - FCP no buffers needed */ |
2106 | ||
2107 | return 0; | |
2108 | } | |
2109 | ||
2110 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) | |
2111 | ||
e59058c4 | 2112 | /** |
3621a710 | 2113 | * lpfc_sha_init - Set up initial array of hash table entries |
e59058c4 JS |
2114 | * @HashResultPointer: pointer to an array as hash table. |
2115 | * | |
2116 | * This routine sets up the initial values to the array of hash table entries | |
2117 | * for the LC HBAs. | |
2118 | **/ | |
dea3101e JB |
2119 | static void |
2120 | lpfc_sha_init(uint32_t * HashResultPointer) | |
2121 | { | |
2122 | HashResultPointer[0] = 0x67452301; | |
2123 | HashResultPointer[1] = 0xEFCDAB89; | |
2124 | HashResultPointer[2] = 0x98BADCFE; | |
2125 | HashResultPointer[3] = 0x10325476; | |
2126 | HashResultPointer[4] = 0xC3D2E1F0; | |
2127 | } | |
2128 | ||
e59058c4 | 2129 | /** |
3621a710 | 2130 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
e59058c4 JS |
2131 | * @HashResultPointer: pointer to an initial/result hash table. |
2132 | * @HashWorkingPointer: pointer to an working hash table. | |
2133 | * | |
2134 | * This routine iterates an initial hash table pointed by @HashResultPointer | |
2135 | * with the values from the working hash table pointeed by @HashWorkingPointer. | |
2136 | * The results are putting back to the initial hash table, returned through | |
2137 | * the @HashResultPointer as the result hash table. | |
2138 | **/ | |
dea3101e JB |
2139 | static void |
2140 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) | |
2141 | { | |
2142 | int t; | |
2143 | uint32_t TEMP; | |
2144 | uint32_t A, B, C, D, E; | |
2145 | t = 16; | |
2146 | do { | |
2147 | HashWorkingPointer[t] = | |
2148 | S(1, | |
2149 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - | |
2150 | 8] ^ | |
2151 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); | |
2152 | } while (++t <= 79); | |
2153 | t = 0; | |
2154 | A = HashResultPointer[0]; | |
2155 | B = HashResultPointer[1]; | |
2156 | C = HashResultPointer[2]; | |
2157 | D = HashResultPointer[3]; | |
2158 | E = HashResultPointer[4]; | |
2159 | ||
2160 | do { | |
2161 | if (t < 20) { | |
2162 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; | |
2163 | } else if (t < 40) { | |
2164 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; | |
2165 | } else if (t < 60) { | |
2166 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; | |
2167 | } else { | |
2168 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; | |
2169 | } | |
2170 | TEMP += S(5, A) + E + HashWorkingPointer[t]; | |
2171 | E = D; | |
2172 | D = C; | |
2173 | C = S(30, B); | |
2174 | B = A; | |
2175 | A = TEMP; | |
2176 | } while (++t <= 79); | |
2177 | ||
2178 | HashResultPointer[0] += A; | |
2179 | HashResultPointer[1] += B; | |
2180 | HashResultPointer[2] += C; | |
2181 | HashResultPointer[3] += D; | |
2182 | HashResultPointer[4] += E; | |
2183 | ||
2184 | } | |
2185 | ||
e59058c4 | 2186 | /** |
3621a710 | 2187 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
e59058c4 JS |
2188 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
2189 | * @HashWorking: pointer to the entry of the working hash array. | |
2190 | * | |
2191 | * This routine calculates the working hash array referred by @HashWorking | |
2192 | * from the challenge random numbers associated with the host, referred by | |
2193 | * @RandomChallenge. The result is put into the entry of the working hash | |
2194 | * array and returned by reference through @HashWorking. | |
2195 | **/ | |
dea3101e JB |
2196 | static void |
2197 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) | |
2198 | { | |
2199 | *HashWorking = (*RandomChallenge ^ *HashWorking); | |
2200 | } | |
2201 | ||
e59058c4 | 2202 | /** |
3621a710 | 2203 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
e59058c4 JS |
2204 | * @phba: pointer to lpfc hba data structure. |
2205 | * @hbainit: pointer to an array of unsigned 32-bit integers. | |
2206 | * | |
2207 | * This routine performs the special handling for LC HBA initialization. | |
2208 | **/ | |
dea3101e JB |
2209 | void |
2210 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) | |
2211 | { | |
2212 | int t; | |
2213 | uint32_t *HashWorking; | |
2e0fef85 | 2214 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
dea3101e | 2215 | |
bbfbbbc1 | 2216 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
dea3101e JB |
2217 | if (!HashWorking) |
2218 | return; | |
2219 | ||
dea3101e JB |
2220 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
2221 | HashWorking[1] = HashWorking[79] = *pwwnn; | |
2222 | ||
2223 | for (t = 0; t < 7; t++) | |
2224 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); | |
2225 | ||
2226 | lpfc_sha_init(hbainit); | |
2227 | lpfc_sha_iterate(hbainit, HashWorking); | |
2228 | kfree(HashWorking); | |
2229 | } | |
2230 | ||
e59058c4 | 2231 | /** |
3621a710 | 2232 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
e59058c4 JS |
2233 | * @vport: pointer to a virtual N_Port data structure. |
2234 | * | |
2235 | * This routine performs the necessary cleanups before deleting the @vport. | |
2236 | * It invokes the discovery state machine to perform necessary state | |
2237 | * transitions and to release the ndlps associated with the @vport. Note, | |
2238 | * the physical port is treated as @vport 0. | |
2239 | **/ | |
87af33fe | 2240 | void |
2e0fef85 | 2241 | lpfc_cleanup(struct lpfc_vport *vport) |
dea3101e | 2242 | { |
87af33fe | 2243 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2244 | struct lpfc_nodelist *ndlp, *next_ndlp; |
a8adb832 | 2245 | int i = 0; |
dea3101e | 2246 | |
87af33fe JS |
2247 | if (phba->link_state > LPFC_LINK_DOWN) |
2248 | lpfc_port_link_failure(vport); | |
2249 | ||
2250 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
2251 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
2252 | ndlp = lpfc_enable_node(vport, ndlp, | |
2253 | NLP_STE_UNUSED_NODE); | |
2254 | if (!ndlp) | |
2255 | continue; | |
2256 | spin_lock_irq(&phba->ndlp_lock); | |
2257 | NLP_SET_FREE_REQ(ndlp); | |
2258 | spin_unlock_irq(&phba->ndlp_lock); | |
2259 | /* Trigger the release of the ndlp memory */ | |
2260 | lpfc_nlp_put(ndlp); | |
2261 | continue; | |
2262 | } | |
2263 | spin_lock_irq(&phba->ndlp_lock); | |
2264 | if (NLP_CHK_FREE_REQ(ndlp)) { | |
2265 | /* The ndlp should not be in memory free mode already */ | |
2266 | spin_unlock_irq(&phba->ndlp_lock); | |
2267 | continue; | |
2268 | } else | |
2269 | /* Indicate request for freeing ndlp memory */ | |
2270 | NLP_SET_FREE_REQ(ndlp); | |
2271 | spin_unlock_irq(&phba->ndlp_lock); | |
2272 | ||
58da1ffb JS |
2273 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
2274 | ndlp->nlp_DID == Fabric_DID) { | |
2275 | /* Just free up ndlp with Fabric_DID for vports */ | |
2276 | lpfc_nlp_put(ndlp); | |
2277 | continue; | |
2278 | } | |
2279 | ||
87af33fe JS |
2280 | if (ndlp->nlp_type & NLP_FABRIC) |
2281 | lpfc_disc_state_machine(vport, ndlp, NULL, | |
2282 | NLP_EVT_DEVICE_RECOVERY); | |
e47c9093 | 2283 | |
87af33fe JS |
2284 | lpfc_disc_state_machine(vport, ndlp, NULL, |
2285 | NLP_EVT_DEVICE_RM); | |
495a714c | 2286 | |
87af33fe JS |
2287 | } |
2288 | ||
a8adb832 JS |
2289 | /* At this point, ALL ndlp's should be gone |
2290 | * because of the previous NLP_EVT_DEVICE_RM. | |
2291 | * Lets wait for this to happen, if needed. | |
2292 | */ | |
87af33fe | 2293 | while (!list_empty(&vport->fc_nodes)) { |
a8adb832 | 2294 | if (i++ > 3000) { |
87af33fe | 2295 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
a8adb832 | 2296 | "0233 Nodelist not empty\n"); |
e47c9093 JS |
2297 | list_for_each_entry_safe(ndlp, next_ndlp, |
2298 | &vport->fc_nodes, nlp_listp) { | |
2299 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, | |
2300 | LOG_NODE, | |
d7c255b2 | 2301 | "0282 did:x%x ndlp:x%p " |
e47c9093 JS |
2302 | "usgmap:x%x refcnt:%d\n", |
2303 | ndlp->nlp_DID, (void *)ndlp, | |
2304 | ndlp->nlp_usg_map, | |
2305 | atomic_read( | |
2306 | &ndlp->kref.refcount)); | |
2307 | } | |
a8adb832 | 2308 | break; |
87af33fe | 2309 | } |
a8adb832 JS |
2310 | |
2311 | /* Wait for any activity on ndlps to settle */ | |
2312 | msleep(10); | |
87af33fe | 2313 | } |
1151e3ec | 2314 | lpfc_cleanup_vports_rrqs(vport, NULL); |
dea3101e JB |
2315 | } |
2316 | ||
e59058c4 | 2317 | /** |
3621a710 | 2318 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
e59058c4 JS |
2319 | * @vport: pointer to a virtual N_Port data structure. |
2320 | * | |
2321 | * This routine stops all the timers associated with a @vport. This function | |
2322 | * is invoked before disabling or deleting a @vport. Note that the physical | |
2323 | * port is treated as @vport 0. | |
2324 | **/ | |
92d7f7b0 JS |
2325 | void |
2326 | lpfc_stop_vport_timers(struct lpfc_vport *vport) | |
dea3101e | 2327 | { |
92d7f7b0 JS |
2328 | del_timer_sync(&vport->els_tmofunc); |
2329 | del_timer_sync(&vport->fc_fdmitmo); | |
92494144 | 2330 | del_timer_sync(&vport->delayed_disc_tmo); |
92d7f7b0 JS |
2331 | lpfc_can_disctmo(vport); |
2332 | return; | |
dea3101e JB |
2333 | } |
2334 | ||
ecfd03c6 JS |
2335 | /** |
2336 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2337 | * @phba: pointer to lpfc hba data structure. | |
2338 | * | |
2339 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The | |
2340 | * caller of this routine should already hold the host lock. | |
2341 | **/ | |
2342 | void | |
2343 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2344 | { | |
5ac6b303 JS |
2345 | /* Clear pending FCF rediscovery wait flag */ |
2346 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; | |
2347 | ||
ecfd03c6 JS |
2348 | /* Now, try to stop the timer */ |
2349 | del_timer(&phba->fcf.redisc_wait); | |
2350 | } | |
2351 | ||
2352 | /** | |
2353 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2354 | * @phba: pointer to lpfc hba data structure. | |
2355 | * | |
2356 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It | |
2357 | * checks whether the FCF rediscovery wait timer is pending with the host | |
2358 | * lock held before proceeding with disabling the timer and clearing the | |
2359 | * wait timer pendig flag. | |
2360 | **/ | |
2361 | void | |
2362 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2363 | { | |
2364 | spin_lock_irq(&phba->hbalock); | |
2365 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
2366 | /* FCF rediscovery timer already fired or stopped */ | |
2367 | spin_unlock_irq(&phba->hbalock); | |
2368 | return; | |
2369 | } | |
2370 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); | |
5ac6b303 JS |
2371 | /* Clear failover in progress flags */ |
2372 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); | |
ecfd03c6 JS |
2373 | spin_unlock_irq(&phba->hbalock); |
2374 | } | |
2375 | ||
e59058c4 | 2376 | /** |
3772a991 | 2377 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
e59058c4 JS |
2378 | * @phba: pointer to lpfc hba data structure. |
2379 | * | |
2380 | * This routine stops all the timers associated with a HBA. This function is | |
2381 | * invoked before either putting a HBA offline or unloading the driver. | |
2382 | **/ | |
3772a991 JS |
2383 | void |
2384 | lpfc_stop_hba_timers(struct lpfc_hba *phba) | |
dea3101e | 2385 | { |
51ef4c26 | 2386 | lpfc_stop_vport_timers(phba->pport); |
2e0fef85 | 2387 | del_timer_sync(&phba->sli.mbox_tmo); |
92d7f7b0 | 2388 | del_timer_sync(&phba->fabric_block_timer); |
9399627f | 2389 | del_timer_sync(&phba->eratt_poll); |
3772a991 | 2390 | del_timer_sync(&phba->hb_tmofunc); |
1151e3ec JS |
2391 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2392 | del_timer_sync(&phba->rrq_tmr); | |
2393 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
2394 | } | |
3772a991 JS |
2395 | phba->hb_outstanding = 0; |
2396 | ||
2397 | switch (phba->pci_dev_grp) { | |
2398 | case LPFC_PCI_DEV_LP: | |
2399 | /* Stop any LightPulse device specific driver timers */ | |
2400 | del_timer_sync(&phba->fcp_poll_timer); | |
2401 | break; | |
2402 | case LPFC_PCI_DEV_OC: | |
2403 | /* Stop any OneConnect device sepcific driver timers */ | |
ecfd03c6 | 2404 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
3772a991 JS |
2405 | break; |
2406 | default: | |
2407 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2408 | "0297 Invalid device group (x%x)\n", | |
2409 | phba->pci_dev_grp); | |
2410 | break; | |
2411 | } | |
2e0fef85 | 2412 | return; |
dea3101e JB |
2413 | } |
2414 | ||
e59058c4 | 2415 | /** |
3621a710 | 2416 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
e59058c4 JS |
2417 | * @phba: pointer to lpfc hba data structure. |
2418 | * | |
2419 | * This routine marks a HBA's management interface as blocked. Once the HBA's | |
2420 | * management interface is marked as blocked, all the user space access to | |
2421 | * the HBA, whether they are from sysfs interface or libdfc interface will | |
2422 | * all be blocked. The HBA is set to block the management interface when the | |
2423 | * driver prepares the HBA interface for online or offline. | |
2424 | **/ | |
a6ababd2 AB |
2425 | static void |
2426 | lpfc_block_mgmt_io(struct lpfc_hba * phba) | |
2427 | { | |
2428 | unsigned long iflag; | |
6e7288d9 JS |
2429 | uint8_t actcmd = MBX_HEARTBEAT; |
2430 | unsigned long timeout; | |
2431 | ||
a6ababd2 AB |
2432 | |
2433 | spin_lock_irqsave(&phba->hbalock, iflag); | |
2434 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; | |
6e7288d9 JS |
2435 | if (phba->sli.mbox_active) |
2436 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; | |
a6ababd2 | 2437 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
6e7288d9 JS |
2438 | /* Determine how long we might wait for the active mailbox |
2439 | * command to be gracefully completed by firmware. | |
2440 | */ | |
2441 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, actcmd) * 1000) + | |
2442 | jiffies; | |
2443 | /* Wait for the outstnading mailbox command to complete */ | |
2444 | while (phba->sli.mbox_active) { | |
2445 | /* Check active mailbox complete status every 2ms */ | |
2446 | msleep(2); | |
2447 | if (time_after(jiffies, timeout)) { | |
2448 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2449 | "2813 Mgmt IO is Blocked %x " | |
2450 | "- mbox cmd %x still active\n", | |
2451 | phba->sli.sli_flag, actcmd); | |
2452 | break; | |
2453 | } | |
2454 | } | |
a6ababd2 AB |
2455 | } |
2456 | ||
e59058c4 | 2457 | /** |
3621a710 | 2458 | * lpfc_online - Initialize and bring a HBA online |
e59058c4 JS |
2459 | * @phba: pointer to lpfc hba data structure. |
2460 | * | |
2461 | * This routine initializes the HBA and brings a HBA online. During this | |
2462 | * process, the management interface is blocked to prevent user space access | |
2463 | * to the HBA interfering with the driver initialization. | |
2464 | * | |
2465 | * Return codes | |
2466 | * 0 - successful | |
2467 | * 1 - failed | |
2468 | **/ | |
dea3101e | 2469 | int |
2e0fef85 | 2470 | lpfc_online(struct lpfc_hba *phba) |
dea3101e | 2471 | { |
372bd282 | 2472 | struct lpfc_vport *vport; |
549e55cd JS |
2473 | struct lpfc_vport **vports; |
2474 | int i; | |
2e0fef85 | 2475 | |
dea3101e JB |
2476 | if (!phba) |
2477 | return 0; | |
372bd282 | 2478 | vport = phba->pport; |
dea3101e | 2479 | |
2e0fef85 | 2480 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
dea3101e JB |
2481 | return 0; |
2482 | ||
ed957684 | 2483 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 2484 | "0458 Bring Adapter online\n"); |
dea3101e | 2485 | |
46fa311e JS |
2486 | lpfc_block_mgmt_io(phba); |
2487 | ||
2488 | if (!lpfc_sli_queue_setup(phba)) { | |
2489 | lpfc_unblock_mgmt_io(phba); | |
dea3101e | 2490 | return 1; |
46fa311e | 2491 | } |
dea3101e | 2492 | |
da0436e9 JS |
2493 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2494 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ | |
2495 | lpfc_unblock_mgmt_io(phba); | |
2496 | return 1; | |
2497 | } | |
2498 | } else { | |
2499 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ | |
2500 | lpfc_unblock_mgmt_io(phba); | |
2501 | return 1; | |
2502 | } | |
46fa311e | 2503 | } |
dea3101e | 2504 | |
549e55cd JS |
2505 | vports = lpfc_create_vport_work_array(phba); |
2506 | if (vports != NULL) | |
da0436e9 | 2507 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd JS |
2508 | struct Scsi_Host *shost; |
2509 | shost = lpfc_shost_from_vport(vports[i]); | |
2510 | spin_lock_irq(shost->host_lock); | |
2511 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; | |
2512 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) | |
2513 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
1c6834a7 JS |
2514 | if (phba->sli_rev == LPFC_SLI_REV4) |
2515 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; | |
549e55cd JS |
2516 | spin_unlock_irq(shost->host_lock); |
2517 | } | |
09372820 | 2518 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2519 | |
46fa311e | 2520 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
2521 | return 0; |
2522 | } | |
2523 | ||
e59058c4 | 2524 | /** |
3621a710 | 2525 | * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked |
e59058c4 JS |
2526 | * @phba: pointer to lpfc hba data structure. |
2527 | * | |
2528 | * This routine marks a HBA's management interface as not blocked. Once the | |
2529 | * HBA's management interface is marked as not blocked, all the user space | |
2530 | * access to the HBA, whether they are from sysfs interface or libdfc | |
2531 | * interface will be allowed. The HBA is set to block the management interface | |
2532 | * when the driver prepares the HBA interface for online or offline and then | |
2533 | * set to unblock the management interface afterwards. | |
2534 | **/ | |
46fa311e JS |
2535 | void |
2536 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) | |
2537 | { | |
2538 | unsigned long iflag; | |
2539 | ||
2e0fef85 JS |
2540 | spin_lock_irqsave(&phba->hbalock, iflag); |
2541 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; | |
2542 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
46fa311e JS |
2543 | } |
2544 | ||
e59058c4 | 2545 | /** |
3621a710 | 2546 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
e59058c4 JS |
2547 | * @phba: pointer to lpfc hba data structure. |
2548 | * | |
2549 | * This routine is invoked to prepare a HBA to be brought offline. It performs | |
2550 | * unregistration login to all the nodes on all vports and flushes the mailbox | |
2551 | * queue to make it ready to be brought offline. | |
2552 | **/ | |
46fa311e JS |
2553 | void |
2554 | lpfc_offline_prep(struct lpfc_hba * phba) | |
2555 | { | |
2e0fef85 | 2556 | struct lpfc_vport *vport = phba->pport; |
46fa311e | 2557 | struct lpfc_nodelist *ndlp, *next_ndlp; |
87af33fe | 2558 | struct lpfc_vport **vports; |
72100cc4 | 2559 | struct Scsi_Host *shost; |
87af33fe | 2560 | int i; |
dea3101e | 2561 | |
2e0fef85 | 2562 | if (vport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 2563 | return; |
dea3101e | 2564 | |
46fa311e | 2565 | lpfc_block_mgmt_io(phba); |
dea3101e JB |
2566 | |
2567 | lpfc_linkdown(phba); | |
2568 | ||
87af33fe JS |
2569 | /* Issue an unreg_login to all nodes on all vports */ |
2570 | vports = lpfc_create_vport_work_array(phba); | |
2571 | if (vports != NULL) { | |
da0436e9 | 2572 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
a8adb832 JS |
2573 | if (vports[i]->load_flag & FC_UNLOADING) |
2574 | continue; | |
72100cc4 JS |
2575 | shost = lpfc_shost_from_vport(vports[i]); |
2576 | spin_lock_irq(shost->host_lock); | |
c868595d | 2577 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
695a814e JS |
2578 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
2579 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; | |
72100cc4 | 2580 | spin_unlock_irq(shost->host_lock); |
695a814e | 2581 | |
87af33fe JS |
2582 | shost = lpfc_shost_from_vport(vports[i]); |
2583 | list_for_each_entry_safe(ndlp, next_ndlp, | |
2584 | &vports[i]->fc_nodes, | |
2585 | nlp_listp) { | |
e47c9093 JS |
2586 | if (!NLP_CHK_NODE_ACT(ndlp)) |
2587 | continue; | |
87af33fe JS |
2588 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
2589 | continue; | |
2590 | if (ndlp->nlp_type & NLP_FABRIC) { | |
2591 | lpfc_disc_state_machine(vports[i], ndlp, | |
2592 | NULL, NLP_EVT_DEVICE_RECOVERY); | |
2593 | lpfc_disc_state_machine(vports[i], ndlp, | |
2594 | NULL, NLP_EVT_DEVICE_RM); | |
2595 | } | |
2596 | spin_lock_irq(shost->host_lock); | |
2597 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | |
2598 | spin_unlock_irq(shost->host_lock); | |
2599 | lpfc_unreg_rpi(vports[i], ndlp); | |
2600 | } | |
2601 | } | |
2602 | } | |
09372820 | 2603 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2604 | |
04c68496 | 2605 | lpfc_sli_mbox_sys_shutdown(phba); |
46fa311e JS |
2606 | } |
2607 | ||
e59058c4 | 2608 | /** |
3621a710 | 2609 | * lpfc_offline - Bring a HBA offline |
e59058c4 JS |
2610 | * @phba: pointer to lpfc hba data structure. |
2611 | * | |
2612 | * This routine actually brings a HBA offline. It stops all the timers | |
2613 | * associated with the HBA, brings down the SLI layer, and eventually | |
2614 | * marks the HBA as in offline state for the upper layer protocol. | |
2615 | **/ | |
46fa311e | 2616 | void |
2e0fef85 | 2617 | lpfc_offline(struct lpfc_hba *phba) |
46fa311e | 2618 | { |
549e55cd JS |
2619 | struct Scsi_Host *shost; |
2620 | struct lpfc_vport **vports; | |
2621 | int i; | |
46fa311e | 2622 | |
549e55cd | 2623 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 2624 | return; |
688a8863 | 2625 | |
da0436e9 JS |
2626 | /* stop port and all timers associated with this hba */ |
2627 | lpfc_stop_port(phba); | |
51ef4c26 JS |
2628 | vports = lpfc_create_vport_work_array(phba); |
2629 | if (vports != NULL) | |
da0436e9 | 2630 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
51ef4c26 | 2631 | lpfc_stop_vport_timers(vports[i]); |
09372820 | 2632 | lpfc_destroy_vport_work_array(phba, vports); |
92d7f7b0 | 2633 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 2634 | "0460 Bring Adapter offline\n"); |
dea3101e JB |
2635 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
2636 | now. */ | |
2637 | lpfc_sli_hba_down(phba); | |
92d7f7b0 | 2638 | spin_lock_irq(&phba->hbalock); |
7054a606 | 2639 | phba->work_ha = 0; |
92d7f7b0 | 2640 | spin_unlock_irq(&phba->hbalock); |
549e55cd JS |
2641 | vports = lpfc_create_vport_work_array(phba); |
2642 | if (vports != NULL) | |
da0436e9 | 2643 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd | 2644 | shost = lpfc_shost_from_vport(vports[i]); |
549e55cd JS |
2645 | spin_lock_irq(shost->host_lock); |
2646 | vports[i]->work_port_events = 0; | |
2647 | vports[i]->fc_flag |= FC_OFFLINE_MODE; | |
2648 | spin_unlock_irq(shost->host_lock); | |
2649 | } | |
09372820 | 2650 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e JB |
2651 | } |
2652 | ||
e59058c4 | 2653 | /** |
3621a710 | 2654 | * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists |
e59058c4 JS |
2655 | * @phba: pointer to lpfc hba data structure. |
2656 | * | |
2657 | * This routine is to free all the SCSI buffers and IOCBs from the driver | |
2658 | * list back to kernel. It is called from lpfc_pci_remove_one to free | |
2659 | * the internal resources before the device is removed from the system. | |
2660 | * | |
2661 | * Return codes | |
2662 | * 0 - successful (for now, it always returns 0) | |
2663 | **/ | |
dea3101e | 2664 | static int |
2e0fef85 | 2665 | lpfc_scsi_free(struct lpfc_hba *phba) |
dea3101e JB |
2666 | { |
2667 | struct lpfc_scsi_buf *sb, *sb_next; | |
2668 | struct lpfc_iocbq *io, *io_next; | |
2669 | ||
2e0fef85 | 2670 | spin_lock_irq(&phba->hbalock); |
dea3101e | 2671 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
1c6f4ef5 | 2672 | spin_lock(&phba->scsi_buf_list_lock); |
dea3101e JB |
2673 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { |
2674 | list_del(&sb->list); | |
2675 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, | |
92d7f7b0 | 2676 | sb->dma_handle); |
dea3101e JB |
2677 | kfree(sb); |
2678 | phba->total_scsi_bufs--; | |
2679 | } | |
1c6f4ef5 | 2680 | spin_unlock(&phba->scsi_buf_list_lock); |
dea3101e JB |
2681 | |
2682 | /* Release all the lpfc_iocbq entries maintained by this host. */ | |
2683 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { | |
2684 | list_del(&io->list); | |
2685 | kfree(io); | |
2686 | phba->total_iocbq_bufs--; | |
2687 | } | |
2e0fef85 | 2688 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
2689 | return 0; |
2690 | } | |
2691 | ||
e59058c4 | 2692 | /** |
3621a710 | 2693 | * lpfc_create_port - Create an FC port |
e59058c4 JS |
2694 | * @phba: pointer to lpfc hba data structure. |
2695 | * @instance: a unique integer ID to this FC port. | |
2696 | * @dev: pointer to the device data structure. | |
2697 | * | |
2698 | * This routine creates a FC port for the upper layer protocol. The FC port | |
2699 | * can be created on top of either a physical port or a virtual port provided | |
2700 | * by the HBA. This routine also allocates a SCSI host data structure (shost) | |
2701 | * and associates the FC port created before adding the shost into the SCSI | |
2702 | * layer. | |
2703 | * | |
2704 | * Return codes | |
2705 | * @vport - pointer to the virtual N_Port data structure. | |
2706 | * NULL - port create failed. | |
2707 | **/ | |
2e0fef85 | 2708 | struct lpfc_vport * |
3de2a653 | 2709 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
47a8617c | 2710 | { |
2e0fef85 JS |
2711 | struct lpfc_vport *vport; |
2712 | struct Scsi_Host *shost; | |
2713 | int error = 0; | |
47a8617c | 2714 | |
3de2a653 JS |
2715 | if (dev != &phba->pcidev->dev) |
2716 | shost = scsi_host_alloc(&lpfc_vport_template, | |
2717 | sizeof(struct lpfc_vport)); | |
2718 | else | |
2719 | shost = scsi_host_alloc(&lpfc_template, | |
2720 | sizeof(struct lpfc_vport)); | |
2e0fef85 JS |
2721 | if (!shost) |
2722 | goto out; | |
47a8617c | 2723 | |
2e0fef85 JS |
2724 | vport = (struct lpfc_vport *) shost->hostdata; |
2725 | vport->phba = phba; | |
2e0fef85 | 2726 | vport->load_flag |= FC_LOADING; |
92d7f7b0 | 2727 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
7f5f3d0d | 2728 | vport->fc_rscn_flush = 0; |
47a8617c | 2729 | |
3de2a653 | 2730 | lpfc_get_vport_cfgparam(vport); |
2e0fef85 JS |
2731 | shost->unique_id = instance; |
2732 | shost->max_id = LPFC_MAX_TARGET; | |
3de2a653 | 2733 | shost->max_lun = vport->cfg_max_luns; |
2e0fef85 JS |
2734 | shost->this_id = -1; |
2735 | shost->max_cmd_len = 16; | |
da0436e9 | 2736 | if (phba->sli_rev == LPFC_SLI_REV4) { |
28baac74 | 2737 | shost->dma_boundary = |
cb5172ea | 2738 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
da0436e9 JS |
2739 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
2740 | } | |
81301a9b | 2741 | |
47a8617c | 2742 | /* |
2e0fef85 JS |
2743 | * Set initial can_queue value since 0 is no longer supported and |
2744 | * scsi_add_host will fail. This will be adjusted later based on the | |
2745 | * max xri value determined in hba setup. | |
47a8617c | 2746 | */ |
2e0fef85 | 2747 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
3de2a653 | 2748 | if (dev != &phba->pcidev->dev) { |
92d7f7b0 JS |
2749 | shost->transportt = lpfc_vport_transport_template; |
2750 | vport->port_type = LPFC_NPIV_PORT; | |
2751 | } else { | |
2752 | shost->transportt = lpfc_transport_template; | |
2753 | vport->port_type = LPFC_PHYSICAL_PORT; | |
2754 | } | |
47a8617c | 2755 | |
2e0fef85 JS |
2756 | /* Initialize all internally managed lists. */ |
2757 | INIT_LIST_HEAD(&vport->fc_nodes); | |
da0436e9 | 2758 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
2e0fef85 | 2759 | spin_lock_init(&vport->work_port_lock); |
47a8617c | 2760 | |
2e0fef85 JS |
2761 | init_timer(&vport->fc_disctmo); |
2762 | vport->fc_disctmo.function = lpfc_disc_timeout; | |
92d7f7b0 | 2763 | vport->fc_disctmo.data = (unsigned long)vport; |
47a8617c | 2764 | |
2e0fef85 JS |
2765 | init_timer(&vport->fc_fdmitmo); |
2766 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; | |
92d7f7b0 | 2767 | vport->fc_fdmitmo.data = (unsigned long)vport; |
47a8617c | 2768 | |
2e0fef85 JS |
2769 | init_timer(&vport->els_tmofunc); |
2770 | vport->els_tmofunc.function = lpfc_els_timeout; | |
92d7f7b0 | 2771 | vport->els_tmofunc.data = (unsigned long)vport; |
92494144 JS |
2772 | |
2773 | init_timer(&vport->delayed_disc_tmo); | |
2774 | vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo; | |
2775 | vport->delayed_disc_tmo.data = (unsigned long)vport; | |
2776 | ||
d139b9bd | 2777 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
2e0fef85 JS |
2778 | if (error) |
2779 | goto out_put_shost; | |
47a8617c | 2780 | |
549e55cd | 2781 | spin_lock_irq(&phba->hbalock); |
2e0fef85 | 2782 | list_add_tail(&vport->listentry, &phba->port_list); |
549e55cd | 2783 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 2784 | return vport; |
47a8617c | 2785 | |
2e0fef85 JS |
2786 | out_put_shost: |
2787 | scsi_host_put(shost); | |
2788 | out: | |
2789 | return NULL; | |
47a8617c JS |
2790 | } |
2791 | ||
e59058c4 | 2792 | /** |
3621a710 | 2793 | * destroy_port - destroy an FC port |
e59058c4 JS |
2794 | * @vport: pointer to an lpfc virtual N_Port data structure. |
2795 | * | |
2796 | * This routine destroys a FC port from the upper layer protocol. All the | |
2797 | * resources associated with the port are released. | |
2798 | **/ | |
2e0fef85 JS |
2799 | void |
2800 | destroy_port(struct lpfc_vport *vport) | |
47a8617c | 2801 | { |
92d7f7b0 JS |
2802 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2803 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 2804 | |
858c9f6c | 2805 | lpfc_debugfs_terminate(vport); |
92d7f7b0 JS |
2806 | fc_remove_host(shost); |
2807 | scsi_remove_host(shost); | |
47a8617c | 2808 | |
92d7f7b0 JS |
2809 | spin_lock_irq(&phba->hbalock); |
2810 | list_del_init(&vport->listentry); | |
2811 | spin_unlock_irq(&phba->hbalock); | |
47a8617c | 2812 | |
92d7f7b0 | 2813 | lpfc_cleanup(vport); |
47a8617c | 2814 | return; |
47a8617c JS |
2815 | } |
2816 | ||
e59058c4 | 2817 | /** |
3621a710 | 2818 | * lpfc_get_instance - Get a unique integer ID |
e59058c4 JS |
2819 | * |
2820 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It | |
2821 | * uses the kernel idr facility to perform the task. | |
2822 | * | |
2823 | * Return codes: | |
2824 | * instance - a unique integer ID allocated as the new instance. | |
2825 | * -1 - lpfc get instance failed. | |
2826 | **/ | |
92d7f7b0 JS |
2827 | int |
2828 | lpfc_get_instance(void) | |
2829 | { | |
2830 | int instance = 0; | |
47a8617c | 2831 | |
92d7f7b0 JS |
2832 | /* Assign an unused number */ |
2833 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) | |
2834 | return -1; | |
2835 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) | |
2836 | return -1; | |
2837 | return instance; | |
47a8617c JS |
2838 | } |
2839 | ||
e59058c4 | 2840 | /** |
3621a710 | 2841 | * lpfc_scan_finished - method for SCSI layer to detect whether scan is done |
e59058c4 JS |
2842 | * @shost: pointer to SCSI host data structure. |
2843 | * @time: elapsed time of the scan in jiffies. | |
2844 | * | |
2845 | * This routine is called by the SCSI layer with a SCSI host to determine | |
2846 | * whether the scan host is finished. | |
2847 | * | |
2848 | * Note: there is no scan_start function as adapter initialization will have | |
2849 | * asynchronously kicked off the link initialization. | |
2850 | * | |
2851 | * Return codes | |
2852 | * 0 - SCSI host scan is not over yet. | |
2853 | * 1 - SCSI host scan is over. | |
2854 | **/ | |
47a8617c JS |
2855 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
2856 | { | |
2e0fef85 JS |
2857 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
2858 | struct lpfc_hba *phba = vport->phba; | |
858c9f6c | 2859 | int stat = 0; |
47a8617c | 2860 | |
858c9f6c JS |
2861 | spin_lock_irq(shost->host_lock); |
2862 | ||
51ef4c26 | 2863 | if (vport->load_flag & FC_UNLOADING) { |
858c9f6c JS |
2864 | stat = 1; |
2865 | goto finished; | |
2866 | } | |
2e0fef85 JS |
2867 | if (time >= 30 * HZ) { |
2868 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
2869 | "0461 Scanning longer than 30 " |
2870 | "seconds. Continuing initialization\n"); | |
858c9f6c | 2871 | stat = 1; |
47a8617c | 2872 | goto finished; |
2e0fef85 JS |
2873 | } |
2874 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { | |
2875 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
2876 | "0465 Link down longer than 15 " |
2877 | "seconds. Continuing initialization\n"); | |
858c9f6c | 2878 | stat = 1; |
47a8617c | 2879 | goto finished; |
2e0fef85 | 2880 | } |
47a8617c | 2881 | |
2e0fef85 | 2882 | if (vport->port_state != LPFC_VPORT_READY) |
858c9f6c | 2883 | goto finished; |
2e0fef85 | 2884 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
858c9f6c | 2885 | goto finished; |
2e0fef85 | 2886 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
858c9f6c | 2887 | goto finished; |
2e0fef85 | 2888 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
858c9f6c JS |
2889 | goto finished; |
2890 | ||
2891 | stat = 1; | |
47a8617c JS |
2892 | |
2893 | finished: | |
858c9f6c JS |
2894 | spin_unlock_irq(shost->host_lock); |
2895 | return stat; | |
92d7f7b0 | 2896 | } |
47a8617c | 2897 | |
e59058c4 | 2898 | /** |
3621a710 | 2899 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
e59058c4 JS |
2900 | * @shost: pointer to SCSI host data structure. |
2901 | * | |
2902 | * This routine initializes a given SCSI host attributes on a FC port. The | |
2903 | * SCSI host can be either on top of a physical port or a virtual port. | |
2904 | **/ | |
92d7f7b0 JS |
2905 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
2906 | { | |
2907 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2908 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 2909 | /* |
2e0fef85 | 2910 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
47a8617c JS |
2911 | */ |
2912 | ||
2e0fef85 JS |
2913 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
2914 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
47a8617c JS |
2915 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
2916 | ||
2917 | memset(fc_host_supported_fc4s(shost), 0, | |
2e0fef85 | 2918 | sizeof(fc_host_supported_fc4s(shost))); |
47a8617c JS |
2919 | fc_host_supported_fc4s(shost)[2] = 1; |
2920 | fc_host_supported_fc4s(shost)[7] = 1; | |
2921 | ||
92d7f7b0 JS |
2922 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
2923 | sizeof fc_host_symbolic_name(shost)); | |
47a8617c JS |
2924 | |
2925 | fc_host_supported_speeds(shost) = 0; | |
2926 | if (phba->lmt & LMT_10Gb) | |
2927 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; | |
a8adb832 JS |
2928 | if (phba->lmt & LMT_8Gb) |
2929 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; | |
47a8617c JS |
2930 | if (phba->lmt & LMT_4Gb) |
2931 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; | |
2932 | if (phba->lmt & LMT_2Gb) | |
2933 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; | |
2934 | if (phba->lmt & LMT_1Gb) | |
2935 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; | |
2936 | ||
2937 | fc_host_maxframe_size(shost) = | |
2e0fef85 JS |
2938 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
2939 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; | |
47a8617c | 2940 | |
0af5d708 MC |
2941 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
2942 | ||
47a8617c JS |
2943 | /* This value is also unchanging */ |
2944 | memset(fc_host_active_fc4s(shost), 0, | |
2e0fef85 | 2945 | sizeof(fc_host_active_fc4s(shost))); |
47a8617c JS |
2946 | fc_host_active_fc4s(shost)[2] = 1; |
2947 | fc_host_active_fc4s(shost)[7] = 1; | |
2948 | ||
92d7f7b0 | 2949 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
47a8617c | 2950 | spin_lock_irq(shost->host_lock); |
51ef4c26 | 2951 | vport->load_flag &= ~FC_LOADING; |
47a8617c | 2952 | spin_unlock_irq(shost->host_lock); |
47a8617c | 2953 | } |
dea3101e | 2954 | |
e59058c4 | 2955 | /** |
da0436e9 | 2956 | * lpfc_stop_port_s3 - Stop SLI3 device port |
e59058c4 JS |
2957 | * @phba: pointer to lpfc hba data structure. |
2958 | * | |
da0436e9 JS |
2959 | * This routine is invoked to stop an SLI3 device port, it stops the device |
2960 | * from generating interrupts and stops the device driver's timers for the | |
2961 | * device. | |
e59058c4 | 2962 | **/ |
da0436e9 JS |
2963 | static void |
2964 | lpfc_stop_port_s3(struct lpfc_hba *phba) | |
db2378e0 | 2965 | { |
da0436e9 JS |
2966 | /* Clear all interrupt enable conditions */ |
2967 | writel(0, phba->HCregaddr); | |
2968 | readl(phba->HCregaddr); /* flush */ | |
2969 | /* Clear all pending interrupts */ | |
2970 | writel(0xffffffff, phba->HAregaddr); | |
2971 | readl(phba->HAregaddr); /* flush */ | |
db2378e0 | 2972 | |
da0436e9 JS |
2973 | /* Reset some HBA SLI setup states */ |
2974 | lpfc_stop_hba_timers(phba); | |
2975 | phba->pport->work_port_events = 0; | |
2976 | } | |
db2378e0 | 2977 | |
da0436e9 JS |
2978 | /** |
2979 | * lpfc_stop_port_s4 - Stop SLI4 device port | |
2980 | * @phba: pointer to lpfc hba data structure. | |
2981 | * | |
2982 | * This routine is invoked to stop an SLI4 device port, it stops the device | |
2983 | * from generating interrupts and stops the device driver's timers for the | |
2984 | * device. | |
2985 | **/ | |
2986 | static void | |
2987 | lpfc_stop_port_s4(struct lpfc_hba *phba) | |
2988 | { | |
2989 | /* Reset some HBA SLI4 setup states */ | |
2990 | lpfc_stop_hba_timers(phba); | |
2991 | phba->pport->work_port_events = 0; | |
2992 | phba->sli4_hba.intr_enable = 0; | |
da0436e9 | 2993 | } |
9399627f | 2994 | |
da0436e9 JS |
2995 | /** |
2996 | * lpfc_stop_port - Wrapper function for stopping hba port | |
2997 | * @phba: Pointer to HBA context object. | |
2998 | * | |
2999 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from | |
3000 | * the API jump table function pointer from the lpfc_hba struct. | |
3001 | **/ | |
3002 | void | |
3003 | lpfc_stop_port(struct lpfc_hba *phba) | |
3004 | { | |
3005 | phba->lpfc_stop_port(phba); | |
3006 | } | |
db2378e0 | 3007 | |
ecfd03c6 JS |
3008 | /** |
3009 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer | |
3010 | * @phba: Pointer to hba for which this call is being executed. | |
3011 | * | |
3012 | * This routine starts the timer waiting for the FCF rediscovery to complete. | |
3013 | **/ | |
3014 | void | |
3015 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) | |
3016 | { | |
3017 | unsigned long fcf_redisc_wait_tmo = | |
3018 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); | |
3019 | /* Start fcf rediscovery wait period timer */ | |
3020 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); | |
3021 | spin_lock_irq(&phba->hbalock); | |
3022 | /* Allow action to new fcf asynchronous event */ | |
3023 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); | |
3024 | /* Mark the FCF rediscovery pending state */ | |
3025 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; | |
3026 | spin_unlock_irq(&phba->hbalock); | |
3027 | } | |
3028 | ||
3029 | /** | |
3030 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout | |
3031 | * @ptr: Map to lpfc_hba data structure pointer. | |
3032 | * | |
3033 | * This routine is invoked when waiting for FCF table rediscover has been | |
3034 | * timed out. If new FCF record(s) has (have) been discovered during the | |
3035 | * wait period, a new FCF event shall be added to the FCOE async event | |
3036 | * list, and then worker thread shall be waked up for processing from the | |
3037 | * worker thread context. | |
3038 | **/ | |
3039 | void | |
3040 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) | |
3041 | { | |
3042 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; | |
3043 | ||
3044 | /* Don't send FCF rediscovery event if timer cancelled */ | |
3045 | spin_lock_irq(&phba->hbalock); | |
3046 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
3047 | spin_unlock_irq(&phba->hbalock); | |
3048 | return; | |
3049 | } | |
3050 | /* Clear FCF rediscovery timer pending flag */ | |
3051 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; | |
3052 | /* FCF rediscovery event to worker thread */ | |
3053 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; | |
3054 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 | 3055 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 3056 | "2776 FCF rediscover quiescent timer expired\n"); |
ecfd03c6 JS |
3057 | /* wake up worker thread */ |
3058 | lpfc_worker_wake_up(phba); | |
3059 | } | |
3060 | ||
e59058c4 | 3061 | /** |
da0436e9 | 3062 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
e59058c4 | 3063 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3064 | * @acqe_link: pointer to the async link completion queue entry. |
e59058c4 | 3065 | * |
da0436e9 JS |
3066 | * This routine is to parse the SLI4 link-attention link fault code and |
3067 | * translate it into the base driver's read link attention mailbox command | |
3068 | * status. | |
3069 | * | |
3070 | * Return: Link-attention status in terms of base driver's coding. | |
e59058c4 | 3071 | **/ |
da0436e9 JS |
3072 | static uint16_t |
3073 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, | |
3074 | struct lpfc_acqe_link *acqe_link) | |
db2378e0 | 3075 | { |
da0436e9 | 3076 | uint16_t latt_fault; |
9399627f | 3077 | |
da0436e9 JS |
3078 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
3079 | case LPFC_ASYNC_LINK_FAULT_NONE: | |
3080 | case LPFC_ASYNC_LINK_FAULT_LOCAL: | |
3081 | case LPFC_ASYNC_LINK_FAULT_REMOTE: | |
3082 | latt_fault = 0; | |
3083 | break; | |
3084 | default: | |
3085 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3086 | "0398 Invalid link fault code: x%x\n", | |
3087 | bf_get(lpfc_acqe_link_fault, acqe_link)); | |
3088 | latt_fault = MBXERR_ERROR; | |
3089 | break; | |
3090 | } | |
3091 | return latt_fault; | |
db2378e0 JS |
3092 | } |
3093 | ||
5b75da2f | 3094 | /** |
da0436e9 | 3095 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
5b75da2f | 3096 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3097 | * @acqe_link: pointer to the async link completion queue entry. |
5b75da2f | 3098 | * |
da0436e9 JS |
3099 | * This routine is to parse the SLI4 link attention type and translate it |
3100 | * into the base driver's link attention type coding. | |
5b75da2f | 3101 | * |
da0436e9 JS |
3102 | * Return: Link attention type in terms of base driver's coding. |
3103 | **/ | |
3104 | static uint8_t | |
3105 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, | |
3106 | struct lpfc_acqe_link *acqe_link) | |
5b75da2f | 3107 | { |
da0436e9 | 3108 | uint8_t att_type; |
5b75da2f | 3109 | |
da0436e9 JS |
3110 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
3111 | case LPFC_ASYNC_LINK_STATUS_DOWN: | |
3112 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: | |
76a95d75 | 3113 | att_type = LPFC_ATT_LINK_DOWN; |
da0436e9 JS |
3114 | break; |
3115 | case LPFC_ASYNC_LINK_STATUS_UP: | |
3116 | /* Ignore physical link up events - wait for logical link up */ | |
76a95d75 | 3117 | att_type = LPFC_ATT_RESERVED; |
da0436e9 JS |
3118 | break; |
3119 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: | |
76a95d75 | 3120 | att_type = LPFC_ATT_LINK_UP; |
da0436e9 JS |
3121 | break; |
3122 | default: | |
3123 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3124 | "0399 Invalid link attention type: x%x\n", | |
3125 | bf_get(lpfc_acqe_link_status, acqe_link)); | |
76a95d75 | 3126 | att_type = LPFC_ATT_RESERVED; |
da0436e9 | 3127 | break; |
5b75da2f | 3128 | } |
da0436e9 | 3129 | return att_type; |
5b75da2f JS |
3130 | } |
3131 | ||
3132 | /** | |
da0436e9 | 3133 | * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed |
5b75da2f | 3134 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3135 | * @acqe_link: pointer to the async link completion queue entry. |
5b75da2f | 3136 | * |
da0436e9 JS |
3137 | * This routine is to parse the SLI4 link-attention link speed and translate |
3138 | * it into the base driver's link-attention link speed coding. | |
3139 | * | |
3140 | * Return: Link-attention link speed in terms of base driver's coding. | |
3141 | **/ | |
3142 | static uint8_t | |
3143 | lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba, | |
3144 | struct lpfc_acqe_link *acqe_link) | |
5b75da2f | 3145 | { |
da0436e9 JS |
3146 | uint8_t link_speed; |
3147 | ||
3148 | switch (bf_get(lpfc_acqe_link_speed, acqe_link)) { | |
3149 | case LPFC_ASYNC_LINK_SPEED_ZERO: | |
da0436e9 | 3150 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
da0436e9 | 3151 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
76a95d75 | 3152 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
da0436e9 JS |
3153 | break; |
3154 | case LPFC_ASYNC_LINK_SPEED_1GBPS: | |
76a95d75 | 3155 | link_speed = LPFC_LINK_SPEED_1GHZ; |
da0436e9 JS |
3156 | break; |
3157 | case LPFC_ASYNC_LINK_SPEED_10GBPS: | |
76a95d75 | 3158 | link_speed = LPFC_LINK_SPEED_10GHZ; |
da0436e9 JS |
3159 | break; |
3160 | default: | |
3161 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3162 | "0483 Invalid link-attention link speed: x%x\n", | |
3163 | bf_get(lpfc_acqe_link_speed, acqe_link)); | |
76a95d75 | 3164 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
da0436e9 JS |
3165 | break; |
3166 | } | |
3167 | return link_speed; | |
3168 | } | |
3169 | ||
3170 | /** | |
70f3c073 | 3171 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
da0436e9 JS |
3172 | * @phba: pointer to lpfc hba data structure. |
3173 | * @acqe_link: pointer to the async link completion queue entry. | |
3174 | * | |
70f3c073 | 3175 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
da0436e9 JS |
3176 | **/ |
3177 | static void | |
3178 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, | |
3179 | struct lpfc_acqe_link *acqe_link) | |
3180 | { | |
3181 | struct lpfc_dmabuf *mp; | |
3182 | LPFC_MBOXQ_t *pmb; | |
3183 | MAILBOX_t *mb; | |
76a95d75 | 3184 | struct lpfc_mbx_read_top *la; |
da0436e9 | 3185 | uint8_t att_type; |
76a95d75 | 3186 | int rc; |
da0436e9 JS |
3187 | |
3188 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); | |
76a95d75 | 3189 | if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP) |
da0436e9 | 3190 | return; |
32b9793f | 3191 | phba->fcoe_eventtag = acqe_link->event_tag; |
da0436e9 JS |
3192 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3193 | if (!pmb) { | |
3194 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3195 | "0395 The mboxq allocation failed\n"); | |
3196 | return; | |
3197 | } | |
3198 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
3199 | if (!mp) { | |
3200 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3201 | "0396 The lpfc_dmabuf allocation failed\n"); | |
3202 | goto out_free_pmb; | |
3203 | } | |
3204 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
3205 | if (!mp->virt) { | |
3206 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3207 | "0397 The mbuf allocation failed\n"); | |
3208 | goto out_free_dmabuf; | |
3209 | } | |
3210 | ||
3211 | /* Cleanup any outstanding ELS commands */ | |
3212 | lpfc_els_flush_all_cmd(phba); | |
3213 | ||
3214 | /* Block ELS IOCBs until we have done process link event */ | |
3215 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
3216 | ||
3217 | /* Update link event statistics */ | |
3218 | phba->sli.slistat.link_event++; | |
3219 | ||
76a95d75 JS |
3220 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
3221 | lpfc_read_topology(phba, pmb, mp); | |
3222 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
da0436e9 JS |
3223 | pmb->vport = phba->pport; |
3224 | ||
da0436e9 JS |
3225 | /* Keep the link status for extra SLI4 state machine reference */ |
3226 | phba->sli4_hba.link_state.speed = | |
3227 | bf_get(lpfc_acqe_link_speed, acqe_link); | |
3228 | phba->sli4_hba.link_state.duplex = | |
3229 | bf_get(lpfc_acqe_link_duplex, acqe_link); | |
3230 | phba->sli4_hba.link_state.status = | |
3231 | bf_get(lpfc_acqe_link_status, acqe_link); | |
70f3c073 JS |
3232 | phba->sli4_hba.link_state.type = |
3233 | bf_get(lpfc_acqe_link_type, acqe_link); | |
3234 | phba->sli4_hba.link_state.number = | |
3235 | bf_get(lpfc_acqe_link_number, acqe_link); | |
da0436e9 JS |
3236 | phba->sli4_hba.link_state.fault = |
3237 | bf_get(lpfc_acqe_link_fault, acqe_link); | |
65467b6b | 3238 | phba->sli4_hba.link_state.logical_speed = |
70f3c073 JS |
3239 | bf_get(lpfc_acqe_logical_link_speed, acqe_link); |
3240 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
c31098ce JS |
3241 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
3242 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " | |
3243 | "Logical speed:%dMbps Fault:%d\n", | |
70f3c073 JS |
3244 | phba->sli4_hba.link_state.speed, |
3245 | phba->sli4_hba.link_state.topology, | |
3246 | phba->sli4_hba.link_state.status, | |
3247 | phba->sli4_hba.link_state.type, | |
3248 | phba->sli4_hba.link_state.number, | |
3249 | phba->sli4_hba.link_state.logical_speed * 10, | |
3250 | phba->sli4_hba.link_state.fault); | |
76a95d75 JS |
3251 | /* |
3252 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch | |
3253 | * topology info. Note: Optional for non FC-AL ports. | |
3254 | */ | |
3255 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { | |
3256 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3257 | if (rc == MBX_NOT_FINISHED) | |
3258 | goto out_free_dmabuf; | |
3259 | return; | |
3260 | } | |
3261 | /* | |
3262 | * For FCoE Mode: fill in all the topology information we need and call | |
3263 | * the READ_TOPOLOGY completion routine to continue without actually | |
3264 | * sending the READ_TOPOLOGY mailbox command to the port. | |
3265 | */ | |
3266 | /* Parse and translate status field */ | |
3267 | mb = &pmb->u.mb; | |
3268 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); | |
3269 | ||
3270 | /* Parse and translate link attention fields */ | |
3271 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; | |
3272 | la->eventTag = acqe_link->event_tag; | |
3273 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); | |
3274 | bf_set(lpfc_mbx_read_top_link_spd, la, | |
3275 | lpfc_sli4_parse_latt_link_speed(phba, acqe_link)); | |
3276 | ||
3277 | /* Fake the the following irrelvant fields */ | |
3278 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); | |
3279 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); | |
3280 | bf_set(lpfc_mbx_read_top_il, la, 0); | |
3281 | bf_set(lpfc_mbx_read_top_pb, la, 0); | |
3282 | bf_set(lpfc_mbx_read_top_fa, la, 0); | |
3283 | bf_set(lpfc_mbx_read_top_mm, la, 0); | |
da0436e9 JS |
3284 | |
3285 | /* Invoke the lpfc_handle_latt mailbox command callback function */ | |
76a95d75 | 3286 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
da0436e9 | 3287 | |
5b75da2f | 3288 | return; |
da0436e9 JS |
3289 | |
3290 | out_free_dmabuf: | |
3291 | kfree(mp); | |
3292 | out_free_pmb: | |
3293 | mempool_free(pmb, phba->mbox_mem_pool); | |
3294 | } | |
3295 | ||
70f3c073 JS |
3296 | /** |
3297 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event | |
3298 | * @phba: pointer to lpfc hba data structure. | |
3299 | * @acqe_fc: pointer to the async fc completion queue entry. | |
3300 | * | |
3301 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log | |
3302 | * that the event was received and then issue a read_topology mailbox command so | |
3303 | * that the rest of the driver will treat it the same as SLI3. | |
3304 | **/ | |
3305 | static void | |
3306 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) | |
3307 | { | |
3308 | struct lpfc_dmabuf *mp; | |
3309 | LPFC_MBOXQ_t *pmb; | |
3310 | int rc; | |
3311 | ||
3312 | if (bf_get(lpfc_trailer_type, acqe_fc) != | |
3313 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { | |
3314 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3315 | "2895 Non FC link Event detected.(%d)\n", | |
3316 | bf_get(lpfc_trailer_type, acqe_fc)); | |
3317 | return; | |
3318 | } | |
3319 | /* Keep the link status for extra SLI4 state machine reference */ | |
3320 | phba->sli4_hba.link_state.speed = | |
3321 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc); | |
3322 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; | |
3323 | phba->sli4_hba.link_state.topology = | |
3324 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); | |
3325 | phba->sli4_hba.link_state.status = | |
3326 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); | |
3327 | phba->sli4_hba.link_state.type = | |
3328 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); | |
3329 | phba->sli4_hba.link_state.number = | |
3330 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); | |
3331 | phba->sli4_hba.link_state.fault = | |
3332 | bf_get(lpfc_acqe_link_fault, acqe_fc); | |
3333 | phba->sli4_hba.link_state.logical_speed = | |
3334 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc); | |
3335 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3336 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " | |
3337 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" | |
3338 | "%dMbps Fault:%d\n", | |
3339 | phba->sli4_hba.link_state.speed, | |
3340 | phba->sli4_hba.link_state.topology, | |
3341 | phba->sli4_hba.link_state.status, | |
3342 | phba->sli4_hba.link_state.type, | |
3343 | phba->sli4_hba.link_state.number, | |
3344 | phba->sli4_hba.link_state.logical_speed * 10, | |
3345 | phba->sli4_hba.link_state.fault); | |
3346 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
3347 | if (!pmb) { | |
3348 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3349 | "2897 The mboxq allocation failed\n"); | |
3350 | return; | |
3351 | } | |
3352 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
3353 | if (!mp) { | |
3354 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3355 | "2898 The lpfc_dmabuf allocation failed\n"); | |
3356 | goto out_free_pmb; | |
3357 | } | |
3358 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
3359 | if (!mp->virt) { | |
3360 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3361 | "2899 The mbuf allocation failed\n"); | |
3362 | goto out_free_dmabuf; | |
3363 | } | |
3364 | ||
3365 | /* Cleanup any outstanding ELS commands */ | |
3366 | lpfc_els_flush_all_cmd(phba); | |
3367 | ||
3368 | /* Block ELS IOCBs until we have done process link event */ | |
3369 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
3370 | ||
3371 | /* Update link event statistics */ | |
3372 | phba->sli.slistat.link_event++; | |
3373 | ||
3374 | /* Create lpfc_handle_latt mailbox command from link ACQE */ | |
3375 | lpfc_read_topology(phba, pmb, mp); | |
3376 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
3377 | pmb->vport = phba->pport; | |
3378 | ||
3379 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3380 | if (rc == MBX_NOT_FINISHED) | |
3381 | goto out_free_dmabuf; | |
3382 | return; | |
3383 | ||
3384 | out_free_dmabuf: | |
3385 | kfree(mp); | |
3386 | out_free_pmb: | |
3387 | mempool_free(pmb, phba->mbox_mem_pool); | |
3388 | } | |
3389 | ||
3390 | /** | |
3391 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event | |
3392 | * @phba: pointer to lpfc hba data structure. | |
3393 | * @acqe_fc: pointer to the async SLI completion queue entry. | |
3394 | * | |
3395 | * This routine is to handle the SLI4 asynchronous SLI events. | |
3396 | **/ | |
3397 | static void | |
3398 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) | |
3399 | { | |
3400 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3401 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" | |
3402 | "x%08x SLI Event Type:%d", | |
3403 | acqe_sli->event_data1, acqe_sli->event_data2, | |
3404 | bf_get(lpfc_trailer_type, acqe_sli)); | |
3405 | return; | |
3406 | } | |
3407 | ||
fc2b989b JS |
3408 | /** |
3409 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport | |
3410 | * @vport: pointer to vport data structure. | |
3411 | * | |
3412 | * This routine is to perform Clear Virtual Link (CVL) on a vport in | |
3413 | * response to a CVL event. | |
3414 | * | |
3415 | * Return the pointer to the ndlp with the vport if successful, otherwise | |
3416 | * return NULL. | |
3417 | **/ | |
3418 | static struct lpfc_nodelist * | |
3419 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) | |
3420 | { | |
3421 | struct lpfc_nodelist *ndlp; | |
3422 | struct Scsi_Host *shost; | |
3423 | struct lpfc_hba *phba; | |
3424 | ||
3425 | if (!vport) | |
3426 | return NULL; | |
fc2b989b JS |
3427 | phba = vport->phba; |
3428 | if (!phba) | |
3429 | return NULL; | |
78730cfe JS |
3430 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
3431 | if (!ndlp) { | |
3432 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | |
3433 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
3434 | if (!ndlp) | |
3435 | return 0; | |
3436 | lpfc_nlp_init(vport, ndlp, Fabric_DID); | |
3437 | /* Set the node type */ | |
3438 | ndlp->nlp_type |= NLP_FABRIC; | |
3439 | /* Put ndlp onto node list */ | |
3440 | lpfc_enqueue_node(vport, ndlp); | |
3441 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
3442 | /* re-setup ndlp without removing from node list */ | |
3443 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
3444 | if (!ndlp) | |
3445 | return 0; | |
3446 | } | |
63e801ce JS |
3447 | if ((phba->pport->port_state < LPFC_FLOGI) && |
3448 | (phba->pport->port_state != LPFC_VPORT_FAILED)) | |
fc2b989b JS |
3449 | return NULL; |
3450 | /* If virtual link is not yet instantiated ignore CVL */ | |
63e801ce JS |
3451 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
3452 | && (vport->port_state != LPFC_VPORT_FAILED)) | |
fc2b989b JS |
3453 | return NULL; |
3454 | shost = lpfc_shost_from_vport(vport); | |
3455 | if (!shost) | |
3456 | return NULL; | |
3457 | lpfc_linkdown_port(vport); | |
3458 | lpfc_cleanup_pending_mbox(vport); | |
3459 | spin_lock_irq(shost->host_lock); | |
3460 | vport->fc_flag |= FC_VPORT_CVL_RCVD; | |
3461 | spin_unlock_irq(shost->host_lock); | |
3462 | ||
3463 | return ndlp; | |
3464 | } | |
3465 | ||
3466 | /** | |
3467 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports | |
3468 | * @vport: pointer to lpfc hba data structure. | |
3469 | * | |
3470 | * This routine is to perform Clear Virtual Link (CVL) on all vports in | |
3471 | * response to a FCF dead event. | |
3472 | **/ | |
3473 | static void | |
3474 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) | |
3475 | { | |
3476 | struct lpfc_vport **vports; | |
3477 | int i; | |
3478 | ||
3479 | vports = lpfc_create_vport_work_array(phba); | |
3480 | if (vports) | |
3481 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) | |
3482 | lpfc_sli4_perform_vport_cvl(vports[i]); | |
3483 | lpfc_destroy_vport_work_array(phba, vports); | |
3484 | } | |
3485 | ||
da0436e9 | 3486 | /** |
76a95d75 | 3487 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
da0436e9 JS |
3488 | * @phba: pointer to lpfc hba data structure. |
3489 | * @acqe_link: pointer to the async fcoe completion queue entry. | |
3490 | * | |
3491 | * This routine is to handle the SLI4 asynchronous fcoe event. | |
3492 | **/ | |
3493 | static void | |
76a95d75 | 3494 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
70f3c073 | 3495 | struct lpfc_acqe_fip *acqe_fip) |
da0436e9 | 3496 | { |
70f3c073 | 3497 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
da0436e9 | 3498 | int rc; |
6669f9bb JS |
3499 | struct lpfc_vport *vport; |
3500 | struct lpfc_nodelist *ndlp; | |
3501 | struct Scsi_Host *shost; | |
695a814e JS |
3502 | int active_vlink_present; |
3503 | struct lpfc_vport **vports; | |
3504 | int i; | |
da0436e9 | 3505 | |
70f3c073 JS |
3506 | phba->fc_eventTag = acqe_fip->event_tag; |
3507 | phba->fcoe_eventtag = acqe_fip->event_tag; | |
da0436e9 | 3508 | switch (event_type) { |
70f3c073 JS |
3509 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
3510 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: | |
3511 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) | |
999d813f JS |
3512 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
3513 | LOG_DISCOVERY, | |
a93ff37a JS |
3514 | "2546 New FCF event, evt_tag:x%x, " |
3515 | "index:x%x\n", | |
70f3c073 JS |
3516 | acqe_fip->event_tag, |
3517 | acqe_fip->index); | |
999d813f JS |
3518 | else |
3519 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | | |
3520 | LOG_DISCOVERY, | |
a93ff37a JS |
3521 | "2788 FCF param modified event, " |
3522 | "evt_tag:x%x, index:x%x\n", | |
70f3c073 JS |
3523 | acqe_fip->event_tag, |
3524 | acqe_fip->index); | |
38b92ef8 | 3525 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
0c9ab6f5 JS |
3526 | /* |
3527 | * During period of FCF discovery, read the FCF | |
3528 | * table record indexed by the event to update | |
a93ff37a | 3529 | * FCF roundrobin failover eligible FCF bmask. |
0c9ab6f5 JS |
3530 | */ |
3531 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | | |
3532 | LOG_DISCOVERY, | |
a93ff37a JS |
3533 | "2779 Read FCF (x%x) for updating " |
3534 | "roundrobin FCF failover bmask\n", | |
70f3c073 JS |
3535 | acqe_fip->index); |
3536 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); | |
0c9ab6f5 | 3537 | } |
38b92ef8 JS |
3538 | |
3539 | /* If the FCF discovery is in progress, do nothing. */ | |
3804dc84 | 3540 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 3541 | if (phba->hba_flag & FCF_TS_INPROG) { |
38b92ef8 JS |
3542 | spin_unlock_irq(&phba->hbalock); |
3543 | break; | |
3544 | } | |
3545 | /* If fast FCF failover rescan event is pending, do nothing */ | |
3546 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { | |
3547 | spin_unlock_irq(&phba->hbalock); | |
3548 | break; | |
3549 | } | |
3550 | ||
3551 | /* If the FCF has been in discovered state, do nothing. */ | |
3804dc84 JS |
3552 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
3553 | spin_unlock_irq(&phba->hbalock); | |
3554 | break; | |
3555 | } | |
3556 | spin_unlock_irq(&phba->hbalock); | |
38b92ef8 | 3557 | |
0c9ab6f5 JS |
3558 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
3559 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, | |
a93ff37a JS |
3560 | "2770 Start FCF table scan per async FCF " |
3561 | "event, evt_tag:x%x, index:x%x\n", | |
70f3c073 | 3562 | acqe_fip->event_tag, acqe_fip->index); |
0c9ab6f5 JS |
3563 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
3564 | LPFC_FCOE_FCF_GET_FIRST); | |
da0436e9 | 3565 | if (rc) |
0c9ab6f5 JS |
3566 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
3567 | "2547 Issue FCF scan read FCF mailbox " | |
a93ff37a | 3568 | "command failed (x%x)\n", rc); |
da0436e9 JS |
3569 | break; |
3570 | ||
70f3c073 | 3571 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
da0436e9 | 3572 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e4e74273 | 3573 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
70f3c073 JS |
3574 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
3575 | acqe_fip->event_tag); | |
da0436e9 JS |
3576 | break; |
3577 | ||
70f3c073 | 3578 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
0c9ab6f5 | 3579 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
a93ff37a | 3580 | "2549 FCF (x%x) disconnected from network, " |
70f3c073 | 3581 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
38b92ef8 JS |
3582 | /* |
3583 | * If we are in the middle of FCF failover process, clear | |
3584 | * the corresponding FCF bit in the roundrobin bitmap. | |
da0436e9 | 3585 | */ |
fc2b989b | 3586 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3587 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
fc2b989b | 3588 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 | 3589 | /* Update FLOGI FCF failover eligible FCF bmask */ |
70f3c073 | 3590 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
fc2b989b JS |
3591 | break; |
3592 | } | |
38b92ef8 JS |
3593 | spin_unlock_irq(&phba->hbalock); |
3594 | ||
3595 | /* If the event is not for currently used fcf do nothing */ | |
70f3c073 | 3596 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
38b92ef8 JS |
3597 | break; |
3598 | ||
3599 | /* | |
3600 | * Otherwise, request the port to rediscover the entire FCF | |
3601 | * table for a fast recovery from case that the current FCF | |
3602 | * is no longer valid as we are not in the middle of FCF | |
3603 | * failover process already. | |
3604 | */ | |
3605 | spin_lock_irq(&phba->hbalock); | |
fc2b989b | 3606 | /* Mark the fast failover process in progress */ |
0c9ab6f5 | 3607 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
fc2b989b | 3608 | spin_unlock_irq(&phba->hbalock); |
38b92ef8 | 3609 | |
0c9ab6f5 JS |
3610 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
3611 | "2771 Start FCF fast failover process due to " | |
3612 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " | |
70f3c073 | 3613 | "\n", acqe_fip->event_tag, acqe_fip->index); |
fc2b989b JS |
3614 | rc = lpfc_sli4_redisc_fcf_table(phba); |
3615 | if (rc) { | |
0c9ab6f5 JS |
3616 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
3617 | LOG_DISCOVERY, | |
3618 | "2772 Issue FCF rediscover mabilbox " | |
3619 | "command failed, fail through to FCF " | |
3620 | "dead event\n"); | |
fc2b989b | 3621 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3622 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
3623 | spin_unlock_irq(&phba->hbalock); |
3624 | /* | |
3625 | * Last resort will fail over by treating this | |
3626 | * as a link down to FCF registration. | |
3627 | */ | |
3628 | lpfc_sli4_fcf_dead_failthrough(phba); | |
38b92ef8 JS |
3629 | } else { |
3630 | /* Reset FCF roundrobin bmask for new discovery */ | |
3631 | memset(phba->fcf.fcf_rr_bmask, 0, | |
3632 | sizeof(*phba->fcf.fcf_rr_bmask)); | |
3633 | /* | |
3634 | * Handling fast FCF failover to a DEAD FCF event is | |
3635 | * considered equalivant to receiving CVL to all vports. | |
fc2b989b JS |
3636 | */ |
3637 | lpfc_sli4_perform_all_vport_cvl(phba); | |
38b92ef8 | 3638 | } |
da0436e9 | 3639 | break; |
70f3c073 | 3640 | case LPFC_FIP_EVENT_TYPE_CVL: |
0c9ab6f5 | 3641 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
6669f9bb | 3642 | "2718 Clear Virtual Link Received for VPI 0x%x" |
70f3c073 | 3643 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
6669f9bb | 3644 | vport = lpfc_find_vport_by_vpid(phba, |
70f3c073 | 3645 | acqe_fip->index - phba->vpi_base); |
fc2b989b | 3646 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
6669f9bb JS |
3647 | if (!ndlp) |
3648 | break; | |
695a814e JS |
3649 | active_vlink_present = 0; |
3650 | ||
3651 | vports = lpfc_create_vport_work_array(phba); | |
3652 | if (vports) { | |
3653 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; | |
3654 | i++) { | |
3655 | if ((!(vports[i]->fc_flag & | |
3656 | FC_VPORT_CVL_RCVD)) && | |
3657 | (vports[i]->port_state > LPFC_FDISC)) { | |
3658 | active_vlink_present = 1; | |
3659 | break; | |
3660 | } | |
3661 | } | |
3662 | lpfc_destroy_vport_work_array(phba, vports); | |
3663 | } | |
3664 | ||
3665 | if (active_vlink_present) { | |
3666 | /* | |
3667 | * If there are other active VLinks present, | |
3668 | * re-instantiate the Vlink using FDISC. | |
3669 | */ | |
6669f9bb | 3670 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
fc2b989b | 3671 | shost = lpfc_shost_from_vport(vport); |
6669f9bb JS |
3672 | spin_lock_irq(shost->host_lock); |
3673 | ndlp->nlp_flag |= NLP_DELAY_TMO; | |
3674 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
3675 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
3676 | vport->port_state = LPFC_FDISC; | |
3677 | } else { | |
ecfd03c6 JS |
3678 | /* |
3679 | * Otherwise, we request port to rediscover | |
3680 | * the entire FCF table for a fast recovery | |
3681 | * from possible case that the current FCF | |
0c9ab6f5 JS |
3682 | * is no longer valid if we are not already |
3683 | * in the FCF failover process. | |
ecfd03c6 | 3684 | */ |
fc2b989b | 3685 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3686 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
fc2b989b JS |
3687 | spin_unlock_irq(&phba->hbalock); |
3688 | break; | |
3689 | } | |
3690 | /* Mark the fast failover process in progress */ | |
0c9ab6f5 | 3691 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
fc2b989b | 3692 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 JS |
3693 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
3694 | LOG_DISCOVERY, | |
a93ff37a | 3695 | "2773 Start FCF failover per CVL, " |
70f3c073 | 3696 | "evt_tag:x%x\n", acqe_fip->event_tag); |
ecfd03c6 | 3697 | rc = lpfc_sli4_redisc_fcf_table(phba); |
fc2b989b | 3698 | if (rc) { |
0c9ab6f5 JS |
3699 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
3700 | LOG_DISCOVERY, | |
3701 | "2774 Issue FCF rediscover " | |
3702 | "mabilbox command failed, " | |
3703 | "through to CVL event\n"); | |
fc2b989b | 3704 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3705 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b | 3706 | spin_unlock_irq(&phba->hbalock); |
ecfd03c6 JS |
3707 | /* |
3708 | * Last resort will be re-try on the | |
3709 | * the current registered FCF entry. | |
3710 | */ | |
3711 | lpfc_retry_pport_discovery(phba); | |
38b92ef8 JS |
3712 | } else |
3713 | /* | |
3714 | * Reset FCF roundrobin bmask for new | |
3715 | * discovery. | |
3716 | */ | |
3717 | memset(phba->fcf.fcf_rr_bmask, 0, | |
3718 | sizeof(*phba->fcf.fcf_rr_bmask)); | |
6669f9bb JS |
3719 | } |
3720 | break; | |
da0436e9 JS |
3721 | default: |
3722 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3723 | "0288 Unknown FCoE event type 0x%x event tag " | |
70f3c073 | 3724 | "0x%x\n", event_type, acqe_fip->event_tag); |
da0436e9 JS |
3725 | break; |
3726 | } | |
3727 | } | |
3728 | ||
3729 | /** | |
3730 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event | |
3731 | * @phba: pointer to lpfc hba data structure. | |
3732 | * @acqe_link: pointer to the async dcbx completion queue entry. | |
3733 | * | |
3734 | * This routine is to handle the SLI4 asynchronous dcbx event. | |
3735 | **/ | |
3736 | static void | |
3737 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, | |
3738 | struct lpfc_acqe_dcbx *acqe_dcbx) | |
3739 | { | |
4d9ab994 | 3740 | phba->fc_eventTag = acqe_dcbx->event_tag; |
da0436e9 JS |
3741 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
3742 | "0290 The SLI4 DCBX asynchronous event is not " | |
3743 | "handled yet\n"); | |
3744 | } | |
3745 | ||
b19a061a JS |
3746 | /** |
3747 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event | |
3748 | * @phba: pointer to lpfc hba data structure. | |
3749 | * @acqe_link: pointer to the async grp5 completion queue entry. | |
3750 | * | |
3751 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event | |
3752 | * is an asynchronous notified of a logical link speed change. The Port | |
3753 | * reports the logical link speed in units of 10Mbps. | |
3754 | **/ | |
3755 | static void | |
3756 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, | |
3757 | struct lpfc_acqe_grp5 *acqe_grp5) | |
3758 | { | |
3759 | uint16_t prev_ll_spd; | |
3760 | ||
3761 | phba->fc_eventTag = acqe_grp5->event_tag; | |
3762 | phba->fcoe_eventtag = acqe_grp5->event_tag; | |
3763 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; | |
3764 | phba->sli4_hba.link_state.logical_speed = | |
3765 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)); | |
3766 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3767 | "2789 GRP5 Async Event: Updating logical link speed " | |
3768 | "from %dMbps to %dMbps\n", (prev_ll_spd * 10), | |
3769 | (phba->sli4_hba.link_state.logical_speed*10)); | |
3770 | } | |
3771 | ||
da0436e9 JS |
3772 | /** |
3773 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event | |
3774 | * @phba: pointer to lpfc hba data structure. | |
3775 | * | |
3776 | * This routine is invoked by the worker thread to process all the pending | |
3777 | * SLI4 asynchronous events. | |
3778 | **/ | |
3779 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) | |
3780 | { | |
3781 | struct lpfc_cq_event *cq_event; | |
3782 | ||
3783 | /* First, declare the async event has been handled */ | |
3784 | spin_lock_irq(&phba->hbalock); | |
3785 | phba->hba_flag &= ~ASYNC_EVENT; | |
3786 | spin_unlock_irq(&phba->hbalock); | |
3787 | /* Now, handle all the async events */ | |
3788 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { | |
3789 | /* Get the first event from the head of the event queue */ | |
3790 | spin_lock_irq(&phba->hbalock); | |
3791 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, | |
3792 | cq_event, struct lpfc_cq_event, list); | |
3793 | spin_unlock_irq(&phba->hbalock); | |
3794 | /* Process the asynchronous event */ | |
3795 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { | |
3796 | case LPFC_TRAILER_CODE_LINK: | |
3797 | lpfc_sli4_async_link_evt(phba, | |
3798 | &cq_event->cqe.acqe_link); | |
3799 | break; | |
3800 | case LPFC_TRAILER_CODE_FCOE: | |
70f3c073 | 3801 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
da0436e9 JS |
3802 | break; |
3803 | case LPFC_TRAILER_CODE_DCBX: | |
3804 | lpfc_sli4_async_dcbx_evt(phba, | |
3805 | &cq_event->cqe.acqe_dcbx); | |
3806 | break; | |
b19a061a JS |
3807 | case LPFC_TRAILER_CODE_GRP5: |
3808 | lpfc_sli4_async_grp5_evt(phba, | |
3809 | &cq_event->cqe.acqe_grp5); | |
3810 | break; | |
70f3c073 JS |
3811 | case LPFC_TRAILER_CODE_FC: |
3812 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); | |
3813 | break; | |
3814 | case LPFC_TRAILER_CODE_SLI: | |
3815 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); | |
3816 | break; | |
da0436e9 JS |
3817 | default: |
3818 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3819 | "1804 Invalid asynchrous event code: " | |
3820 | "x%x\n", bf_get(lpfc_trailer_code, | |
3821 | &cq_event->cqe.mcqe_cmpl)); | |
3822 | break; | |
3823 | } | |
3824 | /* Free the completion event processed to the free pool */ | |
3825 | lpfc_sli4_cq_event_release(phba, cq_event); | |
3826 | } | |
3827 | } | |
3828 | ||
ecfd03c6 JS |
3829 | /** |
3830 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event | |
3831 | * @phba: pointer to lpfc hba data structure. | |
3832 | * | |
3833 | * This routine is invoked by the worker thread to process FCF table | |
3834 | * rediscovery pending completion event. | |
3835 | **/ | |
3836 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) | |
3837 | { | |
3838 | int rc; | |
3839 | ||
3840 | spin_lock_irq(&phba->hbalock); | |
3841 | /* Clear FCF rediscovery timeout event */ | |
3842 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; | |
3843 | /* Clear driver fast failover FCF record flag */ | |
3844 | phba->fcf.failover_rec.flag = 0; | |
3845 | /* Set state for FCF fast failover */ | |
3846 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; | |
3847 | spin_unlock_irq(&phba->hbalock); | |
3848 | ||
3849 | /* Scan FCF table from the first entry to re-discover SAN */ | |
0c9ab6f5 | 3850 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
a93ff37a | 3851 | "2777 Start post-quiescent FCF table scan\n"); |
0c9ab6f5 | 3852 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
ecfd03c6 | 3853 | if (rc) |
0c9ab6f5 JS |
3854 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
3855 | "2747 Issue FCF scan read FCF mailbox " | |
3856 | "command failed 0x%x\n", rc); | |
ecfd03c6 JS |
3857 | } |
3858 | ||
da0436e9 JS |
3859 | /** |
3860 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table | |
3861 | * @phba: pointer to lpfc hba data structure. | |
3862 | * @dev_grp: The HBA PCI-Device group number. | |
3863 | * | |
3864 | * This routine is invoked to set up the per HBA PCI-Device group function | |
3865 | * API jump table entries. | |
3866 | * | |
3867 | * Return: 0 if success, otherwise -ENODEV | |
3868 | **/ | |
3869 | int | |
3870 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
3871 | { | |
3872 | int rc; | |
3873 | ||
3874 | /* Set up lpfc PCI-device group */ | |
3875 | phba->pci_dev_grp = dev_grp; | |
3876 | ||
3877 | /* The LPFC_PCI_DEV_OC uses SLI4 */ | |
3878 | if (dev_grp == LPFC_PCI_DEV_OC) | |
3879 | phba->sli_rev = LPFC_SLI_REV4; | |
3880 | ||
3881 | /* Set up device INIT API function jump table */ | |
3882 | rc = lpfc_init_api_table_setup(phba, dev_grp); | |
3883 | if (rc) | |
3884 | return -ENODEV; | |
3885 | /* Set up SCSI API function jump table */ | |
3886 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); | |
3887 | if (rc) | |
3888 | return -ENODEV; | |
3889 | /* Set up SLI API function jump table */ | |
3890 | rc = lpfc_sli_api_table_setup(phba, dev_grp); | |
3891 | if (rc) | |
3892 | return -ENODEV; | |
3893 | /* Set up MBOX API function jump table */ | |
3894 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); | |
3895 | if (rc) | |
3896 | return -ENODEV; | |
3897 | ||
3898 | return 0; | |
5b75da2f JS |
3899 | } |
3900 | ||
3901 | /** | |
3621a710 | 3902 | * lpfc_log_intr_mode - Log the active interrupt mode |
5b75da2f JS |
3903 | * @phba: pointer to lpfc hba data structure. |
3904 | * @intr_mode: active interrupt mode adopted. | |
3905 | * | |
3906 | * This routine it invoked to log the currently used active interrupt mode | |
3907 | * to the device. | |
3772a991 JS |
3908 | **/ |
3909 | static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode) | |
5b75da2f JS |
3910 | { |
3911 | switch (intr_mode) { | |
3912 | case 0: | |
3913 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3914 | "0470 Enable INTx interrupt mode.\n"); | |
3915 | break; | |
3916 | case 1: | |
3917 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3918 | "0481 Enabled MSI interrupt mode.\n"); | |
3919 | break; | |
3920 | case 2: | |
3921 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3922 | "0480 Enabled MSI-X interrupt mode.\n"); | |
3923 | break; | |
3924 | default: | |
3925 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3926 | "0482 Illegal interrupt mode.\n"); | |
3927 | break; | |
3928 | } | |
3929 | return; | |
3930 | } | |
3931 | ||
5b75da2f | 3932 | /** |
3772a991 | 3933 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
5b75da2f JS |
3934 | * @phba: pointer to lpfc hba data structure. |
3935 | * | |
3772a991 JS |
3936 | * This routine is invoked to enable the PCI device that is common to all |
3937 | * PCI devices. | |
5b75da2f JS |
3938 | * |
3939 | * Return codes | |
af901ca1 | 3940 | * 0 - successful |
3772a991 | 3941 | * other values - error |
5b75da2f | 3942 | **/ |
3772a991 JS |
3943 | static int |
3944 | lpfc_enable_pci_dev(struct lpfc_hba *phba) | |
5b75da2f | 3945 | { |
3772a991 JS |
3946 | struct pci_dev *pdev; |
3947 | int bars; | |
5b75da2f | 3948 | |
3772a991 JS |
3949 | /* Obtain PCI device reference */ |
3950 | if (!phba->pcidev) | |
3951 | goto out_error; | |
3952 | else | |
3953 | pdev = phba->pcidev; | |
3954 | /* Select PCI BARs */ | |
3955 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
3956 | /* Enable PCI device */ | |
3957 | if (pci_enable_device_mem(pdev)) | |
3958 | goto out_error; | |
3959 | /* Request PCI resource for the device */ | |
3960 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) | |
3961 | goto out_disable_device; | |
3962 | /* Set up device as PCI master and save state for EEH */ | |
3963 | pci_set_master(pdev); | |
3964 | pci_try_set_mwi(pdev); | |
3965 | pci_save_state(pdev); | |
5b75da2f | 3966 | |
0558056c JS |
3967 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
3968 | if (pci_find_capability(pdev, PCI_CAP_ID_EXP)) | |
3969 | pdev->needs_freset = 1; | |
3970 | ||
3772a991 | 3971 | return 0; |
5b75da2f | 3972 | |
3772a991 JS |
3973 | out_disable_device: |
3974 | pci_disable_device(pdev); | |
3975 | out_error: | |
3976 | return -ENODEV; | |
5b75da2f JS |
3977 | } |
3978 | ||
3979 | /** | |
3772a991 | 3980 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
5b75da2f JS |
3981 | * @phba: pointer to lpfc hba data structure. |
3982 | * | |
3772a991 JS |
3983 | * This routine is invoked to disable the PCI device that is common to all |
3984 | * PCI devices. | |
5b75da2f JS |
3985 | **/ |
3986 | static void | |
3772a991 | 3987 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
5b75da2f | 3988 | { |
3772a991 JS |
3989 | struct pci_dev *pdev; |
3990 | int bars; | |
5b75da2f | 3991 | |
3772a991 JS |
3992 | /* Obtain PCI device reference */ |
3993 | if (!phba->pcidev) | |
3994 | return; | |
3995 | else | |
3996 | pdev = phba->pcidev; | |
3997 | /* Select PCI BARs */ | |
3998 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
3999 | /* Release PCI resource and disable PCI device */ | |
4000 | pci_release_selected_regions(pdev, bars); | |
4001 | pci_disable_device(pdev); | |
4002 | /* Null out PCI private reference to driver */ | |
4003 | pci_set_drvdata(pdev, NULL); | |
5b75da2f JS |
4004 | |
4005 | return; | |
4006 | } | |
4007 | ||
e59058c4 | 4008 | /** |
3772a991 JS |
4009 | * lpfc_reset_hba - Reset a hba |
4010 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 4011 | * |
3772a991 JS |
4012 | * This routine is invoked to reset a hba device. It brings the HBA |
4013 | * offline, performs a board restart, and then brings the board back | |
4014 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up | |
4015 | * on outstanding mailbox commands. | |
e59058c4 | 4016 | **/ |
3772a991 JS |
4017 | void |
4018 | lpfc_reset_hba(struct lpfc_hba *phba) | |
dea3101e | 4019 | { |
3772a991 JS |
4020 | /* If resets are disabled then set error state and return. */ |
4021 | if (!phba->cfg_enable_hba_reset) { | |
4022 | phba->link_state = LPFC_HBA_ERROR; | |
4023 | return; | |
4024 | } | |
4025 | lpfc_offline_prep(phba); | |
4026 | lpfc_offline(phba); | |
4027 | lpfc_sli_brdrestart(phba); | |
4028 | lpfc_online(phba); | |
4029 | lpfc_unblock_mgmt_io(phba); | |
4030 | } | |
dea3101e | 4031 | |
3772a991 JS |
4032 | /** |
4033 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. | |
4034 | * @phba: pointer to lpfc hba data structure. | |
4035 | * | |
4036 | * This routine is invoked to set up the driver internal resources specific to | |
4037 | * support the SLI-3 HBA device it attached to. | |
4038 | * | |
4039 | * Return codes | |
af901ca1 | 4040 | * 0 - successful |
3772a991 JS |
4041 | * other values - error |
4042 | **/ | |
4043 | static int | |
4044 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) | |
4045 | { | |
4046 | struct lpfc_sli *psli; | |
dea3101e | 4047 | |
2e0fef85 | 4048 | /* |
3772a991 | 4049 | * Initialize timers used by driver |
2e0fef85 | 4050 | */ |
dea3101e | 4051 | |
3772a991 | 4052 | /* Heartbeat timer */ |
858c9f6c JS |
4053 | init_timer(&phba->hb_tmofunc); |
4054 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
4055 | phba->hb_tmofunc.data = (unsigned long)phba; | |
4056 | ||
dea3101e | 4057 | psli = &phba->sli; |
3772a991 | 4058 | /* MBOX heartbeat timer */ |
dea3101e JB |
4059 | init_timer(&psli->mbox_tmo); |
4060 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
2e0fef85 | 4061 | psli->mbox_tmo.data = (unsigned long) phba; |
3772a991 | 4062 | /* FCP polling mode timer */ |
875fbdfe JSEC |
4063 | init_timer(&phba->fcp_poll_timer); |
4064 | phba->fcp_poll_timer.function = lpfc_poll_timeout; | |
2e0fef85 | 4065 | phba->fcp_poll_timer.data = (unsigned long) phba; |
3772a991 | 4066 | /* Fabric block timer */ |
92d7f7b0 JS |
4067 | init_timer(&phba->fabric_block_timer); |
4068 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
4069 | phba->fabric_block_timer.data = (unsigned long) phba; | |
3772a991 | 4070 | /* EA polling mode timer */ |
9399627f JS |
4071 | init_timer(&phba->eratt_poll); |
4072 | phba->eratt_poll.function = lpfc_poll_eratt; | |
4073 | phba->eratt_poll.data = (unsigned long) phba; | |
dea3101e | 4074 | |
3772a991 JS |
4075 | /* Host attention work mask setup */ |
4076 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); | |
4077 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); | |
dea3101e | 4078 | |
3772a991 JS |
4079 | /* Get all the module params for configuring this host */ |
4080 | lpfc_get_cfgparam(phba); | |
49198b37 JS |
4081 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
4082 | phba->menlo_flag |= HBA_MENLO_SUPPORT; | |
4083 | /* check for menlo minimum sg count */ | |
4084 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) | |
4085 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; | |
4086 | } | |
4087 | ||
dea3101e | 4088 | /* |
3772a991 JS |
4089 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size |
4090 | * used to create the sg_dma_buf_pool must be dynamically calculated. | |
4091 | * 2 segments are added since the IOCB needs a command and response bde. | |
dea3101e | 4092 | */ |
3772a991 JS |
4093 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
4094 | sizeof(struct fcp_rsp) + | |
4095 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); | |
4096 | ||
4097 | if (phba->cfg_enable_bg) { | |
4098 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT; | |
4099 | phba->cfg_sg_dma_buf_size += | |
4100 | phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64); | |
901a920f | 4101 | } |
dea3101e | 4102 | |
3772a991 JS |
4103 | /* Also reinitialize the host templates with new values. */ |
4104 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
4105 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
dea3101e | 4106 | |
3772a991 JS |
4107 | phba->max_vpi = LPFC_MAX_VPI; |
4108 | /* This will be set to correct value after config_port mbox */ | |
4109 | phba->max_vports = 0; | |
dea3101e | 4110 | |
3772a991 JS |
4111 | /* |
4112 | * Initialize the SLI Layer to run with lpfc HBAs. | |
4113 | */ | |
4114 | lpfc_sli_setup(phba); | |
4115 | lpfc_sli_queue_setup(phba); | |
ed957684 | 4116 | |
3772a991 JS |
4117 | /* Allocate device driver memory */ |
4118 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) | |
4119 | return -ENOMEM; | |
51ef4c26 | 4120 | |
3772a991 JS |
4121 | return 0; |
4122 | } | |
ed957684 | 4123 | |
3772a991 JS |
4124 | /** |
4125 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev | |
4126 | * @phba: pointer to lpfc hba data structure. | |
4127 | * | |
4128 | * This routine is invoked to unset the driver internal resources set up | |
4129 | * specific for supporting the SLI-3 HBA device it attached to. | |
4130 | **/ | |
4131 | static void | |
4132 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) | |
4133 | { | |
4134 | /* Free device driver memory allocated */ | |
4135 | lpfc_mem_free_all(phba); | |
3163f725 | 4136 | |
3772a991 JS |
4137 | return; |
4138 | } | |
dea3101e | 4139 | |
3772a991 | 4140 | /** |
da0436e9 | 4141 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
3772a991 JS |
4142 | * @phba: pointer to lpfc hba data structure. |
4143 | * | |
da0436e9 JS |
4144 | * This routine is invoked to set up the driver internal resources specific to |
4145 | * support the SLI-4 HBA device it attached to. | |
3772a991 JS |
4146 | * |
4147 | * Return codes | |
af901ca1 | 4148 | * 0 - successful |
da0436e9 | 4149 | * other values - error |
3772a991 JS |
4150 | **/ |
4151 | static int | |
da0436e9 | 4152 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
3772a991 | 4153 | { |
da0436e9 | 4154 | struct lpfc_sli *psli; |
28baac74 JS |
4155 | LPFC_MBOXQ_t *mboxq; |
4156 | int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size; | |
4157 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; | |
4158 | struct lpfc_mqe *mqe; | |
085c647c | 4159 | int longs, sli_family; |
da0436e9 JS |
4160 | |
4161 | /* Before proceed, wait for POST done and device ready */ | |
4162 | rc = lpfc_sli4_post_status_check(phba); | |
4163 | if (rc) | |
4164 | return -ENODEV; | |
4165 | ||
3772a991 | 4166 | /* |
da0436e9 | 4167 | * Initialize timers used by driver |
3772a991 | 4168 | */ |
3772a991 | 4169 | |
da0436e9 JS |
4170 | /* Heartbeat timer */ |
4171 | init_timer(&phba->hb_tmofunc); | |
4172 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
4173 | phba->hb_tmofunc.data = (unsigned long)phba; | |
19ca7609 JS |
4174 | init_timer(&phba->rrq_tmr); |
4175 | phba->rrq_tmr.function = lpfc_rrq_timeout; | |
4176 | phba->rrq_tmr.data = (unsigned long)phba; | |
3772a991 | 4177 | |
da0436e9 JS |
4178 | psli = &phba->sli; |
4179 | /* MBOX heartbeat timer */ | |
4180 | init_timer(&psli->mbox_tmo); | |
4181 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
4182 | psli->mbox_tmo.data = (unsigned long) phba; | |
4183 | /* Fabric block timer */ | |
4184 | init_timer(&phba->fabric_block_timer); | |
4185 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
4186 | phba->fabric_block_timer.data = (unsigned long) phba; | |
4187 | /* EA polling mode timer */ | |
4188 | init_timer(&phba->eratt_poll); | |
4189 | phba->eratt_poll.function = lpfc_poll_eratt; | |
4190 | phba->eratt_poll.data = (unsigned long) phba; | |
ecfd03c6 JS |
4191 | /* FCF rediscover timer */ |
4192 | init_timer(&phba->fcf.redisc_wait); | |
4193 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; | |
4194 | phba->fcf.redisc_wait.data = (unsigned long)phba; | |
4195 | ||
da0436e9 JS |
4196 | /* |
4197 | * We need to do a READ_CONFIG mailbox command here before | |
4198 | * calling lpfc_get_cfgparam. For VFs this will report the | |
4199 | * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings. | |
4200 | * All of the resources allocated | |
4201 | * for this Port are tied to these values. | |
4202 | */ | |
4203 | /* Get all the module params for configuring this host */ | |
4204 | lpfc_get_cfgparam(phba); | |
4205 | phba->max_vpi = LPFC_MAX_VPI; | |
4206 | /* This will be set to correct value after the read_config mbox */ | |
4207 | phba->max_vports = 0; | |
3772a991 | 4208 | |
da0436e9 JS |
4209 | /* Program the default value of vlan_id and fc_map */ |
4210 | phba->valid_vlan = 0; | |
4211 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4212 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4213 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
3772a991 | 4214 | |
da0436e9 JS |
4215 | /* |
4216 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size | |
4217 | * used to create the sg_dma_buf_pool must be dynamically calculated. | |
4218 | * 2 segments are added since the IOCB needs a command and response bde. | |
4219 | * To insure that the scsi sgl does not cross a 4k page boundary only | |
28baac74 | 4220 | * sgl sizes of must be a power of 2. |
da0436e9 | 4221 | */ |
28baac74 JS |
4222 | buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) + |
4223 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge))); | |
085c647c JS |
4224 | |
4225 | sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf); | |
4226 | max_buf_size = LPFC_SLI4_MAX_BUF_SIZE; | |
4227 | switch (sli_family) { | |
4228 | case LPFC_SLI_INTF_FAMILY_BE2: | |
4229 | case LPFC_SLI_INTF_FAMILY_BE3: | |
4230 | /* There is a single hint for BE - 2 pages per BPL. */ | |
4231 | if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) == | |
4232 | LPFC_SLI_INTF_SLI_HINT1_1) | |
4233 | max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE; | |
4234 | break; | |
4235 | case LPFC_SLI_INTF_FAMILY_LNCR_A0: | |
4236 | case LPFC_SLI_INTF_FAMILY_LNCR_B0: | |
4237 | default: | |
4238 | break; | |
4239 | } | |
28baac74 JS |
4240 | for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE; |
4241 | dma_buf_size < max_buf_size && buf_size > dma_buf_size; | |
4242 | dma_buf_size = dma_buf_size << 1) | |
4243 | ; | |
4244 | if (dma_buf_size == max_buf_size) | |
4245 | phba->cfg_sg_seg_cnt = (dma_buf_size - | |
4246 | sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) - | |
4247 | (2 * sizeof(struct sli4_sge))) / | |
4248 | sizeof(struct sli4_sge); | |
4249 | phba->cfg_sg_dma_buf_size = dma_buf_size; | |
3772a991 | 4250 | |
da0436e9 JS |
4251 | /* Initialize buffer queue management fields */ |
4252 | hbq_count = lpfc_sli_hbq_count(); | |
4253 | for (i = 0; i < hbq_count; ++i) | |
4254 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
4255 | INIT_LIST_HEAD(&phba->rb_pend_list); | |
4256 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; | |
4257 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; | |
3772a991 | 4258 | |
da0436e9 JS |
4259 | /* |
4260 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. | |
4261 | */ | |
4262 | /* Initialize the Abort scsi buffer list used by driver */ | |
4263 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
4264 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
4265 | /* This abort list used by worker thread */ | |
4266 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); | |
3772a991 | 4267 | |
da0436e9 JS |
4268 | /* |
4269 | * Initialize dirver internal slow-path work queues | |
4270 | */ | |
3772a991 | 4271 | |
da0436e9 JS |
4272 | /* Driver internel slow-path CQ Event pool */ |
4273 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); | |
4274 | /* Response IOCB work queue list */ | |
45ed1190 | 4275 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
da0436e9 JS |
4276 | /* Asynchronous event CQ Event work queue list */ |
4277 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); | |
4278 | /* Fast-path XRI aborted CQ Event work queue list */ | |
4279 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
4280 | /* Slow-path XRI aborted CQ Event work queue list */ | |
4281 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
4282 | /* Receive queue CQ Event work queue list */ | |
4283 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); | |
4284 | ||
4285 | /* Initialize the driver internal SLI layer lists. */ | |
4286 | lpfc_sli_setup(phba); | |
4287 | lpfc_sli_queue_setup(phba); | |
3772a991 | 4288 | |
da0436e9 JS |
4289 | /* Allocate device driver memory */ |
4290 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); | |
4291 | if (rc) | |
4292 | return -ENOMEM; | |
4293 | ||
2fcee4bf JS |
4294 | /* IF Type 2 ports get initialized now. */ |
4295 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
4296 | LPFC_SLI_INTF_IF_TYPE_2) { | |
4297 | rc = lpfc_pci_function_reset(phba); | |
4298 | if (unlikely(rc)) | |
4299 | return -ENODEV; | |
4300 | } | |
4301 | ||
da0436e9 JS |
4302 | /* Create the bootstrap mailbox command */ |
4303 | rc = lpfc_create_bootstrap_mbox(phba); | |
4304 | if (unlikely(rc)) | |
4305 | goto out_free_mem; | |
4306 | ||
4307 | /* Set up the host's endian order with the device. */ | |
4308 | rc = lpfc_setup_endian_order(phba); | |
4309 | if (unlikely(rc)) | |
4310 | goto out_free_bsmbx; | |
4311 | ||
4312 | /* Set up the hba's configuration parameters. */ | |
4313 | rc = lpfc_sli4_read_config(phba); | |
4314 | if (unlikely(rc)) | |
4315 | goto out_free_bsmbx; | |
4316 | ||
2fcee4bf JS |
4317 | /* IF Type 0 ports get initialized now. */ |
4318 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
4319 | LPFC_SLI_INTF_IF_TYPE_0) { | |
4320 | rc = lpfc_pci_function_reset(phba); | |
4321 | if (unlikely(rc)) | |
4322 | goto out_free_bsmbx; | |
4323 | } | |
da0436e9 | 4324 | |
cb5172ea JS |
4325 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
4326 | GFP_KERNEL); | |
4327 | if (!mboxq) { | |
4328 | rc = -ENOMEM; | |
4329 | goto out_free_bsmbx; | |
4330 | } | |
4331 | ||
fedd3b7b | 4332 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
cb5172ea JS |
4333 | lpfc_supported_pages(mboxq); |
4334 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
fedd3b7b JS |
4335 | if (!rc) { |
4336 | mqe = &mboxq->u.mqe; | |
4337 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), | |
4338 | LPFC_MAX_SUPPORTED_PAGES); | |
4339 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { | |
4340 | switch (pn_page[i]) { | |
4341 | case LPFC_SLI4_PARAMETERS: | |
4342 | phba->sli4_hba.pc_sli4_params.supported = 1; | |
4343 | break; | |
4344 | default: | |
4345 | break; | |
4346 | } | |
4347 | } | |
4348 | /* Read the port's SLI4 Parameters capabilities if supported. */ | |
4349 | if (phba->sli4_hba.pc_sli4_params.supported) | |
4350 | rc = lpfc_pc_sli4_params_get(phba, mboxq); | |
4351 | if (rc) { | |
4352 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4353 | rc = -EIO; | |
4354 | goto out_free_bsmbx; | |
cb5172ea JS |
4355 | } |
4356 | } | |
fedd3b7b JS |
4357 | /* |
4358 | * Get sli4 parameters that override parameters from Port capabilities. | |
4359 | * If this call fails it is not a critical error so continue loading. | |
4360 | */ | |
4361 | lpfc_get_sli4_parameters(phba, mboxq); | |
cb5172ea | 4362 | mempool_free(mboxq, phba->mbox_mem_pool); |
da0436e9 JS |
4363 | /* Create all the SLI4 queues */ |
4364 | rc = lpfc_sli4_queue_create(phba); | |
4365 | if (rc) | |
4366 | goto out_free_bsmbx; | |
4367 | ||
4368 | /* Create driver internal CQE event pool */ | |
4369 | rc = lpfc_sli4_cq_event_pool_create(phba); | |
4370 | if (rc) | |
4371 | goto out_destroy_queue; | |
4372 | ||
4373 | /* Initialize and populate the iocb list per host */ | |
4374 | rc = lpfc_init_sgl_list(phba); | |
4375 | if (rc) { | |
4376 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4377 | "1400 Failed to initialize sgl list.\n"); | |
4378 | goto out_destroy_cq_event_pool; | |
4379 | } | |
4380 | rc = lpfc_init_active_sgl_array(phba); | |
4381 | if (rc) { | |
4382 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4383 | "1430 Failed to initialize sgl list.\n"); | |
4384 | goto out_free_sgl_list; | |
4385 | } | |
4386 | ||
4387 | rc = lpfc_sli4_init_rpi_hdrs(phba); | |
4388 | if (rc) { | |
4389 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4390 | "1432 Failed to initialize rpi headers.\n"); | |
4391 | goto out_free_active_sgl; | |
4392 | } | |
4393 | ||
a93ff37a | 4394 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
0c9ab6f5 JS |
4395 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
4396 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), | |
4397 | GFP_KERNEL); | |
4398 | if (!phba->fcf.fcf_rr_bmask) { | |
4399 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4400 | "2759 Failed allocate memory for FCF round " | |
4401 | "robin failover bmask\n"); | |
0558056c | 4402 | rc = -ENOMEM; |
0c9ab6f5 JS |
4403 | goto out_remove_rpi_hdrs; |
4404 | } | |
4405 | ||
da0436e9 JS |
4406 | phba->sli4_hba.fcp_eq_hdl = kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * |
4407 | phba->cfg_fcp_eq_count), GFP_KERNEL); | |
4408 | if (!phba->sli4_hba.fcp_eq_hdl) { | |
4409 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4410 | "2572 Failed allocate memory for fast-path " | |
4411 | "per-EQ handle array\n"); | |
0558056c | 4412 | rc = -ENOMEM; |
0c9ab6f5 | 4413 | goto out_free_fcf_rr_bmask; |
da0436e9 JS |
4414 | } |
4415 | ||
4416 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * | |
4417 | phba->sli4_hba.cfg_eqn), GFP_KERNEL); | |
4418 | if (!phba->sli4_hba.msix_entries) { | |
4419 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4420 | "2573 Failed allocate memory for msi-x " | |
4421 | "interrupt vector entries\n"); | |
0558056c | 4422 | rc = -ENOMEM; |
da0436e9 JS |
4423 | goto out_free_fcp_eq_hdl; |
4424 | } | |
4425 | ||
4426 | return rc; | |
4427 | ||
4428 | out_free_fcp_eq_hdl: | |
4429 | kfree(phba->sli4_hba.fcp_eq_hdl); | |
0c9ab6f5 JS |
4430 | out_free_fcf_rr_bmask: |
4431 | kfree(phba->fcf.fcf_rr_bmask); | |
da0436e9 JS |
4432 | out_remove_rpi_hdrs: |
4433 | lpfc_sli4_remove_rpi_hdrs(phba); | |
4434 | out_free_active_sgl: | |
4435 | lpfc_free_active_sgl(phba); | |
4436 | out_free_sgl_list: | |
4437 | lpfc_free_sgl_list(phba); | |
4438 | out_destroy_cq_event_pool: | |
4439 | lpfc_sli4_cq_event_pool_destroy(phba); | |
4440 | out_destroy_queue: | |
4441 | lpfc_sli4_queue_destroy(phba); | |
4442 | out_free_bsmbx: | |
4443 | lpfc_destroy_bootstrap_mbox(phba); | |
4444 | out_free_mem: | |
4445 | lpfc_mem_free(phba); | |
4446 | return rc; | |
4447 | } | |
4448 | ||
4449 | /** | |
4450 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev | |
4451 | * @phba: pointer to lpfc hba data structure. | |
4452 | * | |
4453 | * This routine is invoked to unset the driver internal resources set up | |
4454 | * specific for supporting the SLI-4 HBA device it attached to. | |
4455 | **/ | |
4456 | static void | |
4457 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) | |
4458 | { | |
4459 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; | |
4460 | ||
da0436e9 JS |
4461 | /* Free memory allocated for msi-x interrupt vector entries */ |
4462 | kfree(phba->sli4_hba.msix_entries); | |
4463 | ||
4464 | /* Free memory allocated for fast-path work queue handles */ | |
4465 | kfree(phba->sli4_hba.fcp_eq_hdl); | |
4466 | ||
4467 | /* Free the allocated rpi headers. */ | |
4468 | lpfc_sli4_remove_rpi_hdrs(phba); | |
d11e31dd | 4469 | lpfc_sli4_remove_rpis(phba); |
da0436e9 | 4470 | |
0c9ab6f5 JS |
4471 | /* Free eligible FCF index bmask */ |
4472 | kfree(phba->fcf.fcf_rr_bmask); | |
4473 | ||
da0436e9 JS |
4474 | /* Free the ELS sgl list */ |
4475 | lpfc_free_active_sgl(phba); | |
4476 | lpfc_free_sgl_list(phba); | |
4477 | ||
4478 | /* Free the SCSI sgl management array */ | |
4479 | kfree(phba->sli4_hba.lpfc_scsi_psb_array); | |
4480 | ||
4481 | /* Free the SLI4 queues */ | |
4482 | lpfc_sli4_queue_destroy(phba); | |
4483 | ||
4484 | /* Free the completion queue EQ event pool */ | |
4485 | lpfc_sli4_cq_event_release_all(phba); | |
4486 | lpfc_sli4_cq_event_pool_destroy(phba); | |
4487 | ||
da0436e9 JS |
4488 | /* Free the bsmbx region. */ |
4489 | lpfc_destroy_bootstrap_mbox(phba); | |
4490 | ||
4491 | /* Free the SLI Layer memory with SLI4 HBAs */ | |
4492 | lpfc_mem_free_all(phba); | |
4493 | ||
4494 | /* Free the current connect table */ | |
4495 | list_for_each_entry_safe(conn_entry, next_conn_entry, | |
4d9ab994 JS |
4496 | &phba->fcf_conn_rec_list, list) { |
4497 | list_del_init(&conn_entry->list); | |
da0436e9 | 4498 | kfree(conn_entry); |
4d9ab994 | 4499 | } |
da0436e9 JS |
4500 | |
4501 | return; | |
4502 | } | |
4503 | ||
4504 | /** | |
25985edc | 4505 | * lpfc_init_api_table_setup - Set up init api function jump table |
da0436e9 JS |
4506 | * @phba: The hba struct for which this call is being executed. |
4507 | * @dev_grp: The HBA PCI-Device group number. | |
4508 | * | |
4509 | * This routine sets up the device INIT interface API function jump table | |
4510 | * in @phba struct. | |
4511 | * | |
4512 | * Returns: 0 - success, -ENODEV - failure. | |
4513 | **/ | |
4514 | int | |
4515 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
4516 | { | |
84d1b006 JS |
4517 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
4518 | phba->lpfc_hba_down_link = lpfc_hba_down_link; | |
7f86059a | 4519 | phba->lpfc_selective_reset = lpfc_selective_reset; |
da0436e9 JS |
4520 | switch (dev_grp) { |
4521 | case LPFC_PCI_DEV_LP: | |
4522 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; | |
4523 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; | |
4524 | phba->lpfc_stop_port = lpfc_stop_port_s3; | |
4525 | break; | |
4526 | case LPFC_PCI_DEV_OC: | |
4527 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; | |
4528 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; | |
4529 | phba->lpfc_stop_port = lpfc_stop_port_s4; | |
4530 | break; | |
4531 | default: | |
4532 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4533 | "1431 Invalid HBA PCI-device group: 0x%x\n", | |
4534 | dev_grp); | |
4535 | return -ENODEV; | |
4536 | break; | |
4537 | } | |
4538 | return 0; | |
4539 | } | |
4540 | ||
4541 | /** | |
4542 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. | |
4543 | * @phba: pointer to lpfc hba data structure. | |
4544 | * | |
4545 | * This routine is invoked to set up the driver internal resources before the | |
4546 | * device specific resource setup to support the HBA device it attached to. | |
4547 | * | |
4548 | * Return codes | |
af901ca1 | 4549 | * 0 - successful |
da0436e9 JS |
4550 | * other values - error |
4551 | **/ | |
4552 | static int | |
4553 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) | |
4554 | { | |
4555 | /* | |
4556 | * Driver resources common to all SLI revisions | |
4557 | */ | |
4558 | atomic_set(&phba->fast_event_count, 0); | |
4559 | spin_lock_init(&phba->hbalock); | |
4560 | ||
4561 | /* Initialize ndlp management spinlock */ | |
4562 | spin_lock_init(&phba->ndlp_lock); | |
4563 | ||
4564 | INIT_LIST_HEAD(&phba->port_list); | |
4565 | INIT_LIST_HEAD(&phba->work_list); | |
4566 | init_waitqueue_head(&phba->wait_4_mlo_m_q); | |
4567 | ||
4568 | /* Initialize the wait queue head for the kernel thread */ | |
4569 | init_waitqueue_head(&phba->work_waitq); | |
4570 | ||
4571 | /* Initialize the scsi buffer list used by driver for scsi IO */ | |
4572 | spin_lock_init(&phba->scsi_buf_list_lock); | |
4573 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); | |
4574 | ||
4575 | /* Initialize the fabric iocb list */ | |
4576 | INIT_LIST_HEAD(&phba->fabric_iocb_list); | |
4577 | ||
4578 | /* Initialize list to save ELS buffers */ | |
4579 | INIT_LIST_HEAD(&phba->elsbuf); | |
4580 | ||
4581 | /* Initialize FCF connection rec list */ | |
4582 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); | |
4583 | ||
4584 | return 0; | |
4585 | } | |
4586 | ||
4587 | /** | |
4588 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. | |
4589 | * @phba: pointer to lpfc hba data structure. | |
4590 | * | |
4591 | * This routine is invoked to set up the driver internal resources after the | |
4592 | * device specific resource setup to support the HBA device it attached to. | |
4593 | * | |
4594 | * Return codes | |
af901ca1 | 4595 | * 0 - successful |
da0436e9 JS |
4596 | * other values - error |
4597 | **/ | |
4598 | static int | |
4599 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) | |
4600 | { | |
4601 | int error; | |
4602 | ||
4603 | /* Startup the kernel thread for this host adapter. */ | |
4604 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
4605 | "lpfc_worker_%d", phba->brd_no); | |
4606 | if (IS_ERR(phba->worker_thread)) { | |
4607 | error = PTR_ERR(phba->worker_thread); | |
4608 | return error; | |
3772a991 JS |
4609 | } |
4610 | ||
4611 | return 0; | |
4612 | } | |
4613 | ||
4614 | /** | |
4615 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. | |
4616 | * @phba: pointer to lpfc hba data structure. | |
4617 | * | |
4618 | * This routine is invoked to unset the driver internal resources set up after | |
4619 | * the device specific resource setup for supporting the HBA device it | |
4620 | * attached to. | |
4621 | **/ | |
4622 | static void | |
4623 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) | |
4624 | { | |
4625 | /* Stop kernel worker thread */ | |
4626 | kthread_stop(phba->worker_thread); | |
4627 | } | |
4628 | ||
4629 | /** | |
4630 | * lpfc_free_iocb_list - Free iocb list. | |
4631 | * @phba: pointer to lpfc hba data structure. | |
4632 | * | |
4633 | * This routine is invoked to free the driver's IOCB list and memory. | |
4634 | **/ | |
4635 | static void | |
4636 | lpfc_free_iocb_list(struct lpfc_hba *phba) | |
4637 | { | |
4638 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; | |
4639 | ||
4640 | spin_lock_irq(&phba->hbalock); | |
4641 | list_for_each_entry_safe(iocbq_entry, iocbq_next, | |
4642 | &phba->lpfc_iocb_list, list) { | |
4643 | list_del(&iocbq_entry->list); | |
4644 | kfree(iocbq_entry); | |
4645 | phba->total_iocbq_bufs--; | |
98c9ea5c | 4646 | } |
3772a991 JS |
4647 | spin_unlock_irq(&phba->hbalock); |
4648 | ||
4649 | return; | |
4650 | } | |
4651 | ||
4652 | /** | |
4653 | * lpfc_init_iocb_list - Allocate and initialize iocb list. | |
4654 | * @phba: pointer to lpfc hba data structure. | |
4655 | * | |
4656 | * This routine is invoked to allocate and initizlize the driver's IOCB | |
4657 | * list and set up the IOCB tag array accordingly. | |
4658 | * | |
4659 | * Return codes | |
af901ca1 | 4660 | * 0 - successful |
3772a991 JS |
4661 | * other values - error |
4662 | **/ | |
4663 | static int | |
4664 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) | |
4665 | { | |
4666 | struct lpfc_iocbq *iocbq_entry = NULL; | |
4667 | uint16_t iotag; | |
4668 | int i; | |
dea3101e JB |
4669 | |
4670 | /* Initialize and populate the iocb list per host. */ | |
4671 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); | |
3772a991 | 4672 | for (i = 0; i < iocb_count; i++) { |
dd00cc48 | 4673 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
dea3101e JB |
4674 | if (iocbq_entry == NULL) { |
4675 | printk(KERN_ERR "%s: only allocated %d iocbs of " | |
4676 | "expected %d count. Unloading driver.\n", | |
cadbd4a5 | 4677 | __func__, i, LPFC_IOCB_LIST_CNT); |
dea3101e JB |
4678 | goto out_free_iocbq; |
4679 | } | |
4680 | ||
604a3e30 JB |
4681 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
4682 | if (iotag == 0) { | |
3772a991 | 4683 | kfree(iocbq_entry); |
604a3e30 | 4684 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
3772a991 | 4685 | "Unloading driver.\n", __func__); |
604a3e30 JB |
4686 | goto out_free_iocbq; |
4687 | } | |
3772a991 | 4688 | iocbq_entry->sli4_xritag = NO_XRI; |
2e0fef85 JS |
4689 | |
4690 | spin_lock_irq(&phba->hbalock); | |
dea3101e JB |
4691 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
4692 | phba->total_iocbq_bufs++; | |
2e0fef85 | 4693 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4694 | } |
4695 | ||
3772a991 | 4696 | return 0; |
dea3101e | 4697 | |
3772a991 JS |
4698 | out_free_iocbq: |
4699 | lpfc_free_iocb_list(phba); | |
dea3101e | 4700 | |
3772a991 JS |
4701 | return -ENOMEM; |
4702 | } | |
5e9d9b82 | 4703 | |
3772a991 | 4704 | /** |
da0436e9 JS |
4705 | * lpfc_free_sgl_list - Free sgl list. |
4706 | * @phba: pointer to lpfc hba data structure. | |
3772a991 | 4707 | * |
da0436e9 | 4708 | * This routine is invoked to free the driver's sgl list and memory. |
3772a991 | 4709 | **/ |
da0436e9 JS |
4710 | static void |
4711 | lpfc_free_sgl_list(struct lpfc_hba *phba) | |
3772a991 | 4712 | { |
da0436e9 JS |
4713 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
4714 | LIST_HEAD(sglq_list); | |
dea3101e | 4715 | |
da0436e9 JS |
4716 | spin_lock_irq(&phba->hbalock); |
4717 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); | |
4718 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 4719 | |
da0436e9 JS |
4720 | list_for_each_entry_safe(sglq_entry, sglq_next, |
4721 | &sglq_list, list) { | |
4722 | list_del(&sglq_entry->list); | |
4723 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); | |
4724 | kfree(sglq_entry); | |
4725 | phba->sli4_hba.total_sglq_bufs--; | |
4726 | } | |
da0436e9 JS |
4727 | kfree(phba->sli4_hba.lpfc_els_sgl_array); |
4728 | } | |
92d7f7b0 | 4729 | |
da0436e9 JS |
4730 | /** |
4731 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. | |
4732 | * @phba: pointer to lpfc hba data structure. | |
4733 | * | |
4734 | * This routine is invoked to allocate the driver's active sgl memory. | |
4735 | * This array will hold the sglq_entry's for active IOs. | |
4736 | **/ | |
4737 | static int | |
4738 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) | |
4739 | { | |
4740 | int size; | |
4741 | size = sizeof(struct lpfc_sglq *); | |
4742 | size *= phba->sli4_hba.max_cfg_param.max_xri; | |
4743 | ||
4744 | phba->sli4_hba.lpfc_sglq_active_list = | |
4745 | kzalloc(size, GFP_KERNEL); | |
4746 | if (!phba->sli4_hba.lpfc_sglq_active_list) | |
4747 | return -ENOMEM; | |
4748 | return 0; | |
3772a991 JS |
4749 | } |
4750 | ||
4751 | /** | |
da0436e9 | 4752 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
3772a991 JS |
4753 | * @phba: pointer to lpfc hba data structure. |
4754 | * | |
da0436e9 JS |
4755 | * This routine is invoked to walk through the array of active sglq entries |
4756 | * and free all of the resources. | |
4757 | * This is just a place holder for now. | |
3772a991 JS |
4758 | **/ |
4759 | static void | |
da0436e9 | 4760 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
3772a991 | 4761 | { |
da0436e9 | 4762 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
3772a991 JS |
4763 | } |
4764 | ||
4765 | /** | |
da0436e9 | 4766 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
3772a991 JS |
4767 | * @phba: pointer to lpfc hba data structure. |
4768 | * | |
da0436e9 JS |
4769 | * This routine is invoked to allocate and initizlize the driver's sgl |
4770 | * list and set up the sgl xritag tag array accordingly. | |
3772a991 JS |
4771 | * |
4772 | * Return codes | |
af901ca1 | 4773 | * 0 - successful |
da0436e9 | 4774 | * other values - error |
3772a991 JS |
4775 | **/ |
4776 | static int | |
da0436e9 | 4777 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
3772a991 | 4778 | { |
da0436e9 JS |
4779 | struct lpfc_sglq *sglq_entry = NULL; |
4780 | int i; | |
4781 | int els_xri_cnt; | |
4782 | ||
4783 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
4784 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4785 | "2400 lpfc_init_sgl_list els %d.\n", | |
4786 | els_xri_cnt); | |
4787 | /* Initialize and populate the sglq list per host/VF. */ | |
4788 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); | |
4789 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
4790 | ||
4791 | /* Sanity check on XRI management */ | |
4792 | if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) { | |
4793 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4794 | "2562 No room left for SCSI XRI allocation: " | |
4795 | "max_xri=%d, els_xri=%d\n", | |
4796 | phba->sli4_hba.max_cfg_param.max_xri, | |
4797 | els_xri_cnt); | |
4798 | return -ENOMEM; | |
4799 | } | |
3772a991 | 4800 | |
da0436e9 JS |
4801 | /* Allocate memory for the ELS XRI management array */ |
4802 | phba->sli4_hba.lpfc_els_sgl_array = | |
4803 | kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt), | |
4804 | GFP_KERNEL); | |
0ff10d46 | 4805 | |
da0436e9 JS |
4806 | if (!phba->sli4_hba.lpfc_els_sgl_array) { |
4807 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4808 | "2401 Failed to allocate memory for ELS " | |
4809 | "XRI management array of size %d.\n", | |
4810 | els_xri_cnt); | |
4811 | return -ENOMEM; | |
4812 | } | |
2e0fef85 | 4813 | |
da0436e9 JS |
4814 | /* Keep the SCSI XRI into the XRI management array */ |
4815 | phba->sli4_hba.scsi_xri_max = | |
4816 | phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; | |
4817 | phba->sli4_hba.scsi_xri_cnt = 0; | |
4818 | ||
4819 | phba->sli4_hba.lpfc_scsi_psb_array = | |
4820 | kzalloc((sizeof(struct lpfc_scsi_buf *) * | |
4821 | phba->sli4_hba.scsi_xri_max), GFP_KERNEL); | |
4822 | ||
4823 | if (!phba->sli4_hba.lpfc_scsi_psb_array) { | |
4824 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4825 | "2563 Failed to allocate memory for SCSI " | |
4826 | "XRI management array of size %d.\n", | |
4827 | phba->sli4_hba.scsi_xri_max); | |
4828 | kfree(phba->sli4_hba.lpfc_els_sgl_array); | |
4829 | return -ENOMEM; | |
4830 | } | |
4831 | ||
4832 | for (i = 0; i < els_xri_cnt; i++) { | |
4833 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL); | |
4834 | if (sglq_entry == NULL) { | |
4835 | printk(KERN_ERR "%s: only allocated %d sgls of " | |
4836 | "expected %d count. Unloading driver.\n", | |
4837 | __func__, i, els_xri_cnt); | |
4838 | goto out_free_mem; | |
4839 | } | |
4840 | ||
4841 | sglq_entry->sli4_xritag = lpfc_sli4_next_xritag(phba); | |
4842 | if (sglq_entry->sli4_xritag == NO_XRI) { | |
4843 | kfree(sglq_entry); | |
4844 | printk(KERN_ERR "%s: failed to allocate XRI.\n" | |
4845 | "Unloading driver.\n", __func__); | |
4846 | goto out_free_mem; | |
4847 | } | |
4848 | sglq_entry->buff_type = GEN_BUFF_TYPE; | |
4849 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys); | |
4850 | if (sglq_entry->virt == NULL) { | |
4851 | kfree(sglq_entry); | |
4852 | printk(KERN_ERR "%s: failed to allocate mbuf.\n" | |
4853 | "Unloading driver.\n", __func__); | |
4854 | goto out_free_mem; | |
4855 | } | |
4856 | sglq_entry->sgl = sglq_entry->virt; | |
4857 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); | |
4858 | ||
4859 | /* The list order is used by later block SGL registraton */ | |
4860 | spin_lock_irq(&phba->hbalock); | |
0f65ff68 | 4861 | sglq_entry->state = SGL_FREED; |
da0436e9 JS |
4862 | list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list); |
4863 | phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry; | |
4864 | phba->sli4_hba.total_sglq_bufs++; | |
4865 | spin_unlock_irq(&phba->hbalock); | |
4866 | } | |
4867 | return 0; | |
4868 | ||
4869 | out_free_mem: | |
4870 | kfree(phba->sli4_hba.lpfc_scsi_psb_array); | |
4871 | lpfc_free_sgl_list(phba); | |
4872 | return -ENOMEM; | |
4873 | } | |
4874 | ||
4875 | /** | |
4876 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port | |
4877 | * @phba: pointer to lpfc hba data structure. | |
4878 | * | |
4879 | * This routine is invoked to post rpi header templates to the | |
4880 | * HBA consistent with the SLI-4 interface spec. This routine | |
4881 | * posts a PAGE_SIZE memory region to the port to hold up to | |
4882 | * PAGE_SIZE modulo 64 rpi context headers. | |
4883 | * No locks are held here because this is an initialization routine | |
4884 | * called only from probe or lpfc_online when interrupts are not | |
4885 | * enabled and the driver is reinitializing the device. | |
4886 | * | |
4887 | * Return codes | |
af901ca1 | 4888 | * 0 - successful |
25985edc | 4889 | * -ENOMEM - No available memory |
d439d286 | 4890 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
4891 | **/ |
4892 | int | |
4893 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) | |
4894 | { | |
4895 | int rc = 0; | |
4896 | int longs; | |
4897 | uint16_t rpi_count; | |
4898 | struct lpfc_rpi_hdr *rpi_hdr; | |
4899 | ||
4900 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); | |
4901 | ||
4902 | /* | |
4903 | * Provision an rpi bitmask range for discovery. The total count | |
4904 | * is the difference between max and base + 1. | |
4905 | */ | |
4906 | rpi_count = phba->sli4_hba.max_cfg_param.rpi_base + | |
4907 | phba->sli4_hba.max_cfg_param.max_rpi - 1; | |
4908 | ||
4909 | longs = ((rpi_count) + BITS_PER_LONG - 1) / BITS_PER_LONG; | |
4910 | phba->sli4_hba.rpi_bmask = kzalloc(longs * sizeof(unsigned long), | |
4911 | GFP_KERNEL); | |
4912 | if (!phba->sli4_hba.rpi_bmask) | |
4913 | return -ENOMEM; | |
4914 | ||
4915 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
4916 | if (!rpi_hdr) { | |
4917 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
4918 | "0391 Error during rpi post operation\n"); | |
4919 | lpfc_sli4_remove_rpis(phba); | |
4920 | rc = -ENODEV; | |
4921 | } | |
4922 | ||
4923 | return rc; | |
4924 | } | |
4925 | ||
4926 | /** | |
4927 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region | |
4928 | * @phba: pointer to lpfc hba data structure. | |
4929 | * | |
4930 | * This routine is invoked to allocate a single 4KB memory region to | |
4931 | * support rpis and stores them in the phba. This single region | |
4932 | * provides support for up to 64 rpis. The region is used globally | |
4933 | * by the device. | |
4934 | * | |
4935 | * Returns: | |
4936 | * A valid rpi hdr on success. | |
4937 | * A NULL pointer on any failure. | |
4938 | **/ | |
4939 | struct lpfc_rpi_hdr * | |
4940 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) | |
4941 | { | |
4942 | uint16_t rpi_limit, curr_rpi_range; | |
4943 | struct lpfc_dmabuf *dmabuf; | |
4944 | struct lpfc_rpi_hdr *rpi_hdr; | |
9589b062 | 4945 | uint32_t rpi_count; |
da0436e9 JS |
4946 | |
4947 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + | |
4948 | phba->sli4_hba.max_cfg_param.max_rpi - 1; | |
4949 | ||
4950 | spin_lock_irq(&phba->hbalock); | |
4951 | curr_rpi_range = phba->sli4_hba.next_rpi; | |
4952 | spin_unlock_irq(&phba->hbalock); | |
4953 | ||
4954 | /* | |
4955 | * The port has a limited number of rpis. The increment here | |
4956 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value | |
4957 | * and to allow the full max_rpi range per port. | |
4958 | */ | |
4959 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) | |
9589b062 JS |
4960 | rpi_count = rpi_limit - curr_rpi_range; |
4961 | else | |
4962 | rpi_count = LPFC_RPI_HDR_COUNT; | |
da0436e9 JS |
4963 | |
4964 | /* | |
4965 | * First allocate the protocol header region for the port. The | |
4966 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. | |
4967 | */ | |
4968 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
4969 | if (!dmabuf) | |
4970 | return NULL; | |
4971 | ||
4972 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
4973 | LPFC_HDR_TEMPLATE_SIZE, | |
4974 | &dmabuf->phys, | |
4975 | GFP_KERNEL); | |
4976 | if (!dmabuf->virt) { | |
4977 | rpi_hdr = NULL; | |
4978 | goto err_free_dmabuf; | |
4979 | } | |
4980 | ||
4981 | memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE); | |
4982 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { | |
4983 | rpi_hdr = NULL; | |
4984 | goto err_free_coherent; | |
4985 | } | |
4986 | ||
4987 | /* Save the rpi header data for cleanup later. */ | |
4988 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); | |
4989 | if (!rpi_hdr) | |
4990 | goto err_free_coherent; | |
4991 | ||
4992 | rpi_hdr->dmabuf = dmabuf; | |
4993 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; | |
4994 | rpi_hdr->page_count = 1; | |
4995 | spin_lock_irq(&phba->hbalock); | |
4996 | rpi_hdr->start_rpi = phba->sli4_hba.next_rpi; | |
4997 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); | |
4998 | ||
4999 | /* | |
5000 | * The next_rpi stores the next module-64 rpi value to post | |
5001 | * in any subsequent rpi memory region postings. | |
5002 | */ | |
9589b062 | 5003 | phba->sli4_hba.next_rpi += rpi_count; |
da0436e9 JS |
5004 | spin_unlock_irq(&phba->hbalock); |
5005 | return rpi_hdr; | |
5006 | ||
5007 | err_free_coherent: | |
5008 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, | |
5009 | dmabuf->virt, dmabuf->phys); | |
5010 | err_free_dmabuf: | |
5011 | kfree(dmabuf); | |
5012 | return NULL; | |
5013 | } | |
5014 | ||
5015 | /** | |
5016 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions | |
5017 | * @phba: pointer to lpfc hba data structure. | |
5018 | * | |
5019 | * This routine is invoked to remove all memory resources allocated | |
5020 | * to support rpis. This routine presumes the caller has released all | |
5021 | * rpis consumed by fabric or port logins and is prepared to have | |
5022 | * the header pages removed. | |
5023 | **/ | |
5024 | void | |
5025 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) | |
5026 | { | |
5027 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; | |
5028 | ||
5029 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, | |
5030 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { | |
5031 | list_del(&rpi_hdr->list); | |
5032 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, | |
5033 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); | |
5034 | kfree(rpi_hdr->dmabuf); | |
5035 | kfree(rpi_hdr); | |
5036 | } | |
da0436e9 | 5037 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base; |
da0436e9 JS |
5038 | } |
5039 | ||
5040 | /** | |
5041 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. | |
5042 | * @pdev: pointer to pci device data structure. | |
5043 | * | |
5044 | * This routine is invoked to allocate the driver hba data structure for an | |
5045 | * HBA device. If the allocation is successful, the phba reference to the | |
5046 | * PCI device data structure is set. | |
5047 | * | |
5048 | * Return codes | |
af901ca1 | 5049 | * pointer to @phba - successful |
da0436e9 JS |
5050 | * NULL - error |
5051 | **/ | |
5052 | static struct lpfc_hba * | |
5053 | lpfc_hba_alloc(struct pci_dev *pdev) | |
5054 | { | |
5055 | struct lpfc_hba *phba; | |
5056 | ||
5057 | /* Allocate memory for HBA structure */ | |
5058 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); | |
5059 | if (!phba) { | |
e34ccdfe | 5060 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
da0436e9 JS |
5061 | return NULL; |
5062 | } | |
5063 | ||
5064 | /* Set reference to PCI device in HBA structure */ | |
5065 | phba->pcidev = pdev; | |
5066 | ||
5067 | /* Assign an unused board number */ | |
5068 | phba->brd_no = lpfc_get_instance(); | |
5069 | if (phba->brd_no < 0) { | |
5070 | kfree(phba); | |
5071 | return NULL; | |
5072 | } | |
5073 | ||
4fede78f | 5074 | spin_lock_init(&phba->ct_ev_lock); |
f1c3b0fc JS |
5075 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
5076 | ||
da0436e9 JS |
5077 | return phba; |
5078 | } | |
5079 | ||
5080 | /** | |
5081 | * lpfc_hba_free - Free driver hba data structure with a device. | |
5082 | * @phba: pointer to lpfc hba data structure. | |
5083 | * | |
5084 | * This routine is invoked to free the driver hba data structure with an | |
5085 | * HBA device. | |
5086 | **/ | |
5087 | static void | |
5088 | lpfc_hba_free(struct lpfc_hba *phba) | |
5089 | { | |
5090 | /* Release the driver assigned board number */ | |
5091 | idr_remove(&lpfc_hba_index, phba->brd_no); | |
5092 | ||
5093 | kfree(phba); | |
5094 | return; | |
5095 | } | |
5096 | ||
5097 | /** | |
5098 | * lpfc_create_shost - Create hba physical port with associated scsi host. | |
5099 | * @phba: pointer to lpfc hba data structure. | |
5100 | * | |
5101 | * This routine is invoked to create HBA physical port and associate a SCSI | |
5102 | * host with it. | |
5103 | * | |
5104 | * Return codes | |
af901ca1 | 5105 | * 0 - successful |
da0436e9 JS |
5106 | * other values - error |
5107 | **/ | |
5108 | static int | |
5109 | lpfc_create_shost(struct lpfc_hba *phba) | |
5110 | { | |
5111 | struct lpfc_vport *vport; | |
5112 | struct Scsi_Host *shost; | |
5113 | ||
5114 | /* Initialize HBA FC structure */ | |
5115 | phba->fc_edtov = FF_DEF_EDTOV; | |
5116 | phba->fc_ratov = FF_DEF_RATOV; | |
5117 | phba->fc_altov = FF_DEF_ALTOV; | |
5118 | phba->fc_arbtov = FF_DEF_ARBTOV; | |
5119 | ||
d7c47992 | 5120 | atomic_set(&phba->sdev_cnt, 0); |
da0436e9 JS |
5121 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
5122 | if (!vport) | |
5123 | return -ENODEV; | |
5124 | ||
5125 | shost = lpfc_shost_from_vport(vport); | |
5126 | phba->pport = vport; | |
5127 | lpfc_debugfs_initialize(vport); | |
5128 | /* Put reference to SCSI host to driver's device private data */ | |
5129 | pci_set_drvdata(phba->pcidev, shost); | |
2e0fef85 | 5130 | |
3772a991 JS |
5131 | return 0; |
5132 | } | |
db2378e0 | 5133 | |
3772a991 JS |
5134 | /** |
5135 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. | |
5136 | * @phba: pointer to lpfc hba data structure. | |
5137 | * | |
5138 | * This routine is invoked to destroy HBA physical port and the associated | |
5139 | * SCSI host. | |
5140 | **/ | |
5141 | static void | |
5142 | lpfc_destroy_shost(struct lpfc_hba *phba) | |
5143 | { | |
5144 | struct lpfc_vport *vport = phba->pport; | |
5145 | ||
5146 | /* Destroy physical port that associated with the SCSI host */ | |
5147 | destroy_port(vport); | |
5148 | ||
5149 | return; | |
5150 | } | |
5151 | ||
5152 | /** | |
5153 | * lpfc_setup_bg - Setup Block guard structures and debug areas. | |
5154 | * @phba: pointer to lpfc hba data structure. | |
5155 | * @shost: the shost to be used to detect Block guard settings. | |
5156 | * | |
5157 | * This routine sets up the local Block guard protocol settings for @shost. | |
5158 | * This routine also allocates memory for debugging bg buffers. | |
5159 | **/ | |
5160 | static void | |
5161 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) | |
5162 | { | |
5163 | int pagecnt = 10; | |
5164 | if (lpfc_prot_mask && lpfc_prot_guard) { | |
5165 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5166 | "1478 Registering BlockGuard with the " | |
5167 | "SCSI layer\n"); | |
5168 | scsi_host_set_prot(shost, lpfc_prot_mask); | |
5169 | scsi_host_set_guard(shost, lpfc_prot_guard); | |
5170 | } | |
5171 | if (!_dump_buf_data) { | |
5172 | while (pagecnt) { | |
5173 | spin_lock_init(&_dump_buf_lock); | |
5174 | _dump_buf_data = | |
5175 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
5176 | if (_dump_buf_data) { | |
6a9c52cf JS |
5177 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5178 | "9043 BLKGRD: allocated %d pages for " | |
3772a991 JS |
5179 | "_dump_buf_data at 0x%p\n", |
5180 | (1 << pagecnt), _dump_buf_data); | |
5181 | _dump_buf_data_order = pagecnt; | |
5182 | memset(_dump_buf_data, 0, | |
5183 | ((1 << PAGE_SHIFT) << pagecnt)); | |
5184 | break; | |
5185 | } else | |
5186 | --pagecnt; | |
5187 | } | |
5188 | if (!_dump_buf_data_order) | |
6a9c52cf JS |
5189 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5190 | "9044 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
5191 | "memory for hexdump\n"); |
5192 | } else | |
6a9c52cf JS |
5193 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5194 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" | |
3772a991 JS |
5195 | "\n", _dump_buf_data); |
5196 | if (!_dump_buf_dif) { | |
5197 | while (pagecnt) { | |
5198 | _dump_buf_dif = | |
5199 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
5200 | if (_dump_buf_dif) { | |
6a9c52cf JS |
5201 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5202 | "9046 BLKGRD: allocated %d pages for " | |
3772a991 JS |
5203 | "_dump_buf_dif at 0x%p\n", |
5204 | (1 << pagecnt), _dump_buf_dif); | |
5205 | _dump_buf_dif_order = pagecnt; | |
5206 | memset(_dump_buf_dif, 0, | |
5207 | ((1 << PAGE_SHIFT) << pagecnt)); | |
5208 | break; | |
5209 | } else | |
5210 | --pagecnt; | |
5211 | } | |
5212 | if (!_dump_buf_dif_order) | |
6a9c52cf JS |
5213 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5214 | "9047 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
5215 | "memory for hexdump\n"); |
5216 | } else | |
6a9c52cf JS |
5217 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5218 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", | |
3772a991 JS |
5219 | _dump_buf_dif); |
5220 | } | |
5221 | ||
5222 | /** | |
5223 | * lpfc_post_init_setup - Perform necessary device post initialization setup. | |
5224 | * @phba: pointer to lpfc hba data structure. | |
5225 | * | |
5226 | * This routine is invoked to perform all the necessary post initialization | |
5227 | * setup for the device. | |
5228 | **/ | |
5229 | static void | |
5230 | lpfc_post_init_setup(struct lpfc_hba *phba) | |
5231 | { | |
5232 | struct Scsi_Host *shost; | |
5233 | struct lpfc_adapter_event_header adapter_event; | |
5234 | ||
5235 | /* Get the default values for Model Name and Description */ | |
5236 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
5237 | ||
5238 | /* | |
5239 | * hba setup may have changed the hba_queue_depth so we need to | |
5240 | * adjust the value of can_queue. | |
5241 | */ | |
5242 | shost = pci_get_drvdata(phba->pcidev); | |
5243 | shost->can_queue = phba->cfg_hba_queue_depth - 10; | |
5244 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) | |
5245 | lpfc_setup_bg(phba, shost); | |
5246 | ||
5247 | lpfc_host_attrib_init(shost); | |
5248 | ||
5249 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | |
5250 | spin_lock_irq(shost->host_lock); | |
5251 | lpfc_poll_start_timer(phba); | |
5252 | spin_unlock_irq(shost->host_lock); | |
5253 | } | |
5254 | ||
5255 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5256 | "0428 Perform SCSI scan\n"); | |
5257 | /* Send board arrival event to upper layer */ | |
5258 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; | |
5259 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; | |
5260 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
5261 | sizeof(adapter_event), | |
5262 | (char *) &adapter_event, | |
5263 | LPFC_NL_VENDOR_ID); | |
5264 | return; | |
5265 | } | |
5266 | ||
5267 | /** | |
5268 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. | |
5269 | * @phba: pointer to lpfc hba data structure. | |
5270 | * | |
5271 | * This routine is invoked to set up the PCI device memory space for device | |
5272 | * with SLI-3 interface spec. | |
5273 | * | |
5274 | * Return codes | |
af901ca1 | 5275 | * 0 - successful |
3772a991 JS |
5276 | * other values - error |
5277 | **/ | |
5278 | static int | |
5279 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) | |
5280 | { | |
5281 | struct pci_dev *pdev; | |
5282 | unsigned long bar0map_len, bar2map_len; | |
5283 | int i, hbq_count; | |
5284 | void *ptr; | |
5285 | int error = -ENODEV; | |
5286 | ||
5287 | /* Obtain PCI device reference */ | |
5288 | if (!phba->pcidev) | |
5289 | return error; | |
5290 | else | |
5291 | pdev = phba->pcidev; | |
5292 | ||
5293 | /* Set the device DMA mask size */ | |
8e68597d MR |
5294 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
5295 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
5296 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
5297 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
3772a991 | 5298 | return error; |
8e68597d MR |
5299 | } |
5300 | } | |
3772a991 JS |
5301 | |
5302 | /* Get the bus address of Bar0 and Bar2 and the number of bytes | |
5303 | * required by each mapping. | |
5304 | */ | |
5305 | phba->pci_bar0_map = pci_resource_start(pdev, 0); | |
5306 | bar0map_len = pci_resource_len(pdev, 0); | |
5307 | ||
5308 | phba->pci_bar2_map = pci_resource_start(pdev, 2); | |
5309 | bar2map_len = pci_resource_len(pdev, 2); | |
5310 | ||
5311 | /* Map HBA SLIM to a kernel virtual address. */ | |
5312 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); | |
5313 | if (!phba->slim_memmap_p) { | |
5314 | dev_printk(KERN_ERR, &pdev->dev, | |
5315 | "ioremap failed for SLIM memory.\n"); | |
5316 | goto out; | |
5317 | } | |
5318 | ||
5319 | /* Map HBA Control Registers to a kernel virtual address. */ | |
5320 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); | |
5321 | if (!phba->ctrl_regs_memmap_p) { | |
5322 | dev_printk(KERN_ERR, &pdev->dev, | |
5323 | "ioremap failed for HBA control registers.\n"); | |
5324 | goto out_iounmap_slim; | |
5325 | } | |
5326 | ||
5327 | /* Allocate memory for SLI-2 structures */ | |
5328 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, | |
5329 | SLI2_SLIM_SIZE, | |
5330 | &phba->slim2p.phys, | |
5331 | GFP_KERNEL); | |
5332 | if (!phba->slim2p.virt) | |
5333 | goto out_iounmap; | |
5334 | ||
5335 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); | |
5336 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); | |
7a470277 JS |
5337 | phba->mbox_ext = (phba->slim2p.virt + |
5338 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); | |
3772a991 JS |
5339 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
5340 | phba->IOCBs = (phba->slim2p.virt + | |
5341 | offsetof(struct lpfc_sli2_slim, IOCBs)); | |
5342 | ||
5343 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, | |
5344 | lpfc_sli_hbq_size(), | |
5345 | &phba->hbqslimp.phys, | |
5346 | GFP_KERNEL); | |
5347 | if (!phba->hbqslimp.virt) | |
5348 | goto out_free_slim; | |
5349 | ||
5350 | hbq_count = lpfc_sli_hbq_count(); | |
5351 | ptr = phba->hbqslimp.virt; | |
5352 | for (i = 0; i < hbq_count; ++i) { | |
5353 | phba->hbqs[i].hbq_virt = ptr; | |
5354 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
5355 | ptr += (lpfc_hbq_defs[i]->entry_count * | |
5356 | sizeof(struct lpfc_hbq_entry)); | |
5357 | } | |
5358 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; | |
5359 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; | |
5360 | ||
5361 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); | |
5362 | ||
5363 | INIT_LIST_HEAD(&phba->rb_pend_list); | |
5364 | ||
5365 | phba->MBslimaddr = phba->slim_memmap_p; | |
5366 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; | |
5367 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; | |
5368 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; | |
5369 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; | |
5370 | ||
5371 | return 0; | |
5372 | ||
5373 | out_free_slim: | |
5374 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
5375 | phba->slim2p.virt, phba->slim2p.phys); | |
5376 | out_iounmap: | |
5377 | iounmap(phba->ctrl_regs_memmap_p); | |
5378 | out_iounmap_slim: | |
5379 | iounmap(phba->slim_memmap_p); | |
5380 | out: | |
5381 | return error; | |
5382 | } | |
5383 | ||
5384 | /** | |
5385 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. | |
5386 | * @phba: pointer to lpfc hba data structure. | |
5387 | * | |
5388 | * This routine is invoked to unset the PCI device memory space for device | |
5389 | * with SLI-3 interface spec. | |
5390 | **/ | |
5391 | static void | |
5392 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) | |
5393 | { | |
5394 | struct pci_dev *pdev; | |
5395 | ||
5396 | /* Obtain PCI device reference */ | |
5397 | if (!phba->pcidev) | |
5398 | return; | |
5399 | else | |
5400 | pdev = phba->pcidev; | |
5401 | ||
5402 | /* Free coherent DMA memory allocated */ | |
5403 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
5404 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
5405 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
5406 | phba->slim2p.virt, phba->slim2p.phys); | |
5407 | ||
5408 | /* I/O memory unmap */ | |
5409 | iounmap(phba->ctrl_regs_memmap_p); | |
5410 | iounmap(phba->slim_memmap_p); | |
5411 | ||
5412 | return; | |
5413 | } | |
5414 | ||
5415 | /** | |
da0436e9 | 5416 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
3772a991 JS |
5417 | * @phba: pointer to lpfc hba data structure. |
5418 | * | |
da0436e9 JS |
5419 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
5420 | * done and check status. | |
3772a991 | 5421 | * |
da0436e9 | 5422 | * Return 0 if successful, otherwise -ENODEV. |
3772a991 | 5423 | **/ |
da0436e9 JS |
5424 | int |
5425 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) | |
3772a991 | 5426 | { |
2fcee4bf JS |
5427 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
5428 | struct lpfc_register reg_data; | |
5429 | int i, port_error = 0; | |
5430 | uint32_t if_type; | |
3772a991 | 5431 | |
9940b97b JS |
5432 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
5433 | memset(®_data, 0, sizeof(reg_data)); | |
2fcee4bf | 5434 | if (!phba->sli4_hba.PSMPHRregaddr) |
da0436e9 | 5435 | return -ENODEV; |
3772a991 | 5436 | |
da0436e9 JS |
5437 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
5438 | for (i = 0; i < 3000; i++) { | |
9940b97b JS |
5439 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
5440 | &portsmphr_reg.word0) || | |
5441 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { | |
2fcee4bf | 5442 | /* Port has a fatal POST error, break out */ |
da0436e9 JS |
5443 | port_error = -ENODEV; |
5444 | break; | |
5445 | } | |
2fcee4bf JS |
5446 | if (LPFC_POST_STAGE_PORT_READY == |
5447 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) | |
da0436e9 | 5448 | break; |
da0436e9 | 5449 | msleep(10); |
3772a991 JS |
5450 | } |
5451 | ||
2fcee4bf JS |
5452 | /* |
5453 | * If there was a port error during POST, then don't proceed with | |
5454 | * other register reads as the data may not be valid. Just exit. | |
5455 | */ | |
5456 | if (port_error) { | |
da0436e9 | 5457 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2fcee4bf JS |
5458 | "1408 Port Failed POST - portsmphr=0x%x, " |
5459 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " | |
5460 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", | |
5461 | portsmphr_reg.word0, | |
5462 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), | |
5463 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), | |
5464 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), | |
5465 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), | |
5466 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), | |
5467 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), | |
5468 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), | |
5469 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); | |
5470 | } else { | |
28baac74 | 5471 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2fcee4bf JS |
5472 | "2534 Device Info: SLIFamily=0x%x, " |
5473 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " | |
5474 | "SLIHint_2=0x%x, FT=0x%x\n", | |
28baac74 JS |
5475 | bf_get(lpfc_sli_intf_sli_family, |
5476 | &phba->sli4_hba.sli_intf), | |
5477 | bf_get(lpfc_sli_intf_slirev, | |
5478 | &phba->sli4_hba.sli_intf), | |
085c647c JS |
5479 | bf_get(lpfc_sli_intf_if_type, |
5480 | &phba->sli4_hba.sli_intf), | |
5481 | bf_get(lpfc_sli_intf_sli_hint1, | |
28baac74 | 5482 | &phba->sli4_hba.sli_intf), |
085c647c JS |
5483 | bf_get(lpfc_sli_intf_sli_hint2, |
5484 | &phba->sli4_hba.sli_intf), | |
5485 | bf_get(lpfc_sli_intf_func_type, | |
28baac74 | 5486 | &phba->sli4_hba.sli_intf)); |
2fcee4bf JS |
5487 | /* |
5488 | * Check for other Port errors during the initialization | |
5489 | * process. Fail the load if the port did not come up | |
5490 | * correctly. | |
5491 | */ | |
5492 | if_type = bf_get(lpfc_sli_intf_if_type, | |
5493 | &phba->sli4_hba.sli_intf); | |
5494 | switch (if_type) { | |
5495 | case LPFC_SLI_INTF_IF_TYPE_0: | |
5496 | phba->sli4_hba.ue_mask_lo = | |
5497 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); | |
5498 | phba->sli4_hba.ue_mask_hi = | |
5499 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); | |
5500 | uerrlo_reg.word0 = | |
5501 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); | |
5502 | uerrhi_reg.word0 = | |
5503 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); | |
5504 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || | |
5505 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { | |
5506 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5507 | "1422 Unrecoverable Error " | |
5508 | "Detected during POST " | |
5509 | "uerr_lo_reg=0x%x, " | |
5510 | "uerr_hi_reg=0x%x, " | |
5511 | "ue_mask_lo_reg=0x%x, " | |
5512 | "ue_mask_hi_reg=0x%x\n", | |
5513 | uerrlo_reg.word0, | |
5514 | uerrhi_reg.word0, | |
5515 | phba->sli4_hba.ue_mask_lo, | |
5516 | phba->sli4_hba.ue_mask_hi); | |
5517 | port_error = -ENODEV; | |
5518 | } | |
5519 | break; | |
5520 | case LPFC_SLI_INTF_IF_TYPE_2: | |
5521 | /* Final checks. The port status should be clean. */ | |
9940b97b JS |
5522 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
5523 | ®_data.word0) || | |
0558056c JS |
5524 | (bf_get(lpfc_sliport_status_err, ®_data) && |
5525 | !bf_get(lpfc_sliport_status_rn, ®_data))) { | |
2fcee4bf JS |
5526 | phba->work_status[0] = |
5527 | readl(phba->sli4_hba.u.if_type2. | |
5528 | ERR1regaddr); | |
5529 | phba->work_status[1] = | |
5530 | readl(phba->sli4_hba.u.if_type2. | |
5531 | ERR2regaddr); | |
5532 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5533 | "2888 Port Error Detected " | |
5534 | "during POST: " | |
5535 | "port status reg 0x%x, " | |
5536 | "port_smphr reg 0x%x, " | |
5537 | "error 1=0x%x, error 2=0x%x\n", | |
5538 | reg_data.word0, | |
5539 | portsmphr_reg.word0, | |
5540 | phba->work_status[0], | |
5541 | phba->work_status[1]); | |
5542 | port_error = -ENODEV; | |
5543 | } | |
5544 | break; | |
5545 | case LPFC_SLI_INTF_IF_TYPE_1: | |
5546 | default: | |
5547 | break; | |
5548 | } | |
28baac74 | 5549 | } |
da0436e9 JS |
5550 | return port_error; |
5551 | } | |
3772a991 | 5552 | |
da0436e9 JS |
5553 | /** |
5554 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. | |
5555 | * @phba: pointer to lpfc hba data structure. | |
2fcee4bf | 5556 | * @if_type: The SLI4 interface type getting configured. |
da0436e9 JS |
5557 | * |
5558 | * This routine is invoked to set up SLI4 BAR0 PCI config space register | |
5559 | * memory map. | |
5560 | **/ | |
5561 | static void | |
2fcee4bf JS |
5562 | lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type) |
5563 | { | |
5564 | switch (if_type) { | |
5565 | case LPFC_SLI_INTF_IF_TYPE_0: | |
5566 | phba->sli4_hba.u.if_type0.UERRLOregaddr = | |
5567 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; | |
5568 | phba->sli4_hba.u.if_type0.UERRHIregaddr = | |
5569 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; | |
5570 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = | |
5571 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; | |
5572 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = | |
5573 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; | |
5574 | phba->sli4_hba.SLIINTFregaddr = | |
5575 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; | |
5576 | break; | |
5577 | case LPFC_SLI_INTF_IF_TYPE_2: | |
5578 | phba->sli4_hba.u.if_type2.ERR1regaddr = | |
5579 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLIPORT_ERR_1; | |
5580 | phba->sli4_hba.u.if_type2.ERR2regaddr = | |
5581 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLIPORT_ERR_2; | |
5582 | phba->sli4_hba.u.if_type2.CTRLregaddr = | |
5583 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLIPORT_CNTRL; | |
5584 | phba->sli4_hba.u.if_type2.STATUSregaddr = | |
5585 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLIPORT_STATUS; | |
5586 | phba->sli4_hba.SLIINTFregaddr = | |
5587 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; | |
5588 | phba->sli4_hba.PSMPHRregaddr = | |
5589 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLIPORT_IF2_SMPHR; | |
5590 | phba->sli4_hba.RQDBregaddr = | |
5591 | phba->sli4_hba.conf_regs_memmap_p + LPFC_RQ_DOORBELL; | |
5592 | phba->sli4_hba.WQDBregaddr = | |
5593 | phba->sli4_hba.conf_regs_memmap_p + LPFC_WQ_DOORBELL; | |
5594 | phba->sli4_hba.EQCQDBregaddr = | |
5595 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; | |
5596 | phba->sli4_hba.MQDBregaddr = | |
5597 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; | |
5598 | phba->sli4_hba.BMBXregaddr = | |
5599 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; | |
5600 | break; | |
5601 | case LPFC_SLI_INTF_IF_TYPE_1: | |
5602 | default: | |
5603 | dev_printk(KERN_ERR, &phba->pcidev->dev, | |
5604 | "FATAL - unsupported SLI4 interface type - %d\n", | |
5605 | if_type); | |
5606 | break; | |
5607 | } | |
da0436e9 | 5608 | } |
3772a991 | 5609 | |
da0436e9 JS |
5610 | /** |
5611 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. | |
5612 | * @phba: pointer to lpfc hba data structure. | |
5613 | * | |
5614 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) | |
5615 | * memory map. | |
5616 | **/ | |
5617 | static void | |
5618 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) | |
5619 | { | |
2fcee4bf JS |
5620 | phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
5621 | LPFC_SLIPORT_IF0_SMPHR; | |
da0436e9 | 5622 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 5623 | LPFC_HST_ISR0; |
da0436e9 | 5624 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 5625 | LPFC_HST_IMR0; |
da0436e9 | 5626 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 5627 | LPFC_HST_ISCR0; |
3772a991 JS |
5628 | } |
5629 | ||
5630 | /** | |
da0436e9 | 5631 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
3772a991 | 5632 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 5633 | * @vf: virtual function number |
3772a991 | 5634 | * |
da0436e9 JS |
5635 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
5636 | * based on the given viftual function number, @vf. | |
5637 | * | |
5638 | * Return 0 if successful, otherwise -ENODEV. | |
3772a991 | 5639 | **/ |
da0436e9 JS |
5640 | static int |
5641 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) | |
3772a991 | 5642 | { |
da0436e9 JS |
5643 | if (vf > LPFC_VIR_FUNC_MAX) |
5644 | return -ENODEV; | |
3772a991 | 5645 | |
da0436e9 JS |
5646 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
5647 | vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL); | |
5648 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5649 | vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL); | |
5650 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5651 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); | |
5652 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5653 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); | |
5654 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5655 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); | |
5656 | return 0; | |
3772a991 JS |
5657 | } |
5658 | ||
5659 | /** | |
da0436e9 | 5660 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
3772a991 JS |
5661 | * @phba: pointer to lpfc hba data structure. |
5662 | * | |
da0436e9 JS |
5663 | * This routine is invoked to create the bootstrap mailbox |
5664 | * region consistent with the SLI-4 interface spec. This | |
5665 | * routine allocates all memory necessary to communicate | |
5666 | * mailbox commands to the port and sets up all alignment | |
5667 | * needs. No locks are expected to be held when calling | |
5668 | * this routine. | |
3772a991 JS |
5669 | * |
5670 | * Return codes | |
af901ca1 | 5671 | * 0 - successful |
d439d286 | 5672 | * -ENOMEM - could not allocated memory. |
da0436e9 | 5673 | **/ |
3772a991 | 5674 | static int |
da0436e9 | 5675 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 5676 | { |
da0436e9 JS |
5677 | uint32_t bmbx_size; |
5678 | struct lpfc_dmabuf *dmabuf; | |
5679 | struct dma_address *dma_address; | |
5680 | uint32_t pa_addr; | |
5681 | uint64_t phys_addr; | |
5682 | ||
5683 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
5684 | if (!dmabuf) | |
5685 | return -ENOMEM; | |
3772a991 | 5686 | |
da0436e9 JS |
5687 | /* |
5688 | * The bootstrap mailbox region is comprised of 2 parts | |
5689 | * plus an alignment restriction of 16 bytes. | |
5690 | */ | |
5691 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); | |
5692 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
5693 | bmbx_size, | |
5694 | &dmabuf->phys, | |
5695 | GFP_KERNEL); | |
5696 | if (!dmabuf->virt) { | |
5697 | kfree(dmabuf); | |
5698 | return -ENOMEM; | |
3772a991 | 5699 | } |
da0436e9 | 5700 | memset(dmabuf->virt, 0, bmbx_size); |
3772a991 | 5701 | |
da0436e9 JS |
5702 | /* |
5703 | * Initialize the bootstrap mailbox pointers now so that the register | |
5704 | * operations are simple later. The mailbox dma address is required | |
5705 | * to be 16-byte aligned. Also align the virtual memory as each | |
5706 | * maibox is copied into the bmbx mailbox region before issuing the | |
5707 | * command to the port. | |
5708 | */ | |
5709 | phba->sli4_hba.bmbx.dmabuf = dmabuf; | |
5710 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; | |
5711 | ||
5712 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, | |
5713 | LPFC_ALIGN_16_BYTE); | |
5714 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, | |
5715 | LPFC_ALIGN_16_BYTE); | |
5716 | ||
5717 | /* | |
5718 | * Set the high and low physical addresses now. The SLI4 alignment | |
5719 | * requirement is 16 bytes and the mailbox is posted to the port | |
5720 | * as two 30-bit addresses. The other data is a bit marking whether | |
5721 | * the 30-bit address is the high or low address. | |
5722 | * Upcast bmbx aphys to 64bits so shift instruction compiles | |
5723 | * clean on 32 bit machines. | |
5724 | */ | |
5725 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
5726 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; | |
5727 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); | |
5728 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | | |
5729 | LPFC_BMBX_BIT1_ADDR_HI); | |
5730 | ||
5731 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); | |
5732 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | | |
5733 | LPFC_BMBX_BIT1_ADDR_LO); | |
5734 | return 0; | |
3772a991 JS |
5735 | } |
5736 | ||
5737 | /** | |
da0436e9 | 5738 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
3772a991 JS |
5739 | * @phba: pointer to lpfc hba data structure. |
5740 | * | |
da0436e9 JS |
5741 | * This routine is invoked to teardown the bootstrap mailbox |
5742 | * region and release all host resources. This routine requires | |
5743 | * the caller to ensure all mailbox commands recovered, no | |
5744 | * additional mailbox comands are sent, and interrupts are disabled | |
5745 | * before calling this routine. | |
5746 | * | |
5747 | **/ | |
3772a991 | 5748 | static void |
da0436e9 | 5749 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 5750 | { |
da0436e9 JS |
5751 | dma_free_coherent(&phba->pcidev->dev, |
5752 | phba->sli4_hba.bmbx.bmbx_size, | |
5753 | phba->sli4_hba.bmbx.dmabuf->virt, | |
5754 | phba->sli4_hba.bmbx.dmabuf->phys); | |
5755 | ||
5756 | kfree(phba->sli4_hba.bmbx.dmabuf); | |
5757 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); | |
3772a991 JS |
5758 | } |
5759 | ||
5760 | /** | |
da0436e9 | 5761 | * lpfc_sli4_read_config - Get the config parameters. |
3772a991 JS |
5762 | * @phba: pointer to lpfc hba data structure. |
5763 | * | |
da0436e9 JS |
5764 | * This routine is invoked to read the configuration parameters from the HBA. |
5765 | * The configuration parameters are used to set the base and maximum values | |
5766 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource | |
5767 | * allocation for the port. | |
3772a991 JS |
5768 | * |
5769 | * Return codes | |
af901ca1 | 5770 | * 0 - successful |
25985edc | 5771 | * -ENOMEM - No available memory |
d439d286 | 5772 | * -EIO - The mailbox failed to complete successfully. |
3772a991 | 5773 | **/ |
da0436e9 JS |
5774 | static int |
5775 | lpfc_sli4_read_config(struct lpfc_hba *phba) | |
3772a991 | 5776 | { |
da0436e9 JS |
5777 | LPFC_MBOXQ_t *pmb; |
5778 | struct lpfc_mbx_read_config *rd_config; | |
5779 | uint32_t rc = 0; | |
3772a991 | 5780 | |
da0436e9 JS |
5781 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
5782 | if (!pmb) { | |
5783 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5784 | "2011 Unable to allocate memory for issuing " | |
5785 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
5786 | return -ENOMEM; | |
3772a991 JS |
5787 | } |
5788 | ||
da0436e9 | 5789 | lpfc_read_config(phba, pmb); |
3772a991 | 5790 | |
da0436e9 JS |
5791 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
5792 | if (rc != MBX_SUCCESS) { | |
5793 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5794 | "2012 Mailbox failed , mbxCmd x%x " | |
5795 | "READ_CONFIG, mbxStatus x%x\n", | |
5796 | bf_get(lpfc_mqe_command, &pmb->u.mqe), | |
5797 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); | |
5798 | rc = -EIO; | |
5799 | } else { | |
5800 | rd_config = &pmb->u.mqe.un.rd_config; | |
5801 | phba->sli4_hba.max_cfg_param.max_xri = | |
5802 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); | |
5803 | phba->sli4_hba.max_cfg_param.xri_base = | |
5804 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); | |
5805 | phba->sli4_hba.max_cfg_param.max_vpi = | |
5806 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); | |
5807 | phba->sli4_hba.max_cfg_param.vpi_base = | |
5808 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); | |
5809 | phba->sli4_hba.max_cfg_param.max_rpi = | |
5810 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); | |
5811 | phba->sli4_hba.max_cfg_param.rpi_base = | |
5812 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); | |
5813 | phba->sli4_hba.max_cfg_param.max_vfi = | |
5814 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); | |
5815 | phba->sli4_hba.max_cfg_param.vfi_base = | |
5816 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); | |
5817 | phba->sli4_hba.max_cfg_param.max_fcfi = | |
5818 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); | |
5819 | phba->sli4_hba.max_cfg_param.fcfi_base = | |
5820 | bf_get(lpfc_mbx_rd_conf_fcfi_base, rd_config); | |
5821 | phba->sli4_hba.max_cfg_param.max_eq = | |
5822 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); | |
5823 | phba->sli4_hba.max_cfg_param.max_rq = | |
5824 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); | |
5825 | phba->sli4_hba.max_cfg_param.max_wq = | |
5826 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); | |
5827 | phba->sli4_hba.max_cfg_param.max_cq = | |
5828 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); | |
5829 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); | |
5830 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; | |
5831 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; | |
5832 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; | |
5833 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base; | |
5ffc266e JS |
5834 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
5835 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; | |
da0436e9 JS |
5836 | phba->max_vports = phba->max_vpi; |
5837 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
5838 | "2003 cfg params XRI(B:%d M:%d), " | |
5839 | "VPI(B:%d M:%d) " | |
5840 | "VFI(B:%d M:%d) " | |
5841 | "RPI(B:%d M:%d) " | |
5842 | "FCFI(B:%d M:%d)\n", | |
5843 | phba->sli4_hba.max_cfg_param.xri_base, | |
5844 | phba->sli4_hba.max_cfg_param.max_xri, | |
5845 | phba->sli4_hba.max_cfg_param.vpi_base, | |
5846 | phba->sli4_hba.max_cfg_param.max_vpi, | |
5847 | phba->sli4_hba.max_cfg_param.vfi_base, | |
5848 | phba->sli4_hba.max_cfg_param.max_vfi, | |
5849 | phba->sli4_hba.max_cfg_param.rpi_base, | |
5850 | phba->sli4_hba.max_cfg_param.max_rpi, | |
5851 | phba->sli4_hba.max_cfg_param.fcfi_base, | |
5852 | phba->sli4_hba.max_cfg_param.max_fcfi); | |
3772a991 | 5853 | } |
da0436e9 JS |
5854 | mempool_free(pmb, phba->mbox_mem_pool); |
5855 | ||
5856 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ | |
b92938b4 JS |
5857 | if (phba->cfg_hba_queue_depth > |
5858 | (phba->sli4_hba.max_cfg_param.max_xri - | |
5859 | lpfc_sli4_get_els_iocb_cnt(phba))) | |
da0436e9 | 5860 | phba->cfg_hba_queue_depth = |
b92938b4 JS |
5861 | phba->sli4_hba.max_cfg_param.max_xri - |
5862 | lpfc_sli4_get_els_iocb_cnt(phba); | |
da0436e9 | 5863 | return rc; |
3772a991 JS |
5864 | } |
5865 | ||
5866 | /** | |
2fcee4bf | 5867 | * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port. |
3772a991 JS |
5868 | * @phba: pointer to lpfc hba data structure. |
5869 | * | |
2fcee4bf JS |
5870 | * This routine is invoked to setup the port-side endian order when |
5871 | * the port if_type is 0. This routine has no function for other | |
5872 | * if_types. | |
da0436e9 JS |
5873 | * |
5874 | * Return codes | |
af901ca1 | 5875 | * 0 - successful |
25985edc | 5876 | * -ENOMEM - No available memory |
d439d286 | 5877 | * -EIO - The mailbox failed to complete successfully. |
3772a991 | 5878 | **/ |
da0436e9 JS |
5879 | static int |
5880 | lpfc_setup_endian_order(struct lpfc_hba *phba) | |
3772a991 | 5881 | { |
da0436e9 | 5882 | LPFC_MBOXQ_t *mboxq; |
2fcee4bf | 5883 | uint32_t if_type, rc = 0; |
da0436e9 JS |
5884 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
5885 | HOST_ENDIAN_HIGH_WORD1}; | |
3772a991 | 5886 | |
2fcee4bf JS |
5887 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
5888 | switch (if_type) { | |
5889 | case LPFC_SLI_INTF_IF_TYPE_0: | |
5890 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, | |
5891 | GFP_KERNEL); | |
5892 | if (!mboxq) { | |
5893 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5894 | "0492 Unable to allocate memory for " | |
5895 | "issuing SLI_CONFIG_SPECIAL mailbox " | |
5896 | "command\n"); | |
5897 | return -ENOMEM; | |
5898 | } | |
3772a991 | 5899 | |
2fcee4bf JS |
5900 | /* |
5901 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first | |
5902 | * two words to contain special data values and no other data. | |
5903 | */ | |
5904 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
5905 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); | |
5906 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
5907 | if (rc != MBX_SUCCESS) { | |
5908 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5909 | "0493 SLI_CONFIG_SPECIAL mailbox " | |
5910 | "failed with status x%x\n", | |
5911 | rc); | |
5912 | rc = -EIO; | |
5913 | } | |
5914 | mempool_free(mboxq, phba->mbox_mem_pool); | |
5915 | break; | |
5916 | case LPFC_SLI_INTF_IF_TYPE_2: | |
5917 | case LPFC_SLI_INTF_IF_TYPE_1: | |
5918 | default: | |
5919 | break; | |
da0436e9 | 5920 | } |
da0436e9 | 5921 | return rc; |
3772a991 JS |
5922 | } |
5923 | ||
5924 | /** | |
da0436e9 | 5925 | * lpfc_sli4_queue_create - Create all the SLI4 queues |
3772a991 JS |
5926 | * @phba: pointer to lpfc hba data structure. |
5927 | * | |
da0436e9 JS |
5928 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA |
5929 | * operation. For each SLI4 queue type, the parameters such as queue entry | |
5930 | * count (queue depth) shall be taken from the module parameter. For now, | |
5931 | * we just use some constant number as place holder. | |
5932 | * | |
5933 | * Return codes | |
af901ca1 | 5934 | * 0 - successful |
25985edc | 5935 | * -ENOMEM - No available memory |
d439d286 | 5936 | * -EIO - The mailbox failed to complete successfully. |
3772a991 | 5937 | **/ |
da0436e9 JS |
5938 | static int |
5939 | lpfc_sli4_queue_create(struct lpfc_hba *phba) | |
3772a991 | 5940 | { |
da0436e9 JS |
5941 | struct lpfc_queue *qdesc; |
5942 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; | |
5943 | int cfg_fcp_wq_count; | |
5944 | int cfg_fcp_eq_count; | |
3772a991 | 5945 | |
da0436e9 JS |
5946 | /* |
5947 | * Sanity check for confiugred queue parameters against the run-time | |
5948 | * device parameters | |
5949 | */ | |
3772a991 | 5950 | |
da0436e9 JS |
5951 | /* Sanity check on FCP fast-path WQ parameters */ |
5952 | cfg_fcp_wq_count = phba->cfg_fcp_wq_count; | |
5953 | if (cfg_fcp_wq_count > | |
5954 | (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) { | |
5955 | cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq - | |
5956 | LPFC_SP_WQN_DEF; | |
5957 | if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) { | |
5958 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5959 | "2581 Not enough WQs (%d) from " | |
5960 | "the pci function for supporting " | |
5961 | "FCP WQs (%d)\n", | |
5962 | phba->sli4_hba.max_cfg_param.max_wq, | |
5963 | phba->cfg_fcp_wq_count); | |
5964 | goto out_error; | |
5965 | } | |
5966 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
5967 | "2582 Not enough WQs (%d) from the pci " | |
5968 | "function for supporting the requested " | |
5969 | "FCP WQs (%d), the actual FCP WQs can " | |
5970 | "be supported: %d\n", | |
5971 | phba->sli4_hba.max_cfg_param.max_wq, | |
5972 | phba->cfg_fcp_wq_count, cfg_fcp_wq_count); | |
5973 | } | |
5974 | /* The actual number of FCP work queues adopted */ | |
5975 | phba->cfg_fcp_wq_count = cfg_fcp_wq_count; | |
5976 | ||
5977 | /* Sanity check on FCP fast-path EQ parameters */ | |
5978 | cfg_fcp_eq_count = phba->cfg_fcp_eq_count; | |
5979 | if (cfg_fcp_eq_count > | |
5980 | (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) { | |
5981 | cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq - | |
5982 | LPFC_SP_EQN_DEF; | |
5983 | if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) { | |
5984 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5985 | "2574 Not enough EQs (%d) from the " | |
5986 | "pci function for supporting FCP " | |
5987 | "EQs (%d)\n", | |
5988 | phba->sli4_hba.max_cfg_param.max_eq, | |
5989 | phba->cfg_fcp_eq_count); | |
5990 | goto out_error; | |
5991 | } | |
5992 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
5993 | "2575 Not enough EQs (%d) from the pci " | |
5994 | "function for supporting the requested " | |
5995 | "FCP EQs (%d), the actual FCP EQs can " | |
5996 | "be supported: %d\n", | |
5997 | phba->sli4_hba.max_cfg_param.max_eq, | |
5998 | phba->cfg_fcp_eq_count, cfg_fcp_eq_count); | |
5999 | } | |
6000 | /* It does not make sense to have more EQs than WQs */ | |
6001 | if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) { | |
6002 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6a9c52cf JS |
6003 | "2593 The FCP EQ count(%d) cannot be greater " |
6004 | "than the FCP WQ count(%d), limiting the " | |
6005 | "FCP EQ count to %d\n", cfg_fcp_eq_count, | |
da0436e9 JS |
6006 | phba->cfg_fcp_wq_count, |
6007 | phba->cfg_fcp_wq_count); | |
6008 | cfg_fcp_eq_count = phba->cfg_fcp_wq_count; | |
6009 | } | |
6010 | /* The actual number of FCP event queues adopted */ | |
6011 | phba->cfg_fcp_eq_count = cfg_fcp_eq_count; | |
6012 | /* The overall number of event queues used */ | |
6013 | phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF; | |
3772a991 | 6014 | |
da0436e9 JS |
6015 | /* |
6016 | * Create Event Queues (EQs) | |
6017 | */ | |
3772a991 | 6018 | |
da0436e9 JS |
6019 | /* Get EQ depth from module parameter, fake the default for now */ |
6020 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; | |
6021 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; | |
3772a991 | 6022 | |
da0436e9 JS |
6023 | /* Create slow path event queue */ |
6024 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | |
6025 | phba->sli4_hba.eq_ecount); | |
6026 | if (!qdesc) { | |
6027 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6028 | "0496 Failed allocate slow-path EQ\n"); | |
6029 | goto out_error; | |
6030 | } | |
6031 | phba->sli4_hba.sp_eq = qdesc; | |
6032 | ||
6033 | /* Create fast-path FCP Event Queue(s) */ | |
6034 | phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) * | |
6035 | phba->cfg_fcp_eq_count), GFP_KERNEL); | |
6036 | if (!phba->sli4_hba.fp_eq) { | |
6037 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6038 | "2576 Failed allocate memory for fast-path " | |
6039 | "EQ record array\n"); | |
6040 | goto out_free_sp_eq; | |
6041 | } | |
6042 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
6043 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | |
6044 | phba->sli4_hba.eq_ecount); | |
6045 | if (!qdesc) { | |
6046 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6047 | "0497 Failed allocate fast-path EQ\n"); | |
6048 | goto out_free_fp_eq; | |
6049 | } | |
6050 | phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc; | |
6051 | } | |
6052 | ||
6053 | /* | |
6054 | * Create Complete Queues (CQs) | |
6055 | */ | |
6056 | ||
6057 | /* Get CQ depth from module parameter, fake the default for now */ | |
6058 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; | |
6059 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; | |
6060 | ||
6061 | /* Create slow-path Mailbox Command Complete Queue */ | |
6062 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
6063 | phba->sli4_hba.cq_ecount); | |
6064 | if (!qdesc) { | |
6065 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6066 | "0500 Failed allocate slow-path mailbox CQ\n"); | |
6067 | goto out_free_fp_eq; | |
6068 | } | |
6069 | phba->sli4_hba.mbx_cq = qdesc; | |
6070 | ||
6071 | /* Create slow-path ELS Complete Queue */ | |
6072 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
6073 | phba->sli4_hba.cq_ecount); | |
6074 | if (!qdesc) { | |
6075 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6076 | "0501 Failed allocate slow-path ELS CQ\n"); | |
6077 | goto out_free_mbx_cq; | |
6078 | } | |
6079 | phba->sli4_hba.els_cq = qdesc; | |
6080 | ||
da0436e9 JS |
6081 | |
6082 | /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */ | |
6083 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * | |
6084 | phba->cfg_fcp_eq_count), GFP_KERNEL); | |
6085 | if (!phba->sli4_hba.fcp_cq) { | |
6086 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6087 | "2577 Failed allocate memory for fast-path " | |
6088 | "CQ record array\n"); | |
4d9ab994 | 6089 | goto out_free_els_cq; |
da0436e9 JS |
6090 | } |
6091 | for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) { | |
6092 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
6093 | phba->sli4_hba.cq_ecount); | |
6094 | if (!qdesc) { | |
6095 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6096 | "0499 Failed allocate fast-path FCP " | |
6097 | "CQ (%d)\n", fcp_cqidx); | |
6098 | goto out_free_fcp_cq; | |
6099 | } | |
6100 | phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc; | |
6101 | } | |
6102 | ||
6103 | /* Create Mailbox Command Queue */ | |
6104 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; | |
6105 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; | |
6106 | ||
6107 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, | |
6108 | phba->sli4_hba.mq_ecount); | |
6109 | if (!qdesc) { | |
6110 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6111 | "0505 Failed allocate slow-path MQ\n"); | |
6112 | goto out_free_fcp_cq; | |
6113 | } | |
6114 | phba->sli4_hba.mbx_wq = qdesc; | |
6115 | ||
6116 | /* | |
6117 | * Create all the Work Queues (WQs) | |
6118 | */ | |
6119 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; | |
6120 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; | |
6121 | ||
6122 | /* Create slow-path ELS Work Queue */ | |
6123 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
6124 | phba->sli4_hba.wq_ecount); | |
6125 | if (!qdesc) { | |
6126 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6127 | "0504 Failed allocate slow-path ELS WQ\n"); | |
6128 | goto out_free_mbx_wq; | |
6129 | } | |
6130 | phba->sli4_hba.els_wq = qdesc; | |
6131 | ||
6132 | /* Create fast-path FCP Work Queue(s) */ | |
6133 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * | |
6134 | phba->cfg_fcp_wq_count), GFP_KERNEL); | |
6135 | if (!phba->sli4_hba.fcp_wq) { | |
6136 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6137 | "2578 Failed allocate memory for fast-path " | |
6138 | "WQ record array\n"); | |
6139 | goto out_free_els_wq; | |
6140 | } | |
6141 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { | |
6142 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
6143 | phba->sli4_hba.wq_ecount); | |
6144 | if (!qdesc) { | |
6145 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6146 | "0503 Failed allocate fast-path FCP " | |
6147 | "WQ (%d)\n", fcp_wqidx); | |
6148 | goto out_free_fcp_wq; | |
6149 | } | |
6150 | phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc; | |
6151 | } | |
6152 | ||
6153 | /* | |
6154 | * Create Receive Queue (RQ) | |
6155 | */ | |
6156 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; | |
6157 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; | |
6158 | ||
6159 | /* Create Receive Queue for header */ | |
6160 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
6161 | phba->sli4_hba.rq_ecount); | |
6162 | if (!qdesc) { | |
6163 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6164 | "0506 Failed allocate receive HRQ\n"); | |
6165 | goto out_free_fcp_wq; | |
6166 | } | |
6167 | phba->sli4_hba.hdr_rq = qdesc; | |
6168 | ||
6169 | /* Create Receive Queue for data */ | |
6170 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
6171 | phba->sli4_hba.rq_ecount); | |
6172 | if (!qdesc) { | |
6173 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6174 | "0507 Failed allocate receive DRQ\n"); | |
6175 | goto out_free_hdr_rq; | |
6176 | } | |
6177 | phba->sli4_hba.dat_rq = qdesc; | |
6178 | ||
6179 | return 0; | |
6180 | ||
6181 | out_free_hdr_rq: | |
6182 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); | |
6183 | phba->sli4_hba.hdr_rq = NULL; | |
6184 | out_free_fcp_wq: | |
6185 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) { | |
6186 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]); | |
6187 | phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL; | |
6188 | } | |
6189 | kfree(phba->sli4_hba.fcp_wq); | |
6190 | out_free_els_wq: | |
6191 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); | |
6192 | phba->sli4_hba.els_wq = NULL; | |
6193 | out_free_mbx_wq: | |
6194 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); | |
6195 | phba->sli4_hba.mbx_wq = NULL; | |
6196 | out_free_fcp_cq: | |
6197 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) { | |
6198 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]); | |
6199 | phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL; | |
6200 | } | |
6201 | kfree(phba->sli4_hba.fcp_cq); | |
da0436e9 JS |
6202 | out_free_els_cq: |
6203 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); | |
6204 | phba->sli4_hba.els_cq = NULL; | |
6205 | out_free_mbx_cq: | |
6206 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); | |
6207 | phba->sli4_hba.mbx_cq = NULL; | |
6208 | out_free_fp_eq: | |
6209 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) { | |
6210 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]); | |
6211 | phba->sli4_hba.fp_eq[fcp_eqidx] = NULL; | |
6212 | } | |
6213 | kfree(phba->sli4_hba.fp_eq); | |
6214 | out_free_sp_eq: | |
6215 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); | |
6216 | phba->sli4_hba.sp_eq = NULL; | |
6217 | out_error: | |
6218 | return -ENOMEM; | |
6219 | } | |
6220 | ||
6221 | /** | |
6222 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues | |
6223 | * @phba: pointer to lpfc hba data structure. | |
6224 | * | |
6225 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA | |
6226 | * operation. | |
6227 | * | |
6228 | * Return codes | |
af901ca1 | 6229 | * 0 - successful |
25985edc | 6230 | * -ENOMEM - No available memory |
d439d286 | 6231 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
6232 | **/ |
6233 | static void | |
6234 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) | |
6235 | { | |
6236 | int fcp_qidx; | |
6237 | ||
6238 | /* Release mailbox command work queue */ | |
6239 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); | |
6240 | phba->sli4_hba.mbx_wq = NULL; | |
6241 | ||
6242 | /* Release ELS work queue */ | |
6243 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); | |
6244 | phba->sli4_hba.els_wq = NULL; | |
6245 | ||
6246 | /* Release FCP work queue */ | |
6247 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) | |
6248 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]); | |
6249 | kfree(phba->sli4_hba.fcp_wq); | |
6250 | phba->sli4_hba.fcp_wq = NULL; | |
6251 | ||
6252 | /* Release unsolicited receive queue */ | |
6253 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); | |
6254 | phba->sli4_hba.hdr_rq = NULL; | |
6255 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); | |
6256 | phba->sli4_hba.dat_rq = NULL; | |
6257 | ||
da0436e9 JS |
6258 | /* Release ELS complete queue */ |
6259 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); | |
6260 | phba->sli4_hba.els_cq = NULL; | |
6261 | ||
6262 | /* Release mailbox command complete queue */ | |
6263 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); | |
6264 | phba->sli4_hba.mbx_cq = NULL; | |
6265 | ||
6266 | /* Release FCP response complete queue */ | |
0558056c JS |
6267 | fcp_qidx = 0; |
6268 | do | |
da0436e9 | 6269 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]); |
0558056c | 6270 | while (++fcp_qidx < phba->cfg_fcp_eq_count); |
da0436e9 JS |
6271 | kfree(phba->sli4_hba.fcp_cq); |
6272 | phba->sli4_hba.fcp_cq = NULL; | |
6273 | ||
6274 | /* Release fast-path event queue */ | |
6275 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | |
6276 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]); | |
6277 | kfree(phba->sli4_hba.fp_eq); | |
6278 | phba->sli4_hba.fp_eq = NULL; | |
6279 | ||
6280 | /* Release slow-path event queue */ | |
6281 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); | |
6282 | phba->sli4_hba.sp_eq = NULL; | |
6283 | ||
6284 | return; | |
6285 | } | |
6286 | ||
6287 | /** | |
6288 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues | |
6289 | * @phba: pointer to lpfc hba data structure. | |
6290 | * | |
6291 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA | |
6292 | * operation. | |
6293 | * | |
6294 | * Return codes | |
af901ca1 | 6295 | * 0 - successful |
25985edc | 6296 | * -ENOMEM - No available memory |
d439d286 | 6297 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
6298 | **/ |
6299 | int | |
6300 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) | |
6301 | { | |
6302 | int rc = -ENOMEM; | |
6303 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; | |
6304 | int fcp_cq_index = 0; | |
6305 | ||
6306 | /* | |
6307 | * Set up Event Queues (EQs) | |
6308 | */ | |
6309 | ||
6310 | /* Set up slow-path event queue */ | |
6311 | if (!phba->sli4_hba.sp_eq) { | |
6312 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6313 | "0520 Slow-path EQ not allocated\n"); | |
6314 | goto out_error; | |
6315 | } | |
6316 | rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq, | |
6317 | LPFC_SP_DEF_IMAX); | |
6318 | if (rc) { | |
6319 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6320 | "0521 Failed setup of slow-path EQ: " | |
6321 | "rc = 0x%x\n", rc); | |
6322 | goto out_error; | |
6323 | } | |
6324 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6325 | "2583 Slow-path EQ setup: queue-id=%d\n", | |
6326 | phba->sli4_hba.sp_eq->queue_id); | |
6327 | ||
6328 | /* Set up fast-path event queue */ | |
6329 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
6330 | if (!phba->sli4_hba.fp_eq[fcp_eqidx]) { | |
6331 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6332 | "0522 Fast-path EQ (%d) not " | |
6333 | "allocated\n", fcp_eqidx); | |
6334 | goto out_destroy_fp_eq; | |
6335 | } | |
6336 | rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx], | |
6337 | phba->cfg_fcp_imax); | |
6338 | if (rc) { | |
6339 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6340 | "0523 Failed setup of fast-path EQ " | |
6341 | "(%d), rc = 0x%x\n", fcp_eqidx, rc); | |
6342 | goto out_destroy_fp_eq; | |
6343 | } | |
6344 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6345 | "2584 Fast-path EQ setup: " | |
6346 | "queue[%d]-id=%d\n", fcp_eqidx, | |
6347 | phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id); | |
6348 | } | |
6349 | ||
6350 | /* | |
6351 | * Set up Complete Queues (CQs) | |
6352 | */ | |
6353 | ||
6354 | /* Set up slow-path MBOX Complete Queue as the first CQ */ | |
6355 | if (!phba->sli4_hba.mbx_cq) { | |
6356 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6357 | "0528 Mailbox CQ not allocated\n"); | |
6358 | goto out_destroy_fp_eq; | |
6359 | } | |
6360 | rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq, | |
6361 | LPFC_MCQ, LPFC_MBOX); | |
6362 | if (rc) { | |
6363 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6364 | "0529 Failed setup of slow-path mailbox CQ: " | |
6365 | "rc = 0x%x\n", rc); | |
6366 | goto out_destroy_fp_eq; | |
6367 | } | |
6368 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6369 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", | |
6370 | phba->sli4_hba.mbx_cq->queue_id, | |
6371 | phba->sli4_hba.sp_eq->queue_id); | |
6372 | ||
6373 | /* Set up slow-path ELS Complete Queue */ | |
6374 | if (!phba->sli4_hba.els_cq) { | |
6375 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6376 | "0530 ELS CQ not allocated\n"); | |
6377 | goto out_destroy_mbx_cq; | |
6378 | } | |
6379 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq, | |
6380 | LPFC_WCQ, LPFC_ELS); | |
6381 | if (rc) { | |
6382 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6383 | "0531 Failed setup of slow-path ELS CQ: " | |
6384 | "rc = 0x%x\n", rc); | |
6385 | goto out_destroy_mbx_cq; | |
6386 | } | |
6387 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6388 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", | |
6389 | phba->sli4_hba.els_cq->queue_id, | |
6390 | phba->sli4_hba.sp_eq->queue_id); | |
6391 | ||
da0436e9 | 6392 | /* Set up fast-path FCP Response Complete Queue */ |
0558056c JS |
6393 | fcp_cqidx = 0; |
6394 | do { | |
da0436e9 JS |
6395 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { |
6396 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6397 | "0526 Fast-path FCP CQ (%d) not " | |
6398 | "allocated\n", fcp_cqidx); | |
6399 | goto out_destroy_fcp_cq; | |
6400 | } | |
0558056c JS |
6401 | if (phba->cfg_fcp_eq_count) |
6402 | rc = lpfc_cq_create(phba, | |
6403 | phba->sli4_hba.fcp_cq[fcp_cqidx], | |
6404 | phba->sli4_hba.fp_eq[fcp_cqidx], | |
6405 | LPFC_WCQ, LPFC_FCP); | |
6406 | else | |
6407 | rc = lpfc_cq_create(phba, | |
6408 | phba->sli4_hba.fcp_cq[fcp_cqidx], | |
6409 | phba->sli4_hba.sp_eq, | |
6410 | LPFC_WCQ, LPFC_FCP); | |
da0436e9 JS |
6411 | if (rc) { |
6412 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6413 | "0527 Failed setup of fast-path FCP " | |
6414 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc); | |
6415 | goto out_destroy_fcp_cq; | |
6416 | } | |
6417 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6418 | "2588 FCP CQ setup: cq[%d]-id=%d, " | |
0558056c | 6419 | "parent %seq[%d]-id=%d\n", |
da0436e9 JS |
6420 | fcp_cqidx, |
6421 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, | |
0558056c | 6422 | (phba->cfg_fcp_eq_count) ? "" : "sp_", |
da0436e9 | 6423 | fcp_cqidx, |
0558056c JS |
6424 | (phba->cfg_fcp_eq_count) ? |
6425 | phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id : | |
6426 | phba->sli4_hba.sp_eq->queue_id); | |
6427 | } while (++fcp_cqidx < phba->cfg_fcp_eq_count); | |
da0436e9 JS |
6428 | |
6429 | /* | |
6430 | * Set up all the Work Queues (WQs) | |
6431 | */ | |
6432 | ||
6433 | /* Set up Mailbox Command Queue */ | |
6434 | if (!phba->sli4_hba.mbx_wq) { | |
6435 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6436 | "0538 Slow-path MQ not allocated\n"); | |
6437 | goto out_destroy_fcp_cq; | |
6438 | } | |
6439 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, | |
6440 | phba->sli4_hba.mbx_cq, LPFC_MBOX); | |
6441 | if (rc) { | |
6442 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6443 | "0539 Failed setup of slow-path MQ: " | |
6444 | "rc = 0x%x\n", rc); | |
6445 | goto out_destroy_fcp_cq; | |
6446 | } | |
6447 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6448 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", | |
6449 | phba->sli4_hba.mbx_wq->queue_id, | |
6450 | phba->sli4_hba.mbx_cq->queue_id); | |
6451 | ||
6452 | /* Set up slow-path ELS Work Queue */ | |
6453 | if (!phba->sli4_hba.els_wq) { | |
6454 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6455 | "0536 Slow-path ELS WQ not allocated\n"); | |
6456 | goto out_destroy_mbx_wq; | |
6457 | } | |
6458 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, | |
6459 | phba->sli4_hba.els_cq, LPFC_ELS); | |
6460 | if (rc) { | |
6461 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6462 | "0537 Failed setup of slow-path ELS WQ: " | |
6463 | "rc = 0x%x\n", rc); | |
6464 | goto out_destroy_mbx_wq; | |
6465 | } | |
6466 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6467 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", | |
6468 | phba->sli4_hba.els_wq->queue_id, | |
6469 | phba->sli4_hba.els_cq->queue_id); | |
6470 | ||
6471 | /* Set up fast-path FCP Work Queue */ | |
6472 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { | |
6473 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { | |
6474 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6475 | "0534 Fast-path FCP WQ (%d) not " | |
6476 | "allocated\n", fcp_wqidx); | |
6477 | goto out_destroy_fcp_wq; | |
6478 | } | |
6479 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], | |
6480 | phba->sli4_hba.fcp_cq[fcp_cq_index], | |
6481 | LPFC_FCP); | |
6482 | if (rc) { | |
6483 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6484 | "0535 Failed setup of fast-path FCP " | |
6485 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc); | |
6486 | goto out_destroy_fcp_wq; | |
6487 | } | |
6488 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6489 | "2591 FCP WQ setup: wq[%d]-id=%d, " | |
6490 | "parent cq[%d]-id=%d\n", | |
6491 | fcp_wqidx, | |
6492 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, | |
6493 | fcp_cq_index, | |
6494 | phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id); | |
6495 | /* Round robin FCP Work Queue's Completion Queue assignment */ | |
0558056c JS |
6496 | if (phba->cfg_fcp_eq_count) |
6497 | fcp_cq_index = ((fcp_cq_index + 1) % | |
6498 | phba->cfg_fcp_eq_count); | |
da0436e9 JS |
6499 | } |
6500 | ||
6501 | /* | |
6502 | * Create Receive Queue (RQ) | |
6503 | */ | |
6504 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { | |
6505 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6506 | "0540 Receive Queue not allocated\n"); | |
6507 | goto out_destroy_fcp_wq; | |
6508 | } | |
6509 | rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, | |
4d9ab994 | 6510 | phba->sli4_hba.els_cq, LPFC_USOL); |
da0436e9 JS |
6511 | if (rc) { |
6512 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6513 | "0541 Failed setup of Receive Queue: " | |
6514 | "rc = 0x%x\n", rc); | |
6515 | goto out_destroy_fcp_wq; | |
6516 | } | |
6517 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6518 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " | |
6519 | "parent cq-id=%d\n", | |
6520 | phba->sli4_hba.hdr_rq->queue_id, | |
6521 | phba->sli4_hba.dat_rq->queue_id, | |
4d9ab994 | 6522 | phba->sli4_hba.els_cq->queue_id); |
da0436e9 JS |
6523 | return 0; |
6524 | ||
6525 | out_destroy_fcp_wq: | |
6526 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) | |
6527 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); | |
6528 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); | |
6529 | out_destroy_mbx_wq: | |
6530 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | |
6531 | out_destroy_fcp_cq: | |
6532 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) | |
6533 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); | |
da0436e9 JS |
6534 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
6535 | out_destroy_mbx_cq: | |
6536 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | |
6537 | out_destroy_fp_eq: | |
6538 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) | |
6539 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]); | |
6540 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); | |
6541 | out_error: | |
6542 | return rc; | |
6543 | } | |
6544 | ||
6545 | /** | |
6546 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues | |
6547 | * @phba: pointer to lpfc hba data structure. | |
6548 | * | |
6549 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA | |
6550 | * operation. | |
6551 | * | |
6552 | * Return codes | |
af901ca1 | 6553 | * 0 - successful |
25985edc | 6554 | * -ENOMEM - No available memory |
d439d286 | 6555 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
6556 | **/ |
6557 | void | |
6558 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) | |
6559 | { | |
6560 | int fcp_qidx; | |
6561 | ||
6562 | /* Unset mailbox command work queue */ | |
6563 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | |
6564 | /* Unset ELS work queue */ | |
6565 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); | |
6566 | /* Unset unsolicited receive queue */ | |
6567 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); | |
6568 | /* Unset FCP work queue */ | |
6569 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) | |
6570 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); | |
6571 | /* Unset mailbox command complete queue */ | |
6572 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | |
6573 | /* Unset ELS complete queue */ | |
6574 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); | |
da0436e9 JS |
6575 | /* Unset FCP response complete queue */ |
6576 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | |
6577 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); | |
6578 | /* Unset fast-path event queue */ | |
6579 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | |
6580 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]); | |
6581 | /* Unset slow-path event queue */ | |
6582 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); | |
6583 | } | |
6584 | ||
6585 | /** | |
6586 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool | |
6587 | * @phba: pointer to lpfc hba data structure. | |
6588 | * | |
6589 | * This routine is invoked to allocate and set up a pool of completion queue | |
6590 | * events. The body of the completion queue event is a completion queue entry | |
6591 | * CQE. For now, this pool is used for the interrupt service routine to queue | |
6592 | * the following HBA completion queue events for the worker thread to process: | |
6593 | * - Mailbox asynchronous events | |
6594 | * - Receive queue completion unsolicited events | |
6595 | * Later, this can be used for all the slow-path events. | |
6596 | * | |
6597 | * Return codes | |
af901ca1 | 6598 | * 0 - successful |
25985edc | 6599 | * -ENOMEM - No available memory |
da0436e9 JS |
6600 | **/ |
6601 | static int | |
6602 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) | |
6603 | { | |
6604 | struct lpfc_cq_event *cq_event; | |
6605 | int i; | |
6606 | ||
6607 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { | |
6608 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); | |
6609 | if (!cq_event) | |
6610 | goto out_pool_create_fail; | |
6611 | list_add_tail(&cq_event->list, | |
6612 | &phba->sli4_hba.sp_cqe_event_pool); | |
6613 | } | |
6614 | return 0; | |
6615 | ||
6616 | out_pool_create_fail: | |
6617 | lpfc_sli4_cq_event_pool_destroy(phba); | |
6618 | return -ENOMEM; | |
6619 | } | |
6620 | ||
6621 | /** | |
6622 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool | |
6623 | * @phba: pointer to lpfc hba data structure. | |
6624 | * | |
6625 | * This routine is invoked to free the pool of completion queue events at | |
6626 | * driver unload time. Note that, it is the responsibility of the driver | |
6627 | * cleanup routine to free all the outstanding completion-queue events | |
6628 | * allocated from this pool back into the pool before invoking this routine | |
6629 | * to destroy the pool. | |
6630 | **/ | |
6631 | static void | |
6632 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) | |
6633 | { | |
6634 | struct lpfc_cq_event *cq_event, *next_cq_event; | |
6635 | ||
6636 | list_for_each_entry_safe(cq_event, next_cq_event, | |
6637 | &phba->sli4_hba.sp_cqe_event_pool, list) { | |
6638 | list_del(&cq_event->list); | |
6639 | kfree(cq_event); | |
6640 | } | |
6641 | } | |
6642 | ||
6643 | /** | |
6644 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
6645 | * @phba: pointer to lpfc hba data structure. | |
6646 | * | |
6647 | * This routine is the lock free version of the API invoked to allocate a | |
6648 | * completion-queue event from the free pool. | |
6649 | * | |
6650 | * Return: Pointer to the newly allocated completion-queue event if successful | |
6651 | * NULL otherwise. | |
6652 | **/ | |
6653 | struct lpfc_cq_event * | |
6654 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
6655 | { | |
6656 | struct lpfc_cq_event *cq_event = NULL; | |
6657 | ||
6658 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, | |
6659 | struct lpfc_cq_event, list); | |
6660 | return cq_event; | |
6661 | } | |
6662 | ||
6663 | /** | |
6664 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
6665 | * @phba: pointer to lpfc hba data structure. | |
6666 | * | |
6667 | * This routine is the lock version of the API invoked to allocate a | |
6668 | * completion-queue event from the free pool. | |
6669 | * | |
6670 | * Return: Pointer to the newly allocated completion-queue event if successful | |
6671 | * NULL otherwise. | |
6672 | **/ | |
6673 | struct lpfc_cq_event * | |
6674 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
6675 | { | |
6676 | struct lpfc_cq_event *cq_event; | |
6677 | unsigned long iflags; | |
6678 | ||
6679 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6680 | cq_event = __lpfc_sli4_cq_event_alloc(phba); | |
6681 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6682 | return cq_event; | |
6683 | } | |
6684 | ||
6685 | /** | |
6686 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
6687 | * @phba: pointer to lpfc hba data structure. | |
6688 | * @cq_event: pointer to the completion queue event to be freed. | |
6689 | * | |
6690 | * This routine is the lock free version of the API invoked to release a | |
6691 | * completion-queue event back into the free pool. | |
6692 | **/ | |
6693 | void | |
6694 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
6695 | struct lpfc_cq_event *cq_event) | |
6696 | { | |
6697 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); | |
6698 | } | |
6699 | ||
6700 | /** | |
6701 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
6702 | * @phba: pointer to lpfc hba data structure. | |
6703 | * @cq_event: pointer to the completion queue event to be freed. | |
6704 | * | |
6705 | * This routine is the lock version of the API invoked to release a | |
6706 | * completion-queue event back into the free pool. | |
6707 | **/ | |
6708 | void | |
6709 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
6710 | struct lpfc_cq_event *cq_event) | |
6711 | { | |
6712 | unsigned long iflags; | |
6713 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6714 | __lpfc_sli4_cq_event_release(phba, cq_event); | |
6715 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6716 | } | |
6717 | ||
6718 | /** | |
6719 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool | |
6720 | * @phba: pointer to lpfc hba data structure. | |
6721 | * | |
6722 | * This routine is to free all the pending completion-queue events to the | |
6723 | * back into the free pool for device reset. | |
6724 | **/ | |
6725 | static void | |
6726 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) | |
6727 | { | |
6728 | LIST_HEAD(cqelist); | |
6729 | struct lpfc_cq_event *cqe; | |
6730 | unsigned long iflags; | |
6731 | ||
6732 | /* Retrieve all the pending WCQEs from pending WCQE lists */ | |
6733 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6734 | /* Pending FCP XRI abort events */ | |
6735 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
6736 | &cqelist); | |
6737 | /* Pending ELS XRI abort events */ | |
6738 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
6739 | &cqelist); | |
6740 | /* Pending asynnc events */ | |
6741 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, | |
6742 | &cqelist); | |
6743 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6744 | ||
6745 | while (!list_empty(&cqelist)) { | |
6746 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); | |
6747 | lpfc_sli4_cq_event_release(phba, cqe); | |
6748 | } | |
6749 | } | |
6750 | ||
6751 | /** | |
6752 | * lpfc_pci_function_reset - Reset pci function. | |
6753 | * @phba: pointer to lpfc hba data structure. | |
6754 | * | |
6755 | * This routine is invoked to request a PCI function reset. It will destroys | |
6756 | * all resources assigned to the PCI function which originates this request. | |
6757 | * | |
6758 | * Return codes | |
af901ca1 | 6759 | * 0 - successful |
25985edc | 6760 | * -ENOMEM - No available memory |
d439d286 | 6761 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
6762 | **/ |
6763 | int | |
6764 | lpfc_pci_function_reset(struct lpfc_hba *phba) | |
6765 | { | |
6766 | LPFC_MBOXQ_t *mboxq; | |
2fcee4bf | 6767 | uint32_t rc = 0, if_type; |
da0436e9 | 6768 | uint32_t shdr_status, shdr_add_status; |
2fcee4bf | 6769 | uint32_t rdy_chk, num_resets = 0, reset_again = 0; |
da0436e9 | 6770 | union lpfc_sli4_cfg_shdr *shdr; |
2fcee4bf | 6771 | struct lpfc_register reg_data; |
da0436e9 | 6772 | |
2fcee4bf JS |
6773 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
6774 | switch (if_type) { | |
6775 | case LPFC_SLI_INTF_IF_TYPE_0: | |
6776 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, | |
6777 | GFP_KERNEL); | |
6778 | if (!mboxq) { | |
6779 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6780 | "0494 Unable to allocate memory for " | |
6781 | "issuing SLI_FUNCTION_RESET mailbox " | |
6782 | "command\n"); | |
6783 | return -ENOMEM; | |
6784 | } | |
da0436e9 | 6785 | |
2fcee4bf JS |
6786 | /* Setup PCI function reset mailbox-ioctl command */ |
6787 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
6788 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, | |
6789 | LPFC_SLI4_MBX_EMBED); | |
6790 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6791 | shdr = (union lpfc_sli4_cfg_shdr *) | |
6792 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
6793 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
6794 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
6795 | &shdr->response); | |
6796 | if (rc != MBX_TIMEOUT) | |
6797 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6798 | if (shdr_status || shdr_add_status || rc) { | |
6799 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6800 | "0495 SLI_FUNCTION_RESET mailbox " | |
6801 | "failed with status x%x add_status x%x," | |
6802 | " mbx status x%x\n", | |
6803 | shdr_status, shdr_add_status, rc); | |
6804 | rc = -ENXIO; | |
6805 | } | |
6806 | break; | |
6807 | case LPFC_SLI_INTF_IF_TYPE_2: | |
6808 | for (num_resets = 0; | |
6809 | num_resets < MAX_IF_TYPE_2_RESETS; | |
6810 | num_resets++) { | |
6811 | reg_data.word0 = 0; | |
6812 | bf_set(lpfc_sliport_ctrl_end, ®_data, | |
6813 | LPFC_SLIPORT_LITTLE_ENDIAN); | |
6814 | bf_set(lpfc_sliport_ctrl_ip, ®_data, | |
6815 | LPFC_SLIPORT_INIT_PORT); | |
6816 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. | |
6817 | CTRLregaddr); | |
6818 | ||
6819 | /* | |
6820 | * Poll the Port Status Register and wait for RDY for | |
6821 | * up to 10 seconds. If the port doesn't respond, treat | |
6822 | * it as an error. If the port responds with RN, start | |
6823 | * the loop again. | |
6824 | */ | |
6825 | for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) { | |
9940b97b JS |
6826 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
6827 | STATUSregaddr, ®_data.word0)) { | |
6828 | rc = -ENODEV; | |
6829 | break; | |
6830 | } | |
2fcee4bf JS |
6831 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
6832 | break; | |
6833 | if (bf_get(lpfc_sliport_status_rn, ®_data)) { | |
6834 | reset_again++; | |
6835 | break; | |
6836 | } | |
6837 | msleep(10); | |
6838 | } | |
6839 | ||
6840 | /* | |
6841 | * If the port responds to the init request with | |
6842 | * reset needed, delay for a bit and restart the loop. | |
6843 | */ | |
6844 | if (reset_again) { | |
6845 | msleep(10); | |
6846 | reset_again = 0; | |
6847 | continue; | |
6848 | } | |
6849 | ||
6850 | /* Detect any port errors. */ | |
9940b97b JS |
6851 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
6852 | ®_data.word0)) { | |
6853 | rc = -ENODEV; | |
6854 | break; | |
6855 | } | |
2fcee4bf JS |
6856 | if ((bf_get(lpfc_sliport_status_err, ®_data)) || |
6857 | (rdy_chk >= 1000)) { | |
6858 | phba->work_status[0] = readl( | |
6859 | phba->sli4_hba.u.if_type2.ERR1regaddr); | |
6860 | phba->work_status[1] = readl( | |
6861 | phba->sli4_hba.u.if_type2.ERR2regaddr); | |
6862 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6863 | "2890 Port Error Detected " | |
6864 | "during Port Reset: " | |
6865 | "port status reg 0x%x, " | |
6866 | "error 1=0x%x, error 2=0x%x\n", | |
6867 | reg_data.word0, | |
6868 | phba->work_status[0], | |
6869 | phba->work_status[1]); | |
6870 | rc = -ENODEV; | |
6871 | } | |
6872 | ||
6873 | /* | |
6874 | * Terminate the outer loop provided the Port indicated | |
6875 | * ready within 10 seconds. | |
6876 | */ | |
6877 | if (rdy_chk < 1000) | |
6878 | break; | |
6879 | } | |
0558056c JS |
6880 | /* delay driver action following IF_TYPE_2 function reset */ |
6881 | msleep(100); | |
2fcee4bf JS |
6882 | break; |
6883 | case LPFC_SLI_INTF_IF_TYPE_1: | |
6884 | default: | |
6885 | break; | |
da0436e9 | 6886 | } |
2fcee4bf JS |
6887 | |
6888 | /* Catch the not-ready port failure after a port reset. */ | |
6889 | if (num_resets >= MAX_IF_TYPE_2_RESETS) | |
6890 | rc = -ENODEV; | |
6891 | ||
da0436e9 JS |
6892 | return rc; |
6893 | } | |
6894 | ||
6895 | /** | |
6896 | * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands | |
6897 | * @phba: pointer to lpfc hba data structure. | |
6898 | * @cnt: number of nop mailbox commands to send. | |
6899 | * | |
6900 | * This routine is invoked to send a number @cnt of NOP mailbox command and | |
6901 | * wait for each command to complete. | |
6902 | * | |
6903 | * Return: the number of NOP mailbox command completed. | |
6904 | **/ | |
6905 | static int | |
6906 | lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt) | |
6907 | { | |
6908 | LPFC_MBOXQ_t *mboxq; | |
6909 | int length, cmdsent; | |
6910 | uint32_t mbox_tmo; | |
6911 | uint32_t rc = 0; | |
6912 | uint32_t shdr_status, shdr_add_status; | |
6913 | union lpfc_sli4_cfg_shdr *shdr; | |
6914 | ||
6915 | if (cnt == 0) { | |
6916 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6917 | "2518 Requested to send 0 NOP mailbox cmd\n"); | |
6918 | return cnt; | |
6919 | } | |
6920 | ||
6921 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
6922 | if (!mboxq) { | |
6923 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6924 | "2519 Unable to allocate memory for issuing " | |
6925 | "NOP mailbox command\n"); | |
6926 | return 0; | |
6927 | } | |
6928 | ||
6929 | /* Set up NOP SLI4_CONFIG mailbox-ioctl command */ | |
6930 | length = (sizeof(struct lpfc_mbx_nop) - | |
6931 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
6932 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
6933 | LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED); | |
6934 | ||
6935 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG); | |
6936 | for (cmdsent = 0; cmdsent < cnt; cmdsent++) { | |
6937 | if (!phba->sli4_hba.intr_enable) | |
6938 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6939 | else | |
6940 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
6941 | if (rc == MBX_TIMEOUT) | |
6942 | break; | |
6943 | /* Check return status */ | |
6944 | shdr = (union lpfc_sli4_cfg_shdr *) | |
6945 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
6946 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
6947 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
6948 | &shdr->response); | |
6949 | if (shdr_status || shdr_add_status || rc) { | |
6950 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6951 | "2520 NOP mailbox command failed " | |
6952 | "status x%x add_status x%x mbx " | |
6953 | "status x%x\n", shdr_status, | |
6954 | shdr_add_status, rc); | |
6955 | break; | |
6956 | } | |
6957 | } | |
6958 | ||
6959 | if (rc != MBX_TIMEOUT) | |
6960 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6961 | ||
6962 | return cmdsent; | |
6963 | } | |
6964 | ||
da0436e9 JS |
6965 | /** |
6966 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. | |
6967 | * @phba: pointer to lpfc hba data structure. | |
6968 | * | |
6969 | * This routine is invoked to set up the PCI device memory space for device | |
6970 | * with SLI-4 interface spec. | |
6971 | * | |
6972 | * Return codes | |
af901ca1 | 6973 | * 0 - successful |
da0436e9 JS |
6974 | * other values - error |
6975 | **/ | |
6976 | static int | |
6977 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) | |
6978 | { | |
6979 | struct pci_dev *pdev; | |
6980 | unsigned long bar0map_len, bar1map_len, bar2map_len; | |
6981 | int error = -ENODEV; | |
2fcee4bf | 6982 | uint32_t if_type; |
da0436e9 JS |
6983 | |
6984 | /* Obtain PCI device reference */ | |
6985 | if (!phba->pcidev) | |
6986 | return error; | |
6987 | else | |
6988 | pdev = phba->pcidev; | |
6989 | ||
6990 | /* Set the device DMA mask size */ | |
8e68597d MR |
6991 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
6992 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
6993 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
6994 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
da0436e9 | 6995 | return error; |
8e68597d MR |
6996 | } |
6997 | } | |
da0436e9 | 6998 | |
2fcee4bf JS |
6999 | /* |
7000 | * The BARs and register set definitions and offset locations are | |
7001 | * dependent on the if_type. | |
7002 | */ | |
7003 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, | |
7004 | &phba->sli4_hba.sli_intf.word0)) { | |
7005 | return error; | |
7006 | } | |
7007 | ||
7008 | /* There is no SLI3 failback for SLI4 devices. */ | |
7009 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != | |
7010 | LPFC_SLI_INTF_VALID) { | |
7011 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7012 | "2894 SLI_INTF reg contents invalid " | |
7013 | "sli_intf reg 0x%x\n", | |
7014 | phba->sli4_hba.sli_intf.word0); | |
7015 | return error; | |
7016 | } | |
7017 | ||
7018 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); | |
7019 | /* | |
7020 | * Get the bus address of SLI4 device Bar regions and the | |
7021 | * number of bytes required by each mapping. The mapping of the | |
7022 | * particular PCI BARs regions is dependent on the type of | |
7023 | * SLI4 device. | |
da0436e9 | 7024 | */ |
1dfb5a47 JS |
7025 | if (pci_resource_start(pdev, 0)) { |
7026 | phba->pci_bar0_map = pci_resource_start(pdev, 0); | |
7027 | bar0map_len = pci_resource_len(pdev, 0); | |
2fcee4bf JS |
7028 | |
7029 | /* | |
7030 | * Map SLI4 PCI Config Space Register base to a kernel virtual | |
7031 | * addr | |
7032 | */ | |
7033 | phba->sli4_hba.conf_regs_memmap_p = | |
7034 | ioremap(phba->pci_bar0_map, bar0map_len); | |
7035 | if (!phba->sli4_hba.conf_regs_memmap_p) { | |
7036 | dev_printk(KERN_ERR, &pdev->dev, | |
7037 | "ioremap failed for SLI4 PCI config " | |
7038 | "registers.\n"); | |
7039 | goto out; | |
7040 | } | |
7041 | /* Set up BAR0 PCI config space register memory map */ | |
7042 | lpfc_sli4_bar0_register_memmap(phba, if_type); | |
1dfb5a47 JS |
7043 | } else { |
7044 | phba->pci_bar0_map = pci_resource_start(pdev, 1); | |
7045 | bar0map_len = pci_resource_len(pdev, 1); | |
2fcee4bf JS |
7046 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
7047 | dev_printk(KERN_ERR, &pdev->dev, | |
7048 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); | |
7049 | goto out; | |
7050 | } | |
7051 | phba->sli4_hba.conf_regs_memmap_p = | |
da0436e9 | 7052 | ioremap(phba->pci_bar0_map, bar0map_len); |
2fcee4bf JS |
7053 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
7054 | dev_printk(KERN_ERR, &pdev->dev, | |
7055 | "ioremap failed for SLI4 PCI config " | |
7056 | "registers.\n"); | |
7057 | goto out; | |
7058 | } | |
7059 | lpfc_sli4_bar0_register_memmap(phba, if_type); | |
da0436e9 JS |
7060 | } |
7061 | ||
c31098ce JS |
7062 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
7063 | (pci_resource_start(pdev, 2))) { | |
2fcee4bf JS |
7064 | /* |
7065 | * Map SLI4 if type 0 HBA Control Register base to a kernel | |
7066 | * virtual address and setup the registers. | |
7067 | */ | |
7068 | phba->pci_bar1_map = pci_resource_start(pdev, 2); | |
7069 | bar1map_len = pci_resource_len(pdev, 2); | |
7070 | phba->sli4_hba.ctrl_regs_memmap_p = | |
da0436e9 | 7071 | ioremap(phba->pci_bar1_map, bar1map_len); |
2fcee4bf JS |
7072 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
7073 | dev_printk(KERN_ERR, &pdev->dev, | |
da0436e9 | 7074 | "ioremap failed for SLI4 HBA control registers.\n"); |
2fcee4bf JS |
7075 | goto out_iounmap_conf; |
7076 | } | |
7077 | lpfc_sli4_bar1_register_memmap(phba); | |
da0436e9 JS |
7078 | } |
7079 | ||
c31098ce JS |
7080 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
7081 | (pci_resource_start(pdev, 4))) { | |
2fcee4bf JS |
7082 | /* |
7083 | * Map SLI4 if type 0 HBA Doorbell Register base to a kernel | |
7084 | * virtual address and setup the registers. | |
7085 | */ | |
7086 | phba->pci_bar2_map = pci_resource_start(pdev, 4); | |
7087 | bar2map_len = pci_resource_len(pdev, 4); | |
7088 | phba->sli4_hba.drbl_regs_memmap_p = | |
da0436e9 | 7089 | ioremap(phba->pci_bar2_map, bar2map_len); |
2fcee4bf JS |
7090 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
7091 | dev_printk(KERN_ERR, &pdev->dev, | |
da0436e9 | 7092 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
2fcee4bf JS |
7093 | goto out_iounmap_ctrl; |
7094 | } | |
7095 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); | |
7096 | if (error) | |
7097 | goto out_iounmap_all; | |
da0436e9 JS |
7098 | } |
7099 | ||
da0436e9 JS |
7100 | return 0; |
7101 | ||
7102 | out_iounmap_all: | |
7103 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
7104 | out_iounmap_ctrl: | |
7105 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
7106 | out_iounmap_conf: | |
7107 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
7108 | out: | |
7109 | return error; | |
7110 | } | |
7111 | ||
7112 | /** | |
7113 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. | |
7114 | * @phba: pointer to lpfc hba data structure. | |
7115 | * | |
7116 | * This routine is invoked to unset the PCI device memory space for device | |
7117 | * with SLI-4 interface spec. | |
7118 | **/ | |
7119 | static void | |
7120 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) | |
7121 | { | |
7122 | struct pci_dev *pdev; | |
7123 | ||
7124 | /* Obtain PCI device reference */ | |
7125 | if (!phba->pcidev) | |
7126 | return; | |
7127 | else | |
7128 | pdev = phba->pcidev; | |
7129 | ||
7130 | /* Free coherent DMA memory allocated */ | |
7131 | ||
7132 | /* Unmap I/O memory space */ | |
7133 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
7134 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
7135 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
7136 | ||
7137 | return; | |
7138 | } | |
7139 | ||
7140 | /** | |
7141 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device | |
7142 | * @phba: pointer to lpfc hba data structure. | |
7143 | * | |
7144 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
7145 | * with SLI-3 interface specs. The kernel function pci_enable_msix() is | |
7146 | * called to enable the MSI-X vectors. Note that pci_enable_msix(), once | |
7147 | * invoked, enables either all or nothing, depending on the current | |
7148 | * availability of PCI vector resources. The device driver is responsible | |
7149 | * for calling the individual request_irq() to register each MSI-X vector | |
7150 | * with a interrupt handler, which is done in this function. Note that | |
7151 | * later when device is unloading, the driver should always call free_irq() | |
7152 | * on all MSI-X vectors it has done request_irq() on before calling | |
7153 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device | |
7154 | * will be left with MSI-X enabled and leaks its vectors. | |
7155 | * | |
7156 | * Return codes | |
af901ca1 | 7157 | * 0 - successful |
da0436e9 JS |
7158 | * other values - error |
7159 | **/ | |
7160 | static int | |
7161 | lpfc_sli_enable_msix(struct lpfc_hba *phba) | |
7162 | { | |
7163 | int rc, i; | |
7164 | LPFC_MBOXQ_t *pmb; | |
7165 | ||
7166 | /* Set up MSI-X multi-message vectors */ | |
7167 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
7168 | phba->msix_entries[i].entry = i; | |
7169 | ||
7170 | /* Configure MSI-X capability structure */ | |
7171 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, | |
7172 | ARRAY_SIZE(phba->msix_entries)); | |
7173 | if (rc) { | |
7174 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7175 | "0420 PCI enable MSI-X failed (%d)\n", rc); | |
7176 | goto msi_fail_out; | |
7177 | } | |
7178 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
7179 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7180 | "0477 MSI-X entry[%d]: vector=x%x " | |
7181 | "message=%d\n", i, | |
7182 | phba->msix_entries[i].vector, | |
7183 | phba->msix_entries[i].entry); | |
7184 | /* | |
7185 | * Assign MSI-X vectors to interrupt handlers | |
7186 | */ | |
7187 | ||
7188 | /* vector-0 is associated to slow-path handler */ | |
7189 | rc = request_irq(phba->msix_entries[0].vector, | |
7190 | &lpfc_sli_sp_intr_handler, IRQF_SHARED, | |
7191 | LPFC_SP_DRIVER_HANDLER_NAME, phba); | |
7192 | if (rc) { | |
7193 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7194 | "0421 MSI-X slow-path request_irq failed " | |
7195 | "(%d)\n", rc); | |
7196 | goto msi_fail_out; | |
7197 | } | |
7198 | ||
7199 | /* vector-1 is associated to fast-path handler */ | |
7200 | rc = request_irq(phba->msix_entries[1].vector, | |
7201 | &lpfc_sli_fp_intr_handler, IRQF_SHARED, | |
7202 | LPFC_FP_DRIVER_HANDLER_NAME, phba); | |
7203 | ||
7204 | if (rc) { | |
7205 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7206 | "0429 MSI-X fast-path request_irq failed " | |
7207 | "(%d)\n", rc); | |
7208 | goto irq_fail_out; | |
7209 | } | |
7210 | ||
7211 | /* | |
7212 | * Configure HBA MSI-X attention conditions to messages | |
7213 | */ | |
7214 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
7215 | ||
7216 | if (!pmb) { | |
7217 | rc = -ENOMEM; | |
7218 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7219 | "0474 Unable to allocate memory for issuing " | |
7220 | "MBOX_CONFIG_MSI command\n"); | |
7221 | goto mem_fail_out; | |
7222 | } | |
7223 | rc = lpfc_config_msi(phba, pmb); | |
7224 | if (rc) | |
7225 | goto mbx_fail_out; | |
7226 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
7227 | if (rc != MBX_SUCCESS) { | |
7228 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | |
7229 | "0351 Config MSI mailbox command failed, " | |
7230 | "mbxCmd x%x, mbxStatus x%x\n", | |
7231 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); | |
7232 | goto mbx_fail_out; | |
7233 | } | |
7234 | ||
7235 | /* Free memory allocated for mailbox command */ | |
7236 | mempool_free(pmb, phba->mbox_mem_pool); | |
7237 | return rc; | |
7238 | ||
7239 | mbx_fail_out: | |
7240 | /* Free memory allocated for mailbox command */ | |
7241 | mempool_free(pmb, phba->mbox_mem_pool); | |
7242 | ||
7243 | mem_fail_out: | |
7244 | /* free the irq already requested */ | |
7245 | free_irq(phba->msix_entries[1].vector, phba); | |
7246 | ||
7247 | irq_fail_out: | |
7248 | /* free the irq already requested */ | |
7249 | free_irq(phba->msix_entries[0].vector, phba); | |
7250 | ||
7251 | msi_fail_out: | |
7252 | /* Unconfigure MSI-X capability structure */ | |
7253 | pci_disable_msix(phba->pcidev); | |
7254 | return rc; | |
7255 | } | |
7256 | ||
7257 | /** | |
7258 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. | |
7259 | * @phba: pointer to lpfc hba data structure. | |
7260 | * | |
7261 | * This routine is invoked to release the MSI-X vectors and then disable the | |
7262 | * MSI-X interrupt mode to device with SLI-3 interface spec. | |
7263 | **/ | |
7264 | static void | |
7265 | lpfc_sli_disable_msix(struct lpfc_hba *phba) | |
7266 | { | |
7267 | int i; | |
7268 | ||
7269 | /* Free up MSI-X multi-message vectors */ | |
7270 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
7271 | free_irq(phba->msix_entries[i].vector, phba); | |
7272 | /* Disable MSI-X */ | |
7273 | pci_disable_msix(phba->pcidev); | |
7274 | ||
7275 | return; | |
7276 | } | |
7277 | ||
7278 | /** | |
7279 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. | |
7280 | * @phba: pointer to lpfc hba data structure. | |
7281 | * | |
7282 | * This routine is invoked to enable the MSI interrupt mode to device with | |
7283 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to | |
7284 | * enable the MSI vector. The device driver is responsible for calling the | |
7285 | * request_irq() to register MSI vector with a interrupt the handler, which | |
7286 | * is done in this function. | |
7287 | * | |
7288 | * Return codes | |
af901ca1 | 7289 | * 0 - successful |
da0436e9 JS |
7290 | * other values - error |
7291 | */ | |
7292 | static int | |
7293 | lpfc_sli_enable_msi(struct lpfc_hba *phba) | |
7294 | { | |
7295 | int rc; | |
7296 | ||
7297 | rc = pci_enable_msi(phba->pcidev); | |
7298 | if (!rc) | |
7299 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7300 | "0462 PCI enable MSI mode success.\n"); | |
7301 | else { | |
7302 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7303 | "0471 PCI enable MSI mode failed (%d)\n", rc); | |
7304 | return rc; | |
7305 | } | |
7306 | ||
7307 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
7308 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
7309 | if (rc) { | |
7310 | pci_disable_msi(phba->pcidev); | |
7311 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7312 | "0478 MSI request_irq failed (%d)\n", rc); | |
7313 | } | |
7314 | return rc; | |
7315 | } | |
7316 | ||
7317 | /** | |
7318 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. | |
7319 | * @phba: pointer to lpfc hba data structure. | |
7320 | * | |
7321 | * This routine is invoked to disable the MSI interrupt mode to device with | |
7322 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has | |
7323 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | |
7324 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | |
7325 | * its vector. | |
7326 | */ | |
7327 | static void | |
7328 | lpfc_sli_disable_msi(struct lpfc_hba *phba) | |
7329 | { | |
7330 | free_irq(phba->pcidev->irq, phba); | |
7331 | pci_disable_msi(phba->pcidev); | |
7332 | return; | |
7333 | } | |
7334 | ||
7335 | /** | |
7336 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. | |
7337 | * @phba: pointer to lpfc hba data structure. | |
7338 | * | |
7339 | * This routine is invoked to enable device interrupt and associate driver's | |
7340 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface | |
7341 | * spec. Depends on the interrupt mode configured to the driver, the driver | |
7342 | * will try to fallback from the configured interrupt mode to an interrupt | |
7343 | * mode which is supported by the platform, kernel, and device in the order | |
7344 | * of: | |
7345 | * MSI-X -> MSI -> IRQ. | |
7346 | * | |
7347 | * Return codes | |
af901ca1 | 7348 | * 0 - successful |
da0436e9 JS |
7349 | * other values - error |
7350 | **/ | |
7351 | static uint32_t | |
7352 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
7353 | { | |
7354 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
7355 | int retval; | |
7356 | ||
7357 | if (cfg_mode == 2) { | |
7358 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ | |
7359 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); | |
7360 | if (!retval) { | |
7361 | /* Now, try to enable MSI-X interrupt mode */ | |
7362 | retval = lpfc_sli_enable_msix(phba); | |
7363 | if (!retval) { | |
7364 | /* Indicate initialization to MSI-X mode */ | |
7365 | phba->intr_type = MSIX; | |
7366 | intr_mode = 2; | |
7367 | } | |
7368 | } | |
7369 | } | |
7370 | ||
7371 | /* Fallback to MSI if MSI-X initialization failed */ | |
7372 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
7373 | retval = lpfc_sli_enable_msi(phba); | |
7374 | if (!retval) { | |
7375 | /* Indicate initialization to MSI mode */ | |
7376 | phba->intr_type = MSI; | |
7377 | intr_mode = 1; | |
7378 | } | |
7379 | } | |
7380 | ||
7381 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
7382 | if (phba->intr_type == NONE) { | |
7383 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
7384 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
7385 | if (!retval) { | |
7386 | /* Indicate initialization to INTx mode */ | |
7387 | phba->intr_type = INTx; | |
7388 | intr_mode = 0; | |
7389 | } | |
7390 | } | |
7391 | return intr_mode; | |
7392 | } | |
7393 | ||
7394 | /** | |
7395 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. | |
7396 | * @phba: pointer to lpfc hba data structure. | |
7397 | * | |
7398 | * This routine is invoked to disable device interrupt and disassociate the | |
7399 | * driver's interrupt handler(s) from interrupt vector(s) to device with | |
7400 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will | |
7401 | * release the interrupt vector(s) for the message signaled interrupt. | |
7402 | **/ | |
7403 | static void | |
7404 | lpfc_sli_disable_intr(struct lpfc_hba *phba) | |
7405 | { | |
7406 | /* Disable the currently initialized interrupt mode */ | |
7407 | if (phba->intr_type == MSIX) | |
7408 | lpfc_sli_disable_msix(phba); | |
7409 | else if (phba->intr_type == MSI) | |
7410 | lpfc_sli_disable_msi(phba); | |
7411 | else if (phba->intr_type == INTx) | |
7412 | free_irq(phba->pcidev->irq, phba); | |
7413 | ||
7414 | /* Reset interrupt management states */ | |
7415 | phba->intr_type = NONE; | |
7416 | phba->sli.slistat.sli_intr = 0; | |
7417 | ||
7418 | return; | |
7419 | } | |
7420 | ||
7421 | /** | |
7422 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device | |
7423 | * @phba: pointer to lpfc hba data structure. | |
7424 | * | |
7425 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
7426 | * with SLI-4 interface spec. The kernel function pci_enable_msix() is called | |
7427 | * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked, | |
7428 | * enables either all or nothing, depending on the current availability of | |
7429 | * PCI vector resources. The device driver is responsible for calling the | |
7430 | * individual request_irq() to register each MSI-X vector with a interrupt | |
7431 | * handler, which is done in this function. Note that later when device is | |
7432 | * unloading, the driver should always call free_irq() on all MSI-X vectors | |
7433 | * it has done request_irq() on before calling pci_disable_msix(). Failure | |
7434 | * to do so results in a BUG_ON() and a device will be left with MSI-X | |
7435 | * enabled and leaks its vectors. | |
7436 | * | |
7437 | * Return codes | |
af901ca1 | 7438 | * 0 - successful |
da0436e9 JS |
7439 | * other values - error |
7440 | **/ | |
7441 | static int | |
7442 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) | |
7443 | { | |
75baf696 | 7444 | int vectors, rc, index; |
da0436e9 JS |
7445 | |
7446 | /* Set up MSI-X multi-message vectors */ | |
7447 | for (index = 0; index < phba->sli4_hba.cfg_eqn; index++) | |
7448 | phba->sli4_hba.msix_entries[index].entry = index; | |
7449 | ||
7450 | /* Configure MSI-X capability structure */ | |
75baf696 JS |
7451 | vectors = phba->sli4_hba.cfg_eqn; |
7452 | enable_msix_vectors: | |
da0436e9 | 7453 | rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries, |
75baf696 JS |
7454 | vectors); |
7455 | if (rc > 1) { | |
7456 | vectors = rc; | |
7457 | goto enable_msix_vectors; | |
7458 | } else if (rc) { | |
da0436e9 JS |
7459 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
7460 | "0484 PCI enable MSI-X failed (%d)\n", rc); | |
7461 | goto msi_fail_out; | |
7462 | } | |
75baf696 | 7463 | |
da0436e9 | 7464 | /* Log MSI-X vector assignment */ |
75baf696 | 7465 | for (index = 0; index < vectors; index++) |
da0436e9 JS |
7466 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
7467 | "0489 MSI-X entry[%d]: vector=x%x " | |
7468 | "message=%d\n", index, | |
7469 | phba->sli4_hba.msix_entries[index].vector, | |
7470 | phba->sli4_hba.msix_entries[index].entry); | |
7471 | /* | |
7472 | * Assign MSI-X vectors to interrupt handlers | |
7473 | */ | |
0558056c JS |
7474 | if (vectors > 1) |
7475 | rc = request_irq(phba->sli4_hba.msix_entries[0].vector, | |
7476 | &lpfc_sli4_sp_intr_handler, IRQF_SHARED, | |
7477 | LPFC_SP_DRIVER_HANDLER_NAME, phba); | |
7478 | else | |
7479 | /* All Interrupts need to be handled by one EQ */ | |
7480 | rc = request_irq(phba->sli4_hba.msix_entries[0].vector, | |
7481 | &lpfc_sli4_intr_handler, IRQF_SHARED, | |
7482 | LPFC_DRIVER_NAME, phba); | |
da0436e9 JS |
7483 | if (rc) { |
7484 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7485 | "0485 MSI-X slow-path request_irq failed " | |
7486 | "(%d)\n", rc); | |
7487 | goto msi_fail_out; | |
7488 | } | |
7489 | ||
7490 | /* The rest of the vector(s) are associated to fast-path handler(s) */ | |
75baf696 | 7491 | for (index = 1; index < vectors; index++) { |
da0436e9 JS |
7492 | phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1; |
7493 | phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba; | |
7494 | rc = request_irq(phba->sli4_hba.msix_entries[index].vector, | |
7495 | &lpfc_sli4_fp_intr_handler, IRQF_SHARED, | |
7496 | LPFC_FP_DRIVER_HANDLER_NAME, | |
7497 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
7498 | if (rc) { | |
7499 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7500 | "0486 MSI-X fast-path (%d) " | |
7501 | "request_irq failed (%d)\n", index, rc); | |
7502 | goto cfg_fail_out; | |
7503 | } | |
7504 | } | |
75baf696 | 7505 | phba->sli4_hba.msix_vec_nr = vectors; |
da0436e9 JS |
7506 | |
7507 | return rc; | |
7508 | ||
7509 | cfg_fail_out: | |
7510 | /* free the irq already requested */ | |
7511 | for (--index; index >= 1; index--) | |
7512 | free_irq(phba->sli4_hba.msix_entries[index - 1].vector, | |
7513 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
7514 | ||
7515 | /* free the irq already requested */ | |
7516 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); | |
7517 | ||
7518 | msi_fail_out: | |
7519 | /* Unconfigure MSI-X capability structure */ | |
7520 | pci_disable_msix(phba->pcidev); | |
7521 | return rc; | |
7522 | } | |
7523 | ||
7524 | /** | |
7525 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device | |
7526 | * @phba: pointer to lpfc hba data structure. | |
7527 | * | |
7528 | * This routine is invoked to release the MSI-X vectors and then disable the | |
7529 | * MSI-X interrupt mode to device with SLI-4 interface spec. | |
7530 | **/ | |
7531 | static void | |
7532 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) | |
7533 | { | |
7534 | int index; | |
7535 | ||
7536 | /* Free up MSI-X multi-message vectors */ | |
7537 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); | |
7538 | ||
75baf696 | 7539 | for (index = 1; index < phba->sli4_hba.msix_vec_nr; index++) |
da0436e9 JS |
7540 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
7541 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
75baf696 | 7542 | |
da0436e9 JS |
7543 | /* Disable MSI-X */ |
7544 | pci_disable_msix(phba->pcidev); | |
7545 | ||
7546 | return; | |
7547 | } | |
7548 | ||
7549 | /** | |
7550 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device | |
7551 | * @phba: pointer to lpfc hba data structure. | |
7552 | * | |
7553 | * This routine is invoked to enable the MSI interrupt mode to device with | |
7554 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called | |
7555 | * to enable the MSI vector. The device driver is responsible for calling | |
7556 | * the request_irq() to register MSI vector with a interrupt the handler, | |
7557 | * which is done in this function. | |
7558 | * | |
7559 | * Return codes | |
af901ca1 | 7560 | * 0 - successful |
da0436e9 JS |
7561 | * other values - error |
7562 | **/ | |
7563 | static int | |
7564 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) | |
7565 | { | |
7566 | int rc, index; | |
7567 | ||
7568 | rc = pci_enable_msi(phba->pcidev); | |
7569 | if (!rc) | |
7570 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7571 | "0487 PCI enable MSI mode success.\n"); | |
7572 | else { | |
7573 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7574 | "0488 PCI enable MSI mode failed (%d)\n", rc); | |
7575 | return rc; | |
7576 | } | |
7577 | ||
7578 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
7579 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
7580 | if (rc) { | |
7581 | pci_disable_msi(phba->pcidev); | |
7582 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7583 | "0490 MSI request_irq failed (%d)\n", rc); | |
75baf696 | 7584 | return rc; |
da0436e9 JS |
7585 | } |
7586 | ||
7587 | for (index = 0; index < phba->cfg_fcp_eq_count; index++) { | |
7588 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | |
7589 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
7590 | } | |
7591 | ||
75baf696 | 7592 | return 0; |
da0436e9 JS |
7593 | } |
7594 | ||
7595 | /** | |
7596 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device | |
7597 | * @phba: pointer to lpfc hba data structure. | |
7598 | * | |
7599 | * This routine is invoked to disable the MSI interrupt mode to device with | |
7600 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has | |
7601 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | |
7602 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | |
7603 | * its vector. | |
7604 | **/ | |
7605 | static void | |
7606 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) | |
7607 | { | |
7608 | free_irq(phba->pcidev->irq, phba); | |
7609 | pci_disable_msi(phba->pcidev); | |
7610 | return; | |
7611 | } | |
7612 | ||
7613 | /** | |
7614 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device | |
7615 | * @phba: pointer to lpfc hba data structure. | |
7616 | * | |
7617 | * This routine is invoked to enable device interrupt and associate driver's | |
7618 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 | |
7619 | * interface spec. Depends on the interrupt mode configured to the driver, | |
7620 | * the driver will try to fallback from the configured interrupt mode to an | |
7621 | * interrupt mode which is supported by the platform, kernel, and device in | |
7622 | * the order of: | |
7623 | * MSI-X -> MSI -> IRQ. | |
7624 | * | |
7625 | * Return codes | |
af901ca1 | 7626 | * 0 - successful |
da0436e9 JS |
7627 | * other values - error |
7628 | **/ | |
7629 | static uint32_t | |
7630 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
7631 | { | |
7632 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
7633 | int retval, index; | |
7634 | ||
7635 | if (cfg_mode == 2) { | |
7636 | /* Preparation before conf_msi mbox cmd */ | |
7637 | retval = 0; | |
7638 | if (!retval) { | |
7639 | /* Now, try to enable MSI-X interrupt mode */ | |
7640 | retval = lpfc_sli4_enable_msix(phba); | |
7641 | if (!retval) { | |
7642 | /* Indicate initialization to MSI-X mode */ | |
7643 | phba->intr_type = MSIX; | |
7644 | intr_mode = 2; | |
7645 | } | |
7646 | } | |
7647 | } | |
7648 | ||
7649 | /* Fallback to MSI if MSI-X initialization failed */ | |
7650 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
7651 | retval = lpfc_sli4_enable_msi(phba); | |
7652 | if (!retval) { | |
7653 | /* Indicate initialization to MSI mode */ | |
7654 | phba->intr_type = MSI; | |
7655 | intr_mode = 1; | |
7656 | } | |
7657 | } | |
7658 | ||
7659 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
7660 | if (phba->intr_type == NONE) { | |
7661 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
7662 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
7663 | if (!retval) { | |
7664 | /* Indicate initialization to INTx mode */ | |
7665 | phba->intr_type = INTx; | |
7666 | intr_mode = 0; | |
7667 | for (index = 0; index < phba->cfg_fcp_eq_count; | |
7668 | index++) { | |
7669 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | |
7670 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
7671 | } | |
7672 | } | |
7673 | } | |
7674 | return intr_mode; | |
7675 | } | |
7676 | ||
7677 | /** | |
7678 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device | |
7679 | * @phba: pointer to lpfc hba data structure. | |
7680 | * | |
7681 | * This routine is invoked to disable device interrupt and disassociate | |
7682 | * the driver's interrupt handler(s) from interrupt vector(s) to device | |
7683 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver | |
7684 | * will release the interrupt vector(s) for the message signaled interrupt. | |
7685 | **/ | |
7686 | static void | |
7687 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) | |
7688 | { | |
7689 | /* Disable the currently initialized interrupt mode */ | |
7690 | if (phba->intr_type == MSIX) | |
7691 | lpfc_sli4_disable_msix(phba); | |
7692 | else if (phba->intr_type == MSI) | |
7693 | lpfc_sli4_disable_msi(phba); | |
7694 | else if (phba->intr_type == INTx) | |
7695 | free_irq(phba->pcidev->irq, phba); | |
7696 | ||
7697 | /* Reset interrupt management states */ | |
7698 | phba->intr_type = NONE; | |
7699 | phba->sli.slistat.sli_intr = 0; | |
7700 | ||
7701 | return; | |
7702 | } | |
7703 | ||
7704 | /** | |
7705 | * lpfc_unset_hba - Unset SLI3 hba device initialization | |
7706 | * @phba: pointer to lpfc hba data structure. | |
7707 | * | |
7708 | * This routine is invoked to unset the HBA device initialization steps to | |
7709 | * a device with SLI-3 interface spec. | |
7710 | **/ | |
7711 | static void | |
7712 | lpfc_unset_hba(struct lpfc_hba *phba) | |
7713 | { | |
7714 | struct lpfc_vport *vport = phba->pport; | |
7715 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
7716 | ||
7717 | spin_lock_irq(shost->host_lock); | |
7718 | vport->load_flag |= FC_UNLOADING; | |
7719 | spin_unlock_irq(shost->host_lock); | |
7720 | ||
7721 | lpfc_stop_hba_timers(phba); | |
7722 | ||
7723 | phba->pport->work_port_events = 0; | |
7724 | ||
7725 | lpfc_sli_hba_down(phba); | |
7726 | ||
7727 | lpfc_sli_brdrestart(phba); | |
7728 | ||
7729 | lpfc_sli_disable_intr(phba); | |
7730 | ||
7731 | return; | |
7732 | } | |
7733 | ||
7734 | /** | |
7735 | * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization. | |
7736 | * @phba: pointer to lpfc hba data structure. | |
7737 | * | |
7738 | * This routine is invoked to unset the HBA device initialization steps to | |
7739 | * a device with SLI-4 interface spec. | |
7740 | **/ | |
7741 | static void | |
7742 | lpfc_sli4_unset_hba(struct lpfc_hba *phba) | |
7743 | { | |
7744 | struct lpfc_vport *vport = phba->pport; | |
7745 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
7746 | ||
7747 | spin_lock_irq(shost->host_lock); | |
7748 | vport->load_flag |= FC_UNLOADING; | |
7749 | spin_unlock_irq(shost->host_lock); | |
7750 | ||
7751 | phba->pport->work_port_events = 0; | |
7752 | ||
3677a3a7 JS |
7753 | /* Stop the SLI4 device port */ |
7754 | lpfc_stop_port(phba); | |
da0436e9 JS |
7755 | |
7756 | lpfc_sli4_disable_intr(phba); | |
7757 | ||
3677a3a7 JS |
7758 | /* Reset SLI4 HBA FCoE function */ |
7759 | lpfc_pci_function_reset(phba); | |
7760 | ||
da0436e9 JS |
7761 | return; |
7762 | } | |
7763 | ||
5af5eee7 JS |
7764 | /** |
7765 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy | |
7766 | * @phba: Pointer to HBA context object. | |
7767 | * | |
7768 | * This function is called in the SLI4 code path to wait for completion | |
7769 | * of device's XRIs exchange busy. It will check the XRI exchange busy | |
7770 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after | |
7771 | * that, it will check the XRI exchange busy on outstanding FCP and ELS | |
7772 | * I/Os every 30 seconds, log error message, and wait forever. Only when | |
7773 | * all XRI exchange busy complete, the driver unload shall proceed with | |
7774 | * invoking the function reset ioctl mailbox command to the CNA and the | |
7775 | * the rest of the driver unload resource release. | |
7776 | **/ | |
7777 | static void | |
7778 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) | |
7779 | { | |
7780 | int wait_time = 0; | |
7781 | int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
7782 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
7783 | ||
7784 | while (!fcp_xri_cmpl || !els_xri_cmpl) { | |
7785 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { | |
7786 | if (!fcp_xri_cmpl) | |
7787 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7788 | "2877 FCP XRI exchange busy " | |
7789 | "wait time: %d seconds.\n", | |
7790 | wait_time/1000); | |
7791 | if (!els_xri_cmpl) | |
7792 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7793 | "2878 ELS XRI exchange busy " | |
7794 | "wait time: %d seconds.\n", | |
7795 | wait_time/1000); | |
7796 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); | |
7797 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; | |
7798 | } else { | |
7799 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); | |
7800 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; | |
7801 | } | |
7802 | fcp_xri_cmpl = | |
7803 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
7804 | els_xri_cmpl = | |
7805 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
7806 | } | |
7807 | } | |
7808 | ||
da0436e9 JS |
7809 | /** |
7810 | * lpfc_sli4_hba_unset - Unset the fcoe hba | |
7811 | * @phba: Pointer to HBA context object. | |
7812 | * | |
7813 | * This function is called in the SLI4 code path to reset the HBA's FCoE | |
7814 | * function. The caller is not required to hold any lock. This routine | |
7815 | * issues PCI function reset mailbox command to reset the FCoE function. | |
7816 | * At the end of the function, it calls lpfc_hba_down_post function to | |
7817 | * free any pending commands. | |
7818 | **/ | |
7819 | static void | |
7820 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) | |
7821 | { | |
7822 | int wait_cnt = 0; | |
7823 | LPFC_MBOXQ_t *mboxq; | |
7824 | ||
7825 | lpfc_stop_hba_timers(phba); | |
7826 | phba->sli4_hba.intr_enable = 0; | |
7827 | ||
7828 | /* | |
7829 | * Gracefully wait out the potential current outstanding asynchronous | |
7830 | * mailbox command. | |
7831 | */ | |
7832 | ||
7833 | /* First, block any pending async mailbox command from posted */ | |
7834 | spin_lock_irq(&phba->hbalock); | |
7835 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
7836 | spin_unlock_irq(&phba->hbalock); | |
7837 | /* Now, trying to wait it out if we can */ | |
7838 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
7839 | msleep(10); | |
7840 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) | |
7841 | break; | |
7842 | } | |
7843 | /* Forcefully release the outstanding mailbox command if timed out */ | |
7844 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
7845 | spin_lock_irq(&phba->hbalock); | |
7846 | mboxq = phba->sli.mbox_active; | |
7847 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
7848 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
7849 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
7850 | phba->sli.mbox_active = NULL; | |
7851 | spin_unlock_irq(&phba->hbalock); | |
7852 | } | |
7853 | ||
5af5eee7 JS |
7854 | /* Abort all iocbs associated with the hba */ |
7855 | lpfc_sli_hba_iocb_abort(phba); | |
7856 | ||
7857 | /* Wait for completion of device XRI exchange busy */ | |
7858 | lpfc_sli4_xri_exchange_busy_wait(phba); | |
7859 | ||
da0436e9 JS |
7860 | /* Disable PCI subsystem interrupt */ |
7861 | lpfc_sli4_disable_intr(phba); | |
7862 | ||
7863 | /* Stop kthread signal shall trigger work_done one more time */ | |
7864 | kthread_stop(phba->worker_thread); | |
7865 | ||
3677a3a7 JS |
7866 | /* Reset SLI4 HBA FCoE function */ |
7867 | lpfc_pci_function_reset(phba); | |
7868 | ||
da0436e9 JS |
7869 | /* Stop the SLI4 device port */ |
7870 | phba->pport->work_port_events = 0; | |
7871 | } | |
7872 | ||
28baac74 JS |
7873 | /** |
7874 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. | |
7875 | * @phba: Pointer to HBA context object. | |
7876 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. | |
7877 | * | |
7878 | * This function is called in the SLI4 code path to read the port's | |
7879 | * sli4 capabilities. | |
7880 | * | |
7881 | * This function may be be called from any context that can block-wait | |
7882 | * for the completion. The expectation is that this routine is called | |
7883 | * typically from probe_one or from the online routine. | |
7884 | **/ | |
7885 | int | |
7886 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
7887 | { | |
7888 | int rc; | |
7889 | struct lpfc_mqe *mqe; | |
7890 | struct lpfc_pc_sli4_params *sli4_params; | |
7891 | uint32_t mbox_tmo; | |
7892 | ||
7893 | rc = 0; | |
7894 | mqe = &mboxq->u.mqe; | |
7895 | ||
7896 | /* Read the port's SLI4 Parameters port capabilities */ | |
fedd3b7b | 7897 | lpfc_pc_sli4_params(mboxq); |
28baac74 JS |
7898 | if (!phba->sli4_hba.intr_enable) |
7899 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7900 | else { | |
7901 | mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_PORT_CAPABILITIES); | |
7902 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
7903 | } | |
7904 | ||
7905 | if (unlikely(rc)) | |
7906 | return 1; | |
7907 | ||
7908 | sli4_params = &phba->sli4_hba.pc_sli4_params; | |
7909 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); | |
7910 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); | |
7911 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); | |
7912 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, | |
7913 | &mqe->un.sli4_params); | |
7914 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, | |
7915 | &mqe->un.sli4_params); | |
7916 | sli4_params->proto_types = mqe->un.sli4_params.word3; | |
7917 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; | |
7918 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); | |
7919 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); | |
7920 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); | |
7921 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); | |
7922 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); | |
7923 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); | |
7924 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); | |
7925 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); | |
7926 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); | |
7927 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); | |
7928 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); | |
7929 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); | |
7930 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); | |
7931 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); | |
7932 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); | |
7933 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); | |
7934 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); | |
7935 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); | |
7936 | sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params); | |
0558056c JS |
7937 | |
7938 | /* Make sure that sge_supp_len can be handled by the driver */ | |
7939 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) | |
7940 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; | |
7941 | ||
28baac74 JS |
7942 | return rc; |
7943 | } | |
7944 | ||
fedd3b7b JS |
7945 | /** |
7946 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. | |
7947 | * @phba: Pointer to HBA context object. | |
7948 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. | |
7949 | * | |
7950 | * This function is called in the SLI4 code path to read the port's | |
7951 | * sli4 capabilities. | |
7952 | * | |
7953 | * This function may be be called from any context that can block-wait | |
7954 | * for the completion. The expectation is that this routine is called | |
7955 | * typically from probe_one or from the online routine. | |
7956 | **/ | |
7957 | int | |
7958 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
7959 | { | |
7960 | int rc; | |
7961 | struct lpfc_mqe *mqe = &mboxq->u.mqe; | |
7962 | struct lpfc_pc_sli4_params *sli4_params; | |
7963 | int length; | |
7964 | struct lpfc_sli4_parameters *mbx_sli4_parameters; | |
7965 | ||
7966 | /* Read the port's SLI4 Config Parameters */ | |
7967 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - | |
7968 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
7969 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
7970 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, | |
7971 | length, LPFC_SLI4_MBX_EMBED); | |
7972 | if (!phba->sli4_hba.intr_enable) | |
7973 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7974 | else | |
7975 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, | |
7976 | lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG)); | |
7977 | if (unlikely(rc)) | |
7978 | return rc; | |
7979 | sli4_params = &phba->sli4_hba.pc_sli4_params; | |
7980 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; | |
7981 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); | |
7982 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); | |
7983 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); | |
7984 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, | |
7985 | mbx_sli4_parameters); | |
7986 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, | |
7987 | mbx_sli4_parameters); | |
7988 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) | |
7989 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; | |
7990 | else | |
7991 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; | |
7992 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; | |
7993 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); | |
7994 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); | |
7995 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); | |
7996 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); | |
7997 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); | |
7998 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, | |
7999 | mbx_sli4_parameters); | |
8000 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, | |
8001 | mbx_sli4_parameters); | |
0558056c JS |
8002 | |
8003 | /* Make sure that sge_supp_len can be handled by the driver */ | |
8004 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) | |
8005 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; | |
8006 | ||
fedd3b7b JS |
8007 | return 0; |
8008 | } | |
8009 | ||
da0436e9 JS |
8010 | /** |
8011 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. | |
8012 | * @pdev: pointer to PCI device | |
8013 | * @pid: pointer to PCI device identifier | |
8014 | * | |
8015 | * This routine is to be called to attach a device with SLI-3 interface spec | |
8016 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
8017 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific | |
8018 | * information of the device and driver to see if the driver state that it can | |
8019 | * support this kind of device. If the match is successful, the driver core | |
8020 | * invokes this routine. If this routine determines it can claim the HBA, it | |
8021 | * does all the initialization that it needs to do to handle the HBA properly. | |
8022 | * | |
8023 | * Return code | |
8024 | * 0 - driver can claim the device | |
8025 | * negative value - driver can not claim the device | |
8026 | **/ | |
8027 | static int __devinit | |
8028 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) | |
8029 | { | |
8030 | struct lpfc_hba *phba; | |
8031 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 8032 | struct Scsi_Host *shost = NULL; |
da0436e9 JS |
8033 | int error; |
8034 | uint32_t cfg_mode, intr_mode; | |
8035 | ||
8036 | /* Allocate memory for HBA structure */ | |
8037 | phba = lpfc_hba_alloc(pdev); | |
8038 | if (!phba) | |
8039 | return -ENOMEM; | |
8040 | ||
8041 | /* Perform generic PCI device enabling operation */ | |
8042 | error = lpfc_enable_pci_dev(phba); | |
8043 | if (error) { | |
8044 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8045 | "1401 Failed to enable pci device.\n"); | |
8046 | goto out_free_phba; | |
8047 | } | |
8048 | ||
8049 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ | |
8050 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); | |
8051 | if (error) | |
8052 | goto out_disable_pci_dev; | |
8053 | ||
8054 | /* Set up SLI-3 specific device PCI memory space */ | |
8055 | error = lpfc_sli_pci_mem_setup(phba); | |
8056 | if (error) { | |
8057 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8058 | "1402 Failed to set up pci memory space.\n"); | |
8059 | goto out_disable_pci_dev; | |
8060 | } | |
8061 | ||
8062 | /* Set up phase-1 common device driver resources */ | |
8063 | error = lpfc_setup_driver_resource_phase1(phba); | |
8064 | if (error) { | |
8065 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8066 | "1403 Failed to set up driver resource.\n"); | |
8067 | goto out_unset_pci_mem_s3; | |
8068 | } | |
8069 | ||
8070 | /* Set up SLI-3 specific device driver resources */ | |
8071 | error = lpfc_sli_driver_resource_setup(phba); | |
8072 | if (error) { | |
8073 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8074 | "1404 Failed to set up driver resource.\n"); | |
8075 | goto out_unset_pci_mem_s3; | |
8076 | } | |
8077 | ||
8078 | /* Initialize and populate the iocb list per host */ | |
8079 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); | |
8080 | if (error) { | |
8081 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8082 | "1405 Failed to initialize iocb list.\n"); | |
8083 | goto out_unset_driver_resource_s3; | |
8084 | } | |
8085 | ||
8086 | /* Set up common device driver resources */ | |
8087 | error = lpfc_setup_driver_resource_phase2(phba); | |
8088 | if (error) { | |
8089 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8090 | "1406 Failed to set up driver resource.\n"); | |
8091 | goto out_free_iocb_list; | |
8092 | } | |
8093 | ||
8094 | /* Create SCSI host to the physical port */ | |
8095 | error = lpfc_create_shost(phba); | |
8096 | if (error) { | |
8097 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8098 | "1407 Failed to create scsi host.\n"); | |
8099 | goto out_unset_driver_resource; | |
8100 | } | |
8101 | ||
8102 | /* Configure sysfs attributes */ | |
8103 | vport = phba->pport; | |
8104 | error = lpfc_alloc_sysfs_attr(vport); | |
8105 | if (error) { | |
8106 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8107 | "1476 Failed to allocate sysfs attr\n"); | |
8108 | goto out_destroy_shost; | |
8109 | } | |
8110 | ||
6669f9bb | 8111 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
da0436e9 JS |
8112 | /* Now, trying to enable interrupt and bring up the device */ |
8113 | cfg_mode = phba->cfg_use_msi; | |
8114 | while (true) { | |
8115 | /* Put device to a known state before enabling interrupt */ | |
8116 | lpfc_stop_port(phba); | |
8117 | /* Configure and enable interrupt */ | |
8118 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); | |
8119 | if (intr_mode == LPFC_INTR_ERROR) { | |
8120 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8121 | "0431 Failed to enable interrupt.\n"); | |
8122 | error = -ENODEV; | |
8123 | goto out_free_sysfs_attr; | |
8124 | } | |
8125 | /* SLI-3 HBA setup */ | |
8126 | if (lpfc_sli_hba_setup(phba)) { | |
8127 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8128 | "1477 Failed to set up hba\n"); | |
8129 | error = -ENODEV; | |
8130 | goto out_remove_device; | |
8131 | } | |
8132 | ||
8133 | /* Wait 50ms for the interrupts of previous mailbox commands */ | |
8134 | msleep(50); | |
8135 | /* Check active interrupts on message signaled interrupts */ | |
8136 | if (intr_mode == 0 || | |
8137 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { | |
8138 | /* Log the current active interrupt mode */ | |
8139 | phba->intr_mode = intr_mode; | |
8140 | lpfc_log_intr_mode(phba, intr_mode); | |
8141 | break; | |
8142 | } else { | |
8143 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8144 | "0447 Configure interrupt mode (%d) " | |
8145 | "failed active interrupt test.\n", | |
8146 | intr_mode); | |
8147 | /* Disable the current interrupt mode */ | |
8148 | lpfc_sli_disable_intr(phba); | |
8149 | /* Try next level of interrupt mode */ | |
8150 | cfg_mode = --intr_mode; | |
8151 | } | |
8152 | } | |
8153 | ||
8154 | /* Perform post initialization setup */ | |
8155 | lpfc_post_init_setup(phba); | |
8156 | ||
8157 | /* Check if there are static vports to be created. */ | |
8158 | lpfc_create_static_vport(phba); | |
8159 | ||
8160 | return 0; | |
8161 | ||
8162 | out_remove_device: | |
8163 | lpfc_unset_hba(phba); | |
8164 | out_free_sysfs_attr: | |
8165 | lpfc_free_sysfs_attr(vport); | |
8166 | out_destroy_shost: | |
8167 | lpfc_destroy_shost(phba); | |
8168 | out_unset_driver_resource: | |
8169 | lpfc_unset_driver_resource_phase2(phba); | |
8170 | out_free_iocb_list: | |
8171 | lpfc_free_iocb_list(phba); | |
8172 | out_unset_driver_resource_s3: | |
8173 | lpfc_sli_driver_resource_unset(phba); | |
8174 | out_unset_pci_mem_s3: | |
8175 | lpfc_sli_pci_mem_unset(phba); | |
8176 | out_disable_pci_dev: | |
8177 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
8178 | if (shost) |
8179 | scsi_host_put(shost); | |
da0436e9 JS |
8180 | out_free_phba: |
8181 | lpfc_hba_free(phba); | |
8182 | return error; | |
8183 | } | |
8184 | ||
8185 | /** | |
8186 | * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem. | |
8187 | * @pdev: pointer to PCI device | |
8188 | * | |
8189 | * This routine is to be called to disattach a device with SLI-3 interface | |
8190 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
8191 | * removed from PCI bus, it performs all the necessary cleanup for the HBA | |
8192 | * device to be removed from the PCI subsystem properly. | |
8193 | **/ | |
8194 | static void __devexit | |
8195 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) | |
8196 | { | |
8197 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8198 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
8199 | struct lpfc_vport **vports; | |
8200 | struct lpfc_hba *phba = vport->phba; | |
8201 | int i; | |
8202 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
8203 | ||
8204 | spin_lock_irq(&phba->hbalock); | |
8205 | vport->load_flag |= FC_UNLOADING; | |
8206 | spin_unlock_irq(&phba->hbalock); | |
8207 | ||
8208 | lpfc_free_sysfs_attr(vport); | |
8209 | ||
8210 | /* Release all the vports against this physical port */ | |
8211 | vports = lpfc_create_vport_work_array(phba); | |
8212 | if (vports != NULL) | |
8213 | for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) | |
8214 | fc_vport_terminate(vports[i]->fc_vport); | |
8215 | lpfc_destroy_vport_work_array(phba, vports); | |
8216 | ||
8217 | /* Remove FC host and then SCSI host with the physical port */ | |
8218 | fc_remove_host(shost); | |
8219 | scsi_remove_host(shost); | |
8220 | lpfc_cleanup(vport); | |
8221 | ||
8222 | /* | |
8223 | * Bring down the SLI Layer. This step disable all interrupts, | |
8224 | * clears the rings, discards all mailbox commands, and resets | |
8225 | * the HBA. | |
8226 | */ | |
8227 | ||
48e34d0f | 8228 | /* HBA interrupt will be disabled after this call */ |
da0436e9 JS |
8229 | lpfc_sli_hba_down(phba); |
8230 | /* Stop kthread signal shall trigger work_done one more time */ | |
8231 | kthread_stop(phba->worker_thread); | |
8232 | /* Final cleanup of txcmplq and reset the HBA */ | |
8233 | lpfc_sli_brdrestart(phba); | |
8234 | ||
8235 | lpfc_stop_hba_timers(phba); | |
8236 | spin_lock_irq(&phba->hbalock); | |
8237 | list_del_init(&vport->listentry); | |
8238 | spin_unlock_irq(&phba->hbalock); | |
8239 | ||
8240 | lpfc_debugfs_terminate(vport); | |
8241 | ||
8242 | /* Disable interrupt */ | |
8243 | lpfc_sli_disable_intr(phba); | |
8244 | ||
8245 | pci_set_drvdata(pdev, NULL); | |
8246 | scsi_host_put(shost); | |
8247 | ||
8248 | /* | |
8249 | * Call scsi_free before mem_free since scsi bufs are released to their | |
8250 | * corresponding pools here. | |
8251 | */ | |
8252 | lpfc_scsi_free(phba); | |
8253 | lpfc_mem_free_all(phba); | |
8254 | ||
8255 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
8256 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
8257 | ||
8258 | /* Free resources associated with SLI2 interface */ | |
8259 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
8260 | phba->slim2p.virt, phba->slim2p.phys); | |
8261 | ||
8262 | /* unmap adapter SLIM and Control Registers */ | |
8263 | iounmap(phba->ctrl_regs_memmap_p); | |
8264 | iounmap(phba->slim_memmap_p); | |
8265 | ||
8266 | lpfc_hba_free(phba); | |
8267 | ||
8268 | pci_release_selected_regions(pdev, bars); | |
8269 | pci_disable_device(pdev); | |
8270 | } | |
8271 | ||
8272 | /** | |
8273 | * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt | |
8274 | * @pdev: pointer to PCI device | |
8275 | * @msg: power management message | |
8276 | * | |
8277 | * This routine is to be called from the kernel's PCI subsystem to support | |
8278 | * system Power Management (PM) to device with SLI-3 interface spec. When | |
8279 | * PM invokes this method, it quiesces the device by stopping the driver's | |
8280 | * worker thread for the device, turning off device's interrupt and DMA, | |
8281 | * and bring the device offline. Note that as the driver implements the | |
8282 | * minimum PM requirements to a power-aware driver's PM support for the | |
8283 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
8284 | * to the suspend() method call will be treated as SUSPEND and the driver will | |
8285 | * fully reinitialize its device during resume() method call, the driver will | |
8286 | * set device to PCI_D3hot state in PCI config space instead of setting it | |
8287 | * according to the @msg provided by the PM. | |
8288 | * | |
8289 | * Return code | |
8290 | * 0 - driver suspended the device | |
8291 | * Error otherwise | |
8292 | **/ | |
8293 | static int | |
8294 | lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg) | |
8295 | { | |
8296 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8297 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8298 | ||
8299 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8300 | "0473 PCI device Power Management suspend.\n"); | |
8301 | ||
8302 | /* Bring down the device */ | |
8303 | lpfc_offline_prep(phba); | |
8304 | lpfc_offline(phba); | |
8305 | kthread_stop(phba->worker_thread); | |
8306 | ||
8307 | /* Disable interrupt from device */ | |
8308 | lpfc_sli_disable_intr(phba); | |
8309 | ||
8310 | /* Save device state to PCI config space */ | |
8311 | pci_save_state(pdev); | |
8312 | pci_set_power_state(pdev, PCI_D3hot); | |
8313 | ||
8314 | return 0; | |
8315 | } | |
8316 | ||
8317 | /** | |
8318 | * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt | |
8319 | * @pdev: pointer to PCI device | |
8320 | * | |
8321 | * This routine is to be called from the kernel's PCI subsystem to support | |
8322 | * system Power Management (PM) to device with SLI-3 interface spec. When PM | |
8323 | * invokes this method, it restores the device's PCI config space state and | |
8324 | * fully reinitializes the device and brings it online. Note that as the | |
8325 | * driver implements the minimum PM requirements to a power-aware driver's | |
8326 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, | |
8327 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the | |
8328 | * driver will fully reinitialize its device during resume() method call, | |
8329 | * the device will be set to PCI_D0 directly in PCI config space before | |
8330 | * restoring the state. | |
8331 | * | |
8332 | * Return code | |
8333 | * 0 - driver suspended the device | |
8334 | * Error otherwise | |
8335 | **/ | |
8336 | static int | |
8337 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) | |
8338 | { | |
8339 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8340 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8341 | uint32_t intr_mode; | |
8342 | int error; | |
8343 | ||
8344 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8345 | "0452 PCI device Power Management resume.\n"); | |
8346 | ||
8347 | /* Restore device state from PCI config space */ | |
8348 | pci_set_power_state(pdev, PCI_D0); | |
8349 | pci_restore_state(pdev); | |
0d878419 | 8350 | |
1dfb5a47 JS |
8351 | /* |
8352 | * As the new kernel behavior of pci_restore_state() API call clears | |
8353 | * device saved_state flag, need to save the restored state again. | |
8354 | */ | |
8355 | pci_save_state(pdev); | |
8356 | ||
da0436e9 JS |
8357 | if (pdev->is_busmaster) |
8358 | pci_set_master(pdev); | |
8359 | ||
8360 | /* Startup the kernel thread for this host adapter. */ | |
8361 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
8362 | "lpfc_worker_%d", phba->brd_no); | |
8363 | if (IS_ERR(phba->worker_thread)) { | |
8364 | error = PTR_ERR(phba->worker_thread); | |
8365 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8366 | "0434 PM resume failed to start worker " | |
8367 | "thread: error=x%x.\n", error); | |
8368 | return error; | |
8369 | } | |
8370 | ||
8371 | /* Configure and enable interrupt */ | |
8372 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
8373 | if (intr_mode == LPFC_INTR_ERROR) { | |
8374 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8375 | "0430 PM resume Failed to enable interrupt\n"); | |
8376 | return -EIO; | |
8377 | } else | |
8378 | phba->intr_mode = intr_mode; | |
8379 | ||
8380 | /* Restart HBA and bring it online */ | |
8381 | lpfc_sli_brdrestart(phba); | |
8382 | lpfc_online(phba); | |
8383 | ||
8384 | /* Log the current active interrupt mode */ | |
8385 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
8386 | ||
8387 | return 0; | |
8388 | } | |
8389 | ||
891478a2 JS |
8390 | /** |
8391 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover | |
8392 | * @phba: pointer to lpfc hba data structure. | |
8393 | * | |
8394 | * This routine is called to prepare the SLI3 device for PCI slot recover. It | |
e2af0d2e | 8395 | * aborts all the outstanding SCSI I/Os to the pci device. |
891478a2 JS |
8396 | **/ |
8397 | static void | |
8398 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) | |
8399 | { | |
e2af0d2e JS |
8400 | struct lpfc_sli *psli = &phba->sli; |
8401 | struct lpfc_sli_ring *pring; | |
8402 | ||
891478a2 JS |
8403 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
8404 | "2723 PCI channel I/O abort preparing for recovery\n"); | |
e2af0d2e JS |
8405 | |
8406 | /* | |
8407 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
8408 | * and let the SCSI mid-layer to retry them to recover. | |
8409 | */ | |
8410 | pring = &psli->ring[psli->fcp_ring]; | |
8411 | lpfc_sli_abort_iocb_ring(phba, pring); | |
891478a2 JS |
8412 | } |
8413 | ||
0d878419 JS |
8414 | /** |
8415 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset | |
8416 | * @phba: pointer to lpfc hba data structure. | |
8417 | * | |
8418 | * This routine is called to prepare the SLI3 device for PCI slot reset. It | |
8419 | * disables the device interrupt and pci device, and aborts the internal FCP | |
8420 | * pending I/Os. | |
8421 | **/ | |
8422 | static void | |
8423 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) | |
8424 | { | |
0d878419 | 8425 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
891478a2 | 8426 | "2710 PCI channel disable preparing for reset\n"); |
e2af0d2e | 8427 | |
75baf696 JS |
8428 | /* Block any management I/Os to the device */ |
8429 | lpfc_block_mgmt_io(phba); | |
8430 | ||
e2af0d2e JS |
8431 | /* Block all SCSI devices' I/Os on the host */ |
8432 | lpfc_scsi_dev_block(phba); | |
8433 | ||
8434 | /* stop all timers */ | |
8435 | lpfc_stop_hba_timers(phba); | |
8436 | ||
0d878419 JS |
8437 | /* Disable interrupt and pci device */ |
8438 | lpfc_sli_disable_intr(phba); | |
8439 | pci_disable_device(phba->pcidev); | |
75baf696 | 8440 | |
e2af0d2e JS |
8441 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
8442 | lpfc_sli_flush_fcp_rings(phba); | |
0d878419 JS |
8443 | } |
8444 | ||
8445 | /** | |
8446 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable | |
8447 | * @phba: pointer to lpfc hba data structure. | |
8448 | * | |
8449 | * This routine is called to prepare the SLI3 device for PCI slot permanently | |
8450 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
8451 | * pending I/Os. | |
8452 | **/ | |
8453 | static void | |
75baf696 | 8454 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
0d878419 JS |
8455 | { |
8456 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
891478a2 | 8457 | "2711 PCI channel permanent disable for failure\n"); |
e2af0d2e JS |
8458 | /* Block all SCSI devices' I/Os on the host */ |
8459 | lpfc_scsi_dev_block(phba); | |
8460 | ||
8461 | /* stop all timers */ | |
8462 | lpfc_stop_hba_timers(phba); | |
8463 | ||
0d878419 JS |
8464 | /* Clean up all driver's outstanding SCSI I/Os */ |
8465 | lpfc_sli_flush_fcp_rings(phba); | |
8466 | } | |
8467 | ||
da0436e9 JS |
8468 | /** |
8469 | * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error | |
8470 | * @pdev: pointer to PCI device. | |
8471 | * @state: the current PCI connection state. | |
8472 | * | |
8473 | * This routine is called from the PCI subsystem for I/O error handling to | |
8474 | * device with SLI-3 interface spec. This function is called by the PCI | |
8475 | * subsystem after a PCI bus error affecting this device has been detected. | |
8476 | * When this function is invoked, it will need to stop all the I/Os and | |
8477 | * interrupt(s) to the device. Once that is done, it will return | |
8478 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery | |
8479 | * as desired. | |
8480 | * | |
8481 | * Return codes | |
0d878419 | 8482 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
da0436e9 JS |
8483 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
8484 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8485 | **/ | |
8486 | static pci_ers_result_t | |
8487 | lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state) | |
8488 | { | |
8489 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8490 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
da0436e9 | 8491 | |
0d878419 JS |
8492 | switch (state) { |
8493 | case pci_channel_io_normal: | |
891478a2 JS |
8494 | /* Non-fatal error, prepare for recovery */ |
8495 | lpfc_sli_prep_dev_for_recover(phba); | |
0d878419 JS |
8496 | return PCI_ERS_RESULT_CAN_RECOVER; |
8497 | case pci_channel_io_frozen: | |
8498 | /* Fatal error, prepare for slot reset */ | |
8499 | lpfc_sli_prep_dev_for_reset(phba); | |
8500 | return PCI_ERS_RESULT_NEED_RESET; | |
8501 | case pci_channel_io_perm_failure: | |
8502 | /* Permanent failure, prepare for device down */ | |
75baf696 | 8503 | lpfc_sli_prep_dev_for_perm_failure(phba); |
da0436e9 | 8504 | return PCI_ERS_RESULT_DISCONNECT; |
0d878419 JS |
8505 | default: |
8506 | /* Unknown state, prepare and request slot reset */ | |
8507 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8508 | "0472 Unknown PCI error state: x%x\n", state); | |
8509 | lpfc_sli_prep_dev_for_reset(phba); | |
8510 | return PCI_ERS_RESULT_NEED_RESET; | |
da0436e9 | 8511 | } |
da0436e9 JS |
8512 | } |
8513 | ||
8514 | /** | |
8515 | * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch. | |
8516 | * @pdev: pointer to PCI device. | |
8517 | * | |
8518 | * This routine is called from the PCI subsystem for error handling to | |
8519 | * device with SLI-3 interface spec. This is called after PCI bus has been | |
8520 | * reset to restart the PCI card from scratch, as if from a cold-boot. | |
8521 | * During the PCI subsystem error recovery, after driver returns | |
8522 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error | |
8523 | * recovery and then call this routine before calling the .resume method | |
8524 | * to recover the device. This function will initialize the HBA device, | |
8525 | * enable the interrupt, but it will just put the HBA to offline state | |
8526 | * without passing any I/O traffic. | |
8527 | * | |
8528 | * Return codes | |
8529 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
8530 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8531 | */ | |
8532 | static pci_ers_result_t | |
8533 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) | |
8534 | { | |
8535 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8536 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8537 | struct lpfc_sli *psli = &phba->sli; | |
8538 | uint32_t intr_mode; | |
8539 | ||
8540 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
8541 | if (pci_enable_device_mem(pdev)) { | |
8542 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
8543 | "PCI device after reset.\n"); | |
8544 | return PCI_ERS_RESULT_DISCONNECT; | |
8545 | } | |
8546 | ||
8547 | pci_restore_state(pdev); | |
1dfb5a47 JS |
8548 | |
8549 | /* | |
8550 | * As the new kernel behavior of pci_restore_state() API call clears | |
8551 | * device saved_state flag, need to save the restored state again. | |
8552 | */ | |
8553 | pci_save_state(pdev); | |
8554 | ||
da0436e9 JS |
8555 | if (pdev->is_busmaster) |
8556 | pci_set_master(pdev); | |
8557 | ||
8558 | spin_lock_irq(&phba->hbalock); | |
8559 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
8560 | spin_unlock_irq(&phba->hbalock); | |
8561 | ||
8562 | /* Configure and enable interrupt */ | |
8563 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
8564 | if (intr_mode == LPFC_INTR_ERROR) { | |
8565 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8566 | "0427 Cannot re-enable interrupt after " | |
8567 | "slot reset.\n"); | |
8568 | return PCI_ERS_RESULT_DISCONNECT; | |
8569 | } else | |
8570 | phba->intr_mode = intr_mode; | |
8571 | ||
75baf696 JS |
8572 | /* Take device offline, it will perform cleanup */ |
8573 | lpfc_offline_prep(phba); | |
da0436e9 JS |
8574 | lpfc_offline(phba); |
8575 | lpfc_sli_brdrestart(phba); | |
8576 | ||
8577 | /* Log the current active interrupt mode */ | |
8578 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
8579 | ||
8580 | return PCI_ERS_RESULT_RECOVERED; | |
8581 | } | |
8582 | ||
8583 | /** | |
8584 | * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device. | |
8585 | * @pdev: pointer to PCI device | |
8586 | * | |
8587 | * This routine is called from the PCI subsystem for error handling to device | |
8588 | * with SLI-3 interface spec. It is called when kernel error recovery tells | |
8589 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus | |
8590 | * error recovery. After this call, traffic can start to flow from this device | |
8591 | * again. | |
8592 | */ | |
8593 | static void | |
8594 | lpfc_io_resume_s3(struct pci_dev *pdev) | |
8595 | { | |
8596 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8597 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
3772a991 | 8598 | |
e2af0d2e | 8599 | /* Bring device online, it will be no-op for non-fatal error resume */ |
da0436e9 | 8600 | lpfc_online(phba); |
0d878419 JS |
8601 | |
8602 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
8603 | if (phba->hba_flag & HBA_AER_ENABLED) | |
8604 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
da0436e9 | 8605 | } |
3772a991 | 8606 | |
da0436e9 JS |
8607 | /** |
8608 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve | |
8609 | * @phba: pointer to lpfc hba data structure. | |
8610 | * | |
8611 | * returns the number of ELS/CT IOCBs to reserve | |
8612 | **/ | |
8613 | int | |
8614 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) | |
8615 | { | |
8616 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; | |
8617 | ||
f1126688 JS |
8618 | if (phba->sli_rev == LPFC_SLI_REV4) { |
8619 | if (max_xri <= 100) | |
6a9c52cf | 8620 | return 10; |
f1126688 | 8621 | else if (max_xri <= 256) |
6a9c52cf | 8622 | return 25; |
f1126688 | 8623 | else if (max_xri <= 512) |
6a9c52cf | 8624 | return 50; |
f1126688 | 8625 | else if (max_xri <= 1024) |
6a9c52cf | 8626 | return 100; |
f1126688 | 8627 | else |
6a9c52cf | 8628 | return 150; |
f1126688 JS |
8629 | } else |
8630 | return 0; | |
3772a991 JS |
8631 | } |
8632 | ||
8633 | /** | |
da0436e9 | 8634 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
3772a991 JS |
8635 | * @pdev: pointer to PCI device |
8636 | * @pid: pointer to PCI device identifier | |
8637 | * | |
da0436e9 JS |
8638 | * This routine is called from the kernel's PCI subsystem to device with |
8639 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 | 8640 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
da0436e9 JS |
8641 | * information of the device and driver to see if the driver state that it |
8642 | * can support this kind of device. If the match is successful, the driver | |
8643 | * core invokes this routine. If this routine determines it can claim the HBA, | |
8644 | * it does all the initialization that it needs to do to handle the HBA | |
8645 | * properly. | |
3772a991 JS |
8646 | * |
8647 | * Return code | |
8648 | * 0 - driver can claim the device | |
8649 | * negative value - driver can not claim the device | |
8650 | **/ | |
8651 | static int __devinit | |
da0436e9 | 8652 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
3772a991 JS |
8653 | { |
8654 | struct lpfc_hba *phba; | |
8655 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 8656 | struct Scsi_Host *shost = NULL; |
3772a991 JS |
8657 | int error; |
8658 | uint32_t cfg_mode, intr_mode; | |
da0436e9 | 8659 | int mcnt; |
0558056c JS |
8660 | int adjusted_fcp_eq_count; |
8661 | int fcp_qidx; | |
3772a991 JS |
8662 | |
8663 | /* Allocate memory for HBA structure */ | |
8664 | phba = lpfc_hba_alloc(pdev); | |
8665 | if (!phba) | |
8666 | return -ENOMEM; | |
8667 | ||
8668 | /* Perform generic PCI device enabling operation */ | |
8669 | error = lpfc_enable_pci_dev(phba); | |
8670 | if (error) { | |
8671 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8672 | "1409 Failed to enable pci device.\n"); |
3772a991 JS |
8673 | goto out_free_phba; |
8674 | } | |
8675 | ||
da0436e9 JS |
8676 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
8677 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); | |
3772a991 JS |
8678 | if (error) |
8679 | goto out_disable_pci_dev; | |
8680 | ||
da0436e9 JS |
8681 | /* Set up SLI-4 specific device PCI memory space */ |
8682 | error = lpfc_sli4_pci_mem_setup(phba); | |
3772a991 JS |
8683 | if (error) { |
8684 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8685 | "1410 Failed to set up pci memory space.\n"); |
3772a991 JS |
8686 | goto out_disable_pci_dev; |
8687 | } | |
8688 | ||
8689 | /* Set up phase-1 common device driver resources */ | |
8690 | error = lpfc_setup_driver_resource_phase1(phba); | |
8691 | if (error) { | |
8692 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
8693 | "1411 Failed to set up driver resource.\n"); |
8694 | goto out_unset_pci_mem_s4; | |
3772a991 JS |
8695 | } |
8696 | ||
da0436e9 JS |
8697 | /* Set up SLI-4 Specific device driver resources */ |
8698 | error = lpfc_sli4_driver_resource_setup(phba); | |
3772a991 JS |
8699 | if (error) { |
8700 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
8701 | "1412 Failed to set up driver resource.\n"); |
8702 | goto out_unset_pci_mem_s4; | |
3772a991 JS |
8703 | } |
8704 | ||
8705 | /* Initialize and populate the iocb list per host */ | |
2a9bf3d0 JS |
8706 | |
8707 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8708 | "2821 initialize iocb list %d.\n", | |
8709 | phba->cfg_iocb_cnt*1024); | |
8710 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); | |
8711 | ||
3772a991 JS |
8712 | if (error) { |
8713 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
8714 | "1413 Failed to initialize iocb list.\n"); |
8715 | goto out_unset_driver_resource_s4; | |
3772a991 JS |
8716 | } |
8717 | ||
19ca7609 JS |
8718 | INIT_LIST_HEAD(&phba->active_rrq_list); |
8719 | ||
3772a991 JS |
8720 | /* Set up common device driver resources */ |
8721 | error = lpfc_setup_driver_resource_phase2(phba); | |
8722 | if (error) { | |
8723 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8724 | "1414 Failed to set up driver resource.\n"); |
3772a991 JS |
8725 | goto out_free_iocb_list; |
8726 | } | |
8727 | ||
8728 | /* Create SCSI host to the physical port */ | |
8729 | error = lpfc_create_shost(phba); | |
8730 | if (error) { | |
8731 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8732 | "1415 Failed to create scsi host.\n"); |
3772a991 JS |
8733 | goto out_unset_driver_resource; |
8734 | } | |
9399627f | 8735 | |
5b75da2f | 8736 | /* Configure sysfs attributes */ |
3772a991 JS |
8737 | vport = phba->pport; |
8738 | error = lpfc_alloc_sysfs_attr(vport); | |
8739 | if (error) { | |
9399627f | 8740 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 8741 | "1416 Failed to allocate sysfs attr\n"); |
3772a991 | 8742 | goto out_destroy_shost; |
98c9ea5c | 8743 | } |
875fbdfe | 8744 | |
6669f9bb | 8745 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
3772a991 | 8746 | /* Now, trying to enable interrupt and bring up the device */ |
5b75da2f JS |
8747 | cfg_mode = phba->cfg_use_msi; |
8748 | while (true) { | |
3772a991 JS |
8749 | /* Put device to a known state before enabling interrupt */ |
8750 | lpfc_stop_port(phba); | |
5b75da2f | 8751 | /* Configure and enable interrupt */ |
da0436e9 | 8752 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
5b75da2f JS |
8753 | if (intr_mode == LPFC_INTR_ERROR) { |
8754 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 8755 | "0426 Failed to enable interrupt.\n"); |
3772a991 | 8756 | error = -ENODEV; |
5b75da2f JS |
8757 | goto out_free_sysfs_attr; |
8758 | } | |
0558056c | 8759 | /* Default to single EQ for non-MSI-X */ |
def9c7a9 | 8760 | if (phba->intr_type != MSIX) |
0558056c JS |
8761 | adjusted_fcp_eq_count = 0; |
8762 | else if (phba->sli4_hba.msix_vec_nr < | |
8763 | phba->cfg_fcp_eq_count + 1) | |
8764 | adjusted_fcp_eq_count = phba->sli4_hba.msix_vec_nr - 1; | |
8765 | else | |
8766 | adjusted_fcp_eq_count = phba->cfg_fcp_eq_count; | |
8767 | /* Free unused EQs */ | |
8768 | for (fcp_qidx = adjusted_fcp_eq_count; | |
8769 | fcp_qidx < phba->cfg_fcp_eq_count; | |
8770 | fcp_qidx++) { | |
8771 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]); | |
8772 | /* do not delete the first fcp_cq */ | |
8773 | if (fcp_qidx) | |
8774 | lpfc_sli4_queue_free( | |
8775 | phba->sli4_hba.fcp_cq[fcp_qidx]); | |
8776 | } | |
8777 | phba->cfg_fcp_eq_count = adjusted_fcp_eq_count; | |
da0436e9 JS |
8778 | /* Set up SLI-4 HBA */ |
8779 | if (lpfc_sli4_hba_setup(phba)) { | |
5b75da2f | 8780 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 8781 | "1421 Failed to set up hba\n"); |
5b75da2f | 8782 | error = -ENODEV; |
da0436e9 | 8783 | goto out_disable_intr; |
5b75da2f JS |
8784 | } |
8785 | ||
da0436e9 JS |
8786 | /* Send NOP mbx cmds for non-INTx mode active interrupt test */ |
8787 | if (intr_mode != 0) | |
8788 | mcnt = lpfc_sli4_send_nop_mbox_cmds(phba, | |
8789 | LPFC_ACT_INTR_CNT); | |
8790 | ||
8791 | /* Check active interrupts received only for MSI/MSI-X */ | |
3772a991 | 8792 | if (intr_mode == 0 || |
da0436e9 | 8793 | phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) { |
5b75da2f JS |
8794 | /* Log the current active interrupt mode */ |
8795 | phba->intr_mode = intr_mode; | |
8796 | lpfc_log_intr_mode(phba, intr_mode); | |
8797 | break; | |
5b75da2f | 8798 | } |
da0436e9 JS |
8799 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
8800 | "0451 Configure interrupt mode (%d) " | |
8801 | "failed active interrupt test.\n", | |
8802 | intr_mode); | |
2fcee4bf JS |
8803 | /* Unset the previous SLI-4 HBA setup. */ |
8804 | /* | |
8805 | * TODO: Is this operation compatible with IF TYPE 2 | |
8806 | * devices? All port state is deleted and cleared. | |
8807 | */ | |
da0436e9 JS |
8808 | lpfc_sli4_unset_hba(phba); |
8809 | /* Try next level of interrupt mode */ | |
8810 | cfg_mode = --intr_mode; | |
98c9ea5c | 8811 | } |
858c9f6c | 8812 | |
3772a991 JS |
8813 | /* Perform post initialization setup */ |
8814 | lpfc_post_init_setup(phba); | |
dea3101e | 8815 | |
1c6834a7 JS |
8816 | /* Check if there are static vports to be created. */ |
8817 | lpfc_create_static_vport(phba); | |
8818 | ||
dea3101e JB |
8819 | return 0; |
8820 | ||
da0436e9 JS |
8821 | out_disable_intr: |
8822 | lpfc_sli4_disable_intr(phba); | |
5b75da2f JS |
8823 | out_free_sysfs_attr: |
8824 | lpfc_free_sysfs_attr(vport); | |
3772a991 JS |
8825 | out_destroy_shost: |
8826 | lpfc_destroy_shost(phba); | |
8827 | out_unset_driver_resource: | |
8828 | lpfc_unset_driver_resource_phase2(phba); | |
8829 | out_free_iocb_list: | |
8830 | lpfc_free_iocb_list(phba); | |
da0436e9 JS |
8831 | out_unset_driver_resource_s4: |
8832 | lpfc_sli4_driver_resource_unset(phba); | |
8833 | out_unset_pci_mem_s4: | |
8834 | lpfc_sli4_pci_mem_unset(phba); | |
3772a991 JS |
8835 | out_disable_pci_dev: |
8836 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
8837 | if (shost) |
8838 | scsi_host_put(shost); | |
2e0fef85 | 8839 | out_free_phba: |
3772a991 | 8840 | lpfc_hba_free(phba); |
dea3101e JB |
8841 | return error; |
8842 | } | |
8843 | ||
e59058c4 | 8844 | /** |
da0436e9 | 8845 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
e59058c4 JS |
8846 | * @pdev: pointer to PCI device |
8847 | * | |
da0436e9 JS |
8848 | * This routine is called from the kernel's PCI subsystem to device with |
8849 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 JS |
8850 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
8851 | * device to be removed from the PCI subsystem properly. | |
e59058c4 | 8852 | **/ |
dea3101e | 8853 | static void __devexit |
da0436e9 | 8854 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
dea3101e | 8855 | { |
da0436e9 | 8856 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2e0fef85 | 8857 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
eada272d | 8858 | struct lpfc_vport **vports; |
da0436e9 | 8859 | struct lpfc_hba *phba = vport->phba; |
eada272d | 8860 | int i; |
8a4df120 | 8861 | |
da0436e9 | 8862 | /* Mark the device unloading flag */ |
549e55cd | 8863 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 8864 | vport->load_flag |= FC_UNLOADING; |
549e55cd | 8865 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 8866 | |
da0436e9 | 8867 | /* Free the HBA sysfs attributes */ |
858c9f6c JS |
8868 | lpfc_free_sysfs_attr(vport); |
8869 | ||
eada272d JS |
8870 | /* Release all the vports against this physical port */ |
8871 | vports = lpfc_create_vport_work_array(phba); | |
8872 | if (vports != NULL) | |
3772a991 | 8873 | for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) |
eada272d JS |
8874 | fc_vport_terminate(vports[i]->fc_vport); |
8875 | lpfc_destroy_vport_work_array(phba, vports); | |
8876 | ||
8877 | /* Remove FC host and then SCSI host with the physical port */ | |
858c9f6c JS |
8878 | fc_remove_host(shost); |
8879 | scsi_remove_host(shost); | |
da0436e9 JS |
8880 | |
8881 | /* Perform cleanup on the physical port */ | |
87af33fe JS |
8882 | lpfc_cleanup(vport); |
8883 | ||
2e0fef85 | 8884 | /* |
da0436e9 | 8885 | * Bring down the SLI Layer. This step disables all interrupts, |
2e0fef85 | 8886 | * clears the rings, discards all mailbox commands, and resets |
da0436e9 | 8887 | * the HBA FCoE function. |
2e0fef85 | 8888 | */ |
da0436e9 JS |
8889 | lpfc_debugfs_terminate(vport); |
8890 | lpfc_sli4_hba_unset(phba); | |
a257bf90 | 8891 | |
858c9f6c JS |
8892 | spin_lock_irq(&phba->hbalock); |
8893 | list_del_init(&vport->listentry); | |
8894 | spin_unlock_irq(&phba->hbalock); | |
8895 | ||
3677a3a7 | 8896 | /* Perform scsi free before driver resource_unset since scsi |
da0436e9 | 8897 | * buffers are released to their corresponding pools here. |
2e0fef85 JS |
8898 | */ |
8899 | lpfc_scsi_free(phba); | |
da0436e9 | 8900 | lpfc_sli4_driver_resource_unset(phba); |
ed957684 | 8901 | |
da0436e9 JS |
8902 | /* Unmap adapter Control and Doorbell registers */ |
8903 | lpfc_sli4_pci_mem_unset(phba); | |
2e0fef85 | 8904 | |
da0436e9 JS |
8905 | /* Release PCI resources and disable device's PCI function */ |
8906 | scsi_host_put(shost); | |
8907 | lpfc_disable_pci_dev(phba); | |
2e0fef85 | 8908 | |
da0436e9 | 8909 | /* Finally, free the driver's device data structure */ |
3772a991 | 8910 | lpfc_hba_free(phba); |
2e0fef85 | 8911 | |
da0436e9 | 8912 | return; |
dea3101e JB |
8913 | } |
8914 | ||
3a55b532 | 8915 | /** |
da0436e9 | 8916 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
3a55b532 JS |
8917 | * @pdev: pointer to PCI device |
8918 | * @msg: power management message | |
8919 | * | |
da0436e9 JS |
8920 | * This routine is called from the kernel's PCI subsystem to support system |
8921 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes | |
8922 | * this method, it quiesces the device by stopping the driver's worker | |
8923 | * thread for the device, turning off device's interrupt and DMA, and bring | |
8924 | * the device offline. Note that as the driver implements the minimum PM | |
8925 | * requirements to a power-aware driver's PM support for suspend/resume -- all | |
8926 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() | |
8927 | * method call will be treated as SUSPEND and the driver will fully | |
8928 | * reinitialize its device during resume() method call, the driver will set | |
8929 | * device to PCI_D3hot state in PCI config space instead of setting it | |
3772a991 | 8930 | * according to the @msg provided by the PM. |
3a55b532 JS |
8931 | * |
8932 | * Return code | |
3772a991 JS |
8933 | * 0 - driver suspended the device |
8934 | * Error otherwise | |
3a55b532 JS |
8935 | **/ |
8936 | static int | |
da0436e9 | 8937 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
3a55b532 JS |
8938 | { |
8939 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8940 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8941 | ||
8942 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
75baf696 | 8943 | "2843 PCI device Power Management suspend.\n"); |
3a55b532 JS |
8944 | |
8945 | /* Bring down the device */ | |
8946 | lpfc_offline_prep(phba); | |
8947 | lpfc_offline(phba); | |
8948 | kthread_stop(phba->worker_thread); | |
8949 | ||
8950 | /* Disable interrupt from device */ | |
da0436e9 | 8951 | lpfc_sli4_disable_intr(phba); |
3a55b532 JS |
8952 | |
8953 | /* Save device state to PCI config space */ | |
8954 | pci_save_state(pdev); | |
8955 | pci_set_power_state(pdev, PCI_D3hot); | |
8956 | ||
8957 | return 0; | |
8958 | } | |
8959 | ||
8960 | /** | |
da0436e9 | 8961 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
3a55b532 JS |
8962 | * @pdev: pointer to PCI device |
8963 | * | |
da0436e9 JS |
8964 | * This routine is called from the kernel's PCI subsystem to support system |
8965 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes | |
8966 | * this method, it restores the device's PCI config space state and fully | |
8967 | * reinitializes the device and brings it online. Note that as the driver | |
8968 | * implements the minimum PM requirements to a power-aware driver's PM for | |
8969 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
8970 | * to the suspend() method call will be treated as SUSPEND and the driver | |
8971 | * will fully reinitialize its device during resume() method call, the device | |
8972 | * will be set to PCI_D0 directly in PCI config space before restoring the | |
8973 | * state. | |
3a55b532 JS |
8974 | * |
8975 | * Return code | |
3772a991 JS |
8976 | * 0 - driver suspended the device |
8977 | * Error otherwise | |
3a55b532 JS |
8978 | **/ |
8979 | static int | |
da0436e9 | 8980 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
3a55b532 JS |
8981 | { |
8982 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8983 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
5b75da2f | 8984 | uint32_t intr_mode; |
3a55b532 JS |
8985 | int error; |
8986 | ||
8987 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
da0436e9 | 8988 | "0292 PCI device Power Management resume.\n"); |
3a55b532 JS |
8989 | |
8990 | /* Restore device state from PCI config space */ | |
8991 | pci_set_power_state(pdev, PCI_D0); | |
8992 | pci_restore_state(pdev); | |
1dfb5a47 JS |
8993 | |
8994 | /* | |
8995 | * As the new kernel behavior of pci_restore_state() API call clears | |
8996 | * device saved_state flag, need to save the restored state again. | |
8997 | */ | |
8998 | pci_save_state(pdev); | |
8999 | ||
3a55b532 JS |
9000 | if (pdev->is_busmaster) |
9001 | pci_set_master(pdev); | |
9002 | ||
da0436e9 | 9003 | /* Startup the kernel thread for this host adapter. */ |
3a55b532 JS |
9004 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
9005 | "lpfc_worker_%d", phba->brd_no); | |
9006 | if (IS_ERR(phba->worker_thread)) { | |
9007 | error = PTR_ERR(phba->worker_thread); | |
9008 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9009 | "0293 PM resume failed to start worker " |
3a55b532 JS |
9010 | "thread: error=x%x.\n", error); |
9011 | return error; | |
9012 | } | |
9013 | ||
5b75da2f | 9014 | /* Configure and enable interrupt */ |
da0436e9 | 9015 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
5b75da2f | 9016 | if (intr_mode == LPFC_INTR_ERROR) { |
3a55b532 | 9017 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 9018 | "0294 PM resume Failed to enable interrupt\n"); |
5b75da2f JS |
9019 | return -EIO; |
9020 | } else | |
9021 | phba->intr_mode = intr_mode; | |
3a55b532 JS |
9022 | |
9023 | /* Restart HBA and bring it online */ | |
9024 | lpfc_sli_brdrestart(phba); | |
9025 | lpfc_online(phba); | |
9026 | ||
5b75da2f JS |
9027 | /* Log the current active interrupt mode */ |
9028 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
9029 | ||
3a55b532 JS |
9030 | return 0; |
9031 | } | |
9032 | ||
75baf696 JS |
9033 | /** |
9034 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover | |
9035 | * @phba: pointer to lpfc hba data structure. | |
9036 | * | |
9037 | * This routine is called to prepare the SLI4 device for PCI slot recover. It | |
9038 | * aborts all the outstanding SCSI I/Os to the pci device. | |
9039 | **/ | |
9040 | static void | |
9041 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) | |
9042 | { | |
9043 | struct lpfc_sli *psli = &phba->sli; | |
9044 | struct lpfc_sli_ring *pring; | |
9045 | ||
9046 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9047 | "2828 PCI channel I/O abort preparing for recovery\n"); | |
9048 | /* | |
9049 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
9050 | * and let the SCSI mid-layer to retry them to recover. | |
9051 | */ | |
9052 | pring = &psli->ring[psli->fcp_ring]; | |
9053 | lpfc_sli_abort_iocb_ring(phba, pring); | |
9054 | } | |
9055 | ||
9056 | /** | |
9057 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset | |
9058 | * @phba: pointer to lpfc hba data structure. | |
9059 | * | |
9060 | * This routine is called to prepare the SLI4 device for PCI slot reset. It | |
9061 | * disables the device interrupt and pci device, and aborts the internal FCP | |
9062 | * pending I/Os. | |
9063 | **/ | |
9064 | static void | |
9065 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) | |
9066 | { | |
9067 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9068 | "2826 PCI channel disable preparing for reset\n"); | |
9069 | ||
9070 | /* Block any management I/Os to the device */ | |
9071 | lpfc_block_mgmt_io(phba); | |
9072 | ||
9073 | /* Block all SCSI devices' I/Os on the host */ | |
9074 | lpfc_scsi_dev_block(phba); | |
9075 | ||
9076 | /* stop all timers */ | |
9077 | lpfc_stop_hba_timers(phba); | |
9078 | ||
9079 | /* Disable interrupt and pci device */ | |
9080 | lpfc_sli4_disable_intr(phba); | |
9081 | pci_disable_device(phba->pcidev); | |
9082 | ||
9083 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ | |
9084 | lpfc_sli_flush_fcp_rings(phba); | |
9085 | } | |
9086 | ||
9087 | /** | |
9088 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable | |
9089 | * @phba: pointer to lpfc hba data structure. | |
9090 | * | |
9091 | * This routine is called to prepare the SLI4 device for PCI slot permanently | |
9092 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
9093 | * pending I/Os. | |
9094 | **/ | |
9095 | static void | |
9096 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) | |
9097 | { | |
9098 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9099 | "2827 PCI channel permanent disable for failure\n"); | |
9100 | ||
9101 | /* Block all SCSI devices' I/Os on the host */ | |
9102 | lpfc_scsi_dev_block(phba); | |
9103 | ||
9104 | /* stop all timers */ | |
9105 | lpfc_stop_hba_timers(phba); | |
9106 | ||
9107 | /* Clean up all driver's outstanding SCSI I/Os */ | |
9108 | lpfc_sli_flush_fcp_rings(phba); | |
9109 | } | |
9110 | ||
8d63f375 | 9111 | /** |
da0436e9 | 9112 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
e59058c4 JS |
9113 | * @pdev: pointer to PCI device. |
9114 | * @state: the current PCI connection state. | |
8d63f375 | 9115 | * |
da0436e9 JS |
9116 | * This routine is called from the PCI subsystem for error handling to device |
9117 | * with SLI-4 interface spec. This function is called by the PCI subsystem | |
9118 | * after a PCI bus error affecting this device has been detected. When this | |
9119 | * function is invoked, it will need to stop all the I/Os and interrupt(s) | |
9120 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET | |
9121 | * for the PCI subsystem to perform proper recovery as desired. | |
e59058c4 JS |
9122 | * |
9123 | * Return codes | |
3772a991 JS |
9124 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
9125 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
e59058c4 | 9126 | **/ |
3772a991 | 9127 | static pci_ers_result_t |
da0436e9 | 9128 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
8d63f375 | 9129 | { |
75baf696 JS |
9130 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
9131 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9132 | ||
9133 | switch (state) { | |
9134 | case pci_channel_io_normal: | |
9135 | /* Non-fatal error, prepare for recovery */ | |
9136 | lpfc_sli4_prep_dev_for_recover(phba); | |
9137 | return PCI_ERS_RESULT_CAN_RECOVER; | |
9138 | case pci_channel_io_frozen: | |
9139 | /* Fatal error, prepare for slot reset */ | |
9140 | lpfc_sli4_prep_dev_for_reset(phba); | |
9141 | return PCI_ERS_RESULT_NEED_RESET; | |
9142 | case pci_channel_io_perm_failure: | |
9143 | /* Permanent failure, prepare for device down */ | |
9144 | lpfc_sli4_prep_dev_for_perm_failure(phba); | |
9145 | return PCI_ERS_RESULT_DISCONNECT; | |
9146 | default: | |
9147 | /* Unknown state, prepare and request slot reset */ | |
9148 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9149 | "2825 Unknown PCI error state: x%x\n", state); | |
9150 | lpfc_sli4_prep_dev_for_reset(phba); | |
9151 | return PCI_ERS_RESULT_NEED_RESET; | |
9152 | } | |
8d63f375 LV |
9153 | } |
9154 | ||
9155 | /** | |
da0436e9 | 9156 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
e59058c4 JS |
9157 | * @pdev: pointer to PCI device. |
9158 | * | |
da0436e9 JS |
9159 | * This routine is called from the PCI subsystem for error handling to device |
9160 | * with SLI-4 interface spec. It is called after PCI bus has been reset to | |
9161 | * restart the PCI card from scratch, as if from a cold-boot. During the | |
9162 | * PCI subsystem error recovery, after the driver returns | |
3772a991 | 9163 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
da0436e9 JS |
9164 | * recovery and then call this routine before calling the .resume method to |
9165 | * recover the device. This function will initialize the HBA device, enable | |
9166 | * the interrupt, but it will just put the HBA to offline state without | |
9167 | * passing any I/O traffic. | |
8d63f375 | 9168 | * |
e59058c4 | 9169 | * Return codes |
3772a991 JS |
9170 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
9171 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8d63f375 | 9172 | */ |
3772a991 | 9173 | static pci_ers_result_t |
da0436e9 | 9174 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
8d63f375 | 9175 | { |
75baf696 JS |
9176 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
9177 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9178 | struct lpfc_sli *psli = &phba->sli; | |
9179 | uint32_t intr_mode; | |
9180 | ||
9181 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
9182 | if (pci_enable_device_mem(pdev)) { | |
9183 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
9184 | "PCI device after reset.\n"); | |
9185 | return PCI_ERS_RESULT_DISCONNECT; | |
9186 | } | |
9187 | ||
9188 | pci_restore_state(pdev); | |
9189 | if (pdev->is_busmaster) | |
9190 | pci_set_master(pdev); | |
9191 | ||
9192 | spin_lock_irq(&phba->hbalock); | |
9193 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
9194 | spin_unlock_irq(&phba->hbalock); | |
9195 | ||
9196 | /* Configure and enable interrupt */ | |
9197 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); | |
9198 | if (intr_mode == LPFC_INTR_ERROR) { | |
9199 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9200 | "2824 Cannot re-enable interrupt after " | |
9201 | "slot reset.\n"); | |
9202 | return PCI_ERS_RESULT_DISCONNECT; | |
9203 | } else | |
9204 | phba->intr_mode = intr_mode; | |
9205 | ||
9206 | /* Log the current active interrupt mode */ | |
9207 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
9208 | ||
8d63f375 LV |
9209 | return PCI_ERS_RESULT_RECOVERED; |
9210 | } | |
9211 | ||
9212 | /** | |
da0436e9 | 9213 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
e59058c4 | 9214 | * @pdev: pointer to PCI device |
8d63f375 | 9215 | * |
3772a991 | 9216 | * This routine is called from the PCI subsystem for error handling to device |
da0436e9 | 9217 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
3772a991 JS |
9218 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
9219 | * error recovery. After this call, traffic can start to flow from this device | |
9220 | * again. | |
da0436e9 | 9221 | **/ |
3772a991 | 9222 | static void |
da0436e9 | 9223 | lpfc_io_resume_s4(struct pci_dev *pdev) |
8d63f375 | 9224 | { |
75baf696 JS |
9225 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
9226 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9227 | ||
9228 | /* | |
9229 | * In case of slot reset, as function reset is performed through | |
9230 | * mailbox command which needs DMA to be enabled, this operation | |
9231 | * has to be moved to the io resume phase. Taking device offline | |
9232 | * will perform the necessary cleanup. | |
9233 | */ | |
9234 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { | |
9235 | /* Perform device reset */ | |
9236 | lpfc_offline_prep(phba); | |
9237 | lpfc_offline(phba); | |
9238 | lpfc_sli_brdrestart(phba); | |
9239 | /* Bring the device back online */ | |
9240 | lpfc_online(phba); | |
9241 | } | |
9242 | ||
9243 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
9244 | if (phba->hba_flag & HBA_AER_ENABLED) | |
9245 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
8d63f375 LV |
9246 | } |
9247 | ||
3772a991 JS |
9248 | /** |
9249 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem | |
9250 | * @pdev: pointer to PCI device | |
9251 | * @pid: pointer to PCI device identifier | |
9252 | * | |
9253 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
9254 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks | |
9255 | * at PCI device-specific information of the device and driver to see if the | |
9256 | * driver state that it can support this kind of device. If the match is | |
9257 | * successful, the driver core invokes this routine. This routine dispatches | |
9258 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will | |
9259 | * do all the initialization that it needs to do to handle the HBA device | |
9260 | * properly. | |
9261 | * | |
9262 | * Return code | |
9263 | * 0 - driver can claim the device | |
9264 | * negative value - driver can not claim the device | |
9265 | **/ | |
9266 | static int __devinit | |
9267 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | |
9268 | { | |
9269 | int rc; | |
8fa38513 | 9270 | struct lpfc_sli_intf intf; |
3772a991 | 9271 | |
28baac74 | 9272 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
3772a991 JS |
9273 | return -ENODEV; |
9274 | ||
8fa38513 | 9275 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
28baac74 | 9276 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
da0436e9 | 9277 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
8fa38513 | 9278 | else |
3772a991 | 9279 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
8fa38513 | 9280 | |
3772a991 JS |
9281 | return rc; |
9282 | } | |
9283 | ||
9284 | /** | |
9285 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem | |
9286 | * @pdev: pointer to PCI device | |
9287 | * | |
9288 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
9289 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. | |
9290 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device | |
9291 | * remove routine, which will perform all the necessary cleanup for the | |
9292 | * device to be removed from the PCI subsystem properly. | |
9293 | **/ | |
9294 | static void __devexit | |
9295 | lpfc_pci_remove_one(struct pci_dev *pdev) | |
9296 | { | |
9297 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9298 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9299 | ||
9300 | switch (phba->pci_dev_grp) { | |
9301 | case LPFC_PCI_DEV_LP: | |
9302 | lpfc_pci_remove_one_s3(pdev); | |
9303 | break; | |
da0436e9 JS |
9304 | case LPFC_PCI_DEV_OC: |
9305 | lpfc_pci_remove_one_s4(pdev); | |
9306 | break; | |
3772a991 JS |
9307 | default: |
9308 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9309 | "1424 Invalid PCI device group: 0x%x\n", | |
9310 | phba->pci_dev_grp); | |
9311 | break; | |
9312 | } | |
9313 | return; | |
9314 | } | |
9315 | ||
9316 | /** | |
9317 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management | |
9318 | * @pdev: pointer to PCI device | |
9319 | * @msg: power management message | |
9320 | * | |
9321 | * This routine is to be registered to the kernel's PCI subsystem to support | |
9322 | * system Power Management (PM). When PM invokes this method, it dispatches | |
9323 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will | |
9324 | * suspend the device. | |
9325 | * | |
9326 | * Return code | |
9327 | * 0 - driver suspended the device | |
9328 | * Error otherwise | |
9329 | **/ | |
9330 | static int | |
9331 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | |
9332 | { | |
9333 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9334 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9335 | int rc = -ENODEV; | |
9336 | ||
9337 | switch (phba->pci_dev_grp) { | |
9338 | case LPFC_PCI_DEV_LP: | |
9339 | rc = lpfc_pci_suspend_one_s3(pdev, msg); | |
9340 | break; | |
da0436e9 JS |
9341 | case LPFC_PCI_DEV_OC: |
9342 | rc = lpfc_pci_suspend_one_s4(pdev, msg); | |
9343 | break; | |
3772a991 JS |
9344 | default: |
9345 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9346 | "1425 Invalid PCI device group: 0x%x\n", | |
9347 | phba->pci_dev_grp); | |
9348 | break; | |
9349 | } | |
9350 | return rc; | |
9351 | } | |
9352 | ||
9353 | /** | |
9354 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management | |
9355 | * @pdev: pointer to PCI device | |
9356 | * | |
9357 | * This routine is to be registered to the kernel's PCI subsystem to support | |
9358 | * system Power Management (PM). When PM invokes this method, it dispatches | |
9359 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will | |
9360 | * resume the device. | |
9361 | * | |
9362 | * Return code | |
9363 | * 0 - driver suspended the device | |
9364 | * Error otherwise | |
9365 | **/ | |
9366 | static int | |
9367 | lpfc_pci_resume_one(struct pci_dev *pdev) | |
9368 | { | |
9369 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9370 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9371 | int rc = -ENODEV; | |
9372 | ||
9373 | switch (phba->pci_dev_grp) { | |
9374 | case LPFC_PCI_DEV_LP: | |
9375 | rc = lpfc_pci_resume_one_s3(pdev); | |
9376 | break; | |
da0436e9 JS |
9377 | case LPFC_PCI_DEV_OC: |
9378 | rc = lpfc_pci_resume_one_s4(pdev); | |
9379 | break; | |
3772a991 JS |
9380 | default: |
9381 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9382 | "1426 Invalid PCI device group: 0x%x\n", | |
9383 | phba->pci_dev_grp); | |
9384 | break; | |
9385 | } | |
9386 | return rc; | |
9387 | } | |
9388 | ||
9389 | /** | |
9390 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error | |
9391 | * @pdev: pointer to PCI device. | |
9392 | * @state: the current PCI connection state. | |
9393 | * | |
9394 | * This routine is registered to the PCI subsystem for error handling. This | |
9395 | * function is called by the PCI subsystem after a PCI bus error affecting | |
9396 | * this device has been detected. When this routine is invoked, it dispatches | |
9397 | * the action to the proper SLI-3 or SLI-4 device error detected handling | |
9398 | * routine, which will perform the proper error detected operation. | |
9399 | * | |
9400 | * Return codes | |
9401 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery | |
9402 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
9403 | **/ | |
9404 | static pci_ers_result_t | |
9405 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | |
9406 | { | |
9407 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9408 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9409 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
9410 | ||
9411 | switch (phba->pci_dev_grp) { | |
9412 | case LPFC_PCI_DEV_LP: | |
9413 | rc = lpfc_io_error_detected_s3(pdev, state); | |
9414 | break; | |
da0436e9 JS |
9415 | case LPFC_PCI_DEV_OC: |
9416 | rc = lpfc_io_error_detected_s4(pdev, state); | |
9417 | break; | |
3772a991 JS |
9418 | default: |
9419 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9420 | "1427 Invalid PCI device group: 0x%x\n", | |
9421 | phba->pci_dev_grp); | |
9422 | break; | |
9423 | } | |
9424 | return rc; | |
9425 | } | |
9426 | ||
9427 | /** | |
9428 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch | |
9429 | * @pdev: pointer to PCI device. | |
9430 | * | |
9431 | * This routine is registered to the PCI subsystem for error handling. This | |
9432 | * function is called after PCI bus has been reset to restart the PCI card | |
9433 | * from scratch, as if from a cold-boot. When this routine is invoked, it | |
9434 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling | |
9435 | * routine, which will perform the proper device reset. | |
9436 | * | |
9437 | * Return codes | |
9438 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
9439 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
9440 | **/ | |
9441 | static pci_ers_result_t | |
9442 | lpfc_io_slot_reset(struct pci_dev *pdev) | |
9443 | { | |
9444 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9445 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9446 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
9447 | ||
9448 | switch (phba->pci_dev_grp) { | |
9449 | case LPFC_PCI_DEV_LP: | |
9450 | rc = lpfc_io_slot_reset_s3(pdev); | |
9451 | break; | |
da0436e9 JS |
9452 | case LPFC_PCI_DEV_OC: |
9453 | rc = lpfc_io_slot_reset_s4(pdev); | |
9454 | break; | |
3772a991 JS |
9455 | default: |
9456 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9457 | "1428 Invalid PCI device group: 0x%x\n", | |
9458 | phba->pci_dev_grp); | |
9459 | break; | |
9460 | } | |
9461 | return rc; | |
9462 | } | |
9463 | ||
9464 | /** | |
9465 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation | |
9466 | * @pdev: pointer to PCI device | |
9467 | * | |
9468 | * This routine is registered to the PCI subsystem for error handling. It | |
9469 | * is called when kernel error recovery tells the lpfc driver that it is | |
9470 | * OK to resume normal PCI operation after PCI bus error recovery. When | |
9471 | * this routine is invoked, it dispatches the action to the proper SLI-3 | |
9472 | * or SLI-4 device io_resume routine, which will resume the device operation. | |
9473 | **/ | |
9474 | static void | |
9475 | lpfc_io_resume(struct pci_dev *pdev) | |
9476 | { | |
9477 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9478 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9479 | ||
9480 | switch (phba->pci_dev_grp) { | |
9481 | case LPFC_PCI_DEV_LP: | |
9482 | lpfc_io_resume_s3(pdev); | |
9483 | break; | |
da0436e9 JS |
9484 | case LPFC_PCI_DEV_OC: |
9485 | lpfc_io_resume_s4(pdev); | |
9486 | break; | |
3772a991 JS |
9487 | default: |
9488 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9489 | "1429 Invalid PCI device group: 0x%x\n", | |
9490 | phba->pci_dev_grp); | |
9491 | break; | |
9492 | } | |
9493 | return; | |
9494 | } | |
9495 | ||
dea3101e JB |
9496 | static struct pci_device_id lpfc_id_table[] = { |
9497 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, | |
9498 | PCI_ANY_ID, PCI_ANY_ID, }, | |
06325e74 JSEC |
9499 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
9500 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
9501 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
9502 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9503 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, | |
9504 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9505 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, | |
9506 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9507 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, | |
9508 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9509 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, | |
9510 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9511 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, | |
9512 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9513 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, | |
9514 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
9515 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
9516 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9517 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, | |
9518 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9519 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, | |
9520 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
9521 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
9522 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
9523 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
9524 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9525 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, | |
9526 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
9527 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
9528 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9529 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, | |
9530 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9531 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, | |
9532 | PCI_ANY_ID, PCI_ANY_ID, }, | |
84774a4d JS |
9533 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
9534 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
9535 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
9536 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9537 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, | |
9538 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
9539 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
9540 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9541 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, | |
9542 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9543 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, | |
9544 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9545 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, | |
9546 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9547 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, | |
9548 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
9549 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
9550 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9551 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, | |
9552 | PCI_ANY_ID, PCI_ANY_ID, }, | |
b87eab38 JS |
9553 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
9554 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9555 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, | |
9556 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9557 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, | |
9558 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9559 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, | |
9560 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9561 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, | |
9562 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9563 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, | |
9564 | PCI_ANY_ID, PCI_ANY_ID, }, | |
84774a4d JS |
9565 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
9566 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9567 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, | |
9568 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9569 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, | |
9570 | PCI_ANY_ID, PCI_ANY_ID, }, | |
3772a991 JS |
9571 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, |
9572 | PCI_ANY_ID, PCI_ANY_ID, }, | |
a747c9ce JS |
9573 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT, |
9574 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9575 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON, | |
6669f9bb | 9576 | PCI_ANY_ID, PCI_ANY_ID, }, |
98fc5dd9 JS |
9577 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS, |
9578 | PCI_ANY_ID, PCI_ANY_ID, }, | |
085c647c JS |
9579 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC, |
9580 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9581 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE, | |
9582 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
9583 | { 0 } |
9584 | }; | |
9585 | ||
9586 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); | |
9587 | ||
8d63f375 LV |
9588 | static struct pci_error_handlers lpfc_err_handler = { |
9589 | .error_detected = lpfc_io_error_detected, | |
9590 | .slot_reset = lpfc_io_slot_reset, | |
9591 | .resume = lpfc_io_resume, | |
9592 | }; | |
9593 | ||
dea3101e JB |
9594 | static struct pci_driver lpfc_driver = { |
9595 | .name = LPFC_DRIVER_NAME, | |
9596 | .id_table = lpfc_id_table, | |
9597 | .probe = lpfc_pci_probe_one, | |
9598 | .remove = __devexit_p(lpfc_pci_remove_one), | |
3a55b532 | 9599 | .suspend = lpfc_pci_suspend_one, |
3772a991 | 9600 | .resume = lpfc_pci_resume_one, |
2e0fef85 | 9601 | .err_handler = &lpfc_err_handler, |
dea3101e JB |
9602 | }; |
9603 | ||
e59058c4 | 9604 | /** |
3621a710 | 9605 | * lpfc_init - lpfc module initialization routine |
e59058c4 JS |
9606 | * |
9607 | * This routine is to be invoked when the lpfc module is loaded into the | |
9608 | * kernel. The special kernel macro module_init() is used to indicate the | |
9609 | * role of this routine to the kernel as lpfc module entry point. | |
9610 | * | |
9611 | * Return codes | |
9612 | * 0 - successful | |
9613 | * -ENOMEM - FC attach transport failed | |
9614 | * all others - failed | |
9615 | */ | |
dea3101e JB |
9616 | static int __init |
9617 | lpfc_init(void) | |
9618 | { | |
9619 | int error = 0; | |
9620 | ||
9621 | printk(LPFC_MODULE_DESC "\n"); | |
c44ce173 | 9622 | printk(LPFC_COPYRIGHT "\n"); |
dea3101e | 9623 | |
7ee5d43e JS |
9624 | if (lpfc_enable_npiv) { |
9625 | lpfc_transport_functions.vport_create = lpfc_vport_create; | |
9626 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; | |
9627 | } | |
dea3101e JB |
9628 | lpfc_transport_template = |
9629 | fc_attach_transport(&lpfc_transport_functions); | |
7ee5d43e | 9630 | if (lpfc_transport_template == NULL) |
dea3101e | 9631 | return -ENOMEM; |
7ee5d43e | 9632 | if (lpfc_enable_npiv) { |
7ee5d43e | 9633 | lpfc_vport_transport_template = |
98c9ea5c JS |
9634 | fc_attach_transport(&lpfc_vport_transport_functions); |
9635 | if (lpfc_vport_transport_template == NULL) { | |
9636 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e | 9637 | return -ENOMEM; |
98c9ea5c | 9638 | } |
7ee5d43e | 9639 | } |
dea3101e | 9640 | error = pci_register_driver(&lpfc_driver); |
92d7f7b0 | 9641 | if (error) { |
dea3101e | 9642 | fc_release_transport(lpfc_transport_template); |
d7c255b2 JS |
9643 | if (lpfc_enable_npiv) |
9644 | fc_release_transport(lpfc_vport_transport_template); | |
92d7f7b0 | 9645 | } |
dea3101e JB |
9646 | |
9647 | return error; | |
9648 | } | |
9649 | ||
e59058c4 | 9650 | /** |
3621a710 | 9651 | * lpfc_exit - lpfc module removal routine |
e59058c4 JS |
9652 | * |
9653 | * This routine is invoked when the lpfc module is removed from the kernel. | |
9654 | * The special kernel macro module_exit() is used to indicate the role of | |
9655 | * this routine to the kernel as lpfc module exit point. | |
9656 | */ | |
dea3101e JB |
9657 | static void __exit |
9658 | lpfc_exit(void) | |
9659 | { | |
9660 | pci_unregister_driver(&lpfc_driver); | |
9661 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e JS |
9662 | if (lpfc_enable_npiv) |
9663 | fc_release_transport(lpfc_vport_transport_template); | |
81301a9b | 9664 | if (_dump_buf_data) { |
6a9c52cf JS |
9665 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
9666 | "_dump_buf_data at 0x%p\n", | |
81301a9b JS |
9667 | (1L << _dump_buf_data_order), _dump_buf_data); |
9668 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); | |
9669 | } | |
9670 | ||
9671 | if (_dump_buf_dif) { | |
6a9c52cf JS |
9672 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
9673 | "_dump_buf_dif at 0x%p\n", | |
81301a9b JS |
9674 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
9675 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); | |
9676 | } | |
dea3101e JB |
9677 | } |
9678 | ||
9679 | module_init(lpfc_init); | |
9680 | module_exit(lpfc_exit); | |
9681 | MODULE_LICENSE("GPL"); | |
9682 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); | |
9683 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); | |
9684 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |