1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2012 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/delay.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/idr.h>
26 #include <linux/interrupt.h>
27 #include <linux/module.h>
28 #include <linux/kthread.h>
29 #include <linux/pci.h>
30 #include <linux/spinlock.h>
31 #include <linux/ctype.h>
32 #include <linux/aer.h>
33 #include <linux/slab.h>
34 #include <linux/firmware.h>
35 #include <linux/miscdevice.h>
37 #include <scsi/scsi.h>
38 #include <scsi/scsi_device.h>
39 #include <scsi/scsi_host.h>
40 #include <scsi/scsi_transport_fc.h>
45 #include "lpfc_sli4.h"
47 #include "lpfc_disc.h"
48 #include "lpfc_scsi.h"
50 #include "lpfc_logmsg.h"
51 #include "lpfc_crtn.h"
52 #include "lpfc_vport.h"
53 #include "lpfc_version.h"
56 unsigned long _dump_buf_data_order
;
58 unsigned long _dump_buf_dif_order
;
59 spinlock_t _dump_buf_lock
;
61 static void lpfc_get_hba_model_desc(struct lpfc_hba
*, uint8_t *, uint8_t *);
62 static int lpfc_post_rcv_buf(struct lpfc_hba
*);
63 static int lpfc_sli4_queue_verify(struct lpfc_hba
*);
64 static int lpfc_create_bootstrap_mbox(struct lpfc_hba
*);
65 static int lpfc_setup_endian_order(struct lpfc_hba
*);
66 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*);
67 static void lpfc_free_els_sgl_list(struct lpfc_hba
*);
68 static void lpfc_init_sgl_list(struct lpfc_hba
*);
69 static int lpfc_init_active_sgl_array(struct lpfc_hba
*);
70 static void lpfc_free_active_sgl(struct lpfc_hba
*);
71 static int lpfc_hba_down_post_s3(struct lpfc_hba
*phba
);
72 static int lpfc_hba_down_post_s4(struct lpfc_hba
*phba
);
73 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*);
74 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*);
75 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba
*);
76 static void lpfc_sli4_disable_intr(struct lpfc_hba
*);
77 static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba
*, uint32_t);
79 static struct scsi_transport_template
*lpfc_transport_template
= NULL
;
80 static struct scsi_transport_template
*lpfc_vport_transport_template
= NULL
;
81 static DEFINE_IDR(lpfc_hba_index
);
84 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
85 * @phba: pointer to lpfc hba data structure.
87 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
88 * mailbox command. It retrieves the revision information from the HBA and
89 * collects the Vital Product Data (VPD) about the HBA for preparing the
90 * configuration of the HBA.
94 * -ERESTART - requests the SLI layer to reset the HBA and try again.
95 * Any other value - indicates an error.
98 lpfc_config_port_prep(struct lpfc_hba
*phba
)
100 lpfc_vpd_t
*vp
= &phba
->vpd
;
104 char *lpfc_vpd_data
= NULL
;
106 static char licensed
[56] =
107 "key unlock for use with gnu public licensed code only\0";
108 static int init_key
= 1;
110 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
112 phba
->link_state
= LPFC_HBA_ERROR
;
117 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
119 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
121 uint32_t *ptext
= (uint32_t *) licensed
;
123 for (i
= 0; i
< 56; i
+= sizeof (uint32_t), ptext
++)
124 *ptext
= cpu_to_be32(*ptext
);
128 lpfc_read_nv(phba
, pmb
);
129 memset((char*)mb
->un
.varRDnvp
.rsvd3
, 0,
130 sizeof (mb
->un
.varRDnvp
.rsvd3
));
131 memcpy((char*)mb
->un
.varRDnvp
.rsvd3
, licensed
,
134 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
136 if (rc
!= MBX_SUCCESS
) {
137 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
138 "0324 Config Port initialization "
139 "error, mbxCmd x%x READ_NVPARM, "
141 mb
->mbxCommand
, mb
->mbxStatus
);
142 mempool_free(pmb
, phba
->mbox_mem_pool
);
145 memcpy(phba
->wwnn
, (char *)mb
->un
.varRDnvp
.nodename
,
147 memcpy(phba
->wwpn
, (char *)mb
->un
.varRDnvp
.portname
,
151 phba
->sli3_options
= 0x0;
153 /* Setup and issue mailbox READ REV command */
154 lpfc_read_rev(phba
, pmb
);
155 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
156 if (rc
!= MBX_SUCCESS
) {
157 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
158 "0439 Adapter failed to init, mbxCmd x%x "
159 "READ_REV, mbxStatus x%x\n",
160 mb
->mbxCommand
, mb
->mbxStatus
);
161 mempool_free( pmb
, phba
->mbox_mem_pool
);
167 * The value of rr must be 1 since the driver set the cv field to 1.
168 * This setting requires the FW to set all revision fields.
170 if (mb
->un
.varRdRev
.rr
== 0) {
172 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
173 "0440 Adapter failed to init, READ_REV has "
174 "missing revision information.\n");
175 mempool_free(pmb
, phba
->mbox_mem_pool
);
179 if (phba
->sli_rev
== 3 && !mb
->un
.varRdRev
.v3rsp
) {
180 mempool_free(pmb
, phba
->mbox_mem_pool
);
184 /* Save information as VPD data */
186 memcpy(&vp
->sli3Feat
, &mb
->un
.varRdRev
.sli3Feat
, sizeof(uint32_t));
187 vp
->rev
.sli1FwRev
= mb
->un
.varRdRev
.sli1FwRev
;
188 memcpy(vp
->rev
.sli1FwName
, (char*) mb
->un
.varRdRev
.sli1FwName
, 16);
189 vp
->rev
.sli2FwRev
= mb
->un
.varRdRev
.sli2FwRev
;
190 memcpy(vp
->rev
.sli2FwName
, (char *) mb
->un
.varRdRev
.sli2FwName
, 16);
191 vp
->rev
.biuRev
= mb
->un
.varRdRev
.biuRev
;
192 vp
->rev
.smRev
= mb
->un
.varRdRev
.smRev
;
193 vp
->rev
.smFwRev
= mb
->un
.varRdRev
.un
.smFwRev
;
194 vp
->rev
.endecRev
= mb
->un
.varRdRev
.endecRev
;
195 vp
->rev
.fcphHigh
= mb
->un
.varRdRev
.fcphHigh
;
196 vp
->rev
.fcphLow
= mb
->un
.varRdRev
.fcphLow
;
197 vp
->rev
.feaLevelHigh
= mb
->un
.varRdRev
.feaLevelHigh
;
198 vp
->rev
.feaLevelLow
= mb
->un
.varRdRev
.feaLevelLow
;
199 vp
->rev
.postKernRev
= mb
->un
.varRdRev
.postKernRev
;
200 vp
->rev
.opFwRev
= mb
->un
.varRdRev
.opFwRev
;
202 /* If the sli feature level is less then 9, we must
203 * tear down all RPIs and VPIs on link down if NPIV
206 if (vp
->rev
.feaLevelHigh
< 9)
207 phba
->sli3_options
|= LPFC_SLI3_VPORT_TEARDOWN
;
209 if (lpfc_is_LC_HBA(phba
->pcidev
->device
))
210 memcpy(phba
->RandomData
, (char *)&mb
->un
.varWords
[24],
211 sizeof (phba
->RandomData
));
213 /* Get adapter VPD information */
214 lpfc_vpd_data
= kmalloc(DMP_VPD_SIZE
, GFP_KERNEL
);
218 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_VPD
);
219 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
221 if (rc
!= MBX_SUCCESS
) {
222 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
223 "0441 VPD not present on adapter, "
224 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
225 mb
->mbxCommand
, mb
->mbxStatus
);
226 mb
->un
.varDmp
.word_cnt
= 0;
228 /* dump mem may return a zero when finished or we got a
229 * mailbox error, either way we are done.
231 if (mb
->un
.varDmp
.word_cnt
== 0)
233 if (mb
->un
.varDmp
.word_cnt
> DMP_VPD_SIZE
- offset
)
234 mb
->un
.varDmp
.word_cnt
= DMP_VPD_SIZE
- offset
;
235 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
236 lpfc_vpd_data
+ offset
,
237 mb
->un
.varDmp
.word_cnt
);
238 offset
+= mb
->un
.varDmp
.word_cnt
;
239 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_VPD_SIZE
);
240 lpfc_parse_vpd(phba
, lpfc_vpd_data
, offset
);
242 kfree(lpfc_vpd_data
);
244 mempool_free(pmb
, phba
->mbox_mem_pool
);
249 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
250 * @phba: pointer to lpfc hba data structure.
251 * @pmboxq: pointer to the driver internal queue element for mailbox command.
253 * This is the completion handler for driver's configuring asynchronous event
254 * mailbox command to the device. If the mailbox command returns successfully,
255 * it will set internal async event support flag to 1; otherwise, it will
256 * set internal async event support flag to 0.
259 lpfc_config_async_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
261 if (pmboxq
->u
.mb
.mbxStatus
== MBX_SUCCESS
)
262 phba
->temp_sensor_support
= 1;
264 phba
->temp_sensor_support
= 0;
265 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
270 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
271 * @phba: pointer to lpfc hba data structure.
272 * @pmboxq: pointer to the driver internal queue element for mailbox command.
274 * This is the completion handler for dump mailbox command for getting
275 * wake up parameters. When this command complete, the response contain
276 * Option rom version of the HBA. This function translate the version number
277 * into a human readable string and store it in OptionROMVersion.
280 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
283 uint32_t prog_id_word
;
285 /* character array used for decoding dist type. */
286 char dist_char
[] = "nabx";
288 if (pmboxq
->u
.mb
.mbxStatus
!= MBX_SUCCESS
) {
289 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
293 prg
= (struct prog_id
*) &prog_id_word
;
295 /* word 7 contain option rom version */
296 prog_id_word
= pmboxq
->u
.mb
.un
.varWords
[7];
298 /* Decode the Option rom version word to a readable string */
300 dist
= dist_char
[prg
->dist
];
302 if ((prg
->dist
== 3) && (prg
->num
== 0))
303 sprintf(phba
->OptionROMVersion
, "%d.%d%d",
304 prg
->ver
, prg
->rev
, prg
->lev
);
306 sprintf(phba
->OptionROMVersion
, "%d.%d%d%c%d",
307 prg
->ver
, prg
->rev
, prg
->lev
,
309 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
314 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
315 * cfg_soft_wwnn, cfg_soft_wwpn
316 * @vport: pointer to lpfc vport data structure.
323 lpfc_update_vport_wwn(struct lpfc_vport
*vport
)
325 /* If the soft name exists then update it using the service params */
326 if (vport
->phba
->cfg_soft_wwnn
)
327 u64_to_wwn(vport
->phba
->cfg_soft_wwnn
,
328 vport
->fc_sparam
.nodeName
.u
.wwn
);
329 if (vport
->phba
->cfg_soft_wwpn
)
330 u64_to_wwn(vport
->phba
->cfg_soft_wwpn
,
331 vport
->fc_sparam
.portName
.u
.wwn
);
334 * If the name is empty or there exists a soft name
335 * then copy the service params name, otherwise use the fc name
337 if (vport
->fc_nodename
.u
.wwn
[0] == 0 || vport
->phba
->cfg_soft_wwnn
)
338 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
339 sizeof(struct lpfc_name
));
341 memcpy(&vport
->fc_sparam
.nodeName
, &vport
->fc_nodename
,
342 sizeof(struct lpfc_name
));
344 if (vport
->fc_portname
.u
.wwn
[0] == 0 || vport
->phba
->cfg_soft_wwpn
)
345 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
346 sizeof(struct lpfc_name
));
348 memcpy(&vport
->fc_sparam
.portName
, &vport
->fc_portname
,
349 sizeof(struct lpfc_name
));
353 * lpfc_config_port_post - Perform lpfc initialization after config port
354 * @phba: pointer to lpfc hba data structure.
356 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
357 * command call. It performs all internal resource and state setups on the
358 * port: post IOCB buffers, enable appropriate host interrupt attentions,
359 * ELS ring timers, etc.
363 * Any other value - error.
366 lpfc_config_port_post(struct lpfc_hba
*phba
)
368 struct lpfc_vport
*vport
= phba
->pport
;
369 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
372 struct lpfc_dmabuf
*mp
;
373 struct lpfc_sli
*psli
= &phba
->sli
;
374 uint32_t status
, timeout
;
378 spin_lock_irq(&phba
->hbalock
);
380 * If the Config port completed correctly the HBA is not
381 * over heated any more.
383 if (phba
->over_temp_state
== HBA_OVER_TEMP
)
384 phba
->over_temp_state
= HBA_NORMAL_TEMP
;
385 spin_unlock_irq(&phba
->hbalock
);
387 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
389 phba
->link_state
= LPFC_HBA_ERROR
;
394 /* Get login parameters for NID. */
395 rc
= lpfc_read_sparam(phba
, pmb
, 0);
397 mempool_free(pmb
, phba
->mbox_mem_pool
);
402 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
403 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
404 "0448 Adapter failed init, mbxCmd x%x "
405 "READ_SPARM mbxStatus x%x\n",
406 mb
->mbxCommand
, mb
->mbxStatus
);
407 phba
->link_state
= LPFC_HBA_ERROR
;
408 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
409 mempool_free(pmb
, phba
->mbox_mem_pool
);
410 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
415 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
417 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof (struct serv_parm
));
418 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
420 pmb
->context1
= NULL
;
421 lpfc_update_vport_wwn(vport
);
423 /* Update the fc_host data structures with new wwn. */
424 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
425 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
426 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
428 /* If no serial number in VPD data, use low 6 bytes of WWNN */
429 /* This should be consolidated into parse_vpd ? - mr */
430 if (phba
->SerialNumber
[0] == 0) {
433 outptr
= &vport
->fc_nodename
.u
.s
.IEEE
[0];
434 for (i
= 0; i
< 12; i
++) {
436 j
= ((status
& 0xf0) >> 4);
438 phba
->SerialNumber
[i
] =
439 (char)((uint8_t) 0x30 + (uint8_t) j
);
441 phba
->SerialNumber
[i
] =
442 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
446 phba
->SerialNumber
[i
] =
447 (char)((uint8_t) 0x30 + (uint8_t) j
);
449 phba
->SerialNumber
[i
] =
450 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
454 lpfc_read_config(phba
, pmb
);
456 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
457 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
458 "0453 Adapter failed to init, mbxCmd x%x "
459 "READ_CONFIG, mbxStatus x%x\n",
460 mb
->mbxCommand
, mb
->mbxStatus
);
461 phba
->link_state
= LPFC_HBA_ERROR
;
462 mempool_free( pmb
, phba
->mbox_mem_pool
);
466 /* Check if the port is disabled */
467 lpfc_sli_read_link_ste(phba
);
469 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
470 if (phba
->cfg_hba_queue_depth
> (mb
->un
.varRdConfig
.max_xri
+1))
471 phba
->cfg_hba_queue_depth
=
472 (mb
->un
.varRdConfig
.max_xri
+ 1) -
473 lpfc_sli4_get_els_iocb_cnt(phba
);
475 phba
->lmt
= mb
->un
.varRdConfig
.lmt
;
477 /* Get the default values for Model Name and Description */
478 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
480 phba
->link_state
= LPFC_LINK_DOWN
;
482 /* Only process IOCBs on ELS ring till hba_state is READY */
483 if (psli
->ring
[psli
->extra_ring
].sli
.sli3
.cmdringaddr
)
484 psli
->ring
[psli
->extra_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
485 if (psli
->ring
[psli
->fcp_ring
].sli
.sli3
.cmdringaddr
)
486 psli
->ring
[psli
->fcp_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
487 if (psli
->ring
[psli
->next_ring
].sli
.sli3
.cmdringaddr
)
488 psli
->ring
[psli
->next_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
490 /* Post receive buffers for desired rings */
491 if (phba
->sli_rev
!= 3)
492 lpfc_post_rcv_buf(phba
);
495 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
497 if (phba
->intr_type
== MSIX
) {
498 rc
= lpfc_config_msi(phba
, pmb
);
500 mempool_free(pmb
, phba
->mbox_mem_pool
);
503 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
504 if (rc
!= MBX_SUCCESS
) {
505 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
506 "0352 Config MSI mailbox command "
507 "failed, mbxCmd x%x, mbxStatus x%x\n",
508 pmb
->u
.mb
.mbxCommand
,
509 pmb
->u
.mb
.mbxStatus
);
510 mempool_free(pmb
, phba
->mbox_mem_pool
);
515 spin_lock_irq(&phba
->hbalock
);
516 /* Initialize ERATT handling flag */
517 phba
->hba_flag
&= ~HBA_ERATT_HANDLED
;
519 /* Enable appropriate host interrupts */
520 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
521 spin_unlock_irq(&phba
->hbalock
);
524 status
|= HC_MBINT_ENA
| HC_ERINT_ENA
| HC_LAINT_ENA
;
525 if (psli
->num_rings
> 0)
526 status
|= HC_R0INT_ENA
;
527 if (psli
->num_rings
> 1)
528 status
|= HC_R1INT_ENA
;
529 if (psli
->num_rings
> 2)
530 status
|= HC_R2INT_ENA
;
531 if (psli
->num_rings
> 3)
532 status
|= HC_R3INT_ENA
;
534 if ((phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) &&
535 (phba
->cfg_poll
& DISABLE_FCP_RING_INT
))
536 status
&= ~(HC_R0INT_ENA
);
538 writel(status
, phba
->HCregaddr
);
539 readl(phba
->HCregaddr
); /* flush */
540 spin_unlock_irq(&phba
->hbalock
);
542 /* Set up ring-0 (ELS) timer */
543 timeout
= phba
->fc_ratov
* 2;
544 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
545 /* Set up heart beat (HB) timer */
546 mod_timer(&phba
->hb_tmofunc
, jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
547 phba
->hb_outstanding
= 0;
548 phba
->last_completion_time
= jiffies
;
549 /* Set up error attention (ERATT) polling timer */
550 mod_timer(&phba
->eratt_poll
, jiffies
+ HZ
* LPFC_ERATT_POLL_INTERVAL
);
552 if (phba
->hba_flag
& LINK_DISABLED
) {
553 lpfc_printf_log(phba
,
555 "2598 Adapter Link is disabled.\n");
556 lpfc_down_link(phba
, pmb
);
557 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
558 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
559 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
560 lpfc_printf_log(phba
,
562 "2599 Adapter failed to issue DOWN_LINK"
563 " mbox command rc 0x%x\n", rc
);
565 mempool_free(pmb
, phba
->mbox_mem_pool
);
568 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
569 mempool_free(pmb
, phba
->mbox_mem_pool
);
570 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
574 /* MBOX buffer will be freed in mbox compl */
575 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
577 phba
->link_state
= LPFC_HBA_ERROR
;
581 lpfc_config_async(phba
, pmb
, LPFC_ELS_RING
);
582 pmb
->mbox_cmpl
= lpfc_config_async_cmpl
;
583 pmb
->vport
= phba
->pport
;
584 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
586 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
587 lpfc_printf_log(phba
,
590 "0456 Adapter failed to issue "
591 "ASYNCEVT_ENABLE mbox status x%x\n",
593 mempool_free(pmb
, phba
->mbox_mem_pool
);
596 /* Get Option rom version */
597 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
599 phba
->link_state
= LPFC_HBA_ERROR
;
603 lpfc_dump_wakeup_param(phba
, pmb
);
604 pmb
->mbox_cmpl
= lpfc_dump_wakeup_param_cmpl
;
605 pmb
->vport
= phba
->pport
;
606 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
608 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
609 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
, "0435 Adapter failed "
610 "to get Option ROM version status x%x\n", rc
);
611 mempool_free(pmb
, phba
->mbox_mem_pool
);
618 * lpfc_hba_init_link - Initialize the FC link
619 * @phba: pointer to lpfc hba data structure.
620 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
622 * This routine will issue the INIT_LINK mailbox command call.
623 * It is available to other drivers through the lpfc_hba data
624 * structure for use as a delayed link up mechanism with the
625 * module parameter lpfc_suppress_link_up.
629 * Any other value - error
632 lpfc_hba_init_link(struct lpfc_hba
*phba
, uint32_t flag
)
634 return lpfc_hba_init_link_fc_topology(phba
, phba
->cfg_topology
, flag
);
638 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
639 * @phba: pointer to lpfc hba data structure.
640 * @fc_topology: desired fc topology.
641 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
643 * This routine will issue the INIT_LINK mailbox command call.
644 * It is available to other drivers through the lpfc_hba data
645 * structure for use as a delayed link up mechanism with the
646 * module parameter lpfc_suppress_link_up.
650 * Any other value - error
653 lpfc_hba_init_link_fc_topology(struct lpfc_hba
*phba
, uint32_t fc_topology
,
656 struct lpfc_vport
*vport
= phba
->pport
;
661 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
663 phba
->link_state
= LPFC_HBA_ERROR
;
669 if ((phba
->cfg_link_speed
> LPFC_USER_LINK_SPEED_MAX
) ||
670 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_1G
) &&
671 !(phba
->lmt
& LMT_1Gb
)) ||
672 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_2G
) &&
673 !(phba
->lmt
& LMT_2Gb
)) ||
674 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_4G
) &&
675 !(phba
->lmt
& LMT_4Gb
)) ||
676 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_8G
) &&
677 !(phba
->lmt
& LMT_8Gb
)) ||
678 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_10G
) &&
679 !(phba
->lmt
& LMT_10Gb
)) ||
680 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_16G
) &&
681 !(phba
->lmt
& LMT_16Gb
))) {
682 /* Reset link speed to auto */
683 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
684 "1302 Invalid speed for this board:%d "
685 "Reset link speed to auto.\n",
686 phba
->cfg_link_speed
);
687 phba
->cfg_link_speed
= LPFC_USER_LINK_SPEED_AUTO
;
689 lpfc_init_link(phba
, pmb
, fc_topology
, phba
->cfg_link_speed
);
690 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
691 if (phba
->sli_rev
< LPFC_SLI_REV4
)
692 lpfc_set_loopback_flag(phba
);
693 rc
= lpfc_sli_issue_mbox(phba
, pmb
, flag
);
694 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
695 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
696 "0498 Adapter failed to init, mbxCmd x%x "
697 "INIT_LINK, mbxStatus x%x\n",
698 mb
->mbxCommand
, mb
->mbxStatus
);
699 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
700 /* Clear all interrupt enable conditions */
701 writel(0, phba
->HCregaddr
);
702 readl(phba
->HCregaddr
); /* flush */
703 /* Clear all pending interrupts */
704 writel(0xffffffff, phba
->HAregaddr
);
705 readl(phba
->HAregaddr
); /* flush */
707 phba
->link_state
= LPFC_HBA_ERROR
;
708 if (rc
!= MBX_BUSY
|| flag
== MBX_POLL
)
709 mempool_free(pmb
, phba
->mbox_mem_pool
);
712 phba
->cfg_suppress_link_up
= LPFC_INITIALIZE_LINK
;
713 if (flag
== MBX_POLL
)
714 mempool_free(pmb
, phba
->mbox_mem_pool
);
720 * lpfc_hba_down_link - this routine downs the FC link
721 * @phba: pointer to lpfc hba data structure.
722 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
724 * This routine will issue the DOWN_LINK mailbox command call.
725 * It is available to other drivers through the lpfc_hba data
726 * structure for use to stop the link.
730 * Any other value - error
733 lpfc_hba_down_link(struct lpfc_hba
*phba
, uint32_t flag
)
738 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
740 phba
->link_state
= LPFC_HBA_ERROR
;
744 lpfc_printf_log(phba
,
746 "0491 Adapter Link is disabled.\n");
747 lpfc_down_link(phba
, pmb
);
748 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
749 rc
= lpfc_sli_issue_mbox(phba
, pmb
, flag
);
750 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
751 lpfc_printf_log(phba
,
753 "2522 Adapter failed to issue DOWN_LINK"
754 " mbox command rc 0x%x\n", rc
);
756 mempool_free(pmb
, phba
->mbox_mem_pool
);
759 if (flag
== MBX_POLL
)
760 mempool_free(pmb
, phba
->mbox_mem_pool
);
766 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
767 * @phba: pointer to lpfc HBA data structure.
769 * This routine will do LPFC uninitialization before the HBA is reset when
770 * bringing down the SLI Layer.
774 * Any other value - error.
777 lpfc_hba_down_prep(struct lpfc_hba
*phba
)
779 struct lpfc_vport
**vports
;
782 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
783 /* Disable interrupts */
784 writel(0, phba
->HCregaddr
);
785 readl(phba
->HCregaddr
); /* flush */
788 if (phba
->pport
->load_flag
& FC_UNLOADING
)
789 lpfc_cleanup_discovery_resources(phba
->pport
);
791 vports
= lpfc_create_vport_work_array(phba
);
793 for (i
= 0; i
<= phba
->max_vports
&&
794 vports
[i
] != NULL
; i
++)
795 lpfc_cleanup_discovery_resources(vports
[i
]);
796 lpfc_destroy_vport_work_array(phba
, vports
);
802 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
803 * @phba: pointer to lpfc HBA data structure.
805 * This routine will do uninitialization after the HBA is reset when bring
806 * down the SLI Layer.
810 * Any other value - error.
813 lpfc_hba_down_post_s3(struct lpfc_hba
*phba
)
815 struct lpfc_sli
*psli
= &phba
->sli
;
816 struct lpfc_sli_ring
*pring
;
817 struct lpfc_dmabuf
*mp
, *next_mp
;
818 LIST_HEAD(completions
);
821 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
822 lpfc_sli_hbqbuf_free_all(phba
);
824 /* Cleanup preposted buffers on the ELS ring */
825 pring
= &psli
->ring
[LPFC_ELS_RING
];
826 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
828 pring
->postbufq_cnt
--;
829 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
834 spin_lock_irq(&phba
->hbalock
);
835 for (i
= 0; i
< psli
->num_rings
; i
++) {
836 pring
= &psli
->ring
[i
];
838 /* At this point in time the HBA is either reset or DOA. Either
839 * way, nothing should be on txcmplq as it will NEVER complete.
841 list_splice_init(&pring
->txcmplq
, &completions
);
842 pring
->txcmplq_cnt
= 0;
843 spin_unlock_irq(&phba
->hbalock
);
845 /* Cancel all the IOCBs from the completions list */
846 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
849 lpfc_sli_abort_iocb_ring(phba
, pring
);
850 spin_lock_irq(&phba
->hbalock
);
852 spin_unlock_irq(&phba
->hbalock
);
858 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
859 * @phba: pointer to lpfc HBA data structure.
861 * This routine will do uninitialization after the HBA is reset when bring
862 * down the SLI Layer.
866 * Any other value - error.
869 lpfc_hba_down_post_s4(struct lpfc_hba
*phba
)
871 struct lpfc_scsi_buf
*psb
, *psb_next
;
874 unsigned long iflag
= 0;
875 struct lpfc_sglq
*sglq_entry
= NULL
;
877 ret
= lpfc_hba_down_post_s3(phba
);
880 /* At this point in time the HBA is either reset or DOA. Either
881 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
882 * on the lpfc_sgl_list so that it can either be freed if the
883 * driver is unloading or reposted if the driver is restarting
886 spin_lock_irq(&phba
->hbalock
); /* required for lpfc_sgl_list and */
888 /* abts_sgl_list_lock required because worker thread uses this
891 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
892 list_for_each_entry(sglq_entry
,
893 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
)
894 sglq_entry
->state
= SGL_FREED
;
896 list_splice_init(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
,
897 &phba
->sli4_hba
.lpfc_sgl_list
);
898 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
899 /* abts_scsi_buf_list_lock required because worker thread uses this
902 spin_lock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
903 list_splice_init(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
,
905 spin_unlock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
906 spin_unlock_irq(&phba
->hbalock
);
908 list_for_each_entry_safe(psb
, psb_next
, &aborts
, list
) {
910 psb
->status
= IOSTAT_SUCCESS
;
912 spin_lock_irqsave(&phba
->scsi_buf_list_lock
, iflag
);
913 list_splice(&aborts
, &phba
->lpfc_scsi_buf_list
);
914 spin_unlock_irqrestore(&phba
->scsi_buf_list_lock
, iflag
);
919 * lpfc_hba_down_post - Wrapper func for hba down post routine
920 * @phba: pointer to lpfc HBA data structure.
922 * This routine wraps the actual SLI3 or SLI4 routine for performing
923 * uninitialization after the HBA is reset when bring down the SLI Layer.
927 * Any other value - error.
930 lpfc_hba_down_post(struct lpfc_hba
*phba
)
932 return (*phba
->lpfc_hba_down_post
)(phba
);
936 * lpfc_hb_timeout - The HBA-timer timeout handler
937 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
939 * This is the HBA-timer timeout handler registered to the lpfc driver. When
940 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
941 * work-port-events bitmap and the worker thread is notified. This timeout
942 * event will be used by the worker thread to invoke the actual timeout
943 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
944 * be performed in the timeout handler and the HBA timeout event bit shall
945 * be cleared by the worker thread after it has taken the event bitmap out.
948 lpfc_hb_timeout(unsigned long ptr
)
950 struct lpfc_hba
*phba
;
954 phba
= (struct lpfc_hba
*)ptr
;
956 /* Check for heart beat timeout conditions */
957 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
958 tmo_posted
= phba
->pport
->work_port_events
& WORKER_HB_TMO
;
960 phba
->pport
->work_port_events
|= WORKER_HB_TMO
;
961 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
963 /* Tell the worker thread there is work to do */
965 lpfc_worker_wake_up(phba
);
970 * lpfc_rrq_timeout - The RRQ-timer timeout handler
971 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
973 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
974 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
975 * work-port-events bitmap and the worker thread is notified. This timeout
976 * event will be used by the worker thread to invoke the actual timeout
977 * handler routine, lpfc_rrq_handler. Any periodical operations will
978 * be performed in the timeout handler and the RRQ timeout event bit shall
979 * be cleared by the worker thread after it has taken the event bitmap out.
982 lpfc_rrq_timeout(unsigned long ptr
)
984 struct lpfc_hba
*phba
;
987 phba
= (struct lpfc_hba
*)ptr
;
988 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
989 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
990 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
991 lpfc_worker_wake_up(phba
);
995 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
996 * @phba: pointer to lpfc hba data structure.
997 * @pmboxq: pointer to the driver internal queue element for mailbox command.
999 * This is the callback function to the lpfc heart-beat mailbox command.
1000 * If configured, the lpfc driver issues the heart-beat mailbox command to
1001 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1002 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1003 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1004 * heart-beat outstanding state. Once the mailbox command comes back and
1005 * no error conditions detected, the heart-beat mailbox command timer is
1006 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1007 * state is cleared for the next heart-beat. If the timer expired with the
1008 * heart-beat outstanding state set, the driver will put the HBA offline.
1011 lpfc_hb_mbox_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
1013 unsigned long drvr_flag
;
1015 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
1016 phba
->hb_outstanding
= 0;
1017 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
1019 /* Check and reset heart-beat timer is necessary */
1020 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1021 if (!(phba
->pport
->fc_flag
& FC_OFFLINE_MODE
) &&
1022 !(phba
->link_state
== LPFC_HBA_ERROR
) &&
1023 !(phba
->pport
->load_flag
& FC_UNLOADING
))
1024 mod_timer(&phba
->hb_tmofunc
,
1025 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
1030 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1031 * @phba: pointer to lpfc hba data structure.
1033 * This is the actual HBA-timer timeout handler to be invoked by the worker
1034 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1035 * handler performs any periodic operations needed for the device. If such
1036 * periodic event has already been attended to either in the interrupt handler
1037 * or by processing slow-ring or fast-ring events within the HBA-timer
1038 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1039 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1040 * is configured and there is no heart-beat mailbox command outstanding, a
1041 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1042 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1046 lpfc_hb_timeout_handler(struct lpfc_hba
*phba
)
1048 struct lpfc_vport
**vports
;
1049 LPFC_MBOXQ_t
*pmboxq
;
1050 struct lpfc_dmabuf
*buf_ptr
;
1052 struct lpfc_sli
*psli
= &phba
->sli
;
1053 LIST_HEAD(completions
);
1055 vports
= lpfc_create_vport_work_array(phba
);
1057 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
1058 lpfc_rcv_seq_check_edtov(vports
[i
]);
1059 lpfc_destroy_vport_work_array(phba
, vports
);
1061 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
1062 (phba
->pport
->load_flag
& FC_UNLOADING
) ||
1063 (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
))
1066 spin_lock_irq(&phba
->pport
->work_port_lock
);
1068 if (time_after(phba
->last_completion_time
+ LPFC_HB_MBOX_INTERVAL
* HZ
,
1070 spin_unlock_irq(&phba
->pport
->work_port_lock
);
1071 if (!phba
->hb_outstanding
)
1072 mod_timer(&phba
->hb_tmofunc
,
1073 jiffies
+ HZ
* LPFC_HB_MBOX_INTERVAL
);
1075 mod_timer(&phba
->hb_tmofunc
,
1076 jiffies
+ HZ
* LPFC_HB_MBOX_TIMEOUT
);
1079 spin_unlock_irq(&phba
->pport
->work_port_lock
);
1081 if (phba
->elsbuf_cnt
&&
1082 (phba
->elsbuf_cnt
== phba
->elsbuf_prev_cnt
)) {
1083 spin_lock_irq(&phba
->hbalock
);
1084 list_splice_init(&phba
->elsbuf
, &completions
);
1085 phba
->elsbuf_cnt
= 0;
1086 phba
->elsbuf_prev_cnt
= 0;
1087 spin_unlock_irq(&phba
->hbalock
);
1089 while (!list_empty(&completions
)) {
1090 list_remove_head(&completions
, buf_ptr
,
1091 struct lpfc_dmabuf
, list
);
1092 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
1096 phba
->elsbuf_prev_cnt
= phba
->elsbuf_cnt
;
1098 /* If there is no heart beat outstanding, issue a heartbeat command */
1099 if (phba
->cfg_enable_hba_heartbeat
) {
1100 if (!phba
->hb_outstanding
) {
1101 if ((!(psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
)) &&
1102 (list_empty(&psli
->mboxq
))) {
1103 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,
1106 mod_timer(&phba
->hb_tmofunc
,
1108 HZ
* LPFC_HB_MBOX_INTERVAL
);
1112 lpfc_heart_beat(phba
, pmboxq
);
1113 pmboxq
->mbox_cmpl
= lpfc_hb_mbox_cmpl
;
1114 pmboxq
->vport
= phba
->pport
;
1115 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
,
1118 if (retval
!= MBX_BUSY
&&
1119 retval
!= MBX_SUCCESS
) {
1120 mempool_free(pmboxq
,
1121 phba
->mbox_mem_pool
);
1122 mod_timer(&phba
->hb_tmofunc
,
1124 HZ
* LPFC_HB_MBOX_INTERVAL
);
1127 phba
->skipped_hb
= 0;
1128 phba
->hb_outstanding
= 1;
1129 } else if (time_before_eq(phba
->last_completion_time
,
1130 phba
->skipped_hb
)) {
1131 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1132 "2857 Last completion time not "
1133 " updated in %d ms\n",
1134 jiffies_to_msecs(jiffies
1135 - phba
->last_completion_time
));
1137 phba
->skipped_hb
= jiffies
;
1139 mod_timer(&phba
->hb_tmofunc
,
1140 jiffies
+ HZ
* LPFC_HB_MBOX_TIMEOUT
);
1144 * If heart beat timeout called with hb_outstanding set
1145 * we need to give the hb mailbox cmd a chance to
1148 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
1149 "0459 Adapter heartbeat still out"
1150 "standing:last compl time was %d ms.\n",
1151 jiffies_to_msecs(jiffies
1152 - phba
->last_completion_time
));
1153 mod_timer(&phba
->hb_tmofunc
,
1154 jiffies
+ HZ
* LPFC_HB_MBOX_TIMEOUT
);
1160 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1161 * @phba: pointer to lpfc hba data structure.
1163 * This routine is called to bring the HBA offline when HBA hardware error
1164 * other than Port Error 6 has been detected.
1167 lpfc_offline_eratt(struct lpfc_hba
*phba
)
1169 struct lpfc_sli
*psli
= &phba
->sli
;
1171 spin_lock_irq(&phba
->hbalock
);
1172 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1173 spin_unlock_irq(&phba
->hbalock
);
1174 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
1177 lpfc_reset_barrier(phba
);
1178 spin_lock_irq(&phba
->hbalock
);
1179 lpfc_sli_brdreset(phba
);
1180 spin_unlock_irq(&phba
->hbalock
);
1181 lpfc_hba_down_post(phba
);
1182 lpfc_sli_brdready(phba
, HS_MBRDY
);
1183 lpfc_unblock_mgmt_io(phba
);
1184 phba
->link_state
= LPFC_HBA_ERROR
;
1189 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1190 * @phba: pointer to lpfc hba data structure.
1192 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1193 * other than Port Error 6 has been detected.
1196 lpfc_sli4_offline_eratt(struct lpfc_hba
*phba
)
1198 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
1200 lpfc_sli4_brdreset(phba
);
1201 lpfc_hba_down_post(phba
);
1202 lpfc_sli4_post_status_check(phba
);
1203 lpfc_unblock_mgmt_io(phba
);
1204 phba
->link_state
= LPFC_HBA_ERROR
;
1208 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1209 * @phba: pointer to lpfc hba data structure.
1211 * This routine is invoked to handle the deferred HBA hardware error
1212 * conditions. This type of error is indicated by HBA by setting ER1
1213 * and another ER bit in the host status register. The driver will
1214 * wait until the ER1 bit clears before handling the error condition.
1217 lpfc_handle_deferred_eratt(struct lpfc_hba
*phba
)
1219 uint32_t old_host_status
= phba
->work_hs
;
1220 struct lpfc_sli_ring
*pring
;
1221 struct lpfc_sli
*psli
= &phba
->sli
;
1223 /* If the pci channel is offline, ignore possible errors,
1224 * since we cannot communicate with the pci card anyway.
1226 if (pci_channel_offline(phba
->pcidev
)) {
1227 spin_lock_irq(&phba
->hbalock
);
1228 phba
->hba_flag
&= ~DEFER_ERATT
;
1229 spin_unlock_irq(&phba
->hbalock
);
1233 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1234 "0479 Deferred Adapter Hardware Error "
1235 "Data: x%x x%x x%x\n",
1237 phba
->work_status
[0], phba
->work_status
[1]);
1239 spin_lock_irq(&phba
->hbalock
);
1240 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1241 spin_unlock_irq(&phba
->hbalock
);
1245 * Firmware stops when it triggred erratt. That could cause the I/Os
1246 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1247 * SCSI layer retry it after re-establishing link.
1249 pring
= &psli
->ring
[psli
->fcp_ring
];
1250 lpfc_sli_abort_iocb_ring(phba
, pring
);
1253 * There was a firmware error. Take the hba offline and then
1254 * attempt to restart it.
1256 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
1259 /* Wait for the ER1 bit to clear.*/
1260 while (phba
->work_hs
& HS_FFER1
) {
1262 if (lpfc_readl(phba
->HSregaddr
, &phba
->work_hs
)) {
1263 phba
->work_hs
= UNPLUG_ERR
;
1266 /* If driver is unloading let the worker thread continue */
1267 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
1274 * This is to ptrotect against a race condition in which
1275 * first write to the host attention register clear the
1276 * host status register.
1278 if ((!phba
->work_hs
) && (!(phba
->pport
->load_flag
& FC_UNLOADING
)))
1279 phba
->work_hs
= old_host_status
& ~HS_FFER1
;
1281 spin_lock_irq(&phba
->hbalock
);
1282 phba
->hba_flag
&= ~DEFER_ERATT
;
1283 spin_unlock_irq(&phba
->hbalock
);
1284 phba
->work_status
[0] = readl(phba
->MBslimaddr
+ 0xa8);
1285 phba
->work_status
[1] = readl(phba
->MBslimaddr
+ 0xac);
1289 lpfc_board_errevt_to_mgmt(struct lpfc_hba
*phba
)
1291 struct lpfc_board_event_header board_event
;
1292 struct Scsi_Host
*shost
;
1294 board_event
.event_type
= FC_REG_BOARD_EVENT
;
1295 board_event
.subcategory
= LPFC_EVENT_PORTINTERR
;
1296 shost
= lpfc_shost_from_vport(phba
->pport
);
1297 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1298 sizeof(board_event
),
1299 (char *) &board_event
,
1304 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1305 * @phba: pointer to lpfc hba data structure.
1307 * This routine is invoked to handle the following HBA hardware error
1309 * 1 - HBA error attention interrupt
1310 * 2 - DMA ring index out of range
1311 * 3 - Mailbox command came back as unknown
1314 lpfc_handle_eratt_s3(struct lpfc_hba
*phba
)
1316 struct lpfc_vport
*vport
= phba
->pport
;
1317 struct lpfc_sli
*psli
= &phba
->sli
;
1318 struct lpfc_sli_ring
*pring
;
1319 uint32_t event_data
;
1320 unsigned long temperature
;
1321 struct temp_event temp_event_data
;
1322 struct Scsi_Host
*shost
;
1324 /* If the pci channel is offline, ignore possible errors,
1325 * since we cannot communicate with the pci card anyway.
1327 if (pci_channel_offline(phba
->pcidev
)) {
1328 spin_lock_irq(&phba
->hbalock
);
1329 phba
->hba_flag
&= ~DEFER_ERATT
;
1330 spin_unlock_irq(&phba
->hbalock
);
1334 /* If resets are disabled then leave the HBA alone and return */
1335 if (!phba
->cfg_enable_hba_reset
)
1338 /* Send an internal error event to mgmt application */
1339 lpfc_board_errevt_to_mgmt(phba
);
1341 if (phba
->hba_flag
& DEFER_ERATT
)
1342 lpfc_handle_deferred_eratt(phba
);
1344 if ((phba
->work_hs
& HS_FFER6
) || (phba
->work_hs
& HS_FFER8
)) {
1345 if (phba
->work_hs
& HS_FFER6
)
1346 /* Re-establishing Link */
1347 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1348 "1301 Re-establishing Link "
1349 "Data: x%x x%x x%x\n",
1350 phba
->work_hs
, phba
->work_status
[0],
1351 phba
->work_status
[1]);
1352 if (phba
->work_hs
& HS_FFER8
)
1353 /* Device Zeroization */
1354 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1355 "2861 Host Authentication device "
1356 "zeroization Data:x%x x%x x%x\n",
1357 phba
->work_hs
, phba
->work_status
[0],
1358 phba
->work_status
[1]);
1360 spin_lock_irq(&phba
->hbalock
);
1361 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1362 spin_unlock_irq(&phba
->hbalock
);
1365 * Firmware stops when it triggled erratt with HS_FFER6.
1366 * That could cause the I/Os dropped by the firmware.
1367 * Error iocb (I/O) on txcmplq and let the SCSI layer
1368 * retry it after re-establishing link.
1370 pring
= &psli
->ring
[psli
->fcp_ring
];
1371 lpfc_sli_abort_iocb_ring(phba
, pring
);
1374 * There was a firmware error. Take the hba offline and then
1375 * attempt to restart it.
1377 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
1379 lpfc_sli_brdrestart(phba
);
1380 if (lpfc_online(phba
) == 0) { /* Initialize the HBA */
1381 lpfc_unblock_mgmt_io(phba
);
1384 lpfc_unblock_mgmt_io(phba
);
1385 } else if (phba
->work_hs
& HS_CRIT_TEMP
) {
1386 temperature
= readl(phba
->MBslimaddr
+ TEMPERATURE_OFFSET
);
1387 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
1388 temp_event_data
.event_code
= LPFC_CRIT_TEMP
;
1389 temp_event_data
.data
= (uint32_t)temperature
;
1391 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1392 "0406 Adapter maximum temperature exceeded "
1393 "(%ld), taking this port offline "
1394 "Data: x%x x%x x%x\n",
1395 temperature
, phba
->work_hs
,
1396 phba
->work_status
[0], phba
->work_status
[1]);
1398 shost
= lpfc_shost_from_vport(phba
->pport
);
1399 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1400 sizeof(temp_event_data
),
1401 (char *) &temp_event_data
,
1402 SCSI_NL_VID_TYPE_PCI
1403 | PCI_VENDOR_ID_EMULEX
);
1405 spin_lock_irq(&phba
->hbalock
);
1406 phba
->over_temp_state
= HBA_OVER_TEMP
;
1407 spin_unlock_irq(&phba
->hbalock
);
1408 lpfc_offline_eratt(phba
);
1411 /* The if clause above forces this code path when the status
1412 * failure is a value other than FFER6. Do not call the offline
1413 * twice. This is the adapter hardware error path.
1415 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1416 "0457 Adapter Hardware Error "
1417 "Data: x%x x%x x%x\n",
1419 phba
->work_status
[0], phba
->work_status
[1]);
1421 event_data
= FC_REG_DUMP_EVENT
;
1422 shost
= lpfc_shost_from_vport(vport
);
1423 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1424 sizeof(event_data
), (char *) &event_data
,
1425 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
1427 lpfc_offline_eratt(phba
);
1433 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1434 * @phba: pointer to lpfc hba data structure.
1435 * @mbx_action: flag for mailbox shutdown action.
1437 * This routine is invoked to perform an SLI4 port PCI function reset in
1438 * response to port status register polling attention. It waits for port
1439 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1440 * During this process, interrupt vectors are freed and later requested
1441 * for handling possible port resource change.
1444 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba
*phba
, int mbx_action
)
1450 * On error status condition, driver need to wait for port
1451 * ready before performing reset.
1453 rc
= lpfc_sli4_pdev_status_reg_wait(phba
);
1455 /* need reset: attempt for port recovery */
1456 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1457 "2887 Reset Needed: Attempting Port "
1459 lpfc_offline_prep(phba
, mbx_action
);
1461 /* release interrupt for possible resource change */
1462 lpfc_sli4_disable_intr(phba
);
1463 lpfc_sli_brdrestart(phba
);
1464 /* request and enable interrupt */
1465 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
1466 if (intr_mode
== LPFC_INTR_ERROR
) {
1467 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1468 "3175 Failed to enable interrupt\n");
1471 phba
->intr_mode
= intr_mode
;
1473 rc
= lpfc_online(phba
);
1475 lpfc_unblock_mgmt_io(phba
);
1481 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1482 * @phba: pointer to lpfc hba data structure.
1484 * This routine is invoked to handle the SLI4 HBA hardware error attention
1488 lpfc_handle_eratt_s4(struct lpfc_hba
*phba
)
1490 struct lpfc_vport
*vport
= phba
->pport
;
1491 uint32_t event_data
;
1492 struct Scsi_Host
*shost
;
1494 struct lpfc_register portstat_reg
= {0};
1495 uint32_t reg_err1
, reg_err2
;
1496 uint32_t uerrlo_reg
, uemasklo_reg
;
1497 uint32_t pci_rd_rc1
, pci_rd_rc2
;
1500 /* If the pci channel is offline, ignore possible errors, since
1501 * we cannot communicate with the pci card anyway.
1503 if (pci_channel_offline(phba
->pcidev
))
1505 /* If resets are disabled then leave the HBA alone and return */
1506 if (!phba
->cfg_enable_hba_reset
)
1509 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
1511 case LPFC_SLI_INTF_IF_TYPE_0
:
1512 pci_rd_rc1
= lpfc_readl(
1513 phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
1515 pci_rd_rc2
= lpfc_readl(
1516 phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
,
1518 /* consider PCI bus read error as pci_channel_offline */
1519 if (pci_rd_rc1
== -EIO
&& pci_rd_rc2
== -EIO
)
1521 lpfc_sli4_offline_eratt(phba
);
1523 case LPFC_SLI_INTF_IF_TYPE_2
:
1524 pci_rd_rc1
= lpfc_readl(
1525 phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
1526 &portstat_reg
.word0
);
1527 /* consider PCI bus read error as pci_channel_offline */
1528 if (pci_rd_rc1
== -EIO
) {
1529 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1530 "3151 PCI bus read access failure: x%x\n",
1531 readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
));
1534 reg_err1
= readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
1535 reg_err2
= readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
1536 if (bf_get(lpfc_sliport_status_oti
, &portstat_reg
)) {
1537 /* TODO: Register for Overtemp async events. */
1538 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1539 "2889 Port Overtemperature event, "
1540 "taking port offline\n");
1541 spin_lock_irq(&phba
->hbalock
);
1542 phba
->over_temp_state
= HBA_OVER_TEMP
;
1543 spin_unlock_irq(&phba
->hbalock
);
1544 lpfc_sli4_offline_eratt(phba
);
1547 if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1548 reg_err2
== SLIPORT_ERR2_REG_FW_RESTART
)
1549 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1550 "3143 Port Down: Firmware Restarted\n");
1551 else if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1552 reg_err2
== SLIPORT_ERR2_REG_FORCED_DUMP
)
1553 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1554 "3144 Port Down: Debug Dump\n");
1555 else if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1556 reg_err2
== SLIPORT_ERR2_REG_FUNC_PROVISON
)
1557 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1558 "3145 Port Down: Provisioning\n");
1560 /* Check port status register for function reset */
1561 rc
= lpfc_sli4_port_sta_fn_reset(phba
, LPFC_MBX_NO_WAIT
);
1563 /* don't report event on forced debug dump */
1564 if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1565 reg_err2
== SLIPORT_ERR2_REG_FORCED_DUMP
)
1570 /* fall through for not able to recover */
1571 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1572 "3152 Unrecoverable error, bring the port "
1574 lpfc_sli4_offline_eratt(phba
);
1576 case LPFC_SLI_INTF_IF_TYPE_1
:
1580 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
1581 "3123 Report dump event to upper layer\n");
1582 /* Send an internal error event to mgmt application */
1583 lpfc_board_errevt_to_mgmt(phba
);
1585 event_data
= FC_REG_DUMP_EVENT
;
1586 shost
= lpfc_shost_from_vport(vport
);
1587 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1588 sizeof(event_data
), (char *) &event_data
,
1589 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
1593 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1594 * @phba: pointer to lpfc HBA data structure.
1596 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1597 * routine from the API jump table function pointer from the lpfc_hba struct.
1601 * Any other value - error.
1604 lpfc_handle_eratt(struct lpfc_hba
*phba
)
1606 (*phba
->lpfc_handle_eratt
)(phba
);
1610 * lpfc_handle_latt - The HBA link event handler
1611 * @phba: pointer to lpfc hba data structure.
1613 * This routine is invoked from the worker thread to handle a HBA host
1614 * attention link event.
1617 lpfc_handle_latt(struct lpfc_hba
*phba
)
1619 struct lpfc_vport
*vport
= phba
->pport
;
1620 struct lpfc_sli
*psli
= &phba
->sli
;
1622 volatile uint32_t control
;
1623 struct lpfc_dmabuf
*mp
;
1626 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1629 goto lpfc_handle_latt_err_exit
;
1632 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1635 goto lpfc_handle_latt_free_pmb
;
1638 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
1641 goto lpfc_handle_latt_free_mp
;
1644 /* Cleanup any outstanding ELS commands */
1645 lpfc_els_flush_all_cmd(phba
);
1647 psli
->slistat
.link_event
++;
1648 lpfc_read_topology(phba
, pmb
, mp
);
1649 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
1651 /* Block ELS IOCBs until we have processed this mbox command */
1652 phba
->sli
.ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
1653 rc
= lpfc_sli_issue_mbox (phba
, pmb
, MBX_NOWAIT
);
1654 if (rc
== MBX_NOT_FINISHED
) {
1656 goto lpfc_handle_latt_free_mbuf
;
1659 /* Clear Link Attention in HA REG */
1660 spin_lock_irq(&phba
->hbalock
);
1661 writel(HA_LATT
, phba
->HAregaddr
);
1662 readl(phba
->HAregaddr
); /* flush */
1663 spin_unlock_irq(&phba
->hbalock
);
1667 lpfc_handle_latt_free_mbuf
:
1668 phba
->sli
.ring
[LPFC_ELS_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1669 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1670 lpfc_handle_latt_free_mp
:
1672 lpfc_handle_latt_free_pmb
:
1673 mempool_free(pmb
, phba
->mbox_mem_pool
);
1674 lpfc_handle_latt_err_exit
:
1675 /* Enable Link attention interrupts */
1676 spin_lock_irq(&phba
->hbalock
);
1677 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1678 control
= readl(phba
->HCregaddr
);
1679 control
|= HC_LAINT_ENA
;
1680 writel(control
, phba
->HCregaddr
);
1681 readl(phba
->HCregaddr
); /* flush */
1683 /* Clear Link Attention in HA REG */
1684 writel(HA_LATT
, phba
->HAregaddr
);
1685 readl(phba
->HAregaddr
); /* flush */
1686 spin_unlock_irq(&phba
->hbalock
);
1687 lpfc_linkdown(phba
);
1688 phba
->link_state
= LPFC_HBA_ERROR
;
1690 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1691 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc
);
1697 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
1698 * @phba: pointer to lpfc hba data structure.
1699 * @vpd: pointer to the vital product data.
1700 * @len: length of the vital product data in bytes.
1702 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1703 * an array of characters. In this routine, the ModelName, ProgramType, and
1704 * ModelDesc, etc. fields of the phba data structure will be populated.
1707 * 0 - pointer to the VPD passed in is NULL
1711 lpfc_parse_vpd(struct lpfc_hba
*phba
, uint8_t *vpd
, int len
)
1713 uint8_t lenlo
, lenhi
;
1723 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1724 "0455 Vital Product Data: x%x x%x x%x x%x\n",
1725 (uint32_t) vpd
[0], (uint32_t) vpd
[1], (uint32_t) vpd
[2],
1727 while (!finished
&& (index
< (len
- 4))) {
1728 switch (vpd
[index
]) {
1736 i
= ((((unsigned short)lenhi
) << 8) + lenlo
);
1745 Length
= ((((unsigned short)lenhi
) << 8) + lenlo
);
1746 if (Length
> len
- index
)
1747 Length
= len
- index
;
1748 while (Length
> 0) {
1749 /* Look for Serial Number */
1750 if ((vpd
[index
] == 'S') && (vpd
[index
+1] == 'N')) {
1757 phba
->SerialNumber
[j
++] = vpd
[index
++];
1761 phba
->SerialNumber
[j
] = 0;
1764 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '1')) {
1765 phba
->vpd_flag
|= VPD_MODEL_DESC
;
1772 phba
->ModelDesc
[j
++] = vpd
[index
++];
1776 phba
->ModelDesc
[j
] = 0;
1779 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '2')) {
1780 phba
->vpd_flag
|= VPD_MODEL_NAME
;
1787 phba
->ModelName
[j
++] = vpd
[index
++];
1791 phba
->ModelName
[j
] = 0;
1794 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '3')) {
1795 phba
->vpd_flag
|= VPD_PROGRAM_TYPE
;
1802 phba
->ProgramType
[j
++] = vpd
[index
++];
1806 phba
->ProgramType
[j
] = 0;
1809 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '4')) {
1810 phba
->vpd_flag
|= VPD_PORT
;
1817 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
1818 (phba
->sli4_hba
.pport_name_sta
==
1819 LPFC_SLI4_PPNAME_GET
)) {
1823 phba
->Port
[j
++] = vpd
[index
++];
1827 if ((phba
->sli_rev
!= LPFC_SLI_REV4
) ||
1828 (phba
->sli4_hba
.pport_name_sta
==
1829 LPFC_SLI4_PPNAME_NON
))
1856 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
1857 * @phba: pointer to lpfc hba data structure.
1858 * @mdp: pointer to the data structure to hold the derived model name.
1859 * @descp: pointer to the data structure to hold the derived description.
1861 * This routine retrieves HBA's description based on its registered PCI device
1862 * ID. The @descp passed into this function points to an array of 256 chars. It
1863 * shall be returned with the model name, maximum speed, and the host bus type.
1864 * The @mdp passed into this function points to an array of 80 chars. When the
1865 * function returns, the @mdp will be filled with the model name.
1868 lpfc_get_hba_model_desc(struct lpfc_hba
*phba
, uint8_t *mdp
, uint8_t *descp
)
1871 uint16_t dev_id
= phba
->pcidev
->device
;
1874 int oneConnect
= 0; /* default is not a oneConnect */
1879 } m
= {"<Unknown>", "", ""};
1881 if (mdp
&& mdp
[0] != '\0'
1882 && descp
&& descp
[0] != '\0')
1885 if (phba
->lmt
& LMT_16Gb
)
1887 else if (phba
->lmt
& LMT_10Gb
)
1889 else if (phba
->lmt
& LMT_8Gb
)
1891 else if (phba
->lmt
& LMT_4Gb
)
1893 else if (phba
->lmt
& LMT_2Gb
)
1901 case PCI_DEVICE_ID_FIREFLY
:
1902 m
= (typeof(m
)){"LP6000", "PCI", "Fibre Channel Adapter"};
1904 case PCI_DEVICE_ID_SUPERFLY
:
1905 if (vp
->rev
.biuRev
>= 1 && vp
->rev
.biuRev
<= 3)
1906 m
= (typeof(m
)){"LP7000", "PCI",
1907 "Fibre Channel Adapter"};
1909 m
= (typeof(m
)){"LP7000E", "PCI",
1910 "Fibre Channel Adapter"};
1912 case PCI_DEVICE_ID_DRAGONFLY
:
1913 m
= (typeof(m
)){"LP8000", "PCI",
1914 "Fibre Channel Adapter"};
1916 case PCI_DEVICE_ID_CENTAUR
:
1917 if (FC_JEDEC_ID(vp
->rev
.biuRev
) == CENTAUR_2G_JEDEC_ID
)
1918 m
= (typeof(m
)){"LP9002", "PCI",
1919 "Fibre Channel Adapter"};
1921 m
= (typeof(m
)){"LP9000", "PCI",
1922 "Fibre Channel Adapter"};
1924 case PCI_DEVICE_ID_RFLY
:
1925 m
= (typeof(m
)){"LP952", "PCI",
1926 "Fibre Channel Adapter"};
1928 case PCI_DEVICE_ID_PEGASUS
:
1929 m
= (typeof(m
)){"LP9802", "PCI-X",
1930 "Fibre Channel Adapter"};
1932 case PCI_DEVICE_ID_THOR
:
1933 m
= (typeof(m
)){"LP10000", "PCI-X",
1934 "Fibre Channel Adapter"};
1936 case PCI_DEVICE_ID_VIPER
:
1937 m
= (typeof(m
)){"LPX1000", "PCI-X",
1938 "Fibre Channel Adapter"};
1940 case PCI_DEVICE_ID_PFLY
:
1941 m
= (typeof(m
)){"LP982", "PCI-X",
1942 "Fibre Channel Adapter"};
1944 case PCI_DEVICE_ID_TFLY
:
1945 m
= (typeof(m
)){"LP1050", "PCI-X",
1946 "Fibre Channel Adapter"};
1948 case PCI_DEVICE_ID_HELIOS
:
1949 m
= (typeof(m
)){"LP11000", "PCI-X2",
1950 "Fibre Channel Adapter"};
1952 case PCI_DEVICE_ID_HELIOS_SCSP
:
1953 m
= (typeof(m
)){"LP11000-SP", "PCI-X2",
1954 "Fibre Channel Adapter"};
1956 case PCI_DEVICE_ID_HELIOS_DCSP
:
1957 m
= (typeof(m
)){"LP11002-SP", "PCI-X2",
1958 "Fibre Channel Adapter"};
1960 case PCI_DEVICE_ID_NEPTUNE
:
1961 m
= (typeof(m
)){"LPe1000", "PCIe", "Fibre Channel Adapter"};
1963 case PCI_DEVICE_ID_NEPTUNE_SCSP
:
1964 m
= (typeof(m
)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"};
1966 case PCI_DEVICE_ID_NEPTUNE_DCSP
:
1967 m
= (typeof(m
)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"};
1969 case PCI_DEVICE_ID_BMID
:
1970 m
= (typeof(m
)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
1972 case PCI_DEVICE_ID_BSMB
:
1973 m
= (typeof(m
)){"LP111", "PCI-X2", "Fibre Channel Adapter"};
1975 case PCI_DEVICE_ID_ZEPHYR
:
1976 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
1978 case PCI_DEVICE_ID_ZEPHYR_SCSP
:
1979 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
1981 case PCI_DEVICE_ID_ZEPHYR_DCSP
:
1982 m
= (typeof(m
)){"LP2105", "PCIe", "FCoE Adapter"};
1985 case PCI_DEVICE_ID_ZMID
:
1986 m
= (typeof(m
)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
1988 case PCI_DEVICE_ID_ZSMB
:
1989 m
= (typeof(m
)){"LPe111", "PCIe", "Fibre Channel Adapter"};
1991 case PCI_DEVICE_ID_LP101
:
1992 m
= (typeof(m
)){"LP101", "PCI-X", "Fibre Channel Adapter"};
1994 case PCI_DEVICE_ID_LP10000S
:
1995 m
= (typeof(m
)){"LP10000-S", "PCI", "Fibre Channel Adapter"};
1997 case PCI_DEVICE_ID_LP11000S
:
1998 m
= (typeof(m
)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"};
2000 case PCI_DEVICE_ID_LPE11000S
:
2001 m
= (typeof(m
)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"};
2003 case PCI_DEVICE_ID_SAT
:
2004 m
= (typeof(m
)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2006 case PCI_DEVICE_ID_SAT_MID
:
2007 m
= (typeof(m
)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2009 case PCI_DEVICE_ID_SAT_SMB
:
2010 m
= (typeof(m
)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2012 case PCI_DEVICE_ID_SAT_DCSP
:
2013 m
= (typeof(m
)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2015 case PCI_DEVICE_ID_SAT_SCSP
:
2016 m
= (typeof(m
)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2018 case PCI_DEVICE_ID_SAT_S
:
2019 m
= (typeof(m
)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2021 case PCI_DEVICE_ID_HORNET
:
2022 m
= (typeof(m
)){"LP21000", "PCIe", "FCoE Adapter"};
2025 case PCI_DEVICE_ID_PROTEUS_VF
:
2026 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
2027 "Fibre Channel Adapter"};
2029 case PCI_DEVICE_ID_PROTEUS_PF
:
2030 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
2031 "Fibre Channel Adapter"};
2033 case PCI_DEVICE_ID_PROTEUS_S
:
2034 m
= (typeof(m
)){"LPemv12002-S", "PCIe IOV",
2035 "Fibre Channel Adapter"};
2037 case PCI_DEVICE_ID_TIGERSHARK
:
2039 m
= (typeof(m
)){"OCe10100", "PCIe", "FCoE"};
2041 case PCI_DEVICE_ID_TOMCAT
:
2043 m
= (typeof(m
)){"OCe11100", "PCIe", "FCoE"};
2045 case PCI_DEVICE_ID_FALCON
:
2046 m
= (typeof(m
)){"LPSe12002-ML1-E", "PCIe",
2047 "EmulexSecure Fibre"};
2049 case PCI_DEVICE_ID_BALIUS
:
2050 m
= (typeof(m
)){"LPVe12002", "PCIe Shared I/O",
2051 "Fibre Channel Adapter"};
2053 case PCI_DEVICE_ID_LANCER_FC
:
2054 case PCI_DEVICE_ID_LANCER_FC_VF
:
2055 m
= (typeof(m
)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2057 case PCI_DEVICE_ID_LANCER_FCOE
:
2058 case PCI_DEVICE_ID_LANCER_FCOE_VF
:
2060 m
= (typeof(m
)){"OCe15100", "PCIe", "FCoE"};
2062 case PCI_DEVICE_ID_SKYHAWK
:
2063 case PCI_DEVICE_ID_SKYHAWK_VF
:
2065 m
= (typeof(m
)){"OCe14000", "PCIe", "FCoE"};
2068 m
= (typeof(m
)){"Unknown", "", ""};
2072 if (mdp
&& mdp
[0] == '\0')
2073 snprintf(mdp
, 79,"%s", m
.name
);
2075 * oneConnect hba requires special processing, they are all initiators
2076 * and we put the port number on the end
2078 if (descp
&& descp
[0] == '\0') {
2080 snprintf(descp
, 255,
2081 "Emulex OneConnect %s, %s Initiator, Port %s",
2085 snprintf(descp
, 255,
2086 "Emulex %s %d%s %s %s",
2087 m
.name
, max_speed
, (GE
) ? "GE" : "Gb",
2093 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2094 * @phba: pointer to lpfc hba data structure.
2095 * @pring: pointer to a IOCB ring.
2096 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2098 * This routine posts a given number of IOCBs with the associated DMA buffer
2099 * descriptors specified by the cnt argument to the given IOCB ring.
2102 * The number of IOCBs NOT able to be posted to the IOCB ring.
2105 lpfc_post_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
, int cnt
)
2108 struct lpfc_iocbq
*iocb
;
2109 struct lpfc_dmabuf
*mp1
, *mp2
;
2111 cnt
+= pring
->missbufcnt
;
2113 /* While there are buffers to post */
2115 /* Allocate buffer for command iocb */
2116 iocb
= lpfc_sli_get_iocbq(phba
);
2118 pring
->missbufcnt
= cnt
;
2123 /* 2 buffers can be posted per command */
2124 /* Allocate buffer to post */
2125 mp1
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
2127 mp1
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &mp1
->phys
);
2128 if (!mp1
|| !mp1
->virt
) {
2130 lpfc_sli_release_iocbq(phba
, iocb
);
2131 pring
->missbufcnt
= cnt
;
2135 INIT_LIST_HEAD(&mp1
->list
);
2136 /* Allocate buffer to post */
2138 mp2
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
2140 mp2
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
2142 if (!mp2
|| !mp2
->virt
) {
2144 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
2146 lpfc_sli_release_iocbq(phba
, iocb
);
2147 pring
->missbufcnt
= cnt
;
2151 INIT_LIST_HEAD(&mp2
->list
);
2156 icmd
->un
.cont64
[0].addrHigh
= putPaddrHigh(mp1
->phys
);
2157 icmd
->un
.cont64
[0].addrLow
= putPaddrLow(mp1
->phys
);
2158 icmd
->un
.cont64
[0].tus
.f
.bdeSize
= FCELSSIZE
;
2159 icmd
->ulpBdeCount
= 1;
2162 icmd
->un
.cont64
[1].addrHigh
= putPaddrHigh(mp2
->phys
);
2163 icmd
->un
.cont64
[1].addrLow
= putPaddrLow(mp2
->phys
);
2164 icmd
->un
.cont64
[1].tus
.f
.bdeSize
= FCELSSIZE
;
2166 icmd
->ulpBdeCount
= 2;
2169 icmd
->ulpCommand
= CMD_QUE_RING_BUF64_CN
;
2172 if (lpfc_sli_issue_iocb(phba
, pring
->ringno
, iocb
, 0) ==
2174 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
2178 lpfc_mbuf_free(phba
, mp2
->virt
, mp2
->phys
);
2182 lpfc_sli_release_iocbq(phba
, iocb
);
2183 pring
->missbufcnt
= cnt
;
2186 lpfc_sli_ringpostbuf_put(phba
, pring
, mp1
);
2188 lpfc_sli_ringpostbuf_put(phba
, pring
, mp2
);
2190 pring
->missbufcnt
= 0;
2195 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2196 * @phba: pointer to lpfc hba data structure.
2198 * This routine posts initial receive IOCB buffers to the ELS ring. The
2199 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2203 * 0 - success (currently always success)
2206 lpfc_post_rcv_buf(struct lpfc_hba
*phba
)
2208 struct lpfc_sli
*psli
= &phba
->sli
;
2210 /* Ring 0, ELS / CT buffers */
2211 lpfc_post_buffer(phba
, &psli
->ring
[LPFC_ELS_RING
], LPFC_BUF_RING0
);
2212 /* Ring 2 - FCP no buffers needed */
2217 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2220 * lpfc_sha_init - Set up initial array of hash table entries
2221 * @HashResultPointer: pointer to an array as hash table.
2223 * This routine sets up the initial values to the array of hash table entries
2227 lpfc_sha_init(uint32_t * HashResultPointer
)
2229 HashResultPointer
[0] = 0x67452301;
2230 HashResultPointer
[1] = 0xEFCDAB89;
2231 HashResultPointer
[2] = 0x98BADCFE;
2232 HashResultPointer
[3] = 0x10325476;
2233 HashResultPointer
[4] = 0xC3D2E1F0;
2237 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2238 * @HashResultPointer: pointer to an initial/result hash table.
2239 * @HashWorkingPointer: pointer to an working hash table.
2241 * This routine iterates an initial hash table pointed by @HashResultPointer
2242 * with the values from the working hash table pointeed by @HashWorkingPointer.
2243 * The results are putting back to the initial hash table, returned through
2244 * the @HashResultPointer as the result hash table.
2247 lpfc_sha_iterate(uint32_t * HashResultPointer
, uint32_t * HashWorkingPointer
)
2251 uint32_t A
, B
, C
, D
, E
;
2254 HashWorkingPointer
[t
] =
2256 HashWorkingPointer
[t
- 3] ^ HashWorkingPointer
[t
-
2258 HashWorkingPointer
[t
- 14] ^ HashWorkingPointer
[t
- 16]);
2259 } while (++t
<= 79);
2261 A
= HashResultPointer
[0];
2262 B
= HashResultPointer
[1];
2263 C
= HashResultPointer
[2];
2264 D
= HashResultPointer
[3];
2265 E
= HashResultPointer
[4];
2269 TEMP
= ((B
& C
) | ((~B
) & D
)) + 0x5A827999;
2270 } else if (t
< 40) {
2271 TEMP
= (B
^ C
^ D
) + 0x6ED9EBA1;
2272 } else if (t
< 60) {
2273 TEMP
= ((B
& C
) | (B
& D
) | (C
& D
)) + 0x8F1BBCDC;
2275 TEMP
= (B
^ C
^ D
) + 0xCA62C1D6;
2277 TEMP
+= S(5, A
) + E
+ HashWorkingPointer
[t
];
2283 } while (++t
<= 79);
2285 HashResultPointer
[0] += A
;
2286 HashResultPointer
[1] += B
;
2287 HashResultPointer
[2] += C
;
2288 HashResultPointer
[3] += D
;
2289 HashResultPointer
[4] += E
;
2294 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2295 * @RandomChallenge: pointer to the entry of host challenge random number array.
2296 * @HashWorking: pointer to the entry of the working hash array.
2298 * This routine calculates the working hash array referred by @HashWorking
2299 * from the challenge random numbers associated with the host, referred by
2300 * @RandomChallenge. The result is put into the entry of the working hash
2301 * array and returned by reference through @HashWorking.
2304 lpfc_challenge_key(uint32_t * RandomChallenge
, uint32_t * HashWorking
)
2306 *HashWorking
= (*RandomChallenge
^ *HashWorking
);
2310 * lpfc_hba_init - Perform special handling for LC HBA initialization
2311 * @phba: pointer to lpfc hba data structure.
2312 * @hbainit: pointer to an array of unsigned 32-bit integers.
2314 * This routine performs the special handling for LC HBA initialization.
2317 lpfc_hba_init(struct lpfc_hba
*phba
, uint32_t *hbainit
)
2320 uint32_t *HashWorking
;
2321 uint32_t *pwwnn
= (uint32_t *) phba
->wwnn
;
2323 HashWorking
= kcalloc(80, sizeof(uint32_t), GFP_KERNEL
);
2327 HashWorking
[0] = HashWorking
[78] = *pwwnn
++;
2328 HashWorking
[1] = HashWorking
[79] = *pwwnn
;
2330 for (t
= 0; t
< 7; t
++)
2331 lpfc_challenge_key(phba
->RandomData
+ t
, HashWorking
+ t
);
2333 lpfc_sha_init(hbainit
);
2334 lpfc_sha_iterate(hbainit
, HashWorking
);
2339 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2340 * @vport: pointer to a virtual N_Port data structure.
2342 * This routine performs the necessary cleanups before deleting the @vport.
2343 * It invokes the discovery state machine to perform necessary state
2344 * transitions and to release the ndlps associated with the @vport. Note,
2345 * the physical port is treated as @vport 0.
2348 lpfc_cleanup(struct lpfc_vport
*vport
)
2350 struct lpfc_hba
*phba
= vport
->phba
;
2351 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2354 if (phba
->link_state
> LPFC_LINK_DOWN
)
2355 lpfc_port_link_failure(vport
);
2357 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2358 if (!NLP_CHK_NODE_ACT(ndlp
)) {
2359 ndlp
= lpfc_enable_node(vport
, ndlp
,
2360 NLP_STE_UNUSED_NODE
);
2363 spin_lock_irq(&phba
->ndlp_lock
);
2364 NLP_SET_FREE_REQ(ndlp
);
2365 spin_unlock_irq(&phba
->ndlp_lock
);
2366 /* Trigger the release of the ndlp memory */
2370 spin_lock_irq(&phba
->ndlp_lock
);
2371 if (NLP_CHK_FREE_REQ(ndlp
)) {
2372 /* The ndlp should not be in memory free mode already */
2373 spin_unlock_irq(&phba
->ndlp_lock
);
2376 /* Indicate request for freeing ndlp memory */
2377 NLP_SET_FREE_REQ(ndlp
);
2378 spin_unlock_irq(&phba
->ndlp_lock
);
2380 if (vport
->port_type
!= LPFC_PHYSICAL_PORT
&&
2381 ndlp
->nlp_DID
== Fabric_DID
) {
2382 /* Just free up ndlp with Fabric_DID for vports */
2387 /* take care of nodes in unused state before the state
2388 * machine taking action.
2390 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
2395 if (ndlp
->nlp_type
& NLP_FABRIC
)
2396 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2397 NLP_EVT_DEVICE_RECOVERY
);
2399 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2403 /* At this point, ALL ndlp's should be gone
2404 * because of the previous NLP_EVT_DEVICE_RM.
2405 * Lets wait for this to happen, if needed.
2407 while (!list_empty(&vport
->fc_nodes
)) {
2409 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2410 "0233 Nodelist not empty\n");
2411 list_for_each_entry_safe(ndlp
, next_ndlp
,
2412 &vport
->fc_nodes
, nlp_listp
) {
2413 lpfc_printf_vlog(ndlp
->vport
, KERN_ERR
,
2415 "0282 did:x%x ndlp:x%p "
2416 "usgmap:x%x refcnt:%d\n",
2417 ndlp
->nlp_DID
, (void *)ndlp
,
2420 &ndlp
->kref
.refcount
));
2425 /* Wait for any activity on ndlps to settle */
2428 lpfc_cleanup_vports_rrqs(vport
, NULL
);
2432 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2433 * @vport: pointer to a virtual N_Port data structure.
2435 * This routine stops all the timers associated with a @vport. This function
2436 * is invoked before disabling or deleting a @vport. Note that the physical
2437 * port is treated as @vport 0.
2440 lpfc_stop_vport_timers(struct lpfc_vport
*vport
)
2442 del_timer_sync(&vport
->els_tmofunc
);
2443 del_timer_sync(&vport
->fc_fdmitmo
);
2444 del_timer_sync(&vport
->delayed_disc_tmo
);
2445 lpfc_can_disctmo(vport
);
2450 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2451 * @phba: pointer to lpfc hba data structure.
2453 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2454 * caller of this routine should already hold the host lock.
2457 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2459 /* Clear pending FCF rediscovery wait flag */
2460 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_PEND
;
2462 /* Now, try to stop the timer */
2463 del_timer(&phba
->fcf
.redisc_wait
);
2467 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2468 * @phba: pointer to lpfc hba data structure.
2470 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2471 * checks whether the FCF rediscovery wait timer is pending with the host
2472 * lock held before proceeding with disabling the timer and clearing the
2473 * wait timer pendig flag.
2476 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2478 spin_lock_irq(&phba
->hbalock
);
2479 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
2480 /* FCF rediscovery timer already fired or stopped */
2481 spin_unlock_irq(&phba
->hbalock
);
2484 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
2485 /* Clear failover in progress flags */
2486 phba
->fcf
.fcf_flag
&= ~(FCF_DEAD_DISC
| FCF_ACVL_DISC
);
2487 spin_unlock_irq(&phba
->hbalock
);
2491 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2492 * @phba: pointer to lpfc hba data structure.
2494 * This routine stops all the timers associated with a HBA. This function is
2495 * invoked before either putting a HBA offline or unloading the driver.
2498 lpfc_stop_hba_timers(struct lpfc_hba
*phba
)
2500 lpfc_stop_vport_timers(phba
->pport
);
2501 del_timer_sync(&phba
->sli
.mbox_tmo
);
2502 del_timer_sync(&phba
->fabric_block_timer
);
2503 del_timer_sync(&phba
->eratt_poll
);
2504 del_timer_sync(&phba
->hb_tmofunc
);
2505 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2506 del_timer_sync(&phba
->rrq_tmr
);
2507 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
2509 phba
->hb_outstanding
= 0;
2511 switch (phba
->pci_dev_grp
) {
2512 case LPFC_PCI_DEV_LP
:
2513 /* Stop any LightPulse device specific driver timers */
2514 del_timer_sync(&phba
->fcp_poll_timer
);
2516 case LPFC_PCI_DEV_OC
:
2517 /* Stop any OneConnect device sepcific driver timers */
2518 lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
2521 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2522 "0297 Invalid device group (x%x)\n",
2530 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
2531 * @phba: pointer to lpfc hba data structure.
2533 * This routine marks a HBA's management interface as blocked. Once the HBA's
2534 * management interface is marked as blocked, all the user space access to
2535 * the HBA, whether they are from sysfs interface or libdfc interface will
2536 * all be blocked. The HBA is set to block the management interface when the
2537 * driver prepares the HBA interface for online or offline.
2540 lpfc_block_mgmt_io(struct lpfc_hba
*phba
, int mbx_action
)
2542 unsigned long iflag
;
2543 uint8_t actcmd
= MBX_HEARTBEAT
;
2544 unsigned long timeout
;
2546 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2547 phba
->sli
.sli_flag
|= LPFC_BLOCK_MGMT_IO
;
2548 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2549 if (mbx_action
== LPFC_MBX_NO_WAIT
)
2551 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
2552 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2553 if (phba
->sli
.mbox_active
) {
2554 actcmd
= phba
->sli
.mbox_active
->u
.mb
.mbxCommand
;
2555 /* Determine how long we might wait for the active mailbox
2556 * command to be gracefully completed by firmware.
2558 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
2559 phba
->sli
.mbox_active
) * 1000) + jiffies
;
2561 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2563 /* Wait for the outstnading mailbox command to complete */
2564 while (phba
->sli
.mbox_active
) {
2565 /* Check active mailbox complete status every 2ms */
2567 if (time_after(jiffies
, timeout
)) {
2568 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2569 "2813 Mgmt IO is Blocked %x "
2570 "- mbox cmd %x still active\n",
2571 phba
->sli
.sli_flag
, actcmd
);
2578 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2579 * @phba: pointer to lpfc hba data structure.
2581 * Allocate RPIs for all active remote nodes. This is needed whenever
2582 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2583 * is to fixup the temporary rpi assignments.
2586 lpfc_sli4_node_prep(struct lpfc_hba
*phba
)
2588 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2589 struct lpfc_vport
**vports
;
2592 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
2595 vports
= lpfc_create_vport_work_array(phba
);
2596 if (vports
!= NULL
) {
2597 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2598 if (vports
[i
]->load_flag
& FC_UNLOADING
)
2601 list_for_each_entry_safe(ndlp
, next_ndlp
,
2602 &vports
[i
]->fc_nodes
,
2604 if (NLP_CHK_NODE_ACT(ndlp
))
2606 lpfc_sli4_alloc_rpi(phba
);
2610 lpfc_destroy_vport_work_array(phba
, vports
);
2614 * lpfc_online - Initialize and bring a HBA online
2615 * @phba: pointer to lpfc hba data structure.
2617 * This routine initializes the HBA and brings a HBA online. During this
2618 * process, the management interface is blocked to prevent user space access
2619 * to the HBA interfering with the driver initialization.
2626 lpfc_online(struct lpfc_hba
*phba
)
2628 struct lpfc_vport
*vport
;
2629 struct lpfc_vport
**vports
;
2634 vport
= phba
->pport
;
2636 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
))
2639 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2640 "0458 Bring Adapter online\n");
2642 lpfc_block_mgmt_io(phba
, LPFC_MBX_WAIT
);
2644 if (!lpfc_sli_queue_setup(phba
)) {
2645 lpfc_unblock_mgmt_io(phba
);
2649 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2650 if (lpfc_sli4_hba_setup(phba
)) { /* Initialize SLI4 HBA */
2651 lpfc_unblock_mgmt_io(phba
);
2655 if (lpfc_sli_hba_setup(phba
)) { /* Initialize SLI2/SLI3 HBA */
2656 lpfc_unblock_mgmt_io(phba
);
2661 vports
= lpfc_create_vport_work_array(phba
);
2663 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2664 struct Scsi_Host
*shost
;
2665 shost
= lpfc_shost_from_vport(vports
[i
]);
2666 spin_lock_irq(shost
->host_lock
);
2667 vports
[i
]->fc_flag
&= ~FC_OFFLINE_MODE
;
2668 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
2669 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2670 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2671 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
2672 spin_unlock_irq(shost
->host_lock
);
2674 lpfc_destroy_vport_work_array(phba
, vports
);
2676 lpfc_unblock_mgmt_io(phba
);
2681 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
2682 * @phba: pointer to lpfc hba data structure.
2684 * This routine marks a HBA's management interface as not blocked. Once the
2685 * HBA's management interface is marked as not blocked, all the user space
2686 * access to the HBA, whether they are from sysfs interface or libdfc
2687 * interface will be allowed. The HBA is set to block the management interface
2688 * when the driver prepares the HBA interface for online or offline and then
2689 * set to unblock the management interface afterwards.
2692 lpfc_unblock_mgmt_io(struct lpfc_hba
* phba
)
2694 unsigned long iflag
;
2696 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2697 phba
->sli
.sli_flag
&= ~LPFC_BLOCK_MGMT_IO
;
2698 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2702 * lpfc_offline_prep - Prepare a HBA to be brought offline
2703 * @phba: pointer to lpfc hba data structure.
2705 * This routine is invoked to prepare a HBA to be brought offline. It performs
2706 * unregistration login to all the nodes on all vports and flushes the mailbox
2707 * queue to make it ready to be brought offline.
2710 lpfc_offline_prep(struct lpfc_hba
*phba
, int mbx_action
)
2712 struct lpfc_vport
*vport
= phba
->pport
;
2713 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2714 struct lpfc_vport
**vports
;
2715 struct Scsi_Host
*shost
;
2718 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
2721 lpfc_block_mgmt_io(phba
, mbx_action
);
2723 lpfc_linkdown(phba
);
2725 /* Issue an unreg_login to all nodes on all vports */
2726 vports
= lpfc_create_vport_work_array(phba
);
2727 if (vports
!= NULL
) {
2728 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2729 if (vports
[i
]->load_flag
& FC_UNLOADING
)
2731 shost
= lpfc_shost_from_vport(vports
[i
]);
2732 spin_lock_irq(shost
->host_lock
);
2733 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
2734 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2735 vports
[i
]->fc_flag
&= ~FC_VFI_REGISTERED
;
2736 spin_unlock_irq(shost
->host_lock
);
2738 shost
= lpfc_shost_from_vport(vports
[i
]);
2739 list_for_each_entry_safe(ndlp
, next_ndlp
,
2740 &vports
[i
]->fc_nodes
,
2742 if (!NLP_CHK_NODE_ACT(ndlp
))
2744 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
2746 if (ndlp
->nlp_type
& NLP_FABRIC
) {
2747 lpfc_disc_state_machine(vports
[i
], ndlp
,
2748 NULL
, NLP_EVT_DEVICE_RECOVERY
);
2749 lpfc_disc_state_machine(vports
[i
], ndlp
,
2750 NULL
, NLP_EVT_DEVICE_RM
);
2752 spin_lock_irq(shost
->host_lock
);
2753 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2754 spin_unlock_irq(shost
->host_lock
);
2756 * Whenever an SLI4 port goes offline, free the
2757 * RPI. Get a new RPI when the adapter port
2758 * comes back online.
2760 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2761 lpfc_sli4_free_rpi(phba
, ndlp
->nlp_rpi
);
2762 lpfc_unreg_rpi(vports
[i
], ndlp
);
2766 lpfc_destroy_vport_work_array(phba
, vports
);
2768 lpfc_sli_mbox_sys_shutdown(phba
, mbx_action
);
2772 * lpfc_offline - Bring a HBA offline
2773 * @phba: pointer to lpfc hba data structure.
2775 * This routine actually brings a HBA offline. It stops all the timers
2776 * associated with the HBA, brings down the SLI layer, and eventually
2777 * marks the HBA as in offline state for the upper layer protocol.
2780 lpfc_offline(struct lpfc_hba
*phba
)
2782 struct Scsi_Host
*shost
;
2783 struct lpfc_vport
**vports
;
2786 if (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
2789 /* stop port and all timers associated with this hba */
2790 lpfc_stop_port(phba
);
2791 vports
= lpfc_create_vport_work_array(phba
);
2793 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
2794 lpfc_stop_vport_timers(vports
[i
]);
2795 lpfc_destroy_vport_work_array(phba
, vports
);
2796 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2797 "0460 Bring Adapter offline\n");
2798 /* Bring down the SLI Layer and cleanup. The HBA is offline
2800 lpfc_sli_hba_down(phba
);
2801 spin_lock_irq(&phba
->hbalock
);
2803 spin_unlock_irq(&phba
->hbalock
);
2804 vports
= lpfc_create_vport_work_array(phba
);
2806 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2807 shost
= lpfc_shost_from_vport(vports
[i
]);
2808 spin_lock_irq(shost
->host_lock
);
2809 vports
[i
]->work_port_events
= 0;
2810 vports
[i
]->fc_flag
|= FC_OFFLINE_MODE
;
2811 spin_unlock_irq(shost
->host_lock
);
2813 lpfc_destroy_vport_work_array(phba
, vports
);
2817 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
2818 * @phba: pointer to lpfc hba data structure.
2820 * This routine is to free all the SCSI buffers and IOCBs from the driver
2821 * list back to kernel. It is called from lpfc_pci_remove_one to free
2822 * the internal resources before the device is removed from the system.
2825 lpfc_scsi_free(struct lpfc_hba
*phba
)
2827 struct lpfc_scsi_buf
*sb
, *sb_next
;
2828 struct lpfc_iocbq
*io
, *io_next
;
2830 spin_lock_irq(&phba
->hbalock
);
2831 /* Release all the lpfc_scsi_bufs maintained by this host. */
2832 spin_lock(&phba
->scsi_buf_list_lock
);
2833 list_for_each_entry_safe(sb
, sb_next
, &phba
->lpfc_scsi_buf_list
, list
) {
2834 list_del(&sb
->list
);
2835 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
, sb
->data
,
2838 phba
->total_scsi_bufs
--;
2840 spin_unlock(&phba
->scsi_buf_list_lock
);
2842 /* Release all the lpfc_iocbq entries maintained by this host. */
2843 list_for_each_entry_safe(io
, io_next
, &phba
->lpfc_iocb_list
, list
) {
2844 list_del(&io
->list
);
2846 phba
->total_iocbq_bufs
--;
2849 spin_unlock_irq(&phba
->hbalock
);
2853 * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
2854 * @phba: pointer to lpfc hba data structure.
2856 * This routine first calculates the sizes of the current els and allocated
2857 * scsi sgl lists, and then goes through all sgls to updates the physical
2858 * XRIs assigned due to port function reset. During port initialization, the
2859 * current els and allocated scsi sgl lists are 0s.
2862 * 0 - successful (for now, it always returns 0)
2865 lpfc_sli4_xri_sgl_update(struct lpfc_hba
*phba
)
2867 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_entry_next
= NULL
;
2868 struct lpfc_scsi_buf
*psb
= NULL
, *psb_next
= NULL
;
2869 uint16_t i
, lxri
, xri_cnt
, els_xri_cnt
, scsi_xri_cnt
;
2870 LIST_HEAD(els_sgl_list
);
2871 LIST_HEAD(scsi_sgl_list
);
2875 * update on pci function's els xri-sgl list
2877 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
2878 if (els_xri_cnt
> phba
->sli4_hba
.els_xri_cnt
) {
2879 /* els xri-sgl expanded */
2880 xri_cnt
= els_xri_cnt
- phba
->sli4_hba
.els_xri_cnt
;
2881 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2882 "3157 ELS xri-sgl count increased from "
2883 "%d to %d\n", phba
->sli4_hba
.els_xri_cnt
,
2885 /* allocate the additional els sgls */
2886 for (i
= 0; i
< xri_cnt
; i
++) {
2887 sglq_entry
= kzalloc(sizeof(struct lpfc_sglq
),
2889 if (sglq_entry
== NULL
) {
2890 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2891 "2562 Failure to allocate an "
2892 "ELS sgl entry:%d\n", i
);
2896 sglq_entry
->buff_type
= GEN_BUFF_TYPE
;
2897 sglq_entry
->virt
= lpfc_mbuf_alloc(phba
, 0,
2899 if (sglq_entry
->virt
== NULL
) {
2901 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2902 "2563 Failure to allocate an "
2903 "ELS mbuf:%d\n", i
);
2907 sglq_entry
->sgl
= sglq_entry
->virt
;
2908 memset(sglq_entry
->sgl
, 0, LPFC_BPL_SIZE
);
2909 sglq_entry
->state
= SGL_FREED
;
2910 list_add_tail(&sglq_entry
->list
, &els_sgl_list
);
2912 spin_lock(&phba
->hbalock
);
2913 list_splice_init(&els_sgl_list
, &phba
->sli4_hba
.lpfc_sgl_list
);
2914 spin_unlock(&phba
->hbalock
);
2915 } else if (els_xri_cnt
< phba
->sli4_hba
.els_xri_cnt
) {
2916 /* els xri-sgl shrinked */
2917 xri_cnt
= phba
->sli4_hba
.els_xri_cnt
- els_xri_cnt
;
2918 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2919 "3158 ELS xri-sgl count decreased from "
2920 "%d to %d\n", phba
->sli4_hba
.els_xri_cnt
,
2922 spin_lock_irq(&phba
->hbalock
);
2923 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &els_sgl_list
);
2924 spin_unlock_irq(&phba
->hbalock
);
2925 /* release extra els sgls from list */
2926 for (i
= 0; i
< xri_cnt
; i
++) {
2927 list_remove_head(&els_sgl_list
,
2928 sglq_entry
, struct lpfc_sglq
, list
);
2930 lpfc_mbuf_free(phba
, sglq_entry
->virt
,
2935 spin_lock_irq(&phba
->hbalock
);
2936 list_splice_init(&els_sgl_list
, &phba
->sli4_hba
.lpfc_sgl_list
);
2937 spin_unlock_irq(&phba
->hbalock
);
2939 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2940 "3163 ELS xri-sgl count unchanged: %d\n",
2942 phba
->sli4_hba
.els_xri_cnt
= els_xri_cnt
;
2944 /* update xris to els sgls on the list */
2946 sglq_entry_next
= NULL
;
2947 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
2948 &phba
->sli4_hba
.lpfc_sgl_list
, list
) {
2949 lxri
= lpfc_sli4_next_xritag(phba
);
2950 if (lxri
== NO_XRI
) {
2951 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2952 "2400 Failed to allocate xri for "
2957 sglq_entry
->sli4_lxritag
= lxri
;
2958 sglq_entry
->sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
2962 * update on pci function's allocated scsi xri-sgl list
2964 phba
->total_scsi_bufs
= 0;
2966 /* maximum number of xris available for scsi buffers */
2967 phba
->sli4_hba
.scsi_xri_max
= phba
->sli4_hba
.max_cfg_param
.max_xri
-
2970 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2971 "2401 Current allocated SCSI xri-sgl count:%d, "
2972 "maximum SCSI xri count:%d\n",
2973 phba
->sli4_hba
.scsi_xri_cnt
,
2974 phba
->sli4_hba
.scsi_xri_max
);
2976 spin_lock_irq(&phba
->scsi_buf_list_lock
);
2977 list_splice_init(&phba
->lpfc_scsi_buf_list
, &scsi_sgl_list
);
2978 spin_unlock_irq(&phba
->scsi_buf_list_lock
);
2980 if (phba
->sli4_hba
.scsi_xri_cnt
> phba
->sli4_hba
.scsi_xri_max
) {
2981 /* max scsi xri shrinked below the allocated scsi buffers */
2982 scsi_xri_cnt
= phba
->sli4_hba
.scsi_xri_cnt
-
2983 phba
->sli4_hba
.scsi_xri_max
;
2984 /* release the extra allocated scsi buffers */
2985 for (i
= 0; i
< scsi_xri_cnt
; i
++) {
2986 list_remove_head(&scsi_sgl_list
, psb
,
2987 struct lpfc_scsi_buf
, list
);
2988 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
, psb
->data
,
2992 spin_lock_irq(&phba
->scsi_buf_list_lock
);
2993 phba
->sli4_hba
.scsi_xri_cnt
-= scsi_xri_cnt
;
2994 spin_unlock_irq(&phba
->scsi_buf_list_lock
);
2997 /* update xris associated to remaining allocated scsi buffers */
3000 list_for_each_entry_safe(psb
, psb_next
, &scsi_sgl_list
, list
) {
3001 lxri
= lpfc_sli4_next_xritag(phba
);
3002 if (lxri
== NO_XRI
) {
3003 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3004 "2560 Failed to allocate xri for "
3009 psb
->cur_iocbq
.sli4_lxritag
= lxri
;
3010 psb
->cur_iocbq
.sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
3012 spin_lock(&phba
->scsi_buf_list_lock
);
3013 list_splice_init(&scsi_sgl_list
, &phba
->lpfc_scsi_buf_list
);
3014 spin_unlock(&phba
->scsi_buf_list_lock
);
3019 lpfc_free_els_sgl_list(phba
);
3020 lpfc_scsi_free(phba
);
3025 * lpfc_create_port - Create an FC port
3026 * @phba: pointer to lpfc hba data structure.
3027 * @instance: a unique integer ID to this FC port.
3028 * @dev: pointer to the device data structure.
3030 * This routine creates a FC port for the upper layer protocol. The FC port
3031 * can be created on top of either a physical port or a virtual port provided
3032 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3033 * and associates the FC port created before adding the shost into the SCSI
3037 * @vport - pointer to the virtual N_Port data structure.
3038 * NULL - port create failed.
3041 lpfc_create_port(struct lpfc_hba
*phba
, int instance
, struct device
*dev
)
3043 struct lpfc_vport
*vport
;
3044 struct Scsi_Host
*shost
;
3047 if (dev
!= &phba
->pcidev
->dev
)
3048 shost
= scsi_host_alloc(&lpfc_vport_template
,
3049 sizeof(struct lpfc_vport
));
3051 shost
= scsi_host_alloc(&lpfc_template
,
3052 sizeof(struct lpfc_vport
));
3056 vport
= (struct lpfc_vport
*) shost
->hostdata
;
3058 vport
->load_flag
|= FC_LOADING
;
3059 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
3060 vport
->fc_rscn_flush
= 0;
3062 lpfc_get_vport_cfgparam(vport
);
3063 shost
->unique_id
= instance
;
3064 shost
->max_id
= LPFC_MAX_TARGET
;
3065 shost
->max_lun
= vport
->cfg_max_luns
;
3066 shost
->this_id
= -1;
3067 shost
->max_cmd_len
= 16;
3068 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3069 shost
->dma_boundary
=
3070 phba
->sli4_hba
.pc_sli4_params
.sge_supp_len
-1;
3071 shost
->sg_tablesize
= phba
->cfg_sg_seg_cnt
;
3075 * Set initial can_queue value since 0 is no longer supported and
3076 * scsi_add_host will fail. This will be adjusted later based on the
3077 * max xri value determined in hba setup.
3079 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
3080 if (dev
!= &phba
->pcidev
->dev
) {
3081 shost
->transportt
= lpfc_vport_transport_template
;
3082 vport
->port_type
= LPFC_NPIV_PORT
;
3084 shost
->transportt
= lpfc_transport_template
;
3085 vport
->port_type
= LPFC_PHYSICAL_PORT
;
3088 /* Initialize all internally managed lists. */
3089 INIT_LIST_HEAD(&vport
->fc_nodes
);
3090 INIT_LIST_HEAD(&vport
->rcv_buffer_list
);
3091 spin_lock_init(&vport
->work_port_lock
);
3093 init_timer(&vport
->fc_disctmo
);
3094 vport
->fc_disctmo
.function
= lpfc_disc_timeout
;
3095 vport
->fc_disctmo
.data
= (unsigned long)vport
;
3097 init_timer(&vport
->fc_fdmitmo
);
3098 vport
->fc_fdmitmo
.function
= lpfc_fdmi_tmo
;
3099 vport
->fc_fdmitmo
.data
= (unsigned long)vport
;
3101 init_timer(&vport
->els_tmofunc
);
3102 vport
->els_tmofunc
.function
= lpfc_els_timeout
;
3103 vport
->els_tmofunc
.data
= (unsigned long)vport
;
3105 init_timer(&vport
->delayed_disc_tmo
);
3106 vport
->delayed_disc_tmo
.function
= lpfc_delayed_disc_tmo
;
3107 vport
->delayed_disc_tmo
.data
= (unsigned long)vport
;
3109 error
= scsi_add_host_with_dma(shost
, dev
, &phba
->pcidev
->dev
);
3113 spin_lock_irq(&phba
->hbalock
);
3114 list_add_tail(&vport
->listentry
, &phba
->port_list
);
3115 spin_unlock_irq(&phba
->hbalock
);
3119 scsi_host_put(shost
);
3125 * destroy_port - destroy an FC port
3126 * @vport: pointer to an lpfc virtual N_Port data structure.
3128 * This routine destroys a FC port from the upper layer protocol. All the
3129 * resources associated with the port are released.
3132 destroy_port(struct lpfc_vport
*vport
)
3134 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3135 struct lpfc_hba
*phba
= vport
->phba
;
3137 lpfc_debugfs_terminate(vport
);
3138 fc_remove_host(shost
);
3139 scsi_remove_host(shost
);
3141 spin_lock_irq(&phba
->hbalock
);
3142 list_del_init(&vport
->listentry
);
3143 spin_unlock_irq(&phba
->hbalock
);
3145 lpfc_cleanup(vport
);
3150 * lpfc_get_instance - Get a unique integer ID
3152 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3153 * uses the kernel idr facility to perform the task.
3156 * instance - a unique integer ID allocated as the new instance.
3157 * -1 - lpfc get instance failed.
3160 lpfc_get_instance(void)
3164 /* Assign an unused number */
3165 if (!idr_pre_get(&lpfc_hba_index
, GFP_KERNEL
))
3167 if (idr_get_new(&lpfc_hba_index
, NULL
, &instance
))
3173 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
3174 * @shost: pointer to SCSI host data structure.
3175 * @time: elapsed time of the scan in jiffies.
3177 * This routine is called by the SCSI layer with a SCSI host to determine
3178 * whether the scan host is finished.
3180 * Note: there is no scan_start function as adapter initialization will have
3181 * asynchronously kicked off the link initialization.
3184 * 0 - SCSI host scan is not over yet.
3185 * 1 - SCSI host scan is over.
3187 int lpfc_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
3189 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3190 struct lpfc_hba
*phba
= vport
->phba
;
3193 spin_lock_irq(shost
->host_lock
);
3195 if (vport
->load_flag
& FC_UNLOADING
) {
3199 if (time
>= 30 * HZ
) {
3200 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3201 "0461 Scanning longer than 30 "
3202 "seconds. Continuing initialization\n");
3206 if (time
>= 15 * HZ
&& phba
->link_state
<= LPFC_LINK_DOWN
) {
3207 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3208 "0465 Link down longer than 15 "
3209 "seconds. Continuing initialization\n");
3214 if (vport
->port_state
!= LPFC_VPORT_READY
)
3216 if (vport
->num_disc_nodes
|| vport
->fc_prli_sent
)
3218 if (vport
->fc_map_cnt
== 0 && time
< 2 * HZ
)
3220 if ((phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) != 0)
3226 spin_unlock_irq(shost
->host_lock
);
3231 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
3232 * @shost: pointer to SCSI host data structure.
3234 * This routine initializes a given SCSI host attributes on a FC port. The
3235 * SCSI host can be either on top of a physical port or a virtual port.
3237 void lpfc_host_attrib_init(struct Scsi_Host
*shost
)
3239 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3240 struct lpfc_hba
*phba
= vport
->phba
;
3242 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
3245 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
3246 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
3247 fc_host_supported_classes(shost
) = FC_COS_CLASS3
;
3249 memset(fc_host_supported_fc4s(shost
), 0,
3250 sizeof(fc_host_supported_fc4s(shost
)));
3251 fc_host_supported_fc4s(shost
)[2] = 1;
3252 fc_host_supported_fc4s(shost
)[7] = 1;
3254 lpfc_vport_symbolic_node_name(vport
, fc_host_symbolic_name(shost
),
3255 sizeof fc_host_symbolic_name(shost
));
3257 fc_host_supported_speeds(shost
) = 0;
3258 if (phba
->lmt
& LMT_16Gb
)
3259 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_16GBIT
;
3260 if (phba
->lmt
& LMT_10Gb
)
3261 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_10GBIT
;
3262 if (phba
->lmt
& LMT_8Gb
)
3263 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_8GBIT
;
3264 if (phba
->lmt
& LMT_4Gb
)
3265 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_4GBIT
;
3266 if (phba
->lmt
& LMT_2Gb
)
3267 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_2GBIT
;
3268 if (phba
->lmt
& LMT_1Gb
)
3269 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_1GBIT
;
3271 fc_host_maxframe_size(shost
) =
3272 (((uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
3273 (uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeLsb
;
3275 fc_host_dev_loss_tmo(shost
) = vport
->cfg_devloss_tmo
;
3277 /* This value is also unchanging */
3278 memset(fc_host_active_fc4s(shost
), 0,
3279 sizeof(fc_host_active_fc4s(shost
)));
3280 fc_host_active_fc4s(shost
)[2] = 1;
3281 fc_host_active_fc4s(shost
)[7] = 1;
3283 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
3284 spin_lock_irq(shost
->host_lock
);
3285 vport
->load_flag
&= ~FC_LOADING
;
3286 spin_unlock_irq(shost
->host_lock
);
3290 * lpfc_stop_port_s3 - Stop SLI3 device port
3291 * @phba: pointer to lpfc hba data structure.
3293 * This routine is invoked to stop an SLI3 device port, it stops the device
3294 * from generating interrupts and stops the device driver's timers for the
3298 lpfc_stop_port_s3(struct lpfc_hba
*phba
)
3300 /* Clear all interrupt enable conditions */
3301 writel(0, phba
->HCregaddr
);
3302 readl(phba
->HCregaddr
); /* flush */
3303 /* Clear all pending interrupts */
3304 writel(0xffffffff, phba
->HAregaddr
);
3305 readl(phba
->HAregaddr
); /* flush */
3307 /* Reset some HBA SLI setup states */
3308 lpfc_stop_hba_timers(phba
);
3309 phba
->pport
->work_port_events
= 0;
3313 * lpfc_stop_port_s4 - Stop SLI4 device port
3314 * @phba: pointer to lpfc hba data structure.
3316 * This routine is invoked to stop an SLI4 device port, it stops the device
3317 * from generating interrupts and stops the device driver's timers for the
3321 lpfc_stop_port_s4(struct lpfc_hba
*phba
)
3323 /* Reset some HBA SLI4 setup states */
3324 lpfc_stop_hba_timers(phba
);
3325 phba
->pport
->work_port_events
= 0;
3326 phba
->sli4_hba
.intr_enable
= 0;
3330 * lpfc_stop_port - Wrapper function for stopping hba port
3331 * @phba: Pointer to HBA context object.
3333 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3334 * the API jump table function pointer from the lpfc_hba struct.
3337 lpfc_stop_port(struct lpfc_hba
*phba
)
3339 phba
->lpfc_stop_port(phba
);
3343 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3344 * @phba: Pointer to hba for which this call is being executed.
3346 * This routine starts the timer waiting for the FCF rediscovery to complete.
3349 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba
*phba
)
3351 unsigned long fcf_redisc_wait_tmo
=
3352 (jiffies
+ msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO
));
3353 /* Start fcf rediscovery wait period timer */
3354 mod_timer(&phba
->fcf
.redisc_wait
, fcf_redisc_wait_tmo
);
3355 spin_lock_irq(&phba
->hbalock
);
3356 /* Allow action to new fcf asynchronous event */
3357 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
3358 /* Mark the FCF rediscovery pending state */
3359 phba
->fcf
.fcf_flag
|= FCF_REDISC_PEND
;
3360 spin_unlock_irq(&phba
->hbalock
);
3364 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3365 * @ptr: Map to lpfc_hba data structure pointer.
3367 * This routine is invoked when waiting for FCF table rediscover has been
3368 * timed out. If new FCF record(s) has (have) been discovered during the
3369 * wait period, a new FCF event shall be added to the FCOE async event
3370 * list, and then worker thread shall be waked up for processing from the
3371 * worker thread context.
3374 lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr
)
3376 struct lpfc_hba
*phba
= (struct lpfc_hba
*)ptr
;
3378 /* Don't send FCF rediscovery event if timer cancelled */
3379 spin_lock_irq(&phba
->hbalock
);
3380 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
3381 spin_unlock_irq(&phba
->hbalock
);
3384 /* Clear FCF rediscovery timer pending flag */
3385 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_PEND
;
3386 /* FCF rediscovery event to worker thread */
3387 phba
->fcf
.fcf_flag
|= FCF_REDISC_EVT
;
3388 spin_unlock_irq(&phba
->hbalock
);
3389 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
3390 "2776 FCF rediscover quiescent timer expired\n");
3391 /* wake up worker thread */
3392 lpfc_worker_wake_up(phba
);
3396 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3397 * @phba: pointer to lpfc hba data structure.
3398 * @acqe_link: pointer to the async link completion queue entry.
3400 * This routine is to parse the SLI4 link-attention link fault code and
3401 * translate it into the base driver's read link attention mailbox command
3404 * Return: Link-attention status in terms of base driver's coding.
3407 lpfc_sli4_parse_latt_fault(struct lpfc_hba
*phba
,
3408 struct lpfc_acqe_link
*acqe_link
)
3410 uint16_t latt_fault
;
3412 switch (bf_get(lpfc_acqe_link_fault
, acqe_link
)) {
3413 case LPFC_ASYNC_LINK_FAULT_NONE
:
3414 case LPFC_ASYNC_LINK_FAULT_LOCAL
:
3415 case LPFC_ASYNC_LINK_FAULT_REMOTE
:
3419 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3420 "0398 Invalid link fault code: x%x\n",
3421 bf_get(lpfc_acqe_link_fault
, acqe_link
));
3422 latt_fault
= MBXERR_ERROR
;
3429 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3430 * @phba: pointer to lpfc hba data structure.
3431 * @acqe_link: pointer to the async link completion queue entry.
3433 * This routine is to parse the SLI4 link attention type and translate it
3434 * into the base driver's link attention type coding.
3436 * Return: Link attention type in terms of base driver's coding.
3439 lpfc_sli4_parse_latt_type(struct lpfc_hba
*phba
,
3440 struct lpfc_acqe_link
*acqe_link
)
3444 switch (bf_get(lpfc_acqe_link_status
, acqe_link
)) {
3445 case LPFC_ASYNC_LINK_STATUS_DOWN
:
3446 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN
:
3447 att_type
= LPFC_ATT_LINK_DOWN
;
3449 case LPFC_ASYNC_LINK_STATUS_UP
:
3450 /* Ignore physical link up events - wait for logical link up */
3451 att_type
= LPFC_ATT_RESERVED
;
3453 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP
:
3454 att_type
= LPFC_ATT_LINK_UP
;
3457 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3458 "0399 Invalid link attention type: x%x\n",
3459 bf_get(lpfc_acqe_link_status
, acqe_link
));
3460 att_type
= LPFC_ATT_RESERVED
;
3467 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
3468 * @phba: pointer to lpfc hba data structure.
3469 * @acqe_link: pointer to the async link completion queue entry.
3471 * This routine is to parse the SLI4 link-attention link speed and translate
3472 * it into the base driver's link-attention link speed coding.
3474 * Return: Link-attention link speed in terms of base driver's coding.
3477 lpfc_sli4_parse_latt_link_speed(struct lpfc_hba
*phba
,
3478 struct lpfc_acqe_link
*acqe_link
)
3482 switch (bf_get(lpfc_acqe_link_speed
, acqe_link
)) {
3483 case LPFC_ASYNC_LINK_SPEED_ZERO
:
3484 case LPFC_ASYNC_LINK_SPEED_10MBPS
:
3485 case LPFC_ASYNC_LINK_SPEED_100MBPS
:
3486 link_speed
= LPFC_LINK_SPEED_UNKNOWN
;
3488 case LPFC_ASYNC_LINK_SPEED_1GBPS
:
3489 link_speed
= LPFC_LINK_SPEED_1GHZ
;
3491 case LPFC_ASYNC_LINK_SPEED_10GBPS
:
3492 link_speed
= LPFC_LINK_SPEED_10GHZ
;
3495 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3496 "0483 Invalid link-attention link speed: x%x\n",
3497 bf_get(lpfc_acqe_link_speed
, acqe_link
));
3498 link_speed
= LPFC_LINK_SPEED_UNKNOWN
;
3505 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
3506 * @phba: pointer to lpfc hba data structure.
3507 * @acqe_link: pointer to the async link completion queue entry.
3509 * This routine is to handle the SLI4 asynchronous FCoE link event.
3512 lpfc_sli4_async_link_evt(struct lpfc_hba
*phba
,
3513 struct lpfc_acqe_link
*acqe_link
)
3515 struct lpfc_dmabuf
*mp
;
3518 struct lpfc_mbx_read_top
*la
;
3522 att_type
= lpfc_sli4_parse_latt_type(phba
, acqe_link
);
3523 if (att_type
!= LPFC_ATT_LINK_DOWN
&& att_type
!= LPFC_ATT_LINK_UP
)
3525 phba
->fcoe_eventtag
= acqe_link
->event_tag
;
3526 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3528 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3529 "0395 The mboxq allocation failed\n");
3532 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
3534 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3535 "0396 The lpfc_dmabuf allocation failed\n");
3538 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
3540 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3541 "0397 The mbuf allocation failed\n");
3542 goto out_free_dmabuf
;
3545 /* Cleanup any outstanding ELS commands */
3546 lpfc_els_flush_all_cmd(phba
);
3548 /* Block ELS IOCBs until we have done process link event */
3549 phba
->sli
.ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
3551 /* Update link event statistics */
3552 phba
->sli
.slistat
.link_event
++;
3554 /* Create lpfc_handle_latt mailbox command from link ACQE */
3555 lpfc_read_topology(phba
, pmb
, mp
);
3556 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
3557 pmb
->vport
= phba
->pport
;
3559 /* Keep the link status for extra SLI4 state machine reference */
3560 phba
->sli4_hba
.link_state
.speed
=
3561 bf_get(lpfc_acqe_link_speed
, acqe_link
);
3562 phba
->sli4_hba
.link_state
.duplex
=
3563 bf_get(lpfc_acqe_link_duplex
, acqe_link
);
3564 phba
->sli4_hba
.link_state
.status
=
3565 bf_get(lpfc_acqe_link_status
, acqe_link
);
3566 phba
->sli4_hba
.link_state
.type
=
3567 bf_get(lpfc_acqe_link_type
, acqe_link
);
3568 phba
->sli4_hba
.link_state
.number
=
3569 bf_get(lpfc_acqe_link_number
, acqe_link
);
3570 phba
->sli4_hba
.link_state
.fault
=
3571 bf_get(lpfc_acqe_link_fault
, acqe_link
);
3572 phba
->sli4_hba
.link_state
.logical_speed
=
3573 bf_get(lpfc_acqe_logical_link_speed
, acqe_link
);
3574 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3575 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3576 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3577 "Logical speed:%dMbps Fault:%d\n",
3578 phba
->sli4_hba
.link_state
.speed
,
3579 phba
->sli4_hba
.link_state
.topology
,
3580 phba
->sli4_hba
.link_state
.status
,
3581 phba
->sli4_hba
.link_state
.type
,
3582 phba
->sli4_hba
.link_state
.number
,
3583 phba
->sli4_hba
.link_state
.logical_speed
* 10,
3584 phba
->sli4_hba
.link_state
.fault
);
3586 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3587 * topology info. Note: Optional for non FC-AL ports.
3589 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
3590 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3591 if (rc
== MBX_NOT_FINISHED
)
3592 goto out_free_dmabuf
;
3596 * For FCoE Mode: fill in all the topology information we need and call
3597 * the READ_TOPOLOGY completion routine to continue without actually
3598 * sending the READ_TOPOLOGY mailbox command to the port.
3600 /* Parse and translate status field */
3602 mb
->mbxStatus
= lpfc_sli4_parse_latt_fault(phba
, acqe_link
);
3604 /* Parse and translate link attention fields */
3605 la
= (struct lpfc_mbx_read_top
*) &pmb
->u
.mb
.un
.varReadTop
;
3606 la
->eventTag
= acqe_link
->event_tag
;
3607 bf_set(lpfc_mbx_read_top_att_type
, la
, att_type
);
3608 bf_set(lpfc_mbx_read_top_link_spd
, la
,
3609 lpfc_sli4_parse_latt_link_speed(phba
, acqe_link
));
3611 /* Fake the the following irrelvant fields */
3612 bf_set(lpfc_mbx_read_top_topology
, la
, LPFC_TOPOLOGY_PT_PT
);
3613 bf_set(lpfc_mbx_read_top_alpa_granted
, la
, 0);
3614 bf_set(lpfc_mbx_read_top_il
, la
, 0);
3615 bf_set(lpfc_mbx_read_top_pb
, la
, 0);
3616 bf_set(lpfc_mbx_read_top_fa
, la
, 0);
3617 bf_set(lpfc_mbx_read_top_mm
, la
, 0);
3619 /* Invoke the lpfc_handle_latt mailbox command callback function */
3620 lpfc_mbx_cmpl_read_topology(phba
, pmb
);
3627 mempool_free(pmb
, phba
->mbox_mem_pool
);
3631 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
3632 * @phba: pointer to lpfc hba data structure.
3633 * @acqe_fc: pointer to the async fc completion queue entry.
3635 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
3636 * that the event was received and then issue a read_topology mailbox command so
3637 * that the rest of the driver will treat it the same as SLI3.
3640 lpfc_sli4_async_fc_evt(struct lpfc_hba
*phba
, struct lpfc_acqe_fc_la
*acqe_fc
)
3642 struct lpfc_dmabuf
*mp
;
3646 if (bf_get(lpfc_trailer_type
, acqe_fc
) !=
3647 LPFC_FC_LA_EVENT_TYPE_FC_LINK
) {
3648 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3649 "2895 Non FC link Event detected.(%d)\n",
3650 bf_get(lpfc_trailer_type
, acqe_fc
));
3653 /* Keep the link status for extra SLI4 state machine reference */
3654 phba
->sli4_hba
.link_state
.speed
=
3655 bf_get(lpfc_acqe_fc_la_speed
, acqe_fc
);
3656 phba
->sli4_hba
.link_state
.duplex
= LPFC_ASYNC_LINK_DUPLEX_FULL
;
3657 phba
->sli4_hba
.link_state
.topology
=
3658 bf_get(lpfc_acqe_fc_la_topology
, acqe_fc
);
3659 phba
->sli4_hba
.link_state
.status
=
3660 bf_get(lpfc_acqe_fc_la_att_type
, acqe_fc
);
3661 phba
->sli4_hba
.link_state
.type
=
3662 bf_get(lpfc_acqe_fc_la_port_type
, acqe_fc
);
3663 phba
->sli4_hba
.link_state
.number
=
3664 bf_get(lpfc_acqe_fc_la_port_number
, acqe_fc
);
3665 phba
->sli4_hba
.link_state
.fault
=
3666 bf_get(lpfc_acqe_link_fault
, acqe_fc
);
3667 phba
->sli4_hba
.link_state
.logical_speed
=
3668 bf_get(lpfc_acqe_fc_la_llink_spd
, acqe_fc
);
3669 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3670 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
3671 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
3672 "%dMbps Fault:%d\n",
3673 phba
->sli4_hba
.link_state
.speed
,
3674 phba
->sli4_hba
.link_state
.topology
,
3675 phba
->sli4_hba
.link_state
.status
,
3676 phba
->sli4_hba
.link_state
.type
,
3677 phba
->sli4_hba
.link_state
.number
,
3678 phba
->sli4_hba
.link_state
.logical_speed
* 10,
3679 phba
->sli4_hba
.link_state
.fault
);
3680 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3682 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3683 "2897 The mboxq allocation failed\n");
3686 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
3688 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3689 "2898 The lpfc_dmabuf allocation failed\n");
3692 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
3694 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3695 "2899 The mbuf allocation failed\n");
3696 goto out_free_dmabuf
;
3699 /* Cleanup any outstanding ELS commands */
3700 lpfc_els_flush_all_cmd(phba
);
3702 /* Block ELS IOCBs until we have done process link event */
3703 phba
->sli
.ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
3705 /* Update link event statistics */
3706 phba
->sli
.slistat
.link_event
++;
3708 /* Create lpfc_handle_latt mailbox command from link ACQE */
3709 lpfc_read_topology(phba
, pmb
, mp
);
3710 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
3711 pmb
->vport
= phba
->pport
;
3713 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3714 if (rc
== MBX_NOT_FINISHED
)
3715 goto out_free_dmabuf
;
3721 mempool_free(pmb
, phba
->mbox_mem_pool
);
3725 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
3726 * @phba: pointer to lpfc hba data structure.
3727 * @acqe_fc: pointer to the async SLI completion queue entry.
3729 * This routine is to handle the SLI4 asynchronous SLI events.
3732 lpfc_sli4_async_sli_evt(struct lpfc_hba
*phba
, struct lpfc_acqe_sli
*acqe_sli
)
3737 struct lpfc_acqe_misconfigured_event
*misconfigured
;
3739 /* special case misconfigured event as it contains data for all ports */
3740 if ((bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
3741 LPFC_SLI_INTF_IF_TYPE_2
) ||
3742 (bf_get(lpfc_trailer_type
, acqe_sli
) !=
3743 LPFC_SLI_EVENT_TYPE_MISCONFIGURED
)) {
3744 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3745 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
3746 "x%08x SLI Event Type:%d\n",
3747 acqe_sli
->event_data1
, acqe_sli
->event_data2
,
3748 bf_get(lpfc_trailer_type
, acqe_sli
));
3752 port_name
= phba
->Port
[0];
3753 if (port_name
== 0x00)
3754 port_name
= '?'; /* get port name is empty */
3756 misconfigured
= (struct lpfc_acqe_misconfigured_event
*)
3757 &acqe_sli
->event_data1
;
3759 /* fetch the status for this port */
3760 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
3761 case LPFC_LINK_NUMBER_0
:
3762 status
= bf_get(lpfc_sli_misconfigured_port0
,
3763 &misconfigured
->theEvent
);
3765 case LPFC_LINK_NUMBER_1
:
3766 status
= bf_get(lpfc_sli_misconfigured_port1
,
3767 &misconfigured
->theEvent
);
3769 case LPFC_LINK_NUMBER_2
:
3770 status
= bf_get(lpfc_sli_misconfigured_port2
,
3771 &misconfigured
->theEvent
);
3773 case LPFC_LINK_NUMBER_3
:
3774 status
= bf_get(lpfc_sli_misconfigured_port3
,
3775 &misconfigured
->theEvent
);
3778 status
= ~LPFC_SLI_EVENT_STATUS_VALID
;
3783 case LPFC_SLI_EVENT_STATUS_VALID
:
3784 return; /* no message if the sfp is okay */
3785 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT
:
3786 sprintf(message
, "Not installed");
3788 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE
:
3790 "Optics of two types installed");
3792 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED
:
3793 sprintf(message
, "Incompatible optics");
3796 /* firmware is reporting a status we don't know about */
3797 sprintf(message
, "Unknown event status x%02x", status
);
3801 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3802 "3176 Misconfigured Physical Port - "
3803 "Port Name %c %s\n", port_name
, message
);
3807 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
3808 * @vport: pointer to vport data structure.
3810 * This routine is to perform Clear Virtual Link (CVL) on a vport in
3811 * response to a CVL event.
3813 * Return the pointer to the ndlp with the vport if successful, otherwise
3816 static struct lpfc_nodelist
*
3817 lpfc_sli4_perform_vport_cvl(struct lpfc_vport
*vport
)
3819 struct lpfc_nodelist
*ndlp
;
3820 struct Scsi_Host
*shost
;
3821 struct lpfc_hba
*phba
;
3828 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
3830 /* Cannot find existing Fabric ndlp, so allocate a new one */
3831 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
3834 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
3835 /* Set the node type */
3836 ndlp
->nlp_type
|= NLP_FABRIC
;
3837 /* Put ndlp onto node list */
3838 lpfc_enqueue_node(vport
, ndlp
);
3839 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
3840 /* re-setup ndlp without removing from node list */
3841 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
3845 if ((phba
->pport
->port_state
< LPFC_FLOGI
) &&
3846 (phba
->pport
->port_state
!= LPFC_VPORT_FAILED
))
3848 /* If virtual link is not yet instantiated ignore CVL */
3849 if ((vport
!= phba
->pport
) && (vport
->port_state
< LPFC_FDISC
)
3850 && (vport
->port_state
!= LPFC_VPORT_FAILED
))
3852 shost
= lpfc_shost_from_vport(vport
);
3855 lpfc_linkdown_port(vport
);
3856 lpfc_cleanup_pending_mbox(vport
);
3857 spin_lock_irq(shost
->host_lock
);
3858 vport
->fc_flag
|= FC_VPORT_CVL_RCVD
;
3859 spin_unlock_irq(shost
->host_lock
);
3865 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
3866 * @vport: pointer to lpfc hba data structure.
3868 * This routine is to perform Clear Virtual Link (CVL) on all vports in
3869 * response to a FCF dead event.
3872 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba
*phba
)
3874 struct lpfc_vport
**vports
;
3877 vports
= lpfc_create_vport_work_array(phba
);
3879 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
3880 lpfc_sli4_perform_vport_cvl(vports
[i
]);
3881 lpfc_destroy_vport_work_array(phba
, vports
);
3885 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
3886 * @phba: pointer to lpfc hba data structure.
3887 * @acqe_link: pointer to the async fcoe completion queue entry.
3889 * This routine is to handle the SLI4 asynchronous fcoe event.
3892 lpfc_sli4_async_fip_evt(struct lpfc_hba
*phba
,
3893 struct lpfc_acqe_fip
*acqe_fip
)
3895 uint8_t event_type
= bf_get(lpfc_trailer_type
, acqe_fip
);
3897 struct lpfc_vport
*vport
;
3898 struct lpfc_nodelist
*ndlp
;
3899 struct Scsi_Host
*shost
;
3900 int active_vlink_present
;
3901 struct lpfc_vport
**vports
;
3904 phba
->fc_eventTag
= acqe_fip
->event_tag
;
3905 phba
->fcoe_eventtag
= acqe_fip
->event_tag
;
3906 switch (event_type
) {
3907 case LPFC_FIP_EVENT_TYPE_NEW_FCF
:
3908 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD
:
3909 if (event_type
== LPFC_FIP_EVENT_TYPE_NEW_FCF
)
3910 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
3912 "2546 New FCF event, evt_tag:x%x, "
3914 acqe_fip
->event_tag
,
3917 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
|
3919 "2788 FCF param modified event, "
3920 "evt_tag:x%x, index:x%x\n",
3921 acqe_fip
->event_tag
,
3923 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
3925 * During period of FCF discovery, read the FCF
3926 * table record indexed by the event to update
3927 * FCF roundrobin failover eligible FCF bmask.
3929 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
3931 "2779 Read FCF (x%x) for updating "
3932 "roundrobin FCF failover bmask\n",
3934 rc
= lpfc_sli4_read_fcf_rec(phba
, acqe_fip
->index
);
3937 /* If the FCF discovery is in progress, do nothing. */
3938 spin_lock_irq(&phba
->hbalock
);
3939 if (phba
->hba_flag
& FCF_TS_INPROG
) {
3940 spin_unlock_irq(&phba
->hbalock
);
3943 /* If fast FCF failover rescan event is pending, do nothing */
3944 if (phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
) {
3945 spin_unlock_irq(&phba
->hbalock
);
3949 /* If the FCF has been in discovered state, do nothing. */
3950 if (phba
->fcf
.fcf_flag
& FCF_SCAN_DONE
) {
3951 spin_unlock_irq(&phba
->hbalock
);
3954 spin_unlock_irq(&phba
->hbalock
);
3956 /* Otherwise, scan the entire FCF table and re-discover SAN */
3957 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
3958 "2770 Start FCF table scan per async FCF "
3959 "event, evt_tag:x%x, index:x%x\n",
3960 acqe_fip
->event_tag
, acqe_fip
->index
);
3961 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
3962 LPFC_FCOE_FCF_GET_FIRST
);
3964 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
3965 "2547 Issue FCF scan read FCF mailbox "
3966 "command failed (x%x)\n", rc
);
3969 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL
:
3970 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3971 "2548 FCF Table full count 0x%x tag 0x%x\n",
3972 bf_get(lpfc_acqe_fip_fcf_count
, acqe_fip
),
3973 acqe_fip
->event_tag
);
3976 case LPFC_FIP_EVENT_TYPE_FCF_DEAD
:
3977 phba
->fcoe_cvl_eventtag
= acqe_fip
->event_tag
;
3978 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
3979 "2549 FCF (x%x) disconnected from network, "
3980 "tag:x%x\n", acqe_fip
->index
, acqe_fip
->event_tag
);
3982 * If we are in the middle of FCF failover process, clear
3983 * the corresponding FCF bit in the roundrobin bitmap.
3985 spin_lock_irq(&phba
->hbalock
);
3986 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
3987 spin_unlock_irq(&phba
->hbalock
);
3988 /* Update FLOGI FCF failover eligible FCF bmask */
3989 lpfc_sli4_fcf_rr_index_clear(phba
, acqe_fip
->index
);
3992 spin_unlock_irq(&phba
->hbalock
);
3994 /* If the event is not for currently used fcf do nothing */
3995 if (phba
->fcf
.current_rec
.fcf_indx
!= acqe_fip
->index
)
3999 * Otherwise, request the port to rediscover the entire FCF
4000 * table for a fast recovery from case that the current FCF
4001 * is no longer valid as we are not in the middle of FCF
4002 * failover process already.
4004 spin_lock_irq(&phba
->hbalock
);
4005 /* Mark the fast failover process in progress */
4006 phba
->fcf
.fcf_flag
|= FCF_DEAD_DISC
;
4007 spin_unlock_irq(&phba
->hbalock
);
4009 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
4010 "2771 Start FCF fast failover process due to "
4011 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4012 "\n", acqe_fip
->event_tag
, acqe_fip
->index
);
4013 rc
= lpfc_sli4_redisc_fcf_table(phba
);
4015 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
4017 "2772 Issue FCF rediscover mabilbox "
4018 "command failed, fail through to FCF "
4020 spin_lock_irq(&phba
->hbalock
);
4021 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
4022 spin_unlock_irq(&phba
->hbalock
);
4024 * Last resort will fail over by treating this
4025 * as a link down to FCF registration.
4027 lpfc_sli4_fcf_dead_failthrough(phba
);
4029 /* Reset FCF roundrobin bmask for new discovery */
4030 lpfc_sli4_clear_fcf_rr_bmask(phba
);
4032 * Handling fast FCF failover to a DEAD FCF event is
4033 * considered equalivant to receiving CVL to all vports.
4035 lpfc_sli4_perform_all_vport_cvl(phba
);
4038 case LPFC_FIP_EVENT_TYPE_CVL
:
4039 phba
->fcoe_cvl_eventtag
= acqe_fip
->event_tag
;
4040 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4041 "2718 Clear Virtual Link Received for VPI 0x%x"
4042 " tag 0x%x\n", acqe_fip
->index
, acqe_fip
->event_tag
);
4044 vport
= lpfc_find_vport_by_vpid(phba
,
4046 ndlp
= lpfc_sli4_perform_vport_cvl(vport
);
4049 active_vlink_present
= 0;
4051 vports
= lpfc_create_vport_work_array(phba
);
4053 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
4055 if ((!(vports
[i
]->fc_flag
&
4056 FC_VPORT_CVL_RCVD
)) &&
4057 (vports
[i
]->port_state
> LPFC_FDISC
)) {
4058 active_vlink_present
= 1;
4062 lpfc_destroy_vport_work_array(phba
, vports
);
4065 if (active_vlink_present
) {
4067 * If there are other active VLinks present,
4068 * re-instantiate the Vlink using FDISC.
4070 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ HZ
);
4071 shost
= lpfc_shost_from_vport(vport
);
4072 spin_lock_irq(shost
->host_lock
);
4073 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
4074 spin_unlock_irq(shost
->host_lock
);
4075 ndlp
->nlp_last_elscmd
= ELS_CMD_FDISC
;
4076 vport
->port_state
= LPFC_FDISC
;
4079 * Otherwise, we request port to rediscover
4080 * the entire FCF table for a fast recovery
4081 * from possible case that the current FCF
4082 * is no longer valid if we are not already
4083 * in the FCF failover process.
4085 spin_lock_irq(&phba
->hbalock
);
4086 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
4087 spin_unlock_irq(&phba
->hbalock
);
4090 /* Mark the fast failover process in progress */
4091 phba
->fcf
.fcf_flag
|= FCF_ACVL_DISC
;
4092 spin_unlock_irq(&phba
->hbalock
);
4093 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
4095 "2773 Start FCF failover per CVL, "
4096 "evt_tag:x%x\n", acqe_fip
->event_tag
);
4097 rc
= lpfc_sli4_redisc_fcf_table(phba
);
4099 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
4101 "2774 Issue FCF rediscover "
4102 "mabilbox command failed, "
4103 "through to CVL event\n");
4104 spin_lock_irq(&phba
->hbalock
);
4105 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
4106 spin_unlock_irq(&phba
->hbalock
);
4108 * Last resort will be re-try on the
4109 * the current registered FCF entry.
4111 lpfc_retry_pport_discovery(phba
);
4114 * Reset FCF roundrobin bmask for new
4117 lpfc_sli4_clear_fcf_rr_bmask(phba
);
4121 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4122 "0288 Unknown FCoE event type 0x%x event tag "
4123 "0x%x\n", event_type
, acqe_fip
->event_tag
);
4129 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4130 * @phba: pointer to lpfc hba data structure.
4131 * @acqe_link: pointer to the async dcbx completion queue entry.
4133 * This routine is to handle the SLI4 asynchronous dcbx event.
4136 lpfc_sli4_async_dcbx_evt(struct lpfc_hba
*phba
,
4137 struct lpfc_acqe_dcbx
*acqe_dcbx
)
4139 phba
->fc_eventTag
= acqe_dcbx
->event_tag
;
4140 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4141 "0290 The SLI4 DCBX asynchronous event is not "
4146 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4147 * @phba: pointer to lpfc hba data structure.
4148 * @acqe_link: pointer to the async grp5 completion queue entry.
4150 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4151 * is an asynchronous notified of a logical link speed change. The Port
4152 * reports the logical link speed in units of 10Mbps.
4155 lpfc_sli4_async_grp5_evt(struct lpfc_hba
*phba
,
4156 struct lpfc_acqe_grp5
*acqe_grp5
)
4158 uint16_t prev_ll_spd
;
4160 phba
->fc_eventTag
= acqe_grp5
->event_tag
;
4161 phba
->fcoe_eventtag
= acqe_grp5
->event_tag
;
4162 prev_ll_spd
= phba
->sli4_hba
.link_state
.logical_speed
;
4163 phba
->sli4_hba
.link_state
.logical_speed
=
4164 (bf_get(lpfc_acqe_grp5_llink_spd
, acqe_grp5
));
4165 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4166 "2789 GRP5 Async Event: Updating logical link speed "
4167 "from %dMbps to %dMbps\n", (prev_ll_spd
* 10),
4168 (phba
->sli4_hba
.link_state
.logical_speed
*10));
4172 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4173 * @phba: pointer to lpfc hba data structure.
4175 * This routine is invoked by the worker thread to process all the pending
4176 * SLI4 asynchronous events.
4178 void lpfc_sli4_async_event_proc(struct lpfc_hba
*phba
)
4180 struct lpfc_cq_event
*cq_event
;
4182 /* First, declare the async event has been handled */
4183 spin_lock_irq(&phba
->hbalock
);
4184 phba
->hba_flag
&= ~ASYNC_EVENT
;
4185 spin_unlock_irq(&phba
->hbalock
);
4186 /* Now, handle all the async events */
4187 while (!list_empty(&phba
->sli4_hba
.sp_asynce_work_queue
)) {
4188 /* Get the first event from the head of the event queue */
4189 spin_lock_irq(&phba
->hbalock
);
4190 list_remove_head(&phba
->sli4_hba
.sp_asynce_work_queue
,
4191 cq_event
, struct lpfc_cq_event
, list
);
4192 spin_unlock_irq(&phba
->hbalock
);
4193 /* Process the asynchronous event */
4194 switch (bf_get(lpfc_trailer_code
, &cq_event
->cqe
.mcqe_cmpl
)) {
4195 case LPFC_TRAILER_CODE_LINK
:
4196 lpfc_sli4_async_link_evt(phba
,
4197 &cq_event
->cqe
.acqe_link
);
4199 case LPFC_TRAILER_CODE_FCOE
:
4200 lpfc_sli4_async_fip_evt(phba
, &cq_event
->cqe
.acqe_fip
);
4202 case LPFC_TRAILER_CODE_DCBX
:
4203 lpfc_sli4_async_dcbx_evt(phba
,
4204 &cq_event
->cqe
.acqe_dcbx
);
4206 case LPFC_TRAILER_CODE_GRP5
:
4207 lpfc_sli4_async_grp5_evt(phba
,
4208 &cq_event
->cqe
.acqe_grp5
);
4210 case LPFC_TRAILER_CODE_FC
:
4211 lpfc_sli4_async_fc_evt(phba
, &cq_event
->cqe
.acqe_fc
);
4213 case LPFC_TRAILER_CODE_SLI
:
4214 lpfc_sli4_async_sli_evt(phba
, &cq_event
->cqe
.acqe_sli
);
4217 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4218 "1804 Invalid asynchrous event code: "
4219 "x%x\n", bf_get(lpfc_trailer_code
,
4220 &cq_event
->cqe
.mcqe_cmpl
));
4223 /* Free the completion event processed to the free pool */
4224 lpfc_sli4_cq_event_release(phba
, cq_event
);
4229 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4230 * @phba: pointer to lpfc hba data structure.
4232 * This routine is invoked by the worker thread to process FCF table
4233 * rediscovery pending completion event.
4235 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba
*phba
)
4239 spin_lock_irq(&phba
->hbalock
);
4240 /* Clear FCF rediscovery timeout event */
4241 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_EVT
;
4242 /* Clear driver fast failover FCF record flag */
4243 phba
->fcf
.failover_rec
.flag
= 0;
4244 /* Set state for FCF fast failover */
4245 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
4246 spin_unlock_irq(&phba
->hbalock
);
4248 /* Scan FCF table from the first entry to re-discover SAN */
4249 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
4250 "2777 Start post-quiescent FCF table scan\n");
4251 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
4253 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4254 "2747 Issue FCF scan read FCF mailbox "
4255 "command failed 0x%x\n", rc
);
4259 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4260 * @phba: pointer to lpfc hba data structure.
4261 * @dev_grp: The HBA PCI-Device group number.
4263 * This routine is invoked to set up the per HBA PCI-Device group function
4264 * API jump table entries.
4266 * Return: 0 if success, otherwise -ENODEV
4269 lpfc_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
4273 /* Set up lpfc PCI-device group */
4274 phba
->pci_dev_grp
= dev_grp
;
4276 /* The LPFC_PCI_DEV_OC uses SLI4 */
4277 if (dev_grp
== LPFC_PCI_DEV_OC
)
4278 phba
->sli_rev
= LPFC_SLI_REV4
;
4280 /* Set up device INIT API function jump table */
4281 rc
= lpfc_init_api_table_setup(phba
, dev_grp
);
4284 /* Set up SCSI API function jump table */
4285 rc
= lpfc_scsi_api_table_setup(phba
, dev_grp
);
4288 /* Set up SLI API function jump table */
4289 rc
= lpfc_sli_api_table_setup(phba
, dev_grp
);
4292 /* Set up MBOX API function jump table */
4293 rc
= lpfc_mbox_api_table_setup(phba
, dev_grp
);
4301 * lpfc_log_intr_mode - Log the active interrupt mode
4302 * @phba: pointer to lpfc hba data structure.
4303 * @intr_mode: active interrupt mode adopted.
4305 * This routine it invoked to log the currently used active interrupt mode
4308 static void lpfc_log_intr_mode(struct lpfc_hba
*phba
, uint32_t intr_mode
)
4310 switch (intr_mode
) {
4312 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4313 "0470 Enable INTx interrupt mode.\n");
4316 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4317 "0481 Enabled MSI interrupt mode.\n");
4320 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4321 "0480 Enabled MSI-X interrupt mode.\n");
4324 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4325 "0482 Illegal interrupt mode.\n");
4332 * lpfc_enable_pci_dev - Enable a generic PCI device.
4333 * @phba: pointer to lpfc hba data structure.
4335 * This routine is invoked to enable the PCI device that is common to all
4340 * other values - error
4343 lpfc_enable_pci_dev(struct lpfc_hba
*phba
)
4345 struct pci_dev
*pdev
;
4348 /* Obtain PCI device reference */
4352 pdev
= phba
->pcidev
;
4353 /* Select PCI BARs */
4354 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
4355 /* Enable PCI device */
4356 if (pci_enable_device_mem(pdev
))
4358 /* Request PCI resource for the device */
4359 if (pci_request_selected_regions(pdev
, bars
, LPFC_DRIVER_NAME
))
4360 goto out_disable_device
;
4361 /* Set up device as PCI master and save state for EEH */
4362 pci_set_master(pdev
);
4363 pci_try_set_mwi(pdev
);
4364 pci_save_state(pdev
);
4366 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
4367 if (pci_find_capability(pdev
, PCI_CAP_ID_EXP
))
4368 pdev
->needs_freset
= 1;
4373 pci_disable_device(pdev
);
4375 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4376 "1401 Failed to enable pci device, bars:x%x\n", bars
);
4381 * lpfc_disable_pci_dev - Disable a generic PCI device.
4382 * @phba: pointer to lpfc hba data structure.
4384 * This routine is invoked to disable the PCI device that is common to all
4388 lpfc_disable_pci_dev(struct lpfc_hba
*phba
)
4390 struct pci_dev
*pdev
;
4393 /* Obtain PCI device reference */
4397 pdev
= phba
->pcidev
;
4398 /* Select PCI BARs */
4399 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
4400 /* Release PCI resource and disable PCI device */
4401 pci_release_selected_regions(pdev
, bars
);
4402 pci_disable_device(pdev
);
4403 /* Null out PCI private reference to driver */
4404 pci_set_drvdata(pdev
, NULL
);
4410 * lpfc_reset_hba - Reset a hba
4411 * @phba: pointer to lpfc hba data structure.
4413 * This routine is invoked to reset a hba device. It brings the HBA
4414 * offline, performs a board restart, and then brings the board back
4415 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4416 * on outstanding mailbox commands.
4419 lpfc_reset_hba(struct lpfc_hba
*phba
)
4421 /* If resets are disabled then set error state and return. */
4422 if (!phba
->cfg_enable_hba_reset
) {
4423 phba
->link_state
= LPFC_HBA_ERROR
;
4426 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
4428 lpfc_sli_brdrestart(phba
);
4430 lpfc_unblock_mgmt_io(phba
);
4434 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4435 * @phba: pointer to lpfc hba data structure.
4437 * This function enables the PCI SR-IOV virtual functions to a physical
4438 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4439 * enable the number of virtual functions to the physical function. As
4440 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4441 * API call does not considered as an error condition for most of the device.
4444 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba
*phba
)
4446 struct pci_dev
*pdev
= phba
->pcidev
;
4450 pos
= pci_find_ext_capability(pdev
, PCI_EXT_CAP_ID_SRIOV
);
4454 pci_read_config_word(pdev
, pos
+ PCI_SRIOV_TOTAL_VF
, &nr_virtfn
);
4459 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4460 * @phba: pointer to lpfc hba data structure.
4461 * @nr_vfn: number of virtual functions to be enabled.
4463 * This function enables the PCI SR-IOV virtual functions to a physical
4464 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4465 * enable the number of virtual functions to the physical function. As
4466 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4467 * API call does not considered as an error condition for most of the device.
4470 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba
*phba
, int nr_vfn
)
4472 struct pci_dev
*pdev
= phba
->pcidev
;
4473 uint16_t max_nr_vfn
;
4476 max_nr_vfn
= lpfc_sli_sriov_nr_virtfn_get(phba
);
4477 if (nr_vfn
> max_nr_vfn
) {
4478 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4479 "3057 Requested vfs (%d) greater than "
4480 "supported vfs (%d)", nr_vfn
, max_nr_vfn
);
4484 rc
= pci_enable_sriov(pdev
, nr_vfn
);
4486 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4487 "2806 Failed to enable sriov on this device "
4488 "with vfn number nr_vf:%d, rc:%d\n",
4491 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4492 "2807 Successful enable sriov on this device "
4493 "with vfn number nr_vf:%d\n", nr_vfn
);
4498 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
4499 * @phba: pointer to lpfc hba data structure.
4501 * This routine is invoked to set up the driver internal resources specific to
4502 * support the SLI-3 HBA device it attached to.
4506 * other values - error
4509 lpfc_sli_driver_resource_setup(struct lpfc_hba
*phba
)
4511 struct lpfc_sli
*psli
;
4515 * Initialize timers used by driver
4518 /* Heartbeat timer */
4519 init_timer(&phba
->hb_tmofunc
);
4520 phba
->hb_tmofunc
.function
= lpfc_hb_timeout
;
4521 phba
->hb_tmofunc
.data
= (unsigned long)phba
;
4524 /* MBOX heartbeat timer */
4525 init_timer(&psli
->mbox_tmo
);
4526 psli
->mbox_tmo
.function
= lpfc_mbox_timeout
;
4527 psli
->mbox_tmo
.data
= (unsigned long) phba
;
4528 /* FCP polling mode timer */
4529 init_timer(&phba
->fcp_poll_timer
);
4530 phba
->fcp_poll_timer
.function
= lpfc_poll_timeout
;
4531 phba
->fcp_poll_timer
.data
= (unsigned long) phba
;
4532 /* Fabric block timer */
4533 init_timer(&phba
->fabric_block_timer
);
4534 phba
->fabric_block_timer
.function
= lpfc_fabric_block_timeout
;
4535 phba
->fabric_block_timer
.data
= (unsigned long) phba
;
4536 /* EA polling mode timer */
4537 init_timer(&phba
->eratt_poll
);
4538 phba
->eratt_poll
.function
= lpfc_poll_eratt
;
4539 phba
->eratt_poll
.data
= (unsigned long) phba
;
4541 /* Host attention work mask setup */
4542 phba
->work_ha_mask
= (HA_ERATT
| HA_MBATT
| HA_LATT
);
4543 phba
->work_ha_mask
|= (HA_RXMASK
<< (LPFC_ELS_RING
* 4));
4545 /* Get all the module params for configuring this host */
4546 lpfc_get_cfgparam(phba
);
4547 if (phba
->pcidev
->device
== PCI_DEVICE_ID_HORNET
) {
4548 phba
->menlo_flag
|= HBA_MENLO_SUPPORT
;
4549 /* check for menlo minimum sg count */
4550 if (phba
->cfg_sg_seg_cnt
< LPFC_DEFAULT_MENLO_SG_SEG_CNT
)
4551 phba
->cfg_sg_seg_cnt
= LPFC_DEFAULT_MENLO_SG_SEG_CNT
;
4554 if (!phba
->sli
.ring
)
4555 phba
->sli
.ring
= (struct lpfc_sli_ring
*)
4556 kzalloc(LPFC_SLI3_MAX_RING
*
4557 sizeof(struct lpfc_sli_ring
), GFP_KERNEL
);
4558 if (!phba
->sli
.ring
)
4562 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4563 * used to create the sg_dma_buf_pool must be dynamically calculated.
4564 * 2 segments are added since the IOCB needs a command and response bde.
4566 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
4567 sizeof(struct fcp_rsp
) +
4568 ((phba
->cfg_sg_seg_cnt
+ 2) * sizeof(struct ulp_bde64
));
4570 if (phba
->cfg_enable_bg
) {
4571 phba
->cfg_sg_seg_cnt
= LPFC_MAX_SG_SEG_CNT
;
4572 phba
->cfg_sg_dma_buf_size
+=
4573 phba
->cfg_prot_sg_seg_cnt
* sizeof(struct ulp_bde64
);
4576 /* Also reinitialize the host templates with new values. */
4577 lpfc_vport_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
4578 lpfc_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
4580 phba
->max_vpi
= LPFC_MAX_VPI
;
4581 /* This will be set to correct value after config_port mbox */
4582 phba
->max_vports
= 0;
4585 * Initialize the SLI Layer to run with lpfc HBAs.
4587 lpfc_sli_setup(phba
);
4588 lpfc_sli_queue_setup(phba
);
4590 /* Allocate device driver memory */
4591 if (lpfc_mem_alloc(phba
, BPL_ALIGN_SZ
))
4595 * Enable sr-iov virtual functions if supported and configured
4596 * through the module parameter.
4598 if (phba
->cfg_sriov_nr_virtfn
> 0) {
4599 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
,
4600 phba
->cfg_sriov_nr_virtfn
);
4602 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4603 "2808 Requested number of SR-IOV "
4604 "virtual functions (%d) is not "
4606 phba
->cfg_sriov_nr_virtfn
);
4607 phba
->cfg_sriov_nr_virtfn
= 0;
4615 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
4616 * @phba: pointer to lpfc hba data structure.
4618 * This routine is invoked to unset the driver internal resources set up
4619 * specific for supporting the SLI-3 HBA device it attached to.
4622 lpfc_sli_driver_resource_unset(struct lpfc_hba
*phba
)
4624 /* Free device driver memory allocated */
4625 lpfc_mem_free_all(phba
);
4631 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
4632 * @phba: pointer to lpfc hba data structure.
4634 * This routine is invoked to set up the driver internal resources specific to
4635 * support the SLI-4 HBA device it attached to.
4639 * other values - error
4642 lpfc_sli4_driver_resource_setup(struct lpfc_hba
*phba
)
4644 struct lpfc_sli
*psli
;
4645 LPFC_MBOXQ_t
*mboxq
;
4646 int rc
, i
, hbq_count
, buf_size
, dma_buf_size
, max_buf_size
;
4647 uint8_t pn_page
[LPFC_MAX_SUPPORTED_PAGES
] = {0};
4648 struct lpfc_mqe
*mqe
;
4649 int longs
, sli_family
;
4650 int sges_per_segment
;
4652 /* Before proceed, wait for POST done and device ready */
4653 rc
= lpfc_sli4_post_status_check(phba
);
4658 * Initialize timers used by driver
4661 /* Heartbeat timer */
4662 init_timer(&phba
->hb_tmofunc
);
4663 phba
->hb_tmofunc
.function
= lpfc_hb_timeout
;
4664 phba
->hb_tmofunc
.data
= (unsigned long)phba
;
4665 init_timer(&phba
->rrq_tmr
);
4666 phba
->rrq_tmr
.function
= lpfc_rrq_timeout
;
4667 phba
->rrq_tmr
.data
= (unsigned long)phba
;
4670 /* MBOX heartbeat timer */
4671 init_timer(&psli
->mbox_tmo
);
4672 psli
->mbox_tmo
.function
= lpfc_mbox_timeout
;
4673 psli
->mbox_tmo
.data
= (unsigned long) phba
;
4674 /* Fabric block timer */
4675 init_timer(&phba
->fabric_block_timer
);
4676 phba
->fabric_block_timer
.function
= lpfc_fabric_block_timeout
;
4677 phba
->fabric_block_timer
.data
= (unsigned long) phba
;
4678 /* EA polling mode timer */
4679 init_timer(&phba
->eratt_poll
);
4680 phba
->eratt_poll
.function
= lpfc_poll_eratt
;
4681 phba
->eratt_poll
.data
= (unsigned long) phba
;
4682 /* FCF rediscover timer */
4683 init_timer(&phba
->fcf
.redisc_wait
);
4684 phba
->fcf
.redisc_wait
.function
= lpfc_sli4_fcf_redisc_wait_tmo
;
4685 phba
->fcf
.redisc_wait
.data
= (unsigned long)phba
;
4688 * Control structure for handling external multi-buffer mailbox
4689 * command pass-through.
4691 memset((uint8_t *)&phba
->mbox_ext_buf_ctx
, 0,
4692 sizeof(struct lpfc_mbox_ext_buf_ctx
));
4693 INIT_LIST_HEAD(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
4696 * We need to do a READ_CONFIG mailbox command here before
4697 * calling lpfc_get_cfgparam. For VFs this will report the
4698 * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
4699 * All of the resources allocated
4700 * for this Port are tied to these values.
4702 /* Get all the module params for configuring this host */
4703 lpfc_get_cfgparam(phba
);
4704 phba
->max_vpi
= LPFC_MAX_VPI
;
4706 /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */
4707 phba
->cfg_fcp_io_channel
= phba
->cfg_fcp_eq_count
;
4709 /* This will be set to correct value after the read_config mbox */
4710 phba
->max_vports
= 0;
4712 /* Program the default value of vlan_id and fc_map */
4713 phba
->valid_vlan
= 0;
4714 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4715 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4716 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4718 /* With BlockGuard we can have multiple SGEs per Data Segemnt */
4719 sges_per_segment
= 1;
4720 if (phba
->cfg_enable_bg
)
4721 sges_per_segment
= 2;
4724 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
4725 * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
4727 if (!phba
->sli
.ring
)
4728 phba
->sli
.ring
= kzalloc(
4729 (LPFC_SLI3_MAX_RING
+ phba
->cfg_fcp_io_channel
) *
4730 sizeof(struct lpfc_sli_ring
), GFP_KERNEL
);
4731 if (!phba
->sli
.ring
)
4734 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4735 * used to create the sg_dma_buf_pool must be dynamically calculated.
4736 * 2 segments are added since the IOCB needs a command and response bde.
4737 * To insure that the scsi sgl does not cross a 4k page boundary only
4738 * sgl sizes of must be a power of 2.
4740 buf_size
= (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
) +
4741 (((phba
->cfg_sg_seg_cnt
* sges_per_segment
) + 2) *
4742 sizeof(struct sli4_sge
)));
4744 sli_family
= bf_get(lpfc_sli_intf_sli_family
, &phba
->sli4_hba
.sli_intf
);
4745 max_buf_size
= LPFC_SLI4_MAX_BUF_SIZE
;
4746 switch (sli_family
) {
4747 case LPFC_SLI_INTF_FAMILY_BE2
:
4748 case LPFC_SLI_INTF_FAMILY_BE3
:
4749 /* There is a single hint for BE - 2 pages per BPL. */
4750 if (bf_get(lpfc_sli_intf_sli_hint1
, &phba
->sli4_hba
.sli_intf
) ==
4751 LPFC_SLI_INTF_SLI_HINT1_1
)
4752 max_buf_size
= LPFC_SLI4_FL1_MAX_BUF_SIZE
;
4754 case LPFC_SLI_INTF_FAMILY_LNCR_A0
:
4755 case LPFC_SLI_INTF_FAMILY_LNCR_B0
:
4760 for (dma_buf_size
= LPFC_SLI4_MIN_BUF_SIZE
;
4761 dma_buf_size
< max_buf_size
&& buf_size
> dma_buf_size
;
4762 dma_buf_size
= dma_buf_size
<< 1)
4764 if (dma_buf_size
== max_buf_size
)
4765 phba
->cfg_sg_seg_cnt
= (dma_buf_size
-
4766 sizeof(struct fcp_cmnd
) - sizeof(struct fcp_rsp
) -
4767 (2 * sizeof(struct sli4_sge
))) /
4768 sizeof(struct sli4_sge
);
4769 phba
->cfg_sg_dma_buf_size
= dma_buf_size
;
4771 /* Initialize buffer queue management fields */
4772 hbq_count
= lpfc_sli_hbq_count();
4773 for (i
= 0; i
< hbq_count
; ++i
)
4774 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
4775 INIT_LIST_HEAD(&phba
->rb_pend_list
);
4776 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_sli4_rb_alloc
;
4777 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_sli4_rb_free
;
4780 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
4782 /* Initialize the Abort scsi buffer list used by driver */
4783 spin_lock_init(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
4784 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
4785 /* This abort list used by worker thread */
4786 spin_lock_init(&phba
->sli4_hba
.abts_sgl_list_lock
);
4789 * Initialize driver internal slow-path work queues
4792 /* Driver internel slow-path CQ Event pool */
4793 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_cqe_event_pool
);
4794 /* Response IOCB work queue list */
4795 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_queue_event
);
4796 /* Asynchronous event CQ Event work queue list */
4797 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_asynce_work_queue
);
4798 /* Fast-path XRI aborted CQ Event work queue list */
4799 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
4800 /* Slow-path XRI aborted CQ Event work queue list */
4801 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
4802 /* Receive queue CQ Event work queue list */
4803 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_unsol_work_queue
);
4805 /* Initialize extent block lists. */
4806 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_blk_list
);
4807 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_xri_blk_list
);
4808 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_vfi_blk_list
);
4809 INIT_LIST_HEAD(&phba
->lpfc_vpi_blk_list
);
4811 /* Initialize the driver internal SLI layer lists. */
4812 lpfc_sli_setup(phba
);
4813 lpfc_sli_queue_setup(phba
);
4815 /* Allocate device driver memory */
4816 rc
= lpfc_mem_alloc(phba
, SGL_ALIGN_SZ
);
4820 /* IF Type 2 ports get initialized now. */
4821 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
4822 LPFC_SLI_INTF_IF_TYPE_2
) {
4823 rc
= lpfc_pci_function_reset(phba
);
4828 /* Create the bootstrap mailbox command */
4829 rc
= lpfc_create_bootstrap_mbox(phba
);
4833 /* Set up the host's endian order with the device. */
4834 rc
= lpfc_setup_endian_order(phba
);
4836 goto out_free_bsmbx
;
4838 /* Set up the hba's configuration parameters. */
4839 rc
= lpfc_sli4_read_config(phba
);
4841 goto out_free_bsmbx
;
4843 /* IF Type 0 ports get initialized now. */
4844 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
4845 LPFC_SLI_INTF_IF_TYPE_0
) {
4846 rc
= lpfc_pci_function_reset(phba
);
4848 goto out_free_bsmbx
;
4851 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
4855 goto out_free_bsmbx
;
4858 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
4859 lpfc_supported_pages(mboxq
);
4860 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4862 mqe
= &mboxq
->u
.mqe
;
4863 memcpy(&pn_page
[0], ((uint8_t *)&mqe
->un
.supp_pages
.word3
),
4864 LPFC_MAX_SUPPORTED_PAGES
);
4865 for (i
= 0; i
< LPFC_MAX_SUPPORTED_PAGES
; i
++) {
4866 switch (pn_page
[i
]) {
4867 case LPFC_SLI4_PARAMETERS
:
4868 phba
->sli4_hba
.pc_sli4_params
.supported
= 1;
4874 /* Read the port's SLI4 Parameters capabilities if supported. */
4875 if (phba
->sli4_hba
.pc_sli4_params
.supported
)
4876 rc
= lpfc_pc_sli4_params_get(phba
, mboxq
);
4878 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4880 goto out_free_bsmbx
;
4884 * Get sli4 parameters that override parameters from Port capabilities.
4885 * If this call fails, it isn't critical unless the SLI4 parameters come
4888 rc
= lpfc_get_sli4_parameters(phba
, mboxq
);
4890 if (phba
->sli4_hba
.extents_in_use
&&
4891 phba
->sli4_hba
.rpi_hdrs_in_use
) {
4892 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4893 "2999 Unsupported SLI4 Parameters "
4894 "Extents and RPI headers enabled.\n");
4895 goto out_free_bsmbx
;
4898 mempool_free(mboxq
, phba
->mbox_mem_pool
);
4899 /* Verify all the SLI4 queues */
4900 rc
= lpfc_sli4_queue_verify(phba
);
4902 goto out_free_bsmbx
;
4904 /* Create driver internal CQE event pool */
4905 rc
= lpfc_sli4_cq_event_pool_create(phba
);
4907 goto out_free_bsmbx
;
4909 /* Initialize sgl lists per host */
4910 lpfc_init_sgl_list(phba
);
4912 /* Allocate and initialize active sgl array */
4913 rc
= lpfc_init_active_sgl_array(phba
);
4915 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4916 "1430 Failed to initialize sgl list.\n");
4917 goto out_destroy_cq_event_pool
;
4919 rc
= lpfc_sli4_init_rpi_hdrs(phba
);
4921 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4922 "1432 Failed to initialize rpi headers.\n");
4923 goto out_free_active_sgl
;
4926 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
4927 longs
= (LPFC_SLI4_FCF_TBL_INDX_MAX
+ BITS_PER_LONG
- 1)/BITS_PER_LONG
;
4928 phba
->fcf
.fcf_rr_bmask
= kzalloc(longs
* sizeof(unsigned long),
4930 if (!phba
->fcf
.fcf_rr_bmask
) {
4931 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4932 "2759 Failed allocate memory for FCF round "
4933 "robin failover bmask\n");
4935 goto out_remove_rpi_hdrs
;
4938 phba
->sli4_hba
.fcp_eq_hdl
=
4939 kzalloc((sizeof(struct lpfc_fcp_eq_hdl
) *
4940 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
4941 if (!phba
->sli4_hba
.fcp_eq_hdl
) {
4942 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4943 "2572 Failed allocate memory for "
4944 "fast-path per-EQ handle array\n");
4946 goto out_free_fcf_rr_bmask
;
4949 phba
->sli4_hba
.msix_entries
= kzalloc((sizeof(struct msix_entry
) *
4950 phba
->sli4_hba
.cfg_eqn
), GFP_KERNEL
);
4951 if (!phba
->sli4_hba
.msix_entries
) {
4952 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4953 "2573 Failed allocate memory for msi-x "
4954 "interrupt vector entries\n");
4956 goto out_free_fcp_eq_hdl
;
4960 * Enable sr-iov virtual functions if supported and configured
4961 * through the module parameter.
4963 if (phba
->cfg_sriov_nr_virtfn
> 0) {
4964 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
,
4965 phba
->cfg_sriov_nr_virtfn
);
4967 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4968 "3020 Requested number of SR-IOV "
4969 "virtual functions (%d) is not "
4971 phba
->cfg_sriov_nr_virtfn
);
4972 phba
->cfg_sriov_nr_virtfn
= 0;
4978 out_free_fcp_eq_hdl
:
4979 kfree(phba
->sli4_hba
.fcp_eq_hdl
);
4980 out_free_fcf_rr_bmask
:
4981 kfree(phba
->fcf
.fcf_rr_bmask
);
4982 out_remove_rpi_hdrs
:
4983 lpfc_sli4_remove_rpi_hdrs(phba
);
4984 out_free_active_sgl
:
4985 lpfc_free_active_sgl(phba
);
4986 out_destroy_cq_event_pool
:
4987 lpfc_sli4_cq_event_pool_destroy(phba
);
4989 lpfc_destroy_bootstrap_mbox(phba
);
4991 lpfc_mem_free(phba
);
4996 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
4997 * @phba: pointer to lpfc hba data structure.
4999 * This routine is invoked to unset the driver internal resources set up
5000 * specific for supporting the SLI-4 HBA device it attached to.
5003 lpfc_sli4_driver_resource_unset(struct lpfc_hba
*phba
)
5005 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
5007 /* Free memory allocated for msi-x interrupt vector entries */
5008 kfree(phba
->sli4_hba
.msix_entries
);
5010 /* Free memory allocated for fast-path work queue handles */
5011 kfree(phba
->sli4_hba
.fcp_eq_hdl
);
5013 /* Free the allocated rpi headers. */
5014 lpfc_sli4_remove_rpi_hdrs(phba
);
5015 lpfc_sli4_remove_rpis(phba
);
5017 /* Free eligible FCF index bmask */
5018 kfree(phba
->fcf
.fcf_rr_bmask
);
5020 /* Free the ELS sgl list */
5021 lpfc_free_active_sgl(phba
);
5022 lpfc_free_els_sgl_list(phba
);
5024 /* Free the completion queue EQ event pool */
5025 lpfc_sli4_cq_event_release_all(phba
);
5026 lpfc_sli4_cq_event_pool_destroy(phba
);
5028 /* Release resource identifiers. */
5029 lpfc_sli4_dealloc_resource_identifiers(phba
);
5031 /* Free the bsmbx region. */
5032 lpfc_destroy_bootstrap_mbox(phba
);
5034 /* Free the SLI Layer memory with SLI4 HBAs */
5035 lpfc_mem_free_all(phba
);
5037 /* Free the current connect table */
5038 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
5039 &phba
->fcf_conn_rec_list
, list
) {
5040 list_del_init(&conn_entry
->list
);
5048 * lpfc_init_api_table_setup - Set up init api function jump table
5049 * @phba: The hba struct for which this call is being executed.
5050 * @dev_grp: The HBA PCI-Device group number.
5052 * This routine sets up the device INIT interface API function jump table
5055 * Returns: 0 - success, -ENODEV - failure.
5058 lpfc_init_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
5060 phba
->lpfc_hba_init_link
= lpfc_hba_init_link
;
5061 phba
->lpfc_hba_down_link
= lpfc_hba_down_link
;
5062 phba
->lpfc_selective_reset
= lpfc_selective_reset
;
5064 case LPFC_PCI_DEV_LP
:
5065 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s3
;
5066 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s3
;
5067 phba
->lpfc_stop_port
= lpfc_stop_port_s3
;
5069 case LPFC_PCI_DEV_OC
:
5070 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s4
;
5071 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s4
;
5072 phba
->lpfc_stop_port
= lpfc_stop_port_s4
;
5075 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5076 "1431 Invalid HBA PCI-device group: 0x%x\n",
5085 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5086 * @phba: pointer to lpfc hba data structure.
5088 * This routine is invoked to set up the driver internal resources before the
5089 * device specific resource setup to support the HBA device it attached to.
5093 * other values - error
5096 lpfc_setup_driver_resource_phase1(struct lpfc_hba
*phba
)
5099 * Driver resources common to all SLI revisions
5101 atomic_set(&phba
->fast_event_count
, 0);
5102 spin_lock_init(&phba
->hbalock
);
5104 /* Initialize ndlp management spinlock */
5105 spin_lock_init(&phba
->ndlp_lock
);
5107 INIT_LIST_HEAD(&phba
->port_list
);
5108 INIT_LIST_HEAD(&phba
->work_list
);
5109 init_waitqueue_head(&phba
->wait_4_mlo_m_q
);
5111 /* Initialize the wait queue head for the kernel thread */
5112 init_waitqueue_head(&phba
->work_waitq
);
5114 /* Initialize the scsi buffer list used by driver for scsi IO */
5115 spin_lock_init(&phba
->scsi_buf_list_lock
);
5116 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list
);
5118 /* Initialize the fabric iocb list */
5119 INIT_LIST_HEAD(&phba
->fabric_iocb_list
);
5121 /* Initialize list to save ELS buffers */
5122 INIT_LIST_HEAD(&phba
->elsbuf
);
5124 /* Initialize FCF connection rec list */
5125 INIT_LIST_HEAD(&phba
->fcf_conn_rec_list
);
5131 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5132 * @phba: pointer to lpfc hba data structure.
5134 * This routine is invoked to set up the driver internal resources after the
5135 * device specific resource setup to support the HBA device it attached to.
5139 * other values - error
5142 lpfc_setup_driver_resource_phase2(struct lpfc_hba
*phba
)
5146 /* Startup the kernel thread for this host adapter. */
5147 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
5148 "lpfc_worker_%d", phba
->brd_no
);
5149 if (IS_ERR(phba
->worker_thread
)) {
5150 error
= PTR_ERR(phba
->worker_thread
);
5158 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5159 * @phba: pointer to lpfc hba data structure.
5161 * This routine is invoked to unset the driver internal resources set up after
5162 * the device specific resource setup for supporting the HBA device it
5166 lpfc_unset_driver_resource_phase2(struct lpfc_hba
*phba
)
5168 /* Stop kernel worker thread */
5169 kthread_stop(phba
->worker_thread
);
5173 * lpfc_free_iocb_list - Free iocb list.
5174 * @phba: pointer to lpfc hba data structure.
5176 * This routine is invoked to free the driver's IOCB list and memory.
5179 lpfc_free_iocb_list(struct lpfc_hba
*phba
)
5181 struct lpfc_iocbq
*iocbq_entry
= NULL
, *iocbq_next
= NULL
;
5183 spin_lock_irq(&phba
->hbalock
);
5184 list_for_each_entry_safe(iocbq_entry
, iocbq_next
,
5185 &phba
->lpfc_iocb_list
, list
) {
5186 list_del(&iocbq_entry
->list
);
5188 phba
->total_iocbq_bufs
--;
5190 spin_unlock_irq(&phba
->hbalock
);
5196 * lpfc_init_iocb_list - Allocate and initialize iocb list.
5197 * @phba: pointer to lpfc hba data structure.
5199 * This routine is invoked to allocate and initizlize the driver's IOCB
5200 * list and set up the IOCB tag array accordingly.
5204 * other values - error
5207 lpfc_init_iocb_list(struct lpfc_hba
*phba
, int iocb_count
)
5209 struct lpfc_iocbq
*iocbq_entry
= NULL
;
5213 /* Initialize and populate the iocb list per host. */
5214 INIT_LIST_HEAD(&phba
->lpfc_iocb_list
);
5215 for (i
= 0; i
< iocb_count
; i
++) {
5216 iocbq_entry
= kzalloc(sizeof(struct lpfc_iocbq
), GFP_KERNEL
);
5217 if (iocbq_entry
== NULL
) {
5218 printk(KERN_ERR
"%s: only allocated %d iocbs of "
5219 "expected %d count. Unloading driver.\n",
5220 __func__
, i
, LPFC_IOCB_LIST_CNT
);
5221 goto out_free_iocbq
;
5224 iotag
= lpfc_sli_next_iotag(phba
, iocbq_entry
);
5227 printk(KERN_ERR
"%s: failed to allocate IOTAG. "
5228 "Unloading driver.\n", __func__
);
5229 goto out_free_iocbq
;
5231 iocbq_entry
->sli4_lxritag
= NO_XRI
;
5232 iocbq_entry
->sli4_xritag
= NO_XRI
;
5234 spin_lock_irq(&phba
->hbalock
);
5235 list_add(&iocbq_entry
->list
, &phba
->lpfc_iocb_list
);
5236 phba
->total_iocbq_bufs
++;
5237 spin_unlock_irq(&phba
->hbalock
);
5243 lpfc_free_iocb_list(phba
);
5249 * lpfc_free_sgl_list - Free a given sgl list.
5250 * @phba: pointer to lpfc hba data structure.
5251 * @sglq_list: pointer to the head of sgl list.
5253 * This routine is invoked to free a give sgl list and memory.
5256 lpfc_free_sgl_list(struct lpfc_hba
*phba
, struct list_head
*sglq_list
)
5258 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
5260 list_for_each_entry_safe(sglq_entry
, sglq_next
, sglq_list
, list
) {
5261 list_del(&sglq_entry
->list
);
5262 lpfc_mbuf_free(phba
, sglq_entry
->virt
, sglq_entry
->phys
);
5268 * lpfc_free_els_sgl_list - Free els sgl list.
5269 * @phba: pointer to lpfc hba data structure.
5271 * This routine is invoked to free the driver's els sgl list and memory.
5274 lpfc_free_els_sgl_list(struct lpfc_hba
*phba
)
5276 LIST_HEAD(sglq_list
);
5278 /* Retrieve all els sgls from driver list */
5279 spin_lock_irq(&phba
->hbalock
);
5280 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &sglq_list
);
5281 spin_unlock_irq(&phba
->hbalock
);
5283 /* Now free the sgl list */
5284 lpfc_free_sgl_list(phba
, &sglq_list
);
5288 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
5289 * @phba: pointer to lpfc hba data structure.
5291 * This routine is invoked to allocate the driver's active sgl memory.
5292 * This array will hold the sglq_entry's for active IOs.
5295 lpfc_init_active_sgl_array(struct lpfc_hba
*phba
)
5298 size
= sizeof(struct lpfc_sglq
*);
5299 size
*= phba
->sli4_hba
.max_cfg_param
.max_xri
;
5301 phba
->sli4_hba
.lpfc_sglq_active_list
=
5302 kzalloc(size
, GFP_KERNEL
);
5303 if (!phba
->sli4_hba
.lpfc_sglq_active_list
)
5309 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
5310 * @phba: pointer to lpfc hba data structure.
5312 * This routine is invoked to walk through the array of active sglq entries
5313 * and free all of the resources.
5314 * This is just a place holder for now.
5317 lpfc_free_active_sgl(struct lpfc_hba
*phba
)
5319 kfree(phba
->sli4_hba
.lpfc_sglq_active_list
);
5323 * lpfc_init_sgl_list - Allocate and initialize sgl list.
5324 * @phba: pointer to lpfc hba data structure.
5326 * This routine is invoked to allocate and initizlize the driver's sgl
5327 * list and set up the sgl xritag tag array accordingly.
5331 lpfc_init_sgl_list(struct lpfc_hba
*phba
)
5333 /* Initialize and populate the sglq list per host/VF. */
5334 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_sgl_list
);
5335 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
5337 /* els xri-sgl book keeping */
5338 phba
->sli4_hba
.els_xri_cnt
= 0;
5340 /* scsi xri-buffer book keeping */
5341 phba
->sli4_hba
.scsi_xri_cnt
= 0;
5345 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5346 * @phba: pointer to lpfc hba data structure.
5348 * This routine is invoked to post rpi header templates to the
5349 * port for those SLI4 ports that do not support extents. This routine
5350 * posts a PAGE_SIZE memory region to the port to hold up to
5351 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5352 * and should be called only when interrupts are disabled.
5356 * -ERROR - otherwise.
5359 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba
*phba
)
5362 struct lpfc_rpi_hdr
*rpi_hdr
;
5364 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_hdr_list
);
5365 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5367 if (phba
->sli4_hba
.extents_in_use
)
5370 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
5372 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5373 "0391 Error during rpi post operation\n");
5374 lpfc_sli4_remove_rpis(phba
);
5382 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
5383 * @phba: pointer to lpfc hba data structure.
5385 * This routine is invoked to allocate a single 4KB memory region to
5386 * support rpis and stores them in the phba. This single region
5387 * provides support for up to 64 rpis. The region is used globally
5391 * A valid rpi hdr on success.
5392 * A NULL pointer on any failure.
5394 struct lpfc_rpi_hdr
*
5395 lpfc_sli4_create_rpi_hdr(struct lpfc_hba
*phba
)
5397 uint16_t rpi_limit
, curr_rpi_range
;
5398 struct lpfc_dmabuf
*dmabuf
;
5399 struct lpfc_rpi_hdr
*rpi_hdr
;
5403 * If the SLI4 port supports extents, posting the rpi header isn't
5404 * required. Set the expected maximum count and let the actual value
5405 * get set when extents are fully allocated.
5407 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5409 if (phba
->sli4_hba
.extents_in_use
)
5412 /* The limit on the logical index is just the max_rpi count. */
5413 rpi_limit
= phba
->sli4_hba
.max_cfg_param
.rpi_base
+
5414 phba
->sli4_hba
.max_cfg_param
.max_rpi
- 1;
5416 spin_lock_irq(&phba
->hbalock
);
5418 * Establish the starting RPI in this header block. The starting
5419 * rpi is normalized to a zero base because the physical rpi is
5422 curr_rpi_range
= phba
->sli4_hba
.next_rpi
;
5423 spin_unlock_irq(&phba
->hbalock
);
5426 * The port has a limited number of rpis. The increment here
5427 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
5428 * and to allow the full max_rpi range per port.
5430 if ((curr_rpi_range
+ (LPFC_RPI_HDR_COUNT
- 1)) > rpi_limit
)
5431 rpi_count
= rpi_limit
- curr_rpi_range
;
5433 rpi_count
= LPFC_RPI_HDR_COUNT
;
5438 * First allocate the protocol header region for the port. The
5439 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
5441 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
5445 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
5446 LPFC_HDR_TEMPLATE_SIZE
,
5449 if (!dmabuf
->virt
) {
5451 goto err_free_dmabuf
;
5454 memset(dmabuf
->virt
, 0, LPFC_HDR_TEMPLATE_SIZE
);
5455 if (!IS_ALIGNED(dmabuf
->phys
, LPFC_HDR_TEMPLATE_SIZE
)) {
5457 goto err_free_coherent
;
5460 /* Save the rpi header data for cleanup later. */
5461 rpi_hdr
= kzalloc(sizeof(struct lpfc_rpi_hdr
), GFP_KERNEL
);
5463 goto err_free_coherent
;
5465 rpi_hdr
->dmabuf
= dmabuf
;
5466 rpi_hdr
->len
= LPFC_HDR_TEMPLATE_SIZE
;
5467 rpi_hdr
->page_count
= 1;
5468 spin_lock_irq(&phba
->hbalock
);
5470 /* The rpi_hdr stores the logical index only. */
5471 rpi_hdr
->start_rpi
= curr_rpi_range
;
5472 list_add_tail(&rpi_hdr
->list
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
);
5475 * The next_rpi stores the next logical module-64 rpi value used
5476 * to post physical rpis in subsequent rpi postings.
5478 phba
->sli4_hba
.next_rpi
+= rpi_count
;
5479 spin_unlock_irq(&phba
->hbalock
);
5483 dma_free_coherent(&phba
->pcidev
->dev
, LPFC_HDR_TEMPLATE_SIZE
,
5484 dmabuf
->virt
, dmabuf
->phys
);
5491 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
5492 * @phba: pointer to lpfc hba data structure.
5494 * This routine is invoked to remove all memory resources allocated
5495 * to support rpis for SLI4 ports not supporting extents. This routine
5496 * presumes the caller has released all rpis consumed by fabric or port
5497 * logins and is prepared to have the header pages removed.
5500 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba
*phba
)
5502 struct lpfc_rpi_hdr
*rpi_hdr
, *next_rpi_hdr
;
5504 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5507 list_for_each_entry_safe(rpi_hdr
, next_rpi_hdr
,
5508 &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
5509 list_del(&rpi_hdr
->list
);
5510 dma_free_coherent(&phba
->pcidev
->dev
, rpi_hdr
->len
,
5511 rpi_hdr
->dmabuf
->virt
, rpi_hdr
->dmabuf
->phys
);
5512 kfree(rpi_hdr
->dmabuf
);
5516 /* There are no rpis available to the port now. */
5517 phba
->sli4_hba
.next_rpi
= 0;
5521 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
5522 * @pdev: pointer to pci device data structure.
5524 * This routine is invoked to allocate the driver hba data structure for an
5525 * HBA device. If the allocation is successful, the phba reference to the
5526 * PCI device data structure is set.
5529 * pointer to @phba - successful
5532 static struct lpfc_hba
*
5533 lpfc_hba_alloc(struct pci_dev
*pdev
)
5535 struct lpfc_hba
*phba
;
5537 /* Allocate memory for HBA structure */
5538 phba
= kzalloc(sizeof(struct lpfc_hba
), GFP_KERNEL
);
5540 dev_err(&pdev
->dev
, "failed to allocate hba struct\n");
5544 /* Set reference to PCI device in HBA structure */
5545 phba
->pcidev
= pdev
;
5547 /* Assign an unused board number */
5548 phba
->brd_no
= lpfc_get_instance();
5549 if (phba
->brd_no
< 0) {
5554 spin_lock_init(&phba
->ct_ev_lock
);
5555 INIT_LIST_HEAD(&phba
->ct_ev_waiters
);
5561 * lpfc_hba_free - Free driver hba data structure with a device.
5562 * @phba: pointer to lpfc hba data structure.
5564 * This routine is invoked to free the driver hba data structure with an
5568 lpfc_hba_free(struct lpfc_hba
*phba
)
5570 /* Release the driver assigned board number */
5571 idr_remove(&lpfc_hba_index
, phba
->brd_no
);
5573 /* Free memory allocated with sli rings */
5574 kfree(phba
->sli
.ring
);
5575 phba
->sli
.ring
= NULL
;
5582 * lpfc_create_shost - Create hba physical port with associated scsi host.
5583 * @phba: pointer to lpfc hba data structure.
5585 * This routine is invoked to create HBA physical port and associate a SCSI
5590 * other values - error
5593 lpfc_create_shost(struct lpfc_hba
*phba
)
5595 struct lpfc_vport
*vport
;
5596 struct Scsi_Host
*shost
;
5598 /* Initialize HBA FC structure */
5599 phba
->fc_edtov
= FF_DEF_EDTOV
;
5600 phba
->fc_ratov
= FF_DEF_RATOV
;
5601 phba
->fc_altov
= FF_DEF_ALTOV
;
5602 phba
->fc_arbtov
= FF_DEF_ARBTOV
;
5604 atomic_set(&phba
->sdev_cnt
, 0);
5605 vport
= lpfc_create_port(phba
, phba
->brd_no
, &phba
->pcidev
->dev
);
5609 shost
= lpfc_shost_from_vport(vport
);
5610 phba
->pport
= vport
;
5611 lpfc_debugfs_initialize(vport
);
5612 /* Put reference to SCSI host to driver's device private data */
5613 pci_set_drvdata(phba
->pcidev
, shost
);
5619 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
5620 * @phba: pointer to lpfc hba data structure.
5622 * This routine is invoked to destroy HBA physical port and the associated
5626 lpfc_destroy_shost(struct lpfc_hba
*phba
)
5628 struct lpfc_vport
*vport
= phba
->pport
;
5630 /* Destroy physical port that associated with the SCSI host */
5631 destroy_port(vport
);
5637 * lpfc_setup_bg - Setup Block guard structures and debug areas.
5638 * @phba: pointer to lpfc hba data structure.
5639 * @shost: the shost to be used to detect Block guard settings.
5641 * This routine sets up the local Block guard protocol settings for @shost.
5642 * This routine also allocates memory for debugging bg buffers.
5645 lpfc_setup_bg(struct lpfc_hba
*phba
, struct Scsi_Host
*shost
)
5651 if (lpfc_prot_mask
&& lpfc_prot_guard
) {
5652 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5653 "1478 Registering BlockGuard with the "
5656 old_mask
= lpfc_prot_mask
;
5657 old_guard
= lpfc_prot_guard
;
5659 /* Only allow supported values */
5660 lpfc_prot_mask
&= (SHOST_DIF_TYPE1_PROTECTION
|
5661 SHOST_DIX_TYPE0_PROTECTION
|
5662 SHOST_DIX_TYPE1_PROTECTION
);
5663 lpfc_prot_guard
&= (SHOST_DIX_GUARD_IP
| SHOST_DIX_GUARD_CRC
);
5665 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
5666 if (lpfc_prot_mask
== SHOST_DIX_TYPE1_PROTECTION
)
5667 lpfc_prot_mask
|= SHOST_DIF_TYPE1_PROTECTION
;
5669 if (lpfc_prot_mask
&& lpfc_prot_guard
) {
5670 if ((old_mask
!= lpfc_prot_mask
) ||
5671 (old_guard
!= lpfc_prot_guard
))
5672 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5673 "1475 Registering BlockGuard with the "
5674 "SCSI layer: mask %d guard %d\n",
5675 lpfc_prot_mask
, lpfc_prot_guard
);
5677 scsi_host_set_prot(shost
, lpfc_prot_mask
);
5678 scsi_host_set_guard(shost
, lpfc_prot_guard
);
5680 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5681 "1479 Not Registering BlockGuard with the SCSI "
5682 "layer, Bad protection parameters: %d %d\n",
5683 old_mask
, old_guard
);
5686 if (!_dump_buf_data
) {
5688 spin_lock_init(&_dump_buf_lock
);
5690 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
5691 if (_dump_buf_data
) {
5692 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5693 "9043 BLKGRD: allocated %d pages for "
5694 "_dump_buf_data at 0x%p\n",
5695 (1 << pagecnt
), _dump_buf_data
);
5696 _dump_buf_data_order
= pagecnt
;
5697 memset(_dump_buf_data
, 0,
5698 ((1 << PAGE_SHIFT
) << pagecnt
));
5703 if (!_dump_buf_data_order
)
5704 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5705 "9044 BLKGRD: ERROR unable to allocate "
5706 "memory for hexdump\n");
5708 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5709 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
5710 "\n", _dump_buf_data
);
5711 if (!_dump_buf_dif
) {
5714 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
5715 if (_dump_buf_dif
) {
5716 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5717 "9046 BLKGRD: allocated %d pages for "
5718 "_dump_buf_dif at 0x%p\n",
5719 (1 << pagecnt
), _dump_buf_dif
);
5720 _dump_buf_dif_order
= pagecnt
;
5721 memset(_dump_buf_dif
, 0,
5722 ((1 << PAGE_SHIFT
) << pagecnt
));
5727 if (!_dump_buf_dif_order
)
5728 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5729 "9047 BLKGRD: ERROR unable to allocate "
5730 "memory for hexdump\n");
5732 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5733 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
5738 * lpfc_post_init_setup - Perform necessary device post initialization setup.
5739 * @phba: pointer to lpfc hba data structure.
5741 * This routine is invoked to perform all the necessary post initialization
5742 * setup for the device.
5745 lpfc_post_init_setup(struct lpfc_hba
*phba
)
5747 struct Scsi_Host
*shost
;
5748 struct lpfc_adapter_event_header adapter_event
;
5750 /* Get the default values for Model Name and Description */
5751 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
5754 * hba setup may have changed the hba_queue_depth so we need to
5755 * adjust the value of can_queue.
5757 shost
= pci_get_drvdata(phba
->pcidev
);
5758 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
5759 if (phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)
5760 lpfc_setup_bg(phba
, shost
);
5762 lpfc_host_attrib_init(shost
);
5764 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
5765 spin_lock_irq(shost
->host_lock
);
5766 lpfc_poll_start_timer(phba
);
5767 spin_unlock_irq(shost
->host_lock
);
5770 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5771 "0428 Perform SCSI scan\n");
5772 /* Send board arrival event to upper layer */
5773 adapter_event
.event_type
= FC_REG_ADAPTER_EVENT
;
5774 adapter_event
.subcategory
= LPFC_EVENT_ARRIVAL
;
5775 fc_host_post_vendor_event(shost
, fc_get_event_number(),
5776 sizeof(adapter_event
),
5777 (char *) &adapter_event
,
5783 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
5784 * @phba: pointer to lpfc hba data structure.
5786 * This routine is invoked to set up the PCI device memory space for device
5787 * with SLI-3 interface spec.
5791 * other values - error
5794 lpfc_sli_pci_mem_setup(struct lpfc_hba
*phba
)
5796 struct pci_dev
*pdev
;
5797 unsigned long bar0map_len
, bar2map_len
;
5800 int error
= -ENODEV
;
5802 /* Obtain PCI device reference */
5806 pdev
= phba
->pcidev
;
5808 /* Set the device DMA mask size */
5809 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
5810 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
5811 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
5812 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
5817 /* Get the bus address of Bar0 and Bar2 and the number of bytes
5818 * required by each mapping.
5820 phba
->pci_bar0_map
= pci_resource_start(pdev
, 0);
5821 bar0map_len
= pci_resource_len(pdev
, 0);
5823 phba
->pci_bar2_map
= pci_resource_start(pdev
, 2);
5824 bar2map_len
= pci_resource_len(pdev
, 2);
5826 /* Map HBA SLIM to a kernel virtual address. */
5827 phba
->slim_memmap_p
= ioremap(phba
->pci_bar0_map
, bar0map_len
);
5828 if (!phba
->slim_memmap_p
) {
5829 dev_printk(KERN_ERR
, &pdev
->dev
,
5830 "ioremap failed for SLIM memory.\n");
5834 /* Map HBA Control Registers to a kernel virtual address. */
5835 phba
->ctrl_regs_memmap_p
= ioremap(phba
->pci_bar2_map
, bar2map_len
);
5836 if (!phba
->ctrl_regs_memmap_p
) {
5837 dev_printk(KERN_ERR
, &pdev
->dev
,
5838 "ioremap failed for HBA control registers.\n");
5839 goto out_iounmap_slim
;
5842 /* Allocate memory for SLI-2 structures */
5843 phba
->slim2p
.virt
= dma_alloc_coherent(&pdev
->dev
,
5847 if (!phba
->slim2p
.virt
)
5850 memset(phba
->slim2p
.virt
, 0, SLI2_SLIM_SIZE
);
5851 phba
->mbox
= phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, mbx
);
5852 phba
->mbox_ext
= (phba
->slim2p
.virt
+
5853 offsetof(struct lpfc_sli2_slim
, mbx_ext_words
));
5854 phba
->pcb
= (phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, pcb
));
5855 phba
->IOCBs
= (phba
->slim2p
.virt
+
5856 offsetof(struct lpfc_sli2_slim
, IOCBs
));
5858 phba
->hbqslimp
.virt
= dma_alloc_coherent(&pdev
->dev
,
5859 lpfc_sli_hbq_size(),
5860 &phba
->hbqslimp
.phys
,
5862 if (!phba
->hbqslimp
.virt
)
5865 hbq_count
= lpfc_sli_hbq_count();
5866 ptr
= phba
->hbqslimp
.virt
;
5867 for (i
= 0; i
< hbq_count
; ++i
) {
5868 phba
->hbqs
[i
].hbq_virt
= ptr
;
5869 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
5870 ptr
+= (lpfc_hbq_defs
[i
]->entry_count
*
5871 sizeof(struct lpfc_hbq_entry
));
5873 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_els_hbq_alloc
;
5874 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_els_hbq_free
;
5876 memset(phba
->hbqslimp
.virt
, 0, lpfc_sli_hbq_size());
5878 INIT_LIST_HEAD(&phba
->rb_pend_list
);
5880 phba
->MBslimaddr
= phba
->slim_memmap_p
;
5881 phba
->HAregaddr
= phba
->ctrl_regs_memmap_p
+ HA_REG_OFFSET
;
5882 phba
->CAregaddr
= phba
->ctrl_regs_memmap_p
+ CA_REG_OFFSET
;
5883 phba
->HSregaddr
= phba
->ctrl_regs_memmap_p
+ HS_REG_OFFSET
;
5884 phba
->HCregaddr
= phba
->ctrl_regs_memmap_p
+ HC_REG_OFFSET
;
5889 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
5890 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
5892 iounmap(phba
->ctrl_regs_memmap_p
);
5894 iounmap(phba
->slim_memmap_p
);
5900 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
5901 * @phba: pointer to lpfc hba data structure.
5903 * This routine is invoked to unset the PCI device memory space for device
5904 * with SLI-3 interface spec.
5907 lpfc_sli_pci_mem_unset(struct lpfc_hba
*phba
)
5909 struct pci_dev
*pdev
;
5911 /* Obtain PCI device reference */
5915 pdev
= phba
->pcidev
;
5917 /* Free coherent DMA memory allocated */
5918 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
5919 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
5920 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
5921 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
5923 /* I/O memory unmap */
5924 iounmap(phba
->ctrl_regs_memmap_p
);
5925 iounmap(phba
->slim_memmap_p
);
5931 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
5932 * @phba: pointer to lpfc hba data structure.
5934 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
5935 * done and check status.
5937 * Return 0 if successful, otherwise -ENODEV.
5940 lpfc_sli4_post_status_check(struct lpfc_hba
*phba
)
5942 struct lpfc_register portsmphr_reg
, uerrlo_reg
, uerrhi_reg
;
5943 struct lpfc_register reg_data
;
5944 int i
, port_error
= 0;
5947 memset(&portsmphr_reg
, 0, sizeof(portsmphr_reg
));
5948 memset(®_data
, 0, sizeof(reg_data
));
5949 if (!phba
->sli4_hba
.PSMPHRregaddr
)
5952 /* Wait up to 30 seconds for the SLI Port POST done and ready */
5953 for (i
= 0; i
< 3000; i
++) {
5954 if (lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
5955 &portsmphr_reg
.word0
) ||
5956 (bf_get(lpfc_port_smphr_perr
, &portsmphr_reg
))) {
5957 /* Port has a fatal POST error, break out */
5958 port_error
= -ENODEV
;
5961 if (LPFC_POST_STAGE_PORT_READY
==
5962 bf_get(lpfc_port_smphr_port_status
, &portsmphr_reg
))
5968 * If there was a port error during POST, then don't proceed with
5969 * other register reads as the data may not be valid. Just exit.
5972 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5973 "1408 Port Failed POST - portsmphr=0x%x, "
5974 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
5975 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
5976 portsmphr_reg
.word0
,
5977 bf_get(lpfc_port_smphr_perr
, &portsmphr_reg
),
5978 bf_get(lpfc_port_smphr_sfi
, &portsmphr_reg
),
5979 bf_get(lpfc_port_smphr_nip
, &portsmphr_reg
),
5980 bf_get(lpfc_port_smphr_ipc
, &portsmphr_reg
),
5981 bf_get(lpfc_port_smphr_scr1
, &portsmphr_reg
),
5982 bf_get(lpfc_port_smphr_scr2
, &portsmphr_reg
),
5983 bf_get(lpfc_port_smphr_host_scratch
, &portsmphr_reg
),
5984 bf_get(lpfc_port_smphr_port_status
, &portsmphr_reg
));
5986 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5987 "2534 Device Info: SLIFamily=0x%x, "
5988 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
5989 "SLIHint_2=0x%x, FT=0x%x\n",
5990 bf_get(lpfc_sli_intf_sli_family
,
5991 &phba
->sli4_hba
.sli_intf
),
5992 bf_get(lpfc_sli_intf_slirev
,
5993 &phba
->sli4_hba
.sli_intf
),
5994 bf_get(lpfc_sli_intf_if_type
,
5995 &phba
->sli4_hba
.sli_intf
),
5996 bf_get(lpfc_sli_intf_sli_hint1
,
5997 &phba
->sli4_hba
.sli_intf
),
5998 bf_get(lpfc_sli_intf_sli_hint2
,
5999 &phba
->sli4_hba
.sli_intf
),
6000 bf_get(lpfc_sli_intf_func_type
,
6001 &phba
->sli4_hba
.sli_intf
));
6003 * Check for other Port errors during the initialization
6004 * process. Fail the load if the port did not come up
6007 if_type
= bf_get(lpfc_sli_intf_if_type
,
6008 &phba
->sli4_hba
.sli_intf
);
6010 case LPFC_SLI_INTF_IF_TYPE_0
:
6011 phba
->sli4_hba
.ue_mask_lo
=
6012 readl(phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
);
6013 phba
->sli4_hba
.ue_mask_hi
=
6014 readl(phba
->sli4_hba
.u
.if_type0
.UEMASKHIregaddr
);
6016 readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
);
6018 readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
);
6019 if ((~phba
->sli4_hba
.ue_mask_lo
& uerrlo_reg
.word0
) ||
6020 (~phba
->sli4_hba
.ue_mask_hi
& uerrhi_reg
.word0
)) {
6021 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6022 "1422 Unrecoverable Error "
6023 "Detected during POST "
6024 "uerr_lo_reg=0x%x, "
6025 "uerr_hi_reg=0x%x, "
6026 "ue_mask_lo_reg=0x%x, "
6027 "ue_mask_hi_reg=0x%x\n",
6030 phba
->sli4_hba
.ue_mask_lo
,
6031 phba
->sli4_hba
.ue_mask_hi
);
6032 port_error
= -ENODEV
;
6035 case LPFC_SLI_INTF_IF_TYPE_2
:
6036 /* Final checks. The port status should be clean. */
6037 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
6039 (bf_get(lpfc_sliport_status_err
, ®_data
) &&
6040 !bf_get(lpfc_sliport_status_rn
, ®_data
))) {
6041 phba
->work_status
[0] =
6042 readl(phba
->sli4_hba
.u
.if_type2
.
6044 phba
->work_status
[1] =
6045 readl(phba
->sli4_hba
.u
.if_type2
.
6047 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6048 "2888 Unrecoverable port error "
6049 "following POST: port status reg "
6050 "0x%x, port_smphr reg 0x%x, "
6051 "error 1=0x%x, error 2=0x%x\n",
6053 portsmphr_reg
.word0
,
6054 phba
->work_status
[0],
6055 phba
->work_status
[1]);
6056 port_error
= -ENODEV
;
6059 case LPFC_SLI_INTF_IF_TYPE_1
:
6068 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6069 * @phba: pointer to lpfc hba data structure.
6070 * @if_type: The SLI4 interface type getting configured.
6072 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6076 lpfc_sli4_bar0_register_memmap(struct lpfc_hba
*phba
, uint32_t if_type
)
6079 case LPFC_SLI_INTF_IF_TYPE_0
:
6080 phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
=
6081 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UERR_STATUS_LO
;
6082 phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
=
6083 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UERR_STATUS_HI
;
6084 phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
=
6085 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UE_MASK_LO
;
6086 phba
->sli4_hba
.u
.if_type0
.UEMASKHIregaddr
=
6087 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UE_MASK_HI
;
6088 phba
->sli4_hba
.SLIINTFregaddr
=
6089 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_SLI_INTF
;
6091 case LPFC_SLI_INTF_IF_TYPE_2
:
6092 phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
=
6093 phba
->sli4_hba
.conf_regs_memmap_p
+
6094 LPFC_CTL_PORT_ER1_OFFSET
;
6095 phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
=
6096 phba
->sli4_hba
.conf_regs_memmap_p
+
6097 LPFC_CTL_PORT_ER2_OFFSET
;
6098 phba
->sli4_hba
.u
.if_type2
.CTRLregaddr
=
6099 phba
->sli4_hba
.conf_regs_memmap_p
+
6100 LPFC_CTL_PORT_CTL_OFFSET
;
6101 phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
=
6102 phba
->sli4_hba
.conf_regs_memmap_p
+
6103 LPFC_CTL_PORT_STA_OFFSET
;
6104 phba
->sli4_hba
.SLIINTFregaddr
=
6105 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_SLI_INTF
;
6106 phba
->sli4_hba
.PSMPHRregaddr
=
6107 phba
->sli4_hba
.conf_regs_memmap_p
+
6108 LPFC_CTL_PORT_SEM_OFFSET
;
6109 phba
->sli4_hba
.RQDBregaddr
=
6110 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_RQ_DOORBELL
;
6111 phba
->sli4_hba
.WQDBregaddr
=
6112 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_WQ_DOORBELL
;
6113 phba
->sli4_hba
.EQCQDBregaddr
=
6114 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_EQCQ_DOORBELL
;
6115 phba
->sli4_hba
.MQDBregaddr
=
6116 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_MQ_DOORBELL
;
6117 phba
->sli4_hba
.BMBXregaddr
=
6118 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_BMBX
;
6120 case LPFC_SLI_INTF_IF_TYPE_1
:
6122 dev_printk(KERN_ERR
, &phba
->pcidev
->dev
,
6123 "FATAL - unsupported SLI4 interface type - %d\n",
6130 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6131 * @phba: pointer to lpfc hba data structure.
6133 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6137 lpfc_sli4_bar1_register_memmap(struct lpfc_hba
*phba
)
6139 phba
->sli4_hba
.PSMPHRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
6140 LPFC_SLIPORT_IF0_SMPHR
;
6141 phba
->sli4_hba
.ISRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
6143 phba
->sli4_hba
.IMRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
6145 phba
->sli4_hba
.ISCRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
6150 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6151 * @phba: pointer to lpfc hba data structure.
6152 * @vf: virtual function number
6154 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6155 * based on the given viftual function number, @vf.
6157 * Return 0 if successful, otherwise -ENODEV.
6160 lpfc_sli4_bar2_register_memmap(struct lpfc_hba
*phba
, uint32_t vf
)
6162 if (vf
> LPFC_VIR_FUNC_MAX
)
6165 phba
->sli4_hba
.RQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
6166 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_RQ_DOORBELL
);
6167 phba
->sli4_hba
.WQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
6168 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_WQ_DOORBELL
);
6169 phba
->sli4_hba
.EQCQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
6170 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_EQCQ_DOORBELL
);
6171 phba
->sli4_hba
.MQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
6172 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_MQ_DOORBELL
);
6173 phba
->sli4_hba
.BMBXregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
6174 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_BMBX
);
6179 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
6180 * @phba: pointer to lpfc hba data structure.
6182 * This routine is invoked to create the bootstrap mailbox
6183 * region consistent with the SLI-4 interface spec. This
6184 * routine allocates all memory necessary to communicate
6185 * mailbox commands to the port and sets up all alignment
6186 * needs. No locks are expected to be held when calling
6191 * -ENOMEM - could not allocated memory.
6194 lpfc_create_bootstrap_mbox(struct lpfc_hba
*phba
)
6197 struct lpfc_dmabuf
*dmabuf
;
6198 struct dma_address
*dma_address
;
6202 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
6207 * The bootstrap mailbox region is comprised of 2 parts
6208 * plus an alignment restriction of 16 bytes.
6210 bmbx_size
= sizeof(struct lpfc_bmbx_create
) + (LPFC_ALIGN_16_BYTE
- 1);
6211 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
6215 if (!dmabuf
->virt
) {
6219 memset(dmabuf
->virt
, 0, bmbx_size
);
6222 * Initialize the bootstrap mailbox pointers now so that the register
6223 * operations are simple later. The mailbox dma address is required
6224 * to be 16-byte aligned. Also align the virtual memory as each
6225 * maibox is copied into the bmbx mailbox region before issuing the
6226 * command to the port.
6228 phba
->sli4_hba
.bmbx
.dmabuf
= dmabuf
;
6229 phba
->sli4_hba
.bmbx
.bmbx_size
= bmbx_size
;
6231 phba
->sli4_hba
.bmbx
.avirt
= PTR_ALIGN(dmabuf
->virt
,
6232 LPFC_ALIGN_16_BYTE
);
6233 phba
->sli4_hba
.bmbx
.aphys
= ALIGN(dmabuf
->phys
,
6234 LPFC_ALIGN_16_BYTE
);
6237 * Set the high and low physical addresses now. The SLI4 alignment
6238 * requirement is 16 bytes and the mailbox is posted to the port
6239 * as two 30-bit addresses. The other data is a bit marking whether
6240 * the 30-bit address is the high or low address.
6241 * Upcast bmbx aphys to 64bits so shift instruction compiles
6242 * clean on 32 bit machines.
6244 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
6245 phys_addr
= (uint64_t)phba
->sli4_hba
.bmbx
.aphys
;
6246 pa_addr
= (uint32_t) ((phys_addr
>> 34) & 0x3fffffff);
6247 dma_address
->addr_hi
= (uint32_t) ((pa_addr
<< 2) |
6248 LPFC_BMBX_BIT1_ADDR_HI
);
6250 pa_addr
= (uint32_t) ((phba
->sli4_hba
.bmbx
.aphys
>> 4) & 0x3fffffff);
6251 dma_address
->addr_lo
= (uint32_t) ((pa_addr
<< 2) |
6252 LPFC_BMBX_BIT1_ADDR_LO
);
6257 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
6258 * @phba: pointer to lpfc hba data structure.
6260 * This routine is invoked to teardown the bootstrap mailbox
6261 * region and release all host resources. This routine requires
6262 * the caller to ensure all mailbox commands recovered, no
6263 * additional mailbox comands are sent, and interrupts are disabled
6264 * before calling this routine.
6268 lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*phba
)
6270 dma_free_coherent(&phba
->pcidev
->dev
,
6271 phba
->sli4_hba
.bmbx
.bmbx_size
,
6272 phba
->sli4_hba
.bmbx
.dmabuf
->virt
,
6273 phba
->sli4_hba
.bmbx
.dmabuf
->phys
);
6275 kfree(phba
->sli4_hba
.bmbx
.dmabuf
);
6276 memset(&phba
->sli4_hba
.bmbx
, 0, sizeof(struct lpfc_bmbx
));
6280 * lpfc_sli4_read_config - Get the config parameters.
6281 * @phba: pointer to lpfc hba data structure.
6283 * This routine is invoked to read the configuration parameters from the HBA.
6284 * The configuration parameters are used to set the base and maximum values
6285 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
6286 * allocation for the port.
6290 * -ENOMEM - No available memory
6291 * -EIO - The mailbox failed to complete successfully.
6294 lpfc_sli4_read_config(struct lpfc_hba
*phba
)
6297 struct lpfc_mbx_read_config
*rd_config
;
6298 union lpfc_sli4_cfg_shdr
*shdr
;
6299 uint32_t shdr_status
, shdr_add_status
;
6300 struct lpfc_mbx_get_func_cfg
*get_func_cfg
;
6301 struct lpfc_rsrc_desc_fcfcoe
*desc
;
6302 uint32_t desc_count
;
6303 int length
, i
, rc
= 0;
6305 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6307 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6308 "2011 Unable to allocate memory for issuing "
6309 "SLI_CONFIG_SPECIAL mailbox command\n");
6313 lpfc_read_config(phba
, pmb
);
6315 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
6316 if (rc
!= MBX_SUCCESS
) {
6317 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6318 "2012 Mailbox failed , mbxCmd x%x "
6319 "READ_CONFIG, mbxStatus x%x\n",
6320 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
6321 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
6324 rd_config
= &pmb
->u
.mqe
.un
.rd_config
;
6325 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv
, rd_config
)) {
6326 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
6327 phba
->sli4_hba
.lnk_info
.lnk_tp
=
6328 bf_get(lpfc_mbx_rd_conf_lnk_type
, rd_config
);
6329 phba
->sli4_hba
.lnk_info
.lnk_no
=
6330 bf_get(lpfc_mbx_rd_conf_lnk_numb
, rd_config
);
6331 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
6332 "3081 lnk_type:%d, lnk_numb:%d\n",
6333 phba
->sli4_hba
.lnk_info
.lnk_tp
,
6334 phba
->sli4_hba
.lnk_info
.lnk_no
);
6336 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
6337 "3082 Mailbox (x%x) returned ldv:x0\n",
6338 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
));
6339 phba
->sli4_hba
.extents_in_use
=
6340 bf_get(lpfc_mbx_rd_conf_extnts_inuse
, rd_config
);
6341 phba
->sli4_hba
.max_cfg_param
.max_xri
=
6342 bf_get(lpfc_mbx_rd_conf_xri_count
, rd_config
);
6343 phba
->sli4_hba
.max_cfg_param
.xri_base
=
6344 bf_get(lpfc_mbx_rd_conf_xri_base
, rd_config
);
6345 phba
->sli4_hba
.max_cfg_param
.max_vpi
=
6346 bf_get(lpfc_mbx_rd_conf_vpi_count
, rd_config
);
6347 phba
->sli4_hba
.max_cfg_param
.vpi_base
=
6348 bf_get(lpfc_mbx_rd_conf_vpi_base
, rd_config
);
6349 phba
->sli4_hba
.max_cfg_param
.max_rpi
=
6350 bf_get(lpfc_mbx_rd_conf_rpi_count
, rd_config
);
6351 phba
->sli4_hba
.max_cfg_param
.rpi_base
=
6352 bf_get(lpfc_mbx_rd_conf_rpi_base
, rd_config
);
6353 phba
->sli4_hba
.max_cfg_param
.max_vfi
=
6354 bf_get(lpfc_mbx_rd_conf_vfi_count
, rd_config
);
6355 phba
->sli4_hba
.max_cfg_param
.vfi_base
=
6356 bf_get(lpfc_mbx_rd_conf_vfi_base
, rd_config
);
6357 phba
->sli4_hba
.max_cfg_param
.max_fcfi
=
6358 bf_get(lpfc_mbx_rd_conf_fcfi_count
, rd_config
);
6359 phba
->sli4_hba
.max_cfg_param
.max_eq
=
6360 bf_get(lpfc_mbx_rd_conf_eq_count
, rd_config
);
6361 phba
->sli4_hba
.max_cfg_param
.max_rq
=
6362 bf_get(lpfc_mbx_rd_conf_rq_count
, rd_config
);
6363 phba
->sli4_hba
.max_cfg_param
.max_wq
=
6364 bf_get(lpfc_mbx_rd_conf_wq_count
, rd_config
);
6365 phba
->sli4_hba
.max_cfg_param
.max_cq
=
6366 bf_get(lpfc_mbx_rd_conf_cq_count
, rd_config
);
6367 phba
->lmt
= bf_get(lpfc_mbx_rd_conf_lmt
, rd_config
);
6368 phba
->sli4_hba
.next_xri
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
6369 phba
->vpi_base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
6370 phba
->vfi_base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
6371 phba
->max_vpi
= (phba
->sli4_hba
.max_cfg_param
.max_vpi
> 0) ?
6372 (phba
->sli4_hba
.max_cfg_param
.max_vpi
- 1) : 0;
6373 phba
->max_vports
= phba
->max_vpi
;
6374 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
6375 "2003 cfg params Extents? %d "
6381 phba
->sli4_hba
.extents_in_use
,
6382 phba
->sli4_hba
.max_cfg_param
.xri_base
,
6383 phba
->sli4_hba
.max_cfg_param
.max_xri
,
6384 phba
->sli4_hba
.max_cfg_param
.vpi_base
,
6385 phba
->sli4_hba
.max_cfg_param
.max_vpi
,
6386 phba
->sli4_hba
.max_cfg_param
.vfi_base
,
6387 phba
->sli4_hba
.max_cfg_param
.max_vfi
,
6388 phba
->sli4_hba
.max_cfg_param
.rpi_base
,
6389 phba
->sli4_hba
.max_cfg_param
.max_rpi
,
6390 phba
->sli4_hba
.max_cfg_param
.max_fcfi
);
6396 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
6397 if (phba
->cfg_hba_queue_depth
>
6398 (phba
->sli4_hba
.max_cfg_param
.max_xri
-
6399 lpfc_sli4_get_els_iocb_cnt(phba
)))
6400 phba
->cfg_hba_queue_depth
=
6401 phba
->sli4_hba
.max_cfg_param
.max_xri
-
6402 lpfc_sli4_get_els_iocb_cnt(phba
);
6404 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
6405 LPFC_SLI_INTF_IF_TYPE_2
)
6408 /* get the pf# and vf# for SLI4 if_type 2 port */
6409 length
= (sizeof(struct lpfc_mbx_get_func_cfg
) -
6410 sizeof(struct lpfc_sli4_cfg_mhdr
));
6411 lpfc_sli4_config(phba
, pmb
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6412 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG
,
6413 length
, LPFC_SLI4_MBX_EMBED
);
6415 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
6416 shdr
= (union lpfc_sli4_cfg_shdr
*)
6417 &pmb
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
6418 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
6419 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
6420 if (rc
|| shdr_status
|| shdr_add_status
) {
6421 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6422 "3026 Mailbox failed , mbxCmd x%x "
6423 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
6424 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
6425 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
6430 /* search for fc_fcoe resrouce descriptor */
6431 get_func_cfg
= &pmb
->u
.mqe
.un
.get_func_cfg
;
6432 desc_count
= get_func_cfg
->func_cfg
.rsrc_desc_count
;
6434 for (i
= 0; i
< LPFC_RSRC_DESC_MAX_NUM
; i
++) {
6435 desc
= (struct lpfc_rsrc_desc_fcfcoe
*)
6436 &get_func_cfg
->func_cfg
.desc
[i
];
6437 if (LPFC_RSRC_DESC_TYPE_FCFCOE
==
6438 bf_get(lpfc_rsrc_desc_pcie_type
, desc
)) {
6439 phba
->sli4_hba
.iov
.pf_number
=
6440 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum
, desc
);
6441 phba
->sli4_hba
.iov
.vf_number
=
6442 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum
, desc
);
6447 if (i
< LPFC_RSRC_DESC_MAX_NUM
)
6448 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
6449 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
6450 "vf_number:%d\n", phba
->sli4_hba
.iov
.pf_number
,
6451 phba
->sli4_hba
.iov
.vf_number
);
6453 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6454 "3028 GET_FUNCTION_CONFIG: failed to find "
6455 "Resrouce Descriptor:x%x\n",
6456 LPFC_RSRC_DESC_TYPE_FCFCOE
);
6461 mempool_free(pmb
, phba
->mbox_mem_pool
);
6466 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
6467 * @phba: pointer to lpfc hba data structure.
6469 * This routine is invoked to setup the port-side endian order when
6470 * the port if_type is 0. This routine has no function for other
6475 * -ENOMEM - No available memory
6476 * -EIO - The mailbox failed to complete successfully.
6479 lpfc_setup_endian_order(struct lpfc_hba
*phba
)
6481 LPFC_MBOXQ_t
*mboxq
;
6482 uint32_t if_type
, rc
= 0;
6483 uint32_t endian_mb_data
[2] = {HOST_ENDIAN_LOW_WORD0
,
6484 HOST_ENDIAN_HIGH_WORD1
};
6486 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
6488 case LPFC_SLI_INTF_IF_TYPE_0
:
6489 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
6492 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6493 "0492 Unable to allocate memory for "
6494 "issuing SLI_CONFIG_SPECIAL mailbox "
6500 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
6501 * two words to contain special data values and no other data.
6503 memset(mboxq
, 0, sizeof(LPFC_MBOXQ_t
));
6504 memcpy(&mboxq
->u
.mqe
, &endian_mb_data
, sizeof(endian_mb_data
));
6505 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6506 if (rc
!= MBX_SUCCESS
) {
6507 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6508 "0493 SLI_CONFIG_SPECIAL mailbox "
6509 "failed with status x%x\n",
6513 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6515 case LPFC_SLI_INTF_IF_TYPE_2
:
6516 case LPFC_SLI_INTF_IF_TYPE_1
:
6524 * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
6525 * @phba: pointer to lpfc hba data structure.
6527 * This routine is invoked to check the user settable queue counts for EQs and
6528 * CQs. after this routine is called the counts will be set to valid values that
6529 * adhere to the constraints of the system's interrupt vectors and the port's
6534 * -ENOMEM - No available memory
6537 lpfc_sli4_queue_verify(struct lpfc_hba
*phba
)
6539 int cfg_fcp_io_channel
;
6542 * Sanity check for configured queue parameters against the run-time
6546 /* Sanity check on HBA EQ parameters */
6547 cfg_fcp_io_channel
= phba
->cfg_fcp_io_channel
;
6549 if (cfg_fcp_io_channel
>
6550 phba
->sli4_hba
.max_cfg_param
.max_eq
) {
6551 cfg_fcp_io_channel
= phba
->sli4_hba
.max_cfg_param
.max_eq
;
6552 if (cfg_fcp_io_channel
< LPFC_FCP_IO_CHAN_MIN
) {
6553 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6554 "2574 Not enough EQs (%d) from the "
6555 "pci function for supporting FCP "
6557 phba
->sli4_hba
.max_cfg_param
.max_eq
,
6558 phba
->cfg_fcp_io_channel
);
6561 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
6562 "2575 Not enough EQs (%d) from the pci "
6563 "function for supporting the requested "
6564 "FCP EQs (%d), the actual FCP EQs can "
6565 "be supported: %d\n",
6566 phba
->sli4_hba
.max_cfg_param
.max_eq
,
6567 phba
->cfg_fcp_io_channel
, cfg_fcp_io_channel
);
6570 /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */
6572 /* The actual number of FCP event queues adopted */
6573 phba
->cfg_fcp_eq_count
= cfg_fcp_io_channel
;
6574 phba
->cfg_fcp_wq_count
= cfg_fcp_io_channel
;
6575 phba
->cfg_fcp_io_channel
= cfg_fcp_io_channel
;
6576 phba
->sli4_hba
.cfg_eqn
= cfg_fcp_io_channel
;
6578 /* Get EQ depth from module parameter, fake the default for now */
6579 phba
->sli4_hba
.eq_esize
= LPFC_EQE_SIZE_4B
;
6580 phba
->sli4_hba
.eq_ecount
= LPFC_EQE_DEF_COUNT
;
6582 /* Get CQ depth from module parameter, fake the default for now */
6583 phba
->sli4_hba
.cq_esize
= LPFC_CQE_SIZE
;
6584 phba
->sli4_hba
.cq_ecount
= LPFC_CQE_DEF_COUNT
;
6592 * lpfc_sli4_queue_create - Create all the SLI4 queues
6593 * @phba: pointer to lpfc hba data structure.
6595 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
6596 * operation. For each SLI4 queue type, the parameters such as queue entry
6597 * count (queue depth) shall be taken from the module parameter. For now,
6598 * we just use some constant number as place holder.
6602 * -ENOMEM - No availble memory
6603 * -EIO - The mailbox failed to complete successfully.
6606 lpfc_sli4_queue_create(struct lpfc_hba
*phba
)
6608 struct lpfc_queue
*qdesc
;
6612 * Create HBA Record arrays.
6614 if (!phba
->cfg_fcp_io_channel
)
6617 phba
->sli4_hba
.mq_esize
= LPFC_MQE_SIZE
;
6618 phba
->sli4_hba
.mq_ecount
= LPFC_MQE_DEF_COUNT
;
6619 phba
->sli4_hba
.wq_esize
= LPFC_WQE_SIZE
;
6620 phba
->sli4_hba
.wq_ecount
= LPFC_WQE_DEF_COUNT
;
6621 phba
->sli4_hba
.rq_esize
= LPFC_RQE_SIZE
;
6622 phba
->sli4_hba
.rq_ecount
= LPFC_RQE_DEF_COUNT
;
6624 phba
->sli4_hba
.hba_eq
= kzalloc((sizeof(struct lpfc_queue
*) *
6625 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
6626 if (!phba
->sli4_hba
.hba_eq
) {
6627 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6628 "2576 Failed allocate memory for "
6629 "fast-path EQ record array\n");
6633 phba
->sli4_hba
.fcp_cq
= kzalloc((sizeof(struct lpfc_queue
*) *
6634 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
6635 if (!phba
->sli4_hba
.fcp_cq
) {
6636 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6637 "2577 Failed allocate memory for fast-path "
6638 "CQ record array\n");
6642 phba
->sli4_hba
.fcp_wq
= kzalloc((sizeof(struct lpfc_queue
*) *
6643 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
6644 if (!phba
->sli4_hba
.fcp_wq
) {
6645 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6646 "2578 Failed allocate memory for fast-path "
6647 "WQ record array\n");
6652 * Since the first EQ can have multiple CQs associated with it,
6653 * this array is used to quickly see if we have a FCP fast-path
6656 phba
->sli4_hba
.fcp_cq_map
= kzalloc((sizeof(uint16_t) *
6657 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
6658 if (!phba
->sli4_hba
.fcp_cq_map
) {
6659 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6660 "2545 Failed allocate memory for fast-path "
6666 * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
6667 * how many EQs to create.
6669 for (idx
= 0; idx
< phba
->cfg_fcp_io_channel
; idx
++) {
6672 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.eq_esize
,
6673 phba
->sli4_hba
.eq_ecount
);
6675 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6676 "0497 Failed allocate EQ (%d)\n", idx
);
6679 phba
->sli4_hba
.hba_eq
[idx
] = qdesc
;
6681 /* Create Fast Path FCP CQs */
6682 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
6683 phba
->sli4_hba
.cq_ecount
);
6685 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6686 "0499 Failed allocate fast-path FCP "
6690 phba
->sli4_hba
.fcp_cq
[idx
] = qdesc
;
6692 /* Create Fast Path FCP WQs */
6693 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
6694 phba
->sli4_hba
.wq_ecount
);
6696 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6697 "0503 Failed allocate fast-path FCP "
6701 phba
->sli4_hba
.fcp_wq
[idx
] = qdesc
;
6706 * Create Slow Path Completion Queues (CQs)
6709 /* Create slow-path Mailbox Command Complete Queue */
6710 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
6711 phba
->sli4_hba
.cq_ecount
);
6713 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6714 "0500 Failed allocate slow-path mailbox CQ\n");
6717 phba
->sli4_hba
.mbx_cq
= qdesc
;
6719 /* Create slow-path ELS Complete Queue */
6720 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
6721 phba
->sli4_hba
.cq_ecount
);
6723 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6724 "0501 Failed allocate slow-path ELS CQ\n");
6727 phba
->sli4_hba
.els_cq
= qdesc
;
6731 * Create Slow Path Work Queues (WQs)
6734 /* Create Mailbox Command Queue */
6736 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.mq_esize
,
6737 phba
->sli4_hba
.mq_ecount
);
6739 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6740 "0505 Failed allocate slow-path MQ\n");
6743 phba
->sli4_hba
.mbx_wq
= qdesc
;
6746 * Create ELS Work Queues
6749 /* Create slow-path ELS Work Queue */
6750 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
6751 phba
->sli4_hba
.wq_ecount
);
6753 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6754 "0504 Failed allocate slow-path ELS WQ\n");
6757 phba
->sli4_hba
.els_wq
= qdesc
;
6760 * Create Receive Queue (RQ)
6763 /* Create Receive Queue for header */
6764 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
6765 phba
->sli4_hba
.rq_ecount
);
6767 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6768 "0506 Failed allocate receive HRQ\n");
6771 phba
->sli4_hba
.hdr_rq
= qdesc
;
6773 /* Create Receive Queue for data */
6774 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
6775 phba
->sli4_hba
.rq_ecount
);
6777 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6778 "0507 Failed allocate receive DRQ\n");
6781 phba
->sli4_hba
.dat_rq
= qdesc
;
6786 lpfc_sli4_queue_destroy(phba
);
6791 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
6792 * @phba: pointer to lpfc hba data structure.
6794 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
6799 * -ENOMEM - No available memory
6800 * -EIO - The mailbox failed to complete successfully.
6803 lpfc_sli4_queue_destroy(struct lpfc_hba
*phba
)
6807 if (phba
->sli4_hba
.hba_eq
!= NULL
) {
6808 /* Release HBA event queue */
6809 for (idx
= 0; idx
< phba
->cfg_fcp_io_channel
; idx
++) {
6810 if (phba
->sli4_hba
.hba_eq
[idx
] != NULL
) {
6811 lpfc_sli4_queue_free(
6812 phba
->sli4_hba
.hba_eq
[idx
]);
6813 phba
->sli4_hba
.hba_eq
[idx
] = NULL
;
6816 kfree(phba
->sli4_hba
.hba_eq
);
6817 phba
->sli4_hba
.hba_eq
= NULL
;
6820 if (phba
->sli4_hba
.fcp_cq
!= NULL
) {
6821 /* Release FCP completion queue */
6822 for (idx
= 0; idx
< phba
->cfg_fcp_io_channel
; idx
++) {
6823 if (phba
->sli4_hba
.fcp_cq
[idx
] != NULL
) {
6824 lpfc_sli4_queue_free(
6825 phba
->sli4_hba
.fcp_cq
[idx
]);
6826 phba
->sli4_hba
.fcp_cq
[idx
] = NULL
;
6829 kfree(phba
->sli4_hba
.fcp_cq
);
6830 phba
->sli4_hba
.fcp_cq
= NULL
;
6833 if (phba
->sli4_hba
.fcp_wq
!= NULL
) {
6834 /* Release FCP work queue */
6835 for (idx
= 0; idx
< phba
->cfg_fcp_io_channel
; idx
++) {
6836 if (phba
->sli4_hba
.fcp_wq
[idx
] != NULL
) {
6837 lpfc_sli4_queue_free(
6838 phba
->sli4_hba
.fcp_wq
[idx
]);
6839 phba
->sli4_hba
.fcp_wq
[idx
] = NULL
;
6842 kfree(phba
->sli4_hba
.fcp_wq
);
6843 phba
->sli4_hba
.fcp_wq
= NULL
;
6846 /* Release FCP CQ mapping array */
6847 if (phba
->sli4_hba
.fcp_cq_map
!= NULL
) {
6848 kfree(phba
->sli4_hba
.fcp_cq_map
);
6849 phba
->sli4_hba
.fcp_cq_map
= NULL
;
6852 /* Release mailbox command work queue */
6853 if (phba
->sli4_hba
.mbx_wq
!= NULL
) {
6854 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_wq
);
6855 phba
->sli4_hba
.mbx_wq
= NULL
;
6858 /* Release ELS work queue */
6859 if (phba
->sli4_hba
.els_wq
!= NULL
) {
6860 lpfc_sli4_queue_free(phba
->sli4_hba
.els_wq
);
6861 phba
->sli4_hba
.els_wq
= NULL
;
6864 /* Release unsolicited receive queue */
6865 if (phba
->sli4_hba
.hdr_rq
!= NULL
) {
6866 lpfc_sli4_queue_free(phba
->sli4_hba
.hdr_rq
);
6867 phba
->sli4_hba
.hdr_rq
= NULL
;
6869 if (phba
->sli4_hba
.dat_rq
!= NULL
) {
6870 lpfc_sli4_queue_free(phba
->sli4_hba
.dat_rq
);
6871 phba
->sli4_hba
.dat_rq
= NULL
;
6874 /* Release ELS complete queue */
6875 if (phba
->sli4_hba
.els_cq
!= NULL
) {
6876 lpfc_sli4_queue_free(phba
->sli4_hba
.els_cq
);
6877 phba
->sli4_hba
.els_cq
= NULL
;
6880 /* Release mailbox command complete queue */
6881 if (phba
->sli4_hba
.mbx_cq
!= NULL
) {
6882 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_cq
);
6883 phba
->sli4_hba
.mbx_cq
= NULL
;
6890 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
6891 * @phba: pointer to lpfc hba data structure.
6893 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
6898 * -ENOMEM - No available memory
6899 * -EIO - The mailbox failed to complete successfully.
6902 lpfc_sli4_queue_setup(struct lpfc_hba
*phba
)
6904 struct lpfc_sli
*psli
= &phba
->sli
;
6905 struct lpfc_sli_ring
*pring
;
6907 int fcp_eqidx
, fcp_cqidx
, fcp_wqidx
;
6908 int fcp_cq_index
= 0;
6911 * Set up HBA Event Queues (EQs)
6914 /* Set up HBA event queue */
6915 if (phba
->cfg_fcp_io_channel
&& !phba
->sli4_hba
.hba_eq
) {
6916 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6917 "3147 Fast-path EQs not allocated\n");
6921 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_io_channel
; fcp_eqidx
++) {
6922 if (!phba
->sli4_hba
.hba_eq
[fcp_eqidx
]) {
6923 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6924 "0522 Fast-path EQ (%d) not "
6925 "allocated\n", fcp_eqidx
);
6927 goto out_destroy_hba_eq
;
6929 rc
= lpfc_eq_create(phba
, phba
->sli4_hba
.hba_eq
[fcp_eqidx
],
6930 (phba
->cfg_fcp_imax
/ phba
->cfg_fcp_io_channel
));
6932 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6933 "0523 Failed setup of fast-path EQ "
6934 "(%d), rc = 0x%x\n", fcp_eqidx
, rc
);
6935 goto out_destroy_hba_eq
;
6937 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6938 "2584 HBA EQ setup: "
6939 "queue[%d]-id=%d\n", fcp_eqidx
,
6940 phba
->sli4_hba
.hba_eq
[fcp_eqidx
]->queue_id
);
6943 /* Set up fast-path FCP Response Complete Queue */
6944 if (!phba
->sli4_hba
.fcp_cq
) {
6945 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6946 "3148 Fast-path FCP CQ array not "
6949 goto out_destroy_hba_eq
;
6952 for (fcp_cqidx
= 0; fcp_cqidx
< phba
->cfg_fcp_io_channel
; fcp_cqidx
++) {
6953 if (!phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]) {
6954 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6955 "0526 Fast-path FCP CQ (%d) not "
6956 "allocated\n", fcp_cqidx
);
6958 goto out_destroy_fcp_cq
;
6960 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.fcp_cq
[fcp_cqidx
],
6961 phba
->sli4_hba
.hba_eq
[fcp_cqidx
], LPFC_WCQ
, LPFC_FCP
);
6963 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6964 "0527 Failed setup of fast-path FCP "
6965 "CQ (%d), rc = 0x%x\n", fcp_cqidx
, rc
);
6966 goto out_destroy_fcp_cq
;
6969 /* Setup fcp_cq_map for fast lookup */
6970 phba
->sli4_hba
.fcp_cq_map
[fcp_cqidx
] =
6971 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]->queue_id
;
6973 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6974 "2588 FCP CQ setup: cq[%d]-id=%d, "
6975 "parent seq[%d]-id=%d\n",
6977 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]->queue_id
,
6979 phba
->sli4_hba
.hba_eq
[fcp_cqidx
]->queue_id
);
6982 /* Set up fast-path FCP Work Queue */
6983 if (!phba
->sli4_hba
.fcp_wq
) {
6984 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6985 "3149 Fast-path FCP WQ array not "
6988 goto out_destroy_fcp_cq
;
6991 for (fcp_wqidx
= 0; fcp_wqidx
< phba
->cfg_fcp_io_channel
; fcp_wqidx
++) {
6992 if (!phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]) {
6993 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6994 "0534 Fast-path FCP WQ (%d) not "
6995 "allocated\n", fcp_wqidx
);
6997 goto out_destroy_fcp_wq
;
6999 rc
= lpfc_wq_create(phba
, phba
->sli4_hba
.fcp_wq
[fcp_wqidx
],
7000 phba
->sli4_hba
.fcp_cq
[fcp_wqidx
],
7003 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7004 "0535 Failed setup of fast-path FCP "
7005 "WQ (%d), rc = 0x%x\n", fcp_wqidx
, rc
);
7006 goto out_destroy_fcp_wq
;
7009 /* Bind this WQ to the next FCP ring */
7010 pring
= &psli
->ring
[MAX_SLI3_CONFIGURED_RINGS
+ fcp_wqidx
];
7011 pring
->sli
.sli4
.wqp
= (void *)phba
->sli4_hba
.fcp_wq
[fcp_wqidx
];
7012 phba
->sli4_hba
.fcp_cq
[fcp_wqidx
]->pring
= pring
;
7014 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7015 "2591 FCP WQ setup: wq[%d]-id=%d, "
7016 "parent cq[%d]-id=%d\n",
7018 phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]->queue_id
,
7020 phba
->sli4_hba
.fcp_cq
[fcp_wqidx
]->queue_id
);
7023 * Set up Complete Queues (CQs)
7026 /* Set up slow-path MBOX Complete Queue as the first CQ */
7027 if (!phba
->sli4_hba
.mbx_cq
) {
7028 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7029 "0528 Mailbox CQ not allocated\n");
7031 goto out_destroy_fcp_wq
;
7033 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.mbx_cq
,
7034 phba
->sli4_hba
.hba_eq
[0], LPFC_MCQ
, LPFC_MBOX
);
7036 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7037 "0529 Failed setup of slow-path mailbox CQ: "
7039 goto out_destroy_fcp_wq
;
7041 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7042 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
7043 phba
->sli4_hba
.mbx_cq
->queue_id
,
7044 phba
->sli4_hba
.hba_eq
[0]->queue_id
);
7046 /* Set up slow-path ELS Complete Queue */
7047 if (!phba
->sli4_hba
.els_cq
) {
7048 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7049 "0530 ELS CQ not allocated\n");
7051 goto out_destroy_mbx_cq
;
7053 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.els_cq
,
7054 phba
->sli4_hba
.hba_eq
[0], LPFC_WCQ
, LPFC_ELS
);
7056 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7057 "0531 Failed setup of slow-path ELS CQ: "
7059 goto out_destroy_mbx_cq
;
7061 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7062 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
7063 phba
->sli4_hba
.els_cq
->queue_id
,
7064 phba
->sli4_hba
.hba_eq
[0]->queue_id
);
7067 * Set up all the Work Queues (WQs)
7070 /* Set up Mailbox Command Queue */
7071 if (!phba
->sli4_hba
.mbx_wq
) {
7072 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7073 "0538 Slow-path MQ not allocated\n");
7075 goto out_destroy_els_cq
;
7077 rc
= lpfc_mq_create(phba
, phba
->sli4_hba
.mbx_wq
,
7078 phba
->sli4_hba
.mbx_cq
, LPFC_MBOX
);
7080 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7081 "0539 Failed setup of slow-path MQ: "
7083 goto out_destroy_els_cq
;
7085 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7086 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
7087 phba
->sli4_hba
.mbx_wq
->queue_id
,
7088 phba
->sli4_hba
.mbx_cq
->queue_id
);
7090 /* Set up slow-path ELS Work Queue */
7091 if (!phba
->sli4_hba
.els_wq
) {
7092 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7093 "0536 Slow-path ELS WQ not allocated\n");
7095 goto out_destroy_mbx_wq
;
7097 rc
= lpfc_wq_create(phba
, phba
->sli4_hba
.els_wq
,
7098 phba
->sli4_hba
.els_cq
, LPFC_ELS
);
7100 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7101 "0537 Failed setup of slow-path ELS WQ: "
7103 goto out_destroy_mbx_wq
;
7106 /* Bind this WQ to the ELS ring */
7107 pring
= &psli
->ring
[LPFC_ELS_RING
];
7108 pring
->sli
.sli4
.wqp
= (void *)phba
->sli4_hba
.els_wq
;
7109 phba
->sli4_hba
.els_cq
->pring
= pring
;
7111 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7112 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
7113 phba
->sli4_hba
.els_wq
->queue_id
,
7114 phba
->sli4_hba
.els_cq
->queue_id
);
7117 * Create Receive Queue (RQ)
7119 if (!phba
->sli4_hba
.hdr_rq
|| !phba
->sli4_hba
.dat_rq
) {
7120 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7121 "0540 Receive Queue not allocated\n");
7123 goto out_destroy_els_wq
;
7126 lpfc_rq_adjust_repost(phba
, phba
->sli4_hba
.hdr_rq
, LPFC_ELS_HBQ
);
7127 lpfc_rq_adjust_repost(phba
, phba
->sli4_hba
.dat_rq
, LPFC_ELS_HBQ
);
7129 rc
= lpfc_rq_create(phba
, phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
7130 phba
->sli4_hba
.els_cq
, LPFC_USOL
);
7132 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7133 "0541 Failed setup of Receive Queue: "
7135 goto out_destroy_fcp_wq
;
7138 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7139 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
7140 "parent cq-id=%d\n",
7141 phba
->sli4_hba
.hdr_rq
->queue_id
,
7142 phba
->sli4_hba
.dat_rq
->queue_id
,
7143 phba
->sli4_hba
.els_cq
->queue_id
);
7147 lpfc_wq_destroy(phba
, phba
->sli4_hba
.els_wq
);
7149 lpfc_mq_destroy(phba
, phba
->sli4_hba
.mbx_wq
);
7151 lpfc_cq_destroy(phba
, phba
->sli4_hba
.els_cq
);
7153 lpfc_cq_destroy(phba
, phba
->sli4_hba
.mbx_cq
);
7155 for (--fcp_wqidx
; fcp_wqidx
>= 0; fcp_wqidx
--)
7156 lpfc_wq_destroy(phba
, phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]);
7158 for (--fcp_cqidx
; fcp_cqidx
>= 0; fcp_cqidx
--)
7159 lpfc_cq_destroy(phba
, phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]);
7161 for (--fcp_eqidx
; fcp_eqidx
>= 0; fcp_eqidx
--)
7162 lpfc_eq_destroy(phba
, phba
->sli4_hba
.hba_eq
[fcp_eqidx
]);
7168 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
7169 * @phba: pointer to lpfc hba data structure.
7171 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
7176 * -ENOMEM - No available memory
7177 * -EIO - The mailbox failed to complete successfully.
7180 lpfc_sli4_queue_unset(struct lpfc_hba
*phba
)
7184 /* Unset mailbox command work queue */
7185 lpfc_mq_destroy(phba
, phba
->sli4_hba
.mbx_wq
);
7186 /* Unset ELS work queue */
7187 lpfc_wq_destroy(phba
, phba
->sli4_hba
.els_wq
);
7188 /* Unset unsolicited receive queue */
7189 lpfc_rq_destroy(phba
, phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
);
7190 /* Unset FCP work queue */
7191 if (phba
->sli4_hba
.fcp_wq
) {
7192 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_io_channel
;
7194 lpfc_wq_destroy(phba
, phba
->sli4_hba
.fcp_wq
[fcp_qidx
]);
7196 /* Unset mailbox command complete queue */
7197 lpfc_cq_destroy(phba
, phba
->sli4_hba
.mbx_cq
);
7198 /* Unset ELS complete queue */
7199 lpfc_cq_destroy(phba
, phba
->sli4_hba
.els_cq
);
7200 /* Unset FCP response complete queue */
7201 if (phba
->sli4_hba
.fcp_cq
) {
7202 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_io_channel
;
7204 lpfc_cq_destroy(phba
, phba
->sli4_hba
.fcp_cq
[fcp_qidx
]);
7206 /* Unset fast-path event queue */
7207 if (phba
->sli4_hba
.hba_eq
) {
7208 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_io_channel
;
7210 lpfc_eq_destroy(phba
, phba
->sli4_hba
.hba_eq
[fcp_qidx
]);
7215 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
7216 * @phba: pointer to lpfc hba data structure.
7218 * This routine is invoked to allocate and set up a pool of completion queue
7219 * events. The body of the completion queue event is a completion queue entry
7220 * CQE. For now, this pool is used for the interrupt service routine to queue
7221 * the following HBA completion queue events for the worker thread to process:
7222 * - Mailbox asynchronous events
7223 * - Receive queue completion unsolicited events
7224 * Later, this can be used for all the slow-path events.
7228 * -ENOMEM - No available memory
7231 lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*phba
)
7233 struct lpfc_cq_event
*cq_event
;
7236 for (i
= 0; i
< (4 * phba
->sli4_hba
.cq_ecount
); i
++) {
7237 cq_event
= kmalloc(sizeof(struct lpfc_cq_event
), GFP_KERNEL
);
7239 goto out_pool_create_fail
;
7240 list_add_tail(&cq_event
->list
,
7241 &phba
->sli4_hba
.sp_cqe_event_pool
);
7245 out_pool_create_fail
:
7246 lpfc_sli4_cq_event_pool_destroy(phba
);
7251 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
7252 * @phba: pointer to lpfc hba data structure.
7254 * This routine is invoked to free the pool of completion queue events at
7255 * driver unload time. Note that, it is the responsibility of the driver
7256 * cleanup routine to free all the outstanding completion-queue events
7257 * allocated from this pool back into the pool before invoking this routine
7258 * to destroy the pool.
7261 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*phba
)
7263 struct lpfc_cq_event
*cq_event
, *next_cq_event
;
7265 list_for_each_entry_safe(cq_event
, next_cq_event
,
7266 &phba
->sli4_hba
.sp_cqe_event_pool
, list
) {
7267 list_del(&cq_event
->list
);
7273 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7274 * @phba: pointer to lpfc hba data structure.
7276 * This routine is the lock free version of the API invoked to allocate a
7277 * completion-queue event from the free pool.
7279 * Return: Pointer to the newly allocated completion-queue event if successful
7282 struct lpfc_cq_event
*
7283 __lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
7285 struct lpfc_cq_event
*cq_event
= NULL
;
7287 list_remove_head(&phba
->sli4_hba
.sp_cqe_event_pool
, cq_event
,
7288 struct lpfc_cq_event
, list
);
7293 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7294 * @phba: pointer to lpfc hba data structure.
7296 * This routine is the lock version of the API invoked to allocate a
7297 * completion-queue event from the free pool.
7299 * Return: Pointer to the newly allocated completion-queue event if successful
7302 struct lpfc_cq_event
*
7303 lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
7305 struct lpfc_cq_event
*cq_event
;
7306 unsigned long iflags
;
7308 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7309 cq_event
= __lpfc_sli4_cq_event_alloc(phba
);
7310 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7315 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7316 * @phba: pointer to lpfc hba data structure.
7317 * @cq_event: pointer to the completion queue event to be freed.
7319 * This routine is the lock free version of the API invoked to release a
7320 * completion-queue event back into the free pool.
7323 __lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
7324 struct lpfc_cq_event
*cq_event
)
7326 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_cqe_event_pool
);
7330 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7331 * @phba: pointer to lpfc hba data structure.
7332 * @cq_event: pointer to the completion queue event to be freed.
7334 * This routine is the lock version of the API invoked to release a
7335 * completion-queue event back into the free pool.
7338 lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
7339 struct lpfc_cq_event
*cq_event
)
7341 unsigned long iflags
;
7342 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7343 __lpfc_sli4_cq_event_release(phba
, cq_event
);
7344 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7348 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
7349 * @phba: pointer to lpfc hba data structure.
7351 * This routine is to free all the pending completion-queue events to the
7352 * back into the free pool for device reset.
7355 lpfc_sli4_cq_event_release_all(struct lpfc_hba
*phba
)
7358 struct lpfc_cq_event
*cqe
;
7359 unsigned long iflags
;
7361 /* Retrieve all the pending WCQEs from pending WCQE lists */
7362 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7363 /* Pending FCP XRI abort events */
7364 list_splice_init(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
7366 /* Pending ELS XRI abort events */
7367 list_splice_init(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
7369 /* Pending asynnc events */
7370 list_splice_init(&phba
->sli4_hba
.sp_asynce_work_queue
,
7372 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7374 while (!list_empty(&cqelist
)) {
7375 list_remove_head(&cqelist
, cqe
, struct lpfc_cq_event
, list
);
7376 lpfc_sli4_cq_event_release(phba
, cqe
);
7381 * lpfc_pci_function_reset - Reset pci function.
7382 * @phba: pointer to lpfc hba data structure.
7384 * This routine is invoked to request a PCI function reset. It will destroys
7385 * all resources assigned to the PCI function which originates this request.
7389 * -ENOMEM - No available memory
7390 * -EIO - The mailbox failed to complete successfully.
7393 lpfc_pci_function_reset(struct lpfc_hba
*phba
)
7395 LPFC_MBOXQ_t
*mboxq
;
7396 uint32_t rc
= 0, if_type
;
7397 uint32_t shdr_status
, shdr_add_status
;
7398 uint32_t rdy_chk
, num_resets
= 0, reset_again
= 0;
7399 union lpfc_sli4_cfg_shdr
*shdr
;
7400 struct lpfc_register reg_data
;
7403 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
7405 case LPFC_SLI_INTF_IF_TYPE_0
:
7406 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
7409 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7410 "0494 Unable to allocate memory for "
7411 "issuing SLI_FUNCTION_RESET mailbox "
7416 /* Setup PCI function reset mailbox-ioctl command */
7417 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
7418 LPFC_MBOX_OPCODE_FUNCTION_RESET
, 0,
7419 LPFC_SLI4_MBX_EMBED
);
7420 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7421 shdr
= (union lpfc_sli4_cfg_shdr
*)
7422 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
7423 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
7424 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
7426 if (rc
!= MBX_TIMEOUT
)
7427 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7428 if (shdr_status
|| shdr_add_status
|| rc
) {
7429 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7430 "0495 SLI_FUNCTION_RESET mailbox "
7431 "failed with status x%x add_status x%x,"
7432 " mbx status x%x\n",
7433 shdr_status
, shdr_add_status
, rc
);
7437 case LPFC_SLI_INTF_IF_TYPE_2
:
7438 for (num_resets
= 0;
7439 num_resets
< MAX_IF_TYPE_2_RESETS
;
7442 bf_set(lpfc_sliport_ctrl_end
, ®_data
,
7443 LPFC_SLIPORT_LITTLE_ENDIAN
);
7444 bf_set(lpfc_sliport_ctrl_ip
, ®_data
,
7445 LPFC_SLIPORT_INIT_PORT
);
7446 writel(reg_data
.word0
, phba
->sli4_hba
.u
.if_type2
.
7449 pci_read_config_word(phba
->pcidev
,
7450 PCI_DEVICE_ID
, &devid
);
7452 * Poll the Port Status Register and wait for RDY for
7453 * up to 10 seconds. If the port doesn't respond, treat
7454 * it as an error. If the port responds with RN, start
7457 for (rdy_chk
= 0; rdy_chk
< 1000; rdy_chk
++) {
7459 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.
7460 STATUSregaddr
, ®_data
.word0
)) {
7464 if (bf_get(lpfc_sliport_status_rn
, ®_data
))
7466 if (bf_get(lpfc_sliport_status_rdy
, ®_data
))
7471 * If the port responds to the init request with
7472 * reset needed, delay for a bit and restart the loop.
7474 if (reset_again
&& (rdy_chk
< 1000)) {
7480 /* Detect any port errors. */
7481 if ((bf_get(lpfc_sliport_status_err
, ®_data
)) ||
7482 (rdy_chk
>= 1000)) {
7483 phba
->work_status
[0] = readl(
7484 phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
7485 phba
->work_status
[1] = readl(
7486 phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
7487 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7488 "2890 Port error detected during port "
7489 "reset(%d): wait_tmo:%d ms, "
7490 "port status reg 0x%x, "
7491 "error 1=0x%x, error 2=0x%x\n",
7492 num_resets
, rdy_chk
*10,
7494 phba
->work_status
[0],
7495 phba
->work_status
[1]);
7500 * Terminate the outer loop provided the Port indicated
7501 * ready within 10 seconds.
7506 /* delay driver action following IF_TYPE_2 function reset */
7509 case LPFC_SLI_INTF_IF_TYPE_1
:
7515 /* Catch the not-ready port failure after a port reset. */
7516 if (num_resets
>= MAX_IF_TYPE_2_RESETS
)
7523 * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
7524 * @phba: pointer to lpfc hba data structure.
7525 * @cnt: number of nop mailbox commands to send.
7527 * This routine is invoked to send a number @cnt of NOP mailbox command and
7528 * wait for each command to complete.
7530 * Return: the number of NOP mailbox command completed.
7533 lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba
*phba
, uint32_t cnt
)
7535 LPFC_MBOXQ_t
*mboxq
;
7536 int length
, cmdsent
;
7539 uint32_t shdr_status
, shdr_add_status
;
7540 union lpfc_sli4_cfg_shdr
*shdr
;
7543 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7544 "2518 Requested to send 0 NOP mailbox cmd\n");
7548 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
7550 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7551 "2519 Unable to allocate memory for issuing "
7552 "NOP mailbox command\n");
7556 /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
7557 length
= (sizeof(struct lpfc_mbx_nop
) -
7558 sizeof(struct lpfc_sli4_cfg_mhdr
));
7560 for (cmdsent
= 0; cmdsent
< cnt
; cmdsent
++) {
7561 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
7562 LPFC_MBOX_OPCODE_NOP
, length
,
7563 LPFC_SLI4_MBX_EMBED
);
7564 if (!phba
->sli4_hba
.intr_enable
)
7565 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7567 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
7568 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
7570 if (rc
== MBX_TIMEOUT
)
7572 /* Check return status */
7573 shdr
= (union lpfc_sli4_cfg_shdr
*)
7574 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
7575 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
7576 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
7578 if (shdr_status
|| shdr_add_status
|| rc
) {
7579 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7580 "2520 NOP mailbox command failed "
7581 "status x%x add_status x%x mbx "
7582 "status x%x\n", shdr_status
,
7583 shdr_add_status
, rc
);
7588 if (rc
!= MBX_TIMEOUT
)
7589 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7595 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
7596 * @phba: pointer to lpfc hba data structure.
7598 * This routine is invoked to set up the PCI device memory space for device
7599 * with SLI-4 interface spec.
7603 * other values - error
7606 lpfc_sli4_pci_mem_setup(struct lpfc_hba
*phba
)
7608 struct pci_dev
*pdev
;
7609 unsigned long bar0map_len
, bar1map_len
, bar2map_len
;
7610 int error
= -ENODEV
;
7613 /* Obtain PCI device reference */
7617 pdev
= phba
->pcidev
;
7619 /* Set the device DMA mask size */
7620 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
7621 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
7622 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
7623 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
7629 * The BARs and register set definitions and offset locations are
7630 * dependent on the if_type.
7632 if (pci_read_config_dword(pdev
, LPFC_SLI_INTF
,
7633 &phba
->sli4_hba
.sli_intf
.word0
)) {
7637 /* There is no SLI3 failback for SLI4 devices. */
7638 if (bf_get(lpfc_sli_intf_valid
, &phba
->sli4_hba
.sli_intf
) !=
7639 LPFC_SLI_INTF_VALID
) {
7640 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7641 "2894 SLI_INTF reg contents invalid "
7642 "sli_intf reg 0x%x\n",
7643 phba
->sli4_hba
.sli_intf
.word0
);
7647 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
7649 * Get the bus address of SLI4 device Bar regions and the
7650 * number of bytes required by each mapping. The mapping of the
7651 * particular PCI BARs regions is dependent on the type of
7654 if (pci_resource_start(pdev
, 0)) {
7655 phba
->pci_bar0_map
= pci_resource_start(pdev
, 0);
7656 bar0map_len
= pci_resource_len(pdev
, 0);
7659 * Map SLI4 PCI Config Space Register base to a kernel virtual
7662 phba
->sli4_hba
.conf_regs_memmap_p
=
7663 ioremap(phba
->pci_bar0_map
, bar0map_len
);
7664 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
7665 dev_printk(KERN_ERR
, &pdev
->dev
,
7666 "ioremap failed for SLI4 PCI config "
7670 /* Set up BAR0 PCI config space register memory map */
7671 lpfc_sli4_bar0_register_memmap(phba
, if_type
);
7673 phba
->pci_bar0_map
= pci_resource_start(pdev
, 1);
7674 bar0map_len
= pci_resource_len(pdev
, 1);
7675 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
7676 dev_printk(KERN_ERR
, &pdev
->dev
,
7677 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
7680 phba
->sli4_hba
.conf_regs_memmap_p
=
7681 ioremap(phba
->pci_bar0_map
, bar0map_len
);
7682 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
7683 dev_printk(KERN_ERR
, &pdev
->dev
,
7684 "ioremap failed for SLI4 PCI config "
7688 lpfc_sli4_bar0_register_memmap(phba
, if_type
);
7691 if ((if_type
== LPFC_SLI_INTF_IF_TYPE_0
) &&
7692 (pci_resource_start(pdev
, 2))) {
7694 * Map SLI4 if type 0 HBA Control Register base to a kernel
7695 * virtual address and setup the registers.
7697 phba
->pci_bar1_map
= pci_resource_start(pdev
, 2);
7698 bar1map_len
= pci_resource_len(pdev
, 2);
7699 phba
->sli4_hba
.ctrl_regs_memmap_p
=
7700 ioremap(phba
->pci_bar1_map
, bar1map_len
);
7701 if (!phba
->sli4_hba
.ctrl_regs_memmap_p
) {
7702 dev_printk(KERN_ERR
, &pdev
->dev
,
7703 "ioremap failed for SLI4 HBA control registers.\n");
7704 goto out_iounmap_conf
;
7706 lpfc_sli4_bar1_register_memmap(phba
);
7709 if ((if_type
== LPFC_SLI_INTF_IF_TYPE_0
) &&
7710 (pci_resource_start(pdev
, 4))) {
7712 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
7713 * virtual address and setup the registers.
7715 phba
->pci_bar2_map
= pci_resource_start(pdev
, 4);
7716 bar2map_len
= pci_resource_len(pdev
, 4);
7717 phba
->sli4_hba
.drbl_regs_memmap_p
=
7718 ioremap(phba
->pci_bar2_map
, bar2map_len
);
7719 if (!phba
->sli4_hba
.drbl_regs_memmap_p
) {
7720 dev_printk(KERN_ERR
, &pdev
->dev
,
7721 "ioremap failed for SLI4 HBA doorbell registers.\n");
7722 goto out_iounmap_ctrl
;
7724 error
= lpfc_sli4_bar2_register_memmap(phba
, LPFC_VF0
);
7726 goto out_iounmap_all
;
7732 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
7734 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
7736 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
7742 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
7743 * @phba: pointer to lpfc hba data structure.
7745 * This routine is invoked to unset the PCI device memory space for device
7746 * with SLI-4 interface spec.
7749 lpfc_sli4_pci_mem_unset(struct lpfc_hba
*phba
)
7752 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
7755 case LPFC_SLI_INTF_IF_TYPE_0
:
7756 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
7757 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
7758 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
7760 case LPFC_SLI_INTF_IF_TYPE_2
:
7761 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
7763 case LPFC_SLI_INTF_IF_TYPE_1
:
7765 dev_printk(KERN_ERR
, &phba
->pcidev
->dev
,
7766 "FATAL - unsupported SLI4 interface type - %d\n",
7773 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
7774 * @phba: pointer to lpfc hba data structure.
7776 * This routine is invoked to enable the MSI-X interrupt vectors to device
7777 * with SLI-3 interface specs. The kernel function pci_enable_msix() is
7778 * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
7779 * invoked, enables either all or nothing, depending on the current
7780 * availability of PCI vector resources. The device driver is responsible
7781 * for calling the individual request_irq() to register each MSI-X vector
7782 * with a interrupt handler, which is done in this function. Note that
7783 * later when device is unloading, the driver should always call free_irq()
7784 * on all MSI-X vectors it has done request_irq() on before calling
7785 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
7786 * will be left with MSI-X enabled and leaks its vectors.
7790 * other values - error
7793 lpfc_sli_enable_msix(struct lpfc_hba
*phba
)
7798 /* Set up MSI-X multi-message vectors */
7799 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
7800 phba
->msix_entries
[i
].entry
= i
;
7802 /* Configure MSI-X capability structure */
7803 rc
= pci_enable_msix(phba
->pcidev
, phba
->msix_entries
,
7804 ARRAY_SIZE(phba
->msix_entries
));
7806 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7807 "0420 PCI enable MSI-X failed (%d)\n", rc
);
7810 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
7811 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7812 "0477 MSI-X entry[%d]: vector=x%x "
7814 phba
->msix_entries
[i
].vector
,
7815 phba
->msix_entries
[i
].entry
);
7817 * Assign MSI-X vectors to interrupt handlers
7820 /* vector-0 is associated to slow-path handler */
7821 rc
= request_irq(phba
->msix_entries
[0].vector
,
7822 &lpfc_sli_sp_intr_handler
, IRQF_SHARED
,
7823 LPFC_SP_DRIVER_HANDLER_NAME
, phba
);
7825 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7826 "0421 MSI-X slow-path request_irq failed "
7831 /* vector-1 is associated to fast-path handler */
7832 rc
= request_irq(phba
->msix_entries
[1].vector
,
7833 &lpfc_sli_fp_intr_handler
, IRQF_SHARED
,
7834 LPFC_FP_DRIVER_HANDLER_NAME
, phba
);
7837 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7838 "0429 MSI-X fast-path request_irq failed "
7844 * Configure HBA MSI-X attention conditions to messages
7846 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
7850 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7851 "0474 Unable to allocate memory for issuing "
7852 "MBOX_CONFIG_MSI command\n");
7855 rc
= lpfc_config_msi(phba
, pmb
);
7858 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
7859 if (rc
!= MBX_SUCCESS
) {
7860 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
7861 "0351 Config MSI mailbox command failed, "
7862 "mbxCmd x%x, mbxStatus x%x\n",
7863 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
);
7867 /* Free memory allocated for mailbox command */
7868 mempool_free(pmb
, phba
->mbox_mem_pool
);
7872 /* Free memory allocated for mailbox command */
7873 mempool_free(pmb
, phba
->mbox_mem_pool
);
7876 /* free the irq already requested */
7877 free_irq(phba
->msix_entries
[1].vector
, phba
);
7880 /* free the irq already requested */
7881 free_irq(phba
->msix_entries
[0].vector
, phba
);
7884 /* Unconfigure MSI-X capability structure */
7885 pci_disable_msix(phba
->pcidev
);
7890 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
7891 * @phba: pointer to lpfc hba data structure.
7893 * This routine is invoked to release the MSI-X vectors and then disable the
7894 * MSI-X interrupt mode to device with SLI-3 interface spec.
7897 lpfc_sli_disable_msix(struct lpfc_hba
*phba
)
7901 /* Free up MSI-X multi-message vectors */
7902 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
7903 free_irq(phba
->msix_entries
[i
].vector
, phba
);
7905 pci_disable_msix(phba
->pcidev
);
7911 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
7912 * @phba: pointer to lpfc hba data structure.
7914 * This routine is invoked to enable the MSI interrupt mode to device with
7915 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
7916 * enable the MSI vector. The device driver is responsible for calling the
7917 * request_irq() to register MSI vector with a interrupt the handler, which
7918 * is done in this function.
7922 * other values - error
7925 lpfc_sli_enable_msi(struct lpfc_hba
*phba
)
7929 rc
= pci_enable_msi(phba
->pcidev
);
7931 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7932 "0462 PCI enable MSI mode success.\n");
7934 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7935 "0471 PCI enable MSI mode failed (%d)\n", rc
);
7939 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
7940 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
7942 pci_disable_msi(phba
->pcidev
);
7943 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7944 "0478 MSI request_irq failed (%d)\n", rc
);
7950 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
7951 * @phba: pointer to lpfc hba data structure.
7953 * This routine is invoked to disable the MSI interrupt mode to device with
7954 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
7955 * done request_irq() on before calling pci_disable_msi(). Failure to do so
7956 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
7960 lpfc_sli_disable_msi(struct lpfc_hba
*phba
)
7962 free_irq(phba
->pcidev
->irq
, phba
);
7963 pci_disable_msi(phba
->pcidev
);
7968 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
7969 * @phba: pointer to lpfc hba data structure.
7971 * This routine is invoked to enable device interrupt and associate driver's
7972 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
7973 * spec. Depends on the interrupt mode configured to the driver, the driver
7974 * will try to fallback from the configured interrupt mode to an interrupt
7975 * mode which is supported by the platform, kernel, and device in the order
7977 * MSI-X -> MSI -> IRQ.
7981 * other values - error
7984 lpfc_sli_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
7986 uint32_t intr_mode
= LPFC_INTR_ERROR
;
7989 if (cfg_mode
== 2) {
7990 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
7991 retval
= lpfc_sli_config_port(phba
, LPFC_SLI_REV3
);
7993 /* Now, try to enable MSI-X interrupt mode */
7994 retval
= lpfc_sli_enable_msix(phba
);
7996 /* Indicate initialization to MSI-X mode */
7997 phba
->intr_type
= MSIX
;
8003 /* Fallback to MSI if MSI-X initialization failed */
8004 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
8005 retval
= lpfc_sli_enable_msi(phba
);
8007 /* Indicate initialization to MSI mode */
8008 phba
->intr_type
= MSI
;
8013 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8014 if (phba
->intr_type
== NONE
) {
8015 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
8016 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
8018 /* Indicate initialization to INTx mode */
8019 phba
->intr_type
= INTx
;
8027 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
8028 * @phba: pointer to lpfc hba data structure.
8030 * This routine is invoked to disable device interrupt and disassociate the
8031 * driver's interrupt handler(s) from interrupt vector(s) to device with
8032 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
8033 * release the interrupt vector(s) for the message signaled interrupt.
8036 lpfc_sli_disable_intr(struct lpfc_hba
*phba
)
8038 /* Disable the currently initialized interrupt mode */
8039 if (phba
->intr_type
== MSIX
)
8040 lpfc_sli_disable_msix(phba
);
8041 else if (phba
->intr_type
== MSI
)
8042 lpfc_sli_disable_msi(phba
);
8043 else if (phba
->intr_type
== INTx
)
8044 free_irq(phba
->pcidev
->irq
, phba
);
8046 /* Reset interrupt management states */
8047 phba
->intr_type
= NONE
;
8048 phba
->sli
.slistat
.sli_intr
= 0;
8054 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
8055 * @phba: pointer to lpfc hba data structure.
8057 * This routine is invoked to enable the MSI-X interrupt vectors to device
8058 * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
8059 * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
8060 * enables either all or nothing, depending on the current availability of
8061 * PCI vector resources. The device driver is responsible for calling the
8062 * individual request_irq() to register each MSI-X vector with a interrupt
8063 * handler, which is done in this function. Note that later when device is
8064 * unloading, the driver should always call free_irq() on all MSI-X vectors
8065 * it has done request_irq() on before calling pci_disable_msix(). Failure
8066 * to do so results in a BUG_ON() and a device will be left with MSI-X
8067 * enabled and leaks its vectors.
8071 * other values - error
8074 lpfc_sli4_enable_msix(struct lpfc_hba
*phba
)
8076 int vectors
, rc
, index
;
8078 /* Set up MSI-X multi-message vectors */
8079 for (index
= 0; index
< phba
->sli4_hba
.cfg_eqn
; index
++)
8080 phba
->sli4_hba
.msix_entries
[index
].entry
= index
;
8082 /* Configure MSI-X capability structure */
8083 vectors
= phba
->sli4_hba
.cfg_eqn
;
8084 enable_msix_vectors
:
8085 rc
= pci_enable_msix(phba
->pcidev
, phba
->sli4_hba
.msix_entries
,
8089 goto enable_msix_vectors
;
8091 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8092 "0484 PCI enable MSI-X failed (%d)\n", rc
);
8096 /* Log MSI-X vector assignment */
8097 for (index
= 0; index
< vectors
; index
++)
8098 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8099 "0489 MSI-X entry[%d]: vector=x%x "
8100 "message=%d\n", index
,
8101 phba
->sli4_hba
.msix_entries
[index
].vector
,
8102 phba
->sli4_hba
.msix_entries
[index
].entry
);
8105 * Assign MSI-X vectors to interrupt handlers
8107 for (index
= 0; index
< vectors
; index
++) {
8108 memset(&phba
->sli4_hba
.handler_name
[index
], 0, 16);
8109 sprintf((char *)&phba
->sli4_hba
.handler_name
[index
],
8110 LPFC_DRIVER_HANDLER_NAME
"%d", index
);
8112 phba
->sli4_hba
.fcp_eq_hdl
[index
].idx
= index
;
8113 phba
->sli4_hba
.fcp_eq_hdl
[index
].phba
= phba
;
8114 atomic_set(&phba
->sli4_hba
.fcp_eq_hdl
[index
].fcp_eq_in_use
, 1);
8115 rc
= request_irq(phba
->sli4_hba
.msix_entries
[index
].vector
,
8116 &lpfc_sli4_hba_intr_handler
, IRQF_SHARED
,
8117 (char *)&phba
->sli4_hba
.handler_name
[index
],
8118 &phba
->sli4_hba
.fcp_eq_hdl
[index
]);
8120 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
8121 "0486 MSI-X fast-path (%d) "
8122 "request_irq failed (%d)\n", index
, rc
);
8126 phba
->sli4_hba
.msix_vec_nr
= vectors
;
8131 /* free the irq already requested */
8132 for (--index
; index
>= 0; index
--)
8133 free_irq(phba
->sli4_hba
.msix_entries
[index
].vector
,
8134 &phba
->sli4_hba
.fcp_eq_hdl
[index
]);
8137 /* Unconfigure MSI-X capability structure */
8138 pci_disable_msix(phba
->pcidev
);
8143 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
8144 * @phba: pointer to lpfc hba data structure.
8146 * This routine is invoked to release the MSI-X vectors and then disable the
8147 * MSI-X interrupt mode to device with SLI-4 interface spec.
8150 lpfc_sli4_disable_msix(struct lpfc_hba
*phba
)
8154 /* Free up MSI-X multi-message vectors */
8155 for (index
= 0; index
< phba
->sli4_hba
.msix_vec_nr
; index
++)
8156 free_irq(phba
->sli4_hba
.msix_entries
[index
].vector
,
8157 &phba
->sli4_hba
.fcp_eq_hdl
[index
]);
8160 pci_disable_msix(phba
->pcidev
);
8166 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
8167 * @phba: pointer to lpfc hba data structure.
8169 * This routine is invoked to enable the MSI interrupt mode to device with
8170 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
8171 * to enable the MSI vector. The device driver is responsible for calling
8172 * the request_irq() to register MSI vector with a interrupt the handler,
8173 * which is done in this function.
8177 * other values - error
8180 lpfc_sli4_enable_msi(struct lpfc_hba
*phba
)
8184 rc
= pci_enable_msi(phba
->pcidev
);
8186 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8187 "0487 PCI enable MSI mode success.\n");
8189 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8190 "0488 PCI enable MSI mode failed (%d)\n", rc
);
8194 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
8195 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
8197 pci_disable_msi(phba
->pcidev
);
8198 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
8199 "0490 MSI request_irq failed (%d)\n", rc
);
8203 for (index
= 0; index
< phba
->cfg_fcp_io_channel
; index
++) {
8204 phba
->sli4_hba
.fcp_eq_hdl
[index
].idx
= index
;
8205 phba
->sli4_hba
.fcp_eq_hdl
[index
].phba
= phba
;
8212 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
8213 * @phba: pointer to lpfc hba data structure.
8215 * This routine is invoked to disable the MSI interrupt mode to device with
8216 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
8217 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8218 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8222 lpfc_sli4_disable_msi(struct lpfc_hba
*phba
)
8224 free_irq(phba
->pcidev
->irq
, phba
);
8225 pci_disable_msi(phba
->pcidev
);
8230 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
8231 * @phba: pointer to lpfc hba data structure.
8233 * This routine is invoked to enable device interrupt and associate driver's
8234 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
8235 * interface spec. Depends on the interrupt mode configured to the driver,
8236 * the driver will try to fallback from the configured interrupt mode to an
8237 * interrupt mode which is supported by the platform, kernel, and device in
8239 * MSI-X -> MSI -> IRQ.
8243 * other values - error
8246 lpfc_sli4_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
8248 uint32_t intr_mode
= LPFC_INTR_ERROR
;
8251 if (cfg_mode
== 2) {
8252 /* Preparation before conf_msi mbox cmd */
8255 /* Now, try to enable MSI-X interrupt mode */
8256 retval
= lpfc_sli4_enable_msix(phba
);
8258 /* Indicate initialization to MSI-X mode */
8259 phba
->intr_type
= MSIX
;
8265 /* Fallback to MSI if MSI-X initialization failed */
8266 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
8267 retval
= lpfc_sli4_enable_msi(phba
);
8269 /* Indicate initialization to MSI mode */
8270 phba
->intr_type
= MSI
;
8275 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8276 if (phba
->intr_type
== NONE
) {
8277 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
8278 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
8280 /* Indicate initialization to INTx mode */
8281 phba
->intr_type
= INTx
;
8283 for (index
= 0; index
< phba
->cfg_fcp_io_channel
;
8285 phba
->sli4_hba
.fcp_eq_hdl
[index
].idx
= index
;
8286 phba
->sli4_hba
.fcp_eq_hdl
[index
].phba
= phba
;
8287 atomic_set(&phba
->sli4_hba
.fcp_eq_hdl
[index
].
8296 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
8297 * @phba: pointer to lpfc hba data structure.
8299 * This routine is invoked to disable device interrupt and disassociate
8300 * the driver's interrupt handler(s) from interrupt vector(s) to device
8301 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
8302 * will release the interrupt vector(s) for the message signaled interrupt.
8305 lpfc_sli4_disable_intr(struct lpfc_hba
*phba
)
8307 /* Disable the currently initialized interrupt mode */
8308 if (phba
->intr_type
== MSIX
)
8309 lpfc_sli4_disable_msix(phba
);
8310 else if (phba
->intr_type
== MSI
)
8311 lpfc_sli4_disable_msi(phba
);
8312 else if (phba
->intr_type
== INTx
)
8313 free_irq(phba
->pcidev
->irq
, phba
);
8315 /* Reset interrupt management states */
8316 phba
->intr_type
= NONE
;
8317 phba
->sli
.slistat
.sli_intr
= 0;
8323 * lpfc_unset_hba - Unset SLI3 hba device initialization
8324 * @phba: pointer to lpfc hba data structure.
8326 * This routine is invoked to unset the HBA device initialization steps to
8327 * a device with SLI-3 interface spec.
8330 lpfc_unset_hba(struct lpfc_hba
*phba
)
8332 struct lpfc_vport
*vport
= phba
->pport
;
8333 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8335 spin_lock_irq(shost
->host_lock
);
8336 vport
->load_flag
|= FC_UNLOADING
;
8337 spin_unlock_irq(shost
->host_lock
);
8339 kfree(phba
->vpi_bmask
);
8340 kfree(phba
->vpi_ids
);
8342 lpfc_stop_hba_timers(phba
);
8344 phba
->pport
->work_port_events
= 0;
8346 lpfc_sli_hba_down(phba
);
8348 lpfc_sli_brdrestart(phba
);
8350 lpfc_sli_disable_intr(phba
);
8356 * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
8357 * @phba: pointer to lpfc hba data structure.
8359 * This routine is invoked to unset the HBA device initialization steps to
8360 * a device with SLI-4 interface spec.
8363 lpfc_sli4_unset_hba(struct lpfc_hba
*phba
)
8365 struct lpfc_vport
*vport
= phba
->pport
;
8366 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8368 spin_lock_irq(shost
->host_lock
);
8369 vport
->load_flag
|= FC_UNLOADING
;
8370 spin_unlock_irq(shost
->host_lock
);
8372 phba
->pport
->work_port_events
= 0;
8374 /* Stop the SLI4 device port */
8375 lpfc_stop_port(phba
);
8377 lpfc_sli4_disable_intr(phba
);
8379 /* Reset SLI4 HBA FCoE function */
8380 lpfc_pci_function_reset(phba
);
8381 lpfc_sli4_queue_destroy(phba
);
8387 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
8388 * @phba: Pointer to HBA context object.
8390 * This function is called in the SLI4 code path to wait for completion
8391 * of device's XRIs exchange busy. It will check the XRI exchange busy
8392 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
8393 * that, it will check the XRI exchange busy on outstanding FCP and ELS
8394 * I/Os every 30 seconds, log error message, and wait forever. Only when
8395 * all XRI exchange busy complete, the driver unload shall proceed with
8396 * invoking the function reset ioctl mailbox command to the CNA and the
8397 * the rest of the driver unload resource release.
8400 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba
*phba
)
8403 int fcp_xri_cmpl
= list_empty(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
8404 int els_xri_cmpl
= list_empty(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
8406 while (!fcp_xri_cmpl
|| !els_xri_cmpl
) {
8407 if (wait_time
> LPFC_XRI_EXCH_BUSY_WAIT_TMO
) {
8409 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8410 "2877 FCP XRI exchange busy "
8411 "wait time: %d seconds.\n",
8414 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8415 "2878 ELS XRI exchange busy "
8416 "wait time: %d seconds.\n",
8418 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2
);
8419 wait_time
+= LPFC_XRI_EXCH_BUSY_WAIT_T2
;
8421 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1
);
8422 wait_time
+= LPFC_XRI_EXCH_BUSY_WAIT_T1
;
8425 list_empty(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
8427 list_empty(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
8432 * lpfc_sli4_hba_unset - Unset the fcoe hba
8433 * @phba: Pointer to HBA context object.
8435 * This function is called in the SLI4 code path to reset the HBA's FCoE
8436 * function. The caller is not required to hold any lock. This routine
8437 * issues PCI function reset mailbox command to reset the FCoE function.
8438 * At the end of the function, it calls lpfc_hba_down_post function to
8439 * free any pending commands.
8442 lpfc_sli4_hba_unset(struct lpfc_hba
*phba
)
8445 LPFC_MBOXQ_t
*mboxq
;
8446 struct pci_dev
*pdev
= phba
->pcidev
;
8448 lpfc_stop_hba_timers(phba
);
8449 phba
->sli4_hba
.intr_enable
= 0;
8452 * Gracefully wait out the potential current outstanding asynchronous
8456 /* First, block any pending async mailbox command from posted */
8457 spin_lock_irq(&phba
->hbalock
);
8458 phba
->sli
.sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
8459 spin_unlock_irq(&phba
->hbalock
);
8460 /* Now, trying to wait it out if we can */
8461 while (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
8463 if (++wait_cnt
> LPFC_ACTIVE_MBOX_WAIT_CNT
)
8466 /* Forcefully release the outstanding mailbox command if timed out */
8467 if (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
8468 spin_lock_irq(&phba
->hbalock
);
8469 mboxq
= phba
->sli
.mbox_active
;
8470 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
8471 __lpfc_mbox_cmpl_put(phba
, mboxq
);
8472 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8473 phba
->sli
.mbox_active
= NULL
;
8474 spin_unlock_irq(&phba
->hbalock
);
8477 /* Abort all iocbs associated with the hba */
8478 lpfc_sli_hba_iocb_abort(phba
);
8480 /* Wait for completion of device XRI exchange busy */
8481 lpfc_sli4_xri_exchange_busy_wait(phba
);
8483 /* Disable PCI subsystem interrupt */
8484 lpfc_sli4_disable_intr(phba
);
8486 /* Disable SR-IOV if enabled */
8487 if (phba
->cfg_sriov_nr_virtfn
)
8488 pci_disable_sriov(pdev
);
8490 /* Stop kthread signal shall trigger work_done one more time */
8491 kthread_stop(phba
->worker_thread
);
8493 /* Reset SLI4 HBA FCoE function */
8494 lpfc_pci_function_reset(phba
);
8495 lpfc_sli4_queue_destroy(phba
);
8497 /* Stop the SLI4 device port */
8498 phba
->pport
->work_port_events
= 0;
8502 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
8503 * @phba: Pointer to HBA context object.
8504 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8506 * This function is called in the SLI4 code path to read the port's
8507 * sli4 capabilities.
8509 * This function may be be called from any context that can block-wait
8510 * for the completion. The expectation is that this routine is called
8511 * typically from probe_one or from the online routine.
8514 lpfc_pc_sli4_params_get(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
8517 struct lpfc_mqe
*mqe
;
8518 struct lpfc_pc_sli4_params
*sli4_params
;
8522 mqe
= &mboxq
->u
.mqe
;
8524 /* Read the port's SLI4 Parameters port capabilities */
8525 lpfc_pc_sli4_params(mboxq
);
8526 if (!phba
->sli4_hba
.intr_enable
)
8527 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
8529 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
8530 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
8536 sli4_params
= &phba
->sli4_hba
.pc_sli4_params
;
8537 sli4_params
->if_type
= bf_get(if_type
, &mqe
->un
.sli4_params
);
8538 sli4_params
->sli_rev
= bf_get(sli_rev
, &mqe
->un
.sli4_params
);
8539 sli4_params
->sli_family
= bf_get(sli_family
, &mqe
->un
.sli4_params
);
8540 sli4_params
->featurelevel_1
= bf_get(featurelevel_1
,
8541 &mqe
->un
.sli4_params
);
8542 sli4_params
->featurelevel_2
= bf_get(featurelevel_2
,
8543 &mqe
->un
.sli4_params
);
8544 sli4_params
->proto_types
= mqe
->un
.sli4_params
.word3
;
8545 sli4_params
->sge_supp_len
= mqe
->un
.sli4_params
.sge_supp_len
;
8546 sli4_params
->if_page_sz
= bf_get(if_page_sz
, &mqe
->un
.sli4_params
);
8547 sli4_params
->rq_db_window
= bf_get(rq_db_window
, &mqe
->un
.sli4_params
);
8548 sli4_params
->loopbk_scope
= bf_get(loopbk_scope
, &mqe
->un
.sli4_params
);
8549 sli4_params
->eq_pages_max
= bf_get(eq_pages
, &mqe
->un
.sli4_params
);
8550 sli4_params
->eqe_size
= bf_get(eqe_size
, &mqe
->un
.sli4_params
);
8551 sli4_params
->cq_pages_max
= bf_get(cq_pages
, &mqe
->un
.sli4_params
);
8552 sli4_params
->cqe_size
= bf_get(cqe_size
, &mqe
->un
.sli4_params
);
8553 sli4_params
->mq_pages_max
= bf_get(mq_pages
, &mqe
->un
.sli4_params
);
8554 sli4_params
->mqe_size
= bf_get(mqe_size
, &mqe
->un
.sli4_params
);
8555 sli4_params
->mq_elem_cnt
= bf_get(mq_elem_cnt
, &mqe
->un
.sli4_params
);
8556 sli4_params
->wq_pages_max
= bf_get(wq_pages
, &mqe
->un
.sli4_params
);
8557 sli4_params
->wqe_size
= bf_get(wqe_size
, &mqe
->un
.sli4_params
);
8558 sli4_params
->rq_pages_max
= bf_get(rq_pages
, &mqe
->un
.sli4_params
);
8559 sli4_params
->rqe_size
= bf_get(rqe_size
, &mqe
->un
.sli4_params
);
8560 sli4_params
->hdr_pages_max
= bf_get(hdr_pages
, &mqe
->un
.sli4_params
);
8561 sli4_params
->hdr_size
= bf_get(hdr_size
, &mqe
->un
.sli4_params
);
8562 sli4_params
->hdr_pp_align
= bf_get(hdr_pp_align
, &mqe
->un
.sli4_params
);
8563 sli4_params
->sgl_pages_max
= bf_get(sgl_pages
, &mqe
->un
.sli4_params
);
8564 sli4_params
->sgl_pp_align
= bf_get(sgl_pp_align
, &mqe
->un
.sli4_params
);
8566 /* Make sure that sge_supp_len can be handled by the driver */
8567 if (sli4_params
->sge_supp_len
> LPFC_MAX_SGE_SIZE
)
8568 sli4_params
->sge_supp_len
= LPFC_MAX_SGE_SIZE
;
8574 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
8575 * @phba: Pointer to HBA context object.
8576 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8578 * This function is called in the SLI4 code path to read the port's
8579 * sli4 capabilities.
8581 * This function may be be called from any context that can block-wait
8582 * for the completion. The expectation is that this routine is called
8583 * typically from probe_one or from the online routine.
8586 lpfc_get_sli4_parameters(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
8589 struct lpfc_mqe
*mqe
= &mboxq
->u
.mqe
;
8590 struct lpfc_pc_sli4_params
*sli4_params
;
8593 struct lpfc_sli4_parameters
*mbx_sli4_parameters
;
8596 * By default, the driver assumes the SLI4 port requires RPI
8597 * header postings. The SLI4_PARAM response will correct this
8600 phba
->sli4_hba
.rpi_hdrs_in_use
= 1;
8602 /* Read the port's SLI4 Config Parameters */
8603 length
= (sizeof(struct lpfc_mbx_get_sli4_parameters
) -
8604 sizeof(struct lpfc_sli4_cfg_mhdr
));
8605 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
8606 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS
,
8607 length
, LPFC_SLI4_MBX_EMBED
);
8608 if (!phba
->sli4_hba
.intr_enable
)
8609 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
8611 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
8612 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
8616 sli4_params
= &phba
->sli4_hba
.pc_sli4_params
;
8617 mbx_sli4_parameters
= &mqe
->un
.get_sli4_parameters
.sli4_parameters
;
8618 sli4_params
->if_type
= bf_get(cfg_if_type
, mbx_sli4_parameters
);
8619 sli4_params
->sli_rev
= bf_get(cfg_sli_rev
, mbx_sli4_parameters
);
8620 sli4_params
->sli_family
= bf_get(cfg_sli_family
, mbx_sli4_parameters
);
8621 sli4_params
->featurelevel_1
= bf_get(cfg_sli_hint_1
,
8622 mbx_sli4_parameters
);
8623 sli4_params
->featurelevel_2
= bf_get(cfg_sli_hint_2
,
8624 mbx_sli4_parameters
);
8625 if (bf_get(cfg_phwq
, mbx_sli4_parameters
))
8626 phba
->sli3_options
|= LPFC_SLI4_PHWQ_ENABLED
;
8628 phba
->sli3_options
&= ~LPFC_SLI4_PHWQ_ENABLED
;
8629 sli4_params
->sge_supp_len
= mbx_sli4_parameters
->sge_supp_len
;
8630 sli4_params
->loopbk_scope
= bf_get(loopbk_scope
, mbx_sli4_parameters
);
8631 sli4_params
->cqv
= bf_get(cfg_cqv
, mbx_sli4_parameters
);
8632 sli4_params
->mqv
= bf_get(cfg_mqv
, mbx_sli4_parameters
);
8633 sli4_params
->wqv
= bf_get(cfg_wqv
, mbx_sli4_parameters
);
8634 sli4_params
->rqv
= bf_get(cfg_rqv
, mbx_sli4_parameters
);
8635 sli4_params
->sgl_pages_max
= bf_get(cfg_sgl_page_cnt
,
8636 mbx_sli4_parameters
);
8637 sli4_params
->sgl_pp_align
= bf_get(cfg_sgl_pp_align
,
8638 mbx_sli4_parameters
);
8639 phba
->sli4_hba
.extents_in_use
= bf_get(cfg_ext
, mbx_sli4_parameters
);
8640 phba
->sli4_hba
.rpi_hdrs_in_use
= bf_get(cfg_hdrr
, mbx_sli4_parameters
);
8642 /* Make sure that sge_supp_len can be handled by the driver */
8643 if (sli4_params
->sge_supp_len
> LPFC_MAX_SGE_SIZE
)
8644 sli4_params
->sge_supp_len
= LPFC_MAX_SGE_SIZE
;
8650 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
8651 * @pdev: pointer to PCI device
8652 * @pid: pointer to PCI device identifier
8654 * This routine is to be called to attach a device with SLI-3 interface spec
8655 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8656 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
8657 * information of the device and driver to see if the driver state that it can
8658 * support this kind of device. If the match is successful, the driver core
8659 * invokes this routine. If this routine determines it can claim the HBA, it
8660 * does all the initialization that it needs to do to handle the HBA properly.
8663 * 0 - driver can claim the device
8664 * negative value - driver can not claim the device
8666 static int __devinit
8667 lpfc_pci_probe_one_s3(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
8669 struct lpfc_hba
*phba
;
8670 struct lpfc_vport
*vport
= NULL
;
8671 struct Scsi_Host
*shost
= NULL
;
8673 uint32_t cfg_mode
, intr_mode
;
8675 /* Allocate memory for HBA structure */
8676 phba
= lpfc_hba_alloc(pdev
);
8680 /* Perform generic PCI device enabling operation */
8681 error
= lpfc_enable_pci_dev(phba
);
8685 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
8686 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_LP
);
8688 goto out_disable_pci_dev
;
8690 /* Set up SLI-3 specific device PCI memory space */
8691 error
= lpfc_sli_pci_mem_setup(phba
);
8693 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8694 "1402 Failed to set up pci memory space.\n");
8695 goto out_disable_pci_dev
;
8698 /* Set up phase-1 common device driver resources */
8699 error
= lpfc_setup_driver_resource_phase1(phba
);
8701 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8702 "1403 Failed to set up driver resource.\n");
8703 goto out_unset_pci_mem_s3
;
8706 /* Set up SLI-3 specific device driver resources */
8707 error
= lpfc_sli_driver_resource_setup(phba
);
8709 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8710 "1404 Failed to set up driver resource.\n");
8711 goto out_unset_pci_mem_s3
;
8714 /* Initialize and populate the iocb list per host */
8715 error
= lpfc_init_iocb_list(phba
, LPFC_IOCB_LIST_CNT
);
8717 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8718 "1405 Failed to initialize iocb list.\n");
8719 goto out_unset_driver_resource_s3
;
8722 /* Set up common device driver resources */
8723 error
= lpfc_setup_driver_resource_phase2(phba
);
8725 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8726 "1406 Failed to set up driver resource.\n");
8727 goto out_free_iocb_list
;
8730 /* Get the default values for Model Name and Description */
8731 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
8733 /* Create SCSI host to the physical port */
8734 error
= lpfc_create_shost(phba
);
8736 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8737 "1407 Failed to create scsi host.\n");
8738 goto out_unset_driver_resource
;
8741 /* Configure sysfs attributes */
8742 vport
= phba
->pport
;
8743 error
= lpfc_alloc_sysfs_attr(vport
);
8745 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8746 "1476 Failed to allocate sysfs attr\n");
8747 goto out_destroy_shost
;
8750 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
8751 /* Now, trying to enable interrupt and bring up the device */
8752 cfg_mode
= phba
->cfg_use_msi
;
8754 /* Put device to a known state before enabling interrupt */
8755 lpfc_stop_port(phba
);
8756 /* Configure and enable interrupt */
8757 intr_mode
= lpfc_sli_enable_intr(phba
, cfg_mode
);
8758 if (intr_mode
== LPFC_INTR_ERROR
) {
8759 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8760 "0431 Failed to enable interrupt.\n");
8762 goto out_free_sysfs_attr
;
8764 /* SLI-3 HBA setup */
8765 if (lpfc_sli_hba_setup(phba
)) {
8766 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8767 "1477 Failed to set up hba\n");
8769 goto out_remove_device
;
8772 /* Wait 50ms for the interrupts of previous mailbox commands */
8774 /* Check active interrupts on message signaled interrupts */
8775 if (intr_mode
== 0 ||
8776 phba
->sli
.slistat
.sli_intr
> LPFC_MSIX_VECTORS
) {
8777 /* Log the current active interrupt mode */
8778 phba
->intr_mode
= intr_mode
;
8779 lpfc_log_intr_mode(phba
, intr_mode
);
8782 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8783 "0447 Configure interrupt mode (%d) "
8784 "failed active interrupt test.\n",
8786 /* Disable the current interrupt mode */
8787 lpfc_sli_disable_intr(phba
);
8788 /* Try next level of interrupt mode */
8789 cfg_mode
= --intr_mode
;
8793 /* Perform post initialization setup */
8794 lpfc_post_init_setup(phba
);
8796 /* Check if there are static vports to be created. */
8797 lpfc_create_static_vport(phba
);
8802 lpfc_unset_hba(phba
);
8803 out_free_sysfs_attr
:
8804 lpfc_free_sysfs_attr(vport
);
8806 lpfc_destroy_shost(phba
);
8807 out_unset_driver_resource
:
8808 lpfc_unset_driver_resource_phase2(phba
);
8810 lpfc_free_iocb_list(phba
);
8811 out_unset_driver_resource_s3
:
8812 lpfc_sli_driver_resource_unset(phba
);
8813 out_unset_pci_mem_s3
:
8814 lpfc_sli_pci_mem_unset(phba
);
8815 out_disable_pci_dev
:
8816 lpfc_disable_pci_dev(phba
);
8818 scsi_host_put(shost
);
8820 lpfc_hba_free(phba
);
8825 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
8826 * @pdev: pointer to PCI device
8828 * This routine is to be called to disattach a device with SLI-3 interface
8829 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8830 * removed from PCI bus, it performs all the necessary cleanup for the HBA
8831 * device to be removed from the PCI subsystem properly.
8833 static void __devexit
8834 lpfc_pci_remove_one_s3(struct pci_dev
*pdev
)
8836 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8837 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
8838 struct lpfc_vport
**vports
;
8839 struct lpfc_hba
*phba
= vport
->phba
;
8841 int bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
8843 spin_lock_irq(&phba
->hbalock
);
8844 vport
->load_flag
|= FC_UNLOADING
;
8845 spin_unlock_irq(&phba
->hbalock
);
8847 lpfc_free_sysfs_attr(vport
);
8849 /* Release all the vports against this physical port */
8850 vports
= lpfc_create_vport_work_array(phba
);
8852 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
8853 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
8855 fc_vport_terminate(vports
[i
]->fc_vport
);
8857 lpfc_destroy_vport_work_array(phba
, vports
);
8859 /* Remove FC host and then SCSI host with the physical port */
8860 fc_remove_host(shost
);
8861 scsi_remove_host(shost
);
8862 lpfc_cleanup(vport
);
8865 * Bring down the SLI Layer. This step disable all interrupts,
8866 * clears the rings, discards all mailbox commands, and resets
8870 /* HBA interrupt will be disabled after this call */
8871 lpfc_sli_hba_down(phba
);
8872 /* Stop kthread signal shall trigger work_done one more time */
8873 kthread_stop(phba
->worker_thread
);
8874 /* Final cleanup of txcmplq and reset the HBA */
8875 lpfc_sli_brdrestart(phba
);
8877 kfree(phba
->vpi_bmask
);
8878 kfree(phba
->vpi_ids
);
8880 lpfc_stop_hba_timers(phba
);
8881 spin_lock_irq(&phba
->hbalock
);
8882 list_del_init(&vport
->listentry
);
8883 spin_unlock_irq(&phba
->hbalock
);
8885 lpfc_debugfs_terminate(vport
);
8887 /* Disable SR-IOV if enabled */
8888 if (phba
->cfg_sriov_nr_virtfn
)
8889 pci_disable_sriov(pdev
);
8891 /* Disable interrupt */
8892 lpfc_sli_disable_intr(phba
);
8894 pci_set_drvdata(pdev
, NULL
);
8895 scsi_host_put(shost
);
8898 * Call scsi_free before mem_free since scsi bufs are released to their
8899 * corresponding pools here.
8901 lpfc_scsi_free(phba
);
8902 lpfc_mem_free_all(phba
);
8904 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
8905 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
8907 /* Free resources associated with SLI2 interface */
8908 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
8909 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
8911 /* unmap adapter SLIM and Control Registers */
8912 iounmap(phba
->ctrl_regs_memmap_p
);
8913 iounmap(phba
->slim_memmap_p
);
8915 lpfc_hba_free(phba
);
8917 pci_release_selected_regions(pdev
, bars
);
8918 pci_disable_device(pdev
);
8922 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
8923 * @pdev: pointer to PCI device
8924 * @msg: power management message
8926 * This routine is to be called from the kernel's PCI subsystem to support
8927 * system Power Management (PM) to device with SLI-3 interface spec. When
8928 * PM invokes this method, it quiesces the device by stopping the driver's
8929 * worker thread for the device, turning off device's interrupt and DMA,
8930 * and bring the device offline. Note that as the driver implements the
8931 * minimum PM requirements to a power-aware driver's PM support for the
8932 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
8933 * to the suspend() method call will be treated as SUSPEND and the driver will
8934 * fully reinitialize its device during resume() method call, the driver will
8935 * set device to PCI_D3hot state in PCI config space instead of setting it
8936 * according to the @msg provided by the PM.
8939 * 0 - driver suspended the device
8943 lpfc_pci_suspend_one_s3(struct pci_dev
*pdev
, pm_message_t msg
)
8945 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8946 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8948 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8949 "0473 PCI device Power Management suspend.\n");
8951 /* Bring down the device */
8952 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
8954 kthread_stop(phba
->worker_thread
);
8956 /* Disable interrupt from device */
8957 lpfc_sli_disable_intr(phba
);
8959 /* Save device state to PCI config space */
8960 pci_save_state(pdev
);
8961 pci_set_power_state(pdev
, PCI_D3hot
);
8967 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
8968 * @pdev: pointer to PCI device
8970 * This routine is to be called from the kernel's PCI subsystem to support
8971 * system Power Management (PM) to device with SLI-3 interface spec. When PM
8972 * invokes this method, it restores the device's PCI config space state and
8973 * fully reinitializes the device and brings it online. Note that as the
8974 * driver implements the minimum PM requirements to a power-aware driver's
8975 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
8976 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
8977 * driver will fully reinitialize its device during resume() method call,
8978 * the device will be set to PCI_D0 directly in PCI config space before
8979 * restoring the state.
8982 * 0 - driver suspended the device
8986 lpfc_pci_resume_one_s3(struct pci_dev
*pdev
)
8988 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8989 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
8993 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8994 "0452 PCI device Power Management resume.\n");
8996 /* Restore device state from PCI config space */
8997 pci_set_power_state(pdev
, PCI_D0
);
8998 pci_restore_state(pdev
);
9001 * As the new kernel behavior of pci_restore_state() API call clears
9002 * device saved_state flag, need to save the restored state again.
9004 pci_save_state(pdev
);
9006 if (pdev
->is_busmaster
)
9007 pci_set_master(pdev
);
9009 /* Startup the kernel thread for this host adapter. */
9010 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
9011 "lpfc_worker_%d", phba
->brd_no
);
9012 if (IS_ERR(phba
->worker_thread
)) {
9013 error
= PTR_ERR(phba
->worker_thread
);
9014 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9015 "0434 PM resume failed to start worker "
9016 "thread: error=x%x.\n", error
);
9020 /* Configure and enable interrupt */
9021 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
9022 if (intr_mode
== LPFC_INTR_ERROR
) {
9023 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9024 "0430 PM resume Failed to enable interrupt\n");
9027 phba
->intr_mode
= intr_mode
;
9029 /* Restart HBA and bring it online */
9030 lpfc_sli_brdrestart(phba
);
9033 /* Log the current active interrupt mode */
9034 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
9040 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
9041 * @phba: pointer to lpfc hba data structure.
9043 * This routine is called to prepare the SLI3 device for PCI slot recover. It
9044 * aborts all the outstanding SCSI I/Os to the pci device.
9047 lpfc_sli_prep_dev_for_recover(struct lpfc_hba
*phba
)
9049 struct lpfc_sli
*psli
= &phba
->sli
;
9050 struct lpfc_sli_ring
*pring
;
9052 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9053 "2723 PCI channel I/O abort preparing for recovery\n");
9056 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9057 * and let the SCSI mid-layer to retry them to recover.
9059 pring
= &psli
->ring
[psli
->fcp_ring
];
9060 lpfc_sli_abort_iocb_ring(phba
, pring
);
9064 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
9065 * @phba: pointer to lpfc hba data structure.
9067 * This routine is called to prepare the SLI3 device for PCI slot reset. It
9068 * disables the device interrupt and pci device, and aborts the internal FCP
9072 lpfc_sli_prep_dev_for_reset(struct lpfc_hba
*phba
)
9074 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9075 "2710 PCI channel disable preparing for reset\n");
9077 /* Block any management I/Os to the device */
9078 lpfc_block_mgmt_io(phba
, LPFC_MBX_WAIT
);
9080 /* Block all SCSI devices' I/Os on the host */
9081 lpfc_scsi_dev_block(phba
);
9083 /* stop all timers */
9084 lpfc_stop_hba_timers(phba
);
9086 /* Disable interrupt and pci device */
9087 lpfc_sli_disable_intr(phba
);
9088 pci_disable_device(phba
->pcidev
);
9090 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9091 lpfc_sli_flush_fcp_rings(phba
);
9095 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
9096 * @phba: pointer to lpfc hba data structure.
9098 * This routine is called to prepare the SLI3 device for PCI slot permanently
9099 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9103 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
9105 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9106 "2711 PCI channel permanent disable for failure\n");
9107 /* Block all SCSI devices' I/Os on the host */
9108 lpfc_scsi_dev_block(phba
);
9110 /* stop all timers */
9111 lpfc_stop_hba_timers(phba
);
9113 /* Clean up all driver's outstanding SCSI I/Os */
9114 lpfc_sli_flush_fcp_rings(phba
);
9118 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
9119 * @pdev: pointer to PCI device.
9120 * @state: the current PCI connection state.
9122 * This routine is called from the PCI subsystem for I/O error handling to
9123 * device with SLI-3 interface spec. This function is called by the PCI
9124 * subsystem after a PCI bus error affecting this device has been detected.
9125 * When this function is invoked, it will need to stop all the I/Os and
9126 * interrupt(s) to the device. Once that is done, it will return
9127 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
9131 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
9132 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9133 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9135 static pci_ers_result_t
9136 lpfc_io_error_detected_s3(struct pci_dev
*pdev
, pci_channel_state_t state
)
9138 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9139 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9142 case pci_channel_io_normal
:
9143 /* Non-fatal error, prepare for recovery */
9144 lpfc_sli_prep_dev_for_recover(phba
);
9145 return PCI_ERS_RESULT_CAN_RECOVER
;
9146 case pci_channel_io_frozen
:
9147 /* Fatal error, prepare for slot reset */
9148 lpfc_sli_prep_dev_for_reset(phba
);
9149 return PCI_ERS_RESULT_NEED_RESET
;
9150 case pci_channel_io_perm_failure
:
9151 /* Permanent failure, prepare for device down */
9152 lpfc_sli_prep_dev_for_perm_failure(phba
);
9153 return PCI_ERS_RESULT_DISCONNECT
;
9155 /* Unknown state, prepare and request slot reset */
9156 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9157 "0472 Unknown PCI error state: x%x\n", state
);
9158 lpfc_sli_prep_dev_for_reset(phba
);
9159 return PCI_ERS_RESULT_NEED_RESET
;
9164 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
9165 * @pdev: pointer to PCI device.
9167 * This routine is called from the PCI subsystem for error handling to
9168 * device with SLI-3 interface spec. This is called after PCI bus has been
9169 * reset to restart the PCI card from scratch, as if from a cold-boot.
9170 * During the PCI subsystem error recovery, after driver returns
9171 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
9172 * recovery and then call this routine before calling the .resume method
9173 * to recover the device. This function will initialize the HBA device,
9174 * enable the interrupt, but it will just put the HBA to offline state
9175 * without passing any I/O traffic.
9178 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9179 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9181 static pci_ers_result_t
9182 lpfc_io_slot_reset_s3(struct pci_dev
*pdev
)
9184 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9185 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9186 struct lpfc_sli
*psli
= &phba
->sli
;
9189 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
9190 if (pci_enable_device_mem(pdev
)) {
9191 printk(KERN_ERR
"lpfc: Cannot re-enable "
9192 "PCI device after reset.\n");
9193 return PCI_ERS_RESULT_DISCONNECT
;
9196 pci_restore_state(pdev
);
9199 * As the new kernel behavior of pci_restore_state() API call clears
9200 * device saved_state flag, need to save the restored state again.
9202 pci_save_state(pdev
);
9204 if (pdev
->is_busmaster
)
9205 pci_set_master(pdev
);
9207 spin_lock_irq(&phba
->hbalock
);
9208 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
9209 spin_unlock_irq(&phba
->hbalock
);
9211 /* Configure and enable interrupt */
9212 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
9213 if (intr_mode
== LPFC_INTR_ERROR
) {
9214 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9215 "0427 Cannot re-enable interrupt after "
9217 return PCI_ERS_RESULT_DISCONNECT
;
9219 phba
->intr_mode
= intr_mode
;
9221 /* Take device offline, it will perform cleanup */
9222 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
9224 lpfc_sli_brdrestart(phba
);
9226 /* Log the current active interrupt mode */
9227 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
9229 return PCI_ERS_RESULT_RECOVERED
;
9233 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
9234 * @pdev: pointer to PCI device
9236 * This routine is called from the PCI subsystem for error handling to device
9237 * with SLI-3 interface spec. It is called when kernel error recovery tells
9238 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
9239 * error recovery. After this call, traffic can start to flow from this device
9243 lpfc_io_resume_s3(struct pci_dev
*pdev
)
9245 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9246 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9248 /* Bring device online, it will be no-op for non-fatal error resume */
9251 /* Clean up Advanced Error Reporting (AER) if needed */
9252 if (phba
->hba_flag
& HBA_AER_ENABLED
)
9253 pci_cleanup_aer_uncorrect_error_status(pdev
);
9257 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
9258 * @phba: pointer to lpfc hba data structure.
9260 * returns the number of ELS/CT IOCBs to reserve
9263 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba
*phba
)
9265 int max_xri
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
9267 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9270 else if (max_xri
<= 256)
9272 else if (max_xri
<= 512)
9274 else if (max_xri
<= 1024)
9276 else if (max_xri
<= 1536)
9278 else if (max_xri
<= 2048)
9287 * lpfc_write_firmware - attempt to write a firmware image to the port
9288 * @phba: pointer to lpfc hba data structure.
9289 * @fw: pointer to firmware image returned from request_firmware.
9291 * returns the number of bytes written if write is successful.
9292 * returns a negative error value if there were errors.
9293 * returns 0 if firmware matches currently active firmware on port.
9296 lpfc_write_firmware(struct lpfc_hba
*phba
, const struct firmware
*fw
)
9298 char fwrev
[FW_REV_STR_SIZE
];
9299 struct lpfc_grp_hdr
*image
= (struct lpfc_grp_hdr
*)fw
->data
;
9300 struct list_head dma_buffer_list
;
9302 struct lpfc_dmabuf
*dmabuf
, *next
;
9303 uint32_t offset
= 0, temp_offset
= 0;
9305 INIT_LIST_HEAD(&dma_buffer_list
);
9306 if ((be32_to_cpu(image
->magic_number
) != LPFC_GROUP_OJECT_MAGIC_NUM
) ||
9307 (bf_get_be32(lpfc_grp_hdr_file_type
, image
) !=
9308 LPFC_FILE_TYPE_GROUP
) ||
9309 (bf_get_be32(lpfc_grp_hdr_id
, image
) != LPFC_FILE_ID_GROUP
) ||
9310 (be32_to_cpu(image
->size
) != fw
->size
)) {
9311 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9312 "3022 Invalid FW image found. "
9313 "Magic:%x Type:%x ID:%x\n",
9314 be32_to_cpu(image
->magic_number
),
9315 bf_get_be32(lpfc_grp_hdr_file_type
, image
),
9316 bf_get_be32(lpfc_grp_hdr_id
, image
));
9319 lpfc_decode_firmware_rev(phba
, fwrev
, 1);
9320 if (strncmp(fwrev
, image
->revision
, strnlen(image
->revision
, 16))) {
9321 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9322 "3023 Updating Firmware. Current Version:%s "
9324 fwrev
, image
->revision
);
9325 for (i
= 0; i
< LPFC_MBX_WR_CONFIG_MAX_BDE
; i
++) {
9326 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
),
9332 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
9336 if (!dmabuf
->virt
) {
9341 list_add_tail(&dmabuf
->list
, &dma_buffer_list
);
9343 while (offset
< fw
->size
) {
9344 temp_offset
= offset
;
9345 list_for_each_entry(dmabuf
, &dma_buffer_list
, list
) {
9346 if (temp_offset
+ SLI4_PAGE_SIZE
> fw
->size
) {
9347 memcpy(dmabuf
->virt
,
9348 fw
->data
+ temp_offset
,
9349 fw
->size
- temp_offset
);
9350 temp_offset
= fw
->size
;
9353 memcpy(dmabuf
->virt
, fw
->data
+ temp_offset
,
9355 temp_offset
+= SLI4_PAGE_SIZE
;
9357 rc
= lpfc_wr_object(phba
, &dma_buffer_list
,
9358 (fw
->size
- offset
), &offset
);
9360 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9361 "3024 Firmware update failed. "
9369 list_for_each_entry_safe(dmabuf
, next
, &dma_buffer_list
, list
) {
9370 list_del(&dmabuf
->list
);
9371 dma_free_coherent(&phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
9372 dmabuf
->virt
, dmabuf
->phys
);
9379 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
9380 * @pdev: pointer to PCI device
9381 * @pid: pointer to PCI device identifier
9383 * This routine is called from the kernel's PCI subsystem to device with
9384 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
9385 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9386 * information of the device and driver to see if the driver state that it
9387 * can support this kind of device. If the match is successful, the driver
9388 * core invokes this routine. If this routine determines it can claim the HBA,
9389 * it does all the initialization that it needs to do to handle the HBA
9393 * 0 - driver can claim the device
9394 * negative value - driver can not claim the device
9396 static int __devinit
9397 lpfc_pci_probe_one_s4(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
9399 struct lpfc_hba
*phba
;
9400 struct lpfc_vport
*vport
= NULL
;
9401 struct Scsi_Host
*shost
= NULL
;
9403 uint32_t cfg_mode
, intr_mode
;
9405 int adjusted_fcp_io_channel
;
9406 const struct firmware
*fw
;
9407 uint8_t file_name
[16];
9409 /* Allocate memory for HBA structure */
9410 phba
= lpfc_hba_alloc(pdev
);
9414 /* Perform generic PCI device enabling operation */
9415 error
= lpfc_enable_pci_dev(phba
);
9419 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
9420 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_OC
);
9422 goto out_disable_pci_dev
;
9424 /* Set up SLI-4 specific device PCI memory space */
9425 error
= lpfc_sli4_pci_mem_setup(phba
);
9427 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9428 "1410 Failed to set up pci memory space.\n");
9429 goto out_disable_pci_dev
;
9432 /* Set up phase-1 common device driver resources */
9433 error
= lpfc_setup_driver_resource_phase1(phba
);
9435 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9436 "1411 Failed to set up driver resource.\n");
9437 goto out_unset_pci_mem_s4
;
9440 /* Set up SLI-4 Specific device driver resources */
9441 error
= lpfc_sli4_driver_resource_setup(phba
);
9443 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9444 "1412 Failed to set up driver resource.\n");
9445 goto out_unset_pci_mem_s4
;
9448 /* Initialize and populate the iocb list per host */
9450 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9451 "2821 initialize iocb list %d.\n",
9452 phba
->cfg_iocb_cnt
*1024);
9453 error
= lpfc_init_iocb_list(phba
, phba
->cfg_iocb_cnt
*1024);
9456 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9457 "1413 Failed to initialize iocb list.\n");
9458 goto out_unset_driver_resource_s4
;
9461 INIT_LIST_HEAD(&phba
->active_rrq_list
);
9462 INIT_LIST_HEAD(&phba
->fcf
.fcf_pri_list
);
9464 /* Set up common device driver resources */
9465 error
= lpfc_setup_driver_resource_phase2(phba
);
9467 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9468 "1414 Failed to set up driver resource.\n");
9469 goto out_free_iocb_list
;
9472 /* Get the default values for Model Name and Description */
9473 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
9475 /* Create SCSI host to the physical port */
9476 error
= lpfc_create_shost(phba
);
9478 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9479 "1415 Failed to create scsi host.\n");
9480 goto out_unset_driver_resource
;
9483 /* Configure sysfs attributes */
9484 vport
= phba
->pport
;
9485 error
= lpfc_alloc_sysfs_attr(vport
);
9487 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9488 "1416 Failed to allocate sysfs attr\n");
9489 goto out_destroy_shost
;
9492 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
9493 /* Now, trying to enable interrupt and bring up the device */
9494 cfg_mode
= phba
->cfg_use_msi
;
9496 /* Put device to a known state before enabling interrupt */
9497 lpfc_stop_port(phba
);
9498 /* Configure and enable interrupt */
9499 intr_mode
= lpfc_sli4_enable_intr(phba
, cfg_mode
);
9500 if (intr_mode
== LPFC_INTR_ERROR
) {
9501 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9502 "0426 Failed to enable interrupt.\n");
9504 goto out_free_sysfs_attr
;
9506 /* Default to single EQ for non-MSI-X */
9507 if (phba
->intr_type
!= MSIX
)
9508 adjusted_fcp_io_channel
= 0;
9509 else if (phba
->sli4_hba
.msix_vec_nr
<
9510 phba
->cfg_fcp_io_channel
)
9511 adjusted_fcp_io_channel
= phba
->sli4_hba
.msix_vec_nr
;
9513 adjusted_fcp_io_channel
= phba
->cfg_fcp_io_channel
;
9514 phba
->cfg_fcp_io_channel
= adjusted_fcp_io_channel
;
9515 /* Set up SLI-4 HBA */
9516 if (lpfc_sli4_hba_setup(phba
)) {
9517 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9518 "1421 Failed to set up hba\n");
9520 goto out_disable_intr
;
9523 /* Send NOP mbx cmds for non-INTx mode active interrupt test */
9525 mcnt
= lpfc_sli4_send_nop_mbox_cmds(phba
,
9528 /* Check active interrupts received only for MSI/MSI-X */
9529 if (intr_mode
== 0 ||
9530 phba
->sli
.slistat
.sli_intr
>= LPFC_ACT_INTR_CNT
) {
9531 /* Log the current active interrupt mode */
9532 phba
->intr_mode
= intr_mode
;
9533 lpfc_log_intr_mode(phba
, intr_mode
);
9536 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9537 "0451 Configure interrupt mode (%d) "
9538 "failed active interrupt test.\n",
9540 /* Unset the previous SLI-4 HBA setup. */
9542 * TODO: Is this operation compatible with IF TYPE 2
9543 * devices? All port state is deleted and cleared.
9545 lpfc_sli4_unset_hba(phba
);
9546 /* Try next level of interrupt mode */
9547 cfg_mode
= --intr_mode
;
9550 /* Perform post initialization setup */
9551 lpfc_post_init_setup(phba
);
9553 /* check for firmware upgrade or downgrade (if_type 2 only) */
9554 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
9555 LPFC_SLI_INTF_IF_TYPE_2
) {
9556 snprintf(file_name
, 16, "%s.grp", phba
->ModelName
);
9557 error
= request_firmware(&fw
, file_name
, &phba
->pcidev
->dev
);
9559 lpfc_write_firmware(phba
, fw
);
9560 release_firmware(fw
);
9564 /* Check if there are static vports to be created. */
9565 lpfc_create_static_vport(phba
);
9569 lpfc_sli4_disable_intr(phba
);
9570 out_free_sysfs_attr
:
9571 lpfc_free_sysfs_attr(vport
);
9573 lpfc_destroy_shost(phba
);
9574 out_unset_driver_resource
:
9575 lpfc_unset_driver_resource_phase2(phba
);
9577 lpfc_free_iocb_list(phba
);
9578 out_unset_driver_resource_s4
:
9579 lpfc_sli4_driver_resource_unset(phba
);
9580 out_unset_pci_mem_s4
:
9581 lpfc_sli4_pci_mem_unset(phba
);
9582 out_disable_pci_dev
:
9583 lpfc_disable_pci_dev(phba
);
9585 scsi_host_put(shost
);
9587 lpfc_hba_free(phba
);
9592 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
9593 * @pdev: pointer to PCI device
9595 * This routine is called from the kernel's PCI subsystem to device with
9596 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
9597 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9598 * device to be removed from the PCI subsystem properly.
9600 static void __devexit
9601 lpfc_pci_remove_one_s4(struct pci_dev
*pdev
)
9603 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9604 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
9605 struct lpfc_vport
**vports
;
9606 struct lpfc_hba
*phba
= vport
->phba
;
9609 /* Mark the device unloading flag */
9610 spin_lock_irq(&phba
->hbalock
);
9611 vport
->load_flag
|= FC_UNLOADING
;
9612 spin_unlock_irq(&phba
->hbalock
);
9614 /* Free the HBA sysfs attributes */
9615 lpfc_free_sysfs_attr(vport
);
9617 /* Release all the vports against this physical port */
9618 vports
= lpfc_create_vport_work_array(phba
);
9620 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
9621 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
9623 fc_vport_terminate(vports
[i
]->fc_vport
);
9625 lpfc_destroy_vport_work_array(phba
, vports
);
9627 /* Remove FC host and then SCSI host with the physical port */
9628 fc_remove_host(shost
);
9629 scsi_remove_host(shost
);
9631 /* Perform cleanup on the physical port */
9632 lpfc_cleanup(vport
);
9635 * Bring down the SLI Layer. This step disables all interrupts,
9636 * clears the rings, discards all mailbox commands, and resets
9637 * the HBA FCoE function.
9639 lpfc_debugfs_terminate(vport
);
9640 lpfc_sli4_hba_unset(phba
);
9642 spin_lock_irq(&phba
->hbalock
);
9643 list_del_init(&vport
->listentry
);
9644 spin_unlock_irq(&phba
->hbalock
);
9646 /* Perform scsi free before driver resource_unset since scsi
9647 * buffers are released to their corresponding pools here.
9649 lpfc_scsi_free(phba
);
9651 lpfc_sli4_driver_resource_unset(phba
);
9653 /* Unmap adapter Control and Doorbell registers */
9654 lpfc_sli4_pci_mem_unset(phba
);
9656 /* Release PCI resources and disable device's PCI function */
9657 scsi_host_put(shost
);
9658 lpfc_disable_pci_dev(phba
);
9660 /* Finally, free the driver's device data structure */
9661 lpfc_hba_free(phba
);
9667 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
9668 * @pdev: pointer to PCI device
9669 * @msg: power management message
9671 * This routine is called from the kernel's PCI subsystem to support system
9672 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
9673 * this method, it quiesces the device by stopping the driver's worker
9674 * thread for the device, turning off device's interrupt and DMA, and bring
9675 * the device offline. Note that as the driver implements the minimum PM
9676 * requirements to a power-aware driver's PM support for suspend/resume -- all
9677 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
9678 * method call will be treated as SUSPEND and the driver will fully
9679 * reinitialize its device during resume() method call, the driver will set
9680 * device to PCI_D3hot state in PCI config space instead of setting it
9681 * according to the @msg provided by the PM.
9684 * 0 - driver suspended the device
9688 lpfc_pci_suspend_one_s4(struct pci_dev
*pdev
, pm_message_t msg
)
9690 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9691 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9693 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9694 "2843 PCI device Power Management suspend.\n");
9696 /* Bring down the device */
9697 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
9699 kthread_stop(phba
->worker_thread
);
9701 /* Disable interrupt from device */
9702 lpfc_sli4_disable_intr(phba
);
9703 lpfc_sli4_queue_destroy(phba
);
9705 /* Save device state to PCI config space */
9706 pci_save_state(pdev
);
9707 pci_set_power_state(pdev
, PCI_D3hot
);
9713 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
9714 * @pdev: pointer to PCI device
9716 * This routine is called from the kernel's PCI subsystem to support system
9717 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
9718 * this method, it restores the device's PCI config space state and fully
9719 * reinitializes the device and brings it online. Note that as the driver
9720 * implements the minimum PM requirements to a power-aware driver's PM for
9721 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9722 * to the suspend() method call will be treated as SUSPEND and the driver
9723 * will fully reinitialize its device during resume() method call, the device
9724 * will be set to PCI_D0 directly in PCI config space before restoring the
9728 * 0 - driver suspended the device
9732 lpfc_pci_resume_one_s4(struct pci_dev
*pdev
)
9734 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9735 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9739 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9740 "0292 PCI device Power Management resume.\n");
9742 /* Restore device state from PCI config space */
9743 pci_set_power_state(pdev
, PCI_D0
);
9744 pci_restore_state(pdev
);
9747 * As the new kernel behavior of pci_restore_state() API call clears
9748 * device saved_state flag, need to save the restored state again.
9750 pci_save_state(pdev
);
9752 if (pdev
->is_busmaster
)
9753 pci_set_master(pdev
);
9755 /* Startup the kernel thread for this host adapter. */
9756 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
9757 "lpfc_worker_%d", phba
->brd_no
);
9758 if (IS_ERR(phba
->worker_thread
)) {
9759 error
= PTR_ERR(phba
->worker_thread
);
9760 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9761 "0293 PM resume failed to start worker "
9762 "thread: error=x%x.\n", error
);
9766 /* Configure and enable interrupt */
9767 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
9768 if (intr_mode
== LPFC_INTR_ERROR
) {
9769 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9770 "0294 PM resume Failed to enable interrupt\n");
9773 phba
->intr_mode
= intr_mode
;
9775 /* Restart HBA and bring it online */
9776 lpfc_sli_brdrestart(phba
);
9779 /* Log the current active interrupt mode */
9780 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
9786 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
9787 * @phba: pointer to lpfc hba data structure.
9789 * This routine is called to prepare the SLI4 device for PCI slot recover. It
9790 * aborts all the outstanding SCSI I/Os to the pci device.
9793 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba
*phba
)
9795 struct lpfc_sli
*psli
= &phba
->sli
;
9796 struct lpfc_sli_ring
*pring
;
9798 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9799 "2828 PCI channel I/O abort preparing for recovery\n");
9801 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9802 * and let the SCSI mid-layer to retry them to recover.
9804 pring
= &psli
->ring
[psli
->fcp_ring
];
9805 lpfc_sli_abort_iocb_ring(phba
, pring
);
9809 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
9810 * @phba: pointer to lpfc hba data structure.
9812 * This routine is called to prepare the SLI4 device for PCI slot reset. It
9813 * disables the device interrupt and pci device, and aborts the internal FCP
9817 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba
*phba
)
9819 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9820 "2826 PCI channel disable preparing for reset\n");
9822 /* Block any management I/Os to the device */
9823 lpfc_block_mgmt_io(phba
, LPFC_MBX_NO_WAIT
);
9825 /* Block all SCSI devices' I/Os on the host */
9826 lpfc_scsi_dev_block(phba
);
9828 /* stop all timers */
9829 lpfc_stop_hba_timers(phba
);
9831 /* Disable interrupt and pci device */
9832 lpfc_sli4_disable_intr(phba
);
9833 lpfc_sli4_queue_destroy(phba
);
9834 pci_disable_device(phba
->pcidev
);
9836 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9837 lpfc_sli_flush_fcp_rings(phba
);
9841 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
9842 * @phba: pointer to lpfc hba data structure.
9844 * This routine is called to prepare the SLI4 device for PCI slot permanently
9845 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9849 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
9851 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9852 "2827 PCI channel permanent disable for failure\n");
9854 /* Block all SCSI devices' I/Os on the host */
9855 lpfc_scsi_dev_block(phba
);
9857 /* stop all timers */
9858 lpfc_stop_hba_timers(phba
);
9860 /* Clean up all driver's outstanding SCSI I/Os */
9861 lpfc_sli_flush_fcp_rings(phba
);
9865 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
9866 * @pdev: pointer to PCI device.
9867 * @state: the current PCI connection state.
9869 * This routine is called from the PCI subsystem for error handling to device
9870 * with SLI-4 interface spec. This function is called by the PCI subsystem
9871 * after a PCI bus error affecting this device has been detected. When this
9872 * function is invoked, it will need to stop all the I/Os and interrupt(s)
9873 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
9874 * for the PCI subsystem to perform proper recovery as desired.
9877 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9878 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9880 static pci_ers_result_t
9881 lpfc_io_error_detected_s4(struct pci_dev
*pdev
, pci_channel_state_t state
)
9883 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9884 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9887 case pci_channel_io_normal
:
9888 /* Non-fatal error, prepare for recovery */
9889 lpfc_sli4_prep_dev_for_recover(phba
);
9890 return PCI_ERS_RESULT_CAN_RECOVER
;
9891 case pci_channel_io_frozen
:
9892 /* Fatal error, prepare for slot reset */
9893 lpfc_sli4_prep_dev_for_reset(phba
);
9894 return PCI_ERS_RESULT_NEED_RESET
;
9895 case pci_channel_io_perm_failure
:
9896 /* Permanent failure, prepare for device down */
9897 lpfc_sli4_prep_dev_for_perm_failure(phba
);
9898 return PCI_ERS_RESULT_DISCONNECT
;
9900 /* Unknown state, prepare and request slot reset */
9901 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9902 "2825 Unknown PCI error state: x%x\n", state
);
9903 lpfc_sli4_prep_dev_for_reset(phba
);
9904 return PCI_ERS_RESULT_NEED_RESET
;
9909 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
9910 * @pdev: pointer to PCI device.
9912 * This routine is called from the PCI subsystem for error handling to device
9913 * with SLI-4 interface spec. It is called after PCI bus has been reset to
9914 * restart the PCI card from scratch, as if from a cold-boot. During the
9915 * PCI subsystem error recovery, after the driver returns
9916 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
9917 * recovery and then call this routine before calling the .resume method to
9918 * recover the device. This function will initialize the HBA device, enable
9919 * the interrupt, but it will just put the HBA to offline state without
9920 * passing any I/O traffic.
9923 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9924 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9926 static pci_ers_result_t
9927 lpfc_io_slot_reset_s4(struct pci_dev
*pdev
)
9929 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9930 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9931 struct lpfc_sli
*psli
= &phba
->sli
;
9934 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
9935 if (pci_enable_device_mem(pdev
)) {
9936 printk(KERN_ERR
"lpfc: Cannot re-enable "
9937 "PCI device after reset.\n");
9938 return PCI_ERS_RESULT_DISCONNECT
;
9941 pci_restore_state(pdev
);
9944 * As the new kernel behavior of pci_restore_state() API call clears
9945 * device saved_state flag, need to save the restored state again.
9947 pci_save_state(pdev
);
9949 if (pdev
->is_busmaster
)
9950 pci_set_master(pdev
);
9952 spin_lock_irq(&phba
->hbalock
);
9953 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
9954 spin_unlock_irq(&phba
->hbalock
);
9956 /* Configure and enable interrupt */
9957 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
9958 if (intr_mode
== LPFC_INTR_ERROR
) {
9959 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9960 "2824 Cannot re-enable interrupt after "
9962 return PCI_ERS_RESULT_DISCONNECT
;
9964 phba
->intr_mode
= intr_mode
;
9966 /* Log the current active interrupt mode */
9967 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
9969 return PCI_ERS_RESULT_RECOVERED
;
9973 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
9974 * @pdev: pointer to PCI device
9976 * This routine is called from the PCI subsystem for error handling to device
9977 * with SLI-4 interface spec. It is called when kernel error recovery tells
9978 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
9979 * error recovery. After this call, traffic can start to flow from this device
9983 lpfc_io_resume_s4(struct pci_dev
*pdev
)
9985 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9986 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9989 * In case of slot reset, as function reset is performed through
9990 * mailbox command which needs DMA to be enabled, this operation
9991 * has to be moved to the io resume phase. Taking device offline
9992 * will perform the necessary cleanup.
9994 if (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)) {
9995 /* Perform device reset */
9996 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
9998 lpfc_sli_brdrestart(phba
);
9999 /* Bring the device back online */
10003 /* Clean up Advanced Error Reporting (AER) if needed */
10004 if (phba
->hba_flag
& HBA_AER_ENABLED
)
10005 pci_cleanup_aer_uncorrect_error_status(pdev
);
10009 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
10010 * @pdev: pointer to PCI device
10011 * @pid: pointer to PCI device identifier
10013 * This routine is to be registered to the kernel's PCI subsystem. When an
10014 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
10015 * at PCI device-specific information of the device and driver to see if the
10016 * driver state that it can support this kind of device. If the match is
10017 * successful, the driver core invokes this routine. This routine dispatches
10018 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
10019 * do all the initialization that it needs to do to handle the HBA device
10023 * 0 - driver can claim the device
10024 * negative value - driver can not claim the device
10026 static int __devinit
10027 lpfc_pci_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
10030 struct lpfc_sli_intf intf
;
10032 if (pci_read_config_dword(pdev
, LPFC_SLI_INTF
, &intf
.word0
))
10035 if ((bf_get(lpfc_sli_intf_valid
, &intf
) == LPFC_SLI_INTF_VALID
) &&
10036 (bf_get(lpfc_sli_intf_slirev
, &intf
) == LPFC_SLI_INTF_REV_SLI4
))
10037 rc
= lpfc_pci_probe_one_s4(pdev
, pid
);
10039 rc
= lpfc_pci_probe_one_s3(pdev
, pid
);
10045 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
10046 * @pdev: pointer to PCI device
10048 * This routine is to be registered to the kernel's PCI subsystem. When an
10049 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
10050 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
10051 * remove routine, which will perform all the necessary cleanup for the
10052 * device to be removed from the PCI subsystem properly.
10054 static void __devexit
10055 lpfc_pci_remove_one(struct pci_dev
*pdev
)
10057 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10058 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10060 switch (phba
->pci_dev_grp
) {
10061 case LPFC_PCI_DEV_LP
:
10062 lpfc_pci_remove_one_s3(pdev
);
10064 case LPFC_PCI_DEV_OC
:
10065 lpfc_pci_remove_one_s4(pdev
);
10068 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10069 "1424 Invalid PCI device group: 0x%x\n",
10070 phba
->pci_dev_grp
);
10077 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
10078 * @pdev: pointer to PCI device
10079 * @msg: power management message
10081 * This routine is to be registered to the kernel's PCI subsystem to support
10082 * system Power Management (PM). When PM invokes this method, it dispatches
10083 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
10084 * suspend the device.
10087 * 0 - driver suspended the device
10091 lpfc_pci_suspend_one(struct pci_dev
*pdev
, pm_message_t msg
)
10093 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10094 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10097 switch (phba
->pci_dev_grp
) {
10098 case LPFC_PCI_DEV_LP
:
10099 rc
= lpfc_pci_suspend_one_s3(pdev
, msg
);
10101 case LPFC_PCI_DEV_OC
:
10102 rc
= lpfc_pci_suspend_one_s4(pdev
, msg
);
10105 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10106 "1425 Invalid PCI device group: 0x%x\n",
10107 phba
->pci_dev_grp
);
10114 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
10115 * @pdev: pointer to PCI device
10117 * This routine is to be registered to the kernel's PCI subsystem to support
10118 * system Power Management (PM). When PM invokes this method, it dispatches
10119 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
10120 * resume the device.
10123 * 0 - driver suspended the device
10127 lpfc_pci_resume_one(struct pci_dev
*pdev
)
10129 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10130 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10133 switch (phba
->pci_dev_grp
) {
10134 case LPFC_PCI_DEV_LP
:
10135 rc
= lpfc_pci_resume_one_s3(pdev
);
10137 case LPFC_PCI_DEV_OC
:
10138 rc
= lpfc_pci_resume_one_s4(pdev
);
10141 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10142 "1426 Invalid PCI device group: 0x%x\n",
10143 phba
->pci_dev_grp
);
10150 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
10151 * @pdev: pointer to PCI device.
10152 * @state: the current PCI connection state.
10154 * This routine is registered to the PCI subsystem for error handling. This
10155 * function is called by the PCI subsystem after a PCI bus error affecting
10156 * this device has been detected. When this routine is invoked, it dispatches
10157 * the action to the proper SLI-3 or SLI-4 device error detected handling
10158 * routine, which will perform the proper error detected operation.
10161 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10162 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10164 static pci_ers_result_t
10165 lpfc_io_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
10167 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10168 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10169 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
10171 switch (phba
->pci_dev_grp
) {
10172 case LPFC_PCI_DEV_LP
:
10173 rc
= lpfc_io_error_detected_s3(pdev
, state
);
10175 case LPFC_PCI_DEV_OC
:
10176 rc
= lpfc_io_error_detected_s4(pdev
, state
);
10179 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10180 "1427 Invalid PCI device group: 0x%x\n",
10181 phba
->pci_dev_grp
);
10188 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
10189 * @pdev: pointer to PCI device.
10191 * This routine is registered to the PCI subsystem for error handling. This
10192 * function is called after PCI bus has been reset to restart the PCI card
10193 * from scratch, as if from a cold-boot. When this routine is invoked, it
10194 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
10195 * routine, which will perform the proper device reset.
10198 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10199 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10201 static pci_ers_result_t
10202 lpfc_io_slot_reset(struct pci_dev
*pdev
)
10204 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10205 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10206 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
10208 switch (phba
->pci_dev_grp
) {
10209 case LPFC_PCI_DEV_LP
:
10210 rc
= lpfc_io_slot_reset_s3(pdev
);
10212 case LPFC_PCI_DEV_OC
:
10213 rc
= lpfc_io_slot_reset_s4(pdev
);
10216 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10217 "1428 Invalid PCI device group: 0x%x\n",
10218 phba
->pci_dev_grp
);
10225 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
10226 * @pdev: pointer to PCI device
10228 * This routine is registered to the PCI subsystem for error handling. It
10229 * is called when kernel error recovery tells the lpfc driver that it is
10230 * OK to resume normal PCI operation after PCI bus error recovery. When
10231 * this routine is invoked, it dispatches the action to the proper SLI-3
10232 * or SLI-4 device io_resume routine, which will resume the device operation.
10235 lpfc_io_resume(struct pci_dev
*pdev
)
10237 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10238 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10240 switch (phba
->pci_dev_grp
) {
10241 case LPFC_PCI_DEV_LP
:
10242 lpfc_io_resume_s3(pdev
);
10244 case LPFC_PCI_DEV_OC
:
10245 lpfc_io_resume_s4(pdev
);
10248 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10249 "1429 Invalid PCI device group: 0x%x\n",
10250 phba
->pci_dev_grp
);
10257 * lpfc_mgmt_open - method called when 'lpfcmgmt' is opened from userspace
10258 * @inode: pointer to the inode representing the lpfcmgmt device
10259 * @filep: pointer to the file representing the open lpfcmgmt device
10261 * This routine puts a reference count on the lpfc module whenever the
10262 * character device is opened
10265 lpfc_mgmt_open(struct inode
*inode
, struct file
*filep
)
10267 try_module_get(THIS_MODULE
);
10272 * lpfc_mgmt_release - method called when 'lpfcmgmt' is closed in userspace
10273 * @inode: pointer to the inode representing the lpfcmgmt device
10274 * @filep: pointer to the file representing the open lpfcmgmt device
10276 * This routine removes a reference count from the lpfc module when the
10277 * character device is closed
10280 lpfc_mgmt_release(struct inode
*inode
, struct file
*filep
)
10282 module_put(THIS_MODULE
);
10286 static struct pci_device_id lpfc_id_table
[] = {
10287 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_VIPER
,
10288 PCI_ANY_ID
, PCI_ANY_ID
, },
10289 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_FIREFLY
,
10290 PCI_ANY_ID
, PCI_ANY_ID
, },
10291 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_THOR
,
10292 PCI_ANY_ID
, PCI_ANY_ID
, },
10293 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PEGASUS
,
10294 PCI_ANY_ID
, PCI_ANY_ID
, },
10295 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_CENTAUR
,
10296 PCI_ANY_ID
, PCI_ANY_ID
, },
10297 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_DRAGONFLY
,
10298 PCI_ANY_ID
, PCI_ANY_ID
, },
10299 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SUPERFLY
,
10300 PCI_ANY_ID
, PCI_ANY_ID
, },
10301 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_RFLY
,
10302 PCI_ANY_ID
, PCI_ANY_ID
, },
10303 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PFLY
,
10304 PCI_ANY_ID
, PCI_ANY_ID
, },
10305 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE
,
10306 PCI_ANY_ID
, PCI_ANY_ID
, },
10307 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_SCSP
,
10308 PCI_ANY_ID
, PCI_ANY_ID
, },
10309 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_DCSP
,
10310 PCI_ANY_ID
, PCI_ANY_ID
, },
10311 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS
,
10312 PCI_ANY_ID
, PCI_ANY_ID
, },
10313 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_SCSP
,
10314 PCI_ANY_ID
, PCI_ANY_ID
, },
10315 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_DCSP
,
10316 PCI_ANY_ID
, PCI_ANY_ID
, },
10317 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BMID
,
10318 PCI_ANY_ID
, PCI_ANY_ID
, },
10319 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BSMB
,
10320 PCI_ANY_ID
, PCI_ANY_ID
, },
10321 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR
,
10322 PCI_ANY_ID
, PCI_ANY_ID
, },
10323 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HORNET
,
10324 PCI_ANY_ID
, PCI_ANY_ID
, },
10325 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_SCSP
,
10326 PCI_ANY_ID
, PCI_ANY_ID
, },
10327 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_DCSP
,
10328 PCI_ANY_ID
, PCI_ANY_ID
, },
10329 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZMID
,
10330 PCI_ANY_ID
, PCI_ANY_ID
, },
10331 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZSMB
,
10332 PCI_ANY_ID
, PCI_ANY_ID
, },
10333 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_TFLY
,
10334 PCI_ANY_ID
, PCI_ANY_ID
, },
10335 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP101
,
10336 PCI_ANY_ID
, PCI_ANY_ID
, },
10337 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP10000S
,
10338 PCI_ANY_ID
, PCI_ANY_ID
, },
10339 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP11000S
,
10340 PCI_ANY_ID
, PCI_ANY_ID
, },
10341 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LPE11000S
,
10342 PCI_ANY_ID
, PCI_ANY_ID
, },
10343 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT
,
10344 PCI_ANY_ID
, PCI_ANY_ID
, },
10345 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_MID
,
10346 PCI_ANY_ID
, PCI_ANY_ID
, },
10347 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SMB
,
10348 PCI_ANY_ID
, PCI_ANY_ID
, },
10349 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_DCSP
,
10350 PCI_ANY_ID
, PCI_ANY_ID
, },
10351 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SCSP
,
10352 PCI_ANY_ID
, PCI_ANY_ID
, },
10353 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_S
,
10354 PCI_ANY_ID
, PCI_ANY_ID
, },
10355 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_VF
,
10356 PCI_ANY_ID
, PCI_ANY_ID
, },
10357 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_PF
,
10358 PCI_ANY_ID
, PCI_ANY_ID
, },
10359 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_S
,
10360 PCI_ANY_ID
, PCI_ANY_ID
, },
10361 {PCI_VENDOR_ID_SERVERENGINE
, PCI_DEVICE_ID_TIGERSHARK
,
10362 PCI_ANY_ID
, PCI_ANY_ID
, },
10363 {PCI_VENDOR_ID_SERVERENGINE
, PCI_DEVICE_ID_TOMCAT
,
10364 PCI_ANY_ID
, PCI_ANY_ID
, },
10365 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_FALCON
,
10366 PCI_ANY_ID
, PCI_ANY_ID
, },
10367 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BALIUS
,
10368 PCI_ANY_ID
, PCI_ANY_ID
, },
10369 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FC
,
10370 PCI_ANY_ID
, PCI_ANY_ID
, },
10371 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FCOE
,
10372 PCI_ANY_ID
, PCI_ANY_ID
, },
10373 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FC_VF
,
10374 PCI_ANY_ID
, PCI_ANY_ID
, },
10375 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FCOE_VF
,
10376 PCI_ANY_ID
, PCI_ANY_ID
, },
10377 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SKYHAWK
,
10378 PCI_ANY_ID
, PCI_ANY_ID
, },
10379 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SKYHAWK_VF
,
10380 PCI_ANY_ID
, PCI_ANY_ID
, },
10384 MODULE_DEVICE_TABLE(pci
, lpfc_id_table
);
10386 static struct pci_error_handlers lpfc_err_handler
= {
10387 .error_detected
= lpfc_io_error_detected
,
10388 .slot_reset
= lpfc_io_slot_reset
,
10389 .resume
= lpfc_io_resume
,
10392 static struct pci_driver lpfc_driver
= {
10393 .name
= LPFC_DRIVER_NAME
,
10394 .id_table
= lpfc_id_table
,
10395 .probe
= lpfc_pci_probe_one
,
10396 .remove
= __devexit_p(lpfc_pci_remove_one
),
10397 .suspend
= lpfc_pci_suspend_one
,
10398 .resume
= lpfc_pci_resume_one
,
10399 .err_handler
= &lpfc_err_handler
,
10402 static const struct file_operations lpfc_mgmt_fop
= {
10403 .open
= lpfc_mgmt_open
,
10404 .release
= lpfc_mgmt_release
,
10407 static struct miscdevice lpfc_mgmt_dev
= {
10408 .minor
= MISC_DYNAMIC_MINOR
,
10409 .name
= "lpfcmgmt",
10410 .fops
= &lpfc_mgmt_fop
,
10414 * lpfc_init - lpfc module initialization routine
10416 * This routine is to be invoked when the lpfc module is loaded into the
10417 * kernel. The special kernel macro module_init() is used to indicate the
10418 * role of this routine to the kernel as lpfc module entry point.
10422 * -ENOMEM - FC attach transport failed
10423 * all others - failed
10430 printk(LPFC_MODULE_DESC
"\n");
10431 printk(LPFC_COPYRIGHT
"\n");
10433 error
= misc_register(&lpfc_mgmt_dev
);
10435 printk(KERN_ERR
"Could not register lpfcmgmt device, "
10436 "misc_register returned with status %d", error
);
10438 if (lpfc_enable_npiv
) {
10439 lpfc_transport_functions
.vport_create
= lpfc_vport_create
;
10440 lpfc_transport_functions
.vport_delete
= lpfc_vport_delete
;
10442 lpfc_transport_template
=
10443 fc_attach_transport(&lpfc_transport_functions
);
10444 if (lpfc_transport_template
== NULL
)
10446 if (lpfc_enable_npiv
) {
10447 lpfc_vport_transport_template
=
10448 fc_attach_transport(&lpfc_vport_transport_functions
);
10449 if (lpfc_vport_transport_template
== NULL
) {
10450 fc_release_transport(lpfc_transport_template
);
10454 error
= pci_register_driver(&lpfc_driver
);
10456 fc_release_transport(lpfc_transport_template
);
10457 if (lpfc_enable_npiv
)
10458 fc_release_transport(lpfc_vport_transport_template
);
10465 * lpfc_exit - lpfc module removal routine
10467 * This routine is invoked when the lpfc module is removed from the kernel.
10468 * The special kernel macro module_exit() is used to indicate the role of
10469 * this routine to the kernel as lpfc module exit point.
10474 misc_deregister(&lpfc_mgmt_dev
);
10475 pci_unregister_driver(&lpfc_driver
);
10476 fc_release_transport(lpfc_transport_template
);
10477 if (lpfc_enable_npiv
)
10478 fc_release_transport(lpfc_vport_transport_template
);
10479 if (_dump_buf_data
) {
10480 printk(KERN_ERR
"9062 BLKGRD: freeing %lu pages for "
10481 "_dump_buf_data at 0x%p\n",
10482 (1L << _dump_buf_data_order
), _dump_buf_data
);
10483 free_pages((unsigned long)_dump_buf_data
, _dump_buf_data_order
);
10486 if (_dump_buf_dif
) {
10487 printk(KERN_ERR
"9049 BLKGRD: freeing %lu pages for "
10488 "_dump_buf_dif at 0x%p\n",
10489 (1L << _dump_buf_dif_order
), _dump_buf_dif
);
10490 free_pages((unsigned long)_dump_buf_dif
, _dump_buf_dif_order
);
10494 module_init(lpfc_init
);
10495 module_exit(lpfc_exit
);
10496 MODULE_LICENSE("GPL");
10497 MODULE_DESCRIPTION(LPFC_MODULE_DESC
);
10498 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
10499 MODULE_VERSION("0:" LPFC_DRIVER_VERSION
);