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
)
1895 else if (phba
->lmt
& LMT_1Gb
)
1903 case PCI_DEVICE_ID_FIREFLY
:
1904 m
= (typeof(m
)){"LP6000", "PCI", "Fibre Channel Adapter"};
1906 case PCI_DEVICE_ID_SUPERFLY
:
1907 if (vp
->rev
.biuRev
>= 1 && vp
->rev
.biuRev
<= 3)
1908 m
= (typeof(m
)){"LP7000", "PCI",
1909 "Fibre Channel Adapter"};
1911 m
= (typeof(m
)){"LP7000E", "PCI",
1912 "Fibre Channel Adapter"};
1914 case PCI_DEVICE_ID_DRAGONFLY
:
1915 m
= (typeof(m
)){"LP8000", "PCI",
1916 "Fibre Channel Adapter"};
1918 case PCI_DEVICE_ID_CENTAUR
:
1919 if (FC_JEDEC_ID(vp
->rev
.biuRev
) == CENTAUR_2G_JEDEC_ID
)
1920 m
= (typeof(m
)){"LP9002", "PCI",
1921 "Fibre Channel Adapter"};
1923 m
= (typeof(m
)){"LP9000", "PCI",
1924 "Fibre Channel Adapter"};
1926 case PCI_DEVICE_ID_RFLY
:
1927 m
= (typeof(m
)){"LP952", "PCI",
1928 "Fibre Channel Adapter"};
1930 case PCI_DEVICE_ID_PEGASUS
:
1931 m
= (typeof(m
)){"LP9802", "PCI-X",
1932 "Fibre Channel Adapter"};
1934 case PCI_DEVICE_ID_THOR
:
1935 m
= (typeof(m
)){"LP10000", "PCI-X",
1936 "Fibre Channel Adapter"};
1938 case PCI_DEVICE_ID_VIPER
:
1939 m
= (typeof(m
)){"LPX1000", "PCI-X",
1940 "Fibre Channel Adapter"};
1942 case PCI_DEVICE_ID_PFLY
:
1943 m
= (typeof(m
)){"LP982", "PCI-X",
1944 "Fibre Channel Adapter"};
1946 case PCI_DEVICE_ID_TFLY
:
1947 m
= (typeof(m
)){"LP1050", "PCI-X",
1948 "Fibre Channel Adapter"};
1950 case PCI_DEVICE_ID_HELIOS
:
1951 m
= (typeof(m
)){"LP11000", "PCI-X2",
1952 "Fibre Channel Adapter"};
1954 case PCI_DEVICE_ID_HELIOS_SCSP
:
1955 m
= (typeof(m
)){"LP11000-SP", "PCI-X2",
1956 "Fibre Channel Adapter"};
1958 case PCI_DEVICE_ID_HELIOS_DCSP
:
1959 m
= (typeof(m
)){"LP11002-SP", "PCI-X2",
1960 "Fibre Channel Adapter"};
1962 case PCI_DEVICE_ID_NEPTUNE
:
1963 m
= (typeof(m
)){"LPe1000", "PCIe", "Fibre Channel Adapter"};
1965 case PCI_DEVICE_ID_NEPTUNE_SCSP
:
1966 m
= (typeof(m
)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"};
1968 case PCI_DEVICE_ID_NEPTUNE_DCSP
:
1969 m
= (typeof(m
)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"};
1971 case PCI_DEVICE_ID_BMID
:
1972 m
= (typeof(m
)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
1974 case PCI_DEVICE_ID_BSMB
:
1975 m
= (typeof(m
)){"LP111", "PCI-X2", "Fibre Channel Adapter"};
1977 case PCI_DEVICE_ID_ZEPHYR
:
1978 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
1980 case PCI_DEVICE_ID_ZEPHYR_SCSP
:
1981 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
1983 case PCI_DEVICE_ID_ZEPHYR_DCSP
:
1984 m
= (typeof(m
)){"LP2105", "PCIe", "FCoE Adapter"};
1987 case PCI_DEVICE_ID_ZMID
:
1988 m
= (typeof(m
)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
1990 case PCI_DEVICE_ID_ZSMB
:
1991 m
= (typeof(m
)){"LPe111", "PCIe", "Fibre Channel Adapter"};
1993 case PCI_DEVICE_ID_LP101
:
1994 m
= (typeof(m
)){"LP101", "PCI-X", "Fibre Channel Adapter"};
1996 case PCI_DEVICE_ID_LP10000S
:
1997 m
= (typeof(m
)){"LP10000-S", "PCI", "Fibre Channel Adapter"};
1999 case PCI_DEVICE_ID_LP11000S
:
2000 m
= (typeof(m
)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"};
2002 case PCI_DEVICE_ID_LPE11000S
:
2003 m
= (typeof(m
)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"};
2005 case PCI_DEVICE_ID_SAT
:
2006 m
= (typeof(m
)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2008 case PCI_DEVICE_ID_SAT_MID
:
2009 m
= (typeof(m
)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2011 case PCI_DEVICE_ID_SAT_SMB
:
2012 m
= (typeof(m
)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2014 case PCI_DEVICE_ID_SAT_DCSP
:
2015 m
= (typeof(m
)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2017 case PCI_DEVICE_ID_SAT_SCSP
:
2018 m
= (typeof(m
)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2020 case PCI_DEVICE_ID_SAT_S
:
2021 m
= (typeof(m
)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2023 case PCI_DEVICE_ID_HORNET
:
2024 m
= (typeof(m
)){"LP21000", "PCIe", "FCoE Adapter"};
2027 case PCI_DEVICE_ID_PROTEUS_VF
:
2028 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
2029 "Fibre Channel Adapter"};
2031 case PCI_DEVICE_ID_PROTEUS_PF
:
2032 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
2033 "Fibre Channel Adapter"};
2035 case PCI_DEVICE_ID_PROTEUS_S
:
2036 m
= (typeof(m
)){"LPemv12002-S", "PCIe IOV",
2037 "Fibre Channel Adapter"};
2039 case PCI_DEVICE_ID_TIGERSHARK
:
2041 m
= (typeof(m
)){"OCe10100", "PCIe", "FCoE"};
2043 case PCI_DEVICE_ID_TOMCAT
:
2045 m
= (typeof(m
)){"OCe11100", "PCIe", "FCoE"};
2047 case PCI_DEVICE_ID_FALCON
:
2048 m
= (typeof(m
)){"LPSe12002-ML1-E", "PCIe",
2049 "EmulexSecure Fibre"};
2051 case PCI_DEVICE_ID_BALIUS
:
2052 m
= (typeof(m
)){"LPVe12002", "PCIe Shared I/O",
2053 "Fibre Channel Adapter"};
2055 case PCI_DEVICE_ID_LANCER_FC
:
2056 case PCI_DEVICE_ID_LANCER_FC_VF
:
2057 m
= (typeof(m
)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2059 case PCI_DEVICE_ID_LANCER_FCOE
:
2060 case PCI_DEVICE_ID_LANCER_FCOE_VF
:
2062 m
= (typeof(m
)){"OCe15100", "PCIe", "FCoE"};
2064 case PCI_DEVICE_ID_SKYHAWK
:
2065 case PCI_DEVICE_ID_SKYHAWK_VF
:
2067 m
= (typeof(m
)){"OCe14000", "PCIe", "FCoE"};
2070 m
= (typeof(m
)){"Unknown", "", ""};
2074 if (mdp
&& mdp
[0] == '\0')
2075 snprintf(mdp
, 79,"%s", m
.name
);
2077 * oneConnect hba requires special processing, they are all initiators
2078 * and we put the port number on the end
2080 if (descp
&& descp
[0] == '\0') {
2082 snprintf(descp
, 255,
2083 "Emulex OneConnect %s, %s Initiator %s",
2086 else if (max_speed
== 0)
2087 snprintf(descp
, 255,
2089 m
.name
, m
.bus
, m
.function
);
2091 snprintf(descp
, 255,
2092 "Emulex %s %d%s %s %s",
2093 m
.name
, max_speed
, (GE
) ? "GE" : "Gb",
2099 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2100 * @phba: pointer to lpfc hba data structure.
2101 * @pring: pointer to a IOCB ring.
2102 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2104 * This routine posts a given number of IOCBs with the associated DMA buffer
2105 * descriptors specified by the cnt argument to the given IOCB ring.
2108 * The number of IOCBs NOT able to be posted to the IOCB ring.
2111 lpfc_post_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
, int cnt
)
2114 struct lpfc_iocbq
*iocb
;
2115 struct lpfc_dmabuf
*mp1
, *mp2
;
2117 cnt
+= pring
->missbufcnt
;
2119 /* While there are buffers to post */
2121 /* Allocate buffer for command iocb */
2122 iocb
= lpfc_sli_get_iocbq(phba
);
2124 pring
->missbufcnt
= cnt
;
2129 /* 2 buffers can be posted per command */
2130 /* Allocate buffer to post */
2131 mp1
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
2133 mp1
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &mp1
->phys
);
2134 if (!mp1
|| !mp1
->virt
) {
2136 lpfc_sli_release_iocbq(phba
, iocb
);
2137 pring
->missbufcnt
= cnt
;
2141 INIT_LIST_HEAD(&mp1
->list
);
2142 /* Allocate buffer to post */
2144 mp2
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
2146 mp2
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
2148 if (!mp2
|| !mp2
->virt
) {
2150 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
2152 lpfc_sli_release_iocbq(phba
, iocb
);
2153 pring
->missbufcnt
= cnt
;
2157 INIT_LIST_HEAD(&mp2
->list
);
2162 icmd
->un
.cont64
[0].addrHigh
= putPaddrHigh(mp1
->phys
);
2163 icmd
->un
.cont64
[0].addrLow
= putPaddrLow(mp1
->phys
);
2164 icmd
->un
.cont64
[0].tus
.f
.bdeSize
= FCELSSIZE
;
2165 icmd
->ulpBdeCount
= 1;
2168 icmd
->un
.cont64
[1].addrHigh
= putPaddrHigh(mp2
->phys
);
2169 icmd
->un
.cont64
[1].addrLow
= putPaddrLow(mp2
->phys
);
2170 icmd
->un
.cont64
[1].tus
.f
.bdeSize
= FCELSSIZE
;
2172 icmd
->ulpBdeCount
= 2;
2175 icmd
->ulpCommand
= CMD_QUE_RING_BUF64_CN
;
2178 if (lpfc_sli_issue_iocb(phba
, pring
->ringno
, iocb
, 0) ==
2180 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
2184 lpfc_mbuf_free(phba
, mp2
->virt
, mp2
->phys
);
2188 lpfc_sli_release_iocbq(phba
, iocb
);
2189 pring
->missbufcnt
= cnt
;
2192 lpfc_sli_ringpostbuf_put(phba
, pring
, mp1
);
2194 lpfc_sli_ringpostbuf_put(phba
, pring
, mp2
);
2196 pring
->missbufcnt
= 0;
2201 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2202 * @phba: pointer to lpfc hba data structure.
2204 * This routine posts initial receive IOCB buffers to the ELS ring. The
2205 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2209 * 0 - success (currently always success)
2212 lpfc_post_rcv_buf(struct lpfc_hba
*phba
)
2214 struct lpfc_sli
*psli
= &phba
->sli
;
2216 /* Ring 0, ELS / CT buffers */
2217 lpfc_post_buffer(phba
, &psli
->ring
[LPFC_ELS_RING
], LPFC_BUF_RING0
);
2218 /* Ring 2 - FCP no buffers needed */
2223 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2226 * lpfc_sha_init - Set up initial array of hash table entries
2227 * @HashResultPointer: pointer to an array as hash table.
2229 * This routine sets up the initial values to the array of hash table entries
2233 lpfc_sha_init(uint32_t * HashResultPointer
)
2235 HashResultPointer
[0] = 0x67452301;
2236 HashResultPointer
[1] = 0xEFCDAB89;
2237 HashResultPointer
[2] = 0x98BADCFE;
2238 HashResultPointer
[3] = 0x10325476;
2239 HashResultPointer
[4] = 0xC3D2E1F0;
2243 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2244 * @HashResultPointer: pointer to an initial/result hash table.
2245 * @HashWorkingPointer: pointer to an working hash table.
2247 * This routine iterates an initial hash table pointed by @HashResultPointer
2248 * with the values from the working hash table pointeed by @HashWorkingPointer.
2249 * The results are putting back to the initial hash table, returned through
2250 * the @HashResultPointer as the result hash table.
2253 lpfc_sha_iterate(uint32_t * HashResultPointer
, uint32_t * HashWorkingPointer
)
2257 uint32_t A
, B
, C
, D
, E
;
2260 HashWorkingPointer
[t
] =
2262 HashWorkingPointer
[t
- 3] ^ HashWorkingPointer
[t
-
2264 HashWorkingPointer
[t
- 14] ^ HashWorkingPointer
[t
- 16]);
2265 } while (++t
<= 79);
2267 A
= HashResultPointer
[0];
2268 B
= HashResultPointer
[1];
2269 C
= HashResultPointer
[2];
2270 D
= HashResultPointer
[3];
2271 E
= HashResultPointer
[4];
2275 TEMP
= ((B
& C
) | ((~B
) & D
)) + 0x5A827999;
2276 } else if (t
< 40) {
2277 TEMP
= (B
^ C
^ D
) + 0x6ED9EBA1;
2278 } else if (t
< 60) {
2279 TEMP
= ((B
& C
) | (B
& D
) | (C
& D
)) + 0x8F1BBCDC;
2281 TEMP
= (B
^ C
^ D
) + 0xCA62C1D6;
2283 TEMP
+= S(5, A
) + E
+ HashWorkingPointer
[t
];
2289 } while (++t
<= 79);
2291 HashResultPointer
[0] += A
;
2292 HashResultPointer
[1] += B
;
2293 HashResultPointer
[2] += C
;
2294 HashResultPointer
[3] += D
;
2295 HashResultPointer
[4] += E
;
2300 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2301 * @RandomChallenge: pointer to the entry of host challenge random number array.
2302 * @HashWorking: pointer to the entry of the working hash array.
2304 * This routine calculates the working hash array referred by @HashWorking
2305 * from the challenge random numbers associated with the host, referred by
2306 * @RandomChallenge. The result is put into the entry of the working hash
2307 * array and returned by reference through @HashWorking.
2310 lpfc_challenge_key(uint32_t * RandomChallenge
, uint32_t * HashWorking
)
2312 *HashWorking
= (*RandomChallenge
^ *HashWorking
);
2316 * lpfc_hba_init - Perform special handling for LC HBA initialization
2317 * @phba: pointer to lpfc hba data structure.
2318 * @hbainit: pointer to an array of unsigned 32-bit integers.
2320 * This routine performs the special handling for LC HBA initialization.
2323 lpfc_hba_init(struct lpfc_hba
*phba
, uint32_t *hbainit
)
2326 uint32_t *HashWorking
;
2327 uint32_t *pwwnn
= (uint32_t *) phba
->wwnn
;
2329 HashWorking
= kcalloc(80, sizeof(uint32_t), GFP_KERNEL
);
2333 HashWorking
[0] = HashWorking
[78] = *pwwnn
++;
2334 HashWorking
[1] = HashWorking
[79] = *pwwnn
;
2336 for (t
= 0; t
< 7; t
++)
2337 lpfc_challenge_key(phba
->RandomData
+ t
, HashWorking
+ t
);
2339 lpfc_sha_init(hbainit
);
2340 lpfc_sha_iterate(hbainit
, HashWorking
);
2345 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2346 * @vport: pointer to a virtual N_Port data structure.
2348 * This routine performs the necessary cleanups before deleting the @vport.
2349 * It invokes the discovery state machine to perform necessary state
2350 * transitions and to release the ndlps associated with the @vport. Note,
2351 * the physical port is treated as @vport 0.
2354 lpfc_cleanup(struct lpfc_vport
*vport
)
2356 struct lpfc_hba
*phba
= vport
->phba
;
2357 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2360 if (phba
->link_state
> LPFC_LINK_DOWN
)
2361 lpfc_port_link_failure(vport
);
2363 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2364 if (!NLP_CHK_NODE_ACT(ndlp
)) {
2365 ndlp
= lpfc_enable_node(vport
, ndlp
,
2366 NLP_STE_UNUSED_NODE
);
2369 spin_lock_irq(&phba
->ndlp_lock
);
2370 NLP_SET_FREE_REQ(ndlp
);
2371 spin_unlock_irq(&phba
->ndlp_lock
);
2372 /* Trigger the release of the ndlp memory */
2376 spin_lock_irq(&phba
->ndlp_lock
);
2377 if (NLP_CHK_FREE_REQ(ndlp
)) {
2378 /* The ndlp should not be in memory free mode already */
2379 spin_unlock_irq(&phba
->ndlp_lock
);
2382 /* Indicate request for freeing ndlp memory */
2383 NLP_SET_FREE_REQ(ndlp
);
2384 spin_unlock_irq(&phba
->ndlp_lock
);
2386 if (vport
->port_type
!= LPFC_PHYSICAL_PORT
&&
2387 ndlp
->nlp_DID
== Fabric_DID
) {
2388 /* Just free up ndlp with Fabric_DID for vports */
2393 /* take care of nodes in unused state before the state
2394 * machine taking action.
2396 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
2401 if (ndlp
->nlp_type
& NLP_FABRIC
)
2402 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2403 NLP_EVT_DEVICE_RECOVERY
);
2405 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2409 /* At this point, ALL ndlp's should be gone
2410 * because of the previous NLP_EVT_DEVICE_RM.
2411 * Lets wait for this to happen, if needed.
2413 while (!list_empty(&vport
->fc_nodes
)) {
2415 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2416 "0233 Nodelist not empty\n");
2417 list_for_each_entry_safe(ndlp
, next_ndlp
,
2418 &vport
->fc_nodes
, nlp_listp
) {
2419 lpfc_printf_vlog(ndlp
->vport
, KERN_ERR
,
2421 "0282 did:x%x ndlp:x%p "
2422 "usgmap:x%x refcnt:%d\n",
2423 ndlp
->nlp_DID
, (void *)ndlp
,
2426 &ndlp
->kref
.refcount
));
2431 /* Wait for any activity on ndlps to settle */
2434 lpfc_cleanup_vports_rrqs(vport
, NULL
);
2438 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2439 * @vport: pointer to a virtual N_Port data structure.
2441 * This routine stops all the timers associated with a @vport. This function
2442 * is invoked before disabling or deleting a @vport. Note that the physical
2443 * port is treated as @vport 0.
2446 lpfc_stop_vport_timers(struct lpfc_vport
*vport
)
2448 del_timer_sync(&vport
->els_tmofunc
);
2449 del_timer_sync(&vport
->fc_fdmitmo
);
2450 del_timer_sync(&vport
->delayed_disc_tmo
);
2451 lpfc_can_disctmo(vport
);
2456 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2457 * @phba: pointer to lpfc hba data structure.
2459 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2460 * caller of this routine should already hold the host lock.
2463 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2465 /* Clear pending FCF rediscovery wait flag */
2466 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_PEND
;
2468 /* Now, try to stop the timer */
2469 del_timer(&phba
->fcf
.redisc_wait
);
2473 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2474 * @phba: pointer to lpfc hba data structure.
2476 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2477 * checks whether the FCF rediscovery wait timer is pending with the host
2478 * lock held before proceeding with disabling the timer and clearing the
2479 * wait timer pendig flag.
2482 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2484 spin_lock_irq(&phba
->hbalock
);
2485 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
2486 /* FCF rediscovery timer already fired or stopped */
2487 spin_unlock_irq(&phba
->hbalock
);
2490 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
2491 /* Clear failover in progress flags */
2492 phba
->fcf
.fcf_flag
&= ~(FCF_DEAD_DISC
| FCF_ACVL_DISC
);
2493 spin_unlock_irq(&phba
->hbalock
);
2497 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2498 * @phba: pointer to lpfc hba data structure.
2500 * This routine stops all the timers associated with a HBA. This function is
2501 * invoked before either putting a HBA offline or unloading the driver.
2504 lpfc_stop_hba_timers(struct lpfc_hba
*phba
)
2506 lpfc_stop_vport_timers(phba
->pport
);
2507 del_timer_sync(&phba
->sli
.mbox_tmo
);
2508 del_timer_sync(&phba
->fabric_block_timer
);
2509 del_timer_sync(&phba
->eratt_poll
);
2510 del_timer_sync(&phba
->hb_tmofunc
);
2511 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2512 del_timer_sync(&phba
->rrq_tmr
);
2513 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
2515 phba
->hb_outstanding
= 0;
2517 switch (phba
->pci_dev_grp
) {
2518 case LPFC_PCI_DEV_LP
:
2519 /* Stop any LightPulse device specific driver timers */
2520 del_timer_sync(&phba
->fcp_poll_timer
);
2522 case LPFC_PCI_DEV_OC
:
2523 /* Stop any OneConnect device sepcific driver timers */
2524 lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
2527 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2528 "0297 Invalid device group (x%x)\n",
2536 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
2537 * @phba: pointer to lpfc hba data structure.
2539 * This routine marks a HBA's management interface as blocked. Once the HBA's
2540 * management interface is marked as blocked, all the user space access to
2541 * the HBA, whether they are from sysfs interface or libdfc interface will
2542 * all be blocked. The HBA is set to block the management interface when the
2543 * driver prepares the HBA interface for online or offline.
2546 lpfc_block_mgmt_io(struct lpfc_hba
*phba
, int mbx_action
)
2548 unsigned long iflag
;
2549 uint8_t actcmd
= MBX_HEARTBEAT
;
2550 unsigned long timeout
;
2552 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2553 phba
->sli
.sli_flag
|= LPFC_BLOCK_MGMT_IO
;
2554 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2555 if (mbx_action
== LPFC_MBX_NO_WAIT
)
2557 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
2558 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2559 if (phba
->sli
.mbox_active
) {
2560 actcmd
= phba
->sli
.mbox_active
->u
.mb
.mbxCommand
;
2561 /* Determine how long we might wait for the active mailbox
2562 * command to be gracefully completed by firmware.
2564 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
2565 phba
->sli
.mbox_active
) * 1000) + jiffies
;
2567 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2569 /* Wait for the outstnading mailbox command to complete */
2570 while (phba
->sli
.mbox_active
) {
2571 /* Check active mailbox complete status every 2ms */
2573 if (time_after(jiffies
, timeout
)) {
2574 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2575 "2813 Mgmt IO is Blocked %x "
2576 "- mbox cmd %x still active\n",
2577 phba
->sli
.sli_flag
, actcmd
);
2584 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2585 * @phba: pointer to lpfc hba data structure.
2587 * Allocate RPIs for all active remote nodes. This is needed whenever
2588 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2589 * is to fixup the temporary rpi assignments.
2592 lpfc_sli4_node_prep(struct lpfc_hba
*phba
)
2594 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2595 struct lpfc_vport
**vports
;
2598 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
2601 vports
= lpfc_create_vport_work_array(phba
);
2602 if (vports
!= NULL
) {
2603 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2604 if (vports
[i
]->load_flag
& FC_UNLOADING
)
2607 list_for_each_entry_safe(ndlp
, next_ndlp
,
2608 &vports
[i
]->fc_nodes
,
2610 if (NLP_CHK_NODE_ACT(ndlp
))
2612 lpfc_sli4_alloc_rpi(phba
);
2616 lpfc_destroy_vport_work_array(phba
, vports
);
2620 * lpfc_online - Initialize and bring a HBA online
2621 * @phba: pointer to lpfc hba data structure.
2623 * This routine initializes the HBA and brings a HBA online. During this
2624 * process, the management interface is blocked to prevent user space access
2625 * to the HBA interfering with the driver initialization.
2632 lpfc_online(struct lpfc_hba
*phba
)
2634 struct lpfc_vport
*vport
;
2635 struct lpfc_vport
**vports
;
2640 vport
= phba
->pport
;
2642 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
))
2645 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2646 "0458 Bring Adapter online\n");
2648 lpfc_block_mgmt_io(phba
, LPFC_MBX_WAIT
);
2650 if (!lpfc_sli_queue_setup(phba
)) {
2651 lpfc_unblock_mgmt_io(phba
);
2655 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2656 if (lpfc_sli4_hba_setup(phba
)) { /* Initialize SLI4 HBA */
2657 lpfc_unblock_mgmt_io(phba
);
2661 if (lpfc_sli_hba_setup(phba
)) { /* Initialize SLI2/SLI3 HBA */
2662 lpfc_unblock_mgmt_io(phba
);
2667 vports
= lpfc_create_vport_work_array(phba
);
2669 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2670 struct Scsi_Host
*shost
;
2671 shost
= lpfc_shost_from_vport(vports
[i
]);
2672 spin_lock_irq(shost
->host_lock
);
2673 vports
[i
]->fc_flag
&= ~FC_OFFLINE_MODE
;
2674 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
2675 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2676 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2677 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
2678 spin_unlock_irq(shost
->host_lock
);
2680 lpfc_destroy_vport_work_array(phba
, vports
);
2682 lpfc_unblock_mgmt_io(phba
);
2687 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
2688 * @phba: pointer to lpfc hba data structure.
2690 * This routine marks a HBA's management interface as not blocked. Once the
2691 * HBA's management interface is marked as not blocked, all the user space
2692 * access to the HBA, whether they are from sysfs interface or libdfc
2693 * interface will be allowed. The HBA is set to block the management interface
2694 * when the driver prepares the HBA interface for online or offline and then
2695 * set to unblock the management interface afterwards.
2698 lpfc_unblock_mgmt_io(struct lpfc_hba
* phba
)
2700 unsigned long iflag
;
2702 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2703 phba
->sli
.sli_flag
&= ~LPFC_BLOCK_MGMT_IO
;
2704 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2708 * lpfc_offline_prep - Prepare a HBA to be brought offline
2709 * @phba: pointer to lpfc hba data structure.
2711 * This routine is invoked to prepare a HBA to be brought offline. It performs
2712 * unregistration login to all the nodes on all vports and flushes the mailbox
2713 * queue to make it ready to be brought offline.
2716 lpfc_offline_prep(struct lpfc_hba
*phba
, int mbx_action
)
2718 struct lpfc_vport
*vport
= phba
->pport
;
2719 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2720 struct lpfc_vport
**vports
;
2721 struct Scsi_Host
*shost
;
2724 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
2727 lpfc_block_mgmt_io(phba
, mbx_action
);
2729 lpfc_linkdown(phba
);
2731 /* Issue an unreg_login to all nodes on all vports */
2732 vports
= lpfc_create_vport_work_array(phba
);
2733 if (vports
!= NULL
) {
2734 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2735 if (vports
[i
]->load_flag
& FC_UNLOADING
)
2737 shost
= lpfc_shost_from_vport(vports
[i
]);
2738 spin_lock_irq(shost
->host_lock
);
2739 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
2740 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2741 vports
[i
]->fc_flag
&= ~FC_VFI_REGISTERED
;
2742 spin_unlock_irq(shost
->host_lock
);
2744 shost
= lpfc_shost_from_vport(vports
[i
]);
2745 list_for_each_entry_safe(ndlp
, next_ndlp
,
2746 &vports
[i
]->fc_nodes
,
2748 if (!NLP_CHK_NODE_ACT(ndlp
))
2750 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
2752 if (ndlp
->nlp_type
& NLP_FABRIC
) {
2753 lpfc_disc_state_machine(vports
[i
], ndlp
,
2754 NULL
, NLP_EVT_DEVICE_RECOVERY
);
2755 lpfc_disc_state_machine(vports
[i
], ndlp
,
2756 NULL
, NLP_EVT_DEVICE_RM
);
2758 spin_lock_irq(shost
->host_lock
);
2759 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2760 spin_unlock_irq(shost
->host_lock
);
2762 * Whenever an SLI4 port goes offline, free the
2763 * RPI. Get a new RPI when the adapter port
2764 * comes back online.
2766 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2767 lpfc_sli4_free_rpi(phba
, ndlp
->nlp_rpi
);
2768 lpfc_unreg_rpi(vports
[i
], ndlp
);
2772 lpfc_destroy_vport_work_array(phba
, vports
);
2774 lpfc_sli_mbox_sys_shutdown(phba
, mbx_action
);
2778 * lpfc_offline - Bring a HBA offline
2779 * @phba: pointer to lpfc hba data structure.
2781 * This routine actually brings a HBA offline. It stops all the timers
2782 * associated with the HBA, brings down the SLI layer, and eventually
2783 * marks the HBA as in offline state for the upper layer protocol.
2786 lpfc_offline(struct lpfc_hba
*phba
)
2788 struct Scsi_Host
*shost
;
2789 struct lpfc_vport
**vports
;
2792 if (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
2795 /* stop port and all timers associated with this hba */
2796 lpfc_stop_port(phba
);
2797 vports
= lpfc_create_vport_work_array(phba
);
2799 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
2800 lpfc_stop_vport_timers(vports
[i
]);
2801 lpfc_destroy_vport_work_array(phba
, vports
);
2802 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2803 "0460 Bring Adapter offline\n");
2804 /* Bring down the SLI Layer and cleanup. The HBA is offline
2806 lpfc_sli_hba_down(phba
);
2807 spin_lock_irq(&phba
->hbalock
);
2809 spin_unlock_irq(&phba
->hbalock
);
2810 vports
= lpfc_create_vport_work_array(phba
);
2812 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2813 shost
= lpfc_shost_from_vport(vports
[i
]);
2814 spin_lock_irq(shost
->host_lock
);
2815 vports
[i
]->work_port_events
= 0;
2816 vports
[i
]->fc_flag
|= FC_OFFLINE_MODE
;
2817 spin_unlock_irq(shost
->host_lock
);
2819 lpfc_destroy_vport_work_array(phba
, vports
);
2823 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
2824 * @phba: pointer to lpfc hba data structure.
2826 * This routine is to free all the SCSI buffers and IOCBs from the driver
2827 * list back to kernel. It is called from lpfc_pci_remove_one to free
2828 * the internal resources before the device is removed from the system.
2831 lpfc_scsi_free(struct lpfc_hba
*phba
)
2833 struct lpfc_scsi_buf
*sb
, *sb_next
;
2834 struct lpfc_iocbq
*io
, *io_next
;
2836 spin_lock_irq(&phba
->hbalock
);
2837 /* Release all the lpfc_scsi_bufs maintained by this host. */
2838 spin_lock(&phba
->scsi_buf_list_lock
);
2839 list_for_each_entry_safe(sb
, sb_next
, &phba
->lpfc_scsi_buf_list
, list
) {
2840 list_del(&sb
->list
);
2841 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
, sb
->data
,
2844 phba
->total_scsi_bufs
--;
2846 spin_unlock(&phba
->scsi_buf_list_lock
);
2848 /* Release all the lpfc_iocbq entries maintained by this host. */
2849 list_for_each_entry_safe(io
, io_next
, &phba
->lpfc_iocb_list
, list
) {
2850 list_del(&io
->list
);
2852 phba
->total_iocbq_bufs
--;
2855 spin_unlock_irq(&phba
->hbalock
);
2859 * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
2860 * @phba: pointer to lpfc hba data structure.
2862 * This routine first calculates the sizes of the current els and allocated
2863 * scsi sgl lists, and then goes through all sgls to updates the physical
2864 * XRIs assigned due to port function reset. During port initialization, the
2865 * current els and allocated scsi sgl lists are 0s.
2868 * 0 - successful (for now, it always returns 0)
2871 lpfc_sli4_xri_sgl_update(struct lpfc_hba
*phba
)
2873 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_entry_next
= NULL
;
2874 struct lpfc_scsi_buf
*psb
= NULL
, *psb_next
= NULL
;
2875 uint16_t i
, lxri
, xri_cnt
, els_xri_cnt
, scsi_xri_cnt
;
2876 LIST_HEAD(els_sgl_list
);
2877 LIST_HEAD(scsi_sgl_list
);
2881 * update on pci function's els xri-sgl list
2883 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
2884 if (els_xri_cnt
> phba
->sli4_hba
.els_xri_cnt
) {
2885 /* els xri-sgl expanded */
2886 xri_cnt
= els_xri_cnt
- phba
->sli4_hba
.els_xri_cnt
;
2887 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2888 "3157 ELS xri-sgl count increased from "
2889 "%d to %d\n", phba
->sli4_hba
.els_xri_cnt
,
2891 /* allocate the additional els sgls */
2892 for (i
= 0; i
< xri_cnt
; i
++) {
2893 sglq_entry
= kzalloc(sizeof(struct lpfc_sglq
),
2895 if (sglq_entry
== NULL
) {
2896 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2897 "2562 Failure to allocate an "
2898 "ELS sgl entry:%d\n", i
);
2902 sglq_entry
->buff_type
= GEN_BUFF_TYPE
;
2903 sglq_entry
->virt
= lpfc_mbuf_alloc(phba
, 0,
2905 if (sglq_entry
->virt
== NULL
) {
2907 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2908 "2563 Failure to allocate an "
2909 "ELS mbuf:%d\n", i
);
2913 sglq_entry
->sgl
= sglq_entry
->virt
;
2914 memset(sglq_entry
->sgl
, 0, LPFC_BPL_SIZE
);
2915 sglq_entry
->state
= SGL_FREED
;
2916 list_add_tail(&sglq_entry
->list
, &els_sgl_list
);
2918 spin_lock(&phba
->hbalock
);
2919 list_splice_init(&els_sgl_list
, &phba
->sli4_hba
.lpfc_sgl_list
);
2920 spin_unlock(&phba
->hbalock
);
2921 } else if (els_xri_cnt
< phba
->sli4_hba
.els_xri_cnt
) {
2922 /* els xri-sgl shrinked */
2923 xri_cnt
= phba
->sli4_hba
.els_xri_cnt
- els_xri_cnt
;
2924 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2925 "3158 ELS xri-sgl count decreased from "
2926 "%d to %d\n", phba
->sli4_hba
.els_xri_cnt
,
2928 spin_lock_irq(&phba
->hbalock
);
2929 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &els_sgl_list
);
2930 spin_unlock_irq(&phba
->hbalock
);
2931 /* release extra els sgls from list */
2932 for (i
= 0; i
< xri_cnt
; i
++) {
2933 list_remove_head(&els_sgl_list
,
2934 sglq_entry
, struct lpfc_sglq
, list
);
2936 lpfc_mbuf_free(phba
, sglq_entry
->virt
,
2941 spin_lock_irq(&phba
->hbalock
);
2942 list_splice_init(&els_sgl_list
, &phba
->sli4_hba
.lpfc_sgl_list
);
2943 spin_unlock_irq(&phba
->hbalock
);
2945 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2946 "3163 ELS xri-sgl count unchanged: %d\n",
2948 phba
->sli4_hba
.els_xri_cnt
= els_xri_cnt
;
2950 /* update xris to els sgls on the list */
2952 sglq_entry_next
= NULL
;
2953 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
2954 &phba
->sli4_hba
.lpfc_sgl_list
, list
) {
2955 lxri
= lpfc_sli4_next_xritag(phba
);
2956 if (lxri
== NO_XRI
) {
2957 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2958 "2400 Failed to allocate xri for "
2963 sglq_entry
->sli4_lxritag
= lxri
;
2964 sglq_entry
->sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
2968 * update on pci function's allocated scsi xri-sgl list
2970 phba
->total_scsi_bufs
= 0;
2972 /* maximum number of xris available for scsi buffers */
2973 phba
->sli4_hba
.scsi_xri_max
= phba
->sli4_hba
.max_cfg_param
.max_xri
-
2976 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2977 "2401 Current allocated SCSI xri-sgl count:%d, "
2978 "maximum SCSI xri count:%d\n",
2979 phba
->sli4_hba
.scsi_xri_cnt
,
2980 phba
->sli4_hba
.scsi_xri_max
);
2982 spin_lock_irq(&phba
->scsi_buf_list_lock
);
2983 list_splice_init(&phba
->lpfc_scsi_buf_list
, &scsi_sgl_list
);
2984 spin_unlock_irq(&phba
->scsi_buf_list_lock
);
2986 if (phba
->sli4_hba
.scsi_xri_cnt
> phba
->sli4_hba
.scsi_xri_max
) {
2987 /* max scsi xri shrinked below the allocated scsi buffers */
2988 scsi_xri_cnt
= phba
->sli4_hba
.scsi_xri_cnt
-
2989 phba
->sli4_hba
.scsi_xri_max
;
2990 /* release the extra allocated scsi buffers */
2991 for (i
= 0; i
< scsi_xri_cnt
; i
++) {
2992 list_remove_head(&scsi_sgl_list
, psb
,
2993 struct lpfc_scsi_buf
, list
);
2994 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
, psb
->data
,
2998 spin_lock_irq(&phba
->scsi_buf_list_lock
);
2999 phba
->sli4_hba
.scsi_xri_cnt
-= scsi_xri_cnt
;
3000 spin_unlock_irq(&phba
->scsi_buf_list_lock
);
3003 /* update xris associated to remaining allocated scsi buffers */
3006 list_for_each_entry_safe(psb
, psb_next
, &scsi_sgl_list
, list
) {
3007 lxri
= lpfc_sli4_next_xritag(phba
);
3008 if (lxri
== NO_XRI
) {
3009 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3010 "2560 Failed to allocate xri for "
3015 psb
->cur_iocbq
.sli4_lxritag
= lxri
;
3016 psb
->cur_iocbq
.sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
3018 spin_lock(&phba
->scsi_buf_list_lock
);
3019 list_splice_init(&scsi_sgl_list
, &phba
->lpfc_scsi_buf_list
);
3020 spin_unlock(&phba
->scsi_buf_list_lock
);
3025 lpfc_free_els_sgl_list(phba
);
3026 lpfc_scsi_free(phba
);
3031 * lpfc_create_port - Create an FC port
3032 * @phba: pointer to lpfc hba data structure.
3033 * @instance: a unique integer ID to this FC port.
3034 * @dev: pointer to the device data structure.
3036 * This routine creates a FC port for the upper layer protocol. The FC port
3037 * can be created on top of either a physical port or a virtual port provided
3038 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3039 * and associates the FC port created before adding the shost into the SCSI
3043 * @vport - pointer to the virtual N_Port data structure.
3044 * NULL - port create failed.
3047 lpfc_create_port(struct lpfc_hba
*phba
, int instance
, struct device
*dev
)
3049 struct lpfc_vport
*vport
;
3050 struct Scsi_Host
*shost
;
3053 if (dev
!= &phba
->pcidev
->dev
)
3054 shost
= scsi_host_alloc(&lpfc_vport_template
,
3055 sizeof(struct lpfc_vport
));
3057 shost
= scsi_host_alloc(&lpfc_template
,
3058 sizeof(struct lpfc_vport
));
3062 vport
= (struct lpfc_vport
*) shost
->hostdata
;
3064 vport
->load_flag
|= FC_LOADING
;
3065 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
3066 vport
->fc_rscn_flush
= 0;
3068 lpfc_get_vport_cfgparam(vport
);
3069 shost
->unique_id
= instance
;
3070 shost
->max_id
= LPFC_MAX_TARGET
;
3071 shost
->max_lun
= vport
->cfg_max_luns
;
3072 shost
->this_id
= -1;
3073 shost
->max_cmd_len
= 16;
3074 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3075 shost
->dma_boundary
=
3076 phba
->sli4_hba
.pc_sli4_params
.sge_supp_len
-1;
3077 shost
->sg_tablesize
= phba
->cfg_sg_seg_cnt
;
3081 * Set initial can_queue value since 0 is no longer supported and
3082 * scsi_add_host will fail. This will be adjusted later based on the
3083 * max xri value determined in hba setup.
3085 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
3086 if (dev
!= &phba
->pcidev
->dev
) {
3087 shost
->transportt
= lpfc_vport_transport_template
;
3088 vport
->port_type
= LPFC_NPIV_PORT
;
3090 shost
->transportt
= lpfc_transport_template
;
3091 vport
->port_type
= LPFC_PHYSICAL_PORT
;
3094 /* Initialize all internally managed lists. */
3095 INIT_LIST_HEAD(&vport
->fc_nodes
);
3096 INIT_LIST_HEAD(&vport
->rcv_buffer_list
);
3097 spin_lock_init(&vport
->work_port_lock
);
3099 init_timer(&vport
->fc_disctmo
);
3100 vport
->fc_disctmo
.function
= lpfc_disc_timeout
;
3101 vport
->fc_disctmo
.data
= (unsigned long)vport
;
3103 init_timer(&vport
->fc_fdmitmo
);
3104 vport
->fc_fdmitmo
.function
= lpfc_fdmi_tmo
;
3105 vport
->fc_fdmitmo
.data
= (unsigned long)vport
;
3107 init_timer(&vport
->els_tmofunc
);
3108 vport
->els_tmofunc
.function
= lpfc_els_timeout
;
3109 vport
->els_tmofunc
.data
= (unsigned long)vport
;
3111 init_timer(&vport
->delayed_disc_tmo
);
3112 vport
->delayed_disc_tmo
.function
= lpfc_delayed_disc_tmo
;
3113 vport
->delayed_disc_tmo
.data
= (unsigned long)vport
;
3115 error
= scsi_add_host_with_dma(shost
, dev
, &phba
->pcidev
->dev
);
3119 spin_lock_irq(&phba
->hbalock
);
3120 list_add_tail(&vport
->listentry
, &phba
->port_list
);
3121 spin_unlock_irq(&phba
->hbalock
);
3125 scsi_host_put(shost
);
3131 * destroy_port - destroy an FC port
3132 * @vport: pointer to an lpfc virtual N_Port data structure.
3134 * This routine destroys a FC port from the upper layer protocol. All the
3135 * resources associated with the port are released.
3138 destroy_port(struct lpfc_vport
*vport
)
3140 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3141 struct lpfc_hba
*phba
= vport
->phba
;
3143 lpfc_debugfs_terminate(vport
);
3144 fc_remove_host(shost
);
3145 scsi_remove_host(shost
);
3147 spin_lock_irq(&phba
->hbalock
);
3148 list_del_init(&vport
->listentry
);
3149 spin_unlock_irq(&phba
->hbalock
);
3151 lpfc_cleanup(vport
);
3156 * lpfc_get_instance - Get a unique integer ID
3158 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3159 * uses the kernel idr facility to perform the task.
3162 * instance - a unique integer ID allocated as the new instance.
3163 * -1 - lpfc get instance failed.
3166 lpfc_get_instance(void)
3170 /* Assign an unused number */
3171 if (!idr_pre_get(&lpfc_hba_index
, GFP_KERNEL
))
3173 if (idr_get_new(&lpfc_hba_index
, NULL
, &instance
))
3179 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
3180 * @shost: pointer to SCSI host data structure.
3181 * @time: elapsed time of the scan in jiffies.
3183 * This routine is called by the SCSI layer with a SCSI host to determine
3184 * whether the scan host is finished.
3186 * Note: there is no scan_start function as adapter initialization will have
3187 * asynchronously kicked off the link initialization.
3190 * 0 - SCSI host scan is not over yet.
3191 * 1 - SCSI host scan is over.
3193 int lpfc_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
3195 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3196 struct lpfc_hba
*phba
= vport
->phba
;
3199 spin_lock_irq(shost
->host_lock
);
3201 if (vport
->load_flag
& FC_UNLOADING
) {
3205 if (time
>= 30 * HZ
) {
3206 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3207 "0461 Scanning longer than 30 "
3208 "seconds. Continuing initialization\n");
3212 if (time
>= 15 * HZ
&& phba
->link_state
<= LPFC_LINK_DOWN
) {
3213 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3214 "0465 Link down longer than 15 "
3215 "seconds. Continuing initialization\n");
3220 if (vport
->port_state
!= LPFC_VPORT_READY
)
3222 if (vport
->num_disc_nodes
|| vport
->fc_prli_sent
)
3224 if (vport
->fc_map_cnt
== 0 && time
< 2 * HZ
)
3226 if ((phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) != 0)
3232 spin_unlock_irq(shost
->host_lock
);
3237 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
3238 * @shost: pointer to SCSI host data structure.
3240 * This routine initializes a given SCSI host attributes on a FC port. The
3241 * SCSI host can be either on top of a physical port or a virtual port.
3243 void lpfc_host_attrib_init(struct Scsi_Host
*shost
)
3245 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3246 struct lpfc_hba
*phba
= vport
->phba
;
3248 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
3251 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
3252 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
3253 fc_host_supported_classes(shost
) = FC_COS_CLASS3
;
3255 memset(fc_host_supported_fc4s(shost
), 0,
3256 sizeof(fc_host_supported_fc4s(shost
)));
3257 fc_host_supported_fc4s(shost
)[2] = 1;
3258 fc_host_supported_fc4s(shost
)[7] = 1;
3260 lpfc_vport_symbolic_node_name(vport
, fc_host_symbolic_name(shost
),
3261 sizeof fc_host_symbolic_name(shost
));
3263 fc_host_supported_speeds(shost
) = 0;
3264 if (phba
->lmt
& LMT_16Gb
)
3265 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_16GBIT
;
3266 if (phba
->lmt
& LMT_10Gb
)
3267 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_10GBIT
;
3268 if (phba
->lmt
& LMT_8Gb
)
3269 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_8GBIT
;
3270 if (phba
->lmt
& LMT_4Gb
)
3271 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_4GBIT
;
3272 if (phba
->lmt
& LMT_2Gb
)
3273 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_2GBIT
;
3274 if (phba
->lmt
& LMT_1Gb
)
3275 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_1GBIT
;
3277 fc_host_maxframe_size(shost
) =
3278 (((uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
3279 (uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeLsb
;
3281 fc_host_dev_loss_tmo(shost
) = vport
->cfg_devloss_tmo
;
3283 /* This value is also unchanging */
3284 memset(fc_host_active_fc4s(shost
), 0,
3285 sizeof(fc_host_active_fc4s(shost
)));
3286 fc_host_active_fc4s(shost
)[2] = 1;
3287 fc_host_active_fc4s(shost
)[7] = 1;
3289 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
3290 spin_lock_irq(shost
->host_lock
);
3291 vport
->load_flag
&= ~FC_LOADING
;
3292 spin_unlock_irq(shost
->host_lock
);
3296 * lpfc_stop_port_s3 - Stop SLI3 device port
3297 * @phba: pointer to lpfc hba data structure.
3299 * This routine is invoked to stop an SLI3 device port, it stops the device
3300 * from generating interrupts and stops the device driver's timers for the
3304 lpfc_stop_port_s3(struct lpfc_hba
*phba
)
3306 /* Clear all interrupt enable conditions */
3307 writel(0, phba
->HCregaddr
);
3308 readl(phba
->HCregaddr
); /* flush */
3309 /* Clear all pending interrupts */
3310 writel(0xffffffff, phba
->HAregaddr
);
3311 readl(phba
->HAregaddr
); /* flush */
3313 /* Reset some HBA SLI setup states */
3314 lpfc_stop_hba_timers(phba
);
3315 phba
->pport
->work_port_events
= 0;
3319 * lpfc_stop_port_s4 - Stop SLI4 device port
3320 * @phba: pointer to lpfc hba data structure.
3322 * This routine is invoked to stop an SLI4 device port, it stops the device
3323 * from generating interrupts and stops the device driver's timers for the
3327 lpfc_stop_port_s4(struct lpfc_hba
*phba
)
3329 /* Reset some HBA SLI4 setup states */
3330 lpfc_stop_hba_timers(phba
);
3331 phba
->pport
->work_port_events
= 0;
3332 phba
->sli4_hba
.intr_enable
= 0;
3336 * lpfc_stop_port - Wrapper function for stopping hba port
3337 * @phba: Pointer to HBA context object.
3339 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3340 * the API jump table function pointer from the lpfc_hba struct.
3343 lpfc_stop_port(struct lpfc_hba
*phba
)
3345 phba
->lpfc_stop_port(phba
);
3349 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3350 * @phba: Pointer to hba for which this call is being executed.
3352 * This routine starts the timer waiting for the FCF rediscovery to complete.
3355 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba
*phba
)
3357 unsigned long fcf_redisc_wait_tmo
=
3358 (jiffies
+ msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO
));
3359 /* Start fcf rediscovery wait period timer */
3360 mod_timer(&phba
->fcf
.redisc_wait
, fcf_redisc_wait_tmo
);
3361 spin_lock_irq(&phba
->hbalock
);
3362 /* Allow action to new fcf asynchronous event */
3363 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
3364 /* Mark the FCF rediscovery pending state */
3365 phba
->fcf
.fcf_flag
|= FCF_REDISC_PEND
;
3366 spin_unlock_irq(&phba
->hbalock
);
3370 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3371 * @ptr: Map to lpfc_hba data structure pointer.
3373 * This routine is invoked when waiting for FCF table rediscover has been
3374 * timed out. If new FCF record(s) has (have) been discovered during the
3375 * wait period, a new FCF event shall be added to the FCOE async event
3376 * list, and then worker thread shall be waked up for processing from the
3377 * worker thread context.
3380 lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr
)
3382 struct lpfc_hba
*phba
= (struct lpfc_hba
*)ptr
;
3384 /* Don't send FCF rediscovery event if timer cancelled */
3385 spin_lock_irq(&phba
->hbalock
);
3386 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
3387 spin_unlock_irq(&phba
->hbalock
);
3390 /* Clear FCF rediscovery timer pending flag */
3391 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_PEND
;
3392 /* FCF rediscovery event to worker thread */
3393 phba
->fcf
.fcf_flag
|= FCF_REDISC_EVT
;
3394 spin_unlock_irq(&phba
->hbalock
);
3395 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
3396 "2776 FCF rediscover quiescent timer expired\n");
3397 /* wake up worker thread */
3398 lpfc_worker_wake_up(phba
);
3402 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3403 * @phba: pointer to lpfc hba data structure.
3404 * @acqe_link: pointer to the async link completion queue entry.
3406 * This routine is to parse the SLI4 link-attention link fault code and
3407 * translate it into the base driver's read link attention mailbox command
3410 * Return: Link-attention status in terms of base driver's coding.
3413 lpfc_sli4_parse_latt_fault(struct lpfc_hba
*phba
,
3414 struct lpfc_acqe_link
*acqe_link
)
3416 uint16_t latt_fault
;
3418 switch (bf_get(lpfc_acqe_link_fault
, acqe_link
)) {
3419 case LPFC_ASYNC_LINK_FAULT_NONE
:
3420 case LPFC_ASYNC_LINK_FAULT_LOCAL
:
3421 case LPFC_ASYNC_LINK_FAULT_REMOTE
:
3425 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3426 "0398 Invalid link fault code: x%x\n",
3427 bf_get(lpfc_acqe_link_fault
, acqe_link
));
3428 latt_fault
= MBXERR_ERROR
;
3435 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3436 * @phba: pointer to lpfc hba data structure.
3437 * @acqe_link: pointer to the async link completion queue entry.
3439 * This routine is to parse the SLI4 link attention type and translate it
3440 * into the base driver's link attention type coding.
3442 * Return: Link attention type in terms of base driver's coding.
3445 lpfc_sli4_parse_latt_type(struct lpfc_hba
*phba
,
3446 struct lpfc_acqe_link
*acqe_link
)
3450 switch (bf_get(lpfc_acqe_link_status
, acqe_link
)) {
3451 case LPFC_ASYNC_LINK_STATUS_DOWN
:
3452 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN
:
3453 att_type
= LPFC_ATT_LINK_DOWN
;
3455 case LPFC_ASYNC_LINK_STATUS_UP
:
3456 /* Ignore physical link up events - wait for logical link up */
3457 att_type
= LPFC_ATT_RESERVED
;
3459 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP
:
3460 att_type
= LPFC_ATT_LINK_UP
;
3463 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3464 "0399 Invalid link attention type: x%x\n",
3465 bf_get(lpfc_acqe_link_status
, acqe_link
));
3466 att_type
= LPFC_ATT_RESERVED
;
3473 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
3474 * @phba: pointer to lpfc hba data structure.
3475 * @acqe_link: pointer to the async link completion queue entry.
3477 * This routine is to parse the SLI4 link-attention link speed and translate
3478 * it into the base driver's link-attention link speed coding.
3480 * Return: Link-attention link speed in terms of base driver's coding.
3483 lpfc_sli4_parse_latt_link_speed(struct lpfc_hba
*phba
,
3484 struct lpfc_acqe_link
*acqe_link
)
3488 switch (bf_get(lpfc_acqe_link_speed
, acqe_link
)) {
3489 case LPFC_ASYNC_LINK_SPEED_ZERO
:
3490 case LPFC_ASYNC_LINK_SPEED_10MBPS
:
3491 case LPFC_ASYNC_LINK_SPEED_100MBPS
:
3492 link_speed
= LPFC_LINK_SPEED_UNKNOWN
;
3494 case LPFC_ASYNC_LINK_SPEED_1GBPS
:
3495 link_speed
= LPFC_LINK_SPEED_1GHZ
;
3497 case LPFC_ASYNC_LINK_SPEED_10GBPS
:
3498 link_speed
= LPFC_LINK_SPEED_10GHZ
;
3501 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3502 "0483 Invalid link-attention link speed: x%x\n",
3503 bf_get(lpfc_acqe_link_speed
, acqe_link
));
3504 link_speed
= LPFC_LINK_SPEED_UNKNOWN
;
3511 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
3512 * @phba: pointer to lpfc hba data structure.
3514 * This routine is to get an SLI3 FC port's link speed in Mbps.
3516 * Return: link speed in terms of Mbps.
3519 lpfc_sli_port_speed_get(struct lpfc_hba
*phba
)
3521 uint32_t link_speed
;
3523 if (!lpfc_is_link_up(phba
))
3526 switch (phba
->fc_linkspeed
) {
3527 case LPFC_LINK_SPEED_1GHZ
:
3530 case LPFC_LINK_SPEED_2GHZ
:
3533 case LPFC_LINK_SPEED_4GHZ
:
3536 case LPFC_LINK_SPEED_8GHZ
:
3539 case LPFC_LINK_SPEED_10GHZ
:
3542 case LPFC_LINK_SPEED_16GHZ
:
3552 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
3553 * @phba: pointer to lpfc hba data structure.
3554 * @evt_code: asynchronous event code.
3555 * @speed_code: asynchronous event link speed code.
3557 * This routine is to parse the giving SLI4 async event link speed code into
3558 * value of Mbps for the link speed.
3560 * Return: link speed in terms of Mbps.
3563 lpfc_sli4_port_speed_parse(struct lpfc_hba
*phba
, uint32_t evt_code
,
3566 uint32_t port_speed
;
3569 case LPFC_TRAILER_CODE_LINK
:
3570 switch (speed_code
) {
3571 case LPFC_EVT_CODE_LINK_NO_LINK
:
3574 case LPFC_EVT_CODE_LINK_10_MBIT
:
3577 case LPFC_EVT_CODE_LINK_100_MBIT
:
3580 case LPFC_EVT_CODE_LINK_1_GBIT
:
3583 case LPFC_EVT_CODE_LINK_10_GBIT
:
3590 case LPFC_TRAILER_CODE_FC
:
3591 switch (speed_code
) {
3592 case LPFC_EVT_CODE_FC_NO_LINK
:
3595 case LPFC_EVT_CODE_FC_1_GBAUD
:
3598 case LPFC_EVT_CODE_FC_2_GBAUD
:
3601 case LPFC_EVT_CODE_FC_4_GBAUD
:
3604 case LPFC_EVT_CODE_FC_8_GBAUD
:
3607 case LPFC_EVT_CODE_FC_10_GBAUD
:
3610 case LPFC_EVT_CODE_FC_16_GBAUD
:
3624 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
3625 * @phba: pointer to lpfc hba data structure.
3626 * @acqe_link: pointer to the async link completion queue entry.
3628 * This routine is to handle the SLI4 asynchronous FCoE link event.
3631 lpfc_sli4_async_link_evt(struct lpfc_hba
*phba
,
3632 struct lpfc_acqe_link
*acqe_link
)
3634 struct lpfc_dmabuf
*mp
;
3637 struct lpfc_mbx_read_top
*la
;
3641 att_type
= lpfc_sli4_parse_latt_type(phba
, acqe_link
);
3642 if (att_type
!= LPFC_ATT_LINK_DOWN
&& att_type
!= LPFC_ATT_LINK_UP
)
3644 phba
->fcoe_eventtag
= acqe_link
->event_tag
;
3645 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3647 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3648 "0395 The mboxq allocation failed\n");
3651 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
3653 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3654 "0396 The lpfc_dmabuf allocation failed\n");
3657 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
3659 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3660 "0397 The mbuf allocation failed\n");
3661 goto out_free_dmabuf
;
3664 /* Cleanup any outstanding ELS commands */
3665 lpfc_els_flush_all_cmd(phba
);
3667 /* Block ELS IOCBs until we have done process link event */
3668 phba
->sli
.ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
3670 /* Update link event statistics */
3671 phba
->sli
.slistat
.link_event
++;
3673 /* Create lpfc_handle_latt mailbox command from link ACQE */
3674 lpfc_read_topology(phba
, pmb
, mp
);
3675 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
3676 pmb
->vport
= phba
->pport
;
3678 /* Keep the link status for extra SLI4 state machine reference */
3679 phba
->sli4_hba
.link_state
.speed
=
3680 lpfc_sli4_port_speed_parse(phba
, LPFC_TRAILER_CODE_LINK
,
3681 bf_get(lpfc_acqe_link_speed
, acqe_link
));
3682 phba
->sli4_hba
.link_state
.duplex
=
3683 bf_get(lpfc_acqe_link_duplex
, acqe_link
);
3684 phba
->sli4_hba
.link_state
.status
=
3685 bf_get(lpfc_acqe_link_status
, acqe_link
);
3686 phba
->sli4_hba
.link_state
.type
=
3687 bf_get(lpfc_acqe_link_type
, acqe_link
);
3688 phba
->sli4_hba
.link_state
.number
=
3689 bf_get(lpfc_acqe_link_number
, acqe_link
);
3690 phba
->sli4_hba
.link_state
.fault
=
3691 bf_get(lpfc_acqe_link_fault
, acqe_link
);
3692 phba
->sli4_hba
.link_state
.logical_speed
=
3693 bf_get(lpfc_acqe_logical_link_speed
, acqe_link
) * 10;
3695 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3696 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3697 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3698 "Logical speed:%dMbps Fault:%d\n",
3699 phba
->sli4_hba
.link_state
.speed
,
3700 phba
->sli4_hba
.link_state
.topology
,
3701 phba
->sli4_hba
.link_state
.status
,
3702 phba
->sli4_hba
.link_state
.type
,
3703 phba
->sli4_hba
.link_state
.number
,
3704 phba
->sli4_hba
.link_state
.logical_speed
,
3705 phba
->sli4_hba
.link_state
.fault
);
3707 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3708 * topology info. Note: Optional for non FC-AL ports.
3710 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
3711 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3712 if (rc
== MBX_NOT_FINISHED
)
3713 goto out_free_dmabuf
;
3717 * For FCoE Mode: fill in all the topology information we need and call
3718 * the READ_TOPOLOGY completion routine to continue without actually
3719 * sending the READ_TOPOLOGY mailbox command to the port.
3721 /* Parse and translate status field */
3723 mb
->mbxStatus
= lpfc_sli4_parse_latt_fault(phba
, acqe_link
);
3725 /* Parse and translate link attention fields */
3726 la
= (struct lpfc_mbx_read_top
*) &pmb
->u
.mb
.un
.varReadTop
;
3727 la
->eventTag
= acqe_link
->event_tag
;
3728 bf_set(lpfc_mbx_read_top_att_type
, la
, att_type
);
3729 bf_set(lpfc_mbx_read_top_link_spd
, la
,
3730 lpfc_sli4_parse_latt_link_speed(phba
, acqe_link
));
3732 /* Fake the the following irrelvant fields */
3733 bf_set(lpfc_mbx_read_top_topology
, la
, LPFC_TOPOLOGY_PT_PT
);
3734 bf_set(lpfc_mbx_read_top_alpa_granted
, la
, 0);
3735 bf_set(lpfc_mbx_read_top_il
, la
, 0);
3736 bf_set(lpfc_mbx_read_top_pb
, la
, 0);
3737 bf_set(lpfc_mbx_read_top_fa
, la
, 0);
3738 bf_set(lpfc_mbx_read_top_mm
, la
, 0);
3740 /* Invoke the lpfc_handle_latt mailbox command callback function */
3741 lpfc_mbx_cmpl_read_topology(phba
, pmb
);
3748 mempool_free(pmb
, phba
->mbox_mem_pool
);
3752 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
3753 * @phba: pointer to lpfc hba data structure.
3754 * @acqe_fc: pointer to the async fc completion queue entry.
3756 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
3757 * that the event was received and then issue a read_topology mailbox command so
3758 * that the rest of the driver will treat it the same as SLI3.
3761 lpfc_sli4_async_fc_evt(struct lpfc_hba
*phba
, struct lpfc_acqe_fc_la
*acqe_fc
)
3763 struct lpfc_dmabuf
*mp
;
3767 if (bf_get(lpfc_trailer_type
, acqe_fc
) !=
3768 LPFC_FC_LA_EVENT_TYPE_FC_LINK
) {
3769 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3770 "2895 Non FC link Event detected.(%d)\n",
3771 bf_get(lpfc_trailer_type
, acqe_fc
));
3774 /* Keep the link status for extra SLI4 state machine reference */
3775 phba
->sli4_hba
.link_state
.speed
=
3776 lpfc_sli4_port_speed_parse(phba
, LPFC_TRAILER_CODE_FC
,
3777 bf_get(lpfc_acqe_fc_la_speed
, acqe_fc
));
3778 phba
->sli4_hba
.link_state
.duplex
= LPFC_ASYNC_LINK_DUPLEX_FULL
;
3779 phba
->sli4_hba
.link_state
.topology
=
3780 bf_get(lpfc_acqe_fc_la_topology
, acqe_fc
);
3781 phba
->sli4_hba
.link_state
.status
=
3782 bf_get(lpfc_acqe_fc_la_att_type
, acqe_fc
);
3783 phba
->sli4_hba
.link_state
.type
=
3784 bf_get(lpfc_acqe_fc_la_port_type
, acqe_fc
);
3785 phba
->sli4_hba
.link_state
.number
=
3786 bf_get(lpfc_acqe_fc_la_port_number
, acqe_fc
);
3787 phba
->sli4_hba
.link_state
.fault
=
3788 bf_get(lpfc_acqe_link_fault
, acqe_fc
);
3789 phba
->sli4_hba
.link_state
.logical_speed
=
3790 bf_get(lpfc_acqe_fc_la_llink_spd
, acqe_fc
) * 10;
3791 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3792 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
3793 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
3794 "%dMbps Fault:%d\n",
3795 phba
->sli4_hba
.link_state
.speed
,
3796 phba
->sli4_hba
.link_state
.topology
,
3797 phba
->sli4_hba
.link_state
.status
,
3798 phba
->sli4_hba
.link_state
.type
,
3799 phba
->sli4_hba
.link_state
.number
,
3800 phba
->sli4_hba
.link_state
.logical_speed
,
3801 phba
->sli4_hba
.link_state
.fault
);
3802 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3804 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3805 "2897 The mboxq allocation failed\n");
3808 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
3810 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3811 "2898 The lpfc_dmabuf allocation failed\n");
3814 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
3816 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3817 "2899 The mbuf allocation failed\n");
3818 goto out_free_dmabuf
;
3821 /* Cleanup any outstanding ELS commands */
3822 lpfc_els_flush_all_cmd(phba
);
3824 /* Block ELS IOCBs until we have done process link event */
3825 phba
->sli
.ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
3827 /* Update link event statistics */
3828 phba
->sli
.slistat
.link_event
++;
3830 /* Create lpfc_handle_latt mailbox command from link ACQE */
3831 lpfc_read_topology(phba
, pmb
, mp
);
3832 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
3833 pmb
->vport
= phba
->pport
;
3835 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3836 if (rc
== MBX_NOT_FINISHED
)
3837 goto out_free_dmabuf
;
3843 mempool_free(pmb
, phba
->mbox_mem_pool
);
3847 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
3848 * @phba: pointer to lpfc hba data structure.
3849 * @acqe_fc: pointer to the async SLI completion queue entry.
3851 * This routine is to handle the SLI4 asynchronous SLI events.
3854 lpfc_sli4_async_sli_evt(struct lpfc_hba
*phba
, struct lpfc_acqe_sli
*acqe_sli
)
3859 struct lpfc_acqe_misconfigured_event
*misconfigured
;
3861 /* special case misconfigured event as it contains data for all ports */
3862 if ((bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
3863 LPFC_SLI_INTF_IF_TYPE_2
) ||
3864 (bf_get(lpfc_trailer_type
, acqe_sli
) !=
3865 LPFC_SLI_EVENT_TYPE_MISCONFIGURED
)) {
3866 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3867 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
3868 "x%08x SLI Event Type:%d\n",
3869 acqe_sli
->event_data1
, acqe_sli
->event_data2
,
3870 bf_get(lpfc_trailer_type
, acqe_sli
));
3874 port_name
= phba
->Port
[0];
3875 if (port_name
== 0x00)
3876 port_name
= '?'; /* get port name is empty */
3878 misconfigured
= (struct lpfc_acqe_misconfigured_event
*)
3879 &acqe_sli
->event_data1
;
3881 /* fetch the status for this port */
3882 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
3883 case LPFC_LINK_NUMBER_0
:
3884 status
= bf_get(lpfc_sli_misconfigured_port0
,
3885 &misconfigured
->theEvent
);
3887 case LPFC_LINK_NUMBER_1
:
3888 status
= bf_get(lpfc_sli_misconfigured_port1
,
3889 &misconfigured
->theEvent
);
3891 case LPFC_LINK_NUMBER_2
:
3892 status
= bf_get(lpfc_sli_misconfigured_port2
,
3893 &misconfigured
->theEvent
);
3895 case LPFC_LINK_NUMBER_3
:
3896 status
= bf_get(lpfc_sli_misconfigured_port3
,
3897 &misconfigured
->theEvent
);
3900 status
= ~LPFC_SLI_EVENT_STATUS_VALID
;
3905 case LPFC_SLI_EVENT_STATUS_VALID
:
3906 return; /* no message if the sfp is okay */
3907 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT
:
3908 sprintf(message
, "Optics faulted/incorrectly installed/not " \
3909 "installed - Reseat optics, if issue not "
3910 "resolved, replace.");
3912 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE
:
3914 "Optics of two types installed - Remove one optic or " \
3915 "install matching pair of optics.");
3917 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED
:
3918 sprintf(message
, "Incompatible optics - Replace with " \
3919 "compatible optics for card to function.");
3922 /* firmware is reporting a status we don't know about */
3923 sprintf(message
, "Unknown event status x%02x", status
);
3927 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3928 "3176 Misconfigured Physical Port - "
3929 "Port Name %c %s\n", port_name
, message
);
3933 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
3934 * @vport: pointer to vport data structure.
3936 * This routine is to perform Clear Virtual Link (CVL) on a vport in
3937 * response to a CVL event.
3939 * Return the pointer to the ndlp with the vport if successful, otherwise
3942 static struct lpfc_nodelist
*
3943 lpfc_sli4_perform_vport_cvl(struct lpfc_vport
*vport
)
3945 struct lpfc_nodelist
*ndlp
;
3946 struct Scsi_Host
*shost
;
3947 struct lpfc_hba
*phba
;
3954 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
3956 /* Cannot find existing Fabric ndlp, so allocate a new one */
3957 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
3960 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
3961 /* Set the node type */
3962 ndlp
->nlp_type
|= NLP_FABRIC
;
3963 /* Put ndlp onto node list */
3964 lpfc_enqueue_node(vport
, ndlp
);
3965 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
3966 /* re-setup ndlp without removing from node list */
3967 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
3971 if ((phba
->pport
->port_state
< LPFC_FLOGI
) &&
3972 (phba
->pport
->port_state
!= LPFC_VPORT_FAILED
))
3974 /* If virtual link is not yet instantiated ignore CVL */
3975 if ((vport
!= phba
->pport
) && (vport
->port_state
< LPFC_FDISC
)
3976 && (vport
->port_state
!= LPFC_VPORT_FAILED
))
3978 shost
= lpfc_shost_from_vport(vport
);
3981 lpfc_linkdown_port(vport
);
3982 lpfc_cleanup_pending_mbox(vport
);
3983 spin_lock_irq(shost
->host_lock
);
3984 vport
->fc_flag
|= FC_VPORT_CVL_RCVD
;
3985 spin_unlock_irq(shost
->host_lock
);
3991 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
3992 * @vport: pointer to lpfc hba data structure.
3994 * This routine is to perform Clear Virtual Link (CVL) on all vports in
3995 * response to a FCF dead event.
3998 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba
*phba
)
4000 struct lpfc_vport
**vports
;
4003 vports
= lpfc_create_vport_work_array(phba
);
4005 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
4006 lpfc_sli4_perform_vport_cvl(vports
[i
]);
4007 lpfc_destroy_vport_work_array(phba
, vports
);
4011 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
4012 * @phba: pointer to lpfc hba data structure.
4013 * @acqe_link: pointer to the async fcoe completion queue entry.
4015 * This routine is to handle the SLI4 asynchronous fcoe event.
4018 lpfc_sli4_async_fip_evt(struct lpfc_hba
*phba
,
4019 struct lpfc_acqe_fip
*acqe_fip
)
4021 uint8_t event_type
= bf_get(lpfc_trailer_type
, acqe_fip
);
4023 struct lpfc_vport
*vport
;
4024 struct lpfc_nodelist
*ndlp
;
4025 struct Scsi_Host
*shost
;
4026 int active_vlink_present
;
4027 struct lpfc_vport
**vports
;
4030 phba
->fc_eventTag
= acqe_fip
->event_tag
;
4031 phba
->fcoe_eventtag
= acqe_fip
->event_tag
;
4032 switch (event_type
) {
4033 case LPFC_FIP_EVENT_TYPE_NEW_FCF
:
4034 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD
:
4035 if (event_type
== LPFC_FIP_EVENT_TYPE_NEW_FCF
)
4036 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
4038 "2546 New FCF event, evt_tag:x%x, "
4040 acqe_fip
->event_tag
,
4043 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
|
4045 "2788 FCF param modified event, "
4046 "evt_tag:x%x, index:x%x\n",
4047 acqe_fip
->event_tag
,
4049 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
4051 * During period of FCF discovery, read the FCF
4052 * table record indexed by the event to update
4053 * FCF roundrobin failover eligible FCF bmask.
4055 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
4057 "2779 Read FCF (x%x) for updating "
4058 "roundrobin FCF failover bmask\n",
4060 rc
= lpfc_sli4_read_fcf_rec(phba
, acqe_fip
->index
);
4063 /* If the FCF discovery is in progress, do nothing. */
4064 spin_lock_irq(&phba
->hbalock
);
4065 if (phba
->hba_flag
& FCF_TS_INPROG
) {
4066 spin_unlock_irq(&phba
->hbalock
);
4069 /* If fast FCF failover rescan event is pending, do nothing */
4070 if (phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
) {
4071 spin_unlock_irq(&phba
->hbalock
);
4075 /* If the FCF has been in discovered state, do nothing. */
4076 if (phba
->fcf
.fcf_flag
& FCF_SCAN_DONE
) {
4077 spin_unlock_irq(&phba
->hbalock
);
4080 spin_unlock_irq(&phba
->hbalock
);
4082 /* Otherwise, scan the entire FCF table and re-discover SAN */
4083 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
4084 "2770 Start FCF table scan per async FCF "
4085 "event, evt_tag:x%x, index:x%x\n",
4086 acqe_fip
->event_tag
, acqe_fip
->index
);
4087 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
4088 LPFC_FCOE_FCF_GET_FIRST
);
4090 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4091 "2547 Issue FCF scan read FCF mailbox "
4092 "command failed (x%x)\n", rc
);
4095 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL
:
4096 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4097 "2548 FCF Table full count 0x%x tag 0x%x\n",
4098 bf_get(lpfc_acqe_fip_fcf_count
, acqe_fip
),
4099 acqe_fip
->event_tag
);
4102 case LPFC_FIP_EVENT_TYPE_FCF_DEAD
:
4103 phba
->fcoe_cvl_eventtag
= acqe_fip
->event_tag
;
4104 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4105 "2549 FCF (x%x) disconnected from network, "
4106 "tag:x%x\n", acqe_fip
->index
, acqe_fip
->event_tag
);
4108 * If we are in the middle of FCF failover process, clear
4109 * the corresponding FCF bit in the roundrobin bitmap.
4111 spin_lock_irq(&phba
->hbalock
);
4112 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
4113 spin_unlock_irq(&phba
->hbalock
);
4114 /* Update FLOGI FCF failover eligible FCF bmask */
4115 lpfc_sli4_fcf_rr_index_clear(phba
, acqe_fip
->index
);
4118 spin_unlock_irq(&phba
->hbalock
);
4120 /* If the event is not for currently used fcf do nothing */
4121 if (phba
->fcf
.current_rec
.fcf_indx
!= acqe_fip
->index
)
4125 * Otherwise, request the port to rediscover the entire FCF
4126 * table for a fast recovery from case that the current FCF
4127 * is no longer valid as we are not in the middle of FCF
4128 * failover process already.
4130 spin_lock_irq(&phba
->hbalock
);
4131 /* Mark the fast failover process in progress */
4132 phba
->fcf
.fcf_flag
|= FCF_DEAD_DISC
;
4133 spin_unlock_irq(&phba
->hbalock
);
4135 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
4136 "2771 Start FCF fast failover process due to "
4137 "FCF DEAD event: evt_tag:x%x, fcf_index:x%x "
4138 "\n", acqe_fip
->event_tag
, acqe_fip
->index
);
4139 rc
= lpfc_sli4_redisc_fcf_table(phba
);
4141 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
4143 "2772 Issue FCF rediscover mabilbox "
4144 "command failed, fail through to FCF "
4146 spin_lock_irq(&phba
->hbalock
);
4147 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
4148 spin_unlock_irq(&phba
->hbalock
);
4150 * Last resort will fail over by treating this
4151 * as a link down to FCF registration.
4153 lpfc_sli4_fcf_dead_failthrough(phba
);
4155 /* Reset FCF roundrobin bmask for new discovery */
4156 lpfc_sli4_clear_fcf_rr_bmask(phba
);
4158 * Handling fast FCF failover to a DEAD FCF event is
4159 * considered equalivant to receiving CVL to all vports.
4161 lpfc_sli4_perform_all_vport_cvl(phba
);
4164 case LPFC_FIP_EVENT_TYPE_CVL
:
4165 phba
->fcoe_cvl_eventtag
= acqe_fip
->event_tag
;
4166 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4167 "2718 Clear Virtual Link Received for VPI 0x%x"
4168 " tag 0x%x\n", acqe_fip
->index
, acqe_fip
->event_tag
);
4170 vport
= lpfc_find_vport_by_vpid(phba
,
4172 ndlp
= lpfc_sli4_perform_vport_cvl(vport
);
4175 active_vlink_present
= 0;
4177 vports
= lpfc_create_vport_work_array(phba
);
4179 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
4181 if ((!(vports
[i
]->fc_flag
&
4182 FC_VPORT_CVL_RCVD
)) &&
4183 (vports
[i
]->port_state
> LPFC_FDISC
)) {
4184 active_vlink_present
= 1;
4188 lpfc_destroy_vport_work_array(phba
, vports
);
4191 if (active_vlink_present
) {
4193 * If there are other active VLinks present,
4194 * re-instantiate the Vlink using FDISC.
4196 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ HZ
);
4197 shost
= lpfc_shost_from_vport(vport
);
4198 spin_lock_irq(shost
->host_lock
);
4199 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
4200 spin_unlock_irq(shost
->host_lock
);
4201 ndlp
->nlp_last_elscmd
= ELS_CMD_FDISC
;
4202 vport
->port_state
= LPFC_FDISC
;
4205 * Otherwise, we request port to rediscover
4206 * the entire FCF table for a fast recovery
4207 * from possible case that the current FCF
4208 * is no longer valid if we are not already
4209 * in the FCF failover process.
4211 spin_lock_irq(&phba
->hbalock
);
4212 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
4213 spin_unlock_irq(&phba
->hbalock
);
4216 /* Mark the fast failover process in progress */
4217 phba
->fcf
.fcf_flag
|= FCF_ACVL_DISC
;
4218 spin_unlock_irq(&phba
->hbalock
);
4219 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
4221 "2773 Start FCF failover per CVL, "
4222 "evt_tag:x%x\n", acqe_fip
->event_tag
);
4223 rc
= lpfc_sli4_redisc_fcf_table(phba
);
4225 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
4227 "2774 Issue FCF rediscover "
4228 "mabilbox command failed, "
4229 "through to CVL event\n");
4230 spin_lock_irq(&phba
->hbalock
);
4231 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
4232 spin_unlock_irq(&phba
->hbalock
);
4234 * Last resort will be re-try on the
4235 * the current registered FCF entry.
4237 lpfc_retry_pport_discovery(phba
);
4240 * Reset FCF roundrobin bmask for new
4243 lpfc_sli4_clear_fcf_rr_bmask(phba
);
4247 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4248 "0288 Unknown FCoE event type 0x%x event tag "
4249 "0x%x\n", event_type
, acqe_fip
->event_tag
);
4255 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4256 * @phba: pointer to lpfc hba data structure.
4257 * @acqe_link: pointer to the async dcbx completion queue entry.
4259 * This routine is to handle the SLI4 asynchronous dcbx event.
4262 lpfc_sli4_async_dcbx_evt(struct lpfc_hba
*phba
,
4263 struct lpfc_acqe_dcbx
*acqe_dcbx
)
4265 phba
->fc_eventTag
= acqe_dcbx
->event_tag
;
4266 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4267 "0290 The SLI4 DCBX asynchronous event is not "
4272 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4273 * @phba: pointer to lpfc hba data structure.
4274 * @acqe_link: pointer to the async grp5 completion queue entry.
4276 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4277 * is an asynchronous notified of a logical link speed change. The Port
4278 * reports the logical link speed in units of 10Mbps.
4281 lpfc_sli4_async_grp5_evt(struct lpfc_hba
*phba
,
4282 struct lpfc_acqe_grp5
*acqe_grp5
)
4284 uint16_t prev_ll_spd
;
4286 phba
->fc_eventTag
= acqe_grp5
->event_tag
;
4287 phba
->fcoe_eventtag
= acqe_grp5
->event_tag
;
4288 prev_ll_spd
= phba
->sli4_hba
.link_state
.logical_speed
;
4289 phba
->sli4_hba
.link_state
.logical_speed
=
4290 (bf_get(lpfc_acqe_grp5_llink_spd
, acqe_grp5
)) * 10;
4291 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4292 "2789 GRP5 Async Event: Updating logical link speed "
4293 "from %dMbps to %dMbps\n", prev_ll_spd
,
4294 phba
->sli4_hba
.link_state
.logical_speed
);
4298 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4299 * @phba: pointer to lpfc hba data structure.
4301 * This routine is invoked by the worker thread to process all the pending
4302 * SLI4 asynchronous events.
4304 void lpfc_sli4_async_event_proc(struct lpfc_hba
*phba
)
4306 struct lpfc_cq_event
*cq_event
;
4308 /* First, declare the async event has been handled */
4309 spin_lock_irq(&phba
->hbalock
);
4310 phba
->hba_flag
&= ~ASYNC_EVENT
;
4311 spin_unlock_irq(&phba
->hbalock
);
4312 /* Now, handle all the async events */
4313 while (!list_empty(&phba
->sli4_hba
.sp_asynce_work_queue
)) {
4314 /* Get the first event from the head of the event queue */
4315 spin_lock_irq(&phba
->hbalock
);
4316 list_remove_head(&phba
->sli4_hba
.sp_asynce_work_queue
,
4317 cq_event
, struct lpfc_cq_event
, list
);
4318 spin_unlock_irq(&phba
->hbalock
);
4319 /* Process the asynchronous event */
4320 switch (bf_get(lpfc_trailer_code
, &cq_event
->cqe
.mcqe_cmpl
)) {
4321 case LPFC_TRAILER_CODE_LINK
:
4322 lpfc_sli4_async_link_evt(phba
,
4323 &cq_event
->cqe
.acqe_link
);
4325 case LPFC_TRAILER_CODE_FCOE
:
4326 lpfc_sli4_async_fip_evt(phba
, &cq_event
->cqe
.acqe_fip
);
4328 case LPFC_TRAILER_CODE_DCBX
:
4329 lpfc_sli4_async_dcbx_evt(phba
,
4330 &cq_event
->cqe
.acqe_dcbx
);
4332 case LPFC_TRAILER_CODE_GRP5
:
4333 lpfc_sli4_async_grp5_evt(phba
,
4334 &cq_event
->cqe
.acqe_grp5
);
4336 case LPFC_TRAILER_CODE_FC
:
4337 lpfc_sli4_async_fc_evt(phba
, &cq_event
->cqe
.acqe_fc
);
4339 case LPFC_TRAILER_CODE_SLI
:
4340 lpfc_sli4_async_sli_evt(phba
, &cq_event
->cqe
.acqe_sli
);
4343 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4344 "1804 Invalid asynchrous event code: "
4345 "x%x\n", bf_get(lpfc_trailer_code
,
4346 &cq_event
->cqe
.mcqe_cmpl
));
4349 /* Free the completion event processed to the free pool */
4350 lpfc_sli4_cq_event_release(phba
, cq_event
);
4355 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4356 * @phba: pointer to lpfc hba data structure.
4358 * This routine is invoked by the worker thread to process FCF table
4359 * rediscovery pending completion event.
4361 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba
*phba
)
4365 spin_lock_irq(&phba
->hbalock
);
4366 /* Clear FCF rediscovery timeout event */
4367 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_EVT
;
4368 /* Clear driver fast failover FCF record flag */
4369 phba
->fcf
.failover_rec
.flag
= 0;
4370 /* Set state for FCF fast failover */
4371 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
4372 spin_unlock_irq(&phba
->hbalock
);
4374 /* Scan FCF table from the first entry to re-discover SAN */
4375 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
4376 "2777 Start post-quiescent FCF table scan\n");
4377 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
4379 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4380 "2747 Issue FCF scan read FCF mailbox "
4381 "command failed 0x%x\n", rc
);
4385 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4386 * @phba: pointer to lpfc hba data structure.
4387 * @dev_grp: The HBA PCI-Device group number.
4389 * This routine is invoked to set up the per HBA PCI-Device group function
4390 * API jump table entries.
4392 * Return: 0 if success, otherwise -ENODEV
4395 lpfc_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
4399 /* Set up lpfc PCI-device group */
4400 phba
->pci_dev_grp
= dev_grp
;
4402 /* The LPFC_PCI_DEV_OC uses SLI4 */
4403 if (dev_grp
== LPFC_PCI_DEV_OC
)
4404 phba
->sli_rev
= LPFC_SLI_REV4
;
4406 /* Set up device INIT API function jump table */
4407 rc
= lpfc_init_api_table_setup(phba
, dev_grp
);
4410 /* Set up SCSI API function jump table */
4411 rc
= lpfc_scsi_api_table_setup(phba
, dev_grp
);
4414 /* Set up SLI API function jump table */
4415 rc
= lpfc_sli_api_table_setup(phba
, dev_grp
);
4418 /* Set up MBOX API function jump table */
4419 rc
= lpfc_mbox_api_table_setup(phba
, dev_grp
);
4427 * lpfc_log_intr_mode - Log the active interrupt mode
4428 * @phba: pointer to lpfc hba data structure.
4429 * @intr_mode: active interrupt mode adopted.
4431 * This routine it invoked to log the currently used active interrupt mode
4434 static void lpfc_log_intr_mode(struct lpfc_hba
*phba
, uint32_t intr_mode
)
4436 switch (intr_mode
) {
4438 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4439 "0470 Enable INTx interrupt mode.\n");
4442 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4443 "0481 Enabled MSI interrupt mode.\n");
4446 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4447 "0480 Enabled MSI-X interrupt mode.\n");
4450 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4451 "0482 Illegal interrupt mode.\n");
4458 * lpfc_enable_pci_dev - Enable a generic PCI device.
4459 * @phba: pointer to lpfc hba data structure.
4461 * This routine is invoked to enable the PCI device that is common to all
4466 * other values - error
4469 lpfc_enable_pci_dev(struct lpfc_hba
*phba
)
4471 struct pci_dev
*pdev
;
4474 /* Obtain PCI device reference */
4478 pdev
= phba
->pcidev
;
4479 /* Select PCI BARs */
4480 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
4481 /* Enable PCI device */
4482 if (pci_enable_device_mem(pdev
))
4484 /* Request PCI resource for the device */
4485 if (pci_request_selected_regions(pdev
, bars
, LPFC_DRIVER_NAME
))
4486 goto out_disable_device
;
4487 /* Set up device as PCI master and save state for EEH */
4488 pci_set_master(pdev
);
4489 pci_try_set_mwi(pdev
);
4490 pci_save_state(pdev
);
4492 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
4493 if (pci_find_capability(pdev
, PCI_CAP_ID_EXP
))
4494 pdev
->needs_freset
= 1;
4499 pci_disable_device(pdev
);
4501 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4502 "1401 Failed to enable pci device, bars:x%x\n", bars
);
4507 * lpfc_disable_pci_dev - Disable a generic PCI device.
4508 * @phba: pointer to lpfc hba data structure.
4510 * This routine is invoked to disable the PCI device that is common to all
4514 lpfc_disable_pci_dev(struct lpfc_hba
*phba
)
4516 struct pci_dev
*pdev
;
4519 /* Obtain PCI device reference */
4523 pdev
= phba
->pcidev
;
4524 /* Select PCI BARs */
4525 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
4526 /* Release PCI resource and disable PCI device */
4527 pci_release_selected_regions(pdev
, bars
);
4528 pci_disable_device(pdev
);
4529 /* Null out PCI private reference to driver */
4530 pci_set_drvdata(pdev
, NULL
);
4536 * lpfc_reset_hba - Reset a hba
4537 * @phba: pointer to lpfc hba data structure.
4539 * This routine is invoked to reset a hba device. It brings the HBA
4540 * offline, performs a board restart, and then brings the board back
4541 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4542 * on outstanding mailbox commands.
4545 lpfc_reset_hba(struct lpfc_hba
*phba
)
4547 /* If resets are disabled then set error state and return. */
4548 if (!phba
->cfg_enable_hba_reset
) {
4549 phba
->link_state
= LPFC_HBA_ERROR
;
4552 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
4554 lpfc_sli_brdrestart(phba
);
4556 lpfc_unblock_mgmt_io(phba
);
4560 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4561 * @phba: pointer to lpfc hba data structure.
4563 * This function enables the PCI SR-IOV virtual functions to a physical
4564 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4565 * enable the number of virtual functions to the physical function. As
4566 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4567 * API call does not considered as an error condition for most of the device.
4570 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba
*phba
)
4572 struct pci_dev
*pdev
= phba
->pcidev
;
4576 pos
= pci_find_ext_capability(pdev
, PCI_EXT_CAP_ID_SRIOV
);
4580 pci_read_config_word(pdev
, pos
+ PCI_SRIOV_TOTAL_VF
, &nr_virtfn
);
4585 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4586 * @phba: pointer to lpfc hba data structure.
4587 * @nr_vfn: number of virtual functions to be enabled.
4589 * This function enables the PCI SR-IOV virtual functions to a physical
4590 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4591 * enable the number of virtual functions to the physical function. As
4592 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4593 * API call does not considered as an error condition for most of the device.
4596 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba
*phba
, int nr_vfn
)
4598 struct pci_dev
*pdev
= phba
->pcidev
;
4599 uint16_t max_nr_vfn
;
4602 max_nr_vfn
= lpfc_sli_sriov_nr_virtfn_get(phba
);
4603 if (nr_vfn
> max_nr_vfn
) {
4604 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4605 "3057 Requested vfs (%d) greater than "
4606 "supported vfs (%d)", nr_vfn
, max_nr_vfn
);
4610 rc
= pci_enable_sriov(pdev
, nr_vfn
);
4612 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4613 "2806 Failed to enable sriov on this device "
4614 "with vfn number nr_vf:%d, rc:%d\n",
4617 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4618 "2807 Successful enable sriov on this device "
4619 "with vfn number nr_vf:%d\n", nr_vfn
);
4624 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
4625 * @phba: pointer to lpfc hba data structure.
4627 * This routine is invoked to set up the driver internal resources specific to
4628 * support the SLI-3 HBA device it attached to.
4632 * other values - error
4635 lpfc_sli_driver_resource_setup(struct lpfc_hba
*phba
)
4637 struct lpfc_sli
*psli
;
4641 * Initialize timers used by driver
4644 /* Heartbeat timer */
4645 init_timer(&phba
->hb_tmofunc
);
4646 phba
->hb_tmofunc
.function
= lpfc_hb_timeout
;
4647 phba
->hb_tmofunc
.data
= (unsigned long)phba
;
4650 /* MBOX heartbeat timer */
4651 init_timer(&psli
->mbox_tmo
);
4652 psli
->mbox_tmo
.function
= lpfc_mbox_timeout
;
4653 psli
->mbox_tmo
.data
= (unsigned long) phba
;
4654 /* FCP polling mode timer */
4655 init_timer(&phba
->fcp_poll_timer
);
4656 phba
->fcp_poll_timer
.function
= lpfc_poll_timeout
;
4657 phba
->fcp_poll_timer
.data
= (unsigned long) phba
;
4658 /* Fabric block timer */
4659 init_timer(&phba
->fabric_block_timer
);
4660 phba
->fabric_block_timer
.function
= lpfc_fabric_block_timeout
;
4661 phba
->fabric_block_timer
.data
= (unsigned long) phba
;
4662 /* EA polling mode timer */
4663 init_timer(&phba
->eratt_poll
);
4664 phba
->eratt_poll
.function
= lpfc_poll_eratt
;
4665 phba
->eratt_poll
.data
= (unsigned long) phba
;
4667 /* Host attention work mask setup */
4668 phba
->work_ha_mask
= (HA_ERATT
| HA_MBATT
| HA_LATT
);
4669 phba
->work_ha_mask
|= (HA_RXMASK
<< (LPFC_ELS_RING
* 4));
4671 /* Get all the module params for configuring this host */
4672 lpfc_get_cfgparam(phba
);
4673 if (phba
->pcidev
->device
== PCI_DEVICE_ID_HORNET
) {
4674 phba
->menlo_flag
|= HBA_MENLO_SUPPORT
;
4675 /* check for menlo minimum sg count */
4676 if (phba
->cfg_sg_seg_cnt
< LPFC_DEFAULT_MENLO_SG_SEG_CNT
)
4677 phba
->cfg_sg_seg_cnt
= LPFC_DEFAULT_MENLO_SG_SEG_CNT
;
4680 if (!phba
->sli
.ring
)
4681 phba
->sli
.ring
= (struct lpfc_sli_ring
*)
4682 kzalloc(LPFC_SLI3_MAX_RING
*
4683 sizeof(struct lpfc_sli_ring
), GFP_KERNEL
);
4684 if (!phba
->sli
.ring
)
4688 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4689 * used to create the sg_dma_buf_pool must be dynamically calculated.
4690 * 2 segments are added since the IOCB needs a command and response bde.
4692 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
4693 sizeof(struct fcp_rsp
) +
4694 ((phba
->cfg_sg_seg_cnt
+ 2) * sizeof(struct ulp_bde64
));
4696 if (phba
->cfg_enable_bg
) {
4697 phba
->cfg_sg_seg_cnt
= LPFC_MAX_SG_SEG_CNT
;
4698 phba
->cfg_sg_dma_buf_size
+=
4699 phba
->cfg_prot_sg_seg_cnt
* sizeof(struct ulp_bde64
);
4702 /* Also reinitialize the host templates with new values. */
4703 lpfc_vport_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
4704 lpfc_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
4706 phba
->max_vpi
= LPFC_MAX_VPI
;
4707 /* This will be set to correct value after config_port mbox */
4708 phba
->max_vports
= 0;
4711 * Initialize the SLI Layer to run with lpfc HBAs.
4713 lpfc_sli_setup(phba
);
4714 lpfc_sli_queue_setup(phba
);
4716 /* Allocate device driver memory */
4717 if (lpfc_mem_alloc(phba
, BPL_ALIGN_SZ
))
4721 * Enable sr-iov virtual functions if supported and configured
4722 * through the module parameter.
4724 if (phba
->cfg_sriov_nr_virtfn
> 0) {
4725 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
,
4726 phba
->cfg_sriov_nr_virtfn
);
4728 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4729 "2808 Requested number of SR-IOV "
4730 "virtual functions (%d) is not "
4732 phba
->cfg_sriov_nr_virtfn
);
4733 phba
->cfg_sriov_nr_virtfn
= 0;
4741 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
4742 * @phba: pointer to lpfc hba data structure.
4744 * This routine is invoked to unset the driver internal resources set up
4745 * specific for supporting the SLI-3 HBA device it attached to.
4748 lpfc_sli_driver_resource_unset(struct lpfc_hba
*phba
)
4750 /* Free device driver memory allocated */
4751 lpfc_mem_free_all(phba
);
4757 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
4758 * @phba: pointer to lpfc hba data structure.
4760 * This routine is invoked to set up the driver internal resources specific to
4761 * support the SLI-4 HBA device it attached to.
4765 * other values - error
4768 lpfc_sli4_driver_resource_setup(struct lpfc_hba
*phba
)
4770 struct lpfc_sli
*psli
;
4771 LPFC_MBOXQ_t
*mboxq
;
4772 int rc
, i
, hbq_count
, buf_size
, dma_buf_size
, max_buf_size
;
4773 uint8_t pn_page
[LPFC_MAX_SUPPORTED_PAGES
] = {0};
4774 struct lpfc_mqe
*mqe
;
4775 int longs
, sli_family
;
4776 int sges_per_segment
;
4778 /* Before proceed, wait for POST done and device ready */
4779 rc
= lpfc_sli4_post_status_check(phba
);
4784 * Initialize timers used by driver
4787 /* Heartbeat timer */
4788 init_timer(&phba
->hb_tmofunc
);
4789 phba
->hb_tmofunc
.function
= lpfc_hb_timeout
;
4790 phba
->hb_tmofunc
.data
= (unsigned long)phba
;
4791 init_timer(&phba
->rrq_tmr
);
4792 phba
->rrq_tmr
.function
= lpfc_rrq_timeout
;
4793 phba
->rrq_tmr
.data
= (unsigned long)phba
;
4796 /* MBOX heartbeat timer */
4797 init_timer(&psli
->mbox_tmo
);
4798 psli
->mbox_tmo
.function
= lpfc_mbox_timeout
;
4799 psli
->mbox_tmo
.data
= (unsigned long) phba
;
4800 /* Fabric block timer */
4801 init_timer(&phba
->fabric_block_timer
);
4802 phba
->fabric_block_timer
.function
= lpfc_fabric_block_timeout
;
4803 phba
->fabric_block_timer
.data
= (unsigned long) phba
;
4804 /* EA polling mode timer */
4805 init_timer(&phba
->eratt_poll
);
4806 phba
->eratt_poll
.function
= lpfc_poll_eratt
;
4807 phba
->eratt_poll
.data
= (unsigned long) phba
;
4808 /* FCF rediscover timer */
4809 init_timer(&phba
->fcf
.redisc_wait
);
4810 phba
->fcf
.redisc_wait
.function
= lpfc_sli4_fcf_redisc_wait_tmo
;
4811 phba
->fcf
.redisc_wait
.data
= (unsigned long)phba
;
4814 * Control structure for handling external multi-buffer mailbox
4815 * command pass-through.
4817 memset((uint8_t *)&phba
->mbox_ext_buf_ctx
, 0,
4818 sizeof(struct lpfc_mbox_ext_buf_ctx
));
4819 INIT_LIST_HEAD(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
4822 * We need to do a READ_CONFIG mailbox command here before
4823 * calling lpfc_get_cfgparam. For VFs this will report the
4824 * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
4825 * All of the resources allocated
4826 * for this Port are tied to these values.
4828 /* Get all the module params for configuring this host */
4829 lpfc_get_cfgparam(phba
);
4830 phba
->max_vpi
= LPFC_MAX_VPI
;
4832 /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */
4833 phba
->cfg_fcp_io_channel
= phba
->cfg_fcp_eq_count
;
4835 /* This will be set to correct value after the read_config mbox */
4836 phba
->max_vports
= 0;
4838 /* Program the default value of vlan_id and fc_map */
4839 phba
->valid_vlan
= 0;
4840 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4841 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4842 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4844 /* With BlockGuard we can have multiple SGEs per Data Segemnt */
4845 sges_per_segment
= 1;
4846 if (phba
->cfg_enable_bg
)
4847 sges_per_segment
= 2;
4850 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
4851 * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
4853 if (!phba
->sli
.ring
)
4854 phba
->sli
.ring
= kzalloc(
4855 (LPFC_SLI3_MAX_RING
+ phba
->cfg_fcp_io_channel
) *
4856 sizeof(struct lpfc_sli_ring
), GFP_KERNEL
);
4857 if (!phba
->sli
.ring
)
4860 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
4861 * used to create the sg_dma_buf_pool must be dynamically calculated.
4862 * 2 segments are added since the IOCB needs a command and response bde.
4863 * To insure that the scsi sgl does not cross a 4k page boundary only
4864 * sgl sizes of must be a power of 2.
4866 buf_size
= (sizeof(struct fcp_cmnd
) + sizeof(struct fcp_rsp
) +
4867 (((phba
->cfg_sg_seg_cnt
* sges_per_segment
) + 2) *
4868 sizeof(struct sli4_sge
)));
4870 sli_family
= bf_get(lpfc_sli_intf_sli_family
, &phba
->sli4_hba
.sli_intf
);
4871 max_buf_size
= LPFC_SLI4_MAX_BUF_SIZE
;
4872 switch (sli_family
) {
4873 case LPFC_SLI_INTF_FAMILY_BE2
:
4874 case LPFC_SLI_INTF_FAMILY_BE3
:
4875 /* There is a single hint for BE - 2 pages per BPL. */
4876 if (bf_get(lpfc_sli_intf_sli_hint1
, &phba
->sli4_hba
.sli_intf
) ==
4877 LPFC_SLI_INTF_SLI_HINT1_1
)
4878 max_buf_size
= LPFC_SLI4_FL1_MAX_BUF_SIZE
;
4880 case LPFC_SLI_INTF_FAMILY_LNCR_A0
:
4881 case LPFC_SLI_INTF_FAMILY_LNCR_B0
:
4886 for (dma_buf_size
= LPFC_SLI4_MIN_BUF_SIZE
;
4887 dma_buf_size
< max_buf_size
&& buf_size
> dma_buf_size
;
4888 dma_buf_size
= dma_buf_size
<< 1)
4890 if (dma_buf_size
== max_buf_size
)
4891 phba
->cfg_sg_seg_cnt
= (dma_buf_size
-
4892 sizeof(struct fcp_cmnd
) - sizeof(struct fcp_rsp
) -
4893 (2 * sizeof(struct sli4_sge
))) /
4894 sizeof(struct sli4_sge
);
4895 phba
->cfg_sg_dma_buf_size
= dma_buf_size
;
4897 /* Initialize buffer queue management fields */
4898 hbq_count
= lpfc_sli_hbq_count();
4899 for (i
= 0; i
< hbq_count
; ++i
)
4900 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
4901 INIT_LIST_HEAD(&phba
->rb_pend_list
);
4902 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_sli4_rb_alloc
;
4903 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_sli4_rb_free
;
4906 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
4908 /* Initialize the Abort scsi buffer list used by driver */
4909 spin_lock_init(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
4910 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
4911 /* This abort list used by worker thread */
4912 spin_lock_init(&phba
->sli4_hba
.abts_sgl_list_lock
);
4915 * Initialize driver internal slow-path work queues
4918 /* Driver internel slow-path CQ Event pool */
4919 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_cqe_event_pool
);
4920 /* Response IOCB work queue list */
4921 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_queue_event
);
4922 /* Asynchronous event CQ Event work queue list */
4923 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_asynce_work_queue
);
4924 /* Fast-path XRI aborted CQ Event work queue list */
4925 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
4926 /* Slow-path XRI aborted CQ Event work queue list */
4927 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
4928 /* Receive queue CQ Event work queue list */
4929 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_unsol_work_queue
);
4931 /* Initialize extent block lists. */
4932 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_blk_list
);
4933 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_xri_blk_list
);
4934 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_vfi_blk_list
);
4935 INIT_LIST_HEAD(&phba
->lpfc_vpi_blk_list
);
4937 /* Initialize the driver internal SLI layer lists. */
4938 lpfc_sli_setup(phba
);
4939 lpfc_sli_queue_setup(phba
);
4941 /* Allocate device driver memory */
4942 rc
= lpfc_mem_alloc(phba
, SGL_ALIGN_SZ
);
4946 /* IF Type 2 ports get initialized now. */
4947 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
4948 LPFC_SLI_INTF_IF_TYPE_2
) {
4949 rc
= lpfc_pci_function_reset(phba
);
4954 /* Create the bootstrap mailbox command */
4955 rc
= lpfc_create_bootstrap_mbox(phba
);
4959 /* Set up the host's endian order with the device. */
4960 rc
= lpfc_setup_endian_order(phba
);
4962 goto out_free_bsmbx
;
4964 /* Set up the hba's configuration parameters. */
4965 rc
= lpfc_sli4_read_config(phba
);
4967 goto out_free_bsmbx
;
4969 /* IF Type 0 ports get initialized now. */
4970 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
4971 LPFC_SLI_INTF_IF_TYPE_0
) {
4972 rc
= lpfc_pci_function_reset(phba
);
4974 goto out_free_bsmbx
;
4977 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
4981 goto out_free_bsmbx
;
4984 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
4985 lpfc_supported_pages(mboxq
);
4986 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
4988 mqe
= &mboxq
->u
.mqe
;
4989 memcpy(&pn_page
[0], ((uint8_t *)&mqe
->un
.supp_pages
.word3
),
4990 LPFC_MAX_SUPPORTED_PAGES
);
4991 for (i
= 0; i
< LPFC_MAX_SUPPORTED_PAGES
; i
++) {
4992 switch (pn_page
[i
]) {
4993 case LPFC_SLI4_PARAMETERS
:
4994 phba
->sli4_hba
.pc_sli4_params
.supported
= 1;
5000 /* Read the port's SLI4 Parameters capabilities if supported. */
5001 if (phba
->sli4_hba
.pc_sli4_params
.supported
)
5002 rc
= lpfc_pc_sli4_params_get(phba
, mboxq
);
5004 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5006 goto out_free_bsmbx
;
5010 * Get sli4 parameters that override parameters from Port capabilities.
5011 * If this call fails, it isn't critical unless the SLI4 parameters come
5014 rc
= lpfc_get_sli4_parameters(phba
, mboxq
);
5016 if (phba
->sli4_hba
.extents_in_use
&&
5017 phba
->sli4_hba
.rpi_hdrs_in_use
) {
5018 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5019 "2999 Unsupported SLI4 Parameters "
5020 "Extents and RPI headers enabled.\n");
5021 goto out_free_bsmbx
;
5024 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5025 /* Verify all the SLI4 queues */
5026 rc
= lpfc_sli4_queue_verify(phba
);
5028 goto out_free_bsmbx
;
5030 /* Create driver internal CQE event pool */
5031 rc
= lpfc_sli4_cq_event_pool_create(phba
);
5033 goto out_free_bsmbx
;
5035 /* Initialize sgl lists per host */
5036 lpfc_init_sgl_list(phba
);
5038 /* Allocate and initialize active sgl array */
5039 rc
= lpfc_init_active_sgl_array(phba
);
5041 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5042 "1430 Failed to initialize sgl list.\n");
5043 goto out_destroy_cq_event_pool
;
5045 rc
= lpfc_sli4_init_rpi_hdrs(phba
);
5047 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5048 "1432 Failed to initialize rpi headers.\n");
5049 goto out_free_active_sgl
;
5052 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
5053 longs
= (LPFC_SLI4_FCF_TBL_INDX_MAX
+ BITS_PER_LONG
- 1)/BITS_PER_LONG
;
5054 phba
->fcf
.fcf_rr_bmask
= kzalloc(longs
* sizeof(unsigned long),
5056 if (!phba
->fcf
.fcf_rr_bmask
) {
5057 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5058 "2759 Failed allocate memory for FCF round "
5059 "robin failover bmask\n");
5061 goto out_remove_rpi_hdrs
;
5064 phba
->sli4_hba
.fcp_eq_hdl
=
5065 kzalloc((sizeof(struct lpfc_fcp_eq_hdl
) *
5066 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
5067 if (!phba
->sli4_hba
.fcp_eq_hdl
) {
5068 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5069 "2572 Failed allocate memory for "
5070 "fast-path per-EQ handle array\n");
5072 goto out_free_fcf_rr_bmask
;
5075 phba
->sli4_hba
.msix_entries
= kzalloc((sizeof(struct msix_entry
) *
5076 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
5077 if (!phba
->sli4_hba
.msix_entries
) {
5078 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5079 "2573 Failed allocate memory for msi-x "
5080 "interrupt vector entries\n");
5082 goto out_free_fcp_eq_hdl
;
5086 * Enable sr-iov virtual functions if supported and configured
5087 * through the module parameter.
5089 if (phba
->cfg_sriov_nr_virtfn
> 0) {
5090 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
,
5091 phba
->cfg_sriov_nr_virtfn
);
5093 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5094 "3020 Requested number of SR-IOV "
5095 "virtual functions (%d) is not "
5097 phba
->cfg_sriov_nr_virtfn
);
5098 phba
->cfg_sriov_nr_virtfn
= 0;
5104 out_free_fcp_eq_hdl
:
5105 kfree(phba
->sli4_hba
.fcp_eq_hdl
);
5106 out_free_fcf_rr_bmask
:
5107 kfree(phba
->fcf
.fcf_rr_bmask
);
5108 out_remove_rpi_hdrs
:
5109 lpfc_sli4_remove_rpi_hdrs(phba
);
5110 out_free_active_sgl
:
5111 lpfc_free_active_sgl(phba
);
5112 out_destroy_cq_event_pool
:
5113 lpfc_sli4_cq_event_pool_destroy(phba
);
5115 lpfc_destroy_bootstrap_mbox(phba
);
5117 lpfc_mem_free(phba
);
5122 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
5123 * @phba: pointer to lpfc hba data structure.
5125 * This routine is invoked to unset the driver internal resources set up
5126 * specific for supporting the SLI-4 HBA device it attached to.
5129 lpfc_sli4_driver_resource_unset(struct lpfc_hba
*phba
)
5131 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
5133 /* Free memory allocated for msi-x interrupt vector entries */
5134 kfree(phba
->sli4_hba
.msix_entries
);
5136 /* Free memory allocated for fast-path work queue handles */
5137 kfree(phba
->sli4_hba
.fcp_eq_hdl
);
5139 /* Free the allocated rpi headers. */
5140 lpfc_sli4_remove_rpi_hdrs(phba
);
5141 lpfc_sli4_remove_rpis(phba
);
5143 /* Free eligible FCF index bmask */
5144 kfree(phba
->fcf
.fcf_rr_bmask
);
5146 /* Free the ELS sgl list */
5147 lpfc_free_active_sgl(phba
);
5148 lpfc_free_els_sgl_list(phba
);
5150 /* Free the completion queue EQ event pool */
5151 lpfc_sli4_cq_event_release_all(phba
);
5152 lpfc_sli4_cq_event_pool_destroy(phba
);
5154 /* Release resource identifiers. */
5155 lpfc_sli4_dealloc_resource_identifiers(phba
);
5157 /* Free the bsmbx region. */
5158 lpfc_destroy_bootstrap_mbox(phba
);
5160 /* Free the SLI Layer memory with SLI4 HBAs */
5161 lpfc_mem_free_all(phba
);
5163 /* Free the current connect table */
5164 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
5165 &phba
->fcf_conn_rec_list
, list
) {
5166 list_del_init(&conn_entry
->list
);
5174 * lpfc_init_api_table_setup - Set up init api function jump table
5175 * @phba: The hba struct for which this call is being executed.
5176 * @dev_grp: The HBA PCI-Device group number.
5178 * This routine sets up the device INIT interface API function jump table
5181 * Returns: 0 - success, -ENODEV - failure.
5184 lpfc_init_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
5186 phba
->lpfc_hba_init_link
= lpfc_hba_init_link
;
5187 phba
->lpfc_hba_down_link
= lpfc_hba_down_link
;
5188 phba
->lpfc_selective_reset
= lpfc_selective_reset
;
5190 case LPFC_PCI_DEV_LP
:
5191 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s3
;
5192 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s3
;
5193 phba
->lpfc_stop_port
= lpfc_stop_port_s3
;
5195 case LPFC_PCI_DEV_OC
:
5196 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s4
;
5197 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s4
;
5198 phba
->lpfc_stop_port
= lpfc_stop_port_s4
;
5201 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5202 "1431 Invalid HBA PCI-device group: 0x%x\n",
5211 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5212 * @phba: pointer to lpfc hba data structure.
5214 * This routine is invoked to set up the driver internal resources before the
5215 * device specific resource setup to support the HBA device it attached to.
5219 * other values - error
5222 lpfc_setup_driver_resource_phase1(struct lpfc_hba
*phba
)
5225 * Driver resources common to all SLI revisions
5227 atomic_set(&phba
->fast_event_count
, 0);
5228 spin_lock_init(&phba
->hbalock
);
5230 /* Initialize ndlp management spinlock */
5231 spin_lock_init(&phba
->ndlp_lock
);
5233 INIT_LIST_HEAD(&phba
->port_list
);
5234 INIT_LIST_HEAD(&phba
->work_list
);
5235 init_waitqueue_head(&phba
->wait_4_mlo_m_q
);
5237 /* Initialize the wait queue head for the kernel thread */
5238 init_waitqueue_head(&phba
->work_waitq
);
5240 /* Initialize the scsi buffer list used by driver for scsi IO */
5241 spin_lock_init(&phba
->scsi_buf_list_lock
);
5242 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list
);
5244 /* Initialize the fabric iocb list */
5245 INIT_LIST_HEAD(&phba
->fabric_iocb_list
);
5247 /* Initialize list to save ELS buffers */
5248 INIT_LIST_HEAD(&phba
->elsbuf
);
5250 /* Initialize FCF connection rec list */
5251 INIT_LIST_HEAD(&phba
->fcf_conn_rec_list
);
5257 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5258 * @phba: pointer to lpfc hba data structure.
5260 * This routine is invoked to set up the driver internal resources after the
5261 * device specific resource setup to support the HBA device it attached to.
5265 * other values - error
5268 lpfc_setup_driver_resource_phase2(struct lpfc_hba
*phba
)
5272 /* Startup the kernel thread for this host adapter. */
5273 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
5274 "lpfc_worker_%d", phba
->brd_no
);
5275 if (IS_ERR(phba
->worker_thread
)) {
5276 error
= PTR_ERR(phba
->worker_thread
);
5284 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5285 * @phba: pointer to lpfc hba data structure.
5287 * This routine is invoked to unset the driver internal resources set up after
5288 * the device specific resource setup for supporting the HBA device it
5292 lpfc_unset_driver_resource_phase2(struct lpfc_hba
*phba
)
5294 /* Stop kernel worker thread */
5295 kthread_stop(phba
->worker_thread
);
5299 * lpfc_free_iocb_list - Free iocb list.
5300 * @phba: pointer to lpfc hba data structure.
5302 * This routine is invoked to free the driver's IOCB list and memory.
5305 lpfc_free_iocb_list(struct lpfc_hba
*phba
)
5307 struct lpfc_iocbq
*iocbq_entry
= NULL
, *iocbq_next
= NULL
;
5309 spin_lock_irq(&phba
->hbalock
);
5310 list_for_each_entry_safe(iocbq_entry
, iocbq_next
,
5311 &phba
->lpfc_iocb_list
, list
) {
5312 list_del(&iocbq_entry
->list
);
5314 phba
->total_iocbq_bufs
--;
5316 spin_unlock_irq(&phba
->hbalock
);
5322 * lpfc_init_iocb_list - Allocate and initialize iocb list.
5323 * @phba: pointer to lpfc hba data structure.
5325 * This routine is invoked to allocate and initizlize the driver's IOCB
5326 * list and set up the IOCB tag array accordingly.
5330 * other values - error
5333 lpfc_init_iocb_list(struct lpfc_hba
*phba
, int iocb_count
)
5335 struct lpfc_iocbq
*iocbq_entry
= NULL
;
5339 /* Initialize and populate the iocb list per host. */
5340 INIT_LIST_HEAD(&phba
->lpfc_iocb_list
);
5341 for (i
= 0; i
< iocb_count
; i
++) {
5342 iocbq_entry
= kzalloc(sizeof(struct lpfc_iocbq
), GFP_KERNEL
);
5343 if (iocbq_entry
== NULL
) {
5344 printk(KERN_ERR
"%s: only allocated %d iocbs of "
5345 "expected %d count. Unloading driver.\n",
5346 __func__
, i
, LPFC_IOCB_LIST_CNT
);
5347 goto out_free_iocbq
;
5350 iotag
= lpfc_sli_next_iotag(phba
, iocbq_entry
);
5353 printk(KERN_ERR
"%s: failed to allocate IOTAG. "
5354 "Unloading driver.\n", __func__
);
5355 goto out_free_iocbq
;
5357 iocbq_entry
->sli4_lxritag
= NO_XRI
;
5358 iocbq_entry
->sli4_xritag
= NO_XRI
;
5360 spin_lock_irq(&phba
->hbalock
);
5361 list_add(&iocbq_entry
->list
, &phba
->lpfc_iocb_list
);
5362 phba
->total_iocbq_bufs
++;
5363 spin_unlock_irq(&phba
->hbalock
);
5369 lpfc_free_iocb_list(phba
);
5375 * lpfc_free_sgl_list - Free a given sgl list.
5376 * @phba: pointer to lpfc hba data structure.
5377 * @sglq_list: pointer to the head of sgl list.
5379 * This routine is invoked to free a give sgl list and memory.
5382 lpfc_free_sgl_list(struct lpfc_hba
*phba
, struct list_head
*sglq_list
)
5384 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
5386 list_for_each_entry_safe(sglq_entry
, sglq_next
, sglq_list
, list
) {
5387 list_del(&sglq_entry
->list
);
5388 lpfc_mbuf_free(phba
, sglq_entry
->virt
, sglq_entry
->phys
);
5394 * lpfc_free_els_sgl_list - Free els sgl list.
5395 * @phba: pointer to lpfc hba data structure.
5397 * This routine is invoked to free the driver's els sgl list and memory.
5400 lpfc_free_els_sgl_list(struct lpfc_hba
*phba
)
5402 LIST_HEAD(sglq_list
);
5404 /* Retrieve all els sgls from driver list */
5405 spin_lock_irq(&phba
->hbalock
);
5406 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &sglq_list
);
5407 spin_unlock_irq(&phba
->hbalock
);
5409 /* Now free the sgl list */
5410 lpfc_free_sgl_list(phba
, &sglq_list
);
5414 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
5415 * @phba: pointer to lpfc hba data structure.
5417 * This routine is invoked to allocate the driver's active sgl memory.
5418 * This array will hold the sglq_entry's for active IOs.
5421 lpfc_init_active_sgl_array(struct lpfc_hba
*phba
)
5424 size
= sizeof(struct lpfc_sglq
*);
5425 size
*= phba
->sli4_hba
.max_cfg_param
.max_xri
;
5427 phba
->sli4_hba
.lpfc_sglq_active_list
=
5428 kzalloc(size
, GFP_KERNEL
);
5429 if (!phba
->sli4_hba
.lpfc_sglq_active_list
)
5435 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
5436 * @phba: pointer to lpfc hba data structure.
5438 * This routine is invoked to walk through the array of active sglq entries
5439 * and free all of the resources.
5440 * This is just a place holder for now.
5443 lpfc_free_active_sgl(struct lpfc_hba
*phba
)
5445 kfree(phba
->sli4_hba
.lpfc_sglq_active_list
);
5449 * lpfc_init_sgl_list - Allocate and initialize sgl list.
5450 * @phba: pointer to lpfc hba data structure.
5452 * This routine is invoked to allocate and initizlize the driver's sgl
5453 * list and set up the sgl xritag tag array accordingly.
5457 lpfc_init_sgl_list(struct lpfc_hba
*phba
)
5459 /* Initialize and populate the sglq list per host/VF. */
5460 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_sgl_list
);
5461 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
5463 /* els xri-sgl book keeping */
5464 phba
->sli4_hba
.els_xri_cnt
= 0;
5466 /* scsi xri-buffer book keeping */
5467 phba
->sli4_hba
.scsi_xri_cnt
= 0;
5471 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5472 * @phba: pointer to lpfc hba data structure.
5474 * This routine is invoked to post rpi header templates to the
5475 * port for those SLI4 ports that do not support extents. This routine
5476 * posts a PAGE_SIZE memory region to the port to hold up to
5477 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5478 * and should be called only when interrupts are disabled.
5482 * -ERROR - otherwise.
5485 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba
*phba
)
5488 struct lpfc_rpi_hdr
*rpi_hdr
;
5490 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_hdr_list
);
5491 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5493 if (phba
->sli4_hba
.extents_in_use
)
5496 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
5498 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5499 "0391 Error during rpi post operation\n");
5500 lpfc_sli4_remove_rpis(phba
);
5508 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
5509 * @phba: pointer to lpfc hba data structure.
5511 * This routine is invoked to allocate a single 4KB memory region to
5512 * support rpis and stores them in the phba. This single region
5513 * provides support for up to 64 rpis. The region is used globally
5517 * A valid rpi hdr on success.
5518 * A NULL pointer on any failure.
5520 struct lpfc_rpi_hdr
*
5521 lpfc_sli4_create_rpi_hdr(struct lpfc_hba
*phba
)
5523 uint16_t rpi_limit
, curr_rpi_range
;
5524 struct lpfc_dmabuf
*dmabuf
;
5525 struct lpfc_rpi_hdr
*rpi_hdr
;
5529 * If the SLI4 port supports extents, posting the rpi header isn't
5530 * required. Set the expected maximum count and let the actual value
5531 * get set when extents are fully allocated.
5533 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5535 if (phba
->sli4_hba
.extents_in_use
)
5538 /* The limit on the logical index is just the max_rpi count. */
5539 rpi_limit
= phba
->sli4_hba
.max_cfg_param
.rpi_base
+
5540 phba
->sli4_hba
.max_cfg_param
.max_rpi
- 1;
5542 spin_lock_irq(&phba
->hbalock
);
5544 * Establish the starting RPI in this header block. The starting
5545 * rpi is normalized to a zero base because the physical rpi is
5548 curr_rpi_range
= phba
->sli4_hba
.next_rpi
;
5549 spin_unlock_irq(&phba
->hbalock
);
5552 * The port has a limited number of rpis. The increment here
5553 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
5554 * and to allow the full max_rpi range per port.
5556 if ((curr_rpi_range
+ (LPFC_RPI_HDR_COUNT
- 1)) > rpi_limit
)
5557 rpi_count
= rpi_limit
- curr_rpi_range
;
5559 rpi_count
= LPFC_RPI_HDR_COUNT
;
5564 * First allocate the protocol header region for the port. The
5565 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
5567 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
5571 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
5572 LPFC_HDR_TEMPLATE_SIZE
,
5575 if (!dmabuf
->virt
) {
5577 goto err_free_dmabuf
;
5580 memset(dmabuf
->virt
, 0, LPFC_HDR_TEMPLATE_SIZE
);
5581 if (!IS_ALIGNED(dmabuf
->phys
, LPFC_HDR_TEMPLATE_SIZE
)) {
5583 goto err_free_coherent
;
5586 /* Save the rpi header data for cleanup later. */
5587 rpi_hdr
= kzalloc(sizeof(struct lpfc_rpi_hdr
), GFP_KERNEL
);
5589 goto err_free_coherent
;
5591 rpi_hdr
->dmabuf
= dmabuf
;
5592 rpi_hdr
->len
= LPFC_HDR_TEMPLATE_SIZE
;
5593 rpi_hdr
->page_count
= 1;
5594 spin_lock_irq(&phba
->hbalock
);
5596 /* The rpi_hdr stores the logical index only. */
5597 rpi_hdr
->start_rpi
= curr_rpi_range
;
5598 list_add_tail(&rpi_hdr
->list
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
);
5601 * The next_rpi stores the next logical module-64 rpi value used
5602 * to post physical rpis in subsequent rpi postings.
5604 phba
->sli4_hba
.next_rpi
+= rpi_count
;
5605 spin_unlock_irq(&phba
->hbalock
);
5609 dma_free_coherent(&phba
->pcidev
->dev
, LPFC_HDR_TEMPLATE_SIZE
,
5610 dmabuf
->virt
, dmabuf
->phys
);
5617 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
5618 * @phba: pointer to lpfc hba data structure.
5620 * This routine is invoked to remove all memory resources allocated
5621 * to support rpis for SLI4 ports not supporting extents. This routine
5622 * presumes the caller has released all rpis consumed by fabric or port
5623 * logins and is prepared to have the header pages removed.
5626 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba
*phba
)
5628 struct lpfc_rpi_hdr
*rpi_hdr
, *next_rpi_hdr
;
5630 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5633 list_for_each_entry_safe(rpi_hdr
, next_rpi_hdr
,
5634 &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
5635 list_del(&rpi_hdr
->list
);
5636 dma_free_coherent(&phba
->pcidev
->dev
, rpi_hdr
->len
,
5637 rpi_hdr
->dmabuf
->virt
, rpi_hdr
->dmabuf
->phys
);
5638 kfree(rpi_hdr
->dmabuf
);
5642 /* There are no rpis available to the port now. */
5643 phba
->sli4_hba
.next_rpi
= 0;
5647 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
5648 * @pdev: pointer to pci device data structure.
5650 * This routine is invoked to allocate the driver hba data structure for an
5651 * HBA device. If the allocation is successful, the phba reference to the
5652 * PCI device data structure is set.
5655 * pointer to @phba - successful
5658 static struct lpfc_hba
*
5659 lpfc_hba_alloc(struct pci_dev
*pdev
)
5661 struct lpfc_hba
*phba
;
5663 /* Allocate memory for HBA structure */
5664 phba
= kzalloc(sizeof(struct lpfc_hba
), GFP_KERNEL
);
5666 dev_err(&pdev
->dev
, "failed to allocate hba struct\n");
5670 /* Set reference to PCI device in HBA structure */
5671 phba
->pcidev
= pdev
;
5673 /* Assign an unused board number */
5674 phba
->brd_no
= lpfc_get_instance();
5675 if (phba
->brd_no
< 0) {
5680 spin_lock_init(&phba
->ct_ev_lock
);
5681 INIT_LIST_HEAD(&phba
->ct_ev_waiters
);
5687 * lpfc_hba_free - Free driver hba data structure with a device.
5688 * @phba: pointer to lpfc hba data structure.
5690 * This routine is invoked to free the driver hba data structure with an
5694 lpfc_hba_free(struct lpfc_hba
*phba
)
5696 /* Release the driver assigned board number */
5697 idr_remove(&lpfc_hba_index
, phba
->brd_no
);
5699 /* Free memory allocated with sli rings */
5700 kfree(phba
->sli
.ring
);
5701 phba
->sli
.ring
= NULL
;
5708 * lpfc_create_shost - Create hba physical port with associated scsi host.
5709 * @phba: pointer to lpfc hba data structure.
5711 * This routine is invoked to create HBA physical port and associate a SCSI
5716 * other values - error
5719 lpfc_create_shost(struct lpfc_hba
*phba
)
5721 struct lpfc_vport
*vport
;
5722 struct Scsi_Host
*shost
;
5724 /* Initialize HBA FC structure */
5725 phba
->fc_edtov
= FF_DEF_EDTOV
;
5726 phba
->fc_ratov
= FF_DEF_RATOV
;
5727 phba
->fc_altov
= FF_DEF_ALTOV
;
5728 phba
->fc_arbtov
= FF_DEF_ARBTOV
;
5730 atomic_set(&phba
->sdev_cnt
, 0);
5731 vport
= lpfc_create_port(phba
, phba
->brd_no
, &phba
->pcidev
->dev
);
5735 shost
= lpfc_shost_from_vport(vport
);
5736 phba
->pport
= vport
;
5737 lpfc_debugfs_initialize(vport
);
5738 /* Put reference to SCSI host to driver's device private data */
5739 pci_set_drvdata(phba
->pcidev
, shost
);
5745 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
5746 * @phba: pointer to lpfc hba data structure.
5748 * This routine is invoked to destroy HBA physical port and the associated
5752 lpfc_destroy_shost(struct lpfc_hba
*phba
)
5754 struct lpfc_vport
*vport
= phba
->pport
;
5756 /* Destroy physical port that associated with the SCSI host */
5757 destroy_port(vport
);
5763 * lpfc_setup_bg - Setup Block guard structures and debug areas.
5764 * @phba: pointer to lpfc hba data structure.
5765 * @shost: the shost to be used to detect Block guard settings.
5767 * This routine sets up the local Block guard protocol settings for @shost.
5768 * This routine also allocates memory for debugging bg buffers.
5771 lpfc_setup_bg(struct lpfc_hba
*phba
, struct Scsi_Host
*shost
)
5777 if (lpfc_prot_mask
&& lpfc_prot_guard
) {
5778 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5779 "1478 Registering BlockGuard with the "
5782 old_mask
= lpfc_prot_mask
;
5783 old_guard
= lpfc_prot_guard
;
5785 /* Only allow supported values */
5786 lpfc_prot_mask
&= (SHOST_DIF_TYPE1_PROTECTION
|
5787 SHOST_DIX_TYPE0_PROTECTION
|
5788 SHOST_DIX_TYPE1_PROTECTION
);
5789 lpfc_prot_guard
&= (SHOST_DIX_GUARD_IP
| SHOST_DIX_GUARD_CRC
);
5791 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
5792 if (lpfc_prot_mask
== SHOST_DIX_TYPE1_PROTECTION
)
5793 lpfc_prot_mask
|= SHOST_DIF_TYPE1_PROTECTION
;
5795 if (lpfc_prot_mask
&& lpfc_prot_guard
) {
5796 if ((old_mask
!= lpfc_prot_mask
) ||
5797 (old_guard
!= lpfc_prot_guard
))
5798 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5799 "1475 Registering BlockGuard with the "
5800 "SCSI layer: mask %d guard %d\n",
5801 lpfc_prot_mask
, lpfc_prot_guard
);
5803 scsi_host_set_prot(shost
, lpfc_prot_mask
);
5804 scsi_host_set_guard(shost
, lpfc_prot_guard
);
5806 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5807 "1479 Not Registering BlockGuard with the SCSI "
5808 "layer, Bad protection parameters: %d %d\n",
5809 old_mask
, old_guard
);
5812 if (!_dump_buf_data
) {
5814 spin_lock_init(&_dump_buf_lock
);
5816 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
5817 if (_dump_buf_data
) {
5818 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5819 "9043 BLKGRD: allocated %d pages for "
5820 "_dump_buf_data at 0x%p\n",
5821 (1 << pagecnt
), _dump_buf_data
);
5822 _dump_buf_data_order
= pagecnt
;
5823 memset(_dump_buf_data
, 0,
5824 ((1 << PAGE_SHIFT
) << pagecnt
));
5829 if (!_dump_buf_data_order
)
5830 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5831 "9044 BLKGRD: ERROR unable to allocate "
5832 "memory for hexdump\n");
5834 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5835 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
5836 "\n", _dump_buf_data
);
5837 if (!_dump_buf_dif
) {
5840 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
5841 if (_dump_buf_dif
) {
5842 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5843 "9046 BLKGRD: allocated %d pages for "
5844 "_dump_buf_dif at 0x%p\n",
5845 (1 << pagecnt
), _dump_buf_dif
);
5846 _dump_buf_dif_order
= pagecnt
;
5847 memset(_dump_buf_dif
, 0,
5848 ((1 << PAGE_SHIFT
) << pagecnt
));
5853 if (!_dump_buf_dif_order
)
5854 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5855 "9047 BLKGRD: ERROR unable to allocate "
5856 "memory for hexdump\n");
5858 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5859 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
5864 * lpfc_post_init_setup - Perform necessary device post initialization setup.
5865 * @phba: pointer to lpfc hba data structure.
5867 * This routine is invoked to perform all the necessary post initialization
5868 * setup for the device.
5871 lpfc_post_init_setup(struct lpfc_hba
*phba
)
5873 struct Scsi_Host
*shost
;
5874 struct lpfc_adapter_event_header adapter_event
;
5876 /* Get the default values for Model Name and Description */
5877 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
5880 * hba setup may have changed the hba_queue_depth so we need to
5881 * adjust the value of can_queue.
5883 shost
= pci_get_drvdata(phba
->pcidev
);
5884 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
5885 if (phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)
5886 lpfc_setup_bg(phba
, shost
);
5888 lpfc_host_attrib_init(shost
);
5890 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
5891 spin_lock_irq(shost
->host_lock
);
5892 lpfc_poll_start_timer(phba
);
5893 spin_unlock_irq(shost
->host_lock
);
5896 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5897 "0428 Perform SCSI scan\n");
5898 /* Send board arrival event to upper layer */
5899 adapter_event
.event_type
= FC_REG_ADAPTER_EVENT
;
5900 adapter_event
.subcategory
= LPFC_EVENT_ARRIVAL
;
5901 fc_host_post_vendor_event(shost
, fc_get_event_number(),
5902 sizeof(adapter_event
),
5903 (char *) &adapter_event
,
5909 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
5910 * @phba: pointer to lpfc hba data structure.
5912 * This routine is invoked to set up the PCI device memory space for device
5913 * with SLI-3 interface spec.
5917 * other values - error
5920 lpfc_sli_pci_mem_setup(struct lpfc_hba
*phba
)
5922 struct pci_dev
*pdev
;
5923 unsigned long bar0map_len
, bar2map_len
;
5926 int error
= -ENODEV
;
5928 /* Obtain PCI device reference */
5932 pdev
= phba
->pcidev
;
5934 /* Set the device DMA mask size */
5935 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
5936 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
5937 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
5938 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
5943 /* Get the bus address of Bar0 and Bar2 and the number of bytes
5944 * required by each mapping.
5946 phba
->pci_bar0_map
= pci_resource_start(pdev
, 0);
5947 bar0map_len
= pci_resource_len(pdev
, 0);
5949 phba
->pci_bar2_map
= pci_resource_start(pdev
, 2);
5950 bar2map_len
= pci_resource_len(pdev
, 2);
5952 /* Map HBA SLIM to a kernel virtual address. */
5953 phba
->slim_memmap_p
= ioremap(phba
->pci_bar0_map
, bar0map_len
);
5954 if (!phba
->slim_memmap_p
) {
5955 dev_printk(KERN_ERR
, &pdev
->dev
,
5956 "ioremap failed for SLIM memory.\n");
5960 /* Map HBA Control Registers to a kernel virtual address. */
5961 phba
->ctrl_regs_memmap_p
= ioremap(phba
->pci_bar2_map
, bar2map_len
);
5962 if (!phba
->ctrl_regs_memmap_p
) {
5963 dev_printk(KERN_ERR
, &pdev
->dev
,
5964 "ioremap failed for HBA control registers.\n");
5965 goto out_iounmap_slim
;
5968 /* Allocate memory for SLI-2 structures */
5969 phba
->slim2p
.virt
= dma_alloc_coherent(&pdev
->dev
,
5973 if (!phba
->slim2p
.virt
)
5976 memset(phba
->slim2p
.virt
, 0, SLI2_SLIM_SIZE
);
5977 phba
->mbox
= phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, mbx
);
5978 phba
->mbox_ext
= (phba
->slim2p
.virt
+
5979 offsetof(struct lpfc_sli2_slim
, mbx_ext_words
));
5980 phba
->pcb
= (phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, pcb
));
5981 phba
->IOCBs
= (phba
->slim2p
.virt
+
5982 offsetof(struct lpfc_sli2_slim
, IOCBs
));
5984 phba
->hbqslimp
.virt
= dma_alloc_coherent(&pdev
->dev
,
5985 lpfc_sli_hbq_size(),
5986 &phba
->hbqslimp
.phys
,
5988 if (!phba
->hbqslimp
.virt
)
5991 hbq_count
= lpfc_sli_hbq_count();
5992 ptr
= phba
->hbqslimp
.virt
;
5993 for (i
= 0; i
< hbq_count
; ++i
) {
5994 phba
->hbqs
[i
].hbq_virt
= ptr
;
5995 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
5996 ptr
+= (lpfc_hbq_defs
[i
]->entry_count
*
5997 sizeof(struct lpfc_hbq_entry
));
5999 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_els_hbq_alloc
;
6000 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_els_hbq_free
;
6002 memset(phba
->hbqslimp
.virt
, 0, lpfc_sli_hbq_size());
6004 INIT_LIST_HEAD(&phba
->rb_pend_list
);
6006 phba
->MBslimaddr
= phba
->slim_memmap_p
;
6007 phba
->HAregaddr
= phba
->ctrl_regs_memmap_p
+ HA_REG_OFFSET
;
6008 phba
->CAregaddr
= phba
->ctrl_regs_memmap_p
+ CA_REG_OFFSET
;
6009 phba
->HSregaddr
= phba
->ctrl_regs_memmap_p
+ HS_REG_OFFSET
;
6010 phba
->HCregaddr
= phba
->ctrl_regs_memmap_p
+ HC_REG_OFFSET
;
6015 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
6016 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
6018 iounmap(phba
->ctrl_regs_memmap_p
);
6020 iounmap(phba
->slim_memmap_p
);
6026 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6027 * @phba: pointer to lpfc hba data structure.
6029 * This routine is invoked to unset the PCI device memory space for device
6030 * with SLI-3 interface spec.
6033 lpfc_sli_pci_mem_unset(struct lpfc_hba
*phba
)
6035 struct pci_dev
*pdev
;
6037 /* Obtain PCI device reference */
6041 pdev
= phba
->pcidev
;
6043 /* Free coherent DMA memory allocated */
6044 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
6045 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
6046 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
6047 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
6049 /* I/O memory unmap */
6050 iounmap(phba
->ctrl_regs_memmap_p
);
6051 iounmap(phba
->slim_memmap_p
);
6057 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6058 * @phba: pointer to lpfc hba data structure.
6060 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6061 * done and check status.
6063 * Return 0 if successful, otherwise -ENODEV.
6066 lpfc_sli4_post_status_check(struct lpfc_hba
*phba
)
6068 struct lpfc_register portsmphr_reg
, uerrlo_reg
, uerrhi_reg
;
6069 struct lpfc_register reg_data
;
6070 int i
, port_error
= 0;
6073 memset(&portsmphr_reg
, 0, sizeof(portsmphr_reg
));
6074 memset(®_data
, 0, sizeof(reg_data
));
6075 if (!phba
->sli4_hba
.PSMPHRregaddr
)
6078 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6079 for (i
= 0; i
< 3000; i
++) {
6080 if (lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
6081 &portsmphr_reg
.word0
) ||
6082 (bf_get(lpfc_port_smphr_perr
, &portsmphr_reg
))) {
6083 /* Port has a fatal POST error, break out */
6084 port_error
= -ENODEV
;
6087 if (LPFC_POST_STAGE_PORT_READY
==
6088 bf_get(lpfc_port_smphr_port_status
, &portsmphr_reg
))
6094 * If there was a port error during POST, then don't proceed with
6095 * other register reads as the data may not be valid. Just exit.
6098 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6099 "1408 Port Failed POST - portsmphr=0x%x, "
6100 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
6101 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
6102 portsmphr_reg
.word0
,
6103 bf_get(lpfc_port_smphr_perr
, &portsmphr_reg
),
6104 bf_get(lpfc_port_smphr_sfi
, &portsmphr_reg
),
6105 bf_get(lpfc_port_smphr_nip
, &portsmphr_reg
),
6106 bf_get(lpfc_port_smphr_ipc
, &portsmphr_reg
),
6107 bf_get(lpfc_port_smphr_scr1
, &portsmphr_reg
),
6108 bf_get(lpfc_port_smphr_scr2
, &portsmphr_reg
),
6109 bf_get(lpfc_port_smphr_host_scratch
, &portsmphr_reg
),
6110 bf_get(lpfc_port_smphr_port_status
, &portsmphr_reg
));
6112 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6113 "2534 Device Info: SLIFamily=0x%x, "
6114 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
6115 "SLIHint_2=0x%x, FT=0x%x\n",
6116 bf_get(lpfc_sli_intf_sli_family
,
6117 &phba
->sli4_hba
.sli_intf
),
6118 bf_get(lpfc_sli_intf_slirev
,
6119 &phba
->sli4_hba
.sli_intf
),
6120 bf_get(lpfc_sli_intf_if_type
,
6121 &phba
->sli4_hba
.sli_intf
),
6122 bf_get(lpfc_sli_intf_sli_hint1
,
6123 &phba
->sli4_hba
.sli_intf
),
6124 bf_get(lpfc_sli_intf_sli_hint2
,
6125 &phba
->sli4_hba
.sli_intf
),
6126 bf_get(lpfc_sli_intf_func_type
,
6127 &phba
->sli4_hba
.sli_intf
));
6129 * Check for other Port errors during the initialization
6130 * process. Fail the load if the port did not come up
6133 if_type
= bf_get(lpfc_sli_intf_if_type
,
6134 &phba
->sli4_hba
.sli_intf
);
6136 case LPFC_SLI_INTF_IF_TYPE_0
:
6137 phba
->sli4_hba
.ue_mask_lo
=
6138 readl(phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
);
6139 phba
->sli4_hba
.ue_mask_hi
=
6140 readl(phba
->sli4_hba
.u
.if_type0
.UEMASKHIregaddr
);
6142 readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
);
6144 readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
);
6145 if ((~phba
->sli4_hba
.ue_mask_lo
& uerrlo_reg
.word0
) ||
6146 (~phba
->sli4_hba
.ue_mask_hi
& uerrhi_reg
.word0
)) {
6147 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6148 "1422 Unrecoverable Error "
6149 "Detected during POST "
6150 "uerr_lo_reg=0x%x, "
6151 "uerr_hi_reg=0x%x, "
6152 "ue_mask_lo_reg=0x%x, "
6153 "ue_mask_hi_reg=0x%x\n",
6156 phba
->sli4_hba
.ue_mask_lo
,
6157 phba
->sli4_hba
.ue_mask_hi
);
6158 port_error
= -ENODEV
;
6161 case LPFC_SLI_INTF_IF_TYPE_2
:
6162 /* Final checks. The port status should be clean. */
6163 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
6165 (bf_get(lpfc_sliport_status_err
, ®_data
) &&
6166 !bf_get(lpfc_sliport_status_rn
, ®_data
))) {
6167 phba
->work_status
[0] =
6168 readl(phba
->sli4_hba
.u
.if_type2
.
6170 phba
->work_status
[1] =
6171 readl(phba
->sli4_hba
.u
.if_type2
.
6173 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6174 "2888 Unrecoverable port error "
6175 "following POST: port status reg "
6176 "0x%x, port_smphr reg 0x%x, "
6177 "error 1=0x%x, error 2=0x%x\n",
6179 portsmphr_reg
.word0
,
6180 phba
->work_status
[0],
6181 phba
->work_status
[1]);
6182 port_error
= -ENODEV
;
6185 case LPFC_SLI_INTF_IF_TYPE_1
:
6194 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6195 * @phba: pointer to lpfc hba data structure.
6196 * @if_type: The SLI4 interface type getting configured.
6198 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6202 lpfc_sli4_bar0_register_memmap(struct lpfc_hba
*phba
, uint32_t if_type
)
6205 case LPFC_SLI_INTF_IF_TYPE_0
:
6206 phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
=
6207 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UERR_STATUS_LO
;
6208 phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
=
6209 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UERR_STATUS_HI
;
6210 phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
=
6211 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UE_MASK_LO
;
6212 phba
->sli4_hba
.u
.if_type0
.UEMASKHIregaddr
=
6213 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UE_MASK_HI
;
6214 phba
->sli4_hba
.SLIINTFregaddr
=
6215 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_SLI_INTF
;
6217 case LPFC_SLI_INTF_IF_TYPE_2
:
6218 phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
=
6219 phba
->sli4_hba
.conf_regs_memmap_p
+
6220 LPFC_CTL_PORT_ER1_OFFSET
;
6221 phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
=
6222 phba
->sli4_hba
.conf_regs_memmap_p
+
6223 LPFC_CTL_PORT_ER2_OFFSET
;
6224 phba
->sli4_hba
.u
.if_type2
.CTRLregaddr
=
6225 phba
->sli4_hba
.conf_regs_memmap_p
+
6226 LPFC_CTL_PORT_CTL_OFFSET
;
6227 phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
=
6228 phba
->sli4_hba
.conf_regs_memmap_p
+
6229 LPFC_CTL_PORT_STA_OFFSET
;
6230 phba
->sli4_hba
.SLIINTFregaddr
=
6231 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_SLI_INTF
;
6232 phba
->sli4_hba
.PSMPHRregaddr
=
6233 phba
->sli4_hba
.conf_regs_memmap_p
+
6234 LPFC_CTL_PORT_SEM_OFFSET
;
6235 phba
->sli4_hba
.RQDBregaddr
=
6236 phba
->sli4_hba
.conf_regs_memmap_p
+
6237 LPFC_ULP0_RQ_DOORBELL
;
6238 phba
->sli4_hba
.WQDBregaddr
=
6239 phba
->sli4_hba
.conf_regs_memmap_p
+
6240 LPFC_ULP0_WQ_DOORBELL
;
6241 phba
->sli4_hba
.EQCQDBregaddr
=
6242 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_EQCQ_DOORBELL
;
6243 phba
->sli4_hba
.MQDBregaddr
=
6244 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_MQ_DOORBELL
;
6245 phba
->sli4_hba
.BMBXregaddr
=
6246 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_BMBX
;
6248 case LPFC_SLI_INTF_IF_TYPE_1
:
6250 dev_printk(KERN_ERR
, &phba
->pcidev
->dev
,
6251 "FATAL - unsupported SLI4 interface type - %d\n",
6258 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6259 * @phba: pointer to lpfc hba data structure.
6261 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6265 lpfc_sli4_bar1_register_memmap(struct lpfc_hba
*phba
)
6267 phba
->sli4_hba
.PSMPHRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
6268 LPFC_SLIPORT_IF0_SMPHR
;
6269 phba
->sli4_hba
.ISRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
6271 phba
->sli4_hba
.IMRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
6273 phba
->sli4_hba
.ISCRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
6278 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6279 * @phba: pointer to lpfc hba data structure.
6280 * @vf: virtual function number
6282 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6283 * based on the given viftual function number, @vf.
6285 * Return 0 if successful, otherwise -ENODEV.
6288 lpfc_sli4_bar2_register_memmap(struct lpfc_hba
*phba
, uint32_t vf
)
6290 if (vf
> LPFC_VIR_FUNC_MAX
)
6293 phba
->sli4_hba
.RQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
6294 vf
* LPFC_VFR_PAGE_SIZE
+
6295 LPFC_ULP0_RQ_DOORBELL
);
6296 phba
->sli4_hba
.WQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
6297 vf
* LPFC_VFR_PAGE_SIZE
+
6298 LPFC_ULP0_WQ_DOORBELL
);
6299 phba
->sli4_hba
.EQCQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
6300 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_EQCQ_DOORBELL
);
6301 phba
->sli4_hba
.MQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
6302 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_MQ_DOORBELL
);
6303 phba
->sli4_hba
.BMBXregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
6304 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_BMBX
);
6309 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
6310 * @phba: pointer to lpfc hba data structure.
6312 * This routine is invoked to create the bootstrap mailbox
6313 * region consistent with the SLI-4 interface spec. This
6314 * routine allocates all memory necessary to communicate
6315 * mailbox commands to the port and sets up all alignment
6316 * needs. No locks are expected to be held when calling
6321 * -ENOMEM - could not allocated memory.
6324 lpfc_create_bootstrap_mbox(struct lpfc_hba
*phba
)
6327 struct lpfc_dmabuf
*dmabuf
;
6328 struct dma_address
*dma_address
;
6332 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
6337 * The bootstrap mailbox region is comprised of 2 parts
6338 * plus an alignment restriction of 16 bytes.
6340 bmbx_size
= sizeof(struct lpfc_bmbx_create
) + (LPFC_ALIGN_16_BYTE
- 1);
6341 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
6345 if (!dmabuf
->virt
) {
6349 memset(dmabuf
->virt
, 0, bmbx_size
);
6352 * Initialize the bootstrap mailbox pointers now so that the register
6353 * operations are simple later. The mailbox dma address is required
6354 * to be 16-byte aligned. Also align the virtual memory as each
6355 * maibox is copied into the bmbx mailbox region before issuing the
6356 * command to the port.
6358 phba
->sli4_hba
.bmbx
.dmabuf
= dmabuf
;
6359 phba
->sli4_hba
.bmbx
.bmbx_size
= bmbx_size
;
6361 phba
->sli4_hba
.bmbx
.avirt
= PTR_ALIGN(dmabuf
->virt
,
6362 LPFC_ALIGN_16_BYTE
);
6363 phba
->sli4_hba
.bmbx
.aphys
= ALIGN(dmabuf
->phys
,
6364 LPFC_ALIGN_16_BYTE
);
6367 * Set the high and low physical addresses now. The SLI4 alignment
6368 * requirement is 16 bytes and the mailbox is posted to the port
6369 * as two 30-bit addresses. The other data is a bit marking whether
6370 * the 30-bit address is the high or low address.
6371 * Upcast bmbx aphys to 64bits so shift instruction compiles
6372 * clean on 32 bit machines.
6374 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
6375 phys_addr
= (uint64_t)phba
->sli4_hba
.bmbx
.aphys
;
6376 pa_addr
= (uint32_t) ((phys_addr
>> 34) & 0x3fffffff);
6377 dma_address
->addr_hi
= (uint32_t) ((pa_addr
<< 2) |
6378 LPFC_BMBX_BIT1_ADDR_HI
);
6380 pa_addr
= (uint32_t) ((phba
->sli4_hba
.bmbx
.aphys
>> 4) & 0x3fffffff);
6381 dma_address
->addr_lo
= (uint32_t) ((pa_addr
<< 2) |
6382 LPFC_BMBX_BIT1_ADDR_LO
);
6387 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
6388 * @phba: pointer to lpfc hba data structure.
6390 * This routine is invoked to teardown the bootstrap mailbox
6391 * region and release all host resources. This routine requires
6392 * the caller to ensure all mailbox commands recovered, no
6393 * additional mailbox comands are sent, and interrupts are disabled
6394 * before calling this routine.
6398 lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*phba
)
6400 dma_free_coherent(&phba
->pcidev
->dev
,
6401 phba
->sli4_hba
.bmbx
.bmbx_size
,
6402 phba
->sli4_hba
.bmbx
.dmabuf
->virt
,
6403 phba
->sli4_hba
.bmbx
.dmabuf
->phys
);
6405 kfree(phba
->sli4_hba
.bmbx
.dmabuf
);
6406 memset(&phba
->sli4_hba
.bmbx
, 0, sizeof(struct lpfc_bmbx
));
6410 * lpfc_sli4_read_config - Get the config parameters.
6411 * @phba: pointer to lpfc hba data structure.
6413 * This routine is invoked to read the configuration parameters from the HBA.
6414 * The configuration parameters are used to set the base and maximum values
6415 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
6416 * allocation for the port.
6420 * -ENOMEM - No available memory
6421 * -EIO - The mailbox failed to complete successfully.
6424 lpfc_sli4_read_config(struct lpfc_hba
*phba
)
6427 struct lpfc_mbx_read_config
*rd_config
;
6428 union lpfc_sli4_cfg_shdr
*shdr
;
6429 uint32_t shdr_status
, shdr_add_status
;
6430 struct lpfc_mbx_get_func_cfg
*get_func_cfg
;
6431 struct lpfc_rsrc_desc_fcfcoe
*desc
;
6433 uint32_t desc_count
;
6434 int length
, i
, rc
= 0, rc2
;
6436 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6438 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6439 "2011 Unable to allocate memory for issuing "
6440 "SLI_CONFIG_SPECIAL mailbox command\n");
6444 lpfc_read_config(phba
, pmb
);
6446 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
6447 if (rc
!= MBX_SUCCESS
) {
6448 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6449 "2012 Mailbox failed , mbxCmd x%x "
6450 "READ_CONFIG, mbxStatus x%x\n",
6451 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
6452 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
6455 rd_config
= &pmb
->u
.mqe
.un
.rd_config
;
6456 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv
, rd_config
)) {
6457 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
6458 phba
->sli4_hba
.lnk_info
.lnk_tp
=
6459 bf_get(lpfc_mbx_rd_conf_lnk_type
, rd_config
);
6460 phba
->sli4_hba
.lnk_info
.lnk_no
=
6461 bf_get(lpfc_mbx_rd_conf_lnk_numb
, rd_config
);
6462 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
6463 "3081 lnk_type:%d, lnk_numb:%d\n",
6464 phba
->sli4_hba
.lnk_info
.lnk_tp
,
6465 phba
->sli4_hba
.lnk_info
.lnk_no
);
6467 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
6468 "3082 Mailbox (x%x) returned ldv:x0\n",
6469 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
));
6470 phba
->sli4_hba
.extents_in_use
=
6471 bf_get(lpfc_mbx_rd_conf_extnts_inuse
, rd_config
);
6472 phba
->sli4_hba
.max_cfg_param
.max_xri
=
6473 bf_get(lpfc_mbx_rd_conf_xri_count
, rd_config
);
6474 phba
->sli4_hba
.max_cfg_param
.xri_base
=
6475 bf_get(lpfc_mbx_rd_conf_xri_base
, rd_config
);
6476 phba
->sli4_hba
.max_cfg_param
.max_vpi
=
6477 bf_get(lpfc_mbx_rd_conf_vpi_count
, rd_config
);
6478 phba
->sli4_hba
.max_cfg_param
.vpi_base
=
6479 bf_get(lpfc_mbx_rd_conf_vpi_base
, rd_config
);
6480 phba
->sli4_hba
.max_cfg_param
.max_rpi
=
6481 bf_get(lpfc_mbx_rd_conf_rpi_count
, rd_config
);
6482 phba
->sli4_hba
.max_cfg_param
.rpi_base
=
6483 bf_get(lpfc_mbx_rd_conf_rpi_base
, rd_config
);
6484 phba
->sli4_hba
.max_cfg_param
.max_vfi
=
6485 bf_get(lpfc_mbx_rd_conf_vfi_count
, rd_config
);
6486 phba
->sli4_hba
.max_cfg_param
.vfi_base
=
6487 bf_get(lpfc_mbx_rd_conf_vfi_base
, rd_config
);
6488 phba
->sli4_hba
.max_cfg_param
.max_fcfi
=
6489 bf_get(lpfc_mbx_rd_conf_fcfi_count
, rd_config
);
6490 phba
->sli4_hba
.max_cfg_param
.max_eq
=
6491 bf_get(lpfc_mbx_rd_conf_eq_count
, rd_config
);
6492 phba
->sli4_hba
.max_cfg_param
.max_rq
=
6493 bf_get(lpfc_mbx_rd_conf_rq_count
, rd_config
);
6494 phba
->sli4_hba
.max_cfg_param
.max_wq
=
6495 bf_get(lpfc_mbx_rd_conf_wq_count
, rd_config
);
6496 phba
->sli4_hba
.max_cfg_param
.max_cq
=
6497 bf_get(lpfc_mbx_rd_conf_cq_count
, rd_config
);
6498 phba
->lmt
= bf_get(lpfc_mbx_rd_conf_lmt
, rd_config
);
6499 phba
->sli4_hba
.next_xri
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
6500 phba
->vpi_base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
6501 phba
->vfi_base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
6502 phba
->max_vpi
= (phba
->sli4_hba
.max_cfg_param
.max_vpi
> 0) ?
6503 (phba
->sli4_hba
.max_cfg_param
.max_vpi
- 1) : 0;
6504 phba
->max_vports
= phba
->max_vpi
;
6505 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
6506 "2003 cfg params Extents? %d "
6512 phba
->sli4_hba
.extents_in_use
,
6513 phba
->sli4_hba
.max_cfg_param
.xri_base
,
6514 phba
->sli4_hba
.max_cfg_param
.max_xri
,
6515 phba
->sli4_hba
.max_cfg_param
.vpi_base
,
6516 phba
->sli4_hba
.max_cfg_param
.max_vpi
,
6517 phba
->sli4_hba
.max_cfg_param
.vfi_base
,
6518 phba
->sli4_hba
.max_cfg_param
.max_vfi
,
6519 phba
->sli4_hba
.max_cfg_param
.rpi_base
,
6520 phba
->sli4_hba
.max_cfg_param
.max_rpi
,
6521 phba
->sli4_hba
.max_cfg_param
.max_fcfi
);
6527 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
6528 if (phba
->cfg_hba_queue_depth
>
6529 (phba
->sli4_hba
.max_cfg_param
.max_xri
-
6530 lpfc_sli4_get_els_iocb_cnt(phba
)))
6531 phba
->cfg_hba_queue_depth
=
6532 phba
->sli4_hba
.max_cfg_param
.max_xri
-
6533 lpfc_sli4_get_els_iocb_cnt(phba
);
6535 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
6536 LPFC_SLI_INTF_IF_TYPE_2
)
6539 /* get the pf# and vf# for SLI4 if_type 2 port */
6540 length
= (sizeof(struct lpfc_mbx_get_func_cfg
) -
6541 sizeof(struct lpfc_sli4_cfg_mhdr
));
6542 lpfc_sli4_config(phba
, pmb
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6543 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG
,
6544 length
, LPFC_SLI4_MBX_EMBED
);
6546 rc2
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
6547 shdr
= (union lpfc_sli4_cfg_shdr
*)
6548 &pmb
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
6549 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
6550 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
6551 if (rc2
|| shdr_status
|| shdr_add_status
) {
6552 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6553 "3026 Mailbox failed , mbxCmd x%x "
6554 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
6555 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
6556 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
6560 /* search for fc_fcoe resrouce descriptor */
6561 get_func_cfg
= &pmb
->u
.mqe
.un
.get_func_cfg
;
6562 desc_count
= get_func_cfg
->func_cfg
.rsrc_desc_count
;
6564 pdesc_0
= (char *)&get_func_cfg
->func_cfg
.desc
[0];
6565 desc
= (struct lpfc_rsrc_desc_fcfcoe
*)pdesc_0
;
6566 length
= bf_get(lpfc_rsrc_desc_fcfcoe_length
, desc
);
6567 if (length
== LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD
)
6568 length
= LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH
;
6569 else if (length
!= LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH
)
6572 for (i
= 0; i
< LPFC_RSRC_DESC_MAX_NUM
; i
++) {
6573 desc
= (struct lpfc_rsrc_desc_fcfcoe
*)(pdesc_0
+ length
* i
);
6574 if (LPFC_RSRC_DESC_TYPE_FCFCOE
==
6575 bf_get(lpfc_rsrc_desc_fcfcoe_type
, desc
)) {
6576 phba
->sli4_hba
.iov
.pf_number
=
6577 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum
, desc
);
6578 phba
->sli4_hba
.iov
.vf_number
=
6579 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum
, desc
);
6584 if (i
< LPFC_RSRC_DESC_MAX_NUM
)
6585 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
6586 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
6587 "vf_number:%d\n", phba
->sli4_hba
.iov
.pf_number
,
6588 phba
->sli4_hba
.iov
.vf_number
);
6590 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6591 "3028 GET_FUNCTION_CONFIG: failed to find "
6592 "Resrouce Descriptor:x%x\n",
6593 LPFC_RSRC_DESC_TYPE_FCFCOE
);
6596 mempool_free(pmb
, phba
->mbox_mem_pool
);
6601 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
6602 * @phba: pointer to lpfc hba data structure.
6604 * This routine is invoked to setup the port-side endian order when
6605 * the port if_type is 0. This routine has no function for other
6610 * -ENOMEM - No available memory
6611 * -EIO - The mailbox failed to complete successfully.
6614 lpfc_setup_endian_order(struct lpfc_hba
*phba
)
6616 LPFC_MBOXQ_t
*mboxq
;
6617 uint32_t if_type
, rc
= 0;
6618 uint32_t endian_mb_data
[2] = {HOST_ENDIAN_LOW_WORD0
,
6619 HOST_ENDIAN_HIGH_WORD1
};
6621 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
6623 case LPFC_SLI_INTF_IF_TYPE_0
:
6624 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
6627 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6628 "0492 Unable to allocate memory for "
6629 "issuing SLI_CONFIG_SPECIAL mailbox "
6635 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
6636 * two words to contain special data values and no other data.
6638 memset(mboxq
, 0, sizeof(LPFC_MBOXQ_t
));
6639 memcpy(&mboxq
->u
.mqe
, &endian_mb_data
, sizeof(endian_mb_data
));
6640 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6641 if (rc
!= MBX_SUCCESS
) {
6642 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6643 "0493 SLI_CONFIG_SPECIAL mailbox "
6644 "failed with status x%x\n",
6648 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6650 case LPFC_SLI_INTF_IF_TYPE_2
:
6651 case LPFC_SLI_INTF_IF_TYPE_1
:
6659 * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
6660 * @phba: pointer to lpfc hba data structure.
6662 * This routine is invoked to check the user settable queue counts for EQs and
6663 * CQs. after this routine is called the counts will be set to valid values that
6664 * adhere to the constraints of the system's interrupt vectors and the port's
6669 * -ENOMEM - No available memory
6672 lpfc_sli4_queue_verify(struct lpfc_hba
*phba
)
6674 int cfg_fcp_io_channel
;
6680 * Sanity check for configured queue parameters against the run-time
6684 /* Sanity check on HBA EQ parameters */
6685 cfg_fcp_io_channel
= phba
->cfg_fcp_io_channel
;
6687 /* It doesn't make sense to have more io channels then CPUs */
6688 for_each_online_cpu(cpu
) {
6691 if (i
< cfg_fcp_io_channel
) {
6692 lpfc_printf_log(phba
,
6694 "3188 Reducing IO channels to match number of "
6695 "CPUs: from %d to %d\n", cfg_fcp_io_channel
, i
);
6696 cfg_fcp_io_channel
= i
;
6699 if (cfg_fcp_io_channel
>
6700 phba
->sli4_hba
.max_cfg_param
.max_eq
) {
6701 if (phba
->sli4_hba
.max_cfg_param
.max_eq
<
6702 LPFC_FCP_IO_CHAN_MIN
) {
6703 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6704 "2574 Not enough EQs (%d) from the "
6705 "pci function for supporting FCP "
6707 phba
->sli4_hba
.max_cfg_param
.max_eq
,
6708 phba
->cfg_fcp_io_channel
);
6711 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6712 "2575 Reducing IO channels to match number of "
6713 "available EQs: from %d to %d\n",
6715 phba
->sli4_hba
.max_cfg_param
.max_eq
);
6716 cfg_fcp_io_channel
= phba
->sli4_hba
.max_cfg_param
.max_eq
;
6719 /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */
6721 /* The actual number of FCP event queues adopted */
6722 phba
->cfg_fcp_eq_count
= cfg_fcp_io_channel
;
6723 phba
->cfg_fcp_wq_count
= cfg_fcp_io_channel
;
6724 phba
->cfg_fcp_io_channel
= cfg_fcp_io_channel
;
6726 /* Get EQ depth from module parameter, fake the default for now */
6727 phba
->sli4_hba
.eq_esize
= LPFC_EQE_SIZE_4B
;
6728 phba
->sli4_hba
.eq_ecount
= LPFC_EQE_DEF_COUNT
;
6730 /* Get CQ depth from module parameter, fake the default for now */
6731 phba
->sli4_hba
.cq_esize
= LPFC_CQE_SIZE
;
6732 phba
->sli4_hba
.cq_ecount
= LPFC_CQE_DEF_COUNT
;
6740 * lpfc_sli4_queue_create - Create all the SLI4 queues
6741 * @phba: pointer to lpfc hba data structure.
6743 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
6744 * operation. For each SLI4 queue type, the parameters such as queue entry
6745 * count (queue depth) shall be taken from the module parameter. For now,
6746 * we just use some constant number as place holder.
6750 * -ENOMEM - No availble memory
6751 * -EIO - The mailbox failed to complete successfully.
6754 lpfc_sli4_queue_create(struct lpfc_hba
*phba
)
6756 struct lpfc_queue
*qdesc
;
6760 * Create HBA Record arrays.
6762 if (!phba
->cfg_fcp_io_channel
)
6765 phba
->sli4_hba
.mq_esize
= LPFC_MQE_SIZE
;
6766 phba
->sli4_hba
.mq_ecount
= LPFC_MQE_DEF_COUNT
;
6767 phba
->sli4_hba
.wq_esize
= LPFC_WQE_SIZE
;
6768 phba
->sli4_hba
.wq_ecount
= LPFC_WQE_DEF_COUNT
;
6769 phba
->sli4_hba
.rq_esize
= LPFC_RQE_SIZE
;
6770 phba
->sli4_hba
.rq_ecount
= LPFC_RQE_DEF_COUNT
;
6772 phba
->sli4_hba
.hba_eq
= kzalloc((sizeof(struct lpfc_queue
*) *
6773 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
6774 if (!phba
->sli4_hba
.hba_eq
) {
6775 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6776 "2576 Failed allocate memory for "
6777 "fast-path EQ record array\n");
6781 phba
->sli4_hba
.fcp_cq
= kzalloc((sizeof(struct lpfc_queue
*) *
6782 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
6783 if (!phba
->sli4_hba
.fcp_cq
) {
6784 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6785 "2577 Failed allocate memory for fast-path "
6786 "CQ record array\n");
6790 phba
->sli4_hba
.fcp_wq
= kzalloc((sizeof(struct lpfc_queue
*) *
6791 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
6792 if (!phba
->sli4_hba
.fcp_wq
) {
6793 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6794 "2578 Failed allocate memory for fast-path "
6795 "WQ record array\n");
6800 * Since the first EQ can have multiple CQs associated with it,
6801 * this array is used to quickly see if we have a FCP fast-path
6804 phba
->sli4_hba
.fcp_cq_map
= kzalloc((sizeof(uint16_t) *
6805 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
6806 if (!phba
->sli4_hba
.fcp_cq_map
) {
6807 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6808 "2545 Failed allocate memory for fast-path "
6814 * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
6815 * how many EQs to create.
6817 for (idx
= 0; idx
< phba
->cfg_fcp_io_channel
; idx
++) {
6820 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.eq_esize
,
6821 phba
->sli4_hba
.eq_ecount
);
6823 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6824 "0497 Failed allocate EQ (%d)\n", idx
);
6827 phba
->sli4_hba
.hba_eq
[idx
] = qdesc
;
6829 /* Create Fast Path FCP CQs */
6830 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
6831 phba
->sli4_hba
.cq_ecount
);
6833 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6834 "0499 Failed allocate fast-path FCP "
6838 phba
->sli4_hba
.fcp_cq
[idx
] = qdesc
;
6840 /* Create Fast Path FCP WQs */
6841 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
6842 phba
->sli4_hba
.wq_ecount
);
6844 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6845 "0503 Failed allocate fast-path FCP "
6849 phba
->sli4_hba
.fcp_wq
[idx
] = qdesc
;
6854 * Create Slow Path Completion Queues (CQs)
6857 /* Create slow-path Mailbox Command Complete Queue */
6858 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
6859 phba
->sli4_hba
.cq_ecount
);
6861 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6862 "0500 Failed allocate slow-path mailbox CQ\n");
6865 phba
->sli4_hba
.mbx_cq
= qdesc
;
6867 /* Create slow-path ELS Complete Queue */
6868 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
6869 phba
->sli4_hba
.cq_ecount
);
6871 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6872 "0501 Failed allocate slow-path ELS CQ\n");
6875 phba
->sli4_hba
.els_cq
= qdesc
;
6879 * Create Slow Path Work Queues (WQs)
6882 /* Create Mailbox Command Queue */
6884 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.mq_esize
,
6885 phba
->sli4_hba
.mq_ecount
);
6887 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6888 "0505 Failed allocate slow-path MQ\n");
6891 phba
->sli4_hba
.mbx_wq
= qdesc
;
6894 * Create ELS Work Queues
6897 /* Create slow-path ELS Work Queue */
6898 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
6899 phba
->sli4_hba
.wq_ecount
);
6901 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6902 "0504 Failed allocate slow-path ELS WQ\n");
6905 phba
->sli4_hba
.els_wq
= qdesc
;
6908 * Create Receive Queue (RQ)
6911 /* Create Receive Queue for header */
6912 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
6913 phba
->sli4_hba
.rq_ecount
);
6915 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6916 "0506 Failed allocate receive HRQ\n");
6919 phba
->sli4_hba
.hdr_rq
= qdesc
;
6921 /* Create Receive Queue for data */
6922 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
6923 phba
->sli4_hba
.rq_ecount
);
6925 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6926 "0507 Failed allocate receive DRQ\n");
6929 phba
->sli4_hba
.dat_rq
= qdesc
;
6934 lpfc_sli4_queue_destroy(phba
);
6939 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
6940 * @phba: pointer to lpfc hba data structure.
6942 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
6947 * -ENOMEM - No available memory
6948 * -EIO - The mailbox failed to complete successfully.
6951 lpfc_sli4_queue_destroy(struct lpfc_hba
*phba
)
6955 if (phba
->sli4_hba
.hba_eq
!= NULL
) {
6956 /* Release HBA event queue */
6957 for (idx
= 0; idx
< phba
->cfg_fcp_io_channel
; idx
++) {
6958 if (phba
->sli4_hba
.hba_eq
[idx
] != NULL
) {
6959 lpfc_sli4_queue_free(
6960 phba
->sli4_hba
.hba_eq
[idx
]);
6961 phba
->sli4_hba
.hba_eq
[idx
] = NULL
;
6964 kfree(phba
->sli4_hba
.hba_eq
);
6965 phba
->sli4_hba
.hba_eq
= NULL
;
6968 if (phba
->sli4_hba
.fcp_cq
!= NULL
) {
6969 /* Release FCP completion queue */
6970 for (idx
= 0; idx
< phba
->cfg_fcp_io_channel
; idx
++) {
6971 if (phba
->sli4_hba
.fcp_cq
[idx
] != NULL
) {
6972 lpfc_sli4_queue_free(
6973 phba
->sli4_hba
.fcp_cq
[idx
]);
6974 phba
->sli4_hba
.fcp_cq
[idx
] = NULL
;
6977 kfree(phba
->sli4_hba
.fcp_cq
);
6978 phba
->sli4_hba
.fcp_cq
= NULL
;
6981 if (phba
->sli4_hba
.fcp_wq
!= NULL
) {
6982 /* Release FCP work queue */
6983 for (idx
= 0; idx
< phba
->cfg_fcp_io_channel
; idx
++) {
6984 if (phba
->sli4_hba
.fcp_wq
[idx
] != NULL
) {
6985 lpfc_sli4_queue_free(
6986 phba
->sli4_hba
.fcp_wq
[idx
]);
6987 phba
->sli4_hba
.fcp_wq
[idx
] = NULL
;
6990 kfree(phba
->sli4_hba
.fcp_wq
);
6991 phba
->sli4_hba
.fcp_wq
= NULL
;
6994 if (phba
->pci_bar0_memmap_p
) {
6995 iounmap(phba
->pci_bar0_memmap_p
);
6996 phba
->pci_bar0_memmap_p
= NULL
;
6998 if (phba
->pci_bar2_memmap_p
) {
6999 iounmap(phba
->pci_bar2_memmap_p
);
7000 phba
->pci_bar2_memmap_p
= NULL
;
7002 if (phba
->pci_bar4_memmap_p
) {
7003 iounmap(phba
->pci_bar4_memmap_p
);
7004 phba
->pci_bar4_memmap_p
= NULL
;
7007 /* Release FCP CQ mapping array */
7008 if (phba
->sli4_hba
.fcp_cq_map
!= NULL
) {
7009 kfree(phba
->sli4_hba
.fcp_cq_map
);
7010 phba
->sli4_hba
.fcp_cq_map
= NULL
;
7013 /* Release mailbox command work queue */
7014 if (phba
->sli4_hba
.mbx_wq
!= NULL
) {
7015 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_wq
);
7016 phba
->sli4_hba
.mbx_wq
= NULL
;
7019 /* Release ELS work queue */
7020 if (phba
->sli4_hba
.els_wq
!= NULL
) {
7021 lpfc_sli4_queue_free(phba
->sli4_hba
.els_wq
);
7022 phba
->sli4_hba
.els_wq
= NULL
;
7025 /* Release unsolicited receive queue */
7026 if (phba
->sli4_hba
.hdr_rq
!= NULL
) {
7027 lpfc_sli4_queue_free(phba
->sli4_hba
.hdr_rq
);
7028 phba
->sli4_hba
.hdr_rq
= NULL
;
7030 if (phba
->sli4_hba
.dat_rq
!= NULL
) {
7031 lpfc_sli4_queue_free(phba
->sli4_hba
.dat_rq
);
7032 phba
->sli4_hba
.dat_rq
= NULL
;
7035 /* Release ELS complete queue */
7036 if (phba
->sli4_hba
.els_cq
!= NULL
) {
7037 lpfc_sli4_queue_free(phba
->sli4_hba
.els_cq
);
7038 phba
->sli4_hba
.els_cq
= NULL
;
7041 /* Release mailbox command complete queue */
7042 if (phba
->sli4_hba
.mbx_cq
!= NULL
) {
7043 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_cq
);
7044 phba
->sli4_hba
.mbx_cq
= NULL
;
7051 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
7052 * @phba: pointer to lpfc hba data structure.
7054 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
7059 * -ENOMEM - No available memory
7060 * -EIO - The mailbox failed to complete successfully.
7063 lpfc_sli4_queue_setup(struct lpfc_hba
*phba
)
7065 struct lpfc_sli
*psli
= &phba
->sli
;
7066 struct lpfc_sli_ring
*pring
;
7068 int fcp_eqidx
, fcp_cqidx
, fcp_wqidx
;
7069 int fcp_cq_index
= 0;
7070 uint32_t shdr_status
, shdr_add_status
;
7071 union lpfc_sli4_cfg_shdr
*shdr
;
7072 LPFC_MBOXQ_t
*mboxq
;
7075 /* Check for dual-ULP support */
7076 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
7078 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7079 "3249 Unable to allocate memory for "
7080 "QUERY_FW_CFG mailbox command\n");
7083 length
= (sizeof(struct lpfc_mbx_query_fw_config
) -
7084 sizeof(struct lpfc_sli4_cfg_mhdr
));
7085 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
7086 LPFC_MBOX_OPCODE_QUERY_FW_CFG
,
7087 length
, LPFC_SLI4_MBX_EMBED
);
7089 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7091 shdr
= (union lpfc_sli4_cfg_shdr
*)
7092 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
7093 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
7094 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
7095 if (shdr_status
|| shdr_add_status
|| rc
) {
7096 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7097 "3250 QUERY_FW_CFG mailbox failed with status "
7098 "x%x add_status x%x, mbx status x%x\n",
7099 shdr_status
, shdr_add_status
, rc
);
7100 if (rc
!= MBX_TIMEOUT
)
7101 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7106 phba
->sli4_hba
.fw_func_mode
=
7107 mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.function_mode
;
7108 phba
->sli4_hba
.ulp0_mode
= mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.ulp0_mode
;
7109 phba
->sli4_hba
.ulp1_mode
= mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.ulp1_mode
;
7110 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7111 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
7112 "ulp1_mode:x%x\n", phba
->sli4_hba
.fw_func_mode
,
7113 phba
->sli4_hba
.ulp0_mode
, phba
->sli4_hba
.ulp1_mode
);
7115 if (rc
!= MBX_TIMEOUT
)
7116 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7119 * Set up HBA Event Queues (EQs)
7122 /* Set up HBA event queue */
7123 if (phba
->cfg_fcp_io_channel
&& !phba
->sli4_hba
.hba_eq
) {
7124 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7125 "3147 Fast-path EQs not allocated\n");
7129 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_io_channel
; fcp_eqidx
++) {
7130 if (!phba
->sli4_hba
.hba_eq
[fcp_eqidx
]) {
7131 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7132 "0522 Fast-path EQ (%d) not "
7133 "allocated\n", fcp_eqidx
);
7135 goto out_destroy_hba_eq
;
7137 rc
= lpfc_eq_create(phba
, phba
->sli4_hba
.hba_eq
[fcp_eqidx
],
7138 (phba
->cfg_fcp_imax
/ phba
->cfg_fcp_io_channel
));
7140 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7141 "0523 Failed setup of fast-path EQ "
7142 "(%d), rc = 0x%x\n", fcp_eqidx
, rc
);
7143 goto out_destroy_hba_eq
;
7145 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7146 "2584 HBA EQ setup: "
7147 "queue[%d]-id=%d\n", fcp_eqidx
,
7148 phba
->sli4_hba
.hba_eq
[fcp_eqidx
]->queue_id
);
7151 /* Set up fast-path FCP Response Complete Queue */
7152 if (!phba
->sli4_hba
.fcp_cq
) {
7153 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7154 "3148 Fast-path FCP CQ array not "
7157 goto out_destroy_hba_eq
;
7160 for (fcp_cqidx
= 0; fcp_cqidx
< phba
->cfg_fcp_io_channel
; fcp_cqidx
++) {
7161 if (!phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]) {
7162 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7163 "0526 Fast-path FCP CQ (%d) not "
7164 "allocated\n", fcp_cqidx
);
7166 goto out_destroy_fcp_cq
;
7168 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.fcp_cq
[fcp_cqidx
],
7169 phba
->sli4_hba
.hba_eq
[fcp_cqidx
], LPFC_WCQ
, LPFC_FCP
);
7171 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7172 "0527 Failed setup of fast-path FCP "
7173 "CQ (%d), rc = 0x%x\n", fcp_cqidx
, rc
);
7174 goto out_destroy_fcp_cq
;
7177 /* Setup fcp_cq_map for fast lookup */
7178 phba
->sli4_hba
.fcp_cq_map
[fcp_cqidx
] =
7179 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]->queue_id
;
7181 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7182 "2588 FCP CQ setup: cq[%d]-id=%d, "
7183 "parent seq[%d]-id=%d\n",
7185 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]->queue_id
,
7187 phba
->sli4_hba
.hba_eq
[fcp_cqidx
]->queue_id
);
7190 /* Set up fast-path FCP Work Queue */
7191 if (!phba
->sli4_hba
.fcp_wq
) {
7192 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7193 "3149 Fast-path FCP WQ array not "
7196 goto out_destroy_fcp_cq
;
7199 for (fcp_wqidx
= 0; fcp_wqidx
< phba
->cfg_fcp_io_channel
; fcp_wqidx
++) {
7200 if (!phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]) {
7201 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7202 "0534 Fast-path FCP WQ (%d) not "
7203 "allocated\n", fcp_wqidx
);
7205 goto out_destroy_fcp_wq
;
7207 rc
= lpfc_wq_create(phba
, phba
->sli4_hba
.fcp_wq
[fcp_wqidx
],
7208 phba
->sli4_hba
.fcp_cq
[fcp_wqidx
],
7211 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7212 "0535 Failed setup of fast-path FCP "
7213 "WQ (%d), rc = 0x%x\n", fcp_wqidx
, rc
);
7214 goto out_destroy_fcp_wq
;
7217 /* Bind this WQ to the next FCP ring */
7218 pring
= &psli
->ring
[MAX_SLI3_CONFIGURED_RINGS
+ fcp_wqidx
];
7219 pring
->sli
.sli4
.wqp
= (void *)phba
->sli4_hba
.fcp_wq
[fcp_wqidx
];
7220 phba
->sli4_hba
.fcp_cq
[fcp_wqidx
]->pring
= pring
;
7222 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7223 "2591 FCP WQ setup: wq[%d]-id=%d, "
7224 "parent cq[%d]-id=%d\n",
7226 phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]->queue_id
,
7228 phba
->sli4_hba
.fcp_cq
[fcp_wqidx
]->queue_id
);
7231 * Set up Complete Queues (CQs)
7234 /* Set up slow-path MBOX Complete Queue as the first CQ */
7235 if (!phba
->sli4_hba
.mbx_cq
) {
7236 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7237 "0528 Mailbox CQ not allocated\n");
7239 goto out_destroy_fcp_wq
;
7241 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.mbx_cq
,
7242 phba
->sli4_hba
.hba_eq
[0], LPFC_MCQ
, LPFC_MBOX
);
7244 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7245 "0529 Failed setup of slow-path mailbox CQ: "
7247 goto out_destroy_fcp_wq
;
7249 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7250 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
7251 phba
->sli4_hba
.mbx_cq
->queue_id
,
7252 phba
->sli4_hba
.hba_eq
[0]->queue_id
);
7254 /* Set up slow-path ELS Complete Queue */
7255 if (!phba
->sli4_hba
.els_cq
) {
7256 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7257 "0530 ELS CQ not allocated\n");
7259 goto out_destroy_mbx_cq
;
7261 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.els_cq
,
7262 phba
->sli4_hba
.hba_eq
[0], LPFC_WCQ
, LPFC_ELS
);
7264 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7265 "0531 Failed setup of slow-path ELS CQ: "
7267 goto out_destroy_mbx_cq
;
7269 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7270 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
7271 phba
->sli4_hba
.els_cq
->queue_id
,
7272 phba
->sli4_hba
.hba_eq
[0]->queue_id
);
7275 * Set up all the Work Queues (WQs)
7278 /* Set up Mailbox Command Queue */
7279 if (!phba
->sli4_hba
.mbx_wq
) {
7280 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7281 "0538 Slow-path MQ not allocated\n");
7283 goto out_destroy_els_cq
;
7285 rc
= lpfc_mq_create(phba
, phba
->sli4_hba
.mbx_wq
,
7286 phba
->sli4_hba
.mbx_cq
, LPFC_MBOX
);
7288 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7289 "0539 Failed setup of slow-path MQ: "
7291 goto out_destroy_els_cq
;
7293 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7294 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
7295 phba
->sli4_hba
.mbx_wq
->queue_id
,
7296 phba
->sli4_hba
.mbx_cq
->queue_id
);
7298 /* Set up slow-path ELS Work Queue */
7299 if (!phba
->sli4_hba
.els_wq
) {
7300 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7301 "0536 Slow-path ELS WQ not allocated\n");
7303 goto out_destroy_mbx_wq
;
7305 rc
= lpfc_wq_create(phba
, phba
->sli4_hba
.els_wq
,
7306 phba
->sli4_hba
.els_cq
, LPFC_ELS
);
7308 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7309 "0537 Failed setup of slow-path ELS WQ: "
7311 goto out_destroy_mbx_wq
;
7314 /* Bind this WQ to the ELS ring */
7315 pring
= &psli
->ring
[LPFC_ELS_RING
];
7316 pring
->sli
.sli4
.wqp
= (void *)phba
->sli4_hba
.els_wq
;
7317 phba
->sli4_hba
.els_cq
->pring
= pring
;
7319 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7320 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
7321 phba
->sli4_hba
.els_wq
->queue_id
,
7322 phba
->sli4_hba
.els_cq
->queue_id
);
7325 * Create Receive Queue (RQ)
7327 if (!phba
->sli4_hba
.hdr_rq
|| !phba
->sli4_hba
.dat_rq
) {
7328 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7329 "0540 Receive Queue not allocated\n");
7331 goto out_destroy_els_wq
;
7334 lpfc_rq_adjust_repost(phba
, phba
->sli4_hba
.hdr_rq
, LPFC_ELS_HBQ
);
7335 lpfc_rq_adjust_repost(phba
, phba
->sli4_hba
.dat_rq
, LPFC_ELS_HBQ
);
7337 rc
= lpfc_rq_create(phba
, phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
7338 phba
->sli4_hba
.els_cq
, LPFC_USOL
);
7340 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7341 "0541 Failed setup of Receive Queue: "
7343 goto out_destroy_fcp_wq
;
7346 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7347 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
7348 "parent cq-id=%d\n",
7349 phba
->sli4_hba
.hdr_rq
->queue_id
,
7350 phba
->sli4_hba
.dat_rq
->queue_id
,
7351 phba
->sli4_hba
.els_cq
->queue_id
);
7355 lpfc_wq_destroy(phba
, phba
->sli4_hba
.els_wq
);
7357 lpfc_mq_destroy(phba
, phba
->sli4_hba
.mbx_wq
);
7359 lpfc_cq_destroy(phba
, phba
->sli4_hba
.els_cq
);
7361 lpfc_cq_destroy(phba
, phba
->sli4_hba
.mbx_cq
);
7363 for (--fcp_wqidx
; fcp_wqidx
>= 0; fcp_wqidx
--)
7364 lpfc_wq_destroy(phba
, phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]);
7366 for (--fcp_cqidx
; fcp_cqidx
>= 0; fcp_cqidx
--)
7367 lpfc_cq_destroy(phba
, phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]);
7369 for (--fcp_eqidx
; fcp_eqidx
>= 0; fcp_eqidx
--)
7370 lpfc_eq_destroy(phba
, phba
->sli4_hba
.hba_eq
[fcp_eqidx
]);
7376 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
7377 * @phba: pointer to lpfc hba data structure.
7379 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
7384 * -ENOMEM - No available memory
7385 * -EIO - The mailbox failed to complete successfully.
7388 lpfc_sli4_queue_unset(struct lpfc_hba
*phba
)
7392 /* Unset mailbox command work queue */
7393 lpfc_mq_destroy(phba
, phba
->sli4_hba
.mbx_wq
);
7394 /* Unset ELS work queue */
7395 lpfc_wq_destroy(phba
, phba
->sli4_hba
.els_wq
);
7396 /* Unset unsolicited receive queue */
7397 lpfc_rq_destroy(phba
, phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
);
7398 /* Unset FCP work queue */
7399 if (phba
->sli4_hba
.fcp_wq
) {
7400 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_io_channel
;
7402 lpfc_wq_destroy(phba
, phba
->sli4_hba
.fcp_wq
[fcp_qidx
]);
7404 /* Unset mailbox command complete queue */
7405 lpfc_cq_destroy(phba
, phba
->sli4_hba
.mbx_cq
);
7406 /* Unset ELS complete queue */
7407 lpfc_cq_destroy(phba
, phba
->sli4_hba
.els_cq
);
7408 /* Unset FCP response complete queue */
7409 if (phba
->sli4_hba
.fcp_cq
) {
7410 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_io_channel
;
7412 lpfc_cq_destroy(phba
, phba
->sli4_hba
.fcp_cq
[fcp_qidx
]);
7414 /* Unset fast-path event queue */
7415 if (phba
->sli4_hba
.hba_eq
) {
7416 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_io_channel
;
7418 lpfc_eq_destroy(phba
, phba
->sli4_hba
.hba_eq
[fcp_qidx
]);
7423 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
7424 * @phba: pointer to lpfc hba data structure.
7426 * This routine is invoked to allocate and set up a pool of completion queue
7427 * events. The body of the completion queue event is a completion queue entry
7428 * CQE. For now, this pool is used for the interrupt service routine to queue
7429 * the following HBA completion queue events for the worker thread to process:
7430 * - Mailbox asynchronous events
7431 * - Receive queue completion unsolicited events
7432 * Later, this can be used for all the slow-path events.
7436 * -ENOMEM - No available memory
7439 lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*phba
)
7441 struct lpfc_cq_event
*cq_event
;
7444 for (i
= 0; i
< (4 * phba
->sli4_hba
.cq_ecount
); i
++) {
7445 cq_event
= kmalloc(sizeof(struct lpfc_cq_event
), GFP_KERNEL
);
7447 goto out_pool_create_fail
;
7448 list_add_tail(&cq_event
->list
,
7449 &phba
->sli4_hba
.sp_cqe_event_pool
);
7453 out_pool_create_fail
:
7454 lpfc_sli4_cq_event_pool_destroy(phba
);
7459 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
7460 * @phba: pointer to lpfc hba data structure.
7462 * This routine is invoked to free the pool of completion queue events at
7463 * driver unload time. Note that, it is the responsibility of the driver
7464 * cleanup routine to free all the outstanding completion-queue events
7465 * allocated from this pool back into the pool before invoking this routine
7466 * to destroy the pool.
7469 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*phba
)
7471 struct lpfc_cq_event
*cq_event
, *next_cq_event
;
7473 list_for_each_entry_safe(cq_event
, next_cq_event
,
7474 &phba
->sli4_hba
.sp_cqe_event_pool
, list
) {
7475 list_del(&cq_event
->list
);
7481 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7482 * @phba: pointer to lpfc hba data structure.
7484 * This routine is the lock free version of the API invoked to allocate a
7485 * completion-queue event from the free pool.
7487 * Return: Pointer to the newly allocated completion-queue event if successful
7490 struct lpfc_cq_event
*
7491 __lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
7493 struct lpfc_cq_event
*cq_event
= NULL
;
7495 list_remove_head(&phba
->sli4_hba
.sp_cqe_event_pool
, cq_event
,
7496 struct lpfc_cq_event
, list
);
7501 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7502 * @phba: pointer to lpfc hba data structure.
7504 * This routine is the lock version of the API invoked to allocate a
7505 * completion-queue event from the free pool.
7507 * Return: Pointer to the newly allocated completion-queue event if successful
7510 struct lpfc_cq_event
*
7511 lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
7513 struct lpfc_cq_event
*cq_event
;
7514 unsigned long iflags
;
7516 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7517 cq_event
= __lpfc_sli4_cq_event_alloc(phba
);
7518 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7523 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7524 * @phba: pointer to lpfc hba data structure.
7525 * @cq_event: pointer to the completion queue event to be freed.
7527 * This routine is the lock free version of the API invoked to release a
7528 * completion-queue event back into the free pool.
7531 __lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
7532 struct lpfc_cq_event
*cq_event
)
7534 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_cqe_event_pool
);
7538 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7539 * @phba: pointer to lpfc hba data structure.
7540 * @cq_event: pointer to the completion queue event to be freed.
7542 * This routine is the lock version of the API invoked to release a
7543 * completion-queue event back into the free pool.
7546 lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
7547 struct lpfc_cq_event
*cq_event
)
7549 unsigned long iflags
;
7550 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7551 __lpfc_sli4_cq_event_release(phba
, cq_event
);
7552 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7556 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
7557 * @phba: pointer to lpfc hba data structure.
7559 * This routine is to free all the pending completion-queue events to the
7560 * back into the free pool for device reset.
7563 lpfc_sli4_cq_event_release_all(struct lpfc_hba
*phba
)
7566 struct lpfc_cq_event
*cqe
;
7567 unsigned long iflags
;
7569 /* Retrieve all the pending WCQEs from pending WCQE lists */
7570 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7571 /* Pending FCP XRI abort events */
7572 list_splice_init(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
7574 /* Pending ELS XRI abort events */
7575 list_splice_init(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
7577 /* Pending asynnc events */
7578 list_splice_init(&phba
->sli4_hba
.sp_asynce_work_queue
,
7580 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7582 while (!list_empty(&cqelist
)) {
7583 list_remove_head(&cqelist
, cqe
, struct lpfc_cq_event
, list
);
7584 lpfc_sli4_cq_event_release(phba
, cqe
);
7589 * lpfc_pci_function_reset - Reset pci function.
7590 * @phba: pointer to lpfc hba data structure.
7592 * This routine is invoked to request a PCI function reset. It will destroys
7593 * all resources assigned to the PCI function which originates this request.
7597 * -ENOMEM - No available memory
7598 * -EIO - The mailbox failed to complete successfully.
7601 lpfc_pci_function_reset(struct lpfc_hba
*phba
)
7603 LPFC_MBOXQ_t
*mboxq
;
7604 uint32_t rc
= 0, if_type
;
7605 uint32_t shdr_status
, shdr_add_status
;
7606 uint32_t rdy_chk
, num_resets
= 0, reset_again
= 0;
7607 union lpfc_sli4_cfg_shdr
*shdr
;
7608 struct lpfc_register reg_data
;
7611 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
7613 case LPFC_SLI_INTF_IF_TYPE_0
:
7614 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
7617 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7618 "0494 Unable to allocate memory for "
7619 "issuing SLI_FUNCTION_RESET mailbox "
7624 /* Setup PCI function reset mailbox-ioctl command */
7625 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
7626 LPFC_MBOX_OPCODE_FUNCTION_RESET
, 0,
7627 LPFC_SLI4_MBX_EMBED
);
7628 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7629 shdr
= (union lpfc_sli4_cfg_shdr
*)
7630 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
7631 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
7632 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
7634 if (rc
!= MBX_TIMEOUT
)
7635 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7636 if (shdr_status
|| shdr_add_status
|| rc
) {
7637 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7638 "0495 SLI_FUNCTION_RESET mailbox "
7639 "failed with status x%x add_status x%x,"
7640 " mbx status x%x\n",
7641 shdr_status
, shdr_add_status
, rc
);
7645 case LPFC_SLI_INTF_IF_TYPE_2
:
7646 for (num_resets
= 0;
7647 num_resets
< MAX_IF_TYPE_2_RESETS
;
7650 bf_set(lpfc_sliport_ctrl_end
, ®_data
,
7651 LPFC_SLIPORT_LITTLE_ENDIAN
);
7652 bf_set(lpfc_sliport_ctrl_ip
, ®_data
,
7653 LPFC_SLIPORT_INIT_PORT
);
7654 writel(reg_data
.word0
, phba
->sli4_hba
.u
.if_type2
.
7657 pci_read_config_word(phba
->pcidev
,
7658 PCI_DEVICE_ID
, &devid
);
7660 * Poll the Port Status Register and wait for RDY for
7661 * up to 10 seconds. If the port doesn't respond, treat
7662 * it as an error. If the port responds with RN, start
7665 for (rdy_chk
= 0; rdy_chk
< 1000; rdy_chk
++) {
7667 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.
7668 STATUSregaddr
, ®_data
.word0
)) {
7672 if (bf_get(lpfc_sliport_status_rn
, ®_data
))
7674 if (bf_get(lpfc_sliport_status_rdy
, ®_data
))
7679 * If the port responds to the init request with
7680 * reset needed, delay for a bit and restart the loop.
7682 if (reset_again
&& (rdy_chk
< 1000)) {
7688 /* Detect any port errors. */
7689 if ((bf_get(lpfc_sliport_status_err
, ®_data
)) ||
7690 (rdy_chk
>= 1000)) {
7691 phba
->work_status
[0] = readl(
7692 phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
7693 phba
->work_status
[1] = readl(
7694 phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
7695 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7696 "2890 Port error detected during port "
7697 "reset(%d): wait_tmo:%d ms, "
7698 "port status reg 0x%x, "
7699 "error 1=0x%x, error 2=0x%x\n",
7700 num_resets
, rdy_chk
*10,
7702 phba
->work_status
[0],
7703 phba
->work_status
[1]);
7708 * Terminate the outer loop provided the Port indicated
7709 * ready within 10 seconds.
7714 /* delay driver action following IF_TYPE_2 function reset */
7717 case LPFC_SLI_INTF_IF_TYPE_1
:
7723 /* Catch the not-ready port failure after a port reset. */
7724 if (num_resets
>= MAX_IF_TYPE_2_RESETS
)
7731 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
7732 * @phba: pointer to lpfc hba data structure.
7734 * This routine is invoked to set up the PCI device memory space for device
7735 * with SLI-4 interface spec.
7739 * other values - error
7742 lpfc_sli4_pci_mem_setup(struct lpfc_hba
*phba
)
7744 struct pci_dev
*pdev
;
7745 unsigned long bar0map_len
, bar1map_len
, bar2map_len
;
7746 int error
= -ENODEV
;
7749 /* Obtain PCI device reference */
7753 pdev
= phba
->pcidev
;
7755 /* Set the device DMA mask size */
7756 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
7757 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
7758 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
7759 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
7765 * The BARs and register set definitions and offset locations are
7766 * dependent on the if_type.
7768 if (pci_read_config_dword(pdev
, LPFC_SLI_INTF
,
7769 &phba
->sli4_hba
.sli_intf
.word0
)) {
7773 /* There is no SLI3 failback for SLI4 devices. */
7774 if (bf_get(lpfc_sli_intf_valid
, &phba
->sli4_hba
.sli_intf
) !=
7775 LPFC_SLI_INTF_VALID
) {
7776 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7777 "2894 SLI_INTF reg contents invalid "
7778 "sli_intf reg 0x%x\n",
7779 phba
->sli4_hba
.sli_intf
.word0
);
7783 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
7785 * Get the bus address of SLI4 device Bar regions and the
7786 * number of bytes required by each mapping. The mapping of the
7787 * particular PCI BARs regions is dependent on the type of
7790 if (pci_resource_start(pdev
, 0)) {
7791 phba
->pci_bar0_map
= pci_resource_start(pdev
, 0);
7792 bar0map_len
= pci_resource_len(pdev
, 0);
7795 * Map SLI4 PCI Config Space Register base to a kernel virtual
7798 phba
->sli4_hba
.conf_regs_memmap_p
=
7799 ioremap(phba
->pci_bar0_map
, bar0map_len
);
7800 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
7801 dev_printk(KERN_ERR
, &pdev
->dev
,
7802 "ioremap failed for SLI4 PCI config "
7806 /* Set up BAR0 PCI config space register memory map */
7807 lpfc_sli4_bar0_register_memmap(phba
, if_type
);
7809 phba
->pci_bar0_map
= pci_resource_start(pdev
, 1);
7810 bar0map_len
= pci_resource_len(pdev
, 1);
7811 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
7812 dev_printk(KERN_ERR
, &pdev
->dev
,
7813 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
7816 phba
->sli4_hba
.conf_regs_memmap_p
=
7817 ioremap(phba
->pci_bar0_map
, bar0map_len
);
7818 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
7819 dev_printk(KERN_ERR
, &pdev
->dev
,
7820 "ioremap failed for SLI4 PCI config "
7824 lpfc_sli4_bar0_register_memmap(phba
, if_type
);
7827 if ((if_type
== LPFC_SLI_INTF_IF_TYPE_0
) &&
7828 (pci_resource_start(pdev
, 2))) {
7830 * Map SLI4 if type 0 HBA Control Register base to a kernel
7831 * virtual address and setup the registers.
7833 phba
->pci_bar1_map
= pci_resource_start(pdev
, 2);
7834 bar1map_len
= pci_resource_len(pdev
, 2);
7835 phba
->sli4_hba
.ctrl_regs_memmap_p
=
7836 ioremap(phba
->pci_bar1_map
, bar1map_len
);
7837 if (!phba
->sli4_hba
.ctrl_regs_memmap_p
) {
7838 dev_printk(KERN_ERR
, &pdev
->dev
,
7839 "ioremap failed for SLI4 HBA control registers.\n");
7840 goto out_iounmap_conf
;
7842 lpfc_sli4_bar1_register_memmap(phba
);
7845 if ((if_type
== LPFC_SLI_INTF_IF_TYPE_0
) &&
7846 (pci_resource_start(pdev
, 4))) {
7848 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
7849 * virtual address and setup the registers.
7851 phba
->pci_bar2_map
= pci_resource_start(pdev
, 4);
7852 bar2map_len
= pci_resource_len(pdev
, 4);
7853 phba
->sli4_hba
.drbl_regs_memmap_p
=
7854 ioremap(phba
->pci_bar2_map
, bar2map_len
);
7855 if (!phba
->sli4_hba
.drbl_regs_memmap_p
) {
7856 dev_printk(KERN_ERR
, &pdev
->dev
,
7857 "ioremap failed for SLI4 HBA doorbell registers.\n");
7858 goto out_iounmap_ctrl
;
7860 error
= lpfc_sli4_bar2_register_memmap(phba
, LPFC_VF0
);
7862 goto out_iounmap_all
;
7868 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
7870 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
7872 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
7878 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
7879 * @phba: pointer to lpfc hba data structure.
7881 * This routine is invoked to unset the PCI device memory space for device
7882 * with SLI-4 interface spec.
7885 lpfc_sli4_pci_mem_unset(struct lpfc_hba
*phba
)
7888 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
7891 case LPFC_SLI_INTF_IF_TYPE_0
:
7892 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
7893 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
7894 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
7896 case LPFC_SLI_INTF_IF_TYPE_2
:
7897 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
7899 case LPFC_SLI_INTF_IF_TYPE_1
:
7901 dev_printk(KERN_ERR
, &phba
->pcidev
->dev
,
7902 "FATAL - unsupported SLI4 interface type - %d\n",
7909 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
7910 * @phba: pointer to lpfc hba data structure.
7912 * This routine is invoked to enable the MSI-X interrupt vectors to device
7913 * with SLI-3 interface specs. The kernel function pci_enable_msix() is
7914 * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
7915 * invoked, enables either all or nothing, depending on the current
7916 * availability of PCI vector resources. The device driver is responsible
7917 * for calling the individual request_irq() to register each MSI-X vector
7918 * with a interrupt handler, which is done in this function. Note that
7919 * later when device is unloading, the driver should always call free_irq()
7920 * on all MSI-X vectors it has done request_irq() on before calling
7921 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
7922 * will be left with MSI-X enabled and leaks its vectors.
7926 * other values - error
7929 lpfc_sli_enable_msix(struct lpfc_hba
*phba
)
7934 /* Set up MSI-X multi-message vectors */
7935 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
7936 phba
->msix_entries
[i
].entry
= i
;
7938 /* Configure MSI-X capability structure */
7939 rc
= pci_enable_msix(phba
->pcidev
, phba
->msix_entries
,
7940 ARRAY_SIZE(phba
->msix_entries
));
7942 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7943 "0420 PCI enable MSI-X failed (%d)\n", rc
);
7946 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
7947 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7948 "0477 MSI-X entry[%d]: vector=x%x "
7950 phba
->msix_entries
[i
].vector
,
7951 phba
->msix_entries
[i
].entry
);
7953 * Assign MSI-X vectors to interrupt handlers
7956 /* vector-0 is associated to slow-path handler */
7957 rc
= request_irq(phba
->msix_entries
[0].vector
,
7958 &lpfc_sli_sp_intr_handler
, IRQF_SHARED
,
7959 LPFC_SP_DRIVER_HANDLER_NAME
, phba
);
7961 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7962 "0421 MSI-X slow-path request_irq failed "
7967 /* vector-1 is associated to fast-path handler */
7968 rc
= request_irq(phba
->msix_entries
[1].vector
,
7969 &lpfc_sli_fp_intr_handler
, IRQF_SHARED
,
7970 LPFC_FP_DRIVER_HANDLER_NAME
, phba
);
7973 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
7974 "0429 MSI-X fast-path request_irq failed "
7980 * Configure HBA MSI-X attention conditions to messages
7982 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
7986 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7987 "0474 Unable to allocate memory for issuing "
7988 "MBOX_CONFIG_MSI command\n");
7991 rc
= lpfc_config_msi(phba
, pmb
);
7994 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
7995 if (rc
!= MBX_SUCCESS
) {
7996 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
7997 "0351 Config MSI mailbox command failed, "
7998 "mbxCmd x%x, mbxStatus x%x\n",
7999 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
);
8003 /* Free memory allocated for mailbox command */
8004 mempool_free(pmb
, phba
->mbox_mem_pool
);
8008 /* Free memory allocated for mailbox command */
8009 mempool_free(pmb
, phba
->mbox_mem_pool
);
8012 /* free the irq already requested */
8013 free_irq(phba
->msix_entries
[1].vector
, phba
);
8016 /* free the irq already requested */
8017 free_irq(phba
->msix_entries
[0].vector
, phba
);
8020 /* Unconfigure MSI-X capability structure */
8021 pci_disable_msix(phba
->pcidev
);
8026 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
8027 * @phba: pointer to lpfc hba data structure.
8029 * This routine is invoked to release the MSI-X vectors and then disable the
8030 * MSI-X interrupt mode to device with SLI-3 interface spec.
8033 lpfc_sli_disable_msix(struct lpfc_hba
*phba
)
8037 /* Free up MSI-X multi-message vectors */
8038 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
8039 free_irq(phba
->msix_entries
[i
].vector
, phba
);
8041 pci_disable_msix(phba
->pcidev
);
8047 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
8048 * @phba: pointer to lpfc hba data structure.
8050 * This routine is invoked to enable the MSI interrupt mode to device with
8051 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
8052 * enable the MSI vector. The device driver is responsible for calling the
8053 * request_irq() to register MSI vector with a interrupt the handler, which
8054 * is done in this function.
8058 * other values - error
8061 lpfc_sli_enable_msi(struct lpfc_hba
*phba
)
8065 rc
= pci_enable_msi(phba
->pcidev
);
8067 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8068 "0462 PCI enable MSI mode success.\n");
8070 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8071 "0471 PCI enable MSI mode failed (%d)\n", rc
);
8075 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
8076 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
8078 pci_disable_msi(phba
->pcidev
);
8079 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
8080 "0478 MSI request_irq failed (%d)\n", rc
);
8086 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
8087 * @phba: pointer to lpfc hba data structure.
8089 * This routine is invoked to disable the MSI interrupt mode to device with
8090 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
8091 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8092 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8096 lpfc_sli_disable_msi(struct lpfc_hba
*phba
)
8098 free_irq(phba
->pcidev
->irq
, phba
);
8099 pci_disable_msi(phba
->pcidev
);
8104 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
8105 * @phba: pointer to lpfc hba data structure.
8107 * This routine is invoked to enable device interrupt and associate driver's
8108 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
8109 * spec. Depends on the interrupt mode configured to the driver, the driver
8110 * will try to fallback from the configured interrupt mode to an interrupt
8111 * mode which is supported by the platform, kernel, and device in the order
8113 * MSI-X -> MSI -> IRQ.
8117 * other values - error
8120 lpfc_sli_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
8122 uint32_t intr_mode
= LPFC_INTR_ERROR
;
8125 if (cfg_mode
== 2) {
8126 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
8127 retval
= lpfc_sli_config_port(phba
, LPFC_SLI_REV3
);
8129 /* Now, try to enable MSI-X interrupt mode */
8130 retval
= lpfc_sli_enable_msix(phba
);
8132 /* Indicate initialization to MSI-X mode */
8133 phba
->intr_type
= MSIX
;
8139 /* Fallback to MSI if MSI-X initialization failed */
8140 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
8141 retval
= lpfc_sli_enable_msi(phba
);
8143 /* Indicate initialization to MSI mode */
8144 phba
->intr_type
= MSI
;
8149 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8150 if (phba
->intr_type
== NONE
) {
8151 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
8152 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
8154 /* Indicate initialization to INTx mode */
8155 phba
->intr_type
= INTx
;
8163 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
8164 * @phba: pointer to lpfc hba data structure.
8166 * This routine is invoked to disable device interrupt and disassociate the
8167 * driver's interrupt handler(s) from interrupt vector(s) to device with
8168 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
8169 * release the interrupt vector(s) for the message signaled interrupt.
8172 lpfc_sli_disable_intr(struct lpfc_hba
*phba
)
8174 /* Disable the currently initialized interrupt mode */
8175 if (phba
->intr_type
== MSIX
)
8176 lpfc_sli_disable_msix(phba
);
8177 else if (phba
->intr_type
== MSI
)
8178 lpfc_sli_disable_msi(phba
);
8179 else if (phba
->intr_type
== INTx
)
8180 free_irq(phba
->pcidev
->irq
, phba
);
8182 /* Reset interrupt management states */
8183 phba
->intr_type
= NONE
;
8184 phba
->sli
.slistat
.sli_intr
= 0;
8190 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
8191 * @phba: pointer to lpfc hba data structure.
8193 * This routine is invoked to enable the MSI-X interrupt vectors to device
8194 * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
8195 * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
8196 * enables either all or nothing, depending on the current availability of
8197 * PCI vector resources. The device driver is responsible for calling the
8198 * individual request_irq() to register each MSI-X vector with a interrupt
8199 * handler, which is done in this function. Note that later when device is
8200 * unloading, the driver should always call free_irq() on all MSI-X vectors
8201 * it has done request_irq() on before calling pci_disable_msix(). Failure
8202 * to do so results in a BUG_ON() and a device will be left with MSI-X
8203 * enabled and leaks its vectors.
8207 * other values - error
8210 lpfc_sli4_enable_msix(struct lpfc_hba
*phba
)
8212 int vectors
, rc
, index
;
8214 /* Set up MSI-X multi-message vectors */
8215 for (index
= 0; index
< phba
->cfg_fcp_io_channel
; index
++)
8216 phba
->sli4_hba
.msix_entries
[index
].entry
= index
;
8218 /* Configure MSI-X capability structure */
8219 vectors
= phba
->cfg_fcp_io_channel
;
8220 enable_msix_vectors
:
8221 rc
= pci_enable_msix(phba
->pcidev
, phba
->sli4_hba
.msix_entries
,
8225 goto enable_msix_vectors
;
8227 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8228 "0484 PCI enable MSI-X failed (%d)\n", rc
);
8232 /* Log MSI-X vector assignment */
8233 for (index
= 0; index
< vectors
; index
++)
8234 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8235 "0489 MSI-X entry[%d]: vector=x%x "
8236 "message=%d\n", index
,
8237 phba
->sli4_hba
.msix_entries
[index
].vector
,
8238 phba
->sli4_hba
.msix_entries
[index
].entry
);
8241 * Assign MSI-X vectors to interrupt handlers
8243 for (index
= 0; index
< vectors
; index
++) {
8244 memset(&phba
->sli4_hba
.handler_name
[index
], 0, 16);
8245 sprintf((char *)&phba
->sli4_hba
.handler_name
[index
],
8246 LPFC_DRIVER_HANDLER_NAME
"%d", index
);
8248 phba
->sli4_hba
.fcp_eq_hdl
[index
].idx
= index
;
8249 phba
->sli4_hba
.fcp_eq_hdl
[index
].phba
= phba
;
8250 atomic_set(&phba
->sli4_hba
.fcp_eq_hdl
[index
].fcp_eq_in_use
, 1);
8251 rc
= request_irq(phba
->sli4_hba
.msix_entries
[index
].vector
,
8252 &lpfc_sli4_hba_intr_handler
, IRQF_SHARED
,
8253 (char *)&phba
->sli4_hba
.handler_name
[index
],
8254 &phba
->sli4_hba
.fcp_eq_hdl
[index
]);
8256 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
8257 "0486 MSI-X fast-path (%d) "
8258 "request_irq failed (%d)\n", index
, rc
);
8263 if (vectors
!= phba
->cfg_fcp_io_channel
) {
8264 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8265 "3238 Reducing IO channels to match number of "
8266 "MSI-X vectors, requested %d got %d\n",
8267 phba
->cfg_fcp_io_channel
, vectors
);
8268 phba
->cfg_fcp_io_channel
= vectors
;
8273 /* free the irq already requested */
8274 for (--index
; index
>= 0; index
--)
8275 free_irq(phba
->sli4_hba
.msix_entries
[index
].vector
,
8276 &phba
->sli4_hba
.fcp_eq_hdl
[index
]);
8279 /* Unconfigure MSI-X capability structure */
8280 pci_disable_msix(phba
->pcidev
);
8285 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
8286 * @phba: pointer to lpfc hba data structure.
8288 * This routine is invoked to release the MSI-X vectors and then disable the
8289 * MSI-X interrupt mode to device with SLI-4 interface spec.
8292 lpfc_sli4_disable_msix(struct lpfc_hba
*phba
)
8296 /* Free up MSI-X multi-message vectors */
8297 for (index
= 0; index
< phba
->cfg_fcp_io_channel
; index
++)
8298 free_irq(phba
->sli4_hba
.msix_entries
[index
].vector
,
8299 &phba
->sli4_hba
.fcp_eq_hdl
[index
]);
8302 pci_disable_msix(phba
->pcidev
);
8308 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
8309 * @phba: pointer to lpfc hba data structure.
8311 * This routine is invoked to enable the MSI interrupt mode to device with
8312 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
8313 * to enable the MSI vector. The device driver is responsible for calling
8314 * the request_irq() to register MSI vector with a interrupt the handler,
8315 * which is done in this function.
8319 * other values - error
8322 lpfc_sli4_enable_msi(struct lpfc_hba
*phba
)
8326 rc
= pci_enable_msi(phba
->pcidev
);
8328 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8329 "0487 PCI enable MSI mode success.\n");
8331 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8332 "0488 PCI enable MSI mode failed (%d)\n", rc
);
8336 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
8337 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
8339 pci_disable_msi(phba
->pcidev
);
8340 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
8341 "0490 MSI request_irq failed (%d)\n", rc
);
8345 for (index
= 0; index
< phba
->cfg_fcp_io_channel
; index
++) {
8346 phba
->sli4_hba
.fcp_eq_hdl
[index
].idx
= index
;
8347 phba
->sli4_hba
.fcp_eq_hdl
[index
].phba
= phba
;
8354 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
8355 * @phba: pointer to lpfc hba data structure.
8357 * This routine is invoked to disable the MSI interrupt mode to device with
8358 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
8359 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8360 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8364 lpfc_sli4_disable_msi(struct lpfc_hba
*phba
)
8366 free_irq(phba
->pcidev
->irq
, phba
);
8367 pci_disable_msi(phba
->pcidev
);
8372 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
8373 * @phba: pointer to lpfc hba data structure.
8375 * This routine is invoked to enable device interrupt and associate driver's
8376 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
8377 * interface spec. Depends on the interrupt mode configured to the driver,
8378 * the driver will try to fallback from the configured interrupt mode to an
8379 * interrupt mode which is supported by the platform, kernel, and device in
8381 * MSI-X -> MSI -> IRQ.
8385 * other values - error
8388 lpfc_sli4_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
8390 uint32_t intr_mode
= LPFC_INTR_ERROR
;
8393 if (cfg_mode
== 2) {
8394 /* Preparation before conf_msi mbox cmd */
8397 /* Now, try to enable MSI-X interrupt mode */
8398 retval
= lpfc_sli4_enable_msix(phba
);
8400 /* Indicate initialization to MSI-X mode */
8401 phba
->intr_type
= MSIX
;
8407 /* Fallback to MSI if MSI-X initialization failed */
8408 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
8409 retval
= lpfc_sli4_enable_msi(phba
);
8411 /* Indicate initialization to MSI mode */
8412 phba
->intr_type
= MSI
;
8417 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8418 if (phba
->intr_type
== NONE
) {
8419 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
8420 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
8422 /* Indicate initialization to INTx mode */
8423 phba
->intr_type
= INTx
;
8425 for (index
= 0; index
< phba
->cfg_fcp_io_channel
;
8427 phba
->sli4_hba
.fcp_eq_hdl
[index
].idx
= index
;
8428 phba
->sli4_hba
.fcp_eq_hdl
[index
].phba
= phba
;
8429 atomic_set(&phba
->sli4_hba
.fcp_eq_hdl
[index
].
8438 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
8439 * @phba: pointer to lpfc hba data structure.
8441 * This routine is invoked to disable device interrupt and disassociate
8442 * the driver's interrupt handler(s) from interrupt vector(s) to device
8443 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
8444 * will release the interrupt vector(s) for the message signaled interrupt.
8447 lpfc_sli4_disable_intr(struct lpfc_hba
*phba
)
8449 /* Disable the currently initialized interrupt mode */
8450 if (phba
->intr_type
== MSIX
)
8451 lpfc_sli4_disable_msix(phba
);
8452 else if (phba
->intr_type
== MSI
)
8453 lpfc_sli4_disable_msi(phba
);
8454 else if (phba
->intr_type
== INTx
)
8455 free_irq(phba
->pcidev
->irq
, phba
);
8457 /* Reset interrupt management states */
8458 phba
->intr_type
= NONE
;
8459 phba
->sli
.slistat
.sli_intr
= 0;
8465 * lpfc_unset_hba - Unset SLI3 hba device initialization
8466 * @phba: pointer to lpfc hba data structure.
8468 * This routine is invoked to unset the HBA device initialization steps to
8469 * a device with SLI-3 interface spec.
8472 lpfc_unset_hba(struct lpfc_hba
*phba
)
8474 struct lpfc_vport
*vport
= phba
->pport
;
8475 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8477 spin_lock_irq(shost
->host_lock
);
8478 vport
->load_flag
|= FC_UNLOADING
;
8479 spin_unlock_irq(shost
->host_lock
);
8481 kfree(phba
->vpi_bmask
);
8482 kfree(phba
->vpi_ids
);
8484 lpfc_stop_hba_timers(phba
);
8486 phba
->pport
->work_port_events
= 0;
8488 lpfc_sli_hba_down(phba
);
8490 lpfc_sli_brdrestart(phba
);
8492 lpfc_sli_disable_intr(phba
);
8498 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
8499 * @phba: Pointer to HBA context object.
8501 * This function is called in the SLI4 code path to wait for completion
8502 * of device's XRIs exchange busy. It will check the XRI exchange busy
8503 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
8504 * that, it will check the XRI exchange busy on outstanding FCP and ELS
8505 * I/Os every 30 seconds, log error message, and wait forever. Only when
8506 * all XRI exchange busy complete, the driver unload shall proceed with
8507 * invoking the function reset ioctl mailbox command to the CNA and the
8508 * the rest of the driver unload resource release.
8511 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba
*phba
)
8514 int fcp_xri_cmpl
= list_empty(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
8515 int els_xri_cmpl
= list_empty(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
8517 while (!fcp_xri_cmpl
|| !els_xri_cmpl
) {
8518 if (wait_time
> LPFC_XRI_EXCH_BUSY_WAIT_TMO
) {
8520 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8521 "2877 FCP XRI exchange busy "
8522 "wait time: %d seconds.\n",
8525 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8526 "2878 ELS XRI exchange busy "
8527 "wait time: %d seconds.\n",
8529 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2
);
8530 wait_time
+= LPFC_XRI_EXCH_BUSY_WAIT_T2
;
8532 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1
);
8533 wait_time
+= LPFC_XRI_EXCH_BUSY_WAIT_T1
;
8536 list_empty(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
8538 list_empty(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
8543 * lpfc_sli4_hba_unset - Unset the fcoe hba
8544 * @phba: Pointer to HBA context object.
8546 * This function is called in the SLI4 code path to reset the HBA's FCoE
8547 * function. The caller is not required to hold any lock. This routine
8548 * issues PCI function reset mailbox command to reset the FCoE function.
8549 * At the end of the function, it calls lpfc_hba_down_post function to
8550 * free any pending commands.
8553 lpfc_sli4_hba_unset(struct lpfc_hba
*phba
)
8556 LPFC_MBOXQ_t
*mboxq
;
8557 struct pci_dev
*pdev
= phba
->pcidev
;
8559 lpfc_stop_hba_timers(phba
);
8560 phba
->sli4_hba
.intr_enable
= 0;
8563 * Gracefully wait out the potential current outstanding asynchronous
8567 /* First, block any pending async mailbox command from posted */
8568 spin_lock_irq(&phba
->hbalock
);
8569 phba
->sli
.sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
8570 spin_unlock_irq(&phba
->hbalock
);
8571 /* Now, trying to wait it out if we can */
8572 while (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
8574 if (++wait_cnt
> LPFC_ACTIVE_MBOX_WAIT_CNT
)
8577 /* Forcefully release the outstanding mailbox command if timed out */
8578 if (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
8579 spin_lock_irq(&phba
->hbalock
);
8580 mboxq
= phba
->sli
.mbox_active
;
8581 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
8582 __lpfc_mbox_cmpl_put(phba
, mboxq
);
8583 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
8584 phba
->sli
.mbox_active
= NULL
;
8585 spin_unlock_irq(&phba
->hbalock
);
8588 /* Abort all iocbs associated with the hba */
8589 lpfc_sli_hba_iocb_abort(phba
);
8591 /* Wait for completion of device XRI exchange busy */
8592 lpfc_sli4_xri_exchange_busy_wait(phba
);
8594 /* Disable PCI subsystem interrupt */
8595 lpfc_sli4_disable_intr(phba
);
8597 /* Disable SR-IOV if enabled */
8598 if (phba
->cfg_sriov_nr_virtfn
)
8599 pci_disable_sriov(pdev
);
8601 /* Stop kthread signal shall trigger work_done one more time */
8602 kthread_stop(phba
->worker_thread
);
8604 /* Reset SLI4 HBA FCoE function */
8605 lpfc_pci_function_reset(phba
);
8606 lpfc_sli4_queue_destroy(phba
);
8608 /* Stop the SLI4 device port */
8609 phba
->pport
->work_port_events
= 0;
8613 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
8614 * @phba: Pointer to HBA context object.
8615 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8617 * This function is called in the SLI4 code path to read the port's
8618 * sli4 capabilities.
8620 * This function may be be called from any context that can block-wait
8621 * for the completion. The expectation is that this routine is called
8622 * typically from probe_one or from the online routine.
8625 lpfc_pc_sli4_params_get(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
8628 struct lpfc_mqe
*mqe
;
8629 struct lpfc_pc_sli4_params
*sli4_params
;
8633 mqe
= &mboxq
->u
.mqe
;
8635 /* Read the port's SLI4 Parameters port capabilities */
8636 lpfc_pc_sli4_params(mboxq
);
8637 if (!phba
->sli4_hba
.intr_enable
)
8638 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
8640 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
8641 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
8647 sli4_params
= &phba
->sli4_hba
.pc_sli4_params
;
8648 sli4_params
->if_type
= bf_get(if_type
, &mqe
->un
.sli4_params
);
8649 sli4_params
->sli_rev
= bf_get(sli_rev
, &mqe
->un
.sli4_params
);
8650 sli4_params
->sli_family
= bf_get(sli_family
, &mqe
->un
.sli4_params
);
8651 sli4_params
->featurelevel_1
= bf_get(featurelevel_1
,
8652 &mqe
->un
.sli4_params
);
8653 sli4_params
->featurelevel_2
= bf_get(featurelevel_2
,
8654 &mqe
->un
.sli4_params
);
8655 sli4_params
->proto_types
= mqe
->un
.sli4_params
.word3
;
8656 sli4_params
->sge_supp_len
= mqe
->un
.sli4_params
.sge_supp_len
;
8657 sli4_params
->if_page_sz
= bf_get(if_page_sz
, &mqe
->un
.sli4_params
);
8658 sli4_params
->rq_db_window
= bf_get(rq_db_window
, &mqe
->un
.sli4_params
);
8659 sli4_params
->loopbk_scope
= bf_get(loopbk_scope
, &mqe
->un
.sli4_params
);
8660 sli4_params
->eq_pages_max
= bf_get(eq_pages
, &mqe
->un
.sli4_params
);
8661 sli4_params
->eqe_size
= bf_get(eqe_size
, &mqe
->un
.sli4_params
);
8662 sli4_params
->cq_pages_max
= bf_get(cq_pages
, &mqe
->un
.sli4_params
);
8663 sli4_params
->cqe_size
= bf_get(cqe_size
, &mqe
->un
.sli4_params
);
8664 sli4_params
->mq_pages_max
= bf_get(mq_pages
, &mqe
->un
.sli4_params
);
8665 sli4_params
->mqe_size
= bf_get(mqe_size
, &mqe
->un
.sli4_params
);
8666 sli4_params
->mq_elem_cnt
= bf_get(mq_elem_cnt
, &mqe
->un
.sli4_params
);
8667 sli4_params
->wq_pages_max
= bf_get(wq_pages
, &mqe
->un
.sli4_params
);
8668 sli4_params
->wqe_size
= bf_get(wqe_size
, &mqe
->un
.sli4_params
);
8669 sli4_params
->rq_pages_max
= bf_get(rq_pages
, &mqe
->un
.sli4_params
);
8670 sli4_params
->rqe_size
= bf_get(rqe_size
, &mqe
->un
.sli4_params
);
8671 sli4_params
->hdr_pages_max
= bf_get(hdr_pages
, &mqe
->un
.sli4_params
);
8672 sli4_params
->hdr_size
= bf_get(hdr_size
, &mqe
->un
.sli4_params
);
8673 sli4_params
->hdr_pp_align
= bf_get(hdr_pp_align
, &mqe
->un
.sli4_params
);
8674 sli4_params
->sgl_pages_max
= bf_get(sgl_pages
, &mqe
->un
.sli4_params
);
8675 sli4_params
->sgl_pp_align
= bf_get(sgl_pp_align
, &mqe
->un
.sli4_params
);
8677 /* Make sure that sge_supp_len can be handled by the driver */
8678 if (sli4_params
->sge_supp_len
> LPFC_MAX_SGE_SIZE
)
8679 sli4_params
->sge_supp_len
= LPFC_MAX_SGE_SIZE
;
8685 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
8686 * @phba: Pointer to HBA context object.
8687 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
8689 * This function is called in the SLI4 code path to read the port's
8690 * sli4 capabilities.
8692 * This function may be be called from any context that can block-wait
8693 * for the completion. The expectation is that this routine is called
8694 * typically from probe_one or from the online routine.
8697 lpfc_get_sli4_parameters(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
8700 struct lpfc_mqe
*mqe
= &mboxq
->u
.mqe
;
8701 struct lpfc_pc_sli4_params
*sli4_params
;
8704 struct lpfc_sli4_parameters
*mbx_sli4_parameters
;
8707 * By default, the driver assumes the SLI4 port requires RPI
8708 * header postings. The SLI4_PARAM response will correct this
8711 phba
->sli4_hba
.rpi_hdrs_in_use
= 1;
8713 /* Read the port's SLI4 Config Parameters */
8714 length
= (sizeof(struct lpfc_mbx_get_sli4_parameters
) -
8715 sizeof(struct lpfc_sli4_cfg_mhdr
));
8716 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
8717 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS
,
8718 length
, LPFC_SLI4_MBX_EMBED
);
8719 if (!phba
->sli4_hba
.intr_enable
)
8720 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
8722 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
8723 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
8727 sli4_params
= &phba
->sli4_hba
.pc_sli4_params
;
8728 mbx_sli4_parameters
= &mqe
->un
.get_sli4_parameters
.sli4_parameters
;
8729 sli4_params
->if_type
= bf_get(cfg_if_type
, mbx_sli4_parameters
);
8730 sli4_params
->sli_rev
= bf_get(cfg_sli_rev
, mbx_sli4_parameters
);
8731 sli4_params
->sli_family
= bf_get(cfg_sli_family
, mbx_sli4_parameters
);
8732 sli4_params
->featurelevel_1
= bf_get(cfg_sli_hint_1
,
8733 mbx_sli4_parameters
);
8734 sli4_params
->featurelevel_2
= bf_get(cfg_sli_hint_2
,
8735 mbx_sli4_parameters
);
8736 if (bf_get(cfg_phwq
, mbx_sli4_parameters
))
8737 phba
->sli3_options
|= LPFC_SLI4_PHWQ_ENABLED
;
8739 phba
->sli3_options
&= ~LPFC_SLI4_PHWQ_ENABLED
;
8740 sli4_params
->sge_supp_len
= mbx_sli4_parameters
->sge_supp_len
;
8741 sli4_params
->loopbk_scope
= bf_get(loopbk_scope
, mbx_sli4_parameters
);
8742 sli4_params
->cqv
= bf_get(cfg_cqv
, mbx_sli4_parameters
);
8743 sli4_params
->mqv
= bf_get(cfg_mqv
, mbx_sli4_parameters
);
8744 sli4_params
->wqv
= bf_get(cfg_wqv
, mbx_sli4_parameters
);
8745 sli4_params
->rqv
= bf_get(cfg_rqv
, mbx_sli4_parameters
);
8746 sli4_params
->sgl_pages_max
= bf_get(cfg_sgl_page_cnt
,
8747 mbx_sli4_parameters
);
8748 sli4_params
->sgl_pp_align
= bf_get(cfg_sgl_pp_align
,
8749 mbx_sli4_parameters
);
8750 phba
->sli4_hba
.extents_in_use
= bf_get(cfg_ext
, mbx_sli4_parameters
);
8751 phba
->sli4_hba
.rpi_hdrs_in_use
= bf_get(cfg_hdrr
, mbx_sli4_parameters
);
8753 /* Make sure that sge_supp_len can be handled by the driver */
8754 if (sli4_params
->sge_supp_len
> LPFC_MAX_SGE_SIZE
)
8755 sli4_params
->sge_supp_len
= LPFC_MAX_SGE_SIZE
;
8761 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
8762 * @pdev: pointer to PCI device
8763 * @pid: pointer to PCI device identifier
8765 * This routine is to be called to attach a device with SLI-3 interface spec
8766 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8767 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
8768 * information of the device and driver to see if the driver state that it can
8769 * support this kind of device. If the match is successful, the driver core
8770 * invokes this routine. If this routine determines it can claim the HBA, it
8771 * does all the initialization that it needs to do to handle the HBA properly.
8774 * 0 - driver can claim the device
8775 * negative value - driver can not claim the device
8778 lpfc_pci_probe_one_s3(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
8780 struct lpfc_hba
*phba
;
8781 struct lpfc_vport
*vport
= NULL
;
8782 struct Scsi_Host
*shost
= NULL
;
8784 uint32_t cfg_mode
, intr_mode
;
8786 /* Allocate memory for HBA structure */
8787 phba
= lpfc_hba_alloc(pdev
);
8791 /* Perform generic PCI device enabling operation */
8792 error
= lpfc_enable_pci_dev(phba
);
8796 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
8797 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_LP
);
8799 goto out_disable_pci_dev
;
8801 /* Set up SLI-3 specific device PCI memory space */
8802 error
= lpfc_sli_pci_mem_setup(phba
);
8804 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8805 "1402 Failed to set up pci memory space.\n");
8806 goto out_disable_pci_dev
;
8809 /* Set up phase-1 common device driver resources */
8810 error
= lpfc_setup_driver_resource_phase1(phba
);
8812 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8813 "1403 Failed to set up driver resource.\n");
8814 goto out_unset_pci_mem_s3
;
8817 /* Set up SLI-3 specific device driver resources */
8818 error
= lpfc_sli_driver_resource_setup(phba
);
8820 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8821 "1404 Failed to set up driver resource.\n");
8822 goto out_unset_pci_mem_s3
;
8825 /* Initialize and populate the iocb list per host */
8826 error
= lpfc_init_iocb_list(phba
, LPFC_IOCB_LIST_CNT
);
8828 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8829 "1405 Failed to initialize iocb list.\n");
8830 goto out_unset_driver_resource_s3
;
8833 /* Set up common device driver resources */
8834 error
= lpfc_setup_driver_resource_phase2(phba
);
8836 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8837 "1406 Failed to set up driver resource.\n");
8838 goto out_free_iocb_list
;
8841 /* Get the default values for Model Name and Description */
8842 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
8844 /* Create SCSI host to the physical port */
8845 error
= lpfc_create_shost(phba
);
8847 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8848 "1407 Failed to create scsi host.\n");
8849 goto out_unset_driver_resource
;
8852 /* Configure sysfs attributes */
8853 vport
= phba
->pport
;
8854 error
= lpfc_alloc_sysfs_attr(vport
);
8856 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8857 "1476 Failed to allocate sysfs attr\n");
8858 goto out_destroy_shost
;
8861 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
8862 /* Now, trying to enable interrupt and bring up the device */
8863 cfg_mode
= phba
->cfg_use_msi
;
8865 /* Put device to a known state before enabling interrupt */
8866 lpfc_stop_port(phba
);
8867 /* Configure and enable interrupt */
8868 intr_mode
= lpfc_sli_enable_intr(phba
, cfg_mode
);
8869 if (intr_mode
== LPFC_INTR_ERROR
) {
8870 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8871 "0431 Failed to enable interrupt.\n");
8873 goto out_free_sysfs_attr
;
8875 /* SLI-3 HBA setup */
8876 if (lpfc_sli_hba_setup(phba
)) {
8877 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8878 "1477 Failed to set up hba\n");
8880 goto out_remove_device
;
8883 /* Wait 50ms for the interrupts of previous mailbox commands */
8885 /* Check active interrupts on message signaled interrupts */
8886 if (intr_mode
== 0 ||
8887 phba
->sli
.slistat
.sli_intr
> LPFC_MSIX_VECTORS
) {
8888 /* Log the current active interrupt mode */
8889 phba
->intr_mode
= intr_mode
;
8890 lpfc_log_intr_mode(phba
, intr_mode
);
8893 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8894 "0447 Configure interrupt mode (%d) "
8895 "failed active interrupt test.\n",
8897 /* Disable the current interrupt mode */
8898 lpfc_sli_disable_intr(phba
);
8899 /* Try next level of interrupt mode */
8900 cfg_mode
= --intr_mode
;
8904 /* Perform post initialization setup */
8905 lpfc_post_init_setup(phba
);
8907 /* Check if there are static vports to be created. */
8908 lpfc_create_static_vport(phba
);
8913 lpfc_unset_hba(phba
);
8914 out_free_sysfs_attr
:
8915 lpfc_free_sysfs_attr(vport
);
8917 lpfc_destroy_shost(phba
);
8918 out_unset_driver_resource
:
8919 lpfc_unset_driver_resource_phase2(phba
);
8921 lpfc_free_iocb_list(phba
);
8922 out_unset_driver_resource_s3
:
8923 lpfc_sli_driver_resource_unset(phba
);
8924 out_unset_pci_mem_s3
:
8925 lpfc_sli_pci_mem_unset(phba
);
8926 out_disable_pci_dev
:
8927 lpfc_disable_pci_dev(phba
);
8929 scsi_host_put(shost
);
8931 lpfc_hba_free(phba
);
8936 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
8937 * @pdev: pointer to PCI device
8939 * This routine is to be called to disattach a device with SLI-3 interface
8940 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
8941 * removed from PCI bus, it performs all the necessary cleanup for the HBA
8942 * device to be removed from the PCI subsystem properly.
8945 lpfc_pci_remove_one_s3(struct pci_dev
*pdev
)
8947 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
8948 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
8949 struct lpfc_vport
**vports
;
8950 struct lpfc_hba
*phba
= vport
->phba
;
8952 int bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
8954 spin_lock_irq(&phba
->hbalock
);
8955 vport
->load_flag
|= FC_UNLOADING
;
8956 spin_unlock_irq(&phba
->hbalock
);
8958 lpfc_free_sysfs_attr(vport
);
8960 /* Release all the vports against this physical port */
8961 vports
= lpfc_create_vport_work_array(phba
);
8963 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
8964 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
8966 fc_vport_terminate(vports
[i
]->fc_vport
);
8968 lpfc_destroy_vport_work_array(phba
, vports
);
8970 /* Remove FC host and then SCSI host with the physical port */
8971 fc_remove_host(shost
);
8972 scsi_remove_host(shost
);
8973 lpfc_cleanup(vport
);
8976 * Bring down the SLI Layer. This step disable all interrupts,
8977 * clears the rings, discards all mailbox commands, and resets
8981 /* HBA interrupt will be disabled after this call */
8982 lpfc_sli_hba_down(phba
);
8983 /* Stop kthread signal shall trigger work_done one more time */
8984 kthread_stop(phba
->worker_thread
);
8985 /* Final cleanup of txcmplq and reset the HBA */
8986 lpfc_sli_brdrestart(phba
);
8988 kfree(phba
->vpi_bmask
);
8989 kfree(phba
->vpi_ids
);
8991 lpfc_stop_hba_timers(phba
);
8992 spin_lock_irq(&phba
->hbalock
);
8993 list_del_init(&vport
->listentry
);
8994 spin_unlock_irq(&phba
->hbalock
);
8996 lpfc_debugfs_terminate(vport
);
8998 /* Disable SR-IOV if enabled */
8999 if (phba
->cfg_sriov_nr_virtfn
)
9000 pci_disable_sriov(pdev
);
9002 /* Disable interrupt */
9003 lpfc_sli_disable_intr(phba
);
9005 pci_set_drvdata(pdev
, NULL
);
9006 scsi_host_put(shost
);
9009 * Call scsi_free before mem_free since scsi bufs are released to their
9010 * corresponding pools here.
9012 lpfc_scsi_free(phba
);
9013 lpfc_mem_free_all(phba
);
9015 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
9016 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
9018 /* Free resources associated with SLI2 interface */
9019 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
9020 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
9022 /* unmap adapter SLIM and Control Registers */
9023 iounmap(phba
->ctrl_regs_memmap_p
);
9024 iounmap(phba
->slim_memmap_p
);
9026 lpfc_hba_free(phba
);
9028 pci_release_selected_regions(pdev
, bars
);
9029 pci_disable_device(pdev
);
9033 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
9034 * @pdev: pointer to PCI device
9035 * @msg: power management message
9037 * This routine is to be called from the kernel's PCI subsystem to support
9038 * system Power Management (PM) to device with SLI-3 interface spec. When
9039 * PM invokes this method, it quiesces the device by stopping the driver's
9040 * worker thread for the device, turning off device's interrupt and DMA,
9041 * and bring the device offline. Note that as the driver implements the
9042 * minimum PM requirements to a power-aware driver's PM support for the
9043 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9044 * to the suspend() method call will be treated as SUSPEND and the driver will
9045 * fully reinitialize its device during resume() method call, the driver will
9046 * set device to PCI_D3hot state in PCI config space instead of setting it
9047 * according to the @msg provided by the PM.
9050 * 0 - driver suspended the device
9054 lpfc_pci_suspend_one_s3(struct pci_dev
*pdev
, pm_message_t msg
)
9056 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9057 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9059 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9060 "0473 PCI device Power Management suspend.\n");
9062 /* Bring down the device */
9063 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
9065 kthread_stop(phba
->worker_thread
);
9067 /* Disable interrupt from device */
9068 lpfc_sli_disable_intr(phba
);
9070 /* Save device state to PCI config space */
9071 pci_save_state(pdev
);
9072 pci_set_power_state(pdev
, PCI_D3hot
);
9078 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
9079 * @pdev: pointer to PCI device
9081 * This routine is to be called from the kernel's PCI subsystem to support
9082 * system Power Management (PM) to device with SLI-3 interface spec. When PM
9083 * invokes this method, it restores the device's PCI config space state and
9084 * fully reinitializes the device and brings it online. Note that as the
9085 * driver implements the minimum PM requirements to a power-aware driver's
9086 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
9087 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
9088 * driver will fully reinitialize its device during resume() method call,
9089 * the device will be set to PCI_D0 directly in PCI config space before
9090 * restoring the state.
9093 * 0 - driver suspended the device
9097 lpfc_pci_resume_one_s3(struct pci_dev
*pdev
)
9099 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9100 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9104 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9105 "0452 PCI device Power Management resume.\n");
9107 /* Restore device state from PCI config space */
9108 pci_set_power_state(pdev
, PCI_D0
);
9109 pci_restore_state(pdev
);
9112 * As the new kernel behavior of pci_restore_state() API call clears
9113 * device saved_state flag, need to save the restored state again.
9115 pci_save_state(pdev
);
9117 if (pdev
->is_busmaster
)
9118 pci_set_master(pdev
);
9120 /* Startup the kernel thread for this host adapter. */
9121 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
9122 "lpfc_worker_%d", phba
->brd_no
);
9123 if (IS_ERR(phba
->worker_thread
)) {
9124 error
= PTR_ERR(phba
->worker_thread
);
9125 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9126 "0434 PM resume failed to start worker "
9127 "thread: error=x%x.\n", error
);
9131 /* Configure and enable interrupt */
9132 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
9133 if (intr_mode
== LPFC_INTR_ERROR
) {
9134 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9135 "0430 PM resume Failed to enable interrupt\n");
9138 phba
->intr_mode
= intr_mode
;
9140 /* Restart HBA and bring it online */
9141 lpfc_sli_brdrestart(phba
);
9144 /* Log the current active interrupt mode */
9145 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
9151 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
9152 * @phba: pointer to lpfc hba data structure.
9154 * This routine is called to prepare the SLI3 device for PCI slot recover. It
9155 * aborts all the outstanding SCSI I/Os to the pci device.
9158 lpfc_sli_prep_dev_for_recover(struct lpfc_hba
*phba
)
9160 struct lpfc_sli
*psli
= &phba
->sli
;
9161 struct lpfc_sli_ring
*pring
;
9163 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9164 "2723 PCI channel I/O abort preparing for recovery\n");
9167 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9168 * and let the SCSI mid-layer to retry them to recover.
9170 pring
= &psli
->ring
[psli
->fcp_ring
];
9171 lpfc_sli_abort_iocb_ring(phba
, pring
);
9175 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
9176 * @phba: pointer to lpfc hba data structure.
9178 * This routine is called to prepare the SLI3 device for PCI slot reset. It
9179 * disables the device interrupt and pci device, and aborts the internal FCP
9183 lpfc_sli_prep_dev_for_reset(struct lpfc_hba
*phba
)
9185 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9186 "2710 PCI channel disable preparing for reset\n");
9188 /* Block any management I/Os to the device */
9189 lpfc_block_mgmt_io(phba
, LPFC_MBX_WAIT
);
9191 /* Block all SCSI devices' I/Os on the host */
9192 lpfc_scsi_dev_block(phba
);
9194 /* stop all timers */
9195 lpfc_stop_hba_timers(phba
);
9197 /* Disable interrupt and pci device */
9198 lpfc_sli_disable_intr(phba
);
9199 pci_disable_device(phba
->pcidev
);
9201 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9202 lpfc_sli_flush_fcp_rings(phba
);
9206 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
9207 * @phba: pointer to lpfc hba data structure.
9209 * This routine is called to prepare the SLI3 device for PCI slot permanently
9210 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9214 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
9216 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9217 "2711 PCI channel permanent disable for failure\n");
9218 /* Block all SCSI devices' I/Os on the host */
9219 lpfc_scsi_dev_block(phba
);
9221 /* stop all timers */
9222 lpfc_stop_hba_timers(phba
);
9224 /* Clean up all driver's outstanding SCSI I/Os */
9225 lpfc_sli_flush_fcp_rings(phba
);
9229 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
9230 * @pdev: pointer to PCI device.
9231 * @state: the current PCI connection state.
9233 * This routine is called from the PCI subsystem for I/O error handling to
9234 * device with SLI-3 interface spec. This function is called by the PCI
9235 * subsystem after a PCI bus error affecting this device has been detected.
9236 * When this function is invoked, it will need to stop all the I/Os and
9237 * interrupt(s) to the device. Once that is done, it will return
9238 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
9242 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
9243 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9244 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9246 static pci_ers_result_t
9247 lpfc_io_error_detected_s3(struct pci_dev
*pdev
, pci_channel_state_t state
)
9249 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9250 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9253 case pci_channel_io_normal
:
9254 /* Non-fatal error, prepare for recovery */
9255 lpfc_sli_prep_dev_for_recover(phba
);
9256 return PCI_ERS_RESULT_CAN_RECOVER
;
9257 case pci_channel_io_frozen
:
9258 /* Fatal error, prepare for slot reset */
9259 lpfc_sli_prep_dev_for_reset(phba
);
9260 return PCI_ERS_RESULT_NEED_RESET
;
9261 case pci_channel_io_perm_failure
:
9262 /* Permanent failure, prepare for device down */
9263 lpfc_sli_prep_dev_for_perm_failure(phba
);
9264 return PCI_ERS_RESULT_DISCONNECT
;
9266 /* Unknown state, prepare and request slot reset */
9267 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9268 "0472 Unknown PCI error state: x%x\n", state
);
9269 lpfc_sli_prep_dev_for_reset(phba
);
9270 return PCI_ERS_RESULT_NEED_RESET
;
9275 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
9276 * @pdev: pointer to PCI device.
9278 * This routine is called from the PCI subsystem for error handling to
9279 * device with SLI-3 interface spec. This is called after PCI bus has been
9280 * reset to restart the PCI card from scratch, as if from a cold-boot.
9281 * During the PCI subsystem error recovery, after driver returns
9282 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
9283 * recovery and then call this routine before calling the .resume method
9284 * to recover the device. This function will initialize the HBA device,
9285 * enable the interrupt, but it will just put the HBA to offline state
9286 * without passing any I/O traffic.
9289 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9290 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9292 static pci_ers_result_t
9293 lpfc_io_slot_reset_s3(struct pci_dev
*pdev
)
9295 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9296 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9297 struct lpfc_sli
*psli
= &phba
->sli
;
9300 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
9301 if (pci_enable_device_mem(pdev
)) {
9302 printk(KERN_ERR
"lpfc: Cannot re-enable "
9303 "PCI device after reset.\n");
9304 return PCI_ERS_RESULT_DISCONNECT
;
9307 pci_restore_state(pdev
);
9310 * As the new kernel behavior of pci_restore_state() API call clears
9311 * device saved_state flag, need to save the restored state again.
9313 pci_save_state(pdev
);
9315 if (pdev
->is_busmaster
)
9316 pci_set_master(pdev
);
9318 spin_lock_irq(&phba
->hbalock
);
9319 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
9320 spin_unlock_irq(&phba
->hbalock
);
9322 /* Configure and enable interrupt */
9323 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
9324 if (intr_mode
== LPFC_INTR_ERROR
) {
9325 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9326 "0427 Cannot re-enable interrupt after "
9328 return PCI_ERS_RESULT_DISCONNECT
;
9330 phba
->intr_mode
= intr_mode
;
9332 /* Take device offline, it will perform cleanup */
9333 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
9335 lpfc_sli_brdrestart(phba
);
9337 /* Log the current active interrupt mode */
9338 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
9340 return PCI_ERS_RESULT_RECOVERED
;
9344 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
9345 * @pdev: pointer to PCI device
9347 * This routine is called from the PCI subsystem for error handling to device
9348 * with SLI-3 interface spec. It is called when kernel error recovery tells
9349 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
9350 * error recovery. After this call, traffic can start to flow from this device
9354 lpfc_io_resume_s3(struct pci_dev
*pdev
)
9356 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9357 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9359 /* Bring device online, it will be no-op for non-fatal error resume */
9362 /* Clean up Advanced Error Reporting (AER) if needed */
9363 if (phba
->hba_flag
& HBA_AER_ENABLED
)
9364 pci_cleanup_aer_uncorrect_error_status(pdev
);
9368 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
9369 * @phba: pointer to lpfc hba data structure.
9371 * returns the number of ELS/CT IOCBs to reserve
9374 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba
*phba
)
9376 int max_xri
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
9378 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9381 else if (max_xri
<= 256)
9383 else if (max_xri
<= 512)
9385 else if (max_xri
<= 1024)
9387 else if (max_xri
<= 1536)
9389 else if (max_xri
<= 2048)
9398 * lpfc_write_firmware - attempt to write a firmware image to the port
9399 * @fw: pointer to firmware image returned from request_firmware.
9400 * @phba: pointer to lpfc hba data structure.
9404 lpfc_write_firmware(const struct firmware
*fw
, void *context
)
9406 struct lpfc_hba
*phba
= (struct lpfc_hba
*)context
;
9407 char fwrev
[FW_REV_STR_SIZE
];
9408 struct lpfc_grp_hdr
*image
;
9409 struct list_head dma_buffer_list
;
9411 struct lpfc_dmabuf
*dmabuf
, *next
;
9412 uint32_t offset
= 0, temp_offset
= 0;
9414 /* It can be null in no-wait mode, sanity check */
9419 image
= (struct lpfc_grp_hdr
*)fw
->data
;
9421 INIT_LIST_HEAD(&dma_buffer_list
);
9422 if ((be32_to_cpu(image
->magic_number
) != LPFC_GROUP_OJECT_MAGIC_NUM
) ||
9423 (bf_get_be32(lpfc_grp_hdr_file_type
, image
) !=
9424 LPFC_FILE_TYPE_GROUP
) ||
9425 (bf_get_be32(lpfc_grp_hdr_id
, image
) != LPFC_FILE_ID_GROUP
) ||
9426 (be32_to_cpu(image
->size
) != fw
->size
)) {
9427 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9428 "3022 Invalid FW image found. "
9429 "Magic:%x Type:%x ID:%x\n",
9430 be32_to_cpu(image
->magic_number
),
9431 bf_get_be32(lpfc_grp_hdr_file_type
, image
),
9432 bf_get_be32(lpfc_grp_hdr_id
, image
));
9436 lpfc_decode_firmware_rev(phba
, fwrev
, 1);
9437 if (strncmp(fwrev
, image
->revision
, strnlen(image
->revision
, 16))) {
9438 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9439 "3023 Updating Firmware, Current Version:%s "
9441 fwrev
, image
->revision
);
9442 for (i
= 0; i
< LPFC_MBX_WR_CONFIG_MAX_BDE
; i
++) {
9443 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
),
9449 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
9453 if (!dmabuf
->virt
) {
9458 list_add_tail(&dmabuf
->list
, &dma_buffer_list
);
9460 while (offset
< fw
->size
) {
9461 temp_offset
= offset
;
9462 list_for_each_entry(dmabuf
, &dma_buffer_list
, list
) {
9463 if (temp_offset
+ SLI4_PAGE_SIZE
> fw
->size
) {
9464 memcpy(dmabuf
->virt
,
9465 fw
->data
+ temp_offset
,
9466 fw
->size
- temp_offset
);
9467 temp_offset
= fw
->size
;
9470 memcpy(dmabuf
->virt
, fw
->data
+ temp_offset
,
9472 temp_offset
+= SLI4_PAGE_SIZE
;
9474 rc
= lpfc_wr_object(phba
, &dma_buffer_list
,
9475 (fw
->size
- offset
), &offset
);
9483 list_for_each_entry_safe(dmabuf
, next
, &dma_buffer_list
, list
) {
9484 list_del(&dmabuf
->list
);
9485 dma_free_coherent(&phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
9486 dmabuf
->virt
, dmabuf
->phys
);
9489 release_firmware(fw
);
9491 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9492 "3024 Firmware update done: %d.\n", rc
);
9497 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
9498 * @phba: pointer to lpfc hba data structure.
9500 * This routine is called to perform Linux generic firmware upgrade on device
9501 * that supports such feature.
9504 lpfc_sli4_request_firmware_update(struct lpfc_hba
*phba
, uint8_t fw_upgrade
)
9506 uint8_t file_name
[ELX_MODEL_NAME_SIZE
];
9508 const struct firmware
*fw
;
9510 /* Only supported on SLI4 interface type 2 for now */
9511 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
9512 LPFC_SLI_INTF_IF_TYPE_2
)
9515 snprintf(file_name
, ELX_MODEL_NAME_SIZE
, "%s.grp", phba
->ModelName
);
9517 if (fw_upgrade
== INT_FW_UPGRADE
) {
9518 ret
= request_firmware_nowait(THIS_MODULE
, FW_ACTION_HOTPLUG
,
9519 file_name
, &phba
->pcidev
->dev
,
9520 GFP_KERNEL
, (void *)phba
,
9521 lpfc_write_firmware
);
9522 } else if (fw_upgrade
== RUN_FW_UPGRADE
) {
9523 ret
= request_firmware(&fw
, file_name
, &phba
->pcidev
->dev
);
9525 lpfc_write_firmware(fw
, (void *)phba
);
9534 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
9535 * @pdev: pointer to PCI device
9536 * @pid: pointer to PCI device identifier
9538 * This routine is called from the kernel's PCI subsystem to device with
9539 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
9540 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9541 * information of the device and driver to see if the driver state that it
9542 * can support this kind of device. If the match is successful, the driver
9543 * core invokes this routine. If this routine determines it can claim the HBA,
9544 * it does all the initialization that it needs to do to handle the HBA
9548 * 0 - driver can claim the device
9549 * negative value - driver can not claim the device
9552 lpfc_pci_probe_one_s4(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
9554 struct lpfc_hba
*phba
;
9555 struct lpfc_vport
*vport
= NULL
;
9556 struct Scsi_Host
*shost
= NULL
;
9558 uint32_t cfg_mode
, intr_mode
;
9559 int adjusted_fcp_io_channel
;
9561 /* Allocate memory for HBA structure */
9562 phba
= lpfc_hba_alloc(pdev
);
9566 /* Perform generic PCI device enabling operation */
9567 error
= lpfc_enable_pci_dev(phba
);
9571 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
9572 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_OC
);
9574 goto out_disable_pci_dev
;
9576 /* Set up SLI-4 specific device PCI memory space */
9577 error
= lpfc_sli4_pci_mem_setup(phba
);
9579 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9580 "1410 Failed to set up pci memory space.\n");
9581 goto out_disable_pci_dev
;
9584 /* Set up phase-1 common device driver resources */
9585 error
= lpfc_setup_driver_resource_phase1(phba
);
9587 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9588 "1411 Failed to set up driver resource.\n");
9589 goto out_unset_pci_mem_s4
;
9592 /* Set up SLI-4 Specific device driver resources */
9593 error
= lpfc_sli4_driver_resource_setup(phba
);
9595 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9596 "1412 Failed to set up driver resource.\n");
9597 goto out_unset_pci_mem_s4
;
9600 /* Initialize and populate the iocb list per host */
9602 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9603 "2821 initialize iocb list %d.\n",
9604 phba
->cfg_iocb_cnt
*1024);
9605 error
= lpfc_init_iocb_list(phba
, phba
->cfg_iocb_cnt
*1024);
9608 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9609 "1413 Failed to initialize iocb list.\n");
9610 goto out_unset_driver_resource_s4
;
9613 INIT_LIST_HEAD(&phba
->active_rrq_list
);
9614 INIT_LIST_HEAD(&phba
->fcf
.fcf_pri_list
);
9616 /* Set up common device driver resources */
9617 error
= lpfc_setup_driver_resource_phase2(phba
);
9619 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9620 "1414 Failed to set up driver resource.\n");
9621 goto out_free_iocb_list
;
9624 /* Get the default values for Model Name and Description */
9625 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
9627 /* Create SCSI host to the physical port */
9628 error
= lpfc_create_shost(phba
);
9630 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9631 "1415 Failed to create scsi host.\n");
9632 goto out_unset_driver_resource
;
9635 /* Configure sysfs attributes */
9636 vport
= phba
->pport
;
9637 error
= lpfc_alloc_sysfs_attr(vport
);
9639 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9640 "1416 Failed to allocate sysfs attr\n");
9641 goto out_destroy_shost
;
9644 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
9645 /* Now, trying to enable interrupt and bring up the device */
9646 cfg_mode
= phba
->cfg_use_msi
;
9648 /* Put device to a known state before enabling interrupt */
9649 lpfc_stop_port(phba
);
9650 /* Configure and enable interrupt */
9651 intr_mode
= lpfc_sli4_enable_intr(phba
, cfg_mode
);
9652 if (intr_mode
== LPFC_INTR_ERROR
) {
9653 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9654 "0426 Failed to enable interrupt.\n");
9656 goto out_free_sysfs_attr
;
9658 /* Default to single EQ for non-MSI-X */
9659 if (phba
->intr_type
!= MSIX
)
9660 adjusted_fcp_io_channel
= 1;
9662 adjusted_fcp_io_channel
= phba
->cfg_fcp_io_channel
;
9663 phba
->cfg_fcp_io_channel
= adjusted_fcp_io_channel
;
9664 /* Set up SLI-4 HBA */
9665 if (lpfc_sli4_hba_setup(phba
)) {
9666 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9667 "1421 Failed to set up hba\n");
9669 goto out_disable_intr
;
9672 /* Log the current active interrupt mode */
9673 phba
->intr_mode
= intr_mode
;
9674 lpfc_log_intr_mode(phba
, intr_mode
);
9676 /* Perform post initialization setup */
9677 lpfc_post_init_setup(phba
);
9679 /* check for firmware upgrade or downgrade */
9680 if (phba
->cfg_request_firmware_upgrade
)
9681 ret
= lpfc_sli4_request_firmware_update(phba
, INT_FW_UPGRADE
);
9683 /* Check if there are static vports to be created. */
9684 lpfc_create_static_vport(phba
);
9688 lpfc_sli4_disable_intr(phba
);
9689 out_free_sysfs_attr
:
9690 lpfc_free_sysfs_attr(vport
);
9692 lpfc_destroy_shost(phba
);
9693 out_unset_driver_resource
:
9694 lpfc_unset_driver_resource_phase2(phba
);
9696 lpfc_free_iocb_list(phba
);
9697 out_unset_driver_resource_s4
:
9698 lpfc_sli4_driver_resource_unset(phba
);
9699 out_unset_pci_mem_s4
:
9700 lpfc_sli4_pci_mem_unset(phba
);
9701 out_disable_pci_dev
:
9702 lpfc_disable_pci_dev(phba
);
9704 scsi_host_put(shost
);
9706 lpfc_hba_free(phba
);
9711 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
9712 * @pdev: pointer to PCI device
9714 * This routine is called from the kernel's PCI subsystem to device with
9715 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
9716 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9717 * device to be removed from the PCI subsystem properly.
9720 lpfc_pci_remove_one_s4(struct pci_dev
*pdev
)
9722 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9723 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
9724 struct lpfc_vport
**vports
;
9725 struct lpfc_hba
*phba
= vport
->phba
;
9728 /* Mark the device unloading flag */
9729 spin_lock_irq(&phba
->hbalock
);
9730 vport
->load_flag
|= FC_UNLOADING
;
9731 spin_unlock_irq(&phba
->hbalock
);
9733 /* Free the HBA sysfs attributes */
9734 lpfc_free_sysfs_attr(vport
);
9736 /* Release all the vports against this physical port */
9737 vports
= lpfc_create_vport_work_array(phba
);
9739 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
9740 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
9742 fc_vport_terminate(vports
[i
]->fc_vport
);
9744 lpfc_destroy_vport_work_array(phba
, vports
);
9746 /* Remove FC host and then SCSI host with the physical port */
9747 fc_remove_host(shost
);
9748 scsi_remove_host(shost
);
9750 /* Perform cleanup on the physical port */
9751 lpfc_cleanup(vport
);
9754 * Bring down the SLI Layer. This step disables all interrupts,
9755 * clears the rings, discards all mailbox commands, and resets
9756 * the HBA FCoE function.
9758 lpfc_debugfs_terminate(vport
);
9759 lpfc_sli4_hba_unset(phba
);
9761 spin_lock_irq(&phba
->hbalock
);
9762 list_del_init(&vport
->listentry
);
9763 spin_unlock_irq(&phba
->hbalock
);
9765 /* Perform scsi free before driver resource_unset since scsi
9766 * buffers are released to their corresponding pools here.
9768 lpfc_scsi_free(phba
);
9770 lpfc_sli4_driver_resource_unset(phba
);
9772 /* Unmap adapter Control and Doorbell registers */
9773 lpfc_sli4_pci_mem_unset(phba
);
9775 /* Release PCI resources and disable device's PCI function */
9776 scsi_host_put(shost
);
9777 lpfc_disable_pci_dev(phba
);
9779 /* Finally, free the driver's device data structure */
9780 lpfc_hba_free(phba
);
9786 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
9787 * @pdev: pointer to PCI device
9788 * @msg: power management message
9790 * This routine is called from the kernel's PCI subsystem to support system
9791 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
9792 * this method, it quiesces the device by stopping the driver's worker
9793 * thread for the device, turning off device's interrupt and DMA, and bring
9794 * the device offline. Note that as the driver implements the minimum PM
9795 * requirements to a power-aware driver's PM support for suspend/resume -- all
9796 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
9797 * method call will be treated as SUSPEND and the driver will fully
9798 * reinitialize its device during resume() method call, the driver will set
9799 * device to PCI_D3hot state in PCI config space instead of setting it
9800 * according to the @msg provided by the PM.
9803 * 0 - driver suspended the device
9807 lpfc_pci_suspend_one_s4(struct pci_dev
*pdev
, pm_message_t msg
)
9809 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9810 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9812 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9813 "2843 PCI device Power Management suspend.\n");
9815 /* Bring down the device */
9816 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
9818 kthread_stop(phba
->worker_thread
);
9820 /* Disable interrupt from device */
9821 lpfc_sli4_disable_intr(phba
);
9822 lpfc_sli4_queue_destroy(phba
);
9824 /* Save device state to PCI config space */
9825 pci_save_state(pdev
);
9826 pci_set_power_state(pdev
, PCI_D3hot
);
9832 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
9833 * @pdev: pointer to PCI device
9835 * This routine is called from the kernel's PCI subsystem to support system
9836 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
9837 * this method, it restores the device's PCI config space state and fully
9838 * reinitializes the device and brings it online. Note that as the driver
9839 * implements the minimum PM requirements to a power-aware driver's PM for
9840 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9841 * to the suspend() method call will be treated as SUSPEND and the driver
9842 * will fully reinitialize its device during resume() method call, the device
9843 * will be set to PCI_D0 directly in PCI config space before restoring the
9847 * 0 - driver suspended the device
9851 lpfc_pci_resume_one_s4(struct pci_dev
*pdev
)
9853 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9854 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9858 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9859 "0292 PCI device Power Management resume.\n");
9861 /* Restore device state from PCI config space */
9862 pci_set_power_state(pdev
, PCI_D0
);
9863 pci_restore_state(pdev
);
9866 * As the new kernel behavior of pci_restore_state() API call clears
9867 * device saved_state flag, need to save the restored state again.
9869 pci_save_state(pdev
);
9871 if (pdev
->is_busmaster
)
9872 pci_set_master(pdev
);
9874 /* Startup the kernel thread for this host adapter. */
9875 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
9876 "lpfc_worker_%d", phba
->brd_no
);
9877 if (IS_ERR(phba
->worker_thread
)) {
9878 error
= PTR_ERR(phba
->worker_thread
);
9879 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9880 "0293 PM resume failed to start worker "
9881 "thread: error=x%x.\n", error
);
9885 /* Configure and enable interrupt */
9886 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
9887 if (intr_mode
== LPFC_INTR_ERROR
) {
9888 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9889 "0294 PM resume Failed to enable interrupt\n");
9892 phba
->intr_mode
= intr_mode
;
9894 /* Restart HBA and bring it online */
9895 lpfc_sli_brdrestart(phba
);
9898 /* Log the current active interrupt mode */
9899 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
9905 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
9906 * @phba: pointer to lpfc hba data structure.
9908 * This routine is called to prepare the SLI4 device for PCI slot recover. It
9909 * aborts all the outstanding SCSI I/Os to the pci device.
9912 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba
*phba
)
9914 struct lpfc_sli
*psli
= &phba
->sli
;
9915 struct lpfc_sli_ring
*pring
;
9917 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9918 "2828 PCI channel I/O abort preparing for recovery\n");
9920 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9921 * and let the SCSI mid-layer to retry them to recover.
9923 pring
= &psli
->ring
[psli
->fcp_ring
];
9924 lpfc_sli_abort_iocb_ring(phba
, pring
);
9928 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
9929 * @phba: pointer to lpfc hba data structure.
9931 * This routine is called to prepare the SLI4 device for PCI slot reset. It
9932 * disables the device interrupt and pci device, and aborts the internal FCP
9936 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba
*phba
)
9938 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9939 "2826 PCI channel disable preparing for reset\n");
9941 /* Block any management I/Os to the device */
9942 lpfc_block_mgmt_io(phba
, LPFC_MBX_NO_WAIT
);
9944 /* Block all SCSI devices' I/Os on the host */
9945 lpfc_scsi_dev_block(phba
);
9947 /* stop all timers */
9948 lpfc_stop_hba_timers(phba
);
9950 /* Disable interrupt and pci device */
9951 lpfc_sli4_disable_intr(phba
);
9952 lpfc_sli4_queue_destroy(phba
);
9953 pci_disable_device(phba
->pcidev
);
9955 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9956 lpfc_sli_flush_fcp_rings(phba
);
9960 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
9961 * @phba: pointer to lpfc hba data structure.
9963 * This routine is called to prepare the SLI4 device for PCI slot permanently
9964 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9968 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
9970 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9971 "2827 PCI channel permanent disable for failure\n");
9973 /* Block all SCSI devices' I/Os on the host */
9974 lpfc_scsi_dev_block(phba
);
9976 /* stop all timers */
9977 lpfc_stop_hba_timers(phba
);
9979 /* Clean up all driver's outstanding SCSI I/Os */
9980 lpfc_sli_flush_fcp_rings(phba
);
9984 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
9985 * @pdev: pointer to PCI device.
9986 * @state: the current PCI connection state.
9988 * This routine is called from the PCI subsystem for error handling to device
9989 * with SLI-4 interface spec. This function is called by the PCI subsystem
9990 * after a PCI bus error affecting this device has been detected. When this
9991 * function is invoked, it will need to stop all the I/Os and interrupt(s)
9992 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
9993 * for the PCI subsystem to perform proper recovery as desired.
9996 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9997 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9999 static pci_ers_result_t
10000 lpfc_io_error_detected_s4(struct pci_dev
*pdev
, pci_channel_state_t state
)
10002 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10003 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10006 case pci_channel_io_normal
:
10007 /* Non-fatal error, prepare for recovery */
10008 lpfc_sli4_prep_dev_for_recover(phba
);
10009 return PCI_ERS_RESULT_CAN_RECOVER
;
10010 case pci_channel_io_frozen
:
10011 /* Fatal error, prepare for slot reset */
10012 lpfc_sli4_prep_dev_for_reset(phba
);
10013 return PCI_ERS_RESULT_NEED_RESET
;
10014 case pci_channel_io_perm_failure
:
10015 /* Permanent failure, prepare for device down */
10016 lpfc_sli4_prep_dev_for_perm_failure(phba
);
10017 return PCI_ERS_RESULT_DISCONNECT
;
10019 /* Unknown state, prepare and request slot reset */
10020 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10021 "2825 Unknown PCI error state: x%x\n", state
);
10022 lpfc_sli4_prep_dev_for_reset(phba
);
10023 return PCI_ERS_RESULT_NEED_RESET
;
10028 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
10029 * @pdev: pointer to PCI device.
10031 * This routine is called from the PCI subsystem for error handling to device
10032 * with SLI-4 interface spec. It is called after PCI bus has been reset to
10033 * restart the PCI card from scratch, as if from a cold-boot. During the
10034 * PCI subsystem error recovery, after the driver returns
10035 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10036 * recovery and then call this routine before calling the .resume method to
10037 * recover the device. This function will initialize the HBA device, enable
10038 * the interrupt, but it will just put the HBA to offline state without
10039 * passing any I/O traffic.
10042 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10043 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10045 static pci_ers_result_t
10046 lpfc_io_slot_reset_s4(struct pci_dev
*pdev
)
10048 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10049 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10050 struct lpfc_sli
*psli
= &phba
->sli
;
10051 uint32_t intr_mode
;
10053 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
10054 if (pci_enable_device_mem(pdev
)) {
10055 printk(KERN_ERR
"lpfc: Cannot re-enable "
10056 "PCI device after reset.\n");
10057 return PCI_ERS_RESULT_DISCONNECT
;
10060 pci_restore_state(pdev
);
10063 * As the new kernel behavior of pci_restore_state() API call clears
10064 * device saved_state flag, need to save the restored state again.
10066 pci_save_state(pdev
);
10068 if (pdev
->is_busmaster
)
10069 pci_set_master(pdev
);
10071 spin_lock_irq(&phba
->hbalock
);
10072 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
10073 spin_unlock_irq(&phba
->hbalock
);
10075 /* Configure and enable interrupt */
10076 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
10077 if (intr_mode
== LPFC_INTR_ERROR
) {
10078 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10079 "2824 Cannot re-enable interrupt after "
10081 return PCI_ERS_RESULT_DISCONNECT
;
10083 phba
->intr_mode
= intr_mode
;
10085 /* Log the current active interrupt mode */
10086 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
10088 return PCI_ERS_RESULT_RECOVERED
;
10092 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
10093 * @pdev: pointer to PCI device
10095 * This routine is called from the PCI subsystem for error handling to device
10096 * with SLI-4 interface spec. It is called when kernel error recovery tells
10097 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10098 * error recovery. After this call, traffic can start to flow from this device
10102 lpfc_io_resume_s4(struct pci_dev
*pdev
)
10104 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10105 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10108 * In case of slot reset, as function reset is performed through
10109 * mailbox command which needs DMA to be enabled, this operation
10110 * has to be moved to the io resume phase. Taking device offline
10111 * will perform the necessary cleanup.
10113 if (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)) {
10114 /* Perform device reset */
10115 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
10116 lpfc_offline(phba
);
10117 lpfc_sli_brdrestart(phba
);
10118 /* Bring the device back online */
10122 /* Clean up Advanced Error Reporting (AER) if needed */
10123 if (phba
->hba_flag
& HBA_AER_ENABLED
)
10124 pci_cleanup_aer_uncorrect_error_status(pdev
);
10128 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
10129 * @pdev: pointer to PCI device
10130 * @pid: pointer to PCI device identifier
10132 * This routine is to be registered to the kernel's PCI subsystem. When an
10133 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
10134 * at PCI device-specific information of the device and driver to see if the
10135 * driver state that it can support this kind of device. If the match is
10136 * successful, the driver core invokes this routine. This routine dispatches
10137 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
10138 * do all the initialization that it needs to do to handle the HBA device
10142 * 0 - driver can claim the device
10143 * negative value - driver can not claim the device
10146 lpfc_pci_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
10149 struct lpfc_sli_intf intf
;
10151 if (pci_read_config_dword(pdev
, LPFC_SLI_INTF
, &intf
.word0
))
10154 if ((bf_get(lpfc_sli_intf_valid
, &intf
) == LPFC_SLI_INTF_VALID
) &&
10155 (bf_get(lpfc_sli_intf_slirev
, &intf
) == LPFC_SLI_INTF_REV_SLI4
))
10156 rc
= lpfc_pci_probe_one_s4(pdev
, pid
);
10158 rc
= lpfc_pci_probe_one_s3(pdev
, pid
);
10164 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
10165 * @pdev: pointer to PCI device
10167 * This routine is to be registered to the kernel's PCI subsystem. When an
10168 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
10169 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
10170 * remove routine, which will perform all the necessary cleanup for the
10171 * device to be removed from the PCI subsystem properly.
10174 lpfc_pci_remove_one(struct pci_dev
*pdev
)
10176 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10177 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10179 switch (phba
->pci_dev_grp
) {
10180 case LPFC_PCI_DEV_LP
:
10181 lpfc_pci_remove_one_s3(pdev
);
10183 case LPFC_PCI_DEV_OC
:
10184 lpfc_pci_remove_one_s4(pdev
);
10187 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10188 "1424 Invalid PCI device group: 0x%x\n",
10189 phba
->pci_dev_grp
);
10196 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
10197 * @pdev: pointer to PCI device
10198 * @msg: power management message
10200 * This routine is to be registered to the kernel's PCI subsystem to support
10201 * system Power Management (PM). When PM invokes this method, it dispatches
10202 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
10203 * suspend the device.
10206 * 0 - driver suspended the device
10210 lpfc_pci_suspend_one(struct pci_dev
*pdev
, pm_message_t msg
)
10212 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10213 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10216 switch (phba
->pci_dev_grp
) {
10217 case LPFC_PCI_DEV_LP
:
10218 rc
= lpfc_pci_suspend_one_s3(pdev
, msg
);
10220 case LPFC_PCI_DEV_OC
:
10221 rc
= lpfc_pci_suspend_one_s4(pdev
, msg
);
10224 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10225 "1425 Invalid PCI device group: 0x%x\n",
10226 phba
->pci_dev_grp
);
10233 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
10234 * @pdev: pointer to PCI device
10236 * This routine is to be registered to the kernel's PCI subsystem to support
10237 * system Power Management (PM). When PM invokes this method, it dispatches
10238 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
10239 * resume the device.
10242 * 0 - driver suspended the device
10246 lpfc_pci_resume_one(struct pci_dev
*pdev
)
10248 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10249 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10252 switch (phba
->pci_dev_grp
) {
10253 case LPFC_PCI_DEV_LP
:
10254 rc
= lpfc_pci_resume_one_s3(pdev
);
10256 case LPFC_PCI_DEV_OC
:
10257 rc
= lpfc_pci_resume_one_s4(pdev
);
10260 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10261 "1426 Invalid PCI device group: 0x%x\n",
10262 phba
->pci_dev_grp
);
10269 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
10270 * @pdev: pointer to PCI device.
10271 * @state: the current PCI connection state.
10273 * This routine is registered to the PCI subsystem for error handling. This
10274 * function is called by the PCI subsystem after a PCI bus error affecting
10275 * this device has been detected. When this routine is invoked, it dispatches
10276 * the action to the proper SLI-3 or SLI-4 device error detected handling
10277 * routine, which will perform the proper error detected operation.
10280 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10281 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10283 static pci_ers_result_t
10284 lpfc_io_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
10286 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10287 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10288 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
10290 switch (phba
->pci_dev_grp
) {
10291 case LPFC_PCI_DEV_LP
:
10292 rc
= lpfc_io_error_detected_s3(pdev
, state
);
10294 case LPFC_PCI_DEV_OC
:
10295 rc
= lpfc_io_error_detected_s4(pdev
, state
);
10298 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10299 "1427 Invalid PCI device group: 0x%x\n",
10300 phba
->pci_dev_grp
);
10307 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
10308 * @pdev: pointer to PCI device.
10310 * This routine is registered to the PCI subsystem for error handling. This
10311 * function is called after PCI bus has been reset to restart the PCI card
10312 * from scratch, as if from a cold-boot. When this routine is invoked, it
10313 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
10314 * routine, which will perform the proper device reset.
10317 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10318 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10320 static pci_ers_result_t
10321 lpfc_io_slot_reset(struct pci_dev
*pdev
)
10323 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10324 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10325 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
10327 switch (phba
->pci_dev_grp
) {
10328 case LPFC_PCI_DEV_LP
:
10329 rc
= lpfc_io_slot_reset_s3(pdev
);
10331 case LPFC_PCI_DEV_OC
:
10332 rc
= lpfc_io_slot_reset_s4(pdev
);
10335 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10336 "1428 Invalid PCI device group: 0x%x\n",
10337 phba
->pci_dev_grp
);
10344 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
10345 * @pdev: pointer to PCI device
10347 * This routine is registered to the PCI subsystem for error handling. It
10348 * is called when kernel error recovery tells the lpfc driver that it is
10349 * OK to resume normal PCI operation after PCI bus error recovery. When
10350 * this routine is invoked, it dispatches the action to the proper SLI-3
10351 * or SLI-4 device io_resume routine, which will resume the device operation.
10354 lpfc_io_resume(struct pci_dev
*pdev
)
10356 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10357 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10359 switch (phba
->pci_dev_grp
) {
10360 case LPFC_PCI_DEV_LP
:
10361 lpfc_io_resume_s3(pdev
);
10363 case LPFC_PCI_DEV_OC
:
10364 lpfc_io_resume_s4(pdev
);
10367 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10368 "1429 Invalid PCI device group: 0x%x\n",
10369 phba
->pci_dev_grp
);
10376 * lpfc_mgmt_open - method called when 'lpfcmgmt' is opened from userspace
10377 * @inode: pointer to the inode representing the lpfcmgmt device
10378 * @filep: pointer to the file representing the open lpfcmgmt device
10380 * This routine puts a reference count on the lpfc module whenever the
10381 * character device is opened
10384 lpfc_mgmt_open(struct inode
*inode
, struct file
*filep
)
10386 try_module_get(THIS_MODULE
);
10391 * lpfc_mgmt_release - method called when 'lpfcmgmt' is closed in userspace
10392 * @inode: pointer to the inode representing the lpfcmgmt device
10393 * @filep: pointer to the file representing the open lpfcmgmt device
10395 * This routine removes a reference count from the lpfc module when the
10396 * character device is closed
10399 lpfc_mgmt_release(struct inode
*inode
, struct file
*filep
)
10401 module_put(THIS_MODULE
);
10405 static struct pci_device_id lpfc_id_table
[] = {
10406 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_VIPER
,
10407 PCI_ANY_ID
, PCI_ANY_ID
, },
10408 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_FIREFLY
,
10409 PCI_ANY_ID
, PCI_ANY_ID
, },
10410 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_THOR
,
10411 PCI_ANY_ID
, PCI_ANY_ID
, },
10412 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PEGASUS
,
10413 PCI_ANY_ID
, PCI_ANY_ID
, },
10414 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_CENTAUR
,
10415 PCI_ANY_ID
, PCI_ANY_ID
, },
10416 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_DRAGONFLY
,
10417 PCI_ANY_ID
, PCI_ANY_ID
, },
10418 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SUPERFLY
,
10419 PCI_ANY_ID
, PCI_ANY_ID
, },
10420 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_RFLY
,
10421 PCI_ANY_ID
, PCI_ANY_ID
, },
10422 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PFLY
,
10423 PCI_ANY_ID
, PCI_ANY_ID
, },
10424 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE
,
10425 PCI_ANY_ID
, PCI_ANY_ID
, },
10426 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_SCSP
,
10427 PCI_ANY_ID
, PCI_ANY_ID
, },
10428 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_DCSP
,
10429 PCI_ANY_ID
, PCI_ANY_ID
, },
10430 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS
,
10431 PCI_ANY_ID
, PCI_ANY_ID
, },
10432 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_SCSP
,
10433 PCI_ANY_ID
, PCI_ANY_ID
, },
10434 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_DCSP
,
10435 PCI_ANY_ID
, PCI_ANY_ID
, },
10436 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BMID
,
10437 PCI_ANY_ID
, PCI_ANY_ID
, },
10438 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BSMB
,
10439 PCI_ANY_ID
, PCI_ANY_ID
, },
10440 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR
,
10441 PCI_ANY_ID
, PCI_ANY_ID
, },
10442 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HORNET
,
10443 PCI_ANY_ID
, PCI_ANY_ID
, },
10444 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_SCSP
,
10445 PCI_ANY_ID
, PCI_ANY_ID
, },
10446 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_DCSP
,
10447 PCI_ANY_ID
, PCI_ANY_ID
, },
10448 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZMID
,
10449 PCI_ANY_ID
, PCI_ANY_ID
, },
10450 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZSMB
,
10451 PCI_ANY_ID
, PCI_ANY_ID
, },
10452 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_TFLY
,
10453 PCI_ANY_ID
, PCI_ANY_ID
, },
10454 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP101
,
10455 PCI_ANY_ID
, PCI_ANY_ID
, },
10456 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP10000S
,
10457 PCI_ANY_ID
, PCI_ANY_ID
, },
10458 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP11000S
,
10459 PCI_ANY_ID
, PCI_ANY_ID
, },
10460 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LPE11000S
,
10461 PCI_ANY_ID
, PCI_ANY_ID
, },
10462 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT
,
10463 PCI_ANY_ID
, PCI_ANY_ID
, },
10464 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_MID
,
10465 PCI_ANY_ID
, PCI_ANY_ID
, },
10466 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SMB
,
10467 PCI_ANY_ID
, PCI_ANY_ID
, },
10468 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_DCSP
,
10469 PCI_ANY_ID
, PCI_ANY_ID
, },
10470 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SCSP
,
10471 PCI_ANY_ID
, PCI_ANY_ID
, },
10472 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_S
,
10473 PCI_ANY_ID
, PCI_ANY_ID
, },
10474 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_VF
,
10475 PCI_ANY_ID
, PCI_ANY_ID
, },
10476 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_PF
,
10477 PCI_ANY_ID
, PCI_ANY_ID
, },
10478 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_S
,
10479 PCI_ANY_ID
, PCI_ANY_ID
, },
10480 {PCI_VENDOR_ID_SERVERENGINE
, PCI_DEVICE_ID_TIGERSHARK
,
10481 PCI_ANY_ID
, PCI_ANY_ID
, },
10482 {PCI_VENDOR_ID_SERVERENGINE
, PCI_DEVICE_ID_TOMCAT
,
10483 PCI_ANY_ID
, PCI_ANY_ID
, },
10484 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_FALCON
,
10485 PCI_ANY_ID
, PCI_ANY_ID
, },
10486 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BALIUS
,
10487 PCI_ANY_ID
, PCI_ANY_ID
, },
10488 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FC
,
10489 PCI_ANY_ID
, PCI_ANY_ID
, },
10490 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FCOE
,
10491 PCI_ANY_ID
, PCI_ANY_ID
, },
10492 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FC_VF
,
10493 PCI_ANY_ID
, PCI_ANY_ID
, },
10494 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FCOE_VF
,
10495 PCI_ANY_ID
, PCI_ANY_ID
, },
10496 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SKYHAWK
,
10497 PCI_ANY_ID
, PCI_ANY_ID
, },
10498 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SKYHAWK_VF
,
10499 PCI_ANY_ID
, PCI_ANY_ID
, },
10503 MODULE_DEVICE_TABLE(pci
, lpfc_id_table
);
10505 static const struct pci_error_handlers lpfc_err_handler
= {
10506 .error_detected
= lpfc_io_error_detected
,
10507 .slot_reset
= lpfc_io_slot_reset
,
10508 .resume
= lpfc_io_resume
,
10511 static struct pci_driver lpfc_driver
= {
10512 .name
= LPFC_DRIVER_NAME
,
10513 .id_table
= lpfc_id_table
,
10514 .probe
= lpfc_pci_probe_one
,
10515 .remove
= lpfc_pci_remove_one
,
10516 .suspend
= lpfc_pci_suspend_one
,
10517 .resume
= lpfc_pci_resume_one
,
10518 .err_handler
= &lpfc_err_handler
,
10521 static const struct file_operations lpfc_mgmt_fop
= {
10522 .open
= lpfc_mgmt_open
,
10523 .release
= lpfc_mgmt_release
,
10526 static struct miscdevice lpfc_mgmt_dev
= {
10527 .minor
= MISC_DYNAMIC_MINOR
,
10528 .name
= "lpfcmgmt",
10529 .fops
= &lpfc_mgmt_fop
,
10533 * lpfc_init - lpfc module initialization routine
10535 * This routine is to be invoked when the lpfc module is loaded into the
10536 * kernel. The special kernel macro module_init() is used to indicate the
10537 * role of this routine to the kernel as lpfc module entry point.
10541 * -ENOMEM - FC attach transport failed
10542 * all others - failed
10549 printk(LPFC_MODULE_DESC
"\n");
10550 printk(LPFC_COPYRIGHT
"\n");
10552 error
= misc_register(&lpfc_mgmt_dev
);
10554 printk(KERN_ERR
"Could not register lpfcmgmt device, "
10555 "misc_register returned with status %d", error
);
10557 if (lpfc_enable_npiv
) {
10558 lpfc_transport_functions
.vport_create
= lpfc_vport_create
;
10559 lpfc_transport_functions
.vport_delete
= lpfc_vport_delete
;
10561 lpfc_transport_template
=
10562 fc_attach_transport(&lpfc_transport_functions
);
10563 if (lpfc_transport_template
== NULL
)
10565 if (lpfc_enable_npiv
) {
10566 lpfc_vport_transport_template
=
10567 fc_attach_transport(&lpfc_vport_transport_functions
);
10568 if (lpfc_vport_transport_template
== NULL
) {
10569 fc_release_transport(lpfc_transport_template
);
10573 error
= pci_register_driver(&lpfc_driver
);
10575 fc_release_transport(lpfc_transport_template
);
10576 if (lpfc_enable_npiv
)
10577 fc_release_transport(lpfc_vport_transport_template
);
10584 * lpfc_exit - lpfc module removal routine
10586 * This routine is invoked when the lpfc module is removed from the kernel.
10587 * The special kernel macro module_exit() is used to indicate the role of
10588 * this routine to the kernel as lpfc module exit point.
10593 misc_deregister(&lpfc_mgmt_dev
);
10594 pci_unregister_driver(&lpfc_driver
);
10595 fc_release_transport(lpfc_transport_template
);
10596 if (lpfc_enable_npiv
)
10597 fc_release_transport(lpfc_vport_transport_template
);
10598 if (_dump_buf_data
) {
10599 printk(KERN_ERR
"9062 BLKGRD: freeing %lu pages for "
10600 "_dump_buf_data at 0x%p\n",
10601 (1L << _dump_buf_data_order
), _dump_buf_data
);
10602 free_pages((unsigned long)_dump_buf_data
, _dump_buf_data_order
);
10605 if (_dump_buf_dif
) {
10606 printk(KERN_ERR
"9049 BLKGRD: freeing %lu pages for "
10607 "_dump_buf_dif at 0x%p\n",
10608 (1L << _dump_buf_dif_order
), _dump_buf_dif
);
10609 free_pages((unsigned long)_dump_buf_dif
, _dump_buf_dif_order
);
10613 module_init(lpfc_init
);
10614 module_exit(lpfc_exit
);
10615 MODULE_LICENSE("GPL");
10616 MODULE_DESCRIPTION(LPFC_MODULE_DESC
);
10617 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
10618 MODULE_VERSION("0:" LPFC_DRIVER_VERSION
);