]>
Commit | Line | Data |
---|---|---|
dea3101e JB |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
792581de | 4 | * Copyright (C) 2004-2011 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e JB |
8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
10 | * modify it under the terms of version 2 of the GNU General * |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
dea3101e JB |
20 | *******************************************************************/ |
21 | ||
dea3101e JB |
22 | #include <linux/blkdev.h> |
23 | #include <linux/delay.h> | |
24 | #include <linux/dma-mapping.h> | |
25 | #include <linux/idr.h> | |
26 | #include <linux/interrupt.h> | |
acf3368f | 27 | #include <linux/module.h> |
dea3101e JB |
28 | #include <linux/kthread.h> |
29 | #include <linux/pci.h> | |
30 | #include <linux/spinlock.h> | |
92d7f7b0 | 31 | #include <linux/ctype.h> |
0d878419 | 32 | #include <linux/aer.h> |
5a0e3ad6 | 33 | #include <linux/slab.h> |
52d52440 | 34 | #include <linux/firmware.h> |
3ef6d24c | 35 | #include <linux/miscdevice.h> |
dea3101e | 36 | |
91886523 | 37 | #include <scsi/scsi.h> |
dea3101e JB |
38 | #include <scsi/scsi_device.h> |
39 | #include <scsi/scsi_host.h> | |
40 | #include <scsi/scsi_transport_fc.h> | |
41 | ||
da0436e9 | 42 | #include "lpfc_hw4.h" |
dea3101e JB |
43 | #include "lpfc_hw.h" |
44 | #include "lpfc_sli.h" | |
da0436e9 | 45 | #include "lpfc_sli4.h" |
ea2151b4 | 46 | #include "lpfc_nl.h" |
dea3101e JB |
47 | #include "lpfc_disc.h" |
48 | #include "lpfc_scsi.h" | |
49 | #include "lpfc.h" | |
50 | #include "lpfc_logmsg.h" | |
51 | #include "lpfc_crtn.h" | |
92d7f7b0 | 52 | #include "lpfc_vport.h" |
dea3101e JB |
53 | #include "lpfc_version.h" |
54 | ||
81301a9b JS |
55 | char *_dump_buf_data; |
56 | unsigned long _dump_buf_data_order; | |
57 | char *_dump_buf_dif; | |
58 | unsigned long _dump_buf_dif_order; | |
59 | spinlock_t _dump_buf_lock; | |
60 | ||
dea3101e JB |
61 | static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); |
62 | static int lpfc_post_rcv_buf(struct lpfc_hba *); | |
5350d872 | 63 | static int lpfc_sli4_queue_verify(struct lpfc_hba *); |
da0436e9 JS |
64 | static int lpfc_create_bootstrap_mbox(struct lpfc_hba *); |
65 | static int lpfc_setup_endian_order(struct lpfc_hba *); | |
da0436e9 JS |
66 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); |
67 | static void lpfc_free_sgl_list(struct lpfc_hba *); | |
68 | static int lpfc_init_sgl_list(struct lpfc_hba *); | |
69 | static int lpfc_init_active_sgl_array(struct lpfc_hba *); | |
70 | static void lpfc_free_active_sgl(struct lpfc_hba *); | |
71 | static int lpfc_hba_down_post_s3(struct lpfc_hba *phba); | |
72 | static int lpfc_hba_down_post_s4(struct lpfc_hba *phba); | |
73 | static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *); | |
74 | static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *); | |
75 | static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *); | |
dea3101e JB |
76 | |
77 | static struct scsi_transport_template *lpfc_transport_template = NULL; | |
92d7f7b0 | 78 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
dea3101e JB |
79 | static DEFINE_IDR(lpfc_hba_index); |
80 | ||
e59058c4 | 81 | /** |
3621a710 | 82 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
e59058c4 JS |
83 | * @phba: pointer to lpfc hba data structure. |
84 | * | |
85 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT | |
86 | * mailbox command. It retrieves the revision information from the HBA and | |
87 | * collects the Vital Product Data (VPD) about the HBA for preparing the | |
88 | * configuration of the HBA. | |
89 | * | |
90 | * Return codes: | |
91 | * 0 - success. | |
92 | * -ERESTART - requests the SLI layer to reset the HBA and try again. | |
93 | * Any other value - indicates an error. | |
94 | **/ | |
dea3101e | 95 | int |
2e0fef85 | 96 | lpfc_config_port_prep(struct lpfc_hba *phba) |
dea3101e JB |
97 | { |
98 | lpfc_vpd_t *vp = &phba->vpd; | |
99 | int i = 0, rc; | |
100 | LPFC_MBOXQ_t *pmb; | |
101 | MAILBOX_t *mb; | |
102 | char *lpfc_vpd_data = NULL; | |
103 | uint16_t offset = 0; | |
104 | static char licensed[56] = | |
105 | "key unlock for use with gnu public licensed code only\0"; | |
65a29c16 | 106 | static int init_key = 1; |
dea3101e JB |
107 | |
108 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
109 | if (!pmb) { | |
2e0fef85 | 110 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
111 | return -ENOMEM; |
112 | } | |
113 | ||
04c68496 | 114 | mb = &pmb->u.mb; |
2e0fef85 | 115 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e JB |
116 | |
117 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { | |
65a29c16 JS |
118 | if (init_key) { |
119 | uint32_t *ptext = (uint32_t *) licensed; | |
dea3101e | 120 | |
65a29c16 JS |
121 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
122 | *ptext = cpu_to_be32(*ptext); | |
123 | init_key = 0; | |
124 | } | |
dea3101e JB |
125 | |
126 | lpfc_read_nv(phba, pmb); | |
127 | memset((char*)mb->un.varRDnvp.rsvd3, 0, | |
128 | sizeof (mb->un.varRDnvp.rsvd3)); | |
129 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, | |
130 | sizeof (licensed)); | |
131 | ||
132 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
133 | ||
134 | if (rc != MBX_SUCCESS) { | |
ed957684 | 135 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
e8b62011 | 136 | "0324 Config Port initialization " |
dea3101e JB |
137 | "error, mbxCmd x%x READ_NVPARM, " |
138 | "mbxStatus x%x\n", | |
dea3101e JB |
139 | mb->mbxCommand, mb->mbxStatus); |
140 | mempool_free(pmb, phba->mbox_mem_pool); | |
141 | return -ERESTART; | |
142 | } | |
143 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, | |
2e0fef85 JS |
144 | sizeof(phba->wwnn)); |
145 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, | |
146 | sizeof(phba->wwpn)); | |
dea3101e JB |
147 | } |
148 | ||
92d7f7b0 JS |
149 | phba->sli3_options = 0x0; |
150 | ||
dea3101e JB |
151 | /* Setup and issue mailbox READ REV command */ |
152 | lpfc_read_rev(phba, pmb); | |
153 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
154 | if (rc != MBX_SUCCESS) { | |
ed957684 | 155 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 156 | "0439 Adapter failed to init, mbxCmd x%x " |
dea3101e | 157 | "READ_REV, mbxStatus x%x\n", |
dea3101e JB |
158 | mb->mbxCommand, mb->mbxStatus); |
159 | mempool_free( pmb, phba->mbox_mem_pool); | |
160 | return -ERESTART; | |
161 | } | |
162 | ||
92d7f7b0 | 163 | |
1de933f3 JSEC |
164 | /* |
165 | * The value of rr must be 1 since the driver set the cv field to 1. | |
166 | * This setting requires the FW to set all revision fields. | |
dea3101e | 167 | */ |
1de933f3 | 168 | if (mb->un.varRdRev.rr == 0) { |
dea3101e | 169 | vp->rev.rBit = 0; |
1de933f3 | 170 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 JS |
171 | "0440 Adapter failed to init, READ_REV has " |
172 | "missing revision information.\n"); | |
dea3101e JB |
173 | mempool_free(pmb, phba->mbox_mem_pool); |
174 | return -ERESTART; | |
dea3101e JB |
175 | } |
176 | ||
495a714c JS |
177 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
178 | mempool_free(pmb, phba->mbox_mem_pool); | |
ed957684 | 179 | return -EINVAL; |
495a714c | 180 | } |
ed957684 | 181 | |
dea3101e | 182 | /* Save information as VPD data */ |
1de933f3 | 183 | vp->rev.rBit = 1; |
92d7f7b0 | 184 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
1de933f3 JSEC |
185 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
186 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); | |
187 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; | |
188 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); | |
dea3101e JB |
189 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
190 | vp->rev.smRev = mb->un.varRdRev.smRev; | |
191 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; | |
192 | vp->rev.endecRev = mb->un.varRdRev.endecRev; | |
193 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; | |
194 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; | |
195 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; | |
196 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; | |
197 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; | |
198 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; | |
199 | ||
92d7f7b0 JS |
200 | /* If the sli feature level is less then 9, we must |
201 | * tear down all RPIs and VPIs on link down if NPIV | |
202 | * is enabled. | |
203 | */ | |
204 | if (vp->rev.feaLevelHigh < 9) | |
205 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; | |
206 | ||
dea3101e JB |
207 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
208 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], | |
209 | sizeof (phba->RandomData)); | |
210 | ||
dea3101e | 211 | /* Get adapter VPD information */ |
dea3101e JB |
212 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
213 | if (!lpfc_vpd_data) | |
d7c255b2 | 214 | goto out_free_mbox; |
dea3101e | 215 | do { |
a0c87cbd | 216 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
dea3101e JB |
217 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
218 | ||
219 | if (rc != MBX_SUCCESS) { | |
220 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 | 221 | "0441 VPD not present on adapter, " |
dea3101e | 222 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
dea3101e | 223 | mb->mbxCommand, mb->mbxStatus); |
74b72a59 | 224 | mb->un.varDmp.word_cnt = 0; |
dea3101e | 225 | } |
04c68496 JS |
226 | /* dump mem may return a zero when finished or we got a |
227 | * mailbox error, either way we are done. | |
228 | */ | |
229 | if (mb->un.varDmp.word_cnt == 0) | |
230 | break; | |
74b72a59 JW |
231 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
232 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; | |
d7c255b2 JS |
233 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
234 | lpfc_vpd_data + offset, | |
92d7f7b0 | 235 | mb->un.varDmp.word_cnt); |
dea3101e | 236 | offset += mb->un.varDmp.word_cnt; |
74b72a59 JW |
237 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
238 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); | |
dea3101e JB |
239 | |
240 | kfree(lpfc_vpd_data); | |
dea3101e JB |
241 | out_free_mbox: |
242 | mempool_free(pmb, phba->mbox_mem_pool); | |
243 | return 0; | |
244 | } | |
245 | ||
e59058c4 | 246 | /** |
3621a710 | 247 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
e59058c4 JS |
248 | * @phba: pointer to lpfc hba data structure. |
249 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
250 | * | |
251 | * This is the completion handler for driver's configuring asynchronous event | |
252 | * mailbox command to the device. If the mailbox command returns successfully, | |
253 | * it will set internal async event support flag to 1; otherwise, it will | |
254 | * set internal async event support flag to 0. | |
255 | **/ | |
57127f15 JS |
256 | static void |
257 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
258 | { | |
04c68496 | 259 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
57127f15 JS |
260 | phba->temp_sensor_support = 1; |
261 | else | |
262 | phba->temp_sensor_support = 0; | |
263 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
264 | return; | |
265 | } | |
266 | ||
97207482 | 267 | /** |
3621a710 | 268 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
97207482 JS |
269 | * @phba: pointer to lpfc hba data structure. |
270 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
271 | * | |
272 | * This is the completion handler for dump mailbox command for getting | |
273 | * wake up parameters. When this command complete, the response contain | |
274 | * Option rom version of the HBA. This function translate the version number | |
275 | * into a human readable string and store it in OptionROMVersion. | |
276 | **/ | |
277 | static void | |
278 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) | |
279 | { | |
280 | struct prog_id *prg; | |
281 | uint32_t prog_id_word; | |
282 | char dist = ' '; | |
283 | /* character array used for decoding dist type. */ | |
284 | char dist_char[] = "nabx"; | |
285 | ||
04c68496 | 286 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
9f1e1b50 | 287 | mempool_free(pmboxq, phba->mbox_mem_pool); |
97207482 | 288 | return; |
9f1e1b50 | 289 | } |
97207482 JS |
290 | |
291 | prg = (struct prog_id *) &prog_id_word; | |
292 | ||
293 | /* word 7 contain option rom version */ | |
04c68496 | 294 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
97207482 JS |
295 | |
296 | /* Decode the Option rom version word to a readable string */ | |
297 | if (prg->dist < 4) | |
298 | dist = dist_char[prg->dist]; | |
299 | ||
300 | if ((prg->dist == 3) && (prg->num == 0)) | |
301 | sprintf(phba->OptionROMVersion, "%d.%d%d", | |
302 | prg->ver, prg->rev, prg->lev); | |
303 | else | |
304 | sprintf(phba->OptionROMVersion, "%d.%d%d%c%d", | |
305 | prg->ver, prg->rev, prg->lev, | |
306 | dist, prg->num); | |
9f1e1b50 | 307 | mempool_free(pmboxq, phba->mbox_mem_pool); |
97207482 JS |
308 | return; |
309 | } | |
310 | ||
0558056c JS |
311 | /** |
312 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, | |
313 | * cfg_soft_wwnn, cfg_soft_wwpn | |
314 | * @vport: pointer to lpfc vport data structure. | |
315 | * | |
316 | * | |
317 | * Return codes | |
318 | * None. | |
319 | **/ | |
320 | void | |
321 | lpfc_update_vport_wwn(struct lpfc_vport *vport) | |
322 | { | |
323 | /* If the soft name exists then update it using the service params */ | |
324 | if (vport->phba->cfg_soft_wwnn) | |
325 | u64_to_wwn(vport->phba->cfg_soft_wwnn, | |
326 | vport->fc_sparam.nodeName.u.wwn); | |
327 | if (vport->phba->cfg_soft_wwpn) | |
328 | u64_to_wwn(vport->phba->cfg_soft_wwpn, | |
329 | vport->fc_sparam.portName.u.wwn); | |
330 | ||
331 | /* | |
332 | * If the name is empty or there exists a soft name | |
333 | * then copy the service params name, otherwise use the fc name | |
334 | */ | |
335 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) | |
336 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, | |
337 | sizeof(struct lpfc_name)); | |
338 | else | |
339 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, | |
340 | sizeof(struct lpfc_name)); | |
341 | ||
342 | if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn) | |
343 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, | |
344 | sizeof(struct lpfc_name)); | |
345 | else | |
346 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, | |
347 | sizeof(struct lpfc_name)); | |
348 | } | |
349 | ||
e59058c4 | 350 | /** |
3621a710 | 351 | * lpfc_config_port_post - Perform lpfc initialization after config port |
e59058c4 JS |
352 | * @phba: pointer to lpfc hba data structure. |
353 | * | |
354 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox | |
355 | * command call. It performs all internal resource and state setups on the | |
356 | * port: post IOCB buffers, enable appropriate host interrupt attentions, | |
357 | * ELS ring timers, etc. | |
358 | * | |
359 | * Return codes | |
360 | * 0 - success. | |
361 | * Any other value - error. | |
362 | **/ | |
dea3101e | 363 | int |
2e0fef85 | 364 | lpfc_config_port_post(struct lpfc_hba *phba) |
dea3101e | 365 | { |
2e0fef85 | 366 | struct lpfc_vport *vport = phba->pport; |
a257bf90 | 367 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e JB |
368 | LPFC_MBOXQ_t *pmb; |
369 | MAILBOX_t *mb; | |
370 | struct lpfc_dmabuf *mp; | |
371 | struct lpfc_sli *psli = &phba->sli; | |
372 | uint32_t status, timeout; | |
2e0fef85 JS |
373 | int i, j; |
374 | int rc; | |
dea3101e | 375 | |
7af67051 JS |
376 | spin_lock_irq(&phba->hbalock); |
377 | /* | |
378 | * If the Config port completed correctly the HBA is not | |
379 | * over heated any more. | |
380 | */ | |
381 | if (phba->over_temp_state == HBA_OVER_TEMP) | |
382 | phba->over_temp_state = HBA_NORMAL_TEMP; | |
383 | spin_unlock_irq(&phba->hbalock); | |
384 | ||
dea3101e JB |
385 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
386 | if (!pmb) { | |
2e0fef85 | 387 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
388 | return -ENOMEM; |
389 | } | |
04c68496 | 390 | mb = &pmb->u.mb; |
dea3101e | 391 | |
dea3101e | 392 | /* Get login parameters for NID. */ |
9f1177a3 JS |
393 | rc = lpfc_read_sparam(phba, pmb, 0); |
394 | if (rc) { | |
395 | mempool_free(pmb, phba->mbox_mem_pool); | |
396 | return -ENOMEM; | |
397 | } | |
398 | ||
ed957684 | 399 | pmb->vport = vport; |
dea3101e | 400 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 401 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 402 | "0448 Adapter failed init, mbxCmd x%x " |
dea3101e | 403 | "READ_SPARM mbxStatus x%x\n", |
dea3101e | 404 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 405 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 406 | mp = (struct lpfc_dmabuf *) pmb->context1; |
9f1177a3 | 407 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e JB |
408 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
409 | kfree(mp); | |
410 | return -EIO; | |
411 | } | |
412 | ||
413 | mp = (struct lpfc_dmabuf *) pmb->context1; | |
414 | ||
2e0fef85 | 415 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
dea3101e JB |
416 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
417 | kfree(mp); | |
418 | pmb->context1 = NULL; | |
0558056c | 419 | lpfc_update_vport_wwn(vport); |
a257bf90 JS |
420 | |
421 | /* Update the fc_host data structures with new wwn. */ | |
422 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
423 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
21e9a0a5 | 424 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
a257bf90 | 425 | |
dea3101e JB |
426 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
427 | /* This should be consolidated into parse_vpd ? - mr */ | |
428 | if (phba->SerialNumber[0] == 0) { | |
429 | uint8_t *outptr; | |
430 | ||
2e0fef85 | 431 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
dea3101e JB |
432 | for (i = 0; i < 12; i++) { |
433 | status = *outptr++; | |
434 | j = ((status & 0xf0) >> 4); | |
435 | if (j <= 9) | |
436 | phba->SerialNumber[i] = | |
437 | (char)((uint8_t) 0x30 + (uint8_t) j); | |
438 | else | |
439 | phba->SerialNumber[i] = | |
440 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | |
441 | i++; | |
442 | j = (status & 0xf); | |
443 | if (j <= 9) | |
444 | phba->SerialNumber[i] = | |
445 | (char)((uint8_t) 0x30 + (uint8_t) j); | |
446 | else | |
447 | phba->SerialNumber[i] = | |
448 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | |
449 | } | |
450 | } | |
451 | ||
dea3101e | 452 | lpfc_read_config(phba, pmb); |
ed957684 | 453 | pmb->vport = vport; |
dea3101e | 454 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 455 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 456 | "0453 Adapter failed to init, mbxCmd x%x " |
dea3101e | 457 | "READ_CONFIG, mbxStatus x%x\n", |
dea3101e | 458 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 459 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
460 | mempool_free( pmb, phba->mbox_mem_pool); |
461 | return -EIO; | |
462 | } | |
463 | ||
a0c87cbd JS |
464 | /* Check if the port is disabled */ |
465 | lpfc_sli_read_link_ste(phba); | |
466 | ||
dea3101e JB |
467 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
468 | if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1)) | |
469 | phba->cfg_hba_queue_depth = | |
f1126688 JS |
470 | (mb->un.varRdConfig.max_xri + 1) - |
471 | lpfc_sli4_get_els_iocb_cnt(phba); | |
dea3101e JB |
472 | |
473 | phba->lmt = mb->un.varRdConfig.lmt; | |
74b72a59 JW |
474 | |
475 | /* Get the default values for Model Name and Description */ | |
476 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
477 | ||
2e0fef85 | 478 | phba->link_state = LPFC_LINK_DOWN; |
dea3101e | 479 | |
0b727fea | 480 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
a4bc3379 JS |
481 | if (psli->ring[psli->extra_ring].cmdringaddr) |
482 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; | |
dea3101e JB |
483 | if (psli->ring[psli->fcp_ring].cmdringaddr) |
484 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; | |
485 | if (psli->ring[psli->next_ring].cmdringaddr) | |
486 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; | |
487 | ||
488 | /* Post receive buffers for desired rings */ | |
ed957684 JS |
489 | if (phba->sli_rev != 3) |
490 | lpfc_post_rcv_buf(phba); | |
dea3101e | 491 | |
9399627f JS |
492 | /* |
493 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode | |
494 | */ | |
495 | if (phba->intr_type == MSIX) { | |
496 | rc = lpfc_config_msi(phba, pmb); | |
497 | if (rc) { | |
498 | mempool_free(pmb, phba->mbox_mem_pool); | |
499 | return -EIO; | |
500 | } | |
501 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
502 | if (rc != MBX_SUCCESS) { | |
503 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
504 | "0352 Config MSI mailbox command " | |
505 | "failed, mbxCmd x%x, mbxStatus x%x\n", | |
04c68496 JS |
506 | pmb->u.mb.mbxCommand, |
507 | pmb->u.mb.mbxStatus); | |
9399627f JS |
508 | mempool_free(pmb, phba->mbox_mem_pool); |
509 | return -EIO; | |
510 | } | |
511 | } | |
512 | ||
04c68496 | 513 | spin_lock_irq(&phba->hbalock); |
9399627f JS |
514 | /* Initialize ERATT handling flag */ |
515 | phba->hba_flag &= ~HBA_ERATT_HANDLED; | |
516 | ||
dea3101e | 517 | /* Enable appropriate host interrupts */ |
9940b97b JS |
518 | if (lpfc_readl(phba->HCregaddr, &status)) { |
519 | spin_unlock_irq(&phba->hbalock); | |
520 | return -EIO; | |
521 | } | |
dea3101e JB |
522 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
523 | if (psli->num_rings > 0) | |
524 | status |= HC_R0INT_ENA; | |
525 | if (psli->num_rings > 1) | |
526 | status |= HC_R1INT_ENA; | |
527 | if (psli->num_rings > 2) | |
528 | status |= HC_R2INT_ENA; | |
529 | if (psli->num_rings > 3) | |
530 | status |= HC_R3INT_ENA; | |
531 | ||
875fbdfe JSEC |
532 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
533 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) | |
9399627f | 534 | status &= ~(HC_R0INT_ENA); |
875fbdfe | 535 | |
dea3101e JB |
536 | writel(status, phba->HCregaddr); |
537 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 538 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 539 | |
9399627f JS |
540 | /* Set up ring-0 (ELS) timer */ |
541 | timeout = phba->fc_ratov * 2; | |
2e0fef85 | 542 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
9399627f | 543 | /* Set up heart beat (HB) timer */ |
858c9f6c JS |
544 | mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
545 | phba->hb_outstanding = 0; | |
546 | phba->last_completion_time = jiffies; | |
9399627f JS |
547 | /* Set up error attention (ERATT) polling timer */ |
548 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); | |
dea3101e | 549 | |
a0c87cbd JS |
550 | if (phba->hba_flag & LINK_DISABLED) { |
551 | lpfc_printf_log(phba, | |
552 | KERN_ERR, LOG_INIT, | |
553 | "2598 Adapter Link is disabled.\n"); | |
554 | lpfc_down_link(phba, pmb); | |
555 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
556 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
557 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { | |
558 | lpfc_printf_log(phba, | |
559 | KERN_ERR, LOG_INIT, | |
560 | "2599 Adapter failed to issue DOWN_LINK" | |
561 | " mbox command rc 0x%x\n", rc); | |
562 | ||
563 | mempool_free(pmb, phba->mbox_mem_pool); | |
564 | return -EIO; | |
565 | } | |
e40a02c1 | 566 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
026abb87 JS |
567 | mempool_free(pmb, phba->mbox_mem_pool); |
568 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); | |
569 | if (rc) | |
570 | return rc; | |
dea3101e JB |
571 | } |
572 | /* MBOX buffer will be freed in mbox compl */ | |
57127f15 | 573 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
9f1177a3 JS |
574 | if (!pmb) { |
575 | phba->link_state = LPFC_HBA_ERROR; | |
576 | return -ENOMEM; | |
577 | } | |
578 | ||
57127f15 JS |
579 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
580 | pmb->mbox_cmpl = lpfc_config_async_cmpl; | |
581 | pmb->vport = phba->pport; | |
582 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
dea3101e | 583 | |
57127f15 JS |
584 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
585 | lpfc_printf_log(phba, | |
586 | KERN_ERR, | |
587 | LOG_INIT, | |
588 | "0456 Adapter failed to issue " | |
e4e74273 | 589 | "ASYNCEVT_ENABLE mbox status x%x\n", |
57127f15 JS |
590 | rc); |
591 | mempool_free(pmb, phba->mbox_mem_pool); | |
592 | } | |
97207482 JS |
593 | |
594 | /* Get Option rom version */ | |
595 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
9f1177a3 JS |
596 | if (!pmb) { |
597 | phba->link_state = LPFC_HBA_ERROR; | |
598 | return -ENOMEM; | |
599 | } | |
600 | ||
97207482 JS |
601 | lpfc_dump_wakeup_param(phba, pmb); |
602 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; | |
603 | pmb->vport = phba->pport; | |
604 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
605 | ||
606 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { | |
607 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " | |
e4e74273 | 608 | "to get Option ROM version status x%x\n", rc); |
97207482 JS |
609 | mempool_free(pmb, phba->mbox_mem_pool); |
610 | } | |
611 | ||
d7c255b2 | 612 | return 0; |
ce8b3ce5 JS |
613 | } |
614 | ||
84d1b006 JS |
615 | /** |
616 | * lpfc_hba_init_link - Initialize the FC link | |
617 | * @phba: pointer to lpfc hba data structure. | |
6e7288d9 | 618 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
84d1b006 JS |
619 | * |
620 | * This routine will issue the INIT_LINK mailbox command call. | |
621 | * It is available to other drivers through the lpfc_hba data | |
622 | * structure for use as a delayed link up mechanism with the | |
623 | * module parameter lpfc_suppress_link_up. | |
624 | * | |
625 | * Return code | |
626 | * 0 - success | |
627 | * Any other value - error | |
628 | **/ | |
629 | int | |
6e7288d9 | 630 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
1b51197d JS |
631 | { |
632 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); | |
633 | } | |
634 | ||
635 | /** | |
636 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology | |
637 | * @phba: pointer to lpfc hba data structure. | |
638 | * @fc_topology: desired fc topology. | |
639 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT | |
640 | * | |
641 | * This routine will issue the INIT_LINK mailbox command call. | |
642 | * It is available to other drivers through the lpfc_hba data | |
643 | * structure for use as a delayed link up mechanism with the | |
644 | * module parameter lpfc_suppress_link_up. | |
645 | * | |
646 | * Return code | |
647 | * 0 - success | |
648 | * Any other value - error | |
649 | **/ | |
650 | int | |
651 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, | |
652 | uint32_t flag) | |
84d1b006 JS |
653 | { |
654 | struct lpfc_vport *vport = phba->pport; | |
655 | LPFC_MBOXQ_t *pmb; | |
656 | MAILBOX_t *mb; | |
657 | int rc; | |
658 | ||
659 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
660 | if (!pmb) { | |
661 | phba->link_state = LPFC_HBA_ERROR; | |
662 | return -ENOMEM; | |
663 | } | |
664 | mb = &pmb->u.mb; | |
665 | pmb->vport = vport; | |
666 | ||
026abb87 JS |
667 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
668 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && | |
669 | !(phba->lmt & LMT_1Gb)) || | |
670 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && | |
671 | !(phba->lmt & LMT_2Gb)) || | |
672 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && | |
673 | !(phba->lmt & LMT_4Gb)) || | |
674 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && | |
675 | !(phba->lmt & LMT_8Gb)) || | |
676 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && | |
677 | !(phba->lmt & LMT_10Gb)) || | |
678 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && | |
679 | !(phba->lmt & LMT_16Gb))) { | |
680 | /* Reset link speed to auto */ | |
681 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, | |
682 | "1302 Invalid speed for this board:%d " | |
683 | "Reset link speed to auto.\n", | |
684 | phba->cfg_link_speed); | |
685 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; | |
686 | } | |
1b51197d | 687 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
84d1b006 | 688 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
1b51197d JS |
689 | if (phba->sli_rev < LPFC_SLI_REV4) |
690 | lpfc_set_loopback_flag(phba); | |
6e7288d9 | 691 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
76a95d75 | 692 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
84d1b006 JS |
693 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
694 | "0498 Adapter failed to init, mbxCmd x%x " | |
695 | "INIT_LINK, mbxStatus x%x\n", | |
696 | mb->mbxCommand, mb->mbxStatus); | |
76a95d75 JS |
697 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
698 | /* Clear all interrupt enable conditions */ | |
699 | writel(0, phba->HCregaddr); | |
700 | readl(phba->HCregaddr); /* flush */ | |
701 | /* Clear all pending interrupts */ | |
702 | writel(0xffffffff, phba->HAregaddr); | |
703 | readl(phba->HAregaddr); /* flush */ | |
704 | } | |
84d1b006 | 705 | phba->link_state = LPFC_HBA_ERROR; |
6e7288d9 | 706 | if (rc != MBX_BUSY || flag == MBX_POLL) |
84d1b006 JS |
707 | mempool_free(pmb, phba->mbox_mem_pool); |
708 | return -EIO; | |
709 | } | |
e40a02c1 | 710 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
6e7288d9 JS |
711 | if (flag == MBX_POLL) |
712 | mempool_free(pmb, phba->mbox_mem_pool); | |
84d1b006 JS |
713 | |
714 | return 0; | |
715 | } | |
716 | ||
717 | /** | |
718 | * lpfc_hba_down_link - this routine downs the FC link | |
6e7288d9 JS |
719 | * @phba: pointer to lpfc hba data structure. |
720 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT | |
84d1b006 JS |
721 | * |
722 | * This routine will issue the DOWN_LINK mailbox command call. | |
723 | * It is available to other drivers through the lpfc_hba data | |
724 | * structure for use to stop the link. | |
725 | * | |
726 | * Return code | |
727 | * 0 - success | |
728 | * Any other value - error | |
729 | **/ | |
730 | int | |
6e7288d9 | 731 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
84d1b006 JS |
732 | { |
733 | LPFC_MBOXQ_t *pmb; | |
734 | int rc; | |
735 | ||
736 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
737 | if (!pmb) { | |
738 | phba->link_state = LPFC_HBA_ERROR; | |
739 | return -ENOMEM; | |
740 | } | |
741 | ||
742 | lpfc_printf_log(phba, | |
743 | KERN_ERR, LOG_INIT, | |
744 | "0491 Adapter Link is disabled.\n"); | |
745 | lpfc_down_link(phba, pmb); | |
746 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
6e7288d9 | 747 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
84d1b006 JS |
748 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
749 | lpfc_printf_log(phba, | |
750 | KERN_ERR, LOG_INIT, | |
751 | "2522 Adapter failed to issue DOWN_LINK" | |
752 | " mbox command rc 0x%x\n", rc); | |
753 | ||
754 | mempool_free(pmb, phba->mbox_mem_pool); | |
755 | return -EIO; | |
756 | } | |
6e7288d9 JS |
757 | if (flag == MBX_POLL) |
758 | mempool_free(pmb, phba->mbox_mem_pool); | |
759 | ||
84d1b006 JS |
760 | return 0; |
761 | } | |
762 | ||
e59058c4 | 763 | /** |
3621a710 | 764 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
e59058c4 JS |
765 | * @phba: pointer to lpfc HBA data structure. |
766 | * | |
767 | * This routine will do LPFC uninitialization before the HBA is reset when | |
768 | * bringing down the SLI Layer. | |
769 | * | |
770 | * Return codes | |
771 | * 0 - success. | |
772 | * Any other value - error. | |
773 | **/ | |
dea3101e | 774 | int |
2e0fef85 | 775 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
dea3101e | 776 | { |
1b32f6aa JS |
777 | struct lpfc_vport **vports; |
778 | int i; | |
3772a991 JS |
779 | |
780 | if (phba->sli_rev <= LPFC_SLI_REV3) { | |
781 | /* Disable interrupts */ | |
782 | writel(0, phba->HCregaddr); | |
783 | readl(phba->HCregaddr); /* flush */ | |
784 | } | |
dea3101e | 785 | |
1b32f6aa JS |
786 | if (phba->pport->load_flag & FC_UNLOADING) |
787 | lpfc_cleanup_discovery_resources(phba->pport); | |
788 | else { | |
789 | vports = lpfc_create_vport_work_array(phba); | |
790 | if (vports != NULL) | |
3772a991 JS |
791 | for (i = 0; i <= phba->max_vports && |
792 | vports[i] != NULL; i++) | |
1b32f6aa JS |
793 | lpfc_cleanup_discovery_resources(vports[i]); |
794 | lpfc_destroy_vport_work_array(phba, vports); | |
7f5f3d0d JS |
795 | } |
796 | return 0; | |
dea3101e JB |
797 | } |
798 | ||
e59058c4 | 799 | /** |
3772a991 | 800 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
e59058c4 JS |
801 | * @phba: pointer to lpfc HBA data structure. |
802 | * | |
803 | * This routine will do uninitialization after the HBA is reset when bring | |
804 | * down the SLI Layer. | |
805 | * | |
806 | * Return codes | |
af901ca1 | 807 | * 0 - success. |
e59058c4 JS |
808 | * Any other value - error. |
809 | **/ | |
3772a991 JS |
810 | static int |
811 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) | |
41415862 JW |
812 | { |
813 | struct lpfc_sli *psli = &phba->sli; | |
814 | struct lpfc_sli_ring *pring; | |
815 | struct lpfc_dmabuf *mp, *next_mp; | |
09372820 | 816 | LIST_HEAD(completions); |
41415862 JW |
817 | int i; |
818 | ||
92d7f7b0 JS |
819 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
820 | lpfc_sli_hbqbuf_free_all(phba); | |
821 | else { | |
822 | /* Cleanup preposted buffers on the ELS ring */ | |
823 | pring = &psli->ring[LPFC_ELS_RING]; | |
824 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
825 | list_del(&mp->list); | |
826 | pring->postbufq_cnt--; | |
827 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
828 | kfree(mp); | |
829 | } | |
41415862 JW |
830 | } |
831 | ||
09372820 | 832 | spin_lock_irq(&phba->hbalock); |
41415862 JW |
833 | for (i = 0; i < psli->num_rings; i++) { |
834 | pring = &psli->ring[i]; | |
09372820 JS |
835 | |
836 | /* At this point in time the HBA is either reset or DOA. Either | |
837 | * way, nothing should be on txcmplq as it will NEVER complete. | |
838 | */ | |
839 | list_splice_init(&pring->txcmplq, &completions); | |
840 | pring->txcmplq_cnt = 0; | |
841 | spin_unlock_irq(&phba->hbalock); | |
842 | ||
a257bf90 JS |
843 | /* Cancel all the IOCBs from the completions list */ |
844 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
845 | IOERR_SLI_ABORTED); | |
09372820 | 846 | |
41415862 | 847 | lpfc_sli_abort_iocb_ring(phba, pring); |
09372820 | 848 | spin_lock_irq(&phba->hbalock); |
41415862 | 849 | } |
09372820 | 850 | spin_unlock_irq(&phba->hbalock); |
41415862 JW |
851 | |
852 | return 0; | |
853 | } | |
5af5eee7 | 854 | |
da0436e9 JS |
855 | /** |
856 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset | |
857 | * @phba: pointer to lpfc HBA data structure. | |
858 | * | |
859 | * This routine will do uninitialization after the HBA is reset when bring | |
860 | * down the SLI Layer. | |
861 | * | |
862 | * Return codes | |
af901ca1 | 863 | * 0 - success. |
da0436e9 JS |
864 | * Any other value - error. |
865 | **/ | |
866 | static int | |
867 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) | |
868 | { | |
869 | struct lpfc_scsi_buf *psb, *psb_next; | |
870 | LIST_HEAD(aborts); | |
871 | int ret; | |
872 | unsigned long iflag = 0; | |
0f65ff68 JS |
873 | struct lpfc_sglq *sglq_entry = NULL; |
874 | ||
da0436e9 JS |
875 | ret = lpfc_hba_down_post_s3(phba); |
876 | if (ret) | |
877 | return ret; | |
878 | /* At this point in time the HBA is either reset or DOA. Either | |
879 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be | |
880 | * on the lpfc_sgl_list so that it can either be freed if the | |
881 | * driver is unloading or reposted if the driver is restarting | |
882 | * the port. | |
883 | */ | |
884 | spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */ | |
885 | /* scsl_buf_list */ | |
886 | /* abts_sgl_list_lock required because worker thread uses this | |
887 | * list. | |
888 | */ | |
889 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); | |
0f65ff68 JS |
890 | list_for_each_entry(sglq_entry, |
891 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) | |
892 | sglq_entry->state = SGL_FREED; | |
893 | ||
da0436e9 JS |
894 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
895 | &phba->sli4_hba.lpfc_sgl_list); | |
896 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); | |
897 | /* abts_scsi_buf_list_lock required because worker thread uses this | |
898 | * list. | |
899 | */ | |
900 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
901 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, | |
902 | &aborts); | |
903 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
904 | spin_unlock_irq(&phba->hbalock); | |
905 | ||
906 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { | |
907 | psb->pCmd = NULL; | |
908 | psb->status = IOSTAT_SUCCESS; | |
909 | } | |
910 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); | |
911 | list_splice(&aborts, &phba->lpfc_scsi_buf_list); | |
912 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); | |
913 | return 0; | |
914 | } | |
915 | ||
916 | /** | |
917 | * lpfc_hba_down_post - Wrapper func for hba down post routine | |
918 | * @phba: pointer to lpfc HBA data structure. | |
919 | * | |
920 | * This routine wraps the actual SLI3 or SLI4 routine for performing | |
921 | * uninitialization after the HBA is reset when bring down the SLI Layer. | |
922 | * | |
923 | * Return codes | |
af901ca1 | 924 | * 0 - success. |
da0436e9 JS |
925 | * Any other value - error. |
926 | **/ | |
927 | int | |
928 | lpfc_hba_down_post(struct lpfc_hba *phba) | |
929 | { | |
930 | return (*phba->lpfc_hba_down_post)(phba); | |
931 | } | |
41415862 | 932 | |
e59058c4 | 933 | /** |
3621a710 | 934 | * lpfc_hb_timeout - The HBA-timer timeout handler |
e59058c4 JS |
935 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
936 | * | |
937 | * This is the HBA-timer timeout handler registered to the lpfc driver. When | |
938 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver | |
939 | * work-port-events bitmap and the worker thread is notified. This timeout | |
940 | * event will be used by the worker thread to invoke the actual timeout | |
941 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will | |
942 | * be performed in the timeout handler and the HBA timeout event bit shall | |
943 | * be cleared by the worker thread after it has taken the event bitmap out. | |
944 | **/ | |
a6ababd2 | 945 | static void |
858c9f6c JS |
946 | lpfc_hb_timeout(unsigned long ptr) |
947 | { | |
948 | struct lpfc_hba *phba; | |
5e9d9b82 | 949 | uint32_t tmo_posted; |
858c9f6c JS |
950 | unsigned long iflag; |
951 | ||
952 | phba = (struct lpfc_hba *)ptr; | |
9399627f JS |
953 | |
954 | /* Check for heart beat timeout conditions */ | |
858c9f6c | 955 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
5e9d9b82 JS |
956 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
957 | if (!tmo_posted) | |
858c9f6c JS |
958 | phba->pport->work_port_events |= WORKER_HB_TMO; |
959 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
960 | ||
9399627f | 961 | /* Tell the worker thread there is work to do */ |
5e9d9b82 JS |
962 | if (!tmo_posted) |
963 | lpfc_worker_wake_up(phba); | |
858c9f6c JS |
964 | return; |
965 | } | |
966 | ||
19ca7609 JS |
967 | /** |
968 | * lpfc_rrq_timeout - The RRQ-timer timeout handler | |
969 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. | |
970 | * | |
971 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When | |
972 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver | |
973 | * work-port-events bitmap and the worker thread is notified. This timeout | |
974 | * event will be used by the worker thread to invoke the actual timeout | |
975 | * handler routine, lpfc_rrq_handler. Any periodical operations will | |
976 | * be performed in the timeout handler and the RRQ timeout event bit shall | |
977 | * be cleared by the worker thread after it has taken the event bitmap out. | |
978 | **/ | |
979 | static void | |
980 | lpfc_rrq_timeout(unsigned long ptr) | |
981 | { | |
982 | struct lpfc_hba *phba; | |
19ca7609 JS |
983 | unsigned long iflag; |
984 | ||
985 | phba = (struct lpfc_hba *)ptr; | |
986 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
1151e3ec | 987 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
19ca7609 | 988 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
1151e3ec | 989 | lpfc_worker_wake_up(phba); |
19ca7609 JS |
990 | } |
991 | ||
e59058c4 | 992 | /** |
3621a710 | 993 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
e59058c4 JS |
994 | * @phba: pointer to lpfc hba data structure. |
995 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
996 | * | |
997 | * This is the callback function to the lpfc heart-beat mailbox command. | |
998 | * If configured, the lpfc driver issues the heart-beat mailbox command to | |
999 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the | |
1000 | * heart-beat mailbox command is issued, the driver shall set up heart-beat | |
1001 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks | |
1002 | * heart-beat outstanding state. Once the mailbox command comes back and | |
1003 | * no error conditions detected, the heart-beat mailbox command timer is | |
1004 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding | |
1005 | * state is cleared for the next heart-beat. If the timer expired with the | |
1006 | * heart-beat outstanding state set, the driver will put the HBA offline. | |
1007 | **/ | |
858c9f6c JS |
1008 | static void |
1009 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
1010 | { | |
1011 | unsigned long drvr_flag; | |
1012 | ||
1013 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
1014 | phba->hb_outstanding = 0; | |
1015 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
1016 | ||
9399627f | 1017 | /* Check and reset heart-beat timer is necessary */ |
858c9f6c JS |
1018 | mempool_free(pmboxq, phba->mbox_mem_pool); |
1019 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && | |
1020 | !(phba->link_state == LPFC_HBA_ERROR) && | |
51ef4c26 | 1021 | !(phba->pport->load_flag & FC_UNLOADING)) |
858c9f6c JS |
1022 | mod_timer(&phba->hb_tmofunc, |
1023 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
1024 | return; | |
1025 | } | |
1026 | ||
e59058c4 | 1027 | /** |
3621a710 | 1028 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
e59058c4 JS |
1029 | * @phba: pointer to lpfc hba data structure. |
1030 | * | |
1031 | * This is the actual HBA-timer timeout handler to be invoked by the worker | |
1032 | * thread whenever the HBA timer fired and HBA-timeout event posted. This | |
1033 | * handler performs any periodic operations needed for the device. If such | |
1034 | * periodic event has already been attended to either in the interrupt handler | |
1035 | * or by processing slow-ring or fast-ring events within the HBA-timer | |
1036 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets | |
1037 | * the timer for the next timeout period. If lpfc heart-beat mailbox command | |
1038 | * is configured and there is no heart-beat mailbox command outstanding, a | |
1039 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there | |
1040 | * has been a heart-beat mailbox command outstanding, the HBA shall be put | |
1041 | * to offline. | |
1042 | **/ | |
858c9f6c JS |
1043 | void |
1044 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) | |
1045 | { | |
45ed1190 | 1046 | struct lpfc_vport **vports; |
858c9f6c | 1047 | LPFC_MBOXQ_t *pmboxq; |
0ff10d46 | 1048 | struct lpfc_dmabuf *buf_ptr; |
45ed1190 | 1049 | int retval, i; |
858c9f6c | 1050 | struct lpfc_sli *psli = &phba->sli; |
0ff10d46 | 1051 | LIST_HEAD(completions); |
858c9f6c | 1052 | |
45ed1190 JS |
1053 | vports = lpfc_create_vport_work_array(phba); |
1054 | if (vports != NULL) | |
1055 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) | |
1056 | lpfc_rcv_seq_check_edtov(vports[i]); | |
1057 | lpfc_destroy_vport_work_array(phba, vports); | |
1058 | ||
858c9f6c | 1059 | if ((phba->link_state == LPFC_HBA_ERROR) || |
51ef4c26 | 1060 | (phba->pport->load_flag & FC_UNLOADING) || |
858c9f6c JS |
1061 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
1062 | return; | |
1063 | ||
1064 | spin_lock_irq(&phba->pport->work_port_lock); | |
858c9f6c JS |
1065 | |
1066 | if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, | |
1067 | jiffies)) { | |
1068 | spin_unlock_irq(&phba->pport->work_port_lock); | |
1069 | if (!phba->hb_outstanding) | |
1070 | mod_timer(&phba->hb_tmofunc, | |
1071 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
1072 | else | |
1073 | mod_timer(&phba->hb_tmofunc, | |
1074 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | |
1075 | return; | |
1076 | } | |
1077 | spin_unlock_irq(&phba->pport->work_port_lock); | |
1078 | ||
0ff10d46 JS |
1079 | if (phba->elsbuf_cnt && |
1080 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { | |
1081 | spin_lock_irq(&phba->hbalock); | |
1082 | list_splice_init(&phba->elsbuf, &completions); | |
1083 | phba->elsbuf_cnt = 0; | |
1084 | phba->elsbuf_prev_cnt = 0; | |
1085 | spin_unlock_irq(&phba->hbalock); | |
1086 | ||
1087 | while (!list_empty(&completions)) { | |
1088 | list_remove_head(&completions, buf_ptr, | |
1089 | struct lpfc_dmabuf, list); | |
1090 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
1091 | kfree(buf_ptr); | |
1092 | } | |
1093 | } | |
1094 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; | |
1095 | ||
858c9f6c | 1096 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
13815c83 JS |
1097 | if (phba->cfg_enable_hba_heartbeat) { |
1098 | if (!phba->hb_outstanding) { | |
bc73905a JS |
1099 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
1100 | (list_empty(&psli->mboxq))) { | |
1101 | pmboxq = mempool_alloc(phba->mbox_mem_pool, | |
1102 | GFP_KERNEL); | |
1103 | if (!pmboxq) { | |
1104 | mod_timer(&phba->hb_tmofunc, | |
1105 | jiffies + | |
1106 | HZ * LPFC_HB_MBOX_INTERVAL); | |
1107 | return; | |
1108 | } | |
1109 | ||
1110 | lpfc_heart_beat(phba, pmboxq); | |
1111 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; | |
1112 | pmboxq->vport = phba->pport; | |
1113 | retval = lpfc_sli_issue_mbox(phba, pmboxq, | |
1114 | MBX_NOWAIT); | |
1115 | ||
1116 | if (retval != MBX_BUSY && | |
1117 | retval != MBX_SUCCESS) { | |
1118 | mempool_free(pmboxq, | |
1119 | phba->mbox_mem_pool); | |
1120 | mod_timer(&phba->hb_tmofunc, | |
1121 | jiffies + | |
1122 | HZ * LPFC_HB_MBOX_INTERVAL); | |
1123 | return; | |
1124 | } | |
1125 | phba->skipped_hb = 0; | |
1126 | phba->hb_outstanding = 1; | |
1127 | } else if (time_before_eq(phba->last_completion_time, | |
1128 | phba->skipped_hb)) { | |
1129 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
1130 | "2857 Last completion time not " | |
1131 | " updated in %d ms\n", | |
1132 | jiffies_to_msecs(jiffies | |
1133 | - phba->last_completion_time)); | |
1134 | } else | |
1135 | phba->skipped_hb = jiffies; | |
1136 | ||
858c9f6c | 1137 | mod_timer(&phba->hb_tmofunc, |
13815c83 | 1138 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
858c9f6c | 1139 | return; |
13815c83 JS |
1140 | } else { |
1141 | /* | |
1142 | * If heart beat timeout called with hb_outstanding set | |
dcf2a4e0 JS |
1143 | * we need to give the hb mailbox cmd a chance to |
1144 | * complete or TMO. | |
13815c83 | 1145 | */ |
dcf2a4e0 JS |
1146 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
1147 | "0459 Adapter heartbeat still out" | |
1148 | "standing:last compl time was %d ms.\n", | |
1149 | jiffies_to_msecs(jiffies | |
1150 | - phba->last_completion_time)); | |
1151 | mod_timer(&phba->hb_tmofunc, | |
1152 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | |
858c9f6c | 1153 | } |
858c9f6c JS |
1154 | } |
1155 | } | |
1156 | ||
e59058c4 | 1157 | /** |
3621a710 | 1158 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
e59058c4 JS |
1159 | * @phba: pointer to lpfc hba data structure. |
1160 | * | |
1161 | * This routine is called to bring the HBA offline when HBA hardware error | |
1162 | * other than Port Error 6 has been detected. | |
1163 | **/ | |
09372820 JS |
1164 | static void |
1165 | lpfc_offline_eratt(struct lpfc_hba *phba) | |
1166 | { | |
1167 | struct lpfc_sli *psli = &phba->sli; | |
1168 | ||
1169 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1170 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
09372820 JS |
1171 | spin_unlock_irq(&phba->hbalock); |
1172 | lpfc_offline_prep(phba); | |
1173 | ||
1174 | lpfc_offline(phba); | |
1175 | lpfc_reset_barrier(phba); | |
f4b4c68f | 1176 | spin_lock_irq(&phba->hbalock); |
09372820 | 1177 | lpfc_sli_brdreset(phba); |
f4b4c68f | 1178 | spin_unlock_irq(&phba->hbalock); |
09372820 JS |
1179 | lpfc_hba_down_post(phba); |
1180 | lpfc_sli_brdready(phba, HS_MBRDY); | |
1181 | lpfc_unblock_mgmt_io(phba); | |
1182 | phba->link_state = LPFC_HBA_ERROR; | |
1183 | return; | |
1184 | } | |
1185 | ||
da0436e9 JS |
1186 | /** |
1187 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention | |
1188 | * @phba: pointer to lpfc hba data structure. | |
1189 | * | |
1190 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error | |
1191 | * other than Port Error 6 has been detected. | |
1192 | **/ | |
1193 | static void | |
1194 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) | |
1195 | { | |
1196 | lpfc_offline_prep(phba); | |
1197 | lpfc_offline(phba); | |
1198 | lpfc_sli4_brdreset(phba); | |
1199 | lpfc_hba_down_post(phba); | |
1200 | lpfc_sli4_post_status_check(phba); | |
1201 | lpfc_unblock_mgmt_io(phba); | |
1202 | phba->link_state = LPFC_HBA_ERROR; | |
1203 | } | |
1204 | ||
a257bf90 JS |
1205 | /** |
1206 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler | |
1207 | * @phba: pointer to lpfc hba data structure. | |
1208 | * | |
1209 | * This routine is invoked to handle the deferred HBA hardware error | |
1210 | * conditions. This type of error is indicated by HBA by setting ER1 | |
1211 | * and another ER bit in the host status register. The driver will | |
1212 | * wait until the ER1 bit clears before handling the error condition. | |
1213 | **/ | |
1214 | static void | |
1215 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) | |
1216 | { | |
1217 | uint32_t old_host_status = phba->work_hs; | |
1218 | struct lpfc_sli_ring *pring; | |
1219 | struct lpfc_sli *psli = &phba->sli; | |
1220 | ||
f4b4c68f JS |
1221 | /* If the pci channel is offline, ignore possible errors, |
1222 | * since we cannot communicate with the pci card anyway. | |
1223 | */ | |
1224 | if (pci_channel_offline(phba->pcidev)) { | |
1225 | spin_lock_irq(&phba->hbalock); | |
1226 | phba->hba_flag &= ~DEFER_ERATT; | |
1227 | spin_unlock_irq(&phba->hbalock); | |
1228 | return; | |
1229 | } | |
1230 | ||
a257bf90 JS |
1231 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
1232 | "0479 Deferred Adapter Hardware Error " | |
1233 | "Data: x%x x%x x%x\n", | |
1234 | phba->work_hs, | |
1235 | phba->work_status[0], phba->work_status[1]); | |
1236 | ||
1237 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1238 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
a257bf90 JS |
1239 | spin_unlock_irq(&phba->hbalock); |
1240 | ||
1241 | ||
1242 | /* | |
1243 | * Firmware stops when it triggred erratt. That could cause the I/Os | |
1244 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the | |
1245 | * SCSI layer retry it after re-establishing link. | |
1246 | */ | |
1247 | pring = &psli->ring[psli->fcp_ring]; | |
1248 | lpfc_sli_abort_iocb_ring(phba, pring); | |
1249 | ||
1250 | /* | |
1251 | * There was a firmware error. Take the hba offline and then | |
1252 | * attempt to restart it. | |
1253 | */ | |
1254 | lpfc_offline_prep(phba); | |
1255 | lpfc_offline(phba); | |
1256 | ||
1257 | /* Wait for the ER1 bit to clear.*/ | |
1258 | while (phba->work_hs & HS_FFER1) { | |
1259 | msleep(100); | |
9940b97b JS |
1260 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
1261 | phba->work_hs = UNPLUG_ERR ; | |
1262 | break; | |
1263 | } | |
a257bf90 JS |
1264 | /* If driver is unloading let the worker thread continue */ |
1265 | if (phba->pport->load_flag & FC_UNLOADING) { | |
1266 | phba->work_hs = 0; | |
1267 | break; | |
1268 | } | |
1269 | } | |
1270 | ||
1271 | /* | |
1272 | * This is to ptrotect against a race condition in which | |
1273 | * first write to the host attention register clear the | |
1274 | * host status register. | |
1275 | */ | |
1276 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) | |
1277 | phba->work_hs = old_host_status & ~HS_FFER1; | |
1278 | ||
3772a991 | 1279 | spin_lock_irq(&phba->hbalock); |
a257bf90 | 1280 | phba->hba_flag &= ~DEFER_ERATT; |
3772a991 | 1281 | spin_unlock_irq(&phba->hbalock); |
a257bf90 JS |
1282 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
1283 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); | |
1284 | } | |
1285 | ||
3772a991 JS |
1286 | static void |
1287 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) | |
1288 | { | |
1289 | struct lpfc_board_event_header board_event; | |
1290 | struct Scsi_Host *shost; | |
1291 | ||
1292 | board_event.event_type = FC_REG_BOARD_EVENT; | |
1293 | board_event.subcategory = LPFC_EVENT_PORTINTERR; | |
1294 | shost = lpfc_shost_from_vport(phba->pport); | |
1295 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1296 | sizeof(board_event), | |
1297 | (char *) &board_event, | |
1298 | LPFC_NL_VENDOR_ID); | |
1299 | } | |
1300 | ||
e59058c4 | 1301 | /** |
3772a991 | 1302 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
e59058c4 JS |
1303 | * @phba: pointer to lpfc hba data structure. |
1304 | * | |
1305 | * This routine is invoked to handle the following HBA hardware error | |
1306 | * conditions: | |
1307 | * 1 - HBA error attention interrupt | |
1308 | * 2 - DMA ring index out of range | |
1309 | * 3 - Mailbox command came back as unknown | |
1310 | **/ | |
3772a991 JS |
1311 | static void |
1312 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) | |
dea3101e | 1313 | { |
2e0fef85 | 1314 | struct lpfc_vport *vport = phba->pport; |
2e0fef85 | 1315 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 1316 | struct lpfc_sli_ring *pring; |
d2873e4c | 1317 | uint32_t event_data; |
57127f15 JS |
1318 | unsigned long temperature; |
1319 | struct temp_event temp_event_data; | |
92d7f7b0 | 1320 | struct Scsi_Host *shost; |
2e0fef85 | 1321 | |
8d63f375 | 1322 | /* If the pci channel is offline, ignore possible errors, |
3772a991 JS |
1323 | * since we cannot communicate with the pci card anyway. |
1324 | */ | |
1325 | if (pci_channel_offline(phba->pcidev)) { | |
1326 | spin_lock_irq(&phba->hbalock); | |
1327 | phba->hba_flag &= ~DEFER_ERATT; | |
1328 | spin_unlock_irq(&phba->hbalock); | |
8d63f375 | 1329 | return; |
3772a991 JS |
1330 | } |
1331 | ||
13815c83 JS |
1332 | /* If resets are disabled then leave the HBA alone and return */ |
1333 | if (!phba->cfg_enable_hba_reset) | |
1334 | return; | |
dea3101e | 1335 | |
ea2151b4 | 1336 | /* Send an internal error event to mgmt application */ |
3772a991 | 1337 | lpfc_board_errevt_to_mgmt(phba); |
ea2151b4 | 1338 | |
a257bf90 JS |
1339 | if (phba->hba_flag & DEFER_ERATT) |
1340 | lpfc_handle_deferred_eratt(phba); | |
1341 | ||
dcf2a4e0 JS |
1342 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
1343 | if (phba->work_hs & HS_FFER6) | |
1344 | /* Re-establishing Link */ | |
1345 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
1346 | "1301 Re-establishing Link " | |
1347 | "Data: x%x x%x x%x\n", | |
1348 | phba->work_hs, phba->work_status[0], | |
1349 | phba->work_status[1]); | |
1350 | if (phba->work_hs & HS_FFER8) | |
1351 | /* Device Zeroization */ | |
1352 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
1353 | "2861 Host Authentication device " | |
1354 | "zeroization Data:x%x x%x x%x\n", | |
1355 | phba->work_hs, phba->work_status[0], | |
1356 | phba->work_status[1]); | |
58da1ffb | 1357 | |
92d7f7b0 | 1358 | spin_lock_irq(&phba->hbalock); |
f4b4c68f | 1359 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
92d7f7b0 | 1360 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1361 | |
1362 | /* | |
1363 | * Firmware stops when it triggled erratt with HS_FFER6. | |
1364 | * That could cause the I/Os dropped by the firmware. | |
1365 | * Error iocb (I/O) on txcmplq and let the SCSI layer | |
1366 | * retry it after re-establishing link. | |
1367 | */ | |
1368 | pring = &psli->ring[psli->fcp_ring]; | |
1369 | lpfc_sli_abort_iocb_ring(phba, pring); | |
1370 | ||
dea3101e JB |
1371 | /* |
1372 | * There was a firmware error. Take the hba offline and then | |
1373 | * attempt to restart it. | |
1374 | */ | |
46fa311e | 1375 | lpfc_offline_prep(phba); |
dea3101e | 1376 | lpfc_offline(phba); |
41415862 | 1377 | lpfc_sli_brdrestart(phba); |
dea3101e | 1378 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
46fa311e | 1379 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
1380 | return; |
1381 | } | |
46fa311e | 1382 | lpfc_unblock_mgmt_io(phba); |
57127f15 JS |
1383 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
1384 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); | |
1385 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
1386 | temp_event_data.event_code = LPFC_CRIT_TEMP; | |
1387 | temp_event_data.data = (uint32_t)temperature; | |
1388 | ||
1389 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 1390 | "0406 Adapter maximum temperature exceeded " |
57127f15 JS |
1391 | "(%ld), taking this port offline " |
1392 | "Data: x%x x%x x%x\n", | |
1393 | temperature, phba->work_hs, | |
1394 | phba->work_status[0], phba->work_status[1]); | |
1395 | ||
1396 | shost = lpfc_shost_from_vport(phba->pport); | |
1397 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1398 | sizeof(temp_event_data), | |
1399 | (char *) &temp_event_data, | |
1400 | SCSI_NL_VID_TYPE_PCI | |
1401 | | PCI_VENDOR_ID_EMULEX); | |
1402 | ||
7af67051 | 1403 | spin_lock_irq(&phba->hbalock); |
7af67051 JS |
1404 | phba->over_temp_state = HBA_OVER_TEMP; |
1405 | spin_unlock_irq(&phba->hbalock); | |
09372820 | 1406 | lpfc_offline_eratt(phba); |
57127f15 | 1407 | |
dea3101e JB |
1408 | } else { |
1409 | /* The if clause above forces this code path when the status | |
9399627f JS |
1410 | * failure is a value other than FFER6. Do not call the offline |
1411 | * twice. This is the adapter hardware error path. | |
dea3101e JB |
1412 | */ |
1413 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 | 1414 | "0457 Adapter Hardware Error " |
dea3101e | 1415 | "Data: x%x x%x x%x\n", |
e8b62011 | 1416 | phba->work_hs, |
dea3101e JB |
1417 | phba->work_status[0], phba->work_status[1]); |
1418 | ||
d2873e4c | 1419 | event_data = FC_REG_DUMP_EVENT; |
92d7f7b0 | 1420 | shost = lpfc_shost_from_vport(vport); |
2e0fef85 | 1421 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
d2873e4c JS |
1422 | sizeof(event_data), (char *) &event_data, |
1423 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
1424 | ||
09372820 | 1425 | lpfc_offline_eratt(phba); |
dea3101e | 1426 | } |
9399627f | 1427 | return; |
dea3101e JB |
1428 | } |
1429 | ||
da0436e9 JS |
1430 | /** |
1431 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler | |
1432 | * @phba: pointer to lpfc hba data structure. | |
1433 | * | |
1434 | * This routine is invoked to handle the SLI4 HBA hardware error attention | |
1435 | * conditions. | |
1436 | **/ | |
1437 | static void | |
1438 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) | |
1439 | { | |
1440 | struct lpfc_vport *vport = phba->pport; | |
1441 | uint32_t event_data; | |
1442 | struct Scsi_Host *shost; | |
2fcee4bf | 1443 | uint32_t if_type; |
2e90f4b5 JS |
1444 | struct lpfc_register portstat_reg = {0}; |
1445 | uint32_t reg_err1, reg_err2; | |
1446 | uint32_t uerrlo_reg, uemasklo_reg; | |
1447 | uint32_t pci_rd_rc1, pci_rd_rc2; | |
73d91e50 | 1448 | int rc; |
da0436e9 JS |
1449 | |
1450 | /* If the pci channel is offline, ignore possible errors, since | |
1451 | * we cannot communicate with the pci card anyway. | |
1452 | */ | |
1453 | if (pci_channel_offline(phba->pcidev)) | |
1454 | return; | |
1455 | /* If resets are disabled then leave the HBA alone and return */ | |
1456 | if (!phba->cfg_enable_hba_reset) | |
1457 | return; | |
1458 | ||
2fcee4bf JS |
1459 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
1460 | switch (if_type) { | |
1461 | case LPFC_SLI_INTF_IF_TYPE_0: | |
2e90f4b5 JS |
1462 | pci_rd_rc1 = lpfc_readl( |
1463 | phba->sli4_hba.u.if_type0.UERRLOregaddr, | |
1464 | &uerrlo_reg); | |
1465 | pci_rd_rc2 = lpfc_readl( | |
1466 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, | |
1467 | &uemasklo_reg); | |
1468 | /* consider PCI bus read error as pci_channel_offline */ | |
1469 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) | |
1470 | return; | |
2fcee4bf JS |
1471 | lpfc_sli4_offline_eratt(phba); |
1472 | break; | |
1473 | case LPFC_SLI_INTF_IF_TYPE_2: | |
2e90f4b5 JS |
1474 | pci_rd_rc1 = lpfc_readl( |
1475 | phba->sli4_hba.u.if_type2.STATUSregaddr, | |
1476 | &portstat_reg.word0); | |
1477 | /* consider PCI bus read error as pci_channel_offline */ | |
6b5151fd JS |
1478 | if (pci_rd_rc1 == -EIO) { |
1479 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1480 | "3151 PCI bus read access failure: x%x\n", | |
1481 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); | |
2e90f4b5 | 1482 | return; |
6b5151fd | 1483 | } |
2e90f4b5 JS |
1484 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
1485 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); | |
2fcee4bf JS |
1486 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
1487 | /* TODO: Register for Overtemp async events. */ | |
1488 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1489 | "2889 Port Overtemperature event, " | |
026abb87 | 1490 | "taking port offline\n"); |
2fcee4bf JS |
1491 | spin_lock_irq(&phba->hbalock); |
1492 | phba->over_temp_state = HBA_OVER_TEMP; | |
1493 | spin_unlock_irq(&phba->hbalock); | |
1494 | lpfc_sli4_offline_eratt(phba); | |
2e90f4b5 | 1495 | break; |
2fcee4bf | 1496 | } |
2e90f4b5 JS |
1497 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
1498 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) | |
1499 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1500 | "3143 Port Down: Firmware Restarted\n"); | |
1501 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && | |
1502 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) | |
1503 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1504 | "3144 Port Down: Debug Dump\n"); | |
1505 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && | |
1506 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) | |
1507 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1508 | "3145 Port Down: Provisioning\n"); | |
73d91e50 JS |
1509 | /* |
1510 | * On error status condition, driver need to wait for port | |
1511 | * ready before performing reset. | |
1512 | */ | |
1513 | rc = lpfc_sli4_pdev_status_reg_wait(phba); | |
1514 | if (!rc) { | |
079b5c91 | 1515 | /* need reset: attempt for port recovery */ |
2fcee4bf | 1516 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2e90f4b5 JS |
1517 | "2887 Reset Needed: Attempting Port " |
1518 | "Recovery...\n"); | |
079b5c91 JS |
1519 | lpfc_offline_prep(phba); |
1520 | lpfc_offline(phba); | |
1521 | lpfc_sli_brdrestart(phba); | |
1522 | if (lpfc_online(phba) == 0) { | |
1523 | lpfc_unblock_mgmt_io(phba); | |
2e90f4b5 JS |
1524 | /* don't report event on forced debug dump */ |
1525 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && | |
1526 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) | |
1527 | return; | |
1528 | else | |
1529 | break; | |
079b5c91 JS |
1530 | } |
1531 | /* fall through for not able to recover */ | |
2fcee4bf | 1532 | } |
6b5151fd JS |
1533 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
1534 | "3152 Unrecoverable error, bring the port " | |
1535 | "offline\n"); | |
2fcee4bf JS |
1536 | lpfc_sli4_offline_eratt(phba); |
1537 | break; | |
1538 | case LPFC_SLI_INTF_IF_TYPE_1: | |
1539 | default: | |
1540 | break; | |
1541 | } | |
2e90f4b5 JS |
1542 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
1543 | "3123 Report dump event to upper layer\n"); | |
1544 | /* Send an internal error event to mgmt application */ | |
1545 | lpfc_board_errevt_to_mgmt(phba); | |
1546 | ||
1547 | event_data = FC_REG_DUMP_EVENT; | |
1548 | shost = lpfc_shost_from_vport(vport); | |
1549 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1550 | sizeof(event_data), (char *) &event_data, | |
1551 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
da0436e9 JS |
1552 | } |
1553 | ||
1554 | /** | |
1555 | * lpfc_handle_eratt - Wrapper func for handling hba error attention | |
1556 | * @phba: pointer to lpfc HBA data structure. | |
1557 | * | |
1558 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling | |
1559 | * routine from the API jump table function pointer from the lpfc_hba struct. | |
1560 | * | |
1561 | * Return codes | |
af901ca1 | 1562 | * 0 - success. |
da0436e9 JS |
1563 | * Any other value - error. |
1564 | **/ | |
1565 | void | |
1566 | lpfc_handle_eratt(struct lpfc_hba *phba) | |
1567 | { | |
1568 | (*phba->lpfc_handle_eratt)(phba); | |
1569 | } | |
1570 | ||
e59058c4 | 1571 | /** |
3621a710 | 1572 | * lpfc_handle_latt - The HBA link event handler |
e59058c4 JS |
1573 | * @phba: pointer to lpfc hba data structure. |
1574 | * | |
1575 | * This routine is invoked from the worker thread to handle a HBA host | |
1576 | * attention link event. | |
1577 | **/ | |
dea3101e | 1578 | void |
2e0fef85 | 1579 | lpfc_handle_latt(struct lpfc_hba *phba) |
dea3101e | 1580 | { |
2e0fef85 JS |
1581 | struct lpfc_vport *vport = phba->pport; |
1582 | struct lpfc_sli *psli = &phba->sli; | |
dea3101e JB |
1583 | LPFC_MBOXQ_t *pmb; |
1584 | volatile uint32_t control; | |
1585 | struct lpfc_dmabuf *mp; | |
09372820 | 1586 | int rc = 0; |
dea3101e JB |
1587 | |
1588 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
09372820 JS |
1589 | if (!pmb) { |
1590 | rc = 1; | |
dea3101e | 1591 | goto lpfc_handle_latt_err_exit; |
09372820 | 1592 | } |
dea3101e JB |
1593 | |
1594 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
09372820 JS |
1595 | if (!mp) { |
1596 | rc = 2; | |
dea3101e | 1597 | goto lpfc_handle_latt_free_pmb; |
09372820 | 1598 | } |
dea3101e JB |
1599 | |
1600 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
09372820 JS |
1601 | if (!mp->virt) { |
1602 | rc = 3; | |
dea3101e | 1603 | goto lpfc_handle_latt_free_mp; |
09372820 | 1604 | } |
dea3101e | 1605 | |
6281bfe0 | 1606 | /* Cleanup any outstanding ELS commands */ |
549e55cd | 1607 | lpfc_els_flush_all_cmd(phba); |
dea3101e JB |
1608 | |
1609 | psli->slistat.link_event++; | |
76a95d75 JS |
1610 | lpfc_read_topology(phba, pmb, mp); |
1611 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
2e0fef85 | 1612 | pmb->vport = vport; |
0d2b6b83 JS |
1613 | /* Block ELS IOCBs until we have processed this mbox command */ |
1614 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
0b727fea | 1615 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
09372820 JS |
1616 | if (rc == MBX_NOT_FINISHED) { |
1617 | rc = 4; | |
14691150 | 1618 | goto lpfc_handle_latt_free_mbuf; |
09372820 | 1619 | } |
dea3101e JB |
1620 | |
1621 | /* Clear Link Attention in HA REG */ | |
2e0fef85 | 1622 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1623 | writel(HA_LATT, phba->HAregaddr); |
1624 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1625 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1626 | |
1627 | return; | |
1628 | ||
14691150 | 1629 | lpfc_handle_latt_free_mbuf: |
0d2b6b83 | 1630 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
14691150 | 1631 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
dea3101e JB |
1632 | lpfc_handle_latt_free_mp: |
1633 | kfree(mp); | |
1634 | lpfc_handle_latt_free_pmb: | |
1dcb58e5 | 1635 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e JB |
1636 | lpfc_handle_latt_err_exit: |
1637 | /* Enable Link attention interrupts */ | |
2e0fef85 | 1638 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1639 | psli->sli_flag |= LPFC_PROCESS_LA; |
1640 | control = readl(phba->HCregaddr); | |
1641 | control |= HC_LAINT_ENA; | |
1642 | writel(control, phba->HCregaddr); | |
1643 | readl(phba->HCregaddr); /* flush */ | |
1644 | ||
1645 | /* Clear Link Attention in HA REG */ | |
1646 | writel(HA_LATT, phba->HAregaddr); | |
1647 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1648 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1649 | lpfc_linkdown(phba); |
2e0fef85 | 1650 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 1651 | |
09372820 JS |
1652 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
1653 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); | |
dea3101e JB |
1654 | |
1655 | return; | |
1656 | } | |
1657 | ||
e59058c4 | 1658 | /** |
3621a710 | 1659 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
e59058c4 JS |
1660 | * @phba: pointer to lpfc hba data structure. |
1661 | * @vpd: pointer to the vital product data. | |
1662 | * @len: length of the vital product data in bytes. | |
1663 | * | |
1664 | * This routine parses the Vital Product Data (VPD). The VPD is treated as | |
1665 | * an array of characters. In this routine, the ModelName, ProgramType, and | |
1666 | * ModelDesc, etc. fields of the phba data structure will be populated. | |
1667 | * | |
1668 | * Return codes | |
1669 | * 0 - pointer to the VPD passed in is NULL | |
1670 | * 1 - success | |
1671 | **/ | |
3772a991 | 1672 | int |
2e0fef85 | 1673 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
dea3101e JB |
1674 | { |
1675 | uint8_t lenlo, lenhi; | |
07da60c1 | 1676 | int Length; |
dea3101e JB |
1677 | int i, j; |
1678 | int finished = 0; | |
1679 | int index = 0; | |
1680 | ||
1681 | if (!vpd) | |
1682 | return 0; | |
1683 | ||
1684 | /* Vital Product */ | |
ed957684 | 1685 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
e8b62011 | 1686 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
dea3101e JB |
1687 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
1688 | (uint32_t) vpd[3]); | |
74b72a59 | 1689 | while (!finished && (index < (len - 4))) { |
dea3101e JB |
1690 | switch (vpd[index]) { |
1691 | case 0x82: | |
74b72a59 | 1692 | case 0x91: |
dea3101e JB |
1693 | index += 1; |
1694 | lenlo = vpd[index]; | |
1695 | index += 1; | |
1696 | lenhi = vpd[index]; | |
1697 | index += 1; | |
1698 | i = ((((unsigned short)lenhi) << 8) + lenlo); | |
1699 | index += i; | |
1700 | break; | |
1701 | case 0x90: | |
1702 | index += 1; | |
1703 | lenlo = vpd[index]; | |
1704 | index += 1; | |
1705 | lenhi = vpd[index]; | |
1706 | index += 1; | |
1707 | Length = ((((unsigned short)lenhi) << 8) + lenlo); | |
74b72a59 JW |
1708 | if (Length > len - index) |
1709 | Length = len - index; | |
dea3101e JB |
1710 | while (Length > 0) { |
1711 | /* Look for Serial Number */ | |
1712 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { | |
1713 | index += 2; | |
1714 | i = vpd[index]; | |
1715 | index += 1; | |
1716 | j = 0; | |
1717 | Length -= (3+i); | |
1718 | while(i--) { | |
1719 | phba->SerialNumber[j++] = vpd[index++]; | |
1720 | if (j == 31) | |
1721 | break; | |
1722 | } | |
1723 | phba->SerialNumber[j] = 0; | |
1724 | continue; | |
1725 | } | |
1726 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { | |
1727 | phba->vpd_flag |= VPD_MODEL_DESC; | |
1728 | index += 2; | |
1729 | i = vpd[index]; | |
1730 | index += 1; | |
1731 | j = 0; | |
1732 | Length -= (3+i); | |
1733 | while(i--) { | |
1734 | phba->ModelDesc[j++] = vpd[index++]; | |
1735 | if (j == 255) | |
1736 | break; | |
1737 | } | |
1738 | phba->ModelDesc[j] = 0; | |
1739 | continue; | |
1740 | } | |
1741 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { | |
1742 | phba->vpd_flag |= VPD_MODEL_NAME; | |
1743 | index += 2; | |
1744 | i = vpd[index]; | |
1745 | index += 1; | |
1746 | j = 0; | |
1747 | Length -= (3+i); | |
1748 | while(i--) { | |
1749 | phba->ModelName[j++] = vpd[index++]; | |
1750 | if (j == 79) | |
1751 | break; | |
1752 | } | |
1753 | phba->ModelName[j] = 0; | |
1754 | continue; | |
1755 | } | |
1756 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { | |
1757 | phba->vpd_flag |= VPD_PROGRAM_TYPE; | |
1758 | index += 2; | |
1759 | i = vpd[index]; | |
1760 | index += 1; | |
1761 | j = 0; | |
1762 | Length -= (3+i); | |
1763 | while(i--) { | |
1764 | phba->ProgramType[j++] = vpd[index++]; | |
1765 | if (j == 255) | |
1766 | break; | |
1767 | } | |
1768 | phba->ProgramType[j] = 0; | |
1769 | continue; | |
1770 | } | |
1771 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { | |
1772 | phba->vpd_flag |= VPD_PORT; | |
1773 | index += 2; | |
1774 | i = vpd[index]; | |
1775 | index += 1; | |
1776 | j = 0; | |
1777 | Length -= (3+i); | |
1778 | while(i--) { | |
cd1c8301 JS |
1779 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
1780 | (phba->sli4_hba.pport_name_sta == | |
1781 | LPFC_SLI4_PPNAME_GET)) { | |
1782 | j++; | |
1783 | index++; | |
1784 | } else | |
1785 | phba->Port[j++] = vpd[index++]; | |
1786 | if (j == 19) | |
1787 | break; | |
dea3101e | 1788 | } |
cd1c8301 JS |
1789 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
1790 | (phba->sli4_hba.pport_name_sta == | |
1791 | LPFC_SLI4_PPNAME_NON)) | |
1792 | phba->Port[j] = 0; | |
dea3101e JB |
1793 | continue; |
1794 | } | |
1795 | else { | |
1796 | index += 2; | |
1797 | i = vpd[index]; | |
1798 | index += 1; | |
1799 | index += i; | |
1800 | Length -= (3 + i); | |
1801 | } | |
1802 | } | |
1803 | finished = 0; | |
1804 | break; | |
1805 | case 0x78: | |
1806 | finished = 1; | |
1807 | break; | |
1808 | default: | |
1809 | index ++; | |
1810 | break; | |
1811 | } | |
74b72a59 | 1812 | } |
dea3101e JB |
1813 | |
1814 | return(1); | |
1815 | } | |
1816 | ||
e59058c4 | 1817 | /** |
3621a710 | 1818 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
e59058c4 JS |
1819 | * @phba: pointer to lpfc hba data structure. |
1820 | * @mdp: pointer to the data structure to hold the derived model name. | |
1821 | * @descp: pointer to the data structure to hold the derived description. | |
1822 | * | |
1823 | * This routine retrieves HBA's description based on its registered PCI device | |
1824 | * ID. The @descp passed into this function points to an array of 256 chars. It | |
1825 | * shall be returned with the model name, maximum speed, and the host bus type. | |
1826 | * The @mdp passed into this function points to an array of 80 chars. When the | |
1827 | * function returns, the @mdp will be filled with the model name. | |
1828 | **/ | |
dea3101e | 1829 | static void |
2e0fef85 | 1830 | lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) |
dea3101e JB |
1831 | { |
1832 | lpfc_vpd_t *vp; | |
fefcb2b6 | 1833 | uint16_t dev_id = phba->pcidev->device; |
74b72a59 | 1834 | int max_speed; |
84774a4d | 1835 | int GE = 0; |
da0436e9 | 1836 | int oneConnect = 0; /* default is not a oneConnect */ |
74b72a59 | 1837 | struct { |
a747c9ce JS |
1838 | char *name; |
1839 | char *bus; | |
1840 | char *function; | |
1841 | } m = {"<Unknown>", "", ""}; | |
74b72a59 JW |
1842 | |
1843 | if (mdp && mdp[0] != '\0' | |
1844 | && descp && descp[0] != '\0') | |
1845 | return; | |
1846 | ||
c0c11512 JS |
1847 | if (phba->lmt & LMT_16Gb) |
1848 | max_speed = 16; | |
1849 | else if (phba->lmt & LMT_10Gb) | |
74b72a59 JW |
1850 | max_speed = 10; |
1851 | else if (phba->lmt & LMT_8Gb) | |
1852 | max_speed = 8; | |
1853 | else if (phba->lmt & LMT_4Gb) | |
1854 | max_speed = 4; | |
1855 | else if (phba->lmt & LMT_2Gb) | |
1856 | max_speed = 2; | |
1857 | else | |
1858 | max_speed = 1; | |
dea3101e JB |
1859 | |
1860 | vp = &phba->vpd; | |
dea3101e | 1861 | |
e4adb204 | 1862 | switch (dev_id) { |
06325e74 | 1863 | case PCI_DEVICE_ID_FIREFLY: |
a747c9ce | 1864 | m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"}; |
06325e74 | 1865 | break; |
dea3101e JB |
1866 | case PCI_DEVICE_ID_SUPERFLY: |
1867 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) | |
a747c9ce JS |
1868 | m = (typeof(m)){"LP7000", "PCI", |
1869 | "Fibre Channel Adapter"}; | |
dea3101e | 1870 | else |
a747c9ce JS |
1871 | m = (typeof(m)){"LP7000E", "PCI", |
1872 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1873 | break; |
1874 | case PCI_DEVICE_ID_DRAGONFLY: | |
a747c9ce JS |
1875 | m = (typeof(m)){"LP8000", "PCI", |
1876 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1877 | break; |
1878 | case PCI_DEVICE_ID_CENTAUR: | |
1879 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) | |
a747c9ce JS |
1880 | m = (typeof(m)){"LP9002", "PCI", |
1881 | "Fibre Channel Adapter"}; | |
dea3101e | 1882 | else |
a747c9ce JS |
1883 | m = (typeof(m)){"LP9000", "PCI", |
1884 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1885 | break; |
1886 | case PCI_DEVICE_ID_RFLY: | |
a747c9ce JS |
1887 | m = (typeof(m)){"LP952", "PCI", |
1888 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1889 | break; |
1890 | case PCI_DEVICE_ID_PEGASUS: | |
a747c9ce JS |
1891 | m = (typeof(m)){"LP9802", "PCI-X", |
1892 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1893 | break; |
1894 | case PCI_DEVICE_ID_THOR: | |
a747c9ce JS |
1895 | m = (typeof(m)){"LP10000", "PCI-X", |
1896 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1897 | break; |
1898 | case PCI_DEVICE_ID_VIPER: | |
a747c9ce JS |
1899 | m = (typeof(m)){"LPX1000", "PCI-X", |
1900 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1901 | break; |
1902 | case PCI_DEVICE_ID_PFLY: | |
a747c9ce JS |
1903 | m = (typeof(m)){"LP982", "PCI-X", |
1904 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1905 | break; |
1906 | case PCI_DEVICE_ID_TFLY: | |
a747c9ce JS |
1907 | m = (typeof(m)){"LP1050", "PCI-X", |
1908 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1909 | break; |
1910 | case PCI_DEVICE_ID_HELIOS: | |
a747c9ce JS |
1911 | m = (typeof(m)){"LP11000", "PCI-X2", |
1912 | "Fibre Channel Adapter"}; | |
dea3101e | 1913 | break; |
e4adb204 | 1914 | case PCI_DEVICE_ID_HELIOS_SCSP: |
a747c9ce JS |
1915 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
1916 | "Fibre Channel Adapter"}; | |
e4adb204 JSEC |
1917 | break; |
1918 | case PCI_DEVICE_ID_HELIOS_DCSP: | |
a747c9ce JS |
1919 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
1920 | "Fibre Channel Adapter"}; | |
e4adb204 JSEC |
1921 | break; |
1922 | case PCI_DEVICE_ID_NEPTUNE: | |
a747c9ce | 1923 | m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1924 | break; |
1925 | case PCI_DEVICE_ID_NEPTUNE_SCSP: | |
a747c9ce | 1926 | m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1927 | break; |
1928 | case PCI_DEVICE_ID_NEPTUNE_DCSP: | |
a747c9ce | 1929 | m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 | 1930 | break; |
dea3101e | 1931 | case PCI_DEVICE_ID_BMID: |
a747c9ce | 1932 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
dea3101e JB |
1933 | break; |
1934 | case PCI_DEVICE_ID_BSMB: | |
a747c9ce | 1935 | m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"}; |
dea3101e JB |
1936 | break; |
1937 | case PCI_DEVICE_ID_ZEPHYR: | |
a747c9ce | 1938 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
dea3101e | 1939 | break; |
e4adb204 | 1940 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
a747c9ce | 1941 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1942 | break; |
1943 | case PCI_DEVICE_ID_ZEPHYR_DCSP: | |
a747c9ce | 1944 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
a257bf90 | 1945 | GE = 1; |
e4adb204 | 1946 | break; |
dea3101e | 1947 | case PCI_DEVICE_ID_ZMID: |
a747c9ce | 1948 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
dea3101e JB |
1949 | break; |
1950 | case PCI_DEVICE_ID_ZSMB: | |
a747c9ce | 1951 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
dea3101e JB |
1952 | break; |
1953 | case PCI_DEVICE_ID_LP101: | |
a747c9ce | 1954 | m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"}; |
dea3101e JB |
1955 | break; |
1956 | case PCI_DEVICE_ID_LP10000S: | |
a747c9ce | 1957 | m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"}; |
06325e74 | 1958 | break; |
e4adb204 | 1959 | case PCI_DEVICE_ID_LP11000S: |
a747c9ce | 1960 | m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"}; |
18a3b596 | 1961 | break; |
e4adb204 | 1962 | case PCI_DEVICE_ID_LPE11000S: |
a747c9ce | 1963 | m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"}; |
5cc36b3c | 1964 | break; |
b87eab38 | 1965 | case PCI_DEVICE_ID_SAT: |
a747c9ce | 1966 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1967 | break; |
1968 | case PCI_DEVICE_ID_SAT_MID: | |
a747c9ce | 1969 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1970 | break; |
1971 | case PCI_DEVICE_ID_SAT_SMB: | |
a747c9ce | 1972 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1973 | break; |
1974 | case PCI_DEVICE_ID_SAT_DCSP: | |
a747c9ce | 1975 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1976 | break; |
1977 | case PCI_DEVICE_ID_SAT_SCSP: | |
a747c9ce | 1978 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
1979 | break; |
1980 | case PCI_DEVICE_ID_SAT_S: | |
a747c9ce | 1981 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 | 1982 | break; |
84774a4d | 1983 | case PCI_DEVICE_ID_HORNET: |
a747c9ce | 1984 | m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"}; |
84774a4d JS |
1985 | GE = 1; |
1986 | break; | |
1987 | case PCI_DEVICE_ID_PROTEUS_VF: | |
a747c9ce JS |
1988 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
1989 | "Fibre Channel Adapter"}; | |
84774a4d JS |
1990 | break; |
1991 | case PCI_DEVICE_ID_PROTEUS_PF: | |
a747c9ce JS |
1992 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
1993 | "Fibre Channel Adapter"}; | |
84774a4d JS |
1994 | break; |
1995 | case PCI_DEVICE_ID_PROTEUS_S: | |
a747c9ce JS |
1996 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
1997 | "Fibre Channel Adapter"}; | |
84774a4d | 1998 | break; |
da0436e9 JS |
1999 | case PCI_DEVICE_ID_TIGERSHARK: |
2000 | oneConnect = 1; | |
a747c9ce | 2001 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
da0436e9 | 2002 | break; |
a747c9ce | 2003 | case PCI_DEVICE_ID_TOMCAT: |
6669f9bb | 2004 | oneConnect = 1; |
a747c9ce JS |
2005 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
2006 | break; | |
2007 | case PCI_DEVICE_ID_FALCON: | |
2008 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", | |
2009 | "EmulexSecure Fibre"}; | |
6669f9bb | 2010 | break; |
98fc5dd9 JS |
2011 | case PCI_DEVICE_ID_BALIUS: |
2012 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", | |
2013 | "Fibre Channel Adapter"}; | |
2014 | break; | |
085c647c | 2015 | case PCI_DEVICE_ID_LANCER_FC: |
c0c11512 JS |
2016 | case PCI_DEVICE_ID_LANCER_FC_VF: |
2017 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; | |
085c647c JS |
2018 | break; |
2019 | case PCI_DEVICE_ID_LANCER_FCOE: | |
c0c11512 | 2020 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
085c647c | 2021 | oneConnect = 1; |
079b5c91 | 2022 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
085c647c | 2023 | break; |
5cc36b3c | 2024 | default: |
a747c9ce | 2025 | m = (typeof(m)){"Unknown", "", ""}; |
e4adb204 | 2026 | break; |
dea3101e | 2027 | } |
74b72a59 JW |
2028 | |
2029 | if (mdp && mdp[0] == '\0') | |
2030 | snprintf(mdp, 79,"%s", m.name); | |
c0c11512 JS |
2031 | /* |
2032 | * oneConnect hba requires special processing, they are all initiators | |
da0436e9 JS |
2033 | * and we put the port number on the end |
2034 | */ | |
2035 | if (descp && descp[0] == '\0') { | |
2036 | if (oneConnect) | |
2037 | snprintf(descp, 255, | |
a747c9ce JS |
2038 | "Emulex OneConnect %s, %s Initiator, Port %s", |
2039 | m.name, m.function, | |
da0436e9 JS |
2040 | phba->Port); |
2041 | else | |
2042 | snprintf(descp, 255, | |
2043 | "Emulex %s %d%s %s %s", | |
a747c9ce JS |
2044 | m.name, max_speed, (GE) ? "GE" : "Gb", |
2045 | m.bus, m.function); | |
da0436e9 | 2046 | } |
dea3101e JB |
2047 | } |
2048 | ||
e59058c4 | 2049 | /** |
3621a710 | 2050 | * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring |
e59058c4 JS |
2051 | * @phba: pointer to lpfc hba data structure. |
2052 | * @pring: pointer to a IOCB ring. | |
2053 | * @cnt: the number of IOCBs to be posted to the IOCB ring. | |
2054 | * | |
2055 | * This routine posts a given number of IOCBs with the associated DMA buffer | |
2056 | * descriptors specified by the cnt argument to the given IOCB ring. | |
2057 | * | |
2058 | * Return codes | |
2059 | * The number of IOCBs NOT able to be posted to the IOCB ring. | |
2060 | **/ | |
dea3101e | 2061 | int |
495a714c | 2062 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
dea3101e JB |
2063 | { |
2064 | IOCB_t *icmd; | |
0bd4ca25 | 2065 | struct lpfc_iocbq *iocb; |
dea3101e JB |
2066 | struct lpfc_dmabuf *mp1, *mp2; |
2067 | ||
2068 | cnt += pring->missbufcnt; | |
2069 | ||
2070 | /* While there are buffers to post */ | |
2071 | while (cnt > 0) { | |
2072 | /* Allocate buffer for command iocb */ | |
0bd4ca25 | 2073 | iocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
2074 | if (iocb == NULL) { |
2075 | pring->missbufcnt = cnt; | |
2076 | return cnt; | |
2077 | } | |
dea3101e JB |
2078 | icmd = &iocb->iocb; |
2079 | ||
2080 | /* 2 buffers can be posted per command */ | |
2081 | /* Allocate buffer to post */ | |
2082 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
2083 | if (mp1) | |
98c9ea5c JS |
2084 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
2085 | if (!mp1 || !mp1->virt) { | |
c9475cb0 | 2086 | kfree(mp1); |
604a3e30 | 2087 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
2088 | pring->missbufcnt = cnt; |
2089 | return cnt; | |
2090 | } | |
2091 | ||
2092 | INIT_LIST_HEAD(&mp1->list); | |
2093 | /* Allocate buffer to post */ | |
2094 | if (cnt > 1) { | |
2095 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
2096 | if (mp2) | |
2097 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | |
2098 | &mp2->phys); | |
98c9ea5c | 2099 | if (!mp2 || !mp2->virt) { |
c9475cb0 | 2100 | kfree(mp2); |
dea3101e JB |
2101 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
2102 | kfree(mp1); | |
604a3e30 | 2103 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
2104 | pring->missbufcnt = cnt; |
2105 | return cnt; | |
2106 | } | |
2107 | ||
2108 | INIT_LIST_HEAD(&mp2->list); | |
2109 | } else { | |
2110 | mp2 = NULL; | |
2111 | } | |
2112 | ||
2113 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); | |
2114 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); | |
2115 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; | |
2116 | icmd->ulpBdeCount = 1; | |
2117 | cnt--; | |
2118 | if (mp2) { | |
2119 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); | |
2120 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); | |
2121 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; | |
2122 | cnt--; | |
2123 | icmd->ulpBdeCount = 2; | |
2124 | } | |
2125 | ||
2126 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; | |
2127 | icmd->ulpLe = 1; | |
2128 | ||
3772a991 JS |
2129 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
2130 | IOCB_ERROR) { | |
dea3101e JB |
2131 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
2132 | kfree(mp1); | |
2133 | cnt++; | |
2134 | if (mp2) { | |
2135 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); | |
2136 | kfree(mp2); | |
2137 | cnt++; | |
2138 | } | |
604a3e30 | 2139 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e | 2140 | pring->missbufcnt = cnt; |
dea3101e JB |
2141 | return cnt; |
2142 | } | |
dea3101e | 2143 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
92d7f7b0 | 2144 | if (mp2) |
dea3101e | 2145 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
dea3101e JB |
2146 | } |
2147 | pring->missbufcnt = 0; | |
2148 | return 0; | |
2149 | } | |
2150 | ||
e59058c4 | 2151 | /** |
3621a710 | 2152 | * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring |
e59058c4 JS |
2153 | * @phba: pointer to lpfc hba data structure. |
2154 | * | |
2155 | * This routine posts initial receive IOCB buffers to the ELS ring. The | |
2156 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is | |
2157 | * set to 64 IOCBs. | |
2158 | * | |
2159 | * Return codes | |
2160 | * 0 - success (currently always success) | |
2161 | **/ | |
dea3101e | 2162 | static int |
2e0fef85 | 2163 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
dea3101e JB |
2164 | { |
2165 | struct lpfc_sli *psli = &phba->sli; | |
2166 | ||
2167 | /* Ring 0, ELS / CT buffers */ | |
495a714c | 2168 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
dea3101e JB |
2169 | /* Ring 2 - FCP no buffers needed */ |
2170 | ||
2171 | return 0; | |
2172 | } | |
2173 | ||
2174 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) | |
2175 | ||
e59058c4 | 2176 | /** |
3621a710 | 2177 | * lpfc_sha_init - Set up initial array of hash table entries |
e59058c4 JS |
2178 | * @HashResultPointer: pointer to an array as hash table. |
2179 | * | |
2180 | * This routine sets up the initial values to the array of hash table entries | |
2181 | * for the LC HBAs. | |
2182 | **/ | |
dea3101e JB |
2183 | static void |
2184 | lpfc_sha_init(uint32_t * HashResultPointer) | |
2185 | { | |
2186 | HashResultPointer[0] = 0x67452301; | |
2187 | HashResultPointer[1] = 0xEFCDAB89; | |
2188 | HashResultPointer[2] = 0x98BADCFE; | |
2189 | HashResultPointer[3] = 0x10325476; | |
2190 | HashResultPointer[4] = 0xC3D2E1F0; | |
2191 | } | |
2192 | ||
e59058c4 | 2193 | /** |
3621a710 | 2194 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
e59058c4 JS |
2195 | * @HashResultPointer: pointer to an initial/result hash table. |
2196 | * @HashWorkingPointer: pointer to an working hash table. | |
2197 | * | |
2198 | * This routine iterates an initial hash table pointed by @HashResultPointer | |
2199 | * with the values from the working hash table pointeed by @HashWorkingPointer. | |
2200 | * The results are putting back to the initial hash table, returned through | |
2201 | * the @HashResultPointer as the result hash table. | |
2202 | **/ | |
dea3101e JB |
2203 | static void |
2204 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) | |
2205 | { | |
2206 | int t; | |
2207 | uint32_t TEMP; | |
2208 | uint32_t A, B, C, D, E; | |
2209 | t = 16; | |
2210 | do { | |
2211 | HashWorkingPointer[t] = | |
2212 | S(1, | |
2213 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - | |
2214 | 8] ^ | |
2215 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); | |
2216 | } while (++t <= 79); | |
2217 | t = 0; | |
2218 | A = HashResultPointer[0]; | |
2219 | B = HashResultPointer[1]; | |
2220 | C = HashResultPointer[2]; | |
2221 | D = HashResultPointer[3]; | |
2222 | E = HashResultPointer[4]; | |
2223 | ||
2224 | do { | |
2225 | if (t < 20) { | |
2226 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; | |
2227 | } else if (t < 40) { | |
2228 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; | |
2229 | } else if (t < 60) { | |
2230 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; | |
2231 | } else { | |
2232 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; | |
2233 | } | |
2234 | TEMP += S(5, A) + E + HashWorkingPointer[t]; | |
2235 | E = D; | |
2236 | D = C; | |
2237 | C = S(30, B); | |
2238 | B = A; | |
2239 | A = TEMP; | |
2240 | } while (++t <= 79); | |
2241 | ||
2242 | HashResultPointer[0] += A; | |
2243 | HashResultPointer[1] += B; | |
2244 | HashResultPointer[2] += C; | |
2245 | HashResultPointer[3] += D; | |
2246 | HashResultPointer[4] += E; | |
2247 | ||
2248 | } | |
2249 | ||
e59058c4 | 2250 | /** |
3621a710 | 2251 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
e59058c4 JS |
2252 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
2253 | * @HashWorking: pointer to the entry of the working hash array. | |
2254 | * | |
2255 | * This routine calculates the working hash array referred by @HashWorking | |
2256 | * from the challenge random numbers associated with the host, referred by | |
2257 | * @RandomChallenge. The result is put into the entry of the working hash | |
2258 | * array and returned by reference through @HashWorking. | |
2259 | **/ | |
dea3101e JB |
2260 | static void |
2261 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) | |
2262 | { | |
2263 | *HashWorking = (*RandomChallenge ^ *HashWorking); | |
2264 | } | |
2265 | ||
e59058c4 | 2266 | /** |
3621a710 | 2267 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
e59058c4 JS |
2268 | * @phba: pointer to lpfc hba data structure. |
2269 | * @hbainit: pointer to an array of unsigned 32-bit integers. | |
2270 | * | |
2271 | * This routine performs the special handling for LC HBA initialization. | |
2272 | **/ | |
dea3101e JB |
2273 | void |
2274 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) | |
2275 | { | |
2276 | int t; | |
2277 | uint32_t *HashWorking; | |
2e0fef85 | 2278 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
dea3101e | 2279 | |
bbfbbbc1 | 2280 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
dea3101e JB |
2281 | if (!HashWorking) |
2282 | return; | |
2283 | ||
dea3101e JB |
2284 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
2285 | HashWorking[1] = HashWorking[79] = *pwwnn; | |
2286 | ||
2287 | for (t = 0; t < 7; t++) | |
2288 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); | |
2289 | ||
2290 | lpfc_sha_init(hbainit); | |
2291 | lpfc_sha_iterate(hbainit, HashWorking); | |
2292 | kfree(HashWorking); | |
2293 | } | |
2294 | ||
e59058c4 | 2295 | /** |
3621a710 | 2296 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
e59058c4 JS |
2297 | * @vport: pointer to a virtual N_Port data structure. |
2298 | * | |
2299 | * This routine performs the necessary cleanups before deleting the @vport. | |
2300 | * It invokes the discovery state machine to perform necessary state | |
2301 | * transitions and to release the ndlps associated with the @vport. Note, | |
2302 | * the physical port is treated as @vport 0. | |
2303 | **/ | |
87af33fe | 2304 | void |
2e0fef85 | 2305 | lpfc_cleanup(struct lpfc_vport *vport) |
dea3101e | 2306 | { |
87af33fe | 2307 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2308 | struct lpfc_nodelist *ndlp, *next_ndlp; |
a8adb832 | 2309 | int i = 0; |
dea3101e | 2310 | |
87af33fe JS |
2311 | if (phba->link_state > LPFC_LINK_DOWN) |
2312 | lpfc_port_link_failure(vport); | |
2313 | ||
2314 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
2315 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
2316 | ndlp = lpfc_enable_node(vport, ndlp, | |
2317 | NLP_STE_UNUSED_NODE); | |
2318 | if (!ndlp) | |
2319 | continue; | |
2320 | spin_lock_irq(&phba->ndlp_lock); | |
2321 | NLP_SET_FREE_REQ(ndlp); | |
2322 | spin_unlock_irq(&phba->ndlp_lock); | |
2323 | /* Trigger the release of the ndlp memory */ | |
2324 | lpfc_nlp_put(ndlp); | |
2325 | continue; | |
2326 | } | |
2327 | spin_lock_irq(&phba->ndlp_lock); | |
2328 | if (NLP_CHK_FREE_REQ(ndlp)) { | |
2329 | /* The ndlp should not be in memory free mode already */ | |
2330 | spin_unlock_irq(&phba->ndlp_lock); | |
2331 | continue; | |
2332 | } else | |
2333 | /* Indicate request for freeing ndlp memory */ | |
2334 | NLP_SET_FREE_REQ(ndlp); | |
2335 | spin_unlock_irq(&phba->ndlp_lock); | |
2336 | ||
58da1ffb JS |
2337 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
2338 | ndlp->nlp_DID == Fabric_DID) { | |
2339 | /* Just free up ndlp with Fabric_DID for vports */ | |
2340 | lpfc_nlp_put(ndlp); | |
2341 | continue; | |
2342 | } | |
2343 | ||
87af33fe JS |
2344 | if (ndlp->nlp_type & NLP_FABRIC) |
2345 | lpfc_disc_state_machine(vport, ndlp, NULL, | |
2346 | NLP_EVT_DEVICE_RECOVERY); | |
e47c9093 | 2347 | |
87af33fe JS |
2348 | lpfc_disc_state_machine(vport, ndlp, NULL, |
2349 | NLP_EVT_DEVICE_RM); | |
495a714c | 2350 | |
87af33fe JS |
2351 | } |
2352 | ||
a8adb832 JS |
2353 | /* At this point, ALL ndlp's should be gone |
2354 | * because of the previous NLP_EVT_DEVICE_RM. | |
2355 | * Lets wait for this to happen, if needed. | |
2356 | */ | |
87af33fe | 2357 | while (!list_empty(&vport->fc_nodes)) { |
a8adb832 | 2358 | if (i++ > 3000) { |
87af33fe | 2359 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
a8adb832 | 2360 | "0233 Nodelist not empty\n"); |
e47c9093 JS |
2361 | list_for_each_entry_safe(ndlp, next_ndlp, |
2362 | &vport->fc_nodes, nlp_listp) { | |
2363 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, | |
2364 | LOG_NODE, | |
d7c255b2 | 2365 | "0282 did:x%x ndlp:x%p " |
e47c9093 JS |
2366 | "usgmap:x%x refcnt:%d\n", |
2367 | ndlp->nlp_DID, (void *)ndlp, | |
2368 | ndlp->nlp_usg_map, | |
2369 | atomic_read( | |
2370 | &ndlp->kref.refcount)); | |
2371 | } | |
a8adb832 | 2372 | break; |
87af33fe | 2373 | } |
a8adb832 JS |
2374 | |
2375 | /* Wait for any activity on ndlps to settle */ | |
2376 | msleep(10); | |
87af33fe | 2377 | } |
1151e3ec | 2378 | lpfc_cleanup_vports_rrqs(vport, NULL); |
dea3101e JB |
2379 | } |
2380 | ||
e59058c4 | 2381 | /** |
3621a710 | 2382 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
e59058c4 JS |
2383 | * @vport: pointer to a virtual N_Port data structure. |
2384 | * | |
2385 | * This routine stops all the timers associated with a @vport. This function | |
2386 | * is invoked before disabling or deleting a @vport. Note that the physical | |
2387 | * port is treated as @vport 0. | |
2388 | **/ | |
92d7f7b0 JS |
2389 | void |
2390 | lpfc_stop_vport_timers(struct lpfc_vport *vport) | |
dea3101e | 2391 | { |
92d7f7b0 JS |
2392 | del_timer_sync(&vport->els_tmofunc); |
2393 | del_timer_sync(&vport->fc_fdmitmo); | |
92494144 | 2394 | del_timer_sync(&vport->delayed_disc_tmo); |
92d7f7b0 JS |
2395 | lpfc_can_disctmo(vport); |
2396 | return; | |
dea3101e JB |
2397 | } |
2398 | ||
ecfd03c6 JS |
2399 | /** |
2400 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2401 | * @phba: pointer to lpfc hba data structure. | |
2402 | * | |
2403 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The | |
2404 | * caller of this routine should already hold the host lock. | |
2405 | **/ | |
2406 | void | |
2407 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2408 | { | |
5ac6b303 JS |
2409 | /* Clear pending FCF rediscovery wait flag */ |
2410 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; | |
2411 | ||
ecfd03c6 JS |
2412 | /* Now, try to stop the timer */ |
2413 | del_timer(&phba->fcf.redisc_wait); | |
2414 | } | |
2415 | ||
2416 | /** | |
2417 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2418 | * @phba: pointer to lpfc hba data structure. | |
2419 | * | |
2420 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It | |
2421 | * checks whether the FCF rediscovery wait timer is pending with the host | |
2422 | * lock held before proceeding with disabling the timer and clearing the | |
2423 | * wait timer pendig flag. | |
2424 | **/ | |
2425 | void | |
2426 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2427 | { | |
2428 | spin_lock_irq(&phba->hbalock); | |
2429 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
2430 | /* FCF rediscovery timer already fired or stopped */ | |
2431 | spin_unlock_irq(&phba->hbalock); | |
2432 | return; | |
2433 | } | |
2434 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); | |
5ac6b303 JS |
2435 | /* Clear failover in progress flags */ |
2436 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); | |
ecfd03c6 JS |
2437 | spin_unlock_irq(&phba->hbalock); |
2438 | } | |
2439 | ||
e59058c4 | 2440 | /** |
3772a991 | 2441 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
e59058c4 JS |
2442 | * @phba: pointer to lpfc hba data structure. |
2443 | * | |
2444 | * This routine stops all the timers associated with a HBA. This function is | |
2445 | * invoked before either putting a HBA offline or unloading the driver. | |
2446 | **/ | |
3772a991 JS |
2447 | void |
2448 | lpfc_stop_hba_timers(struct lpfc_hba *phba) | |
dea3101e | 2449 | { |
51ef4c26 | 2450 | lpfc_stop_vport_timers(phba->pport); |
2e0fef85 | 2451 | del_timer_sync(&phba->sli.mbox_tmo); |
92d7f7b0 | 2452 | del_timer_sync(&phba->fabric_block_timer); |
9399627f | 2453 | del_timer_sync(&phba->eratt_poll); |
3772a991 | 2454 | del_timer_sync(&phba->hb_tmofunc); |
1151e3ec JS |
2455 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2456 | del_timer_sync(&phba->rrq_tmr); | |
2457 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
2458 | } | |
3772a991 JS |
2459 | phba->hb_outstanding = 0; |
2460 | ||
2461 | switch (phba->pci_dev_grp) { | |
2462 | case LPFC_PCI_DEV_LP: | |
2463 | /* Stop any LightPulse device specific driver timers */ | |
2464 | del_timer_sync(&phba->fcp_poll_timer); | |
2465 | break; | |
2466 | case LPFC_PCI_DEV_OC: | |
2467 | /* Stop any OneConnect device sepcific driver timers */ | |
ecfd03c6 | 2468 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
3772a991 JS |
2469 | break; |
2470 | default: | |
2471 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2472 | "0297 Invalid device group (x%x)\n", | |
2473 | phba->pci_dev_grp); | |
2474 | break; | |
2475 | } | |
2e0fef85 | 2476 | return; |
dea3101e JB |
2477 | } |
2478 | ||
e59058c4 | 2479 | /** |
3621a710 | 2480 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
e59058c4 JS |
2481 | * @phba: pointer to lpfc hba data structure. |
2482 | * | |
2483 | * This routine marks a HBA's management interface as blocked. Once the HBA's | |
2484 | * management interface is marked as blocked, all the user space access to | |
2485 | * the HBA, whether they are from sysfs interface or libdfc interface will | |
2486 | * all be blocked. The HBA is set to block the management interface when the | |
2487 | * driver prepares the HBA interface for online or offline. | |
2488 | **/ | |
a6ababd2 AB |
2489 | static void |
2490 | lpfc_block_mgmt_io(struct lpfc_hba * phba) | |
2491 | { | |
2492 | unsigned long iflag; | |
6e7288d9 JS |
2493 | uint8_t actcmd = MBX_HEARTBEAT; |
2494 | unsigned long timeout; | |
2495 | ||
a183a15f | 2496 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; |
a6ababd2 AB |
2497 | spin_lock_irqsave(&phba->hbalock, iflag); |
2498 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; | |
a183a15f | 2499 | if (phba->sli.mbox_active) { |
6e7288d9 | 2500 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
a183a15f JS |
2501 | /* Determine how long we might wait for the active mailbox |
2502 | * command to be gracefully completed by firmware. | |
2503 | */ | |
2504 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
2505 | phba->sli.mbox_active) * 1000) + jiffies; | |
2506 | } | |
a6ababd2 | 2507 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a183a15f | 2508 | |
6e7288d9 JS |
2509 | /* Wait for the outstnading mailbox command to complete */ |
2510 | while (phba->sli.mbox_active) { | |
2511 | /* Check active mailbox complete status every 2ms */ | |
2512 | msleep(2); | |
2513 | if (time_after(jiffies, timeout)) { | |
2514 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2515 | "2813 Mgmt IO is Blocked %x " | |
2516 | "- mbox cmd %x still active\n", | |
2517 | phba->sli.sli_flag, actcmd); | |
2518 | break; | |
2519 | } | |
2520 | } | |
a6ababd2 AB |
2521 | } |
2522 | ||
6b5151fd JS |
2523 | /** |
2524 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. | |
2525 | * @phba: pointer to lpfc hba data structure. | |
2526 | * | |
2527 | * Allocate RPIs for all active remote nodes. This is needed whenever | |
2528 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose | |
2529 | * is to fixup the temporary rpi assignments. | |
2530 | **/ | |
2531 | void | |
2532 | lpfc_sli4_node_prep(struct lpfc_hba *phba) | |
2533 | { | |
2534 | struct lpfc_nodelist *ndlp, *next_ndlp; | |
2535 | struct lpfc_vport **vports; | |
2536 | int i; | |
2537 | ||
2538 | if (phba->sli_rev != LPFC_SLI_REV4) | |
2539 | return; | |
2540 | ||
2541 | vports = lpfc_create_vport_work_array(phba); | |
2542 | if (vports != NULL) { | |
2543 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { | |
2544 | if (vports[i]->load_flag & FC_UNLOADING) | |
2545 | continue; | |
2546 | ||
2547 | list_for_each_entry_safe(ndlp, next_ndlp, | |
2548 | &vports[i]->fc_nodes, | |
2549 | nlp_listp) { | |
2550 | if (NLP_CHK_NODE_ACT(ndlp)) | |
2551 | ndlp->nlp_rpi = | |
2552 | lpfc_sli4_alloc_rpi(phba); | |
2553 | } | |
2554 | } | |
2555 | } | |
2556 | lpfc_destroy_vport_work_array(phba, vports); | |
2557 | } | |
2558 | ||
e59058c4 | 2559 | /** |
3621a710 | 2560 | * lpfc_online - Initialize and bring a HBA online |
e59058c4 JS |
2561 | * @phba: pointer to lpfc hba data structure. |
2562 | * | |
2563 | * This routine initializes the HBA and brings a HBA online. During this | |
2564 | * process, the management interface is blocked to prevent user space access | |
2565 | * to the HBA interfering with the driver initialization. | |
2566 | * | |
2567 | * Return codes | |
2568 | * 0 - successful | |
2569 | * 1 - failed | |
2570 | **/ | |
dea3101e | 2571 | int |
2e0fef85 | 2572 | lpfc_online(struct lpfc_hba *phba) |
dea3101e | 2573 | { |
372bd282 | 2574 | struct lpfc_vport *vport; |
549e55cd JS |
2575 | struct lpfc_vport **vports; |
2576 | int i; | |
2e0fef85 | 2577 | |
dea3101e JB |
2578 | if (!phba) |
2579 | return 0; | |
372bd282 | 2580 | vport = phba->pport; |
dea3101e | 2581 | |
2e0fef85 | 2582 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
dea3101e JB |
2583 | return 0; |
2584 | ||
ed957684 | 2585 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 2586 | "0458 Bring Adapter online\n"); |
dea3101e | 2587 | |
46fa311e JS |
2588 | lpfc_block_mgmt_io(phba); |
2589 | ||
2590 | if (!lpfc_sli_queue_setup(phba)) { | |
2591 | lpfc_unblock_mgmt_io(phba); | |
dea3101e | 2592 | return 1; |
46fa311e | 2593 | } |
dea3101e | 2594 | |
da0436e9 JS |
2595 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2596 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ | |
2597 | lpfc_unblock_mgmt_io(phba); | |
2598 | return 1; | |
2599 | } | |
2600 | } else { | |
2601 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ | |
2602 | lpfc_unblock_mgmt_io(phba); | |
2603 | return 1; | |
2604 | } | |
46fa311e | 2605 | } |
dea3101e | 2606 | |
549e55cd JS |
2607 | vports = lpfc_create_vport_work_array(phba); |
2608 | if (vports != NULL) | |
da0436e9 | 2609 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd JS |
2610 | struct Scsi_Host *shost; |
2611 | shost = lpfc_shost_from_vport(vports[i]); | |
2612 | spin_lock_irq(shost->host_lock); | |
2613 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; | |
2614 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) | |
2615 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
1c6834a7 JS |
2616 | if (phba->sli_rev == LPFC_SLI_REV4) |
2617 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; | |
549e55cd JS |
2618 | spin_unlock_irq(shost->host_lock); |
2619 | } | |
09372820 | 2620 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2621 | |
46fa311e | 2622 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
2623 | return 0; |
2624 | } | |
2625 | ||
e59058c4 | 2626 | /** |
3621a710 | 2627 | * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked |
e59058c4 JS |
2628 | * @phba: pointer to lpfc hba data structure. |
2629 | * | |
2630 | * This routine marks a HBA's management interface as not blocked. Once the | |
2631 | * HBA's management interface is marked as not blocked, all the user space | |
2632 | * access to the HBA, whether they are from sysfs interface or libdfc | |
2633 | * interface will be allowed. The HBA is set to block the management interface | |
2634 | * when the driver prepares the HBA interface for online or offline and then | |
2635 | * set to unblock the management interface afterwards. | |
2636 | **/ | |
46fa311e JS |
2637 | void |
2638 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) | |
2639 | { | |
2640 | unsigned long iflag; | |
2641 | ||
2e0fef85 JS |
2642 | spin_lock_irqsave(&phba->hbalock, iflag); |
2643 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; | |
2644 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
46fa311e JS |
2645 | } |
2646 | ||
e59058c4 | 2647 | /** |
3621a710 | 2648 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
e59058c4 JS |
2649 | * @phba: pointer to lpfc hba data structure. |
2650 | * | |
2651 | * This routine is invoked to prepare a HBA to be brought offline. It performs | |
2652 | * unregistration login to all the nodes on all vports and flushes the mailbox | |
2653 | * queue to make it ready to be brought offline. | |
2654 | **/ | |
46fa311e JS |
2655 | void |
2656 | lpfc_offline_prep(struct lpfc_hba * phba) | |
2657 | { | |
2e0fef85 | 2658 | struct lpfc_vport *vport = phba->pport; |
46fa311e | 2659 | struct lpfc_nodelist *ndlp, *next_ndlp; |
87af33fe | 2660 | struct lpfc_vport **vports; |
72100cc4 | 2661 | struct Scsi_Host *shost; |
87af33fe | 2662 | int i; |
dea3101e | 2663 | |
2e0fef85 | 2664 | if (vport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 2665 | return; |
dea3101e | 2666 | |
46fa311e | 2667 | lpfc_block_mgmt_io(phba); |
dea3101e JB |
2668 | |
2669 | lpfc_linkdown(phba); | |
2670 | ||
87af33fe JS |
2671 | /* Issue an unreg_login to all nodes on all vports */ |
2672 | vports = lpfc_create_vport_work_array(phba); | |
2673 | if (vports != NULL) { | |
da0436e9 | 2674 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
a8adb832 JS |
2675 | if (vports[i]->load_flag & FC_UNLOADING) |
2676 | continue; | |
72100cc4 JS |
2677 | shost = lpfc_shost_from_vport(vports[i]); |
2678 | spin_lock_irq(shost->host_lock); | |
c868595d | 2679 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
695a814e JS |
2680 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
2681 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; | |
72100cc4 | 2682 | spin_unlock_irq(shost->host_lock); |
695a814e | 2683 | |
87af33fe JS |
2684 | shost = lpfc_shost_from_vport(vports[i]); |
2685 | list_for_each_entry_safe(ndlp, next_ndlp, | |
2686 | &vports[i]->fc_nodes, | |
2687 | nlp_listp) { | |
e47c9093 JS |
2688 | if (!NLP_CHK_NODE_ACT(ndlp)) |
2689 | continue; | |
87af33fe JS |
2690 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
2691 | continue; | |
2692 | if (ndlp->nlp_type & NLP_FABRIC) { | |
2693 | lpfc_disc_state_machine(vports[i], ndlp, | |
2694 | NULL, NLP_EVT_DEVICE_RECOVERY); | |
2695 | lpfc_disc_state_machine(vports[i], ndlp, | |
2696 | NULL, NLP_EVT_DEVICE_RM); | |
2697 | } | |
2698 | spin_lock_irq(shost->host_lock); | |
2699 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | |
6b5151fd JS |
2700 | |
2701 | /* | |
2702 | * Whenever an SLI4 port goes offline, free the | |
2703 | * RPI. A new RPI when the adapter port comes | |
2704 | * back online. | |
2705 | */ | |
2706 | if (phba->sli_rev == LPFC_SLI_REV4) | |
2707 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); | |
2708 | ||
87af33fe JS |
2709 | spin_unlock_irq(shost->host_lock); |
2710 | lpfc_unreg_rpi(vports[i], ndlp); | |
2711 | } | |
2712 | } | |
2713 | } | |
09372820 | 2714 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2715 | |
04c68496 | 2716 | lpfc_sli_mbox_sys_shutdown(phba); |
46fa311e JS |
2717 | } |
2718 | ||
e59058c4 | 2719 | /** |
3621a710 | 2720 | * lpfc_offline - Bring a HBA offline |
e59058c4 JS |
2721 | * @phba: pointer to lpfc hba data structure. |
2722 | * | |
2723 | * This routine actually brings a HBA offline. It stops all the timers | |
2724 | * associated with the HBA, brings down the SLI layer, and eventually | |
2725 | * marks the HBA as in offline state for the upper layer protocol. | |
2726 | **/ | |
46fa311e | 2727 | void |
2e0fef85 | 2728 | lpfc_offline(struct lpfc_hba *phba) |
46fa311e | 2729 | { |
549e55cd JS |
2730 | struct Scsi_Host *shost; |
2731 | struct lpfc_vport **vports; | |
2732 | int i; | |
46fa311e | 2733 | |
549e55cd | 2734 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 2735 | return; |
688a8863 | 2736 | |
da0436e9 JS |
2737 | /* stop port and all timers associated with this hba */ |
2738 | lpfc_stop_port(phba); | |
51ef4c26 JS |
2739 | vports = lpfc_create_vport_work_array(phba); |
2740 | if (vports != NULL) | |
da0436e9 | 2741 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
51ef4c26 | 2742 | lpfc_stop_vport_timers(vports[i]); |
09372820 | 2743 | lpfc_destroy_vport_work_array(phba, vports); |
92d7f7b0 | 2744 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 2745 | "0460 Bring Adapter offline\n"); |
dea3101e JB |
2746 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
2747 | now. */ | |
2748 | lpfc_sli_hba_down(phba); | |
92d7f7b0 | 2749 | spin_lock_irq(&phba->hbalock); |
7054a606 | 2750 | phba->work_ha = 0; |
92d7f7b0 | 2751 | spin_unlock_irq(&phba->hbalock); |
549e55cd JS |
2752 | vports = lpfc_create_vport_work_array(phba); |
2753 | if (vports != NULL) | |
da0436e9 | 2754 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd | 2755 | shost = lpfc_shost_from_vport(vports[i]); |
549e55cd JS |
2756 | spin_lock_irq(shost->host_lock); |
2757 | vports[i]->work_port_events = 0; | |
2758 | vports[i]->fc_flag |= FC_OFFLINE_MODE; | |
2759 | spin_unlock_irq(shost->host_lock); | |
2760 | } | |
09372820 | 2761 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e JB |
2762 | } |
2763 | ||
ff78d8f9 JS |
2764 | /** |
2765 | * lpfc_scsi_buf_update - Update the scsi_buffers that are already allocated. | |
2766 | * @phba: pointer to lpfc hba data structure. | |
2767 | * | |
2768 | * This routine goes through all the scsi buffers in the system and updates the | |
2769 | * Physical XRIs assigned to the SCSI buffer because these may change after any | |
2770 | * firmware reset | |
2771 | * | |
2772 | * Return codes | |
2773 | * 0 - successful (for now, it always returns 0) | |
2774 | **/ | |
2775 | int | |
2776 | lpfc_scsi_buf_update(struct lpfc_hba *phba) | |
2777 | { | |
2778 | struct lpfc_scsi_buf *sb, *sb_next; | |
2779 | ||
2780 | spin_lock_irq(&phba->hbalock); | |
2781 | spin_lock(&phba->scsi_buf_list_lock); | |
2782 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) | |
2783 | sb->cur_iocbq.sli4_xritag = | |
2784 | phba->sli4_hba.xri_ids[sb->cur_iocbq.sli4_lxritag]; | |
2785 | spin_unlock(&phba->scsi_buf_list_lock); | |
2786 | spin_unlock_irq(&phba->hbalock); | |
2787 | return 0; | |
2788 | } | |
2789 | ||
e59058c4 | 2790 | /** |
3621a710 | 2791 | * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists |
e59058c4 JS |
2792 | * @phba: pointer to lpfc hba data structure. |
2793 | * | |
2794 | * This routine is to free all the SCSI buffers and IOCBs from the driver | |
2795 | * list back to kernel. It is called from lpfc_pci_remove_one to free | |
2796 | * the internal resources before the device is removed from the system. | |
2797 | * | |
2798 | * Return codes | |
2799 | * 0 - successful (for now, it always returns 0) | |
2800 | **/ | |
dea3101e | 2801 | static int |
2e0fef85 | 2802 | lpfc_scsi_free(struct lpfc_hba *phba) |
dea3101e JB |
2803 | { |
2804 | struct lpfc_scsi_buf *sb, *sb_next; | |
2805 | struct lpfc_iocbq *io, *io_next; | |
2806 | ||
2e0fef85 | 2807 | spin_lock_irq(&phba->hbalock); |
dea3101e | 2808 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
1c6f4ef5 | 2809 | spin_lock(&phba->scsi_buf_list_lock); |
dea3101e JB |
2810 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { |
2811 | list_del(&sb->list); | |
2812 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, | |
92d7f7b0 | 2813 | sb->dma_handle); |
dea3101e JB |
2814 | kfree(sb); |
2815 | phba->total_scsi_bufs--; | |
2816 | } | |
1c6f4ef5 | 2817 | spin_unlock(&phba->scsi_buf_list_lock); |
dea3101e JB |
2818 | |
2819 | /* Release all the lpfc_iocbq entries maintained by this host. */ | |
2820 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { | |
2821 | list_del(&io->list); | |
2822 | kfree(io); | |
2823 | phba->total_iocbq_bufs--; | |
2824 | } | |
6d368e53 | 2825 | |
2e0fef85 | 2826 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
2827 | return 0; |
2828 | } | |
2829 | ||
e59058c4 | 2830 | /** |
3621a710 | 2831 | * lpfc_create_port - Create an FC port |
e59058c4 JS |
2832 | * @phba: pointer to lpfc hba data structure. |
2833 | * @instance: a unique integer ID to this FC port. | |
2834 | * @dev: pointer to the device data structure. | |
2835 | * | |
2836 | * This routine creates a FC port for the upper layer protocol. The FC port | |
2837 | * can be created on top of either a physical port or a virtual port provided | |
2838 | * by the HBA. This routine also allocates a SCSI host data structure (shost) | |
2839 | * and associates the FC port created before adding the shost into the SCSI | |
2840 | * layer. | |
2841 | * | |
2842 | * Return codes | |
2843 | * @vport - pointer to the virtual N_Port data structure. | |
2844 | * NULL - port create failed. | |
2845 | **/ | |
2e0fef85 | 2846 | struct lpfc_vport * |
3de2a653 | 2847 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
47a8617c | 2848 | { |
2e0fef85 JS |
2849 | struct lpfc_vport *vport; |
2850 | struct Scsi_Host *shost; | |
2851 | int error = 0; | |
47a8617c | 2852 | |
3de2a653 JS |
2853 | if (dev != &phba->pcidev->dev) |
2854 | shost = scsi_host_alloc(&lpfc_vport_template, | |
2855 | sizeof(struct lpfc_vport)); | |
2856 | else | |
2857 | shost = scsi_host_alloc(&lpfc_template, | |
2858 | sizeof(struct lpfc_vport)); | |
2e0fef85 JS |
2859 | if (!shost) |
2860 | goto out; | |
47a8617c | 2861 | |
2e0fef85 JS |
2862 | vport = (struct lpfc_vport *) shost->hostdata; |
2863 | vport->phba = phba; | |
2e0fef85 | 2864 | vport->load_flag |= FC_LOADING; |
92d7f7b0 | 2865 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
7f5f3d0d | 2866 | vport->fc_rscn_flush = 0; |
47a8617c | 2867 | |
3de2a653 | 2868 | lpfc_get_vport_cfgparam(vport); |
2e0fef85 JS |
2869 | shost->unique_id = instance; |
2870 | shost->max_id = LPFC_MAX_TARGET; | |
3de2a653 | 2871 | shost->max_lun = vport->cfg_max_luns; |
2e0fef85 JS |
2872 | shost->this_id = -1; |
2873 | shost->max_cmd_len = 16; | |
da0436e9 | 2874 | if (phba->sli_rev == LPFC_SLI_REV4) { |
28baac74 | 2875 | shost->dma_boundary = |
cb5172ea | 2876 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
da0436e9 JS |
2877 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
2878 | } | |
81301a9b | 2879 | |
47a8617c | 2880 | /* |
2e0fef85 JS |
2881 | * Set initial can_queue value since 0 is no longer supported and |
2882 | * scsi_add_host will fail. This will be adjusted later based on the | |
2883 | * max xri value determined in hba setup. | |
47a8617c | 2884 | */ |
2e0fef85 | 2885 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
3de2a653 | 2886 | if (dev != &phba->pcidev->dev) { |
92d7f7b0 JS |
2887 | shost->transportt = lpfc_vport_transport_template; |
2888 | vport->port_type = LPFC_NPIV_PORT; | |
2889 | } else { | |
2890 | shost->transportt = lpfc_transport_template; | |
2891 | vport->port_type = LPFC_PHYSICAL_PORT; | |
2892 | } | |
47a8617c | 2893 | |
2e0fef85 JS |
2894 | /* Initialize all internally managed lists. */ |
2895 | INIT_LIST_HEAD(&vport->fc_nodes); | |
da0436e9 | 2896 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
2e0fef85 | 2897 | spin_lock_init(&vport->work_port_lock); |
47a8617c | 2898 | |
2e0fef85 JS |
2899 | init_timer(&vport->fc_disctmo); |
2900 | vport->fc_disctmo.function = lpfc_disc_timeout; | |
92d7f7b0 | 2901 | vport->fc_disctmo.data = (unsigned long)vport; |
47a8617c | 2902 | |
2e0fef85 JS |
2903 | init_timer(&vport->fc_fdmitmo); |
2904 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; | |
92d7f7b0 | 2905 | vport->fc_fdmitmo.data = (unsigned long)vport; |
47a8617c | 2906 | |
2e0fef85 JS |
2907 | init_timer(&vport->els_tmofunc); |
2908 | vport->els_tmofunc.function = lpfc_els_timeout; | |
92d7f7b0 | 2909 | vport->els_tmofunc.data = (unsigned long)vport; |
92494144 JS |
2910 | |
2911 | init_timer(&vport->delayed_disc_tmo); | |
2912 | vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo; | |
2913 | vport->delayed_disc_tmo.data = (unsigned long)vport; | |
2914 | ||
d139b9bd | 2915 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
2e0fef85 JS |
2916 | if (error) |
2917 | goto out_put_shost; | |
47a8617c | 2918 | |
549e55cd | 2919 | spin_lock_irq(&phba->hbalock); |
2e0fef85 | 2920 | list_add_tail(&vport->listentry, &phba->port_list); |
549e55cd | 2921 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 2922 | return vport; |
47a8617c | 2923 | |
2e0fef85 JS |
2924 | out_put_shost: |
2925 | scsi_host_put(shost); | |
2926 | out: | |
2927 | return NULL; | |
47a8617c JS |
2928 | } |
2929 | ||
e59058c4 | 2930 | /** |
3621a710 | 2931 | * destroy_port - destroy an FC port |
e59058c4 JS |
2932 | * @vport: pointer to an lpfc virtual N_Port data structure. |
2933 | * | |
2934 | * This routine destroys a FC port from the upper layer protocol. All the | |
2935 | * resources associated with the port are released. | |
2936 | **/ | |
2e0fef85 JS |
2937 | void |
2938 | destroy_port(struct lpfc_vport *vport) | |
47a8617c | 2939 | { |
92d7f7b0 JS |
2940 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
2941 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 2942 | |
858c9f6c | 2943 | lpfc_debugfs_terminate(vport); |
92d7f7b0 JS |
2944 | fc_remove_host(shost); |
2945 | scsi_remove_host(shost); | |
47a8617c | 2946 | |
92d7f7b0 JS |
2947 | spin_lock_irq(&phba->hbalock); |
2948 | list_del_init(&vport->listentry); | |
2949 | spin_unlock_irq(&phba->hbalock); | |
47a8617c | 2950 | |
92d7f7b0 | 2951 | lpfc_cleanup(vport); |
47a8617c | 2952 | return; |
47a8617c JS |
2953 | } |
2954 | ||
e59058c4 | 2955 | /** |
3621a710 | 2956 | * lpfc_get_instance - Get a unique integer ID |
e59058c4 JS |
2957 | * |
2958 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It | |
2959 | * uses the kernel idr facility to perform the task. | |
2960 | * | |
2961 | * Return codes: | |
2962 | * instance - a unique integer ID allocated as the new instance. | |
2963 | * -1 - lpfc get instance failed. | |
2964 | **/ | |
92d7f7b0 JS |
2965 | int |
2966 | lpfc_get_instance(void) | |
2967 | { | |
2968 | int instance = 0; | |
47a8617c | 2969 | |
92d7f7b0 JS |
2970 | /* Assign an unused number */ |
2971 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) | |
2972 | return -1; | |
2973 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) | |
2974 | return -1; | |
2975 | return instance; | |
47a8617c JS |
2976 | } |
2977 | ||
e59058c4 | 2978 | /** |
3621a710 | 2979 | * lpfc_scan_finished - method for SCSI layer to detect whether scan is done |
e59058c4 JS |
2980 | * @shost: pointer to SCSI host data structure. |
2981 | * @time: elapsed time of the scan in jiffies. | |
2982 | * | |
2983 | * This routine is called by the SCSI layer with a SCSI host to determine | |
2984 | * whether the scan host is finished. | |
2985 | * | |
2986 | * Note: there is no scan_start function as adapter initialization will have | |
2987 | * asynchronously kicked off the link initialization. | |
2988 | * | |
2989 | * Return codes | |
2990 | * 0 - SCSI host scan is not over yet. | |
2991 | * 1 - SCSI host scan is over. | |
2992 | **/ | |
47a8617c JS |
2993 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
2994 | { | |
2e0fef85 JS |
2995 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
2996 | struct lpfc_hba *phba = vport->phba; | |
858c9f6c | 2997 | int stat = 0; |
47a8617c | 2998 | |
858c9f6c JS |
2999 | spin_lock_irq(shost->host_lock); |
3000 | ||
51ef4c26 | 3001 | if (vport->load_flag & FC_UNLOADING) { |
858c9f6c JS |
3002 | stat = 1; |
3003 | goto finished; | |
3004 | } | |
2e0fef85 JS |
3005 | if (time >= 30 * HZ) { |
3006 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
3007 | "0461 Scanning longer than 30 " |
3008 | "seconds. Continuing initialization\n"); | |
858c9f6c | 3009 | stat = 1; |
47a8617c | 3010 | goto finished; |
2e0fef85 JS |
3011 | } |
3012 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { | |
3013 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
3014 | "0465 Link down longer than 15 " |
3015 | "seconds. Continuing initialization\n"); | |
858c9f6c | 3016 | stat = 1; |
47a8617c | 3017 | goto finished; |
2e0fef85 | 3018 | } |
47a8617c | 3019 | |
2e0fef85 | 3020 | if (vport->port_state != LPFC_VPORT_READY) |
858c9f6c | 3021 | goto finished; |
2e0fef85 | 3022 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
858c9f6c | 3023 | goto finished; |
2e0fef85 | 3024 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
858c9f6c | 3025 | goto finished; |
2e0fef85 | 3026 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
858c9f6c JS |
3027 | goto finished; |
3028 | ||
3029 | stat = 1; | |
47a8617c JS |
3030 | |
3031 | finished: | |
858c9f6c JS |
3032 | spin_unlock_irq(shost->host_lock); |
3033 | return stat; | |
92d7f7b0 | 3034 | } |
47a8617c | 3035 | |
e59058c4 | 3036 | /** |
3621a710 | 3037 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
e59058c4 JS |
3038 | * @shost: pointer to SCSI host data structure. |
3039 | * | |
3040 | * This routine initializes a given SCSI host attributes on a FC port. The | |
3041 | * SCSI host can be either on top of a physical port or a virtual port. | |
3042 | **/ | |
92d7f7b0 JS |
3043 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
3044 | { | |
3045 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3046 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 3047 | /* |
2e0fef85 | 3048 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
47a8617c JS |
3049 | */ |
3050 | ||
2e0fef85 JS |
3051 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
3052 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
47a8617c JS |
3053 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
3054 | ||
3055 | memset(fc_host_supported_fc4s(shost), 0, | |
2e0fef85 | 3056 | sizeof(fc_host_supported_fc4s(shost))); |
47a8617c JS |
3057 | fc_host_supported_fc4s(shost)[2] = 1; |
3058 | fc_host_supported_fc4s(shost)[7] = 1; | |
3059 | ||
92d7f7b0 JS |
3060 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
3061 | sizeof fc_host_symbolic_name(shost)); | |
47a8617c JS |
3062 | |
3063 | fc_host_supported_speeds(shost) = 0; | |
88a2cfbb JS |
3064 | if (phba->lmt & LMT_16Gb) |
3065 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; | |
47a8617c JS |
3066 | if (phba->lmt & LMT_10Gb) |
3067 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; | |
a8adb832 JS |
3068 | if (phba->lmt & LMT_8Gb) |
3069 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; | |
47a8617c JS |
3070 | if (phba->lmt & LMT_4Gb) |
3071 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; | |
3072 | if (phba->lmt & LMT_2Gb) | |
3073 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; | |
3074 | if (phba->lmt & LMT_1Gb) | |
3075 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; | |
3076 | ||
3077 | fc_host_maxframe_size(shost) = | |
2e0fef85 JS |
3078 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
3079 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; | |
47a8617c | 3080 | |
0af5d708 MC |
3081 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
3082 | ||
47a8617c JS |
3083 | /* This value is also unchanging */ |
3084 | memset(fc_host_active_fc4s(shost), 0, | |
2e0fef85 | 3085 | sizeof(fc_host_active_fc4s(shost))); |
47a8617c JS |
3086 | fc_host_active_fc4s(shost)[2] = 1; |
3087 | fc_host_active_fc4s(shost)[7] = 1; | |
3088 | ||
92d7f7b0 | 3089 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
47a8617c | 3090 | spin_lock_irq(shost->host_lock); |
51ef4c26 | 3091 | vport->load_flag &= ~FC_LOADING; |
47a8617c | 3092 | spin_unlock_irq(shost->host_lock); |
47a8617c | 3093 | } |
dea3101e | 3094 | |
e59058c4 | 3095 | /** |
da0436e9 | 3096 | * lpfc_stop_port_s3 - Stop SLI3 device port |
e59058c4 JS |
3097 | * @phba: pointer to lpfc hba data structure. |
3098 | * | |
da0436e9 JS |
3099 | * This routine is invoked to stop an SLI3 device port, it stops the device |
3100 | * from generating interrupts and stops the device driver's timers for the | |
3101 | * device. | |
e59058c4 | 3102 | **/ |
da0436e9 JS |
3103 | static void |
3104 | lpfc_stop_port_s3(struct lpfc_hba *phba) | |
db2378e0 | 3105 | { |
da0436e9 JS |
3106 | /* Clear all interrupt enable conditions */ |
3107 | writel(0, phba->HCregaddr); | |
3108 | readl(phba->HCregaddr); /* flush */ | |
3109 | /* Clear all pending interrupts */ | |
3110 | writel(0xffffffff, phba->HAregaddr); | |
3111 | readl(phba->HAregaddr); /* flush */ | |
db2378e0 | 3112 | |
da0436e9 JS |
3113 | /* Reset some HBA SLI setup states */ |
3114 | lpfc_stop_hba_timers(phba); | |
3115 | phba->pport->work_port_events = 0; | |
3116 | } | |
db2378e0 | 3117 | |
da0436e9 JS |
3118 | /** |
3119 | * lpfc_stop_port_s4 - Stop SLI4 device port | |
3120 | * @phba: pointer to lpfc hba data structure. | |
3121 | * | |
3122 | * This routine is invoked to stop an SLI4 device port, it stops the device | |
3123 | * from generating interrupts and stops the device driver's timers for the | |
3124 | * device. | |
3125 | **/ | |
3126 | static void | |
3127 | lpfc_stop_port_s4(struct lpfc_hba *phba) | |
3128 | { | |
3129 | /* Reset some HBA SLI4 setup states */ | |
3130 | lpfc_stop_hba_timers(phba); | |
3131 | phba->pport->work_port_events = 0; | |
3132 | phba->sli4_hba.intr_enable = 0; | |
da0436e9 | 3133 | } |
9399627f | 3134 | |
da0436e9 JS |
3135 | /** |
3136 | * lpfc_stop_port - Wrapper function for stopping hba port | |
3137 | * @phba: Pointer to HBA context object. | |
3138 | * | |
3139 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from | |
3140 | * the API jump table function pointer from the lpfc_hba struct. | |
3141 | **/ | |
3142 | void | |
3143 | lpfc_stop_port(struct lpfc_hba *phba) | |
3144 | { | |
3145 | phba->lpfc_stop_port(phba); | |
3146 | } | |
db2378e0 | 3147 | |
ecfd03c6 JS |
3148 | /** |
3149 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer | |
3150 | * @phba: Pointer to hba for which this call is being executed. | |
3151 | * | |
3152 | * This routine starts the timer waiting for the FCF rediscovery to complete. | |
3153 | **/ | |
3154 | void | |
3155 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) | |
3156 | { | |
3157 | unsigned long fcf_redisc_wait_tmo = | |
3158 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); | |
3159 | /* Start fcf rediscovery wait period timer */ | |
3160 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); | |
3161 | spin_lock_irq(&phba->hbalock); | |
3162 | /* Allow action to new fcf asynchronous event */ | |
3163 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); | |
3164 | /* Mark the FCF rediscovery pending state */ | |
3165 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; | |
3166 | spin_unlock_irq(&phba->hbalock); | |
3167 | } | |
3168 | ||
3169 | /** | |
3170 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout | |
3171 | * @ptr: Map to lpfc_hba data structure pointer. | |
3172 | * | |
3173 | * This routine is invoked when waiting for FCF table rediscover has been | |
3174 | * timed out. If new FCF record(s) has (have) been discovered during the | |
3175 | * wait period, a new FCF event shall be added to the FCOE async event | |
3176 | * list, and then worker thread shall be waked up for processing from the | |
3177 | * worker thread context. | |
3178 | **/ | |
3179 | void | |
3180 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) | |
3181 | { | |
3182 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; | |
3183 | ||
3184 | /* Don't send FCF rediscovery event if timer cancelled */ | |
3185 | spin_lock_irq(&phba->hbalock); | |
3186 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
3187 | spin_unlock_irq(&phba->hbalock); | |
3188 | return; | |
3189 | } | |
3190 | /* Clear FCF rediscovery timer pending flag */ | |
3191 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; | |
3192 | /* FCF rediscovery event to worker thread */ | |
3193 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; | |
3194 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 | 3195 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 3196 | "2776 FCF rediscover quiescent timer expired\n"); |
ecfd03c6 JS |
3197 | /* wake up worker thread */ |
3198 | lpfc_worker_wake_up(phba); | |
3199 | } | |
3200 | ||
e59058c4 | 3201 | /** |
da0436e9 | 3202 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
e59058c4 | 3203 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3204 | * @acqe_link: pointer to the async link completion queue entry. |
e59058c4 | 3205 | * |
da0436e9 JS |
3206 | * This routine is to parse the SLI4 link-attention link fault code and |
3207 | * translate it into the base driver's read link attention mailbox command | |
3208 | * status. | |
3209 | * | |
3210 | * Return: Link-attention status in terms of base driver's coding. | |
e59058c4 | 3211 | **/ |
da0436e9 JS |
3212 | static uint16_t |
3213 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, | |
3214 | struct lpfc_acqe_link *acqe_link) | |
db2378e0 | 3215 | { |
da0436e9 | 3216 | uint16_t latt_fault; |
9399627f | 3217 | |
da0436e9 JS |
3218 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
3219 | case LPFC_ASYNC_LINK_FAULT_NONE: | |
3220 | case LPFC_ASYNC_LINK_FAULT_LOCAL: | |
3221 | case LPFC_ASYNC_LINK_FAULT_REMOTE: | |
3222 | latt_fault = 0; | |
3223 | break; | |
3224 | default: | |
3225 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3226 | "0398 Invalid link fault code: x%x\n", | |
3227 | bf_get(lpfc_acqe_link_fault, acqe_link)); | |
3228 | latt_fault = MBXERR_ERROR; | |
3229 | break; | |
3230 | } | |
3231 | return latt_fault; | |
db2378e0 JS |
3232 | } |
3233 | ||
5b75da2f | 3234 | /** |
da0436e9 | 3235 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
5b75da2f | 3236 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3237 | * @acqe_link: pointer to the async link completion queue entry. |
5b75da2f | 3238 | * |
da0436e9 JS |
3239 | * This routine is to parse the SLI4 link attention type and translate it |
3240 | * into the base driver's link attention type coding. | |
5b75da2f | 3241 | * |
da0436e9 JS |
3242 | * Return: Link attention type in terms of base driver's coding. |
3243 | **/ | |
3244 | static uint8_t | |
3245 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, | |
3246 | struct lpfc_acqe_link *acqe_link) | |
5b75da2f | 3247 | { |
da0436e9 | 3248 | uint8_t att_type; |
5b75da2f | 3249 | |
da0436e9 JS |
3250 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
3251 | case LPFC_ASYNC_LINK_STATUS_DOWN: | |
3252 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: | |
76a95d75 | 3253 | att_type = LPFC_ATT_LINK_DOWN; |
da0436e9 JS |
3254 | break; |
3255 | case LPFC_ASYNC_LINK_STATUS_UP: | |
3256 | /* Ignore physical link up events - wait for logical link up */ | |
76a95d75 | 3257 | att_type = LPFC_ATT_RESERVED; |
da0436e9 JS |
3258 | break; |
3259 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: | |
76a95d75 | 3260 | att_type = LPFC_ATT_LINK_UP; |
da0436e9 JS |
3261 | break; |
3262 | default: | |
3263 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3264 | "0399 Invalid link attention type: x%x\n", | |
3265 | bf_get(lpfc_acqe_link_status, acqe_link)); | |
76a95d75 | 3266 | att_type = LPFC_ATT_RESERVED; |
da0436e9 | 3267 | break; |
5b75da2f | 3268 | } |
da0436e9 | 3269 | return att_type; |
5b75da2f JS |
3270 | } |
3271 | ||
3272 | /** | |
da0436e9 | 3273 | * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed |
5b75da2f | 3274 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3275 | * @acqe_link: pointer to the async link completion queue entry. |
5b75da2f | 3276 | * |
da0436e9 JS |
3277 | * This routine is to parse the SLI4 link-attention link speed and translate |
3278 | * it into the base driver's link-attention link speed coding. | |
3279 | * | |
3280 | * Return: Link-attention link speed in terms of base driver's coding. | |
3281 | **/ | |
3282 | static uint8_t | |
3283 | lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba, | |
3284 | struct lpfc_acqe_link *acqe_link) | |
5b75da2f | 3285 | { |
da0436e9 JS |
3286 | uint8_t link_speed; |
3287 | ||
3288 | switch (bf_get(lpfc_acqe_link_speed, acqe_link)) { | |
3289 | case LPFC_ASYNC_LINK_SPEED_ZERO: | |
da0436e9 | 3290 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
da0436e9 | 3291 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
76a95d75 | 3292 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
da0436e9 JS |
3293 | break; |
3294 | case LPFC_ASYNC_LINK_SPEED_1GBPS: | |
76a95d75 | 3295 | link_speed = LPFC_LINK_SPEED_1GHZ; |
da0436e9 JS |
3296 | break; |
3297 | case LPFC_ASYNC_LINK_SPEED_10GBPS: | |
76a95d75 | 3298 | link_speed = LPFC_LINK_SPEED_10GHZ; |
da0436e9 JS |
3299 | break; |
3300 | default: | |
3301 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3302 | "0483 Invalid link-attention link speed: x%x\n", | |
3303 | bf_get(lpfc_acqe_link_speed, acqe_link)); | |
76a95d75 | 3304 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
da0436e9 JS |
3305 | break; |
3306 | } | |
3307 | return link_speed; | |
3308 | } | |
3309 | ||
3310 | /** | |
70f3c073 | 3311 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
da0436e9 JS |
3312 | * @phba: pointer to lpfc hba data structure. |
3313 | * @acqe_link: pointer to the async link completion queue entry. | |
3314 | * | |
70f3c073 | 3315 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
da0436e9 JS |
3316 | **/ |
3317 | static void | |
3318 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, | |
3319 | struct lpfc_acqe_link *acqe_link) | |
3320 | { | |
3321 | struct lpfc_dmabuf *mp; | |
3322 | LPFC_MBOXQ_t *pmb; | |
3323 | MAILBOX_t *mb; | |
76a95d75 | 3324 | struct lpfc_mbx_read_top *la; |
da0436e9 | 3325 | uint8_t att_type; |
76a95d75 | 3326 | int rc; |
da0436e9 JS |
3327 | |
3328 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); | |
76a95d75 | 3329 | if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP) |
da0436e9 | 3330 | return; |
32b9793f | 3331 | phba->fcoe_eventtag = acqe_link->event_tag; |
da0436e9 JS |
3332 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3333 | if (!pmb) { | |
3334 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3335 | "0395 The mboxq allocation failed\n"); | |
3336 | return; | |
3337 | } | |
3338 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
3339 | if (!mp) { | |
3340 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3341 | "0396 The lpfc_dmabuf allocation failed\n"); | |
3342 | goto out_free_pmb; | |
3343 | } | |
3344 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
3345 | if (!mp->virt) { | |
3346 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3347 | "0397 The mbuf allocation failed\n"); | |
3348 | goto out_free_dmabuf; | |
3349 | } | |
3350 | ||
3351 | /* Cleanup any outstanding ELS commands */ | |
3352 | lpfc_els_flush_all_cmd(phba); | |
3353 | ||
3354 | /* Block ELS IOCBs until we have done process link event */ | |
3355 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
3356 | ||
3357 | /* Update link event statistics */ | |
3358 | phba->sli.slistat.link_event++; | |
3359 | ||
76a95d75 JS |
3360 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
3361 | lpfc_read_topology(phba, pmb, mp); | |
3362 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
da0436e9 JS |
3363 | pmb->vport = phba->pport; |
3364 | ||
da0436e9 JS |
3365 | /* Keep the link status for extra SLI4 state machine reference */ |
3366 | phba->sli4_hba.link_state.speed = | |
3367 | bf_get(lpfc_acqe_link_speed, acqe_link); | |
3368 | phba->sli4_hba.link_state.duplex = | |
3369 | bf_get(lpfc_acqe_link_duplex, acqe_link); | |
3370 | phba->sli4_hba.link_state.status = | |
3371 | bf_get(lpfc_acqe_link_status, acqe_link); | |
70f3c073 JS |
3372 | phba->sli4_hba.link_state.type = |
3373 | bf_get(lpfc_acqe_link_type, acqe_link); | |
3374 | phba->sli4_hba.link_state.number = | |
3375 | bf_get(lpfc_acqe_link_number, acqe_link); | |
da0436e9 JS |
3376 | phba->sli4_hba.link_state.fault = |
3377 | bf_get(lpfc_acqe_link_fault, acqe_link); | |
65467b6b | 3378 | phba->sli4_hba.link_state.logical_speed = |
70f3c073 JS |
3379 | bf_get(lpfc_acqe_logical_link_speed, acqe_link); |
3380 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
c31098ce JS |
3381 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
3382 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " | |
3383 | "Logical speed:%dMbps Fault:%d\n", | |
70f3c073 JS |
3384 | phba->sli4_hba.link_state.speed, |
3385 | phba->sli4_hba.link_state.topology, | |
3386 | phba->sli4_hba.link_state.status, | |
3387 | phba->sli4_hba.link_state.type, | |
3388 | phba->sli4_hba.link_state.number, | |
3389 | phba->sli4_hba.link_state.logical_speed * 10, | |
3390 | phba->sli4_hba.link_state.fault); | |
76a95d75 JS |
3391 | /* |
3392 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch | |
3393 | * topology info. Note: Optional for non FC-AL ports. | |
3394 | */ | |
3395 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { | |
3396 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3397 | if (rc == MBX_NOT_FINISHED) | |
3398 | goto out_free_dmabuf; | |
3399 | return; | |
3400 | } | |
3401 | /* | |
3402 | * For FCoE Mode: fill in all the topology information we need and call | |
3403 | * the READ_TOPOLOGY completion routine to continue without actually | |
3404 | * sending the READ_TOPOLOGY mailbox command to the port. | |
3405 | */ | |
3406 | /* Parse and translate status field */ | |
3407 | mb = &pmb->u.mb; | |
3408 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); | |
3409 | ||
3410 | /* Parse and translate link attention fields */ | |
3411 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; | |
3412 | la->eventTag = acqe_link->event_tag; | |
3413 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); | |
3414 | bf_set(lpfc_mbx_read_top_link_spd, la, | |
3415 | lpfc_sli4_parse_latt_link_speed(phba, acqe_link)); | |
3416 | ||
3417 | /* Fake the the following irrelvant fields */ | |
3418 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); | |
3419 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); | |
3420 | bf_set(lpfc_mbx_read_top_il, la, 0); | |
3421 | bf_set(lpfc_mbx_read_top_pb, la, 0); | |
3422 | bf_set(lpfc_mbx_read_top_fa, la, 0); | |
3423 | bf_set(lpfc_mbx_read_top_mm, la, 0); | |
da0436e9 JS |
3424 | |
3425 | /* Invoke the lpfc_handle_latt mailbox command callback function */ | |
76a95d75 | 3426 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
da0436e9 | 3427 | |
5b75da2f | 3428 | return; |
da0436e9 JS |
3429 | |
3430 | out_free_dmabuf: | |
3431 | kfree(mp); | |
3432 | out_free_pmb: | |
3433 | mempool_free(pmb, phba->mbox_mem_pool); | |
3434 | } | |
3435 | ||
70f3c073 JS |
3436 | /** |
3437 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event | |
3438 | * @phba: pointer to lpfc hba data structure. | |
3439 | * @acqe_fc: pointer to the async fc completion queue entry. | |
3440 | * | |
3441 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log | |
3442 | * that the event was received and then issue a read_topology mailbox command so | |
3443 | * that the rest of the driver will treat it the same as SLI3. | |
3444 | **/ | |
3445 | static void | |
3446 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) | |
3447 | { | |
3448 | struct lpfc_dmabuf *mp; | |
3449 | LPFC_MBOXQ_t *pmb; | |
3450 | int rc; | |
3451 | ||
3452 | if (bf_get(lpfc_trailer_type, acqe_fc) != | |
3453 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { | |
3454 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3455 | "2895 Non FC link Event detected.(%d)\n", | |
3456 | bf_get(lpfc_trailer_type, acqe_fc)); | |
3457 | return; | |
3458 | } | |
3459 | /* Keep the link status for extra SLI4 state machine reference */ | |
3460 | phba->sli4_hba.link_state.speed = | |
3461 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc); | |
3462 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; | |
3463 | phba->sli4_hba.link_state.topology = | |
3464 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); | |
3465 | phba->sli4_hba.link_state.status = | |
3466 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); | |
3467 | phba->sli4_hba.link_state.type = | |
3468 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); | |
3469 | phba->sli4_hba.link_state.number = | |
3470 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); | |
3471 | phba->sli4_hba.link_state.fault = | |
3472 | bf_get(lpfc_acqe_link_fault, acqe_fc); | |
3473 | phba->sli4_hba.link_state.logical_speed = | |
3474 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc); | |
3475 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3476 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " | |
3477 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" | |
3478 | "%dMbps Fault:%d\n", | |
3479 | phba->sli4_hba.link_state.speed, | |
3480 | phba->sli4_hba.link_state.topology, | |
3481 | phba->sli4_hba.link_state.status, | |
3482 | phba->sli4_hba.link_state.type, | |
3483 | phba->sli4_hba.link_state.number, | |
3484 | phba->sli4_hba.link_state.logical_speed * 10, | |
3485 | phba->sli4_hba.link_state.fault); | |
3486 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
3487 | if (!pmb) { | |
3488 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3489 | "2897 The mboxq allocation failed\n"); | |
3490 | return; | |
3491 | } | |
3492 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
3493 | if (!mp) { | |
3494 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3495 | "2898 The lpfc_dmabuf allocation failed\n"); | |
3496 | goto out_free_pmb; | |
3497 | } | |
3498 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
3499 | if (!mp->virt) { | |
3500 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3501 | "2899 The mbuf allocation failed\n"); | |
3502 | goto out_free_dmabuf; | |
3503 | } | |
3504 | ||
3505 | /* Cleanup any outstanding ELS commands */ | |
3506 | lpfc_els_flush_all_cmd(phba); | |
3507 | ||
3508 | /* Block ELS IOCBs until we have done process link event */ | |
3509 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
3510 | ||
3511 | /* Update link event statistics */ | |
3512 | phba->sli.slistat.link_event++; | |
3513 | ||
3514 | /* Create lpfc_handle_latt mailbox command from link ACQE */ | |
3515 | lpfc_read_topology(phba, pmb, mp); | |
3516 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
3517 | pmb->vport = phba->pport; | |
3518 | ||
3519 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3520 | if (rc == MBX_NOT_FINISHED) | |
3521 | goto out_free_dmabuf; | |
3522 | return; | |
3523 | ||
3524 | out_free_dmabuf: | |
3525 | kfree(mp); | |
3526 | out_free_pmb: | |
3527 | mempool_free(pmb, phba->mbox_mem_pool); | |
3528 | } | |
3529 | ||
3530 | /** | |
3531 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event | |
3532 | * @phba: pointer to lpfc hba data structure. | |
3533 | * @acqe_fc: pointer to the async SLI completion queue entry. | |
3534 | * | |
3535 | * This routine is to handle the SLI4 asynchronous SLI events. | |
3536 | **/ | |
3537 | static void | |
3538 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) | |
3539 | { | |
3540 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3541 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" | |
3542 | "x%08x SLI Event Type:%d", | |
3543 | acqe_sli->event_data1, acqe_sli->event_data2, | |
3544 | bf_get(lpfc_trailer_type, acqe_sli)); | |
3545 | return; | |
3546 | } | |
3547 | ||
fc2b989b JS |
3548 | /** |
3549 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport | |
3550 | * @vport: pointer to vport data structure. | |
3551 | * | |
3552 | * This routine is to perform Clear Virtual Link (CVL) on a vport in | |
3553 | * response to a CVL event. | |
3554 | * | |
3555 | * Return the pointer to the ndlp with the vport if successful, otherwise | |
3556 | * return NULL. | |
3557 | **/ | |
3558 | static struct lpfc_nodelist * | |
3559 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) | |
3560 | { | |
3561 | struct lpfc_nodelist *ndlp; | |
3562 | struct Scsi_Host *shost; | |
3563 | struct lpfc_hba *phba; | |
3564 | ||
3565 | if (!vport) | |
3566 | return NULL; | |
fc2b989b JS |
3567 | phba = vport->phba; |
3568 | if (!phba) | |
3569 | return NULL; | |
78730cfe JS |
3570 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
3571 | if (!ndlp) { | |
3572 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | |
3573 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
3574 | if (!ndlp) | |
3575 | return 0; | |
3576 | lpfc_nlp_init(vport, ndlp, Fabric_DID); | |
3577 | /* Set the node type */ | |
3578 | ndlp->nlp_type |= NLP_FABRIC; | |
3579 | /* Put ndlp onto node list */ | |
3580 | lpfc_enqueue_node(vport, ndlp); | |
3581 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
3582 | /* re-setup ndlp without removing from node list */ | |
3583 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
3584 | if (!ndlp) | |
3585 | return 0; | |
3586 | } | |
63e801ce JS |
3587 | if ((phba->pport->port_state < LPFC_FLOGI) && |
3588 | (phba->pport->port_state != LPFC_VPORT_FAILED)) | |
fc2b989b JS |
3589 | return NULL; |
3590 | /* If virtual link is not yet instantiated ignore CVL */ | |
63e801ce JS |
3591 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
3592 | && (vport->port_state != LPFC_VPORT_FAILED)) | |
fc2b989b JS |
3593 | return NULL; |
3594 | shost = lpfc_shost_from_vport(vport); | |
3595 | if (!shost) | |
3596 | return NULL; | |
3597 | lpfc_linkdown_port(vport); | |
3598 | lpfc_cleanup_pending_mbox(vport); | |
3599 | spin_lock_irq(shost->host_lock); | |
3600 | vport->fc_flag |= FC_VPORT_CVL_RCVD; | |
3601 | spin_unlock_irq(shost->host_lock); | |
3602 | ||
3603 | return ndlp; | |
3604 | } | |
3605 | ||
3606 | /** | |
3607 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports | |
3608 | * @vport: pointer to lpfc hba data structure. | |
3609 | * | |
3610 | * This routine is to perform Clear Virtual Link (CVL) on all vports in | |
3611 | * response to a FCF dead event. | |
3612 | **/ | |
3613 | static void | |
3614 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) | |
3615 | { | |
3616 | struct lpfc_vport **vports; | |
3617 | int i; | |
3618 | ||
3619 | vports = lpfc_create_vport_work_array(phba); | |
3620 | if (vports) | |
3621 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) | |
3622 | lpfc_sli4_perform_vport_cvl(vports[i]); | |
3623 | lpfc_destroy_vport_work_array(phba, vports); | |
3624 | } | |
3625 | ||
da0436e9 | 3626 | /** |
76a95d75 | 3627 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
da0436e9 JS |
3628 | * @phba: pointer to lpfc hba data structure. |
3629 | * @acqe_link: pointer to the async fcoe completion queue entry. | |
3630 | * | |
3631 | * This routine is to handle the SLI4 asynchronous fcoe event. | |
3632 | **/ | |
3633 | static void | |
76a95d75 | 3634 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
70f3c073 | 3635 | struct lpfc_acqe_fip *acqe_fip) |
da0436e9 | 3636 | { |
70f3c073 | 3637 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
da0436e9 | 3638 | int rc; |
6669f9bb JS |
3639 | struct lpfc_vport *vport; |
3640 | struct lpfc_nodelist *ndlp; | |
3641 | struct Scsi_Host *shost; | |
695a814e JS |
3642 | int active_vlink_present; |
3643 | struct lpfc_vport **vports; | |
3644 | int i; | |
da0436e9 | 3645 | |
70f3c073 JS |
3646 | phba->fc_eventTag = acqe_fip->event_tag; |
3647 | phba->fcoe_eventtag = acqe_fip->event_tag; | |
da0436e9 | 3648 | switch (event_type) { |
70f3c073 JS |
3649 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
3650 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: | |
3651 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) | |
999d813f JS |
3652 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
3653 | LOG_DISCOVERY, | |
a93ff37a JS |
3654 | "2546 New FCF event, evt_tag:x%x, " |
3655 | "index:x%x\n", | |
70f3c073 JS |
3656 | acqe_fip->event_tag, |
3657 | acqe_fip->index); | |
999d813f JS |
3658 | else |
3659 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | | |
3660 | LOG_DISCOVERY, | |
a93ff37a JS |
3661 | "2788 FCF param modified event, " |
3662 | "evt_tag:x%x, index:x%x\n", | |
70f3c073 JS |
3663 | acqe_fip->event_tag, |
3664 | acqe_fip->index); | |
38b92ef8 | 3665 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
0c9ab6f5 JS |
3666 | /* |
3667 | * During period of FCF discovery, read the FCF | |
3668 | * table record indexed by the event to update | |
a93ff37a | 3669 | * FCF roundrobin failover eligible FCF bmask. |
0c9ab6f5 JS |
3670 | */ |
3671 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | | |
3672 | LOG_DISCOVERY, | |
a93ff37a JS |
3673 | "2779 Read FCF (x%x) for updating " |
3674 | "roundrobin FCF failover bmask\n", | |
70f3c073 JS |
3675 | acqe_fip->index); |
3676 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); | |
0c9ab6f5 | 3677 | } |
38b92ef8 JS |
3678 | |
3679 | /* If the FCF discovery is in progress, do nothing. */ | |
3804dc84 | 3680 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 3681 | if (phba->hba_flag & FCF_TS_INPROG) { |
38b92ef8 JS |
3682 | spin_unlock_irq(&phba->hbalock); |
3683 | break; | |
3684 | } | |
3685 | /* If fast FCF failover rescan event is pending, do nothing */ | |
3686 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { | |
3687 | spin_unlock_irq(&phba->hbalock); | |
3688 | break; | |
3689 | } | |
3690 | ||
3691 | /* If the FCF has been in discovered state, do nothing. */ | |
3804dc84 JS |
3692 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
3693 | spin_unlock_irq(&phba->hbalock); | |
3694 | break; | |
3695 | } | |
3696 | spin_unlock_irq(&phba->hbalock); | |
38b92ef8 | 3697 | |
0c9ab6f5 JS |
3698 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
3699 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, | |
a93ff37a JS |
3700 | "2770 Start FCF table scan per async FCF " |
3701 | "event, evt_tag:x%x, index:x%x\n", | |
70f3c073 | 3702 | acqe_fip->event_tag, acqe_fip->index); |
0c9ab6f5 JS |
3703 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
3704 | LPFC_FCOE_FCF_GET_FIRST); | |
da0436e9 | 3705 | if (rc) |
0c9ab6f5 JS |
3706 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
3707 | "2547 Issue FCF scan read FCF mailbox " | |
a93ff37a | 3708 | "command failed (x%x)\n", rc); |
da0436e9 JS |
3709 | break; |
3710 | ||
70f3c073 | 3711 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
da0436e9 | 3712 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e4e74273 | 3713 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
70f3c073 JS |
3714 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
3715 | acqe_fip->event_tag); | |
da0436e9 JS |
3716 | break; |
3717 | ||
70f3c073 | 3718 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
0c9ab6f5 | 3719 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
a93ff37a | 3720 | "2549 FCF (x%x) disconnected from network, " |
70f3c073 | 3721 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
38b92ef8 JS |
3722 | /* |
3723 | * If we are in the middle of FCF failover process, clear | |
3724 | * the corresponding FCF bit in the roundrobin bitmap. | |
da0436e9 | 3725 | */ |
fc2b989b | 3726 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3727 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
fc2b989b | 3728 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 | 3729 | /* Update FLOGI FCF failover eligible FCF bmask */ |
70f3c073 | 3730 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
fc2b989b JS |
3731 | break; |
3732 | } | |
38b92ef8 JS |
3733 | spin_unlock_irq(&phba->hbalock); |
3734 | ||
3735 | /* If the event is not for currently used fcf do nothing */ | |
70f3c073 | 3736 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
38b92ef8 JS |
3737 | break; |
3738 | ||
3739 | /* | |
3740 | * Otherwise, request the port to rediscover the entire FCF | |
3741 | * table for a fast recovery from case that the current FCF | |
3742 | * is no longer valid as we are not in the middle of FCF | |
3743 | * failover process already. | |
3744 | */ | |
3745 | spin_lock_irq(&phba->hbalock); | |
fc2b989b | 3746 | /* Mark the fast failover process in progress */ |
0c9ab6f5 | 3747 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
fc2b989b | 3748 | spin_unlock_irq(&phba->hbalock); |
38b92ef8 | 3749 | |
0c9ab6f5 JS |
3750 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
3751 | "2771 Start FCF fast failover process due to " | |
3752 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " | |
70f3c073 | 3753 | "\n", acqe_fip->event_tag, acqe_fip->index); |
fc2b989b JS |
3754 | rc = lpfc_sli4_redisc_fcf_table(phba); |
3755 | if (rc) { | |
0c9ab6f5 JS |
3756 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
3757 | LOG_DISCOVERY, | |
3758 | "2772 Issue FCF rediscover mabilbox " | |
3759 | "command failed, fail through to FCF " | |
3760 | "dead event\n"); | |
fc2b989b | 3761 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3762 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
3763 | spin_unlock_irq(&phba->hbalock); |
3764 | /* | |
3765 | * Last resort will fail over by treating this | |
3766 | * as a link down to FCF registration. | |
3767 | */ | |
3768 | lpfc_sli4_fcf_dead_failthrough(phba); | |
38b92ef8 JS |
3769 | } else { |
3770 | /* Reset FCF roundrobin bmask for new discovery */ | |
7d791df7 | 3771 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
38b92ef8 JS |
3772 | /* |
3773 | * Handling fast FCF failover to a DEAD FCF event is | |
3774 | * considered equalivant to receiving CVL to all vports. | |
fc2b989b JS |
3775 | */ |
3776 | lpfc_sli4_perform_all_vport_cvl(phba); | |
38b92ef8 | 3777 | } |
da0436e9 | 3778 | break; |
70f3c073 | 3779 | case LPFC_FIP_EVENT_TYPE_CVL: |
0c9ab6f5 | 3780 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
6669f9bb | 3781 | "2718 Clear Virtual Link Received for VPI 0x%x" |
70f3c073 | 3782 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
6d368e53 | 3783 | |
6669f9bb | 3784 | vport = lpfc_find_vport_by_vpid(phba, |
5248a749 | 3785 | acqe_fip->index); |
fc2b989b | 3786 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
6669f9bb JS |
3787 | if (!ndlp) |
3788 | break; | |
695a814e JS |
3789 | active_vlink_present = 0; |
3790 | ||
3791 | vports = lpfc_create_vport_work_array(phba); | |
3792 | if (vports) { | |
3793 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; | |
3794 | i++) { | |
3795 | if ((!(vports[i]->fc_flag & | |
3796 | FC_VPORT_CVL_RCVD)) && | |
3797 | (vports[i]->port_state > LPFC_FDISC)) { | |
3798 | active_vlink_present = 1; | |
3799 | break; | |
3800 | } | |
3801 | } | |
3802 | lpfc_destroy_vport_work_array(phba, vports); | |
3803 | } | |
3804 | ||
3805 | if (active_vlink_present) { | |
3806 | /* | |
3807 | * If there are other active VLinks present, | |
3808 | * re-instantiate the Vlink using FDISC. | |
3809 | */ | |
6669f9bb | 3810 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
fc2b989b | 3811 | shost = lpfc_shost_from_vport(vport); |
6669f9bb JS |
3812 | spin_lock_irq(shost->host_lock); |
3813 | ndlp->nlp_flag |= NLP_DELAY_TMO; | |
3814 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
3815 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
3816 | vport->port_state = LPFC_FDISC; | |
3817 | } else { | |
ecfd03c6 JS |
3818 | /* |
3819 | * Otherwise, we request port to rediscover | |
3820 | * the entire FCF table for a fast recovery | |
3821 | * from possible case that the current FCF | |
0c9ab6f5 JS |
3822 | * is no longer valid if we are not already |
3823 | * in the FCF failover process. | |
ecfd03c6 | 3824 | */ |
fc2b989b | 3825 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3826 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
fc2b989b JS |
3827 | spin_unlock_irq(&phba->hbalock); |
3828 | break; | |
3829 | } | |
3830 | /* Mark the fast failover process in progress */ | |
0c9ab6f5 | 3831 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
fc2b989b | 3832 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 JS |
3833 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
3834 | LOG_DISCOVERY, | |
a93ff37a | 3835 | "2773 Start FCF failover per CVL, " |
70f3c073 | 3836 | "evt_tag:x%x\n", acqe_fip->event_tag); |
ecfd03c6 | 3837 | rc = lpfc_sli4_redisc_fcf_table(phba); |
fc2b989b | 3838 | if (rc) { |
0c9ab6f5 JS |
3839 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
3840 | LOG_DISCOVERY, | |
3841 | "2774 Issue FCF rediscover " | |
3842 | "mabilbox command failed, " | |
3843 | "through to CVL event\n"); | |
fc2b989b | 3844 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3845 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b | 3846 | spin_unlock_irq(&phba->hbalock); |
ecfd03c6 JS |
3847 | /* |
3848 | * Last resort will be re-try on the | |
3849 | * the current registered FCF entry. | |
3850 | */ | |
3851 | lpfc_retry_pport_discovery(phba); | |
38b92ef8 JS |
3852 | } else |
3853 | /* | |
3854 | * Reset FCF roundrobin bmask for new | |
3855 | * discovery. | |
3856 | */ | |
7d791df7 | 3857 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
6669f9bb JS |
3858 | } |
3859 | break; | |
da0436e9 JS |
3860 | default: |
3861 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3862 | "0288 Unknown FCoE event type 0x%x event tag " | |
70f3c073 | 3863 | "0x%x\n", event_type, acqe_fip->event_tag); |
da0436e9 JS |
3864 | break; |
3865 | } | |
3866 | } | |
3867 | ||
3868 | /** | |
3869 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event | |
3870 | * @phba: pointer to lpfc hba data structure. | |
3871 | * @acqe_link: pointer to the async dcbx completion queue entry. | |
3872 | * | |
3873 | * This routine is to handle the SLI4 asynchronous dcbx event. | |
3874 | **/ | |
3875 | static void | |
3876 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, | |
3877 | struct lpfc_acqe_dcbx *acqe_dcbx) | |
3878 | { | |
4d9ab994 | 3879 | phba->fc_eventTag = acqe_dcbx->event_tag; |
da0436e9 JS |
3880 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
3881 | "0290 The SLI4 DCBX asynchronous event is not " | |
3882 | "handled yet\n"); | |
3883 | } | |
3884 | ||
b19a061a JS |
3885 | /** |
3886 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event | |
3887 | * @phba: pointer to lpfc hba data structure. | |
3888 | * @acqe_link: pointer to the async grp5 completion queue entry. | |
3889 | * | |
3890 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event | |
3891 | * is an asynchronous notified of a logical link speed change. The Port | |
3892 | * reports the logical link speed in units of 10Mbps. | |
3893 | **/ | |
3894 | static void | |
3895 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, | |
3896 | struct lpfc_acqe_grp5 *acqe_grp5) | |
3897 | { | |
3898 | uint16_t prev_ll_spd; | |
3899 | ||
3900 | phba->fc_eventTag = acqe_grp5->event_tag; | |
3901 | phba->fcoe_eventtag = acqe_grp5->event_tag; | |
3902 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; | |
3903 | phba->sli4_hba.link_state.logical_speed = | |
3904 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)); | |
3905 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3906 | "2789 GRP5 Async Event: Updating logical link speed " | |
3907 | "from %dMbps to %dMbps\n", (prev_ll_spd * 10), | |
3908 | (phba->sli4_hba.link_state.logical_speed*10)); | |
3909 | } | |
3910 | ||
da0436e9 JS |
3911 | /** |
3912 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event | |
3913 | * @phba: pointer to lpfc hba data structure. | |
3914 | * | |
3915 | * This routine is invoked by the worker thread to process all the pending | |
3916 | * SLI4 asynchronous events. | |
3917 | **/ | |
3918 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) | |
3919 | { | |
3920 | struct lpfc_cq_event *cq_event; | |
3921 | ||
3922 | /* First, declare the async event has been handled */ | |
3923 | spin_lock_irq(&phba->hbalock); | |
3924 | phba->hba_flag &= ~ASYNC_EVENT; | |
3925 | spin_unlock_irq(&phba->hbalock); | |
3926 | /* Now, handle all the async events */ | |
3927 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { | |
3928 | /* Get the first event from the head of the event queue */ | |
3929 | spin_lock_irq(&phba->hbalock); | |
3930 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, | |
3931 | cq_event, struct lpfc_cq_event, list); | |
3932 | spin_unlock_irq(&phba->hbalock); | |
3933 | /* Process the asynchronous event */ | |
3934 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { | |
3935 | case LPFC_TRAILER_CODE_LINK: | |
3936 | lpfc_sli4_async_link_evt(phba, | |
3937 | &cq_event->cqe.acqe_link); | |
3938 | break; | |
3939 | case LPFC_TRAILER_CODE_FCOE: | |
70f3c073 | 3940 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
da0436e9 JS |
3941 | break; |
3942 | case LPFC_TRAILER_CODE_DCBX: | |
3943 | lpfc_sli4_async_dcbx_evt(phba, | |
3944 | &cq_event->cqe.acqe_dcbx); | |
3945 | break; | |
b19a061a JS |
3946 | case LPFC_TRAILER_CODE_GRP5: |
3947 | lpfc_sli4_async_grp5_evt(phba, | |
3948 | &cq_event->cqe.acqe_grp5); | |
3949 | break; | |
70f3c073 JS |
3950 | case LPFC_TRAILER_CODE_FC: |
3951 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); | |
3952 | break; | |
3953 | case LPFC_TRAILER_CODE_SLI: | |
3954 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); | |
3955 | break; | |
da0436e9 JS |
3956 | default: |
3957 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3958 | "1804 Invalid asynchrous event code: " | |
3959 | "x%x\n", bf_get(lpfc_trailer_code, | |
3960 | &cq_event->cqe.mcqe_cmpl)); | |
3961 | break; | |
3962 | } | |
3963 | /* Free the completion event processed to the free pool */ | |
3964 | lpfc_sli4_cq_event_release(phba, cq_event); | |
3965 | } | |
3966 | } | |
3967 | ||
ecfd03c6 JS |
3968 | /** |
3969 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event | |
3970 | * @phba: pointer to lpfc hba data structure. | |
3971 | * | |
3972 | * This routine is invoked by the worker thread to process FCF table | |
3973 | * rediscovery pending completion event. | |
3974 | **/ | |
3975 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) | |
3976 | { | |
3977 | int rc; | |
3978 | ||
3979 | spin_lock_irq(&phba->hbalock); | |
3980 | /* Clear FCF rediscovery timeout event */ | |
3981 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; | |
3982 | /* Clear driver fast failover FCF record flag */ | |
3983 | phba->fcf.failover_rec.flag = 0; | |
3984 | /* Set state for FCF fast failover */ | |
3985 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; | |
3986 | spin_unlock_irq(&phba->hbalock); | |
3987 | ||
3988 | /* Scan FCF table from the first entry to re-discover SAN */ | |
0c9ab6f5 | 3989 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
a93ff37a | 3990 | "2777 Start post-quiescent FCF table scan\n"); |
0c9ab6f5 | 3991 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
ecfd03c6 | 3992 | if (rc) |
0c9ab6f5 JS |
3993 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
3994 | "2747 Issue FCF scan read FCF mailbox " | |
3995 | "command failed 0x%x\n", rc); | |
ecfd03c6 JS |
3996 | } |
3997 | ||
da0436e9 JS |
3998 | /** |
3999 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table | |
4000 | * @phba: pointer to lpfc hba data structure. | |
4001 | * @dev_grp: The HBA PCI-Device group number. | |
4002 | * | |
4003 | * This routine is invoked to set up the per HBA PCI-Device group function | |
4004 | * API jump table entries. | |
4005 | * | |
4006 | * Return: 0 if success, otherwise -ENODEV | |
4007 | **/ | |
4008 | int | |
4009 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
4010 | { | |
4011 | int rc; | |
4012 | ||
4013 | /* Set up lpfc PCI-device group */ | |
4014 | phba->pci_dev_grp = dev_grp; | |
4015 | ||
4016 | /* The LPFC_PCI_DEV_OC uses SLI4 */ | |
4017 | if (dev_grp == LPFC_PCI_DEV_OC) | |
4018 | phba->sli_rev = LPFC_SLI_REV4; | |
4019 | ||
4020 | /* Set up device INIT API function jump table */ | |
4021 | rc = lpfc_init_api_table_setup(phba, dev_grp); | |
4022 | if (rc) | |
4023 | return -ENODEV; | |
4024 | /* Set up SCSI API function jump table */ | |
4025 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); | |
4026 | if (rc) | |
4027 | return -ENODEV; | |
4028 | /* Set up SLI API function jump table */ | |
4029 | rc = lpfc_sli_api_table_setup(phba, dev_grp); | |
4030 | if (rc) | |
4031 | return -ENODEV; | |
4032 | /* Set up MBOX API function jump table */ | |
4033 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); | |
4034 | if (rc) | |
4035 | return -ENODEV; | |
4036 | ||
4037 | return 0; | |
5b75da2f JS |
4038 | } |
4039 | ||
4040 | /** | |
3621a710 | 4041 | * lpfc_log_intr_mode - Log the active interrupt mode |
5b75da2f JS |
4042 | * @phba: pointer to lpfc hba data structure. |
4043 | * @intr_mode: active interrupt mode adopted. | |
4044 | * | |
4045 | * This routine it invoked to log the currently used active interrupt mode | |
4046 | * to the device. | |
3772a991 JS |
4047 | **/ |
4048 | static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode) | |
5b75da2f JS |
4049 | { |
4050 | switch (intr_mode) { | |
4051 | case 0: | |
4052 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4053 | "0470 Enable INTx interrupt mode.\n"); | |
4054 | break; | |
4055 | case 1: | |
4056 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4057 | "0481 Enabled MSI interrupt mode.\n"); | |
4058 | break; | |
4059 | case 2: | |
4060 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4061 | "0480 Enabled MSI-X interrupt mode.\n"); | |
4062 | break; | |
4063 | default: | |
4064 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4065 | "0482 Illegal interrupt mode.\n"); | |
4066 | break; | |
4067 | } | |
4068 | return; | |
4069 | } | |
4070 | ||
5b75da2f | 4071 | /** |
3772a991 | 4072 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
5b75da2f JS |
4073 | * @phba: pointer to lpfc hba data structure. |
4074 | * | |
3772a991 JS |
4075 | * This routine is invoked to enable the PCI device that is common to all |
4076 | * PCI devices. | |
5b75da2f JS |
4077 | * |
4078 | * Return codes | |
af901ca1 | 4079 | * 0 - successful |
3772a991 | 4080 | * other values - error |
5b75da2f | 4081 | **/ |
3772a991 JS |
4082 | static int |
4083 | lpfc_enable_pci_dev(struct lpfc_hba *phba) | |
5b75da2f | 4084 | { |
3772a991 | 4085 | struct pci_dev *pdev; |
079b5c91 | 4086 | int bars = 0; |
5b75da2f | 4087 | |
3772a991 JS |
4088 | /* Obtain PCI device reference */ |
4089 | if (!phba->pcidev) | |
4090 | goto out_error; | |
4091 | else | |
4092 | pdev = phba->pcidev; | |
4093 | /* Select PCI BARs */ | |
4094 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
4095 | /* Enable PCI device */ | |
4096 | if (pci_enable_device_mem(pdev)) | |
4097 | goto out_error; | |
4098 | /* Request PCI resource for the device */ | |
4099 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) | |
4100 | goto out_disable_device; | |
4101 | /* Set up device as PCI master and save state for EEH */ | |
4102 | pci_set_master(pdev); | |
4103 | pci_try_set_mwi(pdev); | |
4104 | pci_save_state(pdev); | |
5b75da2f | 4105 | |
0558056c JS |
4106 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
4107 | if (pci_find_capability(pdev, PCI_CAP_ID_EXP)) | |
4108 | pdev->needs_freset = 1; | |
4109 | ||
3772a991 | 4110 | return 0; |
5b75da2f | 4111 | |
3772a991 JS |
4112 | out_disable_device: |
4113 | pci_disable_device(pdev); | |
4114 | out_error: | |
079b5c91 JS |
4115 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
4116 | "1401 Failed to enable pci device, bars:x%x\n", bars); | |
3772a991 | 4117 | return -ENODEV; |
5b75da2f JS |
4118 | } |
4119 | ||
4120 | /** | |
3772a991 | 4121 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
5b75da2f JS |
4122 | * @phba: pointer to lpfc hba data structure. |
4123 | * | |
3772a991 JS |
4124 | * This routine is invoked to disable the PCI device that is common to all |
4125 | * PCI devices. | |
5b75da2f JS |
4126 | **/ |
4127 | static void | |
3772a991 | 4128 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
5b75da2f | 4129 | { |
3772a991 JS |
4130 | struct pci_dev *pdev; |
4131 | int bars; | |
5b75da2f | 4132 | |
3772a991 JS |
4133 | /* Obtain PCI device reference */ |
4134 | if (!phba->pcidev) | |
4135 | return; | |
4136 | else | |
4137 | pdev = phba->pcidev; | |
4138 | /* Select PCI BARs */ | |
4139 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
4140 | /* Release PCI resource and disable PCI device */ | |
4141 | pci_release_selected_regions(pdev, bars); | |
4142 | pci_disable_device(pdev); | |
4143 | /* Null out PCI private reference to driver */ | |
4144 | pci_set_drvdata(pdev, NULL); | |
5b75da2f JS |
4145 | |
4146 | return; | |
4147 | } | |
4148 | ||
e59058c4 | 4149 | /** |
3772a991 JS |
4150 | * lpfc_reset_hba - Reset a hba |
4151 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 4152 | * |
3772a991 JS |
4153 | * This routine is invoked to reset a hba device. It brings the HBA |
4154 | * offline, performs a board restart, and then brings the board back | |
4155 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up | |
4156 | * on outstanding mailbox commands. | |
e59058c4 | 4157 | **/ |
3772a991 JS |
4158 | void |
4159 | lpfc_reset_hba(struct lpfc_hba *phba) | |
dea3101e | 4160 | { |
3772a991 JS |
4161 | /* If resets are disabled then set error state and return. */ |
4162 | if (!phba->cfg_enable_hba_reset) { | |
4163 | phba->link_state = LPFC_HBA_ERROR; | |
4164 | return; | |
4165 | } | |
4166 | lpfc_offline_prep(phba); | |
4167 | lpfc_offline(phba); | |
4168 | lpfc_sli_brdrestart(phba); | |
4169 | lpfc_online(phba); | |
4170 | lpfc_unblock_mgmt_io(phba); | |
4171 | } | |
dea3101e | 4172 | |
0a96e975 JS |
4173 | /** |
4174 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions | |
4175 | * @phba: pointer to lpfc hba data structure. | |
4176 | * | |
4177 | * This function enables the PCI SR-IOV virtual functions to a physical | |
4178 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to | |
4179 | * enable the number of virtual functions to the physical function. As | |
4180 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() | |
4181 | * API call does not considered as an error condition for most of the device. | |
4182 | **/ | |
4183 | uint16_t | |
4184 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) | |
4185 | { | |
4186 | struct pci_dev *pdev = phba->pcidev; | |
4187 | uint16_t nr_virtfn; | |
4188 | int pos; | |
4189 | ||
0a96e975 JS |
4190 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
4191 | if (pos == 0) | |
4192 | return 0; | |
4193 | ||
4194 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); | |
4195 | return nr_virtfn; | |
4196 | } | |
4197 | ||
912e3acd JS |
4198 | /** |
4199 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions | |
4200 | * @phba: pointer to lpfc hba data structure. | |
4201 | * @nr_vfn: number of virtual functions to be enabled. | |
4202 | * | |
4203 | * This function enables the PCI SR-IOV virtual functions to a physical | |
4204 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to | |
4205 | * enable the number of virtual functions to the physical function. As | |
4206 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() | |
4207 | * API call does not considered as an error condition for most of the device. | |
4208 | **/ | |
4209 | int | |
4210 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) | |
4211 | { | |
4212 | struct pci_dev *pdev = phba->pcidev; | |
0a96e975 | 4213 | uint16_t max_nr_vfn; |
912e3acd JS |
4214 | int rc; |
4215 | ||
0a96e975 JS |
4216 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
4217 | if (nr_vfn > max_nr_vfn) { | |
4218 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4219 | "3057 Requested vfs (%d) greater than " | |
4220 | "supported vfs (%d)", nr_vfn, max_nr_vfn); | |
4221 | return -EINVAL; | |
4222 | } | |
4223 | ||
912e3acd JS |
4224 | rc = pci_enable_sriov(pdev, nr_vfn); |
4225 | if (rc) { | |
4226 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4227 | "2806 Failed to enable sriov on this device " | |
4228 | "with vfn number nr_vf:%d, rc:%d\n", | |
4229 | nr_vfn, rc); | |
4230 | } else | |
4231 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4232 | "2807 Successful enable sriov on this device " | |
4233 | "with vfn number nr_vf:%d\n", nr_vfn); | |
4234 | return rc; | |
4235 | } | |
4236 | ||
3772a991 JS |
4237 | /** |
4238 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. | |
4239 | * @phba: pointer to lpfc hba data structure. | |
4240 | * | |
4241 | * This routine is invoked to set up the driver internal resources specific to | |
4242 | * support the SLI-3 HBA device it attached to. | |
4243 | * | |
4244 | * Return codes | |
af901ca1 | 4245 | * 0 - successful |
3772a991 JS |
4246 | * other values - error |
4247 | **/ | |
4248 | static int | |
4249 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) | |
4250 | { | |
4251 | struct lpfc_sli *psli; | |
912e3acd | 4252 | int rc; |
dea3101e | 4253 | |
2e0fef85 | 4254 | /* |
3772a991 | 4255 | * Initialize timers used by driver |
2e0fef85 | 4256 | */ |
dea3101e | 4257 | |
3772a991 | 4258 | /* Heartbeat timer */ |
858c9f6c JS |
4259 | init_timer(&phba->hb_tmofunc); |
4260 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
4261 | phba->hb_tmofunc.data = (unsigned long)phba; | |
4262 | ||
dea3101e | 4263 | psli = &phba->sli; |
3772a991 | 4264 | /* MBOX heartbeat timer */ |
dea3101e JB |
4265 | init_timer(&psli->mbox_tmo); |
4266 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
2e0fef85 | 4267 | psli->mbox_tmo.data = (unsigned long) phba; |
3772a991 | 4268 | /* FCP polling mode timer */ |
875fbdfe JSEC |
4269 | init_timer(&phba->fcp_poll_timer); |
4270 | phba->fcp_poll_timer.function = lpfc_poll_timeout; | |
2e0fef85 | 4271 | phba->fcp_poll_timer.data = (unsigned long) phba; |
3772a991 | 4272 | /* Fabric block timer */ |
92d7f7b0 JS |
4273 | init_timer(&phba->fabric_block_timer); |
4274 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
4275 | phba->fabric_block_timer.data = (unsigned long) phba; | |
3772a991 | 4276 | /* EA polling mode timer */ |
9399627f JS |
4277 | init_timer(&phba->eratt_poll); |
4278 | phba->eratt_poll.function = lpfc_poll_eratt; | |
4279 | phba->eratt_poll.data = (unsigned long) phba; | |
dea3101e | 4280 | |
3772a991 JS |
4281 | /* Host attention work mask setup */ |
4282 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); | |
4283 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); | |
dea3101e | 4284 | |
3772a991 JS |
4285 | /* Get all the module params for configuring this host */ |
4286 | lpfc_get_cfgparam(phba); | |
49198b37 JS |
4287 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
4288 | phba->menlo_flag |= HBA_MENLO_SUPPORT; | |
4289 | /* check for menlo minimum sg count */ | |
4290 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) | |
4291 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; | |
4292 | } | |
4293 | ||
dea3101e | 4294 | /* |
3772a991 JS |
4295 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size |
4296 | * used to create the sg_dma_buf_pool must be dynamically calculated. | |
4297 | * 2 segments are added since the IOCB needs a command and response bde. | |
dea3101e | 4298 | */ |
3772a991 JS |
4299 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
4300 | sizeof(struct fcp_rsp) + | |
4301 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); | |
4302 | ||
4303 | if (phba->cfg_enable_bg) { | |
4304 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT; | |
4305 | phba->cfg_sg_dma_buf_size += | |
4306 | phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64); | |
901a920f | 4307 | } |
dea3101e | 4308 | |
3772a991 JS |
4309 | /* Also reinitialize the host templates with new values. */ |
4310 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
4311 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
dea3101e | 4312 | |
3772a991 JS |
4313 | phba->max_vpi = LPFC_MAX_VPI; |
4314 | /* This will be set to correct value after config_port mbox */ | |
4315 | phba->max_vports = 0; | |
dea3101e | 4316 | |
3772a991 JS |
4317 | /* |
4318 | * Initialize the SLI Layer to run with lpfc HBAs. | |
4319 | */ | |
4320 | lpfc_sli_setup(phba); | |
4321 | lpfc_sli_queue_setup(phba); | |
ed957684 | 4322 | |
3772a991 JS |
4323 | /* Allocate device driver memory */ |
4324 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) | |
4325 | return -ENOMEM; | |
51ef4c26 | 4326 | |
912e3acd JS |
4327 | /* |
4328 | * Enable sr-iov virtual functions if supported and configured | |
4329 | * through the module parameter. | |
4330 | */ | |
4331 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
4332 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, | |
4333 | phba->cfg_sriov_nr_virtfn); | |
4334 | if (rc) { | |
4335 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4336 | "2808 Requested number of SR-IOV " | |
4337 | "virtual functions (%d) is not " | |
4338 | "supported\n", | |
4339 | phba->cfg_sriov_nr_virtfn); | |
4340 | phba->cfg_sriov_nr_virtfn = 0; | |
4341 | } | |
4342 | } | |
4343 | ||
3772a991 JS |
4344 | return 0; |
4345 | } | |
ed957684 | 4346 | |
3772a991 JS |
4347 | /** |
4348 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev | |
4349 | * @phba: pointer to lpfc hba data structure. | |
4350 | * | |
4351 | * This routine is invoked to unset the driver internal resources set up | |
4352 | * specific for supporting the SLI-3 HBA device it attached to. | |
4353 | **/ | |
4354 | static void | |
4355 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) | |
4356 | { | |
4357 | /* Free device driver memory allocated */ | |
4358 | lpfc_mem_free_all(phba); | |
3163f725 | 4359 | |
3772a991 JS |
4360 | return; |
4361 | } | |
dea3101e | 4362 | |
3772a991 | 4363 | /** |
da0436e9 | 4364 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
3772a991 JS |
4365 | * @phba: pointer to lpfc hba data structure. |
4366 | * | |
da0436e9 JS |
4367 | * This routine is invoked to set up the driver internal resources specific to |
4368 | * support the SLI-4 HBA device it attached to. | |
3772a991 JS |
4369 | * |
4370 | * Return codes | |
af901ca1 | 4371 | * 0 - successful |
da0436e9 | 4372 | * other values - error |
3772a991 JS |
4373 | **/ |
4374 | static int | |
da0436e9 | 4375 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
3772a991 | 4376 | { |
da0436e9 | 4377 | struct lpfc_sli *psli; |
28baac74 JS |
4378 | LPFC_MBOXQ_t *mboxq; |
4379 | int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size; | |
4380 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; | |
4381 | struct lpfc_mqe *mqe; | |
085c647c | 4382 | int longs, sli_family; |
da0436e9 JS |
4383 | |
4384 | /* Before proceed, wait for POST done and device ready */ | |
4385 | rc = lpfc_sli4_post_status_check(phba); | |
4386 | if (rc) | |
4387 | return -ENODEV; | |
4388 | ||
3772a991 | 4389 | /* |
da0436e9 | 4390 | * Initialize timers used by driver |
3772a991 | 4391 | */ |
3772a991 | 4392 | |
da0436e9 JS |
4393 | /* Heartbeat timer */ |
4394 | init_timer(&phba->hb_tmofunc); | |
4395 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
4396 | phba->hb_tmofunc.data = (unsigned long)phba; | |
19ca7609 JS |
4397 | init_timer(&phba->rrq_tmr); |
4398 | phba->rrq_tmr.function = lpfc_rrq_timeout; | |
4399 | phba->rrq_tmr.data = (unsigned long)phba; | |
3772a991 | 4400 | |
da0436e9 JS |
4401 | psli = &phba->sli; |
4402 | /* MBOX heartbeat timer */ | |
4403 | init_timer(&psli->mbox_tmo); | |
4404 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
4405 | psli->mbox_tmo.data = (unsigned long) phba; | |
4406 | /* Fabric block timer */ | |
4407 | init_timer(&phba->fabric_block_timer); | |
4408 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
4409 | phba->fabric_block_timer.data = (unsigned long) phba; | |
4410 | /* EA polling mode timer */ | |
4411 | init_timer(&phba->eratt_poll); | |
4412 | phba->eratt_poll.function = lpfc_poll_eratt; | |
4413 | phba->eratt_poll.data = (unsigned long) phba; | |
ecfd03c6 JS |
4414 | /* FCF rediscover timer */ |
4415 | init_timer(&phba->fcf.redisc_wait); | |
4416 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; | |
4417 | phba->fcf.redisc_wait.data = (unsigned long)phba; | |
4418 | ||
7ad20aa9 JS |
4419 | /* |
4420 | * Control structure for handling external multi-buffer mailbox | |
4421 | * command pass-through. | |
4422 | */ | |
4423 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, | |
4424 | sizeof(struct lpfc_mbox_ext_buf_ctx)); | |
4425 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); | |
4426 | ||
da0436e9 JS |
4427 | /* |
4428 | * We need to do a READ_CONFIG mailbox command here before | |
4429 | * calling lpfc_get_cfgparam. For VFs this will report the | |
4430 | * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings. | |
4431 | * All of the resources allocated | |
4432 | * for this Port are tied to these values. | |
4433 | */ | |
4434 | /* Get all the module params for configuring this host */ | |
4435 | lpfc_get_cfgparam(phba); | |
4436 | phba->max_vpi = LPFC_MAX_VPI; | |
4437 | /* This will be set to correct value after the read_config mbox */ | |
4438 | phba->max_vports = 0; | |
3772a991 | 4439 | |
da0436e9 JS |
4440 | /* Program the default value of vlan_id and fc_map */ |
4441 | phba->valid_vlan = 0; | |
4442 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4443 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4444 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
3772a991 | 4445 | |
da0436e9 JS |
4446 | /* |
4447 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size | |
4448 | * used to create the sg_dma_buf_pool must be dynamically calculated. | |
4449 | * 2 segments are added since the IOCB needs a command and response bde. | |
4450 | * To insure that the scsi sgl does not cross a 4k page boundary only | |
28baac74 | 4451 | * sgl sizes of must be a power of 2. |
da0436e9 | 4452 | */ |
28baac74 JS |
4453 | buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) + |
4454 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge))); | |
085c647c JS |
4455 | |
4456 | sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf); | |
4457 | max_buf_size = LPFC_SLI4_MAX_BUF_SIZE; | |
4458 | switch (sli_family) { | |
4459 | case LPFC_SLI_INTF_FAMILY_BE2: | |
4460 | case LPFC_SLI_INTF_FAMILY_BE3: | |
4461 | /* There is a single hint for BE - 2 pages per BPL. */ | |
4462 | if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) == | |
4463 | LPFC_SLI_INTF_SLI_HINT1_1) | |
4464 | max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE; | |
4465 | break; | |
4466 | case LPFC_SLI_INTF_FAMILY_LNCR_A0: | |
4467 | case LPFC_SLI_INTF_FAMILY_LNCR_B0: | |
4468 | default: | |
4469 | break; | |
4470 | } | |
28baac74 JS |
4471 | for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE; |
4472 | dma_buf_size < max_buf_size && buf_size > dma_buf_size; | |
4473 | dma_buf_size = dma_buf_size << 1) | |
4474 | ; | |
4475 | if (dma_buf_size == max_buf_size) | |
4476 | phba->cfg_sg_seg_cnt = (dma_buf_size - | |
4477 | sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) - | |
4478 | (2 * sizeof(struct sli4_sge))) / | |
4479 | sizeof(struct sli4_sge); | |
4480 | phba->cfg_sg_dma_buf_size = dma_buf_size; | |
3772a991 | 4481 | |
da0436e9 JS |
4482 | /* Initialize buffer queue management fields */ |
4483 | hbq_count = lpfc_sli_hbq_count(); | |
4484 | for (i = 0; i < hbq_count; ++i) | |
4485 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
4486 | INIT_LIST_HEAD(&phba->rb_pend_list); | |
4487 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; | |
4488 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; | |
3772a991 | 4489 | |
da0436e9 JS |
4490 | /* |
4491 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. | |
4492 | */ | |
4493 | /* Initialize the Abort scsi buffer list used by driver */ | |
4494 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
4495 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
4496 | /* This abort list used by worker thread */ | |
4497 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); | |
3772a991 | 4498 | |
da0436e9 | 4499 | /* |
6d368e53 | 4500 | * Initialize driver internal slow-path work queues |
da0436e9 | 4501 | */ |
3772a991 | 4502 | |
da0436e9 JS |
4503 | /* Driver internel slow-path CQ Event pool */ |
4504 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); | |
4505 | /* Response IOCB work queue list */ | |
45ed1190 | 4506 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
da0436e9 JS |
4507 | /* Asynchronous event CQ Event work queue list */ |
4508 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); | |
4509 | /* Fast-path XRI aborted CQ Event work queue list */ | |
4510 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
4511 | /* Slow-path XRI aborted CQ Event work queue list */ | |
4512 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
4513 | /* Receive queue CQ Event work queue list */ | |
4514 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); | |
4515 | ||
6d368e53 JS |
4516 | /* Initialize extent block lists. */ |
4517 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); | |
4518 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); | |
4519 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); | |
4520 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); | |
4521 | ||
da0436e9 JS |
4522 | /* Initialize the driver internal SLI layer lists. */ |
4523 | lpfc_sli_setup(phba); | |
4524 | lpfc_sli_queue_setup(phba); | |
3772a991 | 4525 | |
da0436e9 JS |
4526 | /* Allocate device driver memory */ |
4527 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); | |
4528 | if (rc) | |
4529 | return -ENOMEM; | |
4530 | ||
2fcee4bf JS |
4531 | /* IF Type 2 ports get initialized now. */ |
4532 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
4533 | LPFC_SLI_INTF_IF_TYPE_2) { | |
4534 | rc = lpfc_pci_function_reset(phba); | |
4535 | if (unlikely(rc)) | |
4536 | return -ENODEV; | |
4537 | } | |
4538 | ||
da0436e9 JS |
4539 | /* Create the bootstrap mailbox command */ |
4540 | rc = lpfc_create_bootstrap_mbox(phba); | |
4541 | if (unlikely(rc)) | |
4542 | goto out_free_mem; | |
4543 | ||
4544 | /* Set up the host's endian order with the device. */ | |
4545 | rc = lpfc_setup_endian_order(phba); | |
4546 | if (unlikely(rc)) | |
4547 | goto out_free_bsmbx; | |
4548 | ||
4549 | /* Set up the hba's configuration parameters. */ | |
4550 | rc = lpfc_sli4_read_config(phba); | |
4551 | if (unlikely(rc)) | |
4552 | goto out_free_bsmbx; | |
4553 | ||
2fcee4bf JS |
4554 | /* IF Type 0 ports get initialized now. */ |
4555 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
4556 | LPFC_SLI_INTF_IF_TYPE_0) { | |
4557 | rc = lpfc_pci_function_reset(phba); | |
4558 | if (unlikely(rc)) | |
4559 | goto out_free_bsmbx; | |
4560 | } | |
da0436e9 | 4561 | |
cb5172ea JS |
4562 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
4563 | GFP_KERNEL); | |
4564 | if (!mboxq) { | |
4565 | rc = -ENOMEM; | |
4566 | goto out_free_bsmbx; | |
4567 | } | |
4568 | ||
fedd3b7b | 4569 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
cb5172ea JS |
4570 | lpfc_supported_pages(mboxq); |
4571 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
fedd3b7b JS |
4572 | if (!rc) { |
4573 | mqe = &mboxq->u.mqe; | |
4574 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), | |
4575 | LPFC_MAX_SUPPORTED_PAGES); | |
4576 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { | |
4577 | switch (pn_page[i]) { | |
4578 | case LPFC_SLI4_PARAMETERS: | |
4579 | phba->sli4_hba.pc_sli4_params.supported = 1; | |
4580 | break; | |
4581 | default: | |
4582 | break; | |
4583 | } | |
4584 | } | |
4585 | /* Read the port's SLI4 Parameters capabilities if supported. */ | |
4586 | if (phba->sli4_hba.pc_sli4_params.supported) | |
4587 | rc = lpfc_pc_sli4_params_get(phba, mboxq); | |
4588 | if (rc) { | |
4589 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4590 | rc = -EIO; | |
4591 | goto out_free_bsmbx; | |
cb5172ea JS |
4592 | } |
4593 | } | |
fedd3b7b JS |
4594 | /* |
4595 | * Get sli4 parameters that override parameters from Port capabilities. | |
6d368e53 JS |
4596 | * If this call fails, it isn't critical unless the SLI4 parameters come |
4597 | * back in conflict. | |
fedd3b7b | 4598 | */ |
6d368e53 JS |
4599 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
4600 | if (rc) { | |
4601 | if (phba->sli4_hba.extents_in_use && | |
4602 | phba->sli4_hba.rpi_hdrs_in_use) { | |
4603 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4604 | "2999 Unsupported SLI4 Parameters " | |
4605 | "Extents and RPI headers enabled.\n"); | |
4606 | goto out_free_bsmbx; | |
4607 | } | |
4608 | } | |
cb5172ea | 4609 | mempool_free(mboxq, phba->mbox_mem_pool); |
5350d872 JS |
4610 | /* Verify all the SLI4 queues */ |
4611 | rc = lpfc_sli4_queue_verify(phba); | |
da0436e9 JS |
4612 | if (rc) |
4613 | goto out_free_bsmbx; | |
4614 | ||
4615 | /* Create driver internal CQE event pool */ | |
4616 | rc = lpfc_sli4_cq_event_pool_create(phba); | |
4617 | if (rc) | |
5350d872 | 4618 | goto out_free_bsmbx; |
da0436e9 JS |
4619 | |
4620 | /* Initialize and populate the iocb list per host */ | |
4621 | rc = lpfc_init_sgl_list(phba); | |
4622 | if (rc) { | |
4623 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4624 | "1400 Failed to initialize sgl list.\n"); | |
4625 | goto out_destroy_cq_event_pool; | |
4626 | } | |
4627 | rc = lpfc_init_active_sgl_array(phba); | |
4628 | if (rc) { | |
4629 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4630 | "1430 Failed to initialize sgl list.\n"); | |
4631 | goto out_free_sgl_list; | |
4632 | } | |
da0436e9 JS |
4633 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
4634 | if (rc) { | |
4635 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4636 | "1432 Failed to initialize rpi headers.\n"); | |
4637 | goto out_free_active_sgl; | |
4638 | } | |
4639 | ||
a93ff37a | 4640 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
0c9ab6f5 JS |
4641 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
4642 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), | |
4643 | GFP_KERNEL); | |
4644 | if (!phba->fcf.fcf_rr_bmask) { | |
4645 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4646 | "2759 Failed allocate memory for FCF round " | |
4647 | "robin failover bmask\n"); | |
0558056c | 4648 | rc = -ENOMEM; |
0c9ab6f5 JS |
4649 | goto out_remove_rpi_hdrs; |
4650 | } | |
4651 | ||
5350d872 JS |
4652 | /* |
4653 | * The cfg_fcp_eq_count can be zero whenever there is exactly one | |
4654 | * interrupt vector. This is not an error | |
4655 | */ | |
4656 | if (phba->cfg_fcp_eq_count) { | |
4657 | phba->sli4_hba.fcp_eq_hdl = | |
4658 | kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * | |
da0436e9 | 4659 | phba->cfg_fcp_eq_count), GFP_KERNEL); |
5350d872 JS |
4660 | if (!phba->sli4_hba.fcp_eq_hdl) { |
4661 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4662 | "2572 Failed allocate memory for " | |
4663 | "fast-path per-EQ handle array\n"); | |
4664 | rc = -ENOMEM; | |
4665 | goto out_free_fcf_rr_bmask; | |
4666 | } | |
da0436e9 JS |
4667 | } |
4668 | ||
4669 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * | |
4670 | phba->sli4_hba.cfg_eqn), GFP_KERNEL); | |
4671 | if (!phba->sli4_hba.msix_entries) { | |
4672 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4673 | "2573 Failed allocate memory for msi-x " | |
4674 | "interrupt vector entries\n"); | |
0558056c | 4675 | rc = -ENOMEM; |
da0436e9 JS |
4676 | goto out_free_fcp_eq_hdl; |
4677 | } | |
4678 | ||
912e3acd JS |
4679 | /* |
4680 | * Enable sr-iov virtual functions if supported and configured | |
4681 | * through the module parameter. | |
4682 | */ | |
4683 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
4684 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, | |
4685 | phba->cfg_sriov_nr_virtfn); | |
4686 | if (rc) { | |
4687 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4688 | "3020 Requested number of SR-IOV " | |
4689 | "virtual functions (%d) is not " | |
4690 | "supported\n", | |
4691 | phba->cfg_sriov_nr_virtfn); | |
4692 | phba->cfg_sriov_nr_virtfn = 0; | |
4693 | } | |
4694 | } | |
4695 | ||
5248a749 | 4696 | return 0; |
da0436e9 JS |
4697 | |
4698 | out_free_fcp_eq_hdl: | |
4699 | kfree(phba->sli4_hba.fcp_eq_hdl); | |
0c9ab6f5 JS |
4700 | out_free_fcf_rr_bmask: |
4701 | kfree(phba->fcf.fcf_rr_bmask); | |
da0436e9 JS |
4702 | out_remove_rpi_hdrs: |
4703 | lpfc_sli4_remove_rpi_hdrs(phba); | |
4704 | out_free_active_sgl: | |
4705 | lpfc_free_active_sgl(phba); | |
4706 | out_free_sgl_list: | |
4707 | lpfc_free_sgl_list(phba); | |
4708 | out_destroy_cq_event_pool: | |
4709 | lpfc_sli4_cq_event_pool_destroy(phba); | |
da0436e9 JS |
4710 | out_free_bsmbx: |
4711 | lpfc_destroy_bootstrap_mbox(phba); | |
4712 | out_free_mem: | |
4713 | lpfc_mem_free(phba); | |
4714 | return rc; | |
4715 | } | |
4716 | ||
4717 | /** | |
4718 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev | |
4719 | * @phba: pointer to lpfc hba data structure. | |
4720 | * | |
4721 | * This routine is invoked to unset the driver internal resources set up | |
4722 | * specific for supporting the SLI-4 HBA device it attached to. | |
4723 | **/ | |
4724 | static void | |
4725 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) | |
4726 | { | |
4727 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; | |
4728 | ||
da0436e9 JS |
4729 | /* Free memory allocated for msi-x interrupt vector entries */ |
4730 | kfree(phba->sli4_hba.msix_entries); | |
4731 | ||
4732 | /* Free memory allocated for fast-path work queue handles */ | |
4733 | kfree(phba->sli4_hba.fcp_eq_hdl); | |
4734 | ||
4735 | /* Free the allocated rpi headers. */ | |
4736 | lpfc_sli4_remove_rpi_hdrs(phba); | |
d11e31dd | 4737 | lpfc_sli4_remove_rpis(phba); |
da0436e9 | 4738 | |
0c9ab6f5 JS |
4739 | /* Free eligible FCF index bmask */ |
4740 | kfree(phba->fcf.fcf_rr_bmask); | |
4741 | ||
da0436e9 JS |
4742 | /* Free the ELS sgl list */ |
4743 | lpfc_free_active_sgl(phba); | |
4744 | lpfc_free_sgl_list(phba); | |
4745 | ||
4746 | /* Free the SCSI sgl management array */ | |
4747 | kfree(phba->sli4_hba.lpfc_scsi_psb_array); | |
4748 | ||
da0436e9 JS |
4749 | /* Free the completion queue EQ event pool */ |
4750 | lpfc_sli4_cq_event_release_all(phba); | |
4751 | lpfc_sli4_cq_event_pool_destroy(phba); | |
4752 | ||
6d368e53 JS |
4753 | /* Release resource identifiers. */ |
4754 | lpfc_sli4_dealloc_resource_identifiers(phba); | |
4755 | ||
da0436e9 JS |
4756 | /* Free the bsmbx region. */ |
4757 | lpfc_destroy_bootstrap_mbox(phba); | |
4758 | ||
4759 | /* Free the SLI Layer memory with SLI4 HBAs */ | |
4760 | lpfc_mem_free_all(phba); | |
4761 | ||
4762 | /* Free the current connect table */ | |
4763 | list_for_each_entry_safe(conn_entry, next_conn_entry, | |
4d9ab994 JS |
4764 | &phba->fcf_conn_rec_list, list) { |
4765 | list_del_init(&conn_entry->list); | |
da0436e9 | 4766 | kfree(conn_entry); |
4d9ab994 | 4767 | } |
da0436e9 JS |
4768 | |
4769 | return; | |
4770 | } | |
4771 | ||
4772 | /** | |
25985edc | 4773 | * lpfc_init_api_table_setup - Set up init api function jump table |
da0436e9 JS |
4774 | * @phba: The hba struct for which this call is being executed. |
4775 | * @dev_grp: The HBA PCI-Device group number. | |
4776 | * | |
4777 | * This routine sets up the device INIT interface API function jump table | |
4778 | * in @phba struct. | |
4779 | * | |
4780 | * Returns: 0 - success, -ENODEV - failure. | |
4781 | **/ | |
4782 | int | |
4783 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
4784 | { | |
84d1b006 JS |
4785 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
4786 | phba->lpfc_hba_down_link = lpfc_hba_down_link; | |
7f86059a | 4787 | phba->lpfc_selective_reset = lpfc_selective_reset; |
da0436e9 JS |
4788 | switch (dev_grp) { |
4789 | case LPFC_PCI_DEV_LP: | |
4790 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; | |
4791 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; | |
4792 | phba->lpfc_stop_port = lpfc_stop_port_s3; | |
4793 | break; | |
4794 | case LPFC_PCI_DEV_OC: | |
4795 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; | |
4796 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; | |
4797 | phba->lpfc_stop_port = lpfc_stop_port_s4; | |
4798 | break; | |
4799 | default: | |
4800 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4801 | "1431 Invalid HBA PCI-device group: 0x%x\n", | |
4802 | dev_grp); | |
4803 | return -ENODEV; | |
4804 | break; | |
4805 | } | |
4806 | return 0; | |
4807 | } | |
4808 | ||
4809 | /** | |
4810 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. | |
4811 | * @phba: pointer to lpfc hba data structure. | |
4812 | * | |
4813 | * This routine is invoked to set up the driver internal resources before the | |
4814 | * device specific resource setup to support the HBA device it attached to. | |
4815 | * | |
4816 | * Return codes | |
af901ca1 | 4817 | * 0 - successful |
da0436e9 JS |
4818 | * other values - error |
4819 | **/ | |
4820 | static int | |
4821 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) | |
4822 | { | |
4823 | /* | |
4824 | * Driver resources common to all SLI revisions | |
4825 | */ | |
4826 | atomic_set(&phba->fast_event_count, 0); | |
4827 | spin_lock_init(&phba->hbalock); | |
4828 | ||
4829 | /* Initialize ndlp management spinlock */ | |
4830 | spin_lock_init(&phba->ndlp_lock); | |
4831 | ||
4832 | INIT_LIST_HEAD(&phba->port_list); | |
4833 | INIT_LIST_HEAD(&phba->work_list); | |
4834 | init_waitqueue_head(&phba->wait_4_mlo_m_q); | |
4835 | ||
4836 | /* Initialize the wait queue head for the kernel thread */ | |
4837 | init_waitqueue_head(&phba->work_waitq); | |
4838 | ||
4839 | /* Initialize the scsi buffer list used by driver for scsi IO */ | |
4840 | spin_lock_init(&phba->scsi_buf_list_lock); | |
4841 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); | |
4842 | ||
4843 | /* Initialize the fabric iocb list */ | |
4844 | INIT_LIST_HEAD(&phba->fabric_iocb_list); | |
4845 | ||
4846 | /* Initialize list to save ELS buffers */ | |
4847 | INIT_LIST_HEAD(&phba->elsbuf); | |
4848 | ||
4849 | /* Initialize FCF connection rec list */ | |
4850 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); | |
4851 | ||
4852 | return 0; | |
4853 | } | |
4854 | ||
4855 | /** | |
4856 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. | |
4857 | * @phba: pointer to lpfc hba data structure. | |
4858 | * | |
4859 | * This routine is invoked to set up the driver internal resources after the | |
4860 | * device specific resource setup to support the HBA device it attached to. | |
4861 | * | |
4862 | * Return codes | |
af901ca1 | 4863 | * 0 - successful |
da0436e9 JS |
4864 | * other values - error |
4865 | **/ | |
4866 | static int | |
4867 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) | |
4868 | { | |
4869 | int error; | |
4870 | ||
4871 | /* Startup the kernel thread for this host adapter. */ | |
4872 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
4873 | "lpfc_worker_%d", phba->brd_no); | |
4874 | if (IS_ERR(phba->worker_thread)) { | |
4875 | error = PTR_ERR(phba->worker_thread); | |
4876 | return error; | |
3772a991 JS |
4877 | } |
4878 | ||
4879 | return 0; | |
4880 | } | |
4881 | ||
4882 | /** | |
4883 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. | |
4884 | * @phba: pointer to lpfc hba data structure. | |
4885 | * | |
4886 | * This routine is invoked to unset the driver internal resources set up after | |
4887 | * the device specific resource setup for supporting the HBA device it | |
4888 | * attached to. | |
4889 | **/ | |
4890 | static void | |
4891 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) | |
4892 | { | |
4893 | /* Stop kernel worker thread */ | |
4894 | kthread_stop(phba->worker_thread); | |
4895 | } | |
4896 | ||
4897 | /** | |
4898 | * lpfc_free_iocb_list - Free iocb list. | |
4899 | * @phba: pointer to lpfc hba data structure. | |
4900 | * | |
4901 | * This routine is invoked to free the driver's IOCB list and memory. | |
4902 | **/ | |
4903 | static void | |
4904 | lpfc_free_iocb_list(struct lpfc_hba *phba) | |
4905 | { | |
4906 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; | |
4907 | ||
4908 | spin_lock_irq(&phba->hbalock); | |
4909 | list_for_each_entry_safe(iocbq_entry, iocbq_next, | |
4910 | &phba->lpfc_iocb_list, list) { | |
4911 | list_del(&iocbq_entry->list); | |
4912 | kfree(iocbq_entry); | |
4913 | phba->total_iocbq_bufs--; | |
98c9ea5c | 4914 | } |
3772a991 JS |
4915 | spin_unlock_irq(&phba->hbalock); |
4916 | ||
4917 | return; | |
4918 | } | |
4919 | ||
4920 | /** | |
4921 | * lpfc_init_iocb_list - Allocate and initialize iocb list. | |
4922 | * @phba: pointer to lpfc hba data structure. | |
4923 | * | |
4924 | * This routine is invoked to allocate and initizlize the driver's IOCB | |
4925 | * list and set up the IOCB tag array accordingly. | |
4926 | * | |
4927 | * Return codes | |
af901ca1 | 4928 | * 0 - successful |
3772a991 JS |
4929 | * other values - error |
4930 | **/ | |
4931 | static int | |
4932 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) | |
4933 | { | |
4934 | struct lpfc_iocbq *iocbq_entry = NULL; | |
4935 | uint16_t iotag; | |
4936 | int i; | |
dea3101e JB |
4937 | |
4938 | /* Initialize and populate the iocb list per host. */ | |
4939 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); | |
3772a991 | 4940 | for (i = 0; i < iocb_count; i++) { |
dd00cc48 | 4941 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
dea3101e JB |
4942 | if (iocbq_entry == NULL) { |
4943 | printk(KERN_ERR "%s: only allocated %d iocbs of " | |
4944 | "expected %d count. Unloading driver.\n", | |
cadbd4a5 | 4945 | __func__, i, LPFC_IOCB_LIST_CNT); |
dea3101e JB |
4946 | goto out_free_iocbq; |
4947 | } | |
4948 | ||
604a3e30 JB |
4949 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
4950 | if (iotag == 0) { | |
3772a991 | 4951 | kfree(iocbq_entry); |
604a3e30 | 4952 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
3772a991 | 4953 | "Unloading driver.\n", __func__); |
604a3e30 JB |
4954 | goto out_free_iocbq; |
4955 | } | |
6d368e53 | 4956 | iocbq_entry->sli4_lxritag = NO_XRI; |
3772a991 | 4957 | iocbq_entry->sli4_xritag = NO_XRI; |
2e0fef85 JS |
4958 | |
4959 | spin_lock_irq(&phba->hbalock); | |
dea3101e JB |
4960 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
4961 | phba->total_iocbq_bufs++; | |
2e0fef85 | 4962 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
4963 | } |
4964 | ||
3772a991 | 4965 | return 0; |
dea3101e | 4966 | |
3772a991 JS |
4967 | out_free_iocbq: |
4968 | lpfc_free_iocb_list(phba); | |
dea3101e | 4969 | |
3772a991 JS |
4970 | return -ENOMEM; |
4971 | } | |
5e9d9b82 | 4972 | |
3772a991 | 4973 | /** |
da0436e9 JS |
4974 | * lpfc_free_sgl_list - Free sgl list. |
4975 | * @phba: pointer to lpfc hba data structure. | |
3772a991 | 4976 | * |
da0436e9 | 4977 | * This routine is invoked to free the driver's sgl list and memory. |
3772a991 | 4978 | **/ |
da0436e9 JS |
4979 | static void |
4980 | lpfc_free_sgl_list(struct lpfc_hba *phba) | |
3772a991 | 4981 | { |
da0436e9 JS |
4982 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
4983 | LIST_HEAD(sglq_list); | |
dea3101e | 4984 | |
da0436e9 JS |
4985 | spin_lock_irq(&phba->hbalock); |
4986 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); | |
4987 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 4988 | |
da0436e9 JS |
4989 | list_for_each_entry_safe(sglq_entry, sglq_next, |
4990 | &sglq_list, list) { | |
4991 | list_del(&sglq_entry->list); | |
4992 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); | |
4993 | kfree(sglq_entry); | |
4994 | phba->sli4_hba.total_sglq_bufs--; | |
4995 | } | |
da0436e9 JS |
4996 | kfree(phba->sli4_hba.lpfc_els_sgl_array); |
4997 | } | |
92d7f7b0 | 4998 | |
da0436e9 JS |
4999 | /** |
5000 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. | |
5001 | * @phba: pointer to lpfc hba data structure. | |
5002 | * | |
5003 | * This routine is invoked to allocate the driver's active sgl memory. | |
5004 | * This array will hold the sglq_entry's for active IOs. | |
5005 | **/ | |
5006 | static int | |
5007 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) | |
5008 | { | |
5009 | int size; | |
5010 | size = sizeof(struct lpfc_sglq *); | |
5011 | size *= phba->sli4_hba.max_cfg_param.max_xri; | |
5012 | ||
5013 | phba->sli4_hba.lpfc_sglq_active_list = | |
5014 | kzalloc(size, GFP_KERNEL); | |
5015 | if (!phba->sli4_hba.lpfc_sglq_active_list) | |
5016 | return -ENOMEM; | |
5017 | return 0; | |
3772a991 JS |
5018 | } |
5019 | ||
5020 | /** | |
da0436e9 | 5021 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
3772a991 JS |
5022 | * @phba: pointer to lpfc hba data structure. |
5023 | * | |
da0436e9 JS |
5024 | * This routine is invoked to walk through the array of active sglq entries |
5025 | * and free all of the resources. | |
5026 | * This is just a place holder for now. | |
3772a991 JS |
5027 | **/ |
5028 | static void | |
da0436e9 | 5029 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
3772a991 | 5030 | { |
da0436e9 | 5031 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
3772a991 JS |
5032 | } |
5033 | ||
5034 | /** | |
da0436e9 | 5035 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
3772a991 JS |
5036 | * @phba: pointer to lpfc hba data structure. |
5037 | * | |
da0436e9 JS |
5038 | * This routine is invoked to allocate and initizlize the driver's sgl |
5039 | * list and set up the sgl xritag tag array accordingly. | |
3772a991 JS |
5040 | * |
5041 | * Return codes | |
af901ca1 | 5042 | * 0 - successful |
da0436e9 | 5043 | * other values - error |
3772a991 JS |
5044 | **/ |
5045 | static int | |
da0436e9 | 5046 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
3772a991 | 5047 | { |
da0436e9 JS |
5048 | struct lpfc_sglq *sglq_entry = NULL; |
5049 | int i; | |
5050 | int els_xri_cnt; | |
5051 | ||
5052 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
5053 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
6d368e53 | 5054 | "2400 ELS XRI count %d.\n", |
da0436e9 JS |
5055 | els_xri_cnt); |
5056 | /* Initialize and populate the sglq list per host/VF. */ | |
5057 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); | |
5058 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
5059 | ||
5060 | /* Sanity check on XRI management */ | |
5061 | if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) { | |
5062 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5063 | "2562 No room left for SCSI XRI allocation: " | |
5064 | "max_xri=%d, els_xri=%d\n", | |
5065 | phba->sli4_hba.max_cfg_param.max_xri, | |
5066 | els_xri_cnt); | |
5067 | return -ENOMEM; | |
5068 | } | |
3772a991 | 5069 | |
da0436e9 JS |
5070 | /* Allocate memory for the ELS XRI management array */ |
5071 | phba->sli4_hba.lpfc_els_sgl_array = | |
5072 | kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt), | |
5073 | GFP_KERNEL); | |
0ff10d46 | 5074 | |
da0436e9 JS |
5075 | if (!phba->sli4_hba.lpfc_els_sgl_array) { |
5076 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5077 | "2401 Failed to allocate memory for ELS " | |
5078 | "XRI management array of size %d.\n", | |
5079 | els_xri_cnt); | |
5080 | return -ENOMEM; | |
5081 | } | |
2e0fef85 | 5082 | |
da0436e9 JS |
5083 | /* Keep the SCSI XRI into the XRI management array */ |
5084 | phba->sli4_hba.scsi_xri_max = | |
5085 | phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt; | |
5086 | phba->sli4_hba.scsi_xri_cnt = 0; | |
da0436e9 JS |
5087 | phba->sli4_hba.lpfc_scsi_psb_array = |
5088 | kzalloc((sizeof(struct lpfc_scsi_buf *) * | |
5089 | phba->sli4_hba.scsi_xri_max), GFP_KERNEL); | |
5090 | ||
5091 | if (!phba->sli4_hba.lpfc_scsi_psb_array) { | |
5092 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
5093 | "2563 Failed to allocate memory for SCSI " | |
5094 | "XRI management array of size %d.\n", | |
5095 | phba->sli4_hba.scsi_xri_max); | |
5096 | kfree(phba->sli4_hba.lpfc_els_sgl_array); | |
5097 | return -ENOMEM; | |
5098 | } | |
5099 | ||
5100 | for (i = 0; i < els_xri_cnt; i++) { | |
5101 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL); | |
5102 | if (sglq_entry == NULL) { | |
5103 | printk(KERN_ERR "%s: only allocated %d sgls of " | |
5104 | "expected %d count. Unloading driver.\n", | |
5105 | __func__, i, els_xri_cnt); | |
5106 | goto out_free_mem; | |
5107 | } | |
5108 | ||
da0436e9 JS |
5109 | sglq_entry->buff_type = GEN_BUFF_TYPE; |
5110 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys); | |
5111 | if (sglq_entry->virt == NULL) { | |
5112 | kfree(sglq_entry); | |
5113 | printk(KERN_ERR "%s: failed to allocate mbuf.\n" | |
5114 | "Unloading driver.\n", __func__); | |
5115 | goto out_free_mem; | |
5116 | } | |
5117 | sglq_entry->sgl = sglq_entry->virt; | |
5118 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); | |
5119 | ||
5120 | /* The list order is used by later block SGL registraton */ | |
5121 | spin_lock_irq(&phba->hbalock); | |
0f65ff68 | 5122 | sglq_entry->state = SGL_FREED; |
da0436e9 JS |
5123 | list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list); |
5124 | phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry; | |
5125 | phba->sli4_hba.total_sglq_bufs++; | |
5126 | spin_unlock_irq(&phba->hbalock); | |
5127 | } | |
5128 | return 0; | |
5129 | ||
5130 | out_free_mem: | |
5131 | kfree(phba->sli4_hba.lpfc_scsi_psb_array); | |
5132 | lpfc_free_sgl_list(phba); | |
5133 | return -ENOMEM; | |
5134 | } | |
5135 | ||
5136 | /** | |
5137 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port | |
5138 | * @phba: pointer to lpfc hba data structure. | |
5139 | * | |
5140 | * This routine is invoked to post rpi header templates to the | |
88a2cfbb | 5141 | * port for those SLI4 ports that do not support extents. This routine |
da0436e9 | 5142 | * posts a PAGE_SIZE memory region to the port to hold up to |
88a2cfbb JS |
5143 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
5144 | * and should be called only when interrupts are disabled. | |
da0436e9 JS |
5145 | * |
5146 | * Return codes | |
af901ca1 | 5147 | * 0 - successful |
88a2cfbb | 5148 | * -ERROR - otherwise. |
da0436e9 JS |
5149 | **/ |
5150 | int | |
5151 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) | |
5152 | { | |
5153 | int rc = 0; | |
da0436e9 JS |
5154 | struct lpfc_rpi_hdr *rpi_hdr; |
5155 | ||
5156 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); | |
ff78d8f9 | 5157 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
6d368e53 | 5158 | return rc; |
6d368e53 JS |
5159 | if (phba->sli4_hba.extents_in_use) |
5160 | return -EIO; | |
da0436e9 JS |
5161 | |
5162 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
5163 | if (!rpi_hdr) { | |
5164 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5165 | "0391 Error during rpi post operation\n"); | |
5166 | lpfc_sli4_remove_rpis(phba); | |
5167 | rc = -ENODEV; | |
5168 | } | |
5169 | ||
5170 | return rc; | |
5171 | } | |
5172 | ||
5173 | /** | |
5174 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region | |
5175 | * @phba: pointer to lpfc hba data structure. | |
5176 | * | |
5177 | * This routine is invoked to allocate a single 4KB memory region to | |
5178 | * support rpis and stores them in the phba. This single region | |
5179 | * provides support for up to 64 rpis. The region is used globally | |
5180 | * by the device. | |
5181 | * | |
5182 | * Returns: | |
5183 | * A valid rpi hdr on success. | |
5184 | * A NULL pointer on any failure. | |
5185 | **/ | |
5186 | struct lpfc_rpi_hdr * | |
5187 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) | |
5188 | { | |
5189 | uint16_t rpi_limit, curr_rpi_range; | |
5190 | struct lpfc_dmabuf *dmabuf; | |
5191 | struct lpfc_rpi_hdr *rpi_hdr; | |
9589b062 | 5192 | uint32_t rpi_count; |
da0436e9 | 5193 | |
6d368e53 JS |
5194 | /* |
5195 | * If the SLI4 port supports extents, posting the rpi header isn't | |
5196 | * required. Set the expected maximum count and let the actual value | |
5197 | * get set when extents are fully allocated. | |
5198 | */ | |
5199 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
5200 | return NULL; | |
5201 | if (phba->sli4_hba.extents_in_use) | |
5202 | return NULL; | |
5203 | ||
5204 | /* The limit on the logical index is just the max_rpi count. */ | |
da0436e9 | 5205 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + |
6d368e53 | 5206 | phba->sli4_hba.max_cfg_param.max_rpi - 1; |
da0436e9 JS |
5207 | |
5208 | spin_lock_irq(&phba->hbalock); | |
6d368e53 JS |
5209 | /* |
5210 | * Establish the starting RPI in this header block. The starting | |
5211 | * rpi is normalized to a zero base because the physical rpi is | |
5212 | * port based. | |
5213 | */ | |
5214 | curr_rpi_range = phba->sli4_hba.next_rpi - | |
5215 | phba->sli4_hba.max_cfg_param.rpi_base; | |
da0436e9 JS |
5216 | spin_unlock_irq(&phba->hbalock); |
5217 | ||
5218 | /* | |
5219 | * The port has a limited number of rpis. The increment here | |
5220 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value | |
5221 | * and to allow the full max_rpi range per port. | |
5222 | */ | |
5223 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) | |
9589b062 JS |
5224 | rpi_count = rpi_limit - curr_rpi_range; |
5225 | else | |
5226 | rpi_count = LPFC_RPI_HDR_COUNT; | |
da0436e9 | 5227 | |
6d368e53 JS |
5228 | if (!rpi_count) |
5229 | return NULL; | |
da0436e9 JS |
5230 | /* |
5231 | * First allocate the protocol header region for the port. The | |
5232 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. | |
5233 | */ | |
5234 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
5235 | if (!dmabuf) | |
5236 | return NULL; | |
5237 | ||
5238 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
5239 | LPFC_HDR_TEMPLATE_SIZE, | |
5240 | &dmabuf->phys, | |
5241 | GFP_KERNEL); | |
5242 | if (!dmabuf->virt) { | |
5243 | rpi_hdr = NULL; | |
5244 | goto err_free_dmabuf; | |
5245 | } | |
5246 | ||
5247 | memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE); | |
5248 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { | |
5249 | rpi_hdr = NULL; | |
5250 | goto err_free_coherent; | |
5251 | } | |
5252 | ||
5253 | /* Save the rpi header data for cleanup later. */ | |
5254 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); | |
5255 | if (!rpi_hdr) | |
5256 | goto err_free_coherent; | |
5257 | ||
5258 | rpi_hdr->dmabuf = dmabuf; | |
5259 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; | |
5260 | rpi_hdr->page_count = 1; | |
5261 | spin_lock_irq(&phba->hbalock); | |
6d368e53 JS |
5262 | |
5263 | /* The rpi_hdr stores the logical index only. */ | |
5264 | rpi_hdr->start_rpi = curr_rpi_range; | |
da0436e9 JS |
5265 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
5266 | ||
5267 | /* | |
6d368e53 JS |
5268 | * The next_rpi stores the next logical module-64 rpi value used |
5269 | * to post physical rpis in subsequent rpi postings. | |
da0436e9 | 5270 | */ |
9589b062 | 5271 | phba->sli4_hba.next_rpi += rpi_count; |
da0436e9 JS |
5272 | spin_unlock_irq(&phba->hbalock); |
5273 | return rpi_hdr; | |
5274 | ||
5275 | err_free_coherent: | |
5276 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, | |
5277 | dmabuf->virt, dmabuf->phys); | |
5278 | err_free_dmabuf: | |
5279 | kfree(dmabuf); | |
5280 | return NULL; | |
5281 | } | |
5282 | ||
5283 | /** | |
5284 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions | |
5285 | * @phba: pointer to lpfc hba data structure. | |
5286 | * | |
5287 | * This routine is invoked to remove all memory resources allocated | |
6d368e53 JS |
5288 | * to support rpis for SLI4 ports not supporting extents. This routine |
5289 | * presumes the caller has released all rpis consumed by fabric or port | |
5290 | * logins and is prepared to have the header pages removed. | |
da0436e9 JS |
5291 | **/ |
5292 | void | |
5293 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) | |
5294 | { | |
5295 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; | |
5296 | ||
6d368e53 JS |
5297 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
5298 | goto exit; | |
5299 | ||
da0436e9 JS |
5300 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
5301 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { | |
5302 | list_del(&rpi_hdr->list); | |
5303 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, | |
5304 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); | |
5305 | kfree(rpi_hdr->dmabuf); | |
5306 | kfree(rpi_hdr); | |
5307 | } | |
6d368e53 JS |
5308 | exit: |
5309 | /* There are no rpis available to the port now. */ | |
5310 | phba->sli4_hba.next_rpi = 0; | |
da0436e9 JS |
5311 | } |
5312 | ||
5313 | /** | |
5314 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. | |
5315 | * @pdev: pointer to pci device data structure. | |
5316 | * | |
5317 | * This routine is invoked to allocate the driver hba data structure for an | |
5318 | * HBA device. If the allocation is successful, the phba reference to the | |
5319 | * PCI device data structure is set. | |
5320 | * | |
5321 | * Return codes | |
af901ca1 | 5322 | * pointer to @phba - successful |
da0436e9 JS |
5323 | * NULL - error |
5324 | **/ | |
5325 | static struct lpfc_hba * | |
5326 | lpfc_hba_alloc(struct pci_dev *pdev) | |
5327 | { | |
5328 | struct lpfc_hba *phba; | |
5329 | ||
5330 | /* Allocate memory for HBA structure */ | |
5331 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); | |
5332 | if (!phba) { | |
e34ccdfe | 5333 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
da0436e9 JS |
5334 | return NULL; |
5335 | } | |
5336 | ||
5337 | /* Set reference to PCI device in HBA structure */ | |
5338 | phba->pcidev = pdev; | |
5339 | ||
5340 | /* Assign an unused board number */ | |
5341 | phba->brd_no = lpfc_get_instance(); | |
5342 | if (phba->brd_no < 0) { | |
5343 | kfree(phba); | |
5344 | return NULL; | |
5345 | } | |
5346 | ||
4fede78f | 5347 | spin_lock_init(&phba->ct_ev_lock); |
f1c3b0fc JS |
5348 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
5349 | ||
da0436e9 JS |
5350 | return phba; |
5351 | } | |
5352 | ||
5353 | /** | |
5354 | * lpfc_hba_free - Free driver hba data structure with a device. | |
5355 | * @phba: pointer to lpfc hba data structure. | |
5356 | * | |
5357 | * This routine is invoked to free the driver hba data structure with an | |
5358 | * HBA device. | |
5359 | **/ | |
5360 | static void | |
5361 | lpfc_hba_free(struct lpfc_hba *phba) | |
5362 | { | |
5363 | /* Release the driver assigned board number */ | |
5364 | idr_remove(&lpfc_hba_index, phba->brd_no); | |
5365 | ||
5366 | kfree(phba); | |
5367 | return; | |
5368 | } | |
5369 | ||
5370 | /** | |
5371 | * lpfc_create_shost - Create hba physical port with associated scsi host. | |
5372 | * @phba: pointer to lpfc hba data structure. | |
5373 | * | |
5374 | * This routine is invoked to create HBA physical port and associate a SCSI | |
5375 | * host with it. | |
5376 | * | |
5377 | * Return codes | |
af901ca1 | 5378 | * 0 - successful |
da0436e9 JS |
5379 | * other values - error |
5380 | **/ | |
5381 | static int | |
5382 | lpfc_create_shost(struct lpfc_hba *phba) | |
5383 | { | |
5384 | struct lpfc_vport *vport; | |
5385 | struct Scsi_Host *shost; | |
5386 | ||
5387 | /* Initialize HBA FC structure */ | |
5388 | phba->fc_edtov = FF_DEF_EDTOV; | |
5389 | phba->fc_ratov = FF_DEF_RATOV; | |
5390 | phba->fc_altov = FF_DEF_ALTOV; | |
5391 | phba->fc_arbtov = FF_DEF_ARBTOV; | |
5392 | ||
d7c47992 | 5393 | atomic_set(&phba->sdev_cnt, 0); |
da0436e9 JS |
5394 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
5395 | if (!vport) | |
5396 | return -ENODEV; | |
5397 | ||
5398 | shost = lpfc_shost_from_vport(vport); | |
5399 | phba->pport = vport; | |
5400 | lpfc_debugfs_initialize(vport); | |
5401 | /* Put reference to SCSI host to driver's device private data */ | |
5402 | pci_set_drvdata(phba->pcidev, shost); | |
2e0fef85 | 5403 | |
3772a991 JS |
5404 | return 0; |
5405 | } | |
db2378e0 | 5406 | |
3772a991 JS |
5407 | /** |
5408 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. | |
5409 | * @phba: pointer to lpfc hba data structure. | |
5410 | * | |
5411 | * This routine is invoked to destroy HBA physical port and the associated | |
5412 | * SCSI host. | |
5413 | **/ | |
5414 | static void | |
5415 | lpfc_destroy_shost(struct lpfc_hba *phba) | |
5416 | { | |
5417 | struct lpfc_vport *vport = phba->pport; | |
5418 | ||
5419 | /* Destroy physical port that associated with the SCSI host */ | |
5420 | destroy_port(vport); | |
5421 | ||
5422 | return; | |
5423 | } | |
5424 | ||
5425 | /** | |
5426 | * lpfc_setup_bg - Setup Block guard structures and debug areas. | |
5427 | * @phba: pointer to lpfc hba data structure. | |
5428 | * @shost: the shost to be used to detect Block guard settings. | |
5429 | * | |
5430 | * This routine sets up the local Block guard protocol settings for @shost. | |
5431 | * This routine also allocates memory for debugging bg buffers. | |
5432 | **/ | |
5433 | static void | |
5434 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) | |
5435 | { | |
5436 | int pagecnt = 10; | |
5437 | if (lpfc_prot_mask && lpfc_prot_guard) { | |
5438 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5439 | "1478 Registering BlockGuard with the " | |
5440 | "SCSI layer\n"); | |
5441 | scsi_host_set_prot(shost, lpfc_prot_mask); | |
5442 | scsi_host_set_guard(shost, lpfc_prot_guard); | |
5443 | } | |
5444 | if (!_dump_buf_data) { | |
5445 | while (pagecnt) { | |
5446 | spin_lock_init(&_dump_buf_lock); | |
5447 | _dump_buf_data = | |
5448 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
5449 | if (_dump_buf_data) { | |
6a9c52cf JS |
5450 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5451 | "9043 BLKGRD: allocated %d pages for " | |
3772a991 JS |
5452 | "_dump_buf_data at 0x%p\n", |
5453 | (1 << pagecnt), _dump_buf_data); | |
5454 | _dump_buf_data_order = pagecnt; | |
5455 | memset(_dump_buf_data, 0, | |
5456 | ((1 << PAGE_SHIFT) << pagecnt)); | |
5457 | break; | |
5458 | } else | |
5459 | --pagecnt; | |
5460 | } | |
5461 | if (!_dump_buf_data_order) | |
6a9c52cf JS |
5462 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5463 | "9044 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
5464 | "memory for hexdump\n"); |
5465 | } else | |
6a9c52cf JS |
5466 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5467 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" | |
3772a991 JS |
5468 | "\n", _dump_buf_data); |
5469 | if (!_dump_buf_dif) { | |
5470 | while (pagecnt) { | |
5471 | _dump_buf_dif = | |
5472 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
5473 | if (_dump_buf_dif) { | |
6a9c52cf JS |
5474 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5475 | "9046 BLKGRD: allocated %d pages for " | |
3772a991 JS |
5476 | "_dump_buf_dif at 0x%p\n", |
5477 | (1 << pagecnt), _dump_buf_dif); | |
5478 | _dump_buf_dif_order = pagecnt; | |
5479 | memset(_dump_buf_dif, 0, | |
5480 | ((1 << PAGE_SHIFT) << pagecnt)); | |
5481 | break; | |
5482 | } else | |
5483 | --pagecnt; | |
5484 | } | |
5485 | if (!_dump_buf_dif_order) | |
6a9c52cf JS |
5486 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5487 | "9047 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
5488 | "memory for hexdump\n"); |
5489 | } else | |
6a9c52cf JS |
5490 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5491 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", | |
3772a991 JS |
5492 | _dump_buf_dif); |
5493 | } | |
5494 | ||
5495 | /** | |
5496 | * lpfc_post_init_setup - Perform necessary device post initialization setup. | |
5497 | * @phba: pointer to lpfc hba data structure. | |
5498 | * | |
5499 | * This routine is invoked to perform all the necessary post initialization | |
5500 | * setup for the device. | |
5501 | **/ | |
5502 | static void | |
5503 | lpfc_post_init_setup(struct lpfc_hba *phba) | |
5504 | { | |
5505 | struct Scsi_Host *shost; | |
5506 | struct lpfc_adapter_event_header adapter_event; | |
5507 | ||
5508 | /* Get the default values for Model Name and Description */ | |
5509 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
5510 | ||
5511 | /* | |
5512 | * hba setup may have changed the hba_queue_depth so we need to | |
5513 | * adjust the value of can_queue. | |
5514 | */ | |
5515 | shost = pci_get_drvdata(phba->pcidev); | |
5516 | shost->can_queue = phba->cfg_hba_queue_depth - 10; | |
5517 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) | |
5518 | lpfc_setup_bg(phba, shost); | |
5519 | ||
5520 | lpfc_host_attrib_init(shost); | |
5521 | ||
5522 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | |
5523 | spin_lock_irq(shost->host_lock); | |
5524 | lpfc_poll_start_timer(phba); | |
5525 | spin_unlock_irq(shost->host_lock); | |
5526 | } | |
5527 | ||
5528 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5529 | "0428 Perform SCSI scan\n"); | |
5530 | /* Send board arrival event to upper layer */ | |
5531 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; | |
5532 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; | |
5533 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
5534 | sizeof(adapter_event), | |
5535 | (char *) &adapter_event, | |
5536 | LPFC_NL_VENDOR_ID); | |
5537 | return; | |
5538 | } | |
5539 | ||
5540 | /** | |
5541 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. | |
5542 | * @phba: pointer to lpfc hba data structure. | |
5543 | * | |
5544 | * This routine is invoked to set up the PCI device memory space for device | |
5545 | * with SLI-3 interface spec. | |
5546 | * | |
5547 | * Return codes | |
af901ca1 | 5548 | * 0 - successful |
3772a991 JS |
5549 | * other values - error |
5550 | **/ | |
5551 | static int | |
5552 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) | |
5553 | { | |
5554 | struct pci_dev *pdev; | |
5555 | unsigned long bar0map_len, bar2map_len; | |
5556 | int i, hbq_count; | |
5557 | void *ptr; | |
5558 | int error = -ENODEV; | |
5559 | ||
5560 | /* Obtain PCI device reference */ | |
5561 | if (!phba->pcidev) | |
5562 | return error; | |
5563 | else | |
5564 | pdev = phba->pcidev; | |
5565 | ||
5566 | /* Set the device DMA mask size */ | |
8e68597d MR |
5567 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
5568 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
5569 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
5570 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
3772a991 | 5571 | return error; |
8e68597d MR |
5572 | } |
5573 | } | |
3772a991 JS |
5574 | |
5575 | /* Get the bus address of Bar0 and Bar2 and the number of bytes | |
5576 | * required by each mapping. | |
5577 | */ | |
5578 | phba->pci_bar0_map = pci_resource_start(pdev, 0); | |
5579 | bar0map_len = pci_resource_len(pdev, 0); | |
5580 | ||
5581 | phba->pci_bar2_map = pci_resource_start(pdev, 2); | |
5582 | bar2map_len = pci_resource_len(pdev, 2); | |
5583 | ||
5584 | /* Map HBA SLIM to a kernel virtual address. */ | |
5585 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); | |
5586 | if (!phba->slim_memmap_p) { | |
5587 | dev_printk(KERN_ERR, &pdev->dev, | |
5588 | "ioremap failed for SLIM memory.\n"); | |
5589 | goto out; | |
5590 | } | |
5591 | ||
5592 | /* Map HBA Control Registers to a kernel virtual address. */ | |
5593 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); | |
5594 | if (!phba->ctrl_regs_memmap_p) { | |
5595 | dev_printk(KERN_ERR, &pdev->dev, | |
5596 | "ioremap failed for HBA control registers.\n"); | |
5597 | goto out_iounmap_slim; | |
5598 | } | |
5599 | ||
5600 | /* Allocate memory for SLI-2 structures */ | |
5601 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, | |
5602 | SLI2_SLIM_SIZE, | |
5603 | &phba->slim2p.phys, | |
5604 | GFP_KERNEL); | |
5605 | if (!phba->slim2p.virt) | |
5606 | goto out_iounmap; | |
5607 | ||
5608 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); | |
5609 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); | |
7a470277 JS |
5610 | phba->mbox_ext = (phba->slim2p.virt + |
5611 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); | |
3772a991 JS |
5612 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
5613 | phba->IOCBs = (phba->slim2p.virt + | |
5614 | offsetof(struct lpfc_sli2_slim, IOCBs)); | |
5615 | ||
5616 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, | |
5617 | lpfc_sli_hbq_size(), | |
5618 | &phba->hbqslimp.phys, | |
5619 | GFP_KERNEL); | |
5620 | if (!phba->hbqslimp.virt) | |
5621 | goto out_free_slim; | |
5622 | ||
5623 | hbq_count = lpfc_sli_hbq_count(); | |
5624 | ptr = phba->hbqslimp.virt; | |
5625 | for (i = 0; i < hbq_count; ++i) { | |
5626 | phba->hbqs[i].hbq_virt = ptr; | |
5627 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
5628 | ptr += (lpfc_hbq_defs[i]->entry_count * | |
5629 | sizeof(struct lpfc_hbq_entry)); | |
5630 | } | |
5631 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; | |
5632 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; | |
5633 | ||
5634 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); | |
5635 | ||
5636 | INIT_LIST_HEAD(&phba->rb_pend_list); | |
5637 | ||
5638 | phba->MBslimaddr = phba->slim_memmap_p; | |
5639 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; | |
5640 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; | |
5641 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; | |
5642 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; | |
5643 | ||
5644 | return 0; | |
5645 | ||
5646 | out_free_slim: | |
5647 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
5648 | phba->slim2p.virt, phba->slim2p.phys); | |
5649 | out_iounmap: | |
5650 | iounmap(phba->ctrl_regs_memmap_p); | |
5651 | out_iounmap_slim: | |
5652 | iounmap(phba->slim_memmap_p); | |
5653 | out: | |
5654 | return error; | |
5655 | } | |
5656 | ||
5657 | /** | |
5658 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. | |
5659 | * @phba: pointer to lpfc hba data structure. | |
5660 | * | |
5661 | * This routine is invoked to unset the PCI device memory space for device | |
5662 | * with SLI-3 interface spec. | |
5663 | **/ | |
5664 | static void | |
5665 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) | |
5666 | { | |
5667 | struct pci_dev *pdev; | |
5668 | ||
5669 | /* Obtain PCI device reference */ | |
5670 | if (!phba->pcidev) | |
5671 | return; | |
5672 | else | |
5673 | pdev = phba->pcidev; | |
5674 | ||
5675 | /* Free coherent DMA memory allocated */ | |
5676 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
5677 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
5678 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
5679 | phba->slim2p.virt, phba->slim2p.phys); | |
5680 | ||
5681 | /* I/O memory unmap */ | |
5682 | iounmap(phba->ctrl_regs_memmap_p); | |
5683 | iounmap(phba->slim_memmap_p); | |
5684 | ||
5685 | return; | |
5686 | } | |
5687 | ||
5688 | /** | |
da0436e9 | 5689 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
3772a991 JS |
5690 | * @phba: pointer to lpfc hba data structure. |
5691 | * | |
da0436e9 JS |
5692 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
5693 | * done and check status. | |
3772a991 | 5694 | * |
da0436e9 | 5695 | * Return 0 if successful, otherwise -ENODEV. |
3772a991 | 5696 | **/ |
da0436e9 JS |
5697 | int |
5698 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) | |
3772a991 | 5699 | { |
2fcee4bf JS |
5700 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
5701 | struct lpfc_register reg_data; | |
5702 | int i, port_error = 0; | |
5703 | uint32_t if_type; | |
3772a991 | 5704 | |
9940b97b JS |
5705 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
5706 | memset(®_data, 0, sizeof(reg_data)); | |
2fcee4bf | 5707 | if (!phba->sli4_hba.PSMPHRregaddr) |
da0436e9 | 5708 | return -ENODEV; |
3772a991 | 5709 | |
da0436e9 JS |
5710 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
5711 | for (i = 0; i < 3000; i++) { | |
9940b97b JS |
5712 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
5713 | &portsmphr_reg.word0) || | |
5714 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { | |
2fcee4bf | 5715 | /* Port has a fatal POST error, break out */ |
da0436e9 JS |
5716 | port_error = -ENODEV; |
5717 | break; | |
5718 | } | |
2fcee4bf JS |
5719 | if (LPFC_POST_STAGE_PORT_READY == |
5720 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) | |
da0436e9 | 5721 | break; |
da0436e9 | 5722 | msleep(10); |
3772a991 JS |
5723 | } |
5724 | ||
2fcee4bf JS |
5725 | /* |
5726 | * If there was a port error during POST, then don't proceed with | |
5727 | * other register reads as the data may not be valid. Just exit. | |
5728 | */ | |
5729 | if (port_error) { | |
da0436e9 | 5730 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2fcee4bf JS |
5731 | "1408 Port Failed POST - portsmphr=0x%x, " |
5732 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " | |
5733 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", | |
5734 | portsmphr_reg.word0, | |
5735 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), | |
5736 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), | |
5737 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), | |
5738 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), | |
5739 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), | |
5740 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), | |
5741 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), | |
5742 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); | |
5743 | } else { | |
28baac74 | 5744 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2fcee4bf JS |
5745 | "2534 Device Info: SLIFamily=0x%x, " |
5746 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " | |
5747 | "SLIHint_2=0x%x, FT=0x%x\n", | |
28baac74 JS |
5748 | bf_get(lpfc_sli_intf_sli_family, |
5749 | &phba->sli4_hba.sli_intf), | |
5750 | bf_get(lpfc_sli_intf_slirev, | |
5751 | &phba->sli4_hba.sli_intf), | |
085c647c JS |
5752 | bf_get(lpfc_sli_intf_if_type, |
5753 | &phba->sli4_hba.sli_intf), | |
5754 | bf_get(lpfc_sli_intf_sli_hint1, | |
28baac74 | 5755 | &phba->sli4_hba.sli_intf), |
085c647c JS |
5756 | bf_get(lpfc_sli_intf_sli_hint2, |
5757 | &phba->sli4_hba.sli_intf), | |
5758 | bf_get(lpfc_sli_intf_func_type, | |
28baac74 | 5759 | &phba->sli4_hba.sli_intf)); |
2fcee4bf JS |
5760 | /* |
5761 | * Check for other Port errors during the initialization | |
5762 | * process. Fail the load if the port did not come up | |
5763 | * correctly. | |
5764 | */ | |
5765 | if_type = bf_get(lpfc_sli_intf_if_type, | |
5766 | &phba->sli4_hba.sli_intf); | |
5767 | switch (if_type) { | |
5768 | case LPFC_SLI_INTF_IF_TYPE_0: | |
5769 | phba->sli4_hba.ue_mask_lo = | |
5770 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); | |
5771 | phba->sli4_hba.ue_mask_hi = | |
5772 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); | |
5773 | uerrlo_reg.word0 = | |
5774 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); | |
5775 | uerrhi_reg.word0 = | |
5776 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); | |
5777 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || | |
5778 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { | |
5779 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5780 | "1422 Unrecoverable Error " | |
5781 | "Detected during POST " | |
5782 | "uerr_lo_reg=0x%x, " | |
5783 | "uerr_hi_reg=0x%x, " | |
5784 | "ue_mask_lo_reg=0x%x, " | |
5785 | "ue_mask_hi_reg=0x%x\n", | |
5786 | uerrlo_reg.word0, | |
5787 | uerrhi_reg.word0, | |
5788 | phba->sli4_hba.ue_mask_lo, | |
5789 | phba->sli4_hba.ue_mask_hi); | |
5790 | port_error = -ENODEV; | |
5791 | } | |
5792 | break; | |
5793 | case LPFC_SLI_INTF_IF_TYPE_2: | |
5794 | /* Final checks. The port status should be clean. */ | |
9940b97b JS |
5795 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
5796 | ®_data.word0) || | |
0558056c JS |
5797 | (bf_get(lpfc_sliport_status_err, ®_data) && |
5798 | !bf_get(lpfc_sliport_status_rn, ®_data))) { | |
2fcee4bf JS |
5799 | phba->work_status[0] = |
5800 | readl(phba->sli4_hba.u.if_type2. | |
5801 | ERR1regaddr); | |
5802 | phba->work_status[1] = | |
5803 | readl(phba->sli4_hba.u.if_type2. | |
5804 | ERR2regaddr); | |
5805 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5806 | "2888 Port Error Detected " | |
5807 | "during POST: " | |
5808 | "port status reg 0x%x, " | |
5809 | "port_smphr reg 0x%x, " | |
5810 | "error 1=0x%x, error 2=0x%x\n", | |
5811 | reg_data.word0, | |
5812 | portsmphr_reg.word0, | |
5813 | phba->work_status[0], | |
5814 | phba->work_status[1]); | |
5815 | port_error = -ENODEV; | |
5816 | } | |
5817 | break; | |
5818 | case LPFC_SLI_INTF_IF_TYPE_1: | |
5819 | default: | |
5820 | break; | |
5821 | } | |
28baac74 | 5822 | } |
da0436e9 JS |
5823 | return port_error; |
5824 | } | |
3772a991 | 5825 | |
da0436e9 JS |
5826 | /** |
5827 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. | |
5828 | * @phba: pointer to lpfc hba data structure. | |
2fcee4bf | 5829 | * @if_type: The SLI4 interface type getting configured. |
da0436e9 JS |
5830 | * |
5831 | * This routine is invoked to set up SLI4 BAR0 PCI config space register | |
5832 | * memory map. | |
5833 | **/ | |
5834 | static void | |
2fcee4bf JS |
5835 | lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type) |
5836 | { | |
5837 | switch (if_type) { | |
5838 | case LPFC_SLI_INTF_IF_TYPE_0: | |
5839 | phba->sli4_hba.u.if_type0.UERRLOregaddr = | |
5840 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; | |
5841 | phba->sli4_hba.u.if_type0.UERRHIregaddr = | |
5842 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; | |
5843 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = | |
5844 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; | |
5845 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = | |
5846 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; | |
5847 | phba->sli4_hba.SLIINTFregaddr = | |
5848 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; | |
5849 | break; | |
5850 | case LPFC_SLI_INTF_IF_TYPE_2: | |
5851 | phba->sli4_hba.u.if_type2.ERR1regaddr = | |
88a2cfbb JS |
5852 | phba->sli4_hba.conf_regs_memmap_p + |
5853 | LPFC_CTL_PORT_ER1_OFFSET; | |
2fcee4bf | 5854 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
88a2cfbb JS |
5855 | phba->sli4_hba.conf_regs_memmap_p + |
5856 | LPFC_CTL_PORT_ER2_OFFSET; | |
2fcee4bf | 5857 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
88a2cfbb JS |
5858 | phba->sli4_hba.conf_regs_memmap_p + |
5859 | LPFC_CTL_PORT_CTL_OFFSET; | |
2fcee4bf | 5860 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
88a2cfbb JS |
5861 | phba->sli4_hba.conf_regs_memmap_p + |
5862 | LPFC_CTL_PORT_STA_OFFSET; | |
2fcee4bf JS |
5863 | phba->sli4_hba.SLIINTFregaddr = |
5864 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; | |
5865 | phba->sli4_hba.PSMPHRregaddr = | |
88a2cfbb JS |
5866 | phba->sli4_hba.conf_regs_memmap_p + |
5867 | LPFC_CTL_PORT_SEM_OFFSET; | |
2fcee4bf JS |
5868 | phba->sli4_hba.RQDBregaddr = |
5869 | phba->sli4_hba.conf_regs_memmap_p + LPFC_RQ_DOORBELL; | |
5870 | phba->sli4_hba.WQDBregaddr = | |
5871 | phba->sli4_hba.conf_regs_memmap_p + LPFC_WQ_DOORBELL; | |
5872 | phba->sli4_hba.EQCQDBregaddr = | |
5873 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; | |
5874 | phba->sli4_hba.MQDBregaddr = | |
5875 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; | |
5876 | phba->sli4_hba.BMBXregaddr = | |
5877 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; | |
5878 | break; | |
5879 | case LPFC_SLI_INTF_IF_TYPE_1: | |
5880 | default: | |
5881 | dev_printk(KERN_ERR, &phba->pcidev->dev, | |
5882 | "FATAL - unsupported SLI4 interface type - %d\n", | |
5883 | if_type); | |
5884 | break; | |
5885 | } | |
da0436e9 | 5886 | } |
3772a991 | 5887 | |
da0436e9 JS |
5888 | /** |
5889 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. | |
5890 | * @phba: pointer to lpfc hba data structure. | |
5891 | * | |
5892 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) | |
5893 | * memory map. | |
5894 | **/ | |
5895 | static void | |
5896 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) | |
5897 | { | |
2fcee4bf JS |
5898 | phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
5899 | LPFC_SLIPORT_IF0_SMPHR; | |
da0436e9 | 5900 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 5901 | LPFC_HST_ISR0; |
da0436e9 | 5902 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 5903 | LPFC_HST_IMR0; |
da0436e9 | 5904 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 5905 | LPFC_HST_ISCR0; |
3772a991 JS |
5906 | } |
5907 | ||
5908 | /** | |
da0436e9 | 5909 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
3772a991 | 5910 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 5911 | * @vf: virtual function number |
3772a991 | 5912 | * |
da0436e9 JS |
5913 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
5914 | * based on the given viftual function number, @vf. | |
5915 | * | |
5916 | * Return 0 if successful, otherwise -ENODEV. | |
3772a991 | 5917 | **/ |
da0436e9 JS |
5918 | static int |
5919 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) | |
3772a991 | 5920 | { |
da0436e9 JS |
5921 | if (vf > LPFC_VIR_FUNC_MAX) |
5922 | return -ENODEV; | |
3772a991 | 5923 | |
da0436e9 JS |
5924 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
5925 | vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL); | |
5926 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5927 | vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL); | |
5928 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5929 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); | |
5930 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5931 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); | |
5932 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
5933 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); | |
5934 | return 0; | |
3772a991 JS |
5935 | } |
5936 | ||
5937 | /** | |
da0436e9 | 5938 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
3772a991 JS |
5939 | * @phba: pointer to lpfc hba data structure. |
5940 | * | |
da0436e9 JS |
5941 | * This routine is invoked to create the bootstrap mailbox |
5942 | * region consistent with the SLI-4 interface spec. This | |
5943 | * routine allocates all memory necessary to communicate | |
5944 | * mailbox commands to the port and sets up all alignment | |
5945 | * needs. No locks are expected to be held when calling | |
5946 | * this routine. | |
3772a991 JS |
5947 | * |
5948 | * Return codes | |
af901ca1 | 5949 | * 0 - successful |
d439d286 | 5950 | * -ENOMEM - could not allocated memory. |
da0436e9 | 5951 | **/ |
3772a991 | 5952 | static int |
da0436e9 | 5953 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 5954 | { |
da0436e9 JS |
5955 | uint32_t bmbx_size; |
5956 | struct lpfc_dmabuf *dmabuf; | |
5957 | struct dma_address *dma_address; | |
5958 | uint32_t pa_addr; | |
5959 | uint64_t phys_addr; | |
5960 | ||
5961 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
5962 | if (!dmabuf) | |
5963 | return -ENOMEM; | |
3772a991 | 5964 | |
da0436e9 JS |
5965 | /* |
5966 | * The bootstrap mailbox region is comprised of 2 parts | |
5967 | * plus an alignment restriction of 16 bytes. | |
5968 | */ | |
5969 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); | |
5970 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
5971 | bmbx_size, | |
5972 | &dmabuf->phys, | |
5973 | GFP_KERNEL); | |
5974 | if (!dmabuf->virt) { | |
5975 | kfree(dmabuf); | |
5976 | return -ENOMEM; | |
3772a991 | 5977 | } |
da0436e9 | 5978 | memset(dmabuf->virt, 0, bmbx_size); |
3772a991 | 5979 | |
da0436e9 JS |
5980 | /* |
5981 | * Initialize the bootstrap mailbox pointers now so that the register | |
5982 | * operations are simple later. The mailbox dma address is required | |
5983 | * to be 16-byte aligned. Also align the virtual memory as each | |
5984 | * maibox is copied into the bmbx mailbox region before issuing the | |
5985 | * command to the port. | |
5986 | */ | |
5987 | phba->sli4_hba.bmbx.dmabuf = dmabuf; | |
5988 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; | |
5989 | ||
5990 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, | |
5991 | LPFC_ALIGN_16_BYTE); | |
5992 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, | |
5993 | LPFC_ALIGN_16_BYTE); | |
5994 | ||
5995 | /* | |
5996 | * Set the high and low physical addresses now. The SLI4 alignment | |
5997 | * requirement is 16 bytes and the mailbox is posted to the port | |
5998 | * as two 30-bit addresses. The other data is a bit marking whether | |
5999 | * the 30-bit address is the high or low address. | |
6000 | * Upcast bmbx aphys to 64bits so shift instruction compiles | |
6001 | * clean on 32 bit machines. | |
6002 | */ | |
6003 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
6004 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; | |
6005 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); | |
6006 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | | |
6007 | LPFC_BMBX_BIT1_ADDR_HI); | |
6008 | ||
6009 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); | |
6010 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | | |
6011 | LPFC_BMBX_BIT1_ADDR_LO); | |
6012 | return 0; | |
3772a991 JS |
6013 | } |
6014 | ||
6015 | /** | |
da0436e9 | 6016 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
3772a991 JS |
6017 | * @phba: pointer to lpfc hba data structure. |
6018 | * | |
da0436e9 JS |
6019 | * This routine is invoked to teardown the bootstrap mailbox |
6020 | * region and release all host resources. This routine requires | |
6021 | * the caller to ensure all mailbox commands recovered, no | |
6022 | * additional mailbox comands are sent, and interrupts are disabled | |
6023 | * before calling this routine. | |
6024 | * | |
6025 | **/ | |
3772a991 | 6026 | static void |
da0436e9 | 6027 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 6028 | { |
da0436e9 JS |
6029 | dma_free_coherent(&phba->pcidev->dev, |
6030 | phba->sli4_hba.bmbx.bmbx_size, | |
6031 | phba->sli4_hba.bmbx.dmabuf->virt, | |
6032 | phba->sli4_hba.bmbx.dmabuf->phys); | |
6033 | ||
6034 | kfree(phba->sli4_hba.bmbx.dmabuf); | |
6035 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); | |
3772a991 JS |
6036 | } |
6037 | ||
6038 | /** | |
da0436e9 | 6039 | * lpfc_sli4_read_config - Get the config parameters. |
3772a991 JS |
6040 | * @phba: pointer to lpfc hba data structure. |
6041 | * | |
da0436e9 JS |
6042 | * This routine is invoked to read the configuration parameters from the HBA. |
6043 | * The configuration parameters are used to set the base and maximum values | |
6044 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource | |
6045 | * allocation for the port. | |
3772a991 JS |
6046 | * |
6047 | * Return codes | |
af901ca1 | 6048 | * 0 - successful |
25985edc | 6049 | * -ENOMEM - No available memory |
d439d286 | 6050 | * -EIO - The mailbox failed to complete successfully. |
3772a991 | 6051 | **/ |
ff78d8f9 | 6052 | int |
da0436e9 | 6053 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
3772a991 | 6054 | { |
da0436e9 JS |
6055 | LPFC_MBOXQ_t *pmb; |
6056 | struct lpfc_mbx_read_config *rd_config; | |
912e3acd JS |
6057 | union lpfc_sli4_cfg_shdr *shdr; |
6058 | uint32_t shdr_status, shdr_add_status; | |
6059 | struct lpfc_mbx_get_func_cfg *get_func_cfg; | |
6060 | struct lpfc_rsrc_desc_fcfcoe *desc; | |
6061 | uint32_t desc_count; | |
6062 | int length, i, rc = 0; | |
3772a991 | 6063 | |
da0436e9 JS |
6064 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
6065 | if (!pmb) { | |
6066 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6067 | "2011 Unable to allocate memory for issuing " | |
6068 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
6069 | return -ENOMEM; | |
3772a991 JS |
6070 | } |
6071 | ||
da0436e9 | 6072 | lpfc_read_config(phba, pmb); |
3772a991 | 6073 | |
da0436e9 JS |
6074 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
6075 | if (rc != MBX_SUCCESS) { | |
6076 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6077 | "2012 Mailbox failed , mbxCmd x%x " | |
6078 | "READ_CONFIG, mbxStatus x%x\n", | |
6079 | bf_get(lpfc_mqe_command, &pmb->u.mqe), | |
6080 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); | |
6081 | rc = -EIO; | |
6082 | } else { | |
6083 | rd_config = &pmb->u.mqe.un.rd_config; | |
ff78d8f9 JS |
6084 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
6085 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; | |
6086 | phba->sli4_hba.lnk_info.lnk_tp = | |
6087 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); | |
6088 | phba->sli4_hba.lnk_info.lnk_no = | |
6089 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); | |
6090 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
6091 | "3081 lnk_type:%d, lnk_numb:%d\n", | |
6092 | phba->sli4_hba.lnk_info.lnk_tp, | |
6093 | phba->sli4_hba.lnk_info.lnk_no); | |
6094 | } else | |
6095 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
6096 | "3082 Mailbox (x%x) returned ldv:x0\n", | |
6097 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); | |
6d368e53 JS |
6098 | phba->sli4_hba.extents_in_use = |
6099 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); | |
da0436e9 JS |
6100 | phba->sli4_hba.max_cfg_param.max_xri = |
6101 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); | |
6102 | phba->sli4_hba.max_cfg_param.xri_base = | |
6103 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); | |
6104 | phba->sli4_hba.max_cfg_param.max_vpi = | |
6105 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); | |
6106 | phba->sli4_hba.max_cfg_param.vpi_base = | |
6107 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); | |
6108 | phba->sli4_hba.max_cfg_param.max_rpi = | |
6109 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); | |
6110 | phba->sli4_hba.max_cfg_param.rpi_base = | |
6111 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); | |
6112 | phba->sli4_hba.max_cfg_param.max_vfi = | |
6113 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); | |
6114 | phba->sli4_hba.max_cfg_param.vfi_base = | |
6115 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); | |
6116 | phba->sli4_hba.max_cfg_param.max_fcfi = | |
6117 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); | |
da0436e9 JS |
6118 | phba->sli4_hba.max_cfg_param.max_eq = |
6119 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); | |
6120 | phba->sli4_hba.max_cfg_param.max_rq = | |
6121 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); | |
6122 | phba->sli4_hba.max_cfg_param.max_wq = | |
6123 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); | |
6124 | phba->sli4_hba.max_cfg_param.max_cq = | |
6125 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); | |
6126 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); | |
6127 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; | |
6128 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; | |
6129 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; | |
6130 | phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base; | |
5ffc266e JS |
6131 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
6132 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; | |
da0436e9 JS |
6133 | phba->max_vports = phba->max_vpi; |
6134 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
6d368e53 JS |
6135 | "2003 cfg params Extents? %d " |
6136 | "XRI(B:%d M:%d), " | |
da0436e9 JS |
6137 | "VPI(B:%d M:%d) " |
6138 | "VFI(B:%d M:%d) " | |
6139 | "RPI(B:%d M:%d) " | |
6d368e53 JS |
6140 | "FCFI(Count:%d)\n", |
6141 | phba->sli4_hba.extents_in_use, | |
da0436e9 JS |
6142 | phba->sli4_hba.max_cfg_param.xri_base, |
6143 | phba->sli4_hba.max_cfg_param.max_xri, | |
6144 | phba->sli4_hba.max_cfg_param.vpi_base, | |
6145 | phba->sli4_hba.max_cfg_param.max_vpi, | |
6146 | phba->sli4_hba.max_cfg_param.vfi_base, | |
6147 | phba->sli4_hba.max_cfg_param.max_vfi, | |
6148 | phba->sli4_hba.max_cfg_param.rpi_base, | |
6149 | phba->sli4_hba.max_cfg_param.max_rpi, | |
da0436e9 | 6150 | phba->sli4_hba.max_cfg_param.max_fcfi); |
3772a991 | 6151 | } |
912e3acd JS |
6152 | |
6153 | if (rc) | |
6154 | goto read_cfg_out; | |
da0436e9 JS |
6155 | |
6156 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ | |
b92938b4 JS |
6157 | if (phba->cfg_hba_queue_depth > |
6158 | (phba->sli4_hba.max_cfg_param.max_xri - | |
6159 | lpfc_sli4_get_els_iocb_cnt(phba))) | |
da0436e9 | 6160 | phba->cfg_hba_queue_depth = |
b92938b4 JS |
6161 | phba->sli4_hba.max_cfg_param.max_xri - |
6162 | lpfc_sli4_get_els_iocb_cnt(phba); | |
912e3acd JS |
6163 | |
6164 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
6165 | LPFC_SLI_INTF_IF_TYPE_2) | |
6166 | goto read_cfg_out; | |
6167 | ||
6168 | /* get the pf# and vf# for SLI4 if_type 2 port */ | |
6169 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - | |
6170 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
6171 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, | |
6172 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, | |
6173 | length, LPFC_SLI4_MBX_EMBED); | |
6174 | ||
6175 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
6176 | shdr = (union lpfc_sli4_cfg_shdr *) | |
6177 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; | |
6178 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
6179 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
6180 | if (rc || shdr_status || shdr_add_status) { | |
6181 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6182 | "3026 Mailbox failed , mbxCmd x%x " | |
6183 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", | |
6184 | bf_get(lpfc_mqe_command, &pmb->u.mqe), | |
6185 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); | |
6186 | rc = -EIO; | |
6187 | goto read_cfg_out; | |
6188 | } | |
6189 | ||
6190 | /* search for fc_fcoe resrouce descriptor */ | |
6191 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; | |
6192 | desc_count = get_func_cfg->func_cfg.rsrc_desc_count; | |
6193 | ||
6194 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { | |
6195 | desc = (struct lpfc_rsrc_desc_fcfcoe *) | |
6196 | &get_func_cfg->func_cfg.desc[i]; | |
6197 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == | |
6198 | bf_get(lpfc_rsrc_desc_pcie_type, desc)) { | |
6199 | phba->sli4_hba.iov.pf_number = | |
6200 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); | |
6201 | phba->sli4_hba.iov.vf_number = | |
6202 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); | |
6203 | break; | |
6204 | } | |
6205 | } | |
6206 | ||
6207 | if (i < LPFC_RSRC_DESC_MAX_NUM) | |
6208 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
6209 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " | |
6210 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, | |
6211 | phba->sli4_hba.iov.vf_number); | |
6212 | else { | |
6213 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6214 | "3028 GET_FUNCTION_CONFIG: failed to find " | |
6215 | "Resrouce Descriptor:x%x\n", | |
6216 | LPFC_RSRC_DESC_TYPE_FCFCOE); | |
6217 | rc = -EIO; | |
6218 | } | |
6219 | ||
6220 | read_cfg_out: | |
6221 | mempool_free(pmb, phba->mbox_mem_pool); | |
da0436e9 | 6222 | return rc; |
3772a991 JS |
6223 | } |
6224 | ||
6225 | /** | |
2fcee4bf | 6226 | * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port. |
3772a991 JS |
6227 | * @phba: pointer to lpfc hba data structure. |
6228 | * | |
2fcee4bf JS |
6229 | * This routine is invoked to setup the port-side endian order when |
6230 | * the port if_type is 0. This routine has no function for other | |
6231 | * if_types. | |
da0436e9 JS |
6232 | * |
6233 | * Return codes | |
af901ca1 | 6234 | * 0 - successful |
25985edc | 6235 | * -ENOMEM - No available memory |
d439d286 | 6236 | * -EIO - The mailbox failed to complete successfully. |
3772a991 | 6237 | **/ |
da0436e9 JS |
6238 | static int |
6239 | lpfc_setup_endian_order(struct lpfc_hba *phba) | |
3772a991 | 6240 | { |
da0436e9 | 6241 | LPFC_MBOXQ_t *mboxq; |
2fcee4bf | 6242 | uint32_t if_type, rc = 0; |
da0436e9 JS |
6243 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
6244 | HOST_ENDIAN_HIGH_WORD1}; | |
3772a991 | 6245 | |
2fcee4bf JS |
6246 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
6247 | switch (if_type) { | |
6248 | case LPFC_SLI_INTF_IF_TYPE_0: | |
6249 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, | |
6250 | GFP_KERNEL); | |
6251 | if (!mboxq) { | |
6252 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6253 | "0492 Unable to allocate memory for " | |
6254 | "issuing SLI_CONFIG_SPECIAL mailbox " | |
6255 | "command\n"); | |
6256 | return -ENOMEM; | |
6257 | } | |
3772a991 | 6258 | |
2fcee4bf JS |
6259 | /* |
6260 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first | |
6261 | * two words to contain special data values and no other data. | |
6262 | */ | |
6263 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
6264 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); | |
6265 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6266 | if (rc != MBX_SUCCESS) { | |
6267 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6268 | "0493 SLI_CONFIG_SPECIAL mailbox " | |
6269 | "failed with status x%x\n", | |
6270 | rc); | |
6271 | rc = -EIO; | |
6272 | } | |
6273 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6274 | break; | |
6275 | case LPFC_SLI_INTF_IF_TYPE_2: | |
6276 | case LPFC_SLI_INTF_IF_TYPE_1: | |
6277 | default: | |
6278 | break; | |
da0436e9 | 6279 | } |
da0436e9 | 6280 | return rc; |
3772a991 JS |
6281 | } |
6282 | ||
6283 | /** | |
5350d872 | 6284 | * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts |
3772a991 JS |
6285 | * @phba: pointer to lpfc hba data structure. |
6286 | * | |
5350d872 JS |
6287 | * This routine is invoked to check the user settable queue counts for EQs and |
6288 | * CQs. after this routine is called the counts will be set to valid values that | |
6289 | * adhere to the constraints of the system's interrupt vectors and the port's | |
6290 | * queue resources. | |
da0436e9 JS |
6291 | * |
6292 | * Return codes | |
af901ca1 | 6293 | * 0 - successful |
25985edc | 6294 | * -ENOMEM - No available memory |
3772a991 | 6295 | **/ |
da0436e9 | 6296 | static int |
5350d872 | 6297 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
3772a991 | 6298 | { |
da0436e9 JS |
6299 | int cfg_fcp_wq_count; |
6300 | int cfg_fcp_eq_count; | |
3772a991 | 6301 | |
da0436e9 JS |
6302 | /* |
6303 | * Sanity check for confiugred queue parameters against the run-time | |
6304 | * device parameters | |
6305 | */ | |
3772a991 | 6306 | |
da0436e9 JS |
6307 | /* Sanity check on FCP fast-path WQ parameters */ |
6308 | cfg_fcp_wq_count = phba->cfg_fcp_wq_count; | |
6309 | if (cfg_fcp_wq_count > | |
6310 | (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) { | |
6311 | cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq - | |
6312 | LPFC_SP_WQN_DEF; | |
6313 | if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) { | |
6314 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6315 | "2581 Not enough WQs (%d) from " | |
6316 | "the pci function for supporting " | |
6317 | "FCP WQs (%d)\n", | |
6318 | phba->sli4_hba.max_cfg_param.max_wq, | |
6319 | phba->cfg_fcp_wq_count); | |
6320 | goto out_error; | |
6321 | } | |
6322 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6323 | "2582 Not enough WQs (%d) from the pci " | |
6324 | "function for supporting the requested " | |
6325 | "FCP WQs (%d), the actual FCP WQs can " | |
6326 | "be supported: %d\n", | |
6327 | phba->sli4_hba.max_cfg_param.max_wq, | |
6328 | phba->cfg_fcp_wq_count, cfg_fcp_wq_count); | |
6329 | } | |
6330 | /* The actual number of FCP work queues adopted */ | |
6331 | phba->cfg_fcp_wq_count = cfg_fcp_wq_count; | |
6332 | ||
6333 | /* Sanity check on FCP fast-path EQ parameters */ | |
6334 | cfg_fcp_eq_count = phba->cfg_fcp_eq_count; | |
6335 | if (cfg_fcp_eq_count > | |
6336 | (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) { | |
6337 | cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq - | |
6338 | LPFC_SP_EQN_DEF; | |
6339 | if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) { | |
6340 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6341 | "2574 Not enough EQs (%d) from the " | |
6342 | "pci function for supporting FCP " | |
6343 | "EQs (%d)\n", | |
6344 | phba->sli4_hba.max_cfg_param.max_eq, | |
6345 | phba->cfg_fcp_eq_count); | |
6346 | goto out_error; | |
6347 | } | |
6348 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6349 | "2575 Not enough EQs (%d) from the pci " | |
6350 | "function for supporting the requested " | |
6351 | "FCP EQs (%d), the actual FCP EQs can " | |
6352 | "be supported: %d\n", | |
6353 | phba->sli4_hba.max_cfg_param.max_eq, | |
6354 | phba->cfg_fcp_eq_count, cfg_fcp_eq_count); | |
6355 | } | |
6356 | /* It does not make sense to have more EQs than WQs */ | |
6357 | if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) { | |
6358 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6a9c52cf JS |
6359 | "2593 The FCP EQ count(%d) cannot be greater " |
6360 | "than the FCP WQ count(%d), limiting the " | |
6361 | "FCP EQ count to %d\n", cfg_fcp_eq_count, | |
da0436e9 JS |
6362 | phba->cfg_fcp_wq_count, |
6363 | phba->cfg_fcp_wq_count); | |
6364 | cfg_fcp_eq_count = phba->cfg_fcp_wq_count; | |
6365 | } | |
6366 | /* The actual number of FCP event queues adopted */ | |
6367 | phba->cfg_fcp_eq_count = cfg_fcp_eq_count; | |
6368 | /* The overall number of event queues used */ | |
6369 | phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF; | |
3772a991 | 6370 | |
da0436e9 JS |
6371 | /* Get EQ depth from module parameter, fake the default for now */ |
6372 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; | |
6373 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; | |
3772a991 | 6374 | |
5350d872 JS |
6375 | /* Get CQ depth from module parameter, fake the default for now */ |
6376 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; | |
6377 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; | |
6378 | ||
6379 | return 0; | |
6380 | out_error: | |
6381 | return -ENOMEM; | |
6382 | } | |
6383 | ||
6384 | /** | |
6385 | * lpfc_sli4_queue_create - Create all the SLI4 queues | |
6386 | * @phba: pointer to lpfc hba data structure. | |
6387 | * | |
6388 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA | |
6389 | * operation. For each SLI4 queue type, the parameters such as queue entry | |
6390 | * count (queue depth) shall be taken from the module parameter. For now, | |
6391 | * we just use some constant number as place holder. | |
6392 | * | |
6393 | * Return codes | |
6394 | * 0 - sucessful | |
6395 | * -ENOMEM - No availble memory | |
6396 | * -EIO - The mailbox failed to complete successfully. | |
6397 | **/ | |
6398 | int | |
6399 | lpfc_sli4_queue_create(struct lpfc_hba *phba) | |
6400 | { | |
6401 | struct lpfc_queue *qdesc; | |
6402 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; | |
6403 | ||
6404 | /* | |
6405 | * Create Event Queues (EQs) | |
6406 | */ | |
6407 | ||
da0436e9 JS |
6408 | /* Create slow path event queue */ |
6409 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | |
6410 | phba->sli4_hba.eq_ecount); | |
6411 | if (!qdesc) { | |
6412 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6413 | "0496 Failed allocate slow-path EQ\n"); | |
6414 | goto out_error; | |
6415 | } | |
6416 | phba->sli4_hba.sp_eq = qdesc; | |
6417 | ||
5350d872 JS |
6418 | /* |
6419 | * Create fast-path FCP Event Queue(s). The cfg_fcp_eq_count can be | |
6420 | * zero whenever there is exactly one interrupt vector. This is not | |
6421 | * an error. | |
6422 | */ | |
6423 | if (phba->cfg_fcp_eq_count) { | |
6424 | phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) * | |
6425 | phba->cfg_fcp_eq_count), GFP_KERNEL); | |
6426 | if (!phba->sli4_hba.fp_eq) { | |
6427 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6428 | "2576 Failed allocate memory for " | |
6429 | "fast-path EQ record array\n"); | |
6430 | goto out_free_sp_eq; | |
6431 | } | |
da0436e9 JS |
6432 | } |
6433 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
6434 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | |
6435 | phba->sli4_hba.eq_ecount); | |
6436 | if (!qdesc) { | |
6437 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6438 | "0497 Failed allocate fast-path EQ\n"); | |
6439 | goto out_free_fp_eq; | |
6440 | } | |
6441 | phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc; | |
6442 | } | |
6443 | ||
6444 | /* | |
6445 | * Create Complete Queues (CQs) | |
6446 | */ | |
6447 | ||
da0436e9 JS |
6448 | /* Create slow-path Mailbox Command Complete Queue */ |
6449 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
6450 | phba->sli4_hba.cq_ecount); | |
6451 | if (!qdesc) { | |
6452 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6453 | "0500 Failed allocate slow-path mailbox CQ\n"); | |
6454 | goto out_free_fp_eq; | |
6455 | } | |
6456 | phba->sli4_hba.mbx_cq = qdesc; | |
6457 | ||
6458 | /* Create slow-path ELS Complete Queue */ | |
6459 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
6460 | phba->sli4_hba.cq_ecount); | |
6461 | if (!qdesc) { | |
6462 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6463 | "0501 Failed allocate slow-path ELS CQ\n"); | |
6464 | goto out_free_mbx_cq; | |
6465 | } | |
6466 | phba->sli4_hba.els_cq = qdesc; | |
6467 | ||
da0436e9 | 6468 | |
5350d872 JS |
6469 | /* |
6470 | * Create fast-path FCP Completion Queue(s), one-to-one with FCP EQs. | |
6471 | * If there are no FCP EQs then create exactly one FCP CQ. | |
6472 | */ | |
6473 | if (phba->cfg_fcp_eq_count) | |
6474 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * | |
6475 | phba->cfg_fcp_eq_count), | |
6476 | GFP_KERNEL); | |
6477 | else | |
6478 | phba->sli4_hba.fcp_cq = kzalloc(sizeof(struct lpfc_queue *), | |
6479 | GFP_KERNEL); | |
da0436e9 JS |
6480 | if (!phba->sli4_hba.fcp_cq) { |
6481 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6482 | "2577 Failed allocate memory for fast-path " | |
6483 | "CQ record array\n"); | |
4d9ab994 | 6484 | goto out_free_els_cq; |
da0436e9 | 6485 | } |
5350d872 JS |
6486 | fcp_cqidx = 0; |
6487 | do { | |
da0436e9 JS |
6488 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
6489 | phba->sli4_hba.cq_ecount); | |
6490 | if (!qdesc) { | |
6491 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6492 | "0499 Failed allocate fast-path FCP " | |
6493 | "CQ (%d)\n", fcp_cqidx); | |
6494 | goto out_free_fcp_cq; | |
6495 | } | |
6496 | phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc; | |
5350d872 | 6497 | } while (++fcp_cqidx < phba->cfg_fcp_eq_count); |
da0436e9 JS |
6498 | |
6499 | /* Create Mailbox Command Queue */ | |
6500 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; | |
6501 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; | |
6502 | ||
6503 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, | |
6504 | phba->sli4_hba.mq_ecount); | |
6505 | if (!qdesc) { | |
6506 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6507 | "0505 Failed allocate slow-path MQ\n"); | |
6508 | goto out_free_fcp_cq; | |
6509 | } | |
6510 | phba->sli4_hba.mbx_wq = qdesc; | |
6511 | ||
6512 | /* | |
6513 | * Create all the Work Queues (WQs) | |
6514 | */ | |
6515 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; | |
6516 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; | |
6517 | ||
6518 | /* Create slow-path ELS Work Queue */ | |
6519 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
6520 | phba->sli4_hba.wq_ecount); | |
6521 | if (!qdesc) { | |
6522 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6523 | "0504 Failed allocate slow-path ELS WQ\n"); | |
6524 | goto out_free_mbx_wq; | |
6525 | } | |
6526 | phba->sli4_hba.els_wq = qdesc; | |
6527 | ||
6528 | /* Create fast-path FCP Work Queue(s) */ | |
6529 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * | |
6530 | phba->cfg_fcp_wq_count), GFP_KERNEL); | |
6531 | if (!phba->sli4_hba.fcp_wq) { | |
6532 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6533 | "2578 Failed allocate memory for fast-path " | |
6534 | "WQ record array\n"); | |
6535 | goto out_free_els_wq; | |
6536 | } | |
6537 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { | |
6538 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
6539 | phba->sli4_hba.wq_ecount); | |
6540 | if (!qdesc) { | |
6541 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6542 | "0503 Failed allocate fast-path FCP " | |
6543 | "WQ (%d)\n", fcp_wqidx); | |
6544 | goto out_free_fcp_wq; | |
6545 | } | |
6546 | phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc; | |
6547 | } | |
6548 | ||
6549 | /* | |
6550 | * Create Receive Queue (RQ) | |
6551 | */ | |
6552 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; | |
6553 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; | |
6554 | ||
6555 | /* Create Receive Queue for header */ | |
6556 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
6557 | phba->sli4_hba.rq_ecount); | |
6558 | if (!qdesc) { | |
6559 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6560 | "0506 Failed allocate receive HRQ\n"); | |
6561 | goto out_free_fcp_wq; | |
6562 | } | |
6563 | phba->sli4_hba.hdr_rq = qdesc; | |
6564 | ||
6565 | /* Create Receive Queue for data */ | |
6566 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
6567 | phba->sli4_hba.rq_ecount); | |
6568 | if (!qdesc) { | |
6569 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6570 | "0507 Failed allocate receive DRQ\n"); | |
6571 | goto out_free_hdr_rq; | |
6572 | } | |
6573 | phba->sli4_hba.dat_rq = qdesc; | |
6574 | ||
6575 | return 0; | |
6576 | ||
6577 | out_free_hdr_rq: | |
6578 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); | |
6579 | phba->sli4_hba.hdr_rq = NULL; | |
6580 | out_free_fcp_wq: | |
6581 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) { | |
6582 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]); | |
6583 | phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL; | |
6584 | } | |
6585 | kfree(phba->sli4_hba.fcp_wq); | |
2e90f4b5 | 6586 | phba->sli4_hba.fcp_wq = NULL; |
da0436e9 JS |
6587 | out_free_els_wq: |
6588 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); | |
6589 | phba->sli4_hba.els_wq = NULL; | |
6590 | out_free_mbx_wq: | |
6591 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); | |
6592 | phba->sli4_hba.mbx_wq = NULL; | |
6593 | out_free_fcp_cq: | |
6594 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) { | |
6595 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]); | |
6596 | phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL; | |
6597 | } | |
6598 | kfree(phba->sli4_hba.fcp_cq); | |
2e90f4b5 | 6599 | phba->sli4_hba.fcp_cq = NULL; |
da0436e9 JS |
6600 | out_free_els_cq: |
6601 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); | |
6602 | phba->sli4_hba.els_cq = NULL; | |
6603 | out_free_mbx_cq: | |
6604 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); | |
6605 | phba->sli4_hba.mbx_cq = NULL; | |
6606 | out_free_fp_eq: | |
6607 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) { | |
6608 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]); | |
6609 | phba->sli4_hba.fp_eq[fcp_eqidx] = NULL; | |
6610 | } | |
6611 | kfree(phba->sli4_hba.fp_eq); | |
2e90f4b5 | 6612 | phba->sli4_hba.fp_eq = NULL; |
da0436e9 JS |
6613 | out_free_sp_eq: |
6614 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); | |
6615 | phba->sli4_hba.sp_eq = NULL; | |
6616 | out_error: | |
6617 | return -ENOMEM; | |
6618 | } | |
6619 | ||
6620 | /** | |
6621 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues | |
6622 | * @phba: pointer to lpfc hba data structure. | |
6623 | * | |
6624 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA | |
6625 | * operation. | |
6626 | * | |
6627 | * Return codes | |
af901ca1 | 6628 | * 0 - successful |
25985edc | 6629 | * -ENOMEM - No available memory |
d439d286 | 6630 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 | 6631 | **/ |
5350d872 | 6632 | void |
da0436e9 JS |
6633 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
6634 | { | |
6635 | int fcp_qidx; | |
6636 | ||
6637 | /* Release mailbox command work queue */ | |
6638 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); | |
6639 | phba->sli4_hba.mbx_wq = NULL; | |
6640 | ||
6641 | /* Release ELS work queue */ | |
6642 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); | |
6643 | phba->sli4_hba.els_wq = NULL; | |
6644 | ||
6645 | /* Release FCP work queue */ | |
2e90f4b5 JS |
6646 | if (phba->sli4_hba.fcp_wq != NULL) |
6647 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; | |
6648 | fcp_qidx++) | |
6649 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]); | |
da0436e9 JS |
6650 | kfree(phba->sli4_hba.fcp_wq); |
6651 | phba->sli4_hba.fcp_wq = NULL; | |
6652 | ||
6653 | /* Release unsolicited receive queue */ | |
6654 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); | |
6655 | phba->sli4_hba.hdr_rq = NULL; | |
6656 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); | |
6657 | phba->sli4_hba.dat_rq = NULL; | |
6658 | ||
da0436e9 JS |
6659 | /* Release ELS complete queue */ |
6660 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); | |
6661 | phba->sli4_hba.els_cq = NULL; | |
6662 | ||
6663 | /* Release mailbox command complete queue */ | |
6664 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); | |
6665 | phba->sli4_hba.mbx_cq = NULL; | |
6666 | ||
6667 | /* Release FCP response complete queue */ | |
0558056c | 6668 | fcp_qidx = 0; |
2e90f4b5 JS |
6669 | if (phba->sli4_hba.fcp_cq != NULL) |
6670 | do | |
6671 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]); | |
6672 | while (++fcp_qidx < phba->cfg_fcp_eq_count); | |
da0436e9 JS |
6673 | kfree(phba->sli4_hba.fcp_cq); |
6674 | phba->sli4_hba.fcp_cq = NULL; | |
6675 | ||
6676 | /* Release fast-path event queue */ | |
2e90f4b5 JS |
6677 | if (phba->sli4_hba.fp_eq != NULL) |
6678 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; | |
6679 | fcp_qidx++) | |
6680 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]); | |
da0436e9 JS |
6681 | kfree(phba->sli4_hba.fp_eq); |
6682 | phba->sli4_hba.fp_eq = NULL; | |
6683 | ||
6684 | /* Release slow-path event queue */ | |
6685 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); | |
6686 | phba->sli4_hba.sp_eq = NULL; | |
6687 | ||
6688 | return; | |
6689 | } | |
6690 | ||
6691 | /** | |
6692 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues | |
6693 | * @phba: pointer to lpfc hba data structure. | |
6694 | * | |
6695 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA | |
6696 | * operation. | |
6697 | * | |
6698 | * Return codes | |
af901ca1 | 6699 | * 0 - successful |
25985edc | 6700 | * -ENOMEM - No available memory |
d439d286 | 6701 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
6702 | **/ |
6703 | int | |
6704 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) | |
6705 | { | |
6706 | int rc = -ENOMEM; | |
6707 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; | |
6708 | int fcp_cq_index = 0; | |
6709 | ||
6710 | /* | |
6711 | * Set up Event Queues (EQs) | |
6712 | */ | |
6713 | ||
6714 | /* Set up slow-path event queue */ | |
6715 | if (!phba->sli4_hba.sp_eq) { | |
6716 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6717 | "0520 Slow-path EQ not allocated\n"); | |
6718 | goto out_error; | |
6719 | } | |
6720 | rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq, | |
6721 | LPFC_SP_DEF_IMAX); | |
6722 | if (rc) { | |
6723 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6724 | "0521 Failed setup of slow-path EQ: " | |
6725 | "rc = 0x%x\n", rc); | |
6726 | goto out_error; | |
6727 | } | |
6728 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6729 | "2583 Slow-path EQ setup: queue-id=%d\n", | |
6730 | phba->sli4_hba.sp_eq->queue_id); | |
6731 | ||
6732 | /* Set up fast-path event queue */ | |
1b51197d | 6733 | if (phba->cfg_fcp_eq_count && !phba->sli4_hba.fp_eq) { |
2e90f4b5 JS |
6734 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
6735 | "3147 Fast-path EQs not allocated\n"); | |
1b51197d | 6736 | rc = -ENOMEM; |
2e90f4b5 JS |
6737 | goto out_destroy_sp_eq; |
6738 | } | |
da0436e9 JS |
6739 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { |
6740 | if (!phba->sli4_hba.fp_eq[fcp_eqidx]) { | |
6741 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6742 | "0522 Fast-path EQ (%d) not " | |
6743 | "allocated\n", fcp_eqidx); | |
1b51197d | 6744 | rc = -ENOMEM; |
da0436e9 JS |
6745 | goto out_destroy_fp_eq; |
6746 | } | |
6747 | rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx], | |
6748 | phba->cfg_fcp_imax); | |
6749 | if (rc) { | |
6750 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6751 | "0523 Failed setup of fast-path EQ " | |
6752 | "(%d), rc = 0x%x\n", fcp_eqidx, rc); | |
6753 | goto out_destroy_fp_eq; | |
6754 | } | |
6755 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6756 | "2584 Fast-path EQ setup: " | |
6757 | "queue[%d]-id=%d\n", fcp_eqidx, | |
6758 | phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id); | |
6759 | } | |
6760 | ||
6761 | /* | |
6762 | * Set up Complete Queues (CQs) | |
6763 | */ | |
6764 | ||
6765 | /* Set up slow-path MBOX Complete Queue as the first CQ */ | |
6766 | if (!phba->sli4_hba.mbx_cq) { | |
6767 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6768 | "0528 Mailbox CQ not allocated\n"); | |
1b51197d | 6769 | rc = -ENOMEM; |
da0436e9 JS |
6770 | goto out_destroy_fp_eq; |
6771 | } | |
6772 | rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq, | |
6773 | LPFC_MCQ, LPFC_MBOX); | |
6774 | if (rc) { | |
6775 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6776 | "0529 Failed setup of slow-path mailbox CQ: " | |
6777 | "rc = 0x%x\n", rc); | |
6778 | goto out_destroy_fp_eq; | |
6779 | } | |
6780 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6781 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", | |
6782 | phba->sli4_hba.mbx_cq->queue_id, | |
6783 | phba->sli4_hba.sp_eq->queue_id); | |
6784 | ||
6785 | /* Set up slow-path ELS Complete Queue */ | |
6786 | if (!phba->sli4_hba.els_cq) { | |
6787 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6788 | "0530 ELS CQ not allocated\n"); | |
1b51197d | 6789 | rc = -ENOMEM; |
da0436e9 JS |
6790 | goto out_destroy_mbx_cq; |
6791 | } | |
6792 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq, | |
6793 | LPFC_WCQ, LPFC_ELS); | |
6794 | if (rc) { | |
6795 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6796 | "0531 Failed setup of slow-path ELS CQ: " | |
6797 | "rc = 0x%x\n", rc); | |
6798 | goto out_destroy_mbx_cq; | |
6799 | } | |
6800 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6801 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", | |
6802 | phba->sli4_hba.els_cq->queue_id, | |
6803 | phba->sli4_hba.sp_eq->queue_id); | |
6804 | ||
da0436e9 | 6805 | /* Set up fast-path FCP Response Complete Queue */ |
2e90f4b5 JS |
6806 | if (!phba->sli4_hba.fcp_cq) { |
6807 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6808 | "3148 Fast-path FCP CQ array not " | |
6809 | "allocated\n"); | |
1b51197d | 6810 | rc = -ENOMEM; |
2e90f4b5 JS |
6811 | goto out_destroy_els_cq; |
6812 | } | |
0558056c JS |
6813 | fcp_cqidx = 0; |
6814 | do { | |
da0436e9 JS |
6815 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { |
6816 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6817 | "0526 Fast-path FCP CQ (%d) not " | |
6818 | "allocated\n", fcp_cqidx); | |
1b51197d | 6819 | rc = -ENOMEM; |
da0436e9 JS |
6820 | goto out_destroy_fcp_cq; |
6821 | } | |
0558056c JS |
6822 | if (phba->cfg_fcp_eq_count) |
6823 | rc = lpfc_cq_create(phba, | |
6824 | phba->sli4_hba.fcp_cq[fcp_cqidx], | |
6825 | phba->sli4_hba.fp_eq[fcp_cqidx], | |
6826 | LPFC_WCQ, LPFC_FCP); | |
6827 | else | |
6828 | rc = lpfc_cq_create(phba, | |
6829 | phba->sli4_hba.fcp_cq[fcp_cqidx], | |
6830 | phba->sli4_hba.sp_eq, | |
6831 | LPFC_WCQ, LPFC_FCP); | |
da0436e9 JS |
6832 | if (rc) { |
6833 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6834 | "0527 Failed setup of fast-path FCP " | |
6835 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc); | |
6836 | goto out_destroy_fcp_cq; | |
6837 | } | |
6838 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6839 | "2588 FCP CQ setup: cq[%d]-id=%d, " | |
0558056c | 6840 | "parent %seq[%d]-id=%d\n", |
da0436e9 JS |
6841 | fcp_cqidx, |
6842 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, | |
0558056c | 6843 | (phba->cfg_fcp_eq_count) ? "" : "sp_", |
da0436e9 | 6844 | fcp_cqidx, |
0558056c JS |
6845 | (phba->cfg_fcp_eq_count) ? |
6846 | phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id : | |
6847 | phba->sli4_hba.sp_eq->queue_id); | |
6848 | } while (++fcp_cqidx < phba->cfg_fcp_eq_count); | |
da0436e9 JS |
6849 | |
6850 | /* | |
6851 | * Set up all the Work Queues (WQs) | |
6852 | */ | |
6853 | ||
6854 | /* Set up Mailbox Command Queue */ | |
6855 | if (!phba->sli4_hba.mbx_wq) { | |
6856 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6857 | "0538 Slow-path MQ not allocated\n"); | |
1b51197d | 6858 | rc = -ENOMEM; |
da0436e9 JS |
6859 | goto out_destroy_fcp_cq; |
6860 | } | |
6861 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, | |
6862 | phba->sli4_hba.mbx_cq, LPFC_MBOX); | |
6863 | if (rc) { | |
6864 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6865 | "0539 Failed setup of slow-path MQ: " | |
6866 | "rc = 0x%x\n", rc); | |
6867 | goto out_destroy_fcp_cq; | |
6868 | } | |
6869 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6870 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", | |
6871 | phba->sli4_hba.mbx_wq->queue_id, | |
6872 | phba->sli4_hba.mbx_cq->queue_id); | |
6873 | ||
6874 | /* Set up slow-path ELS Work Queue */ | |
6875 | if (!phba->sli4_hba.els_wq) { | |
6876 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6877 | "0536 Slow-path ELS WQ not allocated\n"); | |
1b51197d | 6878 | rc = -ENOMEM; |
da0436e9 JS |
6879 | goto out_destroy_mbx_wq; |
6880 | } | |
6881 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, | |
6882 | phba->sli4_hba.els_cq, LPFC_ELS); | |
6883 | if (rc) { | |
6884 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6885 | "0537 Failed setup of slow-path ELS WQ: " | |
6886 | "rc = 0x%x\n", rc); | |
6887 | goto out_destroy_mbx_wq; | |
6888 | } | |
6889 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6890 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", | |
6891 | phba->sli4_hba.els_wq->queue_id, | |
6892 | phba->sli4_hba.els_cq->queue_id); | |
6893 | ||
6894 | /* Set up fast-path FCP Work Queue */ | |
2e90f4b5 JS |
6895 | if (!phba->sli4_hba.fcp_wq) { |
6896 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6897 | "3149 Fast-path FCP WQ array not " | |
6898 | "allocated\n"); | |
1b51197d | 6899 | rc = -ENOMEM; |
2e90f4b5 JS |
6900 | goto out_destroy_els_wq; |
6901 | } | |
da0436e9 JS |
6902 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { |
6903 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { | |
6904 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6905 | "0534 Fast-path FCP WQ (%d) not " | |
6906 | "allocated\n", fcp_wqidx); | |
1b51197d | 6907 | rc = -ENOMEM; |
da0436e9 JS |
6908 | goto out_destroy_fcp_wq; |
6909 | } | |
6910 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], | |
6911 | phba->sli4_hba.fcp_cq[fcp_cq_index], | |
6912 | LPFC_FCP); | |
6913 | if (rc) { | |
6914 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6915 | "0535 Failed setup of fast-path FCP " | |
6916 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc); | |
6917 | goto out_destroy_fcp_wq; | |
6918 | } | |
6919 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6920 | "2591 FCP WQ setup: wq[%d]-id=%d, " | |
6921 | "parent cq[%d]-id=%d\n", | |
6922 | fcp_wqidx, | |
6923 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, | |
6924 | fcp_cq_index, | |
6925 | phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id); | |
6926 | /* Round robin FCP Work Queue's Completion Queue assignment */ | |
0558056c JS |
6927 | if (phba->cfg_fcp_eq_count) |
6928 | fcp_cq_index = ((fcp_cq_index + 1) % | |
6929 | phba->cfg_fcp_eq_count); | |
da0436e9 JS |
6930 | } |
6931 | ||
6932 | /* | |
6933 | * Create Receive Queue (RQ) | |
6934 | */ | |
6935 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { | |
6936 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6937 | "0540 Receive Queue not allocated\n"); | |
1b51197d | 6938 | rc = -ENOMEM; |
da0436e9 JS |
6939 | goto out_destroy_fcp_wq; |
6940 | } | |
73d91e50 JS |
6941 | |
6942 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ); | |
6943 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ); | |
6944 | ||
da0436e9 | 6945 | rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, |
4d9ab994 | 6946 | phba->sli4_hba.els_cq, LPFC_USOL); |
da0436e9 JS |
6947 | if (rc) { |
6948 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6949 | "0541 Failed setup of Receive Queue: " | |
6950 | "rc = 0x%x\n", rc); | |
6951 | goto out_destroy_fcp_wq; | |
6952 | } | |
73d91e50 | 6953 | |
da0436e9 JS |
6954 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
6955 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " | |
6956 | "parent cq-id=%d\n", | |
6957 | phba->sli4_hba.hdr_rq->queue_id, | |
6958 | phba->sli4_hba.dat_rq->queue_id, | |
4d9ab994 | 6959 | phba->sli4_hba.els_cq->queue_id); |
da0436e9 JS |
6960 | return 0; |
6961 | ||
6962 | out_destroy_fcp_wq: | |
6963 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) | |
6964 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); | |
2e90f4b5 | 6965 | out_destroy_els_wq: |
da0436e9 JS |
6966 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
6967 | out_destroy_mbx_wq: | |
6968 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | |
6969 | out_destroy_fcp_cq: | |
6970 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) | |
6971 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); | |
2e90f4b5 | 6972 | out_destroy_els_cq: |
da0436e9 JS |
6973 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
6974 | out_destroy_mbx_cq: | |
6975 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | |
6976 | out_destroy_fp_eq: | |
6977 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) | |
6978 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]); | |
2e90f4b5 | 6979 | out_destroy_sp_eq: |
da0436e9 JS |
6980 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); |
6981 | out_error: | |
6982 | return rc; | |
6983 | } | |
6984 | ||
6985 | /** | |
6986 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues | |
6987 | * @phba: pointer to lpfc hba data structure. | |
6988 | * | |
6989 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA | |
6990 | * operation. | |
6991 | * | |
6992 | * Return codes | |
af901ca1 | 6993 | * 0 - successful |
25985edc | 6994 | * -ENOMEM - No available memory |
d439d286 | 6995 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
6996 | **/ |
6997 | void | |
6998 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) | |
6999 | { | |
7000 | int fcp_qidx; | |
7001 | ||
7002 | /* Unset mailbox command work queue */ | |
7003 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | |
7004 | /* Unset ELS work queue */ | |
7005 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); | |
7006 | /* Unset unsolicited receive queue */ | |
7007 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); | |
7008 | /* Unset FCP work queue */ | |
7009 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) | |
7010 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); | |
7011 | /* Unset mailbox command complete queue */ | |
7012 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | |
7013 | /* Unset ELS complete queue */ | |
7014 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); | |
da0436e9 | 7015 | /* Unset FCP response complete queue */ |
2e90f4b5 JS |
7016 | if (phba->sli4_hba.fcp_cq) { |
7017 | fcp_qidx = 0; | |
7018 | do { | |
7019 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); | |
7020 | } while (++fcp_qidx < phba->cfg_fcp_eq_count); | |
7021 | } | |
da0436e9 | 7022 | /* Unset fast-path event queue */ |
2e90f4b5 JS |
7023 | if (phba->sli4_hba.fp_eq) { |
7024 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; | |
7025 | fcp_qidx++) | |
7026 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]); | |
7027 | } | |
da0436e9 JS |
7028 | /* Unset slow-path event queue */ |
7029 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); | |
7030 | } | |
7031 | ||
7032 | /** | |
7033 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool | |
7034 | * @phba: pointer to lpfc hba data structure. | |
7035 | * | |
7036 | * This routine is invoked to allocate and set up a pool of completion queue | |
7037 | * events. The body of the completion queue event is a completion queue entry | |
7038 | * CQE. For now, this pool is used for the interrupt service routine to queue | |
7039 | * the following HBA completion queue events for the worker thread to process: | |
7040 | * - Mailbox asynchronous events | |
7041 | * - Receive queue completion unsolicited events | |
7042 | * Later, this can be used for all the slow-path events. | |
7043 | * | |
7044 | * Return codes | |
af901ca1 | 7045 | * 0 - successful |
25985edc | 7046 | * -ENOMEM - No available memory |
da0436e9 JS |
7047 | **/ |
7048 | static int | |
7049 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) | |
7050 | { | |
7051 | struct lpfc_cq_event *cq_event; | |
7052 | int i; | |
7053 | ||
7054 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { | |
7055 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); | |
7056 | if (!cq_event) | |
7057 | goto out_pool_create_fail; | |
7058 | list_add_tail(&cq_event->list, | |
7059 | &phba->sli4_hba.sp_cqe_event_pool); | |
7060 | } | |
7061 | return 0; | |
7062 | ||
7063 | out_pool_create_fail: | |
7064 | lpfc_sli4_cq_event_pool_destroy(phba); | |
7065 | return -ENOMEM; | |
7066 | } | |
7067 | ||
7068 | /** | |
7069 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool | |
7070 | * @phba: pointer to lpfc hba data structure. | |
7071 | * | |
7072 | * This routine is invoked to free the pool of completion queue events at | |
7073 | * driver unload time. Note that, it is the responsibility of the driver | |
7074 | * cleanup routine to free all the outstanding completion-queue events | |
7075 | * allocated from this pool back into the pool before invoking this routine | |
7076 | * to destroy the pool. | |
7077 | **/ | |
7078 | static void | |
7079 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) | |
7080 | { | |
7081 | struct lpfc_cq_event *cq_event, *next_cq_event; | |
7082 | ||
7083 | list_for_each_entry_safe(cq_event, next_cq_event, | |
7084 | &phba->sli4_hba.sp_cqe_event_pool, list) { | |
7085 | list_del(&cq_event->list); | |
7086 | kfree(cq_event); | |
7087 | } | |
7088 | } | |
7089 | ||
7090 | /** | |
7091 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
7092 | * @phba: pointer to lpfc hba data structure. | |
7093 | * | |
7094 | * This routine is the lock free version of the API invoked to allocate a | |
7095 | * completion-queue event from the free pool. | |
7096 | * | |
7097 | * Return: Pointer to the newly allocated completion-queue event if successful | |
7098 | * NULL otherwise. | |
7099 | **/ | |
7100 | struct lpfc_cq_event * | |
7101 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
7102 | { | |
7103 | struct lpfc_cq_event *cq_event = NULL; | |
7104 | ||
7105 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, | |
7106 | struct lpfc_cq_event, list); | |
7107 | return cq_event; | |
7108 | } | |
7109 | ||
7110 | /** | |
7111 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
7112 | * @phba: pointer to lpfc hba data structure. | |
7113 | * | |
7114 | * This routine is the lock version of the API invoked to allocate a | |
7115 | * completion-queue event from the free pool. | |
7116 | * | |
7117 | * Return: Pointer to the newly allocated completion-queue event if successful | |
7118 | * NULL otherwise. | |
7119 | **/ | |
7120 | struct lpfc_cq_event * | |
7121 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
7122 | { | |
7123 | struct lpfc_cq_event *cq_event; | |
7124 | unsigned long iflags; | |
7125 | ||
7126 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7127 | cq_event = __lpfc_sli4_cq_event_alloc(phba); | |
7128 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7129 | return cq_event; | |
7130 | } | |
7131 | ||
7132 | /** | |
7133 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
7134 | * @phba: pointer to lpfc hba data structure. | |
7135 | * @cq_event: pointer to the completion queue event to be freed. | |
7136 | * | |
7137 | * This routine is the lock free version of the API invoked to release a | |
7138 | * completion-queue event back into the free pool. | |
7139 | **/ | |
7140 | void | |
7141 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
7142 | struct lpfc_cq_event *cq_event) | |
7143 | { | |
7144 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); | |
7145 | } | |
7146 | ||
7147 | /** | |
7148 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
7149 | * @phba: pointer to lpfc hba data structure. | |
7150 | * @cq_event: pointer to the completion queue event to be freed. | |
7151 | * | |
7152 | * This routine is the lock version of the API invoked to release a | |
7153 | * completion-queue event back into the free pool. | |
7154 | **/ | |
7155 | void | |
7156 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
7157 | struct lpfc_cq_event *cq_event) | |
7158 | { | |
7159 | unsigned long iflags; | |
7160 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7161 | __lpfc_sli4_cq_event_release(phba, cq_event); | |
7162 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7163 | } | |
7164 | ||
7165 | /** | |
7166 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool | |
7167 | * @phba: pointer to lpfc hba data structure. | |
7168 | * | |
7169 | * This routine is to free all the pending completion-queue events to the | |
7170 | * back into the free pool for device reset. | |
7171 | **/ | |
7172 | static void | |
7173 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) | |
7174 | { | |
7175 | LIST_HEAD(cqelist); | |
7176 | struct lpfc_cq_event *cqe; | |
7177 | unsigned long iflags; | |
7178 | ||
7179 | /* Retrieve all the pending WCQEs from pending WCQE lists */ | |
7180 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7181 | /* Pending FCP XRI abort events */ | |
7182 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
7183 | &cqelist); | |
7184 | /* Pending ELS XRI abort events */ | |
7185 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
7186 | &cqelist); | |
7187 | /* Pending asynnc events */ | |
7188 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, | |
7189 | &cqelist); | |
7190 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7191 | ||
7192 | while (!list_empty(&cqelist)) { | |
7193 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); | |
7194 | lpfc_sli4_cq_event_release(phba, cqe); | |
7195 | } | |
7196 | } | |
7197 | ||
7198 | /** | |
7199 | * lpfc_pci_function_reset - Reset pci function. | |
7200 | * @phba: pointer to lpfc hba data structure. | |
7201 | * | |
7202 | * This routine is invoked to request a PCI function reset. It will destroys | |
7203 | * all resources assigned to the PCI function which originates this request. | |
7204 | * | |
7205 | * Return codes | |
af901ca1 | 7206 | * 0 - successful |
25985edc | 7207 | * -ENOMEM - No available memory |
d439d286 | 7208 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
7209 | **/ |
7210 | int | |
7211 | lpfc_pci_function_reset(struct lpfc_hba *phba) | |
7212 | { | |
7213 | LPFC_MBOXQ_t *mboxq; | |
2fcee4bf | 7214 | uint32_t rc = 0, if_type; |
da0436e9 | 7215 | uint32_t shdr_status, shdr_add_status; |
2fcee4bf | 7216 | uint32_t rdy_chk, num_resets = 0, reset_again = 0; |
da0436e9 | 7217 | union lpfc_sli4_cfg_shdr *shdr; |
2fcee4bf | 7218 | struct lpfc_register reg_data; |
da0436e9 | 7219 | |
2fcee4bf JS |
7220 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
7221 | switch (if_type) { | |
7222 | case LPFC_SLI_INTF_IF_TYPE_0: | |
7223 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, | |
7224 | GFP_KERNEL); | |
7225 | if (!mboxq) { | |
7226 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7227 | "0494 Unable to allocate memory for " | |
7228 | "issuing SLI_FUNCTION_RESET mailbox " | |
7229 | "command\n"); | |
7230 | return -ENOMEM; | |
7231 | } | |
da0436e9 | 7232 | |
2fcee4bf JS |
7233 | /* Setup PCI function reset mailbox-ioctl command */ |
7234 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
7235 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, | |
7236 | LPFC_SLI4_MBX_EMBED); | |
7237 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7238 | shdr = (union lpfc_sli4_cfg_shdr *) | |
7239 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
7240 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
7241 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
7242 | &shdr->response); | |
7243 | if (rc != MBX_TIMEOUT) | |
7244 | mempool_free(mboxq, phba->mbox_mem_pool); | |
7245 | if (shdr_status || shdr_add_status || rc) { | |
7246 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7247 | "0495 SLI_FUNCTION_RESET mailbox " | |
7248 | "failed with status x%x add_status x%x," | |
7249 | " mbx status x%x\n", | |
7250 | shdr_status, shdr_add_status, rc); | |
7251 | rc = -ENXIO; | |
7252 | } | |
7253 | break; | |
7254 | case LPFC_SLI_INTF_IF_TYPE_2: | |
7255 | for (num_resets = 0; | |
7256 | num_resets < MAX_IF_TYPE_2_RESETS; | |
7257 | num_resets++) { | |
7258 | reg_data.word0 = 0; | |
7259 | bf_set(lpfc_sliport_ctrl_end, ®_data, | |
7260 | LPFC_SLIPORT_LITTLE_ENDIAN); | |
7261 | bf_set(lpfc_sliport_ctrl_ip, ®_data, | |
7262 | LPFC_SLIPORT_INIT_PORT); | |
7263 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. | |
7264 | CTRLregaddr); | |
7265 | ||
7266 | /* | |
7267 | * Poll the Port Status Register and wait for RDY for | |
7268 | * up to 10 seconds. If the port doesn't respond, treat | |
7269 | * it as an error. If the port responds with RN, start | |
7270 | * the loop again. | |
7271 | */ | |
7272 | for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) { | |
73d91e50 | 7273 | msleep(10); |
9940b97b JS |
7274 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
7275 | STATUSregaddr, ®_data.word0)) { | |
7276 | rc = -ENODEV; | |
73d91e50 | 7277 | goto out; |
9940b97b | 7278 | } |
6b5151fd | 7279 | if (bf_get(lpfc_sliport_status_rn, ®_data)) |
2fcee4bf | 7280 | reset_again++; |
6b5151fd | 7281 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
2fcee4bf | 7282 | break; |
2fcee4bf JS |
7283 | } |
7284 | ||
7285 | /* | |
7286 | * If the port responds to the init request with | |
7287 | * reset needed, delay for a bit and restart the loop. | |
7288 | */ | |
6b5151fd | 7289 | if (reset_again && (rdy_chk < 1000)) { |
2fcee4bf JS |
7290 | msleep(10); |
7291 | reset_again = 0; | |
7292 | continue; | |
7293 | } | |
7294 | ||
7295 | /* Detect any port errors. */ | |
2fcee4bf JS |
7296 | if ((bf_get(lpfc_sliport_status_err, ®_data)) || |
7297 | (rdy_chk >= 1000)) { | |
7298 | phba->work_status[0] = readl( | |
7299 | phba->sli4_hba.u.if_type2.ERR1regaddr); | |
7300 | phba->work_status[1] = readl( | |
7301 | phba->sli4_hba.u.if_type2.ERR2regaddr); | |
7302 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7303 | "2890 Port Error Detected " | |
7304 | "during Port Reset: " | |
7305 | "port status reg 0x%x, " | |
7306 | "error 1=0x%x, error 2=0x%x\n", | |
7307 | reg_data.word0, | |
7308 | phba->work_status[0], | |
7309 | phba->work_status[1]); | |
7310 | rc = -ENODEV; | |
7311 | } | |
7312 | ||
7313 | /* | |
7314 | * Terminate the outer loop provided the Port indicated | |
7315 | * ready within 10 seconds. | |
7316 | */ | |
7317 | if (rdy_chk < 1000) | |
7318 | break; | |
7319 | } | |
0558056c JS |
7320 | /* delay driver action following IF_TYPE_2 function reset */ |
7321 | msleep(100); | |
2fcee4bf JS |
7322 | break; |
7323 | case LPFC_SLI_INTF_IF_TYPE_1: | |
7324 | default: | |
7325 | break; | |
da0436e9 | 7326 | } |
2fcee4bf | 7327 | |
73d91e50 | 7328 | out: |
2fcee4bf JS |
7329 | /* Catch the not-ready port failure after a port reset. */ |
7330 | if (num_resets >= MAX_IF_TYPE_2_RESETS) | |
7331 | rc = -ENODEV; | |
7332 | ||
da0436e9 JS |
7333 | return rc; |
7334 | } | |
7335 | ||
7336 | /** | |
7337 | * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands | |
7338 | * @phba: pointer to lpfc hba data structure. | |
7339 | * @cnt: number of nop mailbox commands to send. | |
7340 | * | |
7341 | * This routine is invoked to send a number @cnt of NOP mailbox command and | |
7342 | * wait for each command to complete. | |
7343 | * | |
7344 | * Return: the number of NOP mailbox command completed. | |
7345 | **/ | |
7346 | static int | |
7347 | lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt) | |
7348 | { | |
7349 | LPFC_MBOXQ_t *mboxq; | |
7350 | int length, cmdsent; | |
7351 | uint32_t mbox_tmo; | |
7352 | uint32_t rc = 0; | |
7353 | uint32_t shdr_status, shdr_add_status; | |
7354 | union lpfc_sli4_cfg_shdr *shdr; | |
7355 | ||
7356 | if (cnt == 0) { | |
7357 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7358 | "2518 Requested to send 0 NOP mailbox cmd\n"); | |
7359 | return cnt; | |
7360 | } | |
7361 | ||
7362 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
7363 | if (!mboxq) { | |
7364 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7365 | "2519 Unable to allocate memory for issuing " | |
7366 | "NOP mailbox command\n"); | |
7367 | return 0; | |
7368 | } | |
7369 | ||
7370 | /* Set up NOP SLI4_CONFIG mailbox-ioctl command */ | |
7371 | length = (sizeof(struct lpfc_mbx_nop) - | |
7372 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
7373 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
7374 | LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED); | |
7375 | ||
da0436e9 JS |
7376 | for (cmdsent = 0; cmdsent < cnt; cmdsent++) { |
7377 | if (!phba->sli4_hba.intr_enable) | |
7378 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
a183a15f JS |
7379 | else { |
7380 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); | |
da0436e9 | 7381 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
a183a15f | 7382 | } |
da0436e9 JS |
7383 | if (rc == MBX_TIMEOUT) |
7384 | break; | |
7385 | /* Check return status */ | |
7386 | shdr = (union lpfc_sli4_cfg_shdr *) | |
7387 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
7388 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
7389 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
7390 | &shdr->response); | |
7391 | if (shdr_status || shdr_add_status || rc) { | |
7392 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7393 | "2520 NOP mailbox command failed " | |
7394 | "status x%x add_status x%x mbx " | |
7395 | "status x%x\n", shdr_status, | |
7396 | shdr_add_status, rc); | |
7397 | break; | |
7398 | } | |
7399 | } | |
7400 | ||
7401 | if (rc != MBX_TIMEOUT) | |
7402 | mempool_free(mboxq, phba->mbox_mem_pool); | |
7403 | ||
7404 | return cmdsent; | |
7405 | } | |
7406 | ||
da0436e9 JS |
7407 | /** |
7408 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. | |
7409 | * @phba: pointer to lpfc hba data structure. | |
7410 | * | |
7411 | * This routine is invoked to set up the PCI device memory space for device | |
7412 | * with SLI-4 interface spec. | |
7413 | * | |
7414 | * Return codes | |
af901ca1 | 7415 | * 0 - successful |
da0436e9 JS |
7416 | * other values - error |
7417 | **/ | |
7418 | static int | |
7419 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) | |
7420 | { | |
7421 | struct pci_dev *pdev; | |
7422 | unsigned long bar0map_len, bar1map_len, bar2map_len; | |
7423 | int error = -ENODEV; | |
2fcee4bf | 7424 | uint32_t if_type; |
da0436e9 JS |
7425 | |
7426 | /* Obtain PCI device reference */ | |
7427 | if (!phba->pcidev) | |
7428 | return error; | |
7429 | else | |
7430 | pdev = phba->pcidev; | |
7431 | ||
7432 | /* Set the device DMA mask size */ | |
8e68597d MR |
7433 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
7434 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
7435 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
7436 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
da0436e9 | 7437 | return error; |
8e68597d MR |
7438 | } |
7439 | } | |
da0436e9 | 7440 | |
2fcee4bf JS |
7441 | /* |
7442 | * The BARs and register set definitions and offset locations are | |
7443 | * dependent on the if_type. | |
7444 | */ | |
7445 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, | |
7446 | &phba->sli4_hba.sli_intf.word0)) { | |
7447 | return error; | |
7448 | } | |
7449 | ||
7450 | /* There is no SLI3 failback for SLI4 devices. */ | |
7451 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != | |
7452 | LPFC_SLI_INTF_VALID) { | |
7453 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7454 | "2894 SLI_INTF reg contents invalid " | |
7455 | "sli_intf reg 0x%x\n", | |
7456 | phba->sli4_hba.sli_intf.word0); | |
7457 | return error; | |
7458 | } | |
7459 | ||
7460 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); | |
7461 | /* | |
7462 | * Get the bus address of SLI4 device Bar regions and the | |
7463 | * number of bytes required by each mapping. The mapping of the | |
7464 | * particular PCI BARs regions is dependent on the type of | |
7465 | * SLI4 device. | |
da0436e9 | 7466 | */ |
1dfb5a47 JS |
7467 | if (pci_resource_start(pdev, 0)) { |
7468 | phba->pci_bar0_map = pci_resource_start(pdev, 0); | |
7469 | bar0map_len = pci_resource_len(pdev, 0); | |
2fcee4bf JS |
7470 | |
7471 | /* | |
7472 | * Map SLI4 PCI Config Space Register base to a kernel virtual | |
7473 | * addr | |
7474 | */ | |
7475 | phba->sli4_hba.conf_regs_memmap_p = | |
7476 | ioremap(phba->pci_bar0_map, bar0map_len); | |
7477 | if (!phba->sli4_hba.conf_regs_memmap_p) { | |
7478 | dev_printk(KERN_ERR, &pdev->dev, | |
7479 | "ioremap failed for SLI4 PCI config " | |
7480 | "registers.\n"); | |
7481 | goto out; | |
7482 | } | |
7483 | /* Set up BAR0 PCI config space register memory map */ | |
7484 | lpfc_sli4_bar0_register_memmap(phba, if_type); | |
1dfb5a47 JS |
7485 | } else { |
7486 | phba->pci_bar0_map = pci_resource_start(pdev, 1); | |
7487 | bar0map_len = pci_resource_len(pdev, 1); | |
2fcee4bf JS |
7488 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
7489 | dev_printk(KERN_ERR, &pdev->dev, | |
7490 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); | |
7491 | goto out; | |
7492 | } | |
7493 | phba->sli4_hba.conf_regs_memmap_p = | |
da0436e9 | 7494 | ioremap(phba->pci_bar0_map, bar0map_len); |
2fcee4bf JS |
7495 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
7496 | dev_printk(KERN_ERR, &pdev->dev, | |
7497 | "ioremap failed for SLI4 PCI config " | |
7498 | "registers.\n"); | |
7499 | goto out; | |
7500 | } | |
7501 | lpfc_sli4_bar0_register_memmap(phba, if_type); | |
da0436e9 JS |
7502 | } |
7503 | ||
c31098ce JS |
7504 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
7505 | (pci_resource_start(pdev, 2))) { | |
2fcee4bf JS |
7506 | /* |
7507 | * Map SLI4 if type 0 HBA Control Register base to a kernel | |
7508 | * virtual address and setup the registers. | |
7509 | */ | |
7510 | phba->pci_bar1_map = pci_resource_start(pdev, 2); | |
7511 | bar1map_len = pci_resource_len(pdev, 2); | |
7512 | phba->sli4_hba.ctrl_regs_memmap_p = | |
da0436e9 | 7513 | ioremap(phba->pci_bar1_map, bar1map_len); |
2fcee4bf JS |
7514 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
7515 | dev_printk(KERN_ERR, &pdev->dev, | |
da0436e9 | 7516 | "ioremap failed for SLI4 HBA control registers.\n"); |
2fcee4bf JS |
7517 | goto out_iounmap_conf; |
7518 | } | |
7519 | lpfc_sli4_bar1_register_memmap(phba); | |
da0436e9 JS |
7520 | } |
7521 | ||
c31098ce JS |
7522 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
7523 | (pci_resource_start(pdev, 4))) { | |
2fcee4bf JS |
7524 | /* |
7525 | * Map SLI4 if type 0 HBA Doorbell Register base to a kernel | |
7526 | * virtual address and setup the registers. | |
7527 | */ | |
7528 | phba->pci_bar2_map = pci_resource_start(pdev, 4); | |
7529 | bar2map_len = pci_resource_len(pdev, 4); | |
7530 | phba->sli4_hba.drbl_regs_memmap_p = | |
da0436e9 | 7531 | ioremap(phba->pci_bar2_map, bar2map_len); |
2fcee4bf JS |
7532 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
7533 | dev_printk(KERN_ERR, &pdev->dev, | |
da0436e9 | 7534 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
2fcee4bf JS |
7535 | goto out_iounmap_ctrl; |
7536 | } | |
7537 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); | |
7538 | if (error) | |
7539 | goto out_iounmap_all; | |
da0436e9 JS |
7540 | } |
7541 | ||
da0436e9 JS |
7542 | return 0; |
7543 | ||
7544 | out_iounmap_all: | |
7545 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
7546 | out_iounmap_ctrl: | |
7547 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
7548 | out_iounmap_conf: | |
7549 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
7550 | out: | |
7551 | return error; | |
7552 | } | |
7553 | ||
7554 | /** | |
7555 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. | |
7556 | * @phba: pointer to lpfc hba data structure. | |
7557 | * | |
7558 | * This routine is invoked to unset the PCI device memory space for device | |
7559 | * with SLI-4 interface spec. | |
7560 | **/ | |
7561 | static void | |
7562 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) | |
7563 | { | |
2e90f4b5 JS |
7564 | uint32_t if_type; |
7565 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); | |
da0436e9 | 7566 | |
2e90f4b5 JS |
7567 | switch (if_type) { |
7568 | case LPFC_SLI_INTF_IF_TYPE_0: | |
7569 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
7570 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
7571 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
7572 | break; | |
7573 | case LPFC_SLI_INTF_IF_TYPE_2: | |
7574 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
7575 | break; | |
7576 | case LPFC_SLI_INTF_IF_TYPE_1: | |
7577 | default: | |
7578 | dev_printk(KERN_ERR, &phba->pcidev->dev, | |
7579 | "FATAL - unsupported SLI4 interface type - %d\n", | |
7580 | if_type); | |
7581 | break; | |
7582 | } | |
da0436e9 JS |
7583 | } |
7584 | ||
7585 | /** | |
7586 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device | |
7587 | * @phba: pointer to lpfc hba data structure. | |
7588 | * | |
7589 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
7590 | * with SLI-3 interface specs. The kernel function pci_enable_msix() is | |
7591 | * called to enable the MSI-X vectors. Note that pci_enable_msix(), once | |
7592 | * invoked, enables either all or nothing, depending on the current | |
7593 | * availability of PCI vector resources. The device driver is responsible | |
7594 | * for calling the individual request_irq() to register each MSI-X vector | |
7595 | * with a interrupt handler, which is done in this function. Note that | |
7596 | * later when device is unloading, the driver should always call free_irq() | |
7597 | * on all MSI-X vectors it has done request_irq() on before calling | |
7598 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device | |
7599 | * will be left with MSI-X enabled and leaks its vectors. | |
7600 | * | |
7601 | * Return codes | |
af901ca1 | 7602 | * 0 - successful |
da0436e9 JS |
7603 | * other values - error |
7604 | **/ | |
7605 | static int | |
7606 | lpfc_sli_enable_msix(struct lpfc_hba *phba) | |
7607 | { | |
7608 | int rc, i; | |
7609 | LPFC_MBOXQ_t *pmb; | |
7610 | ||
7611 | /* Set up MSI-X multi-message vectors */ | |
7612 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
7613 | phba->msix_entries[i].entry = i; | |
7614 | ||
7615 | /* Configure MSI-X capability structure */ | |
7616 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, | |
7617 | ARRAY_SIZE(phba->msix_entries)); | |
7618 | if (rc) { | |
7619 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7620 | "0420 PCI enable MSI-X failed (%d)\n", rc); | |
7621 | goto msi_fail_out; | |
7622 | } | |
7623 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
7624 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7625 | "0477 MSI-X entry[%d]: vector=x%x " | |
7626 | "message=%d\n", i, | |
7627 | phba->msix_entries[i].vector, | |
7628 | phba->msix_entries[i].entry); | |
7629 | /* | |
7630 | * Assign MSI-X vectors to interrupt handlers | |
7631 | */ | |
7632 | ||
7633 | /* vector-0 is associated to slow-path handler */ | |
7634 | rc = request_irq(phba->msix_entries[0].vector, | |
7635 | &lpfc_sli_sp_intr_handler, IRQF_SHARED, | |
7636 | LPFC_SP_DRIVER_HANDLER_NAME, phba); | |
7637 | if (rc) { | |
7638 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7639 | "0421 MSI-X slow-path request_irq failed " | |
7640 | "(%d)\n", rc); | |
7641 | goto msi_fail_out; | |
7642 | } | |
7643 | ||
7644 | /* vector-1 is associated to fast-path handler */ | |
7645 | rc = request_irq(phba->msix_entries[1].vector, | |
7646 | &lpfc_sli_fp_intr_handler, IRQF_SHARED, | |
7647 | LPFC_FP_DRIVER_HANDLER_NAME, phba); | |
7648 | ||
7649 | if (rc) { | |
7650 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7651 | "0429 MSI-X fast-path request_irq failed " | |
7652 | "(%d)\n", rc); | |
7653 | goto irq_fail_out; | |
7654 | } | |
7655 | ||
7656 | /* | |
7657 | * Configure HBA MSI-X attention conditions to messages | |
7658 | */ | |
7659 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
7660 | ||
7661 | if (!pmb) { | |
7662 | rc = -ENOMEM; | |
7663 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7664 | "0474 Unable to allocate memory for issuing " | |
7665 | "MBOX_CONFIG_MSI command\n"); | |
7666 | goto mem_fail_out; | |
7667 | } | |
7668 | rc = lpfc_config_msi(phba, pmb); | |
7669 | if (rc) | |
7670 | goto mbx_fail_out; | |
7671 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
7672 | if (rc != MBX_SUCCESS) { | |
7673 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | |
7674 | "0351 Config MSI mailbox command failed, " | |
7675 | "mbxCmd x%x, mbxStatus x%x\n", | |
7676 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); | |
7677 | goto mbx_fail_out; | |
7678 | } | |
7679 | ||
7680 | /* Free memory allocated for mailbox command */ | |
7681 | mempool_free(pmb, phba->mbox_mem_pool); | |
7682 | return rc; | |
7683 | ||
7684 | mbx_fail_out: | |
7685 | /* Free memory allocated for mailbox command */ | |
7686 | mempool_free(pmb, phba->mbox_mem_pool); | |
7687 | ||
7688 | mem_fail_out: | |
7689 | /* free the irq already requested */ | |
7690 | free_irq(phba->msix_entries[1].vector, phba); | |
7691 | ||
7692 | irq_fail_out: | |
7693 | /* free the irq already requested */ | |
7694 | free_irq(phba->msix_entries[0].vector, phba); | |
7695 | ||
7696 | msi_fail_out: | |
7697 | /* Unconfigure MSI-X capability structure */ | |
7698 | pci_disable_msix(phba->pcidev); | |
7699 | return rc; | |
7700 | } | |
7701 | ||
7702 | /** | |
7703 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. | |
7704 | * @phba: pointer to lpfc hba data structure. | |
7705 | * | |
7706 | * This routine is invoked to release the MSI-X vectors and then disable the | |
7707 | * MSI-X interrupt mode to device with SLI-3 interface spec. | |
7708 | **/ | |
7709 | static void | |
7710 | lpfc_sli_disable_msix(struct lpfc_hba *phba) | |
7711 | { | |
7712 | int i; | |
7713 | ||
7714 | /* Free up MSI-X multi-message vectors */ | |
7715 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
7716 | free_irq(phba->msix_entries[i].vector, phba); | |
7717 | /* Disable MSI-X */ | |
7718 | pci_disable_msix(phba->pcidev); | |
7719 | ||
7720 | return; | |
7721 | } | |
7722 | ||
7723 | /** | |
7724 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. | |
7725 | * @phba: pointer to lpfc hba data structure. | |
7726 | * | |
7727 | * This routine is invoked to enable the MSI interrupt mode to device with | |
7728 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to | |
7729 | * enable the MSI vector. The device driver is responsible for calling the | |
7730 | * request_irq() to register MSI vector with a interrupt the handler, which | |
7731 | * is done in this function. | |
7732 | * | |
7733 | * Return codes | |
af901ca1 | 7734 | * 0 - successful |
da0436e9 JS |
7735 | * other values - error |
7736 | */ | |
7737 | static int | |
7738 | lpfc_sli_enable_msi(struct lpfc_hba *phba) | |
7739 | { | |
7740 | int rc; | |
7741 | ||
7742 | rc = pci_enable_msi(phba->pcidev); | |
7743 | if (!rc) | |
7744 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7745 | "0462 PCI enable MSI mode success.\n"); | |
7746 | else { | |
7747 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7748 | "0471 PCI enable MSI mode failed (%d)\n", rc); | |
7749 | return rc; | |
7750 | } | |
7751 | ||
7752 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
7753 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
7754 | if (rc) { | |
7755 | pci_disable_msi(phba->pcidev); | |
7756 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7757 | "0478 MSI request_irq failed (%d)\n", rc); | |
7758 | } | |
7759 | return rc; | |
7760 | } | |
7761 | ||
7762 | /** | |
7763 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. | |
7764 | * @phba: pointer to lpfc hba data structure. | |
7765 | * | |
7766 | * This routine is invoked to disable the MSI interrupt mode to device with | |
7767 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has | |
7768 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | |
7769 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | |
7770 | * its vector. | |
7771 | */ | |
7772 | static void | |
7773 | lpfc_sli_disable_msi(struct lpfc_hba *phba) | |
7774 | { | |
7775 | free_irq(phba->pcidev->irq, phba); | |
7776 | pci_disable_msi(phba->pcidev); | |
7777 | return; | |
7778 | } | |
7779 | ||
7780 | /** | |
7781 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. | |
7782 | * @phba: pointer to lpfc hba data structure. | |
7783 | * | |
7784 | * This routine is invoked to enable device interrupt and associate driver's | |
7785 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface | |
7786 | * spec. Depends on the interrupt mode configured to the driver, the driver | |
7787 | * will try to fallback from the configured interrupt mode to an interrupt | |
7788 | * mode which is supported by the platform, kernel, and device in the order | |
7789 | * of: | |
7790 | * MSI-X -> MSI -> IRQ. | |
7791 | * | |
7792 | * Return codes | |
af901ca1 | 7793 | * 0 - successful |
da0436e9 JS |
7794 | * other values - error |
7795 | **/ | |
7796 | static uint32_t | |
7797 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
7798 | { | |
7799 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
7800 | int retval; | |
7801 | ||
7802 | if (cfg_mode == 2) { | |
7803 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ | |
7804 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); | |
7805 | if (!retval) { | |
7806 | /* Now, try to enable MSI-X interrupt mode */ | |
7807 | retval = lpfc_sli_enable_msix(phba); | |
7808 | if (!retval) { | |
7809 | /* Indicate initialization to MSI-X mode */ | |
7810 | phba->intr_type = MSIX; | |
7811 | intr_mode = 2; | |
7812 | } | |
7813 | } | |
7814 | } | |
7815 | ||
7816 | /* Fallback to MSI if MSI-X initialization failed */ | |
7817 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
7818 | retval = lpfc_sli_enable_msi(phba); | |
7819 | if (!retval) { | |
7820 | /* Indicate initialization to MSI mode */ | |
7821 | phba->intr_type = MSI; | |
7822 | intr_mode = 1; | |
7823 | } | |
7824 | } | |
7825 | ||
7826 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
7827 | if (phba->intr_type == NONE) { | |
7828 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
7829 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
7830 | if (!retval) { | |
7831 | /* Indicate initialization to INTx mode */ | |
7832 | phba->intr_type = INTx; | |
7833 | intr_mode = 0; | |
7834 | } | |
7835 | } | |
7836 | return intr_mode; | |
7837 | } | |
7838 | ||
7839 | /** | |
7840 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. | |
7841 | * @phba: pointer to lpfc hba data structure. | |
7842 | * | |
7843 | * This routine is invoked to disable device interrupt and disassociate the | |
7844 | * driver's interrupt handler(s) from interrupt vector(s) to device with | |
7845 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will | |
7846 | * release the interrupt vector(s) for the message signaled interrupt. | |
7847 | **/ | |
7848 | static void | |
7849 | lpfc_sli_disable_intr(struct lpfc_hba *phba) | |
7850 | { | |
7851 | /* Disable the currently initialized interrupt mode */ | |
7852 | if (phba->intr_type == MSIX) | |
7853 | lpfc_sli_disable_msix(phba); | |
7854 | else if (phba->intr_type == MSI) | |
7855 | lpfc_sli_disable_msi(phba); | |
7856 | else if (phba->intr_type == INTx) | |
7857 | free_irq(phba->pcidev->irq, phba); | |
7858 | ||
7859 | /* Reset interrupt management states */ | |
7860 | phba->intr_type = NONE; | |
7861 | phba->sli.slistat.sli_intr = 0; | |
7862 | ||
7863 | return; | |
7864 | } | |
7865 | ||
7866 | /** | |
7867 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device | |
7868 | * @phba: pointer to lpfc hba data structure. | |
7869 | * | |
7870 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
7871 | * with SLI-4 interface spec. The kernel function pci_enable_msix() is called | |
7872 | * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked, | |
7873 | * enables either all or nothing, depending on the current availability of | |
7874 | * PCI vector resources. The device driver is responsible for calling the | |
7875 | * individual request_irq() to register each MSI-X vector with a interrupt | |
7876 | * handler, which is done in this function. Note that later when device is | |
7877 | * unloading, the driver should always call free_irq() on all MSI-X vectors | |
7878 | * it has done request_irq() on before calling pci_disable_msix(). Failure | |
7879 | * to do so results in a BUG_ON() and a device will be left with MSI-X | |
7880 | * enabled and leaks its vectors. | |
7881 | * | |
7882 | * Return codes | |
af901ca1 | 7883 | * 0 - successful |
da0436e9 JS |
7884 | * other values - error |
7885 | **/ | |
7886 | static int | |
7887 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) | |
7888 | { | |
75baf696 | 7889 | int vectors, rc, index; |
da0436e9 JS |
7890 | |
7891 | /* Set up MSI-X multi-message vectors */ | |
7892 | for (index = 0; index < phba->sli4_hba.cfg_eqn; index++) | |
7893 | phba->sli4_hba.msix_entries[index].entry = index; | |
7894 | ||
7895 | /* Configure MSI-X capability structure */ | |
75baf696 JS |
7896 | vectors = phba->sli4_hba.cfg_eqn; |
7897 | enable_msix_vectors: | |
da0436e9 | 7898 | rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries, |
75baf696 JS |
7899 | vectors); |
7900 | if (rc > 1) { | |
7901 | vectors = rc; | |
7902 | goto enable_msix_vectors; | |
7903 | } else if (rc) { | |
da0436e9 JS |
7904 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
7905 | "0484 PCI enable MSI-X failed (%d)\n", rc); | |
7906 | goto msi_fail_out; | |
7907 | } | |
75baf696 | 7908 | |
da0436e9 | 7909 | /* Log MSI-X vector assignment */ |
75baf696 | 7910 | for (index = 0; index < vectors; index++) |
da0436e9 JS |
7911 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
7912 | "0489 MSI-X entry[%d]: vector=x%x " | |
7913 | "message=%d\n", index, | |
7914 | phba->sli4_hba.msix_entries[index].vector, | |
7915 | phba->sli4_hba.msix_entries[index].entry); | |
7916 | /* | |
7917 | * Assign MSI-X vectors to interrupt handlers | |
7918 | */ | |
0558056c JS |
7919 | if (vectors > 1) |
7920 | rc = request_irq(phba->sli4_hba.msix_entries[0].vector, | |
7921 | &lpfc_sli4_sp_intr_handler, IRQF_SHARED, | |
7922 | LPFC_SP_DRIVER_HANDLER_NAME, phba); | |
7923 | else | |
7924 | /* All Interrupts need to be handled by one EQ */ | |
7925 | rc = request_irq(phba->sli4_hba.msix_entries[0].vector, | |
7926 | &lpfc_sli4_intr_handler, IRQF_SHARED, | |
7927 | LPFC_DRIVER_NAME, phba); | |
da0436e9 JS |
7928 | if (rc) { |
7929 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7930 | "0485 MSI-X slow-path request_irq failed " | |
7931 | "(%d)\n", rc); | |
7932 | goto msi_fail_out; | |
7933 | } | |
7934 | ||
7935 | /* The rest of the vector(s) are associated to fast-path handler(s) */ | |
75baf696 | 7936 | for (index = 1; index < vectors; index++) { |
da0436e9 JS |
7937 | phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1; |
7938 | phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba; | |
7939 | rc = request_irq(phba->sli4_hba.msix_entries[index].vector, | |
7940 | &lpfc_sli4_fp_intr_handler, IRQF_SHARED, | |
7941 | LPFC_FP_DRIVER_HANDLER_NAME, | |
7942 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
7943 | if (rc) { | |
7944 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7945 | "0486 MSI-X fast-path (%d) " | |
7946 | "request_irq failed (%d)\n", index, rc); | |
7947 | goto cfg_fail_out; | |
7948 | } | |
7949 | } | |
75baf696 | 7950 | phba->sli4_hba.msix_vec_nr = vectors; |
da0436e9 JS |
7951 | |
7952 | return rc; | |
7953 | ||
7954 | cfg_fail_out: | |
7955 | /* free the irq already requested */ | |
7956 | for (--index; index >= 1; index--) | |
7957 | free_irq(phba->sli4_hba.msix_entries[index - 1].vector, | |
7958 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
7959 | ||
7960 | /* free the irq already requested */ | |
7961 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); | |
7962 | ||
7963 | msi_fail_out: | |
7964 | /* Unconfigure MSI-X capability structure */ | |
7965 | pci_disable_msix(phba->pcidev); | |
7966 | return rc; | |
7967 | } | |
7968 | ||
7969 | /** | |
7970 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device | |
7971 | * @phba: pointer to lpfc hba data structure. | |
7972 | * | |
7973 | * This routine is invoked to release the MSI-X vectors and then disable the | |
7974 | * MSI-X interrupt mode to device with SLI-4 interface spec. | |
7975 | **/ | |
7976 | static void | |
7977 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) | |
7978 | { | |
7979 | int index; | |
7980 | ||
7981 | /* Free up MSI-X multi-message vectors */ | |
7982 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); | |
7983 | ||
75baf696 | 7984 | for (index = 1; index < phba->sli4_hba.msix_vec_nr; index++) |
da0436e9 JS |
7985 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
7986 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
75baf696 | 7987 | |
da0436e9 JS |
7988 | /* Disable MSI-X */ |
7989 | pci_disable_msix(phba->pcidev); | |
7990 | ||
7991 | return; | |
7992 | } | |
7993 | ||
7994 | /** | |
7995 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device | |
7996 | * @phba: pointer to lpfc hba data structure. | |
7997 | * | |
7998 | * This routine is invoked to enable the MSI interrupt mode to device with | |
7999 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called | |
8000 | * to enable the MSI vector. The device driver is responsible for calling | |
8001 | * the request_irq() to register MSI vector with a interrupt the handler, | |
8002 | * which is done in this function. | |
8003 | * | |
8004 | * Return codes | |
af901ca1 | 8005 | * 0 - successful |
da0436e9 JS |
8006 | * other values - error |
8007 | **/ | |
8008 | static int | |
8009 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) | |
8010 | { | |
8011 | int rc, index; | |
8012 | ||
8013 | rc = pci_enable_msi(phba->pcidev); | |
8014 | if (!rc) | |
8015 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8016 | "0487 PCI enable MSI mode success.\n"); | |
8017 | else { | |
8018 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8019 | "0488 PCI enable MSI mode failed (%d)\n", rc); | |
8020 | return rc; | |
8021 | } | |
8022 | ||
8023 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
8024 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
8025 | if (rc) { | |
8026 | pci_disable_msi(phba->pcidev); | |
8027 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
8028 | "0490 MSI request_irq failed (%d)\n", rc); | |
75baf696 | 8029 | return rc; |
da0436e9 JS |
8030 | } |
8031 | ||
8032 | for (index = 0; index < phba->cfg_fcp_eq_count; index++) { | |
8033 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | |
8034 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
8035 | } | |
8036 | ||
75baf696 | 8037 | return 0; |
da0436e9 JS |
8038 | } |
8039 | ||
8040 | /** | |
8041 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device | |
8042 | * @phba: pointer to lpfc hba data structure. | |
8043 | * | |
8044 | * This routine is invoked to disable the MSI interrupt mode to device with | |
8045 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has | |
8046 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | |
8047 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | |
8048 | * its vector. | |
8049 | **/ | |
8050 | static void | |
8051 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) | |
8052 | { | |
8053 | free_irq(phba->pcidev->irq, phba); | |
8054 | pci_disable_msi(phba->pcidev); | |
8055 | return; | |
8056 | } | |
8057 | ||
8058 | /** | |
8059 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device | |
8060 | * @phba: pointer to lpfc hba data structure. | |
8061 | * | |
8062 | * This routine is invoked to enable device interrupt and associate driver's | |
8063 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 | |
8064 | * interface spec. Depends on the interrupt mode configured to the driver, | |
8065 | * the driver will try to fallback from the configured interrupt mode to an | |
8066 | * interrupt mode which is supported by the platform, kernel, and device in | |
8067 | * the order of: | |
8068 | * MSI-X -> MSI -> IRQ. | |
8069 | * | |
8070 | * Return codes | |
af901ca1 | 8071 | * 0 - successful |
da0436e9 JS |
8072 | * other values - error |
8073 | **/ | |
8074 | static uint32_t | |
8075 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
8076 | { | |
8077 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
8078 | int retval, index; | |
8079 | ||
8080 | if (cfg_mode == 2) { | |
8081 | /* Preparation before conf_msi mbox cmd */ | |
8082 | retval = 0; | |
8083 | if (!retval) { | |
8084 | /* Now, try to enable MSI-X interrupt mode */ | |
8085 | retval = lpfc_sli4_enable_msix(phba); | |
8086 | if (!retval) { | |
8087 | /* Indicate initialization to MSI-X mode */ | |
8088 | phba->intr_type = MSIX; | |
8089 | intr_mode = 2; | |
8090 | } | |
8091 | } | |
8092 | } | |
8093 | ||
8094 | /* Fallback to MSI if MSI-X initialization failed */ | |
8095 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
8096 | retval = lpfc_sli4_enable_msi(phba); | |
8097 | if (!retval) { | |
8098 | /* Indicate initialization to MSI mode */ | |
8099 | phba->intr_type = MSI; | |
8100 | intr_mode = 1; | |
8101 | } | |
8102 | } | |
8103 | ||
8104 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
8105 | if (phba->intr_type == NONE) { | |
8106 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
8107 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
8108 | if (!retval) { | |
8109 | /* Indicate initialization to INTx mode */ | |
8110 | phba->intr_type = INTx; | |
8111 | intr_mode = 0; | |
8112 | for (index = 0; index < phba->cfg_fcp_eq_count; | |
8113 | index++) { | |
8114 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | |
8115 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
8116 | } | |
8117 | } | |
8118 | } | |
8119 | return intr_mode; | |
8120 | } | |
8121 | ||
8122 | /** | |
8123 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device | |
8124 | * @phba: pointer to lpfc hba data structure. | |
8125 | * | |
8126 | * This routine is invoked to disable device interrupt and disassociate | |
8127 | * the driver's interrupt handler(s) from interrupt vector(s) to device | |
8128 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver | |
8129 | * will release the interrupt vector(s) for the message signaled interrupt. | |
8130 | **/ | |
8131 | static void | |
8132 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) | |
8133 | { | |
8134 | /* Disable the currently initialized interrupt mode */ | |
8135 | if (phba->intr_type == MSIX) | |
8136 | lpfc_sli4_disable_msix(phba); | |
8137 | else if (phba->intr_type == MSI) | |
8138 | lpfc_sli4_disable_msi(phba); | |
8139 | else if (phba->intr_type == INTx) | |
8140 | free_irq(phba->pcidev->irq, phba); | |
8141 | ||
8142 | /* Reset interrupt management states */ | |
8143 | phba->intr_type = NONE; | |
8144 | phba->sli.slistat.sli_intr = 0; | |
8145 | ||
8146 | return; | |
8147 | } | |
8148 | ||
8149 | /** | |
8150 | * lpfc_unset_hba - Unset SLI3 hba device initialization | |
8151 | * @phba: pointer to lpfc hba data structure. | |
8152 | * | |
8153 | * This routine is invoked to unset the HBA device initialization steps to | |
8154 | * a device with SLI-3 interface spec. | |
8155 | **/ | |
8156 | static void | |
8157 | lpfc_unset_hba(struct lpfc_hba *phba) | |
8158 | { | |
8159 | struct lpfc_vport *vport = phba->pport; | |
8160 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
8161 | ||
8162 | spin_lock_irq(shost->host_lock); | |
8163 | vport->load_flag |= FC_UNLOADING; | |
8164 | spin_unlock_irq(shost->host_lock); | |
8165 | ||
8166 | lpfc_stop_hba_timers(phba); | |
8167 | ||
8168 | phba->pport->work_port_events = 0; | |
8169 | ||
8170 | lpfc_sli_hba_down(phba); | |
8171 | ||
8172 | lpfc_sli_brdrestart(phba); | |
8173 | ||
8174 | lpfc_sli_disable_intr(phba); | |
8175 | ||
8176 | return; | |
8177 | } | |
8178 | ||
8179 | /** | |
8180 | * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization. | |
8181 | * @phba: pointer to lpfc hba data structure. | |
8182 | * | |
8183 | * This routine is invoked to unset the HBA device initialization steps to | |
8184 | * a device with SLI-4 interface spec. | |
8185 | **/ | |
8186 | static void | |
8187 | lpfc_sli4_unset_hba(struct lpfc_hba *phba) | |
8188 | { | |
8189 | struct lpfc_vport *vport = phba->pport; | |
8190 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
8191 | ||
8192 | spin_lock_irq(shost->host_lock); | |
8193 | vport->load_flag |= FC_UNLOADING; | |
8194 | spin_unlock_irq(shost->host_lock); | |
8195 | ||
8196 | phba->pport->work_port_events = 0; | |
8197 | ||
3677a3a7 JS |
8198 | /* Stop the SLI4 device port */ |
8199 | lpfc_stop_port(phba); | |
da0436e9 JS |
8200 | |
8201 | lpfc_sli4_disable_intr(phba); | |
8202 | ||
3677a3a7 JS |
8203 | /* Reset SLI4 HBA FCoE function */ |
8204 | lpfc_pci_function_reset(phba); | |
5350d872 | 8205 | lpfc_sli4_queue_destroy(phba); |
3677a3a7 | 8206 | |
da0436e9 JS |
8207 | return; |
8208 | } | |
8209 | ||
5af5eee7 JS |
8210 | /** |
8211 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy | |
8212 | * @phba: Pointer to HBA context object. | |
8213 | * | |
8214 | * This function is called in the SLI4 code path to wait for completion | |
8215 | * of device's XRIs exchange busy. It will check the XRI exchange busy | |
8216 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after | |
8217 | * that, it will check the XRI exchange busy on outstanding FCP and ELS | |
8218 | * I/Os every 30 seconds, log error message, and wait forever. Only when | |
8219 | * all XRI exchange busy complete, the driver unload shall proceed with | |
8220 | * invoking the function reset ioctl mailbox command to the CNA and the | |
8221 | * the rest of the driver unload resource release. | |
8222 | **/ | |
8223 | static void | |
8224 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) | |
8225 | { | |
8226 | int wait_time = 0; | |
8227 | int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
8228 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
8229 | ||
8230 | while (!fcp_xri_cmpl || !els_xri_cmpl) { | |
8231 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { | |
8232 | if (!fcp_xri_cmpl) | |
8233 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8234 | "2877 FCP XRI exchange busy " | |
8235 | "wait time: %d seconds.\n", | |
8236 | wait_time/1000); | |
8237 | if (!els_xri_cmpl) | |
8238 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8239 | "2878 ELS XRI exchange busy " | |
8240 | "wait time: %d seconds.\n", | |
8241 | wait_time/1000); | |
8242 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); | |
8243 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; | |
8244 | } else { | |
8245 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); | |
8246 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; | |
8247 | } | |
8248 | fcp_xri_cmpl = | |
8249 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
8250 | els_xri_cmpl = | |
8251 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
8252 | } | |
8253 | } | |
8254 | ||
da0436e9 JS |
8255 | /** |
8256 | * lpfc_sli4_hba_unset - Unset the fcoe hba | |
8257 | * @phba: Pointer to HBA context object. | |
8258 | * | |
8259 | * This function is called in the SLI4 code path to reset the HBA's FCoE | |
8260 | * function. The caller is not required to hold any lock. This routine | |
8261 | * issues PCI function reset mailbox command to reset the FCoE function. | |
8262 | * At the end of the function, it calls lpfc_hba_down_post function to | |
8263 | * free any pending commands. | |
8264 | **/ | |
8265 | static void | |
8266 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) | |
8267 | { | |
8268 | int wait_cnt = 0; | |
8269 | LPFC_MBOXQ_t *mboxq; | |
912e3acd | 8270 | struct pci_dev *pdev = phba->pcidev; |
da0436e9 JS |
8271 | |
8272 | lpfc_stop_hba_timers(phba); | |
8273 | phba->sli4_hba.intr_enable = 0; | |
8274 | ||
8275 | /* | |
8276 | * Gracefully wait out the potential current outstanding asynchronous | |
8277 | * mailbox command. | |
8278 | */ | |
8279 | ||
8280 | /* First, block any pending async mailbox command from posted */ | |
8281 | spin_lock_irq(&phba->hbalock); | |
8282 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
8283 | spin_unlock_irq(&phba->hbalock); | |
8284 | /* Now, trying to wait it out if we can */ | |
8285 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
8286 | msleep(10); | |
8287 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) | |
8288 | break; | |
8289 | } | |
8290 | /* Forcefully release the outstanding mailbox command if timed out */ | |
8291 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
8292 | spin_lock_irq(&phba->hbalock); | |
8293 | mboxq = phba->sli.mbox_active; | |
8294 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
8295 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
8296 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
8297 | phba->sli.mbox_active = NULL; | |
8298 | spin_unlock_irq(&phba->hbalock); | |
8299 | } | |
8300 | ||
5af5eee7 JS |
8301 | /* Abort all iocbs associated with the hba */ |
8302 | lpfc_sli_hba_iocb_abort(phba); | |
8303 | ||
8304 | /* Wait for completion of device XRI exchange busy */ | |
8305 | lpfc_sli4_xri_exchange_busy_wait(phba); | |
8306 | ||
da0436e9 JS |
8307 | /* Disable PCI subsystem interrupt */ |
8308 | lpfc_sli4_disable_intr(phba); | |
8309 | ||
912e3acd JS |
8310 | /* Disable SR-IOV if enabled */ |
8311 | if (phba->cfg_sriov_nr_virtfn) | |
8312 | pci_disable_sriov(pdev); | |
8313 | ||
da0436e9 JS |
8314 | /* Stop kthread signal shall trigger work_done one more time */ |
8315 | kthread_stop(phba->worker_thread); | |
8316 | ||
3677a3a7 JS |
8317 | /* Reset SLI4 HBA FCoE function */ |
8318 | lpfc_pci_function_reset(phba); | |
5350d872 | 8319 | lpfc_sli4_queue_destroy(phba); |
3677a3a7 | 8320 | |
da0436e9 JS |
8321 | /* Stop the SLI4 device port */ |
8322 | phba->pport->work_port_events = 0; | |
8323 | } | |
8324 | ||
28baac74 JS |
8325 | /** |
8326 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. | |
8327 | * @phba: Pointer to HBA context object. | |
8328 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. | |
8329 | * | |
8330 | * This function is called in the SLI4 code path to read the port's | |
8331 | * sli4 capabilities. | |
8332 | * | |
8333 | * This function may be be called from any context that can block-wait | |
8334 | * for the completion. The expectation is that this routine is called | |
8335 | * typically from probe_one or from the online routine. | |
8336 | **/ | |
8337 | int | |
8338 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
8339 | { | |
8340 | int rc; | |
8341 | struct lpfc_mqe *mqe; | |
8342 | struct lpfc_pc_sli4_params *sli4_params; | |
8343 | uint32_t mbox_tmo; | |
8344 | ||
8345 | rc = 0; | |
8346 | mqe = &mboxq->u.mqe; | |
8347 | ||
8348 | /* Read the port's SLI4 Parameters port capabilities */ | |
fedd3b7b | 8349 | lpfc_pc_sli4_params(mboxq); |
28baac74 JS |
8350 | if (!phba->sli4_hba.intr_enable) |
8351 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
8352 | else { | |
a183a15f | 8353 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
28baac74 JS |
8354 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
8355 | } | |
8356 | ||
8357 | if (unlikely(rc)) | |
8358 | return 1; | |
8359 | ||
8360 | sli4_params = &phba->sli4_hba.pc_sli4_params; | |
8361 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); | |
8362 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); | |
8363 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); | |
8364 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, | |
8365 | &mqe->un.sli4_params); | |
8366 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, | |
8367 | &mqe->un.sli4_params); | |
8368 | sli4_params->proto_types = mqe->un.sli4_params.word3; | |
8369 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; | |
8370 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); | |
8371 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); | |
8372 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); | |
8373 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); | |
8374 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); | |
8375 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); | |
8376 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); | |
8377 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); | |
8378 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); | |
8379 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); | |
8380 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); | |
8381 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); | |
8382 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); | |
8383 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); | |
8384 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); | |
8385 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); | |
8386 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); | |
8387 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); | |
8388 | sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params); | |
0558056c JS |
8389 | |
8390 | /* Make sure that sge_supp_len can be handled by the driver */ | |
8391 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) | |
8392 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; | |
8393 | ||
28baac74 JS |
8394 | return rc; |
8395 | } | |
8396 | ||
fedd3b7b JS |
8397 | /** |
8398 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. | |
8399 | * @phba: Pointer to HBA context object. | |
8400 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. | |
8401 | * | |
8402 | * This function is called in the SLI4 code path to read the port's | |
8403 | * sli4 capabilities. | |
8404 | * | |
8405 | * This function may be be called from any context that can block-wait | |
8406 | * for the completion. The expectation is that this routine is called | |
8407 | * typically from probe_one or from the online routine. | |
8408 | **/ | |
8409 | int | |
8410 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
8411 | { | |
8412 | int rc; | |
8413 | struct lpfc_mqe *mqe = &mboxq->u.mqe; | |
8414 | struct lpfc_pc_sli4_params *sli4_params; | |
a183a15f | 8415 | uint32_t mbox_tmo; |
fedd3b7b JS |
8416 | int length; |
8417 | struct lpfc_sli4_parameters *mbx_sli4_parameters; | |
8418 | ||
6d368e53 JS |
8419 | /* |
8420 | * By default, the driver assumes the SLI4 port requires RPI | |
8421 | * header postings. The SLI4_PARAM response will correct this | |
8422 | * assumption. | |
8423 | */ | |
8424 | phba->sli4_hba.rpi_hdrs_in_use = 1; | |
8425 | ||
fedd3b7b JS |
8426 | /* Read the port's SLI4 Config Parameters */ |
8427 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - | |
8428 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
8429 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
8430 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, | |
8431 | length, LPFC_SLI4_MBX_EMBED); | |
8432 | if (!phba->sli4_hba.intr_enable) | |
8433 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
a183a15f JS |
8434 | else { |
8435 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); | |
8436 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
8437 | } | |
fedd3b7b JS |
8438 | if (unlikely(rc)) |
8439 | return rc; | |
8440 | sli4_params = &phba->sli4_hba.pc_sli4_params; | |
8441 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; | |
8442 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); | |
8443 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); | |
8444 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); | |
8445 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, | |
8446 | mbx_sli4_parameters); | |
8447 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, | |
8448 | mbx_sli4_parameters); | |
8449 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) | |
8450 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; | |
8451 | else | |
8452 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; | |
8453 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; | |
8454 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); | |
8455 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); | |
8456 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); | |
8457 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); | |
8458 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); | |
8459 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, | |
8460 | mbx_sli4_parameters); | |
8461 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, | |
8462 | mbx_sli4_parameters); | |
6d368e53 JS |
8463 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
8464 | phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters); | |
0558056c JS |
8465 | |
8466 | /* Make sure that sge_supp_len can be handled by the driver */ | |
8467 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) | |
8468 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; | |
8469 | ||
fedd3b7b JS |
8470 | return 0; |
8471 | } | |
8472 | ||
da0436e9 JS |
8473 | /** |
8474 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. | |
8475 | * @pdev: pointer to PCI device | |
8476 | * @pid: pointer to PCI device identifier | |
8477 | * | |
8478 | * This routine is to be called to attach a device with SLI-3 interface spec | |
8479 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
8480 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific | |
8481 | * information of the device and driver to see if the driver state that it can | |
8482 | * support this kind of device. If the match is successful, the driver core | |
8483 | * invokes this routine. If this routine determines it can claim the HBA, it | |
8484 | * does all the initialization that it needs to do to handle the HBA properly. | |
8485 | * | |
8486 | * Return code | |
8487 | * 0 - driver can claim the device | |
8488 | * negative value - driver can not claim the device | |
8489 | **/ | |
8490 | static int __devinit | |
8491 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) | |
8492 | { | |
8493 | struct lpfc_hba *phba; | |
8494 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 8495 | struct Scsi_Host *shost = NULL; |
da0436e9 JS |
8496 | int error; |
8497 | uint32_t cfg_mode, intr_mode; | |
8498 | ||
8499 | /* Allocate memory for HBA structure */ | |
8500 | phba = lpfc_hba_alloc(pdev); | |
8501 | if (!phba) | |
8502 | return -ENOMEM; | |
8503 | ||
8504 | /* Perform generic PCI device enabling operation */ | |
8505 | error = lpfc_enable_pci_dev(phba); | |
079b5c91 | 8506 | if (error) |
da0436e9 | 8507 | goto out_free_phba; |
da0436e9 JS |
8508 | |
8509 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ | |
8510 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); | |
8511 | if (error) | |
8512 | goto out_disable_pci_dev; | |
8513 | ||
8514 | /* Set up SLI-3 specific device PCI memory space */ | |
8515 | error = lpfc_sli_pci_mem_setup(phba); | |
8516 | if (error) { | |
8517 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8518 | "1402 Failed to set up pci memory space.\n"); | |
8519 | goto out_disable_pci_dev; | |
8520 | } | |
8521 | ||
8522 | /* Set up phase-1 common device driver resources */ | |
8523 | error = lpfc_setup_driver_resource_phase1(phba); | |
8524 | if (error) { | |
8525 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8526 | "1403 Failed to set up driver resource.\n"); | |
8527 | goto out_unset_pci_mem_s3; | |
8528 | } | |
8529 | ||
8530 | /* Set up SLI-3 specific device driver resources */ | |
8531 | error = lpfc_sli_driver_resource_setup(phba); | |
8532 | if (error) { | |
8533 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8534 | "1404 Failed to set up driver resource.\n"); | |
8535 | goto out_unset_pci_mem_s3; | |
8536 | } | |
8537 | ||
8538 | /* Initialize and populate the iocb list per host */ | |
8539 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); | |
8540 | if (error) { | |
8541 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8542 | "1405 Failed to initialize iocb list.\n"); | |
8543 | goto out_unset_driver_resource_s3; | |
8544 | } | |
8545 | ||
8546 | /* Set up common device driver resources */ | |
8547 | error = lpfc_setup_driver_resource_phase2(phba); | |
8548 | if (error) { | |
8549 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8550 | "1406 Failed to set up driver resource.\n"); | |
8551 | goto out_free_iocb_list; | |
8552 | } | |
8553 | ||
079b5c91 JS |
8554 | /* Get the default values for Model Name and Description */ |
8555 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
8556 | ||
da0436e9 JS |
8557 | /* Create SCSI host to the physical port */ |
8558 | error = lpfc_create_shost(phba); | |
8559 | if (error) { | |
8560 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8561 | "1407 Failed to create scsi host.\n"); | |
8562 | goto out_unset_driver_resource; | |
8563 | } | |
8564 | ||
8565 | /* Configure sysfs attributes */ | |
8566 | vport = phba->pport; | |
8567 | error = lpfc_alloc_sysfs_attr(vport); | |
8568 | if (error) { | |
8569 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8570 | "1476 Failed to allocate sysfs attr\n"); | |
8571 | goto out_destroy_shost; | |
8572 | } | |
8573 | ||
6669f9bb | 8574 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
da0436e9 JS |
8575 | /* Now, trying to enable interrupt and bring up the device */ |
8576 | cfg_mode = phba->cfg_use_msi; | |
8577 | while (true) { | |
8578 | /* Put device to a known state before enabling interrupt */ | |
8579 | lpfc_stop_port(phba); | |
8580 | /* Configure and enable interrupt */ | |
8581 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); | |
8582 | if (intr_mode == LPFC_INTR_ERROR) { | |
8583 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8584 | "0431 Failed to enable interrupt.\n"); | |
8585 | error = -ENODEV; | |
8586 | goto out_free_sysfs_attr; | |
8587 | } | |
8588 | /* SLI-3 HBA setup */ | |
8589 | if (lpfc_sli_hba_setup(phba)) { | |
8590 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8591 | "1477 Failed to set up hba\n"); | |
8592 | error = -ENODEV; | |
8593 | goto out_remove_device; | |
8594 | } | |
8595 | ||
8596 | /* Wait 50ms for the interrupts of previous mailbox commands */ | |
8597 | msleep(50); | |
8598 | /* Check active interrupts on message signaled interrupts */ | |
8599 | if (intr_mode == 0 || | |
8600 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { | |
8601 | /* Log the current active interrupt mode */ | |
8602 | phba->intr_mode = intr_mode; | |
8603 | lpfc_log_intr_mode(phba, intr_mode); | |
8604 | break; | |
8605 | } else { | |
8606 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8607 | "0447 Configure interrupt mode (%d) " | |
8608 | "failed active interrupt test.\n", | |
8609 | intr_mode); | |
8610 | /* Disable the current interrupt mode */ | |
8611 | lpfc_sli_disable_intr(phba); | |
8612 | /* Try next level of interrupt mode */ | |
8613 | cfg_mode = --intr_mode; | |
8614 | } | |
8615 | } | |
8616 | ||
8617 | /* Perform post initialization setup */ | |
8618 | lpfc_post_init_setup(phba); | |
8619 | ||
8620 | /* Check if there are static vports to be created. */ | |
8621 | lpfc_create_static_vport(phba); | |
8622 | ||
8623 | return 0; | |
8624 | ||
8625 | out_remove_device: | |
8626 | lpfc_unset_hba(phba); | |
8627 | out_free_sysfs_attr: | |
8628 | lpfc_free_sysfs_attr(vport); | |
8629 | out_destroy_shost: | |
8630 | lpfc_destroy_shost(phba); | |
8631 | out_unset_driver_resource: | |
8632 | lpfc_unset_driver_resource_phase2(phba); | |
8633 | out_free_iocb_list: | |
8634 | lpfc_free_iocb_list(phba); | |
8635 | out_unset_driver_resource_s3: | |
8636 | lpfc_sli_driver_resource_unset(phba); | |
8637 | out_unset_pci_mem_s3: | |
8638 | lpfc_sli_pci_mem_unset(phba); | |
8639 | out_disable_pci_dev: | |
8640 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
8641 | if (shost) |
8642 | scsi_host_put(shost); | |
da0436e9 JS |
8643 | out_free_phba: |
8644 | lpfc_hba_free(phba); | |
8645 | return error; | |
8646 | } | |
8647 | ||
8648 | /** | |
8649 | * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem. | |
8650 | * @pdev: pointer to PCI device | |
8651 | * | |
8652 | * This routine is to be called to disattach a device with SLI-3 interface | |
8653 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
8654 | * removed from PCI bus, it performs all the necessary cleanup for the HBA | |
8655 | * device to be removed from the PCI subsystem properly. | |
8656 | **/ | |
8657 | static void __devexit | |
8658 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) | |
8659 | { | |
8660 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8661 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
8662 | struct lpfc_vport **vports; | |
8663 | struct lpfc_hba *phba = vport->phba; | |
8664 | int i; | |
8665 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
8666 | ||
8667 | spin_lock_irq(&phba->hbalock); | |
8668 | vport->load_flag |= FC_UNLOADING; | |
8669 | spin_unlock_irq(&phba->hbalock); | |
8670 | ||
8671 | lpfc_free_sysfs_attr(vport); | |
8672 | ||
8673 | /* Release all the vports against this physical port */ | |
8674 | vports = lpfc_create_vport_work_array(phba); | |
8675 | if (vports != NULL) | |
8676 | for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) | |
8677 | fc_vport_terminate(vports[i]->fc_vport); | |
8678 | lpfc_destroy_vport_work_array(phba, vports); | |
8679 | ||
8680 | /* Remove FC host and then SCSI host with the physical port */ | |
8681 | fc_remove_host(shost); | |
8682 | scsi_remove_host(shost); | |
8683 | lpfc_cleanup(vport); | |
8684 | ||
8685 | /* | |
8686 | * Bring down the SLI Layer. This step disable all interrupts, | |
8687 | * clears the rings, discards all mailbox commands, and resets | |
8688 | * the HBA. | |
8689 | */ | |
8690 | ||
48e34d0f | 8691 | /* HBA interrupt will be disabled after this call */ |
da0436e9 JS |
8692 | lpfc_sli_hba_down(phba); |
8693 | /* Stop kthread signal shall trigger work_done one more time */ | |
8694 | kthread_stop(phba->worker_thread); | |
8695 | /* Final cleanup of txcmplq and reset the HBA */ | |
8696 | lpfc_sli_brdrestart(phba); | |
8697 | ||
8698 | lpfc_stop_hba_timers(phba); | |
8699 | spin_lock_irq(&phba->hbalock); | |
8700 | list_del_init(&vport->listentry); | |
8701 | spin_unlock_irq(&phba->hbalock); | |
8702 | ||
8703 | lpfc_debugfs_terminate(vport); | |
8704 | ||
912e3acd JS |
8705 | /* Disable SR-IOV if enabled */ |
8706 | if (phba->cfg_sriov_nr_virtfn) | |
8707 | pci_disable_sriov(pdev); | |
8708 | ||
da0436e9 JS |
8709 | /* Disable interrupt */ |
8710 | lpfc_sli_disable_intr(phba); | |
8711 | ||
8712 | pci_set_drvdata(pdev, NULL); | |
8713 | scsi_host_put(shost); | |
8714 | ||
8715 | /* | |
8716 | * Call scsi_free before mem_free since scsi bufs are released to their | |
8717 | * corresponding pools here. | |
8718 | */ | |
8719 | lpfc_scsi_free(phba); | |
8720 | lpfc_mem_free_all(phba); | |
8721 | ||
8722 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
8723 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
8724 | ||
8725 | /* Free resources associated with SLI2 interface */ | |
8726 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
8727 | phba->slim2p.virt, phba->slim2p.phys); | |
8728 | ||
8729 | /* unmap adapter SLIM and Control Registers */ | |
8730 | iounmap(phba->ctrl_regs_memmap_p); | |
8731 | iounmap(phba->slim_memmap_p); | |
8732 | ||
8733 | lpfc_hba_free(phba); | |
8734 | ||
8735 | pci_release_selected_regions(pdev, bars); | |
8736 | pci_disable_device(pdev); | |
8737 | } | |
8738 | ||
8739 | /** | |
8740 | * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt | |
8741 | * @pdev: pointer to PCI device | |
8742 | * @msg: power management message | |
8743 | * | |
8744 | * This routine is to be called from the kernel's PCI subsystem to support | |
8745 | * system Power Management (PM) to device with SLI-3 interface spec. When | |
8746 | * PM invokes this method, it quiesces the device by stopping the driver's | |
8747 | * worker thread for the device, turning off device's interrupt and DMA, | |
8748 | * and bring the device offline. Note that as the driver implements the | |
8749 | * minimum PM requirements to a power-aware driver's PM support for the | |
8750 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
8751 | * to the suspend() method call will be treated as SUSPEND and the driver will | |
8752 | * fully reinitialize its device during resume() method call, the driver will | |
8753 | * set device to PCI_D3hot state in PCI config space instead of setting it | |
8754 | * according to the @msg provided by the PM. | |
8755 | * | |
8756 | * Return code | |
8757 | * 0 - driver suspended the device | |
8758 | * Error otherwise | |
8759 | **/ | |
8760 | static int | |
8761 | lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg) | |
8762 | { | |
8763 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8764 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8765 | ||
8766 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8767 | "0473 PCI device Power Management suspend.\n"); | |
8768 | ||
8769 | /* Bring down the device */ | |
8770 | lpfc_offline_prep(phba); | |
8771 | lpfc_offline(phba); | |
8772 | kthread_stop(phba->worker_thread); | |
8773 | ||
8774 | /* Disable interrupt from device */ | |
8775 | lpfc_sli_disable_intr(phba); | |
8776 | ||
8777 | /* Save device state to PCI config space */ | |
8778 | pci_save_state(pdev); | |
8779 | pci_set_power_state(pdev, PCI_D3hot); | |
8780 | ||
8781 | return 0; | |
8782 | } | |
8783 | ||
8784 | /** | |
8785 | * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt | |
8786 | * @pdev: pointer to PCI device | |
8787 | * | |
8788 | * This routine is to be called from the kernel's PCI subsystem to support | |
8789 | * system Power Management (PM) to device with SLI-3 interface spec. When PM | |
8790 | * invokes this method, it restores the device's PCI config space state and | |
8791 | * fully reinitializes the device and brings it online. Note that as the | |
8792 | * driver implements the minimum PM requirements to a power-aware driver's | |
8793 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, | |
8794 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the | |
8795 | * driver will fully reinitialize its device during resume() method call, | |
8796 | * the device will be set to PCI_D0 directly in PCI config space before | |
8797 | * restoring the state. | |
8798 | * | |
8799 | * Return code | |
8800 | * 0 - driver suspended the device | |
8801 | * Error otherwise | |
8802 | **/ | |
8803 | static int | |
8804 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) | |
8805 | { | |
8806 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8807 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
8808 | uint32_t intr_mode; | |
8809 | int error; | |
8810 | ||
8811 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8812 | "0452 PCI device Power Management resume.\n"); | |
8813 | ||
8814 | /* Restore device state from PCI config space */ | |
8815 | pci_set_power_state(pdev, PCI_D0); | |
8816 | pci_restore_state(pdev); | |
0d878419 | 8817 | |
1dfb5a47 JS |
8818 | /* |
8819 | * As the new kernel behavior of pci_restore_state() API call clears | |
8820 | * device saved_state flag, need to save the restored state again. | |
8821 | */ | |
8822 | pci_save_state(pdev); | |
8823 | ||
da0436e9 JS |
8824 | if (pdev->is_busmaster) |
8825 | pci_set_master(pdev); | |
8826 | ||
8827 | /* Startup the kernel thread for this host adapter. */ | |
8828 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
8829 | "lpfc_worker_%d", phba->brd_no); | |
8830 | if (IS_ERR(phba->worker_thread)) { | |
8831 | error = PTR_ERR(phba->worker_thread); | |
8832 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8833 | "0434 PM resume failed to start worker " | |
8834 | "thread: error=x%x.\n", error); | |
8835 | return error; | |
8836 | } | |
8837 | ||
8838 | /* Configure and enable interrupt */ | |
8839 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
8840 | if (intr_mode == LPFC_INTR_ERROR) { | |
8841 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8842 | "0430 PM resume Failed to enable interrupt\n"); | |
8843 | return -EIO; | |
8844 | } else | |
8845 | phba->intr_mode = intr_mode; | |
8846 | ||
8847 | /* Restart HBA and bring it online */ | |
8848 | lpfc_sli_brdrestart(phba); | |
8849 | lpfc_online(phba); | |
8850 | ||
8851 | /* Log the current active interrupt mode */ | |
8852 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
8853 | ||
8854 | return 0; | |
8855 | } | |
8856 | ||
891478a2 JS |
8857 | /** |
8858 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover | |
8859 | * @phba: pointer to lpfc hba data structure. | |
8860 | * | |
8861 | * This routine is called to prepare the SLI3 device for PCI slot recover. It | |
e2af0d2e | 8862 | * aborts all the outstanding SCSI I/Os to the pci device. |
891478a2 JS |
8863 | **/ |
8864 | static void | |
8865 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) | |
8866 | { | |
e2af0d2e JS |
8867 | struct lpfc_sli *psli = &phba->sli; |
8868 | struct lpfc_sli_ring *pring; | |
8869 | ||
891478a2 JS |
8870 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
8871 | "2723 PCI channel I/O abort preparing for recovery\n"); | |
e2af0d2e JS |
8872 | |
8873 | /* | |
8874 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
8875 | * and let the SCSI mid-layer to retry them to recover. | |
8876 | */ | |
8877 | pring = &psli->ring[psli->fcp_ring]; | |
8878 | lpfc_sli_abort_iocb_ring(phba, pring); | |
891478a2 JS |
8879 | } |
8880 | ||
0d878419 JS |
8881 | /** |
8882 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset | |
8883 | * @phba: pointer to lpfc hba data structure. | |
8884 | * | |
8885 | * This routine is called to prepare the SLI3 device for PCI slot reset. It | |
8886 | * disables the device interrupt and pci device, and aborts the internal FCP | |
8887 | * pending I/Os. | |
8888 | **/ | |
8889 | static void | |
8890 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) | |
8891 | { | |
0d878419 | 8892 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
891478a2 | 8893 | "2710 PCI channel disable preparing for reset\n"); |
e2af0d2e | 8894 | |
75baf696 JS |
8895 | /* Block any management I/Os to the device */ |
8896 | lpfc_block_mgmt_io(phba); | |
8897 | ||
e2af0d2e JS |
8898 | /* Block all SCSI devices' I/Os on the host */ |
8899 | lpfc_scsi_dev_block(phba); | |
8900 | ||
8901 | /* stop all timers */ | |
8902 | lpfc_stop_hba_timers(phba); | |
8903 | ||
0d878419 JS |
8904 | /* Disable interrupt and pci device */ |
8905 | lpfc_sli_disable_intr(phba); | |
8906 | pci_disable_device(phba->pcidev); | |
75baf696 | 8907 | |
e2af0d2e JS |
8908 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
8909 | lpfc_sli_flush_fcp_rings(phba); | |
0d878419 JS |
8910 | } |
8911 | ||
8912 | /** | |
8913 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable | |
8914 | * @phba: pointer to lpfc hba data structure. | |
8915 | * | |
8916 | * This routine is called to prepare the SLI3 device for PCI slot permanently | |
8917 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
8918 | * pending I/Os. | |
8919 | **/ | |
8920 | static void | |
75baf696 | 8921 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
0d878419 JS |
8922 | { |
8923 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
891478a2 | 8924 | "2711 PCI channel permanent disable for failure\n"); |
e2af0d2e JS |
8925 | /* Block all SCSI devices' I/Os on the host */ |
8926 | lpfc_scsi_dev_block(phba); | |
8927 | ||
8928 | /* stop all timers */ | |
8929 | lpfc_stop_hba_timers(phba); | |
8930 | ||
0d878419 JS |
8931 | /* Clean up all driver's outstanding SCSI I/Os */ |
8932 | lpfc_sli_flush_fcp_rings(phba); | |
8933 | } | |
8934 | ||
da0436e9 JS |
8935 | /** |
8936 | * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error | |
8937 | * @pdev: pointer to PCI device. | |
8938 | * @state: the current PCI connection state. | |
8939 | * | |
8940 | * This routine is called from the PCI subsystem for I/O error handling to | |
8941 | * device with SLI-3 interface spec. This function is called by the PCI | |
8942 | * subsystem after a PCI bus error affecting this device has been detected. | |
8943 | * When this function is invoked, it will need to stop all the I/Os and | |
8944 | * interrupt(s) to the device. Once that is done, it will return | |
8945 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery | |
8946 | * as desired. | |
8947 | * | |
8948 | * Return codes | |
0d878419 | 8949 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
da0436e9 JS |
8950 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
8951 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8952 | **/ | |
8953 | static pci_ers_result_t | |
8954 | lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state) | |
8955 | { | |
8956 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8957 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
da0436e9 | 8958 | |
0d878419 JS |
8959 | switch (state) { |
8960 | case pci_channel_io_normal: | |
891478a2 JS |
8961 | /* Non-fatal error, prepare for recovery */ |
8962 | lpfc_sli_prep_dev_for_recover(phba); | |
0d878419 JS |
8963 | return PCI_ERS_RESULT_CAN_RECOVER; |
8964 | case pci_channel_io_frozen: | |
8965 | /* Fatal error, prepare for slot reset */ | |
8966 | lpfc_sli_prep_dev_for_reset(phba); | |
8967 | return PCI_ERS_RESULT_NEED_RESET; | |
8968 | case pci_channel_io_perm_failure: | |
8969 | /* Permanent failure, prepare for device down */ | |
75baf696 | 8970 | lpfc_sli_prep_dev_for_perm_failure(phba); |
da0436e9 | 8971 | return PCI_ERS_RESULT_DISCONNECT; |
0d878419 JS |
8972 | default: |
8973 | /* Unknown state, prepare and request slot reset */ | |
8974 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8975 | "0472 Unknown PCI error state: x%x\n", state); | |
8976 | lpfc_sli_prep_dev_for_reset(phba); | |
8977 | return PCI_ERS_RESULT_NEED_RESET; | |
da0436e9 | 8978 | } |
da0436e9 JS |
8979 | } |
8980 | ||
8981 | /** | |
8982 | * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch. | |
8983 | * @pdev: pointer to PCI device. | |
8984 | * | |
8985 | * This routine is called from the PCI subsystem for error handling to | |
8986 | * device with SLI-3 interface spec. This is called after PCI bus has been | |
8987 | * reset to restart the PCI card from scratch, as if from a cold-boot. | |
8988 | * During the PCI subsystem error recovery, after driver returns | |
8989 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error | |
8990 | * recovery and then call this routine before calling the .resume method | |
8991 | * to recover the device. This function will initialize the HBA device, | |
8992 | * enable the interrupt, but it will just put the HBA to offline state | |
8993 | * without passing any I/O traffic. | |
8994 | * | |
8995 | * Return codes | |
8996 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
8997 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8998 | */ | |
8999 | static pci_ers_result_t | |
9000 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) | |
9001 | { | |
9002 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9003 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9004 | struct lpfc_sli *psli = &phba->sli; | |
9005 | uint32_t intr_mode; | |
9006 | ||
9007 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
9008 | if (pci_enable_device_mem(pdev)) { | |
9009 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
9010 | "PCI device after reset.\n"); | |
9011 | return PCI_ERS_RESULT_DISCONNECT; | |
9012 | } | |
9013 | ||
9014 | pci_restore_state(pdev); | |
1dfb5a47 JS |
9015 | |
9016 | /* | |
9017 | * As the new kernel behavior of pci_restore_state() API call clears | |
9018 | * device saved_state flag, need to save the restored state again. | |
9019 | */ | |
9020 | pci_save_state(pdev); | |
9021 | ||
da0436e9 JS |
9022 | if (pdev->is_busmaster) |
9023 | pci_set_master(pdev); | |
9024 | ||
9025 | spin_lock_irq(&phba->hbalock); | |
9026 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
9027 | spin_unlock_irq(&phba->hbalock); | |
9028 | ||
9029 | /* Configure and enable interrupt */ | |
9030 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
9031 | if (intr_mode == LPFC_INTR_ERROR) { | |
9032 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9033 | "0427 Cannot re-enable interrupt after " | |
9034 | "slot reset.\n"); | |
9035 | return PCI_ERS_RESULT_DISCONNECT; | |
9036 | } else | |
9037 | phba->intr_mode = intr_mode; | |
9038 | ||
75baf696 JS |
9039 | /* Take device offline, it will perform cleanup */ |
9040 | lpfc_offline_prep(phba); | |
da0436e9 JS |
9041 | lpfc_offline(phba); |
9042 | lpfc_sli_brdrestart(phba); | |
9043 | ||
9044 | /* Log the current active interrupt mode */ | |
9045 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
9046 | ||
9047 | return PCI_ERS_RESULT_RECOVERED; | |
9048 | } | |
9049 | ||
9050 | /** | |
9051 | * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device. | |
9052 | * @pdev: pointer to PCI device | |
9053 | * | |
9054 | * This routine is called from the PCI subsystem for error handling to device | |
9055 | * with SLI-3 interface spec. It is called when kernel error recovery tells | |
9056 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus | |
9057 | * error recovery. After this call, traffic can start to flow from this device | |
9058 | * again. | |
9059 | */ | |
9060 | static void | |
9061 | lpfc_io_resume_s3(struct pci_dev *pdev) | |
9062 | { | |
9063 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9064 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
3772a991 | 9065 | |
e2af0d2e | 9066 | /* Bring device online, it will be no-op for non-fatal error resume */ |
da0436e9 | 9067 | lpfc_online(phba); |
0d878419 JS |
9068 | |
9069 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
9070 | if (phba->hba_flag & HBA_AER_ENABLED) | |
9071 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
da0436e9 | 9072 | } |
3772a991 | 9073 | |
da0436e9 JS |
9074 | /** |
9075 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve | |
9076 | * @phba: pointer to lpfc hba data structure. | |
9077 | * | |
9078 | * returns the number of ELS/CT IOCBs to reserve | |
9079 | **/ | |
9080 | int | |
9081 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) | |
9082 | { | |
9083 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; | |
9084 | ||
f1126688 JS |
9085 | if (phba->sli_rev == LPFC_SLI_REV4) { |
9086 | if (max_xri <= 100) | |
6a9c52cf | 9087 | return 10; |
f1126688 | 9088 | else if (max_xri <= 256) |
6a9c52cf | 9089 | return 25; |
f1126688 | 9090 | else if (max_xri <= 512) |
6a9c52cf | 9091 | return 50; |
f1126688 | 9092 | else if (max_xri <= 1024) |
6a9c52cf | 9093 | return 100; |
f1126688 | 9094 | else |
6a9c52cf | 9095 | return 150; |
f1126688 JS |
9096 | } else |
9097 | return 0; | |
3772a991 JS |
9098 | } |
9099 | ||
52d52440 JS |
9100 | /** |
9101 | * lpfc_write_firmware - attempt to write a firmware image to the port | |
9102 | * @phba: pointer to lpfc hba data structure. | |
9103 | * @fw: pointer to firmware image returned from request_firmware. | |
9104 | * | |
9105 | * returns the number of bytes written if write is successful. | |
9106 | * returns a negative error value if there were errors. | |
9107 | * returns 0 if firmware matches currently active firmware on port. | |
9108 | **/ | |
9109 | int | |
9110 | lpfc_write_firmware(struct lpfc_hba *phba, const struct firmware *fw) | |
9111 | { | |
6b5151fd | 9112 | char fwrev[FW_REV_STR_SIZE]; |
52d52440 JS |
9113 | struct lpfc_grp_hdr *image = (struct lpfc_grp_hdr *)fw->data; |
9114 | struct list_head dma_buffer_list; | |
9115 | int i, rc = 0; | |
9116 | struct lpfc_dmabuf *dmabuf, *next; | |
9117 | uint32_t offset = 0, temp_offset = 0; | |
9118 | ||
9119 | INIT_LIST_HEAD(&dma_buffer_list); | |
079b5c91 JS |
9120 | if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) || |
9121 | (bf_get_be32(lpfc_grp_hdr_file_type, image) != | |
9122 | LPFC_FILE_TYPE_GROUP) || | |
9123 | (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) || | |
9124 | (be32_to_cpu(image->size) != fw->size)) { | |
52d52440 JS |
9125 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
9126 | "3022 Invalid FW image found. " | |
079b5c91 JS |
9127 | "Magic:%x Type:%x ID:%x\n", |
9128 | be32_to_cpu(image->magic_number), | |
9129 | bf_get_be32(lpfc_grp_hdr_file_type, image), | |
9130 | bf_get_be32(lpfc_grp_hdr_id, image)); | |
52d52440 JS |
9131 | return -EINVAL; |
9132 | } | |
9133 | lpfc_decode_firmware_rev(phba, fwrev, 1); | |
88a2cfbb | 9134 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
52d52440 JS |
9135 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
9136 | "3023 Updating Firmware. Current Version:%s " | |
9137 | "New Version:%s\n", | |
88a2cfbb | 9138 | fwrev, image->revision); |
52d52440 JS |
9139 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
9140 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), | |
9141 | GFP_KERNEL); | |
9142 | if (!dmabuf) { | |
9143 | rc = -ENOMEM; | |
9144 | goto out; | |
9145 | } | |
9146 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
9147 | SLI4_PAGE_SIZE, | |
9148 | &dmabuf->phys, | |
9149 | GFP_KERNEL); | |
9150 | if (!dmabuf->virt) { | |
9151 | kfree(dmabuf); | |
9152 | rc = -ENOMEM; | |
9153 | goto out; | |
9154 | } | |
9155 | list_add_tail(&dmabuf->list, &dma_buffer_list); | |
9156 | } | |
9157 | while (offset < fw->size) { | |
9158 | temp_offset = offset; | |
9159 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { | |
079b5c91 | 9160 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
52d52440 JS |
9161 | memcpy(dmabuf->virt, |
9162 | fw->data + temp_offset, | |
079b5c91 JS |
9163 | fw->size - temp_offset); |
9164 | temp_offset = fw->size; | |
52d52440 JS |
9165 | break; |
9166 | } | |
52d52440 JS |
9167 | memcpy(dmabuf->virt, fw->data + temp_offset, |
9168 | SLI4_PAGE_SIZE); | |
88a2cfbb | 9169 | temp_offset += SLI4_PAGE_SIZE; |
52d52440 JS |
9170 | } |
9171 | rc = lpfc_wr_object(phba, &dma_buffer_list, | |
9172 | (fw->size - offset), &offset); | |
9173 | if (rc) { | |
9174 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9175 | "3024 Firmware update failed. " | |
9176 | "%d\n", rc); | |
9177 | goto out; | |
9178 | } | |
9179 | } | |
9180 | rc = offset; | |
9181 | } | |
9182 | out: | |
9183 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { | |
9184 | list_del(&dmabuf->list); | |
9185 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, | |
9186 | dmabuf->virt, dmabuf->phys); | |
9187 | kfree(dmabuf); | |
9188 | } | |
9189 | return rc; | |
9190 | } | |
9191 | ||
3772a991 | 9192 | /** |
da0436e9 | 9193 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
3772a991 JS |
9194 | * @pdev: pointer to PCI device |
9195 | * @pid: pointer to PCI device identifier | |
9196 | * | |
da0436e9 JS |
9197 | * This routine is called from the kernel's PCI subsystem to device with |
9198 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 | 9199 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
da0436e9 JS |
9200 | * information of the device and driver to see if the driver state that it |
9201 | * can support this kind of device. If the match is successful, the driver | |
9202 | * core invokes this routine. If this routine determines it can claim the HBA, | |
9203 | * it does all the initialization that it needs to do to handle the HBA | |
9204 | * properly. | |
3772a991 JS |
9205 | * |
9206 | * Return code | |
9207 | * 0 - driver can claim the device | |
9208 | * negative value - driver can not claim the device | |
9209 | **/ | |
9210 | static int __devinit | |
da0436e9 | 9211 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
3772a991 JS |
9212 | { |
9213 | struct lpfc_hba *phba; | |
9214 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 9215 | struct Scsi_Host *shost = NULL; |
3772a991 JS |
9216 | int error; |
9217 | uint32_t cfg_mode, intr_mode; | |
da0436e9 | 9218 | int mcnt; |
0558056c | 9219 | int adjusted_fcp_eq_count; |
52d52440 JS |
9220 | const struct firmware *fw; |
9221 | uint8_t file_name[16]; | |
3772a991 JS |
9222 | |
9223 | /* Allocate memory for HBA structure */ | |
9224 | phba = lpfc_hba_alloc(pdev); | |
9225 | if (!phba) | |
9226 | return -ENOMEM; | |
9227 | ||
9228 | /* Perform generic PCI device enabling operation */ | |
9229 | error = lpfc_enable_pci_dev(phba); | |
079b5c91 | 9230 | if (error) |
3772a991 | 9231 | goto out_free_phba; |
3772a991 | 9232 | |
da0436e9 JS |
9233 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
9234 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); | |
3772a991 JS |
9235 | if (error) |
9236 | goto out_disable_pci_dev; | |
9237 | ||
da0436e9 JS |
9238 | /* Set up SLI-4 specific device PCI memory space */ |
9239 | error = lpfc_sli4_pci_mem_setup(phba); | |
3772a991 JS |
9240 | if (error) { |
9241 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9242 | "1410 Failed to set up pci memory space.\n"); |
3772a991 JS |
9243 | goto out_disable_pci_dev; |
9244 | } | |
9245 | ||
9246 | /* Set up phase-1 common device driver resources */ | |
9247 | error = lpfc_setup_driver_resource_phase1(phba); | |
9248 | if (error) { | |
9249 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
9250 | "1411 Failed to set up driver resource.\n"); |
9251 | goto out_unset_pci_mem_s4; | |
3772a991 JS |
9252 | } |
9253 | ||
da0436e9 JS |
9254 | /* Set up SLI-4 Specific device driver resources */ |
9255 | error = lpfc_sli4_driver_resource_setup(phba); | |
3772a991 JS |
9256 | if (error) { |
9257 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
9258 | "1412 Failed to set up driver resource.\n"); |
9259 | goto out_unset_pci_mem_s4; | |
3772a991 JS |
9260 | } |
9261 | ||
9262 | /* Initialize and populate the iocb list per host */ | |
2a9bf3d0 JS |
9263 | |
9264 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
9265 | "2821 initialize iocb list %d.\n", | |
9266 | phba->cfg_iocb_cnt*1024); | |
9267 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); | |
9268 | ||
3772a991 JS |
9269 | if (error) { |
9270 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
9271 | "1413 Failed to initialize iocb list.\n"); |
9272 | goto out_unset_driver_resource_s4; | |
3772a991 JS |
9273 | } |
9274 | ||
19ca7609 | 9275 | INIT_LIST_HEAD(&phba->active_rrq_list); |
7d791df7 | 9276 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
19ca7609 | 9277 | |
3772a991 JS |
9278 | /* Set up common device driver resources */ |
9279 | error = lpfc_setup_driver_resource_phase2(phba); | |
9280 | if (error) { | |
9281 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9282 | "1414 Failed to set up driver resource.\n"); |
3772a991 JS |
9283 | goto out_free_iocb_list; |
9284 | } | |
9285 | ||
079b5c91 JS |
9286 | /* Get the default values for Model Name and Description */ |
9287 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
9288 | ||
3772a991 JS |
9289 | /* Create SCSI host to the physical port */ |
9290 | error = lpfc_create_shost(phba); | |
9291 | if (error) { | |
9292 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9293 | "1415 Failed to create scsi host.\n"); |
3772a991 JS |
9294 | goto out_unset_driver_resource; |
9295 | } | |
9399627f | 9296 | |
5b75da2f | 9297 | /* Configure sysfs attributes */ |
3772a991 JS |
9298 | vport = phba->pport; |
9299 | error = lpfc_alloc_sysfs_attr(vport); | |
9300 | if (error) { | |
9399627f | 9301 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 9302 | "1416 Failed to allocate sysfs attr\n"); |
3772a991 | 9303 | goto out_destroy_shost; |
98c9ea5c | 9304 | } |
875fbdfe | 9305 | |
6669f9bb | 9306 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
3772a991 | 9307 | /* Now, trying to enable interrupt and bring up the device */ |
5b75da2f JS |
9308 | cfg_mode = phba->cfg_use_msi; |
9309 | while (true) { | |
3772a991 JS |
9310 | /* Put device to a known state before enabling interrupt */ |
9311 | lpfc_stop_port(phba); | |
5b75da2f | 9312 | /* Configure and enable interrupt */ |
da0436e9 | 9313 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
5b75da2f JS |
9314 | if (intr_mode == LPFC_INTR_ERROR) { |
9315 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9316 | "0426 Failed to enable interrupt.\n"); |
3772a991 | 9317 | error = -ENODEV; |
5b75da2f JS |
9318 | goto out_free_sysfs_attr; |
9319 | } | |
0558056c | 9320 | /* Default to single EQ for non-MSI-X */ |
def9c7a9 | 9321 | if (phba->intr_type != MSIX) |
0558056c JS |
9322 | adjusted_fcp_eq_count = 0; |
9323 | else if (phba->sli4_hba.msix_vec_nr < | |
9324 | phba->cfg_fcp_eq_count + 1) | |
9325 | adjusted_fcp_eq_count = phba->sli4_hba.msix_vec_nr - 1; | |
9326 | else | |
9327 | adjusted_fcp_eq_count = phba->cfg_fcp_eq_count; | |
0558056c | 9328 | phba->cfg_fcp_eq_count = adjusted_fcp_eq_count; |
da0436e9 JS |
9329 | /* Set up SLI-4 HBA */ |
9330 | if (lpfc_sli4_hba_setup(phba)) { | |
5b75da2f | 9331 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 9332 | "1421 Failed to set up hba\n"); |
5b75da2f | 9333 | error = -ENODEV; |
da0436e9 | 9334 | goto out_disable_intr; |
5b75da2f JS |
9335 | } |
9336 | ||
da0436e9 JS |
9337 | /* Send NOP mbx cmds for non-INTx mode active interrupt test */ |
9338 | if (intr_mode != 0) | |
9339 | mcnt = lpfc_sli4_send_nop_mbox_cmds(phba, | |
9340 | LPFC_ACT_INTR_CNT); | |
9341 | ||
9342 | /* Check active interrupts received only for MSI/MSI-X */ | |
3772a991 | 9343 | if (intr_mode == 0 || |
da0436e9 | 9344 | phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) { |
5b75da2f JS |
9345 | /* Log the current active interrupt mode */ |
9346 | phba->intr_mode = intr_mode; | |
9347 | lpfc_log_intr_mode(phba, intr_mode); | |
9348 | break; | |
5b75da2f | 9349 | } |
da0436e9 JS |
9350 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
9351 | "0451 Configure interrupt mode (%d) " | |
9352 | "failed active interrupt test.\n", | |
9353 | intr_mode); | |
2fcee4bf JS |
9354 | /* Unset the previous SLI-4 HBA setup. */ |
9355 | /* | |
9356 | * TODO: Is this operation compatible with IF TYPE 2 | |
9357 | * devices? All port state is deleted and cleared. | |
9358 | */ | |
da0436e9 JS |
9359 | lpfc_sli4_unset_hba(phba); |
9360 | /* Try next level of interrupt mode */ | |
9361 | cfg_mode = --intr_mode; | |
98c9ea5c | 9362 | } |
858c9f6c | 9363 | |
3772a991 JS |
9364 | /* Perform post initialization setup */ |
9365 | lpfc_post_init_setup(phba); | |
dea3101e | 9366 | |
026abb87 JS |
9367 | /* check for firmware upgrade or downgrade (if_type 2 only) */ |
9368 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
9369 | LPFC_SLI_INTF_IF_TYPE_2) { | |
9370 | snprintf(file_name, 16, "%s.grp", phba->ModelName); | |
9371 | error = request_firmware(&fw, file_name, &phba->pcidev->dev); | |
9372 | if (!error) { | |
9373 | lpfc_write_firmware(phba, fw); | |
9374 | release_firmware(fw); | |
9375 | } | |
52d52440 JS |
9376 | } |
9377 | ||
1c6834a7 JS |
9378 | /* Check if there are static vports to be created. */ |
9379 | lpfc_create_static_vport(phba); | |
dea3101e JB |
9380 | return 0; |
9381 | ||
da0436e9 JS |
9382 | out_disable_intr: |
9383 | lpfc_sli4_disable_intr(phba); | |
5b75da2f JS |
9384 | out_free_sysfs_attr: |
9385 | lpfc_free_sysfs_attr(vport); | |
3772a991 JS |
9386 | out_destroy_shost: |
9387 | lpfc_destroy_shost(phba); | |
9388 | out_unset_driver_resource: | |
9389 | lpfc_unset_driver_resource_phase2(phba); | |
9390 | out_free_iocb_list: | |
9391 | lpfc_free_iocb_list(phba); | |
da0436e9 JS |
9392 | out_unset_driver_resource_s4: |
9393 | lpfc_sli4_driver_resource_unset(phba); | |
9394 | out_unset_pci_mem_s4: | |
9395 | lpfc_sli4_pci_mem_unset(phba); | |
3772a991 JS |
9396 | out_disable_pci_dev: |
9397 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
9398 | if (shost) |
9399 | scsi_host_put(shost); | |
2e0fef85 | 9400 | out_free_phba: |
3772a991 | 9401 | lpfc_hba_free(phba); |
dea3101e JB |
9402 | return error; |
9403 | } | |
9404 | ||
e59058c4 | 9405 | /** |
da0436e9 | 9406 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
e59058c4 JS |
9407 | * @pdev: pointer to PCI device |
9408 | * | |
da0436e9 JS |
9409 | * This routine is called from the kernel's PCI subsystem to device with |
9410 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 JS |
9411 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
9412 | * device to be removed from the PCI subsystem properly. | |
e59058c4 | 9413 | **/ |
dea3101e | 9414 | static void __devexit |
da0436e9 | 9415 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
dea3101e | 9416 | { |
da0436e9 | 9417 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2e0fef85 | 9418 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
eada272d | 9419 | struct lpfc_vport **vports; |
da0436e9 | 9420 | struct lpfc_hba *phba = vport->phba; |
eada272d | 9421 | int i; |
8a4df120 | 9422 | |
da0436e9 | 9423 | /* Mark the device unloading flag */ |
549e55cd | 9424 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 9425 | vport->load_flag |= FC_UNLOADING; |
549e55cd | 9426 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 9427 | |
da0436e9 | 9428 | /* Free the HBA sysfs attributes */ |
858c9f6c JS |
9429 | lpfc_free_sysfs_attr(vport); |
9430 | ||
eada272d JS |
9431 | /* Release all the vports against this physical port */ |
9432 | vports = lpfc_create_vport_work_array(phba); | |
9433 | if (vports != NULL) | |
3772a991 | 9434 | for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++) |
eada272d JS |
9435 | fc_vport_terminate(vports[i]->fc_vport); |
9436 | lpfc_destroy_vport_work_array(phba, vports); | |
9437 | ||
9438 | /* Remove FC host and then SCSI host with the physical port */ | |
858c9f6c JS |
9439 | fc_remove_host(shost); |
9440 | scsi_remove_host(shost); | |
da0436e9 JS |
9441 | |
9442 | /* Perform cleanup on the physical port */ | |
87af33fe JS |
9443 | lpfc_cleanup(vport); |
9444 | ||
2e0fef85 | 9445 | /* |
da0436e9 | 9446 | * Bring down the SLI Layer. This step disables all interrupts, |
2e0fef85 | 9447 | * clears the rings, discards all mailbox commands, and resets |
da0436e9 | 9448 | * the HBA FCoE function. |
2e0fef85 | 9449 | */ |
da0436e9 JS |
9450 | lpfc_debugfs_terminate(vport); |
9451 | lpfc_sli4_hba_unset(phba); | |
a257bf90 | 9452 | |
858c9f6c JS |
9453 | spin_lock_irq(&phba->hbalock); |
9454 | list_del_init(&vport->listentry); | |
9455 | spin_unlock_irq(&phba->hbalock); | |
9456 | ||
3677a3a7 | 9457 | /* Perform scsi free before driver resource_unset since scsi |
da0436e9 | 9458 | * buffers are released to their corresponding pools here. |
2e0fef85 JS |
9459 | */ |
9460 | lpfc_scsi_free(phba); | |
da0436e9 | 9461 | lpfc_sli4_driver_resource_unset(phba); |
ed957684 | 9462 | |
da0436e9 JS |
9463 | /* Unmap adapter Control and Doorbell registers */ |
9464 | lpfc_sli4_pci_mem_unset(phba); | |
2e0fef85 | 9465 | |
da0436e9 JS |
9466 | /* Release PCI resources and disable device's PCI function */ |
9467 | scsi_host_put(shost); | |
9468 | lpfc_disable_pci_dev(phba); | |
2e0fef85 | 9469 | |
da0436e9 | 9470 | /* Finally, free the driver's device data structure */ |
3772a991 | 9471 | lpfc_hba_free(phba); |
2e0fef85 | 9472 | |
da0436e9 | 9473 | return; |
dea3101e JB |
9474 | } |
9475 | ||
3a55b532 | 9476 | /** |
da0436e9 | 9477 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
3a55b532 JS |
9478 | * @pdev: pointer to PCI device |
9479 | * @msg: power management message | |
9480 | * | |
da0436e9 JS |
9481 | * This routine is called from the kernel's PCI subsystem to support system |
9482 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes | |
9483 | * this method, it quiesces the device by stopping the driver's worker | |
9484 | * thread for the device, turning off device's interrupt and DMA, and bring | |
9485 | * the device offline. Note that as the driver implements the minimum PM | |
9486 | * requirements to a power-aware driver's PM support for suspend/resume -- all | |
9487 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() | |
9488 | * method call will be treated as SUSPEND and the driver will fully | |
9489 | * reinitialize its device during resume() method call, the driver will set | |
9490 | * device to PCI_D3hot state in PCI config space instead of setting it | |
3772a991 | 9491 | * according to the @msg provided by the PM. |
3a55b532 JS |
9492 | * |
9493 | * Return code | |
3772a991 JS |
9494 | * 0 - driver suspended the device |
9495 | * Error otherwise | |
3a55b532 JS |
9496 | **/ |
9497 | static int | |
da0436e9 | 9498 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
3a55b532 JS |
9499 | { |
9500 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9501 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9502 | ||
9503 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
75baf696 | 9504 | "2843 PCI device Power Management suspend.\n"); |
3a55b532 JS |
9505 | |
9506 | /* Bring down the device */ | |
9507 | lpfc_offline_prep(phba); | |
9508 | lpfc_offline(phba); | |
9509 | kthread_stop(phba->worker_thread); | |
9510 | ||
9511 | /* Disable interrupt from device */ | |
da0436e9 | 9512 | lpfc_sli4_disable_intr(phba); |
5350d872 | 9513 | lpfc_sli4_queue_destroy(phba); |
3a55b532 JS |
9514 | |
9515 | /* Save device state to PCI config space */ | |
9516 | pci_save_state(pdev); | |
9517 | pci_set_power_state(pdev, PCI_D3hot); | |
9518 | ||
9519 | return 0; | |
9520 | } | |
9521 | ||
9522 | /** | |
da0436e9 | 9523 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
3a55b532 JS |
9524 | * @pdev: pointer to PCI device |
9525 | * | |
da0436e9 JS |
9526 | * This routine is called from the kernel's PCI subsystem to support system |
9527 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes | |
9528 | * this method, it restores the device's PCI config space state and fully | |
9529 | * reinitializes the device and brings it online. Note that as the driver | |
9530 | * implements the minimum PM requirements to a power-aware driver's PM for | |
9531 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
9532 | * to the suspend() method call will be treated as SUSPEND and the driver | |
9533 | * will fully reinitialize its device during resume() method call, the device | |
9534 | * will be set to PCI_D0 directly in PCI config space before restoring the | |
9535 | * state. | |
3a55b532 JS |
9536 | * |
9537 | * Return code | |
3772a991 JS |
9538 | * 0 - driver suspended the device |
9539 | * Error otherwise | |
3a55b532 JS |
9540 | **/ |
9541 | static int | |
da0436e9 | 9542 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
3a55b532 JS |
9543 | { |
9544 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9545 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
5b75da2f | 9546 | uint32_t intr_mode; |
3a55b532 JS |
9547 | int error; |
9548 | ||
9549 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
da0436e9 | 9550 | "0292 PCI device Power Management resume.\n"); |
3a55b532 JS |
9551 | |
9552 | /* Restore device state from PCI config space */ | |
9553 | pci_set_power_state(pdev, PCI_D0); | |
9554 | pci_restore_state(pdev); | |
1dfb5a47 JS |
9555 | |
9556 | /* | |
9557 | * As the new kernel behavior of pci_restore_state() API call clears | |
9558 | * device saved_state flag, need to save the restored state again. | |
9559 | */ | |
9560 | pci_save_state(pdev); | |
9561 | ||
3a55b532 JS |
9562 | if (pdev->is_busmaster) |
9563 | pci_set_master(pdev); | |
9564 | ||
da0436e9 | 9565 | /* Startup the kernel thread for this host adapter. */ |
3a55b532 JS |
9566 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
9567 | "lpfc_worker_%d", phba->brd_no); | |
9568 | if (IS_ERR(phba->worker_thread)) { | |
9569 | error = PTR_ERR(phba->worker_thread); | |
9570 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9571 | "0293 PM resume failed to start worker " |
3a55b532 JS |
9572 | "thread: error=x%x.\n", error); |
9573 | return error; | |
9574 | } | |
9575 | ||
5b75da2f | 9576 | /* Configure and enable interrupt */ |
da0436e9 | 9577 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
5b75da2f | 9578 | if (intr_mode == LPFC_INTR_ERROR) { |
3a55b532 | 9579 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 9580 | "0294 PM resume Failed to enable interrupt\n"); |
5b75da2f JS |
9581 | return -EIO; |
9582 | } else | |
9583 | phba->intr_mode = intr_mode; | |
3a55b532 JS |
9584 | |
9585 | /* Restart HBA and bring it online */ | |
9586 | lpfc_sli_brdrestart(phba); | |
9587 | lpfc_online(phba); | |
9588 | ||
5b75da2f JS |
9589 | /* Log the current active interrupt mode */ |
9590 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
9591 | ||
3a55b532 JS |
9592 | return 0; |
9593 | } | |
9594 | ||
75baf696 JS |
9595 | /** |
9596 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover | |
9597 | * @phba: pointer to lpfc hba data structure. | |
9598 | * | |
9599 | * This routine is called to prepare the SLI4 device for PCI slot recover. It | |
9600 | * aborts all the outstanding SCSI I/Os to the pci device. | |
9601 | **/ | |
9602 | static void | |
9603 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) | |
9604 | { | |
9605 | struct lpfc_sli *psli = &phba->sli; | |
9606 | struct lpfc_sli_ring *pring; | |
9607 | ||
9608 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9609 | "2828 PCI channel I/O abort preparing for recovery\n"); | |
9610 | /* | |
9611 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
9612 | * and let the SCSI mid-layer to retry them to recover. | |
9613 | */ | |
9614 | pring = &psli->ring[psli->fcp_ring]; | |
9615 | lpfc_sli_abort_iocb_ring(phba, pring); | |
9616 | } | |
9617 | ||
9618 | /** | |
9619 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset | |
9620 | * @phba: pointer to lpfc hba data structure. | |
9621 | * | |
9622 | * This routine is called to prepare the SLI4 device for PCI slot reset. It | |
9623 | * disables the device interrupt and pci device, and aborts the internal FCP | |
9624 | * pending I/Os. | |
9625 | **/ | |
9626 | static void | |
9627 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) | |
9628 | { | |
9629 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9630 | "2826 PCI channel disable preparing for reset\n"); | |
9631 | ||
9632 | /* Block any management I/Os to the device */ | |
9633 | lpfc_block_mgmt_io(phba); | |
9634 | ||
9635 | /* Block all SCSI devices' I/Os on the host */ | |
9636 | lpfc_scsi_dev_block(phba); | |
9637 | ||
9638 | /* stop all timers */ | |
9639 | lpfc_stop_hba_timers(phba); | |
9640 | ||
9641 | /* Disable interrupt and pci device */ | |
9642 | lpfc_sli4_disable_intr(phba); | |
5350d872 | 9643 | lpfc_sli4_queue_destroy(phba); |
75baf696 JS |
9644 | pci_disable_device(phba->pcidev); |
9645 | ||
9646 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ | |
9647 | lpfc_sli_flush_fcp_rings(phba); | |
9648 | } | |
9649 | ||
9650 | /** | |
9651 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable | |
9652 | * @phba: pointer to lpfc hba data structure. | |
9653 | * | |
9654 | * This routine is called to prepare the SLI4 device for PCI slot permanently | |
9655 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
9656 | * pending I/Os. | |
9657 | **/ | |
9658 | static void | |
9659 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) | |
9660 | { | |
9661 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9662 | "2827 PCI channel permanent disable for failure\n"); | |
9663 | ||
9664 | /* Block all SCSI devices' I/Os on the host */ | |
9665 | lpfc_scsi_dev_block(phba); | |
9666 | ||
9667 | /* stop all timers */ | |
9668 | lpfc_stop_hba_timers(phba); | |
9669 | ||
9670 | /* Clean up all driver's outstanding SCSI I/Os */ | |
9671 | lpfc_sli_flush_fcp_rings(phba); | |
9672 | } | |
9673 | ||
8d63f375 | 9674 | /** |
da0436e9 | 9675 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
e59058c4 JS |
9676 | * @pdev: pointer to PCI device. |
9677 | * @state: the current PCI connection state. | |
8d63f375 | 9678 | * |
da0436e9 JS |
9679 | * This routine is called from the PCI subsystem for error handling to device |
9680 | * with SLI-4 interface spec. This function is called by the PCI subsystem | |
9681 | * after a PCI bus error affecting this device has been detected. When this | |
9682 | * function is invoked, it will need to stop all the I/Os and interrupt(s) | |
9683 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET | |
9684 | * for the PCI subsystem to perform proper recovery as desired. | |
e59058c4 JS |
9685 | * |
9686 | * Return codes | |
3772a991 JS |
9687 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
9688 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
e59058c4 | 9689 | **/ |
3772a991 | 9690 | static pci_ers_result_t |
da0436e9 | 9691 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
8d63f375 | 9692 | { |
75baf696 JS |
9693 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
9694 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9695 | ||
9696 | switch (state) { | |
9697 | case pci_channel_io_normal: | |
9698 | /* Non-fatal error, prepare for recovery */ | |
9699 | lpfc_sli4_prep_dev_for_recover(phba); | |
9700 | return PCI_ERS_RESULT_CAN_RECOVER; | |
9701 | case pci_channel_io_frozen: | |
9702 | /* Fatal error, prepare for slot reset */ | |
9703 | lpfc_sli4_prep_dev_for_reset(phba); | |
9704 | return PCI_ERS_RESULT_NEED_RESET; | |
9705 | case pci_channel_io_perm_failure: | |
9706 | /* Permanent failure, prepare for device down */ | |
9707 | lpfc_sli4_prep_dev_for_perm_failure(phba); | |
9708 | return PCI_ERS_RESULT_DISCONNECT; | |
9709 | default: | |
9710 | /* Unknown state, prepare and request slot reset */ | |
9711 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9712 | "2825 Unknown PCI error state: x%x\n", state); | |
9713 | lpfc_sli4_prep_dev_for_reset(phba); | |
9714 | return PCI_ERS_RESULT_NEED_RESET; | |
9715 | } | |
8d63f375 LV |
9716 | } |
9717 | ||
9718 | /** | |
da0436e9 | 9719 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
e59058c4 JS |
9720 | * @pdev: pointer to PCI device. |
9721 | * | |
da0436e9 JS |
9722 | * This routine is called from the PCI subsystem for error handling to device |
9723 | * with SLI-4 interface spec. It is called after PCI bus has been reset to | |
9724 | * restart the PCI card from scratch, as if from a cold-boot. During the | |
9725 | * PCI subsystem error recovery, after the driver returns | |
3772a991 | 9726 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
da0436e9 JS |
9727 | * recovery and then call this routine before calling the .resume method to |
9728 | * recover the device. This function will initialize the HBA device, enable | |
9729 | * the interrupt, but it will just put the HBA to offline state without | |
9730 | * passing any I/O traffic. | |
8d63f375 | 9731 | * |
e59058c4 | 9732 | * Return codes |
3772a991 JS |
9733 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
9734 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8d63f375 | 9735 | */ |
3772a991 | 9736 | static pci_ers_result_t |
da0436e9 | 9737 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
8d63f375 | 9738 | { |
75baf696 JS |
9739 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
9740 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9741 | struct lpfc_sli *psli = &phba->sli; | |
9742 | uint32_t intr_mode; | |
9743 | ||
9744 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
9745 | if (pci_enable_device_mem(pdev)) { | |
9746 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
9747 | "PCI device after reset.\n"); | |
9748 | return PCI_ERS_RESULT_DISCONNECT; | |
9749 | } | |
9750 | ||
9751 | pci_restore_state(pdev); | |
0a96e975 JS |
9752 | |
9753 | /* | |
9754 | * As the new kernel behavior of pci_restore_state() API call clears | |
9755 | * device saved_state flag, need to save the restored state again. | |
9756 | */ | |
9757 | pci_save_state(pdev); | |
9758 | ||
75baf696 JS |
9759 | if (pdev->is_busmaster) |
9760 | pci_set_master(pdev); | |
9761 | ||
9762 | spin_lock_irq(&phba->hbalock); | |
9763 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
9764 | spin_unlock_irq(&phba->hbalock); | |
9765 | ||
9766 | /* Configure and enable interrupt */ | |
9767 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); | |
9768 | if (intr_mode == LPFC_INTR_ERROR) { | |
9769 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9770 | "2824 Cannot re-enable interrupt after " | |
9771 | "slot reset.\n"); | |
9772 | return PCI_ERS_RESULT_DISCONNECT; | |
9773 | } else | |
9774 | phba->intr_mode = intr_mode; | |
9775 | ||
9776 | /* Log the current active interrupt mode */ | |
9777 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
9778 | ||
8d63f375 LV |
9779 | return PCI_ERS_RESULT_RECOVERED; |
9780 | } | |
9781 | ||
9782 | /** | |
da0436e9 | 9783 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
e59058c4 | 9784 | * @pdev: pointer to PCI device |
8d63f375 | 9785 | * |
3772a991 | 9786 | * This routine is called from the PCI subsystem for error handling to device |
da0436e9 | 9787 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
3772a991 JS |
9788 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
9789 | * error recovery. After this call, traffic can start to flow from this device | |
9790 | * again. | |
da0436e9 | 9791 | **/ |
3772a991 | 9792 | static void |
da0436e9 | 9793 | lpfc_io_resume_s4(struct pci_dev *pdev) |
8d63f375 | 9794 | { |
75baf696 JS |
9795 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
9796 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9797 | ||
9798 | /* | |
9799 | * In case of slot reset, as function reset is performed through | |
9800 | * mailbox command which needs DMA to be enabled, this operation | |
9801 | * has to be moved to the io resume phase. Taking device offline | |
9802 | * will perform the necessary cleanup. | |
9803 | */ | |
9804 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { | |
9805 | /* Perform device reset */ | |
9806 | lpfc_offline_prep(phba); | |
9807 | lpfc_offline(phba); | |
9808 | lpfc_sli_brdrestart(phba); | |
9809 | /* Bring the device back online */ | |
9810 | lpfc_online(phba); | |
9811 | } | |
9812 | ||
9813 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
9814 | if (phba->hba_flag & HBA_AER_ENABLED) | |
9815 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
8d63f375 LV |
9816 | } |
9817 | ||
3772a991 JS |
9818 | /** |
9819 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem | |
9820 | * @pdev: pointer to PCI device | |
9821 | * @pid: pointer to PCI device identifier | |
9822 | * | |
9823 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
9824 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks | |
9825 | * at PCI device-specific information of the device and driver to see if the | |
9826 | * driver state that it can support this kind of device. If the match is | |
9827 | * successful, the driver core invokes this routine. This routine dispatches | |
9828 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will | |
9829 | * do all the initialization that it needs to do to handle the HBA device | |
9830 | * properly. | |
9831 | * | |
9832 | * Return code | |
9833 | * 0 - driver can claim the device | |
9834 | * negative value - driver can not claim the device | |
9835 | **/ | |
9836 | static int __devinit | |
9837 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | |
9838 | { | |
9839 | int rc; | |
8fa38513 | 9840 | struct lpfc_sli_intf intf; |
3772a991 | 9841 | |
28baac74 | 9842 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
3772a991 JS |
9843 | return -ENODEV; |
9844 | ||
8fa38513 | 9845 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
28baac74 | 9846 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
da0436e9 | 9847 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
8fa38513 | 9848 | else |
3772a991 | 9849 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
8fa38513 | 9850 | |
3772a991 JS |
9851 | return rc; |
9852 | } | |
9853 | ||
9854 | /** | |
9855 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem | |
9856 | * @pdev: pointer to PCI device | |
9857 | * | |
9858 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
9859 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. | |
9860 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device | |
9861 | * remove routine, which will perform all the necessary cleanup for the | |
9862 | * device to be removed from the PCI subsystem properly. | |
9863 | **/ | |
9864 | static void __devexit | |
9865 | lpfc_pci_remove_one(struct pci_dev *pdev) | |
9866 | { | |
9867 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9868 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9869 | ||
9870 | switch (phba->pci_dev_grp) { | |
9871 | case LPFC_PCI_DEV_LP: | |
9872 | lpfc_pci_remove_one_s3(pdev); | |
9873 | break; | |
da0436e9 JS |
9874 | case LPFC_PCI_DEV_OC: |
9875 | lpfc_pci_remove_one_s4(pdev); | |
9876 | break; | |
3772a991 JS |
9877 | default: |
9878 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9879 | "1424 Invalid PCI device group: 0x%x\n", | |
9880 | phba->pci_dev_grp); | |
9881 | break; | |
9882 | } | |
9883 | return; | |
9884 | } | |
9885 | ||
9886 | /** | |
9887 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management | |
9888 | * @pdev: pointer to PCI device | |
9889 | * @msg: power management message | |
9890 | * | |
9891 | * This routine is to be registered to the kernel's PCI subsystem to support | |
9892 | * system Power Management (PM). When PM invokes this method, it dispatches | |
9893 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will | |
9894 | * suspend the device. | |
9895 | * | |
9896 | * Return code | |
9897 | * 0 - driver suspended the device | |
9898 | * Error otherwise | |
9899 | **/ | |
9900 | static int | |
9901 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | |
9902 | { | |
9903 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9904 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9905 | int rc = -ENODEV; | |
9906 | ||
9907 | switch (phba->pci_dev_grp) { | |
9908 | case LPFC_PCI_DEV_LP: | |
9909 | rc = lpfc_pci_suspend_one_s3(pdev, msg); | |
9910 | break; | |
da0436e9 JS |
9911 | case LPFC_PCI_DEV_OC: |
9912 | rc = lpfc_pci_suspend_one_s4(pdev, msg); | |
9913 | break; | |
3772a991 JS |
9914 | default: |
9915 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9916 | "1425 Invalid PCI device group: 0x%x\n", | |
9917 | phba->pci_dev_grp); | |
9918 | break; | |
9919 | } | |
9920 | return rc; | |
9921 | } | |
9922 | ||
9923 | /** | |
9924 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management | |
9925 | * @pdev: pointer to PCI device | |
9926 | * | |
9927 | * This routine is to be registered to the kernel's PCI subsystem to support | |
9928 | * system Power Management (PM). When PM invokes this method, it dispatches | |
9929 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will | |
9930 | * resume the device. | |
9931 | * | |
9932 | * Return code | |
9933 | * 0 - driver suspended the device | |
9934 | * Error otherwise | |
9935 | **/ | |
9936 | static int | |
9937 | lpfc_pci_resume_one(struct pci_dev *pdev) | |
9938 | { | |
9939 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9940 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9941 | int rc = -ENODEV; | |
9942 | ||
9943 | switch (phba->pci_dev_grp) { | |
9944 | case LPFC_PCI_DEV_LP: | |
9945 | rc = lpfc_pci_resume_one_s3(pdev); | |
9946 | break; | |
da0436e9 JS |
9947 | case LPFC_PCI_DEV_OC: |
9948 | rc = lpfc_pci_resume_one_s4(pdev); | |
9949 | break; | |
3772a991 JS |
9950 | default: |
9951 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9952 | "1426 Invalid PCI device group: 0x%x\n", | |
9953 | phba->pci_dev_grp); | |
9954 | break; | |
9955 | } | |
9956 | return rc; | |
9957 | } | |
9958 | ||
9959 | /** | |
9960 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error | |
9961 | * @pdev: pointer to PCI device. | |
9962 | * @state: the current PCI connection state. | |
9963 | * | |
9964 | * This routine is registered to the PCI subsystem for error handling. This | |
9965 | * function is called by the PCI subsystem after a PCI bus error affecting | |
9966 | * this device has been detected. When this routine is invoked, it dispatches | |
9967 | * the action to the proper SLI-3 or SLI-4 device error detected handling | |
9968 | * routine, which will perform the proper error detected operation. | |
9969 | * | |
9970 | * Return codes | |
9971 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery | |
9972 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
9973 | **/ | |
9974 | static pci_ers_result_t | |
9975 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | |
9976 | { | |
9977 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9978 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9979 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
9980 | ||
9981 | switch (phba->pci_dev_grp) { | |
9982 | case LPFC_PCI_DEV_LP: | |
9983 | rc = lpfc_io_error_detected_s3(pdev, state); | |
9984 | break; | |
da0436e9 JS |
9985 | case LPFC_PCI_DEV_OC: |
9986 | rc = lpfc_io_error_detected_s4(pdev, state); | |
9987 | break; | |
3772a991 JS |
9988 | default: |
9989 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9990 | "1427 Invalid PCI device group: 0x%x\n", | |
9991 | phba->pci_dev_grp); | |
9992 | break; | |
9993 | } | |
9994 | return rc; | |
9995 | } | |
9996 | ||
9997 | /** | |
9998 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch | |
9999 | * @pdev: pointer to PCI device. | |
10000 | * | |
10001 | * This routine is registered to the PCI subsystem for error handling. This | |
10002 | * function is called after PCI bus has been reset to restart the PCI card | |
10003 | * from scratch, as if from a cold-boot. When this routine is invoked, it | |
10004 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling | |
10005 | * routine, which will perform the proper device reset. | |
10006 | * | |
10007 | * Return codes | |
10008 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
10009 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
10010 | **/ | |
10011 | static pci_ers_result_t | |
10012 | lpfc_io_slot_reset(struct pci_dev *pdev) | |
10013 | { | |
10014 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10015 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10016 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
10017 | ||
10018 | switch (phba->pci_dev_grp) { | |
10019 | case LPFC_PCI_DEV_LP: | |
10020 | rc = lpfc_io_slot_reset_s3(pdev); | |
10021 | break; | |
da0436e9 JS |
10022 | case LPFC_PCI_DEV_OC: |
10023 | rc = lpfc_io_slot_reset_s4(pdev); | |
10024 | break; | |
3772a991 JS |
10025 | default: |
10026 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10027 | "1428 Invalid PCI device group: 0x%x\n", | |
10028 | phba->pci_dev_grp); | |
10029 | break; | |
10030 | } | |
10031 | return rc; | |
10032 | } | |
10033 | ||
10034 | /** | |
10035 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation | |
10036 | * @pdev: pointer to PCI device | |
10037 | * | |
10038 | * This routine is registered to the PCI subsystem for error handling. It | |
10039 | * is called when kernel error recovery tells the lpfc driver that it is | |
10040 | * OK to resume normal PCI operation after PCI bus error recovery. When | |
10041 | * this routine is invoked, it dispatches the action to the proper SLI-3 | |
10042 | * or SLI-4 device io_resume routine, which will resume the device operation. | |
10043 | **/ | |
10044 | static void | |
10045 | lpfc_io_resume(struct pci_dev *pdev) | |
10046 | { | |
10047 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10048 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10049 | ||
10050 | switch (phba->pci_dev_grp) { | |
10051 | case LPFC_PCI_DEV_LP: | |
10052 | lpfc_io_resume_s3(pdev); | |
10053 | break; | |
da0436e9 JS |
10054 | case LPFC_PCI_DEV_OC: |
10055 | lpfc_io_resume_s4(pdev); | |
10056 | break; | |
3772a991 JS |
10057 | default: |
10058 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10059 | "1429 Invalid PCI device group: 0x%x\n", | |
10060 | phba->pci_dev_grp); | |
10061 | break; | |
10062 | } | |
10063 | return; | |
10064 | } | |
10065 | ||
3ef6d24c JS |
10066 | /** |
10067 | * lpfc_mgmt_open - method called when 'lpfcmgmt' is opened from userspace | |
10068 | * @inode: pointer to the inode representing the lpfcmgmt device | |
10069 | * @filep: pointer to the file representing the open lpfcmgmt device | |
10070 | * | |
10071 | * This routine puts a reference count on the lpfc module whenever the | |
10072 | * character device is opened | |
10073 | **/ | |
10074 | static int | |
10075 | lpfc_mgmt_open(struct inode *inode, struct file *filep) | |
10076 | { | |
10077 | try_module_get(THIS_MODULE); | |
10078 | return 0; | |
10079 | } | |
10080 | ||
10081 | /** | |
10082 | * lpfc_mgmt_release - method called when 'lpfcmgmt' is closed in userspace | |
10083 | * @inode: pointer to the inode representing the lpfcmgmt device | |
10084 | * @filep: pointer to the file representing the open lpfcmgmt device | |
10085 | * | |
10086 | * This routine removes a reference count from the lpfc module when the | |
10087 | * character device is closed | |
10088 | **/ | |
10089 | static int | |
10090 | lpfc_mgmt_release(struct inode *inode, struct file *filep) | |
10091 | { | |
10092 | module_put(THIS_MODULE); | |
10093 | return 0; | |
10094 | } | |
10095 | ||
dea3101e JB |
10096 | static struct pci_device_id lpfc_id_table[] = { |
10097 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, | |
10098 | PCI_ANY_ID, PCI_ANY_ID, }, | |
06325e74 JSEC |
10099 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
10100 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
10101 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
10102 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10103 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, | |
10104 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10105 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, | |
10106 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10107 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, | |
10108 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10109 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, | |
10110 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10111 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, | |
10112 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10113 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, | |
10114 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
10115 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
10116 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10117 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, | |
10118 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10119 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, | |
10120 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
10121 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
10122 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
10123 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
10124 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10125 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, | |
10126 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
10127 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
10128 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10129 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, | |
10130 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10131 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, | |
10132 | PCI_ANY_ID, PCI_ANY_ID, }, | |
84774a4d JS |
10133 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
10134 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
10135 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
10136 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10137 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, | |
10138 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
10139 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
10140 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10141 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, | |
10142 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10143 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, | |
10144 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10145 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, | |
10146 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10147 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, | |
10148 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
10149 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
10150 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10151 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, | |
10152 | PCI_ANY_ID, PCI_ANY_ID, }, | |
b87eab38 JS |
10153 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
10154 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10155 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, | |
10156 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10157 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, | |
10158 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10159 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, | |
10160 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10161 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, | |
10162 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10163 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, | |
10164 | PCI_ANY_ID, PCI_ANY_ID, }, | |
84774a4d JS |
10165 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
10166 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10167 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, | |
10168 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10169 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, | |
10170 | PCI_ANY_ID, PCI_ANY_ID, }, | |
3772a991 JS |
10171 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, |
10172 | PCI_ANY_ID, PCI_ANY_ID, }, | |
a747c9ce JS |
10173 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT, |
10174 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10175 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON, | |
6669f9bb | 10176 | PCI_ANY_ID, PCI_ANY_ID, }, |
98fc5dd9 JS |
10177 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS, |
10178 | PCI_ANY_ID, PCI_ANY_ID, }, | |
085c647c JS |
10179 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC, |
10180 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10181 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE, | |
10182 | PCI_ANY_ID, PCI_ANY_ID, }, | |
c0c11512 JS |
10183 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF, |
10184 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10185 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF, | |
10186 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
10187 | { 0 } |
10188 | }; | |
10189 | ||
10190 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); | |
10191 | ||
8d63f375 LV |
10192 | static struct pci_error_handlers lpfc_err_handler = { |
10193 | .error_detected = lpfc_io_error_detected, | |
10194 | .slot_reset = lpfc_io_slot_reset, | |
10195 | .resume = lpfc_io_resume, | |
10196 | }; | |
10197 | ||
dea3101e JB |
10198 | static struct pci_driver lpfc_driver = { |
10199 | .name = LPFC_DRIVER_NAME, | |
10200 | .id_table = lpfc_id_table, | |
10201 | .probe = lpfc_pci_probe_one, | |
10202 | .remove = __devexit_p(lpfc_pci_remove_one), | |
3a55b532 | 10203 | .suspend = lpfc_pci_suspend_one, |
3772a991 | 10204 | .resume = lpfc_pci_resume_one, |
2e0fef85 | 10205 | .err_handler = &lpfc_err_handler, |
dea3101e JB |
10206 | }; |
10207 | ||
3ef6d24c JS |
10208 | static const struct file_operations lpfc_mgmt_fop = { |
10209 | .open = lpfc_mgmt_open, | |
10210 | .release = lpfc_mgmt_release, | |
10211 | }; | |
10212 | ||
10213 | static struct miscdevice lpfc_mgmt_dev = { | |
10214 | .minor = MISC_DYNAMIC_MINOR, | |
10215 | .name = "lpfcmgmt", | |
10216 | .fops = &lpfc_mgmt_fop, | |
10217 | }; | |
10218 | ||
e59058c4 | 10219 | /** |
3621a710 | 10220 | * lpfc_init - lpfc module initialization routine |
e59058c4 JS |
10221 | * |
10222 | * This routine is to be invoked when the lpfc module is loaded into the | |
10223 | * kernel. The special kernel macro module_init() is used to indicate the | |
10224 | * role of this routine to the kernel as lpfc module entry point. | |
10225 | * | |
10226 | * Return codes | |
10227 | * 0 - successful | |
10228 | * -ENOMEM - FC attach transport failed | |
10229 | * all others - failed | |
10230 | */ | |
dea3101e JB |
10231 | static int __init |
10232 | lpfc_init(void) | |
10233 | { | |
10234 | int error = 0; | |
10235 | ||
10236 | printk(LPFC_MODULE_DESC "\n"); | |
c44ce173 | 10237 | printk(LPFC_COPYRIGHT "\n"); |
dea3101e | 10238 | |
3ef6d24c JS |
10239 | error = misc_register(&lpfc_mgmt_dev); |
10240 | if (error) | |
10241 | printk(KERN_ERR "Could not register lpfcmgmt device, " | |
10242 | "misc_register returned with status %d", error); | |
10243 | ||
7ee5d43e JS |
10244 | if (lpfc_enable_npiv) { |
10245 | lpfc_transport_functions.vport_create = lpfc_vport_create; | |
10246 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; | |
10247 | } | |
dea3101e JB |
10248 | lpfc_transport_template = |
10249 | fc_attach_transport(&lpfc_transport_functions); | |
7ee5d43e | 10250 | if (lpfc_transport_template == NULL) |
dea3101e | 10251 | return -ENOMEM; |
7ee5d43e | 10252 | if (lpfc_enable_npiv) { |
7ee5d43e | 10253 | lpfc_vport_transport_template = |
98c9ea5c JS |
10254 | fc_attach_transport(&lpfc_vport_transport_functions); |
10255 | if (lpfc_vport_transport_template == NULL) { | |
10256 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e | 10257 | return -ENOMEM; |
98c9ea5c | 10258 | } |
7ee5d43e | 10259 | } |
dea3101e | 10260 | error = pci_register_driver(&lpfc_driver); |
92d7f7b0 | 10261 | if (error) { |
dea3101e | 10262 | fc_release_transport(lpfc_transport_template); |
d7c255b2 JS |
10263 | if (lpfc_enable_npiv) |
10264 | fc_release_transport(lpfc_vport_transport_template); | |
92d7f7b0 | 10265 | } |
dea3101e JB |
10266 | |
10267 | return error; | |
10268 | } | |
10269 | ||
e59058c4 | 10270 | /** |
3621a710 | 10271 | * lpfc_exit - lpfc module removal routine |
e59058c4 JS |
10272 | * |
10273 | * This routine is invoked when the lpfc module is removed from the kernel. | |
10274 | * The special kernel macro module_exit() is used to indicate the role of | |
10275 | * this routine to the kernel as lpfc module exit point. | |
10276 | */ | |
dea3101e JB |
10277 | static void __exit |
10278 | lpfc_exit(void) | |
10279 | { | |
3ef6d24c | 10280 | misc_deregister(&lpfc_mgmt_dev); |
dea3101e JB |
10281 | pci_unregister_driver(&lpfc_driver); |
10282 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e JS |
10283 | if (lpfc_enable_npiv) |
10284 | fc_release_transport(lpfc_vport_transport_template); | |
81301a9b | 10285 | if (_dump_buf_data) { |
6a9c52cf JS |
10286 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
10287 | "_dump_buf_data at 0x%p\n", | |
81301a9b JS |
10288 | (1L << _dump_buf_data_order), _dump_buf_data); |
10289 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); | |
10290 | } | |
10291 | ||
10292 | if (_dump_buf_dif) { | |
6a9c52cf JS |
10293 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
10294 | "_dump_buf_dif at 0x%p\n", | |
81301a9b JS |
10295 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
10296 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); | |
10297 | } | |
dea3101e JB |
10298 | } |
10299 | ||
10300 | module_init(lpfc_init); | |
10301 | module_exit(lpfc_exit); | |
10302 | MODULE_LICENSE("GPL"); | |
10303 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); | |
10304 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); | |
10305 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |