Commit | Line | Data |
---|---|---|
dea3101e | 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 | 8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
10 | * modify it under the terms of version 2 of the GNU General * |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
dea3101e | 20 | *******************************************************************/ |
21 | ||
dea3101e | 22 | #include <linux/blkdev.h> |
23 | #include <linux/delay.h> | |
24 | #include <linux/dma-mapping.h> | |
25 | #include <linux/idr.h> | |
26 | #include <linux/interrupt.h> | |
acf3368f | 27 | #include <linux/module.h> |
dea3101e | 28 | #include <linux/kthread.h> |
29 | #include <linux/pci.h> | |
30 | #include <linux/spinlock.h> | |
92d7f7b0 | 31 | #include <linux/ctype.h> |
0d878419 | 32 | #include <linux/aer.h> |
5a0e3ad6 | 33 | #include <linux/slab.h> |
52d52440 | 34 | #include <linux/firmware.h> |
dea3101e | 35 | |
91886523 | 36 | #include <scsi/scsi.h> |
dea3101e | 37 | #include <scsi/scsi_device.h> |
38 | #include <scsi/scsi_host.h> | |
39 | #include <scsi/scsi_transport_fc.h> | |
40 | ||
da0436e9 | 41 | #include "lpfc_hw4.h" |
dea3101e | 42 | #include "lpfc_hw.h" |
43 | #include "lpfc_sli.h" | |
da0436e9 | 44 | #include "lpfc_sli4.h" |
ea2151b4 | 45 | #include "lpfc_nl.h" |
dea3101e | 46 | #include "lpfc_disc.h" |
47 | #include "lpfc_scsi.h" | |
48 | #include "lpfc.h" | |
49 | #include "lpfc_logmsg.h" | |
50 | #include "lpfc_crtn.h" | |
92d7f7b0 | 51 | #include "lpfc_vport.h" |
dea3101e | 52 | #include "lpfc_version.h" |
53 | ||
81301a9b JS |
54 | char *_dump_buf_data; |
55 | unsigned long _dump_buf_data_order; | |
56 | char *_dump_buf_dif; | |
57 | unsigned long _dump_buf_dif_order; | |
58 | spinlock_t _dump_buf_lock; | |
59 | ||
dea3101e | 60 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
61 | static int lpfc_post_rcv_buf(struct lpfc_hba *); | |
5350d872 | 62 | static int lpfc_sli4_queue_verify(struct lpfc_hba *); |
da0436e9 JS |
63 | static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); |
64 | static int lpfc_setup_endian_order(struct lpfc_hba *); | |
da0436e9 JS |
65 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); |
66 | static void lpfc_free_sgl_list(struct lpfc_hba *); | |
67 | static int lpfc_init_sgl_list(struct lpfc_hba *); | |
68 | static int lpfc_init_active_sgl_array(struct lpfc_hba *); | |
69 | static void lpfc_free_active_sgl(struct lpfc_hba *); | |
70 | static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); | |
71 | static int lpfc_hba_down_post_s4(struct lpfc_hba *phba); | |
72 | static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *); | |
73 | static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *); | |
74 | static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *); | |
dea3101e | 75 | |
76 | static struct scsi_transport_template *lpfc_transport_template = NULL; | |
92d7f7b0 | 77 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
dea3101e | 78 | static DEFINE_IDR(lpfc_hba_index); |
79 | ||
e59058c4 | 80 | /** |
3621a710 | 81 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
e59058c4 JS |
82 | * @phba: pointer to lpfc hba data structure. |
83 | * | |
84 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT | |
85 | * mailbox command. It retrieves the revision information from the HBA and | |
86 | * collects the Vital Product Data (VPD) about the HBA for preparing the | |
87 | * configuration of the HBA. | |
88 | * | |
89 | * Return codes: | |
90 | * 0 - success. | |
91 | * -ERESTART - requests the SLI layer to reset the HBA and try again. | |
92 | * Any other value - indicates an error. | |
93 | **/ | |
dea3101e | 94 | int |
2e0fef85 | 95 | lpfc_config_port_prep(struct lpfc_hba *phba) |
dea3101e | 96 | { |
97 | lpfc_vpd_t *vp = &phba->vpd; | |
98 | int i = 0, rc; | |
99 | LPFC_MBOXQ_t *pmb; | |
100 | MAILBOX_t *mb; | |
101 | char *lpfc_vpd_data = NULL; | |
102 | uint16_t offset = 0; | |
103 | static char licensed[56] = | |
104 | "key unlock for use with gnu public licensed code only\0"; | |
65a29c16 | 105 | static int init_key = 1; |
dea3101e | 106 | |
107 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
108 | if (!pmb) { | |
2e0fef85 | 109 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 110 | return -ENOMEM; |
111 | } | |
112 | ||
04c68496 | 113 | mb = &pmb->u.mb; |
2e0fef85 | 114 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e | 115 | |
116 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { | |
65a29c16 JS |
117 | if (init_key) { |
118 | uint32_t *ptext = (uint32_t *) licensed; | |
dea3101e | 119 | |
65a29c16 JS |
120 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
121 | *ptext = cpu_to_be32(*ptext); | |
122 | init_key = 0; | |
123 | } | |
dea3101e | 124 | |
125 | lpfc_read_nv(phba, pmb); | |
126 | memset((char*)mb->un.varRDnvp.rsvd3, 0, | |
127 | sizeof (mb->un.varRDnvp.rsvd3)); | |
128 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, | |
129 | sizeof (licensed)); | |
130 | ||
131 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
132 | ||
133 | if (rc != MBX_SUCCESS) { | |
ed957684 | 134 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
e8b62011 | 135 | "0324 Config Port initialization " |
dea3101e | 136 | "error, mbxCmd x%x READ_NVPARM, " |
137 | "mbxStatus x%x\n", | |
dea3101e | 138 | mb->mbxCommand, mb->mbxStatus); |
139 | mempool_free(pmb, phba->mbox_mem_pool); | |
140 | return -ERESTART; | |
141 | } | |
142 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, | |
2e0fef85 JS |
143 | sizeof(phba->wwnn)); |
144 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, | |
145 | sizeof(phba->wwpn)); | |
dea3101e | 146 | } |
147 | ||
92d7f7b0 JS |
148 | phba->sli3_options = 0x0; |
149 | ||
dea3101e | 150 | /* Setup and issue mailbox READ REV command */ |
151 | lpfc_read_rev(phba, pmb); | |
152 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
153 | if (rc != MBX_SUCCESS) { | |
ed957684 | 154 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 155 | "0439 Adapter failed to init, mbxCmd x%x " |
dea3101e | 156 | "READ_REV, mbxStatus x%x\n", |
dea3101e | 157 | mb->mbxCommand, mb->mbxStatus); |
158 | mempool_free( pmb, phba->mbox_mem_pool); | |
159 | return -ERESTART; | |
160 | } | |
161 | ||
92d7f7b0 | 162 | |
1de933f3 JSEC |
163 | /* |
164 | * The value of rr must be 1 since the driver set the cv field to 1. | |
165 | * This setting requires the FW to set all revision fields. | |
dea3101e | 166 | */ |
1de933f3 | 167 | if (mb->un.varRdRev.rr == 0) { |
dea3101e | 168 | vp->rev.rBit = 0; |
1de933f3 | 169 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 JS |
170 | "0440 Adapter failed to init, READ_REV has " |
171 | "missing revision information.\n"); | |
dea3101e | 172 | mempool_free(pmb, phba->mbox_mem_pool); |
173 | return -ERESTART; | |
dea3101e | 174 | } |
175 | ||
495a714c JS |
176 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
177 | mempool_free(pmb, phba->mbox_mem_pool); | |
ed957684 | 178 | return -EINVAL; |
495a714c | 179 | } |
ed957684 | 180 | |
dea3101e | 181 | /* Save information as VPD data */ |
1de933f3 | 182 | vp->rev.rBit = 1; |
92d7f7b0 | 183 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
1de933f3 JSEC |
184 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
185 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); | |
186 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; | |
187 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); | |
dea3101e | 188 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
189 | vp->rev.smRev = mb->un.varRdRev.smRev; | |
190 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; | |
191 | vp->rev.endecRev = mb->un.varRdRev.endecRev; | |
192 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; | |
193 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; | |
194 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; | |
195 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; | |
196 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; | |
197 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; | |
198 | ||
92d7f7b0 JS |
199 | /* If the sli feature level is less then 9, we must |
200 | * tear down all RPIs and VPIs on link down if NPIV | |
201 | * is enabled. | |
202 | */ | |
203 | if (vp->rev.feaLevelHigh < 9) | |
204 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; | |
205 | ||
dea3101e | 206 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
207 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], | |
208 | sizeof (phba->RandomData)); | |
209 | ||
dea3101e | 210 | /* Get adapter VPD information */ |
dea3101e | 211 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
212 | if (!lpfc_vpd_data) | |
d7c255b2 | 213 | goto out_free_mbox; |
dea3101e | 214 | do { |
a0c87cbd | 215 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
dea3101e | 216 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
217 | ||
218 | if (rc != MBX_SUCCESS) { | |
219 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 | 220 | "0441 VPD not present on adapter, " |
dea3101e | 221 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
dea3101e | 222 | mb->mbxCommand, mb->mbxStatus); |
74b72a59 | 223 | mb->un.varDmp.word_cnt = 0; |
dea3101e | 224 | } |
04c68496 JS |
225 | /* dump mem may return a zero when finished or we got a |
226 | * mailbox error, either way we are done. | |
227 | */ | |
228 | if (mb->un.varDmp.word_cnt == 0) | |
229 | break; | |
74b72a59 JW |
230 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
231 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; | |
d7c255b2 JS |
232 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
233 | lpfc_vpd_data + offset, | |
92d7f7b0 | 234 | mb->un.varDmp.word_cnt); |
dea3101e | 235 | offset += mb->un.varDmp.word_cnt; |
74b72a59 JW |
236 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
237 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); | |
dea3101e | 238 | |
239 | kfree(lpfc_vpd_data); | |
dea3101e | 240 | out_free_mbox: |
241 | mempool_free(pmb, phba->mbox_mem_pool); | |
242 | return 0; | |
243 | } | |
244 | ||
e59058c4 | 245 | /** |
3621a710 | 246 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
e59058c4 JS |
247 | * @phba: pointer to lpfc hba data structure. |
248 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
249 | * | |
250 | * This is the completion handler for driver's configuring asynchronous event | |
251 | * mailbox command to the device. If the mailbox command returns successfully, | |
252 | * it will set internal async event support flag to 1; otherwise, it will | |
253 | * set internal async event support flag to 0. | |
254 | **/ | |
57127f15 JS |
255 | static void |
256 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
257 | { | |
04c68496 | 258 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
57127f15 JS |
259 | phba->temp_sensor_support = 1; |
260 | else | |
261 | phba->temp_sensor_support = 0; | |
262 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
263 | return; | |
264 | } | |
265 | ||
97207482 | 266 | /** |
3621a710 | 267 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
97207482 JS |
268 | * @phba: pointer to lpfc hba data structure. |
269 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
270 | * | |
271 | * This is the completion handler for dump mailbox command for getting | |
272 | * wake up parameters. When this command complete, the response contain | |
273 | * Option rom version of the HBA. This function translate the version number | |
274 | * into a human readable string and store it in OptionROMVersion. | |
275 | **/ | |
276 | static void | |
277 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) | |
278 | { | |
279 | struct prog_id *prg; | |
280 | uint32_t prog_id_word; | |
281 | char dist = ' '; | |
282 | /* character array used for decoding dist type. */ | |
283 | char dist_char[] = "nabx"; | |
284 | ||
04c68496 | 285 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
9f1e1b50 | 286 | mempool_free(pmboxq, phba->mbox_mem_pool); |
97207482 | 287 | return; |
9f1e1b50 | 288 | } |
97207482 JS |
289 | |
290 | prg = (struct prog_id *) &prog_id_word; | |
291 | ||
292 | /* word 7 contain option rom version */ | |
04c68496 | 293 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
97207482 JS |
294 | |
295 | /* Decode the Option rom version word to a readable string */ | |
296 | if (prg->dist < 4) | |
297 | dist = dist_char[prg->dist]; | |
298 | ||
299 | if ((prg->dist == 3) && (prg->num == 0)) | |
300 | sprintf(phba->OptionROMVersion, "%d.%d%d", | |
301 | prg->ver, prg->rev, prg->lev); | |
302 | else | |
303 | sprintf(phba->OptionROMVersion, "%d.%d%d%c%d", | |
304 | prg->ver, prg->rev, prg->lev, | |
305 | dist, prg->num); | |
9f1e1b50 | 306 | mempool_free(pmboxq, phba->mbox_mem_pool); |
97207482 JS |
307 | return; |
308 | } | |
309 | ||
0558056c JS |
310 | /** |
311 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, | |
312 | * cfg_soft_wwnn, cfg_soft_wwpn | |
313 | * @vport: pointer to lpfc vport data structure. | |
314 | * | |
315 | * | |
316 | * Return codes | |
317 | * None. | |
318 | **/ | |
319 | void | |
320 | lpfc_update_vport_wwn(struct lpfc_vport *vport) | |
321 | { | |
322 | /* If the soft name exists then update it using the service params */ | |
323 | if (vport->phba->cfg_soft_wwnn) | |
324 | u64_to_wwn(vport->phba->cfg_soft_wwnn, | |
325 | vport->fc_sparam.nodeName.u.wwn); | |
326 | if (vport->phba->cfg_soft_wwpn) | |
327 | u64_to_wwn(vport->phba->cfg_soft_wwpn, | |
328 | vport->fc_sparam.portName.u.wwn); | |
329 | ||
330 | /* | |
331 | * If the name is empty or there exists a soft name | |
332 | * then copy the service params name, otherwise use the fc name | |
333 | */ | |
334 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) | |
335 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, | |
336 | sizeof(struct lpfc_name)); | |
337 | else | |
338 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, | |
339 | sizeof(struct lpfc_name)); | |
340 | ||
341 | if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn) | |
342 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, | |
343 | sizeof(struct lpfc_name)); | |
344 | else | |
345 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, | |
346 | sizeof(struct lpfc_name)); | |
347 | } | |
348 | ||
e59058c4 | 349 | /** |
3621a710 | 350 | * lpfc_config_port_post - Perform lpfc initialization after config port |
e59058c4 JS |
351 | * @phba: pointer to lpfc hba data structure. |
352 | * | |
353 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox | |
354 | * command call. It performs all internal resource and state setups on the | |
355 | * port: post IOCB buffers, enable appropriate host interrupt attentions, | |
356 | * ELS ring timers, etc. | |
357 | * | |
358 | * Return codes | |
359 | * 0 - success. | |
360 | * Any other value - error. | |
361 | **/ | |
dea3101e | 362 | int |
2e0fef85 | 363 | lpfc_config_port_post(struct lpfc_hba *phba) |
dea3101e | 364 | { |
2e0fef85 | 365 | struct lpfc_vport *vport = phba->pport; |
a257bf90 | 366 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 367 | LPFC_MBOXQ_t *pmb; |
368 | MAILBOX_t *mb; | |
369 | struct lpfc_dmabuf *mp; | |
370 | struct lpfc_sli *psli = &phba->sli; | |
371 | uint32_t status, timeout; | |
2e0fef85 JS |
372 | int i, j; |
373 | int rc; | |
dea3101e | 374 | |
7af67051 JS |
375 | spin_lock_irq(&phba->hbalock); |
376 | /* | |
377 | * If the Config port completed correctly the HBA is not | |
378 | * over heated any more. | |
379 | */ | |
380 | if (phba->over_temp_state == HBA_OVER_TEMP) | |
381 | phba->over_temp_state = HBA_NORMAL_TEMP; | |
382 | spin_unlock_irq(&phba->hbalock); | |
383 | ||
dea3101e | 384 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
385 | if (!pmb) { | |
2e0fef85 | 386 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 387 | return -ENOMEM; |
388 | } | |
04c68496 | 389 | mb = &pmb->u.mb; |
dea3101e | 390 | |
dea3101e | 391 | /* Get login parameters for NID. */ |
9f1177a3 JS |
392 | rc = lpfc_read_sparam(phba, pmb, 0); |
393 | if (rc) { | |
394 | mempool_free(pmb, phba->mbox_mem_pool); | |
395 | return -ENOMEM; | |
396 | } | |
397 | ||
ed957684 | 398 | pmb->vport = vport; |
dea3101e | 399 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 400 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 401 | "0448 Adapter failed init, mbxCmd x%x " |
dea3101e | 402 | "READ_SPARM mbxStatus x%x\n", |
dea3101e | 403 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 404 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 405 | mp = (struct lpfc_dmabuf *) pmb->context1; |
9f1177a3 | 406 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e | 407 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
408 | kfree(mp); | |
409 | return -EIO; | |
410 | } | |
411 | ||
412 | mp = (struct lpfc_dmabuf *) pmb->context1; | |
413 | ||
2e0fef85 | 414 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
dea3101e | 415 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
416 | kfree(mp); | |
417 | pmb->context1 = NULL; | |
0558056c | 418 | lpfc_update_vport_wwn(vport); |
a257bf90 JS |
419 | |
420 | /* Update the fc_host data structures with new wwn. */ | |
421 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
422 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
21e9a0a5 | 423 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
a257bf90 | 424 | |
dea3101e | 425 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
426 | /* This should be consolidated into parse_vpd ? - mr */ | |
427 | if (phba->SerialNumber[0] == 0) { | |
428 | uint8_t *outptr; | |
429 | ||
2e0fef85 | 430 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
dea3101e | 431 | for (i = 0; i < 12; i++) { |
432 | status = *outptr++; | |
433 | j = ((status & 0xf0) >> 4); | |
434 | if (j <= 9) | |
435 | phba->SerialNumber[i] = | |
436 | (char)((uint8_t) 0x30 + (uint8_t) j); | |
437 | else | |
438 | phba->SerialNumber[i] = | |
439 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | |
440 | i++; | |
441 | j = (status & 0xf); | |
442 | if (j <= 9) | |
443 | phba->SerialNumber[i] = | |
444 | (char)((uint8_t) 0x30 + (uint8_t) j); | |
445 | else | |
446 | phba->SerialNumber[i] = | |
447 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | |
448 | } | |
449 | } | |
450 | ||
dea3101e | 451 | lpfc_read_config(phba, pmb); |
ed957684 | 452 | pmb->vport = vport; |
dea3101e | 453 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 454 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 455 | "0453 Adapter failed to init, mbxCmd x%x " |
dea3101e | 456 | "READ_CONFIG, mbxStatus x%x\n", |
dea3101e | 457 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 458 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 459 | mempool_free( pmb, phba->mbox_mem_pool); |
460 | return -EIO; | |
461 | } | |
462 | ||
a0c87cbd JS |
463 | /* Check if the port is disabled */ |
464 | lpfc_sli_read_link_ste(phba); | |
465 | ||
dea3101e | 466 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
467 | if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1)) | |
468 | phba->cfg_hba_queue_depth = | |
f1126688 JS |
469 | (mb->un.varRdConfig.max_xri + 1) - |
470 | lpfc_sli4_get_els_iocb_cnt(phba); | |
dea3101e | 471 | |
472 | phba->lmt = mb->un.varRdConfig.lmt; | |
74b72a59 JW |
473 | |
474 | /* Get the default values for Model Name and Description */ | |
475 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
476 | ||
2e0fef85 | 477 | phba->link_state = LPFC_LINK_DOWN; |
dea3101e | 478 | |
0b727fea | 479 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
a4bc3379 JS |
480 | if (psli->ring[psli->extra_ring].cmdringaddr) |
481 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; | |
dea3101e | 482 | if (psli->ring[psli->fcp_ring].cmdringaddr) |
483 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; | |
484 | if (psli->ring[psli->next_ring].cmdringaddr) | |
485 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; | |
486 | ||
487 | /* Post receive buffers for desired rings */ | |
ed957684 JS |
488 | if (phba->sli_rev != 3) |
489 | lpfc_post_rcv_buf(phba); | |
dea3101e | 490 | |
9399627f JS |
491 | /* |
492 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode | |
493 | */ | |
494 | if (phba->intr_type == MSIX) { | |
495 | rc = lpfc_config_msi(phba, pmb); | |
496 | if (rc) { | |
497 | mempool_free(pmb, phba->mbox_mem_pool); | |
498 | return -EIO; | |
499 | } | |
500 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
501 | if (rc != MBX_SUCCESS) { | |
502 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
503 | "0352 Config MSI mailbox command " | |
504 | "failed, mbxCmd x%x, mbxStatus x%x\n", | |
04c68496 JS |
505 | pmb->u.mb.mbxCommand, |
506 | pmb->u.mb.mbxStatus); | |
9399627f JS |
507 | mempool_free(pmb, phba->mbox_mem_pool); |
508 | return -EIO; | |
509 | } | |
510 | } | |
511 | ||
04c68496 | 512 | spin_lock_irq(&phba->hbalock); |
9399627f JS |
513 | /* Initialize ERATT handling flag */ |
514 | phba->hba_flag &= ~HBA_ERATT_HANDLED; | |
515 | ||
dea3101e | 516 | /* Enable appropriate host interrupts */ |
9940b97b JS |
517 | if (lpfc_readl(phba->HCregaddr, &status)) { |
518 | spin_unlock_irq(&phba->hbalock); | |
519 | return -EIO; | |
520 | } | |
dea3101e | 521 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
522 | if (psli->num_rings > 0) | |
523 | status |= HC_R0INT_ENA; | |
524 | if (psli->num_rings > 1) | |
525 | status |= HC_R1INT_ENA; | |
526 | if (psli->num_rings > 2) | |
527 | status |= HC_R2INT_ENA; | |
528 | if (psli->num_rings > 3) | |
529 | status |= HC_R3INT_ENA; | |
530 | ||
875fbdfe JSEC |
531 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
532 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) | |
9399627f | 533 | status &= ~(HC_R0INT_ENA); |
875fbdfe | 534 | |
dea3101e | 535 | writel(status, phba->HCregaddr); |
536 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 537 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 538 | |
9399627f JS |
539 | /* Set up ring-0 (ELS) timer */ |
540 | timeout = phba->fc_ratov * 2; | |
2e0fef85 | 541 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
9399627f | 542 | /* Set up heart beat (HB) timer */ |
858c9f6c JS |
543 | mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
544 | phba->hb_outstanding = 0; | |
545 | phba->last_completion_time = jiffies; | |
9399627f JS |
546 | /* Set up error attention (ERATT) polling timer */ |
547 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); | |
dea3101e | 548 | |
a0c87cbd JS |
549 | if (phba->hba_flag & LINK_DISABLED) { |
550 | lpfc_printf_log(phba, | |
551 | KERN_ERR, LOG_INIT, | |
552 | "2598 Adapter Link is disabled.\n"); | |
553 | lpfc_down_link(phba, pmb); | |
554 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
555 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
556 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { | |
557 | lpfc_printf_log(phba, | |
558 | KERN_ERR, LOG_INIT, | |
559 | "2599 Adapter failed to issue DOWN_LINK" | |
560 | " mbox command rc 0x%x\n", rc); | |
561 | ||
562 | mempool_free(pmb, phba->mbox_mem_pool); | |
563 | return -EIO; | |
564 | } | |
e40a02c1 | 565 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
026abb87 JS |
566 | mempool_free(pmb, phba->mbox_mem_pool); |
567 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); | |
568 | if (rc) | |
569 | return rc; | |
dea3101e | 570 | } |
571 | /* MBOX buffer will be freed in mbox compl */ | |
57127f15 | 572 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
9f1177a3 JS |
573 | if (!pmb) { |
574 | phba->link_state = LPFC_HBA_ERROR; | |
575 | return -ENOMEM; | |
576 | } | |
577 | ||
57127f15 JS |
578 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
579 | pmb->mbox_cmpl = lpfc_config_async_cmpl; | |
580 | pmb->vport = phba->pport; | |
581 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
dea3101e | 582 | |
57127f15 JS |
583 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
584 | lpfc_printf_log(phba, | |
585 | KERN_ERR, | |
586 | LOG_INIT, | |
587 | "0456 Adapter failed to issue " | |
e4e74273 | 588 | "ASYNCEVT_ENABLE mbox status x%x\n", |
57127f15 JS |
589 | rc); |
590 | mempool_free(pmb, phba->mbox_mem_pool); | |
591 | } | |
97207482 JS |
592 | |
593 | /* Get Option rom version */ | |
594 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
9f1177a3 JS |
595 | if (!pmb) { |
596 | phba->link_state = LPFC_HBA_ERROR; | |
597 | return -ENOMEM; | |
598 | } | |
599 | ||
97207482 JS |
600 | lpfc_dump_wakeup_param(phba, pmb); |
601 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; | |
602 | pmb->vport = phba->pport; | |
603 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
604 | ||
605 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { | |
606 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " | |
e4e74273 | 607 | "to get Option ROM version status x%x\n", rc); |
97207482 JS |
608 | mempool_free(pmb, phba->mbox_mem_pool); |
609 | } | |
610 | ||
d7c255b2 | 611 | return 0; |
ce8b3ce5 JS |
612 | } |
613 | ||
84d1b006 JS |
614 | /** |
615 | * lpfc_hba_init_link - Initialize the FC link | |
616 | * @phba: pointer to lpfc hba data structure. | |
6e7288d9 | 617 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
84d1b006 JS |
618 | * |
619 | * This routine will issue the INIT_LINK mailbox command call. | |
620 | * It is available to other drivers through the lpfc_hba data | |
621 | * structure for use as a delayed link up mechanism with the | |
622 | * module parameter lpfc_suppress_link_up. | |
623 | * | |
624 | * Return code | |
625 | * 0 - success | |
626 | * Any other value - error | |
627 | **/ | |
628 | int | |
6e7288d9 | 629 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
84d1b006 JS |
630 | { |
631 | struct lpfc_vport *vport = phba->pport; | |
632 | LPFC_MBOXQ_t *pmb; | |
633 | MAILBOX_t *mb; | |
634 | int rc; | |
635 | ||
636 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
637 | if (!pmb) { | |
638 | phba->link_state = LPFC_HBA_ERROR; | |
639 | return -ENOMEM; | |
640 | } | |
641 | mb = &pmb->u.mb; | |
642 | pmb->vport = vport; | |
643 | ||
026abb87 JS |
644 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
645 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && | |
646 | !(phba->lmt & LMT_1Gb)) || | |
647 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && | |
648 | !(phba->lmt & LMT_2Gb)) || | |
649 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && | |
650 | !(phba->lmt & LMT_4Gb)) || | |
651 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && | |
652 | !(phba->lmt & LMT_8Gb)) || | |
653 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && | |
654 | !(phba->lmt & LMT_10Gb)) || | |
655 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && | |
656 | !(phba->lmt & LMT_16Gb))) { | |
657 | /* Reset link speed to auto */ | |
658 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, | |
659 | "1302 Invalid speed for this board:%d " | |
660 | "Reset link speed to auto.\n", | |
661 | phba->cfg_link_speed); | |
662 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; | |
663 | } | |
76a95d75 | 664 | lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed); |
84d1b006 JS |
665 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
666 | lpfc_set_loopback_flag(phba); | |
6e7288d9 | 667 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
76a95d75 | 668 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
84d1b006 JS |
669 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
670 | "0498 Adapter failed to init, mbxCmd x%x " | |
671 | "INIT_LINK, mbxStatus x%x\n", | |
672 | mb->mbxCommand, mb->mbxStatus); | |
76a95d75 JS |
673 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
674 | /* Clear all interrupt enable conditions */ | |
675 | writel(0, phba->HCregaddr); | |
676 | readl(phba->HCregaddr); /* flush */ | |
677 | /* Clear all pending interrupts */ | |
678 | writel(0xffffffff, phba->HAregaddr); | |
679 | readl(phba->HAregaddr); /* flush */ | |
680 | } | |
84d1b006 | 681 | phba->link_state = LPFC_HBA_ERROR; |
6e7288d9 | 682 | if (rc != MBX_BUSY || flag == MBX_POLL) |
84d1b006 JS |
683 | mempool_free(pmb, phba->mbox_mem_pool); |
684 | return -EIO; | |
685 | } | |
e40a02c1 | 686 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
6e7288d9 JS |
687 | if (flag == MBX_POLL) |
688 | mempool_free(pmb, phba->mbox_mem_pool); | |
84d1b006 JS |
689 | |
690 | return 0; | |
691 | } | |
692 | ||
693 | /** | |
694 | * lpfc_hba_down_link - this routine downs the FC link | |
6e7288d9 JS |
695 | * @phba: pointer to lpfc hba data structure. |
696 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT | |
84d1b006 JS |
697 | * |
698 | * This routine will issue the DOWN_LINK mailbox command call. | |
699 | * It is available to other drivers through the lpfc_hba data | |
700 | * structure for use to stop the link. | |
701 | * | |
702 | * Return code | |
703 | * 0 - success | |
704 | * Any other value - error | |
705 | **/ | |
706 | int | |
6e7288d9 | 707 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
84d1b006 JS |
708 | { |
709 | LPFC_MBOXQ_t *pmb; | |
710 | int rc; | |
711 | ||
712 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
713 | if (!pmb) { | |
714 | phba->link_state = LPFC_HBA_ERROR; | |
715 | return -ENOMEM; | |
716 | } | |
717 | ||
718 | lpfc_printf_log(phba, | |
719 | KERN_ERR, LOG_INIT, | |
720 | "0491 Adapter Link is disabled.\n"); | |
721 | lpfc_down_link(phba, pmb); | |
722 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
6e7288d9 | 723 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
84d1b006 JS |
724 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
725 | lpfc_printf_log(phba, | |
726 | KERN_ERR, LOG_INIT, | |
727 | "2522 Adapter failed to issue DOWN_LINK" | |
728 | " mbox command rc 0x%x\n", rc); | |
729 | ||
730 | mempool_free(pmb, phba->mbox_mem_pool); | |
731 | return -EIO; | |
732 | } | |
6e7288d9 JS |
733 | if (flag == MBX_POLL) |
734 | mempool_free(pmb, phba->mbox_mem_pool); | |
735 | ||
84d1b006 JS |
736 | return 0; |
737 | } | |
738 | ||
e59058c4 | 739 | /** |
3621a710 | 740 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
e59058c4 JS |
741 | * @phba: pointer to lpfc HBA data structure. |
742 | * | |
743 | * This routine will do LPFC uninitialization before the HBA is reset when | |
744 | * bringing down the SLI Layer. | |
745 | * | |
746 | * Return codes | |
747 | * 0 - success. | |
748 | * Any other value - error. | |
749 | **/ | |
dea3101e | 750 | int |
2e0fef85 | 751 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
dea3101e | 752 | { |
1b32f6aa JS |
753 | struct lpfc_vport **vports; |
754 | int i; | |
3772a991 JS |
755 | |
756 | if (phba->sli_rev <= LPFC_SLI_REV3) { | |
757 | /* Disable interrupts */ | |
758 | writel(0, phba->HCregaddr); | |
759 | readl(phba->HCregaddr); /* flush */ | |
760 | } | |
dea3101e | 761 | |
1b32f6aa JS |
762 | if (phba->pport->load_flag & FC_UNLOADING) |
763 | lpfc_cleanup_discovery_resources(phba->pport); | |
764 | else { | |
765 | vports = lpfc_create_vport_work_array(phba); | |
766 | if (vports != NULL) | |
3772a991 JS |
767 | for (i = 0; i <= phba->max_vports && |
768 | vports[i] != NULL; i++) | |
1b32f6aa JS |
769 | lpfc_cleanup_discovery_resources(vports[i]); |
770 | lpfc_destroy_vport_work_array(phba, vports); | |
7f5f3d0d JS |
771 | } |
772 | return 0; | |
dea3101e | 773 | } |
774 | ||
e59058c4 | 775 | /** |
3772a991 | 776 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
e59058c4 JS |
777 | * @phba: pointer to lpfc HBA data structure. |
778 | * | |
779 | * This routine will do uninitialization after the HBA is reset when bring | |
780 | * down the SLI Layer. | |
781 | * | |
782 | * Return codes | |
af901ca1 | 783 | * 0 - success. |
e59058c4 JS |
784 | * Any other value - error. |
785 | **/ | |
3772a991 JS |
786 | static int |
787 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) | |
41415862 JW |
788 | { |
789 | struct lpfc_sli *psli = &phba->sli; | |
790 | struct lpfc_sli_ring *pring; | |
791 | struct lpfc_dmabuf *mp, *next_mp; | |
09372820 | 792 | LIST_HEAD(completions); |
41415862 JW |
793 | int i; |
794 | ||
92d7f7b0 JS |
795 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
796 | lpfc_sli_hbqbuf_free_all(phba); | |
797 | else { | |
798 | /* Cleanup preposted buffers on the ELS ring */ | |
799 | pring = &psli->ring[LPFC_ELS_RING]; | |
800 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
801 | list_del(&mp->list); | |
802 | pring->postbufq_cnt--; | |
803 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
804 | kfree(mp); | |
805 | } | |
41415862 JW |
806 | } |
807 | ||
09372820 | 808 | spin_lock_irq(&phba->hbalock); |
41415862 JW |
809 | for (i = 0; i < psli->num_rings; i++) { |
810 | pring = &psli->ring[i]; | |
09372820 JS |
811 | |
812 | /* At this point in time the HBA is either reset or DOA. Either | |
813 | * way, nothing should be on txcmplq as it will NEVER complete. | |
814 | */ | |
815 | list_splice_init(&pring->txcmplq, &completions); | |
816 | pring->txcmplq_cnt = 0; | |
817 | spin_unlock_irq(&phba->hbalock); | |
818 | ||
a257bf90 JS |
819 | /* Cancel all the IOCBs from the completions list */ |
820 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
821 | IOERR_SLI_ABORTED); | |
09372820 | 822 | |
41415862 | 823 | lpfc_sli_abort_iocb_ring(phba, pring); |
09372820 | 824 | spin_lock_irq(&phba->hbalock); |
41415862 | 825 | } |
09372820 | 826 | spin_unlock_irq(&phba->hbalock); |
41415862 JW |
827 | |
828 | return 0; | |
829 | } | |
5af5eee7 | 830 | |
da0436e9 JS |
831 | /** |
832 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset | |
833 | * @phba: pointer to lpfc HBA data structure. | |
834 | * | |
835 | * This routine will do uninitialization after the HBA is reset when bring | |
836 | * down the SLI Layer. | |
837 | * | |
838 | * Return codes | |
af901ca1 | 839 | * 0 - success. |
da0436e9 JS |
840 | * Any other value - error. |
841 | **/ | |
842 | static int | |
843 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) | |
844 | { | |
845 | struct lpfc_scsi_buf *psb, *psb_next; | |
846 | LIST_HEAD(aborts); | |
847 | int ret; | |
848 | unsigned long iflag = 0; | |
0f65ff68 JS |
849 | struct lpfc_sglq *sglq_entry = NULL; |
850 | ||
da0436e9 JS |
851 | ret = lpfc_hba_down_post_s3(phba); |
852 | if (ret) | |
853 | return ret; | |
854 | /* At this point in time the HBA is either reset or DOA. Either | |
855 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be | |
856 | * on the lpfc_sgl_list so that it can either be freed if the | |
857 | * driver is unloading or reposted if the driver is restarting | |
858 | * the port. | |
859 | */ | |
860 | spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */ | |
861 | /* scsl_buf_list */ | |
862 | /* abts_sgl_list_lock required because worker thread uses this | |
863 | * list. | |
864 | */ | |
865 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); | |
0f65ff68 JS |
866 | list_for_each_entry(sglq_entry, |
867 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) | |
868 | sglq_entry->state = SGL_FREED; | |
869 | ||
da0436e9 JS |
870 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
871 | &phba->sli4_hba.lpfc_sgl_list); | |
872 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); | |
873 | /* abts_scsi_buf_list_lock required because worker thread uses this | |
874 | * list. | |
875 | */ | |
876 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
877 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, | |
878 | &aborts); | |
879 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
880 | spin_unlock_irq(&phba->hbalock); | |
881 | ||
882 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { | |
883 | psb->pCmd = NULL; | |
884 | psb->status = IOSTAT_SUCCESS; | |
885 | } | |
886 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); | |
887 | list_splice(&aborts, &phba->lpfc_scsi_buf_list); | |
888 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); | |
889 | return 0; | |
890 | } | |
891 | ||
892 | /** | |
893 | * lpfc_hba_down_post - Wrapper func for hba down post routine | |
894 | * @phba: pointer to lpfc HBA data structure. | |
895 | * | |
896 | * This routine wraps the actual SLI3 or SLI4 routine for performing | |
897 | * uninitialization after the HBA is reset when bring down the SLI Layer. | |
898 | * | |
899 | * Return codes | |
af901ca1 | 900 | * 0 - success. |
da0436e9 JS |
901 | * Any other value - error. |
902 | **/ | |
903 | int | |
904 | lpfc_hba_down_post(struct lpfc_hba *phba) | |
905 | { | |
906 | return (*phba->lpfc_hba_down_post)(phba); | |
907 | } | |
41415862 | 908 | |
e59058c4 | 909 | /** |
3621a710 | 910 | * lpfc_hb_timeout - The HBA-timer timeout handler |
e59058c4 JS |
911 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
912 | * | |
913 | * This is the HBA-timer timeout handler registered to the lpfc driver. When | |
914 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver | |
915 | * work-port-events bitmap and the worker thread is notified. This timeout | |
916 | * event will be used by the worker thread to invoke the actual timeout | |
917 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will | |
918 | * be performed in the timeout handler and the HBA timeout event bit shall | |
919 | * be cleared by the worker thread after it has taken the event bitmap out. | |
920 | **/ | |
a6ababd2 | 921 | static void |
858c9f6c JS |
922 | lpfc_hb_timeout(unsigned long ptr) |
923 | { | |
924 | struct lpfc_hba *phba; | |
5e9d9b82 | 925 | uint32_t tmo_posted; |
858c9f6c JS |
926 | unsigned long iflag; |
927 | ||
928 | phba = (struct lpfc_hba *)ptr; | |
9399627f JS |
929 | |
930 | /* Check for heart beat timeout conditions */ | |
858c9f6c | 931 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
5e9d9b82 JS |
932 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
933 | if (!tmo_posted) | |
858c9f6c JS |
934 | phba->pport->work_port_events |= WORKER_HB_TMO; |
935 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
936 | ||
9399627f | 937 | /* Tell the worker thread there is work to do */ |
5e9d9b82 JS |
938 | if (!tmo_posted) |
939 | lpfc_worker_wake_up(phba); | |
858c9f6c JS |
940 | return; |
941 | } | |
942 | ||
19ca7609 JS |
943 | /** |
944 | * lpfc_rrq_timeout - The RRQ-timer timeout handler | |
945 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. | |
946 | * | |
947 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When | |
948 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver | |
949 | * work-port-events bitmap and the worker thread is notified. This timeout | |
950 | * event will be used by the worker thread to invoke the actual timeout | |
951 | * handler routine, lpfc_rrq_handler. Any periodical operations will | |
952 | * be performed in the timeout handler and the RRQ timeout event bit shall | |
953 | * be cleared by the worker thread after it has taken the event bitmap out. | |
954 | **/ | |
955 | static void | |
956 | lpfc_rrq_timeout(unsigned long ptr) | |
957 | { | |
958 | struct lpfc_hba *phba; | |
19ca7609 JS |
959 | unsigned long iflag; |
960 | ||
961 | phba = (struct lpfc_hba *)ptr; | |
962 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
1151e3ec | 963 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
19ca7609 | 964 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
1151e3ec | 965 | lpfc_worker_wake_up(phba); |
19ca7609 JS |
966 | } |
967 | ||
e59058c4 | 968 | /** |
3621a710 | 969 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
e59058c4 JS |
970 | * @phba: pointer to lpfc hba data structure. |
971 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
972 | * | |
973 | * This is the callback function to the lpfc heart-beat mailbox command. | |
974 | * If configured, the lpfc driver issues the heart-beat mailbox command to | |
975 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the | |
976 | * heart-beat mailbox command is issued, the driver shall set up heart-beat | |
977 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks | |
978 | * heart-beat outstanding state. Once the mailbox command comes back and | |
979 | * no error conditions detected, the heart-beat mailbox command timer is | |
980 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding | |
981 | * state is cleared for the next heart-beat. If the timer expired with the | |
982 | * heart-beat outstanding state set, the driver will put the HBA offline. | |
983 | **/ | |
858c9f6c JS |
984 | static void |
985 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
986 | { | |
987 | unsigned long drvr_flag; | |
988 | ||
989 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
990 | phba->hb_outstanding = 0; | |
991 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
992 | ||
9399627f | 993 | /* Check and reset heart-beat timer is necessary */ |
858c9f6c JS |
994 | mempool_free(pmboxq, phba->mbox_mem_pool); |
995 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && | |
996 | !(phba->link_state == LPFC_HBA_ERROR) && | |
51ef4c26 | 997 | !(phba->pport->load_flag & FC_UNLOADING)) |
858c9f6c JS |
998 | mod_timer(&phba->hb_tmofunc, |
999 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
1000 | return; | |
1001 | } | |
1002 | ||
e59058c4 | 1003 | /** |
3621a710 | 1004 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
e59058c4 JS |
1005 | * @phba: pointer to lpfc hba data structure. |
1006 | * | |
1007 | * This is the actual HBA-timer timeout handler to be invoked by the worker | |
1008 | * thread whenever the HBA timer fired and HBA-timeout event posted. This | |
1009 | * handler performs any periodic operations needed for the device. If such | |
1010 | * periodic event has already been attended to either in the interrupt handler | |
1011 | * or by processing slow-ring or fast-ring events within the HBA-timer | |
1012 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets | |
1013 | * the timer for the next timeout period. If lpfc heart-beat mailbox command | |
1014 | * is configured and there is no heart-beat mailbox command outstanding, a | |
1015 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there | |
1016 | * has been a heart-beat mailbox command outstanding, the HBA shall be put | |
1017 | * to offline. | |
1018 | **/ | |
858c9f6c JS |
1019 | void |
1020 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) | |
1021 | { | |
45ed1190 | 1022 | struct lpfc_vport **vports; |
858c9f6c | 1023 | LPFC_MBOXQ_t *pmboxq; |
0ff10d46 | 1024 | struct lpfc_dmabuf *buf_ptr; |
45ed1190 | 1025 | int retval, i; |
858c9f6c | 1026 | struct lpfc_sli *psli = &phba->sli; |
0ff10d46 | 1027 | LIST_HEAD(completions); |
858c9f6c | 1028 | |
45ed1190 JS |
1029 | vports = lpfc_create_vport_work_array(phba); |
1030 | if (vports != NULL) | |
1031 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) | |
1032 | lpfc_rcv_seq_check_edtov(vports[i]); | |
1033 | lpfc_destroy_vport_work_array(phba, vports); | |
1034 | ||
858c9f6c | 1035 | if ((phba->link_state == LPFC_HBA_ERROR) || |
51ef4c26 | 1036 | (phba->pport->load_flag & FC_UNLOADING) || |
858c9f6c JS |
1037 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
1038 | return; | |
1039 | ||
1040 | spin_lock_irq(&phba->pport->work_port_lock); | |
858c9f6c JS |
1041 | |
1042 | if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, | |
1043 | jiffies)) { | |
1044 | spin_unlock_irq(&phba->pport->work_port_lock); | |
1045 | if (!phba->hb_outstanding) | |
1046 | mod_timer(&phba->hb_tmofunc, | |
1047 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
1048 | else | |
1049 | mod_timer(&phba->hb_tmofunc, | |
1050 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | |
1051 | return; | |
1052 | } | |
1053 | spin_unlock_irq(&phba->pport->work_port_lock); | |
1054 | ||
0ff10d46 JS |
1055 | if (phba->elsbuf_cnt && |
1056 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { | |
1057 | spin_lock_irq(&phba->hbalock); | |
1058 | list_splice_init(&phba->elsbuf, &completions); | |
1059 | phba->elsbuf_cnt = 0; | |
1060 | phba->elsbuf_prev_cnt = 0; | |
1061 | spin_unlock_irq(&phba->hbalock); | |
1062 | ||
1063 | while (!list_empty(&completions)) { | |
1064 | list_remove_head(&completions, buf_ptr, | |
1065 | struct lpfc_dmabuf, list); | |
1066 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
1067 | kfree(buf_ptr); | |
1068 | } | |
1069 | } | |
1070 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; | |
1071 | ||
858c9f6c | 1072 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
13815c83 JS |
1073 | if (phba->cfg_enable_hba_heartbeat) { |
1074 | if (!phba->hb_outstanding) { | |
bc73905a JS |
1075 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
1076 | (list_empty(&psli->mboxq))) { | |
1077 | pmboxq = mempool_alloc(phba->mbox_mem_pool, | |
1078 | GFP_KERNEL); | |
1079 | if (!pmboxq) { | |
1080 | mod_timer(&phba->hb_tmofunc, | |
1081 | jiffies + | |
1082 | HZ * LPFC_HB_MBOX_INTERVAL); | |
1083 | return; | |
1084 | } | |
1085 | ||
1086 | lpfc_heart_beat(phba, pmboxq); | |
1087 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; | |
1088 | pmboxq->vport = phba->pport; | |
1089 | retval = lpfc_sli_issue_mbox(phba, pmboxq, | |
1090 | MBX_NOWAIT); | |
1091 | ||
1092 | if (retval != MBX_BUSY && | |
1093 | retval != MBX_SUCCESS) { | |
1094 | mempool_free(pmboxq, | |
1095 | phba->mbox_mem_pool); | |
1096 | mod_timer(&phba->hb_tmofunc, | |
1097 | jiffies + | |
1098 | HZ * LPFC_HB_MBOX_INTERVAL); | |
1099 | return; | |
1100 | } | |
1101 | phba->skipped_hb = 0; | |
1102 | phba->hb_outstanding = 1; | |
1103 | } else if (time_before_eq(phba->last_completion_time, | |
1104 | phba->skipped_hb)) { | |
1105 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
1106 | "2857 Last completion time not " | |
1107 | " updated in %d ms\n", | |
1108 | jiffies_to_msecs(jiffies | |
1109 | - phba->last_completion_time)); | |
1110 | } else | |
1111 | phba->skipped_hb = jiffies; | |
1112 | ||
858c9f6c | 1113 | mod_timer(&phba->hb_tmofunc, |
13815c83 | 1114 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
858c9f6c | 1115 | return; |
13815c83 JS |
1116 | } else { |
1117 | /* | |
1118 | * If heart beat timeout called with hb_outstanding set | |
dcf2a4e0 JS |
1119 | * we need to give the hb mailbox cmd a chance to |
1120 | * complete or TMO. | |
13815c83 | 1121 | */ |
dcf2a4e0 JS |
1122 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
1123 | "0459 Adapter heartbeat still out" | |
1124 | "standing:last compl time was %d ms.\n", | |
1125 | jiffies_to_msecs(jiffies | |
1126 | - phba->last_completion_time)); | |
1127 | mod_timer(&phba->hb_tmofunc, | |
1128 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | |
858c9f6c | 1129 | } |
858c9f6c JS |
1130 | } |
1131 | } | |
1132 | ||
e59058c4 | 1133 | /** |
3621a710 | 1134 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
e59058c4 JS |
1135 | * @phba: pointer to lpfc hba data structure. |
1136 | * | |
1137 | * This routine is called to bring the HBA offline when HBA hardware error | |
1138 | * other than Port Error 6 has been detected. | |
1139 | **/ | |
09372820 JS |
1140 | static void |
1141 | lpfc_offline_eratt(struct lpfc_hba *phba) | |
1142 | { | |
1143 | struct lpfc_sli *psli = &phba->sli; | |
1144 | ||
1145 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1146 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
09372820 JS |
1147 | spin_unlock_irq(&phba->hbalock); |
1148 | lpfc_offline_prep(phba); | |
1149 | ||
1150 | lpfc_offline(phba); | |
1151 | lpfc_reset_barrier(phba); | |
f4b4c68f | 1152 | spin_lock_irq(&phba->hbalock); |
09372820 | 1153 | lpfc_sli_brdreset(phba); |
f4b4c68f | 1154 | spin_unlock_irq(&phba->hbalock); |
09372820 JS |
1155 | lpfc_hba_down_post(phba); |
1156 | lpfc_sli_brdready(phba, HS_MBRDY); | |
1157 | lpfc_unblock_mgmt_io(phba); | |
1158 | phba->link_state = LPFC_HBA_ERROR; | |
1159 | return; | |
1160 | } | |
1161 | ||
da0436e9 JS |
1162 | /** |
1163 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention | |
1164 | * @phba: pointer to lpfc hba data structure. | |
1165 | * | |
1166 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error | |
1167 | * other than Port Error 6 has been detected. | |
1168 | **/ | |
1169 | static void | |
1170 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) | |
1171 | { | |
1172 | lpfc_offline_prep(phba); | |
1173 | lpfc_offline(phba); | |
1174 | lpfc_sli4_brdreset(phba); | |
1175 | lpfc_hba_down_post(phba); | |
1176 | lpfc_sli4_post_status_check(phba); | |
1177 | lpfc_unblock_mgmt_io(phba); | |
1178 | phba->link_state = LPFC_HBA_ERROR; | |
1179 | } | |
1180 | ||
a257bf90 JS |
1181 | /** |
1182 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler | |
1183 | * @phba: pointer to lpfc hba data structure. | |
1184 | * | |
1185 | * This routine is invoked to handle the deferred HBA hardware error | |
1186 | * conditions. This type of error is indicated by HBA by setting ER1 | |
1187 | * and another ER bit in the host status register. The driver will | |
1188 | * wait until the ER1 bit clears before handling the error condition. | |
1189 | **/ | |
1190 | static void | |
1191 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) | |
1192 | { | |
1193 | uint32_t old_host_status = phba->work_hs; | |
1194 | struct lpfc_sli_ring *pring; | |
1195 | struct lpfc_sli *psli = &phba->sli; | |
1196 | ||
f4b4c68f JS |
1197 | /* If the pci channel is offline, ignore possible errors, |
1198 | * since we cannot communicate with the pci card anyway. | |
1199 | */ | |
1200 | if (pci_channel_offline(phba->pcidev)) { | |
1201 | spin_lock_irq(&phba->hbalock); | |
1202 | phba->hba_flag &= ~DEFER_ERATT; | |
1203 | spin_unlock_irq(&phba->hbalock); | |
1204 | return; | |
1205 | } | |
1206 | ||
a257bf90 JS |
1207 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
1208 | "0479 Deferred Adapter Hardware Error " | |
1209 | "Data: x%x x%x x%x\n", | |
1210 | phba->work_hs, | |
1211 | phba->work_status[0], phba->work_status[1]); | |
1212 | ||
1213 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1214 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
a257bf90 JS |
1215 | spin_unlock_irq(&phba->hbalock); |
1216 | ||
1217 | ||
1218 | /* | |
1219 | * Firmware stops when it triggred erratt. That could cause the I/Os | |
1220 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the | |
1221 | * SCSI layer retry it after re-establishing link. | |
1222 | */ | |
1223 | pring = &psli->ring[psli->fcp_ring]; | |
1224 | lpfc_sli_abort_iocb_ring(phba, pring); | |
1225 | ||
1226 | /* | |
1227 | * There was a firmware error. Take the hba offline and then | |
1228 | * attempt to restart it. | |
1229 | */ | |
1230 | lpfc_offline_prep(phba); | |
1231 | lpfc_offline(phba); | |
1232 | ||
1233 | /* Wait for the ER1 bit to clear.*/ | |
1234 | while (phba->work_hs & HS_FFER1) { | |
1235 | msleep(100); | |
9940b97b JS |
1236 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
1237 | phba->work_hs = UNPLUG_ERR ; | |
1238 | break; | |
1239 | } | |
a257bf90 JS |
1240 | /* If driver is unloading let the worker thread continue */ |
1241 | if (phba->pport->load_flag & FC_UNLOADING) { | |
1242 | phba->work_hs = 0; | |
1243 | break; | |
1244 | } | |
1245 | } | |
1246 | ||
1247 | /* | |
1248 | * This is to ptrotect against a race condition in which | |
1249 | * first write to the host attention register clear the | |
1250 | * host status register. | |
1251 | */ | |
1252 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) | |
1253 | phba->work_hs = old_host_status & ~HS_FFER1; | |
1254 | ||
3772a991 | 1255 | spin_lock_irq(&phba->hbalock); |
a257bf90 | 1256 | phba->hba_flag &= ~DEFER_ERATT; |
3772a991 | 1257 | spin_unlock_irq(&phba->hbalock); |
a257bf90 JS |
1258 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
1259 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); | |
1260 | } | |
1261 | ||
3772a991 JS |
1262 | static void |
1263 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) | |
1264 | { | |
1265 | struct lpfc_board_event_header board_event; | |
1266 | struct Scsi_Host *shost; | |
1267 | ||
1268 | board_event.event_type = FC_REG_BOARD_EVENT; | |
1269 | board_event.subcategory = LPFC_EVENT_PORTINTERR; | |
1270 | shost = lpfc_shost_from_vport(phba->pport); | |
1271 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1272 | sizeof(board_event), | |
1273 | (char *) &board_event, | |
1274 | LPFC_NL_VENDOR_ID); | |
1275 | } | |
1276 | ||
e59058c4 | 1277 | /** |
3772a991 | 1278 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
e59058c4 JS |
1279 | * @phba: pointer to lpfc hba data structure. |
1280 | * | |
1281 | * This routine is invoked to handle the following HBA hardware error | |
1282 | * conditions: | |
1283 | * 1 - HBA error attention interrupt | |
1284 | * 2 - DMA ring index out of range | |
1285 | * 3 - Mailbox command came back as unknown | |
1286 | **/ | |
3772a991 JS |
1287 | static void |
1288 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) | |
dea3101e | 1289 | { |
2e0fef85 | 1290 | struct lpfc_vport *vport = phba->pport; |
2e0fef85 | 1291 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 1292 | struct lpfc_sli_ring *pring; |
d2873e4c | 1293 | uint32_t event_data; |
57127f15 JS |
1294 | unsigned long temperature; |
1295 | struct temp_event temp_event_data; | |
92d7f7b0 | 1296 | struct Scsi_Host *shost; |
2e0fef85 | 1297 | |
8d63f375 | 1298 | /* If the pci channel is offline, ignore possible errors, |
3772a991 JS |
1299 | * since we cannot communicate with the pci card anyway. |
1300 | */ | |
1301 | if (pci_channel_offline(phba->pcidev)) { | |
1302 | spin_lock_irq(&phba->hbalock); | |
1303 | phba->hba_flag &= ~DEFER_ERATT; | |
1304 | spin_unlock_irq(&phba->hbalock); | |
8d63f375 | 1305 | return; |
3772a991 JS |
1306 | } |
1307 | ||
13815c83 JS |
1308 | /* If resets are disabled then leave the HBA alone and return */ |
1309 | if (!phba->cfg_enable_hba_reset) | |
1310 | return; | |
dea3101e | 1311 | |
ea2151b4 | 1312 | /* Send an internal error event to mgmt application */ |
3772a991 | 1313 | lpfc_board_errevt_to_mgmt(phba); |
ea2151b4 | 1314 | |
a257bf90 JS |
1315 | if (phba->hba_flag & DEFER_ERATT) |
1316 | lpfc_handle_deferred_eratt(phba); | |
1317 | ||
dcf2a4e0 JS |
1318 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
1319 | if (phba->work_hs & HS_FFER6) | |
1320 | /* Re-establishing Link */ | |
1321 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
1322 | "1301 Re-establishing Link " | |
1323 | "Data: x%x x%x x%x\n", | |
1324 | phba->work_hs, phba->work_status[0], | |
1325 | phba->work_status[1]); | |
1326 | if (phba->work_hs & HS_FFER8) | |
1327 | /* Device Zeroization */ | |
1328 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
1329 | "2861 Host Authentication device " | |
1330 | "zeroization Data:x%x x%x x%x\n", | |
1331 | phba->work_hs, phba->work_status[0], | |
1332 | phba->work_status[1]); | |
58da1ffb | 1333 | |
92d7f7b0 | 1334 | spin_lock_irq(&phba->hbalock); |
f4b4c68f | 1335 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
92d7f7b0 | 1336 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1337 | |
1338 | /* | |
1339 | * Firmware stops when it triggled erratt with HS_FFER6. | |
1340 | * That could cause the I/Os dropped by the firmware. | |
1341 | * Error iocb (I/O) on txcmplq and let the SCSI layer | |
1342 | * retry it after re-establishing link. | |
1343 | */ | |
1344 | pring = &psli->ring[psli->fcp_ring]; | |
1345 | lpfc_sli_abort_iocb_ring(phba, pring); | |
1346 | ||
dea3101e | 1347 | /* |
1348 | * There was a firmware error. Take the hba offline and then | |
1349 | * attempt to restart it. | |
1350 | */ | |
46fa311e | 1351 | lpfc_offline_prep(phba); |
dea3101e | 1352 | lpfc_offline(phba); |
41415862 | 1353 | lpfc_sli_brdrestart(phba); |
dea3101e | 1354 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
46fa311e | 1355 | lpfc_unblock_mgmt_io(phba); |
dea3101e | 1356 | return; |
1357 | } | |
46fa311e | 1358 | lpfc_unblock_mgmt_io(phba); |
57127f15 JS |
1359 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
1360 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); | |
1361 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
1362 | temp_event_data.event_code = LPFC_CRIT_TEMP; | |
1363 | temp_event_data.data = (uint32_t)temperature; | |
1364 | ||
1365 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 1366 | "0406 Adapter maximum temperature exceeded " |
57127f15 JS |
1367 | "(%ld), taking this port offline " |
1368 | "Data: x%x x%x x%x\n", | |
1369 | temperature, phba->work_hs, | |
1370 | phba->work_status[0], phba->work_status[1]); | |
1371 | ||
1372 | shost = lpfc_shost_from_vport(phba->pport); | |
1373 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1374 | sizeof(temp_event_data), | |
1375 | (char *) &temp_event_data, | |
1376 | SCSI_NL_VID_TYPE_PCI | |
1377 | | PCI_VENDOR_ID_EMULEX); | |
1378 | ||
7af67051 | 1379 | spin_lock_irq(&phba->hbalock); |
7af67051 JS |
1380 | phba->over_temp_state = HBA_OVER_TEMP; |
1381 | spin_unlock_irq(&phba->hbalock); | |
09372820 | 1382 | lpfc_offline_eratt(phba); |
57127f15 | 1383 | |
dea3101e | 1384 | } else { |
1385 | /* The if clause above forces this code path when the status | |
9399627f JS |
1386 | * failure is a value other than FFER6. Do not call the offline |
1387 | * twice. This is the adapter hardware error path. | |
dea3101e | 1388 | */ |
1389 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 | 1390 | "0457 Adapter Hardware Error " |
dea3101e | 1391 | "Data: x%x x%x x%x\n", |
e8b62011 | 1392 | phba->work_hs, |
dea3101e | 1393 | phba->work_status[0], phba->work_status[1]); |
1394 | ||
d2873e4c | 1395 | event_data = FC_REG_DUMP_EVENT; |
92d7f7b0 | 1396 | shost = lpfc_shost_from_vport(vport); |
2e0fef85 | 1397 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
d2873e4c JS |
1398 | sizeof(event_data), (char *) &event_data, |
1399 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
1400 | ||
09372820 | 1401 | lpfc_offline_eratt(phba); |
dea3101e | 1402 | } |
9399627f | 1403 | return; |
dea3101e | 1404 | } |
1405 | ||
da0436e9 JS |
1406 | /** |
1407 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler | |
1408 | * @phba: pointer to lpfc hba data structure. | |
1409 | * | |
1410 | * This routine is invoked to handle the SLI4 HBA hardware error attention | |
1411 | * conditions. | |
1412 | **/ | |
1413 | static void | |
1414 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) | |
1415 | { | |
1416 | struct lpfc_vport *vport = phba->pport; | |
1417 | uint32_t event_data; | |
1418 | struct Scsi_Host *shost; | |
2fcee4bf JS |
1419 | uint32_t if_type; |
1420 | struct lpfc_register portstat_reg; | |
73d91e50 | 1421 | int rc; |
da0436e9 JS |
1422 | |
1423 | /* If the pci channel is offline, ignore possible errors, since | |
1424 | * we cannot communicate with the pci card anyway. | |
1425 | */ | |
1426 | if (pci_channel_offline(phba->pcidev)) | |
1427 | return; | |
1428 | /* If resets are disabled then leave the HBA alone and return */ | |
1429 | if (!phba->cfg_enable_hba_reset) | |
1430 | return; | |
1431 | ||
1432 | /* Send an internal error event to mgmt application */ | |
1433 | lpfc_board_errevt_to_mgmt(phba); | |
1434 | ||
1435 | /* For now, the actual action for SLI4 device handling is not | |
1436 | * specified yet, just treated it as adaptor hardware failure | |
1437 | */ | |
da0436e9 JS |
1438 | event_data = FC_REG_DUMP_EVENT; |
1439 | shost = lpfc_shost_from_vport(vport); | |
1440 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1441 | sizeof(event_data), (char *) &event_data, | |
1442 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
1443 | ||
2fcee4bf JS |
1444 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
1445 | switch (if_type) { | |
1446 | case LPFC_SLI_INTF_IF_TYPE_0: | |
1447 | lpfc_sli4_offline_eratt(phba); | |
1448 | break; | |
1449 | case LPFC_SLI_INTF_IF_TYPE_2: | |
1450 | portstat_reg.word0 = | |
1451 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr); | |
1452 | ||
1453 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { | |
1454 | /* TODO: Register for Overtemp async events. */ | |
1455 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1456 | "2889 Port Overtemperature event, " | |
026abb87 | 1457 | "taking port offline\n"); |
2fcee4bf JS |
1458 | spin_lock_irq(&phba->hbalock); |
1459 | phba->over_temp_state = HBA_OVER_TEMP; | |
1460 | spin_unlock_irq(&phba->hbalock); | |
1461 | lpfc_sli4_offline_eratt(phba); | |
1462 | return; | |
1463 | } | |
73d91e50 JS |
1464 | /* |
1465 | * On error status condition, driver need to wait for port | |
1466 | * ready before performing reset. | |
1467 | */ | |
1468 | rc = lpfc_sli4_pdev_status_reg_wait(phba); | |
1469 | if (!rc) { | |
079b5c91 | 1470 | /* need reset: attempt for port recovery */ |
2fcee4bf JS |
1471 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
1472 | "2887 Port Error: Attempting " | |
1473 | "Port Recovery\n"); | |
079b5c91 JS |
1474 | lpfc_offline_prep(phba); |
1475 | lpfc_offline(phba); | |
1476 | lpfc_sli_brdrestart(phba); | |
1477 | if (lpfc_online(phba) == 0) { | |
1478 | lpfc_unblock_mgmt_io(phba); | |
1479 | return; | |
1480 | } | |
1481 | /* fall through for not able to recover */ | |
2fcee4bf JS |
1482 | } |
1483 | lpfc_sli4_offline_eratt(phba); | |
1484 | break; | |
1485 | case LPFC_SLI_INTF_IF_TYPE_1: | |
1486 | default: | |
1487 | break; | |
1488 | } | |
da0436e9 JS |
1489 | } |
1490 | ||
1491 | /** | |
1492 | * lpfc_handle_eratt - Wrapper func for handling hba error attention | |
1493 | * @phba: pointer to lpfc HBA data structure. | |
1494 | * | |
1495 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling | |
1496 | * routine from the API jump table function pointer from the lpfc_hba struct. | |
1497 | * | |
1498 | * Return codes | |
af901ca1 | 1499 | * 0 - success. |
da0436e9 JS |
1500 | * Any other value - error. |
1501 | **/ | |
1502 | void | |
1503 | lpfc_handle_eratt(struct lpfc_hba *phba) | |
1504 | { | |
1505 | (*phba->lpfc_handle_eratt)(phba); | |
1506 | } | |
1507 | ||
e59058c4 | 1508 | /** |
3621a710 | 1509 | * lpfc_handle_latt - The HBA link event handler |
e59058c4 JS |
1510 | * @phba: pointer to lpfc hba data structure. |
1511 | * | |
1512 | * This routine is invoked from the worker thread to handle a HBA host | |
1513 | * attention link event. | |
1514 | **/ | |
dea3101e | 1515 | void |
2e0fef85 | 1516 | lpfc_handle_latt(struct lpfc_hba *phba) |
dea3101e | 1517 | { |
2e0fef85 JS |
1518 | struct lpfc_vport *vport = phba->pport; |
1519 | struct lpfc_sli *psli = &phba->sli; | |
dea3101e | 1520 | LPFC_MBOXQ_t *pmb; |
1521 | volatile uint32_t control; | |
1522 | struct lpfc_dmabuf *mp; | |
09372820 | 1523 | int rc = 0; |
dea3101e | 1524 | |
1525 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
09372820 JS |
1526 | if (!pmb) { |
1527 | rc = 1; | |
dea3101e | 1528 | goto lpfc_handle_latt_err_exit; |
09372820 | 1529 | } |
dea3101e | 1530 | |
1531 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
09372820 JS |
1532 | if (!mp) { |
1533 | rc = 2; | |
dea3101e | 1534 | goto lpfc_handle_latt_free_pmb; |
09372820 | 1535 | } |
dea3101e | 1536 | |
1537 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
09372820 JS |
1538 | if (!mp->virt) { |
1539 | rc = 3; | |
dea3101e | 1540 | goto lpfc_handle_latt_free_mp; |
09372820 | 1541 | } |
dea3101e | 1542 | |
6281bfe0 | 1543 | /* Cleanup any outstanding ELS commands */ |
549e55cd | 1544 | lpfc_els_flush_all_cmd(phba); |
dea3101e | 1545 | |
1546 | psli->slistat.link_event++; | |
76a95d75 JS |
1547 | lpfc_read_topology(phba, pmb, mp); |
1548 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
2e0fef85 | 1549 | pmb->vport = vport; |
0d2b6b83 JS |
1550 | /* Block ELS IOCBs until we have processed this mbox command */ |
1551 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
0b727fea | 1552 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
09372820 JS |
1553 | if (rc == MBX_NOT_FINISHED) { |
1554 | rc = 4; | |
14691150 | 1555 | goto lpfc_handle_latt_free_mbuf; |
09372820 | 1556 | } |
dea3101e | 1557 | |
1558 | /* Clear Link Attention in HA REG */ | |
2e0fef85 | 1559 | spin_lock_irq(&phba->hbalock); |
dea3101e | 1560 | writel(HA_LATT, phba->HAregaddr); |
1561 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1562 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1563 | |
1564 | return; | |
1565 | ||
14691150 | 1566 | lpfc_handle_latt_free_mbuf: |
0d2b6b83 | 1567 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
14691150 | 1568 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
dea3101e | 1569 | lpfc_handle_latt_free_mp: |
1570 | kfree(mp); | |
1571 | lpfc_handle_latt_free_pmb: | |
1dcb58e5 | 1572 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e | 1573 | lpfc_handle_latt_err_exit: |
1574 | /* Enable Link attention interrupts */ | |
2e0fef85 | 1575 | spin_lock_irq(&phba->hbalock); |
dea3101e | 1576 | psli->sli_flag |= LPFC_PROCESS_LA; |
1577 | control = readl(phba->HCregaddr); | |
1578 | control |= HC_LAINT_ENA; | |
1579 | writel(control, phba->HCregaddr); | |
1580 | readl(phba->HCregaddr); /* flush */ | |
1581 | ||
1582 | /* Clear Link Attention in HA REG */ | |
1583 | writel(HA_LATT, phba->HAregaddr); | |
1584 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1585 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1586 | lpfc_linkdown(phba); |
2e0fef85 | 1587 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 1588 | |
09372820 JS |
1589 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
1590 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); | |
dea3101e | 1591 | |
1592 | return; | |
1593 | } | |
1594 | ||
e59058c4 | 1595 | /** |
3621a710 | 1596 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
e59058c4 JS |
1597 | * @phba: pointer to lpfc hba data structure. |
1598 | * @vpd: pointer to the vital product data. | |
1599 | * @len: length of the vital product data in bytes. | |
1600 | * | |
1601 | * This routine parses the Vital Product Data (VPD). The VPD is treated as | |
1602 | * an array of characters. In this routine, the ModelName, ProgramType, and | |
1603 | * ModelDesc, etc. fields of the phba data structure will be populated. | |
1604 | * | |
1605 | * Return codes | |
1606 | * 0 - pointer to the VPD passed in is NULL | |
1607 | * 1 - success | |
1608 | **/ | |
3772a991 | 1609 | int |
2e0fef85 | 1610 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
dea3101e | 1611 | { |
1612 | uint8_t lenlo, lenhi; | |
07da60c1 | 1613 | int Length; |
dea3101e | 1614 | int i, j; |
1615 | int finished = 0; | |
1616 | int index = 0; | |
1617 | ||
1618 | if (!vpd) | |
1619 | return 0; | |
1620 | ||
1621 | /* Vital Product */ | |
ed957684 | 1622 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
e8b62011 | 1623 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
dea3101e | 1624 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
1625 | (uint32_t) vpd[3]); | |
74b72a59 | 1626 | while (!finished && (index < (len - 4))) { |
dea3101e | 1627 | switch (vpd[index]) { |
1628 | case 0x82: | |
74b72a59 | 1629 | case 0x91: |
dea3101e | 1630 | index += 1; |
1631 | lenlo = vpd[index]; | |
1632 | index += 1; | |
1633 | lenhi = vpd[index]; | |
1634 | index += 1; | |
1635 | i = ((((unsigned short)lenhi) << 8) + lenlo); | |
1636 | index += i; | |
1637 | break; | |
1638 | case 0x90: | |
1639 | index += 1; | |
1640 | lenlo = vpd[index]; | |
1641 | index += 1; | |
1642 | lenhi = vpd[index]; | |
1643 | index += 1; | |
1644 | Length = ((((unsigned short)lenhi) << 8) + lenlo); | |
74b72a59 JW |
1645 | if (Length > len - index) |
1646 | Length = len - index; | |
dea3101e | 1647 | while (Length > 0) { |
1648 | /* Look for Serial Number */ | |
1649 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { | |
1650 | index += 2; | |
1651 | i = vpd[index]; | |
1652 | index += 1; | |
1653 | j = 0; | |
1654 | Length -= (3+i); | |
1655 | while(i--) { | |
1656 | phba->SerialNumber[j++] = vpd[index++]; | |
1657 | if (j == 31) | |
1658 | break; | |
1659 | } | |
1660 | phba->SerialNumber[j] = 0; | |
1661 | continue; | |
1662 | } | |
1663 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { | |
1664 | phba->vpd_flag |= VPD_MODEL_DESC; | |
1665 | index += 2; | |
1666 | i = vpd[index]; | |
1667 | index += 1; | |
1668 | j = 0; | |
1669 | Length -= (3+i); | |
1670 | while(i--) { | |
1671 | phba->ModelDesc[j++] = vpd[index++]; | |
1672 | if (j == 255) | |
1673 | break; | |
1674 | } | |
1675 | phba->ModelDesc[j] = 0; | |
1676 | continue; | |
1677 | } | |
1678 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { | |
1679 | phba->vpd_flag |= VPD_MODEL_NAME; | |
1680 | index += 2; | |
1681 | i = vpd[index]; | |
1682 | index += 1; | |
1683 | j = 0; | |
1684 | Length -= (3+i); | |
1685 | while(i--) { | |
1686 | phba->ModelName[j++] = vpd[index++]; | |
1687 | if (j == 79) | |
1688 | break; | |
1689 | } | |
1690 | phba->ModelName[j] = 0; | |
1691 | continue; | |
1692 | } | |
1693 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { | |
1694 | phba->vpd_flag |= VPD_PROGRAM_TYPE; | |
1695 | index += 2; | |
1696 | i = vpd[index]; | |
1697 | index += 1; | |
1698 | j = 0; | |
1699 | Length -= (3+i); | |
1700 | while(i--) { | |
1701 | phba->ProgramType[j++] = vpd[index++]; | |
1702 | if (j == 255) | |
1703 | break; | |
1704 | } | |
1705 | phba->ProgramType[j] = 0; | |
1706 | continue; | |
1707 | } | |
1708 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { | |
1709 | phba->vpd_flag |= VPD_PORT; | |
1710 | index += 2; | |
1711 | i = vpd[index]; | |
1712 | index += 1; | |
1713 | j = 0; | |
1714 | Length -= (3+i); | |
1715 | while(i--) { | |
cd1c8301 JS |
1716 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
1717 | (phba->sli4_hba.pport_name_sta == | |
1718 | LPFC_SLI4_PPNAME_GET)) { | |
1719 | j++; | |
1720 | index++; | |
1721 | } else | |
1722 | phba->Port[j++] = vpd[index++]; | |
1723 | if (j == 19) | |
1724 | break; | |
dea3101e | 1725 | } |
cd1c8301 JS |
1726 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
1727 | (phba->sli4_hba.pport_name_sta == | |
1728 | LPFC_SLI4_PPNAME_NON)) | |
1729 | phba->Port[j] = 0; | |
dea3101e | 1730 | continue; |
1731 | } | |
1732 | else { | |
1733 | index += 2; | |
1734 | i = vpd[index]; | |
1735 | index += 1; | |
1736 | index += i; | |
1737 | Length -= (3 + i); | |
1738 | } | |
1739 | } | |
1740 | finished = 0; | |
1741 | break; | |
1742 | case 0x78: | |
1743 | finished = 1; | |
1744 | break; | |
1745 | default: | |
1746 | index ++; | |
1747 | break; | |
1748 | } | |
74b72a59 | 1749 | } |
dea3101e | 1750 | |
1751 | return(1); | |
1752 | } | |
1753 | ||
e59058c4 | 1754 | /** |
3621a710 | 1755 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
e59058c4 JS |
1756 | * @phba: pointer to lpfc hba data structure. |
1757 | * @mdp: pointer to the data structure to hold the derived model name. | |
1758 | * @descp: pointer to the data structure to hold the derived description. | |
1759 | * | |
1760 | * This routine retrieves HBA's description based on its registered PCI device | |
1761 | * ID. The @descp passed into this function points to an array of 256 chars. It | |
1762 | * shall be returned with the model name, maximum speed, and the host bus type. | |
1763 | * The @mdp passed into this function points to an array of 80 chars. When the | |
1764 | * function returns, the @mdp will be filled with the model name. | |
1765 | **/ | |
dea3101e | 1766 | static void |
2e0fef85 | 1767 | lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) |
dea3101e | 1768 | { |
1769 | lpfc_vpd_t *vp; | |
fefcb2b6 | 1770 | uint16_t dev_id = phba->pcidev->device; |
74b72a59 | 1771 | int max_speed; |
84774a4d | 1772 | int GE = 0; |
da0436e9 | 1773 | int oneConnect = 0; /* default is not a oneConnect */ |
74b72a59 | 1774 | struct { |
a747c9ce JS |
1775 | char *name; |
1776 | char *bus; | |
1777 | char *function; | |
1778 | } m = {"<Unknown>", "", ""}; | |
74b72a59 JW |
1779 | |
1780 | if (mdp && mdp[0] != '\0' | |
1781 | && descp && descp[0] != '\0') | |
1782 | return; | |
1783 | ||
c0c11512 JS |
1784 | if (phba->lmt & LMT_16Gb) |
1785 | max_speed = 16; | |
1786 | else if (phba->lmt & LMT_10Gb) | |
74b72a59 JW |
1787 | max_speed = 10; |
1788 | else if (phba->lmt & LMT_8Gb) | |
1789 | max_speed = 8; | |
1790 | else if (phba->lmt & LMT_4Gb) | |
1791 | max_speed = 4; | |
1792 | else if (phba->lmt & LMT_2Gb) | |
1793 | max_speed = 2; | |
1794 | else | |
1795 | max_speed = 1; | |
dea3101e | 1796 | |
1797 | vp = &phba->vpd; | |
dea3101e | 1798 | |
e4adb204 | 1799 | switch (dev_id) { |
06325e74 | 1800 | case PCI_DEVICE_ID_FIREFLY: |
a747c9ce | 1801 | m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"}; |
06325e74 | 1802 | break; |
dea3101e | 1803 | case PCI_DEVICE_ID_SUPERFLY: |
1804 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) | |
a747c9ce JS |
1805 | m = (typeof(m)){"LP7000", "PCI", |
1806 | "Fibre Channel Adapter"}; | |
dea3101e | 1807 | else |
a747c9ce JS |
1808 | m = (typeof(m)){"LP7000E", "PCI", |
1809 | "Fibre Channel Adapter"}; | |
dea3101e | 1810 | break; |
1811 | case PCI_DEVICE_ID_DRAGONFLY: | |
a747c9ce JS |
1812 | m = (typeof(m)){"LP8000", "PCI", |
1813 | "Fibre Channel Adapter"}; | |
dea3101e | 1814 | break; |
1815 | case PCI_DEVICE_ID_CENTAUR: | |
1816 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) | |
a747c9ce JS |
1817 | m = (typeof(m)){"LP9002", "PCI", |
1818 | "Fibre Channel Adapter"}; | |
dea3101e | 1819 | else |
a747c9ce JS |
1820 | m = (typeof(m)){"LP9000", "PCI", |
1821 | "Fibre Channel Adapter"}; | |
dea3101e | 1822 | break; |
1823 | case PCI_DEVICE_ID_RFLY: | |
a747c9ce JS |
1824 | m = (typeof(m)){"LP952", "PCI", |
1825 | "Fibre Channel Adapter"}; | |
dea3101e | 1826 | break; |
1827 | case PCI_DEVICE_ID_PEGASUS: | |
a747c9ce JS |
1828 | m = (typeof(m)){"LP9802", "PCI-X", |
1829 | "Fibre Channel Adapter"}; | |
dea3101e | 1830 | break; |
1831 | case PCI_DEVICE_ID_THOR: | |
a747c9ce JS |
1832 | m = (typeof(m)){"LP10000", "PCI-X", |
1833 | "Fibre Channel Adapter"}; | |
dea3101e | 1834 | break; |
1835 | case PCI_DEVICE_ID_VIPER: | |
a747c9ce JS |
1836 | m = (typeof(m)){"LPX1000", "PCI-X", |
1837 | "Fibre Channel Adapter"}; | |
dea3101e | 1838 | break; |
1839 | case PCI_DEVICE_ID_PFLY: | |
a747c9ce JS |
1840 | m = (typeof(m)){"LP982", "PCI-X", |
1841 | "Fibre Channel Adapter"}; | |
dea3101e | 1842 | break; |
1843 | case PCI_DEVICE_ID_TFLY: | |
a747c9ce JS |
1844 | m = (typeof(m)){"LP1050", "PCI-X", |
1845 | "Fibre Channel Adapter"}; | |
dea3101e | 1846 | break; |
1847 | case PCI_DEVICE_ID_HELIOS: | |
a747c9ce JS |
1848 | m = (typeof(m)){"LP11000", "PCI-X2", |
1849 | "Fibre Channel Adapter"}; | |
dea3101e | 1850 | break; |
e4adb204 | 1851 | case PCI_DEVICE_ID_HELIOS_SCSP: |
a747c9ce JS |
1852 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
1853 | "Fibre Channel Adapter"}; | |
e4adb204 JSEC |
1854 | break; |
1855 | case PCI_DEVICE_ID_HELIOS_DCSP: | |
a747c9ce JS |
1856 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
1857 | "Fibre Channel Adapter"}; | |
e4adb204 JSEC |
1858 | break; |
1859 | case PCI_DEVICE_ID_NEPTUNE: | |
a747c9ce | 1860 | m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1861 | break; |
1862 | case PCI_DEVICE_ID_NEPTUNE_SCSP: | |
a747c9ce | 1863 | m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1864 | break; |
1865 | case PCI_DEVICE_ID_NEPTUNE_DCSP: | |
a747c9ce | 1866 | m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 | 1867 | break; |
dea3101e | 1868 | case PCI_DEVICE_ID_BMID: |
a747c9ce | 1869 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
dea3101e | 1870 | break; |
1871 | case PCI_DEVICE_ID_BSMB: | |
a747c9ce | 1872 | m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"}; |
dea3101e | 1873 | break; |
1874 | case PCI_DEVICE_ID_ZEPHYR: | |
a747c9ce | 1875 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
dea3101e | 1876 | break; |
e4adb204 | 1877 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
a747c9ce | 1878 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1879 | break; |
1880 | case PCI_DEVICE_ID_ZEPHYR_DCSP: | |
a747c9ce | 1881 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
a257bf90 | 1882 | GE = 1; |
e4adb204 | 1883 | break; |
dea3101e | 1884 | case PCI_DEVICE_ID_ZMID: |
a747c9ce | 1885 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
dea3101e | 1886 | break; |
1887 | case PCI_DEVICE_ID_ZSMB: | |
a747c9ce | 1888 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
dea3101e | 1889 | break; |
1890 | case PCI_DEVICE_ID_LP101: | |
a747c9ce | 1891 | m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"}; |
dea3101e | 1892 | break; |
1893 | case PCI_DEVICE_ID_LP10000S: | |
a747c9ce | 1894 | m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"}; |
06325e74 | 1895 | break; |
e4adb204 | 1896 | case PCI_DEVICE_ID_LP11000S: |
a747c9ce | 1897 | m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"}; |
18a3b596 | 1898 | break; |
e4adb204 | 1899 | case PCI_DEVICE_ID_LPE11000S: |
a747c9ce | 1900 | m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"}; |
5cc36b3c | 1901 | break; |
b87eab38 | 1902 | case PCI_DEVICE_ID_SAT: |
a747c9ce | 1903 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1904 | break; |
1905 | case PCI_DEVICE_ID_SAT_MID: | |
a747c9ce | 1906 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1907 | break; |
1908 | case PCI_DEVICE_ID_SAT_SMB: | |
a747c9ce | 1909 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1910 | break; |
1911 | case PCI_DEVICE_ID_SAT_DCSP: | |
a747c9ce | 1912 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1913 | break; |
1914 | case PCI_DEVICE_ID_SAT_SCSP: | |
a747c9ce | 1915 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1916 | break; |
1917 | case PCI_DEVICE_ID_SAT_S: | |
a747c9ce | 1918 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 | 1919 | break; |
84774a4d | 1920 | case PCI_DEVICE_ID_HORNET: |
a747c9ce | 1921 | m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"}; |
84774a4d JS |
1922 | GE = 1; |
1923 | break; | |
1924 | case PCI_DEVICE_ID_PROTEUS_VF: | |
a747c9ce JS |
1925 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
1926 | "Fibre Channel Adapter"}; | |
84774a4d JS |
1927 | break; |
1928 | case PCI_DEVICE_ID_PROTEUS_PF: | |
a747c9ce JS |
1929 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
1930 | "Fibre Channel Adapter"}; | |
84774a4d JS |
1931 | break; |
1932 | case PCI_DEVICE_ID_PROTEUS_S: | |
a747c9ce JS |
1933 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
1934 | "Fibre Channel Adapter"}; | |
84774a4d | 1935 | break; |
da0436e9 JS |
1936 | case PCI_DEVICE_ID_TIGERSHARK: |
1937 | oneConnect = 1; | |
a747c9ce | 1938 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
da0436e9 | 1939 | break; |
a747c9ce | 1940 | case PCI_DEVICE_ID_TOMCAT: |
6669f9bb | 1941 | oneConnect = 1; |
a747c9ce JS |
1942 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
1943 | break; | |
1944 | case PCI_DEVICE_ID_FALCON: | |
1945 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", | |
1946 | "EmulexSecure Fibre"}; | |
6669f9bb | 1947 | break; |
98fc5dd9 JS |
1948 | case PCI_DEVICE_ID_BALIUS: |
1949 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", | |
1950 | "Fibre Channel Adapter"}; | |
1951 | break; | |
085c647c | 1952 | case PCI_DEVICE_ID_LANCER_FC: |
c0c11512 JS |
1953 | case PCI_DEVICE_ID_LANCER_FC_VF: |
1954 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; | |
085c647c JS |
1955 | break; |
1956 | case PCI_DEVICE_ID_LANCER_FCOE: | |
c0c11512 | 1957 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
085c647c | 1958 | oneConnect = 1; |
079b5c91 | 1959 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
085c647c | 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); | |
c0c11512 JS |
1968 | /* |
1969 | * oneConnect hba requires special processing, they are all initiators | |
da0436e9 JS |
1970 | * and we put the port number on the end |
1971 | */ | |
1972 | if (descp && descp[0] == '\0') { | |
1973 | if (oneConnect) | |
1974 | snprintf(descp, 255, | |
a747c9ce JS |
1975 | "Emulex OneConnect %s, %s Initiator, Port %s", |
1976 | m.name, m.function, | |
da0436e9 JS |
1977 | phba->Port); |
1978 | else | |
1979 | snprintf(descp, 255, | |
1980 | "Emulex %s %d%s %s %s", | |
a747c9ce JS |
1981 | m.name, max_speed, (GE) ? "GE" : "Gb", |
1982 | m.bus, m.function); | |
da0436e9 | 1983 | } |
dea3101e | 1984 | } |
1985 | ||
e59058c4 | 1986 | /** |
3621a710 | 1987 | * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring |
e59058c4 JS |
1988 | * @phba: pointer to lpfc hba data structure. |
1989 | * @pring: pointer to a IOCB ring. | |
1990 | * @cnt: the number of IOCBs to be posted to the IOCB ring. | |
1991 | * | |
1992 | * This routine posts a given number of IOCBs with the associated DMA buffer | |
1993 | * descriptors specified by the cnt argument to the given IOCB ring. | |
1994 | * | |
1995 | * Return codes | |
1996 | * The number of IOCBs NOT able to be posted to the IOCB ring. | |
1997 | **/ | |
dea3101e | 1998 | int |
495a714c | 1999 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
dea3101e | 2000 | { |
2001 | IOCB_t *icmd; | |
0bd4ca25 | 2002 | struct lpfc_iocbq *iocb; |
dea3101e | 2003 | struct lpfc_dmabuf *mp1, *mp2; |
2004 | ||
2005 | cnt += pring->missbufcnt; | |
2006 | ||
2007 | /* While there are buffers to post */ | |
2008 | while (cnt > 0) { | |
2009 | /* Allocate buffer for command iocb */ | |
0bd4ca25 | 2010 | iocb = lpfc_sli_get_iocbq(phba); |
dea3101e | 2011 | if (iocb == NULL) { |
2012 | pring->missbufcnt = cnt; | |
2013 | return cnt; | |
2014 | } | |
dea3101e | 2015 | icmd = &iocb->iocb; |
2016 | ||
2017 | /* 2 buffers can be posted per command */ | |
2018 | /* Allocate buffer to post */ | |
2019 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
2020 | if (mp1) | |
98c9ea5c JS |
2021 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
2022 | if (!mp1 || !mp1->virt) { | |
c9475cb0 | 2023 | kfree(mp1); |
604a3e30 | 2024 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e | 2025 | pring->missbufcnt = cnt; |
2026 | return cnt; | |
2027 | } | |
2028 | ||
2029 | INIT_LIST_HEAD(&mp1->list); | |
2030 | /* Allocate buffer to post */ | |
2031 | if (cnt > 1) { | |
2032 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
2033 | if (mp2) | |
2034 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | |
2035 | &mp2->phys); | |
98c9ea5c | 2036 | if (!mp2 || !mp2->virt) { |
c9475cb0 | 2037 | kfree(mp2); |
dea3101e | 2038 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
2039 | kfree(mp1); | |
604a3e30 | 2040 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e | 2041 | pring->missbufcnt = cnt; |
2042 | return cnt; | |
2043 | } | |
2044 | ||
2045 | INIT_LIST_HEAD(&mp2->list); | |
2046 | } else { | |
2047 | mp2 = NULL; | |
2048 | } | |
2049 | ||
2050 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); | |
2051 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); | |
2052 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; | |
2053 | icmd->ulpBdeCount = 1; | |
2054 | cnt--; | |
2055 | if (mp2) { | |
2056 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); | |
2057 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); | |
2058 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; | |
2059 | cnt--; | |
2060 | icmd->ulpBdeCount = 2; | |
2061 | } | |
2062 | ||
2063 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; | |
2064 | icmd->ulpLe = 1; | |
2065 | ||
3772a991 JS |
2066 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
2067 | IOCB_ERROR) { | |
dea3101e | 2068 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
2069 | kfree(mp1); | |
2070 | cnt++; | |
2071 | if (mp2) { | |
2072 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); | |
2073 | kfree(mp2); | |
2074 | cnt++; | |
2075 | } | |
604a3e30 | 2076 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e | 2077 | pring->missbufcnt = cnt; |
dea3101e | 2078 | return cnt; |
2079 | } | |
dea3101e | 2080 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
92d7f7b0 | 2081 | if (mp2) |
dea3101e | 2082 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
dea3101e | 2083 | } |
2084 | pring->missbufcnt = 0; | |
2085 | return 0; | |
2086 | } | |
2087 | ||
e59058c4 | 2088 | /** |
3621a710 | 2089 | * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring |
e59058c4 JS |
2090 | * @phba: pointer to lpfc hba data structure. |
2091 | * | |
2092 | * This routine posts initial receive IOCB buffers to the ELS ring. The | |
2093 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is | |
2094 | * set to 64 IOCBs. | |
2095 | * | |
2096 | * Return codes | |
2097 | * 0 - success (currently always success) | |
2098 | **/ | |
dea3101e | 2099 | static int |
2e0fef85 | 2100 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
dea3101e | 2101 | { |
2102 | struct lpfc_sli *psli = &phba->sli; | |
2103 | ||
2104 | /* Ring 0, ELS / CT buffers */ | |
495a714c | 2105 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
dea3101e | 2106 | /* Ring 2 - FCP no buffers needed */ |
2107 | ||
2108 | return 0; | |
2109 | } | |
2110 | ||
2111 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) | |
2112 | ||
e59058c4 | 2113 | /** |
3621a710 | 2114 | * lpfc_sha_init - Set up initial array of hash table entries |
e59058c4 JS |
2115 | * @HashResultPointer: pointer to an array as hash table. |
2116 | * | |
2117 | * This routine sets up the initial values to the array of hash table entries | |
2118 | * for the LC HBAs. | |
2119 | **/ | |
dea3101e | 2120 | static void |
2121 | lpfc_sha_init(uint32_t * HashResultPointer) | |
2122 | { | |
2123 | HashResultPointer[0] = 0x67452301; | |
2124 | HashResultPointer[1] = 0xEFCDAB89; | |
2125 | HashResultPointer[2] = 0x98BADCFE; | |
2126 | HashResultPointer[3] = 0x10325476; | |
2127 | HashResultPointer[4] = 0xC3D2E1F0; | |
2128 | } | |
2129 | ||
e59058c4 | 2130 | /** |
3621a710 | 2131 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
e59058c4 JS |
2132 | * @HashResultPointer: pointer to an initial/result hash table. |
2133 | * @HashWorkingPointer: pointer to an working hash table. | |
2134 | * | |
2135 | * This routine iterates an initial hash table pointed by @HashResultPointer | |
2136 | * with the values from the working hash table pointeed by @HashWorkingPointer. | |
2137 | * The results are putting back to the initial hash table, returned through | |
2138 | * the @HashResultPointer as the result hash table. | |
2139 | **/ | |
dea3101e | 2140 | static void |
2141 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) | |
2142 | { | |
2143 | int t; | |
2144 | uint32_t TEMP; | |
2145 | uint32_t A, B, C, D, E; | |
2146 | t = 16; | |
2147 | do { | |
2148 | HashWorkingPointer[t] = | |
2149 | S(1, | |
2150 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - | |
2151 | 8] ^ | |
2152 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); | |
2153 | } while (++t <= 79); | |
2154 | t = 0; | |
2155 | A = HashResultPointer[0]; | |
2156 | B = HashResultPointer[1]; | |
2157 | C = HashResultPointer[2]; | |
2158 | D = HashResultPointer[3]; | |
2159 | E = HashResultPointer[4]; | |
2160 | ||
2161 | do { | |
2162 | if (t < 20) { | |
2163 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; | |
2164 | } else if (t < 40) { | |
2165 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; | |
2166 | } else if (t < 60) { | |
2167 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; | |
2168 | } else { | |
2169 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; | |
2170 | } | |
2171 | TEMP += S(5, A) + E + HashWorkingPointer[t]; | |
2172 | E = D; | |
2173 | D = C; | |
2174 | C = S(30, B); | |
2175 | B = A; | |
2176 | A = TEMP; | |
2177 | } while (++t <= 79); | |
2178 | ||
2179 | HashResultPointer[0] += A; | |
2180 | HashResultPointer[1] += B; | |
2181 | HashResultPointer[2] += C; | |
2182 | HashResultPointer[3] += D; | |
2183 | HashResultPointer[4] += E; | |
2184 | ||
2185 | } | |
2186 | ||
e59058c4 | 2187 | /** |
3621a710 | 2188 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
e59058c4 JS |
2189 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
2190 | * @HashWorking: pointer to the entry of the working hash array. | |
2191 | * | |
2192 | * This routine calculates the working hash array referred by @HashWorking | |
2193 | * from the challenge random numbers associated with the host, referred by | |
2194 | * @RandomChallenge. The result is put into the entry of the working hash | |
2195 | * array and returned by reference through @HashWorking. | |
2196 | **/ | |
dea3101e | 2197 | static void |
2198 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) | |
2199 | { | |
2200 | *HashWorking = (*RandomChallenge ^ *HashWorking); | |
2201 | } | |
2202 | ||
e59058c4 | 2203 | /** |
3621a710 | 2204 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
e59058c4 JS |
2205 | * @phba: pointer to lpfc hba data structure. |
2206 | * @hbainit: pointer to an array of unsigned 32-bit integers. | |
2207 | * | |
2208 | * This routine performs the special handling for LC HBA initialization. | |
2209 | **/ | |
dea3101e | 2210 | void |
2211 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) | |
2212 | { | |
2213 | int t; | |
2214 | uint32_t *HashWorking; | |
2e0fef85 | 2215 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
dea3101e | 2216 | |
bbfbbbc1 | 2217 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
dea3101e | 2218 | if (!HashWorking) |
2219 | return; | |
2220 | ||
dea3101e | 2221 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
2222 | HashWorking[1] = HashWorking[79] = *pwwnn; | |
2223 | ||
2224 | for (t = 0; t < 7; t++) | |
2225 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); | |
2226 | ||
2227 | lpfc_sha_init(hbainit); | |
2228 | lpfc_sha_iterate(hbainit, HashWorking); | |
2229 | kfree(HashWorking); | |
2230 | } | |
2231 | ||
e59058c4 | 2232 | /** |
3621a710 | 2233 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
e59058c4 JS |
2234 | * @vport: pointer to a virtual N_Port data structure. |
2235 | * | |
2236 | * This routine performs the necessary cleanups before deleting the @vport. | |
2237 | * It invokes the discovery state machine to perform necessary state | |
2238 | * transitions and to release the ndlps associated with the @vport. Note, | |
2239 | * the physical port is treated as @vport 0. | |
2240 | **/ | |
87af33fe | 2241 | void |
2e0fef85 | 2242 | lpfc_cleanup(struct lpfc_vport *vport) |
dea3101e | 2243 | { |
87af33fe | 2244 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2245 | struct lpfc_nodelist *ndlp, *next_ndlp; |
a8adb832 | 2246 | int i = 0; |
dea3101e | 2247 | |
87af33fe JS |
2248 | if (phba->link_state > LPFC_LINK_DOWN) |
2249 | lpfc_port_link_failure(vport); | |
2250 | ||
2251 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
2252 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
2253 | ndlp = lpfc_enable_node(vport, ndlp, | |
2254 | NLP_STE_UNUSED_NODE); | |
2255 | if (!ndlp) | |
2256 | continue; | |
2257 | spin_lock_irq(&phba->ndlp_lock); | |
2258 | NLP_SET_FREE_REQ(ndlp); | |
2259 | spin_unlock_irq(&phba->ndlp_lock); | |
2260 | /* Trigger the release of the ndlp memory */ | |
2261 | lpfc_nlp_put(ndlp); | |
2262 | continue; | |
2263 | } | |
2264 | spin_lock_irq(&phba->ndlp_lock); | |
2265 | if (NLP_CHK_FREE_REQ(ndlp)) { | |
2266 | /* The ndlp should not be in memory free mode already */ | |
2267 | spin_unlock_irq(&phba->ndlp_lock); | |
2268 | continue; | |
2269 | } else | |
2270 | /* Indicate request for freeing ndlp memory */ | |
2271 | NLP_SET_FREE_REQ(ndlp); | |
2272 | spin_unlock_irq(&phba->ndlp_lock); | |
2273 | ||
58da1ffb JS |
2274 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
2275 | ndlp->nlp_DID == Fabric_DID) { | |
2276 | /* Just free up ndlp with Fabric_DID for vports */ | |
2277 | lpfc_nlp_put(ndlp); | |
2278 | continue; | |
2279 | } | |
2280 | ||
87af33fe JS |
2281 | if (ndlp->nlp_type & NLP_FABRIC) |
2282 | lpfc_disc_state_machine(vport, ndlp, NULL, | |
2283 | NLP_EVT_DEVICE_RECOVERY); | |
e47c9093 | 2284 | |
87af33fe JS |
2285 | lpfc_disc_state_machine(vport, ndlp, NULL, |
2286 | NLP_EVT_DEVICE_RM); | |
495a714c | 2287 | |
87af33fe JS |
2288 | } |
2289 | ||
a8adb832 JS |
2290 | /* At this point, ALL ndlp's should be gone |
2291 | * because of the previous NLP_EVT_DEVICE_RM. | |
2292 | * Lets wait for this to happen, if needed. | |
2293 | */ | |
87af33fe | 2294 | while (!list_empty(&vport->fc_nodes)) { |
a8adb832 | 2295 | if (i++ > 3000) { |
87af33fe | 2296 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
a8adb832 | 2297 | "0233 Nodelist not empty\n"); |
e47c9093 JS |
2298 | list_for_each_entry_safe(ndlp, next_ndlp, |
2299 | &vport->fc_nodes, nlp_listp) { | |
2300 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, | |
2301 | LOG_NODE, | |
d7c255b2 | 2302 | "0282 did:x%x ndlp:x%p " |
e47c9093 JS |
2303 | "usgmap:x%x refcnt:%d\n", |
2304 | ndlp->nlp_DID, (void *)ndlp, | |
2305 | ndlp->nlp_usg_map, | |
2306 | atomic_read( | |
2307 | &ndlp->kref.refcount)); | |
2308 | } | |
a8adb832 | 2309 | break; |
87af33fe | 2310 | } |
a8adb832 JS |
2311 | |
2312 | /* Wait for any activity on ndlps to settle */ | |
2313 | msleep(10); | |
87af33fe | 2314 | } |
1151e3ec | 2315 | lpfc_cleanup_vports_rrqs(vport, NULL); |
dea3101e | 2316 | } |
2317 | ||
e59058c4 | 2318 | /** |
3621a710 | 2319 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
e59058c4 JS |
2320 | * @vport: pointer to a virtual N_Port data structure. |
2321 | * | |
2322 | * This routine stops all the timers associated with a @vport. This function | |
2323 | * is invoked before disabling or deleting a @vport. Note that the physical | |
2324 | * port is treated as @vport 0. | |
2325 | **/ | |
92d7f7b0 JS |
2326 | void |
2327 | lpfc_stop_vport_timers(struct lpfc_vport *vport) | |
dea3101e | 2328 | { |
92d7f7b0 JS |
2329 | del_timer_sync(&vport->els_tmofunc); |
2330 | del_timer_sync(&vport->fc_fdmitmo); | |
92494144 | 2331 | del_timer_sync(&vport->delayed_disc_tmo); |
92d7f7b0 JS |
2332 | lpfc_can_disctmo(vport); |
2333 | return; | |
dea3101e | 2334 | } |
2335 | ||
ecfd03c6 JS |
2336 | /** |
2337 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2338 | * @phba: pointer to lpfc hba data structure. | |
2339 | * | |
2340 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The | |
2341 | * caller of this routine should already hold the host lock. | |
2342 | **/ | |
2343 | void | |
2344 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2345 | { | |
5ac6b303 JS |
2346 | /* Clear pending FCF rediscovery wait flag */ |
2347 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; | |
2348 | ||
ecfd03c6 JS |
2349 | /* Now, try to stop the timer */ |
2350 | del_timer(&phba->fcf.redisc_wait); | |
2351 | } | |
2352 | ||
2353 | /** | |
2354 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2355 | * @phba: pointer to lpfc hba data structure. | |
2356 | * | |
2357 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It | |
2358 | * checks whether the FCF rediscovery wait timer is pending with the host | |
2359 | * lock held before proceeding with disabling the timer and clearing the | |
2360 | * wait timer pendig flag. | |
2361 | **/ | |
2362 | void | |
2363 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2364 | { | |
2365 | spin_lock_irq(&phba->hbalock); | |
2366 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
2367 | /* FCF rediscovery timer already fired or stopped */ | |
2368 | spin_unlock_irq(&phba->hbalock); | |
2369 | return; | |
2370 | } | |
2371 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); | |
5ac6b303 JS |
2372 | /* Clear failover in progress flags */ |
2373 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); | |
ecfd03c6 JS |
2374 | spin_unlock_irq(&phba->hbalock); |
2375 | } | |
2376 | ||
e59058c4 | 2377 | /** |
3772a991 | 2378 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
e59058c4 JS |
2379 | * @phba: pointer to lpfc hba data structure. |
2380 | * | |
2381 | * This routine stops all the timers associated with a HBA. This function is | |
2382 | * invoked before either putting a HBA offline or unloading the driver. | |
2383 | **/ | |
3772a991 JS |
2384 | void |
2385 | lpfc_stop_hba_timers(struct lpfc_hba *phba) | |
dea3101e | 2386 | { |
51ef4c26 | 2387 | lpfc_stop_vport_timers(phba->pport); |
2e0fef85 | 2388 | del_timer_sync(&phba->sli.mbox_tmo); |
92d7f7b0 | 2389 | del_timer_sync(&phba->fabric_block_timer); |
9399627f | 2390 | del_timer_sync(&phba->eratt_poll); |
3772a991 | 2391 | del_timer_sync(&phba->hb_tmofunc); |
1151e3ec JS |
2392 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2393 | del_timer_sync(&phba->rrq_tmr); | |
2394 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
2395 | } | |
3772a991 JS |
2396 | phba->hb_outstanding = 0; |
2397 | ||
2398 | switch (phba->pci_dev_grp) { | |
2399 | case LPFC_PCI_DEV_LP: | |
2400 | /* Stop any LightPulse device specific driver timers */ | |
2401 | del_timer_sync(&phba->fcp_poll_timer); | |
2402 | break; | |
2403 | case LPFC_PCI_DEV_OC: | |
2404 | /* Stop any OneConnect device sepcific driver timers */ | |
ecfd03c6 | 2405 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
3772a991 JS |
2406 | break; |
2407 | default: | |
2408 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2409 | "0297 Invalid device group (x%x)\n", | |
2410 | phba->pci_dev_grp); | |
2411 | break; | |
2412 | } | |
2e0fef85 | 2413 | return; |
dea3101e | 2414 | } |
2415 | ||
e59058c4 | 2416 | /** |
3621a710 | 2417 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
e59058c4 JS |
2418 | * @phba: pointer to lpfc hba data structure. |
2419 | * | |
2420 | * This routine marks a HBA's management interface as blocked. Once the HBA's | |
2421 | * management interface is marked as blocked, all the user space access to | |
2422 | * the HBA, whether they are from sysfs interface or libdfc interface will | |
2423 | * all be blocked. The HBA is set to block the management interface when the | |
2424 | * driver prepares the HBA interface for online or offline. | |
2425 | **/ | |
a6ababd2 AB |
2426 | static void |
2427 | lpfc_block_mgmt_io(struct lpfc_hba * phba) | |
2428 | { | |
2429 | unsigned long iflag; | |
6e7288d9 JS |
2430 | uint8_t actcmd = MBX_HEARTBEAT; |
2431 | unsigned long timeout; | |
2432 | ||
a183a15f | 2433 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
a6ababd2 AB |
2434 | spin_lock_irqsave(&phba->hbalock, iflag); |
2435 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; | |
a183a15f | 2436 | if (phba->sli.mbox_active) { |
6e7288d9 | 2437 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
a183a15f 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, | |
2442 | phba->sli.mbox_active) * 1000) + jiffies; | |
2443 | } | |
a6ababd2 | 2444 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a183a15f | 2445 | |
6e7288d9 JS |
2446 | /* Wait for the outstnading mailbox command to complete */ |
2447 | while (phba->sli.mbox_active) { | |
2448 | /* Check active mailbox complete status every 2ms */ | |
2449 | msleep(2); | |
2450 | if (time_after(jiffies, timeout)) { | |
2451 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2452 | "2813 Mgmt IO is Blocked %x " | |
2453 | "- mbox cmd %x still active\n", | |
2454 | phba->sli.sli_flag, actcmd); | |
2455 | break; | |
2456 | } | |
2457 | } | |
a6ababd2 AB |
2458 | } |
2459 | ||
e59058c4 | 2460 | /** |
3621a710 | 2461 | * lpfc_online - Initialize and bring a HBA online |
e59058c4 JS |
2462 | * @phba: pointer to lpfc hba data structure. |
2463 | * | |
2464 | * This routine initializes the HBA and brings a HBA online. During this | |
2465 | * process, the management interface is blocked to prevent user space access | |
2466 | * to the HBA interfering with the driver initialization. | |
2467 | * | |
2468 | * Return codes | |
2469 | * 0 - successful | |
2470 | * 1 - failed | |
2471 | **/ | |
dea3101e | 2472 | int |
2e0fef85 | 2473 | lpfc_online(struct lpfc_hba *phba) |
dea3101e | 2474 | { |
372bd282 | 2475 | struct lpfc_vport *vport; |
549e55cd JS |
2476 | struct lpfc_vport **vports; |
2477 | int i; | |
2e0fef85 | 2478 | |
dea3101e | 2479 | if (!phba) |
2480 | return 0; | |
372bd282 | 2481 | vport = phba->pport; |
dea3101e | 2482 | |
2e0fef85 | 2483 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
dea3101e | 2484 | return 0; |
2485 | ||
ed957684 | 2486 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 2487 | "0458 Bring Adapter online\n"); |
dea3101e | 2488 | |
46fa311e JS |
2489 | lpfc_block_mgmt_io(phba); |
2490 | ||
2491 | if (!lpfc_sli_queue_setup(phba)) { | |
2492 | lpfc_unblock_mgmt_io(phba); | |
dea3101e | 2493 | return 1; |
46fa311e | 2494 | } |
dea3101e | 2495 | |
da0436e9 JS |
2496 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2497 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ | |
2498 | lpfc_unblock_mgmt_io(phba); | |
2499 | return 1; | |
2500 | } | |
2501 | } else { | |
2502 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ | |
2503 | lpfc_unblock_mgmt_io(phba); | |
2504 | return 1; | |
2505 | } | |
46fa311e | 2506 | } |
dea3101e | 2507 | |
549e55cd JS |
2508 | vports = lpfc_create_vport_work_array(phba); |
2509 | if (vports != NULL) | |
da0436e9 | 2510 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd JS |
2511 | struct Scsi_Host *shost; |
2512 | shost = lpfc_shost_from_vport(vports[i]); | |
2513 | spin_lock_irq(shost->host_lock); | |
2514 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; | |
2515 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) | |
2516 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
1c6834a7 JS |
2517 | if (phba->sli_rev == LPFC_SLI_REV4) |
2518 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; | |
549e55cd JS |
2519 | spin_unlock_irq(shost->host_lock); |
2520 | } | |
09372820 | 2521 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2522 | |
46fa311e | 2523 | lpfc_unblock_mgmt_io(phba); |
dea3101e | 2524 | return 0; |
2525 | } | |
2526 | ||
e59058c4 | 2527 | /** |
3621a710 | 2528 | * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked |
e59058c4 JS |
2529 | * @phba: pointer to lpfc hba data structure. |
2530 | * | |
2531 | * This routine marks a HBA's management interface as not blocked. Once the | |
2532 | * HBA's management interface is marked as not blocked, all the user space | |
2533 | * access to the HBA, whether they are from sysfs interface or libdfc | |
2534 | * interface will be allowed. The HBA is set to block the management interface | |
2535 | * when the driver prepares the HBA interface for online or offline and then | |
2536 | * set to unblock the management interface afterwards. | |
2537 | **/ | |
46fa311e JS |
2538 | void |
2539 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) | |
2540 | { | |
2541 | unsigned long iflag; | |
2542 | ||
2e0fef85 JS |
2543 | spin_lock_irqsave(&phba->hbalock, iflag); |
2544 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; | |
2545 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
46fa311e JS |
2546 | } |
2547 | ||
e59058c4 | 2548 | /** |
3621a710 | 2549 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
e59058c4 JS |
2550 | * @phba: pointer to lpfc hba data structure. |
2551 | * | |
2552 | * This routine is invoked to prepare a HBA to be brought offline. It performs | |
2553 | * unregistration login to all the nodes on all vports and flushes the mailbox | |
2554 | * queue to make it ready to be brought offline. | |
2555 | **/ | |
46fa311e JS |
2556 | void |
2557 | lpfc_offline_prep(struct lpfc_hba * phba) | |
2558 | { | |
2e0fef85 | 2559 | struct lpfc_vport *vport = phba->pport; |
46fa311e | 2560 | struct lpfc_nodelist *ndlp, *next_ndlp; |
87af33fe | 2561 | struct lpfc_vport **vports; |
72100cc4 | 2562 | struct Scsi_Host *shost; |
87af33fe | 2563 | int i; |
dea3101e | 2564 | |
2e0fef85 | 2565 | if (vport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 2566 | return; |
dea3101e | 2567 | |
46fa311e | 2568 | lpfc_block_mgmt_io(phba); |
dea3101e | 2569 | |
2570 | lpfc_linkdown(phba); | |
2571 | ||
87af33fe JS |
2572 | /* Issue an unreg_login to all nodes on all vports */ |
2573 | vports = lpfc_create_vport_work_array(phba); | |
2574 | if (vports != NULL) { | |
da0436e9 | 2575 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
a8adb832 JS |
2576 | if (vports[i]->load_flag & FC_UNLOADING) |
2577 | continue; | |
72100cc4 JS |
2578 | shost = lpfc_shost_from_vport(vports[i]); |
2579 | spin_lock_irq(shost->host_lock); | |
c868595d | 2580 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
695a814e JS |
2581 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
2582 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; | |
72100cc4 | 2583 | spin_unlock_irq(shost->host_lock); |
695a814e | 2584 | |
87af33fe JS |
2585 | shost = lpfc_shost_from_vport(vports[i]); |
2586 | list_for_each_entry_safe(ndlp, next_ndlp, | |
2587 | &vports[i]->fc_nodes, | |
2588 | nlp_listp) { | |
e47c9093 JS |
2589 | if (!NLP_CHK_NODE_ACT(ndlp)) |
2590 | continue; | |
87af33fe JS |
2591 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
2592 | continue; | |
2593 | if (ndlp->nlp_type & NLP_FABRIC) { | |
2594 | lpfc_disc_state_machine(vports[i], ndlp, | |
2595 | NULL, NLP_EVT_DEVICE_RECOVERY); | |
2596 | lpfc_disc_state_machine(vports[i], ndlp, | |
2597 | NULL, NLP_EVT_DEVICE_RM); | |
2598 | } | |
2599 | spin_lock_irq(shost->host_lock); | |
2600 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | |
2601 | spin_unlock_irq(shost->host_lock); | |
2602 | lpfc_unreg_rpi(vports[i], ndlp); | |
2603 | } | |
2604 | } | |
2605 | } | |
09372820 | 2606 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2607 | |
04c68496 | 2608 | lpfc_sli_mbox_sys_shutdown(phba); |
46fa311e JS |
2609 | } |
2610 | ||
e59058c4 | 2611 | /** |
3621a710 | 2612 | * lpfc_offline - Bring a HBA offline |
e59058c4 JS |
2613 | * @phba: pointer to lpfc hba data structure. |
2614 | * | |
2615 | * This routine actually brings a HBA offline. It stops all the timers | |
2616 | * associated with the HBA, brings down the SLI layer, and eventually | |
2617 | * marks the HBA as in offline state for the upper layer protocol. | |
2618 | **/ | |
46fa311e | 2619 | void |
2e0fef85 | 2620 | lpfc_offline(struct lpfc_hba *phba) |
46fa311e | 2621 | { |
549e55cd JS |
2622 | struct Scsi_Host *shost; |
2623 | struct lpfc_vport **vports; | |
2624 | int i; | |
46fa311e | 2625 | |
549e55cd | 2626 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 2627 | return; |
688a8863 | 2628 | |
da0436e9 JS |
2629 | /* stop port and all timers associated with this hba */ |
2630 | lpfc_stop_port(phba); | |
51ef4c26 JS |
2631 | vports = lpfc_create_vport_work_array(phba); |
2632 | if (vports != NULL) | |
da0436e9 | 2633 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
51ef4c26 | 2634 | lpfc_stop_vport_timers(vports[i]); |
09372820 | 2635 | lpfc_destroy_vport_work_array(phba, vports); |
92d7f7b0 | 2636 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 2637 | "0460 Bring Adapter offline\n"); |
dea3101e | 2638 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
2639 | now. */ | |
2640 | lpfc_sli_hba_down(phba); | |
92d7f7b0 | 2641 | spin_lock_irq(&phba->hbalock); |
7054a606 | 2642 | phba->work_ha = 0; |
92d7f7b0 | 2643 | spin_unlock_irq(&phba->hbalock); |
549e55cd JS |
2644 | vports = lpfc_create_vport_work_array(phba); |
2645 | if (vports != NULL) | |
da0436e9 | 2646 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd | 2647 | shost = lpfc_shost_from_vport(vports[i]); |
549e55cd JS |
2648 | spin_lock_irq(shost->host_lock); |
2649 | vports[i]->work_port_events = 0; | |
2650 | vports[i]->fc_flag |= FC_OFFLINE_MODE; | |
2651 | spin_unlock_irq(shost->host_lock); | |
2652 | } | |
09372820 | 2653 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2654 | } |
2655 | ||
ff78d8f9 JS |
2656 | /** |
2657 | * lpfc_scsi_buf_update - Update the scsi_buffers that are already allocated. | |
2658 | * @phba: pointer to lpfc hba data structure. | |
2659 | * | |
2660 | * This routine goes through all the scsi buffers in the system and updates the | |
2661 | * Physical XRIs assigned to the SCSI buffer because these may change after any | |
2662 | * firmware reset | |
2663 | * | |
2664 | * Return codes | |
2665 | * 0 - successful (for now, it always returns 0) | |
2666 | **/ | |
2667 | int | |
2668 | lpfc_scsi_buf_update(struct lpfc_hba *phba) | |
2669 | { | |
2670 | struct lpfc_scsi_buf *sb, *sb_next; | |
2671 | ||
2672 | spin_lock_irq(&phba->hbalock); | |
2673 | spin_lock(&phba->scsi_buf_list_lock); | |
2674 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) | |
2675 | sb->cur_iocbq.sli4_xritag = | |
2676 | phba->sli4_hba.xri_ids[sb->cur_iocbq.sli4_lxritag]; | |
2677 | spin_unlock(&phba->scsi_buf_list_lock); | |
2678 | spin_unlock_irq(&phba->hbalock); | |
2679 | return 0; | |
2680 | } | |
2681 | ||
e59058c4 | 2682 | /** |
3621a710 | 2683 | * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists |
e59058c4 JS |
2684 | * @phba: pointer to lpfc hba data structure. |
2685 | * | |
2686 | * This routine is to free all the SCSI buffers and IOCBs from the driver | |
2687 | * list back to kernel. It is called from lpfc_pci_remove_one to free | |
2688 | * the internal resources before the device is removed from the system. | |
2689 | * | |
2690 | * Return codes | |
2691 | * 0 - successful (for now, it always returns 0) | |
2692 | **/ | |
dea3101e | 2693 | static int |
2e0fef85 | 2694 | lpfc_scsi_free(struct lpfc_hba *phba) |
dea3101e | 2695 | { |
2696 | struct lpfc_scsi_buf *sb, *sb_next; | |
2697 | struct lpfc_iocbq *io, *io_next; | |
2698 | ||
2e0fef85 | 2699 | spin_lock_irq(&phba->hbalock); |
dea3101e | 2700 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
1c6f4ef5 | 2701 | spin_lock(&phba->scsi_buf_list_lock); |
dea3101e | 2702 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { |
2703 | list_del(&sb->list); | |
2704 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, | |
92d7f7b0 | 2705 | sb->dma_handle); |
dea3101e | 2706 | kfree(sb); |
2707 | phba->total_scsi_bufs--; | |
2708 | } | |
1c6f4ef5 | 2709 | spin_unlock(&phba->scsi_buf_list_lock); |
dea3101e | 2710 | |
2711 | /* Release all the lpfc_iocbq entries maintained by this host. */ | |
2712 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { | |
2713 | list_del(&io->list); | |
2714 | kfree(io); | |
2715 | phba->total_iocbq_bufs--; | |
2716 | } | |
6d368e53 | 2717 | |
2e0fef85 | 2718 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 2719 | return 0; |
2720 | } | |
2721 | ||
e59058c4 | 2722 | /** |
3621a710 | 2723 | * lpfc_create_port - Create an FC port |
e59058c4 JS |
2724 | * @phba: pointer to lpfc hba data structure. |
2725 | * @instance: a unique integer ID to this FC port. | |
2726 | * @dev: pointer to the device data structure. | |
2727 | * | |
2728 | * This routine creates a FC port for the upper layer protocol. The FC port | |
2729 | * can be created on top of either a physical port or a virtual port provided | |
2730 | * by the HBA. This routine also allocates a SCSI host data structure (shost) | |
2731 | * and associates the FC port created before adding the shost into the SCSI | |
2732 | * layer. | |
2733 | * | |
2734 | * Return codes | |
2735 | * @vport - pointer to the virtual N_Port data structure. | |
2736 | * NULL - port create failed. | |
2737 | **/ | |
2e0fef85 | 2738 | struct lpfc_vport * |
3de2a653 | 2739 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
47a8617c | 2740 | { |
2e0fef85 JS |
2741 | struct lpfc_vport *vport; |
2742 | struct Scsi_Host *shost; | |
2743 | int error = 0; | |
47a8617c | 2744 | |
3de2a653 JS |
2745 | if (dev != &phba->pcidev->dev) |
2746 | shost = scsi_host_alloc(&lpfc_vport_template, | |
2747 | sizeof(struct lpfc_vport)); | |
2748 | else | |
2749 | shost = scsi_host_alloc(&lpfc_template, | |
2750 | sizeof(struct lpfc_vport)); | |
2e0fef85 JS |
2751 | if (!shost) |
2752 | goto out; | |
47a8617c | 2753 | |
2e0fef85 JS |
2754 | vport = (struct lpfc_vport *) shost->hostdata; |
2755 | vport->phba = phba; | |
2e0fef85 | 2756 | vport->load_flag |= FC_LOADING; |
92d7f7b0 | 2757 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
7f5f3d0d | 2758 | vport->fc_rscn_flush = 0; |
47a8617c | 2759 | |
3de2a653 | 2760 | lpfc_get_vport_cfgparam(vport); |
2e0fef85 JS |
2761 | shost->unique_id = instance; |
2762 | shost->max_id = LPFC_MAX_TARGET; | |
3de2a653 | 2763 | shost->max_lun = vport->cfg_max_luns; |
2e0fef85 JS |
2764 | shost->this_id = -1; |
2765 | shost->max_cmd_len = 16; | |
da0436e9 | 2766 | if (phba->sli_rev == LPFC_SLI_REV4) { |
28baac74 | 2767 | shost->dma_boundary = |
cb5172ea | 2768 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
da0436e9 JS |
2769 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
2770 | } | |
81301a9b | 2771 | |
47a8617c | 2772 | /* |
2e0fef85 JS |
2773 | * Set initial can_queue value since 0 is no longer supported and |
2774 | * scsi_add_host will fail. This will be adjusted later based on the | |
2775 | * max xri value determined in hba setup. | |
47a8617c | 2776 | */ |
2e0fef85 | 2777 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
3de2a653 | 2778 | if (dev != &phba->pcidev->dev) { |
92d7f7b0 JS |
2779 | shost->transportt = lpfc_vport_transport_template; |
2780 | vport->port_type = LPFC_NPIV_PORT; | |
2781 | } else { | |
2782 | shost->transportt = lpfc_transport_template; | |
2783 | vport->port_type = LPFC_PHYSICAL_PORT; | |
2784 | } | |
47a8617c | 2785 | |
2e0fef85 JS |
2786 | /* Initialize all internally managed lists. */ |
2787 | INIT_LIST_HEAD(&vport->fc_nodes); | |
da0436e9 | 2788 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
2e0fef85 | 2789 | spin_lock_init(&vport->work_port_lock); |
47a8617c | 2790 | |
2e0fef85 JS |
2791 | init_timer(&vport->fc_disctmo); |
2792 | vport->fc_disctmo.function = lpfc_disc_timeout; | |
92d7f7b0 | 2793 | vport->fc_disctmo.data = (unsigned long)vport; |
47a8617c | 2794 | |
2e0fef85 JS |
2795 | init_timer(&vport->fc_fdmitmo); |
2796 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; | |
92d7f7b0 | 2797 | vport->fc_fdmitmo.data = (unsigned long)vport; |
47a8617c | 2798 | |
2e0fef85 JS |
2799 | init_timer(&vport->els_tmofunc); |
2800 | vport->els_tmofunc.function = lpfc_els_timeout; | |
92d7f7b0 | 2801 | vport->els_tmofunc.data = (unsigned long)vport; |
92494144 JS |
2802 | |
2803 | init_timer(&vport->delayed_disc_tmo); | |
2804 | vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo; | |
2805 | vport->delayed_disc_tmo.data = (unsigned long)vport; | |
2806 | ||
d139b9bd | 2807 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
2e0fef85 JS |
2808 | if (error) |
2809 | goto out_put_shost; | |
47a8617c | 2810 | |
549e55cd | 2811 | spin_lock_irq(&phba->hbalock); |
2e0fef85 | 2812 | list_add_tail(&vport->listentry, &phba->port_list); |
549e55cd | 2813 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 2814 | return vport; |
47a8617c | 2815 | |
2e0fef85 JS |
2816 | out_put_shost: |
2817 | scsi_host_put(shost); | |
2818 | out: | |
2819 | return NULL; | |
47a8617c JS |
2820 | } |
2821 | ||
e59058c4 | 2822 | /** |
3621a710 | 2823 | * destroy_port - destroy an FC port |
e59058c4 JS |
2824 | * @vport: pointer to an lpfc virtual N_Port data structure. |
2825 | * | |
2826 | * This routine destroys a FC port from the upper layer protocol. All the | |
2827 | * resources associated with the port are released. | |
2828 | **/ | |
2e0fef85 JS |
2829 | void |
2830 | destroy_port(struct lpfc_vport *vport) | |
47a8617c | 2831 | { |
92d7f7b0 JS |
2832 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2833 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 2834 | |
858c9f6c | 2835 | lpfc_debugfs_terminate(vport); |
92d7f7b0 JS |
2836 | fc_remove_host(shost); |
2837 | scsi_remove_host(shost); | |
47a8617c | 2838 | |
92d7f7b0 JS |
2839 | spin_lock_irq(&phba->hbalock); |
2840 | list_del_init(&vport->listentry); | |
2841 | spin_unlock_irq(&phba->hbalock); | |
47a8617c | 2842 | |
92d7f7b0 | 2843 | lpfc_cleanup(vport); |
47a8617c | 2844 | return; |
47a8617c JS |
2845 | } |
2846 | ||
e59058c4 | 2847 | /** |
3621a710 | 2848 | * lpfc_get_instance - Get a unique integer ID |
e59058c4 JS |
2849 | * |
2850 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It | |
2851 | * uses the kernel idr facility to perform the task. | |
2852 | * | |
2853 | * Return codes: | |
2854 | * instance - a unique integer ID allocated as the new instance. | |
2855 | * -1 - lpfc get instance failed. | |
2856 | **/ | |
92d7f7b0 JS |
2857 | int |
2858 | lpfc_get_instance(void) | |
2859 | { | |
2860 | int instance = 0; | |
47a8617c | 2861 | |
92d7f7b0 JS |
2862 | /* Assign an unused number */ |
2863 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) | |
2864 | return -1; | |
2865 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) | |
2866 | return -1; | |
2867 | return instance; | |
47a8617c JS |
2868 | } |
2869 | ||
e59058c4 | 2870 | /** |
3621a710 | 2871 | * lpfc_scan_finished - method for SCSI layer to detect whether scan is done |
e59058c4 JS |
2872 | * @shost: pointer to SCSI host data structure. |
2873 | * @time: elapsed time of the scan in jiffies. | |
2874 | * | |
2875 | * This routine is called by the SCSI layer with a SCSI host to determine | |
2876 | * whether the scan host is finished. | |
2877 | * | |
2878 | * Note: there is no scan_start function as adapter initialization will have | |
2879 | * asynchronously kicked off the link initialization. | |
2880 | * | |
2881 | * Return codes | |
2882 | * 0 - SCSI host scan is not over yet. | |
2883 | * 1 - SCSI host scan is over. | |
2884 | **/ | |
47a8617c JS |
2885 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
2886 | { | |
2e0fef85 JS |
2887 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
2888 | struct lpfc_hba *phba = vport->phba; | |
858c9f6c | 2889 | int stat = 0; |
47a8617c | 2890 | |
858c9f6c JS |
2891 | spin_lock_irq(shost->host_lock); |
2892 | ||
51ef4c26 | 2893 | if (vport->load_flag & FC_UNLOADING) { |
858c9f6c JS |
2894 | stat = 1; |
2895 | goto finished; | |
2896 | } | |
2e0fef85 JS |
2897 | if (time >= 30 * HZ) { |
2898 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
2899 | "0461 Scanning longer than 30 " |
2900 | "seconds. Continuing initialization\n"); | |
858c9f6c | 2901 | stat = 1; |
47a8617c | 2902 | goto finished; |
2e0fef85 JS |
2903 | } |
2904 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { | |
2905 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
2906 | "0465 Link down longer than 15 " |
2907 | "seconds. Continuing initialization\n"); | |
858c9f6c | 2908 | stat = 1; |
47a8617c | 2909 | goto finished; |
2e0fef85 | 2910 | } |
47a8617c | 2911 | |
2e0fef85 | 2912 | if (vport->port_state != LPFC_VPORT_READY) |
858c9f6c | 2913 | goto finished; |
2e0fef85 | 2914 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
858c9f6c | 2915 | goto finished; |
2e0fef85 | 2916 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
858c9f6c | 2917 | goto finished; |
2e0fef85 | 2918 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
858c9f6c JS |
2919 | goto finished; |
2920 | ||
2921 | stat = 1; | |
47a8617c JS |
2922 | |
2923 | finished: | |
858c9f6c JS |
2924 | spin_unlock_irq(shost->host_lock); |
2925 | return stat; | |
92d7f7b0 | 2926 | } |
47a8617c | 2927 | |
e59058c4 | 2928 | /** |
3621a710 | 2929 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
e59058c4 JS |
2930 | * @shost: pointer to SCSI host data structure. |
2931 | * | |
2932 | * This routine initializes a given SCSI host attributes on a FC port. The | |
2933 | * SCSI host can be either on top of a physical port or a virtual port. | |
2934 | **/ | |
92d7f7b0 JS |
2935 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
2936 | { | |
2937 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2938 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 2939 | /* |
2e0fef85 | 2940 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
47a8617c JS |
2941 | */ |
2942 | ||
2e0fef85 JS |
2943 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
2944 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
47a8617c JS |
2945 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
2946 | ||
2947 | memset(fc_host_supported_fc4s(shost), 0, | |
2e0fef85 | 2948 | sizeof(fc_host_supported_fc4s(shost))); |
47a8617c JS |
2949 | fc_host_supported_fc4s(shost)[2] = 1; |
2950 | fc_host_supported_fc4s(shost)[7] = 1; | |
2951 | ||
92d7f7b0 JS |
2952 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
2953 | sizeof fc_host_symbolic_name(shost)); | |
47a8617c JS |
2954 | |
2955 | fc_host_supported_speeds(shost) = 0; | |
88a2cfbb JS |
2956 | if (phba->lmt & LMT_16Gb) |
2957 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; | |
47a8617c JS |
2958 | if (phba->lmt & LMT_10Gb) |
2959 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; | |
a8adb832 JS |
2960 | if (phba->lmt & LMT_8Gb) |
2961 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; | |
47a8617c JS |
2962 | if (phba->lmt & LMT_4Gb) |
2963 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; | |
2964 | if (phba->lmt & LMT_2Gb) | |
2965 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; | |
2966 | if (phba->lmt & LMT_1Gb) | |
2967 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; | |
2968 | ||
2969 | fc_host_maxframe_size(shost) = | |
2e0fef85 JS |
2970 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
2971 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; | |
47a8617c | 2972 | |
0af5d708 MC |
2973 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
2974 | ||
47a8617c JS |
2975 | /* This value is also unchanging */ |
2976 | memset(fc_host_active_fc4s(shost), 0, | |
2e0fef85 | 2977 | sizeof(fc_host_active_fc4s(shost))); |
47a8617c JS |
2978 | fc_host_active_fc4s(shost)[2] = 1; |
2979 | fc_host_active_fc4s(shost)[7] = 1; | |
2980 | ||
92d7f7b0 | 2981 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
47a8617c | 2982 | spin_lock_irq(shost->host_lock); |
51ef4c26 | 2983 | vport->load_flag &= ~FC_LOADING; |
47a8617c | 2984 | spin_unlock_irq(shost->host_lock); |
47a8617c | 2985 | } |
dea3101e | 2986 | |
e59058c4 | 2987 | /** |
da0436e9 | 2988 | * lpfc_stop_port_s3 - Stop SLI3 device port |
e59058c4 JS |
2989 | * @phba: pointer to lpfc hba data structure. |
2990 | * | |
da0436e9 JS |
2991 | * This routine is invoked to stop an SLI3 device port, it stops the device |
2992 | * from generating interrupts and stops the device driver's timers for the | |
2993 | * device. | |
e59058c4 | 2994 | **/ |
da0436e9 JS |
2995 | static void |
2996 | lpfc_stop_port_s3(struct lpfc_hba *phba) | |
db2378e0 | 2997 | { |
da0436e9 JS |
2998 | /* Clear all interrupt enable conditions */ |
2999 | writel(0, phba->HCregaddr); | |
3000 | readl(phba->HCregaddr); /* flush */ | |
3001 | /* Clear all pending interrupts */ | |
3002 | writel(0xffffffff, phba->HAregaddr); | |
3003 | readl(phba->HAregaddr); /* flush */ | |
db2378e0 | 3004 | |
da0436e9 JS |
3005 | /* Reset some HBA SLI setup states */ |
3006 | lpfc_stop_hba_timers(phba); | |
3007 | phba->pport->work_port_events = 0; | |
3008 | } | |
db2378e0 | 3009 | |
da0436e9 JS |
3010 | /** |
3011 | * lpfc_stop_port_s4 - Stop SLI4 device port | |
3012 | * @phba: pointer to lpfc hba data structure. | |
3013 | * | |
3014 | * This routine is invoked to stop an SLI4 device port, it stops the device | |
3015 | * from generating interrupts and stops the device driver's timers for the | |
3016 | * device. | |
3017 | **/ | |
3018 | static void | |
3019 | lpfc_stop_port_s4(struct lpfc_hba *phba) | |
3020 | { | |
3021 | /* Reset some HBA SLI4 setup states */ | |
3022 | lpfc_stop_hba_timers(phba); | |
3023 | phba->pport->work_port_events = 0; | |
3024 | phba->sli4_hba.intr_enable = 0; | |
da0436e9 | 3025 | } |
9399627f | 3026 | |
da0436e9 JS |
3027 | /** |
3028 | * lpfc_stop_port - Wrapper function for stopping hba port | |
3029 | * @phba: Pointer to HBA context object. | |
3030 | * | |
3031 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from | |
3032 | * the API jump table function pointer from the lpfc_hba struct. | |
3033 | **/ | |
3034 | void | |
3035 | lpfc_stop_port(struct lpfc_hba *phba) | |
3036 | { | |
3037 | phba->lpfc_stop_port(phba); | |
3038 | } | |
db2378e0 | 3039 | |
ecfd03c6 JS |
3040 | /** |
3041 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer | |
3042 | * @phba: Pointer to hba for which this call is being executed. | |
3043 | * | |
3044 | * This routine starts the timer waiting for the FCF rediscovery to complete. | |
3045 | **/ | |
3046 | void | |
3047 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) | |
3048 | { | |
3049 | unsigned long fcf_redisc_wait_tmo = | |
3050 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); | |
3051 | /* Start fcf rediscovery wait period timer */ | |
3052 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); | |
3053 | spin_lock_irq(&phba->hbalock); | |
3054 | /* Allow action to new fcf asynchronous event */ | |
3055 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); | |
3056 | /* Mark the FCF rediscovery pending state */ | |
3057 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; | |
3058 | spin_unlock_irq(&phba->hbalock); | |
3059 | } | |
3060 | ||
3061 | /** | |
3062 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout | |
3063 | * @ptr: Map to lpfc_hba data structure pointer. | |
3064 | * | |
3065 | * This routine is invoked when waiting for FCF table rediscover has been | |
3066 | * timed out. If new FCF record(s) has (have) been discovered during the | |
3067 | * wait period, a new FCF event shall be added to the FCOE async event | |
3068 | * list, and then worker thread shall be waked up for processing from the | |
3069 | * worker thread context. | |
3070 | **/ | |
3071 | void | |
3072 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) | |
3073 | { | |
3074 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; | |
3075 | ||
3076 | /* Don't send FCF rediscovery event if timer cancelled */ | |
3077 | spin_lock_irq(&phba->hbalock); | |
3078 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
3079 | spin_unlock_irq(&phba->hbalock); | |
3080 | return; | |
3081 | } | |
3082 | /* Clear FCF rediscovery timer pending flag */ | |
3083 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; | |
3084 | /* FCF rediscovery event to worker thread */ | |
3085 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; | |
3086 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 | 3087 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 3088 | "2776 FCF rediscover quiescent timer expired\n"); |
ecfd03c6 JS |
3089 | /* wake up worker thread */ |
3090 | lpfc_worker_wake_up(phba); | |
3091 | } | |
3092 | ||
e59058c4 | 3093 | /** |
da0436e9 | 3094 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
e59058c4 | 3095 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3096 | * @acqe_link: pointer to the async link completion queue entry. |
e59058c4 | 3097 | * |
da0436e9 JS |
3098 | * This routine is to parse the SLI4 link-attention link fault code and |
3099 | * translate it into the base driver's read link attention mailbox command | |
3100 | * status. | |
3101 | * | |
3102 | * Return: Link-attention status in terms of base driver's coding. | |
e59058c4 | 3103 | **/ |
da0436e9 JS |
3104 | static uint16_t |
3105 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, | |
3106 | struct lpfc_acqe_link *acqe_link) | |
db2378e0 | 3107 | { |
da0436e9 | 3108 | uint16_t latt_fault; |
9399627f | 3109 | |
da0436e9 JS |
3110 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
3111 | case LPFC_ASYNC_LINK_FAULT_NONE: | |
3112 | case LPFC_ASYNC_LINK_FAULT_LOCAL: | |
3113 | case LPFC_ASYNC_LINK_FAULT_REMOTE: | |
3114 | latt_fault = 0; | |
3115 | break; | |
3116 | default: | |
3117 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3118 | "0398 Invalid link fault code: x%x\n", | |
3119 | bf_get(lpfc_acqe_link_fault, acqe_link)); | |
3120 | latt_fault = MBXERR_ERROR; | |
3121 | break; | |
3122 | } | |
3123 | return latt_fault; | |
db2378e0 JS |
3124 | } |
3125 | ||
5b75da2f | 3126 | /** |
da0436e9 | 3127 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
5b75da2f | 3128 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3129 | * @acqe_link: pointer to the async link completion queue entry. |
5b75da2f | 3130 | * |
da0436e9 JS |
3131 | * This routine is to parse the SLI4 link attention type and translate it |
3132 | * into the base driver's link attention type coding. | |
5b75da2f | 3133 | * |
da0436e9 JS |
3134 | * Return: Link attention type in terms of base driver's coding. |
3135 | **/ | |
3136 | static uint8_t | |
3137 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, | |
3138 | struct lpfc_acqe_link *acqe_link) | |
5b75da2f | 3139 | { |
da0436e9 | 3140 | uint8_t att_type; |
5b75da2f | 3141 | |
da0436e9 JS |
3142 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
3143 | case LPFC_ASYNC_LINK_STATUS_DOWN: | |
3144 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: | |
76a95d75 | 3145 | att_type = LPFC_ATT_LINK_DOWN; |
da0436e9 JS |
3146 | break; |
3147 | case LPFC_ASYNC_LINK_STATUS_UP: | |
3148 | /* Ignore physical link up events - wait for logical link up */ | |
76a95d75 | 3149 | att_type = LPFC_ATT_RESERVED; |
da0436e9 JS |
3150 | break; |
3151 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: | |
76a95d75 | 3152 | att_type = LPFC_ATT_LINK_UP; |
da0436e9 JS |
3153 | break; |
3154 | default: | |
3155 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3156 | "0399 Invalid link attention type: x%x\n", | |
3157 | bf_get(lpfc_acqe_link_status, acqe_link)); | |
76a95d75 | 3158 | att_type = LPFC_ATT_RESERVED; |
da0436e9 | 3159 | break; |
5b75da2f | 3160 | } |
da0436e9 | 3161 | return att_type; |
5b75da2f JS |
3162 | } |
3163 | ||
3164 | /** | |
da0436e9 | 3165 | * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed |
5b75da2f | 3166 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3167 | * @acqe_link: pointer to the async link completion queue entry. |
5b75da2f | 3168 | * |
da0436e9 JS |
3169 | * This routine is to parse the SLI4 link-attention link speed and translate |
3170 | * it into the base driver's link-attention link speed coding. | |
3171 | * | |
3172 | * Return: Link-attention link speed in terms of base driver's coding. | |
3173 | **/ | |
3174 | static uint8_t | |
3175 | lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba, | |
3176 | struct lpfc_acqe_link *acqe_link) | |
5b75da2f | 3177 | { |
da0436e9 JS |
3178 | uint8_t link_speed; |
3179 | ||
3180 | switch (bf_get(lpfc_acqe_link_speed, acqe_link)) { | |
3181 | case LPFC_ASYNC_LINK_SPEED_ZERO: | |
da0436e9 | 3182 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
da0436e9 | 3183 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
76a95d75 | 3184 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
da0436e9 JS |
3185 | break; |
3186 | case LPFC_ASYNC_LINK_SPEED_1GBPS: | |
76a95d75 | 3187 | link_speed = LPFC_LINK_SPEED_1GHZ; |
da0436e9 JS |
3188 | break; |
3189 | case LPFC_ASYNC_LINK_SPEED_10GBPS: | |
76a95d75 | 3190 | link_speed = LPFC_LINK_SPEED_10GHZ; |
da0436e9 JS |
3191 | break; |
3192 | default: | |
3193 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3194 | "0483 Invalid link-attention link speed: x%x\n", | |
3195 | bf_get(lpfc_acqe_link_speed, acqe_link)); | |
76a95d75 | 3196 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
da0436e9 JS |
3197 | break; |
3198 | } | |
3199 | return link_speed; | |
3200 | } | |
3201 | ||
3202 | /** | |
70f3c073 | 3203 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
da0436e9 JS |
3204 | * @phba: pointer to lpfc hba data structure. |
3205 | * @acqe_link: pointer to the async link completion queue entry. | |
3206 | * | |
70f3c073 | 3207 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
da0436e9 JS |
3208 | **/ |
3209 | static void | |
3210 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, | |
3211 | struct lpfc_acqe_link *acqe_link) | |
3212 | { | |
3213 | struct lpfc_dmabuf *mp; | |
3214 | LPFC_MBOXQ_t *pmb; | |
3215 | MAILBOX_t *mb; | |
76a95d75 | 3216 | struct lpfc_mbx_read_top *la; |
da0436e9 | 3217 | uint8_t att_type; |
76a95d75 | 3218 | int rc; |
da0436e9 JS |
3219 | |
3220 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); | |
76a95d75 | 3221 | if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP) |
da0436e9 | 3222 | return; |
32b9793f | 3223 | phba->fcoe_eventtag = acqe_link->event_tag; |
da0436e9 JS |
3224 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3225 | if (!pmb) { | |
3226 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3227 | "0395 The mboxq allocation failed\n"); | |
3228 | return; | |
3229 | } | |
3230 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
3231 | if (!mp) { | |
3232 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3233 | "0396 The lpfc_dmabuf allocation failed\n"); | |
3234 | goto out_free_pmb; | |
3235 | } | |
3236 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
3237 | if (!mp->virt) { | |
3238 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3239 | "0397 The mbuf allocation failed\n"); | |
3240 | goto out_free_dmabuf; | |
3241 | } | |
3242 | ||
3243 | /* Cleanup any outstanding ELS commands */ | |
3244 | lpfc_els_flush_all_cmd(phba); | |
3245 | ||
3246 | /* Block ELS IOCBs until we have done process link event */ | |
3247 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
3248 | ||
3249 | /* Update link event statistics */ | |
3250 | phba->sli.slistat.link_event++; | |
3251 | ||
76a95d75 JS |
3252 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
3253 | lpfc_read_topology(phba, pmb, mp); | |
3254 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
da0436e9 JS |
3255 | pmb->vport = phba->pport; |
3256 | ||
da0436e9 JS |
3257 | /* Keep the link status for extra SLI4 state machine reference */ |
3258 | phba->sli4_hba.link_state.speed = | |
3259 | bf_get(lpfc_acqe_link_speed, acqe_link); | |
3260 | phba->sli4_hba.link_state.duplex = | |
3261 | bf_get(lpfc_acqe_link_duplex, acqe_link); | |
3262 | phba->sli4_hba.link_state.status = | |
3263 | bf_get(lpfc_acqe_link_status, acqe_link); | |
70f3c073 JS |
3264 | phba->sli4_hba.link_state.type = |
3265 | bf_get(lpfc_acqe_link_type, acqe_link); | |
3266 | phba->sli4_hba.link_state.number = | |
3267 | bf_get(lpfc_acqe_link_number, acqe_link); | |
da0436e9 JS |
3268 | phba->sli4_hba.link_state.fault = |
3269 | bf_get(lpfc_acqe_link_fault, acqe_link); | |
65467b6b | 3270 | phba->sli4_hba.link_state.logical_speed = |
70f3c073 JS |
3271 | bf_get(lpfc_acqe_logical_link_speed, acqe_link); |
3272 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
c31098ce JS |
3273 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
3274 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " | |
3275 | "Logical speed:%dMbps Fault:%d\n", | |
70f3c073 JS |
3276 | phba->sli4_hba.link_state.speed, |
3277 | phba->sli4_hba.link_state.topology, | |
3278 | phba->sli4_hba.link_state.status, | |
3279 | phba->sli4_hba.link_state.type, | |
3280 | phba->sli4_hba.link_state.number, | |
3281 | phba->sli4_hba.link_state.logical_speed * 10, | |
3282 | phba->sli4_hba.link_state.fault); | |
76a95d75 JS |
3283 | /* |
3284 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch | |
3285 | * topology info. Note: Optional for non FC-AL ports. | |
3286 | */ | |
3287 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { | |
3288 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3289 | if (rc == MBX_NOT_FINISHED) | |
3290 | goto out_free_dmabuf; | |
3291 | return; | |
3292 | } | |
3293 | /* | |
3294 | * For FCoE Mode: fill in all the topology information we need and call | |
3295 | * the READ_TOPOLOGY completion routine to continue without actually | |
3296 | * sending the READ_TOPOLOGY mailbox command to the port. | |
3297 | */ | |
3298 | /* Parse and translate status field */ | |
3299 | mb = &pmb->u.mb; | |
3300 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); | |
3301 | ||
3302 | /* Parse and translate link attention fields */ | |
3303 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; | |
3304 | la->eventTag = acqe_link->event_tag; | |
3305 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); | |
3306 | bf_set(lpfc_mbx_read_top_link_spd, la, | |
3307 | lpfc_sli4_parse_latt_link_speed(phba, acqe_link)); | |
3308 | ||
3309 | /* Fake the the following irrelvant fields */ | |
3310 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); | |
3311 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); | |
3312 | bf_set(lpfc_mbx_read_top_il, la, 0); | |
3313 | bf_set(lpfc_mbx_read_top_pb, la, 0); | |
3314 | bf_set(lpfc_mbx_read_top_fa, la, 0); | |
3315 | bf_set(lpfc_mbx_read_top_mm, la, 0); | |
da0436e9 JS |
3316 | |
3317 | /* Invoke the lpfc_handle_latt mailbox command callback function */ | |
76a95d75 | 3318 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
da0436e9 | 3319 | |
5b75da2f | 3320 | return; |
da0436e9 JS |
3321 | |
3322 | out_free_dmabuf: | |
3323 | kfree(mp); | |
3324 | out_free_pmb: | |
3325 | mempool_free(pmb, phba->mbox_mem_pool); | |
3326 | } | |
3327 | ||
70f3c073 JS |
3328 | /** |
3329 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event | |
3330 | * @phba: pointer to lpfc hba data structure. | |
3331 | * @acqe_fc: pointer to the async fc completion queue entry. | |
3332 | * | |
3333 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log | |
3334 | * that the event was received and then issue a read_topology mailbox command so | |
3335 | * that the rest of the driver will treat it the same as SLI3. | |
3336 | **/ | |
3337 | static void | |
3338 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) | |
3339 | { | |
3340 | struct lpfc_dmabuf *mp; | |
3341 | LPFC_MBOXQ_t *pmb; | |
3342 | int rc; | |
3343 | ||
3344 | if (bf_get(lpfc_trailer_type, acqe_fc) != | |
3345 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { | |
3346 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3347 | "2895 Non FC link Event detected.(%d)\n", | |
3348 | bf_get(lpfc_trailer_type, acqe_fc)); | |
3349 | return; | |
3350 | } | |
3351 | /* Keep the link status for extra SLI4 state machine reference */ | |
3352 | phba->sli4_hba.link_state.speed = | |
3353 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc); | |
3354 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; | |
3355 | phba->sli4_hba.link_state.topology = | |
3356 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); | |
3357 | phba->sli4_hba.link_state.status = | |
3358 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); | |
3359 | phba->sli4_hba.link_state.type = | |
3360 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); | |
3361 | phba->sli4_hba.link_state.number = | |
3362 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); | |
3363 | phba->sli4_hba.link_state.fault = | |
3364 | bf_get(lpfc_acqe_link_fault, acqe_fc); | |
3365 | phba->sli4_hba.link_state.logical_speed = | |
3366 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc); | |
3367 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3368 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " | |
3369 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" | |
3370 | "%dMbps Fault:%d\n", | |
3371 | phba->sli4_hba.link_state.speed, | |
3372 | phba->sli4_hba.link_state.topology, | |
3373 | phba->sli4_hba.link_state.status, | |
3374 | phba->sli4_hba.link_state.type, | |
3375 | phba->sli4_hba.link_state.number, | |
3376 | phba->sli4_hba.link_state.logical_speed * 10, | |
3377 | phba->sli4_hba.link_state.fault); | |
3378 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
3379 | if (!pmb) { | |
3380 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3381 | "2897 The mboxq allocation failed\n"); | |
3382 | return; | |
3383 | } | |
3384 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
3385 | if (!mp) { | |
3386 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3387 | "2898 The lpfc_dmabuf allocation failed\n"); | |
3388 | goto out_free_pmb; | |
3389 | } | |
3390 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
3391 | if (!mp->virt) { | |
3392 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3393 | "2899 The mbuf allocation failed\n"); | |
3394 | goto out_free_dmabuf; | |
3395 | } | |
3396 | ||
3397 | /* Cleanup any outstanding ELS commands */ | |
3398 | lpfc_els_flush_all_cmd(phba); | |
3399 | ||
3400 | /* Block ELS IOCBs until we have done process link event */ | |
3401 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
3402 | ||
3403 | /* Update link event statistics */ | |
3404 | phba->sli.slistat.link_event++; | |
3405 | ||
3406 | /* Create lpfc_handle_latt mailbox command from link ACQE */ | |
3407 | lpfc_read_topology(phba, pmb, mp); | |
3408 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
3409 | pmb->vport = phba->pport; | |
3410 | ||
3411 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3412 | if (rc == MBX_NOT_FINISHED) | |
3413 | goto out_free_dmabuf; | |
3414 | return; | |
3415 | ||
3416 | out_free_dmabuf: | |
3417 | kfree(mp); | |
3418 | out_free_pmb: | |
3419 | mempool_free(pmb, phba->mbox_mem_pool); | |
3420 | } | |
3421 | ||
3422 | /** | |
3423 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event | |
3424 | * @phba: pointer to lpfc hba data structure. | |
3425 | * @acqe_fc: pointer to the async SLI completion queue entry. | |
3426 | * | |
3427 | * This routine is to handle the SLI4 asynchronous SLI events. | |
3428 | **/ | |
3429 | static void | |
3430 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) | |
3431 | { | |
3432 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3433 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" | |
3434 | "x%08x SLI Event Type:%d", | |
3435 | acqe_sli->event_data1, acqe_sli->event_data2, | |
3436 | bf_get(lpfc_trailer_type, acqe_sli)); | |
3437 | return; | |
3438 | } | |
3439 | ||
fc2b989b JS |
3440 | /** |
3441 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport | |
3442 | * @vport: pointer to vport data structure. | |
3443 | * | |
3444 | * This routine is to perform Clear Virtual Link (CVL) on a vport in | |
3445 | * response to a CVL event. | |
3446 | * | |
3447 | * Return the pointer to the ndlp with the vport if successful, otherwise | |
3448 | * return NULL. | |
3449 | **/ | |
3450 | static struct lpfc_nodelist * | |
3451 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) | |
3452 | { | |
3453 | struct lpfc_nodelist *ndlp; | |
3454 | struct Scsi_Host *shost; | |
3455 | struct lpfc_hba *phba; | |
3456 | ||
3457 | if (!vport) | |
3458 | return NULL; | |
fc2b989b JS |
3459 | phba = vport->phba; |
3460 | if (!phba) | |
3461 | return NULL; | |
78730cfe JS |
3462 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
3463 | if (!ndlp) { | |
3464 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | |
3465 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
3466 | if (!ndlp) | |
3467 | return 0; | |
3468 | lpfc_nlp_init(vport, ndlp, Fabric_DID); | |
3469 | /* Set the node type */ | |
3470 | ndlp->nlp_type |= NLP_FABRIC; | |
3471 | /* Put ndlp onto node list */ | |
3472 | lpfc_enqueue_node(vport, ndlp); | |
3473 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
3474 | /* re-setup ndlp without removing from node list */ | |
3475 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
3476 | if (!ndlp) | |
3477 | return 0; | |
3478 | } | |
63e801ce JS |
3479 | if ((phba->pport->port_state < LPFC_FLOGI) && |
3480 | (phba->pport->port_state != LPFC_VPORT_FAILED)) | |
fc2b989b JS |
3481 | return NULL; |
3482 | /* If virtual link is not yet instantiated ignore CVL */ | |
63e801ce JS |
3483 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
3484 | && (vport->port_state != LPFC_VPORT_FAILED)) | |
fc2b989b JS |
3485 | return NULL; |
3486 | shost = lpfc_shost_from_vport(vport); | |
3487 | if (!shost) | |
3488 | return NULL; | |
3489 | lpfc_linkdown_port(vport); | |
3490 | lpfc_cleanup_pending_mbox(vport); | |
3491 | spin_lock_irq(shost->host_lock); | |
3492 | vport->fc_flag |= FC_VPORT_CVL_RCVD; | |
3493 | spin_unlock_irq(shost->host_lock); | |
3494 | ||
3495 | return ndlp; | |
3496 | } | |
3497 | ||
3498 | /** | |
3499 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports | |
3500 | * @vport: pointer to lpfc hba data structure. | |
3501 | * | |
3502 | * This routine is to perform Clear Virtual Link (CVL) on all vports in | |
3503 | * response to a FCF dead event. | |
3504 | **/ | |
3505 | static void | |
3506 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) | |
3507 | { | |
3508 | struct lpfc_vport **vports; | |
3509 | int i; | |
3510 | ||
3511 | vports = lpfc_create_vport_work_array(phba); | |
3512 | if (vports) | |
3513 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) | |
3514 | lpfc_sli4_perform_vport_cvl(vports[i]); | |
3515 | lpfc_destroy_vport_work_array(phba, vports); | |
3516 | } | |
3517 | ||
da0436e9 | 3518 | /** |
76a95d75 | 3519 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
da0436e9 JS |
3520 | * @phba: pointer to lpfc hba data structure. |
3521 | * @acqe_link: pointer to the async fcoe completion queue entry. | |
3522 | * | |
3523 | * This routine is to handle the SLI4 asynchronous fcoe event. | |
3524 | **/ | |
3525 | static void | |
76a95d75 | 3526 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
70f3c073 | 3527 | struct lpfc_acqe_fip *acqe_fip) |
da0436e9 | 3528 | { |
70f3c073 | 3529 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
da0436e9 | 3530 | int rc; |
6669f9bb JS |
3531 | struct lpfc_vport *vport; |
3532 | struct lpfc_nodelist *ndlp; | |
3533 | struct Scsi_Host *shost; | |
695a814e JS |
3534 | int active_vlink_present; |
3535 | struct lpfc_vport **vports; | |
3536 | int i; | |
da0436e9 | 3537 | |
70f3c073 JS |
3538 | phba->fc_eventTag = acqe_fip->event_tag; |
3539 | phba->fcoe_eventtag = acqe_fip->event_tag; | |
da0436e9 | 3540 | switch (event_type) { |
70f3c073 JS |
3541 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
3542 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: | |
3543 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) | |
999d813f JS |
3544 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
3545 | LOG_DISCOVERY, | |
a93ff37a JS |
3546 | "2546 New FCF event, evt_tag:x%x, " |
3547 | "index:x%x\n", | |
70f3c073 JS |
3548 | acqe_fip->event_tag, |
3549 | acqe_fip->index); | |
999d813f JS |
3550 | else |
3551 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | | |
3552 | LOG_DISCOVERY, | |
a93ff37a JS |
3553 | "2788 FCF param modified event, " |
3554 | "evt_tag:x%x, index:x%x\n", | |
70f3c073 JS |
3555 | acqe_fip->event_tag, |
3556 | acqe_fip->index); | |
38b92ef8 | 3557 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
0c9ab6f5 JS |
3558 | /* |
3559 | * During period of FCF discovery, read the FCF | |
3560 | * table record indexed by the event to update | |
a93ff37a | 3561 | * FCF roundrobin failover eligible FCF bmask. |
0c9ab6f5 JS |
3562 | */ |
3563 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | | |
3564 | LOG_DISCOVERY, | |
a93ff37a JS |
3565 | "2779 Read FCF (x%x) for updating " |
3566 | "roundrobin FCF failover bmask\n", | |
70f3c073 JS |
3567 | acqe_fip->index); |
3568 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); | |
0c9ab6f5 | 3569 | } |
38b92ef8 JS |
3570 | |
3571 | /* If the FCF discovery is in progress, do nothing. */ | |
3804dc84 | 3572 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 3573 | if (phba->hba_flag & FCF_TS_INPROG) { |
38b92ef8 JS |
3574 | spin_unlock_irq(&phba->hbalock); |
3575 | break; | |
3576 | } | |
3577 | /* If fast FCF failover rescan event is pending, do nothing */ | |
3578 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { | |
3579 | spin_unlock_irq(&phba->hbalock); | |
3580 | break; | |
3581 | } | |
3582 | ||
3583 | /* If the FCF has been in discovered state, do nothing. */ | |
3804dc84 JS |
3584 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
3585 | spin_unlock_irq(&phba->hbalock); | |
3586 | break; | |
3587 | } | |
3588 | spin_unlock_irq(&phba->hbalock); | |
38b92ef8 | 3589 | |
0c9ab6f5 JS |
3590 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
3591 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, | |
a93ff37a JS |
3592 | "2770 Start FCF table scan per async FCF " |
3593 | "event, evt_tag:x%x, index:x%x\n", | |
70f3c073 | 3594 | acqe_fip->event_tag, acqe_fip->index); |
0c9ab6f5 JS |
3595 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
3596 | LPFC_FCOE_FCF_GET_FIRST); | |
da0436e9 | 3597 | if (rc) |
0c9ab6f5 JS |
3598 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
3599 | "2547 Issue FCF scan read FCF mailbox " | |
a93ff37a | 3600 | "command failed (x%x)\n", rc); |
da0436e9 JS |
3601 | break; |
3602 | ||
70f3c073 | 3603 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
da0436e9 | 3604 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e4e74273 | 3605 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
70f3c073 JS |
3606 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
3607 | acqe_fip->event_tag); | |
da0436e9 JS |
3608 | break; |
3609 | ||
70f3c073 | 3610 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
0c9ab6f5 | 3611 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
a93ff37a | 3612 | "2549 FCF (x%x) disconnected from network, " |
70f3c073 | 3613 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
38b92ef8 JS |
3614 | /* |
3615 | * If we are in the middle of FCF failover process, clear | |
3616 | * the corresponding FCF bit in the roundrobin bitmap. | |
da0436e9 | 3617 | */ |
fc2b989b | 3618 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3619 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
fc2b989b | 3620 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 | 3621 | /* Update FLOGI FCF failover eligible FCF bmask */ |
70f3c073 | 3622 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
fc2b989b JS |
3623 | break; |
3624 | } | |
38b92ef8 JS |
3625 | spin_unlock_irq(&phba->hbalock); |
3626 | ||
3627 | /* If the event is not for currently used fcf do nothing */ | |
70f3c073 | 3628 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
38b92ef8 JS |
3629 | break; |
3630 | ||
3631 | /* | |
3632 | * Otherwise, request the port to rediscover the entire FCF | |
3633 | * table for a fast recovery from case that the current FCF | |
3634 | * is no longer valid as we are not in the middle of FCF | |
3635 | * failover process already. | |
3636 | */ | |
3637 | spin_lock_irq(&phba->hbalock); | |
fc2b989b | 3638 | /* Mark the fast failover process in progress */ |
0c9ab6f5 | 3639 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
fc2b989b | 3640 | spin_unlock_irq(&phba->hbalock); |
38b92ef8 | 3641 | |
0c9ab6f5 JS |
3642 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
3643 | "2771 Start FCF fast failover process due to " | |
3644 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " | |
70f3c073 | 3645 | "\n", acqe_fip->event_tag, acqe_fip->index); |
fc2b989b JS |
3646 | rc = lpfc_sli4_redisc_fcf_table(phba); |
3647 | if (rc) { | |
0c9ab6f5 JS |
3648 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
3649 | LOG_DISCOVERY, | |
3650 | "2772 Issue FCF rediscover mabilbox " | |
3651 | "command failed, fail through to FCF " | |
3652 | "dead event\n"); | |
fc2b989b | 3653 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3654 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
3655 | spin_unlock_irq(&phba->hbalock); |
3656 | /* | |
3657 | * Last resort will fail over by treating this | |
3658 | * as a link down to FCF registration. | |
3659 | */ | |
3660 | lpfc_sli4_fcf_dead_failthrough(phba); | |
38b92ef8 JS |
3661 | } else { |
3662 | /* Reset FCF roundrobin bmask for new discovery */ | |
7d791df7 | 3663 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
38b92ef8 JS |
3664 | /* |
3665 | * Handling fast FCF failover to a DEAD FCF event is | |
3666 | * considered equalivant to receiving CVL to all vports. | |
fc2b989b JS |
3667 | */ |
3668 | lpfc_sli4_perform_all_vport_cvl(phba); | |
38b92ef8 | 3669 | } |
da0436e9 | 3670 | break; |
70f3c073 | 3671 | case LPFC_FIP_EVENT_TYPE_CVL: |
0c9ab6f5 | 3672 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
6669f9bb | 3673 | "2718 Clear Virtual Link Received for VPI 0x%x" |
70f3c073 | 3674 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
6d368e53 | 3675 | |
6669f9bb | 3676 | vport = lpfc_find_vport_by_vpid(phba, |
5248a749 | 3677 | acqe_fip->index); |
fc2b989b | 3678 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
6669f9bb JS |
3679 | if (!ndlp) |
3680 | break; | |
695a814e JS |
3681 | active_vlink_present = 0; |
3682 | ||
3683 | vports = lpfc_create_vport_work_array(phba); | |
3684 | if (vports) { | |
3685 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; | |
3686 | i++) { | |
3687 | if ((!(vports[i]->fc_flag & | |
3688 | FC_VPORT_CVL_RCVD)) && | |
3689 | (vports[i]->port_state > LPFC_FDISC)) { | |
3690 | active_vlink_present = 1; | |
3691 | break; | |
3692 | } | |
3693 | } | |
3694 | lpfc_destroy_vport_work_array(phba, vports); | |
3695 | } | |
3696 | ||
3697 | if (active_vlink_present) { | |
3698 | /* | |
3699 | * If there are other active VLinks present, | |
3700 | * re-instantiate the Vlink using FDISC. | |
3701 | */ | |
6669f9bb | 3702 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
fc2b989b | 3703 | shost = lpfc_shost_from_vport(vport); |
6669f9bb JS |
3704 | spin_lock_irq(shost->host_lock); |
3705 | ndlp->nlp_flag |= NLP_DELAY_TMO; | |
3706 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
3707 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
3708 | vport->port_state = LPFC_FDISC; | |
3709 | } else { | |
ecfd03c6 JS |
3710 | /* |
3711 | * Otherwise, we request port to rediscover | |
3712 | * the entire FCF table for a fast recovery | |
3713 | * from possible case that the current FCF | |
0c9ab6f5 JS |
3714 | * is no longer valid if we are not already |
3715 | * in the FCF failover process. | |
ecfd03c6 | 3716 | */ |
fc2b989b | 3717 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3718 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
fc2b989b JS |
3719 | spin_unlock_irq(&phba->hbalock); |
3720 | break; | |
3721 | } | |
3722 | /* Mark the fast failover process in progress */ | |
0c9ab6f5 | 3723 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
fc2b989b | 3724 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 JS |
3725 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
3726 | LOG_DISCOVERY, | |
a93ff37a | 3727 | "2773 Start FCF failover per CVL, " |
70f3c073 | 3728 | "evt_tag:x%x\n", acqe_fip->event_tag); |
ecfd03c6 | 3729 | rc = lpfc_sli4_redisc_fcf_table(phba); |
fc2b989b | 3730 | if (rc) { |
0c9ab6f5 JS |
3731 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
3732 | LOG_DISCOVERY, | |
3733 | "2774 Issue FCF rediscover " | |
3734 | "mabilbox command failed, " | |
3735 | "through to CVL event\n"); | |
fc2b989b | 3736 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3737 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b | 3738 | spin_unlock_irq(&phba->hbalock); |
ecfd03c6 JS |
3739 | /* |
3740 | * Last resort will be re-try on the | |
3741 | * the current registered FCF entry. | |
3742 | */ | |
3743 | lpfc_retry_pport_discovery(phba); | |
38b92ef8 JS |
3744 | } else |
3745 | /* | |
3746 | * Reset FCF roundrobin bmask for new | |
3747 | * discovery. | |
3748 | */ | |
7d791df7 | 3749 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
6669f9bb JS |
3750 | } |
3751 | break; | |
da0436e9 JS |
3752 | default: |
3753 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3754 | "0288 Unknown FCoE event type 0x%x event tag " | |
70f3c073 | 3755 | "0x%x\n", event_type, acqe_fip->event_tag); |
da0436e9 JS |
3756 | break; |
3757 | } | |
3758 | } | |
3759 | ||
3760 | /** | |
3761 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event | |
3762 | * @phba: pointer to lpfc hba data structure. | |
3763 | * @acqe_link: pointer to the async dcbx completion queue entry. | |
3764 | * | |
3765 | * This routine is to handle the SLI4 asynchronous dcbx event. | |
3766 | **/ | |
3767 | static void | |
3768 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, | |
3769 | struct lpfc_acqe_dcbx *acqe_dcbx) | |
3770 | { | |
4d9ab994 | 3771 | phba->fc_eventTag = acqe_dcbx->event_tag; |
da0436e9 JS |
3772 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
3773 | "0290 The SLI4 DCBX asynchronous event is not " | |
3774 | "handled yet\n"); | |
3775 | } | |
3776 | ||
b19a061a JS |
3777 | /** |
3778 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event | |
3779 | * @phba: pointer to lpfc hba data structure. | |
3780 | * @acqe_link: pointer to the async grp5 completion queue entry. | |
3781 | * | |
3782 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event | |
3783 | * is an asynchronous notified of a logical link speed change. The Port | |
3784 | * reports the logical link speed in units of 10Mbps. | |
3785 | **/ | |
3786 | static void | |
3787 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, | |
3788 | struct lpfc_acqe_grp5 *acqe_grp5) | |
3789 | { | |
3790 | uint16_t prev_ll_spd; | |
3791 | ||
3792 | phba->fc_eventTag = acqe_grp5->event_tag; | |
3793 | phba->fcoe_eventtag = acqe_grp5->event_tag; | |
3794 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; | |
3795 | phba->sli4_hba.link_state.logical_speed = | |
3796 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)); | |
3797 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3798 | "2789 GRP5 Async Event: Updating logical link speed " | |
3799 | "from %dMbps to %dMbps\n", (prev_ll_spd * 10), | |
3800 | (phba->sli4_hba.link_state.logical_speed*10)); | |
3801 | } | |
3802 | ||
da0436e9 JS |
3803 | /** |
3804 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event | |
3805 | * @phba: pointer to lpfc hba data structure. | |
3806 | * | |
3807 | * This routine is invoked by the worker thread to process all the pending | |
3808 | * SLI4 asynchronous events. | |
3809 | **/ | |
3810 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) | |
3811 | { | |
3812 | struct lpfc_cq_event *cq_event; | |
3813 | ||
3814 | /* First, declare the async event has been handled */ | |
3815 | spin_lock_irq(&phba->hbalock); | |
3816 | phba->hba_flag &= ~ASYNC_EVENT; | |
3817 | spin_unlock_irq(&phba->hbalock); | |
3818 | /* Now, handle all the async events */ | |
3819 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { | |
3820 | /* Get the first event from the head of the event queue */ | |
3821 | spin_lock_irq(&phba->hbalock); | |
3822 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, | |
3823 | cq_event, struct lpfc_cq_event, list); | |
3824 | spin_unlock_irq(&phba->hbalock); | |
3825 | /* Process the asynchronous event */ | |
3826 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { | |
3827 | case LPFC_TRAILER_CODE_LINK: | |
3828 | lpfc_sli4_async_link_evt(phba, | |
3829 | &cq_event->cqe.acqe_link); | |
3830 | break; | |
3831 | case LPFC_TRAILER_CODE_FCOE: | |
70f3c073 | 3832 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
da0436e9 JS |
3833 | break; |
3834 | case LPFC_TRAILER_CODE_DCBX: | |
3835 | lpfc_sli4_async_dcbx_evt(phba, | |
3836 | &cq_event->cqe.acqe_dcbx); | |
3837 | break; | |
b19a061a JS |
3838 | case LPFC_TRAILER_CODE_GRP5: |
3839 | lpfc_sli4_async_grp5_evt(phba, | |
3840 | &cq_event->cqe.acqe_grp5); | |
3841 | break; | |
70f3c073 JS |
3842 | case LPFC_TRAILER_CODE_FC: |
3843 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); | |
3844 | break; | |
3845 | case LPFC_TRAILER_CODE_SLI: | |
3846 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); | |
3847 | break; | |
da0436e9 JS |
3848 | default: |
3849 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3850 | "1804 Invalid asynchrous event code: " | |
3851 | "x%x\n", bf_get(lpfc_trailer_code, | |
3852 | &cq_event->cqe.mcqe_cmpl)); | |
3853 | break; | |
3854 | } | |
3855 | /* Free the completion event processed to the free pool */ | |
3856 | lpfc_sli4_cq_event_release(phba, cq_event); | |
3857 | } | |
3858 | } | |
3859 | ||
ecfd03c6 JS |
3860 | /** |
3861 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event | |
3862 | * @phba: pointer to lpfc hba data structure. | |
3863 | * | |
3864 | * This routine is invoked by the worker thread to process FCF table | |
3865 | * rediscovery pending completion event. | |
3866 | **/ | |
3867 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) | |
3868 | { | |
3869 | int rc; | |
3870 | ||
3871 | spin_lock_irq(&phba->hbalock); | |
3872 | /* Clear FCF rediscovery timeout event */ | |
3873 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; | |
3874 | /* Clear driver fast failover FCF record flag */ | |
3875 | phba->fcf.failover_rec.flag = 0; | |
3876 | /* Set state for FCF fast failover */ | |
3877 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; | |
3878 | spin_unlock_irq(&phba->hbalock); | |
3879 | ||
3880 | /* Scan FCF table from the first entry to re-discover SAN */ | |
0c9ab6f5 | 3881 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
a93ff37a | 3882 | "2777 Start post-quiescent FCF table scan\n"); |
0c9ab6f5 | 3883 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
ecfd03c6 | 3884 | if (rc) |
0c9ab6f5 JS |
3885 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
3886 | "2747 Issue FCF scan read FCF mailbox " | |
3887 | "command failed 0x%x\n", rc); | |
ecfd03c6 JS |
3888 | } |
3889 | ||
da0436e9 JS |
3890 | /** |
3891 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table | |
3892 | * @phba: pointer to lpfc hba data structure. | |
3893 | * @dev_grp: The HBA PCI-Device group number. | |
3894 | * | |
3895 | * This routine is invoked to set up the per HBA PCI-Device group function | |
3896 | * API jump table entries. | |
3897 | * | |
3898 | * Return: 0 if success, otherwise -ENODEV | |
3899 | **/ | |
3900 | int | |
3901 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
3902 | { | |
3903 | int rc; | |
3904 | ||
3905 | /* Set up lpfc PCI-device group */ | |
3906 | phba->pci_dev_grp = dev_grp; | |
3907 | ||
3908 | /* The LPFC_PCI_DEV_OC uses SLI4 */ | |
3909 | if (dev_grp == LPFC_PCI_DEV_OC) | |
3910 | phba->sli_rev = LPFC_SLI_REV4; | |
3911 | ||
3912 | /* Set up device INIT API function jump table */ | |
3913 | rc = lpfc_init_api_table_setup(phba, dev_grp); | |
3914 | if (rc) | |
3915 | return -ENODEV; | |
3916 | /* Set up SCSI API function jump table */ | |
3917 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); | |
3918 | if (rc) | |
3919 | return -ENODEV; | |
3920 | /* Set up SLI API function jump table */ | |
3921 | rc = lpfc_sli_api_table_setup(phba, dev_grp); | |
3922 | if (rc) | |
3923 | return -ENODEV; | |
3924 | /* Set up MBOX API function jump table */ | |
3925 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); | |
3926 | if (rc) | |
3927 | return -ENODEV; | |
3928 | ||
3929 | return 0; | |
5b75da2f JS |
3930 | } |
3931 | ||
3932 | /** | |
3621a710 | 3933 | * lpfc_log_intr_mode - Log the active interrupt mode |
5b75da2f JS |
3934 | * @phba: pointer to lpfc hba data structure. |
3935 | * @intr_mode: active interrupt mode adopted. | |
3936 | * | |
3937 | * This routine it invoked to log the currently used active interrupt mode | |
3938 | * to the device. | |
3772a991 JS |
3939 | **/ |
3940 | static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode) | |
5b75da2f JS |
3941 | { |
3942 | switch (intr_mode) { | |
3943 | case 0: | |
3944 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3945 | "0470 Enable INTx interrupt mode.\n"); | |
3946 | break; | |
3947 | case 1: | |
3948 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3949 | "0481 Enabled MSI interrupt mode.\n"); | |
3950 | break; | |
3951 | case 2: | |
3952 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
3953 | "0480 Enabled MSI-X interrupt mode.\n"); | |
3954 | break; | |
3955 | default: | |
3956 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3957 | "0482 Illegal interrupt mode.\n"); | |
3958 | break; | |
3959 | } | |
3960 | return; | |
3961 | } | |
3962 | ||
5b75da2f | 3963 | /** |
3772a991 | 3964 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
5b75da2f JS |
3965 | * @phba: pointer to lpfc hba data structure. |
3966 | * | |
3772a991 JS |
3967 | * This routine is invoked to enable the PCI device that is common to all |
3968 | * PCI devices. | |
5b75da2f JS |
3969 | * |
3970 | * Return codes | |
af901ca1 | 3971 | * 0 - successful |
3772a991 | 3972 | * other values - error |
5b75da2f | 3973 | **/ |
3772a991 JS |
3974 | static int |
3975 | lpfc_enable_pci_dev(struct lpfc_hba *phba) | |
5b75da2f | 3976 | { |
3772a991 | 3977 | struct pci_dev *pdev; |
079b5c91 | 3978 | int bars = 0; |
5b75da2f | 3979 | |
3772a991 JS |
3980 | /* Obtain PCI device reference */ |
3981 | if (!phba->pcidev) | |
3982 | goto out_error; | |
3983 | else | |
3984 | pdev = phba->pcidev; | |
3985 | /* Select PCI BARs */ | |
3986 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
3987 | /* Enable PCI device */ | |
3988 | if (pci_enable_device_mem(pdev)) | |
3989 | goto out_error; | |
3990 | /* Request PCI resource for the device */ | |
3991 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) | |
3992 | goto out_disable_device; | |
3993 | /* Set up device as PCI master and save state for EEH */ | |
3994 | pci_set_master(pdev); | |
3995 | pci_try_set_mwi(pdev); | |
3996 | pci_save_state(pdev); | |
5b75da2f | 3997 | |
0558056c JS |
3998 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
3999 | if (pci_find_capability(pdev, PCI_CAP_ID_EXP)) | |
4000 | pdev->needs_freset = 1; | |
4001 | ||
3772a991 | 4002 | return 0; |
5b75da2f | 4003 | |
3772a991 JS |
4004 | out_disable_device: |
4005 | pci_disable_device(pdev); | |
4006 | out_error: | |
079b5c91 JS |
4007 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
4008 | "1401 Failed to enable pci device, bars:x%x\n", bars); | |
3772a991 | 4009 | return -ENODEV; |
5b75da2f JS |
4010 | } |
4011 | ||
4012 | /** | |
3772a991 | 4013 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
5b75da2f JS |
4014 | * @phba: pointer to lpfc hba data structure. |
4015 | * | |
3772a991 JS |
4016 | * This routine is invoked to disable the PCI device that is common to all |
4017 | * PCI devices. | |
5b75da2f JS |
4018 | **/ |
4019 | static void | |
3772a991 | 4020 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
5b75da2f | 4021 | { |
3772a991 JS |
4022 | struct pci_dev *pdev; |
4023 | int bars; | |
5b75da2f | 4024 | |
3772a991 JS |
4025 | /* Obtain PCI device reference */ |
4026 | if (!phba->pcidev) | |
4027 | return; | |
4028 | else | |
4029 | pdev = phba->pcidev; | |
4030 | /* Select PCI BARs */ | |
4031 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
4032 | /* Release PCI resource and disable PCI device */ | |
4033 | pci_release_selected_regions(pdev, bars); | |
4034 | pci_disable_device(pdev); | |
4035 | /* Null out PCI private reference to driver */ | |
4036 | pci_set_drvdata(pdev, NULL); | |
5b75da2f JS |
4037 | |
4038 | return; | |
4039 | } | |
4040 | ||
e59058c4 | 4041 | /** |
3772a991 JS |
4042 | * lpfc_reset_hba - Reset a hba |
4043 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 4044 | * |
3772a991 JS |
4045 | * This routine is invoked to reset a hba device. It brings the HBA |
4046 | * offline, performs a board restart, and then brings the board back | |
4047 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up | |
4048 | * on outstanding mailbox commands. | |
e59058c4 | 4049 | **/ |
3772a991 JS |
4050 | void |
4051 | lpfc_reset_hba(struct lpfc_hba *phba) | |
dea3101e | 4052 | { |
3772a991 JS |
4053 | /* If resets are disabled then set error state and return. */ |
4054 | if (!phba->cfg_enable_hba_reset) { | |
4055 | phba->link_state = LPFC_HBA_ERROR; | |
4056 | return; | |
4057 | } | |
4058 | lpfc_offline_prep(phba); | |
4059 | lpfc_offline(phba); | |
4060 | lpfc_sli_brdrestart(phba); | |
4061 | lpfc_online(phba); | |
4062 | lpfc_unblock_mgmt_io(phba); | |
4063 | } | |
dea3101e | 4064 | |
0a96e975 JS |
4065 | /** |
4066 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions | |
4067 | * @phba: pointer to lpfc hba data structure. | |
4068 | * | |
4069 | * This function enables the PCI SR-IOV virtual functions to a physical | |
4070 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to | |
4071 | * enable the number of virtual functions to the physical function. As | |
4072 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() | |
4073 | * API call does not considered as an error condition for most of the device. | |
4074 | **/ | |
4075 | uint16_t | |
4076 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) | |
4077 | { | |
4078 | struct pci_dev *pdev = phba->pcidev; | |
4079 | uint16_t nr_virtfn; | |
4080 | int pos; | |
4081 | ||
0a96e975 JS |
4082 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
4083 | if (pos == 0) | |
4084 | return 0; | |
4085 | ||
4086 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); | |
4087 | return nr_virtfn; | |
4088 | } | |
4089 | ||
912e3acd JS |
4090 | /** |
4091 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions | |
4092 | * @phba: pointer to lpfc hba data structure. | |
4093 | * @nr_vfn: number of virtual functions to be enabled. | |
4094 | * | |
4095 | * This function enables the PCI SR-IOV virtual functions to a physical | |
4096 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to | |
4097 | * enable the number of virtual functions to the physical function. As | |
4098 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() | |
4099 | * API call does not considered as an error condition for most of the device. | |
4100 | **/ | |
4101 | int | |
4102 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) | |
4103 | { | |
4104 | struct pci_dev *pdev = phba->pcidev; | |
0a96e975 | 4105 | uint16_t max_nr_vfn; |
912e3acd JS |
4106 | int rc; |
4107 | ||
0a96e975 JS |
4108 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
4109 | if (nr_vfn > max_nr_vfn) { | |
4110 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4111 | "3057 Requested vfs (%d) greater than " | |
4112 | "supported vfs (%d)", nr_vfn, max_nr_vfn); | |
4113 | return -EINVAL; | |
4114 | } | |
4115 | ||
912e3acd JS |
4116 | rc = pci_enable_sriov(pdev, nr_vfn); |
4117 | if (rc) { | |
4118 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4119 | "2806 Failed to enable sriov on this device " | |
4120 | "with vfn number nr_vf:%d, rc:%d\n", | |
4121 | nr_vfn, rc); | |
4122 | } else | |
4123 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4124 | "2807 Successful enable sriov on this device " | |
4125 | "with vfn number nr_vf:%d\n", nr_vfn); | |
4126 | return rc; | |
4127 | } | |
4128 | ||
3772a991 JS |
4129 | /** |
4130 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. | |
4131 | * @phba: pointer to lpfc hba data structure. | |
4132 | * | |
4133 | * This routine is invoked to set up the driver internal resources specific to | |
4134 | * support the SLI-3 HBA device it attached to. | |
4135 | * | |
4136 | * Return codes | |
af901ca1 | 4137 | * 0 - successful |
3772a991 JS |
4138 | * other values - error |
4139 | **/ | |
4140 | static int | |
4141 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) | |
4142 | { | |
4143 | struct lpfc_sli *psli; | |
912e3acd | 4144 | int rc; |
dea3101e | 4145 | |
2e0fef85 | 4146 | /* |
3772a991 | 4147 | * Initialize timers used by driver |
2e0fef85 | 4148 | */ |
dea3101e | 4149 | |
3772a991 | 4150 | /* Heartbeat timer */ |
858c9f6c JS |
4151 | init_timer(&phba->hb_tmofunc); |
4152 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
4153 | phba->hb_tmofunc.data = (unsigned long)phba; | |
4154 | ||
dea3101e | 4155 | psli = &phba->sli; |
3772a991 | 4156 | /* MBOX heartbeat timer */ |
dea3101e | 4157 | init_timer(&psli->mbox_tmo); |
4158 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
2e0fef85 | 4159 | psli->mbox_tmo.data = (unsigned long) phba; |
3772a991 | 4160 | /* FCP polling mode timer */ |
875fbdfe JSEC |
4161 | init_timer(&phba->fcp_poll_timer); |
4162 | phba->fcp_poll_timer.function = lpfc_poll_timeout; | |
2e0fef85 | 4163 | phba->fcp_poll_timer.data = (unsigned long) phba; |
3772a991 | 4164 | /* Fabric block timer */ |
92d7f7b0 JS |
4165 | init_timer(&phba->fabric_block_timer); |
4166 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
4167 | phba->fabric_block_timer.data = (unsigned long) phba; | |
3772a991 | 4168 | /* EA polling mode timer */ |
9399627f JS |
4169 | init_timer(&phba->eratt_poll); |
4170 | phba->eratt_poll.function = lpfc_poll_eratt; | |
4171 | phba->eratt_poll.data = (unsigned long) phba; | |
dea3101e | 4172 | |
3772a991 JS |
4173 | /* Host attention work mask setup */ |
4174 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); | |
4175 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); | |
dea3101e | 4176 | |
3772a991 JS |
4177 | /* Get all the module params for configuring this host */ |
4178 | lpfc_get_cfgparam(phba); | |
49198b37 JS |
4179 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
4180 | phba->menlo_flag |= HBA_MENLO_SUPPORT; | |
4181 | /* check for menlo minimum sg count */ | |
4182 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) | |
4183 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; | |
4184 | } | |
4185 | ||
dea3101e | 4186 | /* |
3772a991 JS |
4187 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size |
4188 | * used to create the sg_dma_buf_pool must be dynamically calculated. | |
4189 | * 2 segments are added since the IOCB needs a command and response bde. | |
dea3101e | 4190 | */ |
3772a991 JS |
4191 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
4192 | sizeof(struct fcp_rsp) + | |
4193 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); | |
4194 | ||
4195 | if (phba->cfg_enable_bg) { | |
4196 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT; | |
4197 | phba->cfg_sg_dma_buf_size += | |
4198 | phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64); | |
901a920f | 4199 | } |
dea3101e | 4200 | |
3772a991 JS |
4201 | /* Also reinitialize the host templates with new values. */ |
4202 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
4203 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
dea3101e | 4204 | |
3772a991 JS |
4205 | phba->max_vpi = LPFC_MAX_VPI; |
4206 | /* This will be set to correct value after config_port mbox */ | |
4207 | phba->max_vports = 0; | |
dea3101e | 4208 | |
3772a991 JS |
4209 | /* |
4210 | * Initialize the SLI Layer to run with lpfc HBAs. | |
4211 | */ | |
4212 | lpfc_sli_setup(phba); | |
4213 | lpfc_sli_queue_setup(phba); | |
ed957684 | 4214 | |
3772a991 JS |
4215 | /* Allocate device driver memory */ |
4216 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) | |
4217 | return -ENOMEM; | |
51ef4c26 | 4218 | |
912e3acd JS |
4219 | /* |
4220 | * Enable sr-iov virtual functions if supported and configured | |
4221 | * through the module parameter. | |
4222 | */ | |
4223 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
4224 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, | |
4225 | phba->cfg_sriov_nr_virtfn); | |
4226 | if (rc) { | |
4227 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4228 | "2808 Requested number of SR-IOV " | |
4229 | "virtual functions (%d) is not " | |
4230 | "supported\n", | |
4231 | phba->cfg_sriov_nr_virtfn); | |
4232 | phba->cfg_sriov_nr_virtfn = 0; | |
4233 | } | |
4234 | } | |
4235 | ||
3772a991 JS |
4236 | return 0; |
4237 | } | |
ed957684 | 4238 | |
3772a991 JS |
4239 | /** |
4240 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev | |
4241 | * @phba: pointer to lpfc hba data structure. | |
4242 | * | |
4243 | * This routine is invoked to unset the driver internal resources set up | |
4244 | * specific for supporting the SLI-3 HBA device it attached to. | |
4245 | **/ | |
4246 | static void | |
4247 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) | |
4248 | { | |
4249 | /* Free device driver memory allocated */ | |
4250 | lpfc_mem_free_all(phba); | |
3163f725 | 4251 | |
3772a991 JS |
4252 | return; |
4253 | } | |
dea3101e | 4254 | |
3772a991 | 4255 | /** |
da0436e9 | 4256 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
3772a991 JS |
4257 | * @phba: pointer to lpfc hba data structure. |
4258 | * | |
da0436e9 JS |
4259 | * This routine is invoked to set up the driver internal resources specific to |
4260 | * support the SLI-4 HBA device it attached to. | |
3772a991 JS |
4261 | * |
4262 | * Return codes | |
af901ca1 | 4263 | * 0 - successful |
da0436e9 | 4264 | * other values - error |
3772a991 JS |
4265 | **/ |
4266 | static int | |
da0436e9 | 4267 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
3772a991 | 4268 | { |
da0436e9 | 4269 | struct lpfc_sli *psli; |
28baac74 JS |
4270 | LPFC_MBOXQ_t *mboxq; |
4271 | int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size; | |
4272 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; | |
4273 | struct lpfc_mqe *mqe; | |
085c647c | 4274 | int longs, sli_family; |
da0436e9 JS |
4275 | |
4276 | /* Before proceed, wait for POST done and device ready */ | |
4277 | rc = lpfc_sli4_post_status_check(phba); | |
4278 | if (rc) | |
4279 | return -ENODEV; | |
4280 | ||
3772a991 | 4281 | /* |
da0436e9 | 4282 | * Initialize timers used by driver |
3772a991 | 4283 | */ |
3772a991 | 4284 | |
da0436e9 JS |
4285 | /* Heartbeat timer */ |
4286 | init_timer(&phba->hb_tmofunc); | |
4287 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
4288 | phba->hb_tmofunc.data = (unsigned long)phba; | |
19ca7609 JS |
4289 | init_timer(&phba->rrq_tmr); |
4290 | phba->rrq_tmr.function = lpfc_rrq_timeout; | |
4291 | phba->rrq_tmr.data = (unsigned long)phba; | |
3772a991 | 4292 | |
da0436e9 JS |
4293 | psli = &phba->sli; |
4294 | /* MBOX heartbeat timer */ | |
4295 | init_timer(&psli->mbox_tmo); | |
4296 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
4297 | psli->mbox_tmo.data = (unsigned long) phba; | |
4298 | /* Fabric block timer */ | |
4299 | init_timer(&phba->fabric_block_timer); | |
4300 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
4301 | phba->fabric_block_timer.data = (unsigned long) phba; | |
4302 | /* EA polling mode timer */ | |
4303 | init_timer(&phba->eratt_poll); | |
4304 | phba->eratt_poll.function = lpfc_poll_eratt; | |
4305 | phba->eratt_poll.data = (unsigned long) phba; | |
ecfd03c6 JS |
4306 | /* FCF rediscover timer */ |
4307 | init_timer(&phba->fcf.redisc_wait); | |
4308 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; | |
4309 | phba->fcf.redisc_wait.data = (unsigned long)phba; | |
4310 | ||
7ad20aa9 JS |
4311 | /* |
4312 | * Control structure for handling external multi-buffer mailbox | |
4313 | * command pass-through. | |
4314 | */ | |
4315 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, | |
4316 | sizeof(struct lpfc_mbox_ext_buf_ctx)); | |
4317 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); | |
4318 | ||
da0436e9 JS |
4319 | /* |
4320 | * We need to do a READ_CONFIG mailbox command here before | |
4321 | * calling lpfc_get_cfgparam. For VFs this will report the | |
4322 | * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings. | |
4323 | * All of the resources allocated | |
4324 | * for this Port are tied to these values. | |
4325 | */ | |
4326 | /* Get all the module params for configuring this host */ | |
4327 | lpfc_get_cfgparam(phba); | |
4328 | phba->max_vpi = LPFC_MAX_VPI; | |
4329 | /* This will be set to correct value after the read_config mbox */ | |
4330 | phba->max_vports = 0; | |
3772a991 | 4331 | |
da0436e9 JS |
4332 | /* Program the default value of vlan_id and fc_map */ |
4333 | phba->valid_vlan = 0; | |
4334 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4335 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4336 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
3772a991 | 4337 | |
da0436e9 JS |
4338 | /* |
4339 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size | |
4340 | * used to create the sg_dma_buf_pool must be dynamically calculated. | |
4341 | * 2 segments are added since the IOCB needs a command and response bde. | |
4342 | * To insure that the scsi sgl does not cross a 4k page boundary only | |
28baac74 | 4343 | * sgl sizes of must be a power of 2. |
da0436e9 | 4344 | */ |
28baac74 JS |
4345 | buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) + |
4346 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge))); | |
085c647c JS |
4347 | |
4348 | sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf); | |
4349 | max_buf_size = LPFC_SLI4_MAX_BUF_SIZE; | |
4350 | switch (sli_family) { | |
4351 | case LPFC_SLI_INTF_FAMILY_BE2: | |
4352 | case LPFC_SLI_INTF_FAMILY_BE3: | |
4353 | /* There is a single hint for BE - 2 pages per BPL. */ | |
4354 | if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) == | |
4355 | LPFC_SLI_INTF_SLI_HINT1_1) | |
4356 | max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE; | |
4357 | break; | |
4358 | case LPFC_SLI_INTF_FAMILY_LNCR_A0: | |
4359 | case LPFC_SLI_INTF_FAMILY_LNCR_B0: | |
4360 | default: | |
4361 | break; | |
4362 | } | |
28baac74 JS |
4363 | for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE; |
4364 | dma_buf_size < max_buf_size && buf_size > dma_buf_size; | |
4365 | dma_buf_size = dma_buf_size << 1) | |
4366 | ; | |
4367 | if (dma_buf_size == max_buf_size) | |
4368 | phba->cfg_sg_seg_cnt = (dma_buf_size - | |
4369 | sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) - | |
4370 | (2 * sizeof(struct sli4_sge))) / | |
4371 | sizeof(struct sli4_sge); | |
4372 | phba->cfg_sg_dma_buf_size = dma_buf_size; | |
3772a991 | 4373 | |
da0436e9 JS |
4374 | /* Initialize buffer queue management fields */ |
4375 | hbq_count = lpfc_sli_hbq_count(); | |
4376 | for (i = 0; i < hbq_count; ++i) | |
4377 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
4378 | INIT_LIST_HEAD(&phba->rb_pend_list); | |
4379 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; | |
4380 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; | |
3772a991 | 4381 | |
da0436e9 JS |
4382 | /* |
4383 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. | |
4384 | */ | |
4385 | /* Initialize the Abort scsi buffer list used by driver */ | |
4386 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
4387 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
4388 | /* This abort list used by worker thread */ | |
4389 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); | |
3772a991 | 4390 | |
da0436e9 | 4391 | /* |
6d368e53 | 4392 | * Initialize driver internal slow-path work queues |
da0436e9 | 4393 | */ |
3772a991 | 4394 | |
da0436e9 JS |
4395 | /* Driver internel slow-path CQ Event pool */ |
4396 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); | |
4397 | /* Response IOCB work queue list */ | |
45ed1190 | 4398 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
da0436e9 JS |
4399 | /* Asynchronous event CQ Event work queue list */ |
4400 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); | |
4401 | /* Fast-path XRI aborted CQ Event work queue list */ | |
4402 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
4403 | /* Slow-path XRI aborted CQ Event work queue list */ | |
4404 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
4405 | /* Receive queue CQ Event work queue list */ | |
4406 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); | |
4407 | ||
6d368e53 JS |
4408 | /* Initialize extent block lists. */ |
4409 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); | |
4410 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); | |
4411 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); | |
4412 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); | |
4413 | ||
da0436e9 JS |
4414 | /* Initialize the driver internal SLI layer lists. */ |
4415 | lpfc_sli_setup(phba); | |
4416 | lpfc_sli_queue_setup(phba); | |
3772a991 | 4417 | |
da0436e9 JS |
4418 | /* Allocate device driver memory */ |
4419 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); | |
4420 | if (rc) | |
4421 | return -ENOMEM; | |
4422 | ||
2fcee4bf JS |
4423 | /* IF Type 2 ports get initialized now. */ |
4424 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
4425 | LPFC_SLI_INTF_IF_TYPE_2) { | |
4426 | rc = lpfc_pci_function_reset(phba); | |
4427 | if (unlikely(rc)) | |
4428 | return -ENODEV; | |
4429 | } | |
4430 | ||
da0436e9 JS |
4431 | /* Create the bootstrap mailbox command */ |
4432 | rc = lpfc_create_bootstrap_mbox(phba); | |
4433 | if (unlikely(rc)) | |
4434 | goto out_free_mem; | |
4435 | ||
4436 | /* Set up the host's endian order with the device. */ | |
4437 | rc = lpfc_setup_endian_order(phba); | |
4438 | if (unlikely(rc)) | |
4439 | goto out_free_bsmbx; | |
4440 | ||
4441 | /* Set up the hba's configuration parameters. */ | |
4442 | rc = lpfc_sli4_read_config(phba); | |
4443 | if (unlikely(rc)) | |
4444 | goto out_free_bsmbx; | |
4445 | ||
2fcee4bf JS |
4446 | /* IF Type 0 ports get initialized now. */ |
4447 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
4448 | LPFC_SLI_INTF_IF_TYPE_0) { | |
4449 | rc = lpfc_pci_function_reset(phba); | |
4450 | if (unlikely(rc)) | |
4451 | goto out_free_bsmbx; | |
4452 | } | |
da0436e9 | 4453 | |
cb5172ea JS |
4454 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
4455 | GFP_KERNEL); | |
4456 | if (!mboxq) { | |
4457 | rc = -ENOMEM; | |
4458 | goto out_free_bsmbx; | |
4459 | } | |
4460 | ||
fedd3b7b | 4461 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
cb5172ea JS |
4462 | lpfc_supported_pages(mboxq); |
4463 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
fedd3b7b JS |
4464 | if (!rc) { |
4465 | mqe = &mboxq->u.mqe; | |
4466 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), | |
4467 | LPFC_MAX_SUPPORTED_PAGES); | |
4468 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { | |
4469 | switch (pn_page[i]) { | |
4470 | case LPFC_SLI4_PARAMETERS: | |
4471 | phba->sli4_hba.pc_sli4_params.supported = 1; | |
4472 | break; | |
4473 | default: | |
4474 | break; | |
4475 | } | |
4476 | } | |
4477 | /* Read the port's SLI4 Parameters capabilities if supported. */ | |
4478 | if (phba->sli4_hba.pc_sli4_params.supported) | |
4479 | rc = lpfc_pc_sli4_params_get(phba, mboxq); | |
4480 | if (rc) { | |
4481 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4482 | rc = -EIO; | |
4483 | goto out_free_bsmbx; | |
cb5172ea JS |
4484 | } |
4485 | } | |
fedd3b7b JS |
4486 | /* |
4487 | * Get sli4 parameters that override parameters from Port capabilities. | |
6d368e53 JS |
4488 | * If this call fails, it isn't critical unless the SLI4 parameters come |
4489 | * back in conflict. | |
fedd3b7b | 4490 | */ |
6d368e53 JS |
4491 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
4492 | if (rc) { | |
4493 | if (phba->sli4_hba.extents_in_use && | |
4494 | phba->sli4_hba.rpi_hdrs_in_use) { | |
4495 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4496 | "2999 Unsupported SLI4 Parameters " | |
4497 | "Extents and RPI headers enabled.\n"); | |
4498 | goto out_free_bsmbx; | |
4499 | } | |
4500 | } | |
cb5172ea | 4501 | mempool_free(mboxq, phba->mbox_mem_pool); |
5350d872 JS |
4502 | /* Verify all the SLI4 queues */ |
4503 | rc = lpfc_sli4_queue_verify(phba); | |
da0436e9 JS |
4504 | if (rc) |
4505 | goto out_free_bsmbx; | |
4506 | ||
4507 | /* Create driver internal CQE event pool */ | |
4508 | rc = lpfc_sli4_cq_event_pool_create(phba); | |
4509 | if (rc) | |
5350d872 | 4510 | goto out_free_bsmbx; |
da0436e9 JS |
4511 | |
4512 | /* Initialize and populate the iocb list per host */ | |
4513 | rc = lpfc_init_sgl_list(phba); | |
4514 | if (rc) { | |
4515 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4516 | "1400 Failed to initialize sgl list.\n"); | |
4517 | goto out_destroy_cq_event_pool; | |
4518 | } | |
4519 | rc = lpfc_init_active_sgl_array(phba); | |
4520 | if (rc) { | |
4521 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4522 | "1430 Failed to initialize sgl list.\n"); | |
4523 | goto out_free_sgl_list; | |
4524 | } | |
da0436e9 JS |
4525 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
4526 | if (rc) { | |
4527 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4528 | "1432 Failed to initialize rpi headers.\n"); | |
4529 | goto out_free_active_sgl; | |
4530 | } | |
4531 | ||
a93ff37a | 4532 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
0c9ab6f5 JS |
4533 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
4534 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), | |
4535 | GFP_KERNEL); | |
4536 | if (!phba->fcf.fcf_rr_bmask) { | |
4537 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4538 | "2759 Failed allocate memory for FCF round " | |
4539 | "robin failover bmask\n"); | |
0558056c | 4540 | rc = -ENOMEM; |
0c9ab6f5 JS |
4541 | goto out_remove_rpi_hdrs; |
4542 | } | |
4543 | ||
5350d872 JS |
4544 | /* |
4545 | * The cfg_fcp_eq_count can be zero whenever there is exactly one | |
4546 | * interrupt vector. This is not an error | |
4547 | */ | |
4548 | if (phba->cfg_fcp_eq_count) { | |
4549 | phba->sli4_hba.fcp_eq_hdl = | |
4550 | kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * | |
da0436e9 | 4551 | phba->cfg_fcp_eq_count), GFP_KERNEL); |
5350d872 JS |
4552 | if (!phba->sli4_hba.fcp_eq_hdl) { |
4553 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4554 | "2572 Failed allocate memory for " | |
4555 | "fast-path per-EQ handle array\n"); | |
4556 | rc = -ENOMEM; | |
4557 | goto out_free_fcf_rr_bmask; | |
4558 | } | |
da0436e9 JS |
4559 | } |
4560 | ||
4561 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * | |
4562 | phba->sli4_hba.cfg_eqn), GFP_KERNEL); | |
4563 | if (!phba->sli4_hba.msix_entries) { | |
4564 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4565 | "2573 Failed allocate memory for msi-x " | |
4566 | "interrupt vector entries\n"); | |
0558056c | 4567 | rc = -ENOMEM; |
da0436e9 JS |
4568 | goto out_free_fcp_eq_hdl; |
4569 | } | |
4570 | ||
912e3acd JS |
4571 | /* |
4572 | * Enable sr-iov virtual functions if supported and configured | |
4573 | * through the module parameter. | |
4574 | */ | |
4575 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
4576 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, | |
4577 | phba->cfg_sriov_nr_virtfn); | |
4578 | if (rc) { | |
4579 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4580 | "3020 Requested number of SR-IOV " | |
4581 | "virtual functions (%d) is not " | |
4582 | "supported\n", | |
4583 | phba->cfg_sriov_nr_virtfn); | |
4584 | phba->cfg_sriov_nr_virtfn = 0; | |
4585 | } | |
4586 | } | |
4587 | ||
5248a749 | 4588 | return 0; |
da0436e9 JS |
4589 | |
4590 | out_free_fcp_eq_hdl: | |
4591 | kfree(phba->sli4_hba.fcp_eq_hdl); | |
0c9ab6f5 JS |
4592 | out_free_fcf_rr_bmask: |
4593 | kfree(phba->fcf.fcf_rr_bmask); | |
da0436e9 JS |
4594 | out_remove_rpi_hdrs: |
4595 | lpfc_sli4_remove_rpi_hdrs(phba); | |
4596 | out_free_active_sgl: | |
4597 | lpfc_free_active_sgl(phba); | |
4598 | out_free_sgl_list: | |
4599 | lpfc_free_sgl_list(phba); | |
4600 | out_destroy_cq_event_pool: | |
4601 | lpfc_sli4_cq_event_pool_destroy(phba); | |
da0436e9 JS |
4602 | out_free_bsmbx: |
4603 | lpfc_destroy_bootstrap_mbox(phba); | |
4604 | out_free_mem: | |
4605 | lpfc_mem_free(phba); | |
4606 | return rc; | |
4607 | } | |
4608 | ||
4609 | /** | |
4610 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev | |
4611 | * @phba: pointer to lpfc hba data structure. | |
4612 | * | |
4613 | * This routine is invoked to unset the driver internal resources set up | |
4614 | * specific for supporting the SLI-4 HBA device it attached to. | |
4615 | **/ | |
4616 | static void | |
4617 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) | |
4618 | { | |
4619 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; | |
4620 | ||
da0436e9 JS |
4621 | /* Free memory allocated for msi-x interrupt vector entries */ |
4622 | kfree(phba->sli4_hba.msix_entries); | |
4623 | ||
4624 | /* Free memory allocated for fast-path work queue handles */ | |
4625 | kfree(phba->sli4_hba.fcp_eq_hdl); | |
4626 | ||
4627 | /* Free the allocated rpi headers. */ | |
4628 | lpfc_sli4_remove_rpi_hdrs(phba); | |
d11e31dd | 4629 | lpfc_sli4_remove_rpis(phba); |
da0436e9 | 4630 | |
0c9ab6f5 JS |
4631 | /* Free eligible FCF index bmask */ |
4632 | kfree(phba->fcf.fcf_rr_bmask); | |
4633 | ||
da0436e9 JS |
4634 | /* Free the ELS sgl list */ |
4635 | lpfc_free_active_sgl(phba); | |
4636 | lpfc_free_sgl_list(phba); | |
4637 | ||
4638 | /* Free the SCSI sgl management array */ | |
4639 | kfree(phba->sli4_hba.lpfc_scsi_psb_array); | |
4640 | ||
da0436e9 JS |
4641 | /* Free the completion queue EQ event pool */ |
4642 | lpfc_sli4_cq_event_release_all(phba); | |
4643 | lpfc_sli4_cq_event_pool_destroy(phba); | |
4644 | ||
6d368e53 JS |
4645 | /* Release resource identifiers. */ |
4646 | lpfc_sli4_dealloc_resource_identifiers(phba); | |
4647 | ||
da0436e9 JS |
4648 | /* Free the bsmbx region. */ |
4649 | lpfc_destroy_bootstrap_mbox(phba); | |
4650 | ||
4651 | /* Free the SLI Layer memory with SLI4 HBAs */ | |
4652 | lpfc_mem_free_all(phba); | |
4653 | ||
4654 | /* Free the current connect table */ | |
4655 | list_for_each_entry_safe(conn_entry, next_conn_entry, | |
4d9ab994 JS |
4656 | &phba->fcf_conn_rec_list, list) { |
4657 | list_del_init(&conn_entry->list); | |
da0436e9 | 4658 | kfree(conn_entry); |
4d9ab994 | 4659 | } |
da0436e9 JS |
4660 | |
4661 | return; | |
4662 | } | |
4663 | ||
4664 | /** | |
25985edc | 4665 | * lpfc_init_api_table_setup - Set up init api function jump table |
da0436e9 JS |
4666 | * @phba: The hba struct for which this call is being executed. |
4667 | * @dev_grp: The HBA PCI-Device group number. | |
4668 | * | |
4669 | * This routine sets up the device INIT interface API function jump table | |
4670 | * in @phba struct. | |
4671 | * | |
4672 | * Returns: 0 - success, -ENODEV - failure. | |
4673 | **/ | |
4674 | int | |
4675 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
4676 | { | |
84d1b006 JS |
4677 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
4678 | phba->lpfc_hba_down_link = lpfc_hba_down_link; | |
7f86059a | 4679 | phba->lpfc_selective_reset = lpfc_selective_reset; |
da0436e9 JS |
4680 | switch (dev_grp) { |
4681 | case LPFC_PCI_DEV_LP: | |
4682 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; | |
4683 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; | |
4684 | phba->lpfc_stop_port = lpfc_stop_port_s3; | |
4685 | break; | |
4686 | case LPFC_PCI_DEV_OC: | |
4687 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; | |
4688 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; | |
4689 | phba->lpfc_stop_port = lpfc_stop_port_s4; | |
4690 | break; | |
4691 | default: | |
4692 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4693 | "1431 Invalid HBA PCI-device group: 0x%x\n", | |
4694 | dev_grp); | |
4695 | return -ENODEV; | |
4696 | break; | |
4697 | } | |
4698 | return 0; | |
4699 | } | |
4700 | ||
4701 | /** | |
4702 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. | |
4703 | * @phba: pointer to lpfc hba data structure. | |
4704 | * | |
4705 | * This routine is invoked to set up the driver internal resources before the | |
4706 | * device specific resource setup to support the HBA device it attached to. | |
4707 | * | |
4708 | * Return codes | |
af901ca1 | 4709 | * 0 - successful |
da0436e9 JS |
4710 | * other values - error |
4711 | **/ | |
4712 | static int | |
4713 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) | |
4714 | { | |
4715 | /* | |
4716 | * Driver resources common to all SLI revisions | |
4717 | */ | |
4718 | atomic_set(&phba->fast_event_count, 0); | |
4719 | spin_lock_init(&phba->hbalock); | |
4720 | ||
4721 | /* Initialize ndlp management spinlock */ | |
4722 | spin_lock_init(&phba->ndlp_lock); | |
4723 | ||
4724 | INIT_LIST_HEAD(&phba->port_list); | |
4725 | INIT_LIST_HEAD(&phba->work_list); | |
4726 | init_waitqueue_head(&phba->wait_4_mlo_m_q); | |
4727 | ||
4728 | /* Initialize the wait queue head for the kernel thread */ | |
4729 | init_waitqueue_head(&phba->work_waitq); | |
4730 | ||
4731 | /* Initialize the scsi buffer list used by driver for scsi IO */ | |
4732 | spin_lock_init(&phba->scsi_buf_list_lock); | |
4733 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); | |
4734 | ||
4735 | /* Initialize the fabric iocb list */ | |
4736 | INIT_LIST_HEAD(&phba->fabric_iocb_list); | |
4737 | ||
4738 | /* Initialize list to save ELS buffers */ | |
4739 | INIT_LIST_HEAD(&phba->elsbuf); | |
4740 | ||
4741 | /* Initialize FCF connection rec list */ | |
4742 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); | |
4743 | ||
4744 | return 0; | |
4745 | } | |
4746 | ||
4747 | /** | |
4748 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. | |
4749 | * @phba: pointer to lpfc hba data structure. | |
4750 | * | |
4751 | * This routine is invoked to set up the driver internal resources after the | |
4752 | * device specific resource setup to support the HBA device it attached to. | |
4753 | * | |
4754 | * Return codes | |
af901ca1 | 4755 | * 0 - successful |
da0436e9 JS |
4756 | * other values - error |
4757 | **/ | |
4758 | static int | |
4759 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) | |
4760 | { | |
4761 | int error; | |
4762 | ||
4763 | /* Startup the kernel thread for this host adapter. */ | |
4764 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
4765 | "lpfc_worker_%d", phba->brd_no); | |
4766 | if (IS_ERR(phba->worker_thread)) { | |
4767 | error = PTR_ERR(phba->worker_thread); | |
4768 | return error; | |
3772a991 JS |
4769 | } |
4770 | ||
4771 | return 0; | |
4772 | } | |
4773 | ||
4774 | /** | |
4775 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. | |
4776 | * @phba: pointer to lpfc hba data structure. | |
4777 | * | |
4778 | * This routine is invoked to unset the driver internal resources set up after | |
4779 | * the device specific resource setup for supporting the HBA device it | |
4780 | * attached to. | |
4781 | **/ | |
4782 | static void | |
4783 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) | |
4784 | { | |
4785 | /* Stop kernel worker thread */ | |
4786 | kthread_stop(phba->worker_thread); | |
4787 | } | |
4788 | ||
4789 | /** | |
4790 | * lpfc_free_iocb_list - Free iocb list. | |
4791 | * @phba: pointer to lpfc hba data structure. | |
4792 | * | |
4793 | * This routine is invoked to free the driver's IOCB list and memory. | |
4794 | **/ | |
4795 | static void | |
4796 | lpfc_free_iocb_list(struct lpfc_hba *phba) | |
4797 | { | |
4798 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; | |
4799 | ||
4800 | spin_lock_irq(&phba->hbalock); | |
4801 | list_for_each_entry_safe(iocbq_entry, iocbq_next, | |
4802 | &phba->lpfc_iocb_list, list) { | |
4803 | list_del(&iocbq_entry->list); | |
4804 | kfree(iocbq_entry); | |
4805 | phba->total_iocbq_bufs--; | |
98c9ea5c | 4806 | } |
3772a991 JS |
4807 | spin_unlock_irq(&phba->hbalock); |
4808 | ||
4809 | return; | |
4810 | } | |
4811 | ||
4812 | /** | |
4813 | * lpfc_init_iocb_list - Allocate and initialize iocb list. | |
4814 | * @phba: pointer to lpfc hba data structure. | |
4815 | * | |
4816 | * This routine is invoked to allocate and initizlize the driver's IOCB | |
4817 | * list and set up the IOCB tag array accordingly. | |
4818 | * | |
4819 | * Return codes | |
af901ca1 | 4820 | * 0 - successful |
3772a991 JS |
4821 | * other values - error |
4822 | **/ | |
4823 | static int | |
4824 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) | |
4825 | { | |
4826 | struct lpfc_iocbq *iocbq_entry = NULL; | |
4827 | uint16_t iotag; | |
4828 | int i; | |
dea3101e | 4829 | |
4830 | /* Initialize and populate the iocb list per host. */ | |
4831 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); | |
3772a991 | 4832 | for (i = 0; i < iocb_count; i++) { |
dd00cc48 | 4833 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
dea3101e | 4834 | if (iocbq_entry == NULL) { |
4835 | printk(KERN_ERR "%s: only allocated %d iocbs of " | |
4836 | "expected %d count. Unloading driver.\n", | |
cadbd4a5 | 4837 | __func__, i, LPFC_IOCB_LIST_CNT); |
dea3101e | 4838 | goto out_free_iocbq; |
4839 | } | |
4840 | ||
604a3e30 JB |
4841 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
4842 | if (iotag == 0) { | |
3772a991 | 4843 | kfree(iocbq_entry); |
604a3e30 | 4844 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
3772a991 | 4845 | "Unloading driver.\n", __func__); |
604a3e30 JB |
4846 | goto out_free_iocbq; |
4847 | } | |
6d368e53 | 4848 | iocbq_entry->sli4_lxritag = NO_XRI; |
3772a991 | 4849 | iocbq_entry->sli4_xritag = NO_XRI; |
2e0fef85 JS |
4850 | |
4851 | spin_lock_irq(&phba->hbalock); | |
dea3101e | 4852 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
4853 | phba->total_iocbq_bufs++; | |
2e0fef85 | 4854 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 4855 | } |
4856 | ||
3772a991 | 4857 | return 0; |
dea3101e | 4858 | |
3772a991 JS |
4859 | out_free_iocbq: |
4860 | lpfc_free_iocb_list(phba); | |
dea3101e | 4861 | |
3772a991 JS |
4862 | return -ENOMEM; |
4863 | } | |
5e9d9b82 | 4864 | |
3772a991 | 4865 | /** |
da0436e9 JS |
4866 | * lpfc_free_sgl_list - Free sgl list. |
4867 | * @phba: pointer to lpfc hba data structure. | |
3772a991 | 4868 | * |
da0436e9 | 4869 | * This routine is invoked to free the driver's sgl list and memory. |
3772a991 | 4870 | **/ |
da0436e9 JS |
4871 | static void |
4872 | lpfc_free_sgl_list(struct lpfc_hba *phba) | |
3772a991 | 4873 | { |
da0436e9 JS |
4874 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
4875 | LIST_HEAD(sglq_list); | |
dea3101e | 4876 | |
da0436e9 JS |
4877 | spin_lock_irq(&phba->hbalock); |
4878 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); | |
4879 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 4880 | |
da0436e9 JS |
4881 | list_for_each_entry_safe(sglq_entry, sglq_next, |
4882 | &sglq_list, list) { | |
4883 | list_del(&sglq_entry->list); | |
4884 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); | |
4885 | kfree(sglq_entry); | |
4886 | phba->sli4_hba.total_sglq_bufs--; | |
4887 | } | |
da0436e9 JS |
4888 | kfree(phba->sli4_hba.lpfc_els_sgl_array); |
4889 | } | |
92d7f7b0 | 4890 | |
da0436e9 JS |
4891 | /** |
4892 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. | |
4893 | * @phba: pointer to lpfc hba data structure. | |
4894 | * | |
4895 | * This routine is invoked to allocate the driver's active sgl memory. | |
4896 | * This array will hold the sglq_entry's for active IOs. | |
4897 | **/ | |
4898 | static int | |
4899 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) | |
4900 | { | |
4901 | int size; | |
4902 | size = sizeof(struct lpfc_sglq *); | |
4903 | size *= phba->sli4_hba.max_cfg_param.max_xri; | |
4904 | ||
4905 | phba->sli4_hba.lpfc_sglq_active_list = | |
4906 | kzalloc(size, GFP_KERNEL); | |
4907 | if (!phba->sli4_hba.lpfc_sglq_active_list) | |
4908 | return -ENOMEM; | |
4909 | return 0; | |
3772a991 JS |
4910 | } |
4911 | ||
4912 | /** | |
da0436e9 | 4913 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
3772a991 JS |
4914 | * @phba: pointer to lpfc hba data structure. |
4915 | * | |
da0436e9 JS |
4916 | * This routine is invoked to walk through the array of active sglq entries |
4917 | * and free all of the resources. | |
4918 | * This is just a place holder for now. | |
3772a991 JS |
4919 | **/ |
4920 | static void | |
da0436e9 | 4921 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
3772a991 | 4922 | { |
da0436e9 | 4923 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
3772a991 JS |
4924 | } |
4925 | ||
4926 | /** | |
da0436e9 | 4927 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
3772a991 JS |
4928 | * @phba: pointer to lpfc hba data structure. |
4929 | * | |
da0436e9 JS |
4930 | * This routine is invoked to allocate and initizlize the driver's sgl |
4931 | * list and set up the sgl xritag tag array accordingly. | |
3772a991 JS |
4932 | * |
4933 | * Return codes | |
af901ca1 | 4934 | * 0 - successful |
da0436e9 | 4935 | * other values - error |
3772a991 JS |
4936 | **/ |
4937 | static int | |
da0436e9 | 4938 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
3772a991 | 4939 | { |
da0436e9 JS |
4940 | struct lpfc_sglq *sglq_entry = NULL; |
4941 | int i; | |
4942 | int els_xri_cnt; | |
4943 | ||
4944 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
4945 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
6d368e53 | 4946 | "2400 ELS XRI count %d.\n", |
da0436e9 JS |
4947 | els_xri_cnt); |
4948 | /* Initialize and populate the sglq list per host/VF. */ | |
4949 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); | |
4950 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
4951 | ||
4952 | /* Sanity check on XRI management */ | |
4953 | if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) { | |
4954 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4955 | "2562 No room left for SCSI XRI allocation: " | |
4956 | "max_xri=%d, els_xri=%d\n", | |
4957 | phba->sli4_hba.max_cfg_param.max_xri, | |
4958 | els_xri_cnt); | |
4959 | return -ENOMEM; | |
4960 | } | |
3772a991 | 4961 | |
da0436e9 JS |
4962 | /* Allocate memory for the ELS XRI management array */ |
4963 | phba->sli4_hba.lpfc_els_sgl_array = | |
4964 | kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt), | |
4965 | GFP_KERNEL); | |
0ff10d46 | 4966 | |
da0436e9 JS |
4967 | if (!phba->sli4_hba.lpfc_els_sgl_array) { |
4968 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4969 | "2401 Failed to allocate memory for ELS " | |
4970 | "XRI management array of size %d.\n", | |
4971 | els_xri_cnt); | |
4972 | return -ENOMEM; | |
4973 | } | |
2e0fef85 | 4974 | |
da0436e9 JS |
4975 | /* Keep the SCSI XRI into the XRI management array */ |
4976 | phba->sli4_hba.scsi_xri_max = | |
4977 | phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; | |
4978 | phba->sli4_hba.scsi_xri_cnt = 0; | |
da0436e9 JS |
4979 | phba->sli4_hba.lpfc_scsi_psb_array = |
4980 | kzalloc((sizeof(struct lpfc_scsi_buf *) * | |
4981 | phba->sli4_hba.scsi_xri_max), GFP_KERNEL); | |
4982 | ||
4983 | if (!phba->sli4_hba.lpfc_scsi_psb_array) { | |
4984 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4985 | "2563 Failed to allocate memory for SCSI " | |
4986 | "XRI management array of size %d.\n", | |
4987 | phba->sli4_hba.scsi_xri_max); | |
4988 | kfree(phba->sli4_hba.lpfc_els_sgl_array); | |
4989 | return -ENOMEM; | |
4990 | } | |
4991 | ||
4992 | for (i = 0; i < els_xri_cnt; i++) { | |
4993 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL); | |
4994 | if (sglq_entry == NULL) { | |
4995 | printk(KERN_ERR "%s: only allocated %d sgls of " | |
4996 | "expected %d count. Unloading driver.\n", | |
4997 | __func__, i, els_xri_cnt); | |
4998 | goto out_free_mem; | |
4999 | } | |
5000 | ||
da0436e9 JS |
5001 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
5002 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys); | |
5003 | if (sglq_entry->virt == NULL) { | |
5004 | kfree(sglq_entry); | |
5005 | printk(KERN_ERR "%s: failed to allocate mbuf.\n" | |
5006 | "Unloading driver.\n", __func__); | |
5007 | goto out_free_mem; | |
5008 | } | |
5009 | sglq_entry->sgl = sglq_entry->virt; | |
5010 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); | |
5011 | ||
5012 | /* The list order is used by later block SGL registraton */ | |
5013 | spin_lock_irq(&phba->hbalock); | |
0f65ff68 | 5014 | sglq_entry->state = SGL_FREED; |
da0436e9 JS |
5015 | list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list); |
5016 | phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry; | |
5017 | phba->sli4_hba.total_sglq_bufs++; | |
5018 | spin_unlock_irq(&phba->hbalock); | |
5019 | } | |
5020 | return 0; | |
5021 | ||
5022 | out_free_mem: | |
5023 | kfree(phba->sli4_hba.lpfc_scsi_psb_array); | |
5024 | lpfc_free_sgl_list(phba); | |
5025 | return -ENOMEM; | |
5026 | } | |
5027 | ||
5028 | /** | |
5029 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port | |
5030 | * @phba: pointer to lpfc hba data structure. | |
5031 | * | |
5032 | * This routine is invoked to post rpi header templates to the | |
88a2cfbb | 5033 | * port for those SLI4 ports that do not support extents. This routine |
da0436e9 | 5034 | * posts a PAGE_SIZE memory region to the port to hold up to |
88a2cfbb JS |
5035 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
5036 | * and should be called only when interrupts are disabled. | |
da0436e9 JS |
5037 | * |
5038 | * Return codes | |
af901ca1 | 5039 | * 0 - successful |
88a2cfbb | 5040 | * -ERROR - otherwise. |
da0436e9 JS |
5041 | **/ |
5042 | int | |
5043 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) | |
5044 | { | |
5045 | int rc = 0; | |
da0436e9 JS |
5046 | struct lpfc_rpi_hdr *rpi_hdr; |
5047 | ||
5048 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); | |
ff78d8f9 | 5049 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
6d368e53 | 5050 | return rc; |
6d368e53 JS |
5051 | if (phba->sli4_hba.extents_in_use) |
5052 | return -EIO; | |
da0436e9 JS |
5053 | |
5054 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
5055 | if (!rpi_hdr) { | |
5056 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5057 | "0391 Error during rpi post operation\n"); | |
5058 | lpfc_sli4_remove_rpis(phba); | |
5059 | rc = -ENODEV; | |
5060 | } | |
5061 | ||
5062 | return rc; | |
5063 | } | |
5064 | ||
5065 | /** | |
5066 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region | |
5067 | * @phba: pointer to lpfc hba data structure. | |
5068 | * | |
5069 | * This routine is invoked to allocate a single 4KB memory region to | |
5070 | * support rpis and stores them in the phba. This single region | |
5071 | * provides support for up to 64 rpis. The region is used globally | |
5072 | * by the device. | |
5073 | * | |
5074 | * Returns: | |
5075 | * A valid rpi hdr on success. | |
5076 | * A NULL pointer on any failure. | |
5077 | **/ | |
5078 | struct lpfc_rpi_hdr * | |
5079 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) | |
5080 | { | |
5081 | uint16_t rpi_limit, curr_rpi_range; | |
5082 | struct lpfc_dmabuf *dmabuf; | |
5083 | struct lpfc_rpi_hdr *rpi_hdr; | |
9589b062 | 5084 | uint32_t rpi_count; |
da0436e9 | 5085 | |
6d368e53 JS |
5086 | /* |
5087 | * If the SLI4 port supports extents, posting the rpi header isn't | |
5088 | * required. Set the expected maximum count and let the actual value | |
5089 | * get set when extents are fully allocated. | |
5090 | */ | |
5091 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
5092 | return NULL; | |
5093 | if (phba->sli4_hba.extents_in_use) | |
5094 | return NULL; | |
5095 | ||
5096 | /* The limit on the logical index is just the max_rpi count. */ | |
da0436e9 | 5097 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + |
6d368e53 | 5098 | phba->sli4_hba.max_cfg_param.max_rpi - 1; |
da0436e9 JS |
5099 | |
5100 | spin_lock_irq(&phba->hbalock); | |
6d368e53 JS |
5101 | /* |
5102 | * Establish the starting RPI in this header block. The starting | |
5103 | * rpi is normalized to a zero base because the physical rpi is | |
5104 | * port based. | |
5105 | */ | |
5106 | curr_rpi_range = phba->sli4_hba.next_rpi - | |
5107 | phba->sli4_hba.max_cfg_param.rpi_base; | |
da0436e9 JS |
5108 | spin_unlock_irq(&phba->hbalock); |
5109 | ||
5110 | /* | |
5111 | * The port has a limited number of rpis. The increment here | |
5112 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value | |
5113 | * and to allow the full max_rpi range per port. | |
5114 | */ | |
5115 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) | |
9589b062 JS |
5116 | rpi_count = rpi_limit - curr_rpi_range; |
5117 | else | |
5118 | rpi_count = LPFC_RPI_HDR_COUNT; | |
da0436e9 | 5119 | |
6d368e53 JS |
5120 | if (!rpi_count) |
5121 | return NULL; | |
da0436e9 JS |
5122 | /* |
5123 | * First allocate the protocol header region for the port. The | |
5124 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. | |
5125 | */ | |
5126 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
5127 | if (!dmabuf) | |
5128 | return NULL; | |
5129 | ||
5130 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
5131 | LPFC_HDR_TEMPLATE_SIZE, | |
5132 | &dmabuf->phys, | |
5133 | GFP_KERNEL); | |
5134 | if (!dmabuf->virt) { | |
5135 | rpi_hdr = NULL; | |
5136 | goto err_free_dmabuf; | |
5137 | } | |
5138 | ||
5139 | memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE); | |
5140 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { | |
5141 | rpi_hdr = NULL; | |
5142 | goto err_free_coherent; | |
5143 | } | |
5144 | ||
5145 | /* Save the rpi header data for cleanup later. */ | |
5146 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); | |
5147 | if (!rpi_hdr) | |
5148 | goto err_free_coherent; | |
5149 | ||
5150 | rpi_hdr->dmabuf = dmabuf; | |
5151 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; | |
5152 | rpi_hdr->page_count = 1; | |
5153 | spin_lock_irq(&phba->hbalock); | |
6d368e53 JS |
5154 | |
5155 | /* The rpi_hdr stores the logical index only. */ | |
5156 | rpi_hdr->start_rpi = curr_rpi_range; | |
da0436e9 JS |
5157 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
5158 | ||
5159 | /* | |
6d368e53 JS |
5160 | * The next_rpi stores the next logical module-64 rpi value used |
5161 | * to post physical rpis in subsequent rpi postings. | |
da0436e9 | 5162 | */ |
9589b062 | 5163 | phba->sli4_hba.next_rpi += rpi_count; |
da0436e9 JS |
5164 | spin_unlock_irq(&phba->hbalock); |
5165 | return rpi_hdr; | |
5166 | ||
5167 | err_free_coherent: | |
5168 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, | |
5169 | dmabuf->virt, dmabuf->phys); | |
5170 | err_free_dmabuf: | |
5171 | kfree(dmabuf); | |
5172 | return NULL; | |
5173 | } | |
5174 | ||
5175 | /** | |
5176 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions | |
5177 | * @phba: pointer to lpfc hba data structure. | |
5178 | * | |
5179 | * This routine is invoked to remove all memory resources allocated | |
6d368e53 JS |
5180 | * to support rpis for SLI4 ports not supporting extents. This routine |
5181 | * presumes the caller has released all rpis consumed by fabric or port | |
5182 | * logins and is prepared to have the header pages removed. | |
da0436e9 JS |
5183 | **/ |
5184 | void | |
5185 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) | |
5186 | { | |
5187 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; | |
5188 | ||
6d368e53 JS |
5189 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
5190 | goto exit; | |
5191 | ||
da0436e9 JS |
5192 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
5193 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { | |
5194 | list_del(&rpi_hdr->list); | |
5195 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, | |
5196 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); | |
5197 | kfree(rpi_hdr->dmabuf); | |
5198 | kfree(rpi_hdr); | |
5199 | } | |
6d368e53 JS |
5200 | exit: |
5201 | /* There are no rpis available to the port now. */ | |
5202 | phba->sli4_hba.next_rpi = 0; | |
da0436e9 JS |
5203 | } |
5204 | ||
5205 | /** | |
5206 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. | |
5207 | * @pdev: pointer to pci device data structure. | |
5208 | * | |
5209 | * This routine is invoked to allocate the driver hba data structure for an | |
5210 | * HBA device. If the allocation is successful, the phba reference to the | |
5211 | * PCI device data structure is set. | |
5212 | * | |
5213 | * Return codes | |
af901ca1 | 5214 | * pointer to @phba - successful |
da0436e9 JS |
5215 | * NULL - error |
5216 | **/ | |
5217 | static struct lpfc_hba * | |
5218 | lpfc_hba_alloc(struct pci_dev *pdev) | |
5219 | { | |
5220 | struct lpfc_hba *phba; | |
5221 | ||
5222 | /* Allocate memory for HBA structure */ | |
5223 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); | |
5224 | if (!phba) { | |
e34ccdfe | 5225 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
da0436e9 JS |
5226 | return NULL; |
5227 | } | |
5228 | ||
5229 | /* Set reference to PCI device in HBA structure */ | |
5230 | phba->pcidev = pdev; | |
5231 | ||
5232 | /* Assign an unused board number */ | |
5233 | phba->brd_no = lpfc_get_instance(); | |
5234 | if (phba->brd_no < 0) { | |
5235 | kfree(phba); | |
5236 | return NULL; | |
5237 | } | |
5238 | ||
4fede78f | 5239 | spin_lock_init(&phba->ct_ev_lock); |
f1c3b0fc JS |
5240 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
5241 | ||
da0436e9 JS |
5242 | return phba; |
5243 | } | |
5244 | ||
5245 | /** | |
5246 | * lpfc_hba_free - Free driver hba data structure with a device. | |
5247 | * @phba: pointer to lpfc hba data structure. | |
5248 | * | |
5249 | * This routine is invoked to free the driver hba data structure with an | |
5250 | * HBA device. | |
5251 | **/ | |
5252 | static void | |
5253 | lpfc_hba_free(struct lpfc_hba *phba) | |
5254 | { | |
5255 | /* Release the driver assigned board number */ | |
5256 | idr_remove(&lpfc_hba_index, phba->brd_no); | |
5257 | ||
5258 | kfree(phba); | |
5259 | return; | |
5260 | } | |
5261 | ||
5262 | /** | |
5263 | * lpfc_create_shost - Create hba physical port with associated scsi host. | |
5264 | * @phba: pointer to lpfc hba data structure. | |
5265 | * | |
5266 | * This routine is invoked to create HBA physical port and associate a SCSI | |
5267 | * host with it. | |
5268 | * | |
5269 | * Return codes | |
af901ca1 | 5270 | * 0 - successful |
da0436e9 JS |
5271 | * other values - error |
5272 | **/ | |
5273 | static int | |
5274 | lpfc_create_shost(struct lpfc_hba *phba) | |
5275 | { | |
5276 | struct lpfc_vport *vport; | |
5277 | struct Scsi_Host *shost; | |
5278 | ||
5279 | /* Initialize HBA FC structure */ | |
5280 | phba->fc_edtov = FF_DEF_EDTOV; | |
5281 | phba->fc_ratov = FF_DEF_RATOV; | |
5282 | phba->fc_altov = FF_DEF_ALTOV; | |
5283 | phba->fc_arbtov = FF_DEF_ARBTOV; | |
5284 | ||
d7c47992 | 5285 | atomic_set(&phba->sdev_cnt, 0); |
da0436e9 JS |
5286 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
5287 | if (!vport) | |
5288 | return -ENODEV; | |
5289 | ||
5290 | shost = lpfc_shost_from_vport(vport); | |
5291 | phba->pport = vport; | |
5292 | lpfc_debugfs_initialize(vport); | |
5293 | /* Put reference to SCSI host to driver's device private data */ | |
5294 | pci_set_drvdata(phba->pcidev, shost); | |
2e0fef85 | 5295 | |
3772a991 JS |
5296 | return 0; |
5297 | } | |
db2378e0 | 5298 | |
3772a991 JS |
5299 | /** |
5300 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. | |
5301 | * @phba: pointer to lpfc hba data structure. | |
5302 | * | |
5303 | * This routine is invoked to destroy HBA physical port and the associated | |
5304 | * SCSI host. | |
5305 | **/ | |
5306 | static void | |
5307 | lpfc_destroy_shost(struct lpfc_hba *phba) | |
5308 | { | |
5309 | struct lpfc_vport *vport = phba->pport; | |
5310 | ||
5311 | /* Destroy physical port that associated with the SCSI host */ | |
5312 | destroy_port(vport); | |
5313 | ||
5314 | return; | |
5315 | } | |
5316 | ||
5317 | /** | |
5318 | * lpfc_setup_bg - Setup Block guard structures and debug areas. | |
5319 | * @phba: pointer to lpfc hba data structure. | |
5320 | * @shost: the shost to be used to detect Block guard settings. | |
5321 | * | |
5322 | * This routine sets up the local Block guard protocol settings for @shost. | |
5323 | * This routine also allocates memory for debugging bg buffers. | |
5324 | **/ | |
5325 | static void | |
5326 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) | |
5327 | { | |
5328 | int pagecnt = 10; | |
5329 | if (lpfc_prot_mask && lpfc_prot_guard) { | |
5330 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5331 | "1478 Registering BlockGuard with the " | |
5332 | "SCSI layer\n"); | |
5333 | scsi_host_set_prot(shost, lpfc_prot_mask); | |
5334 | scsi_host_set_guard(shost, lpfc_prot_guard); | |
5335 | } | |
5336 | if (!_dump_buf_data) { | |
5337 | while (pagecnt) { | |
5338 | spin_lock_init(&_dump_buf_lock); | |
5339 | _dump_buf_data = | |
5340 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
5341 | if (_dump_buf_data) { | |
6a9c52cf JS |
5342 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5343 | "9043 BLKGRD: allocated %d pages for " | |
3772a991 JS |
5344 | "_dump_buf_data at 0x%p\n", |
5345 | (1 << pagecnt), _dump_buf_data); | |
5346 | _dump_buf_data_order = pagecnt; | |
5347 | memset(_dump_buf_data, 0, | |
5348 | ((1 << PAGE_SHIFT) << pagecnt)); | |
5349 | break; | |
5350 | } else | |
5351 | --pagecnt; | |
5352 | } | |
5353 | if (!_dump_buf_data_order) | |
6a9c52cf JS |
5354 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5355 | "9044 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
5356 | "memory for hexdump\n"); |
5357 | } else | |
6a9c52cf JS |
5358 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5359 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" | |
3772a991 JS |
5360 | "\n", _dump_buf_data); |
5361 | if (!_dump_buf_dif) { | |
5362 | while (pagecnt) { | |
5363 | _dump_buf_dif = | |
5364 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
5365 | if (_dump_buf_dif) { | |
6a9c52cf JS |
5366 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5367 | "9046 BLKGRD: allocated %d pages for " | |
3772a991 JS |
5368 | "_dump_buf_dif at 0x%p\n", |
5369 | (1 << pagecnt), _dump_buf_dif); | |
5370 | _dump_buf_dif_order = pagecnt; | |
5371 | memset(_dump_buf_dif, 0, | |
5372 | ((1 << PAGE_SHIFT) << pagecnt)); | |
5373 | break; | |
5374 | } else | |
5375 | --pagecnt; | |
5376 | } | |
5377 | if (!_dump_buf_dif_order) | |
6a9c52cf JS |
5378 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5379 | "9047 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
5380 | "memory for hexdump\n"); |
5381 | } else | |
6a9c52cf JS |
5382 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5383 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", | |
3772a991 JS |
5384 | _dump_buf_dif); |
5385 | } | |
5386 | ||
5387 | /** | |
5388 | * lpfc_post_init_setup - Perform necessary device post initialization setup. | |
5389 | * @phba: pointer to lpfc hba data structure. | |
5390 | * | |
5391 | * This routine is invoked to perform all the necessary post initialization | |
5392 | * setup for the device. | |
5393 | **/ | |
5394 | static void | |
5395 | lpfc_post_init_setup(struct lpfc_hba *phba) | |
5396 | { | |
5397 | struct Scsi_Host *shost; | |
5398 | struct lpfc_adapter_event_header adapter_event; | |
5399 | ||
5400 | /* Get the default values for Model Name and Description */ | |
5401 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
5402 | ||
5403 | /* | |
5404 | * hba setup may have changed the hba_queue_depth so we need to | |
5405 | * adjust the value of can_queue. | |
5406 | */ | |
5407 | shost = pci_get_drvdata(phba->pcidev); | |
5408 | shost->can_queue = phba->cfg_hba_queue_depth - 10; | |
5409 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) | |
5410 | lpfc_setup_bg(phba, shost); | |
5411 | ||
5412 | lpfc_host_attrib_init(shost); | |
5413 | ||
5414 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | |
5415 | spin_lock_irq(shost->host_lock); | |
5416 | lpfc_poll_start_timer(phba); | |
5417 | spin_unlock_irq(shost->host_lock); | |
5418 | } | |
5419 | ||
5420 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5421 | "0428 Perform SCSI scan\n"); | |
5422 | /* Send board arrival event to upper layer */ | |
5423 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; | |
5424 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; | |
5425 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
5426 | sizeof(adapter_event), | |
5427 | (char *) &adapter_event, | |
5428 | LPFC_NL_VENDOR_ID); | |
5429 | return; | |
5430 | } | |
5431 | ||
5432 | /** | |
5433 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. | |
5434 | * @phba: pointer to lpfc hba data structure. | |
5435 | * | |
5436 | * This routine is invoked to set up the PCI device memory space for device | |
5437 | * with SLI-3 interface spec. | |
5438 | * | |
5439 | * Return codes | |
af901ca1 | 5440 | * 0 - successful |
3772a991 JS |
5441 | * other values - error |
5442 | **/ | |
5443 | static int | |
5444 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) | |
5445 | { | |
5446 | struct pci_dev *pdev; | |
5447 | unsigned long bar0map_len, bar2map_len; | |
5448 | int i, hbq_count; | |
5449 | void *ptr; | |
5450 | int error = -ENODEV; | |
5451 | ||
5452 | /* Obtain PCI device reference */ | |
5453 | if (!phba->pcidev) | |
5454 | return error; | |
5455 | else | |
5456 | pdev = phba->pcidev; | |
5457 | ||
5458 | /* Set the device DMA mask size */ | |
8e68597d MR |
5459 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
5460 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
5461 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
5462 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
3772a991 | 5463 | return error; |
8e68597d MR |
5464 | } |
5465 | } | |
3772a991 JS |
5466 | |
5467 | /* Get the bus address of Bar0 and Bar2 and the number of bytes | |
5468 | * required by each mapping. | |
5469 | */ | |
5470 | phba->pci_bar0_map = pci_resource_start(pdev, 0); | |
5471 | bar0map_len = pci_resource_len(pdev, 0); | |
5472 | ||
5473 | phba->pci_bar2_map = pci_resource_start(pdev, 2); | |
5474 | bar2map_len = pci_resource_len(pdev, 2); | |
5475 | ||
5476 | /* Map HBA SLIM to a kernel virtual address. */ | |
5477 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); | |
5478 | if (!phba->slim_memmap_p) { | |
5479 | dev_printk(KERN_ERR, &pdev->dev, | |
5480 | "ioremap failed for SLIM memory.\n"); | |
5481 | goto out; | |
5482 | } | |
5483 | ||
5484 | /* Map HBA Control Registers to a kernel virtual address. */ | |
5485 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); | |
5486 | if (!phba->ctrl_regs_memmap_p) { | |
5487 | dev_printk(KERN_ERR, &pdev->dev, | |
5488 | "ioremap failed for HBA control registers.\n"); | |
5489 | goto out_iounmap_slim; | |
5490 | } | |
5491 | ||
5492 | /* Allocate memory for SLI-2 structures */ | |
5493 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, | |
5494 | SLI2_SLIM_SIZE, | |
5495 | &phba->slim2p.phys, | |
5496 | GFP_KERNEL); | |
5497 | if (!phba->slim2p.virt) | |
5498 | goto out_iounmap; | |
5499 | ||
5500 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); | |
5501 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); | |
7a470277 JS |
5502 | phba->mbox_ext = (phba->slim2p.virt + |
5503 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); | |
3772a991 JS |
5504 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
5505 | phba->IOCBs = (phba->slim2p.virt + | |
5506 | offsetof(struct lpfc_sli2_slim, IOCBs)); | |
5507 | ||
5508 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, | |
5509 | lpfc_sli_hbq_size(), | |
5510 | &phba->hbqslimp.phys, | |
5511 | GFP_KERNEL); | |
5512 | if (!phba->hbqslimp.virt) | |
5513 | goto out_free_slim; | |
5514 | ||
5515 | hbq_count = lpfc_sli_hbq_count(); | |
5516 | ptr = phba->hbqslimp.virt; | |
5517 | for (i = 0; i < hbq_count; ++i) { | |
5518 | phba->hbqs[i].hbq_virt = ptr; | |
5519 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
5520 | ptr += (lpfc_hbq_defs[i]->entry_count * | |
5521 | sizeof(struct lpfc_hbq_entry)); | |
5522 | } | |
5523 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; | |
5524 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; | |
5525 | ||
5526 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); | |
5527 | ||
5528 | INIT_LIST_HEAD(&phba->rb_pend_list); | |
5529 | ||
5530 | phba->MBslimaddr = phba->slim_memmap_p; | |
5531 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; | |
5532 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; | |
5533 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; | |
5534 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; | |
5535 | ||
5536 | return 0; | |
5537 | ||
5538 | out_free_slim: | |
5539 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
5540 | phba->slim2p.virt, phba->slim2p.phys); | |
5541 | out_iounmap: | |
5542 | iounmap(phba->ctrl_regs_memmap_p); | |
5543 | out_iounmap_slim: | |
5544 | iounmap(phba->slim_memmap_p); | |
5545 | out: | |
5546 | return error; | |
5547 | } | |
5548 | ||
5549 | /** | |
5550 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. | |
5551 | * @phba: pointer to lpfc hba data structure. | |
5552 | * | |
5553 | * This routine is invoked to unset the PCI device memory space for device | |
5554 | * with SLI-3 interface spec. | |
5555 | **/ | |
5556 | static void | |
5557 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) | |
5558 | { | |
5559 | struct pci_dev *pdev; | |
5560 | ||
5561 | /* Obtain PCI device reference */ | |
5562 | if (!phba->pcidev) | |
5563 | return; | |
5564 | else | |
5565 | pdev = phba->pcidev; | |
5566 | ||
5567 | /* Free coherent DMA memory allocated */ | |
5568 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
5569 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
5570 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
5571 | phba->slim2p.virt, phba->slim2p.phys); | |
5572 | ||
5573 | /* I/O memory unmap */ | |
5574 | iounmap(phba->ctrl_regs_memmap_p); | |
5575 | iounmap(phba->slim_memmap_p); | |
5576 | ||
5577 | return; | |
5578 | } | |
5579 | ||
5580 | /** | |
da0436e9 | 5581 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
3772a991 JS |
5582 | * @phba: pointer to lpfc hba data structure. |
5583 | * | |
da0436e9 JS |
5584 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
5585 | * done and check status. | |
3772a991 | 5586 | * |
da0436e9 | 5587 | * Return 0 if successful, otherwise -ENODEV. |
3772a991 | 5588 | **/ |
da0436e9 JS |
5589 | int |
5590 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) | |
3772a991 | 5591 | { |
2fcee4bf JS |
5592 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
5593 | struct lpfc_register reg_data; | |
5594 | int i, port_error = 0; | |
5595 | uint32_t if_type; | |
3772a991 | 5596 | |
9940b97b JS |
5597 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
5598 | memset(®_data, 0, sizeof(reg_data)); | |
2fcee4bf | 5599 | if (!phba->sli4_hba.PSMPHRregaddr) |
da0436e9 | 5600 | return -ENODEV; |
3772a991 | 5601 | |
da0436e9 JS |
5602 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
5603 | for (i = 0; i < 3000; i++) { | |
9940b97b JS |
5604 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
5605 | &portsmphr_reg.word0) || | |
5606 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { | |
2fcee4bf | 5607 | /* Port has a fatal POST error, break out */ |
da0436e9 JS |
5608 | port_error = -ENODEV; |
5609 | break; | |
5610 | } | |
2fcee4bf JS |
5611 | if (LPFC_POST_STAGE_PORT_READY == |
5612 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) | |
da0436e9 | 5613 | break; |
da0436e9 | 5614 | msleep(10); |
3772a991 JS |
5615 | } |
5616 | ||
2fcee4bf JS |
5617 | /* |
5618 | * If there was a port error during POST, then don't proceed with | |
5619 | * other register reads as the data may not be valid. Just exit. | |
5620 | */ | |
5621 | if (port_error) { | |
da0436e9 | 5622 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2fcee4bf JS |
5623 | "1408 Port Failed POST - portsmphr=0x%x, " |
5624 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " | |
5625 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", | |
5626 | portsmphr_reg.word0, | |
5627 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), | |
5628 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), | |
5629 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), | |
5630 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), | |
5631 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), | |
5632 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), | |
5633 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), | |
5634 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); | |
5635 | } else { | |
28baac74 | 5636 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2fcee4bf JS |
5637 | "2534 Device Info: SLIFamily=0x%x, " |
5638 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " | |
5639 | "SLIHint_2=0x%x, FT=0x%x\n", | |
28baac74 JS |
5640 | bf_get(lpfc_sli_intf_sli_family, |
5641 | &phba->sli4_hba.sli_intf), | |
5642 | bf_get(lpfc_sli_intf_slirev, | |
5643 | &phba->sli4_hba.sli_intf), | |
085c647c JS |
5644 | bf_get(lpfc_sli_intf_if_type, |
5645 | &phba->sli4_hba.sli_intf), | |
5646 | bf_get(lpfc_sli_intf_sli_hint1, | |
28baac74 | 5647 | &phba->sli4_hba.sli_intf), |
085c647c JS |
5648 | bf_get(lpfc_sli_intf_sli_hint2, |
5649 | &phba->sli4_hba.sli_intf), | |
5650 | bf_get(lpfc_sli_intf_func_type, | |
28baac74 | 5651 | &phba->sli4_hba.sli_intf)); |
2fcee4bf JS |
5652 | /* |
5653 | * Check for other Port errors during the initialization | |
5654 | * process. Fail the load if the port did not come up | |
5655 | * correctly. | |
5656 | */ | |
5657 | if_type = bf_get(lpfc_sli_intf_if_type, | |
5658 | &phba->sli4_hba.sli_intf); | |
5659 | switch (if_type) { | |
5660 | case LPFC_SLI_INTF_IF_TYPE_0: | |
5661 | phba->sli4_hba.ue_mask_lo = | |
5662 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); | |
5663 | phba->sli4_hba.ue_mask_hi = | |
5664 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); | |
5665 | uerrlo_reg.word0 = | |
5666 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); | |
5667 | uerrhi_reg.word0 = | |
5668 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); | |
5669 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || | |
5670 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { | |
5671 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5672 | "1422 Unrecoverable Error " | |
5673 | "Detected during POST " | |
5674 | "uerr_lo_reg=0x%x, " | |
5675 | "uerr_hi_reg=0x%x, " | |
5676 | "ue_mask_lo_reg=0x%x, " | |
5677 | "ue_mask_hi_reg=0x%x\n", | |
5678 | uerrlo_reg.word0, | |
5679 | uerrhi_reg.word0, | |
5680 | phba->sli4_hba.ue_mask_lo, | |
5681 | phba->sli4_hba.ue_mask_hi); | |
5682 | port_error = -ENODEV; | |
5683 | } | |
5684 | break; | |
5685 | case LPFC_SLI_INTF_IF_TYPE_2: | |
5686 | /* Final checks. The port status should be clean. */ | |
9940b97b JS |
5687 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
5688 | ®_data.word0) || | |
0558056c JS |
5689 | (bf_get(lpfc_sliport_status_err, ®_data) && |
5690 | !bf_get(lpfc_sliport_status_rn, ®_data))) { | |
2fcee4bf JS |
5691 | phba->work_status[0] = |
5692 | readl(phba->sli4_hba.u.if_type2. | |
5693 | ERR1regaddr); | |
5694 | phba->work_status[1] = | |
5695 | readl(phba->sli4_hba.u.if_type2. | |
5696 | ERR2regaddr); | |
5697 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5698 | "2888 Port Error Detected " | |
5699 | "during POST: " | |
5700 | "port status reg 0x%x, " | |
5701 | "port_smphr reg 0x%x, " | |
5702 | "error 1=0x%x, error 2=0x%x\n", | |
5703 | reg_data.word0, | |
5704 | portsmphr_reg.word0, | |
5705 | phba->work_status[0], | |
5706 | phba->work_status[1]); | |
5707 | port_error = -ENODEV; | |
5708 | } | |
5709 | break; | |
5710 | case LPFC_SLI_INTF_IF_TYPE_1: | |
5711 | default: | |
5712 | break; | |
5713 | } | |
28baac74 | 5714 | } |
da0436e9 JS |
5715 | return port_error; |
5716 | } | |
3772a991 | 5717 | |
da0436e9 JS |
5718 | /** |
5719 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. | |
5720 | * @phba: pointer to lpfc hba data structure. | |
2fcee4bf | 5721 | * @if_type: The SLI4 interface type getting configured. |
da0436e9 JS |
5722 | * |
5723 | * This routine is invoked to set up SLI4 BAR0 PCI config space register | |
5724 | * memory map. | |
5725 | **/ | |
5726 | static void | |
2fcee4bf JS |
5727 | lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type) |
5728 | { | |
5729 | switch (if_type) { | |
5730 | case LPFC_SLI_INTF_IF_TYPE_0: | |
5731 | phba->sli4_hba.u.if_type0.UERRLOregaddr = | |
5732 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; | |
5733 | phba->sli4_hba.u.if_type0.UERRHIregaddr = | |
5734 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; | |
5735 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = | |
5736 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; | |
5737 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = | |
5738 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; | |
5739 | phba->sli4_hba.SLIINTFregaddr = | |
5740 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; | |
5741 | break; | |
5742 | case LPFC_SLI_INTF_IF_TYPE_2: | |
5743 | phba->sli4_hba.u.if_type2.ERR1regaddr = | |
88a2cfbb JS |
5744 | phba->sli4_hba.conf_regs_memmap_p + |
5745 | LPFC_CTL_PORT_ER1_OFFSET; | |
2fcee4bf | 5746 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
88a2cfbb JS |
5747 | phba->sli4_hba.conf_regs_memmap_p + |
5748 | LPFC_CTL_PORT_ER2_OFFSET; | |
2fcee4bf | 5749 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
88a2cfbb JS |
5750 | phba->sli4_hba.conf_regs_memmap_p + |
5751 | LPFC_CTL_PORT_CTL_OFFSET; | |
2fcee4bf | 5752 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
88a2cfbb JS |
5753 | phba->sli4_hba.conf_regs_memmap_p + |
5754 | LPFC_CTL_PORT_STA_OFFSET; | |
2fcee4bf JS |
5755 | phba->sli4_hba.SLIINTFregaddr = |
5756 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; | |
5757 | phba->sli4_hba.PSMPHRregaddr = | |
88a2cfbb JS |
5758 | phba->sli4_hba.conf_regs_memmap_p + |
5759 | LPFC_CTL_PORT_SEM_OFFSET; | |
2fcee4bf JS |
5760 | phba->sli4_hba.RQDBregaddr = |
5761 | phba->sli4_hba.conf_regs_memmap_p + LPFC_RQ_DOORBELL; | |
5762 | phba->sli4_hba.WQDBregaddr = | |
5763 | phba->sli4_hba.conf_regs_memmap_p + LPFC_WQ_DOORBELL; | |
5764 | phba->sli4_hba.EQCQDBregaddr = | |
5765 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; | |
5766 | phba->sli4_hba.MQDBregaddr = | |
5767 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; | |
5768 | phba->sli4_hba.BMBXregaddr = | |
5769 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; | |
5770 | break; | |
5771 | case LPFC_SLI_INTF_IF_TYPE_1: | |
5772 | default: | |
5773 | dev_printk(KERN_ERR, &phba->pcidev->dev, | |
5774 | "FATAL - unsupported SLI4 interface type - %d\n", | |
5775 | if_type); | |
5776 | break; | |
5777 | } | |
da0436e9 | 5778 | } |
3772a991 | 5779 | |
da0436e9 JS |
5780 | /** |
5781 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. | |
5782 | * @phba: pointer to lpfc hba data structure. | |
5783 | * | |
5784 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) | |
5785 | * memory map. | |
5786 | **/ | |
5787 | static void | |
5788 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) | |
5789 | { | |
2fcee4bf JS |
5790 | phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
5791 | LPFC_SLIPORT_IF0_SMPHR; | |
da0436e9 | 5792 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 5793 | LPFC_HST_ISR0; |
da0436e9 | 5794 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 5795 | LPFC_HST_IMR0; |
da0436e9 | 5796 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 5797 | LPFC_HST_ISCR0; |
3772a991 JS |
5798 | } |
5799 | ||
5800 | /** | |
da0436e9 | 5801 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
3772a991 | 5802 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 5803 | * @vf: virtual function number |
3772a991 | 5804 | * |
da0436e9 JS |
5805 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
5806 | * based on the given viftual function number, @vf. | |
5807 | * | |
5808 | * Return 0 if successful, otherwise -ENODEV. | |
3772a991 | 5809 | **/ |
da0436e9 JS |
5810 | static int |
5811 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) | |
3772a991 | 5812 | { |
da0436e9 JS |
5813 | if (vf > LPFC_VIR_FUNC_MAX) |
5814 | return -ENODEV; | |
3772a991 | 5815 | |
da0436e9 JS |
5816 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
5817 | vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL); | |
5818 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5819 | vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL); | |
5820 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5821 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); | |
5822 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5823 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); | |
5824 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5825 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); | |
5826 | return 0; | |
3772a991 JS |
5827 | } |
5828 | ||
5829 | /** | |
da0436e9 | 5830 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
3772a991 JS |
5831 | * @phba: pointer to lpfc hba data structure. |
5832 | * | |
da0436e9 JS |
5833 | * This routine is invoked to create the bootstrap mailbox |
5834 | * region consistent with the SLI-4 interface spec. This | |
5835 | * routine allocates all memory necessary to communicate | |
5836 | * mailbox commands to the port and sets up all alignment | |
5837 | * needs. No locks are expected to be held when calling | |
5838 | * this routine. | |
3772a991 JS |
5839 | * |
5840 | * Return codes | |
af901ca1 | 5841 | * 0 - successful |
d439d286 | 5842 | * -ENOMEM - could not allocated memory. |
da0436e9 | 5843 | **/ |
3772a991 | 5844 | static int |
da0436e9 | 5845 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 5846 | { |
da0436e9 JS |
5847 | uint32_t bmbx_size; |
5848 | struct lpfc_dmabuf *dmabuf; | |
5849 | struct dma_address *dma_address; | |
5850 | uint32_t pa_addr; | |
5851 | uint64_t phys_addr; | |
5852 | ||
5853 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
5854 | if (!dmabuf) | |
5855 | return -ENOMEM; | |
3772a991 | 5856 | |
da0436e9 JS |
5857 | /* |
5858 | * The bootstrap mailbox region is comprised of 2 parts | |
5859 | * plus an alignment restriction of 16 bytes. | |
5860 | */ | |
5861 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); | |
5862 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
5863 | bmbx_size, | |
5864 | &dmabuf->phys, | |
5865 | GFP_KERNEL); | |
5866 | if (!dmabuf->virt) { | |
5867 | kfree(dmabuf); | |
5868 | return -ENOMEM; | |
3772a991 | 5869 | } |
da0436e9 | 5870 | memset(dmabuf->virt, 0, bmbx_size); |
3772a991 | 5871 | |
da0436e9 JS |
5872 | /* |
5873 | * Initialize the bootstrap mailbox pointers now so that the register | |
5874 | * operations are simple later. The mailbox dma address is required | |
5875 | * to be 16-byte aligned. Also align the virtual memory as each | |
5876 | * maibox is copied into the bmbx mailbox region before issuing the | |
5877 | * command to the port. | |
5878 | */ | |
5879 | phba->sli4_hba.bmbx.dmabuf = dmabuf; | |
5880 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; | |
5881 | ||
5882 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, | |
5883 | LPFC_ALIGN_16_BYTE); | |
5884 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, | |
5885 | LPFC_ALIGN_16_BYTE); | |
5886 | ||
5887 | /* | |
5888 | * Set the high and low physical addresses now. The SLI4 alignment | |
5889 | * requirement is 16 bytes and the mailbox is posted to the port | |
5890 | * as two 30-bit addresses. The other data is a bit marking whether | |
5891 | * the 30-bit address is the high or low address. | |
5892 | * Upcast bmbx aphys to 64bits so shift instruction compiles | |
5893 | * clean on 32 bit machines. | |
5894 | */ | |
5895 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
5896 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; | |
5897 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); | |
5898 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | | |
5899 | LPFC_BMBX_BIT1_ADDR_HI); | |
5900 | ||
5901 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); | |
5902 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | | |
5903 | LPFC_BMBX_BIT1_ADDR_LO); | |
5904 | return 0; | |
3772a991 JS |
5905 | } |
5906 | ||
5907 | /** | |
da0436e9 | 5908 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
3772a991 JS |
5909 | * @phba: pointer to lpfc hba data structure. |
5910 | * | |
da0436e9 JS |
5911 | * This routine is invoked to teardown the bootstrap mailbox |
5912 | * region and release all host resources. This routine requires | |
5913 | * the caller to ensure all mailbox commands recovered, no | |
5914 | * additional mailbox comands are sent, and interrupts are disabled | |
5915 | * before calling this routine. | |
5916 | * | |
5917 | **/ | |
3772a991 | 5918 | static void |
da0436e9 | 5919 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 5920 | { |
da0436e9 JS |
5921 | dma_free_coherent(&phba->pcidev->dev, |
5922 | phba->sli4_hba.bmbx.bmbx_size, | |
5923 | phba->sli4_hba.bmbx.dmabuf->virt, | |
5924 | phba->sli4_hba.bmbx.dmabuf->phys); | |
5925 | ||
5926 | kfree(phba->sli4_hba.bmbx.dmabuf); | |
5927 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); | |
3772a991 JS |
5928 | } |
5929 | ||
5930 | /** | |
da0436e9 | 5931 | * lpfc_sli4_read_config - Get the config parameters. |
3772a991 JS |
5932 | * @phba: pointer to lpfc hba data structure. |
5933 | * | |
da0436e9 JS |
5934 | * This routine is invoked to read the configuration parameters from the HBA. |
5935 | * The configuration parameters are used to set the base and maximum values | |
5936 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource | |
5937 | * allocation for the port. | |
3772a991 JS |
5938 | * |
5939 | * Return codes | |
af901ca1 | 5940 | * 0 - successful |
25985edc | 5941 | * -ENOMEM - No available memory |
d439d286 | 5942 | * -EIO - The mailbox failed to complete successfully. |
3772a991 | 5943 | **/ |
ff78d8f9 | 5944 | int |
da0436e9 | 5945 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
3772a991 | 5946 | { |
da0436e9 JS |
5947 | LPFC_MBOXQ_t *pmb; |
5948 | struct lpfc_mbx_read_config *rd_config; | |
912e3acd JS |
5949 | union lpfc_sli4_cfg_shdr *shdr; |
5950 | uint32_t shdr_status, shdr_add_status; | |
5951 | struct lpfc_mbx_get_func_cfg *get_func_cfg; | |
5952 | struct lpfc_rsrc_desc_fcfcoe *desc; | |
5953 | uint32_t desc_count; | |
5954 | int length, i, rc = 0; | |
3772a991 | 5955 | |
da0436e9 JS |
5956 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
5957 | if (!pmb) { | |
5958 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5959 | "2011 Unable to allocate memory for issuing " | |
5960 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
5961 | return -ENOMEM; | |
3772a991 JS |
5962 | } |
5963 | ||
da0436e9 | 5964 | lpfc_read_config(phba, pmb); |
3772a991 | 5965 | |
da0436e9 JS |
5966 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
5967 | if (rc != MBX_SUCCESS) { | |
5968 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5969 | "2012 Mailbox failed , mbxCmd x%x " | |
5970 | "READ_CONFIG, mbxStatus x%x\n", | |
5971 | bf_get(lpfc_mqe_command, &pmb->u.mqe), | |
5972 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); | |
5973 | rc = -EIO; | |
5974 | } else { | |
5975 | rd_config = &pmb->u.mqe.un.rd_config; | |
ff78d8f9 JS |
5976 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
5977 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; | |
5978 | phba->sli4_hba.lnk_info.lnk_tp = | |
5979 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); | |
5980 | phba->sli4_hba.lnk_info.lnk_no = | |
5981 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); | |
5982 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
5983 | "3081 lnk_type:%d, lnk_numb:%d\n", | |
5984 | phba->sli4_hba.lnk_info.lnk_tp, | |
5985 | phba->sli4_hba.lnk_info.lnk_no); | |
5986 | } else | |
5987 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
5988 | "3082 Mailbox (x%x) returned ldv:x0\n", | |
5989 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); | |
6d368e53 JS |
5990 | phba->sli4_hba.extents_in_use = |
5991 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); | |
da0436e9 JS |
5992 | phba->sli4_hba.max_cfg_param.max_xri = |
5993 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); | |
5994 | phba->sli4_hba.max_cfg_param.xri_base = | |
5995 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); | |
5996 | phba->sli4_hba.max_cfg_param.max_vpi = | |
5997 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); | |
5998 | phba->sli4_hba.max_cfg_param.vpi_base = | |
5999 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); | |
6000 | phba->sli4_hba.max_cfg_param.max_rpi = | |
6001 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); | |
6002 | phba->sli4_hba.max_cfg_param.rpi_base = | |
6003 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); | |
6004 | phba->sli4_hba.max_cfg_param.max_vfi = | |
6005 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); | |
6006 | phba->sli4_hba.max_cfg_param.vfi_base = | |
6007 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); | |
6008 | phba->sli4_hba.max_cfg_param.max_fcfi = | |
6009 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); | |
da0436e9 JS |
6010 | phba->sli4_hba.max_cfg_param.max_eq = |
6011 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); | |
6012 | phba->sli4_hba.max_cfg_param.max_rq = | |
6013 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); | |
6014 | phba->sli4_hba.max_cfg_param.max_wq = | |
6015 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); | |
6016 | phba->sli4_hba.max_cfg_param.max_cq = | |
6017 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); | |
6018 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); | |
6019 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; | |
6020 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; | |
6021 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; | |
6022 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base; | |
5ffc266e JS |
6023 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
6024 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; | |
da0436e9 JS |
6025 | phba->max_vports = phba->max_vpi; |
6026 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
6d368e53 JS |
6027 | "2003 cfg params Extents? %d " |
6028 | "XRI(B:%d M:%d), " | |
da0436e9 JS |
6029 | "VPI(B:%d M:%d) " |
6030 | "VFI(B:%d M:%d) " | |
6031 | "RPI(B:%d M:%d) " | |
6d368e53 JS |
6032 | "FCFI(Count:%d)\n", |
6033 | phba->sli4_hba.extents_in_use, | |
da0436e9 JS |
6034 | phba->sli4_hba.max_cfg_param.xri_base, |
6035 | phba->sli4_hba.max_cfg_param.max_xri, | |
6036 | phba->sli4_hba.max_cfg_param.vpi_base, | |
6037 | phba->sli4_hba.max_cfg_param.max_vpi, | |
6038 | phba->sli4_hba.max_cfg_param.vfi_base, | |
6039 | phba->sli4_hba.max_cfg_param.max_vfi, | |
6040 | phba->sli4_hba.max_cfg_param.rpi_base, | |
6041 | phba->sli4_hba.max_cfg_param.max_rpi, | |
da0436e9 | 6042 | phba->sli4_hba.max_cfg_param.max_fcfi); |
3772a991 | 6043 | } |
912e3acd JS |
6044 | |
6045 | if (rc) | |
6046 | goto read_cfg_out; | |
da0436e9 JS |
6047 | |
6048 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ | |
b92938b4 JS |
6049 | if (phba->cfg_hba_queue_depth > |
6050 | (phba->sli4_hba.max_cfg_param.max_xri - | |
6051 | lpfc_sli4_get_els_iocb_cnt(phba))) | |
da0436e9 | 6052 | phba->cfg_hba_queue_depth = |
b92938b4 JS |
6053 | phba->sli4_hba.max_cfg_param.max_xri - |
6054 | lpfc_sli4_get_els_iocb_cnt(phba); | |
912e3acd JS |
6055 | |
6056 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
6057 | LPFC_SLI_INTF_IF_TYPE_2) | |
6058 | goto read_cfg_out; | |
6059 | ||
6060 | /* get the pf# and vf# for SLI4 if_type 2 port */ | |
6061 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - | |
6062 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
6063 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, | |
6064 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, | |
6065 | length, LPFC_SLI4_MBX_EMBED); | |
6066 | ||
6067 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
6068 | shdr = (union lpfc_sli4_cfg_shdr *) | |
6069 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; | |
6070 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
6071 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
6072 | if (rc || shdr_status || shdr_add_status) { | |
6073 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6074 | "3026 Mailbox failed , mbxCmd x%x " | |
6075 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", | |
6076 | bf_get(lpfc_mqe_command, &pmb->u.mqe), | |
6077 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); | |
6078 | rc = -EIO; | |
6079 | goto read_cfg_out; | |
6080 | } | |
6081 | ||
6082 | /* search for fc_fcoe resrouce descriptor */ | |
6083 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; | |
6084 | desc_count = get_func_cfg->func_cfg.rsrc_desc_count; | |
6085 | ||
6086 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { | |
6087 | desc = (struct lpfc_rsrc_desc_fcfcoe *) | |
6088 | &get_func_cfg->func_cfg.desc[i]; | |
6089 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == | |
6090 | bf_get(lpfc_rsrc_desc_pcie_type, desc)) { | |
6091 | phba->sli4_hba.iov.pf_number = | |
6092 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); | |
6093 | phba->sli4_hba.iov.vf_number = | |
6094 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); | |
6095 | break; | |
6096 | } | |
6097 | } | |
6098 | ||
6099 | if (i < LPFC_RSRC_DESC_MAX_NUM) | |
6100 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
6101 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " | |
6102 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, | |
6103 | phba->sli4_hba.iov.vf_number); | |
6104 | else { | |
6105 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6106 | "3028 GET_FUNCTION_CONFIG: failed to find " | |
6107 | "Resrouce Descriptor:x%x\n", | |
6108 | LPFC_RSRC_DESC_TYPE_FCFCOE); | |
6109 | rc = -EIO; | |
6110 | } | |
6111 | ||
6112 | read_cfg_out: | |
6113 | mempool_free(pmb, phba->mbox_mem_pool); | |
da0436e9 | 6114 | return rc; |
3772a991 JS |
6115 | } |
6116 | ||
6117 | /** | |
2fcee4bf | 6118 | * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port. |
3772a991 JS |
6119 | * @phba: pointer to lpfc hba data structure. |
6120 | * | |
2fcee4bf JS |
6121 | * This routine is invoked to setup the port-side endian order when |
6122 | * the port if_type is 0. This routine has no function for other | |
6123 | * if_types. | |
da0436e9 JS |
6124 | * |
6125 | * Return codes | |
af901ca1 | 6126 | * 0 - successful |
25985edc | 6127 | * -ENOMEM - No available memory |
d439d286 | 6128 | * -EIO - The mailbox failed to complete successfully. |
3772a991 | 6129 | **/ |
da0436e9 JS |
6130 | static int |
6131 | lpfc_setup_endian_order(struct lpfc_hba *phba) | |
3772a991 | 6132 | { |
da0436e9 | 6133 | LPFC_MBOXQ_t *mboxq; |
2fcee4bf | 6134 | uint32_t if_type, rc = 0; |
da0436e9 JS |
6135 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
6136 | HOST_ENDIAN_HIGH_WORD1}; | |
3772a991 | 6137 | |
2fcee4bf JS |
6138 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
6139 | switch (if_type) { | |
6140 | case LPFC_SLI_INTF_IF_TYPE_0: | |
6141 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, | |
6142 | GFP_KERNEL); | |
6143 | if (!mboxq) { | |
6144 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6145 | "0492 Unable to allocate memory for " | |
6146 | "issuing SLI_CONFIG_SPECIAL mailbox " | |
6147 | "command\n"); | |
6148 | return -ENOMEM; | |
6149 | } | |
3772a991 | 6150 | |
2fcee4bf JS |
6151 | /* |
6152 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first | |
6153 | * two words to contain special data values and no other data. | |
6154 | */ | |
6155 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
6156 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); | |
6157 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6158 | if (rc != MBX_SUCCESS) { | |
6159 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6160 | "0493 SLI_CONFIG_SPECIAL mailbox " | |
6161 | "failed with status x%x\n", | |
6162 | rc); | |
6163 | rc = -EIO; | |
6164 | } | |
6165 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6166 | break; | |
6167 | case LPFC_SLI_INTF_IF_TYPE_2: | |
6168 | case LPFC_SLI_INTF_IF_TYPE_1: | |
6169 | default: | |
6170 | break; | |
da0436e9 | 6171 | } |
da0436e9 | 6172 | return rc; |
3772a991 JS |
6173 | } |
6174 | ||
6175 | /** | |
5350d872 | 6176 | * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts |
3772a991 JS |
6177 | * @phba: pointer to lpfc hba data structure. |
6178 | * | |
5350d872 JS |
6179 | * This routine is invoked to check the user settable queue counts for EQs and |
6180 | * CQs. after this routine is called the counts will be set to valid values that | |
6181 | * adhere to the constraints of the system's interrupt vectors and the port's | |
6182 | * queue resources. | |
da0436e9 JS |
6183 | * |
6184 | * Return codes | |
af901ca1 | 6185 | * 0 - successful |
25985edc | 6186 | * -ENOMEM - No available memory |
3772a991 | 6187 | **/ |
da0436e9 | 6188 | static int |
5350d872 | 6189 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
3772a991 | 6190 | { |
da0436e9 JS |
6191 | int cfg_fcp_wq_count; |
6192 | int cfg_fcp_eq_count; | |
3772a991 | 6193 | |
da0436e9 JS |
6194 | /* |
6195 | * Sanity check for confiugred queue parameters against the run-time | |
6196 | * device parameters | |
6197 | */ | |
3772a991 | 6198 | |
da0436e9 JS |
6199 | /* Sanity check on FCP fast-path WQ parameters */ |
6200 | cfg_fcp_wq_count = phba->cfg_fcp_wq_count; | |
6201 | if (cfg_fcp_wq_count > | |
6202 | (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) { | |
6203 | cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq - | |
6204 | LPFC_SP_WQN_DEF; | |
6205 | if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) { | |
6206 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6207 | "2581 Not enough WQs (%d) from " | |
6208 | "the pci function for supporting " | |
6209 | "FCP WQs (%d)\n", | |
6210 | phba->sli4_hba.max_cfg_param.max_wq, | |
6211 | phba->cfg_fcp_wq_count); | |
6212 | goto out_error; | |
6213 | } | |
6214 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6215 | "2582 Not enough WQs (%d) from the pci " | |
6216 | "function for supporting the requested " | |
6217 | "FCP WQs (%d), the actual FCP WQs can " | |
6218 | "be supported: %d\n", | |
6219 | phba->sli4_hba.max_cfg_param.max_wq, | |
6220 | phba->cfg_fcp_wq_count, cfg_fcp_wq_count); | |
6221 | } | |
6222 | /* The actual number of FCP work queues adopted */ | |
6223 | phba->cfg_fcp_wq_count = cfg_fcp_wq_count; | |
6224 | ||
6225 | /* Sanity check on FCP fast-path EQ parameters */ | |
6226 | cfg_fcp_eq_count = phba->cfg_fcp_eq_count; | |
6227 | if (cfg_fcp_eq_count > | |
6228 | (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) { | |
6229 | cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq - | |
6230 | LPFC_SP_EQN_DEF; | |
6231 | if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) { | |
6232 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6233 | "2574 Not enough EQs (%d) from the " | |
6234 | "pci function for supporting FCP " | |
6235 | "EQs (%d)\n", | |
6236 | phba->sli4_hba.max_cfg_param.max_eq, | |
6237 | phba->cfg_fcp_eq_count); | |
6238 | goto out_error; | |
6239 | } | |
6240 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6241 | "2575 Not enough EQs (%d) from the pci " | |
6242 | "function for supporting the requested " | |
6243 | "FCP EQs (%d), the actual FCP EQs can " | |
6244 | "be supported: %d\n", | |
6245 | phba->sli4_hba.max_cfg_param.max_eq, | |
6246 | phba->cfg_fcp_eq_count, cfg_fcp_eq_count); | |
6247 | } | |
6248 | /* It does not make sense to have more EQs than WQs */ | |
6249 | if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) { | |
6250 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6a9c52cf JS |
6251 | "2593 The FCP EQ count(%d) cannot be greater " |
6252 | "than the FCP WQ count(%d), limiting the " | |
6253 | "FCP EQ count to %d\n", cfg_fcp_eq_count, | |
da0436e9 JS |
6254 | phba->cfg_fcp_wq_count, |
6255 | phba->cfg_fcp_wq_count); | |
6256 | cfg_fcp_eq_count = phba->cfg_fcp_wq_count; | |
6257 | } | |
6258 | /* The actual number of FCP event queues adopted */ | |
6259 | phba->cfg_fcp_eq_count = cfg_fcp_eq_count; | |
6260 | /* The overall number of event queues used */ | |
6261 | phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF; | |
3772a991 | 6262 | |
da0436e9 JS |
6263 | /* Get EQ depth from module parameter, fake the default for now */ |
6264 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; | |
6265 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; | |
3772a991 | 6266 | |
5350d872 JS |
6267 | /* Get CQ depth from module parameter, fake the default for now */ |
6268 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; | |
6269 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; | |
6270 | ||
6271 | return 0; | |
6272 | out_error: | |
6273 | return -ENOMEM; | |
6274 | } | |
6275 | ||
6276 | /** | |
6277 | * lpfc_sli4_queue_create - Create all the SLI4 queues | |
6278 | * @phba: pointer to lpfc hba data structure. | |
6279 | * | |
6280 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA | |
6281 | * operation. For each SLI4 queue type, the parameters such as queue entry | |
6282 | * count (queue depth) shall be taken from the module parameter. For now, | |
6283 | * we just use some constant number as place holder. | |
6284 | * | |
6285 | * Return codes | |
6286 | * 0 - sucessful | |
6287 | * -ENOMEM - No availble memory | |
6288 | * -EIO - The mailbox failed to complete successfully. | |
6289 | **/ | |
6290 | int | |
6291 | lpfc_sli4_queue_create(struct lpfc_hba *phba) | |
6292 | { | |
6293 | struct lpfc_queue *qdesc; | |
6294 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; | |
6295 | ||
6296 | /* | |
6297 | * Create Event Queues (EQs) | |
6298 | */ | |
6299 | ||
da0436e9 JS |
6300 | /* Create slow path event queue */ |
6301 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | |
6302 | phba->sli4_hba.eq_ecount); | |
6303 | if (!qdesc) { | |
6304 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6305 | "0496 Failed allocate slow-path EQ\n"); | |
6306 | goto out_error; | |
6307 | } | |
6308 | phba->sli4_hba.sp_eq = qdesc; | |
6309 | ||
5350d872 JS |
6310 | /* |
6311 | * Create fast-path FCP Event Queue(s). The cfg_fcp_eq_count can be | |
6312 | * zero whenever there is exactly one interrupt vector. This is not | |
6313 | * an error. | |
6314 | */ | |
6315 | if (phba->cfg_fcp_eq_count) { | |
6316 | phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) * | |
6317 | phba->cfg_fcp_eq_count), GFP_KERNEL); | |
6318 | if (!phba->sli4_hba.fp_eq) { | |
6319 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6320 | "2576 Failed allocate memory for " | |
6321 | "fast-path EQ record array\n"); | |
6322 | goto out_free_sp_eq; | |
6323 | } | |
da0436e9 JS |
6324 | } |
6325 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
6326 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | |
6327 | phba->sli4_hba.eq_ecount); | |
6328 | if (!qdesc) { | |
6329 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6330 | "0497 Failed allocate fast-path EQ\n"); | |
6331 | goto out_free_fp_eq; | |
6332 | } | |
6333 | phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc; | |
6334 | } | |
6335 | ||
6336 | /* | |
6337 | * Create Complete Queues (CQs) | |
6338 | */ | |
6339 | ||
da0436e9 JS |
6340 | /* Create slow-path Mailbox Command Complete Queue */ |
6341 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
6342 | phba->sli4_hba.cq_ecount); | |
6343 | if (!qdesc) { | |
6344 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6345 | "0500 Failed allocate slow-path mailbox CQ\n"); | |
6346 | goto out_free_fp_eq; | |
6347 | } | |
6348 | phba->sli4_hba.mbx_cq = qdesc; | |
6349 | ||
6350 | /* Create slow-path ELS Complete Queue */ | |
6351 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
6352 | phba->sli4_hba.cq_ecount); | |
6353 | if (!qdesc) { | |
6354 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6355 | "0501 Failed allocate slow-path ELS CQ\n"); | |
6356 | goto out_free_mbx_cq; | |
6357 | } | |
6358 | phba->sli4_hba.els_cq = qdesc; | |
6359 | ||
da0436e9 | 6360 | |
5350d872 JS |
6361 | /* |
6362 | * Create fast-path FCP Completion Queue(s), one-to-one with FCP EQs. | |
6363 | * If there are no FCP EQs then create exactly one FCP CQ. | |
6364 | */ | |
6365 | if (phba->cfg_fcp_eq_count) | |
6366 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * | |
6367 | phba->cfg_fcp_eq_count), | |
6368 | GFP_KERNEL); | |
6369 | else | |
6370 | phba->sli4_hba.fcp_cq = kzalloc(sizeof(struct lpfc_queue *), | |
6371 | GFP_KERNEL); | |
da0436e9 JS |
6372 | if (!phba->sli4_hba.fcp_cq) { |
6373 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6374 | "2577 Failed allocate memory for fast-path " | |
6375 | "CQ record array\n"); | |
4d9ab994 | 6376 | goto out_free_els_cq; |
da0436e9 | 6377 | } |
5350d872 JS |
6378 | fcp_cqidx = 0; |
6379 | do { | |
da0436e9 JS |
6380 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
6381 | phba->sli4_hba.cq_ecount); | |
6382 | if (!qdesc) { | |
6383 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6384 | "0499 Failed allocate fast-path FCP " | |
6385 | "CQ (%d)\n", fcp_cqidx); | |
6386 | goto out_free_fcp_cq; | |
6387 | } | |
6388 | phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc; | |
5350d872 | 6389 | } while (++fcp_cqidx < phba->cfg_fcp_eq_count); |
da0436e9 JS |
6390 | |
6391 | /* Create Mailbox Command Queue */ | |
6392 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; | |
6393 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; | |
6394 | ||
6395 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, | |
6396 | phba->sli4_hba.mq_ecount); | |
6397 | if (!qdesc) { | |
6398 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6399 | "0505 Failed allocate slow-path MQ\n"); | |
6400 | goto out_free_fcp_cq; | |
6401 | } | |
6402 | phba->sli4_hba.mbx_wq = qdesc; | |
6403 | ||
6404 | /* | |
6405 | * Create all the Work Queues (WQs) | |
6406 | */ | |
6407 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; | |
6408 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; | |
6409 | ||
6410 | /* Create slow-path ELS Work Queue */ | |
6411 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
6412 | phba->sli4_hba.wq_ecount); | |
6413 | if (!qdesc) { | |
6414 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6415 | "0504 Failed allocate slow-path ELS WQ\n"); | |
6416 | goto out_free_mbx_wq; | |
6417 | } | |
6418 | phba->sli4_hba.els_wq = qdesc; | |
6419 | ||
6420 | /* Create fast-path FCP Work Queue(s) */ | |
6421 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * | |
6422 | phba->cfg_fcp_wq_count), GFP_KERNEL); | |
6423 | if (!phba->sli4_hba.fcp_wq) { | |
6424 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6425 | "2578 Failed allocate memory for fast-path " | |
6426 | "WQ record array\n"); | |
6427 | goto out_free_els_wq; | |
6428 | } | |
6429 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { | |
6430 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
6431 | phba->sli4_hba.wq_ecount); | |
6432 | if (!qdesc) { | |
6433 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6434 | "0503 Failed allocate fast-path FCP " | |
6435 | "WQ (%d)\n", fcp_wqidx); | |
6436 | goto out_free_fcp_wq; | |
6437 | } | |
6438 | phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc; | |
6439 | } | |
6440 | ||
6441 | /* | |
6442 | * Create Receive Queue (RQ) | |
6443 | */ | |
6444 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; | |
6445 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; | |
6446 | ||
6447 | /* Create Receive Queue for header */ | |
6448 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
6449 | phba->sli4_hba.rq_ecount); | |
6450 | if (!qdesc) { | |
6451 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6452 | "0506 Failed allocate receive HRQ\n"); | |
6453 | goto out_free_fcp_wq; | |
6454 | } | |
6455 | phba->sli4_hba.hdr_rq = qdesc; | |
6456 | ||
6457 | /* Create Receive Queue for data */ | |
6458 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
6459 | phba->sli4_hba.rq_ecount); | |
6460 | if (!qdesc) { | |
6461 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6462 | "0507 Failed allocate receive DRQ\n"); | |
6463 | goto out_free_hdr_rq; | |
6464 | } | |
6465 | phba->sli4_hba.dat_rq = qdesc; | |
6466 | ||
6467 | return 0; | |
6468 | ||
6469 | out_free_hdr_rq: | |
6470 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); | |
6471 | phba->sli4_hba.hdr_rq = NULL; | |
6472 | out_free_fcp_wq: | |
6473 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) { | |
6474 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]); | |
6475 | phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL; | |
6476 | } | |
6477 | kfree(phba->sli4_hba.fcp_wq); | |
6478 | out_free_els_wq: | |
6479 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); | |
6480 | phba->sli4_hba.els_wq = NULL; | |
6481 | out_free_mbx_wq: | |
6482 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); | |
6483 | phba->sli4_hba.mbx_wq = NULL; | |
6484 | out_free_fcp_cq: | |
6485 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) { | |
6486 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]); | |
6487 | phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL; | |
6488 | } | |
6489 | kfree(phba->sli4_hba.fcp_cq); | |
da0436e9 JS |
6490 | out_free_els_cq: |
6491 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); | |
6492 | phba->sli4_hba.els_cq = NULL; | |
6493 | out_free_mbx_cq: | |
6494 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); | |
6495 | phba->sli4_hba.mbx_cq = NULL; | |
6496 | out_free_fp_eq: | |
6497 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) { | |
6498 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]); | |
6499 | phba->sli4_hba.fp_eq[fcp_eqidx] = NULL; | |
6500 | } | |
6501 | kfree(phba->sli4_hba.fp_eq); | |
6502 | out_free_sp_eq: | |
6503 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); | |
6504 | phba->sli4_hba.sp_eq = NULL; | |
6505 | out_error: | |
6506 | return -ENOMEM; | |
6507 | } | |
6508 | ||
6509 | /** | |
6510 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues | |
6511 | * @phba: pointer to lpfc hba data structure. | |
6512 | * | |
6513 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA | |
6514 | * operation. | |
6515 | * | |
6516 | * Return codes | |
af901ca1 | 6517 | * 0 - successful |
25985edc | 6518 | * -ENOMEM - No available memory |
d439d286 | 6519 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 | 6520 | **/ |
5350d872 | 6521 | void |
da0436e9 JS |
6522 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
6523 | { | |
6524 | int fcp_qidx; | |
6525 | ||
6526 | /* Release mailbox command work queue */ | |
6527 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); | |
6528 | phba->sli4_hba.mbx_wq = NULL; | |
6529 | ||
6530 | /* Release ELS work queue */ | |
6531 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); | |
6532 | phba->sli4_hba.els_wq = NULL; | |
6533 | ||
6534 | /* Release FCP work queue */ | |
6535 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) | |
6536 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]); | |
6537 | kfree(phba->sli4_hba.fcp_wq); | |
6538 | phba->sli4_hba.fcp_wq = NULL; | |
6539 | ||
6540 | /* Release unsolicited receive queue */ | |
6541 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); | |
6542 | phba->sli4_hba.hdr_rq = NULL; | |
6543 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); | |
6544 | phba->sli4_hba.dat_rq = NULL; | |
6545 | ||
da0436e9 JS |
6546 | /* Release ELS complete queue */ |
6547 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); | |
6548 | phba->sli4_hba.els_cq = NULL; | |
6549 | ||
6550 | /* Release mailbox command complete queue */ | |
6551 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); | |
6552 | phba->sli4_hba.mbx_cq = NULL; | |
6553 | ||
6554 | /* Release FCP response complete queue */ | |
0558056c JS |
6555 | fcp_qidx = 0; |
6556 | do | |
da0436e9 | 6557 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]); |
0558056c | 6558 | while (++fcp_qidx < phba->cfg_fcp_eq_count); |
da0436e9 JS |
6559 | kfree(phba->sli4_hba.fcp_cq); |
6560 | phba->sli4_hba.fcp_cq = NULL; | |
6561 | ||
6562 | /* Release fast-path event queue */ | |
6563 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | |
6564 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]); | |
6565 | kfree(phba->sli4_hba.fp_eq); | |
6566 | phba->sli4_hba.fp_eq = NULL; | |
6567 | ||
6568 | /* Release slow-path event queue */ | |
6569 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); | |
6570 | phba->sli4_hba.sp_eq = NULL; | |
6571 | ||
6572 | return; | |
6573 | } | |
6574 | ||
6575 | /** | |
6576 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues | |
6577 | * @phba: pointer to lpfc hba data structure. | |
6578 | * | |
6579 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA | |
6580 | * operation. | |
6581 | * | |
6582 | * Return codes | |
af901ca1 | 6583 | * 0 - successful |
25985edc | 6584 | * -ENOMEM - No available memory |
d439d286 | 6585 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
6586 | **/ |
6587 | int | |
6588 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) | |
6589 | { | |
6590 | int rc = -ENOMEM; | |
6591 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; | |
6592 | int fcp_cq_index = 0; | |
6593 | ||
6594 | /* | |
6595 | * Set up Event Queues (EQs) | |
6596 | */ | |
6597 | ||
6598 | /* Set up slow-path event queue */ | |
6599 | if (!phba->sli4_hba.sp_eq) { | |
6600 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6601 | "0520 Slow-path EQ not allocated\n"); | |
6602 | goto out_error; | |
6603 | } | |
6604 | rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq, | |
6605 | LPFC_SP_DEF_IMAX); | |
6606 | if (rc) { | |
6607 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6608 | "0521 Failed setup of slow-path EQ: " | |
6609 | "rc = 0x%x\n", rc); | |
6610 | goto out_error; | |
6611 | } | |
6612 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6613 | "2583 Slow-path EQ setup: queue-id=%d\n", | |
6614 | phba->sli4_hba.sp_eq->queue_id); | |
6615 | ||
6616 | /* Set up fast-path event queue */ | |
6617 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
6618 | if (!phba->sli4_hba.fp_eq[fcp_eqidx]) { | |
6619 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6620 | "0522 Fast-path EQ (%d) not " | |
6621 | "allocated\n", fcp_eqidx); | |
6622 | goto out_destroy_fp_eq; | |
6623 | } | |
6624 | rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx], | |
6625 | phba->cfg_fcp_imax); | |
6626 | if (rc) { | |
6627 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6628 | "0523 Failed setup of fast-path EQ " | |
6629 | "(%d), rc = 0x%x\n", fcp_eqidx, rc); | |
6630 | goto out_destroy_fp_eq; | |
6631 | } | |
6632 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6633 | "2584 Fast-path EQ setup: " | |
6634 | "queue[%d]-id=%d\n", fcp_eqidx, | |
6635 | phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id); | |
6636 | } | |
6637 | ||
6638 | /* | |
6639 | * Set up Complete Queues (CQs) | |
6640 | */ | |
6641 | ||
6642 | /* Set up slow-path MBOX Complete Queue as the first CQ */ | |
6643 | if (!phba->sli4_hba.mbx_cq) { | |
6644 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6645 | "0528 Mailbox CQ not allocated\n"); | |
6646 | goto out_destroy_fp_eq; | |
6647 | } | |
6648 | rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq, | |
6649 | LPFC_MCQ, LPFC_MBOX); | |
6650 | if (rc) { | |
6651 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6652 | "0529 Failed setup of slow-path mailbox CQ: " | |
6653 | "rc = 0x%x\n", rc); | |
6654 | goto out_destroy_fp_eq; | |
6655 | } | |
6656 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6657 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", | |
6658 | phba->sli4_hba.mbx_cq->queue_id, | |
6659 | phba->sli4_hba.sp_eq->queue_id); | |
6660 | ||
6661 | /* Set up slow-path ELS Complete Queue */ | |
6662 | if (!phba->sli4_hba.els_cq) { | |
6663 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6664 | "0530 ELS CQ not allocated\n"); | |
6665 | goto out_destroy_mbx_cq; | |
6666 | } | |
6667 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq, | |
6668 | LPFC_WCQ, LPFC_ELS); | |
6669 | if (rc) { | |
6670 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6671 | "0531 Failed setup of slow-path ELS CQ: " | |
6672 | "rc = 0x%x\n", rc); | |
6673 | goto out_destroy_mbx_cq; | |
6674 | } | |
6675 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6676 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", | |
6677 | phba->sli4_hba.els_cq->queue_id, | |
6678 | phba->sli4_hba.sp_eq->queue_id); | |
6679 | ||
da0436e9 | 6680 | /* Set up fast-path FCP Response Complete Queue */ |
0558056c JS |
6681 | fcp_cqidx = 0; |
6682 | do { | |
da0436e9 JS |
6683 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { |
6684 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6685 | "0526 Fast-path FCP CQ (%d) not " | |
6686 | "allocated\n", fcp_cqidx); | |
6687 | goto out_destroy_fcp_cq; | |
6688 | } | |
0558056c JS |
6689 | if (phba->cfg_fcp_eq_count) |
6690 | rc = lpfc_cq_create(phba, | |
6691 | phba->sli4_hba.fcp_cq[fcp_cqidx], | |
6692 | phba->sli4_hba.fp_eq[fcp_cqidx], | |
6693 | LPFC_WCQ, LPFC_FCP); | |
6694 | else | |
6695 | rc = lpfc_cq_create(phba, | |
6696 | phba->sli4_hba.fcp_cq[fcp_cqidx], | |
6697 | phba->sli4_hba.sp_eq, | |
6698 | LPFC_WCQ, LPFC_FCP); | |
da0436e9 JS |
6699 | if (rc) { |
6700 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6701 | "0527 Failed setup of fast-path FCP " | |
6702 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc); | |
6703 | goto out_destroy_fcp_cq; | |
6704 | } | |
6705 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6706 | "2588 FCP CQ setup: cq[%d]-id=%d, " | |
0558056c | 6707 | "parent %seq[%d]-id=%d\n", |
da0436e9 JS |
6708 | fcp_cqidx, |
6709 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, | |
0558056c | 6710 | (phba->cfg_fcp_eq_count) ? "" : "sp_", |
da0436e9 | 6711 | fcp_cqidx, |
0558056c JS |
6712 | (phba->cfg_fcp_eq_count) ? |
6713 | phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id : | |
6714 | phba->sli4_hba.sp_eq->queue_id); | |
6715 | } while (++fcp_cqidx < phba->cfg_fcp_eq_count); | |
da0436e9 JS |
6716 | |
6717 | /* | |
6718 | * Set up all the Work Queues (WQs) | |
6719 | */ | |
6720 | ||
6721 | /* Set up Mailbox Command Queue */ | |
6722 | if (!phba->sli4_hba.mbx_wq) { | |
6723 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6724 | "0538 Slow-path MQ not allocated\n"); | |
6725 | goto out_destroy_fcp_cq; | |
6726 | } | |
6727 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, | |
6728 | phba->sli4_hba.mbx_cq, LPFC_MBOX); | |
6729 | if (rc) { | |
6730 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6731 | "0539 Failed setup of slow-path MQ: " | |
6732 | "rc = 0x%x\n", rc); | |
6733 | goto out_destroy_fcp_cq; | |
6734 | } | |
6735 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6736 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", | |
6737 | phba->sli4_hba.mbx_wq->queue_id, | |
6738 | phba->sli4_hba.mbx_cq->queue_id); | |
6739 | ||
6740 | /* Set up slow-path ELS Work Queue */ | |
6741 | if (!phba->sli4_hba.els_wq) { | |
6742 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6743 | "0536 Slow-path ELS WQ not allocated\n"); | |
6744 | goto out_destroy_mbx_wq; | |
6745 | } | |
6746 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, | |
6747 | phba->sli4_hba.els_cq, LPFC_ELS); | |
6748 | if (rc) { | |
6749 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6750 | "0537 Failed setup of slow-path ELS WQ: " | |
6751 | "rc = 0x%x\n", rc); | |
6752 | goto out_destroy_mbx_wq; | |
6753 | } | |
6754 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6755 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", | |
6756 | phba->sli4_hba.els_wq->queue_id, | |
6757 | phba->sli4_hba.els_cq->queue_id); | |
6758 | ||
6759 | /* Set up fast-path FCP Work Queue */ | |
6760 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { | |
6761 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { | |
6762 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6763 | "0534 Fast-path FCP WQ (%d) not " | |
6764 | "allocated\n", fcp_wqidx); | |
6765 | goto out_destroy_fcp_wq; | |
6766 | } | |
6767 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], | |
6768 | phba->sli4_hba.fcp_cq[fcp_cq_index], | |
6769 | LPFC_FCP); | |
6770 | if (rc) { | |
6771 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6772 | "0535 Failed setup of fast-path FCP " | |
6773 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc); | |
6774 | goto out_destroy_fcp_wq; | |
6775 | } | |
6776 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6777 | "2591 FCP WQ setup: wq[%d]-id=%d, " | |
6778 | "parent cq[%d]-id=%d\n", | |
6779 | fcp_wqidx, | |
6780 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, | |
6781 | fcp_cq_index, | |
6782 | phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id); | |
6783 | /* Round robin FCP Work Queue's Completion Queue assignment */ | |
0558056c JS |
6784 | if (phba->cfg_fcp_eq_count) |
6785 | fcp_cq_index = ((fcp_cq_index + 1) % | |
6786 | phba->cfg_fcp_eq_count); | |
da0436e9 JS |
6787 | } |
6788 | ||
6789 | /* | |
6790 | * Create Receive Queue (RQ) | |
6791 | */ | |
6792 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { | |
6793 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6794 | "0540 Receive Queue not allocated\n"); | |
6795 | goto out_destroy_fcp_wq; | |
6796 | } | |
73d91e50 JS |
6797 | |
6798 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ); | |
6799 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ); | |
6800 | ||
da0436e9 | 6801 | rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, |
4d9ab994 | 6802 | phba->sli4_hba.els_cq, LPFC_USOL); |
da0436e9 JS |
6803 | if (rc) { |
6804 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6805 | "0541 Failed setup of Receive Queue: " | |
6806 | "rc = 0x%x\n", rc); | |
6807 | goto out_destroy_fcp_wq; | |
6808 | } | |
73d91e50 | 6809 | |
da0436e9 JS |
6810 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
6811 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " | |
6812 | "parent cq-id=%d\n", | |
6813 | phba->sli4_hba.hdr_rq->queue_id, | |
6814 | phba->sli4_hba.dat_rq->queue_id, | |
4d9ab994 | 6815 | phba->sli4_hba.els_cq->queue_id); |
da0436e9 JS |
6816 | return 0; |
6817 | ||
6818 | out_destroy_fcp_wq: | |
6819 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) | |
6820 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); | |
6821 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); | |
6822 | out_destroy_mbx_wq: | |
6823 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | |
6824 | out_destroy_fcp_cq: | |
6825 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) | |
6826 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); | |
da0436e9 JS |
6827 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
6828 | out_destroy_mbx_cq: | |
6829 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | |
6830 | out_destroy_fp_eq: | |
6831 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) | |
6832 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]); | |
6833 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); | |
6834 | out_error: | |
6835 | return rc; | |
6836 | } | |
6837 | ||
6838 | /** | |
6839 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues | |
6840 | * @phba: pointer to lpfc hba data structure. | |
6841 | * | |
6842 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA | |
6843 | * operation. | |
6844 | * | |
6845 | * Return codes | |
af901ca1 | 6846 | * 0 - successful |
25985edc | 6847 | * -ENOMEM - No available memory |
d439d286 | 6848 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
6849 | **/ |
6850 | void | |
6851 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) | |
6852 | { | |
6853 | int fcp_qidx; | |
6854 | ||
6855 | /* Unset mailbox command work queue */ | |
6856 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | |
6857 | /* Unset ELS work queue */ | |
6858 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); | |
6859 | /* Unset unsolicited receive queue */ | |
6860 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); | |
6861 | /* Unset FCP work queue */ | |
6862 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) | |
6863 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); | |
6864 | /* Unset mailbox command complete queue */ | |
6865 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | |
6866 | /* Unset ELS complete queue */ | |
6867 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); | |
da0436e9 | 6868 | /* Unset FCP response complete queue */ |
5350d872 JS |
6869 | fcp_qidx = 0; |
6870 | do { | |
da0436e9 | 6871 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); |
5350d872 | 6872 | } while (++fcp_qidx < phba->cfg_fcp_eq_count); |
da0436e9 JS |
6873 | /* Unset fast-path event queue */ |
6874 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++) | |
6875 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]); | |
6876 | /* Unset slow-path event queue */ | |
6877 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); | |
6878 | } | |
6879 | ||
6880 | /** | |
6881 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool | |
6882 | * @phba: pointer to lpfc hba data structure. | |
6883 | * | |
6884 | * This routine is invoked to allocate and set up a pool of completion queue | |
6885 | * events. The body of the completion queue event is a completion queue entry | |
6886 | * CQE. For now, this pool is used for the interrupt service routine to queue | |
6887 | * the following HBA completion queue events for the worker thread to process: | |
6888 | * - Mailbox asynchronous events | |
6889 | * - Receive queue completion unsolicited events | |
6890 | * Later, this can be used for all the slow-path events. | |
6891 | * | |
6892 | * Return codes | |
af901ca1 | 6893 | * 0 - successful |
25985edc | 6894 | * -ENOMEM - No available memory |
da0436e9 JS |
6895 | **/ |
6896 | static int | |
6897 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) | |
6898 | { | |
6899 | struct lpfc_cq_event *cq_event; | |
6900 | int i; | |
6901 | ||
6902 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { | |
6903 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); | |
6904 | if (!cq_event) | |
6905 | goto out_pool_create_fail; | |
6906 | list_add_tail(&cq_event->list, | |
6907 | &phba->sli4_hba.sp_cqe_event_pool); | |
6908 | } | |
6909 | return 0; | |
6910 | ||
6911 | out_pool_create_fail: | |
6912 | lpfc_sli4_cq_event_pool_destroy(phba); | |
6913 | return -ENOMEM; | |
6914 | } | |
6915 | ||
6916 | /** | |
6917 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool | |
6918 | * @phba: pointer to lpfc hba data structure. | |
6919 | * | |
6920 | * This routine is invoked to free the pool of completion queue events at | |
6921 | * driver unload time. Note that, it is the responsibility of the driver | |
6922 | * cleanup routine to free all the outstanding completion-queue events | |
6923 | * allocated from this pool back into the pool before invoking this routine | |
6924 | * to destroy the pool. | |
6925 | **/ | |
6926 | static void | |
6927 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) | |
6928 | { | |
6929 | struct lpfc_cq_event *cq_event, *next_cq_event; | |
6930 | ||
6931 | list_for_each_entry_safe(cq_event, next_cq_event, | |
6932 | &phba->sli4_hba.sp_cqe_event_pool, list) { | |
6933 | list_del(&cq_event->list); | |
6934 | kfree(cq_event); | |
6935 | } | |
6936 | } | |
6937 | ||
6938 | /** | |
6939 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
6940 | * @phba: pointer to lpfc hba data structure. | |
6941 | * | |
6942 | * This routine is the lock free version of the API invoked to allocate a | |
6943 | * completion-queue event from the free pool. | |
6944 | * | |
6945 | * Return: Pointer to the newly allocated completion-queue event if successful | |
6946 | * NULL otherwise. | |
6947 | **/ | |
6948 | struct lpfc_cq_event * | |
6949 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
6950 | { | |
6951 | struct lpfc_cq_event *cq_event = NULL; | |
6952 | ||
6953 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, | |
6954 | struct lpfc_cq_event, list); | |
6955 | return cq_event; | |
6956 | } | |
6957 | ||
6958 | /** | |
6959 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
6960 | * @phba: pointer to lpfc hba data structure. | |
6961 | * | |
6962 | * This routine is the lock version of the API invoked to allocate a | |
6963 | * completion-queue event from the free pool. | |
6964 | * | |
6965 | * Return: Pointer to the newly allocated completion-queue event if successful | |
6966 | * NULL otherwise. | |
6967 | **/ | |
6968 | struct lpfc_cq_event * | |
6969 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
6970 | { | |
6971 | struct lpfc_cq_event *cq_event; | |
6972 | unsigned long iflags; | |
6973 | ||
6974 | spin_lock_irqsave(&phba->hbalock, iflags); | |
6975 | cq_event = __lpfc_sli4_cq_event_alloc(phba); | |
6976 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
6977 | return cq_event; | |
6978 | } | |
6979 | ||
6980 | /** | |
6981 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
6982 | * @phba: pointer to lpfc hba data structure. | |
6983 | * @cq_event: pointer to the completion queue event to be freed. | |
6984 | * | |
6985 | * This routine is the lock free version of the API invoked to release a | |
6986 | * completion-queue event back into the free pool. | |
6987 | **/ | |
6988 | void | |
6989 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
6990 | struct lpfc_cq_event *cq_event) | |
6991 | { | |
6992 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); | |
6993 | } | |
6994 | ||
6995 | /** | |
6996 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
6997 | * @phba: pointer to lpfc hba data structure. | |
6998 | * @cq_event: pointer to the completion queue event to be freed. | |
6999 | * | |
7000 | * This routine is the lock version of the API invoked to release a | |
7001 | * completion-queue event back into the free pool. | |
7002 | **/ | |
7003 | void | |
7004 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
7005 | struct lpfc_cq_event *cq_event) | |
7006 | { | |
7007 | unsigned long iflags; | |
7008 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7009 | __lpfc_sli4_cq_event_release(phba, cq_event); | |
7010 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7011 | } | |
7012 | ||
7013 | /** | |
7014 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool | |
7015 | * @phba: pointer to lpfc hba data structure. | |
7016 | * | |
7017 | * This routine is to free all the pending completion-queue events to the | |
7018 | * back into the free pool for device reset. | |
7019 | **/ | |
7020 | static void | |
7021 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) | |
7022 | { | |
7023 | LIST_HEAD(cqelist); | |
7024 | struct lpfc_cq_event *cqe; | |
7025 | unsigned long iflags; | |
7026 | ||
7027 | /* Retrieve all the pending WCQEs from pending WCQE lists */ | |
7028 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7029 | /* Pending FCP XRI abort events */ | |
7030 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
7031 | &cqelist); | |
7032 | /* Pending ELS XRI abort events */ | |
7033 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
7034 | &cqelist); | |
7035 | /* Pending asynnc events */ | |
7036 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, | |
7037 | &cqelist); | |
7038 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7039 | ||
7040 | while (!list_empty(&cqelist)) { | |
7041 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); | |
7042 | lpfc_sli4_cq_event_release(phba, cqe); | |
7043 | } | |
7044 | } | |
7045 | ||
7046 | /** | |
7047 | * lpfc_pci_function_reset - Reset pci function. | |
7048 | * @phba: pointer to lpfc hba data structure. | |
7049 | * | |
7050 | * This routine is invoked to request a PCI function reset. It will destroys | |
7051 | * all resources assigned to the PCI function which originates this request. | |
7052 | * | |
7053 | * Return codes | |
af901ca1 | 7054 | * 0 - successful |
25985edc | 7055 | * -ENOMEM - No available memory |
d439d286 | 7056 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
7057 | **/ |
7058 | int | |
7059 | lpfc_pci_function_reset(struct lpfc_hba *phba) | |
7060 | { | |
7061 | LPFC_MBOXQ_t *mboxq; | |
2fcee4bf | 7062 | uint32_t rc = 0, if_type; |
da0436e9 | 7063 | uint32_t shdr_status, shdr_add_status; |
2fcee4bf | 7064 | uint32_t rdy_chk, num_resets = 0, reset_again = 0; |
da0436e9 | 7065 | union lpfc_sli4_cfg_shdr *shdr; |
2fcee4bf | 7066 | struct lpfc_register reg_data; |
da0436e9 | 7067 | |
2fcee4bf JS |
7068 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
7069 | switch (if_type) { | |
7070 | case LPFC_SLI_INTF_IF_TYPE_0: | |
7071 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, | |
7072 | GFP_KERNEL); | |
7073 | if (!mboxq) { | |
7074 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7075 | "0494 Unable to allocate memory for " | |
7076 | "issuing SLI_FUNCTION_RESET mailbox " | |
7077 | "command\n"); | |
7078 | return -ENOMEM; | |
7079 | } | |
da0436e9 | 7080 | |
2fcee4bf JS |
7081 | /* Setup PCI function reset mailbox-ioctl command */ |
7082 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
7083 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, | |
7084 | LPFC_SLI4_MBX_EMBED); | |
7085 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7086 | shdr = (union lpfc_sli4_cfg_shdr *) | |
7087 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
7088 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
7089 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
7090 | &shdr->response); | |
7091 | if (rc != MBX_TIMEOUT) | |
7092 | mempool_free(mboxq, phba->mbox_mem_pool); | |
7093 | if (shdr_status || shdr_add_status || rc) { | |
7094 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7095 | "0495 SLI_FUNCTION_RESET mailbox " | |
7096 | "failed with status x%x add_status x%x," | |
7097 | " mbx status x%x\n", | |
7098 | shdr_status, shdr_add_status, rc); | |
7099 | rc = -ENXIO; | |
7100 | } | |
7101 | break; | |
7102 | case LPFC_SLI_INTF_IF_TYPE_2: | |
7103 | for (num_resets = 0; | |
7104 | num_resets < MAX_IF_TYPE_2_RESETS; | |
7105 | num_resets++) { | |
7106 | reg_data.word0 = 0; | |
7107 | bf_set(lpfc_sliport_ctrl_end, ®_data, | |
7108 | LPFC_SLIPORT_LITTLE_ENDIAN); | |
7109 | bf_set(lpfc_sliport_ctrl_ip, ®_data, | |
7110 | LPFC_SLIPORT_INIT_PORT); | |
7111 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. | |
7112 | CTRLregaddr); | |
7113 | ||
7114 | /* | |
7115 | * Poll the Port Status Register and wait for RDY for | |
7116 | * up to 10 seconds. If the port doesn't respond, treat | |
7117 | * it as an error. If the port responds with RN, start | |
7118 | * the loop again. | |
7119 | */ | |
7120 | for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) { | |
73d91e50 | 7121 | msleep(10); |
9940b97b JS |
7122 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
7123 | STATUSregaddr, ®_data.word0)) { | |
7124 | rc = -ENODEV; | |
73d91e50 | 7125 | goto out; |
9940b97b | 7126 | } |
2fcee4bf JS |
7127 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
7128 | break; | |
7129 | if (bf_get(lpfc_sliport_status_rn, ®_data)) { | |
7130 | reset_again++; | |
7131 | break; | |
7132 | } | |
2fcee4bf JS |
7133 | } |
7134 | ||
7135 | /* | |
7136 | * If the port responds to the init request with | |
7137 | * reset needed, delay for a bit and restart the loop. | |
7138 | */ | |
7139 | if (reset_again) { | |
7140 | msleep(10); | |
7141 | reset_again = 0; | |
7142 | continue; | |
7143 | } | |
7144 | ||
7145 | /* Detect any port errors. */ | |
2fcee4bf JS |
7146 | if ((bf_get(lpfc_sliport_status_err, ®_data)) || |
7147 | (rdy_chk >= 1000)) { | |
7148 | phba->work_status[0] = readl( | |
7149 | phba->sli4_hba.u.if_type2.ERR1regaddr); | |
7150 | phba->work_status[1] = readl( | |
7151 | phba->sli4_hba.u.if_type2.ERR2regaddr); | |
7152 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7153 | "2890 Port Error Detected " | |
7154 | "during Port Reset: " | |
7155 | "port status reg 0x%x, " | |
7156 | "error 1=0x%x, error 2=0x%x\n", | |
7157 | reg_data.word0, | |
7158 | phba->work_status[0], | |
7159 | phba->work_status[1]); | |
7160 | rc = -ENODEV; | |
7161 | } | |
7162 | ||
7163 | /* | |
7164 | * Terminate the outer loop provided the Port indicated | |
7165 | * ready within 10 seconds. | |
7166 | */ | |
7167 | if (rdy_chk < 1000) | |
7168 | break; | |
7169 | } | |
0558056c JS |
7170 | /* delay driver action following IF_TYPE_2 function reset */ |
7171 | msleep(100); | |
2fcee4bf JS |
7172 | break; |
7173 | case LPFC_SLI_INTF_IF_TYPE_1: | |
7174 | default: | |
7175 | break; | |
da0436e9 | 7176 | } |
2fcee4bf | 7177 | |
73d91e50 | 7178 | out: |
2fcee4bf JS |
7179 | /* Catch the not-ready port failure after a port reset. */ |
7180 | if (num_resets >= MAX_IF_TYPE_2_RESETS) | |
7181 | rc = -ENODEV; | |
7182 | ||
da0436e9 JS |
7183 | return rc; |
7184 | } | |
7185 | ||
7186 | /** | |
7187 | * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands | |
7188 | * @phba: pointer to lpfc hba data structure. | |
7189 | * @cnt: number of nop mailbox commands to send. | |
7190 | * | |
7191 | * This routine is invoked to send a number @cnt of NOP mailbox command and | |
7192 | * wait for each command to complete. | |
7193 | * | |
7194 | * Return: the number of NOP mailbox command completed. | |
7195 | **/ | |
7196 | static int | |
7197 | lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt) | |
7198 | { | |
7199 | LPFC_MBOXQ_t *mboxq; | |
7200 | int length, cmdsent; | |
7201 | uint32_t mbox_tmo; | |
7202 | uint32_t rc = 0; | |
7203 | uint32_t shdr_status, shdr_add_status; | |
7204 | union lpfc_sli4_cfg_shdr *shdr; | |
7205 | ||
7206 | if (cnt == 0) { | |
7207 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7208 | "2518 Requested to send 0 NOP mailbox cmd\n"); | |
7209 | return cnt; | |
7210 | } | |
7211 | ||
7212 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
7213 | if (!mboxq) { | |
7214 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7215 | "2519 Unable to allocate memory for issuing " | |
7216 | "NOP mailbox command\n"); | |
7217 | return 0; | |
7218 | } | |
7219 | ||
7220 | /* Set up NOP SLI4_CONFIG mailbox-ioctl command */ | |
7221 | length = (sizeof(struct lpfc_mbx_nop) - | |
7222 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
7223 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
7224 | LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED); | |
7225 | ||
da0436e9 JS |
7226 | for (cmdsent = 0; cmdsent < cnt; cmdsent++) { |
7227 | if (!phba->sli4_hba.intr_enable) | |
7228 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
a183a15f JS |
7229 | else { |
7230 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); | |
da0436e9 | 7231 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
a183a15f | 7232 | } |
da0436e9 JS |
7233 | if (rc == MBX_TIMEOUT) |
7234 | break; | |
7235 | /* Check return status */ | |
7236 | shdr = (union lpfc_sli4_cfg_shdr *) | |
7237 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
7238 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
7239 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
7240 | &shdr->response); | |
7241 | if (shdr_status || shdr_add_status || rc) { | |
7242 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7243 | "2520 NOP mailbox command failed " | |
7244 | "status x%x add_status x%x mbx " | |
7245 | "status x%x\n", shdr_status, | |
7246 | shdr_add_status, rc); | |
7247 | break; | |
7248 | } | |
7249 | } | |
7250 | ||
7251 | if (rc != MBX_TIMEOUT) | |
7252 | mempool_free(mboxq, phba->mbox_mem_pool); | |
7253 | ||
7254 | return cmdsent; | |
7255 | } | |
7256 | ||
da0436e9 JS |
7257 | /** |
7258 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. | |
7259 | * @phba: pointer to lpfc hba data structure. | |
7260 | * | |
7261 | * This routine is invoked to set up the PCI device memory space for device | |
7262 | * with SLI-4 interface spec. | |
7263 | * | |
7264 | * Return codes | |
af901ca1 | 7265 | * 0 - successful |
da0436e9 JS |
7266 | * other values - error |
7267 | **/ | |
7268 | static int | |
7269 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) | |
7270 | { | |
7271 | struct pci_dev *pdev; | |
7272 | unsigned long bar0map_len, bar1map_len, bar2map_len; | |
7273 | int error = -ENODEV; | |
2fcee4bf | 7274 | uint32_t if_type; |
da0436e9 JS |
7275 | |
7276 | /* Obtain PCI device reference */ | |
7277 | if (!phba->pcidev) | |
7278 | return error; | |
7279 | else | |
7280 | pdev = phba->pcidev; | |
7281 | ||
7282 | /* Set the device DMA mask size */ | |
8e68597d MR |
7283 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
7284 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
7285 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
7286 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
da0436e9 | 7287 | return error; |
8e68597d MR |
7288 | } |
7289 | } | |
da0436e9 | 7290 | |
2fcee4bf JS |
7291 | /* |
7292 | * The BARs and register set definitions and offset locations are | |
7293 | * dependent on the if_type. | |
7294 | */ | |
7295 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, | |
7296 | &phba->sli4_hba.sli_intf.word0)) { | |
7297 | return error; | |
7298 | } | |
7299 | ||
7300 | /* There is no SLI3 failback for SLI4 devices. */ | |
7301 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != | |
7302 | LPFC_SLI_INTF_VALID) { | |
7303 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7304 | "2894 SLI_INTF reg contents invalid " | |
7305 | "sli_intf reg 0x%x\n", | |
7306 | phba->sli4_hba.sli_intf.word0); | |
7307 | return error; | |
7308 | } | |
7309 | ||
7310 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); | |
7311 | /* | |
7312 | * Get the bus address of SLI4 device Bar regions and the | |
7313 | * number of bytes required by each mapping. The mapping of the | |
7314 | * particular PCI BARs regions is dependent on the type of | |
7315 | * SLI4 device. | |
da0436e9 | 7316 | */ |
1dfb5a47 JS |
7317 | if (pci_resource_start(pdev, 0)) { |
7318 | phba->pci_bar0_map = pci_resource_start(pdev, 0); | |
7319 | bar0map_len = pci_resource_len(pdev, 0); | |
2fcee4bf JS |
7320 | |
7321 | /* | |
7322 | * Map SLI4 PCI Config Space Register base to a kernel virtual | |
7323 | * addr | |
7324 | */ | |
7325 | phba->sli4_hba.conf_regs_memmap_p = | |
7326 | ioremap(phba->pci_bar0_map, bar0map_len); | |
7327 | if (!phba->sli4_hba.conf_regs_memmap_p) { | |
7328 | dev_printk(KERN_ERR, &pdev->dev, | |
7329 | "ioremap failed for SLI4 PCI config " | |
7330 | "registers.\n"); | |
7331 | goto out; | |
7332 | } | |
7333 | /* Set up BAR0 PCI config space register memory map */ | |
7334 | lpfc_sli4_bar0_register_memmap(phba, if_type); | |
1dfb5a47 JS |
7335 | } else { |
7336 | phba->pci_bar0_map = pci_resource_start(pdev, 1); | |
7337 | bar0map_len = pci_resource_len(pdev, 1); | |
2fcee4bf JS |
7338 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
7339 | dev_printk(KERN_ERR, &pdev->dev, | |
7340 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); | |
7341 | goto out; | |
7342 | } | |
7343 | phba->sli4_hba.conf_regs_memmap_p = | |
da0436e9 | 7344 | ioremap(phba->pci_bar0_map, bar0map_len); |
2fcee4bf JS |
7345 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
7346 | dev_printk(KERN_ERR, &pdev->dev, | |
7347 | "ioremap failed for SLI4 PCI config " | |
7348 | "registers.\n"); | |
7349 | goto out; | |
7350 | } | |
7351 | lpfc_sli4_bar0_register_memmap(phba, if_type); | |
da0436e9 JS |
7352 | } |
7353 | ||
c31098ce JS |
7354 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
7355 | (pci_resource_start(pdev, 2))) { | |
2fcee4bf JS |
7356 | /* |
7357 | * Map SLI4 if type 0 HBA Control Register base to a kernel | |
7358 | * virtual address and setup the registers. | |
7359 | */ | |
7360 | phba->pci_bar1_map = pci_resource_start(pdev, 2); | |
7361 | bar1map_len = pci_resource_len(pdev, 2); | |
7362 | phba->sli4_hba.ctrl_regs_memmap_p = | |
da0436e9 | 7363 | ioremap(phba->pci_bar1_map, bar1map_len); |
2fcee4bf JS |
7364 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
7365 | dev_printk(KERN_ERR, &pdev->dev, | |
da0436e9 | 7366 | "ioremap failed for SLI4 HBA control registers.\n"); |
2fcee4bf JS |
7367 | goto out_iounmap_conf; |
7368 | } | |
7369 | lpfc_sli4_bar1_register_memmap(phba); | |
da0436e9 JS |
7370 | } |
7371 | ||
c31098ce JS |
7372 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
7373 | (pci_resource_start(pdev, 4))) { | |
2fcee4bf JS |
7374 | /* |
7375 | * Map SLI4 if type 0 HBA Doorbell Register base to a kernel | |
7376 | * virtual address and setup the registers. | |
7377 | */ | |
7378 | phba->pci_bar2_map = pci_resource_start(pdev, 4); | |
7379 | bar2map_len = pci_resource_len(pdev, 4); | |
7380 | phba->sli4_hba.drbl_regs_memmap_p = | |
da0436e9 | 7381 | ioremap(phba->pci_bar2_map, bar2map_len); |
2fcee4bf JS |
7382 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
7383 | dev_printk(KERN_ERR, &pdev->dev, | |
da0436e9 | 7384 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
2fcee4bf JS |
7385 | goto out_iounmap_ctrl; |
7386 | } | |
7387 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); | |
7388 | if (error) | |
7389 | goto out_iounmap_all; | |
da0436e9 JS |
7390 | } |
7391 | ||
da0436e9 JS |
7392 | return 0; |
7393 | ||
7394 | out_iounmap_all: | |
7395 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
7396 | out_iounmap_ctrl: | |
7397 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
7398 | out_iounmap_conf: | |
7399 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
7400 | out: | |
7401 | return error; | |
7402 | } | |
7403 | ||
7404 | /** | |
7405 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. | |
7406 | * @phba: pointer to lpfc hba data structure. | |
7407 | * | |
7408 | * This routine is invoked to unset the PCI device memory space for device | |
7409 | * with SLI-4 interface spec. | |
7410 | **/ | |
7411 | static void | |
7412 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) | |
7413 | { | |
7414 | struct pci_dev *pdev; | |
7415 | ||
7416 | /* Obtain PCI device reference */ | |
7417 | if (!phba->pcidev) | |
7418 | return; | |
7419 | else | |
7420 | pdev = phba->pcidev; | |
7421 | ||
7422 | /* Free coherent DMA memory allocated */ | |
7423 | ||
7424 | /* Unmap I/O memory space */ | |
7425 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
7426 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
7427 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
7428 | ||
7429 | return; | |
7430 | } | |
7431 | ||
7432 | /** | |
7433 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device | |
7434 | * @phba: pointer to lpfc hba data structure. | |
7435 | * | |
7436 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
7437 | * with SLI-3 interface specs. The kernel function pci_enable_msix() is | |
7438 | * called to enable the MSI-X vectors. Note that pci_enable_msix(), once | |
7439 | * invoked, enables either all or nothing, depending on the current | |
7440 | * availability of PCI vector resources. The device driver is responsible | |
7441 | * for calling the individual request_irq() to register each MSI-X vector | |
7442 | * with a interrupt handler, which is done in this function. Note that | |
7443 | * later when device is unloading, the driver should always call free_irq() | |
7444 | * on all MSI-X vectors it has done request_irq() on before calling | |
7445 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device | |
7446 | * will be left with MSI-X enabled and leaks its vectors. | |
7447 | * | |
7448 | * Return codes | |
af901ca1 | 7449 | * 0 - successful |
da0436e9 JS |
7450 | * other values - error |
7451 | **/ | |
7452 | static int | |
7453 | lpfc_sli_enable_msix(struct lpfc_hba *phba) | |
7454 | { | |
7455 | int rc, i; | |
7456 | LPFC_MBOXQ_t *pmb; | |
7457 | ||
7458 | /* Set up MSI-X multi-message vectors */ | |
7459 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
7460 | phba->msix_entries[i].entry = i; | |
7461 | ||
7462 | /* Configure MSI-X capability structure */ | |
7463 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, | |
7464 | ARRAY_SIZE(phba->msix_entries)); | |
7465 | if (rc) { | |
7466 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7467 | "0420 PCI enable MSI-X failed (%d)\n", rc); | |
7468 | goto msi_fail_out; | |
7469 | } | |
7470 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
7471 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7472 | "0477 MSI-X entry[%d]: vector=x%x " | |
7473 | "message=%d\n", i, | |
7474 | phba->msix_entries[i].vector, | |
7475 | phba->msix_entries[i].entry); | |
7476 | /* | |
7477 | * Assign MSI-X vectors to interrupt handlers | |
7478 | */ | |
7479 | ||
7480 | /* vector-0 is associated to slow-path handler */ | |
7481 | rc = request_irq(phba->msix_entries[0].vector, | |
7482 | &lpfc_sli_sp_intr_handler, IRQF_SHARED, | |
7483 | LPFC_SP_DRIVER_HANDLER_NAME, phba); | |
7484 | if (rc) { | |
7485 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7486 | "0421 MSI-X slow-path request_irq failed " | |
7487 | "(%d)\n", rc); | |
7488 | goto msi_fail_out; | |
7489 | } | |
7490 | ||
7491 | /* vector-1 is associated to fast-path handler */ | |
7492 | rc = request_irq(phba->msix_entries[1].vector, | |
7493 | &lpfc_sli_fp_intr_handler, IRQF_SHARED, | |
7494 | LPFC_FP_DRIVER_HANDLER_NAME, phba); | |
7495 | ||
7496 | if (rc) { | |
7497 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7498 | "0429 MSI-X fast-path request_irq failed " | |
7499 | "(%d)\n", rc); | |
7500 | goto irq_fail_out; | |
7501 | } | |
7502 | ||
7503 | /* | |
7504 | * Configure HBA MSI-X attention conditions to messages | |
7505 | */ | |
7506 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
7507 | ||
7508 | if (!pmb) { | |
7509 | rc = -ENOMEM; | |
7510 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7511 | "0474 Unable to allocate memory for issuing " | |
7512 | "MBOX_CONFIG_MSI command\n"); | |
7513 | goto mem_fail_out; | |
7514 | } | |
7515 | rc = lpfc_config_msi(phba, pmb); | |
7516 | if (rc) | |
7517 | goto mbx_fail_out; | |
7518 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
7519 | if (rc != MBX_SUCCESS) { | |
7520 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | |
7521 | "0351 Config MSI mailbox command failed, " | |
7522 | "mbxCmd x%x, mbxStatus x%x\n", | |
7523 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); | |
7524 | goto mbx_fail_out; | |
7525 | } | |
7526 | ||
7527 | /* Free memory allocated for mailbox command */ | |
7528 | mempool_free(pmb, phba->mbox_mem_pool); | |
7529 | return rc; | |
7530 | ||
7531 | mbx_fail_out: | |
7532 | /* Free memory allocated for mailbox command */ | |
7533 | mempool_free(pmb, phba->mbox_mem_pool); | |
7534 | ||
7535 | mem_fail_out: | |
7536 | /* free the irq already requested */ | |
7537 | free_irq(phba->msix_entries[1].vector, phba); | |
7538 | ||
7539 | irq_fail_out: | |
7540 | /* free the irq already requested */ | |
7541 | free_irq(phba->msix_entries[0].vector, phba); | |
7542 | ||
7543 | msi_fail_out: | |
7544 | /* Unconfigure MSI-X capability structure */ | |
7545 | pci_disable_msix(phba->pcidev); | |
7546 | return rc; | |
7547 | } | |
7548 | ||
7549 | /** | |
7550 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. | |
7551 | * @phba: pointer to lpfc hba data structure. | |
7552 | * | |
7553 | * This routine is invoked to release the MSI-X vectors and then disable the | |
7554 | * MSI-X interrupt mode to device with SLI-3 interface spec. | |
7555 | **/ | |
7556 | static void | |
7557 | lpfc_sli_disable_msix(struct lpfc_hba *phba) | |
7558 | { | |
7559 | int i; | |
7560 | ||
7561 | /* Free up MSI-X multi-message vectors */ | |
7562 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
7563 | free_irq(phba->msix_entries[i].vector, phba); | |
7564 | /* Disable MSI-X */ | |
7565 | pci_disable_msix(phba->pcidev); | |
7566 | ||
7567 | return; | |
7568 | } | |
7569 | ||
7570 | /** | |
7571 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. | |
7572 | * @phba: pointer to lpfc hba data structure. | |
7573 | * | |
7574 | * This routine is invoked to enable the MSI interrupt mode to device with | |
7575 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to | |
7576 | * enable the MSI vector. The device driver is responsible for calling the | |
7577 | * request_irq() to register MSI vector with a interrupt the handler, which | |
7578 | * is done in this function. | |
7579 | * | |
7580 | * Return codes | |
af901ca1 | 7581 | * 0 - successful |
da0436e9 JS |
7582 | * other values - error |
7583 | */ | |
7584 | static int | |
7585 | lpfc_sli_enable_msi(struct lpfc_hba *phba) | |
7586 | { | |
7587 | int rc; | |
7588 | ||
7589 | rc = pci_enable_msi(phba->pcidev); | |
7590 | if (!rc) | |
7591 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7592 | "0462 PCI enable MSI mode success.\n"); | |
7593 | else { | |
7594 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7595 | "0471 PCI enable MSI mode failed (%d)\n", rc); | |
7596 | return rc; | |
7597 | } | |
7598 | ||
7599 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
7600 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
7601 | if (rc) { | |
7602 | pci_disable_msi(phba->pcidev); | |
7603 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7604 | "0478 MSI request_irq failed (%d)\n", rc); | |
7605 | } | |
7606 | return rc; | |
7607 | } | |
7608 | ||
7609 | /** | |
7610 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. | |
7611 | * @phba: pointer to lpfc hba data structure. | |
7612 | * | |
7613 | * This routine is invoked to disable the MSI interrupt mode to device with | |
7614 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has | |
7615 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | |
7616 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | |
7617 | * its vector. | |
7618 | */ | |
7619 | static void | |
7620 | lpfc_sli_disable_msi(struct lpfc_hba *phba) | |
7621 | { | |
7622 | free_irq(phba->pcidev->irq, phba); | |
7623 | pci_disable_msi(phba->pcidev); | |
7624 | return; | |
7625 | } | |
7626 | ||
7627 | /** | |
7628 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. | |
7629 | * @phba: pointer to lpfc hba data structure. | |
7630 | * | |
7631 | * This routine is invoked to enable device interrupt and associate driver's | |
7632 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface | |
7633 | * spec. Depends on the interrupt mode configured to the driver, the driver | |
7634 | * will try to fallback from the configured interrupt mode to an interrupt | |
7635 | * mode which is supported by the platform, kernel, and device in the order | |
7636 | * of: | |
7637 | * MSI-X -> MSI -> IRQ. | |
7638 | * | |
7639 | * Return codes | |
af901ca1 | 7640 | * 0 - successful |
da0436e9 JS |
7641 | * other values - error |
7642 | **/ | |
7643 | static uint32_t | |
7644 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
7645 | { | |
7646 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
7647 | int retval; | |
7648 | ||
7649 | if (cfg_mode == 2) { | |
7650 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ | |
7651 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); | |
7652 | if (!retval) { | |
7653 | /* Now, try to enable MSI-X interrupt mode */ | |
7654 | retval = lpfc_sli_enable_msix(phba); | |
7655 | if (!retval) { | |
7656 | /* Indicate initialization to MSI-X mode */ | |
7657 | phba->intr_type = MSIX; | |
7658 | intr_mode = 2; | |
7659 | } | |
7660 | } | |
7661 | } | |
7662 | ||
7663 | /* Fallback to MSI if MSI-X initialization failed */ | |
7664 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
7665 | retval = lpfc_sli_enable_msi(phba); | |
7666 | if (!retval) { | |
7667 | /* Indicate initialization to MSI mode */ | |
7668 | phba->intr_type = MSI; | |
7669 | intr_mode = 1; | |
7670 | } | |
7671 | } | |
7672 | ||
7673 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
7674 | if (phba->intr_type == NONE) { | |
7675 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
7676 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
7677 | if (!retval) { | |
7678 | /* Indicate initialization to INTx mode */ | |
7679 | phba->intr_type = INTx; | |
7680 | intr_mode = 0; | |
7681 | } | |
7682 | } | |
7683 | return intr_mode; | |
7684 | } | |
7685 | ||
7686 | /** | |
7687 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. | |
7688 | * @phba: pointer to lpfc hba data structure. | |
7689 | * | |
7690 | * This routine is invoked to disable device interrupt and disassociate the | |
7691 | * driver's interrupt handler(s) from interrupt vector(s) to device with | |
7692 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will | |
7693 | * release the interrupt vector(s) for the message signaled interrupt. | |
7694 | **/ | |
7695 | static void | |
7696 | lpfc_sli_disable_intr(struct lpfc_hba *phba) | |
7697 | { | |
7698 | /* Disable the currently initialized interrupt mode */ | |
7699 | if (phba->intr_type == MSIX) | |
7700 | lpfc_sli_disable_msix(phba); | |
7701 | else if (phba->intr_type == MSI) | |
7702 | lpfc_sli_disable_msi(phba); | |
7703 | else if (phba->intr_type == INTx) | |
7704 | free_irq(phba->pcidev->irq, phba); | |
7705 | ||
7706 | /* Reset interrupt management states */ | |
7707 | phba->intr_type = NONE; | |
7708 | phba->sli.slistat.sli_intr = 0; | |
7709 | ||
7710 | return; | |
7711 | } | |
7712 | ||
7713 | /** | |
7714 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device | |
7715 | * @phba: pointer to lpfc hba data structure. | |
7716 | * | |
7717 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
7718 | * with SLI-4 interface spec. The kernel function pci_enable_msix() is called | |
7719 | * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked, | |
7720 | * enables either all or nothing, depending on the current availability of | |
7721 | * PCI vector resources. The device driver is responsible for calling the | |
7722 | * individual request_irq() to register each MSI-X vector with a interrupt | |
7723 | * handler, which is done in this function. Note that later when device is | |
7724 | * unloading, the driver should always call free_irq() on all MSI-X vectors | |
7725 | * it has done request_irq() on before calling pci_disable_msix(). Failure | |
7726 | * to do so results in a BUG_ON() and a device will be left with MSI-X | |
7727 | * enabled and leaks its vectors. | |
7728 | * | |
7729 | * Return codes | |
af901ca1 | 7730 | * 0 - successful |
da0436e9 JS |
7731 | * other values - error |
7732 | **/ | |
7733 | static int | |
7734 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) | |
7735 | { | |
75baf696 | 7736 | int vectors, rc, index; |
da0436e9 JS |
7737 | |
7738 | /* Set up MSI-X multi-message vectors */ | |
7739 | for (index = 0; index < phba->sli4_hba.cfg_eqn; index++) | |
7740 | phba->sli4_hba.msix_entries[index].entry = index; | |
7741 | ||
7742 | /* Configure MSI-X capability structure */ | |
75baf696 JS |
7743 | vectors = phba->sli4_hba.cfg_eqn; |
7744 | enable_msix_vectors: | |
da0436e9 | 7745 | rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries, |
75baf696 JS |
7746 | vectors); |
7747 | if (rc > 1) { | |
7748 | vectors = rc; | |
7749 | goto enable_msix_vectors; | |
7750 | } else if (rc) { | |
da0436e9 JS |
7751 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
7752 | "0484 PCI enable MSI-X failed (%d)\n", rc); | |
7753 | goto msi_fail_out; | |
7754 | } | |
75baf696 | 7755 | |
da0436e9 | 7756 | /* Log MSI-X vector assignment */ |
75baf696 | 7757 | for (index = 0; index < vectors; index++) |
da0436e9 JS |
7758 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
7759 | "0489 MSI-X entry[%d]: vector=x%x " | |
7760 | "message=%d\n", index, | |
7761 | phba->sli4_hba.msix_entries[index].vector, | |
7762 | phba->sli4_hba.msix_entries[index].entry); | |
7763 | /* | |
7764 | * Assign MSI-X vectors to interrupt handlers | |
7765 | */ | |
0558056c JS |
7766 | if (vectors > 1) |
7767 | rc = request_irq(phba->sli4_hba.msix_entries[0].vector, | |
7768 | &lpfc_sli4_sp_intr_handler, IRQF_SHARED, | |
7769 | LPFC_SP_DRIVER_HANDLER_NAME, phba); | |
7770 | else | |
7771 | /* All Interrupts need to be handled by one EQ */ | |
7772 | rc = request_irq(phba->sli4_hba.msix_entries[0].vector, | |
7773 | &lpfc_sli4_intr_handler, IRQF_SHARED, | |
7774 | LPFC_DRIVER_NAME, phba); | |
da0436e9 JS |
7775 | if (rc) { |
7776 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7777 | "0485 MSI-X slow-path request_irq failed " | |
7778 | "(%d)\n", rc); | |
7779 | goto msi_fail_out; | |
7780 | } | |
7781 | ||
7782 | /* The rest of the vector(s) are associated to fast-path handler(s) */ | |
75baf696 | 7783 | for (index = 1; index < vectors; index++) { |
da0436e9 JS |
7784 | phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1; |
7785 | phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba; | |
7786 | rc = request_irq(phba->sli4_hba.msix_entries[index].vector, | |
7787 | &lpfc_sli4_fp_intr_handler, IRQF_SHARED, | |
7788 | LPFC_FP_DRIVER_HANDLER_NAME, | |
7789 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
7790 | if (rc) { | |
7791 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7792 | "0486 MSI-X fast-path (%d) " | |
7793 | "request_irq failed (%d)\n", index, rc); | |
7794 | goto cfg_fail_out; | |
7795 | } | |
7796 | } | |
75baf696 | 7797 | phba->sli4_hba.msix_vec_nr = vectors; |
da0436e9 JS |
7798 | |
7799 | return rc; | |
7800 | ||
7801 | cfg_fail_out: | |
7802 | /* free the irq already requested */ | |
7803 | for (--index; index >= 1; index--) | |
7804 | free_irq(phba->sli4_hba.msix_entries[index - 1].vector, | |
7805 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
7806 | ||
7807 | /* free the irq already requested */ | |
7808 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); | |
7809 | ||
7810 | msi_fail_out: | |
7811 | /* Unconfigure MSI-X capability structure */ | |
7812 | pci_disable_msix(phba->pcidev); | |
7813 | return rc; | |
7814 | } | |
7815 | ||
7816 | /** | |
7817 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device | |
7818 | * @phba: pointer to lpfc hba data structure. | |
7819 | * | |
7820 | * This routine is invoked to release the MSI-X vectors and then disable the | |
7821 | * MSI-X interrupt mode to device with SLI-4 interface spec. | |
7822 | **/ | |
7823 | static void | |
7824 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) | |
7825 | { | |
7826 | int index; | |
7827 | ||
7828 | /* Free up MSI-X multi-message vectors */ | |
7829 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); | |
7830 | ||
75baf696 | 7831 | for (index = 1; index < phba->sli4_hba.msix_vec_nr; index++) |
da0436e9 JS |
7832 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
7833 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
75baf696 | 7834 | |
da0436e9 JS |
7835 | /* Disable MSI-X */ |
7836 | pci_disable_msix(phba->pcidev); | |
7837 | ||
7838 | return; | |
7839 | } | |
7840 | ||
7841 | /** | |
7842 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device | |
7843 | * @phba: pointer to lpfc hba data structure. | |
7844 | * | |
7845 | * This routine is invoked to enable the MSI interrupt mode to device with | |
7846 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called | |
7847 | * to enable the MSI vector. The device driver is responsible for calling | |
7848 | * the request_irq() to register MSI vector with a interrupt the handler, | |
7849 | * which is done in this function. | |
7850 | * | |
7851 | * Return codes | |
af901ca1 | 7852 | * 0 - successful |
da0436e9 JS |
7853 | * other values - error |
7854 | **/ | |
7855 | static int | |
7856 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) | |
7857 | { | |
7858 | int rc, index; | |
7859 | ||
7860 | rc = pci_enable_msi(phba->pcidev); | |
7861 | if (!rc) | |
7862 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7863 | "0487 PCI enable MSI mode success.\n"); | |
7864 | else { | |
7865 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7866 | "0488 PCI enable MSI mode failed (%d)\n", rc); | |
7867 | return rc; | |
7868 | } | |
7869 | ||
7870 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
7871 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
7872 | if (rc) { | |
7873 | pci_disable_msi(phba->pcidev); | |
7874 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7875 | "0490 MSI request_irq failed (%d)\n", rc); | |
75baf696 | 7876 | return rc; |
da0436e9 JS |
7877 | } |
7878 | ||
7879 | for (index = 0; index < phba->cfg_fcp_eq_count; index++) { | |
7880 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | |
7881 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
7882 | } | |
7883 | ||
75baf696 | 7884 | return 0; |
da0436e9 JS |
7885 | } |
7886 | ||
7887 | /** | |
7888 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device | |
7889 | * @phba: pointer to lpfc hba data structure. | |
7890 | * | |
7891 | * This routine is invoked to disable the MSI interrupt mode to device with | |
7892 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has | |
7893 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | |
7894 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | |
7895 | * its vector. | |
7896 | **/ | |
7897 | static void | |
7898 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) | |
7899 | { | |
7900 | free_irq(phba->pcidev->irq, phba); | |
7901 | pci_disable_msi(phba->pcidev); | |
7902 | return; | |
7903 | } | |
7904 | ||
7905 | /** | |
7906 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device | |
7907 | * @phba: pointer to lpfc hba data structure. | |
7908 | * | |
7909 | * This routine is invoked to enable device interrupt and associate driver's | |
7910 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 | |
7911 | * interface spec. Depends on the interrupt mode configured to the driver, | |
7912 | * the driver will try to fallback from the configured interrupt mode to an | |
7913 | * interrupt mode which is supported by the platform, kernel, and device in | |
7914 | * the order of: | |
7915 | * MSI-X -> MSI -> IRQ. | |
7916 | * | |
7917 | * Return codes | |
af901ca1 | 7918 | * 0 - successful |
da0436e9 JS |
7919 | * other values - error |
7920 | **/ | |
7921 | static uint32_t | |
7922 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
7923 | { | |
7924 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
7925 | int retval, index; | |
7926 | ||
7927 | if (cfg_mode == 2) { | |
7928 | /* Preparation before conf_msi mbox cmd */ | |
7929 | retval = 0; | |
7930 | if (!retval) { | |
7931 | /* Now, try to enable MSI-X interrupt mode */ | |
7932 | retval = lpfc_sli4_enable_msix(phba); | |
7933 | if (!retval) { | |
7934 | /* Indicate initialization to MSI-X mode */ | |
7935 | phba->intr_type = MSIX; | |
7936 | intr_mode = 2; | |
7937 | } | |
7938 | } | |
7939 | } | |
7940 | ||
7941 | /* Fallback to MSI if MSI-X initialization failed */ | |
7942 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
7943 | retval = lpfc_sli4_enable_msi(phba); | |
7944 | if (!retval) { | |
7945 | /* Indicate initialization to MSI mode */ | |
7946 | phba->intr_type = MSI; | |
7947 | intr_mode = 1; | |
7948 | } | |
7949 | } | |
7950 | ||
7951 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
7952 | if (phba->intr_type == NONE) { | |
7953 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
7954 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
7955 | if (!retval) { | |
7956 | /* Indicate initialization to INTx mode */ | |
7957 | phba->intr_type = INTx; | |
7958 | intr_mode = 0; | |
7959 | for (index = 0; index < phba->cfg_fcp_eq_count; | |
7960 | index++) { | |
7961 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | |
7962 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
7963 | } | |
7964 | } | |
7965 | } | |
7966 | return intr_mode; | |
7967 | } | |
7968 | ||
7969 | /** | |
7970 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device | |
7971 | * @phba: pointer to lpfc hba data structure. | |
7972 | * | |
7973 | * This routine is invoked to disable device interrupt and disassociate | |
7974 | * the driver's interrupt handler(s) from interrupt vector(s) to device | |
7975 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver | |
7976 | * will release the interrupt vector(s) for the message signaled interrupt. | |
7977 | **/ | |
7978 | static void | |
7979 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) | |
7980 | { | |
7981 | /* Disable the currently initialized interrupt mode */ | |
7982 | if (phba->intr_type == MSIX) | |
7983 | lpfc_sli4_disable_msix(phba); | |
7984 | else if (phba->intr_type == MSI) | |
7985 | lpfc_sli4_disable_msi(phba); | |
7986 | else if (phba->intr_type == INTx) | |
7987 | free_irq(phba->pcidev->irq, phba); | |
7988 | ||
7989 | /* Reset interrupt management states */ | |
7990 | phba->intr_type = NONE; | |
7991 | phba->sli.slistat.sli_intr = 0; | |
7992 | ||
7993 | return; | |
7994 | } | |
7995 | ||
7996 | /** | |
7997 | * lpfc_unset_hba - Unset SLI3 hba device initialization | |
7998 | * @phba: pointer to lpfc hba data structure. | |
7999 | * | |
8000 | * This routine is invoked to unset the HBA device initialization steps to | |
8001 | * a device with SLI-3 interface spec. | |
8002 | **/ | |
8003 | static void | |
8004 | lpfc_unset_hba(struct lpfc_hba *phba) | |
8005 | { | |
8006 | struct lpfc_vport *vport = phba->pport; | |
8007 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
8008 | ||
8009 | spin_lock_irq(shost->host_lock); | |
8010 | vport->load_flag |= FC_UNLOADING; | |
8011 | spin_unlock_irq(shost->host_lock); | |
8012 | ||
8013 | lpfc_stop_hba_timers(phba); | |
8014 | ||
8015 | phba->pport->work_port_events = 0; | |
8016 | ||
8017 | lpfc_sli_hba_down(phba); | |
8018 | ||
8019 | lpfc_sli_brdrestart(phba); | |
8020 | ||
8021 | lpfc_sli_disable_intr(phba); | |
8022 | ||
8023 | return; | |
8024 | } | |
8025 | ||
8026 | /** | |
8027 | * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization. | |
8028 | * @phba: pointer to lpfc hba data structure. | |
8029 | * | |
8030 | * This routine is invoked to unset the HBA device initialization steps to | |
8031 | * a device with SLI-4 interface spec. | |
8032 | **/ | |
8033 | static void | |
8034 | lpfc_sli4_unset_hba(struct lpfc_hba *phba) | |
8035 | { | |
8036 | struct lpfc_vport *vport = phba->pport; | |
8037 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
8038 | ||
8039 | spin_lock_irq(shost->host_lock); | |
8040 | vport->load_flag |= FC_UNLOADING; | |
8041 | spin_unlock_irq(shost->host_lock); | |
8042 | ||
8043 | phba->pport->work_port_events = 0; | |
8044 | ||
3677a3a7 JS |
8045 | /* Stop the SLI4 device port */ |
8046 | lpfc_stop_port(phba); | |
da0436e9 JS |
8047 | |
8048 | lpfc_sli4_disable_intr(phba); | |
8049 | ||
3677a3a7 JS |
8050 | /* Reset SLI4 HBA FCoE function */ |
8051 | lpfc_pci_function_reset(phba); | |
5350d872 | 8052 | lpfc_sli4_queue_destroy(phba); |
3677a3a7 | 8053 | |
da0436e9 JS |
8054 | return; |
8055 | } | |
8056 | ||
5af5eee7 JS |
8057 | /** |
8058 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy | |
8059 | * @phba: Pointer to HBA context object. | |
8060 | * | |
8061 | * This function is called in the SLI4 code path to wait for completion | |
8062 | * of device's XRIs exchange busy. It will check the XRI exchange busy | |
8063 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after | |
8064 | * that, it will check the XRI exchange busy on outstanding FCP and ELS | |
8065 | * I/Os every 30 seconds, log error message, and wait forever. Only when | |
8066 | * all XRI exchange busy complete, the driver unload shall proceed with | |
8067 | * invoking the function reset ioctl mailbox command to the CNA and the | |
8068 | * the rest of the driver unload resource release. | |
8069 | **/ | |
8070 | static void | |
8071 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) | |
8072 | { | |
8073 | int wait_time = 0; | |
8074 | int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
8075 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
8076 | ||
8077 | while (!fcp_xri_cmpl || !els_xri_cmpl) { | |
8078 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { | |
8079 | if (!fcp_xri_cmpl) | |
8080 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8081 | "2877 FCP XRI exchange busy " | |
8082 | "wait time: %d seconds.\n", | |
8083 | wait_time/1000); | |
8084 | if (!els_xri_cmpl) | |
8085 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8086 | "2878 ELS XRI exchange busy " | |
8087 | "wait time: %d seconds.\n", | |
8088 | wait_time/1000); | |
8089 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); | |
8090 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; | |
8091 | } else { | |
8092 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); | |
8093 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; | |
8094 | } | |
8095 | fcp_xri_cmpl = | |
8096 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
8097 | els_xri_cmpl = | |
8098 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
8099 | } | |
8100 | } | |
8101 | ||
da0436e9 JS |
8102 | /** |
8103 | * lpfc_sli4_hba_unset - Unset the fcoe hba | |
8104 | * @phba: Pointer to HBA context object. | |
8105 | * | |
8106 | * This function is called in the SLI4 code path to reset the HBA's FCoE | |
8107 | * function. The caller is not required to hold any lock. This routine | |
8108 | * issues PCI function reset mailbox command to reset the FCoE function. | |
8109 | * At the end of the function, it calls lpfc_hba_down_post function to | |
8110 | * free any pending commands. | |
8111 | **/ | |
8112 | static void | |
8113 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) | |
8114 | { | |
8115 | int wait_cnt = 0; | |
8116 | LPFC_MBOXQ_t *mboxq; | |
912e3acd | 8117 | struct pci_dev *pdev = phba->pcidev; |
da0436e9 JS |
8118 | |
8119 | lpfc_stop_hba_timers(phba); | |
8120 | phba->sli4_hba.intr_enable = 0; | |
8121 | ||
8122 | /* | |
8123 | * Gracefully wait out the potential current outstanding asynchronous | |
8124 | * mailbox command. | |
8125 | */ | |
8126 | ||
8127 | /* First, block any pending async mailbox command from posted */ | |
8128 | spin_lock_irq(&phba->hbalock); | |
8129 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
8130 | spin_unlock_irq(&phba->hbalock); | |
8131 | /* Now, trying to wait it out if we can */ | |
8132 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
8133 | msleep(10); | |
8134 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) | |
8135 | break; | |
8136 | } | |
8137 | /* Forcefully release the outstanding mailbox command if timed out */ | |
8138 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
8139 | spin_lock_irq(&phba->hbalock); | |
8140 | mboxq = phba->sli.mbox_active; | |
8141 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
8142 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
8143 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
8144 | phba->sli.mbox_active = NULL; | |
8145 | spin_unlock_irq(&phba->hbalock); | |
8146 | } | |
8147 | ||
5af5eee7 JS |
8148 | /* Abort all iocbs associated with the hba */ |
8149 | lpfc_sli_hba_iocb_abort(phba); | |
8150 | ||
8151 | /* Wait for completion of device XRI exchange busy */ | |
8152 | lpfc_sli4_xri_exchange_busy_wait(phba); | |
8153 | ||
da0436e9 JS |
8154 | /* Disable PCI subsystem interrupt */ |
8155 | lpfc_sli4_disable_intr(phba); | |
8156 | ||
912e3acd JS |
8157 | /* Disable SR-IOV if enabled */ |
8158 | if (phba->cfg_sriov_nr_virtfn) | |
8159 | pci_disable_sriov(pdev); | |
8160 | ||
da0436e9 JS |
8161 | /* Stop kthread signal shall trigger work_done one more time */ |
8162 | kthread_stop(phba->worker_thread); | |
8163 | ||
3677a3a7 JS |
8164 | /* Reset SLI4 HBA FCoE function */ |
8165 | lpfc_pci_function_reset(phba); | |
5350d872 | 8166 | lpfc_sli4_queue_destroy(phba); |
3677a3a7 | 8167 | |
da0436e9 JS |
8168 | /* Stop the SLI4 device port */ |
8169 | phba->pport->work_port_events = 0; | |
8170 | } | |
8171 | ||
28baac74 JS |
8172 | /** |
8173 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. | |
8174 | * @phba: Pointer to HBA context object. | |
8175 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. | |
8176 | * | |
8177 | * This function is called in the SLI4 code path to read the port's | |
8178 | * sli4 capabilities. | |
8179 | * | |
8180 | * This function may be be called from any context that can block-wait | |
8181 | * for the completion. The expectation is that this routine is called | |
8182 | * typically from probe_one or from the online routine. | |
8183 | **/ | |
8184 | int | |
8185 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
8186 | { | |
8187 | int rc; | |
8188 | struct lpfc_mqe *mqe; | |
8189 | struct lpfc_pc_sli4_params *sli4_params; | |
8190 | uint32_t mbox_tmo; | |
8191 | ||
8192 | rc = 0; | |
8193 | mqe = &mboxq->u.mqe; | |
8194 | ||
8195 | /* Read the port's SLI4 Parameters port capabilities */ | |
fedd3b7b | 8196 | lpfc_pc_sli4_params(mboxq); |
28baac74 JS |
8197 | if (!phba->sli4_hba.intr_enable) |
8198 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
8199 | else { | |
a183a15f | 8200 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
28baac74 JS |
8201 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
8202 | } | |
8203 | ||
8204 | if (unlikely(rc)) | |
8205 | return 1; | |
8206 | ||
8207 | sli4_params = &phba->sli4_hba.pc_sli4_params; | |
8208 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); | |
8209 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); | |
8210 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); | |
8211 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, | |
8212 | &mqe->un.sli4_params); | |
8213 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, | |
8214 | &mqe->un.sli4_params); | |
8215 | sli4_params->proto_types = mqe->un.sli4_params.word3; | |
8216 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; | |
8217 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); | |
8218 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); | |
8219 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); | |
8220 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); | |
8221 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); | |
8222 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); | |
8223 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); | |
8224 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); | |
8225 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); | |
8226 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); | |
8227 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); | |
8228 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); | |
8229 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); | |
8230 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); | |
8231 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); | |
8232 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); | |
8233 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); | |
8234 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); | |
8235 | sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params); | |
0558056c JS |
8236 | |
8237 | /* Make sure that sge_supp_len can be handled by the driver */ | |
8238 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) | |
8239 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; | |
8240 | ||
28baac74 JS |
8241 | return rc; |
8242 | } | |
8243 | ||
fedd3b7b JS |
8244 | /** |
8245 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. | |
8246 | * @phba: Pointer to HBA context object. | |
8247 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. | |
8248 | * | |
8249 | * This function is called in the SLI4 code path to read the port's | |
8250 | * sli4 capabilities. | |
8251 | * | |
8252 | * This function may be be called from any context that can block-wait | |
8253 | * for the completion. The expectation is that this routine is called | |
8254 | * typically from probe_one or from the online routine. | |
8255 | **/ | |
8256 | int | |
8257 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
8258 | { | |
8259 | int rc; | |
8260 | struct lpfc_mqe *mqe = &mboxq->u.mqe; | |
8261 | struct lpfc_pc_sli4_params *sli4_params; | |
a183a15f | 8262 | uint32_t mbox_tmo; |
fedd3b7b JS |
8263 | int length; |
8264 | struct lpfc_sli4_parameters *mbx_sli4_parameters; | |
8265 | ||
6d368e53 JS |
8266 | /* |
8267 | * By default, the driver assumes the SLI4 port requires RPI | |
8268 | * header postings. The SLI4_PARAM response will correct this | |
8269 | * assumption. | |
8270 | */ | |
8271 | phba->sli4_hba.rpi_hdrs_in_use = 1; | |
8272 | ||
fedd3b7b JS |
8273 | /* Read the port's SLI4 Config Parameters */ |
8274 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - | |
8275 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
8276 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
8277 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, | |
8278 | length, LPFC_SLI4_MBX_EMBED); | |
8279 | if (!phba->sli4_hba.intr_enable) | |
8280 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
a183a15f JS |
8281 | else { |
8282 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); | |
8283 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
8284 | } | |
fedd3b7b JS |
8285 | if (unlikely(rc)) |
8286 | return rc; | |
8287 | sli4_params = &phba->sli4_hba.pc_sli4_params; | |
8288 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; | |
8289 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); | |
8290 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); | |
8291 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); | |
8292 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, | |
8293 | mbx_sli4_parameters); | |
8294 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, | |
8295 | mbx_sli4_parameters); | |
8296 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) | |
8297 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; | |
8298 | else | |
8299 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; | |
8300 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; | |
8301 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); | |
8302 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); | |
8303 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); | |
8304 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); | |
8305 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); | |
8306 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, | |
8307 | mbx_sli4_parameters); | |
8308 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, | |
8309 | mbx_sli4_parameters); | |
6d368e53 JS |
8310 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
8311 | phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters); | |
0558056c JS |
8312 | |
8313 | /* Make sure that sge_supp_len can be handled by the driver */ | |
8314 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) | |
8315 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; | |
8316 | ||
fedd3b7b JS |
8317 | return 0; |
8318 | } | |
8319 | ||
da0436e9 JS |
8320 | /** |
8321 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. | |
8322 | * @pdev: pointer to PCI device | |
8323 | * @pid: pointer to PCI device identifier | |
8324 | * | |
8325 | * This routine is to be called to attach a device with SLI-3 interface spec | |
8326 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
8327 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific | |
8328 | * information of the device and driver to see if the driver state that it can | |
8329 | * support this kind of device. If the match is successful, the driver core | |
8330 | * invokes this routine. If this routine determines it can claim the HBA, it | |
8331 | * does all the initialization that it needs to do to handle the HBA properly. | |
8332 | * | |
8333 | * Return code | |
8334 | * 0 - driver can claim the device | |
8335 | * negative value - driver can not claim the device | |
8336 | **/ | |
8337 | static int __devinit | |
8338 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) | |
8339 | { | |
8340 | struct lpfc_hba *phba; | |
8341 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 8342 | struct Scsi_Host *shost = NULL; |
da0436e9 JS |
8343 | int error; |
8344 | uint32_t cfg_mode, intr_mode; | |
8345 | ||
8346 | /* Allocate memory for HBA structure */ | |
8347 | phba = lpfc_hba_alloc(pdev); | |
8348 | if (!phba) | |
8349 | return -ENOMEM; | |
8350 | ||
8351 | /* Perform generic PCI device enabling operation */ | |
8352 | error = lpfc_enable_pci_dev(phba); | |
079b5c91 | 8353 | if (error) |
da0436e9 | 8354 | goto out_free_phba; |
da0436e9 JS |
8355 | |
8356 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ | |
8357 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); | |
8358 | if (error) | |
8359 | goto out_disable_pci_dev; | |
8360 | ||
8361 | /* Set up SLI-3 specific device PCI memory space */ | |
8362 | error = lpfc_sli_pci_mem_setup(phba); | |
8363 | if (error) { | |
8364 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8365 | "1402 Failed to set up pci memory space.\n"); | |
8366 | goto out_disable_pci_dev; | |
8367 | } | |
8368 | ||
8369 | /* Set up phase-1 common device driver resources */ | |
8370 | error = lpfc_setup_driver_resource_phase1(phba); | |
8371 | if (error) { | |
8372 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8373 | "1403 Failed to set up driver resource.\n"); | |
8374 | goto out_unset_pci_mem_s3; | |
8375 | } | |
8376 | ||
8377 | /* Set up SLI-3 specific device driver resources */ | |
8378 | error = lpfc_sli_driver_resource_setup(phba); | |
8379 | if (error) { | |
8380 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8381 | "1404 Failed to set up driver resource.\n"); | |
8382 | goto out_unset_pci_mem_s3; | |
8383 | } | |
8384 | ||
8385 | /* Initialize and populate the iocb list per host */ | |
8386 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); | |
8387 | if (error) { | |
8388 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8389 | "1405 Failed to initialize iocb list.\n"); | |
8390 | goto out_unset_driver_resource_s3; | |
8391 | } | |
8392 | ||
8393 | /* Set up common device driver resources */ | |
8394 | error = lpfc_setup_driver_resource_phase2(phba); | |
8395 | if (error) { | |
8396 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8397 | "1406 Failed to set up driver resource.\n"); | |
8398 | goto out_free_iocb_list; | |
8399 | } | |
8400 | ||
079b5c91 JS |
8401 | /* Get the default values for Model Name and Description */ |
8402 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
8403 | ||
da0436e9 JS |
8404 | /* Create SCSI host to the physical port */ |
8405 | error = lpfc_create_shost(phba); | |
8406 | if (error) { | |
8407 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8408 | "1407 Failed to create scsi host.\n"); | |
8409 | goto out_unset_driver_resource; | |
8410 | } | |
8411 | ||
8412 | /* Configure sysfs attributes */ | |
8413 | vport = phba->pport; | |
8414 | error = lpfc_alloc_sysfs_attr(vport); | |
8415 | if (error) { | |
8416 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8417 | "1476 Failed to allocate sysfs attr\n"); | |
8418 | goto out_destroy_shost; | |
8419 | } | |
8420 | ||
6669f9bb | 8421 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
da0436e9 JS |
8422 | /* Now, trying to enable interrupt and bring up the device */ |
8423 | cfg_mode = phba->cfg_use_msi; | |
8424 | while (true) { | |
8425 | /* Put device to a known state before enabling interrupt */ | |
8426 | lpfc_stop_port(phba); | |
8427 | /* Configure and enable interrupt */ | |
8428 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); | |
8429 | if (intr_mode == LPFC_INTR_ERROR) { | |
8430 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8431 | "0431 Failed to enable interrupt.\n"); | |
8432 | error = -ENODEV; | |
8433 | goto out_free_sysfs_attr; | |
8434 | } | |
8435 | /* SLI-3 HBA setup */ | |
8436 | if (lpfc_sli_hba_setup(phba)) { | |
8437 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8438 | "1477 Failed to set up hba\n"); | |
8439 | error = -ENODEV; | |
8440 | goto out_remove_device; | |
8441 | } | |
8442 | ||
8443 | /* Wait 50ms for the interrupts of previous mailbox commands */ | |
8444 | msleep(50); | |
8445 | /* Check active interrupts on message signaled interrupts */ | |
8446 | if (intr_mode == 0 || | |
8447 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { | |
8448 | /* Log the current active interrupt mode */ | |
8449 | phba->intr_mode = intr_mode; | |
8450 | lpfc_log_intr_mode(phba, intr_mode); | |
8451 | break; | |
8452 | } else { | |
8453 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8454 | "0447 Configure interrupt mode (%d) " | |
8455 | "failed active interrupt test.\n", | |
8456 | intr_mode); | |
8457 | /* Disable the current interrupt mode */ | |
8458 | lpfc_sli_disable_intr(phba); | |
8459 | /* Try next level of interrupt mode */ | |
8460 | cfg_mode = --intr_mode; | |
8461 | } | |
8462 | } | |
8463 | ||
8464 | /* Perform post initialization setup */ | |
8465 | lpfc_post_init_setup(phba); | |
8466 | ||
8467 | /* Check if there are static vports to be created. */ | |
8468 | lpfc_create_static_vport(phba); | |
8469 | ||
8470 | return 0; | |
8471 | ||
8472 | out_remove_device: | |
8473 | lpfc_unset_hba(phba); | |
8474 | out_free_sysfs_attr: | |
8475 | lpfc_free_sysfs_attr(vport); | |
8476 | out_destroy_shost: | |
8477 | lpfc_destroy_shost(phba); | |
8478 | out_unset_driver_resource: | |
8479 | lpfc_unset_driver_resource_phase2(phba); | |
8480 | out_free_iocb_list: | |
8481 | lpfc_free_iocb_list(phba); | |
8482 | out_unset_driver_resource_s3: | |
8483 | lpfc_sli_driver_resource_unset(phba); | |
8484 | out_unset_pci_mem_s3: | |
8485 | lpfc_sli_pci_mem_unset(phba); | |
8486 | out_disable_pci_dev: | |
8487 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
8488 | if (shost) |
8489 | scsi_host_put(shost); | |
da0436e9 JS |
8490 | out_free_phba: |
8491 | lpfc_hba_free(phba); | |
8492 | return error; | |
8493 | } | |
8494 | ||
8495 | /** | |
8496 | * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem. | |
8497 | * @pdev: pointer to PCI device | |
8498 | * | |
8499 | * This routine is to be called to disattach a device with SLI-3 interface | |
8500 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
8501 | * removed from PCI bus, it performs all the necessary cleanup for the HBA | |
8502 | * device to be removed from the PCI subsystem properly. | |
8503 | **/ | |
8504 | static void __devexit | |
8505 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) | |
8506 | { | |
8507 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8508 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
8509 | struct lpfc_vport **vports; | |
8510 | struct lpfc_hba *phba = vport->phba; | |
8511 | int i; | |
8512 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
8513 | ||
8514 | spin_lock_irq(&phba->hbalock); | |
8515 | vport->load_flag |= FC_UNLOADING; | |
8516 | spin_unlock_irq(&phba->hbalock); | |
8517 | ||
8518 | lpfc_free_sysfs_attr(vport); | |
8519 | ||
8520 | /* Release all the vports against this physical port */ | |
8521 | vports = lpfc_create_vport_work_array(phba); | |
8522 | if (vports != NULL) | |
8523 | for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) | |
8524 | fc_vport_terminate(vports[i]->fc_vport); | |
8525 | lpfc_destroy_vport_work_array(phba, vports); | |
8526 | ||
8527 | /* Remove FC host and then SCSI host with the physical port */ | |
8528 | fc_remove_host(shost); | |
8529 | scsi_remove_host(shost); | |
8530 | lpfc_cleanup(vport); | |
8531 | ||
8532 | /* | |
8533 | * Bring down the SLI Layer. This step disable all interrupts, | |
8534 | * clears the rings, discards all mailbox commands, and resets | |
8535 | * the HBA. | |
8536 | */ | |
8537 | ||
48e34d0f | 8538 | /* HBA interrupt will be disabled after this call */ |
da0436e9 JS |
8539 | lpfc_sli_hba_down(phba); |
8540 | /* Stop kthread signal shall trigger work_done one more time */ | |
8541 | kthread_stop(phba->worker_thread); | |
8542 | /* Final cleanup of txcmplq and reset the HBA */ | |
8543 | lpfc_sli_brdrestart(phba); | |
8544 | ||
8545 | lpfc_stop_hba_timers(phba); | |
8546 | spin_lock_irq(&phba->hbalock); | |
8547 | list_del_init(&vport->listentry); | |
8548 | spin_unlock_irq(&phba->hbalock); | |
8549 | ||
8550 | lpfc_debugfs_terminate(vport); | |
8551 | ||
912e3acd JS |
8552 | /* Disable SR-IOV if enabled */ |
8553 | if (phba->cfg_sriov_nr_virtfn) | |
8554 | pci_disable_sriov(pdev); | |
8555 | ||
da0436e9 JS |
8556 | /* Disable interrupt */ |
8557 | lpfc_sli_disable_intr(phba); | |
8558 | ||
8559 | pci_set_drvdata(pdev, NULL); | |
8560 | scsi_host_put(shost); | |
8561 | ||
8562 | /* | |
8563 | * Call scsi_free before mem_free since scsi bufs are released to their | |
8564 | * corresponding pools here. | |
8565 | */ | |
8566 | lpfc_scsi_free(phba); | |
8567 | lpfc_mem_free_all(phba); | |
8568 | ||
8569 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
8570 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
8571 | ||
8572 | /* Free resources associated with SLI2 interface */ | |
8573 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
8574 | phba->slim2p.virt, phba->slim2p.phys); | |
8575 | ||
8576 | /* unmap adapter SLIM and Control Registers */ | |
8577 | iounmap(phba->ctrl_regs_memmap_p); | |
8578 | iounmap(phba->slim_memmap_p); | |
8579 | ||
8580 | lpfc_hba_free(phba); | |
8581 | ||
8582 | pci_release_selected_regions(pdev, bars); | |
8583 | pci_disable_device(pdev); | |
8584 | } | |
8585 | ||
8586 | /** | |
8587 | * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt | |
8588 | * @pdev: pointer to PCI device | |
8589 | * @msg: power management message | |
8590 | * | |
8591 | * This routine is to be called from the kernel's PCI subsystem to support | |
8592 | * system Power Management (PM) to device with SLI-3 interface spec. When | |
8593 | * PM invokes this method, it quiesces the device by stopping the driver's | |
8594 | * worker thread for the device, turning off device's interrupt and DMA, | |
8595 | * and bring the device offline. Note that as the driver implements the | |
8596 | * minimum PM requirements to a power-aware driver's PM support for the | |
8597 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
8598 | * to the suspend() method call will be treated as SUSPEND and the driver will | |
8599 | * fully reinitialize its device during resume() method call, the driver will | |
8600 | * set device to PCI_D3hot state in PCI config space instead of setting it | |
8601 | * according to the @msg provided by the PM. | |
8602 | * | |
8603 | * Return code | |
8604 | * 0 - driver suspended the device | |
8605 | * Error otherwise | |
8606 | **/ | |
8607 | static int | |
8608 | lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg) | |
8609 | { | |
8610 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8611 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8612 | ||
8613 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8614 | "0473 PCI device Power Management suspend.\n"); | |
8615 | ||
8616 | /* Bring down the device */ | |
8617 | lpfc_offline_prep(phba); | |
8618 | lpfc_offline(phba); | |
8619 | kthread_stop(phba->worker_thread); | |
8620 | ||
8621 | /* Disable interrupt from device */ | |
8622 | lpfc_sli_disable_intr(phba); | |
8623 | ||
8624 | /* Save device state to PCI config space */ | |
8625 | pci_save_state(pdev); | |
8626 | pci_set_power_state(pdev, PCI_D3hot); | |
8627 | ||
8628 | return 0; | |
8629 | } | |
8630 | ||
8631 | /** | |
8632 | * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt | |
8633 | * @pdev: pointer to PCI device | |
8634 | * | |
8635 | * This routine is to be called from the kernel's PCI subsystem to support | |
8636 | * system Power Management (PM) to device with SLI-3 interface spec. When PM | |
8637 | * invokes this method, it restores the device's PCI config space state and | |
8638 | * fully reinitializes the device and brings it online. Note that as the | |
8639 | * driver implements the minimum PM requirements to a power-aware driver's | |
8640 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, | |
8641 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the | |
8642 | * driver will fully reinitialize its device during resume() method call, | |
8643 | * the device will be set to PCI_D0 directly in PCI config space before | |
8644 | * restoring the state. | |
8645 | * | |
8646 | * Return code | |
8647 | * 0 - driver suspended the device | |
8648 | * Error otherwise | |
8649 | **/ | |
8650 | static int | |
8651 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) | |
8652 | { | |
8653 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8654 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8655 | uint32_t intr_mode; | |
8656 | int error; | |
8657 | ||
8658 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8659 | "0452 PCI device Power Management resume.\n"); | |
8660 | ||
8661 | /* Restore device state from PCI config space */ | |
8662 | pci_set_power_state(pdev, PCI_D0); | |
8663 | pci_restore_state(pdev); | |
0d878419 | 8664 | |
1dfb5a47 JS |
8665 | /* |
8666 | * As the new kernel behavior of pci_restore_state() API call clears | |
8667 | * device saved_state flag, need to save the restored state again. | |
8668 | */ | |
8669 | pci_save_state(pdev); | |
8670 | ||
da0436e9 JS |
8671 | if (pdev->is_busmaster) |
8672 | pci_set_master(pdev); | |
8673 | ||
8674 | /* Startup the kernel thread for this host adapter. */ | |
8675 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
8676 | "lpfc_worker_%d", phba->brd_no); | |
8677 | if (IS_ERR(phba->worker_thread)) { | |
8678 | error = PTR_ERR(phba->worker_thread); | |
8679 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8680 | "0434 PM resume failed to start worker " | |
8681 | "thread: error=x%x.\n", error); | |
8682 | return error; | |
8683 | } | |
8684 | ||
8685 | /* Configure and enable interrupt */ | |
8686 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
8687 | if (intr_mode == LPFC_INTR_ERROR) { | |
8688 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8689 | "0430 PM resume Failed to enable interrupt\n"); | |
8690 | return -EIO; | |
8691 | } else | |
8692 | phba->intr_mode = intr_mode; | |
8693 | ||
8694 | /* Restart HBA and bring it online */ | |
8695 | lpfc_sli_brdrestart(phba); | |
8696 | lpfc_online(phba); | |
8697 | ||
8698 | /* Log the current active interrupt mode */ | |
8699 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
8700 | ||
8701 | return 0; | |
8702 | } | |
8703 | ||
891478a2 JS |
8704 | /** |
8705 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover | |
8706 | * @phba: pointer to lpfc hba data structure. | |
8707 | * | |
8708 | * This routine is called to prepare the SLI3 device for PCI slot recover. It | |
e2af0d2e | 8709 | * aborts all the outstanding SCSI I/Os to the pci device. |
891478a2 JS |
8710 | **/ |
8711 | static void | |
8712 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) | |
8713 | { | |
e2af0d2e JS |
8714 | struct lpfc_sli *psli = &phba->sli; |
8715 | struct lpfc_sli_ring *pring; | |
8716 | ||
891478a2 JS |
8717 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
8718 | "2723 PCI channel I/O abort preparing for recovery\n"); | |
e2af0d2e JS |
8719 | |
8720 | /* | |
8721 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
8722 | * and let the SCSI mid-layer to retry them to recover. | |
8723 | */ | |
8724 | pring = &psli->ring[psli->fcp_ring]; | |
8725 | lpfc_sli_abort_iocb_ring(phba, pring); | |
891478a2 JS |
8726 | } |
8727 | ||
0d878419 JS |
8728 | /** |
8729 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset | |
8730 | * @phba: pointer to lpfc hba data structure. | |
8731 | * | |
8732 | * This routine is called to prepare the SLI3 device for PCI slot reset. It | |
8733 | * disables the device interrupt and pci device, and aborts the internal FCP | |
8734 | * pending I/Os. | |
8735 | **/ | |
8736 | static void | |
8737 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) | |
8738 | { | |
0d878419 | 8739 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
891478a2 | 8740 | "2710 PCI channel disable preparing for reset\n"); |
e2af0d2e | 8741 | |
75baf696 JS |
8742 | /* Block any management I/Os to the device */ |
8743 | lpfc_block_mgmt_io(phba); | |
8744 | ||
e2af0d2e JS |
8745 | /* Block all SCSI devices' I/Os on the host */ |
8746 | lpfc_scsi_dev_block(phba); | |
8747 | ||
8748 | /* stop all timers */ | |
8749 | lpfc_stop_hba_timers(phba); | |
8750 | ||
0d878419 JS |
8751 | /* Disable interrupt and pci device */ |
8752 | lpfc_sli_disable_intr(phba); | |
8753 | pci_disable_device(phba->pcidev); | |
75baf696 | 8754 | |
e2af0d2e JS |
8755 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
8756 | lpfc_sli_flush_fcp_rings(phba); | |
0d878419 JS |
8757 | } |
8758 | ||
8759 | /** | |
8760 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable | |
8761 | * @phba: pointer to lpfc hba data structure. | |
8762 | * | |
8763 | * This routine is called to prepare the SLI3 device for PCI slot permanently | |
8764 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
8765 | * pending I/Os. | |
8766 | **/ | |
8767 | static void | |
75baf696 | 8768 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
0d878419 JS |
8769 | { |
8770 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
891478a2 | 8771 | "2711 PCI channel permanent disable for failure\n"); |
e2af0d2e JS |
8772 | /* Block all SCSI devices' I/Os on the host */ |
8773 | lpfc_scsi_dev_block(phba); | |
8774 | ||
8775 | /* stop all timers */ | |
8776 | lpfc_stop_hba_timers(phba); | |
8777 | ||
0d878419 JS |
8778 | /* Clean up all driver's outstanding SCSI I/Os */ |
8779 | lpfc_sli_flush_fcp_rings(phba); | |
8780 | } | |
8781 | ||
da0436e9 JS |
8782 | /** |
8783 | * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error | |
8784 | * @pdev: pointer to PCI device. | |
8785 | * @state: the current PCI connection state. | |
8786 | * | |
8787 | * This routine is called from the PCI subsystem for I/O error handling to | |
8788 | * device with SLI-3 interface spec. This function is called by the PCI | |
8789 | * subsystem after a PCI bus error affecting this device has been detected. | |
8790 | * When this function is invoked, it will need to stop all the I/Os and | |
8791 | * interrupt(s) to the device. Once that is done, it will return | |
8792 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery | |
8793 | * as desired. | |
8794 | * | |
8795 | * Return codes | |
0d878419 | 8796 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
da0436e9 JS |
8797 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
8798 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8799 | **/ | |
8800 | static pci_ers_result_t | |
8801 | lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state) | |
8802 | { | |
8803 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8804 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
da0436e9 | 8805 | |
0d878419 JS |
8806 | switch (state) { |
8807 | case pci_channel_io_normal: | |
891478a2 JS |
8808 | /* Non-fatal error, prepare for recovery */ |
8809 | lpfc_sli_prep_dev_for_recover(phba); | |
0d878419 JS |
8810 | return PCI_ERS_RESULT_CAN_RECOVER; |
8811 | case pci_channel_io_frozen: | |
8812 | /* Fatal error, prepare for slot reset */ | |
8813 | lpfc_sli_prep_dev_for_reset(phba); | |
8814 | return PCI_ERS_RESULT_NEED_RESET; | |
8815 | case pci_channel_io_perm_failure: | |
8816 | /* Permanent failure, prepare for device down */ | |
75baf696 | 8817 | lpfc_sli_prep_dev_for_perm_failure(phba); |
da0436e9 | 8818 | return PCI_ERS_RESULT_DISCONNECT; |
0d878419 JS |
8819 | default: |
8820 | /* Unknown state, prepare and request slot reset */ | |
8821 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8822 | "0472 Unknown PCI error state: x%x\n", state); | |
8823 | lpfc_sli_prep_dev_for_reset(phba); | |
8824 | return PCI_ERS_RESULT_NEED_RESET; | |
da0436e9 | 8825 | } |
da0436e9 JS |
8826 | } |
8827 | ||
8828 | /** | |
8829 | * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch. | |
8830 | * @pdev: pointer to PCI device. | |
8831 | * | |
8832 | * This routine is called from the PCI subsystem for error handling to | |
8833 | * device with SLI-3 interface spec. This is called after PCI bus has been | |
8834 | * reset to restart the PCI card from scratch, as if from a cold-boot. | |
8835 | * During the PCI subsystem error recovery, after driver returns | |
8836 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error | |
8837 | * recovery and then call this routine before calling the .resume method | |
8838 | * to recover the device. This function will initialize the HBA device, | |
8839 | * enable the interrupt, but it will just put the HBA to offline state | |
8840 | * without passing any I/O traffic. | |
8841 | * | |
8842 | * Return codes | |
8843 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
8844 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8845 | */ | |
8846 | static pci_ers_result_t | |
8847 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) | |
8848 | { | |
8849 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8850 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8851 | struct lpfc_sli *psli = &phba->sli; | |
8852 | uint32_t intr_mode; | |
8853 | ||
8854 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
8855 | if (pci_enable_device_mem(pdev)) { | |
8856 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
8857 | "PCI device after reset.\n"); | |
8858 | return PCI_ERS_RESULT_DISCONNECT; | |
8859 | } | |
8860 | ||
8861 | pci_restore_state(pdev); | |
1dfb5a47 JS |
8862 | |
8863 | /* | |
8864 | * As the new kernel behavior of pci_restore_state() API call clears | |
8865 | * device saved_state flag, need to save the restored state again. | |
8866 | */ | |
8867 | pci_save_state(pdev); | |
8868 | ||
da0436e9 JS |
8869 | if (pdev->is_busmaster) |
8870 | pci_set_master(pdev); | |
8871 | ||
8872 | spin_lock_irq(&phba->hbalock); | |
8873 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
8874 | spin_unlock_irq(&phba->hbalock); | |
8875 | ||
8876 | /* Configure and enable interrupt */ | |
8877 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
8878 | if (intr_mode == LPFC_INTR_ERROR) { | |
8879 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8880 | "0427 Cannot re-enable interrupt after " | |
8881 | "slot reset.\n"); | |
8882 | return PCI_ERS_RESULT_DISCONNECT; | |
8883 | } else | |
8884 | phba->intr_mode = intr_mode; | |
8885 | ||
75baf696 JS |
8886 | /* Take device offline, it will perform cleanup */ |
8887 | lpfc_offline_prep(phba); | |
da0436e9 JS |
8888 | lpfc_offline(phba); |
8889 | lpfc_sli_brdrestart(phba); | |
8890 | ||
8891 | /* Log the current active interrupt mode */ | |
8892 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
8893 | ||
8894 | return PCI_ERS_RESULT_RECOVERED; | |
8895 | } | |
8896 | ||
8897 | /** | |
8898 | * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device. | |
8899 | * @pdev: pointer to PCI device | |
8900 | * | |
8901 | * This routine is called from the PCI subsystem for error handling to device | |
8902 | * with SLI-3 interface spec. It is called when kernel error recovery tells | |
8903 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus | |
8904 | * error recovery. After this call, traffic can start to flow from this device | |
8905 | * again. | |
8906 | */ | |
8907 | static void | |
8908 | lpfc_io_resume_s3(struct pci_dev *pdev) | |
8909 | { | |
8910 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8911 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
3772a991 | 8912 | |
e2af0d2e | 8913 | /* Bring device online, it will be no-op for non-fatal error resume */ |
da0436e9 | 8914 | lpfc_online(phba); |
0d878419 JS |
8915 | |
8916 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
8917 | if (phba->hba_flag & HBA_AER_ENABLED) | |
8918 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
da0436e9 | 8919 | } |
3772a991 | 8920 | |
da0436e9 JS |
8921 | /** |
8922 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve | |
8923 | * @phba: pointer to lpfc hba data structure. | |
8924 | * | |
8925 | * returns the number of ELS/CT IOCBs to reserve | |
8926 | **/ | |
8927 | int | |
8928 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) | |
8929 | { | |
8930 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; | |
8931 | ||
f1126688 JS |
8932 | if (phba->sli_rev == LPFC_SLI_REV4) { |
8933 | if (max_xri <= 100) | |
6a9c52cf | 8934 | return 10; |
f1126688 | 8935 | else if (max_xri <= 256) |
6a9c52cf | 8936 | return 25; |
f1126688 | 8937 | else if (max_xri <= 512) |
6a9c52cf | 8938 | return 50; |
f1126688 | 8939 | else if (max_xri <= 1024) |
6a9c52cf | 8940 | return 100; |
f1126688 | 8941 | else |
6a9c52cf | 8942 | return 150; |
f1126688 JS |
8943 | } else |
8944 | return 0; | |
3772a991 JS |
8945 | } |
8946 | ||
52d52440 JS |
8947 | /** |
8948 | * lpfc_write_firmware - attempt to write a firmware image to the port | |
8949 | * @phba: pointer to lpfc hba data structure. | |
8950 | * @fw: pointer to firmware image returned from request_firmware. | |
8951 | * | |
8952 | * returns the number of bytes written if write is successful. | |
8953 | * returns a negative error value if there were errors. | |
8954 | * returns 0 if firmware matches currently active firmware on port. | |
8955 | **/ | |
8956 | int | |
8957 | lpfc_write_firmware(struct lpfc_hba *phba, const struct firmware *fw) | |
8958 | { | |
8959 | char fwrev[32]; | |
8960 | struct lpfc_grp_hdr *image = (struct lpfc_grp_hdr *)fw->data; | |
8961 | struct list_head dma_buffer_list; | |
8962 | int i, rc = 0; | |
8963 | struct lpfc_dmabuf *dmabuf, *next; | |
8964 | uint32_t offset = 0, temp_offset = 0; | |
8965 | ||
8966 | INIT_LIST_HEAD(&dma_buffer_list); | |
079b5c91 JS |
8967 | if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) || |
8968 | (bf_get_be32(lpfc_grp_hdr_file_type, image) != | |
8969 | LPFC_FILE_TYPE_GROUP) || | |
8970 | (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) || | |
8971 | (be32_to_cpu(image->size) != fw->size)) { | |
52d52440 JS |
8972 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
8973 | "3022 Invalid FW image found. " | |
079b5c91 JS |
8974 | "Magic:%x Type:%x ID:%x\n", |
8975 | be32_to_cpu(image->magic_number), | |
8976 | bf_get_be32(lpfc_grp_hdr_file_type, image), | |
8977 | bf_get_be32(lpfc_grp_hdr_id, image)); | |
52d52440 JS |
8978 | return -EINVAL; |
8979 | } | |
8980 | lpfc_decode_firmware_rev(phba, fwrev, 1); | |
88a2cfbb | 8981 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
52d52440 JS |
8982 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
8983 | "3023 Updating Firmware. Current Version:%s " | |
8984 | "New Version:%s\n", | |
88a2cfbb | 8985 | fwrev, image->revision); |
52d52440 JS |
8986 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
8987 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), | |
8988 | GFP_KERNEL); | |
8989 | if (!dmabuf) { | |
8990 | rc = -ENOMEM; | |
8991 | goto out; | |
8992 | } | |
8993 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
8994 | SLI4_PAGE_SIZE, | |
8995 | &dmabuf->phys, | |
8996 | GFP_KERNEL); | |
8997 | if (!dmabuf->virt) { | |
8998 | kfree(dmabuf); | |
8999 | rc = -ENOMEM; | |
9000 | goto out; | |
9001 | } | |
9002 | list_add_tail(&dmabuf->list, &dma_buffer_list); | |
9003 | } | |
9004 | while (offset < fw->size) { | |
9005 | temp_offset = offset; | |
9006 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { | |
079b5c91 | 9007 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
52d52440 JS |
9008 | memcpy(dmabuf->virt, |
9009 | fw->data + temp_offset, | |
079b5c91 JS |
9010 | fw->size - temp_offset); |
9011 | temp_offset = fw->size; | |
52d52440 JS |
9012 | break; |
9013 | } | |
52d52440 JS |
9014 | memcpy(dmabuf->virt, fw->data + temp_offset, |
9015 | SLI4_PAGE_SIZE); | |
88a2cfbb | 9016 | temp_offset += SLI4_PAGE_SIZE; |
52d52440 JS |
9017 | } |
9018 | rc = lpfc_wr_object(phba, &dma_buffer_list, | |
9019 | (fw->size - offset), &offset); | |
9020 | if (rc) { | |
9021 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9022 | "3024 Firmware update failed. " | |
9023 | "%d\n", rc); | |
9024 | goto out; | |
9025 | } | |
9026 | } | |
9027 | rc = offset; | |
9028 | } | |
9029 | out: | |
9030 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { | |
9031 | list_del(&dmabuf->list); | |
9032 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, | |
9033 | dmabuf->virt, dmabuf->phys); | |
9034 | kfree(dmabuf); | |
9035 | } | |
9036 | return rc; | |
9037 | } | |
9038 | ||
3772a991 | 9039 | /** |
da0436e9 | 9040 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
3772a991 JS |
9041 | * @pdev: pointer to PCI device |
9042 | * @pid: pointer to PCI device identifier | |
9043 | * | |
da0436e9 JS |
9044 | * This routine is called from the kernel's PCI subsystem to device with |
9045 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 | 9046 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
da0436e9 JS |
9047 | * information of the device and driver to see if the driver state that it |
9048 | * can support this kind of device. If the match is successful, the driver | |
9049 | * core invokes this routine. If this routine determines it can claim the HBA, | |
9050 | * it does all the initialization that it needs to do to handle the HBA | |
9051 | * properly. | |
3772a991 JS |
9052 | * |
9053 | * Return code | |
9054 | * 0 - driver can claim the device | |
9055 | * negative value - driver can not claim the device | |
9056 | **/ | |
9057 | static int __devinit | |
da0436e9 | 9058 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
3772a991 JS |
9059 | { |
9060 | struct lpfc_hba *phba; | |
9061 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 9062 | struct Scsi_Host *shost = NULL; |
3772a991 JS |
9063 | int error; |
9064 | uint32_t cfg_mode, intr_mode; | |
da0436e9 | 9065 | int mcnt; |
0558056c | 9066 | int adjusted_fcp_eq_count; |
52d52440 JS |
9067 | const struct firmware *fw; |
9068 | uint8_t file_name[16]; | |
3772a991 JS |
9069 | |
9070 | /* Allocate memory for HBA structure */ | |
9071 | phba = lpfc_hba_alloc(pdev); | |
9072 | if (!phba) | |
9073 | return -ENOMEM; | |
9074 | ||
9075 | /* Perform generic PCI device enabling operation */ | |
9076 | error = lpfc_enable_pci_dev(phba); | |
079b5c91 | 9077 | if (error) |
3772a991 | 9078 | goto out_free_phba; |
3772a991 | 9079 | |
da0436e9 JS |
9080 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
9081 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); | |
3772a991 JS |
9082 | if (error) |
9083 | goto out_disable_pci_dev; | |
9084 | ||
da0436e9 JS |
9085 | /* Set up SLI-4 specific device PCI memory space */ |
9086 | error = lpfc_sli4_pci_mem_setup(phba); | |
3772a991 JS |
9087 | if (error) { |
9088 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9089 | "1410 Failed to set up pci memory space.\n"); |
3772a991 JS |
9090 | goto out_disable_pci_dev; |
9091 | } | |
9092 | ||
9093 | /* Set up phase-1 common device driver resources */ | |
9094 | error = lpfc_setup_driver_resource_phase1(phba); | |
9095 | if (error) { | |
9096 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
9097 | "1411 Failed to set up driver resource.\n"); |
9098 | goto out_unset_pci_mem_s4; | |
3772a991 JS |
9099 | } |
9100 | ||
da0436e9 JS |
9101 | /* Set up SLI-4 Specific device driver resources */ |
9102 | error = lpfc_sli4_driver_resource_setup(phba); | |
3772a991 JS |
9103 | if (error) { |
9104 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
9105 | "1412 Failed to set up driver resource.\n"); |
9106 | goto out_unset_pci_mem_s4; | |
3772a991 JS |
9107 | } |
9108 | ||
9109 | /* Initialize and populate the iocb list per host */ | |
2a9bf3d0 JS |
9110 | |
9111 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
9112 | "2821 initialize iocb list %d.\n", | |
9113 | phba->cfg_iocb_cnt*1024); | |
9114 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); | |
9115 | ||
3772a991 JS |
9116 | if (error) { |
9117 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
9118 | "1413 Failed to initialize iocb list.\n"); |
9119 | goto out_unset_driver_resource_s4; | |
3772a991 JS |
9120 | } |
9121 | ||
19ca7609 | 9122 | INIT_LIST_HEAD(&phba->active_rrq_list); |
7d791df7 | 9123 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
19ca7609 | 9124 | |
3772a991 JS |
9125 | /* Set up common device driver resources */ |
9126 | error = lpfc_setup_driver_resource_phase2(phba); | |
9127 | if (error) { | |
9128 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9129 | "1414 Failed to set up driver resource.\n"); |
3772a991 JS |
9130 | goto out_free_iocb_list; |
9131 | } | |
9132 | ||
079b5c91 JS |
9133 | /* Get the default values for Model Name and Description */ |
9134 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
9135 | ||
3772a991 JS |
9136 | /* Create SCSI host to the physical port */ |
9137 | error = lpfc_create_shost(phba); | |
9138 | if (error) { | |
9139 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9140 | "1415 Failed to create scsi host.\n"); |
3772a991 JS |
9141 | goto out_unset_driver_resource; |
9142 | } | |
9399627f | 9143 | |
5b75da2f | 9144 | /* Configure sysfs attributes */ |
3772a991 JS |
9145 | vport = phba->pport; |
9146 | error = lpfc_alloc_sysfs_attr(vport); | |
9147 | if (error) { | |
9399627f | 9148 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 9149 | "1416 Failed to allocate sysfs attr\n"); |
3772a991 | 9150 | goto out_destroy_shost; |
98c9ea5c | 9151 | } |
875fbdfe | 9152 | |
6669f9bb | 9153 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
3772a991 | 9154 | /* Now, trying to enable interrupt and bring up the device */ |
5b75da2f JS |
9155 | cfg_mode = phba->cfg_use_msi; |
9156 | while (true) { | |
3772a991 JS |
9157 | /* Put device to a known state before enabling interrupt */ |
9158 | lpfc_stop_port(phba); | |
5b75da2f | 9159 | /* Configure and enable interrupt */ |
da0436e9 | 9160 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
5b75da2f JS |
9161 | if (intr_mode == LPFC_INTR_ERROR) { |
9162 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9163 | "0426 Failed to enable interrupt.\n"); |
3772a991 | 9164 | error = -ENODEV; |
5b75da2f JS |
9165 | goto out_free_sysfs_attr; |
9166 | } | |
0558056c | 9167 | /* Default to single EQ for non-MSI-X */ |
def9c7a9 | 9168 | if (phba->intr_type != MSIX) |
0558056c JS |
9169 | adjusted_fcp_eq_count = 0; |
9170 | else if (phba->sli4_hba.msix_vec_nr < | |
9171 | phba->cfg_fcp_eq_count + 1) | |
9172 | adjusted_fcp_eq_count = phba->sli4_hba.msix_vec_nr - 1; | |
9173 | else | |
9174 | adjusted_fcp_eq_count = phba->cfg_fcp_eq_count; | |
0558056c | 9175 | phba->cfg_fcp_eq_count = adjusted_fcp_eq_count; |
da0436e9 JS |
9176 | /* Set up SLI-4 HBA */ |
9177 | if (lpfc_sli4_hba_setup(phba)) { | |
5b75da2f | 9178 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 9179 | "1421 Failed to set up hba\n"); |
5b75da2f | 9180 | error = -ENODEV; |
da0436e9 | 9181 | goto out_disable_intr; |
5b75da2f JS |
9182 | } |
9183 | ||
da0436e9 JS |
9184 | /* Send NOP mbx cmds for non-INTx mode active interrupt test */ |
9185 | if (intr_mode != 0) | |
9186 | mcnt = lpfc_sli4_send_nop_mbox_cmds(phba, | |
9187 | LPFC_ACT_INTR_CNT); | |
9188 | ||
9189 | /* Check active interrupts received only for MSI/MSI-X */ | |
3772a991 | 9190 | if (intr_mode == 0 || |
da0436e9 | 9191 | phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) { |
5b75da2f JS |
9192 | /* Log the current active interrupt mode */ |
9193 | phba->intr_mode = intr_mode; | |
9194 | lpfc_log_intr_mode(phba, intr_mode); | |
9195 | break; | |
5b75da2f | 9196 | } |
da0436e9 JS |
9197 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
9198 | "0451 Configure interrupt mode (%d) " | |
9199 | "failed active interrupt test.\n", | |
9200 | intr_mode); | |
2fcee4bf JS |
9201 | /* Unset the previous SLI-4 HBA setup. */ |
9202 | /* | |
9203 | * TODO: Is this operation compatible with IF TYPE 2 | |
9204 | * devices? All port state is deleted and cleared. | |
9205 | */ | |
da0436e9 JS |
9206 | lpfc_sli4_unset_hba(phba); |
9207 | /* Try next level of interrupt mode */ | |
9208 | cfg_mode = --intr_mode; | |
98c9ea5c | 9209 | } |
858c9f6c | 9210 | |
3772a991 JS |
9211 | /* Perform post initialization setup */ |
9212 | lpfc_post_init_setup(phba); | |
dea3101e | 9213 | |
026abb87 JS |
9214 | /* check for firmware upgrade or downgrade (if_type 2 only) */ |
9215 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
9216 | LPFC_SLI_INTF_IF_TYPE_2) { | |
9217 | snprintf(file_name, 16, "%s.grp", phba->ModelName); | |
9218 | error = request_firmware(&fw, file_name, &phba->pcidev->dev); | |
9219 | if (!error) { | |
9220 | lpfc_write_firmware(phba, fw); | |
9221 | release_firmware(fw); | |
9222 | } | |
52d52440 JS |
9223 | } |
9224 | ||
1c6834a7 JS |
9225 | /* Check if there are static vports to be created. */ |
9226 | lpfc_create_static_vport(phba); | |
dea3101e | 9227 | return 0; |
9228 | ||
da0436e9 JS |
9229 | out_disable_intr: |
9230 | lpfc_sli4_disable_intr(phba); | |
5b75da2f JS |
9231 | out_free_sysfs_attr: |
9232 | lpfc_free_sysfs_attr(vport); | |
3772a991 JS |
9233 | out_destroy_shost: |
9234 | lpfc_destroy_shost(phba); | |
9235 | out_unset_driver_resource: | |
9236 | lpfc_unset_driver_resource_phase2(phba); | |
9237 | out_free_iocb_list: | |
9238 | lpfc_free_iocb_list(phba); | |
da0436e9 JS |
9239 | out_unset_driver_resource_s4: |
9240 | lpfc_sli4_driver_resource_unset(phba); | |
9241 | out_unset_pci_mem_s4: | |
9242 | lpfc_sli4_pci_mem_unset(phba); | |
3772a991 JS |
9243 | out_disable_pci_dev: |
9244 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
9245 | if (shost) |
9246 | scsi_host_put(shost); | |
2e0fef85 | 9247 | out_free_phba: |
3772a991 | 9248 | lpfc_hba_free(phba); |
dea3101e | 9249 | return error; |
9250 | } | |
9251 | ||
e59058c4 | 9252 | /** |
da0436e9 | 9253 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
e59058c4 JS |
9254 | * @pdev: pointer to PCI device |
9255 | * | |
da0436e9 JS |
9256 | * This routine is called from the kernel's PCI subsystem to device with |
9257 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 JS |
9258 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
9259 | * device to be removed from the PCI subsystem properly. | |
e59058c4 | 9260 | **/ |
dea3101e | 9261 | static void __devexit |
da0436e9 | 9262 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
dea3101e | 9263 | { |
da0436e9 | 9264 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2e0fef85 | 9265 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
eada272d | 9266 | struct lpfc_vport **vports; |
da0436e9 | 9267 | struct lpfc_hba *phba = vport->phba; |
eada272d | 9268 | int i; |
8a4df120 | 9269 | |
da0436e9 | 9270 | /* Mark the device unloading flag */ |
549e55cd | 9271 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 9272 | vport->load_flag |= FC_UNLOADING; |
549e55cd | 9273 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 9274 | |
da0436e9 | 9275 | /* Free the HBA sysfs attributes */ |
858c9f6c JS |
9276 | lpfc_free_sysfs_attr(vport); |
9277 | ||
eada272d JS |
9278 | /* Release all the vports against this physical port */ |
9279 | vports = lpfc_create_vport_work_array(phba); | |
9280 | if (vports != NULL) | |
3772a991 | 9281 | for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) |
eada272d JS |
9282 | fc_vport_terminate(vports[i]->fc_vport); |
9283 | lpfc_destroy_vport_work_array(phba, vports); | |
9284 | ||
9285 | /* Remove FC host and then SCSI host with the physical port */ | |
858c9f6c JS |
9286 | fc_remove_host(shost); |
9287 | scsi_remove_host(shost); | |
da0436e9 JS |
9288 | |
9289 | /* Perform cleanup on the physical port */ | |
87af33fe JS |
9290 | lpfc_cleanup(vport); |
9291 | ||
2e0fef85 | 9292 | /* |
da0436e9 | 9293 | * Bring down the SLI Layer. This step disables all interrupts, |
2e0fef85 | 9294 | * clears the rings, discards all mailbox commands, and resets |
da0436e9 | 9295 | * the HBA FCoE function. |
2e0fef85 | 9296 | */ |
da0436e9 JS |
9297 | lpfc_debugfs_terminate(vport); |
9298 | lpfc_sli4_hba_unset(phba); | |
a257bf90 | 9299 | |
858c9f6c JS |
9300 | spin_lock_irq(&phba->hbalock); |
9301 | list_del_init(&vport->listentry); | |
9302 | spin_unlock_irq(&phba->hbalock); | |
9303 | ||
3677a3a7 | 9304 | /* Perform scsi free before driver resource_unset since scsi |
da0436e9 | 9305 | * buffers are released to their corresponding pools here. |
2e0fef85 JS |
9306 | */ |
9307 | lpfc_scsi_free(phba); | |
da0436e9 | 9308 | lpfc_sli4_driver_resource_unset(phba); |
ed957684 | 9309 | |
da0436e9 JS |
9310 | /* Unmap adapter Control and Doorbell registers */ |
9311 | lpfc_sli4_pci_mem_unset(phba); | |
2e0fef85 | 9312 | |
da0436e9 JS |
9313 | /* Release PCI resources and disable device's PCI function */ |
9314 | scsi_host_put(shost); | |
9315 | lpfc_disable_pci_dev(phba); | |
2e0fef85 | 9316 | |
da0436e9 | 9317 | /* Finally, free the driver's device data structure */ |
3772a991 | 9318 | lpfc_hba_free(phba); |
2e0fef85 | 9319 | |
da0436e9 | 9320 | return; |
dea3101e | 9321 | } |
9322 | ||
3a55b532 | 9323 | /** |
da0436e9 | 9324 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
3a55b532 JS |
9325 | * @pdev: pointer to PCI device |
9326 | * @msg: power management message | |
9327 | * | |
da0436e9 JS |
9328 | * This routine is called from the kernel's PCI subsystem to support system |
9329 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes | |
9330 | * this method, it quiesces the device by stopping the driver's worker | |
9331 | * thread for the device, turning off device's interrupt and DMA, and bring | |
9332 | * the device offline. Note that as the driver implements the minimum PM | |
9333 | * requirements to a power-aware driver's PM support for suspend/resume -- all | |
9334 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() | |
9335 | * method call will be treated as SUSPEND and the driver will fully | |
9336 | * reinitialize its device during resume() method call, the driver will set | |
9337 | * device to PCI_D3hot state in PCI config space instead of setting it | |
3772a991 | 9338 | * according to the @msg provided by the PM. |
3a55b532 JS |
9339 | * |
9340 | * Return code | |
3772a991 JS |
9341 | * 0 - driver suspended the device |
9342 | * Error otherwise | |
3a55b532 JS |
9343 | **/ |
9344 | static int | |
da0436e9 | 9345 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
3a55b532 JS |
9346 | { |
9347 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9348 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9349 | ||
9350 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
75baf696 | 9351 | "2843 PCI device Power Management suspend.\n"); |
3a55b532 JS |
9352 | |
9353 | /* Bring down the device */ | |
9354 | lpfc_offline_prep(phba); | |
9355 | lpfc_offline(phba); | |
9356 | kthread_stop(phba->worker_thread); | |
9357 | ||
9358 | /* Disable interrupt from device */ | |
da0436e9 | 9359 | lpfc_sli4_disable_intr(phba); |
5350d872 | 9360 | lpfc_sli4_queue_destroy(phba); |
3a55b532 JS |
9361 | |
9362 | /* Save device state to PCI config space */ | |
9363 | pci_save_state(pdev); | |
9364 | pci_set_power_state(pdev, PCI_D3hot); | |
9365 | ||
9366 | return 0; | |
9367 | } | |
9368 | ||
9369 | /** | |
da0436e9 | 9370 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
3a55b532 JS |
9371 | * @pdev: pointer to PCI device |
9372 | * | |
da0436e9 JS |
9373 | * This routine is called from the kernel's PCI subsystem to support system |
9374 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes | |
9375 | * this method, it restores the device's PCI config space state and fully | |
9376 | * reinitializes the device and brings it online. Note that as the driver | |
9377 | * implements the minimum PM requirements to a power-aware driver's PM for | |
9378 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
9379 | * to the suspend() method call will be treated as SUSPEND and the driver | |
9380 | * will fully reinitialize its device during resume() method call, the device | |
9381 | * will be set to PCI_D0 directly in PCI config space before restoring the | |
9382 | * state. | |
3a55b532 JS |
9383 | * |
9384 | * Return code | |
3772a991 JS |
9385 | * 0 - driver suspended the device |
9386 | * Error otherwise | |
3a55b532 JS |
9387 | **/ |
9388 | static int | |
da0436e9 | 9389 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
3a55b532 JS |
9390 | { |
9391 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9392 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
5b75da2f | 9393 | uint32_t intr_mode; |
3a55b532 JS |
9394 | int error; |
9395 | ||
9396 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
da0436e9 | 9397 | "0292 PCI device Power Management resume.\n"); |
3a55b532 JS |
9398 | |
9399 | /* Restore device state from PCI config space */ | |
9400 | pci_set_power_state(pdev, PCI_D0); | |
9401 | pci_restore_state(pdev); | |
1dfb5a47 JS |
9402 | |
9403 | /* | |
9404 | * As the new kernel behavior of pci_restore_state() API call clears | |
9405 | * device saved_state flag, need to save the restored state again. | |
9406 | */ | |
9407 | pci_save_state(pdev); | |
9408 | ||
3a55b532 JS |
9409 | if (pdev->is_busmaster) |
9410 | pci_set_master(pdev); | |
9411 | ||
da0436e9 | 9412 | /* Startup the kernel thread for this host adapter. */ |
3a55b532 JS |
9413 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
9414 | "lpfc_worker_%d", phba->brd_no); | |
9415 | if (IS_ERR(phba->worker_thread)) { | |
9416 | error = PTR_ERR(phba->worker_thread); | |
9417 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9418 | "0293 PM resume failed to start worker " |
3a55b532 JS |
9419 | "thread: error=x%x.\n", error); |
9420 | return error; | |
9421 | } | |
9422 | ||
5b75da2f | 9423 | /* Configure and enable interrupt */ |
da0436e9 | 9424 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
5b75da2f | 9425 | if (intr_mode == LPFC_INTR_ERROR) { |
3a55b532 | 9426 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 9427 | "0294 PM resume Failed to enable interrupt\n"); |
5b75da2f JS |
9428 | return -EIO; |
9429 | } else | |
9430 | phba->intr_mode = intr_mode; | |
3a55b532 JS |
9431 | |
9432 | /* Restart HBA and bring it online */ | |
9433 | lpfc_sli_brdrestart(phba); | |
9434 | lpfc_online(phba); | |
9435 | ||
5b75da2f JS |
9436 | /* Log the current active interrupt mode */ |
9437 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
9438 | ||
3a55b532 JS |
9439 | return 0; |
9440 | } | |
9441 | ||
75baf696 JS |
9442 | /** |
9443 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover | |
9444 | * @phba: pointer to lpfc hba data structure. | |
9445 | * | |
9446 | * This routine is called to prepare the SLI4 device for PCI slot recover. It | |
9447 | * aborts all the outstanding SCSI I/Os to the pci device. | |
9448 | **/ | |
9449 | static void | |
9450 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) | |
9451 | { | |
9452 | struct lpfc_sli *psli = &phba->sli; | |
9453 | struct lpfc_sli_ring *pring; | |
9454 | ||
9455 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9456 | "2828 PCI channel I/O abort preparing for recovery\n"); | |
9457 | /* | |
9458 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
9459 | * and let the SCSI mid-layer to retry them to recover. | |
9460 | */ | |
9461 | pring = &psli->ring[psli->fcp_ring]; | |
9462 | lpfc_sli_abort_iocb_ring(phba, pring); | |
9463 | } | |
9464 | ||
9465 | /** | |
9466 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset | |
9467 | * @phba: pointer to lpfc hba data structure. | |
9468 | * | |
9469 | * This routine is called to prepare the SLI4 device for PCI slot reset. It | |
9470 | * disables the device interrupt and pci device, and aborts the internal FCP | |
9471 | * pending I/Os. | |
9472 | **/ | |
9473 | static void | |
9474 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) | |
9475 | { | |
9476 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9477 | "2826 PCI channel disable preparing for reset\n"); | |
9478 | ||
9479 | /* Block any management I/Os to the device */ | |
9480 | lpfc_block_mgmt_io(phba); | |
9481 | ||
9482 | /* Block all SCSI devices' I/Os on the host */ | |
9483 | lpfc_scsi_dev_block(phba); | |
9484 | ||
9485 | /* stop all timers */ | |
9486 | lpfc_stop_hba_timers(phba); | |
9487 | ||
9488 | /* Disable interrupt and pci device */ | |
9489 | lpfc_sli4_disable_intr(phba); | |
5350d872 | 9490 | lpfc_sli4_queue_destroy(phba); |
75baf696 JS |
9491 | pci_disable_device(phba->pcidev); |
9492 | ||
9493 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ | |
9494 | lpfc_sli_flush_fcp_rings(phba); | |
9495 | } | |
9496 | ||
9497 | /** | |
9498 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable | |
9499 | * @phba: pointer to lpfc hba data structure. | |
9500 | * | |
9501 | * This routine is called to prepare the SLI4 device for PCI slot permanently | |
9502 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
9503 | * pending I/Os. | |
9504 | **/ | |
9505 | static void | |
9506 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) | |
9507 | { | |
9508 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9509 | "2827 PCI channel permanent disable for failure\n"); | |
9510 | ||
9511 | /* Block all SCSI devices' I/Os on the host */ | |
9512 | lpfc_scsi_dev_block(phba); | |
9513 | ||
9514 | /* stop all timers */ | |
9515 | lpfc_stop_hba_timers(phba); | |
9516 | ||
9517 | /* Clean up all driver's outstanding SCSI I/Os */ | |
9518 | lpfc_sli_flush_fcp_rings(phba); | |
9519 | } | |
9520 | ||
8d63f375 | 9521 | /** |
da0436e9 | 9522 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
e59058c4 JS |
9523 | * @pdev: pointer to PCI device. |
9524 | * @state: the current PCI connection state. | |
8d63f375 | 9525 | * |
da0436e9 JS |
9526 | * This routine is called from the PCI subsystem for error handling to device |
9527 | * with SLI-4 interface spec. This function is called by the PCI subsystem | |
9528 | * after a PCI bus error affecting this device has been detected. When this | |
9529 | * function is invoked, it will need to stop all the I/Os and interrupt(s) | |
9530 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET | |
9531 | * for the PCI subsystem to perform proper recovery as desired. | |
e59058c4 JS |
9532 | * |
9533 | * Return codes | |
3772a991 JS |
9534 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
9535 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
e59058c4 | 9536 | **/ |
3772a991 | 9537 | static pci_ers_result_t |
da0436e9 | 9538 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
8d63f375 | 9539 | { |
75baf696 JS |
9540 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
9541 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9542 | ||
9543 | switch (state) { | |
9544 | case pci_channel_io_normal: | |
9545 | /* Non-fatal error, prepare for recovery */ | |
9546 | lpfc_sli4_prep_dev_for_recover(phba); | |
9547 | return PCI_ERS_RESULT_CAN_RECOVER; | |
9548 | case pci_channel_io_frozen: | |
9549 | /* Fatal error, prepare for slot reset */ | |
9550 | lpfc_sli4_prep_dev_for_reset(phba); | |
9551 | return PCI_ERS_RESULT_NEED_RESET; | |
9552 | case pci_channel_io_perm_failure: | |
9553 | /* Permanent failure, prepare for device down */ | |
9554 | lpfc_sli4_prep_dev_for_perm_failure(phba); | |
9555 | return PCI_ERS_RESULT_DISCONNECT; | |
9556 | default: | |
9557 | /* Unknown state, prepare and request slot reset */ | |
9558 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9559 | "2825 Unknown PCI error state: x%x\n", state); | |
9560 | lpfc_sli4_prep_dev_for_reset(phba); | |
9561 | return PCI_ERS_RESULT_NEED_RESET; | |
9562 | } | |
8d63f375 LV |
9563 | } |
9564 | ||
9565 | /** | |
da0436e9 | 9566 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
e59058c4 JS |
9567 | * @pdev: pointer to PCI device. |
9568 | * | |
da0436e9 JS |
9569 | * This routine is called from the PCI subsystem for error handling to device |
9570 | * with SLI-4 interface spec. It is called after PCI bus has been reset to | |
9571 | * restart the PCI card from scratch, as if from a cold-boot. During the | |
9572 | * PCI subsystem error recovery, after the driver returns | |
3772a991 | 9573 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
da0436e9 JS |
9574 | * recovery and then call this routine before calling the .resume method to |
9575 | * recover the device. This function will initialize the HBA device, enable | |
9576 | * the interrupt, but it will just put the HBA to offline state without | |
9577 | * passing any I/O traffic. | |
8d63f375 | 9578 | * |
e59058c4 | 9579 | * Return codes |
3772a991 JS |
9580 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
9581 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8d63f375 | 9582 | */ |
3772a991 | 9583 | static pci_ers_result_t |
da0436e9 | 9584 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
8d63f375 | 9585 | { |
75baf696 JS |
9586 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
9587 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9588 | struct lpfc_sli *psli = &phba->sli; | |
9589 | uint32_t intr_mode; | |
9590 | ||
9591 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
9592 | if (pci_enable_device_mem(pdev)) { | |
9593 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
9594 | "PCI device after reset.\n"); | |
9595 | return PCI_ERS_RESULT_DISCONNECT; | |
9596 | } | |
9597 | ||
9598 | pci_restore_state(pdev); | |
0a96e975 JS |
9599 | |
9600 | /* | |
9601 | * As the new kernel behavior of pci_restore_state() API call clears | |
9602 | * device saved_state flag, need to save the restored state again. | |
9603 | */ | |
9604 | pci_save_state(pdev); | |
9605 | ||
75baf696 JS |
9606 | if (pdev->is_busmaster) |
9607 | pci_set_master(pdev); | |
9608 | ||
9609 | spin_lock_irq(&phba->hbalock); | |
9610 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
9611 | spin_unlock_irq(&phba->hbalock); | |
9612 | ||
9613 | /* Configure and enable interrupt */ | |
9614 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); | |
9615 | if (intr_mode == LPFC_INTR_ERROR) { | |
9616 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9617 | "2824 Cannot re-enable interrupt after " | |
9618 | "slot reset.\n"); | |
9619 | return PCI_ERS_RESULT_DISCONNECT; | |
9620 | } else | |
9621 | phba->intr_mode = intr_mode; | |
9622 | ||
9623 | /* Log the current active interrupt mode */ | |
9624 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
9625 | ||
8d63f375 LV |
9626 | return PCI_ERS_RESULT_RECOVERED; |
9627 | } | |
9628 | ||
9629 | /** | |
da0436e9 | 9630 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
e59058c4 | 9631 | * @pdev: pointer to PCI device |
8d63f375 | 9632 | * |
3772a991 | 9633 | * This routine is called from the PCI subsystem for error handling to device |
da0436e9 | 9634 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
3772a991 JS |
9635 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
9636 | * error recovery. After this call, traffic can start to flow from this device | |
9637 | * again. | |
da0436e9 | 9638 | **/ |
3772a991 | 9639 | static void |
da0436e9 | 9640 | lpfc_io_resume_s4(struct pci_dev *pdev) |
8d63f375 | 9641 | { |
75baf696 JS |
9642 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
9643 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9644 | ||
9645 | /* | |
9646 | * In case of slot reset, as function reset is performed through | |
9647 | * mailbox command which needs DMA to be enabled, this operation | |
9648 | * has to be moved to the io resume phase. Taking device offline | |
9649 | * will perform the necessary cleanup. | |
9650 | */ | |
9651 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { | |
9652 | /* Perform device reset */ | |
9653 | lpfc_offline_prep(phba); | |
9654 | lpfc_offline(phba); | |
9655 | lpfc_sli_brdrestart(phba); | |
9656 | /* Bring the device back online */ | |
9657 | lpfc_online(phba); | |
9658 | } | |
9659 | ||
9660 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
9661 | if (phba->hba_flag & HBA_AER_ENABLED) | |
9662 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
8d63f375 LV |
9663 | } |
9664 | ||
3772a991 JS |
9665 | /** |
9666 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem | |
9667 | * @pdev: pointer to PCI device | |
9668 | * @pid: pointer to PCI device identifier | |
9669 | * | |
9670 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
9671 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks | |
9672 | * at PCI device-specific information of the device and driver to see if the | |
9673 | * driver state that it can support this kind of device. If the match is | |
9674 | * successful, the driver core invokes this routine. This routine dispatches | |
9675 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will | |
9676 | * do all the initialization that it needs to do to handle the HBA device | |
9677 | * properly. | |
9678 | * | |
9679 | * Return code | |
9680 | * 0 - driver can claim the device | |
9681 | * negative value - driver can not claim the device | |
9682 | **/ | |
9683 | static int __devinit | |
9684 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | |
9685 | { | |
9686 | int rc; | |
8fa38513 | 9687 | struct lpfc_sli_intf intf; |
3772a991 | 9688 | |
28baac74 | 9689 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
3772a991 JS |
9690 | return -ENODEV; |
9691 | ||
8fa38513 | 9692 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
28baac74 | 9693 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
da0436e9 | 9694 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
8fa38513 | 9695 | else |
3772a991 | 9696 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
8fa38513 | 9697 | |
3772a991 JS |
9698 | return rc; |
9699 | } | |
9700 | ||
9701 | /** | |
9702 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem | |
9703 | * @pdev: pointer to PCI device | |
9704 | * | |
9705 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
9706 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. | |
9707 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device | |
9708 | * remove routine, which will perform all the necessary cleanup for the | |
9709 | * device to be removed from the PCI subsystem properly. | |
9710 | **/ | |
9711 | static void __devexit | |
9712 | lpfc_pci_remove_one(struct pci_dev *pdev) | |
9713 | { | |
9714 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9715 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9716 | ||
9717 | switch (phba->pci_dev_grp) { | |
9718 | case LPFC_PCI_DEV_LP: | |
9719 | lpfc_pci_remove_one_s3(pdev); | |
9720 | break; | |
da0436e9 JS |
9721 | case LPFC_PCI_DEV_OC: |
9722 | lpfc_pci_remove_one_s4(pdev); | |
9723 | break; | |
3772a991 JS |
9724 | default: |
9725 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9726 | "1424 Invalid PCI device group: 0x%x\n", | |
9727 | phba->pci_dev_grp); | |
9728 | break; | |
9729 | } | |
9730 | return; | |
9731 | } | |
9732 | ||
9733 | /** | |
9734 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management | |
9735 | * @pdev: pointer to PCI device | |
9736 | * @msg: power management message | |
9737 | * | |
9738 | * This routine is to be registered to the kernel's PCI subsystem to support | |
9739 | * system Power Management (PM). When PM invokes this method, it dispatches | |
9740 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will | |
9741 | * suspend the device. | |
9742 | * | |
9743 | * Return code | |
9744 | * 0 - driver suspended the device | |
9745 | * Error otherwise | |
9746 | **/ | |
9747 | static int | |
9748 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | |
9749 | { | |
9750 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9751 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9752 | int rc = -ENODEV; | |
9753 | ||
9754 | switch (phba->pci_dev_grp) { | |
9755 | case LPFC_PCI_DEV_LP: | |
9756 | rc = lpfc_pci_suspend_one_s3(pdev, msg); | |
9757 | break; | |
da0436e9 JS |
9758 | case LPFC_PCI_DEV_OC: |
9759 | rc = lpfc_pci_suspend_one_s4(pdev, msg); | |
9760 | break; | |
3772a991 JS |
9761 | default: |
9762 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9763 | "1425 Invalid PCI device group: 0x%x\n", | |
9764 | phba->pci_dev_grp); | |
9765 | break; | |
9766 | } | |
9767 | return rc; | |
9768 | } | |
9769 | ||
9770 | /** | |
9771 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management | |
9772 | * @pdev: pointer to PCI device | |
9773 | * | |
9774 | * This routine is to be registered to the kernel's PCI subsystem to support | |
9775 | * system Power Management (PM). When PM invokes this method, it dispatches | |
9776 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will | |
9777 | * resume the device. | |
9778 | * | |
9779 | * Return code | |
9780 | * 0 - driver suspended the device | |
9781 | * Error otherwise | |
9782 | **/ | |
9783 | static int | |
9784 | lpfc_pci_resume_one(struct pci_dev *pdev) | |
9785 | { | |
9786 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9787 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9788 | int rc = -ENODEV; | |
9789 | ||
9790 | switch (phba->pci_dev_grp) { | |
9791 | case LPFC_PCI_DEV_LP: | |
9792 | rc = lpfc_pci_resume_one_s3(pdev); | |
9793 | break; | |
da0436e9 JS |
9794 | case LPFC_PCI_DEV_OC: |
9795 | rc = lpfc_pci_resume_one_s4(pdev); | |
9796 | break; | |
3772a991 JS |
9797 | default: |
9798 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9799 | "1426 Invalid PCI device group: 0x%x\n", | |
9800 | phba->pci_dev_grp); | |
9801 | break; | |
9802 | } | |
9803 | return rc; | |
9804 | } | |
9805 | ||
9806 | /** | |
9807 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error | |
9808 | * @pdev: pointer to PCI device. | |
9809 | * @state: the current PCI connection state. | |
9810 | * | |
9811 | * This routine is registered to the PCI subsystem for error handling. This | |
9812 | * function is called by the PCI subsystem after a PCI bus error affecting | |
9813 | * this device has been detected. When this routine is invoked, it dispatches | |
9814 | * the action to the proper SLI-3 or SLI-4 device error detected handling | |
9815 | * routine, which will perform the proper error detected operation. | |
9816 | * | |
9817 | * Return codes | |
9818 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery | |
9819 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
9820 | **/ | |
9821 | static pci_ers_result_t | |
9822 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | |
9823 | { | |
9824 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9825 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9826 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
9827 | ||
9828 | switch (phba->pci_dev_grp) { | |
9829 | case LPFC_PCI_DEV_LP: | |
9830 | rc = lpfc_io_error_detected_s3(pdev, state); | |
9831 | break; | |
da0436e9 JS |
9832 | case LPFC_PCI_DEV_OC: |
9833 | rc = lpfc_io_error_detected_s4(pdev, state); | |
9834 | break; | |
3772a991 JS |
9835 | default: |
9836 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9837 | "1427 Invalid PCI device group: 0x%x\n", | |
9838 | phba->pci_dev_grp); | |
9839 | break; | |
9840 | } | |
9841 | return rc; | |
9842 | } | |
9843 | ||
9844 | /** | |
9845 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch | |
9846 | * @pdev: pointer to PCI device. | |
9847 | * | |
9848 | * This routine is registered to the PCI subsystem for error handling. This | |
9849 | * function is called after PCI bus has been reset to restart the PCI card | |
9850 | * from scratch, as if from a cold-boot. When this routine is invoked, it | |
9851 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling | |
9852 | * routine, which will perform the proper device reset. | |
9853 | * | |
9854 | * Return codes | |
9855 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
9856 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
9857 | **/ | |
9858 | static pci_ers_result_t | |
9859 | lpfc_io_slot_reset(struct pci_dev *pdev) | |
9860 | { | |
9861 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9862 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9863 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
9864 | ||
9865 | switch (phba->pci_dev_grp) { | |
9866 | case LPFC_PCI_DEV_LP: | |
9867 | rc = lpfc_io_slot_reset_s3(pdev); | |
9868 | break; | |
da0436e9 JS |
9869 | case LPFC_PCI_DEV_OC: |
9870 | rc = lpfc_io_slot_reset_s4(pdev); | |
9871 | break; | |
3772a991 JS |
9872 | default: |
9873 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9874 | "1428 Invalid PCI device group: 0x%x\n", | |
9875 | phba->pci_dev_grp); | |
9876 | break; | |
9877 | } | |
9878 | return rc; | |
9879 | } | |
9880 | ||
9881 | /** | |
9882 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation | |
9883 | * @pdev: pointer to PCI device | |
9884 | * | |
9885 | * This routine is registered to the PCI subsystem for error handling. It | |
9886 | * is called when kernel error recovery tells the lpfc driver that it is | |
9887 | * OK to resume normal PCI operation after PCI bus error recovery. When | |
9888 | * this routine is invoked, it dispatches the action to the proper SLI-3 | |
9889 | * or SLI-4 device io_resume routine, which will resume the device operation. | |
9890 | **/ | |
9891 | static void | |
9892 | lpfc_io_resume(struct pci_dev *pdev) | |
9893 | { | |
9894 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9895 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9896 | ||
9897 | switch (phba->pci_dev_grp) { | |
9898 | case LPFC_PCI_DEV_LP: | |
9899 | lpfc_io_resume_s3(pdev); | |
9900 | break; | |
da0436e9 JS |
9901 | case LPFC_PCI_DEV_OC: |
9902 | lpfc_io_resume_s4(pdev); | |
9903 | break; | |
3772a991 JS |
9904 | default: |
9905 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9906 | "1429 Invalid PCI device group: 0x%x\n", | |
9907 | phba->pci_dev_grp); | |
9908 | break; | |
9909 | } | |
9910 | return; | |
9911 | } | |
9912 | ||
dea3101e | 9913 | static struct pci_device_id lpfc_id_table[] = { |
9914 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, | |
9915 | PCI_ANY_ID, PCI_ANY_ID, }, | |
06325e74 JSEC |
9916 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
9917 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e | 9918 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
9919 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9920 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, | |
9921 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9922 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, | |
9923 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9924 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, | |
9925 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9926 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, | |
9927 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9928 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, | |
9929 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9930 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, | |
9931 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
9932 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
9933 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9934 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, | |
9935 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9936 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, | |
9937 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e | 9938 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
9939 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
9940 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
9941 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9942 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, | |
9943 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e | 9944 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
9945 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9946 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, | |
9947 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9948 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, | |
9949 | PCI_ANY_ID, PCI_ANY_ID, }, | |
84774a4d JS |
9950 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
9951 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
9952 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
9953 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9954 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, | |
9955 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e | 9956 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
9957 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9958 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, | |
9959 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9960 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, | |
9961 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9962 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, | |
9963 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9964 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, | |
9965 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
9966 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
9967 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9968 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, | |
9969 | PCI_ANY_ID, PCI_ANY_ID, }, | |
b87eab38 JS |
9970 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
9971 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9972 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, | |
9973 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9974 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, | |
9975 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9976 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, | |
9977 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9978 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, | |
9979 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9980 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, | |
9981 | PCI_ANY_ID, PCI_ANY_ID, }, | |
84774a4d JS |
9982 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
9983 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9984 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, | |
9985 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9986 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, | |
9987 | PCI_ANY_ID, PCI_ANY_ID, }, | |
3772a991 JS |
9988 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, |
9989 | PCI_ANY_ID, PCI_ANY_ID, }, | |
a747c9ce JS |
9990 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT, |
9991 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9992 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON, | |
6669f9bb | 9993 | PCI_ANY_ID, PCI_ANY_ID, }, |
98fc5dd9 JS |
9994 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS, |
9995 | PCI_ANY_ID, PCI_ANY_ID, }, | |
085c647c JS |
9996 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC, |
9997 | PCI_ANY_ID, PCI_ANY_ID, }, | |
9998 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE, | |
9999 | PCI_ANY_ID, PCI_ANY_ID, }, | |
c0c11512 JS |
10000 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF, |
10001 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10002 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF, | |
10003 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e | 10004 | { 0 } |
10005 | }; | |
10006 | ||
10007 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); | |
10008 | ||
8d63f375 LV |
10009 | static struct pci_error_handlers lpfc_err_handler = { |
10010 | .error_detected = lpfc_io_error_detected, | |
10011 | .slot_reset = lpfc_io_slot_reset, | |
10012 | .resume = lpfc_io_resume, | |
10013 | }; | |
10014 | ||
dea3101e | 10015 | static struct pci_driver lpfc_driver = { |
10016 | .name = LPFC_DRIVER_NAME, | |
10017 | .id_table = lpfc_id_table, | |
10018 | .probe = lpfc_pci_probe_one, | |
10019 | .remove = __devexit_p(lpfc_pci_remove_one), | |
3a55b532 | 10020 | .suspend = lpfc_pci_suspend_one, |
3772a991 | 10021 | .resume = lpfc_pci_resume_one, |
2e0fef85 | 10022 | .err_handler = &lpfc_err_handler, |
dea3101e | 10023 | }; |
10024 | ||
e59058c4 | 10025 | /** |
3621a710 | 10026 | * lpfc_init - lpfc module initialization routine |
e59058c4 JS |
10027 | * |
10028 | * This routine is to be invoked when the lpfc module is loaded into the | |
10029 | * kernel. The special kernel macro module_init() is used to indicate the | |
10030 | * role of this routine to the kernel as lpfc module entry point. | |
10031 | * | |
10032 | * Return codes | |
10033 | * 0 - successful | |
10034 | * -ENOMEM - FC attach transport failed | |
10035 | * all others - failed | |
10036 | */ | |
dea3101e | 10037 | static int __init |
10038 | lpfc_init(void) | |
10039 | { | |
10040 | int error = 0; | |
10041 | ||
10042 | printk(LPFC_MODULE_DESC "\n"); | |
c44ce173 | 10043 | printk(LPFC_COPYRIGHT "\n"); |
dea3101e | 10044 | |
7ee5d43e JS |
10045 | if (lpfc_enable_npiv) { |
10046 | lpfc_transport_functions.vport_create = lpfc_vport_create; | |
10047 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; | |
10048 | } | |
dea3101e | 10049 | lpfc_transport_template = |
10050 | fc_attach_transport(&lpfc_transport_functions); | |
7ee5d43e | 10051 | if (lpfc_transport_template == NULL) |
dea3101e | 10052 | return -ENOMEM; |
7ee5d43e | 10053 | if (lpfc_enable_npiv) { |
7ee5d43e | 10054 | lpfc_vport_transport_template = |
98c9ea5c JS |
10055 | fc_attach_transport(&lpfc_vport_transport_functions); |
10056 | if (lpfc_vport_transport_template == NULL) { | |
10057 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e | 10058 | return -ENOMEM; |
98c9ea5c | 10059 | } |
7ee5d43e | 10060 | } |
dea3101e | 10061 | error = pci_register_driver(&lpfc_driver); |
92d7f7b0 | 10062 | if (error) { |
dea3101e | 10063 | fc_release_transport(lpfc_transport_template); |
d7c255b2 JS |
10064 | if (lpfc_enable_npiv) |
10065 | fc_release_transport(lpfc_vport_transport_template); | |
92d7f7b0 | 10066 | } |
dea3101e | 10067 | |
10068 | return error; | |
10069 | } | |
10070 | ||
e59058c4 | 10071 | /** |
3621a710 | 10072 | * lpfc_exit - lpfc module removal routine |
e59058c4 JS |
10073 | * |
10074 | * This routine is invoked when the lpfc module is removed from the kernel. | |
10075 | * The special kernel macro module_exit() is used to indicate the role of | |
10076 | * this routine to the kernel as lpfc module exit point. | |
10077 | */ | |
dea3101e | 10078 | static void __exit |
10079 | lpfc_exit(void) | |
10080 | { | |
10081 | pci_unregister_driver(&lpfc_driver); | |
10082 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e JS |
10083 | if (lpfc_enable_npiv) |
10084 | fc_release_transport(lpfc_vport_transport_template); | |
81301a9b | 10085 | if (_dump_buf_data) { |
6a9c52cf JS |
10086 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
10087 | "_dump_buf_data at 0x%p\n", | |
81301a9b JS |
10088 | (1L << _dump_buf_data_order), _dump_buf_data); |
10089 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); | |
10090 | } | |
10091 | ||
10092 | if (_dump_buf_dif) { | |
6a9c52cf JS |
10093 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
10094 | "_dump_buf_dif at 0x%p\n", | |
81301a9b JS |
10095 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
10096 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); | |
10097 | } | |
dea3101e | 10098 | } |
10099 | ||
10100 | module_init(lpfc_init); | |
10101 | module_exit(lpfc_exit); | |
10102 | MODULE_LICENSE("GPL"); | |
10103 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); | |
10104 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); | |
10105 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |