1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2011 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
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. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/delay.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/idr.h>
26 #include <linux/interrupt.h>
27 #include <linux/module.h>
28 #include <linux/kthread.h>
29 #include <linux/pci.h>
30 #include <linux/spinlock.h>
31 #include <linux/ctype.h>
32 #include <linux/aer.h>
33 #include <linux/slab.h>
34 #include <linux/firmware.h>
36 #include <scsi/scsi.h>
37 #include <scsi/scsi_device.h>
38 #include <scsi/scsi_host.h>
39 #include <scsi/scsi_transport_fc.h>
44 #include "lpfc_sli4.h"
46 #include "lpfc_disc.h"
47 #include "lpfc_scsi.h"
49 #include "lpfc_logmsg.h"
50 #include "lpfc_crtn.h"
51 #include "lpfc_vport.h"
52 #include "lpfc_version.h"
55 unsigned long _dump_buf_data_order
;
57 unsigned long _dump_buf_dif_order
;
58 spinlock_t _dump_buf_lock
;
60 static void lpfc_get_hba_model_desc(struct lpfc_hba
*, uint8_t *, uint8_t *);
61 static int lpfc_post_rcv_buf(struct lpfc_hba
*);
62 static int lpfc_sli4_queue_create(struct lpfc_hba
*);
63 static void lpfc_sli4_queue_destroy(struct lpfc_hba
*);
64 static int lpfc_create_bootstrap_mbox(struct lpfc_hba
*);
65 static int lpfc_setup_endian_order(struct lpfc_hba
*);
66 static int lpfc_sli4_read_config(struct lpfc_hba
*);
67 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*);
68 static void lpfc_free_sgl_list(struct lpfc_hba
*);
69 static int lpfc_init_sgl_list(struct lpfc_hba
*);
70 static int lpfc_init_active_sgl_array(struct lpfc_hba
*);
71 static void lpfc_free_active_sgl(struct lpfc_hba
*);
72 static int lpfc_hba_down_post_s3(struct lpfc_hba
*phba
);
73 static int lpfc_hba_down_post_s4(struct lpfc_hba
*phba
);
74 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*);
75 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*);
76 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba
*);
78 static struct scsi_transport_template
*lpfc_transport_template
= NULL
;
79 static struct scsi_transport_template
*lpfc_vport_transport_template
= NULL
;
80 static DEFINE_IDR(lpfc_hba_index
);
83 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
84 * @phba: pointer to lpfc hba data structure.
86 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
87 * mailbox command. It retrieves the revision information from the HBA and
88 * collects the Vital Product Data (VPD) about the HBA for preparing the
89 * configuration of the HBA.
93 * -ERESTART - requests the SLI layer to reset the HBA and try again.
94 * Any other value - indicates an error.
97 lpfc_config_port_prep(struct lpfc_hba
*phba
)
99 lpfc_vpd_t
*vp
= &phba
->vpd
;
103 char *lpfc_vpd_data
= NULL
;
105 static char licensed
[56] =
106 "key unlock for use with gnu public licensed code only\0";
107 static int init_key
= 1;
109 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
111 phba
->link_state
= LPFC_HBA_ERROR
;
116 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
118 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
120 uint32_t *ptext
= (uint32_t *) licensed
;
122 for (i
= 0; i
< 56; i
+= sizeof (uint32_t), ptext
++)
123 *ptext
= cpu_to_be32(*ptext
);
127 lpfc_read_nv(phba
, pmb
);
128 memset((char*)mb
->un
.varRDnvp
.rsvd3
, 0,
129 sizeof (mb
->un
.varRDnvp
.rsvd3
));
130 memcpy((char*)mb
->un
.varRDnvp
.rsvd3
, licensed
,
133 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
135 if (rc
!= MBX_SUCCESS
) {
136 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
137 "0324 Config Port initialization "
138 "error, mbxCmd x%x READ_NVPARM, "
140 mb
->mbxCommand
, mb
->mbxStatus
);
141 mempool_free(pmb
, phba
->mbox_mem_pool
);
144 memcpy(phba
->wwnn
, (char *)mb
->un
.varRDnvp
.nodename
,
146 memcpy(phba
->wwpn
, (char *)mb
->un
.varRDnvp
.portname
,
150 phba
->sli3_options
= 0x0;
152 /* Setup and issue mailbox READ REV command */
153 lpfc_read_rev(phba
, pmb
);
154 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
155 if (rc
!= MBX_SUCCESS
) {
156 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
157 "0439 Adapter failed to init, mbxCmd x%x "
158 "READ_REV, mbxStatus x%x\n",
159 mb
->mbxCommand
, mb
->mbxStatus
);
160 mempool_free( pmb
, phba
->mbox_mem_pool
);
166 * The value of rr must be 1 since the driver set the cv field to 1.
167 * This setting requires the FW to set all revision fields.
169 if (mb
->un
.varRdRev
.rr
== 0) {
171 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
172 "0440 Adapter failed to init, READ_REV has "
173 "missing revision information.\n");
174 mempool_free(pmb
, phba
->mbox_mem_pool
);
178 if (phba
->sli_rev
== 3 && !mb
->un
.varRdRev
.v3rsp
) {
179 mempool_free(pmb
, phba
->mbox_mem_pool
);
183 /* Save information as VPD data */
185 memcpy(&vp
->sli3Feat
, &mb
->un
.varRdRev
.sli3Feat
, sizeof(uint32_t));
186 vp
->rev
.sli1FwRev
= mb
->un
.varRdRev
.sli1FwRev
;
187 memcpy(vp
->rev
.sli1FwName
, (char*) mb
->un
.varRdRev
.sli1FwName
, 16);
188 vp
->rev
.sli2FwRev
= mb
->un
.varRdRev
.sli2FwRev
;
189 memcpy(vp
->rev
.sli2FwName
, (char *) mb
->un
.varRdRev
.sli2FwName
, 16);
190 vp
->rev
.biuRev
= mb
->un
.varRdRev
.biuRev
;
191 vp
->rev
.smRev
= mb
->un
.varRdRev
.smRev
;
192 vp
->rev
.smFwRev
= mb
->un
.varRdRev
.un
.smFwRev
;
193 vp
->rev
.endecRev
= mb
->un
.varRdRev
.endecRev
;
194 vp
->rev
.fcphHigh
= mb
->un
.varRdRev
.fcphHigh
;
195 vp
->rev
.fcphLow
= mb
->un
.varRdRev
.fcphLow
;
196 vp
->rev
.feaLevelHigh
= mb
->un
.varRdRev
.feaLevelHigh
;
197 vp
->rev
.feaLevelLow
= mb
->un
.varRdRev
.feaLevelLow
;
198 vp
->rev
.postKernRev
= mb
->un
.varRdRev
.postKernRev
;
199 vp
->rev
.opFwRev
= mb
->un
.varRdRev
.opFwRev
;
201 /* If the sli feature level is less then 9, we must
202 * tear down all RPIs and VPIs on link down if NPIV
205 if (vp
->rev
.feaLevelHigh
< 9)
206 phba
->sli3_options
|= LPFC_SLI3_VPORT_TEARDOWN
;
208 if (lpfc_is_LC_HBA(phba
->pcidev
->device
))
209 memcpy(phba
->RandomData
, (char *)&mb
->un
.varWords
[24],
210 sizeof (phba
->RandomData
));
212 /* Get adapter VPD information */
213 lpfc_vpd_data
= kmalloc(DMP_VPD_SIZE
, GFP_KERNEL
);
217 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_VPD
);
218 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
220 if (rc
!= MBX_SUCCESS
) {
221 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
222 "0441 VPD not present on adapter, "
223 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
224 mb
->mbxCommand
, mb
->mbxStatus
);
225 mb
->un
.varDmp
.word_cnt
= 0;
227 /* dump mem may return a zero when finished or we got a
228 * mailbox error, either way we are done.
230 if (mb
->un
.varDmp
.word_cnt
== 0)
232 if (mb
->un
.varDmp
.word_cnt
> DMP_VPD_SIZE
- offset
)
233 mb
->un
.varDmp
.word_cnt
= DMP_VPD_SIZE
- offset
;
234 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
235 lpfc_vpd_data
+ offset
,
236 mb
->un
.varDmp
.word_cnt
);
237 offset
+= mb
->un
.varDmp
.word_cnt
;
238 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_VPD_SIZE
);
239 lpfc_parse_vpd(phba
, lpfc_vpd_data
, offset
);
241 kfree(lpfc_vpd_data
);
243 mempool_free(pmb
, phba
->mbox_mem_pool
);
248 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
249 * @phba: pointer to lpfc hba data structure.
250 * @pmboxq: pointer to the driver internal queue element for mailbox command.
252 * This is the completion handler for driver's configuring asynchronous event
253 * mailbox command to the device. If the mailbox command returns successfully,
254 * it will set internal async event support flag to 1; otherwise, it will
255 * set internal async event support flag to 0.
258 lpfc_config_async_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
260 if (pmboxq
->u
.mb
.mbxStatus
== MBX_SUCCESS
)
261 phba
->temp_sensor_support
= 1;
263 phba
->temp_sensor_support
= 0;
264 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
269 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
270 * @phba: pointer to lpfc hba data structure.
271 * @pmboxq: pointer to the driver internal queue element for mailbox command.
273 * This is the completion handler for dump mailbox command for getting
274 * wake up parameters. When this command complete, the response contain
275 * Option rom version of the HBA. This function translate the version number
276 * into a human readable string and store it in OptionROMVersion.
279 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
282 uint32_t prog_id_word
;
284 /* character array used for decoding dist type. */
285 char dist_char
[] = "nabx";
287 if (pmboxq
->u
.mb
.mbxStatus
!= MBX_SUCCESS
) {
288 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
292 prg
= (struct prog_id
*) &prog_id_word
;
294 /* word 7 contain option rom version */
295 prog_id_word
= pmboxq
->u
.mb
.un
.varWords
[7];
297 /* Decode the Option rom version word to a readable string */
299 dist
= dist_char
[prg
->dist
];
301 if ((prg
->dist
== 3) && (prg
->num
== 0))
302 sprintf(phba
->OptionROMVersion
, "%d.%d%d",
303 prg
->ver
, prg
->rev
, prg
->lev
);
305 sprintf(phba
->OptionROMVersion
, "%d.%d%d%c%d",
306 prg
->ver
, prg
->rev
, prg
->lev
,
308 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
313 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
314 * cfg_soft_wwnn, cfg_soft_wwpn
315 * @vport: pointer to lpfc vport data structure.
322 lpfc_update_vport_wwn(struct lpfc_vport
*vport
)
324 /* If the soft name exists then update it using the service params */
325 if (vport
->phba
->cfg_soft_wwnn
)
326 u64_to_wwn(vport
->phba
->cfg_soft_wwnn
,
327 vport
->fc_sparam
.nodeName
.u
.wwn
);
328 if (vport
->phba
->cfg_soft_wwpn
)
329 u64_to_wwn(vport
->phba
->cfg_soft_wwpn
,
330 vport
->fc_sparam
.portName
.u
.wwn
);
333 * If the name is empty or there exists a soft name
334 * then copy the service params name, otherwise use the fc name
336 if (vport
->fc_nodename
.u
.wwn
[0] == 0 || vport
->phba
->cfg_soft_wwnn
)
337 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
338 sizeof(struct lpfc_name
));
340 memcpy(&vport
->fc_sparam
.nodeName
, &vport
->fc_nodename
,
341 sizeof(struct lpfc_name
));
343 if (vport
->fc_portname
.u
.wwn
[0] == 0 || vport
->phba
->cfg_soft_wwpn
)
344 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
345 sizeof(struct lpfc_name
));
347 memcpy(&vport
->fc_sparam
.portName
, &vport
->fc_portname
,
348 sizeof(struct lpfc_name
));
352 * lpfc_config_port_post - Perform lpfc initialization after config port
353 * @phba: pointer to lpfc hba data structure.
355 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
356 * command call. It performs all internal resource and state setups on the
357 * port: post IOCB buffers, enable appropriate host interrupt attentions,
358 * ELS ring timers, etc.
362 * Any other value - error.
365 lpfc_config_port_post(struct lpfc_hba
*phba
)
367 struct lpfc_vport
*vport
= phba
->pport
;
368 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
371 struct lpfc_dmabuf
*mp
;
372 struct lpfc_sli
*psli
= &phba
->sli
;
373 uint32_t status
, timeout
;
377 spin_lock_irq(&phba
->hbalock
);
379 * If the Config port completed correctly the HBA is not
380 * over heated any more.
382 if (phba
->over_temp_state
== HBA_OVER_TEMP
)
383 phba
->over_temp_state
= HBA_NORMAL_TEMP
;
384 spin_unlock_irq(&phba
->hbalock
);
386 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
388 phba
->link_state
= LPFC_HBA_ERROR
;
393 /* Get login parameters for NID. */
394 rc
= lpfc_read_sparam(phba
, pmb
, 0);
396 mempool_free(pmb
, phba
->mbox_mem_pool
);
401 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
402 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
403 "0448 Adapter failed init, mbxCmd x%x "
404 "READ_SPARM mbxStatus x%x\n",
405 mb
->mbxCommand
, mb
->mbxStatus
);
406 phba
->link_state
= LPFC_HBA_ERROR
;
407 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
408 mempool_free(pmb
, phba
->mbox_mem_pool
);
409 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
414 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
416 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof (struct serv_parm
));
417 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
419 pmb
->context1
= NULL
;
420 lpfc_update_vport_wwn(vport
);
422 /* Update the fc_host data structures with new wwn. */
423 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
424 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
425 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
427 /* If no serial number in VPD data, use low 6 bytes of WWNN */
428 /* This should be consolidated into parse_vpd ? - mr */
429 if (phba
->SerialNumber
[0] == 0) {
432 outptr
= &vport
->fc_nodename
.u
.s
.IEEE
[0];
433 for (i
= 0; i
< 12; i
++) {
435 j
= ((status
& 0xf0) >> 4);
437 phba
->SerialNumber
[i
] =
438 (char)((uint8_t) 0x30 + (uint8_t) j
);
440 phba
->SerialNumber
[i
] =
441 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
445 phba
->SerialNumber
[i
] =
446 (char)((uint8_t) 0x30 + (uint8_t) j
);
448 phba
->SerialNumber
[i
] =
449 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
453 lpfc_read_config(phba
, pmb
);
455 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
456 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
457 "0453 Adapter failed to init, mbxCmd x%x "
458 "READ_CONFIG, mbxStatus x%x\n",
459 mb
->mbxCommand
, mb
->mbxStatus
);
460 phba
->link_state
= LPFC_HBA_ERROR
;
461 mempool_free( pmb
, phba
->mbox_mem_pool
);
465 /* Check if the port is disabled */
466 lpfc_sli_read_link_ste(phba
);
468 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
469 if (phba
->cfg_hba_queue_depth
> (mb
->un
.varRdConfig
.max_xri
+1))
470 phba
->cfg_hba_queue_depth
=
471 (mb
->un
.varRdConfig
.max_xri
+ 1) -
472 lpfc_sli4_get_els_iocb_cnt(phba
);
474 phba
->lmt
= mb
->un
.varRdConfig
.lmt
;
476 /* Get the default values for Model Name and Description */
477 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
479 if ((phba
->cfg_link_speed
> LPFC_USER_LINK_SPEED_16G
)
480 || ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_1G
)
481 && !(phba
->lmt
& LMT_1Gb
))
482 || ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_2G
)
483 && !(phba
->lmt
& LMT_2Gb
))
484 || ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_4G
)
485 && !(phba
->lmt
& LMT_4Gb
))
486 || ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_8G
)
487 && !(phba
->lmt
& LMT_8Gb
))
488 || ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_10G
)
489 && !(phba
->lmt
& LMT_10Gb
))
490 || ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_16G
)
491 && !(phba
->lmt
& LMT_16Gb
))) {
492 /* Reset link speed to auto */
493 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
494 "1302 Invalid speed for this board: "
495 "Reset link speed to auto: x%x\n",
496 phba
->cfg_link_speed
);
497 phba
->cfg_link_speed
= LPFC_USER_LINK_SPEED_AUTO
;
500 phba
->link_state
= LPFC_LINK_DOWN
;
502 /* Only process IOCBs on ELS ring till hba_state is READY */
503 if (psli
->ring
[psli
->extra_ring
].cmdringaddr
)
504 psli
->ring
[psli
->extra_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
505 if (psli
->ring
[psli
->fcp_ring
].cmdringaddr
)
506 psli
->ring
[psli
->fcp_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
507 if (psli
->ring
[psli
->next_ring
].cmdringaddr
)
508 psli
->ring
[psli
->next_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
510 /* Post receive buffers for desired rings */
511 if (phba
->sli_rev
!= 3)
512 lpfc_post_rcv_buf(phba
);
515 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
517 if (phba
->intr_type
== MSIX
) {
518 rc
= lpfc_config_msi(phba
, pmb
);
520 mempool_free(pmb
, phba
->mbox_mem_pool
);
523 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
524 if (rc
!= MBX_SUCCESS
) {
525 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
526 "0352 Config MSI mailbox command "
527 "failed, mbxCmd x%x, mbxStatus x%x\n",
528 pmb
->u
.mb
.mbxCommand
,
529 pmb
->u
.mb
.mbxStatus
);
530 mempool_free(pmb
, phba
->mbox_mem_pool
);
535 spin_lock_irq(&phba
->hbalock
);
536 /* Initialize ERATT handling flag */
537 phba
->hba_flag
&= ~HBA_ERATT_HANDLED
;
539 /* Enable appropriate host interrupts */
540 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
541 spin_unlock_irq(&phba
->hbalock
);
544 status
|= HC_MBINT_ENA
| HC_ERINT_ENA
| HC_LAINT_ENA
;
545 if (psli
->num_rings
> 0)
546 status
|= HC_R0INT_ENA
;
547 if (psli
->num_rings
> 1)
548 status
|= HC_R1INT_ENA
;
549 if (psli
->num_rings
> 2)
550 status
|= HC_R2INT_ENA
;
551 if (psli
->num_rings
> 3)
552 status
|= HC_R3INT_ENA
;
554 if ((phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) &&
555 (phba
->cfg_poll
& DISABLE_FCP_RING_INT
))
556 status
&= ~(HC_R0INT_ENA
);
558 writel(status
, phba
->HCregaddr
);
559 readl(phba
->HCregaddr
); /* flush */
560 spin_unlock_irq(&phba
->hbalock
);
562 /* Set up ring-0 (ELS) timer */
563 timeout
= phba
->fc_ratov
* 2;
564 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
565 /* Set up heart beat (HB) timer */
566 mod_timer(&phba
->hb_tmofunc
, jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
567 phba
->hb_outstanding
= 0;
568 phba
->last_completion_time
= jiffies
;
569 /* Set up error attention (ERATT) polling timer */
570 mod_timer(&phba
->eratt_poll
, jiffies
+ HZ
* LPFC_ERATT_POLL_INTERVAL
);
572 if (phba
->hba_flag
& LINK_DISABLED
) {
573 lpfc_printf_log(phba
,
575 "2598 Adapter Link is disabled.\n");
576 lpfc_down_link(phba
, pmb
);
577 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
578 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
579 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
580 lpfc_printf_log(phba
,
582 "2599 Adapter failed to issue DOWN_LINK"
583 " mbox command rc 0x%x\n", rc
);
585 mempool_free(pmb
, phba
->mbox_mem_pool
);
588 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
589 lpfc_init_link(phba
, pmb
, phba
->cfg_topology
,
590 phba
->cfg_link_speed
);
591 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
592 lpfc_set_loopback_flag(phba
);
593 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
594 if (rc
!= MBX_SUCCESS
) {
595 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
596 "0454 Adapter failed to init, mbxCmd x%x "
597 "INIT_LINK, mbxStatus x%x\n",
598 mb
->mbxCommand
, mb
->mbxStatus
);
600 /* Clear all interrupt enable conditions */
601 writel(0, phba
->HCregaddr
);
602 readl(phba
->HCregaddr
); /* flush */
603 /* Clear all pending interrupts */
604 writel(0xffffffff, phba
->HAregaddr
);
605 readl(phba
->HAregaddr
); /* flush */
606 phba
->link_state
= LPFC_HBA_ERROR
;
608 mempool_free(pmb
, phba
->mbox_mem_pool
);
612 /* MBOX buffer will be freed in mbox compl */
613 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
615 phba
->link_state
= LPFC_HBA_ERROR
;
619 lpfc_config_async(phba
, pmb
, LPFC_ELS_RING
);
620 pmb
->mbox_cmpl
= lpfc_config_async_cmpl
;
621 pmb
->vport
= phba
->pport
;
622 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
624 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
625 lpfc_printf_log(phba
,
628 "0456 Adapter failed to issue "
629 "ASYNCEVT_ENABLE mbox status x%x\n",
631 mempool_free(pmb
, phba
->mbox_mem_pool
);
634 /* Get Option rom version */
635 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
637 phba
->link_state
= LPFC_HBA_ERROR
;
641 lpfc_dump_wakeup_param(phba
, pmb
);
642 pmb
->mbox_cmpl
= lpfc_dump_wakeup_param_cmpl
;
643 pmb
->vport
= phba
->pport
;
644 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
646 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
647 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
, "0435 Adapter failed "
648 "to get Option ROM version status x%x\n", rc
);
649 mempool_free(pmb
, phba
->mbox_mem_pool
);
656 * lpfc_hba_init_link - Initialize the FC link
657 * @phba: pointer to lpfc hba data structure.
658 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
660 * This routine will issue the INIT_LINK mailbox command call.
661 * It is available to other drivers through the lpfc_hba data
662 * structure for use as a delayed link up mechanism with the
663 * module parameter lpfc_suppress_link_up.
667 * Any other value - error
670 lpfc_hba_init_link(struct lpfc_hba
*phba
, uint32_t flag
)
672 struct lpfc_vport
*vport
= phba
->pport
;
677 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
679 phba
->link_state
= LPFC_HBA_ERROR
;
685 lpfc_init_link(phba
, pmb
, phba
->cfg_topology
, phba
->cfg_link_speed
);
686 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
687 lpfc_set_loopback_flag(phba
);
688 rc
= lpfc_sli_issue_mbox(phba
, pmb
, flag
);
689 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
690 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
691 "0498 Adapter failed to init, mbxCmd x%x "
692 "INIT_LINK, mbxStatus x%x\n",
693 mb
->mbxCommand
, mb
->mbxStatus
);
694 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
695 /* Clear all interrupt enable conditions */
696 writel(0, phba
->HCregaddr
);
697 readl(phba
->HCregaddr
); /* flush */
698 /* Clear all pending interrupts */
699 writel(0xffffffff, phba
->HAregaddr
);
700 readl(phba
->HAregaddr
); /* flush */
702 phba
->link_state
= LPFC_HBA_ERROR
;
703 if (rc
!= MBX_BUSY
|| flag
== MBX_POLL
)
704 mempool_free(pmb
, phba
->mbox_mem_pool
);
707 phba
->cfg_suppress_link_up
= LPFC_INITIALIZE_LINK
;
708 if (flag
== MBX_POLL
)
709 mempool_free(pmb
, phba
->mbox_mem_pool
);
715 * lpfc_hba_down_link - this routine downs the FC link
716 * @phba: pointer to lpfc hba data structure.
717 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
719 * This routine will issue the DOWN_LINK mailbox command call.
720 * It is available to other drivers through the lpfc_hba data
721 * structure for use to stop the link.
725 * Any other value - error
728 lpfc_hba_down_link(struct lpfc_hba
*phba
, uint32_t flag
)
733 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
735 phba
->link_state
= LPFC_HBA_ERROR
;
739 lpfc_printf_log(phba
,
741 "0491 Adapter Link is disabled.\n");
742 lpfc_down_link(phba
, pmb
);
743 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
744 rc
= lpfc_sli_issue_mbox(phba
, pmb
, flag
);
745 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
746 lpfc_printf_log(phba
,
748 "2522 Adapter failed to issue DOWN_LINK"
749 " mbox command rc 0x%x\n", rc
);
751 mempool_free(pmb
, phba
->mbox_mem_pool
);
754 if (flag
== MBX_POLL
)
755 mempool_free(pmb
, phba
->mbox_mem_pool
);
761 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
762 * @phba: pointer to lpfc HBA data structure.
764 * This routine will do LPFC uninitialization before the HBA is reset when
765 * bringing down the SLI Layer.
769 * Any other value - error.
772 lpfc_hba_down_prep(struct lpfc_hba
*phba
)
774 struct lpfc_vport
**vports
;
777 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
778 /* Disable interrupts */
779 writel(0, phba
->HCregaddr
);
780 readl(phba
->HCregaddr
); /* flush */
783 if (phba
->pport
->load_flag
& FC_UNLOADING
)
784 lpfc_cleanup_discovery_resources(phba
->pport
);
786 vports
= lpfc_create_vport_work_array(phba
);
788 for (i
= 0; i
<= phba
->max_vports
&&
789 vports
[i
] != NULL
; i
++)
790 lpfc_cleanup_discovery_resources(vports
[i
]);
791 lpfc_destroy_vport_work_array(phba
, vports
);
797 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
798 * @phba: pointer to lpfc HBA data structure.
800 * This routine will do uninitialization after the HBA is reset when bring
801 * down the SLI Layer.
805 * Any other value - error.
808 lpfc_hba_down_post_s3(struct lpfc_hba
*phba
)
810 struct lpfc_sli
*psli
= &phba
->sli
;
811 struct lpfc_sli_ring
*pring
;
812 struct lpfc_dmabuf
*mp
, *next_mp
;
813 LIST_HEAD(completions
);
816 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
817 lpfc_sli_hbqbuf_free_all(phba
);
819 /* Cleanup preposted buffers on the ELS ring */
820 pring
= &psli
->ring
[LPFC_ELS_RING
];
821 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
823 pring
->postbufq_cnt
--;
824 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
829 spin_lock_irq(&phba
->hbalock
);
830 for (i
= 0; i
< psli
->num_rings
; i
++) {
831 pring
= &psli
->ring
[i
];
833 /* At this point in time the HBA is either reset or DOA. Either
834 * way, nothing should be on txcmplq as it will NEVER complete.
836 list_splice_init(&pring
->txcmplq
, &completions
);
837 pring
->txcmplq_cnt
= 0;
838 spin_unlock_irq(&phba
->hbalock
);
840 /* Cancel all the IOCBs from the completions list */
841 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
844 lpfc_sli_abort_iocb_ring(phba
, pring
);
845 spin_lock_irq(&phba
->hbalock
);
847 spin_unlock_irq(&phba
->hbalock
);
853 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
854 * @phba: pointer to lpfc HBA data structure.
856 * This routine will do uninitialization after the HBA is reset when bring
857 * down the SLI Layer.
861 * Any other value - error.
864 lpfc_hba_down_post_s4(struct lpfc_hba
*phba
)
866 struct lpfc_scsi_buf
*psb
, *psb_next
;
869 unsigned long iflag
= 0;
870 struct lpfc_sglq
*sglq_entry
= NULL
;
872 ret
= lpfc_hba_down_post_s3(phba
);
875 /* At this point in time the HBA is either reset or DOA. Either
876 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
877 * on the lpfc_sgl_list so that it can either be freed if the
878 * driver is unloading or reposted if the driver is restarting
881 spin_lock_irq(&phba
->hbalock
); /* required for lpfc_sgl_list and */
883 /* abts_sgl_list_lock required because worker thread uses this
886 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
887 list_for_each_entry(sglq_entry
,
888 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
)
889 sglq_entry
->state
= SGL_FREED
;
891 list_splice_init(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
,
892 &phba
->sli4_hba
.lpfc_sgl_list
);
893 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
894 /* abts_scsi_buf_list_lock required because worker thread uses this
897 spin_lock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
898 list_splice_init(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
,
900 spin_unlock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
901 spin_unlock_irq(&phba
->hbalock
);
903 list_for_each_entry_safe(psb
, psb_next
, &aborts
, list
) {
905 psb
->status
= IOSTAT_SUCCESS
;
907 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
908 list_splice(&aborts
, &phba
->lpfc_scsi_buf_list
);
909 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
914 * lpfc_hba_down_post - Wrapper func for hba down post routine
915 * @phba: pointer to lpfc HBA data structure.
917 * This routine wraps the actual SLI3 or SLI4 routine for performing
918 * uninitialization after the HBA is reset when bring down the SLI Layer.
922 * Any other value - error.
925 lpfc_hba_down_post(struct lpfc_hba
*phba
)
927 return (*phba
->lpfc_hba_down_post
)(phba
);
931 * lpfc_hb_timeout - The HBA-timer timeout handler
932 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
934 * This is the HBA-timer timeout handler registered to the lpfc driver. When
935 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
936 * work-port-events bitmap and the worker thread is notified. This timeout
937 * event will be used by the worker thread to invoke the actual timeout
938 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
939 * be performed in the timeout handler and the HBA timeout event bit shall
940 * be cleared by the worker thread after it has taken the event bitmap out.
943 lpfc_hb_timeout(unsigned long ptr
)
945 struct lpfc_hba
*phba
;
949 phba
= (struct lpfc_hba
*)ptr
;
951 /* Check for heart beat timeout conditions */
952 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
953 tmo_posted
= phba
->pport
->work_port_events
& WORKER_HB_TMO
;
955 phba
->pport
->work_port_events
|= WORKER_HB_TMO
;
956 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
958 /* Tell the worker thread there is work to do */
960 lpfc_worker_wake_up(phba
);
965 * lpfc_rrq_timeout - The RRQ-timer timeout handler
966 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
968 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
969 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
970 * work-port-events bitmap and the worker thread is notified. This timeout
971 * event will be used by the worker thread to invoke the actual timeout
972 * handler routine, lpfc_rrq_handler. Any periodical operations will
973 * be performed in the timeout handler and the RRQ timeout event bit shall
974 * be cleared by the worker thread after it has taken the event bitmap out.
977 lpfc_rrq_timeout(unsigned long ptr
)
979 struct lpfc_hba
*phba
;
982 phba
= (struct lpfc_hba
*)ptr
;
983 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
984 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
985 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
986 lpfc_worker_wake_up(phba
);
990 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
991 * @phba: pointer to lpfc hba data structure.
992 * @pmboxq: pointer to the driver internal queue element for mailbox command.
994 * This is the callback function to the lpfc heart-beat mailbox command.
995 * If configured, the lpfc driver issues the heart-beat mailbox command to
996 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
997 * heart-beat mailbox command is issued, the driver shall set up heart-beat
998 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
999 * heart-beat outstanding state. Once the mailbox command comes back and
1000 * no error conditions detected, the heart-beat mailbox command timer is
1001 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1002 * state is cleared for the next heart-beat. If the timer expired with the
1003 * heart-beat outstanding state set, the driver will put the HBA offline.
1006 lpfc_hb_mbox_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
1008 unsigned long drvr_flag
;
1010 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
1011 phba
->hb_outstanding
= 0;
1012 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
1014 /* Check and reset heart-beat timer is necessary */
1015 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1016 if (!(phba
->pport
->fc_flag
& FC_OFFLINE_MODE
) &&
1017 !(phba
->link_state
== LPFC_HBA_ERROR
) &&
1018 !(phba
->pport
->load_flag
& FC_UNLOADING
))
1019 mod_timer(&phba
->hb_tmofunc
,
1020 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
1025 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1026 * @phba: pointer to lpfc hba data structure.
1028 * This is the actual HBA-timer timeout handler to be invoked by the worker
1029 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1030 * handler performs any periodic operations needed for the device. If such
1031 * periodic event has already been attended to either in the interrupt handler
1032 * or by processing slow-ring or fast-ring events within the HBA-timer
1033 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1034 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1035 * is configured and there is no heart-beat mailbox command outstanding, a
1036 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1037 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1041 lpfc_hb_timeout_handler(struct lpfc_hba
*phba
)
1043 struct lpfc_vport
**vports
;
1044 LPFC_MBOXQ_t
*pmboxq
;
1045 struct lpfc_dmabuf
*buf_ptr
;
1047 struct lpfc_sli
*psli
= &phba
->sli
;
1048 LIST_HEAD(completions
);
1050 vports
= lpfc_create_vport_work_array(phba
);
1052 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
1053 lpfc_rcv_seq_check_edtov(vports
[i
]);
1054 lpfc_destroy_vport_work_array(phba
, vports
);
1056 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
1057 (phba
->pport
->load_flag
& FC_UNLOADING
) ||
1058 (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
))
1061 spin_lock_irq(&phba
->pport
->work_port_lock
);
1063 if (time_after(phba
->last_completion_time
+ LPFC_HB_MBOX_INTERVAL
* HZ
,
1065 spin_unlock_irq(&phba
->pport
->work_port_lock
);
1066 if (!phba
->hb_outstanding
)
1067 mod_timer(&phba
->hb_tmofunc
,
1068 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
1070 mod_timer(&phba
->hb_tmofunc
,
1071 jiffies
+ HZ
* LPFC_HB_MBOX_TIMEOUT
);
1074 spin_unlock_irq(&phba
->pport
->work_port_lock
);
1076 if (phba
->elsbuf_cnt
&&
1077 (phba
->elsbuf_cnt
== phba
->elsbuf_prev_cnt
)) {
1078 spin_lock_irq(&phba
->hbalock
);
1079 list_splice_init(&phba
->elsbuf
, &completions
);
1080 phba
->elsbuf_cnt
= 0;
1081 phba
->elsbuf_prev_cnt
= 0;
1082 spin_unlock_irq(&phba
->hbalock
);
1084 while (!list_empty(&completions
)) {
1085 list_remove_head(&completions
, buf_ptr
,
1086 struct lpfc_dmabuf
, list
);
1087 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
1091 phba
->elsbuf_prev_cnt
= phba
->elsbuf_cnt
;
1093 /* If there is no heart beat outstanding, issue a heartbeat command */
1094 if (phba
->cfg_enable_hba_heartbeat
) {
1095 if (!phba
->hb_outstanding
) {
1096 if ((!(psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
)) &&
1097 (list_empty(&psli
->mboxq
))) {
1098 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,
1101 mod_timer(&phba
->hb_tmofunc
,
1103 HZ
* LPFC_HB_MBOX_INTERVAL
);
1107 lpfc_heart_beat(phba
, pmboxq
);
1108 pmboxq
->mbox_cmpl
= lpfc_hb_mbox_cmpl
;
1109 pmboxq
->vport
= phba
->pport
;
1110 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
,
1113 if (retval
!= MBX_BUSY
&&
1114 retval
!= MBX_SUCCESS
) {
1115 mempool_free(pmboxq
,
1116 phba
->mbox_mem_pool
);
1117 mod_timer(&phba
->hb_tmofunc
,
1119 HZ
* LPFC_HB_MBOX_INTERVAL
);
1122 phba
->skipped_hb
= 0;
1123 phba
->hb_outstanding
= 1;
1124 } else if (time_before_eq(phba
->last_completion_time
,
1125 phba
->skipped_hb
)) {
1126 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1127 "2857 Last completion time not "
1128 " updated in %d ms\n",
1129 jiffies_to_msecs(jiffies
1130 - phba
->last_completion_time
));
1132 phba
->skipped_hb
= jiffies
;
1134 mod_timer(&phba
->hb_tmofunc
,
1135 jiffies
+ HZ
* LPFC_HB_MBOX_TIMEOUT
);
1139 * If heart beat timeout called with hb_outstanding set
1140 * we need to give the hb mailbox cmd a chance to
1143 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
1144 "0459 Adapter heartbeat still out"
1145 "standing:last compl time was %d ms.\n",
1146 jiffies_to_msecs(jiffies
1147 - phba
->last_completion_time
));
1148 mod_timer(&phba
->hb_tmofunc
,
1149 jiffies
+ HZ
* LPFC_HB_MBOX_TIMEOUT
);
1155 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1156 * @phba: pointer to lpfc hba data structure.
1158 * This routine is called to bring the HBA offline when HBA hardware error
1159 * other than Port Error 6 has been detected.
1162 lpfc_offline_eratt(struct lpfc_hba
*phba
)
1164 struct lpfc_sli
*psli
= &phba
->sli
;
1166 spin_lock_irq(&phba
->hbalock
);
1167 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1168 spin_unlock_irq(&phba
->hbalock
);
1169 lpfc_offline_prep(phba
);
1172 lpfc_reset_barrier(phba
);
1173 spin_lock_irq(&phba
->hbalock
);
1174 lpfc_sli_brdreset(phba
);
1175 spin_unlock_irq(&phba
->hbalock
);
1176 lpfc_hba_down_post(phba
);
1177 lpfc_sli_brdready(phba
, HS_MBRDY
);
1178 lpfc_unblock_mgmt_io(phba
);
1179 phba
->link_state
= LPFC_HBA_ERROR
;
1184 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1185 * @phba: pointer to lpfc hba data structure.
1187 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1188 * other than Port Error 6 has been detected.
1191 lpfc_sli4_offline_eratt(struct lpfc_hba
*phba
)
1193 lpfc_offline_prep(phba
);
1195 lpfc_sli4_brdreset(phba
);
1196 lpfc_hba_down_post(phba
);
1197 lpfc_sli4_post_status_check(phba
);
1198 lpfc_unblock_mgmt_io(phba
);
1199 phba
->link_state
= LPFC_HBA_ERROR
;
1203 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1204 * @phba: pointer to lpfc hba data structure.
1206 * This routine is invoked to handle the deferred HBA hardware error
1207 * conditions. This type of error is indicated by HBA by setting ER1
1208 * and another ER bit in the host status register. The driver will
1209 * wait until the ER1 bit clears before handling the error condition.
1212 lpfc_handle_deferred_eratt(struct lpfc_hba
*phba
)
1214 uint32_t old_host_status
= phba
->work_hs
;
1215 struct lpfc_sli_ring
*pring
;
1216 struct lpfc_sli
*psli
= &phba
->sli
;
1218 /* If the pci channel is offline, ignore possible errors,
1219 * since we cannot communicate with the pci card anyway.
1221 if (pci_channel_offline(phba
->pcidev
)) {
1222 spin_lock_irq(&phba
->hbalock
);
1223 phba
->hba_flag
&= ~DEFER_ERATT
;
1224 spin_unlock_irq(&phba
->hbalock
);
1228 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1229 "0479 Deferred Adapter Hardware Error "
1230 "Data: x%x x%x x%x\n",
1232 phba
->work_status
[0], phba
->work_status
[1]);
1234 spin_lock_irq(&phba
->hbalock
);
1235 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1236 spin_unlock_irq(&phba
->hbalock
);
1240 * Firmware stops when it triggred erratt. That could cause the I/Os
1241 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1242 * SCSI layer retry it after re-establishing link.
1244 pring
= &psli
->ring
[psli
->fcp_ring
];
1245 lpfc_sli_abort_iocb_ring(phba
, pring
);
1248 * There was a firmware error. Take the hba offline and then
1249 * attempt to restart it.
1251 lpfc_offline_prep(phba
);
1254 /* Wait for the ER1 bit to clear.*/
1255 while (phba
->work_hs
& HS_FFER1
) {
1257 if (lpfc_readl(phba
->HSregaddr
, &phba
->work_hs
)) {
1258 phba
->work_hs
= UNPLUG_ERR
;
1261 /* If driver is unloading let the worker thread continue */
1262 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
1269 * This is to ptrotect against a race condition in which
1270 * first write to the host attention register clear the
1271 * host status register.
1273 if ((!phba
->work_hs
) && (!(phba
->pport
->load_flag
& FC_UNLOADING
)))
1274 phba
->work_hs
= old_host_status
& ~HS_FFER1
;
1276 spin_lock_irq(&phba
->hbalock
);
1277 phba
->hba_flag
&= ~DEFER_ERATT
;
1278 spin_unlock_irq(&phba
->hbalock
);
1279 phba
->work_status
[0] = readl(phba
->MBslimaddr
+ 0xa8);
1280 phba
->work_status
[1] = readl(phba
->MBslimaddr
+ 0xac);
1284 lpfc_board_errevt_to_mgmt(struct lpfc_hba
*phba
)
1286 struct lpfc_board_event_header board_event
;
1287 struct Scsi_Host
*shost
;
1289 board_event
.event_type
= FC_REG_BOARD_EVENT
;
1290 board_event
.subcategory
= LPFC_EVENT_PORTINTERR
;
1291 shost
= lpfc_shost_from_vport(phba
->pport
);
1292 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1293 sizeof(board_event
),
1294 (char *) &board_event
,
1299 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1300 * @phba: pointer to lpfc hba data structure.
1302 * This routine is invoked to handle the following HBA hardware error
1304 * 1 - HBA error attention interrupt
1305 * 2 - DMA ring index out of range
1306 * 3 - Mailbox command came back as unknown
1309 lpfc_handle_eratt_s3(struct lpfc_hba
*phba
)
1311 struct lpfc_vport
*vport
= phba
->pport
;
1312 struct lpfc_sli
*psli
= &phba
->sli
;
1313 struct lpfc_sli_ring
*pring
;
1314 uint32_t event_data
;
1315 unsigned long temperature
;
1316 struct temp_event temp_event_data
;
1317 struct Scsi_Host
*shost
;
1319 /* If the pci channel is offline, ignore possible errors,
1320 * since we cannot communicate with the pci card anyway.
1322 if (pci_channel_offline(phba
->pcidev
)) {
1323 spin_lock_irq(&phba
->hbalock
);
1324 phba
->hba_flag
&= ~DEFER_ERATT
;
1325 spin_unlock_irq(&phba
->hbalock
);
1329 /* If resets are disabled then leave the HBA alone and return */
1330 if (!phba
->cfg_enable_hba_reset
)
1333 /* Send an internal error event to mgmt application */
1334 lpfc_board_errevt_to_mgmt(phba
);
1336 if (phba
->hba_flag
& DEFER_ERATT
)
1337 lpfc_handle_deferred_eratt(phba
);
1339 if ((phba
->work_hs
& HS_FFER6
) || (phba
->work_hs
& HS_FFER8
)) {
1340 if (phba
->work_hs
& HS_FFER6
)
1341 /* Re-establishing Link */
1342 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1343 "1301 Re-establishing Link "
1344 "Data: x%x x%x x%x\n",
1345 phba
->work_hs
, phba
->work_status
[0],
1346 phba
->work_status
[1]);
1347 if (phba
->work_hs
& HS_FFER8
)
1348 /* Device Zeroization */
1349 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1350 "2861 Host Authentication device "
1351 "zeroization Data:x%x x%x x%x\n",
1352 phba
->work_hs
, phba
->work_status
[0],
1353 phba
->work_status
[1]);
1355 spin_lock_irq(&phba
->hbalock
);
1356 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1357 spin_unlock_irq(&phba
->hbalock
);
1360 * Firmware stops when it triggled erratt with HS_FFER6.
1361 * That could cause the I/Os dropped by the firmware.
1362 * Error iocb (I/O) on txcmplq and let the SCSI layer
1363 * retry it after re-establishing link.
1365 pring
= &psli
->ring
[psli
->fcp_ring
];
1366 lpfc_sli_abort_iocb_ring(phba
, pring
);
1369 * There was a firmware error. Take the hba offline and then
1370 * attempt to restart it.
1372 lpfc_offline_prep(phba
);
1374 lpfc_sli_brdrestart(phba
);
1375 if (lpfc_online(phba
) == 0) { /* Initialize the HBA */
1376 lpfc_unblock_mgmt_io(phba
);
1379 lpfc_unblock_mgmt_io(phba
);
1380 } else if (phba
->work_hs
& HS_CRIT_TEMP
) {
1381 temperature
= readl(phba
->MBslimaddr
+ TEMPERATURE_OFFSET
);
1382 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
1383 temp_event_data
.event_code
= LPFC_CRIT_TEMP
;
1384 temp_event_data
.data
= (uint32_t)temperature
;
1386 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1387 "0406 Adapter maximum temperature exceeded "
1388 "(%ld), taking this port offline "
1389 "Data: x%x x%x x%x\n",
1390 temperature
, phba
->work_hs
,
1391 phba
->work_status
[0], phba
->work_status
[1]);
1393 shost
= lpfc_shost_from_vport(phba
->pport
);
1394 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1395 sizeof(temp_event_data
),
1396 (char *) &temp_event_data
,
1397 SCSI_NL_VID_TYPE_PCI
1398 | PCI_VENDOR_ID_EMULEX
);
1400 spin_lock_irq(&phba
->hbalock
);
1401 phba
->over_temp_state
= HBA_OVER_TEMP
;
1402 spin_unlock_irq(&phba
->hbalock
);
1403 lpfc_offline_eratt(phba
);
1406 /* The if clause above forces this code path when the status
1407 * failure is a value other than FFER6. Do not call the offline
1408 * twice. This is the adapter hardware error path.
1410 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1411 "0457 Adapter Hardware Error "
1412 "Data: x%x x%x x%x\n",
1414 phba
->work_status
[0], phba
->work_status
[1]);
1416 event_data
= FC_REG_DUMP_EVENT
;
1417 shost
= lpfc_shost_from_vport(vport
);
1418 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1419 sizeof(event_data
), (char *) &event_data
,
1420 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
1422 lpfc_offline_eratt(phba
);
1428 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1429 * @phba: pointer to lpfc hba data structure.
1431 * This routine is invoked to handle the SLI4 HBA hardware error attention
1435 lpfc_handle_eratt_s4(struct lpfc_hba
*phba
)
1437 struct lpfc_vport
*vport
= phba
->pport
;
1438 uint32_t event_data
;
1439 struct Scsi_Host
*shost
;
1441 struct lpfc_register portstat_reg
;
1443 /* If the pci channel is offline, ignore possible errors, since
1444 * we cannot communicate with the pci card anyway.
1446 if (pci_channel_offline(phba
->pcidev
))
1448 /* If resets are disabled then leave the HBA alone and return */
1449 if (!phba
->cfg_enable_hba_reset
)
1452 /* Send an internal error event to mgmt application */
1453 lpfc_board_errevt_to_mgmt(phba
);
1455 /* For now, the actual action for SLI4 device handling is not
1456 * specified yet, just treated it as adaptor hardware failure
1458 event_data
= FC_REG_DUMP_EVENT
;
1459 shost
= lpfc_shost_from_vport(vport
);
1460 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1461 sizeof(event_data
), (char *) &event_data
,
1462 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
1464 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
1466 case LPFC_SLI_INTF_IF_TYPE_0
:
1467 lpfc_sli4_offline_eratt(phba
);
1469 case LPFC_SLI_INTF_IF_TYPE_2
:
1470 portstat_reg
.word0
=
1471 readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
);
1473 if (bf_get(lpfc_sliport_status_oti
, &portstat_reg
)) {
1474 /* TODO: Register for Overtemp async events. */
1475 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1476 "2889 Port Overtemperature event, "
1478 spin_lock_irq(&phba
->hbalock
);
1479 phba
->over_temp_state
= HBA_OVER_TEMP
;
1480 spin_unlock_irq(&phba
->hbalock
);
1481 lpfc_sli4_offline_eratt(phba
);
1484 if (bf_get(lpfc_sliport_status_rn
, &portstat_reg
)) {
1486 * TODO: Attempt port recovery via a port reset.
1487 * When fully implemented, the driver should
1488 * attempt to recover the port here and return.
1489 * For now, log an error and take the port offline.
1491 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1492 "2887 Port Error: Attempting "
1495 lpfc_sli4_offline_eratt(phba
);
1497 case LPFC_SLI_INTF_IF_TYPE_1
:
1504 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1505 * @phba: pointer to lpfc HBA data structure.
1507 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1508 * routine from the API jump table function pointer from the lpfc_hba struct.
1512 * Any other value - error.
1515 lpfc_handle_eratt(struct lpfc_hba
*phba
)
1517 (*phba
->lpfc_handle_eratt
)(phba
);
1521 * lpfc_handle_latt - The HBA link event handler
1522 * @phba: pointer to lpfc hba data structure.
1524 * This routine is invoked from the worker thread to handle a HBA host
1525 * attention link event.
1528 lpfc_handle_latt(struct lpfc_hba
*phba
)
1530 struct lpfc_vport
*vport
= phba
->pport
;
1531 struct lpfc_sli
*psli
= &phba
->sli
;
1533 volatile uint32_t control
;
1534 struct lpfc_dmabuf
*mp
;
1537 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1540 goto lpfc_handle_latt_err_exit
;
1543 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1546 goto lpfc_handle_latt_free_pmb
;
1549 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
1552 goto lpfc_handle_latt_free_mp
;
1555 /* Cleanup any outstanding ELS commands */
1556 lpfc_els_flush_all_cmd(phba
);
1558 psli
->slistat
.link_event
++;
1559 lpfc_read_topology(phba
, pmb
, mp
);
1560 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
1562 /* Block ELS IOCBs until we have processed this mbox command */
1563 phba
->sli
.ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
1564 rc
= lpfc_sli_issue_mbox (phba
, pmb
, MBX_NOWAIT
);
1565 if (rc
== MBX_NOT_FINISHED
) {
1567 goto lpfc_handle_latt_free_mbuf
;
1570 /* Clear Link Attention in HA REG */
1571 spin_lock_irq(&phba
->hbalock
);
1572 writel(HA_LATT
, phba
->HAregaddr
);
1573 readl(phba
->HAregaddr
); /* flush */
1574 spin_unlock_irq(&phba
->hbalock
);
1578 lpfc_handle_latt_free_mbuf
:
1579 phba
->sli
.ring
[LPFC_ELS_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1580 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1581 lpfc_handle_latt_free_mp
:
1583 lpfc_handle_latt_free_pmb
:
1584 mempool_free(pmb
, phba
->mbox_mem_pool
);
1585 lpfc_handle_latt_err_exit
:
1586 /* Enable Link attention interrupts */
1587 spin_lock_irq(&phba
->hbalock
);
1588 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1589 control
= readl(phba
->HCregaddr
);
1590 control
|= HC_LAINT_ENA
;
1591 writel(control
, phba
->HCregaddr
);
1592 readl(phba
->HCregaddr
); /* flush */
1594 /* Clear Link Attention in HA REG */
1595 writel(HA_LATT
, phba
->HAregaddr
);
1596 readl(phba
->HAregaddr
); /* flush */
1597 spin_unlock_irq(&phba
->hbalock
);
1598 lpfc_linkdown(phba
);
1599 phba
->link_state
= LPFC_HBA_ERROR
;
1601 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1602 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc
);
1608 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
1609 * @phba: pointer to lpfc hba data structure.
1610 * @vpd: pointer to the vital product data.
1611 * @len: length of the vital product data in bytes.
1613 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1614 * an array of characters. In this routine, the ModelName, ProgramType, and
1615 * ModelDesc, etc. fields of the phba data structure will be populated.
1618 * 0 - pointer to the VPD passed in is NULL
1622 lpfc_parse_vpd(struct lpfc_hba
*phba
, uint8_t *vpd
, int len
)
1624 uint8_t lenlo
, lenhi
;
1634 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1635 "0455 Vital Product Data: x%x x%x x%x x%x\n",
1636 (uint32_t) vpd
[0], (uint32_t) vpd
[1], (uint32_t) vpd
[2],
1638 while (!finished
&& (index
< (len
- 4))) {
1639 switch (vpd
[index
]) {
1647 i
= ((((unsigned short)lenhi
) << 8) + lenlo
);
1656 Length
= ((((unsigned short)lenhi
) << 8) + lenlo
);
1657 if (Length
> len
- index
)
1658 Length
= len
- index
;
1659 while (Length
> 0) {
1660 /* Look for Serial Number */
1661 if ((vpd
[index
] == 'S') && (vpd
[index
+1] == 'N')) {
1668 phba
->SerialNumber
[j
++] = vpd
[index
++];
1672 phba
->SerialNumber
[j
] = 0;
1675 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '1')) {
1676 phba
->vpd_flag
|= VPD_MODEL_DESC
;
1683 phba
->ModelDesc
[j
++] = vpd
[index
++];
1687 phba
->ModelDesc
[j
] = 0;
1690 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '2')) {
1691 phba
->vpd_flag
|= VPD_MODEL_NAME
;
1698 phba
->ModelName
[j
++] = vpd
[index
++];
1702 phba
->ModelName
[j
] = 0;
1705 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '3')) {
1706 phba
->vpd_flag
|= VPD_PROGRAM_TYPE
;
1713 phba
->ProgramType
[j
++] = vpd
[index
++];
1717 phba
->ProgramType
[j
] = 0;
1720 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '4')) {
1721 phba
->vpd_flag
|= VPD_PORT
;
1728 phba
->Port
[j
++] = vpd
[index
++];
1758 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
1759 * @phba: pointer to lpfc hba data structure.
1760 * @mdp: pointer to the data structure to hold the derived model name.
1761 * @descp: pointer to the data structure to hold the derived description.
1763 * This routine retrieves HBA's description based on its registered PCI device
1764 * ID. The @descp passed into this function points to an array of 256 chars. It
1765 * shall be returned with the model name, maximum speed, and the host bus type.
1766 * The @mdp passed into this function points to an array of 80 chars. When the
1767 * function returns, the @mdp will be filled with the model name.
1770 lpfc_get_hba_model_desc(struct lpfc_hba
*phba
, uint8_t *mdp
, uint8_t *descp
)
1773 uint16_t dev_id
= phba
->pcidev
->device
;
1776 int oneConnect
= 0; /* default is not a oneConnect */
1781 } m
= {"<Unknown>", "", ""};
1783 if (mdp
&& mdp
[0] != '\0'
1784 && descp
&& descp
[0] != '\0')
1787 if (phba
->lmt
& LMT_16Gb
)
1789 else if (phba
->lmt
& LMT_10Gb
)
1791 else if (phba
->lmt
& LMT_8Gb
)
1793 else if (phba
->lmt
& LMT_4Gb
)
1795 else if (phba
->lmt
& LMT_2Gb
)
1803 case PCI_DEVICE_ID_FIREFLY
:
1804 m
= (typeof(m
)){"LP6000", "PCI", "Fibre Channel Adapter"};
1806 case PCI_DEVICE_ID_SUPERFLY
:
1807 if (vp
->rev
.biuRev
>= 1 && vp
->rev
.biuRev
<= 3)
1808 m
= (typeof(m
)){"LP7000", "PCI",
1809 "Fibre Channel Adapter"};
1811 m
= (typeof(m
)){"LP7000E", "PCI",
1812 "Fibre Channel Adapter"};
1814 case PCI_DEVICE_ID_DRAGONFLY
:
1815 m
= (typeof(m
)){"LP8000", "PCI",
1816 "Fibre Channel Adapter"};
1818 case PCI_DEVICE_ID_CENTAUR
:
1819 if (FC_JEDEC_ID(vp
->rev
.biuRev
) == CENTAUR_2G_JEDEC_ID
)
1820 m
= (typeof(m
)){"LP9002", "PCI",
1821 "Fibre Channel Adapter"};
1823 m
= (typeof(m
)){"LP9000", "PCI",
1824 "Fibre Channel Adapter"};
1826 case PCI_DEVICE_ID_RFLY
:
1827 m
= (typeof(m
)){"LP952", "PCI",
1828 "Fibre Channel Adapter"};
1830 case PCI_DEVICE_ID_PEGASUS
:
1831 m
= (typeof(m
)){"LP9802", "PCI-X",
1832 "Fibre Channel Adapter"};
1834 case PCI_DEVICE_ID_THOR
:
1835 m
= (typeof(m
)){"LP10000", "PCI-X",
1836 "Fibre Channel Adapter"};
1838 case PCI_DEVICE_ID_VIPER
:
1839 m
= (typeof(m
)){"LPX1000", "PCI-X",
1840 "Fibre Channel Adapter"};
1842 case PCI_DEVICE_ID_PFLY
:
1843 m
= (typeof(m
)){"LP982", "PCI-X",
1844 "Fibre Channel Adapter"};
1846 case PCI_DEVICE_ID_TFLY
:
1847 m
= (typeof(m
)){"LP1050", "PCI-X",
1848 "Fibre Channel Adapter"};
1850 case PCI_DEVICE_ID_HELIOS
:
1851 m
= (typeof(m
)){"LP11000", "PCI-X2",
1852 "Fibre Channel Adapter"};
1854 case PCI_DEVICE_ID_HELIOS_SCSP
:
1855 m
= (typeof(m
)){"LP11000-SP", "PCI-X2",
1856 "Fibre Channel Adapter"};
1858 case PCI_DEVICE_ID_HELIOS_DCSP
:
1859 m
= (typeof(m
)){"LP11002-SP", "PCI-X2",
1860 "Fibre Channel Adapter"};
1862 case PCI_DEVICE_ID_NEPTUNE
:
1863 m
= (typeof(m
)){"LPe1000", "PCIe", "Fibre Channel Adapter"};
1865 case PCI_DEVICE_ID_NEPTUNE_SCSP
:
1866 m
= (typeof(m
)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"};
1868 case PCI_DEVICE_ID_NEPTUNE_DCSP
:
1869 m
= (typeof(m
)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"};
1871 case PCI_DEVICE_ID_BMID
:
1872 m
= (typeof(m
)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
1874 case PCI_DEVICE_ID_BSMB
:
1875 m
= (typeof(m
)){"LP111", "PCI-X2", "Fibre Channel Adapter"};
1877 case PCI_DEVICE_ID_ZEPHYR
:
1878 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
1880 case PCI_DEVICE_ID_ZEPHYR_SCSP
:
1881 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
1883 case PCI_DEVICE_ID_ZEPHYR_DCSP
:
1884 m
= (typeof(m
)){"LP2105", "PCIe", "FCoE Adapter"};
1887 case PCI_DEVICE_ID_ZMID
:
1888 m
= (typeof(m
)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
1890 case PCI_DEVICE_ID_ZSMB
:
1891 m
= (typeof(m
)){"LPe111", "PCIe", "Fibre Channel Adapter"};
1893 case PCI_DEVICE_ID_LP101
:
1894 m
= (typeof(m
)){"LP101", "PCI-X", "Fibre Channel Adapter"};
1896 case PCI_DEVICE_ID_LP10000S
:
1897 m
= (typeof(m
)){"LP10000-S", "PCI", "Fibre Channel Adapter"};
1899 case PCI_DEVICE_ID_LP11000S
:
1900 m
= (typeof(m
)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"};
1902 case PCI_DEVICE_ID_LPE11000S
:
1903 m
= (typeof(m
)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"};
1905 case PCI_DEVICE_ID_SAT
:
1906 m
= (typeof(m
)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
1908 case PCI_DEVICE_ID_SAT_MID
:
1909 m
= (typeof(m
)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
1911 case PCI_DEVICE_ID_SAT_SMB
:
1912 m
= (typeof(m
)){"LPe121", "PCIe", "Fibre Channel Adapter"};
1914 case PCI_DEVICE_ID_SAT_DCSP
:
1915 m
= (typeof(m
)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
1917 case PCI_DEVICE_ID_SAT_SCSP
:
1918 m
= (typeof(m
)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
1920 case PCI_DEVICE_ID_SAT_S
:
1921 m
= (typeof(m
)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
1923 case PCI_DEVICE_ID_HORNET
:
1924 m
= (typeof(m
)){"LP21000", "PCIe", "FCoE Adapter"};
1927 case PCI_DEVICE_ID_PROTEUS_VF
:
1928 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
1929 "Fibre Channel Adapter"};
1931 case PCI_DEVICE_ID_PROTEUS_PF
:
1932 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
1933 "Fibre Channel Adapter"};
1935 case PCI_DEVICE_ID_PROTEUS_S
:
1936 m
= (typeof(m
)){"LPemv12002-S", "PCIe IOV",
1937 "Fibre Channel Adapter"};
1939 case PCI_DEVICE_ID_TIGERSHARK
:
1941 m
= (typeof(m
)){"OCe10100", "PCIe", "FCoE"};
1943 case PCI_DEVICE_ID_TOMCAT
:
1945 m
= (typeof(m
)){"OCe11100", "PCIe", "FCoE"};
1947 case PCI_DEVICE_ID_FALCON
:
1948 m
= (typeof(m
)){"LPSe12002-ML1-E", "PCIe",
1949 "EmulexSecure Fibre"};
1951 case PCI_DEVICE_ID_BALIUS
:
1952 m
= (typeof(m
)){"LPVe12002", "PCIe Shared I/O",
1953 "Fibre Channel Adapter"};
1955 case PCI_DEVICE_ID_LANCER_FC
:
1956 case PCI_DEVICE_ID_LANCER_FC_VF
:
1957 m
= (typeof(m
)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
1959 case PCI_DEVICE_ID_LANCER_FCOE
:
1960 case PCI_DEVICE_ID_LANCER_FCOE_VF
:
1962 m
= (typeof(m
)){"OCe50100", "PCIe", "FCoE"};
1965 m
= (typeof(m
)){"Unknown", "", ""};
1969 if (mdp
&& mdp
[0] == '\0')
1970 snprintf(mdp
, 79,"%s", m
.name
);
1972 * oneConnect hba requires special processing, they are all initiators
1973 * and we put the port number on the end
1975 if (descp
&& descp
[0] == '\0') {
1977 snprintf(descp
, 255,
1978 "Emulex OneConnect %s, %s Initiator, Port %s",
1982 snprintf(descp
, 255,
1983 "Emulex %s %d%s %s %s",
1984 m
.name
, max_speed
, (GE
) ? "GE" : "Gb",
1990 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
1991 * @phba: pointer to lpfc hba data structure.
1992 * @pring: pointer to a IOCB ring.
1993 * @cnt: the number of IOCBs to be posted to the IOCB ring.
1995 * This routine posts a given number of IOCBs with the associated DMA buffer
1996 * descriptors specified by the cnt argument to the given IOCB ring.
1999 * The number of IOCBs NOT able to be posted to the IOCB ring.
2002 lpfc_post_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
, int cnt
)
2005 struct lpfc_iocbq
*iocb
;
2006 struct lpfc_dmabuf
*mp1
, *mp2
;
2008 cnt
+= pring
->missbufcnt
;
2010 /* While there are buffers to post */
2012 /* Allocate buffer for command iocb */
2013 iocb
= lpfc_sli_get_iocbq(phba
);
2015 pring
->missbufcnt
= cnt
;
2020 /* 2 buffers can be posted per command */
2021 /* Allocate buffer to post */
2022 mp1
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
2024 mp1
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &mp1
->phys
);
2025 if (!mp1
|| !mp1
->virt
) {
2027 lpfc_sli_release_iocbq(phba
, iocb
);
2028 pring
->missbufcnt
= cnt
;
2032 INIT_LIST_HEAD(&mp1
->list
);
2033 /* Allocate buffer to post */
2035 mp2
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
2037 mp2
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
2039 if (!mp2
|| !mp2
->virt
) {
2041 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
2043 lpfc_sli_release_iocbq(phba
, iocb
);
2044 pring
->missbufcnt
= cnt
;
2048 INIT_LIST_HEAD(&mp2
->list
);
2053 icmd
->un
.cont64
[0].addrHigh
= putPaddrHigh(mp1
->phys
);
2054 icmd
->un
.cont64
[0].addrLow
= putPaddrLow(mp1
->phys
);
2055 icmd
->un
.cont64
[0].tus
.f
.bdeSize
= FCELSSIZE
;
2056 icmd
->ulpBdeCount
= 1;
2059 icmd
->un
.cont64
[1].addrHigh
= putPaddrHigh(mp2
->phys
);
2060 icmd
->un
.cont64
[1].addrLow
= putPaddrLow(mp2
->phys
);
2061 icmd
->un
.cont64
[1].tus
.f
.bdeSize
= FCELSSIZE
;
2063 icmd
->ulpBdeCount
= 2;
2066 icmd
->ulpCommand
= CMD_QUE_RING_BUF64_CN
;
2069 if (lpfc_sli_issue_iocb(phba
, pring
->ringno
, iocb
, 0) ==
2071 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
2075 lpfc_mbuf_free(phba
, mp2
->virt
, mp2
->phys
);
2079 lpfc_sli_release_iocbq(phba
, iocb
);
2080 pring
->missbufcnt
= cnt
;
2083 lpfc_sli_ringpostbuf_put(phba
, pring
, mp1
);
2085 lpfc_sli_ringpostbuf_put(phba
, pring
, mp2
);
2087 pring
->missbufcnt
= 0;
2092 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2093 * @phba: pointer to lpfc hba data structure.
2095 * This routine posts initial receive IOCB buffers to the ELS ring. The
2096 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2100 * 0 - success (currently always success)
2103 lpfc_post_rcv_buf(struct lpfc_hba
*phba
)
2105 struct lpfc_sli
*psli
= &phba
->sli
;
2107 /* Ring 0, ELS / CT buffers */
2108 lpfc_post_buffer(phba
, &psli
->ring
[LPFC_ELS_RING
], LPFC_BUF_RING0
);
2109 /* Ring 2 - FCP no buffers needed */
2114 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2117 * lpfc_sha_init - Set up initial array of hash table entries
2118 * @HashResultPointer: pointer to an array as hash table.
2120 * This routine sets up the initial values to the array of hash table entries
2124 lpfc_sha_init(uint32_t * HashResultPointer
)
2126 HashResultPointer
[0] = 0x67452301;
2127 HashResultPointer
[1] = 0xEFCDAB89;
2128 HashResultPointer
[2] = 0x98BADCFE;
2129 HashResultPointer
[3] = 0x10325476;
2130 HashResultPointer
[4] = 0xC3D2E1F0;
2134 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2135 * @HashResultPointer: pointer to an initial/result hash table.
2136 * @HashWorkingPointer: pointer to an working hash table.
2138 * This routine iterates an initial hash table pointed by @HashResultPointer
2139 * with the values from the working hash table pointeed by @HashWorkingPointer.
2140 * The results are putting back to the initial hash table, returned through
2141 * the @HashResultPointer as the result hash table.
2144 lpfc_sha_iterate(uint32_t * HashResultPointer
, uint32_t * HashWorkingPointer
)
2148 uint32_t A
, B
, C
, D
, E
;
2151 HashWorkingPointer
[t
] =
2153 HashWorkingPointer
[t
- 3] ^ HashWorkingPointer
[t
-
2155 HashWorkingPointer
[t
- 14] ^ HashWorkingPointer
[t
- 16]);
2156 } while (++t
<= 79);
2158 A
= HashResultPointer
[0];
2159 B
= HashResultPointer
[1];
2160 C
= HashResultPointer
[2];
2161 D
= HashResultPointer
[3];
2162 E
= HashResultPointer
[4];
2166 TEMP
= ((B
& C
) | ((~B
) & D
)) + 0x5A827999;
2167 } else if (t
< 40) {
2168 TEMP
= (B
^ C
^ D
) + 0x6ED9EBA1;
2169 } else if (t
< 60) {
2170 TEMP
= ((B
& C
) | (B
& D
) | (C
& D
)) + 0x8F1BBCDC;
2172 TEMP
= (B
^ C
^ D
) + 0xCA62C1D6;
2174 TEMP
+= S(5, A
) + E
+ HashWorkingPointer
[t
];
2180 } while (++t
<= 79);
2182 HashResultPointer
[0] += A
;
2183 HashResultPointer
[1] += B
;
2184 HashResultPointer
[2] += C
;
2185 HashResultPointer
[3] += D
;
2186 HashResultPointer
[4] += E
;
2191 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2192 * @RandomChallenge: pointer to the entry of host challenge random number array.
2193 * @HashWorking: pointer to the entry of the working hash array.
2195 * This routine calculates the working hash array referred by @HashWorking
2196 * from the challenge random numbers associated with the host, referred by
2197 * @RandomChallenge. The result is put into the entry of the working hash
2198 * array and returned by reference through @HashWorking.
2201 lpfc_challenge_key(uint32_t * RandomChallenge
, uint32_t * HashWorking
)
2203 *HashWorking
= (*RandomChallenge
^ *HashWorking
);
2207 * lpfc_hba_init - Perform special handling for LC HBA initialization
2208 * @phba: pointer to lpfc hba data structure.
2209 * @hbainit: pointer to an array of unsigned 32-bit integers.
2211 * This routine performs the special handling for LC HBA initialization.
2214 lpfc_hba_init(struct lpfc_hba
*phba
, uint32_t *hbainit
)
2217 uint32_t *HashWorking
;
2218 uint32_t *pwwnn
= (uint32_t *) phba
->wwnn
;
2220 HashWorking
= kcalloc(80, sizeof(uint32_t), GFP_KERNEL
);
2224 HashWorking
[0] = HashWorking
[78] = *pwwnn
++;
2225 HashWorking
[1] = HashWorking
[79] = *pwwnn
;
2227 for (t
= 0; t
< 7; t
++)
2228 lpfc_challenge_key(phba
->RandomData
+ t
, HashWorking
+ t
);
2230 lpfc_sha_init(hbainit
);
2231 lpfc_sha_iterate(hbainit
, HashWorking
);
2236 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2237 * @vport: pointer to a virtual N_Port data structure.
2239 * This routine performs the necessary cleanups before deleting the @vport.
2240 * It invokes the discovery state machine to perform necessary state
2241 * transitions and to release the ndlps associated with the @vport. Note,
2242 * the physical port is treated as @vport 0.
2245 lpfc_cleanup(struct lpfc_vport
*vport
)
2247 struct lpfc_hba
*phba
= vport
->phba
;
2248 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2251 if (phba
->link_state
> LPFC_LINK_DOWN
)
2252 lpfc_port_link_failure(vport
);
2254 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2255 if (!NLP_CHK_NODE_ACT(ndlp
)) {
2256 ndlp
= lpfc_enable_node(vport
, ndlp
,
2257 NLP_STE_UNUSED_NODE
);
2260 spin_lock_irq(&phba
->ndlp_lock
);
2261 NLP_SET_FREE_REQ(ndlp
);
2262 spin_unlock_irq(&phba
->ndlp_lock
);
2263 /* Trigger the release of the ndlp memory */
2267 spin_lock_irq(&phba
->ndlp_lock
);
2268 if (NLP_CHK_FREE_REQ(ndlp
)) {
2269 /* The ndlp should not be in memory free mode already */
2270 spin_unlock_irq(&phba
->ndlp_lock
);
2273 /* Indicate request for freeing ndlp memory */
2274 NLP_SET_FREE_REQ(ndlp
);
2275 spin_unlock_irq(&phba
->ndlp_lock
);
2277 if (vport
->port_type
!= LPFC_PHYSICAL_PORT
&&
2278 ndlp
->nlp_DID
== Fabric_DID
) {
2279 /* Just free up ndlp with Fabric_DID for vports */
2284 if (ndlp
->nlp_type
& NLP_FABRIC
)
2285 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2286 NLP_EVT_DEVICE_RECOVERY
);
2288 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2293 /* At this point, ALL ndlp's should be gone
2294 * because of the previous NLP_EVT_DEVICE_RM.
2295 * Lets wait for this to happen, if needed.
2297 while (!list_empty(&vport
->fc_nodes
)) {
2299 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2300 "0233 Nodelist not empty\n");
2301 list_for_each_entry_safe(ndlp
, next_ndlp
,
2302 &vport
->fc_nodes
, nlp_listp
) {
2303 lpfc_printf_vlog(ndlp
->vport
, KERN_ERR
,
2305 "0282 did:x%x ndlp:x%p "
2306 "usgmap:x%x refcnt:%d\n",
2307 ndlp
->nlp_DID
, (void *)ndlp
,
2310 &ndlp
->kref
.refcount
));
2315 /* Wait for any activity on ndlps to settle */
2318 lpfc_cleanup_vports_rrqs(vport
, NULL
);
2322 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2323 * @vport: pointer to a virtual N_Port data structure.
2325 * This routine stops all the timers associated with a @vport. This function
2326 * is invoked before disabling or deleting a @vport. Note that the physical
2327 * port is treated as @vport 0.
2330 lpfc_stop_vport_timers(struct lpfc_vport
*vport
)
2332 del_timer_sync(&vport
->els_tmofunc
);
2333 del_timer_sync(&vport
->fc_fdmitmo
);
2334 del_timer_sync(&vport
->delayed_disc_tmo
);
2335 lpfc_can_disctmo(vport
);
2340 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2341 * @phba: pointer to lpfc hba data structure.
2343 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2344 * caller of this routine should already hold the host lock.
2347 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2349 /* Clear pending FCF rediscovery wait flag */
2350 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_PEND
;
2352 /* Now, try to stop the timer */
2353 del_timer(&phba
->fcf
.redisc_wait
);
2357 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2358 * @phba: pointer to lpfc hba data structure.
2360 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2361 * checks whether the FCF rediscovery wait timer is pending with the host
2362 * lock held before proceeding with disabling the timer and clearing the
2363 * wait timer pendig flag.
2366 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2368 spin_lock_irq(&phba
->hbalock
);
2369 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
2370 /* FCF rediscovery timer already fired or stopped */
2371 spin_unlock_irq(&phba
->hbalock
);
2374 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
2375 /* Clear failover in progress flags */
2376 phba
->fcf
.fcf_flag
&= ~(FCF_DEAD_DISC
| FCF_ACVL_DISC
);
2377 spin_unlock_irq(&phba
->hbalock
);
2381 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2382 * @phba: pointer to lpfc hba data structure.
2384 * This routine stops all the timers associated with a HBA. This function is
2385 * invoked before either putting a HBA offline or unloading the driver.
2388 lpfc_stop_hba_timers(struct lpfc_hba
*phba
)
2390 lpfc_stop_vport_timers(phba
->pport
);
2391 del_timer_sync(&phba
->sli
.mbox_tmo
);
2392 del_timer_sync(&phba
->fabric_block_timer
);
2393 del_timer_sync(&phba
->eratt_poll
);
2394 del_timer_sync(&phba
->hb_tmofunc
);
2395 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2396 del_timer_sync(&phba
->rrq_tmr
);
2397 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
2399 phba
->hb_outstanding
= 0;
2401 switch (phba
->pci_dev_grp
) {
2402 case LPFC_PCI_DEV_LP
:
2403 /* Stop any LightPulse device specific driver timers */
2404 del_timer_sync(&phba
->fcp_poll_timer
);
2406 case LPFC_PCI_DEV_OC
:
2407 /* Stop any OneConnect device sepcific driver timers */
2408 lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
2411 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2412 "0297 Invalid device group (x%x)\n",
2420 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
2421 * @phba: pointer to lpfc hba data structure.
2423 * This routine marks a HBA's management interface as blocked. Once the HBA's
2424 * management interface is marked as blocked, all the user space access to
2425 * the HBA, whether they are from sysfs interface or libdfc interface will
2426 * all be blocked. The HBA is set to block the management interface when the
2427 * driver prepares the HBA interface for online or offline.
2430 lpfc_block_mgmt_io(struct lpfc_hba
* phba
)
2432 unsigned long iflag
;
2433 uint8_t actcmd
= MBX_HEARTBEAT
;
2434 unsigned long timeout
;
2437 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2438 phba
->sli
.sli_flag
|= LPFC_BLOCK_MGMT_IO
;
2439 if (phba
->sli
.mbox_active
)
2440 actcmd
= phba
->sli
.mbox_active
->u
.mb
.mbxCommand
;
2441 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2442 /* Determine how long we might wait for the active mailbox
2443 * command to be gracefully completed by firmware.
2445 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
, actcmd
) * 1000) +
2447 /* Wait for the outstnading mailbox command to complete */
2448 while (phba
->sli
.mbox_active
) {
2449 /* Check active mailbox complete status every 2ms */
2451 if (time_after(jiffies
, timeout
)) {
2452 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2453 "2813 Mgmt IO is Blocked %x "
2454 "- mbox cmd %x still active\n",
2455 phba
->sli
.sli_flag
, actcmd
);
2462 * lpfc_online - Initialize and bring a HBA online
2463 * @phba: pointer to lpfc hba data structure.
2465 * This routine initializes the HBA and brings a HBA online. During this
2466 * process, the management interface is blocked to prevent user space access
2467 * to the HBA interfering with the driver initialization.
2474 lpfc_online(struct lpfc_hba
*phba
)
2476 struct lpfc_vport
*vport
;
2477 struct lpfc_vport
**vports
;
2482 vport
= phba
->pport
;
2484 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
))
2487 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2488 "0458 Bring Adapter online\n");
2490 lpfc_block_mgmt_io(phba
);
2492 if (!lpfc_sli_queue_setup(phba
)) {
2493 lpfc_unblock_mgmt_io(phba
);
2497 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2498 if (lpfc_sli4_hba_setup(phba
)) { /* Initialize SLI4 HBA */
2499 lpfc_unblock_mgmt_io(phba
);
2503 if (lpfc_sli_hba_setup(phba
)) { /* Initialize SLI2/SLI3 HBA */
2504 lpfc_unblock_mgmt_io(phba
);
2509 vports
= lpfc_create_vport_work_array(phba
);
2511 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2512 struct Scsi_Host
*shost
;
2513 shost
= lpfc_shost_from_vport(vports
[i
]);
2514 spin_lock_irq(shost
->host_lock
);
2515 vports
[i
]->fc_flag
&= ~FC_OFFLINE_MODE
;
2516 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
2517 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2518 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2519 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
2520 spin_unlock_irq(shost
->host_lock
);
2522 lpfc_destroy_vport_work_array(phba
, vports
);
2524 lpfc_unblock_mgmt_io(phba
);
2529 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
2530 * @phba: pointer to lpfc hba data structure.
2532 * This routine marks a HBA's management interface as not blocked. Once the
2533 * HBA's management interface is marked as not blocked, all the user space
2534 * access to the HBA, whether they are from sysfs interface or libdfc
2535 * interface will be allowed. The HBA is set to block the management interface
2536 * when the driver prepares the HBA interface for online or offline and then
2537 * set to unblock the management interface afterwards.
2540 lpfc_unblock_mgmt_io(struct lpfc_hba
* phba
)
2542 unsigned long iflag
;
2544 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2545 phba
->sli
.sli_flag
&= ~LPFC_BLOCK_MGMT_IO
;
2546 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2550 * lpfc_offline_prep - Prepare a HBA to be brought offline
2551 * @phba: pointer to lpfc hba data structure.
2553 * This routine is invoked to prepare a HBA to be brought offline. It performs
2554 * unregistration login to all the nodes on all vports and flushes the mailbox
2555 * queue to make it ready to be brought offline.
2558 lpfc_offline_prep(struct lpfc_hba
* phba
)
2560 struct lpfc_vport
*vport
= phba
->pport
;
2561 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2562 struct lpfc_vport
**vports
;
2563 struct Scsi_Host
*shost
;
2566 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
2569 lpfc_block_mgmt_io(phba
);
2571 lpfc_linkdown(phba
);
2573 /* Issue an unreg_login to all nodes on all vports */
2574 vports
= lpfc_create_vport_work_array(phba
);
2575 if (vports
!= NULL
) {
2576 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2577 if (vports
[i
]->load_flag
& FC_UNLOADING
)
2579 shost
= lpfc_shost_from_vport(vports
[i
]);
2580 spin_lock_irq(shost
->host_lock
);
2581 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
2582 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2583 vports
[i
]->fc_flag
&= ~FC_VFI_REGISTERED
;
2584 spin_unlock_irq(shost
->host_lock
);
2586 shost
= lpfc_shost_from_vport(vports
[i
]);
2587 list_for_each_entry_safe(ndlp
, next_ndlp
,
2588 &vports
[i
]->fc_nodes
,
2590 if (!NLP_CHK_NODE_ACT(ndlp
))
2592 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
2594 if (ndlp
->nlp_type
& NLP_FABRIC
) {
2595 lpfc_disc_state_machine(vports
[i
], ndlp
,
2596 NULL
, NLP_EVT_DEVICE_RECOVERY
);
2597 lpfc_disc_state_machine(vports
[i
], ndlp
,
2598 NULL
, NLP_EVT_DEVICE_RM
);
2600 spin_lock_irq(shost
->host_lock
);
2601 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2602 spin_unlock_irq(shost
->host_lock
);
2603 lpfc_unreg_rpi(vports
[i
], ndlp
);
2607 lpfc_destroy_vport_work_array(phba
, vports
);
2609 lpfc_sli_mbox_sys_shutdown(phba
);
2613 * lpfc_offline - Bring a HBA offline
2614 * @phba: pointer to lpfc hba data structure.
2616 * This routine actually brings a HBA offline. It stops all the timers
2617 * associated with the HBA, brings down the SLI layer, and eventually
2618 * marks the HBA as in offline state for the upper layer protocol.
2621 lpfc_offline(struct lpfc_hba
*phba
)
2623 struct Scsi_Host
*shost
;
2624 struct lpfc_vport
**vports
;
2627 if (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
2630 /* stop port and all timers associated with this hba */
2631 lpfc_stop_port(phba
);
2632 vports
= lpfc_create_vport_work_array(phba
);
2634 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
2635 lpfc_stop_vport_timers(vports
[i
]);
2636 lpfc_destroy_vport_work_array(phba
, vports
);
2637 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2638 "0460 Bring Adapter offline\n");
2639 /* Bring down the SLI Layer and cleanup. The HBA is offline
2641 lpfc_sli_hba_down(phba
);
2642 spin_lock_irq(&phba
->hbalock
);
2644 spin_unlock_irq(&phba
->hbalock
);
2645 vports
= lpfc_create_vport_work_array(phba
);
2647 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2648 shost
= lpfc_shost_from_vport(vports
[i
]);
2649 spin_lock_irq(shost
->host_lock
);
2650 vports
[i
]->work_port_events
= 0;
2651 vports
[i
]->fc_flag
|= FC_OFFLINE_MODE
;
2652 spin_unlock_irq(shost
->host_lock
);
2654 lpfc_destroy_vport_work_array(phba
, vports
);
2658 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
2659 * @phba: pointer to lpfc hba data structure.
2661 * This routine is to free all the SCSI buffers and IOCBs from the driver
2662 * list back to kernel. It is called from lpfc_pci_remove_one to free
2663 * the internal resources before the device is removed from the system.
2666 * 0 - successful (for now, it always returns 0)
2669 lpfc_scsi_free(struct lpfc_hba
*phba
)
2671 struct lpfc_scsi_buf
*sb
, *sb_next
;
2672 struct lpfc_iocbq
*io
, *io_next
;
2674 spin_lock_irq(&phba
->hbalock
);
2675 /* Release all the lpfc_scsi_bufs maintained by this host. */
2676 spin_lock(&phba
->scsi_buf_list_lock
);
2677 list_for_each_entry_safe(sb
, sb_next
, &phba
->lpfc_scsi_buf_list
, list
) {
2678 list_del(&sb
->list
);
2679 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
, sb
->data
,
2682 phba
->total_scsi_bufs
--;
2684 spin_unlock(&phba
->scsi_buf_list_lock
);
2686 /* Release all the lpfc_iocbq entries maintained by this host. */
2687 list_for_each_entry_safe(io
, io_next
, &phba
->lpfc_iocb_list
, list
) {
2688 list_del(&io
->list
);
2690 phba
->total_iocbq_bufs
--;
2693 spin_unlock_irq(&phba
->hbalock
);
2698 * lpfc_create_port - Create an FC port
2699 * @phba: pointer to lpfc hba data structure.
2700 * @instance: a unique integer ID to this FC port.
2701 * @dev: pointer to the device data structure.
2703 * This routine creates a FC port for the upper layer protocol. The FC port
2704 * can be created on top of either a physical port or a virtual port provided
2705 * by the HBA. This routine also allocates a SCSI host data structure (shost)
2706 * and associates the FC port created before adding the shost into the SCSI
2710 * @vport - pointer to the virtual N_Port data structure.
2711 * NULL - port create failed.
2714 lpfc_create_port(struct lpfc_hba
*phba
, int instance
, struct device
*dev
)
2716 struct lpfc_vport
*vport
;
2717 struct Scsi_Host
*shost
;
2720 if (dev
!= &phba
->pcidev
->dev
)
2721 shost
= scsi_host_alloc(&lpfc_vport_template
,
2722 sizeof(struct lpfc_vport
));
2724 shost
= scsi_host_alloc(&lpfc_template
,
2725 sizeof(struct lpfc_vport
));
2729 vport
= (struct lpfc_vport
*) shost
->hostdata
;
2731 vport
->load_flag
|= FC_LOADING
;
2732 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2733 vport
->fc_rscn_flush
= 0;
2735 lpfc_get_vport_cfgparam(vport
);
2736 shost
->unique_id
= instance
;
2737 shost
->max_id
= LPFC_MAX_TARGET
;
2738 shost
->max_lun
= vport
->cfg_max_luns
;
2739 shost
->this_id
= -1;
2740 shost
->max_cmd_len
= 16;
2741 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2742 shost
->dma_boundary
=
2743 phba
->sli4_hba
.pc_sli4_params
.sge_supp_len
-1;
2744 shost
->sg_tablesize
= phba
->cfg_sg_seg_cnt
;
2748 * Set initial can_queue value since 0 is no longer supported and
2749 * scsi_add_host will fail. This will be adjusted later based on the
2750 * max xri value determined in hba setup.
2752 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
2753 if (dev
!= &phba
->pcidev
->dev
) {
2754 shost
->transportt
= lpfc_vport_transport_template
;
2755 vport
->port_type
= LPFC_NPIV_PORT
;
2757 shost
->transportt
= lpfc_transport_template
;
2758 vport
->port_type
= LPFC_PHYSICAL_PORT
;
2761 /* Initialize all internally managed lists. */
2762 INIT_LIST_HEAD(&vport
->fc_nodes
);
2763 INIT_LIST_HEAD(&vport
->rcv_buffer_list
);
2764 spin_lock_init(&vport
->work_port_lock
);
2766 init_timer(&vport
->fc_disctmo
);
2767 vport
->fc_disctmo
.function
= lpfc_disc_timeout
;
2768 vport
->fc_disctmo
.data
= (unsigned long)vport
;
2770 init_timer(&vport
->fc_fdmitmo
);
2771 vport
->fc_fdmitmo
.function
= lpfc_fdmi_tmo
;
2772 vport
->fc_fdmitmo
.data
= (unsigned long)vport
;
2774 init_timer(&vport
->els_tmofunc
);
2775 vport
->els_tmofunc
.function
= lpfc_els_timeout
;
2776 vport
->els_tmofunc
.data
= (unsigned long)vport
;
2778 init_timer(&vport
->delayed_disc_tmo
);
2779 vport
->delayed_disc_tmo
.function
= lpfc_delayed_disc_tmo
;
2780 vport
->delayed_disc_tmo
.data
= (unsigned long)vport
;
2782 error
= scsi_add_host_with_dma(shost
, dev
, &phba
->pcidev
->dev
);
2786 spin_lock_irq(&phba
->hbalock
);
2787 list_add_tail(&vport
->listentry
, &phba
->port_list
);
2788 spin_unlock_irq(&phba
->hbalock
);
2792 scsi_host_put(shost
);
2798 * destroy_port - destroy an FC port
2799 * @vport: pointer to an lpfc virtual N_Port data structure.
2801 * This routine destroys a FC port from the upper layer protocol. All the
2802 * resources associated with the port are released.
2805 destroy_port(struct lpfc_vport
*vport
)
2807 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2808 struct lpfc_hba
*phba
= vport
->phba
;
2810 lpfc_debugfs_terminate(vport
);
2811 fc_remove_host(shost
);
2812 scsi_remove_host(shost
);
2814 spin_lock_irq(&phba
->hbalock
);
2815 list_del_init(&vport
->listentry
);
2816 spin_unlock_irq(&phba
->hbalock
);
2818 lpfc_cleanup(vport
);
2823 * lpfc_get_instance - Get a unique integer ID
2825 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
2826 * uses the kernel idr facility to perform the task.
2829 * instance - a unique integer ID allocated as the new instance.
2830 * -1 - lpfc get instance failed.
2833 lpfc_get_instance(void)
2837 /* Assign an unused number */
2838 if (!idr_pre_get(&lpfc_hba_index
, GFP_KERNEL
))
2840 if (idr_get_new(&lpfc_hba_index
, NULL
, &instance
))
2846 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
2847 * @shost: pointer to SCSI host data structure.
2848 * @time: elapsed time of the scan in jiffies.
2850 * This routine is called by the SCSI layer with a SCSI host to determine
2851 * whether the scan host is finished.
2853 * Note: there is no scan_start function as adapter initialization will have
2854 * asynchronously kicked off the link initialization.
2857 * 0 - SCSI host scan is not over yet.
2858 * 1 - SCSI host scan is over.
2860 int lpfc_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
2862 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2863 struct lpfc_hba
*phba
= vport
->phba
;
2866 spin_lock_irq(shost
->host_lock
);
2868 if (vport
->load_flag
& FC_UNLOADING
) {
2872 if (time
>= 30 * HZ
) {
2873 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
2874 "0461 Scanning longer than 30 "
2875 "seconds. Continuing initialization\n");
2879 if (time
>= 15 * HZ
&& phba
->link_state
<= LPFC_LINK_DOWN
) {
2880 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
2881 "0465 Link down longer than 15 "
2882 "seconds. Continuing initialization\n");
2887 if (vport
->port_state
!= LPFC_VPORT_READY
)
2889 if (vport
->num_disc_nodes
|| vport
->fc_prli_sent
)
2891 if (vport
->fc_map_cnt
== 0 && time
< 2 * HZ
)
2893 if ((phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) != 0)
2899 spin_unlock_irq(shost
->host_lock
);
2904 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
2905 * @shost: pointer to SCSI host data structure.
2907 * This routine initializes a given SCSI host attributes on a FC port. The
2908 * SCSI host can be either on top of a physical port or a virtual port.
2910 void lpfc_host_attrib_init(struct Scsi_Host
*shost
)
2912 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2913 struct lpfc_hba
*phba
= vport
->phba
;
2915 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
2918 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
2919 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
2920 fc_host_supported_classes(shost
) = FC_COS_CLASS3
;
2922 memset(fc_host_supported_fc4s(shost
), 0,
2923 sizeof(fc_host_supported_fc4s(shost
)));
2924 fc_host_supported_fc4s(shost
)[2] = 1;
2925 fc_host_supported_fc4s(shost
)[7] = 1;
2927 lpfc_vport_symbolic_node_name(vport
, fc_host_symbolic_name(shost
),
2928 sizeof fc_host_symbolic_name(shost
));
2930 fc_host_supported_speeds(shost
) = 0;
2931 if (phba
->lmt
& LMT_16Gb
)
2932 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_16GBIT
;
2933 if (phba
->lmt
& LMT_10Gb
)
2934 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_10GBIT
;
2935 if (phba
->lmt
& LMT_8Gb
)
2936 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_8GBIT
;
2937 if (phba
->lmt
& LMT_4Gb
)
2938 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_4GBIT
;
2939 if (phba
->lmt
& LMT_2Gb
)
2940 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_2GBIT
;
2941 if (phba
->lmt
& LMT_1Gb
)
2942 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_1GBIT
;
2944 fc_host_maxframe_size(shost
) =
2945 (((uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
2946 (uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeLsb
;
2948 fc_host_dev_loss_tmo(shost
) = vport
->cfg_devloss_tmo
;
2950 /* This value is also unchanging */
2951 memset(fc_host_active_fc4s(shost
), 0,
2952 sizeof(fc_host_active_fc4s(shost
)));
2953 fc_host_active_fc4s(shost
)[2] = 1;
2954 fc_host_active_fc4s(shost
)[7] = 1;
2956 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
2957 spin_lock_irq(shost
->host_lock
);
2958 vport
->load_flag
&= ~FC_LOADING
;
2959 spin_unlock_irq(shost
->host_lock
);
2963 * lpfc_stop_port_s3 - Stop SLI3 device port
2964 * @phba: pointer to lpfc hba data structure.
2966 * This routine is invoked to stop an SLI3 device port, it stops the device
2967 * from generating interrupts and stops the device driver's timers for the
2971 lpfc_stop_port_s3(struct lpfc_hba
*phba
)
2973 /* Clear all interrupt enable conditions */
2974 writel(0, phba
->HCregaddr
);
2975 readl(phba
->HCregaddr
); /* flush */
2976 /* Clear all pending interrupts */
2977 writel(0xffffffff, phba
->HAregaddr
);
2978 readl(phba
->HAregaddr
); /* flush */
2980 /* Reset some HBA SLI setup states */
2981 lpfc_stop_hba_timers(phba
);
2982 phba
->pport
->work_port_events
= 0;
2986 * lpfc_stop_port_s4 - Stop SLI4 device port
2987 * @phba: pointer to lpfc hba data structure.
2989 * This routine is invoked to stop an SLI4 device port, it stops the device
2990 * from generating interrupts and stops the device driver's timers for the
2994 lpfc_stop_port_s4(struct lpfc_hba
*phba
)
2996 /* Reset some HBA SLI4 setup states */
2997 lpfc_stop_hba_timers(phba
);
2998 phba
->pport
->work_port_events
= 0;
2999 phba
->sli4_hba
.intr_enable
= 0;
3003 * lpfc_stop_port - Wrapper function for stopping hba port
3004 * @phba: Pointer to HBA context object.
3006 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3007 * the API jump table function pointer from the lpfc_hba struct.
3010 lpfc_stop_port(struct lpfc_hba
*phba
)
3012 phba
->lpfc_stop_port(phba
);
3016 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3017 * @phba: Pointer to hba for which this call is being executed.
3019 * This routine starts the timer waiting for the FCF rediscovery to complete.
3022 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba
*phba
)
3024 unsigned long fcf_redisc_wait_tmo
=
3025 (jiffies
+ msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO
));
3026 /* Start fcf rediscovery wait period timer */
3027 mod_timer(&phba
->fcf
.redisc_wait
, fcf_redisc_wait_tmo
);
3028 spin_lock_irq(&phba
->hbalock
);
3029 /* Allow action to new fcf asynchronous event */
3030 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
3031 /* Mark the FCF rediscovery pending state */
3032 phba
->fcf
.fcf_flag
|= FCF_REDISC_PEND
;
3033 spin_unlock_irq(&phba
->hbalock
);
3037 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3038 * @ptr: Map to lpfc_hba data structure pointer.
3040 * This routine is invoked when waiting for FCF table rediscover has been
3041 * timed out. If new FCF record(s) has (have) been discovered during the
3042 * wait period, a new FCF event shall be added to the FCOE async event
3043 * list, and then worker thread shall be waked up for processing from the
3044 * worker thread context.
3047 lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr
)
3049 struct lpfc_hba
*phba
= (struct lpfc_hba
*)ptr
;
3051 /* Don't send FCF rediscovery event if timer cancelled */
3052 spin_lock_irq(&phba
->hbalock
);
3053 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
3054 spin_unlock_irq(&phba
->hbalock
);
3057 /* Clear FCF rediscovery timer pending flag */
3058 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_PEND
;
3059 /* FCF rediscovery event to worker thread */
3060 phba
->fcf
.fcf_flag
|= FCF_REDISC_EVT
;
3061 spin_unlock_irq(&phba
->hbalock
);
3062 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
3063 "2776 FCF rediscover quiescent timer expired\n");
3064 /* wake up worker thread */
3065 lpfc_worker_wake_up(phba
);
3069 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3070 * @phba: pointer to lpfc hba data structure.
3071 * @acqe_link: pointer to the async link completion queue entry.
3073 * This routine is to parse the SLI4 link-attention link fault code and
3074 * translate it into the base driver's read link attention mailbox command
3077 * Return: Link-attention status in terms of base driver's coding.
3080 lpfc_sli4_parse_latt_fault(struct lpfc_hba
*phba
,
3081 struct lpfc_acqe_link
*acqe_link
)
3083 uint16_t latt_fault
;
3085 switch (bf_get(lpfc_acqe_link_fault
, acqe_link
)) {
3086 case LPFC_ASYNC_LINK_FAULT_NONE
:
3087 case LPFC_ASYNC_LINK_FAULT_LOCAL
:
3088 case LPFC_ASYNC_LINK_FAULT_REMOTE
:
3092 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3093 "0398 Invalid link fault code: x%x\n",
3094 bf_get(lpfc_acqe_link_fault
, acqe_link
));
3095 latt_fault
= MBXERR_ERROR
;
3102 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3103 * @phba: pointer to lpfc hba data structure.
3104 * @acqe_link: pointer to the async link completion queue entry.
3106 * This routine is to parse the SLI4 link attention type and translate it
3107 * into the base driver's link attention type coding.
3109 * Return: Link attention type in terms of base driver's coding.
3112 lpfc_sli4_parse_latt_type(struct lpfc_hba
*phba
,
3113 struct lpfc_acqe_link
*acqe_link
)
3117 switch (bf_get(lpfc_acqe_link_status
, acqe_link
)) {
3118 case LPFC_ASYNC_LINK_STATUS_DOWN
:
3119 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN
:
3120 att_type
= LPFC_ATT_LINK_DOWN
;
3122 case LPFC_ASYNC_LINK_STATUS_UP
:
3123 /* Ignore physical link up events - wait for logical link up */
3124 att_type
= LPFC_ATT_RESERVED
;
3126 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP
:
3127 att_type
= LPFC_ATT_LINK_UP
;
3130 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3131 "0399 Invalid link attention type: x%x\n",
3132 bf_get(lpfc_acqe_link_status
, acqe_link
));
3133 att_type
= LPFC_ATT_RESERVED
;
3140 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
3141 * @phba: pointer to lpfc hba data structure.
3142 * @acqe_link: pointer to the async link completion queue entry.
3144 * This routine is to parse the SLI4 link-attention link speed and translate
3145 * it into the base driver's link-attention link speed coding.
3147 * Return: Link-attention link speed in terms of base driver's coding.
3150 lpfc_sli4_parse_latt_link_speed(struct lpfc_hba
*phba
,
3151 struct lpfc_acqe_link
*acqe_link
)
3155 switch (bf_get(lpfc_acqe_link_speed
, acqe_link
)) {
3156 case LPFC_ASYNC_LINK_SPEED_ZERO
:
3157 case LPFC_ASYNC_LINK_SPEED_10MBPS
:
3158 case LPFC_ASYNC_LINK_SPEED_100MBPS
:
3159 link_speed
= LPFC_LINK_SPEED_UNKNOWN
;
3161 case LPFC_ASYNC_LINK_SPEED_1GBPS
:
3162 link_speed
= LPFC_LINK_SPEED_1GHZ
;
3164 case LPFC_ASYNC_LINK_SPEED_10GBPS
:
3165 link_speed
= LPFC_LINK_SPEED_10GHZ
;
3168 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3169 "0483 Invalid link-attention link speed: x%x\n",
3170 bf_get(lpfc_acqe_link_speed
, acqe_link
));
3171 link_speed
= LPFC_LINK_SPEED_UNKNOWN
;
3178 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
3179 * @phba: pointer to lpfc hba data structure.
3180 * @acqe_link: pointer to the async link completion queue entry.
3182 * This routine is to handle the SLI4 asynchronous FCoE link event.
3185 lpfc_sli4_async_link_evt(struct lpfc_hba
*phba
,
3186 struct lpfc_acqe_link
*acqe_link
)
3188 struct lpfc_dmabuf
*mp
;
3191 struct lpfc_mbx_read_top
*la
;
3195 att_type
= lpfc_sli4_parse_latt_type(phba
, acqe_link
);
3196 if (att_type
!= LPFC_ATT_LINK_DOWN
&& att_type
!= LPFC_ATT_LINK_UP
)
3198 phba
->fcoe_eventtag
= acqe_link
->event_tag
;
3199 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3201 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3202 "0395 The mboxq allocation failed\n");
3205 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
3207 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3208 "0396 The lpfc_dmabuf allocation failed\n");
3211 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
3213 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3214 "0397 The mbuf allocation failed\n");
3215 goto out_free_dmabuf
;
3218 /* Cleanup any outstanding ELS commands */
3219 lpfc_els_flush_all_cmd(phba
);
3221 /* Block ELS IOCBs until we have done process link event */
3222 phba
->sli
.ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
3224 /* Update link event statistics */
3225 phba
->sli
.slistat
.link_event
++;
3227 /* Create lpfc_handle_latt mailbox command from link ACQE */
3228 lpfc_read_topology(phba
, pmb
, mp
);
3229 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
3230 pmb
->vport
= phba
->pport
;
3232 /* Keep the link status for extra SLI4 state machine reference */
3233 phba
->sli4_hba
.link_state
.speed
=
3234 bf_get(lpfc_acqe_link_speed
, acqe_link
);
3235 phba
->sli4_hba
.link_state
.duplex
=
3236 bf_get(lpfc_acqe_link_duplex
, acqe_link
);
3237 phba
->sli4_hba
.link_state
.status
=
3238 bf_get(lpfc_acqe_link_status
, acqe_link
);
3239 phba
->sli4_hba
.link_state
.type
=
3240 bf_get(lpfc_acqe_link_type
, acqe_link
);
3241 phba
->sli4_hba
.link_state
.number
=
3242 bf_get(lpfc_acqe_link_number
, acqe_link
);
3243 phba
->sli4_hba
.link_state
.fault
=
3244 bf_get(lpfc_acqe_link_fault
, acqe_link
);
3245 phba
->sli4_hba
.link_state
.logical_speed
=
3246 bf_get(lpfc_acqe_logical_link_speed
, acqe_link
);
3247 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3248 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3249 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3250 "Logical speed:%dMbps Fault:%d\n",
3251 phba
->sli4_hba
.link_state
.speed
,
3252 phba
->sli4_hba
.link_state
.topology
,
3253 phba
->sli4_hba
.link_state
.status
,
3254 phba
->sli4_hba
.link_state
.type
,
3255 phba
->sli4_hba
.link_state
.number
,
3256 phba
->sli4_hba
.link_state
.logical_speed
* 10,
3257 phba
->sli4_hba
.link_state
.fault
);
3259 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3260 * topology info. Note: Optional for non FC-AL ports.
3262 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
3263 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3264 if (rc
== MBX_NOT_FINISHED
)
3265 goto out_free_dmabuf
;
3269 * For FCoE Mode: fill in all the topology information we need and call
3270 * the READ_TOPOLOGY completion routine to continue without actually
3271 * sending the READ_TOPOLOGY mailbox command to the port.
3273 /* Parse and translate status field */
3275 mb
->mbxStatus
= lpfc_sli4_parse_latt_fault(phba
, acqe_link
);
3277 /* Parse and translate link attention fields */
3278 la
= (struct lpfc_mbx_read_top
*) &pmb
->u
.mb
.un
.varReadTop
;
3279 la
->eventTag
= acqe_link
->event_tag
;
3280 bf_set(lpfc_mbx_read_top_att_type
, la
, att_type
);
3281 bf_set(lpfc_mbx_read_top_link_spd
, la
,
3282 lpfc_sli4_parse_latt_link_speed(phba
, acqe_link
));
3284 /* Fake the the following irrelvant fields */
3285 bf_set(lpfc_mbx_read_top_topology
, la
, LPFC_TOPOLOGY_PT_PT
);
3286 bf_set(lpfc_mbx_read_top_alpa_granted
, la
, 0);
3287 bf_set(lpfc_mbx_read_top_il
, la
, 0);
3288 bf_set(lpfc_mbx_read_top_pb
, la
, 0);
3289 bf_set(lpfc_mbx_read_top_fa
, la
, 0);
3290 bf_set(lpfc_mbx_read_top_mm
, la
, 0);
3292 /* Invoke the lpfc_handle_latt mailbox command callback function */
3293 lpfc_mbx_cmpl_read_topology(phba
, pmb
);
3300 mempool_free(pmb
, phba
->mbox_mem_pool
);
3304 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
3305 * @phba: pointer to lpfc hba data structure.
3306 * @acqe_fc: pointer to the async fc completion queue entry.
3308 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
3309 * that the event was received and then issue a read_topology mailbox command so
3310 * that the rest of the driver will treat it the same as SLI3.
3313 lpfc_sli4_async_fc_evt(struct lpfc_hba
*phba
, struct lpfc_acqe_fc_la
*acqe_fc
)
3315 struct lpfc_dmabuf
*mp
;
3319 if (bf_get(lpfc_trailer_type
, acqe_fc
) !=
3320 LPFC_FC_LA_EVENT_TYPE_FC_LINK
) {
3321 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3322 "2895 Non FC link Event detected.(%d)\n",
3323 bf_get(lpfc_trailer_type
, acqe_fc
));
3326 /* Keep the link status for extra SLI4 state machine reference */
3327 phba
->sli4_hba
.link_state
.speed
=
3328 bf_get(lpfc_acqe_fc_la_speed
, acqe_fc
);
3329 phba
->sli4_hba
.link_state
.duplex
= LPFC_ASYNC_LINK_DUPLEX_FULL
;
3330 phba
->sli4_hba
.link_state
.topology
=
3331 bf_get(lpfc_acqe_fc_la_topology
, acqe_fc
);
3332 phba
->sli4_hba
.link_state
.status
=
3333 bf_get(lpfc_acqe_fc_la_att_type
, acqe_fc
);
3334 phba
->sli4_hba
.link_state
.type
=
3335 bf_get(lpfc_acqe_fc_la_port_type
, acqe_fc
);
3336 phba
->sli4_hba
.link_state
.number
=
3337 bf_get(lpfc_acqe_fc_la_port_number
, acqe_fc
);
3338 phba
->sli4_hba
.link_state
.fault
=
3339 bf_get(lpfc_acqe_link_fault
, acqe_fc
);
3340 phba
->sli4_hba
.link_state
.logical_speed
=
3341 bf_get(lpfc_acqe_fc_la_llink_spd
, acqe_fc
);
3342 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3343 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
3344 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
3345 "%dMbps Fault:%d\n",
3346 phba
->sli4_hba
.link_state
.speed
,
3347 phba
->sli4_hba
.link_state
.topology
,
3348 phba
->sli4_hba
.link_state
.status
,
3349 phba
->sli4_hba
.link_state
.type
,
3350 phba
->sli4_hba
.link_state
.number
,
3351 phba
->sli4_hba
.link_state
.logical_speed
* 10,
3352 phba
->sli4_hba
.link_state
.fault
);
3353 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3355 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3356 "2897 The mboxq allocation failed\n");
3359 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
3361 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3362 "2898 The lpfc_dmabuf allocation failed\n");
3365 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
3367 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3368 "2899 The mbuf allocation failed\n");
3369 goto out_free_dmabuf
;
3372 /* Cleanup any outstanding ELS commands */
3373 lpfc_els_flush_all_cmd(phba
);
3375 /* Block ELS IOCBs until we have done process link event */
3376 phba
->sli
.ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
3378 /* Update link event statistics */
3379 phba
->sli
.slistat
.link_event
++;
3381 /* Create lpfc_handle_latt mailbox command from link ACQE */
3382 lpfc_read_topology(phba
, pmb
, mp
);
3383 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
3384 pmb
->vport
= phba
->pport
;
3386 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3387 if (rc
== MBX_NOT_FINISHED
)
3388 goto out_free_dmabuf
;
3394 mempool_free(pmb
, phba
->mbox_mem_pool
);
3398 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
3399 * @phba: pointer to lpfc hba data structure.
3400 * @acqe_fc: pointer to the async SLI completion queue entry.
3402 * This routine is to handle the SLI4 asynchronous SLI events.
3405 lpfc_sli4_async_sli_evt(struct lpfc_hba
*phba
, struct lpfc_acqe_sli
*acqe_sli
)
3407 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3408 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
3409 "x%08x SLI Event Type:%d",
3410 acqe_sli
->event_data1
, acqe_sli
->event_data2
,
3411 bf_get(lpfc_trailer_type
, acqe_sli
));
3416 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
3417 * @vport: pointer to vport data structure.
3419 * This routine is to perform Clear Virtual Link (CVL) on a vport in
3420 * response to a CVL event.
3422 * Return the pointer to the ndlp with the vport if successful, otherwise
3425 static struct lpfc_nodelist
*
3426 lpfc_sli4_perform_vport_cvl(struct lpfc_vport
*vport
)
3428 struct lpfc_nodelist
*ndlp
;
3429 struct Scsi_Host
*shost
;
3430 struct lpfc_hba
*phba
;
3437 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
3439 /* Cannot find existing Fabric ndlp, so allocate a new one */
3440 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
3443 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
3444 /* Set the node type */
3445 ndlp
->nlp_type
|= NLP_FABRIC
;
3446 /* Put ndlp onto node list */
3447 lpfc_enqueue_node(vport
, ndlp
);
3448 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
3449 /* re-setup ndlp without removing from node list */
3450 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
3454 if ((phba
->pport
->port_state
< LPFC_FLOGI
) &&
3455 (phba
->pport
->port_state
!= LPFC_VPORT_FAILED
))
3457 /* If virtual link is not yet instantiated ignore CVL */
3458 if ((vport
!= phba
->pport
) && (vport
->port_state
< LPFC_FDISC
)
3459 && (vport
->port_state
!= LPFC_VPORT_FAILED
))
3461 shost
= lpfc_shost_from_vport(vport
);
3464 lpfc_linkdown_port(vport
);
3465 lpfc_cleanup_pending_mbox(vport
);
3466 spin_lock_irq(shost
->host_lock
);
3467 vport
->fc_flag
|= FC_VPORT_CVL_RCVD
;
3468 spin_unlock_irq(shost
->host_lock
);
3474 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
3475 * @vport: pointer to lpfc hba data structure.
3477 * This routine is to perform Clear Virtual Link (CVL) on all vports in
3478 * response to a FCF dead event.
3481 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba
*phba
)
3483 struct lpfc_vport
**vports
;
3486 vports
= lpfc_create_vport_work_array(phba
);
3488 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
3489 lpfc_sli4_perform_vport_cvl(vports
[i
]);
3490 lpfc_destroy_vport_work_array(phba
, vports
);
3494 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
3495 * @phba: pointer to lpfc hba data structure.
3496 * @acqe_link: pointer to the async fcoe completion queue entry.
3498 * This routine is to handle the SLI4 asynchronous fcoe event.
3501 lpfc_sli4_async_fip_evt(struct lpfc_hba
*phba
,
3502 struct lpfc_acqe_fip
*acqe_fip
)
3504 uint8_t event_type
= bf_get(lpfc_trailer_type
, acqe_fip
);
3506 struct lpfc_vport
*vport
;
3507 struct lpfc_nodelist
*ndlp
;
3508 struct Scsi_Host
*shost
;
3509 int active_vlink_present
;
3510 struct lpfc_vport
**vports
;
3513 phba
->fc_eventTag
= acqe_fip
->event_tag
;
3514 phba
->fcoe_eventtag
= acqe_fip
->event_tag
;
3515 switch (event_type
) {
3516 case LPFC_FIP_EVENT_TYPE_NEW_FCF
:
3517 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD
:
3518 if (event_type
== LPFC_FIP_EVENT_TYPE_NEW_FCF
)
3519 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
3521 "2546 New FCF event, evt_tag:x%x, "
3523 acqe_fip
->event_tag
,
3526 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
|
3528 "2788 FCF param modified event, "
3529 "evt_tag:x%x, index:x%x\n",
3530 acqe_fip
->event_tag
,
3532 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
3534 * During period of FCF discovery, read the FCF
3535 * table record indexed by the event to update
3536 * FCF roundrobin failover eligible FCF bmask.
3538 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
3540 "2779 Read FCF (x%x) for updating "
3541 "roundrobin FCF failover bmask\n",
3543 rc
= lpfc_sli4_read_fcf_rec(phba
, acqe_fip
->index
);
3546 /* If the FCF discovery is in progress, do nothing. */
3547 spin_lock_irq(&phba
->hbalock
);
3548 if (phba
->hba_flag
& FCF_TS_INPROG
) {
3549 spin_unlock_irq(&phba
->hbalock
);
3552 /* If fast FCF failover rescan event is pending, do nothing */
3553 if (phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
) {
3554 spin_unlock_irq(&phba
->hbalock
);
3558 /* If the FCF has been in discovered state, do nothing. */
3559 if (phba
->fcf
.fcf_flag
& FCF_SCAN_DONE
) {
3560 spin_unlock_irq(&phba
->hbalock
);
3563 spin_unlock_irq(&phba
->hbalock
);
3565 /* Otherwise, scan the entire FCF table and re-discover SAN */
3566 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
3567 "2770 Start FCF table scan per async FCF "
3568 "event, evt_tag:x%x, index:x%x\n",
3569 acqe_fip
->event_tag
, acqe_fip
->index
);
3570 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
3571 LPFC_FCOE_FCF_GET_FIRST
);
3573 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
3574 "2547 Issue FCF scan read FCF mailbox "
3575 "command failed (x%x)\n", rc
);
3578 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL
:
3579 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3580 "2548 FCF Table full count 0x%x tag 0x%x\n",
3581 bf_get(lpfc_acqe_fip_fcf_count
, acqe_fip
),
3582 acqe_fip
->event_tag
);
3585 case LPFC_FIP_EVENT_TYPE_FCF_DEAD
:
3586 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
3587 "2549 FCF (x%x) disconnected from network, "
3588 "tag:x%x\n", acqe_fip
->index
, acqe_fip
->event_tag
);
3590 * If we are in the middle of FCF failover process, clear
3591 * the corresponding FCF bit in the roundrobin bitmap.
3593 spin_lock_irq(&phba
->hbalock
);
3594 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
3595 spin_unlock_irq(&phba
->hbalock
);
3596 /* Update FLOGI FCF failover eligible FCF bmask */
3597 lpfc_sli4_fcf_rr_index_clear(phba
, acqe_fip
->index
);
3600 spin_unlock_irq(&phba
->hbalock
);
3602 /* If the event is not for currently used fcf do nothing */
3603 if (phba
->fcf
.current_rec
.fcf_indx
!= acqe_fip
->index
)
3607 * Otherwise, request the port to rediscover the entire FCF
3608 * table for a fast recovery from case that the current FCF
3609 * is no longer valid as we are not in the middle of FCF
3610 * failover process already.
3612 spin_lock_irq(&phba
->hbalock
);
3613 /* Mark the fast failover process in progress */
3614 phba
->fcf
.fcf_flag
|= FCF_DEAD_DISC
;
3615 spin_unlock_irq(&phba
->hbalock
);
3617 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
3618 "2771 Start FCF fast failover process due to "
3619 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
3620 "\n", acqe_fip
->event_tag
, acqe_fip
->index
);
3621 rc
= lpfc_sli4_redisc_fcf_table(phba
);
3623 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
3625 "2772 Issue FCF rediscover mabilbox "
3626 "command failed, fail through to FCF "
3628 spin_lock_irq(&phba
->hbalock
);
3629 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
3630 spin_unlock_irq(&phba
->hbalock
);
3632 * Last resort will fail over by treating this
3633 * as a link down to FCF registration.
3635 lpfc_sli4_fcf_dead_failthrough(phba
);
3637 /* Reset FCF roundrobin bmask for new discovery */
3638 lpfc_sli4_clear_fcf_rr_bmask(phba
);
3640 * Handling fast FCF failover to a DEAD FCF event is
3641 * considered equalivant to receiving CVL to all vports.
3643 lpfc_sli4_perform_all_vport_cvl(phba
);
3646 case LPFC_FIP_EVENT_TYPE_CVL
:
3647 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
3648 "2718 Clear Virtual Link Received for VPI 0x%x"
3649 " tag 0x%x\n", acqe_fip
->index
, acqe_fip
->event_tag
);
3651 vport
= lpfc_find_vport_by_vpid(phba
,
3653 ndlp
= lpfc_sli4_perform_vport_cvl(vport
);
3656 active_vlink_present
= 0;
3658 vports
= lpfc_create_vport_work_array(phba
);
3660 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
3662 if ((!(vports
[i
]->fc_flag
&
3663 FC_VPORT_CVL_RCVD
)) &&
3664 (vports
[i
]->port_state
> LPFC_FDISC
)) {
3665 active_vlink_present
= 1;
3669 lpfc_destroy_vport_work_array(phba
, vports
);
3672 if (active_vlink_present
) {
3674 * If there are other active VLinks present,
3675 * re-instantiate the Vlink using FDISC.
3677 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ HZ
);
3678 shost
= lpfc_shost_from_vport(vport
);
3679 spin_lock_irq(shost
->host_lock
);
3680 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
3681 spin_unlock_irq(shost
->host_lock
);
3682 ndlp
->nlp_last_elscmd
= ELS_CMD_FDISC
;
3683 vport
->port_state
= LPFC_FDISC
;
3686 * Otherwise, we request port to rediscover
3687 * the entire FCF table for a fast recovery
3688 * from possible case that the current FCF
3689 * is no longer valid if we are not already
3690 * in the FCF failover process.
3692 spin_lock_irq(&phba
->hbalock
);
3693 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
3694 spin_unlock_irq(&phba
->hbalock
);
3697 /* Mark the fast failover process in progress */
3698 phba
->fcf
.fcf_flag
|= FCF_ACVL_DISC
;
3699 spin_unlock_irq(&phba
->hbalock
);
3700 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
3702 "2773 Start FCF failover per CVL, "
3703 "evt_tag:x%x\n", acqe_fip
->event_tag
);
3704 rc
= lpfc_sli4_redisc_fcf_table(phba
);
3706 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
3708 "2774 Issue FCF rediscover "
3709 "mabilbox command failed, "
3710 "through to CVL event\n");
3711 spin_lock_irq(&phba
->hbalock
);
3712 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
3713 spin_unlock_irq(&phba
->hbalock
);
3715 * Last resort will be re-try on the
3716 * the current registered FCF entry.
3718 lpfc_retry_pport_discovery(phba
);
3721 * Reset FCF roundrobin bmask for new
3724 lpfc_sli4_clear_fcf_rr_bmask(phba
);
3728 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3729 "0288 Unknown FCoE event type 0x%x event tag "
3730 "0x%x\n", event_type
, acqe_fip
->event_tag
);
3736 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
3737 * @phba: pointer to lpfc hba data structure.
3738 * @acqe_link: pointer to the async dcbx completion queue entry.
3740 * This routine is to handle the SLI4 asynchronous dcbx event.
3743 lpfc_sli4_async_dcbx_evt(struct lpfc_hba
*phba
,
3744 struct lpfc_acqe_dcbx
*acqe_dcbx
)
3746 phba
->fc_eventTag
= acqe_dcbx
->event_tag
;
3747 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3748 "0290 The SLI4 DCBX asynchronous event is not "
3753 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
3754 * @phba: pointer to lpfc hba data structure.
3755 * @acqe_link: pointer to the async grp5 completion queue entry.
3757 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
3758 * is an asynchronous notified of a logical link speed change. The Port
3759 * reports the logical link speed in units of 10Mbps.
3762 lpfc_sli4_async_grp5_evt(struct lpfc_hba
*phba
,
3763 struct lpfc_acqe_grp5
*acqe_grp5
)
3765 uint16_t prev_ll_spd
;
3767 phba
->fc_eventTag
= acqe_grp5
->event_tag
;
3768 phba
->fcoe_eventtag
= acqe_grp5
->event_tag
;
3769 prev_ll_spd
= phba
->sli4_hba
.link_state
.logical_speed
;
3770 phba
->sli4_hba
.link_state
.logical_speed
=
3771 (bf_get(lpfc_acqe_grp5_llink_spd
, acqe_grp5
));
3772 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3773 "2789 GRP5 Async Event: Updating logical link speed "
3774 "from %dMbps to %dMbps\n", (prev_ll_spd
* 10),
3775 (phba
->sli4_hba
.link_state
.logical_speed
*10));
3779 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
3780 * @phba: pointer to lpfc hba data structure.
3782 * This routine is invoked by the worker thread to process all the pending
3783 * SLI4 asynchronous events.
3785 void lpfc_sli4_async_event_proc(struct lpfc_hba
*phba
)
3787 struct lpfc_cq_event
*cq_event
;
3789 /* First, declare the async event has been handled */
3790 spin_lock_irq(&phba
->hbalock
);
3791 phba
->hba_flag
&= ~ASYNC_EVENT
;
3792 spin_unlock_irq(&phba
->hbalock
);
3793 /* Now, handle all the async events */
3794 while (!list_empty(&phba
->sli4_hba
.sp_asynce_work_queue
)) {
3795 /* Get the first event from the head of the event queue */
3796 spin_lock_irq(&phba
->hbalock
);
3797 list_remove_head(&phba
->sli4_hba
.sp_asynce_work_queue
,
3798 cq_event
, struct lpfc_cq_event
, list
);
3799 spin_unlock_irq(&phba
->hbalock
);
3800 /* Process the asynchronous event */
3801 switch (bf_get(lpfc_trailer_code
, &cq_event
->cqe
.mcqe_cmpl
)) {
3802 case LPFC_TRAILER_CODE_LINK
:
3803 lpfc_sli4_async_link_evt(phba
,
3804 &cq_event
->cqe
.acqe_link
);
3806 case LPFC_TRAILER_CODE_FCOE
:
3807 lpfc_sli4_async_fip_evt(phba
, &cq_event
->cqe
.acqe_fip
);
3809 case LPFC_TRAILER_CODE_DCBX
:
3810 lpfc_sli4_async_dcbx_evt(phba
,
3811 &cq_event
->cqe
.acqe_dcbx
);
3813 case LPFC_TRAILER_CODE_GRP5
:
3814 lpfc_sli4_async_grp5_evt(phba
,
3815 &cq_event
->cqe
.acqe_grp5
);
3817 case LPFC_TRAILER_CODE_FC
:
3818 lpfc_sli4_async_fc_evt(phba
, &cq_event
->cqe
.acqe_fc
);
3820 case LPFC_TRAILER_CODE_SLI
:
3821 lpfc_sli4_async_sli_evt(phba
, &cq_event
->cqe
.acqe_sli
);
3824 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3825 "1804 Invalid asynchrous event code: "
3826 "x%x\n", bf_get(lpfc_trailer_code
,
3827 &cq_event
->cqe
.mcqe_cmpl
));
3830 /* Free the completion event processed to the free pool */
3831 lpfc_sli4_cq_event_release(phba
, cq_event
);
3836 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
3837 * @phba: pointer to lpfc hba data structure.
3839 * This routine is invoked by the worker thread to process FCF table
3840 * rediscovery pending completion event.
3842 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba
*phba
)
3846 spin_lock_irq(&phba
->hbalock
);
3847 /* Clear FCF rediscovery timeout event */
3848 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_EVT
;
3849 /* Clear driver fast failover FCF record flag */
3850 phba
->fcf
.failover_rec
.flag
= 0;
3851 /* Set state for FCF fast failover */
3852 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
3853 spin_unlock_irq(&phba
->hbalock
);
3855 /* Scan FCF table from the first entry to re-discover SAN */
3856 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
3857 "2777 Start post-quiescent FCF table scan\n");
3858 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
3860 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
3861 "2747 Issue FCF scan read FCF mailbox "
3862 "command failed 0x%x\n", rc
);
3866 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
3867 * @phba: pointer to lpfc hba data structure.
3868 * @dev_grp: The HBA PCI-Device group number.
3870 * This routine is invoked to set up the per HBA PCI-Device group function
3871 * API jump table entries.
3873 * Return: 0 if success, otherwise -ENODEV
3876 lpfc_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
3880 /* Set up lpfc PCI-device group */
3881 phba
->pci_dev_grp
= dev_grp
;
3883 /* The LPFC_PCI_DEV_OC uses SLI4 */
3884 if (dev_grp
== LPFC_PCI_DEV_OC
)
3885 phba
->sli_rev
= LPFC_SLI_REV4
;
3887 /* Set up device INIT API function jump table */
3888 rc
= lpfc_init_api_table_setup(phba
, dev_grp
);
3891 /* Set up SCSI API function jump table */
3892 rc
= lpfc_scsi_api_table_setup(phba
, dev_grp
);
3895 /* Set up SLI API function jump table */
3896 rc
= lpfc_sli_api_table_setup(phba
, dev_grp
);
3899 /* Set up MBOX API function jump table */
3900 rc
= lpfc_mbox_api_table_setup(phba
, dev_grp
);
3908 * lpfc_log_intr_mode - Log the active interrupt mode
3909 * @phba: pointer to lpfc hba data structure.
3910 * @intr_mode: active interrupt mode adopted.
3912 * This routine it invoked to log the currently used active interrupt mode
3915 static void lpfc_log_intr_mode(struct lpfc_hba
*phba
, uint32_t intr_mode
)
3917 switch (intr_mode
) {
3919 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3920 "0470 Enable INTx interrupt mode.\n");
3923 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3924 "0481 Enabled MSI interrupt mode.\n");
3927 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3928 "0480 Enabled MSI-X interrupt mode.\n");
3931 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3932 "0482 Illegal interrupt mode.\n");
3939 * lpfc_enable_pci_dev - Enable a generic PCI device.
3940 * @phba: pointer to lpfc hba data structure.
3942 * This routine is invoked to enable the PCI device that is common to all
3947 * other values - error
3950 lpfc_enable_pci_dev(struct lpfc_hba
*phba
)
3952 struct pci_dev
*pdev
;
3955 /* Obtain PCI device reference */
3959 pdev
= phba
->pcidev
;
3960 /* Select PCI BARs */
3961 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
3962 /* Enable PCI device */
3963 if (pci_enable_device_mem(pdev
))
3965 /* Request PCI resource for the device */
3966 if (pci_request_selected_regions(pdev
, bars
, LPFC_DRIVER_NAME
))
3967 goto out_disable_device
;
3968 /* Set up device as PCI master and save state for EEH */
3969 pci_set_master(pdev
);
3970 pci_try_set_mwi(pdev
);
3971 pci_save_state(pdev
);
3973 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
3974 if (pci_find_capability(pdev
, PCI_CAP_ID_EXP
))
3975 pdev
->needs_freset
= 1;
3980 pci_disable_device(pdev
);
3986 * lpfc_disable_pci_dev - Disable a generic PCI device.
3987 * @phba: pointer to lpfc hba data structure.
3989 * This routine is invoked to disable the PCI device that is common to all
3993 lpfc_disable_pci_dev(struct lpfc_hba
*phba
)
3995 struct pci_dev
*pdev
;
3998 /* Obtain PCI device reference */
4002 pdev
= phba
->pcidev
;
4003 /* Select PCI BARs */
4004 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
4005 /* Release PCI resource and disable PCI device */
4006 pci_release_selected_regions(pdev
, bars
);
4007 pci_disable_device(pdev
);
4008 /* Null out PCI private reference to driver */
4009 pci_set_drvdata(pdev
, NULL
);
4015 * lpfc_reset_hba - Reset a hba
4016 * @phba: pointer to lpfc hba data structure.
4018 * This routine is invoked to reset a hba device. It brings the HBA
4019 * offline, performs a board restart, and then brings the board back
4020 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4021 * on outstanding mailbox commands.
4024 lpfc_reset_hba(struct lpfc_hba
*phba
)
4026 /* If resets are disabled then set error state and return. */
4027 if (!phba
->cfg_enable_hba_reset
) {
4028 phba
->link_state
= LPFC_HBA_ERROR
;
4031 lpfc_offline_prep(phba
);
4033 lpfc_sli_brdrestart(phba
);
4035 lpfc_unblock_mgmt_io(phba
);
4039 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4040 * @phba: pointer to lpfc hba data structure.
4042 * This function enables the PCI SR-IOV virtual functions to a physical
4043 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4044 * enable the number of virtual functions to the physical function. As
4045 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4046 * API call does not considered as an error condition for most of the device.
4049 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba
*phba
)
4051 struct pci_dev
*pdev
= phba
->pcidev
;
4055 if (!pdev
->is_physfn
)
4058 pos
= pci_find_ext_capability(pdev
, PCI_EXT_CAP_ID_SRIOV
);
4062 pci_read_config_word(pdev
, pos
+ PCI_SRIOV_TOTAL_VF
, &nr_virtfn
);
4067 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4068 * @phba: pointer to lpfc hba data structure.
4069 * @nr_vfn: number of virtual functions to be enabled.
4071 * This function enables the PCI SR-IOV virtual functions to a physical
4072 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4073 * enable the number of virtual functions to the physical function. As
4074 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4075 * API call does not considered as an error condition for most of the device.
4078 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba
*phba
, int nr_vfn
)
4080 struct pci_dev
*pdev
= phba
->pcidev
;
4081 uint16_t max_nr_vfn
;
4084 max_nr_vfn
= lpfc_sli_sriov_nr_virtfn_get(phba
);
4085 if (nr_vfn
> max_nr_vfn
) {
4086 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4087 "3057 Requested vfs (%d) greater than "
4088 "supported vfs (%d)", nr_vfn
, max_nr_vfn
);
4092 rc
= pci_enable_sriov(pdev
, nr_vfn
);
4094 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4095 "2806 Failed to enable sriov on this device "
4096 "with vfn number nr_vf:%d, rc:%d\n",
4099 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4100 "2807 Successful enable sriov on this device "
4101 "with vfn number nr_vf:%d\n", nr_vfn
);
4106 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
4107 * @phba: pointer to lpfc hba data structure.
4109 * This routine is invoked to set up the driver internal resources specific to
4110 * support the SLI-3 HBA device it attached to.
4114 * other values - error
4117 lpfc_sli_driver_resource_setup(struct lpfc_hba
*phba
)
4119 struct lpfc_sli
*psli
;
4123 * Initialize timers used by driver
4126 /* Heartbeat timer */
4127 init_timer(&phba
->hb_tmofunc
);
4128 phba
->hb_tmofunc
.function
= lpfc_hb_timeout
;
4129 phba
->hb_tmofunc
.data
= (unsigned long)phba
;
4132 /* MBOX heartbeat timer */
4133 init_timer(&psli
->mbox_tmo
);
4134 psli
->mbox_tmo
.function
= lpfc_mbox_timeout
;
4135 psli
->mbox_tmo
.data
= (unsigned long) phba
;
4136 /* FCP polling mode timer */
4137 init_timer(&phba
->fcp_poll_timer
);
4138 phba
->fcp_poll_timer
.function
= lpfc_poll_timeout
;
4139 phba
->fcp_poll_timer
.data
= (unsigned long) phba
;
4140 /* Fabric block timer */
4141 init_timer(&phba
->fabric_block_timer
);
4142 phba
->fabric_block_timer
.function
= lpfc_fabric_block_timeout
;
4143 phba
->fabric_block_timer
.data
= (unsigned long) phba
;
4144 /* EA polling mode timer */
4145 init_timer(&phba
->eratt_poll
);
4146 phba
->eratt_poll
.function
= lpfc_poll_eratt
;
4147 phba
->eratt_poll
.data
= (unsigned long) phba
;
4149 /* Host attention work mask setup */
4150 phba
->work_ha_mask
= (HA_ERATT
| HA_MBATT
| HA_LATT
);
4151 phba
->work_ha_mask
|= (HA_RXMASK
<< (LPFC_ELS_RING
* 4));
4153 /* Get all the module params for configuring this host */
4154 lpfc_get_cfgparam(phba
);
4155 if (phba
->pcidev
->device
== PCI_DEVICE_ID_HORNET
) {
4156 phba
->menlo_flag
|= HBA_MENLO_SUPPORT
;
4157 /* check for menlo minimum sg count */
4158 if (phba
->cfg_sg_seg_cnt
< LPFC_DEFAULT_MENLO_SG_SEG_CNT
)
4159 phba
->cfg_sg_seg_cnt
= LPFC_DEFAULT_MENLO_SG_SEG_CNT
;
4163 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4164 * used to create the sg_dma_buf_pool must be dynamically calculated.
4165 * 2 segments are added since the IOCB needs a command and response bde.
4167 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
4168 sizeof(struct fcp_rsp
) +
4169 ((phba
->cfg_sg_seg_cnt
+ 2) * sizeof(struct ulp_bde64
));
4171 if (phba
->cfg_enable_bg
) {
4172 phba
->cfg_sg_seg_cnt
= LPFC_MAX_SG_SEG_CNT
;
4173 phba
->cfg_sg_dma_buf_size
+=
4174 phba
->cfg_prot_sg_seg_cnt
* sizeof(struct ulp_bde64
);
4177 /* Also reinitialize the host templates with new values. */
4178 lpfc_vport_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
4179 lpfc_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
4181 phba
->max_vpi
= LPFC_MAX_VPI
;
4182 /* This will be set to correct value after config_port mbox */
4183 phba
->max_vports
= 0;
4186 * Initialize the SLI Layer to run with lpfc HBAs.
4188 lpfc_sli_setup(phba
);
4189 lpfc_sli_queue_setup(phba
);
4191 /* Allocate device driver memory */
4192 if (lpfc_mem_alloc(phba
, BPL_ALIGN_SZ
))
4196 * Enable sr-iov virtual functions if supported and configured
4197 * through the module parameter.
4199 if (phba
->cfg_sriov_nr_virtfn
> 0) {
4200 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
,
4201 phba
->cfg_sriov_nr_virtfn
);
4203 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4204 "2808 Requested number of SR-IOV "
4205 "virtual functions (%d) is not "
4207 phba
->cfg_sriov_nr_virtfn
);
4208 phba
->cfg_sriov_nr_virtfn
= 0;
4216 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
4217 * @phba: pointer to lpfc hba data structure.
4219 * This routine is invoked to unset the driver internal resources set up
4220 * specific for supporting the SLI-3 HBA device it attached to.
4223 lpfc_sli_driver_resource_unset(struct lpfc_hba
*phba
)
4225 /* Free device driver memory allocated */
4226 lpfc_mem_free_all(phba
);
4232 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
4233 * @phba: pointer to lpfc hba data structure.
4235 * This routine is invoked to set up the driver internal resources specific to
4236 * support the SLI-4 HBA device it attached to.
4240 * other values - error
4243 lpfc_sli4_driver_resource_setup(struct lpfc_hba
*phba
)
4245 struct lpfc_sli
*psli
;
4246 LPFC_MBOXQ_t
*mboxq
;
4247 int rc
, i
, hbq_count
, buf_size
, dma_buf_size
, max_buf_size
;
4248 uint8_t pn_page
[LPFC_MAX_SUPPORTED_PAGES
] = {0};
4249 struct lpfc_mqe
*mqe
;
4250 int longs
, sli_family
;
4252 /* Before proceed, wait for POST done and device ready */
4253 rc
= lpfc_sli4_post_status_check(phba
);
4258 * Initialize timers used by driver
4261 /* Heartbeat timer */
4262 init_timer(&phba
->hb_tmofunc
);
4263 phba
->hb_tmofunc
.function
= lpfc_hb_timeout
;
4264 phba
->hb_tmofunc
.data
= (unsigned long)phba
;
4265 init_timer(&phba
->rrq_tmr
);
4266 phba
->rrq_tmr
.function
= lpfc_rrq_timeout
;
4267 phba
->rrq_tmr
.data
= (unsigned long)phba
;
4270 /* MBOX heartbeat timer */
4271 init_timer(&psli
->mbox_tmo
);
4272 psli
->mbox_tmo
.function
= lpfc_mbox_timeout
;
4273 psli
->mbox_tmo
.data
= (unsigned long) phba
;
4274 /* Fabric block timer */
4275 init_timer(&phba
->fabric_block_timer
);
4276 phba
->fabric_block_timer
.function
= lpfc_fabric_block_timeout
;
4277 phba
->fabric_block_timer
.data
= (unsigned long) phba
;
4278 /* EA polling mode timer */
4279 init_timer(&phba
->eratt_poll
);
4280 phba
->eratt_poll
.function
= lpfc_poll_eratt
;
4281 phba
->eratt_poll
.data
= (unsigned long) phba
;
4282 /* FCF rediscover timer */
4283 init_timer(&phba
->fcf
.redisc_wait
);
4284 phba
->fcf
.redisc_wait
.function
= lpfc_sli4_fcf_redisc_wait_tmo
;
4285 phba
->fcf
.redisc_wait
.data
= (unsigned long)phba
;
4288 * Control structure for handling external multi-buffer mailbox
4289 * command pass-through.
4291 memset((uint8_t *)&phba
->mbox_ext_buf_ctx
, 0,
4292 sizeof(struct lpfc_mbox_ext_buf_ctx
));
4293 INIT_LIST_HEAD(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
4296 * We need to do a READ_CONFIG mailbox command here before
4297 * calling lpfc_get_cfgparam. For VFs this will report the
4298 * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
4299 * All of the resources allocated
4300 * for this Port are tied to these values.
4302 /* Get all the module params for configuring this host */
4303 lpfc_get_cfgparam(phba
);
4304 phba
->max_vpi
= LPFC_MAX_VPI
;
4305 /* This will be set to correct value after the read_config mbox */
4306 phba
->max_vports
= 0;
4308 /* Program the default value of vlan_id and fc_map */
4309 phba
->valid_vlan
= 0;
4310 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4311 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4312 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4315 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4316 * used to create the sg_dma_buf_pool must be dynamically calculated.
4317 * 2 segments are added since the IOCB needs a command and response bde.
4318 * To insure that the scsi sgl does not cross a 4k page boundary only
4319 * sgl sizes of must be a power of 2.
4321 buf_size
= (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
) +
4322 ((phba
->cfg_sg_seg_cnt
+ 2) * sizeof(struct sli4_sge
)));
4324 sli_family
= bf_get(lpfc_sli_intf_sli_family
, &phba
->sli4_hba
.sli_intf
);
4325 max_buf_size
= LPFC_SLI4_MAX_BUF_SIZE
;
4326 switch (sli_family
) {
4327 case LPFC_SLI_INTF_FAMILY_BE2
:
4328 case LPFC_SLI_INTF_FAMILY_BE3
:
4329 /* There is a single hint for BE - 2 pages per BPL. */
4330 if (bf_get(lpfc_sli_intf_sli_hint1
, &phba
->sli4_hba
.sli_intf
) ==
4331 LPFC_SLI_INTF_SLI_HINT1_1
)
4332 max_buf_size
= LPFC_SLI4_FL1_MAX_BUF_SIZE
;
4334 case LPFC_SLI_INTF_FAMILY_LNCR_A0
:
4335 case LPFC_SLI_INTF_FAMILY_LNCR_B0
:
4339 for (dma_buf_size
= LPFC_SLI4_MIN_BUF_SIZE
;
4340 dma_buf_size
< max_buf_size
&& buf_size
> dma_buf_size
;
4341 dma_buf_size
= dma_buf_size
<< 1)
4343 if (dma_buf_size
== max_buf_size
)
4344 phba
->cfg_sg_seg_cnt
= (dma_buf_size
-
4345 sizeof(struct fcp_cmnd
) - sizeof(struct fcp_rsp
) -
4346 (2 * sizeof(struct sli4_sge
))) /
4347 sizeof(struct sli4_sge
);
4348 phba
->cfg_sg_dma_buf_size
= dma_buf_size
;
4350 /* Initialize buffer queue management fields */
4351 hbq_count
= lpfc_sli_hbq_count();
4352 for (i
= 0; i
< hbq_count
; ++i
)
4353 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
4354 INIT_LIST_HEAD(&phba
->rb_pend_list
);
4355 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_sli4_rb_alloc
;
4356 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_sli4_rb_free
;
4359 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
4361 /* Initialize the Abort scsi buffer list used by driver */
4362 spin_lock_init(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
4363 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
4364 /* This abort list used by worker thread */
4365 spin_lock_init(&phba
->sli4_hba
.abts_sgl_list_lock
);
4368 * Initialize driver internal slow-path work queues
4371 /* Driver internel slow-path CQ Event pool */
4372 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_cqe_event_pool
);
4373 /* Response IOCB work queue list */
4374 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_queue_event
);
4375 /* Asynchronous event CQ Event work queue list */
4376 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_asynce_work_queue
);
4377 /* Fast-path XRI aborted CQ Event work queue list */
4378 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
4379 /* Slow-path XRI aborted CQ Event work queue list */
4380 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
4381 /* Receive queue CQ Event work queue list */
4382 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_unsol_work_queue
);
4384 /* Initialize extent block lists. */
4385 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_blk_list
);
4386 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_xri_blk_list
);
4387 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_vfi_blk_list
);
4388 INIT_LIST_HEAD(&phba
->lpfc_vpi_blk_list
);
4390 /* Initialize the driver internal SLI layer lists. */
4391 lpfc_sli_setup(phba
);
4392 lpfc_sli_queue_setup(phba
);
4394 /* Allocate device driver memory */
4395 rc
= lpfc_mem_alloc(phba
, SGL_ALIGN_SZ
);
4399 /* IF Type 2 ports get initialized now. */
4400 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
4401 LPFC_SLI_INTF_IF_TYPE_2
) {
4402 rc
= lpfc_pci_function_reset(phba
);
4407 /* Create the bootstrap mailbox command */
4408 rc
= lpfc_create_bootstrap_mbox(phba
);
4412 /* Set up the host's endian order with the device. */
4413 rc
= lpfc_setup_endian_order(phba
);
4415 goto out_free_bsmbx
;
4417 /* Set up the hba's configuration parameters. */
4418 rc
= lpfc_sli4_read_config(phba
);
4420 goto out_free_bsmbx
;
4422 /* IF Type 0 ports get initialized now. */
4423 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
4424 LPFC_SLI_INTF_IF_TYPE_0
) {
4425 rc
= lpfc_pci_function_reset(phba
);
4427 goto out_free_bsmbx
;
4430 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
4434 goto out_free_bsmbx
;
4437 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
4438 lpfc_supported_pages(mboxq
);
4439 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4441 mqe
= &mboxq
->u
.mqe
;
4442 memcpy(&pn_page
[0], ((uint8_t *)&mqe
->un
.supp_pages
.word3
),
4443 LPFC_MAX_SUPPORTED_PAGES
);
4444 for (i
= 0; i
< LPFC_MAX_SUPPORTED_PAGES
; i
++) {
4445 switch (pn_page
[i
]) {
4446 case LPFC_SLI4_PARAMETERS
:
4447 phba
->sli4_hba
.pc_sli4_params
.supported
= 1;
4453 /* Read the port's SLI4 Parameters capabilities if supported. */
4454 if (phba
->sli4_hba
.pc_sli4_params
.supported
)
4455 rc
= lpfc_pc_sli4_params_get(phba
, mboxq
);
4457 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4459 goto out_free_bsmbx
;
4463 * Get sli4 parameters that override parameters from Port capabilities.
4464 * If this call fails, it isn't critical unless the SLI4 parameters come
4467 rc
= lpfc_get_sli4_parameters(phba
, mboxq
);
4469 if (phba
->sli4_hba
.extents_in_use
&&
4470 phba
->sli4_hba
.rpi_hdrs_in_use
) {
4471 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4472 "2999 Unsupported SLI4 Parameters "
4473 "Extents and RPI headers enabled.\n");
4474 goto out_free_bsmbx
;
4477 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4478 /* Create all the SLI4 queues */
4479 rc
= lpfc_sli4_queue_create(phba
);
4481 goto out_free_bsmbx
;
4483 /* Create driver internal CQE event pool */
4484 rc
= lpfc_sli4_cq_event_pool_create(phba
);
4486 goto out_destroy_queue
;
4488 /* Initialize and populate the iocb list per host */
4489 rc
= lpfc_init_sgl_list(phba
);
4491 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4492 "1400 Failed to initialize sgl list.\n");
4493 goto out_destroy_cq_event_pool
;
4495 rc
= lpfc_init_active_sgl_array(phba
);
4497 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4498 "1430 Failed to initialize sgl list.\n");
4499 goto out_free_sgl_list
;
4501 rc
= lpfc_sli4_init_rpi_hdrs(phba
);
4503 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4504 "1432 Failed to initialize rpi headers.\n");
4505 goto out_free_active_sgl
;
4508 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
4509 longs
= (LPFC_SLI4_FCF_TBL_INDX_MAX
+ BITS_PER_LONG
- 1)/BITS_PER_LONG
;
4510 phba
->fcf
.fcf_rr_bmask
= kzalloc(longs
* sizeof(unsigned long),
4512 if (!phba
->fcf
.fcf_rr_bmask
) {
4513 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4514 "2759 Failed allocate memory for FCF round "
4515 "robin failover bmask\n");
4517 goto out_remove_rpi_hdrs
;
4520 phba
->sli4_hba
.fcp_eq_hdl
= kzalloc((sizeof(struct lpfc_fcp_eq_hdl
) *
4521 phba
->cfg_fcp_eq_count
), GFP_KERNEL
);
4522 if (!phba
->sli4_hba
.fcp_eq_hdl
) {
4523 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4524 "2572 Failed allocate memory for fast-path "
4525 "per-EQ handle array\n");
4527 goto out_free_fcf_rr_bmask
;
4530 phba
->sli4_hba
.msix_entries
= kzalloc((sizeof(struct msix_entry
) *
4531 phba
->sli4_hba
.cfg_eqn
), GFP_KERNEL
);
4532 if (!phba
->sli4_hba
.msix_entries
) {
4533 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4534 "2573 Failed allocate memory for msi-x "
4535 "interrupt vector entries\n");
4537 goto out_free_fcp_eq_hdl
;
4541 * Enable sr-iov virtual functions if supported and configured
4542 * through the module parameter.
4544 if (phba
->cfg_sriov_nr_virtfn
> 0) {
4545 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
,
4546 phba
->cfg_sriov_nr_virtfn
);
4548 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4549 "3020 Requested number of SR-IOV "
4550 "virtual functions (%d) is not "
4552 phba
->cfg_sriov_nr_virtfn
);
4553 phba
->cfg_sriov_nr_virtfn
= 0;
4559 out_free_fcp_eq_hdl
:
4560 kfree(phba
->sli4_hba
.fcp_eq_hdl
);
4561 out_free_fcf_rr_bmask
:
4562 kfree(phba
->fcf
.fcf_rr_bmask
);
4563 out_remove_rpi_hdrs
:
4564 lpfc_sli4_remove_rpi_hdrs(phba
);
4565 out_free_active_sgl
:
4566 lpfc_free_active_sgl(phba
);
4568 lpfc_free_sgl_list(phba
);
4569 out_destroy_cq_event_pool
:
4570 lpfc_sli4_cq_event_pool_destroy(phba
);
4572 lpfc_sli4_queue_destroy(phba
);
4574 lpfc_destroy_bootstrap_mbox(phba
);
4576 lpfc_mem_free(phba
);
4581 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
4582 * @phba: pointer to lpfc hba data structure.
4584 * This routine is invoked to unset the driver internal resources set up
4585 * specific for supporting the SLI-4 HBA device it attached to.
4588 lpfc_sli4_driver_resource_unset(struct lpfc_hba
*phba
)
4590 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
4592 /* Free memory allocated for msi-x interrupt vector entries */
4593 kfree(phba
->sli4_hba
.msix_entries
);
4595 /* Free memory allocated for fast-path work queue handles */
4596 kfree(phba
->sli4_hba
.fcp_eq_hdl
);
4598 /* Free the allocated rpi headers. */
4599 lpfc_sli4_remove_rpi_hdrs(phba
);
4600 lpfc_sli4_remove_rpis(phba
);
4602 /* Free eligible FCF index bmask */
4603 kfree(phba
->fcf
.fcf_rr_bmask
);
4605 /* Free the ELS sgl list */
4606 lpfc_free_active_sgl(phba
);
4607 lpfc_free_sgl_list(phba
);
4609 /* Free the SCSI sgl management array */
4610 kfree(phba
->sli4_hba
.lpfc_scsi_psb_array
);
4612 /* Free the SLI4 queues */
4613 lpfc_sli4_queue_destroy(phba
);
4615 /* Free the completion queue EQ event pool */
4616 lpfc_sli4_cq_event_release_all(phba
);
4617 lpfc_sli4_cq_event_pool_destroy(phba
);
4619 /* Release resource identifiers. */
4620 lpfc_sli4_dealloc_resource_identifiers(phba
);
4622 /* Free the bsmbx region. */
4623 lpfc_destroy_bootstrap_mbox(phba
);
4625 /* Free the SLI Layer memory with SLI4 HBAs */
4626 lpfc_mem_free_all(phba
);
4628 /* Free the current connect table */
4629 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
4630 &phba
->fcf_conn_rec_list
, list
) {
4631 list_del_init(&conn_entry
->list
);
4639 * lpfc_init_api_table_setup - Set up init api function jump table
4640 * @phba: The hba struct for which this call is being executed.
4641 * @dev_grp: The HBA PCI-Device group number.
4643 * This routine sets up the device INIT interface API function jump table
4646 * Returns: 0 - success, -ENODEV - failure.
4649 lpfc_init_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
4651 phba
->lpfc_hba_init_link
= lpfc_hba_init_link
;
4652 phba
->lpfc_hba_down_link
= lpfc_hba_down_link
;
4653 phba
->lpfc_selective_reset
= lpfc_selective_reset
;
4655 case LPFC_PCI_DEV_LP
:
4656 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s3
;
4657 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s3
;
4658 phba
->lpfc_stop_port
= lpfc_stop_port_s3
;
4660 case LPFC_PCI_DEV_OC
:
4661 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s4
;
4662 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s4
;
4663 phba
->lpfc_stop_port
= lpfc_stop_port_s4
;
4666 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4667 "1431 Invalid HBA PCI-device group: 0x%x\n",
4676 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
4677 * @phba: pointer to lpfc hba data structure.
4679 * This routine is invoked to set up the driver internal resources before the
4680 * device specific resource setup to support the HBA device it attached to.
4684 * other values - error
4687 lpfc_setup_driver_resource_phase1(struct lpfc_hba
*phba
)
4690 * Driver resources common to all SLI revisions
4692 atomic_set(&phba
->fast_event_count
, 0);
4693 spin_lock_init(&phba
->hbalock
);
4695 /* Initialize ndlp management spinlock */
4696 spin_lock_init(&phba
->ndlp_lock
);
4698 INIT_LIST_HEAD(&phba
->port_list
);
4699 INIT_LIST_HEAD(&phba
->work_list
);
4700 init_waitqueue_head(&phba
->wait_4_mlo_m_q
);
4702 /* Initialize the wait queue head for the kernel thread */
4703 init_waitqueue_head(&phba
->work_waitq
);
4705 /* Initialize the scsi buffer list used by driver for scsi IO */
4706 spin_lock_init(&phba
->scsi_buf_list_lock
);
4707 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list
);
4709 /* Initialize the fabric iocb list */
4710 INIT_LIST_HEAD(&phba
->fabric_iocb_list
);
4712 /* Initialize list to save ELS buffers */
4713 INIT_LIST_HEAD(&phba
->elsbuf
);
4715 /* Initialize FCF connection rec list */
4716 INIT_LIST_HEAD(&phba
->fcf_conn_rec_list
);
4722 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
4723 * @phba: pointer to lpfc hba data structure.
4725 * This routine is invoked to set up the driver internal resources after the
4726 * device specific resource setup to support the HBA device it attached to.
4730 * other values - error
4733 lpfc_setup_driver_resource_phase2(struct lpfc_hba
*phba
)
4737 /* Startup the kernel thread for this host adapter. */
4738 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
4739 "lpfc_worker_%d", phba
->brd_no
);
4740 if (IS_ERR(phba
->worker_thread
)) {
4741 error
= PTR_ERR(phba
->worker_thread
);
4749 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
4750 * @phba: pointer to lpfc hba data structure.
4752 * This routine is invoked to unset the driver internal resources set up after
4753 * the device specific resource setup for supporting the HBA device it
4757 lpfc_unset_driver_resource_phase2(struct lpfc_hba
*phba
)
4759 /* Stop kernel worker thread */
4760 kthread_stop(phba
->worker_thread
);
4764 * lpfc_free_iocb_list - Free iocb list.
4765 * @phba: pointer to lpfc hba data structure.
4767 * This routine is invoked to free the driver's IOCB list and memory.
4770 lpfc_free_iocb_list(struct lpfc_hba
*phba
)
4772 struct lpfc_iocbq
*iocbq_entry
= NULL
, *iocbq_next
= NULL
;
4774 spin_lock_irq(&phba
->hbalock
);
4775 list_for_each_entry_safe(iocbq_entry
, iocbq_next
,
4776 &phba
->lpfc_iocb_list
, list
) {
4777 list_del(&iocbq_entry
->list
);
4779 phba
->total_iocbq_bufs
--;
4781 spin_unlock_irq(&phba
->hbalock
);
4787 * lpfc_init_iocb_list - Allocate and initialize iocb list.
4788 * @phba: pointer to lpfc hba data structure.
4790 * This routine is invoked to allocate and initizlize the driver's IOCB
4791 * list and set up the IOCB tag array accordingly.
4795 * other values - error
4798 lpfc_init_iocb_list(struct lpfc_hba
*phba
, int iocb_count
)
4800 struct lpfc_iocbq
*iocbq_entry
= NULL
;
4804 /* Initialize and populate the iocb list per host. */
4805 INIT_LIST_HEAD(&phba
->lpfc_iocb_list
);
4806 for (i
= 0; i
< iocb_count
; i
++) {
4807 iocbq_entry
= kzalloc(sizeof(struct lpfc_iocbq
), GFP_KERNEL
);
4808 if (iocbq_entry
== NULL
) {
4809 printk(KERN_ERR
"%s: only allocated %d iocbs of "
4810 "expected %d count. Unloading driver.\n",
4811 __func__
, i
, LPFC_IOCB_LIST_CNT
);
4812 goto out_free_iocbq
;
4815 iotag
= lpfc_sli_next_iotag(phba
, iocbq_entry
);
4818 printk(KERN_ERR
"%s: failed to allocate IOTAG. "
4819 "Unloading driver.\n", __func__
);
4820 goto out_free_iocbq
;
4822 iocbq_entry
->sli4_lxritag
= NO_XRI
;
4823 iocbq_entry
->sli4_xritag
= NO_XRI
;
4825 spin_lock_irq(&phba
->hbalock
);
4826 list_add(&iocbq_entry
->list
, &phba
->lpfc_iocb_list
);
4827 phba
->total_iocbq_bufs
++;
4828 spin_unlock_irq(&phba
->hbalock
);
4834 lpfc_free_iocb_list(phba
);
4840 * lpfc_free_sgl_list - Free sgl list.
4841 * @phba: pointer to lpfc hba data structure.
4843 * This routine is invoked to free the driver's sgl list and memory.
4846 lpfc_free_sgl_list(struct lpfc_hba
*phba
)
4848 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
4849 LIST_HEAD(sglq_list
);
4851 spin_lock_irq(&phba
->hbalock
);
4852 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &sglq_list
);
4853 spin_unlock_irq(&phba
->hbalock
);
4855 list_for_each_entry_safe(sglq_entry
, sglq_next
,
4857 list_del(&sglq_entry
->list
);
4858 lpfc_mbuf_free(phba
, sglq_entry
->virt
, sglq_entry
->phys
);
4860 phba
->sli4_hba
.total_sglq_bufs
--;
4862 kfree(phba
->sli4_hba
.lpfc_els_sgl_array
);
4866 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
4867 * @phba: pointer to lpfc hba data structure.
4869 * This routine is invoked to allocate the driver's active sgl memory.
4870 * This array will hold the sglq_entry's for active IOs.
4873 lpfc_init_active_sgl_array(struct lpfc_hba
*phba
)
4876 size
= sizeof(struct lpfc_sglq
*);
4877 size
*= phba
->sli4_hba
.max_cfg_param
.max_xri
;
4879 phba
->sli4_hba
.lpfc_sglq_active_list
=
4880 kzalloc(size
, GFP_KERNEL
);
4881 if (!phba
->sli4_hba
.lpfc_sglq_active_list
)
4887 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
4888 * @phba: pointer to lpfc hba data structure.
4890 * This routine is invoked to walk through the array of active sglq entries
4891 * and free all of the resources.
4892 * This is just a place holder for now.
4895 lpfc_free_active_sgl(struct lpfc_hba
*phba
)
4897 kfree(phba
->sli4_hba
.lpfc_sglq_active_list
);
4901 * lpfc_init_sgl_list - Allocate and initialize sgl list.
4902 * @phba: pointer to lpfc hba data structure.
4904 * This routine is invoked to allocate and initizlize the driver's sgl
4905 * list and set up the sgl xritag tag array accordingly.
4909 * other values - error
4912 lpfc_init_sgl_list(struct lpfc_hba
*phba
)
4914 struct lpfc_sglq
*sglq_entry
= NULL
;
4918 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
4919 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4920 "2400 ELS XRI count %d.\n",
4922 /* Initialize and populate the sglq list per host/VF. */
4923 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_sgl_list
);
4924 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
4926 /* Sanity check on XRI management */
4927 if (phba
->sli4_hba
.max_cfg_param
.max_xri
<= els_xri_cnt
) {
4928 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4929 "2562 No room left for SCSI XRI allocation: "
4930 "max_xri=%d, els_xri=%d\n",
4931 phba
->sli4_hba
.max_cfg_param
.max_xri
,
4936 /* Allocate memory for the ELS XRI management array */
4937 phba
->sli4_hba
.lpfc_els_sgl_array
=
4938 kzalloc((sizeof(struct lpfc_sglq
*) * els_xri_cnt
),
4941 if (!phba
->sli4_hba
.lpfc_els_sgl_array
) {
4942 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4943 "2401 Failed to allocate memory for ELS "
4944 "XRI management array of size %d.\n",
4949 /* Keep the SCSI XRI into the XRI management array */
4950 phba
->sli4_hba
.scsi_xri_max
=
4951 phba
->sli4_hba
.max_cfg_param
.max_xri
- els_xri_cnt
;
4952 phba
->sli4_hba
.scsi_xri_cnt
= 0;
4953 phba
->sli4_hba
.lpfc_scsi_psb_array
=
4954 kzalloc((sizeof(struct lpfc_scsi_buf
*) *
4955 phba
->sli4_hba
.scsi_xri_max
), GFP_KERNEL
);
4957 if (!phba
->sli4_hba
.lpfc_scsi_psb_array
) {
4958 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4959 "2563 Failed to allocate memory for SCSI "
4960 "XRI management array of size %d.\n",
4961 phba
->sli4_hba
.scsi_xri_max
);
4962 kfree(phba
->sli4_hba
.lpfc_els_sgl_array
);
4966 for (i
= 0; i
< els_xri_cnt
; i
++) {
4967 sglq_entry
= kzalloc(sizeof(struct lpfc_sglq
), GFP_KERNEL
);
4968 if (sglq_entry
== NULL
) {
4969 printk(KERN_ERR
"%s: only allocated %d sgls of "
4970 "expected %d count. Unloading driver.\n",
4971 __func__
, i
, els_xri_cnt
);
4975 sglq_entry
->buff_type
= GEN_BUFF_TYPE
;
4976 sglq_entry
->virt
= lpfc_mbuf_alloc(phba
, 0, &sglq_entry
->phys
);
4977 if (sglq_entry
->virt
== NULL
) {
4979 printk(KERN_ERR
"%s: failed to allocate mbuf.\n"
4980 "Unloading driver.\n", __func__
);
4983 sglq_entry
->sgl
= sglq_entry
->virt
;
4984 memset(sglq_entry
->sgl
, 0, LPFC_BPL_SIZE
);
4986 /* The list order is used by later block SGL registraton */
4987 spin_lock_irq(&phba
->hbalock
);
4988 sglq_entry
->state
= SGL_FREED
;
4989 list_add_tail(&sglq_entry
->list
, &phba
->sli4_hba
.lpfc_sgl_list
);
4990 phba
->sli4_hba
.lpfc_els_sgl_array
[i
] = sglq_entry
;
4991 phba
->sli4_hba
.total_sglq_bufs
++;
4992 spin_unlock_irq(&phba
->hbalock
);
4997 kfree(phba
->sli4_hba
.lpfc_scsi_psb_array
);
4998 lpfc_free_sgl_list(phba
);
5003 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5004 * @phba: pointer to lpfc hba data structure.
5006 * This routine is invoked to post rpi header templates to the
5007 * port for those SLI4 ports that do not support extents. This routine
5008 * posts a PAGE_SIZE memory region to the port to hold up to
5009 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5010 * and should be called only when interrupts are disabled.
5014 * -ERROR - otherwise.
5017 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba
*phba
)
5020 struct lpfc_rpi_hdr
*rpi_hdr
;
5022 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_hdr_list
);
5024 * If the SLI4 port supports extents, posting the rpi header isn't
5025 * required. Set the expected maximum count and let the actual value
5026 * get set when extents are fully allocated.
5028 if (!phba
->sli4_hba
.rpi_hdrs_in_use
) {
5029 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.max_rpi
;
5032 if (phba
->sli4_hba
.extents_in_use
)
5035 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
5037 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5038 "0391 Error during rpi post operation\n");
5039 lpfc_sli4_remove_rpis(phba
);
5047 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
5048 * @phba: pointer to lpfc hba data structure.
5050 * This routine is invoked to allocate a single 4KB memory region to
5051 * support rpis and stores them in the phba. This single region
5052 * provides support for up to 64 rpis. The region is used globally
5056 * A valid rpi hdr on success.
5057 * A NULL pointer on any failure.
5059 struct lpfc_rpi_hdr
*
5060 lpfc_sli4_create_rpi_hdr(struct lpfc_hba
*phba
)
5062 uint16_t rpi_limit
, curr_rpi_range
;
5063 struct lpfc_dmabuf
*dmabuf
;
5064 struct lpfc_rpi_hdr
*rpi_hdr
;
5068 * If the SLI4 port supports extents, posting the rpi header isn't
5069 * required. Set the expected maximum count and let the actual value
5070 * get set when extents are fully allocated.
5072 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5074 if (phba
->sli4_hba
.extents_in_use
)
5077 /* The limit on the logical index is just the max_rpi count. */
5078 rpi_limit
= phba
->sli4_hba
.max_cfg_param
.rpi_base
+
5079 phba
->sli4_hba
.max_cfg_param
.max_rpi
- 1;
5081 spin_lock_irq(&phba
->hbalock
);
5083 * Establish the starting RPI in this header block. The starting
5084 * rpi is normalized to a zero base because the physical rpi is
5087 curr_rpi_range
= phba
->sli4_hba
.next_rpi
-
5088 phba
->sli4_hba
.max_cfg_param
.rpi_base
;
5089 spin_unlock_irq(&phba
->hbalock
);
5092 * The port has a limited number of rpis. The increment here
5093 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
5094 * and to allow the full max_rpi range per port.
5096 if ((curr_rpi_range
+ (LPFC_RPI_HDR_COUNT
- 1)) > rpi_limit
)
5097 rpi_count
= rpi_limit
- curr_rpi_range
;
5099 rpi_count
= LPFC_RPI_HDR_COUNT
;
5104 * First allocate the protocol header region for the port. The
5105 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
5107 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
5111 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
5112 LPFC_HDR_TEMPLATE_SIZE
,
5115 if (!dmabuf
->virt
) {
5117 goto err_free_dmabuf
;
5120 memset(dmabuf
->virt
, 0, LPFC_HDR_TEMPLATE_SIZE
);
5121 if (!IS_ALIGNED(dmabuf
->phys
, LPFC_HDR_TEMPLATE_SIZE
)) {
5123 goto err_free_coherent
;
5126 /* Save the rpi header data for cleanup later. */
5127 rpi_hdr
= kzalloc(sizeof(struct lpfc_rpi_hdr
), GFP_KERNEL
);
5129 goto err_free_coherent
;
5131 rpi_hdr
->dmabuf
= dmabuf
;
5132 rpi_hdr
->len
= LPFC_HDR_TEMPLATE_SIZE
;
5133 rpi_hdr
->page_count
= 1;
5134 spin_lock_irq(&phba
->hbalock
);
5136 /* The rpi_hdr stores the logical index only. */
5137 rpi_hdr
->start_rpi
= curr_rpi_range
;
5138 list_add_tail(&rpi_hdr
->list
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
);
5141 * The next_rpi stores the next logical module-64 rpi value used
5142 * to post physical rpis in subsequent rpi postings.
5144 phba
->sli4_hba
.next_rpi
+= rpi_count
;
5145 spin_unlock_irq(&phba
->hbalock
);
5149 dma_free_coherent(&phba
->pcidev
->dev
, LPFC_HDR_TEMPLATE_SIZE
,
5150 dmabuf
->virt
, dmabuf
->phys
);
5157 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
5158 * @phba: pointer to lpfc hba data structure.
5160 * This routine is invoked to remove all memory resources allocated
5161 * to support rpis for SLI4 ports not supporting extents. This routine
5162 * presumes the caller has released all rpis consumed by fabric or port
5163 * logins and is prepared to have the header pages removed.
5166 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba
*phba
)
5168 struct lpfc_rpi_hdr
*rpi_hdr
, *next_rpi_hdr
;
5170 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5173 list_for_each_entry_safe(rpi_hdr
, next_rpi_hdr
,
5174 &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
5175 list_del(&rpi_hdr
->list
);
5176 dma_free_coherent(&phba
->pcidev
->dev
, rpi_hdr
->len
,
5177 rpi_hdr
->dmabuf
->virt
, rpi_hdr
->dmabuf
->phys
);
5178 kfree(rpi_hdr
->dmabuf
);
5182 /* There are no rpis available to the port now. */
5183 phba
->sli4_hba
.next_rpi
= 0;
5187 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
5188 * @pdev: pointer to pci device data structure.
5190 * This routine is invoked to allocate the driver hba data structure for an
5191 * HBA device. If the allocation is successful, the phba reference to the
5192 * PCI device data structure is set.
5195 * pointer to @phba - successful
5198 static struct lpfc_hba
*
5199 lpfc_hba_alloc(struct pci_dev
*pdev
)
5201 struct lpfc_hba
*phba
;
5203 /* Allocate memory for HBA structure */
5204 phba
= kzalloc(sizeof(struct lpfc_hba
), GFP_KERNEL
);
5206 dev_err(&pdev
->dev
, "failed to allocate hba struct\n");
5210 /* Set reference to PCI device in HBA structure */
5211 phba
->pcidev
= pdev
;
5213 /* Assign an unused board number */
5214 phba
->brd_no
= lpfc_get_instance();
5215 if (phba
->brd_no
< 0) {
5220 spin_lock_init(&phba
->ct_ev_lock
);
5221 INIT_LIST_HEAD(&phba
->ct_ev_waiters
);
5227 * lpfc_hba_free - Free driver hba data structure with a device.
5228 * @phba: pointer to lpfc hba data structure.
5230 * This routine is invoked to free the driver hba data structure with an
5234 lpfc_hba_free(struct lpfc_hba
*phba
)
5236 /* Release the driver assigned board number */
5237 idr_remove(&lpfc_hba_index
, phba
->brd_no
);
5244 * lpfc_create_shost - Create hba physical port with associated scsi host.
5245 * @phba: pointer to lpfc hba data structure.
5247 * This routine is invoked to create HBA physical port and associate a SCSI
5252 * other values - error
5255 lpfc_create_shost(struct lpfc_hba
*phba
)
5257 struct lpfc_vport
*vport
;
5258 struct Scsi_Host
*shost
;
5260 /* Initialize HBA FC structure */
5261 phba
->fc_edtov
= FF_DEF_EDTOV
;
5262 phba
->fc_ratov
= FF_DEF_RATOV
;
5263 phba
->fc_altov
= FF_DEF_ALTOV
;
5264 phba
->fc_arbtov
= FF_DEF_ARBTOV
;
5266 atomic_set(&phba
->sdev_cnt
, 0);
5267 vport
= lpfc_create_port(phba
, phba
->brd_no
, &phba
->pcidev
->dev
);
5271 shost
= lpfc_shost_from_vport(vport
);
5272 phba
->pport
= vport
;
5273 lpfc_debugfs_initialize(vport
);
5274 /* Put reference to SCSI host to driver's device private data */
5275 pci_set_drvdata(phba
->pcidev
, shost
);
5281 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
5282 * @phba: pointer to lpfc hba data structure.
5284 * This routine is invoked to destroy HBA physical port and the associated
5288 lpfc_destroy_shost(struct lpfc_hba
*phba
)
5290 struct lpfc_vport
*vport
= phba
->pport
;
5292 /* Destroy physical port that associated with the SCSI host */
5293 destroy_port(vport
);
5299 * lpfc_setup_bg - Setup Block guard structures and debug areas.
5300 * @phba: pointer to lpfc hba data structure.
5301 * @shost: the shost to be used to detect Block guard settings.
5303 * This routine sets up the local Block guard protocol settings for @shost.
5304 * This routine also allocates memory for debugging bg buffers.
5307 lpfc_setup_bg(struct lpfc_hba
*phba
, struct Scsi_Host
*shost
)
5310 if (lpfc_prot_mask
&& lpfc_prot_guard
) {
5311 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5312 "1478 Registering BlockGuard with the "
5314 scsi_host_set_prot(shost
, lpfc_prot_mask
);
5315 scsi_host_set_guard(shost
, lpfc_prot_guard
);
5317 if (!_dump_buf_data
) {
5319 spin_lock_init(&_dump_buf_lock
);
5321 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
5322 if (_dump_buf_data
) {
5323 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5324 "9043 BLKGRD: allocated %d pages for "
5325 "_dump_buf_data at 0x%p\n",
5326 (1 << pagecnt
), _dump_buf_data
);
5327 _dump_buf_data_order
= pagecnt
;
5328 memset(_dump_buf_data
, 0,
5329 ((1 << PAGE_SHIFT
) << pagecnt
));
5334 if (!_dump_buf_data_order
)
5335 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5336 "9044 BLKGRD: ERROR unable to allocate "
5337 "memory for hexdump\n");
5339 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5340 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
5341 "\n", _dump_buf_data
);
5342 if (!_dump_buf_dif
) {
5345 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
5346 if (_dump_buf_dif
) {
5347 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5348 "9046 BLKGRD: allocated %d pages for "
5349 "_dump_buf_dif at 0x%p\n",
5350 (1 << pagecnt
), _dump_buf_dif
);
5351 _dump_buf_dif_order
= pagecnt
;
5352 memset(_dump_buf_dif
, 0,
5353 ((1 << PAGE_SHIFT
) << pagecnt
));
5358 if (!_dump_buf_dif_order
)
5359 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5360 "9047 BLKGRD: ERROR unable to allocate "
5361 "memory for hexdump\n");
5363 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5364 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
5369 * lpfc_post_init_setup - Perform necessary device post initialization setup.
5370 * @phba: pointer to lpfc hba data structure.
5372 * This routine is invoked to perform all the necessary post initialization
5373 * setup for the device.
5376 lpfc_post_init_setup(struct lpfc_hba
*phba
)
5378 struct Scsi_Host
*shost
;
5379 struct lpfc_adapter_event_header adapter_event
;
5381 /* Get the default values for Model Name and Description */
5382 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
5385 * hba setup may have changed the hba_queue_depth so we need to
5386 * adjust the value of can_queue.
5388 shost
= pci_get_drvdata(phba
->pcidev
);
5389 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
5390 if (phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)
5391 lpfc_setup_bg(phba
, shost
);
5393 lpfc_host_attrib_init(shost
);
5395 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
5396 spin_lock_irq(shost
->host_lock
);
5397 lpfc_poll_start_timer(phba
);
5398 spin_unlock_irq(shost
->host_lock
);
5401 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5402 "0428 Perform SCSI scan\n");
5403 /* Send board arrival event to upper layer */
5404 adapter_event
.event_type
= FC_REG_ADAPTER_EVENT
;
5405 adapter_event
.subcategory
= LPFC_EVENT_ARRIVAL
;
5406 fc_host_post_vendor_event(shost
, fc_get_event_number(),
5407 sizeof(adapter_event
),
5408 (char *) &adapter_event
,
5414 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
5415 * @phba: pointer to lpfc hba data structure.
5417 * This routine is invoked to set up the PCI device memory space for device
5418 * with SLI-3 interface spec.
5422 * other values - error
5425 lpfc_sli_pci_mem_setup(struct lpfc_hba
*phba
)
5427 struct pci_dev
*pdev
;
5428 unsigned long bar0map_len
, bar2map_len
;
5431 int error
= -ENODEV
;
5433 /* Obtain PCI device reference */
5437 pdev
= phba
->pcidev
;
5439 /* Set the device DMA mask size */
5440 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
5441 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
5442 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
5443 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
5448 /* Get the bus address of Bar0 and Bar2 and the number of bytes
5449 * required by each mapping.
5451 phba
->pci_bar0_map
= pci_resource_start(pdev
, 0);
5452 bar0map_len
= pci_resource_len(pdev
, 0);
5454 phba
->pci_bar2_map
= pci_resource_start(pdev
, 2);
5455 bar2map_len
= pci_resource_len(pdev
, 2);
5457 /* Map HBA SLIM to a kernel virtual address. */
5458 phba
->slim_memmap_p
= ioremap(phba
->pci_bar0_map
, bar0map_len
);
5459 if (!phba
->slim_memmap_p
) {
5460 dev_printk(KERN_ERR
, &pdev
->dev
,
5461 "ioremap failed for SLIM memory.\n");
5465 /* Map HBA Control Registers to a kernel virtual address. */
5466 phba
->ctrl_regs_memmap_p
= ioremap(phba
->pci_bar2_map
, bar2map_len
);
5467 if (!phba
->ctrl_regs_memmap_p
) {
5468 dev_printk(KERN_ERR
, &pdev
->dev
,
5469 "ioremap failed for HBA control registers.\n");
5470 goto out_iounmap_slim
;
5473 /* Allocate memory for SLI-2 structures */
5474 phba
->slim2p
.virt
= dma_alloc_coherent(&pdev
->dev
,
5478 if (!phba
->slim2p
.virt
)
5481 memset(phba
->slim2p
.virt
, 0, SLI2_SLIM_SIZE
);
5482 phba
->mbox
= phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, mbx
);
5483 phba
->mbox_ext
= (phba
->slim2p
.virt
+
5484 offsetof(struct lpfc_sli2_slim
, mbx_ext_words
));
5485 phba
->pcb
= (phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, pcb
));
5486 phba
->IOCBs
= (phba
->slim2p
.virt
+
5487 offsetof(struct lpfc_sli2_slim
, IOCBs
));
5489 phba
->hbqslimp
.virt
= dma_alloc_coherent(&pdev
->dev
,
5490 lpfc_sli_hbq_size(),
5491 &phba
->hbqslimp
.phys
,
5493 if (!phba
->hbqslimp
.virt
)
5496 hbq_count
= lpfc_sli_hbq_count();
5497 ptr
= phba
->hbqslimp
.virt
;
5498 for (i
= 0; i
< hbq_count
; ++i
) {
5499 phba
->hbqs
[i
].hbq_virt
= ptr
;
5500 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
5501 ptr
+= (lpfc_hbq_defs
[i
]->entry_count
*
5502 sizeof(struct lpfc_hbq_entry
));
5504 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_els_hbq_alloc
;
5505 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_els_hbq_free
;
5507 memset(phba
->hbqslimp
.virt
, 0, lpfc_sli_hbq_size());
5509 INIT_LIST_HEAD(&phba
->rb_pend_list
);
5511 phba
->MBslimaddr
= phba
->slim_memmap_p
;
5512 phba
->HAregaddr
= phba
->ctrl_regs_memmap_p
+ HA_REG_OFFSET
;
5513 phba
->CAregaddr
= phba
->ctrl_regs_memmap_p
+ CA_REG_OFFSET
;
5514 phba
->HSregaddr
= phba
->ctrl_regs_memmap_p
+ HS_REG_OFFSET
;
5515 phba
->HCregaddr
= phba
->ctrl_regs_memmap_p
+ HC_REG_OFFSET
;
5520 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
5521 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
5523 iounmap(phba
->ctrl_regs_memmap_p
);
5525 iounmap(phba
->slim_memmap_p
);
5531 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
5532 * @phba: pointer to lpfc hba data structure.
5534 * This routine is invoked to unset the PCI device memory space for device
5535 * with SLI-3 interface spec.
5538 lpfc_sli_pci_mem_unset(struct lpfc_hba
*phba
)
5540 struct pci_dev
*pdev
;
5542 /* Obtain PCI device reference */
5546 pdev
= phba
->pcidev
;
5548 /* Free coherent DMA memory allocated */
5549 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
5550 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
5551 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
5552 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
5554 /* I/O memory unmap */
5555 iounmap(phba
->ctrl_regs_memmap_p
);
5556 iounmap(phba
->slim_memmap_p
);
5562 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
5563 * @phba: pointer to lpfc hba data structure.
5565 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
5566 * done and check status.
5568 * Return 0 if successful, otherwise -ENODEV.
5571 lpfc_sli4_post_status_check(struct lpfc_hba
*phba
)
5573 struct lpfc_register portsmphr_reg
, uerrlo_reg
, uerrhi_reg
;
5574 struct lpfc_register reg_data
;
5575 int i
, port_error
= 0;
5578 memset(&portsmphr_reg
, 0, sizeof(portsmphr_reg
));
5579 memset(®_data
, 0, sizeof(reg_data
));
5580 if (!phba
->sli4_hba
.PSMPHRregaddr
)
5583 /* Wait up to 30 seconds for the SLI Port POST done and ready */
5584 for (i
= 0; i
< 3000; i
++) {
5585 if (lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
5586 &portsmphr_reg
.word0
) ||
5587 (bf_get(lpfc_port_smphr_perr
, &portsmphr_reg
))) {
5588 /* Port has a fatal POST error, break out */
5589 port_error
= -ENODEV
;
5592 if (LPFC_POST_STAGE_PORT_READY
==
5593 bf_get(lpfc_port_smphr_port_status
, &portsmphr_reg
))
5599 * If there was a port error during POST, then don't proceed with
5600 * other register reads as the data may not be valid. Just exit.
5603 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5604 "1408 Port Failed POST - portsmphr=0x%x, "
5605 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
5606 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
5607 portsmphr_reg
.word0
,
5608 bf_get(lpfc_port_smphr_perr
, &portsmphr_reg
),
5609 bf_get(lpfc_port_smphr_sfi
, &portsmphr_reg
),
5610 bf_get(lpfc_port_smphr_nip
, &portsmphr_reg
),
5611 bf_get(lpfc_port_smphr_ipc
, &portsmphr_reg
),
5612 bf_get(lpfc_port_smphr_scr1
, &portsmphr_reg
),
5613 bf_get(lpfc_port_smphr_scr2
, &portsmphr_reg
),
5614 bf_get(lpfc_port_smphr_host_scratch
, &portsmphr_reg
),
5615 bf_get(lpfc_port_smphr_port_status
, &portsmphr_reg
));
5617 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5618 "2534 Device Info: SLIFamily=0x%x, "
5619 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
5620 "SLIHint_2=0x%x, FT=0x%x\n",
5621 bf_get(lpfc_sli_intf_sli_family
,
5622 &phba
->sli4_hba
.sli_intf
),
5623 bf_get(lpfc_sli_intf_slirev
,
5624 &phba
->sli4_hba
.sli_intf
),
5625 bf_get(lpfc_sli_intf_if_type
,
5626 &phba
->sli4_hba
.sli_intf
),
5627 bf_get(lpfc_sli_intf_sli_hint1
,
5628 &phba
->sli4_hba
.sli_intf
),
5629 bf_get(lpfc_sli_intf_sli_hint2
,
5630 &phba
->sli4_hba
.sli_intf
),
5631 bf_get(lpfc_sli_intf_func_type
,
5632 &phba
->sli4_hba
.sli_intf
));
5634 * Check for other Port errors during the initialization
5635 * process. Fail the load if the port did not come up
5638 if_type
= bf_get(lpfc_sli_intf_if_type
,
5639 &phba
->sli4_hba
.sli_intf
);
5641 case LPFC_SLI_INTF_IF_TYPE_0
:
5642 phba
->sli4_hba
.ue_mask_lo
=
5643 readl(phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
);
5644 phba
->sli4_hba
.ue_mask_hi
=
5645 readl(phba
->sli4_hba
.u
.if_type0
.UEMASKHIregaddr
);
5647 readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
);
5649 readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
);
5650 if ((~phba
->sli4_hba
.ue_mask_lo
& uerrlo_reg
.word0
) ||
5651 (~phba
->sli4_hba
.ue_mask_hi
& uerrhi_reg
.word0
)) {
5652 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5653 "1422 Unrecoverable Error "
5654 "Detected during POST "
5655 "uerr_lo_reg=0x%x, "
5656 "uerr_hi_reg=0x%x, "
5657 "ue_mask_lo_reg=0x%x, "
5658 "ue_mask_hi_reg=0x%x\n",
5661 phba
->sli4_hba
.ue_mask_lo
,
5662 phba
->sli4_hba
.ue_mask_hi
);
5663 port_error
= -ENODEV
;
5666 case LPFC_SLI_INTF_IF_TYPE_2
:
5667 /* Final checks. The port status should be clean. */
5668 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
5670 (bf_get(lpfc_sliport_status_err
, ®_data
) &&
5671 !bf_get(lpfc_sliport_status_rn
, ®_data
))) {
5672 phba
->work_status
[0] =
5673 readl(phba
->sli4_hba
.u
.if_type2
.
5675 phba
->work_status
[1] =
5676 readl(phba
->sli4_hba
.u
.if_type2
.
5678 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5679 "2888 Port Error Detected "
5681 "port status reg 0x%x, "
5682 "port_smphr reg 0x%x, "
5683 "error 1=0x%x, error 2=0x%x\n",
5685 portsmphr_reg
.word0
,
5686 phba
->work_status
[0],
5687 phba
->work_status
[1]);
5688 port_error
= -ENODEV
;
5691 case LPFC_SLI_INTF_IF_TYPE_1
:
5700 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
5701 * @phba: pointer to lpfc hba data structure.
5702 * @if_type: The SLI4 interface type getting configured.
5704 * This routine is invoked to set up SLI4 BAR0 PCI config space register
5708 lpfc_sli4_bar0_register_memmap(struct lpfc_hba
*phba
, uint32_t if_type
)
5711 case LPFC_SLI_INTF_IF_TYPE_0
:
5712 phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
=
5713 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UERR_STATUS_LO
;
5714 phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
=
5715 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UERR_STATUS_HI
;
5716 phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
=
5717 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UE_MASK_LO
;
5718 phba
->sli4_hba
.u
.if_type0
.UEMASKHIregaddr
=
5719 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UE_MASK_HI
;
5720 phba
->sli4_hba
.SLIINTFregaddr
=
5721 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_SLI_INTF
;
5723 case LPFC_SLI_INTF_IF_TYPE_2
:
5724 phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
=
5725 phba
->sli4_hba
.conf_regs_memmap_p
+
5726 LPFC_CTL_PORT_ER1_OFFSET
;
5727 phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
=
5728 phba
->sli4_hba
.conf_regs_memmap_p
+
5729 LPFC_CTL_PORT_ER2_OFFSET
;
5730 phba
->sli4_hba
.u
.if_type2
.CTRLregaddr
=
5731 phba
->sli4_hba
.conf_regs_memmap_p
+
5732 LPFC_CTL_PORT_CTL_OFFSET
;
5733 phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
=
5734 phba
->sli4_hba
.conf_regs_memmap_p
+
5735 LPFC_CTL_PORT_STA_OFFSET
;
5736 phba
->sli4_hba
.SLIINTFregaddr
=
5737 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_SLI_INTF
;
5738 phba
->sli4_hba
.PSMPHRregaddr
=
5739 phba
->sli4_hba
.conf_regs_memmap_p
+
5740 LPFC_CTL_PORT_SEM_OFFSET
;
5741 phba
->sli4_hba
.RQDBregaddr
=
5742 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_RQ_DOORBELL
;
5743 phba
->sli4_hba
.WQDBregaddr
=
5744 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_WQ_DOORBELL
;
5745 phba
->sli4_hba
.EQCQDBregaddr
=
5746 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_EQCQ_DOORBELL
;
5747 phba
->sli4_hba
.MQDBregaddr
=
5748 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_MQ_DOORBELL
;
5749 phba
->sli4_hba
.BMBXregaddr
=
5750 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_BMBX
;
5752 case LPFC_SLI_INTF_IF_TYPE_1
:
5754 dev_printk(KERN_ERR
, &phba
->pcidev
->dev
,
5755 "FATAL - unsupported SLI4 interface type - %d\n",
5762 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
5763 * @phba: pointer to lpfc hba data structure.
5765 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
5769 lpfc_sli4_bar1_register_memmap(struct lpfc_hba
*phba
)
5771 phba
->sli4_hba
.PSMPHRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
5772 LPFC_SLIPORT_IF0_SMPHR
;
5773 phba
->sli4_hba
.ISRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
5775 phba
->sli4_hba
.IMRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
5777 phba
->sli4_hba
.ISCRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
5782 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
5783 * @phba: pointer to lpfc hba data structure.
5784 * @vf: virtual function number
5786 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
5787 * based on the given viftual function number, @vf.
5789 * Return 0 if successful, otherwise -ENODEV.
5792 lpfc_sli4_bar2_register_memmap(struct lpfc_hba
*phba
, uint32_t vf
)
5794 if (vf
> LPFC_VIR_FUNC_MAX
)
5797 phba
->sli4_hba
.RQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
5798 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_RQ_DOORBELL
);
5799 phba
->sli4_hba
.WQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
5800 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_WQ_DOORBELL
);
5801 phba
->sli4_hba
.EQCQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
5802 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_EQCQ_DOORBELL
);
5803 phba
->sli4_hba
.MQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
5804 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_MQ_DOORBELL
);
5805 phba
->sli4_hba
.BMBXregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
5806 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_BMBX
);
5811 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
5812 * @phba: pointer to lpfc hba data structure.
5814 * This routine is invoked to create the bootstrap mailbox
5815 * region consistent with the SLI-4 interface spec. This
5816 * routine allocates all memory necessary to communicate
5817 * mailbox commands to the port and sets up all alignment
5818 * needs. No locks are expected to be held when calling
5823 * -ENOMEM - could not allocated memory.
5826 lpfc_create_bootstrap_mbox(struct lpfc_hba
*phba
)
5829 struct lpfc_dmabuf
*dmabuf
;
5830 struct dma_address
*dma_address
;
5834 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
5839 * The bootstrap mailbox region is comprised of 2 parts
5840 * plus an alignment restriction of 16 bytes.
5842 bmbx_size
= sizeof(struct lpfc_bmbx_create
) + (LPFC_ALIGN_16_BYTE
- 1);
5843 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
5847 if (!dmabuf
->virt
) {
5851 memset(dmabuf
->virt
, 0, bmbx_size
);
5854 * Initialize the bootstrap mailbox pointers now so that the register
5855 * operations are simple later. The mailbox dma address is required
5856 * to be 16-byte aligned. Also align the virtual memory as each
5857 * maibox is copied into the bmbx mailbox region before issuing the
5858 * command to the port.
5860 phba
->sli4_hba
.bmbx
.dmabuf
= dmabuf
;
5861 phba
->sli4_hba
.bmbx
.bmbx_size
= bmbx_size
;
5863 phba
->sli4_hba
.bmbx
.avirt
= PTR_ALIGN(dmabuf
->virt
,
5864 LPFC_ALIGN_16_BYTE
);
5865 phba
->sli4_hba
.bmbx
.aphys
= ALIGN(dmabuf
->phys
,
5866 LPFC_ALIGN_16_BYTE
);
5869 * Set the high and low physical addresses now. The SLI4 alignment
5870 * requirement is 16 bytes and the mailbox is posted to the port
5871 * as two 30-bit addresses. The other data is a bit marking whether
5872 * the 30-bit address is the high or low address.
5873 * Upcast bmbx aphys to 64bits so shift instruction compiles
5874 * clean on 32 bit machines.
5876 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
5877 phys_addr
= (uint64_t)phba
->sli4_hba
.bmbx
.aphys
;
5878 pa_addr
= (uint32_t) ((phys_addr
>> 34) & 0x3fffffff);
5879 dma_address
->addr_hi
= (uint32_t) ((pa_addr
<< 2) |
5880 LPFC_BMBX_BIT1_ADDR_HI
);
5882 pa_addr
= (uint32_t) ((phba
->sli4_hba
.bmbx
.aphys
>> 4) & 0x3fffffff);
5883 dma_address
->addr_lo
= (uint32_t) ((pa_addr
<< 2) |
5884 LPFC_BMBX_BIT1_ADDR_LO
);
5889 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
5890 * @phba: pointer to lpfc hba data structure.
5892 * This routine is invoked to teardown the bootstrap mailbox
5893 * region and release all host resources. This routine requires
5894 * the caller to ensure all mailbox commands recovered, no
5895 * additional mailbox comands are sent, and interrupts are disabled
5896 * before calling this routine.
5900 lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*phba
)
5902 dma_free_coherent(&phba
->pcidev
->dev
,
5903 phba
->sli4_hba
.bmbx
.bmbx_size
,
5904 phba
->sli4_hba
.bmbx
.dmabuf
->virt
,
5905 phba
->sli4_hba
.bmbx
.dmabuf
->phys
);
5907 kfree(phba
->sli4_hba
.bmbx
.dmabuf
);
5908 memset(&phba
->sli4_hba
.bmbx
, 0, sizeof(struct lpfc_bmbx
));
5912 * lpfc_sli4_read_config - Get the config parameters.
5913 * @phba: pointer to lpfc hba data structure.
5915 * This routine is invoked to read the configuration parameters from the HBA.
5916 * The configuration parameters are used to set the base and maximum values
5917 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
5918 * allocation for the port.
5922 * -ENOMEM - No available memory
5923 * -EIO - The mailbox failed to complete successfully.
5926 lpfc_sli4_read_config(struct lpfc_hba
*phba
)
5929 struct lpfc_mbx_read_config
*rd_config
;
5930 union lpfc_sli4_cfg_shdr
*shdr
;
5931 uint32_t shdr_status
, shdr_add_status
;
5932 struct lpfc_mbx_get_func_cfg
*get_func_cfg
;
5933 struct lpfc_rsrc_desc_fcfcoe
*desc
;
5934 uint32_t desc_count
;
5935 int length
, i
, rc
= 0;
5937 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5939 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5940 "2011 Unable to allocate memory for issuing "
5941 "SLI_CONFIG_SPECIAL mailbox command\n");
5945 lpfc_read_config(phba
, pmb
);
5947 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
5948 if (rc
!= MBX_SUCCESS
) {
5949 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
5950 "2012 Mailbox failed , mbxCmd x%x "
5951 "READ_CONFIG, mbxStatus x%x\n",
5952 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
5953 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
5956 rd_config
= &pmb
->u
.mqe
.un
.rd_config
;
5957 phba
->sli4_hba
.extents_in_use
=
5958 bf_get(lpfc_mbx_rd_conf_extnts_inuse
, rd_config
);
5959 phba
->sli4_hba
.max_cfg_param
.max_xri
=
5960 bf_get(lpfc_mbx_rd_conf_xri_count
, rd_config
);
5961 phba
->sli4_hba
.max_cfg_param
.xri_base
=
5962 bf_get(lpfc_mbx_rd_conf_xri_base
, rd_config
);
5963 phba
->sli4_hba
.max_cfg_param
.max_vpi
=
5964 bf_get(lpfc_mbx_rd_conf_vpi_count
, rd_config
);
5965 phba
->sli4_hba
.max_cfg_param
.vpi_base
=
5966 bf_get(lpfc_mbx_rd_conf_vpi_base
, rd_config
);
5967 phba
->sli4_hba
.max_cfg_param
.max_rpi
=
5968 bf_get(lpfc_mbx_rd_conf_rpi_count
, rd_config
);
5969 phba
->sli4_hba
.max_cfg_param
.rpi_base
=
5970 bf_get(lpfc_mbx_rd_conf_rpi_base
, rd_config
);
5971 phba
->sli4_hba
.max_cfg_param
.max_vfi
=
5972 bf_get(lpfc_mbx_rd_conf_vfi_count
, rd_config
);
5973 phba
->sli4_hba
.max_cfg_param
.vfi_base
=
5974 bf_get(lpfc_mbx_rd_conf_vfi_base
, rd_config
);
5975 phba
->sli4_hba
.max_cfg_param
.max_fcfi
=
5976 bf_get(lpfc_mbx_rd_conf_fcfi_count
, rd_config
);
5977 phba
->sli4_hba
.max_cfg_param
.max_eq
=
5978 bf_get(lpfc_mbx_rd_conf_eq_count
, rd_config
);
5979 phba
->sli4_hba
.max_cfg_param
.max_rq
=
5980 bf_get(lpfc_mbx_rd_conf_rq_count
, rd_config
);
5981 phba
->sli4_hba
.max_cfg_param
.max_wq
=
5982 bf_get(lpfc_mbx_rd_conf_wq_count
, rd_config
);
5983 phba
->sli4_hba
.max_cfg_param
.max_cq
=
5984 bf_get(lpfc_mbx_rd_conf_cq_count
, rd_config
);
5985 phba
->lmt
= bf_get(lpfc_mbx_rd_conf_lmt
, rd_config
);
5986 phba
->sli4_hba
.next_xri
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
5987 phba
->vpi_base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
5988 phba
->vfi_base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
5989 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
5990 phba
->max_vpi
= (phba
->sli4_hba
.max_cfg_param
.max_vpi
> 0) ?
5991 (phba
->sli4_hba
.max_cfg_param
.max_vpi
- 1) : 0;
5992 phba
->max_vports
= phba
->max_vpi
;
5993 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5994 "2003 cfg params Extents? %d "
6000 phba
->sli4_hba
.extents_in_use
,
6001 phba
->sli4_hba
.max_cfg_param
.xri_base
,
6002 phba
->sli4_hba
.max_cfg_param
.max_xri
,
6003 phba
->sli4_hba
.max_cfg_param
.vpi_base
,
6004 phba
->sli4_hba
.max_cfg_param
.max_vpi
,
6005 phba
->sli4_hba
.max_cfg_param
.vfi_base
,
6006 phba
->sli4_hba
.max_cfg_param
.max_vfi
,
6007 phba
->sli4_hba
.max_cfg_param
.rpi_base
,
6008 phba
->sli4_hba
.max_cfg_param
.max_rpi
,
6009 phba
->sli4_hba
.max_cfg_param
.max_fcfi
);
6015 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
6016 if (phba
->cfg_hba_queue_depth
>
6017 (phba
->sli4_hba
.max_cfg_param
.max_xri
-
6018 lpfc_sli4_get_els_iocb_cnt(phba
)))
6019 phba
->cfg_hba_queue_depth
=
6020 phba
->sli4_hba
.max_cfg_param
.max_xri
-
6021 lpfc_sli4_get_els_iocb_cnt(phba
);
6023 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
6024 LPFC_SLI_INTF_IF_TYPE_2
)
6027 /* get the pf# and vf# for SLI4 if_type 2 port */
6028 length
= (sizeof(struct lpfc_mbx_get_func_cfg
) -
6029 sizeof(struct lpfc_sli4_cfg_mhdr
));
6030 lpfc_sli4_config(phba
, pmb
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6031 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG
,
6032 length
, LPFC_SLI4_MBX_EMBED
);
6034 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
6035 shdr
= (union lpfc_sli4_cfg_shdr
*)
6036 &pmb
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
6037 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
6038 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
6039 if (rc
|| shdr_status
|| shdr_add_status
) {
6040 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6041 "3026 Mailbox failed , mbxCmd x%x "
6042 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
6043 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
6044 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
6049 /* search for fc_fcoe resrouce descriptor */
6050 get_func_cfg
= &pmb
->u
.mqe
.un
.get_func_cfg
;
6051 desc_count
= get_func_cfg
->func_cfg
.rsrc_desc_count
;
6053 for (i
= 0; i
< LPFC_RSRC_DESC_MAX_NUM
; i
++) {
6054 desc
= (struct lpfc_rsrc_desc_fcfcoe
*)
6055 &get_func_cfg
->func_cfg
.desc
[i
];
6056 if (LPFC_RSRC_DESC_TYPE_FCFCOE
==
6057 bf_get(lpfc_rsrc_desc_pcie_type
, desc
)) {
6058 phba
->sli4_hba
.iov
.pf_number
=
6059 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum
, desc
);
6060 phba
->sli4_hba
.iov
.vf_number
=
6061 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum
, desc
);
6066 if (i
< LPFC_RSRC_DESC_MAX_NUM
)
6067 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
6068 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
6069 "vf_number:%d\n", phba
->sli4_hba
.iov
.pf_number
,
6070 phba
->sli4_hba
.iov
.vf_number
);
6072 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6073 "3028 GET_FUNCTION_CONFIG: failed to find "
6074 "Resrouce Descriptor:x%x\n",
6075 LPFC_RSRC_DESC_TYPE_FCFCOE
);
6080 mempool_free(pmb
, phba
->mbox_mem_pool
);
6085 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
6086 * @phba: pointer to lpfc hba data structure.
6088 * This routine is invoked to setup the port-side endian order when
6089 * the port if_type is 0. This routine has no function for other
6094 * -ENOMEM - No available memory
6095 * -EIO - The mailbox failed to complete successfully.
6098 lpfc_setup_endian_order(struct lpfc_hba
*phba
)
6100 LPFC_MBOXQ_t
*mboxq
;
6101 uint32_t if_type
, rc
= 0;
6102 uint32_t endian_mb_data
[2] = {HOST_ENDIAN_LOW_WORD0
,
6103 HOST_ENDIAN_HIGH_WORD1
};
6105 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
6107 case LPFC_SLI_INTF_IF_TYPE_0
:
6108 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
6111 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6112 "0492 Unable to allocate memory for "
6113 "issuing SLI_CONFIG_SPECIAL mailbox "
6119 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
6120 * two words to contain special data values and no other data.
6122 memset(mboxq
, 0, sizeof(LPFC_MBOXQ_t
));
6123 memcpy(&mboxq
->u
.mqe
, &endian_mb_data
, sizeof(endian_mb_data
));
6124 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6125 if (rc
!= MBX_SUCCESS
) {
6126 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6127 "0493 SLI_CONFIG_SPECIAL mailbox "
6128 "failed with status x%x\n",
6132 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6134 case LPFC_SLI_INTF_IF_TYPE_2
:
6135 case LPFC_SLI_INTF_IF_TYPE_1
:
6143 * lpfc_sli4_queue_create - Create all the SLI4 queues
6144 * @phba: pointer to lpfc hba data structure.
6146 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
6147 * operation. For each SLI4 queue type, the parameters such as queue entry
6148 * count (queue depth) shall be taken from the module parameter. For now,
6149 * we just use some constant number as place holder.
6153 * -ENOMEM - No available memory
6154 * -EIO - The mailbox failed to complete successfully.
6157 lpfc_sli4_queue_create(struct lpfc_hba
*phba
)
6159 struct lpfc_queue
*qdesc
;
6160 int fcp_eqidx
, fcp_cqidx
, fcp_wqidx
;
6161 int cfg_fcp_wq_count
;
6162 int cfg_fcp_eq_count
;
6165 * Sanity check for confiugred queue parameters against the run-time
6169 /* Sanity check on FCP fast-path WQ parameters */
6170 cfg_fcp_wq_count
= phba
->cfg_fcp_wq_count
;
6171 if (cfg_fcp_wq_count
>
6172 (phba
->sli4_hba
.max_cfg_param
.max_wq
- LPFC_SP_WQN_DEF
)) {
6173 cfg_fcp_wq_count
= phba
->sli4_hba
.max_cfg_param
.max_wq
-
6175 if (cfg_fcp_wq_count
< LPFC_FP_WQN_MIN
) {
6176 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6177 "2581 Not enough WQs (%d) from "
6178 "the pci function for supporting "
6180 phba
->sli4_hba
.max_cfg_param
.max_wq
,
6181 phba
->cfg_fcp_wq_count
);
6184 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6185 "2582 Not enough WQs (%d) from the pci "
6186 "function for supporting the requested "
6187 "FCP WQs (%d), the actual FCP WQs can "
6188 "be supported: %d\n",
6189 phba
->sli4_hba
.max_cfg_param
.max_wq
,
6190 phba
->cfg_fcp_wq_count
, cfg_fcp_wq_count
);
6192 /* The actual number of FCP work queues adopted */
6193 phba
->cfg_fcp_wq_count
= cfg_fcp_wq_count
;
6195 /* Sanity check on FCP fast-path EQ parameters */
6196 cfg_fcp_eq_count
= phba
->cfg_fcp_eq_count
;
6197 if (cfg_fcp_eq_count
>
6198 (phba
->sli4_hba
.max_cfg_param
.max_eq
- LPFC_SP_EQN_DEF
)) {
6199 cfg_fcp_eq_count
= phba
->sli4_hba
.max_cfg_param
.max_eq
-
6201 if (cfg_fcp_eq_count
< LPFC_FP_EQN_MIN
) {
6202 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6203 "2574 Not enough EQs (%d) from the "
6204 "pci function for supporting FCP "
6206 phba
->sli4_hba
.max_cfg_param
.max_eq
,
6207 phba
->cfg_fcp_eq_count
);
6210 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6211 "2575 Not enough EQs (%d) from the pci "
6212 "function for supporting the requested "
6213 "FCP EQs (%d), the actual FCP EQs can "
6214 "be supported: %d\n",
6215 phba
->sli4_hba
.max_cfg_param
.max_eq
,
6216 phba
->cfg_fcp_eq_count
, cfg_fcp_eq_count
);
6218 /* It does not make sense to have more EQs than WQs */
6219 if (cfg_fcp_eq_count
> phba
->cfg_fcp_wq_count
) {
6220 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6221 "2593 The FCP EQ count(%d) cannot be greater "
6222 "than the FCP WQ count(%d), limiting the "
6223 "FCP EQ count to %d\n", cfg_fcp_eq_count
,
6224 phba
->cfg_fcp_wq_count
,
6225 phba
->cfg_fcp_wq_count
);
6226 cfg_fcp_eq_count
= phba
->cfg_fcp_wq_count
;
6228 /* The actual number of FCP event queues adopted */
6229 phba
->cfg_fcp_eq_count
= cfg_fcp_eq_count
;
6230 /* The overall number of event queues used */
6231 phba
->sli4_hba
.cfg_eqn
= phba
->cfg_fcp_eq_count
+ LPFC_SP_EQN_DEF
;
6234 * Create Event Queues (EQs)
6237 /* Get EQ depth from module parameter, fake the default for now */
6238 phba
->sli4_hba
.eq_esize
= LPFC_EQE_SIZE_4B
;
6239 phba
->sli4_hba
.eq_ecount
= LPFC_EQE_DEF_COUNT
;
6241 /* Create slow path event queue */
6242 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.eq_esize
,
6243 phba
->sli4_hba
.eq_ecount
);
6245 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6246 "0496 Failed allocate slow-path EQ\n");
6249 phba
->sli4_hba
.sp_eq
= qdesc
;
6251 /* Create fast-path FCP Event Queue(s) */
6252 phba
->sli4_hba
.fp_eq
= kzalloc((sizeof(struct lpfc_queue
*) *
6253 phba
->cfg_fcp_eq_count
), GFP_KERNEL
);
6254 if (!phba
->sli4_hba
.fp_eq
) {
6255 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6256 "2576 Failed allocate memory for fast-path "
6257 "EQ record array\n");
6258 goto out_free_sp_eq
;
6260 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++) {
6261 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.eq_esize
,
6262 phba
->sli4_hba
.eq_ecount
);
6264 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6265 "0497 Failed allocate fast-path EQ\n");
6266 goto out_free_fp_eq
;
6268 phba
->sli4_hba
.fp_eq
[fcp_eqidx
] = qdesc
;
6272 * Create Complete Queues (CQs)
6275 /* Get CQ depth from module parameter, fake the default for now */
6276 phba
->sli4_hba
.cq_esize
= LPFC_CQE_SIZE
;
6277 phba
->sli4_hba
.cq_ecount
= LPFC_CQE_DEF_COUNT
;
6279 /* Create slow-path Mailbox Command Complete Queue */
6280 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
6281 phba
->sli4_hba
.cq_ecount
);
6283 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6284 "0500 Failed allocate slow-path mailbox CQ\n");
6285 goto out_free_fp_eq
;
6287 phba
->sli4_hba
.mbx_cq
= qdesc
;
6289 /* Create slow-path ELS Complete Queue */
6290 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
6291 phba
->sli4_hba
.cq_ecount
);
6293 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6294 "0501 Failed allocate slow-path ELS CQ\n");
6295 goto out_free_mbx_cq
;
6297 phba
->sli4_hba
.els_cq
= qdesc
;
6300 /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */
6301 phba
->sli4_hba
.fcp_cq
= kzalloc((sizeof(struct lpfc_queue
*) *
6302 phba
->cfg_fcp_eq_count
), GFP_KERNEL
);
6303 if (!phba
->sli4_hba
.fcp_cq
) {
6304 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6305 "2577 Failed allocate memory for fast-path "
6306 "CQ record array\n");
6307 goto out_free_els_cq
;
6309 for (fcp_cqidx
= 0; fcp_cqidx
< phba
->cfg_fcp_eq_count
; fcp_cqidx
++) {
6310 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
6311 phba
->sli4_hba
.cq_ecount
);
6313 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6314 "0499 Failed allocate fast-path FCP "
6315 "CQ (%d)\n", fcp_cqidx
);
6316 goto out_free_fcp_cq
;
6318 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
] = qdesc
;
6321 /* Create Mailbox Command Queue */
6322 phba
->sli4_hba
.mq_esize
= LPFC_MQE_SIZE
;
6323 phba
->sli4_hba
.mq_ecount
= LPFC_MQE_DEF_COUNT
;
6325 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.mq_esize
,
6326 phba
->sli4_hba
.mq_ecount
);
6328 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6329 "0505 Failed allocate slow-path MQ\n");
6330 goto out_free_fcp_cq
;
6332 phba
->sli4_hba
.mbx_wq
= qdesc
;
6335 * Create all the Work Queues (WQs)
6337 phba
->sli4_hba
.wq_esize
= LPFC_WQE_SIZE
;
6338 phba
->sli4_hba
.wq_ecount
= LPFC_WQE_DEF_COUNT
;
6340 /* Create slow-path ELS Work Queue */
6341 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
6342 phba
->sli4_hba
.wq_ecount
);
6344 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6345 "0504 Failed allocate slow-path ELS WQ\n");
6346 goto out_free_mbx_wq
;
6348 phba
->sli4_hba
.els_wq
= qdesc
;
6350 /* Create fast-path FCP Work Queue(s) */
6351 phba
->sli4_hba
.fcp_wq
= kzalloc((sizeof(struct lpfc_queue
*) *
6352 phba
->cfg_fcp_wq_count
), GFP_KERNEL
);
6353 if (!phba
->sli4_hba
.fcp_wq
) {
6354 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6355 "2578 Failed allocate memory for fast-path "
6356 "WQ record array\n");
6357 goto out_free_els_wq
;
6359 for (fcp_wqidx
= 0; fcp_wqidx
< phba
->cfg_fcp_wq_count
; fcp_wqidx
++) {
6360 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
6361 phba
->sli4_hba
.wq_ecount
);
6363 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6364 "0503 Failed allocate fast-path FCP "
6365 "WQ (%d)\n", fcp_wqidx
);
6366 goto out_free_fcp_wq
;
6368 phba
->sli4_hba
.fcp_wq
[fcp_wqidx
] = qdesc
;
6372 * Create Receive Queue (RQ)
6374 phba
->sli4_hba
.rq_esize
= LPFC_RQE_SIZE
;
6375 phba
->sli4_hba
.rq_ecount
= LPFC_RQE_DEF_COUNT
;
6377 /* Create Receive Queue for header */
6378 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
6379 phba
->sli4_hba
.rq_ecount
);
6381 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6382 "0506 Failed allocate receive HRQ\n");
6383 goto out_free_fcp_wq
;
6385 phba
->sli4_hba
.hdr_rq
= qdesc
;
6387 /* Create Receive Queue for data */
6388 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
6389 phba
->sli4_hba
.rq_ecount
);
6391 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6392 "0507 Failed allocate receive DRQ\n");
6393 goto out_free_hdr_rq
;
6395 phba
->sli4_hba
.dat_rq
= qdesc
;
6400 lpfc_sli4_queue_free(phba
->sli4_hba
.hdr_rq
);
6401 phba
->sli4_hba
.hdr_rq
= NULL
;
6403 for (--fcp_wqidx
; fcp_wqidx
>= 0; fcp_wqidx
--) {
6404 lpfc_sli4_queue_free(phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]);
6405 phba
->sli4_hba
.fcp_wq
[fcp_wqidx
] = NULL
;
6407 kfree(phba
->sli4_hba
.fcp_wq
);
6409 lpfc_sli4_queue_free(phba
->sli4_hba
.els_wq
);
6410 phba
->sli4_hba
.els_wq
= NULL
;
6412 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_wq
);
6413 phba
->sli4_hba
.mbx_wq
= NULL
;
6415 for (--fcp_cqidx
; fcp_cqidx
>= 0; fcp_cqidx
--) {
6416 lpfc_sli4_queue_free(phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]);
6417 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
] = NULL
;
6419 kfree(phba
->sli4_hba
.fcp_cq
);
6421 lpfc_sli4_queue_free(phba
->sli4_hba
.els_cq
);
6422 phba
->sli4_hba
.els_cq
= NULL
;
6424 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_cq
);
6425 phba
->sli4_hba
.mbx_cq
= NULL
;
6427 for (--fcp_eqidx
; fcp_eqidx
>= 0; fcp_eqidx
--) {
6428 lpfc_sli4_queue_free(phba
->sli4_hba
.fp_eq
[fcp_eqidx
]);
6429 phba
->sli4_hba
.fp_eq
[fcp_eqidx
] = NULL
;
6431 kfree(phba
->sli4_hba
.fp_eq
);
6433 lpfc_sli4_queue_free(phba
->sli4_hba
.sp_eq
);
6434 phba
->sli4_hba
.sp_eq
= NULL
;
6440 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
6441 * @phba: pointer to lpfc hba data structure.
6443 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
6448 * -ENOMEM - No available memory
6449 * -EIO - The mailbox failed to complete successfully.
6452 lpfc_sli4_queue_destroy(struct lpfc_hba
*phba
)
6456 /* Release mailbox command work queue */
6457 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_wq
);
6458 phba
->sli4_hba
.mbx_wq
= NULL
;
6460 /* Release ELS work queue */
6461 lpfc_sli4_queue_free(phba
->sli4_hba
.els_wq
);
6462 phba
->sli4_hba
.els_wq
= NULL
;
6464 /* Release FCP work queue */
6465 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_wq_count
; fcp_qidx
++)
6466 lpfc_sli4_queue_free(phba
->sli4_hba
.fcp_wq
[fcp_qidx
]);
6467 kfree(phba
->sli4_hba
.fcp_wq
);
6468 phba
->sli4_hba
.fcp_wq
= NULL
;
6470 /* Release unsolicited receive queue */
6471 lpfc_sli4_queue_free(phba
->sli4_hba
.hdr_rq
);
6472 phba
->sli4_hba
.hdr_rq
= NULL
;
6473 lpfc_sli4_queue_free(phba
->sli4_hba
.dat_rq
);
6474 phba
->sli4_hba
.dat_rq
= NULL
;
6476 /* Release ELS complete queue */
6477 lpfc_sli4_queue_free(phba
->sli4_hba
.els_cq
);
6478 phba
->sli4_hba
.els_cq
= NULL
;
6480 /* Release mailbox command complete queue */
6481 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_cq
);
6482 phba
->sli4_hba
.mbx_cq
= NULL
;
6484 /* Release FCP response complete queue */
6487 lpfc_sli4_queue_free(phba
->sli4_hba
.fcp_cq
[fcp_qidx
]);
6488 while (++fcp_qidx
< phba
->cfg_fcp_eq_count
);
6489 kfree(phba
->sli4_hba
.fcp_cq
);
6490 phba
->sli4_hba
.fcp_cq
= NULL
;
6492 /* Release fast-path event queue */
6493 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_eq_count
; fcp_qidx
++)
6494 lpfc_sli4_queue_free(phba
->sli4_hba
.fp_eq
[fcp_qidx
]);
6495 kfree(phba
->sli4_hba
.fp_eq
);
6496 phba
->sli4_hba
.fp_eq
= NULL
;
6498 /* Release slow-path event queue */
6499 lpfc_sli4_queue_free(phba
->sli4_hba
.sp_eq
);
6500 phba
->sli4_hba
.sp_eq
= NULL
;
6506 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
6507 * @phba: pointer to lpfc hba data structure.
6509 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
6514 * -ENOMEM - No available memory
6515 * -EIO - The mailbox failed to complete successfully.
6518 lpfc_sli4_queue_setup(struct lpfc_hba
*phba
)
6521 int fcp_eqidx
, fcp_cqidx
, fcp_wqidx
;
6522 int fcp_cq_index
= 0;
6525 * Set up Event Queues (EQs)
6528 /* Set up slow-path event queue */
6529 if (!phba
->sli4_hba
.sp_eq
) {
6530 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6531 "0520 Slow-path EQ not allocated\n");
6534 rc
= lpfc_eq_create(phba
, phba
->sli4_hba
.sp_eq
,
6537 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6538 "0521 Failed setup of slow-path EQ: "
6542 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6543 "2583 Slow-path EQ setup: queue-id=%d\n",
6544 phba
->sli4_hba
.sp_eq
->queue_id
);
6546 /* Set up fast-path event queue */
6547 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++) {
6548 if (!phba
->sli4_hba
.fp_eq
[fcp_eqidx
]) {
6549 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6550 "0522 Fast-path EQ (%d) not "
6551 "allocated\n", fcp_eqidx
);
6552 goto out_destroy_fp_eq
;
6554 rc
= lpfc_eq_create(phba
, phba
->sli4_hba
.fp_eq
[fcp_eqidx
],
6555 phba
->cfg_fcp_imax
);
6557 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6558 "0523 Failed setup of fast-path EQ "
6559 "(%d), rc = 0x%x\n", fcp_eqidx
, rc
);
6560 goto out_destroy_fp_eq
;
6562 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6563 "2584 Fast-path EQ setup: "
6564 "queue[%d]-id=%d\n", fcp_eqidx
,
6565 phba
->sli4_hba
.fp_eq
[fcp_eqidx
]->queue_id
);
6569 * Set up Complete Queues (CQs)
6572 /* Set up slow-path MBOX Complete Queue as the first CQ */
6573 if (!phba
->sli4_hba
.mbx_cq
) {
6574 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6575 "0528 Mailbox CQ not allocated\n");
6576 goto out_destroy_fp_eq
;
6578 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.mbx_cq
, phba
->sli4_hba
.sp_eq
,
6579 LPFC_MCQ
, LPFC_MBOX
);
6581 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6582 "0529 Failed setup of slow-path mailbox CQ: "
6584 goto out_destroy_fp_eq
;
6586 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6587 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
6588 phba
->sli4_hba
.mbx_cq
->queue_id
,
6589 phba
->sli4_hba
.sp_eq
->queue_id
);
6591 /* Set up slow-path ELS Complete Queue */
6592 if (!phba
->sli4_hba
.els_cq
) {
6593 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6594 "0530 ELS CQ not allocated\n");
6595 goto out_destroy_mbx_cq
;
6597 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.els_cq
, phba
->sli4_hba
.sp_eq
,
6598 LPFC_WCQ
, LPFC_ELS
);
6600 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6601 "0531 Failed setup of slow-path ELS CQ: "
6603 goto out_destroy_mbx_cq
;
6605 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6606 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
6607 phba
->sli4_hba
.els_cq
->queue_id
,
6608 phba
->sli4_hba
.sp_eq
->queue_id
);
6610 /* Set up fast-path FCP Response Complete Queue */
6613 if (!phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]) {
6614 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6615 "0526 Fast-path FCP CQ (%d) not "
6616 "allocated\n", fcp_cqidx
);
6617 goto out_destroy_fcp_cq
;
6619 if (phba
->cfg_fcp_eq_count
)
6620 rc
= lpfc_cq_create(phba
,
6621 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
],
6622 phba
->sli4_hba
.fp_eq
[fcp_cqidx
],
6623 LPFC_WCQ
, LPFC_FCP
);
6625 rc
= lpfc_cq_create(phba
,
6626 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
],
6627 phba
->sli4_hba
.sp_eq
,
6628 LPFC_WCQ
, LPFC_FCP
);
6630 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6631 "0527 Failed setup of fast-path FCP "
6632 "CQ (%d), rc = 0x%x\n", fcp_cqidx
, rc
);
6633 goto out_destroy_fcp_cq
;
6635 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6636 "2588 FCP CQ setup: cq[%d]-id=%d, "
6637 "parent %seq[%d]-id=%d\n",
6639 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]->queue_id
,
6640 (phba
->cfg_fcp_eq_count
) ? "" : "sp_",
6642 (phba
->cfg_fcp_eq_count
) ?
6643 phba
->sli4_hba
.fp_eq
[fcp_cqidx
]->queue_id
:
6644 phba
->sli4_hba
.sp_eq
->queue_id
);
6645 } while (++fcp_cqidx
< phba
->cfg_fcp_eq_count
);
6648 * Set up all the Work Queues (WQs)
6651 /* Set up Mailbox Command Queue */
6652 if (!phba
->sli4_hba
.mbx_wq
) {
6653 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6654 "0538 Slow-path MQ not allocated\n");
6655 goto out_destroy_fcp_cq
;
6657 rc
= lpfc_mq_create(phba
, phba
->sli4_hba
.mbx_wq
,
6658 phba
->sli4_hba
.mbx_cq
, LPFC_MBOX
);
6660 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6661 "0539 Failed setup of slow-path MQ: "
6663 goto out_destroy_fcp_cq
;
6665 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6666 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
6667 phba
->sli4_hba
.mbx_wq
->queue_id
,
6668 phba
->sli4_hba
.mbx_cq
->queue_id
);
6670 /* Set up slow-path ELS Work Queue */
6671 if (!phba
->sli4_hba
.els_wq
) {
6672 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6673 "0536 Slow-path ELS WQ not allocated\n");
6674 goto out_destroy_mbx_wq
;
6676 rc
= lpfc_wq_create(phba
, phba
->sli4_hba
.els_wq
,
6677 phba
->sli4_hba
.els_cq
, LPFC_ELS
);
6679 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6680 "0537 Failed setup of slow-path ELS WQ: "
6682 goto out_destroy_mbx_wq
;
6684 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6685 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
6686 phba
->sli4_hba
.els_wq
->queue_id
,
6687 phba
->sli4_hba
.els_cq
->queue_id
);
6689 /* Set up fast-path FCP Work Queue */
6690 for (fcp_wqidx
= 0; fcp_wqidx
< phba
->cfg_fcp_wq_count
; fcp_wqidx
++) {
6691 if (!phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]) {
6692 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6693 "0534 Fast-path FCP WQ (%d) not "
6694 "allocated\n", fcp_wqidx
);
6695 goto out_destroy_fcp_wq
;
6697 rc
= lpfc_wq_create(phba
, phba
->sli4_hba
.fcp_wq
[fcp_wqidx
],
6698 phba
->sli4_hba
.fcp_cq
[fcp_cq_index
],
6701 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6702 "0535 Failed setup of fast-path FCP "
6703 "WQ (%d), rc = 0x%x\n", fcp_wqidx
, rc
);
6704 goto out_destroy_fcp_wq
;
6706 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6707 "2591 FCP WQ setup: wq[%d]-id=%d, "
6708 "parent cq[%d]-id=%d\n",
6710 phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]->queue_id
,
6712 phba
->sli4_hba
.fcp_cq
[fcp_cq_index
]->queue_id
);
6713 /* Round robin FCP Work Queue's Completion Queue assignment */
6714 if (phba
->cfg_fcp_eq_count
)
6715 fcp_cq_index
= ((fcp_cq_index
+ 1) %
6716 phba
->cfg_fcp_eq_count
);
6720 * Create Receive Queue (RQ)
6722 if (!phba
->sli4_hba
.hdr_rq
|| !phba
->sli4_hba
.dat_rq
) {
6723 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6724 "0540 Receive Queue not allocated\n");
6725 goto out_destroy_fcp_wq
;
6727 rc
= lpfc_rq_create(phba
, phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
6728 phba
->sli4_hba
.els_cq
, LPFC_USOL
);
6730 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6731 "0541 Failed setup of Receive Queue: "
6733 goto out_destroy_fcp_wq
;
6735 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6736 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
6737 "parent cq-id=%d\n",
6738 phba
->sli4_hba
.hdr_rq
->queue_id
,
6739 phba
->sli4_hba
.dat_rq
->queue_id
,
6740 phba
->sli4_hba
.els_cq
->queue_id
);
6744 for (--fcp_wqidx
; fcp_wqidx
>= 0; fcp_wqidx
--)
6745 lpfc_wq_destroy(phba
, phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]);
6746 lpfc_wq_destroy(phba
, phba
->sli4_hba
.els_wq
);
6748 lpfc_mq_destroy(phba
, phba
->sli4_hba
.mbx_wq
);
6750 for (--fcp_cqidx
; fcp_cqidx
>= 0; fcp_cqidx
--)
6751 lpfc_cq_destroy(phba
, phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]);
6752 lpfc_cq_destroy(phba
, phba
->sli4_hba
.els_cq
);
6754 lpfc_cq_destroy(phba
, phba
->sli4_hba
.mbx_cq
);
6756 for (--fcp_eqidx
; fcp_eqidx
>= 0; fcp_eqidx
--)
6757 lpfc_eq_destroy(phba
, phba
->sli4_hba
.fp_eq
[fcp_eqidx
]);
6758 lpfc_eq_destroy(phba
, phba
->sli4_hba
.sp_eq
);
6764 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
6765 * @phba: pointer to lpfc hba data structure.
6767 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
6772 * -ENOMEM - No available memory
6773 * -EIO - The mailbox failed to complete successfully.
6776 lpfc_sli4_queue_unset(struct lpfc_hba
*phba
)
6780 /* Unset mailbox command work queue */
6781 lpfc_mq_destroy(phba
, phba
->sli4_hba
.mbx_wq
);
6782 /* Unset ELS work queue */
6783 lpfc_wq_destroy(phba
, phba
->sli4_hba
.els_wq
);
6784 /* Unset unsolicited receive queue */
6785 lpfc_rq_destroy(phba
, phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
);
6786 /* Unset FCP work queue */
6787 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_wq_count
; fcp_qidx
++)
6788 lpfc_wq_destroy(phba
, phba
->sli4_hba
.fcp_wq
[fcp_qidx
]);
6789 /* Unset mailbox command complete queue */
6790 lpfc_cq_destroy(phba
, phba
->sli4_hba
.mbx_cq
);
6791 /* Unset ELS complete queue */
6792 lpfc_cq_destroy(phba
, phba
->sli4_hba
.els_cq
);
6793 /* Unset FCP response complete queue */
6794 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_eq_count
; fcp_qidx
++)
6795 lpfc_cq_destroy(phba
, phba
->sli4_hba
.fcp_cq
[fcp_qidx
]);
6796 /* Unset fast-path event queue */
6797 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_eq_count
; fcp_qidx
++)
6798 lpfc_eq_destroy(phba
, phba
->sli4_hba
.fp_eq
[fcp_qidx
]);
6799 /* Unset slow-path event queue */
6800 lpfc_eq_destroy(phba
, phba
->sli4_hba
.sp_eq
);
6804 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
6805 * @phba: pointer to lpfc hba data structure.
6807 * This routine is invoked to allocate and set up a pool of completion queue
6808 * events. The body of the completion queue event is a completion queue entry
6809 * CQE. For now, this pool is used for the interrupt service routine to queue
6810 * the following HBA completion queue events for the worker thread to process:
6811 * - Mailbox asynchronous events
6812 * - Receive queue completion unsolicited events
6813 * Later, this can be used for all the slow-path events.
6817 * -ENOMEM - No available memory
6820 lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*phba
)
6822 struct lpfc_cq_event
*cq_event
;
6825 for (i
= 0; i
< (4 * phba
->sli4_hba
.cq_ecount
); i
++) {
6826 cq_event
= kmalloc(sizeof(struct lpfc_cq_event
), GFP_KERNEL
);
6828 goto out_pool_create_fail
;
6829 list_add_tail(&cq_event
->list
,
6830 &phba
->sli4_hba
.sp_cqe_event_pool
);
6834 out_pool_create_fail
:
6835 lpfc_sli4_cq_event_pool_destroy(phba
);
6840 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
6841 * @phba: pointer to lpfc hba data structure.
6843 * This routine is invoked to free the pool of completion queue events at
6844 * driver unload time. Note that, it is the responsibility of the driver
6845 * cleanup routine to free all the outstanding completion-queue events
6846 * allocated from this pool back into the pool before invoking this routine
6847 * to destroy the pool.
6850 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*phba
)
6852 struct lpfc_cq_event
*cq_event
, *next_cq_event
;
6854 list_for_each_entry_safe(cq_event
, next_cq_event
,
6855 &phba
->sli4_hba
.sp_cqe_event_pool
, list
) {
6856 list_del(&cq_event
->list
);
6862 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
6863 * @phba: pointer to lpfc hba data structure.
6865 * This routine is the lock free version of the API invoked to allocate a
6866 * completion-queue event from the free pool.
6868 * Return: Pointer to the newly allocated completion-queue event if successful
6871 struct lpfc_cq_event
*
6872 __lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
6874 struct lpfc_cq_event
*cq_event
= NULL
;
6876 list_remove_head(&phba
->sli4_hba
.sp_cqe_event_pool
, cq_event
,
6877 struct lpfc_cq_event
, list
);
6882 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
6883 * @phba: pointer to lpfc hba data structure.
6885 * This routine is the lock version of the API invoked to allocate a
6886 * completion-queue event from the free pool.
6888 * Return: Pointer to the newly allocated completion-queue event if successful
6891 struct lpfc_cq_event
*
6892 lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
6894 struct lpfc_cq_event
*cq_event
;
6895 unsigned long iflags
;
6897 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6898 cq_event
= __lpfc_sli4_cq_event_alloc(phba
);
6899 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6904 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
6905 * @phba: pointer to lpfc hba data structure.
6906 * @cq_event: pointer to the completion queue event to be freed.
6908 * This routine is the lock free version of the API invoked to release a
6909 * completion-queue event back into the free pool.
6912 __lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
6913 struct lpfc_cq_event
*cq_event
)
6915 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_cqe_event_pool
);
6919 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
6920 * @phba: pointer to lpfc hba data structure.
6921 * @cq_event: pointer to the completion queue event to be freed.
6923 * This routine is the lock version of the API invoked to release a
6924 * completion-queue event back into the free pool.
6927 lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
6928 struct lpfc_cq_event
*cq_event
)
6930 unsigned long iflags
;
6931 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6932 __lpfc_sli4_cq_event_release(phba
, cq_event
);
6933 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6937 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
6938 * @phba: pointer to lpfc hba data structure.
6940 * This routine is to free all the pending completion-queue events to the
6941 * back into the free pool for device reset.
6944 lpfc_sli4_cq_event_release_all(struct lpfc_hba
*phba
)
6947 struct lpfc_cq_event
*cqe
;
6948 unsigned long iflags
;
6950 /* Retrieve all the pending WCQEs from pending WCQE lists */
6951 spin_lock_irqsave(&phba
->hbalock
, iflags
);
6952 /* Pending FCP XRI abort events */
6953 list_splice_init(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
6955 /* Pending ELS XRI abort events */
6956 list_splice_init(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
6958 /* Pending asynnc events */
6959 list_splice_init(&phba
->sli4_hba
.sp_asynce_work_queue
,
6961 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
6963 while (!list_empty(&cqelist
)) {
6964 list_remove_head(&cqelist
, cqe
, struct lpfc_cq_event
, list
);
6965 lpfc_sli4_cq_event_release(phba
, cqe
);
6970 * lpfc_pci_function_reset - Reset pci function.
6971 * @phba: pointer to lpfc hba data structure.
6973 * This routine is invoked to request a PCI function reset. It will destroys
6974 * all resources assigned to the PCI function which originates this request.
6978 * -ENOMEM - No available memory
6979 * -EIO - The mailbox failed to complete successfully.
6982 lpfc_pci_function_reset(struct lpfc_hba
*phba
)
6984 LPFC_MBOXQ_t
*mboxq
;
6985 uint32_t rc
= 0, if_type
;
6986 uint32_t shdr_status
, shdr_add_status
;
6987 uint32_t rdy_chk
, num_resets
= 0, reset_again
= 0;
6988 union lpfc_sli4_cfg_shdr
*shdr
;
6989 struct lpfc_register reg_data
;
6991 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
6993 case LPFC_SLI_INTF_IF_TYPE_0
:
6994 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
6997 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6998 "0494 Unable to allocate memory for "
6999 "issuing SLI_FUNCTION_RESET mailbox "
7004 /* Setup PCI function reset mailbox-ioctl command */
7005 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
7006 LPFC_MBOX_OPCODE_FUNCTION_RESET
, 0,
7007 LPFC_SLI4_MBX_EMBED
);
7008 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7009 shdr
= (union lpfc_sli4_cfg_shdr
*)
7010 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
7011 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
7012 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
7014 if (rc
!= MBX_TIMEOUT
)
7015 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7016 if (shdr_status
|| shdr_add_status
|| rc
) {
7017 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7018 "0495 SLI_FUNCTION_RESET mailbox "
7019 "failed with status x%x add_status x%x,"
7020 " mbx status x%x\n",
7021 shdr_status
, shdr_add_status
, rc
);
7025 case LPFC_SLI_INTF_IF_TYPE_2
:
7026 for (num_resets
= 0;
7027 num_resets
< MAX_IF_TYPE_2_RESETS
;
7030 bf_set(lpfc_sliport_ctrl_end
, ®_data
,
7031 LPFC_SLIPORT_LITTLE_ENDIAN
);
7032 bf_set(lpfc_sliport_ctrl_ip
, ®_data
,
7033 LPFC_SLIPORT_INIT_PORT
);
7034 writel(reg_data
.word0
, phba
->sli4_hba
.u
.if_type2
.
7038 * Poll the Port Status Register and wait for RDY for
7039 * up to 10 seconds. If the port doesn't respond, treat
7040 * it as an error. If the port responds with RN, start
7043 for (rdy_chk
= 0; rdy_chk
< 1000; rdy_chk
++) {
7044 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.
7045 STATUSregaddr
, ®_data
.word0
)) {
7049 if (bf_get(lpfc_sliport_status_rdy
, ®_data
))
7051 if (bf_get(lpfc_sliport_status_rn
, ®_data
)) {
7059 * If the port responds to the init request with
7060 * reset needed, delay for a bit and restart the loop.
7068 /* Detect any port errors. */
7069 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
7074 if ((bf_get(lpfc_sliport_status_err
, ®_data
)) ||
7075 (rdy_chk
>= 1000)) {
7076 phba
->work_status
[0] = readl(
7077 phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
7078 phba
->work_status
[1] = readl(
7079 phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
7080 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7081 "2890 Port Error Detected "
7082 "during Port Reset: "
7083 "port status reg 0x%x, "
7084 "error 1=0x%x, error 2=0x%x\n",
7086 phba
->work_status
[0],
7087 phba
->work_status
[1]);
7092 * Terminate the outer loop provided the Port indicated
7093 * ready within 10 seconds.
7098 /* delay driver action following IF_TYPE_2 function reset */
7101 case LPFC_SLI_INTF_IF_TYPE_1
:
7106 /* Catch the not-ready port failure after a port reset. */
7107 if (num_resets
>= MAX_IF_TYPE_2_RESETS
)
7114 * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
7115 * @phba: pointer to lpfc hba data structure.
7116 * @cnt: number of nop mailbox commands to send.
7118 * This routine is invoked to send a number @cnt of NOP mailbox command and
7119 * wait for each command to complete.
7121 * Return: the number of NOP mailbox command completed.
7124 lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba
*phba
, uint32_t cnt
)
7126 LPFC_MBOXQ_t
*mboxq
;
7127 int length
, cmdsent
;
7130 uint32_t shdr_status
, shdr_add_status
;
7131 union lpfc_sli4_cfg_shdr
*shdr
;
7134 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7135 "2518 Requested to send 0 NOP mailbox cmd\n");
7139 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
7141 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7142 "2519 Unable to allocate memory for issuing "
7143 "NOP mailbox command\n");
7147 /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
7148 length
= (sizeof(struct lpfc_mbx_nop
) -
7149 sizeof(struct lpfc_sli4_cfg_mhdr
));
7150 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
7151 LPFC_MBOX_OPCODE_NOP
, length
, LPFC_SLI4_MBX_EMBED
);
7153 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
7154 for (cmdsent
= 0; cmdsent
< cnt
; cmdsent
++) {
7155 if (!phba
->sli4_hba
.intr_enable
)
7156 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7158 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
7159 if (rc
== MBX_TIMEOUT
)
7161 /* Check return status */
7162 shdr
= (union lpfc_sli4_cfg_shdr
*)
7163 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
7164 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
7165 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
7167 if (shdr_status
|| shdr_add_status
|| rc
) {
7168 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7169 "2520 NOP mailbox command failed "
7170 "status x%x add_status x%x mbx "
7171 "status x%x\n", shdr_status
,
7172 shdr_add_status
, rc
);
7177 if (rc
!= MBX_TIMEOUT
)
7178 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7184 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
7185 * @phba: pointer to lpfc hba data structure.
7187 * This routine is invoked to set up the PCI device memory space for device
7188 * with SLI-4 interface spec.
7192 * other values - error
7195 lpfc_sli4_pci_mem_setup(struct lpfc_hba
*phba
)
7197 struct pci_dev
*pdev
;
7198 unsigned long bar0map_len
, bar1map_len
, bar2map_len
;
7199 int error
= -ENODEV
;
7202 /* Obtain PCI device reference */
7206 pdev
= phba
->pcidev
;
7208 /* Set the device DMA mask size */
7209 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
7210 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
7211 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
7212 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
7218 * The BARs and register set definitions and offset locations are
7219 * dependent on the if_type.
7221 if (pci_read_config_dword(pdev
, LPFC_SLI_INTF
,
7222 &phba
->sli4_hba
.sli_intf
.word0
)) {
7226 /* There is no SLI3 failback for SLI4 devices. */
7227 if (bf_get(lpfc_sli_intf_valid
, &phba
->sli4_hba
.sli_intf
) !=
7228 LPFC_SLI_INTF_VALID
) {
7229 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7230 "2894 SLI_INTF reg contents invalid "
7231 "sli_intf reg 0x%x\n",
7232 phba
->sli4_hba
.sli_intf
.word0
);
7236 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
7238 * Get the bus address of SLI4 device Bar regions and the
7239 * number of bytes required by each mapping. The mapping of the
7240 * particular PCI BARs regions is dependent on the type of
7243 if (pci_resource_start(pdev
, 0)) {
7244 phba
->pci_bar0_map
= pci_resource_start(pdev
, 0);
7245 bar0map_len
= pci_resource_len(pdev
, 0);
7248 * Map SLI4 PCI Config Space Register base to a kernel virtual
7251 phba
->sli4_hba
.conf_regs_memmap_p
=
7252 ioremap(phba
->pci_bar0_map
, bar0map_len
);
7253 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
7254 dev_printk(KERN_ERR
, &pdev
->dev
,
7255 "ioremap failed for SLI4 PCI config "
7259 /* Set up BAR0 PCI config space register memory map */
7260 lpfc_sli4_bar0_register_memmap(phba
, if_type
);
7262 phba
->pci_bar0_map
= pci_resource_start(pdev
, 1);
7263 bar0map_len
= pci_resource_len(pdev
, 1);
7264 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
7265 dev_printk(KERN_ERR
, &pdev
->dev
,
7266 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
7269 phba
->sli4_hba
.conf_regs_memmap_p
=
7270 ioremap(phba
->pci_bar0_map
, bar0map_len
);
7271 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
7272 dev_printk(KERN_ERR
, &pdev
->dev
,
7273 "ioremap failed for SLI4 PCI config "
7277 lpfc_sli4_bar0_register_memmap(phba
, if_type
);
7280 if ((if_type
== LPFC_SLI_INTF_IF_TYPE_0
) &&
7281 (pci_resource_start(pdev
, 2))) {
7283 * Map SLI4 if type 0 HBA Control Register base to a kernel
7284 * virtual address and setup the registers.
7286 phba
->pci_bar1_map
= pci_resource_start(pdev
, 2);
7287 bar1map_len
= pci_resource_len(pdev
, 2);
7288 phba
->sli4_hba
.ctrl_regs_memmap_p
=
7289 ioremap(phba
->pci_bar1_map
, bar1map_len
);
7290 if (!phba
->sli4_hba
.ctrl_regs_memmap_p
) {
7291 dev_printk(KERN_ERR
, &pdev
->dev
,
7292 "ioremap failed for SLI4 HBA control registers.\n");
7293 goto out_iounmap_conf
;
7295 lpfc_sli4_bar1_register_memmap(phba
);
7298 if ((if_type
== LPFC_SLI_INTF_IF_TYPE_0
) &&
7299 (pci_resource_start(pdev
, 4))) {
7301 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
7302 * virtual address and setup the registers.
7304 phba
->pci_bar2_map
= pci_resource_start(pdev
, 4);
7305 bar2map_len
= pci_resource_len(pdev
, 4);
7306 phba
->sli4_hba
.drbl_regs_memmap_p
=
7307 ioremap(phba
->pci_bar2_map
, bar2map_len
);
7308 if (!phba
->sli4_hba
.drbl_regs_memmap_p
) {
7309 dev_printk(KERN_ERR
, &pdev
->dev
,
7310 "ioremap failed for SLI4 HBA doorbell registers.\n");
7311 goto out_iounmap_ctrl
;
7313 error
= lpfc_sli4_bar2_register_memmap(phba
, LPFC_VF0
);
7315 goto out_iounmap_all
;
7321 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
7323 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
7325 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
7331 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
7332 * @phba: pointer to lpfc hba data structure.
7334 * This routine is invoked to unset the PCI device memory space for device
7335 * with SLI-4 interface spec.
7338 lpfc_sli4_pci_mem_unset(struct lpfc_hba
*phba
)
7340 struct pci_dev
*pdev
;
7342 /* Obtain PCI device reference */
7346 pdev
= phba
->pcidev
;
7348 /* Free coherent DMA memory allocated */
7350 /* Unmap I/O memory space */
7351 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
7352 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
7353 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
7359 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
7360 * @phba: pointer to lpfc hba data structure.
7362 * This routine is invoked to enable the MSI-X interrupt vectors to device
7363 * with SLI-3 interface specs. The kernel function pci_enable_msix() is
7364 * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
7365 * invoked, enables either all or nothing, depending on the current
7366 * availability of PCI vector resources. The device driver is responsible
7367 * for calling the individual request_irq() to register each MSI-X vector
7368 * with a interrupt handler, which is done in this function. Note that
7369 * later when device is unloading, the driver should always call free_irq()
7370 * on all MSI-X vectors it has done request_irq() on before calling
7371 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
7372 * will be left with MSI-X enabled and leaks its vectors.
7376 * other values - error
7379 lpfc_sli_enable_msix(struct lpfc_hba
*phba
)
7384 /* Set up MSI-X multi-message vectors */
7385 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
7386 phba
->msix_entries
[i
].entry
= i
;
7388 /* Configure MSI-X capability structure */
7389 rc
= pci_enable_msix(phba
->pcidev
, phba
->msix_entries
,
7390 ARRAY_SIZE(phba
->msix_entries
));
7392 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7393 "0420 PCI enable MSI-X failed (%d)\n", rc
);
7396 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
7397 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7398 "0477 MSI-X entry[%d]: vector=x%x "
7400 phba
->msix_entries
[i
].vector
,
7401 phba
->msix_entries
[i
].entry
);
7403 * Assign MSI-X vectors to interrupt handlers
7406 /* vector-0 is associated to slow-path handler */
7407 rc
= request_irq(phba
->msix_entries
[0].vector
,
7408 &lpfc_sli_sp_intr_handler
, IRQF_SHARED
,
7409 LPFC_SP_DRIVER_HANDLER_NAME
, phba
);
7411 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7412 "0421 MSI-X slow-path request_irq failed "
7417 /* vector-1 is associated to fast-path handler */
7418 rc
= request_irq(phba
->msix_entries
[1].vector
,
7419 &lpfc_sli_fp_intr_handler
, IRQF_SHARED
,
7420 LPFC_FP_DRIVER_HANDLER_NAME
, phba
);
7423 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7424 "0429 MSI-X fast-path request_irq failed "
7430 * Configure HBA MSI-X attention conditions to messages
7432 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
7436 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7437 "0474 Unable to allocate memory for issuing "
7438 "MBOX_CONFIG_MSI command\n");
7441 rc
= lpfc_config_msi(phba
, pmb
);
7444 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
7445 if (rc
!= MBX_SUCCESS
) {
7446 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
7447 "0351 Config MSI mailbox command failed, "
7448 "mbxCmd x%x, mbxStatus x%x\n",
7449 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
);
7453 /* Free memory allocated for mailbox command */
7454 mempool_free(pmb
, phba
->mbox_mem_pool
);
7458 /* Free memory allocated for mailbox command */
7459 mempool_free(pmb
, phba
->mbox_mem_pool
);
7462 /* free the irq already requested */
7463 free_irq(phba
->msix_entries
[1].vector
, phba
);
7466 /* free the irq already requested */
7467 free_irq(phba
->msix_entries
[0].vector
, phba
);
7470 /* Unconfigure MSI-X capability structure */
7471 pci_disable_msix(phba
->pcidev
);
7476 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
7477 * @phba: pointer to lpfc hba data structure.
7479 * This routine is invoked to release the MSI-X vectors and then disable the
7480 * MSI-X interrupt mode to device with SLI-3 interface spec.
7483 lpfc_sli_disable_msix(struct lpfc_hba
*phba
)
7487 /* Free up MSI-X multi-message vectors */
7488 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
7489 free_irq(phba
->msix_entries
[i
].vector
, phba
);
7491 pci_disable_msix(phba
->pcidev
);
7497 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
7498 * @phba: pointer to lpfc hba data structure.
7500 * This routine is invoked to enable the MSI interrupt mode to device with
7501 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
7502 * enable the MSI vector. The device driver is responsible for calling the
7503 * request_irq() to register MSI vector with a interrupt the handler, which
7504 * is done in this function.
7508 * other values - error
7511 lpfc_sli_enable_msi(struct lpfc_hba
*phba
)
7515 rc
= pci_enable_msi(phba
->pcidev
);
7517 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7518 "0462 PCI enable MSI mode success.\n");
7520 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7521 "0471 PCI enable MSI mode failed (%d)\n", rc
);
7525 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
7526 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
7528 pci_disable_msi(phba
->pcidev
);
7529 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7530 "0478 MSI request_irq failed (%d)\n", rc
);
7536 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
7537 * @phba: pointer to lpfc hba data structure.
7539 * This routine is invoked to disable the MSI interrupt mode to device with
7540 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
7541 * done request_irq() on before calling pci_disable_msi(). Failure to do so
7542 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
7546 lpfc_sli_disable_msi(struct lpfc_hba
*phba
)
7548 free_irq(phba
->pcidev
->irq
, phba
);
7549 pci_disable_msi(phba
->pcidev
);
7554 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
7555 * @phba: pointer to lpfc hba data structure.
7557 * This routine is invoked to enable device interrupt and associate driver's
7558 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
7559 * spec. Depends on the interrupt mode configured to the driver, the driver
7560 * will try to fallback from the configured interrupt mode to an interrupt
7561 * mode which is supported by the platform, kernel, and device in the order
7563 * MSI-X -> MSI -> IRQ.
7567 * other values - error
7570 lpfc_sli_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
7572 uint32_t intr_mode
= LPFC_INTR_ERROR
;
7575 if (cfg_mode
== 2) {
7576 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
7577 retval
= lpfc_sli_config_port(phba
, LPFC_SLI_REV3
);
7579 /* Now, try to enable MSI-X interrupt mode */
7580 retval
= lpfc_sli_enable_msix(phba
);
7582 /* Indicate initialization to MSI-X mode */
7583 phba
->intr_type
= MSIX
;
7589 /* Fallback to MSI if MSI-X initialization failed */
7590 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
7591 retval
= lpfc_sli_enable_msi(phba
);
7593 /* Indicate initialization to MSI mode */
7594 phba
->intr_type
= MSI
;
7599 /* Fallback to INTx if both MSI-X/MSI initalization failed */
7600 if (phba
->intr_type
== NONE
) {
7601 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
7602 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
7604 /* Indicate initialization to INTx mode */
7605 phba
->intr_type
= INTx
;
7613 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
7614 * @phba: pointer to lpfc hba data structure.
7616 * This routine is invoked to disable device interrupt and disassociate the
7617 * driver's interrupt handler(s) from interrupt vector(s) to device with
7618 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
7619 * release the interrupt vector(s) for the message signaled interrupt.
7622 lpfc_sli_disable_intr(struct lpfc_hba
*phba
)
7624 /* Disable the currently initialized interrupt mode */
7625 if (phba
->intr_type
== MSIX
)
7626 lpfc_sli_disable_msix(phba
);
7627 else if (phba
->intr_type
== MSI
)
7628 lpfc_sli_disable_msi(phba
);
7629 else if (phba
->intr_type
== INTx
)
7630 free_irq(phba
->pcidev
->irq
, phba
);
7632 /* Reset interrupt management states */
7633 phba
->intr_type
= NONE
;
7634 phba
->sli
.slistat
.sli_intr
= 0;
7640 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
7641 * @phba: pointer to lpfc hba data structure.
7643 * This routine is invoked to enable the MSI-X interrupt vectors to device
7644 * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
7645 * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
7646 * enables either all or nothing, depending on the current availability of
7647 * PCI vector resources. The device driver is responsible for calling the
7648 * individual request_irq() to register each MSI-X vector with a interrupt
7649 * handler, which is done in this function. Note that later when device is
7650 * unloading, the driver should always call free_irq() on all MSI-X vectors
7651 * it has done request_irq() on before calling pci_disable_msix(). Failure
7652 * to do so results in a BUG_ON() and a device will be left with MSI-X
7653 * enabled and leaks its vectors.
7657 * other values - error
7660 lpfc_sli4_enable_msix(struct lpfc_hba
*phba
)
7662 int vectors
, rc
, index
;
7664 /* Set up MSI-X multi-message vectors */
7665 for (index
= 0; index
< phba
->sli4_hba
.cfg_eqn
; index
++)
7666 phba
->sli4_hba
.msix_entries
[index
].entry
= index
;
7668 /* Configure MSI-X capability structure */
7669 vectors
= phba
->sli4_hba
.cfg_eqn
;
7670 enable_msix_vectors
:
7671 rc
= pci_enable_msix(phba
->pcidev
, phba
->sli4_hba
.msix_entries
,
7675 goto enable_msix_vectors
;
7677 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7678 "0484 PCI enable MSI-X failed (%d)\n", rc
);
7682 /* Log MSI-X vector assignment */
7683 for (index
= 0; index
< vectors
; index
++)
7684 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7685 "0489 MSI-X entry[%d]: vector=x%x "
7686 "message=%d\n", index
,
7687 phba
->sli4_hba
.msix_entries
[index
].vector
,
7688 phba
->sli4_hba
.msix_entries
[index
].entry
);
7690 * Assign MSI-X vectors to interrupt handlers
7693 rc
= request_irq(phba
->sli4_hba
.msix_entries
[0].vector
,
7694 &lpfc_sli4_sp_intr_handler
, IRQF_SHARED
,
7695 LPFC_SP_DRIVER_HANDLER_NAME
, phba
);
7697 /* All Interrupts need to be handled by one EQ */
7698 rc
= request_irq(phba
->sli4_hba
.msix_entries
[0].vector
,
7699 &lpfc_sli4_intr_handler
, IRQF_SHARED
,
7700 LPFC_DRIVER_NAME
, phba
);
7702 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7703 "0485 MSI-X slow-path request_irq failed "
7708 /* The rest of the vector(s) are associated to fast-path handler(s) */
7709 for (index
= 1; index
< vectors
; index
++) {
7710 phba
->sli4_hba
.fcp_eq_hdl
[index
- 1].idx
= index
- 1;
7711 phba
->sli4_hba
.fcp_eq_hdl
[index
- 1].phba
= phba
;
7712 rc
= request_irq(phba
->sli4_hba
.msix_entries
[index
].vector
,
7713 &lpfc_sli4_fp_intr_handler
, IRQF_SHARED
,
7714 LPFC_FP_DRIVER_HANDLER_NAME
,
7715 &phba
->sli4_hba
.fcp_eq_hdl
[index
- 1]);
7717 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7718 "0486 MSI-X fast-path (%d) "
7719 "request_irq failed (%d)\n", index
, rc
);
7723 phba
->sli4_hba
.msix_vec_nr
= vectors
;
7728 /* free the irq already requested */
7729 for (--index
; index
>= 1; index
--)
7730 free_irq(phba
->sli4_hba
.msix_entries
[index
- 1].vector
,
7731 &phba
->sli4_hba
.fcp_eq_hdl
[index
- 1]);
7733 /* free the irq already requested */
7734 free_irq(phba
->sli4_hba
.msix_entries
[0].vector
, phba
);
7737 /* Unconfigure MSI-X capability structure */
7738 pci_disable_msix(phba
->pcidev
);
7743 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
7744 * @phba: pointer to lpfc hba data structure.
7746 * This routine is invoked to release the MSI-X vectors and then disable the
7747 * MSI-X interrupt mode to device with SLI-4 interface spec.
7750 lpfc_sli4_disable_msix(struct lpfc_hba
*phba
)
7754 /* Free up MSI-X multi-message vectors */
7755 free_irq(phba
->sli4_hba
.msix_entries
[0].vector
, phba
);
7757 for (index
= 1; index
< phba
->sli4_hba
.msix_vec_nr
; index
++)
7758 free_irq(phba
->sli4_hba
.msix_entries
[index
].vector
,
7759 &phba
->sli4_hba
.fcp_eq_hdl
[index
- 1]);
7762 pci_disable_msix(phba
->pcidev
);
7768 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
7769 * @phba: pointer to lpfc hba data structure.
7771 * This routine is invoked to enable the MSI interrupt mode to device with
7772 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
7773 * to enable the MSI vector. The device driver is responsible for calling
7774 * the request_irq() to register MSI vector with a interrupt the handler,
7775 * which is done in this function.
7779 * other values - error
7782 lpfc_sli4_enable_msi(struct lpfc_hba
*phba
)
7786 rc
= pci_enable_msi(phba
->pcidev
);
7788 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7789 "0487 PCI enable MSI mode success.\n");
7791 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7792 "0488 PCI enable MSI mode failed (%d)\n", rc
);
7796 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
7797 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
7799 pci_disable_msi(phba
->pcidev
);
7800 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7801 "0490 MSI request_irq failed (%d)\n", rc
);
7805 for (index
= 0; index
< phba
->cfg_fcp_eq_count
; index
++) {
7806 phba
->sli4_hba
.fcp_eq_hdl
[index
].idx
= index
;
7807 phba
->sli4_hba
.fcp_eq_hdl
[index
].phba
= phba
;
7814 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
7815 * @phba: pointer to lpfc hba data structure.
7817 * This routine is invoked to disable the MSI interrupt mode to device with
7818 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
7819 * done request_irq() on before calling pci_disable_msi(). Failure to do so
7820 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
7824 lpfc_sli4_disable_msi(struct lpfc_hba
*phba
)
7826 free_irq(phba
->pcidev
->irq
, phba
);
7827 pci_disable_msi(phba
->pcidev
);
7832 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
7833 * @phba: pointer to lpfc hba data structure.
7835 * This routine is invoked to enable device interrupt and associate driver's
7836 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
7837 * interface spec. Depends on the interrupt mode configured to the driver,
7838 * the driver will try to fallback from the configured interrupt mode to an
7839 * interrupt mode which is supported by the platform, kernel, and device in
7841 * MSI-X -> MSI -> IRQ.
7845 * other values - error
7848 lpfc_sli4_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
7850 uint32_t intr_mode
= LPFC_INTR_ERROR
;
7853 if (cfg_mode
== 2) {
7854 /* Preparation before conf_msi mbox cmd */
7857 /* Now, try to enable MSI-X interrupt mode */
7858 retval
= lpfc_sli4_enable_msix(phba
);
7860 /* Indicate initialization to MSI-X mode */
7861 phba
->intr_type
= MSIX
;
7867 /* Fallback to MSI if MSI-X initialization failed */
7868 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
7869 retval
= lpfc_sli4_enable_msi(phba
);
7871 /* Indicate initialization to MSI mode */
7872 phba
->intr_type
= MSI
;
7877 /* Fallback to INTx if both MSI-X/MSI initalization failed */
7878 if (phba
->intr_type
== NONE
) {
7879 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
7880 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
7882 /* Indicate initialization to INTx mode */
7883 phba
->intr_type
= INTx
;
7885 for (index
= 0; index
< phba
->cfg_fcp_eq_count
;
7887 phba
->sli4_hba
.fcp_eq_hdl
[index
].idx
= index
;
7888 phba
->sli4_hba
.fcp_eq_hdl
[index
].phba
= phba
;
7896 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
7897 * @phba: pointer to lpfc hba data structure.
7899 * This routine is invoked to disable device interrupt and disassociate
7900 * the driver's interrupt handler(s) from interrupt vector(s) to device
7901 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
7902 * will release the interrupt vector(s) for the message signaled interrupt.
7905 lpfc_sli4_disable_intr(struct lpfc_hba
*phba
)
7907 /* Disable the currently initialized interrupt mode */
7908 if (phba
->intr_type
== MSIX
)
7909 lpfc_sli4_disable_msix(phba
);
7910 else if (phba
->intr_type
== MSI
)
7911 lpfc_sli4_disable_msi(phba
);
7912 else if (phba
->intr_type
== INTx
)
7913 free_irq(phba
->pcidev
->irq
, phba
);
7915 /* Reset interrupt management states */
7916 phba
->intr_type
= NONE
;
7917 phba
->sli
.slistat
.sli_intr
= 0;
7923 * lpfc_unset_hba - Unset SLI3 hba device initialization
7924 * @phba: pointer to lpfc hba data structure.
7926 * This routine is invoked to unset the HBA device initialization steps to
7927 * a device with SLI-3 interface spec.
7930 lpfc_unset_hba(struct lpfc_hba
*phba
)
7932 struct lpfc_vport
*vport
= phba
->pport
;
7933 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7935 spin_lock_irq(shost
->host_lock
);
7936 vport
->load_flag
|= FC_UNLOADING
;
7937 spin_unlock_irq(shost
->host_lock
);
7939 lpfc_stop_hba_timers(phba
);
7941 phba
->pport
->work_port_events
= 0;
7943 lpfc_sli_hba_down(phba
);
7945 lpfc_sli_brdrestart(phba
);
7947 lpfc_sli_disable_intr(phba
);
7953 * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
7954 * @phba: pointer to lpfc hba data structure.
7956 * This routine is invoked to unset the HBA device initialization steps to
7957 * a device with SLI-4 interface spec.
7960 lpfc_sli4_unset_hba(struct lpfc_hba
*phba
)
7962 struct lpfc_vport
*vport
= phba
->pport
;
7963 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7965 spin_lock_irq(shost
->host_lock
);
7966 vport
->load_flag
|= FC_UNLOADING
;
7967 spin_unlock_irq(shost
->host_lock
);
7969 phba
->pport
->work_port_events
= 0;
7971 /* Stop the SLI4 device port */
7972 lpfc_stop_port(phba
);
7974 lpfc_sli4_disable_intr(phba
);
7976 /* Reset SLI4 HBA FCoE function */
7977 lpfc_pci_function_reset(phba
);
7983 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
7984 * @phba: Pointer to HBA context object.
7986 * This function is called in the SLI4 code path to wait for completion
7987 * of device's XRIs exchange busy. It will check the XRI exchange busy
7988 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
7989 * that, it will check the XRI exchange busy on outstanding FCP and ELS
7990 * I/Os every 30 seconds, log error message, and wait forever. Only when
7991 * all XRI exchange busy complete, the driver unload shall proceed with
7992 * invoking the function reset ioctl mailbox command to the CNA and the
7993 * the rest of the driver unload resource release.
7996 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba
*phba
)
7999 int fcp_xri_cmpl
= list_empty(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
8000 int els_xri_cmpl
= list_empty(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
8002 while (!fcp_xri_cmpl
|| !els_xri_cmpl
) {
8003 if (wait_time
> LPFC_XRI_EXCH_BUSY_WAIT_TMO
) {
8005 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8006 "2877 FCP XRI exchange busy "
8007 "wait time: %d seconds.\n",
8010 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8011 "2878 ELS XRI exchange busy "
8012 "wait time: %d seconds.\n",
8014 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2
);
8015 wait_time
+= LPFC_XRI_EXCH_BUSY_WAIT_T2
;
8017 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1
);
8018 wait_time
+= LPFC_XRI_EXCH_BUSY_WAIT_T1
;
8021 list_empty(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
8023 list_empty(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
8028 * lpfc_sli4_hba_unset - Unset the fcoe hba
8029 * @phba: Pointer to HBA context object.
8031 * This function is called in the SLI4 code path to reset the HBA's FCoE
8032 * function. The caller is not required to hold any lock. This routine
8033 * issues PCI function reset mailbox command to reset the FCoE function.
8034 * At the end of the function, it calls lpfc_hba_down_post function to
8035 * free any pending commands.
8038 lpfc_sli4_hba_unset(struct lpfc_hba
*phba
)
8041 LPFC_MBOXQ_t
*mboxq
;
8042 struct pci_dev
*pdev
= phba
->pcidev
;
8044 lpfc_stop_hba_timers(phba
);
8045 phba
->sli4_hba
.intr_enable
= 0;
8048 * Gracefully wait out the potential current outstanding asynchronous
8052 /* First, block any pending async mailbox command from posted */
8053 spin_lock_irq(&phba
->hbalock
);
8054 phba
->sli
.sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
8055 spin_unlock_irq(&phba
->hbalock
);
8056 /* Now, trying to wait it out if we can */
8057 while (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
8059 if (++wait_cnt
> LPFC_ACTIVE_MBOX_WAIT_CNT
)
8062 /* Forcefully release the outstanding mailbox command if timed out */
8063 if (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
8064 spin_lock_irq(&phba
->hbalock
);
8065 mboxq
= phba
->sli
.mbox_active
;
8066 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
8067 __lpfc_mbox_cmpl_put(phba
, mboxq
);
8068 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8069 phba
->sli
.mbox_active
= NULL
;
8070 spin_unlock_irq(&phba
->hbalock
);
8073 /* Abort all iocbs associated with the hba */
8074 lpfc_sli_hba_iocb_abort(phba
);
8076 /* Wait for completion of device XRI exchange busy */
8077 lpfc_sli4_xri_exchange_busy_wait(phba
);
8079 /* Disable PCI subsystem interrupt */
8080 lpfc_sli4_disable_intr(phba
);
8082 /* Disable SR-IOV if enabled */
8083 if (phba
->cfg_sriov_nr_virtfn
)
8084 pci_disable_sriov(pdev
);
8086 /* Stop kthread signal shall trigger work_done one more time */
8087 kthread_stop(phba
->worker_thread
);
8089 /* Reset SLI4 HBA FCoE function */
8090 lpfc_pci_function_reset(phba
);
8092 /* Stop the SLI4 device port */
8093 phba
->pport
->work_port_events
= 0;
8097 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
8098 * @phba: Pointer to HBA context object.
8099 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8101 * This function is called in the SLI4 code path to read the port's
8102 * sli4 capabilities.
8104 * This function may be be called from any context that can block-wait
8105 * for the completion. The expectation is that this routine is called
8106 * typically from probe_one or from the online routine.
8109 lpfc_pc_sli4_params_get(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
8112 struct lpfc_mqe
*mqe
;
8113 struct lpfc_pc_sli4_params
*sli4_params
;
8117 mqe
= &mboxq
->u
.mqe
;
8119 /* Read the port's SLI4 Parameters port capabilities */
8120 lpfc_pc_sli4_params(mboxq
);
8121 if (!phba
->sli4_hba
.intr_enable
)
8122 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
8124 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_PORT_CAPABILITIES
);
8125 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
8131 sli4_params
= &phba
->sli4_hba
.pc_sli4_params
;
8132 sli4_params
->if_type
= bf_get(if_type
, &mqe
->un
.sli4_params
);
8133 sli4_params
->sli_rev
= bf_get(sli_rev
, &mqe
->un
.sli4_params
);
8134 sli4_params
->sli_family
= bf_get(sli_family
, &mqe
->un
.sli4_params
);
8135 sli4_params
->featurelevel_1
= bf_get(featurelevel_1
,
8136 &mqe
->un
.sli4_params
);
8137 sli4_params
->featurelevel_2
= bf_get(featurelevel_2
,
8138 &mqe
->un
.sli4_params
);
8139 sli4_params
->proto_types
= mqe
->un
.sli4_params
.word3
;
8140 sli4_params
->sge_supp_len
= mqe
->un
.sli4_params
.sge_supp_len
;
8141 sli4_params
->if_page_sz
= bf_get(if_page_sz
, &mqe
->un
.sli4_params
);
8142 sli4_params
->rq_db_window
= bf_get(rq_db_window
, &mqe
->un
.sli4_params
);
8143 sli4_params
->loopbk_scope
= bf_get(loopbk_scope
, &mqe
->un
.sli4_params
);
8144 sli4_params
->eq_pages_max
= bf_get(eq_pages
, &mqe
->un
.sli4_params
);
8145 sli4_params
->eqe_size
= bf_get(eqe_size
, &mqe
->un
.sli4_params
);
8146 sli4_params
->cq_pages_max
= bf_get(cq_pages
, &mqe
->un
.sli4_params
);
8147 sli4_params
->cqe_size
= bf_get(cqe_size
, &mqe
->un
.sli4_params
);
8148 sli4_params
->mq_pages_max
= bf_get(mq_pages
, &mqe
->un
.sli4_params
);
8149 sli4_params
->mqe_size
= bf_get(mqe_size
, &mqe
->un
.sli4_params
);
8150 sli4_params
->mq_elem_cnt
= bf_get(mq_elem_cnt
, &mqe
->un
.sli4_params
);
8151 sli4_params
->wq_pages_max
= bf_get(wq_pages
, &mqe
->un
.sli4_params
);
8152 sli4_params
->wqe_size
= bf_get(wqe_size
, &mqe
->un
.sli4_params
);
8153 sli4_params
->rq_pages_max
= bf_get(rq_pages
, &mqe
->un
.sli4_params
);
8154 sli4_params
->rqe_size
= bf_get(rqe_size
, &mqe
->un
.sli4_params
);
8155 sli4_params
->hdr_pages_max
= bf_get(hdr_pages
, &mqe
->un
.sli4_params
);
8156 sli4_params
->hdr_size
= bf_get(hdr_size
, &mqe
->un
.sli4_params
);
8157 sli4_params
->hdr_pp_align
= bf_get(hdr_pp_align
, &mqe
->un
.sli4_params
);
8158 sli4_params
->sgl_pages_max
= bf_get(sgl_pages
, &mqe
->un
.sli4_params
);
8159 sli4_params
->sgl_pp_align
= bf_get(sgl_pp_align
, &mqe
->un
.sli4_params
);
8161 /* Make sure that sge_supp_len can be handled by the driver */
8162 if (sli4_params
->sge_supp_len
> LPFC_MAX_SGE_SIZE
)
8163 sli4_params
->sge_supp_len
= LPFC_MAX_SGE_SIZE
;
8169 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
8170 * @phba: Pointer to HBA context object.
8171 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8173 * This function is called in the SLI4 code path to read the port's
8174 * sli4 capabilities.
8176 * This function may be be called from any context that can block-wait
8177 * for the completion. The expectation is that this routine is called
8178 * typically from probe_one or from the online routine.
8181 lpfc_get_sli4_parameters(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
8184 struct lpfc_mqe
*mqe
= &mboxq
->u
.mqe
;
8185 struct lpfc_pc_sli4_params
*sli4_params
;
8187 struct lpfc_sli4_parameters
*mbx_sli4_parameters
;
8190 * By default, the driver assumes the SLI4 port requires RPI
8191 * header postings. The SLI4_PARAM response will correct this
8194 phba
->sli4_hba
.rpi_hdrs_in_use
= 1;
8196 /* Read the port's SLI4 Config Parameters */
8197 length
= (sizeof(struct lpfc_mbx_get_sli4_parameters
) -
8198 sizeof(struct lpfc_sli4_cfg_mhdr
));
8199 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
8200 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS
,
8201 length
, LPFC_SLI4_MBX_EMBED
);
8202 if (!phba
->sli4_hba
.intr_enable
)
8203 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
8205 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
,
8206 lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
));
8209 sli4_params
= &phba
->sli4_hba
.pc_sli4_params
;
8210 mbx_sli4_parameters
= &mqe
->un
.get_sli4_parameters
.sli4_parameters
;
8211 sli4_params
->if_type
= bf_get(cfg_if_type
, mbx_sli4_parameters
);
8212 sli4_params
->sli_rev
= bf_get(cfg_sli_rev
, mbx_sli4_parameters
);
8213 sli4_params
->sli_family
= bf_get(cfg_sli_family
, mbx_sli4_parameters
);
8214 sli4_params
->featurelevel_1
= bf_get(cfg_sli_hint_1
,
8215 mbx_sli4_parameters
);
8216 sli4_params
->featurelevel_2
= bf_get(cfg_sli_hint_2
,
8217 mbx_sli4_parameters
);
8218 if (bf_get(cfg_phwq
, mbx_sli4_parameters
))
8219 phba
->sli3_options
|= LPFC_SLI4_PHWQ_ENABLED
;
8221 phba
->sli3_options
&= ~LPFC_SLI4_PHWQ_ENABLED
;
8222 sli4_params
->sge_supp_len
= mbx_sli4_parameters
->sge_supp_len
;
8223 sli4_params
->loopbk_scope
= bf_get(loopbk_scope
, mbx_sli4_parameters
);
8224 sli4_params
->cqv
= bf_get(cfg_cqv
, mbx_sli4_parameters
);
8225 sli4_params
->mqv
= bf_get(cfg_mqv
, mbx_sli4_parameters
);
8226 sli4_params
->wqv
= bf_get(cfg_wqv
, mbx_sli4_parameters
);
8227 sli4_params
->rqv
= bf_get(cfg_rqv
, mbx_sli4_parameters
);
8228 sli4_params
->sgl_pages_max
= bf_get(cfg_sgl_page_cnt
,
8229 mbx_sli4_parameters
);
8230 sli4_params
->sgl_pp_align
= bf_get(cfg_sgl_pp_align
,
8231 mbx_sli4_parameters
);
8232 phba
->sli4_hba
.extents_in_use
= bf_get(cfg_ext
, mbx_sli4_parameters
);
8233 phba
->sli4_hba
.rpi_hdrs_in_use
= bf_get(cfg_hdrr
, mbx_sli4_parameters
);
8235 /* Make sure that sge_supp_len can be handled by the driver */
8236 if (sli4_params
->sge_supp_len
> LPFC_MAX_SGE_SIZE
)
8237 sli4_params
->sge_supp_len
= LPFC_MAX_SGE_SIZE
;
8243 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
8244 * @pdev: pointer to PCI device
8245 * @pid: pointer to PCI device identifier
8247 * This routine is to be called to attach a device with SLI-3 interface spec
8248 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8249 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
8250 * information of the device and driver to see if the driver state that it can
8251 * support this kind of device. If the match is successful, the driver core
8252 * invokes this routine. If this routine determines it can claim the HBA, it
8253 * does all the initialization that it needs to do to handle the HBA properly.
8256 * 0 - driver can claim the device
8257 * negative value - driver can not claim the device
8259 static int __devinit
8260 lpfc_pci_probe_one_s3(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
8262 struct lpfc_hba
*phba
;
8263 struct lpfc_vport
*vport
= NULL
;
8264 struct Scsi_Host
*shost
= NULL
;
8266 uint32_t cfg_mode
, intr_mode
;
8268 /* Allocate memory for HBA structure */
8269 phba
= lpfc_hba_alloc(pdev
);
8273 /* Perform generic PCI device enabling operation */
8274 error
= lpfc_enable_pci_dev(phba
);
8276 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8277 "1401 Failed to enable pci device.\n");
8281 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
8282 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_LP
);
8284 goto out_disable_pci_dev
;
8286 /* Set up SLI-3 specific device PCI memory space */
8287 error
= lpfc_sli_pci_mem_setup(phba
);
8289 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8290 "1402 Failed to set up pci memory space.\n");
8291 goto out_disable_pci_dev
;
8294 /* Set up phase-1 common device driver resources */
8295 error
= lpfc_setup_driver_resource_phase1(phba
);
8297 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8298 "1403 Failed to set up driver resource.\n");
8299 goto out_unset_pci_mem_s3
;
8302 /* Set up SLI-3 specific device driver resources */
8303 error
= lpfc_sli_driver_resource_setup(phba
);
8305 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8306 "1404 Failed to set up driver resource.\n");
8307 goto out_unset_pci_mem_s3
;
8310 /* Initialize and populate the iocb list per host */
8311 error
= lpfc_init_iocb_list(phba
, LPFC_IOCB_LIST_CNT
);
8313 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8314 "1405 Failed to initialize iocb list.\n");
8315 goto out_unset_driver_resource_s3
;
8318 /* Set up common device driver resources */
8319 error
= lpfc_setup_driver_resource_phase2(phba
);
8321 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8322 "1406 Failed to set up driver resource.\n");
8323 goto out_free_iocb_list
;
8326 /* Create SCSI host to the physical port */
8327 error
= lpfc_create_shost(phba
);
8329 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8330 "1407 Failed to create scsi host.\n");
8331 goto out_unset_driver_resource
;
8334 /* Configure sysfs attributes */
8335 vport
= phba
->pport
;
8336 error
= lpfc_alloc_sysfs_attr(vport
);
8338 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8339 "1476 Failed to allocate sysfs attr\n");
8340 goto out_destroy_shost
;
8343 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
8344 /* Now, trying to enable interrupt and bring up the device */
8345 cfg_mode
= phba
->cfg_use_msi
;
8347 /* Put device to a known state before enabling interrupt */
8348 lpfc_stop_port(phba
);
8349 /* Configure and enable interrupt */
8350 intr_mode
= lpfc_sli_enable_intr(phba
, cfg_mode
);
8351 if (intr_mode
== LPFC_INTR_ERROR
) {
8352 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8353 "0431 Failed to enable interrupt.\n");
8355 goto out_free_sysfs_attr
;
8357 /* SLI-3 HBA setup */
8358 if (lpfc_sli_hba_setup(phba
)) {
8359 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8360 "1477 Failed to set up hba\n");
8362 goto out_remove_device
;
8365 /* Wait 50ms for the interrupts of previous mailbox commands */
8367 /* Check active interrupts on message signaled interrupts */
8368 if (intr_mode
== 0 ||
8369 phba
->sli
.slistat
.sli_intr
> LPFC_MSIX_VECTORS
) {
8370 /* Log the current active interrupt mode */
8371 phba
->intr_mode
= intr_mode
;
8372 lpfc_log_intr_mode(phba
, intr_mode
);
8375 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8376 "0447 Configure interrupt mode (%d) "
8377 "failed active interrupt test.\n",
8379 /* Disable the current interrupt mode */
8380 lpfc_sli_disable_intr(phba
);
8381 /* Try next level of interrupt mode */
8382 cfg_mode
= --intr_mode
;
8386 /* Perform post initialization setup */
8387 lpfc_post_init_setup(phba
);
8389 /* Check if there are static vports to be created. */
8390 lpfc_create_static_vport(phba
);
8395 lpfc_unset_hba(phba
);
8396 out_free_sysfs_attr
:
8397 lpfc_free_sysfs_attr(vport
);
8399 lpfc_destroy_shost(phba
);
8400 out_unset_driver_resource
:
8401 lpfc_unset_driver_resource_phase2(phba
);
8403 lpfc_free_iocb_list(phba
);
8404 out_unset_driver_resource_s3
:
8405 lpfc_sli_driver_resource_unset(phba
);
8406 out_unset_pci_mem_s3
:
8407 lpfc_sli_pci_mem_unset(phba
);
8408 out_disable_pci_dev
:
8409 lpfc_disable_pci_dev(phba
);
8411 scsi_host_put(shost
);
8413 lpfc_hba_free(phba
);
8418 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
8419 * @pdev: pointer to PCI device
8421 * This routine is to be called to disattach a device with SLI-3 interface
8422 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8423 * removed from PCI bus, it performs all the necessary cleanup for the HBA
8424 * device to be removed from the PCI subsystem properly.
8426 static void __devexit
8427 lpfc_pci_remove_one_s3(struct pci_dev
*pdev
)
8429 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8430 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
8431 struct lpfc_vport
**vports
;
8432 struct lpfc_hba
*phba
= vport
->phba
;
8434 int bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
8436 spin_lock_irq(&phba
->hbalock
);
8437 vport
->load_flag
|= FC_UNLOADING
;
8438 spin_unlock_irq(&phba
->hbalock
);
8440 lpfc_free_sysfs_attr(vport
);
8442 /* Release all the vports against this physical port */
8443 vports
= lpfc_create_vport_work_array(phba
);
8445 for (i
= 1; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
8446 fc_vport_terminate(vports
[i
]->fc_vport
);
8447 lpfc_destroy_vport_work_array(phba
, vports
);
8449 /* Remove FC host and then SCSI host with the physical port */
8450 fc_remove_host(shost
);
8451 scsi_remove_host(shost
);
8452 lpfc_cleanup(vport
);
8455 * Bring down the SLI Layer. This step disable all interrupts,
8456 * clears the rings, discards all mailbox commands, and resets
8460 /* HBA interrupt will be disabled after this call */
8461 lpfc_sli_hba_down(phba
);
8462 /* Stop kthread signal shall trigger work_done one more time */
8463 kthread_stop(phba
->worker_thread
);
8464 /* Final cleanup of txcmplq and reset the HBA */
8465 lpfc_sli_brdrestart(phba
);
8467 lpfc_stop_hba_timers(phba
);
8468 spin_lock_irq(&phba
->hbalock
);
8469 list_del_init(&vport
->listentry
);
8470 spin_unlock_irq(&phba
->hbalock
);
8472 lpfc_debugfs_terminate(vport
);
8474 /* Disable SR-IOV if enabled */
8475 if (phba
->cfg_sriov_nr_virtfn
)
8476 pci_disable_sriov(pdev
);
8478 /* Disable interrupt */
8479 lpfc_sli_disable_intr(phba
);
8481 pci_set_drvdata(pdev
, NULL
);
8482 scsi_host_put(shost
);
8485 * Call scsi_free before mem_free since scsi bufs are released to their
8486 * corresponding pools here.
8488 lpfc_scsi_free(phba
);
8489 lpfc_mem_free_all(phba
);
8491 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
8492 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
8494 /* Free resources associated with SLI2 interface */
8495 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
8496 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
8498 /* unmap adapter SLIM and Control Registers */
8499 iounmap(phba
->ctrl_regs_memmap_p
);
8500 iounmap(phba
->slim_memmap_p
);
8502 lpfc_hba_free(phba
);
8504 pci_release_selected_regions(pdev
, bars
);
8505 pci_disable_device(pdev
);
8509 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
8510 * @pdev: pointer to PCI device
8511 * @msg: power management message
8513 * This routine is to be called from the kernel's PCI subsystem to support
8514 * system Power Management (PM) to device with SLI-3 interface spec. When
8515 * PM invokes this method, it quiesces the device by stopping the driver's
8516 * worker thread for the device, turning off device's interrupt and DMA,
8517 * and bring the device offline. Note that as the driver implements the
8518 * minimum PM requirements to a power-aware driver's PM support for the
8519 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
8520 * to the suspend() method call will be treated as SUSPEND and the driver will
8521 * fully reinitialize its device during resume() method call, the driver will
8522 * set device to PCI_D3hot state in PCI config space instead of setting it
8523 * according to the @msg provided by the PM.
8526 * 0 - driver suspended the device
8530 lpfc_pci_suspend_one_s3(struct pci_dev
*pdev
, pm_message_t msg
)
8532 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8533 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8535 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8536 "0473 PCI device Power Management suspend.\n");
8538 /* Bring down the device */
8539 lpfc_offline_prep(phba
);
8541 kthread_stop(phba
->worker_thread
);
8543 /* Disable interrupt from device */
8544 lpfc_sli_disable_intr(phba
);
8546 /* Save device state to PCI config space */
8547 pci_save_state(pdev
);
8548 pci_set_power_state(pdev
, PCI_D3hot
);
8554 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
8555 * @pdev: pointer to PCI device
8557 * This routine is to be called from the kernel's PCI subsystem to support
8558 * system Power Management (PM) to device with SLI-3 interface spec. When PM
8559 * invokes this method, it restores the device's PCI config space state and
8560 * fully reinitializes the device and brings it online. Note that as the
8561 * driver implements the minimum PM requirements to a power-aware driver's
8562 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
8563 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
8564 * driver will fully reinitialize its device during resume() method call,
8565 * the device will be set to PCI_D0 directly in PCI config space before
8566 * restoring the state.
8569 * 0 - driver suspended the device
8573 lpfc_pci_resume_one_s3(struct pci_dev
*pdev
)
8575 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8576 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8580 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8581 "0452 PCI device Power Management resume.\n");
8583 /* Restore device state from PCI config space */
8584 pci_set_power_state(pdev
, PCI_D0
);
8585 pci_restore_state(pdev
);
8588 * As the new kernel behavior of pci_restore_state() API call clears
8589 * device saved_state flag, need to save the restored state again.
8591 pci_save_state(pdev
);
8593 if (pdev
->is_busmaster
)
8594 pci_set_master(pdev
);
8596 /* Startup the kernel thread for this host adapter. */
8597 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
8598 "lpfc_worker_%d", phba
->brd_no
);
8599 if (IS_ERR(phba
->worker_thread
)) {
8600 error
= PTR_ERR(phba
->worker_thread
);
8601 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8602 "0434 PM resume failed to start worker "
8603 "thread: error=x%x.\n", error
);
8607 /* Configure and enable interrupt */
8608 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
8609 if (intr_mode
== LPFC_INTR_ERROR
) {
8610 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8611 "0430 PM resume Failed to enable interrupt\n");
8614 phba
->intr_mode
= intr_mode
;
8616 /* Restart HBA and bring it online */
8617 lpfc_sli_brdrestart(phba
);
8620 /* Log the current active interrupt mode */
8621 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
8627 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
8628 * @phba: pointer to lpfc hba data structure.
8630 * This routine is called to prepare the SLI3 device for PCI slot recover. It
8631 * aborts all the outstanding SCSI I/Os to the pci device.
8634 lpfc_sli_prep_dev_for_recover(struct lpfc_hba
*phba
)
8636 struct lpfc_sli
*psli
= &phba
->sli
;
8637 struct lpfc_sli_ring
*pring
;
8639 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8640 "2723 PCI channel I/O abort preparing for recovery\n");
8643 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
8644 * and let the SCSI mid-layer to retry them to recover.
8646 pring
= &psli
->ring
[psli
->fcp_ring
];
8647 lpfc_sli_abort_iocb_ring(phba
, pring
);
8651 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
8652 * @phba: pointer to lpfc hba data structure.
8654 * This routine is called to prepare the SLI3 device for PCI slot reset. It
8655 * disables the device interrupt and pci device, and aborts the internal FCP
8659 lpfc_sli_prep_dev_for_reset(struct lpfc_hba
*phba
)
8661 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8662 "2710 PCI channel disable preparing for reset\n");
8664 /* Block any management I/Os to the device */
8665 lpfc_block_mgmt_io(phba
);
8667 /* Block all SCSI devices' I/Os on the host */
8668 lpfc_scsi_dev_block(phba
);
8670 /* stop all timers */
8671 lpfc_stop_hba_timers(phba
);
8673 /* Disable interrupt and pci device */
8674 lpfc_sli_disable_intr(phba
);
8675 pci_disable_device(phba
->pcidev
);
8677 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
8678 lpfc_sli_flush_fcp_rings(phba
);
8682 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
8683 * @phba: pointer to lpfc hba data structure.
8685 * This routine is called to prepare the SLI3 device for PCI slot permanently
8686 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
8690 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
8692 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8693 "2711 PCI channel permanent disable for failure\n");
8694 /* Block all SCSI devices' I/Os on the host */
8695 lpfc_scsi_dev_block(phba
);
8697 /* stop all timers */
8698 lpfc_stop_hba_timers(phba
);
8700 /* Clean up all driver's outstanding SCSI I/Os */
8701 lpfc_sli_flush_fcp_rings(phba
);
8705 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
8706 * @pdev: pointer to PCI device.
8707 * @state: the current PCI connection state.
8709 * This routine is called from the PCI subsystem for I/O error handling to
8710 * device with SLI-3 interface spec. This function is called by the PCI
8711 * subsystem after a PCI bus error affecting this device has been detected.
8712 * When this function is invoked, it will need to stop all the I/Os and
8713 * interrupt(s) to the device. Once that is done, it will return
8714 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
8718 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
8719 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
8720 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
8722 static pci_ers_result_t
8723 lpfc_io_error_detected_s3(struct pci_dev
*pdev
, pci_channel_state_t state
)
8725 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8726 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8729 case pci_channel_io_normal
:
8730 /* Non-fatal error, prepare for recovery */
8731 lpfc_sli_prep_dev_for_recover(phba
);
8732 return PCI_ERS_RESULT_CAN_RECOVER
;
8733 case pci_channel_io_frozen
:
8734 /* Fatal error, prepare for slot reset */
8735 lpfc_sli_prep_dev_for_reset(phba
);
8736 return PCI_ERS_RESULT_NEED_RESET
;
8737 case pci_channel_io_perm_failure
:
8738 /* Permanent failure, prepare for device down */
8739 lpfc_sli_prep_dev_for_perm_failure(phba
);
8740 return PCI_ERS_RESULT_DISCONNECT
;
8742 /* Unknown state, prepare and request slot reset */
8743 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8744 "0472 Unknown PCI error state: x%x\n", state
);
8745 lpfc_sli_prep_dev_for_reset(phba
);
8746 return PCI_ERS_RESULT_NEED_RESET
;
8751 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
8752 * @pdev: pointer to PCI device.
8754 * This routine is called from the PCI subsystem for error handling to
8755 * device with SLI-3 interface spec. This is called after PCI bus has been
8756 * reset to restart the PCI card from scratch, as if from a cold-boot.
8757 * During the PCI subsystem error recovery, after driver returns
8758 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
8759 * recovery and then call this routine before calling the .resume method
8760 * to recover the device. This function will initialize the HBA device,
8761 * enable the interrupt, but it will just put the HBA to offline state
8762 * without passing any I/O traffic.
8765 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
8766 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
8768 static pci_ers_result_t
8769 lpfc_io_slot_reset_s3(struct pci_dev
*pdev
)
8771 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8772 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8773 struct lpfc_sli
*psli
= &phba
->sli
;
8776 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
8777 if (pci_enable_device_mem(pdev
)) {
8778 printk(KERN_ERR
"lpfc: Cannot re-enable "
8779 "PCI device after reset.\n");
8780 return PCI_ERS_RESULT_DISCONNECT
;
8783 pci_restore_state(pdev
);
8786 * As the new kernel behavior of pci_restore_state() API call clears
8787 * device saved_state flag, need to save the restored state again.
8789 pci_save_state(pdev
);
8791 if (pdev
->is_busmaster
)
8792 pci_set_master(pdev
);
8794 spin_lock_irq(&phba
->hbalock
);
8795 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
8796 spin_unlock_irq(&phba
->hbalock
);
8798 /* Configure and enable interrupt */
8799 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
8800 if (intr_mode
== LPFC_INTR_ERROR
) {
8801 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8802 "0427 Cannot re-enable interrupt after "
8804 return PCI_ERS_RESULT_DISCONNECT
;
8806 phba
->intr_mode
= intr_mode
;
8808 /* Take device offline, it will perform cleanup */
8809 lpfc_offline_prep(phba
);
8811 lpfc_sli_brdrestart(phba
);
8813 /* Log the current active interrupt mode */
8814 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
8816 return PCI_ERS_RESULT_RECOVERED
;
8820 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
8821 * @pdev: pointer to PCI device
8823 * This routine is called from the PCI subsystem for error handling to device
8824 * with SLI-3 interface spec. It is called when kernel error recovery tells
8825 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
8826 * error recovery. After this call, traffic can start to flow from this device
8830 lpfc_io_resume_s3(struct pci_dev
*pdev
)
8832 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8833 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8835 /* Bring device online, it will be no-op for non-fatal error resume */
8838 /* Clean up Advanced Error Reporting (AER) if needed */
8839 if (phba
->hba_flag
& HBA_AER_ENABLED
)
8840 pci_cleanup_aer_uncorrect_error_status(pdev
);
8844 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
8845 * @phba: pointer to lpfc hba data structure.
8847 * returns the number of ELS/CT IOCBs to reserve
8850 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba
*phba
)
8852 int max_xri
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
8854 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
8857 else if (max_xri
<= 256)
8859 else if (max_xri
<= 512)
8861 else if (max_xri
<= 1024)
8870 * lpfc_write_firmware - attempt to write a firmware image to the port
8871 * @phba: pointer to lpfc hba data structure.
8872 * @fw: pointer to firmware image returned from request_firmware.
8874 * returns the number of bytes written if write is successful.
8875 * returns a negative error value if there were errors.
8876 * returns 0 if firmware matches currently active firmware on port.
8879 lpfc_write_firmware(struct lpfc_hba
*phba
, const struct firmware
*fw
)
8882 struct lpfc_grp_hdr
*image
= (struct lpfc_grp_hdr
*)fw
->data
;
8883 struct list_head dma_buffer_list
;
8885 struct lpfc_dmabuf
*dmabuf
, *next
;
8886 uint32_t offset
= 0, temp_offset
= 0;
8888 INIT_LIST_HEAD(&dma_buffer_list
);
8889 if ((image
->magic_number
!= LPFC_GROUP_OJECT_MAGIC_NUM
) ||
8890 (bf_get(lpfc_grp_hdr_file_type
, image
) != LPFC_FILE_TYPE_GROUP
) ||
8891 (bf_get(lpfc_grp_hdr_id
, image
) != LPFC_FILE_ID_GROUP
) ||
8892 (image
->size
!= fw
->size
)) {
8893 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8894 "3022 Invalid FW image found. "
8895 "Magic:%d Type:%x ID:%x\n",
8896 image
->magic_number
,
8897 bf_get(lpfc_grp_hdr_file_type
, image
),
8898 bf_get(lpfc_grp_hdr_id
, image
));
8901 lpfc_decode_firmware_rev(phba
, fwrev
, 1);
8902 if (strncmp(fwrev
, image
->revision
, strnlen(image
->revision
, 16))) {
8903 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8904 "3023 Updating Firmware. Current Version:%s "
8906 fwrev
, image
->revision
);
8907 for (i
= 0; i
< LPFC_MBX_WR_CONFIG_MAX_BDE
; i
++) {
8908 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
),
8914 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
8918 if (!dmabuf
->virt
) {
8923 list_add_tail(&dmabuf
->list
, &dma_buffer_list
);
8925 while (offset
< fw
->size
) {
8926 temp_offset
= offset
;
8927 list_for_each_entry(dmabuf
, &dma_buffer_list
, list
) {
8928 if (offset
+ SLI4_PAGE_SIZE
> fw
->size
) {
8929 temp_offset
+= fw
->size
- offset
;
8930 memcpy(dmabuf
->virt
,
8931 fw
->data
+ temp_offset
,
8935 memcpy(dmabuf
->virt
, fw
->data
+ temp_offset
,
8937 temp_offset
+= SLI4_PAGE_SIZE
;
8939 rc
= lpfc_wr_object(phba
, &dma_buffer_list
,
8940 (fw
->size
- offset
), &offset
);
8942 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8943 "3024 Firmware update failed. "
8951 list_for_each_entry_safe(dmabuf
, next
, &dma_buffer_list
, list
) {
8952 list_del(&dmabuf
->list
);
8953 dma_free_coherent(&phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
8954 dmabuf
->virt
, dmabuf
->phys
);
8961 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
8962 * @pdev: pointer to PCI device
8963 * @pid: pointer to PCI device identifier
8965 * This routine is called from the kernel's PCI subsystem to device with
8966 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
8967 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
8968 * information of the device and driver to see if the driver state that it
8969 * can support this kind of device. If the match is successful, the driver
8970 * core invokes this routine. If this routine determines it can claim the HBA,
8971 * it does all the initialization that it needs to do to handle the HBA
8975 * 0 - driver can claim the device
8976 * negative value - driver can not claim the device
8978 static int __devinit
8979 lpfc_pci_probe_one_s4(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
8981 struct lpfc_hba
*phba
;
8982 struct lpfc_vport
*vport
= NULL
;
8983 struct Scsi_Host
*shost
= NULL
;
8985 uint32_t cfg_mode
, intr_mode
;
8987 int adjusted_fcp_eq_count
;
8989 const struct firmware
*fw
;
8990 uint8_t file_name
[16];
8992 /* Allocate memory for HBA structure */
8993 phba
= lpfc_hba_alloc(pdev
);
8997 /* Perform generic PCI device enabling operation */
8998 error
= lpfc_enable_pci_dev(phba
);
9000 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9001 "1409 Failed to enable pci device.\n");
9005 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
9006 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_OC
);
9008 goto out_disable_pci_dev
;
9010 /* Set up SLI-4 specific device PCI memory space */
9011 error
= lpfc_sli4_pci_mem_setup(phba
);
9013 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9014 "1410 Failed to set up pci memory space.\n");
9015 goto out_disable_pci_dev
;
9018 /* Set up phase-1 common device driver resources */
9019 error
= lpfc_setup_driver_resource_phase1(phba
);
9021 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9022 "1411 Failed to set up driver resource.\n");
9023 goto out_unset_pci_mem_s4
;
9026 /* Set up SLI-4 Specific device driver resources */
9027 error
= lpfc_sli4_driver_resource_setup(phba
);
9029 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9030 "1412 Failed to set up driver resource.\n");
9031 goto out_unset_pci_mem_s4
;
9034 /* Initialize and populate the iocb list per host */
9036 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9037 "2821 initialize iocb list %d.\n",
9038 phba
->cfg_iocb_cnt
*1024);
9039 error
= lpfc_init_iocb_list(phba
, phba
->cfg_iocb_cnt
*1024);
9042 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9043 "1413 Failed to initialize iocb list.\n");
9044 goto out_unset_driver_resource_s4
;
9047 INIT_LIST_HEAD(&phba
->active_rrq_list
);
9048 INIT_LIST_HEAD(&phba
->fcf
.fcf_pri_list
);
9050 /* Set up common device driver resources */
9051 error
= lpfc_setup_driver_resource_phase2(phba
);
9053 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9054 "1414 Failed to set up driver resource.\n");
9055 goto out_free_iocb_list
;
9058 /* Create SCSI host to the physical port */
9059 error
= lpfc_create_shost(phba
);
9061 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9062 "1415 Failed to create scsi host.\n");
9063 goto out_unset_driver_resource
;
9066 /* Configure sysfs attributes */
9067 vport
= phba
->pport
;
9068 error
= lpfc_alloc_sysfs_attr(vport
);
9070 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9071 "1416 Failed to allocate sysfs attr\n");
9072 goto out_destroy_shost
;
9075 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
9076 /* Now, trying to enable interrupt and bring up the device */
9077 cfg_mode
= phba
->cfg_use_msi
;
9079 /* Put device to a known state before enabling interrupt */
9080 lpfc_stop_port(phba
);
9081 /* Configure and enable interrupt */
9082 intr_mode
= lpfc_sli4_enable_intr(phba
, cfg_mode
);
9083 if (intr_mode
== LPFC_INTR_ERROR
) {
9084 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9085 "0426 Failed to enable interrupt.\n");
9087 goto out_free_sysfs_attr
;
9089 /* Default to single EQ for non-MSI-X */
9090 if (phba
->intr_type
!= MSIX
)
9091 adjusted_fcp_eq_count
= 0;
9092 else if (phba
->sli4_hba
.msix_vec_nr
<
9093 phba
->cfg_fcp_eq_count
+ 1)
9094 adjusted_fcp_eq_count
= phba
->sli4_hba
.msix_vec_nr
- 1;
9096 adjusted_fcp_eq_count
= phba
->cfg_fcp_eq_count
;
9097 /* Free unused EQs */
9098 for (fcp_qidx
= adjusted_fcp_eq_count
;
9099 fcp_qidx
< phba
->cfg_fcp_eq_count
;
9101 lpfc_sli4_queue_free(phba
->sli4_hba
.fp_eq
[fcp_qidx
]);
9102 /* do not delete the first fcp_cq */
9104 lpfc_sli4_queue_free(
9105 phba
->sli4_hba
.fcp_cq
[fcp_qidx
]);
9107 phba
->cfg_fcp_eq_count
= adjusted_fcp_eq_count
;
9108 /* Set up SLI-4 HBA */
9109 if (lpfc_sli4_hba_setup(phba
)) {
9110 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9111 "1421 Failed to set up hba\n");
9113 goto out_disable_intr
;
9116 /* Send NOP mbx cmds for non-INTx mode active interrupt test */
9118 mcnt
= lpfc_sli4_send_nop_mbox_cmds(phba
,
9121 /* Check active interrupts received only for MSI/MSI-X */
9122 if (intr_mode
== 0 ||
9123 phba
->sli
.slistat
.sli_intr
>= LPFC_ACT_INTR_CNT
) {
9124 /* Log the current active interrupt mode */
9125 phba
->intr_mode
= intr_mode
;
9126 lpfc_log_intr_mode(phba
, intr_mode
);
9129 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9130 "0451 Configure interrupt mode (%d) "
9131 "failed active interrupt test.\n",
9133 /* Unset the previous SLI-4 HBA setup. */
9135 * TODO: Is this operation compatible with IF TYPE 2
9136 * devices? All port state is deleted and cleared.
9138 lpfc_sli4_unset_hba(phba
);
9139 /* Try next level of interrupt mode */
9140 cfg_mode
= --intr_mode
;
9143 /* Perform post initialization setup */
9144 lpfc_post_init_setup(phba
);
9146 /* check for firmware upgrade or downgrade */
9147 snprintf(file_name
, 16, "%s.grp", phba
->ModelName
);
9148 error
= request_firmware(&fw
, file_name
, &phba
->pcidev
->dev
);
9150 lpfc_write_firmware(phba
, fw
);
9151 release_firmware(fw
);
9154 /* Check if there are static vports to be created. */
9155 lpfc_create_static_vport(phba
);
9159 lpfc_sli4_disable_intr(phba
);
9160 out_free_sysfs_attr
:
9161 lpfc_free_sysfs_attr(vport
);
9163 lpfc_destroy_shost(phba
);
9164 out_unset_driver_resource
:
9165 lpfc_unset_driver_resource_phase2(phba
);
9167 lpfc_free_iocb_list(phba
);
9168 out_unset_driver_resource_s4
:
9169 lpfc_sli4_driver_resource_unset(phba
);
9170 out_unset_pci_mem_s4
:
9171 lpfc_sli4_pci_mem_unset(phba
);
9172 out_disable_pci_dev
:
9173 lpfc_disable_pci_dev(phba
);
9175 scsi_host_put(shost
);
9177 lpfc_hba_free(phba
);
9182 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
9183 * @pdev: pointer to PCI device
9185 * This routine is called from the kernel's PCI subsystem to device with
9186 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
9187 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9188 * device to be removed from the PCI subsystem properly.
9190 static void __devexit
9191 lpfc_pci_remove_one_s4(struct pci_dev
*pdev
)
9193 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9194 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
9195 struct lpfc_vport
**vports
;
9196 struct lpfc_hba
*phba
= vport
->phba
;
9199 /* Mark the device unloading flag */
9200 spin_lock_irq(&phba
->hbalock
);
9201 vport
->load_flag
|= FC_UNLOADING
;
9202 spin_unlock_irq(&phba
->hbalock
);
9204 /* Free the HBA sysfs attributes */
9205 lpfc_free_sysfs_attr(vport
);
9207 /* Release all the vports against this physical port */
9208 vports
= lpfc_create_vport_work_array(phba
);
9210 for (i
= 1; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
9211 fc_vport_terminate(vports
[i
]->fc_vport
);
9212 lpfc_destroy_vport_work_array(phba
, vports
);
9214 /* Remove FC host and then SCSI host with the physical port */
9215 fc_remove_host(shost
);
9216 scsi_remove_host(shost
);
9218 /* Perform cleanup on the physical port */
9219 lpfc_cleanup(vport
);
9222 * Bring down the SLI Layer. This step disables all interrupts,
9223 * clears the rings, discards all mailbox commands, and resets
9224 * the HBA FCoE function.
9226 lpfc_debugfs_terminate(vport
);
9227 lpfc_sli4_hba_unset(phba
);
9229 spin_lock_irq(&phba
->hbalock
);
9230 list_del_init(&vport
->listentry
);
9231 spin_unlock_irq(&phba
->hbalock
);
9233 /* Perform scsi free before driver resource_unset since scsi
9234 * buffers are released to their corresponding pools here.
9236 lpfc_scsi_free(phba
);
9237 lpfc_sli4_driver_resource_unset(phba
);
9239 /* Unmap adapter Control and Doorbell registers */
9240 lpfc_sli4_pci_mem_unset(phba
);
9242 /* Release PCI resources and disable device's PCI function */
9243 scsi_host_put(shost
);
9244 lpfc_disable_pci_dev(phba
);
9246 /* Finally, free the driver's device data structure */
9247 lpfc_hba_free(phba
);
9253 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
9254 * @pdev: pointer to PCI device
9255 * @msg: power management message
9257 * This routine is called from the kernel's PCI subsystem to support system
9258 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
9259 * this method, it quiesces the device by stopping the driver's worker
9260 * thread for the device, turning off device's interrupt and DMA, and bring
9261 * the device offline. Note that as the driver implements the minimum PM
9262 * requirements to a power-aware driver's PM support for suspend/resume -- all
9263 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
9264 * method call will be treated as SUSPEND and the driver will fully
9265 * reinitialize its device during resume() method call, the driver will set
9266 * device to PCI_D3hot state in PCI config space instead of setting it
9267 * according to the @msg provided by the PM.
9270 * 0 - driver suspended the device
9274 lpfc_pci_suspend_one_s4(struct pci_dev
*pdev
, pm_message_t msg
)
9276 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9277 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9279 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9280 "2843 PCI device Power Management suspend.\n");
9282 /* Bring down the device */
9283 lpfc_offline_prep(phba
);
9285 kthread_stop(phba
->worker_thread
);
9287 /* Disable interrupt from device */
9288 lpfc_sli4_disable_intr(phba
);
9290 /* Save device state to PCI config space */
9291 pci_save_state(pdev
);
9292 pci_set_power_state(pdev
, PCI_D3hot
);
9298 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
9299 * @pdev: pointer to PCI device
9301 * This routine is called from the kernel's PCI subsystem to support system
9302 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
9303 * this method, it restores the device's PCI config space state and fully
9304 * reinitializes the device and brings it online. Note that as the driver
9305 * implements the minimum PM requirements to a power-aware driver's PM for
9306 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9307 * to the suspend() method call will be treated as SUSPEND and the driver
9308 * will fully reinitialize its device during resume() method call, the device
9309 * will be set to PCI_D0 directly in PCI config space before restoring the
9313 * 0 - driver suspended the device
9317 lpfc_pci_resume_one_s4(struct pci_dev
*pdev
)
9319 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9320 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9324 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9325 "0292 PCI device Power Management resume.\n");
9327 /* Restore device state from PCI config space */
9328 pci_set_power_state(pdev
, PCI_D0
);
9329 pci_restore_state(pdev
);
9332 * As the new kernel behavior of pci_restore_state() API call clears
9333 * device saved_state flag, need to save the restored state again.
9335 pci_save_state(pdev
);
9337 if (pdev
->is_busmaster
)
9338 pci_set_master(pdev
);
9340 /* Startup the kernel thread for this host adapter. */
9341 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
9342 "lpfc_worker_%d", phba
->brd_no
);
9343 if (IS_ERR(phba
->worker_thread
)) {
9344 error
= PTR_ERR(phba
->worker_thread
);
9345 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9346 "0293 PM resume failed to start worker "
9347 "thread: error=x%x.\n", error
);
9351 /* Configure and enable interrupt */
9352 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
9353 if (intr_mode
== LPFC_INTR_ERROR
) {
9354 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9355 "0294 PM resume Failed to enable interrupt\n");
9358 phba
->intr_mode
= intr_mode
;
9360 /* Restart HBA and bring it online */
9361 lpfc_sli_brdrestart(phba
);
9364 /* Log the current active interrupt mode */
9365 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
9371 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
9372 * @phba: pointer to lpfc hba data structure.
9374 * This routine is called to prepare the SLI4 device for PCI slot recover. It
9375 * aborts all the outstanding SCSI I/Os to the pci device.
9378 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba
*phba
)
9380 struct lpfc_sli
*psli
= &phba
->sli
;
9381 struct lpfc_sli_ring
*pring
;
9383 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9384 "2828 PCI channel I/O abort preparing for recovery\n");
9386 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9387 * and let the SCSI mid-layer to retry them to recover.
9389 pring
= &psli
->ring
[psli
->fcp_ring
];
9390 lpfc_sli_abort_iocb_ring(phba
, pring
);
9394 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
9395 * @phba: pointer to lpfc hba data structure.
9397 * This routine is called to prepare the SLI4 device for PCI slot reset. It
9398 * disables the device interrupt and pci device, and aborts the internal FCP
9402 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba
*phba
)
9404 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9405 "2826 PCI channel disable preparing for reset\n");
9407 /* Block any management I/Os to the device */
9408 lpfc_block_mgmt_io(phba
);
9410 /* Block all SCSI devices' I/Os on the host */
9411 lpfc_scsi_dev_block(phba
);
9413 /* stop all timers */
9414 lpfc_stop_hba_timers(phba
);
9416 /* Disable interrupt and pci device */
9417 lpfc_sli4_disable_intr(phba
);
9418 pci_disable_device(phba
->pcidev
);
9420 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9421 lpfc_sli_flush_fcp_rings(phba
);
9425 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
9426 * @phba: pointer to lpfc hba data structure.
9428 * This routine is called to prepare the SLI4 device for PCI slot permanently
9429 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9433 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
9435 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9436 "2827 PCI channel permanent disable for failure\n");
9438 /* Block all SCSI devices' I/Os on the host */
9439 lpfc_scsi_dev_block(phba
);
9441 /* stop all timers */
9442 lpfc_stop_hba_timers(phba
);
9444 /* Clean up all driver's outstanding SCSI I/Os */
9445 lpfc_sli_flush_fcp_rings(phba
);
9449 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
9450 * @pdev: pointer to PCI device.
9451 * @state: the current PCI connection state.
9453 * This routine is called from the PCI subsystem for error handling to device
9454 * with SLI-4 interface spec. This function is called by the PCI subsystem
9455 * after a PCI bus error affecting this device has been detected. When this
9456 * function is invoked, it will need to stop all the I/Os and interrupt(s)
9457 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
9458 * for the PCI subsystem to perform proper recovery as desired.
9461 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9462 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9464 static pci_ers_result_t
9465 lpfc_io_error_detected_s4(struct pci_dev
*pdev
, pci_channel_state_t state
)
9467 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9468 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9471 case pci_channel_io_normal
:
9472 /* Non-fatal error, prepare for recovery */
9473 lpfc_sli4_prep_dev_for_recover(phba
);
9474 return PCI_ERS_RESULT_CAN_RECOVER
;
9475 case pci_channel_io_frozen
:
9476 /* Fatal error, prepare for slot reset */
9477 lpfc_sli4_prep_dev_for_reset(phba
);
9478 return PCI_ERS_RESULT_NEED_RESET
;
9479 case pci_channel_io_perm_failure
:
9480 /* Permanent failure, prepare for device down */
9481 lpfc_sli4_prep_dev_for_perm_failure(phba
);
9482 return PCI_ERS_RESULT_DISCONNECT
;
9484 /* Unknown state, prepare and request slot reset */
9485 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9486 "2825 Unknown PCI error state: x%x\n", state
);
9487 lpfc_sli4_prep_dev_for_reset(phba
);
9488 return PCI_ERS_RESULT_NEED_RESET
;
9493 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
9494 * @pdev: pointer to PCI device.
9496 * This routine is called from the PCI subsystem for error handling to device
9497 * with SLI-4 interface spec. It is called after PCI bus has been reset to
9498 * restart the PCI card from scratch, as if from a cold-boot. During the
9499 * PCI subsystem error recovery, after the driver returns
9500 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
9501 * recovery and then call this routine before calling the .resume method to
9502 * recover the device. This function will initialize the HBA device, enable
9503 * the interrupt, but it will just put the HBA to offline state without
9504 * passing any I/O traffic.
9507 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9508 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9510 static pci_ers_result_t
9511 lpfc_io_slot_reset_s4(struct pci_dev
*pdev
)
9513 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9514 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9515 struct lpfc_sli
*psli
= &phba
->sli
;
9518 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
9519 if (pci_enable_device_mem(pdev
)) {
9520 printk(KERN_ERR
"lpfc: Cannot re-enable "
9521 "PCI device after reset.\n");
9522 return PCI_ERS_RESULT_DISCONNECT
;
9525 pci_restore_state(pdev
);
9528 * As the new kernel behavior of pci_restore_state() API call clears
9529 * device saved_state flag, need to save the restored state again.
9531 pci_save_state(pdev
);
9533 if (pdev
->is_busmaster
)
9534 pci_set_master(pdev
);
9536 spin_lock_irq(&phba
->hbalock
);
9537 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
9538 spin_unlock_irq(&phba
->hbalock
);
9540 /* Configure and enable interrupt */
9541 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
9542 if (intr_mode
== LPFC_INTR_ERROR
) {
9543 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9544 "2824 Cannot re-enable interrupt after "
9546 return PCI_ERS_RESULT_DISCONNECT
;
9548 phba
->intr_mode
= intr_mode
;
9550 /* Log the current active interrupt mode */
9551 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
9553 return PCI_ERS_RESULT_RECOVERED
;
9557 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
9558 * @pdev: pointer to PCI device
9560 * This routine is called from the PCI subsystem for error handling to device
9561 * with SLI-4 interface spec. It is called when kernel error recovery tells
9562 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
9563 * error recovery. After this call, traffic can start to flow from this device
9567 lpfc_io_resume_s4(struct pci_dev
*pdev
)
9569 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9570 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9573 * In case of slot reset, as function reset is performed through
9574 * mailbox command which needs DMA to be enabled, this operation
9575 * has to be moved to the io resume phase. Taking device offline
9576 * will perform the necessary cleanup.
9578 if (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)) {
9579 /* Perform device reset */
9580 lpfc_offline_prep(phba
);
9582 lpfc_sli_brdrestart(phba
);
9583 /* Bring the device back online */
9587 /* Clean up Advanced Error Reporting (AER) if needed */
9588 if (phba
->hba_flag
& HBA_AER_ENABLED
)
9589 pci_cleanup_aer_uncorrect_error_status(pdev
);
9593 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
9594 * @pdev: pointer to PCI device
9595 * @pid: pointer to PCI device identifier
9597 * This routine is to be registered to the kernel's PCI subsystem. When an
9598 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
9599 * at PCI device-specific information of the device and driver to see if the
9600 * driver state that it can support this kind of device. If the match is
9601 * successful, the driver core invokes this routine. This routine dispatches
9602 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
9603 * do all the initialization that it needs to do to handle the HBA device
9607 * 0 - driver can claim the device
9608 * negative value - driver can not claim the device
9610 static int __devinit
9611 lpfc_pci_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
9614 struct lpfc_sli_intf intf
;
9616 if (pci_read_config_dword(pdev
, LPFC_SLI_INTF
, &intf
.word0
))
9619 if ((bf_get(lpfc_sli_intf_valid
, &intf
) == LPFC_SLI_INTF_VALID
) &&
9620 (bf_get(lpfc_sli_intf_slirev
, &intf
) == LPFC_SLI_INTF_REV_SLI4
))
9621 rc
= lpfc_pci_probe_one_s4(pdev
, pid
);
9623 rc
= lpfc_pci_probe_one_s3(pdev
, pid
);
9629 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
9630 * @pdev: pointer to PCI device
9632 * This routine is to be registered to the kernel's PCI subsystem. When an
9633 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
9634 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
9635 * remove routine, which will perform all the necessary cleanup for the
9636 * device to be removed from the PCI subsystem properly.
9638 static void __devexit
9639 lpfc_pci_remove_one(struct pci_dev
*pdev
)
9641 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9642 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9644 switch (phba
->pci_dev_grp
) {
9645 case LPFC_PCI_DEV_LP
:
9646 lpfc_pci_remove_one_s3(pdev
);
9648 case LPFC_PCI_DEV_OC
:
9649 lpfc_pci_remove_one_s4(pdev
);
9652 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9653 "1424 Invalid PCI device group: 0x%x\n",
9661 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
9662 * @pdev: pointer to PCI device
9663 * @msg: power management message
9665 * This routine is to be registered to the kernel's PCI subsystem to support
9666 * system Power Management (PM). When PM invokes this method, it dispatches
9667 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
9668 * suspend the device.
9671 * 0 - driver suspended the device
9675 lpfc_pci_suspend_one(struct pci_dev
*pdev
, pm_message_t msg
)
9677 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9678 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9681 switch (phba
->pci_dev_grp
) {
9682 case LPFC_PCI_DEV_LP
:
9683 rc
= lpfc_pci_suspend_one_s3(pdev
, msg
);
9685 case LPFC_PCI_DEV_OC
:
9686 rc
= lpfc_pci_suspend_one_s4(pdev
, msg
);
9689 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9690 "1425 Invalid PCI device group: 0x%x\n",
9698 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
9699 * @pdev: pointer to PCI device
9701 * This routine is to be registered to the kernel's PCI subsystem to support
9702 * system Power Management (PM). When PM invokes this method, it dispatches
9703 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
9704 * resume the device.
9707 * 0 - driver suspended the device
9711 lpfc_pci_resume_one(struct pci_dev
*pdev
)
9713 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9714 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9717 switch (phba
->pci_dev_grp
) {
9718 case LPFC_PCI_DEV_LP
:
9719 rc
= lpfc_pci_resume_one_s3(pdev
);
9721 case LPFC_PCI_DEV_OC
:
9722 rc
= lpfc_pci_resume_one_s4(pdev
);
9725 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9726 "1426 Invalid PCI device group: 0x%x\n",
9734 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
9735 * @pdev: pointer to PCI device.
9736 * @state: the current PCI connection state.
9738 * This routine is registered to the PCI subsystem for error handling. This
9739 * function is called by the PCI subsystem after a PCI bus error affecting
9740 * this device has been detected. When this routine is invoked, it dispatches
9741 * the action to the proper SLI-3 or SLI-4 device error detected handling
9742 * routine, which will perform the proper error detected operation.
9745 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9746 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9748 static pci_ers_result_t
9749 lpfc_io_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
9751 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9752 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9753 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
9755 switch (phba
->pci_dev_grp
) {
9756 case LPFC_PCI_DEV_LP
:
9757 rc
= lpfc_io_error_detected_s3(pdev
, state
);
9759 case LPFC_PCI_DEV_OC
:
9760 rc
= lpfc_io_error_detected_s4(pdev
, state
);
9763 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9764 "1427 Invalid PCI device group: 0x%x\n",
9772 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
9773 * @pdev: pointer to PCI device.
9775 * This routine is registered to the PCI subsystem for error handling. This
9776 * function is called after PCI bus has been reset to restart the PCI card
9777 * from scratch, as if from a cold-boot. When this routine is invoked, it
9778 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
9779 * routine, which will perform the proper device reset.
9782 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9783 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9785 static pci_ers_result_t
9786 lpfc_io_slot_reset(struct pci_dev
*pdev
)
9788 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9789 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9790 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
9792 switch (phba
->pci_dev_grp
) {
9793 case LPFC_PCI_DEV_LP
:
9794 rc
= lpfc_io_slot_reset_s3(pdev
);
9796 case LPFC_PCI_DEV_OC
:
9797 rc
= lpfc_io_slot_reset_s4(pdev
);
9800 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9801 "1428 Invalid PCI device group: 0x%x\n",
9809 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
9810 * @pdev: pointer to PCI device
9812 * This routine is registered to the PCI subsystem for error handling. It
9813 * is called when kernel error recovery tells the lpfc driver that it is
9814 * OK to resume normal PCI operation after PCI bus error recovery. When
9815 * this routine is invoked, it dispatches the action to the proper SLI-3
9816 * or SLI-4 device io_resume routine, which will resume the device operation.
9819 lpfc_io_resume(struct pci_dev
*pdev
)
9821 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9822 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9824 switch (phba
->pci_dev_grp
) {
9825 case LPFC_PCI_DEV_LP
:
9826 lpfc_io_resume_s3(pdev
);
9828 case LPFC_PCI_DEV_OC
:
9829 lpfc_io_resume_s4(pdev
);
9832 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9833 "1429 Invalid PCI device group: 0x%x\n",
9840 static struct pci_device_id lpfc_id_table
[] = {
9841 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_VIPER
,
9842 PCI_ANY_ID
, PCI_ANY_ID
, },
9843 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_FIREFLY
,
9844 PCI_ANY_ID
, PCI_ANY_ID
, },
9845 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_THOR
,
9846 PCI_ANY_ID
, PCI_ANY_ID
, },
9847 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PEGASUS
,
9848 PCI_ANY_ID
, PCI_ANY_ID
, },
9849 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_CENTAUR
,
9850 PCI_ANY_ID
, PCI_ANY_ID
, },
9851 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_DRAGONFLY
,
9852 PCI_ANY_ID
, PCI_ANY_ID
, },
9853 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SUPERFLY
,
9854 PCI_ANY_ID
, PCI_ANY_ID
, },
9855 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_RFLY
,
9856 PCI_ANY_ID
, PCI_ANY_ID
, },
9857 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PFLY
,
9858 PCI_ANY_ID
, PCI_ANY_ID
, },
9859 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE
,
9860 PCI_ANY_ID
, PCI_ANY_ID
, },
9861 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_SCSP
,
9862 PCI_ANY_ID
, PCI_ANY_ID
, },
9863 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_DCSP
,
9864 PCI_ANY_ID
, PCI_ANY_ID
, },
9865 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS
,
9866 PCI_ANY_ID
, PCI_ANY_ID
, },
9867 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_SCSP
,
9868 PCI_ANY_ID
, PCI_ANY_ID
, },
9869 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_DCSP
,
9870 PCI_ANY_ID
, PCI_ANY_ID
, },
9871 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BMID
,
9872 PCI_ANY_ID
, PCI_ANY_ID
, },
9873 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BSMB
,
9874 PCI_ANY_ID
, PCI_ANY_ID
, },
9875 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR
,
9876 PCI_ANY_ID
, PCI_ANY_ID
, },
9877 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HORNET
,
9878 PCI_ANY_ID
, PCI_ANY_ID
, },
9879 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_SCSP
,
9880 PCI_ANY_ID
, PCI_ANY_ID
, },
9881 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_DCSP
,
9882 PCI_ANY_ID
, PCI_ANY_ID
, },
9883 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZMID
,
9884 PCI_ANY_ID
, PCI_ANY_ID
, },
9885 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZSMB
,
9886 PCI_ANY_ID
, PCI_ANY_ID
, },
9887 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_TFLY
,
9888 PCI_ANY_ID
, PCI_ANY_ID
, },
9889 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP101
,
9890 PCI_ANY_ID
, PCI_ANY_ID
, },
9891 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP10000S
,
9892 PCI_ANY_ID
, PCI_ANY_ID
, },
9893 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP11000S
,
9894 PCI_ANY_ID
, PCI_ANY_ID
, },
9895 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LPE11000S
,
9896 PCI_ANY_ID
, PCI_ANY_ID
, },
9897 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT
,
9898 PCI_ANY_ID
, PCI_ANY_ID
, },
9899 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_MID
,
9900 PCI_ANY_ID
, PCI_ANY_ID
, },
9901 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SMB
,
9902 PCI_ANY_ID
, PCI_ANY_ID
, },
9903 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_DCSP
,
9904 PCI_ANY_ID
, PCI_ANY_ID
, },
9905 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SCSP
,
9906 PCI_ANY_ID
, PCI_ANY_ID
, },
9907 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_S
,
9908 PCI_ANY_ID
, PCI_ANY_ID
, },
9909 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_VF
,
9910 PCI_ANY_ID
, PCI_ANY_ID
, },
9911 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_PF
,
9912 PCI_ANY_ID
, PCI_ANY_ID
, },
9913 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_S
,
9914 PCI_ANY_ID
, PCI_ANY_ID
, },
9915 {PCI_VENDOR_ID_SERVERENGINE
, PCI_DEVICE_ID_TIGERSHARK
,
9916 PCI_ANY_ID
, PCI_ANY_ID
, },
9917 {PCI_VENDOR_ID_SERVERENGINE
, PCI_DEVICE_ID_TOMCAT
,
9918 PCI_ANY_ID
, PCI_ANY_ID
, },
9919 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_FALCON
,
9920 PCI_ANY_ID
, PCI_ANY_ID
, },
9921 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BALIUS
,
9922 PCI_ANY_ID
, PCI_ANY_ID
, },
9923 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FC
,
9924 PCI_ANY_ID
, PCI_ANY_ID
, },
9925 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FCOE
,
9926 PCI_ANY_ID
, PCI_ANY_ID
, },
9927 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FC_VF
,
9928 PCI_ANY_ID
, PCI_ANY_ID
, },
9929 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FCOE_VF
,
9930 PCI_ANY_ID
, PCI_ANY_ID
, },
9934 MODULE_DEVICE_TABLE(pci
, lpfc_id_table
);
9936 static struct pci_error_handlers lpfc_err_handler
= {
9937 .error_detected
= lpfc_io_error_detected
,
9938 .slot_reset
= lpfc_io_slot_reset
,
9939 .resume
= lpfc_io_resume
,
9942 static struct pci_driver lpfc_driver
= {
9943 .name
= LPFC_DRIVER_NAME
,
9944 .id_table
= lpfc_id_table
,
9945 .probe
= lpfc_pci_probe_one
,
9946 .remove
= __devexit_p(lpfc_pci_remove_one
),
9947 .suspend
= lpfc_pci_suspend_one
,
9948 .resume
= lpfc_pci_resume_one
,
9949 .err_handler
= &lpfc_err_handler
,
9953 * lpfc_init - lpfc module initialization routine
9955 * This routine is to be invoked when the lpfc module is loaded into the
9956 * kernel. The special kernel macro module_init() is used to indicate the
9957 * role of this routine to the kernel as lpfc module entry point.
9961 * -ENOMEM - FC attach transport failed
9962 * all others - failed
9969 printk(LPFC_MODULE_DESC
"\n");
9970 printk(LPFC_COPYRIGHT
"\n");
9972 if (lpfc_enable_npiv
) {
9973 lpfc_transport_functions
.vport_create
= lpfc_vport_create
;
9974 lpfc_transport_functions
.vport_delete
= lpfc_vport_delete
;
9976 lpfc_transport_template
=
9977 fc_attach_transport(&lpfc_transport_functions
);
9978 if (lpfc_transport_template
== NULL
)
9980 if (lpfc_enable_npiv
) {
9981 lpfc_vport_transport_template
=
9982 fc_attach_transport(&lpfc_vport_transport_functions
);
9983 if (lpfc_vport_transport_template
== NULL
) {
9984 fc_release_transport(lpfc_transport_template
);
9988 error
= pci_register_driver(&lpfc_driver
);
9990 fc_release_transport(lpfc_transport_template
);
9991 if (lpfc_enable_npiv
)
9992 fc_release_transport(lpfc_vport_transport_template
);
9999 * lpfc_exit - lpfc module removal routine
10001 * This routine is invoked when the lpfc module is removed from the kernel.
10002 * The special kernel macro module_exit() is used to indicate the role of
10003 * this routine to the kernel as lpfc module exit point.
10008 pci_unregister_driver(&lpfc_driver
);
10009 fc_release_transport(lpfc_transport_template
);
10010 if (lpfc_enable_npiv
)
10011 fc_release_transport(lpfc_vport_transport_template
);
10012 if (_dump_buf_data
) {
10013 printk(KERN_ERR
"9062 BLKGRD: freeing %lu pages for "
10014 "_dump_buf_data at 0x%p\n",
10015 (1L << _dump_buf_data_order
), _dump_buf_data
);
10016 free_pages((unsigned long)_dump_buf_data
, _dump_buf_data_order
);
10019 if (_dump_buf_dif
) {
10020 printk(KERN_ERR
"9049 BLKGRD: freeing %lu pages for "
10021 "_dump_buf_dif at 0x%p\n",
10022 (1L << _dump_buf_dif_order
), _dump_buf_dif
);
10023 free_pages((unsigned long)_dump_buf_dif
, _dump_buf_dif_order
);
10027 module_init(lpfc_init
);
10028 module_exit(lpfc_exit
);
10029 MODULE_LICENSE("GPL");
10030 MODULE_DESCRIPTION(LPFC_MODULE_DESC
);
10031 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
10032 MODULE_VERSION("0:" LPFC_DRIVER_VERSION
);