1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 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/kthread.h>
28 #include <linux/pci.h>
29 #include <linux/spinlock.h>
30 #include <linux/ctype.h>
31 #include <linux/aer.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_device.h>
35 #include <scsi/scsi_host.h>
36 #include <scsi/scsi_transport_fc.h>
41 #include "lpfc_sli4.h"
43 #include "lpfc_disc.h"
44 #include "lpfc_scsi.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_crtn.h"
48 #include "lpfc_vport.h"
49 #include "lpfc_version.h"
52 unsigned long _dump_buf_data_order
;
54 unsigned long _dump_buf_dif_order
;
55 spinlock_t _dump_buf_lock
;
57 static void lpfc_get_hba_model_desc(struct lpfc_hba
*, uint8_t *, uint8_t *);
58 static int lpfc_post_rcv_buf(struct lpfc_hba
*);
59 static int lpfc_sli4_queue_create(struct lpfc_hba
*);
60 static void lpfc_sli4_queue_destroy(struct lpfc_hba
*);
61 static int lpfc_create_bootstrap_mbox(struct lpfc_hba
*);
62 static int lpfc_setup_endian_order(struct lpfc_hba
*);
63 static int lpfc_sli4_read_config(struct lpfc_hba
*);
64 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*);
65 static void lpfc_free_sgl_list(struct lpfc_hba
*);
66 static int lpfc_init_sgl_list(struct lpfc_hba
*);
67 static int lpfc_init_active_sgl_array(struct lpfc_hba
*);
68 static void lpfc_free_active_sgl(struct lpfc_hba
*);
69 static int lpfc_hba_down_post_s3(struct lpfc_hba
*phba
);
70 static int lpfc_hba_down_post_s4(struct lpfc_hba
*phba
);
71 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*);
72 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*);
73 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba
*);
75 static struct scsi_transport_template
*lpfc_transport_template
= NULL
;
76 static struct scsi_transport_template
*lpfc_vport_transport_template
= NULL
;
77 static DEFINE_IDR(lpfc_hba_index
);
80 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
81 * @phba: pointer to lpfc hba data structure.
83 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
84 * mailbox command. It retrieves the revision information from the HBA and
85 * collects the Vital Product Data (VPD) about the HBA for preparing the
86 * configuration of the HBA.
90 * -ERESTART - requests the SLI layer to reset the HBA and try again.
91 * Any other value - indicates an error.
94 lpfc_config_port_prep(struct lpfc_hba
*phba
)
96 lpfc_vpd_t
*vp
= &phba
->vpd
;
100 char *lpfc_vpd_data
= NULL
;
102 static char licensed
[56] =
103 "key unlock for use with gnu public licensed code only\0";
104 static int init_key
= 1;
106 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
108 phba
->link_state
= LPFC_HBA_ERROR
;
113 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
115 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
117 uint32_t *ptext
= (uint32_t *) licensed
;
119 for (i
= 0; i
< 56; i
+= sizeof (uint32_t), ptext
++)
120 *ptext
= cpu_to_be32(*ptext
);
124 lpfc_read_nv(phba
, pmb
);
125 memset((char*)mb
->un
.varRDnvp
.rsvd3
, 0,
126 sizeof (mb
->un
.varRDnvp
.rsvd3
));
127 memcpy((char*)mb
->un
.varRDnvp
.rsvd3
, licensed
,
130 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
132 if (rc
!= MBX_SUCCESS
) {
133 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
134 "0324 Config Port initialization "
135 "error, mbxCmd x%x READ_NVPARM, "
137 mb
->mbxCommand
, mb
->mbxStatus
);
138 mempool_free(pmb
, phba
->mbox_mem_pool
);
141 memcpy(phba
->wwnn
, (char *)mb
->un
.varRDnvp
.nodename
,
143 memcpy(phba
->wwpn
, (char *)mb
->un
.varRDnvp
.portname
,
147 phba
->sli3_options
= 0x0;
149 /* Setup and issue mailbox READ REV command */
150 lpfc_read_rev(phba
, pmb
);
151 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
152 if (rc
!= MBX_SUCCESS
) {
153 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
154 "0439 Adapter failed to init, mbxCmd x%x "
155 "READ_REV, mbxStatus x%x\n",
156 mb
->mbxCommand
, mb
->mbxStatus
);
157 mempool_free( pmb
, phba
->mbox_mem_pool
);
163 * The value of rr must be 1 since the driver set the cv field to 1.
164 * This setting requires the FW to set all revision fields.
166 if (mb
->un
.varRdRev
.rr
== 0) {
168 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
169 "0440 Adapter failed to init, READ_REV has "
170 "missing revision information.\n");
171 mempool_free(pmb
, phba
->mbox_mem_pool
);
175 if (phba
->sli_rev
== 3 && !mb
->un
.varRdRev
.v3rsp
) {
176 mempool_free(pmb
, phba
->mbox_mem_pool
);
180 /* Save information as VPD data */
182 memcpy(&vp
->sli3Feat
, &mb
->un
.varRdRev
.sli3Feat
, sizeof(uint32_t));
183 vp
->rev
.sli1FwRev
= mb
->un
.varRdRev
.sli1FwRev
;
184 memcpy(vp
->rev
.sli1FwName
, (char*) mb
->un
.varRdRev
.sli1FwName
, 16);
185 vp
->rev
.sli2FwRev
= mb
->un
.varRdRev
.sli2FwRev
;
186 memcpy(vp
->rev
.sli2FwName
, (char *) mb
->un
.varRdRev
.sli2FwName
, 16);
187 vp
->rev
.biuRev
= mb
->un
.varRdRev
.biuRev
;
188 vp
->rev
.smRev
= mb
->un
.varRdRev
.smRev
;
189 vp
->rev
.smFwRev
= mb
->un
.varRdRev
.un
.smFwRev
;
190 vp
->rev
.endecRev
= mb
->un
.varRdRev
.endecRev
;
191 vp
->rev
.fcphHigh
= mb
->un
.varRdRev
.fcphHigh
;
192 vp
->rev
.fcphLow
= mb
->un
.varRdRev
.fcphLow
;
193 vp
->rev
.feaLevelHigh
= mb
->un
.varRdRev
.feaLevelHigh
;
194 vp
->rev
.feaLevelLow
= mb
->un
.varRdRev
.feaLevelLow
;
195 vp
->rev
.postKernRev
= mb
->un
.varRdRev
.postKernRev
;
196 vp
->rev
.opFwRev
= mb
->un
.varRdRev
.opFwRev
;
198 /* If the sli feature level is less then 9, we must
199 * tear down all RPIs and VPIs on link down if NPIV
202 if (vp
->rev
.feaLevelHigh
< 9)
203 phba
->sli3_options
|= LPFC_SLI3_VPORT_TEARDOWN
;
205 if (lpfc_is_LC_HBA(phba
->pcidev
->device
))
206 memcpy(phba
->RandomData
, (char *)&mb
->un
.varWords
[24],
207 sizeof (phba
->RandomData
));
209 /* Get adapter VPD information */
210 lpfc_vpd_data
= kmalloc(DMP_VPD_SIZE
, GFP_KERNEL
);
215 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_VPD
);
216 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
218 if (rc
!= MBX_SUCCESS
) {
219 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
220 "0441 VPD not present on adapter, "
221 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
222 mb
->mbxCommand
, mb
->mbxStatus
);
223 mb
->un
.varDmp
.word_cnt
= 0;
225 /* dump mem may return a zero when finished or we got a
226 * mailbox error, either way we are done.
228 if (mb
->un
.varDmp
.word_cnt
== 0)
230 if (mb
->un
.varDmp
.word_cnt
> DMP_VPD_SIZE
- offset
)
231 mb
->un
.varDmp
.word_cnt
= DMP_VPD_SIZE
- offset
;
232 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
233 lpfc_vpd_data
+ offset
,
234 mb
->un
.varDmp
.word_cnt
);
235 offset
+= mb
->un
.varDmp
.word_cnt
;
236 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_VPD_SIZE
);
237 lpfc_parse_vpd(phba
, lpfc_vpd_data
, offset
);
239 kfree(lpfc_vpd_data
);
241 mempool_free(pmb
, phba
->mbox_mem_pool
);
246 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
247 * @phba: pointer to lpfc hba data structure.
248 * @pmboxq: pointer to the driver internal queue element for mailbox command.
250 * This is the completion handler for driver's configuring asynchronous event
251 * mailbox command to the device. If the mailbox command returns successfully,
252 * it will set internal async event support flag to 1; otherwise, it will
253 * set internal async event support flag to 0.
256 lpfc_config_async_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
258 if (pmboxq
->u
.mb
.mbxStatus
== MBX_SUCCESS
)
259 phba
->temp_sensor_support
= 1;
261 phba
->temp_sensor_support
= 0;
262 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
267 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
268 * @phba: pointer to lpfc hba data structure.
269 * @pmboxq: pointer to the driver internal queue element for mailbox command.
271 * This is the completion handler for dump mailbox command for getting
272 * wake up parameters. When this command complete, the response contain
273 * Option rom version of the HBA. This function translate the version number
274 * into a human readable string and store it in OptionROMVersion.
277 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
280 uint32_t prog_id_word
;
282 /* character array used for decoding dist type. */
283 char dist_char
[] = "nabx";
285 if (pmboxq
->u
.mb
.mbxStatus
!= MBX_SUCCESS
) {
286 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
290 prg
= (struct prog_id
*) &prog_id_word
;
292 /* word 7 contain option rom version */
293 prog_id_word
= pmboxq
->u
.mb
.un
.varWords
[7];
295 /* Decode the Option rom version word to a readable string */
297 dist
= dist_char
[prg
->dist
];
299 if ((prg
->dist
== 3) && (prg
->num
== 0))
300 sprintf(phba
->OptionROMVersion
, "%d.%d%d",
301 prg
->ver
, prg
->rev
, prg
->lev
);
303 sprintf(phba
->OptionROMVersion
, "%d.%d%d%c%d",
304 prg
->ver
, prg
->rev
, prg
->lev
,
306 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
311 * lpfc_config_port_post - Perform lpfc initialization after config port
312 * @phba: pointer to lpfc hba data structure.
314 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
315 * command call. It performs all internal resource and state setups on the
316 * port: post IOCB buffers, enable appropriate host interrupt attentions,
317 * ELS ring timers, etc.
321 * Any other value - error.
324 lpfc_config_port_post(struct lpfc_hba
*phba
)
326 struct lpfc_vport
*vport
= phba
->pport
;
327 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
330 struct lpfc_dmabuf
*mp
;
331 struct lpfc_sli
*psli
= &phba
->sli
;
332 uint32_t status
, timeout
;
336 spin_lock_irq(&phba
->hbalock
);
338 * If the Config port completed correctly the HBA is not
339 * over heated any more.
341 if (phba
->over_temp_state
== HBA_OVER_TEMP
)
342 phba
->over_temp_state
= HBA_NORMAL_TEMP
;
343 spin_unlock_irq(&phba
->hbalock
);
345 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
347 phba
->link_state
= LPFC_HBA_ERROR
;
352 /* Get login parameters for NID. */
353 lpfc_read_sparam(phba
, pmb
, 0);
355 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
356 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
357 "0448 Adapter failed init, mbxCmd x%x "
358 "READ_SPARM mbxStatus x%x\n",
359 mb
->mbxCommand
, mb
->mbxStatus
);
360 phba
->link_state
= LPFC_HBA_ERROR
;
361 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
362 mempool_free( pmb
, phba
->mbox_mem_pool
);
363 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
368 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
370 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof (struct serv_parm
));
371 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
373 pmb
->context1
= NULL
;
375 if (phba
->cfg_soft_wwnn
)
376 u64_to_wwn(phba
->cfg_soft_wwnn
,
377 vport
->fc_sparam
.nodeName
.u
.wwn
);
378 if (phba
->cfg_soft_wwpn
)
379 u64_to_wwn(phba
->cfg_soft_wwpn
,
380 vport
->fc_sparam
.portName
.u
.wwn
);
381 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
382 sizeof (struct lpfc_name
));
383 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
384 sizeof (struct lpfc_name
));
386 /* Update the fc_host data structures with new wwn. */
387 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
388 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
389 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
391 /* If no serial number in VPD data, use low 6 bytes of WWNN */
392 /* This should be consolidated into parse_vpd ? - mr */
393 if (phba
->SerialNumber
[0] == 0) {
396 outptr
= &vport
->fc_nodename
.u
.s
.IEEE
[0];
397 for (i
= 0; i
< 12; i
++) {
399 j
= ((status
& 0xf0) >> 4);
401 phba
->SerialNumber
[i
] =
402 (char)((uint8_t) 0x30 + (uint8_t) j
);
404 phba
->SerialNumber
[i
] =
405 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
409 phba
->SerialNumber
[i
] =
410 (char)((uint8_t) 0x30 + (uint8_t) j
);
412 phba
->SerialNumber
[i
] =
413 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
417 lpfc_read_config(phba
, pmb
);
419 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
420 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
421 "0453 Adapter failed to init, mbxCmd x%x "
422 "READ_CONFIG, mbxStatus x%x\n",
423 mb
->mbxCommand
, mb
->mbxStatus
);
424 phba
->link_state
= LPFC_HBA_ERROR
;
425 mempool_free( pmb
, phba
->mbox_mem_pool
);
429 /* Check if the port is disabled */
430 lpfc_sli_read_link_ste(phba
);
432 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
433 if (phba
->cfg_hba_queue_depth
> (mb
->un
.varRdConfig
.max_xri
+1))
434 phba
->cfg_hba_queue_depth
=
435 (mb
->un
.varRdConfig
.max_xri
+ 1) -
436 lpfc_sli4_get_els_iocb_cnt(phba
);
438 phba
->lmt
= mb
->un
.varRdConfig
.lmt
;
440 /* Get the default values for Model Name and Description */
441 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
443 if ((phba
->cfg_link_speed
> LINK_SPEED_10G
)
444 || ((phba
->cfg_link_speed
== LINK_SPEED_1G
)
445 && !(phba
->lmt
& LMT_1Gb
))
446 || ((phba
->cfg_link_speed
== LINK_SPEED_2G
)
447 && !(phba
->lmt
& LMT_2Gb
))
448 || ((phba
->cfg_link_speed
== LINK_SPEED_4G
)
449 && !(phba
->lmt
& LMT_4Gb
))
450 || ((phba
->cfg_link_speed
== LINK_SPEED_8G
)
451 && !(phba
->lmt
& LMT_8Gb
))
452 || ((phba
->cfg_link_speed
== LINK_SPEED_10G
)
453 && !(phba
->lmt
& LMT_10Gb
))) {
454 /* Reset link speed to auto */
455 lpfc_printf_log(phba
, KERN_WARNING
, LOG_LINK_EVENT
,
456 "1302 Invalid speed for this board: "
457 "Reset link speed to auto: x%x\n",
458 phba
->cfg_link_speed
);
459 phba
->cfg_link_speed
= LINK_SPEED_AUTO
;
462 phba
->link_state
= LPFC_LINK_DOWN
;
464 /* Only process IOCBs on ELS ring till hba_state is READY */
465 if (psli
->ring
[psli
->extra_ring
].cmdringaddr
)
466 psli
->ring
[psli
->extra_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
467 if (psli
->ring
[psli
->fcp_ring
].cmdringaddr
)
468 psli
->ring
[psli
->fcp_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
469 if (psli
->ring
[psli
->next_ring
].cmdringaddr
)
470 psli
->ring
[psli
->next_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
472 /* Post receive buffers for desired rings */
473 if (phba
->sli_rev
!= 3)
474 lpfc_post_rcv_buf(phba
);
477 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
479 if (phba
->intr_type
== MSIX
) {
480 rc
= lpfc_config_msi(phba
, pmb
);
482 mempool_free(pmb
, phba
->mbox_mem_pool
);
485 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
486 if (rc
!= MBX_SUCCESS
) {
487 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
488 "0352 Config MSI mailbox command "
489 "failed, mbxCmd x%x, mbxStatus x%x\n",
490 pmb
->u
.mb
.mbxCommand
,
491 pmb
->u
.mb
.mbxStatus
);
492 mempool_free(pmb
, phba
->mbox_mem_pool
);
497 spin_lock_irq(&phba
->hbalock
);
498 /* Initialize ERATT handling flag */
499 phba
->hba_flag
&= ~HBA_ERATT_HANDLED
;
501 /* Enable appropriate host interrupts */
502 status
= readl(phba
->HCregaddr
);
503 status
|= HC_MBINT_ENA
| HC_ERINT_ENA
| HC_LAINT_ENA
;
504 if (psli
->num_rings
> 0)
505 status
|= HC_R0INT_ENA
;
506 if (psli
->num_rings
> 1)
507 status
|= HC_R1INT_ENA
;
508 if (psli
->num_rings
> 2)
509 status
|= HC_R2INT_ENA
;
510 if (psli
->num_rings
> 3)
511 status
|= HC_R3INT_ENA
;
513 if ((phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) &&
514 (phba
->cfg_poll
& DISABLE_FCP_RING_INT
))
515 status
&= ~(HC_R0INT_ENA
);
517 writel(status
, phba
->HCregaddr
);
518 readl(phba
->HCregaddr
); /* flush */
519 spin_unlock_irq(&phba
->hbalock
);
521 /* Set up ring-0 (ELS) timer */
522 timeout
= phba
->fc_ratov
* 2;
523 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
524 /* Set up heart beat (HB) timer */
525 mod_timer(&phba
->hb_tmofunc
, jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
526 phba
->hb_outstanding
= 0;
527 phba
->last_completion_time
= jiffies
;
528 /* Set up error attention (ERATT) polling timer */
529 mod_timer(&phba
->eratt_poll
, jiffies
+ HZ
* LPFC_ERATT_POLL_INTERVAL
);
531 if (phba
->hba_flag
& LINK_DISABLED
) {
532 lpfc_printf_log(phba
,
534 "2598 Adapter Link is disabled.\n");
535 lpfc_down_link(phba
, pmb
);
536 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
537 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
538 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
539 lpfc_printf_log(phba
,
541 "2599 Adapter failed to issue DOWN_LINK"
542 " mbox command rc 0x%x\n", rc
);
544 mempool_free(pmb
, phba
->mbox_mem_pool
);
548 lpfc_init_link(phba
, pmb
, phba
->cfg_topology
,
549 phba
->cfg_link_speed
);
550 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
551 lpfc_set_loopback_flag(phba
);
552 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
553 if (rc
!= MBX_SUCCESS
) {
554 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
555 "0454 Adapter failed to init, mbxCmd x%x "
556 "INIT_LINK, mbxStatus x%x\n",
557 mb
->mbxCommand
, mb
->mbxStatus
);
559 /* Clear all interrupt enable conditions */
560 writel(0, phba
->HCregaddr
);
561 readl(phba
->HCregaddr
); /* flush */
562 /* Clear all pending interrupts */
563 writel(0xffffffff, phba
->HAregaddr
);
564 readl(phba
->HAregaddr
); /* flush */
566 phba
->link_state
= LPFC_HBA_ERROR
;
568 mempool_free(pmb
, phba
->mbox_mem_pool
);
572 /* MBOX buffer will be freed in mbox compl */
573 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
574 lpfc_config_async(phba
, pmb
, LPFC_ELS_RING
);
575 pmb
->mbox_cmpl
= lpfc_config_async_cmpl
;
576 pmb
->vport
= phba
->pport
;
577 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
579 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
580 lpfc_printf_log(phba
,
583 "0456 Adapter failed to issue "
584 "ASYNCEVT_ENABLE mbox status x%x\n",
586 mempool_free(pmb
, phba
->mbox_mem_pool
);
589 /* Get Option rom version */
590 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
591 lpfc_dump_wakeup_param(phba
, pmb
);
592 pmb
->mbox_cmpl
= lpfc_dump_wakeup_param_cmpl
;
593 pmb
->vport
= phba
->pport
;
594 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
596 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
597 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
, "0435 Adapter failed "
598 "to get Option ROM version status x%x\n", rc
);
599 mempool_free(pmb
, phba
->mbox_mem_pool
);
606 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
607 * @phba: pointer to lpfc HBA data structure.
609 * This routine will do LPFC uninitialization before the HBA is reset when
610 * bringing down the SLI Layer.
614 * Any other value - error.
617 lpfc_hba_down_prep(struct lpfc_hba
*phba
)
619 struct lpfc_vport
**vports
;
622 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
623 /* Disable interrupts */
624 writel(0, phba
->HCregaddr
);
625 readl(phba
->HCregaddr
); /* flush */
628 if (phba
->pport
->load_flag
& FC_UNLOADING
)
629 lpfc_cleanup_discovery_resources(phba
->pport
);
631 vports
= lpfc_create_vport_work_array(phba
);
633 for (i
= 0; i
<= phba
->max_vports
&&
634 vports
[i
] != NULL
; i
++)
635 lpfc_cleanup_discovery_resources(vports
[i
]);
636 lpfc_destroy_vport_work_array(phba
, vports
);
642 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
643 * @phba: pointer to lpfc HBA data structure.
645 * This routine will do uninitialization after the HBA is reset when bring
646 * down the SLI Layer.
650 * Any other value - error.
653 lpfc_hba_down_post_s3(struct lpfc_hba
*phba
)
655 struct lpfc_sli
*psli
= &phba
->sli
;
656 struct lpfc_sli_ring
*pring
;
657 struct lpfc_dmabuf
*mp
, *next_mp
;
658 LIST_HEAD(completions
);
661 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
662 lpfc_sli_hbqbuf_free_all(phba
);
664 /* Cleanup preposted buffers on the ELS ring */
665 pring
= &psli
->ring
[LPFC_ELS_RING
];
666 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
668 pring
->postbufq_cnt
--;
669 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
674 spin_lock_irq(&phba
->hbalock
);
675 for (i
= 0; i
< psli
->num_rings
; i
++) {
676 pring
= &psli
->ring
[i
];
678 /* At this point in time the HBA is either reset or DOA. Either
679 * way, nothing should be on txcmplq as it will NEVER complete.
681 list_splice_init(&pring
->txcmplq
, &completions
);
682 pring
->txcmplq_cnt
= 0;
683 spin_unlock_irq(&phba
->hbalock
);
685 /* Cancel all the IOCBs from the completions list */
686 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
689 lpfc_sli_abort_iocb_ring(phba
, pring
);
690 spin_lock_irq(&phba
->hbalock
);
692 spin_unlock_irq(&phba
->hbalock
);
697 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
698 * @phba: pointer to lpfc HBA data structure.
700 * This routine will do uninitialization after the HBA is reset when bring
701 * down the SLI Layer.
705 * Any other value - error.
708 lpfc_hba_down_post_s4(struct lpfc_hba
*phba
)
710 struct lpfc_scsi_buf
*psb
, *psb_next
;
713 unsigned long iflag
= 0;
714 ret
= lpfc_hba_down_post_s3(phba
);
717 /* At this point in time the HBA is either reset or DOA. Either
718 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
719 * on the lpfc_sgl_list so that it can either be freed if the
720 * driver is unloading or reposted if the driver is restarting
723 spin_lock_irq(&phba
->hbalock
); /* required for lpfc_sgl_list and */
725 /* abts_sgl_list_lock required because worker thread uses this
728 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
729 list_splice_init(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
,
730 &phba
->sli4_hba
.lpfc_sgl_list
);
731 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
732 /* abts_scsi_buf_list_lock required because worker thread uses this
735 spin_lock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
736 list_splice_init(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
,
738 spin_unlock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
739 spin_unlock_irq(&phba
->hbalock
);
741 list_for_each_entry_safe(psb
, psb_next
, &aborts
, list
) {
743 psb
->status
= IOSTAT_SUCCESS
;
745 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
746 list_splice(&aborts
, &phba
->lpfc_scsi_buf_list
);
747 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
752 * lpfc_hba_down_post - Wrapper func for hba down post routine
753 * @phba: pointer to lpfc HBA data structure.
755 * This routine wraps the actual SLI3 or SLI4 routine for performing
756 * uninitialization after the HBA is reset when bring down the SLI Layer.
760 * Any other value - error.
763 lpfc_hba_down_post(struct lpfc_hba
*phba
)
765 return (*phba
->lpfc_hba_down_post
)(phba
);
769 * lpfc_hb_timeout - The HBA-timer timeout handler
770 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
772 * This is the HBA-timer timeout handler registered to the lpfc driver. When
773 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
774 * work-port-events bitmap and the worker thread is notified. This timeout
775 * event will be used by the worker thread to invoke the actual timeout
776 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
777 * be performed in the timeout handler and the HBA timeout event bit shall
778 * be cleared by the worker thread after it has taken the event bitmap out.
781 lpfc_hb_timeout(unsigned long ptr
)
783 struct lpfc_hba
*phba
;
787 phba
= (struct lpfc_hba
*)ptr
;
789 /* Check for heart beat timeout conditions */
790 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
791 tmo_posted
= phba
->pport
->work_port_events
& WORKER_HB_TMO
;
793 phba
->pport
->work_port_events
|= WORKER_HB_TMO
;
794 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
796 /* Tell the worker thread there is work to do */
798 lpfc_worker_wake_up(phba
);
803 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
804 * @phba: pointer to lpfc hba data structure.
805 * @pmboxq: pointer to the driver internal queue element for mailbox command.
807 * This is the callback function to the lpfc heart-beat mailbox command.
808 * If configured, the lpfc driver issues the heart-beat mailbox command to
809 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
810 * heart-beat mailbox command is issued, the driver shall set up heart-beat
811 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
812 * heart-beat outstanding state. Once the mailbox command comes back and
813 * no error conditions detected, the heart-beat mailbox command timer is
814 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
815 * state is cleared for the next heart-beat. If the timer expired with the
816 * heart-beat outstanding state set, the driver will put the HBA offline.
819 lpfc_hb_mbox_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
821 unsigned long drvr_flag
;
823 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
824 phba
->hb_outstanding
= 0;
825 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
827 /* Check and reset heart-beat timer is necessary */
828 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
829 if (!(phba
->pport
->fc_flag
& FC_OFFLINE_MODE
) &&
830 !(phba
->link_state
== LPFC_HBA_ERROR
) &&
831 !(phba
->pport
->load_flag
& FC_UNLOADING
))
832 mod_timer(&phba
->hb_tmofunc
,
833 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
838 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
839 * @phba: pointer to lpfc hba data structure.
841 * This is the actual HBA-timer timeout handler to be invoked by the worker
842 * thread whenever the HBA timer fired and HBA-timeout event posted. This
843 * handler performs any periodic operations needed for the device. If such
844 * periodic event has already been attended to either in the interrupt handler
845 * or by processing slow-ring or fast-ring events within the HBA-timer
846 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
847 * the timer for the next timeout period. If lpfc heart-beat mailbox command
848 * is configured and there is no heart-beat mailbox command outstanding, a
849 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
850 * has been a heart-beat mailbox command outstanding, the HBA shall be put
854 lpfc_hb_timeout_handler(struct lpfc_hba
*phba
)
856 struct lpfc_vport
**vports
;
857 LPFC_MBOXQ_t
*pmboxq
;
858 struct lpfc_dmabuf
*buf_ptr
;
860 struct lpfc_sli
*psli
= &phba
->sli
;
861 LIST_HEAD(completions
);
863 vports
= lpfc_create_vport_work_array(phba
);
865 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
866 lpfc_rcv_seq_check_edtov(vports
[i
]);
867 lpfc_destroy_vport_work_array(phba
, vports
);
869 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
870 (phba
->pport
->load_flag
& FC_UNLOADING
) ||
871 (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
))
874 spin_lock_irq(&phba
->pport
->work_port_lock
);
876 if (time_after(phba
->last_completion_time
+ LPFC_HB_MBOX_INTERVAL
* HZ
,
878 spin_unlock_irq(&phba
->pport
->work_port_lock
);
879 if (!phba
->hb_outstanding
)
880 mod_timer(&phba
->hb_tmofunc
,
881 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
883 mod_timer(&phba
->hb_tmofunc
,
884 jiffies
+ HZ
* LPFC_HB_MBOX_TIMEOUT
);
887 spin_unlock_irq(&phba
->pport
->work_port_lock
);
889 if (phba
->elsbuf_cnt
&&
890 (phba
->elsbuf_cnt
== phba
->elsbuf_prev_cnt
)) {
891 spin_lock_irq(&phba
->hbalock
);
892 list_splice_init(&phba
->elsbuf
, &completions
);
893 phba
->elsbuf_cnt
= 0;
894 phba
->elsbuf_prev_cnt
= 0;
895 spin_unlock_irq(&phba
->hbalock
);
897 while (!list_empty(&completions
)) {
898 list_remove_head(&completions
, buf_ptr
,
899 struct lpfc_dmabuf
, list
);
900 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
904 phba
->elsbuf_prev_cnt
= phba
->elsbuf_cnt
;
906 /* If there is no heart beat outstanding, issue a heartbeat command */
907 if (phba
->cfg_enable_hba_heartbeat
) {
908 if (!phba
->hb_outstanding
) {
909 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,GFP_KERNEL
);
911 mod_timer(&phba
->hb_tmofunc
,
912 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
916 lpfc_heart_beat(phba
, pmboxq
);
917 pmboxq
->mbox_cmpl
= lpfc_hb_mbox_cmpl
;
918 pmboxq
->vport
= phba
->pport
;
919 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
, MBX_NOWAIT
);
921 if (retval
!= MBX_BUSY
&& retval
!= MBX_SUCCESS
) {
922 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
923 mod_timer(&phba
->hb_tmofunc
,
924 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
927 mod_timer(&phba
->hb_tmofunc
,
928 jiffies
+ HZ
* LPFC_HB_MBOX_TIMEOUT
);
929 phba
->hb_outstanding
= 1;
933 * If heart beat timeout called with hb_outstanding set
934 * we need to take the HBA offline.
936 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
937 "0459 Adapter heartbeat failure, "
938 "taking this port offline.\n");
940 spin_lock_irq(&phba
->hbalock
);
941 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
942 spin_unlock_irq(&phba
->hbalock
);
944 lpfc_offline_prep(phba
);
946 lpfc_unblock_mgmt_io(phba
);
947 phba
->link_state
= LPFC_HBA_ERROR
;
948 lpfc_hba_down_post(phba
);
954 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
955 * @phba: pointer to lpfc hba data structure.
957 * This routine is called to bring the HBA offline when HBA hardware error
958 * other than Port Error 6 has been detected.
961 lpfc_offline_eratt(struct lpfc_hba
*phba
)
963 struct lpfc_sli
*psli
= &phba
->sli
;
965 spin_lock_irq(&phba
->hbalock
);
966 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
967 spin_unlock_irq(&phba
->hbalock
);
968 lpfc_offline_prep(phba
);
971 lpfc_reset_barrier(phba
);
972 spin_lock_irq(&phba
->hbalock
);
973 lpfc_sli_brdreset(phba
);
974 spin_unlock_irq(&phba
->hbalock
);
975 lpfc_hba_down_post(phba
);
976 lpfc_sli_brdready(phba
, HS_MBRDY
);
977 lpfc_unblock_mgmt_io(phba
);
978 phba
->link_state
= LPFC_HBA_ERROR
;
983 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
984 * @phba: pointer to lpfc hba data structure.
986 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
987 * other than Port Error 6 has been detected.
990 lpfc_sli4_offline_eratt(struct lpfc_hba
*phba
)
992 lpfc_offline_prep(phba
);
994 lpfc_sli4_brdreset(phba
);
995 lpfc_hba_down_post(phba
);
996 lpfc_sli4_post_status_check(phba
);
997 lpfc_unblock_mgmt_io(phba
);
998 phba
->link_state
= LPFC_HBA_ERROR
;
1002 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1003 * @phba: pointer to lpfc hba data structure.
1005 * This routine is invoked to handle the deferred HBA hardware error
1006 * conditions. This type of error is indicated by HBA by setting ER1
1007 * and another ER bit in the host status register. The driver will
1008 * wait until the ER1 bit clears before handling the error condition.
1011 lpfc_handle_deferred_eratt(struct lpfc_hba
*phba
)
1013 uint32_t old_host_status
= phba
->work_hs
;
1014 struct lpfc_sli_ring
*pring
;
1015 struct lpfc_sli
*psli
= &phba
->sli
;
1017 /* If the pci channel is offline, ignore possible errors,
1018 * since we cannot communicate with the pci card anyway.
1020 if (pci_channel_offline(phba
->pcidev
)) {
1021 spin_lock_irq(&phba
->hbalock
);
1022 phba
->hba_flag
&= ~DEFER_ERATT
;
1023 spin_unlock_irq(&phba
->hbalock
);
1027 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1028 "0479 Deferred Adapter Hardware Error "
1029 "Data: x%x x%x x%x\n",
1031 phba
->work_status
[0], phba
->work_status
[1]);
1033 spin_lock_irq(&phba
->hbalock
);
1034 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1035 spin_unlock_irq(&phba
->hbalock
);
1039 * Firmware stops when it triggred erratt. That could cause the I/Os
1040 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1041 * SCSI layer retry it after re-establishing link.
1043 pring
= &psli
->ring
[psli
->fcp_ring
];
1044 lpfc_sli_abort_iocb_ring(phba
, pring
);
1047 * There was a firmware error. Take the hba offline and then
1048 * attempt to restart it.
1050 lpfc_offline_prep(phba
);
1053 /* Wait for the ER1 bit to clear.*/
1054 while (phba
->work_hs
& HS_FFER1
) {
1056 phba
->work_hs
= readl(phba
->HSregaddr
);
1057 /* If driver is unloading let the worker thread continue */
1058 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
1065 * This is to ptrotect against a race condition in which
1066 * first write to the host attention register clear the
1067 * host status register.
1069 if ((!phba
->work_hs
) && (!(phba
->pport
->load_flag
& FC_UNLOADING
)))
1070 phba
->work_hs
= old_host_status
& ~HS_FFER1
;
1072 spin_lock_irq(&phba
->hbalock
);
1073 phba
->hba_flag
&= ~DEFER_ERATT
;
1074 spin_unlock_irq(&phba
->hbalock
);
1075 phba
->work_status
[0] = readl(phba
->MBslimaddr
+ 0xa8);
1076 phba
->work_status
[1] = readl(phba
->MBslimaddr
+ 0xac);
1080 lpfc_board_errevt_to_mgmt(struct lpfc_hba
*phba
)
1082 struct lpfc_board_event_header board_event
;
1083 struct Scsi_Host
*shost
;
1085 board_event
.event_type
= FC_REG_BOARD_EVENT
;
1086 board_event
.subcategory
= LPFC_EVENT_PORTINTERR
;
1087 shost
= lpfc_shost_from_vport(phba
->pport
);
1088 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1089 sizeof(board_event
),
1090 (char *) &board_event
,
1095 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1096 * @phba: pointer to lpfc hba data structure.
1098 * This routine is invoked to handle the following HBA hardware error
1100 * 1 - HBA error attention interrupt
1101 * 2 - DMA ring index out of range
1102 * 3 - Mailbox command came back as unknown
1105 lpfc_handle_eratt_s3(struct lpfc_hba
*phba
)
1107 struct lpfc_vport
*vport
= phba
->pport
;
1108 struct lpfc_sli
*psli
= &phba
->sli
;
1109 struct lpfc_sli_ring
*pring
;
1110 uint32_t event_data
;
1111 unsigned long temperature
;
1112 struct temp_event temp_event_data
;
1113 struct Scsi_Host
*shost
;
1115 /* If the pci channel is offline, ignore possible errors,
1116 * since we cannot communicate with the pci card anyway.
1118 if (pci_channel_offline(phba
->pcidev
)) {
1119 spin_lock_irq(&phba
->hbalock
);
1120 phba
->hba_flag
&= ~DEFER_ERATT
;
1121 spin_unlock_irq(&phba
->hbalock
);
1125 /* If resets are disabled then leave the HBA alone and return */
1126 if (!phba
->cfg_enable_hba_reset
)
1129 /* Send an internal error event to mgmt application */
1130 lpfc_board_errevt_to_mgmt(phba
);
1132 if (phba
->hba_flag
& DEFER_ERATT
)
1133 lpfc_handle_deferred_eratt(phba
);
1135 if (phba
->work_hs
& HS_FFER6
) {
1136 /* Re-establishing Link */
1137 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1138 "1301 Re-establishing Link "
1139 "Data: x%x x%x x%x\n",
1141 phba
->work_status
[0], phba
->work_status
[1]);
1143 spin_lock_irq(&phba
->hbalock
);
1144 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1145 spin_unlock_irq(&phba
->hbalock
);
1148 * Firmware stops when it triggled erratt with HS_FFER6.
1149 * That could cause the I/Os dropped by the firmware.
1150 * Error iocb (I/O) on txcmplq and let the SCSI layer
1151 * retry it after re-establishing link.
1153 pring
= &psli
->ring
[psli
->fcp_ring
];
1154 lpfc_sli_abort_iocb_ring(phba
, pring
);
1157 * There was a firmware error. Take the hba offline and then
1158 * attempt to restart it.
1160 lpfc_offline_prep(phba
);
1162 lpfc_sli_brdrestart(phba
);
1163 if (lpfc_online(phba
) == 0) { /* Initialize the HBA */
1164 lpfc_unblock_mgmt_io(phba
);
1167 lpfc_unblock_mgmt_io(phba
);
1168 } else if (phba
->work_hs
& HS_CRIT_TEMP
) {
1169 temperature
= readl(phba
->MBslimaddr
+ TEMPERATURE_OFFSET
);
1170 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
1171 temp_event_data
.event_code
= LPFC_CRIT_TEMP
;
1172 temp_event_data
.data
= (uint32_t)temperature
;
1174 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1175 "0406 Adapter maximum temperature exceeded "
1176 "(%ld), taking this port offline "
1177 "Data: x%x x%x x%x\n",
1178 temperature
, phba
->work_hs
,
1179 phba
->work_status
[0], phba
->work_status
[1]);
1181 shost
= lpfc_shost_from_vport(phba
->pport
);
1182 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1183 sizeof(temp_event_data
),
1184 (char *) &temp_event_data
,
1185 SCSI_NL_VID_TYPE_PCI
1186 | PCI_VENDOR_ID_EMULEX
);
1188 spin_lock_irq(&phba
->hbalock
);
1189 phba
->over_temp_state
= HBA_OVER_TEMP
;
1190 spin_unlock_irq(&phba
->hbalock
);
1191 lpfc_offline_eratt(phba
);
1194 /* The if clause above forces this code path when the status
1195 * failure is a value other than FFER6. Do not call the offline
1196 * twice. This is the adapter hardware error path.
1198 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1199 "0457 Adapter Hardware Error "
1200 "Data: x%x x%x x%x\n",
1202 phba
->work_status
[0], phba
->work_status
[1]);
1204 event_data
= FC_REG_DUMP_EVENT
;
1205 shost
= lpfc_shost_from_vport(vport
);
1206 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1207 sizeof(event_data
), (char *) &event_data
,
1208 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
1210 lpfc_offline_eratt(phba
);
1216 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1217 * @phba: pointer to lpfc hba data structure.
1219 * This routine is invoked to handle the SLI4 HBA hardware error attention
1223 lpfc_handle_eratt_s4(struct lpfc_hba
*phba
)
1225 struct lpfc_vport
*vport
= phba
->pport
;
1226 uint32_t event_data
;
1227 struct Scsi_Host
*shost
;
1229 /* If the pci channel is offline, ignore possible errors, since
1230 * we cannot communicate with the pci card anyway.
1232 if (pci_channel_offline(phba
->pcidev
))
1234 /* If resets are disabled then leave the HBA alone and return */
1235 if (!phba
->cfg_enable_hba_reset
)
1238 /* Send an internal error event to mgmt application */
1239 lpfc_board_errevt_to_mgmt(phba
);
1241 /* For now, the actual action for SLI4 device handling is not
1242 * specified yet, just treated it as adaptor hardware failure
1244 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1245 "0143 SLI4 Adapter Hardware Error Data: x%x x%x\n",
1246 phba
->work_status
[0], phba
->work_status
[1]);
1248 event_data
= FC_REG_DUMP_EVENT
;
1249 shost
= lpfc_shost_from_vport(vport
);
1250 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1251 sizeof(event_data
), (char *) &event_data
,
1252 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
1254 lpfc_sli4_offline_eratt(phba
);
1258 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1259 * @phba: pointer to lpfc HBA data structure.
1261 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1262 * routine from the API jump table function pointer from the lpfc_hba struct.
1266 * Any other value - error.
1269 lpfc_handle_eratt(struct lpfc_hba
*phba
)
1271 (*phba
->lpfc_handle_eratt
)(phba
);
1275 * lpfc_handle_latt - The HBA link event handler
1276 * @phba: pointer to lpfc hba data structure.
1278 * This routine is invoked from the worker thread to handle a HBA host
1279 * attention link event.
1282 lpfc_handle_latt(struct lpfc_hba
*phba
)
1284 struct lpfc_vport
*vport
= phba
->pport
;
1285 struct lpfc_sli
*psli
= &phba
->sli
;
1287 volatile uint32_t control
;
1288 struct lpfc_dmabuf
*mp
;
1291 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1294 goto lpfc_handle_latt_err_exit
;
1297 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1300 goto lpfc_handle_latt_free_pmb
;
1303 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
1306 goto lpfc_handle_latt_free_mp
;
1309 /* Cleanup any outstanding ELS commands */
1310 lpfc_els_flush_all_cmd(phba
);
1312 psli
->slistat
.link_event
++;
1313 lpfc_read_la(phba
, pmb
, mp
);
1314 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_la
;
1316 /* Block ELS IOCBs until we have processed this mbox command */
1317 phba
->sli
.ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
1318 rc
= lpfc_sli_issue_mbox (phba
, pmb
, MBX_NOWAIT
);
1319 if (rc
== MBX_NOT_FINISHED
) {
1321 goto lpfc_handle_latt_free_mbuf
;
1324 /* Clear Link Attention in HA REG */
1325 spin_lock_irq(&phba
->hbalock
);
1326 writel(HA_LATT
, phba
->HAregaddr
);
1327 readl(phba
->HAregaddr
); /* flush */
1328 spin_unlock_irq(&phba
->hbalock
);
1332 lpfc_handle_latt_free_mbuf
:
1333 phba
->sli
.ring
[LPFC_ELS_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1334 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1335 lpfc_handle_latt_free_mp
:
1337 lpfc_handle_latt_free_pmb
:
1338 mempool_free(pmb
, phba
->mbox_mem_pool
);
1339 lpfc_handle_latt_err_exit
:
1340 /* Enable Link attention interrupts */
1341 spin_lock_irq(&phba
->hbalock
);
1342 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1343 control
= readl(phba
->HCregaddr
);
1344 control
|= HC_LAINT_ENA
;
1345 writel(control
, phba
->HCregaddr
);
1346 readl(phba
->HCregaddr
); /* flush */
1348 /* Clear Link Attention in HA REG */
1349 writel(HA_LATT
, phba
->HAregaddr
);
1350 readl(phba
->HAregaddr
); /* flush */
1351 spin_unlock_irq(&phba
->hbalock
);
1352 lpfc_linkdown(phba
);
1353 phba
->link_state
= LPFC_HBA_ERROR
;
1355 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1356 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc
);
1362 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
1363 * @phba: pointer to lpfc hba data structure.
1364 * @vpd: pointer to the vital product data.
1365 * @len: length of the vital product data in bytes.
1367 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1368 * an array of characters. In this routine, the ModelName, ProgramType, and
1369 * ModelDesc, etc. fields of the phba data structure will be populated.
1372 * 0 - pointer to the VPD passed in is NULL
1376 lpfc_parse_vpd(struct lpfc_hba
*phba
, uint8_t *vpd
, int len
)
1378 uint8_t lenlo
, lenhi
;
1388 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1389 "0455 Vital Product Data: x%x x%x x%x x%x\n",
1390 (uint32_t) vpd
[0], (uint32_t) vpd
[1], (uint32_t) vpd
[2],
1392 while (!finished
&& (index
< (len
- 4))) {
1393 switch (vpd
[index
]) {
1401 i
= ((((unsigned short)lenhi
) << 8) + lenlo
);
1410 Length
= ((((unsigned short)lenhi
) << 8) + lenlo
);
1411 if (Length
> len
- index
)
1412 Length
= len
- index
;
1413 while (Length
> 0) {
1414 /* Look for Serial Number */
1415 if ((vpd
[index
] == 'S') && (vpd
[index
+1] == 'N')) {
1422 phba
->SerialNumber
[j
++] = vpd
[index
++];
1426 phba
->SerialNumber
[j
] = 0;
1429 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '1')) {
1430 phba
->vpd_flag
|= VPD_MODEL_DESC
;
1437 phba
->ModelDesc
[j
++] = vpd
[index
++];
1441 phba
->ModelDesc
[j
] = 0;
1444 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '2')) {
1445 phba
->vpd_flag
|= VPD_MODEL_NAME
;
1452 phba
->ModelName
[j
++] = vpd
[index
++];
1456 phba
->ModelName
[j
] = 0;
1459 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '3')) {
1460 phba
->vpd_flag
|= VPD_PROGRAM_TYPE
;
1467 phba
->ProgramType
[j
++] = vpd
[index
++];
1471 phba
->ProgramType
[j
] = 0;
1474 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '4')) {
1475 phba
->vpd_flag
|= VPD_PORT
;
1482 phba
->Port
[j
++] = vpd
[index
++];
1512 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
1513 * @phba: pointer to lpfc hba data structure.
1514 * @mdp: pointer to the data structure to hold the derived model name.
1515 * @descp: pointer to the data structure to hold the derived description.
1517 * This routine retrieves HBA's description based on its registered PCI device
1518 * ID. The @descp passed into this function points to an array of 256 chars. It
1519 * shall be returned with the model name, maximum speed, and the host bus type.
1520 * The @mdp passed into this function points to an array of 80 chars. When the
1521 * function returns, the @mdp will be filled with the model name.
1524 lpfc_get_hba_model_desc(struct lpfc_hba
*phba
, uint8_t *mdp
, uint8_t *descp
)
1527 uint16_t dev_id
= phba
->pcidev
->device
;
1530 int oneConnect
= 0; /* default is not a oneConnect */
1535 } m
= {"<Unknown>", "", ""};
1537 if (mdp
&& mdp
[0] != '\0'
1538 && descp
&& descp
[0] != '\0')
1541 if (phba
->lmt
& LMT_10Gb
)
1543 else if (phba
->lmt
& LMT_8Gb
)
1545 else if (phba
->lmt
& LMT_4Gb
)
1547 else if (phba
->lmt
& LMT_2Gb
)
1555 case PCI_DEVICE_ID_FIREFLY
:
1556 m
= (typeof(m
)){"LP6000", "PCI", "Fibre Channel Adapter"};
1558 case PCI_DEVICE_ID_SUPERFLY
:
1559 if (vp
->rev
.biuRev
>= 1 && vp
->rev
.biuRev
<= 3)
1560 m
= (typeof(m
)){"LP7000", "PCI",
1561 "Fibre Channel Adapter"};
1563 m
= (typeof(m
)){"LP7000E", "PCI",
1564 "Fibre Channel Adapter"};
1566 case PCI_DEVICE_ID_DRAGONFLY
:
1567 m
= (typeof(m
)){"LP8000", "PCI",
1568 "Fibre Channel Adapter"};
1570 case PCI_DEVICE_ID_CENTAUR
:
1571 if (FC_JEDEC_ID(vp
->rev
.biuRev
) == CENTAUR_2G_JEDEC_ID
)
1572 m
= (typeof(m
)){"LP9002", "PCI",
1573 "Fibre Channel Adapter"};
1575 m
= (typeof(m
)){"LP9000", "PCI",
1576 "Fibre Channel Adapter"};
1578 case PCI_DEVICE_ID_RFLY
:
1579 m
= (typeof(m
)){"LP952", "PCI",
1580 "Fibre Channel Adapter"};
1582 case PCI_DEVICE_ID_PEGASUS
:
1583 m
= (typeof(m
)){"LP9802", "PCI-X",
1584 "Fibre Channel Adapter"};
1586 case PCI_DEVICE_ID_THOR
:
1587 m
= (typeof(m
)){"LP10000", "PCI-X",
1588 "Fibre Channel Adapter"};
1590 case PCI_DEVICE_ID_VIPER
:
1591 m
= (typeof(m
)){"LPX1000", "PCI-X",
1592 "Fibre Channel Adapter"};
1594 case PCI_DEVICE_ID_PFLY
:
1595 m
= (typeof(m
)){"LP982", "PCI-X",
1596 "Fibre Channel Adapter"};
1598 case PCI_DEVICE_ID_TFLY
:
1599 m
= (typeof(m
)){"LP1050", "PCI-X",
1600 "Fibre Channel Adapter"};
1602 case PCI_DEVICE_ID_HELIOS
:
1603 m
= (typeof(m
)){"LP11000", "PCI-X2",
1604 "Fibre Channel Adapter"};
1606 case PCI_DEVICE_ID_HELIOS_SCSP
:
1607 m
= (typeof(m
)){"LP11000-SP", "PCI-X2",
1608 "Fibre Channel Adapter"};
1610 case PCI_DEVICE_ID_HELIOS_DCSP
:
1611 m
= (typeof(m
)){"LP11002-SP", "PCI-X2",
1612 "Fibre Channel Adapter"};
1614 case PCI_DEVICE_ID_NEPTUNE
:
1615 m
= (typeof(m
)){"LPe1000", "PCIe", "Fibre Channel Adapter"};
1617 case PCI_DEVICE_ID_NEPTUNE_SCSP
:
1618 m
= (typeof(m
)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"};
1620 case PCI_DEVICE_ID_NEPTUNE_DCSP
:
1621 m
= (typeof(m
)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"};
1623 case PCI_DEVICE_ID_BMID
:
1624 m
= (typeof(m
)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
1626 case PCI_DEVICE_ID_BSMB
:
1627 m
= (typeof(m
)){"LP111", "PCI-X2", "Fibre Channel Adapter"};
1629 case PCI_DEVICE_ID_ZEPHYR
:
1630 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
1632 case PCI_DEVICE_ID_ZEPHYR_SCSP
:
1633 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
1635 case PCI_DEVICE_ID_ZEPHYR_DCSP
:
1636 m
= (typeof(m
)){"LP2105", "PCIe", "FCoE Adapter"};
1639 case PCI_DEVICE_ID_ZMID
:
1640 m
= (typeof(m
)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
1642 case PCI_DEVICE_ID_ZSMB
:
1643 m
= (typeof(m
)){"LPe111", "PCIe", "Fibre Channel Adapter"};
1645 case PCI_DEVICE_ID_LP101
:
1646 m
= (typeof(m
)){"LP101", "PCI-X", "Fibre Channel Adapter"};
1648 case PCI_DEVICE_ID_LP10000S
:
1649 m
= (typeof(m
)){"LP10000-S", "PCI", "Fibre Channel Adapter"};
1651 case PCI_DEVICE_ID_LP11000S
:
1652 m
= (typeof(m
)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"};
1654 case PCI_DEVICE_ID_LPE11000S
:
1655 m
= (typeof(m
)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"};
1657 case PCI_DEVICE_ID_SAT
:
1658 m
= (typeof(m
)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
1660 case PCI_DEVICE_ID_SAT_MID
:
1661 m
= (typeof(m
)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
1663 case PCI_DEVICE_ID_SAT_SMB
:
1664 m
= (typeof(m
)){"LPe121", "PCIe", "Fibre Channel Adapter"};
1666 case PCI_DEVICE_ID_SAT_DCSP
:
1667 m
= (typeof(m
)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
1669 case PCI_DEVICE_ID_SAT_SCSP
:
1670 m
= (typeof(m
)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
1672 case PCI_DEVICE_ID_SAT_S
:
1673 m
= (typeof(m
)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
1675 case PCI_DEVICE_ID_HORNET
:
1676 m
= (typeof(m
)){"LP21000", "PCIe", "FCoE Adapter"};
1679 case PCI_DEVICE_ID_PROTEUS_VF
:
1680 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
1681 "Fibre Channel Adapter"};
1683 case PCI_DEVICE_ID_PROTEUS_PF
:
1684 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
1685 "Fibre Channel Adapter"};
1687 case PCI_DEVICE_ID_PROTEUS_S
:
1688 m
= (typeof(m
)){"LPemv12002-S", "PCIe IOV",
1689 "Fibre Channel Adapter"};
1691 case PCI_DEVICE_ID_TIGERSHARK
:
1693 m
= (typeof(m
)){"OCe10100", "PCIe", "FCoE"};
1695 case PCI_DEVICE_ID_TOMCAT
:
1697 m
= (typeof(m
)){"OCe11100", "PCIe", "FCoE"};
1699 case PCI_DEVICE_ID_FALCON
:
1700 m
= (typeof(m
)){"LPSe12002-ML1-E", "PCIe",
1701 "EmulexSecure Fibre"};
1704 m
= (typeof(m
)){"Unknown", "", ""};
1708 if (mdp
&& mdp
[0] == '\0')
1709 snprintf(mdp
, 79,"%s", m
.name
);
1710 /* oneConnect hba requires special processing, they are all initiators
1711 * and we put the port number on the end
1713 if (descp
&& descp
[0] == '\0') {
1715 snprintf(descp
, 255,
1716 "Emulex OneConnect %s, %s Initiator, Port %s",
1720 snprintf(descp
, 255,
1721 "Emulex %s %d%s %s %s",
1722 m
.name
, max_speed
, (GE
) ? "GE" : "Gb",
1728 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
1729 * @phba: pointer to lpfc hba data structure.
1730 * @pring: pointer to a IOCB ring.
1731 * @cnt: the number of IOCBs to be posted to the IOCB ring.
1733 * This routine posts a given number of IOCBs with the associated DMA buffer
1734 * descriptors specified by the cnt argument to the given IOCB ring.
1737 * The number of IOCBs NOT able to be posted to the IOCB ring.
1740 lpfc_post_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
, int cnt
)
1743 struct lpfc_iocbq
*iocb
;
1744 struct lpfc_dmabuf
*mp1
, *mp2
;
1746 cnt
+= pring
->missbufcnt
;
1748 /* While there are buffers to post */
1750 /* Allocate buffer for command iocb */
1751 iocb
= lpfc_sli_get_iocbq(phba
);
1753 pring
->missbufcnt
= cnt
;
1758 /* 2 buffers can be posted per command */
1759 /* Allocate buffer to post */
1760 mp1
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
1762 mp1
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &mp1
->phys
);
1763 if (!mp1
|| !mp1
->virt
) {
1765 lpfc_sli_release_iocbq(phba
, iocb
);
1766 pring
->missbufcnt
= cnt
;
1770 INIT_LIST_HEAD(&mp1
->list
);
1771 /* Allocate buffer to post */
1773 mp2
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
1775 mp2
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
1777 if (!mp2
|| !mp2
->virt
) {
1779 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
1781 lpfc_sli_release_iocbq(phba
, iocb
);
1782 pring
->missbufcnt
= cnt
;
1786 INIT_LIST_HEAD(&mp2
->list
);
1791 icmd
->un
.cont64
[0].addrHigh
= putPaddrHigh(mp1
->phys
);
1792 icmd
->un
.cont64
[0].addrLow
= putPaddrLow(mp1
->phys
);
1793 icmd
->un
.cont64
[0].tus
.f
.bdeSize
= FCELSSIZE
;
1794 icmd
->ulpBdeCount
= 1;
1797 icmd
->un
.cont64
[1].addrHigh
= putPaddrHigh(mp2
->phys
);
1798 icmd
->un
.cont64
[1].addrLow
= putPaddrLow(mp2
->phys
);
1799 icmd
->un
.cont64
[1].tus
.f
.bdeSize
= FCELSSIZE
;
1801 icmd
->ulpBdeCount
= 2;
1804 icmd
->ulpCommand
= CMD_QUE_RING_BUF64_CN
;
1807 if (lpfc_sli_issue_iocb(phba
, pring
->ringno
, iocb
, 0) ==
1809 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
1813 lpfc_mbuf_free(phba
, mp2
->virt
, mp2
->phys
);
1817 lpfc_sli_release_iocbq(phba
, iocb
);
1818 pring
->missbufcnt
= cnt
;
1821 lpfc_sli_ringpostbuf_put(phba
, pring
, mp1
);
1823 lpfc_sli_ringpostbuf_put(phba
, pring
, mp2
);
1825 pring
->missbufcnt
= 0;
1830 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
1831 * @phba: pointer to lpfc hba data structure.
1833 * This routine posts initial receive IOCB buffers to the ELS ring. The
1834 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
1838 * 0 - success (currently always success)
1841 lpfc_post_rcv_buf(struct lpfc_hba
*phba
)
1843 struct lpfc_sli
*psli
= &phba
->sli
;
1845 /* Ring 0, ELS / CT buffers */
1846 lpfc_post_buffer(phba
, &psli
->ring
[LPFC_ELS_RING
], LPFC_BUF_RING0
);
1847 /* Ring 2 - FCP no buffers needed */
1852 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
1855 * lpfc_sha_init - Set up initial array of hash table entries
1856 * @HashResultPointer: pointer to an array as hash table.
1858 * This routine sets up the initial values to the array of hash table entries
1862 lpfc_sha_init(uint32_t * HashResultPointer
)
1864 HashResultPointer
[0] = 0x67452301;
1865 HashResultPointer
[1] = 0xEFCDAB89;
1866 HashResultPointer
[2] = 0x98BADCFE;
1867 HashResultPointer
[3] = 0x10325476;
1868 HashResultPointer
[4] = 0xC3D2E1F0;
1872 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
1873 * @HashResultPointer: pointer to an initial/result hash table.
1874 * @HashWorkingPointer: pointer to an working hash table.
1876 * This routine iterates an initial hash table pointed by @HashResultPointer
1877 * with the values from the working hash table pointeed by @HashWorkingPointer.
1878 * The results are putting back to the initial hash table, returned through
1879 * the @HashResultPointer as the result hash table.
1882 lpfc_sha_iterate(uint32_t * HashResultPointer
, uint32_t * HashWorkingPointer
)
1886 uint32_t A
, B
, C
, D
, E
;
1889 HashWorkingPointer
[t
] =
1891 HashWorkingPointer
[t
- 3] ^ HashWorkingPointer
[t
-
1893 HashWorkingPointer
[t
- 14] ^ HashWorkingPointer
[t
- 16]);
1894 } while (++t
<= 79);
1896 A
= HashResultPointer
[0];
1897 B
= HashResultPointer
[1];
1898 C
= HashResultPointer
[2];
1899 D
= HashResultPointer
[3];
1900 E
= HashResultPointer
[4];
1904 TEMP
= ((B
& C
) | ((~B
) & D
)) + 0x5A827999;
1905 } else if (t
< 40) {
1906 TEMP
= (B
^ C
^ D
) + 0x6ED9EBA1;
1907 } else if (t
< 60) {
1908 TEMP
= ((B
& C
) | (B
& D
) | (C
& D
)) + 0x8F1BBCDC;
1910 TEMP
= (B
^ C
^ D
) + 0xCA62C1D6;
1912 TEMP
+= S(5, A
) + E
+ HashWorkingPointer
[t
];
1918 } while (++t
<= 79);
1920 HashResultPointer
[0] += A
;
1921 HashResultPointer
[1] += B
;
1922 HashResultPointer
[2] += C
;
1923 HashResultPointer
[3] += D
;
1924 HashResultPointer
[4] += E
;
1929 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
1930 * @RandomChallenge: pointer to the entry of host challenge random number array.
1931 * @HashWorking: pointer to the entry of the working hash array.
1933 * This routine calculates the working hash array referred by @HashWorking
1934 * from the challenge random numbers associated with the host, referred by
1935 * @RandomChallenge. The result is put into the entry of the working hash
1936 * array and returned by reference through @HashWorking.
1939 lpfc_challenge_key(uint32_t * RandomChallenge
, uint32_t * HashWorking
)
1941 *HashWorking
= (*RandomChallenge
^ *HashWorking
);
1945 * lpfc_hba_init - Perform special handling for LC HBA initialization
1946 * @phba: pointer to lpfc hba data structure.
1947 * @hbainit: pointer to an array of unsigned 32-bit integers.
1949 * This routine performs the special handling for LC HBA initialization.
1952 lpfc_hba_init(struct lpfc_hba
*phba
, uint32_t *hbainit
)
1955 uint32_t *HashWorking
;
1956 uint32_t *pwwnn
= (uint32_t *) phba
->wwnn
;
1958 HashWorking
= kcalloc(80, sizeof(uint32_t), GFP_KERNEL
);
1962 HashWorking
[0] = HashWorking
[78] = *pwwnn
++;
1963 HashWorking
[1] = HashWorking
[79] = *pwwnn
;
1965 for (t
= 0; t
< 7; t
++)
1966 lpfc_challenge_key(phba
->RandomData
+ t
, HashWorking
+ t
);
1968 lpfc_sha_init(hbainit
);
1969 lpfc_sha_iterate(hbainit
, HashWorking
);
1974 * lpfc_cleanup - Performs vport cleanups before deleting a vport
1975 * @vport: pointer to a virtual N_Port data structure.
1977 * This routine performs the necessary cleanups before deleting the @vport.
1978 * It invokes the discovery state machine to perform necessary state
1979 * transitions and to release the ndlps associated with the @vport. Note,
1980 * the physical port is treated as @vport 0.
1983 lpfc_cleanup(struct lpfc_vport
*vport
)
1985 struct lpfc_hba
*phba
= vport
->phba
;
1986 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
1989 if (phba
->link_state
> LPFC_LINK_DOWN
)
1990 lpfc_port_link_failure(vport
);
1992 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
1993 if (!NLP_CHK_NODE_ACT(ndlp
)) {
1994 ndlp
= lpfc_enable_node(vport
, ndlp
,
1995 NLP_STE_UNUSED_NODE
);
1998 spin_lock_irq(&phba
->ndlp_lock
);
1999 NLP_SET_FREE_REQ(ndlp
);
2000 spin_unlock_irq(&phba
->ndlp_lock
);
2001 /* Trigger the release of the ndlp memory */
2005 spin_lock_irq(&phba
->ndlp_lock
);
2006 if (NLP_CHK_FREE_REQ(ndlp
)) {
2007 /* The ndlp should not be in memory free mode already */
2008 spin_unlock_irq(&phba
->ndlp_lock
);
2011 /* Indicate request for freeing ndlp memory */
2012 NLP_SET_FREE_REQ(ndlp
);
2013 spin_unlock_irq(&phba
->ndlp_lock
);
2015 if (vport
->port_type
!= LPFC_PHYSICAL_PORT
&&
2016 ndlp
->nlp_DID
== Fabric_DID
) {
2017 /* Just free up ndlp with Fabric_DID for vports */
2022 if (ndlp
->nlp_type
& NLP_FABRIC
)
2023 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2024 NLP_EVT_DEVICE_RECOVERY
);
2026 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2031 /* At this point, ALL ndlp's should be gone
2032 * because of the previous NLP_EVT_DEVICE_RM.
2033 * Lets wait for this to happen, if needed.
2035 while (!list_empty(&vport
->fc_nodes
)) {
2037 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2038 "0233 Nodelist not empty\n");
2039 list_for_each_entry_safe(ndlp
, next_ndlp
,
2040 &vport
->fc_nodes
, nlp_listp
) {
2041 lpfc_printf_vlog(ndlp
->vport
, KERN_ERR
,
2043 "0282 did:x%x ndlp:x%p "
2044 "usgmap:x%x refcnt:%d\n",
2045 ndlp
->nlp_DID
, (void *)ndlp
,
2048 &ndlp
->kref
.refcount
));
2053 /* Wait for any activity on ndlps to settle */
2059 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2060 * @vport: pointer to a virtual N_Port data structure.
2062 * This routine stops all the timers associated with a @vport. This function
2063 * is invoked before disabling or deleting a @vport. Note that the physical
2064 * port is treated as @vport 0.
2067 lpfc_stop_vport_timers(struct lpfc_vport
*vport
)
2069 del_timer_sync(&vport
->els_tmofunc
);
2070 del_timer_sync(&vport
->fc_fdmitmo
);
2071 lpfc_can_disctmo(vport
);
2076 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2077 * @phba: pointer to lpfc hba data structure.
2079 * This routine stops all the timers associated with a HBA. This function is
2080 * invoked before either putting a HBA offline or unloading the driver.
2083 lpfc_stop_hba_timers(struct lpfc_hba
*phba
)
2085 lpfc_stop_vport_timers(phba
->pport
);
2086 del_timer_sync(&phba
->sli
.mbox_tmo
);
2087 del_timer_sync(&phba
->fabric_block_timer
);
2088 del_timer_sync(&phba
->eratt_poll
);
2089 del_timer_sync(&phba
->hb_tmofunc
);
2090 phba
->hb_outstanding
= 0;
2092 switch (phba
->pci_dev_grp
) {
2093 case LPFC_PCI_DEV_LP
:
2094 /* Stop any LightPulse device specific driver timers */
2095 del_timer_sync(&phba
->fcp_poll_timer
);
2097 case LPFC_PCI_DEV_OC
:
2098 /* Stop any OneConnect device sepcific driver timers */
2101 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2102 "0297 Invalid device group (x%x)\n",
2110 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
2111 * @phba: pointer to lpfc hba data structure.
2113 * This routine marks a HBA's management interface as blocked. Once the HBA's
2114 * management interface is marked as blocked, all the user space access to
2115 * the HBA, whether they are from sysfs interface or libdfc interface will
2116 * all be blocked. The HBA is set to block the management interface when the
2117 * driver prepares the HBA interface for online or offline.
2120 lpfc_block_mgmt_io(struct lpfc_hba
* phba
)
2122 unsigned long iflag
;
2124 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2125 phba
->sli
.sli_flag
|= LPFC_BLOCK_MGMT_IO
;
2126 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2130 * lpfc_online - Initialize and bring a HBA online
2131 * @phba: pointer to lpfc hba data structure.
2133 * This routine initializes the HBA and brings a HBA online. During this
2134 * process, the management interface is blocked to prevent user space access
2135 * to the HBA interfering with the driver initialization.
2142 lpfc_online(struct lpfc_hba
*phba
)
2144 struct lpfc_vport
*vport
;
2145 struct lpfc_vport
**vports
;
2150 vport
= phba
->pport
;
2152 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
))
2155 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2156 "0458 Bring Adapter online\n");
2158 lpfc_block_mgmt_io(phba
);
2160 if (!lpfc_sli_queue_setup(phba
)) {
2161 lpfc_unblock_mgmt_io(phba
);
2165 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2166 if (lpfc_sli4_hba_setup(phba
)) { /* Initialize SLI4 HBA */
2167 lpfc_unblock_mgmt_io(phba
);
2171 if (lpfc_sli_hba_setup(phba
)) { /* Initialize SLI2/SLI3 HBA */
2172 lpfc_unblock_mgmt_io(phba
);
2177 vports
= lpfc_create_vport_work_array(phba
);
2179 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2180 struct Scsi_Host
*shost
;
2181 shost
= lpfc_shost_from_vport(vports
[i
]);
2182 spin_lock_irq(shost
->host_lock
);
2183 vports
[i
]->fc_flag
&= ~FC_OFFLINE_MODE
;
2184 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
2185 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2186 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2187 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
2188 spin_unlock_irq(shost
->host_lock
);
2190 lpfc_destroy_vport_work_array(phba
, vports
);
2192 lpfc_unblock_mgmt_io(phba
);
2197 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
2198 * @phba: pointer to lpfc hba data structure.
2200 * This routine marks a HBA's management interface as not blocked. Once the
2201 * HBA's management interface is marked as not blocked, all the user space
2202 * access to the HBA, whether they are from sysfs interface or libdfc
2203 * interface will be allowed. The HBA is set to block the management interface
2204 * when the driver prepares the HBA interface for online or offline and then
2205 * set to unblock the management interface afterwards.
2208 lpfc_unblock_mgmt_io(struct lpfc_hba
* phba
)
2210 unsigned long iflag
;
2212 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2213 phba
->sli
.sli_flag
&= ~LPFC_BLOCK_MGMT_IO
;
2214 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2218 * lpfc_offline_prep - Prepare a HBA to be brought offline
2219 * @phba: pointer to lpfc hba data structure.
2221 * This routine is invoked to prepare a HBA to be brought offline. It performs
2222 * unregistration login to all the nodes on all vports and flushes the mailbox
2223 * queue to make it ready to be brought offline.
2226 lpfc_offline_prep(struct lpfc_hba
* phba
)
2228 struct lpfc_vport
*vport
= phba
->pport
;
2229 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2230 struct lpfc_vport
**vports
;
2233 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
2236 lpfc_block_mgmt_io(phba
);
2238 lpfc_linkdown(phba
);
2240 /* Issue an unreg_login to all nodes on all vports */
2241 vports
= lpfc_create_vport_work_array(phba
);
2242 if (vports
!= NULL
) {
2243 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2244 struct Scsi_Host
*shost
;
2246 if (vports
[i
]->load_flag
& FC_UNLOADING
)
2248 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
2249 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2250 vports
[i
]->fc_flag
&= ~FC_VFI_REGISTERED
;
2252 shost
= lpfc_shost_from_vport(vports
[i
]);
2253 list_for_each_entry_safe(ndlp
, next_ndlp
,
2254 &vports
[i
]->fc_nodes
,
2256 if (!NLP_CHK_NODE_ACT(ndlp
))
2258 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
2260 if (ndlp
->nlp_type
& NLP_FABRIC
) {
2261 lpfc_disc_state_machine(vports
[i
], ndlp
,
2262 NULL
, NLP_EVT_DEVICE_RECOVERY
);
2263 lpfc_disc_state_machine(vports
[i
], ndlp
,
2264 NULL
, NLP_EVT_DEVICE_RM
);
2266 spin_lock_irq(shost
->host_lock
);
2267 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2268 spin_unlock_irq(shost
->host_lock
);
2269 lpfc_unreg_rpi(vports
[i
], ndlp
);
2273 lpfc_destroy_vport_work_array(phba
, vports
);
2275 lpfc_sli_mbox_sys_shutdown(phba
);
2279 * lpfc_offline - Bring a HBA offline
2280 * @phba: pointer to lpfc hba data structure.
2282 * This routine actually brings a HBA offline. It stops all the timers
2283 * associated with the HBA, brings down the SLI layer, and eventually
2284 * marks the HBA as in offline state for the upper layer protocol.
2287 lpfc_offline(struct lpfc_hba
*phba
)
2289 struct Scsi_Host
*shost
;
2290 struct lpfc_vport
**vports
;
2293 if (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
2296 /* stop port and all timers associated with this hba */
2297 lpfc_stop_port(phba
);
2298 vports
= lpfc_create_vport_work_array(phba
);
2300 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
2301 lpfc_stop_vport_timers(vports
[i
]);
2302 lpfc_destroy_vport_work_array(phba
, vports
);
2303 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2304 "0460 Bring Adapter offline\n");
2305 /* Bring down the SLI Layer and cleanup. The HBA is offline
2307 lpfc_sli_hba_down(phba
);
2308 spin_lock_irq(&phba
->hbalock
);
2310 spin_unlock_irq(&phba
->hbalock
);
2311 vports
= lpfc_create_vport_work_array(phba
);
2313 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2314 shost
= lpfc_shost_from_vport(vports
[i
]);
2315 spin_lock_irq(shost
->host_lock
);
2316 vports
[i
]->work_port_events
= 0;
2317 vports
[i
]->fc_flag
|= FC_OFFLINE_MODE
;
2318 spin_unlock_irq(shost
->host_lock
);
2320 lpfc_destroy_vport_work_array(phba
, vports
);
2324 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
2325 * @phba: pointer to lpfc hba data structure.
2327 * This routine is to free all the SCSI buffers and IOCBs from the driver
2328 * list back to kernel. It is called from lpfc_pci_remove_one to free
2329 * the internal resources before the device is removed from the system.
2332 * 0 - successful (for now, it always returns 0)
2335 lpfc_scsi_free(struct lpfc_hba
*phba
)
2337 struct lpfc_scsi_buf
*sb
, *sb_next
;
2338 struct lpfc_iocbq
*io
, *io_next
;
2340 spin_lock_irq(&phba
->hbalock
);
2341 /* Release all the lpfc_scsi_bufs maintained by this host. */
2342 spin_lock(&phba
->scsi_buf_list_lock
);
2343 list_for_each_entry_safe(sb
, sb_next
, &phba
->lpfc_scsi_buf_list
, list
) {
2344 list_del(&sb
->list
);
2345 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
, sb
->data
,
2348 phba
->total_scsi_bufs
--;
2350 spin_unlock(&phba
->scsi_buf_list_lock
);
2352 /* Release all the lpfc_iocbq entries maintained by this host. */
2353 list_for_each_entry_safe(io
, io_next
, &phba
->lpfc_iocb_list
, list
) {
2354 list_del(&io
->list
);
2356 phba
->total_iocbq_bufs
--;
2358 spin_unlock_irq(&phba
->hbalock
);
2363 * lpfc_create_port - Create an FC port
2364 * @phba: pointer to lpfc hba data structure.
2365 * @instance: a unique integer ID to this FC port.
2366 * @dev: pointer to the device data structure.
2368 * This routine creates a FC port for the upper layer protocol. The FC port
2369 * can be created on top of either a physical port or a virtual port provided
2370 * by the HBA. This routine also allocates a SCSI host data structure (shost)
2371 * and associates the FC port created before adding the shost into the SCSI
2375 * @vport - pointer to the virtual N_Port data structure.
2376 * NULL - port create failed.
2379 lpfc_create_port(struct lpfc_hba
*phba
, int instance
, struct device
*dev
)
2381 struct lpfc_vport
*vport
;
2382 struct Scsi_Host
*shost
;
2385 if (dev
!= &phba
->pcidev
->dev
)
2386 shost
= scsi_host_alloc(&lpfc_vport_template
,
2387 sizeof(struct lpfc_vport
));
2389 shost
= scsi_host_alloc(&lpfc_template
,
2390 sizeof(struct lpfc_vport
));
2394 vport
= (struct lpfc_vport
*) shost
->hostdata
;
2396 vport
->load_flag
|= FC_LOADING
;
2397 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2398 vport
->fc_rscn_flush
= 0;
2400 lpfc_get_vport_cfgparam(vport
);
2401 shost
->unique_id
= instance
;
2402 shost
->max_id
= LPFC_MAX_TARGET
;
2403 shost
->max_lun
= vport
->cfg_max_luns
;
2404 shost
->this_id
= -1;
2405 shost
->max_cmd_len
= 16;
2406 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2407 shost
->dma_boundary
= LPFC_SLI4_MAX_SEGMENT_SIZE
;
2408 shost
->sg_tablesize
= phba
->cfg_sg_seg_cnt
;
2412 * Set initial can_queue value since 0 is no longer supported and
2413 * scsi_add_host will fail. This will be adjusted later based on the
2414 * max xri value determined in hba setup.
2416 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
2417 if (dev
!= &phba
->pcidev
->dev
) {
2418 shost
->transportt
= lpfc_vport_transport_template
;
2419 vport
->port_type
= LPFC_NPIV_PORT
;
2421 shost
->transportt
= lpfc_transport_template
;
2422 vport
->port_type
= LPFC_PHYSICAL_PORT
;
2425 /* Initialize all internally managed lists. */
2426 INIT_LIST_HEAD(&vport
->fc_nodes
);
2427 INIT_LIST_HEAD(&vport
->rcv_buffer_list
);
2428 spin_lock_init(&vport
->work_port_lock
);
2430 init_timer(&vport
->fc_disctmo
);
2431 vport
->fc_disctmo
.function
= lpfc_disc_timeout
;
2432 vport
->fc_disctmo
.data
= (unsigned long)vport
;
2434 init_timer(&vport
->fc_fdmitmo
);
2435 vport
->fc_fdmitmo
.function
= lpfc_fdmi_tmo
;
2436 vport
->fc_fdmitmo
.data
= (unsigned long)vport
;
2438 init_timer(&vport
->els_tmofunc
);
2439 vport
->els_tmofunc
.function
= lpfc_els_timeout
;
2440 vport
->els_tmofunc
.data
= (unsigned long)vport
;
2442 error
= scsi_add_host_with_dma(shost
, dev
, &phba
->pcidev
->dev
);
2446 spin_lock_irq(&phba
->hbalock
);
2447 list_add_tail(&vport
->listentry
, &phba
->port_list
);
2448 spin_unlock_irq(&phba
->hbalock
);
2452 scsi_host_put(shost
);
2458 * destroy_port - destroy an FC port
2459 * @vport: pointer to an lpfc virtual N_Port data structure.
2461 * This routine destroys a FC port from the upper layer protocol. All the
2462 * resources associated with the port are released.
2465 destroy_port(struct lpfc_vport
*vport
)
2467 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2468 struct lpfc_hba
*phba
= vport
->phba
;
2470 lpfc_debugfs_terminate(vport
);
2471 fc_remove_host(shost
);
2472 scsi_remove_host(shost
);
2474 spin_lock_irq(&phba
->hbalock
);
2475 list_del_init(&vport
->listentry
);
2476 spin_unlock_irq(&phba
->hbalock
);
2478 lpfc_cleanup(vport
);
2483 * lpfc_get_instance - Get a unique integer ID
2485 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
2486 * uses the kernel idr facility to perform the task.
2489 * instance - a unique integer ID allocated as the new instance.
2490 * -1 - lpfc get instance failed.
2493 lpfc_get_instance(void)
2497 /* Assign an unused number */
2498 if (!idr_pre_get(&lpfc_hba_index
, GFP_KERNEL
))
2500 if (idr_get_new(&lpfc_hba_index
, NULL
, &instance
))
2506 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
2507 * @shost: pointer to SCSI host data structure.
2508 * @time: elapsed time of the scan in jiffies.
2510 * This routine is called by the SCSI layer with a SCSI host to determine
2511 * whether the scan host is finished.
2513 * Note: there is no scan_start function as adapter initialization will have
2514 * asynchronously kicked off the link initialization.
2517 * 0 - SCSI host scan is not over yet.
2518 * 1 - SCSI host scan is over.
2520 int lpfc_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
2522 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2523 struct lpfc_hba
*phba
= vport
->phba
;
2526 spin_lock_irq(shost
->host_lock
);
2528 if (vport
->load_flag
& FC_UNLOADING
) {
2532 if (time
>= 30 * HZ
) {
2533 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
2534 "0461 Scanning longer than 30 "
2535 "seconds. Continuing initialization\n");
2539 if (time
>= 15 * HZ
&& phba
->link_state
<= LPFC_LINK_DOWN
) {
2540 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
2541 "0465 Link down longer than 15 "
2542 "seconds. Continuing initialization\n");
2547 if (vport
->port_state
!= LPFC_VPORT_READY
)
2549 if (vport
->num_disc_nodes
|| vport
->fc_prli_sent
)
2551 if (vport
->fc_map_cnt
== 0 && time
< 2 * HZ
)
2553 if ((phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) != 0)
2559 spin_unlock_irq(shost
->host_lock
);
2564 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
2565 * @shost: pointer to SCSI host data structure.
2567 * This routine initializes a given SCSI host attributes on a FC port. The
2568 * SCSI host can be either on top of a physical port or a virtual port.
2570 void lpfc_host_attrib_init(struct Scsi_Host
*shost
)
2572 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
2573 struct lpfc_hba
*phba
= vport
->phba
;
2575 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
2578 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
2579 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
2580 fc_host_supported_classes(shost
) = FC_COS_CLASS3
;
2582 memset(fc_host_supported_fc4s(shost
), 0,
2583 sizeof(fc_host_supported_fc4s(shost
)));
2584 fc_host_supported_fc4s(shost
)[2] = 1;
2585 fc_host_supported_fc4s(shost
)[7] = 1;
2587 lpfc_vport_symbolic_node_name(vport
, fc_host_symbolic_name(shost
),
2588 sizeof fc_host_symbolic_name(shost
));
2590 fc_host_supported_speeds(shost
) = 0;
2591 if (phba
->lmt
& LMT_10Gb
)
2592 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_10GBIT
;
2593 if (phba
->lmt
& LMT_8Gb
)
2594 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_8GBIT
;
2595 if (phba
->lmt
& LMT_4Gb
)
2596 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_4GBIT
;
2597 if (phba
->lmt
& LMT_2Gb
)
2598 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_2GBIT
;
2599 if (phba
->lmt
& LMT_1Gb
)
2600 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_1GBIT
;
2602 fc_host_maxframe_size(shost
) =
2603 (((uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
2604 (uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeLsb
;
2606 /* This value is also unchanging */
2607 memset(fc_host_active_fc4s(shost
), 0,
2608 sizeof(fc_host_active_fc4s(shost
)));
2609 fc_host_active_fc4s(shost
)[2] = 1;
2610 fc_host_active_fc4s(shost
)[7] = 1;
2612 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
2613 spin_lock_irq(shost
->host_lock
);
2614 vport
->load_flag
&= ~FC_LOADING
;
2615 spin_unlock_irq(shost
->host_lock
);
2619 * lpfc_stop_port_s3 - Stop SLI3 device port
2620 * @phba: pointer to lpfc hba data structure.
2622 * This routine is invoked to stop an SLI3 device port, it stops the device
2623 * from generating interrupts and stops the device driver's timers for the
2627 lpfc_stop_port_s3(struct lpfc_hba
*phba
)
2629 /* Clear all interrupt enable conditions */
2630 writel(0, phba
->HCregaddr
);
2631 readl(phba
->HCregaddr
); /* flush */
2632 /* Clear all pending interrupts */
2633 writel(0xffffffff, phba
->HAregaddr
);
2634 readl(phba
->HAregaddr
); /* flush */
2636 /* Reset some HBA SLI setup states */
2637 lpfc_stop_hba_timers(phba
);
2638 phba
->pport
->work_port_events
= 0;
2642 * lpfc_stop_port_s4 - Stop SLI4 device port
2643 * @phba: pointer to lpfc hba data structure.
2645 * This routine is invoked to stop an SLI4 device port, it stops the device
2646 * from generating interrupts and stops the device driver's timers for the
2650 lpfc_stop_port_s4(struct lpfc_hba
*phba
)
2652 /* Reset some HBA SLI4 setup states */
2653 lpfc_stop_hba_timers(phba
);
2654 phba
->pport
->work_port_events
= 0;
2655 phba
->sli4_hba
.intr_enable
= 0;
2656 /* Hard clear it for now, shall have more graceful way to wait later */
2657 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
2661 * lpfc_stop_port - Wrapper function for stopping hba port
2662 * @phba: Pointer to HBA context object.
2664 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
2665 * the API jump table function pointer from the lpfc_hba struct.
2668 lpfc_stop_port(struct lpfc_hba
*phba
)
2670 phba
->lpfc_stop_port(phba
);
2674 * lpfc_sli4_remove_dflt_fcf - Remove the driver default fcf record from the port.
2675 * @phba: pointer to lpfc hba data structure.
2677 * This routine is invoked to remove the driver default fcf record from
2678 * the port. This routine currently acts on FCF Index 0.
2682 lpfc_sli_remove_dflt_fcf(struct lpfc_hba
*phba
)
2685 LPFC_MBOXQ_t
*mboxq
;
2686 struct lpfc_mbx_del_fcf_tbl_entry
*del_fcf_record
;
2687 uint32_t mbox_tmo
, req_len
;
2688 uint32_t shdr_status
, shdr_add_status
;
2690 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2692 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2693 "2020 Failed to allocate mbox for ADD_FCF cmd\n");
2697 req_len
= sizeof(struct lpfc_mbx_del_fcf_tbl_entry
) -
2698 sizeof(struct lpfc_sli4_cfg_mhdr
);
2699 rc
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
2700 LPFC_MBOX_OPCODE_FCOE_DELETE_FCF
,
2701 req_len
, LPFC_SLI4_MBX_EMBED
);
2703 * In phase 1, there is a single FCF index, 0. In phase2, the driver
2704 * supports multiple FCF indices.
2706 del_fcf_record
= &mboxq
->u
.mqe
.un
.del_fcf_entry
;
2707 bf_set(lpfc_mbx_del_fcf_tbl_count
, del_fcf_record
, 1);
2708 bf_set(lpfc_mbx_del_fcf_tbl_index
, del_fcf_record
,
2709 phba
->fcf
.fcf_indx
);
2711 if (!phba
->sli4_hba
.intr_enable
)
2712 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
2714 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
2715 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
2717 /* The IOCTL status is embedded in the mailbox subheader. */
2718 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
2719 &del_fcf_record
->header
.cfg_shdr
.response
);
2720 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
2721 &del_fcf_record
->header
.cfg_shdr
.response
);
2722 if (shdr_status
|| shdr_add_status
|| rc
!= MBX_SUCCESS
) {
2723 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2724 "2516 DEL FCF of default FCF Index failed "
2725 "mbx status x%x, status x%x add_status x%x\n",
2726 rc
, shdr_status
, shdr_add_status
);
2728 if (rc
!= MBX_TIMEOUT
)
2729 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2733 * lpfc_sli4_fw_cfg_check - Read the firmware config and verify FCoE support
2734 * @phba: pointer to lpfc hba data structure.
2736 * This function uses the QUERY_FW_CFG mailbox command to determine if the
2737 * firmware loaded supports FCoE. A return of zero indicates that the mailbox
2738 * was successful and the firmware supports FCoE. Any other return indicates
2739 * a error. It is assumed that this function will be called before interrupts
2743 lpfc_sli4_fw_cfg_check(struct lpfc_hba
*phba
)
2746 LPFC_MBOXQ_t
*mboxq
;
2747 struct lpfc_mbx_query_fw_cfg
*query_fw_cfg
;
2749 uint32_t shdr_status
, shdr_add_status
;
2751 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2753 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2754 "2621 Failed to allocate mbox for "
2755 "query firmware config cmd\n");
2758 query_fw_cfg
= &mboxq
->u
.mqe
.un
.query_fw_cfg
;
2759 length
= (sizeof(struct lpfc_mbx_query_fw_cfg
) -
2760 sizeof(struct lpfc_sli4_cfg_mhdr
));
2761 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
2762 LPFC_MBOX_OPCODE_QUERY_FW_CFG
,
2763 length
, LPFC_SLI4_MBX_EMBED
);
2764 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
2765 /* The IOCTL status is embedded in the mailbox subheader. */
2766 shdr_status
= bf_get(lpfc_mbox_hdr_status
,
2767 &query_fw_cfg
->header
.cfg_shdr
.response
);
2768 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
2769 &query_fw_cfg
->header
.cfg_shdr
.response
);
2770 if (shdr_status
|| shdr_add_status
|| rc
!= MBX_SUCCESS
) {
2771 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2772 "2622 Query Firmware Config failed "
2773 "mbx status x%x, status x%x add_status x%x\n",
2774 rc
, shdr_status
, shdr_add_status
);
2777 if (!bf_get(lpfc_function_mode_fcoe_i
, query_fw_cfg
)) {
2778 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2779 "2623 FCoE Function not supported by firmware. "
2780 "Function mode = %08x\n",
2781 query_fw_cfg
->function_mode
);
2784 if (rc
!= MBX_TIMEOUT
)
2785 mempool_free(mboxq
, phba
->mbox_mem_pool
);
2790 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
2791 * @phba: pointer to lpfc hba data structure.
2792 * @acqe_link: pointer to the async link completion queue entry.
2794 * This routine is to parse the SLI4 link-attention link fault code and
2795 * translate it into the base driver's read link attention mailbox command
2798 * Return: Link-attention status in terms of base driver's coding.
2801 lpfc_sli4_parse_latt_fault(struct lpfc_hba
*phba
,
2802 struct lpfc_acqe_link
*acqe_link
)
2804 uint16_t latt_fault
;
2806 switch (bf_get(lpfc_acqe_link_fault
, acqe_link
)) {
2807 case LPFC_ASYNC_LINK_FAULT_NONE
:
2808 case LPFC_ASYNC_LINK_FAULT_LOCAL
:
2809 case LPFC_ASYNC_LINK_FAULT_REMOTE
:
2813 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2814 "0398 Invalid link fault code: x%x\n",
2815 bf_get(lpfc_acqe_link_fault
, acqe_link
));
2816 latt_fault
= MBXERR_ERROR
;
2823 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
2824 * @phba: pointer to lpfc hba data structure.
2825 * @acqe_link: pointer to the async link completion queue entry.
2827 * This routine is to parse the SLI4 link attention type and translate it
2828 * into the base driver's link attention type coding.
2830 * Return: Link attention type in terms of base driver's coding.
2833 lpfc_sli4_parse_latt_type(struct lpfc_hba
*phba
,
2834 struct lpfc_acqe_link
*acqe_link
)
2838 switch (bf_get(lpfc_acqe_link_status
, acqe_link
)) {
2839 case LPFC_ASYNC_LINK_STATUS_DOWN
:
2840 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN
:
2841 att_type
= AT_LINK_DOWN
;
2843 case LPFC_ASYNC_LINK_STATUS_UP
:
2844 /* Ignore physical link up events - wait for logical link up */
2845 att_type
= AT_RESERVED
;
2847 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP
:
2848 att_type
= AT_LINK_UP
;
2851 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2852 "0399 Invalid link attention type: x%x\n",
2853 bf_get(lpfc_acqe_link_status
, acqe_link
));
2854 att_type
= AT_RESERVED
;
2861 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
2862 * @phba: pointer to lpfc hba data structure.
2863 * @acqe_link: pointer to the async link completion queue entry.
2865 * This routine is to parse the SLI4 link-attention link speed and translate
2866 * it into the base driver's link-attention link speed coding.
2868 * Return: Link-attention link speed in terms of base driver's coding.
2871 lpfc_sli4_parse_latt_link_speed(struct lpfc_hba
*phba
,
2872 struct lpfc_acqe_link
*acqe_link
)
2876 switch (bf_get(lpfc_acqe_link_speed
, acqe_link
)) {
2877 case LPFC_ASYNC_LINK_SPEED_ZERO
:
2878 link_speed
= LA_UNKNW_LINK
;
2880 case LPFC_ASYNC_LINK_SPEED_10MBPS
:
2881 link_speed
= LA_UNKNW_LINK
;
2883 case LPFC_ASYNC_LINK_SPEED_100MBPS
:
2884 link_speed
= LA_UNKNW_LINK
;
2886 case LPFC_ASYNC_LINK_SPEED_1GBPS
:
2887 link_speed
= LA_1GHZ_LINK
;
2889 case LPFC_ASYNC_LINK_SPEED_10GBPS
:
2890 link_speed
= LA_10GHZ_LINK
;
2893 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2894 "0483 Invalid link-attention link speed: x%x\n",
2895 bf_get(lpfc_acqe_link_speed
, acqe_link
));
2896 link_speed
= LA_UNKNW_LINK
;
2903 * lpfc_sli4_async_link_evt - Process the asynchronous link event
2904 * @phba: pointer to lpfc hba data structure.
2905 * @acqe_link: pointer to the async link completion queue entry.
2907 * This routine is to handle the SLI4 asynchronous link event.
2910 lpfc_sli4_async_link_evt(struct lpfc_hba
*phba
,
2911 struct lpfc_acqe_link
*acqe_link
)
2913 struct lpfc_dmabuf
*mp
;
2919 att_type
= lpfc_sli4_parse_latt_type(phba
, acqe_link
);
2920 if (att_type
!= AT_LINK_DOWN
&& att_type
!= AT_LINK_UP
)
2922 phba
->fcoe_eventtag
= acqe_link
->event_tag
;
2923 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2925 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2926 "0395 The mboxq allocation failed\n");
2929 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2931 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2932 "0396 The lpfc_dmabuf allocation failed\n");
2935 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
2937 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2938 "0397 The mbuf allocation failed\n");
2939 goto out_free_dmabuf
;
2942 /* Cleanup any outstanding ELS commands */
2943 lpfc_els_flush_all_cmd(phba
);
2945 /* Block ELS IOCBs until we have done process link event */
2946 phba
->sli
.ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
2948 /* Update link event statistics */
2949 phba
->sli
.slistat
.link_event
++;
2951 /* Create pseudo lpfc_handle_latt mailbox command from link ACQE */
2952 lpfc_read_la(phba
, pmb
, mp
);
2953 pmb
->vport
= phba
->pport
;
2955 /* Parse and translate status field */
2957 mb
->mbxStatus
= lpfc_sli4_parse_latt_fault(phba
, acqe_link
);
2959 /* Parse and translate link attention fields */
2960 la
= (READ_LA_VAR
*) &pmb
->u
.mb
.un
.varReadLA
;
2961 la
->eventTag
= acqe_link
->event_tag
;
2962 la
->attType
= att_type
;
2963 la
->UlnkSpeed
= lpfc_sli4_parse_latt_link_speed(phba
, acqe_link
);
2965 /* Fake the the following irrelvant fields */
2966 la
->topology
= TOPOLOGY_PT_PT
;
2967 la
->granted_AL_PA
= 0;
2973 /* Keep the link status for extra SLI4 state machine reference */
2974 phba
->sli4_hba
.link_state
.speed
=
2975 bf_get(lpfc_acqe_link_speed
, acqe_link
);
2976 phba
->sli4_hba
.link_state
.duplex
=
2977 bf_get(lpfc_acqe_link_duplex
, acqe_link
);
2978 phba
->sli4_hba
.link_state
.status
=
2979 bf_get(lpfc_acqe_link_status
, acqe_link
);
2980 phba
->sli4_hba
.link_state
.physical
=
2981 bf_get(lpfc_acqe_link_physical
, acqe_link
);
2982 phba
->sli4_hba
.link_state
.fault
=
2983 bf_get(lpfc_acqe_link_fault
, acqe_link
);
2984 phba
->sli4_hba
.link_state
.logical_speed
=
2985 bf_get(lpfc_acqe_qos_link_speed
, acqe_link
);
2987 /* Invoke the lpfc_handle_latt mailbox command callback function */
2988 lpfc_mbx_cmpl_read_la(phba
, pmb
);
2995 mempool_free(pmb
, phba
->mbox_mem_pool
);
2999 * lpfc_sli4_async_fcoe_evt - Process the asynchronous fcoe event
3000 * @phba: pointer to lpfc hba data structure.
3001 * @acqe_link: pointer to the async fcoe completion queue entry.
3003 * This routine is to handle the SLI4 asynchronous fcoe event.
3006 lpfc_sli4_async_fcoe_evt(struct lpfc_hba
*phba
,
3007 struct lpfc_acqe_fcoe
*acqe_fcoe
)
3009 uint8_t event_type
= bf_get(lpfc_acqe_fcoe_event_type
, acqe_fcoe
);
3011 struct lpfc_vport
*vport
;
3012 struct lpfc_nodelist
*ndlp
;
3013 struct Scsi_Host
*shost
;
3014 uint32_t link_state
;
3015 int active_vlink_present
;
3016 struct lpfc_vport
**vports
;
3019 phba
->fc_eventTag
= acqe_fcoe
->event_tag
;
3020 phba
->fcoe_eventtag
= acqe_fcoe
->event_tag
;
3021 switch (event_type
) {
3022 case LPFC_FCOE_EVENT_TYPE_NEW_FCF
:
3023 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
3024 "2546 New FCF found index 0x%x tag 0x%x\n",
3026 acqe_fcoe
->event_tag
);
3028 * If the current FCF is in discovered state, or
3029 * FCF discovery is in progress do nothing.
3031 spin_lock_irq(&phba
->hbalock
);
3032 if ((phba
->fcf
.fcf_flag
& FCF_DISCOVERED
) ||
3033 (phba
->hba_flag
& FCF_DISC_INPROGRESS
)) {
3034 spin_unlock_irq(&phba
->hbalock
);
3037 spin_unlock_irq(&phba
->hbalock
);
3039 /* Read the FCF table and re-discover SAN. */
3040 rc
= lpfc_sli4_read_fcf_record(phba
, LPFC_FCOE_FCF_GET_FIRST
);
3042 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
3043 "2547 Read FCF record failed 0x%x\n",
3047 case LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL
:
3048 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3049 "2548 FCF Table full count 0x%x tag 0x%x\n",
3050 bf_get(lpfc_acqe_fcoe_fcf_count
, acqe_fcoe
),
3051 acqe_fcoe
->event_tag
);
3054 case LPFC_FCOE_EVENT_TYPE_FCF_DEAD
:
3055 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
3056 "2549 FCF disconnected from network index 0x%x"
3057 " tag 0x%x\n", acqe_fcoe
->index
,
3058 acqe_fcoe
->event_tag
);
3059 /* If the event is not for currently used fcf do nothing */
3060 if (phba
->fcf
.fcf_indx
!= acqe_fcoe
->index
)
3063 * Currently, driver support only one FCF - so treat this as
3064 * a link down, but save the link state because we don't want
3065 * it to be changed to Link Down unless it is already down.
3067 link_state
= phba
->link_state
;
3068 lpfc_linkdown(phba
);
3069 phba
->link_state
= link_state
;
3070 /* Unregister FCF if no devices connected to it */
3071 lpfc_unregister_unused_fcf(phba
);
3073 case LPFC_FCOE_EVENT_TYPE_CVL
:
3074 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
3075 "2718 Clear Virtual Link Received for VPI 0x%x"
3076 " tag 0x%x\n", acqe_fcoe
->index
, acqe_fcoe
->event_tag
);
3077 vport
= lpfc_find_vport_by_vpid(phba
,
3078 acqe_fcoe
->index
- phba
->vpi_base
);
3081 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
3084 shost
= lpfc_shost_from_vport(vport
);
3085 if (phba
->pport
->port_state
<= LPFC_FLOGI
)
3087 /* If virtual link is not yet instantiated ignore CVL */
3088 if (vport
->port_state
<= LPFC_FDISC
)
3091 lpfc_linkdown_port(vport
);
3092 lpfc_cleanup_pending_mbox(vport
);
3093 spin_lock_irq(shost
->host_lock
);
3094 vport
->fc_flag
|= FC_VPORT_CVL_RCVD
;
3095 spin_unlock_irq(shost
->host_lock
);
3096 active_vlink_present
= 0;
3098 vports
= lpfc_create_vport_work_array(phba
);
3100 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
3102 if ((!(vports
[i
]->fc_flag
&
3103 FC_VPORT_CVL_RCVD
)) &&
3104 (vports
[i
]->port_state
> LPFC_FDISC
)) {
3105 active_vlink_present
= 1;
3109 lpfc_destroy_vport_work_array(phba
, vports
);
3112 if (active_vlink_present
) {
3114 * If there are other active VLinks present,
3115 * re-instantiate the Vlink using FDISC.
3117 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ HZ
);
3118 spin_lock_irq(shost
->host_lock
);
3119 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
3120 spin_unlock_irq(shost
->host_lock
);
3121 ndlp
->nlp_last_elscmd
= ELS_CMD_FDISC
;
3122 vport
->port_state
= LPFC_FDISC
;
3124 lpfc_retry_pport_discovery(phba
);
3128 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3129 "0288 Unknown FCoE event type 0x%x event tag "
3130 "0x%x\n", event_type
, acqe_fcoe
->event_tag
);
3136 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
3137 * @phba: pointer to lpfc hba data structure.
3138 * @acqe_link: pointer to the async dcbx completion queue entry.
3140 * This routine is to handle the SLI4 asynchronous dcbx event.
3143 lpfc_sli4_async_dcbx_evt(struct lpfc_hba
*phba
,
3144 struct lpfc_acqe_dcbx
*acqe_dcbx
)
3146 phba
->fc_eventTag
= acqe_dcbx
->event_tag
;
3147 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3148 "0290 The SLI4 DCBX asynchronous event is not "
3153 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
3154 * @phba: pointer to lpfc hba data structure.
3156 * This routine is invoked by the worker thread to process all the pending
3157 * SLI4 asynchronous events.
3159 void lpfc_sli4_async_event_proc(struct lpfc_hba
*phba
)
3161 struct lpfc_cq_event
*cq_event
;
3163 /* First, declare the async event has been handled */
3164 spin_lock_irq(&phba
->hbalock
);
3165 phba
->hba_flag
&= ~ASYNC_EVENT
;
3166 spin_unlock_irq(&phba
->hbalock
);
3167 /* Now, handle all the async events */
3168 while (!list_empty(&phba
->sli4_hba
.sp_asynce_work_queue
)) {
3169 /* Get the first event from the head of the event queue */
3170 spin_lock_irq(&phba
->hbalock
);
3171 list_remove_head(&phba
->sli4_hba
.sp_asynce_work_queue
,
3172 cq_event
, struct lpfc_cq_event
, list
);
3173 spin_unlock_irq(&phba
->hbalock
);
3174 /* Process the asynchronous event */
3175 switch (bf_get(lpfc_trailer_code
, &cq_event
->cqe
.mcqe_cmpl
)) {
3176 case LPFC_TRAILER_CODE_LINK
:
3177 lpfc_sli4_async_link_evt(phba
,
3178 &cq_event
->cqe
.acqe_link
);
3180 case LPFC_TRAILER_CODE_FCOE
:
3181 lpfc_sli4_async_fcoe_evt(phba
,
3182 &cq_event
->cqe
.acqe_fcoe
);
3184 case LPFC_TRAILER_CODE_DCBX
:
3185 lpfc_sli4_async_dcbx_evt(phba
,
3186 &cq_event
->cqe
.acqe_dcbx
);
3189 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3190 "1804 Invalid asynchrous event code: "
3191 "x%x\n", bf_get(lpfc_trailer_code
,
3192 &cq_event
->cqe
.mcqe_cmpl
));
3195 /* Free the completion event processed to the free pool */
3196 lpfc_sli4_cq_event_release(phba
, cq_event
);
3201 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
3202 * @phba: pointer to lpfc hba data structure.
3203 * @dev_grp: The HBA PCI-Device group number.
3205 * This routine is invoked to set up the per HBA PCI-Device group function
3206 * API jump table entries.
3208 * Return: 0 if success, otherwise -ENODEV
3211 lpfc_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
3215 /* Set up lpfc PCI-device group */
3216 phba
->pci_dev_grp
= dev_grp
;
3218 /* The LPFC_PCI_DEV_OC uses SLI4 */
3219 if (dev_grp
== LPFC_PCI_DEV_OC
)
3220 phba
->sli_rev
= LPFC_SLI_REV4
;
3222 /* Set up device INIT API function jump table */
3223 rc
= lpfc_init_api_table_setup(phba
, dev_grp
);
3226 /* Set up SCSI API function jump table */
3227 rc
= lpfc_scsi_api_table_setup(phba
, dev_grp
);
3230 /* Set up SLI API function jump table */
3231 rc
= lpfc_sli_api_table_setup(phba
, dev_grp
);
3234 /* Set up MBOX API function jump table */
3235 rc
= lpfc_mbox_api_table_setup(phba
, dev_grp
);
3243 * lpfc_log_intr_mode - Log the active interrupt mode
3244 * @phba: pointer to lpfc hba data structure.
3245 * @intr_mode: active interrupt mode adopted.
3247 * This routine it invoked to log the currently used active interrupt mode
3250 static void lpfc_log_intr_mode(struct lpfc_hba
*phba
, uint32_t intr_mode
)
3252 switch (intr_mode
) {
3254 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3255 "0470 Enable INTx interrupt mode.\n");
3258 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3259 "0481 Enabled MSI interrupt mode.\n");
3262 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3263 "0480 Enabled MSI-X interrupt mode.\n");
3266 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3267 "0482 Illegal interrupt mode.\n");
3274 * lpfc_enable_pci_dev - Enable a generic PCI device.
3275 * @phba: pointer to lpfc hba data structure.
3277 * This routine is invoked to enable the PCI device that is common to all
3282 * other values - error
3285 lpfc_enable_pci_dev(struct lpfc_hba
*phba
)
3287 struct pci_dev
*pdev
;
3290 /* Obtain PCI device reference */
3294 pdev
= phba
->pcidev
;
3295 /* Select PCI BARs */
3296 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
3297 /* Enable PCI device */
3298 if (pci_enable_device_mem(pdev
))
3300 /* Request PCI resource for the device */
3301 if (pci_request_selected_regions(pdev
, bars
, LPFC_DRIVER_NAME
))
3302 goto out_disable_device
;
3303 /* Set up device as PCI master and save state for EEH */
3304 pci_set_master(pdev
);
3305 pci_try_set_mwi(pdev
);
3306 pci_save_state(pdev
);
3311 pci_disable_device(pdev
);
3317 * lpfc_disable_pci_dev - Disable a generic PCI device.
3318 * @phba: pointer to lpfc hba data structure.
3320 * This routine is invoked to disable the PCI device that is common to all
3324 lpfc_disable_pci_dev(struct lpfc_hba
*phba
)
3326 struct pci_dev
*pdev
;
3329 /* Obtain PCI device reference */
3333 pdev
= phba
->pcidev
;
3334 /* Select PCI BARs */
3335 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
3336 /* Release PCI resource and disable PCI device */
3337 pci_release_selected_regions(pdev
, bars
);
3338 pci_disable_device(pdev
);
3339 /* Null out PCI private reference to driver */
3340 pci_set_drvdata(pdev
, NULL
);
3346 * lpfc_reset_hba - Reset a hba
3347 * @phba: pointer to lpfc hba data structure.
3349 * This routine is invoked to reset a hba device. It brings the HBA
3350 * offline, performs a board restart, and then brings the board back
3351 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
3352 * on outstanding mailbox commands.
3355 lpfc_reset_hba(struct lpfc_hba
*phba
)
3357 /* If resets are disabled then set error state and return. */
3358 if (!phba
->cfg_enable_hba_reset
) {
3359 phba
->link_state
= LPFC_HBA_ERROR
;
3362 lpfc_offline_prep(phba
);
3364 lpfc_sli_brdrestart(phba
);
3366 lpfc_unblock_mgmt_io(phba
);
3370 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
3371 * @phba: pointer to lpfc hba data structure.
3373 * This routine is invoked to set up the driver internal resources specific to
3374 * support the SLI-3 HBA device it attached to.
3378 * other values - error
3381 lpfc_sli_driver_resource_setup(struct lpfc_hba
*phba
)
3383 struct lpfc_sli
*psli
;
3386 * Initialize timers used by driver
3389 /* Heartbeat timer */
3390 init_timer(&phba
->hb_tmofunc
);
3391 phba
->hb_tmofunc
.function
= lpfc_hb_timeout
;
3392 phba
->hb_tmofunc
.data
= (unsigned long)phba
;
3395 /* MBOX heartbeat timer */
3396 init_timer(&psli
->mbox_tmo
);
3397 psli
->mbox_tmo
.function
= lpfc_mbox_timeout
;
3398 psli
->mbox_tmo
.data
= (unsigned long) phba
;
3399 /* FCP polling mode timer */
3400 init_timer(&phba
->fcp_poll_timer
);
3401 phba
->fcp_poll_timer
.function
= lpfc_poll_timeout
;
3402 phba
->fcp_poll_timer
.data
= (unsigned long) phba
;
3403 /* Fabric block timer */
3404 init_timer(&phba
->fabric_block_timer
);
3405 phba
->fabric_block_timer
.function
= lpfc_fabric_block_timeout
;
3406 phba
->fabric_block_timer
.data
= (unsigned long) phba
;
3407 /* EA polling mode timer */
3408 init_timer(&phba
->eratt_poll
);
3409 phba
->eratt_poll
.function
= lpfc_poll_eratt
;
3410 phba
->eratt_poll
.data
= (unsigned long) phba
;
3412 /* Host attention work mask setup */
3413 phba
->work_ha_mask
= (HA_ERATT
| HA_MBATT
| HA_LATT
);
3414 phba
->work_ha_mask
|= (HA_RXMASK
<< (LPFC_ELS_RING
* 4));
3416 /* Get all the module params for configuring this host */
3417 lpfc_get_cfgparam(phba
);
3419 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
3420 * used to create the sg_dma_buf_pool must be dynamically calculated.
3421 * 2 segments are added since the IOCB needs a command and response bde.
3423 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
3424 sizeof(struct fcp_rsp
) +
3425 ((phba
->cfg_sg_seg_cnt
+ 2) * sizeof(struct ulp_bde64
));
3427 if (phba
->cfg_enable_bg
) {
3428 phba
->cfg_sg_seg_cnt
= LPFC_MAX_SG_SEG_CNT
;
3429 phba
->cfg_sg_dma_buf_size
+=
3430 phba
->cfg_prot_sg_seg_cnt
* sizeof(struct ulp_bde64
);
3433 /* Also reinitialize the host templates with new values. */
3434 lpfc_vport_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
3435 lpfc_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
3437 phba
->max_vpi
= LPFC_MAX_VPI
;
3438 /* This will be set to correct value after config_port mbox */
3439 phba
->max_vports
= 0;
3442 * Initialize the SLI Layer to run with lpfc HBAs.
3444 lpfc_sli_setup(phba
);
3445 lpfc_sli_queue_setup(phba
);
3447 /* Allocate device driver memory */
3448 if (lpfc_mem_alloc(phba
, BPL_ALIGN_SZ
))
3455 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
3456 * @phba: pointer to lpfc hba data structure.
3458 * This routine is invoked to unset the driver internal resources set up
3459 * specific for supporting the SLI-3 HBA device it attached to.
3462 lpfc_sli_driver_resource_unset(struct lpfc_hba
*phba
)
3464 /* Free device driver memory allocated */
3465 lpfc_mem_free_all(phba
);
3471 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
3472 * @phba: pointer to lpfc hba data structure.
3474 * This routine is invoked to set up the driver internal resources specific to
3475 * support the SLI-4 HBA device it attached to.
3479 * other values - error
3482 lpfc_sli4_driver_resource_setup(struct lpfc_hba
*phba
)
3484 struct lpfc_sli
*psli
;
3488 /* Before proceed, wait for POST done and device ready */
3489 rc
= lpfc_sli4_post_status_check(phba
);
3494 * Initialize timers used by driver
3497 /* Heartbeat timer */
3498 init_timer(&phba
->hb_tmofunc
);
3499 phba
->hb_tmofunc
.function
= lpfc_hb_timeout
;
3500 phba
->hb_tmofunc
.data
= (unsigned long)phba
;
3503 /* MBOX heartbeat timer */
3504 init_timer(&psli
->mbox_tmo
);
3505 psli
->mbox_tmo
.function
= lpfc_mbox_timeout
;
3506 psli
->mbox_tmo
.data
= (unsigned long) phba
;
3507 /* Fabric block timer */
3508 init_timer(&phba
->fabric_block_timer
);
3509 phba
->fabric_block_timer
.function
= lpfc_fabric_block_timeout
;
3510 phba
->fabric_block_timer
.data
= (unsigned long) phba
;
3511 /* EA polling mode timer */
3512 init_timer(&phba
->eratt_poll
);
3513 phba
->eratt_poll
.function
= lpfc_poll_eratt
;
3514 phba
->eratt_poll
.data
= (unsigned long) phba
;
3516 * We need to do a READ_CONFIG mailbox command here before
3517 * calling lpfc_get_cfgparam. For VFs this will report the
3518 * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
3519 * All of the resources allocated
3520 * for this Port are tied to these values.
3522 /* Get all the module params for configuring this host */
3523 lpfc_get_cfgparam(phba
);
3524 phba
->max_vpi
= LPFC_MAX_VPI
;
3525 /* This will be set to correct value after the read_config mbox */
3526 phba
->max_vports
= 0;
3528 /* Program the default value of vlan_id and fc_map */
3529 phba
->valid_vlan
= 0;
3530 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
3531 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
3532 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
3535 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
3536 * used to create the sg_dma_buf_pool must be dynamically calculated.
3537 * 2 segments are added since the IOCB needs a command and response bde.
3538 * To insure that the scsi sgl does not cross a 4k page boundary only
3539 * sgl sizes of 1k, 2k, 4k, and 8k are supported.
3540 * Table of sgl sizes and seg_cnt:
3541 * sgl size, sg_seg_cnt total seg
3546 * cmd(32) + rsp(160) + (52 * sizeof(sli4_sge)) = 1024
3547 * cmd(32) + rsp(160) + (116 * sizeof(sli4_sge)) = 2048
3548 * cmd(32) + rsp(160) + (244 * sizeof(sli4_sge)) = 4096
3549 * cmd(32) + rsp(160) + (500 * sizeof(sli4_sge)) = 8192
3551 if (phba
->cfg_sg_seg_cnt
<= LPFC_DEFAULT_SG_SEG_CNT
)
3552 phba
->cfg_sg_seg_cnt
= 50;
3553 else if (phba
->cfg_sg_seg_cnt
<= 114)
3554 phba
->cfg_sg_seg_cnt
= 114;
3555 else if (phba
->cfg_sg_seg_cnt
<= 242)
3556 phba
->cfg_sg_seg_cnt
= 242;
3558 phba
->cfg_sg_seg_cnt
= 498;
3560 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
)
3561 + sizeof(struct fcp_rsp
);
3562 phba
->cfg_sg_dma_buf_size
+=
3563 ((phba
->cfg_sg_seg_cnt
+ 2) * sizeof(struct sli4_sge
));
3565 /* Initialize buffer queue management fields */
3566 hbq_count
= lpfc_sli_hbq_count();
3567 for (i
= 0; i
< hbq_count
; ++i
)
3568 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
3569 INIT_LIST_HEAD(&phba
->rb_pend_list
);
3570 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_sli4_rb_alloc
;
3571 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_sli4_rb_free
;
3574 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
3576 /* Initialize the Abort scsi buffer list used by driver */
3577 spin_lock_init(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
3578 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
3579 /* This abort list used by worker thread */
3580 spin_lock_init(&phba
->sli4_hba
.abts_sgl_list_lock
);
3583 * Initialize dirver internal slow-path work queues
3586 /* Driver internel slow-path CQ Event pool */
3587 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_cqe_event_pool
);
3588 /* Response IOCB work queue list */
3589 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_queue_event
);
3590 /* Asynchronous event CQ Event work queue list */
3591 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_asynce_work_queue
);
3592 /* Fast-path XRI aborted CQ Event work queue list */
3593 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
3594 /* Slow-path XRI aborted CQ Event work queue list */
3595 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
3596 /* Receive queue CQ Event work queue list */
3597 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_unsol_work_queue
);
3599 /* Initialize the driver internal SLI layer lists. */
3600 lpfc_sli_setup(phba
);
3601 lpfc_sli_queue_setup(phba
);
3603 /* Allocate device driver memory */
3604 rc
= lpfc_mem_alloc(phba
, SGL_ALIGN_SZ
);
3608 /* Create the bootstrap mailbox command */
3609 rc
= lpfc_create_bootstrap_mbox(phba
);
3613 /* Set up the host's endian order with the device. */
3614 rc
= lpfc_setup_endian_order(phba
);
3616 goto out_free_bsmbx
;
3618 rc
= lpfc_sli4_fw_cfg_check(phba
);
3620 goto out_free_bsmbx
;
3622 /* Set up the hba's configuration parameters. */
3623 rc
= lpfc_sli4_read_config(phba
);
3625 goto out_free_bsmbx
;
3627 /* Perform a function reset */
3628 rc
= lpfc_pci_function_reset(phba
);
3630 goto out_free_bsmbx
;
3632 /* Create all the SLI4 queues */
3633 rc
= lpfc_sli4_queue_create(phba
);
3635 goto out_free_bsmbx
;
3637 /* Create driver internal CQE event pool */
3638 rc
= lpfc_sli4_cq_event_pool_create(phba
);
3640 goto out_destroy_queue
;
3642 /* Initialize and populate the iocb list per host */
3643 rc
= lpfc_init_sgl_list(phba
);
3645 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3646 "1400 Failed to initialize sgl list.\n");
3647 goto out_destroy_cq_event_pool
;
3649 rc
= lpfc_init_active_sgl_array(phba
);
3651 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3652 "1430 Failed to initialize sgl list.\n");
3653 goto out_free_sgl_list
;
3656 rc
= lpfc_sli4_init_rpi_hdrs(phba
);
3658 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3659 "1432 Failed to initialize rpi headers.\n");
3660 goto out_free_active_sgl
;
3663 phba
->sli4_hba
.fcp_eq_hdl
= kzalloc((sizeof(struct lpfc_fcp_eq_hdl
) *
3664 phba
->cfg_fcp_eq_count
), GFP_KERNEL
);
3665 if (!phba
->sli4_hba
.fcp_eq_hdl
) {
3666 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3667 "2572 Failed allocate memory for fast-path "
3668 "per-EQ handle array\n");
3669 goto out_remove_rpi_hdrs
;
3672 phba
->sli4_hba
.msix_entries
= kzalloc((sizeof(struct msix_entry
) *
3673 phba
->sli4_hba
.cfg_eqn
), GFP_KERNEL
);
3674 if (!phba
->sli4_hba
.msix_entries
) {
3675 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3676 "2573 Failed allocate memory for msi-x "
3677 "interrupt vector entries\n");
3678 goto out_free_fcp_eq_hdl
;
3683 out_free_fcp_eq_hdl
:
3684 kfree(phba
->sli4_hba
.fcp_eq_hdl
);
3685 out_remove_rpi_hdrs
:
3686 lpfc_sli4_remove_rpi_hdrs(phba
);
3687 out_free_active_sgl
:
3688 lpfc_free_active_sgl(phba
);
3690 lpfc_free_sgl_list(phba
);
3691 out_destroy_cq_event_pool
:
3692 lpfc_sli4_cq_event_pool_destroy(phba
);
3694 lpfc_sli4_queue_destroy(phba
);
3696 lpfc_destroy_bootstrap_mbox(phba
);
3698 lpfc_mem_free(phba
);
3703 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
3704 * @phba: pointer to lpfc hba data structure.
3706 * This routine is invoked to unset the driver internal resources set up
3707 * specific for supporting the SLI-4 HBA device it attached to.
3710 lpfc_sli4_driver_resource_unset(struct lpfc_hba
*phba
)
3712 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
3714 /* unregister default FCFI from the HBA */
3715 lpfc_sli4_fcfi_unreg(phba
, phba
->fcf
.fcfi
);
3717 /* Free the default FCR table */
3718 lpfc_sli_remove_dflt_fcf(phba
);
3720 /* Free memory allocated for msi-x interrupt vector entries */
3721 kfree(phba
->sli4_hba
.msix_entries
);
3723 /* Free memory allocated for fast-path work queue handles */
3724 kfree(phba
->sli4_hba
.fcp_eq_hdl
);
3726 /* Free the allocated rpi headers. */
3727 lpfc_sli4_remove_rpi_hdrs(phba
);
3728 lpfc_sli4_remove_rpis(phba
);
3730 /* Free the ELS sgl list */
3731 lpfc_free_active_sgl(phba
);
3732 lpfc_free_sgl_list(phba
);
3734 /* Free the SCSI sgl management array */
3735 kfree(phba
->sli4_hba
.lpfc_scsi_psb_array
);
3737 /* Free the SLI4 queues */
3738 lpfc_sli4_queue_destroy(phba
);
3740 /* Free the completion queue EQ event pool */
3741 lpfc_sli4_cq_event_release_all(phba
);
3742 lpfc_sli4_cq_event_pool_destroy(phba
);
3744 /* Reset SLI4 HBA FCoE function */
3745 lpfc_pci_function_reset(phba
);
3747 /* Free the bsmbx region. */
3748 lpfc_destroy_bootstrap_mbox(phba
);
3750 /* Free the SLI Layer memory with SLI4 HBAs */
3751 lpfc_mem_free_all(phba
);
3753 /* Free the current connect table */
3754 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
3755 &phba
->fcf_conn_rec_list
, list
) {
3756 list_del_init(&conn_entry
->list
);
3764 * lpfc_init_api_table_setup - Set up init api fucntion jump table
3765 * @phba: The hba struct for which this call is being executed.
3766 * @dev_grp: The HBA PCI-Device group number.
3768 * This routine sets up the device INIT interface API function jump table
3771 * Returns: 0 - success, -ENODEV - failure.
3774 lpfc_init_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
3777 case LPFC_PCI_DEV_LP
:
3778 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s3
;
3779 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s3
;
3780 phba
->lpfc_stop_port
= lpfc_stop_port_s3
;
3782 case LPFC_PCI_DEV_OC
:
3783 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s4
;
3784 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s4
;
3785 phba
->lpfc_stop_port
= lpfc_stop_port_s4
;
3788 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3789 "1431 Invalid HBA PCI-device group: 0x%x\n",
3798 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
3799 * @phba: pointer to lpfc hba data structure.
3801 * This routine is invoked to set up the driver internal resources before the
3802 * device specific resource setup to support the HBA device it attached to.
3806 * other values - error
3809 lpfc_setup_driver_resource_phase1(struct lpfc_hba
*phba
)
3812 * Driver resources common to all SLI revisions
3814 atomic_set(&phba
->fast_event_count
, 0);
3815 spin_lock_init(&phba
->hbalock
);
3817 /* Initialize ndlp management spinlock */
3818 spin_lock_init(&phba
->ndlp_lock
);
3820 INIT_LIST_HEAD(&phba
->port_list
);
3821 INIT_LIST_HEAD(&phba
->work_list
);
3822 init_waitqueue_head(&phba
->wait_4_mlo_m_q
);
3824 /* Initialize the wait queue head for the kernel thread */
3825 init_waitqueue_head(&phba
->work_waitq
);
3827 /* Initialize the scsi buffer list used by driver for scsi IO */
3828 spin_lock_init(&phba
->scsi_buf_list_lock
);
3829 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list
);
3831 /* Initialize the fabric iocb list */
3832 INIT_LIST_HEAD(&phba
->fabric_iocb_list
);
3834 /* Initialize list to save ELS buffers */
3835 INIT_LIST_HEAD(&phba
->elsbuf
);
3837 /* Initialize FCF connection rec list */
3838 INIT_LIST_HEAD(&phba
->fcf_conn_rec_list
);
3844 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
3845 * @phba: pointer to lpfc hba data structure.
3847 * This routine is invoked to set up the driver internal resources after the
3848 * device specific resource setup to support the HBA device it attached to.
3852 * other values - error
3855 lpfc_setup_driver_resource_phase2(struct lpfc_hba
*phba
)
3859 /* Startup the kernel thread for this host adapter. */
3860 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
3861 "lpfc_worker_%d", phba
->brd_no
);
3862 if (IS_ERR(phba
->worker_thread
)) {
3863 error
= PTR_ERR(phba
->worker_thread
);
3871 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
3872 * @phba: pointer to lpfc hba data structure.
3874 * This routine is invoked to unset the driver internal resources set up after
3875 * the device specific resource setup for supporting the HBA device it
3879 lpfc_unset_driver_resource_phase2(struct lpfc_hba
*phba
)
3881 /* Stop kernel worker thread */
3882 kthread_stop(phba
->worker_thread
);
3886 * lpfc_free_iocb_list - Free iocb list.
3887 * @phba: pointer to lpfc hba data structure.
3889 * This routine is invoked to free the driver's IOCB list and memory.
3892 lpfc_free_iocb_list(struct lpfc_hba
*phba
)
3894 struct lpfc_iocbq
*iocbq_entry
= NULL
, *iocbq_next
= NULL
;
3896 spin_lock_irq(&phba
->hbalock
);
3897 list_for_each_entry_safe(iocbq_entry
, iocbq_next
,
3898 &phba
->lpfc_iocb_list
, list
) {
3899 list_del(&iocbq_entry
->list
);
3901 phba
->total_iocbq_bufs
--;
3903 spin_unlock_irq(&phba
->hbalock
);
3909 * lpfc_init_iocb_list - Allocate and initialize iocb list.
3910 * @phba: pointer to lpfc hba data structure.
3912 * This routine is invoked to allocate and initizlize the driver's IOCB
3913 * list and set up the IOCB tag array accordingly.
3917 * other values - error
3920 lpfc_init_iocb_list(struct lpfc_hba
*phba
, int iocb_count
)
3922 struct lpfc_iocbq
*iocbq_entry
= NULL
;
3926 /* Initialize and populate the iocb list per host. */
3927 INIT_LIST_HEAD(&phba
->lpfc_iocb_list
);
3928 for (i
= 0; i
< iocb_count
; i
++) {
3929 iocbq_entry
= kzalloc(sizeof(struct lpfc_iocbq
), GFP_KERNEL
);
3930 if (iocbq_entry
== NULL
) {
3931 printk(KERN_ERR
"%s: only allocated %d iocbs of "
3932 "expected %d count. Unloading driver.\n",
3933 __func__
, i
, LPFC_IOCB_LIST_CNT
);
3934 goto out_free_iocbq
;
3937 iotag
= lpfc_sli_next_iotag(phba
, iocbq_entry
);
3940 printk(KERN_ERR
"%s: failed to allocate IOTAG. "
3941 "Unloading driver.\n", __func__
);
3942 goto out_free_iocbq
;
3944 iocbq_entry
->sli4_xritag
= NO_XRI
;
3946 spin_lock_irq(&phba
->hbalock
);
3947 list_add(&iocbq_entry
->list
, &phba
->lpfc_iocb_list
);
3948 phba
->total_iocbq_bufs
++;
3949 spin_unlock_irq(&phba
->hbalock
);
3955 lpfc_free_iocb_list(phba
);
3961 * lpfc_free_sgl_list - Free sgl list.
3962 * @phba: pointer to lpfc hba data structure.
3964 * This routine is invoked to free the driver's sgl list and memory.
3967 lpfc_free_sgl_list(struct lpfc_hba
*phba
)
3969 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
3970 LIST_HEAD(sglq_list
);
3973 spin_lock_irq(&phba
->hbalock
);
3974 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &sglq_list
);
3975 spin_unlock_irq(&phba
->hbalock
);
3977 list_for_each_entry_safe(sglq_entry
, sglq_next
,
3979 list_del(&sglq_entry
->list
);
3980 lpfc_mbuf_free(phba
, sglq_entry
->virt
, sglq_entry
->phys
);
3982 phba
->sli4_hba
.total_sglq_bufs
--;
3984 rc
= lpfc_sli4_remove_all_sgl_pages(phba
);
3986 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3987 "2005 Unable to deregister pages from HBA: %x\n", rc
);
3989 kfree(phba
->sli4_hba
.lpfc_els_sgl_array
);
3993 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
3994 * @phba: pointer to lpfc hba data structure.
3996 * This routine is invoked to allocate the driver's active sgl memory.
3997 * This array will hold the sglq_entry's for active IOs.
4000 lpfc_init_active_sgl_array(struct lpfc_hba
*phba
)
4003 size
= sizeof(struct lpfc_sglq
*);
4004 size
*= phba
->sli4_hba
.max_cfg_param
.max_xri
;
4006 phba
->sli4_hba
.lpfc_sglq_active_list
=
4007 kzalloc(size
, GFP_KERNEL
);
4008 if (!phba
->sli4_hba
.lpfc_sglq_active_list
)
4014 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
4015 * @phba: pointer to lpfc hba data structure.
4017 * This routine is invoked to walk through the array of active sglq entries
4018 * and free all of the resources.
4019 * This is just a place holder for now.
4022 lpfc_free_active_sgl(struct lpfc_hba
*phba
)
4024 kfree(phba
->sli4_hba
.lpfc_sglq_active_list
);
4028 * lpfc_init_sgl_list - Allocate and initialize sgl list.
4029 * @phba: pointer to lpfc hba data structure.
4031 * This routine is invoked to allocate and initizlize the driver's sgl
4032 * list and set up the sgl xritag tag array accordingly.
4036 * other values - error
4039 lpfc_init_sgl_list(struct lpfc_hba
*phba
)
4041 struct lpfc_sglq
*sglq_entry
= NULL
;
4045 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
4046 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4047 "2400 lpfc_init_sgl_list els %d.\n",
4049 /* Initialize and populate the sglq list per host/VF. */
4050 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_sgl_list
);
4051 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
4053 /* Sanity check on XRI management */
4054 if (phba
->sli4_hba
.max_cfg_param
.max_xri
<= els_xri_cnt
) {
4055 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4056 "2562 No room left for SCSI XRI allocation: "
4057 "max_xri=%d, els_xri=%d\n",
4058 phba
->sli4_hba
.max_cfg_param
.max_xri
,
4063 /* Allocate memory for the ELS XRI management array */
4064 phba
->sli4_hba
.lpfc_els_sgl_array
=
4065 kzalloc((sizeof(struct lpfc_sglq
*) * els_xri_cnt
),
4068 if (!phba
->sli4_hba
.lpfc_els_sgl_array
) {
4069 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4070 "2401 Failed to allocate memory for ELS "
4071 "XRI management array of size %d.\n",
4076 /* Keep the SCSI XRI into the XRI management array */
4077 phba
->sli4_hba
.scsi_xri_max
=
4078 phba
->sli4_hba
.max_cfg_param
.max_xri
- els_xri_cnt
;
4079 phba
->sli4_hba
.scsi_xri_cnt
= 0;
4081 phba
->sli4_hba
.lpfc_scsi_psb_array
=
4082 kzalloc((sizeof(struct lpfc_scsi_buf
*) *
4083 phba
->sli4_hba
.scsi_xri_max
), GFP_KERNEL
);
4085 if (!phba
->sli4_hba
.lpfc_scsi_psb_array
) {
4086 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4087 "2563 Failed to allocate memory for SCSI "
4088 "XRI management array of size %d.\n",
4089 phba
->sli4_hba
.scsi_xri_max
);
4090 kfree(phba
->sli4_hba
.lpfc_els_sgl_array
);
4094 for (i
= 0; i
< els_xri_cnt
; i
++) {
4095 sglq_entry
= kzalloc(sizeof(struct lpfc_sglq
), GFP_KERNEL
);
4096 if (sglq_entry
== NULL
) {
4097 printk(KERN_ERR
"%s: only allocated %d sgls of "
4098 "expected %d count. Unloading driver.\n",
4099 __func__
, i
, els_xri_cnt
);
4103 sglq_entry
->sli4_xritag
= lpfc_sli4_next_xritag(phba
);
4104 if (sglq_entry
->sli4_xritag
== NO_XRI
) {
4106 printk(KERN_ERR
"%s: failed to allocate XRI.\n"
4107 "Unloading driver.\n", __func__
);
4110 sglq_entry
->buff_type
= GEN_BUFF_TYPE
;
4111 sglq_entry
->virt
= lpfc_mbuf_alloc(phba
, 0, &sglq_entry
->phys
);
4112 if (sglq_entry
->virt
== NULL
) {
4114 printk(KERN_ERR
"%s: failed to allocate mbuf.\n"
4115 "Unloading driver.\n", __func__
);
4118 sglq_entry
->sgl
= sglq_entry
->virt
;
4119 memset(sglq_entry
->sgl
, 0, LPFC_BPL_SIZE
);
4121 /* The list order is used by later block SGL registraton */
4122 spin_lock_irq(&phba
->hbalock
);
4123 list_add_tail(&sglq_entry
->list
, &phba
->sli4_hba
.lpfc_sgl_list
);
4124 phba
->sli4_hba
.lpfc_els_sgl_array
[i
] = sglq_entry
;
4125 phba
->sli4_hba
.total_sglq_bufs
++;
4126 spin_unlock_irq(&phba
->hbalock
);
4131 kfree(phba
->sli4_hba
.lpfc_scsi_psb_array
);
4132 lpfc_free_sgl_list(phba
);
4137 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
4138 * @phba: pointer to lpfc hba data structure.
4140 * This routine is invoked to post rpi header templates to the
4141 * HBA consistent with the SLI-4 interface spec. This routine
4142 * posts a PAGE_SIZE memory region to the port to hold up to
4143 * PAGE_SIZE modulo 64 rpi context headers.
4144 * No locks are held here because this is an initialization routine
4145 * called only from probe or lpfc_online when interrupts are not
4146 * enabled and the driver is reinitializing the device.
4150 * ENOMEM - No availble memory
4151 * EIO - The mailbox failed to complete successfully.
4154 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba
*phba
)
4159 struct lpfc_rpi_hdr
*rpi_hdr
;
4161 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_hdr_list
);
4164 * Provision an rpi bitmask range for discovery. The total count
4165 * is the difference between max and base + 1.
4167 rpi_count
= phba
->sli4_hba
.max_cfg_param
.rpi_base
+
4168 phba
->sli4_hba
.max_cfg_param
.max_rpi
- 1;
4170 longs
= ((rpi_count
) + BITS_PER_LONG
- 1) / BITS_PER_LONG
;
4171 phba
->sli4_hba
.rpi_bmask
= kzalloc(longs
* sizeof(unsigned long),
4173 if (!phba
->sli4_hba
.rpi_bmask
)
4176 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
4178 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
4179 "0391 Error during rpi post operation\n");
4180 lpfc_sli4_remove_rpis(phba
);
4188 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
4189 * @phba: pointer to lpfc hba data structure.
4191 * This routine is invoked to allocate a single 4KB memory region to
4192 * support rpis and stores them in the phba. This single region
4193 * provides support for up to 64 rpis. The region is used globally
4197 * A valid rpi hdr on success.
4198 * A NULL pointer on any failure.
4200 struct lpfc_rpi_hdr
*
4201 lpfc_sli4_create_rpi_hdr(struct lpfc_hba
*phba
)
4203 uint16_t rpi_limit
, curr_rpi_range
;
4204 struct lpfc_dmabuf
*dmabuf
;
4205 struct lpfc_rpi_hdr
*rpi_hdr
;
4207 rpi_limit
= phba
->sli4_hba
.max_cfg_param
.rpi_base
+
4208 phba
->sli4_hba
.max_cfg_param
.max_rpi
- 1;
4210 spin_lock_irq(&phba
->hbalock
);
4211 curr_rpi_range
= phba
->sli4_hba
.next_rpi
;
4212 spin_unlock_irq(&phba
->hbalock
);
4215 * The port has a limited number of rpis. The increment here
4216 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
4217 * and to allow the full max_rpi range per port.
4219 if ((curr_rpi_range
+ (LPFC_RPI_HDR_COUNT
- 1)) > rpi_limit
)
4223 * First allocate the protocol header region for the port. The
4224 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
4226 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4230 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
4231 LPFC_HDR_TEMPLATE_SIZE
,
4234 if (!dmabuf
->virt
) {
4236 goto err_free_dmabuf
;
4239 memset(dmabuf
->virt
, 0, LPFC_HDR_TEMPLATE_SIZE
);
4240 if (!IS_ALIGNED(dmabuf
->phys
, LPFC_HDR_TEMPLATE_SIZE
)) {
4242 goto err_free_coherent
;
4245 /* Save the rpi header data for cleanup later. */
4246 rpi_hdr
= kzalloc(sizeof(struct lpfc_rpi_hdr
), GFP_KERNEL
);
4248 goto err_free_coherent
;
4250 rpi_hdr
->dmabuf
= dmabuf
;
4251 rpi_hdr
->len
= LPFC_HDR_TEMPLATE_SIZE
;
4252 rpi_hdr
->page_count
= 1;
4253 spin_lock_irq(&phba
->hbalock
);
4254 rpi_hdr
->start_rpi
= phba
->sli4_hba
.next_rpi
;
4255 list_add_tail(&rpi_hdr
->list
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
);
4258 * The next_rpi stores the next module-64 rpi value to post
4259 * in any subsequent rpi memory region postings.
4261 phba
->sli4_hba
.next_rpi
+= LPFC_RPI_HDR_COUNT
;
4262 spin_unlock_irq(&phba
->hbalock
);
4266 dma_free_coherent(&phba
->pcidev
->dev
, LPFC_HDR_TEMPLATE_SIZE
,
4267 dmabuf
->virt
, dmabuf
->phys
);
4274 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
4275 * @phba: pointer to lpfc hba data structure.
4277 * This routine is invoked to remove all memory resources allocated
4278 * to support rpis. This routine presumes the caller has released all
4279 * rpis consumed by fabric or port logins and is prepared to have
4280 * the header pages removed.
4283 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba
*phba
)
4285 struct lpfc_rpi_hdr
*rpi_hdr
, *next_rpi_hdr
;
4287 list_for_each_entry_safe(rpi_hdr
, next_rpi_hdr
,
4288 &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
4289 list_del(&rpi_hdr
->list
);
4290 dma_free_coherent(&phba
->pcidev
->dev
, rpi_hdr
->len
,
4291 rpi_hdr
->dmabuf
->virt
, rpi_hdr
->dmabuf
->phys
);
4292 kfree(rpi_hdr
->dmabuf
);
4296 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
4297 memset(phba
->sli4_hba
.rpi_bmask
, 0, sizeof(*phba
->sli4_hba
.rpi_bmask
));
4301 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
4302 * @pdev: pointer to pci device data structure.
4304 * This routine is invoked to allocate the driver hba data structure for an
4305 * HBA device. If the allocation is successful, the phba reference to the
4306 * PCI device data structure is set.
4309 * pointer to @phba - successful
4312 static struct lpfc_hba
*
4313 lpfc_hba_alloc(struct pci_dev
*pdev
)
4315 struct lpfc_hba
*phba
;
4317 /* Allocate memory for HBA structure */
4318 phba
= kzalloc(sizeof(struct lpfc_hba
), GFP_KERNEL
);
4320 dev_err(&pdev
->dev
, "failed to allocate hba struct\n");
4324 /* Set reference to PCI device in HBA structure */
4325 phba
->pcidev
= pdev
;
4327 /* Assign an unused board number */
4328 phba
->brd_no
= lpfc_get_instance();
4329 if (phba
->brd_no
< 0) {
4334 mutex_init(&phba
->ct_event_mutex
);
4335 INIT_LIST_HEAD(&phba
->ct_ev_waiters
);
4341 * lpfc_hba_free - Free driver hba data structure with a device.
4342 * @phba: pointer to lpfc hba data structure.
4344 * This routine is invoked to free the driver hba data structure with an
4348 lpfc_hba_free(struct lpfc_hba
*phba
)
4350 /* Release the driver assigned board number */
4351 idr_remove(&lpfc_hba_index
, phba
->brd_no
);
4358 * lpfc_create_shost - Create hba physical port with associated scsi host.
4359 * @phba: pointer to lpfc hba data structure.
4361 * This routine is invoked to create HBA physical port and associate a SCSI
4366 * other values - error
4369 lpfc_create_shost(struct lpfc_hba
*phba
)
4371 struct lpfc_vport
*vport
;
4372 struct Scsi_Host
*shost
;
4374 /* Initialize HBA FC structure */
4375 phba
->fc_edtov
= FF_DEF_EDTOV
;
4376 phba
->fc_ratov
= FF_DEF_RATOV
;
4377 phba
->fc_altov
= FF_DEF_ALTOV
;
4378 phba
->fc_arbtov
= FF_DEF_ARBTOV
;
4380 vport
= lpfc_create_port(phba
, phba
->brd_no
, &phba
->pcidev
->dev
);
4384 shost
= lpfc_shost_from_vport(vport
);
4385 phba
->pport
= vport
;
4386 lpfc_debugfs_initialize(vport
);
4387 /* Put reference to SCSI host to driver's device private data */
4388 pci_set_drvdata(phba
->pcidev
, shost
);
4394 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
4395 * @phba: pointer to lpfc hba data structure.
4397 * This routine is invoked to destroy HBA physical port and the associated
4401 lpfc_destroy_shost(struct lpfc_hba
*phba
)
4403 struct lpfc_vport
*vport
= phba
->pport
;
4405 /* Destroy physical port that associated with the SCSI host */
4406 destroy_port(vport
);
4412 * lpfc_setup_bg - Setup Block guard structures and debug areas.
4413 * @phba: pointer to lpfc hba data structure.
4414 * @shost: the shost to be used to detect Block guard settings.
4416 * This routine sets up the local Block guard protocol settings for @shost.
4417 * This routine also allocates memory for debugging bg buffers.
4420 lpfc_setup_bg(struct lpfc_hba
*phba
, struct Scsi_Host
*shost
)
4423 if (lpfc_prot_mask
&& lpfc_prot_guard
) {
4424 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4425 "1478 Registering BlockGuard with the "
4427 scsi_host_set_prot(shost
, lpfc_prot_mask
);
4428 scsi_host_set_guard(shost
, lpfc_prot_guard
);
4430 if (!_dump_buf_data
) {
4432 spin_lock_init(&_dump_buf_lock
);
4434 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
4435 if (_dump_buf_data
) {
4436 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4437 "9043 BLKGRD: allocated %d pages for "
4438 "_dump_buf_data at 0x%p\n",
4439 (1 << pagecnt
), _dump_buf_data
);
4440 _dump_buf_data_order
= pagecnt
;
4441 memset(_dump_buf_data
, 0,
4442 ((1 << PAGE_SHIFT
) << pagecnt
));
4447 if (!_dump_buf_data_order
)
4448 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4449 "9044 BLKGRD: ERROR unable to allocate "
4450 "memory for hexdump\n");
4452 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4453 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
4454 "\n", _dump_buf_data
);
4455 if (!_dump_buf_dif
) {
4458 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
4459 if (_dump_buf_dif
) {
4460 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4461 "9046 BLKGRD: allocated %d pages for "
4462 "_dump_buf_dif at 0x%p\n",
4463 (1 << pagecnt
), _dump_buf_dif
);
4464 _dump_buf_dif_order
= pagecnt
;
4465 memset(_dump_buf_dif
, 0,
4466 ((1 << PAGE_SHIFT
) << pagecnt
));
4471 if (!_dump_buf_dif_order
)
4472 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4473 "9047 BLKGRD: ERROR unable to allocate "
4474 "memory for hexdump\n");
4476 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
4477 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
4482 * lpfc_post_init_setup - Perform necessary device post initialization setup.
4483 * @phba: pointer to lpfc hba data structure.
4485 * This routine is invoked to perform all the necessary post initialization
4486 * setup for the device.
4489 lpfc_post_init_setup(struct lpfc_hba
*phba
)
4491 struct Scsi_Host
*shost
;
4492 struct lpfc_adapter_event_header adapter_event
;
4494 /* Get the default values for Model Name and Description */
4495 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
4498 * hba setup may have changed the hba_queue_depth so we need to
4499 * adjust the value of can_queue.
4501 shost
= pci_get_drvdata(phba
->pcidev
);
4502 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
4503 if (phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)
4504 lpfc_setup_bg(phba
, shost
);
4506 lpfc_host_attrib_init(shost
);
4508 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
4509 spin_lock_irq(shost
->host_lock
);
4510 lpfc_poll_start_timer(phba
);
4511 spin_unlock_irq(shost
->host_lock
);
4514 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4515 "0428 Perform SCSI scan\n");
4516 /* Send board arrival event to upper layer */
4517 adapter_event
.event_type
= FC_REG_ADAPTER_EVENT
;
4518 adapter_event
.subcategory
= LPFC_EVENT_ARRIVAL
;
4519 fc_host_post_vendor_event(shost
, fc_get_event_number(),
4520 sizeof(adapter_event
),
4521 (char *) &adapter_event
,
4527 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
4528 * @phba: pointer to lpfc hba data structure.
4530 * This routine is invoked to set up the PCI device memory space for device
4531 * with SLI-3 interface spec.
4535 * other values - error
4538 lpfc_sli_pci_mem_setup(struct lpfc_hba
*phba
)
4540 struct pci_dev
*pdev
;
4541 unsigned long bar0map_len
, bar2map_len
;
4544 int error
= -ENODEV
;
4546 /* Obtain PCI device reference */
4550 pdev
= phba
->pcidev
;
4552 /* Set the device DMA mask size */
4553 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
4554 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
4555 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
4556 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
4561 /* Get the bus address of Bar0 and Bar2 and the number of bytes
4562 * required by each mapping.
4564 phba
->pci_bar0_map
= pci_resource_start(pdev
, 0);
4565 bar0map_len
= pci_resource_len(pdev
, 0);
4567 phba
->pci_bar2_map
= pci_resource_start(pdev
, 2);
4568 bar2map_len
= pci_resource_len(pdev
, 2);
4570 /* Map HBA SLIM to a kernel virtual address. */
4571 phba
->slim_memmap_p
= ioremap(phba
->pci_bar0_map
, bar0map_len
);
4572 if (!phba
->slim_memmap_p
) {
4573 dev_printk(KERN_ERR
, &pdev
->dev
,
4574 "ioremap failed for SLIM memory.\n");
4578 /* Map HBA Control Registers to a kernel virtual address. */
4579 phba
->ctrl_regs_memmap_p
= ioremap(phba
->pci_bar2_map
, bar2map_len
);
4580 if (!phba
->ctrl_regs_memmap_p
) {
4581 dev_printk(KERN_ERR
, &pdev
->dev
,
4582 "ioremap failed for HBA control registers.\n");
4583 goto out_iounmap_slim
;
4586 /* Allocate memory for SLI-2 structures */
4587 phba
->slim2p
.virt
= dma_alloc_coherent(&pdev
->dev
,
4591 if (!phba
->slim2p
.virt
)
4594 memset(phba
->slim2p
.virt
, 0, SLI2_SLIM_SIZE
);
4595 phba
->mbox
= phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, mbx
);
4596 phba
->pcb
= (phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, pcb
));
4597 phba
->IOCBs
= (phba
->slim2p
.virt
+
4598 offsetof(struct lpfc_sli2_slim
, IOCBs
));
4600 phba
->hbqslimp
.virt
= dma_alloc_coherent(&pdev
->dev
,
4601 lpfc_sli_hbq_size(),
4602 &phba
->hbqslimp
.phys
,
4604 if (!phba
->hbqslimp
.virt
)
4607 hbq_count
= lpfc_sli_hbq_count();
4608 ptr
= phba
->hbqslimp
.virt
;
4609 for (i
= 0; i
< hbq_count
; ++i
) {
4610 phba
->hbqs
[i
].hbq_virt
= ptr
;
4611 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
4612 ptr
+= (lpfc_hbq_defs
[i
]->entry_count
*
4613 sizeof(struct lpfc_hbq_entry
));
4615 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_els_hbq_alloc
;
4616 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_els_hbq_free
;
4618 memset(phba
->hbqslimp
.virt
, 0, lpfc_sli_hbq_size());
4620 INIT_LIST_HEAD(&phba
->rb_pend_list
);
4622 phba
->MBslimaddr
= phba
->slim_memmap_p
;
4623 phba
->HAregaddr
= phba
->ctrl_regs_memmap_p
+ HA_REG_OFFSET
;
4624 phba
->CAregaddr
= phba
->ctrl_regs_memmap_p
+ CA_REG_OFFSET
;
4625 phba
->HSregaddr
= phba
->ctrl_regs_memmap_p
+ HS_REG_OFFSET
;
4626 phba
->HCregaddr
= phba
->ctrl_regs_memmap_p
+ HC_REG_OFFSET
;
4631 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
4632 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
4634 iounmap(phba
->ctrl_regs_memmap_p
);
4636 iounmap(phba
->slim_memmap_p
);
4642 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
4643 * @phba: pointer to lpfc hba data structure.
4645 * This routine is invoked to unset the PCI device memory space for device
4646 * with SLI-3 interface spec.
4649 lpfc_sli_pci_mem_unset(struct lpfc_hba
*phba
)
4651 struct pci_dev
*pdev
;
4653 /* Obtain PCI device reference */
4657 pdev
= phba
->pcidev
;
4659 /* Free coherent DMA memory allocated */
4660 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
4661 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
4662 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
4663 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
4665 /* I/O memory unmap */
4666 iounmap(phba
->ctrl_regs_memmap_p
);
4667 iounmap(phba
->slim_memmap_p
);
4673 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
4674 * @phba: pointer to lpfc hba data structure.
4676 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
4677 * done and check status.
4679 * Return 0 if successful, otherwise -ENODEV.
4682 lpfc_sli4_post_status_check(struct lpfc_hba
*phba
)
4684 struct lpfc_register sta_reg
, uerrlo_reg
, uerrhi_reg
, scratchpad
;
4685 int i
, port_error
= -ENODEV
;
4687 if (!phba
->sli4_hba
.STAregaddr
)
4690 /* Wait up to 30 seconds for the SLI Port POST done and ready */
4691 for (i
= 0; i
< 3000; i
++) {
4692 sta_reg
.word0
= readl(phba
->sli4_hba
.STAregaddr
);
4693 /* Encounter fatal POST error, break out */
4694 if (bf_get(lpfc_hst_state_perr
, &sta_reg
)) {
4695 port_error
= -ENODEV
;
4698 if (LPFC_POST_STAGE_ARMFW_READY
==
4699 bf_get(lpfc_hst_state_port_status
, &sta_reg
)) {
4707 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4708 "1408 Failure HBA POST Status: sta_reg=0x%x, "
4709 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, xrom=x%x, "
4710 "dl=x%x, pstatus=x%x\n", sta_reg
.word0
,
4711 bf_get(lpfc_hst_state_perr
, &sta_reg
),
4712 bf_get(lpfc_hst_state_sfi
, &sta_reg
),
4713 bf_get(lpfc_hst_state_nip
, &sta_reg
),
4714 bf_get(lpfc_hst_state_ipc
, &sta_reg
),
4715 bf_get(lpfc_hst_state_xrom
, &sta_reg
),
4716 bf_get(lpfc_hst_state_dl
, &sta_reg
),
4717 bf_get(lpfc_hst_state_port_status
, &sta_reg
));
4719 /* Log device information */
4720 scratchpad
.word0
= readl(phba
->sli4_hba
.SCRATCHPADregaddr
);
4721 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4722 "2534 Device Info: ChipType=0x%x, SliRev=0x%x, "
4723 "FeatureL1=0x%x, FeatureL2=0x%x\n",
4724 bf_get(lpfc_scratchpad_chiptype
, &scratchpad
),
4725 bf_get(lpfc_scratchpad_slirev
, &scratchpad
),
4726 bf_get(lpfc_scratchpad_featurelevel1
, &scratchpad
),
4727 bf_get(lpfc_scratchpad_featurelevel2
, &scratchpad
));
4728 phba
->sli4_hba
.ue_mask_lo
= readl(phba
->sli4_hba
.UEMASKLOregaddr
);
4729 phba
->sli4_hba
.ue_mask_hi
= readl(phba
->sli4_hba
.UEMASKHIregaddr
);
4730 /* With uncoverable error, log the error message and return error */
4731 uerrlo_reg
.word0
= readl(phba
->sli4_hba
.UERRLOregaddr
);
4732 uerrhi_reg
.word0
= readl(phba
->sli4_hba
.UERRHIregaddr
);
4733 if ((~phba
->sli4_hba
.ue_mask_lo
& uerrlo_reg
.word0
) ||
4734 (~phba
->sli4_hba
.ue_mask_hi
& uerrhi_reg
.word0
)) {
4735 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4736 "1422 HBA Unrecoverable error: "
4737 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
4738 "ue_mask_lo_reg=0x%x, ue_mask_hi_reg=0x%x\n",
4739 uerrlo_reg
.word0
, uerrhi_reg
.word0
,
4740 phba
->sli4_hba
.ue_mask_lo
,
4741 phba
->sli4_hba
.ue_mask_hi
);
4749 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
4750 * @phba: pointer to lpfc hba data structure.
4752 * This routine is invoked to set up SLI4 BAR0 PCI config space register
4756 lpfc_sli4_bar0_register_memmap(struct lpfc_hba
*phba
)
4758 phba
->sli4_hba
.UERRLOregaddr
= phba
->sli4_hba
.conf_regs_memmap_p
+
4759 LPFC_UERR_STATUS_LO
;
4760 phba
->sli4_hba
.UERRHIregaddr
= phba
->sli4_hba
.conf_regs_memmap_p
+
4761 LPFC_UERR_STATUS_HI
;
4762 phba
->sli4_hba
.UEMASKLOregaddr
= phba
->sli4_hba
.conf_regs_memmap_p
+
4764 phba
->sli4_hba
.UEMASKHIregaddr
= phba
->sli4_hba
.conf_regs_memmap_p
+
4766 phba
->sli4_hba
.SCRATCHPADregaddr
= phba
->sli4_hba
.conf_regs_memmap_p
+
4771 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
4772 * @phba: pointer to lpfc hba data structure.
4774 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
4778 lpfc_sli4_bar1_register_memmap(struct lpfc_hba
*phba
)
4781 phba
->sli4_hba
.STAregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
4783 phba
->sli4_hba
.ISRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
4785 phba
->sli4_hba
.IMRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
4787 phba
->sli4_hba
.ISCRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
4793 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
4794 * @phba: pointer to lpfc hba data structure.
4795 * @vf: virtual function number
4797 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
4798 * based on the given viftual function number, @vf.
4800 * Return 0 if successful, otherwise -ENODEV.
4803 lpfc_sli4_bar2_register_memmap(struct lpfc_hba
*phba
, uint32_t vf
)
4805 if (vf
> LPFC_VIR_FUNC_MAX
)
4808 phba
->sli4_hba
.RQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
4809 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_RQ_DOORBELL
);
4810 phba
->sli4_hba
.WQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
4811 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_WQ_DOORBELL
);
4812 phba
->sli4_hba
.EQCQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
4813 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_EQCQ_DOORBELL
);
4814 phba
->sli4_hba
.MQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
4815 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_MQ_DOORBELL
);
4816 phba
->sli4_hba
.BMBXregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
4817 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_BMBX
);
4822 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
4823 * @phba: pointer to lpfc hba data structure.
4825 * This routine is invoked to create the bootstrap mailbox
4826 * region consistent with the SLI-4 interface spec. This
4827 * routine allocates all memory necessary to communicate
4828 * mailbox commands to the port and sets up all alignment
4829 * needs. No locks are expected to be held when calling
4834 * ENOMEM - could not allocated memory.
4837 lpfc_create_bootstrap_mbox(struct lpfc_hba
*phba
)
4840 struct lpfc_dmabuf
*dmabuf
;
4841 struct dma_address
*dma_address
;
4845 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
4850 * The bootstrap mailbox region is comprised of 2 parts
4851 * plus an alignment restriction of 16 bytes.
4853 bmbx_size
= sizeof(struct lpfc_bmbx_create
) + (LPFC_ALIGN_16_BYTE
- 1);
4854 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
4858 if (!dmabuf
->virt
) {
4862 memset(dmabuf
->virt
, 0, bmbx_size
);
4865 * Initialize the bootstrap mailbox pointers now so that the register
4866 * operations are simple later. The mailbox dma address is required
4867 * to be 16-byte aligned. Also align the virtual memory as each
4868 * maibox is copied into the bmbx mailbox region before issuing the
4869 * command to the port.
4871 phba
->sli4_hba
.bmbx
.dmabuf
= dmabuf
;
4872 phba
->sli4_hba
.bmbx
.bmbx_size
= bmbx_size
;
4874 phba
->sli4_hba
.bmbx
.avirt
= PTR_ALIGN(dmabuf
->virt
,
4875 LPFC_ALIGN_16_BYTE
);
4876 phba
->sli4_hba
.bmbx
.aphys
= ALIGN(dmabuf
->phys
,
4877 LPFC_ALIGN_16_BYTE
);
4880 * Set the high and low physical addresses now. The SLI4 alignment
4881 * requirement is 16 bytes and the mailbox is posted to the port
4882 * as two 30-bit addresses. The other data is a bit marking whether
4883 * the 30-bit address is the high or low address.
4884 * Upcast bmbx aphys to 64bits so shift instruction compiles
4885 * clean on 32 bit machines.
4887 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
4888 phys_addr
= (uint64_t)phba
->sli4_hba
.bmbx
.aphys
;
4889 pa_addr
= (uint32_t) ((phys_addr
>> 34) & 0x3fffffff);
4890 dma_address
->addr_hi
= (uint32_t) ((pa_addr
<< 2) |
4891 LPFC_BMBX_BIT1_ADDR_HI
);
4893 pa_addr
= (uint32_t) ((phba
->sli4_hba
.bmbx
.aphys
>> 4) & 0x3fffffff);
4894 dma_address
->addr_lo
= (uint32_t) ((pa_addr
<< 2) |
4895 LPFC_BMBX_BIT1_ADDR_LO
);
4900 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
4901 * @phba: pointer to lpfc hba data structure.
4903 * This routine is invoked to teardown the bootstrap mailbox
4904 * region and release all host resources. This routine requires
4905 * the caller to ensure all mailbox commands recovered, no
4906 * additional mailbox comands are sent, and interrupts are disabled
4907 * before calling this routine.
4911 lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*phba
)
4913 dma_free_coherent(&phba
->pcidev
->dev
,
4914 phba
->sli4_hba
.bmbx
.bmbx_size
,
4915 phba
->sli4_hba
.bmbx
.dmabuf
->virt
,
4916 phba
->sli4_hba
.bmbx
.dmabuf
->phys
);
4918 kfree(phba
->sli4_hba
.bmbx
.dmabuf
);
4919 memset(&phba
->sli4_hba
.bmbx
, 0, sizeof(struct lpfc_bmbx
));
4923 * lpfc_sli4_read_config - Get the config parameters.
4924 * @phba: pointer to lpfc hba data structure.
4926 * This routine is invoked to read the configuration parameters from the HBA.
4927 * The configuration parameters are used to set the base and maximum values
4928 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
4929 * allocation for the port.
4933 * ENOMEM - No availble memory
4934 * EIO - The mailbox failed to complete successfully.
4937 lpfc_sli4_read_config(struct lpfc_hba
*phba
)
4940 struct lpfc_mbx_read_config
*rd_config
;
4943 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4945 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4946 "2011 Unable to allocate memory for issuing "
4947 "SLI_CONFIG_SPECIAL mailbox command\n");
4951 lpfc_read_config(phba
, pmb
);
4953 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
4954 if (rc
!= MBX_SUCCESS
) {
4955 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4956 "2012 Mailbox failed , mbxCmd x%x "
4957 "READ_CONFIG, mbxStatus x%x\n",
4958 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
4959 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
4962 rd_config
= &pmb
->u
.mqe
.un
.rd_config
;
4963 phba
->sli4_hba
.max_cfg_param
.max_xri
=
4964 bf_get(lpfc_mbx_rd_conf_xri_count
, rd_config
);
4965 phba
->sli4_hba
.max_cfg_param
.xri_base
=
4966 bf_get(lpfc_mbx_rd_conf_xri_base
, rd_config
);
4967 phba
->sli4_hba
.max_cfg_param
.max_vpi
=
4968 bf_get(lpfc_mbx_rd_conf_vpi_count
, rd_config
);
4969 phba
->sli4_hba
.max_cfg_param
.vpi_base
=
4970 bf_get(lpfc_mbx_rd_conf_vpi_base
, rd_config
);
4971 phba
->sli4_hba
.max_cfg_param
.max_rpi
=
4972 bf_get(lpfc_mbx_rd_conf_rpi_count
, rd_config
);
4973 phba
->sli4_hba
.max_cfg_param
.rpi_base
=
4974 bf_get(lpfc_mbx_rd_conf_rpi_base
, rd_config
);
4975 phba
->sli4_hba
.max_cfg_param
.max_vfi
=
4976 bf_get(lpfc_mbx_rd_conf_vfi_count
, rd_config
);
4977 phba
->sli4_hba
.max_cfg_param
.vfi_base
=
4978 bf_get(lpfc_mbx_rd_conf_vfi_base
, rd_config
);
4979 phba
->sli4_hba
.max_cfg_param
.max_fcfi
=
4980 bf_get(lpfc_mbx_rd_conf_fcfi_count
, rd_config
);
4981 phba
->sli4_hba
.max_cfg_param
.fcfi_base
=
4982 bf_get(lpfc_mbx_rd_conf_fcfi_base
, rd_config
);
4983 phba
->sli4_hba
.max_cfg_param
.max_eq
=
4984 bf_get(lpfc_mbx_rd_conf_eq_count
, rd_config
);
4985 phba
->sli4_hba
.max_cfg_param
.max_rq
=
4986 bf_get(lpfc_mbx_rd_conf_rq_count
, rd_config
);
4987 phba
->sli4_hba
.max_cfg_param
.max_wq
=
4988 bf_get(lpfc_mbx_rd_conf_wq_count
, rd_config
);
4989 phba
->sli4_hba
.max_cfg_param
.max_cq
=
4990 bf_get(lpfc_mbx_rd_conf_cq_count
, rd_config
);
4991 phba
->lmt
= bf_get(lpfc_mbx_rd_conf_lmt
, rd_config
);
4992 phba
->sli4_hba
.next_xri
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
4993 phba
->vpi_base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
4994 phba
->vfi_base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
4995 phba
->sli4_hba
.next_rpi
= phba
->sli4_hba
.max_cfg_param
.rpi_base
;
4996 phba
->max_vpi
= (phba
->sli4_hba
.max_cfg_param
.max_vpi
> 0) ?
4997 (phba
->sli4_hba
.max_cfg_param
.max_vpi
- 1) : 0;
4998 phba
->max_vports
= phba
->max_vpi
;
4999 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
5000 "2003 cfg params XRI(B:%d M:%d), "
5004 "FCFI(B:%d M:%d)\n",
5005 phba
->sli4_hba
.max_cfg_param
.xri_base
,
5006 phba
->sli4_hba
.max_cfg_param
.max_xri
,
5007 phba
->sli4_hba
.max_cfg_param
.vpi_base
,
5008 phba
->sli4_hba
.max_cfg_param
.max_vpi
,
5009 phba
->sli4_hba
.max_cfg_param
.vfi_base
,
5010 phba
->sli4_hba
.max_cfg_param
.max_vfi
,
5011 phba
->sli4_hba
.max_cfg_param
.rpi_base
,
5012 phba
->sli4_hba
.max_cfg_param
.max_rpi
,
5013 phba
->sli4_hba
.max_cfg_param
.fcfi_base
,
5014 phba
->sli4_hba
.max_cfg_param
.max_fcfi
);
5016 mempool_free(pmb
, phba
->mbox_mem_pool
);
5018 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
5019 if (phba
->cfg_hba_queue_depth
> (phba
->sli4_hba
.max_cfg_param
.max_xri
))
5020 phba
->cfg_hba_queue_depth
=
5021 phba
->sli4_hba
.max_cfg_param
.max_xri
;
5026 * lpfc_dev_endian_order_setup - Notify the port of the host's endian order.
5027 * @phba: pointer to lpfc hba data structure.
5029 * This routine is invoked to setup the host-side endian order to the
5030 * HBA consistent with the SLI-4 interface spec.
5034 * ENOMEM - No availble memory
5035 * EIO - The mailbox failed to complete successfully.
5038 lpfc_setup_endian_order(struct lpfc_hba
*phba
)
5040 LPFC_MBOXQ_t
*mboxq
;
5042 uint32_t endian_mb_data
[2] = {HOST_ENDIAN_LOW_WORD0
,
5043 HOST_ENDIAN_HIGH_WORD1
};
5045 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5047 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5048 "0492 Unable to allocate memory for issuing "
5049 "SLI_CONFIG_SPECIAL mailbox command\n");
5054 * The SLI4_CONFIG_SPECIAL mailbox command requires the first two
5055 * words to contain special data values and no other data.
5057 memset(mboxq
, 0, sizeof(LPFC_MBOXQ_t
));
5058 memcpy(&mboxq
->u
.mqe
, &endian_mb_data
, sizeof(endian_mb_data
));
5059 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5060 if (rc
!= MBX_SUCCESS
) {
5061 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5062 "0493 SLI_CONFIG_SPECIAL mailbox failed with "
5068 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5073 * lpfc_sli4_queue_create - Create all the SLI4 queues
5074 * @phba: pointer to lpfc hba data structure.
5076 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
5077 * operation. For each SLI4 queue type, the parameters such as queue entry
5078 * count (queue depth) shall be taken from the module parameter. For now,
5079 * we just use some constant number as place holder.
5083 * ENOMEM - No availble memory
5084 * EIO - The mailbox failed to complete successfully.
5087 lpfc_sli4_queue_create(struct lpfc_hba
*phba
)
5089 struct lpfc_queue
*qdesc
;
5090 int fcp_eqidx
, fcp_cqidx
, fcp_wqidx
;
5091 int cfg_fcp_wq_count
;
5092 int cfg_fcp_eq_count
;
5095 * Sanity check for confiugred queue parameters against the run-time
5099 /* Sanity check on FCP fast-path WQ parameters */
5100 cfg_fcp_wq_count
= phba
->cfg_fcp_wq_count
;
5101 if (cfg_fcp_wq_count
>
5102 (phba
->sli4_hba
.max_cfg_param
.max_wq
- LPFC_SP_WQN_DEF
)) {
5103 cfg_fcp_wq_count
= phba
->sli4_hba
.max_cfg_param
.max_wq
-
5105 if (cfg_fcp_wq_count
< LPFC_FP_WQN_MIN
) {
5106 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5107 "2581 Not enough WQs (%d) from "
5108 "the pci function for supporting "
5110 phba
->sli4_hba
.max_cfg_param
.max_wq
,
5111 phba
->cfg_fcp_wq_count
);
5114 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5115 "2582 Not enough WQs (%d) from the pci "
5116 "function for supporting the requested "
5117 "FCP WQs (%d), the actual FCP WQs can "
5118 "be supported: %d\n",
5119 phba
->sli4_hba
.max_cfg_param
.max_wq
,
5120 phba
->cfg_fcp_wq_count
, cfg_fcp_wq_count
);
5122 /* The actual number of FCP work queues adopted */
5123 phba
->cfg_fcp_wq_count
= cfg_fcp_wq_count
;
5125 /* Sanity check on FCP fast-path EQ parameters */
5126 cfg_fcp_eq_count
= phba
->cfg_fcp_eq_count
;
5127 if (cfg_fcp_eq_count
>
5128 (phba
->sli4_hba
.max_cfg_param
.max_eq
- LPFC_SP_EQN_DEF
)) {
5129 cfg_fcp_eq_count
= phba
->sli4_hba
.max_cfg_param
.max_eq
-
5131 if (cfg_fcp_eq_count
< LPFC_FP_EQN_MIN
) {
5132 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5133 "2574 Not enough EQs (%d) from the "
5134 "pci function for supporting FCP "
5136 phba
->sli4_hba
.max_cfg_param
.max_eq
,
5137 phba
->cfg_fcp_eq_count
);
5140 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5141 "2575 Not enough EQs (%d) from the pci "
5142 "function for supporting the requested "
5143 "FCP EQs (%d), the actual FCP EQs can "
5144 "be supported: %d\n",
5145 phba
->sli4_hba
.max_cfg_param
.max_eq
,
5146 phba
->cfg_fcp_eq_count
, cfg_fcp_eq_count
);
5148 /* It does not make sense to have more EQs than WQs */
5149 if (cfg_fcp_eq_count
> phba
->cfg_fcp_wq_count
) {
5150 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5151 "2593 The FCP EQ count(%d) cannot be greater "
5152 "than the FCP WQ count(%d), limiting the "
5153 "FCP EQ count to %d\n", cfg_fcp_eq_count
,
5154 phba
->cfg_fcp_wq_count
,
5155 phba
->cfg_fcp_wq_count
);
5156 cfg_fcp_eq_count
= phba
->cfg_fcp_wq_count
;
5158 /* The actual number of FCP event queues adopted */
5159 phba
->cfg_fcp_eq_count
= cfg_fcp_eq_count
;
5160 /* The overall number of event queues used */
5161 phba
->sli4_hba
.cfg_eqn
= phba
->cfg_fcp_eq_count
+ LPFC_SP_EQN_DEF
;
5164 * Create Event Queues (EQs)
5167 /* Get EQ depth from module parameter, fake the default for now */
5168 phba
->sli4_hba
.eq_esize
= LPFC_EQE_SIZE_4B
;
5169 phba
->sli4_hba
.eq_ecount
= LPFC_EQE_DEF_COUNT
;
5171 /* Create slow path event queue */
5172 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.eq_esize
,
5173 phba
->sli4_hba
.eq_ecount
);
5175 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5176 "0496 Failed allocate slow-path EQ\n");
5179 phba
->sli4_hba
.sp_eq
= qdesc
;
5181 /* Create fast-path FCP Event Queue(s) */
5182 phba
->sli4_hba
.fp_eq
= kzalloc((sizeof(struct lpfc_queue
*) *
5183 phba
->cfg_fcp_eq_count
), GFP_KERNEL
);
5184 if (!phba
->sli4_hba
.fp_eq
) {
5185 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5186 "2576 Failed allocate memory for fast-path "
5187 "EQ record array\n");
5188 goto out_free_sp_eq
;
5190 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++) {
5191 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.eq_esize
,
5192 phba
->sli4_hba
.eq_ecount
);
5194 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5195 "0497 Failed allocate fast-path EQ\n");
5196 goto out_free_fp_eq
;
5198 phba
->sli4_hba
.fp_eq
[fcp_eqidx
] = qdesc
;
5202 * Create Complete Queues (CQs)
5205 /* Get CQ depth from module parameter, fake the default for now */
5206 phba
->sli4_hba
.cq_esize
= LPFC_CQE_SIZE
;
5207 phba
->sli4_hba
.cq_ecount
= LPFC_CQE_DEF_COUNT
;
5209 /* Create slow-path Mailbox Command Complete Queue */
5210 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
5211 phba
->sli4_hba
.cq_ecount
);
5213 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5214 "0500 Failed allocate slow-path mailbox CQ\n");
5215 goto out_free_fp_eq
;
5217 phba
->sli4_hba
.mbx_cq
= qdesc
;
5219 /* Create slow-path ELS Complete Queue */
5220 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
5221 phba
->sli4_hba
.cq_ecount
);
5223 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5224 "0501 Failed allocate slow-path ELS CQ\n");
5225 goto out_free_mbx_cq
;
5227 phba
->sli4_hba
.els_cq
= qdesc
;
5230 /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */
5231 phba
->sli4_hba
.fcp_cq
= kzalloc((sizeof(struct lpfc_queue
*) *
5232 phba
->cfg_fcp_eq_count
), GFP_KERNEL
);
5233 if (!phba
->sli4_hba
.fcp_cq
) {
5234 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5235 "2577 Failed allocate memory for fast-path "
5236 "CQ record array\n");
5237 goto out_free_els_cq
;
5239 for (fcp_cqidx
= 0; fcp_cqidx
< phba
->cfg_fcp_eq_count
; fcp_cqidx
++) {
5240 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
5241 phba
->sli4_hba
.cq_ecount
);
5243 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5244 "0499 Failed allocate fast-path FCP "
5245 "CQ (%d)\n", fcp_cqidx
);
5246 goto out_free_fcp_cq
;
5248 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
] = qdesc
;
5251 /* Create Mailbox Command Queue */
5252 phba
->sli4_hba
.mq_esize
= LPFC_MQE_SIZE
;
5253 phba
->sli4_hba
.mq_ecount
= LPFC_MQE_DEF_COUNT
;
5255 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.mq_esize
,
5256 phba
->sli4_hba
.mq_ecount
);
5258 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5259 "0505 Failed allocate slow-path MQ\n");
5260 goto out_free_fcp_cq
;
5262 phba
->sli4_hba
.mbx_wq
= qdesc
;
5265 * Create all the Work Queues (WQs)
5267 phba
->sli4_hba
.wq_esize
= LPFC_WQE_SIZE
;
5268 phba
->sli4_hba
.wq_ecount
= LPFC_WQE_DEF_COUNT
;
5270 /* Create slow-path ELS Work Queue */
5271 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
5272 phba
->sli4_hba
.wq_ecount
);
5274 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5275 "0504 Failed allocate slow-path ELS WQ\n");
5276 goto out_free_mbx_wq
;
5278 phba
->sli4_hba
.els_wq
= qdesc
;
5280 /* Create fast-path FCP Work Queue(s) */
5281 phba
->sli4_hba
.fcp_wq
= kzalloc((sizeof(struct lpfc_queue
*) *
5282 phba
->cfg_fcp_wq_count
), GFP_KERNEL
);
5283 if (!phba
->sli4_hba
.fcp_wq
) {
5284 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5285 "2578 Failed allocate memory for fast-path "
5286 "WQ record array\n");
5287 goto out_free_els_wq
;
5289 for (fcp_wqidx
= 0; fcp_wqidx
< phba
->cfg_fcp_wq_count
; fcp_wqidx
++) {
5290 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
5291 phba
->sli4_hba
.wq_ecount
);
5293 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5294 "0503 Failed allocate fast-path FCP "
5295 "WQ (%d)\n", fcp_wqidx
);
5296 goto out_free_fcp_wq
;
5298 phba
->sli4_hba
.fcp_wq
[fcp_wqidx
] = qdesc
;
5302 * Create Receive Queue (RQ)
5304 phba
->sli4_hba
.rq_esize
= LPFC_RQE_SIZE
;
5305 phba
->sli4_hba
.rq_ecount
= LPFC_RQE_DEF_COUNT
;
5307 /* Create Receive Queue for header */
5308 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
5309 phba
->sli4_hba
.rq_ecount
);
5311 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5312 "0506 Failed allocate receive HRQ\n");
5313 goto out_free_fcp_wq
;
5315 phba
->sli4_hba
.hdr_rq
= qdesc
;
5317 /* Create Receive Queue for data */
5318 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
5319 phba
->sli4_hba
.rq_ecount
);
5321 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5322 "0507 Failed allocate receive DRQ\n");
5323 goto out_free_hdr_rq
;
5325 phba
->sli4_hba
.dat_rq
= qdesc
;
5330 lpfc_sli4_queue_free(phba
->sli4_hba
.hdr_rq
);
5331 phba
->sli4_hba
.hdr_rq
= NULL
;
5333 for (--fcp_wqidx
; fcp_wqidx
>= 0; fcp_wqidx
--) {
5334 lpfc_sli4_queue_free(phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]);
5335 phba
->sli4_hba
.fcp_wq
[fcp_wqidx
] = NULL
;
5337 kfree(phba
->sli4_hba
.fcp_wq
);
5339 lpfc_sli4_queue_free(phba
->sli4_hba
.els_wq
);
5340 phba
->sli4_hba
.els_wq
= NULL
;
5342 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_wq
);
5343 phba
->sli4_hba
.mbx_wq
= NULL
;
5345 for (--fcp_cqidx
; fcp_cqidx
>= 0; fcp_cqidx
--) {
5346 lpfc_sli4_queue_free(phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]);
5347 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
] = NULL
;
5349 kfree(phba
->sli4_hba
.fcp_cq
);
5351 lpfc_sli4_queue_free(phba
->sli4_hba
.els_cq
);
5352 phba
->sli4_hba
.els_cq
= NULL
;
5354 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_cq
);
5355 phba
->sli4_hba
.mbx_cq
= NULL
;
5357 for (--fcp_eqidx
; fcp_eqidx
>= 0; fcp_eqidx
--) {
5358 lpfc_sli4_queue_free(phba
->sli4_hba
.fp_eq
[fcp_eqidx
]);
5359 phba
->sli4_hba
.fp_eq
[fcp_eqidx
] = NULL
;
5361 kfree(phba
->sli4_hba
.fp_eq
);
5363 lpfc_sli4_queue_free(phba
->sli4_hba
.sp_eq
);
5364 phba
->sli4_hba
.sp_eq
= NULL
;
5370 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
5371 * @phba: pointer to lpfc hba data structure.
5373 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
5378 * ENOMEM - No availble memory
5379 * EIO - The mailbox failed to complete successfully.
5382 lpfc_sli4_queue_destroy(struct lpfc_hba
*phba
)
5386 /* Release mailbox command work queue */
5387 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_wq
);
5388 phba
->sli4_hba
.mbx_wq
= NULL
;
5390 /* Release ELS work queue */
5391 lpfc_sli4_queue_free(phba
->sli4_hba
.els_wq
);
5392 phba
->sli4_hba
.els_wq
= NULL
;
5394 /* Release FCP work queue */
5395 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_wq_count
; fcp_qidx
++)
5396 lpfc_sli4_queue_free(phba
->sli4_hba
.fcp_wq
[fcp_qidx
]);
5397 kfree(phba
->sli4_hba
.fcp_wq
);
5398 phba
->sli4_hba
.fcp_wq
= NULL
;
5400 /* Release unsolicited receive queue */
5401 lpfc_sli4_queue_free(phba
->sli4_hba
.hdr_rq
);
5402 phba
->sli4_hba
.hdr_rq
= NULL
;
5403 lpfc_sli4_queue_free(phba
->sli4_hba
.dat_rq
);
5404 phba
->sli4_hba
.dat_rq
= NULL
;
5406 /* Release ELS complete queue */
5407 lpfc_sli4_queue_free(phba
->sli4_hba
.els_cq
);
5408 phba
->sli4_hba
.els_cq
= NULL
;
5410 /* Release mailbox command complete queue */
5411 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_cq
);
5412 phba
->sli4_hba
.mbx_cq
= NULL
;
5414 /* Release FCP response complete queue */
5415 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_eq_count
; fcp_qidx
++)
5416 lpfc_sli4_queue_free(phba
->sli4_hba
.fcp_cq
[fcp_qidx
]);
5417 kfree(phba
->sli4_hba
.fcp_cq
);
5418 phba
->sli4_hba
.fcp_cq
= NULL
;
5420 /* Release fast-path event queue */
5421 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_eq_count
; fcp_qidx
++)
5422 lpfc_sli4_queue_free(phba
->sli4_hba
.fp_eq
[fcp_qidx
]);
5423 kfree(phba
->sli4_hba
.fp_eq
);
5424 phba
->sli4_hba
.fp_eq
= NULL
;
5426 /* Release slow-path event queue */
5427 lpfc_sli4_queue_free(phba
->sli4_hba
.sp_eq
);
5428 phba
->sli4_hba
.sp_eq
= NULL
;
5434 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
5435 * @phba: pointer to lpfc hba data structure.
5437 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
5442 * ENOMEM - No availble memory
5443 * EIO - The mailbox failed to complete successfully.
5446 lpfc_sli4_queue_setup(struct lpfc_hba
*phba
)
5449 int fcp_eqidx
, fcp_cqidx
, fcp_wqidx
;
5450 int fcp_cq_index
= 0;
5453 * Set up Event Queues (EQs)
5456 /* Set up slow-path event queue */
5457 if (!phba
->sli4_hba
.sp_eq
) {
5458 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5459 "0520 Slow-path EQ not allocated\n");
5462 rc
= lpfc_eq_create(phba
, phba
->sli4_hba
.sp_eq
,
5465 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5466 "0521 Failed setup of slow-path EQ: "
5470 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5471 "2583 Slow-path EQ setup: queue-id=%d\n",
5472 phba
->sli4_hba
.sp_eq
->queue_id
);
5474 /* Set up fast-path event queue */
5475 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_eq_count
; fcp_eqidx
++) {
5476 if (!phba
->sli4_hba
.fp_eq
[fcp_eqidx
]) {
5477 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5478 "0522 Fast-path EQ (%d) not "
5479 "allocated\n", fcp_eqidx
);
5480 goto out_destroy_fp_eq
;
5482 rc
= lpfc_eq_create(phba
, phba
->sli4_hba
.fp_eq
[fcp_eqidx
],
5483 phba
->cfg_fcp_imax
);
5485 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5486 "0523 Failed setup of fast-path EQ "
5487 "(%d), rc = 0x%x\n", fcp_eqidx
, rc
);
5488 goto out_destroy_fp_eq
;
5490 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5491 "2584 Fast-path EQ setup: "
5492 "queue[%d]-id=%d\n", fcp_eqidx
,
5493 phba
->sli4_hba
.fp_eq
[fcp_eqidx
]->queue_id
);
5497 * Set up Complete Queues (CQs)
5500 /* Set up slow-path MBOX Complete Queue as the first CQ */
5501 if (!phba
->sli4_hba
.mbx_cq
) {
5502 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5503 "0528 Mailbox CQ not allocated\n");
5504 goto out_destroy_fp_eq
;
5506 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.mbx_cq
, phba
->sli4_hba
.sp_eq
,
5507 LPFC_MCQ
, LPFC_MBOX
);
5509 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5510 "0529 Failed setup of slow-path mailbox CQ: "
5512 goto out_destroy_fp_eq
;
5514 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5515 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
5516 phba
->sli4_hba
.mbx_cq
->queue_id
,
5517 phba
->sli4_hba
.sp_eq
->queue_id
);
5519 /* Set up slow-path ELS Complete Queue */
5520 if (!phba
->sli4_hba
.els_cq
) {
5521 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5522 "0530 ELS CQ not allocated\n");
5523 goto out_destroy_mbx_cq
;
5525 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.els_cq
, phba
->sli4_hba
.sp_eq
,
5526 LPFC_WCQ
, LPFC_ELS
);
5528 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5529 "0531 Failed setup of slow-path ELS CQ: "
5531 goto out_destroy_mbx_cq
;
5533 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5534 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
5535 phba
->sli4_hba
.els_cq
->queue_id
,
5536 phba
->sli4_hba
.sp_eq
->queue_id
);
5538 /* Set up fast-path FCP Response Complete Queue */
5539 for (fcp_cqidx
= 0; fcp_cqidx
< phba
->cfg_fcp_eq_count
; fcp_cqidx
++) {
5540 if (!phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]) {
5541 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5542 "0526 Fast-path FCP CQ (%d) not "
5543 "allocated\n", fcp_cqidx
);
5544 goto out_destroy_fcp_cq
;
5546 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.fcp_cq
[fcp_cqidx
],
5547 phba
->sli4_hba
.fp_eq
[fcp_cqidx
],
5548 LPFC_WCQ
, LPFC_FCP
);
5550 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5551 "0527 Failed setup of fast-path FCP "
5552 "CQ (%d), rc = 0x%x\n", fcp_cqidx
, rc
);
5553 goto out_destroy_fcp_cq
;
5555 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5556 "2588 FCP CQ setup: cq[%d]-id=%d, "
5557 "parent eq[%d]-id=%d\n",
5559 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]->queue_id
,
5561 phba
->sli4_hba
.fp_eq
[fcp_cqidx
]->queue_id
);
5565 * Set up all the Work Queues (WQs)
5568 /* Set up Mailbox Command Queue */
5569 if (!phba
->sli4_hba
.mbx_wq
) {
5570 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5571 "0538 Slow-path MQ not allocated\n");
5572 goto out_destroy_fcp_cq
;
5574 rc
= lpfc_mq_create(phba
, phba
->sli4_hba
.mbx_wq
,
5575 phba
->sli4_hba
.mbx_cq
, LPFC_MBOX
);
5577 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5578 "0539 Failed setup of slow-path MQ: "
5580 goto out_destroy_fcp_cq
;
5582 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5583 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
5584 phba
->sli4_hba
.mbx_wq
->queue_id
,
5585 phba
->sli4_hba
.mbx_cq
->queue_id
);
5587 /* Set up slow-path ELS Work Queue */
5588 if (!phba
->sli4_hba
.els_wq
) {
5589 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5590 "0536 Slow-path ELS WQ not allocated\n");
5591 goto out_destroy_mbx_wq
;
5593 rc
= lpfc_wq_create(phba
, phba
->sli4_hba
.els_wq
,
5594 phba
->sli4_hba
.els_cq
, LPFC_ELS
);
5596 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5597 "0537 Failed setup of slow-path ELS WQ: "
5599 goto out_destroy_mbx_wq
;
5601 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5602 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
5603 phba
->sli4_hba
.els_wq
->queue_id
,
5604 phba
->sli4_hba
.els_cq
->queue_id
);
5606 /* Set up fast-path FCP Work Queue */
5607 for (fcp_wqidx
= 0; fcp_wqidx
< phba
->cfg_fcp_wq_count
; fcp_wqidx
++) {
5608 if (!phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]) {
5609 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5610 "0534 Fast-path FCP WQ (%d) not "
5611 "allocated\n", fcp_wqidx
);
5612 goto out_destroy_fcp_wq
;
5614 rc
= lpfc_wq_create(phba
, phba
->sli4_hba
.fcp_wq
[fcp_wqidx
],
5615 phba
->sli4_hba
.fcp_cq
[fcp_cq_index
],
5618 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5619 "0535 Failed setup of fast-path FCP "
5620 "WQ (%d), rc = 0x%x\n", fcp_wqidx
, rc
);
5621 goto out_destroy_fcp_wq
;
5623 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5624 "2591 FCP WQ setup: wq[%d]-id=%d, "
5625 "parent cq[%d]-id=%d\n",
5627 phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]->queue_id
,
5629 phba
->sli4_hba
.fcp_cq
[fcp_cq_index
]->queue_id
);
5630 /* Round robin FCP Work Queue's Completion Queue assignment */
5631 fcp_cq_index
= ((fcp_cq_index
+ 1) % phba
->cfg_fcp_eq_count
);
5635 * Create Receive Queue (RQ)
5637 if (!phba
->sli4_hba
.hdr_rq
|| !phba
->sli4_hba
.dat_rq
) {
5638 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5639 "0540 Receive Queue not allocated\n");
5640 goto out_destroy_fcp_wq
;
5642 rc
= lpfc_rq_create(phba
, phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
5643 phba
->sli4_hba
.els_cq
, LPFC_USOL
);
5645 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5646 "0541 Failed setup of Receive Queue: "
5648 goto out_destroy_fcp_wq
;
5650 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5651 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
5652 "parent cq-id=%d\n",
5653 phba
->sli4_hba
.hdr_rq
->queue_id
,
5654 phba
->sli4_hba
.dat_rq
->queue_id
,
5655 phba
->sli4_hba
.els_cq
->queue_id
);
5659 for (--fcp_wqidx
; fcp_wqidx
>= 0; fcp_wqidx
--)
5660 lpfc_wq_destroy(phba
, phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]);
5661 lpfc_wq_destroy(phba
, phba
->sli4_hba
.els_wq
);
5663 lpfc_mq_destroy(phba
, phba
->sli4_hba
.mbx_wq
);
5665 for (--fcp_cqidx
; fcp_cqidx
>= 0; fcp_cqidx
--)
5666 lpfc_cq_destroy(phba
, phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]);
5667 lpfc_cq_destroy(phba
, phba
->sli4_hba
.els_cq
);
5669 lpfc_cq_destroy(phba
, phba
->sli4_hba
.mbx_cq
);
5671 for (--fcp_eqidx
; fcp_eqidx
>= 0; fcp_eqidx
--)
5672 lpfc_eq_destroy(phba
, phba
->sli4_hba
.fp_eq
[fcp_eqidx
]);
5673 lpfc_eq_destroy(phba
, phba
->sli4_hba
.sp_eq
);
5679 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
5680 * @phba: pointer to lpfc hba data structure.
5682 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
5687 * ENOMEM - No availble memory
5688 * EIO - The mailbox failed to complete successfully.
5691 lpfc_sli4_queue_unset(struct lpfc_hba
*phba
)
5695 /* Unset mailbox command work queue */
5696 lpfc_mq_destroy(phba
, phba
->sli4_hba
.mbx_wq
);
5697 /* Unset ELS work queue */
5698 lpfc_wq_destroy(phba
, phba
->sli4_hba
.els_wq
);
5699 /* Unset unsolicited receive queue */
5700 lpfc_rq_destroy(phba
, phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
);
5701 /* Unset FCP work queue */
5702 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_wq_count
; fcp_qidx
++)
5703 lpfc_wq_destroy(phba
, phba
->sli4_hba
.fcp_wq
[fcp_qidx
]);
5704 /* Unset mailbox command complete queue */
5705 lpfc_cq_destroy(phba
, phba
->sli4_hba
.mbx_cq
);
5706 /* Unset ELS complete queue */
5707 lpfc_cq_destroy(phba
, phba
->sli4_hba
.els_cq
);
5708 /* Unset FCP response complete queue */
5709 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_eq_count
; fcp_qidx
++)
5710 lpfc_cq_destroy(phba
, phba
->sli4_hba
.fcp_cq
[fcp_qidx
]);
5711 /* Unset fast-path event queue */
5712 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_eq_count
; fcp_qidx
++)
5713 lpfc_eq_destroy(phba
, phba
->sli4_hba
.fp_eq
[fcp_qidx
]);
5714 /* Unset slow-path event queue */
5715 lpfc_eq_destroy(phba
, phba
->sli4_hba
.sp_eq
);
5719 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
5720 * @phba: pointer to lpfc hba data structure.
5722 * This routine is invoked to allocate and set up a pool of completion queue
5723 * events. The body of the completion queue event is a completion queue entry
5724 * CQE. For now, this pool is used for the interrupt service routine to queue
5725 * the following HBA completion queue events for the worker thread to process:
5726 * - Mailbox asynchronous events
5727 * - Receive queue completion unsolicited events
5728 * Later, this can be used for all the slow-path events.
5732 * -ENOMEM - No availble memory
5735 lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*phba
)
5737 struct lpfc_cq_event
*cq_event
;
5740 for (i
= 0; i
< (4 * phba
->sli4_hba
.cq_ecount
); i
++) {
5741 cq_event
= kmalloc(sizeof(struct lpfc_cq_event
), GFP_KERNEL
);
5743 goto out_pool_create_fail
;
5744 list_add_tail(&cq_event
->list
,
5745 &phba
->sli4_hba
.sp_cqe_event_pool
);
5749 out_pool_create_fail
:
5750 lpfc_sli4_cq_event_pool_destroy(phba
);
5755 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
5756 * @phba: pointer to lpfc hba data structure.
5758 * This routine is invoked to free the pool of completion queue events at
5759 * driver unload time. Note that, it is the responsibility of the driver
5760 * cleanup routine to free all the outstanding completion-queue events
5761 * allocated from this pool back into the pool before invoking this routine
5762 * to destroy the pool.
5765 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*phba
)
5767 struct lpfc_cq_event
*cq_event
, *next_cq_event
;
5769 list_for_each_entry_safe(cq_event
, next_cq_event
,
5770 &phba
->sli4_hba
.sp_cqe_event_pool
, list
) {
5771 list_del(&cq_event
->list
);
5777 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
5778 * @phba: pointer to lpfc hba data structure.
5780 * This routine is the lock free version of the API invoked to allocate a
5781 * completion-queue event from the free pool.
5783 * Return: Pointer to the newly allocated completion-queue event if successful
5786 struct lpfc_cq_event
*
5787 __lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
5789 struct lpfc_cq_event
*cq_event
= NULL
;
5791 list_remove_head(&phba
->sli4_hba
.sp_cqe_event_pool
, cq_event
,
5792 struct lpfc_cq_event
, list
);
5797 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
5798 * @phba: pointer to lpfc hba data structure.
5800 * This routine is the lock version of the API invoked to allocate a
5801 * completion-queue event from the free pool.
5803 * Return: Pointer to the newly allocated completion-queue event if successful
5806 struct lpfc_cq_event
*
5807 lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
5809 struct lpfc_cq_event
*cq_event
;
5810 unsigned long iflags
;
5812 spin_lock_irqsave(&phba
->hbalock
, iflags
);
5813 cq_event
= __lpfc_sli4_cq_event_alloc(phba
);
5814 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5819 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
5820 * @phba: pointer to lpfc hba data structure.
5821 * @cq_event: pointer to the completion queue event to be freed.
5823 * This routine is the lock free version of the API invoked to release a
5824 * completion-queue event back into the free pool.
5827 __lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
5828 struct lpfc_cq_event
*cq_event
)
5830 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_cqe_event_pool
);
5834 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
5835 * @phba: pointer to lpfc hba data structure.
5836 * @cq_event: pointer to the completion queue event to be freed.
5838 * This routine is the lock version of the API invoked to release a
5839 * completion-queue event back into the free pool.
5842 lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
5843 struct lpfc_cq_event
*cq_event
)
5845 unsigned long iflags
;
5846 spin_lock_irqsave(&phba
->hbalock
, iflags
);
5847 __lpfc_sli4_cq_event_release(phba
, cq_event
);
5848 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5852 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
5853 * @phba: pointer to lpfc hba data structure.
5855 * This routine is to free all the pending completion-queue events to the
5856 * back into the free pool for device reset.
5859 lpfc_sli4_cq_event_release_all(struct lpfc_hba
*phba
)
5862 struct lpfc_cq_event
*cqe
;
5863 unsigned long iflags
;
5865 /* Retrieve all the pending WCQEs from pending WCQE lists */
5866 spin_lock_irqsave(&phba
->hbalock
, iflags
);
5867 /* Pending FCP XRI abort events */
5868 list_splice_init(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
5870 /* Pending ELS XRI abort events */
5871 list_splice_init(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
5873 /* Pending asynnc events */
5874 list_splice_init(&phba
->sli4_hba
.sp_asynce_work_queue
,
5876 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
5878 while (!list_empty(&cqelist
)) {
5879 list_remove_head(&cqelist
, cqe
, struct lpfc_cq_event
, list
);
5880 lpfc_sli4_cq_event_release(phba
, cqe
);
5885 * lpfc_pci_function_reset - Reset pci function.
5886 * @phba: pointer to lpfc hba data structure.
5888 * This routine is invoked to request a PCI function reset. It will destroys
5889 * all resources assigned to the PCI function which originates this request.
5893 * ENOMEM - No availble memory
5894 * EIO - The mailbox failed to complete successfully.
5897 lpfc_pci_function_reset(struct lpfc_hba
*phba
)
5899 LPFC_MBOXQ_t
*mboxq
;
5901 uint32_t shdr_status
, shdr_add_status
;
5902 union lpfc_sli4_cfg_shdr
*shdr
;
5904 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5906 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5907 "0494 Unable to allocate memory for issuing "
5908 "SLI_FUNCTION_RESET mailbox command\n");
5912 /* Set up PCI function reset SLI4_CONFIG mailbox-ioctl command */
5913 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5914 LPFC_MBOX_OPCODE_FUNCTION_RESET
, 0,
5915 LPFC_SLI4_MBX_EMBED
);
5916 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5917 shdr
= (union lpfc_sli4_cfg_shdr
*)
5918 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
5919 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
5920 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
5921 if (rc
!= MBX_TIMEOUT
)
5922 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5923 if (shdr_status
|| shdr_add_status
|| rc
) {
5924 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5925 "0495 SLI_FUNCTION_RESET mailbox failed with "
5926 "status x%x add_status x%x, mbx status x%x\n",
5927 shdr_status
, shdr_add_status
, rc
);
5934 * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
5935 * @phba: pointer to lpfc hba data structure.
5936 * @cnt: number of nop mailbox commands to send.
5938 * This routine is invoked to send a number @cnt of NOP mailbox command and
5939 * wait for each command to complete.
5941 * Return: the number of NOP mailbox command completed.
5944 lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba
*phba
, uint32_t cnt
)
5946 LPFC_MBOXQ_t
*mboxq
;
5947 int length
, cmdsent
;
5950 uint32_t shdr_status
, shdr_add_status
;
5951 union lpfc_sli4_cfg_shdr
*shdr
;
5954 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5955 "2518 Requested to send 0 NOP mailbox cmd\n");
5959 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5961 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5962 "2519 Unable to allocate memory for issuing "
5963 "NOP mailbox command\n");
5967 /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
5968 length
= (sizeof(struct lpfc_mbx_nop
) -
5969 sizeof(struct lpfc_sli4_cfg_mhdr
));
5970 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5971 LPFC_MBOX_OPCODE_NOP
, length
, LPFC_SLI4_MBX_EMBED
);
5973 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
5974 for (cmdsent
= 0; cmdsent
< cnt
; cmdsent
++) {
5975 if (!phba
->sli4_hba
.intr_enable
)
5976 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5978 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
5979 if (rc
== MBX_TIMEOUT
)
5981 /* Check return status */
5982 shdr
= (union lpfc_sli4_cfg_shdr
*)
5983 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
5984 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
5985 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
5987 if (shdr_status
|| shdr_add_status
|| rc
) {
5988 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5989 "2520 NOP mailbox command failed "
5990 "status x%x add_status x%x mbx "
5991 "status x%x\n", shdr_status
,
5992 shdr_add_status
, rc
);
5997 if (rc
!= MBX_TIMEOUT
)
5998 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6004 * lpfc_sli4_fcfi_unreg - Unregister fcfi to device
6005 * @phba: pointer to lpfc hba data structure.
6008 * This routine is invoked to unregister a FCFI from device.
6011 lpfc_sli4_fcfi_unreg(struct lpfc_hba
*phba
, uint16_t fcfi
)
6016 unsigned long flags
;
6018 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6023 lpfc_unreg_fcfi(mbox
, fcfi
);
6025 if (!phba
->sli4_hba
.intr_enable
)
6026 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_POLL
);
6028 mbox_tmo
= lpfc_mbox_tmo_val(phba
, MBX_SLI4_CONFIG
);
6029 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, mbox_tmo
);
6031 if (rc
!= MBX_TIMEOUT
)
6032 mempool_free(mbox
, phba
->mbox_mem_pool
);
6033 if (rc
!= MBX_SUCCESS
)
6034 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6035 "2517 Unregister FCFI command failed "
6036 "status %d, mbxStatus x%x\n", rc
,
6037 bf_get(lpfc_mqe_status
, &mbox
->u
.mqe
));
6039 spin_lock_irqsave(&phba
->hbalock
, flags
);
6040 /* Mark the FCFI is no longer registered */
6041 phba
->fcf
.fcf_flag
&=
6042 ~(FCF_AVAILABLE
| FCF_REGISTERED
| FCF_DISCOVERED
);
6043 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6048 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
6049 * @phba: pointer to lpfc hba data structure.
6051 * This routine is invoked to set up the PCI device memory space for device
6052 * with SLI-4 interface spec.
6056 * other values - error
6059 lpfc_sli4_pci_mem_setup(struct lpfc_hba
*phba
)
6061 struct pci_dev
*pdev
;
6062 unsigned long bar0map_len
, bar1map_len
, bar2map_len
;
6063 int error
= -ENODEV
;
6065 /* Obtain PCI device reference */
6069 pdev
= phba
->pcidev
;
6071 /* Set the device DMA mask size */
6072 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
6073 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
6074 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
6075 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
6080 /* Get the bus address of SLI4 device Bar0, Bar1, and Bar2 and the
6081 * number of bytes required by each mapping. They are actually
6082 * mapping to the PCI BAR regions 1, 2, and 4 by the SLI4 device.
6084 phba
->pci_bar0_map
= pci_resource_start(pdev
, LPFC_SLI4_BAR0
);
6085 bar0map_len
= pci_resource_len(pdev
, LPFC_SLI4_BAR0
);
6087 phba
->pci_bar1_map
= pci_resource_start(pdev
, LPFC_SLI4_BAR1
);
6088 bar1map_len
= pci_resource_len(pdev
, LPFC_SLI4_BAR1
);
6090 phba
->pci_bar2_map
= pci_resource_start(pdev
, LPFC_SLI4_BAR2
);
6091 bar2map_len
= pci_resource_len(pdev
, LPFC_SLI4_BAR2
);
6093 /* Map SLI4 PCI Config Space Register base to a kernel virtual addr */
6094 phba
->sli4_hba
.conf_regs_memmap_p
=
6095 ioremap(phba
->pci_bar0_map
, bar0map_len
);
6096 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
6097 dev_printk(KERN_ERR
, &pdev
->dev
,
6098 "ioremap failed for SLI4 PCI config registers.\n");
6102 /* Map SLI4 HBA Control Register base to a kernel virtual address. */
6103 phba
->sli4_hba
.ctrl_regs_memmap_p
=
6104 ioremap(phba
->pci_bar1_map
, bar1map_len
);
6105 if (!phba
->sli4_hba
.ctrl_regs_memmap_p
) {
6106 dev_printk(KERN_ERR
, &pdev
->dev
,
6107 "ioremap failed for SLI4 HBA control registers.\n");
6108 goto out_iounmap_conf
;
6111 /* Map SLI4 HBA Doorbell Register base to a kernel virtual address. */
6112 phba
->sli4_hba
.drbl_regs_memmap_p
=
6113 ioremap(phba
->pci_bar2_map
, bar2map_len
);
6114 if (!phba
->sli4_hba
.drbl_regs_memmap_p
) {
6115 dev_printk(KERN_ERR
, &pdev
->dev
,
6116 "ioremap failed for SLI4 HBA doorbell registers.\n");
6117 goto out_iounmap_ctrl
;
6120 /* Set up BAR0 PCI config space register memory map */
6121 lpfc_sli4_bar0_register_memmap(phba
);
6123 /* Set up BAR1 register memory map */
6124 lpfc_sli4_bar1_register_memmap(phba
);
6126 /* Set up BAR2 register memory map */
6127 error
= lpfc_sli4_bar2_register_memmap(phba
, LPFC_VF0
);
6129 goto out_iounmap_all
;
6134 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
6136 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
6138 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
6144 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
6145 * @phba: pointer to lpfc hba data structure.
6147 * This routine is invoked to unset the PCI device memory space for device
6148 * with SLI-4 interface spec.
6151 lpfc_sli4_pci_mem_unset(struct lpfc_hba
*phba
)
6153 struct pci_dev
*pdev
;
6155 /* Obtain PCI device reference */
6159 pdev
= phba
->pcidev
;
6161 /* Free coherent DMA memory allocated */
6163 /* Unmap I/O memory space */
6164 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
6165 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
6166 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
6172 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
6173 * @phba: pointer to lpfc hba data structure.
6175 * This routine is invoked to enable the MSI-X interrupt vectors to device
6176 * with SLI-3 interface specs. The kernel function pci_enable_msix() is
6177 * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
6178 * invoked, enables either all or nothing, depending on the current
6179 * availability of PCI vector resources. The device driver is responsible
6180 * for calling the individual request_irq() to register each MSI-X vector
6181 * with a interrupt handler, which is done in this function. Note that
6182 * later when device is unloading, the driver should always call free_irq()
6183 * on all MSI-X vectors it has done request_irq() on before calling
6184 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
6185 * will be left with MSI-X enabled and leaks its vectors.
6189 * other values - error
6192 lpfc_sli_enable_msix(struct lpfc_hba
*phba
)
6197 /* Set up MSI-X multi-message vectors */
6198 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
6199 phba
->msix_entries
[i
].entry
= i
;
6201 /* Configure MSI-X capability structure */
6202 rc
= pci_enable_msix(phba
->pcidev
, phba
->msix_entries
,
6203 ARRAY_SIZE(phba
->msix_entries
));
6205 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6206 "0420 PCI enable MSI-X failed (%d)\n", rc
);
6209 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
6210 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6211 "0477 MSI-X entry[%d]: vector=x%x "
6213 phba
->msix_entries
[i
].vector
,
6214 phba
->msix_entries
[i
].entry
);
6216 * Assign MSI-X vectors to interrupt handlers
6219 /* vector-0 is associated to slow-path handler */
6220 rc
= request_irq(phba
->msix_entries
[0].vector
,
6221 &lpfc_sli_sp_intr_handler
, IRQF_SHARED
,
6222 LPFC_SP_DRIVER_HANDLER_NAME
, phba
);
6224 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6225 "0421 MSI-X slow-path request_irq failed "
6230 /* vector-1 is associated to fast-path handler */
6231 rc
= request_irq(phba
->msix_entries
[1].vector
,
6232 &lpfc_sli_fp_intr_handler
, IRQF_SHARED
,
6233 LPFC_FP_DRIVER_HANDLER_NAME
, phba
);
6236 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6237 "0429 MSI-X fast-path request_irq failed "
6243 * Configure HBA MSI-X attention conditions to messages
6245 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6249 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6250 "0474 Unable to allocate memory for issuing "
6251 "MBOX_CONFIG_MSI command\n");
6254 rc
= lpfc_config_msi(phba
, pmb
);
6257 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
6258 if (rc
!= MBX_SUCCESS
) {
6259 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
6260 "0351 Config MSI mailbox command failed, "
6261 "mbxCmd x%x, mbxStatus x%x\n",
6262 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
);
6266 /* Free memory allocated for mailbox command */
6267 mempool_free(pmb
, phba
->mbox_mem_pool
);
6271 /* Free memory allocated for mailbox command */
6272 mempool_free(pmb
, phba
->mbox_mem_pool
);
6275 /* free the irq already requested */
6276 free_irq(phba
->msix_entries
[1].vector
, phba
);
6279 /* free the irq already requested */
6280 free_irq(phba
->msix_entries
[0].vector
, phba
);
6283 /* Unconfigure MSI-X capability structure */
6284 pci_disable_msix(phba
->pcidev
);
6289 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
6290 * @phba: pointer to lpfc hba data structure.
6292 * This routine is invoked to release the MSI-X vectors and then disable the
6293 * MSI-X interrupt mode to device with SLI-3 interface spec.
6296 lpfc_sli_disable_msix(struct lpfc_hba
*phba
)
6300 /* Free up MSI-X multi-message vectors */
6301 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
6302 free_irq(phba
->msix_entries
[i
].vector
, phba
);
6304 pci_disable_msix(phba
->pcidev
);
6310 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
6311 * @phba: pointer to lpfc hba data structure.
6313 * This routine is invoked to enable the MSI interrupt mode to device with
6314 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
6315 * enable the MSI vector. The device driver is responsible for calling the
6316 * request_irq() to register MSI vector with a interrupt the handler, which
6317 * is done in this function.
6321 * other values - error
6324 lpfc_sli_enable_msi(struct lpfc_hba
*phba
)
6328 rc
= pci_enable_msi(phba
->pcidev
);
6330 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6331 "0462 PCI enable MSI mode success.\n");
6333 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6334 "0471 PCI enable MSI mode failed (%d)\n", rc
);
6338 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
6339 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
6341 pci_disable_msi(phba
->pcidev
);
6342 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6343 "0478 MSI request_irq failed (%d)\n", rc
);
6349 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
6350 * @phba: pointer to lpfc hba data structure.
6352 * This routine is invoked to disable the MSI interrupt mode to device with
6353 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
6354 * done request_irq() on before calling pci_disable_msi(). Failure to do so
6355 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
6359 lpfc_sli_disable_msi(struct lpfc_hba
*phba
)
6361 free_irq(phba
->pcidev
->irq
, phba
);
6362 pci_disable_msi(phba
->pcidev
);
6367 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
6368 * @phba: pointer to lpfc hba data structure.
6370 * This routine is invoked to enable device interrupt and associate driver's
6371 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
6372 * spec. Depends on the interrupt mode configured to the driver, the driver
6373 * will try to fallback from the configured interrupt mode to an interrupt
6374 * mode which is supported by the platform, kernel, and device in the order
6376 * MSI-X -> MSI -> IRQ.
6380 * other values - error
6383 lpfc_sli_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
6385 uint32_t intr_mode
= LPFC_INTR_ERROR
;
6388 if (cfg_mode
== 2) {
6389 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
6390 retval
= lpfc_sli_config_port(phba
, LPFC_SLI_REV3
);
6392 /* Now, try to enable MSI-X interrupt mode */
6393 retval
= lpfc_sli_enable_msix(phba
);
6395 /* Indicate initialization to MSI-X mode */
6396 phba
->intr_type
= MSIX
;
6402 /* Fallback to MSI if MSI-X initialization failed */
6403 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
6404 retval
= lpfc_sli_enable_msi(phba
);
6406 /* Indicate initialization to MSI mode */
6407 phba
->intr_type
= MSI
;
6412 /* Fallback to INTx if both MSI-X/MSI initalization failed */
6413 if (phba
->intr_type
== NONE
) {
6414 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
6415 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
6417 /* Indicate initialization to INTx mode */
6418 phba
->intr_type
= INTx
;
6426 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
6427 * @phba: pointer to lpfc hba data structure.
6429 * This routine is invoked to disable device interrupt and disassociate the
6430 * driver's interrupt handler(s) from interrupt vector(s) to device with
6431 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
6432 * release the interrupt vector(s) for the message signaled interrupt.
6435 lpfc_sli_disable_intr(struct lpfc_hba
*phba
)
6437 /* Disable the currently initialized interrupt mode */
6438 if (phba
->intr_type
== MSIX
)
6439 lpfc_sli_disable_msix(phba
);
6440 else if (phba
->intr_type
== MSI
)
6441 lpfc_sli_disable_msi(phba
);
6442 else if (phba
->intr_type
== INTx
)
6443 free_irq(phba
->pcidev
->irq
, phba
);
6445 /* Reset interrupt management states */
6446 phba
->intr_type
= NONE
;
6447 phba
->sli
.slistat
.sli_intr
= 0;
6453 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
6454 * @phba: pointer to lpfc hba data structure.
6456 * This routine is invoked to enable the MSI-X interrupt vectors to device
6457 * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
6458 * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
6459 * enables either all or nothing, depending on the current availability of
6460 * PCI vector resources. The device driver is responsible for calling the
6461 * individual request_irq() to register each MSI-X vector with a interrupt
6462 * handler, which is done in this function. Note that later when device is
6463 * unloading, the driver should always call free_irq() on all MSI-X vectors
6464 * it has done request_irq() on before calling pci_disable_msix(). Failure
6465 * to do so results in a BUG_ON() and a device will be left with MSI-X
6466 * enabled and leaks its vectors.
6470 * other values - error
6473 lpfc_sli4_enable_msix(struct lpfc_hba
*phba
)
6477 /* Set up MSI-X multi-message vectors */
6478 for (index
= 0; index
< phba
->sli4_hba
.cfg_eqn
; index
++)
6479 phba
->sli4_hba
.msix_entries
[index
].entry
= index
;
6481 /* Configure MSI-X capability structure */
6482 rc
= pci_enable_msix(phba
->pcidev
, phba
->sli4_hba
.msix_entries
,
6483 phba
->sli4_hba
.cfg_eqn
);
6485 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6486 "0484 PCI enable MSI-X failed (%d)\n", rc
);
6489 /* Log MSI-X vector assignment */
6490 for (index
= 0; index
< phba
->sli4_hba
.cfg_eqn
; index
++)
6491 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6492 "0489 MSI-X entry[%d]: vector=x%x "
6493 "message=%d\n", index
,
6494 phba
->sli4_hba
.msix_entries
[index
].vector
,
6495 phba
->sli4_hba
.msix_entries
[index
].entry
);
6497 * Assign MSI-X vectors to interrupt handlers
6500 /* The first vector must associated to slow-path handler for MQ */
6501 rc
= request_irq(phba
->sli4_hba
.msix_entries
[0].vector
,
6502 &lpfc_sli4_sp_intr_handler
, IRQF_SHARED
,
6503 LPFC_SP_DRIVER_HANDLER_NAME
, phba
);
6505 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6506 "0485 MSI-X slow-path request_irq failed "
6511 /* The rest of the vector(s) are associated to fast-path handler(s) */
6512 for (index
= 1; index
< phba
->sli4_hba
.cfg_eqn
; index
++) {
6513 phba
->sli4_hba
.fcp_eq_hdl
[index
- 1].idx
= index
- 1;
6514 phba
->sli4_hba
.fcp_eq_hdl
[index
- 1].phba
= phba
;
6515 rc
= request_irq(phba
->sli4_hba
.msix_entries
[index
].vector
,
6516 &lpfc_sli4_fp_intr_handler
, IRQF_SHARED
,
6517 LPFC_FP_DRIVER_HANDLER_NAME
,
6518 &phba
->sli4_hba
.fcp_eq_hdl
[index
- 1]);
6520 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6521 "0486 MSI-X fast-path (%d) "
6522 "request_irq failed (%d)\n", index
, rc
);
6530 /* free the irq already requested */
6531 for (--index
; index
>= 1; index
--)
6532 free_irq(phba
->sli4_hba
.msix_entries
[index
- 1].vector
,
6533 &phba
->sli4_hba
.fcp_eq_hdl
[index
- 1]);
6535 /* free the irq already requested */
6536 free_irq(phba
->sli4_hba
.msix_entries
[0].vector
, phba
);
6539 /* Unconfigure MSI-X capability structure */
6540 pci_disable_msix(phba
->pcidev
);
6545 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
6546 * @phba: pointer to lpfc hba data structure.
6548 * This routine is invoked to release the MSI-X vectors and then disable the
6549 * MSI-X interrupt mode to device with SLI-4 interface spec.
6552 lpfc_sli4_disable_msix(struct lpfc_hba
*phba
)
6556 /* Free up MSI-X multi-message vectors */
6557 free_irq(phba
->sli4_hba
.msix_entries
[0].vector
, phba
);
6559 for (index
= 1; index
< phba
->sli4_hba
.cfg_eqn
; index
++)
6560 free_irq(phba
->sli4_hba
.msix_entries
[index
].vector
,
6561 &phba
->sli4_hba
.fcp_eq_hdl
[index
- 1]);
6563 pci_disable_msix(phba
->pcidev
);
6569 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
6570 * @phba: pointer to lpfc hba data structure.
6572 * This routine is invoked to enable the MSI interrupt mode to device with
6573 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
6574 * to enable the MSI vector. The device driver is responsible for calling
6575 * the request_irq() to register MSI vector with a interrupt the handler,
6576 * which is done in this function.
6580 * other values - error
6583 lpfc_sli4_enable_msi(struct lpfc_hba
*phba
)
6587 rc
= pci_enable_msi(phba
->pcidev
);
6589 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6590 "0487 PCI enable MSI mode success.\n");
6592 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6593 "0488 PCI enable MSI mode failed (%d)\n", rc
);
6597 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
6598 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
6600 pci_disable_msi(phba
->pcidev
);
6601 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6602 "0490 MSI request_irq failed (%d)\n", rc
);
6605 for (index
= 0; index
< phba
->cfg_fcp_eq_count
; index
++) {
6606 phba
->sli4_hba
.fcp_eq_hdl
[index
].idx
= index
;
6607 phba
->sli4_hba
.fcp_eq_hdl
[index
].phba
= phba
;
6614 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
6615 * @phba: pointer to lpfc hba data structure.
6617 * This routine is invoked to disable the MSI interrupt mode to device with
6618 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
6619 * done request_irq() on before calling pci_disable_msi(). Failure to do so
6620 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
6624 lpfc_sli4_disable_msi(struct lpfc_hba
*phba
)
6626 free_irq(phba
->pcidev
->irq
, phba
);
6627 pci_disable_msi(phba
->pcidev
);
6632 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
6633 * @phba: pointer to lpfc hba data structure.
6635 * This routine is invoked to enable device interrupt and associate driver's
6636 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
6637 * interface spec. Depends on the interrupt mode configured to the driver,
6638 * the driver will try to fallback from the configured interrupt mode to an
6639 * interrupt mode which is supported by the platform, kernel, and device in
6641 * MSI-X -> MSI -> IRQ.
6645 * other values - error
6648 lpfc_sli4_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
6650 uint32_t intr_mode
= LPFC_INTR_ERROR
;
6653 if (cfg_mode
== 2) {
6654 /* Preparation before conf_msi mbox cmd */
6657 /* Now, try to enable MSI-X interrupt mode */
6658 retval
= lpfc_sli4_enable_msix(phba
);
6660 /* Indicate initialization to MSI-X mode */
6661 phba
->intr_type
= MSIX
;
6667 /* Fallback to MSI if MSI-X initialization failed */
6668 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
6669 retval
= lpfc_sli4_enable_msi(phba
);
6671 /* Indicate initialization to MSI mode */
6672 phba
->intr_type
= MSI
;
6677 /* Fallback to INTx if both MSI-X/MSI initalization failed */
6678 if (phba
->intr_type
== NONE
) {
6679 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
6680 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
6682 /* Indicate initialization to INTx mode */
6683 phba
->intr_type
= INTx
;
6685 for (index
= 0; index
< phba
->cfg_fcp_eq_count
;
6687 phba
->sli4_hba
.fcp_eq_hdl
[index
].idx
= index
;
6688 phba
->sli4_hba
.fcp_eq_hdl
[index
].phba
= phba
;
6696 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
6697 * @phba: pointer to lpfc hba data structure.
6699 * This routine is invoked to disable device interrupt and disassociate
6700 * the driver's interrupt handler(s) from interrupt vector(s) to device
6701 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
6702 * will release the interrupt vector(s) for the message signaled interrupt.
6705 lpfc_sli4_disable_intr(struct lpfc_hba
*phba
)
6707 /* Disable the currently initialized interrupt mode */
6708 if (phba
->intr_type
== MSIX
)
6709 lpfc_sli4_disable_msix(phba
);
6710 else if (phba
->intr_type
== MSI
)
6711 lpfc_sli4_disable_msi(phba
);
6712 else if (phba
->intr_type
== INTx
)
6713 free_irq(phba
->pcidev
->irq
, phba
);
6715 /* Reset interrupt management states */
6716 phba
->intr_type
= NONE
;
6717 phba
->sli
.slistat
.sli_intr
= 0;
6723 * lpfc_unset_hba - Unset SLI3 hba device initialization
6724 * @phba: pointer to lpfc hba data structure.
6726 * This routine is invoked to unset the HBA device initialization steps to
6727 * a device with SLI-3 interface spec.
6730 lpfc_unset_hba(struct lpfc_hba
*phba
)
6732 struct lpfc_vport
*vport
= phba
->pport
;
6733 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6735 spin_lock_irq(shost
->host_lock
);
6736 vport
->load_flag
|= FC_UNLOADING
;
6737 spin_unlock_irq(shost
->host_lock
);
6739 lpfc_stop_hba_timers(phba
);
6741 phba
->pport
->work_port_events
= 0;
6743 lpfc_sli_hba_down(phba
);
6745 lpfc_sli_brdrestart(phba
);
6747 lpfc_sli_disable_intr(phba
);
6753 * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
6754 * @phba: pointer to lpfc hba data structure.
6756 * This routine is invoked to unset the HBA device initialization steps to
6757 * a device with SLI-4 interface spec.
6760 lpfc_sli4_unset_hba(struct lpfc_hba
*phba
)
6762 struct lpfc_vport
*vport
= phba
->pport
;
6763 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6765 spin_lock_irq(shost
->host_lock
);
6766 vport
->load_flag
|= FC_UNLOADING
;
6767 spin_unlock_irq(shost
->host_lock
);
6769 phba
->pport
->work_port_events
= 0;
6771 lpfc_sli4_hba_down(phba
);
6773 lpfc_sli4_disable_intr(phba
);
6779 * lpfc_sli4_hba_unset - Unset the fcoe hba
6780 * @phba: Pointer to HBA context object.
6782 * This function is called in the SLI4 code path to reset the HBA's FCoE
6783 * function. The caller is not required to hold any lock. This routine
6784 * issues PCI function reset mailbox command to reset the FCoE function.
6785 * At the end of the function, it calls lpfc_hba_down_post function to
6786 * free any pending commands.
6789 lpfc_sli4_hba_unset(struct lpfc_hba
*phba
)
6792 LPFC_MBOXQ_t
*mboxq
;
6794 lpfc_stop_hba_timers(phba
);
6795 phba
->sli4_hba
.intr_enable
= 0;
6798 * Gracefully wait out the potential current outstanding asynchronous
6802 /* First, block any pending async mailbox command from posted */
6803 spin_lock_irq(&phba
->hbalock
);
6804 phba
->sli
.sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
6805 spin_unlock_irq(&phba
->hbalock
);
6806 /* Now, trying to wait it out if we can */
6807 while (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
6809 if (++wait_cnt
> LPFC_ACTIVE_MBOX_WAIT_CNT
)
6812 /* Forcefully release the outstanding mailbox command if timed out */
6813 if (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
6814 spin_lock_irq(&phba
->hbalock
);
6815 mboxq
= phba
->sli
.mbox_active
;
6816 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
6817 __lpfc_mbox_cmpl_put(phba
, mboxq
);
6818 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
6819 phba
->sli
.mbox_active
= NULL
;
6820 spin_unlock_irq(&phba
->hbalock
);
6823 /* Tear down the queues in the HBA */
6824 lpfc_sli4_queue_unset(phba
);
6826 /* Disable PCI subsystem interrupt */
6827 lpfc_sli4_disable_intr(phba
);
6829 /* Stop kthread signal shall trigger work_done one more time */
6830 kthread_stop(phba
->worker_thread
);
6832 /* Stop the SLI4 device port */
6833 phba
->pport
->work_port_events
= 0;
6837 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
6838 * @pdev: pointer to PCI device
6839 * @pid: pointer to PCI device identifier
6841 * This routine is to be called to attach a device with SLI-3 interface spec
6842 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
6843 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
6844 * information of the device and driver to see if the driver state that it can
6845 * support this kind of device. If the match is successful, the driver core
6846 * invokes this routine. If this routine determines it can claim the HBA, it
6847 * does all the initialization that it needs to do to handle the HBA properly.
6850 * 0 - driver can claim the device
6851 * negative value - driver can not claim the device
6853 static int __devinit
6854 lpfc_pci_probe_one_s3(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
6856 struct lpfc_hba
*phba
;
6857 struct lpfc_vport
*vport
= NULL
;
6858 struct Scsi_Host
*shost
= NULL
;
6860 uint32_t cfg_mode
, intr_mode
;
6862 /* Allocate memory for HBA structure */
6863 phba
= lpfc_hba_alloc(pdev
);
6867 /* Perform generic PCI device enabling operation */
6868 error
= lpfc_enable_pci_dev(phba
);
6870 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6871 "1401 Failed to enable pci device.\n");
6875 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
6876 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_LP
);
6878 goto out_disable_pci_dev
;
6880 /* Set up SLI-3 specific device PCI memory space */
6881 error
= lpfc_sli_pci_mem_setup(phba
);
6883 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6884 "1402 Failed to set up pci memory space.\n");
6885 goto out_disable_pci_dev
;
6888 /* Set up phase-1 common device driver resources */
6889 error
= lpfc_setup_driver_resource_phase1(phba
);
6891 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6892 "1403 Failed to set up driver resource.\n");
6893 goto out_unset_pci_mem_s3
;
6896 /* Set up SLI-3 specific device driver resources */
6897 error
= lpfc_sli_driver_resource_setup(phba
);
6899 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6900 "1404 Failed to set up driver resource.\n");
6901 goto out_unset_pci_mem_s3
;
6904 /* Initialize and populate the iocb list per host */
6905 error
= lpfc_init_iocb_list(phba
, LPFC_IOCB_LIST_CNT
);
6907 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6908 "1405 Failed to initialize iocb list.\n");
6909 goto out_unset_driver_resource_s3
;
6912 /* Set up common device driver resources */
6913 error
= lpfc_setup_driver_resource_phase2(phba
);
6915 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6916 "1406 Failed to set up driver resource.\n");
6917 goto out_free_iocb_list
;
6920 /* Create SCSI host to the physical port */
6921 error
= lpfc_create_shost(phba
);
6923 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6924 "1407 Failed to create scsi host.\n");
6925 goto out_unset_driver_resource
;
6928 /* Configure sysfs attributes */
6929 vport
= phba
->pport
;
6930 error
= lpfc_alloc_sysfs_attr(vport
);
6932 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6933 "1476 Failed to allocate sysfs attr\n");
6934 goto out_destroy_shost
;
6937 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
6938 /* Now, trying to enable interrupt and bring up the device */
6939 cfg_mode
= phba
->cfg_use_msi
;
6941 /* Put device to a known state before enabling interrupt */
6942 lpfc_stop_port(phba
);
6943 /* Configure and enable interrupt */
6944 intr_mode
= lpfc_sli_enable_intr(phba
, cfg_mode
);
6945 if (intr_mode
== LPFC_INTR_ERROR
) {
6946 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6947 "0431 Failed to enable interrupt.\n");
6949 goto out_free_sysfs_attr
;
6951 /* SLI-3 HBA setup */
6952 if (lpfc_sli_hba_setup(phba
)) {
6953 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6954 "1477 Failed to set up hba\n");
6956 goto out_remove_device
;
6959 /* Wait 50ms for the interrupts of previous mailbox commands */
6961 /* Check active interrupts on message signaled interrupts */
6962 if (intr_mode
== 0 ||
6963 phba
->sli
.slistat
.sli_intr
> LPFC_MSIX_VECTORS
) {
6964 /* Log the current active interrupt mode */
6965 phba
->intr_mode
= intr_mode
;
6966 lpfc_log_intr_mode(phba
, intr_mode
);
6969 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6970 "0447 Configure interrupt mode (%d) "
6971 "failed active interrupt test.\n",
6973 /* Disable the current interrupt mode */
6974 lpfc_sli_disable_intr(phba
);
6975 /* Try next level of interrupt mode */
6976 cfg_mode
= --intr_mode
;
6980 /* Perform post initialization setup */
6981 lpfc_post_init_setup(phba
);
6983 /* Check if there are static vports to be created. */
6984 lpfc_create_static_vport(phba
);
6989 lpfc_unset_hba(phba
);
6990 out_free_sysfs_attr
:
6991 lpfc_free_sysfs_attr(vport
);
6993 lpfc_destroy_shost(phba
);
6994 out_unset_driver_resource
:
6995 lpfc_unset_driver_resource_phase2(phba
);
6997 lpfc_free_iocb_list(phba
);
6998 out_unset_driver_resource_s3
:
6999 lpfc_sli_driver_resource_unset(phba
);
7000 out_unset_pci_mem_s3
:
7001 lpfc_sli_pci_mem_unset(phba
);
7002 out_disable_pci_dev
:
7003 lpfc_disable_pci_dev(phba
);
7005 scsi_host_put(shost
);
7007 lpfc_hba_free(phba
);
7012 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
7013 * @pdev: pointer to PCI device
7015 * This routine is to be called to disattach a device with SLI-3 interface
7016 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
7017 * removed from PCI bus, it performs all the necessary cleanup for the HBA
7018 * device to be removed from the PCI subsystem properly.
7020 static void __devexit
7021 lpfc_pci_remove_one_s3(struct pci_dev
*pdev
)
7023 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7024 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
7025 struct lpfc_vport
**vports
;
7026 struct lpfc_hba
*phba
= vport
->phba
;
7028 int bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
7030 spin_lock_irq(&phba
->hbalock
);
7031 vport
->load_flag
|= FC_UNLOADING
;
7032 spin_unlock_irq(&phba
->hbalock
);
7034 lpfc_free_sysfs_attr(vport
);
7036 /* Release all the vports against this physical port */
7037 vports
= lpfc_create_vport_work_array(phba
);
7039 for (i
= 1; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
7040 fc_vport_terminate(vports
[i
]->fc_vport
);
7041 lpfc_destroy_vport_work_array(phba
, vports
);
7043 /* Remove FC host and then SCSI host with the physical port */
7044 fc_remove_host(shost
);
7045 scsi_remove_host(shost
);
7046 lpfc_cleanup(vport
);
7049 * Bring down the SLI Layer. This step disable all interrupts,
7050 * clears the rings, discards all mailbox commands, and resets
7054 /* HBA interrupt will be diabled after this call */
7055 lpfc_sli_hba_down(phba
);
7056 /* Stop kthread signal shall trigger work_done one more time */
7057 kthread_stop(phba
->worker_thread
);
7058 /* Final cleanup of txcmplq and reset the HBA */
7059 lpfc_sli_brdrestart(phba
);
7061 lpfc_stop_hba_timers(phba
);
7062 spin_lock_irq(&phba
->hbalock
);
7063 list_del_init(&vport
->listentry
);
7064 spin_unlock_irq(&phba
->hbalock
);
7066 lpfc_debugfs_terminate(vport
);
7068 /* Disable interrupt */
7069 lpfc_sli_disable_intr(phba
);
7071 pci_set_drvdata(pdev
, NULL
);
7072 scsi_host_put(shost
);
7075 * Call scsi_free before mem_free since scsi bufs are released to their
7076 * corresponding pools here.
7078 lpfc_scsi_free(phba
);
7079 lpfc_mem_free_all(phba
);
7081 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
7082 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
7084 /* Free resources associated with SLI2 interface */
7085 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
7086 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
7088 /* unmap adapter SLIM and Control Registers */
7089 iounmap(phba
->ctrl_regs_memmap_p
);
7090 iounmap(phba
->slim_memmap_p
);
7092 lpfc_hba_free(phba
);
7094 pci_release_selected_regions(pdev
, bars
);
7095 pci_disable_device(pdev
);
7099 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
7100 * @pdev: pointer to PCI device
7101 * @msg: power management message
7103 * This routine is to be called from the kernel's PCI subsystem to support
7104 * system Power Management (PM) to device with SLI-3 interface spec. When
7105 * PM invokes this method, it quiesces the device by stopping the driver's
7106 * worker thread for the device, turning off device's interrupt and DMA,
7107 * and bring the device offline. Note that as the driver implements the
7108 * minimum PM requirements to a power-aware driver's PM support for the
7109 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
7110 * to the suspend() method call will be treated as SUSPEND and the driver will
7111 * fully reinitialize its device during resume() method call, the driver will
7112 * set device to PCI_D3hot state in PCI config space instead of setting it
7113 * according to the @msg provided by the PM.
7116 * 0 - driver suspended the device
7120 lpfc_pci_suspend_one_s3(struct pci_dev
*pdev
, pm_message_t msg
)
7122 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7123 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
7125 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7126 "0473 PCI device Power Management suspend.\n");
7128 /* Bring down the device */
7129 lpfc_offline_prep(phba
);
7131 kthread_stop(phba
->worker_thread
);
7133 /* Disable interrupt from device */
7134 lpfc_sli_disable_intr(phba
);
7136 /* Save device state to PCI config space */
7137 pci_save_state(pdev
);
7138 pci_set_power_state(pdev
, PCI_D3hot
);
7144 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
7145 * @pdev: pointer to PCI device
7147 * This routine is to be called from the kernel's PCI subsystem to support
7148 * system Power Management (PM) to device with SLI-3 interface spec. When PM
7149 * invokes this method, it restores the device's PCI config space state and
7150 * fully reinitializes the device and brings it online. Note that as the
7151 * driver implements the minimum PM requirements to a power-aware driver's
7152 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
7153 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
7154 * driver will fully reinitialize its device during resume() method call,
7155 * the device will be set to PCI_D0 directly in PCI config space before
7156 * restoring the state.
7159 * 0 - driver suspended the device
7163 lpfc_pci_resume_one_s3(struct pci_dev
*pdev
)
7165 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7166 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
7170 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7171 "0452 PCI device Power Management resume.\n");
7173 /* Restore device state from PCI config space */
7174 pci_set_power_state(pdev
, PCI_D0
);
7175 pci_restore_state(pdev
);
7177 if (pdev
->is_busmaster
)
7178 pci_set_master(pdev
);
7180 /* Startup the kernel thread for this host adapter. */
7181 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
7182 "lpfc_worker_%d", phba
->brd_no
);
7183 if (IS_ERR(phba
->worker_thread
)) {
7184 error
= PTR_ERR(phba
->worker_thread
);
7185 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7186 "0434 PM resume failed to start worker "
7187 "thread: error=x%x.\n", error
);
7191 /* Configure and enable interrupt */
7192 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
7193 if (intr_mode
== LPFC_INTR_ERROR
) {
7194 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7195 "0430 PM resume Failed to enable interrupt\n");
7198 phba
->intr_mode
= intr_mode
;
7200 /* Restart HBA and bring it online */
7201 lpfc_sli_brdrestart(phba
);
7204 /* Log the current active interrupt mode */
7205 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
7211 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
7212 * @phba: pointer to lpfc hba data structure.
7214 * This routine is called to prepare the SLI3 device for PCI slot recover. It
7215 * aborts and stops all the on-going I/Os on the pci device.
7218 lpfc_sli_prep_dev_for_recover(struct lpfc_hba
*phba
)
7220 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7221 "2723 PCI channel I/O abort preparing for recovery\n");
7222 /* Prepare for bringing HBA offline */
7223 lpfc_offline_prep(phba
);
7224 /* Clear sli active flag to prevent sysfs access to HBA */
7225 spin_lock_irq(&phba
->hbalock
);
7226 phba
->sli
.sli_flag
&= ~LPFC_SLI_ACTIVE
;
7227 spin_unlock_irq(&phba
->hbalock
);
7228 /* Stop and flush all I/Os and bring HBA offline */
7233 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
7234 * @phba: pointer to lpfc hba data structure.
7236 * This routine is called to prepare the SLI3 device for PCI slot reset. It
7237 * disables the device interrupt and pci device, and aborts the internal FCP
7241 lpfc_sli_prep_dev_for_reset(struct lpfc_hba
*phba
)
7243 struct lpfc_sli
*psli
= &phba
->sli
;
7244 struct lpfc_sli_ring
*pring
;
7246 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7247 "2710 PCI channel disable preparing for reset\n");
7248 /* Disable interrupt and pci device */
7249 lpfc_sli_disable_intr(phba
);
7250 pci_disable_device(phba
->pcidev
);
7252 * There may be I/Os dropped by the firmware.
7253 * Error iocb (I/O) on txcmplq and let the SCSI layer
7254 * retry it after re-establishing link.
7256 pring
= &psli
->ring
[psli
->fcp_ring
];
7257 lpfc_sli_abort_iocb_ring(phba
, pring
);
7261 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
7262 * @phba: pointer to lpfc hba data structure.
7264 * This routine is called to prepare the SLI3 device for PCI slot permanently
7265 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
7269 lpfc_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
7271 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7272 "2711 PCI channel permanent disable for failure\n");
7273 /* Clean up all driver's outstanding SCSI I/Os */
7274 lpfc_sli_flush_fcp_rings(phba
);
7278 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
7279 * @pdev: pointer to PCI device.
7280 * @state: the current PCI connection state.
7282 * This routine is called from the PCI subsystem for I/O error handling to
7283 * device with SLI-3 interface spec. This function is called by the PCI
7284 * subsystem after a PCI bus error affecting this device has been detected.
7285 * When this function is invoked, it will need to stop all the I/Os and
7286 * interrupt(s) to the device. Once that is done, it will return
7287 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
7291 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
7292 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
7293 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7295 static pci_ers_result_t
7296 lpfc_io_error_detected_s3(struct pci_dev
*pdev
, pci_channel_state_t state
)
7298 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7299 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
7301 /* Block all SCSI devices' I/Os on the host */
7302 lpfc_scsi_dev_block(phba
);
7305 case pci_channel_io_normal
:
7306 /* Non-fatal error, prepare for recovery */
7307 lpfc_sli_prep_dev_for_recover(phba
);
7308 return PCI_ERS_RESULT_CAN_RECOVER
;
7309 case pci_channel_io_frozen
:
7310 /* Fatal error, prepare for slot reset */
7311 lpfc_sli_prep_dev_for_reset(phba
);
7312 return PCI_ERS_RESULT_NEED_RESET
;
7313 case pci_channel_io_perm_failure
:
7314 /* Permanent failure, prepare for device down */
7315 lpfc_prep_dev_for_perm_failure(phba
);
7316 return PCI_ERS_RESULT_DISCONNECT
;
7318 /* Unknown state, prepare and request slot reset */
7319 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7320 "0472 Unknown PCI error state: x%x\n", state
);
7321 lpfc_sli_prep_dev_for_reset(phba
);
7322 return PCI_ERS_RESULT_NEED_RESET
;
7327 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
7328 * @pdev: pointer to PCI device.
7330 * This routine is called from the PCI subsystem for error handling to
7331 * device with SLI-3 interface spec. This is called after PCI bus has been
7332 * reset to restart the PCI card from scratch, as if from a cold-boot.
7333 * During the PCI subsystem error recovery, after driver returns
7334 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
7335 * recovery and then call this routine before calling the .resume method
7336 * to recover the device. This function will initialize the HBA device,
7337 * enable the interrupt, but it will just put the HBA to offline state
7338 * without passing any I/O traffic.
7341 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
7342 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7344 static pci_ers_result_t
7345 lpfc_io_slot_reset_s3(struct pci_dev
*pdev
)
7347 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7348 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
7349 struct lpfc_sli
*psli
= &phba
->sli
;
7352 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
7353 if (pci_enable_device_mem(pdev
)) {
7354 printk(KERN_ERR
"lpfc: Cannot re-enable "
7355 "PCI device after reset.\n");
7356 return PCI_ERS_RESULT_DISCONNECT
;
7359 pci_restore_state(pdev
);
7360 if (pdev
->is_busmaster
)
7361 pci_set_master(pdev
);
7363 spin_lock_irq(&phba
->hbalock
);
7364 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
7365 spin_unlock_irq(&phba
->hbalock
);
7367 /* Configure and enable interrupt */
7368 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
7369 if (intr_mode
== LPFC_INTR_ERROR
) {
7370 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7371 "0427 Cannot re-enable interrupt after "
7373 return PCI_ERS_RESULT_DISCONNECT
;
7375 phba
->intr_mode
= intr_mode
;
7377 /* Take device offline; this will perform cleanup */
7379 lpfc_sli_brdrestart(phba
);
7381 /* Log the current active interrupt mode */
7382 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
7384 return PCI_ERS_RESULT_RECOVERED
;
7388 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
7389 * @pdev: pointer to PCI device
7391 * This routine is called from the PCI subsystem for error handling to device
7392 * with SLI-3 interface spec. It is called when kernel error recovery tells
7393 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
7394 * error recovery. After this call, traffic can start to flow from this device
7398 lpfc_io_resume_s3(struct pci_dev
*pdev
)
7400 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7401 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
7403 /* Bring the device online */
7406 /* Clean up Advanced Error Reporting (AER) if needed */
7407 if (phba
->hba_flag
& HBA_AER_ENABLED
)
7408 pci_cleanup_aer_uncorrect_error_status(pdev
);
7412 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
7413 * @phba: pointer to lpfc hba data structure.
7415 * returns the number of ELS/CT IOCBs to reserve
7418 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba
*phba
)
7420 int max_xri
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
7422 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
7425 else if (max_xri
<= 256)
7427 else if (max_xri
<= 512)
7429 else if (max_xri
<= 1024)
7438 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
7439 * @pdev: pointer to PCI device
7440 * @pid: pointer to PCI device identifier
7442 * This routine is called from the kernel's PCI subsystem to device with
7443 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
7444 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
7445 * information of the device and driver to see if the driver state that it
7446 * can support this kind of device. If the match is successful, the driver
7447 * core invokes this routine. If this routine determines it can claim the HBA,
7448 * it does all the initialization that it needs to do to handle the HBA
7452 * 0 - driver can claim the device
7453 * negative value - driver can not claim the device
7455 static int __devinit
7456 lpfc_pci_probe_one_s4(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
7458 struct lpfc_hba
*phba
;
7459 struct lpfc_vport
*vport
= NULL
;
7460 struct Scsi_Host
*shost
= NULL
;
7462 uint32_t cfg_mode
, intr_mode
;
7465 /* Allocate memory for HBA structure */
7466 phba
= lpfc_hba_alloc(pdev
);
7470 /* Perform generic PCI device enabling operation */
7471 error
= lpfc_enable_pci_dev(phba
);
7473 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7474 "1409 Failed to enable pci device.\n");
7478 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
7479 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_OC
);
7481 goto out_disable_pci_dev
;
7483 /* Set up SLI-4 specific device PCI memory space */
7484 error
= lpfc_sli4_pci_mem_setup(phba
);
7486 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7487 "1410 Failed to set up pci memory space.\n");
7488 goto out_disable_pci_dev
;
7491 /* Set up phase-1 common device driver resources */
7492 error
= lpfc_setup_driver_resource_phase1(phba
);
7494 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7495 "1411 Failed to set up driver resource.\n");
7496 goto out_unset_pci_mem_s4
;
7499 /* Set up SLI-4 Specific device driver resources */
7500 error
= lpfc_sli4_driver_resource_setup(phba
);
7502 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7503 "1412 Failed to set up driver resource.\n");
7504 goto out_unset_pci_mem_s4
;
7507 /* Initialize and populate the iocb list per host */
7508 error
= lpfc_init_iocb_list(phba
,
7509 phba
->sli4_hba
.max_cfg_param
.max_xri
);
7511 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7512 "1413 Failed to initialize iocb list.\n");
7513 goto out_unset_driver_resource_s4
;
7516 /* Set up common device driver resources */
7517 error
= lpfc_setup_driver_resource_phase2(phba
);
7519 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7520 "1414 Failed to set up driver resource.\n");
7521 goto out_free_iocb_list
;
7524 /* Create SCSI host to the physical port */
7525 error
= lpfc_create_shost(phba
);
7527 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7528 "1415 Failed to create scsi host.\n");
7529 goto out_unset_driver_resource
;
7532 /* Configure sysfs attributes */
7533 vport
= phba
->pport
;
7534 error
= lpfc_alloc_sysfs_attr(vport
);
7536 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7537 "1416 Failed to allocate sysfs attr\n");
7538 goto out_destroy_shost
;
7541 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
7542 /* Now, trying to enable interrupt and bring up the device */
7543 cfg_mode
= phba
->cfg_use_msi
;
7545 /* Put device to a known state before enabling interrupt */
7546 lpfc_stop_port(phba
);
7547 /* Configure and enable interrupt */
7548 intr_mode
= lpfc_sli4_enable_intr(phba
, cfg_mode
);
7549 if (intr_mode
== LPFC_INTR_ERROR
) {
7550 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7551 "0426 Failed to enable interrupt.\n");
7553 goto out_free_sysfs_attr
;
7555 /* Default to single FCP EQ for non-MSI-X */
7556 if (phba
->intr_type
!= MSIX
)
7557 phba
->cfg_fcp_eq_count
= 1;
7558 /* Set up SLI-4 HBA */
7559 if (lpfc_sli4_hba_setup(phba
)) {
7560 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7561 "1421 Failed to set up hba\n");
7563 goto out_disable_intr
;
7566 /* Send NOP mbx cmds for non-INTx mode active interrupt test */
7568 mcnt
= lpfc_sli4_send_nop_mbox_cmds(phba
,
7571 /* Check active interrupts received only for MSI/MSI-X */
7572 if (intr_mode
== 0 ||
7573 phba
->sli
.slistat
.sli_intr
>= LPFC_ACT_INTR_CNT
) {
7574 /* Log the current active interrupt mode */
7575 phba
->intr_mode
= intr_mode
;
7576 lpfc_log_intr_mode(phba
, intr_mode
);
7579 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7580 "0451 Configure interrupt mode (%d) "
7581 "failed active interrupt test.\n",
7583 /* Unset the preivous SLI-4 HBA setup */
7584 lpfc_sli4_unset_hba(phba
);
7585 /* Try next level of interrupt mode */
7586 cfg_mode
= --intr_mode
;
7589 /* Perform post initialization setup */
7590 lpfc_post_init_setup(phba
);
7592 /* Check if there are static vports to be created. */
7593 lpfc_create_static_vport(phba
);
7598 lpfc_sli4_disable_intr(phba
);
7599 out_free_sysfs_attr
:
7600 lpfc_free_sysfs_attr(vport
);
7602 lpfc_destroy_shost(phba
);
7603 out_unset_driver_resource
:
7604 lpfc_unset_driver_resource_phase2(phba
);
7606 lpfc_free_iocb_list(phba
);
7607 out_unset_driver_resource_s4
:
7608 lpfc_sli4_driver_resource_unset(phba
);
7609 out_unset_pci_mem_s4
:
7610 lpfc_sli4_pci_mem_unset(phba
);
7611 out_disable_pci_dev
:
7612 lpfc_disable_pci_dev(phba
);
7614 scsi_host_put(shost
);
7616 lpfc_hba_free(phba
);
7621 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
7622 * @pdev: pointer to PCI device
7624 * This routine is called from the kernel's PCI subsystem to device with
7625 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
7626 * removed from PCI bus, it performs all the necessary cleanup for the HBA
7627 * device to be removed from the PCI subsystem properly.
7629 static void __devexit
7630 lpfc_pci_remove_one_s4(struct pci_dev
*pdev
)
7632 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7633 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
7634 struct lpfc_vport
**vports
;
7635 struct lpfc_hba
*phba
= vport
->phba
;
7638 /* Mark the device unloading flag */
7639 spin_lock_irq(&phba
->hbalock
);
7640 vport
->load_flag
|= FC_UNLOADING
;
7641 spin_unlock_irq(&phba
->hbalock
);
7643 /* Free the HBA sysfs attributes */
7644 lpfc_free_sysfs_attr(vport
);
7646 /* Release all the vports against this physical port */
7647 vports
= lpfc_create_vport_work_array(phba
);
7649 for (i
= 1; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
7650 fc_vport_terminate(vports
[i
]->fc_vport
);
7651 lpfc_destroy_vport_work_array(phba
, vports
);
7653 /* Remove FC host and then SCSI host with the physical port */
7654 fc_remove_host(shost
);
7655 scsi_remove_host(shost
);
7657 /* Perform cleanup on the physical port */
7658 lpfc_cleanup(vport
);
7661 * Bring down the SLI Layer. This step disables all interrupts,
7662 * clears the rings, discards all mailbox commands, and resets
7663 * the HBA FCoE function.
7665 lpfc_debugfs_terminate(vport
);
7666 lpfc_sli4_hba_unset(phba
);
7668 spin_lock_irq(&phba
->hbalock
);
7669 list_del_init(&vport
->listentry
);
7670 spin_unlock_irq(&phba
->hbalock
);
7672 /* Call scsi_free before lpfc_sli4_driver_resource_unset since scsi
7673 * buffers are released to their corresponding pools here.
7675 lpfc_scsi_free(phba
);
7676 lpfc_sli4_driver_resource_unset(phba
);
7678 /* Unmap adapter Control and Doorbell registers */
7679 lpfc_sli4_pci_mem_unset(phba
);
7681 /* Release PCI resources and disable device's PCI function */
7682 scsi_host_put(shost
);
7683 lpfc_disable_pci_dev(phba
);
7685 /* Finally, free the driver's device data structure */
7686 lpfc_hba_free(phba
);
7692 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
7693 * @pdev: pointer to PCI device
7694 * @msg: power management message
7696 * This routine is called from the kernel's PCI subsystem to support system
7697 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
7698 * this method, it quiesces the device by stopping the driver's worker
7699 * thread for the device, turning off device's interrupt and DMA, and bring
7700 * the device offline. Note that as the driver implements the minimum PM
7701 * requirements to a power-aware driver's PM support for suspend/resume -- all
7702 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
7703 * method call will be treated as SUSPEND and the driver will fully
7704 * reinitialize its device during resume() method call, the driver will set
7705 * device to PCI_D3hot state in PCI config space instead of setting it
7706 * according to the @msg provided by the PM.
7709 * 0 - driver suspended the device
7713 lpfc_pci_suspend_one_s4(struct pci_dev
*pdev
, pm_message_t msg
)
7715 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7716 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
7718 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7719 "0298 PCI device Power Management suspend.\n");
7721 /* Bring down the device */
7722 lpfc_offline_prep(phba
);
7724 kthread_stop(phba
->worker_thread
);
7726 /* Disable interrupt from device */
7727 lpfc_sli4_disable_intr(phba
);
7729 /* Save device state to PCI config space */
7730 pci_save_state(pdev
);
7731 pci_set_power_state(pdev
, PCI_D3hot
);
7737 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
7738 * @pdev: pointer to PCI device
7740 * This routine is called from the kernel's PCI subsystem to support system
7741 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
7742 * this method, it restores the device's PCI config space state and fully
7743 * reinitializes the device and brings it online. Note that as the driver
7744 * implements the minimum PM requirements to a power-aware driver's PM for
7745 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
7746 * to the suspend() method call will be treated as SUSPEND and the driver
7747 * will fully reinitialize its device during resume() method call, the device
7748 * will be set to PCI_D0 directly in PCI config space before restoring the
7752 * 0 - driver suspended the device
7756 lpfc_pci_resume_one_s4(struct pci_dev
*pdev
)
7758 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7759 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
7763 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7764 "0292 PCI device Power Management resume.\n");
7766 /* Restore device state from PCI config space */
7767 pci_set_power_state(pdev
, PCI_D0
);
7768 pci_restore_state(pdev
);
7769 if (pdev
->is_busmaster
)
7770 pci_set_master(pdev
);
7772 /* Startup the kernel thread for this host adapter. */
7773 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
7774 "lpfc_worker_%d", phba
->brd_no
);
7775 if (IS_ERR(phba
->worker_thread
)) {
7776 error
= PTR_ERR(phba
->worker_thread
);
7777 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7778 "0293 PM resume failed to start worker "
7779 "thread: error=x%x.\n", error
);
7783 /* Configure and enable interrupt */
7784 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
7785 if (intr_mode
== LPFC_INTR_ERROR
) {
7786 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7787 "0294 PM resume Failed to enable interrupt\n");
7790 phba
->intr_mode
= intr_mode
;
7792 /* Restart HBA and bring it online */
7793 lpfc_sli_brdrestart(phba
);
7796 /* Log the current active interrupt mode */
7797 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
7803 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
7804 * @pdev: pointer to PCI device.
7805 * @state: the current PCI connection state.
7807 * This routine is called from the PCI subsystem for error handling to device
7808 * with SLI-4 interface spec. This function is called by the PCI subsystem
7809 * after a PCI bus error affecting this device has been detected. When this
7810 * function is invoked, it will need to stop all the I/Os and interrupt(s)
7811 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
7812 * for the PCI subsystem to perform proper recovery as desired.
7815 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
7816 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7818 static pci_ers_result_t
7819 lpfc_io_error_detected_s4(struct pci_dev
*pdev
, pci_channel_state_t state
)
7821 return PCI_ERS_RESULT_NEED_RESET
;
7825 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
7826 * @pdev: pointer to PCI device.
7828 * This routine is called from the PCI subsystem for error handling to device
7829 * with SLI-4 interface spec. It is called after PCI bus has been reset to
7830 * restart the PCI card from scratch, as if from a cold-boot. During the
7831 * PCI subsystem error recovery, after the driver returns
7832 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
7833 * recovery and then call this routine before calling the .resume method to
7834 * recover the device. This function will initialize the HBA device, enable
7835 * the interrupt, but it will just put the HBA to offline state without
7836 * passing any I/O traffic.
7839 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
7840 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7842 static pci_ers_result_t
7843 lpfc_io_slot_reset_s4(struct pci_dev
*pdev
)
7845 return PCI_ERS_RESULT_RECOVERED
;
7849 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
7850 * @pdev: pointer to PCI device
7852 * This routine is called from the PCI subsystem for error handling to device
7853 * with SLI-4 interface spec. It is called when kernel error recovery tells
7854 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
7855 * error recovery. After this call, traffic can start to flow from this device
7859 lpfc_io_resume_s4(struct pci_dev
*pdev
)
7865 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
7866 * @pdev: pointer to PCI device
7867 * @pid: pointer to PCI device identifier
7869 * This routine is to be registered to the kernel's PCI subsystem. When an
7870 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
7871 * at PCI device-specific information of the device and driver to see if the
7872 * driver state that it can support this kind of device. If the match is
7873 * successful, the driver core invokes this routine. This routine dispatches
7874 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
7875 * do all the initialization that it needs to do to handle the HBA device
7879 * 0 - driver can claim the device
7880 * negative value - driver can not claim the device
7882 static int __devinit
7883 lpfc_pci_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
7886 struct lpfc_sli_intf intf
;
7888 if (pci_read_config_dword(pdev
, LPFC_SLIREV_CONF_WORD
, &intf
.word0
))
7891 if ((bf_get(lpfc_sli_intf_valid
, &intf
) == LPFC_SLI_INTF_VALID
) &&
7892 (bf_get(lpfc_sli_intf_rev
, &intf
) == LPFC_SLIREV_CONF_SLI4
))
7893 rc
= lpfc_pci_probe_one_s4(pdev
, pid
);
7895 rc
= lpfc_pci_probe_one_s3(pdev
, pid
);
7901 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
7902 * @pdev: pointer to PCI device
7904 * This routine is to be registered to the kernel's PCI subsystem. When an
7905 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
7906 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
7907 * remove routine, which will perform all the necessary cleanup for the
7908 * device to be removed from the PCI subsystem properly.
7910 static void __devexit
7911 lpfc_pci_remove_one(struct pci_dev
*pdev
)
7913 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7914 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
7916 switch (phba
->pci_dev_grp
) {
7917 case LPFC_PCI_DEV_LP
:
7918 lpfc_pci_remove_one_s3(pdev
);
7920 case LPFC_PCI_DEV_OC
:
7921 lpfc_pci_remove_one_s4(pdev
);
7924 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7925 "1424 Invalid PCI device group: 0x%x\n",
7933 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
7934 * @pdev: pointer to PCI device
7935 * @msg: power management message
7937 * This routine is to be registered to the kernel's PCI subsystem to support
7938 * system Power Management (PM). When PM invokes this method, it dispatches
7939 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
7940 * suspend the device.
7943 * 0 - driver suspended the device
7947 lpfc_pci_suspend_one(struct pci_dev
*pdev
, pm_message_t msg
)
7949 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7950 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
7953 switch (phba
->pci_dev_grp
) {
7954 case LPFC_PCI_DEV_LP
:
7955 rc
= lpfc_pci_suspend_one_s3(pdev
, msg
);
7957 case LPFC_PCI_DEV_OC
:
7958 rc
= lpfc_pci_suspend_one_s4(pdev
, msg
);
7961 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7962 "1425 Invalid PCI device group: 0x%x\n",
7970 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
7971 * @pdev: pointer to PCI device
7973 * This routine is to be registered to the kernel's PCI subsystem to support
7974 * system Power Management (PM). When PM invokes this method, it dispatches
7975 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
7976 * resume the device.
7979 * 0 - driver suspended the device
7983 lpfc_pci_resume_one(struct pci_dev
*pdev
)
7985 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
7986 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
7989 switch (phba
->pci_dev_grp
) {
7990 case LPFC_PCI_DEV_LP
:
7991 rc
= lpfc_pci_resume_one_s3(pdev
);
7993 case LPFC_PCI_DEV_OC
:
7994 rc
= lpfc_pci_resume_one_s4(pdev
);
7997 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7998 "1426 Invalid PCI device group: 0x%x\n",
8006 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
8007 * @pdev: pointer to PCI device.
8008 * @state: the current PCI connection state.
8010 * This routine is registered to the PCI subsystem for error handling. This
8011 * function is called by the PCI subsystem after a PCI bus error affecting
8012 * this device has been detected. When this routine is invoked, it dispatches
8013 * the action to the proper SLI-3 or SLI-4 device error detected handling
8014 * routine, which will perform the proper error detected operation.
8017 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
8018 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
8020 static pci_ers_result_t
8021 lpfc_io_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
8023 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8024 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8025 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
8027 switch (phba
->pci_dev_grp
) {
8028 case LPFC_PCI_DEV_LP
:
8029 rc
= lpfc_io_error_detected_s3(pdev
, state
);
8031 case LPFC_PCI_DEV_OC
:
8032 rc
= lpfc_io_error_detected_s4(pdev
, state
);
8035 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8036 "1427 Invalid PCI device group: 0x%x\n",
8044 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
8045 * @pdev: pointer to PCI device.
8047 * This routine is registered to the PCI subsystem for error handling. This
8048 * function is called after PCI bus has been reset to restart the PCI card
8049 * from scratch, as if from a cold-boot. When this routine is invoked, it
8050 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
8051 * routine, which will perform the proper device reset.
8054 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
8055 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
8057 static pci_ers_result_t
8058 lpfc_io_slot_reset(struct pci_dev
*pdev
)
8060 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8061 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8062 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
8064 switch (phba
->pci_dev_grp
) {
8065 case LPFC_PCI_DEV_LP
:
8066 rc
= lpfc_io_slot_reset_s3(pdev
);
8068 case LPFC_PCI_DEV_OC
:
8069 rc
= lpfc_io_slot_reset_s4(pdev
);
8072 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8073 "1428 Invalid PCI device group: 0x%x\n",
8081 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
8082 * @pdev: pointer to PCI device
8084 * This routine is registered to the PCI subsystem for error handling. It
8085 * is called when kernel error recovery tells the lpfc driver that it is
8086 * OK to resume normal PCI operation after PCI bus error recovery. When
8087 * this routine is invoked, it dispatches the action to the proper SLI-3
8088 * or SLI-4 device io_resume routine, which will resume the device operation.
8091 lpfc_io_resume(struct pci_dev
*pdev
)
8093 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8094 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8096 switch (phba
->pci_dev_grp
) {
8097 case LPFC_PCI_DEV_LP
:
8098 lpfc_io_resume_s3(pdev
);
8100 case LPFC_PCI_DEV_OC
:
8101 lpfc_io_resume_s4(pdev
);
8104 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8105 "1429 Invalid PCI device group: 0x%x\n",
8112 static struct pci_device_id lpfc_id_table
[] = {
8113 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_VIPER
,
8114 PCI_ANY_ID
, PCI_ANY_ID
, },
8115 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_FIREFLY
,
8116 PCI_ANY_ID
, PCI_ANY_ID
, },
8117 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_THOR
,
8118 PCI_ANY_ID
, PCI_ANY_ID
, },
8119 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PEGASUS
,
8120 PCI_ANY_ID
, PCI_ANY_ID
, },
8121 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_CENTAUR
,
8122 PCI_ANY_ID
, PCI_ANY_ID
, },
8123 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_DRAGONFLY
,
8124 PCI_ANY_ID
, PCI_ANY_ID
, },
8125 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SUPERFLY
,
8126 PCI_ANY_ID
, PCI_ANY_ID
, },
8127 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_RFLY
,
8128 PCI_ANY_ID
, PCI_ANY_ID
, },
8129 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PFLY
,
8130 PCI_ANY_ID
, PCI_ANY_ID
, },
8131 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE
,
8132 PCI_ANY_ID
, PCI_ANY_ID
, },
8133 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_SCSP
,
8134 PCI_ANY_ID
, PCI_ANY_ID
, },
8135 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_DCSP
,
8136 PCI_ANY_ID
, PCI_ANY_ID
, },
8137 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS
,
8138 PCI_ANY_ID
, PCI_ANY_ID
, },
8139 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_SCSP
,
8140 PCI_ANY_ID
, PCI_ANY_ID
, },
8141 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_DCSP
,
8142 PCI_ANY_ID
, PCI_ANY_ID
, },
8143 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BMID
,
8144 PCI_ANY_ID
, PCI_ANY_ID
, },
8145 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BSMB
,
8146 PCI_ANY_ID
, PCI_ANY_ID
, },
8147 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR
,
8148 PCI_ANY_ID
, PCI_ANY_ID
, },
8149 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HORNET
,
8150 PCI_ANY_ID
, PCI_ANY_ID
, },
8151 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_SCSP
,
8152 PCI_ANY_ID
, PCI_ANY_ID
, },
8153 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_DCSP
,
8154 PCI_ANY_ID
, PCI_ANY_ID
, },
8155 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZMID
,
8156 PCI_ANY_ID
, PCI_ANY_ID
, },
8157 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZSMB
,
8158 PCI_ANY_ID
, PCI_ANY_ID
, },
8159 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_TFLY
,
8160 PCI_ANY_ID
, PCI_ANY_ID
, },
8161 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP101
,
8162 PCI_ANY_ID
, PCI_ANY_ID
, },
8163 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP10000S
,
8164 PCI_ANY_ID
, PCI_ANY_ID
, },
8165 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP11000S
,
8166 PCI_ANY_ID
, PCI_ANY_ID
, },
8167 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LPE11000S
,
8168 PCI_ANY_ID
, PCI_ANY_ID
, },
8169 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT
,
8170 PCI_ANY_ID
, PCI_ANY_ID
, },
8171 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_MID
,
8172 PCI_ANY_ID
, PCI_ANY_ID
, },
8173 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SMB
,
8174 PCI_ANY_ID
, PCI_ANY_ID
, },
8175 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_DCSP
,
8176 PCI_ANY_ID
, PCI_ANY_ID
, },
8177 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SCSP
,
8178 PCI_ANY_ID
, PCI_ANY_ID
, },
8179 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_S
,
8180 PCI_ANY_ID
, PCI_ANY_ID
, },
8181 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_VF
,
8182 PCI_ANY_ID
, PCI_ANY_ID
, },
8183 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_PF
,
8184 PCI_ANY_ID
, PCI_ANY_ID
, },
8185 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_S
,
8186 PCI_ANY_ID
, PCI_ANY_ID
, },
8187 {PCI_VENDOR_ID_SERVERENGINE
, PCI_DEVICE_ID_TIGERSHARK
,
8188 PCI_ANY_ID
, PCI_ANY_ID
, },
8189 {PCI_VENDOR_ID_SERVERENGINE
, PCI_DEVICE_ID_TOMCAT
,
8190 PCI_ANY_ID
, PCI_ANY_ID
, },
8191 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_FALCON
,
8192 PCI_ANY_ID
, PCI_ANY_ID
, },
8196 MODULE_DEVICE_TABLE(pci
, lpfc_id_table
);
8198 static struct pci_error_handlers lpfc_err_handler
= {
8199 .error_detected
= lpfc_io_error_detected
,
8200 .slot_reset
= lpfc_io_slot_reset
,
8201 .resume
= lpfc_io_resume
,
8204 static struct pci_driver lpfc_driver
= {
8205 .name
= LPFC_DRIVER_NAME
,
8206 .id_table
= lpfc_id_table
,
8207 .probe
= lpfc_pci_probe_one
,
8208 .remove
= __devexit_p(lpfc_pci_remove_one
),
8209 .suspend
= lpfc_pci_suspend_one
,
8210 .resume
= lpfc_pci_resume_one
,
8211 .err_handler
= &lpfc_err_handler
,
8215 * lpfc_init - lpfc module initialization routine
8217 * This routine is to be invoked when the lpfc module is loaded into the
8218 * kernel. The special kernel macro module_init() is used to indicate the
8219 * role of this routine to the kernel as lpfc module entry point.
8223 * -ENOMEM - FC attach transport failed
8224 * all others - failed
8231 printk(LPFC_MODULE_DESC
"\n");
8232 printk(LPFC_COPYRIGHT
"\n");
8234 if (lpfc_enable_npiv
) {
8235 lpfc_transport_functions
.vport_create
= lpfc_vport_create
;
8236 lpfc_transport_functions
.vport_delete
= lpfc_vport_delete
;
8238 lpfc_transport_template
=
8239 fc_attach_transport(&lpfc_transport_functions
);
8240 if (lpfc_transport_template
== NULL
)
8242 if (lpfc_enable_npiv
) {
8243 lpfc_vport_transport_template
=
8244 fc_attach_transport(&lpfc_vport_transport_functions
);
8245 if (lpfc_vport_transport_template
== NULL
) {
8246 fc_release_transport(lpfc_transport_template
);
8250 error
= pci_register_driver(&lpfc_driver
);
8252 fc_release_transport(lpfc_transport_template
);
8253 if (lpfc_enable_npiv
)
8254 fc_release_transport(lpfc_vport_transport_template
);
8261 * lpfc_exit - lpfc module removal routine
8263 * This routine is invoked when the lpfc module is removed from the kernel.
8264 * The special kernel macro module_exit() is used to indicate the role of
8265 * this routine to the kernel as lpfc module exit point.
8270 pci_unregister_driver(&lpfc_driver
);
8271 fc_release_transport(lpfc_transport_template
);
8272 if (lpfc_enable_npiv
)
8273 fc_release_transport(lpfc_vport_transport_template
);
8274 if (_dump_buf_data
) {
8275 printk(KERN_ERR
"9062 BLKGRD: freeing %lu pages for "
8276 "_dump_buf_data at 0x%p\n",
8277 (1L << _dump_buf_data_order
), _dump_buf_data
);
8278 free_pages((unsigned long)_dump_buf_data
, _dump_buf_data_order
);
8281 if (_dump_buf_dif
) {
8282 printk(KERN_ERR
"9049 BLKGRD: freeing %lu pages for "
8283 "_dump_buf_dif at 0x%p\n",
8284 (1L << _dump_buf_dif_order
), _dump_buf_dif
);
8285 free_pages((unsigned long)_dump_buf_dif
, _dump_buf_dif_order
);
8289 module_init(lpfc_init
);
8290 module_exit(lpfc_exit
);
8291 MODULE_LICENSE("GPL");
8292 MODULE_DESCRIPTION(LPFC_MODULE_DESC
);
8293 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
8294 MODULE_VERSION("0:" LPFC_DRIVER_VERSION
);