]>
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. * |
d4379acd | 4 | * Copyright (C) 2004-2012 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 | 66 | static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *); |
8a9d2e80 JS |
67 | static void lpfc_free_els_sgl_list(struct lpfc_hba *); |
68 | static void lpfc_init_sgl_list(struct lpfc_hba *); | |
da0436e9 JS |
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 *); | |
618a5230 JS |
76 | static void lpfc_sli4_disable_intr(struct lpfc_hba *); |
77 | static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba *, uint32_t); | |
dea3101e JB |
78 | |
79 | static struct scsi_transport_template *lpfc_transport_template = NULL; | |
92d7f7b0 | 80 | static struct scsi_transport_template *lpfc_vport_transport_template = NULL; |
dea3101e JB |
81 | static DEFINE_IDR(lpfc_hba_index); |
82 | ||
e59058c4 | 83 | /** |
3621a710 | 84 | * lpfc_config_port_prep - Perform lpfc initialization prior to config port |
e59058c4 JS |
85 | * @phba: pointer to lpfc hba data structure. |
86 | * | |
87 | * This routine will do LPFC initialization prior to issuing the CONFIG_PORT | |
88 | * mailbox command. It retrieves the revision information from the HBA and | |
89 | * collects the Vital Product Data (VPD) about the HBA for preparing the | |
90 | * configuration of the HBA. | |
91 | * | |
92 | * Return codes: | |
93 | * 0 - success. | |
94 | * -ERESTART - requests the SLI layer to reset the HBA and try again. | |
95 | * Any other value - indicates an error. | |
96 | **/ | |
dea3101e | 97 | int |
2e0fef85 | 98 | lpfc_config_port_prep(struct lpfc_hba *phba) |
dea3101e JB |
99 | { |
100 | lpfc_vpd_t *vp = &phba->vpd; | |
101 | int i = 0, rc; | |
102 | LPFC_MBOXQ_t *pmb; | |
103 | MAILBOX_t *mb; | |
104 | char *lpfc_vpd_data = NULL; | |
105 | uint16_t offset = 0; | |
106 | static char licensed[56] = | |
107 | "key unlock for use with gnu public licensed code only\0"; | |
65a29c16 | 108 | static int init_key = 1; |
dea3101e JB |
109 | |
110 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
111 | if (!pmb) { | |
2e0fef85 | 112 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
113 | return -ENOMEM; |
114 | } | |
115 | ||
04c68496 | 116 | mb = &pmb->u.mb; |
2e0fef85 | 117 | phba->link_state = LPFC_INIT_MBX_CMDS; |
dea3101e JB |
118 | |
119 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { | |
65a29c16 JS |
120 | if (init_key) { |
121 | uint32_t *ptext = (uint32_t *) licensed; | |
dea3101e | 122 | |
65a29c16 JS |
123 | for (i = 0; i < 56; i += sizeof (uint32_t), ptext++) |
124 | *ptext = cpu_to_be32(*ptext); | |
125 | init_key = 0; | |
126 | } | |
dea3101e JB |
127 | |
128 | lpfc_read_nv(phba, pmb); | |
129 | memset((char*)mb->un.varRDnvp.rsvd3, 0, | |
130 | sizeof (mb->un.varRDnvp.rsvd3)); | |
131 | memcpy((char*)mb->un.varRDnvp.rsvd3, licensed, | |
132 | sizeof (licensed)); | |
133 | ||
134 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
135 | ||
136 | if (rc != MBX_SUCCESS) { | |
ed957684 | 137 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
e8b62011 | 138 | "0324 Config Port initialization " |
dea3101e JB |
139 | "error, mbxCmd x%x READ_NVPARM, " |
140 | "mbxStatus x%x\n", | |
dea3101e JB |
141 | mb->mbxCommand, mb->mbxStatus); |
142 | mempool_free(pmb, phba->mbox_mem_pool); | |
143 | return -ERESTART; | |
144 | } | |
145 | memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, | |
2e0fef85 JS |
146 | sizeof(phba->wwnn)); |
147 | memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname, | |
148 | sizeof(phba->wwpn)); | |
dea3101e JB |
149 | } |
150 | ||
92d7f7b0 JS |
151 | phba->sli3_options = 0x0; |
152 | ||
dea3101e JB |
153 | /* Setup and issue mailbox READ REV command */ |
154 | lpfc_read_rev(phba, pmb); | |
155 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
156 | if (rc != MBX_SUCCESS) { | |
ed957684 | 157 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 158 | "0439 Adapter failed to init, mbxCmd x%x " |
dea3101e | 159 | "READ_REV, mbxStatus x%x\n", |
dea3101e JB |
160 | mb->mbxCommand, mb->mbxStatus); |
161 | mempool_free( pmb, phba->mbox_mem_pool); | |
162 | return -ERESTART; | |
163 | } | |
164 | ||
92d7f7b0 | 165 | |
1de933f3 JSEC |
166 | /* |
167 | * The value of rr must be 1 since the driver set the cv field to 1. | |
168 | * This setting requires the FW to set all revision fields. | |
dea3101e | 169 | */ |
1de933f3 | 170 | if (mb->un.varRdRev.rr == 0) { |
dea3101e | 171 | vp->rev.rBit = 0; |
1de933f3 | 172 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 JS |
173 | "0440 Adapter failed to init, READ_REV has " |
174 | "missing revision information.\n"); | |
dea3101e JB |
175 | mempool_free(pmb, phba->mbox_mem_pool); |
176 | return -ERESTART; | |
dea3101e JB |
177 | } |
178 | ||
495a714c JS |
179 | if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp) { |
180 | mempool_free(pmb, phba->mbox_mem_pool); | |
ed957684 | 181 | return -EINVAL; |
495a714c | 182 | } |
ed957684 | 183 | |
dea3101e | 184 | /* Save information as VPD data */ |
1de933f3 | 185 | vp->rev.rBit = 1; |
92d7f7b0 | 186 | memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t)); |
1de933f3 JSEC |
187 | vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; |
188 | memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); | |
189 | vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; | |
190 | memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16); | |
dea3101e JB |
191 | vp->rev.biuRev = mb->un.varRdRev.biuRev; |
192 | vp->rev.smRev = mb->un.varRdRev.smRev; | |
193 | vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev; | |
194 | vp->rev.endecRev = mb->un.varRdRev.endecRev; | |
195 | vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh; | |
196 | vp->rev.fcphLow = mb->un.varRdRev.fcphLow; | |
197 | vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh; | |
198 | vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow; | |
199 | vp->rev.postKernRev = mb->un.varRdRev.postKernRev; | |
200 | vp->rev.opFwRev = mb->un.varRdRev.opFwRev; | |
201 | ||
92d7f7b0 JS |
202 | /* If the sli feature level is less then 9, we must |
203 | * tear down all RPIs and VPIs on link down if NPIV | |
204 | * is enabled. | |
205 | */ | |
206 | if (vp->rev.feaLevelHigh < 9) | |
207 | phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN; | |
208 | ||
dea3101e JB |
209 | if (lpfc_is_LC_HBA(phba->pcidev->device)) |
210 | memcpy(phba->RandomData, (char *)&mb->un.varWords[24], | |
211 | sizeof (phba->RandomData)); | |
212 | ||
dea3101e | 213 | /* Get adapter VPD information */ |
dea3101e JB |
214 | lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL); |
215 | if (!lpfc_vpd_data) | |
d7c255b2 | 216 | goto out_free_mbox; |
dea3101e | 217 | do { |
a0c87cbd | 218 | lpfc_dump_mem(phba, pmb, offset, DMP_REGION_VPD); |
dea3101e JB |
219 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
220 | ||
221 | if (rc != MBX_SUCCESS) { | |
222 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 | 223 | "0441 VPD not present on adapter, " |
dea3101e | 224 | "mbxCmd x%x DUMP VPD, mbxStatus x%x\n", |
dea3101e | 225 | mb->mbxCommand, mb->mbxStatus); |
74b72a59 | 226 | mb->un.varDmp.word_cnt = 0; |
dea3101e | 227 | } |
04c68496 JS |
228 | /* dump mem may return a zero when finished or we got a |
229 | * mailbox error, either way we are done. | |
230 | */ | |
231 | if (mb->un.varDmp.word_cnt == 0) | |
232 | break; | |
74b72a59 JW |
233 | if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) |
234 | mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; | |
d7c255b2 JS |
235 | lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET, |
236 | lpfc_vpd_data + offset, | |
92d7f7b0 | 237 | mb->un.varDmp.word_cnt); |
dea3101e | 238 | offset += mb->un.varDmp.word_cnt; |
74b72a59 JW |
239 | } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); |
240 | lpfc_parse_vpd(phba, lpfc_vpd_data, offset); | |
dea3101e JB |
241 | |
242 | kfree(lpfc_vpd_data); | |
dea3101e JB |
243 | out_free_mbox: |
244 | mempool_free(pmb, phba->mbox_mem_pool); | |
245 | return 0; | |
246 | } | |
247 | ||
e59058c4 | 248 | /** |
3621a710 | 249 | * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd |
e59058c4 JS |
250 | * @phba: pointer to lpfc hba data structure. |
251 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
252 | * | |
253 | * This is the completion handler for driver's configuring asynchronous event | |
254 | * mailbox command to the device. If the mailbox command returns successfully, | |
255 | * it will set internal async event support flag to 1; otherwise, it will | |
256 | * set internal async event support flag to 0. | |
257 | **/ | |
57127f15 JS |
258 | static void |
259 | lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
260 | { | |
04c68496 | 261 | if (pmboxq->u.mb.mbxStatus == MBX_SUCCESS) |
57127f15 JS |
262 | phba->temp_sensor_support = 1; |
263 | else | |
264 | phba->temp_sensor_support = 0; | |
265 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
266 | return; | |
267 | } | |
268 | ||
97207482 | 269 | /** |
3621a710 | 270 | * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler |
97207482 JS |
271 | * @phba: pointer to lpfc hba data structure. |
272 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
273 | * | |
274 | * This is the completion handler for dump mailbox command for getting | |
275 | * wake up parameters. When this command complete, the response contain | |
276 | * Option rom version of the HBA. This function translate the version number | |
277 | * into a human readable string and store it in OptionROMVersion. | |
278 | **/ | |
279 | static void | |
280 | lpfc_dump_wakeup_param_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) | |
281 | { | |
282 | struct prog_id *prg; | |
283 | uint32_t prog_id_word; | |
284 | char dist = ' '; | |
285 | /* character array used for decoding dist type. */ | |
286 | char dist_char[] = "nabx"; | |
287 | ||
04c68496 | 288 | if (pmboxq->u.mb.mbxStatus != MBX_SUCCESS) { |
9f1e1b50 | 289 | mempool_free(pmboxq, phba->mbox_mem_pool); |
97207482 | 290 | return; |
9f1e1b50 | 291 | } |
97207482 JS |
292 | |
293 | prg = (struct prog_id *) &prog_id_word; | |
294 | ||
295 | /* word 7 contain option rom version */ | |
04c68496 | 296 | prog_id_word = pmboxq->u.mb.un.varWords[7]; |
97207482 JS |
297 | |
298 | /* Decode the Option rom version word to a readable string */ | |
299 | if (prg->dist < 4) | |
300 | dist = dist_char[prg->dist]; | |
301 | ||
302 | if ((prg->dist == 3) && (prg->num == 0)) | |
303 | sprintf(phba->OptionROMVersion, "%d.%d%d", | |
304 | prg->ver, prg->rev, prg->lev); | |
305 | else | |
306 | sprintf(phba->OptionROMVersion, "%d.%d%d%c%d", | |
307 | prg->ver, prg->rev, prg->lev, | |
308 | dist, prg->num); | |
9f1e1b50 | 309 | mempool_free(pmboxq, phba->mbox_mem_pool); |
97207482 JS |
310 | return; |
311 | } | |
312 | ||
0558056c JS |
313 | /** |
314 | * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname, | |
315 | * cfg_soft_wwnn, cfg_soft_wwpn | |
316 | * @vport: pointer to lpfc vport data structure. | |
317 | * | |
318 | * | |
319 | * Return codes | |
320 | * None. | |
321 | **/ | |
322 | void | |
323 | lpfc_update_vport_wwn(struct lpfc_vport *vport) | |
324 | { | |
325 | /* If the soft name exists then update it using the service params */ | |
326 | if (vport->phba->cfg_soft_wwnn) | |
327 | u64_to_wwn(vport->phba->cfg_soft_wwnn, | |
328 | vport->fc_sparam.nodeName.u.wwn); | |
329 | if (vport->phba->cfg_soft_wwpn) | |
330 | u64_to_wwn(vport->phba->cfg_soft_wwpn, | |
331 | vport->fc_sparam.portName.u.wwn); | |
332 | ||
333 | /* | |
334 | * If the name is empty or there exists a soft name | |
335 | * then copy the service params name, otherwise use the fc name | |
336 | */ | |
337 | if (vport->fc_nodename.u.wwn[0] == 0 || vport->phba->cfg_soft_wwnn) | |
338 | memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName, | |
339 | sizeof(struct lpfc_name)); | |
340 | else | |
341 | memcpy(&vport->fc_sparam.nodeName, &vport->fc_nodename, | |
342 | sizeof(struct lpfc_name)); | |
343 | ||
344 | if (vport->fc_portname.u.wwn[0] == 0 || vport->phba->cfg_soft_wwpn) | |
345 | memcpy(&vport->fc_portname, &vport->fc_sparam.portName, | |
346 | sizeof(struct lpfc_name)); | |
347 | else | |
348 | memcpy(&vport->fc_sparam.portName, &vport->fc_portname, | |
349 | sizeof(struct lpfc_name)); | |
350 | } | |
351 | ||
e59058c4 | 352 | /** |
3621a710 | 353 | * lpfc_config_port_post - Perform lpfc initialization after config port |
e59058c4 JS |
354 | * @phba: pointer to lpfc hba data structure. |
355 | * | |
356 | * This routine will do LPFC initialization after the CONFIG_PORT mailbox | |
357 | * command call. It performs all internal resource and state setups on the | |
358 | * port: post IOCB buffers, enable appropriate host interrupt attentions, | |
359 | * ELS ring timers, etc. | |
360 | * | |
361 | * Return codes | |
362 | * 0 - success. | |
363 | * Any other value - error. | |
364 | **/ | |
dea3101e | 365 | int |
2e0fef85 | 366 | lpfc_config_port_post(struct lpfc_hba *phba) |
dea3101e | 367 | { |
2e0fef85 | 368 | struct lpfc_vport *vport = phba->pport; |
a257bf90 | 369 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e JB |
370 | LPFC_MBOXQ_t *pmb; |
371 | MAILBOX_t *mb; | |
372 | struct lpfc_dmabuf *mp; | |
373 | struct lpfc_sli *psli = &phba->sli; | |
374 | uint32_t status, timeout; | |
2e0fef85 JS |
375 | int i, j; |
376 | int rc; | |
dea3101e | 377 | |
7af67051 JS |
378 | spin_lock_irq(&phba->hbalock); |
379 | /* | |
380 | * If the Config port completed correctly the HBA is not | |
381 | * over heated any more. | |
382 | */ | |
383 | if (phba->over_temp_state == HBA_OVER_TEMP) | |
384 | phba->over_temp_state = HBA_NORMAL_TEMP; | |
385 | spin_unlock_irq(&phba->hbalock); | |
386 | ||
dea3101e JB |
387 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
388 | if (!pmb) { | |
2e0fef85 | 389 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
390 | return -ENOMEM; |
391 | } | |
04c68496 | 392 | mb = &pmb->u.mb; |
dea3101e | 393 | |
dea3101e | 394 | /* Get login parameters for NID. */ |
9f1177a3 JS |
395 | rc = lpfc_read_sparam(phba, pmb, 0); |
396 | if (rc) { | |
397 | mempool_free(pmb, phba->mbox_mem_pool); | |
398 | return -ENOMEM; | |
399 | } | |
400 | ||
ed957684 | 401 | pmb->vport = vport; |
dea3101e | 402 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 403 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 404 | "0448 Adapter failed init, mbxCmd x%x " |
dea3101e | 405 | "READ_SPARM mbxStatus x%x\n", |
dea3101e | 406 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 407 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 408 | mp = (struct lpfc_dmabuf *) pmb->context1; |
9f1177a3 | 409 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e JB |
410 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
411 | kfree(mp); | |
412 | return -EIO; | |
413 | } | |
414 | ||
415 | mp = (struct lpfc_dmabuf *) pmb->context1; | |
416 | ||
2e0fef85 | 417 | memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm)); |
dea3101e JB |
418 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
419 | kfree(mp); | |
420 | pmb->context1 = NULL; | |
0558056c | 421 | lpfc_update_vport_wwn(vport); |
a257bf90 JS |
422 | |
423 | /* Update the fc_host data structures with new wwn. */ | |
424 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); | |
425 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
21e9a0a5 | 426 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
a257bf90 | 427 | |
dea3101e JB |
428 | /* If no serial number in VPD data, use low 6 bytes of WWNN */ |
429 | /* This should be consolidated into parse_vpd ? - mr */ | |
430 | if (phba->SerialNumber[0] == 0) { | |
431 | uint8_t *outptr; | |
432 | ||
2e0fef85 | 433 | outptr = &vport->fc_nodename.u.s.IEEE[0]; |
dea3101e JB |
434 | for (i = 0; i < 12; i++) { |
435 | status = *outptr++; | |
436 | j = ((status & 0xf0) >> 4); | |
437 | if (j <= 9) | |
438 | phba->SerialNumber[i] = | |
439 | (char)((uint8_t) 0x30 + (uint8_t) j); | |
440 | else | |
441 | phba->SerialNumber[i] = | |
442 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | |
443 | i++; | |
444 | j = (status & 0xf); | |
445 | if (j <= 9) | |
446 | phba->SerialNumber[i] = | |
447 | (char)((uint8_t) 0x30 + (uint8_t) j); | |
448 | else | |
449 | phba->SerialNumber[i] = | |
450 | (char)((uint8_t) 0x61 + (uint8_t) (j - 10)); | |
451 | } | |
452 | } | |
453 | ||
dea3101e | 454 | lpfc_read_config(phba, pmb); |
ed957684 | 455 | pmb->vport = vport; |
dea3101e | 456 | if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { |
ed957684 | 457 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
e8b62011 | 458 | "0453 Adapter failed to init, mbxCmd x%x " |
dea3101e | 459 | "READ_CONFIG, mbxStatus x%x\n", |
dea3101e | 460 | mb->mbxCommand, mb->mbxStatus); |
2e0fef85 | 461 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e JB |
462 | mempool_free( pmb, phba->mbox_mem_pool); |
463 | return -EIO; | |
464 | } | |
465 | ||
a0c87cbd JS |
466 | /* Check if the port is disabled */ |
467 | lpfc_sli_read_link_ste(phba); | |
468 | ||
dea3101e JB |
469 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ |
470 | if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1)) | |
471 | phba->cfg_hba_queue_depth = | |
f1126688 JS |
472 | (mb->un.varRdConfig.max_xri + 1) - |
473 | lpfc_sli4_get_els_iocb_cnt(phba); | |
dea3101e JB |
474 | |
475 | phba->lmt = mb->un.varRdConfig.lmt; | |
74b72a59 JW |
476 | |
477 | /* Get the default values for Model Name and Description */ | |
478 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
479 | ||
2e0fef85 | 480 | phba->link_state = LPFC_LINK_DOWN; |
dea3101e | 481 | |
0b727fea | 482 | /* Only process IOCBs on ELS ring till hba_state is READY */ |
7e56aa25 | 483 | if (psli->ring[psli->extra_ring].sli.sli3.cmdringaddr) |
a4bc3379 | 484 | psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT; |
7e56aa25 | 485 | if (psli->ring[psli->fcp_ring].sli.sli3.cmdringaddr) |
dea3101e | 486 | psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT; |
7e56aa25 | 487 | if (psli->ring[psli->next_ring].sli.sli3.cmdringaddr) |
dea3101e JB |
488 | psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; |
489 | ||
490 | /* Post receive buffers for desired rings */ | |
ed957684 JS |
491 | if (phba->sli_rev != 3) |
492 | lpfc_post_rcv_buf(phba); | |
dea3101e | 493 | |
9399627f JS |
494 | /* |
495 | * Configure HBA MSI-X attention conditions to messages if MSI-X mode | |
496 | */ | |
497 | if (phba->intr_type == MSIX) { | |
498 | rc = lpfc_config_msi(phba, pmb); | |
499 | if (rc) { | |
500 | mempool_free(pmb, phba->mbox_mem_pool); | |
501 | return -EIO; | |
502 | } | |
503 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
504 | if (rc != MBX_SUCCESS) { | |
505 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, | |
506 | "0352 Config MSI mailbox command " | |
507 | "failed, mbxCmd x%x, mbxStatus x%x\n", | |
04c68496 JS |
508 | pmb->u.mb.mbxCommand, |
509 | pmb->u.mb.mbxStatus); | |
9399627f JS |
510 | mempool_free(pmb, phba->mbox_mem_pool); |
511 | return -EIO; | |
512 | } | |
513 | } | |
514 | ||
04c68496 | 515 | spin_lock_irq(&phba->hbalock); |
9399627f JS |
516 | /* Initialize ERATT handling flag */ |
517 | phba->hba_flag &= ~HBA_ERATT_HANDLED; | |
518 | ||
dea3101e | 519 | /* Enable appropriate host interrupts */ |
9940b97b JS |
520 | if (lpfc_readl(phba->HCregaddr, &status)) { |
521 | spin_unlock_irq(&phba->hbalock); | |
522 | return -EIO; | |
523 | } | |
dea3101e JB |
524 | status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; |
525 | if (psli->num_rings > 0) | |
526 | status |= HC_R0INT_ENA; | |
527 | if (psli->num_rings > 1) | |
528 | status |= HC_R1INT_ENA; | |
529 | if (psli->num_rings > 2) | |
530 | status |= HC_R2INT_ENA; | |
531 | if (psli->num_rings > 3) | |
532 | status |= HC_R3INT_ENA; | |
533 | ||
875fbdfe JSEC |
534 | if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) && |
535 | (phba->cfg_poll & DISABLE_FCP_RING_INT)) | |
9399627f | 536 | status &= ~(HC_R0INT_ENA); |
875fbdfe | 537 | |
dea3101e JB |
538 | writel(status, phba->HCregaddr); |
539 | readl(phba->HCregaddr); /* flush */ | |
2e0fef85 | 540 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 541 | |
9399627f JS |
542 | /* Set up ring-0 (ELS) timer */ |
543 | timeout = phba->fc_ratov * 2; | |
2e0fef85 | 544 | mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout); |
9399627f | 545 | /* Set up heart beat (HB) timer */ |
858c9f6c JS |
546 | mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL); |
547 | phba->hb_outstanding = 0; | |
548 | phba->last_completion_time = jiffies; | |
9399627f JS |
549 | /* Set up error attention (ERATT) polling timer */ |
550 | mod_timer(&phba->eratt_poll, jiffies + HZ * LPFC_ERATT_POLL_INTERVAL); | |
dea3101e | 551 | |
a0c87cbd JS |
552 | if (phba->hba_flag & LINK_DISABLED) { |
553 | lpfc_printf_log(phba, | |
554 | KERN_ERR, LOG_INIT, | |
555 | "2598 Adapter Link is disabled.\n"); | |
556 | lpfc_down_link(phba, pmb); | |
557 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
558 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
559 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { | |
560 | lpfc_printf_log(phba, | |
561 | KERN_ERR, LOG_INIT, | |
562 | "2599 Adapter failed to issue DOWN_LINK" | |
563 | " mbox command rc 0x%x\n", rc); | |
564 | ||
565 | mempool_free(pmb, phba->mbox_mem_pool); | |
566 | return -EIO; | |
567 | } | |
e40a02c1 | 568 | } else if (phba->cfg_suppress_link_up == LPFC_INITIALIZE_LINK) { |
026abb87 JS |
569 | mempool_free(pmb, phba->mbox_mem_pool); |
570 | rc = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); | |
571 | if (rc) | |
572 | return rc; | |
dea3101e JB |
573 | } |
574 | /* MBOX buffer will be freed in mbox compl */ | |
57127f15 | 575 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
9f1177a3 JS |
576 | if (!pmb) { |
577 | phba->link_state = LPFC_HBA_ERROR; | |
578 | return -ENOMEM; | |
579 | } | |
580 | ||
57127f15 JS |
581 | lpfc_config_async(phba, pmb, LPFC_ELS_RING); |
582 | pmb->mbox_cmpl = lpfc_config_async_cmpl; | |
583 | pmb->vport = phba->pport; | |
584 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
dea3101e | 585 | |
57127f15 JS |
586 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
587 | lpfc_printf_log(phba, | |
588 | KERN_ERR, | |
589 | LOG_INIT, | |
590 | "0456 Adapter failed to issue " | |
e4e74273 | 591 | "ASYNCEVT_ENABLE mbox status x%x\n", |
57127f15 JS |
592 | rc); |
593 | mempool_free(pmb, phba->mbox_mem_pool); | |
594 | } | |
97207482 JS |
595 | |
596 | /* Get Option rom version */ | |
597 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
9f1177a3 JS |
598 | if (!pmb) { |
599 | phba->link_state = LPFC_HBA_ERROR; | |
600 | return -ENOMEM; | |
601 | } | |
602 | ||
97207482 JS |
603 | lpfc_dump_wakeup_param(phba, pmb); |
604 | pmb->mbox_cmpl = lpfc_dump_wakeup_param_cmpl; | |
605 | pmb->vport = phba->pport; | |
606 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
607 | ||
608 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { | |
609 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, "0435 Adapter failed " | |
e4e74273 | 610 | "to get Option ROM version status x%x\n", rc); |
97207482 JS |
611 | mempool_free(pmb, phba->mbox_mem_pool); |
612 | } | |
613 | ||
d7c255b2 | 614 | return 0; |
ce8b3ce5 JS |
615 | } |
616 | ||
84d1b006 JS |
617 | /** |
618 | * lpfc_hba_init_link - Initialize the FC link | |
619 | * @phba: pointer to lpfc hba data structure. | |
6e7288d9 | 620 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT |
84d1b006 JS |
621 | * |
622 | * This routine will issue the INIT_LINK mailbox command call. | |
623 | * It is available to other drivers through the lpfc_hba data | |
624 | * structure for use as a delayed link up mechanism with the | |
625 | * module parameter lpfc_suppress_link_up. | |
626 | * | |
627 | * Return code | |
628 | * 0 - success | |
629 | * Any other value - error | |
630 | **/ | |
631 | int | |
6e7288d9 | 632 | lpfc_hba_init_link(struct lpfc_hba *phba, uint32_t flag) |
1b51197d JS |
633 | { |
634 | return lpfc_hba_init_link_fc_topology(phba, phba->cfg_topology, flag); | |
635 | } | |
636 | ||
637 | /** | |
638 | * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology | |
639 | * @phba: pointer to lpfc hba data structure. | |
640 | * @fc_topology: desired fc topology. | |
641 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT | |
642 | * | |
643 | * This routine will issue the INIT_LINK mailbox command call. | |
644 | * It is available to other drivers through the lpfc_hba data | |
645 | * structure for use as a delayed link up mechanism with the | |
646 | * module parameter lpfc_suppress_link_up. | |
647 | * | |
648 | * Return code | |
649 | * 0 - success | |
650 | * Any other value - error | |
651 | **/ | |
652 | int | |
653 | lpfc_hba_init_link_fc_topology(struct lpfc_hba *phba, uint32_t fc_topology, | |
654 | uint32_t flag) | |
84d1b006 JS |
655 | { |
656 | struct lpfc_vport *vport = phba->pport; | |
657 | LPFC_MBOXQ_t *pmb; | |
658 | MAILBOX_t *mb; | |
659 | int rc; | |
660 | ||
661 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
662 | if (!pmb) { | |
663 | phba->link_state = LPFC_HBA_ERROR; | |
664 | return -ENOMEM; | |
665 | } | |
666 | mb = &pmb->u.mb; | |
667 | pmb->vport = vport; | |
668 | ||
026abb87 JS |
669 | if ((phba->cfg_link_speed > LPFC_USER_LINK_SPEED_MAX) || |
670 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_1G) && | |
671 | !(phba->lmt & LMT_1Gb)) || | |
672 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_2G) && | |
673 | !(phba->lmt & LMT_2Gb)) || | |
674 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_4G) && | |
675 | !(phba->lmt & LMT_4Gb)) || | |
676 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_8G) && | |
677 | !(phba->lmt & LMT_8Gb)) || | |
678 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_10G) && | |
679 | !(phba->lmt & LMT_10Gb)) || | |
680 | ((phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G) && | |
681 | !(phba->lmt & LMT_16Gb))) { | |
682 | /* Reset link speed to auto */ | |
683 | lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, | |
684 | "1302 Invalid speed for this board:%d " | |
685 | "Reset link speed to auto.\n", | |
686 | phba->cfg_link_speed); | |
687 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; | |
688 | } | |
1b51197d | 689 | lpfc_init_link(phba, pmb, fc_topology, phba->cfg_link_speed); |
84d1b006 | 690 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
1b51197d JS |
691 | if (phba->sli_rev < LPFC_SLI_REV4) |
692 | lpfc_set_loopback_flag(phba); | |
6e7288d9 | 693 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
76a95d75 | 694 | if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) { |
84d1b006 JS |
695 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
696 | "0498 Adapter failed to init, mbxCmd x%x " | |
697 | "INIT_LINK, mbxStatus x%x\n", | |
698 | mb->mbxCommand, mb->mbxStatus); | |
76a95d75 JS |
699 | if (phba->sli_rev <= LPFC_SLI_REV3) { |
700 | /* Clear all interrupt enable conditions */ | |
701 | writel(0, phba->HCregaddr); | |
702 | readl(phba->HCregaddr); /* flush */ | |
703 | /* Clear all pending interrupts */ | |
704 | writel(0xffffffff, phba->HAregaddr); | |
705 | readl(phba->HAregaddr); /* flush */ | |
706 | } | |
84d1b006 | 707 | phba->link_state = LPFC_HBA_ERROR; |
6e7288d9 | 708 | if (rc != MBX_BUSY || flag == MBX_POLL) |
84d1b006 JS |
709 | mempool_free(pmb, phba->mbox_mem_pool); |
710 | return -EIO; | |
711 | } | |
e40a02c1 | 712 | phba->cfg_suppress_link_up = LPFC_INITIALIZE_LINK; |
6e7288d9 JS |
713 | if (flag == MBX_POLL) |
714 | mempool_free(pmb, phba->mbox_mem_pool); | |
84d1b006 JS |
715 | |
716 | return 0; | |
717 | } | |
718 | ||
719 | /** | |
720 | * lpfc_hba_down_link - this routine downs the FC link | |
6e7288d9 JS |
721 | * @phba: pointer to lpfc hba data structure. |
722 | * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT | |
84d1b006 JS |
723 | * |
724 | * This routine will issue the DOWN_LINK mailbox command call. | |
725 | * It is available to other drivers through the lpfc_hba data | |
726 | * structure for use to stop the link. | |
727 | * | |
728 | * Return code | |
729 | * 0 - success | |
730 | * Any other value - error | |
731 | **/ | |
732 | int | |
6e7288d9 | 733 | lpfc_hba_down_link(struct lpfc_hba *phba, uint32_t flag) |
84d1b006 JS |
734 | { |
735 | LPFC_MBOXQ_t *pmb; | |
736 | int rc; | |
737 | ||
738 | pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
739 | if (!pmb) { | |
740 | phba->link_state = LPFC_HBA_ERROR; | |
741 | return -ENOMEM; | |
742 | } | |
743 | ||
744 | lpfc_printf_log(phba, | |
745 | KERN_ERR, LOG_INIT, | |
746 | "0491 Adapter Link is disabled.\n"); | |
747 | lpfc_down_link(phba, pmb); | |
748 | pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; | |
6e7288d9 | 749 | rc = lpfc_sli_issue_mbox(phba, pmb, flag); |
84d1b006 JS |
750 | if ((rc != MBX_SUCCESS) && (rc != MBX_BUSY)) { |
751 | lpfc_printf_log(phba, | |
752 | KERN_ERR, LOG_INIT, | |
753 | "2522 Adapter failed to issue DOWN_LINK" | |
754 | " mbox command rc 0x%x\n", rc); | |
755 | ||
756 | mempool_free(pmb, phba->mbox_mem_pool); | |
757 | return -EIO; | |
758 | } | |
6e7288d9 JS |
759 | if (flag == MBX_POLL) |
760 | mempool_free(pmb, phba->mbox_mem_pool); | |
761 | ||
84d1b006 JS |
762 | return 0; |
763 | } | |
764 | ||
e59058c4 | 765 | /** |
3621a710 | 766 | * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset |
e59058c4 JS |
767 | * @phba: pointer to lpfc HBA data structure. |
768 | * | |
769 | * This routine will do LPFC uninitialization before the HBA is reset when | |
770 | * bringing down the SLI Layer. | |
771 | * | |
772 | * Return codes | |
773 | * 0 - success. | |
774 | * Any other value - error. | |
775 | **/ | |
dea3101e | 776 | int |
2e0fef85 | 777 | lpfc_hba_down_prep(struct lpfc_hba *phba) |
dea3101e | 778 | { |
1b32f6aa JS |
779 | struct lpfc_vport **vports; |
780 | int i; | |
3772a991 JS |
781 | |
782 | if (phba->sli_rev <= LPFC_SLI_REV3) { | |
783 | /* Disable interrupts */ | |
784 | writel(0, phba->HCregaddr); | |
785 | readl(phba->HCregaddr); /* flush */ | |
786 | } | |
dea3101e | 787 | |
1b32f6aa JS |
788 | if (phba->pport->load_flag & FC_UNLOADING) |
789 | lpfc_cleanup_discovery_resources(phba->pport); | |
790 | else { | |
791 | vports = lpfc_create_vport_work_array(phba); | |
792 | if (vports != NULL) | |
3772a991 JS |
793 | for (i = 0; i <= phba->max_vports && |
794 | vports[i] != NULL; i++) | |
1b32f6aa JS |
795 | lpfc_cleanup_discovery_resources(vports[i]); |
796 | lpfc_destroy_vport_work_array(phba, vports); | |
7f5f3d0d JS |
797 | } |
798 | return 0; | |
dea3101e JB |
799 | } |
800 | ||
e59058c4 | 801 | /** |
3772a991 | 802 | * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset |
e59058c4 JS |
803 | * @phba: pointer to lpfc HBA data structure. |
804 | * | |
805 | * This routine will do uninitialization after the HBA is reset when bring | |
806 | * down the SLI Layer. | |
807 | * | |
808 | * Return codes | |
af901ca1 | 809 | * 0 - success. |
e59058c4 JS |
810 | * Any other value - error. |
811 | **/ | |
3772a991 JS |
812 | static int |
813 | lpfc_hba_down_post_s3(struct lpfc_hba *phba) | |
41415862 JW |
814 | { |
815 | struct lpfc_sli *psli = &phba->sli; | |
816 | struct lpfc_sli_ring *pring; | |
817 | struct lpfc_dmabuf *mp, *next_mp; | |
09372820 | 818 | LIST_HEAD(completions); |
41415862 JW |
819 | int i; |
820 | ||
92d7f7b0 JS |
821 | if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) |
822 | lpfc_sli_hbqbuf_free_all(phba); | |
823 | else { | |
824 | /* Cleanup preposted buffers on the ELS ring */ | |
825 | pring = &psli->ring[LPFC_ELS_RING]; | |
826 | list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { | |
827 | list_del(&mp->list); | |
828 | pring->postbufq_cnt--; | |
829 | lpfc_mbuf_free(phba, mp->virt, mp->phys); | |
830 | kfree(mp); | |
831 | } | |
41415862 JW |
832 | } |
833 | ||
09372820 | 834 | spin_lock_irq(&phba->hbalock); |
41415862 JW |
835 | for (i = 0; i < psli->num_rings; i++) { |
836 | pring = &psli->ring[i]; | |
09372820 JS |
837 | |
838 | /* At this point in time the HBA is either reset or DOA. Either | |
839 | * way, nothing should be on txcmplq as it will NEVER complete. | |
840 | */ | |
841 | list_splice_init(&pring->txcmplq, &completions); | |
842 | pring->txcmplq_cnt = 0; | |
843 | spin_unlock_irq(&phba->hbalock); | |
844 | ||
a257bf90 JS |
845 | /* Cancel all the IOCBs from the completions list */ |
846 | lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT, | |
847 | IOERR_SLI_ABORTED); | |
09372820 | 848 | |
41415862 | 849 | lpfc_sli_abort_iocb_ring(phba, pring); |
09372820 | 850 | spin_lock_irq(&phba->hbalock); |
41415862 | 851 | } |
09372820 | 852 | spin_unlock_irq(&phba->hbalock); |
41415862 JW |
853 | |
854 | return 0; | |
855 | } | |
5af5eee7 | 856 | |
da0436e9 JS |
857 | /** |
858 | * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset | |
859 | * @phba: pointer to lpfc HBA data structure. | |
860 | * | |
861 | * This routine will do uninitialization after the HBA is reset when bring | |
862 | * down the SLI Layer. | |
863 | * | |
864 | * Return codes | |
af901ca1 | 865 | * 0 - success. |
da0436e9 JS |
866 | * Any other value - error. |
867 | **/ | |
868 | static int | |
869 | lpfc_hba_down_post_s4(struct lpfc_hba *phba) | |
870 | { | |
871 | struct lpfc_scsi_buf *psb, *psb_next; | |
872 | LIST_HEAD(aborts); | |
873 | int ret; | |
874 | unsigned long iflag = 0; | |
0f65ff68 JS |
875 | struct lpfc_sglq *sglq_entry = NULL; |
876 | ||
da0436e9 JS |
877 | ret = lpfc_hba_down_post_s3(phba); |
878 | if (ret) | |
879 | return ret; | |
880 | /* At this point in time the HBA is either reset or DOA. Either | |
881 | * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be | |
882 | * on the lpfc_sgl_list so that it can either be freed if the | |
883 | * driver is unloading or reposted if the driver is restarting | |
884 | * the port. | |
885 | */ | |
886 | spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */ | |
887 | /* scsl_buf_list */ | |
888 | /* abts_sgl_list_lock required because worker thread uses this | |
889 | * list. | |
890 | */ | |
891 | spin_lock(&phba->sli4_hba.abts_sgl_list_lock); | |
0f65ff68 JS |
892 | list_for_each_entry(sglq_entry, |
893 | &phba->sli4_hba.lpfc_abts_els_sgl_list, list) | |
894 | sglq_entry->state = SGL_FREED; | |
895 | ||
da0436e9 JS |
896 | list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list, |
897 | &phba->sli4_hba.lpfc_sgl_list); | |
898 | spin_unlock(&phba->sli4_hba.abts_sgl_list_lock); | |
899 | /* abts_scsi_buf_list_lock required because worker thread uses this | |
900 | * list. | |
901 | */ | |
902 | spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
903 | list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list, | |
904 | &aborts); | |
905 | spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
906 | spin_unlock_irq(&phba->hbalock); | |
907 | ||
908 | list_for_each_entry_safe(psb, psb_next, &aborts, list) { | |
909 | psb->pCmd = NULL; | |
910 | psb->status = IOSTAT_SUCCESS; | |
911 | } | |
912 | spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); | |
913 | list_splice(&aborts, &phba->lpfc_scsi_buf_list); | |
914 | spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); | |
915 | return 0; | |
916 | } | |
917 | ||
918 | /** | |
919 | * lpfc_hba_down_post - Wrapper func for hba down post routine | |
920 | * @phba: pointer to lpfc HBA data structure. | |
921 | * | |
922 | * This routine wraps the actual SLI3 or SLI4 routine for performing | |
923 | * uninitialization after the HBA is reset when bring down the SLI Layer. | |
924 | * | |
925 | * Return codes | |
af901ca1 | 926 | * 0 - success. |
da0436e9 JS |
927 | * Any other value - error. |
928 | **/ | |
929 | int | |
930 | lpfc_hba_down_post(struct lpfc_hba *phba) | |
931 | { | |
932 | return (*phba->lpfc_hba_down_post)(phba); | |
933 | } | |
41415862 | 934 | |
e59058c4 | 935 | /** |
3621a710 | 936 | * lpfc_hb_timeout - The HBA-timer timeout handler |
e59058c4 JS |
937 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. |
938 | * | |
939 | * This is the HBA-timer timeout handler registered to the lpfc driver. When | |
940 | * this timer fires, a HBA timeout event shall be posted to the lpfc driver | |
941 | * work-port-events bitmap and the worker thread is notified. This timeout | |
942 | * event will be used by the worker thread to invoke the actual timeout | |
943 | * handler routine, lpfc_hb_timeout_handler. Any periodical operations will | |
944 | * be performed in the timeout handler and the HBA timeout event bit shall | |
945 | * be cleared by the worker thread after it has taken the event bitmap out. | |
946 | **/ | |
a6ababd2 | 947 | static void |
858c9f6c JS |
948 | lpfc_hb_timeout(unsigned long ptr) |
949 | { | |
950 | struct lpfc_hba *phba; | |
5e9d9b82 | 951 | uint32_t tmo_posted; |
858c9f6c JS |
952 | unsigned long iflag; |
953 | ||
954 | phba = (struct lpfc_hba *)ptr; | |
9399627f JS |
955 | |
956 | /* Check for heart beat timeout conditions */ | |
858c9f6c | 957 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); |
5e9d9b82 JS |
958 | tmo_posted = phba->pport->work_port_events & WORKER_HB_TMO; |
959 | if (!tmo_posted) | |
858c9f6c JS |
960 | phba->pport->work_port_events |= WORKER_HB_TMO; |
961 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); | |
962 | ||
9399627f | 963 | /* Tell the worker thread there is work to do */ |
5e9d9b82 JS |
964 | if (!tmo_posted) |
965 | lpfc_worker_wake_up(phba); | |
858c9f6c JS |
966 | return; |
967 | } | |
968 | ||
19ca7609 JS |
969 | /** |
970 | * lpfc_rrq_timeout - The RRQ-timer timeout handler | |
971 | * @ptr: unsigned long holds the pointer to lpfc hba data structure. | |
972 | * | |
973 | * This is the RRQ-timer timeout handler registered to the lpfc driver. When | |
974 | * this timer fires, a RRQ timeout event shall be posted to the lpfc driver | |
975 | * work-port-events bitmap and the worker thread is notified. This timeout | |
976 | * event will be used by the worker thread to invoke the actual timeout | |
977 | * handler routine, lpfc_rrq_handler. Any periodical operations will | |
978 | * be performed in the timeout handler and the RRQ timeout event bit shall | |
979 | * be cleared by the worker thread after it has taken the event bitmap out. | |
980 | **/ | |
981 | static void | |
982 | lpfc_rrq_timeout(unsigned long ptr) | |
983 | { | |
984 | struct lpfc_hba *phba; | |
19ca7609 JS |
985 | unsigned long iflag; |
986 | ||
987 | phba = (struct lpfc_hba *)ptr; | |
988 | spin_lock_irqsave(&phba->pport->work_port_lock, iflag); | |
1151e3ec | 989 | phba->hba_flag |= HBA_RRQ_ACTIVE; |
19ca7609 | 990 | spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); |
1151e3ec | 991 | lpfc_worker_wake_up(phba); |
19ca7609 JS |
992 | } |
993 | ||
e59058c4 | 994 | /** |
3621a710 | 995 | * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function |
e59058c4 JS |
996 | * @phba: pointer to lpfc hba data structure. |
997 | * @pmboxq: pointer to the driver internal queue element for mailbox command. | |
998 | * | |
999 | * This is the callback function to the lpfc heart-beat mailbox command. | |
1000 | * If configured, the lpfc driver issues the heart-beat mailbox command to | |
1001 | * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the | |
1002 | * heart-beat mailbox command is issued, the driver shall set up heart-beat | |
1003 | * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks | |
1004 | * heart-beat outstanding state. Once the mailbox command comes back and | |
1005 | * no error conditions detected, the heart-beat mailbox command timer is | |
1006 | * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding | |
1007 | * state is cleared for the next heart-beat. If the timer expired with the | |
1008 | * heart-beat outstanding state set, the driver will put the HBA offline. | |
1009 | **/ | |
858c9f6c JS |
1010 | static void |
1011 | lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) | |
1012 | { | |
1013 | unsigned long drvr_flag; | |
1014 | ||
1015 | spin_lock_irqsave(&phba->hbalock, drvr_flag); | |
1016 | phba->hb_outstanding = 0; | |
1017 | spin_unlock_irqrestore(&phba->hbalock, drvr_flag); | |
1018 | ||
9399627f | 1019 | /* Check and reset heart-beat timer is necessary */ |
858c9f6c JS |
1020 | mempool_free(pmboxq, phba->mbox_mem_pool); |
1021 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) && | |
1022 | !(phba->link_state == LPFC_HBA_ERROR) && | |
51ef4c26 | 1023 | !(phba->pport->load_flag & FC_UNLOADING)) |
858c9f6c JS |
1024 | mod_timer(&phba->hb_tmofunc, |
1025 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
1026 | return; | |
1027 | } | |
1028 | ||
e59058c4 | 1029 | /** |
3621a710 | 1030 | * lpfc_hb_timeout_handler - The HBA-timer timeout handler |
e59058c4 JS |
1031 | * @phba: pointer to lpfc hba data structure. |
1032 | * | |
1033 | * This is the actual HBA-timer timeout handler to be invoked by the worker | |
1034 | * thread whenever the HBA timer fired and HBA-timeout event posted. This | |
1035 | * handler performs any periodic operations needed for the device. If such | |
1036 | * periodic event has already been attended to either in the interrupt handler | |
1037 | * or by processing slow-ring or fast-ring events within the HBA-timer | |
1038 | * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets | |
1039 | * the timer for the next timeout period. If lpfc heart-beat mailbox command | |
1040 | * is configured and there is no heart-beat mailbox command outstanding, a | |
1041 | * heart-beat mailbox is issued and timer set properly. Otherwise, if there | |
1042 | * has been a heart-beat mailbox command outstanding, the HBA shall be put | |
1043 | * to offline. | |
1044 | **/ | |
858c9f6c JS |
1045 | void |
1046 | lpfc_hb_timeout_handler(struct lpfc_hba *phba) | |
1047 | { | |
45ed1190 | 1048 | struct lpfc_vport **vports; |
858c9f6c | 1049 | LPFC_MBOXQ_t *pmboxq; |
0ff10d46 | 1050 | struct lpfc_dmabuf *buf_ptr; |
45ed1190 | 1051 | int retval, i; |
858c9f6c | 1052 | struct lpfc_sli *psli = &phba->sli; |
0ff10d46 | 1053 | LIST_HEAD(completions); |
858c9f6c | 1054 | |
45ed1190 JS |
1055 | vports = lpfc_create_vport_work_array(phba); |
1056 | if (vports != NULL) | |
1057 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) | |
1058 | lpfc_rcv_seq_check_edtov(vports[i]); | |
1059 | lpfc_destroy_vport_work_array(phba, vports); | |
1060 | ||
858c9f6c | 1061 | if ((phba->link_state == LPFC_HBA_ERROR) || |
51ef4c26 | 1062 | (phba->pport->load_flag & FC_UNLOADING) || |
858c9f6c JS |
1063 | (phba->pport->fc_flag & FC_OFFLINE_MODE)) |
1064 | return; | |
1065 | ||
1066 | spin_lock_irq(&phba->pport->work_port_lock); | |
858c9f6c JS |
1067 | |
1068 | if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ, | |
1069 | jiffies)) { | |
1070 | spin_unlock_irq(&phba->pport->work_port_lock); | |
1071 | if (!phba->hb_outstanding) | |
1072 | mod_timer(&phba->hb_tmofunc, | |
1073 | jiffies + HZ * LPFC_HB_MBOX_INTERVAL); | |
1074 | else | |
1075 | mod_timer(&phba->hb_tmofunc, | |
1076 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | |
1077 | return; | |
1078 | } | |
1079 | spin_unlock_irq(&phba->pport->work_port_lock); | |
1080 | ||
0ff10d46 JS |
1081 | if (phba->elsbuf_cnt && |
1082 | (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) { | |
1083 | spin_lock_irq(&phba->hbalock); | |
1084 | list_splice_init(&phba->elsbuf, &completions); | |
1085 | phba->elsbuf_cnt = 0; | |
1086 | phba->elsbuf_prev_cnt = 0; | |
1087 | spin_unlock_irq(&phba->hbalock); | |
1088 | ||
1089 | while (!list_empty(&completions)) { | |
1090 | list_remove_head(&completions, buf_ptr, | |
1091 | struct lpfc_dmabuf, list); | |
1092 | lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); | |
1093 | kfree(buf_ptr); | |
1094 | } | |
1095 | } | |
1096 | phba->elsbuf_prev_cnt = phba->elsbuf_cnt; | |
1097 | ||
858c9f6c | 1098 | /* If there is no heart beat outstanding, issue a heartbeat command */ |
13815c83 JS |
1099 | if (phba->cfg_enable_hba_heartbeat) { |
1100 | if (!phba->hb_outstanding) { | |
bc73905a JS |
1101 | if ((!(psli->sli_flag & LPFC_SLI_MBOX_ACTIVE)) && |
1102 | (list_empty(&psli->mboxq))) { | |
1103 | pmboxq = mempool_alloc(phba->mbox_mem_pool, | |
1104 | GFP_KERNEL); | |
1105 | if (!pmboxq) { | |
1106 | mod_timer(&phba->hb_tmofunc, | |
1107 | jiffies + | |
1108 | HZ * LPFC_HB_MBOX_INTERVAL); | |
1109 | return; | |
1110 | } | |
1111 | ||
1112 | lpfc_heart_beat(phba, pmboxq); | |
1113 | pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl; | |
1114 | pmboxq->vport = phba->pport; | |
1115 | retval = lpfc_sli_issue_mbox(phba, pmboxq, | |
1116 | MBX_NOWAIT); | |
1117 | ||
1118 | if (retval != MBX_BUSY && | |
1119 | retval != MBX_SUCCESS) { | |
1120 | mempool_free(pmboxq, | |
1121 | phba->mbox_mem_pool); | |
1122 | mod_timer(&phba->hb_tmofunc, | |
1123 | jiffies + | |
1124 | HZ * LPFC_HB_MBOX_INTERVAL); | |
1125 | return; | |
1126 | } | |
1127 | phba->skipped_hb = 0; | |
1128 | phba->hb_outstanding = 1; | |
1129 | } else if (time_before_eq(phba->last_completion_time, | |
1130 | phba->skipped_hb)) { | |
1131 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
1132 | "2857 Last completion time not " | |
1133 | " updated in %d ms\n", | |
1134 | jiffies_to_msecs(jiffies | |
1135 | - phba->last_completion_time)); | |
1136 | } else | |
1137 | phba->skipped_hb = jiffies; | |
1138 | ||
858c9f6c | 1139 | mod_timer(&phba->hb_tmofunc, |
13815c83 | 1140 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); |
858c9f6c | 1141 | return; |
13815c83 JS |
1142 | } else { |
1143 | /* | |
1144 | * If heart beat timeout called with hb_outstanding set | |
dcf2a4e0 JS |
1145 | * we need to give the hb mailbox cmd a chance to |
1146 | * complete or TMO. | |
13815c83 | 1147 | */ |
dcf2a4e0 JS |
1148 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
1149 | "0459 Adapter heartbeat still out" | |
1150 | "standing:last compl time was %d ms.\n", | |
1151 | jiffies_to_msecs(jiffies | |
1152 | - phba->last_completion_time)); | |
1153 | mod_timer(&phba->hb_tmofunc, | |
1154 | jiffies + HZ * LPFC_HB_MBOX_TIMEOUT); | |
858c9f6c | 1155 | } |
858c9f6c JS |
1156 | } |
1157 | } | |
1158 | ||
e59058c4 | 1159 | /** |
3621a710 | 1160 | * lpfc_offline_eratt - Bring lpfc offline on hardware error attention |
e59058c4 JS |
1161 | * @phba: pointer to lpfc hba data structure. |
1162 | * | |
1163 | * This routine is called to bring the HBA offline when HBA hardware error | |
1164 | * other than Port Error 6 has been detected. | |
1165 | **/ | |
09372820 JS |
1166 | static void |
1167 | lpfc_offline_eratt(struct lpfc_hba *phba) | |
1168 | { | |
1169 | struct lpfc_sli *psli = &phba->sli; | |
1170 | ||
1171 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1172 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
09372820 | 1173 | spin_unlock_irq(&phba->hbalock); |
618a5230 | 1174 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
09372820 JS |
1175 | |
1176 | lpfc_offline(phba); | |
1177 | lpfc_reset_barrier(phba); | |
f4b4c68f | 1178 | spin_lock_irq(&phba->hbalock); |
09372820 | 1179 | lpfc_sli_brdreset(phba); |
f4b4c68f | 1180 | spin_unlock_irq(&phba->hbalock); |
09372820 JS |
1181 | lpfc_hba_down_post(phba); |
1182 | lpfc_sli_brdready(phba, HS_MBRDY); | |
1183 | lpfc_unblock_mgmt_io(phba); | |
1184 | phba->link_state = LPFC_HBA_ERROR; | |
1185 | return; | |
1186 | } | |
1187 | ||
da0436e9 JS |
1188 | /** |
1189 | * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention | |
1190 | * @phba: pointer to lpfc hba data structure. | |
1191 | * | |
1192 | * This routine is called to bring a SLI4 HBA offline when HBA hardware error | |
1193 | * other than Port Error 6 has been detected. | |
1194 | **/ | |
1195 | static void | |
1196 | lpfc_sli4_offline_eratt(struct lpfc_hba *phba) | |
1197 | { | |
618a5230 | 1198 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
da0436e9 JS |
1199 | lpfc_offline(phba); |
1200 | lpfc_sli4_brdreset(phba); | |
1201 | lpfc_hba_down_post(phba); | |
1202 | lpfc_sli4_post_status_check(phba); | |
1203 | lpfc_unblock_mgmt_io(phba); | |
1204 | phba->link_state = LPFC_HBA_ERROR; | |
1205 | } | |
1206 | ||
a257bf90 JS |
1207 | /** |
1208 | * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler | |
1209 | * @phba: pointer to lpfc hba data structure. | |
1210 | * | |
1211 | * This routine is invoked to handle the deferred HBA hardware error | |
1212 | * conditions. This type of error is indicated by HBA by setting ER1 | |
1213 | * and another ER bit in the host status register. The driver will | |
1214 | * wait until the ER1 bit clears before handling the error condition. | |
1215 | **/ | |
1216 | static void | |
1217 | lpfc_handle_deferred_eratt(struct lpfc_hba *phba) | |
1218 | { | |
1219 | uint32_t old_host_status = phba->work_hs; | |
1220 | struct lpfc_sli_ring *pring; | |
1221 | struct lpfc_sli *psli = &phba->sli; | |
1222 | ||
f4b4c68f JS |
1223 | /* If the pci channel is offline, ignore possible errors, |
1224 | * since we cannot communicate with the pci card anyway. | |
1225 | */ | |
1226 | if (pci_channel_offline(phba->pcidev)) { | |
1227 | spin_lock_irq(&phba->hbalock); | |
1228 | phba->hba_flag &= ~DEFER_ERATT; | |
1229 | spin_unlock_irq(&phba->hbalock); | |
1230 | return; | |
1231 | } | |
1232 | ||
a257bf90 JS |
1233 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
1234 | "0479 Deferred Adapter Hardware Error " | |
1235 | "Data: x%x x%x x%x\n", | |
1236 | phba->work_hs, | |
1237 | phba->work_status[0], phba->work_status[1]); | |
1238 | ||
1239 | spin_lock_irq(&phba->hbalock); | |
f4b4c68f | 1240 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
a257bf90 JS |
1241 | spin_unlock_irq(&phba->hbalock); |
1242 | ||
1243 | ||
1244 | /* | |
1245 | * Firmware stops when it triggred erratt. That could cause the I/Os | |
1246 | * dropped by the firmware. Error iocb (I/O) on txcmplq and let the | |
1247 | * SCSI layer retry it after re-establishing link. | |
1248 | */ | |
1249 | pring = &psli->ring[psli->fcp_ring]; | |
1250 | lpfc_sli_abort_iocb_ring(phba, pring); | |
1251 | ||
1252 | /* | |
1253 | * There was a firmware error. Take the hba offline and then | |
1254 | * attempt to restart it. | |
1255 | */ | |
618a5230 | 1256 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
a257bf90 JS |
1257 | lpfc_offline(phba); |
1258 | ||
1259 | /* Wait for the ER1 bit to clear.*/ | |
1260 | while (phba->work_hs & HS_FFER1) { | |
1261 | msleep(100); | |
9940b97b JS |
1262 | if (lpfc_readl(phba->HSregaddr, &phba->work_hs)) { |
1263 | phba->work_hs = UNPLUG_ERR ; | |
1264 | break; | |
1265 | } | |
a257bf90 JS |
1266 | /* If driver is unloading let the worker thread continue */ |
1267 | if (phba->pport->load_flag & FC_UNLOADING) { | |
1268 | phba->work_hs = 0; | |
1269 | break; | |
1270 | } | |
1271 | } | |
1272 | ||
1273 | /* | |
1274 | * This is to ptrotect against a race condition in which | |
1275 | * first write to the host attention register clear the | |
1276 | * host status register. | |
1277 | */ | |
1278 | if ((!phba->work_hs) && (!(phba->pport->load_flag & FC_UNLOADING))) | |
1279 | phba->work_hs = old_host_status & ~HS_FFER1; | |
1280 | ||
3772a991 | 1281 | spin_lock_irq(&phba->hbalock); |
a257bf90 | 1282 | phba->hba_flag &= ~DEFER_ERATT; |
3772a991 | 1283 | spin_unlock_irq(&phba->hbalock); |
a257bf90 JS |
1284 | phba->work_status[0] = readl(phba->MBslimaddr + 0xa8); |
1285 | phba->work_status[1] = readl(phba->MBslimaddr + 0xac); | |
1286 | } | |
1287 | ||
3772a991 JS |
1288 | static void |
1289 | lpfc_board_errevt_to_mgmt(struct lpfc_hba *phba) | |
1290 | { | |
1291 | struct lpfc_board_event_header board_event; | |
1292 | struct Scsi_Host *shost; | |
1293 | ||
1294 | board_event.event_type = FC_REG_BOARD_EVENT; | |
1295 | board_event.subcategory = LPFC_EVENT_PORTINTERR; | |
1296 | shost = lpfc_shost_from_vport(phba->pport); | |
1297 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1298 | sizeof(board_event), | |
1299 | (char *) &board_event, | |
1300 | LPFC_NL_VENDOR_ID); | |
1301 | } | |
1302 | ||
e59058c4 | 1303 | /** |
3772a991 | 1304 | * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler |
e59058c4 JS |
1305 | * @phba: pointer to lpfc hba data structure. |
1306 | * | |
1307 | * This routine is invoked to handle the following HBA hardware error | |
1308 | * conditions: | |
1309 | * 1 - HBA error attention interrupt | |
1310 | * 2 - DMA ring index out of range | |
1311 | * 3 - Mailbox command came back as unknown | |
1312 | **/ | |
3772a991 JS |
1313 | static void |
1314 | lpfc_handle_eratt_s3(struct lpfc_hba *phba) | |
dea3101e | 1315 | { |
2e0fef85 | 1316 | struct lpfc_vport *vport = phba->pport; |
2e0fef85 | 1317 | struct lpfc_sli *psli = &phba->sli; |
dea3101e | 1318 | struct lpfc_sli_ring *pring; |
d2873e4c | 1319 | uint32_t event_data; |
57127f15 JS |
1320 | unsigned long temperature; |
1321 | struct temp_event temp_event_data; | |
92d7f7b0 | 1322 | struct Scsi_Host *shost; |
2e0fef85 | 1323 | |
8d63f375 | 1324 | /* If the pci channel is offline, ignore possible errors, |
3772a991 JS |
1325 | * since we cannot communicate with the pci card anyway. |
1326 | */ | |
1327 | if (pci_channel_offline(phba->pcidev)) { | |
1328 | spin_lock_irq(&phba->hbalock); | |
1329 | phba->hba_flag &= ~DEFER_ERATT; | |
1330 | spin_unlock_irq(&phba->hbalock); | |
8d63f375 | 1331 | return; |
3772a991 JS |
1332 | } |
1333 | ||
13815c83 JS |
1334 | /* If resets are disabled then leave the HBA alone and return */ |
1335 | if (!phba->cfg_enable_hba_reset) | |
1336 | return; | |
dea3101e | 1337 | |
ea2151b4 | 1338 | /* Send an internal error event to mgmt application */ |
3772a991 | 1339 | lpfc_board_errevt_to_mgmt(phba); |
ea2151b4 | 1340 | |
a257bf90 JS |
1341 | if (phba->hba_flag & DEFER_ERATT) |
1342 | lpfc_handle_deferred_eratt(phba); | |
1343 | ||
dcf2a4e0 JS |
1344 | if ((phba->work_hs & HS_FFER6) || (phba->work_hs & HS_FFER8)) { |
1345 | if (phba->work_hs & HS_FFER6) | |
1346 | /* Re-establishing Link */ | |
1347 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
1348 | "1301 Re-establishing Link " | |
1349 | "Data: x%x x%x x%x\n", | |
1350 | phba->work_hs, phba->work_status[0], | |
1351 | phba->work_status[1]); | |
1352 | if (phba->work_hs & HS_FFER8) | |
1353 | /* Device Zeroization */ | |
1354 | lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT, | |
1355 | "2861 Host Authentication device " | |
1356 | "zeroization Data:x%x x%x x%x\n", | |
1357 | phba->work_hs, phba->work_status[0], | |
1358 | phba->work_status[1]); | |
58da1ffb | 1359 | |
92d7f7b0 | 1360 | spin_lock_irq(&phba->hbalock); |
f4b4c68f | 1361 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; |
92d7f7b0 | 1362 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1363 | |
1364 | /* | |
1365 | * Firmware stops when it triggled erratt with HS_FFER6. | |
1366 | * That could cause the I/Os dropped by the firmware. | |
1367 | * Error iocb (I/O) on txcmplq and let the SCSI layer | |
1368 | * retry it after re-establishing link. | |
1369 | */ | |
1370 | pring = &psli->ring[psli->fcp_ring]; | |
1371 | lpfc_sli_abort_iocb_ring(phba, pring); | |
1372 | ||
dea3101e JB |
1373 | /* |
1374 | * There was a firmware error. Take the hba offline and then | |
1375 | * attempt to restart it. | |
1376 | */ | |
618a5230 | 1377 | lpfc_offline_prep(phba, LPFC_MBX_NO_WAIT); |
dea3101e | 1378 | lpfc_offline(phba); |
41415862 | 1379 | lpfc_sli_brdrestart(phba); |
dea3101e | 1380 | if (lpfc_online(phba) == 0) { /* Initialize the HBA */ |
46fa311e | 1381 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
1382 | return; |
1383 | } | |
46fa311e | 1384 | lpfc_unblock_mgmt_io(phba); |
57127f15 JS |
1385 | } else if (phba->work_hs & HS_CRIT_TEMP) { |
1386 | temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET); | |
1387 | temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT; | |
1388 | temp_event_data.event_code = LPFC_CRIT_TEMP; | |
1389 | temp_event_data.data = (uint32_t)temperature; | |
1390 | ||
1391 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 1392 | "0406 Adapter maximum temperature exceeded " |
57127f15 JS |
1393 | "(%ld), taking this port offline " |
1394 | "Data: x%x x%x x%x\n", | |
1395 | temperature, phba->work_hs, | |
1396 | phba->work_status[0], phba->work_status[1]); | |
1397 | ||
1398 | shost = lpfc_shost_from_vport(phba->pport); | |
1399 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1400 | sizeof(temp_event_data), | |
1401 | (char *) &temp_event_data, | |
1402 | SCSI_NL_VID_TYPE_PCI | |
1403 | | PCI_VENDOR_ID_EMULEX); | |
1404 | ||
7af67051 | 1405 | spin_lock_irq(&phba->hbalock); |
7af67051 JS |
1406 | phba->over_temp_state = HBA_OVER_TEMP; |
1407 | spin_unlock_irq(&phba->hbalock); | |
09372820 | 1408 | lpfc_offline_eratt(phba); |
57127f15 | 1409 | |
dea3101e JB |
1410 | } else { |
1411 | /* The if clause above forces this code path when the status | |
9399627f JS |
1412 | * failure is a value other than FFER6. Do not call the offline |
1413 | * twice. This is the adapter hardware error path. | |
dea3101e JB |
1414 | */ |
1415 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 | 1416 | "0457 Adapter Hardware Error " |
dea3101e | 1417 | "Data: x%x x%x x%x\n", |
e8b62011 | 1418 | phba->work_hs, |
dea3101e JB |
1419 | phba->work_status[0], phba->work_status[1]); |
1420 | ||
d2873e4c | 1421 | event_data = FC_REG_DUMP_EVENT; |
92d7f7b0 | 1422 | shost = lpfc_shost_from_vport(vport); |
2e0fef85 | 1423 | fc_host_post_vendor_event(shost, fc_get_event_number(), |
d2873e4c JS |
1424 | sizeof(event_data), (char *) &event_data, |
1425 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
1426 | ||
09372820 | 1427 | lpfc_offline_eratt(phba); |
dea3101e | 1428 | } |
9399627f | 1429 | return; |
dea3101e JB |
1430 | } |
1431 | ||
618a5230 JS |
1432 | /** |
1433 | * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg | |
1434 | * @phba: pointer to lpfc hba data structure. | |
1435 | * @mbx_action: flag for mailbox shutdown action. | |
1436 | * | |
1437 | * This routine is invoked to perform an SLI4 port PCI function reset in | |
1438 | * response to port status register polling attention. It waits for port | |
1439 | * status register (ERR, RDY, RN) bits before proceeding with function reset. | |
1440 | * During this process, interrupt vectors are freed and later requested | |
1441 | * for handling possible port resource change. | |
1442 | **/ | |
1443 | static int | |
1444 | lpfc_sli4_port_sta_fn_reset(struct lpfc_hba *phba, int mbx_action) | |
1445 | { | |
1446 | int rc; | |
1447 | uint32_t intr_mode; | |
1448 | ||
1449 | /* | |
1450 | * On error status condition, driver need to wait for port | |
1451 | * ready before performing reset. | |
1452 | */ | |
1453 | rc = lpfc_sli4_pdev_status_reg_wait(phba); | |
1454 | if (!rc) { | |
1455 | /* need reset: attempt for port recovery */ | |
1456 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1457 | "2887 Reset Needed: Attempting Port " | |
1458 | "Recovery...\n"); | |
1459 | lpfc_offline_prep(phba, mbx_action); | |
1460 | lpfc_offline(phba); | |
1461 | /* release interrupt for possible resource change */ | |
1462 | lpfc_sli4_disable_intr(phba); | |
1463 | lpfc_sli_brdrestart(phba); | |
1464 | /* request and enable interrupt */ | |
1465 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); | |
1466 | if (intr_mode == LPFC_INTR_ERROR) { | |
1467 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1468 | "3175 Failed to enable interrupt\n"); | |
1469 | return -EIO; | |
1470 | } else { | |
1471 | phba->intr_mode = intr_mode; | |
1472 | } | |
1473 | rc = lpfc_online(phba); | |
1474 | if (rc == 0) | |
1475 | lpfc_unblock_mgmt_io(phba); | |
1476 | } | |
1477 | return rc; | |
1478 | } | |
1479 | ||
da0436e9 JS |
1480 | /** |
1481 | * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler | |
1482 | * @phba: pointer to lpfc hba data structure. | |
1483 | * | |
1484 | * This routine is invoked to handle the SLI4 HBA hardware error attention | |
1485 | * conditions. | |
1486 | **/ | |
1487 | static void | |
1488 | lpfc_handle_eratt_s4(struct lpfc_hba *phba) | |
1489 | { | |
1490 | struct lpfc_vport *vport = phba->pport; | |
1491 | uint32_t event_data; | |
1492 | struct Scsi_Host *shost; | |
2fcee4bf | 1493 | uint32_t if_type; |
2e90f4b5 JS |
1494 | struct lpfc_register portstat_reg = {0}; |
1495 | uint32_t reg_err1, reg_err2; | |
1496 | uint32_t uerrlo_reg, uemasklo_reg; | |
1497 | uint32_t pci_rd_rc1, pci_rd_rc2; | |
73d91e50 | 1498 | int rc; |
da0436e9 JS |
1499 | |
1500 | /* If the pci channel is offline, ignore possible errors, since | |
1501 | * we cannot communicate with the pci card anyway. | |
1502 | */ | |
1503 | if (pci_channel_offline(phba->pcidev)) | |
1504 | return; | |
1505 | /* If resets are disabled then leave the HBA alone and return */ | |
1506 | if (!phba->cfg_enable_hba_reset) | |
1507 | return; | |
1508 | ||
2fcee4bf JS |
1509 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
1510 | switch (if_type) { | |
1511 | case LPFC_SLI_INTF_IF_TYPE_0: | |
2e90f4b5 JS |
1512 | pci_rd_rc1 = lpfc_readl( |
1513 | phba->sli4_hba.u.if_type0.UERRLOregaddr, | |
1514 | &uerrlo_reg); | |
1515 | pci_rd_rc2 = lpfc_readl( | |
1516 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr, | |
1517 | &uemasklo_reg); | |
1518 | /* consider PCI bus read error as pci_channel_offline */ | |
1519 | if (pci_rd_rc1 == -EIO && pci_rd_rc2 == -EIO) | |
1520 | return; | |
2fcee4bf JS |
1521 | lpfc_sli4_offline_eratt(phba); |
1522 | break; | |
1523 | case LPFC_SLI_INTF_IF_TYPE_2: | |
2e90f4b5 JS |
1524 | pci_rd_rc1 = lpfc_readl( |
1525 | phba->sli4_hba.u.if_type2.STATUSregaddr, | |
1526 | &portstat_reg.word0); | |
1527 | /* consider PCI bus read error as pci_channel_offline */ | |
6b5151fd JS |
1528 | if (pci_rd_rc1 == -EIO) { |
1529 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1530 | "3151 PCI bus read access failure: x%x\n", | |
1531 | readl(phba->sli4_hba.u.if_type2.STATUSregaddr)); | |
2e90f4b5 | 1532 | return; |
6b5151fd | 1533 | } |
2e90f4b5 JS |
1534 | reg_err1 = readl(phba->sli4_hba.u.if_type2.ERR1regaddr); |
1535 | reg_err2 = readl(phba->sli4_hba.u.if_type2.ERR2regaddr); | |
2fcee4bf JS |
1536 | if (bf_get(lpfc_sliport_status_oti, &portstat_reg)) { |
1537 | /* TODO: Register for Overtemp async events. */ | |
1538 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1539 | "2889 Port Overtemperature event, " | |
026abb87 | 1540 | "taking port offline\n"); |
2fcee4bf JS |
1541 | spin_lock_irq(&phba->hbalock); |
1542 | phba->over_temp_state = HBA_OVER_TEMP; | |
1543 | spin_unlock_irq(&phba->hbalock); | |
1544 | lpfc_sli4_offline_eratt(phba); | |
2e90f4b5 | 1545 | break; |
2fcee4bf | 1546 | } |
2e90f4b5 JS |
1547 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && |
1548 | reg_err2 == SLIPORT_ERR2_REG_FW_RESTART) | |
1549 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1550 | "3143 Port Down: Firmware Restarted\n"); | |
1551 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && | |
1552 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) | |
1553 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1554 | "3144 Port Down: Debug Dump\n"); | |
1555 | else if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && | |
1556 | reg_err2 == SLIPORT_ERR2_REG_FUNC_PROVISON) | |
1557 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
1558 | "3145 Port Down: Provisioning\n"); | |
618a5230 JS |
1559 | |
1560 | /* Check port status register for function reset */ | |
1561 | rc = lpfc_sli4_port_sta_fn_reset(phba, LPFC_MBX_NO_WAIT); | |
1562 | if (rc == 0) { | |
1563 | /* don't report event on forced debug dump */ | |
1564 | if (reg_err1 == SLIPORT_ERR1_REG_ERR_CODE_2 && | |
1565 | reg_err2 == SLIPORT_ERR2_REG_FORCED_DUMP) | |
1566 | return; | |
1567 | else | |
1568 | break; | |
2fcee4bf | 1569 | } |
618a5230 | 1570 | /* fall through for not able to recover */ |
6b5151fd JS |
1571 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
1572 | "3152 Unrecoverable error, bring the port " | |
1573 | "offline\n"); | |
2fcee4bf JS |
1574 | lpfc_sli4_offline_eratt(phba); |
1575 | break; | |
1576 | case LPFC_SLI_INTF_IF_TYPE_1: | |
1577 | default: | |
1578 | break; | |
1579 | } | |
2e90f4b5 JS |
1580 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
1581 | "3123 Report dump event to upper layer\n"); | |
1582 | /* Send an internal error event to mgmt application */ | |
1583 | lpfc_board_errevt_to_mgmt(phba); | |
1584 | ||
1585 | event_data = FC_REG_DUMP_EVENT; | |
1586 | shost = lpfc_shost_from_vport(vport); | |
1587 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
1588 | sizeof(event_data), (char *) &event_data, | |
1589 | SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); | |
da0436e9 JS |
1590 | } |
1591 | ||
1592 | /** | |
1593 | * lpfc_handle_eratt - Wrapper func for handling hba error attention | |
1594 | * @phba: pointer to lpfc HBA data structure. | |
1595 | * | |
1596 | * This routine wraps the actual SLI3 or SLI4 hba error attention handling | |
1597 | * routine from the API jump table function pointer from the lpfc_hba struct. | |
1598 | * | |
1599 | * Return codes | |
af901ca1 | 1600 | * 0 - success. |
da0436e9 JS |
1601 | * Any other value - error. |
1602 | **/ | |
1603 | void | |
1604 | lpfc_handle_eratt(struct lpfc_hba *phba) | |
1605 | { | |
1606 | (*phba->lpfc_handle_eratt)(phba); | |
1607 | } | |
1608 | ||
e59058c4 | 1609 | /** |
3621a710 | 1610 | * lpfc_handle_latt - The HBA link event handler |
e59058c4 JS |
1611 | * @phba: pointer to lpfc hba data structure. |
1612 | * | |
1613 | * This routine is invoked from the worker thread to handle a HBA host | |
1614 | * attention link event. | |
1615 | **/ | |
dea3101e | 1616 | void |
2e0fef85 | 1617 | lpfc_handle_latt(struct lpfc_hba *phba) |
dea3101e | 1618 | { |
2e0fef85 JS |
1619 | struct lpfc_vport *vport = phba->pport; |
1620 | struct lpfc_sli *psli = &phba->sli; | |
dea3101e JB |
1621 | LPFC_MBOXQ_t *pmb; |
1622 | volatile uint32_t control; | |
1623 | struct lpfc_dmabuf *mp; | |
09372820 | 1624 | int rc = 0; |
dea3101e JB |
1625 | |
1626 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
09372820 JS |
1627 | if (!pmb) { |
1628 | rc = 1; | |
dea3101e | 1629 | goto lpfc_handle_latt_err_exit; |
09372820 | 1630 | } |
dea3101e JB |
1631 | |
1632 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
09372820 JS |
1633 | if (!mp) { |
1634 | rc = 2; | |
dea3101e | 1635 | goto lpfc_handle_latt_free_pmb; |
09372820 | 1636 | } |
dea3101e JB |
1637 | |
1638 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
09372820 JS |
1639 | if (!mp->virt) { |
1640 | rc = 3; | |
dea3101e | 1641 | goto lpfc_handle_latt_free_mp; |
09372820 | 1642 | } |
dea3101e | 1643 | |
6281bfe0 | 1644 | /* Cleanup any outstanding ELS commands */ |
549e55cd | 1645 | lpfc_els_flush_all_cmd(phba); |
dea3101e JB |
1646 | |
1647 | psli->slistat.link_event++; | |
76a95d75 JS |
1648 | lpfc_read_topology(phba, pmb, mp); |
1649 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
2e0fef85 | 1650 | pmb->vport = vport; |
0d2b6b83 JS |
1651 | /* Block ELS IOCBs until we have processed this mbox command */ |
1652 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
0b727fea | 1653 | rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT); |
09372820 JS |
1654 | if (rc == MBX_NOT_FINISHED) { |
1655 | rc = 4; | |
14691150 | 1656 | goto lpfc_handle_latt_free_mbuf; |
09372820 | 1657 | } |
dea3101e JB |
1658 | |
1659 | /* Clear Link Attention in HA REG */ | |
2e0fef85 | 1660 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1661 | writel(HA_LATT, phba->HAregaddr); |
1662 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1663 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
1664 | |
1665 | return; | |
1666 | ||
14691150 | 1667 | lpfc_handle_latt_free_mbuf: |
0d2b6b83 | 1668 | phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT; |
14691150 | 1669 | lpfc_mbuf_free(phba, mp->virt, mp->phys); |
dea3101e JB |
1670 | lpfc_handle_latt_free_mp: |
1671 | kfree(mp); | |
1672 | lpfc_handle_latt_free_pmb: | |
1dcb58e5 | 1673 | mempool_free(pmb, phba->mbox_mem_pool); |
dea3101e JB |
1674 | lpfc_handle_latt_err_exit: |
1675 | /* Enable Link attention interrupts */ | |
2e0fef85 | 1676 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
1677 | psli->sli_flag |= LPFC_PROCESS_LA; |
1678 | control = readl(phba->HCregaddr); | |
1679 | control |= HC_LAINT_ENA; | |
1680 | writel(control, phba->HCregaddr); | |
1681 | readl(phba->HCregaddr); /* flush */ | |
1682 | ||
1683 | /* Clear Link Attention in HA REG */ | |
1684 | writel(HA_LATT, phba->HAregaddr); | |
1685 | readl(phba->HAregaddr); /* flush */ | |
2e0fef85 | 1686 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 1687 | lpfc_linkdown(phba); |
2e0fef85 | 1688 | phba->link_state = LPFC_HBA_ERROR; |
dea3101e | 1689 | |
09372820 JS |
1690 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
1691 | "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc); | |
dea3101e JB |
1692 | |
1693 | return; | |
1694 | } | |
1695 | ||
e59058c4 | 1696 | /** |
3621a710 | 1697 | * lpfc_parse_vpd - Parse VPD (Vital Product Data) |
e59058c4 JS |
1698 | * @phba: pointer to lpfc hba data structure. |
1699 | * @vpd: pointer to the vital product data. | |
1700 | * @len: length of the vital product data in bytes. | |
1701 | * | |
1702 | * This routine parses the Vital Product Data (VPD). The VPD is treated as | |
1703 | * an array of characters. In this routine, the ModelName, ProgramType, and | |
1704 | * ModelDesc, etc. fields of the phba data structure will be populated. | |
1705 | * | |
1706 | * Return codes | |
1707 | * 0 - pointer to the VPD passed in is NULL | |
1708 | * 1 - success | |
1709 | **/ | |
3772a991 | 1710 | int |
2e0fef85 | 1711 | lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len) |
dea3101e JB |
1712 | { |
1713 | uint8_t lenlo, lenhi; | |
07da60c1 | 1714 | int Length; |
dea3101e JB |
1715 | int i, j; |
1716 | int finished = 0; | |
1717 | int index = 0; | |
1718 | ||
1719 | if (!vpd) | |
1720 | return 0; | |
1721 | ||
1722 | /* Vital Product */ | |
ed957684 | 1723 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
e8b62011 | 1724 | "0455 Vital Product Data: x%x x%x x%x x%x\n", |
dea3101e JB |
1725 | (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], |
1726 | (uint32_t) vpd[3]); | |
74b72a59 | 1727 | while (!finished && (index < (len - 4))) { |
dea3101e JB |
1728 | switch (vpd[index]) { |
1729 | case 0x82: | |
74b72a59 | 1730 | case 0x91: |
dea3101e JB |
1731 | index += 1; |
1732 | lenlo = vpd[index]; | |
1733 | index += 1; | |
1734 | lenhi = vpd[index]; | |
1735 | index += 1; | |
1736 | i = ((((unsigned short)lenhi) << 8) + lenlo); | |
1737 | index += i; | |
1738 | break; | |
1739 | case 0x90: | |
1740 | index += 1; | |
1741 | lenlo = vpd[index]; | |
1742 | index += 1; | |
1743 | lenhi = vpd[index]; | |
1744 | index += 1; | |
1745 | Length = ((((unsigned short)lenhi) << 8) + lenlo); | |
74b72a59 JW |
1746 | if (Length > len - index) |
1747 | Length = len - index; | |
dea3101e JB |
1748 | while (Length > 0) { |
1749 | /* Look for Serial Number */ | |
1750 | if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) { | |
1751 | index += 2; | |
1752 | i = vpd[index]; | |
1753 | index += 1; | |
1754 | j = 0; | |
1755 | Length -= (3+i); | |
1756 | while(i--) { | |
1757 | phba->SerialNumber[j++] = vpd[index++]; | |
1758 | if (j == 31) | |
1759 | break; | |
1760 | } | |
1761 | phba->SerialNumber[j] = 0; | |
1762 | continue; | |
1763 | } | |
1764 | else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) { | |
1765 | phba->vpd_flag |= VPD_MODEL_DESC; | |
1766 | index += 2; | |
1767 | i = vpd[index]; | |
1768 | index += 1; | |
1769 | j = 0; | |
1770 | Length -= (3+i); | |
1771 | while(i--) { | |
1772 | phba->ModelDesc[j++] = vpd[index++]; | |
1773 | if (j == 255) | |
1774 | break; | |
1775 | } | |
1776 | phba->ModelDesc[j] = 0; | |
1777 | continue; | |
1778 | } | |
1779 | else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) { | |
1780 | phba->vpd_flag |= VPD_MODEL_NAME; | |
1781 | index += 2; | |
1782 | i = vpd[index]; | |
1783 | index += 1; | |
1784 | j = 0; | |
1785 | Length -= (3+i); | |
1786 | while(i--) { | |
1787 | phba->ModelName[j++] = vpd[index++]; | |
1788 | if (j == 79) | |
1789 | break; | |
1790 | } | |
1791 | phba->ModelName[j] = 0; | |
1792 | continue; | |
1793 | } | |
1794 | else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) { | |
1795 | phba->vpd_flag |= VPD_PROGRAM_TYPE; | |
1796 | index += 2; | |
1797 | i = vpd[index]; | |
1798 | index += 1; | |
1799 | j = 0; | |
1800 | Length -= (3+i); | |
1801 | while(i--) { | |
1802 | phba->ProgramType[j++] = vpd[index++]; | |
1803 | if (j == 255) | |
1804 | break; | |
1805 | } | |
1806 | phba->ProgramType[j] = 0; | |
1807 | continue; | |
1808 | } | |
1809 | else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) { | |
1810 | phba->vpd_flag |= VPD_PORT; | |
1811 | index += 2; | |
1812 | i = vpd[index]; | |
1813 | index += 1; | |
1814 | j = 0; | |
1815 | Length -= (3+i); | |
1816 | while(i--) { | |
cd1c8301 JS |
1817 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
1818 | (phba->sli4_hba.pport_name_sta == | |
1819 | LPFC_SLI4_PPNAME_GET)) { | |
1820 | j++; | |
1821 | index++; | |
1822 | } else | |
1823 | phba->Port[j++] = vpd[index++]; | |
1824 | if (j == 19) | |
1825 | break; | |
dea3101e | 1826 | } |
cd1c8301 JS |
1827 | if ((phba->sli_rev != LPFC_SLI_REV4) || |
1828 | (phba->sli4_hba.pport_name_sta == | |
1829 | LPFC_SLI4_PPNAME_NON)) | |
1830 | phba->Port[j] = 0; | |
dea3101e JB |
1831 | continue; |
1832 | } | |
1833 | else { | |
1834 | index += 2; | |
1835 | i = vpd[index]; | |
1836 | index += 1; | |
1837 | index += i; | |
1838 | Length -= (3 + i); | |
1839 | } | |
1840 | } | |
1841 | finished = 0; | |
1842 | break; | |
1843 | case 0x78: | |
1844 | finished = 1; | |
1845 | break; | |
1846 | default: | |
1847 | index ++; | |
1848 | break; | |
1849 | } | |
74b72a59 | 1850 | } |
dea3101e JB |
1851 | |
1852 | return(1); | |
1853 | } | |
1854 | ||
e59058c4 | 1855 | /** |
3621a710 | 1856 | * lpfc_get_hba_model_desc - Retrieve HBA device model name and description |
e59058c4 JS |
1857 | * @phba: pointer to lpfc hba data structure. |
1858 | * @mdp: pointer to the data structure to hold the derived model name. | |
1859 | * @descp: pointer to the data structure to hold the derived description. | |
1860 | * | |
1861 | * This routine retrieves HBA's description based on its registered PCI device | |
1862 | * ID. The @descp passed into this function points to an array of 256 chars. It | |
1863 | * shall be returned with the model name, maximum speed, and the host bus type. | |
1864 | * The @mdp passed into this function points to an array of 80 chars. When the | |
1865 | * function returns, the @mdp will be filled with the model name. | |
1866 | **/ | |
dea3101e | 1867 | static void |
2e0fef85 | 1868 | lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp) |
dea3101e JB |
1869 | { |
1870 | lpfc_vpd_t *vp; | |
fefcb2b6 | 1871 | uint16_t dev_id = phba->pcidev->device; |
74b72a59 | 1872 | int max_speed; |
84774a4d | 1873 | int GE = 0; |
da0436e9 | 1874 | int oneConnect = 0; /* default is not a oneConnect */ |
74b72a59 | 1875 | struct { |
a747c9ce JS |
1876 | char *name; |
1877 | char *bus; | |
1878 | char *function; | |
1879 | } m = {"<Unknown>", "", ""}; | |
74b72a59 JW |
1880 | |
1881 | if (mdp && mdp[0] != '\0' | |
1882 | && descp && descp[0] != '\0') | |
1883 | return; | |
1884 | ||
c0c11512 JS |
1885 | if (phba->lmt & LMT_16Gb) |
1886 | max_speed = 16; | |
1887 | else if (phba->lmt & LMT_10Gb) | |
74b72a59 JW |
1888 | max_speed = 10; |
1889 | else if (phba->lmt & LMT_8Gb) | |
1890 | max_speed = 8; | |
1891 | else if (phba->lmt & LMT_4Gb) | |
1892 | max_speed = 4; | |
1893 | else if (phba->lmt & LMT_2Gb) | |
1894 | max_speed = 2; | |
1895 | else | |
1896 | max_speed = 1; | |
dea3101e JB |
1897 | |
1898 | vp = &phba->vpd; | |
dea3101e | 1899 | |
e4adb204 | 1900 | switch (dev_id) { |
06325e74 | 1901 | case PCI_DEVICE_ID_FIREFLY: |
a747c9ce | 1902 | m = (typeof(m)){"LP6000", "PCI", "Fibre Channel Adapter"}; |
06325e74 | 1903 | break; |
dea3101e JB |
1904 | case PCI_DEVICE_ID_SUPERFLY: |
1905 | if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3) | |
a747c9ce JS |
1906 | m = (typeof(m)){"LP7000", "PCI", |
1907 | "Fibre Channel Adapter"}; | |
dea3101e | 1908 | else |
a747c9ce JS |
1909 | m = (typeof(m)){"LP7000E", "PCI", |
1910 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1911 | break; |
1912 | case PCI_DEVICE_ID_DRAGONFLY: | |
a747c9ce JS |
1913 | m = (typeof(m)){"LP8000", "PCI", |
1914 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1915 | break; |
1916 | case PCI_DEVICE_ID_CENTAUR: | |
1917 | if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID) | |
a747c9ce JS |
1918 | m = (typeof(m)){"LP9002", "PCI", |
1919 | "Fibre Channel Adapter"}; | |
dea3101e | 1920 | else |
a747c9ce JS |
1921 | m = (typeof(m)){"LP9000", "PCI", |
1922 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1923 | break; |
1924 | case PCI_DEVICE_ID_RFLY: | |
a747c9ce JS |
1925 | m = (typeof(m)){"LP952", "PCI", |
1926 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1927 | break; |
1928 | case PCI_DEVICE_ID_PEGASUS: | |
a747c9ce JS |
1929 | m = (typeof(m)){"LP9802", "PCI-X", |
1930 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1931 | break; |
1932 | case PCI_DEVICE_ID_THOR: | |
a747c9ce JS |
1933 | m = (typeof(m)){"LP10000", "PCI-X", |
1934 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1935 | break; |
1936 | case PCI_DEVICE_ID_VIPER: | |
a747c9ce JS |
1937 | m = (typeof(m)){"LPX1000", "PCI-X", |
1938 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1939 | break; |
1940 | case PCI_DEVICE_ID_PFLY: | |
a747c9ce JS |
1941 | m = (typeof(m)){"LP982", "PCI-X", |
1942 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1943 | break; |
1944 | case PCI_DEVICE_ID_TFLY: | |
a747c9ce JS |
1945 | m = (typeof(m)){"LP1050", "PCI-X", |
1946 | "Fibre Channel Adapter"}; | |
dea3101e JB |
1947 | break; |
1948 | case PCI_DEVICE_ID_HELIOS: | |
a747c9ce JS |
1949 | m = (typeof(m)){"LP11000", "PCI-X2", |
1950 | "Fibre Channel Adapter"}; | |
dea3101e | 1951 | break; |
e4adb204 | 1952 | case PCI_DEVICE_ID_HELIOS_SCSP: |
a747c9ce JS |
1953 | m = (typeof(m)){"LP11000-SP", "PCI-X2", |
1954 | "Fibre Channel Adapter"}; | |
e4adb204 JSEC |
1955 | break; |
1956 | case PCI_DEVICE_ID_HELIOS_DCSP: | |
a747c9ce JS |
1957 | m = (typeof(m)){"LP11002-SP", "PCI-X2", |
1958 | "Fibre Channel Adapter"}; | |
e4adb204 JSEC |
1959 | break; |
1960 | case PCI_DEVICE_ID_NEPTUNE: | |
a747c9ce | 1961 | m = (typeof(m)){"LPe1000", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1962 | break; |
1963 | case PCI_DEVICE_ID_NEPTUNE_SCSP: | |
a747c9ce | 1964 | m = (typeof(m)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1965 | break; |
1966 | case PCI_DEVICE_ID_NEPTUNE_DCSP: | |
a747c9ce | 1967 | m = (typeof(m)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 | 1968 | break; |
dea3101e | 1969 | case PCI_DEVICE_ID_BMID: |
a747c9ce | 1970 | m = (typeof(m)){"LP1150", "PCI-X2", "Fibre Channel Adapter"}; |
dea3101e JB |
1971 | break; |
1972 | case PCI_DEVICE_ID_BSMB: | |
a747c9ce | 1973 | m = (typeof(m)){"LP111", "PCI-X2", "Fibre Channel Adapter"}; |
dea3101e JB |
1974 | break; |
1975 | case PCI_DEVICE_ID_ZEPHYR: | |
a747c9ce | 1976 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
dea3101e | 1977 | break; |
e4adb204 | 1978 | case PCI_DEVICE_ID_ZEPHYR_SCSP: |
a747c9ce | 1979 | m = (typeof(m)){"LPe11000", "PCIe", "Fibre Channel Adapter"}; |
e4adb204 JSEC |
1980 | break; |
1981 | case PCI_DEVICE_ID_ZEPHYR_DCSP: | |
a747c9ce | 1982 | m = (typeof(m)){"LP2105", "PCIe", "FCoE Adapter"}; |
a257bf90 | 1983 | GE = 1; |
e4adb204 | 1984 | break; |
dea3101e | 1985 | case PCI_DEVICE_ID_ZMID: |
a747c9ce | 1986 | m = (typeof(m)){"LPe1150", "PCIe", "Fibre Channel Adapter"}; |
dea3101e JB |
1987 | break; |
1988 | case PCI_DEVICE_ID_ZSMB: | |
a747c9ce | 1989 | m = (typeof(m)){"LPe111", "PCIe", "Fibre Channel Adapter"}; |
dea3101e JB |
1990 | break; |
1991 | case PCI_DEVICE_ID_LP101: | |
a747c9ce | 1992 | m = (typeof(m)){"LP101", "PCI-X", "Fibre Channel Adapter"}; |
dea3101e JB |
1993 | break; |
1994 | case PCI_DEVICE_ID_LP10000S: | |
a747c9ce | 1995 | m = (typeof(m)){"LP10000-S", "PCI", "Fibre Channel Adapter"}; |
06325e74 | 1996 | break; |
e4adb204 | 1997 | case PCI_DEVICE_ID_LP11000S: |
a747c9ce | 1998 | m = (typeof(m)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"}; |
18a3b596 | 1999 | break; |
e4adb204 | 2000 | case PCI_DEVICE_ID_LPE11000S: |
a747c9ce | 2001 | m = (typeof(m)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"}; |
5cc36b3c | 2002 | break; |
b87eab38 | 2003 | case PCI_DEVICE_ID_SAT: |
a747c9ce | 2004 | m = (typeof(m)){"LPe12000", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
2005 | break; |
2006 | case PCI_DEVICE_ID_SAT_MID: | |
a747c9ce | 2007 | m = (typeof(m)){"LPe1250", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
2008 | break; |
2009 | case PCI_DEVICE_ID_SAT_SMB: | |
a747c9ce | 2010 | m = (typeof(m)){"LPe121", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
2011 | break; |
2012 | case PCI_DEVICE_ID_SAT_DCSP: | |
a747c9ce | 2013 | m = (typeof(m)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
2014 | break; |
2015 | case PCI_DEVICE_ID_SAT_SCSP: | |
a747c9ce | 2016 | m = (typeof(m)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 JS |
2017 | break; |
2018 | case PCI_DEVICE_ID_SAT_S: | |
a747c9ce | 2019 | m = (typeof(m)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"}; |
b87eab38 | 2020 | break; |
84774a4d | 2021 | case PCI_DEVICE_ID_HORNET: |
a747c9ce | 2022 | m = (typeof(m)){"LP21000", "PCIe", "FCoE Adapter"}; |
84774a4d JS |
2023 | GE = 1; |
2024 | break; | |
2025 | case PCI_DEVICE_ID_PROTEUS_VF: | |
a747c9ce JS |
2026 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
2027 | "Fibre Channel Adapter"}; | |
84774a4d JS |
2028 | break; |
2029 | case PCI_DEVICE_ID_PROTEUS_PF: | |
a747c9ce JS |
2030 | m = (typeof(m)){"LPev12000", "PCIe IOV", |
2031 | "Fibre Channel Adapter"}; | |
84774a4d JS |
2032 | break; |
2033 | case PCI_DEVICE_ID_PROTEUS_S: | |
a747c9ce JS |
2034 | m = (typeof(m)){"LPemv12002-S", "PCIe IOV", |
2035 | "Fibre Channel Adapter"}; | |
84774a4d | 2036 | break; |
da0436e9 JS |
2037 | case PCI_DEVICE_ID_TIGERSHARK: |
2038 | oneConnect = 1; | |
a747c9ce | 2039 | m = (typeof(m)){"OCe10100", "PCIe", "FCoE"}; |
da0436e9 | 2040 | break; |
a747c9ce | 2041 | case PCI_DEVICE_ID_TOMCAT: |
6669f9bb | 2042 | oneConnect = 1; |
a747c9ce JS |
2043 | m = (typeof(m)){"OCe11100", "PCIe", "FCoE"}; |
2044 | break; | |
2045 | case PCI_DEVICE_ID_FALCON: | |
2046 | m = (typeof(m)){"LPSe12002-ML1-E", "PCIe", | |
2047 | "EmulexSecure Fibre"}; | |
6669f9bb | 2048 | break; |
98fc5dd9 JS |
2049 | case PCI_DEVICE_ID_BALIUS: |
2050 | m = (typeof(m)){"LPVe12002", "PCIe Shared I/O", | |
2051 | "Fibre Channel Adapter"}; | |
2052 | break; | |
085c647c | 2053 | case PCI_DEVICE_ID_LANCER_FC: |
c0c11512 JS |
2054 | case PCI_DEVICE_ID_LANCER_FC_VF: |
2055 | m = (typeof(m)){"LPe16000", "PCIe", "Fibre Channel Adapter"}; | |
085c647c JS |
2056 | break; |
2057 | case PCI_DEVICE_ID_LANCER_FCOE: | |
c0c11512 | 2058 | case PCI_DEVICE_ID_LANCER_FCOE_VF: |
085c647c | 2059 | oneConnect = 1; |
079b5c91 | 2060 | m = (typeof(m)){"OCe15100", "PCIe", "FCoE"}; |
085c647c | 2061 | break; |
f8cafd38 JS |
2062 | case PCI_DEVICE_ID_SKYHAWK: |
2063 | case PCI_DEVICE_ID_SKYHAWK_VF: | |
2064 | oneConnect = 1; | |
2065 | m = (typeof(m)){"OCe14000", "PCIe", "FCoE"}; | |
2066 | break; | |
5cc36b3c | 2067 | default: |
a747c9ce | 2068 | m = (typeof(m)){"Unknown", "", ""}; |
e4adb204 | 2069 | break; |
dea3101e | 2070 | } |
74b72a59 JW |
2071 | |
2072 | if (mdp && mdp[0] == '\0') | |
2073 | snprintf(mdp, 79,"%s", m.name); | |
c0c11512 JS |
2074 | /* |
2075 | * oneConnect hba requires special processing, they are all initiators | |
da0436e9 JS |
2076 | * and we put the port number on the end |
2077 | */ | |
2078 | if (descp && descp[0] == '\0') { | |
2079 | if (oneConnect) | |
2080 | snprintf(descp, 255, | |
a747c9ce JS |
2081 | "Emulex OneConnect %s, %s Initiator, Port %s", |
2082 | m.name, m.function, | |
da0436e9 JS |
2083 | phba->Port); |
2084 | else | |
2085 | snprintf(descp, 255, | |
2086 | "Emulex %s %d%s %s %s", | |
a747c9ce JS |
2087 | m.name, max_speed, (GE) ? "GE" : "Gb", |
2088 | m.bus, m.function); | |
da0436e9 | 2089 | } |
dea3101e JB |
2090 | } |
2091 | ||
e59058c4 | 2092 | /** |
3621a710 | 2093 | * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring |
e59058c4 JS |
2094 | * @phba: pointer to lpfc hba data structure. |
2095 | * @pring: pointer to a IOCB ring. | |
2096 | * @cnt: the number of IOCBs to be posted to the IOCB ring. | |
2097 | * | |
2098 | * This routine posts a given number of IOCBs with the associated DMA buffer | |
2099 | * descriptors specified by the cnt argument to the given IOCB ring. | |
2100 | * | |
2101 | * Return codes | |
2102 | * The number of IOCBs NOT able to be posted to the IOCB ring. | |
2103 | **/ | |
dea3101e | 2104 | int |
495a714c | 2105 | lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt) |
dea3101e JB |
2106 | { |
2107 | IOCB_t *icmd; | |
0bd4ca25 | 2108 | struct lpfc_iocbq *iocb; |
dea3101e JB |
2109 | struct lpfc_dmabuf *mp1, *mp2; |
2110 | ||
2111 | cnt += pring->missbufcnt; | |
2112 | ||
2113 | /* While there are buffers to post */ | |
2114 | while (cnt > 0) { | |
2115 | /* Allocate buffer for command iocb */ | |
0bd4ca25 | 2116 | iocb = lpfc_sli_get_iocbq(phba); |
dea3101e JB |
2117 | if (iocb == NULL) { |
2118 | pring->missbufcnt = cnt; | |
2119 | return cnt; | |
2120 | } | |
dea3101e JB |
2121 | icmd = &iocb->iocb; |
2122 | ||
2123 | /* 2 buffers can be posted per command */ | |
2124 | /* Allocate buffer to post */ | |
2125 | mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
2126 | if (mp1) | |
98c9ea5c JS |
2127 | mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys); |
2128 | if (!mp1 || !mp1->virt) { | |
c9475cb0 | 2129 | kfree(mp1); |
604a3e30 | 2130 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
2131 | pring->missbufcnt = cnt; |
2132 | return cnt; | |
2133 | } | |
2134 | ||
2135 | INIT_LIST_HEAD(&mp1->list); | |
2136 | /* Allocate buffer to post */ | |
2137 | if (cnt > 1) { | |
2138 | mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); | |
2139 | if (mp2) | |
2140 | mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI, | |
2141 | &mp2->phys); | |
98c9ea5c | 2142 | if (!mp2 || !mp2->virt) { |
c9475cb0 | 2143 | kfree(mp2); |
dea3101e JB |
2144 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
2145 | kfree(mp1); | |
604a3e30 | 2146 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e JB |
2147 | pring->missbufcnt = cnt; |
2148 | return cnt; | |
2149 | } | |
2150 | ||
2151 | INIT_LIST_HEAD(&mp2->list); | |
2152 | } else { | |
2153 | mp2 = NULL; | |
2154 | } | |
2155 | ||
2156 | icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys); | |
2157 | icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys); | |
2158 | icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE; | |
2159 | icmd->ulpBdeCount = 1; | |
2160 | cnt--; | |
2161 | if (mp2) { | |
2162 | icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys); | |
2163 | icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys); | |
2164 | icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE; | |
2165 | cnt--; | |
2166 | icmd->ulpBdeCount = 2; | |
2167 | } | |
2168 | ||
2169 | icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; | |
2170 | icmd->ulpLe = 1; | |
2171 | ||
3772a991 JS |
2172 | if (lpfc_sli_issue_iocb(phba, pring->ringno, iocb, 0) == |
2173 | IOCB_ERROR) { | |
dea3101e JB |
2174 | lpfc_mbuf_free(phba, mp1->virt, mp1->phys); |
2175 | kfree(mp1); | |
2176 | cnt++; | |
2177 | if (mp2) { | |
2178 | lpfc_mbuf_free(phba, mp2->virt, mp2->phys); | |
2179 | kfree(mp2); | |
2180 | cnt++; | |
2181 | } | |
604a3e30 | 2182 | lpfc_sli_release_iocbq(phba, iocb); |
dea3101e | 2183 | pring->missbufcnt = cnt; |
dea3101e JB |
2184 | return cnt; |
2185 | } | |
dea3101e | 2186 | lpfc_sli_ringpostbuf_put(phba, pring, mp1); |
92d7f7b0 | 2187 | if (mp2) |
dea3101e | 2188 | lpfc_sli_ringpostbuf_put(phba, pring, mp2); |
dea3101e JB |
2189 | } |
2190 | pring->missbufcnt = 0; | |
2191 | return 0; | |
2192 | } | |
2193 | ||
e59058c4 | 2194 | /** |
3621a710 | 2195 | * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring |
e59058c4 JS |
2196 | * @phba: pointer to lpfc hba data structure. |
2197 | * | |
2198 | * This routine posts initial receive IOCB buffers to the ELS ring. The | |
2199 | * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is | |
2200 | * set to 64 IOCBs. | |
2201 | * | |
2202 | * Return codes | |
2203 | * 0 - success (currently always success) | |
2204 | **/ | |
dea3101e | 2205 | static int |
2e0fef85 | 2206 | lpfc_post_rcv_buf(struct lpfc_hba *phba) |
dea3101e JB |
2207 | { |
2208 | struct lpfc_sli *psli = &phba->sli; | |
2209 | ||
2210 | /* Ring 0, ELS / CT buffers */ | |
495a714c | 2211 | lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0); |
dea3101e JB |
2212 | /* Ring 2 - FCP no buffers needed */ |
2213 | ||
2214 | return 0; | |
2215 | } | |
2216 | ||
2217 | #define S(N,V) (((V)<<(N))|((V)>>(32-(N)))) | |
2218 | ||
e59058c4 | 2219 | /** |
3621a710 | 2220 | * lpfc_sha_init - Set up initial array of hash table entries |
e59058c4 JS |
2221 | * @HashResultPointer: pointer to an array as hash table. |
2222 | * | |
2223 | * This routine sets up the initial values to the array of hash table entries | |
2224 | * for the LC HBAs. | |
2225 | **/ | |
dea3101e JB |
2226 | static void |
2227 | lpfc_sha_init(uint32_t * HashResultPointer) | |
2228 | { | |
2229 | HashResultPointer[0] = 0x67452301; | |
2230 | HashResultPointer[1] = 0xEFCDAB89; | |
2231 | HashResultPointer[2] = 0x98BADCFE; | |
2232 | HashResultPointer[3] = 0x10325476; | |
2233 | HashResultPointer[4] = 0xC3D2E1F0; | |
2234 | } | |
2235 | ||
e59058c4 | 2236 | /** |
3621a710 | 2237 | * lpfc_sha_iterate - Iterate initial hash table with the working hash table |
e59058c4 JS |
2238 | * @HashResultPointer: pointer to an initial/result hash table. |
2239 | * @HashWorkingPointer: pointer to an working hash table. | |
2240 | * | |
2241 | * This routine iterates an initial hash table pointed by @HashResultPointer | |
2242 | * with the values from the working hash table pointeed by @HashWorkingPointer. | |
2243 | * The results are putting back to the initial hash table, returned through | |
2244 | * the @HashResultPointer as the result hash table. | |
2245 | **/ | |
dea3101e JB |
2246 | static void |
2247 | lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer) | |
2248 | { | |
2249 | int t; | |
2250 | uint32_t TEMP; | |
2251 | uint32_t A, B, C, D, E; | |
2252 | t = 16; | |
2253 | do { | |
2254 | HashWorkingPointer[t] = | |
2255 | S(1, | |
2256 | HashWorkingPointer[t - 3] ^ HashWorkingPointer[t - | |
2257 | 8] ^ | |
2258 | HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]); | |
2259 | } while (++t <= 79); | |
2260 | t = 0; | |
2261 | A = HashResultPointer[0]; | |
2262 | B = HashResultPointer[1]; | |
2263 | C = HashResultPointer[2]; | |
2264 | D = HashResultPointer[3]; | |
2265 | E = HashResultPointer[4]; | |
2266 | ||
2267 | do { | |
2268 | if (t < 20) { | |
2269 | TEMP = ((B & C) | ((~B) & D)) + 0x5A827999; | |
2270 | } else if (t < 40) { | |
2271 | TEMP = (B ^ C ^ D) + 0x6ED9EBA1; | |
2272 | } else if (t < 60) { | |
2273 | TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC; | |
2274 | } else { | |
2275 | TEMP = (B ^ C ^ D) + 0xCA62C1D6; | |
2276 | } | |
2277 | TEMP += S(5, A) + E + HashWorkingPointer[t]; | |
2278 | E = D; | |
2279 | D = C; | |
2280 | C = S(30, B); | |
2281 | B = A; | |
2282 | A = TEMP; | |
2283 | } while (++t <= 79); | |
2284 | ||
2285 | HashResultPointer[0] += A; | |
2286 | HashResultPointer[1] += B; | |
2287 | HashResultPointer[2] += C; | |
2288 | HashResultPointer[3] += D; | |
2289 | HashResultPointer[4] += E; | |
2290 | ||
2291 | } | |
2292 | ||
e59058c4 | 2293 | /** |
3621a710 | 2294 | * lpfc_challenge_key - Create challenge key based on WWPN of the HBA |
e59058c4 JS |
2295 | * @RandomChallenge: pointer to the entry of host challenge random number array. |
2296 | * @HashWorking: pointer to the entry of the working hash array. | |
2297 | * | |
2298 | * This routine calculates the working hash array referred by @HashWorking | |
2299 | * from the challenge random numbers associated with the host, referred by | |
2300 | * @RandomChallenge. The result is put into the entry of the working hash | |
2301 | * array and returned by reference through @HashWorking. | |
2302 | **/ | |
dea3101e JB |
2303 | static void |
2304 | lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking) | |
2305 | { | |
2306 | *HashWorking = (*RandomChallenge ^ *HashWorking); | |
2307 | } | |
2308 | ||
e59058c4 | 2309 | /** |
3621a710 | 2310 | * lpfc_hba_init - Perform special handling for LC HBA initialization |
e59058c4 JS |
2311 | * @phba: pointer to lpfc hba data structure. |
2312 | * @hbainit: pointer to an array of unsigned 32-bit integers. | |
2313 | * | |
2314 | * This routine performs the special handling for LC HBA initialization. | |
2315 | **/ | |
dea3101e JB |
2316 | void |
2317 | lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit) | |
2318 | { | |
2319 | int t; | |
2320 | uint32_t *HashWorking; | |
2e0fef85 | 2321 | uint32_t *pwwnn = (uint32_t *) phba->wwnn; |
dea3101e | 2322 | |
bbfbbbc1 | 2323 | HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL); |
dea3101e JB |
2324 | if (!HashWorking) |
2325 | return; | |
2326 | ||
dea3101e JB |
2327 | HashWorking[0] = HashWorking[78] = *pwwnn++; |
2328 | HashWorking[1] = HashWorking[79] = *pwwnn; | |
2329 | ||
2330 | for (t = 0; t < 7; t++) | |
2331 | lpfc_challenge_key(phba->RandomData + t, HashWorking + t); | |
2332 | ||
2333 | lpfc_sha_init(hbainit); | |
2334 | lpfc_sha_iterate(hbainit, HashWorking); | |
2335 | kfree(HashWorking); | |
2336 | } | |
2337 | ||
e59058c4 | 2338 | /** |
3621a710 | 2339 | * lpfc_cleanup - Performs vport cleanups before deleting a vport |
e59058c4 JS |
2340 | * @vport: pointer to a virtual N_Port data structure. |
2341 | * | |
2342 | * This routine performs the necessary cleanups before deleting the @vport. | |
2343 | * It invokes the discovery state machine to perform necessary state | |
2344 | * transitions and to release the ndlps associated with the @vport. Note, | |
2345 | * the physical port is treated as @vport 0. | |
2346 | **/ | |
87af33fe | 2347 | void |
2e0fef85 | 2348 | lpfc_cleanup(struct lpfc_vport *vport) |
dea3101e | 2349 | { |
87af33fe | 2350 | struct lpfc_hba *phba = vport->phba; |
dea3101e | 2351 | struct lpfc_nodelist *ndlp, *next_ndlp; |
a8adb832 | 2352 | int i = 0; |
dea3101e | 2353 | |
87af33fe JS |
2354 | if (phba->link_state > LPFC_LINK_DOWN) |
2355 | lpfc_port_link_failure(vport); | |
2356 | ||
2357 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
e47c9093 JS |
2358 | if (!NLP_CHK_NODE_ACT(ndlp)) { |
2359 | ndlp = lpfc_enable_node(vport, ndlp, | |
2360 | NLP_STE_UNUSED_NODE); | |
2361 | if (!ndlp) | |
2362 | continue; | |
2363 | spin_lock_irq(&phba->ndlp_lock); | |
2364 | NLP_SET_FREE_REQ(ndlp); | |
2365 | spin_unlock_irq(&phba->ndlp_lock); | |
2366 | /* Trigger the release of the ndlp memory */ | |
2367 | lpfc_nlp_put(ndlp); | |
2368 | continue; | |
2369 | } | |
2370 | spin_lock_irq(&phba->ndlp_lock); | |
2371 | if (NLP_CHK_FREE_REQ(ndlp)) { | |
2372 | /* The ndlp should not be in memory free mode already */ | |
2373 | spin_unlock_irq(&phba->ndlp_lock); | |
2374 | continue; | |
2375 | } else | |
2376 | /* Indicate request for freeing ndlp memory */ | |
2377 | NLP_SET_FREE_REQ(ndlp); | |
2378 | spin_unlock_irq(&phba->ndlp_lock); | |
2379 | ||
58da1ffb JS |
2380 | if (vport->port_type != LPFC_PHYSICAL_PORT && |
2381 | ndlp->nlp_DID == Fabric_DID) { | |
2382 | /* Just free up ndlp with Fabric_DID for vports */ | |
2383 | lpfc_nlp_put(ndlp); | |
2384 | continue; | |
2385 | } | |
2386 | ||
eff4a01b JS |
2387 | /* take care of nodes in unused state before the state |
2388 | * machine taking action. | |
2389 | */ | |
2390 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) { | |
2391 | lpfc_nlp_put(ndlp); | |
2392 | continue; | |
2393 | } | |
2394 | ||
87af33fe JS |
2395 | if (ndlp->nlp_type & NLP_FABRIC) |
2396 | lpfc_disc_state_machine(vport, ndlp, NULL, | |
2397 | NLP_EVT_DEVICE_RECOVERY); | |
e47c9093 | 2398 | |
87af33fe JS |
2399 | lpfc_disc_state_machine(vport, ndlp, NULL, |
2400 | NLP_EVT_DEVICE_RM); | |
2401 | } | |
2402 | ||
a8adb832 JS |
2403 | /* At this point, ALL ndlp's should be gone |
2404 | * because of the previous NLP_EVT_DEVICE_RM. | |
2405 | * Lets wait for this to happen, if needed. | |
2406 | */ | |
87af33fe | 2407 | while (!list_empty(&vport->fc_nodes)) { |
a8adb832 | 2408 | if (i++ > 3000) { |
87af33fe | 2409 | lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY, |
a8adb832 | 2410 | "0233 Nodelist not empty\n"); |
e47c9093 JS |
2411 | list_for_each_entry_safe(ndlp, next_ndlp, |
2412 | &vport->fc_nodes, nlp_listp) { | |
2413 | lpfc_printf_vlog(ndlp->vport, KERN_ERR, | |
2414 | LOG_NODE, | |
d7c255b2 | 2415 | "0282 did:x%x ndlp:x%p " |
e47c9093 JS |
2416 | "usgmap:x%x refcnt:%d\n", |
2417 | ndlp->nlp_DID, (void *)ndlp, | |
2418 | ndlp->nlp_usg_map, | |
2419 | atomic_read( | |
2420 | &ndlp->kref.refcount)); | |
2421 | } | |
a8adb832 | 2422 | break; |
87af33fe | 2423 | } |
a8adb832 JS |
2424 | |
2425 | /* Wait for any activity on ndlps to settle */ | |
2426 | msleep(10); | |
87af33fe | 2427 | } |
1151e3ec | 2428 | lpfc_cleanup_vports_rrqs(vport, NULL); |
dea3101e JB |
2429 | } |
2430 | ||
e59058c4 | 2431 | /** |
3621a710 | 2432 | * lpfc_stop_vport_timers - Stop all the timers associated with a vport |
e59058c4 JS |
2433 | * @vport: pointer to a virtual N_Port data structure. |
2434 | * | |
2435 | * This routine stops all the timers associated with a @vport. This function | |
2436 | * is invoked before disabling or deleting a @vport. Note that the physical | |
2437 | * port is treated as @vport 0. | |
2438 | **/ | |
92d7f7b0 JS |
2439 | void |
2440 | lpfc_stop_vport_timers(struct lpfc_vport *vport) | |
dea3101e | 2441 | { |
92d7f7b0 JS |
2442 | del_timer_sync(&vport->els_tmofunc); |
2443 | del_timer_sync(&vport->fc_fdmitmo); | |
92494144 | 2444 | del_timer_sync(&vport->delayed_disc_tmo); |
92d7f7b0 JS |
2445 | lpfc_can_disctmo(vport); |
2446 | return; | |
dea3101e JB |
2447 | } |
2448 | ||
ecfd03c6 JS |
2449 | /** |
2450 | * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2451 | * @phba: pointer to lpfc hba data structure. | |
2452 | * | |
2453 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. The | |
2454 | * caller of this routine should already hold the host lock. | |
2455 | **/ | |
2456 | void | |
2457 | __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2458 | { | |
5ac6b303 JS |
2459 | /* Clear pending FCF rediscovery wait flag */ |
2460 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; | |
2461 | ||
ecfd03c6 JS |
2462 | /* Now, try to stop the timer */ |
2463 | del_timer(&phba->fcf.redisc_wait); | |
2464 | } | |
2465 | ||
2466 | /** | |
2467 | * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer | |
2468 | * @phba: pointer to lpfc hba data structure. | |
2469 | * | |
2470 | * This routine stops the SLI4 FCF rediscover wait timer if it's on. It | |
2471 | * checks whether the FCF rediscovery wait timer is pending with the host | |
2472 | * lock held before proceeding with disabling the timer and clearing the | |
2473 | * wait timer pendig flag. | |
2474 | **/ | |
2475 | void | |
2476 | lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba *phba) | |
2477 | { | |
2478 | spin_lock_irq(&phba->hbalock); | |
2479 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
2480 | /* FCF rediscovery timer already fired or stopped */ | |
2481 | spin_unlock_irq(&phba->hbalock); | |
2482 | return; | |
2483 | } | |
2484 | __lpfc_sli4_stop_fcf_redisc_wait_timer(phba); | |
5ac6b303 JS |
2485 | /* Clear failover in progress flags */ |
2486 | phba->fcf.fcf_flag &= ~(FCF_DEAD_DISC | FCF_ACVL_DISC); | |
ecfd03c6 JS |
2487 | spin_unlock_irq(&phba->hbalock); |
2488 | } | |
2489 | ||
e59058c4 | 2490 | /** |
3772a991 | 2491 | * lpfc_stop_hba_timers - Stop all the timers associated with an HBA |
e59058c4 JS |
2492 | * @phba: pointer to lpfc hba data structure. |
2493 | * | |
2494 | * This routine stops all the timers associated with a HBA. This function is | |
2495 | * invoked before either putting a HBA offline or unloading the driver. | |
2496 | **/ | |
3772a991 JS |
2497 | void |
2498 | lpfc_stop_hba_timers(struct lpfc_hba *phba) | |
dea3101e | 2499 | { |
51ef4c26 | 2500 | lpfc_stop_vport_timers(phba->pport); |
2e0fef85 | 2501 | del_timer_sync(&phba->sli.mbox_tmo); |
92d7f7b0 | 2502 | del_timer_sync(&phba->fabric_block_timer); |
9399627f | 2503 | del_timer_sync(&phba->eratt_poll); |
3772a991 | 2504 | del_timer_sync(&phba->hb_tmofunc); |
1151e3ec JS |
2505 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2506 | del_timer_sync(&phba->rrq_tmr); | |
2507 | phba->hba_flag &= ~HBA_RRQ_ACTIVE; | |
2508 | } | |
3772a991 JS |
2509 | phba->hb_outstanding = 0; |
2510 | ||
2511 | switch (phba->pci_dev_grp) { | |
2512 | case LPFC_PCI_DEV_LP: | |
2513 | /* Stop any LightPulse device specific driver timers */ | |
2514 | del_timer_sync(&phba->fcp_poll_timer); | |
2515 | break; | |
2516 | case LPFC_PCI_DEV_OC: | |
2517 | /* Stop any OneConnect device sepcific driver timers */ | |
ecfd03c6 | 2518 | lpfc_sli4_stop_fcf_redisc_wait_timer(phba); |
3772a991 JS |
2519 | break; |
2520 | default: | |
2521 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2522 | "0297 Invalid device group (x%x)\n", | |
2523 | phba->pci_dev_grp); | |
2524 | break; | |
2525 | } | |
2e0fef85 | 2526 | return; |
dea3101e JB |
2527 | } |
2528 | ||
e59058c4 | 2529 | /** |
3621a710 | 2530 | * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked |
e59058c4 JS |
2531 | * @phba: pointer to lpfc hba data structure. |
2532 | * | |
2533 | * This routine marks a HBA's management interface as blocked. Once the HBA's | |
2534 | * management interface is marked as blocked, all the user space access to | |
2535 | * the HBA, whether they are from sysfs interface or libdfc interface will | |
2536 | * all be blocked. The HBA is set to block the management interface when the | |
2537 | * driver prepares the HBA interface for online or offline. | |
2538 | **/ | |
a6ababd2 | 2539 | static void |
618a5230 | 2540 | lpfc_block_mgmt_io(struct lpfc_hba *phba, int mbx_action) |
a6ababd2 AB |
2541 | { |
2542 | unsigned long iflag; | |
6e7288d9 JS |
2543 | uint8_t actcmd = MBX_HEARTBEAT; |
2544 | unsigned long timeout; | |
2545 | ||
a6ababd2 AB |
2546 | spin_lock_irqsave(&phba->hbalock, iflag); |
2547 | phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO; | |
618a5230 JS |
2548 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
2549 | if (mbx_action == LPFC_MBX_NO_WAIT) | |
2550 | return; | |
2551 | timeout = msecs_to_jiffies(LPFC_MBOX_TMO * 1000) + jiffies; | |
2552 | spin_lock_irqsave(&phba->hbalock, iflag); | |
a183a15f | 2553 | if (phba->sli.mbox_active) { |
6e7288d9 | 2554 | actcmd = phba->sli.mbox_active->u.mb.mbxCommand; |
a183a15f JS |
2555 | /* Determine how long we might wait for the active mailbox |
2556 | * command to be gracefully completed by firmware. | |
2557 | */ | |
2558 | timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba, | |
2559 | phba->sli.mbox_active) * 1000) + jiffies; | |
2560 | } | |
a6ababd2 | 2561 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
a183a15f | 2562 | |
6e7288d9 JS |
2563 | /* Wait for the outstnading mailbox command to complete */ |
2564 | while (phba->sli.mbox_active) { | |
2565 | /* Check active mailbox complete status every 2ms */ | |
2566 | msleep(2); | |
2567 | if (time_after(jiffies, timeout)) { | |
2568 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2569 | "2813 Mgmt IO is Blocked %x " | |
2570 | "- mbox cmd %x still active\n", | |
2571 | phba->sli.sli_flag, actcmd); | |
2572 | break; | |
2573 | } | |
2574 | } | |
a6ababd2 AB |
2575 | } |
2576 | ||
6b5151fd JS |
2577 | /** |
2578 | * lpfc_sli4_node_prep - Assign RPIs for active nodes. | |
2579 | * @phba: pointer to lpfc hba data structure. | |
2580 | * | |
2581 | * Allocate RPIs for all active remote nodes. This is needed whenever | |
2582 | * an SLI4 adapter is reset and the driver is not unloading. Its purpose | |
2583 | * is to fixup the temporary rpi assignments. | |
2584 | **/ | |
2585 | void | |
2586 | lpfc_sli4_node_prep(struct lpfc_hba *phba) | |
2587 | { | |
2588 | struct lpfc_nodelist *ndlp, *next_ndlp; | |
2589 | struct lpfc_vport **vports; | |
2590 | int i; | |
2591 | ||
2592 | if (phba->sli_rev != LPFC_SLI_REV4) | |
2593 | return; | |
2594 | ||
2595 | vports = lpfc_create_vport_work_array(phba); | |
2596 | if (vports != NULL) { | |
2597 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { | |
2598 | if (vports[i]->load_flag & FC_UNLOADING) | |
2599 | continue; | |
2600 | ||
2601 | list_for_each_entry_safe(ndlp, next_ndlp, | |
2602 | &vports[i]->fc_nodes, | |
2603 | nlp_listp) { | |
2604 | if (NLP_CHK_NODE_ACT(ndlp)) | |
2605 | ndlp->nlp_rpi = | |
2606 | lpfc_sli4_alloc_rpi(phba); | |
2607 | } | |
2608 | } | |
2609 | } | |
2610 | lpfc_destroy_vport_work_array(phba, vports); | |
2611 | } | |
2612 | ||
e59058c4 | 2613 | /** |
3621a710 | 2614 | * lpfc_online - Initialize and bring a HBA online |
e59058c4 JS |
2615 | * @phba: pointer to lpfc hba data structure. |
2616 | * | |
2617 | * This routine initializes the HBA and brings a HBA online. During this | |
2618 | * process, the management interface is blocked to prevent user space access | |
2619 | * to the HBA interfering with the driver initialization. | |
2620 | * | |
2621 | * Return codes | |
2622 | * 0 - successful | |
2623 | * 1 - failed | |
2624 | **/ | |
dea3101e | 2625 | int |
2e0fef85 | 2626 | lpfc_online(struct lpfc_hba *phba) |
dea3101e | 2627 | { |
372bd282 | 2628 | struct lpfc_vport *vport; |
549e55cd JS |
2629 | struct lpfc_vport **vports; |
2630 | int i; | |
2e0fef85 | 2631 | |
dea3101e JB |
2632 | if (!phba) |
2633 | return 0; | |
372bd282 | 2634 | vport = phba->pport; |
dea3101e | 2635 | |
2e0fef85 | 2636 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) |
dea3101e JB |
2637 | return 0; |
2638 | ||
ed957684 | 2639 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 2640 | "0458 Bring Adapter online\n"); |
dea3101e | 2641 | |
618a5230 | 2642 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
46fa311e JS |
2643 | |
2644 | if (!lpfc_sli_queue_setup(phba)) { | |
2645 | lpfc_unblock_mgmt_io(phba); | |
dea3101e | 2646 | return 1; |
46fa311e | 2647 | } |
dea3101e | 2648 | |
da0436e9 JS |
2649 | if (phba->sli_rev == LPFC_SLI_REV4) { |
2650 | if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */ | |
2651 | lpfc_unblock_mgmt_io(phba); | |
2652 | return 1; | |
2653 | } | |
2654 | } else { | |
2655 | if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */ | |
2656 | lpfc_unblock_mgmt_io(phba); | |
2657 | return 1; | |
2658 | } | |
46fa311e | 2659 | } |
dea3101e | 2660 | |
549e55cd JS |
2661 | vports = lpfc_create_vport_work_array(phba); |
2662 | if (vports != NULL) | |
da0436e9 | 2663 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd JS |
2664 | struct Scsi_Host *shost; |
2665 | shost = lpfc_shost_from_vport(vports[i]); | |
2666 | spin_lock_irq(shost->host_lock); | |
2667 | vports[i]->fc_flag &= ~FC_OFFLINE_MODE; | |
2668 | if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) | |
2669 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; | |
1c6834a7 JS |
2670 | if (phba->sli_rev == LPFC_SLI_REV4) |
2671 | vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI; | |
549e55cd JS |
2672 | spin_unlock_irq(shost->host_lock); |
2673 | } | |
09372820 | 2674 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2675 | |
46fa311e | 2676 | lpfc_unblock_mgmt_io(phba); |
dea3101e JB |
2677 | return 0; |
2678 | } | |
2679 | ||
e59058c4 | 2680 | /** |
3621a710 | 2681 | * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked |
e59058c4 JS |
2682 | * @phba: pointer to lpfc hba data structure. |
2683 | * | |
2684 | * This routine marks a HBA's management interface as not blocked. Once the | |
2685 | * HBA's management interface is marked as not blocked, all the user space | |
2686 | * access to the HBA, whether they are from sysfs interface or libdfc | |
2687 | * interface will be allowed. The HBA is set to block the management interface | |
2688 | * when the driver prepares the HBA interface for online or offline and then | |
2689 | * set to unblock the management interface afterwards. | |
2690 | **/ | |
46fa311e JS |
2691 | void |
2692 | lpfc_unblock_mgmt_io(struct lpfc_hba * phba) | |
2693 | { | |
2694 | unsigned long iflag; | |
2695 | ||
2e0fef85 JS |
2696 | spin_lock_irqsave(&phba->hbalock, iflag); |
2697 | phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO; | |
2698 | spin_unlock_irqrestore(&phba->hbalock, iflag); | |
46fa311e JS |
2699 | } |
2700 | ||
e59058c4 | 2701 | /** |
3621a710 | 2702 | * lpfc_offline_prep - Prepare a HBA to be brought offline |
e59058c4 JS |
2703 | * @phba: pointer to lpfc hba data structure. |
2704 | * | |
2705 | * This routine is invoked to prepare a HBA to be brought offline. It performs | |
2706 | * unregistration login to all the nodes on all vports and flushes the mailbox | |
2707 | * queue to make it ready to be brought offline. | |
2708 | **/ | |
46fa311e | 2709 | void |
618a5230 | 2710 | lpfc_offline_prep(struct lpfc_hba *phba, int mbx_action) |
46fa311e | 2711 | { |
2e0fef85 | 2712 | struct lpfc_vport *vport = phba->pport; |
46fa311e | 2713 | struct lpfc_nodelist *ndlp, *next_ndlp; |
87af33fe | 2714 | struct lpfc_vport **vports; |
72100cc4 | 2715 | struct Scsi_Host *shost; |
87af33fe | 2716 | int i; |
dea3101e | 2717 | |
2e0fef85 | 2718 | if (vport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 2719 | return; |
dea3101e | 2720 | |
618a5230 | 2721 | lpfc_block_mgmt_io(phba, mbx_action); |
dea3101e JB |
2722 | |
2723 | lpfc_linkdown(phba); | |
2724 | ||
87af33fe JS |
2725 | /* Issue an unreg_login to all nodes on all vports */ |
2726 | vports = lpfc_create_vport_work_array(phba); | |
2727 | if (vports != NULL) { | |
da0436e9 | 2728 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
a8adb832 JS |
2729 | if (vports[i]->load_flag & FC_UNLOADING) |
2730 | continue; | |
72100cc4 JS |
2731 | shost = lpfc_shost_from_vport(vports[i]); |
2732 | spin_lock_irq(shost->host_lock); | |
c868595d | 2733 | vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED; |
695a814e JS |
2734 | vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
2735 | vports[i]->fc_flag &= ~FC_VFI_REGISTERED; | |
72100cc4 | 2736 | spin_unlock_irq(shost->host_lock); |
695a814e | 2737 | |
87af33fe JS |
2738 | shost = lpfc_shost_from_vport(vports[i]); |
2739 | list_for_each_entry_safe(ndlp, next_ndlp, | |
2740 | &vports[i]->fc_nodes, | |
2741 | nlp_listp) { | |
e47c9093 JS |
2742 | if (!NLP_CHK_NODE_ACT(ndlp)) |
2743 | continue; | |
87af33fe JS |
2744 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) |
2745 | continue; | |
2746 | if (ndlp->nlp_type & NLP_FABRIC) { | |
2747 | lpfc_disc_state_machine(vports[i], ndlp, | |
2748 | NULL, NLP_EVT_DEVICE_RECOVERY); | |
2749 | lpfc_disc_state_machine(vports[i], ndlp, | |
2750 | NULL, NLP_EVT_DEVICE_RM); | |
2751 | } | |
2752 | spin_lock_irq(shost->host_lock); | |
2753 | ndlp->nlp_flag &= ~NLP_NPR_ADISC; | |
401ee0c1 | 2754 | spin_unlock_irq(shost->host_lock); |
6b5151fd JS |
2755 | /* |
2756 | * Whenever an SLI4 port goes offline, free the | |
401ee0c1 JS |
2757 | * RPI. Get a new RPI when the adapter port |
2758 | * comes back online. | |
6b5151fd JS |
2759 | */ |
2760 | if (phba->sli_rev == LPFC_SLI_REV4) | |
2761 | lpfc_sli4_free_rpi(phba, ndlp->nlp_rpi); | |
87af33fe JS |
2762 | lpfc_unreg_rpi(vports[i], ndlp); |
2763 | } | |
2764 | } | |
2765 | } | |
09372820 | 2766 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e | 2767 | |
618a5230 | 2768 | lpfc_sli_mbox_sys_shutdown(phba, mbx_action); |
46fa311e JS |
2769 | } |
2770 | ||
e59058c4 | 2771 | /** |
3621a710 | 2772 | * lpfc_offline - Bring a HBA offline |
e59058c4 JS |
2773 | * @phba: pointer to lpfc hba data structure. |
2774 | * | |
2775 | * This routine actually brings a HBA offline. It stops all the timers | |
2776 | * associated with the HBA, brings down the SLI layer, and eventually | |
2777 | * marks the HBA as in offline state for the upper layer protocol. | |
2778 | **/ | |
46fa311e | 2779 | void |
2e0fef85 | 2780 | lpfc_offline(struct lpfc_hba *phba) |
46fa311e | 2781 | { |
549e55cd JS |
2782 | struct Scsi_Host *shost; |
2783 | struct lpfc_vport **vports; | |
2784 | int i; | |
46fa311e | 2785 | |
549e55cd | 2786 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
46fa311e | 2787 | return; |
688a8863 | 2788 | |
da0436e9 JS |
2789 | /* stop port and all timers associated with this hba */ |
2790 | lpfc_stop_port(phba); | |
51ef4c26 JS |
2791 | vports = lpfc_create_vport_work_array(phba); |
2792 | if (vports != NULL) | |
da0436e9 | 2793 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) |
51ef4c26 | 2794 | lpfc_stop_vport_timers(vports[i]); |
09372820 | 2795 | lpfc_destroy_vport_work_array(phba, vports); |
92d7f7b0 | 2796 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, |
e8b62011 | 2797 | "0460 Bring Adapter offline\n"); |
dea3101e JB |
2798 | /* Bring down the SLI Layer and cleanup. The HBA is offline |
2799 | now. */ | |
2800 | lpfc_sli_hba_down(phba); | |
92d7f7b0 | 2801 | spin_lock_irq(&phba->hbalock); |
7054a606 | 2802 | phba->work_ha = 0; |
92d7f7b0 | 2803 | spin_unlock_irq(&phba->hbalock); |
549e55cd JS |
2804 | vports = lpfc_create_vport_work_array(phba); |
2805 | if (vports != NULL) | |
da0436e9 | 2806 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
549e55cd | 2807 | shost = lpfc_shost_from_vport(vports[i]); |
549e55cd JS |
2808 | spin_lock_irq(shost->host_lock); |
2809 | vports[i]->work_port_events = 0; | |
2810 | vports[i]->fc_flag |= FC_OFFLINE_MODE; | |
2811 | spin_unlock_irq(shost->host_lock); | |
2812 | } | |
09372820 | 2813 | lpfc_destroy_vport_work_array(phba, vports); |
dea3101e JB |
2814 | } |
2815 | ||
e59058c4 | 2816 | /** |
3621a710 | 2817 | * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists |
e59058c4 JS |
2818 | * @phba: pointer to lpfc hba data structure. |
2819 | * | |
2820 | * This routine is to free all the SCSI buffers and IOCBs from the driver | |
2821 | * list back to kernel. It is called from lpfc_pci_remove_one to free | |
2822 | * the internal resources before the device is removed from the system. | |
e59058c4 | 2823 | **/ |
8a9d2e80 | 2824 | static void |
2e0fef85 | 2825 | lpfc_scsi_free(struct lpfc_hba *phba) |
dea3101e JB |
2826 | { |
2827 | struct lpfc_scsi_buf *sb, *sb_next; | |
2828 | struct lpfc_iocbq *io, *io_next; | |
2829 | ||
2e0fef85 | 2830 | spin_lock_irq(&phba->hbalock); |
dea3101e | 2831 | /* Release all the lpfc_scsi_bufs maintained by this host. */ |
1c6f4ef5 | 2832 | spin_lock(&phba->scsi_buf_list_lock); |
dea3101e JB |
2833 | list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { |
2834 | list_del(&sb->list); | |
2835 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, | |
92d7f7b0 | 2836 | sb->dma_handle); |
dea3101e JB |
2837 | kfree(sb); |
2838 | phba->total_scsi_bufs--; | |
2839 | } | |
1c6f4ef5 | 2840 | spin_unlock(&phba->scsi_buf_list_lock); |
dea3101e JB |
2841 | |
2842 | /* Release all the lpfc_iocbq entries maintained by this host. */ | |
2843 | list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) { | |
2844 | list_del(&io->list); | |
2845 | kfree(io); | |
2846 | phba->total_iocbq_bufs--; | |
2847 | } | |
6d368e53 | 2848 | |
2e0fef85 | 2849 | spin_unlock_irq(&phba->hbalock); |
8a9d2e80 JS |
2850 | } |
2851 | ||
2852 | /** | |
2853 | * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping | |
2854 | * @phba: pointer to lpfc hba data structure. | |
2855 | * | |
2856 | * This routine first calculates the sizes of the current els and allocated | |
2857 | * scsi sgl lists, and then goes through all sgls to updates the physical | |
2858 | * XRIs assigned due to port function reset. During port initialization, the | |
2859 | * current els and allocated scsi sgl lists are 0s. | |
2860 | * | |
2861 | * Return codes | |
2862 | * 0 - successful (for now, it always returns 0) | |
2863 | **/ | |
2864 | int | |
2865 | lpfc_sli4_xri_sgl_update(struct lpfc_hba *phba) | |
2866 | { | |
2867 | struct lpfc_sglq *sglq_entry = NULL, *sglq_entry_next = NULL; | |
2868 | struct lpfc_scsi_buf *psb = NULL, *psb_next = NULL; | |
2869 | uint16_t i, lxri, xri_cnt, els_xri_cnt, scsi_xri_cnt; | |
2870 | LIST_HEAD(els_sgl_list); | |
2871 | LIST_HEAD(scsi_sgl_list); | |
2872 | int rc; | |
2873 | ||
2874 | /* | |
2875 | * update on pci function's els xri-sgl list | |
2876 | */ | |
2877 | els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba); | |
2878 | if (els_xri_cnt > phba->sli4_hba.els_xri_cnt) { | |
2879 | /* els xri-sgl expanded */ | |
2880 | xri_cnt = els_xri_cnt - phba->sli4_hba.els_xri_cnt; | |
2881 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
2882 | "3157 ELS xri-sgl count increased from " | |
2883 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, | |
2884 | els_xri_cnt); | |
2885 | /* allocate the additional els sgls */ | |
2886 | for (i = 0; i < xri_cnt; i++) { | |
2887 | sglq_entry = kzalloc(sizeof(struct lpfc_sglq), | |
2888 | GFP_KERNEL); | |
2889 | if (sglq_entry == NULL) { | |
2890 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2891 | "2562 Failure to allocate an " | |
2892 | "ELS sgl entry:%d\n", i); | |
2893 | rc = -ENOMEM; | |
2894 | goto out_free_mem; | |
2895 | } | |
2896 | sglq_entry->buff_type = GEN_BUFF_TYPE; | |
2897 | sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, | |
2898 | &sglq_entry->phys); | |
2899 | if (sglq_entry->virt == NULL) { | |
2900 | kfree(sglq_entry); | |
2901 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2902 | "2563 Failure to allocate an " | |
2903 | "ELS mbuf:%d\n", i); | |
2904 | rc = -ENOMEM; | |
2905 | goto out_free_mem; | |
2906 | } | |
2907 | sglq_entry->sgl = sglq_entry->virt; | |
2908 | memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE); | |
2909 | sglq_entry->state = SGL_FREED; | |
2910 | list_add_tail(&sglq_entry->list, &els_sgl_list); | |
2911 | } | |
2912 | spin_lock(&phba->hbalock); | |
2913 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); | |
2914 | spin_unlock(&phba->hbalock); | |
2915 | } else if (els_xri_cnt < phba->sli4_hba.els_xri_cnt) { | |
2916 | /* els xri-sgl shrinked */ | |
2917 | xri_cnt = phba->sli4_hba.els_xri_cnt - els_xri_cnt; | |
2918 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
2919 | "3158 ELS xri-sgl count decreased from " | |
2920 | "%d to %d\n", phba->sli4_hba.els_xri_cnt, | |
2921 | els_xri_cnt); | |
2922 | spin_lock_irq(&phba->hbalock); | |
2923 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &els_sgl_list); | |
2924 | spin_unlock_irq(&phba->hbalock); | |
2925 | /* release extra els sgls from list */ | |
2926 | for (i = 0; i < xri_cnt; i++) { | |
2927 | list_remove_head(&els_sgl_list, | |
2928 | sglq_entry, struct lpfc_sglq, list); | |
2929 | if (sglq_entry) { | |
2930 | lpfc_mbuf_free(phba, sglq_entry->virt, | |
2931 | sglq_entry->phys); | |
2932 | kfree(sglq_entry); | |
2933 | } | |
2934 | } | |
2935 | spin_lock_irq(&phba->hbalock); | |
2936 | list_splice_init(&els_sgl_list, &phba->sli4_hba.lpfc_sgl_list); | |
2937 | spin_unlock_irq(&phba->hbalock); | |
2938 | } else | |
2939 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
2940 | "3163 ELS xri-sgl count unchanged: %d\n", | |
2941 | els_xri_cnt); | |
2942 | phba->sli4_hba.els_xri_cnt = els_xri_cnt; | |
2943 | ||
2944 | /* update xris to els sgls on the list */ | |
2945 | sglq_entry = NULL; | |
2946 | sglq_entry_next = NULL; | |
2947 | list_for_each_entry_safe(sglq_entry, sglq_entry_next, | |
2948 | &phba->sli4_hba.lpfc_sgl_list, list) { | |
2949 | lxri = lpfc_sli4_next_xritag(phba); | |
2950 | if (lxri == NO_XRI) { | |
2951 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
2952 | "2400 Failed to allocate xri for " | |
2953 | "ELS sgl\n"); | |
2954 | rc = -ENOMEM; | |
2955 | goto out_free_mem; | |
2956 | } | |
2957 | sglq_entry->sli4_lxritag = lxri; | |
2958 | sglq_entry->sli4_xritag = phba->sli4_hba.xri_ids[lxri]; | |
2959 | } | |
2960 | ||
2961 | /* | |
2962 | * update on pci function's allocated scsi xri-sgl list | |
2963 | */ | |
2964 | phba->total_scsi_bufs = 0; | |
2965 | ||
2966 | /* maximum number of xris available for scsi buffers */ | |
2967 | phba->sli4_hba.scsi_xri_max = phba->sli4_hba.max_cfg_param.max_xri - | |
2968 | els_xri_cnt; | |
2969 | ||
2970 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
2971 | "2401 Current allocated SCSI xri-sgl count:%d, " | |
2972 | "maximum SCSI xri count:%d\n", | |
2973 | phba->sli4_hba.scsi_xri_cnt, | |
2974 | phba->sli4_hba.scsi_xri_max); | |
2975 | ||
2976 | spin_lock_irq(&phba->scsi_buf_list_lock); | |
2977 | list_splice_init(&phba->lpfc_scsi_buf_list, &scsi_sgl_list); | |
2978 | spin_unlock_irq(&phba->scsi_buf_list_lock); | |
2979 | ||
2980 | if (phba->sli4_hba.scsi_xri_cnt > phba->sli4_hba.scsi_xri_max) { | |
2981 | /* max scsi xri shrinked below the allocated scsi buffers */ | |
2982 | scsi_xri_cnt = phba->sli4_hba.scsi_xri_cnt - | |
2983 | phba->sli4_hba.scsi_xri_max; | |
2984 | /* release the extra allocated scsi buffers */ | |
2985 | for (i = 0; i < scsi_xri_cnt; i++) { | |
2986 | list_remove_head(&scsi_sgl_list, psb, | |
2987 | struct lpfc_scsi_buf, list); | |
2988 | pci_pool_free(phba->lpfc_scsi_dma_buf_pool, psb->data, | |
2989 | psb->dma_handle); | |
2990 | kfree(psb); | |
2991 | } | |
2992 | spin_lock_irq(&phba->scsi_buf_list_lock); | |
2993 | phba->sli4_hba.scsi_xri_cnt -= scsi_xri_cnt; | |
2994 | spin_unlock_irq(&phba->scsi_buf_list_lock); | |
2995 | } | |
2996 | ||
2997 | /* update xris associated to remaining allocated scsi buffers */ | |
2998 | psb = NULL; | |
2999 | psb_next = NULL; | |
3000 | list_for_each_entry_safe(psb, psb_next, &scsi_sgl_list, list) { | |
3001 | lxri = lpfc_sli4_next_xritag(phba); | |
3002 | if (lxri == NO_XRI) { | |
3003 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3004 | "2560 Failed to allocate xri for " | |
3005 | "scsi buffer\n"); | |
3006 | rc = -ENOMEM; | |
3007 | goto out_free_mem; | |
3008 | } | |
3009 | psb->cur_iocbq.sli4_lxritag = lxri; | |
3010 | psb->cur_iocbq.sli4_xritag = phba->sli4_hba.xri_ids[lxri]; | |
3011 | } | |
3012 | spin_lock(&phba->scsi_buf_list_lock); | |
3013 | list_splice_init(&scsi_sgl_list, &phba->lpfc_scsi_buf_list); | |
3014 | spin_unlock(&phba->scsi_buf_list_lock); | |
3015 | ||
dea3101e | 3016 | return 0; |
8a9d2e80 JS |
3017 | |
3018 | out_free_mem: | |
3019 | lpfc_free_els_sgl_list(phba); | |
3020 | lpfc_scsi_free(phba); | |
3021 | return rc; | |
dea3101e JB |
3022 | } |
3023 | ||
e59058c4 | 3024 | /** |
3621a710 | 3025 | * lpfc_create_port - Create an FC port |
e59058c4 JS |
3026 | * @phba: pointer to lpfc hba data structure. |
3027 | * @instance: a unique integer ID to this FC port. | |
3028 | * @dev: pointer to the device data structure. | |
3029 | * | |
3030 | * This routine creates a FC port for the upper layer protocol. The FC port | |
3031 | * can be created on top of either a physical port or a virtual port provided | |
3032 | * by the HBA. This routine also allocates a SCSI host data structure (shost) | |
3033 | * and associates the FC port created before adding the shost into the SCSI | |
3034 | * layer. | |
3035 | * | |
3036 | * Return codes | |
3037 | * @vport - pointer to the virtual N_Port data structure. | |
3038 | * NULL - port create failed. | |
3039 | **/ | |
2e0fef85 | 3040 | struct lpfc_vport * |
3de2a653 | 3041 | lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev) |
47a8617c | 3042 | { |
2e0fef85 JS |
3043 | struct lpfc_vport *vport; |
3044 | struct Scsi_Host *shost; | |
3045 | int error = 0; | |
47a8617c | 3046 | |
3de2a653 JS |
3047 | if (dev != &phba->pcidev->dev) |
3048 | shost = scsi_host_alloc(&lpfc_vport_template, | |
3049 | sizeof(struct lpfc_vport)); | |
3050 | else | |
3051 | shost = scsi_host_alloc(&lpfc_template, | |
3052 | sizeof(struct lpfc_vport)); | |
2e0fef85 JS |
3053 | if (!shost) |
3054 | goto out; | |
47a8617c | 3055 | |
2e0fef85 JS |
3056 | vport = (struct lpfc_vport *) shost->hostdata; |
3057 | vport->phba = phba; | |
2e0fef85 | 3058 | vport->load_flag |= FC_LOADING; |
92d7f7b0 | 3059 | vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI; |
7f5f3d0d | 3060 | vport->fc_rscn_flush = 0; |
47a8617c | 3061 | |
3de2a653 | 3062 | lpfc_get_vport_cfgparam(vport); |
2e0fef85 JS |
3063 | shost->unique_id = instance; |
3064 | shost->max_id = LPFC_MAX_TARGET; | |
3de2a653 | 3065 | shost->max_lun = vport->cfg_max_luns; |
2e0fef85 JS |
3066 | shost->this_id = -1; |
3067 | shost->max_cmd_len = 16; | |
da0436e9 | 3068 | if (phba->sli_rev == LPFC_SLI_REV4) { |
28baac74 | 3069 | shost->dma_boundary = |
cb5172ea | 3070 | phba->sli4_hba.pc_sli4_params.sge_supp_len-1; |
da0436e9 JS |
3071 | shost->sg_tablesize = phba->cfg_sg_seg_cnt; |
3072 | } | |
81301a9b | 3073 | |
47a8617c | 3074 | /* |
2e0fef85 JS |
3075 | * Set initial can_queue value since 0 is no longer supported and |
3076 | * scsi_add_host will fail. This will be adjusted later based on the | |
3077 | * max xri value determined in hba setup. | |
47a8617c | 3078 | */ |
2e0fef85 | 3079 | shost->can_queue = phba->cfg_hba_queue_depth - 10; |
3de2a653 | 3080 | if (dev != &phba->pcidev->dev) { |
92d7f7b0 JS |
3081 | shost->transportt = lpfc_vport_transport_template; |
3082 | vport->port_type = LPFC_NPIV_PORT; | |
3083 | } else { | |
3084 | shost->transportt = lpfc_transport_template; | |
3085 | vport->port_type = LPFC_PHYSICAL_PORT; | |
3086 | } | |
47a8617c | 3087 | |
2e0fef85 JS |
3088 | /* Initialize all internally managed lists. */ |
3089 | INIT_LIST_HEAD(&vport->fc_nodes); | |
da0436e9 | 3090 | INIT_LIST_HEAD(&vport->rcv_buffer_list); |
2e0fef85 | 3091 | spin_lock_init(&vport->work_port_lock); |
47a8617c | 3092 | |
2e0fef85 JS |
3093 | init_timer(&vport->fc_disctmo); |
3094 | vport->fc_disctmo.function = lpfc_disc_timeout; | |
92d7f7b0 | 3095 | vport->fc_disctmo.data = (unsigned long)vport; |
47a8617c | 3096 | |
2e0fef85 JS |
3097 | init_timer(&vport->fc_fdmitmo); |
3098 | vport->fc_fdmitmo.function = lpfc_fdmi_tmo; | |
92d7f7b0 | 3099 | vport->fc_fdmitmo.data = (unsigned long)vport; |
47a8617c | 3100 | |
2e0fef85 JS |
3101 | init_timer(&vport->els_tmofunc); |
3102 | vport->els_tmofunc.function = lpfc_els_timeout; | |
92d7f7b0 | 3103 | vport->els_tmofunc.data = (unsigned long)vport; |
92494144 JS |
3104 | |
3105 | init_timer(&vport->delayed_disc_tmo); | |
3106 | vport->delayed_disc_tmo.function = lpfc_delayed_disc_tmo; | |
3107 | vport->delayed_disc_tmo.data = (unsigned long)vport; | |
3108 | ||
d139b9bd | 3109 | error = scsi_add_host_with_dma(shost, dev, &phba->pcidev->dev); |
2e0fef85 JS |
3110 | if (error) |
3111 | goto out_put_shost; | |
47a8617c | 3112 | |
549e55cd | 3113 | spin_lock_irq(&phba->hbalock); |
2e0fef85 | 3114 | list_add_tail(&vport->listentry, &phba->port_list); |
549e55cd | 3115 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 3116 | return vport; |
47a8617c | 3117 | |
2e0fef85 JS |
3118 | out_put_shost: |
3119 | scsi_host_put(shost); | |
3120 | out: | |
3121 | return NULL; | |
47a8617c JS |
3122 | } |
3123 | ||
e59058c4 | 3124 | /** |
3621a710 | 3125 | * destroy_port - destroy an FC port |
e59058c4 JS |
3126 | * @vport: pointer to an lpfc virtual N_Port data structure. |
3127 | * | |
3128 | * This routine destroys a FC port from the upper layer protocol. All the | |
3129 | * resources associated with the port are released. | |
3130 | **/ | |
2e0fef85 JS |
3131 | void |
3132 | destroy_port(struct lpfc_vport *vport) | |
47a8617c | 3133 | { |
92d7f7b0 JS |
3134 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
3135 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 3136 | |
858c9f6c | 3137 | lpfc_debugfs_terminate(vport); |
92d7f7b0 JS |
3138 | fc_remove_host(shost); |
3139 | scsi_remove_host(shost); | |
47a8617c | 3140 | |
92d7f7b0 JS |
3141 | spin_lock_irq(&phba->hbalock); |
3142 | list_del_init(&vport->listentry); | |
3143 | spin_unlock_irq(&phba->hbalock); | |
47a8617c | 3144 | |
92d7f7b0 | 3145 | lpfc_cleanup(vport); |
47a8617c | 3146 | return; |
47a8617c JS |
3147 | } |
3148 | ||
e59058c4 | 3149 | /** |
3621a710 | 3150 | * lpfc_get_instance - Get a unique integer ID |
e59058c4 JS |
3151 | * |
3152 | * This routine allocates a unique integer ID from lpfc_hba_index pool. It | |
3153 | * uses the kernel idr facility to perform the task. | |
3154 | * | |
3155 | * Return codes: | |
3156 | * instance - a unique integer ID allocated as the new instance. | |
3157 | * -1 - lpfc get instance failed. | |
3158 | **/ | |
92d7f7b0 JS |
3159 | int |
3160 | lpfc_get_instance(void) | |
3161 | { | |
3162 | int instance = 0; | |
47a8617c | 3163 | |
92d7f7b0 JS |
3164 | /* Assign an unused number */ |
3165 | if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) | |
3166 | return -1; | |
3167 | if (idr_get_new(&lpfc_hba_index, NULL, &instance)) | |
3168 | return -1; | |
3169 | return instance; | |
47a8617c JS |
3170 | } |
3171 | ||
e59058c4 | 3172 | /** |
3621a710 | 3173 | * lpfc_scan_finished - method for SCSI layer to detect whether scan is done |
e59058c4 JS |
3174 | * @shost: pointer to SCSI host data structure. |
3175 | * @time: elapsed time of the scan in jiffies. | |
3176 | * | |
3177 | * This routine is called by the SCSI layer with a SCSI host to determine | |
3178 | * whether the scan host is finished. | |
3179 | * | |
3180 | * Note: there is no scan_start function as adapter initialization will have | |
3181 | * asynchronously kicked off the link initialization. | |
3182 | * | |
3183 | * Return codes | |
3184 | * 0 - SCSI host scan is not over yet. | |
3185 | * 1 - SCSI host scan is over. | |
3186 | **/ | |
47a8617c JS |
3187 | int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) |
3188 | { | |
2e0fef85 JS |
3189 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
3190 | struct lpfc_hba *phba = vport->phba; | |
858c9f6c | 3191 | int stat = 0; |
47a8617c | 3192 | |
858c9f6c JS |
3193 | spin_lock_irq(shost->host_lock); |
3194 | ||
51ef4c26 | 3195 | if (vport->load_flag & FC_UNLOADING) { |
858c9f6c JS |
3196 | stat = 1; |
3197 | goto finished; | |
3198 | } | |
2e0fef85 JS |
3199 | if (time >= 30 * HZ) { |
3200 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
3201 | "0461 Scanning longer than 30 " |
3202 | "seconds. Continuing initialization\n"); | |
858c9f6c | 3203 | stat = 1; |
47a8617c | 3204 | goto finished; |
2e0fef85 JS |
3205 | } |
3206 | if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) { | |
3207 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
e8b62011 JS |
3208 | "0465 Link down longer than 15 " |
3209 | "seconds. Continuing initialization\n"); | |
858c9f6c | 3210 | stat = 1; |
47a8617c | 3211 | goto finished; |
2e0fef85 | 3212 | } |
47a8617c | 3213 | |
2e0fef85 | 3214 | if (vport->port_state != LPFC_VPORT_READY) |
858c9f6c | 3215 | goto finished; |
2e0fef85 | 3216 | if (vport->num_disc_nodes || vport->fc_prli_sent) |
858c9f6c | 3217 | goto finished; |
2e0fef85 | 3218 | if (vport->fc_map_cnt == 0 && time < 2 * HZ) |
858c9f6c | 3219 | goto finished; |
2e0fef85 | 3220 | if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0) |
858c9f6c JS |
3221 | goto finished; |
3222 | ||
3223 | stat = 1; | |
47a8617c JS |
3224 | |
3225 | finished: | |
858c9f6c JS |
3226 | spin_unlock_irq(shost->host_lock); |
3227 | return stat; | |
92d7f7b0 | 3228 | } |
47a8617c | 3229 | |
e59058c4 | 3230 | /** |
3621a710 | 3231 | * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port |
e59058c4 JS |
3232 | * @shost: pointer to SCSI host data structure. |
3233 | * | |
3234 | * This routine initializes a given SCSI host attributes on a FC port. The | |
3235 | * SCSI host can be either on top of a physical port or a virtual port. | |
3236 | **/ | |
92d7f7b0 JS |
3237 | void lpfc_host_attrib_init(struct Scsi_Host *shost) |
3238 | { | |
3239 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3240 | struct lpfc_hba *phba = vport->phba; | |
47a8617c | 3241 | /* |
2e0fef85 | 3242 | * Set fixed host attributes. Must done after lpfc_sli_hba_setup(). |
47a8617c JS |
3243 | */ |
3244 | ||
2e0fef85 JS |
3245 | fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn); |
3246 | fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn); | |
47a8617c JS |
3247 | fc_host_supported_classes(shost) = FC_COS_CLASS3; |
3248 | ||
3249 | memset(fc_host_supported_fc4s(shost), 0, | |
2e0fef85 | 3250 | sizeof(fc_host_supported_fc4s(shost))); |
47a8617c JS |
3251 | fc_host_supported_fc4s(shost)[2] = 1; |
3252 | fc_host_supported_fc4s(shost)[7] = 1; | |
3253 | ||
92d7f7b0 JS |
3254 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), |
3255 | sizeof fc_host_symbolic_name(shost)); | |
47a8617c JS |
3256 | |
3257 | fc_host_supported_speeds(shost) = 0; | |
88a2cfbb JS |
3258 | if (phba->lmt & LMT_16Gb) |
3259 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_16GBIT; | |
47a8617c JS |
3260 | if (phba->lmt & LMT_10Gb) |
3261 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT; | |
a8adb832 JS |
3262 | if (phba->lmt & LMT_8Gb) |
3263 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT; | |
47a8617c JS |
3264 | if (phba->lmt & LMT_4Gb) |
3265 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT; | |
3266 | if (phba->lmt & LMT_2Gb) | |
3267 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT; | |
3268 | if (phba->lmt & LMT_1Gb) | |
3269 | fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; | |
3270 | ||
3271 | fc_host_maxframe_size(shost) = | |
2e0fef85 JS |
3272 | (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | |
3273 | (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb; | |
47a8617c | 3274 | |
0af5d708 MC |
3275 | fc_host_dev_loss_tmo(shost) = vport->cfg_devloss_tmo; |
3276 | ||
47a8617c JS |
3277 | /* This value is also unchanging */ |
3278 | memset(fc_host_active_fc4s(shost), 0, | |
2e0fef85 | 3279 | sizeof(fc_host_active_fc4s(shost))); |
47a8617c JS |
3280 | fc_host_active_fc4s(shost)[2] = 1; |
3281 | fc_host_active_fc4s(shost)[7] = 1; | |
3282 | ||
92d7f7b0 | 3283 | fc_host_max_npiv_vports(shost) = phba->max_vpi; |
47a8617c | 3284 | spin_lock_irq(shost->host_lock); |
51ef4c26 | 3285 | vport->load_flag &= ~FC_LOADING; |
47a8617c | 3286 | spin_unlock_irq(shost->host_lock); |
47a8617c | 3287 | } |
dea3101e | 3288 | |
e59058c4 | 3289 | /** |
da0436e9 | 3290 | * lpfc_stop_port_s3 - Stop SLI3 device port |
e59058c4 JS |
3291 | * @phba: pointer to lpfc hba data structure. |
3292 | * | |
da0436e9 JS |
3293 | * This routine is invoked to stop an SLI3 device port, it stops the device |
3294 | * from generating interrupts and stops the device driver's timers for the | |
3295 | * device. | |
e59058c4 | 3296 | **/ |
da0436e9 JS |
3297 | static void |
3298 | lpfc_stop_port_s3(struct lpfc_hba *phba) | |
db2378e0 | 3299 | { |
da0436e9 JS |
3300 | /* Clear all interrupt enable conditions */ |
3301 | writel(0, phba->HCregaddr); | |
3302 | readl(phba->HCregaddr); /* flush */ | |
3303 | /* Clear all pending interrupts */ | |
3304 | writel(0xffffffff, phba->HAregaddr); | |
3305 | readl(phba->HAregaddr); /* flush */ | |
db2378e0 | 3306 | |
da0436e9 JS |
3307 | /* Reset some HBA SLI setup states */ |
3308 | lpfc_stop_hba_timers(phba); | |
3309 | phba->pport->work_port_events = 0; | |
3310 | } | |
db2378e0 | 3311 | |
da0436e9 JS |
3312 | /** |
3313 | * lpfc_stop_port_s4 - Stop SLI4 device port | |
3314 | * @phba: pointer to lpfc hba data structure. | |
3315 | * | |
3316 | * This routine is invoked to stop an SLI4 device port, it stops the device | |
3317 | * from generating interrupts and stops the device driver's timers for the | |
3318 | * device. | |
3319 | **/ | |
3320 | static void | |
3321 | lpfc_stop_port_s4(struct lpfc_hba *phba) | |
3322 | { | |
3323 | /* Reset some HBA SLI4 setup states */ | |
3324 | lpfc_stop_hba_timers(phba); | |
3325 | phba->pport->work_port_events = 0; | |
3326 | phba->sli4_hba.intr_enable = 0; | |
da0436e9 | 3327 | } |
9399627f | 3328 | |
da0436e9 JS |
3329 | /** |
3330 | * lpfc_stop_port - Wrapper function for stopping hba port | |
3331 | * @phba: Pointer to HBA context object. | |
3332 | * | |
3333 | * This routine wraps the actual SLI3 or SLI4 hba stop port routine from | |
3334 | * the API jump table function pointer from the lpfc_hba struct. | |
3335 | **/ | |
3336 | void | |
3337 | lpfc_stop_port(struct lpfc_hba *phba) | |
3338 | { | |
3339 | phba->lpfc_stop_port(phba); | |
3340 | } | |
db2378e0 | 3341 | |
ecfd03c6 JS |
3342 | /** |
3343 | * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer | |
3344 | * @phba: Pointer to hba for which this call is being executed. | |
3345 | * | |
3346 | * This routine starts the timer waiting for the FCF rediscovery to complete. | |
3347 | **/ | |
3348 | void | |
3349 | lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba *phba) | |
3350 | { | |
3351 | unsigned long fcf_redisc_wait_tmo = | |
3352 | (jiffies + msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO)); | |
3353 | /* Start fcf rediscovery wait period timer */ | |
3354 | mod_timer(&phba->fcf.redisc_wait, fcf_redisc_wait_tmo); | |
3355 | spin_lock_irq(&phba->hbalock); | |
3356 | /* Allow action to new fcf asynchronous event */ | |
3357 | phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE); | |
3358 | /* Mark the FCF rediscovery pending state */ | |
3359 | phba->fcf.fcf_flag |= FCF_REDISC_PEND; | |
3360 | spin_unlock_irq(&phba->hbalock); | |
3361 | } | |
3362 | ||
3363 | /** | |
3364 | * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout | |
3365 | * @ptr: Map to lpfc_hba data structure pointer. | |
3366 | * | |
3367 | * This routine is invoked when waiting for FCF table rediscover has been | |
3368 | * timed out. If new FCF record(s) has (have) been discovered during the | |
3369 | * wait period, a new FCF event shall be added to the FCOE async event | |
3370 | * list, and then worker thread shall be waked up for processing from the | |
3371 | * worker thread context. | |
3372 | **/ | |
3373 | void | |
3374 | lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr) | |
3375 | { | |
3376 | struct lpfc_hba *phba = (struct lpfc_hba *)ptr; | |
3377 | ||
3378 | /* Don't send FCF rediscovery event if timer cancelled */ | |
3379 | spin_lock_irq(&phba->hbalock); | |
3380 | if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND)) { | |
3381 | spin_unlock_irq(&phba->hbalock); | |
3382 | return; | |
3383 | } | |
3384 | /* Clear FCF rediscovery timer pending flag */ | |
3385 | phba->fcf.fcf_flag &= ~FCF_REDISC_PEND; | |
3386 | /* FCF rediscovery event to worker thread */ | |
3387 | phba->fcf.fcf_flag |= FCF_REDISC_EVT; | |
3388 | spin_unlock_irq(&phba->hbalock); | |
0c9ab6f5 | 3389 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP, |
a93ff37a | 3390 | "2776 FCF rediscover quiescent timer expired\n"); |
ecfd03c6 JS |
3391 | /* wake up worker thread */ |
3392 | lpfc_worker_wake_up(phba); | |
3393 | } | |
3394 | ||
e59058c4 | 3395 | /** |
da0436e9 | 3396 | * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code |
e59058c4 | 3397 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3398 | * @acqe_link: pointer to the async link completion queue entry. |
e59058c4 | 3399 | * |
da0436e9 JS |
3400 | * This routine is to parse the SLI4 link-attention link fault code and |
3401 | * translate it into the base driver's read link attention mailbox command | |
3402 | * status. | |
3403 | * | |
3404 | * Return: Link-attention status in terms of base driver's coding. | |
e59058c4 | 3405 | **/ |
da0436e9 JS |
3406 | static uint16_t |
3407 | lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba, | |
3408 | struct lpfc_acqe_link *acqe_link) | |
db2378e0 | 3409 | { |
da0436e9 | 3410 | uint16_t latt_fault; |
9399627f | 3411 | |
da0436e9 JS |
3412 | switch (bf_get(lpfc_acqe_link_fault, acqe_link)) { |
3413 | case LPFC_ASYNC_LINK_FAULT_NONE: | |
3414 | case LPFC_ASYNC_LINK_FAULT_LOCAL: | |
3415 | case LPFC_ASYNC_LINK_FAULT_REMOTE: | |
3416 | latt_fault = 0; | |
3417 | break; | |
3418 | default: | |
3419 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3420 | "0398 Invalid link fault code: x%x\n", | |
3421 | bf_get(lpfc_acqe_link_fault, acqe_link)); | |
3422 | latt_fault = MBXERR_ERROR; | |
3423 | break; | |
3424 | } | |
3425 | return latt_fault; | |
db2378e0 JS |
3426 | } |
3427 | ||
5b75da2f | 3428 | /** |
da0436e9 | 3429 | * lpfc_sli4_parse_latt_type - Parse sli4 link attention type |
5b75da2f | 3430 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3431 | * @acqe_link: pointer to the async link completion queue entry. |
5b75da2f | 3432 | * |
da0436e9 JS |
3433 | * This routine is to parse the SLI4 link attention type and translate it |
3434 | * into the base driver's link attention type coding. | |
5b75da2f | 3435 | * |
da0436e9 JS |
3436 | * Return: Link attention type in terms of base driver's coding. |
3437 | **/ | |
3438 | static uint8_t | |
3439 | lpfc_sli4_parse_latt_type(struct lpfc_hba *phba, | |
3440 | struct lpfc_acqe_link *acqe_link) | |
5b75da2f | 3441 | { |
da0436e9 | 3442 | uint8_t att_type; |
5b75da2f | 3443 | |
da0436e9 JS |
3444 | switch (bf_get(lpfc_acqe_link_status, acqe_link)) { |
3445 | case LPFC_ASYNC_LINK_STATUS_DOWN: | |
3446 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN: | |
76a95d75 | 3447 | att_type = LPFC_ATT_LINK_DOWN; |
da0436e9 JS |
3448 | break; |
3449 | case LPFC_ASYNC_LINK_STATUS_UP: | |
3450 | /* Ignore physical link up events - wait for logical link up */ | |
76a95d75 | 3451 | att_type = LPFC_ATT_RESERVED; |
da0436e9 JS |
3452 | break; |
3453 | case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP: | |
76a95d75 | 3454 | att_type = LPFC_ATT_LINK_UP; |
da0436e9 JS |
3455 | break; |
3456 | default: | |
3457 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3458 | "0399 Invalid link attention type: x%x\n", | |
3459 | bf_get(lpfc_acqe_link_status, acqe_link)); | |
76a95d75 | 3460 | att_type = LPFC_ATT_RESERVED; |
da0436e9 | 3461 | break; |
5b75da2f | 3462 | } |
da0436e9 | 3463 | return att_type; |
5b75da2f JS |
3464 | } |
3465 | ||
3466 | /** | |
da0436e9 | 3467 | * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed |
5b75da2f | 3468 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 3469 | * @acqe_link: pointer to the async link completion queue entry. |
5b75da2f | 3470 | * |
da0436e9 JS |
3471 | * This routine is to parse the SLI4 link-attention link speed and translate |
3472 | * it into the base driver's link-attention link speed coding. | |
3473 | * | |
3474 | * Return: Link-attention link speed in terms of base driver's coding. | |
3475 | **/ | |
3476 | static uint8_t | |
3477 | lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba, | |
3478 | struct lpfc_acqe_link *acqe_link) | |
5b75da2f | 3479 | { |
da0436e9 JS |
3480 | uint8_t link_speed; |
3481 | ||
3482 | switch (bf_get(lpfc_acqe_link_speed, acqe_link)) { | |
3483 | case LPFC_ASYNC_LINK_SPEED_ZERO: | |
da0436e9 | 3484 | case LPFC_ASYNC_LINK_SPEED_10MBPS: |
da0436e9 | 3485 | case LPFC_ASYNC_LINK_SPEED_100MBPS: |
76a95d75 | 3486 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
da0436e9 JS |
3487 | break; |
3488 | case LPFC_ASYNC_LINK_SPEED_1GBPS: | |
76a95d75 | 3489 | link_speed = LPFC_LINK_SPEED_1GHZ; |
da0436e9 JS |
3490 | break; |
3491 | case LPFC_ASYNC_LINK_SPEED_10GBPS: | |
76a95d75 | 3492 | link_speed = LPFC_LINK_SPEED_10GHZ; |
da0436e9 JS |
3493 | break; |
3494 | default: | |
3495 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3496 | "0483 Invalid link-attention link speed: x%x\n", | |
3497 | bf_get(lpfc_acqe_link_speed, acqe_link)); | |
76a95d75 | 3498 | link_speed = LPFC_LINK_SPEED_UNKNOWN; |
da0436e9 JS |
3499 | break; |
3500 | } | |
3501 | return link_speed; | |
3502 | } | |
3503 | ||
3504 | /** | |
70f3c073 | 3505 | * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event |
da0436e9 JS |
3506 | * @phba: pointer to lpfc hba data structure. |
3507 | * @acqe_link: pointer to the async link completion queue entry. | |
3508 | * | |
70f3c073 | 3509 | * This routine is to handle the SLI4 asynchronous FCoE link event. |
da0436e9 JS |
3510 | **/ |
3511 | static void | |
3512 | lpfc_sli4_async_link_evt(struct lpfc_hba *phba, | |
3513 | struct lpfc_acqe_link *acqe_link) | |
3514 | { | |
3515 | struct lpfc_dmabuf *mp; | |
3516 | LPFC_MBOXQ_t *pmb; | |
3517 | MAILBOX_t *mb; | |
76a95d75 | 3518 | struct lpfc_mbx_read_top *la; |
da0436e9 | 3519 | uint8_t att_type; |
76a95d75 | 3520 | int rc; |
da0436e9 JS |
3521 | |
3522 | att_type = lpfc_sli4_parse_latt_type(phba, acqe_link); | |
76a95d75 | 3523 | if (att_type != LPFC_ATT_LINK_DOWN && att_type != LPFC_ATT_LINK_UP) |
da0436e9 | 3524 | return; |
32b9793f | 3525 | phba->fcoe_eventtag = acqe_link->event_tag; |
da0436e9 JS |
3526 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3527 | if (!pmb) { | |
3528 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3529 | "0395 The mboxq allocation failed\n"); | |
3530 | return; | |
3531 | } | |
3532 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
3533 | if (!mp) { | |
3534 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3535 | "0396 The lpfc_dmabuf allocation failed\n"); | |
3536 | goto out_free_pmb; | |
3537 | } | |
3538 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
3539 | if (!mp->virt) { | |
3540 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3541 | "0397 The mbuf allocation failed\n"); | |
3542 | goto out_free_dmabuf; | |
3543 | } | |
3544 | ||
3545 | /* Cleanup any outstanding ELS commands */ | |
3546 | lpfc_els_flush_all_cmd(phba); | |
3547 | ||
3548 | /* Block ELS IOCBs until we have done process link event */ | |
3549 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
3550 | ||
3551 | /* Update link event statistics */ | |
3552 | phba->sli.slistat.link_event++; | |
3553 | ||
76a95d75 JS |
3554 | /* Create lpfc_handle_latt mailbox command from link ACQE */ |
3555 | lpfc_read_topology(phba, pmb, mp); | |
3556 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
da0436e9 JS |
3557 | pmb->vport = phba->pport; |
3558 | ||
da0436e9 JS |
3559 | /* Keep the link status for extra SLI4 state machine reference */ |
3560 | phba->sli4_hba.link_state.speed = | |
3561 | bf_get(lpfc_acqe_link_speed, acqe_link); | |
3562 | phba->sli4_hba.link_state.duplex = | |
3563 | bf_get(lpfc_acqe_link_duplex, acqe_link); | |
3564 | phba->sli4_hba.link_state.status = | |
3565 | bf_get(lpfc_acqe_link_status, acqe_link); | |
70f3c073 JS |
3566 | phba->sli4_hba.link_state.type = |
3567 | bf_get(lpfc_acqe_link_type, acqe_link); | |
3568 | phba->sli4_hba.link_state.number = | |
3569 | bf_get(lpfc_acqe_link_number, acqe_link); | |
da0436e9 JS |
3570 | phba->sli4_hba.link_state.fault = |
3571 | bf_get(lpfc_acqe_link_fault, acqe_link); | |
65467b6b | 3572 | phba->sli4_hba.link_state.logical_speed = |
70f3c073 JS |
3573 | bf_get(lpfc_acqe_logical_link_speed, acqe_link); |
3574 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
c31098ce JS |
3575 | "2900 Async FC/FCoE Link event - Speed:%dGBit " |
3576 | "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d " | |
3577 | "Logical speed:%dMbps Fault:%d\n", | |
70f3c073 JS |
3578 | phba->sli4_hba.link_state.speed, |
3579 | phba->sli4_hba.link_state.topology, | |
3580 | phba->sli4_hba.link_state.status, | |
3581 | phba->sli4_hba.link_state.type, | |
3582 | phba->sli4_hba.link_state.number, | |
3583 | phba->sli4_hba.link_state.logical_speed * 10, | |
3584 | phba->sli4_hba.link_state.fault); | |
76a95d75 JS |
3585 | /* |
3586 | * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch | |
3587 | * topology info. Note: Optional for non FC-AL ports. | |
3588 | */ | |
3589 | if (!(phba->hba_flag & HBA_FCOE_MODE)) { | |
3590 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3591 | if (rc == MBX_NOT_FINISHED) | |
3592 | goto out_free_dmabuf; | |
3593 | return; | |
3594 | } | |
3595 | /* | |
3596 | * For FCoE Mode: fill in all the topology information we need and call | |
3597 | * the READ_TOPOLOGY completion routine to continue without actually | |
3598 | * sending the READ_TOPOLOGY mailbox command to the port. | |
3599 | */ | |
3600 | /* Parse and translate status field */ | |
3601 | mb = &pmb->u.mb; | |
3602 | mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link); | |
3603 | ||
3604 | /* Parse and translate link attention fields */ | |
3605 | la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop; | |
3606 | la->eventTag = acqe_link->event_tag; | |
3607 | bf_set(lpfc_mbx_read_top_att_type, la, att_type); | |
3608 | bf_set(lpfc_mbx_read_top_link_spd, la, | |
3609 | lpfc_sli4_parse_latt_link_speed(phba, acqe_link)); | |
3610 | ||
3611 | /* Fake the the following irrelvant fields */ | |
3612 | bf_set(lpfc_mbx_read_top_topology, la, LPFC_TOPOLOGY_PT_PT); | |
3613 | bf_set(lpfc_mbx_read_top_alpa_granted, la, 0); | |
3614 | bf_set(lpfc_mbx_read_top_il, la, 0); | |
3615 | bf_set(lpfc_mbx_read_top_pb, la, 0); | |
3616 | bf_set(lpfc_mbx_read_top_fa, la, 0); | |
3617 | bf_set(lpfc_mbx_read_top_mm, la, 0); | |
da0436e9 JS |
3618 | |
3619 | /* Invoke the lpfc_handle_latt mailbox command callback function */ | |
76a95d75 | 3620 | lpfc_mbx_cmpl_read_topology(phba, pmb); |
da0436e9 | 3621 | |
5b75da2f | 3622 | return; |
da0436e9 JS |
3623 | |
3624 | out_free_dmabuf: | |
3625 | kfree(mp); | |
3626 | out_free_pmb: | |
3627 | mempool_free(pmb, phba->mbox_mem_pool); | |
3628 | } | |
3629 | ||
70f3c073 JS |
3630 | /** |
3631 | * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event | |
3632 | * @phba: pointer to lpfc hba data structure. | |
3633 | * @acqe_fc: pointer to the async fc completion queue entry. | |
3634 | * | |
3635 | * This routine is to handle the SLI4 asynchronous FC event. It will simply log | |
3636 | * that the event was received and then issue a read_topology mailbox command so | |
3637 | * that the rest of the driver will treat it the same as SLI3. | |
3638 | **/ | |
3639 | static void | |
3640 | lpfc_sli4_async_fc_evt(struct lpfc_hba *phba, struct lpfc_acqe_fc_la *acqe_fc) | |
3641 | { | |
3642 | struct lpfc_dmabuf *mp; | |
3643 | LPFC_MBOXQ_t *pmb; | |
3644 | int rc; | |
3645 | ||
3646 | if (bf_get(lpfc_trailer_type, acqe_fc) != | |
3647 | LPFC_FC_LA_EVENT_TYPE_FC_LINK) { | |
3648 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3649 | "2895 Non FC link Event detected.(%d)\n", | |
3650 | bf_get(lpfc_trailer_type, acqe_fc)); | |
3651 | return; | |
3652 | } | |
3653 | /* Keep the link status for extra SLI4 state machine reference */ | |
3654 | phba->sli4_hba.link_state.speed = | |
3655 | bf_get(lpfc_acqe_fc_la_speed, acqe_fc); | |
3656 | phba->sli4_hba.link_state.duplex = LPFC_ASYNC_LINK_DUPLEX_FULL; | |
3657 | phba->sli4_hba.link_state.topology = | |
3658 | bf_get(lpfc_acqe_fc_la_topology, acqe_fc); | |
3659 | phba->sli4_hba.link_state.status = | |
3660 | bf_get(lpfc_acqe_fc_la_att_type, acqe_fc); | |
3661 | phba->sli4_hba.link_state.type = | |
3662 | bf_get(lpfc_acqe_fc_la_port_type, acqe_fc); | |
3663 | phba->sli4_hba.link_state.number = | |
3664 | bf_get(lpfc_acqe_fc_la_port_number, acqe_fc); | |
3665 | phba->sli4_hba.link_state.fault = | |
3666 | bf_get(lpfc_acqe_link_fault, acqe_fc); | |
3667 | phba->sli4_hba.link_state.logical_speed = | |
3668 | bf_get(lpfc_acqe_fc_la_llink_spd, acqe_fc); | |
3669 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3670 | "2896 Async FC event - Speed:%dGBaud Topology:x%x " | |
3671 | "LA Type:x%x Port Type:%d Port Number:%d Logical speed:" | |
3672 | "%dMbps Fault:%d\n", | |
3673 | phba->sli4_hba.link_state.speed, | |
3674 | phba->sli4_hba.link_state.topology, | |
3675 | phba->sli4_hba.link_state.status, | |
3676 | phba->sli4_hba.link_state.type, | |
3677 | phba->sli4_hba.link_state.number, | |
3678 | phba->sli4_hba.link_state.logical_speed * 10, | |
3679 | phba->sli4_hba.link_state.fault); | |
3680 | pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
3681 | if (!pmb) { | |
3682 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3683 | "2897 The mboxq allocation failed\n"); | |
3684 | return; | |
3685 | } | |
3686 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
3687 | if (!mp) { | |
3688 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3689 | "2898 The lpfc_dmabuf allocation failed\n"); | |
3690 | goto out_free_pmb; | |
3691 | } | |
3692 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); | |
3693 | if (!mp->virt) { | |
3694 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3695 | "2899 The mbuf allocation failed\n"); | |
3696 | goto out_free_dmabuf; | |
3697 | } | |
3698 | ||
3699 | /* Cleanup any outstanding ELS commands */ | |
3700 | lpfc_els_flush_all_cmd(phba); | |
3701 | ||
3702 | /* Block ELS IOCBs until we have done process link event */ | |
3703 | phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT; | |
3704 | ||
3705 | /* Update link event statistics */ | |
3706 | phba->sli.slistat.link_event++; | |
3707 | ||
3708 | /* Create lpfc_handle_latt mailbox command from link ACQE */ | |
3709 | lpfc_read_topology(phba, pmb, mp); | |
3710 | pmb->mbox_cmpl = lpfc_mbx_cmpl_read_topology; | |
3711 | pmb->vport = phba->pport; | |
3712 | ||
3713 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); | |
3714 | if (rc == MBX_NOT_FINISHED) | |
3715 | goto out_free_dmabuf; | |
3716 | return; | |
3717 | ||
3718 | out_free_dmabuf: | |
3719 | kfree(mp); | |
3720 | out_free_pmb: | |
3721 | mempool_free(pmb, phba->mbox_mem_pool); | |
3722 | } | |
3723 | ||
3724 | /** | |
3725 | * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event | |
3726 | * @phba: pointer to lpfc hba data structure. | |
3727 | * @acqe_fc: pointer to the async SLI completion queue entry. | |
3728 | * | |
3729 | * This routine is to handle the SLI4 asynchronous SLI events. | |
3730 | **/ | |
3731 | static void | |
3732 | lpfc_sli4_async_sli_evt(struct lpfc_hba *phba, struct lpfc_acqe_sli *acqe_sli) | |
3733 | { | |
4b8bae08 JS |
3734 | char port_name; |
3735 | char message[80]; | |
3736 | uint8_t status; | |
3737 | struct lpfc_acqe_misconfigured_event *misconfigured; | |
3738 | ||
3739 | /* special case misconfigured event as it contains data for all ports */ | |
3740 | if ((bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
3741 | LPFC_SLI_INTF_IF_TYPE_2) || | |
3742 | (bf_get(lpfc_trailer_type, acqe_sli) != | |
3743 | LPFC_SLI_EVENT_TYPE_MISCONFIGURED)) { | |
3744 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
3745 | "2901 Async SLI event - Event Data1:x%08x Event Data2:" | |
3746 | "x%08x SLI Event Type:%d\n", | |
3747 | acqe_sli->event_data1, acqe_sli->event_data2, | |
3748 | bf_get(lpfc_trailer_type, acqe_sli)); | |
3749 | return; | |
3750 | } | |
3751 | ||
3752 | port_name = phba->Port[0]; | |
3753 | if (port_name == 0x00) | |
3754 | port_name = '?'; /* get port name is empty */ | |
3755 | ||
3756 | misconfigured = (struct lpfc_acqe_misconfigured_event *) | |
3757 | &acqe_sli->event_data1; | |
3758 | ||
3759 | /* fetch the status for this port */ | |
3760 | switch (phba->sli4_hba.lnk_info.lnk_no) { | |
3761 | case LPFC_LINK_NUMBER_0: | |
3762 | status = bf_get(lpfc_sli_misconfigured_port0, | |
3763 | &misconfigured->theEvent); | |
3764 | break; | |
3765 | case LPFC_LINK_NUMBER_1: | |
3766 | status = bf_get(lpfc_sli_misconfigured_port1, | |
3767 | &misconfigured->theEvent); | |
3768 | break; | |
3769 | case LPFC_LINK_NUMBER_2: | |
3770 | status = bf_get(lpfc_sli_misconfigured_port2, | |
3771 | &misconfigured->theEvent); | |
3772 | break; | |
3773 | case LPFC_LINK_NUMBER_3: | |
3774 | status = bf_get(lpfc_sli_misconfigured_port3, | |
3775 | &misconfigured->theEvent); | |
3776 | break; | |
3777 | default: | |
3778 | status = ~LPFC_SLI_EVENT_STATUS_VALID; | |
3779 | break; | |
3780 | } | |
3781 | ||
3782 | switch (status) { | |
3783 | case LPFC_SLI_EVENT_STATUS_VALID: | |
3784 | return; /* no message if the sfp is okay */ | |
3785 | case LPFC_SLI_EVENT_STATUS_NOT_PRESENT: | |
3786 | sprintf(message, "Not installed"); | |
3787 | break; | |
3788 | case LPFC_SLI_EVENT_STATUS_WRONG_TYPE: | |
3789 | sprintf(message, | |
3790 | "Optics of two types installed"); | |
3791 | break; | |
3792 | case LPFC_SLI_EVENT_STATUS_UNSUPPORTED: | |
3793 | sprintf(message, "Incompatible optics"); | |
3794 | break; | |
3795 | default: | |
3796 | /* firmware is reporting a status we don't know about */ | |
3797 | sprintf(message, "Unknown event status x%02x", status); | |
3798 | break; | |
3799 | } | |
3800 | ||
3801 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
3802 | "3176 Misconfigured Physical Port - " | |
3803 | "Port Name %c %s\n", port_name, message); | |
70f3c073 JS |
3804 | } |
3805 | ||
fc2b989b JS |
3806 | /** |
3807 | * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport | |
3808 | * @vport: pointer to vport data structure. | |
3809 | * | |
3810 | * This routine is to perform Clear Virtual Link (CVL) on a vport in | |
3811 | * response to a CVL event. | |
3812 | * | |
3813 | * Return the pointer to the ndlp with the vport if successful, otherwise | |
3814 | * return NULL. | |
3815 | **/ | |
3816 | static struct lpfc_nodelist * | |
3817 | lpfc_sli4_perform_vport_cvl(struct lpfc_vport *vport) | |
3818 | { | |
3819 | struct lpfc_nodelist *ndlp; | |
3820 | struct Scsi_Host *shost; | |
3821 | struct lpfc_hba *phba; | |
3822 | ||
3823 | if (!vport) | |
3824 | return NULL; | |
fc2b989b JS |
3825 | phba = vport->phba; |
3826 | if (!phba) | |
3827 | return NULL; | |
78730cfe JS |
3828 | ndlp = lpfc_findnode_did(vport, Fabric_DID); |
3829 | if (!ndlp) { | |
3830 | /* Cannot find existing Fabric ndlp, so allocate a new one */ | |
3831 | ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); | |
3832 | if (!ndlp) | |
3833 | return 0; | |
3834 | lpfc_nlp_init(vport, ndlp, Fabric_DID); | |
3835 | /* Set the node type */ | |
3836 | ndlp->nlp_type |= NLP_FABRIC; | |
3837 | /* Put ndlp onto node list */ | |
3838 | lpfc_enqueue_node(vport, ndlp); | |
3839 | } else if (!NLP_CHK_NODE_ACT(ndlp)) { | |
3840 | /* re-setup ndlp without removing from node list */ | |
3841 | ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE); | |
3842 | if (!ndlp) | |
3843 | return 0; | |
3844 | } | |
63e801ce JS |
3845 | if ((phba->pport->port_state < LPFC_FLOGI) && |
3846 | (phba->pport->port_state != LPFC_VPORT_FAILED)) | |
fc2b989b JS |
3847 | return NULL; |
3848 | /* If virtual link is not yet instantiated ignore CVL */ | |
63e801ce JS |
3849 | if ((vport != phba->pport) && (vport->port_state < LPFC_FDISC) |
3850 | && (vport->port_state != LPFC_VPORT_FAILED)) | |
fc2b989b JS |
3851 | return NULL; |
3852 | shost = lpfc_shost_from_vport(vport); | |
3853 | if (!shost) | |
3854 | return NULL; | |
3855 | lpfc_linkdown_port(vport); | |
3856 | lpfc_cleanup_pending_mbox(vport); | |
3857 | spin_lock_irq(shost->host_lock); | |
3858 | vport->fc_flag |= FC_VPORT_CVL_RCVD; | |
3859 | spin_unlock_irq(shost->host_lock); | |
3860 | ||
3861 | return ndlp; | |
3862 | } | |
3863 | ||
3864 | /** | |
3865 | * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports | |
3866 | * @vport: pointer to lpfc hba data structure. | |
3867 | * | |
3868 | * This routine is to perform Clear Virtual Link (CVL) on all vports in | |
3869 | * response to a FCF dead event. | |
3870 | **/ | |
3871 | static void | |
3872 | lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba *phba) | |
3873 | { | |
3874 | struct lpfc_vport **vports; | |
3875 | int i; | |
3876 | ||
3877 | vports = lpfc_create_vport_work_array(phba); | |
3878 | if (vports) | |
3879 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) | |
3880 | lpfc_sli4_perform_vport_cvl(vports[i]); | |
3881 | lpfc_destroy_vport_work_array(phba, vports); | |
3882 | } | |
3883 | ||
da0436e9 | 3884 | /** |
76a95d75 | 3885 | * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event |
da0436e9 JS |
3886 | * @phba: pointer to lpfc hba data structure. |
3887 | * @acqe_link: pointer to the async fcoe completion queue entry. | |
3888 | * | |
3889 | * This routine is to handle the SLI4 asynchronous fcoe event. | |
3890 | **/ | |
3891 | static void | |
76a95d75 | 3892 | lpfc_sli4_async_fip_evt(struct lpfc_hba *phba, |
70f3c073 | 3893 | struct lpfc_acqe_fip *acqe_fip) |
da0436e9 | 3894 | { |
70f3c073 | 3895 | uint8_t event_type = bf_get(lpfc_trailer_type, acqe_fip); |
da0436e9 | 3896 | int rc; |
6669f9bb JS |
3897 | struct lpfc_vport *vport; |
3898 | struct lpfc_nodelist *ndlp; | |
3899 | struct Scsi_Host *shost; | |
695a814e JS |
3900 | int active_vlink_present; |
3901 | struct lpfc_vport **vports; | |
3902 | int i; | |
da0436e9 | 3903 | |
70f3c073 JS |
3904 | phba->fc_eventTag = acqe_fip->event_tag; |
3905 | phba->fcoe_eventtag = acqe_fip->event_tag; | |
da0436e9 | 3906 | switch (event_type) { |
70f3c073 JS |
3907 | case LPFC_FIP_EVENT_TYPE_NEW_FCF: |
3908 | case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD: | |
3909 | if (event_type == LPFC_FIP_EVENT_TYPE_NEW_FCF) | |
999d813f JS |
3910 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
3911 | LOG_DISCOVERY, | |
a93ff37a JS |
3912 | "2546 New FCF event, evt_tag:x%x, " |
3913 | "index:x%x\n", | |
70f3c073 JS |
3914 | acqe_fip->event_tag, |
3915 | acqe_fip->index); | |
999d813f JS |
3916 | else |
3917 | lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | | |
3918 | LOG_DISCOVERY, | |
a93ff37a JS |
3919 | "2788 FCF param modified event, " |
3920 | "evt_tag:x%x, index:x%x\n", | |
70f3c073 JS |
3921 | acqe_fip->event_tag, |
3922 | acqe_fip->index); | |
38b92ef8 | 3923 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
0c9ab6f5 JS |
3924 | /* |
3925 | * During period of FCF discovery, read the FCF | |
3926 | * table record indexed by the event to update | |
a93ff37a | 3927 | * FCF roundrobin failover eligible FCF bmask. |
0c9ab6f5 JS |
3928 | */ |
3929 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | | |
3930 | LOG_DISCOVERY, | |
a93ff37a JS |
3931 | "2779 Read FCF (x%x) for updating " |
3932 | "roundrobin FCF failover bmask\n", | |
70f3c073 JS |
3933 | acqe_fip->index); |
3934 | rc = lpfc_sli4_read_fcf_rec(phba, acqe_fip->index); | |
0c9ab6f5 | 3935 | } |
38b92ef8 JS |
3936 | |
3937 | /* If the FCF discovery is in progress, do nothing. */ | |
3804dc84 | 3938 | spin_lock_irq(&phba->hbalock); |
a93ff37a | 3939 | if (phba->hba_flag & FCF_TS_INPROG) { |
38b92ef8 JS |
3940 | spin_unlock_irq(&phba->hbalock); |
3941 | break; | |
3942 | } | |
3943 | /* If fast FCF failover rescan event is pending, do nothing */ | |
3944 | if (phba->fcf.fcf_flag & FCF_REDISC_EVT) { | |
3945 | spin_unlock_irq(&phba->hbalock); | |
3946 | break; | |
3947 | } | |
3948 | ||
3949 | /* If the FCF has been in discovered state, do nothing. */ | |
3804dc84 JS |
3950 | if (phba->fcf.fcf_flag & FCF_SCAN_DONE) { |
3951 | spin_unlock_irq(&phba->hbalock); | |
3952 | break; | |
3953 | } | |
3954 | spin_unlock_irq(&phba->hbalock); | |
38b92ef8 | 3955 | |
0c9ab6f5 JS |
3956 | /* Otherwise, scan the entire FCF table and re-discover SAN */ |
3957 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, | |
a93ff37a JS |
3958 | "2770 Start FCF table scan per async FCF " |
3959 | "event, evt_tag:x%x, index:x%x\n", | |
70f3c073 | 3960 | acqe_fip->event_tag, acqe_fip->index); |
0c9ab6f5 JS |
3961 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, |
3962 | LPFC_FCOE_FCF_GET_FIRST); | |
da0436e9 | 3963 | if (rc) |
0c9ab6f5 JS |
3964 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
3965 | "2547 Issue FCF scan read FCF mailbox " | |
a93ff37a | 3966 | "command failed (x%x)\n", rc); |
da0436e9 JS |
3967 | break; |
3968 | ||
70f3c073 | 3969 | case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL: |
da0436e9 | 3970 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
e4e74273 | 3971 | "2548 FCF Table full count 0x%x tag 0x%x\n", |
70f3c073 JS |
3972 | bf_get(lpfc_acqe_fip_fcf_count, acqe_fip), |
3973 | acqe_fip->event_tag); | |
da0436e9 JS |
3974 | break; |
3975 | ||
70f3c073 | 3976 | case LPFC_FIP_EVENT_TYPE_FCF_DEAD: |
80c17849 | 3977 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
0c9ab6f5 | 3978 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
a93ff37a | 3979 | "2549 FCF (x%x) disconnected from network, " |
70f3c073 | 3980 | "tag:x%x\n", acqe_fip->index, acqe_fip->event_tag); |
38b92ef8 JS |
3981 | /* |
3982 | * If we are in the middle of FCF failover process, clear | |
3983 | * the corresponding FCF bit in the roundrobin bitmap. | |
da0436e9 | 3984 | */ |
fc2b989b | 3985 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 3986 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
fc2b989b | 3987 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 | 3988 | /* Update FLOGI FCF failover eligible FCF bmask */ |
70f3c073 | 3989 | lpfc_sli4_fcf_rr_index_clear(phba, acqe_fip->index); |
fc2b989b JS |
3990 | break; |
3991 | } | |
38b92ef8 JS |
3992 | spin_unlock_irq(&phba->hbalock); |
3993 | ||
3994 | /* If the event is not for currently used fcf do nothing */ | |
70f3c073 | 3995 | if (phba->fcf.current_rec.fcf_indx != acqe_fip->index) |
38b92ef8 JS |
3996 | break; |
3997 | ||
3998 | /* | |
3999 | * Otherwise, request the port to rediscover the entire FCF | |
4000 | * table for a fast recovery from case that the current FCF | |
4001 | * is no longer valid as we are not in the middle of FCF | |
4002 | * failover process already. | |
4003 | */ | |
4004 | spin_lock_irq(&phba->hbalock); | |
fc2b989b | 4005 | /* Mark the fast failover process in progress */ |
0c9ab6f5 | 4006 | phba->fcf.fcf_flag |= FCF_DEAD_DISC; |
fc2b989b | 4007 | spin_unlock_irq(&phba->hbalock); |
38b92ef8 | 4008 | |
0c9ab6f5 JS |
4009 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
4010 | "2771 Start FCF fast failover process due to " | |
4011 | "FCF DEAD event: evt_tag:x%x, fcf_index:x%x " | |
70f3c073 | 4012 | "\n", acqe_fip->event_tag, acqe_fip->index); |
fc2b989b JS |
4013 | rc = lpfc_sli4_redisc_fcf_table(phba); |
4014 | if (rc) { | |
0c9ab6f5 JS |
4015 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
4016 | LOG_DISCOVERY, | |
4017 | "2772 Issue FCF rediscover mabilbox " | |
4018 | "command failed, fail through to FCF " | |
4019 | "dead event\n"); | |
fc2b989b | 4020 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 4021 | phba->fcf.fcf_flag &= ~FCF_DEAD_DISC; |
fc2b989b JS |
4022 | spin_unlock_irq(&phba->hbalock); |
4023 | /* | |
4024 | * Last resort will fail over by treating this | |
4025 | * as a link down to FCF registration. | |
4026 | */ | |
4027 | lpfc_sli4_fcf_dead_failthrough(phba); | |
38b92ef8 JS |
4028 | } else { |
4029 | /* Reset FCF roundrobin bmask for new discovery */ | |
7d791df7 | 4030 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
38b92ef8 JS |
4031 | /* |
4032 | * Handling fast FCF failover to a DEAD FCF event is | |
4033 | * considered equalivant to receiving CVL to all vports. | |
fc2b989b JS |
4034 | */ |
4035 | lpfc_sli4_perform_all_vport_cvl(phba); | |
38b92ef8 | 4036 | } |
da0436e9 | 4037 | break; |
70f3c073 | 4038 | case LPFC_FIP_EVENT_TYPE_CVL: |
80c17849 | 4039 | phba->fcoe_cvl_eventtag = acqe_fip->event_tag; |
0c9ab6f5 | 4040 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
6669f9bb | 4041 | "2718 Clear Virtual Link Received for VPI 0x%x" |
70f3c073 | 4042 | " tag 0x%x\n", acqe_fip->index, acqe_fip->event_tag); |
6d368e53 | 4043 | |
6669f9bb | 4044 | vport = lpfc_find_vport_by_vpid(phba, |
5248a749 | 4045 | acqe_fip->index); |
fc2b989b | 4046 | ndlp = lpfc_sli4_perform_vport_cvl(vport); |
6669f9bb JS |
4047 | if (!ndlp) |
4048 | break; | |
695a814e JS |
4049 | active_vlink_present = 0; |
4050 | ||
4051 | vports = lpfc_create_vport_work_array(phba); | |
4052 | if (vports) { | |
4053 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; | |
4054 | i++) { | |
4055 | if ((!(vports[i]->fc_flag & | |
4056 | FC_VPORT_CVL_RCVD)) && | |
4057 | (vports[i]->port_state > LPFC_FDISC)) { | |
4058 | active_vlink_present = 1; | |
4059 | break; | |
4060 | } | |
4061 | } | |
4062 | lpfc_destroy_vport_work_array(phba, vports); | |
4063 | } | |
4064 | ||
4065 | if (active_vlink_present) { | |
4066 | /* | |
4067 | * If there are other active VLinks present, | |
4068 | * re-instantiate the Vlink using FDISC. | |
4069 | */ | |
6669f9bb | 4070 | mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ); |
fc2b989b | 4071 | shost = lpfc_shost_from_vport(vport); |
6669f9bb JS |
4072 | spin_lock_irq(shost->host_lock); |
4073 | ndlp->nlp_flag |= NLP_DELAY_TMO; | |
4074 | spin_unlock_irq(shost->host_lock); | |
695a814e JS |
4075 | ndlp->nlp_last_elscmd = ELS_CMD_FDISC; |
4076 | vport->port_state = LPFC_FDISC; | |
4077 | } else { | |
ecfd03c6 JS |
4078 | /* |
4079 | * Otherwise, we request port to rediscover | |
4080 | * the entire FCF table for a fast recovery | |
4081 | * from possible case that the current FCF | |
0c9ab6f5 JS |
4082 | * is no longer valid if we are not already |
4083 | * in the FCF failover process. | |
ecfd03c6 | 4084 | */ |
fc2b989b | 4085 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 4086 | if (phba->fcf.fcf_flag & FCF_DISCOVERY) { |
fc2b989b JS |
4087 | spin_unlock_irq(&phba->hbalock); |
4088 | break; | |
4089 | } | |
4090 | /* Mark the fast failover process in progress */ | |
0c9ab6f5 | 4091 | phba->fcf.fcf_flag |= FCF_ACVL_DISC; |
fc2b989b | 4092 | spin_unlock_irq(&phba->hbalock); |
0c9ab6f5 JS |
4093 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | |
4094 | LOG_DISCOVERY, | |
a93ff37a | 4095 | "2773 Start FCF failover per CVL, " |
70f3c073 | 4096 | "evt_tag:x%x\n", acqe_fip->event_tag); |
ecfd03c6 | 4097 | rc = lpfc_sli4_redisc_fcf_table(phba); |
fc2b989b | 4098 | if (rc) { |
0c9ab6f5 JS |
4099 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | |
4100 | LOG_DISCOVERY, | |
4101 | "2774 Issue FCF rediscover " | |
4102 | "mabilbox command failed, " | |
4103 | "through to CVL event\n"); | |
fc2b989b | 4104 | spin_lock_irq(&phba->hbalock); |
0c9ab6f5 | 4105 | phba->fcf.fcf_flag &= ~FCF_ACVL_DISC; |
fc2b989b | 4106 | spin_unlock_irq(&phba->hbalock); |
ecfd03c6 JS |
4107 | /* |
4108 | * Last resort will be re-try on the | |
4109 | * the current registered FCF entry. | |
4110 | */ | |
4111 | lpfc_retry_pport_discovery(phba); | |
38b92ef8 JS |
4112 | } else |
4113 | /* | |
4114 | * Reset FCF roundrobin bmask for new | |
4115 | * discovery. | |
4116 | */ | |
7d791df7 | 4117 | lpfc_sli4_clear_fcf_rr_bmask(phba); |
6669f9bb JS |
4118 | } |
4119 | break; | |
da0436e9 JS |
4120 | default: |
4121 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4122 | "0288 Unknown FCoE event type 0x%x event tag " | |
70f3c073 | 4123 | "0x%x\n", event_type, acqe_fip->event_tag); |
da0436e9 JS |
4124 | break; |
4125 | } | |
4126 | } | |
4127 | ||
4128 | /** | |
4129 | * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event | |
4130 | * @phba: pointer to lpfc hba data structure. | |
4131 | * @acqe_link: pointer to the async dcbx completion queue entry. | |
4132 | * | |
4133 | * This routine is to handle the SLI4 asynchronous dcbx event. | |
4134 | **/ | |
4135 | static void | |
4136 | lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba, | |
4137 | struct lpfc_acqe_dcbx *acqe_dcbx) | |
4138 | { | |
4d9ab994 | 4139 | phba->fc_eventTag = acqe_dcbx->event_tag; |
da0436e9 JS |
4140 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
4141 | "0290 The SLI4 DCBX asynchronous event is not " | |
4142 | "handled yet\n"); | |
4143 | } | |
4144 | ||
b19a061a JS |
4145 | /** |
4146 | * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event | |
4147 | * @phba: pointer to lpfc hba data structure. | |
4148 | * @acqe_link: pointer to the async grp5 completion queue entry. | |
4149 | * | |
4150 | * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event | |
4151 | * is an asynchronous notified of a logical link speed change. The Port | |
4152 | * reports the logical link speed in units of 10Mbps. | |
4153 | **/ | |
4154 | static void | |
4155 | lpfc_sli4_async_grp5_evt(struct lpfc_hba *phba, | |
4156 | struct lpfc_acqe_grp5 *acqe_grp5) | |
4157 | { | |
4158 | uint16_t prev_ll_spd; | |
4159 | ||
4160 | phba->fc_eventTag = acqe_grp5->event_tag; | |
4161 | phba->fcoe_eventtag = acqe_grp5->event_tag; | |
4162 | prev_ll_spd = phba->sli4_hba.link_state.logical_speed; | |
4163 | phba->sli4_hba.link_state.logical_speed = | |
4164 | (bf_get(lpfc_acqe_grp5_llink_spd, acqe_grp5)); | |
4165 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
4166 | "2789 GRP5 Async Event: Updating logical link speed " | |
4167 | "from %dMbps to %dMbps\n", (prev_ll_spd * 10), | |
4168 | (phba->sli4_hba.link_state.logical_speed*10)); | |
4169 | } | |
4170 | ||
da0436e9 JS |
4171 | /** |
4172 | * lpfc_sli4_async_event_proc - Process all the pending asynchronous event | |
4173 | * @phba: pointer to lpfc hba data structure. | |
4174 | * | |
4175 | * This routine is invoked by the worker thread to process all the pending | |
4176 | * SLI4 asynchronous events. | |
4177 | **/ | |
4178 | void lpfc_sli4_async_event_proc(struct lpfc_hba *phba) | |
4179 | { | |
4180 | struct lpfc_cq_event *cq_event; | |
4181 | ||
4182 | /* First, declare the async event has been handled */ | |
4183 | spin_lock_irq(&phba->hbalock); | |
4184 | phba->hba_flag &= ~ASYNC_EVENT; | |
4185 | spin_unlock_irq(&phba->hbalock); | |
4186 | /* Now, handle all the async events */ | |
4187 | while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) { | |
4188 | /* Get the first event from the head of the event queue */ | |
4189 | spin_lock_irq(&phba->hbalock); | |
4190 | list_remove_head(&phba->sli4_hba.sp_asynce_work_queue, | |
4191 | cq_event, struct lpfc_cq_event, list); | |
4192 | spin_unlock_irq(&phba->hbalock); | |
4193 | /* Process the asynchronous event */ | |
4194 | switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) { | |
4195 | case LPFC_TRAILER_CODE_LINK: | |
4196 | lpfc_sli4_async_link_evt(phba, | |
4197 | &cq_event->cqe.acqe_link); | |
4198 | break; | |
4199 | case LPFC_TRAILER_CODE_FCOE: | |
70f3c073 | 4200 | lpfc_sli4_async_fip_evt(phba, &cq_event->cqe.acqe_fip); |
da0436e9 JS |
4201 | break; |
4202 | case LPFC_TRAILER_CODE_DCBX: | |
4203 | lpfc_sli4_async_dcbx_evt(phba, | |
4204 | &cq_event->cqe.acqe_dcbx); | |
4205 | break; | |
b19a061a JS |
4206 | case LPFC_TRAILER_CODE_GRP5: |
4207 | lpfc_sli4_async_grp5_evt(phba, | |
4208 | &cq_event->cqe.acqe_grp5); | |
4209 | break; | |
70f3c073 JS |
4210 | case LPFC_TRAILER_CODE_FC: |
4211 | lpfc_sli4_async_fc_evt(phba, &cq_event->cqe.acqe_fc); | |
4212 | break; | |
4213 | case LPFC_TRAILER_CODE_SLI: | |
4214 | lpfc_sli4_async_sli_evt(phba, &cq_event->cqe.acqe_sli); | |
4215 | break; | |
da0436e9 JS |
4216 | default: |
4217 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
4218 | "1804 Invalid asynchrous event code: " | |
4219 | "x%x\n", bf_get(lpfc_trailer_code, | |
4220 | &cq_event->cqe.mcqe_cmpl)); | |
4221 | break; | |
4222 | } | |
4223 | /* Free the completion event processed to the free pool */ | |
4224 | lpfc_sli4_cq_event_release(phba, cq_event); | |
4225 | } | |
4226 | } | |
4227 | ||
ecfd03c6 JS |
4228 | /** |
4229 | * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event | |
4230 | * @phba: pointer to lpfc hba data structure. | |
4231 | * | |
4232 | * This routine is invoked by the worker thread to process FCF table | |
4233 | * rediscovery pending completion event. | |
4234 | **/ | |
4235 | void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *phba) | |
4236 | { | |
4237 | int rc; | |
4238 | ||
4239 | spin_lock_irq(&phba->hbalock); | |
4240 | /* Clear FCF rediscovery timeout event */ | |
4241 | phba->fcf.fcf_flag &= ~FCF_REDISC_EVT; | |
4242 | /* Clear driver fast failover FCF record flag */ | |
4243 | phba->fcf.failover_rec.flag = 0; | |
4244 | /* Set state for FCF fast failover */ | |
4245 | phba->fcf.fcf_flag |= FCF_REDISC_FOV; | |
4246 | spin_unlock_irq(&phba->hbalock); | |
4247 | ||
4248 | /* Scan FCF table from the first entry to re-discover SAN */ | |
0c9ab6f5 | 4249 | lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY, |
a93ff37a | 4250 | "2777 Start post-quiescent FCF table scan\n"); |
0c9ab6f5 | 4251 | rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST); |
ecfd03c6 | 4252 | if (rc) |
0c9ab6f5 JS |
4253 | lpfc_printf_log(phba, KERN_ERR, LOG_FIP | LOG_DISCOVERY, |
4254 | "2747 Issue FCF scan read FCF mailbox " | |
4255 | "command failed 0x%x\n", rc); | |
ecfd03c6 JS |
4256 | } |
4257 | ||
da0436e9 JS |
4258 | /** |
4259 | * lpfc_api_table_setup - Set up per hba pci-device group func api jump table | |
4260 | * @phba: pointer to lpfc hba data structure. | |
4261 | * @dev_grp: The HBA PCI-Device group number. | |
4262 | * | |
4263 | * This routine is invoked to set up the per HBA PCI-Device group function | |
4264 | * API jump table entries. | |
4265 | * | |
4266 | * Return: 0 if success, otherwise -ENODEV | |
4267 | **/ | |
4268 | int | |
4269 | lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
4270 | { | |
4271 | int rc; | |
4272 | ||
4273 | /* Set up lpfc PCI-device group */ | |
4274 | phba->pci_dev_grp = dev_grp; | |
4275 | ||
4276 | /* The LPFC_PCI_DEV_OC uses SLI4 */ | |
4277 | if (dev_grp == LPFC_PCI_DEV_OC) | |
4278 | phba->sli_rev = LPFC_SLI_REV4; | |
4279 | ||
4280 | /* Set up device INIT API function jump table */ | |
4281 | rc = lpfc_init_api_table_setup(phba, dev_grp); | |
4282 | if (rc) | |
4283 | return -ENODEV; | |
4284 | /* Set up SCSI API function jump table */ | |
4285 | rc = lpfc_scsi_api_table_setup(phba, dev_grp); | |
4286 | if (rc) | |
4287 | return -ENODEV; | |
4288 | /* Set up SLI API function jump table */ | |
4289 | rc = lpfc_sli_api_table_setup(phba, dev_grp); | |
4290 | if (rc) | |
4291 | return -ENODEV; | |
4292 | /* Set up MBOX API function jump table */ | |
4293 | rc = lpfc_mbox_api_table_setup(phba, dev_grp); | |
4294 | if (rc) | |
4295 | return -ENODEV; | |
4296 | ||
4297 | return 0; | |
5b75da2f JS |
4298 | } |
4299 | ||
4300 | /** | |
3621a710 | 4301 | * lpfc_log_intr_mode - Log the active interrupt mode |
5b75da2f JS |
4302 | * @phba: pointer to lpfc hba data structure. |
4303 | * @intr_mode: active interrupt mode adopted. | |
4304 | * | |
4305 | * This routine it invoked to log the currently used active interrupt mode | |
4306 | * to the device. | |
3772a991 JS |
4307 | **/ |
4308 | static void lpfc_log_intr_mode(struct lpfc_hba *phba, uint32_t intr_mode) | |
5b75da2f JS |
4309 | { |
4310 | switch (intr_mode) { | |
4311 | case 0: | |
4312 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4313 | "0470 Enable INTx interrupt mode.\n"); | |
4314 | break; | |
4315 | case 1: | |
4316 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4317 | "0481 Enabled MSI interrupt mode.\n"); | |
4318 | break; | |
4319 | case 2: | |
4320 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
4321 | "0480 Enabled MSI-X interrupt mode.\n"); | |
4322 | break; | |
4323 | default: | |
4324 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4325 | "0482 Illegal interrupt mode.\n"); | |
4326 | break; | |
4327 | } | |
4328 | return; | |
4329 | } | |
4330 | ||
5b75da2f | 4331 | /** |
3772a991 | 4332 | * lpfc_enable_pci_dev - Enable a generic PCI device. |
5b75da2f JS |
4333 | * @phba: pointer to lpfc hba data structure. |
4334 | * | |
3772a991 JS |
4335 | * This routine is invoked to enable the PCI device that is common to all |
4336 | * PCI devices. | |
5b75da2f JS |
4337 | * |
4338 | * Return codes | |
af901ca1 | 4339 | * 0 - successful |
3772a991 | 4340 | * other values - error |
5b75da2f | 4341 | **/ |
3772a991 JS |
4342 | static int |
4343 | lpfc_enable_pci_dev(struct lpfc_hba *phba) | |
5b75da2f | 4344 | { |
3772a991 | 4345 | struct pci_dev *pdev; |
079b5c91 | 4346 | int bars = 0; |
5b75da2f | 4347 | |
3772a991 JS |
4348 | /* Obtain PCI device reference */ |
4349 | if (!phba->pcidev) | |
4350 | goto out_error; | |
4351 | else | |
4352 | pdev = phba->pcidev; | |
4353 | /* Select PCI BARs */ | |
4354 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
4355 | /* Enable PCI device */ | |
4356 | if (pci_enable_device_mem(pdev)) | |
4357 | goto out_error; | |
4358 | /* Request PCI resource for the device */ | |
4359 | if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME)) | |
4360 | goto out_disable_device; | |
4361 | /* Set up device as PCI master and save state for EEH */ | |
4362 | pci_set_master(pdev); | |
4363 | pci_try_set_mwi(pdev); | |
4364 | pci_save_state(pdev); | |
5b75da2f | 4365 | |
0558056c JS |
4366 | /* PCIe EEH recovery on powerpc platforms needs fundamental reset */ |
4367 | if (pci_find_capability(pdev, PCI_CAP_ID_EXP)) | |
4368 | pdev->needs_freset = 1; | |
4369 | ||
3772a991 | 4370 | return 0; |
5b75da2f | 4371 | |
3772a991 JS |
4372 | out_disable_device: |
4373 | pci_disable_device(pdev); | |
4374 | out_error: | |
079b5c91 JS |
4375 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
4376 | "1401 Failed to enable pci device, bars:x%x\n", bars); | |
3772a991 | 4377 | return -ENODEV; |
5b75da2f JS |
4378 | } |
4379 | ||
4380 | /** | |
3772a991 | 4381 | * lpfc_disable_pci_dev - Disable a generic PCI device. |
5b75da2f JS |
4382 | * @phba: pointer to lpfc hba data structure. |
4383 | * | |
3772a991 JS |
4384 | * This routine is invoked to disable the PCI device that is common to all |
4385 | * PCI devices. | |
5b75da2f JS |
4386 | **/ |
4387 | static void | |
3772a991 | 4388 | lpfc_disable_pci_dev(struct lpfc_hba *phba) |
5b75da2f | 4389 | { |
3772a991 JS |
4390 | struct pci_dev *pdev; |
4391 | int bars; | |
5b75da2f | 4392 | |
3772a991 JS |
4393 | /* Obtain PCI device reference */ |
4394 | if (!phba->pcidev) | |
4395 | return; | |
4396 | else | |
4397 | pdev = phba->pcidev; | |
4398 | /* Select PCI BARs */ | |
4399 | bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
4400 | /* Release PCI resource and disable PCI device */ | |
4401 | pci_release_selected_regions(pdev, bars); | |
4402 | pci_disable_device(pdev); | |
4403 | /* Null out PCI private reference to driver */ | |
4404 | pci_set_drvdata(pdev, NULL); | |
5b75da2f JS |
4405 | |
4406 | return; | |
4407 | } | |
4408 | ||
e59058c4 | 4409 | /** |
3772a991 JS |
4410 | * lpfc_reset_hba - Reset a hba |
4411 | * @phba: pointer to lpfc hba data structure. | |
e59058c4 | 4412 | * |
3772a991 JS |
4413 | * This routine is invoked to reset a hba device. It brings the HBA |
4414 | * offline, performs a board restart, and then brings the board back | |
4415 | * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up | |
4416 | * on outstanding mailbox commands. | |
e59058c4 | 4417 | **/ |
3772a991 JS |
4418 | void |
4419 | lpfc_reset_hba(struct lpfc_hba *phba) | |
dea3101e | 4420 | { |
3772a991 JS |
4421 | /* If resets are disabled then set error state and return. */ |
4422 | if (!phba->cfg_enable_hba_reset) { | |
4423 | phba->link_state = LPFC_HBA_ERROR; | |
4424 | return; | |
4425 | } | |
618a5230 | 4426 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
3772a991 JS |
4427 | lpfc_offline(phba); |
4428 | lpfc_sli_brdrestart(phba); | |
4429 | lpfc_online(phba); | |
4430 | lpfc_unblock_mgmt_io(phba); | |
4431 | } | |
dea3101e | 4432 | |
0a96e975 JS |
4433 | /** |
4434 | * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions | |
4435 | * @phba: pointer to lpfc hba data structure. | |
4436 | * | |
4437 | * This function enables the PCI SR-IOV virtual functions to a physical | |
4438 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to | |
4439 | * enable the number of virtual functions to the physical function. As | |
4440 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() | |
4441 | * API call does not considered as an error condition for most of the device. | |
4442 | **/ | |
4443 | uint16_t | |
4444 | lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba *phba) | |
4445 | { | |
4446 | struct pci_dev *pdev = phba->pcidev; | |
4447 | uint16_t nr_virtfn; | |
4448 | int pos; | |
4449 | ||
0a96e975 JS |
4450 | pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
4451 | if (pos == 0) | |
4452 | return 0; | |
4453 | ||
4454 | pci_read_config_word(pdev, pos + PCI_SRIOV_TOTAL_VF, &nr_virtfn); | |
4455 | return nr_virtfn; | |
4456 | } | |
4457 | ||
912e3acd JS |
4458 | /** |
4459 | * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions | |
4460 | * @phba: pointer to lpfc hba data structure. | |
4461 | * @nr_vfn: number of virtual functions to be enabled. | |
4462 | * | |
4463 | * This function enables the PCI SR-IOV virtual functions to a physical | |
4464 | * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to | |
4465 | * enable the number of virtual functions to the physical function. As | |
4466 | * not all devices support SR-IOV, the return code from the pci_enable_sriov() | |
4467 | * API call does not considered as an error condition for most of the device. | |
4468 | **/ | |
4469 | int | |
4470 | lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba *phba, int nr_vfn) | |
4471 | { | |
4472 | struct pci_dev *pdev = phba->pcidev; | |
0a96e975 | 4473 | uint16_t max_nr_vfn; |
912e3acd JS |
4474 | int rc; |
4475 | ||
0a96e975 JS |
4476 | max_nr_vfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
4477 | if (nr_vfn > max_nr_vfn) { | |
4478 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4479 | "3057 Requested vfs (%d) greater than " | |
4480 | "supported vfs (%d)", nr_vfn, max_nr_vfn); | |
4481 | return -EINVAL; | |
4482 | } | |
4483 | ||
912e3acd JS |
4484 | rc = pci_enable_sriov(pdev, nr_vfn); |
4485 | if (rc) { | |
4486 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4487 | "2806 Failed to enable sriov on this device " | |
4488 | "with vfn number nr_vf:%d, rc:%d\n", | |
4489 | nr_vfn, rc); | |
4490 | } else | |
4491 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4492 | "2807 Successful enable sriov on this device " | |
4493 | "with vfn number nr_vf:%d\n", nr_vfn); | |
4494 | return rc; | |
4495 | } | |
4496 | ||
3772a991 JS |
4497 | /** |
4498 | * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev. | |
4499 | * @phba: pointer to lpfc hba data structure. | |
4500 | * | |
4501 | * This routine is invoked to set up the driver internal resources specific to | |
4502 | * support the SLI-3 HBA device it attached to. | |
4503 | * | |
4504 | * Return codes | |
af901ca1 | 4505 | * 0 - successful |
3772a991 JS |
4506 | * other values - error |
4507 | **/ | |
4508 | static int | |
4509 | lpfc_sli_driver_resource_setup(struct lpfc_hba *phba) | |
4510 | { | |
4511 | struct lpfc_sli *psli; | |
912e3acd | 4512 | int rc; |
dea3101e | 4513 | |
2e0fef85 | 4514 | /* |
3772a991 | 4515 | * Initialize timers used by driver |
2e0fef85 | 4516 | */ |
dea3101e | 4517 | |
3772a991 | 4518 | /* Heartbeat timer */ |
858c9f6c JS |
4519 | init_timer(&phba->hb_tmofunc); |
4520 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
4521 | phba->hb_tmofunc.data = (unsigned long)phba; | |
4522 | ||
dea3101e | 4523 | psli = &phba->sli; |
3772a991 | 4524 | /* MBOX heartbeat timer */ |
dea3101e JB |
4525 | init_timer(&psli->mbox_tmo); |
4526 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
2e0fef85 | 4527 | psli->mbox_tmo.data = (unsigned long) phba; |
3772a991 | 4528 | /* FCP polling mode timer */ |
875fbdfe JSEC |
4529 | init_timer(&phba->fcp_poll_timer); |
4530 | phba->fcp_poll_timer.function = lpfc_poll_timeout; | |
2e0fef85 | 4531 | phba->fcp_poll_timer.data = (unsigned long) phba; |
3772a991 | 4532 | /* Fabric block timer */ |
92d7f7b0 JS |
4533 | init_timer(&phba->fabric_block_timer); |
4534 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
4535 | phba->fabric_block_timer.data = (unsigned long) phba; | |
3772a991 | 4536 | /* EA polling mode timer */ |
9399627f JS |
4537 | init_timer(&phba->eratt_poll); |
4538 | phba->eratt_poll.function = lpfc_poll_eratt; | |
4539 | phba->eratt_poll.data = (unsigned long) phba; | |
dea3101e | 4540 | |
3772a991 JS |
4541 | /* Host attention work mask setup */ |
4542 | phba->work_ha_mask = (HA_ERATT | HA_MBATT | HA_LATT); | |
4543 | phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4)); | |
dea3101e | 4544 | |
3772a991 JS |
4545 | /* Get all the module params for configuring this host */ |
4546 | lpfc_get_cfgparam(phba); | |
49198b37 JS |
4547 | if (phba->pcidev->device == PCI_DEVICE_ID_HORNET) { |
4548 | phba->menlo_flag |= HBA_MENLO_SUPPORT; | |
4549 | /* check for menlo minimum sg count */ | |
4550 | if (phba->cfg_sg_seg_cnt < LPFC_DEFAULT_MENLO_SG_SEG_CNT) | |
4551 | phba->cfg_sg_seg_cnt = LPFC_DEFAULT_MENLO_SG_SEG_CNT; | |
4552 | } | |
4553 | ||
2a76a283 JS |
4554 | if (!phba->sli.ring) |
4555 | phba->sli.ring = (struct lpfc_sli_ring *) | |
4556 | kzalloc(LPFC_SLI3_MAX_RING * | |
4557 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); | |
4558 | if (!phba->sli.ring) | |
4559 | return -ENOMEM; | |
4560 | ||
dea3101e | 4561 | /* |
3772a991 JS |
4562 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size |
4563 | * used to create the sg_dma_buf_pool must be dynamically calculated. | |
4564 | * 2 segments are added since the IOCB needs a command and response bde. | |
dea3101e | 4565 | */ |
3772a991 JS |
4566 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + |
4567 | sizeof(struct fcp_rsp) + | |
4568 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); | |
4569 | ||
4570 | if (phba->cfg_enable_bg) { | |
4571 | phba->cfg_sg_seg_cnt = LPFC_MAX_SG_SEG_CNT; | |
4572 | phba->cfg_sg_dma_buf_size += | |
4573 | phba->cfg_prot_sg_seg_cnt * sizeof(struct ulp_bde64); | |
901a920f | 4574 | } |
dea3101e | 4575 | |
3772a991 JS |
4576 | /* Also reinitialize the host templates with new values. */ |
4577 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
4578 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
dea3101e | 4579 | |
3772a991 JS |
4580 | phba->max_vpi = LPFC_MAX_VPI; |
4581 | /* This will be set to correct value after config_port mbox */ | |
4582 | phba->max_vports = 0; | |
dea3101e | 4583 | |
3772a991 JS |
4584 | /* |
4585 | * Initialize the SLI Layer to run with lpfc HBAs. | |
4586 | */ | |
4587 | lpfc_sli_setup(phba); | |
4588 | lpfc_sli_queue_setup(phba); | |
ed957684 | 4589 | |
3772a991 JS |
4590 | /* Allocate device driver memory */ |
4591 | if (lpfc_mem_alloc(phba, BPL_ALIGN_SZ)) | |
4592 | return -ENOMEM; | |
51ef4c26 | 4593 | |
912e3acd JS |
4594 | /* |
4595 | * Enable sr-iov virtual functions if supported and configured | |
4596 | * through the module parameter. | |
4597 | */ | |
4598 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
4599 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, | |
4600 | phba->cfg_sriov_nr_virtfn); | |
4601 | if (rc) { | |
4602 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4603 | "2808 Requested number of SR-IOV " | |
4604 | "virtual functions (%d) is not " | |
4605 | "supported\n", | |
4606 | phba->cfg_sriov_nr_virtfn); | |
4607 | phba->cfg_sriov_nr_virtfn = 0; | |
4608 | } | |
4609 | } | |
4610 | ||
3772a991 JS |
4611 | return 0; |
4612 | } | |
ed957684 | 4613 | |
3772a991 JS |
4614 | /** |
4615 | * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev | |
4616 | * @phba: pointer to lpfc hba data structure. | |
4617 | * | |
4618 | * This routine is invoked to unset the driver internal resources set up | |
4619 | * specific for supporting the SLI-3 HBA device it attached to. | |
4620 | **/ | |
4621 | static void | |
4622 | lpfc_sli_driver_resource_unset(struct lpfc_hba *phba) | |
4623 | { | |
4624 | /* Free device driver memory allocated */ | |
4625 | lpfc_mem_free_all(phba); | |
3163f725 | 4626 | |
3772a991 JS |
4627 | return; |
4628 | } | |
dea3101e | 4629 | |
3772a991 | 4630 | /** |
da0436e9 | 4631 | * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev |
3772a991 JS |
4632 | * @phba: pointer to lpfc hba data structure. |
4633 | * | |
da0436e9 JS |
4634 | * This routine is invoked to set up the driver internal resources specific to |
4635 | * support the SLI-4 HBA device it attached to. | |
3772a991 JS |
4636 | * |
4637 | * Return codes | |
af901ca1 | 4638 | * 0 - successful |
da0436e9 | 4639 | * other values - error |
3772a991 JS |
4640 | **/ |
4641 | static int | |
da0436e9 | 4642 | lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba) |
3772a991 | 4643 | { |
da0436e9 | 4644 | struct lpfc_sli *psli; |
28baac74 JS |
4645 | LPFC_MBOXQ_t *mboxq; |
4646 | int rc, i, hbq_count, buf_size, dma_buf_size, max_buf_size; | |
4647 | uint8_t pn_page[LPFC_MAX_SUPPORTED_PAGES] = {0}; | |
4648 | struct lpfc_mqe *mqe; | |
085c647c | 4649 | int longs, sli_family; |
acd6859b | 4650 | int sges_per_segment; |
da0436e9 JS |
4651 | |
4652 | /* Before proceed, wait for POST done and device ready */ | |
4653 | rc = lpfc_sli4_post_status_check(phba); | |
4654 | if (rc) | |
4655 | return -ENODEV; | |
4656 | ||
3772a991 | 4657 | /* |
da0436e9 | 4658 | * Initialize timers used by driver |
3772a991 | 4659 | */ |
3772a991 | 4660 | |
da0436e9 JS |
4661 | /* Heartbeat timer */ |
4662 | init_timer(&phba->hb_tmofunc); | |
4663 | phba->hb_tmofunc.function = lpfc_hb_timeout; | |
4664 | phba->hb_tmofunc.data = (unsigned long)phba; | |
19ca7609 JS |
4665 | init_timer(&phba->rrq_tmr); |
4666 | phba->rrq_tmr.function = lpfc_rrq_timeout; | |
4667 | phba->rrq_tmr.data = (unsigned long)phba; | |
3772a991 | 4668 | |
da0436e9 JS |
4669 | psli = &phba->sli; |
4670 | /* MBOX heartbeat timer */ | |
4671 | init_timer(&psli->mbox_tmo); | |
4672 | psli->mbox_tmo.function = lpfc_mbox_timeout; | |
4673 | psli->mbox_tmo.data = (unsigned long) phba; | |
4674 | /* Fabric block timer */ | |
4675 | init_timer(&phba->fabric_block_timer); | |
4676 | phba->fabric_block_timer.function = lpfc_fabric_block_timeout; | |
4677 | phba->fabric_block_timer.data = (unsigned long) phba; | |
4678 | /* EA polling mode timer */ | |
4679 | init_timer(&phba->eratt_poll); | |
4680 | phba->eratt_poll.function = lpfc_poll_eratt; | |
4681 | phba->eratt_poll.data = (unsigned long) phba; | |
ecfd03c6 JS |
4682 | /* FCF rediscover timer */ |
4683 | init_timer(&phba->fcf.redisc_wait); | |
4684 | phba->fcf.redisc_wait.function = lpfc_sli4_fcf_redisc_wait_tmo; | |
4685 | phba->fcf.redisc_wait.data = (unsigned long)phba; | |
4686 | ||
7ad20aa9 JS |
4687 | /* |
4688 | * Control structure for handling external multi-buffer mailbox | |
4689 | * command pass-through. | |
4690 | */ | |
4691 | memset((uint8_t *)&phba->mbox_ext_buf_ctx, 0, | |
4692 | sizeof(struct lpfc_mbox_ext_buf_ctx)); | |
4693 | INIT_LIST_HEAD(&phba->mbox_ext_buf_ctx.ext_dmabuf_list); | |
4694 | ||
da0436e9 JS |
4695 | /* |
4696 | * We need to do a READ_CONFIG mailbox command here before | |
4697 | * calling lpfc_get_cfgparam. For VFs this will report the | |
4698 | * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings. | |
4699 | * All of the resources allocated | |
4700 | * for this Port are tied to these values. | |
4701 | */ | |
4702 | /* Get all the module params for configuring this host */ | |
4703 | lpfc_get_cfgparam(phba); | |
4704 | phba->max_vpi = LPFC_MAX_VPI; | |
4705 | /* This will be set to correct value after the read_config mbox */ | |
4706 | phba->max_vports = 0; | |
3772a991 | 4707 | |
da0436e9 JS |
4708 | /* Program the default value of vlan_id and fc_map */ |
4709 | phba->valid_vlan = 0; | |
4710 | phba->fc_map[0] = LPFC_FCOE_FCF_MAP0; | |
4711 | phba->fc_map[1] = LPFC_FCOE_FCF_MAP1; | |
4712 | phba->fc_map[2] = LPFC_FCOE_FCF_MAP2; | |
3772a991 | 4713 | |
acd6859b JS |
4714 | /* With BlockGuard we can have multiple SGEs per Data Segemnt */ |
4715 | sges_per_segment = 1; | |
4716 | if (phba->cfg_enable_bg) | |
4717 | sges_per_segment = 2; | |
4718 | ||
2a76a283 JS |
4719 | /* |
4720 | * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands | |
4721 | * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple. | |
4722 | */ | |
4723 | if (!phba->sli.ring) | |
4724 | phba->sli.ring = kzalloc( | |
4725 | (LPFC_SLI3_MAX_RING + phba->cfg_fcp_eq_count) * | |
4726 | sizeof(struct lpfc_sli_ring), GFP_KERNEL); | |
4727 | if (!phba->sli.ring) | |
4728 | return -ENOMEM; | |
da0436e9 JS |
4729 | /* |
4730 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size | |
4731 | * used to create the sg_dma_buf_pool must be dynamically calculated. | |
4732 | * 2 segments are added since the IOCB needs a command and response bde. | |
4733 | * To insure that the scsi sgl does not cross a 4k page boundary only | |
28baac74 | 4734 | * sgl sizes of must be a power of 2. |
da0436e9 | 4735 | */ |
28baac74 | 4736 | buf_size = (sizeof(struct fcp_cmnd) + sizeof(struct fcp_rsp) + |
acd6859b JS |
4737 | (((phba->cfg_sg_seg_cnt * sges_per_segment) + 2) * |
4738 | sizeof(struct sli4_sge))); | |
085c647c JS |
4739 | |
4740 | sli_family = bf_get(lpfc_sli_intf_sli_family, &phba->sli4_hba.sli_intf); | |
4741 | max_buf_size = LPFC_SLI4_MAX_BUF_SIZE; | |
4742 | switch (sli_family) { | |
4743 | case LPFC_SLI_INTF_FAMILY_BE2: | |
4744 | case LPFC_SLI_INTF_FAMILY_BE3: | |
4745 | /* There is a single hint for BE - 2 pages per BPL. */ | |
4746 | if (bf_get(lpfc_sli_intf_sli_hint1, &phba->sli4_hba.sli_intf) == | |
4747 | LPFC_SLI_INTF_SLI_HINT1_1) | |
4748 | max_buf_size = LPFC_SLI4_FL1_MAX_BUF_SIZE; | |
4749 | break; | |
4750 | case LPFC_SLI_INTF_FAMILY_LNCR_A0: | |
4751 | case LPFC_SLI_INTF_FAMILY_LNCR_B0: | |
4752 | default: | |
4753 | break; | |
4754 | } | |
acd6859b | 4755 | |
28baac74 JS |
4756 | for (dma_buf_size = LPFC_SLI4_MIN_BUF_SIZE; |
4757 | dma_buf_size < max_buf_size && buf_size > dma_buf_size; | |
4758 | dma_buf_size = dma_buf_size << 1) | |
4759 | ; | |
4760 | if (dma_buf_size == max_buf_size) | |
4761 | phba->cfg_sg_seg_cnt = (dma_buf_size - | |
4762 | sizeof(struct fcp_cmnd) - sizeof(struct fcp_rsp) - | |
4763 | (2 * sizeof(struct sli4_sge))) / | |
4764 | sizeof(struct sli4_sge); | |
4765 | phba->cfg_sg_dma_buf_size = dma_buf_size; | |
3772a991 | 4766 | |
da0436e9 JS |
4767 | /* Initialize buffer queue management fields */ |
4768 | hbq_count = lpfc_sli_hbq_count(); | |
4769 | for (i = 0; i < hbq_count; ++i) | |
4770 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
4771 | INIT_LIST_HEAD(&phba->rb_pend_list); | |
4772 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc; | |
4773 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free; | |
3772a991 | 4774 | |
da0436e9 JS |
4775 | /* |
4776 | * Initialize the SLI Layer to run with lpfc SLI4 HBAs. | |
4777 | */ | |
4778 | /* Initialize the Abort scsi buffer list used by driver */ | |
4779 | spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock); | |
4780 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
4781 | /* This abort list used by worker thread */ | |
4782 | spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock); | |
3772a991 | 4783 | |
da0436e9 | 4784 | /* |
6d368e53 | 4785 | * Initialize driver internal slow-path work queues |
da0436e9 | 4786 | */ |
3772a991 | 4787 | |
da0436e9 JS |
4788 | /* Driver internel slow-path CQ Event pool */ |
4789 | INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool); | |
4790 | /* Response IOCB work queue list */ | |
45ed1190 | 4791 | INIT_LIST_HEAD(&phba->sli4_hba.sp_queue_event); |
da0436e9 JS |
4792 | /* Asynchronous event CQ Event work queue list */ |
4793 | INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue); | |
4794 | /* Fast-path XRI aborted CQ Event work queue list */ | |
4795 | INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue); | |
4796 | /* Slow-path XRI aborted CQ Event work queue list */ | |
4797 | INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue); | |
4798 | /* Receive queue CQ Event work queue list */ | |
4799 | INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue); | |
4800 | ||
6d368e53 JS |
4801 | /* Initialize extent block lists. */ |
4802 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_blk_list); | |
4803 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_xri_blk_list); | |
4804 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_vfi_blk_list); | |
4805 | INIT_LIST_HEAD(&phba->lpfc_vpi_blk_list); | |
4806 | ||
da0436e9 JS |
4807 | /* Initialize the driver internal SLI layer lists. */ |
4808 | lpfc_sli_setup(phba); | |
4809 | lpfc_sli_queue_setup(phba); | |
3772a991 | 4810 | |
da0436e9 JS |
4811 | /* Allocate device driver memory */ |
4812 | rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ); | |
4813 | if (rc) | |
4814 | return -ENOMEM; | |
4815 | ||
2fcee4bf JS |
4816 | /* IF Type 2 ports get initialized now. */ |
4817 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
4818 | LPFC_SLI_INTF_IF_TYPE_2) { | |
4819 | rc = lpfc_pci_function_reset(phba); | |
4820 | if (unlikely(rc)) | |
4821 | return -ENODEV; | |
4822 | } | |
4823 | ||
da0436e9 JS |
4824 | /* Create the bootstrap mailbox command */ |
4825 | rc = lpfc_create_bootstrap_mbox(phba); | |
4826 | if (unlikely(rc)) | |
4827 | goto out_free_mem; | |
4828 | ||
4829 | /* Set up the host's endian order with the device. */ | |
4830 | rc = lpfc_setup_endian_order(phba); | |
4831 | if (unlikely(rc)) | |
4832 | goto out_free_bsmbx; | |
4833 | ||
4834 | /* Set up the hba's configuration parameters. */ | |
4835 | rc = lpfc_sli4_read_config(phba); | |
4836 | if (unlikely(rc)) | |
4837 | goto out_free_bsmbx; | |
4838 | ||
2fcee4bf JS |
4839 | /* IF Type 0 ports get initialized now. */ |
4840 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
4841 | LPFC_SLI_INTF_IF_TYPE_0) { | |
4842 | rc = lpfc_pci_function_reset(phba); | |
4843 | if (unlikely(rc)) | |
4844 | goto out_free_bsmbx; | |
4845 | } | |
da0436e9 | 4846 | |
cb5172ea JS |
4847 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, |
4848 | GFP_KERNEL); | |
4849 | if (!mboxq) { | |
4850 | rc = -ENOMEM; | |
4851 | goto out_free_bsmbx; | |
4852 | } | |
4853 | ||
fedd3b7b | 4854 | /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */ |
cb5172ea JS |
4855 | lpfc_supported_pages(mboxq); |
4856 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
fedd3b7b JS |
4857 | if (!rc) { |
4858 | mqe = &mboxq->u.mqe; | |
4859 | memcpy(&pn_page[0], ((uint8_t *)&mqe->un.supp_pages.word3), | |
4860 | LPFC_MAX_SUPPORTED_PAGES); | |
4861 | for (i = 0; i < LPFC_MAX_SUPPORTED_PAGES; i++) { | |
4862 | switch (pn_page[i]) { | |
4863 | case LPFC_SLI4_PARAMETERS: | |
4864 | phba->sli4_hba.pc_sli4_params.supported = 1; | |
4865 | break; | |
4866 | default: | |
4867 | break; | |
4868 | } | |
4869 | } | |
4870 | /* Read the port's SLI4 Parameters capabilities if supported. */ | |
4871 | if (phba->sli4_hba.pc_sli4_params.supported) | |
4872 | rc = lpfc_pc_sli4_params_get(phba, mboxq); | |
4873 | if (rc) { | |
4874 | mempool_free(mboxq, phba->mbox_mem_pool); | |
4875 | rc = -EIO; | |
4876 | goto out_free_bsmbx; | |
cb5172ea JS |
4877 | } |
4878 | } | |
fedd3b7b JS |
4879 | /* |
4880 | * Get sli4 parameters that override parameters from Port capabilities. | |
6d368e53 JS |
4881 | * If this call fails, it isn't critical unless the SLI4 parameters come |
4882 | * back in conflict. | |
fedd3b7b | 4883 | */ |
6d368e53 JS |
4884 | rc = lpfc_get_sli4_parameters(phba, mboxq); |
4885 | if (rc) { | |
4886 | if (phba->sli4_hba.extents_in_use && | |
4887 | phba->sli4_hba.rpi_hdrs_in_use) { | |
4888 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4889 | "2999 Unsupported SLI4 Parameters " | |
4890 | "Extents and RPI headers enabled.\n"); | |
4891 | goto out_free_bsmbx; | |
4892 | } | |
4893 | } | |
cb5172ea | 4894 | mempool_free(mboxq, phba->mbox_mem_pool); |
5350d872 JS |
4895 | /* Verify all the SLI4 queues */ |
4896 | rc = lpfc_sli4_queue_verify(phba); | |
da0436e9 JS |
4897 | if (rc) |
4898 | goto out_free_bsmbx; | |
4899 | ||
4900 | /* Create driver internal CQE event pool */ | |
4901 | rc = lpfc_sli4_cq_event_pool_create(phba); | |
4902 | if (rc) | |
5350d872 | 4903 | goto out_free_bsmbx; |
da0436e9 | 4904 | |
8a9d2e80 JS |
4905 | /* Initialize sgl lists per host */ |
4906 | lpfc_init_sgl_list(phba); | |
4907 | ||
4908 | /* Allocate and initialize active sgl array */ | |
da0436e9 JS |
4909 | rc = lpfc_init_active_sgl_array(phba); |
4910 | if (rc) { | |
4911 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4912 | "1430 Failed to initialize sgl list.\n"); | |
8a9d2e80 | 4913 | goto out_destroy_cq_event_pool; |
da0436e9 | 4914 | } |
da0436e9 JS |
4915 | rc = lpfc_sli4_init_rpi_hdrs(phba); |
4916 | if (rc) { | |
4917 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4918 | "1432 Failed to initialize rpi headers.\n"); | |
4919 | goto out_free_active_sgl; | |
4920 | } | |
4921 | ||
a93ff37a | 4922 | /* Allocate eligible FCF bmask memory for FCF roundrobin failover */ |
0c9ab6f5 JS |
4923 | longs = (LPFC_SLI4_FCF_TBL_INDX_MAX + BITS_PER_LONG - 1)/BITS_PER_LONG; |
4924 | phba->fcf.fcf_rr_bmask = kzalloc(longs * sizeof(unsigned long), | |
4925 | GFP_KERNEL); | |
4926 | if (!phba->fcf.fcf_rr_bmask) { | |
4927 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4928 | "2759 Failed allocate memory for FCF round " | |
4929 | "robin failover bmask\n"); | |
0558056c | 4930 | rc = -ENOMEM; |
0c9ab6f5 JS |
4931 | goto out_remove_rpi_hdrs; |
4932 | } | |
4933 | ||
5350d872 JS |
4934 | /* |
4935 | * The cfg_fcp_eq_count can be zero whenever there is exactly one | |
4936 | * interrupt vector. This is not an error | |
4937 | */ | |
4938 | if (phba->cfg_fcp_eq_count) { | |
4939 | phba->sli4_hba.fcp_eq_hdl = | |
4940 | kzalloc((sizeof(struct lpfc_fcp_eq_hdl) * | |
da0436e9 | 4941 | phba->cfg_fcp_eq_count), GFP_KERNEL); |
5350d872 JS |
4942 | if (!phba->sli4_hba.fcp_eq_hdl) { |
4943 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4944 | "2572 Failed allocate memory for " | |
4945 | "fast-path per-EQ handle array\n"); | |
4946 | rc = -ENOMEM; | |
4947 | goto out_free_fcf_rr_bmask; | |
4948 | } | |
da0436e9 JS |
4949 | } |
4950 | ||
4951 | phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) * | |
4952 | phba->sli4_hba.cfg_eqn), GFP_KERNEL); | |
4953 | if (!phba->sli4_hba.msix_entries) { | |
4954 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4955 | "2573 Failed allocate memory for msi-x " | |
4956 | "interrupt vector entries\n"); | |
0558056c | 4957 | rc = -ENOMEM; |
da0436e9 JS |
4958 | goto out_free_fcp_eq_hdl; |
4959 | } | |
4960 | ||
912e3acd JS |
4961 | /* |
4962 | * Enable sr-iov virtual functions if supported and configured | |
4963 | * through the module parameter. | |
4964 | */ | |
4965 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
4966 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, | |
4967 | phba->cfg_sriov_nr_virtfn); | |
4968 | if (rc) { | |
4969 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
4970 | "3020 Requested number of SR-IOV " | |
4971 | "virtual functions (%d) is not " | |
4972 | "supported\n", | |
4973 | phba->cfg_sriov_nr_virtfn); | |
4974 | phba->cfg_sriov_nr_virtfn = 0; | |
4975 | } | |
4976 | } | |
4977 | ||
5248a749 | 4978 | return 0; |
da0436e9 JS |
4979 | |
4980 | out_free_fcp_eq_hdl: | |
4981 | kfree(phba->sli4_hba.fcp_eq_hdl); | |
0c9ab6f5 JS |
4982 | out_free_fcf_rr_bmask: |
4983 | kfree(phba->fcf.fcf_rr_bmask); | |
da0436e9 JS |
4984 | out_remove_rpi_hdrs: |
4985 | lpfc_sli4_remove_rpi_hdrs(phba); | |
4986 | out_free_active_sgl: | |
4987 | lpfc_free_active_sgl(phba); | |
da0436e9 JS |
4988 | out_destroy_cq_event_pool: |
4989 | lpfc_sli4_cq_event_pool_destroy(phba); | |
da0436e9 JS |
4990 | out_free_bsmbx: |
4991 | lpfc_destroy_bootstrap_mbox(phba); | |
4992 | out_free_mem: | |
4993 | lpfc_mem_free(phba); | |
4994 | return rc; | |
4995 | } | |
4996 | ||
4997 | /** | |
4998 | * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev | |
4999 | * @phba: pointer to lpfc hba data structure. | |
5000 | * | |
5001 | * This routine is invoked to unset the driver internal resources set up | |
5002 | * specific for supporting the SLI-4 HBA device it attached to. | |
5003 | **/ | |
5004 | static void | |
5005 | lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba) | |
5006 | { | |
5007 | struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry; | |
5008 | ||
da0436e9 JS |
5009 | /* Free memory allocated for msi-x interrupt vector entries */ |
5010 | kfree(phba->sli4_hba.msix_entries); | |
5011 | ||
5012 | /* Free memory allocated for fast-path work queue handles */ | |
5013 | kfree(phba->sli4_hba.fcp_eq_hdl); | |
5014 | ||
5015 | /* Free the allocated rpi headers. */ | |
5016 | lpfc_sli4_remove_rpi_hdrs(phba); | |
d11e31dd | 5017 | lpfc_sli4_remove_rpis(phba); |
da0436e9 | 5018 | |
0c9ab6f5 JS |
5019 | /* Free eligible FCF index bmask */ |
5020 | kfree(phba->fcf.fcf_rr_bmask); | |
5021 | ||
da0436e9 JS |
5022 | /* Free the ELS sgl list */ |
5023 | lpfc_free_active_sgl(phba); | |
8a9d2e80 | 5024 | lpfc_free_els_sgl_list(phba); |
da0436e9 | 5025 | |
da0436e9 JS |
5026 | /* Free the completion queue EQ event pool */ |
5027 | lpfc_sli4_cq_event_release_all(phba); | |
5028 | lpfc_sli4_cq_event_pool_destroy(phba); | |
5029 | ||
6d368e53 JS |
5030 | /* Release resource identifiers. */ |
5031 | lpfc_sli4_dealloc_resource_identifiers(phba); | |
5032 | ||
da0436e9 JS |
5033 | /* Free the bsmbx region. */ |
5034 | lpfc_destroy_bootstrap_mbox(phba); | |
5035 | ||
5036 | /* Free the SLI Layer memory with SLI4 HBAs */ | |
5037 | lpfc_mem_free_all(phba); | |
5038 | ||
5039 | /* Free the current connect table */ | |
5040 | list_for_each_entry_safe(conn_entry, next_conn_entry, | |
4d9ab994 JS |
5041 | &phba->fcf_conn_rec_list, list) { |
5042 | list_del_init(&conn_entry->list); | |
da0436e9 | 5043 | kfree(conn_entry); |
4d9ab994 | 5044 | } |
da0436e9 JS |
5045 | |
5046 | return; | |
5047 | } | |
5048 | ||
5049 | /** | |
25985edc | 5050 | * lpfc_init_api_table_setup - Set up init api function jump table |
da0436e9 JS |
5051 | * @phba: The hba struct for which this call is being executed. |
5052 | * @dev_grp: The HBA PCI-Device group number. | |
5053 | * | |
5054 | * This routine sets up the device INIT interface API function jump table | |
5055 | * in @phba struct. | |
5056 | * | |
5057 | * Returns: 0 - success, -ENODEV - failure. | |
5058 | **/ | |
5059 | int | |
5060 | lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp) | |
5061 | { | |
84d1b006 JS |
5062 | phba->lpfc_hba_init_link = lpfc_hba_init_link; |
5063 | phba->lpfc_hba_down_link = lpfc_hba_down_link; | |
7f86059a | 5064 | phba->lpfc_selective_reset = lpfc_selective_reset; |
da0436e9 JS |
5065 | switch (dev_grp) { |
5066 | case LPFC_PCI_DEV_LP: | |
5067 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s3; | |
5068 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; | |
5069 | phba->lpfc_stop_port = lpfc_stop_port_s3; | |
5070 | break; | |
5071 | case LPFC_PCI_DEV_OC: | |
5072 | phba->lpfc_hba_down_post = lpfc_hba_down_post_s4; | |
5073 | phba->lpfc_handle_eratt = lpfc_handle_eratt_s4; | |
5074 | phba->lpfc_stop_port = lpfc_stop_port_s4; | |
5075 | break; | |
5076 | default: | |
5077 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5078 | "1431 Invalid HBA PCI-device group: 0x%x\n", | |
5079 | dev_grp); | |
5080 | return -ENODEV; | |
5081 | break; | |
5082 | } | |
5083 | return 0; | |
5084 | } | |
5085 | ||
5086 | /** | |
5087 | * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources. | |
5088 | * @phba: pointer to lpfc hba data structure. | |
5089 | * | |
5090 | * This routine is invoked to set up the driver internal resources before the | |
5091 | * device specific resource setup to support the HBA device it attached to. | |
5092 | * | |
5093 | * Return codes | |
af901ca1 | 5094 | * 0 - successful |
da0436e9 JS |
5095 | * other values - error |
5096 | **/ | |
5097 | static int | |
5098 | lpfc_setup_driver_resource_phase1(struct lpfc_hba *phba) | |
5099 | { | |
5100 | /* | |
5101 | * Driver resources common to all SLI revisions | |
5102 | */ | |
5103 | atomic_set(&phba->fast_event_count, 0); | |
5104 | spin_lock_init(&phba->hbalock); | |
5105 | ||
5106 | /* Initialize ndlp management spinlock */ | |
5107 | spin_lock_init(&phba->ndlp_lock); | |
5108 | ||
5109 | INIT_LIST_HEAD(&phba->port_list); | |
5110 | INIT_LIST_HEAD(&phba->work_list); | |
5111 | init_waitqueue_head(&phba->wait_4_mlo_m_q); | |
5112 | ||
5113 | /* Initialize the wait queue head for the kernel thread */ | |
5114 | init_waitqueue_head(&phba->work_waitq); | |
5115 | ||
5116 | /* Initialize the scsi buffer list used by driver for scsi IO */ | |
5117 | spin_lock_init(&phba->scsi_buf_list_lock); | |
5118 | INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); | |
5119 | ||
5120 | /* Initialize the fabric iocb list */ | |
5121 | INIT_LIST_HEAD(&phba->fabric_iocb_list); | |
5122 | ||
5123 | /* Initialize list to save ELS buffers */ | |
5124 | INIT_LIST_HEAD(&phba->elsbuf); | |
5125 | ||
5126 | /* Initialize FCF connection rec list */ | |
5127 | INIT_LIST_HEAD(&phba->fcf_conn_rec_list); | |
5128 | ||
5129 | return 0; | |
5130 | } | |
5131 | ||
5132 | /** | |
5133 | * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources. | |
5134 | * @phba: pointer to lpfc hba data structure. | |
5135 | * | |
5136 | * This routine is invoked to set up the driver internal resources after the | |
5137 | * device specific resource setup to support the HBA device it attached to. | |
5138 | * | |
5139 | * Return codes | |
af901ca1 | 5140 | * 0 - successful |
da0436e9 JS |
5141 | * other values - error |
5142 | **/ | |
5143 | static int | |
5144 | lpfc_setup_driver_resource_phase2(struct lpfc_hba *phba) | |
5145 | { | |
5146 | int error; | |
5147 | ||
5148 | /* Startup the kernel thread for this host adapter. */ | |
5149 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
5150 | "lpfc_worker_%d", phba->brd_no); | |
5151 | if (IS_ERR(phba->worker_thread)) { | |
5152 | error = PTR_ERR(phba->worker_thread); | |
5153 | return error; | |
3772a991 JS |
5154 | } |
5155 | ||
5156 | return 0; | |
5157 | } | |
5158 | ||
5159 | /** | |
5160 | * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources. | |
5161 | * @phba: pointer to lpfc hba data structure. | |
5162 | * | |
5163 | * This routine is invoked to unset the driver internal resources set up after | |
5164 | * the device specific resource setup for supporting the HBA device it | |
5165 | * attached to. | |
5166 | **/ | |
5167 | static void | |
5168 | lpfc_unset_driver_resource_phase2(struct lpfc_hba *phba) | |
5169 | { | |
5170 | /* Stop kernel worker thread */ | |
5171 | kthread_stop(phba->worker_thread); | |
5172 | } | |
5173 | ||
5174 | /** | |
5175 | * lpfc_free_iocb_list - Free iocb list. | |
5176 | * @phba: pointer to lpfc hba data structure. | |
5177 | * | |
5178 | * This routine is invoked to free the driver's IOCB list and memory. | |
5179 | **/ | |
5180 | static void | |
5181 | lpfc_free_iocb_list(struct lpfc_hba *phba) | |
5182 | { | |
5183 | struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; | |
5184 | ||
5185 | spin_lock_irq(&phba->hbalock); | |
5186 | list_for_each_entry_safe(iocbq_entry, iocbq_next, | |
5187 | &phba->lpfc_iocb_list, list) { | |
5188 | list_del(&iocbq_entry->list); | |
5189 | kfree(iocbq_entry); | |
5190 | phba->total_iocbq_bufs--; | |
98c9ea5c | 5191 | } |
3772a991 JS |
5192 | spin_unlock_irq(&phba->hbalock); |
5193 | ||
5194 | return; | |
5195 | } | |
5196 | ||
5197 | /** | |
5198 | * lpfc_init_iocb_list - Allocate and initialize iocb list. | |
5199 | * @phba: pointer to lpfc hba data structure. | |
5200 | * | |
5201 | * This routine is invoked to allocate and initizlize the driver's IOCB | |
5202 | * list and set up the IOCB tag array accordingly. | |
5203 | * | |
5204 | * Return codes | |
af901ca1 | 5205 | * 0 - successful |
3772a991 JS |
5206 | * other values - error |
5207 | **/ | |
5208 | static int | |
5209 | lpfc_init_iocb_list(struct lpfc_hba *phba, int iocb_count) | |
5210 | { | |
5211 | struct lpfc_iocbq *iocbq_entry = NULL; | |
5212 | uint16_t iotag; | |
5213 | int i; | |
dea3101e JB |
5214 | |
5215 | /* Initialize and populate the iocb list per host. */ | |
5216 | INIT_LIST_HEAD(&phba->lpfc_iocb_list); | |
3772a991 | 5217 | for (i = 0; i < iocb_count; i++) { |
dd00cc48 | 5218 | iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL); |
dea3101e JB |
5219 | if (iocbq_entry == NULL) { |
5220 | printk(KERN_ERR "%s: only allocated %d iocbs of " | |
5221 | "expected %d count. Unloading driver.\n", | |
cadbd4a5 | 5222 | __func__, i, LPFC_IOCB_LIST_CNT); |
dea3101e JB |
5223 | goto out_free_iocbq; |
5224 | } | |
5225 | ||
604a3e30 JB |
5226 | iotag = lpfc_sli_next_iotag(phba, iocbq_entry); |
5227 | if (iotag == 0) { | |
3772a991 | 5228 | kfree(iocbq_entry); |
604a3e30 | 5229 | printk(KERN_ERR "%s: failed to allocate IOTAG. " |
3772a991 | 5230 | "Unloading driver.\n", __func__); |
604a3e30 JB |
5231 | goto out_free_iocbq; |
5232 | } | |
6d368e53 | 5233 | iocbq_entry->sli4_lxritag = NO_XRI; |
3772a991 | 5234 | iocbq_entry->sli4_xritag = NO_XRI; |
2e0fef85 JS |
5235 | |
5236 | spin_lock_irq(&phba->hbalock); | |
dea3101e JB |
5237 | list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); |
5238 | phba->total_iocbq_bufs++; | |
2e0fef85 | 5239 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
5240 | } |
5241 | ||
3772a991 | 5242 | return 0; |
dea3101e | 5243 | |
3772a991 JS |
5244 | out_free_iocbq: |
5245 | lpfc_free_iocb_list(phba); | |
dea3101e | 5246 | |
3772a991 JS |
5247 | return -ENOMEM; |
5248 | } | |
5e9d9b82 | 5249 | |
3772a991 | 5250 | /** |
8a9d2e80 | 5251 | * lpfc_free_sgl_list - Free a given sgl list. |
da0436e9 | 5252 | * @phba: pointer to lpfc hba data structure. |
8a9d2e80 | 5253 | * @sglq_list: pointer to the head of sgl list. |
3772a991 | 5254 | * |
8a9d2e80 | 5255 | * This routine is invoked to free a give sgl list and memory. |
3772a991 | 5256 | **/ |
8a9d2e80 JS |
5257 | void |
5258 | lpfc_free_sgl_list(struct lpfc_hba *phba, struct list_head *sglq_list) | |
3772a991 | 5259 | { |
da0436e9 | 5260 | struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL; |
8a9d2e80 JS |
5261 | |
5262 | list_for_each_entry_safe(sglq_entry, sglq_next, sglq_list, list) { | |
5263 | list_del(&sglq_entry->list); | |
5264 | lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys); | |
5265 | kfree(sglq_entry); | |
5266 | } | |
5267 | } | |
5268 | ||
5269 | /** | |
5270 | * lpfc_free_els_sgl_list - Free els sgl list. | |
5271 | * @phba: pointer to lpfc hba data structure. | |
5272 | * | |
5273 | * This routine is invoked to free the driver's els sgl list and memory. | |
5274 | **/ | |
5275 | static void | |
5276 | lpfc_free_els_sgl_list(struct lpfc_hba *phba) | |
5277 | { | |
da0436e9 | 5278 | LIST_HEAD(sglq_list); |
dea3101e | 5279 | |
8a9d2e80 | 5280 | /* Retrieve all els sgls from driver list */ |
da0436e9 JS |
5281 | spin_lock_irq(&phba->hbalock); |
5282 | list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list); | |
5283 | spin_unlock_irq(&phba->hbalock); | |
dea3101e | 5284 | |
8a9d2e80 JS |
5285 | /* Now free the sgl list */ |
5286 | lpfc_free_sgl_list(phba, &sglq_list); | |
da0436e9 | 5287 | } |
92d7f7b0 | 5288 | |
da0436e9 JS |
5289 | /** |
5290 | * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs. | |
5291 | * @phba: pointer to lpfc hba data structure. | |
5292 | * | |
5293 | * This routine is invoked to allocate the driver's active sgl memory. | |
5294 | * This array will hold the sglq_entry's for active IOs. | |
5295 | **/ | |
5296 | static int | |
5297 | lpfc_init_active_sgl_array(struct lpfc_hba *phba) | |
5298 | { | |
5299 | int size; | |
5300 | size = sizeof(struct lpfc_sglq *); | |
5301 | size *= phba->sli4_hba.max_cfg_param.max_xri; | |
5302 | ||
5303 | phba->sli4_hba.lpfc_sglq_active_list = | |
5304 | kzalloc(size, GFP_KERNEL); | |
5305 | if (!phba->sli4_hba.lpfc_sglq_active_list) | |
5306 | return -ENOMEM; | |
5307 | return 0; | |
3772a991 JS |
5308 | } |
5309 | ||
5310 | /** | |
da0436e9 | 5311 | * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs. |
3772a991 JS |
5312 | * @phba: pointer to lpfc hba data structure. |
5313 | * | |
da0436e9 JS |
5314 | * This routine is invoked to walk through the array of active sglq entries |
5315 | * and free all of the resources. | |
5316 | * This is just a place holder for now. | |
3772a991 JS |
5317 | **/ |
5318 | static void | |
da0436e9 | 5319 | lpfc_free_active_sgl(struct lpfc_hba *phba) |
3772a991 | 5320 | { |
da0436e9 | 5321 | kfree(phba->sli4_hba.lpfc_sglq_active_list); |
3772a991 JS |
5322 | } |
5323 | ||
5324 | /** | |
da0436e9 | 5325 | * lpfc_init_sgl_list - Allocate and initialize sgl list. |
3772a991 JS |
5326 | * @phba: pointer to lpfc hba data structure. |
5327 | * | |
da0436e9 JS |
5328 | * This routine is invoked to allocate and initizlize the driver's sgl |
5329 | * list and set up the sgl xritag tag array accordingly. | |
3772a991 | 5330 | * |
3772a991 | 5331 | **/ |
8a9d2e80 | 5332 | static void |
da0436e9 | 5333 | lpfc_init_sgl_list(struct lpfc_hba *phba) |
3772a991 | 5334 | { |
da0436e9 JS |
5335 | /* Initialize and populate the sglq list per host/VF. */ |
5336 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list); | |
5337 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
5338 | ||
8a9d2e80 JS |
5339 | /* els xri-sgl book keeping */ |
5340 | phba->sli4_hba.els_xri_cnt = 0; | |
0ff10d46 | 5341 | |
8a9d2e80 | 5342 | /* scsi xri-buffer book keeping */ |
da0436e9 | 5343 | phba->sli4_hba.scsi_xri_cnt = 0; |
da0436e9 JS |
5344 | } |
5345 | ||
5346 | /** | |
5347 | * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port | |
5348 | * @phba: pointer to lpfc hba data structure. | |
5349 | * | |
5350 | * This routine is invoked to post rpi header templates to the | |
88a2cfbb | 5351 | * port for those SLI4 ports that do not support extents. This routine |
da0436e9 | 5352 | * posts a PAGE_SIZE memory region to the port to hold up to |
88a2cfbb JS |
5353 | * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine |
5354 | * and should be called only when interrupts are disabled. | |
da0436e9 JS |
5355 | * |
5356 | * Return codes | |
af901ca1 | 5357 | * 0 - successful |
88a2cfbb | 5358 | * -ERROR - otherwise. |
da0436e9 JS |
5359 | **/ |
5360 | int | |
5361 | lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba) | |
5362 | { | |
5363 | int rc = 0; | |
da0436e9 JS |
5364 | struct lpfc_rpi_hdr *rpi_hdr; |
5365 | ||
5366 | INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list); | |
ff78d8f9 | 5367 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
6d368e53 | 5368 | return rc; |
6d368e53 JS |
5369 | if (phba->sli4_hba.extents_in_use) |
5370 | return -EIO; | |
da0436e9 JS |
5371 | |
5372 | rpi_hdr = lpfc_sli4_create_rpi_hdr(phba); | |
5373 | if (!rpi_hdr) { | |
5374 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
5375 | "0391 Error during rpi post operation\n"); | |
5376 | lpfc_sli4_remove_rpis(phba); | |
5377 | rc = -ENODEV; | |
5378 | } | |
5379 | ||
5380 | return rc; | |
5381 | } | |
5382 | ||
5383 | /** | |
5384 | * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region | |
5385 | * @phba: pointer to lpfc hba data structure. | |
5386 | * | |
5387 | * This routine is invoked to allocate a single 4KB memory region to | |
5388 | * support rpis and stores them in the phba. This single region | |
5389 | * provides support for up to 64 rpis. The region is used globally | |
5390 | * by the device. | |
5391 | * | |
5392 | * Returns: | |
5393 | * A valid rpi hdr on success. | |
5394 | * A NULL pointer on any failure. | |
5395 | **/ | |
5396 | struct lpfc_rpi_hdr * | |
5397 | lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba) | |
5398 | { | |
5399 | uint16_t rpi_limit, curr_rpi_range; | |
5400 | struct lpfc_dmabuf *dmabuf; | |
5401 | struct lpfc_rpi_hdr *rpi_hdr; | |
9589b062 | 5402 | uint32_t rpi_count; |
da0436e9 | 5403 | |
6d368e53 JS |
5404 | /* |
5405 | * If the SLI4 port supports extents, posting the rpi header isn't | |
5406 | * required. Set the expected maximum count and let the actual value | |
5407 | * get set when extents are fully allocated. | |
5408 | */ | |
5409 | if (!phba->sli4_hba.rpi_hdrs_in_use) | |
5410 | return NULL; | |
5411 | if (phba->sli4_hba.extents_in_use) | |
5412 | return NULL; | |
5413 | ||
5414 | /* The limit on the logical index is just the max_rpi count. */ | |
da0436e9 | 5415 | rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base + |
6d368e53 | 5416 | phba->sli4_hba.max_cfg_param.max_rpi - 1; |
da0436e9 JS |
5417 | |
5418 | spin_lock_irq(&phba->hbalock); | |
6d368e53 JS |
5419 | /* |
5420 | * Establish the starting RPI in this header block. The starting | |
5421 | * rpi is normalized to a zero base because the physical rpi is | |
5422 | * port based. | |
5423 | */ | |
97f2ecf1 | 5424 | curr_rpi_range = phba->sli4_hba.next_rpi; |
da0436e9 JS |
5425 | spin_unlock_irq(&phba->hbalock); |
5426 | ||
5427 | /* | |
5428 | * The port has a limited number of rpis. The increment here | |
5429 | * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value | |
5430 | * and to allow the full max_rpi range per port. | |
5431 | */ | |
5432 | if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit) | |
9589b062 JS |
5433 | rpi_count = rpi_limit - curr_rpi_range; |
5434 | else | |
5435 | rpi_count = LPFC_RPI_HDR_COUNT; | |
da0436e9 | 5436 | |
6d368e53 JS |
5437 | if (!rpi_count) |
5438 | return NULL; | |
da0436e9 JS |
5439 | /* |
5440 | * First allocate the protocol header region for the port. The | |
5441 | * port expects a 4KB DMA-mapped memory region that is 4K aligned. | |
5442 | */ | |
5443 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
5444 | if (!dmabuf) | |
5445 | return NULL; | |
5446 | ||
5447 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
5448 | LPFC_HDR_TEMPLATE_SIZE, | |
5449 | &dmabuf->phys, | |
5450 | GFP_KERNEL); | |
5451 | if (!dmabuf->virt) { | |
5452 | rpi_hdr = NULL; | |
5453 | goto err_free_dmabuf; | |
5454 | } | |
5455 | ||
5456 | memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE); | |
5457 | if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) { | |
5458 | rpi_hdr = NULL; | |
5459 | goto err_free_coherent; | |
5460 | } | |
5461 | ||
5462 | /* Save the rpi header data for cleanup later. */ | |
5463 | rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL); | |
5464 | if (!rpi_hdr) | |
5465 | goto err_free_coherent; | |
5466 | ||
5467 | rpi_hdr->dmabuf = dmabuf; | |
5468 | rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE; | |
5469 | rpi_hdr->page_count = 1; | |
5470 | spin_lock_irq(&phba->hbalock); | |
6d368e53 JS |
5471 | |
5472 | /* The rpi_hdr stores the logical index only. */ | |
5473 | rpi_hdr->start_rpi = curr_rpi_range; | |
da0436e9 JS |
5474 | list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list); |
5475 | ||
5476 | /* | |
6d368e53 JS |
5477 | * The next_rpi stores the next logical module-64 rpi value used |
5478 | * to post physical rpis in subsequent rpi postings. | |
da0436e9 | 5479 | */ |
9589b062 | 5480 | phba->sli4_hba.next_rpi += rpi_count; |
da0436e9 JS |
5481 | spin_unlock_irq(&phba->hbalock); |
5482 | return rpi_hdr; | |
5483 | ||
5484 | err_free_coherent: | |
5485 | dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE, | |
5486 | dmabuf->virt, dmabuf->phys); | |
5487 | err_free_dmabuf: | |
5488 | kfree(dmabuf); | |
5489 | return NULL; | |
5490 | } | |
5491 | ||
5492 | /** | |
5493 | * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions | |
5494 | * @phba: pointer to lpfc hba data structure. | |
5495 | * | |
5496 | * This routine is invoked to remove all memory resources allocated | |
6d368e53 JS |
5497 | * to support rpis for SLI4 ports not supporting extents. This routine |
5498 | * presumes the caller has released all rpis consumed by fabric or port | |
5499 | * logins and is prepared to have the header pages removed. | |
da0436e9 JS |
5500 | **/ |
5501 | void | |
5502 | lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba) | |
5503 | { | |
5504 | struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr; | |
5505 | ||
6d368e53 JS |
5506 | if (!phba->sli4_hba.rpi_hdrs_in_use) |
5507 | goto exit; | |
5508 | ||
da0436e9 JS |
5509 | list_for_each_entry_safe(rpi_hdr, next_rpi_hdr, |
5510 | &phba->sli4_hba.lpfc_rpi_hdr_list, list) { | |
5511 | list_del(&rpi_hdr->list); | |
5512 | dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len, | |
5513 | rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys); | |
5514 | kfree(rpi_hdr->dmabuf); | |
5515 | kfree(rpi_hdr); | |
5516 | } | |
6d368e53 JS |
5517 | exit: |
5518 | /* There are no rpis available to the port now. */ | |
5519 | phba->sli4_hba.next_rpi = 0; | |
da0436e9 JS |
5520 | } |
5521 | ||
5522 | /** | |
5523 | * lpfc_hba_alloc - Allocate driver hba data structure for a device. | |
5524 | * @pdev: pointer to pci device data structure. | |
5525 | * | |
5526 | * This routine is invoked to allocate the driver hba data structure for an | |
5527 | * HBA device. If the allocation is successful, the phba reference to the | |
5528 | * PCI device data structure is set. | |
5529 | * | |
5530 | * Return codes | |
af901ca1 | 5531 | * pointer to @phba - successful |
da0436e9 JS |
5532 | * NULL - error |
5533 | **/ | |
5534 | static struct lpfc_hba * | |
5535 | lpfc_hba_alloc(struct pci_dev *pdev) | |
5536 | { | |
5537 | struct lpfc_hba *phba; | |
5538 | ||
5539 | /* Allocate memory for HBA structure */ | |
5540 | phba = kzalloc(sizeof(struct lpfc_hba), GFP_KERNEL); | |
5541 | if (!phba) { | |
e34ccdfe | 5542 | dev_err(&pdev->dev, "failed to allocate hba struct\n"); |
da0436e9 JS |
5543 | return NULL; |
5544 | } | |
5545 | ||
5546 | /* Set reference to PCI device in HBA structure */ | |
5547 | phba->pcidev = pdev; | |
5548 | ||
5549 | /* Assign an unused board number */ | |
5550 | phba->brd_no = lpfc_get_instance(); | |
5551 | if (phba->brd_no < 0) { | |
5552 | kfree(phba); | |
5553 | return NULL; | |
5554 | } | |
5555 | ||
4fede78f | 5556 | spin_lock_init(&phba->ct_ev_lock); |
f1c3b0fc JS |
5557 | INIT_LIST_HEAD(&phba->ct_ev_waiters); |
5558 | ||
da0436e9 JS |
5559 | return phba; |
5560 | } | |
5561 | ||
5562 | /** | |
5563 | * lpfc_hba_free - Free driver hba data structure with a device. | |
5564 | * @phba: pointer to lpfc hba data structure. | |
5565 | * | |
5566 | * This routine is invoked to free the driver hba data structure with an | |
5567 | * HBA device. | |
5568 | **/ | |
5569 | static void | |
5570 | lpfc_hba_free(struct lpfc_hba *phba) | |
5571 | { | |
5572 | /* Release the driver assigned board number */ | |
5573 | idr_remove(&lpfc_hba_index, phba->brd_no); | |
5574 | ||
2a76a283 JS |
5575 | /* Free memory allocated with sli rings */ |
5576 | kfree(phba->sli.ring); | |
5577 | phba->sli.ring = NULL; | |
5578 | ||
da0436e9 JS |
5579 | kfree(phba); |
5580 | return; | |
5581 | } | |
5582 | ||
5583 | /** | |
5584 | * lpfc_create_shost - Create hba physical port with associated scsi host. | |
5585 | * @phba: pointer to lpfc hba data structure. | |
5586 | * | |
5587 | * This routine is invoked to create HBA physical port and associate a SCSI | |
5588 | * host with it. | |
5589 | * | |
5590 | * Return codes | |
af901ca1 | 5591 | * 0 - successful |
da0436e9 JS |
5592 | * other values - error |
5593 | **/ | |
5594 | static int | |
5595 | lpfc_create_shost(struct lpfc_hba *phba) | |
5596 | { | |
5597 | struct lpfc_vport *vport; | |
5598 | struct Scsi_Host *shost; | |
5599 | ||
5600 | /* Initialize HBA FC structure */ | |
5601 | phba->fc_edtov = FF_DEF_EDTOV; | |
5602 | phba->fc_ratov = FF_DEF_RATOV; | |
5603 | phba->fc_altov = FF_DEF_ALTOV; | |
5604 | phba->fc_arbtov = FF_DEF_ARBTOV; | |
5605 | ||
d7c47992 | 5606 | atomic_set(&phba->sdev_cnt, 0); |
da0436e9 JS |
5607 | vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev); |
5608 | if (!vport) | |
5609 | return -ENODEV; | |
5610 | ||
5611 | shost = lpfc_shost_from_vport(vport); | |
5612 | phba->pport = vport; | |
5613 | lpfc_debugfs_initialize(vport); | |
5614 | /* Put reference to SCSI host to driver's device private data */ | |
5615 | pci_set_drvdata(phba->pcidev, shost); | |
2e0fef85 | 5616 | |
3772a991 JS |
5617 | return 0; |
5618 | } | |
db2378e0 | 5619 | |
3772a991 JS |
5620 | /** |
5621 | * lpfc_destroy_shost - Destroy hba physical port with associated scsi host. | |
5622 | * @phba: pointer to lpfc hba data structure. | |
5623 | * | |
5624 | * This routine is invoked to destroy HBA physical port and the associated | |
5625 | * SCSI host. | |
5626 | **/ | |
5627 | static void | |
5628 | lpfc_destroy_shost(struct lpfc_hba *phba) | |
5629 | { | |
5630 | struct lpfc_vport *vport = phba->pport; | |
5631 | ||
5632 | /* Destroy physical port that associated with the SCSI host */ | |
5633 | destroy_port(vport); | |
5634 | ||
5635 | return; | |
5636 | } | |
5637 | ||
5638 | /** | |
5639 | * lpfc_setup_bg - Setup Block guard structures and debug areas. | |
5640 | * @phba: pointer to lpfc hba data structure. | |
5641 | * @shost: the shost to be used to detect Block guard settings. | |
5642 | * | |
5643 | * This routine sets up the local Block guard protocol settings for @shost. | |
5644 | * This routine also allocates memory for debugging bg buffers. | |
5645 | **/ | |
5646 | static void | |
5647 | lpfc_setup_bg(struct lpfc_hba *phba, struct Scsi_Host *shost) | |
5648 | { | |
bbeb79b9 JS |
5649 | uint32_t old_mask; |
5650 | uint32_t old_guard; | |
5651 | ||
3772a991 JS |
5652 | int pagecnt = 10; |
5653 | if (lpfc_prot_mask && lpfc_prot_guard) { | |
5654 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5655 | "1478 Registering BlockGuard with the " | |
5656 | "SCSI layer\n"); | |
bbeb79b9 JS |
5657 | |
5658 | old_mask = lpfc_prot_mask; | |
5659 | old_guard = lpfc_prot_guard; | |
5660 | ||
5661 | /* Only allow supported values */ | |
5662 | lpfc_prot_mask &= (SHOST_DIF_TYPE1_PROTECTION | | |
5663 | SHOST_DIX_TYPE0_PROTECTION | | |
5664 | SHOST_DIX_TYPE1_PROTECTION); | |
5665 | lpfc_prot_guard &= (SHOST_DIX_GUARD_IP | SHOST_DIX_GUARD_CRC); | |
5666 | ||
5667 | /* DIF Type 1 protection for profiles AST1/C1 is end to end */ | |
5668 | if (lpfc_prot_mask == SHOST_DIX_TYPE1_PROTECTION) | |
5669 | lpfc_prot_mask |= SHOST_DIF_TYPE1_PROTECTION; | |
5670 | ||
5671 | if (lpfc_prot_mask && lpfc_prot_guard) { | |
5672 | if ((old_mask != lpfc_prot_mask) || | |
5673 | (old_guard != lpfc_prot_guard)) | |
5674 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5675 | "1475 Registering BlockGuard with the " | |
5676 | "SCSI layer: mask %d guard %d\n", | |
5677 | lpfc_prot_mask, lpfc_prot_guard); | |
5678 | ||
5679 | scsi_host_set_prot(shost, lpfc_prot_mask); | |
5680 | scsi_host_set_guard(shost, lpfc_prot_guard); | |
5681 | } else | |
5682 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
5683 | "1479 Not Registering BlockGuard with the SCSI " | |
5684 | "layer, Bad protection parameters: %d %d\n", | |
5685 | old_mask, old_guard); | |
3772a991 | 5686 | } |
bbeb79b9 | 5687 | |
3772a991 JS |
5688 | if (!_dump_buf_data) { |
5689 | while (pagecnt) { | |
5690 | spin_lock_init(&_dump_buf_lock); | |
5691 | _dump_buf_data = | |
5692 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
5693 | if (_dump_buf_data) { | |
6a9c52cf JS |
5694 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5695 | "9043 BLKGRD: allocated %d pages for " | |
3772a991 JS |
5696 | "_dump_buf_data at 0x%p\n", |
5697 | (1 << pagecnt), _dump_buf_data); | |
5698 | _dump_buf_data_order = pagecnt; | |
5699 | memset(_dump_buf_data, 0, | |
5700 | ((1 << PAGE_SHIFT) << pagecnt)); | |
5701 | break; | |
5702 | } else | |
5703 | --pagecnt; | |
5704 | } | |
5705 | if (!_dump_buf_data_order) | |
6a9c52cf JS |
5706 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5707 | "9044 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
5708 | "memory for hexdump\n"); |
5709 | } else | |
6a9c52cf JS |
5710 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5711 | "9045 BLKGRD: already allocated _dump_buf_data=0x%p" | |
3772a991 JS |
5712 | "\n", _dump_buf_data); |
5713 | if (!_dump_buf_dif) { | |
5714 | while (pagecnt) { | |
5715 | _dump_buf_dif = | |
5716 | (char *) __get_free_pages(GFP_KERNEL, pagecnt); | |
5717 | if (_dump_buf_dif) { | |
6a9c52cf JS |
5718 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5719 | "9046 BLKGRD: allocated %d pages for " | |
3772a991 JS |
5720 | "_dump_buf_dif at 0x%p\n", |
5721 | (1 << pagecnt), _dump_buf_dif); | |
5722 | _dump_buf_dif_order = pagecnt; | |
5723 | memset(_dump_buf_dif, 0, | |
5724 | ((1 << PAGE_SHIFT) << pagecnt)); | |
5725 | break; | |
5726 | } else | |
5727 | --pagecnt; | |
5728 | } | |
5729 | if (!_dump_buf_dif_order) | |
6a9c52cf JS |
5730 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5731 | "9047 BLKGRD: ERROR unable to allocate " | |
3772a991 JS |
5732 | "memory for hexdump\n"); |
5733 | } else | |
6a9c52cf JS |
5734 | lpfc_printf_log(phba, KERN_ERR, LOG_BG, |
5735 | "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n", | |
3772a991 JS |
5736 | _dump_buf_dif); |
5737 | } | |
5738 | ||
5739 | /** | |
5740 | * lpfc_post_init_setup - Perform necessary device post initialization setup. | |
5741 | * @phba: pointer to lpfc hba data structure. | |
5742 | * | |
5743 | * This routine is invoked to perform all the necessary post initialization | |
5744 | * setup for the device. | |
5745 | **/ | |
5746 | static void | |
5747 | lpfc_post_init_setup(struct lpfc_hba *phba) | |
5748 | { | |
5749 | struct Scsi_Host *shost; | |
5750 | struct lpfc_adapter_event_header adapter_event; | |
5751 | ||
5752 | /* Get the default values for Model Name and Description */ | |
5753 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
5754 | ||
5755 | /* | |
5756 | * hba setup may have changed the hba_queue_depth so we need to | |
5757 | * adjust the value of can_queue. | |
5758 | */ | |
5759 | shost = pci_get_drvdata(phba->pcidev); | |
5760 | shost->can_queue = phba->cfg_hba_queue_depth - 10; | |
5761 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) | |
5762 | lpfc_setup_bg(phba, shost); | |
5763 | ||
5764 | lpfc_host_attrib_init(shost); | |
5765 | ||
5766 | if (phba->cfg_poll & DISABLE_FCP_RING_INT) { | |
5767 | spin_lock_irq(shost->host_lock); | |
5768 | lpfc_poll_start_timer(phba); | |
5769 | spin_unlock_irq(shost->host_lock); | |
5770 | } | |
5771 | ||
5772 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
5773 | "0428 Perform SCSI scan\n"); | |
5774 | /* Send board arrival event to upper layer */ | |
5775 | adapter_event.event_type = FC_REG_ADAPTER_EVENT; | |
5776 | adapter_event.subcategory = LPFC_EVENT_ARRIVAL; | |
5777 | fc_host_post_vendor_event(shost, fc_get_event_number(), | |
5778 | sizeof(adapter_event), | |
5779 | (char *) &adapter_event, | |
5780 | LPFC_NL_VENDOR_ID); | |
5781 | return; | |
5782 | } | |
5783 | ||
5784 | /** | |
5785 | * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space. | |
5786 | * @phba: pointer to lpfc hba data structure. | |
5787 | * | |
5788 | * This routine is invoked to set up the PCI device memory space for device | |
5789 | * with SLI-3 interface spec. | |
5790 | * | |
5791 | * Return codes | |
af901ca1 | 5792 | * 0 - successful |
3772a991 JS |
5793 | * other values - error |
5794 | **/ | |
5795 | static int | |
5796 | lpfc_sli_pci_mem_setup(struct lpfc_hba *phba) | |
5797 | { | |
5798 | struct pci_dev *pdev; | |
5799 | unsigned long bar0map_len, bar2map_len; | |
5800 | int i, hbq_count; | |
5801 | void *ptr; | |
5802 | int error = -ENODEV; | |
5803 | ||
5804 | /* Obtain PCI device reference */ | |
5805 | if (!phba->pcidev) | |
5806 | return error; | |
5807 | else | |
5808 | pdev = phba->pcidev; | |
5809 | ||
5810 | /* Set the device DMA mask size */ | |
8e68597d MR |
5811 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
5812 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
5813 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
5814 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
3772a991 | 5815 | return error; |
8e68597d MR |
5816 | } |
5817 | } | |
3772a991 JS |
5818 | |
5819 | /* Get the bus address of Bar0 and Bar2 and the number of bytes | |
5820 | * required by each mapping. | |
5821 | */ | |
5822 | phba->pci_bar0_map = pci_resource_start(pdev, 0); | |
5823 | bar0map_len = pci_resource_len(pdev, 0); | |
5824 | ||
5825 | phba->pci_bar2_map = pci_resource_start(pdev, 2); | |
5826 | bar2map_len = pci_resource_len(pdev, 2); | |
5827 | ||
5828 | /* Map HBA SLIM to a kernel virtual address. */ | |
5829 | phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len); | |
5830 | if (!phba->slim_memmap_p) { | |
5831 | dev_printk(KERN_ERR, &pdev->dev, | |
5832 | "ioremap failed for SLIM memory.\n"); | |
5833 | goto out; | |
5834 | } | |
5835 | ||
5836 | /* Map HBA Control Registers to a kernel virtual address. */ | |
5837 | phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len); | |
5838 | if (!phba->ctrl_regs_memmap_p) { | |
5839 | dev_printk(KERN_ERR, &pdev->dev, | |
5840 | "ioremap failed for HBA control registers.\n"); | |
5841 | goto out_iounmap_slim; | |
5842 | } | |
5843 | ||
5844 | /* Allocate memory for SLI-2 structures */ | |
5845 | phba->slim2p.virt = dma_alloc_coherent(&pdev->dev, | |
5846 | SLI2_SLIM_SIZE, | |
5847 | &phba->slim2p.phys, | |
5848 | GFP_KERNEL); | |
5849 | if (!phba->slim2p.virt) | |
5850 | goto out_iounmap; | |
5851 | ||
5852 | memset(phba->slim2p.virt, 0, SLI2_SLIM_SIZE); | |
5853 | phba->mbox = phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, mbx); | |
7a470277 JS |
5854 | phba->mbox_ext = (phba->slim2p.virt + |
5855 | offsetof(struct lpfc_sli2_slim, mbx_ext_words)); | |
3772a991 JS |
5856 | phba->pcb = (phba->slim2p.virt + offsetof(struct lpfc_sli2_slim, pcb)); |
5857 | phba->IOCBs = (phba->slim2p.virt + | |
5858 | offsetof(struct lpfc_sli2_slim, IOCBs)); | |
5859 | ||
5860 | phba->hbqslimp.virt = dma_alloc_coherent(&pdev->dev, | |
5861 | lpfc_sli_hbq_size(), | |
5862 | &phba->hbqslimp.phys, | |
5863 | GFP_KERNEL); | |
5864 | if (!phba->hbqslimp.virt) | |
5865 | goto out_free_slim; | |
5866 | ||
5867 | hbq_count = lpfc_sli_hbq_count(); | |
5868 | ptr = phba->hbqslimp.virt; | |
5869 | for (i = 0; i < hbq_count; ++i) { | |
5870 | phba->hbqs[i].hbq_virt = ptr; | |
5871 | INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list); | |
5872 | ptr += (lpfc_hbq_defs[i]->entry_count * | |
5873 | sizeof(struct lpfc_hbq_entry)); | |
5874 | } | |
5875 | phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc; | |
5876 | phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free; | |
5877 | ||
5878 | memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size()); | |
5879 | ||
5880 | INIT_LIST_HEAD(&phba->rb_pend_list); | |
5881 | ||
5882 | phba->MBslimaddr = phba->slim_memmap_p; | |
5883 | phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; | |
5884 | phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; | |
5885 | phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET; | |
5886 | phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET; | |
5887 | ||
5888 | return 0; | |
5889 | ||
5890 | out_free_slim: | |
5891 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
5892 | phba->slim2p.virt, phba->slim2p.phys); | |
5893 | out_iounmap: | |
5894 | iounmap(phba->ctrl_regs_memmap_p); | |
5895 | out_iounmap_slim: | |
5896 | iounmap(phba->slim_memmap_p); | |
5897 | out: | |
5898 | return error; | |
5899 | } | |
5900 | ||
5901 | /** | |
5902 | * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space. | |
5903 | * @phba: pointer to lpfc hba data structure. | |
5904 | * | |
5905 | * This routine is invoked to unset the PCI device memory space for device | |
5906 | * with SLI-3 interface spec. | |
5907 | **/ | |
5908 | static void | |
5909 | lpfc_sli_pci_mem_unset(struct lpfc_hba *phba) | |
5910 | { | |
5911 | struct pci_dev *pdev; | |
5912 | ||
5913 | /* Obtain PCI device reference */ | |
5914 | if (!phba->pcidev) | |
5915 | return; | |
5916 | else | |
5917 | pdev = phba->pcidev; | |
5918 | ||
5919 | /* Free coherent DMA memory allocated */ | |
5920 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
5921 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
5922 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
5923 | phba->slim2p.virt, phba->slim2p.phys); | |
5924 | ||
5925 | /* I/O memory unmap */ | |
5926 | iounmap(phba->ctrl_regs_memmap_p); | |
5927 | iounmap(phba->slim_memmap_p); | |
5928 | ||
5929 | return; | |
5930 | } | |
5931 | ||
5932 | /** | |
da0436e9 | 5933 | * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status |
3772a991 JS |
5934 | * @phba: pointer to lpfc hba data structure. |
5935 | * | |
da0436e9 JS |
5936 | * This routine is invoked to wait for SLI4 device Power On Self Test (POST) |
5937 | * done and check status. | |
3772a991 | 5938 | * |
da0436e9 | 5939 | * Return 0 if successful, otherwise -ENODEV. |
3772a991 | 5940 | **/ |
da0436e9 JS |
5941 | int |
5942 | lpfc_sli4_post_status_check(struct lpfc_hba *phba) | |
3772a991 | 5943 | { |
2fcee4bf JS |
5944 | struct lpfc_register portsmphr_reg, uerrlo_reg, uerrhi_reg; |
5945 | struct lpfc_register reg_data; | |
5946 | int i, port_error = 0; | |
5947 | uint32_t if_type; | |
3772a991 | 5948 | |
9940b97b JS |
5949 | memset(&portsmphr_reg, 0, sizeof(portsmphr_reg)); |
5950 | memset(®_data, 0, sizeof(reg_data)); | |
2fcee4bf | 5951 | if (!phba->sli4_hba.PSMPHRregaddr) |
da0436e9 | 5952 | return -ENODEV; |
3772a991 | 5953 | |
da0436e9 JS |
5954 | /* Wait up to 30 seconds for the SLI Port POST done and ready */ |
5955 | for (i = 0; i < 3000; i++) { | |
9940b97b JS |
5956 | if (lpfc_readl(phba->sli4_hba.PSMPHRregaddr, |
5957 | &portsmphr_reg.word0) || | |
5958 | (bf_get(lpfc_port_smphr_perr, &portsmphr_reg))) { | |
2fcee4bf | 5959 | /* Port has a fatal POST error, break out */ |
da0436e9 JS |
5960 | port_error = -ENODEV; |
5961 | break; | |
5962 | } | |
2fcee4bf JS |
5963 | if (LPFC_POST_STAGE_PORT_READY == |
5964 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)) | |
da0436e9 | 5965 | break; |
da0436e9 | 5966 | msleep(10); |
3772a991 JS |
5967 | } |
5968 | ||
2fcee4bf JS |
5969 | /* |
5970 | * If there was a port error during POST, then don't proceed with | |
5971 | * other register reads as the data may not be valid. Just exit. | |
5972 | */ | |
5973 | if (port_error) { | |
da0436e9 | 5974 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
2fcee4bf JS |
5975 | "1408 Port Failed POST - portsmphr=0x%x, " |
5976 | "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, " | |
5977 | "scr2=x%x, hscratch=x%x, pstatus=x%x\n", | |
5978 | portsmphr_reg.word0, | |
5979 | bf_get(lpfc_port_smphr_perr, &portsmphr_reg), | |
5980 | bf_get(lpfc_port_smphr_sfi, &portsmphr_reg), | |
5981 | bf_get(lpfc_port_smphr_nip, &portsmphr_reg), | |
5982 | bf_get(lpfc_port_smphr_ipc, &portsmphr_reg), | |
5983 | bf_get(lpfc_port_smphr_scr1, &portsmphr_reg), | |
5984 | bf_get(lpfc_port_smphr_scr2, &portsmphr_reg), | |
5985 | bf_get(lpfc_port_smphr_host_scratch, &portsmphr_reg), | |
5986 | bf_get(lpfc_port_smphr_port_status, &portsmphr_reg)); | |
5987 | } else { | |
28baac74 | 5988 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
2fcee4bf JS |
5989 | "2534 Device Info: SLIFamily=0x%x, " |
5990 | "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, " | |
5991 | "SLIHint_2=0x%x, FT=0x%x\n", | |
28baac74 JS |
5992 | bf_get(lpfc_sli_intf_sli_family, |
5993 | &phba->sli4_hba.sli_intf), | |
5994 | bf_get(lpfc_sli_intf_slirev, | |
5995 | &phba->sli4_hba.sli_intf), | |
085c647c JS |
5996 | bf_get(lpfc_sli_intf_if_type, |
5997 | &phba->sli4_hba.sli_intf), | |
5998 | bf_get(lpfc_sli_intf_sli_hint1, | |
28baac74 | 5999 | &phba->sli4_hba.sli_intf), |
085c647c JS |
6000 | bf_get(lpfc_sli_intf_sli_hint2, |
6001 | &phba->sli4_hba.sli_intf), | |
6002 | bf_get(lpfc_sli_intf_func_type, | |
28baac74 | 6003 | &phba->sli4_hba.sli_intf)); |
2fcee4bf JS |
6004 | /* |
6005 | * Check for other Port errors during the initialization | |
6006 | * process. Fail the load if the port did not come up | |
6007 | * correctly. | |
6008 | */ | |
6009 | if_type = bf_get(lpfc_sli_intf_if_type, | |
6010 | &phba->sli4_hba.sli_intf); | |
6011 | switch (if_type) { | |
6012 | case LPFC_SLI_INTF_IF_TYPE_0: | |
6013 | phba->sli4_hba.ue_mask_lo = | |
6014 | readl(phba->sli4_hba.u.if_type0.UEMASKLOregaddr); | |
6015 | phba->sli4_hba.ue_mask_hi = | |
6016 | readl(phba->sli4_hba.u.if_type0.UEMASKHIregaddr); | |
6017 | uerrlo_reg.word0 = | |
6018 | readl(phba->sli4_hba.u.if_type0.UERRLOregaddr); | |
6019 | uerrhi_reg.word0 = | |
6020 | readl(phba->sli4_hba.u.if_type0.UERRHIregaddr); | |
6021 | if ((~phba->sli4_hba.ue_mask_lo & uerrlo_reg.word0) || | |
6022 | (~phba->sli4_hba.ue_mask_hi & uerrhi_reg.word0)) { | |
6023 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6024 | "1422 Unrecoverable Error " | |
6025 | "Detected during POST " | |
6026 | "uerr_lo_reg=0x%x, " | |
6027 | "uerr_hi_reg=0x%x, " | |
6028 | "ue_mask_lo_reg=0x%x, " | |
6029 | "ue_mask_hi_reg=0x%x\n", | |
6030 | uerrlo_reg.word0, | |
6031 | uerrhi_reg.word0, | |
6032 | phba->sli4_hba.ue_mask_lo, | |
6033 | phba->sli4_hba.ue_mask_hi); | |
6034 | port_error = -ENODEV; | |
6035 | } | |
6036 | break; | |
6037 | case LPFC_SLI_INTF_IF_TYPE_2: | |
6038 | /* Final checks. The port status should be clean. */ | |
9940b97b JS |
6039 | if (lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
6040 | ®_data.word0) || | |
0558056c JS |
6041 | (bf_get(lpfc_sliport_status_err, ®_data) && |
6042 | !bf_get(lpfc_sliport_status_rn, ®_data))) { | |
2fcee4bf JS |
6043 | phba->work_status[0] = |
6044 | readl(phba->sli4_hba.u.if_type2. | |
6045 | ERR1regaddr); | |
6046 | phba->work_status[1] = | |
6047 | readl(phba->sli4_hba.u.if_type2. | |
6048 | ERR2regaddr); | |
6049 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8fcb8acd JS |
6050 | "2888 Unrecoverable port error " |
6051 | "following POST: port status reg " | |
6052 | "0x%x, port_smphr reg 0x%x, " | |
2fcee4bf JS |
6053 | "error 1=0x%x, error 2=0x%x\n", |
6054 | reg_data.word0, | |
6055 | portsmphr_reg.word0, | |
6056 | phba->work_status[0], | |
6057 | phba->work_status[1]); | |
6058 | port_error = -ENODEV; | |
6059 | } | |
6060 | break; | |
6061 | case LPFC_SLI_INTF_IF_TYPE_1: | |
6062 | default: | |
6063 | break; | |
6064 | } | |
28baac74 | 6065 | } |
da0436e9 JS |
6066 | return port_error; |
6067 | } | |
3772a991 | 6068 | |
da0436e9 JS |
6069 | /** |
6070 | * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map. | |
6071 | * @phba: pointer to lpfc hba data structure. | |
2fcee4bf | 6072 | * @if_type: The SLI4 interface type getting configured. |
da0436e9 JS |
6073 | * |
6074 | * This routine is invoked to set up SLI4 BAR0 PCI config space register | |
6075 | * memory map. | |
6076 | **/ | |
6077 | static void | |
2fcee4bf JS |
6078 | lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba, uint32_t if_type) |
6079 | { | |
6080 | switch (if_type) { | |
6081 | case LPFC_SLI_INTF_IF_TYPE_0: | |
6082 | phba->sli4_hba.u.if_type0.UERRLOregaddr = | |
6083 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_LO; | |
6084 | phba->sli4_hba.u.if_type0.UERRHIregaddr = | |
6085 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UERR_STATUS_HI; | |
6086 | phba->sli4_hba.u.if_type0.UEMASKLOregaddr = | |
6087 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_LO; | |
6088 | phba->sli4_hba.u.if_type0.UEMASKHIregaddr = | |
6089 | phba->sli4_hba.conf_regs_memmap_p + LPFC_UE_MASK_HI; | |
6090 | phba->sli4_hba.SLIINTFregaddr = | |
6091 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; | |
6092 | break; | |
6093 | case LPFC_SLI_INTF_IF_TYPE_2: | |
6094 | phba->sli4_hba.u.if_type2.ERR1regaddr = | |
88a2cfbb JS |
6095 | phba->sli4_hba.conf_regs_memmap_p + |
6096 | LPFC_CTL_PORT_ER1_OFFSET; | |
2fcee4bf | 6097 | phba->sli4_hba.u.if_type2.ERR2regaddr = |
88a2cfbb JS |
6098 | phba->sli4_hba.conf_regs_memmap_p + |
6099 | LPFC_CTL_PORT_ER2_OFFSET; | |
2fcee4bf | 6100 | phba->sli4_hba.u.if_type2.CTRLregaddr = |
88a2cfbb JS |
6101 | phba->sli4_hba.conf_regs_memmap_p + |
6102 | LPFC_CTL_PORT_CTL_OFFSET; | |
2fcee4bf | 6103 | phba->sli4_hba.u.if_type2.STATUSregaddr = |
88a2cfbb JS |
6104 | phba->sli4_hba.conf_regs_memmap_p + |
6105 | LPFC_CTL_PORT_STA_OFFSET; | |
2fcee4bf JS |
6106 | phba->sli4_hba.SLIINTFregaddr = |
6107 | phba->sli4_hba.conf_regs_memmap_p + LPFC_SLI_INTF; | |
6108 | phba->sli4_hba.PSMPHRregaddr = | |
88a2cfbb JS |
6109 | phba->sli4_hba.conf_regs_memmap_p + |
6110 | LPFC_CTL_PORT_SEM_OFFSET; | |
2fcee4bf JS |
6111 | phba->sli4_hba.RQDBregaddr = |
6112 | phba->sli4_hba.conf_regs_memmap_p + LPFC_RQ_DOORBELL; | |
6113 | phba->sli4_hba.WQDBregaddr = | |
6114 | phba->sli4_hba.conf_regs_memmap_p + LPFC_WQ_DOORBELL; | |
6115 | phba->sli4_hba.EQCQDBregaddr = | |
6116 | phba->sli4_hba.conf_regs_memmap_p + LPFC_EQCQ_DOORBELL; | |
6117 | phba->sli4_hba.MQDBregaddr = | |
6118 | phba->sli4_hba.conf_regs_memmap_p + LPFC_MQ_DOORBELL; | |
6119 | phba->sli4_hba.BMBXregaddr = | |
6120 | phba->sli4_hba.conf_regs_memmap_p + LPFC_BMBX; | |
6121 | break; | |
6122 | case LPFC_SLI_INTF_IF_TYPE_1: | |
6123 | default: | |
6124 | dev_printk(KERN_ERR, &phba->pcidev->dev, | |
6125 | "FATAL - unsupported SLI4 interface type - %d\n", | |
6126 | if_type); | |
6127 | break; | |
6128 | } | |
da0436e9 | 6129 | } |
3772a991 | 6130 | |
da0436e9 JS |
6131 | /** |
6132 | * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map. | |
6133 | * @phba: pointer to lpfc hba data structure. | |
6134 | * | |
6135 | * This routine is invoked to set up SLI4 BAR1 control status register (CSR) | |
6136 | * memory map. | |
6137 | **/ | |
6138 | static void | |
6139 | lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba) | |
6140 | { | |
2fcee4bf JS |
6141 | phba->sli4_hba.PSMPHRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
6142 | LPFC_SLIPORT_IF0_SMPHR; | |
da0436e9 | 6143 | phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 6144 | LPFC_HST_ISR0; |
da0436e9 | 6145 | phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 6146 | LPFC_HST_IMR0; |
da0436e9 | 6147 | phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p + |
2fcee4bf | 6148 | LPFC_HST_ISCR0; |
3772a991 JS |
6149 | } |
6150 | ||
6151 | /** | |
da0436e9 | 6152 | * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map. |
3772a991 | 6153 | * @phba: pointer to lpfc hba data structure. |
da0436e9 | 6154 | * @vf: virtual function number |
3772a991 | 6155 | * |
da0436e9 JS |
6156 | * This routine is invoked to set up SLI4 BAR2 doorbell register memory map |
6157 | * based on the given viftual function number, @vf. | |
6158 | * | |
6159 | * Return 0 if successful, otherwise -ENODEV. | |
3772a991 | 6160 | **/ |
da0436e9 JS |
6161 | static int |
6162 | lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf) | |
3772a991 | 6163 | { |
da0436e9 JS |
6164 | if (vf > LPFC_VIR_FUNC_MAX) |
6165 | return -ENODEV; | |
3772a991 | 6166 | |
da0436e9 JS |
6167 | phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + |
6168 | vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL); | |
6169 | phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
6170 | vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL); | |
6171 | phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
6172 | vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL); | |
6173 | phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
6174 | vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL); | |
6175 | phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p + | |
6176 | vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX); | |
6177 | return 0; | |
3772a991 JS |
6178 | } |
6179 | ||
6180 | /** | |
da0436e9 | 6181 | * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox |
3772a991 JS |
6182 | * @phba: pointer to lpfc hba data structure. |
6183 | * | |
da0436e9 JS |
6184 | * This routine is invoked to create the bootstrap mailbox |
6185 | * region consistent with the SLI-4 interface spec. This | |
6186 | * routine allocates all memory necessary to communicate | |
6187 | * mailbox commands to the port and sets up all alignment | |
6188 | * needs. No locks are expected to be held when calling | |
6189 | * this routine. | |
3772a991 JS |
6190 | * |
6191 | * Return codes | |
af901ca1 | 6192 | * 0 - successful |
d439d286 | 6193 | * -ENOMEM - could not allocated memory. |
da0436e9 | 6194 | **/ |
3772a991 | 6195 | static int |
da0436e9 | 6196 | lpfc_create_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 6197 | { |
da0436e9 JS |
6198 | uint32_t bmbx_size; |
6199 | struct lpfc_dmabuf *dmabuf; | |
6200 | struct dma_address *dma_address; | |
6201 | uint32_t pa_addr; | |
6202 | uint64_t phys_addr; | |
6203 | ||
6204 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); | |
6205 | if (!dmabuf) | |
6206 | return -ENOMEM; | |
3772a991 | 6207 | |
da0436e9 JS |
6208 | /* |
6209 | * The bootstrap mailbox region is comprised of 2 parts | |
6210 | * plus an alignment restriction of 16 bytes. | |
6211 | */ | |
6212 | bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1); | |
6213 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
6214 | bmbx_size, | |
6215 | &dmabuf->phys, | |
6216 | GFP_KERNEL); | |
6217 | if (!dmabuf->virt) { | |
6218 | kfree(dmabuf); | |
6219 | return -ENOMEM; | |
3772a991 | 6220 | } |
da0436e9 | 6221 | memset(dmabuf->virt, 0, bmbx_size); |
3772a991 | 6222 | |
da0436e9 JS |
6223 | /* |
6224 | * Initialize the bootstrap mailbox pointers now so that the register | |
6225 | * operations are simple later. The mailbox dma address is required | |
6226 | * to be 16-byte aligned. Also align the virtual memory as each | |
6227 | * maibox is copied into the bmbx mailbox region before issuing the | |
6228 | * command to the port. | |
6229 | */ | |
6230 | phba->sli4_hba.bmbx.dmabuf = dmabuf; | |
6231 | phba->sli4_hba.bmbx.bmbx_size = bmbx_size; | |
6232 | ||
6233 | phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt, | |
6234 | LPFC_ALIGN_16_BYTE); | |
6235 | phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys, | |
6236 | LPFC_ALIGN_16_BYTE); | |
6237 | ||
6238 | /* | |
6239 | * Set the high and low physical addresses now. The SLI4 alignment | |
6240 | * requirement is 16 bytes and the mailbox is posted to the port | |
6241 | * as two 30-bit addresses. The other data is a bit marking whether | |
6242 | * the 30-bit address is the high or low address. | |
6243 | * Upcast bmbx aphys to 64bits so shift instruction compiles | |
6244 | * clean on 32 bit machines. | |
6245 | */ | |
6246 | dma_address = &phba->sli4_hba.bmbx.dma_address; | |
6247 | phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys; | |
6248 | pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff); | |
6249 | dma_address->addr_hi = (uint32_t) ((pa_addr << 2) | | |
6250 | LPFC_BMBX_BIT1_ADDR_HI); | |
6251 | ||
6252 | pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff); | |
6253 | dma_address->addr_lo = (uint32_t) ((pa_addr << 2) | | |
6254 | LPFC_BMBX_BIT1_ADDR_LO); | |
6255 | return 0; | |
3772a991 JS |
6256 | } |
6257 | ||
6258 | /** | |
da0436e9 | 6259 | * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources |
3772a991 JS |
6260 | * @phba: pointer to lpfc hba data structure. |
6261 | * | |
da0436e9 JS |
6262 | * This routine is invoked to teardown the bootstrap mailbox |
6263 | * region and release all host resources. This routine requires | |
6264 | * the caller to ensure all mailbox commands recovered, no | |
6265 | * additional mailbox comands are sent, and interrupts are disabled | |
6266 | * before calling this routine. | |
6267 | * | |
6268 | **/ | |
3772a991 | 6269 | static void |
da0436e9 | 6270 | lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba) |
3772a991 | 6271 | { |
da0436e9 JS |
6272 | dma_free_coherent(&phba->pcidev->dev, |
6273 | phba->sli4_hba.bmbx.bmbx_size, | |
6274 | phba->sli4_hba.bmbx.dmabuf->virt, | |
6275 | phba->sli4_hba.bmbx.dmabuf->phys); | |
6276 | ||
6277 | kfree(phba->sli4_hba.bmbx.dmabuf); | |
6278 | memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx)); | |
3772a991 JS |
6279 | } |
6280 | ||
6281 | /** | |
da0436e9 | 6282 | * lpfc_sli4_read_config - Get the config parameters. |
3772a991 JS |
6283 | * @phba: pointer to lpfc hba data structure. |
6284 | * | |
da0436e9 JS |
6285 | * This routine is invoked to read the configuration parameters from the HBA. |
6286 | * The configuration parameters are used to set the base and maximum values | |
6287 | * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource | |
6288 | * allocation for the port. | |
3772a991 JS |
6289 | * |
6290 | * Return codes | |
af901ca1 | 6291 | * 0 - successful |
25985edc | 6292 | * -ENOMEM - No available memory |
d439d286 | 6293 | * -EIO - The mailbox failed to complete successfully. |
3772a991 | 6294 | **/ |
ff78d8f9 | 6295 | int |
da0436e9 | 6296 | lpfc_sli4_read_config(struct lpfc_hba *phba) |
3772a991 | 6297 | { |
da0436e9 JS |
6298 | LPFC_MBOXQ_t *pmb; |
6299 | struct lpfc_mbx_read_config *rd_config; | |
912e3acd JS |
6300 | union lpfc_sli4_cfg_shdr *shdr; |
6301 | uint32_t shdr_status, shdr_add_status; | |
6302 | struct lpfc_mbx_get_func_cfg *get_func_cfg; | |
6303 | struct lpfc_rsrc_desc_fcfcoe *desc; | |
6304 | uint32_t desc_count; | |
6305 | int length, i, rc = 0; | |
3772a991 | 6306 | |
da0436e9 JS |
6307 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
6308 | if (!pmb) { | |
6309 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6310 | "2011 Unable to allocate memory for issuing " | |
6311 | "SLI_CONFIG_SPECIAL mailbox command\n"); | |
6312 | return -ENOMEM; | |
3772a991 JS |
6313 | } |
6314 | ||
da0436e9 | 6315 | lpfc_read_config(phba, pmb); |
3772a991 | 6316 | |
da0436e9 JS |
6317 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); |
6318 | if (rc != MBX_SUCCESS) { | |
6319 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6320 | "2012 Mailbox failed , mbxCmd x%x " | |
6321 | "READ_CONFIG, mbxStatus x%x\n", | |
6322 | bf_get(lpfc_mqe_command, &pmb->u.mqe), | |
6323 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); | |
6324 | rc = -EIO; | |
6325 | } else { | |
6326 | rd_config = &pmb->u.mqe.un.rd_config; | |
ff78d8f9 JS |
6327 | if (bf_get(lpfc_mbx_rd_conf_lnk_ldv, rd_config)) { |
6328 | phba->sli4_hba.lnk_info.lnk_dv = LPFC_LNK_DAT_VAL; | |
6329 | phba->sli4_hba.lnk_info.lnk_tp = | |
6330 | bf_get(lpfc_mbx_rd_conf_lnk_type, rd_config); | |
6331 | phba->sli4_hba.lnk_info.lnk_no = | |
6332 | bf_get(lpfc_mbx_rd_conf_lnk_numb, rd_config); | |
6333 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
6334 | "3081 lnk_type:%d, lnk_numb:%d\n", | |
6335 | phba->sli4_hba.lnk_info.lnk_tp, | |
6336 | phba->sli4_hba.lnk_info.lnk_no); | |
6337 | } else | |
6338 | lpfc_printf_log(phba, KERN_WARNING, LOG_SLI, | |
6339 | "3082 Mailbox (x%x) returned ldv:x0\n", | |
6340 | bf_get(lpfc_mqe_command, &pmb->u.mqe)); | |
6d368e53 JS |
6341 | phba->sli4_hba.extents_in_use = |
6342 | bf_get(lpfc_mbx_rd_conf_extnts_inuse, rd_config); | |
da0436e9 JS |
6343 | phba->sli4_hba.max_cfg_param.max_xri = |
6344 | bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); | |
6345 | phba->sli4_hba.max_cfg_param.xri_base = | |
6346 | bf_get(lpfc_mbx_rd_conf_xri_base, rd_config); | |
6347 | phba->sli4_hba.max_cfg_param.max_vpi = | |
6348 | bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config); | |
6349 | phba->sli4_hba.max_cfg_param.vpi_base = | |
6350 | bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config); | |
6351 | phba->sli4_hba.max_cfg_param.max_rpi = | |
6352 | bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); | |
6353 | phba->sli4_hba.max_cfg_param.rpi_base = | |
6354 | bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config); | |
6355 | phba->sli4_hba.max_cfg_param.max_vfi = | |
6356 | bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config); | |
6357 | phba->sli4_hba.max_cfg_param.vfi_base = | |
6358 | bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config); | |
6359 | phba->sli4_hba.max_cfg_param.max_fcfi = | |
6360 | bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config); | |
da0436e9 JS |
6361 | phba->sli4_hba.max_cfg_param.max_eq = |
6362 | bf_get(lpfc_mbx_rd_conf_eq_count, rd_config); | |
6363 | phba->sli4_hba.max_cfg_param.max_rq = | |
6364 | bf_get(lpfc_mbx_rd_conf_rq_count, rd_config); | |
6365 | phba->sli4_hba.max_cfg_param.max_wq = | |
6366 | bf_get(lpfc_mbx_rd_conf_wq_count, rd_config); | |
6367 | phba->sli4_hba.max_cfg_param.max_cq = | |
6368 | bf_get(lpfc_mbx_rd_conf_cq_count, rd_config); | |
6369 | phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config); | |
6370 | phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base; | |
6371 | phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base; | |
6372 | phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base; | |
5ffc266e JS |
6373 | phba->max_vpi = (phba->sli4_hba.max_cfg_param.max_vpi > 0) ? |
6374 | (phba->sli4_hba.max_cfg_param.max_vpi - 1) : 0; | |
da0436e9 JS |
6375 | phba->max_vports = phba->max_vpi; |
6376 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
6d368e53 JS |
6377 | "2003 cfg params Extents? %d " |
6378 | "XRI(B:%d M:%d), " | |
da0436e9 JS |
6379 | "VPI(B:%d M:%d) " |
6380 | "VFI(B:%d M:%d) " | |
6381 | "RPI(B:%d M:%d) " | |
6d368e53 JS |
6382 | "FCFI(Count:%d)\n", |
6383 | phba->sli4_hba.extents_in_use, | |
da0436e9 JS |
6384 | phba->sli4_hba.max_cfg_param.xri_base, |
6385 | phba->sli4_hba.max_cfg_param.max_xri, | |
6386 | phba->sli4_hba.max_cfg_param.vpi_base, | |
6387 | phba->sli4_hba.max_cfg_param.max_vpi, | |
6388 | phba->sli4_hba.max_cfg_param.vfi_base, | |
6389 | phba->sli4_hba.max_cfg_param.max_vfi, | |
6390 | phba->sli4_hba.max_cfg_param.rpi_base, | |
6391 | phba->sli4_hba.max_cfg_param.max_rpi, | |
da0436e9 | 6392 | phba->sli4_hba.max_cfg_param.max_fcfi); |
3772a991 | 6393 | } |
912e3acd JS |
6394 | |
6395 | if (rc) | |
6396 | goto read_cfg_out; | |
da0436e9 JS |
6397 | |
6398 | /* Reset the DFT_HBA_Q_DEPTH to the max xri */ | |
b92938b4 JS |
6399 | if (phba->cfg_hba_queue_depth > |
6400 | (phba->sli4_hba.max_cfg_param.max_xri - | |
6401 | lpfc_sli4_get_els_iocb_cnt(phba))) | |
da0436e9 | 6402 | phba->cfg_hba_queue_depth = |
b92938b4 JS |
6403 | phba->sli4_hba.max_cfg_param.max_xri - |
6404 | lpfc_sli4_get_els_iocb_cnt(phba); | |
912e3acd JS |
6405 | |
6406 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
6407 | LPFC_SLI_INTF_IF_TYPE_2) | |
6408 | goto read_cfg_out; | |
6409 | ||
6410 | /* get the pf# and vf# for SLI4 if_type 2 port */ | |
6411 | length = (sizeof(struct lpfc_mbx_get_func_cfg) - | |
6412 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
6413 | lpfc_sli4_config(phba, pmb, LPFC_MBOX_SUBSYSTEM_COMMON, | |
6414 | LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG, | |
6415 | length, LPFC_SLI4_MBX_EMBED); | |
6416 | ||
6417 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
6418 | shdr = (union lpfc_sli4_cfg_shdr *) | |
6419 | &pmb->u.mqe.un.sli4_config.header.cfg_shdr; | |
6420 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
6421 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response); | |
6422 | if (rc || shdr_status || shdr_add_status) { | |
6423 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6424 | "3026 Mailbox failed , mbxCmd x%x " | |
6425 | "GET_FUNCTION_CONFIG, mbxStatus x%x\n", | |
6426 | bf_get(lpfc_mqe_command, &pmb->u.mqe), | |
6427 | bf_get(lpfc_mqe_status, &pmb->u.mqe)); | |
6428 | rc = -EIO; | |
6429 | goto read_cfg_out; | |
6430 | } | |
6431 | ||
6432 | /* search for fc_fcoe resrouce descriptor */ | |
6433 | get_func_cfg = &pmb->u.mqe.un.get_func_cfg; | |
6434 | desc_count = get_func_cfg->func_cfg.rsrc_desc_count; | |
6435 | ||
6436 | for (i = 0; i < LPFC_RSRC_DESC_MAX_NUM; i++) { | |
6437 | desc = (struct lpfc_rsrc_desc_fcfcoe *) | |
6438 | &get_func_cfg->func_cfg.desc[i]; | |
6439 | if (LPFC_RSRC_DESC_TYPE_FCFCOE == | |
6440 | bf_get(lpfc_rsrc_desc_pcie_type, desc)) { | |
6441 | phba->sli4_hba.iov.pf_number = | |
6442 | bf_get(lpfc_rsrc_desc_fcfcoe_pfnum, desc); | |
6443 | phba->sli4_hba.iov.vf_number = | |
6444 | bf_get(lpfc_rsrc_desc_fcfcoe_vfnum, desc); | |
6445 | break; | |
6446 | } | |
6447 | } | |
6448 | ||
6449 | if (i < LPFC_RSRC_DESC_MAX_NUM) | |
6450 | lpfc_printf_log(phba, KERN_INFO, LOG_SLI, | |
6451 | "3027 GET_FUNCTION_CONFIG: pf_number:%d, " | |
6452 | "vf_number:%d\n", phba->sli4_hba.iov.pf_number, | |
6453 | phba->sli4_hba.iov.vf_number); | |
6454 | else { | |
6455 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, | |
6456 | "3028 GET_FUNCTION_CONFIG: failed to find " | |
6457 | "Resrouce Descriptor:x%x\n", | |
6458 | LPFC_RSRC_DESC_TYPE_FCFCOE); | |
6459 | rc = -EIO; | |
6460 | } | |
6461 | ||
6462 | read_cfg_out: | |
6463 | mempool_free(pmb, phba->mbox_mem_pool); | |
da0436e9 | 6464 | return rc; |
3772a991 JS |
6465 | } |
6466 | ||
6467 | /** | |
2fcee4bf | 6468 | * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port. |
3772a991 JS |
6469 | * @phba: pointer to lpfc hba data structure. |
6470 | * | |
2fcee4bf JS |
6471 | * This routine is invoked to setup the port-side endian order when |
6472 | * the port if_type is 0. This routine has no function for other | |
6473 | * if_types. | |
da0436e9 JS |
6474 | * |
6475 | * Return codes | |
af901ca1 | 6476 | * 0 - successful |
25985edc | 6477 | * -ENOMEM - No available memory |
d439d286 | 6478 | * -EIO - The mailbox failed to complete successfully. |
3772a991 | 6479 | **/ |
da0436e9 JS |
6480 | static int |
6481 | lpfc_setup_endian_order(struct lpfc_hba *phba) | |
3772a991 | 6482 | { |
da0436e9 | 6483 | LPFC_MBOXQ_t *mboxq; |
2fcee4bf | 6484 | uint32_t if_type, rc = 0; |
da0436e9 JS |
6485 | uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0, |
6486 | HOST_ENDIAN_HIGH_WORD1}; | |
3772a991 | 6487 | |
2fcee4bf JS |
6488 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
6489 | switch (if_type) { | |
6490 | case LPFC_SLI_INTF_IF_TYPE_0: | |
6491 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, | |
6492 | GFP_KERNEL); | |
6493 | if (!mboxq) { | |
6494 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6495 | "0492 Unable to allocate memory for " | |
6496 | "issuing SLI_CONFIG_SPECIAL mailbox " | |
6497 | "command\n"); | |
6498 | return -ENOMEM; | |
6499 | } | |
3772a991 | 6500 | |
2fcee4bf JS |
6501 | /* |
6502 | * The SLI4_CONFIG_SPECIAL mailbox command requires the first | |
6503 | * two words to contain special data values and no other data. | |
6504 | */ | |
6505 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
6506 | memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data)); | |
6507 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
6508 | if (rc != MBX_SUCCESS) { | |
6509 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6510 | "0493 SLI_CONFIG_SPECIAL mailbox " | |
6511 | "failed with status x%x\n", | |
6512 | rc); | |
6513 | rc = -EIO; | |
6514 | } | |
6515 | mempool_free(mboxq, phba->mbox_mem_pool); | |
6516 | break; | |
6517 | case LPFC_SLI_INTF_IF_TYPE_2: | |
6518 | case LPFC_SLI_INTF_IF_TYPE_1: | |
6519 | default: | |
6520 | break; | |
da0436e9 | 6521 | } |
da0436e9 | 6522 | return rc; |
3772a991 JS |
6523 | } |
6524 | ||
6525 | /** | |
5350d872 | 6526 | * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts |
3772a991 JS |
6527 | * @phba: pointer to lpfc hba data structure. |
6528 | * | |
5350d872 JS |
6529 | * This routine is invoked to check the user settable queue counts for EQs and |
6530 | * CQs. after this routine is called the counts will be set to valid values that | |
6531 | * adhere to the constraints of the system's interrupt vectors and the port's | |
6532 | * queue resources. | |
da0436e9 JS |
6533 | * |
6534 | * Return codes | |
af901ca1 | 6535 | * 0 - successful |
25985edc | 6536 | * -ENOMEM - No available memory |
3772a991 | 6537 | **/ |
da0436e9 | 6538 | static int |
5350d872 | 6539 | lpfc_sli4_queue_verify(struct lpfc_hba *phba) |
3772a991 | 6540 | { |
da0436e9 JS |
6541 | int cfg_fcp_wq_count; |
6542 | int cfg_fcp_eq_count; | |
3772a991 | 6543 | |
da0436e9 JS |
6544 | /* |
6545 | * Sanity check for confiugred queue parameters against the run-time | |
6546 | * device parameters | |
6547 | */ | |
3772a991 | 6548 | |
da0436e9 JS |
6549 | /* Sanity check on FCP fast-path WQ parameters */ |
6550 | cfg_fcp_wq_count = phba->cfg_fcp_wq_count; | |
6551 | if (cfg_fcp_wq_count > | |
6552 | (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) { | |
6553 | cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq - | |
6554 | LPFC_SP_WQN_DEF; | |
6555 | if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) { | |
6556 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6557 | "2581 Not enough WQs (%d) from " | |
6558 | "the pci function for supporting " | |
6559 | "FCP WQs (%d)\n", | |
6560 | phba->sli4_hba.max_cfg_param.max_wq, | |
6561 | phba->cfg_fcp_wq_count); | |
6562 | goto out_error; | |
6563 | } | |
6564 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6565 | "2582 Not enough WQs (%d) from the pci " | |
6566 | "function for supporting the requested " | |
6567 | "FCP WQs (%d), the actual FCP WQs can " | |
6568 | "be supported: %d\n", | |
6569 | phba->sli4_hba.max_cfg_param.max_wq, | |
6570 | phba->cfg_fcp_wq_count, cfg_fcp_wq_count); | |
6571 | } | |
6572 | /* The actual number of FCP work queues adopted */ | |
6573 | phba->cfg_fcp_wq_count = cfg_fcp_wq_count; | |
6574 | ||
6575 | /* Sanity check on FCP fast-path EQ parameters */ | |
6576 | cfg_fcp_eq_count = phba->cfg_fcp_eq_count; | |
6577 | if (cfg_fcp_eq_count > | |
6578 | (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) { | |
6579 | cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq - | |
6580 | LPFC_SP_EQN_DEF; | |
6581 | if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) { | |
6582 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6583 | "2574 Not enough EQs (%d) from the " | |
6584 | "pci function for supporting FCP " | |
6585 | "EQs (%d)\n", | |
6586 | phba->sli4_hba.max_cfg_param.max_eq, | |
6587 | phba->cfg_fcp_eq_count); | |
6588 | goto out_error; | |
6589 | } | |
6590 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6591 | "2575 Not enough EQs (%d) from the pci " | |
6592 | "function for supporting the requested " | |
6593 | "FCP EQs (%d), the actual FCP EQs can " | |
6594 | "be supported: %d\n", | |
6595 | phba->sli4_hba.max_cfg_param.max_eq, | |
6596 | phba->cfg_fcp_eq_count, cfg_fcp_eq_count); | |
6597 | } | |
6598 | /* It does not make sense to have more EQs than WQs */ | |
6599 | if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) { | |
6600 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
6a9c52cf JS |
6601 | "2593 The FCP EQ count(%d) cannot be greater " |
6602 | "than the FCP WQ count(%d), limiting the " | |
6603 | "FCP EQ count to %d\n", cfg_fcp_eq_count, | |
da0436e9 JS |
6604 | phba->cfg_fcp_wq_count, |
6605 | phba->cfg_fcp_wq_count); | |
6606 | cfg_fcp_eq_count = phba->cfg_fcp_wq_count; | |
6607 | } | |
6608 | /* The actual number of FCP event queues adopted */ | |
6609 | phba->cfg_fcp_eq_count = cfg_fcp_eq_count; | |
6610 | /* The overall number of event queues used */ | |
6611 | phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF; | |
3772a991 | 6612 | |
da0436e9 JS |
6613 | /* Get EQ depth from module parameter, fake the default for now */ |
6614 | phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B; | |
6615 | phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT; | |
3772a991 | 6616 | |
5350d872 JS |
6617 | /* Get CQ depth from module parameter, fake the default for now */ |
6618 | phba->sli4_hba.cq_esize = LPFC_CQE_SIZE; | |
6619 | phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT; | |
6620 | ||
6621 | return 0; | |
6622 | out_error: | |
6623 | return -ENOMEM; | |
6624 | } | |
6625 | ||
6626 | /** | |
6627 | * lpfc_sli4_queue_create - Create all the SLI4 queues | |
6628 | * @phba: pointer to lpfc hba data structure. | |
6629 | * | |
6630 | * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA | |
6631 | * operation. For each SLI4 queue type, the parameters such as queue entry | |
6632 | * count (queue depth) shall be taken from the module parameter. For now, | |
6633 | * we just use some constant number as place holder. | |
6634 | * | |
6635 | * Return codes | |
6636 | * 0 - sucessful | |
6637 | * -ENOMEM - No availble memory | |
6638 | * -EIO - The mailbox failed to complete successfully. | |
6639 | **/ | |
6640 | int | |
6641 | lpfc_sli4_queue_create(struct lpfc_hba *phba) | |
6642 | { | |
6643 | struct lpfc_queue *qdesc; | |
6644 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; | |
6645 | ||
6646 | /* | |
6647 | * Create Event Queues (EQs) | |
6648 | */ | |
6649 | ||
da0436e9 JS |
6650 | /* Create slow path event queue */ |
6651 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | |
6652 | phba->sli4_hba.eq_ecount); | |
6653 | if (!qdesc) { | |
6654 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6655 | "0496 Failed allocate slow-path EQ\n"); | |
6656 | goto out_error; | |
6657 | } | |
6658 | phba->sli4_hba.sp_eq = qdesc; | |
6659 | ||
5350d872 JS |
6660 | /* |
6661 | * Create fast-path FCP Event Queue(s). The cfg_fcp_eq_count can be | |
6662 | * zero whenever there is exactly one interrupt vector. This is not | |
6663 | * an error. | |
6664 | */ | |
6665 | if (phba->cfg_fcp_eq_count) { | |
6666 | phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) * | |
6667 | phba->cfg_fcp_eq_count), GFP_KERNEL); | |
6668 | if (!phba->sli4_hba.fp_eq) { | |
6669 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6670 | "2576 Failed allocate memory for " | |
6671 | "fast-path EQ record array\n"); | |
6672 | goto out_free_sp_eq; | |
6673 | } | |
da0436e9 JS |
6674 | } |
6675 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { | |
6676 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize, | |
6677 | phba->sli4_hba.eq_ecount); | |
6678 | if (!qdesc) { | |
6679 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6680 | "0497 Failed allocate fast-path EQ\n"); | |
6681 | goto out_free_fp_eq; | |
6682 | } | |
6683 | phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc; | |
6684 | } | |
6685 | ||
6686 | /* | |
6687 | * Create Complete Queues (CQs) | |
6688 | */ | |
6689 | ||
da0436e9 JS |
6690 | /* Create slow-path Mailbox Command Complete Queue */ |
6691 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
6692 | phba->sli4_hba.cq_ecount); | |
6693 | if (!qdesc) { | |
6694 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6695 | "0500 Failed allocate slow-path mailbox CQ\n"); | |
6696 | goto out_free_fp_eq; | |
6697 | } | |
6698 | phba->sli4_hba.mbx_cq = qdesc; | |
6699 | ||
6700 | /* Create slow-path ELS Complete Queue */ | |
6701 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, | |
6702 | phba->sli4_hba.cq_ecount); | |
6703 | if (!qdesc) { | |
6704 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6705 | "0501 Failed allocate slow-path ELS CQ\n"); | |
6706 | goto out_free_mbx_cq; | |
6707 | } | |
6708 | phba->sli4_hba.els_cq = qdesc; | |
6709 | ||
da0436e9 | 6710 | |
5350d872 JS |
6711 | /* |
6712 | * Create fast-path FCP Completion Queue(s), one-to-one with FCP EQs. | |
6713 | * If there are no FCP EQs then create exactly one FCP CQ. | |
6714 | */ | |
6715 | if (phba->cfg_fcp_eq_count) | |
6716 | phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) * | |
6717 | phba->cfg_fcp_eq_count), | |
6718 | GFP_KERNEL); | |
6719 | else | |
6720 | phba->sli4_hba.fcp_cq = kzalloc(sizeof(struct lpfc_queue *), | |
6721 | GFP_KERNEL); | |
da0436e9 JS |
6722 | if (!phba->sli4_hba.fcp_cq) { |
6723 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6724 | "2577 Failed allocate memory for fast-path " | |
6725 | "CQ record array\n"); | |
4d9ab994 | 6726 | goto out_free_els_cq; |
da0436e9 | 6727 | } |
5350d872 JS |
6728 | fcp_cqidx = 0; |
6729 | do { | |
da0436e9 JS |
6730 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize, |
6731 | phba->sli4_hba.cq_ecount); | |
6732 | if (!qdesc) { | |
6733 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6734 | "0499 Failed allocate fast-path FCP " | |
6735 | "CQ (%d)\n", fcp_cqidx); | |
6736 | goto out_free_fcp_cq; | |
6737 | } | |
6738 | phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc; | |
5350d872 | 6739 | } while (++fcp_cqidx < phba->cfg_fcp_eq_count); |
da0436e9 JS |
6740 | |
6741 | /* Create Mailbox Command Queue */ | |
6742 | phba->sli4_hba.mq_esize = LPFC_MQE_SIZE; | |
6743 | phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT; | |
6744 | ||
6745 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize, | |
6746 | phba->sli4_hba.mq_ecount); | |
6747 | if (!qdesc) { | |
6748 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6749 | "0505 Failed allocate slow-path MQ\n"); | |
6750 | goto out_free_fcp_cq; | |
6751 | } | |
6752 | phba->sli4_hba.mbx_wq = qdesc; | |
6753 | ||
6754 | /* | |
6755 | * Create all the Work Queues (WQs) | |
6756 | */ | |
6757 | phba->sli4_hba.wq_esize = LPFC_WQE_SIZE; | |
6758 | phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT; | |
6759 | ||
6760 | /* Create slow-path ELS Work Queue */ | |
6761 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
6762 | phba->sli4_hba.wq_ecount); | |
6763 | if (!qdesc) { | |
6764 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6765 | "0504 Failed allocate slow-path ELS WQ\n"); | |
6766 | goto out_free_mbx_wq; | |
6767 | } | |
6768 | phba->sli4_hba.els_wq = qdesc; | |
6769 | ||
6770 | /* Create fast-path FCP Work Queue(s) */ | |
6771 | phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) * | |
6772 | phba->cfg_fcp_wq_count), GFP_KERNEL); | |
6773 | if (!phba->sli4_hba.fcp_wq) { | |
6774 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6775 | "2578 Failed allocate memory for fast-path " | |
6776 | "WQ record array\n"); | |
6777 | goto out_free_els_wq; | |
6778 | } | |
6779 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { | |
6780 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize, | |
6781 | phba->sli4_hba.wq_ecount); | |
6782 | if (!qdesc) { | |
6783 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6784 | "0503 Failed allocate fast-path FCP " | |
6785 | "WQ (%d)\n", fcp_wqidx); | |
6786 | goto out_free_fcp_wq; | |
6787 | } | |
6788 | phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc; | |
6789 | } | |
6790 | ||
6791 | /* | |
6792 | * Create Receive Queue (RQ) | |
6793 | */ | |
6794 | phba->sli4_hba.rq_esize = LPFC_RQE_SIZE; | |
6795 | phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT; | |
6796 | ||
6797 | /* Create Receive Queue for header */ | |
6798 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
6799 | phba->sli4_hba.rq_ecount); | |
6800 | if (!qdesc) { | |
6801 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6802 | "0506 Failed allocate receive HRQ\n"); | |
6803 | goto out_free_fcp_wq; | |
6804 | } | |
6805 | phba->sli4_hba.hdr_rq = qdesc; | |
6806 | ||
6807 | /* Create Receive Queue for data */ | |
6808 | qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize, | |
6809 | phba->sli4_hba.rq_ecount); | |
6810 | if (!qdesc) { | |
6811 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6812 | "0507 Failed allocate receive DRQ\n"); | |
6813 | goto out_free_hdr_rq; | |
6814 | } | |
6815 | phba->sli4_hba.dat_rq = qdesc; | |
6816 | ||
6817 | return 0; | |
6818 | ||
6819 | out_free_hdr_rq: | |
6820 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); | |
6821 | phba->sli4_hba.hdr_rq = NULL; | |
6822 | out_free_fcp_wq: | |
6823 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) { | |
6824 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]); | |
6825 | phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL; | |
6826 | } | |
6827 | kfree(phba->sli4_hba.fcp_wq); | |
2e90f4b5 | 6828 | phba->sli4_hba.fcp_wq = NULL; |
da0436e9 JS |
6829 | out_free_els_wq: |
6830 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); | |
6831 | phba->sli4_hba.els_wq = NULL; | |
6832 | out_free_mbx_wq: | |
6833 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); | |
6834 | phba->sli4_hba.mbx_wq = NULL; | |
6835 | out_free_fcp_cq: | |
6836 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) { | |
6837 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]); | |
6838 | phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL; | |
6839 | } | |
6840 | kfree(phba->sli4_hba.fcp_cq); | |
2e90f4b5 | 6841 | phba->sli4_hba.fcp_cq = NULL; |
da0436e9 JS |
6842 | out_free_els_cq: |
6843 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); | |
6844 | phba->sli4_hba.els_cq = NULL; | |
6845 | out_free_mbx_cq: | |
6846 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); | |
6847 | phba->sli4_hba.mbx_cq = NULL; | |
6848 | out_free_fp_eq: | |
6849 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) { | |
6850 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]); | |
6851 | phba->sli4_hba.fp_eq[fcp_eqidx] = NULL; | |
6852 | } | |
6853 | kfree(phba->sli4_hba.fp_eq); | |
2e90f4b5 | 6854 | phba->sli4_hba.fp_eq = NULL; |
da0436e9 JS |
6855 | out_free_sp_eq: |
6856 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); | |
6857 | phba->sli4_hba.sp_eq = NULL; | |
6858 | out_error: | |
6859 | return -ENOMEM; | |
6860 | } | |
6861 | ||
6862 | /** | |
6863 | * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues | |
6864 | * @phba: pointer to lpfc hba data structure. | |
6865 | * | |
6866 | * This routine is invoked to release all the SLI4 queues with the FCoE HBA | |
6867 | * operation. | |
6868 | * | |
6869 | * Return codes | |
af901ca1 | 6870 | * 0 - successful |
25985edc | 6871 | * -ENOMEM - No available memory |
d439d286 | 6872 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 | 6873 | **/ |
5350d872 | 6874 | void |
da0436e9 JS |
6875 | lpfc_sli4_queue_destroy(struct lpfc_hba *phba) |
6876 | { | |
6877 | int fcp_qidx; | |
6878 | ||
6879 | /* Release mailbox command work queue */ | |
6880 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq); | |
6881 | phba->sli4_hba.mbx_wq = NULL; | |
6882 | ||
6883 | /* Release ELS work queue */ | |
6884 | lpfc_sli4_queue_free(phba->sli4_hba.els_wq); | |
6885 | phba->sli4_hba.els_wq = NULL; | |
6886 | ||
6887 | /* Release FCP work queue */ | |
2e90f4b5 JS |
6888 | if (phba->sli4_hba.fcp_wq != NULL) |
6889 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; | |
6890 | fcp_qidx++) | |
6891 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]); | |
da0436e9 JS |
6892 | kfree(phba->sli4_hba.fcp_wq); |
6893 | phba->sli4_hba.fcp_wq = NULL; | |
6894 | ||
6895 | /* Release unsolicited receive queue */ | |
6896 | lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq); | |
6897 | phba->sli4_hba.hdr_rq = NULL; | |
6898 | lpfc_sli4_queue_free(phba->sli4_hba.dat_rq); | |
6899 | phba->sli4_hba.dat_rq = NULL; | |
6900 | ||
da0436e9 JS |
6901 | /* Release ELS complete queue */ |
6902 | lpfc_sli4_queue_free(phba->sli4_hba.els_cq); | |
6903 | phba->sli4_hba.els_cq = NULL; | |
6904 | ||
6905 | /* Release mailbox command complete queue */ | |
6906 | lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq); | |
6907 | phba->sli4_hba.mbx_cq = NULL; | |
6908 | ||
6909 | /* Release FCP response complete queue */ | |
0558056c | 6910 | fcp_qidx = 0; |
2e90f4b5 JS |
6911 | if (phba->sli4_hba.fcp_cq != NULL) |
6912 | do | |
6913 | lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]); | |
6914 | while (++fcp_qidx < phba->cfg_fcp_eq_count); | |
da0436e9 JS |
6915 | kfree(phba->sli4_hba.fcp_cq); |
6916 | phba->sli4_hba.fcp_cq = NULL; | |
6917 | ||
6918 | /* Release fast-path event queue */ | |
2e90f4b5 JS |
6919 | if (phba->sli4_hba.fp_eq != NULL) |
6920 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; | |
6921 | fcp_qidx++) | |
6922 | lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]); | |
da0436e9 JS |
6923 | kfree(phba->sli4_hba.fp_eq); |
6924 | phba->sli4_hba.fp_eq = NULL; | |
6925 | ||
6926 | /* Release slow-path event queue */ | |
6927 | lpfc_sli4_queue_free(phba->sli4_hba.sp_eq); | |
6928 | phba->sli4_hba.sp_eq = NULL; | |
6929 | ||
6930 | return; | |
6931 | } | |
6932 | ||
6933 | /** | |
6934 | * lpfc_sli4_queue_setup - Set up all the SLI4 queues | |
6935 | * @phba: pointer to lpfc hba data structure. | |
6936 | * | |
6937 | * This routine is invoked to set up all the SLI4 queues for the FCoE HBA | |
6938 | * operation. | |
6939 | * | |
6940 | * Return codes | |
af901ca1 | 6941 | * 0 - successful |
25985edc | 6942 | * -ENOMEM - No available memory |
d439d286 | 6943 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
6944 | **/ |
6945 | int | |
6946 | lpfc_sli4_queue_setup(struct lpfc_hba *phba) | |
6947 | { | |
2a76a283 JS |
6948 | struct lpfc_sli *psli = &phba->sli; |
6949 | struct lpfc_sli_ring *pring; | |
da0436e9 JS |
6950 | int rc = -ENOMEM; |
6951 | int fcp_eqidx, fcp_cqidx, fcp_wqidx; | |
6952 | int fcp_cq_index = 0; | |
6953 | ||
6954 | /* | |
6955 | * Set up Event Queues (EQs) | |
6956 | */ | |
6957 | ||
6958 | /* Set up slow-path event queue */ | |
6959 | if (!phba->sli4_hba.sp_eq) { | |
6960 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6961 | "0520 Slow-path EQ not allocated\n"); | |
6962 | goto out_error; | |
6963 | } | |
6964 | rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq, | |
6965 | LPFC_SP_DEF_IMAX); | |
6966 | if (rc) { | |
6967 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6968 | "0521 Failed setup of slow-path EQ: " | |
6969 | "rc = 0x%x\n", rc); | |
6970 | goto out_error; | |
6971 | } | |
6972 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
6973 | "2583 Slow-path EQ setup: queue-id=%d\n", | |
6974 | phba->sli4_hba.sp_eq->queue_id); | |
6975 | ||
6976 | /* Set up fast-path event queue */ | |
1b51197d | 6977 | if (phba->cfg_fcp_eq_count && !phba->sli4_hba.fp_eq) { |
2e90f4b5 JS |
6978 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
6979 | "3147 Fast-path EQs not allocated\n"); | |
1b51197d | 6980 | rc = -ENOMEM; |
2e90f4b5 JS |
6981 | goto out_destroy_sp_eq; |
6982 | } | |
da0436e9 JS |
6983 | for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) { |
6984 | if (!phba->sli4_hba.fp_eq[fcp_eqidx]) { | |
6985 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6986 | "0522 Fast-path EQ (%d) not " | |
6987 | "allocated\n", fcp_eqidx); | |
1b51197d | 6988 | rc = -ENOMEM; |
da0436e9 JS |
6989 | goto out_destroy_fp_eq; |
6990 | } | |
6991 | rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx], | |
6992 | phba->cfg_fcp_imax); | |
6993 | if (rc) { | |
6994 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6995 | "0523 Failed setup of fast-path EQ " | |
6996 | "(%d), rc = 0x%x\n", fcp_eqidx, rc); | |
6997 | goto out_destroy_fp_eq; | |
6998 | } | |
6999 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7000 | "2584 Fast-path EQ setup: " | |
7001 | "queue[%d]-id=%d\n", fcp_eqidx, | |
7002 | phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id); | |
7003 | } | |
7004 | ||
7005 | /* | |
7006 | * Set up Complete Queues (CQs) | |
7007 | */ | |
7008 | ||
7009 | /* Set up slow-path MBOX Complete Queue as the first CQ */ | |
7010 | if (!phba->sli4_hba.mbx_cq) { | |
7011 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7012 | "0528 Mailbox CQ not allocated\n"); | |
1b51197d | 7013 | rc = -ENOMEM; |
da0436e9 JS |
7014 | goto out_destroy_fp_eq; |
7015 | } | |
7016 | rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq, | |
7017 | LPFC_MCQ, LPFC_MBOX); | |
7018 | if (rc) { | |
7019 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7020 | "0529 Failed setup of slow-path mailbox CQ: " | |
7021 | "rc = 0x%x\n", rc); | |
7022 | goto out_destroy_fp_eq; | |
7023 | } | |
7024 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7025 | "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n", | |
7026 | phba->sli4_hba.mbx_cq->queue_id, | |
7027 | phba->sli4_hba.sp_eq->queue_id); | |
7028 | ||
7029 | /* Set up slow-path ELS Complete Queue */ | |
7030 | if (!phba->sli4_hba.els_cq) { | |
7031 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7032 | "0530 ELS CQ not allocated\n"); | |
1b51197d | 7033 | rc = -ENOMEM; |
da0436e9 JS |
7034 | goto out_destroy_mbx_cq; |
7035 | } | |
7036 | rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq, | |
7037 | LPFC_WCQ, LPFC_ELS); | |
7038 | if (rc) { | |
7039 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7040 | "0531 Failed setup of slow-path ELS CQ: " | |
7041 | "rc = 0x%x\n", rc); | |
7042 | goto out_destroy_mbx_cq; | |
7043 | } | |
7044 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7045 | "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n", | |
7046 | phba->sli4_hba.els_cq->queue_id, | |
7047 | phba->sli4_hba.sp_eq->queue_id); | |
7048 | ||
da0436e9 | 7049 | /* Set up fast-path FCP Response Complete Queue */ |
2e90f4b5 JS |
7050 | if (!phba->sli4_hba.fcp_cq) { |
7051 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7052 | "3148 Fast-path FCP CQ array not " | |
7053 | "allocated\n"); | |
1b51197d | 7054 | rc = -ENOMEM; |
2e90f4b5 JS |
7055 | goto out_destroy_els_cq; |
7056 | } | |
0558056c JS |
7057 | fcp_cqidx = 0; |
7058 | do { | |
da0436e9 JS |
7059 | if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) { |
7060 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7061 | "0526 Fast-path FCP CQ (%d) not " | |
7062 | "allocated\n", fcp_cqidx); | |
1b51197d | 7063 | rc = -ENOMEM; |
da0436e9 JS |
7064 | goto out_destroy_fcp_cq; |
7065 | } | |
0558056c JS |
7066 | if (phba->cfg_fcp_eq_count) |
7067 | rc = lpfc_cq_create(phba, | |
7068 | phba->sli4_hba.fcp_cq[fcp_cqidx], | |
7069 | phba->sli4_hba.fp_eq[fcp_cqidx], | |
7070 | LPFC_WCQ, LPFC_FCP); | |
7071 | else | |
7072 | rc = lpfc_cq_create(phba, | |
7073 | phba->sli4_hba.fcp_cq[fcp_cqidx], | |
7074 | phba->sli4_hba.sp_eq, | |
7075 | LPFC_WCQ, LPFC_FCP); | |
da0436e9 JS |
7076 | if (rc) { |
7077 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7078 | "0527 Failed setup of fast-path FCP " | |
7079 | "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc); | |
7080 | goto out_destroy_fcp_cq; | |
7081 | } | |
7082 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7083 | "2588 FCP CQ setup: cq[%d]-id=%d, " | |
0558056c | 7084 | "parent %seq[%d]-id=%d\n", |
da0436e9 JS |
7085 | fcp_cqidx, |
7086 | phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id, | |
0558056c | 7087 | (phba->cfg_fcp_eq_count) ? "" : "sp_", |
da0436e9 | 7088 | fcp_cqidx, |
0558056c JS |
7089 | (phba->cfg_fcp_eq_count) ? |
7090 | phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id : | |
7091 | phba->sli4_hba.sp_eq->queue_id); | |
7092 | } while (++fcp_cqidx < phba->cfg_fcp_eq_count); | |
da0436e9 JS |
7093 | |
7094 | /* | |
7095 | * Set up all the Work Queues (WQs) | |
7096 | */ | |
7097 | ||
7098 | /* Set up Mailbox Command Queue */ | |
7099 | if (!phba->sli4_hba.mbx_wq) { | |
7100 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7101 | "0538 Slow-path MQ not allocated\n"); | |
1b51197d | 7102 | rc = -ENOMEM; |
da0436e9 JS |
7103 | goto out_destroy_fcp_cq; |
7104 | } | |
7105 | rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq, | |
7106 | phba->sli4_hba.mbx_cq, LPFC_MBOX); | |
7107 | if (rc) { | |
7108 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7109 | "0539 Failed setup of slow-path MQ: " | |
7110 | "rc = 0x%x\n", rc); | |
7111 | goto out_destroy_fcp_cq; | |
7112 | } | |
7113 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7114 | "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n", | |
7115 | phba->sli4_hba.mbx_wq->queue_id, | |
7116 | phba->sli4_hba.mbx_cq->queue_id); | |
7117 | ||
7118 | /* Set up slow-path ELS Work Queue */ | |
7119 | if (!phba->sli4_hba.els_wq) { | |
7120 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7121 | "0536 Slow-path ELS WQ not allocated\n"); | |
1b51197d | 7122 | rc = -ENOMEM; |
da0436e9 JS |
7123 | goto out_destroy_mbx_wq; |
7124 | } | |
7125 | rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq, | |
7126 | phba->sli4_hba.els_cq, LPFC_ELS); | |
7127 | if (rc) { | |
7128 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7129 | "0537 Failed setup of slow-path ELS WQ: " | |
7130 | "rc = 0x%x\n", rc); | |
7131 | goto out_destroy_mbx_wq; | |
7132 | } | |
2a76a283 JS |
7133 | |
7134 | /* Bind this WQ to the ELS ring */ | |
7135 | pring = &psli->ring[LPFC_ELS_RING]; | |
7136 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.els_wq; | |
7137 | phba->sli4_hba.els_cq->pring = pring; | |
7138 | ||
da0436e9 JS |
7139 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
7140 | "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n", | |
7141 | phba->sli4_hba.els_wq->queue_id, | |
7142 | phba->sli4_hba.els_cq->queue_id); | |
7143 | ||
7144 | /* Set up fast-path FCP Work Queue */ | |
2e90f4b5 JS |
7145 | if (!phba->sli4_hba.fcp_wq) { |
7146 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7147 | "3149 Fast-path FCP WQ array not " | |
7148 | "allocated\n"); | |
1b51197d | 7149 | rc = -ENOMEM; |
2e90f4b5 JS |
7150 | goto out_destroy_els_wq; |
7151 | } | |
da0436e9 JS |
7152 | for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) { |
7153 | if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) { | |
7154 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7155 | "0534 Fast-path FCP WQ (%d) not " | |
7156 | "allocated\n", fcp_wqidx); | |
1b51197d | 7157 | rc = -ENOMEM; |
da0436e9 JS |
7158 | goto out_destroy_fcp_wq; |
7159 | } | |
7160 | rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx], | |
7161 | phba->sli4_hba.fcp_cq[fcp_cq_index], | |
7162 | LPFC_FCP); | |
7163 | if (rc) { | |
7164 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7165 | "0535 Failed setup of fast-path FCP " | |
7166 | "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc); | |
7167 | goto out_destroy_fcp_wq; | |
7168 | } | |
2a76a283 JS |
7169 | |
7170 | /* Bind this WQ to the next FCP ring */ | |
7171 | pring = &psli->ring[MAX_SLI3_CONFIGURED_RINGS + fcp_wqidx]; | |
7172 | pring->sli.sli4.wqp = (void *)phba->sli4_hba.fcp_wq[fcp_wqidx]; | |
7173 | phba->sli4_hba.fcp_cq[fcp_cq_index]->pring = pring; | |
7174 | ||
da0436e9 JS |
7175 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
7176 | "2591 FCP WQ setup: wq[%d]-id=%d, " | |
7177 | "parent cq[%d]-id=%d\n", | |
7178 | fcp_wqidx, | |
7179 | phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id, | |
7180 | fcp_cq_index, | |
7181 | phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id); | |
7182 | /* Round robin FCP Work Queue's Completion Queue assignment */ | |
0558056c JS |
7183 | if (phba->cfg_fcp_eq_count) |
7184 | fcp_cq_index = ((fcp_cq_index + 1) % | |
7185 | phba->cfg_fcp_eq_count); | |
da0436e9 JS |
7186 | } |
7187 | ||
7188 | /* | |
7189 | * Create Receive Queue (RQ) | |
7190 | */ | |
7191 | if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) { | |
7192 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7193 | "0540 Receive Queue not allocated\n"); | |
1b51197d | 7194 | rc = -ENOMEM; |
da0436e9 JS |
7195 | goto out_destroy_fcp_wq; |
7196 | } | |
73d91e50 JS |
7197 | |
7198 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.hdr_rq, LPFC_ELS_HBQ); | |
7199 | lpfc_rq_adjust_repost(phba, phba->sli4_hba.dat_rq, LPFC_ELS_HBQ); | |
7200 | ||
da0436e9 | 7201 | rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq, |
4d9ab994 | 7202 | phba->sli4_hba.els_cq, LPFC_USOL); |
da0436e9 JS |
7203 | if (rc) { |
7204 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7205 | "0541 Failed setup of Receive Queue: " | |
7206 | "rc = 0x%x\n", rc); | |
7207 | goto out_destroy_fcp_wq; | |
7208 | } | |
73d91e50 | 7209 | |
da0436e9 JS |
7210 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
7211 | "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d " | |
7212 | "parent cq-id=%d\n", | |
7213 | phba->sli4_hba.hdr_rq->queue_id, | |
7214 | phba->sli4_hba.dat_rq->queue_id, | |
4d9ab994 | 7215 | phba->sli4_hba.els_cq->queue_id); |
da0436e9 JS |
7216 | return 0; |
7217 | ||
7218 | out_destroy_fcp_wq: | |
7219 | for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) | |
7220 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]); | |
2e90f4b5 | 7221 | out_destroy_els_wq: |
da0436e9 JS |
7222 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); |
7223 | out_destroy_mbx_wq: | |
7224 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | |
7225 | out_destroy_fcp_cq: | |
7226 | for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) | |
7227 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]); | |
2e90f4b5 | 7228 | out_destroy_els_cq: |
da0436e9 JS |
7229 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); |
7230 | out_destroy_mbx_cq: | |
7231 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | |
7232 | out_destroy_fp_eq: | |
7233 | for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) | |
7234 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]); | |
2e90f4b5 | 7235 | out_destroy_sp_eq: |
da0436e9 JS |
7236 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); |
7237 | out_error: | |
7238 | return rc; | |
7239 | } | |
7240 | ||
7241 | /** | |
7242 | * lpfc_sli4_queue_unset - Unset all the SLI4 queues | |
7243 | * @phba: pointer to lpfc hba data structure. | |
7244 | * | |
7245 | * This routine is invoked to unset all the SLI4 queues with the FCoE HBA | |
7246 | * operation. | |
7247 | * | |
7248 | * Return codes | |
af901ca1 | 7249 | * 0 - successful |
25985edc | 7250 | * -ENOMEM - No available memory |
d439d286 | 7251 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
7252 | **/ |
7253 | void | |
7254 | lpfc_sli4_queue_unset(struct lpfc_hba *phba) | |
7255 | { | |
7256 | int fcp_qidx; | |
7257 | ||
7258 | /* Unset mailbox command work queue */ | |
7259 | lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq); | |
7260 | /* Unset ELS work queue */ | |
7261 | lpfc_wq_destroy(phba, phba->sli4_hba.els_wq); | |
7262 | /* Unset unsolicited receive queue */ | |
7263 | lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq); | |
7264 | /* Unset FCP work queue */ | |
7265 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++) | |
7266 | lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]); | |
7267 | /* Unset mailbox command complete queue */ | |
7268 | lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq); | |
7269 | /* Unset ELS complete queue */ | |
7270 | lpfc_cq_destroy(phba, phba->sli4_hba.els_cq); | |
da0436e9 | 7271 | /* Unset FCP response complete queue */ |
2e90f4b5 JS |
7272 | if (phba->sli4_hba.fcp_cq) { |
7273 | fcp_qidx = 0; | |
7274 | do { | |
7275 | lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]); | |
7276 | } while (++fcp_qidx < phba->cfg_fcp_eq_count); | |
7277 | } | |
da0436e9 | 7278 | /* Unset fast-path event queue */ |
2e90f4b5 JS |
7279 | if (phba->sli4_hba.fp_eq) { |
7280 | for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; | |
7281 | fcp_qidx++) | |
7282 | lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]); | |
7283 | } | |
da0436e9 JS |
7284 | /* Unset slow-path event queue */ |
7285 | lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq); | |
7286 | } | |
7287 | ||
7288 | /** | |
7289 | * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool | |
7290 | * @phba: pointer to lpfc hba data structure. | |
7291 | * | |
7292 | * This routine is invoked to allocate and set up a pool of completion queue | |
7293 | * events. The body of the completion queue event is a completion queue entry | |
7294 | * CQE. For now, this pool is used for the interrupt service routine to queue | |
7295 | * the following HBA completion queue events for the worker thread to process: | |
7296 | * - Mailbox asynchronous events | |
7297 | * - Receive queue completion unsolicited events | |
7298 | * Later, this can be used for all the slow-path events. | |
7299 | * | |
7300 | * Return codes | |
af901ca1 | 7301 | * 0 - successful |
25985edc | 7302 | * -ENOMEM - No available memory |
da0436e9 JS |
7303 | **/ |
7304 | static int | |
7305 | lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba) | |
7306 | { | |
7307 | struct lpfc_cq_event *cq_event; | |
7308 | int i; | |
7309 | ||
7310 | for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) { | |
7311 | cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL); | |
7312 | if (!cq_event) | |
7313 | goto out_pool_create_fail; | |
7314 | list_add_tail(&cq_event->list, | |
7315 | &phba->sli4_hba.sp_cqe_event_pool); | |
7316 | } | |
7317 | return 0; | |
7318 | ||
7319 | out_pool_create_fail: | |
7320 | lpfc_sli4_cq_event_pool_destroy(phba); | |
7321 | return -ENOMEM; | |
7322 | } | |
7323 | ||
7324 | /** | |
7325 | * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool | |
7326 | * @phba: pointer to lpfc hba data structure. | |
7327 | * | |
7328 | * This routine is invoked to free the pool of completion queue events at | |
7329 | * driver unload time. Note that, it is the responsibility of the driver | |
7330 | * cleanup routine to free all the outstanding completion-queue events | |
7331 | * allocated from this pool back into the pool before invoking this routine | |
7332 | * to destroy the pool. | |
7333 | **/ | |
7334 | static void | |
7335 | lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba) | |
7336 | { | |
7337 | struct lpfc_cq_event *cq_event, *next_cq_event; | |
7338 | ||
7339 | list_for_each_entry_safe(cq_event, next_cq_event, | |
7340 | &phba->sli4_hba.sp_cqe_event_pool, list) { | |
7341 | list_del(&cq_event->list); | |
7342 | kfree(cq_event); | |
7343 | } | |
7344 | } | |
7345 | ||
7346 | /** | |
7347 | * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
7348 | * @phba: pointer to lpfc hba data structure. | |
7349 | * | |
7350 | * This routine is the lock free version of the API invoked to allocate a | |
7351 | * completion-queue event from the free pool. | |
7352 | * | |
7353 | * Return: Pointer to the newly allocated completion-queue event if successful | |
7354 | * NULL otherwise. | |
7355 | **/ | |
7356 | struct lpfc_cq_event * | |
7357 | __lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
7358 | { | |
7359 | struct lpfc_cq_event *cq_event = NULL; | |
7360 | ||
7361 | list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event, | |
7362 | struct lpfc_cq_event, list); | |
7363 | return cq_event; | |
7364 | } | |
7365 | ||
7366 | /** | |
7367 | * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool | |
7368 | * @phba: pointer to lpfc hba data structure. | |
7369 | * | |
7370 | * This routine is the lock version of the API invoked to allocate a | |
7371 | * completion-queue event from the free pool. | |
7372 | * | |
7373 | * Return: Pointer to the newly allocated completion-queue event if successful | |
7374 | * NULL otherwise. | |
7375 | **/ | |
7376 | struct lpfc_cq_event * | |
7377 | lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba) | |
7378 | { | |
7379 | struct lpfc_cq_event *cq_event; | |
7380 | unsigned long iflags; | |
7381 | ||
7382 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7383 | cq_event = __lpfc_sli4_cq_event_alloc(phba); | |
7384 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7385 | return cq_event; | |
7386 | } | |
7387 | ||
7388 | /** | |
7389 | * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
7390 | * @phba: pointer to lpfc hba data structure. | |
7391 | * @cq_event: pointer to the completion queue event to be freed. | |
7392 | * | |
7393 | * This routine is the lock free version of the API invoked to release a | |
7394 | * completion-queue event back into the free pool. | |
7395 | **/ | |
7396 | void | |
7397 | __lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
7398 | struct lpfc_cq_event *cq_event) | |
7399 | { | |
7400 | list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool); | |
7401 | } | |
7402 | ||
7403 | /** | |
7404 | * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool | |
7405 | * @phba: pointer to lpfc hba data structure. | |
7406 | * @cq_event: pointer to the completion queue event to be freed. | |
7407 | * | |
7408 | * This routine is the lock version of the API invoked to release a | |
7409 | * completion-queue event back into the free pool. | |
7410 | **/ | |
7411 | void | |
7412 | lpfc_sli4_cq_event_release(struct lpfc_hba *phba, | |
7413 | struct lpfc_cq_event *cq_event) | |
7414 | { | |
7415 | unsigned long iflags; | |
7416 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7417 | __lpfc_sli4_cq_event_release(phba, cq_event); | |
7418 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7419 | } | |
7420 | ||
7421 | /** | |
7422 | * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool | |
7423 | * @phba: pointer to lpfc hba data structure. | |
7424 | * | |
7425 | * This routine is to free all the pending completion-queue events to the | |
7426 | * back into the free pool for device reset. | |
7427 | **/ | |
7428 | static void | |
7429 | lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba) | |
7430 | { | |
7431 | LIST_HEAD(cqelist); | |
7432 | struct lpfc_cq_event *cqe; | |
7433 | unsigned long iflags; | |
7434 | ||
7435 | /* Retrieve all the pending WCQEs from pending WCQE lists */ | |
7436 | spin_lock_irqsave(&phba->hbalock, iflags); | |
7437 | /* Pending FCP XRI abort events */ | |
7438 | list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue, | |
7439 | &cqelist); | |
7440 | /* Pending ELS XRI abort events */ | |
7441 | list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue, | |
7442 | &cqelist); | |
7443 | /* Pending asynnc events */ | |
7444 | list_splice_init(&phba->sli4_hba.sp_asynce_work_queue, | |
7445 | &cqelist); | |
7446 | spin_unlock_irqrestore(&phba->hbalock, iflags); | |
7447 | ||
7448 | while (!list_empty(&cqelist)) { | |
7449 | list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list); | |
7450 | lpfc_sli4_cq_event_release(phba, cqe); | |
7451 | } | |
7452 | } | |
7453 | ||
7454 | /** | |
7455 | * lpfc_pci_function_reset - Reset pci function. | |
7456 | * @phba: pointer to lpfc hba data structure. | |
7457 | * | |
7458 | * This routine is invoked to request a PCI function reset. It will destroys | |
7459 | * all resources assigned to the PCI function which originates this request. | |
7460 | * | |
7461 | * Return codes | |
af901ca1 | 7462 | * 0 - successful |
25985edc | 7463 | * -ENOMEM - No available memory |
d439d286 | 7464 | * -EIO - The mailbox failed to complete successfully. |
da0436e9 JS |
7465 | **/ |
7466 | int | |
7467 | lpfc_pci_function_reset(struct lpfc_hba *phba) | |
7468 | { | |
7469 | LPFC_MBOXQ_t *mboxq; | |
2fcee4bf | 7470 | uint32_t rc = 0, if_type; |
da0436e9 | 7471 | uint32_t shdr_status, shdr_add_status; |
2fcee4bf | 7472 | uint32_t rdy_chk, num_resets = 0, reset_again = 0; |
da0436e9 | 7473 | union lpfc_sli4_cfg_shdr *shdr; |
2fcee4bf | 7474 | struct lpfc_register reg_data; |
2b81f942 | 7475 | uint16_t devid; |
da0436e9 | 7476 | |
2fcee4bf JS |
7477 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); |
7478 | switch (if_type) { | |
7479 | case LPFC_SLI_INTF_IF_TYPE_0: | |
7480 | mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, | |
7481 | GFP_KERNEL); | |
7482 | if (!mboxq) { | |
7483 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7484 | "0494 Unable to allocate memory for " | |
7485 | "issuing SLI_FUNCTION_RESET mailbox " | |
7486 | "command\n"); | |
7487 | return -ENOMEM; | |
7488 | } | |
da0436e9 | 7489 | |
2fcee4bf JS |
7490 | /* Setup PCI function reset mailbox-ioctl command */ |
7491 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
7492 | LPFC_MBOX_OPCODE_FUNCTION_RESET, 0, | |
7493 | LPFC_SLI4_MBX_EMBED); | |
7494 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
7495 | shdr = (union lpfc_sli4_cfg_shdr *) | |
7496 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
7497 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
7498 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
7499 | &shdr->response); | |
7500 | if (rc != MBX_TIMEOUT) | |
7501 | mempool_free(mboxq, phba->mbox_mem_pool); | |
7502 | if (shdr_status || shdr_add_status || rc) { | |
7503 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7504 | "0495 SLI_FUNCTION_RESET mailbox " | |
7505 | "failed with status x%x add_status x%x," | |
7506 | " mbx status x%x\n", | |
7507 | shdr_status, shdr_add_status, rc); | |
7508 | rc = -ENXIO; | |
7509 | } | |
7510 | break; | |
7511 | case LPFC_SLI_INTF_IF_TYPE_2: | |
7512 | for (num_resets = 0; | |
7513 | num_resets < MAX_IF_TYPE_2_RESETS; | |
7514 | num_resets++) { | |
7515 | reg_data.word0 = 0; | |
7516 | bf_set(lpfc_sliport_ctrl_end, ®_data, | |
7517 | LPFC_SLIPORT_LITTLE_ENDIAN); | |
7518 | bf_set(lpfc_sliport_ctrl_ip, ®_data, | |
7519 | LPFC_SLIPORT_INIT_PORT); | |
7520 | writel(reg_data.word0, phba->sli4_hba.u.if_type2. | |
7521 | CTRLregaddr); | |
8fcb8acd | 7522 | /* flush */ |
2b81f942 JS |
7523 | pci_read_config_word(phba->pcidev, |
7524 | PCI_DEVICE_ID, &devid); | |
2fcee4bf JS |
7525 | /* |
7526 | * Poll the Port Status Register and wait for RDY for | |
7527 | * up to 10 seconds. If the port doesn't respond, treat | |
7528 | * it as an error. If the port responds with RN, start | |
7529 | * the loop again. | |
7530 | */ | |
7531 | for (rdy_chk = 0; rdy_chk < 1000; rdy_chk++) { | |
73d91e50 | 7532 | msleep(10); |
9940b97b JS |
7533 | if (lpfc_readl(phba->sli4_hba.u.if_type2. |
7534 | STATUSregaddr, ®_data.word0)) { | |
7535 | rc = -ENODEV; | |
73d91e50 | 7536 | goto out; |
9940b97b | 7537 | } |
6b5151fd | 7538 | if (bf_get(lpfc_sliport_status_rn, ®_data)) |
2fcee4bf | 7539 | reset_again++; |
6b5151fd | 7540 | if (bf_get(lpfc_sliport_status_rdy, ®_data)) |
2fcee4bf | 7541 | break; |
2fcee4bf JS |
7542 | } |
7543 | ||
7544 | /* | |
7545 | * If the port responds to the init request with | |
7546 | * reset needed, delay for a bit and restart the loop. | |
7547 | */ | |
6b5151fd | 7548 | if (reset_again && (rdy_chk < 1000)) { |
2fcee4bf JS |
7549 | msleep(10); |
7550 | reset_again = 0; | |
7551 | continue; | |
7552 | } | |
7553 | ||
7554 | /* Detect any port errors. */ | |
2fcee4bf JS |
7555 | if ((bf_get(lpfc_sliport_status_err, ®_data)) || |
7556 | (rdy_chk >= 1000)) { | |
7557 | phba->work_status[0] = readl( | |
7558 | phba->sli4_hba.u.if_type2.ERR1regaddr); | |
7559 | phba->work_status[1] = readl( | |
7560 | phba->sli4_hba.u.if_type2.ERR2regaddr); | |
7561 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8fcb8acd | 7562 | "2890 Port error detected during port " |
8a9d2e80 JS |
7563 | "reset(%d): wait_tmo:%d ms, " |
7564 | "port status reg 0x%x, " | |
2fcee4bf | 7565 | "error 1=0x%x, error 2=0x%x\n", |
8a9d2e80 JS |
7566 | num_resets, rdy_chk*10, |
7567 | reg_data.word0, | |
2fcee4bf JS |
7568 | phba->work_status[0], |
7569 | phba->work_status[1]); | |
7570 | rc = -ENODEV; | |
7571 | } | |
7572 | ||
7573 | /* | |
7574 | * Terminate the outer loop provided the Port indicated | |
7575 | * ready within 10 seconds. | |
7576 | */ | |
7577 | if (rdy_chk < 1000) | |
7578 | break; | |
7579 | } | |
0558056c JS |
7580 | /* delay driver action following IF_TYPE_2 function reset */ |
7581 | msleep(100); | |
2fcee4bf JS |
7582 | break; |
7583 | case LPFC_SLI_INTF_IF_TYPE_1: | |
7584 | default: | |
7585 | break; | |
da0436e9 | 7586 | } |
2fcee4bf | 7587 | |
73d91e50 | 7588 | out: |
2fcee4bf JS |
7589 | /* Catch the not-ready port failure after a port reset. */ |
7590 | if (num_resets >= MAX_IF_TYPE_2_RESETS) | |
7591 | rc = -ENODEV; | |
7592 | ||
da0436e9 JS |
7593 | return rc; |
7594 | } | |
7595 | ||
7596 | /** | |
7597 | * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands | |
7598 | * @phba: pointer to lpfc hba data structure. | |
7599 | * @cnt: number of nop mailbox commands to send. | |
7600 | * | |
7601 | * This routine is invoked to send a number @cnt of NOP mailbox command and | |
7602 | * wait for each command to complete. | |
7603 | * | |
7604 | * Return: the number of NOP mailbox command completed. | |
7605 | **/ | |
7606 | static int | |
7607 | lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt) | |
7608 | { | |
7609 | LPFC_MBOXQ_t *mboxq; | |
7610 | int length, cmdsent; | |
7611 | uint32_t mbox_tmo; | |
7612 | uint32_t rc = 0; | |
7613 | uint32_t shdr_status, shdr_add_status; | |
7614 | union lpfc_sli4_cfg_shdr *shdr; | |
7615 | ||
7616 | if (cnt == 0) { | |
7617 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7618 | "2518 Requested to send 0 NOP mailbox cmd\n"); | |
7619 | return cnt; | |
7620 | } | |
7621 | ||
7622 | mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
7623 | if (!mboxq) { | |
7624 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7625 | "2519 Unable to allocate memory for issuing " | |
7626 | "NOP mailbox command\n"); | |
7627 | return 0; | |
7628 | } | |
7629 | ||
7630 | /* Set up NOP SLI4_CONFIG mailbox-ioctl command */ | |
7631 | length = (sizeof(struct lpfc_mbx_nop) - | |
7632 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
da0436e9 | 7633 | |
da0436e9 | 7634 | for (cmdsent = 0; cmdsent < cnt; cmdsent++) { |
59df3acf JS |
7635 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, |
7636 | LPFC_MBOX_OPCODE_NOP, length, | |
7637 | LPFC_SLI4_MBX_EMBED); | |
da0436e9 JS |
7638 | if (!phba->sli4_hba.intr_enable) |
7639 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
a183a15f JS |
7640 | else { |
7641 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); | |
da0436e9 | 7642 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
a183a15f | 7643 | } |
da0436e9 JS |
7644 | if (rc == MBX_TIMEOUT) |
7645 | break; | |
7646 | /* Check return status */ | |
7647 | shdr = (union lpfc_sli4_cfg_shdr *) | |
7648 | &mboxq->u.mqe.un.sli4_config.header.cfg_shdr; | |
7649 | shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response); | |
7650 | shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, | |
7651 | &shdr->response); | |
7652 | if (shdr_status || shdr_add_status || rc) { | |
7653 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7654 | "2520 NOP mailbox command failed " | |
7655 | "status x%x add_status x%x mbx " | |
7656 | "status x%x\n", shdr_status, | |
7657 | shdr_add_status, rc); | |
7658 | break; | |
7659 | } | |
7660 | } | |
7661 | ||
7662 | if (rc != MBX_TIMEOUT) | |
7663 | mempool_free(mboxq, phba->mbox_mem_pool); | |
7664 | ||
7665 | return cmdsent; | |
7666 | } | |
7667 | ||
da0436e9 JS |
7668 | /** |
7669 | * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space. | |
7670 | * @phba: pointer to lpfc hba data structure. | |
7671 | * | |
7672 | * This routine is invoked to set up the PCI device memory space for device | |
7673 | * with SLI-4 interface spec. | |
7674 | * | |
7675 | * Return codes | |
af901ca1 | 7676 | * 0 - successful |
da0436e9 JS |
7677 | * other values - error |
7678 | **/ | |
7679 | static int | |
7680 | lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba) | |
7681 | { | |
7682 | struct pci_dev *pdev; | |
7683 | unsigned long bar0map_len, bar1map_len, bar2map_len; | |
7684 | int error = -ENODEV; | |
2fcee4bf | 7685 | uint32_t if_type; |
da0436e9 JS |
7686 | |
7687 | /* Obtain PCI device reference */ | |
7688 | if (!phba->pcidev) | |
7689 | return error; | |
7690 | else | |
7691 | pdev = phba->pcidev; | |
7692 | ||
7693 | /* Set the device DMA mask size */ | |
8e68597d MR |
7694 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 |
7695 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(64)) != 0) { | |
7696 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 | |
7697 | || pci_set_consistent_dma_mask(pdev,DMA_BIT_MASK(32)) != 0) { | |
da0436e9 | 7698 | return error; |
8e68597d MR |
7699 | } |
7700 | } | |
da0436e9 | 7701 | |
2fcee4bf JS |
7702 | /* |
7703 | * The BARs and register set definitions and offset locations are | |
7704 | * dependent on the if_type. | |
7705 | */ | |
7706 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, | |
7707 | &phba->sli4_hba.sli_intf.word0)) { | |
7708 | return error; | |
7709 | } | |
7710 | ||
7711 | /* There is no SLI3 failback for SLI4 devices. */ | |
7712 | if (bf_get(lpfc_sli_intf_valid, &phba->sli4_hba.sli_intf) != | |
7713 | LPFC_SLI_INTF_VALID) { | |
7714 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7715 | "2894 SLI_INTF reg contents invalid " | |
7716 | "sli_intf reg 0x%x\n", | |
7717 | phba->sli4_hba.sli_intf.word0); | |
7718 | return error; | |
7719 | } | |
7720 | ||
7721 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); | |
7722 | /* | |
7723 | * Get the bus address of SLI4 device Bar regions and the | |
7724 | * number of bytes required by each mapping. The mapping of the | |
7725 | * particular PCI BARs regions is dependent on the type of | |
7726 | * SLI4 device. | |
da0436e9 | 7727 | */ |
1dfb5a47 JS |
7728 | if (pci_resource_start(pdev, 0)) { |
7729 | phba->pci_bar0_map = pci_resource_start(pdev, 0); | |
7730 | bar0map_len = pci_resource_len(pdev, 0); | |
2fcee4bf JS |
7731 | |
7732 | /* | |
7733 | * Map SLI4 PCI Config Space Register base to a kernel virtual | |
7734 | * addr | |
7735 | */ | |
7736 | phba->sli4_hba.conf_regs_memmap_p = | |
7737 | ioremap(phba->pci_bar0_map, bar0map_len); | |
7738 | if (!phba->sli4_hba.conf_regs_memmap_p) { | |
7739 | dev_printk(KERN_ERR, &pdev->dev, | |
7740 | "ioremap failed for SLI4 PCI config " | |
7741 | "registers.\n"); | |
7742 | goto out; | |
7743 | } | |
7744 | /* Set up BAR0 PCI config space register memory map */ | |
7745 | lpfc_sli4_bar0_register_memmap(phba, if_type); | |
1dfb5a47 JS |
7746 | } else { |
7747 | phba->pci_bar0_map = pci_resource_start(pdev, 1); | |
7748 | bar0map_len = pci_resource_len(pdev, 1); | |
2fcee4bf JS |
7749 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2) { |
7750 | dev_printk(KERN_ERR, &pdev->dev, | |
7751 | "FATAL - No BAR0 mapping for SLI4, if_type 2\n"); | |
7752 | goto out; | |
7753 | } | |
7754 | phba->sli4_hba.conf_regs_memmap_p = | |
da0436e9 | 7755 | ioremap(phba->pci_bar0_map, bar0map_len); |
2fcee4bf JS |
7756 | if (!phba->sli4_hba.conf_regs_memmap_p) { |
7757 | dev_printk(KERN_ERR, &pdev->dev, | |
7758 | "ioremap failed for SLI4 PCI config " | |
7759 | "registers.\n"); | |
7760 | goto out; | |
7761 | } | |
7762 | lpfc_sli4_bar0_register_memmap(phba, if_type); | |
da0436e9 JS |
7763 | } |
7764 | ||
c31098ce JS |
7765 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
7766 | (pci_resource_start(pdev, 2))) { | |
2fcee4bf JS |
7767 | /* |
7768 | * Map SLI4 if type 0 HBA Control Register base to a kernel | |
7769 | * virtual address and setup the registers. | |
7770 | */ | |
7771 | phba->pci_bar1_map = pci_resource_start(pdev, 2); | |
7772 | bar1map_len = pci_resource_len(pdev, 2); | |
7773 | phba->sli4_hba.ctrl_regs_memmap_p = | |
da0436e9 | 7774 | ioremap(phba->pci_bar1_map, bar1map_len); |
2fcee4bf JS |
7775 | if (!phba->sli4_hba.ctrl_regs_memmap_p) { |
7776 | dev_printk(KERN_ERR, &pdev->dev, | |
da0436e9 | 7777 | "ioremap failed for SLI4 HBA control registers.\n"); |
2fcee4bf JS |
7778 | goto out_iounmap_conf; |
7779 | } | |
7780 | lpfc_sli4_bar1_register_memmap(phba); | |
da0436e9 JS |
7781 | } |
7782 | ||
c31098ce JS |
7783 | if ((if_type == LPFC_SLI_INTF_IF_TYPE_0) && |
7784 | (pci_resource_start(pdev, 4))) { | |
2fcee4bf JS |
7785 | /* |
7786 | * Map SLI4 if type 0 HBA Doorbell Register base to a kernel | |
7787 | * virtual address and setup the registers. | |
7788 | */ | |
7789 | phba->pci_bar2_map = pci_resource_start(pdev, 4); | |
7790 | bar2map_len = pci_resource_len(pdev, 4); | |
7791 | phba->sli4_hba.drbl_regs_memmap_p = | |
da0436e9 | 7792 | ioremap(phba->pci_bar2_map, bar2map_len); |
2fcee4bf JS |
7793 | if (!phba->sli4_hba.drbl_regs_memmap_p) { |
7794 | dev_printk(KERN_ERR, &pdev->dev, | |
da0436e9 | 7795 | "ioremap failed for SLI4 HBA doorbell registers.\n"); |
2fcee4bf JS |
7796 | goto out_iounmap_ctrl; |
7797 | } | |
7798 | error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0); | |
7799 | if (error) | |
7800 | goto out_iounmap_all; | |
da0436e9 JS |
7801 | } |
7802 | ||
da0436e9 JS |
7803 | return 0; |
7804 | ||
7805 | out_iounmap_all: | |
7806 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
7807 | out_iounmap_ctrl: | |
7808 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
7809 | out_iounmap_conf: | |
7810 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
7811 | out: | |
7812 | return error; | |
7813 | } | |
7814 | ||
7815 | /** | |
7816 | * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space. | |
7817 | * @phba: pointer to lpfc hba data structure. | |
7818 | * | |
7819 | * This routine is invoked to unset the PCI device memory space for device | |
7820 | * with SLI-4 interface spec. | |
7821 | **/ | |
7822 | static void | |
7823 | lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba) | |
7824 | { | |
2e90f4b5 JS |
7825 | uint32_t if_type; |
7826 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); | |
da0436e9 | 7827 | |
2e90f4b5 JS |
7828 | switch (if_type) { |
7829 | case LPFC_SLI_INTF_IF_TYPE_0: | |
7830 | iounmap(phba->sli4_hba.drbl_regs_memmap_p); | |
7831 | iounmap(phba->sli4_hba.ctrl_regs_memmap_p); | |
7832 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
7833 | break; | |
7834 | case LPFC_SLI_INTF_IF_TYPE_2: | |
7835 | iounmap(phba->sli4_hba.conf_regs_memmap_p); | |
7836 | break; | |
7837 | case LPFC_SLI_INTF_IF_TYPE_1: | |
7838 | default: | |
7839 | dev_printk(KERN_ERR, &phba->pcidev->dev, | |
7840 | "FATAL - unsupported SLI4 interface type - %d\n", | |
7841 | if_type); | |
7842 | break; | |
7843 | } | |
da0436e9 JS |
7844 | } |
7845 | ||
7846 | /** | |
7847 | * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device | |
7848 | * @phba: pointer to lpfc hba data structure. | |
7849 | * | |
7850 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
7851 | * with SLI-3 interface specs. The kernel function pci_enable_msix() is | |
7852 | * called to enable the MSI-X vectors. Note that pci_enable_msix(), once | |
7853 | * invoked, enables either all or nothing, depending on the current | |
7854 | * availability of PCI vector resources. The device driver is responsible | |
7855 | * for calling the individual request_irq() to register each MSI-X vector | |
7856 | * with a interrupt handler, which is done in this function. Note that | |
7857 | * later when device is unloading, the driver should always call free_irq() | |
7858 | * on all MSI-X vectors it has done request_irq() on before calling | |
7859 | * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device | |
7860 | * will be left with MSI-X enabled and leaks its vectors. | |
7861 | * | |
7862 | * Return codes | |
af901ca1 | 7863 | * 0 - successful |
da0436e9 JS |
7864 | * other values - error |
7865 | **/ | |
7866 | static int | |
7867 | lpfc_sli_enable_msix(struct lpfc_hba *phba) | |
7868 | { | |
7869 | int rc, i; | |
7870 | LPFC_MBOXQ_t *pmb; | |
7871 | ||
7872 | /* Set up MSI-X multi-message vectors */ | |
7873 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
7874 | phba->msix_entries[i].entry = i; | |
7875 | ||
7876 | /* Configure MSI-X capability structure */ | |
7877 | rc = pci_enable_msix(phba->pcidev, phba->msix_entries, | |
7878 | ARRAY_SIZE(phba->msix_entries)); | |
7879 | if (rc) { | |
7880 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7881 | "0420 PCI enable MSI-X failed (%d)\n", rc); | |
7882 | goto msi_fail_out; | |
7883 | } | |
7884 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
7885 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
7886 | "0477 MSI-X entry[%d]: vector=x%x " | |
7887 | "message=%d\n", i, | |
7888 | phba->msix_entries[i].vector, | |
7889 | phba->msix_entries[i].entry); | |
7890 | /* | |
7891 | * Assign MSI-X vectors to interrupt handlers | |
7892 | */ | |
7893 | ||
7894 | /* vector-0 is associated to slow-path handler */ | |
7895 | rc = request_irq(phba->msix_entries[0].vector, | |
7896 | &lpfc_sli_sp_intr_handler, IRQF_SHARED, | |
7897 | LPFC_SP_DRIVER_HANDLER_NAME, phba); | |
7898 | if (rc) { | |
7899 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7900 | "0421 MSI-X slow-path request_irq failed " | |
7901 | "(%d)\n", rc); | |
7902 | goto msi_fail_out; | |
7903 | } | |
7904 | ||
7905 | /* vector-1 is associated to fast-path handler */ | |
7906 | rc = request_irq(phba->msix_entries[1].vector, | |
7907 | &lpfc_sli_fp_intr_handler, IRQF_SHARED, | |
7908 | LPFC_FP_DRIVER_HANDLER_NAME, phba); | |
7909 | ||
7910 | if (rc) { | |
7911 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
7912 | "0429 MSI-X fast-path request_irq failed " | |
7913 | "(%d)\n", rc); | |
7914 | goto irq_fail_out; | |
7915 | } | |
7916 | ||
7917 | /* | |
7918 | * Configure HBA MSI-X attention conditions to messages | |
7919 | */ | |
7920 | pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
7921 | ||
7922 | if (!pmb) { | |
7923 | rc = -ENOMEM; | |
7924 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
7925 | "0474 Unable to allocate memory for issuing " | |
7926 | "MBOX_CONFIG_MSI command\n"); | |
7927 | goto mem_fail_out; | |
7928 | } | |
7929 | rc = lpfc_config_msi(phba, pmb); | |
7930 | if (rc) | |
7931 | goto mbx_fail_out; | |
7932 | rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); | |
7933 | if (rc != MBX_SUCCESS) { | |
7934 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | |
7935 | "0351 Config MSI mailbox command failed, " | |
7936 | "mbxCmd x%x, mbxStatus x%x\n", | |
7937 | pmb->u.mb.mbxCommand, pmb->u.mb.mbxStatus); | |
7938 | goto mbx_fail_out; | |
7939 | } | |
7940 | ||
7941 | /* Free memory allocated for mailbox command */ | |
7942 | mempool_free(pmb, phba->mbox_mem_pool); | |
7943 | return rc; | |
7944 | ||
7945 | mbx_fail_out: | |
7946 | /* Free memory allocated for mailbox command */ | |
7947 | mempool_free(pmb, phba->mbox_mem_pool); | |
7948 | ||
7949 | mem_fail_out: | |
7950 | /* free the irq already requested */ | |
7951 | free_irq(phba->msix_entries[1].vector, phba); | |
7952 | ||
7953 | irq_fail_out: | |
7954 | /* free the irq already requested */ | |
7955 | free_irq(phba->msix_entries[0].vector, phba); | |
7956 | ||
7957 | msi_fail_out: | |
7958 | /* Unconfigure MSI-X capability structure */ | |
7959 | pci_disable_msix(phba->pcidev); | |
7960 | return rc; | |
7961 | } | |
7962 | ||
7963 | /** | |
7964 | * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device. | |
7965 | * @phba: pointer to lpfc hba data structure. | |
7966 | * | |
7967 | * This routine is invoked to release the MSI-X vectors and then disable the | |
7968 | * MSI-X interrupt mode to device with SLI-3 interface spec. | |
7969 | **/ | |
7970 | static void | |
7971 | lpfc_sli_disable_msix(struct lpfc_hba *phba) | |
7972 | { | |
7973 | int i; | |
7974 | ||
7975 | /* Free up MSI-X multi-message vectors */ | |
7976 | for (i = 0; i < LPFC_MSIX_VECTORS; i++) | |
7977 | free_irq(phba->msix_entries[i].vector, phba); | |
7978 | /* Disable MSI-X */ | |
7979 | pci_disable_msix(phba->pcidev); | |
7980 | ||
7981 | return; | |
7982 | } | |
7983 | ||
7984 | /** | |
7985 | * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device. | |
7986 | * @phba: pointer to lpfc hba data structure. | |
7987 | * | |
7988 | * This routine is invoked to enable the MSI interrupt mode to device with | |
7989 | * SLI-3 interface spec. The kernel function pci_enable_msi() is called to | |
7990 | * enable the MSI vector. The device driver is responsible for calling the | |
7991 | * request_irq() to register MSI vector with a interrupt the handler, which | |
7992 | * is done in this function. | |
7993 | * | |
7994 | * Return codes | |
af901ca1 | 7995 | * 0 - successful |
da0436e9 JS |
7996 | * other values - error |
7997 | */ | |
7998 | static int | |
7999 | lpfc_sli_enable_msi(struct lpfc_hba *phba) | |
8000 | { | |
8001 | int rc; | |
8002 | ||
8003 | rc = pci_enable_msi(phba->pcidev); | |
8004 | if (!rc) | |
8005 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8006 | "0462 PCI enable MSI mode success.\n"); | |
8007 | else { | |
8008 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8009 | "0471 PCI enable MSI mode failed (%d)\n", rc); | |
8010 | return rc; | |
8011 | } | |
8012 | ||
8013 | rc = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
8014 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
8015 | if (rc) { | |
8016 | pci_disable_msi(phba->pcidev); | |
8017 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
8018 | "0478 MSI request_irq failed (%d)\n", rc); | |
8019 | } | |
8020 | return rc; | |
8021 | } | |
8022 | ||
8023 | /** | |
8024 | * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device. | |
8025 | * @phba: pointer to lpfc hba data structure. | |
8026 | * | |
8027 | * This routine is invoked to disable the MSI interrupt mode to device with | |
8028 | * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has | |
8029 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | |
8030 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | |
8031 | * its vector. | |
8032 | */ | |
8033 | static void | |
8034 | lpfc_sli_disable_msi(struct lpfc_hba *phba) | |
8035 | { | |
8036 | free_irq(phba->pcidev->irq, phba); | |
8037 | pci_disable_msi(phba->pcidev); | |
8038 | return; | |
8039 | } | |
8040 | ||
8041 | /** | |
8042 | * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device. | |
8043 | * @phba: pointer to lpfc hba data structure. | |
8044 | * | |
8045 | * This routine is invoked to enable device interrupt and associate driver's | |
8046 | * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface | |
8047 | * spec. Depends on the interrupt mode configured to the driver, the driver | |
8048 | * will try to fallback from the configured interrupt mode to an interrupt | |
8049 | * mode which is supported by the platform, kernel, and device in the order | |
8050 | * of: | |
8051 | * MSI-X -> MSI -> IRQ. | |
8052 | * | |
8053 | * Return codes | |
af901ca1 | 8054 | * 0 - successful |
da0436e9 JS |
8055 | * other values - error |
8056 | **/ | |
8057 | static uint32_t | |
8058 | lpfc_sli_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
8059 | { | |
8060 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
8061 | int retval; | |
8062 | ||
8063 | if (cfg_mode == 2) { | |
8064 | /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */ | |
8065 | retval = lpfc_sli_config_port(phba, LPFC_SLI_REV3); | |
8066 | if (!retval) { | |
8067 | /* Now, try to enable MSI-X interrupt mode */ | |
8068 | retval = lpfc_sli_enable_msix(phba); | |
8069 | if (!retval) { | |
8070 | /* Indicate initialization to MSI-X mode */ | |
8071 | phba->intr_type = MSIX; | |
8072 | intr_mode = 2; | |
8073 | } | |
8074 | } | |
8075 | } | |
8076 | ||
8077 | /* Fallback to MSI if MSI-X initialization failed */ | |
8078 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
8079 | retval = lpfc_sli_enable_msi(phba); | |
8080 | if (!retval) { | |
8081 | /* Indicate initialization to MSI mode */ | |
8082 | phba->intr_type = MSI; | |
8083 | intr_mode = 1; | |
8084 | } | |
8085 | } | |
8086 | ||
8087 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
8088 | if (phba->intr_type == NONE) { | |
8089 | retval = request_irq(phba->pcidev->irq, lpfc_sli_intr_handler, | |
8090 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
8091 | if (!retval) { | |
8092 | /* Indicate initialization to INTx mode */ | |
8093 | phba->intr_type = INTx; | |
8094 | intr_mode = 0; | |
8095 | } | |
8096 | } | |
8097 | return intr_mode; | |
8098 | } | |
8099 | ||
8100 | /** | |
8101 | * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device. | |
8102 | * @phba: pointer to lpfc hba data structure. | |
8103 | * | |
8104 | * This routine is invoked to disable device interrupt and disassociate the | |
8105 | * driver's interrupt handler(s) from interrupt vector(s) to device with | |
8106 | * SLI-3 interface spec. Depending on the interrupt mode, the driver will | |
8107 | * release the interrupt vector(s) for the message signaled interrupt. | |
8108 | **/ | |
8109 | static void | |
8110 | lpfc_sli_disable_intr(struct lpfc_hba *phba) | |
8111 | { | |
8112 | /* Disable the currently initialized interrupt mode */ | |
8113 | if (phba->intr_type == MSIX) | |
8114 | lpfc_sli_disable_msix(phba); | |
8115 | else if (phba->intr_type == MSI) | |
8116 | lpfc_sli_disable_msi(phba); | |
8117 | else if (phba->intr_type == INTx) | |
8118 | free_irq(phba->pcidev->irq, phba); | |
8119 | ||
8120 | /* Reset interrupt management states */ | |
8121 | phba->intr_type = NONE; | |
8122 | phba->sli.slistat.sli_intr = 0; | |
8123 | ||
8124 | return; | |
8125 | } | |
8126 | ||
8127 | /** | |
8128 | * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device | |
8129 | * @phba: pointer to lpfc hba data structure. | |
8130 | * | |
8131 | * This routine is invoked to enable the MSI-X interrupt vectors to device | |
8132 | * with SLI-4 interface spec. The kernel function pci_enable_msix() is called | |
8133 | * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked, | |
8134 | * enables either all or nothing, depending on the current availability of | |
8135 | * PCI vector resources. The device driver is responsible for calling the | |
8136 | * individual request_irq() to register each MSI-X vector with a interrupt | |
8137 | * handler, which is done in this function. Note that later when device is | |
8138 | * unloading, the driver should always call free_irq() on all MSI-X vectors | |
8139 | * it has done request_irq() on before calling pci_disable_msix(). Failure | |
8140 | * to do so results in a BUG_ON() and a device will be left with MSI-X | |
8141 | * enabled and leaks its vectors. | |
8142 | * | |
8143 | * Return codes | |
af901ca1 | 8144 | * 0 - successful |
da0436e9 JS |
8145 | * other values - error |
8146 | **/ | |
8147 | static int | |
8148 | lpfc_sli4_enable_msix(struct lpfc_hba *phba) | |
8149 | { | |
75baf696 | 8150 | int vectors, rc, index; |
da0436e9 JS |
8151 | |
8152 | /* Set up MSI-X multi-message vectors */ | |
8153 | for (index = 0; index < phba->sli4_hba.cfg_eqn; index++) | |
8154 | phba->sli4_hba.msix_entries[index].entry = index; | |
8155 | ||
8156 | /* Configure MSI-X capability structure */ | |
75baf696 JS |
8157 | vectors = phba->sli4_hba.cfg_eqn; |
8158 | enable_msix_vectors: | |
da0436e9 | 8159 | rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries, |
75baf696 JS |
8160 | vectors); |
8161 | if (rc > 1) { | |
8162 | vectors = rc; | |
8163 | goto enable_msix_vectors; | |
8164 | } else if (rc) { | |
da0436e9 JS |
8165 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
8166 | "0484 PCI enable MSI-X failed (%d)\n", rc); | |
8167 | goto msi_fail_out; | |
8168 | } | |
75baf696 | 8169 | |
da0436e9 | 8170 | /* Log MSI-X vector assignment */ |
75baf696 | 8171 | for (index = 0; index < vectors; index++) |
da0436e9 JS |
8172 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
8173 | "0489 MSI-X entry[%d]: vector=x%x " | |
8174 | "message=%d\n", index, | |
8175 | phba->sli4_hba.msix_entries[index].vector, | |
8176 | phba->sli4_hba.msix_entries[index].entry); | |
8177 | /* | |
8178 | * Assign MSI-X vectors to interrupt handlers | |
8179 | */ | |
0558056c JS |
8180 | if (vectors > 1) |
8181 | rc = request_irq(phba->sli4_hba.msix_entries[0].vector, | |
8182 | &lpfc_sli4_sp_intr_handler, IRQF_SHARED, | |
8183 | LPFC_SP_DRIVER_HANDLER_NAME, phba); | |
8184 | else | |
8185 | /* All Interrupts need to be handled by one EQ */ | |
8186 | rc = request_irq(phba->sli4_hba.msix_entries[0].vector, | |
8187 | &lpfc_sli4_intr_handler, IRQF_SHARED, | |
8188 | LPFC_DRIVER_NAME, phba); | |
da0436e9 JS |
8189 | if (rc) { |
8190 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
8191 | "0485 MSI-X slow-path request_irq failed " | |
8192 | "(%d)\n", rc); | |
8193 | goto msi_fail_out; | |
8194 | } | |
8195 | ||
8196 | /* The rest of the vector(s) are associated to fast-path handler(s) */ | |
75baf696 | 8197 | for (index = 1; index < vectors; index++) { |
da0436e9 JS |
8198 | phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1; |
8199 | phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba; | |
8200 | rc = request_irq(phba->sli4_hba.msix_entries[index].vector, | |
8201 | &lpfc_sli4_fp_intr_handler, IRQF_SHARED, | |
8202 | LPFC_FP_DRIVER_HANDLER_NAME, | |
8203 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
8204 | if (rc) { | |
8205 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
8206 | "0486 MSI-X fast-path (%d) " | |
8207 | "request_irq failed (%d)\n", index, rc); | |
8208 | goto cfg_fail_out; | |
8209 | } | |
8210 | } | |
75baf696 | 8211 | phba->sli4_hba.msix_vec_nr = vectors; |
da0436e9 JS |
8212 | |
8213 | return rc; | |
8214 | ||
8215 | cfg_fail_out: | |
8216 | /* free the irq already requested */ | |
8217 | for (--index; index >= 1; index--) | |
8218 | free_irq(phba->sli4_hba.msix_entries[index - 1].vector, | |
8219 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
8220 | ||
8221 | /* free the irq already requested */ | |
8222 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); | |
8223 | ||
8224 | msi_fail_out: | |
8225 | /* Unconfigure MSI-X capability structure */ | |
8226 | pci_disable_msix(phba->pcidev); | |
8227 | return rc; | |
8228 | } | |
8229 | ||
8230 | /** | |
8231 | * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device | |
8232 | * @phba: pointer to lpfc hba data structure. | |
8233 | * | |
8234 | * This routine is invoked to release the MSI-X vectors and then disable the | |
8235 | * MSI-X interrupt mode to device with SLI-4 interface spec. | |
8236 | **/ | |
8237 | static void | |
8238 | lpfc_sli4_disable_msix(struct lpfc_hba *phba) | |
8239 | { | |
8240 | int index; | |
8241 | ||
8242 | /* Free up MSI-X multi-message vectors */ | |
8243 | free_irq(phba->sli4_hba.msix_entries[0].vector, phba); | |
8244 | ||
75baf696 | 8245 | for (index = 1; index < phba->sli4_hba.msix_vec_nr; index++) |
da0436e9 JS |
8246 | free_irq(phba->sli4_hba.msix_entries[index].vector, |
8247 | &phba->sli4_hba.fcp_eq_hdl[index - 1]); | |
75baf696 | 8248 | |
da0436e9 JS |
8249 | /* Disable MSI-X */ |
8250 | pci_disable_msix(phba->pcidev); | |
8251 | ||
8252 | return; | |
8253 | } | |
8254 | ||
8255 | /** | |
8256 | * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device | |
8257 | * @phba: pointer to lpfc hba data structure. | |
8258 | * | |
8259 | * This routine is invoked to enable the MSI interrupt mode to device with | |
8260 | * SLI-4 interface spec. The kernel function pci_enable_msi() is called | |
8261 | * to enable the MSI vector. The device driver is responsible for calling | |
8262 | * the request_irq() to register MSI vector with a interrupt the handler, | |
8263 | * which is done in this function. | |
8264 | * | |
8265 | * Return codes | |
af901ca1 | 8266 | * 0 - successful |
da0436e9 JS |
8267 | * other values - error |
8268 | **/ | |
8269 | static int | |
8270 | lpfc_sli4_enable_msi(struct lpfc_hba *phba) | |
8271 | { | |
8272 | int rc, index; | |
8273 | ||
8274 | rc = pci_enable_msi(phba->pcidev); | |
8275 | if (!rc) | |
8276 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8277 | "0487 PCI enable MSI mode success.\n"); | |
8278 | else { | |
8279 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8280 | "0488 PCI enable MSI mode failed (%d)\n", rc); | |
8281 | return rc; | |
8282 | } | |
8283 | ||
8284 | rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
8285 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
8286 | if (rc) { | |
8287 | pci_disable_msi(phba->pcidev); | |
8288 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
8289 | "0490 MSI request_irq failed (%d)\n", rc); | |
75baf696 | 8290 | return rc; |
da0436e9 JS |
8291 | } |
8292 | ||
8293 | for (index = 0; index < phba->cfg_fcp_eq_count; index++) { | |
8294 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | |
8295 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
8296 | } | |
8297 | ||
75baf696 | 8298 | return 0; |
da0436e9 JS |
8299 | } |
8300 | ||
8301 | /** | |
8302 | * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device | |
8303 | * @phba: pointer to lpfc hba data structure. | |
8304 | * | |
8305 | * This routine is invoked to disable the MSI interrupt mode to device with | |
8306 | * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has | |
8307 | * done request_irq() on before calling pci_disable_msi(). Failure to do so | |
8308 | * results in a BUG_ON() and a device will be left with MSI enabled and leaks | |
8309 | * its vector. | |
8310 | **/ | |
8311 | static void | |
8312 | lpfc_sli4_disable_msi(struct lpfc_hba *phba) | |
8313 | { | |
8314 | free_irq(phba->pcidev->irq, phba); | |
8315 | pci_disable_msi(phba->pcidev); | |
8316 | return; | |
8317 | } | |
8318 | ||
8319 | /** | |
8320 | * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device | |
8321 | * @phba: pointer to lpfc hba data structure. | |
8322 | * | |
8323 | * This routine is invoked to enable device interrupt and associate driver's | |
8324 | * interrupt handler(s) to interrupt vector(s) to device with SLI-4 | |
8325 | * interface spec. Depends on the interrupt mode configured to the driver, | |
8326 | * the driver will try to fallback from the configured interrupt mode to an | |
8327 | * interrupt mode which is supported by the platform, kernel, and device in | |
8328 | * the order of: | |
8329 | * MSI-X -> MSI -> IRQ. | |
8330 | * | |
8331 | * Return codes | |
af901ca1 | 8332 | * 0 - successful |
da0436e9 JS |
8333 | * other values - error |
8334 | **/ | |
8335 | static uint32_t | |
8336 | lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode) | |
8337 | { | |
8338 | uint32_t intr_mode = LPFC_INTR_ERROR; | |
8339 | int retval, index; | |
8340 | ||
8341 | if (cfg_mode == 2) { | |
8342 | /* Preparation before conf_msi mbox cmd */ | |
8343 | retval = 0; | |
8344 | if (!retval) { | |
8345 | /* Now, try to enable MSI-X interrupt mode */ | |
8346 | retval = lpfc_sli4_enable_msix(phba); | |
8347 | if (!retval) { | |
8348 | /* Indicate initialization to MSI-X mode */ | |
8349 | phba->intr_type = MSIX; | |
8350 | intr_mode = 2; | |
8351 | } | |
8352 | } | |
8353 | } | |
8354 | ||
8355 | /* Fallback to MSI if MSI-X initialization failed */ | |
8356 | if (cfg_mode >= 1 && phba->intr_type == NONE) { | |
8357 | retval = lpfc_sli4_enable_msi(phba); | |
8358 | if (!retval) { | |
8359 | /* Indicate initialization to MSI mode */ | |
8360 | phba->intr_type = MSI; | |
8361 | intr_mode = 1; | |
8362 | } | |
8363 | } | |
8364 | ||
8365 | /* Fallback to INTx if both MSI-X/MSI initalization failed */ | |
8366 | if (phba->intr_type == NONE) { | |
8367 | retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler, | |
8368 | IRQF_SHARED, LPFC_DRIVER_NAME, phba); | |
8369 | if (!retval) { | |
8370 | /* Indicate initialization to INTx mode */ | |
8371 | phba->intr_type = INTx; | |
8372 | intr_mode = 0; | |
8373 | for (index = 0; index < phba->cfg_fcp_eq_count; | |
8374 | index++) { | |
8375 | phba->sli4_hba.fcp_eq_hdl[index].idx = index; | |
8376 | phba->sli4_hba.fcp_eq_hdl[index].phba = phba; | |
8377 | } | |
8378 | } | |
8379 | } | |
8380 | return intr_mode; | |
8381 | } | |
8382 | ||
8383 | /** | |
8384 | * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device | |
8385 | * @phba: pointer to lpfc hba data structure. | |
8386 | * | |
8387 | * This routine is invoked to disable device interrupt and disassociate | |
8388 | * the driver's interrupt handler(s) from interrupt vector(s) to device | |
8389 | * with SLI-4 interface spec. Depending on the interrupt mode, the driver | |
8390 | * will release the interrupt vector(s) for the message signaled interrupt. | |
8391 | **/ | |
8392 | static void | |
8393 | lpfc_sli4_disable_intr(struct lpfc_hba *phba) | |
8394 | { | |
8395 | /* Disable the currently initialized interrupt mode */ | |
8396 | if (phba->intr_type == MSIX) | |
8397 | lpfc_sli4_disable_msix(phba); | |
8398 | else if (phba->intr_type == MSI) | |
8399 | lpfc_sli4_disable_msi(phba); | |
8400 | else if (phba->intr_type == INTx) | |
8401 | free_irq(phba->pcidev->irq, phba); | |
8402 | ||
8403 | /* Reset interrupt management states */ | |
8404 | phba->intr_type = NONE; | |
8405 | phba->sli.slistat.sli_intr = 0; | |
8406 | ||
8407 | return; | |
8408 | } | |
8409 | ||
8410 | /** | |
8411 | * lpfc_unset_hba - Unset SLI3 hba device initialization | |
8412 | * @phba: pointer to lpfc hba data structure. | |
8413 | * | |
8414 | * This routine is invoked to unset the HBA device initialization steps to | |
8415 | * a device with SLI-3 interface spec. | |
8416 | **/ | |
8417 | static void | |
8418 | lpfc_unset_hba(struct lpfc_hba *phba) | |
8419 | { | |
8420 | struct lpfc_vport *vport = phba->pport; | |
8421 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
8422 | ||
8423 | spin_lock_irq(shost->host_lock); | |
8424 | vport->load_flag |= FC_UNLOADING; | |
8425 | spin_unlock_irq(shost->host_lock); | |
8426 | ||
72859909 JS |
8427 | kfree(phba->vpi_bmask); |
8428 | kfree(phba->vpi_ids); | |
8429 | ||
da0436e9 JS |
8430 | lpfc_stop_hba_timers(phba); |
8431 | ||
8432 | phba->pport->work_port_events = 0; | |
8433 | ||
8434 | lpfc_sli_hba_down(phba); | |
8435 | ||
8436 | lpfc_sli_brdrestart(phba); | |
8437 | ||
8438 | lpfc_sli_disable_intr(phba); | |
8439 | ||
8440 | return; | |
8441 | } | |
8442 | ||
8443 | /** | |
8444 | * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization. | |
8445 | * @phba: pointer to lpfc hba data structure. | |
8446 | * | |
8447 | * This routine is invoked to unset the HBA device initialization steps to | |
8448 | * a device with SLI-4 interface spec. | |
8449 | **/ | |
8450 | static void | |
8451 | lpfc_sli4_unset_hba(struct lpfc_hba *phba) | |
8452 | { | |
8453 | struct lpfc_vport *vport = phba->pport; | |
8454 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
8455 | ||
8456 | spin_lock_irq(shost->host_lock); | |
8457 | vport->load_flag |= FC_UNLOADING; | |
8458 | spin_unlock_irq(shost->host_lock); | |
8459 | ||
8460 | phba->pport->work_port_events = 0; | |
8461 | ||
3677a3a7 JS |
8462 | /* Stop the SLI4 device port */ |
8463 | lpfc_stop_port(phba); | |
da0436e9 JS |
8464 | |
8465 | lpfc_sli4_disable_intr(phba); | |
8466 | ||
3677a3a7 JS |
8467 | /* Reset SLI4 HBA FCoE function */ |
8468 | lpfc_pci_function_reset(phba); | |
5350d872 | 8469 | lpfc_sli4_queue_destroy(phba); |
3677a3a7 | 8470 | |
da0436e9 JS |
8471 | return; |
8472 | } | |
8473 | ||
5af5eee7 JS |
8474 | /** |
8475 | * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy | |
8476 | * @phba: Pointer to HBA context object. | |
8477 | * | |
8478 | * This function is called in the SLI4 code path to wait for completion | |
8479 | * of device's XRIs exchange busy. It will check the XRI exchange busy | |
8480 | * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after | |
8481 | * that, it will check the XRI exchange busy on outstanding FCP and ELS | |
8482 | * I/Os every 30 seconds, log error message, and wait forever. Only when | |
8483 | * all XRI exchange busy complete, the driver unload shall proceed with | |
8484 | * invoking the function reset ioctl mailbox command to the CNA and the | |
8485 | * the rest of the driver unload resource release. | |
8486 | **/ | |
8487 | static void | |
8488 | lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba *phba) | |
8489 | { | |
8490 | int wait_time = 0; | |
8491 | int fcp_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
8492 | int els_xri_cmpl = list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
8493 | ||
8494 | while (!fcp_xri_cmpl || !els_xri_cmpl) { | |
8495 | if (wait_time > LPFC_XRI_EXCH_BUSY_WAIT_TMO) { | |
8496 | if (!fcp_xri_cmpl) | |
8497 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8498 | "2877 FCP XRI exchange busy " | |
8499 | "wait time: %d seconds.\n", | |
8500 | wait_time/1000); | |
8501 | if (!els_xri_cmpl) | |
8502 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8503 | "2878 ELS XRI exchange busy " | |
8504 | "wait time: %d seconds.\n", | |
8505 | wait_time/1000); | |
8506 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2); | |
8507 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T2; | |
8508 | } else { | |
8509 | msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1); | |
8510 | wait_time += LPFC_XRI_EXCH_BUSY_WAIT_T1; | |
8511 | } | |
8512 | fcp_xri_cmpl = | |
8513 | list_empty(&phba->sli4_hba.lpfc_abts_scsi_buf_list); | |
8514 | els_xri_cmpl = | |
8515 | list_empty(&phba->sli4_hba.lpfc_abts_els_sgl_list); | |
8516 | } | |
8517 | } | |
8518 | ||
da0436e9 JS |
8519 | /** |
8520 | * lpfc_sli4_hba_unset - Unset the fcoe hba | |
8521 | * @phba: Pointer to HBA context object. | |
8522 | * | |
8523 | * This function is called in the SLI4 code path to reset the HBA's FCoE | |
8524 | * function. The caller is not required to hold any lock. This routine | |
8525 | * issues PCI function reset mailbox command to reset the FCoE function. | |
8526 | * At the end of the function, it calls lpfc_hba_down_post function to | |
8527 | * free any pending commands. | |
8528 | **/ | |
8529 | static void | |
8530 | lpfc_sli4_hba_unset(struct lpfc_hba *phba) | |
8531 | { | |
8532 | int wait_cnt = 0; | |
8533 | LPFC_MBOXQ_t *mboxq; | |
912e3acd | 8534 | struct pci_dev *pdev = phba->pcidev; |
da0436e9 JS |
8535 | |
8536 | lpfc_stop_hba_timers(phba); | |
8537 | phba->sli4_hba.intr_enable = 0; | |
8538 | ||
8539 | /* | |
8540 | * Gracefully wait out the potential current outstanding asynchronous | |
8541 | * mailbox command. | |
8542 | */ | |
8543 | ||
8544 | /* First, block any pending async mailbox command from posted */ | |
8545 | spin_lock_irq(&phba->hbalock); | |
8546 | phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK; | |
8547 | spin_unlock_irq(&phba->hbalock); | |
8548 | /* Now, trying to wait it out if we can */ | |
8549 | while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
8550 | msleep(10); | |
8551 | if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT) | |
8552 | break; | |
8553 | } | |
8554 | /* Forcefully release the outstanding mailbox command if timed out */ | |
8555 | if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) { | |
8556 | spin_lock_irq(&phba->hbalock); | |
8557 | mboxq = phba->sli.mbox_active; | |
8558 | mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED; | |
8559 | __lpfc_mbox_cmpl_put(phba, mboxq); | |
8560 | phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; | |
8561 | phba->sli.mbox_active = NULL; | |
8562 | spin_unlock_irq(&phba->hbalock); | |
8563 | } | |
8564 | ||
5af5eee7 JS |
8565 | /* Abort all iocbs associated with the hba */ |
8566 | lpfc_sli_hba_iocb_abort(phba); | |
8567 | ||
8568 | /* Wait for completion of device XRI exchange busy */ | |
8569 | lpfc_sli4_xri_exchange_busy_wait(phba); | |
8570 | ||
da0436e9 JS |
8571 | /* Disable PCI subsystem interrupt */ |
8572 | lpfc_sli4_disable_intr(phba); | |
8573 | ||
912e3acd JS |
8574 | /* Disable SR-IOV if enabled */ |
8575 | if (phba->cfg_sriov_nr_virtfn) | |
8576 | pci_disable_sriov(pdev); | |
8577 | ||
da0436e9 JS |
8578 | /* Stop kthread signal shall trigger work_done one more time */ |
8579 | kthread_stop(phba->worker_thread); | |
8580 | ||
3677a3a7 JS |
8581 | /* Reset SLI4 HBA FCoE function */ |
8582 | lpfc_pci_function_reset(phba); | |
5350d872 | 8583 | lpfc_sli4_queue_destroy(phba); |
3677a3a7 | 8584 | |
da0436e9 JS |
8585 | /* Stop the SLI4 device port */ |
8586 | phba->pport->work_port_events = 0; | |
8587 | } | |
8588 | ||
28baac74 JS |
8589 | /** |
8590 | * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities. | |
8591 | * @phba: Pointer to HBA context object. | |
8592 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. | |
8593 | * | |
8594 | * This function is called in the SLI4 code path to read the port's | |
8595 | * sli4 capabilities. | |
8596 | * | |
8597 | * This function may be be called from any context that can block-wait | |
8598 | * for the completion. The expectation is that this routine is called | |
8599 | * typically from probe_one or from the online routine. | |
8600 | **/ | |
8601 | int | |
8602 | lpfc_pc_sli4_params_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
8603 | { | |
8604 | int rc; | |
8605 | struct lpfc_mqe *mqe; | |
8606 | struct lpfc_pc_sli4_params *sli4_params; | |
8607 | uint32_t mbox_tmo; | |
8608 | ||
8609 | rc = 0; | |
8610 | mqe = &mboxq->u.mqe; | |
8611 | ||
8612 | /* Read the port's SLI4 Parameters port capabilities */ | |
fedd3b7b | 8613 | lpfc_pc_sli4_params(mboxq); |
28baac74 JS |
8614 | if (!phba->sli4_hba.intr_enable) |
8615 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
8616 | else { | |
a183a15f | 8617 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); |
28baac74 JS |
8618 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); |
8619 | } | |
8620 | ||
8621 | if (unlikely(rc)) | |
8622 | return 1; | |
8623 | ||
8624 | sli4_params = &phba->sli4_hba.pc_sli4_params; | |
8625 | sli4_params->if_type = bf_get(if_type, &mqe->un.sli4_params); | |
8626 | sli4_params->sli_rev = bf_get(sli_rev, &mqe->un.sli4_params); | |
8627 | sli4_params->sli_family = bf_get(sli_family, &mqe->un.sli4_params); | |
8628 | sli4_params->featurelevel_1 = bf_get(featurelevel_1, | |
8629 | &mqe->un.sli4_params); | |
8630 | sli4_params->featurelevel_2 = bf_get(featurelevel_2, | |
8631 | &mqe->un.sli4_params); | |
8632 | sli4_params->proto_types = mqe->un.sli4_params.word3; | |
8633 | sli4_params->sge_supp_len = mqe->un.sli4_params.sge_supp_len; | |
8634 | sli4_params->if_page_sz = bf_get(if_page_sz, &mqe->un.sli4_params); | |
8635 | sli4_params->rq_db_window = bf_get(rq_db_window, &mqe->un.sli4_params); | |
8636 | sli4_params->loopbk_scope = bf_get(loopbk_scope, &mqe->un.sli4_params); | |
8637 | sli4_params->eq_pages_max = bf_get(eq_pages, &mqe->un.sli4_params); | |
8638 | sli4_params->eqe_size = bf_get(eqe_size, &mqe->un.sli4_params); | |
8639 | sli4_params->cq_pages_max = bf_get(cq_pages, &mqe->un.sli4_params); | |
8640 | sli4_params->cqe_size = bf_get(cqe_size, &mqe->un.sli4_params); | |
8641 | sli4_params->mq_pages_max = bf_get(mq_pages, &mqe->un.sli4_params); | |
8642 | sli4_params->mqe_size = bf_get(mqe_size, &mqe->un.sli4_params); | |
8643 | sli4_params->mq_elem_cnt = bf_get(mq_elem_cnt, &mqe->un.sli4_params); | |
8644 | sli4_params->wq_pages_max = bf_get(wq_pages, &mqe->un.sli4_params); | |
8645 | sli4_params->wqe_size = bf_get(wqe_size, &mqe->un.sli4_params); | |
8646 | sli4_params->rq_pages_max = bf_get(rq_pages, &mqe->un.sli4_params); | |
8647 | sli4_params->rqe_size = bf_get(rqe_size, &mqe->un.sli4_params); | |
8648 | sli4_params->hdr_pages_max = bf_get(hdr_pages, &mqe->un.sli4_params); | |
8649 | sli4_params->hdr_size = bf_get(hdr_size, &mqe->un.sli4_params); | |
8650 | sli4_params->hdr_pp_align = bf_get(hdr_pp_align, &mqe->un.sli4_params); | |
8651 | sli4_params->sgl_pages_max = bf_get(sgl_pages, &mqe->un.sli4_params); | |
8652 | sli4_params->sgl_pp_align = bf_get(sgl_pp_align, &mqe->un.sli4_params); | |
0558056c JS |
8653 | |
8654 | /* Make sure that sge_supp_len can be handled by the driver */ | |
8655 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) | |
8656 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; | |
8657 | ||
28baac74 JS |
8658 | return rc; |
8659 | } | |
8660 | ||
fedd3b7b JS |
8661 | /** |
8662 | * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS. | |
8663 | * @phba: Pointer to HBA context object. | |
8664 | * @mboxq: Pointer to the mailboxq memory for the mailbox command response. | |
8665 | * | |
8666 | * This function is called in the SLI4 code path to read the port's | |
8667 | * sli4 capabilities. | |
8668 | * | |
8669 | * This function may be be called from any context that can block-wait | |
8670 | * for the completion. The expectation is that this routine is called | |
8671 | * typically from probe_one or from the online routine. | |
8672 | **/ | |
8673 | int | |
8674 | lpfc_get_sli4_parameters(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) | |
8675 | { | |
8676 | int rc; | |
8677 | struct lpfc_mqe *mqe = &mboxq->u.mqe; | |
8678 | struct lpfc_pc_sli4_params *sli4_params; | |
a183a15f | 8679 | uint32_t mbox_tmo; |
fedd3b7b JS |
8680 | int length; |
8681 | struct lpfc_sli4_parameters *mbx_sli4_parameters; | |
8682 | ||
6d368e53 JS |
8683 | /* |
8684 | * By default, the driver assumes the SLI4 port requires RPI | |
8685 | * header postings. The SLI4_PARAM response will correct this | |
8686 | * assumption. | |
8687 | */ | |
8688 | phba->sli4_hba.rpi_hdrs_in_use = 1; | |
8689 | ||
fedd3b7b JS |
8690 | /* Read the port's SLI4 Config Parameters */ |
8691 | length = (sizeof(struct lpfc_mbx_get_sli4_parameters) - | |
8692 | sizeof(struct lpfc_sli4_cfg_mhdr)); | |
8693 | lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON, | |
8694 | LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS, | |
8695 | length, LPFC_SLI4_MBX_EMBED); | |
8696 | if (!phba->sli4_hba.intr_enable) | |
8697 | rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL); | |
a183a15f JS |
8698 | else { |
8699 | mbox_tmo = lpfc_mbox_tmo_val(phba, mboxq); | |
8700 | rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo); | |
8701 | } | |
fedd3b7b JS |
8702 | if (unlikely(rc)) |
8703 | return rc; | |
8704 | sli4_params = &phba->sli4_hba.pc_sli4_params; | |
8705 | mbx_sli4_parameters = &mqe->un.get_sli4_parameters.sli4_parameters; | |
8706 | sli4_params->if_type = bf_get(cfg_if_type, mbx_sli4_parameters); | |
8707 | sli4_params->sli_rev = bf_get(cfg_sli_rev, mbx_sli4_parameters); | |
8708 | sli4_params->sli_family = bf_get(cfg_sli_family, mbx_sli4_parameters); | |
8709 | sli4_params->featurelevel_1 = bf_get(cfg_sli_hint_1, | |
8710 | mbx_sli4_parameters); | |
8711 | sli4_params->featurelevel_2 = bf_get(cfg_sli_hint_2, | |
8712 | mbx_sli4_parameters); | |
8713 | if (bf_get(cfg_phwq, mbx_sli4_parameters)) | |
8714 | phba->sli3_options |= LPFC_SLI4_PHWQ_ENABLED; | |
8715 | else | |
8716 | phba->sli3_options &= ~LPFC_SLI4_PHWQ_ENABLED; | |
8717 | sli4_params->sge_supp_len = mbx_sli4_parameters->sge_supp_len; | |
8718 | sli4_params->loopbk_scope = bf_get(loopbk_scope, mbx_sli4_parameters); | |
8719 | sli4_params->cqv = bf_get(cfg_cqv, mbx_sli4_parameters); | |
8720 | sli4_params->mqv = bf_get(cfg_mqv, mbx_sli4_parameters); | |
8721 | sli4_params->wqv = bf_get(cfg_wqv, mbx_sli4_parameters); | |
8722 | sli4_params->rqv = bf_get(cfg_rqv, mbx_sli4_parameters); | |
8723 | sli4_params->sgl_pages_max = bf_get(cfg_sgl_page_cnt, | |
8724 | mbx_sli4_parameters); | |
8725 | sli4_params->sgl_pp_align = bf_get(cfg_sgl_pp_align, | |
8726 | mbx_sli4_parameters); | |
6d368e53 JS |
8727 | phba->sli4_hba.extents_in_use = bf_get(cfg_ext, mbx_sli4_parameters); |
8728 | phba->sli4_hba.rpi_hdrs_in_use = bf_get(cfg_hdrr, mbx_sli4_parameters); | |
0558056c JS |
8729 | |
8730 | /* Make sure that sge_supp_len can be handled by the driver */ | |
8731 | if (sli4_params->sge_supp_len > LPFC_MAX_SGE_SIZE) | |
8732 | sli4_params->sge_supp_len = LPFC_MAX_SGE_SIZE; | |
8733 | ||
fedd3b7b JS |
8734 | return 0; |
8735 | } | |
8736 | ||
da0436e9 JS |
8737 | /** |
8738 | * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. | |
8739 | * @pdev: pointer to PCI device | |
8740 | * @pid: pointer to PCI device identifier | |
8741 | * | |
8742 | * This routine is to be called to attach a device with SLI-3 interface spec | |
8743 | * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
8744 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific | |
8745 | * information of the device and driver to see if the driver state that it can | |
8746 | * support this kind of device. If the match is successful, the driver core | |
8747 | * invokes this routine. If this routine determines it can claim the HBA, it | |
8748 | * does all the initialization that it needs to do to handle the HBA properly. | |
8749 | * | |
8750 | * Return code | |
8751 | * 0 - driver can claim the device | |
8752 | * negative value - driver can not claim the device | |
8753 | **/ | |
8754 | static int __devinit | |
8755 | lpfc_pci_probe_one_s3(struct pci_dev *pdev, const struct pci_device_id *pid) | |
8756 | { | |
8757 | struct lpfc_hba *phba; | |
8758 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 8759 | struct Scsi_Host *shost = NULL; |
da0436e9 JS |
8760 | int error; |
8761 | uint32_t cfg_mode, intr_mode; | |
8762 | ||
8763 | /* Allocate memory for HBA structure */ | |
8764 | phba = lpfc_hba_alloc(pdev); | |
8765 | if (!phba) | |
8766 | return -ENOMEM; | |
8767 | ||
8768 | /* Perform generic PCI device enabling operation */ | |
8769 | error = lpfc_enable_pci_dev(phba); | |
079b5c91 | 8770 | if (error) |
da0436e9 | 8771 | goto out_free_phba; |
da0436e9 JS |
8772 | |
8773 | /* Set up SLI API function jump table for PCI-device group-0 HBAs */ | |
8774 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_LP); | |
8775 | if (error) | |
8776 | goto out_disable_pci_dev; | |
8777 | ||
8778 | /* Set up SLI-3 specific device PCI memory space */ | |
8779 | error = lpfc_sli_pci_mem_setup(phba); | |
8780 | if (error) { | |
8781 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8782 | "1402 Failed to set up pci memory space.\n"); | |
8783 | goto out_disable_pci_dev; | |
8784 | } | |
8785 | ||
8786 | /* Set up phase-1 common device driver resources */ | |
8787 | error = lpfc_setup_driver_resource_phase1(phba); | |
8788 | if (error) { | |
8789 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8790 | "1403 Failed to set up driver resource.\n"); | |
8791 | goto out_unset_pci_mem_s3; | |
8792 | } | |
8793 | ||
8794 | /* Set up SLI-3 specific device driver resources */ | |
8795 | error = lpfc_sli_driver_resource_setup(phba); | |
8796 | if (error) { | |
8797 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8798 | "1404 Failed to set up driver resource.\n"); | |
8799 | goto out_unset_pci_mem_s3; | |
8800 | } | |
8801 | ||
8802 | /* Initialize and populate the iocb list per host */ | |
8803 | error = lpfc_init_iocb_list(phba, LPFC_IOCB_LIST_CNT); | |
8804 | if (error) { | |
8805 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8806 | "1405 Failed to initialize iocb list.\n"); | |
8807 | goto out_unset_driver_resource_s3; | |
8808 | } | |
8809 | ||
8810 | /* Set up common device driver resources */ | |
8811 | error = lpfc_setup_driver_resource_phase2(phba); | |
8812 | if (error) { | |
8813 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8814 | "1406 Failed to set up driver resource.\n"); | |
8815 | goto out_free_iocb_list; | |
8816 | } | |
8817 | ||
079b5c91 JS |
8818 | /* Get the default values for Model Name and Description */ |
8819 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
8820 | ||
da0436e9 JS |
8821 | /* Create SCSI host to the physical port */ |
8822 | error = lpfc_create_shost(phba); | |
8823 | if (error) { | |
8824 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8825 | "1407 Failed to create scsi host.\n"); | |
8826 | goto out_unset_driver_resource; | |
8827 | } | |
8828 | ||
8829 | /* Configure sysfs attributes */ | |
8830 | vport = phba->pport; | |
8831 | error = lpfc_alloc_sysfs_attr(vport); | |
8832 | if (error) { | |
8833 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8834 | "1476 Failed to allocate sysfs attr\n"); | |
8835 | goto out_destroy_shost; | |
8836 | } | |
8837 | ||
6669f9bb | 8838 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
da0436e9 JS |
8839 | /* Now, trying to enable interrupt and bring up the device */ |
8840 | cfg_mode = phba->cfg_use_msi; | |
8841 | while (true) { | |
8842 | /* Put device to a known state before enabling interrupt */ | |
8843 | lpfc_stop_port(phba); | |
8844 | /* Configure and enable interrupt */ | |
8845 | intr_mode = lpfc_sli_enable_intr(phba, cfg_mode); | |
8846 | if (intr_mode == LPFC_INTR_ERROR) { | |
8847 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8848 | "0431 Failed to enable interrupt.\n"); | |
8849 | error = -ENODEV; | |
8850 | goto out_free_sysfs_attr; | |
8851 | } | |
8852 | /* SLI-3 HBA setup */ | |
8853 | if (lpfc_sli_hba_setup(phba)) { | |
8854 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
8855 | "1477 Failed to set up hba\n"); | |
8856 | error = -ENODEV; | |
8857 | goto out_remove_device; | |
8858 | } | |
8859 | ||
8860 | /* Wait 50ms for the interrupts of previous mailbox commands */ | |
8861 | msleep(50); | |
8862 | /* Check active interrupts on message signaled interrupts */ | |
8863 | if (intr_mode == 0 || | |
8864 | phba->sli.slistat.sli_intr > LPFC_MSIX_VECTORS) { | |
8865 | /* Log the current active interrupt mode */ | |
8866 | phba->intr_mode = intr_mode; | |
8867 | lpfc_log_intr_mode(phba, intr_mode); | |
8868 | break; | |
8869 | } else { | |
8870 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
8871 | "0447 Configure interrupt mode (%d) " | |
8872 | "failed active interrupt test.\n", | |
8873 | intr_mode); | |
8874 | /* Disable the current interrupt mode */ | |
8875 | lpfc_sli_disable_intr(phba); | |
8876 | /* Try next level of interrupt mode */ | |
8877 | cfg_mode = --intr_mode; | |
8878 | } | |
8879 | } | |
8880 | ||
8881 | /* Perform post initialization setup */ | |
8882 | lpfc_post_init_setup(phba); | |
8883 | ||
8884 | /* Check if there are static vports to be created. */ | |
8885 | lpfc_create_static_vport(phba); | |
8886 | ||
8887 | return 0; | |
8888 | ||
8889 | out_remove_device: | |
8890 | lpfc_unset_hba(phba); | |
8891 | out_free_sysfs_attr: | |
8892 | lpfc_free_sysfs_attr(vport); | |
8893 | out_destroy_shost: | |
8894 | lpfc_destroy_shost(phba); | |
8895 | out_unset_driver_resource: | |
8896 | lpfc_unset_driver_resource_phase2(phba); | |
8897 | out_free_iocb_list: | |
8898 | lpfc_free_iocb_list(phba); | |
8899 | out_unset_driver_resource_s3: | |
8900 | lpfc_sli_driver_resource_unset(phba); | |
8901 | out_unset_pci_mem_s3: | |
8902 | lpfc_sli_pci_mem_unset(phba); | |
8903 | out_disable_pci_dev: | |
8904 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
8905 | if (shost) |
8906 | scsi_host_put(shost); | |
da0436e9 JS |
8907 | out_free_phba: |
8908 | lpfc_hba_free(phba); | |
8909 | return error; | |
8910 | } | |
8911 | ||
8912 | /** | |
8913 | * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem. | |
8914 | * @pdev: pointer to PCI device | |
8915 | * | |
8916 | * This routine is to be called to disattach a device with SLI-3 interface | |
8917 | * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is | |
8918 | * removed from PCI bus, it performs all the necessary cleanup for the HBA | |
8919 | * device to be removed from the PCI subsystem properly. | |
8920 | **/ | |
8921 | static void __devexit | |
8922 | lpfc_pci_remove_one_s3(struct pci_dev *pdev) | |
8923 | { | |
8924 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
8925 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
8926 | struct lpfc_vport **vports; | |
8927 | struct lpfc_hba *phba = vport->phba; | |
8928 | int i; | |
8929 | int bars = pci_select_bars(pdev, IORESOURCE_MEM); | |
8930 | ||
8931 | spin_lock_irq(&phba->hbalock); | |
8932 | vport->load_flag |= FC_UNLOADING; | |
8933 | spin_unlock_irq(&phba->hbalock); | |
8934 | ||
8935 | lpfc_free_sysfs_attr(vport); | |
8936 | ||
8937 | /* Release all the vports against this physical port */ | |
8938 | vports = lpfc_create_vport_work_array(phba); | |
8939 | if (vports != NULL) | |
587a37f6 JS |
8940 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
8941 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) | |
8942 | continue; | |
da0436e9 | 8943 | fc_vport_terminate(vports[i]->fc_vport); |
587a37f6 | 8944 | } |
da0436e9 JS |
8945 | lpfc_destroy_vport_work_array(phba, vports); |
8946 | ||
8947 | /* Remove FC host and then SCSI host with the physical port */ | |
8948 | fc_remove_host(shost); | |
8949 | scsi_remove_host(shost); | |
8950 | lpfc_cleanup(vport); | |
8951 | ||
8952 | /* | |
8953 | * Bring down the SLI Layer. This step disable all interrupts, | |
8954 | * clears the rings, discards all mailbox commands, and resets | |
8955 | * the HBA. | |
8956 | */ | |
8957 | ||
48e34d0f | 8958 | /* HBA interrupt will be disabled after this call */ |
da0436e9 JS |
8959 | lpfc_sli_hba_down(phba); |
8960 | /* Stop kthread signal shall trigger work_done one more time */ | |
8961 | kthread_stop(phba->worker_thread); | |
8962 | /* Final cleanup of txcmplq and reset the HBA */ | |
8963 | lpfc_sli_brdrestart(phba); | |
8964 | ||
72859909 JS |
8965 | kfree(phba->vpi_bmask); |
8966 | kfree(phba->vpi_ids); | |
8967 | ||
da0436e9 JS |
8968 | lpfc_stop_hba_timers(phba); |
8969 | spin_lock_irq(&phba->hbalock); | |
8970 | list_del_init(&vport->listentry); | |
8971 | spin_unlock_irq(&phba->hbalock); | |
8972 | ||
8973 | lpfc_debugfs_terminate(vport); | |
8974 | ||
912e3acd JS |
8975 | /* Disable SR-IOV if enabled */ |
8976 | if (phba->cfg_sriov_nr_virtfn) | |
8977 | pci_disable_sriov(pdev); | |
8978 | ||
da0436e9 JS |
8979 | /* Disable interrupt */ |
8980 | lpfc_sli_disable_intr(phba); | |
8981 | ||
8982 | pci_set_drvdata(pdev, NULL); | |
8983 | scsi_host_put(shost); | |
8984 | ||
8985 | /* | |
8986 | * Call scsi_free before mem_free since scsi bufs are released to their | |
8987 | * corresponding pools here. | |
8988 | */ | |
8989 | lpfc_scsi_free(phba); | |
8990 | lpfc_mem_free_all(phba); | |
8991 | ||
8992 | dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), | |
8993 | phba->hbqslimp.virt, phba->hbqslimp.phys); | |
8994 | ||
8995 | /* Free resources associated with SLI2 interface */ | |
8996 | dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, | |
8997 | phba->slim2p.virt, phba->slim2p.phys); | |
8998 | ||
8999 | /* unmap adapter SLIM and Control Registers */ | |
9000 | iounmap(phba->ctrl_regs_memmap_p); | |
9001 | iounmap(phba->slim_memmap_p); | |
9002 | ||
9003 | lpfc_hba_free(phba); | |
9004 | ||
9005 | pci_release_selected_regions(pdev, bars); | |
9006 | pci_disable_device(pdev); | |
9007 | } | |
9008 | ||
9009 | /** | |
9010 | * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt | |
9011 | * @pdev: pointer to PCI device | |
9012 | * @msg: power management message | |
9013 | * | |
9014 | * This routine is to be called from the kernel's PCI subsystem to support | |
9015 | * system Power Management (PM) to device with SLI-3 interface spec. When | |
9016 | * PM invokes this method, it quiesces the device by stopping the driver's | |
9017 | * worker thread for the device, turning off device's interrupt and DMA, | |
9018 | * and bring the device offline. Note that as the driver implements the | |
9019 | * minimum PM requirements to a power-aware driver's PM support for the | |
9020 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
9021 | * to the suspend() method call will be treated as SUSPEND and the driver will | |
9022 | * fully reinitialize its device during resume() method call, the driver will | |
9023 | * set device to PCI_D3hot state in PCI config space instead of setting it | |
9024 | * according to the @msg provided by the PM. | |
9025 | * | |
9026 | * Return code | |
9027 | * 0 - driver suspended the device | |
9028 | * Error otherwise | |
9029 | **/ | |
9030 | static int | |
9031 | lpfc_pci_suspend_one_s3(struct pci_dev *pdev, pm_message_t msg) | |
9032 | { | |
9033 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9034 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9035 | ||
9036 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
9037 | "0473 PCI device Power Management suspend.\n"); | |
9038 | ||
9039 | /* Bring down the device */ | |
618a5230 | 9040 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
da0436e9 JS |
9041 | lpfc_offline(phba); |
9042 | kthread_stop(phba->worker_thread); | |
9043 | ||
9044 | /* Disable interrupt from device */ | |
9045 | lpfc_sli_disable_intr(phba); | |
9046 | ||
9047 | /* Save device state to PCI config space */ | |
9048 | pci_save_state(pdev); | |
9049 | pci_set_power_state(pdev, PCI_D3hot); | |
9050 | ||
9051 | return 0; | |
9052 | } | |
9053 | ||
9054 | /** | |
9055 | * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt | |
9056 | * @pdev: pointer to PCI device | |
9057 | * | |
9058 | * This routine is to be called from the kernel's PCI subsystem to support | |
9059 | * system Power Management (PM) to device with SLI-3 interface spec. When PM | |
9060 | * invokes this method, it restores the device's PCI config space state and | |
9061 | * fully reinitializes the device and brings it online. Note that as the | |
9062 | * driver implements the minimum PM requirements to a power-aware driver's | |
9063 | * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, | |
9064 | * FREEZE) to the suspend() method call will be treated as SUSPEND and the | |
9065 | * driver will fully reinitialize its device during resume() method call, | |
9066 | * the device will be set to PCI_D0 directly in PCI config space before | |
9067 | * restoring the state. | |
9068 | * | |
9069 | * Return code | |
9070 | * 0 - driver suspended the device | |
9071 | * Error otherwise | |
9072 | **/ | |
9073 | static int | |
9074 | lpfc_pci_resume_one_s3(struct pci_dev *pdev) | |
9075 | { | |
9076 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9077 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9078 | uint32_t intr_mode; | |
9079 | int error; | |
9080 | ||
9081 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
9082 | "0452 PCI device Power Management resume.\n"); | |
9083 | ||
9084 | /* Restore device state from PCI config space */ | |
9085 | pci_set_power_state(pdev, PCI_D0); | |
9086 | pci_restore_state(pdev); | |
0d878419 | 9087 | |
1dfb5a47 JS |
9088 | /* |
9089 | * As the new kernel behavior of pci_restore_state() API call clears | |
9090 | * device saved_state flag, need to save the restored state again. | |
9091 | */ | |
9092 | pci_save_state(pdev); | |
9093 | ||
da0436e9 JS |
9094 | if (pdev->is_busmaster) |
9095 | pci_set_master(pdev); | |
9096 | ||
9097 | /* Startup the kernel thread for this host adapter. */ | |
9098 | phba->worker_thread = kthread_run(lpfc_do_work, phba, | |
9099 | "lpfc_worker_%d", phba->brd_no); | |
9100 | if (IS_ERR(phba->worker_thread)) { | |
9101 | error = PTR_ERR(phba->worker_thread); | |
9102 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9103 | "0434 PM resume failed to start worker " | |
9104 | "thread: error=x%x.\n", error); | |
9105 | return error; | |
9106 | } | |
9107 | ||
9108 | /* Configure and enable interrupt */ | |
9109 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
9110 | if (intr_mode == LPFC_INTR_ERROR) { | |
9111 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9112 | "0430 PM resume Failed to enable interrupt\n"); | |
9113 | return -EIO; | |
9114 | } else | |
9115 | phba->intr_mode = intr_mode; | |
9116 | ||
9117 | /* Restart HBA and bring it online */ | |
9118 | lpfc_sli_brdrestart(phba); | |
9119 | lpfc_online(phba); | |
9120 | ||
9121 | /* Log the current active interrupt mode */ | |
9122 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
9123 | ||
9124 | return 0; | |
9125 | } | |
9126 | ||
891478a2 JS |
9127 | /** |
9128 | * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover | |
9129 | * @phba: pointer to lpfc hba data structure. | |
9130 | * | |
9131 | * This routine is called to prepare the SLI3 device for PCI slot recover. It | |
e2af0d2e | 9132 | * aborts all the outstanding SCSI I/Os to the pci device. |
891478a2 JS |
9133 | **/ |
9134 | static void | |
9135 | lpfc_sli_prep_dev_for_recover(struct lpfc_hba *phba) | |
9136 | { | |
e2af0d2e JS |
9137 | struct lpfc_sli *psli = &phba->sli; |
9138 | struct lpfc_sli_ring *pring; | |
9139 | ||
891478a2 JS |
9140 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
9141 | "2723 PCI channel I/O abort preparing for recovery\n"); | |
e2af0d2e JS |
9142 | |
9143 | /* | |
9144 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
9145 | * and let the SCSI mid-layer to retry them to recover. | |
9146 | */ | |
9147 | pring = &psli->ring[psli->fcp_ring]; | |
9148 | lpfc_sli_abort_iocb_ring(phba, pring); | |
891478a2 JS |
9149 | } |
9150 | ||
0d878419 JS |
9151 | /** |
9152 | * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset | |
9153 | * @phba: pointer to lpfc hba data structure. | |
9154 | * | |
9155 | * This routine is called to prepare the SLI3 device for PCI slot reset. It | |
9156 | * disables the device interrupt and pci device, and aborts the internal FCP | |
9157 | * pending I/Os. | |
9158 | **/ | |
9159 | static void | |
9160 | lpfc_sli_prep_dev_for_reset(struct lpfc_hba *phba) | |
9161 | { | |
0d878419 | 9162 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
891478a2 | 9163 | "2710 PCI channel disable preparing for reset\n"); |
e2af0d2e | 9164 | |
75baf696 | 9165 | /* Block any management I/Os to the device */ |
618a5230 | 9166 | lpfc_block_mgmt_io(phba, LPFC_MBX_WAIT); |
75baf696 | 9167 | |
e2af0d2e JS |
9168 | /* Block all SCSI devices' I/Os on the host */ |
9169 | lpfc_scsi_dev_block(phba); | |
9170 | ||
9171 | /* stop all timers */ | |
9172 | lpfc_stop_hba_timers(phba); | |
9173 | ||
0d878419 JS |
9174 | /* Disable interrupt and pci device */ |
9175 | lpfc_sli_disable_intr(phba); | |
9176 | pci_disable_device(phba->pcidev); | |
75baf696 | 9177 | |
e2af0d2e JS |
9178 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ |
9179 | lpfc_sli_flush_fcp_rings(phba); | |
0d878419 JS |
9180 | } |
9181 | ||
9182 | /** | |
9183 | * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable | |
9184 | * @phba: pointer to lpfc hba data structure. | |
9185 | * | |
9186 | * This routine is called to prepare the SLI3 device for PCI slot permanently | |
9187 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
9188 | * pending I/Os. | |
9189 | **/ | |
9190 | static void | |
75baf696 | 9191 | lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba *phba) |
0d878419 JS |
9192 | { |
9193 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
891478a2 | 9194 | "2711 PCI channel permanent disable for failure\n"); |
e2af0d2e JS |
9195 | /* Block all SCSI devices' I/Os on the host */ |
9196 | lpfc_scsi_dev_block(phba); | |
9197 | ||
9198 | /* stop all timers */ | |
9199 | lpfc_stop_hba_timers(phba); | |
9200 | ||
0d878419 JS |
9201 | /* Clean up all driver's outstanding SCSI I/Os */ |
9202 | lpfc_sli_flush_fcp_rings(phba); | |
9203 | } | |
9204 | ||
da0436e9 JS |
9205 | /** |
9206 | * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error | |
9207 | * @pdev: pointer to PCI device. | |
9208 | * @state: the current PCI connection state. | |
9209 | * | |
9210 | * This routine is called from the PCI subsystem for I/O error handling to | |
9211 | * device with SLI-3 interface spec. This function is called by the PCI | |
9212 | * subsystem after a PCI bus error affecting this device has been detected. | |
9213 | * When this function is invoked, it will need to stop all the I/Os and | |
9214 | * interrupt(s) to the device. Once that is done, it will return | |
9215 | * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery | |
9216 | * as desired. | |
9217 | * | |
9218 | * Return codes | |
0d878419 | 9219 | * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link |
da0436e9 JS |
9220 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
9221 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
9222 | **/ | |
9223 | static pci_ers_result_t | |
9224 | lpfc_io_error_detected_s3(struct pci_dev *pdev, pci_channel_state_t state) | |
9225 | { | |
9226 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9227 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
da0436e9 | 9228 | |
0d878419 JS |
9229 | switch (state) { |
9230 | case pci_channel_io_normal: | |
891478a2 JS |
9231 | /* Non-fatal error, prepare for recovery */ |
9232 | lpfc_sli_prep_dev_for_recover(phba); | |
0d878419 JS |
9233 | return PCI_ERS_RESULT_CAN_RECOVER; |
9234 | case pci_channel_io_frozen: | |
9235 | /* Fatal error, prepare for slot reset */ | |
9236 | lpfc_sli_prep_dev_for_reset(phba); | |
9237 | return PCI_ERS_RESULT_NEED_RESET; | |
9238 | case pci_channel_io_perm_failure: | |
9239 | /* Permanent failure, prepare for device down */ | |
75baf696 | 9240 | lpfc_sli_prep_dev_for_perm_failure(phba); |
da0436e9 | 9241 | return PCI_ERS_RESULT_DISCONNECT; |
0d878419 JS |
9242 | default: |
9243 | /* Unknown state, prepare and request slot reset */ | |
9244 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9245 | "0472 Unknown PCI error state: x%x\n", state); | |
9246 | lpfc_sli_prep_dev_for_reset(phba); | |
9247 | return PCI_ERS_RESULT_NEED_RESET; | |
da0436e9 | 9248 | } |
da0436e9 JS |
9249 | } |
9250 | ||
9251 | /** | |
9252 | * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch. | |
9253 | * @pdev: pointer to PCI device. | |
9254 | * | |
9255 | * This routine is called from the PCI subsystem for error handling to | |
9256 | * device with SLI-3 interface spec. This is called after PCI bus has been | |
9257 | * reset to restart the PCI card from scratch, as if from a cold-boot. | |
9258 | * During the PCI subsystem error recovery, after driver returns | |
9259 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error | |
9260 | * recovery and then call this routine before calling the .resume method | |
9261 | * to recover the device. This function will initialize the HBA device, | |
9262 | * enable the interrupt, but it will just put the HBA to offline state | |
9263 | * without passing any I/O traffic. | |
9264 | * | |
9265 | * Return codes | |
9266 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
9267 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
9268 | */ | |
9269 | static pci_ers_result_t | |
9270 | lpfc_io_slot_reset_s3(struct pci_dev *pdev) | |
9271 | { | |
9272 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9273 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9274 | struct lpfc_sli *psli = &phba->sli; | |
9275 | uint32_t intr_mode; | |
9276 | ||
9277 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
9278 | if (pci_enable_device_mem(pdev)) { | |
9279 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
9280 | "PCI device after reset.\n"); | |
9281 | return PCI_ERS_RESULT_DISCONNECT; | |
9282 | } | |
9283 | ||
9284 | pci_restore_state(pdev); | |
1dfb5a47 JS |
9285 | |
9286 | /* | |
9287 | * As the new kernel behavior of pci_restore_state() API call clears | |
9288 | * device saved_state flag, need to save the restored state again. | |
9289 | */ | |
9290 | pci_save_state(pdev); | |
9291 | ||
da0436e9 JS |
9292 | if (pdev->is_busmaster) |
9293 | pci_set_master(pdev); | |
9294 | ||
9295 | spin_lock_irq(&phba->hbalock); | |
9296 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
9297 | spin_unlock_irq(&phba->hbalock); | |
9298 | ||
9299 | /* Configure and enable interrupt */ | |
9300 | intr_mode = lpfc_sli_enable_intr(phba, phba->intr_mode); | |
9301 | if (intr_mode == LPFC_INTR_ERROR) { | |
9302 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9303 | "0427 Cannot re-enable interrupt after " | |
9304 | "slot reset.\n"); | |
9305 | return PCI_ERS_RESULT_DISCONNECT; | |
9306 | } else | |
9307 | phba->intr_mode = intr_mode; | |
9308 | ||
75baf696 | 9309 | /* Take device offline, it will perform cleanup */ |
618a5230 | 9310 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
da0436e9 JS |
9311 | lpfc_offline(phba); |
9312 | lpfc_sli_brdrestart(phba); | |
9313 | ||
9314 | /* Log the current active interrupt mode */ | |
9315 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
9316 | ||
9317 | return PCI_ERS_RESULT_RECOVERED; | |
9318 | } | |
9319 | ||
9320 | /** | |
9321 | * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device. | |
9322 | * @pdev: pointer to PCI device | |
9323 | * | |
9324 | * This routine is called from the PCI subsystem for error handling to device | |
9325 | * with SLI-3 interface spec. It is called when kernel error recovery tells | |
9326 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus | |
9327 | * error recovery. After this call, traffic can start to flow from this device | |
9328 | * again. | |
9329 | */ | |
9330 | static void | |
9331 | lpfc_io_resume_s3(struct pci_dev *pdev) | |
9332 | { | |
9333 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9334 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
3772a991 | 9335 | |
e2af0d2e | 9336 | /* Bring device online, it will be no-op for non-fatal error resume */ |
da0436e9 | 9337 | lpfc_online(phba); |
0d878419 JS |
9338 | |
9339 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
9340 | if (phba->hba_flag & HBA_AER_ENABLED) | |
9341 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
da0436e9 | 9342 | } |
3772a991 | 9343 | |
da0436e9 JS |
9344 | /** |
9345 | * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve | |
9346 | * @phba: pointer to lpfc hba data structure. | |
9347 | * | |
9348 | * returns the number of ELS/CT IOCBs to reserve | |
9349 | **/ | |
9350 | int | |
9351 | lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba) | |
9352 | { | |
9353 | int max_xri = phba->sli4_hba.max_cfg_param.max_xri; | |
9354 | ||
f1126688 JS |
9355 | if (phba->sli_rev == LPFC_SLI_REV4) { |
9356 | if (max_xri <= 100) | |
6a9c52cf | 9357 | return 10; |
f1126688 | 9358 | else if (max_xri <= 256) |
6a9c52cf | 9359 | return 25; |
f1126688 | 9360 | else if (max_xri <= 512) |
6a9c52cf | 9361 | return 50; |
f1126688 | 9362 | else if (max_xri <= 1024) |
6a9c52cf | 9363 | return 100; |
8a9d2e80 | 9364 | else if (max_xri <= 1536) |
6a9c52cf | 9365 | return 150; |
8a9d2e80 JS |
9366 | else if (max_xri <= 2048) |
9367 | return 200; | |
9368 | else | |
9369 | return 250; | |
f1126688 JS |
9370 | } else |
9371 | return 0; | |
3772a991 JS |
9372 | } |
9373 | ||
52d52440 JS |
9374 | /** |
9375 | * lpfc_write_firmware - attempt to write a firmware image to the port | |
9376 | * @phba: pointer to lpfc hba data structure. | |
9377 | * @fw: pointer to firmware image returned from request_firmware. | |
9378 | * | |
9379 | * returns the number of bytes written if write is successful. | |
9380 | * returns a negative error value if there were errors. | |
9381 | * returns 0 if firmware matches currently active firmware on port. | |
9382 | **/ | |
9383 | int | |
9384 | lpfc_write_firmware(struct lpfc_hba *phba, const struct firmware *fw) | |
9385 | { | |
6b5151fd | 9386 | char fwrev[FW_REV_STR_SIZE]; |
52d52440 JS |
9387 | struct lpfc_grp_hdr *image = (struct lpfc_grp_hdr *)fw->data; |
9388 | struct list_head dma_buffer_list; | |
9389 | int i, rc = 0; | |
9390 | struct lpfc_dmabuf *dmabuf, *next; | |
9391 | uint32_t offset = 0, temp_offset = 0; | |
9392 | ||
9393 | INIT_LIST_HEAD(&dma_buffer_list); | |
079b5c91 JS |
9394 | if ((be32_to_cpu(image->magic_number) != LPFC_GROUP_OJECT_MAGIC_NUM) || |
9395 | (bf_get_be32(lpfc_grp_hdr_file_type, image) != | |
9396 | LPFC_FILE_TYPE_GROUP) || | |
9397 | (bf_get_be32(lpfc_grp_hdr_id, image) != LPFC_FILE_ID_GROUP) || | |
9398 | (be32_to_cpu(image->size) != fw->size)) { | |
52d52440 JS |
9399 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
9400 | "3022 Invalid FW image found. " | |
079b5c91 JS |
9401 | "Magic:%x Type:%x ID:%x\n", |
9402 | be32_to_cpu(image->magic_number), | |
9403 | bf_get_be32(lpfc_grp_hdr_file_type, image), | |
9404 | bf_get_be32(lpfc_grp_hdr_id, image)); | |
52d52440 JS |
9405 | return -EINVAL; |
9406 | } | |
9407 | lpfc_decode_firmware_rev(phba, fwrev, 1); | |
88a2cfbb | 9408 | if (strncmp(fwrev, image->revision, strnlen(image->revision, 16))) { |
52d52440 JS |
9409 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
9410 | "3023 Updating Firmware. Current Version:%s " | |
9411 | "New Version:%s\n", | |
88a2cfbb | 9412 | fwrev, image->revision); |
52d52440 JS |
9413 | for (i = 0; i < LPFC_MBX_WR_CONFIG_MAX_BDE; i++) { |
9414 | dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), | |
9415 | GFP_KERNEL); | |
9416 | if (!dmabuf) { | |
9417 | rc = -ENOMEM; | |
9418 | goto out; | |
9419 | } | |
9420 | dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev, | |
9421 | SLI4_PAGE_SIZE, | |
9422 | &dmabuf->phys, | |
9423 | GFP_KERNEL); | |
9424 | if (!dmabuf->virt) { | |
9425 | kfree(dmabuf); | |
9426 | rc = -ENOMEM; | |
9427 | goto out; | |
9428 | } | |
9429 | list_add_tail(&dmabuf->list, &dma_buffer_list); | |
9430 | } | |
9431 | while (offset < fw->size) { | |
9432 | temp_offset = offset; | |
9433 | list_for_each_entry(dmabuf, &dma_buffer_list, list) { | |
079b5c91 | 9434 | if (temp_offset + SLI4_PAGE_SIZE > fw->size) { |
52d52440 JS |
9435 | memcpy(dmabuf->virt, |
9436 | fw->data + temp_offset, | |
079b5c91 JS |
9437 | fw->size - temp_offset); |
9438 | temp_offset = fw->size; | |
52d52440 JS |
9439 | break; |
9440 | } | |
52d52440 JS |
9441 | memcpy(dmabuf->virt, fw->data + temp_offset, |
9442 | SLI4_PAGE_SIZE); | |
88a2cfbb | 9443 | temp_offset += SLI4_PAGE_SIZE; |
52d52440 JS |
9444 | } |
9445 | rc = lpfc_wr_object(phba, &dma_buffer_list, | |
9446 | (fw->size - offset), &offset); | |
9447 | if (rc) { | |
9448 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9449 | "3024 Firmware update failed. " | |
9450 | "%d\n", rc); | |
9451 | goto out; | |
9452 | } | |
9453 | } | |
9454 | rc = offset; | |
9455 | } | |
9456 | out: | |
9457 | list_for_each_entry_safe(dmabuf, next, &dma_buffer_list, list) { | |
9458 | list_del(&dmabuf->list); | |
9459 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, | |
9460 | dmabuf->virt, dmabuf->phys); | |
9461 | kfree(dmabuf); | |
9462 | } | |
9463 | return rc; | |
9464 | } | |
9465 | ||
3772a991 | 9466 | /** |
da0436e9 | 9467 | * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys |
3772a991 JS |
9468 | * @pdev: pointer to PCI device |
9469 | * @pid: pointer to PCI device identifier | |
9470 | * | |
da0436e9 JS |
9471 | * This routine is called from the kernel's PCI subsystem to device with |
9472 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 | 9473 | * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific |
da0436e9 JS |
9474 | * information of the device and driver to see if the driver state that it |
9475 | * can support this kind of device. If the match is successful, the driver | |
9476 | * core invokes this routine. If this routine determines it can claim the HBA, | |
9477 | * it does all the initialization that it needs to do to handle the HBA | |
9478 | * properly. | |
3772a991 JS |
9479 | * |
9480 | * Return code | |
9481 | * 0 - driver can claim the device | |
9482 | * negative value - driver can not claim the device | |
9483 | **/ | |
9484 | static int __devinit | |
da0436e9 | 9485 | lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid) |
3772a991 JS |
9486 | { |
9487 | struct lpfc_hba *phba; | |
9488 | struct lpfc_vport *vport = NULL; | |
6669f9bb | 9489 | struct Scsi_Host *shost = NULL; |
3772a991 JS |
9490 | int error; |
9491 | uint32_t cfg_mode, intr_mode; | |
da0436e9 | 9492 | int mcnt; |
0558056c | 9493 | int adjusted_fcp_eq_count; |
52d52440 JS |
9494 | const struct firmware *fw; |
9495 | uint8_t file_name[16]; | |
3772a991 JS |
9496 | |
9497 | /* Allocate memory for HBA structure */ | |
9498 | phba = lpfc_hba_alloc(pdev); | |
9499 | if (!phba) | |
9500 | return -ENOMEM; | |
9501 | ||
9502 | /* Perform generic PCI device enabling operation */ | |
9503 | error = lpfc_enable_pci_dev(phba); | |
079b5c91 | 9504 | if (error) |
3772a991 | 9505 | goto out_free_phba; |
3772a991 | 9506 | |
da0436e9 JS |
9507 | /* Set up SLI API function jump table for PCI-device group-1 HBAs */ |
9508 | error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC); | |
3772a991 JS |
9509 | if (error) |
9510 | goto out_disable_pci_dev; | |
9511 | ||
da0436e9 JS |
9512 | /* Set up SLI-4 specific device PCI memory space */ |
9513 | error = lpfc_sli4_pci_mem_setup(phba); | |
3772a991 JS |
9514 | if (error) { |
9515 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9516 | "1410 Failed to set up pci memory space.\n"); |
3772a991 JS |
9517 | goto out_disable_pci_dev; |
9518 | } | |
9519 | ||
9520 | /* Set up phase-1 common device driver resources */ | |
9521 | error = lpfc_setup_driver_resource_phase1(phba); | |
9522 | if (error) { | |
9523 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
9524 | "1411 Failed to set up driver resource.\n"); |
9525 | goto out_unset_pci_mem_s4; | |
3772a991 JS |
9526 | } |
9527 | ||
da0436e9 JS |
9528 | /* Set up SLI-4 Specific device driver resources */ |
9529 | error = lpfc_sli4_driver_resource_setup(phba); | |
3772a991 JS |
9530 | if (error) { |
9531 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
9532 | "1412 Failed to set up driver resource.\n"); |
9533 | goto out_unset_pci_mem_s4; | |
3772a991 JS |
9534 | } |
9535 | ||
9536 | /* Initialize and populate the iocb list per host */ | |
2a9bf3d0 JS |
9537 | |
9538 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
9539 | "2821 initialize iocb list %d.\n", | |
9540 | phba->cfg_iocb_cnt*1024); | |
9541 | error = lpfc_init_iocb_list(phba, phba->cfg_iocb_cnt*1024); | |
9542 | ||
3772a991 JS |
9543 | if (error) { |
9544 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 JS |
9545 | "1413 Failed to initialize iocb list.\n"); |
9546 | goto out_unset_driver_resource_s4; | |
3772a991 JS |
9547 | } |
9548 | ||
19ca7609 | 9549 | INIT_LIST_HEAD(&phba->active_rrq_list); |
7d791df7 | 9550 | INIT_LIST_HEAD(&phba->fcf.fcf_pri_list); |
19ca7609 | 9551 | |
3772a991 JS |
9552 | /* Set up common device driver resources */ |
9553 | error = lpfc_setup_driver_resource_phase2(phba); | |
9554 | if (error) { | |
9555 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9556 | "1414 Failed to set up driver resource.\n"); |
3772a991 JS |
9557 | goto out_free_iocb_list; |
9558 | } | |
9559 | ||
079b5c91 JS |
9560 | /* Get the default values for Model Name and Description */ |
9561 | lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc); | |
9562 | ||
3772a991 JS |
9563 | /* Create SCSI host to the physical port */ |
9564 | error = lpfc_create_shost(phba); | |
9565 | if (error) { | |
9566 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9567 | "1415 Failed to create scsi host.\n"); |
3772a991 JS |
9568 | goto out_unset_driver_resource; |
9569 | } | |
9399627f | 9570 | |
5b75da2f | 9571 | /* Configure sysfs attributes */ |
3772a991 JS |
9572 | vport = phba->pport; |
9573 | error = lpfc_alloc_sysfs_attr(vport); | |
9574 | if (error) { | |
9399627f | 9575 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 9576 | "1416 Failed to allocate sysfs attr\n"); |
3772a991 | 9577 | goto out_destroy_shost; |
98c9ea5c | 9578 | } |
875fbdfe | 9579 | |
6669f9bb | 9580 | shost = lpfc_shost_from_vport(vport); /* save shost for error cleanup */ |
3772a991 | 9581 | /* Now, trying to enable interrupt and bring up the device */ |
5b75da2f JS |
9582 | cfg_mode = phba->cfg_use_msi; |
9583 | while (true) { | |
3772a991 JS |
9584 | /* Put device to a known state before enabling interrupt */ |
9585 | lpfc_stop_port(phba); | |
5b75da2f | 9586 | /* Configure and enable interrupt */ |
da0436e9 | 9587 | intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode); |
5b75da2f JS |
9588 | if (intr_mode == LPFC_INTR_ERROR) { |
9589 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9590 | "0426 Failed to enable interrupt.\n"); |
3772a991 | 9591 | error = -ENODEV; |
5b75da2f JS |
9592 | goto out_free_sysfs_attr; |
9593 | } | |
0558056c | 9594 | /* Default to single EQ for non-MSI-X */ |
def9c7a9 | 9595 | if (phba->intr_type != MSIX) |
0558056c JS |
9596 | adjusted_fcp_eq_count = 0; |
9597 | else if (phba->sli4_hba.msix_vec_nr < | |
9598 | phba->cfg_fcp_eq_count + 1) | |
9599 | adjusted_fcp_eq_count = phba->sli4_hba.msix_vec_nr - 1; | |
9600 | else | |
9601 | adjusted_fcp_eq_count = phba->cfg_fcp_eq_count; | |
0558056c | 9602 | phba->cfg_fcp_eq_count = adjusted_fcp_eq_count; |
da0436e9 JS |
9603 | /* Set up SLI-4 HBA */ |
9604 | if (lpfc_sli4_hba_setup(phba)) { | |
5b75da2f | 9605 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 9606 | "1421 Failed to set up hba\n"); |
5b75da2f | 9607 | error = -ENODEV; |
da0436e9 | 9608 | goto out_disable_intr; |
5b75da2f JS |
9609 | } |
9610 | ||
da0436e9 JS |
9611 | /* Send NOP mbx cmds for non-INTx mode active interrupt test */ |
9612 | if (intr_mode != 0) | |
9613 | mcnt = lpfc_sli4_send_nop_mbox_cmds(phba, | |
9614 | LPFC_ACT_INTR_CNT); | |
9615 | ||
9616 | /* Check active interrupts received only for MSI/MSI-X */ | |
3772a991 | 9617 | if (intr_mode == 0 || |
da0436e9 | 9618 | phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) { |
5b75da2f JS |
9619 | /* Log the current active interrupt mode */ |
9620 | phba->intr_mode = intr_mode; | |
9621 | lpfc_log_intr_mode(phba, intr_mode); | |
9622 | break; | |
5b75da2f | 9623 | } |
da0436e9 JS |
9624 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
9625 | "0451 Configure interrupt mode (%d) " | |
9626 | "failed active interrupt test.\n", | |
9627 | intr_mode); | |
2fcee4bf JS |
9628 | /* Unset the previous SLI-4 HBA setup. */ |
9629 | /* | |
9630 | * TODO: Is this operation compatible with IF TYPE 2 | |
9631 | * devices? All port state is deleted and cleared. | |
9632 | */ | |
da0436e9 JS |
9633 | lpfc_sli4_unset_hba(phba); |
9634 | /* Try next level of interrupt mode */ | |
9635 | cfg_mode = --intr_mode; | |
98c9ea5c | 9636 | } |
858c9f6c | 9637 | |
3772a991 JS |
9638 | /* Perform post initialization setup */ |
9639 | lpfc_post_init_setup(phba); | |
dea3101e | 9640 | |
026abb87 JS |
9641 | /* check for firmware upgrade or downgrade (if_type 2 only) */ |
9642 | if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) == | |
9643 | LPFC_SLI_INTF_IF_TYPE_2) { | |
9644 | snprintf(file_name, 16, "%s.grp", phba->ModelName); | |
9645 | error = request_firmware(&fw, file_name, &phba->pcidev->dev); | |
9646 | if (!error) { | |
9647 | lpfc_write_firmware(phba, fw); | |
9648 | release_firmware(fw); | |
9649 | } | |
52d52440 JS |
9650 | } |
9651 | ||
1c6834a7 JS |
9652 | /* Check if there are static vports to be created. */ |
9653 | lpfc_create_static_vport(phba); | |
dea3101e JB |
9654 | return 0; |
9655 | ||
da0436e9 JS |
9656 | out_disable_intr: |
9657 | lpfc_sli4_disable_intr(phba); | |
5b75da2f JS |
9658 | out_free_sysfs_attr: |
9659 | lpfc_free_sysfs_attr(vport); | |
3772a991 JS |
9660 | out_destroy_shost: |
9661 | lpfc_destroy_shost(phba); | |
9662 | out_unset_driver_resource: | |
9663 | lpfc_unset_driver_resource_phase2(phba); | |
9664 | out_free_iocb_list: | |
9665 | lpfc_free_iocb_list(phba); | |
da0436e9 JS |
9666 | out_unset_driver_resource_s4: |
9667 | lpfc_sli4_driver_resource_unset(phba); | |
9668 | out_unset_pci_mem_s4: | |
9669 | lpfc_sli4_pci_mem_unset(phba); | |
3772a991 JS |
9670 | out_disable_pci_dev: |
9671 | lpfc_disable_pci_dev(phba); | |
6669f9bb JS |
9672 | if (shost) |
9673 | scsi_host_put(shost); | |
2e0fef85 | 9674 | out_free_phba: |
3772a991 | 9675 | lpfc_hba_free(phba); |
dea3101e JB |
9676 | return error; |
9677 | } | |
9678 | ||
e59058c4 | 9679 | /** |
da0436e9 | 9680 | * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem |
e59058c4 JS |
9681 | * @pdev: pointer to PCI device |
9682 | * | |
da0436e9 JS |
9683 | * This routine is called from the kernel's PCI subsystem to device with |
9684 | * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is | |
3772a991 JS |
9685 | * removed from PCI bus, it performs all the necessary cleanup for the HBA |
9686 | * device to be removed from the PCI subsystem properly. | |
e59058c4 | 9687 | **/ |
dea3101e | 9688 | static void __devexit |
da0436e9 | 9689 | lpfc_pci_remove_one_s4(struct pci_dev *pdev) |
dea3101e | 9690 | { |
da0436e9 | 9691 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
2e0fef85 | 9692 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
eada272d | 9693 | struct lpfc_vport **vports; |
da0436e9 | 9694 | struct lpfc_hba *phba = vport->phba; |
eada272d | 9695 | int i; |
8a4df120 | 9696 | |
da0436e9 | 9697 | /* Mark the device unloading flag */ |
549e55cd | 9698 | spin_lock_irq(&phba->hbalock); |
51ef4c26 | 9699 | vport->load_flag |= FC_UNLOADING; |
549e55cd | 9700 | spin_unlock_irq(&phba->hbalock); |
2e0fef85 | 9701 | |
da0436e9 | 9702 | /* Free the HBA sysfs attributes */ |
858c9f6c JS |
9703 | lpfc_free_sysfs_attr(vport); |
9704 | ||
eada272d JS |
9705 | /* Release all the vports against this physical port */ |
9706 | vports = lpfc_create_vport_work_array(phba); | |
9707 | if (vports != NULL) | |
587a37f6 JS |
9708 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
9709 | if (vports[i]->port_type == LPFC_PHYSICAL_PORT) | |
9710 | continue; | |
eada272d | 9711 | fc_vport_terminate(vports[i]->fc_vport); |
587a37f6 | 9712 | } |
eada272d JS |
9713 | lpfc_destroy_vport_work_array(phba, vports); |
9714 | ||
9715 | /* Remove FC host and then SCSI host with the physical port */ | |
858c9f6c JS |
9716 | fc_remove_host(shost); |
9717 | scsi_remove_host(shost); | |
da0436e9 JS |
9718 | |
9719 | /* Perform cleanup on the physical port */ | |
87af33fe JS |
9720 | lpfc_cleanup(vport); |
9721 | ||
2e0fef85 | 9722 | /* |
da0436e9 | 9723 | * Bring down the SLI Layer. This step disables all interrupts, |
2e0fef85 | 9724 | * clears the rings, discards all mailbox commands, and resets |
da0436e9 | 9725 | * the HBA FCoE function. |
2e0fef85 | 9726 | */ |
da0436e9 JS |
9727 | lpfc_debugfs_terminate(vport); |
9728 | lpfc_sli4_hba_unset(phba); | |
a257bf90 | 9729 | |
858c9f6c JS |
9730 | spin_lock_irq(&phba->hbalock); |
9731 | list_del_init(&vport->listentry); | |
9732 | spin_unlock_irq(&phba->hbalock); | |
9733 | ||
3677a3a7 | 9734 | /* Perform scsi free before driver resource_unset since scsi |
da0436e9 | 9735 | * buffers are released to their corresponding pools here. |
2e0fef85 JS |
9736 | */ |
9737 | lpfc_scsi_free(phba); | |
da0436e9 | 9738 | lpfc_sli4_driver_resource_unset(phba); |
ed957684 | 9739 | |
da0436e9 JS |
9740 | /* Unmap adapter Control and Doorbell registers */ |
9741 | lpfc_sli4_pci_mem_unset(phba); | |
2e0fef85 | 9742 | |
da0436e9 JS |
9743 | /* Release PCI resources and disable device's PCI function */ |
9744 | scsi_host_put(shost); | |
9745 | lpfc_disable_pci_dev(phba); | |
2e0fef85 | 9746 | |
da0436e9 | 9747 | /* Finally, free the driver's device data structure */ |
3772a991 | 9748 | lpfc_hba_free(phba); |
2e0fef85 | 9749 | |
da0436e9 | 9750 | return; |
dea3101e JB |
9751 | } |
9752 | ||
3a55b532 | 9753 | /** |
da0436e9 | 9754 | * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt |
3a55b532 JS |
9755 | * @pdev: pointer to PCI device |
9756 | * @msg: power management message | |
9757 | * | |
da0436e9 JS |
9758 | * This routine is called from the kernel's PCI subsystem to support system |
9759 | * Power Management (PM) to device with SLI-4 interface spec. When PM invokes | |
9760 | * this method, it quiesces the device by stopping the driver's worker | |
9761 | * thread for the device, turning off device's interrupt and DMA, and bring | |
9762 | * the device offline. Note that as the driver implements the minimum PM | |
9763 | * requirements to a power-aware driver's PM support for suspend/resume -- all | |
9764 | * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend() | |
9765 | * method call will be treated as SUSPEND and the driver will fully | |
9766 | * reinitialize its device during resume() method call, the driver will set | |
9767 | * device to PCI_D3hot state in PCI config space instead of setting it | |
3772a991 | 9768 | * according to the @msg provided by the PM. |
3a55b532 JS |
9769 | * |
9770 | * Return code | |
3772a991 JS |
9771 | * 0 - driver suspended the device |
9772 | * Error otherwise | |
3a55b532 JS |
9773 | **/ |
9774 | static int | |
da0436e9 | 9775 | lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg) |
3a55b532 JS |
9776 | { |
9777 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9778 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9779 | ||
9780 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
75baf696 | 9781 | "2843 PCI device Power Management suspend.\n"); |
3a55b532 JS |
9782 | |
9783 | /* Bring down the device */ | |
618a5230 | 9784 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
3a55b532 JS |
9785 | lpfc_offline(phba); |
9786 | kthread_stop(phba->worker_thread); | |
9787 | ||
9788 | /* Disable interrupt from device */ | |
da0436e9 | 9789 | lpfc_sli4_disable_intr(phba); |
5350d872 | 9790 | lpfc_sli4_queue_destroy(phba); |
3a55b532 JS |
9791 | |
9792 | /* Save device state to PCI config space */ | |
9793 | pci_save_state(pdev); | |
9794 | pci_set_power_state(pdev, PCI_D3hot); | |
9795 | ||
9796 | return 0; | |
9797 | } | |
9798 | ||
9799 | /** | |
da0436e9 | 9800 | * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt |
3a55b532 JS |
9801 | * @pdev: pointer to PCI device |
9802 | * | |
da0436e9 JS |
9803 | * This routine is called from the kernel's PCI subsystem to support system |
9804 | * Power Management (PM) to device with SLI-4 interface spac. When PM invokes | |
9805 | * this method, it restores the device's PCI config space state and fully | |
9806 | * reinitializes the device and brings it online. Note that as the driver | |
9807 | * implements the minimum PM requirements to a power-aware driver's PM for | |
9808 | * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE) | |
9809 | * to the suspend() method call will be treated as SUSPEND and the driver | |
9810 | * will fully reinitialize its device during resume() method call, the device | |
9811 | * will be set to PCI_D0 directly in PCI config space before restoring the | |
9812 | * state. | |
3a55b532 JS |
9813 | * |
9814 | * Return code | |
3772a991 JS |
9815 | * 0 - driver suspended the device |
9816 | * Error otherwise | |
3a55b532 JS |
9817 | **/ |
9818 | static int | |
da0436e9 | 9819 | lpfc_pci_resume_one_s4(struct pci_dev *pdev) |
3a55b532 JS |
9820 | { |
9821 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
9822 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
5b75da2f | 9823 | uint32_t intr_mode; |
3a55b532 JS |
9824 | int error; |
9825 | ||
9826 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, | |
da0436e9 | 9827 | "0292 PCI device Power Management resume.\n"); |
3a55b532 JS |
9828 | |
9829 | /* Restore device state from PCI config space */ | |
9830 | pci_set_power_state(pdev, PCI_D0); | |
9831 | pci_restore_state(pdev); | |
1dfb5a47 JS |
9832 | |
9833 | /* | |
9834 | * As the new kernel behavior of pci_restore_state() API call clears | |
9835 | * device saved_state flag, need to save the restored state again. | |
9836 | */ | |
9837 | pci_save_state(pdev); | |
9838 | ||
3a55b532 JS |
9839 | if (pdev->is_busmaster) |
9840 | pci_set_master(pdev); | |
9841 | ||
da0436e9 | 9842 | /* Startup the kernel thread for this host adapter. */ |
3a55b532 JS |
9843 | phba->worker_thread = kthread_run(lpfc_do_work, phba, |
9844 | "lpfc_worker_%d", phba->brd_no); | |
9845 | if (IS_ERR(phba->worker_thread)) { | |
9846 | error = PTR_ERR(phba->worker_thread); | |
9847 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
da0436e9 | 9848 | "0293 PM resume failed to start worker " |
3a55b532 JS |
9849 | "thread: error=x%x.\n", error); |
9850 | return error; | |
9851 | } | |
9852 | ||
5b75da2f | 9853 | /* Configure and enable interrupt */ |
da0436e9 | 9854 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); |
5b75da2f | 9855 | if (intr_mode == LPFC_INTR_ERROR) { |
3a55b532 | 9856 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
da0436e9 | 9857 | "0294 PM resume Failed to enable interrupt\n"); |
5b75da2f JS |
9858 | return -EIO; |
9859 | } else | |
9860 | phba->intr_mode = intr_mode; | |
3a55b532 JS |
9861 | |
9862 | /* Restart HBA and bring it online */ | |
9863 | lpfc_sli_brdrestart(phba); | |
9864 | lpfc_online(phba); | |
9865 | ||
5b75da2f JS |
9866 | /* Log the current active interrupt mode */ |
9867 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
9868 | ||
3a55b532 JS |
9869 | return 0; |
9870 | } | |
9871 | ||
75baf696 JS |
9872 | /** |
9873 | * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover | |
9874 | * @phba: pointer to lpfc hba data structure. | |
9875 | * | |
9876 | * This routine is called to prepare the SLI4 device for PCI slot recover. It | |
9877 | * aborts all the outstanding SCSI I/Os to the pci device. | |
9878 | **/ | |
9879 | static void | |
9880 | lpfc_sli4_prep_dev_for_recover(struct lpfc_hba *phba) | |
9881 | { | |
9882 | struct lpfc_sli *psli = &phba->sli; | |
9883 | struct lpfc_sli_ring *pring; | |
9884 | ||
9885 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9886 | "2828 PCI channel I/O abort preparing for recovery\n"); | |
9887 | /* | |
9888 | * There may be errored I/Os through HBA, abort all I/Os on txcmplq | |
9889 | * and let the SCSI mid-layer to retry them to recover. | |
9890 | */ | |
9891 | pring = &psli->ring[psli->fcp_ring]; | |
9892 | lpfc_sli_abort_iocb_ring(phba, pring); | |
9893 | } | |
9894 | ||
9895 | /** | |
9896 | * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset | |
9897 | * @phba: pointer to lpfc hba data structure. | |
9898 | * | |
9899 | * This routine is called to prepare the SLI4 device for PCI slot reset. It | |
9900 | * disables the device interrupt and pci device, and aborts the internal FCP | |
9901 | * pending I/Os. | |
9902 | **/ | |
9903 | static void | |
9904 | lpfc_sli4_prep_dev_for_reset(struct lpfc_hba *phba) | |
9905 | { | |
9906 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9907 | "2826 PCI channel disable preparing for reset\n"); | |
9908 | ||
9909 | /* Block any management I/Os to the device */ | |
618a5230 | 9910 | lpfc_block_mgmt_io(phba, LPFC_MBX_NO_WAIT); |
75baf696 JS |
9911 | |
9912 | /* Block all SCSI devices' I/Os on the host */ | |
9913 | lpfc_scsi_dev_block(phba); | |
9914 | ||
9915 | /* stop all timers */ | |
9916 | lpfc_stop_hba_timers(phba); | |
9917 | ||
9918 | /* Disable interrupt and pci device */ | |
9919 | lpfc_sli4_disable_intr(phba); | |
5350d872 | 9920 | lpfc_sli4_queue_destroy(phba); |
75baf696 JS |
9921 | pci_disable_device(phba->pcidev); |
9922 | ||
9923 | /* Flush all driver's outstanding SCSI I/Os as we are to reset */ | |
9924 | lpfc_sli_flush_fcp_rings(phba); | |
9925 | } | |
9926 | ||
9927 | /** | |
9928 | * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable | |
9929 | * @phba: pointer to lpfc hba data structure. | |
9930 | * | |
9931 | * This routine is called to prepare the SLI4 device for PCI slot permanently | |
9932 | * disabling. It blocks the SCSI transport layer traffic and flushes the FCP | |
9933 | * pending I/Os. | |
9934 | **/ | |
9935 | static void | |
9936 | lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba *phba) | |
9937 | { | |
9938 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9939 | "2827 PCI channel permanent disable for failure\n"); | |
9940 | ||
9941 | /* Block all SCSI devices' I/Os on the host */ | |
9942 | lpfc_scsi_dev_block(phba); | |
9943 | ||
9944 | /* stop all timers */ | |
9945 | lpfc_stop_hba_timers(phba); | |
9946 | ||
9947 | /* Clean up all driver's outstanding SCSI I/Os */ | |
9948 | lpfc_sli_flush_fcp_rings(phba); | |
9949 | } | |
9950 | ||
8d63f375 | 9951 | /** |
da0436e9 | 9952 | * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device |
e59058c4 JS |
9953 | * @pdev: pointer to PCI device. |
9954 | * @state: the current PCI connection state. | |
8d63f375 | 9955 | * |
da0436e9 JS |
9956 | * This routine is called from the PCI subsystem for error handling to device |
9957 | * with SLI-4 interface spec. This function is called by the PCI subsystem | |
9958 | * after a PCI bus error affecting this device has been detected. When this | |
9959 | * function is invoked, it will need to stop all the I/Os and interrupt(s) | |
9960 | * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET | |
9961 | * for the PCI subsystem to perform proper recovery as desired. | |
e59058c4 JS |
9962 | * |
9963 | * Return codes | |
3772a991 JS |
9964 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery |
9965 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
e59058c4 | 9966 | **/ |
3772a991 | 9967 | static pci_ers_result_t |
da0436e9 | 9968 | lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state) |
8d63f375 | 9969 | { |
75baf696 JS |
9970 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
9971 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
9972 | ||
9973 | switch (state) { | |
9974 | case pci_channel_io_normal: | |
9975 | /* Non-fatal error, prepare for recovery */ | |
9976 | lpfc_sli4_prep_dev_for_recover(phba); | |
9977 | return PCI_ERS_RESULT_CAN_RECOVER; | |
9978 | case pci_channel_io_frozen: | |
9979 | /* Fatal error, prepare for slot reset */ | |
9980 | lpfc_sli4_prep_dev_for_reset(phba); | |
9981 | return PCI_ERS_RESULT_NEED_RESET; | |
9982 | case pci_channel_io_perm_failure: | |
9983 | /* Permanent failure, prepare for device down */ | |
9984 | lpfc_sli4_prep_dev_for_perm_failure(phba); | |
9985 | return PCI_ERS_RESULT_DISCONNECT; | |
9986 | default: | |
9987 | /* Unknown state, prepare and request slot reset */ | |
9988 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
9989 | "2825 Unknown PCI error state: x%x\n", state); | |
9990 | lpfc_sli4_prep_dev_for_reset(phba); | |
9991 | return PCI_ERS_RESULT_NEED_RESET; | |
9992 | } | |
8d63f375 LV |
9993 | } |
9994 | ||
9995 | /** | |
da0436e9 | 9996 | * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch |
e59058c4 JS |
9997 | * @pdev: pointer to PCI device. |
9998 | * | |
da0436e9 JS |
9999 | * This routine is called from the PCI subsystem for error handling to device |
10000 | * with SLI-4 interface spec. It is called after PCI bus has been reset to | |
10001 | * restart the PCI card from scratch, as if from a cold-boot. During the | |
10002 | * PCI subsystem error recovery, after the driver returns | |
3772a991 | 10003 | * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error |
da0436e9 JS |
10004 | * recovery and then call this routine before calling the .resume method to |
10005 | * recover the device. This function will initialize the HBA device, enable | |
10006 | * the interrupt, but it will just put the HBA to offline state without | |
10007 | * passing any I/O traffic. | |
8d63f375 | 10008 | * |
e59058c4 | 10009 | * Return codes |
3772a991 JS |
10010 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered |
10011 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
8d63f375 | 10012 | */ |
3772a991 | 10013 | static pci_ers_result_t |
da0436e9 | 10014 | lpfc_io_slot_reset_s4(struct pci_dev *pdev) |
8d63f375 | 10015 | { |
75baf696 JS |
10016 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
10017 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10018 | struct lpfc_sli *psli = &phba->sli; | |
10019 | uint32_t intr_mode; | |
10020 | ||
10021 | dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n"); | |
10022 | if (pci_enable_device_mem(pdev)) { | |
10023 | printk(KERN_ERR "lpfc: Cannot re-enable " | |
10024 | "PCI device after reset.\n"); | |
10025 | return PCI_ERS_RESULT_DISCONNECT; | |
10026 | } | |
10027 | ||
10028 | pci_restore_state(pdev); | |
0a96e975 JS |
10029 | |
10030 | /* | |
10031 | * As the new kernel behavior of pci_restore_state() API call clears | |
10032 | * device saved_state flag, need to save the restored state again. | |
10033 | */ | |
10034 | pci_save_state(pdev); | |
10035 | ||
75baf696 JS |
10036 | if (pdev->is_busmaster) |
10037 | pci_set_master(pdev); | |
10038 | ||
10039 | spin_lock_irq(&phba->hbalock); | |
10040 | psli->sli_flag &= ~LPFC_SLI_ACTIVE; | |
10041 | spin_unlock_irq(&phba->hbalock); | |
10042 | ||
10043 | /* Configure and enable interrupt */ | |
10044 | intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode); | |
10045 | if (intr_mode == LPFC_INTR_ERROR) { | |
10046 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10047 | "2824 Cannot re-enable interrupt after " | |
10048 | "slot reset.\n"); | |
10049 | return PCI_ERS_RESULT_DISCONNECT; | |
10050 | } else | |
10051 | phba->intr_mode = intr_mode; | |
10052 | ||
10053 | /* Log the current active interrupt mode */ | |
10054 | lpfc_log_intr_mode(phba, phba->intr_mode); | |
10055 | ||
8d63f375 LV |
10056 | return PCI_ERS_RESULT_RECOVERED; |
10057 | } | |
10058 | ||
10059 | /** | |
da0436e9 | 10060 | * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device |
e59058c4 | 10061 | * @pdev: pointer to PCI device |
8d63f375 | 10062 | * |
3772a991 | 10063 | * This routine is called from the PCI subsystem for error handling to device |
da0436e9 | 10064 | * with SLI-4 interface spec. It is called when kernel error recovery tells |
3772a991 JS |
10065 | * the lpfc driver that it is ok to resume normal PCI operation after PCI bus |
10066 | * error recovery. After this call, traffic can start to flow from this device | |
10067 | * again. | |
da0436e9 | 10068 | **/ |
3772a991 | 10069 | static void |
da0436e9 | 10070 | lpfc_io_resume_s4(struct pci_dev *pdev) |
8d63f375 | 10071 | { |
75baf696 JS |
10072 | struct Scsi_Host *shost = pci_get_drvdata(pdev); |
10073 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10074 | ||
10075 | /* | |
10076 | * In case of slot reset, as function reset is performed through | |
10077 | * mailbox command which needs DMA to be enabled, this operation | |
10078 | * has to be moved to the io resume phase. Taking device offline | |
10079 | * will perform the necessary cleanup. | |
10080 | */ | |
10081 | if (!(phba->sli.sli_flag & LPFC_SLI_ACTIVE)) { | |
10082 | /* Perform device reset */ | |
618a5230 | 10083 | lpfc_offline_prep(phba, LPFC_MBX_WAIT); |
75baf696 JS |
10084 | lpfc_offline(phba); |
10085 | lpfc_sli_brdrestart(phba); | |
10086 | /* Bring the device back online */ | |
10087 | lpfc_online(phba); | |
10088 | } | |
10089 | ||
10090 | /* Clean up Advanced Error Reporting (AER) if needed */ | |
10091 | if (phba->hba_flag & HBA_AER_ENABLED) | |
10092 | pci_cleanup_aer_uncorrect_error_status(pdev); | |
8d63f375 LV |
10093 | } |
10094 | ||
3772a991 JS |
10095 | /** |
10096 | * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem | |
10097 | * @pdev: pointer to PCI device | |
10098 | * @pid: pointer to PCI device identifier | |
10099 | * | |
10100 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
10101 | * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks | |
10102 | * at PCI device-specific information of the device and driver to see if the | |
10103 | * driver state that it can support this kind of device. If the match is | |
10104 | * successful, the driver core invokes this routine. This routine dispatches | |
10105 | * the action to the proper SLI-3 or SLI-4 device probing routine, which will | |
10106 | * do all the initialization that it needs to do to handle the HBA device | |
10107 | * properly. | |
10108 | * | |
10109 | * Return code | |
10110 | * 0 - driver can claim the device | |
10111 | * negative value - driver can not claim the device | |
10112 | **/ | |
10113 | static int __devinit | |
10114 | lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) | |
10115 | { | |
10116 | int rc; | |
8fa38513 | 10117 | struct lpfc_sli_intf intf; |
3772a991 | 10118 | |
28baac74 | 10119 | if (pci_read_config_dword(pdev, LPFC_SLI_INTF, &intf.word0)) |
3772a991 JS |
10120 | return -ENODEV; |
10121 | ||
8fa38513 | 10122 | if ((bf_get(lpfc_sli_intf_valid, &intf) == LPFC_SLI_INTF_VALID) && |
28baac74 | 10123 | (bf_get(lpfc_sli_intf_slirev, &intf) == LPFC_SLI_INTF_REV_SLI4)) |
da0436e9 | 10124 | rc = lpfc_pci_probe_one_s4(pdev, pid); |
8fa38513 | 10125 | else |
3772a991 | 10126 | rc = lpfc_pci_probe_one_s3(pdev, pid); |
8fa38513 | 10127 | |
3772a991 JS |
10128 | return rc; |
10129 | } | |
10130 | ||
10131 | /** | |
10132 | * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem | |
10133 | * @pdev: pointer to PCI device | |
10134 | * | |
10135 | * This routine is to be registered to the kernel's PCI subsystem. When an | |
10136 | * Emulex HBA is removed from PCI bus, the driver core invokes this routine. | |
10137 | * This routine dispatches the action to the proper SLI-3 or SLI-4 device | |
10138 | * remove routine, which will perform all the necessary cleanup for the | |
10139 | * device to be removed from the PCI subsystem properly. | |
10140 | **/ | |
10141 | static void __devexit | |
10142 | lpfc_pci_remove_one(struct pci_dev *pdev) | |
10143 | { | |
10144 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10145 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10146 | ||
10147 | switch (phba->pci_dev_grp) { | |
10148 | case LPFC_PCI_DEV_LP: | |
10149 | lpfc_pci_remove_one_s3(pdev); | |
10150 | break; | |
da0436e9 JS |
10151 | case LPFC_PCI_DEV_OC: |
10152 | lpfc_pci_remove_one_s4(pdev); | |
10153 | break; | |
3772a991 JS |
10154 | default: |
10155 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10156 | "1424 Invalid PCI device group: 0x%x\n", | |
10157 | phba->pci_dev_grp); | |
10158 | break; | |
10159 | } | |
10160 | return; | |
10161 | } | |
10162 | ||
10163 | /** | |
10164 | * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management | |
10165 | * @pdev: pointer to PCI device | |
10166 | * @msg: power management message | |
10167 | * | |
10168 | * This routine is to be registered to the kernel's PCI subsystem to support | |
10169 | * system Power Management (PM). When PM invokes this method, it dispatches | |
10170 | * the action to the proper SLI-3 or SLI-4 device suspend routine, which will | |
10171 | * suspend the device. | |
10172 | * | |
10173 | * Return code | |
10174 | * 0 - driver suspended the device | |
10175 | * Error otherwise | |
10176 | **/ | |
10177 | static int | |
10178 | lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg) | |
10179 | { | |
10180 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10181 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10182 | int rc = -ENODEV; | |
10183 | ||
10184 | switch (phba->pci_dev_grp) { | |
10185 | case LPFC_PCI_DEV_LP: | |
10186 | rc = lpfc_pci_suspend_one_s3(pdev, msg); | |
10187 | break; | |
da0436e9 JS |
10188 | case LPFC_PCI_DEV_OC: |
10189 | rc = lpfc_pci_suspend_one_s4(pdev, msg); | |
10190 | break; | |
3772a991 JS |
10191 | default: |
10192 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10193 | "1425 Invalid PCI device group: 0x%x\n", | |
10194 | phba->pci_dev_grp); | |
10195 | break; | |
10196 | } | |
10197 | return rc; | |
10198 | } | |
10199 | ||
10200 | /** | |
10201 | * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management | |
10202 | * @pdev: pointer to PCI device | |
10203 | * | |
10204 | * This routine is to be registered to the kernel's PCI subsystem to support | |
10205 | * system Power Management (PM). When PM invokes this method, it dispatches | |
10206 | * the action to the proper SLI-3 or SLI-4 device resume routine, which will | |
10207 | * resume the device. | |
10208 | * | |
10209 | * Return code | |
10210 | * 0 - driver suspended the device | |
10211 | * Error otherwise | |
10212 | **/ | |
10213 | static int | |
10214 | lpfc_pci_resume_one(struct pci_dev *pdev) | |
10215 | { | |
10216 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10217 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10218 | int rc = -ENODEV; | |
10219 | ||
10220 | switch (phba->pci_dev_grp) { | |
10221 | case LPFC_PCI_DEV_LP: | |
10222 | rc = lpfc_pci_resume_one_s3(pdev); | |
10223 | break; | |
da0436e9 JS |
10224 | case LPFC_PCI_DEV_OC: |
10225 | rc = lpfc_pci_resume_one_s4(pdev); | |
10226 | break; | |
3772a991 JS |
10227 | default: |
10228 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10229 | "1426 Invalid PCI device group: 0x%x\n", | |
10230 | phba->pci_dev_grp); | |
10231 | break; | |
10232 | } | |
10233 | return rc; | |
10234 | } | |
10235 | ||
10236 | /** | |
10237 | * lpfc_io_error_detected - lpfc method for handling PCI I/O error | |
10238 | * @pdev: pointer to PCI device. | |
10239 | * @state: the current PCI connection state. | |
10240 | * | |
10241 | * This routine is registered to the PCI subsystem for error handling. This | |
10242 | * function is called by the PCI subsystem after a PCI bus error affecting | |
10243 | * this device has been detected. When this routine is invoked, it dispatches | |
10244 | * the action to the proper SLI-3 or SLI-4 device error detected handling | |
10245 | * routine, which will perform the proper error detected operation. | |
10246 | * | |
10247 | * Return codes | |
10248 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery | |
10249 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
10250 | **/ | |
10251 | static pci_ers_result_t | |
10252 | lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | |
10253 | { | |
10254 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10255 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10256 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
10257 | ||
10258 | switch (phba->pci_dev_grp) { | |
10259 | case LPFC_PCI_DEV_LP: | |
10260 | rc = lpfc_io_error_detected_s3(pdev, state); | |
10261 | break; | |
da0436e9 JS |
10262 | case LPFC_PCI_DEV_OC: |
10263 | rc = lpfc_io_error_detected_s4(pdev, state); | |
10264 | break; | |
3772a991 JS |
10265 | default: |
10266 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10267 | "1427 Invalid PCI device group: 0x%x\n", | |
10268 | phba->pci_dev_grp); | |
10269 | break; | |
10270 | } | |
10271 | return rc; | |
10272 | } | |
10273 | ||
10274 | /** | |
10275 | * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch | |
10276 | * @pdev: pointer to PCI device. | |
10277 | * | |
10278 | * This routine is registered to the PCI subsystem for error handling. This | |
10279 | * function is called after PCI bus has been reset to restart the PCI card | |
10280 | * from scratch, as if from a cold-boot. When this routine is invoked, it | |
10281 | * dispatches the action to the proper SLI-3 or SLI-4 device reset handling | |
10282 | * routine, which will perform the proper device reset. | |
10283 | * | |
10284 | * Return codes | |
10285 | * PCI_ERS_RESULT_RECOVERED - the device has been recovered | |
10286 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | |
10287 | **/ | |
10288 | static pci_ers_result_t | |
10289 | lpfc_io_slot_reset(struct pci_dev *pdev) | |
10290 | { | |
10291 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10292 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10293 | pci_ers_result_t rc = PCI_ERS_RESULT_DISCONNECT; | |
10294 | ||
10295 | switch (phba->pci_dev_grp) { | |
10296 | case LPFC_PCI_DEV_LP: | |
10297 | rc = lpfc_io_slot_reset_s3(pdev); | |
10298 | break; | |
da0436e9 JS |
10299 | case LPFC_PCI_DEV_OC: |
10300 | rc = lpfc_io_slot_reset_s4(pdev); | |
10301 | break; | |
3772a991 JS |
10302 | default: |
10303 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10304 | "1428 Invalid PCI device group: 0x%x\n", | |
10305 | phba->pci_dev_grp); | |
10306 | break; | |
10307 | } | |
10308 | return rc; | |
10309 | } | |
10310 | ||
10311 | /** | |
10312 | * lpfc_io_resume - lpfc method for resuming PCI I/O operation | |
10313 | * @pdev: pointer to PCI device | |
10314 | * | |
10315 | * This routine is registered to the PCI subsystem for error handling. It | |
10316 | * is called when kernel error recovery tells the lpfc driver that it is | |
10317 | * OK to resume normal PCI operation after PCI bus error recovery. When | |
10318 | * this routine is invoked, it dispatches the action to the proper SLI-3 | |
10319 | * or SLI-4 device io_resume routine, which will resume the device operation. | |
10320 | **/ | |
10321 | static void | |
10322 | lpfc_io_resume(struct pci_dev *pdev) | |
10323 | { | |
10324 | struct Scsi_Host *shost = pci_get_drvdata(pdev); | |
10325 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
10326 | ||
10327 | switch (phba->pci_dev_grp) { | |
10328 | case LPFC_PCI_DEV_LP: | |
10329 | lpfc_io_resume_s3(pdev); | |
10330 | break; | |
da0436e9 JS |
10331 | case LPFC_PCI_DEV_OC: |
10332 | lpfc_io_resume_s4(pdev); | |
10333 | break; | |
3772a991 JS |
10334 | default: |
10335 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
10336 | "1429 Invalid PCI device group: 0x%x\n", | |
10337 | phba->pci_dev_grp); | |
10338 | break; | |
10339 | } | |
10340 | return; | |
10341 | } | |
10342 | ||
3ef6d24c JS |
10343 | /** |
10344 | * lpfc_mgmt_open - method called when 'lpfcmgmt' is opened from userspace | |
10345 | * @inode: pointer to the inode representing the lpfcmgmt device | |
10346 | * @filep: pointer to the file representing the open lpfcmgmt device | |
10347 | * | |
10348 | * This routine puts a reference count on the lpfc module whenever the | |
10349 | * character device is opened | |
10350 | **/ | |
10351 | static int | |
10352 | lpfc_mgmt_open(struct inode *inode, struct file *filep) | |
10353 | { | |
10354 | try_module_get(THIS_MODULE); | |
10355 | return 0; | |
10356 | } | |
10357 | ||
10358 | /** | |
10359 | * lpfc_mgmt_release - method called when 'lpfcmgmt' is closed in userspace | |
10360 | * @inode: pointer to the inode representing the lpfcmgmt device | |
10361 | * @filep: pointer to the file representing the open lpfcmgmt device | |
10362 | * | |
10363 | * This routine removes a reference count from the lpfc module when the | |
10364 | * character device is closed | |
10365 | **/ | |
10366 | static int | |
10367 | lpfc_mgmt_release(struct inode *inode, struct file *filep) | |
10368 | { | |
10369 | module_put(THIS_MODULE); | |
10370 | return 0; | |
10371 | } | |
10372 | ||
dea3101e JB |
10373 | static struct pci_device_id lpfc_id_table[] = { |
10374 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER, | |
10375 | PCI_ANY_ID, PCI_ANY_ID, }, | |
06325e74 JSEC |
10376 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY, |
10377 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
10378 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR, |
10379 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10380 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS, | |
10381 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10382 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR, | |
10383 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10384 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY, | |
10385 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10386 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY, | |
10387 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10388 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY, | |
10389 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10390 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY, | |
10391 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
10392 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE, |
10393 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10394 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP, | |
10395 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10396 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP, | |
10397 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
10398 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS, |
10399 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
10400 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP, |
10401 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10402 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP, | |
10403 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
10404 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID, |
10405 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10406 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB, | |
10407 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10408 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR, | |
10409 | PCI_ANY_ID, PCI_ANY_ID, }, | |
84774a4d JS |
10410 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HORNET, |
10411 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
10412 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP, |
10413 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10414 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP, | |
10415 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
10416 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID, |
10417 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10418 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB, | |
10419 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10420 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY, | |
10421 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10422 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101, | |
10423 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10424 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S, | |
10425 | PCI_ANY_ID, PCI_ANY_ID, }, | |
e4adb204 JSEC |
10426 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S, |
10427 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10428 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, | |
10429 | PCI_ANY_ID, PCI_ANY_ID, }, | |
b87eab38 JS |
10430 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT, |
10431 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10432 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID, | |
10433 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10434 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB, | |
10435 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10436 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP, | |
10437 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10438 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP, | |
10439 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10440 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S, | |
10441 | PCI_ANY_ID, PCI_ANY_ID, }, | |
84774a4d JS |
10442 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_VF, |
10443 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10444 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_PF, | |
10445 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10446 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PROTEUS_S, | |
10447 | PCI_ANY_ID, PCI_ANY_ID, }, | |
3772a991 JS |
10448 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TIGERSHARK, |
10449 | PCI_ANY_ID, PCI_ANY_ID, }, | |
a747c9ce JS |
10450 | {PCI_VENDOR_ID_SERVERENGINE, PCI_DEVICE_ID_TOMCAT, |
10451 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10452 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FALCON, | |
6669f9bb | 10453 | PCI_ANY_ID, PCI_ANY_ID, }, |
98fc5dd9 JS |
10454 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BALIUS, |
10455 | PCI_ANY_ID, PCI_ANY_ID, }, | |
085c647c JS |
10456 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC, |
10457 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10458 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE, | |
10459 | PCI_ANY_ID, PCI_ANY_ID, }, | |
c0c11512 JS |
10460 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FC_VF, |
10461 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10462 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LANCER_FCOE_VF, | |
10463 | PCI_ANY_ID, PCI_ANY_ID, }, | |
f8cafd38 JS |
10464 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK, |
10465 | PCI_ANY_ID, PCI_ANY_ID, }, | |
10466 | {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SKYHAWK_VF, | |
10467 | PCI_ANY_ID, PCI_ANY_ID, }, | |
dea3101e JB |
10468 | { 0 } |
10469 | }; | |
10470 | ||
10471 | MODULE_DEVICE_TABLE(pci, lpfc_id_table); | |
10472 | ||
8d63f375 LV |
10473 | static struct pci_error_handlers lpfc_err_handler = { |
10474 | .error_detected = lpfc_io_error_detected, | |
10475 | .slot_reset = lpfc_io_slot_reset, | |
10476 | .resume = lpfc_io_resume, | |
10477 | }; | |
10478 | ||
dea3101e JB |
10479 | static struct pci_driver lpfc_driver = { |
10480 | .name = LPFC_DRIVER_NAME, | |
10481 | .id_table = lpfc_id_table, | |
10482 | .probe = lpfc_pci_probe_one, | |
10483 | .remove = __devexit_p(lpfc_pci_remove_one), | |
3a55b532 | 10484 | .suspend = lpfc_pci_suspend_one, |
3772a991 | 10485 | .resume = lpfc_pci_resume_one, |
2e0fef85 | 10486 | .err_handler = &lpfc_err_handler, |
dea3101e JB |
10487 | }; |
10488 | ||
3ef6d24c JS |
10489 | static const struct file_operations lpfc_mgmt_fop = { |
10490 | .open = lpfc_mgmt_open, | |
10491 | .release = lpfc_mgmt_release, | |
10492 | }; | |
10493 | ||
10494 | static struct miscdevice lpfc_mgmt_dev = { | |
10495 | .minor = MISC_DYNAMIC_MINOR, | |
10496 | .name = "lpfcmgmt", | |
10497 | .fops = &lpfc_mgmt_fop, | |
10498 | }; | |
10499 | ||
e59058c4 | 10500 | /** |
3621a710 | 10501 | * lpfc_init - lpfc module initialization routine |
e59058c4 JS |
10502 | * |
10503 | * This routine is to be invoked when the lpfc module is loaded into the | |
10504 | * kernel. The special kernel macro module_init() is used to indicate the | |
10505 | * role of this routine to the kernel as lpfc module entry point. | |
10506 | * | |
10507 | * Return codes | |
10508 | * 0 - successful | |
10509 | * -ENOMEM - FC attach transport failed | |
10510 | * all others - failed | |
10511 | */ | |
dea3101e JB |
10512 | static int __init |
10513 | lpfc_init(void) | |
10514 | { | |
10515 | int error = 0; | |
10516 | ||
10517 | printk(LPFC_MODULE_DESC "\n"); | |
c44ce173 | 10518 | printk(LPFC_COPYRIGHT "\n"); |
dea3101e | 10519 | |
3ef6d24c JS |
10520 | error = misc_register(&lpfc_mgmt_dev); |
10521 | if (error) | |
10522 | printk(KERN_ERR "Could not register lpfcmgmt device, " | |
10523 | "misc_register returned with status %d", error); | |
10524 | ||
7ee5d43e JS |
10525 | if (lpfc_enable_npiv) { |
10526 | lpfc_transport_functions.vport_create = lpfc_vport_create; | |
10527 | lpfc_transport_functions.vport_delete = lpfc_vport_delete; | |
10528 | } | |
dea3101e JB |
10529 | lpfc_transport_template = |
10530 | fc_attach_transport(&lpfc_transport_functions); | |
7ee5d43e | 10531 | if (lpfc_transport_template == NULL) |
dea3101e | 10532 | return -ENOMEM; |
7ee5d43e | 10533 | if (lpfc_enable_npiv) { |
7ee5d43e | 10534 | lpfc_vport_transport_template = |
98c9ea5c JS |
10535 | fc_attach_transport(&lpfc_vport_transport_functions); |
10536 | if (lpfc_vport_transport_template == NULL) { | |
10537 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e | 10538 | return -ENOMEM; |
98c9ea5c | 10539 | } |
7ee5d43e | 10540 | } |
dea3101e | 10541 | error = pci_register_driver(&lpfc_driver); |
92d7f7b0 | 10542 | if (error) { |
dea3101e | 10543 | fc_release_transport(lpfc_transport_template); |
d7c255b2 JS |
10544 | if (lpfc_enable_npiv) |
10545 | fc_release_transport(lpfc_vport_transport_template); | |
92d7f7b0 | 10546 | } |
dea3101e JB |
10547 | |
10548 | return error; | |
10549 | } | |
10550 | ||
e59058c4 | 10551 | /** |
3621a710 | 10552 | * lpfc_exit - lpfc module removal routine |
e59058c4 JS |
10553 | * |
10554 | * This routine is invoked when the lpfc module is removed from the kernel. | |
10555 | * The special kernel macro module_exit() is used to indicate the role of | |
10556 | * this routine to the kernel as lpfc module exit point. | |
10557 | */ | |
dea3101e JB |
10558 | static void __exit |
10559 | lpfc_exit(void) | |
10560 | { | |
3ef6d24c | 10561 | misc_deregister(&lpfc_mgmt_dev); |
dea3101e JB |
10562 | pci_unregister_driver(&lpfc_driver); |
10563 | fc_release_transport(lpfc_transport_template); | |
7ee5d43e JS |
10564 | if (lpfc_enable_npiv) |
10565 | fc_release_transport(lpfc_vport_transport_template); | |
81301a9b | 10566 | if (_dump_buf_data) { |
6a9c52cf JS |
10567 | printk(KERN_ERR "9062 BLKGRD: freeing %lu pages for " |
10568 | "_dump_buf_data at 0x%p\n", | |
81301a9b JS |
10569 | (1L << _dump_buf_data_order), _dump_buf_data); |
10570 | free_pages((unsigned long)_dump_buf_data, _dump_buf_data_order); | |
10571 | } | |
10572 | ||
10573 | if (_dump_buf_dif) { | |
6a9c52cf JS |
10574 | printk(KERN_ERR "9049 BLKGRD: freeing %lu pages for " |
10575 | "_dump_buf_dif at 0x%p\n", | |
81301a9b JS |
10576 | (1L << _dump_buf_dif_order), _dump_buf_dif); |
10577 | free_pages((unsigned long)_dump_buf_dif, _dump_buf_dif_order); | |
10578 | } | |
dea3101e JB |
10579 | } |
10580 | ||
10581 | module_init(lpfc_init); | |
10582 | module_exit(lpfc_exit); | |
10583 | MODULE_LICENSE("GPL"); | |
10584 | MODULE_DESCRIPTION(LPFC_MODULE_DESC); | |
10585 | MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com"); | |
10586 | MODULE_VERSION("0:" LPFC_DRIVER_VERSION); |