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>
36 #include <linux/percpu.h>
38 #include <scsi/scsi.h>
39 #include <scsi/scsi_device.h>
40 #include <scsi/scsi_host.h>
41 #include <scsi/scsi_transport_fc.h>
46 #include "lpfc_sli4.h"
48 #include "lpfc_disc.h"
49 #include "lpfc_scsi.h"
51 #include "lpfc_logmsg.h"
52 #include "lpfc_crtn.h"
53 #include "lpfc_vport.h"
54 #include "lpfc_version.h"
57 unsigned long _dump_buf_data_order
;
59 unsigned long _dump_buf_dif_order
;
60 spinlock_t _dump_buf_lock
;
62 /* Used when mapping IRQ vectors in a driver centric manner */
63 uint16_t *lpfc_used_cpu
;
64 uint32_t lpfc_present_cpu
;
66 static void lpfc_get_hba_model_desc(struct lpfc_hba
*, uint8_t *, uint8_t *);
67 static int lpfc_post_rcv_buf(struct lpfc_hba
*);
68 static int lpfc_sli4_queue_verify(struct lpfc_hba
*);
69 static int lpfc_create_bootstrap_mbox(struct lpfc_hba
*);
70 static int lpfc_setup_endian_order(struct lpfc_hba
*);
71 static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*);
72 static void lpfc_free_els_sgl_list(struct lpfc_hba
*);
73 static void lpfc_init_sgl_list(struct lpfc_hba
*);
74 static int lpfc_init_active_sgl_array(struct lpfc_hba
*);
75 static void lpfc_free_active_sgl(struct lpfc_hba
*);
76 static int lpfc_hba_down_post_s3(struct lpfc_hba
*phba
);
77 static int lpfc_hba_down_post_s4(struct lpfc_hba
*phba
);
78 static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*);
79 static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*);
80 static void lpfc_sli4_cq_event_release_all(struct lpfc_hba
*);
81 static void lpfc_sli4_disable_intr(struct lpfc_hba
*);
82 static uint32_t lpfc_sli4_enable_intr(struct lpfc_hba
*, uint32_t);
84 static struct scsi_transport_template
*lpfc_transport_template
= NULL
;
85 static struct scsi_transport_template
*lpfc_vport_transport_template
= NULL
;
86 static DEFINE_IDR(lpfc_hba_index
);
89 * lpfc_config_port_prep - Perform lpfc initialization prior to config port
90 * @phba: pointer to lpfc hba data structure.
92 * This routine will do LPFC initialization prior to issuing the CONFIG_PORT
93 * mailbox command. It retrieves the revision information from the HBA and
94 * collects the Vital Product Data (VPD) about the HBA for preparing the
95 * configuration of the HBA.
99 * -ERESTART - requests the SLI layer to reset the HBA and try again.
100 * Any other value - indicates an error.
103 lpfc_config_port_prep(struct lpfc_hba
*phba
)
105 lpfc_vpd_t
*vp
= &phba
->vpd
;
109 char *lpfc_vpd_data
= NULL
;
111 static char licensed
[56] =
112 "key unlock for use with gnu public licensed code only\0";
113 static int init_key
= 1;
115 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
117 phba
->link_state
= LPFC_HBA_ERROR
;
122 phba
->link_state
= LPFC_INIT_MBX_CMDS
;
124 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
126 uint32_t *ptext
= (uint32_t *) licensed
;
128 for (i
= 0; i
< 56; i
+= sizeof (uint32_t), ptext
++)
129 *ptext
= cpu_to_be32(*ptext
);
133 lpfc_read_nv(phba
, pmb
);
134 memset((char*)mb
->un
.varRDnvp
.rsvd3
, 0,
135 sizeof (mb
->un
.varRDnvp
.rsvd3
));
136 memcpy((char*)mb
->un
.varRDnvp
.rsvd3
, licensed
,
139 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
141 if (rc
!= MBX_SUCCESS
) {
142 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
143 "0324 Config Port initialization "
144 "error, mbxCmd x%x READ_NVPARM, "
146 mb
->mbxCommand
, mb
->mbxStatus
);
147 mempool_free(pmb
, phba
->mbox_mem_pool
);
150 memcpy(phba
->wwnn
, (char *)mb
->un
.varRDnvp
.nodename
,
152 memcpy(phba
->wwpn
, (char *)mb
->un
.varRDnvp
.portname
,
156 phba
->sli3_options
= 0x0;
158 /* Setup and issue mailbox READ REV command */
159 lpfc_read_rev(phba
, pmb
);
160 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
161 if (rc
!= MBX_SUCCESS
) {
162 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
163 "0439 Adapter failed to init, mbxCmd x%x "
164 "READ_REV, mbxStatus x%x\n",
165 mb
->mbxCommand
, mb
->mbxStatus
);
166 mempool_free( pmb
, phba
->mbox_mem_pool
);
172 * The value of rr must be 1 since the driver set the cv field to 1.
173 * This setting requires the FW to set all revision fields.
175 if (mb
->un
.varRdRev
.rr
== 0) {
177 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
178 "0440 Adapter failed to init, READ_REV has "
179 "missing revision information.\n");
180 mempool_free(pmb
, phba
->mbox_mem_pool
);
184 if (phba
->sli_rev
== 3 && !mb
->un
.varRdRev
.v3rsp
) {
185 mempool_free(pmb
, phba
->mbox_mem_pool
);
189 /* Save information as VPD data */
191 memcpy(&vp
->sli3Feat
, &mb
->un
.varRdRev
.sli3Feat
, sizeof(uint32_t));
192 vp
->rev
.sli1FwRev
= mb
->un
.varRdRev
.sli1FwRev
;
193 memcpy(vp
->rev
.sli1FwName
, (char*) mb
->un
.varRdRev
.sli1FwName
, 16);
194 vp
->rev
.sli2FwRev
= mb
->un
.varRdRev
.sli2FwRev
;
195 memcpy(vp
->rev
.sli2FwName
, (char *) mb
->un
.varRdRev
.sli2FwName
, 16);
196 vp
->rev
.biuRev
= mb
->un
.varRdRev
.biuRev
;
197 vp
->rev
.smRev
= mb
->un
.varRdRev
.smRev
;
198 vp
->rev
.smFwRev
= mb
->un
.varRdRev
.un
.smFwRev
;
199 vp
->rev
.endecRev
= mb
->un
.varRdRev
.endecRev
;
200 vp
->rev
.fcphHigh
= mb
->un
.varRdRev
.fcphHigh
;
201 vp
->rev
.fcphLow
= mb
->un
.varRdRev
.fcphLow
;
202 vp
->rev
.feaLevelHigh
= mb
->un
.varRdRev
.feaLevelHigh
;
203 vp
->rev
.feaLevelLow
= mb
->un
.varRdRev
.feaLevelLow
;
204 vp
->rev
.postKernRev
= mb
->un
.varRdRev
.postKernRev
;
205 vp
->rev
.opFwRev
= mb
->un
.varRdRev
.opFwRev
;
207 /* If the sli feature level is less then 9, we must
208 * tear down all RPIs and VPIs on link down if NPIV
211 if (vp
->rev
.feaLevelHigh
< 9)
212 phba
->sli3_options
|= LPFC_SLI3_VPORT_TEARDOWN
;
214 if (lpfc_is_LC_HBA(phba
->pcidev
->device
))
215 memcpy(phba
->RandomData
, (char *)&mb
->un
.varWords
[24],
216 sizeof (phba
->RandomData
));
218 /* Get adapter VPD information */
219 lpfc_vpd_data
= kmalloc(DMP_VPD_SIZE
, GFP_KERNEL
);
223 lpfc_dump_mem(phba
, pmb
, offset
, DMP_REGION_VPD
);
224 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
226 if (rc
!= MBX_SUCCESS
) {
227 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
228 "0441 VPD not present on adapter, "
229 "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
230 mb
->mbxCommand
, mb
->mbxStatus
);
231 mb
->un
.varDmp
.word_cnt
= 0;
233 /* dump mem may return a zero when finished or we got a
234 * mailbox error, either way we are done.
236 if (mb
->un
.varDmp
.word_cnt
== 0)
238 if (mb
->un
.varDmp
.word_cnt
> DMP_VPD_SIZE
- offset
)
239 mb
->un
.varDmp
.word_cnt
= DMP_VPD_SIZE
- offset
;
240 lpfc_sli_pcimem_bcopy(((uint8_t *)mb
) + DMP_RSP_OFFSET
,
241 lpfc_vpd_data
+ offset
,
242 mb
->un
.varDmp
.word_cnt
);
243 offset
+= mb
->un
.varDmp
.word_cnt
;
244 } while (mb
->un
.varDmp
.word_cnt
&& offset
< DMP_VPD_SIZE
);
245 lpfc_parse_vpd(phba
, lpfc_vpd_data
, offset
);
247 kfree(lpfc_vpd_data
);
249 mempool_free(pmb
, phba
->mbox_mem_pool
);
254 * lpfc_config_async_cmpl - Completion handler for config async event mbox cmd
255 * @phba: pointer to lpfc hba data structure.
256 * @pmboxq: pointer to the driver internal queue element for mailbox command.
258 * This is the completion handler for driver's configuring asynchronous event
259 * mailbox command to the device. If the mailbox command returns successfully,
260 * it will set internal async event support flag to 1; otherwise, it will
261 * set internal async event support flag to 0.
264 lpfc_config_async_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
266 if (pmboxq
->u
.mb
.mbxStatus
== MBX_SUCCESS
)
267 phba
->temp_sensor_support
= 1;
269 phba
->temp_sensor_support
= 0;
270 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
275 * lpfc_dump_wakeup_param_cmpl - dump memory mailbox command completion handler
276 * @phba: pointer to lpfc hba data structure.
277 * @pmboxq: pointer to the driver internal queue element for mailbox command.
279 * This is the completion handler for dump mailbox command for getting
280 * wake up parameters. When this command complete, the response contain
281 * Option rom version of the HBA. This function translate the version number
282 * into a human readable string and store it in OptionROMVersion.
285 lpfc_dump_wakeup_param_cmpl(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmboxq
)
288 uint32_t prog_id_word
;
290 /* character array used for decoding dist type. */
291 char dist_char
[] = "nabx";
293 if (pmboxq
->u
.mb
.mbxStatus
!= MBX_SUCCESS
) {
294 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
298 prg
= (struct prog_id
*) &prog_id_word
;
300 /* word 7 contain option rom version */
301 prog_id_word
= pmboxq
->u
.mb
.un
.varWords
[7];
303 /* Decode the Option rom version word to a readable string */
305 dist
= dist_char
[prg
->dist
];
307 if ((prg
->dist
== 3) && (prg
->num
== 0))
308 sprintf(phba
->OptionROMVersion
, "%d.%d%d",
309 prg
->ver
, prg
->rev
, prg
->lev
);
311 sprintf(phba
->OptionROMVersion
, "%d.%d%d%c%d",
312 prg
->ver
, prg
->rev
, prg
->lev
,
314 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
319 * lpfc_update_vport_wwn - Updates the fc_nodename, fc_portname,
320 * cfg_soft_wwnn, cfg_soft_wwpn
321 * @vport: pointer to lpfc vport data structure.
328 lpfc_update_vport_wwn(struct lpfc_vport
*vport
)
330 /* If the soft name exists then update it using the service params */
331 if (vport
->phba
->cfg_soft_wwnn
)
332 u64_to_wwn(vport
->phba
->cfg_soft_wwnn
,
333 vport
->fc_sparam
.nodeName
.u
.wwn
);
334 if (vport
->phba
->cfg_soft_wwpn
)
335 u64_to_wwn(vport
->phba
->cfg_soft_wwpn
,
336 vport
->fc_sparam
.portName
.u
.wwn
);
339 * If the name is empty or there exists a soft name
340 * then copy the service params name, otherwise use the fc name
342 if (vport
->fc_nodename
.u
.wwn
[0] == 0 || vport
->phba
->cfg_soft_wwnn
)
343 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
344 sizeof(struct lpfc_name
));
346 memcpy(&vport
->fc_sparam
.nodeName
, &vport
->fc_nodename
,
347 sizeof(struct lpfc_name
));
349 if (vport
->fc_portname
.u
.wwn
[0] == 0 || vport
->phba
->cfg_soft_wwpn
)
350 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
351 sizeof(struct lpfc_name
));
353 memcpy(&vport
->fc_sparam
.portName
, &vport
->fc_portname
,
354 sizeof(struct lpfc_name
));
358 * lpfc_config_port_post - Perform lpfc initialization after config port
359 * @phba: pointer to lpfc hba data structure.
361 * This routine will do LPFC initialization after the CONFIG_PORT mailbox
362 * command call. It performs all internal resource and state setups on the
363 * port: post IOCB buffers, enable appropriate host interrupt attentions,
364 * ELS ring timers, etc.
368 * Any other value - error.
371 lpfc_config_port_post(struct lpfc_hba
*phba
)
373 struct lpfc_vport
*vport
= phba
->pport
;
374 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
377 struct lpfc_dmabuf
*mp
;
378 struct lpfc_sli
*psli
= &phba
->sli
;
379 uint32_t status
, timeout
;
383 spin_lock_irq(&phba
->hbalock
);
385 * If the Config port completed correctly the HBA is not
386 * over heated any more.
388 if (phba
->over_temp_state
== HBA_OVER_TEMP
)
389 phba
->over_temp_state
= HBA_NORMAL_TEMP
;
390 spin_unlock_irq(&phba
->hbalock
);
392 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
394 phba
->link_state
= LPFC_HBA_ERROR
;
399 /* Get login parameters for NID. */
400 rc
= lpfc_read_sparam(phba
, pmb
, 0);
402 mempool_free(pmb
, phba
->mbox_mem_pool
);
407 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
408 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
409 "0448 Adapter failed init, mbxCmd x%x "
410 "READ_SPARM mbxStatus x%x\n",
411 mb
->mbxCommand
, mb
->mbxStatus
);
412 phba
->link_state
= LPFC_HBA_ERROR
;
413 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
414 mempool_free(pmb
, phba
->mbox_mem_pool
);
415 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
420 mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
422 memcpy(&vport
->fc_sparam
, mp
->virt
, sizeof (struct serv_parm
));
423 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
425 pmb
->context1
= NULL
;
426 lpfc_update_vport_wwn(vport
);
428 /* Update the fc_host data structures with new wwn. */
429 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
430 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
431 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
433 /* If no serial number in VPD data, use low 6 bytes of WWNN */
434 /* This should be consolidated into parse_vpd ? - mr */
435 if (phba
->SerialNumber
[0] == 0) {
438 outptr
= &vport
->fc_nodename
.u
.s
.IEEE
[0];
439 for (i
= 0; i
< 12; i
++) {
441 j
= ((status
& 0xf0) >> 4);
443 phba
->SerialNumber
[i
] =
444 (char)((uint8_t) 0x30 + (uint8_t) j
);
446 phba
->SerialNumber
[i
] =
447 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
451 phba
->SerialNumber
[i
] =
452 (char)((uint8_t) 0x30 + (uint8_t) j
);
454 phba
->SerialNumber
[i
] =
455 (char)((uint8_t) 0x61 + (uint8_t) (j
- 10));
459 lpfc_read_config(phba
, pmb
);
461 if (lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
) != MBX_SUCCESS
) {
462 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
463 "0453 Adapter failed to init, mbxCmd x%x "
464 "READ_CONFIG, mbxStatus x%x\n",
465 mb
->mbxCommand
, mb
->mbxStatus
);
466 phba
->link_state
= LPFC_HBA_ERROR
;
467 mempool_free( pmb
, phba
->mbox_mem_pool
);
471 /* Check if the port is disabled */
472 lpfc_sli_read_link_ste(phba
);
474 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
475 if (phba
->cfg_hba_queue_depth
> (mb
->un
.varRdConfig
.max_xri
+1))
476 phba
->cfg_hba_queue_depth
=
477 (mb
->un
.varRdConfig
.max_xri
+ 1) -
478 lpfc_sli4_get_els_iocb_cnt(phba
);
480 phba
->lmt
= mb
->un
.varRdConfig
.lmt
;
482 /* Get the default values for Model Name and Description */
483 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
485 phba
->link_state
= LPFC_LINK_DOWN
;
487 /* Only process IOCBs on ELS ring till hba_state is READY */
488 if (psli
->ring
[psli
->extra_ring
].sli
.sli3
.cmdringaddr
)
489 psli
->ring
[psli
->extra_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
490 if (psli
->ring
[psli
->fcp_ring
].sli
.sli3
.cmdringaddr
)
491 psli
->ring
[psli
->fcp_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
492 if (psli
->ring
[psli
->next_ring
].sli
.sli3
.cmdringaddr
)
493 psli
->ring
[psli
->next_ring
].flag
|= LPFC_STOP_IOCB_EVENT
;
495 /* Post receive buffers for desired rings */
496 if (phba
->sli_rev
!= 3)
497 lpfc_post_rcv_buf(phba
);
500 * Configure HBA MSI-X attention conditions to messages if MSI-X mode
502 if (phba
->intr_type
== MSIX
) {
503 rc
= lpfc_config_msi(phba
, pmb
);
505 mempool_free(pmb
, phba
->mbox_mem_pool
);
508 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
509 if (rc
!= MBX_SUCCESS
) {
510 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
511 "0352 Config MSI mailbox command "
512 "failed, mbxCmd x%x, mbxStatus x%x\n",
513 pmb
->u
.mb
.mbxCommand
,
514 pmb
->u
.mb
.mbxStatus
);
515 mempool_free(pmb
, phba
->mbox_mem_pool
);
520 spin_lock_irq(&phba
->hbalock
);
521 /* Initialize ERATT handling flag */
522 phba
->hba_flag
&= ~HBA_ERATT_HANDLED
;
524 /* Enable appropriate host interrupts */
525 if (lpfc_readl(phba
->HCregaddr
, &status
)) {
526 spin_unlock_irq(&phba
->hbalock
);
529 status
|= HC_MBINT_ENA
| HC_ERINT_ENA
| HC_LAINT_ENA
;
530 if (psli
->num_rings
> 0)
531 status
|= HC_R0INT_ENA
;
532 if (psli
->num_rings
> 1)
533 status
|= HC_R1INT_ENA
;
534 if (psli
->num_rings
> 2)
535 status
|= HC_R2INT_ENA
;
536 if (psli
->num_rings
> 3)
537 status
|= HC_R3INT_ENA
;
539 if ((phba
->cfg_poll
& ENABLE_FCP_RING_POLLING
) &&
540 (phba
->cfg_poll
& DISABLE_FCP_RING_INT
))
541 status
&= ~(HC_R0INT_ENA
);
543 writel(status
, phba
->HCregaddr
);
544 readl(phba
->HCregaddr
); /* flush */
545 spin_unlock_irq(&phba
->hbalock
);
547 /* Set up ring-0 (ELS) timer */
548 timeout
= phba
->fc_ratov
* 2;
549 mod_timer(&vport
->els_tmofunc
,
550 jiffies
+ msecs_to_jiffies(1000 * timeout
));
551 /* Set up heart beat (HB) timer */
552 mod_timer(&phba
->hb_tmofunc
,
553 jiffies
+ msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
554 phba
->hb_outstanding
= 0;
555 phba
->last_completion_time
= jiffies
;
556 /* Set up error attention (ERATT) polling timer */
557 mod_timer(&phba
->eratt_poll
,
558 jiffies
+ msecs_to_jiffies(1000 * LPFC_ERATT_POLL_INTERVAL
));
560 if (phba
->hba_flag
& LINK_DISABLED
) {
561 lpfc_printf_log(phba
,
563 "2598 Adapter Link is disabled.\n");
564 lpfc_down_link(phba
, pmb
);
565 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
566 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
567 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
568 lpfc_printf_log(phba
,
570 "2599 Adapter failed to issue DOWN_LINK"
571 " mbox command rc 0x%x\n", rc
);
573 mempool_free(pmb
, phba
->mbox_mem_pool
);
576 } else if (phba
->cfg_suppress_link_up
== LPFC_INITIALIZE_LINK
) {
577 mempool_free(pmb
, phba
->mbox_mem_pool
);
578 rc
= phba
->lpfc_hba_init_link(phba
, MBX_NOWAIT
);
582 /* MBOX buffer will be freed in mbox compl */
583 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
585 phba
->link_state
= LPFC_HBA_ERROR
;
589 lpfc_config_async(phba
, pmb
, LPFC_ELS_RING
);
590 pmb
->mbox_cmpl
= lpfc_config_async_cmpl
;
591 pmb
->vport
= phba
->pport
;
592 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
594 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
595 lpfc_printf_log(phba
,
598 "0456 Adapter failed to issue "
599 "ASYNCEVT_ENABLE mbox status x%x\n",
601 mempool_free(pmb
, phba
->mbox_mem_pool
);
604 /* Get Option rom version */
605 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
607 phba
->link_state
= LPFC_HBA_ERROR
;
611 lpfc_dump_wakeup_param(phba
, pmb
);
612 pmb
->mbox_cmpl
= lpfc_dump_wakeup_param_cmpl
;
613 pmb
->vport
= phba
->pport
;
614 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
616 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
617 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
, "0435 Adapter failed "
618 "to get Option ROM version status x%x\n", rc
);
619 mempool_free(pmb
, phba
->mbox_mem_pool
);
626 * lpfc_hba_init_link - Initialize the FC link
627 * @phba: pointer to lpfc hba data structure.
628 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
630 * This routine will issue the INIT_LINK mailbox command call.
631 * It is available to other drivers through the lpfc_hba data
632 * structure for use as a delayed link up mechanism with the
633 * module parameter lpfc_suppress_link_up.
637 * Any other value - error
640 lpfc_hba_init_link(struct lpfc_hba
*phba
, uint32_t flag
)
642 return lpfc_hba_init_link_fc_topology(phba
, phba
->cfg_topology
, flag
);
646 * lpfc_hba_init_link_fc_topology - Initialize FC link with desired topology
647 * @phba: pointer to lpfc hba data structure.
648 * @fc_topology: desired fc topology.
649 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
651 * This routine will issue the INIT_LINK mailbox command call.
652 * It is available to other drivers through the lpfc_hba data
653 * structure for use as a delayed link up mechanism with the
654 * module parameter lpfc_suppress_link_up.
658 * Any other value - error
661 lpfc_hba_init_link_fc_topology(struct lpfc_hba
*phba
, uint32_t fc_topology
,
664 struct lpfc_vport
*vport
= phba
->pport
;
669 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
671 phba
->link_state
= LPFC_HBA_ERROR
;
677 if ((phba
->cfg_link_speed
> LPFC_USER_LINK_SPEED_MAX
) ||
678 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_1G
) &&
679 !(phba
->lmt
& LMT_1Gb
)) ||
680 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_2G
) &&
681 !(phba
->lmt
& LMT_2Gb
)) ||
682 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_4G
) &&
683 !(phba
->lmt
& LMT_4Gb
)) ||
684 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_8G
) &&
685 !(phba
->lmt
& LMT_8Gb
)) ||
686 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_10G
) &&
687 !(phba
->lmt
& LMT_10Gb
)) ||
688 ((phba
->cfg_link_speed
== LPFC_USER_LINK_SPEED_16G
) &&
689 !(phba
->lmt
& LMT_16Gb
))) {
690 /* Reset link speed to auto */
691 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
692 "1302 Invalid speed for this board:%d "
693 "Reset link speed to auto.\n",
694 phba
->cfg_link_speed
);
695 phba
->cfg_link_speed
= LPFC_USER_LINK_SPEED_AUTO
;
697 lpfc_init_link(phba
, pmb
, fc_topology
, phba
->cfg_link_speed
);
698 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
699 if (phba
->sli_rev
< LPFC_SLI_REV4
)
700 lpfc_set_loopback_flag(phba
);
701 rc
= lpfc_sli_issue_mbox(phba
, pmb
, flag
);
702 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
703 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
704 "0498 Adapter failed to init, mbxCmd x%x "
705 "INIT_LINK, mbxStatus x%x\n",
706 mb
->mbxCommand
, mb
->mbxStatus
);
707 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
708 /* Clear all interrupt enable conditions */
709 writel(0, phba
->HCregaddr
);
710 readl(phba
->HCregaddr
); /* flush */
711 /* Clear all pending interrupts */
712 writel(0xffffffff, phba
->HAregaddr
);
713 readl(phba
->HAregaddr
); /* flush */
715 phba
->link_state
= LPFC_HBA_ERROR
;
716 if (rc
!= MBX_BUSY
|| flag
== MBX_POLL
)
717 mempool_free(pmb
, phba
->mbox_mem_pool
);
720 phba
->cfg_suppress_link_up
= LPFC_INITIALIZE_LINK
;
721 if (flag
== MBX_POLL
)
722 mempool_free(pmb
, phba
->mbox_mem_pool
);
728 * lpfc_hba_down_link - this routine downs the FC link
729 * @phba: pointer to lpfc hba data structure.
730 * @flag: mailbox command issue mode - either MBX_POLL or MBX_NOWAIT
732 * This routine will issue the DOWN_LINK mailbox command call.
733 * It is available to other drivers through the lpfc_hba data
734 * structure for use to stop the link.
738 * Any other value - error
741 lpfc_hba_down_link(struct lpfc_hba
*phba
, uint32_t flag
)
746 pmb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
748 phba
->link_state
= LPFC_HBA_ERROR
;
752 lpfc_printf_log(phba
,
754 "0491 Adapter Link is disabled.\n");
755 lpfc_down_link(phba
, pmb
);
756 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
757 rc
= lpfc_sli_issue_mbox(phba
, pmb
, flag
);
758 if ((rc
!= MBX_SUCCESS
) && (rc
!= MBX_BUSY
)) {
759 lpfc_printf_log(phba
,
761 "2522 Adapter failed to issue DOWN_LINK"
762 " mbox command rc 0x%x\n", rc
);
764 mempool_free(pmb
, phba
->mbox_mem_pool
);
767 if (flag
== MBX_POLL
)
768 mempool_free(pmb
, phba
->mbox_mem_pool
);
774 * lpfc_hba_down_prep - Perform lpfc uninitialization prior to HBA reset
775 * @phba: pointer to lpfc HBA data structure.
777 * This routine will do LPFC uninitialization before the HBA is reset when
778 * bringing down the SLI Layer.
782 * Any other value - error.
785 lpfc_hba_down_prep(struct lpfc_hba
*phba
)
787 struct lpfc_vport
**vports
;
790 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
791 /* Disable interrupts */
792 writel(0, phba
->HCregaddr
);
793 readl(phba
->HCregaddr
); /* flush */
796 if (phba
->pport
->load_flag
& FC_UNLOADING
)
797 lpfc_cleanup_discovery_resources(phba
->pport
);
799 vports
= lpfc_create_vport_work_array(phba
);
801 for (i
= 0; i
<= phba
->max_vports
&&
802 vports
[i
] != NULL
; i
++)
803 lpfc_cleanup_discovery_resources(vports
[i
]);
804 lpfc_destroy_vport_work_array(phba
, vports
);
810 * lpfc_hba_down_post_s3 - Perform lpfc uninitialization after HBA reset
811 * @phba: pointer to lpfc HBA data structure.
813 * This routine will do uninitialization after the HBA is reset when bring
814 * down the SLI Layer.
818 * Any other value - error.
821 lpfc_hba_down_post_s3(struct lpfc_hba
*phba
)
823 struct lpfc_sli
*psli
= &phba
->sli
;
824 struct lpfc_sli_ring
*pring
;
825 struct lpfc_dmabuf
*mp
, *next_mp
;
826 LIST_HEAD(completions
);
829 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
)
830 lpfc_sli_hbqbuf_free_all(phba
);
832 /* Cleanup preposted buffers on the ELS ring */
833 pring
= &psli
->ring
[LPFC_ELS_RING
];
834 list_for_each_entry_safe(mp
, next_mp
, &pring
->postbufq
, list
) {
836 pring
->postbufq_cnt
--;
837 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
842 spin_lock_irq(&phba
->hbalock
);
843 for (i
= 0; i
< psli
->num_rings
; i
++) {
844 pring
= &psli
->ring
[i
];
846 /* At this point in time the HBA is either reset or DOA. Either
847 * way, nothing should be on txcmplq as it will NEVER complete.
849 list_splice_init(&pring
->txcmplq
, &completions
);
850 spin_unlock_irq(&phba
->hbalock
);
852 /* Cancel all the IOCBs from the completions list */
853 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
856 lpfc_sli_abort_iocb_ring(phba
, pring
);
857 spin_lock_irq(&phba
->hbalock
);
859 spin_unlock_irq(&phba
->hbalock
);
865 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
866 * @phba: pointer to lpfc HBA data structure.
868 * This routine will do uninitialization after the HBA is reset when bring
869 * down the SLI Layer.
873 * Any other value - error.
876 lpfc_hba_down_post_s4(struct lpfc_hba
*phba
)
878 struct lpfc_scsi_buf
*psb
, *psb_next
;
881 unsigned long iflag
= 0;
882 struct lpfc_sglq
*sglq_entry
= NULL
;
884 ret
= lpfc_hba_down_post_s3(phba
);
887 /* At this point in time the HBA is either reset or DOA. Either
888 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
889 * on the lpfc_sgl_list so that it can either be freed if the
890 * driver is unloading or reposted if the driver is restarting
893 spin_lock_irq(&phba
->hbalock
); /* required for lpfc_sgl_list and */
895 /* abts_sgl_list_lock required because worker thread uses this
898 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
899 list_for_each_entry(sglq_entry
,
900 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
)
901 sglq_entry
->state
= SGL_FREED
;
903 list_splice_init(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
,
904 &phba
->sli4_hba
.lpfc_sgl_list
);
905 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
906 /* abts_scsi_buf_list_lock required because worker thread uses this
909 spin_lock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
910 list_splice_init(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
,
912 spin_unlock(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
913 spin_unlock_irq(&phba
->hbalock
);
915 list_for_each_entry_safe(psb
, psb_next
, &aborts
, list
) {
917 psb
->status
= IOSTAT_SUCCESS
;
919 spin_lock_irqsave(&phba
->scsi_buf_list_put_lock
, iflag
);
920 list_splice(&aborts
, &phba
->lpfc_scsi_buf_list_put
);
921 spin_unlock_irqrestore(&phba
->scsi_buf_list_put_lock
, iflag
);
926 * lpfc_hba_down_post - Wrapper func for hba down post routine
927 * @phba: pointer to lpfc HBA data structure.
929 * This routine wraps the actual SLI3 or SLI4 routine for performing
930 * uninitialization after the HBA is reset when bring down the SLI Layer.
934 * Any other value - error.
937 lpfc_hba_down_post(struct lpfc_hba
*phba
)
939 return (*phba
->lpfc_hba_down_post
)(phba
);
943 * lpfc_hb_timeout - The HBA-timer timeout handler
944 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
946 * This is the HBA-timer timeout handler registered to the lpfc driver. When
947 * this timer fires, a HBA timeout event shall be posted to the lpfc driver
948 * work-port-events bitmap and the worker thread is notified. This timeout
949 * event will be used by the worker thread to invoke the actual timeout
950 * handler routine, lpfc_hb_timeout_handler. Any periodical operations will
951 * be performed in the timeout handler and the HBA timeout event bit shall
952 * be cleared by the worker thread after it has taken the event bitmap out.
955 lpfc_hb_timeout(unsigned long ptr
)
957 struct lpfc_hba
*phba
;
961 phba
= (struct lpfc_hba
*)ptr
;
963 /* Check for heart beat timeout conditions */
964 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
965 tmo_posted
= phba
->pport
->work_port_events
& WORKER_HB_TMO
;
967 phba
->pport
->work_port_events
|= WORKER_HB_TMO
;
968 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
970 /* Tell the worker thread there is work to do */
972 lpfc_worker_wake_up(phba
);
977 * lpfc_rrq_timeout - The RRQ-timer timeout handler
978 * @ptr: unsigned long holds the pointer to lpfc hba data structure.
980 * This is the RRQ-timer timeout handler registered to the lpfc driver. When
981 * this timer fires, a RRQ timeout event shall be posted to the lpfc driver
982 * work-port-events bitmap and the worker thread is notified. This timeout
983 * event will be used by the worker thread to invoke the actual timeout
984 * handler routine, lpfc_rrq_handler. Any periodical operations will
985 * be performed in the timeout handler and the RRQ timeout event bit shall
986 * be cleared by the worker thread after it has taken the event bitmap out.
989 lpfc_rrq_timeout(unsigned long ptr
)
991 struct lpfc_hba
*phba
;
994 phba
= (struct lpfc_hba
*)ptr
;
995 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflag
);
996 phba
->hba_flag
|= HBA_RRQ_ACTIVE
;
997 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflag
);
998 lpfc_worker_wake_up(phba
);
1002 * lpfc_hb_mbox_cmpl - The lpfc heart-beat mailbox command callback function
1003 * @phba: pointer to lpfc hba data structure.
1004 * @pmboxq: pointer to the driver internal queue element for mailbox command.
1006 * This is the callback function to the lpfc heart-beat mailbox command.
1007 * If configured, the lpfc driver issues the heart-beat mailbox command to
1008 * the HBA every LPFC_HB_MBOX_INTERVAL (current 5) seconds. At the time the
1009 * heart-beat mailbox command is issued, the driver shall set up heart-beat
1010 * timeout timer to LPFC_HB_MBOX_TIMEOUT (current 30) seconds and marks
1011 * heart-beat outstanding state. Once the mailbox command comes back and
1012 * no error conditions detected, the heart-beat mailbox command timer is
1013 * reset to LPFC_HB_MBOX_INTERVAL seconds and the heart-beat outstanding
1014 * state is cleared for the next heart-beat. If the timer expired with the
1015 * heart-beat outstanding state set, the driver will put the HBA offline.
1018 lpfc_hb_mbox_cmpl(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmboxq
)
1020 unsigned long drvr_flag
;
1022 spin_lock_irqsave(&phba
->hbalock
, drvr_flag
);
1023 phba
->hb_outstanding
= 0;
1024 spin_unlock_irqrestore(&phba
->hbalock
, drvr_flag
);
1026 /* Check and reset heart-beat timer is necessary */
1027 mempool_free(pmboxq
, phba
->mbox_mem_pool
);
1028 if (!(phba
->pport
->fc_flag
& FC_OFFLINE_MODE
) &&
1029 !(phba
->link_state
== LPFC_HBA_ERROR
) &&
1030 !(phba
->pport
->load_flag
& FC_UNLOADING
))
1031 mod_timer(&phba
->hb_tmofunc
,
1033 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
1038 * lpfc_hb_timeout_handler - The HBA-timer timeout handler
1039 * @phba: pointer to lpfc hba data structure.
1041 * This is the actual HBA-timer timeout handler to be invoked by the worker
1042 * thread whenever the HBA timer fired and HBA-timeout event posted. This
1043 * handler performs any periodic operations needed for the device. If such
1044 * periodic event has already been attended to either in the interrupt handler
1045 * or by processing slow-ring or fast-ring events within the HBA-timer
1046 * timeout window (LPFC_HB_MBOX_INTERVAL), this handler just simply resets
1047 * the timer for the next timeout period. If lpfc heart-beat mailbox command
1048 * is configured and there is no heart-beat mailbox command outstanding, a
1049 * heart-beat mailbox is issued and timer set properly. Otherwise, if there
1050 * has been a heart-beat mailbox command outstanding, the HBA shall be put
1054 lpfc_hb_timeout_handler(struct lpfc_hba
*phba
)
1056 struct lpfc_vport
**vports
;
1057 LPFC_MBOXQ_t
*pmboxq
;
1058 struct lpfc_dmabuf
*buf_ptr
;
1060 struct lpfc_sli
*psli
= &phba
->sli
;
1061 LIST_HEAD(completions
);
1063 vports
= lpfc_create_vport_work_array(phba
);
1065 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
1066 lpfc_rcv_seq_check_edtov(vports
[i
]);
1067 lpfc_destroy_vport_work_array(phba
, vports
);
1069 if ((phba
->link_state
== LPFC_HBA_ERROR
) ||
1070 (phba
->pport
->load_flag
& FC_UNLOADING
) ||
1071 (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
))
1074 spin_lock_irq(&phba
->pport
->work_port_lock
);
1076 if (time_after(phba
->last_completion_time
+
1077 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
),
1079 spin_unlock_irq(&phba
->pport
->work_port_lock
);
1080 if (!phba
->hb_outstanding
)
1081 mod_timer(&phba
->hb_tmofunc
,
1083 msecs_to_jiffies(1000 * LPFC_HB_MBOX_INTERVAL
));
1085 mod_timer(&phba
->hb_tmofunc
,
1087 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT
));
1090 spin_unlock_irq(&phba
->pport
->work_port_lock
);
1092 if (phba
->elsbuf_cnt
&&
1093 (phba
->elsbuf_cnt
== phba
->elsbuf_prev_cnt
)) {
1094 spin_lock_irq(&phba
->hbalock
);
1095 list_splice_init(&phba
->elsbuf
, &completions
);
1096 phba
->elsbuf_cnt
= 0;
1097 phba
->elsbuf_prev_cnt
= 0;
1098 spin_unlock_irq(&phba
->hbalock
);
1100 while (!list_empty(&completions
)) {
1101 list_remove_head(&completions
, buf_ptr
,
1102 struct lpfc_dmabuf
, list
);
1103 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
1107 phba
->elsbuf_prev_cnt
= phba
->elsbuf_cnt
;
1109 /* If there is no heart beat outstanding, issue a heartbeat command */
1110 if (phba
->cfg_enable_hba_heartbeat
) {
1111 if (!phba
->hb_outstanding
) {
1112 if ((!(psli
->sli_flag
& LPFC_SLI_MBOX_ACTIVE
)) &&
1113 (list_empty(&psli
->mboxq
))) {
1114 pmboxq
= mempool_alloc(phba
->mbox_mem_pool
,
1117 mod_timer(&phba
->hb_tmofunc
,
1119 msecs_to_jiffies(1000 *
1120 LPFC_HB_MBOX_INTERVAL
));
1124 lpfc_heart_beat(phba
, pmboxq
);
1125 pmboxq
->mbox_cmpl
= lpfc_hb_mbox_cmpl
;
1126 pmboxq
->vport
= phba
->pport
;
1127 retval
= lpfc_sli_issue_mbox(phba
, pmboxq
,
1130 if (retval
!= MBX_BUSY
&&
1131 retval
!= MBX_SUCCESS
) {
1132 mempool_free(pmboxq
,
1133 phba
->mbox_mem_pool
);
1134 mod_timer(&phba
->hb_tmofunc
,
1136 msecs_to_jiffies(1000 *
1137 LPFC_HB_MBOX_INTERVAL
));
1140 phba
->skipped_hb
= 0;
1141 phba
->hb_outstanding
= 1;
1142 } else if (time_before_eq(phba
->last_completion_time
,
1143 phba
->skipped_hb
)) {
1144 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1145 "2857 Last completion time not "
1146 " updated in %d ms\n",
1147 jiffies_to_msecs(jiffies
1148 - phba
->last_completion_time
));
1150 phba
->skipped_hb
= jiffies
;
1152 mod_timer(&phba
->hb_tmofunc
,
1154 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT
));
1158 * If heart beat timeout called with hb_outstanding set
1159 * we need to give the hb mailbox cmd a chance to
1162 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
1163 "0459 Adapter heartbeat still out"
1164 "standing:last compl time was %d ms.\n",
1165 jiffies_to_msecs(jiffies
1166 - phba
->last_completion_time
));
1167 mod_timer(&phba
->hb_tmofunc
,
1169 msecs_to_jiffies(1000 * LPFC_HB_MBOX_TIMEOUT
));
1175 * lpfc_offline_eratt - Bring lpfc offline on hardware error attention
1176 * @phba: pointer to lpfc hba data structure.
1178 * This routine is called to bring the HBA offline when HBA hardware error
1179 * other than Port Error 6 has been detected.
1182 lpfc_offline_eratt(struct lpfc_hba
*phba
)
1184 struct lpfc_sli
*psli
= &phba
->sli
;
1186 spin_lock_irq(&phba
->hbalock
);
1187 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1188 spin_unlock_irq(&phba
->hbalock
);
1189 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
1192 lpfc_reset_barrier(phba
);
1193 spin_lock_irq(&phba
->hbalock
);
1194 lpfc_sli_brdreset(phba
);
1195 spin_unlock_irq(&phba
->hbalock
);
1196 lpfc_hba_down_post(phba
);
1197 lpfc_sli_brdready(phba
, HS_MBRDY
);
1198 lpfc_unblock_mgmt_io(phba
);
1199 phba
->link_state
= LPFC_HBA_ERROR
;
1204 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
1205 * @phba: pointer to lpfc hba data structure.
1207 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
1208 * other than Port Error 6 has been detected.
1211 lpfc_sli4_offline_eratt(struct lpfc_hba
*phba
)
1213 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
1215 lpfc_sli4_brdreset(phba
);
1216 lpfc_hba_down_post(phba
);
1217 lpfc_sli4_post_status_check(phba
);
1218 lpfc_unblock_mgmt_io(phba
);
1219 phba
->link_state
= LPFC_HBA_ERROR
;
1223 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
1224 * @phba: pointer to lpfc hba data structure.
1226 * This routine is invoked to handle the deferred HBA hardware error
1227 * conditions. This type of error is indicated by HBA by setting ER1
1228 * and another ER bit in the host status register. The driver will
1229 * wait until the ER1 bit clears before handling the error condition.
1232 lpfc_handle_deferred_eratt(struct lpfc_hba
*phba
)
1234 uint32_t old_host_status
= phba
->work_hs
;
1235 struct lpfc_sli_ring
*pring
;
1236 struct lpfc_sli
*psli
= &phba
->sli
;
1238 /* If the pci channel is offline, ignore possible errors,
1239 * since we cannot communicate with the pci card anyway.
1241 if (pci_channel_offline(phba
->pcidev
)) {
1242 spin_lock_irq(&phba
->hbalock
);
1243 phba
->hba_flag
&= ~DEFER_ERATT
;
1244 spin_unlock_irq(&phba
->hbalock
);
1248 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1249 "0479 Deferred Adapter Hardware Error "
1250 "Data: x%x x%x x%x\n",
1252 phba
->work_status
[0], phba
->work_status
[1]);
1254 spin_lock_irq(&phba
->hbalock
);
1255 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1256 spin_unlock_irq(&phba
->hbalock
);
1260 * Firmware stops when it triggred erratt. That could cause the I/Os
1261 * dropped by the firmware. Error iocb (I/O) on txcmplq and let the
1262 * SCSI layer retry it after re-establishing link.
1264 pring
= &psli
->ring
[psli
->fcp_ring
];
1265 lpfc_sli_abort_iocb_ring(phba
, pring
);
1268 * There was a firmware error. Take the hba offline and then
1269 * attempt to restart it.
1271 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
1274 /* Wait for the ER1 bit to clear.*/
1275 while (phba
->work_hs
& HS_FFER1
) {
1277 if (lpfc_readl(phba
->HSregaddr
, &phba
->work_hs
)) {
1278 phba
->work_hs
= UNPLUG_ERR
;
1281 /* If driver is unloading let the worker thread continue */
1282 if (phba
->pport
->load_flag
& FC_UNLOADING
) {
1289 * This is to ptrotect against a race condition in which
1290 * first write to the host attention register clear the
1291 * host status register.
1293 if ((!phba
->work_hs
) && (!(phba
->pport
->load_flag
& FC_UNLOADING
)))
1294 phba
->work_hs
= old_host_status
& ~HS_FFER1
;
1296 spin_lock_irq(&phba
->hbalock
);
1297 phba
->hba_flag
&= ~DEFER_ERATT
;
1298 spin_unlock_irq(&phba
->hbalock
);
1299 phba
->work_status
[0] = readl(phba
->MBslimaddr
+ 0xa8);
1300 phba
->work_status
[1] = readl(phba
->MBslimaddr
+ 0xac);
1304 lpfc_board_errevt_to_mgmt(struct lpfc_hba
*phba
)
1306 struct lpfc_board_event_header board_event
;
1307 struct Scsi_Host
*shost
;
1309 board_event
.event_type
= FC_REG_BOARD_EVENT
;
1310 board_event
.subcategory
= LPFC_EVENT_PORTINTERR
;
1311 shost
= lpfc_shost_from_vport(phba
->pport
);
1312 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1313 sizeof(board_event
),
1314 (char *) &board_event
,
1319 * lpfc_handle_eratt_s3 - The SLI3 HBA hardware error handler
1320 * @phba: pointer to lpfc hba data structure.
1322 * This routine is invoked to handle the following HBA hardware error
1324 * 1 - HBA error attention interrupt
1325 * 2 - DMA ring index out of range
1326 * 3 - Mailbox command came back as unknown
1329 lpfc_handle_eratt_s3(struct lpfc_hba
*phba
)
1331 struct lpfc_vport
*vport
= phba
->pport
;
1332 struct lpfc_sli
*psli
= &phba
->sli
;
1333 struct lpfc_sli_ring
*pring
;
1334 uint32_t event_data
;
1335 unsigned long temperature
;
1336 struct temp_event temp_event_data
;
1337 struct Scsi_Host
*shost
;
1339 /* If the pci channel is offline, ignore possible errors,
1340 * since we cannot communicate with the pci card anyway.
1342 if (pci_channel_offline(phba
->pcidev
)) {
1343 spin_lock_irq(&phba
->hbalock
);
1344 phba
->hba_flag
&= ~DEFER_ERATT
;
1345 spin_unlock_irq(&phba
->hbalock
);
1349 /* If resets are disabled then leave the HBA alone and return */
1350 if (!phba
->cfg_enable_hba_reset
)
1353 /* Send an internal error event to mgmt application */
1354 lpfc_board_errevt_to_mgmt(phba
);
1356 if (phba
->hba_flag
& DEFER_ERATT
)
1357 lpfc_handle_deferred_eratt(phba
);
1359 if ((phba
->work_hs
& HS_FFER6
) || (phba
->work_hs
& HS_FFER8
)) {
1360 if (phba
->work_hs
& HS_FFER6
)
1361 /* Re-establishing Link */
1362 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1363 "1301 Re-establishing Link "
1364 "Data: x%x x%x x%x\n",
1365 phba
->work_hs
, phba
->work_status
[0],
1366 phba
->work_status
[1]);
1367 if (phba
->work_hs
& HS_FFER8
)
1368 /* Device Zeroization */
1369 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1370 "2861 Host Authentication device "
1371 "zeroization Data:x%x x%x x%x\n",
1372 phba
->work_hs
, phba
->work_status
[0],
1373 phba
->work_status
[1]);
1375 spin_lock_irq(&phba
->hbalock
);
1376 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
1377 spin_unlock_irq(&phba
->hbalock
);
1380 * Firmware stops when it triggled erratt with HS_FFER6.
1381 * That could cause the I/Os dropped by the firmware.
1382 * Error iocb (I/O) on txcmplq and let the SCSI layer
1383 * retry it after re-establishing link.
1385 pring
= &psli
->ring
[psli
->fcp_ring
];
1386 lpfc_sli_abort_iocb_ring(phba
, pring
);
1389 * There was a firmware error. Take the hba offline and then
1390 * attempt to restart it.
1392 lpfc_offline_prep(phba
, LPFC_MBX_NO_WAIT
);
1394 lpfc_sli_brdrestart(phba
);
1395 if (lpfc_online(phba
) == 0) { /* Initialize the HBA */
1396 lpfc_unblock_mgmt_io(phba
);
1399 lpfc_unblock_mgmt_io(phba
);
1400 } else if (phba
->work_hs
& HS_CRIT_TEMP
) {
1401 temperature
= readl(phba
->MBslimaddr
+ TEMPERATURE_OFFSET
);
1402 temp_event_data
.event_type
= FC_REG_TEMPERATURE_EVENT
;
1403 temp_event_data
.event_code
= LPFC_CRIT_TEMP
;
1404 temp_event_data
.data
= (uint32_t)temperature
;
1406 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1407 "0406 Adapter maximum temperature exceeded "
1408 "(%ld), taking this port offline "
1409 "Data: x%x x%x x%x\n",
1410 temperature
, phba
->work_hs
,
1411 phba
->work_status
[0], phba
->work_status
[1]);
1413 shost
= lpfc_shost_from_vport(phba
->pport
);
1414 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1415 sizeof(temp_event_data
),
1416 (char *) &temp_event_data
,
1417 SCSI_NL_VID_TYPE_PCI
1418 | PCI_VENDOR_ID_EMULEX
);
1420 spin_lock_irq(&phba
->hbalock
);
1421 phba
->over_temp_state
= HBA_OVER_TEMP
;
1422 spin_unlock_irq(&phba
->hbalock
);
1423 lpfc_offline_eratt(phba
);
1426 /* The if clause above forces this code path when the status
1427 * failure is a value other than FFER6. Do not call the offline
1428 * twice. This is the adapter hardware error path.
1430 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1431 "0457 Adapter Hardware Error "
1432 "Data: x%x x%x x%x\n",
1434 phba
->work_status
[0], phba
->work_status
[1]);
1436 event_data
= FC_REG_DUMP_EVENT
;
1437 shost
= lpfc_shost_from_vport(vport
);
1438 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1439 sizeof(event_data
), (char *) &event_data
,
1440 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
1442 lpfc_offline_eratt(phba
);
1448 * lpfc_sli4_port_sta_fn_reset - The SLI4 function reset due to port status reg
1449 * @phba: pointer to lpfc hba data structure.
1450 * @mbx_action: flag for mailbox shutdown action.
1452 * This routine is invoked to perform an SLI4 port PCI function reset in
1453 * response to port status register polling attention. It waits for port
1454 * status register (ERR, RDY, RN) bits before proceeding with function reset.
1455 * During this process, interrupt vectors are freed and later requested
1456 * for handling possible port resource change.
1459 lpfc_sli4_port_sta_fn_reset(struct lpfc_hba
*phba
, int mbx_action
)
1465 * On error status condition, driver need to wait for port
1466 * ready before performing reset.
1468 rc
= lpfc_sli4_pdev_status_reg_wait(phba
);
1470 /* need reset: attempt for port recovery */
1471 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1472 "2887 Reset Needed: Attempting Port "
1474 lpfc_offline_prep(phba
, mbx_action
);
1476 /* release interrupt for possible resource change */
1477 lpfc_sli4_disable_intr(phba
);
1478 lpfc_sli_brdrestart(phba
);
1479 /* request and enable interrupt */
1480 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
1481 if (intr_mode
== LPFC_INTR_ERROR
) {
1482 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1483 "3175 Failed to enable interrupt\n");
1486 phba
->intr_mode
= intr_mode
;
1488 rc
= lpfc_online(phba
);
1490 lpfc_unblock_mgmt_io(phba
);
1496 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1497 * @phba: pointer to lpfc hba data structure.
1499 * This routine is invoked to handle the SLI4 HBA hardware error attention
1503 lpfc_handle_eratt_s4(struct lpfc_hba
*phba
)
1505 struct lpfc_vport
*vport
= phba
->pport
;
1506 uint32_t event_data
;
1507 struct Scsi_Host
*shost
;
1509 struct lpfc_register portstat_reg
= {0};
1510 uint32_t reg_err1
, reg_err2
;
1511 uint32_t uerrlo_reg
, uemasklo_reg
;
1512 uint32_t pci_rd_rc1
, pci_rd_rc2
;
1515 /* If the pci channel is offline, ignore possible errors, since
1516 * we cannot communicate with the pci card anyway.
1518 if (pci_channel_offline(phba
->pcidev
))
1520 /* If resets are disabled then leave the HBA alone and return */
1521 if (!phba
->cfg_enable_hba_reset
)
1524 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
1526 case LPFC_SLI_INTF_IF_TYPE_0
:
1527 pci_rd_rc1
= lpfc_readl(
1528 phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
,
1530 pci_rd_rc2
= lpfc_readl(
1531 phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
,
1533 /* consider PCI bus read error as pci_channel_offline */
1534 if (pci_rd_rc1
== -EIO
&& pci_rd_rc2
== -EIO
)
1536 lpfc_sli4_offline_eratt(phba
);
1538 case LPFC_SLI_INTF_IF_TYPE_2
:
1539 pci_rd_rc1
= lpfc_readl(
1540 phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
1541 &portstat_reg
.word0
);
1542 /* consider PCI bus read error as pci_channel_offline */
1543 if (pci_rd_rc1
== -EIO
) {
1544 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1545 "3151 PCI bus read access failure: x%x\n",
1546 readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
));
1549 reg_err1
= readl(phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
1550 reg_err2
= readl(phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
1551 if (bf_get(lpfc_sliport_status_oti
, &portstat_reg
)) {
1552 /* TODO: Register for Overtemp async events. */
1553 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1554 "2889 Port Overtemperature event, "
1555 "taking port offline\n");
1556 spin_lock_irq(&phba
->hbalock
);
1557 phba
->over_temp_state
= HBA_OVER_TEMP
;
1558 spin_unlock_irq(&phba
->hbalock
);
1559 lpfc_sli4_offline_eratt(phba
);
1562 if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1563 reg_err2
== SLIPORT_ERR2_REG_FW_RESTART
)
1564 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1565 "3143 Port Down: Firmware Restarted\n");
1566 else if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1567 reg_err2
== SLIPORT_ERR2_REG_FORCED_DUMP
)
1568 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1569 "3144 Port Down: Debug Dump\n");
1570 else if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1571 reg_err2
== SLIPORT_ERR2_REG_FUNC_PROVISON
)
1572 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1573 "3145 Port Down: Provisioning\n");
1575 /* Check port status register for function reset */
1576 rc
= lpfc_sli4_port_sta_fn_reset(phba
, LPFC_MBX_NO_WAIT
);
1578 /* don't report event on forced debug dump */
1579 if (reg_err1
== SLIPORT_ERR1_REG_ERR_CODE_2
&&
1580 reg_err2
== SLIPORT_ERR2_REG_FORCED_DUMP
)
1585 /* fall through for not able to recover */
1586 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
1587 "3152 Unrecoverable error, bring the port "
1589 lpfc_sli4_offline_eratt(phba
);
1591 case LPFC_SLI_INTF_IF_TYPE_1
:
1595 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
1596 "3123 Report dump event to upper layer\n");
1597 /* Send an internal error event to mgmt application */
1598 lpfc_board_errevt_to_mgmt(phba
);
1600 event_data
= FC_REG_DUMP_EVENT
;
1601 shost
= lpfc_shost_from_vport(vport
);
1602 fc_host_post_vendor_event(shost
, fc_get_event_number(),
1603 sizeof(event_data
), (char *) &event_data
,
1604 SCSI_NL_VID_TYPE_PCI
| PCI_VENDOR_ID_EMULEX
);
1608 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1609 * @phba: pointer to lpfc HBA data structure.
1611 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1612 * routine from the API jump table function pointer from the lpfc_hba struct.
1616 * Any other value - error.
1619 lpfc_handle_eratt(struct lpfc_hba
*phba
)
1621 (*phba
->lpfc_handle_eratt
)(phba
);
1625 * lpfc_handle_latt - The HBA link event handler
1626 * @phba: pointer to lpfc hba data structure.
1628 * This routine is invoked from the worker thread to handle a HBA host
1629 * attention link event.
1632 lpfc_handle_latt(struct lpfc_hba
*phba
)
1634 struct lpfc_vport
*vport
= phba
->pport
;
1635 struct lpfc_sli
*psli
= &phba
->sli
;
1637 volatile uint32_t control
;
1638 struct lpfc_dmabuf
*mp
;
1641 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1644 goto lpfc_handle_latt_err_exit
;
1647 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1650 goto lpfc_handle_latt_free_pmb
;
1653 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
1656 goto lpfc_handle_latt_free_mp
;
1659 /* Cleanup any outstanding ELS commands */
1660 lpfc_els_flush_all_cmd(phba
);
1662 psli
->slistat
.link_event
++;
1663 lpfc_read_topology(phba
, pmb
, mp
);
1664 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
1666 /* Block ELS IOCBs until we have processed this mbox command */
1667 phba
->sli
.ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
1668 rc
= lpfc_sli_issue_mbox (phba
, pmb
, MBX_NOWAIT
);
1669 if (rc
== MBX_NOT_FINISHED
) {
1671 goto lpfc_handle_latt_free_mbuf
;
1674 /* Clear Link Attention in HA REG */
1675 spin_lock_irq(&phba
->hbalock
);
1676 writel(HA_LATT
, phba
->HAregaddr
);
1677 readl(phba
->HAregaddr
); /* flush */
1678 spin_unlock_irq(&phba
->hbalock
);
1682 lpfc_handle_latt_free_mbuf
:
1683 phba
->sli
.ring
[LPFC_ELS_RING
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
1684 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1685 lpfc_handle_latt_free_mp
:
1687 lpfc_handle_latt_free_pmb
:
1688 mempool_free(pmb
, phba
->mbox_mem_pool
);
1689 lpfc_handle_latt_err_exit
:
1690 /* Enable Link attention interrupts */
1691 spin_lock_irq(&phba
->hbalock
);
1692 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1693 control
= readl(phba
->HCregaddr
);
1694 control
|= HC_LAINT_ENA
;
1695 writel(control
, phba
->HCregaddr
);
1696 readl(phba
->HCregaddr
); /* flush */
1698 /* Clear Link Attention in HA REG */
1699 writel(HA_LATT
, phba
->HAregaddr
);
1700 readl(phba
->HAregaddr
); /* flush */
1701 spin_unlock_irq(&phba
->hbalock
);
1702 lpfc_linkdown(phba
);
1703 phba
->link_state
= LPFC_HBA_ERROR
;
1705 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1706 "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc
);
1712 * lpfc_parse_vpd - Parse VPD (Vital Product Data)
1713 * @phba: pointer to lpfc hba data structure.
1714 * @vpd: pointer to the vital product data.
1715 * @len: length of the vital product data in bytes.
1717 * This routine parses the Vital Product Data (VPD). The VPD is treated as
1718 * an array of characters. In this routine, the ModelName, ProgramType, and
1719 * ModelDesc, etc. fields of the phba data structure will be populated.
1722 * 0 - pointer to the VPD passed in is NULL
1726 lpfc_parse_vpd(struct lpfc_hba
*phba
, uint8_t *vpd
, int len
)
1728 uint8_t lenlo
, lenhi
;
1738 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
1739 "0455 Vital Product Data: x%x x%x x%x x%x\n",
1740 (uint32_t) vpd
[0], (uint32_t) vpd
[1], (uint32_t) vpd
[2],
1742 while (!finished
&& (index
< (len
- 4))) {
1743 switch (vpd
[index
]) {
1751 i
= ((((unsigned short)lenhi
) << 8) + lenlo
);
1760 Length
= ((((unsigned short)lenhi
) << 8) + lenlo
);
1761 if (Length
> len
- index
)
1762 Length
= len
- index
;
1763 while (Length
> 0) {
1764 /* Look for Serial Number */
1765 if ((vpd
[index
] == 'S') && (vpd
[index
+1] == 'N')) {
1772 phba
->SerialNumber
[j
++] = vpd
[index
++];
1776 phba
->SerialNumber
[j
] = 0;
1779 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '1')) {
1780 phba
->vpd_flag
|= VPD_MODEL_DESC
;
1787 phba
->ModelDesc
[j
++] = vpd
[index
++];
1791 phba
->ModelDesc
[j
] = 0;
1794 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '2')) {
1795 phba
->vpd_flag
|= VPD_MODEL_NAME
;
1802 phba
->ModelName
[j
++] = vpd
[index
++];
1806 phba
->ModelName
[j
] = 0;
1809 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '3')) {
1810 phba
->vpd_flag
|= VPD_PROGRAM_TYPE
;
1817 phba
->ProgramType
[j
++] = vpd
[index
++];
1821 phba
->ProgramType
[j
] = 0;
1824 else if ((vpd
[index
] == 'V') && (vpd
[index
+1] == '4')) {
1825 phba
->vpd_flag
|= VPD_PORT
;
1832 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
1833 (phba
->sli4_hba
.pport_name_sta
==
1834 LPFC_SLI4_PPNAME_GET
)) {
1838 phba
->Port
[j
++] = vpd
[index
++];
1842 if ((phba
->sli_rev
!= LPFC_SLI_REV4
) ||
1843 (phba
->sli4_hba
.pport_name_sta
==
1844 LPFC_SLI4_PPNAME_NON
))
1871 * lpfc_get_hba_model_desc - Retrieve HBA device model name and description
1872 * @phba: pointer to lpfc hba data structure.
1873 * @mdp: pointer to the data structure to hold the derived model name.
1874 * @descp: pointer to the data structure to hold the derived description.
1876 * This routine retrieves HBA's description based on its registered PCI device
1877 * ID. The @descp passed into this function points to an array of 256 chars. It
1878 * shall be returned with the model name, maximum speed, and the host bus type.
1879 * The @mdp passed into this function points to an array of 80 chars. When the
1880 * function returns, the @mdp will be filled with the model name.
1883 lpfc_get_hba_model_desc(struct lpfc_hba
*phba
, uint8_t *mdp
, uint8_t *descp
)
1886 uint16_t dev_id
= phba
->pcidev
->device
;
1889 int oneConnect
= 0; /* default is not a oneConnect */
1894 } m
= {"<Unknown>", "", ""};
1896 if (mdp
&& mdp
[0] != '\0'
1897 && descp
&& descp
[0] != '\0')
1900 if (phba
->lmt
& LMT_16Gb
)
1902 else if (phba
->lmt
& LMT_10Gb
)
1904 else if (phba
->lmt
& LMT_8Gb
)
1906 else if (phba
->lmt
& LMT_4Gb
)
1908 else if (phba
->lmt
& LMT_2Gb
)
1910 else if (phba
->lmt
& LMT_1Gb
)
1918 case PCI_DEVICE_ID_FIREFLY
:
1919 m
= (typeof(m
)){"LP6000", "PCI", "Fibre Channel Adapter"};
1921 case PCI_DEVICE_ID_SUPERFLY
:
1922 if (vp
->rev
.biuRev
>= 1 && vp
->rev
.biuRev
<= 3)
1923 m
= (typeof(m
)){"LP7000", "PCI",
1924 "Fibre Channel Adapter"};
1926 m
= (typeof(m
)){"LP7000E", "PCI",
1927 "Fibre Channel Adapter"};
1929 case PCI_DEVICE_ID_DRAGONFLY
:
1930 m
= (typeof(m
)){"LP8000", "PCI",
1931 "Fibre Channel Adapter"};
1933 case PCI_DEVICE_ID_CENTAUR
:
1934 if (FC_JEDEC_ID(vp
->rev
.biuRev
) == CENTAUR_2G_JEDEC_ID
)
1935 m
= (typeof(m
)){"LP9002", "PCI",
1936 "Fibre Channel Adapter"};
1938 m
= (typeof(m
)){"LP9000", "PCI",
1939 "Fibre Channel Adapter"};
1941 case PCI_DEVICE_ID_RFLY
:
1942 m
= (typeof(m
)){"LP952", "PCI",
1943 "Fibre Channel Adapter"};
1945 case PCI_DEVICE_ID_PEGASUS
:
1946 m
= (typeof(m
)){"LP9802", "PCI-X",
1947 "Fibre Channel Adapter"};
1949 case PCI_DEVICE_ID_THOR
:
1950 m
= (typeof(m
)){"LP10000", "PCI-X",
1951 "Fibre Channel Adapter"};
1953 case PCI_DEVICE_ID_VIPER
:
1954 m
= (typeof(m
)){"LPX1000", "PCI-X",
1955 "Fibre Channel Adapter"};
1957 case PCI_DEVICE_ID_PFLY
:
1958 m
= (typeof(m
)){"LP982", "PCI-X",
1959 "Fibre Channel Adapter"};
1961 case PCI_DEVICE_ID_TFLY
:
1962 m
= (typeof(m
)){"LP1050", "PCI-X",
1963 "Fibre Channel Adapter"};
1965 case PCI_DEVICE_ID_HELIOS
:
1966 m
= (typeof(m
)){"LP11000", "PCI-X2",
1967 "Fibre Channel Adapter"};
1969 case PCI_DEVICE_ID_HELIOS_SCSP
:
1970 m
= (typeof(m
)){"LP11000-SP", "PCI-X2",
1971 "Fibre Channel Adapter"};
1973 case PCI_DEVICE_ID_HELIOS_DCSP
:
1974 m
= (typeof(m
)){"LP11002-SP", "PCI-X2",
1975 "Fibre Channel Adapter"};
1977 case PCI_DEVICE_ID_NEPTUNE
:
1978 m
= (typeof(m
)){"LPe1000", "PCIe", "Fibre Channel Adapter"};
1980 case PCI_DEVICE_ID_NEPTUNE_SCSP
:
1981 m
= (typeof(m
)){"LPe1000-SP", "PCIe", "Fibre Channel Adapter"};
1983 case PCI_DEVICE_ID_NEPTUNE_DCSP
:
1984 m
= (typeof(m
)){"LPe1002-SP", "PCIe", "Fibre Channel Adapter"};
1986 case PCI_DEVICE_ID_BMID
:
1987 m
= (typeof(m
)){"LP1150", "PCI-X2", "Fibre Channel Adapter"};
1989 case PCI_DEVICE_ID_BSMB
:
1990 m
= (typeof(m
)){"LP111", "PCI-X2", "Fibre Channel Adapter"};
1992 case PCI_DEVICE_ID_ZEPHYR
:
1993 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
1995 case PCI_DEVICE_ID_ZEPHYR_SCSP
:
1996 m
= (typeof(m
)){"LPe11000", "PCIe", "Fibre Channel Adapter"};
1998 case PCI_DEVICE_ID_ZEPHYR_DCSP
:
1999 m
= (typeof(m
)){"LP2105", "PCIe", "FCoE Adapter"};
2002 case PCI_DEVICE_ID_ZMID
:
2003 m
= (typeof(m
)){"LPe1150", "PCIe", "Fibre Channel Adapter"};
2005 case PCI_DEVICE_ID_ZSMB
:
2006 m
= (typeof(m
)){"LPe111", "PCIe", "Fibre Channel Adapter"};
2008 case PCI_DEVICE_ID_LP101
:
2009 m
= (typeof(m
)){"LP101", "PCI-X", "Fibre Channel Adapter"};
2011 case PCI_DEVICE_ID_LP10000S
:
2012 m
= (typeof(m
)){"LP10000-S", "PCI", "Fibre Channel Adapter"};
2014 case PCI_DEVICE_ID_LP11000S
:
2015 m
= (typeof(m
)){"LP11000-S", "PCI-X2", "Fibre Channel Adapter"};
2017 case PCI_DEVICE_ID_LPE11000S
:
2018 m
= (typeof(m
)){"LPe11000-S", "PCIe", "Fibre Channel Adapter"};
2020 case PCI_DEVICE_ID_SAT
:
2021 m
= (typeof(m
)){"LPe12000", "PCIe", "Fibre Channel Adapter"};
2023 case PCI_DEVICE_ID_SAT_MID
:
2024 m
= (typeof(m
)){"LPe1250", "PCIe", "Fibre Channel Adapter"};
2026 case PCI_DEVICE_ID_SAT_SMB
:
2027 m
= (typeof(m
)){"LPe121", "PCIe", "Fibre Channel Adapter"};
2029 case PCI_DEVICE_ID_SAT_DCSP
:
2030 m
= (typeof(m
)){"LPe12002-SP", "PCIe", "Fibre Channel Adapter"};
2032 case PCI_DEVICE_ID_SAT_SCSP
:
2033 m
= (typeof(m
)){"LPe12000-SP", "PCIe", "Fibre Channel Adapter"};
2035 case PCI_DEVICE_ID_SAT_S
:
2036 m
= (typeof(m
)){"LPe12000-S", "PCIe", "Fibre Channel Adapter"};
2038 case PCI_DEVICE_ID_HORNET
:
2039 m
= (typeof(m
)){"LP21000", "PCIe", "FCoE Adapter"};
2042 case PCI_DEVICE_ID_PROTEUS_VF
:
2043 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
2044 "Fibre Channel Adapter"};
2046 case PCI_DEVICE_ID_PROTEUS_PF
:
2047 m
= (typeof(m
)){"LPev12000", "PCIe IOV",
2048 "Fibre Channel Adapter"};
2050 case PCI_DEVICE_ID_PROTEUS_S
:
2051 m
= (typeof(m
)){"LPemv12002-S", "PCIe IOV",
2052 "Fibre Channel Adapter"};
2054 case PCI_DEVICE_ID_TIGERSHARK
:
2056 m
= (typeof(m
)){"OCe10100", "PCIe", "FCoE"};
2058 case PCI_DEVICE_ID_TOMCAT
:
2060 m
= (typeof(m
)){"OCe11100", "PCIe", "FCoE"};
2062 case PCI_DEVICE_ID_FALCON
:
2063 m
= (typeof(m
)){"LPSe12002-ML1-E", "PCIe",
2064 "EmulexSecure Fibre"};
2066 case PCI_DEVICE_ID_BALIUS
:
2067 m
= (typeof(m
)){"LPVe12002", "PCIe Shared I/O",
2068 "Fibre Channel Adapter"};
2070 case PCI_DEVICE_ID_LANCER_FC
:
2071 case PCI_DEVICE_ID_LANCER_FC_VF
:
2072 m
= (typeof(m
)){"LPe16000", "PCIe", "Fibre Channel Adapter"};
2074 case PCI_DEVICE_ID_LANCER_FCOE
:
2075 case PCI_DEVICE_ID_LANCER_FCOE_VF
:
2077 m
= (typeof(m
)){"OCe15100", "PCIe", "FCoE"};
2079 case PCI_DEVICE_ID_SKYHAWK
:
2080 case PCI_DEVICE_ID_SKYHAWK_VF
:
2082 m
= (typeof(m
)){"OCe14000", "PCIe", "FCoE"};
2085 m
= (typeof(m
)){"Unknown", "", ""};
2089 if (mdp
&& mdp
[0] == '\0')
2090 snprintf(mdp
, 79,"%s", m
.name
);
2092 * oneConnect hba requires special processing, they are all initiators
2093 * and we put the port number on the end
2095 if (descp
&& descp
[0] == '\0') {
2097 snprintf(descp
, 255,
2098 "Emulex OneConnect %s, %s Initiator %s",
2101 else if (max_speed
== 0)
2102 snprintf(descp
, 255,
2104 m
.name
, m
.bus
, m
.function
);
2106 snprintf(descp
, 255,
2107 "Emulex %s %d%s %s %s",
2108 m
.name
, max_speed
, (GE
) ? "GE" : "Gb",
2114 * lpfc_post_buffer - Post IOCB(s) with DMA buffer descriptor(s) to a IOCB ring
2115 * @phba: pointer to lpfc hba data structure.
2116 * @pring: pointer to a IOCB ring.
2117 * @cnt: the number of IOCBs to be posted to the IOCB ring.
2119 * This routine posts a given number of IOCBs with the associated DMA buffer
2120 * descriptors specified by the cnt argument to the given IOCB ring.
2123 * The number of IOCBs NOT able to be posted to the IOCB ring.
2126 lpfc_post_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
, int cnt
)
2129 struct lpfc_iocbq
*iocb
;
2130 struct lpfc_dmabuf
*mp1
, *mp2
;
2132 cnt
+= pring
->missbufcnt
;
2134 /* While there are buffers to post */
2136 /* Allocate buffer for command iocb */
2137 iocb
= lpfc_sli_get_iocbq(phba
);
2139 pring
->missbufcnt
= cnt
;
2144 /* 2 buffers can be posted per command */
2145 /* Allocate buffer to post */
2146 mp1
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
2148 mp1
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &mp1
->phys
);
2149 if (!mp1
|| !mp1
->virt
) {
2151 lpfc_sli_release_iocbq(phba
, iocb
);
2152 pring
->missbufcnt
= cnt
;
2156 INIT_LIST_HEAD(&mp1
->list
);
2157 /* Allocate buffer to post */
2159 mp2
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
2161 mp2
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
2163 if (!mp2
|| !mp2
->virt
) {
2165 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
2167 lpfc_sli_release_iocbq(phba
, iocb
);
2168 pring
->missbufcnt
= cnt
;
2172 INIT_LIST_HEAD(&mp2
->list
);
2177 icmd
->un
.cont64
[0].addrHigh
= putPaddrHigh(mp1
->phys
);
2178 icmd
->un
.cont64
[0].addrLow
= putPaddrLow(mp1
->phys
);
2179 icmd
->un
.cont64
[0].tus
.f
.bdeSize
= FCELSSIZE
;
2180 icmd
->ulpBdeCount
= 1;
2183 icmd
->un
.cont64
[1].addrHigh
= putPaddrHigh(mp2
->phys
);
2184 icmd
->un
.cont64
[1].addrLow
= putPaddrLow(mp2
->phys
);
2185 icmd
->un
.cont64
[1].tus
.f
.bdeSize
= FCELSSIZE
;
2187 icmd
->ulpBdeCount
= 2;
2190 icmd
->ulpCommand
= CMD_QUE_RING_BUF64_CN
;
2193 if (lpfc_sli_issue_iocb(phba
, pring
->ringno
, iocb
, 0) ==
2195 lpfc_mbuf_free(phba
, mp1
->virt
, mp1
->phys
);
2199 lpfc_mbuf_free(phba
, mp2
->virt
, mp2
->phys
);
2203 lpfc_sli_release_iocbq(phba
, iocb
);
2204 pring
->missbufcnt
= cnt
;
2207 lpfc_sli_ringpostbuf_put(phba
, pring
, mp1
);
2209 lpfc_sli_ringpostbuf_put(phba
, pring
, mp2
);
2211 pring
->missbufcnt
= 0;
2216 * lpfc_post_rcv_buf - Post the initial receive IOCB buffers to ELS ring
2217 * @phba: pointer to lpfc hba data structure.
2219 * This routine posts initial receive IOCB buffers to the ELS ring. The
2220 * current number of initial IOCB buffers specified by LPFC_BUF_RING0 is
2224 * 0 - success (currently always success)
2227 lpfc_post_rcv_buf(struct lpfc_hba
*phba
)
2229 struct lpfc_sli
*psli
= &phba
->sli
;
2231 /* Ring 0, ELS / CT buffers */
2232 lpfc_post_buffer(phba
, &psli
->ring
[LPFC_ELS_RING
], LPFC_BUF_RING0
);
2233 /* Ring 2 - FCP no buffers needed */
2238 #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
2241 * lpfc_sha_init - Set up initial array of hash table entries
2242 * @HashResultPointer: pointer to an array as hash table.
2244 * This routine sets up the initial values to the array of hash table entries
2248 lpfc_sha_init(uint32_t * HashResultPointer
)
2250 HashResultPointer
[0] = 0x67452301;
2251 HashResultPointer
[1] = 0xEFCDAB89;
2252 HashResultPointer
[2] = 0x98BADCFE;
2253 HashResultPointer
[3] = 0x10325476;
2254 HashResultPointer
[4] = 0xC3D2E1F0;
2258 * lpfc_sha_iterate - Iterate initial hash table with the working hash table
2259 * @HashResultPointer: pointer to an initial/result hash table.
2260 * @HashWorkingPointer: pointer to an working hash table.
2262 * This routine iterates an initial hash table pointed by @HashResultPointer
2263 * with the values from the working hash table pointeed by @HashWorkingPointer.
2264 * The results are putting back to the initial hash table, returned through
2265 * the @HashResultPointer as the result hash table.
2268 lpfc_sha_iterate(uint32_t * HashResultPointer
, uint32_t * HashWorkingPointer
)
2272 uint32_t A
, B
, C
, D
, E
;
2275 HashWorkingPointer
[t
] =
2277 HashWorkingPointer
[t
- 3] ^ HashWorkingPointer
[t
-
2279 HashWorkingPointer
[t
- 14] ^ HashWorkingPointer
[t
- 16]);
2280 } while (++t
<= 79);
2282 A
= HashResultPointer
[0];
2283 B
= HashResultPointer
[1];
2284 C
= HashResultPointer
[2];
2285 D
= HashResultPointer
[3];
2286 E
= HashResultPointer
[4];
2290 TEMP
= ((B
& C
) | ((~B
) & D
)) + 0x5A827999;
2291 } else if (t
< 40) {
2292 TEMP
= (B
^ C
^ D
) + 0x6ED9EBA1;
2293 } else if (t
< 60) {
2294 TEMP
= ((B
& C
) | (B
& D
) | (C
& D
)) + 0x8F1BBCDC;
2296 TEMP
= (B
^ C
^ D
) + 0xCA62C1D6;
2298 TEMP
+= S(5, A
) + E
+ HashWorkingPointer
[t
];
2304 } while (++t
<= 79);
2306 HashResultPointer
[0] += A
;
2307 HashResultPointer
[1] += B
;
2308 HashResultPointer
[2] += C
;
2309 HashResultPointer
[3] += D
;
2310 HashResultPointer
[4] += E
;
2315 * lpfc_challenge_key - Create challenge key based on WWPN of the HBA
2316 * @RandomChallenge: pointer to the entry of host challenge random number array.
2317 * @HashWorking: pointer to the entry of the working hash array.
2319 * This routine calculates the working hash array referred by @HashWorking
2320 * from the challenge random numbers associated with the host, referred by
2321 * @RandomChallenge. The result is put into the entry of the working hash
2322 * array and returned by reference through @HashWorking.
2325 lpfc_challenge_key(uint32_t * RandomChallenge
, uint32_t * HashWorking
)
2327 *HashWorking
= (*RandomChallenge
^ *HashWorking
);
2331 * lpfc_hba_init - Perform special handling for LC HBA initialization
2332 * @phba: pointer to lpfc hba data structure.
2333 * @hbainit: pointer to an array of unsigned 32-bit integers.
2335 * This routine performs the special handling for LC HBA initialization.
2338 lpfc_hba_init(struct lpfc_hba
*phba
, uint32_t *hbainit
)
2341 uint32_t *HashWorking
;
2342 uint32_t *pwwnn
= (uint32_t *) phba
->wwnn
;
2344 HashWorking
= kcalloc(80, sizeof(uint32_t), GFP_KERNEL
);
2348 HashWorking
[0] = HashWorking
[78] = *pwwnn
++;
2349 HashWorking
[1] = HashWorking
[79] = *pwwnn
;
2351 for (t
= 0; t
< 7; t
++)
2352 lpfc_challenge_key(phba
->RandomData
+ t
, HashWorking
+ t
);
2354 lpfc_sha_init(hbainit
);
2355 lpfc_sha_iterate(hbainit
, HashWorking
);
2360 * lpfc_cleanup - Performs vport cleanups before deleting a vport
2361 * @vport: pointer to a virtual N_Port data structure.
2363 * This routine performs the necessary cleanups before deleting the @vport.
2364 * It invokes the discovery state machine to perform necessary state
2365 * transitions and to release the ndlps associated with the @vport. Note,
2366 * the physical port is treated as @vport 0.
2369 lpfc_cleanup(struct lpfc_vport
*vport
)
2371 struct lpfc_hba
*phba
= vport
->phba
;
2372 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2375 if (phba
->link_state
> LPFC_LINK_DOWN
)
2376 lpfc_port_link_failure(vport
);
2378 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2379 if (!NLP_CHK_NODE_ACT(ndlp
)) {
2380 ndlp
= lpfc_enable_node(vport
, ndlp
,
2381 NLP_STE_UNUSED_NODE
);
2384 spin_lock_irq(&phba
->ndlp_lock
);
2385 NLP_SET_FREE_REQ(ndlp
);
2386 spin_unlock_irq(&phba
->ndlp_lock
);
2387 /* Trigger the release of the ndlp memory */
2391 spin_lock_irq(&phba
->ndlp_lock
);
2392 if (NLP_CHK_FREE_REQ(ndlp
)) {
2393 /* The ndlp should not be in memory free mode already */
2394 spin_unlock_irq(&phba
->ndlp_lock
);
2397 /* Indicate request for freeing ndlp memory */
2398 NLP_SET_FREE_REQ(ndlp
);
2399 spin_unlock_irq(&phba
->ndlp_lock
);
2401 if (vport
->port_type
!= LPFC_PHYSICAL_PORT
&&
2402 ndlp
->nlp_DID
== Fabric_DID
) {
2403 /* Just free up ndlp with Fabric_DID for vports */
2408 /* take care of nodes in unused state before the state
2409 * machine taking action.
2411 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
2416 if (ndlp
->nlp_type
& NLP_FABRIC
)
2417 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2418 NLP_EVT_DEVICE_RECOVERY
);
2420 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2424 /* At this point, ALL ndlp's should be gone
2425 * because of the previous NLP_EVT_DEVICE_RM.
2426 * Lets wait for this to happen, if needed.
2428 while (!list_empty(&vport
->fc_nodes
)) {
2430 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2431 "0233 Nodelist not empty\n");
2432 list_for_each_entry_safe(ndlp
, next_ndlp
,
2433 &vport
->fc_nodes
, nlp_listp
) {
2434 lpfc_printf_vlog(ndlp
->vport
, KERN_ERR
,
2436 "0282 did:x%x ndlp:x%p "
2437 "usgmap:x%x refcnt:%d\n",
2438 ndlp
->nlp_DID
, (void *)ndlp
,
2441 &ndlp
->kref
.refcount
));
2446 /* Wait for any activity on ndlps to settle */
2449 lpfc_cleanup_vports_rrqs(vport
, NULL
);
2453 * lpfc_stop_vport_timers - Stop all the timers associated with a vport
2454 * @vport: pointer to a virtual N_Port data structure.
2456 * This routine stops all the timers associated with a @vport. This function
2457 * is invoked before disabling or deleting a @vport. Note that the physical
2458 * port is treated as @vport 0.
2461 lpfc_stop_vport_timers(struct lpfc_vport
*vport
)
2463 del_timer_sync(&vport
->els_tmofunc
);
2464 del_timer_sync(&vport
->fc_fdmitmo
);
2465 del_timer_sync(&vport
->delayed_disc_tmo
);
2466 lpfc_can_disctmo(vport
);
2471 * __lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2472 * @phba: pointer to lpfc hba data structure.
2474 * This routine stops the SLI4 FCF rediscover wait timer if it's on. The
2475 * caller of this routine should already hold the host lock.
2478 __lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2480 /* Clear pending FCF rediscovery wait flag */
2481 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_PEND
;
2483 /* Now, try to stop the timer */
2484 del_timer(&phba
->fcf
.redisc_wait
);
2488 * lpfc_sli4_stop_fcf_redisc_wait_timer - Stop FCF rediscovery wait timer
2489 * @phba: pointer to lpfc hba data structure.
2491 * This routine stops the SLI4 FCF rediscover wait timer if it's on. It
2492 * checks whether the FCF rediscovery wait timer is pending with the host
2493 * lock held before proceeding with disabling the timer and clearing the
2494 * wait timer pendig flag.
2497 lpfc_sli4_stop_fcf_redisc_wait_timer(struct lpfc_hba
*phba
)
2499 spin_lock_irq(&phba
->hbalock
);
2500 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
2501 /* FCF rediscovery timer already fired or stopped */
2502 spin_unlock_irq(&phba
->hbalock
);
2505 __lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
2506 /* Clear failover in progress flags */
2507 phba
->fcf
.fcf_flag
&= ~(FCF_DEAD_DISC
| FCF_ACVL_DISC
);
2508 spin_unlock_irq(&phba
->hbalock
);
2512 * lpfc_stop_hba_timers - Stop all the timers associated with an HBA
2513 * @phba: pointer to lpfc hba data structure.
2515 * This routine stops all the timers associated with a HBA. This function is
2516 * invoked before either putting a HBA offline or unloading the driver.
2519 lpfc_stop_hba_timers(struct lpfc_hba
*phba
)
2521 lpfc_stop_vport_timers(phba
->pport
);
2522 del_timer_sync(&phba
->sli
.mbox_tmo
);
2523 del_timer_sync(&phba
->fabric_block_timer
);
2524 del_timer_sync(&phba
->eratt_poll
);
2525 del_timer_sync(&phba
->hb_tmofunc
);
2526 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2527 del_timer_sync(&phba
->rrq_tmr
);
2528 phba
->hba_flag
&= ~HBA_RRQ_ACTIVE
;
2530 phba
->hb_outstanding
= 0;
2532 switch (phba
->pci_dev_grp
) {
2533 case LPFC_PCI_DEV_LP
:
2534 /* Stop any LightPulse device specific driver timers */
2535 del_timer_sync(&phba
->fcp_poll_timer
);
2537 case LPFC_PCI_DEV_OC
:
2538 /* Stop any OneConnect device sepcific driver timers */
2539 lpfc_sli4_stop_fcf_redisc_wait_timer(phba
);
2542 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
2543 "0297 Invalid device group (x%x)\n",
2551 * lpfc_block_mgmt_io - Mark a HBA's management interface as blocked
2552 * @phba: pointer to lpfc hba data structure.
2554 * This routine marks a HBA's management interface as blocked. Once the HBA's
2555 * management interface is marked as blocked, all the user space access to
2556 * the HBA, whether they are from sysfs interface or libdfc interface will
2557 * all be blocked. The HBA is set to block the management interface when the
2558 * driver prepares the HBA interface for online or offline.
2561 lpfc_block_mgmt_io(struct lpfc_hba
*phba
, int mbx_action
)
2563 unsigned long iflag
;
2564 uint8_t actcmd
= MBX_HEARTBEAT
;
2565 unsigned long timeout
;
2567 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2568 phba
->sli
.sli_flag
|= LPFC_BLOCK_MGMT_IO
;
2569 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2570 if (mbx_action
== LPFC_MBX_NO_WAIT
)
2572 timeout
= msecs_to_jiffies(LPFC_MBOX_TMO
* 1000) + jiffies
;
2573 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2574 if (phba
->sli
.mbox_active
) {
2575 actcmd
= phba
->sli
.mbox_active
->u
.mb
.mbxCommand
;
2576 /* Determine how long we might wait for the active mailbox
2577 * command to be gracefully completed by firmware.
2579 timeout
= msecs_to_jiffies(lpfc_mbox_tmo_val(phba
,
2580 phba
->sli
.mbox_active
) * 1000) + jiffies
;
2582 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2584 /* Wait for the outstnading mailbox command to complete */
2585 while (phba
->sli
.mbox_active
) {
2586 /* Check active mailbox complete status every 2ms */
2588 if (time_after(jiffies
, timeout
)) {
2589 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2590 "2813 Mgmt IO is Blocked %x "
2591 "- mbox cmd %x still active\n",
2592 phba
->sli
.sli_flag
, actcmd
);
2599 * lpfc_sli4_node_prep - Assign RPIs for active nodes.
2600 * @phba: pointer to lpfc hba data structure.
2602 * Allocate RPIs for all active remote nodes. This is needed whenever
2603 * an SLI4 adapter is reset and the driver is not unloading. Its purpose
2604 * is to fixup the temporary rpi assignments.
2607 lpfc_sli4_node_prep(struct lpfc_hba
*phba
)
2609 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2610 struct lpfc_vport
**vports
;
2613 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
2616 vports
= lpfc_create_vport_work_array(phba
);
2617 if (vports
!= NULL
) {
2618 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2619 if (vports
[i
]->load_flag
& FC_UNLOADING
)
2622 list_for_each_entry_safe(ndlp
, next_ndlp
,
2623 &vports
[i
]->fc_nodes
,
2625 if (NLP_CHK_NODE_ACT(ndlp
))
2627 lpfc_sli4_alloc_rpi(phba
);
2631 lpfc_destroy_vport_work_array(phba
, vports
);
2635 * lpfc_online - Initialize and bring a HBA online
2636 * @phba: pointer to lpfc hba data structure.
2638 * This routine initializes the HBA and brings a HBA online. During this
2639 * process, the management interface is blocked to prevent user space access
2640 * to the HBA interfering with the driver initialization.
2647 lpfc_online(struct lpfc_hba
*phba
)
2649 struct lpfc_vport
*vport
;
2650 struct lpfc_vport
**vports
;
2652 bool vpis_cleared
= false;
2656 vport
= phba
->pport
;
2658 if (!(vport
->fc_flag
& FC_OFFLINE_MODE
))
2661 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2662 "0458 Bring Adapter online\n");
2664 lpfc_block_mgmt_io(phba
, LPFC_MBX_WAIT
);
2666 if (!lpfc_sli_queue_setup(phba
)) {
2667 lpfc_unblock_mgmt_io(phba
);
2671 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2672 if (lpfc_sli4_hba_setup(phba
)) { /* Initialize SLI4 HBA */
2673 lpfc_unblock_mgmt_io(phba
);
2676 spin_lock_irq(&phba
->hbalock
);
2677 if (!phba
->sli4_hba
.max_cfg_param
.vpi_used
)
2678 vpis_cleared
= true;
2679 spin_unlock_irq(&phba
->hbalock
);
2681 if (lpfc_sli_hba_setup(phba
)) { /* Initialize SLI2/SLI3 HBA */
2682 lpfc_unblock_mgmt_io(phba
);
2687 vports
= lpfc_create_vport_work_array(phba
);
2689 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2690 struct Scsi_Host
*shost
;
2691 shost
= lpfc_shost_from_vport(vports
[i
]);
2692 spin_lock_irq(shost
->host_lock
);
2693 vports
[i
]->fc_flag
&= ~FC_OFFLINE_MODE
;
2694 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
2695 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2696 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2697 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
2698 if ((vpis_cleared
) &&
2699 (vports
[i
]->port_type
!=
2700 LPFC_PHYSICAL_PORT
))
2703 spin_unlock_irq(shost
->host_lock
);
2705 lpfc_destroy_vport_work_array(phba
, vports
);
2707 lpfc_unblock_mgmt_io(phba
);
2712 * lpfc_unblock_mgmt_io - Mark a HBA's management interface to be not blocked
2713 * @phba: pointer to lpfc hba data structure.
2715 * This routine marks a HBA's management interface as not blocked. Once the
2716 * HBA's management interface is marked as not blocked, all the user space
2717 * access to the HBA, whether they are from sysfs interface or libdfc
2718 * interface will be allowed. The HBA is set to block the management interface
2719 * when the driver prepares the HBA interface for online or offline and then
2720 * set to unblock the management interface afterwards.
2723 lpfc_unblock_mgmt_io(struct lpfc_hba
* phba
)
2725 unsigned long iflag
;
2727 spin_lock_irqsave(&phba
->hbalock
, iflag
);
2728 phba
->sli
.sli_flag
&= ~LPFC_BLOCK_MGMT_IO
;
2729 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
2733 * lpfc_offline_prep - Prepare a HBA to be brought offline
2734 * @phba: pointer to lpfc hba data structure.
2736 * This routine is invoked to prepare a HBA to be brought offline. It performs
2737 * unregistration login to all the nodes on all vports and flushes the mailbox
2738 * queue to make it ready to be brought offline.
2741 lpfc_offline_prep(struct lpfc_hba
*phba
, int mbx_action
)
2743 struct lpfc_vport
*vport
= phba
->pport
;
2744 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2745 struct lpfc_vport
**vports
;
2746 struct Scsi_Host
*shost
;
2749 if (vport
->fc_flag
& FC_OFFLINE_MODE
)
2752 lpfc_block_mgmt_io(phba
, mbx_action
);
2754 lpfc_linkdown(phba
);
2756 /* Issue an unreg_login to all nodes on all vports */
2757 vports
= lpfc_create_vport_work_array(phba
);
2758 if (vports
!= NULL
) {
2759 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2760 if (vports
[i
]->load_flag
& FC_UNLOADING
)
2762 shost
= lpfc_shost_from_vport(vports
[i
]);
2763 spin_lock_irq(shost
->host_lock
);
2764 vports
[i
]->vpi_state
&= ~LPFC_VPI_REGISTERED
;
2765 vports
[i
]->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
2766 vports
[i
]->fc_flag
&= ~FC_VFI_REGISTERED
;
2767 spin_unlock_irq(shost
->host_lock
);
2769 shost
= lpfc_shost_from_vport(vports
[i
]);
2770 list_for_each_entry_safe(ndlp
, next_ndlp
,
2771 &vports
[i
]->fc_nodes
,
2773 if (!NLP_CHK_NODE_ACT(ndlp
))
2775 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
2777 if (ndlp
->nlp_type
& NLP_FABRIC
) {
2778 lpfc_disc_state_machine(vports
[i
], ndlp
,
2779 NULL
, NLP_EVT_DEVICE_RECOVERY
);
2780 lpfc_disc_state_machine(vports
[i
], ndlp
,
2781 NULL
, NLP_EVT_DEVICE_RM
);
2783 spin_lock_irq(shost
->host_lock
);
2784 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2785 spin_unlock_irq(shost
->host_lock
);
2787 * Whenever an SLI4 port goes offline, free the
2788 * RPI. Get a new RPI when the adapter port
2789 * comes back online.
2791 if (phba
->sli_rev
== LPFC_SLI_REV4
)
2792 lpfc_sli4_free_rpi(phba
, ndlp
->nlp_rpi
);
2793 lpfc_unreg_rpi(vports
[i
], ndlp
);
2797 lpfc_destroy_vport_work_array(phba
, vports
);
2799 lpfc_sli_mbox_sys_shutdown(phba
, mbx_action
);
2803 * lpfc_offline - Bring a HBA offline
2804 * @phba: pointer to lpfc hba data structure.
2806 * This routine actually brings a HBA offline. It stops all the timers
2807 * associated with the HBA, brings down the SLI layer, and eventually
2808 * marks the HBA as in offline state for the upper layer protocol.
2811 lpfc_offline(struct lpfc_hba
*phba
)
2813 struct Scsi_Host
*shost
;
2814 struct lpfc_vport
**vports
;
2817 if (phba
->pport
->fc_flag
& FC_OFFLINE_MODE
)
2820 /* stop port and all timers associated with this hba */
2821 lpfc_stop_port(phba
);
2822 vports
= lpfc_create_vport_work_array(phba
);
2824 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
2825 lpfc_stop_vport_timers(vports
[i
]);
2826 lpfc_destroy_vport_work_array(phba
, vports
);
2827 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
2828 "0460 Bring Adapter offline\n");
2829 /* Bring down the SLI Layer and cleanup. The HBA is offline
2831 lpfc_sli_hba_down(phba
);
2832 spin_lock_irq(&phba
->hbalock
);
2834 spin_unlock_irq(&phba
->hbalock
);
2835 vports
= lpfc_create_vport_work_array(phba
);
2837 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
2838 shost
= lpfc_shost_from_vport(vports
[i
]);
2839 spin_lock_irq(shost
->host_lock
);
2840 vports
[i
]->work_port_events
= 0;
2841 vports
[i
]->fc_flag
|= FC_OFFLINE_MODE
;
2842 spin_unlock_irq(shost
->host_lock
);
2844 lpfc_destroy_vport_work_array(phba
, vports
);
2848 * lpfc_scsi_free - Free all the SCSI buffers and IOCBs from driver lists
2849 * @phba: pointer to lpfc hba data structure.
2851 * This routine is to free all the SCSI buffers and IOCBs from the driver
2852 * list back to kernel. It is called from lpfc_pci_remove_one to free
2853 * the internal resources before the device is removed from the system.
2856 lpfc_scsi_free(struct lpfc_hba
*phba
)
2858 struct lpfc_scsi_buf
*sb
, *sb_next
;
2859 struct lpfc_iocbq
*io
, *io_next
;
2861 spin_lock_irq(&phba
->hbalock
);
2863 /* Release all the lpfc_scsi_bufs maintained by this host. */
2865 spin_lock(&phba
->scsi_buf_list_put_lock
);
2866 list_for_each_entry_safe(sb
, sb_next
, &phba
->lpfc_scsi_buf_list_put
,
2868 list_del(&sb
->list
);
2869 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
, sb
->data
,
2872 phba
->total_scsi_bufs
--;
2874 spin_unlock(&phba
->scsi_buf_list_put_lock
);
2876 spin_lock(&phba
->scsi_buf_list_get_lock
);
2877 list_for_each_entry_safe(sb
, sb_next
, &phba
->lpfc_scsi_buf_list_get
,
2879 list_del(&sb
->list
);
2880 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
, sb
->data
,
2883 phba
->total_scsi_bufs
--;
2885 spin_unlock(&phba
->scsi_buf_list_get_lock
);
2887 /* Release all the lpfc_iocbq entries maintained by this host. */
2888 list_for_each_entry_safe(io
, io_next
, &phba
->lpfc_iocb_list
, list
) {
2889 list_del(&io
->list
);
2891 phba
->total_iocbq_bufs
--;
2894 spin_unlock_irq(&phba
->hbalock
);
2898 * lpfc_sli4_xri_sgl_update - update xri-sgl sizing and mapping
2899 * @phba: pointer to lpfc hba data structure.
2901 * This routine first calculates the sizes of the current els and allocated
2902 * scsi sgl lists, and then goes through all sgls to updates the physical
2903 * XRIs assigned due to port function reset. During port initialization, the
2904 * current els and allocated scsi sgl lists are 0s.
2907 * 0 - successful (for now, it always returns 0)
2910 lpfc_sli4_xri_sgl_update(struct lpfc_hba
*phba
)
2912 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_entry_next
= NULL
;
2913 struct lpfc_scsi_buf
*psb
= NULL
, *psb_next
= NULL
;
2914 uint16_t i
, lxri
, xri_cnt
, els_xri_cnt
, scsi_xri_cnt
;
2915 LIST_HEAD(els_sgl_list
);
2916 LIST_HEAD(scsi_sgl_list
);
2920 * update on pci function's els xri-sgl list
2922 els_xri_cnt
= lpfc_sli4_get_els_iocb_cnt(phba
);
2923 if (els_xri_cnt
> phba
->sli4_hba
.els_xri_cnt
) {
2924 /* els xri-sgl expanded */
2925 xri_cnt
= els_xri_cnt
- phba
->sli4_hba
.els_xri_cnt
;
2926 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2927 "3157 ELS xri-sgl count increased from "
2928 "%d to %d\n", phba
->sli4_hba
.els_xri_cnt
,
2930 /* allocate the additional els sgls */
2931 for (i
= 0; i
< xri_cnt
; i
++) {
2932 sglq_entry
= kzalloc(sizeof(struct lpfc_sglq
),
2934 if (sglq_entry
== NULL
) {
2935 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2936 "2562 Failure to allocate an "
2937 "ELS sgl entry:%d\n", i
);
2941 sglq_entry
->buff_type
= GEN_BUFF_TYPE
;
2942 sglq_entry
->virt
= lpfc_mbuf_alloc(phba
, 0,
2944 if (sglq_entry
->virt
== NULL
) {
2946 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2947 "2563 Failure to allocate an "
2948 "ELS mbuf:%d\n", i
);
2952 sglq_entry
->sgl
= sglq_entry
->virt
;
2953 memset(sglq_entry
->sgl
, 0, LPFC_BPL_SIZE
);
2954 sglq_entry
->state
= SGL_FREED
;
2955 list_add_tail(&sglq_entry
->list
, &els_sgl_list
);
2957 spin_lock_irq(&phba
->hbalock
);
2958 list_splice_init(&els_sgl_list
, &phba
->sli4_hba
.lpfc_sgl_list
);
2959 spin_unlock_irq(&phba
->hbalock
);
2960 } else if (els_xri_cnt
< phba
->sli4_hba
.els_xri_cnt
) {
2961 /* els xri-sgl shrinked */
2962 xri_cnt
= phba
->sli4_hba
.els_xri_cnt
- els_xri_cnt
;
2963 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2964 "3158 ELS xri-sgl count decreased from "
2965 "%d to %d\n", phba
->sli4_hba
.els_xri_cnt
,
2967 spin_lock_irq(&phba
->hbalock
);
2968 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &els_sgl_list
);
2969 spin_unlock_irq(&phba
->hbalock
);
2970 /* release extra els sgls from list */
2971 for (i
= 0; i
< xri_cnt
; i
++) {
2972 list_remove_head(&els_sgl_list
,
2973 sglq_entry
, struct lpfc_sglq
, list
);
2975 lpfc_mbuf_free(phba
, sglq_entry
->virt
,
2980 spin_lock_irq(&phba
->hbalock
);
2981 list_splice_init(&els_sgl_list
, &phba
->sli4_hba
.lpfc_sgl_list
);
2982 spin_unlock_irq(&phba
->hbalock
);
2984 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
2985 "3163 ELS xri-sgl count unchanged: %d\n",
2987 phba
->sli4_hba
.els_xri_cnt
= els_xri_cnt
;
2989 /* update xris to els sgls on the list */
2991 sglq_entry_next
= NULL
;
2992 list_for_each_entry_safe(sglq_entry
, sglq_entry_next
,
2993 &phba
->sli4_hba
.lpfc_sgl_list
, list
) {
2994 lxri
= lpfc_sli4_next_xritag(phba
);
2995 if (lxri
== NO_XRI
) {
2996 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
2997 "2400 Failed to allocate xri for "
3002 sglq_entry
->sli4_lxritag
= lxri
;
3003 sglq_entry
->sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
3007 * update on pci function's allocated scsi xri-sgl list
3009 phba
->total_scsi_bufs
= 0;
3011 /* maximum number of xris available for scsi buffers */
3012 phba
->sli4_hba
.scsi_xri_max
= phba
->sli4_hba
.max_cfg_param
.max_xri
-
3015 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3016 "2401 Current allocated SCSI xri-sgl count:%d, "
3017 "maximum SCSI xri count:%d\n",
3018 phba
->sli4_hba
.scsi_xri_cnt
,
3019 phba
->sli4_hba
.scsi_xri_max
);
3021 spin_lock_irq(&phba
->scsi_buf_list_get_lock
);
3022 spin_lock_irq(&phba
->scsi_buf_list_put_lock
);
3023 list_splice_init(&phba
->lpfc_scsi_buf_list_get
, &scsi_sgl_list
);
3024 list_splice(&phba
->lpfc_scsi_buf_list_put
, &scsi_sgl_list
);
3025 spin_unlock_irq(&phba
->scsi_buf_list_put_lock
);
3026 spin_unlock_irq(&phba
->scsi_buf_list_get_lock
);
3028 if (phba
->sli4_hba
.scsi_xri_cnt
> phba
->sli4_hba
.scsi_xri_max
) {
3029 /* max scsi xri shrinked below the allocated scsi buffers */
3030 scsi_xri_cnt
= phba
->sli4_hba
.scsi_xri_cnt
-
3031 phba
->sli4_hba
.scsi_xri_max
;
3032 /* release the extra allocated scsi buffers */
3033 for (i
= 0; i
< scsi_xri_cnt
; i
++) {
3034 list_remove_head(&scsi_sgl_list
, psb
,
3035 struct lpfc_scsi_buf
, list
);
3036 pci_pool_free(phba
->lpfc_scsi_dma_buf_pool
, psb
->data
,
3040 spin_lock_irq(&phba
->scsi_buf_list_get_lock
);
3041 phba
->sli4_hba
.scsi_xri_cnt
-= scsi_xri_cnt
;
3042 spin_unlock_irq(&phba
->scsi_buf_list_get_lock
);
3045 /* update xris associated to remaining allocated scsi buffers */
3048 list_for_each_entry_safe(psb
, psb_next
, &scsi_sgl_list
, list
) {
3049 lxri
= lpfc_sli4_next_xritag(phba
);
3050 if (lxri
== NO_XRI
) {
3051 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3052 "2560 Failed to allocate xri for "
3057 psb
->cur_iocbq
.sli4_lxritag
= lxri
;
3058 psb
->cur_iocbq
.sli4_xritag
= phba
->sli4_hba
.xri_ids
[lxri
];
3060 spin_lock_irq(&phba
->scsi_buf_list_get_lock
);
3061 spin_lock_irq(&phba
->scsi_buf_list_put_lock
);
3062 list_splice_init(&scsi_sgl_list
, &phba
->lpfc_scsi_buf_list_get
);
3063 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list_put
);
3064 spin_unlock_irq(&phba
->scsi_buf_list_put_lock
);
3065 spin_unlock_irq(&phba
->scsi_buf_list_get_lock
);
3070 lpfc_free_els_sgl_list(phba
);
3071 lpfc_scsi_free(phba
);
3076 * lpfc_create_port - Create an FC port
3077 * @phba: pointer to lpfc hba data structure.
3078 * @instance: a unique integer ID to this FC port.
3079 * @dev: pointer to the device data structure.
3081 * This routine creates a FC port for the upper layer protocol. The FC port
3082 * can be created on top of either a physical port or a virtual port provided
3083 * by the HBA. This routine also allocates a SCSI host data structure (shost)
3084 * and associates the FC port created before adding the shost into the SCSI
3088 * @vport - pointer to the virtual N_Port data structure.
3089 * NULL - port create failed.
3092 lpfc_create_port(struct lpfc_hba
*phba
, int instance
, struct device
*dev
)
3094 struct lpfc_vport
*vport
;
3095 struct Scsi_Host
*shost
;
3098 if (dev
!= &phba
->pcidev
->dev
)
3099 shost
= scsi_host_alloc(&lpfc_vport_template
,
3100 sizeof(struct lpfc_vport
));
3102 shost
= scsi_host_alloc(&lpfc_template
,
3103 sizeof(struct lpfc_vport
));
3107 vport
= (struct lpfc_vport
*) shost
->hostdata
;
3109 vport
->load_flag
|= FC_LOADING
;
3110 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
3111 vport
->fc_rscn_flush
= 0;
3113 lpfc_get_vport_cfgparam(vport
);
3114 shost
->unique_id
= instance
;
3115 shost
->max_id
= LPFC_MAX_TARGET
;
3116 shost
->max_lun
= vport
->cfg_max_luns
;
3117 shost
->this_id
= -1;
3118 shost
->max_cmd_len
= 16;
3119 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3120 shost
->dma_boundary
=
3121 phba
->sli4_hba
.pc_sli4_params
.sge_supp_len
-1;
3122 shost
->sg_tablesize
= phba
->cfg_sg_seg_cnt
;
3126 * Set initial can_queue value since 0 is no longer supported and
3127 * scsi_add_host will fail. This will be adjusted later based on the
3128 * max xri value determined in hba setup.
3130 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
3131 if (dev
!= &phba
->pcidev
->dev
) {
3132 shost
->transportt
= lpfc_vport_transport_template
;
3133 vport
->port_type
= LPFC_NPIV_PORT
;
3135 shost
->transportt
= lpfc_transport_template
;
3136 vport
->port_type
= LPFC_PHYSICAL_PORT
;
3139 /* Initialize all internally managed lists. */
3140 INIT_LIST_HEAD(&vport
->fc_nodes
);
3141 INIT_LIST_HEAD(&vport
->rcv_buffer_list
);
3142 spin_lock_init(&vport
->work_port_lock
);
3144 init_timer(&vport
->fc_disctmo
);
3145 vport
->fc_disctmo
.function
= lpfc_disc_timeout
;
3146 vport
->fc_disctmo
.data
= (unsigned long)vport
;
3148 init_timer(&vport
->fc_fdmitmo
);
3149 vport
->fc_fdmitmo
.function
= lpfc_fdmi_tmo
;
3150 vport
->fc_fdmitmo
.data
= (unsigned long)vport
;
3152 init_timer(&vport
->els_tmofunc
);
3153 vport
->els_tmofunc
.function
= lpfc_els_timeout
;
3154 vport
->els_tmofunc
.data
= (unsigned long)vport
;
3156 init_timer(&vport
->delayed_disc_tmo
);
3157 vport
->delayed_disc_tmo
.function
= lpfc_delayed_disc_tmo
;
3158 vport
->delayed_disc_tmo
.data
= (unsigned long)vport
;
3160 error
= scsi_add_host_with_dma(shost
, dev
, &phba
->pcidev
->dev
);
3164 spin_lock_irq(&phba
->hbalock
);
3165 list_add_tail(&vport
->listentry
, &phba
->port_list
);
3166 spin_unlock_irq(&phba
->hbalock
);
3170 scsi_host_put(shost
);
3176 * destroy_port - destroy an FC port
3177 * @vport: pointer to an lpfc virtual N_Port data structure.
3179 * This routine destroys a FC port from the upper layer protocol. All the
3180 * resources associated with the port are released.
3183 destroy_port(struct lpfc_vport
*vport
)
3185 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3186 struct lpfc_hba
*phba
= vport
->phba
;
3188 lpfc_debugfs_terminate(vport
);
3189 fc_remove_host(shost
);
3190 scsi_remove_host(shost
);
3192 spin_lock_irq(&phba
->hbalock
);
3193 list_del_init(&vport
->listentry
);
3194 spin_unlock_irq(&phba
->hbalock
);
3196 lpfc_cleanup(vport
);
3201 * lpfc_get_instance - Get a unique integer ID
3203 * This routine allocates a unique integer ID from lpfc_hba_index pool. It
3204 * uses the kernel idr facility to perform the task.
3207 * instance - a unique integer ID allocated as the new instance.
3208 * -1 - lpfc get instance failed.
3211 lpfc_get_instance(void)
3215 ret
= idr_alloc(&lpfc_hba_index
, NULL
, 0, 0, GFP_KERNEL
);
3216 return ret
< 0 ? -1 : ret
;
3220 * lpfc_scan_finished - method for SCSI layer to detect whether scan is done
3221 * @shost: pointer to SCSI host data structure.
3222 * @time: elapsed time of the scan in jiffies.
3224 * This routine is called by the SCSI layer with a SCSI host to determine
3225 * whether the scan host is finished.
3227 * Note: there is no scan_start function as adapter initialization will have
3228 * asynchronously kicked off the link initialization.
3231 * 0 - SCSI host scan is not over yet.
3232 * 1 - SCSI host scan is over.
3234 int lpfc_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
3236 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3237 struct lpfc_hba
*phba
= vport
->phba
;
3240 spin_lock_irq(shost
->host_lock
);
3242 if (vport
->load_flag
& FC_UNLOADING
) {
3246 if (time
>= msecs_to_jiffies(30 * 1000)) {
3247 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3248 "0461 Scanning longer than 30 "
3249 "seconds. Continuing initialization\n");
3253 if (time
>= msecs_to_jiffies(15 * 1000) &&
3254 phba
->link_state
<= LPFC_LINK_DOWN
) {
3255 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
3256 "0465 Link down longer than 15 "
3257 "seconds. Continuing initialization\n");
3262 if (vport
->port_state
!= LPFC_VPORT_READY
)
3264 if (vport
->num_disc_nodes
|| vport
->fc_prli_sent
)
3266 if (vport
->fc_map_cnt
== 0 && time
< msecs_to_jiffies(2 * 1000))
3268 if ((phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) != 0)
3274 spin_unlock_irq(shost
->host_lock
);
3279 * lpfc_host_attrib_init - Initialize SCSI host attributes on a FC port
3280 * @shost: pointer to SCSI host data structure.
3282 * This routine initializes a given SCSI host attributes on a FC port. The
3283 * SCSI host can be either on top of a physical port or a virtual port.
3285 void lpfc_host_attrib_init(struct Scsi_Host
*shost
)
3287 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
3288 struct lpfc_hba
*phba
= vport
->phba
;
3290 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
3293 fc_host_node_name(shost
) = wwn_to_u64(vport
->fc_nodename
.u
.wwn
);
3294 fc_host_port_name(shost
) = wwn_to_u64(vport
->fc_portname
.u
.wwn
);
3295 fc_host_supported_classes(shost
) = FC_COS_CLASS3
;
3297 memset(fc_host_supported_fc4s(shost
), 0,
3298 sizeof(fc_host_supported_fc4s(shost
)));
3299 fc_host_supported_fc4s(shost
)[2] = 1;
3300 fc_host_supported_fc4s(shost
)[7] = 1;
3302 lpfc_vport_symbolic_node_name(vport
, fc_host_symbolic_name(shost
),
3303 sizeof fc_host_symbolic_name(shost
));
3305 fc_host_supported_speeds(shost
) = 0;
3306 if (phba
->lmt
& LMT_16Gb
)
3307 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_16GBIT
;
3308 if (phba
->lmt
& LMT_10Gb
)
3309 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_10GBIT
;
3310 if (phba
->lmt
& LMT_8Gb
)
3311 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_8GBIT
;
3312 if (phba
->lmt
& LMT_4Gb
)
3313 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_4GBIT
;
3314 if (phba
->lmt
& LMT_2Gb
)
3315 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_2GBIT
;
3316 if (phba
->lmt
& LMT_1Gb
)
3317 fc_host_supported_speeds(shost
) |= FC_PORTSPEED_1GBIT
;
3319 fc_host_maxframe_size(shost
) =
3320 (((uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
3321 (uint32_t) vport
->fc_sparam
.cmn
.bbRcvSizeLsb
;
3323 fc_host_dev_loss_tmo(shost
) = vport
->cfg_devloss_tmo
;
3325 /* This value is also unchanging */
3326 memset(fc_host_active_fc4s(shost
), 0,
3327 sizeof(fc_host_active_fc4s(shost
)));
3328 fc_host_active_fc4s(shost
)[2] = 1;
3329 fc_host_active_fc4s(shost
)[7] = 1;
3331 fc_host_max_npiv_vports(shost
) = phba
->max_vpi
;
3332 spin_lock_irq(shost
->host_lock
);
3333 vport
->load_flag
&= ~FC_LOADING
;
3334 spin_unlock_irq(shost
->host_lock
);
3338 * lpfc_stop_port_s3 - Stop SLI3 device port
3339 * @phba: pointer to lpfc hba data structure.
3341 * This routine is invoked to stop an SLI3 device port, it stops the device
3342 * from generating interrupts and stops the device driver's timers for the
3346 lpfc_stop_port_s3(struct lpfc_hba
*phba
)
3348 /* Clear all interrupt enable conditions */
3349 writel(0, phba
->HCregaddr
);
3350 readl(phba
->HCregaddr
); /* flush */
3351 /* Clear all pending interrupts */
3352 writel(0xffffffff, phba
->HAregaddr
);
3353 readl(phba
->HAregaddr
); /* flush */
3355 /* Reset some HBA SLI setup states */
3356 lpfc_stop_hba_timers(phba
);
3357 phba
->pport
->work_port_events
= 0;
3361 * lpfc_stop_port_s4 - Stop SLI4 device port
3362 * @phba: pointer to lpfc hba data structure.
3364 * This routine is invoked to stop an SLI4 device port, it stops the device
3365 * from generating interrupts and stops the device driver's timers for the
3369 lpfc_stop_port_s4(struct lpfc_hba
*phba
)
3371 /* Reset some HBA SLI4 setup states */
3372 lpfc_stop_hba_timers(phba
);
3373 phba
->pport
->work_port_events
= 0;
3374 phba
->sli4_hba
.intr_enable
= 0;
3378 * lpfc_stop_port - Wrapper function for stopping hba port
3379 * @phba: Pointer to HBA context object.
3381 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
3382 * the API jump table function pointer from the lpfc_hba struct.
3385 lpfc_stop_port(struct lpfc_hba
*phba
)
3387 phba
->lpfc_stop_port(phba
);
3391 * lpfc_fcf_redisc_wait_start_timer - Start fcf rediscover wait timer
3392 * @phba: Pointer to hba for which this call is being executed.
3394 * This routine starts the timer waiting for the FCF rediscovery to complete.
3397 lpfc_fcf_redisc_wait_start_timer(struct lpfc_hba
*phba
)
3399 unsigned long fcf_redisc_wait_tmo
=
3400 (jiffies
+ msecs_to_jiffies(LPFC_FCF_REDISCOVER_WAIT_TMO
));
3401 /* Start fcf rediscovery wait period timer */
3402 mod_timer(&phba
->fcf
.redisc_wait
, fcf_redisc_wait_tmo
);
3403 spin_lock_irq(&phba
->hbalock
);
3404 /* Allow action to new fcf asynchronous event */
3405 phba
->fcf
.fcf_flag
&= ~(FCF_AVAILABLE
| FCF_SCAN_DONE
);
3406 /* Mark the FCF rediscovery pending state */
3407 phba
->fcf
.fcf_flag
|= FCF_REDISC_PEND
;
3408 spin_unlock_irq(&phba
->hbalock
);
3412 * lpfc_sli4_fcf_redisc_wait_tmo - FCF table rediscover wait timeout
3413 * @ptr: Map to lpfc_hba data structure pointer.
3415 * This routine is invoked when waiting for FCF table rediscover has been
3416 * timed out. If new FCF record(s) has (have) been discovered during the
3417 * wait period, a new FCF event shall be added to the FCOE async event
3418 * list, and then worker thread shall be waked up for processing from the
3419 * worker thread context.
3422 lpfc_sli4_fcf_redisc_wait_tmo(unsigned long ptr
)
3424 struct lpfc_hba
*phba
= (struct lpfc_hba
*)ptr
;
3426 /* Don't send FCF rediscovery event if timer cancelled */
3427 spin_lock_irq(&phba
->hbalock
);
3428 if (!(phba
->fcf
.fcf_flag
& FCF_REDISC_PEND
)) {
3429 spin_unlock_irq(&phba
->hbalock
);
3432 /* Clear FCF rediscovery timer pending flag */
3433 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_PEND
;
3434 /* FCF rediscovery event to worker thread */
3435 phba
->fcf
.fcf_flag
|= FCF_REDISC_EVT
;
3436 spin_unlock_irq(&phba
->hbalock
);
3437 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
,
3438 "2776 FCF rediscover quiescent timer expired\n");
3439 /* wake up worker thread */
3440 lpfc_worker_wake_up(phba
);
3444 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
3445 * @phba: pointer to lpfc hba data structure.
3446 * @acqe_link: pointer to the async link completion queue entry.
3448 * This routine is to parse the SLI4 link-attention link fault code and
3449 * translate it into the base driver's read link attention mailbox command
3452 * Return: Link-attention status in terms of base driver's coding.
3455 lpfc_sli4_parse_latt_fault(struct lpfc_hba
*phba
,
3456 struct lpfc_acqe_link
*acqe_link
)
3458 uint16_t latt_fault
;
3460 switch (bf_get(lpfc_acqe_link_fault
, acqe_link
)) {
3461 case LPFC_ASYNC_LINK_FAULT_NONE
:
3462 case LPFC_ASYNC_LINK_FAULT_LOCAL
:
3463 case LPFC_ASYNC_LINK_FAULT_REMOTE
:
3467 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3468 "0398 Invalid link fault code: x%x\n",
3469 bf_get(lpfc_acqe_link_fault
, acqe_link
));
3470 latt_fault
= MBXERR_ERROR
;
3477 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
3478 * @phba: pointer to lpfc hba data structure.
3479 * @acqe_link: pointer to the async link completion queue entry.
3481 * This routine is to parse the SLI4 link attention type and translate it
3482 * into the base driver's link attention type coding.
3484 * Return: Link attention type in terms of base driver's coding.
3487 lpfc_sli4_parse_latt_type(struct lpfc_hba
*phba
,
3488 struct lpfc_acqe_link
*acqe_link
)
3492 switch (bf_get(lpfc_acqe_link_status
, acqe_link
)) {
3493 case LPFC_ASYNC_LINK_STATUS_DOWN
:
3494 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN
:
3495 att_type
= LPFC_ATT_LINK_DOWN
;
3497 case LPFC_ASYNC_LINK_STATUS_UP
:
3498 /* Ignore physical link up events - wait for logical link up */
3499 att_type
= LPFC_ATT_RESERVED
;
3501 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP
:
3502 att_type
= LPFC_ATT_LINK_UP
;
3505 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3506 "0399 Invalid link attention type: x%x\n",
3507 bf_get(lpfc_acqe_link_status
, acqe_link
));
3508 att_type
= LPFC_ATT_RESERVED
;
3515 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
3516 * @phba: pointer to lpfc hba data structure.
3517 * @acqe_link: pointer to the async link completion queue entry.
3519 * This routine is to parse the SLI4 link-attention link speed and translate
3520 * it into the base driver's link-attention link speed coding.
3522 * Return: Link-attention link speed in terms of base driver's coding.
3525 lpfc_sli4_parse_latt_link_speed(struct lpfc_hba
*phba
,
3526 struct lpfc_acqe_link
*acqe_link
)
3530 switch (bf_get(lpfc_acqe_link_speed
, acqe_link
)) {
3531 case LPFC_ASYNC_LINK_SPEED_ZERO
:
3532 case LPFC_ASYNC_LINK_SPEED_10MBPS
:
3533 case LPFC_ASYNC_LINK_SPEED_100MBPS
:
3534 link_speed
= LPFC_LINK_SPEED_UNKNOWN
;
3536 case LPFC_ASYNC_LINK_SPEED_1GBPS
:
3537 link_speed
= LPFC_LINK_SPEED_1GHZ
;
3539 case LPFC_ASYNC_LINK_SPEED_10GBPS
:
3540 link_speed
= LPFC_LINK_SPEED_10GHZ
;
3543 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
3544 "0483 Invalid link-attention link speed: x%x\n",
3545 bf_get(lpfc_acqe_link_speed
, acqe_link
));
3546 link_speed
= LPFC_LINK_SPEED_UNKNOWN
;
3553 * lpfc_sli_port_speed_get - Get sli3 link speed code to link speed
3554 * @phba: pointer to lpfc hba data structure.
3556 * This routine is to get an SLI3 FC port's link speed in Mbps.
3558 * Return: link speed in terms of Mbps.
3561 lpfc_sli_port_speed_get(struct lpfc_hba
*phba
)
3563 uint32_t link_speed
;
3565 if (!lpfc_is_link_up(phba
))
3568 switch (phba
->fc_linkspeed
) {
3569 case LPFC_LINK_SPEED_1GHZ
:
3572 case LPFC_LINK_SPEED_2GHZ
:
3575 case LPFC_LINK_SPEED_4GHZ
:
3578 case LPFC_LINK_SPEED_8GHZ
:
3581 case LPFC_LINK_SPEED_10GHZ
:
3584 case LPFC_LINK_SPEED_16GHZ
:
3594 * lpfc_sli4_port_speed_parse - Parse async evt link speed code to link speed
3595 * @phba: pointer to lpfc hba data structure.
3596 * @evt_code: asynchronous event code.
3597 * @speed_code: asynchronous event link speed code.
3599 * This routine is to parse the giving SLI4 async event link speed code into
3600 * value of Mbps for the link speed.
3602 * Return: link speed in terms of Mbps.
3605 lpfc_sli4_port_speed_parse(struct lpfc_hba
*phba
, uint32_t evt_code
,
3608 uint32_t port_speed
;
3611 case LPFC_TRAILER_CODE_LINK
:
3612 switch (speed_code
) {
3613 case LPFC_EVT_CODE_LINK_NO_LINK
:
3616 case LPFC_EVT_CODE_LINK_10_MBIT
:
3619 case LPFC_EVT_CODE_LINK_100_MBIT
:
3622 case LPFC_EVT_CODE_LINK_1_GBIT
:
3625 case LPFC_EVT_CODE_LINK_10_GBIT
:
3632 case LPFC_TRAILER_CODE_FC
:
3633 switch (speed_code
) {
3634 case LPFC_EVT_CODE_FC_NO_LINK
:
3637 case LPFC_EVT_CODE_FC_1_GBAUD
:
3640 case LPFC_EVT_CODE_FC_2_GBAUD
:
3643 case LPFC_EVT_CODE_FC_4_GBAUD
:
3646 case LPFC_EVT_CODE_FC_8_GBAUD
:
3649 case LPFC_EVT_CODE_FC_10_GBAUD
:
3652 case LPFC_EVT_CODE_FC_16_GBAUD
:
3666 * lpfc_sli4_async_link_evt - Process the asynchronous FCoE link event
3667 * @phba: pointer to lpfc hba data structure.
3668 * @acqe_link: pointer to the async link completion queue entry.
3670 * This routine is to handle the SLI4 asynchronous FCoE link event.
3673 lpfc_sli4_async_link_evt(struct lpfc_hba
*phba
,
3674 struct lpfc_acqe_link
*acqe_link
)
3676 struct lpfc_dmabuf
*mp
;
3679 struct lpfc_mbx_read_top
*la
;
3683 att_type
= lpfc_sli4_parse_latt_type(phba
, acqe_link
);
3684 if (att_type
!= LPFC_ATT_LINK_DOWN
&& att_type
!= LPFC_ATT_LINK_UP
)
3686 phba
->fcoe_eventtag
= acqe_link
->event_tag
;
3687 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3689 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3690 "0395 The mboxq allocation failed\n");
3693 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
3695 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3696 "0396 The lpfc_dmabuf allocation failed\n");
3699 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
3701 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3702 "0397 The mbuf allocation failed\n");
3703 goto out_free_dmabuf
;
3706 /* Cleanup any outstanding ELS commands */
3707 lpfc_els_flush_all_cmd(phba
);
3709 /* Block ELS IOCBs until we have done process link event */
3710 phba
->sli
.ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
3712 /* Update link event statistics */
3713 phba
->sli
.slistat
.link_event
++;
3715 /* Create lpfc_handle_latt mailbox command from link ACQE */
3716 lpfc_read_topology(phba
, pmb
, mp
);
3717 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
3718 pmb
->vport
= phba
->pport
;
3720 /* Keep the link status for extra SLI4 state machine reference */
3721 phba
->sli4_hba
.link_state
.speed
=
3722 lpfc_sli4_port_speed_parse(phba
, LPFC_TRAILER_CODE_LINK
,
3723 bf_get(lpfc_acqe_link_speed
, acqe_link
));
3724 phba
->sli4_hba
.link_state
.duplex
=
3725 bf_get(lpfc_acqe_link_duplex
, acqe_link
);
3726 phba
->sli4_hba
.link_state
.status
=
3727 bf_get(lpfc_acqe_link_status
, acqe_link
);
3728 phba
->sli4_hba
.link_state
.type
=
3729 bf_get(lpfc_acqe_link_type
, acqe_link
);
3730 phba
->sli4_hba
.link_state
.number
=
3731 bf_get(lpfc_acqe_link_number
, acqe_link
);
3732 phba
->sli4_hba
.link_state
.fault
=
3733 bf_get(lpfc_acqe_link_fault
, acqe_link
);
3734 phba
->sli4_hba
.link_state
.logical_speed
=
3735 bf_get(lpfc_acqe_logical_link_speed
, acqe_link
) * 10;
3737 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3738 "2900 Async FC/FCoE Link event - Speed:%dGBit "
3739 "duplex:x%x LA Type:x%x Port Type:%d Port Number:%d "
3740 "Logical speed:%dMbps Fault:%d\n",
3741 phba
->sli4_hba
.link_state
.speed
,
3742 phba
->sli4_hba
.link_state
.topology
,
3743 phba
->sli4_hba
.link_state
.status
,
3744 phba
->sli4_hba
.link_state
.type
,
3745 phba
->sli4_hba
.link_state
.number
,
3746 phba
->sli4_hba
.link_state
.logical_speed
,
3747 phba
->sli4_hba
.link_state
.fault
);
3749 * For FC Mode: issue the READ_TOPOLOGY mailbox command to fetch
3750 * topology info. Note: Optional for non FC-AL ports.
3752 if (!(phba
->hba_flag
& HBA_FCOE_MODE
)) {
3753 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3754 if (rc
== MBX_NOT_FINISHED
)
3755 goto out_free_dmabuf
;
3759 * For FCoE Mode: fill in all the topology information we need and call
3760 * the READ_TOPOLOGY completion routine to continue without actually
3761 * sending the READ_TOPOLOGY mailbox command to the port.
3763 /* Parse and translate status field */
3765 mb
->mbxStatus
= lpfc_sli4_parse_latt_fault(phba
, acqe_link
);
3767 /* Parse and translate link attention fields */
3768 la
= (struct lpfc_mbx_read_top
*) &pmb
->u
.mb
.un
.varReadTop
;
3769 la
->eventTag
= acqe_link
->event_tag
;
3770 bf_set(lpfc_mbx_read_top_att_type
, la
, att_type
);
3771 bf_set(lpfc_mbx_read_top_link_spd
, la
,
3772 lpfc_sli4_parse_latt_link_speed(phba
, acqe_link
));
3774 /* Fake the the following irrelvant fields */
3775 bf_set(lpfc_mbx_read_top_topology
, la
, LPFC_TOPOLOGY_PT_PT
);
3776 bf_set(lpfc_mbx_read_top_alpa_granted
, la
, 0);
3777 bf_set(lpfc_mbx_read_top_il
, la
, 0);
3778 bf_set(lpfc_mbx_read_top_pb
, la
, 0);
3779 bf_set(lpfc_mbx_read_top_fa
, la
, 0);
3780 bf_set(lpfc_mbx_read_top_mm
, la
, 0);
3782 /* Invoke the lpfc_handle_latt mailbox command callback function */
3783 lpfc_mbx_cmpl_read_topology(phba
, pmb
);
3790 mempool_free(pmb
, phba
->mbox_mem_pool
);
3794 * lpfc_sli4_async_fc_evt - Process the asynchronous FC link event
3795 * @phba: pointer to lpfc hba data structure.
3796 * @acqe_fc: pointer to the async fc completion queue entry.
3798 * This routine is to handle the SLI4 asynchronous FC event. It will simply log
3799 * that the event was received and then issue a read_topology mailbox command so
3800 * that the rest of the driver will treat it the same as SLI3.
3803 lpfc_sli4_async_fc_evt(struct lpfc_hba
*phba
, struct lpfc_acqe_fc_la
*acqe_fc
)
3805 struct lpfc_dmabuf
*mp
;
3809 if (bf_get(lpfc_trailer_type
, acqe_fc
) !=
3810 LPFC_FC_LA_EVENT_TYPE_FC_LINK
) {
3811 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3812 "2895 Non FC link Event detected.(%d)\n",
3813 bf_get(lpfc_trailer_type
, acqe_fc
));
3816 /* Keep the link status for extra SLI4 state machine reference */
3817 phba
->sli4_hba
.link_state
.speed
=
3818 lpfc_sli4_port_speed_parse(phba
, LPFC_TRAILER_CODE_FC
,
3819 bf_get(lpfc_acqe_fc_la_speed
, acqe_fc
));
3820 phba
->sli4_hba
.link_state
.duplex
= LPFC_ASYNC_LINK_DUPLEX_FULL
;
3821 phba
->sli4_hba
.link_state
.topology
=
3822 bf_get(lpfc_acqe_fc_la_topology
, acqe_fc
);
3823 phba
->sli4_hba
.link_state
.status
=
3824 bf_get(lpfc_acqe_fc_la_att_type
, acqe_fc
);
3825 phba
->sli4_hba
.link_state
.type
=
3826 bf_get(lpfc_acqe_fc_la_port_type
, acqe_fc
);
3827 phba
->sli4_hba
.link_state
.number
=
3828 bf_get(lpfc_acqe_fc_la_port_number
, acqe_fc
);
3829 phba
->sli4_hba
.link_state
.fault
=
3830 bf_get(lpfc_acqe_link_fault
, acqe_fc
);
3831 phba
->sli4_hba
.link_state
.logical_speed
=
3832 bf_get(lpfc_acqe_fc_la_llink_spd
, acqe_fc
) * 10;
3833 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3834 "2896 Async FC event - Speed:%dGBaud Topology:x%x "
3835 "LA Type:x%x Port Type:%d Port Number:%d Logical speed:"
3836 "%dMbps Fault:%d\n",
3837 phba
->sli4_hba
.link_state
.speed
,
3838 phba
->sli4_hba
.link_state
.topology
,
3839 phba
->sli4_hba
.link_state
.status
,
3840 phba
->sli4_hba
.link_state
.type
,
3841 phba
->sli4_hba
.link_state
.number
,
3842 phba
->sli4_hba
.link_state
.logical_speed
,
3843 phba
->sli4_hba
.link_state
.fault
);
3844 pmb
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3846 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3847 "2897 The mboxq allocation failed\n");
3850 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
3852 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3853 "2898 The lpfc_dmabuf allocation failed\n");
3856 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
3858 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3859 "2899 The mbuf allocation failed\n");
3860 goto out_free_dmabuf
;
3863 /* Cleanup any outstanding ELS commands */
3864 lpfc_els_flush_all_cmd(phba
);
3866 /* Block ELS IOCBs until we have done process link event */
3867 phba
->sli
.ring
[LPFC_ELS_RING
].flag
|= LPFC_STOP_IOCB_EVENT
;
3869 /* Update link event statistics */
3870 phba
->sli
.slistat
.link_event
++;
3872 /* Create lpfc_handle_latt mailbox command from link ACQE */
3873 lpfc_read_topology(phba
, pmb
, mp
);
3874 pmb
->mbox_cmpl
= lpfc_mbx_cmpl_read_topology
;
3875 pmb
->vport
= phba
->pport
;
3877 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
3878 if (rc
== MBX_NOT_FINISHED
)
3879 goto out_free_dmabuf
;
3885 mempool_free(pmb
, phba
->mbox_mem_pool
);
3889 * lpfc_sli4_async_sli_evt - Process the asynchronous SLI link event
3890 * @phba: pointer to lpfc hba data structure.
3891 * @acqe_fc: pointer to the async SLI completion queue entry.
3893 * This routine is to handle the SLI4 asynchronous SLI events.
3896 lpfc_sli4_async_sli_evt(struct lpfc_hba
*phba
, struct lpfc_acqe_sli
*acqe_sli
)
3901 struct lpfc_acqe_misconfigured_event
*misconfigured
;
3903 /* special case misconfigured event as it contains data for all ports */
3904 if ((bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
3905 LPFC_SLI_INTF_IF_TYPE_2
) ||
3906 (bf_get(lpfc_trailer_type
, acqe_sli
) !=
3907 LPFC_SLI_EVENT_TYPE_MISCONFIGURED
)) {
3908 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
3909 "2901 Async SLI event - Event Data1:x%08x Event Data2:"
3910 "x%08x SLI Event Type:%d\n",
3911 acqe_sli
->event_data1
, acqe_sli
->event_data2
,
3912 bf_get(lpfc_trailer_type
, acqe_sli
));
3916 port_name
= phba
->Port
[0];
3917 if (port_name
== 0x00)
3918 port_name
= '?'; /* get port name is empty */
3920 misconfigured
= (struct lpfc_acqe_misconfigured_event
*)
3921 &acqe_sli
->event_data1
;
3923 /* fetch the status for this port */
3924 switch (phba
->sli4_hba
.lnk_info
.lnk_no
) {
3925 case LPFC_LINK_NUMBER_0
:
3926 status
= bf_get(lpfc_sli_misconfigured_port0
,
3927 &misconfigured
->theEvent
);
3929 case LPFC_LINK_NUMBER_1
:
3930 status
= bf_get(lpfc_sli_misconfigured_port1
,
3931 &misconfigured
->theEvent
);
3933 case LPFC_LINK_NUMBER_2
:
3934 status
= bf_get(lpfc_sli_misconfigured_port2
,
3935 &misconfigured
->theEvent
);
3937 case LPFC_LINK_NUMBER_3
:
3938 status
= bf_get(lpfc_sli_misconfigured_port3
,
3939 &misconfigured
->theEvent
);
3942 status
= ~LPFC_SLI_EVENT_STATUS_VALID
;
3947 case LPFC_SLI_EVENT_STATUS_VALID
:
3948 return; /* no message if the sfp is okay */
3949 case LPFC_SLI_EVENT_STATUS_NOT_PRESENT
:
3950 sprintf(message
, "Optics faulted/incorrectly installed/not " \
3951 "installed - Reseat optics, if issue not "
3952 "resolved, replace.");
3954 case LPFC_SLI_EVENT_STATUS_WRONG_TYPE
:
3956 "Optics of two types installed - Remove one optic or " \
3957 "install matching pair of optics.");
3959 case LPFC_SLI_EVENT_STATUS_UNSUPPORTED
:
3960 sprintf(message
, "Incompatible optics - Replace with " \
3961 "compatible optics for card to function.");
3964 /* firmware is reporting a status we don't know about */
3965 sprintf(message
, "Unknown event status x%02x", status
);
3969 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
3970 "3176 Misconfigured Physical Port - "
3971 "Port Name %c %s\n", port_name
, message
);
3975 * lpfc_sli4_perform_vport_cvl - Perform clear virtual link on a vport
3976 * @vport: pointer to vport data structure.
3978 * This routine is to perform Clear Virtual Link (CVL) on a vport in
3979 * response to a CVL event.
3981 * Return the pointer to the ndlp with the vport if successful, otherwise
3984 static struct lpfc_nodelist
*
3985 lpfc_sli4_perform_vport_cvl(struct lpfc_vport
*vport
)
3987 struct lpfc_nodelist
*ndlp
;
3988 struct Scsi_Host
*shost
;
3989 struct lpfc_hba
*phba
;
3996 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
3998 /* Cannot find existing Fabric ndlp, so allocate a new one */
3999 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
4002 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
4003 /* Set the node type */
4004 ndlp
->nlp_type
|= NLP_FABRIC
;
4005 /* Put ndlp onto node list */
4006 lpfc_enqueue_node(vport
, ndlp
);
4007 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
4008 /* re-setup ndlp without removing from node list */
4009 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
4013 if ((phba
->pport
->port_state
< LPFC_FLOGI
) &&
4014 (phba
->pport
->port_state
!= LPFC_VPORT_FAILED
))
4016 /* If virtual link is not yet instantiated ignore CVL */
4017 if ((vport
!= phba
->pport
) && (vport
->port_state
< LPFC_FDISC
)
4018 && (vport
->port_state
!= LPFC_VPORT_FAILED
))
4020 shost
= lpfc_shost_from_vport(vport
);
4023 lpfc_linkdown_port(vport
);
4024 lpfc_cleanup_pending_mbox(vport
);
4025 spin_lock_irq(shost
->host_lock
);
4026 vport
->fc_flag
|= FC_VPORT_CVL_RCVD
;
4027 spin_unlock_irq(shost
->host_lock
);
4033 * lpfc_sli4_perform_all_vport_cvl - Perform clear virtual link on all vports
4034 * @vport: pointer to lpfc hba data structure.
4036 * This routine is to perform Clear Virtual Link (CVL) on all vports in
4037 * response to a FCF dead event.
4040 lpfc_sli4_perform_all_vport_cvl(struct lpfc_hba
*phba
)
4042 struct lpfc_vport
**vports
;
4045 vports
= lpfc_create_vport_work_array(phba
);
4047 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++)
4048 lpfc_sli4_perform_vport_cvl(vports
[i
]);
4049 lpfc_destroy_vport_work_array(phba
, vports
);
4053 * lpfc_sli4_perform_inuse_fcf_recovery - Perform inuse fcf recovery
4054 * @vport: pointer to lpfc hba data structure.
4056 * This routine is to perform FCF recovery when the in-use FCF either dead or
4060 lpfc_sli4_perform_inuse_fcf_recovery(struct lpfc_hba
*phba
,
4061 struct lpfc_acqe_fip
*acqe_fip
)
4065 spin_lock_irq(&phba
->hbalock
);
4066 /* Mark the fast failover process in progress */
4067 phba
->fcf
.fcf_flag
|= FCF_DEAD_DISC
;
4068 spin_unlock_irq(&phba
->hbalock
);
4070 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
4071 "2771 Start FCF fast failover process due to in-use "
4072 "FCF DEAD/MODIFIED event: evt_tag:x%x, index:x%x\n",
4073 acqe_fip
->event_tag
, acqe_fip
->index
);
4074 rc
= lpfc_sli4_redisc_fcf_table(phba
);
4076 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4077 "2772 Issue FCF rediscover mabilbox command "
4078 "failed, fail through to FCF dead event\n");
4079 spin_lock_irq(&phba
->hbalock
);
4080 phba
->fcf
.fcf_flag
&= ~FCF_DEAD_DISC
;
4081 spin_unlock_irq(&phba
->hbalock
);
4083 * Last resort will fail over by treating this as a link
4084 * down to FCF registration.
4086 lpfc_sli4_fcf_dead_failthrough(phba
);
4088 /* Reset FCF roundrobin bmask for new discovery */
4089 lpfc_sli4_clear_fcf_rr_bmask(phba
);
4091 * Handling fast FCF failover to a DEAD FCF event is
4092 * considered equalivant to receiving CVL to all vports.
4094 lpfc_sli4_perform_all_vport_cvl(phba
);
4099 * lpfc_sli4_async_fip_evt - Process the asynchronous FCoE FIP event
4100 * @phba: pointer to lpfc hba data structure.
4101 * @acqe_link: pointer to the async fcoe completion queue entry.
4103 * This routine is to handle the SLI4 asynchronous fcoe event.
4106 lpfc_sli4_async_fip_evt(struct lpfc_hba
*phba
,
4107 struct lpfc_acqe_fip
*acqe_fip
)
4109 uint8_t event_type
= bf_get(lpfc_trailer_type
, acqe_fip
);
4111 struct lpfc_vport
*vport
;
4112 struct lpfc_nodelist
*ndlp
;
4113 struct Scsi_Host
*shost
;
4114 int active_vlink_present
;
4115 struct lpfc_vport
**vports
;
4118 phba
->fc_eventTag
= acqe_fip
->event_tag
;
4119 phba
->fcoe_eventtag
= acqe_fip
->event_tag
;
4120 switch (event_type
) {
4121 case LPFC_FIP_EVENT_TYPE_NEW_FCF
:
4122 case LPFC_FIP_EVENT_TYPE_FCF_PARAM_MOD
:
4123 if (event_type
== LPFC_FIP_EVENT_TYPE_NEW_FCF
)
4124 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
4126 "2546 New FCF event, evt_tag:x%x, "
4128 acqe_fip
->event_tag
,
4131 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
|
4133 "2788 FCF param modified event, "
4134 "evt_tag:x%x, index:x%x\n",
4135 acqe_fip
->event_tag
,
4137 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
4139 * During period of FCF discovery, read the FCF
4140 * table record indexed by the event to update
4141 * FCF roundrobin failover eligible FCF bmask.
4143 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
4145 "2779 Read FCF (x%x) for updating "
4146 "roundrobin FCF failover bmask\n",
4148 rc
= lpfc_sli4_read_fcf_rec(phba
, acqe_fip
->index
);
4151 /* If the FCF discovery is in progress, do nothing. */
4152 spin_lock_irq(&phba
->hbalock
);
4153 if (phba
->hba_flag
& FCF_TS_INPROG
) {
4154 spin_unlock_irq(&phba
->hbalock
);
4157 /* If fast FCF failover rescan event is pending, do nothing */
4158 if (phba
->fcf
.fcf_flag
& FCF_REDISC_EVT
) {
4159 spin_unlock_irq(&phba
->hbalock
);
4163 /* If FCF has been in discovered state, perform rediscovery
4164 * only if the FCF with the same index of the in-use FCF got
4165 * modified during normal operation. Otherwise, do nothing.
4167 if (phba
->pport
->port_state
> LPFC_FLOGI
) {
4168 spin_unlock_irq(&phba
->hbalock
);
4169 if (phba
->fcf
.current_rec
.fcf_indx
==
4171 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
,
4172 "3300 In-use FCF (%d) "
4173 "modified, perform FCF "
4176 lpfc_sli4_perform_inuse_fcf_recovery(phba
,
4181 spin_unlock_irq(&phba
->hbalock
);
4183 /* Otherwise, scan the entire FCF table and re-discover SAN */
4184 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
4185 "2770 Start FCF table scan per async FCF "
4186 "event, evt_tag:x%x, index:x%x\n",
4187 acqe_fip
->event_tag
, acqe_fip
->index
);
4188 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
,
4189 LPFC_FCOE_FCF_GET_FIRST
);
4191 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4192 "2547 Issue FCF scan read FCF mailbox "
4193 "command failed (x%x)\n", rc
);
4196 case LPFC_FIP_EVENT_TYPE_FCF_TABLE_FULL
:
4197 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4198 "2548 FCF Table full count 0x%x tag 0x%x\n",
4199 bf_get(lpfc_acqe_fip_fcf_count
, acqe_fip
),
4200 acqe_fip
->event_tag
);
4203 case LPFC_FIP_EVENT_TYPE_FCF_DEAD
:
4204 phba
->fcoe_cvl_eventtag
= acqe_fip
->event_tag
;
4205 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4206 "2549 FCF (x%x) disconnected from network, "
4207 "tag:x%x\n", acqe_fip
->index
, acqe_fip
->event_tag
);
4209 * If we are in the middle of FCF failover process, clear
4210 * the corresponding FCF bit in the roundrobin bitmap.
4212 spin_lock_irq(&phba
->hbalock
);
4213 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
4214 spin_unlock_irq(&phba
->hbalock
);
4215 /* Update FLOGI FCF failover eligible FCF bmask */
4216 lpfc_sli4_fcf_rr_index_clear(phba
, acqe_fip
->index
);
4219 spin_unlock_irq(&phba
->hbalock
);
4221 /* If the event is not for currently used fcf do nothing */
4222 if (phba
->fcf
.current_rec
.fcf_indx
!= acqe_fip
->index
)
4226 * Otherwise, request the port to rediscover the entire FCF
4227 * table for a fast recovery from case that the current FCF
4228 * is no longer valid as we are not in the middle of FCF
4229 * failover process already.
4231 lpfc_sli4_perform_inuse_fcf_recovery(phba
, acqe_fip
);
4233 case LPFC_FIP_EVENT_TYPE_CVL
:
4234 phba
->fcoe_cvl_eventtag
= acqe_fip
->event_tag
;
4235 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4236 "2718 Clear Virtual Link Received for VPI 0x%x"
4237 " tag 0x%x\n", acqe_fip
->index
, acqe_fip
->event_tag
);
4239 vport
= lpfc_find_vport_by_vpid(phba
,
4241 ndlp
= lpfc_sli4_perform_vport_cvl(vport
);
4244 active_vlink_present
= 0;
4246 vports
= lpfc_create_vport_work_array(phba
);
4248 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
4250 if ((!(vports
[i
]->fc_flag
&
4251 FC_VPORT_CVL_RCVD
)) &&
4252 (vports
[i
]->port_state
> LPFC_FDISC
)) {
4253 active_vlink_present
= 1;
4257 lpfc_destroy_vport_work_array(phba
, vports
);
4260 if (active_vlink_present
) {
4262 * If there are other active VLinks present,
4263 * re-instantiate the Vlink using FDISC.
4265 mod_timer(&ndlp
->nlp_delayfunc
,
4266 jiffies
+ msecs_to_jiffies(1000));
4267 shost
= lpfc_shost_from_vport(vport
);
4268 spin_lock_irq(shost
->host_lock
);
4269 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
4270 spin_unlock_irq(shost
->host_lock
);
4271 ndlp
->nlp_last_elscmd
= ELS_CMD_FDISC
;
4272 vport
->port_state
= LPFC_FDISC
;
4275 * Otherwise, we request port to rediscover
4276 * the entire FCF table for a fast recovery
4277 * from possible case that the current FCF
4278 * is no longer valid if we are not already
4279 * in the FCF failover process.
4281 spin_lock_irq(&phba
->hbalock
);
4282 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
4283 spin_unlock_irq(&phba
->hbalock
);
4286 /* Mark the fast failover process in progress */
4287 phba
->fcf
.fcf_flag
|= FCF_ACVL_DISC
;
4288 spin_unlock_irq(&phba
->hbalock
);
4289 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
|
4291 "2773 Start FCF failover per CVL, "
4292 "evt_tag:x%x\n", acqe_fip
->event_tag
);
4293 rc
= lpfc_sli4_redisc_fcf_table(phba
);
4295 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
|
4297 "2774 Issue FCF rediscover "
4298 "mabilbox command failed, "
4299 "through to CVL event\n");
4300 spin_lock_irq(&phba
->hbalock
);
4301 phba
->fcf
.fcf_flag
&= ~FCF_ACVL_DISC
;
4302 spin_unlock_irq(&phba
->hbalock
);
4304 * Last resort will be re-try on the
4305 * the current registered FCF entry.
4307 lpfc_retry_pport_discovery(phba
);
4310 * Reset FCF roundrobin bmask for new
4313 lpfc_sli4_clear_fcf_rr_bmask(phba
);
4317 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4318 "0288 Unknown FCoE event type 0x%x event tag "
4319 "0x%x\n", event_type
, acqe_fip
->event_tag
);
4325 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
4326 * @phba: pointer to lpfc hba data structure.
4327 * @acqe_link: pointer to the async dcbx completion queue entry.
4329 * This routine is to handle the SLI4 asynchronous dcbx event.
4332 lpfc_sli4_async_dcbx_evt(struct lpfc_hba
*phba
,
4333 struct lpfc_acqe_dcbx
*acqe_dcbx
)
4335 phba
->fc_eventTag
= acqe_dcbx
->event_tag
;
4336 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4337 "0290 The SLI4 DCBX asynchronous event is not "
4342 * lpfc_sli4_async_grp5_evt - Process the asynchronous group5 event
4343 * @phba: pointer to lpfc hba data structure.
4344 * @acqe_link: pointer to the async grp5 completion queue entry.
4346 * This routine is to handle the SLI4 asynchronous grp5 event. A grp5 event
4347 * is an asynchronous notified of a logical link speed change. The Port
4348 * reports the logical link speed in units of 10Mbps.
4351 lpfc_sli4_async_grp5_evt(struct lpfc_hba
*phba
,
4352 struct lpfc_acqe_grp5
*acqe_grp5
)
4354 uint16_t prev_ll_spd
;
4356 phba
->fc_eventTag
= acqe_grp5
->event_tag
;
4357 phba
->fcoe_eventtag
= acqe_grp5
->event_tag
;
4358 prev_ll_spd
= phba
->sli4_hba
.link_state
.logical_speed
;
4359 phba
->sli4_hba
.link_state
.logical_speed
=
4360 (bf_get(lpfc_acqe_grp5_llink_spd
, acqe_grp5
)) * 10;
4361 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
4362 "2789 GRP5 Async Event: Updating logical link speed "
4363 "from %dMbps to %dMbps\n", prev_ll_spd
,
4364 phba
->sli4_hba
.link_state
.logical_speed
);
4368 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
4369 * @phba: pointer to lpfc hba data structure.
4371 * This routine is invoked by the worker thread to process all the pending
4372 * SLI4 asynchronous events.
4374 void lpfc_sli4_async_event_proc(struct lpfc_hba
*phba
)
4376 struct lpfc_cq_event
*cq_event
;
4378 /* First, declare the async event has been handled */
4379 spin_lock_irq(&phba
->hbalock
);
4380 phba
->hba_flag
&= ~ASYNC_EVENT
;
4381 spin_unlock_irq(&phba
->hbalock
);
4382 /* Now, handle all the async events */
4383 while (!list_empty(&phba
->sli4_hba
.sp_asynce_work_queue
)) {
4384 /* Get the first event from the head of the event queue */
4385 spin_lock_irq(&phba
->hbalock
);
4386 list_remove_head(&phba
->sli4_hba
.sp_asynce_work_queue
,
4387 cq_event
, struct lpfc_cq_event
, list
);
4388 spin_unlock_irq(&phba
->hbalock
);
4389 /* Process the asynchronous event */
4390 switch (bf_get(lpfc_trailer_code
, &cq_event
->cqe
.mcqe_cmpl
)) {
4391 case LPFC_TRAILER_CODE_LINK
:
4392 lpfc_sli4_async_link_evt(phba
,
4393 &cq_event
->cqe
.acqe_link
);
4395 case LPFC_TRAILER_CODE_FCOE
:
4396 lpfc_sli4_async_fip_evt(phba
, &cq_event
->cqe
.acqe_fip
);
4398 case LPFC_TRAILER_CODE_DCBX
:
4399 lpfc_sli4_async_dcbx_evt(phba
,
4400 &cq_event
->cqe
.acqe_dcbx
);
4402 case LPFC_TRAILER_CODE_GRP5
:
4403 lpfc_sli4_async_grp5_evt(phba
,
4404 &cq_event
->cqe
.acqe_grp5
);
4406 case LPFC_TRAILER_CODE_FC
:
4407 lpfc_sli4_async_fc_evt(phba
, &cq_event
->cqe
.acqe_fc
);
4409 case LPFC_TRAILER_CODE_SLI
:
4410 lpfc_sli4_async_sli_evt(phba
, &cq_event
->cqe
.acqe_sli
);
4413 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
4414 "1804 Invalid asynchrous event code: "
4415 "x%x\n", bf_get(lpfc_trailer_code
,
4416 &cq_event
->cqe
.mcqe_cmpl
));
4419 /* Free the completion event processed to the free pool */
4420 lpfc_sli4_cq_event_release(phba
, cq_event
);
4425 * lpfc_sli4_fcf_redisc_event_proc - Process fcf table rediscovery event
4426 * @phba: pointer to lpfc hba data structure.
4428 * This routine is invoked by the worker thread to process FCF table
4429 * rediscovery pending completion event.
4431 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba
*phba
)
4435 spin_lock_irq(&phba
->hbalock
);
4436 /* Clear FCF rediscovery timeout event */
4437 phba
->fcf
.fcf_flag
&= ~FCF_REDISC_EVT
;
4438 /* Clear driver fast failover FCF record flag */
4439 phba
->fcf
.failover_rec
.flag
= 0;
4440 /* Set state for FCF fast failover */
4441 phba
->fcf
.fcf_flag
|= FCF_REDISC_FOV
;
4442 spin_unlock_irq(&phba
->hbalock
);
4444 /* Scan FCF table from the first entry to re-discover SAN */
4445 lpfc_printf_log(phba
, KERN_INFO
, LOG_FIP
| LOG_DISCOVERY
,
4446 "2777 Start post-quiescent FCF table scan\n");
4447 rc
= lpfc_sli4_fcf_scan_read_fcf_rec(phba
, LPFC_FCOE_FCF_GET_FIRST
);
4449 lpfc_printf_log(phba
, KERN_ERR
, LOG_FIP
| LOG_DISCOVERY
,
4450 "2747 Issue FCF scan read FCF mailbox "
4451 "command failed 0x%x\n", rc
);
4455 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
4456 * @phba: pointer to lpfc hba data structure.
4457 * @dev_grp: The HBA PCI-Device group number.
4459 * This routine is invoked to set up the per HBA PCI-Device group function
4460 * API jump table entries.
4462 * Return: 0 if success, otherwise -ENODEV
4465 lpfc_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
4469 /* Set up lpfc PCI-device group */
4470 phba
->pci_dev_grp
= dev_grp
;
4472 /* The LPFC_PCI_DEV_OC uses SLI4 */
4473 if (dev_grp
== LPFC_PCI_DEV_OC
)
4474 phba
->sli_rev
= LPFC_SLI_REV4
;
4476 /* Set up device INIT API function jump table */
4477 rc
= lpfc_init_api_table_setup(phba
, dev_grp
);
4480 /* Set up SCSI API function jump table */
4481 rc
= lpfc_scsi_api_table_setup(phba
, dev_grp
);
4484 /* Set up SLI API function jump table */
4485 rc
= lpfc_sli_api_table_setup(phba
, dev_grp
);
4488 /* Set up MBOX API function jump table */
4489 rc
= lpfc_mbox_api_table_setup(phba
, dev_grp
);
4497 * lpfc_log_intr_mode - Log the active interrupt mode
4498 * @phba: pointer to lpfc hba data structure.
4499 * @intr_mode: active interrupt mode adopted.
4501 * This routine it invoked to log the currently used active interrupt mode
4504 static void lpfc_log_intr_mode(struct lpfc_hba
*phba
, uint32_t intr_mode
)
4506 switch (intr_mode
) {
4508 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4509 "0470 Enable INTx interrupt mode.\n");
4512 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4513 "0481 Enabled MSI interrupt mode.\n");
4516 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
4517 "0480 Enabled MSI-X interrupt mode.\n");
4520 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4521 "0482 Illegal interrupt mode.\n");
4528 * lpfc_enable_pci_dev - Enable a generic PCI device.
4529 * @phba: pointer to lpfc hba data structure.
4531 * This routine is invoked to enable the PCI device that is common to all
4536 * other values - error
4539 lpfc_enable_pci_dev(struct lpfc_hba
*phba
)
4541 struct pci_dev
*pdev
;
4544 /* Obtain PCI device reference */
4548 pdev
= phba
->pcidev
;
4549 /* Select PCI BARs */
4550 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
4551 /* Enable PCI device */
4552 if (pci_enable_device_mem(pdev
))
4554 /* Request PCI resource for the device */
4555 if (pci_request_selected_regions(pdev
, bars
, LPFC_DRIVER_NAME
))
4556 goto out_disable_device
;
4557 /* Set up device as PCI master and save state for EEH */
4558 pci_set_master(pdev
);
4559 pci_try_set_mwi(pdev
);
4560 pci_save_state(pdev
);
4562 /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
4563 if (pci_find_capability(pdev
, PCI_CAP_ID_EXP
))
4564 pdev
->needs_freset
= 1;
4569 pci_disable_device(pdev
);
4571 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4572 "1401 Failed to enable pci device, bars:x%x\n", bars
);
4577 * lpfc_disable_pci_dev - Disable a generic PCI device.
4578 * @phba: pointer to lpfc hba data structure.
4580 * This routine is invoked to disable the PCI device that is common to all
4584 lpfc_disable_pci_dev(struct lpfc_hba
*phba
)
4586 struct pci_dev
*pdev
;
4589 /* Obtain PCI device reference */
4593 pdev
= phba
->pcidev
;
4594 /* Select PCI BARs */
4595 bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
4596 /* Release PCI resource and disable PCI device */
4597 pci_release_selected_regions(pdev
, bars
);
4598 pci_disable_device(pdev
);
4599 /* Null out PCI private reference to driver */
4600 pci_set_drvdata(pdev
, NULL
);
4606 * lpfc_reset_hba - Reset a hba
4607 * @phba: pointer to lpfc hba data structure.
4609 * This routine is invoked to reset a hba device. It brings the HBA
4610 * offline, performs a board restart, and then brings the board back
4611 * online. The lpfc_offline calls lpfc_sli_hba_down which will clean up
4612 * on outstanding mailbox commands.
4615 lpfc_reset_hba(struct lpfc_hba
*phba
)
4617 /* If resets are disabled then set error state and return. */
4618 if (!phba
->cfg_enable_hba_reset
) {
4619 phba
->link_state
= LPFC_HBA_ERROR
;
4622 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
4624 lpfc_sli_brdrestart(phba
);
4626 lpfc_unblock_mgmt_io(phba
);
4630 * lpfc_sli_sriov_nr_virtfn_get - Get the number of sr-iov virtual functions
4631 * @phba: pointer to lpfc hba data structure.
4633 * This function enables the PCI SR-IOV virtual functions to a physical
4634 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4635 * enable the number of virtual functions to the physical function. As
4636 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4637 * API call does not considered as an error condition for most of the device.
4640 lpfc_sli_sriov_nr_virtfn_get(struct lpfc_hba
*phba
)
4642 struct pci_dev
*pdev
= phba
->pcidev
;
4646 pos
= pci_find_ext_capability(pdev
, PCI_EXT_CAP_ID_SRIOV
);
4650 pci_read_config_word(pdev
, pos
+ PCI_SRIOV_TOTAL_VF
, &nr_virtfn
);
4655 * lpfc_sli_probe_sriov_nr_virtfn - Enable a number of sr-iov virtual functions
4656 * @phba: pointer to lpfc hba data structure.
4657 * @nr_vfn: number of virtual functions to be enabled.
4659 * This function enables the PCI SR-IOV virtual functions to a physical
4660 * function. It invokes the PCI SR-IOV api with the @nr_vfn provided to
4661 * enable the number of virtual functions to the physical function. As
4662 * not all devices support SR-IOV, the return code from the pci_enable_sriov()
4663 * API call does not considered as an error condition for most of the device.
4666 lpfc_sli_probe_sriov_nr_virtfn(struct lpfc_hba
*phba
, int nr_vfn
)
4668 struct pci_dev
*pdev
= phba
->pcidev
;
4669 uint16_t max_nr_vfn
;
4672 max_nr_vfn
= lpfc_sli_sriov_nr_virtfn_get(phba
);
4673 if (nr_vfn
> max_nr_vfn
) {
4674 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
4675 "3057 Requested vfs (%d) greater than "
4676 "supported vfs (%d)", nr_vfn
, max_nr_vfn
);
4680 rc
= pci_enable_sriov(pdev
, nr_vfn
);
4682 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4683 "2806 Failed to enable sriov on this device "
4684 "with vfn number nr_vf:%d, rc:%d\n",
4687 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4688 "2807 Successful enable sriov on this device "
4689 "with vfn number nr_vf:%d\n", nr_vfn
);
4694 * lpfc_sli_driver_resource_setup - Setup driver internal resources for SLI3 dev.
4695 * @phba: pointer to lpfc hba data structure.
4697 * This routine is invoked to set up the driver internal resources specific to
4698 * support the SLI-3 HBA device it attached to.
4702 * other values - error
4705 lpfc_sli_driver_resource_setup(struct lpfc_hba
*phba
)
4707 struct lpfc_sli
*psli
;
4711 * Initialize timers used by driver
4714 /* Heartbeat timer */
4715 init_timer(&phba
->hb_tmofunc
);
4716 phba
->hb_tmofunc
.function
= lpfc_hb_timeout
;
4717 phba
->hb_tmofunc
.data
= (unsigned long)phba
;
4720 /* MBOX heartbeat timer */
4721 init_timer(&psli
->mbox_tmo
);
4722 psli
->mbox_tmo
.function
= lpfc_mbox_timeout
;
4723 psli
->mbox_tmo
.data
= (unsigned long) phba
;
4724 /* FCP polling mode timer */
4725 init_timer(&phba
->fcp_poll_timer
);
4726 phba
->fcp_poll_timer
.function
= lpfc_poll_timeout
;
4727 phba
->fcp_poll_timer
.data
= (unsigned long) phba
;
4728 /* Fabric block timer */
4729 init_timer(&phba
->fabric_block_timer
);
4730 phba
->fabric_block_timer
.function
= lpfc_fabric_block_timeout
;
4731 phba
->fabric_block_timer
.data
= (unsigned long) phba
;
4732 /* EA polling mode timer */
4733 init_timer(&phba
->eratt_poll
);
4734 phba
->eratt_poll
.function
= lpfc_poll_eratt
;
4735 phba
->eratt_poll
.data
= (unsigned long) phba
;
4737 /* Host attention work mask setup */
4738 phba
->work_ha_mask
= (HA_ERATT
| HA_MBATT
| HA_LATT
);
4739 phba
->work_ha_mask
|= (HA_RXMASK
<< (LPFC_ELS_RING
* 4));
4741 /* Get all the module params for configuring this host */
4742 lpfc_get_cfgparam(phba
);
4743 if (phba
->pcidev
->device
== PCI_DEVICE_ID_HORNET
) {
4744 phba
->menlo_flag
|= HBA_MENLO_SUPPORT
;
4745 /* check for menlo minimum sg count */
4746 if (phba
->cfg_sg_seg_cnt
< LPFC_DEFAULT_MENLO_SG_SEG_CNT
)
4747 phba
->cfg_sg_seg_cnt
= LPFC_DEFAULT_MENLO_SG_SEG_CNT
;
4750 if (!phba
->sli
.ring
)
4751 phba
->sli
.ring
= (struct lpfc_sli_ring
*)
4752 kzalloc(LPFC_SLI3_MAX_RING
*
4753 sizeof(struct lpfc_sli_ring
), GFP_KERNEL
);
4754 if (!phba
->sli
.ring
)
4758 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
4759 * used to create the sg_dma_buf_pool must be dynamically calculated.
4762 /* Initialize the host templates the configured values. */
4763 lpfc_vport_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
4764 lpfc_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
4766 /* There are going to be 2 reserved BDEs: 1 FCP cmnd + 1 FCP rsp */
4767 if (phba
->cfg_enable_bg
) {
4769 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
4770 * the FCP rsp, and a BDE for each. Sice we have no control
4771 * over how many protection data segments the SCSI Layer
4772 * will hand us (ie: there could be one for every block
4773 * in the IO), we just allocate enough BDEs to accomidate
4774 * our max amount and we need to limit lpfc_sg_seg_cnt to
4775 * minimize the risk of running out.
4777 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
4778 sizeof(struct fcp_rsp
) +
4779 (LPFC_MAX_SG_SEG_CNT
* sizeof(struct ulp_bde64
));
4781 if (phba
->cfg_sg_seg_cnt
> LPFC_MAX_SG_SEG_CNT_DIF
)
4782 phba
->cfg_sg_seg_cnt
= LPFC_MAX_SG_SEG_CNT_DIF
;
4784 /* Total BDEs in BPL for scsi_sg_list and scsi_sg_prot_list */
4785 phba
->cfg_total_seg_cnt
= LPFC_MAX_SG_SEG_CNT
;
4788 * The scsi_buf for a regular I/O will hold the FCP cmnd,
4789 * the FCP rsp, a BDE for each, and a BDE for up to
4790 * cfg_sg_seg_cnt data segments.
4792 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
4793 sizeof(struct fcp_rsp
) +
4794 ((phba
->cfg_sg_seg_cnt
+ 2) * sizeof(struct ulp_bde64
));
4796 /* Total BDEs in BPL for scsi_sg_list */
4797 phba
->cfg_total_seg_cnt
= phba
->cfg_sg_seg_cnt
+ 2;
4800 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
| LOG_FCP
,
4801 "9088 sg_tablesize:%d dmabuf_size:%d total_bde:%d\n",
4802 phba
->cfg_sg_seg_cnt
, phba
->cfg_sg_dma_buf_size
,
4803 phba
->cfg_total_seg_cnt
);
4805 phba
->max_vpi
= LPFC_MAX_VPI
;
4806 /* This will be set to correct value after config_port mbox */
4807 phba
->max_vports
= 0;
4810 * Initialize the SLI Layer to run with lpfc HBAs.
4812 lpfc_sli_setup(phba
);
4813 lpfc_sli_queue_setup(phba
);
4815 /* Allocate device driver memory */
4816 if (lpfc_mem_alloc(phba
, BPL_ALIGN_SZ
))
4820 * Enable sr-iov virtual functions if supported and configured
4821 * through the module parameter.
4823 if (phba
->cfg_sriov_nr_virtfn
> 0) {
4824 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
,
4825 phba
->cfg_sriov_nr_virtfn
);
4827 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
4828 "2808 Requested number of SR-IOV "
4829 "virtual functions (%d) is not "
4831 phba
->cfg_sriov_nr_virtfn
);
4832 phba
->cfg_sriov_nr_virtfn
= 0;
4840 * lpfc_sli_driver_resource_unset - Unset drvr internal resources for SLI3 dev
4841 * @phba: pointer to lpfc hba data structure.
4843 * This routine is invoked to unset the driver internal resources set up
4844 * specific for supporting the SLI-3 HBA device it attached to.
4847 lpfc_sli_driver_resource_unset(struct lpfc_hba
*phba
)
4849 /* Free device driver memory allocated */
4850 lpfc_mem_free_all(phba
);
4856 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
4857 * @phba: pointer to lpfc hba data structure.
4859 * This routine is invoked to set up the driver internal resources specific to
4860 * support the SLI-4 HBA device it attached to.
4864 * other values - error
4867 lpfc_sli4_driver_resource_setup(struct lpfc_hba
*phba
)
4869 struct lpfc_vector_map_info
*cpup
;
4870 struct lpfc_sli
*psli
;
4871 LPFC_MBOXQ_t
*mboxq
;
4872 int rc
, i
, hbq_count
, max_buf_size
;
4873 uint8_t pn_page
[LPFC_MAX_SUPPORTED_PAGES
] = {0};
4874 struct lpfc_mqe
*mqe
;
4877 /* Before proceed, wait for POST done and device ready */
4878 rc
= lpfc_sli4_post_status_check(phba
);
4883 * Initialize timers used by driver
4886 /* Heartbeat timer */
4887 init_timer(&phba
->hb_tmofunc
);
4888 phba
->hb_tmofunc
.function
= lpfc_hb_timeout
;
4889 phba
->hb_tmofunc
.data
= (unsigned long)phba
;
4890 init_timer(&phba
->rrq_tmr
);
4891 phba
->rrq_tmr
.function
= lpfc_rrq_timeout
;
4892 phba
->rrq_tmr
.data
= (unsigned long)phba
;
4895 /* MBOX heartbeat timer */
4896 init_timer(&psli
->mbox_tmo
);
4897 psli
->mbox_tmo
.function
= lpfc_mbox_timeout
;
4898 psli
->mbox_tmo
.data
= (unsigned long) phba
;
4899 /* Fabric block timer */
4900 init_timer(&phba
->fabric_block_timer
);
4901 phba
->fabric_block_timer
.function
= lpfc_fabric_block_timeout
;
4902 phba
->fabric_block_timer
.data
= (unsigned long) phba
;
4903 /* EA polling mode timer */
4904 init_timer(&phba
->eratt_poll
);
4905 phba
->eratt_poll
.function
= lpfc_poll_eratt
;
4906 phba
->eratt_poll
.data
= (unsigned long) phba
;
4907 /* FCF rediscover timer */
4908 init_timer(&phba
->fcf
.redisc_wait
);
4909 phba
->fcf
.redisc_wait
.function
= lpfc_sli4_fcf_redisc_wait_tmo
;
4910 phba
->fcf
.redisc_wait
.data
= (unsigned long)phba
;
4913 * Control structure for handling external multi-buffer mailbox
4914 * command pass-through.
4916 memset((uint8_t *)&phba
->mbox_ext_buf_ctx
, 0,
4917 sizeof(struct lpfc_mbox_ext_buf_ctx
));
4918 INIT_LIST_HEAD(&phba
->mbox_ext_buf_ctx
.ext_dmabuf_list
);
4921 * We need to do a READ_CONFIG mailbox command here before
4922 * calling lpfc_get_cfgparam. For VFs this will report the
4923 * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
4924 * All of the resources allocated
4925 * for this Port are tied to these values.
4927 /* Get all the module params for configuring this host */
4928 lpfc_get_cfgparam(phba
);
4929 phba
->max_vpi
= LPFC_MAX_VPI
;
4931 /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */
4932 phba
->cfg_fcp_io_channel
= phba
->cfg_fcp_eq_count
;
4934 /* This will be set to correct value after the read_config mbox */
4935 phba
->max_vports
= 0;
4937 /* Program the default value of vlan_id and fc_map */
4938 phba
->valid_vlan
= 0;
4939 phba
->fc_map
[0] = LPFC_FCOE_FCF_MAP0
;
4940 phba
->fc_map
[1] = LPFC_FCOE_FCF_MAP1
;
4941 phba
->fc_map
[2] = LPFC_FCOE_FCF_MAP2
;
4944 * For SLI4, instead of using ring 0 (LPFC_FCP_RING) for FCP commands
4945 * we will associate a new ring, for each FCP fastpath EQ/CQ/WQ tuple.
4947 if (!phba
->sli
.ring
)
4948 phba
->sli
.ring
= kzalloc(
4949 (LPFC_SLI3_MAX_RING
+ phba
->cfg_fcp_io_channel
) *
4950 sizeof(struct lpfc_sli_ring
), GFP_KERNEL
);
4951 if (!phba
->sli
.ring
)
4955 * It doesn't matter what family our adapter is in, we are
4956 * limited to 2 Pages, 512 SGEs, for our SGL.
4957 * There are going to be 2 reserved SGEs: 1 FCP cmnd + 1 FCP rsp
4959 max_buf_size
= (2 * SLI4_PAGE_SIZE
);
4960 if (phba
->cfg_sg_seg_cnt
> LPFC_MAX_SGL_SEG_CNT
- 2)
4961 phba
->cfg_sg_seg_cnt
= LPFC_MAX_SGL_SEG_CNT
- 2;
4964 * Since lpfc_sg_seg_cnt is module parameter, the sg_dma_buf_size
4965 * used to create the sg_dma_buf_pool must be dynamically calculated.
4968 if (phba
->cfg_enable_bg
) {
4970 * The scsi_buf for a T10-DIF I/O will hold the FCP cmnd,
4971 * the FCP rsp, and a SGE for each. Sice we have no control
4972 * over how many protection data segments the SCSI Layer
4973 * will hand us (ie: there could be one for every block
4974 * in the IO), we just allocate enough SGEs to accomidate
4975 * our max amount and we need to limit lpfc_sg_seg_cnt to
4976 * minimize the risk of running out.
4978 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
4979 sizeof(struct fcp_rsp
) + max_buf_size
;
4981 /* Total SGEs for scsi_sg_list and scsi_sg_prot_list */
4982 phba
->cfg_total_seg_cnt
= LPFC_MAX_SGL_SEG_CNT
;
4984 if (phba
->cfg_sg_seg_cnt
> LPFC_MAX_SG_SLI4_SEG_CNT_DIF
)
4985 phba
->cfg_sg_seg_cnt
= LPFC_MAX_SG_SLI4_SEG_CNT_DIF
;
4988 * The scsi_buf for a regular I/O will hold the FCP cmnd,
4989 * the FCP rsp, a SGE for each, and a SGE for up to
4990 * cfg_sg_seg_cnt data segments.
4992 phba
->cfg_sg_dma_buf_size
= sizeof(struct fcp_cmnd
) +
4993 sizeof(struct fcp_rsp
) +
4994 ((phba
->cfg_sg_seg_cnt
+ 2) * sizeof(struct sli4_sge
));
4996 /* Total SGEs for scsi_sg_list */
4997 phba
->cfg_total_seg_cnt
= phba
->cfg_sg_seg_cnt
+ 2;
4999 * NOTE: if (phba->cfg_sg_seg_cnt + 2) <= 256 we only need
5000 * to post 1 page for the SGL.
5004 /* Initialize the host templates with the updated values. */
5005 lpfc_vport_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
5006 lpfc_template
.sg_tablesize
= phba
->cfg_sg_seg_cnt
;
5008 if (phba
->cfg_sg_dma_buf_size
<= LPFC_MIN_SG_SLI4_BUF_SZ
)
5009 phba
->cfg_sg_dma_buf_size
= LPFC_MIN_SG_SLI4_BUF_SZ
;
5011 phba
->cfg_sg_dma_buf_size
=
5012 SLI4_PAGE_ALIGN(phba
->cfg_sg_dma_buf_size
);
5014 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
| LOG_FCP
,
5015 "9087 sg_tablesize:%d dmabuf_size:%d total_sge:%d\n",
5016 phba
->cfg_sg_seg_cnt
, phba
->cfg_sg_dma_buf_size
,
5017 phba
->cfg_total_seg_cnt
);
5019 /* Initialize buffer queue management fields */
5020 hbq_count
= lpfc_sli_hbq_count();
5021 for (i
= 0; i
< hbq_count
; ++i
)
5022 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
5023 INIT_LIST_HEAD(&phba
->rb_pend_list
);
5024 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_sli4_rb_alloc
;
5025 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_sli4_rb_free
;
5028 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
5030 /* Initialize the Abort scsi buffer list used by driver */
5031 spin_lock_init(&phba
->sli4_hba
.abts_scsi_buf_list_lock
);
5032 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
5033 /* This abort list used by worker thread */
5034 spin_lock_init(&phba
->sli4_hba
.abts_sgl_list_lock
);
5037 * Initialize driver internal slow-path work queues
5040 /* Driver internel slow-path CQ Event pool */
5041 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_cqe_event_pool
);
5042 /* Response IOCB work queue list */
5043 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_queue_event
);
5044 /* Asynchronous event CQ Event work queue list */
5045 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_asynce_work_queue
);
5046 /* Fast-path XRI aborted CQ Event work queue list */
5047 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
);
5048 /* Slow-path XRI aborted CQ Event work queue list */
5049 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
);
5050 /* Receive queue CQ Event work queue list */
5051 INIT_LIST_HEAD(&phba
->sli4_hba
.sp_unsol_work_queue
);
5053 /* Initialize extent block lists. */
5054 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_blk_list
);
5055 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_xri_blk_list
);
5056 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_vfi_blk_list
);
5057 INIT_LIST_HEAD(&phba
->lpfc_vpi_blk_list
);
5059 /* Initialize the driver internal SLI layer lists. */
5060 lpfc_sli_setup(phba
);
5061 lpfc_sli_queue_setup(phba
);
5063 /* Allocate device driver memory */
5064 rc
= lpfc_mem_alloc(phba
, SGL_ALIGN_SZ
);
5068 /* IF Type 2 ports get initialized now. */
5069 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
5070 LPFC_SLI_INTF_IF_TYPE_2
) {
5071 rc
= lpfc_pci_function_reset(phba
);
5076 /* Create the bootstrap mailbox command */
5077 rc
= lpfc_create_bootstrap_mbox(phba
);
5081 /* Set up the host's endian order with the device. */
5082 rc
= lpfc_setup_endian_order(phba
);
5084 goto out_free_bsmbx
;
5086 /* Set up the hba's configuration parameters. */
5087 rc
= lpfc_sli4_read_config(phba
);
5089 goto out_free_bsmbx
;
5091 /* IF Type 0 ports get initialized now. */
5092 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
5093 LPFC_SLI_INTF_IF_TYPE_0
) {
5094 rc
= lpfc_pci_function_reset(phba
);
5096 goto out_free_bsmbx
;
5099 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
5103 goto out_free_bsmbx
;
5106 /* Get the Supported Pages if PORT_CAPABILITIES is supported by port. */
5107 lpfc_supported_pages(mboxq
);
5108 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
5110 mqe
= &mboxq
->u
.mqe
;
5111 memcpy(&pn_page
[0], ((uint8_t *)&mqe
->un
.supp_pages
.word3
),
5112 LPFC_MAX_SUPPORTED_PAGES
);
5113 for (i
= 0; i
< LPFC_MAX_SUPPORTED_PAGES
; i
++) {
5114 switch (pn_page
[i
]) {
5115 case LPFC_SLI4_PARAMETERS
:
5116 phba
->sli4_hba
.pc_sli4_params
.supported
= 1;
5122 /* Read the port's SLI4 Parameters capabilities if supported. */
5123 if (phba
->sli4_hba
.pc_sli4_params
.supported
)
5124 rc
= lpfc_pc_sli4_params_get(phba
, mboxq
);
5126 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5128 goto out_free_bsmbx
;
5132 * Get sli4 parameters that override parameters from Port capabilities.
5133 * If this call fails, it isn't critical unless the SLI4 parameters come
5136 rc
= lpfc_get_sli4_parameters(phba
, mboxq
);
5138 if (phba
->sli4_hba
.extents_in_use
&&
5139 phba
->sli4_hba
.rpi_hdrs_in_use
) {
5140 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5141 "2999 Unsupported SLI4 Parameters "
5142 "Extents and RPI headers enabled.\n");
5143 goto out_free_bsmbx
;
5146 mempool_free(mboxq
, phba
->mbox_mem_pool
);
5147 /* Verify all the SLI4 queues */
5148 rc
= lpfc_sli4_queue_verify(phba
);
5150 goto out_free_bsmbx
;
5152 /* Create driver internal CQE event pool */
5153 rc
= lpfc_sli4_cq_event_pool_create(phba
);
5155 goto out_free_bsmbx
;
5157 /* Initialize sgl lists per host */
5158 lpfc_init_sgl_list(phba
);
5160 /* Allocate and initialize active sgl array */
5161 rc
= lpfc_init_active_sgl_array(phba
);
5163 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5164 "1430 Failed to initialize sgl list.\n");
5165 goto out_destroy_cq_event_pool
;
5167 rc
= lpfc_sli4_init_rpi_hdrs(phba
);
5169 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5170 "1432 Failed to initialize rpi headers.\n");
5171 goto out_free_active_sgl
;
5174 /* Allocate eligible FCF bmask memory for FCF roundrobin failover */
5175 longs
= (LPFC_SLI4_FCF_TBL_INDX_MAX
+ BITS_PER_LONG
- 1)/BITS_PER_LONG
;
5176 phba
->fcf
.fcf_rr_bmask
= kzalloc(longs
* sizeof(unsigned long),
5178 if (!phba
->fcf
.fcf_rr_bmask
) {
5179 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5180 "2759 Failed allocate memory for FCF round "
5181 "robin failover bmask\n");
5183 goto out_remove_rpi_hdrs
;
5186 phba
->sli4_hba
.fcp_eq_hdl
=
5187 kzalloc((sizeof(struct lpfc_fcp_eq_hdl
) *
5188 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
5189 if (!phba
->sli4_hba
.fcp_eq_hdl
) {
5190 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5191 "2572 Failed allocate memory for "
5192 "fast-path per-EQ handle array\n");
5194 goto out_free_fcf_rr_bmask
;
5197 phba
->sli4_hba
.msix_entries
= kzalloc((sizeof(struct msix_entry
) *
5198 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
5199 if (!phba
->sli4_hba
.msix_entries
) {
5200 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5201 "2573 Failed allocate memory for msi-x "
5202 "interrupt vector entries\n");
5204 goto out_free_fcp_eq_hdl
;
5207 phba
->sli4_hba
.cpu_map
= kzalloc((sizeof(struct lpfc_vector_map_info
) *
5208 phba
->sli4_hba
.num_present_cpu
),
5210 if (!phba
->sli4_hba
.cpu_map
) {
5211 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5212 "3327 Failed allocate memory for msi-x "
5213 "interrupt vector mapping\n");
5217 if (lpfc_used_cpu
== NULL
) {
5218 lpfc_used_cpu
= kzalloc((sizeof(uint16_t) * lpfc_present_cpu
),
5220 if (!lpfc_used_cpu
) {
5221 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5222 "3335 Failed allocate memory for msi-x "
5223 "interrupt vector mapping\n");
5224 kfree(phba
->sli4_hba
.cpu_map
);
5228 for (i
= 0; i
< lpfc_present_cpu
; i
++)
5229 lpfc_used_cpu
[i
] = LPFC_VECTOR_MAP_EMPTY
;
5232 /* Initialize io channels for round robin */
5233 cpup
= phba
->sli4_hba
.cpu_map
;
5235 for (i
= 0; i
< phba
->sli4_hba
.num_present_cpu
; i
++) {
5236 cpup
->channel_id
= rc
;
5238 if (rc
>= phba
->cfg_fcp_io_channel
)
5243 * Enable sr-iov virtual functions if supported and configured
5244 * through the module parameter.
5246 if (phba
->cfg_sriov_nr_virtfn
> 0) {
5247 rc
= lpfc_sli_probe_sriov_nr_virtfn(phba
,
5248 phba
->cfg_sriov_nr_virtfn
);
5250 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
5251 "3020 Requested number of SR-IOV "
5252 "virtual functions (%d) is not "
5254 phba
->cfg_sriov_nr_virtfn
);
5255 phba
->cfg_sriov_nr_virtfn
= 0;
5262 kfree(phba
->sli4_hba
.msix_entries
);
5263 out_free_fcp_eq_hdl
:
5264 kfree(phba
->sli4_hba
.fcp_eq_hdl
);
5265 out_free_fcf_rr_bmask
:
5266 kfree(phba
->fcf
.fcf_rr_bmask
);
5267 out_remove_rpi_hdrs
:
5268 lpfc_sli4_remove_rpi_hdrs(phba
);
5269 out_free_active_sgl
:
5270 lpfc_free_active_sgl(phba
);
5271 out_destroy_cq_event_pool
:
5272 lpfc_sli4_cq_event_pool_destroy(phba
);
5274 lpfc_destroy_bootstrap_mbox(phba
);
5276 lpfc_mem_free(phba
);
5281 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
5282 * @phba: pointer to lpfc hba data structure.
5284 * This routine is invoked to unset the driver internal resources set up
5285 * specific for supporting the SLI-4 HBA device it attached to.
5288 lpfc_sli4_driver_resource_unset(struct lpfc_hba
*phba
)
5290 struct lpfc_fcf_conn_entry
*conn_entry
, *next_conn_entry
;
5292 /* Free memory allocated for msi-x interrupt vector to CPU mapping */
5293 kfree(phba
->sli4_hba
.cpu_map
);
5294 phba
->sli4_hba
.num_present_cpu
= 0;
5295 phba
->sli4_hba
.num_online_cpu
= 0;
5297 /* Free memory allocated for msi-x interrupt vector entries */
5298 kfree(phba
->sli4_hba
.msix_entries
);
5300 /* Free memory allocated for fast-path work queue handles */
5301 kfree(phba
->sli4_hba
.fcp_eq_hdl
);
5303 /* Free the allocated rpi headers. */
5304 lpfc_sli4_remove_rpi_hdrs(phba
);
5305 lpfc_sli4_remove_rpis(phba
);
5307 /* Free eligible FCF index bmask */
5308 kfree(phba
->fcf
.fcf_rr_bmask
);
5310 /* Free the ELS sgl list */
5311 lpfc_free_active_sgl(phba
);
5312 lpfc_free_els_sgl_list(phba
);
5314 /* Free the completion queue EQ event pool */
5315 lpfc_sli4_cq_event_release_all(phba
);
5316 lpfc_sli4_cq_event_pool_destroy(phba
);
5318 /* Release resource identifiers. */
5319 lpfc_sli4_dealloc_resource_identifiers(phba
);
5321 /* Free the bsmbx region. */
5322 lpfc_destroy_bootstrap_mbox(phba
);
5324 /* Free the SLI Layer memory with SLI4 HBAs */
5325 lpfc_mem_free_all(phba
);
5327 /* Free the current connect table */
5328 list_for_each_entry_safe(conn_entry
, next_conn_entry
,
5329 &phba
->fcf_conn_rec_list
, list
) {
5330 list_del_init(&conn_entry
->list
);
5338 * lpfc_init_api_table_setup - Set up init api function jump table
5339 * @phba: The hba struct for which this call is being executed.
5340 * @dev_grp: The HBA PCI-Device group number.
5342 * This routine sets up the device INIT interface API function jump table
5345 * Returns: 0 - success, -ENODEV - failure.
5348 lpfc_init_api_table_setup(struct lpfc_hba
*phba
, uint8_t dev_grp
)
5350 phba
->lpfc_hba_init_link
= lpfc_hba_init_link
;
5351 phba
->lpfc_hba_down_link
= lpfc_hba_down_link
;
5352 phba
->lpfc_selective_reset
= lpfc_selective_reset
;
5354 case LPFC_PCI_DEV_LP
:
5355 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s3
;
5356 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s3
;
5357 phba
->lpfc_stop_port
= lpfc_stop_port_s3
;
5359 case LPFC_PCI_DEV_OC
:
5360 phba
->lpfc_hba_down_post
= lpfc_hba_down_post_s4
;
5361 phba
->lpfc_handle_eratt
= lpfc_handle_eratt_s4
;
5362 phba
->lpfc_stop_port
= lpfc_stop_port_s4
;
5365 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5366 "1431 Invalid HBA PCI-device group: 0x%x\n",
5375 * lpfc_setup_driver_resource_phase1 - Phase1 etup driver internal resources.
5376 * @phba: pointer to lpfc hba data structure.
5378 * This routine is invoked to set up the driver internal resources before the
5379 * device specific resource setup to support the HBA device it attached to.
5383 * other values - error
5386 lpfc_setup_driver_resource_phase1(struct lpfc_hba
*phba
)
5389 * Driver resources common to all SLI revisions
5391 atomic_set(&phba
->fast_event_count
, 0);
5392 spin_lock_init(&phba
->hbalock
);
5394 /* Initialize ndlp management spinlock */
5395 spin_lock_init(&phba
->ndlp_lock
);
5397 INIT_LIST_HEAD(&phba
->port_list
);
5398 INIT_LIST_HEAD(&phba
->work_list
);
5399 init_waitqueue_head(&phba
->wait_4_mlo_m_q
);
5401 /* Initialize the wait queue head for the kernel thread */
5402 init_waitqueue_head(&phba
->work_waitq
);
5404 /* Initialize the scsi buffer list used by driver for scsi IO */
5405 spin_lock_init(&phba
->scsi_buf_list_get_lock
);
5406 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list_get
);
5407 spin_lock_init(&phba
->scsi_buf_list_put_lock
);
5408 INIT_LIST_HEAD(&phba
->lpfc_scsi_buf_list_put
);
5410 /* Initialize the fabric iocb list */
5411 INIT_LIST_HEAD(&phba
->fabric_iocb_list
);
5413 /* Initialize list to save ELS buffers */
5414 INIT_LIST_HEAD(&phba
->elsbuf
);
5416 /* Initialize FCF connection rec list */
5417 INIT_LIST_HEAD(&phba
->fcf_conn_rec_list
);
5423 * lpfc_setup_driver_resource_phase2 - Phase2 setup driver internal resources.
5424 * @phba: pointer to lpfc hba data structure.
5426 * This routine is invoked to set up the driver internal resources after the
5427 * device specific resource setup to support the HBA device it attached to.
5431 * other values - error
5434 lpfc_setup_driver_resource_phase2(struct lpfc_hba
*phba
)
5438 /* Startup the kernel thread for this host adapter. */
5439 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
5440 "lpfc_worker_%d", phba
->brd_no
);
5441 if (IS_ERR(phba
->worker_thread
)) {
5442 error
= PTR_ERR(phba
->worker_thread
);
5450 * lpfc_unset_driver_resource_phase2 - Phase2 unset driver internal resources.
5451 * @phba: pointer to lpfc hba data structure.
5453 * This routine is invoked to unset the driver internal resources set up after
5454 * the device specific resource setup for supporting the HBA device it
5458 lpfc_unset_driver_resource_phase2(struct lpfc_hba
*phba
)
5460 /* Stop kernel worker thread */
5461 kthread_stop(phba
->worker_thread
);
5465 * lpfc_free_iocb_list - Free iocb list.
5466 * @phba: pointer to lpfc hba data structure.
5468 * This routine is invoked to free the driver's IOCB list and memory.
5471 lpfc_free_iocb_list(struct lpfc_hba
*phba
)
5473 struct lpfc_iocbq
*iocbq_entry
= NULL
, *iocbq_next
= NULL
;
5475 spin_lock_irq(&phba
->hbalock
);
5476 list_for_each_entry_safe(iocbq_entry
, iocbq_next
,
5477 &phba
->lpfc_iocb_list
, list
) {
5478 list_del(&iocbq_entry
->list
);
5480 phba
->total_iocbq_bufs
--;
5482 spin_unlock_irq(&phba
->hbalock
);
5488 * lpfc_init_iocb_list - Allocate and initialize iocb list.
5489 * @phba: pointer to lpfc hba data structure.
5491 * This routine is invoked to allocate and initizlize the driver's IOCB
5492 * list and set up the IOCB tag array accordingly.
5496 * other values - error
5499 lpfc_init_iocb_list(struct lpfc_hba
*phba
, int iocb_count
)
5501 struct lpfc_iocbq
*iocbq_entry
= NULL
;
5505 /* Initialize and populate the iocb list per host. */
5506 INIT_LIST_HEAD(&phba
->lpfc_iocb_list
);
5507 for (i
= 0; i
< iocb_count
; i
++) {
5508 iocbq_entry
= kzalloc(sizeof(struct lpfc_iocbq
), GFP_KERNEL
);
5509 if (iocbq_entry
== NULL
) {
5510 printk(KERN_ERR
"%s: only allocated %d iocbs of "
5511 "expected %d count. Unloading driver.\n",
5512 __func__
, i
, LPFC_IOCB_LIST_CNT
);
5513 goto out_free_iocbq
;
5516 iotag
= lpfc_sli_next_iotag(phba
, iocbq_entry
);
5519 printk(KERN_ERR
"%s: failed to allocate IOTAG. "
5520 "Unloading driver.\n", __func__
);
5521 goto out_free_iocbq
;
5523 iocbq_entry
->sli4_lxritag
= NO_XRI
;
5524 iocbq_entry
->sli4_xritag
= NO_XRI
;
5526 spin_lock_irq(&phba
->hbalock
);
5527 list_add(&iocbq_entry
->list
, &phba
->lpfc_iocb_list
);
5528 phba
->total_iocbq_bufs
++;
5529 spin_unlock_irq(&phba
->hbalock
);
5535 lpfc_free_iocb_list(phba
);
5541 * lpfc_free_sgl_list - Free a given sgl list.
5542 * @phba: pointer to lpfc hba data structure.
5543 * @sglq_list: pointer to the head of sgl list.
5545 * This routine is invoked to free a give sgl list and memory.
5548 lpfc_free_sgl_list(struct lpfc_hba
*phba
, struct list_head
*sglq_list
)
5550 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
5552 list_for_each_entry_safe(sglq_entry
, sglq_next
, sglq_list
, list
) {
5553 list_del(&sglq_entry
->list
);
5554 lpfc_mbuf_free(phba
, sglq_entry
->virt
, sglq_entry
->phys
);
5560 * lpfc_free_els_sgl_list - Free els sgl list.
5561 * @phba: pointer to lpfc hba data structure.
5563 * This routine is invoked to free the driver's els sgl list and memory.
5566 lpfc_free_els_sgl_list(struct lpfc_hba
*phba
)
5568 LIST_HEAD(sglq_list
);
5570 /* Retrieve all els sgls from driver list */
5571 spin_lock_irq(&phba
->hbalock
);
5572 list_splice_init(&phba
->sli4_hba
.lpfc_sgl_list
, &sglq_list
);
5573 spin_unlock_irq(&phba
->hbalock
);
5575 /* Now free the sgl list */
5576 lpfc_free_sgl_list(phba
, &sglq_list
);
5580 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
5581 * @phba: pointer to lpfc hba data structure.
5583 * This routine is invoked to allocate the driver's active sgl memory.
5584 * This array will hold the sglq_entry's for active IOs.
5587 lpfc_init_active_sgl_array(struct lpfc_hba
*phba
)
5590 size
= sizeof(struct lpfc_sglq
*);
5591 size
*= phba
->sli4_hba
.max_cfg_param
.max_xri
;
5593 phba
->sli4_hba
.lpfc_sglq_active_list
=
5594 kzalloc(size
, GFP_KERNEL
);
5595 if (!phba
->sli4_hba
.lpfc_sglq_active_list
)
5601 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
5602 * @phba: pointer to lpfc hba data structure.
5604 * This routine is invoked to walk through the array of active sglq entries
5605 * and free all of the resources.
5606 * This is just a place holder for now.
5609 lpfc_free_active_sgl(struct lpfc_hba
*phba
)
5611 kfree(phba
->sli4_hba
.lpfc_sglq_active_list
);
5615 * lpfc_init_sgl_list - Allocate and initialize sgl list.
5616 * @phba: pointer to lpfc hba data structure.
5618 * This routine is invoked to allocate and initizlize the driver's sgl
5619 * list and set up the sgl xritag tag array accordingly.
5623 lpfc_init_sgl_list(struct lpfc_hba
*phba
)
5625 /* Initialize and populate the sglq list per host/VF. */
5626 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_sgl_list
);
5627 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
5629 /* els xri-sgl book keeping */
5630 phba
->sli4_hba
.els_xri_cnt
= 0;
5632 /* scsi xri-buffer book keeping */
5633 phba
->sli4_hba
.scsi_xri_cnt
= 0;
5637 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
5638 * @phba: pointer to lpfc hba data structure.
5640 * This routine is invoked to post rpi header templates to the
5641 * port for those SLI4 ports that do not support extents. This routine
5642 * posts a PAGE_SIZE memory region to the port to hold up to
5643 * PAGE_SIZE modulo 64 rpi context headers. This is an initialization routine
5644 * and should be called only when interrupts are disabled.
5648 * -ERROR - otherwise.
5651 lpfc_sli4_init_rpi_hdrs(struct lpfc_hba
*phba
)
5654 struct lpfc_rpi_hdr
*rpi_hdr
;
5656 INIT_LIST_HEAD(&phba
->sli4_hba
.lpfc_rpi_hdr_list
);
5657 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5659 if (phba
->sli4_hba
.extents_in_use
)
5662 rpi_hdr
= lpfc_sli4_create_rpi_hdr(phba
);
5664 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_SLI
,
5665 "0391 Error during rpi post operation\n");
5666 lpfc_sli4_remove_rpis(phba
);
5674 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
5675 * @phba: pointer to lpfc hba data structure.
5677 * This routine is invoked to allocate a single 4KB memory region to
5678 * support rpis and stores them in the phba. This single region
5679 * provides support for up to 64 rpis. The region is used globally
5683 * A valid rpi hdr on success.
5684 * A NULL pointer on any failure.
5686 struct lpfc_rpi_hdr
*
5687 lpfc_sli4_create_rpi_hdr(struct lpfc_hba
*phba
)
5689 uint16_t rpi_limit
, curr_rpi_range
;
5690 struct lpfc_dmabuf
*dmabuf
;
5691 struct lpfc_rpi_hdr
*rpi_hdr
;
5695 * If the SLI4 port supports extents, posting the rpi header isn't
5696 * required. Set the expected maximum count and let the actual value
5697 * get set when extents are fully allocated.
5699 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5701 if (phba
->sli4_hba
.extents_in_use
)
5704 /* The limit on the logical index is just the max_rpi count. */
5705 rpi_limit
= phba
->sli4_hba
.max_cfg_param
.rpi_base
+
5706 phba
->sli4_hba
.max_cfg_param
.max_rpi
- 1;
5708 spin_lock_irq(&phba
->hbalock
);
5710 * Establish the starting RPI in this header block. The starting
5711 * rpi is normalized to a zero base because the physical rpi is
5714 curr_rpi_range
= phba
->sli4_hba
.next_rpi
;
5715 spin_unlock_irq(&phba
->hbalock
);
5718 * The port has a limited number of rpis. The increment here
5719 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
5720 * and to allow the full max_rpi range per port.
5722 if ((curr_rpi_range
+ (LPFC_RPI_HDR_COUNT
- 1)) > rpi_limit
)
5723 rpi_count
= rpi_limit
- curr_rpi_range
;
5725 rpi_count
= LPFC_RPI_HDR_COUNT
;
5730 * First allocate the protocol header region for the port. The
5731 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
5733 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
5737 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
5738 LPFC_HDR_TEMPLATE_SIZE
,
5741 if (!dmabuf
->virt
) {
5743 goto err_free_dmabuf
;
5746 memset(dmabuf
->virt
, 0, LPFC_HDR_TEMPLATE_SIZE
);
5747 if (!IS_ALIGNED(dmabuf
->phys
, LPFC_HDR_TEMPLATE_SIZE
)) {
5749 goto err_free_coherent
;
5752 /* Save the rpi header data for cleanup later. */
5753 rpi_hdr
= kzalloc(sizeof(struct lpfc_rpi_hdr
), GFP_KERNEL
);
5755 goto err_free_coherent
;
5757 rpi_hdr
->dmabuf
= dmabuf
;
5758 rpi_hdr
->len
= LPFC_HDR_TEMPLATE_SIZE
;
5759 rpi_hdr
->page_count
= 1;
5760 spin_lock_irq(&phba
->hbalock
);
5762 /* The rpi_hdr stores the logical index only. */
5763 rpi_hdr
->start_rpi
= curr_rpi_range
;
5764 list_add_tail(&rpi_hdr
->list
, &phba
->sli4_hba
.lpfc_rpi_hdr_list
);
5767 * The next_rpi stores the next logical module-64 rpi value used
5768 * to post physical rpis in subsequent rpi postings.
5770 phba
->sli4_hba
.next_rpi
+= rpi_count
;
5771 spin_unlock_irq(&phba
->hbalock
);
5775 dma_free_coherent(&phba
->pcidev
->dev
, LPFC_HDR_TEMPLATE_SIZE
,
5776 dmabuf
->virt
, dmabuf
->phys
);
5783 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
5784 * @phba: pointer to lpfc hba data structure.
5786 * This routine is invoked to remove all memory resources allocated
5787 * to support rpis for SLI4 ports not supporting extents. This routine
5788 * presumes the caller has released all rpis consumed by fabric or port
5789 * logins and is prepared to have the header pages removed.
5792 lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba
*phba
)
5794 struct lpfc_rpi_hdr
*rpi_hdr
, *next_rpi_hdr
;
5796 if (!phba
->sli4_hba
.rpi_hdrs_in_use
)
5799 list_for_each_entry_safe(rpi_hdr
, next_rpi_hdr
,
5800 &phba
->sli4_hba
.lpfc_rpi_hdr_list
, list
) {
5801 list_del(&rpi_hdr
->list
);
5802 dma_free_coherent(&phba
->pcidev
->dev
, rpi_hdr
->len
,
5803 rpi_hdr
->dmabuf
->virt
, rpi_hdr
->dmabuf
->phys
);
5804 kfree(rpi_hdr
->dmabuf
);
5808 /* There are no rpis available to the port now. */
5809 phba
->sli4_hba
.next_rpi
= 0;
5813 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
5814 * @pdev: pointer to pci device data structure.
5816 * This routine is invoked to allocate the driver hba data structure for an
5817 * HBA device. If the allocation is successful, the phba reference to the
5818 * PCI device data structure is set.
5821 * pointer to @phba - successful
5824 static struct lpfc_hba
*
5825 lpfc_hba_alloc(struct pci_dev
*pdev
)
5827 struct lpfc_hba
*phba
;
5829 /* Allocate memory for HBA structure */
5830 phba
= kzalloc(sizeof(struct lpfc_hba
), GFP_KERNEL
);
5832 dev_err(&pdev
->dev
, "failed to allocate hba struct\n");
5836 /* Set reference to PCI device in HBA structure */
5837 phba
->pcidev
= pdev
;
5839 /* Assign an unused board number */
5840 phba
->brd_no
= lpfc_get_instance();
5841 if (phba
->brd_no
< 0) {
5846 spin_lock_init(&phba
->ct_ev_lock
);
5847 INIT_LIST_HEAD(&phba
->ct_ev_waiters
);
5853 * lpfc_hba_free - Free driver hba data structure with a device.
5854 * @phba: pointer to lpfc hba data structure.
5856 * This routine is invoked to free the driver hba data structure with an
5860 lpfc_hba_free(struct lpfc_hba
*phba
)
5862 /* Release the driver assigned board number */
5863 idr_remove(&lpfc_hba_index
, phba
->brd_no
);
5865 /* Free memory allocated with sli rings */
5866 kfree(phba
->sli
.ring
);
5867 phba
->sli
.ring
= NULL
;
5874 * lpfc_create_shost - Create hba physical port with associated scsi host.
5875 * @phba: pointer to lpfc hba data structure.
5877 * This routine is invoked to create HBA physical port and associate a SCSI
5882 * other values - error
5885 lpfc_create_shost(struct lpfc_hba
*phba
)
5887 struct lpfc_vport
*vport
;
5888 struct Scsi_Host
*shost
;
5890 /* Initialize HBA FC structure */
5891 phba
->fc_edtov
= FF_DEF_EDTOV
;
5892 phba
->fc_ratov
= FF_DEF_RATOV
;
5893 phba
->fc_altov
= FF_DEF_ALTOV
;
5894 phba
->fc_arbtov
= FF_DEF_ARBTOV
;
5896 atomic_set(&phba
->sdev_cnt
, 0);
5897 vport
= lpfc_create_port(phba
, phba
->brd_no
, &phba
->pcidev
->dev
);
5901 shost
= lpfc_shost_from_vport(vport
);
5902 phba
->pport
= vport
;
5903 lpfc_debugfs_initialize(vport
);
5904 /* Put reference to SCSI host to driver's device private data */
5905 pci_set_drvdata(phba
->pcidev
, shost
);
5911 * lpfc_destroy_shost - Destroy hba physical port with associated scsi host.
5912 * @phba: pointer to lpfc hba data structure.
5914 * This routine is invoked to destroy HBA physical port and the associated
5918 lpfc_destroy_shost(struct lpfc_hba
*phba
)
5920 struct lpfc_vport
*vport
= phba
->pport
;
5922 /* Destroy physical port that associated with the SCSI host */
5923 destroy_port(vport
);
5929 * lpfc_setup_bg - Setup Block guard structures and debug areas.
5930 * @phba: pointer to lpfc hba data structure.
5931 * @shost: the shost to be used to detect Block guard settings.
5933 * This routine sets up the local Block guard protocol settings for @shost.
5934 * This routine also allocates memory for debugging bg buffers.
5937 lpfc_setup_bg(struct lpfc_hba
*phba
, struct Scsi_Host
*shost
)
5943 if (lpfc_prot_mask
&& lpfc_prot_guard
) {
5944 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
5945 "1478 Registering BlockGuard with the "
5948 old_mask
= lpfc_prot_mask
;
5949 old_guard
= lpfc_prot_guard
;
5951 /* Only allow supported values */
5952 lpfc_prot_mask
&= (SHOST_DIF_TYPE1_PROTECTION
|
5953 SHOST_DIX_TYPE0_PROTECTION
|
5954 SHOST_DIX_TYPE1_PROTECTION
);
5955 lpfc_prot_guard
&= (SHOST_DIX_GUARD_IP
| SHOST_DIX_GUARD_CRC
);
5957 /* DIF Type 1 protection for profiles AST1/C1 is end to end */
5958 if (lpfc_prot_mask
== SHOST_DIX_TYPE1_PROTECTION
)
5959 lpfc_prot_mask
|= SHOST_DIF_TYPE1_PROTECTION
;
5961 if (lpfc_prot_mask
&& lpfc_prot_guard
) {
5962 if ((old_mask
!= lpfc_prot_mask
) ||
5963 (old_guard
!= lpfc_prot_guard
))
5964 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5965 "1475 Registering BlockGuard with the "
5966 "SCSI layer: mask %d guard %d\n",
5967 lpfc_prot_mask
, lpfc_prot_guard
);
5969 scsi_host_set_prot(shost
, lpfc_prot_mask
);
5970 scsi_host_set_guard(shost
, lpfc_prot_guard
);
5972 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
5973 "1479 Not Registering BlockGuard with the SCSI "
5974 "layer, Bad protection parameters: %d %d\n",
5975 old_mask
, old_guard
);
5978 if (!_dump_buf_data
) {
5980 spin_lock_init(&_dump_buf_lock
);
5982 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
5983 if (_dump_buf_data
) {
5984 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5985 "9043 BLKGRD: allocated %d pages for "
5986 "_dump_buf_data at 0x%p\n",
5987 (1 << pagecnt
), _dump_buf_data
);
5988 _dump_buf_data_order
= pagecnt
;
5989 memset(_dump_buf_data
, 0,
5990 ((1 << PAGE_SHIFT
) << pagecnt
));
5995 if (!_dump_buf_data_order
)
5996 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
5997 "9044 BLKGRD: ERROR unable to allocate "
5998 "memory for hexdump\n");
6000 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6001 "9045 BLKGRD: already allocated _dump_buf_data=0x%p"
6002 "\n", _dump_buf_data
);
6003 if (!_dump_buf_dif
) {
6006 (char *) __get_free_pages(GFP_KERNEL
, pagecnt
);
6007 if (_dump_buf_dif
) {
6008 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6009 "9046 BLKGRD: allocated %d pages for "
6010 "_dump_buf_dif at 0x%p\n",
6011 (1 << pagecnt
), _dump_buf_dif
);
6012 _dump_buf_dif_order
= pagecnt
;
6013 memset(_dump_buf_dif
, 0,
6014 ((1 << PAGE_SHIFT
) << pagecnt
));
6019 if (!_dump_buf_dif_order
)
6020 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6021 "9047 BLKGRD: ERROR unable to allocate "
6022 "memory for hexdump\n");
6024 lpfc_printf_log(phba
, KERN_ERR
, LOG_BG
,
6025 "9048 BLKGRD: already allocated _dump_buf_dif=0x%p\n",
6030 * lpfc_post_init_setup - Perform necessary device post initialization setup.
6031 * @phba: pointer to lpfc hba data structure.
6033 * This routine is invoked to perform all the necessary post initialization
6034 * setup for the device.
6037 lpfc_post_init_setup(struct lpfc_hba
*phba
)
6039 struct Scsi_Host
*shost
;
6040 struct lpfc_adapter_event_header adapter_event
;
6042 /* Get the default values for Model Name and Description */
6043 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
6046 * hba setup may have changed the hba_queue_depth so we need to
6047 * adjust the value of can_queue.
6049 shost
= pci_get_drvdata(phba
->pcidev
);
6050 shost
->can_queue
= phba
->cfg_hba_queue_depth
- 10;
6051 if (phba
->sli3_options
& LPFC_SLI3_BG_ENABLED
)
6052 lpfc_setup_bg(phba
, shost
);
6054 lpfc_host_attrib_init(shost
);
6056 if (phba
->cfg_poll
& DISABLE_FCP_RING_INT
) {
6057 spin_lock_irq(shost
->host_lock
);
6058 lpfc_poll_start_timer(phba
);
6059 spin_unlock_irq(shost
->host_lock
);
6062 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6063 "0428 Perform SCSI scan\n");
6064 /* Send board arrival event to upper layer */
6065 adapter_event
.event_type
= FC_REG_ADAPTER_EVENT
;
6066 adapter_event
.subcategory
= LPFC_EVENT_ARRIVAL
;
6067 fc_host_post_vendor_event(shost
, fc_get_event_number(),
6068 sizeof(adapter_event
),
6069 (char *) &adapter_event
,
6075 * lpfc_sli_pci_mem_setup - Setup SLI3 HBA PCI memory space.
6076 * @phba: pointer to lpfc hba data structure.
6078 * This routine is invoked to set up the PCI device memory space for device
6079 * with SLI-3 interface spec.
6083 * other values - error
6086 lpfc_sli_pci_mem_setup(struct lpfc_hba
*phba
)
6088 struct pci_dev
*pdev
;
6089 unsigned long bar0map_len
, bar2map_len
;
6092 int error
= -ENODEV
;
6094 /* Obtain PCI device reference */
6098 pdev
= phba
->pcidev
;
6100 /* Set the device DMA mask size */
6101 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
6102 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
6103 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
6104 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
6109 /* Get the bus address of Bar0 and Bar2 and the number of bytes
6110 * required by each mapping.
6112 phba
->pci_bar0_map
= pci_resource_start(pdev
, 0);
6113 bar0map_len
= pci_resource_len(pdev
, 0);
6115 phba
->pci_bar2_map
= pci_resource_start(pdev
, 2);
6116 bar2map_len
= pci_resource_len(pdev
, 2);
6118 /* Map HBA SLIM to a kernel virtual address. */
6119 phba
->slim_memmap_p
= ioremap(phba
->pci_bar0_map
, bar0map_len
);
6120 if (!phba
->slim_memmap_p
) {
6121 dev_printk(KERN_ERR
, &pdev
->dev
,
6122 "ioremap failed for SLIM memory.\n");
6126 /* Map HBA Control Registers to a kernel virtual address. */
6127 phba
->ctrl_regs_memmap_p
= ioremap(phba
->pci_bar2_map
, bar2map_len
);
6128 if (!phba
->ctrl_regs_memmap_p
) {
6129 dev_printk(KERN_ERR
, &pdev
->dev
,
6130 "ioremap failed for HBA control registers.\n");
6131 goto out_iounmap_slim
;
6134 /* Allocate memory for SLI-2 structures */
6135 phba
->slim2p
.virt
= dma_alloc_coherent(&pdev
->dev
,
6139 if (!phba
->slim2p
.virt
)
6142 memset(phba
->slim2p
.virt
, 0, SLI2_SLIM_SIZE
);
6143 phba
->mbox
= phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, mbx
);
6144 phba
->mbox_ext
= (phba
->slim2p
.virt
+
6145 offsetof(struct lpfc_sli2_slim
, mbx_ext_words
));
6146 phba
->pcb
= (phba
->slim2p
.virt
+ offsetof(struct lpfc_sli2_slim
, pcb
));
6147 phba
->IOCBs
= (phba
->slim2p
.virt
+
6148 offsetof(struct lpfc_sli2_slim
, IOCBs
));
6150 phba
->hbqslimp
.virt
= dma_alloc_coherent(&pdev
->dev
,
6151 lpfc_sli_hbq_size(),
6152 &phba
->hbqslimp
.phys
,
6154 if (!phba
->hbqslimp
.virt
)
6157 hbq_count
= lpfc_sli_hbq_count();
6158 ptr
= phba
->hbqslimp
.virt
;
6159 for (i
= 0; i
< hbq_count
; ++i
) {
6160 phba
->hbqs
[i
].hbq_virt
= ptr
;
6161 INIT_LIST_HEAD(&phba
->hbqs
[i
].hbq_buffer_list
);
6162 ptr
+= (lpfc_hbq_defs
[i
]->entry_count
*
6163 sizeof(struct lpfc_hbq_entry
));
6165 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_alloc_buffer
= lpfc_els_hbq_alloc
;
6166 phba
->hbqs
[LPFC_ELS_HBQ
].hbq_free_buffer
= lpfc_els_hbq_free
;
6168 memset(phba
->hbqslimp
.virt
, 0, lpfc_sli_hbq_size());
6170 INIT_LIST_HEAD(&phba
->rb_pend_list
);
6172 phba
->MBslimaddr
= phba
->slim_memmap_p
;
6173 phba
->HAregaddr
= phba
->ctrl_regs_memmap_p
+ HA_REG_OFFSET
;
6174 phba
->CAregaddr
= phba
->ctrl_regs_memmap_p
+ CA_REG_OFFSET
;
6175 phba
->HSregaddr
= phba
->ctrl_regs_memmap_p
+ HS_REG_OFFSET
;
6176 phba
->HCregaddr
= phba
->ctrl_regs_memmap_p
+ HC_REG_OFFSET
;
6181 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
6182 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
6184 iounmap(phba
->ctrl_regs_memmap_p
);
6186 iounmap(phba
->slim_memmap_p
);
6192 * lpfc_sli_pci_mem_unset - Unset SLI3 HBA PCI memory space.
6193 * @phba: pointer to lpfc hba data structure.
6195 * This routine is invoked to unset the PCI device memory space for device
6196 * with SLI-3 interface spec.
6199 lpfc_sli_pci_mem_unset(struct lpfc_hba
*phba
)
6201 struct pci_dev
*pdev
;
6203 /* Obtain PCI device reference */
6207 pdev
= phba
->pcidev
;
6209 /* Free coherent DMA memory allocated */
6210 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
6211 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
6212 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
6213 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
6215 /* I/O memory unmap */
6216 iounmap(phba
->ctrl_regs_memmap_p
);
6217 iounmap(phba
->slim_memmap_p
);
6223 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
6224 * @phba: pointer to lpfc hba data structure.
6226 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
6227 * done and check status.
6229 * Return 0 if successful, otherwise -ENODEV.
6232 lpfc_sli4_post_status_check(struct lpfc_hba
*phba
)
6234 struct lpfc_register portsmphr_reg
, uerrlo_reg
, uerrhi_reg
;
6235 struct lpfc_register reg_data
;
6236 int i
, port_error
= 0;
6239 memset(&portsmphr_reg
, 0, sizeof(portsmphr_reg
));
6240 memset(®_data
, 0, sizeof(reg_data
));
6241 if (!phba
->sli4_hba
.PSMPHRregaddr
)
6244 /* Wait up to 30 seconds for the SLI Port POST done and ready */
6245 for (i
= 0; i
< 3000; i
++) {
6246 if (lpfc_readl(phba
->sli4_hba
.PSMPHRregaddr
,
6247 &portsmphr_reg
.word0
) ||
6248 (bf_get(lpfc_port_smphr_perr
, &portsmphr_reg
))) {
6249 /* Port has a fatal POST error, break out */
6250 port_error
= -ENODEV
;
6253 if (LPFC_POST_STAGE_PORT_READY
==
6254 bf_get(lpfc_port_smphr_port_status
, &portsmphr_reg
))
6260 * If there was a port error during POST, then don't proceed with
6261 * other register reads as the data may not be valid. Just exit.
6264 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6265 "1408 Port Failed POST - portsmphr=0x%x, "
6266 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, scr1=x%x, "
6267 "scr2=x%x, hscratch=x%x, pstatus=x%x\n",
6268 portsmphr_reg
.word0
,
6269 bf_get(lpfc_port_smphr_perr
, &portsmphr_reg
),
6270 bf_get(lpfc_port_smphr_sfi
, &portsmphr_reg
),
6271 bf_get(lpfc_port_smphr_nip
, &portsmphr_reg
),
6272 bf_get(lpfc_port_smphr_ipc
, &portsmphr_reg
),
6273 bf_get(lpfc_port_smphr_scr1
, &portsmphr_reg
),
6274 bf_get(lpfc_port_smphr_scr2
, &portsmphr_reg
),
6275 bf_get(lpfc_port_smphr_host_scratch
, &portsmphr_reg
),
6276 bf_get(lpfc_port_smphr_port_status
, &portsmphr_reg
));
6278 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
6279 "2534 Device Info: SLIFamily=0x%x, "
6280 "SLIRev=0x%x, IFType=0x%x, SLIHint_1=0x%x, "
6281 "SLIHint_2=0x%x, FT=0x%x\n",
6282 bf_get(lpfc_sli_intf_sli_family
,
6283 &phba
->sli4_hba
.sli_intf
),
6284 bf_get(lpfc_sli_intf_slirev
,
6285 &phba
->sli4_hba
.sli_intf
),
6286 bf_get(lpfc_sli_intf_if_type
,
6287 &phba
->sli4_hba
.sli_intf
),
6288 bf_get(lpfc_sli_intf_sli_hint1
,
6289 &phba
->sli4_hba
.sli_intf
),
6290 bf_get(lpfc_sli_intf_sli_hint2
,
6291 &phba
->sli4_hba
.sli_intf
),
6292 bf_get(lpfc_sli_intf_func_type
,
6293 &phba
->sli4_hba
.sli_intf
));
6295 * Check for other Port errors during the initialization
6296 * process. Fail the load if the port did not come up
6299 if_type
= bf_get(lpfc_sli_intf_if_type
,
6300 &phba
->sli4_hba
.sli_intf
);
6302 case LPFC_SLI_INTF_IF_TYPE_0
:
6303 phba
->sli4_hba
.ue_mask_lo
=
6304 readl(phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
);
6305 phba
->sli4_hba
.ue_mask_hi
=
6306 readl(phba
->sli4_hba
.u
.if_type0
.UEMASKHIregaddr
);
6308 readl(phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
);
6310 readl(phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
);
6311 if ((~phba
->sli4_hba
.ue_mask_lo
& uerrlo_reg
.word0
) ||
6312 (~phba
->sli4_hba
.ue_mask_hi
& uerrhi_reg
.word0
)) {
6313 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6314 "1422 Unrecoverable Error "
6315 "Detected during POST "
6316 "uerr_lo_reg=0x%x, "
6317 "uerr_hi_reg=0x%x, "
6318 "ue_mask_lo_reg=0x%x, "
6319 "ue_mask_hi_reg=0x%x\n",
6322 phba
->sli4_hba
.ue_mask_lo
,
6323 phba
->sli4_hba
.ue_mask_hi
);
6324 port_error
= -ENODEV
;
6327 case LPFC_SLI_INTF_IF_TYPE_2
:
6328 /* Final checks. The port status should be clean. */
6329 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
,
6331 (bf_get(lpfc_sliport_status_err
, ®_data
) &&
6332 !bf_get(lpfc_sliport_status_rn
, ®_data
))) {
6333 phba
->work_status
[0] =
6334 readl(phba
->sli4_hba
.u
.if_type2
.
6336 phba
->work_status
[1] =
6337 readl(phba
->sli4_hba
.u
.if_type2
.
6339 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6340 "2888 Unrecoverable port error "
6341 "following POST: port status reg "
6342 "0x%x, port_smphr reg 0x%x, "
6343 "error 1=0x%x, error 2=0x%x\n",
6345 portsmphr_reg
.word0
,
6346 phba
->work_status
[0],
6347 phba
->work_status
[1]);
6348 port_error
= -ENODEV
;
6351 case LPFC_SLI_INTF_IF_TYPE_1
:
6360 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
6361 * @phba: pointer to lpfc hba data structure.
6362 * @if_type: The SLI4 interface type getting configured.
6364 * This routine is invoked to set up SLI4 BAR0 PCI config space register
6368 lpfc_sli4_bar0_register_memmap(struct lpfc_hba
*phba
, uint32_t if_type
)
6371 case LPFC_SLI_INTF_IF_TYPE_0
:
6372 phba
->sli4_hba
.u
.if_type0
.UERRLOregaddr
=
6373 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UERR_STATUS_LO
;
6374 phba
->sli4_hba
.u
.if_type0
.UERRHIregaddr
=
6375 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UERR_STATUS_HI
;
6376 phba
->sli4_hba
.u
.if_type0
.UEMASKLOregaddr
=
6377 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UE_MASK_LO
;
6378 phba
->sli4_hba
.u
.if_type0
.UEMASKHIregaddr
=
6379 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_UE_MASK_HI
;
6380 phba
->sli4_hba
.SLIINTFregaddr
=
6381 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_SLI_INTF
;
6383 case LPFC_SLI_INTF_IF_TYPE_2
:
6384 phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
=
6385 phba
->sli4_hba
.conf_regs_memmap_p
+
6386 LPFC_CTL_PORT_ER1_OFFSET
;
6387 phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
=
6388 phba
->sli4_hba
.conf_regs_memmap_p
+
6389 LPFC_CTL_PORT_ER2_OFFSET
;
6390 phba
->sli4_hba
.u
.if_type2
.CTRLregaddr
=
6391 phba
->sli4_hba
.conf_regs_memmap_p
+
6392 LPFC_CTL_PORT_CTL_OFFSET
;
6393 phba
->sli4_hba
.u
.if_type2
.STATUSregaddr
=
6394 phba
->sli4_hba
.conf_regs_memmap_p
+
6395 LPFC_CTL_PORT_STA_OFFSET
;
6396 phba
->sli4_hba
.SLIINTFregaddr
=
6397 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_SLI_INTF
;
6398 phba
->sli4_hba
.PSMPHRregaddr
=
6399 phba
->sli4_hba
.conf_regs_memmap_p
+
6400 LPFC_CTL_PORT_SEM_OFFSET
;
6401 phba
->sli4_hba
.RQDBregaddr
=
6402 phba
->sli4_hba
.conf_regs_memmap_p
+
6403 LPFC_ULP0_RQ_DOORBELL
;
6404 phba
->sli4_hba
.WQDBregaddr
=
6405 phba
->sli4_hba
.conf_regs_memmap_p
+
6406 LPFC_ULP0_WQ_DOORBELL
;
6407 phba
->sli4_hba
.EQCQDBregaddr
=
6408 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_EQCQ_DOORBELL
;
6409 phba
->sli4_hba
.MQDBregaddr
=
6410 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_MQ_DOORBELL
;
6411 phba
->sli4_hba
.BMBXregaddr
=
6412 phba
->sli4_hba
.conf_regs_memmap_p
+ LPFC_BMBX
;
6414 case LPFC_SLI_INTF_IF_TYPE_1
:
6416 dev_printk(KERN_ERR
, &phba
->pcidev
->dev
,
6417 "FATAL - unsupported SLI4 interface type - %d\n",
6424 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
6425 * @phba: pointer to lpfc hba data structure.
6427 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
6431 lpfc_sli4_bar1_register_memmap(struct lpfc_hba
*phba
)
6433 phba
->sli4_hba
.PSMPHRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
6434 LPFC_SLIPORT_IF0_SMPHR
;
6435 phba
->sli4_hba
.ISRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
6437 phba
->sli4_hba
.IMRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
6439 phba
->sli4_hba
.ISCRregaddr
= phba
->sli4_hba
.ctrl_regs_memmap_p
+
6444 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
6445 * @phba: pointer to lpfc hba data structure.
6446 * @vf: virtual function number
6448 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
6449 * based on the given viftual function number, @vf.
6451 * Return 0 if successful, otherwise -ENODEV.
6454 lpfc_sli4_bar2_register_memmap(struct lpfc_hba
*phba
, uint32_t vf
)
6456 if (vf
> LPFC_VIR_FUNC_MAX
)
6459 phba
->sli4_hba
.RQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
6460 vf
* LPFC_VFR_PAGE_SIZE
+
6461 LPFC_ULP0_RQ_DOORBELL
);
6462 phba
->sli4_hba
.WQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
6463 vf
* LPFC_VFR_PAGE_SIZE
+
6464 LPFC_ULP0_WQ_DOORBELL
);
6465 phba
->sli4_hba
.EQCQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
6466 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_EQCQ_DOORBELL
);
6467 phba
->sli4_hba
.MQDBregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
6468 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_MQ_DOORBELL
);
6469 phba
->sli4_hba
.BMBXregaddr
= (phba
->sli4_hba
.drbl_regs_memmap_p
+
6470 vf
* LPFC_VFR_PAGE_SIZE
+ LPFC_BMBX
);
6475 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
6476 * @phba: pointer to lpfc hba data structure.
6478 * This routine is invoked to create the bootstrap mailbox
6479 * region consistent with the SLI-4 interface spec. This
6480 * routine allocates all memory necessary to communicate
6481 * mailbox commands to the port and sets up all alignment
6482 * needs. No locks are expected to be held when calling
6487 * -ENOMEM - could not allocated memory.
6490 lpfc_create_bootstrap_mbox(struct lpfc_hba
*phba
)
6493 struct lpfc_dmabuf
*dmabuf
;
6494 struct dma_address
*dma_address
;
6498 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
6503 * The bootstrap mailbox region is comprised of 2 parts
6504 * plus an alignment restriction of 16 bytes.
6506 bmbx_size
= sizeof(struct lpfc_bmbx_create
) + (LPFC_ALIGN_16_BYTE
- 1);
6507 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
6511 if (!dmabuf
->virt
) {
6515 memset(dmabuf
->virt
, 0, bmbx_size
);
6518 * Initialize the bootstrap mailbox pointers now so that the register
6519 * operations are simple later. The mailbox dma address is required
6520 * to be 16-byte aligned. Also align the virtual memory as each
6521 * maibox is copied into the bmbx mailbox region before issuing the
6522 * command to the port.
6524 phba
->sli4_hba
.bmbx
.dmabuf
= dmabuf
;
6525 phba
->sli4_hba
.bmbx
.bmbx_size
= bmbx_size
;
6527 phba
->sli4_hba
.bmbx
.avirt
= PTR_ALIGN(dmabuf
->virt
,
6528 LPFC_ALIGN_16_BYTE
);
6529 phba
->sli4_hba
.bmbx
.aphys
= ALIGN(dmabuf
->phys
,
6530 LPFC_ALIGN_16_BYTE
);
6533 * Set the high and low physical addresses now. The SLI4 alignment
6534 * requirement is 16 bytes and the mailbox is posted to the port
6535 * as two 30-bit addresses. The other data is a bit marking whether
6536 * the 30-bit address is the high or low address.
6537 * Upcast bmbx aphys to 64bits so shift instruction compiles
6538 * clean on 32 bit machines.
6540 dma_address
= &phba
->sli4_hba
.bmbx
.dma_address
;
6541 phys_addr
= (uint64_t)phba
->sli4_hba
.bmbx
.aphys
;
6542 pa_addr
= (uint32_t) ((phys_addr
>> 34) & 0x3fffffff);
6543 dma_address
->addr_hi
= (uint32_t) ((pa_addr
<< 2) |
6544 LPFC_BMBX_BIT1_ADDR_HI
);
6546 pa_addr
= (uint32_t) ((phba
->sli4_hba
.bmbx
.aphys
>> 4) & 0x3fffffff);
6547 dma_address
->addr_lo
= (uint32_t) ((pa_addr
<< 2) |
6548 LPFC_BMBX_BIT1_ADDR_LO
);
6553 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
6554 * @phba: pointer to lpfc hba data structure.
6556 * This routine is invoked to teardown the bootstrap mailbox
6557 * region and release all host resources. This routine requires
6558 * the caller to ensure all mailbox commands recovered, no
6559 * additional mailbox comands are sent, and interrupts are disabled
6560 * before calling this routine.
6564 lpfc_destroy_bootstrap_mbox(struct lpfc_hba
*phba
)
6566 dma_free_coherent(&phba
->pcidev
->dev
,
6567 phba
->sli4_hba
.bmbx
.bmbx_size
,
6568 phba
->sli4_hba
.bmbx
.dmabuf
->virt
,
6569 phba
->sli4_hba
.bmbx
.dmabuf
->phys
);
6571 kfree(phba
->sli4_hba
.bmbx
.dmabuf
);
6572 memset(&phba
->sli4_hba
.bmbx
, 0, sizeof(struct lpfc_bmbx
));
6576 * lpfc_sli4_read_config - Get the config parameters.
6577 * @phba: pointer to lpfc hba data structure.
6579 * This routine is invoked to read the configuration parameters from the HBA.
6580 * The configuration parameters are used to set the base and maximum values
6581 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
6582 * allocation for the port.
6586 * -ENOMEM - No available memory
6587 * -EIO - The mailbox failed to complete successfully.
6590 lpfc_sli4_read_config(struct lpfc_hba
*phba
)
6593 struct lpfc_mbx_read_config
*rd_config
;
6594 union lpfc_sli4_cfg_shdr
*shdr
;
6595 uint32_t shdr_status
, shdr_add_status
;
6596 struct lpfc_mbx_get_func_cfg
*get_func_cfg
;
6597 struct lpfc_rsrc_desc_fcfcoe
*desc
;
6599 uint32_t desc_count
;
6600 int length
, i
, rc
= 0, rc2
;
6602 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6604 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6605 "2011 Unable to allocate memory for issuing "
6606 "SLI_CONFIG_SPECIAL mailbox command\n");
6610 lpfc_read_config(phba
, pmb
);
6612 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
6613 if (rc
!= MBX_SUCCESS
) {
6614 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6615 "2012 Mailbox failed , mbxCmd x%x "
6616 "READ_CONFIG, mbxStatus x%x\n",
6617 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
6618 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
6621 rd_config
= &pmb
->u
.mqe
.un
.rd_config
;
6622 if (bf_get(lpfc_mbx_rd_conf_lnk_ldv
, rd_config
)) {
6623 phba
->sli4_hba
.lnk_info
.lnk_dv
= LPFC_LNK_DAT_VAL
;
6624 phba
->sli4_hba
.lnk_info
.lnk_tp
=
6625 bf_get(lpfc_mbx_rd_conf_lnk_type
, rd_config
);
6626 phba
->sli4_hba
.lnk_info
.lnk_no
=
6627 bf_get(lpfc_mbx_rd_conf_lnk_numb
, rd_config
);
6628 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
6629 "3081 lnk_type:%d, lnk_numb:%d\n",
6630 phba
->sli4_hba
.lnk_info
.lnk_tp
,
6631 phba
->sli4_hba
.lnk_info
.lnk_no
);
6633 lpfc_printf_log(phba
, KERN_WARNING
, LOG_SLI
,
6634 "3082 Mailbox (x%x) returned ldv:x0\n",
6635 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
));
6636 phba
->sli4_hba
.extents_in_use
=
6637 bf_get(lpfc_mbx_rd_conf_extnts_inuse
, rd_config
);
6638 phba
->sli4_hba
.max_cfg_param
.max_xri
=
6639 bf_get(lpfc_mbx_rd_conf_xri_count
, rd_config
);
6640 phba
->sli4_hba
.max_cfg_param
.xri_base
=
6641 bf_get(lpfc_mbx_rd_conf_xri_base
, rd_config
);
6642 phba
->sli4_hba
.max_cfg_param
.max_vpi
=
6643 bf_get(lpfc_mbx_rd_conf_vpi_count
, rd_config
);
6644 phba
->sli4_hba
.max_cfg_param
.vpi_base
=
6645 bf_get(lpfc_mbx_rd_conf_vpi_base
, rd_config
);
6646 phba
->sli4_hba
.max_cfg_param
.max_rpi
=
6647 bf_get(lpfc_mbx_rd_conf_rpi_count
, rd_config
);
6648 phba
->sli4_hba
.max_cfg_param
.rpi_base
=
6649 bf_get(lpfc_mbx_rd_conf_rpi_base
, rd_config
);
6650 phba
->sli4_hba
.max_cfg_param
.max_vfi
=
6651 bf_get(lpfc_mbx_rd_conf_vfi_count
, rd_config
);
6652 phba
->sli4_hba
.max_cfg_param
.vfi_base
=
6653 bf_get(lpfc_mbx_rd_conf_vfi_base
, rd_config
);
6654 phba
->sli4_hba
.max_cfg_param
.max_fcfi
=
6655 bf_get(lpfc_mbx_rd_conf_fcfi_count
, rd_config
);
6656 phba
->sli4_hba
.max_cfg_param
.max_eq
=
6657 bf_get(lpfc_mbx_rd_conf_eq_count
, rd_config
);
6658 phba
->sli4_hba
.max_cfg_param
.max_rq
=
6659 bf_get(lpfc_mbx_rd_conf_rq_count
, rd_config
);
6660 phba
->sli4_hba
.max_cfg_param
.max_wq
=
6661 bf_get(lpfc_mbx_rd_conf_wq_count
, rd_config
);
6662 phba
->sli4_hba
.max_cfg_param
.max_cq
=
6663 bf_get(lpfc_mbx_rd_conf_cq_count
, rd_config
);
6664 phba
->lmt
= bf_get(lpfc_mbx_rd_conf_lmt
, rd_config
);
6665 phba
->sli4_hba
.next_xri
= phba
->sli4_hba
.max_cfg_param
.xri_base
;
6666 phba
->vpi_base
= phba
->sli4_hba
.max_cfg_param
.vpi_base
;
6667 phba
->vfi_base
= phba
->sli4_hba
.max_cfg_param
.vfi_base
;
6668 phba
->max_vpi
= (phba
->sli4_hba
.max_cfg_param
.max_vpi
> 0) ?
6669 (phba
->sli4_hba
.max_cfg_param
.max_vpi
- 1) : 0;
6670 phba
->max_vports
= phba
->max_vpi
;
6671 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
6672 "2003 cfg params Extents? %d "
6678 phba
->sli4_hba
.extents_in_use
,
6679 phba
->sli4_hba
.max_cfg_param
.xri_base
,
6680 phba
->sli4_hba
.max_cfg_param
.max_xri
,
6681 phba
->sli4_hba
.max_cfg_param
.vpi_base
,
6682 phba
->sli4_hba
.max_cfg_param
.max_vpi
,
6683 phba
->sli4_hba
.max_cfg_param
.vfi_base
,
6684 phba
->sli4_hba
.max_cfg_param
.max_vfi
,
6685 phba
->sli4_hba
.max_cfg_param
.rpi_base
,
6686 phba
->sli4_hba
.max_cfg_param
.max_rpi
,
6687 phba
->sli4_hba
.max_cfg_param
.max_fcfi
);
6693 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
6694 if (phba
->cfg_hba_queue_depth
>
6695 (phba
->sli4_hba
.max_cfg_param
.max_xri
-
6696 lpfc_sli4_get_els_iocb_cnt(phba
)))
6697 phba
->cfg_hba_queue_depth
=
6698 phba
->sli4_hba
.max_cfg_param
.max_xri
-
6699 lpfc_sli4_get_els_iocb_cnt(phba
);
6701 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
6702 LPFC_SLI_INTF_IF_TYPE_2
)
6705 /* get the pf# and vf# for SLI4 if_type 2 port */
6706 length
= (sizeof(struct lpfc_mbx_get_func_cfg
) -
6707 sizeof(struct lpfc_sli4_cfg_mhdr
));
6708 lpfc_sli4_config(phba
, pmb
, LPFC_MBOX_SUBSYSTEM_COMMON
,
6709 LPFC_MBOX_OPCODE_GET_FUNCTION_CONFIG
,
6710 length
, LPFC_SLI4_MBX_EMBED
);
6712 rc2
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
6713 shdr
= (union lpfc_sli4_cfg_shdr
*)
6714 &pmb
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
6715 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
6716 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
6717 if (rc2
|| shdr_status
|| shdr_add_status
) {
6718 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6719 "3026 Mailbox failed , mbxCmd x%x "
6720 "GET_FUNCTION_CONFIG, mbxStatus x%x\n",
6721 bf_get(lpfc_mqe_command
, &pmb
->u
.mqe
),
6722 bf_get(lpfc_mqe_status
, &pmb
->u
.mqe
));
6726 /* search for fc_fcoe resrouce descriptor */
6727 get_func_cfg
= &pmb
->u
.mqe
.un
.get_func_cfg
;
6728 desc_count
= get_func_cfg
->func_cfg
.rsrc_desc_count
;
6730 pdesc_0
= (char *)&get_func_cfg
->func_cfg
.desc
[0];
6731 desc
= (struct lpfc_rsrc_desc_fcfcoe
*)pdesc_0
;
6732 length
= bf_get(lpfc_rsrc_desc_fcfcoe_length
, desc
);
6733 if (length
== LPFC_RSRC_DESC_TYPE_FCFCOE_V0_RSVD
)
6734 length
= LPFC_RSRC_DESC_TYPE_FCFCOE_V0_LENGTH
;
6735 else if (length
!= LPFC_RSRC_DESC_TYPE_FCFCOE_V1_LENGTH
)
6738 for (i
= 0; i
< LPFC_RSRC_DESC_MAX_NUM
; i
++) {
6739 desc
= (struct lpfc_rsrc_desc_fcfcoe
*)(pdesc_0
+ length
* i
);
6740 if (LPFC_RSRC_DESC_TYPE_FCFCOE
==
6741 bf_get(lpfc_rsrc_desc_fcfcoe_type
, desc
)) {
6742 phba
->sli4_hba
.iov
.pf_number
=
6743 bf_get(lpfc_rsrc_desc_fcfcoe_pfnum
, desc
);
6744 phba
->sli4_hba
.iov
.vf_number
=
6745 bf_get(lpfc_rsrc_desc_fcfcoe_vfnum
, desc
);
6750 if (i
< LPFC_RSRC_DESC_MAX_NUM
)
6751 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
6752 "3027 GET_FUNCTION_CONFIG: pf_number:%d, "
6753 "vf_number:%d\n", phba
->sli4_hba
.iov
.pf_number
,
6754 phba
->sli4_hba
.iov
.vf_number
);
6756 lpfc_printf_log(phba
, KERN_ERR
, LOG_SLI
,
6757 "3028 GET_FUNCTION_CONFIG: failed to find "
6758 "Resrouce Descriptor:x%x\n",
6759 LPFC_RSRC_DESC_TYPE_FCFCOE
);
6762 mempool_free(pmb
, phba
->mbox_mem_pool
);
6767 * lpfc_setup_endian_order - Write endian order to an SLI4 if_type 0 port.
6768 * @phba: pointer to lpfc hba data structure.
6770 * This routine is invoked to setup the port-side endian order when
6771 * the port if_type is 0. This routine has no function for other
6776 * -ENOMEM - No available memory
6777 * -EIO - The mailbox failed to complete successfully.
6780 lpfc_setup_endian_order(struct lpfc_hba
*phba
)
6782 LPFC_MBOXQ_t
*mboxq
;
6783 uint32_t if_type
, rc
= 0;
6784 uint32_t endian_mb_data
[2] = {HOST_ENDIAN_LOW_WORD0
,
6785 HOST_ENDIAN_HIGH_WORD1
};
6787 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
6789 case LPFC_SLI_INTF_IF_TYPE_0
:
6790 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
6793 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6794 "0492 Unable to allocate memory for "
6795 "issuing SLI_CONFIG_SPECIAL mailbox "
6801 * The SLI4_CONFIG_SPECIAL mailbox command requires the first
6802 * two words to contain special data values and no other data.
6804 memset(mboxq
, 0, sizeof(LPFC_MBOXQ_t
));
6805 memcpy(&mboxq
->u
.mqe
, &endian_mb_data
, sizeof(endian_mb_data
));
6806 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
6807 if (rc
!= MBX_SUCCESS
) {
6808 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6809 "0493 SLI_CONFIG_SPECIAL mailbox "
6810 "failed with status x%x\n",
6814 mempool_free(mboxq
, phba
->mbox_mem_pool
);
6816 case LPFC_SLI_INTF_IF_TYPE_2
:
6817 case LPFC_SLI_INTF_IF_TYPE_1
:
6825 * lpfc_sli4_queue_verify - Verify and update EQ and CQ counts
6826 * @phba: pointer to lpfc hba data structure.
6828 * This routine is invoked to check the user settable queue counts for EQs and
6829 * CQs. after this routine is called the counts will be set to valid values that
6830 * adhere to the constraints of the system's interrupt vectors and the port's
6835 * -ENOMEM - No available memory
6838 lpfc_sli4_queue_verify(struct lpfc_hba
*phba
)
6840 int cfg_fcp_io_channel
;
6845 * Sanity check for configured queue parameters against the run-time
6849 /* Sanity check on HBA EQ parameters */
6850 cfg_fcp_io_channel
= phba
->cfg_fcp_io_channel
;
6852 /* It doesn't make sense to have more io channels then online CPUs */
6853 for_each_present_cpu(cpu
) {
6854 if (cpu_online(cpu
))
6857 phba
->sli4_hba
.num_online_cpu
= i
;
6858 phba
->sli4_hba
.num_present_cpu
= lpfc_present_cpu
;
6860 if (i
< cfg_fcp_io_channel
) {
6861 lpfc_printf_log(phba
,
6863 "3188 Reducing IO channels to match number of "
6864 "online CPUs: from %d to %d\n",
6865 cfg_fcp_io_channel
, i
);
6866 cfg_fcp_io_channel
= i
;
6869 if (cfg_fcp_io_channel
>
6870 phba
->sli4_hba
.max_cfg_param
.max_eq
) {
6871 if (phba
->sli4_hba
.max_cfg_param
.max_eq
<
6872 LPFC_FCP_IO_CHAN_MIN
) {
6873 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6874 "2574 Not enough EQs (%d) from the "
6875 "pci function for supporting FCP "
6877 phba
->sli4_hba
.max_cfg_param
.max_eq
,
6878 phba
->cfg_fcp_io_channel
);
6881 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6882 "2575 Reducing IO channels to match number of "
6883 "available EQs: from %d to %d\n",
6885 phba
->sli4_hba
.max_cfg_param
.max_eq
);
6886 cfg_fcp_io_channel
= phba
->sli4_hba
.max_cfg_param
.max_eq
;
6889 /* Eventually cfg_fcp_eq_count / cfg_fcp_wq_count will be depricated */
6891 /* The actual number of FCP event queues adopted */
6892 phba
->cfg_fcp_eq_count
= cfg_fcp_io_channel
;
6893 phba
->cfg_fcp_wq_count
= cfg_fcp_io_channel
;
6894 phba
->cfg_fcp_io_channel
= cfg_fcp_io_channel
;
6896 /* Get EQ depth from module parameter, fake the default for now */
6897 phba
->sli4_hba
.eq_esize
= LPFC_EQE_SIZE_4B
;
6898 phba
->sli4_hba
.eq_ecount
= LPFC_EQE_DEF_COUNT
;
6900 /* Get CQ depth from module parameter, fake the default for now */
6901 phba
->sli4_hba
.cq_esize
= LPFC_CQE_SIZE
;
6902 phba
->sli4_hba
.cq_ecount
= LPFC_CQE_DEF_COUNT
;
6910 * lpfc_sli4_queue_create - Create all the SLI4 queues
6911 * @phba: pointer to lpfc hba data structure.
6913 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
6914 * operation. For each SLI4 queue type, the parameters such as queue entry
6915 * count (queue depth) shall be taken from the module parameter. For now,
6916 * we just use some constant number as place holder.
6920 * -ENOMEM - No availble memory
6921 * -EIO - The mailbox failed to complete successfully.
6924 lpfc_sli4_queue_create(struct lpfc_hba
*phba
)
6926 struct lpfc_queue
*qdesc
;
6930 * Create HBA Record arrays.
6932 if (!phba
->cfg_fcp_io_channel
)
6935 phba
->sli4_hba
.mq_esize
= LPFC_MQE_SIZE
;
6936 phba
->sli4_hba
.mq_ecount
= LPFC_MQE_DEF_COUNT
;
6937 phba
->sli4_hba
.wq_esize
= LPFC_WQE_SIZE
;
6938 phba
->sli4_hba
.wq_ecount
= LPFC_WQE_DEF_COUNT
;
6939 phba
->sli4_hba
.rq_esize
= LPFC_RQE_SIZE
;
6940 phba
->sli4_hba
.rq_ecount
= LPFC_RQE_DEF_COUNT
;
6942 phba
->sli4_hba
.hba_eq
= kzalloc((sizeof(struct lpfc_queue
*) *
6943 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
6944 if (!phba
->sli4_hba
.hba_eq
) {
6945 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6946 "2576 Failed allocate memory for "
6947 "fast-path EQ record array\n");
6951 phba
->sli4_hba
.fcp_cq
= kzalloc((sizeof(struct lpfc_queue
*) *
6952 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
6953 if (!phba
->sli4_hba
.fcp_cq
) {
6954 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6955 "2577 Failed allocate memory for fast-path "
6956 "CQ record array\n");
6960 phba
->sli4_hba
.fcp_wq
= kzalloc((sizeof(struct lpfc_queue
*) *
6961 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
6962 if (!phba
->sli4_hba
.fcp_wq
) {
6963 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6964 "2578 Failed allocate memory for fast-path "
6965 "WQ record array\n");
6970 * Since the first EQ can have multiple CQs associated with it,
6971 * this array is used to quickly see if we have a FCP fast-path
6974 phba
->sli4_hba
.fcp_cq_map
= kzalloc((sizeof(uint16_t) *
6975 phba
->cfg_fcp_io_channel
), GFP_KERNEL
);
6976 if (!phba
->sli4_hba
.fcp_cq_map
) {
6977 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6978 "2545 Failed allocate memory for fast-path "
6984 * Create HBA Event Queues (EQs). The cfg_fcp_io_channel specifies
6985 * how many EQs to create.
6987 for (idx
= 0; idx
< phba
->cfg_fcp_io_channel
; idx
++) {
6990 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.eq_esize
,
6991 phba
->sli4_hba
.eq_ecount
);
6993 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
6994 "0497 Failed allocate EQ (%d)\n", idx
);
6997 phba
->sli4_hba
.hba_eq
[idx
] = qdesc
;
6999 /* Create Fast Path FCP CQs */
7000 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
7001 phba
->sli4_hba
.cq_ecount
);
7003 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7004 "0499 Failed allocate fast-path FCP "
7008 phba
->sli4_hba
.fcp_cq
[idx
] = qdesc
;
7010 /* Create Fast Path FCP WQs */
7011 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
7012 phba
->sli4_hba
.wq_ecount
);
7014 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7015 "0503 Failed allocate fast-path FCP "
7019 phba
->sli4_hba
.fcp_wq
[idx
] = qdesc
;
7024 * Create Slow Path Completion Queues (CQs)
7027 /* Create slow-path Mailbox Command Complete Queue */
7028 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
7029 phba
->sli4_hba
.cq_ecount
);
7031 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7032 "0500 Failed allocate slow-path mailbox CQ\n");
7035 phba
->sli4_hba
.mbx_cq
= qdesc
;
7037 /* Create slow-path ELS Complete Queue */
7038 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.cq_esize
,
7039 phba
->sli4_hba
.cq_ecount
);
7041 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7042 "0501 Failed allocate slow-path ELS CQ\n");
7045 phba
->sli4_hba
.els_cq
= qdesc
;
7049 * Create Slow Path Work Queues (WQs)
7052 /* Create Mailbox Command Queue */
7054 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.mq_esize
,
7055 phba
->sli4_hba
.mq_ecount
);
7057 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7058 "0505 Failed allocate slow-path MQ\n");
7061 phba
->sli4_hba
.mbx_wq
= qdesc
;
7064 * Create ELS Work Queues
7067 /* Create slow-path ELS Work Queue */
7068 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.wq_esize
,
7069 phba
->sli4_hba
.wq_ecount
);
7071 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7072 "0504 Failed allocate slow-path ELS WQ\n");
7075 phba
->sli4_hba
.els_wq
= qdesc
;
7078 * Create Receive Queue (RQ)
7081 /* Create Receive Queue for header */
7082 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
7083 phba
->sli4_hba
.rq_ecount
);
7085 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7086 "0506 Failed allocate receive HRQ\n");
7089 phba
->sli4_hba
.hdr_rq
= qdesc
;
7091 /* Create Receive Queue for data */
7092 qdesc
= lpfc_sli4_queue_alloc(phba
, phba
->sli4_hba
.rq_esize
,
7093 phba
->sli4_hba
.rq_ecount
);
7095 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7096 "0507 Failed allocate receive DRQ\n");
7099 phba
->sli4_hba
.dat_rq
= qdesc
;
7104 lpfc_sli4_queue_destroy(phba
);
7109 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
7110 * @phba: pointer to lpfc hba data structure.
7112 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
7117 * -ENOMEM - No available memory
7118 * -EIO - The mailbox failed to complete successfully.
7121 lpfc_sli4_queue_destroy(struct lpfc_hba
*phba
)
7125 if (phba
->sli4_hba
.hba_eq
!= NULL
) {
7126 /* Release HBA event queue */
7127 for (idx
= 0; idx
< phba
->cfg_fcp_io_channel
; idx
++) {
7128 if (phba
->sli4_hba
.hba_eq
[idx
] != NULL
) {
7129 lpfc_sli4_queue_free(
7130 phba
->sli4_hba
.hba_eq
[idx
]);
7131 phba
->sli4_hba
.hba_eq
[idx
] = NULL
;
7134 kfree(phba
->sli4_hba
.hba_eq
);
7135 phba
->sli4_hba
.hba_eq
= NULL
;
7138 if (phba
->sli4_hba
.fcp_cq
!= NULL
) {
7139 /* Release FCP completion queue */
7140 for (idx
= 0; idx
< phba
->cfg_fcp_io_channel
; idx
++) {
7141 if (phba
->sli4_hba
.fcp_cq
[idx
] != NULL
) {
7142 lpfc_sli4_queue_free(
7143 phba
->sli4_hba
.fcp_cq
[idx
]);
7144 phba
->sli4_hba
.fcp_cq
[idx
] = NULL
;
7147 kfree(phba
->sli4_hba
.fcp_cq
);
7148 phba
->sli4_hba
.fcp_cq
= NULL
;
7151 if (phba
->sli4_hba
.fcp_wq
!= NULL
) {
7152 /* Release FCP work queue */
7153 for (idx
= 0; idx
< phba
->cfg_fcp_io_channel
; idx
++) {
7154 if (phba
->sli4_hba
.fcp_wq
[idx
] != NULL
) {
7155 lpfc_sli4_queue_free(
7156 phba
->sli4_hba
.fcp_wq
[idx
]);
7157 phba
->sli4_hba
.fcp_wq
[idx
] = NULL
;
7160 kfree(phba
->sli4_hba
.fcp_wq
);
7161 phba
->sli4_hba
.fcp_wq
= NULL
;
7164 if (phba
->pci_bar0_memmap_p
) {
7165 iounmap(phba
->pci_bar0_memmap_p
);
7166 phba
->pci_bar0_memmap_p
= NULL
;
7168 if (phba
->pci_bar2_memmap_p
) {
7169 iounmap(phba
->pci_bar2_memmap_p
);
7170 phba
->pci_bar2_memmap_p
= NULL
;
7172 if (phba
->pci_bar4_memmap_p
) {
7173 iounmap(phba
->pci_bar4_memmap_p
);
7174 phba
->pci_bar4_memmap_p
= NULL
;
7177 /* Release FCP CQ mapping array */
7178 if (phba
->sli4_hba
.fcp_cq_map
!= NULL
) {
7179 kfree(phba
->sli4_hba
.fcp_cq_map
);
7180 phba
->sli4_hba
.fcp_cq_map
= NULL
;
7183 /* Release mailbox command work queue */
7184 if (phba
->sli4_hba
.mbx_wq
!= NULL
) {
7185 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_wq
);
7186 phba
->sli4_hba
.mbx_wq
= NULL
;
7189 /* Release ELS work queue */
7190 if (phba
->sli4_hba
.els_wq
!= NULL
) {
7191 lpfc_sli4_queue_free(phba
->sli4_hba
.els_wq
);
7192 phba
->sli4_hba
.els_wq
= NULL
;
7195 /* Release unsolicited receive queue */
7196 if (phba
->sli4_hba
.hdr_rq
!= NULL
) {
7197 lpfc_sli4_queue_free(phba
->sli4_hba
.hdr_rq
);
7198 phba
->sli4_hba
.hdr_rq
= NULL
;
7200 if (phba
->sli4_hba
.dat_rq
!= NULL
) {
7201 lpfc_sli4_queue_free(phba
->sli4_hba
.dat_rq
);
7202 phba
->sli4_hba
.dat_rq
= NULL
;
7205 /* Release ELS complete queue */
7206 if (phba
->sli4_hba
.els_cq
!= NULL
) {
7207 lpfc_sli4_queue_free(phba
->sli4_hba
.els_cq
);
7208 phba
->sli4_hba
.els_cq
= NULL
;
7211 /* Release mailbox command complete queue */
7212 if (phba
->sli4_hba
.mbx_cq
!= NULL
) {
7213 lpfc_sli4_queue_free(phba
->sli4_hba
.mbx_cq
);
7214 phba
->sli4_hba
.mbx_cq
= NULL
;
7221 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
7222 * @phba: pointer to lpfc hba data structure.
7224 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
7229 * -ENOMEM - No available memory
7230 * -EIO - The mailbox failed to complete successfully.
7233 lpfc_sli4_queue_setup(struct lpfc_hba
*phba
)
7235 struct lpfc_sli
*psli
= &phba
->sli
;
7236 struct lpfc_sli_ring
*pring
;
7238 int fcp_eqidx
, fcp_cqidx
, fcp_wqidx
;
7239 int fcp_cq_index
= 0;
7240 uint32_t shdr_status
, shdr_add_status
;
7241 union lpfc_sli4_cfg_shdr
*shdr
;
7242 LPFC_MBOXQ_t
*mboxq
;
7245 /* Check for dual-ULP support */
7246 mboxq
= (LPFC_MBOXQ_t
*)mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
7248 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7249 "3249 Unable to allocate memory for "
7250 "QUERY_FW_CFG mailbox command\n");
7253 length
= (sizeof(struct lpfc_mbx_query_fw_config
) -
7254 sizeof(struct lpfc_sli4_cfg_mhdr
));
7255 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
7256 LPFC_MBOX_OPCODE_QUERY_FW_CFG
,
7257 length
, LPFC_SLI4_MBX_EMBED
);
7259 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7261 shdr
= (union lpfc_sli4_cfg_shdr
*)
7262 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
7263 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
7264 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
7265 if (shdr_status
|| shdr_add_status
|| rc
) {
7266 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7267 "3250 QUERY_FW_CFG mailbox failed with status "
7268 "x%x add_status x%x, mbx status x%x\n",
7269 shdr_status
, shdr_add_status
, rc
);
7270 if (rc
!= MBX_TIMEOUT
)
7271 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7276 phba
->sli4_hba
.fw_func_mode
=
7277 mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.function_mode
;
7278 phba
->sli4_hba
.ulp0_mode
= mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.ulp0_mode
;
7279 phba
->sli4_hba
.ulp1_mode
= mboxq
->u
.mqe
.un
.query_fw_cfg
.rsp
.ulp1_mode
;
7280 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7281 "3251 QUERY_FW_CFG: func_mode:x%x, ulp0_mode:x%x, "
7282 "ulp1_mode:x%x\n", phba
->sli4_hba
.fw_func_mode
,
7283 phba
->sli4_hba
.ulp0_mode
, phba
->sli4_hba
.ulp1_mode
);
7285 if (rc
!= MBX_TIMEOUT
)
7286 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7289 * Set up HBA Event Queues (EQs)
7292 /* Set up HBA event queue */
7293 if (phba
->cfg_fcp_io_channel
&& !phba
->sli4_hba
.hba_eq
) {
7294 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7295 "3147 Fast-path EQs not allocated\n");
7299 for (fcp_eqidx
= 0; fcp_eqidx
< phba
->cfg_fcp_io_channel
; fcp_eqidx
++) {
7300 if (!phba
->sli4_hba
.hba_eq
[fcp_eqidx
]) {
7301 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7302 "0522 Fast-path EQ (%d) not "
7303 "allocated\n", fcp_eqidx
);
7305 goto out_destroy_hba_eq
;
7307 rc
= lpfc_eq_create(phba
, phba
->sli4_hba
.hba_eq
[fcp_eqidx
],
7308 (phba
->cfg_fcp_imax
/ phba
->cfg_fcp_io_channel
));
7310 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7311 "0523 Failed setup of fast-path EQ "
7312 "(%d), rc = 0x%x\n", fcp_eqidx
, rc
);
7313 goto out_destroy_hba_eq
;
7315 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7316 "2584 HBA EQ setup: "
7317 "queue[%d]-id=%d\n", fcp_eqidx
,
7318 phba
->sli4_hba
.hba_eq
[fcp_eqidx
]->queue_id
);
7321 /* Set up fast-path FCP Response Complete Queue */
7322 if (!phba
->sli4_hba
.fcp_cq
) {
7323 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7324 "3148 Fast-path FCP CQ array not "
7327 goto out_destroy_hba_eq
;
7330 for (fcp_cqidx
= 0; fcp_cqidx
< phba
->cfg_fcp_io_channel
; fcp_cqidx
++) {
7331 if (!phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]) {
7332 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7333 "0526 Fast-path FCP CQ (%d) not "
7334 "allocated\n", fcp_cqidx
);
7336 goto out_destroy_fcp_cq
;
7338 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.fcp_cq
[fcp_cqidx
],
7339 phba
->sli4_hba
.hba_eq
[fcp_cqidx
], LPFC_WCQ
, LPFC_FCP
);
7341 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7342 "0527 Failed setup of fast-path FCP "
7343 "CQ (%d), rc = 0x%x\n", fcp_cqidx
, rc
);
7344 goto out_destroy_fcp_cq
;
7347 /* Setup fcp_cq_map for fast lookup */
7348 phba
->sli4_hba
.fcp_cq_map
[fcp_cqidx
] =
7349 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]->queue_id
;
7351 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7352 "2588 FCP CQ setup: cq[%d]-id=%d, "
7353 "parent seq[%d]-id=%d\n",
7355 phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]->queue_id
,
7357 phba
->sli4_hba
.hba_eq
[fcp_cqidx
]->queue_id
);
7360 /* Set up fast-path FCP Work Queue */
7361 if (!phba
->sli4_hba
.fcp_wq
) {
7362 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7363 "3149 Fast-path FCP WQ array not "
7366 goto out_destroy_fcp_cq
;
7369 for (fcp_wqidx
= 0; fcp_wqidx
< phba
->cfg_fcp_io_channel
; fcp_wqidx
++) {
7370 if (!phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]) {
7371 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7372 "0534 Fast-path FCP WQ (%d) not "
7373 "allocated\n", fcp_wqidx
);
7375 goto out_destroy_fcp_wq
;
7377 rc
= lpfc_wq_create(phba
, phba
->sli4_hba
.fcp_wq
[fcp_wqidx
],
7378 phba
->sli4_hba
.fcp_cq
[fcp_wqidx
],
7381 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7382 "0535 Failed setup of fast-path FCP "
7383 "WQ (%d), rc = 0x%x\n", fcp_wqidx
, rc
);
7384 goto out_destroy_fcp_wq
;
7387 /* Bind this WQ to the next FCP ring */
7388 pring
= &psli
->ring
[MAX_SLI3_CONFIGURED_RINGS
+ fcp_wqidx
];
7389 pring
->sli
.sli4
.wqp
= (void *)phba
->sli4_hba
.fcp_wq
[fcp_wqidx
];
7390 phba
->sli4_hba
.fcp_cq
[fcp_wqidx
]->pring
= pring
;
7392 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7393 "2591 FCP WQ setup: wq[%d]-id=%d, "
7394 "parent cq[%d]-id=%d\n",
7396 phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]->queue_id
,
7398 phba
->sli4_hba
.fcp_cq
[fcp_wqidx
]->queue_id
);
7401 * Set up Complete Queues (CQs)
7404 /* Set up slow-path MBOX Complete Queue as the first CQ */
7405 if (!phba
->sli4_hba
.mbx_cq
) {
7406 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7407 "0528 Mailbox CQ not allocated\n");
7409 goto out_destroy_fcp_wq
;
7411 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.mbx_cq
,
7412 phba
->sli4_hba
.hba_eq
[0], LPFC_MCQ
, LPFC_MBOX
);
7414 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7415 "0529 Failed setup of slow-path mailbox CQ: "
7417 goto out_destroy_fcp_wq
;
7419 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7420 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
7421 phba
->sli4_hba
.mbx_cq
->queue_id
,
7422 phba
->sli4_hba
.hba_eq
[0]->queue_id
);
7424 /* Set up slow-path ELS Complete Queue */
7425 if (!phba
->sli4_hba
.els_cq
) {
7426 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7427 "0530 ELS CQ not allocated\n");
7429 goto out_destroy_mbx_cq
;
7431 rc
= lpfc_cq_create(phba
, phba
->sli4_hba
.els_cq
,
7432 phba
->sli4_hba
.hba_eq
[0], LPFC_WCQ
, LPFC_ELS
);
7434 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7435 "0531 Failed setup of slow-path ELS CQ: "
7437 goto out_destroy_mbx_cq
;
7439 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7440 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
7441 phba
->sli4_hba
.els_cq
->queue_id
,
7442 phba
->sli4_hba
.hba_eq
[0]->queue_id
);
7445 * Set up all the Work Queues (WQs)
7448 /* Set up Mailbox Command Queue */
7449 if (!phba
->sli4_hba
.mbx_wq
) {
7450 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7451 "0538 Slow-path MQ not allocated\n");
7453 goto out_destroy_els_cq
;
7455 rc
= lpfc_mq_create(phba
, phba
->sli4_hba
.mbx_wq
,
7456 phba
->sli4_hba
.mbx_cq
, LPFC_MBOX
);
7458 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7459 "0539 Failed setup of slow-path MQ: "
7461 goto out_destroy_els_cq
;
7463 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7464 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
7465 phba
->sli4_hba
.mbx_wq
->queue_id
,
7466 phba
->sli4_hba
.mbx_cq
->queue_id
);
7468 /* Set up slow-path ELS Work Queue */
7469 if (!phba
->sli4_hba
.els_wq
) {
7470 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7471 "0536 Slow-path ELS WQ not allocated\n");
7473 goto out_destroy_mbx_wq
;
7475 rc
= lpfc_wq_create(phba
, phba
->sli4_hba
.els_wq
,
7476 phba
->sli4_hba
.els_cq
, LPFC_ELS
);
7478 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7479 "0537 Failed setup of slow-path ELS WQ: "
7481 goto out_destroy_mbx_wq
;
7484 /* Bind this WQ to the ELS ring */
7485 pring
= &psli
->ring
[LPFC_ELS_RING
];
7486 pring
->sli
.sli4
.wqp
= (void *)phba
->sli4_hba
.els_wq
;
7487 phba
->sli4_hba
.els_cq
->pring
= pring
;
7489 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7490 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
7491 phba
->sli4_hba
.els_wq
->queue_id
,
7492 phba
->sli4_hba
.els_cq
->queue_id
);
7495 * Create Receive Queue (RQ)
7497 if (!phba
->sli4_hba
.hdr_rq
|| !phba
->sli4_hba
.dat_rq
) {
7498 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7499 "0540 Receive Queue not allocated\n");
7501 goto out_destroy_els_wq
;
7504 lpfc_rq_adjust_repost(phba
, phba
->sli4_hba
.hdr_rq
, LPFC_ELS_HBQ
);
7505 lpfc_rq_adjust_repost(phba
, phba
->sli4_hba
.dat_rq
, LPFC_ELS_HBQ
);
7507 rc
= lpfc_rq_create(phba
, phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
,
7508 phba
->sli4_hba
.els_cq
, LPFC_USOL
);
7510 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7511 "0541 Failed setup of Receive Queue: "
7513 goto out_destroy_fcp_wq
;
7516 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
7517 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
7518 "parent cq-id=%d\n",
7519 phba
->sli4_hba
.hdr_rq
->queue_id
,
7520 phba
->sli4_hba
.dat_rq
->queue_id
,
7521 phba
->sli4_hba
.els_cq
->queue_id
);
7525 lpfc_wq_destroy(phba
, phba
->sli4_hba
.els_wq
);
7527 lpfc_mq_destroy(phba
, phba
->sli4_hba
.mbx_wq
);
7529 lpfc_cq_destroy(phba
, phba
->sli4_hba
.els_cq
);
7531 lpfc_cq_destroy(phba
, phba
->sli4_hba
.mbx_cq
);
7533 for (--fcp_wqidx
; fcp_wqidx
>= 0; fcp_wqidx
--)
7534 lpfc_wq_destroy(phba
, phba
->sli4_hba
.fcp_wq
[fcp_wqidx
]);
7536 for (--fcp_cqidx
; fcp_cqidx
>= 0; fcp_cqidx
--)
7537 lpfc_cq_destroy(phba
, phba
->sli4_hba
.fcp_cq
[fcp_cqidx
]);
7539 for (--fcp_eqidx
; fcp_eqidx
>= 0; fcp_eqidx
--)
7540 lpfc_eq_destroy(phba
, phba
->sli4_hba
.hba_eq
[fcp_eqidx
]);
7546 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
7547 * @phba: pointer to lpfc hba data structure.
7549 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
7554 * -ENOMEM - No available memory
7555 * -EIO - The mailbox failed to complete successfully.
7558 lpfc_sli4_queue_unset(struct lpfc_hba
*phba
)
7562 /* Unset mailbox command work queue */
7563 lpfc_mq_destroy(phba
, phba
->sli4_hba
.mbx_wq
);
7564 /* Unset ELS work queue */
7565 lpfc_wq_destroy(phba
, phba
->sli4_hba
.els_wq
);
7566 /* Unset unsolicited receive queue */
7567 lpfc_rq_destroy(phba
, phba
->sli4_hba
.hdr_rq
, phba
->sli4_hba
.dat_rq
);
7568 /* Unset FCP work queue */
7569 if (phba
->sli4_hba
.fcp_wq
) {
7570 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_io_channel
;
7572 lpfc_wq_destroy(phba
, phba
->sli4_hba
.fcp_wq
[fcp_qidx
]);
7574 /* Unset mailbox command complete queue */
7575 lpfc_cq_destroy(phba
, phba
->sli4_hba
.mbx_cq
);
7576 /* Unset ELS complete queue */
7577 lpfc_cq_destroy(phba
, phba
->sli4_hba
.els_cq
);
7578 /* Unset FCP response complete queue */
7579 if (phba
->sli4_hba
.fcp_cq
) {
7580 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_io_channel
;
7582 lpfc_cq_destroy(phba
, phba
->sli4_hba
.fcp_cq
[fcp_qidx
]);
7584 /* Unset fast-path event queue */
7585 if (phba
->sli4_hba
.hba_eq
) {
7586 for (fcp_qidx
= 0; fcp_qidx
< phba
->cfg_fcp_io_channel
;
7588 lpfc_eq_destroy(phba
, phba
->sli4_hba
.hba_eq
[fcp_qidx
]);
7593 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
7594 * @phba: pointer to lpfc hba data structure.
7596 * This routine is invoked to allocate and set up a pool of completion queue
7597 * events. The body of the completion queue event is a completion queue entry
7598 * CQE. For now, this pool is used for the interrupt service routine to queue
7599 * the following HBA completion queue events for the worker thread to process:
7600 * - Mailbox asynchronous events
7601 * - Receive queue completion unsolicited events
7602 * Later, this can be used for all the slow-path events.
7606 * -ENOMEM - No available memory
7609 lpfc_sli4_cq_event_pool_create(struct lpfc_hba
*phba
)
7611 struct lpfc_cq_event
*cq_event
;
7614 for (i
= 0; i
< (4 * phba
->sli4_hba
.cq_ecount
); i
++) {
7615 cq_event
= kmalloc(sizeof(struct lpfc_cq_event
), GFP_KERNEL
);
7617 goto out_pool_create_fail
;
7618 list_add_tail(&cq_event
->list
,
7619 &phba
->sli4_hba
.sp_cqe_event_pool
);
7623 out_pool_create_fail
:
7624 lpfc_sli4_cq_event_pool_destroy(phba
);
7629 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
7630 * @phba: pointer to lpfc hba data structure.
7632 * This routine is invoked to free the pool of completion queue events at
7633 * driver unload time. Note that, it is the responsibility of the driver
7634 * cleanup routine to free all the outstanding completion-queue events
7635 * allocated from this pool back into the pool before invoking this routine
7636 * to destroy the pool.
7639 lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba
*phba
)
7641 struct lpfc_cq_event
*cq_event
, *next_cq_event
;
7643 list_for_each_entry_safe(cq_event
, next_cq_event
,
7644 &phba
->sli4_hba
.sp_cqe_event_pool
, list
) {
7645 list_del(&cq_event
->list
);
7651 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7652 * @phba: pointer to lpfc hba data structure.
7654 * This routine is the lock free version of the API invoked to allocate a
7655 * completion-queue event from the free pool.
7657 * Return: Pointer to the newly allocated completion-queue event if successful
7660 struct lpfc_cq_event
*
7661 __lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
7663 struct lpfc_cq_event
*cq_event
= NULL
;
7665 list_remove_head(&phba
->sli4_hba
.sp_cqe_event_pool
, cq_event
,
7666 struct lpfc_cq_event
, list
);
7671 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
7672 * @phba: pointer to lpfc hba data structure.
7674 * This routine is the lock version of the API invoked to allocate a
7675 * completion-queue event from the free pool.
7677 * Return: Pointer to the newly allocated completion-queue event if successful
7680 struct lpfc_cq_event
*
7681 lpfc_sli4_cq_event_alloc(struct lpfc_hba
*phba
)
7683 struct lpfc_cq_event
*cq_event
;
7684 unsigned long iflags
;
7686 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7687 cq_event
= __lpfc_sli4_cq_event_alloc(phba
);
7688 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7693 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7694 * @phba: pointer to lpfc hba data structure.
7695 * @cq_event: pointer to the completion queue event to be freed.
7697 * This routine is the lock free version of the API invoked to release a
7698 * completion-queue event back into the free pool.
7701 __lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
7702 struct lpfc_cq_event
*cq_event
)
7704 list_add_tail(&cq_event
->list
, &phba
->sli4_hba
.sp_cqe_event_pool
);
7708 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
7709 * @phba: pointer to lpfc hba data structure.
7710 * @cq_event: pointer to the completion queue event to be freed.
7712 * This routine is the lock version of the API invoked to release a
7713 * completion-queue event back into the free pool.
7716 lpfc_sli4_cq_event_release(struct lpfc_hba
*phba
,
7717 struct lpfc_cq_event
*cq_event
)
7719 unsigned long iflags
;
7720 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7721 __lpfc_sli4_cq_event_release(phba
, cq_event
);
7722 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7726 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
7727 * @phba: pointer to lpfc hba data structure.
7729 * This routine is to free all the pending completion-queue events to the
7730 * back into the free pool for device reset.
7733 lpfc_sli4_cq_event_release_all(struct lpfc_hba
*phba
)
7736 struct lpfc_cq_event
*cqe
;
7737 unsigned long iflags
;
7739 /* Retrieve all the pending WCQEs from pending WCQE lists */
7740 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7741 /* Pending FCP XRI abort events */
7742 list_splice_init(&phba
->sli4_hba
.sp_fcp_xri_aborted_work_queue
,
7744 /* Pending ELS XRI abort events */
7745 list_splice_init(&phba
->sli4_hba
.sp_els_xri_aborted_work_queue
,
7747 /* Pending asynnc events */
7748 list_splice_init(&phba
->sli4_hba
.sp_asynce_work_queue
,
7750 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7752 while (!list_empty(&cqelist
)) {
7753 list_remove_head(&cqelist
, cqe
, struct lpfc_cq_event
, list
);
7754 lpfc_sli4_cq_event_release(phba
, cqe
);
7759 * lpfc_pci_function_reset - Reset pci function.
7760 * @phba: pointer to lpfc hba data structure.
7762 * This routine is invoked to request a PCI function reset. It will destroys
7763 * all resources assigned to the PCI function which originates this request.
7767 * -ENOMEM - No available memory
7768 * -EIO - The mailbox failed to complete successfully.
7771 lpfc_pci_function_reset(struct lpfc_hba
*phba
)
7773 LPFC_MBOXQ_t
*mboxq
;
7774 uint32_t rc
= 0, if_type
;
7775 uint32_t shdr_status
, shdr_add_status
;
7776 uint32_t rdy_chk
, num_resets
= 0, reset_again
= 0;
7777 union lpfc_sli4_cfg_shdr
*shdr
;
7778 struct lpfc_register reg_data
;
7781 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
7783 case LPFC_SLI_INTF_IF_TYPE_0
:
7784 mboxq
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
7787 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7788 "0494 Unable to allocate memory for "
7789 "issuing SLI_FUNCTION_RESET mailbox "
7794 /* Setup PCI function reset mailbox-ioctl command */
7795 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
7796 LPFC_MBOX_OPCODE_FUNCTION_RESET
, 0,
7797 LPFC_SLI4_MBX_EMBED
);
7798 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
7799 shdr
= (union lpfc_sli4_cfg_shdr
*)
7800 &mboxq
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
7801 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
7802 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
,
7804 if (rc
!= MBX_TIMEOUT
)
7805 mempool_free(mboxq
, phba
->mbox_mem_pool
);
7806 if (shdr_status
|| shdr_add_status
|| rc
) {
7807 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7808 "0495 SLI_FUNCTION_RESET mailbox "
7809 "failed with status x%x add_status x%x,"
7810 " mbx status x%x\n",
7811 shdr_status
, shdr_add_status
, rc
);
7815 case LPFC_SLI_INTF_IF_TYPE_2
:
7816 for (num_resets
= 0;
7817 num_resets
< MAX_IF_TYPE_2_RESETS
;
7820 bf_set(lpfc_sliport_ctrl_end
, ®_data
,
7821 LPFC_SLIPORT_LITTLE_ENDIAN
);
7822 bf_set(lpfc_sliport_ctrl_ip
, ®_data
,
7823 LPFC_SLIPORT_INIT_PORT
);
7824 writel(reg_data
.word0
, phba
->sli4_hba
.u
.if_type2
.
7827 pci_read_config_word(phba
->pcidev
,
7828 PCI_DEVICE_ID
, &devid
);
7830 * Poll the Port Status Register and wait for RDY for
7831 * up to 10 seconds. If the port doesn't respond, treat
7832 * it as an error. If the port responds with RN, start
7835 for (rdy_chk
= 0; rdy_chk
< 1000; rdy_chk
++) {
7837 if (lpfc_readl(phba
->sli4_hba
.u
.if_type2
.
7838 STATUSregaddr
, ®_data
.word0
)) {
7842 if (bf_get(lpfc_sliport_status_rn
, ®_data
))
7844 if (bf_get(lpfc_sliport_status_rdy
, ®_data
))
7849 * If the port responds to the init request with
7850 * reset needed, delay for a bit and restart the loop.
7852 if (reset_again
&& (rdy_chk
< 1000)) {
7858 /* Detect any port errors. */
7859 if ((bf_get(lpfc_sliport_status_err
, ®_data
)) ||
7860 (rdy_chk
>= 1000)) {
7861 phba
->work_status
[0] = readl(
7862 phba
->sli4_hba
.u
.if_type2
.ERR1regaddr
);
7863 phba
->work_status
[1] = readl(
7864 phba
->sli4_hba
.u
.if_type2
.ERR2regaddr
);
7865 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7866 "2890 Port error detected during port "
7867 "reset(%d): wait_tmo:%d ms, "
7868 "port status reg 0x%x, "
7869 "error 1=0x%x, error 2=0x%x\n",
7870 num_resets
, rdy_chk
*10,
7872 phba
->work_status
[0],
7873 phba
->work_status
[1]);
7878 * Terminate the outer loop provided the Port indicated
7879 * ready within 10 seconds.
7884 /* delay driver action following IF_TYPE_2 function reset */
7887 case LPFC_SLI_INTF_IF_TYPE_1
:
7893 /* Catch the not-ready port failure after a port reset. */
7894 if (num_resets
>= MAX_IF_TYPE_2_RESETS
) {
7895 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7896 "3317 HBA not functional: IP Reset Failed "
7897 "after (%d) retries, try: "
7898 "echo fw_reset > board_mode\n", num_resets
);
7906 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
7907 * @phba: pointer to lpfc hba data structure.
7909 * This routine is invoked to set up the PCI device memory space for device
7910 * with SLI-4 interface spec.
7914 * other values - error
7917 lpfc_sli4_pci_mem_setup(struct lpfc_hba
*phba
)
7919 struct pci_dev
*pdev
;
7920 unsigned long bar0map_len
, bar1map_len
, bar2map_len
;
7921 int error
= -ENODEV
;
7924 /* Obtain PCI device reference */
7928 pdev
= phba
->pcidev
;
7930 /* Set the device DMA mask size */
7931 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0
7932 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(64)) != 0) {
7933 if (pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0
7934 || pci_set_consistent_dma_mask(pdev
,DMA_BIT_MASK(32)) != 0) {
7940 * The BARs and register set definitions and offset locations are
7941 * dependent on the if_type.
7943 if (pci_read_config_dword(pdev
, LPFC_SLI_INTF
,
7944 &phba
->sli4_hba
.sli_intf
.word0
)) {
7948 /* There is no SLI3 failback for SLI4 devices. */
7949 if (bf_get(lpfc_sli_intf_valid
, &phba
->sli4_hba
.sli_intf
) !=
7950 LPFC_SLI_INTF_VALID
) {
7951 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
7952 "2894 SLI_INTF reg contents invalid "
7953 "sli_intf reg 0x%x\n",
7954 phba
->sli4_hba
.sli_intf
.word0
);
7958 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
7960 * Get the bus address of SLI4 device Bar regions and the
7961 * number of bytes required by each mapping. The mapping of the
7962 * particular PCI BARs regions is dependent on the type of
7965 if (pci_resource_start(pdev
, 0)) {
7966 phba
->pci_bar0_map
= pci_resource_start(pdev
, 0);
7967 bar0map_len
= pci_resource_len(pdev
, 0);
7970 * Map SLI4 PCI Config Space Register base to a kernel virtual
7973 phba
->sli4_hba
.conf_regs_memmap_p
=
7974 ioremap(phba
->pci_bar0_map
, bar0map_len
);
7975 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
7976 dev_printk(KERN_ERR
, &pdev
->dev
,
7977 "ioremap failed for SLI4 PCI config "
7981 /* Set up BAR0 PCI config space register memory map */
7982 lpfc_sli4_bar0_register_memmap(phba
, if_type
);
7984 phba
->pci_bar0_map
= pci_resource_start(pdev
, 1);
7985 bar0map_len
= pci_resource_len(pdev
, 1);
7986 if (if_type
== LPFC_SLI_INTF_IF_TYPE_2
) {
7987 dev_printk(KERN_ERR
, &pdev
->dev
,
7988 "FATAL - No BAR0 mapping for SLI4, if_type 2\n");
7991 phba
->sli4_hba
.conf_regs_memmap_p
=
7992 ioremap(phba
->pci_bar0_map
, bar0map_len
);
7993 if (!phba
->sli4_hba
.conf_regs_memmap_p
) {
7994 dev_printk(KERN_ERR
, &pdev
->dev
,
7995 "ioremap failed for SLI4 PCI config "
7999 lpfc_sli4_bar0_register_memmap(phba
, if_type
);
8002 if ((if_type
== LPFC_SLI_INTF_IF_TYPE_0
) &&
8003 (pci_resource_start(pdev
, 2))) {
8005 * Map SLI4 if type 0 HBA Control Register base to a kernel
8006 * virtual address and setup the registers.
8008 phba
->pci_bar1_map
= pci_resource_start(pdev
, 2);
8009 bar1map_len
= pci_resource_len(pdev
, 2);
8010 phba
->sli4_hba
.ctrl_regs_memmap_p
=
8011 ioremap(phba
->pci_bar1_map
, bar1map_len
);
8012 if (!phba
->sli4_hba
.ctrl_regs_memmap_p
) {
8013 dev_printk(KERN_ERR
, &pdev
->dev
,
8014 "ioremap failed for SLI4 HBA control registers.\n");
8015 goto out_iounmap_conf
;
8017 lpfc_sli4_bar1_register_memmap(phba
);
8020 if ((if_type
== LPFC_SLI_INTF_IF_TYPE_0
) &&
8021 (pci_resource_start(pdev
, 4))) {
8023 * Map SLI4 if type 0 HBA Doorbell Register base to a kernel
8024 * virtual address and setup the registers.
8026 phba
->pci_bar2_map
= pci_resource_start(pdev
, 4);
8027 bar2map_len
= pci_resource_len(pdev
, 4);
8028 phba
->sli4_hba
.drbl_regs_memmap_p
=
8029 ioremap(phba
->pci_bar2_map
, bar2map_len
);
8030 if (!phba
->sli4_hba
.drbl_regs_memmap_p
) {
8031 dev_printk(KERN_ERR
, &pdev
->dev
,
8032 "ioremap failed for SLI4 HBA doorbell registers.\n");
8033 goto out_iounmap_ctrl
;
8035 error
= lpfc_sli4_bar2_register_memmap(phba
, LPFC_VF0
);
8037 goto out_iounmap_all
;
8043 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
8045 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
8047 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
8053 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
8054 * @phba: pointer to lpfc hba data structure.
8056 * This routine is invoked to unset the PCI device memory space for device
8057 * with SLI-4 interface spec.
8060 lpfc_sli4_pci_mem_unset(struct lpfc_hba
*phba
)
8063 if_type
= bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
);
8066 case LPFC_SLI_INTF_IF_TYPE_0
:
8067 iounmap(phba
->sli4_hba
.drbl_regs_memmap_p
);
8068 iounmap(phba
->sli4_hba
.ctrl_regs_memmap_p
);
8069 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
8071 case LPFC_SLI_INTF_IF_TYPE_2
:
8072 iounmap(phba
->sli4_hba
.conf_regs_memmap_p
);
8074 case LPFC_SLI_INTF_IF_TYPE_1
:
8076 dev_printk(KERN_ERR
, &phba
->pcidev
->dev
,
8077 "FATAL - unsupported SLI4 interface type - %d\n",
8084 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
8085 * @phba: pointer to lpfc hba data structure.
8087 * This routine is invoked to enable the MSI-X interrupt vectors to device
8088 * with SLI-3 interface specs. The kernel function pci_enable_msix() is
8089 * called to enable the MSI-X vectors. Note that pci_enable_msix(), once
8090 * invoked, enables either all or nothing, depending on the current
8091 * availability of PCI vector resources. The device driver is responsible
8092 * for calling the individual request_irq() to register each MSI-X vector
8093 * with a interrupt handler, which is done in this function. Note that
8094 * later when device is unloading, the driver should always call free_irq()
8095 * on all MSI-X vectors it has done request_irq() on before calling
8096 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device
8097 * will be left with MSI-X enabled and leaks its vectors.
8101 * other values - error
8104 lpfc_sli_enable_msix(struct lpfc_hba
*phba
)
8109 /* Set up MSI-X multi-message vectors */
8110 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
8111 phba
->msix_entries
[i
].entry
= i
;
8113 /* Configure MSI-X capability structure */
8114 rc
= pci_enable_msix(phba
->pcidev
, phba
->msix_entries
,
8115 ARRAY_SIZE(phba
->msix_entries
));
8117 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8118 "0420 PCI enable MSI-X failed (%d)\n", rc
);
8121 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
8122 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8123 "0477 MSI-X entry[%d]: vector=x%x "
8125 phba
->msix_entries
[i
].vector
,
8126 phba
->msix_entries
[i
].entry
);
8128 * Assign MSI-X vectors to interrupt handlers
8131 /* vector-0 is associated to slow-path handler */
8132 rc
= request_irq(phba
->msix_entries
[0].vector
,
8133 &lpfc_sli_sp_intr_handler
, IRQF_SHARED
,
8134 LPFC_SP_DRIVER_HANDLER_NAME
, phba
);
8136 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
8137 "0421 MSI-X slow-path request_irq failed "
8142 /* vector-1 is associated to fast-path handler */
8143 rc
= request_irq(phba
->msix_entries
[1].vector
,
8144 &lpfc_sli_fp_intr_handler
, IRQF_SHARED
,
8145 LPFC_FP_DRIVER_HANDLER_NAME
, phba
);
8148 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
8149 "0429 MSI-X fast-path request_irq failed "
8155 * Configure HBA MSI-X attention conditions to messages
8157 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
8161 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8162 "0474 Unable to allocate memory for issuing "
8163 "MBOX_CONFIG_MSI command\n");
8166 rc
= lpfc_config_msi(phba
, pmb
);
8169 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_POLL
);
8170 if (rc
!= MBX_SUCCESS
) {
8171 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
8172 "0351 Config MSI mailbox command failed, "
8173 "mbxCmd x%x, mbxStatus x%x\n",
8174 pmb
->u
.mb
.mbxCommand
, pmb
->u
.mb
.mbxStatus
);
8178 /* Free memory allocated for mailbox command */
8179 mempool_free(pmb
, phba
->mbox_mem_pool
);
8183 /* Free memory allocated for mailbox command */
8184 mempool_free(pmb
, phba
->mbox_mem_pool
);
8187 /* free the irq already requested */
8188 free_irq(phba
->msix_entries
[1].vector
, phba
);
8191 /* free the irq already requested */
8192 free_irq(phba
->msix_entries
[0].vector
, phba
);
8195 /* Unconfigure MSI-X capability structure */
8196 pci_disable_msix(phba
->pcidev
);
8201 * lpfc_sli_disable_msix - Disable MSI-X interrupt mode on SLI-3 device.
8202 * @phba: pointer to lpfc hba data structure.
8204 * This routine is invoked to release the MSI-X vectors and then disable the
8205 * MSI-X interrupt mode to device with SLI-3 interface spec.
8208 lpfc_sli_disable_msix(struct lpfc_hba
*phba
)
8212 /* Free up MSI-X multi-message vectors */
8213 for (i
= 0; i
< LPFC_MSIX_VECTORS
; i
++)
8214 free_irq(phba
->msix_entries
[i
].vector
, phba
);
8216 pci_disable_msix(phba
->pcidev
);
8222 * lpfc_sli_enable_msi - Enable MSI interrupt mode on SLI-3 device.
8223 * @phba: pointer to lpfc hba data structure.
8225 * This routine is invoked to enable the MSI interrupt mode to device with
8226 * SLI-3 interface spec. The kernel function pci_enable_msi() is called to
8227 * enable the MSI vector. The device driver is responsible for calling the
8228 * request_irq() to register MSI vector with a interrupt the handler, which
8229 * is done in this function.
8233 * other values - error
8236 lpfc_sli_enable_msi(struct lpfc_hba
*phba
)
8240 rc
= pci_enable_msi(phba
->pcidev
);
8242 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8243 "0462 PCI enable MSI mode success.\n");
8245 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8246 "0471 PCI enable MSI mode failed (%d)\n", rc
);
8250 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
8251 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
8253 pci_disable_msi(phba
->pcidev
);
8254 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
8255 "0478 MSI request_irq failed (%d)\n", rc
);
8261 * lpfc_sli_disable_msi - Disable MSI interrupt mode to SLI-3 device.
8262 * @phba: pointer to lpfc hba data structure.
8264 * This routine is invoked to disable the MSI interrupt mode to device with
8265 * SLI-3 interface spec. The driver calls free_irq() on MSI vector it has
8266 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8267 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8271 lpfc_sli_disable_msi(struct lpfc_hba
*phba
)
8273 free_irq(phba
->pcidev
->irq
, phba
);
8274 pci_disable_msi(phba
->pcidev
);
8279 * lpfc_sli_enable_intr - Enable device interrupt to SLI-3 device.
8280 * @phba: pointer to lpfc hba data structure.
8282 * This routine is invoked to enable device interrupt and associate driver's
8283 * interrupt handler(s) to interrupt vector(s) to device with SLI-3 interface
8284 * spec. Depends on the interrupt mode configured to the driver, the driver
8285 * will try to fallback from the configured interrupt mode to an interrupt
8286 * mode which is supported by the platform, kernel, and device in the order
8288 * MSI-X -> MSI -> IRQ.
8292 * other values - error
8295 lpfc_sli_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
8297 uint32_t intr_mode
= LPFC_INTR_ERROR
;
8300 if (cfg_mode
== 2) {
8301 /* Need to issue conf_port mbox cmd before conf_msi mbox cmd */
8302 retval
= lpfc_sli_config_port(phba
, LPFC_SLI_REV3
);
8304 /* Now, try to enable MSI-X interrupt mode */
8305 retval
= lpfc_sli_enable_msix(phba
);
8307 /* Indicate initialization to MSI-X mode */
8308 phba
->intr_type
= MSIX
;
8314 /* Fallback to MSI if MSI-X initialization failed */
8315 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
8316 retval
= lpfc_sli_enable_msi(phba
);
8318 /* Indicate initialization to MSI mode */
8319 phba
->intr_type
= MSI
;
8324 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8325 if (phba
->intr_type
== NONE
) {
8326 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli_intr_handler
,
8327 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
8329 /* Indicate initialization to INTx mode */
8330 phba
->intr_type
= INTx
;
8338 * lpfc_sli_disable_intr - Disable device interrupt to SLI-3 device.
8339 * @phba: pointer to lpfc hba data structure.
8341 * This routine is invoked to disable device interrupt and disassociate the
8342 * driver's interrupt handler(s) from interrupt vector(s) to device with
8343 * SLI-3 interface spec. Depending on the interrupt mode, the driver will
8344 * release the interrupt vector(s) for the message signaled interrupt.
8347 lpfc_sli_disable_intr(struct lpfc_hba
*phba
)
8349 /* Disable the currently initialized interrupt mode */
8350 if (phba
->intr_type
== MSIX
)
8351 lpfc_sli_disable_msix(phba
);
8352 else if (phba
->intr_type
== MSI
)
8353 lpfc_sli_disable_msi(phba
);
8354 else if (phba
->intr_type
== INTx
)
8355 free_irq(phba
->pcidev
->irq
, phba
);
8357 /* Reset interrupt management states */
8358 phba
->intr_type
= NONE
;
8359 phba
->sli
.slistat
.sli_intr
= 0;
8365 * lpfc_find_next_cpu - Find next available CPU that matches the phys_id
8366 * @phba: pointer to lpfc hba data structure.
8368 * Find next available CPU to use for IRQ to CPU affinity.
8371 lpfc_find_next_cpu(struct lpfc_hba
*phba
, uint32_t phys_id
)
8373 struct lpfc_vector_map_info
*cpup
;
8376 cpup
= phba
->sli4_hba
.cpu_map
;
8377 for (cpu
= 0; cpu
< phba
->sli4_hba
.num_present_cpu
; cpu
++) {
8378 /* CPU must be online */
8379 if (cpu_online(cpu
)) {
8380 if ((cpup
->irq
== LPFC_VECTOR_MAP_EMPTY
) &&
8381 (lpfc_used_cpu
[cpu
] == LPFC_VECTOR_MAP_EMPTY
) &&
8382 (cpup
->phys_id
== phys_id
)) {
8390 * If we get here, we have used ALL CPUs for the specific
8391 * phys_id. Now we need to clear out lpfc_used_cpu and start
8395 for (cpu
= 0; cpu
< phba
->sli4_hba
.num_present_cpu
; cpu
++) {
8396 if (lpfc_used_cpu
[cpu
] == phys_id
)
8397 lpfc_used_cpu
[cpu
] = LPFC_VECTOR_MAP_EMPTY
;
8400 cpup
= phba
->sli4_hba
.cpu_map
;
8401 for (cpu
= 0; cpu
< phba
->sli4_hba
.num_present_cpu
; cpu
++) {
8402 /* CPU must be online */
8403 if (cpu_online(cpu
)) {
8404 if ((cpup
->irq
== LPFC_VECTOR_MAP_EMPTY
) &&
8405 (cpup
->phys_id
== phys_id
)) {
8411 return LPFC_VECTOR_MAP_EMPTY
;
8415 * lpfc_sli4_set_affinity - Set affinity for HBA IRQ vectors
8416 * @phba: pointer to lpfc hba data structure.
8417 * @vectors: number of HBA vectors
8419 * Affinitize MSIX IRQ vectors to CPUs. Try to equally spread vector
8420 * affinization across multple physical CPUs (numa nodes).
8421 * In addition, this routine will assign an IO channel for each CPU
8422 * to use when issuing I/Os.
8425 lpfc_sli4_set_affinity(struct lpfc_hba
*phba
, int vectors
)
8427 int i
, idx
, saved_chann
, used_chann
, cpu
, phys_id
;
8428 int max_phys_id
, num_io_channel
, first_cpu
;
8429 struct lpfc_vector_map_info
*cpup
;
8431 struct cpuinfo_x86
*cpuinfo
;
8433 struct cpumask
*mask
;
8434 uint8_t chann
[LPFC_FCP_IO_CHAN_MAX
+1];
8436 /* If there is no mapping, just return */
8437 if (!phba
->cfg_fcp_cpu_map
)
8440 /* Init cpu_map array */
8441 memset(phba
->sli4_hba
.cpu_map
, 0xff,
8442 (sizeof(struct lpfc_vector_map_info
) *
8443 phba
->sli4_hba
.num_present_cpu
));
8448 first_cpu
= LPFC_VECTOR_MAP_EMPTY
;
8450 /* Update CPU map with physical id and core id of each CPU */
8451 cpup
= phba
->sli4_hba
.cpu_map
;
8452 for (cpu
= 0; cpu
< phba
->sli4_hba
.num_present_cpu
; cpu
++) {
8454 cpuinfo
= &cpu_data(cpu
);
8455 cpup
->phys_id
= cpuinfo
->phys_proc_id
;
8456 cpup
->core_id
= cpuinfo
->cpu_core_id
;
8458 /* No distinction between CPUs for other platforms */
8463 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8464 "3328 CPU physid %d coreid %d\n",
8465 cpup
->phys_id
, cpup
->core_id
);
8467 if (cpup
->phys_id
> max_phys_id
)
8468 max_phys_id
= cpup
->phys_id
;
8472 /* Now associate the HBA vectors with specific CPUs */
8473 for (idx
= 0; idx
< vectors
; idx
++) {
8474 cpup
= phba
->sli4_hba
.cpu_map
;
8475 cpu
= lpfc_find_next_cpu(phba
, phys_id
);
8476 if (cpu
== LPFC_VECTOR_MAP_EMPTY
) {
8478 /* Try for all phys_id's */
8479 for (i
= 1; i
< max_phys_id
; i
++) {
8481 if (phys_id
> max_phys_id
)
8483 cpu
= lpfc_find_next_cpu(phba
, phys_id
);
8484 if (cpu
== LPFC_VECTOR_MAP_EMPTY
)
8489 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8490 "3329 Cannot set affinity:"
8491 "Error mapping vector %d (%d)\n",
8497 if (phba
->cfg_fcp_cpu_map
== LPFC_DRIVER_CPU_MAP
)
8498 lpfc_used_cpu
[cpu
] = phys_id
;
8500 /* Associate vector with selected CPU */
8501 cpup
->irq
= phba
->sli4_hba
.msix_entries
[idx
].vector
;
8503 /* Associate IO channel with selected CPU */
8504 cpup
->channel_id
= idx
;
8507 if (first_cpu
== LPFC_VECTOR_MAP_EMPTY
)
8510 /* Now affinitize to the selected CPU */
8511 mask
= &cpup
->maskbits
;
8512 cpumask_clear(mask
);
8513 cpumask_set_cpu(cpu
, mask
);
8514 i
= irq_set_affinity_hint(phba
->sli4_hba
.msix_entries
[idx
].
8517 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8518 "3330 Set Affinity: CPU %d channel %d "
8520 cpu
, cpup
->channel_id
,
8521 phba
->sli4_hba
.msix_entries
[idx
].vector
, i
);
8523 /* Spread vector mapping across multple physical CPU nodes */
8525 if (phys_id
> max_phys_id
)
8530 * Finally fill in the IO channel for any remaining CPUs.
8531 * At this point, all IO channels have been assigned to a specific
8532 * MSIx vector, mapped to a specific CPU.
8533 * Base the remaining IO channel assigned, to IO channels already
8534 * assigned to other CPUs on the same phys_id.
8536 for (i
= 0; i
<= max_phys_id
; i
++) {
8538 * If there are no io channels already mapped to
8539 * this phys_id, just round robin thru the io_channels.
8540 * Setup chann[] for round robin.
8542 for (idx
= 0; idx
< phba
->cfg_fcp_io_channel
; idx
++)
8549 * First build a list of IO channels already assigned
8550 * to this phys_id before reassigning the same IO
8551 * channels to the remaining CPUs.
8553 cpup
= phba
->sli4_hba
.cpu_map
;
8556 for (idx
= 0; idx
< phba
->sli4_hba
.num_present_cpu
;
8558 if (cpup
->phys_id
== i
) {
8560 * Save any IO channels that are
8561 * already mapped to this phys_id.
8563 if (cpup
->irq
!= LPFC_VECTOR_MAP_EMPTY
) {
8564 chann
[saved_chann
] =
8570 /* See if we are using round-robin */
8571 if (saved_chann
== 0)
8573 phba
->cfg_fcp_io_channel
;
8575 /* Associate next IO channel with CPU */
8576 cpup
->channel_id
= chann
[used_chann
];
8579 if (used_chann
== saved_chann
)
8582 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8583 "3331 Set IO_CHANN "
8584 "CPU %d channel %d\n",
8585 idx
, cpup
->channel_id
);
8589 if (cpu
>= phba
->sli4_hba
.num_present_cpu
) {
8590 cpup
= phba
->sli4_hba
.cpu_map
;
8598 if (phba
->sli4_hba
.num_online_cpu
!= phba
->sli4_hba
.num_present_cpu
) {
8599 cpup
= phba
->sli4_hba
.cpu_map
;
8600 for (idx
= 0; idx
< phba
->sli4_hba
.num_present_cpu
; idx
++) {
8601 if (cpup
->channel_id
== LPFC_VECTOR_MAP_EMPTY
) {
8602 cpup
->channel_id
= 0;
8605 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8606 "3332 Assign IO_CHANN "
8607 "CPU %d channel %d\n",
8608 idx
, cpup
->channel_id
);
8615 if (num_io_channel
!= phba
->sli4_hba
.num_present_cpu
)
8616 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8617 "3333 Set affinity mismatch:"
8618 "%d chann != %d cpus: %d vactors\n",
8619 num_io_channel
, phba
->sli4_hba
.num_present_cpu
,
8622 phba
->cfg_fcp_io_sched
= LPFC_FCP_SCHED_BY_CPU
;
8628 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
8629 * @phba: pointer to lpfc hba data structure.
8631 * This routine is invoked to enable the MSI-X interrupt vectors to device
8632 * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
8633 * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
8634 * enables either all or nothing, depending on the current availability of
8635 * PCI vector resources. The device driver is responsible for calling the
8636 * individual request_irq() to register each MSI-X vector with a interrupt
8637 * handler, which is done in this function. Note that later when device is
8638 * unloading, the driver should always call free_irq() on all MSI-X vectors
8639 * it has done request_irq() on before calling pci_disable_msix(). Failure
8640 * to do so results in a BUG_ON() and a device will be left with MSI-X
8641 * enabled and leaks its vectors.
8645 * other values - error
8648 lpfc_sli4_enable_msix(struct lpfc_hba
*phba
)
8650 int vectors
, rc
, index
;
8652 /* Set up MSI-X multi-message vectors */
8653 for (index
= 0; index
< phba
->cfg_fcp_io_channel
; index
++)
8654 phba
->sli4_hba
.msix_entries
[index
].entry
= index
;
8656 /* Configure MSI-X capability structure */
8657 vectors
= phba
->cfg_fcp_io_channel
;
8658 enable_msix_vectors
:
8659 rc
= pci_enable_msix(phba
->pcidev
, phba
->sli4_hba
.msix_entries
,
8663 goto enable_msix_vectors
;
8665 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8666 "0484 PCI enable MSI-X failed (%d)\n", rc
);
8670 /* Log MSI-X vector assignment */
8671 for (index
= 0; index
< vectors
; index
++)
8672 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8673 "0489 MSI-X entry[%d]: vector=x%x "
8674 "message=%d\n", index
,
8675 phba
->sli4_hba
.msix_entries
[index
].vector
,
8676 phba
->sli4_hba
.msix_entries
[index
].entry
);
8678 /* Assign MSI-X vectors to interrupt handlers */
8679 for (index
= 0; index
< vectors
; index
++) {
8680 memset(&phba
->sli4_hba
.handler_name
[index
], 0, 16);
8681 sprintf((char *)&phba
->sli4_hba
.handler_name
[index
],
8682 LPFC_DRIVER_HANDLER_NAME
"%d", index
);
8684 phba
->sli4_hba
.fcp_eq_hdl
[index
].idx
= index
;
8685 phba
->sli4_hba
.fcp_eq_hdl
[index
].phba
= phba
;
8686 atomic_set(&phba
->sli4_hba
.fcp_eq_hdl
[index
].fcp_eq_in_use
, 1);
8687 rc
= request_irq(phba
->sli4_hba
.msix_entries
[index
].vector
,
8688 &lpfc_sli4_hba_intr_handler
, IRQF_SHARED
,
8689 (char *)&phba
->sli4_hba
.handler_name
[index
],
8690 &phba
->sli4_hba
.fcp_eq_hdl
[index
]);
8692 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
8693 "0486 MSI-X fast-path (%d) "
8694 "request_irq failed (%d)\n", index
, rc
);
8699 if (vectors
!= phba
->cfg_fcp_io_channel
) {
8700 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8701 "3238 Reducing IO channels to match number of "
8702 "MSI-X vectors, requested %d got %d\n",
8703 phba
->cfg_fcp_io_channel
, vectors
);
8704 phba
->cfg_fcp_io_channel
= vectors
;
8707 lpfc_sli4_set_affinity(phba
, vectors
);
8711 /* free the irq already requested */
8712 for (--index
; index
>= 0; index
--)
8713 free_irq(phba
->sli4_hba
.msix_entries
[index
].vector
,
8714 &phba
->sli4_hba
.fcp_eq_hdl
[index
]);
8717 /* Unconfigure MSI-X capability structure */
8718 pci_disable_msix(phba
->pcidev
);
8723 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
8724 * @phba: pointer to lpfc hba data structure.
8726 * This routine is invoked to release the MSI-X vectors and then disable the
8727 * MSI-X interrupt mode to device with SLI-4 interface spec.
8730 lpfc_sli4_disable_msix(struct lpfc_hba
*phba
)
8734 /* Free up MSI-X multi-message vectors */
8735 for (index
= 0; index
< phba
->cfg_fcp_io_channel
; index
++)
8736 free_irq(phba
->sli4_hba
.msix_entries
[index
].vector
,
8737 &phba
->sli4_hba
.fcp_eq_hdl
[index
]);
8740 pci_disable_msix(phba
->pcidev
);
8746 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
8747 * @phba: pointer to lpfc hba data structure.
8749 * This routine is invoked to enable the MSI interrupt mode to device with
8750 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
8751 * to enable the MSI vector. The device driver is responsible for calling
8752 * the request_irq() to register MSI vector with a interrupt the handler,
8753 * which is done in this function.
8757 * other values - error
8760 lpfc_sli4_enable_msi(struct lpfc_hba
*phba
)
8764 rc
= pci_enable_msi(phba
->pcidev
);
8766 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8767 "0487 PCI enable MSI mode success.\n");
8769 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
8770 "0488 PCI enable MSI mode failed (%d)\n", rc
);
8774 rc
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
8775 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
8777 pci_disable_msi(phba
->pcidev
);
8778 lpfc_printf_log(phba
, KERN_WARNING
, LOG_INIT
,
8779 "0490 MSI request_irq failed (%d)\n", rc
);
8783 for (index
= 0; index
< phba
->cfg_fcp_io_channel
; index
++) {
8784 phba
->sli4_hba
.fcp_eq_hdl
[index
].idx
= index
;
8785 phba
->sli4_hba
.fcp_eq_hdl
[index
].phba
= phba
;
8792 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
8793 * @phba: pointer to lpfc hba data structure.
8795 * This routine is invoked to disable the MSI interrupt mode to device with
8796 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
8797 * done request_irq() on before calling pci_disable_msi(). Failure to do so
8798 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
8802 lpfc_sli4_disable_msi(struct lpfc_hba
*phba
)
8804 free_irq(phba
->pcidev
->irq
, phba
);
8805 pci_disable_msi(phba
->pcidev
);
8810 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
8811 * @phba: pointer to lpfc hba data structure.
8813 * This routine is invoked to enable device interrupt and associate driver's
8814 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
8815 * interface spec. Depends on the interrupt mode configured to the driver,
8816 * the driver will try to fallback from the configured interrupt mode to an
8817 * interrupt mode which is supported by the platform, kernel, and device in
8819 * MSI-X -> MSI -> IRQ.
8823 * other values - error
8826 lpfc_sli4_enable_intr(struct lpfc_hba
*phba
, uint32_t cfg_mode
)
8828 uint32_t intr_mode
= LPFC_INTR_ERROR
;
8831 if (cfg_mode
== 2) {
8832 /* Preparation before conf_msi mbox cmd */
8835 /* Now, try to enable MSI-X interrupt mode */
8836 retval
= lpfc_sli4_enable_msix(phba
);
8838 /* Indicate initialization to MSI-X mode */
8839 phba
->intr_type
= MSIX
;
8845 /* Fallback to MSI if MSI-X initialization failed */
8846 if (cfg_mode
>= 1 && phba
->intr_type
== NONE
) {
8847 retval
= lpfc_sli4_enable_msi(phba
);
8849 /* Indicate initialization to MSI mode */
8850 phba
->intr_type
= MSI
;
8855 /* Fallback to INTx if both MSI-X/MSI initalization failed */
8856 if (phba
->intr_type
== NONE
) {
8857 retval
= request_irq(phba
->pcidev
->irq
, lpfc_sli4_intr_handler
,
8858 IRQF_SHARED
, LPFC_DRIVER_NAME
, phba
);
8860 /* Indicate initialization to INTx mode */
8861 phba
->intr_type
= INTx
;
8863 for (index
= 0; index
< phba
->cfg_fcp_io_channel
;
8865 phba
->sli4_hba
.fcp_eq_hdl
[index
].idx
= index
;
8866 phba
->sli4_hba
.fcp_eq_hdl
[index
].phba
= phba
;
8867 atomic_set(&phba
->sli4_hba
.fcp_eq_hdl
[index
].
8876 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
8877 * @phba: pointer to lpfc hba data structure.
8879 * This routine is invoked to disable device interrupt and disassociate
8880 * the driver's interrupt handler(s) from interrupt vector(s) to device
8881 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
8882 * will release the interrupt vector(s) for the message signaled interrupt.
8885 lpfc_sli4_disable_intr(struct lpfc_hba
*phba
)
8887 /* Disable the currently initialized interrupt mode */
8888 if (phba
->intr_type
== MSIX
)
8889 lpfc_sli4_disable_msix(phba
);
8890 else if (phba
->intr_type
== MSI
)
8891 lpfc_sli4_disable_msi(phba
);
8892 else if (phba
->intr_type
== INTx
)
8893 free_irq(phba
->pcidev
->irq
, phba
);
8895 /* Reset interrupt management states */
8896 phba
->intr_type
= NONE
;
8897 phba
->sli
.slistat
.sli_intr
= 0;
8903 * lpfc_unset_hba - Unset SLI3 hba device initialization
8904 * @phba: pointer to lpfc hba data structure.
8906 * This routine is invoked to unset the HBA device initialization steps to
8907 * a device with SLI-3 interface spec.
8910 lpfc_unset_hba(struct lpfc_hba
*phba
)
8912 struct lpfc_vport
*vport
= phba
->pport
;
8913 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8915 spin_lock_irq(shost
->host_lock
);
8916 vport
->load_flag
|= FC_UNLOADING
;
8917 spin_unlock_irq(shost
->host_lock
);
8919 kfree(phba
->vpi_bmask
);
8920 kfree(phba
->vpi_ids
);
8922 lpfc_stop_hba_timers(phba
);
8924 phba
->pport
->work_port_events
= 0;
8926 lpfc_sli_hba_down(phba
);
8928 lpfc_sli_brdrestart(phba
);
8930 lpfc_sli_disable_intr(phba
);
8936 * lpfc_sli4_xri_exchange_busy_wait - Wait for device XRI exchange busy
8937 * @phba: Pointer to HBA context object.
8939 * This function is called in the SLI4 code path to wait for completion
8940 * of device's XRIs exchange busy. It will check the XRI exchange busy
8941 * on outstanding FCP and ELS I/Os every 10ms for up to 10 seconds; after
8942 * that, it will check the XRI exchange busy on outstanding FCP and ELS
8943 * I/Os every 30 seconds, log error message, and wait forever. Only when
8944 * all XRI exchange busy complete, the driver unload shall proceed with
8945 * invoking the function reset ioctl mailbox command to the CNA and the
8946 * the rest of the driver unload resource release.
8949 lpfc_sli4_xri_exchange_busy_wait(struct lpfc_hba
*phba
)
8952 int fcp_xri_cmpl
= list_empty(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
8953 int els_xri_cmpl
= list_empty(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
8955 while (!fcp_xri_cmpl
|| !els_xri_cmpl
) {
8956 if (wait_time
> LPFC_XRI_EXCH_BUSY_WAIT_TMO
) {
8958 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8959 "2877 FCP XRI exchange busy "
8960 "wait time: %d seconds.\n",
8963 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
8964 "2878 ELS XRI exchange busy "
8965 "wait time: %d seconds.\n",
8967 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T2
);
8968 wait_time
+= LPFC_XRI_EXCH_BUSY_WAIT_T2
;
8970 msleep(LPFC_XRI_EXCH_BUSY_WAIT_T1
);
8971 wait_time
+= LPFC_XRI_EXCH_BUSY_WAIT_T1
;
8974 list_empty(&phba
->sli4_hba
.lpfc_abts_scsi_buf_list
);
8976 list_empty(&phba
->sli4_hba
.lpfc_abts_els_sgl_list
);
8981 * lpfc_sli4_hba_unset - Unset the fcoe hba
8982 * @phba: Pointer to HBA context object.
8984 * This function is called in the SLI4 code path to reset the HBA's FCoE
8985 * function. The caller is not required to hold any lock. This routine
8986 * issues PCI function reset mailbox command to reset the FCoE function.
8987 * At the end of the function, it calls lpfc_hba_down_post function to
8988 * free any pending commands.
8991 lpfc_sli4_hba_unset(struct lpfc_hba
*phba
)
8994 LPFC_MBOXQ_t
*mboxq
;
8995 struct pci_dev
*pdev
= phba
->pcidev
;
8997 lpfc_stop_hba_timers(phba
);
8998 phba
->sli4_hba
.intr_enable
= 0;
9001 * Gracefully wait out the potential current outstanding asynchronous
9005 /* First, block any pending async mailbox command from posted */
9006 spin_lock_irq(&phba
->hbalock
);
9007 phba
->sli
.sli_flag
|= LPFC_SLI_ASYNC_MBX_BLK
;
9008 spin_unlock_irq(&phba
->hbalock
);
9009 /* Now, trying to wait it out if we can */
9010 while (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
9012 if (++wait_cnt
> LPFC_ACTIVE_MBOX_WAIT_CNT
)
9015 /* Forcefully release the outstanding mailbox command if timed out */
9016 if (phba
->sli
.sli_flag
& LPFC_SLI_MBOX_ACTIVE
) {
9017 spin_lock_irq(&phba
->hbalock
);
9018 mboxq
= phba
->sli
.mbox_active
;
9019 mboxq
->u
.mb
.mbxStatus
= MBX_NOT_FINISHED
;
9020 __lpfc_mbox_cmpl_put(phba
, mboxq
);
9021 phba
->sli
.sli_flag
&= ~LPFC_SLI_MBOX_ACTIVE
;
9022 phba
->sli
.mbox_active
= NULL
;
9023 spin_unlock_irq(&phba
->hbalock
);
9026 /* Abort all iocbs associated with the hba */
9027 lpfc_sli_hba_iocb_abort(phba
);
9029 /* Wait for completion of device XRI exchange busy */
9030 lpfc_sli4_xri_exchange_busy_wait(phba
);
9032 /* Disable PCI subsystem interrupt */
9033 lpfc_sli4_disable_intr(phba
);
9035 /* Disable SR-IOV if enabled */
9036 if (phba
->cfg_sriov_nr_virtfn
)
9037 pci_disable_sriov(pdev
);
9039 /* Stop kthread signal shall trigger work_done one more time */
9040 kthread_stop(phba
->worker_thread
);
9042 /* Reset SLI4 HBA FCoE function */
9043 lpfc_pci_function_reset(phba
);
9044 lpfc_sli4_queue_destroy(phba
);
9046 /* Stop the SLI4 device port */
9047 phba
->pport
->work_port_events
= 0;
9051 * lpfc_pc_sli4_params_get - Get the SLI4_PARAMS port capabilities.
9052 * @phba: Pointer to HBA context object.
9053 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9055 * This function is called in the SLI4 code path to read the port's
9056 * sli4 capabilities.
9058 * This function may be be called from any context that can block-wait
9059 * for the completion. The expectation is that this routine is called
9060 * typically from probe_one or from the online routine.
9063 lpfc_pc_sli4_params_get(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
9066 struct lpfc_mqe
*mqe
;
9067 struct lpfc_pc_sli4_params
*sli4_params
;
9071 mqe
= &mboxq
->u
.mqe
;
9073 /* Read the port's SLI4 Parameters port capabilities */
9074 lpfc_pc_sli4_params(mboxq
);
9075 if (!phba
->sli4_hba
.intr_enable
)
9076 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
9078 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
9079 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
9085 sli4_params
= &phba
->sli4_hba
.pc_sli4_params
;
9086 sli4_params
->if_type
= bf_get(if_type
, &mqe
->un
.sli4_params
);
9087 sli4_params
->sli_rev
= bf_get(sli_rev
, &mqe
->un
.sli4_params
);
9088 sli4_params
->sli_family
= bf_get(sli_family
, &mqe
->un
.sli4_params
);
9089 sli4_params
->featurelevel_1
= bf_get(featurelevel_1
,
9090 &mqe
->un
.sli4_params
);
9091 sli4_params
->featurelevel_2
= bf_get(featurelevel_2
,
9092 &mqe
->un
.sli4_params
);
9093 sli4_params
->proto_types
= mqe
->un
.sli4_params
.word3
;
9094 sli4_params
->sge_supp_len
= mqe
->un
.sli4_params
.sge_supp_len
;
9095 sli4_params
->if_page_sz
= bf_get(if_page_sz
, &mqe
->un
.sli4_params
);
9096 sli4_params
->rq_db_window
= bf_get(rq_db_window
, &mqe
->un
.sli4_params
);
9097 sli4_params
->loopbk_scope
= bf_get(loopbk_scope
, &mqe
->un
.sli4_params
);
9098 sli4_params
->eq_pages_max
= bf_get(eq_pages
, &mqe
->un
.sli4_params
);
9099 sli4_params
->eqe_size
= bf_get(eqe_size
, &mqe
->un
.sli4_params
);
9100 sli4_params
->cq_pages_max
= bf_get(cq_pages
, &mqe
->un
.sli4_params
);
9101 sli4_params
->cqe_size
= bf_get(cqe_size
, &mqe
->un
.sli4_params
);
9102 sli4_params
->mq_pages_max
= bf_get(mq_pages
, &mqe
->un
.sli4_params
);
9103 sli4_params
->mqe_size
= bf_get(mqe_size
, &mqe
->un
.sli4_params
);
9104 sli4_params
->mq_elem_cnt
= bf_get(mq_elem_cnt
, &mqe
->un
.sli4_params
);
9105 sli4_params
->wq_pages_max
= bf_get(wq_pages
, &mqe
->un
.sli4_params
);
9106 sli4_params
->wqe_size
= bf_get(wqe_size
, &mqe
->un
.sli4_params
);
9107 sli4_params
->rq_pages_max
= bf_get(rq_pages
, &mqe
->un
.sli4_params
);
9108 sli4_params
->rqe_size
= bf_get(rqe_size
, &mqe
->un
.sli4_params
);
9109 sli4_params
->hdr_pages_max
= bf_get(hdr_pages
, &mqe
->un
.sli4_params
);
9110 sli4_params
->hdr_size
= bf_get(hdr_size
, &mqe
->un
.sli4_params
);
9111 sli4_params
->hdr_pp_align
= bf_get(hdr_pp_align
, &mqe
->un
.sli4_params
);
9112 sli4_params
->sgl_pages_max
= bf_get(sgl_pages
, &mqe
->un
.sli4_params
);
9113 sli4_params
->sgl_pp_align
= bf_get(sgl_pp_align
, &mqe
->un
.sli4_params
);
9115 /* Make sure that sge_supp_len can be handled by the driver */
9116 if (sli4_params
->sge_supp_len
> LPFC_MAX_SGE_SIZE
)
9117 sli4_params
->sge_supp_len
= LPFC_MAX_SGE_SIZE
;
9123 * lpfc_get_sli4_parameters - Get the SLI4 Config PARAMETERS.
9124 * @phba: Pointer to HBA context object.
9125 * @mboxq: Pointer to the mailboxq memory for the mailbox command response.
9127 * This function is called in the SLI4 code path to read the port's
9128 * sli4 capabilities.
9130 * This function may be be called from any context that can block-wait
9131 * for the completion. The expectation is that this routine is called
9132 * typically from probe_one or from the online routine.
9135 lpfc_get_sli4_parameters(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
9138 struct lpfc_mqe
*mqe
= &mboxq
->u
.mqe
;
9139 struct lpfc_pc_sli4_params
*sli4_params
;
9142 struct lpfc_sli4_parameters
*mbx_sli4_parameters
;
9145 * By default, the driver assumes the SLI4 port requires RPI
9146 * header postings. The SLI4_PARAM response will correct this
9149 phba
->sli4_hba
.rpi_hdrs_in_use
= 1;
9151 /* Read the port's SLI4 Config Parameters */
9152 length
= (sizeof(struct lpfc_mbx_get_sli4_parameters
) -
9153 sizeof(struct lpfc_sli4_cfg_mhdr
));
9154 lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_COMMON
,
9155 LPFC_MBOX_OPCODE_GET_SLI4_PARAMETERS
,
9156 length
, LPFC_SLI4_MBX_EMBED
);
9157 if (!phba
->sli4_hba
.intr_enable
)
9158 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_POLL
);
9160 mbox_tmo
= lpfc_mbox_tmo_val(phba
, mboxq
);
9161 rc
= lpfc_sli_issue_mbox_wait(phba
, mboxq
, mbox_tmo
);
9165 sli4_params
= &phba
->sli4_hba
.pc_sli4_params
;
9166 mbx_sli4_parameters
= &mqe
->un
.get_sli4_parameters
.sli4_parameters
;
9167 sli4_params
->if_type
= bf_get(cfg_if_type
, mbx_sli4_parameters
);
9168 sli4_params
->sli_rev
= bf_get(cfg_sli_rev
, mbx_sli4_parameters
);
9169 sli4_params
->sli_family
= bf_get(cfg_sli_family
, mbx_sli4_parameters
);
9170 sli4_params
->featurelevel_1
= bf_get(cfg_sli_hint_1
,
9171 mbx_sli4_parameters
);
9172 sli4_params
->featurelevel_2
= bf_get(cfg_sli_hint_2
,
9173 mbx_sli4_parameters
);
9174 if (bf_get(cfg_phwq
, mbx_sli4_parameters
))
9175 phba
->sli3_options
|= LPFC_SLI4_PHWQ_ENABLED
;
9177 phba
->sli3_options
&= ~LPFC_SLI4_PHWQ_ENABLED
;
9178 sli4_params
->sge_supp_len
= mbx_sli4_parameters
->sge_supp_len
;
9179 sli4_params
->loopbk_scope
= bf_get(loopbk_scope
, mbx_sli4_parameters
);
9180 sli4_params
->cqv
= bf_get(cfg_cqv
, mbx_sli4_parameters
);
9181 sli4_params
->mqv
= bf_get(cfg_mqv
, mbx_sli4_parameters
);
9182 sli4_params
->wqv
= bf_get(cfg_wqv
, mbx_sli4_parameters
);
9183 sli4_params
->rqv
= bf_get(cfg_rqv
, mbx_sli4_parameters
);
9184 sli4_params
->sgl_pages_max
= bf_get(cfg_sgl_page_cnt
,
9185 mbx_sli4_parameters
);
9186 sli4_params
->sgl_pp_align
= bf_get(cfg_sgl_pp_align
,
9187 mbx_sli4_parameters
);
9188 phba
->sli4_hba
.extents_in_use
= bf_get(cfg_ext
, mbx_sli4_parameters
);
9189 phba
->sli4_hba
.rpi_hdrs_in_use
= bf_get(cfg_hdrr
, mbx_sli4_parameters
);
9191 /* Make sure that sge_supp_len can be handled by the driver */
9192 if (sli4_params
->sge_supp_len
> LPFC_MAX_SGE_SIZE
)
9193 sli4_params
->sge_supp_len
= LPFC_MAX_SGE_SIZE
;
9199 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
9200 * @pdev: pointer to PCI device
9201 * @pid: pointer to PCI device identifier
9203 * This routine is to be called to attach a device with SLI-3 interface spec
9204 * to the PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9205 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9206 * information of the device and driver to see if the driver state that it can
9207 * support this kind of device. If the match is successful, the driver core
9208 * invokes this routine. If this routine determines it can claim the HBA, it
9209 * does all the initialization that it needs to do to handle the HBA properly.
9212 * 0 - driver can claim the device
9213 * negative value - driver can not claim the device
9216 lpfc_pci_probe_one_s3(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
9218 struct lpfc_hba
*phba
;
9219 struct lpfc_vport
*vport
= NULL
;
9220 struct Scsi_Host
*shost
= NULL
;
9222 uint32_t cfg_mode
, intr_mode
;
9224 /* Allocate memory for HBA structure */
9225 phba
= lpfc_hba_alloc(pdev
);
9229 /* Perform generic PCI device enabling operation */
9230 error
= lpfc_enable_pci_dev(phba
);
9234 /* Set up SLI API function jump table for PCI-device group-0 HBAs */
9235 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_LP
);
9237 goto out_disable_pci_dev
;
9239 /* Set up SLI-3 specific device PCI memory space */
9240 error
= lpfc_sli_pci_mem_setup(phba
);
9242 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9243 "1402 Failed to set up pci memory space.\n");
9244 goto out_disable_pci_dev
;
9247 /* Set up phase-1 common device driver resources */
9248 error
= lpfc_setup_driver_resource_phase1(phba
);
9250 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9251 "1403 Failed to set up driver resource.\n");
9252 goto out_unset_pci_mem_s3
;
9255 /* Set up SLI-3 specific device driver resources */
9256 error
= lpfc_sli_driver_resource_setup(phba
);
9258 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9259 "1404 Failed to set up driver resource.\n");
9260 goto out_unset_pci_mem_s3
;
9263 /* Initialize and populate the iocb list per host */
9264 error
= lpfc_init_iocb_list(phba
, LPFC_IOCB_LIST_CNT
);
9266 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9267 "1405 Failed to initialize iocb list.\n");
9268 goto out_unset_driver_resource_s3
;
9271 /* Set up common device driver resources */
9272 error
= lpfc_setup_driver_resource_phase2(phba
);
9274 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9275 "1406 Failed to set up driver resource.\n");
9276 goto out_free_iocb_list
;
9279 /* Get the default values for Model Name and Description */
9280 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
9282 /* Create SCSI host to the physical port */
9283 error
= lpfc_create_shost(phba
);
9285 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9286 "1407 Failed to create scsi host.\n");
9287 goto out_unset_driver_resource
;
9290 /* Configure sysfs attributes */
9291 vport
= phba
->pport
;
9292 error
= lpfc_alloc_sysfs_attr(vport
);
9294 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9295 "1476 Failed to allocate sysfs attr\n");
9296 goto out_destroy_shost
;
9299 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
9300 /* Now, trying to enable interrupt and bring up the device */
9301 cfg_mode
= phba
->cfg_use_msi
;
9303 /* Put device to a known state before enabling interrupt */
9304 lpfc_stop_port(phba
);
9305 /* Configure and enable interrupt */
9306 intr_mode
= lpfc_sli_enable_intr(phba
, cfg_mode
);
9307 if (intr_mode
== LPFC_INTR_ERROR
) {
9308 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9309 "0431 Failed to enable interrupt.\n");
9311 goto out_free_sysfs_attr
;
9313 /* SLI-3 HBA setup */
9314 if (lpfc_sli_hba_setup(phba
)) {
9315 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9316 "1477 Failed to set up hba\n");
9318 goto out_remove_device
;
9321 /* Wait 50ms for the interrupts of previous mailbox commands */
9323 /* Check active interrupts on message signaled interrupts */
9324 if (intr_mode
== 0 ||
9325 phba
->sli
.slistat
.sli_intr
> LPFC_MSIX_VECTORS
) {
9326 /* Log the current active interrupt mode */
9327 phba
->intr_mode
= intr_mode
;
9328 lpfc_log_intr_mode(phba
, intr_mode
);
9331 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9332 "0447 Configure interrupt mode (%d) "
9333 "failed active interrupt test.\n",
9335 /* Disable the current interrupt mode */
9336 lpfc_sli_disable_intr(phba
);
9337 /* Try next level of interrupt mode */
9338 cfg_mode
= --intr_mode
;
9342 /* Perform post initialization setup */
9343 lpfc_post_init_setup(phba
);
9345 /* Check if there are static vports to be created. */
9346 lpfc_create_static_vport(phba
);
9351 lpfc_unset_hba(phba
);
9352 out_free_sysfs_attr
:
9353 lpfc_free_sysfs_attr(vport
);
9355 lpfc_destroy_shost(phba
);
9356 out_unset_driver_resource
:
9357 lpfc_unset_driver_resource_phase2(phba
);
9359 lpfc_free_iocb_list(phba
);
9360 out_unset_driver_resource_s3
:
9361 lpfc_sli_driver_resource_unset(phba
);
9362 out_unset_pci_mem_s3
:
9363 lpfc_sli_pci_mem_unset(phba
);
9364 out_disable_pci_dev
:
9365 lpfc_disable_pci_dev(phba
);
9367 scsi_host_put(shost
);
9369 lpfc_hba_free(phba
);
9374 * lpfc_pci_remove_one_s3 - PCI func to unreg SLI-3 device from PCI subsystem.
9375 * @pdev: pointer to PCI device
9377 * This routine is to be called to disattach a device with SLI-3 interface
9378 * spec from PCI subsystem. When an Emulex HBA with SLI-3 interface spec is
9379 * removed from PCI bus, it performs all the necessary cleanup for the HBA
9380 * device to be removed from the PCI subsystem properly.
9383 lpfc_pci_remove_one_s3(struct pci_dev
*pdev
)
9385 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9386 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
9387 struct lpfc_vport
**vports
;
9388 struct lpfc_hba
*phba
= vport
->phba
;
9390 int bars
= pci_select_bars(pdev
, IORESOURCE_MEM
);
9392 spin_lock_irq(&phba
->hbalock
);
9393 vport
->load_flag
|= FC_UNLOADING
;
9394 spin_unlock_irq(&phba
->hbalock
);
9396 lpfc_free_sysfs_attr(vport
);
9398 /* Release all the vports against this physical port */
9399 vports
= lpfc_create_vport_work_array(phba
);
9401 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
9402 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
9404 fc_vport_terminate(vports
[i
]->fc_vport
);
9406 lpfc_destroy_vport_work_array(phba
, vports
);
9408 /* Remove FC host and then SCSI host with the physical port */
9409 fc_remove_host(shost
);
9410 scsi_remove_host(shost
);
9411 lpfc_cleanup(vport
);
9414 * Bring down the SLI Layer. This step disable all interrupts,
9415 * clears the rings, discards all mailbox commands, and resets
9419 /* HBA interrupt will be disabled after this call */
9420 lpfc_sli_hba_down(phba
);
9421 /* Stop kthread signal shall trigger work_done one more time */
9422 kthread_stop(phba
->worker_thread
);
9423 /* Final cleanup of txcmplq and reset the HBA */
9424 lpfc_sli_brdrestart(phba
);
9426 kfree(phba
->vpi_bmask
);
9427 kfree(phba
->vpi_ids
);
9429 lpfc_stop_hba_timers(phba
);
9430 spin_lock_irq(&phba
->hbalock
);
9431 list_del_init(&vport
->listentry
);
9432 spin_unlock_irq(&phba
->hbalock
);
9434 lpfc_debugfs_terminate(vport
);
9436 /* Disable SR-IOV if enabled */
9437 if (phba
->cfg_sriov_nr_virtfn
)
9438 pci_disable_sriov(pdev
);
9440 /* Disable interrupt */
9441 lpfc_sli_disable_intr(phba
);
9443 pci_set_drvdata(pdev
, NULL
);
9444 scsi_host_put(shost
);
9447 * Call scsi_free before mem_free since scsi bufs are released to their
9448 * corresponding pools here.
9450 lpfc_scsi_free(phba
);
9451 lpfc_mem_free_all(phba
);
9453 dma_free_coherent(&pdev
->dev
, lpfc_sli_hbq_size(),
9454 phba
->hbqslimp
.virt
, phba
->hbqslimp
.phys
);
9456 /* Free resources associated with SLI2 interface */
9457 dma_free_coherent(&pdev
->dev
, SLI2_SLIM_SIZE
,
9458 phba
->slim2p
.virt
, phba
->slim2p
.phys
);
9460 /* unmap adapter SLIM and Control Registers */
9461 iounmap(phba
->ctrl_regs_memmap_p
);
9462 iounmap(phba
->slim_memmap_p
);
9464 lpfc_hba_free(phba
);
9466 pci_release_selected_regions(pdev
, bars
);
9467 pci_disable_device(pdev
);
9471 * lpfc_pci_suspend_one_s3 - PCI func to suspend SLI-3 device for power mgmnt
9472 * @pdev: pointer to PCI device
9473 * @msg: power management message
9475 * This routine is to be called from the kernel's PCI subsystem to support
9476 * system Power Management (PM) to device with SLI-3 interface spec. When
9477 * PM invokes this method, it quiesces the device by stopping the driver's
9478 * worker thread for the device, turning off device's interrupt and DMA,
9479 * and bring the device offline. Note that as the driver implements the
9480 * minimum PM requirements to a power-aware driver's PM support for the
9481 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
9482 * to the suspend() method call will be treated as SUSPEND and the driver will
9483 * fully reinitialize its device during resume() method call, the driver will
9484 * set device to PCI_D3hot state in PCI config space instead of setting it
9485 * according to the @msg provided by the PM.
9488 * 0 - driver suspended the device
9492 lpfc_pci_suspend_one_s3(struct pci_dev
*pdev
, pm_message_t msg
)
9494 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9495 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9497 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9498 "0473 PCI device Power Management suspend.\n");
9500 /* Bring down the device */
9501 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
9503 kthread_stop(phba
->worker_thread
);
9505 /* Disable interrupt from device */
9506 lpfc_sli_disable_intr(phba
);
9508 /* Save device state to PCI config space */
9509 pci_save_state(pdev
);
9510 pci_set_power_state(pdev
, PCI_D3hot
);
9516 * lpfc_pci_resume_one_s3 - PCI func to resume SLI-3 device for power mgmnt
9517 * @pdev: pointer to PCI device
9519 * This routine is to be called from the kernel's PCI subsystem to support
9520 * system Power Management (PM) to device with SLI-3 interface spec. When PM
9521 * invokes this method, it restores the device's PCI config space state and
9522 * fully reinitializes the device and brings it online. Note that as the
9523 * driver implements the minimum PM requirements to a power-aware driver's
9524 * PM for suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE,
9525 * FREEZE) to the suspend() method call will be treated as SUSPEND and the
9526 * driver will fully reinitialize its device during resume() method call,
9527 * the device will be set to PCI_D0 directly in PCI config space before
9528 * restoring the state.
9531 * 0 - driver suspended the device
9535 lpfc_pci_resume_one_s3(struct pci_dev
*pdev
)
9537 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9538 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9542 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
9543 "0452 PCI device Power Management resume.\n");
9545 /* Restore device state from PCI config space */
9546 pci_set_power_state(pdev
, PCI_D0
);
9547 pci_restore_state(pdev
);
9550 * As the new kernel behavior of pci_restore_state() API call clears
9551 * device saved_state flag, need to save the restored state again.
9553 pci_save_state(pdev
);
9555 if (pdev
->is_busmaster
)
9556 pci_set_master(pdev
);
9558 /* Startup the kernel thread for this host adapter. */
9559 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
9560 "lpfc_worker_%d", phba
->brd_no
);
9561 if (IS_ERR(phba
->worker_thread
)) {
9562 error
= PTR_ERR(phba
->worker_thread
);
9563 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9564 "0434 PM resume failed to start worker "
9565 "thread: error=x%x.\n", error
);
9569 /* Configure and enable interrupt */
9570 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
9571 if (intr_mode
== LPFC_INTR_ERROR
) {
9572 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9573 "0430 PM resume Failed to enable interrupt\n");
9576 phba
->intr_mode
= intr_mode
;
9578 /* Restart HBA and bring it online */
9579 lpfc_sli_brdrestart(phba
);
9582 /* Log the current active interrupt mode */
9583 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
9589 * lpfc_sli_prep_dev_for_recover - Prepare SLI3 device for pci slot recover
9590 * @phba: pointer to lpfc hba data structure.
9592 * This routine is called to prepare the SLI3 device for PCI slot recover. It
9593 * aborts all the outstanding SCSI I/Os to the pci device.
9596 lpfc_sli_prep_dev_for_recover(struct lpfc_hba
*phba
)
9598 struct lpfc_sli
*psli
= &phba
->sli
;
9599 struct lpfc_sli_ring
*pring
;
9601 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9602 "2723 PCI channel I/O abort preparing for recovery\n");
9605 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
9606 * and let the SCSI mid-layer to retry them to recover.
9608 pring
= &psli
->ring
[psli
->fcp_ring
];
9609 lpfc_sli_abort_iocb_ring(phba
, pring
);
9613 * lpfc_sli_prep_dev_for_reset - Prepare SLI3 device for pci slot reset
9614 * @phba: pointer to lpfc hba data structure.
9616 * This routine is called to prepare the SLI3 device for PCI slot reset. It
9617 * disables the device interrupt and pci device, and aborts the internal FCP
9621 lpfc_sli_prep_dev_for_reset(struct lpfc_hba
*phba
)
9623 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9624 "2710 PCI channel disable preparing for reset\n");
9626 /* Block any management I/Os to the device */
9627 lpfc_block_mgmt_io(phba
, LPFC_MBX_WAIT
);
9629 /* Block all SCSI devices' I/Os on the host */
9630 lpfc_scsi_dev_block(phba
);
9632 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
9633 lpfc_sli_flush_fcp_rings(phba
);
9635 /* stop all timers */
9636 lpfc_stop_hba_timers(phba
);
9638 /* Disable interrupt and pci device */
9639 lpfc_sli_disable_intr(phba
);
9640 pci_disable_device(phba
->pcidev
);
9644 * lpfc_sli_prep_dev_for_perm_failure - Prepare SLI3 dev for pci slot disable
9645 * @phba: pointer to lpfc hba data structure.
9647 * This routine is called to prepare the SLI3 device for PCI slot permanently
9648 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
9652 lpfc_sli_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
9654 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9655 "2711 PCI channel permanent disable for failure\n");
9656 /* Block all SCSI devices' I/Os on the host */
9657 lpfc_scsi_dev_block(phba
);
9659 /* stop all timers */
9660 lpfc_stop_hba_timers(phba
);
9662 /* Clean up all driver's outstanding SCSI I/Os */
9663 lpfc_sli_flush_fcp_rings(phba
);
9667 * lpfc_io_error_detected_s3 - Method for handling SLI-3 device PCI I/O error
9668 * @pdev: pointer to PCI device.
9669 * @state: the current PCI connection state.
9671 * This routine is called from the PCI subsystem for I/O error handling to
9672 * device with SLI-3 interface spec. This function is called by the PCI
9673 * subsystem after a PCI bus error affecting this device has been detected.
9674 * When this function is invoked, it will need to stop all the I/Os and
9675 * interrupt(s) to the device. Once that is done, it will return
9676 * PCI_ERS_RESULT_NEED_RESET for the PCI subsystem to perform proper recovery
9680 * PCI_ERS_RESULT_CAN_RECOVER - can be recovered with reset_link
9681 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
9682 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9684 static pci_ers_result_t
9685 lpfc_io_error_detected_s3(struct pci_dev
*pdev
, pci_channel_state_t state
)
9687 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9688 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9691 case pci_channel_io_normal
:
9692 /* Non-fatal error, prepare for recovery */
9693 lpfc_sli_prep_dev_for_recover(phba
);
9694 return PCI_ERS_RESULT_CAN_RECOVER
;
9695 case pci_channel_io_frozen
:
9696 /* Fatal error, prepare for slot reset */
9697 lpfc_sli_prep_dev_for_reset(phba
);
9698 return PCI_ERS_RESULT_NEED_RESET
;
9699 case pci_channel_io_perm_failure
:
9700 /* Permanent failure, prepare for device down */
9701 lpfc_sli_prep_dev_for_perm_failure(phba
);
9702 return PCI_ERS_RESULT_DISCONNECT
;
9704 /* Unknown state, prepare and request slot reset */
9705 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9706 "0472 Unknown PCI error state: x%x\n", state
);
9707 lpfc_sli_prep_dev_for_reset(phba
);
9708 return PCI_ERS_RESULT_NEED_RESET
;
9713 * lpfc_io_slot_reset_s3 - Method for restarting PCI SLI-3 device from scratch.
9714 * @pdev: pointer to PCI device.
9716 * This routine is called from the PCI subsystem for error handling to
9717 * device with SLI-3 interface spec. This is called after PCI bus has been
9718 * reset to restart the PCI card from scratch, as if from a cold-boot.
9719 * During the PCI subsystem error recovery, after driver returns
9720 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
9721 * recovery and then call this routine before calling the .resume method
9722 * to recover the device. This function will initialize the HBA device,
9723 * enable the interrupt, but it will just put the HBA to offline state
9724 * without passing any I/O traffic.
9727 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
9728 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
9730 static pci_ers_result_t
9731 lpfc_io_slot_reset_s3(struct pci_dev
*pdev
)
9733 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9734 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9735 struct lpfc_sli
*psli
= &phba
->sli
;
9738 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
9739 if (pci_enable_device_mem(pdev
)) {
9740 printk(KERN_ERR
"lpfc: Cannot re-enable "
9741 "PCI device after reset.\n");
9742 return PCI_ERS_RESULT_DISCONNECT
;
9745 pci_restore_state(pdev
);
9748 * As the new kernel behavior of pci_restore_state() API call clears
9749 * device saved_state flag, need to save the restored state again.
9751 pci_save_state(pdev
);
9753 if (pdev
->is_busmaster
)
9754 pci_set_master(pdev
);
9756 spin_lock_irq(&phba
->hbalock
);
9757 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
9758 spin_unlock_irq(&phba
->hbalock
);
9760 /* Configure and enable interrupt */
9761 intr_mode
= lpfc_sli_enable_intr(phba
, phba
->intr_mode
);
9762 if (intr_mode
== LPFC_INTR_ERROR
) {
9763 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9764 "0427 Cannot re-enable interrupt after "
9766 return PCI_ERS_RESULT_DISCONNECT
;
9768 phba
->intr_mode
= intr_mode
;
9770 /* Take device offline, it will perform cleanup */
9771 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
9773 lpfc_sli_brdrestart(phba
);
9775 /* Log the current active interrupt mode */
9776 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
9778 return PCI_ERS_RESULT_RECOVERED
;
9782 * lpfc_io_resume_s3 - Method for resuming PCI I/O operation on SLI-3 device.
9783 * @pdev: pointer to PCI device
9785 * This routine is called from the PCI subsystem for error handling to device
9786 * with SLI-3 interface spec. It is called when kernel error recovery tells
9787 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
9788 * error recovery. After this call, traffic can start to flow from this device
9792 lpfc_io_resume_s3(struct pci_dev
*pdev
)
9794 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
9795 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
9797 /* Bring device online, it will be no-op for non-fatal error resume */
9800 /* Clean up Advanced Error Reporting (AER) if needed */
9801 if (phba
->hba_flag
& HBA_AER_ENABLED
)
9802 pci_cleanup_aer_uncorrect_error_status(pdev
);
9806 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
9807 * @phba: pointer to lpfc hba data structure.
9809 * returns the number of ELS/CT IOCBs to reserve
9812 lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba
*phba
)
9814 int max_xri
= phba
->sli4_hba
.max_cfg_param
.max_xri
;
9816 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9819 else if (max_xri
<= 256)
9821 else if (max_xri
<= 512)
9823 else if (max_xri
<= 1024)
9825 else if (max_xri
<= 1536)
9827 else if (max_xri
<= 2048)
9836 * lpfc_write_firmware - attempt to write a firmware image to the port
9837 * @fw: pointer to firmware image returned from request_firmware.
9838 * @phba: pointer to lpfc hba data structure.
9842 lpfc_write_firmware(const struct firmware
*fw
, void *context
)
9844 struct lpfc_hba
*phba
= (struct lpfc_hba
*)context
;
9845 char fwrev
[FW_REV_STR_SIZE
];
9846 struct lpfc_grp_hdr
*image
;
9847 struct list_head dma_buffer_list
;
9849 struct lpfc_dmabuf
*dmabuf
, *next
;
9850 uint32_t offset
= 0, temp_offset
= 0;
9852 /* It can be null in no-wait mode, sanity check */
9857 image
= (struct lpfc_grp_hdr
*)fw
->data
;
9859 INIT_LIST_HEAD(&dma_buffer_list
);
9860 if ((be32_to_cpu(image
->magic_number
) != LPFC_GROUP_OJECT_MAGIC_NUM
) ||
9861 (bf_get_be32(lpfc_grp_hdr_file_type
, image
) !=
9862 LPFC_FILE_TYPE_GROUP
) ||
9863 (bf_get_be32(lpfc_grp_hdr_id
, image
) != LPFC_FILE_ID_GROUP
) ||
9864 (be32_to_cpu(image
->size
) != fw
->size
)) {
9865 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9866 "3022 Invalid FW image found. "
9867 "Magic:%x Type:%x ID:%x\n",
9868 be32_to_cpu(image
->magic_number
),
9869 bf_get_be32(lpfc_grp_hdr_file_type
, image
),
9870 bf_get_be32(lpfc_grp_hdr_id
, image
));
9874 lpfc_decode_firmware_rev(phba
, fwrev
, 1);
9875 if (strncmp(fwrev
, image
->revision
, strnlen(image
->revision
, 16))) {
9876 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9877 "3023 Updating Firmware, Current Version:%s "
9879 fwrev
, image
->revision
);
9880 for (i
= 0; i
< LPFC_MBX_WR_CONFIG_MAX_BDE
; i
++) {
9881 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
),
9887 dmabuf
->virt
= dma_alloc_coherent(&phba
->pcidev
->dev
,
9891 if (!dmabuf
->virt
) {
9896 list_add_tail(&dmabuf
->list
, &dma_buffer_list
);
9898 while (offset
< fw
->size
) {
9899 temp_offset
= offset
;
9900 list_for_each_entry(dmabuf
, &dma_buffer_list
, list
) {
9901 if (temp_offset
+ SLI4_PAGE_SIZE
> fw
->size
) {
9902 memcpy(dmabuf
->virt
,
9903 fw
->data
+ temp_offset
,
9904 fw
->size
- temp_offset
);
9905 temp_offset
= fw
->size
;
9908 memcpy(dmabuf
->virt
, fw
->data
+ temp_offset
,
9910 temp_offset
+= SLI4_PAGE_SIZE
;
9912 rc
= lpfc_wr_object(phba
, &dma_buffer_list
,
9913 (fw
->size
- offset
), &offset
);
9921 list_for_each_entry_safe(dmabuf
, next
, &dma_buffer_list
, list
) {
9922 list_del(&dmabuf
->list
);
9923 dma_free_coherent(&phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
9924 dmabuf
->virt
, dmabuf
->phys
);
9927 release_firmware(fw
);
9929 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
9930 "3024 Firmware update done: %d.\n", rc
);
9935 * lpfc_sli4_request_firmware_update - Request linux generic firmware upgrade
9936 * @phba: pointer to lpfc hba data structure.
9938 * This routine is called to perform Linux generic firmware upgrade on device
9939 * that supports such feature.
9942 lpfc_sli4_request_firmware_update(struct lpfc_hba
*phba
, uint8_t fw_upgrade
)
9944 uint8_t file_name
[ELX_MODEL_NAME_SIZE
];
9946 const struct firmware
*fw
;
9948 /* Only supported on SLI4 interface type 2 for now */
9949 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
9950 LPFC_SLI_INTF_IF_TYPE_2
)
9953 snprintf(file_name
, ELX_MODEL_NAME_SIZE
, "%s.grp", phba
->ModelName
);
9955 if (fw_upgrade
== INT_FW_UPGRADE
) {
9956 ret
= request_firmware_nowait(THIS_MODULE
, FW_ACTION_HOTPLUG
,
9957 file_name
, &phba
->pcidev
->dev
,
9958 GFP_KERNEL
, (void *)phba
,
9959 lpfc_write_firmware
);
9960 } else if (fw_upgrade
== RUN_FW_UPGRADE
) {
9961 ret
= request_firmware(&fw
, file_name
, &phba
->pcidev
->dev
);
9963 lpfc_write_firmware(fw
, (void *)phba
);
9972 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
9973 * @pdev: pointer to PCI device
9974 * @pid: pointer to PCI device identifier
9976 * This routine is called from the kernel's PCI subsystem to device with
9977 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
9978 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
9979 * information of the device and driver to see if the driver state that it
9980 * can support this kind of device. If the match is successful, the driver
9981 * core invokes this routine. If this routine determines it can claim the HBA,
9982 * it does all the initialization that it needs to do to handle the HBA
9986 * 0 - driver can claim the device
9987 * negative value - driver can not claim the device
9990 lpfc_pci_probe_one_s4(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
9992 struct lpfc_hba
*phba
;
9993 struct lpfc_vport
*vport
= NULL
;
9994 struct Scsi_Host
*shost
= NULL
;
9996 uint32_t cfg_mode
, intr_mode
;
9997 int adjusted_fcp_io_channel
;
9999 /* Allocate memory for HBA structure */
10000 phba
= lpfc_hba_alloc(pdev
);
10004 /* Perform generic PCI device enabling operation */
10005 error
= lpfc_enable_pci_dev(phba
);
10007 goto out_free_phba
;
10009 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
10010 error
= lpfc_api_table_setup(phba
, LPFC_PCI_DEV_OC
);
10012 goto out_disable_pci_dev
;
10014 /* Set up SLI-4 specific device PCI memory space */
10015 error
= lpfc_sli4_pci_mem_setup(phba
);
10017 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10018 "1410 Failed to set up pci memory space.\n");
10019 goto out_disable_pci_dev
;
10022 /* Set up phase-1 common device driver resources */
10023 error
= lpfc_setup_driver_resource_phase1(phba
);
10025 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10026 "1411 Failed to set up driver resource.\n");
10027 goto out_unset_pci_mem_s4
;
10030 /* Set up SLI-4 Specific device driver resources */
10031 error
= lpfc_sli4_driver_resource_setup(phba
);
10033 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10034 "1412 Failed to set up driver resource.\n");
10035 goto out_unset_pci_mem_s4
;
10038 /* Initialize and populate the iocb list per host */
10040 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10041 "2821 initialize iocb list %d.\n",
10042 phba
->cfg_iocb_cnt
*1024);
10043 error
= lpfc_init_iocb_list(phba
, phba
->cfg_iocb_cnt
*1024);
10046 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10047 "1413 Failed to initialize iocb list.\n");
10048 goto out_unset_driver_resource_s4
;
10051 INIT_LIST_HEAD(&phba
->active_rrq_list
);
10052 INIT_LIST_HEAD(&phba
->fcf
.fcf_pri_list
);
10054 /* Set up common device driver resources */
10055 error
= lpfc_setup_driver_resource_phase2(phba
);
10057 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10058 "1414 Failed to set up driver resource.\n");
10059 goto out_free_iocb_list
;
10062 /* Get the default values for Model Name and Description */
10063 lpfc_get_hba_model_desc(phba
, phba
->ModelName
, phba
->ModelDesc
);
10065 /* Create SCSI host to the physical port */
10066 error
= lpfc_create_shost(phba
);
10068 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10069 "1415 Failed to create scsi host.\n");
10070 goto out_unset_driver_resource
;
10073 /* Configure sysfs attributes */
10074 vport
= phba
->pport
;
10075 error
= lpfc_alloc_sysfs_attr(vport
);
10077 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10078 "1416 Failed to allocate sysfs attr\n");
10079 goto out_destroy_shost
;
10082 shost
= lpfc_shost_from_vport(vport
); /* save shost for error cleanup */
10083 /* Now, trying to enable interrupt and bring up the device */
10084 cfg_mode
= phba
->cfg_use_msi
;
10086 /* Put device to a known state before enabling interrupt */
10087 lpfc_stop_port(phba
);
10088 /* Configure and enable interrupt */
10089 intr_mode
= lpfc_sli4_enable_intr(phba
, cfg_mode
);
10090 if (intr_mode
== LPFC_INTR_ERROR
) {
10091 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10092 "0426 Failed to enable interrupt.\n");
10094 goto out_free_sysfs_attr
;
10096 /* Default to single EQ for non-MSI-X */
10097 if (phba
->intr_type
!= MSIX
)
10098 adjusted_fcp_io_channel
= 1;
10100 adjusted_fcp_io_channel
= phba
->cfg_fcp_io_channel
;
10101 phba
->cfg_fcp_io_channel
= adjusted_fcp_io_channel
;
10102 /* Set up SLI-4 HBA */
10103 if (lpfc_sli4_hba_setup(phba
)) {
10104 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10105 "1421 Failed to set up hba\n");
10107 goto out_disable_intr
;
10110 /* Log the current active interrupt mode */
10111 phba
->intr_mode
= intr_mode
;
10112 lpfc_log_intr_mode(phba
, intr_mode
);
10114 /* Perform post initialization setup */
10115 lpfc_post_init_setup(phba
);
10117 /* check for firmware upgrade or downgrade */
10118 if (phba
->cfg_request_firmware_upgrade
)
10119 ret
= lpfc_sli4_request_firmware_update(phba
, INT_FW_UPGRADE
);
10121 /* Check if there are static vports to be created. */
10122 lpfc_create_static_vport(phba
);
10126 lpfc_sli4_disable_intr(phba
);
10127 out_free_sysfs_attr
:
10128 lpfc_free_sysfs_attr(vport
);
10130 lpfc_destroy_shost(phba
);
10131 out_unset_driver_resource
:
10132 lpfc_unset_driver_resource_phase2(phba
);
10133 out_free_iocb_list
:
10134 lpfc_free_iocb_list(phba
);
10135 out_unset_driver_resource_s4
:
10136 lpfc_sli4_driver_resource_unset(phba
);
10137 out_unset_pci_mem_s4
:
10138 lpfc_sli4_pci_mem_unset(phba
);
10139 out_disable_pci_dev
:
10140 lpfc_disable_pci_dev(phba
);
10142 scsi_host_put(shost
);
10144 lpfc_hba_free(phba
);
10149 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
10150 * @pdev: pointer to PCI device
10152 * This routine is called from the kernel's PCI subsystem to device with
10153 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
10154 * removed from PCI bus, it performs all the necessary cleanup for the HBA
10155 * device to be removed from the PCI subsystem properly.
10158 lpfc_pci_remove_one_s4(struct pci_dev
*pdev
)
10160 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10161 struct lpfc_vport
*vport
= (struct lpfc_vport
*) shost
->hostdata
;
10162 struct lpfc_vport
**vports
;
10163 struct lpfc_hba
*phba
= vport
->phba
;
10166 /* Mark the device unloading flag */
10167 spin_lock_irq(&phba
->hbalock
);
10168 vport
->load_flag
|= FC_UNLOADING
;
10169 spin_unlock_irq(&phba
->hbalock
);
10171 /* Free the HBA sysfs attributes */
10172 lpfc_free_sysfs_attr(vport
);
10174 /* Release all the vports against this physical port */
10175 vports
= lpfc_create_vport_work_array(phba
);
10176 if (vports
!= NULL
)
10177 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
10178 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
10180 fc_vport_terminate(vports
[i
]->fc_vport
);
10182 lpfc_destroy_vport_work_array(phba
, vports
);
10184 /* Remove FC host and then SCSI host with the physical port */
10185 fc_remove_host(shost
);
10186 scsi_remove_host(shost
);
10188 /* Perform cleanup on the physical port */
10189 lpfc_cleanup(vport
);
10192 * Bring down the SLI Layer. This step disables all interrupts,
10193 * clears the rings, discards all mailbox commands, and resets
10194 * the HBA FCoE function.
10196 lpfc_debugfs_terminate(vport
);
10197 lpfc_sli4_hba_unset(phba
);
10199 spin_lock_irq(&phba
->hbalock
);
10200 list_del_init(&vport
->listentry
);
10201 spin_unlock_irq(&phba
->hbalock
);
10203 /* Perform scsi free before driver resource_unset since scsi
10204 * buffers are released to their corresponding pools here.
10206 lpfc_scsi_free(phba
);
10208 lpfc_sli4_driver_resource_unset(phba
);
10210 /* Unmap adapter Control and Doorbell registers */
10211 lpfc_sli4_pci_mem_unset(phba
);
10213 /* Release PCI resources and disable device's PCI function */
10214 scsi_host_put(shost
);
10215 lpfc_disable_pci_dev(phba
);
10217 /* Finally, free the driver's device data structure */
10218 lpfc_hba_free(phba
);
10224 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
10225 * @pdev: pointer to PCI device
10226 * @msg: power management message
10228 * This routine is called from the kernel's PCI subsystem to support system
10229 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
10230 * this method, it quiesces the device by stopping the driver's worker
10231 * thread for the device, turning off device's interrupt and DMA, and bring
10232 * the device offline. Note that as the driver implements the minimum PM
10233 * requirements to a power-aware driver's PM support for suspend/resume -- all
10234 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
10235 * method call will be treated as SUSPEND and the driver will fully
10236 * reinitialize its device during resume() method call, the driver will set
10237 * device to PCI_D3hot state in PCI config space instead of setting it
10238 * according to the @msg provided by the PM.
10241 * 0 - driver suspended the device
10245 lpfc_pci_suspend_one_s4(struct pci_dev
*pdev
, pm_message_t msg
)
10247 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10248 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10250 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10251 "2843 PCI device Power Management suspend.\n");
10253 /* Bring down the device */
10254 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
10255 lpfc_offline(phba
);
10256 kthread_stop(phba
->worker_thread
);
10258 /* Disable interrupt from device */
10259 lpfc_sli4_disable_intr(phba
);
10260 lpfc_sli4_queue_destroy(phba
);
10262 /* Save device state to PCI config space */
10263 pci_save_state(pdev
);
10264 pci_set_power_state(pdev
, PCI_D3hot
);
10270 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
10271 * @pdev: pointer to PCI device
10273 * This routine is called from the kernel's PCI subsystem to support system
10274 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
10275 * this method, it restores the device's PCI config space state and fully
10276 * reinitializes the device and brings it online. Note that as the driver
10277 * implements the minimum PM requirements to a power-aware driver's PM for
10278 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
10279 * to the suspend() method call will be treated as SUSPEND and the driver
10280 * will fully reinitialize its device during resume() method call, the device
10281 * will be set to PCI_D0 directly in PCI config space before restoring the
10285 * 0 - driver suspended the device
10289 lpfc_pci_resume_one_s4(struct pci_dev
*pdev
)
10291 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10292 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10293 uint32_t intr_mode
;
10296 lpfc_printf_log(phba
, KERN_INFO
, LOG_INIT
,
10297 "0292 PCI device Power Management resume.\n");
10299 /* Restore device state from PCI config space */
10300 pci_set_power_state(pdev
, PCI_D0
);
10301 pci_restore_state(pdev
);
10304 * As the new kernel behavior of pci_restore_state() API call clears
10305 * device saved_state flag, need to save the restored state again.
10307 pci_save_state(pdev
);
10309 if (pdev
->is_busmaster
)
10310 pci_set_master(pdev
);
10312 /* Startup the kernel thread for this host adapter. */
10313 phba
->worker_thread
= kthread_run(lpfc_do_work
, phba
,
10314 "lpfc_worker_%d", phba
->brd_no
);
10315 if (IS_ERR(phba
->worker_thread
)) {
10316 error
= PTR_ERR(phba
->worker_thread
);
10317 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10318 "0293 PM resume failed to start worker "
10319 "thread: error=x%x.\n", error
);
10323 /* Configure and enable interrupt */
10324 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
10325 if (intr_mode
== LPFC_INTR_ERROR
) {
10326 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10327 "0294 PM resume Failed to enable interrupt\n");
10330 phba
->intr_mode
= intr_mode
;
10332 /* Restart HBA and bring it online */
10333 lpfc_sli_brdrestart(phba
);
10336 /* Log the current active interrupt mode */
10337 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
10343 * lpfc_sli4_prep_dev_for_recover - Prepare SLI4 device for pci slot recover
10344 * @phba: pointer to lpfc hba data structure.
10346 * This routine is called to prepare the SLI4 device for PCI slot recover. It
10347 * aborts all the outstanding SCSI I/Os to the pci device.
10350 lpfc_sli4_prep_dev_for_recover(struct lpfc_hba
*phba
)
10352 struct lpfc_sli
*psli
= &phba
->sli
;
10353 struct lpfc_sli_ring
*pring
;
10355 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10356 "2828 PCI channel I/O abort preparing for recovery\n");
10358 * There may be errored I/Os through HBA, abort all I/Os on txcmplq
10359 * and let the SCSI mid-layer to retry them to recover.
10361 pring
= &psli
->ring
[psli
->fcp_ring
];
10362 lpfc_sli_abort_iocb_ring(phba
, pring
);
10366 * lpfc_sli4_prep_dev_for_reset - Prepare SLI4 device for pci slot reset
10367 * @phba: pointer to lpfc hba data structure.
10369 * This routine is called to prepare the SLI4 device for PCI slot reset. It
10370 * disables the device interrupt and pci device, and aborts the internal FCP
10374 lpfc_sli4_prep_dev_for_reset(struct lpfc_hba
*phba
)
10376 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10377 "2826 PCI channel disable preparing for reset\n");
10379 /* Block any management I/Os to the device */
10380 lpfc_block_mgmt_io(phba
, LPFC_MBX_NO_WAIT
);
10382 /* Block all SCSI devices' I/Os on the host */
10383 lpfc_scsi_dev_block(phba
);
10385 /* Flush all driver's outstanding SCSI I/Os as we are to reset */
10386 lpfc_sli_flush_fcp_rings(phba
);
10388 /* stop all timers */
10389 lpfc_stop_hba_timers(phba
);
10391 /* Disable interrupt and pci device */
10392 lpfc_sli4_disable_intr(phba
);
10393 lpfc_sli4_queue_destroy(phba
);
10394 pci_disable_device(phba
->pcidev
);
10398 * lpfc_sli4_prep_dev_for_perm_failure - Prepare SLI4 dev for pci slot disable
10399 * @phba: pointer to lpfc hba data structure.
10401 * This routine is called to prepare the SLI4 device for PCI slot permanently
10402 * disabling. It blocks the SCSI transport layer traffic and flushes the FCP
10406 lpfc_sli4_prep_dev_for_perm_failure(struct lpfc_hba
*phba
)
10408 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10409 "2827 PCI channel permanent disable for failure\n");
10411 /* Block all SCSI devices' I/Os on the host */
10412 lpfc_scsi_dev_block(phba
);
10414 /* stop all timers */
10415 lpfc_stop_hba_timers(phba
);
10417 /* Clean up all driver's outstanding SCSI I/Os */
10418 lpfc_sli_flush_fcp_rings(phba
);
10422 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
10423 * @pdev: pointer to PCI device.
10424 * @state: the current PCI connection state.
10426 * This routine is called from the PCI subsystem for error handling to device
10427 * with SLI-4 interface spec. This function is called by the PCI subsystem
10428 * after a PCI bus error affecting this device has been detected. When this
10429 * function is invoked, it will need to stop all the I/Os and interrupt(s)
10430 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
10431 * for the PCI subsystem to perform proper recovery as desired.
10434 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10435 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10437 static pci_ers_result_t
10438 lpfc_io_error_detected_s4(struct pci_dev
*pdev
, pci_channel_state_t state
)
10440 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10441 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10444 case pci_channel_io_normal
:
10445 /* Non-fatal error, prepare for recovery */
10446 lpfc_sli4_prep_dev_for_recover(phba
);
10447 return PCI_ERS_RESULT_CAN_RECOVER
;
10448 case pci_channel_io_frozen
:
10449 /* Fatal error, prepare for slot reset */
10450 lpfc_sli4_prep_dev_for_reset(phba
);
10451 return PCI_ERS_RESULT_NEED_RESET
;
10452 case pci_channel_io_perm_failure
:
10453 /* Permanent failure, prepare for device down */
10454 lpfc_sli4_prep_dev_for_perm_failure(phba
);
10455 return PCI_ERS_RESULT_DISCONNECT
;
10457 /* Unknown state, prepare and request slot reset */
10458 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10459 "2825 Unknown PCI error state: x%x\n", state
);
10460 lpfc_sli4_prep_dev_for_reset(phba
);
10461 return PCI_ERS_RESULT_NEED_RESET
;
10466 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
10467 * @pdev: pointer to PCI device.
10469 * This routine is called from the PCI subsystem for error handling to device
10470 * with SLI-4 interface spec. It is called after PCI bus has been reset to
10471 * restart the PCI card from scratch, as if from a cold-boot. During the
10472 * PCI subsystem error recovery, after the driver returns
10473 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
10474 * recovery and then call this routine before calling the .resume method to
10475 * recover the device. This function will initialize the HBA device, enable
10476 * the interrupt, but it will just put the HBA to offline state without
10477 * passing any I/O traffic.
10480 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10481 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10483 static pci_ers_result_t
10484 lpfc_io_slot_reset_s4(struct pci_dev
*pdev
)
10486 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10487 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10488 struct lpfc_sli
*psli
= &phba
->sli
;
10489 uint32_t intr_mode
;
10491 dev_printk(KERN_INFO
, &pdev
->dev
, "recovering from a slot reset.\n");
10492 if (pci_enable_device_mem(pdev
)) {
10493 printk(KERN_ERR
"lpfc: Cannot re-enable "
10494 "PCI device after reset.\n");
10495 return PCI_ERS_RESULT_DISCONNECT
;
10498 pci_restore_state(pdev
);
10501 * As the new kernel behavior of pci_restore_state() API call clears
10502 * device saved_state flag, need to save the restored state again.
10504 pci_save_state(pdev
);
10506 if (pdev
->is_busmaster
)
10507 pci_set_master(pdev
);
10509 spin_lock_irq(&phba
->hbalock
);
10510 psli
->sli_flag
&= ~LPFC_SLI_ACTIVE
;
10511 spin_unlock_irq(&phba
->hbalock
);
10513 /* Configure and enable interrupt */
10514 intr_mode
= lpfc_sli4_enable_intr(phba
, phba
->intr_mode
);
10515 if (intr_mode
== LPFC_INTR_ERROR
) {
10516 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10517 "2824 Cannot re-enable interrupt after "
10519 return PCI_ERS_RESULT_DISCONNECT
;
10521 phba
->intr_mode
= intr_mode
;
10523 /* Log the current active interrupt mode */
10524 lpfc_log_intr_mode(phba
, phba
->intr_mode
);
10526 return PCI_ERS_RESULT_RECOVERED
;
10530 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
10531 * @pdev: pointer to PCI device
10533 * This routine is called from the PCI subsystem for error handling to device
10534 * with SLI-4 interface spec. It is called when kernel error recovery tells
10535 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
10536 * error recovery. After this call, traffic can start to flow from this device
10540 lpfc_io_resume_s4(struct pci_dev
*pdev
)
10542 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10543 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10546 * In case of slot reset, as function reset is performed through
10547 * mailbox command which needs DMA to be enabled, this operation
10548 * has to be moved to the io resume phase. Taking device offline
10549 * will perform the necessary cleanup.
10551 if (!(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
)) {
10552 /* Perform device reset */
10553 lpfc_offline_prep(phba
, LPFC_MBX_WAIT
);
10554 lpfc_offline(phba
);
10555 lpfc_sli_brdrestart(phba
);
10556 /* Bring the device back online */
10560 /* Clean up Advanced Error Reporting (AER) if needed */
10561 if (phba
->hba_flag
& HBA_AER_ENABLED
)
10562 pci_cleanup_aer_uncorrect_error_status(pdev
);
10566 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
10567 * @pdev: pointer to PCI device
10568 * @pid: pointer to PCI device identifier
10570 * This routine is to be registered to the kernel's PCI subsystem. When an
10571 * Emulex HBA device is presented on PCI bus, the kernel PCI subsystem looks
10572 * at PCI device-specific information of the device and driver to see if the
10573 * driver state that it can support this kind of device. If the match is
10574 * successful, the driver core invokes this routine. This routine dispatches
10575 * the action to the proper SLI-3 or SLI-4 device probing routine, which will
10576 * do all the initialization that it needs to do to handle the HBA device
10580 * 0 - driver can claim the device
10581 * negative value - driver can not claim the device
10584 lpfc_pci_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
10587 struct lpfc_sli_intf intf
;
10589 if (pci_read_config_dword(pdev
, LPFC_SLI_INTF
, &intf
.word0
))
10592 if ((bf_get(lpfc_sli_intf_valid
, &intf
) == LPFC_SLI_INTF_VALID
) &&
10593 (bf_get(lpfc_sli_intf_slirev
, &intf
) == LPFC_SLI_INTF_REV_SLI4
))
10594 rc
= lpfc_pci_probe_one_s4(pdev
, pid
);
10596 rc
= lpfc_pci_probe_one_s3(pdev
, pid
);
10602 * lpfc_pci_remove_one - lpfc PCI func to unreg dev from PCI subsystem
10603 * @pdev: pointer to PCI device
10605 * This routine is to be registered to the kernel's PCI subsystem. When an
10606 * Emulex HBA is removed from PCI bus, the driver core invokes this routine.
10607 * This routine dispatches the action to the proper SLI-3 or SLI-4 device
10608 * remove routine, which will perform all the necessary cleanup for the
10609 * device to be removed from the PCI subsystem properly.
10612 lpfc_pci_remove_one(struct pci_dev
*pdev
)
10614 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10615 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10617 switch (phba
->pci_dev_grp
) {
10618 case LPFC_PCI_DEV_LP
:
10619 lpfc_pci_remove_one_s3(pdev
);
10621 case LPFC_PCI_DEV_OC
:
10622 lpfc_pci_remove_one_s4(pdev
);
10625 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10626 "1424 Invalid PCI device group: 0x%x\n",
10627 phba
->pci_dev_grp
);
10634 * lpfc_pci_suspend_one - lpfc PCI func to suspend dev for power management
10635 * @pdev: pointer to PCI device
10636 * @msg: power management message
10638 * This routine is to be registered to the kernel's PCI subsystem to support
10639 * system Power Management (PM). When PM invokes this method, it dispatches
10640 * the action to the proper SLI-3 or SLI-4 device suspend routine, which will
10641 * suspend the device.
10644 * 0 - driver suspended the device
10648 lpfc_pci_suspend_one(struct pci_dev
*pdev
, pm_message_t msg
)
10650 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10651 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10654 switch (phba
->pci_dev_grp
) {
10655 case LPFC_PCI_DEV_LP
:
10656 rc
= lpfc_pci_suspend_one_s3(pdev
, msg
);
10658 case LPFC_PCI_DEV_OC
:
10659 rc
= lpfc_pci_suspend_one_s4(pdev
, msg
);
10662 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10663 "1425 Invalid PCI device group: 0x%x\n",
10664 phba
->pci_dev_grp
);
10671 * lpfc_pci_resume_one - lpfc PCI func to resume dev for power management
10672 * @pdev: pointer to PCI device
10674 * This routine is to be registered to the kernel's PCI subsystem to support
10675 * system Power Management (PM). When PM invokes this method, it dispatches
10676 * the action to the proper SLI-3 or SLI-4 device resume routine, which will
10677 * resume the device.
10680 * 0 - driver suspended the device
10684 lpfc_pci_resume_one(struct pci_dev
*pdev
)
10686 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10687 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10690 switch (phba
->pci_dev_grp
) {
10691 case LPFC_PCI_DEV_LP
:
10692 rc
= lpfc_pci_resume_one_s3(pdev
);
10694 case LPFC_PCI_DEV_OC
:
10695 rc
= lpfc_pci_resume_one_s4(pdev
);
10698 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10699 "1426 Invalid PCI device group: 0x%x\n",
10700 phba
->pci_dev_grp
);
10707 * lpfc_io_error_detected - lpfc method for handling PCI I/O error
10708 * @pdev: pointer to PCI device.
10709 * @state: the current PCI connection state.
10711 * This routine is registered to the PCI subsystem for error handling. This
10712 * function is called by the PCI subsystem after a PCI bus error affecting
10713 * this device has been detected. When this routine is invoked, it dispatches
10714 * the action to the proper SLI-3 or SLI-4 device error detected handling
10715 * routine, which will perform the proper error detected operation.
10718 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
10719 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10721 static pci_ers_result_t
10722 lpfc_io_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
10724 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10725 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10726 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
10728 switch (phba
->pci_dev_grp
) {
10729 case LPFC_PCI_DEV_LP
:
10730 rc
= lpfc_io_error_detected_s3(pdev
, state
);
10732 case LPFC_PCI_DEV_OC
:
10733 rc
= lpfc_io_error_detected_s4(pdev
, state
);
10736 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10737 "1427 Invalid PCI device group: 0x%x\n",
10738 phba
->pci_dev_grp
);
10745 * lpfc_io_slot_reset - lpfc method for restart PCI dev from scratch
10746 * @pdev: pointer to PCI device.
10748 * This routine is registered to the PCI subsystem for error handling. This
10749 * function is called after PCI bus has been reset to restart the PCI card
10750 * from scratch, as if from a cold-boot. When this routine is invoked, it
10751 * dispatches the action to the proper SLI-3 or SLI-4 device reset handling
10752 * routine, which will perform the proper device reset.
10755 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
10756 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
10758 static pci_ers_result_t
10759 lpfc_io_slot_reset(struct pci_dev
*pdev
)
10761 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10762 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10763 pci_ers_result_t rc
= PCI_ERS_RESULT_DISCONNECT
;
10765 switch (phba
->pci_dev_grp
) {
10766 case LPFC_PCI_DEV_LP
:
10767 rc
= lpfc_io_slot_reset_s3(pdev
);
10769 case LPFC_PCI_DEV_OC
:
10770 rc
= lpfc_io_slot_reset_s4(pdev
);
10773 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10774 "1428 Invalid PCI device group: 0x%x\n",
10775 phba
->pci_dev_grp
);
10782 * lpfc_io_resume - lpfc method for resuming PCI I/O operation
10783 * @pdev: pointer to PCI device
10785 * This routine is registered to the PCI subsystem for error handling. It
10786 * is called when kernel error recovery tells the lpfc driver that it is
10787 * OK to resume normal PCI operation after PCI bus error recovery. When
10788 * this routine is invoked, it dispatches the action to the proper SLI-3
10789 * or SLI-4 device io_resume routine, which will resume the device operation.
10792 lpfc_io_resume(struct pci_dev
*pdev
)
10794 struct Scsi_Host
*shost
= pci_get_drvdata(pdev
);
10795 struct lpfc_hba
*phba
= ((struct lpfc_vport
*)shost
->hostdata
)->phba
;
10797 switch (phba
->pci_dev_grp
) {
10798 case LPFC_PCI_DEV_LP
:
10799 lpfc_io_resume_s3(pdev
);
10801 case LPFC_PCI_DEV_OC
:
10802 lpfc_io_resume_s4(pdev
);
10805 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
10806 "1429 Invalid PCI device group: 0x%x\n",
10807 phba
->pci_dev_grp
);
10813 static struct pci_device_id lpfc_id_table
[] = {
10814 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_VIPER
,
10815 PCI_ANY_ID
, PCI_ANY_ID
, },
10816 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_FIREFLY
,
10817 PCI_ANY_ID
, PCI_ANY_ID
, },
10818 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_THOR
,
10819 PCI_ANY_ID
, PCI_ANY_ID
, },
10820 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PEGASUS
,
10821 PCI_ANY_ID
, PCI_ANY_ID
, },
10822 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_CENTAUR
,
10823 PCI_ANY_ID
, PCI_ANY_ID
, },
10824 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_DRAGONFLY
,
10825 PCI_ANY_ID
, PCI_ANY_ID
, },
10826 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SUPERFLY
,
10827 PCI_ANY_ID
, PCI_ANY_ID
, },
10828 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_RFLY
,
10829 PCI_ANY_ID
, PCI_ANY_ID
, },
10830 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PFLY
,
10831 PCI_ANY_ID
, PCI_ANY_ID
, },
10832 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE
,
10833 PCI_ANY_ID
, PCI_ANY_ID
, },
10834 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_SCSP
,
10835 PCI_ANY_ID
, PCI_ANY_ID
, },
10836 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_NEPTUNE_DCSP
,
10837 PCI_ANY_ID
, PCI_ANY_ID
, },
10838 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS
,
10839 PCI_ANY_ID
, PCI_ANY_ID
, },
10840 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_SCSP
,
10841 PCI_ANY_ID
, PCI_ANY_ID
, },
10842 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HELIOS_DCSP
,
10843 PCI_ANY_ID
, PCI_ANY_ID
, },
10844 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BMID
,
10845 PCI_ANY_ID
, PCI_ANY_ID
, },
10846 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BSMB
,
10847 PCI_ANY_ID
, PCI_ANY_ID
, },
10848 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR
,
10849 PCI_ANY_ID
, PCI_ANY_ID
, },
10850 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_HORNET
,
10851 PCI_ANY_ID
, PCI_ANY_ID
, },
10852 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_SCSP
,
10853 PCI_ANY_ID
, PCI_ANY_ID
, },
10854 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZEPHYR_DCSP
,
10855 PCI_ANY_ID
, PCI_ANY_ID
, },
10856 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZMID
,
10857 PCI_ANY_ID
, PCI_ANY_ID
, },
10858 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_ZSMB
,
10859 PCI_ANY_ID
, PCI_ANY_ID
, },
10860 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_TFLY
,
10861 PCI_ANY_ID
, PCI_ANY_ID
, },
10862 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP101
,
10863 PCI_ANY_ID
, PCI_ANY_ID
, },
10864 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP10000S
,
10865 PCI_ANY_ID
, PCI_ANY_ID
, },
10866 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LP11000S
,
10867 PCI_ANY_ID
, PCI_ANY_ID
, },
10868 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LPE11000S
,
10869 PCI_ANY_ID
, PCI_ANY_ID
, },
10870 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT
,
10871 PCI_ANY_ID
, PCI_ANY_ID
, },
10872 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_MID
,
10873 PCI_ANY_ID
, PCI_ANY_ID
, },
10874 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SMB
,
10875 PCI_ANY_ID
, PCI_ANY_ID
, },
10876 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_DCSP
,
10877 PCI_ANY_ID
, PCI_ANY_ID
, },
10878 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_SCSP
,
10879 PCI_ANY_ID
, PCI_ANY_ID
, },
10880 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SAT_S
,
10881 PCI_ANY_ID
, PCI_ANY_ID
, },
10882 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_VF
,
10883 PCI_ANY_ID
, PCI_ANY_ID
, },
10884 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_PF
,
10885 PCI_ANY_ID
, PCI_ANY_ID
, },
10886 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_PROTEUS_S
,
10887 PCI_ANY_ID
, PCI_ANY_ID
, },
10888 {PCI_VENDOR_ID_SERVERENGINE
, PCI_DEVICE_ID_TIGERSHARK
,
10889 PCI_ANY_ID
, PCI_ANY_ID
, },
10890 {PCI_VENDOR_ID_SERVERENGINE
, PCI_DEVICE_ID_TOMCAT
,
10891 PCI_ANY_ID
, PCI_ANY_ID
, },
10892 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_FALCON
,
10893 PCI_ANY_ID
, PCI_ANY_ID
, },
10894 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_BALIUS
,
10895 PCI_ANY_ID
, PCI_ANY_ID
, },
10896 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FC
,
10897 PCI_ANY_ID
, PCI_ANY_ID
, },
10898 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FCOE
,
10899 PCI_ANY_ID
, PCI_ANY_ID
, },
10900 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FC_VF
,
10901 PCI_ANY_ID
, PCI_ANY_ID
, },
10902 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_LANCER_FCOE_VF
,
10903 PCI_ANY_ID
, PCI_ANY_ID
, },
10904 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SKYHAWK
,
10905 PCI_ANY_ID
, PCI_ANY_ID
, },
10906 {PCI_VENDOR_ID_EMULEX
, PCI_DEVICE_ID_SKYHAWK_VF
,
10907 PCI_ANY_ID
, PCI_ANY_ID
, },
10911 MODULE_DEVICE_TABLE(pci
, lpfc_id_table
);
10913 static const struct pci_error_handlers lpfc_err_handler
= {
10914 .error_detected
= lpfc_io_error_detected
,
10915 .slot_reset
= lpfc_io_slot_reset
,
10916 .resume
= lpfc_io_resume
,
10919 static struct pci_driver lpfc_driver
= {
10920 .name
= LPFC_DRIVER_NAME
,
10921 .id_table
= lpfc_id_table
,
10922 .probe
= lpfc_pci_probe_one
,
10923 .remove
= lpfc_pci_remove_one
,
10924 .suspend
= lpfc_pci_suspend_one
,
10925 .resume
= lpfc_pci_resume_one
,
10926 .err_handler
= &lpfc_err_handler
,
10929 static const struct file_operations lpfc_mgmt_fop
= {
10930 .owner
= THIS_MODULE
,
10933 static struct miscdevice lpfc_mgmt_dev
= {
10934 .minor
= MISC_DYNAMIC_MINOR
,
10935 .name
= "lpfcmgmt",
10936 .fops
= &lpfc_mgmt_fop
,
10940 * lpfc_init - lpfc module initialization routine
10942 * This routine is to be invoked when the lpfc module is loaded into the
10943 * kernel. The special kernel macro module_init() is used to indicate the
10944 * role of this routine to the kernel as lpfc module entry point.
10948 * -ENOMEM - FC attach transport failed
10949 * all others - failed
10957 printk(LPFC_MODULE_DESC
"\n");
10958 printk(LPFC_COPYRIGHT
"\n");
10960 error
= misc_register(&lpfc_mgmt_dev
);
10962 printk(KERN_ERR
"Could not register lpfcmgmt device, "
10963 "misc_register returned with status %d", error
);
10965 if (lpfc_enable_npiv
) {
10966 lpfc_transport_functions
.vport_create
= lpfc_vport_create
;
10967 lpfc_transport_functions
.vport_delete
= lpfc_vport_delete
;
10969 lpfc_transport_template
=
10970 fc_attach_transport(&lpfc_transport_functions
);
10971 if (lpfc_transport_template
== NULL
)
10973 if (lpfc_enable_npiv
) {
10974 lpfc_vport_transport_template
=
10975 fc_attach_transport(&lpfc_vport_transport_functions
);
10976 if (lpfc_vport_transport_template
== NULL
) {
10977 fc_release_transport(lpfc_transport_template
);
10982 /* Initialize in case vector mapping is needed */
10983 lpfc_used_cpu
= NULL
;
10984 lpfc_present_cpu
= 0;
10985 for_each_present_cpu(cpu
)
10986 lpfc_present_cpu
++;
10988 error
= pci_register_driver(&lpfc_driver
);
10990 fc_release_transport(lpfc_transport_template
);
10991 if (lpfc_enable_npiv
)
10992 fc_release_transport(lpfc_vport_transport_template
);
10999 * lpfc_exit - lpfc module removal routine
11001 * This routine is invoked when the lpfc module is removed from the kernel.
11002 * The special kernel macro module_exit() is used to indicate the role of
11003 * this routine to the kernel as lpfc module exit point.
11008 misc_deregister(&lpfc_mgmt_dev
);
11009 pci_unregister_driver(&lpfc_driver
);
11010 fc_release_transport(lpfc_transport_template
);
11011 if (lpfc_enable_npiv
)
11012 fc_release_transport(lpfc_vport_transport_template
);
11013 if (_dump_buf_data
) {
11014 printk(KERN_ERR
"9062 BLKGRD: freeing %lu pages for "
11015 "_dump_buf_data at 0x%p\n",
11016 (1L << _dump_buf_data_order
), _dump_buf_data
);
11017 free_pages((unsigned long)_dump_buf_data
, _dump_buf_data_order
);
11020 if (_dump_buf_dif
) {
11021 printk(KERN_ERR
"9049 BLKGRD: freeing %lu pages for "
11022 "_dump_buf_dif at 0x%p\n",
11023 (1L << _dump_buf_dif_order
), _dump_buf_dif
);
11024 free_pages((unsigned long)_dump_buf_dif
, _dump_buf_dif_order
);
11026 kfree(lpfc_used_cpu
);
11029 module_init(lpfc_init
);
11030 module_exit(lpfc_exit
);
11031 MODULE_LICENSE("GPL");
11032 MODULE_DESCRIPTION(LPFC_MODULE_DESC
);
11033 MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
11034 MODULE_VERSION("0:" LPFC_DRIVER_VERSION
);