1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2024 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_transport_fc.h>
31 #include <scsi/scsi.h>
32 #include <scsi/fc/fc_fs.h>
37 #include "lpfc_sli4.h"
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_compat.h"
47 * lpfc_mbox_rsrc_prep - Prepare a mailbox with DMA buffer memory.
48 * @phba: pointer to lpfc hba data structure.
49 * @mbox: pointer to the driver internal queue element for mailbox command.
51 * A mailbox command consists of the pool memory for the command, @mbox, and
52 * one or more DMA buffers for the data transfer. This routine provides
53 * a standard framework for allocating the dma buffer and assigning to the
54 * @mbox. Callers should cleanup the mbox with a call to
55 * lpfc_mbox_rsrc_cleanup.
57 * The lpfc_mbuf_alloc routine acquires the hbalock so the caller is
58 * responsible to ensure the hbalock is released. Also note that the
59 * driver design is a single dmabuf/mbuf per mbox in the ctx_buf.
63 lpfc_mbox_rsrc_prep(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
65 struct lpfc_dmabuf
*mp
;
67 mp
= kmalloc(sizeof(*mp
), GFP_KERNEL
);
71 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
77 memset(mp
->virt
, 0, LPFC_BPL_SIZE
);
79 /* Initialization only. Driver does not use a list of dmabufs. */
80 INIT_LIST_HEAD(&mp
->list
);
86 * lpfc_mbox_rsrc_cleanup - Free the mailbox DMA buffer and virtual memory.
87 * @phba: pointer to lpfc hba data structure.
88 * @mbox: pointer to the driver internal queue element for mailbox command.
89 * @locked: value that indicates if the hbalock is held (1) or not (0).
91 * A mailbox command consists of the pool memory for the command, @mbox, and
92 * possibly a DMA buffer for the data transfer. This routine provides
93 * a standard framework for releasing any dma buffers and freeing all
94 * memory resources in it as well as releasing the @mbox back to the @phba pool.
95 * Callers should use this routine for cleanup for all mailboxes prepped with
96 * lpfc_mbox_rsrc_prep.
100 lpfc_mbox_rsrc_cleanup(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
,
101 enum lpfc_mbox_ctx locked
)
103 struct lpfc_dmabuf
*mp
;
106 mbox
->ctx_buf
= NULL
;
108 /* Release the generic BPL buffer memory. */
110 if (locked
== MBOX_THD_LOCKED
)
111 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
113 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
117 mempool_free(mbox
, phba
->mbox_mem_pool
);
121 * lpfc_dump_static_vport - Dump HBA's static vport information.
122 * @phba: pointer to lpfc hba data structure.
123 * @pmb: pointer to the driver internal queue element for mailbox command.
124 * @offset: offset for dumping vport info.
126 * The dump mailbox command provides a method for the device driver to obtain
127 * various types of information from the HBA device.
129 * This routine prepares the mailbox command for dumping list of static
130 * vports to be created.
133 lpfc_dump_static_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
,
137 struct lpfc_dmabuf
*mp
;
142 /* Setup to dump vport info region */
143 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
144 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
145 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
146 mb
->un
.varDmp
.entry_index
= offset
;
147 mb
->un
.varDmp
.region_id
= DMP_REGION_VPORT
;
148 mb
->mbxOwner
= OWN_HOST
;
150 /* For SLI3 HBAs data is embedded in mailbox */
151 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
152 mb
->un
.varDmp
.cv
= 1;
153 mb
->un
.varDmp
.word_cnt
= DMP_RSP_SIZE
/sizeof(uint32_t);
157 rc
= lpfc_mbox_rsrc_prep(phba
, pmb
);
159 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
160 "2605 %s: memory allocation failed\n",
166 mb
->un
.varWords
[3] = putPaddrLow(mp
->phys
);
167 mb
->un
.varWords
[4] = putPaddrHigh(mp
->phys
);
168 mb
->un
.varDmp
.sli4_length
= sizeof(struct static_vport_info
);
174 * lpfc_down_link - Bring down HBAs link.
175 * @phba: pointer to lpfc hba data structure.
176 * @pmb: pointer to the driver internal queue element for mailbox command.
178 * This routine prepares a mailbox command to bring down HBA link.
181 lpfc_down_link(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
184 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
186 mb
->mbxCommand
= MBX_DOWN_LINK
;
187 mb
->mbxOwner
= OWN_HOST
;
191 * lpfc_dump_mem - Prepare a mailbox command for reading a region.
192 * @phba: pointer to lpfc hba data structure.
193 * @pmb: pointer to the driver internal queue element for mailbox command.
194 * @offset: offset into the region.
195 * @region_id: config region id.
197 * The dump mailbox command provides a method for the device driver to obtain
198 * various types of information from the HBA device.
200 * This routine prepares the mailbox command for dumping HBA's config region.
203 lpfc_dump_mem(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
, uint16_t offset
,
210 /* Setup to dump VPD region */
211 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
212 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
213 mb
->un
.varDmp
.cv
= 1;
214 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
215 mb
->un
.varDmp
.entry_index
= offset
;
216 mb
->un
.varDmp
.region_id
= region_id
;
217 mb
->un
.varDmp
.word_cnt
= (DMP_RSP_SIZE
/ sizeof (uint32_t));
218 mb
->un
.varDmp
.co
= 0;
219 mb
->un
.varDmp
.resp_offset
= 0;
220 mb
->mbxOwner
= OWN_HOST
;
225 * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
226 * @phba: pointer to lpfc hba data structure.
227 * @pmb: pointer to the driver internal queue element for mailbox command.
229 * This function create a dump memory mailbox command to dump wake up
233 lpfc_dump_wakeup_param(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
239 /* Setup to dump VPD region */
240 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
241 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
242 mb
->mbxOwner
= OWN_HOST
;
243 mb
->un
.varDmp
.cv
= 1;
244 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
245 if (phba
->sli_rev
< LPFC_SLI_REV4
)
246 mb
->un
.varDmp
.entry_index
= 0;
247 mb
->un
.varDmp
.region_id
= WAKE_UP_PARMS_REGION_ID
;
248 mb
->un
.varDmp
.word_cnt
= WAKE_UP_PARMS_WORD_SIZE
;
249 mb
->un
.varDmp
.co
= 0;
250 mb
->un
.varDmp
.resp_offset
= 0;
255 * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
256 * @phba: pointer to lpfc hba data structure.
257 * @pmb: pointer to the driver internal queue element for mailbox command.
259 * The read NVRAM mailbox command returns the HBA's non-volatile parameters
260 * that are used as defaults when the Fibre Channel link is brought on-line.
262 * This routine prepares the mailbox command for reading information stored
263 * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
266 lpfc_read_nv(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
271 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
272 mb
->mbxCommand
= MBX_READ_NV
;
273 mb
->mbxOwner
= OWN_HOST
;
278 * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
279 * @phba: pointer to lpfc hba data structure.
280 * @pmb: pointer to the driver internal queue element for mailbox command.
281 * @ring: ring number for the asynchronous event to be configured.
283 * The asynchronous event enable mailbox command is used to enable the
284 * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
285 * specifies the default ring to which events are posted.
287 * This routine prepares the mailbox command for enabling HBA asynchronous
288 * event support on a IOCB ring.
291 lpfc_config_async(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
,
297 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
298 mb
->mbxCommand
= MBX_ASYNCEVT_ENABLE
;
299 mb
->un
.varCfgAsyncEvent
.ring
= ring
;
300 mb
->mbxOwner
= OWN_HOST
;
305 * lpfc_heart_beat - Prepare a mailbox command for heart beat
306 * @phba: pointer to lpfc hba data structure.
307 * @pmb: pointer to the driver internal queue element for mailbox command.
309 * The heart beat mailbox command is used to detect an unresponsive HBA, which
310 * is defined as any device where no error attention is sent and both mailbox
311 * and rings are not processed.
313 * This routine prepares the mailbox command for issuing a heart beat in the
314 * form of mailbox command to the HBA. The timely completion of the heart
315 * beat mailbox command indicates the health of the HBA.
318 lpfc_heart_beat(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
323 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
324 mb
->mbxCommand
= MBX_HEARTBEAT
;
325 mb
->mbxOwner
= OWN_HOST
;
330 * lpfc_read_topology - Prepare a mailbox command for reading HBA topology
331 * @phba: pointer to lpfc hba data structure.
332 * @pmb: pointer to the driver internal queue element for mailbox command.
333 * @mp: DMA buffer memory for reading the link attention information into.
335 * The read topology mailbox command is issued to read the link topology
336 * information indicated by the HBA port when the Link Event bit of the Host
337 * Attention (HSTATT) register is set to 1 (For SLI-3) or when an FC Link
338 * Attention ACQE is received from the port (For SLI-4). A Link Event
339 * Attention occurs based on an exception detected at the Fibre Channel link
342 * This routine prepares the mailbox command for reading HBA link topology
343 * information. A DMA memory has been set aside and address passed to the
344 * HBA through @mp for the HBA to DMA link attention information into the
345 * memory as part of the execution of the mailbox command.
348 * 0 - Success (currently always return 0)
351 lpfc_read_topology(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
,
352 struct lpfc_dmabuf
*mp
)
357 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
359 INIT_LIST_HEAD(&mp
->list
);
360 mb
->mbxCommand
= MBX_READ_TOPOLOGY
;
361 mb
->un
.varReadTop
.lilpBde64
.tus
.f
.bdeSize
= LPFC_ALPA_MAP_SIZE
;
362 mb
->un
.varReadTop
.lilpBde64
.addrHigh
= putPaddrHigh(mp
->phys
);
363 mb
->un
.varReadTop
.lilpBde64
.addrLow
= putPaddrLow(mp
->phys
);
365 /* Save address for later completion and set the owner to host so that
366 * the FW knows this mailbox is available for processing.
369 mb
->mbxOwner
= OWN_HOST
;
374 * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
375 * @phba: pointer to lpfc hba data structure.
376 * @pmb: pointer to the driver internal queue element for mailbox command.
378 * The clear link attention mailbox command is issued to clear the link event
379 * attention condition indicated by the Link Event bit of the Host Attention
380 * (HSTATT) register. The link event attention condition is cleared only if
381 * the event tag specified matches that of the current link event counter.
382 * The current event tag is read using the read link attention event mailbox
385 * This routine prepares the mailbox command for clearing HBA link attention
389 lpfc_clear_la(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
394 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
396 mb
->un
.varClearLA
.eventTag
= phba
->fc_eventTag
;
397 mb
->mbxCommand
= MBX_CLEAR_LA
;
398 mb
->mbxOwner
= OWN_HOST
;
403 * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
404 * @phba: pointer to lpfc hba data structure.
405 * @pmb: pointer to the driver internal queue element for mailbox command.
407 * The configure link mailbox command is used before the initialize link
408 * mailbox command to override default value and to configure link-oriented
409 * parameters such as DID address and various timers. Typically, this
410 * command would be used after an F_Port login to set the returned DID address
411 * and the fabric timeout values. This command is not valid before a configure
412 * port command has configured the HBA port.
414 * This routine prepares the mailbox command for configuring link on a HBA.
417 lpfc_config_link(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
419 struct lpfc_vport
*vport
= phba
->pport
;
420 MAILBOX_t
*mb
= &pmb
->u
.mb
;
421 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
424 * SLI-2, Coalescing Response Feature.
426 if (phba
->cfg_cr_delay
&& (phba
->sli_rev
< LPFC_SLI_REV4
)) {
427 mb
->un
.varCfgLnk
.cr
= 1;
428 mb
->un
.varCfgLnk
.ci
= 1;
429 mb
->un
.varCfgLnk
.cr_delay
= phba
->cfg_cr_delay
;
430 mb
->un
.varCfgLnk
.cr_count
= phba
->cfg_cr_count
;
433 mb
->un
.varCfgLnk
.myId
= vport
->fc_myDID
;
434 mb
->un
.varCfgLnk
.edtov
= phba
->fc_edtov
;
435 mb
->un
.varCfgLnk
.arbtov
= phba
->fc_arbtov
;
436 mb
->un
.varCfgLnk
.ratov
= phba
->fc_ratov
;
437 mb
->un
.varCfgLnk
.rttov
= phba
->fc_rttov
;
438 mb
->un
.varCfgLnk
.altov
= phba
->fc_altov
;
439 mb
->un
.varCfgLnk
.crtov
= phba
->fc_crtov
;
440 mb
->un
.varCfgLnk
.cscn
= 0;
441 if (phba
->bbcredit_support
&& phba
->cfg_enable_bbcr
) {
442 mb
->un
.varCfgLnk
.cscn
= 1;
443 mb
->un
.varCfgLnk
.bbscn
= bf_get(lpfc_bbscn_def
,
444 &phba
->sli4_hba
.bbscn_params
);
447 if (phba
->cfg_ack0
&& (phba
->sli_rev
< LPFC_SLI_REV4
))
448 mb
->un
.varCfgLnk
.ack0_enable
= 1;
450 mb
->mbxCommand
= MBX_CONFIG_LINK
;
451 mb
->mbxOwner
= OWN_HOST
;
456 * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
457 * @phba: pointer to lpfc hba data structure.
458 * @pmb: pointer to the driver internal queue element for mailbox command.
460 * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
461 * MSI-X multi-message interrupt vector association to interrupt attention
469 lpfc_config_msi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
471 MAILBOX_t
*mb
= &pmb
->u
.mb
;
472 uint32_t attentionConditions
[2];
475 if (phba
->cfg_use_msi
!= 2) {
476 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
477 "0475 Not configured for supporting MSI-X "
478 "cfg_use_msi: 0x%x\n", phba
->cfg_use_msi
);
482 if (phba
->sli_rev
< 3) {
483 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
484 "0476 HBA not supporting SLI-3 or later "
485 "SLI Revision: 0x%x\n", phba
->sli_rev
);
489 /* Clear mailbox command fields */
490 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
493 * SLI-3, Message Signaled Interrupt Feature.
496 /* Multi-message attention configuration */
497 attentionConditions
[0] = (HA_R0ATT
| HA_R1ATT
| HA_R2ATT
| HA_ERATT
|
499 attentionConditions
[1] = 0;
501 mb
->un
.varCfgMSI
.attentionConditions
[0] = attentionConditions
[0];
502 mb
->un
.varCfgMSI
.attentionConditions
[1] = attentionConditions
[1];
505 * Set up message number to HA bit association
507 #ifdef __BIG_ENDIAN_BITFIELD
509 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R0_POS
] = 1;
510 /* RA1 (Other Protocol Extra Ring) */
511 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R1_POS
] = 1;
512 #else /* __LITTLE_ENDIAN_BITFIELD */
514 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R0_POS
^3] = 1;
515 /* RA1 (Other Protocol Extra Ring) */
516 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R1_POS
^3] = 1;
518 /* Multi-message interrupt autoclear configuration*/
519 mb
->un
.varCfgMSI
.autoClearHA
[0] = attentionConditions
[0];
520 mb
->un
.varCfgMSI
.autoClearHA
[1] = attentionConditions
[1];
522 /* For now, HBA autoclear does not work reliably, disable it */
523 mb
->un
.varCfgMSI
.autoClearHA
[0] = 0;
524 mb
->un
.varCfgMSI
.autoClearHA
[1] = 0;
526 /* Set command and owner bit */
527 mb
->mbxCommand
= MBX_CONFIG_MSI
;
528 mb
->mbxOwner
= OWN_HOST
;
534 * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
535 * @phba: pointer to lpfc hba data structure.
536 * @pmb: pointer to the driver internal queue element for mailbox command.
537 * @topology: the link topology for the link to be initialized to.
538 * @linkspeed: the link speed for the link to be initialized to.
540 * The initialize link mailbox command is used to initialize the Fibre
541 * Channel link. This command must follow a configure port command that
542 * establishes the mode of operation.
544 * This routine prepares the mailbox command for initializing link on a HBA
545 * with the specified link topology and speed.
548 lpfc_init_link(struct lpfc_hba
* phba
,
549 LPFC_MBOXQ_t
* pmb
, uint32_t topology
, uint32_t linkspeed
)
555 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
558 case FLAGS_TOPOLOGY_MODE_LOOP_PT
:
559 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_LOOP
;
560 mb
->un
.varInitLnk
.link_flags
|= FLAGS_TOPOLOGY_FAILOVER
;
562 case FLAGS_TOPOLOGY_MODE_PT_PT
:
563 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_PT_PT
;
565 case FLAGS_TOPOLOGY_MODE_LOOP
:
566 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_LOOP
;
568 case FLAGS_TOPOLOGY_MODE_PT_LOOP
:
569 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_PT_PT
;
570 mb
->un
.varInitLnk
.link_flags
|= FLAGS_TOPOLOGY_FAILOVER
;
573 mb
->un
.varInitLnk
.link_flags
= FLAGS_LOCAL_LB
;
577 /* Topology handling for ASIC_GEN_NUM 0xC and later */
578 if ((phba
->sli4_hba
.pc_sli4_params
.sli_family
== LPFC_SLI_INTF_FAMILY_G6
||
579 phba
->sli4_hba
.pc_sli4_params
.if_type
== LPFC_SLI_INTF_IF_TYPE_6
) &&
580 !(phba
->sli4_hba
.pc_sli4_params
.pls
) &&
581 mb
->un
.varInitLnk
.link_flags
& FLAGS_TOPOLOGY_MODE_LOOP
) {
582 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_PT_PT
;
583 phba
->cfg_topology
= FLAGS_TOPOLOGY_MODE_PT_PT
;
586 /* Enable asynchronous ABTS responses from firmware */
587 if (phba
->sli_rev
== LPFC_SLI_REV3
&& !phba
->cfg_fcp_wait_abts_rsp
)
588 mb
->un
.varInitLnk
.link_flags
|= FLAGS_IMED_ABORT
;
591 * Setting up the link speed
594 if (vpd
->rev
.feaLevelHigh
>= 0x02){
596 case LPFC_USER_LINK_SPEED_1G
:
597 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
598 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_1G
;
600 case LPFC_USER_LINK_SPEED_2G
:
601 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
602 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_2G
;
604 case LPFC_USER_LINK_SPEED_4G
:
605 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
606 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_4G
;
608 case LPFC_USER_LINK_SPEED_8G
:
609 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
610 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_8G
;
612 case LPFC_USER_LINK_SPEED_10G
:
613 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
614 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_10G
;
616 case LPFC_USER_LINK_SPEED_16G
:
617 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
618 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_16G
;
620 case LPFC_USER_LINK_SPEED_32G
:
621 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
622 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_32G
;
624 case LPFC_USER_LINK_SPEED_64G
:
625 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
626 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_64G
;
628 case LPFC_USER_LINK_SPEED_AUTO
:
630 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_AUTO
;
636 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_AUTO
;
638 mb
->mbxCommand
= (volatile uint8_t)MBX_INIT_LINK
;
639 mb
->mbxOwner
= OWN_HOST
;
640 mb
->un
.varInitLnk
.fabric_AL_PA
= phba
->fc_pref_ALPA
;
645 * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
646 * @phba: pointer to lpfc hba data structure.
647 * @pmb: pointer to the driver internal queue element for mailbox command.
648 * @vpi: virtual N_Port identifier.
650 * The read service parameter mailbox command is used to read the HBA port
651 * service parameters. The service parameters are read into the buffer
652 * specified directly by a BDE in the mailbox command. These service
653 * parameters may then be used to build the payload of an N_Port/F_POrt
654 * login request and reply (LOGI/ACC).
656 * This routine prepares the mailbox command for reading HBA port service
657 * parameters. The DMA memory is allocated in this function and the addresses
658 * are populated into the mailbox command for the HBA to DMA the service
663 * 1 - DMA memory allocation failed
666 lpfc_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
, int vpi
)
668 struct lpfc_dmabuf
*mp
;
672 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
674 /* Get a buffer to hold the HBAs Service Parameters */
675 rc
= lpfc_mbox_rsrc_prep(phba
, pmb
);
677 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
678 "0301 READ_SPARAM: no buffers\n");
684 mb
->mbxOwner
= OWN_HOST
;
685 mb
->mbxCommand
= MBX_READ_SPARM64
;
686 mb
->un
.varRdSparm
.un
.sp64
.tus
.f
.bdeSize
= sizeof (struct serv_parm
);
687 mb
->un
.varRdSparm
.un
.sp64
.addrHigh
= putPaddrHigh(mp
->phys
);
688 mb
->un
.varRdSparm
.un
.sp64
.addrLow
= putPaddrLow(mp
->phys
);
689 if (phba
->sli_rev
>= LPFC_SLI_REV3
)
690 mb
->un
.varRdSparm
.vpi
= phba
->vpi_ids
[vpi
];
696 * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
697 * @phba: pointer to lpfc hba data structure.
698 * @vpi: virtual N_Port identifier.
699 * @did: remote port identifier.
700 * @pmb: pointer to the driver internal queue element for mailbox command.
702 * The unregister DID mailbox command is used to unregister an N_Port/F_Port
703 * login for an unknown RPI by specifying the DID of a remote port. This
704 * command frees an RPI context in the HBA port. This has the effect of
705 * performing an implicit N_Port/F_Port logout.
707 * This routine prepares the mailbox command for unregistering a remote
708 * N_Port/F_Port (DID) login.
711 lpfc_unreg_did(struct lpfc_hba
* phba
, uint16_t vpi
, uint32_t did
,
717 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
719 mb
->un
.varUnregDID
.did
= did
;
720 mb
->un
.varUnregDID
.vpi
= vpi
;
721 if ((vpi
!= 0xffff) &&
722 (phba
->sli_rev
== LPFC_SLI_REV4
))
723 mb
->un
.varUnregDID
.vpi
= phba
->vpi_ids
[vpi
];
725 mb
->mbxCommand
= MBX_UNREG_D_ID
;
726 mb
->mbxOwner
= OWN_HOST
;
731 * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
732 * @phba: pointer to lpfc hba data structure.
733 * @pmb: pointer to the driver internal queue element for mailbox command.
735 * The read configuration mailbox command is used to read the HBA port
736 * configuration parameters. This mailbox command provides a method for
737 * seeing any parameters that may have changed via various configuration
740 * This routine prepares the mailbox command for reading out HBA configuration
744 lpfc_read_config(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
749 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
751 mb
->mbxCommand
= MBX_READ_CONFIG
;
752 mb
->mbxOwner
= OWN_HOST
;
757 * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
758 * @phba: pointer to lpfc hba data structure.
759 * @pmb: pointer to the driver internal queue element for mailbox command.
761 * The read link status mailbox command is used to read the link status from
762 * the HBA. Link status includes all link-related error counters. These
763 * counters are maintained by the HBA and originated in the link hardware
764 * unit. Note that all of these counters wrap.
766 * This routine prepares the mailbox command for reading out HBA link status.
769 lpfc_read_lnk_stat(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
774 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
776 mb
->mbxCommand
= MBX_READ_LNK_STAT
;
777 mb
->mbxOwner
= OWN_HOST
;
782 * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
783 * @phba: pointer to lpfc hba data structure.
784 * @vpi: virtual N_Port identifier.
785 * @did: remote port identifier.
786 * @param: pointer to memory holding the server parameters.
787 * @pmb: pointer to the driver internal queue element for mailbox command.
788 * @rpi: the rpi to use in the registration (usually only used for SLI4.
790 * The registration login mailbox command is used to register an N_Port or
791 * F_Port login. This registration allows the HBA to cache the remote N_Port
792 * service parameters internally and thereby make the appropriate FC-2
793 * decisions. The remote port service parameters are handed off by the driver
794 * to the HBA using a descriptor entry that directly identifies a buffer in
795 * host memory. In exchange, the HBA returns an RPI identifier.
797 * This routine prepares the mailbox command for registering remote port login.
798 * The function allocates DMA buffer for passing the service parameters to the
799 * HBA with the mailbox command.
803 * 1 - DMA memory allocation failed
806 lpfc_reg_rpi(struct lpfc_hba
*phba
, uint16_t vpi
, uint32_t did
,
807 uint8_t *param
, LPFC_MBOXQ_t
*pmb
, uint16_t rpi
)
809 MAILBOX_t
*mb
= &pmb
->u
.mb
;
811 struct lpfc_dmabuf
*mp
;
814 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
816 mb
->un
.varRegLogin
.rpi
= 0;
817 if (phba
->sli_rev
== LPFC_SLI_REV4
)
818 mb
->un
.varRegLogin
.rpi
= phba
->sli4_hba
.rpi_ids
[rpi
];
819 if (phba
->sli_rev
>= LPFC_SLI_REV3
)
820 mb
->un
.varRegLogin
.vpi
= phba
->vpi_ids
[vpi
];
821 mb
->un
.varRegLogin
.did
= did
;
822 mb
->mbxOwner
= OWN_HOST
;
824 /* Get a buffer to hold NPorts Service Parameters */
825 rc
= lpfc_mbox_rsrc_prep(phba
, pmb
);
827 mb
->mbxCommand
= MBX_REG_LOGIN64
;
828 /* REG_LOGIN: no buffers */
829 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
830 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
831 "rpi x%x\n", vpi
, did
, rpi
);
835 /* Copy param's into a new buffer */
838 memcpy(sparam
, param
, sizeof (struct serv_parm
));
840 /* Finish initializing the mailbox. */
841 mb
->mbxCommand
= MBX_REG_LOGIN64
;
842 mb
->un
.varRegLogin
.un
.sp64
.tus
.f
.bdeSize
= sizeof (struct serv_parm
);
843 mb
->un
.varRegLogin
.un
.sp64
.addrHigh
= putPaddrHigh(mp
->phys
);
844 mb
->un
.varRegLogin
.un
.sp64
.addrLow
= putPaddrLow(mp
->phys
);
850 * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
851 * @phba: pointer to lpfc hba data structure.
852 * @vpi: virtual N_Port identifier.
853 * @rpi: remote port identifier
854 * @pmb: pointer to the driver internal queue element for mailbox command.
856 * The unregistration login mailbox command is used to unregister an N_Port
857 * or F_Port login. This command frees an RPI context in the HBA. It has the
858 * effect of performing an implicit N_Port/F_Port logout.
860 * This routine prepares the mailbox command for unregistering remote port
863 * For SLI4 ports, the rpi passed to this function must be the physical
864 * rpi value, not the logical index.
867 lpfc_unreg_login(struct lpfc_hba
*phba
, uint16_t vpi
, uint32_t rpi
,
873 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
875 mb
->un
.varUnregLogin
.rpi
= rpi
;
876 mb
->un
.varUnregLogin
.rsvd1
= 0;
877 if (phba
->sli_rev
>= LPFC_SLI_REV3
)
878 mb
->un
.varUnregLogin
.vpi
= phba
->vpi_ids
[vpi
];
880 mb
->mbxCommand
= MBX_UNREG_LOGIN
;
881 mb
->mbxOwner
= OWN_HOST
;
887 * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA.
888 * @vport: pointer to a vport object.
890 * This routine sends mailbox command to unregister all active RPIs for
894 lpfc_sli4_unreg_all_rpis(struct lpfc_vport
*vport
)
896 struct lpfc_hba
*phba
= vport
->phba
;
900 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
903 * For SLI4 functions, the rpi field is overloaded for
904 * the vport context unreg all. This routine passes
905 * 0 for the rpi field in lpfc_unreg_login for compatibility
906 * with SLI3 and then overrides the rpi field with the
907 * expected value for SLI4.
909 lpfc_unreg_login(phba
, vport
->vpi
, phba
->vpi_ids
[vport
->vpi
],
911 mbox
->u
.mb
.un
.varUnregLogin
.rsvd1
= 0x4000;
913 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
914 mbox
->ctx_ndlp
= NULL
;
915 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
916 if (rc
== MBX_NOT_FINISHED
)
917 mempool_free(mbox
, phba
->mbox_mem_pool
);
922 * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
923 * @vport: pointer to a vport object.
924 * @pmb: pointer to the driver internal queue element for mailbox command.
926 * The registration vport identifier mailbox command is used to activate a
927 * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
928 * N_Port_ID against the information in the selected virtual N_Port context
929 * block and marks it active to allow normal processing of IOCB commands and
930 * received unsolicited exchanges.
932 * This routine prepares the mailbox command for registering a virtual N_Port.
935 lpfc_reg_vpi(struct lpfc_vport
*vport
, LPFC_MBOXQ_t
*pmb
)
937 MAILBOX_t
*mb
= &pmb
->u
.mb
;
938 struct lpfc_hba
*phba
= vport
->phba
;
940 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
942 * Set the re-reg VPI bit for f/w to update the MAC address.
944 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
945 !test_bit(FC_VPORT_NEEDS_REG_VPI
, &vport
->fc_flag
))
946 mb
->un
.varRegVpi
.upd
= 1;
948 mb
->un
.varRegVpi
.vpi
= phba
->vpi_ids
[vport
->vpi
];
949 mb
->un
.varRegVpi
.sid
= vport
->fc_myDID
;
950 if (phba
->sli_rev
== LPFC_SLI_REV4
)
951 mb
->un
.varRegVpi
.vfi
= phba
->sli4_hba
.vfi_ids
[vport
->vfi
];
953 mb
->un
.varRegVpi
.vfi
= vport
->vfi
+ vport
->phba
->vfi_base
;
954 memcpy(mb
->un
.varRegVpi
.wwn
, &vport
->fc_portname
,
955 sizeof(struct lpfc_name
));
956 mb
->un
.varRegVpi
.wwn
[0] = cpu_to_le32(mb
->un
.varRegVpi
.wwn
[0]);
957 mb
->un
.varRegVpi
.wwn
[1] = cpu_to_le32(mb
->un
.varRegVpi
.wwn
[1]);
959 mb
->mbxCommand
= MBX_REG_VPI
;
960 mb
->mbxOwner
= OWN_HOST
;
966 * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
967 * @phba: pointer to lpfc hba data structure.
968 * @vpi: virtual N_Port identifier.
969 * @pmb: pointer to the driver internal queue element for mailbox command.
971 * The unregistration vport identifier mailbox command is used to inactivate
972 * a virtual N_Port. The driver must have logged out and unregistered all
973 * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
974 * unregisters any default RPIs associated with the specified vpi, aborting
975 * any active exchanges. The HBA will post the mailbox response after making
976 * the virtual N_Port inactive.
978 * This routine prepares the mailbox command for unregistering a virtual
982 lpfc_unreg_vpi(struct lpfc_hba
*phba
, uint16_t vpi
, LPFC_MBOXQ_t
*pmb
)
984 MAILBOX_t
*mb
= &pmb
->u
.mb
;
985 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
987 if (phba
->sli_rev
== LPFC_SLI_REV3
)
988 mb
->un
.varUnregVpi
.vpi
= phba
->vpi_ids
[vpi
];
989 else if (phba
->sli_rev
>= LPFC_SLI_REV4
)
990 mb
->un
.varUnregVpi
.sli4_vpi
= phba
->vpi_ids
[vpi
];
992 mb
->mbxCommand
= MBX_UNREG_VPI
;
993 mb
->mbxOwner
= OWN_HOST
;
999 * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
1000 * @phba: pointer to lpfc hba data structure.
1002 * This routine sets up and initializes the IOCB rings in the Port Control
1006 lpfc_config_pcb_setup(struct lpfc_hba
* phba
)
1008 struct lpfc_sli
*psli
= &phba
->sli
;
1009 struct lpfc_sli_ring
*pring
;
1010 PCB_t
*pcbp
= phba
->pcb
;
1011 dma_addr_t pdma_addr
;
1013 uint32_t iocbCnt
= 0;
1016 pcbp
->maxRing
= (psli
->num_rings
- 1);
1018 for (i
= 0; i
< psli
->num_rings
; i
++) {
1019 pring
= &psli
->sli3_ring
[i
];
1021 pring
->sli
.sli3
.sizeCiocb
=
1022 phba
->sli_rev
== 3 ? SLI3_IOCB_CMD_SIZE
:
1024 pring
->sli
.sli3
.sizeRiocb
=
1025 phba
->sli_rev
== 3 ? SLI3_IOCB_RSP_SIZE
:
1027 /* A ring MUST have both cmd and rsp entries defined to be
1029 if ((pring
->sli
.sli3
.numCiocb
== 0) ||
1030 (pring
->sli
.sli3
.numRiocb
== 0)) {
1031 pcbp
->rdsc
[i
].cmdEntries
= 0;
1032 pcbp
->rdsc
[i
].rspEntries
= 0;
1033 pcbp
->rdsc
[i
].cmdAddrHigh
= 0;
1034 pcbp
->rdsc
[i
].rspAddrHigh
= 0;
1035 pcbp
->rdsc
[i
].cmdAddrLow
= 0;
1036 pcbp
->rdsc
[i
].rspAddrLow
= 0;
1037 pring
->sli
.sli3
.cmdringaddr
= NULL
;
1038 pring
->sli
.sli3
.rspringaddr
= NULL
;
1041 /* Command ring setup for ring */
1042 pring
->sli
.sli3
.cmdringaddr
= (void *)&phba
->IOCBs
[iocbCnt
];
1043 pcbp
->rdsc
[i
].cmdEntries
= pring
->sli
.sli3
.numCiocb
;
1045 offset
= (uint8_t *) &phba
->IOCBs
[iocbCnt
] -
1046 (uint8_t *) phba
->slim2p
.virt
;
1047 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1048 pcbp
->rdsc
[i
].cmdAddrHigh
= putPaddrHigh(pdma_addr
);
1049 pcbp
->rdsc
[i
].cmdAddrLow
= putPaddrLow(pdma_addr
);
1050 iocbCnt
+= pring
->sli
.sli3
.numCiocb
;
1052 /* Response ring setup for ring */
1053 pring
->sli
.sli3
.rspringaddr
= (void *) &phba
->IOCBs
[iocbCnt
];
1055 pcbp
->rdsc
[i
].rspEntries
= pring
->sli
.sli3
.numRiocb
;
1056 offset
= (uint8_t *)&phba
->IOCBs
[iocbCnt
] -
1057 (uint8_t *)phba
->slim2p
.virt
;
1058 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1059 pcbp
->rdsc
[i
].rspAddrHigh
= putPaddrHigh(pdma_addr
);
1060 pcbp
->rdsc
[i
].rspAddrLow
= putPaddrLow(pdma_addr
);
1061 iocbCnt
+= pring
->sli
.sli3
.numRiocb
;
1066 * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
1067 * @phba: pointer to lpfc hba data structure.
1068 * @pmb: pointer to the driver internal queue element for mailbox command.
1070 * The read revision mailbox command is used to read the revision levels of
1071 * the HBA components. These components include hardware units, resident
1072 * firmware, and available firmware. HBAs that supports SLI-3 mode of
1073 * operation provide different response information depending on the version
1074 * requested by the driver.
1076 * This routine prepares the mailbox command for reading HBA revision
1080 lpfc_read_rev(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
1082 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1083 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
1084 mb
->un
.varRdRev
.cv
= 1;
1085 mb
->un
.varRdRev
.v3req
= 1; /* Request SLI3 info */
1086 mb
->mbxCommand
= MBX_READ_REV
;
1087 mb
->mbxOwner
= OWN_HOST
;
1092 lpfc_sli4_swap_str(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1094 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1095 struct lpfc_mqe
*mqe
;
1097 switch (mb
->mbxCommand
) {
1100 lpfc_sli_pcimem_bcopy(mqe
->un
.read_rev
.fw_name
,
1101 mqe
->un
.read_rev
.fw_name
, 16);
1102 lpfc_sli_pcimem_bcopy(mqe
->un
.read_rev
.ulp_fw_name
,
1103 mqe
->un
.read_rev
.ulp_fw_name
, 16);
1112 * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
1113 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1114 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1116 * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
1117 * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
1118 * the Sequence Length Test using the fields in the Selection Profile 2
1119 * extension in words 20:31.
1122 lpfc_build_hbq_profile2(struct config_hbq_var
*hbqmb
,
1123 struct lpfc_hbq_init
*hbq_desc
)
1125 hbqmb
->profiles
.profile2
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
1126 hbqmb
->profiles
.profile2
.maxlen
= hbq_desc
->maxlen
;
1127 hbqmb
->profiles
.profile2
.seqlenoff
= hbq_desc
->seqlenoff
;
1131 * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
1132 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1133 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1135 * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
1136 * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
1137 * the Sequence Length Test and Byte Field Test using the fields in the
1138 * Selection Profile 3 extension in words 20:31.
1141 lpfc_build_hbq_profile3(struct config_hbq_var
*hbqmb
,
1142 struct lpfc_hbq_init
*hbq_desc
)
1144 hbqmb
->profiles
.profile3
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
1145 hbqmb
->profiles
.profile3
.maxlen
= hbq_desc
->maxlen
;
1146 hbqmb
->profiles
.profile3
.cmdcodeoff
= hbq_desc
->cmdcodeoff
;
1147 hbqmb
->profiles
.profile3
.seqlenoff
= hbq_desc
->seqlenoff
;
1148 memcpy(&hbqmb
->profiles
.profile3
.cmdmatch
, hbq_desc
->cmdmatch
,
1149 sizeof(hbqmb
->profiles
.profile3
.cmdmatch
));
1153 * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
1154 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1155 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1157 * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
1158 * HBA tests the initial frame of an incoming sequence using the frame's
1159 * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
1160 * and Byte Field Test using the fields in the Selection Profile 5 extension
1164 lpfc_build_hbq_profile5(struct config_hbq_var
*hbqmb
,
1165 struct lpfc_hbq_init
*hbq_desc
)
1167 hbqmb
->profiles
.profile5
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
1168 hbqmb
->profiles
.profile5
.maxlen
= hbq_desc
->maxlen
;
1169 hbqmb
->profiles
.profile5
.cmdcodeoff
= hbq_desc
->cmdcodeoff
;
1170 hbqmb
->profiles
.profile5
.seqlenoff
= hbq_desc
->seqlenoff
;
1171 memcpy(&hbqmb
->profiles
.profile5
.cmdmatch
, hbq_desc
->cmdmatch
,
1172 sizeof(hbqmb
->profiles
.profile5
.cmdmatch
));
1176 * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
1177 * @phba: pointer to lpfc hba data structure.
1178 * @id: HBQ identifier.
1179 * @hbq_desc: pointer to the HBA descriptor data structure.
1180 * @hbq_entry_index: index of the HBQ entry data structures.
1181 * @pmb: pointer to the driver internal queue element for mailbox command.
1183 * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
1184 * an HBQ. The configuration binds events that require buffers to a particular
1185 * ring and HBQ based on a selection profile.
1187 * This routine prepares the mailbox command for configuring an HBQ.
1190 lpfc_config_hbq(struct lpfc_hba
*phba
, uint32_t id
,
1191 struct lpfc_hbq_init
*hbq_desc
,
1192 uint32_t hbq_entry_index
, LPFC_MBOXQ_t
*pmb
)
1195 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1196 struct config_hbq_var
*hbqmb
= &mb
->un
.varCfgHbq
;
1198 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
1200 hbqmb
->entry_count
= hbq_desc
->entry_count
; /* # entries in HBQ */
1201 hbqmb
->recvNotify
= hbq_desc
->rn
; /* Receive
1203 hbqmb
->numMask
= hbq_desc
->mask_count
; /* # R_CTL/TYPE masks
1204 * # in words 0-19 */
1205 hbqmb
->profile
= hbq_desc
->profile
; /* Selection profile:
1208 hbqmb
->ringMask
= hbq_desc
->ring_mask
; /* Binds HBQ to a ring
1211 hbqmb
->headerLen
= hbq_desc
->headerLen
; /* 0 if not profile 4
1213 hbqmb
->logEntry
= hbq_desc
->logEntry
; /* Set to 1 if this
1217 hbqmb
->hbqaddrLow
= putPaddrLow(phba
->hbqslimp
.phys
) +
1218 hbq_entry_index
* sizeof(struct lpfc_hbq_entry
);
1219 hbqmb
->hbqaddrHigh
= putPaddrHigh(phba
->hbqslimp
.phys
);
1221 mb
->mbxCommand
= MBX_CONFIG_HBQ
;
1222 mb
->mbxOwner
= OWN_HOST
;
1224 /* Copy info for profiles 2,3,5. Other
1225 * profiles this area is reserved
1227 if (hbq_desc
->profile
== 2)
1228 lpfc_build_hbq_profile2(hbqmb
, hbq_desc
);
1229 else if (hbq_desc
->profile
== 3)
1230 lpfc_build_hbq_profile3(hbqmb
, hbq_desc
);
1231 else if (hbq_desc
->profile
== 5)
1232 lpfc_build_hbq_profile5(hbqmb
, hbq_desc
);
1234 /* Return if no rctl / type masks for this HBQ */
1235 if (!hbq_desc
->mask_count
)
1238 /* Otherwise we setup specific rctl / type masks for this HBQ */
1239 for (i
= 0; i
< hbq_desc
->mask_count
; i
++) {
1240 hbqmb
->hbqMasks
[i
].tmatch
= hbq_desc
->hbqMasks
[i
].tmatch
;
1241 hbqmb
->hbqMasks
[i
].tmask
= hbq_desc
->hbqMasks
[i
].tmask
;
1242 hbqmb
->hbqMasks
[i
].rctlmatch
= hbq_desc
->hbqMasks
[i
].rctlmatch
;
1243 hbqmb
->hbqMasks
[i
].rctlmask
= hbq_desc
->hbqMasks
[i
].rctlmask
;
1250 * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
1251 * @phba: pointer to lpfc hba data structure.
1252 * @ring: ring number/index
1253 * @pmb: pointer to the driver internal queue element for mailbox command.
1255 * The configure ring mailbox command is used to configure an IOCB ring. This
1256 * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1257 * ring. This is used to map incoming sequences to a particular ring whose
1258 * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1259 * attempt to configure a ring whose number is greater than the number
1260 * specified in the Port Control Block (PCB). It is an error to issue the
1261 * configure ring command more than once with the same ring number. The HBA
1262 * returns an error if the driver attempts this.
1264 * This routine prepares the mailbox command for configuring IOCB ring.
1267 lpfc_config_ring(struct lpfc_hba
* phba
, int ring
, LPFC_MBOXQ_t
* pmb
)
1270 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1271 struct lpfc_sli
*psli
;
1272 struct lpfc_sli_ring
*pring
;
1274 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
1276 mb
->un
.varCfgRing
.ring
= ring
;
1277 mb
->un
.varCfgRing
.maxOrigXchg
= 0;
1278 mb
->un
.varCfgRing
.maxRespXchg
= 0;
1279 mb
->un
.varCfgRing
.recvNotify
= 1;
1282 pring
= &psli
->sli3_ring
[ring
];
1283 mb
->un
.varCfgRing
.numMask
= pring
->num_mask
;
1284 mb
->mbxCommand
= MBX_CONFIG_RING
;
1285 mb
->mbxOwner
= OWN_HOST
;
1287 /* Is this ring configured for a specific profile */
1288 if (pring
->prt
[0].profile
) {
1289 mb
->un
.varCfgRing
.profile
= pring
->prt
[0].profile
;
1293 /* Otherwise we setup specific rctl / type masks for this ring */
1294 for (i
= 0; i
< pring
->num_mask
; i
++) {
1295 mb
->un
.varCfgRing
.rrRegs
[i
].rval
= pring
->prt
[i
].rctl
;
1296 if (mb
->un
.varCfgRing
.rrRegs
[i
].rval
!= FC_RCTL_ELS_REQ
)
1297 mb
->un
.varCfgRing
.rrRegs
[i
].rmask
= 0xff;
1299 mb
->un
.varCfgRing
.rrRegs
[i
].rmask
= 0xfe;
1300 mb
->un
.varCfgRing
.rrRegs
[i
].tval
= pring
->prt
[i
].type
;
1301 mb
->un
.varCfgRing
.rrRegs
[i
].tmask
= 0xff;
1308 * lpfc_config_port - Prepare a mailbox command for configuring port
1309 * @phba: pointer to lpfc hba data structure.
1310 * @pmb: pointer to the driver internal queue element for mailbox command.
1312 * The configure port mailbox command is used to identify the Port Control
1313 * Block (PCB) in the driver memory. After this command is issued, the
1314 * driver must not access the mailbox in the HBA without first resetting
1315 * the HBA. The HBA may copy the PCB information to internal storage for
1316 * subsequent use; the driver can not change the PCB information unless it
1319 * This routine prepares the mailbox command for configuring port.
1322 lpfc_config_port(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1324 MAILBOX_t __iomem
*mb_slim
= (MAILBOX_t __iomem
*) phba
->MBslimaddr
;
1325 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1326 dma_addr_t pdma_addr
;
1327 uint32_t bar_low
, bar_high
;
1329 struct lpfc_hgp hgp
;
1331 uint32_t pgp_offset
;
1333 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
1334 mb
->mbxCommand
= MBX_CONFIG_PORT
;
1335 mb
->mbxOwner
= OWN_HOST
;
1337 mb
->un
.varCfgPort
.pcbLen
= sizeof(PCB_t
);
1339 offset
= (uint8_t *)phba
->pcb
- (uint8_t *)phba
->slim2p
.virt
;
1340 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1341 mb
->un
.varCfgPort
.pcbLow
= putPaddrLow(pdma_addr
);
1342 mb
->un
.varCfgPort
.pcbHigh
= putPaddrHigh(pdma_addr
);
1344 /* Always Host Group Pointer is in SLIM */
1345 mb
->un
.varCfgPort
.hps
= 1;
1347 /* If HBA supports SLI=3 ask for it */
1349 if (phba
->sli_rev
== LPFC_SLI_REV3
&& phba
->vpd
.sli3Feat
.cerbm
) {
1350 if (phba
->cfg_enable_bg
)
1351 mb
->un
.varCfgPort
.cbg
= 1; /* configure BlockGuard */
1352 mb
->un
.varCfgPort
.cerbm
= 1; /* Request HBQs */
1353 mb
->un
.varCfgPort
.ccrp
= 1; /* Command Ring Polling */
1354 mb
->un
.varCfgPort
.max_hbq
= lpfc_sli_hbq_count();
1355 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
1356 phba
->vpd
.sli3Feat
.cmv
) {
1357 mb
->un
.varCfgPort
.max_vpi
= LPFC_MAX_VPI
;
1358 mb
->un
.varCfgPort
.cmv
= 1;
1360 mb
->un
.varCfgPort
.max_vpi
= phba
->max_vpi
= 0;
1362 phba
->sli_rev
= LPFC_SLI_REV2
;
1363 mb
->un
.varCfgPort
.sli_mode
= phba
->sli_rev
;
1365 /* If this is an SLI3 port, configure async status notification. */
1366 if (phba
->sli_rev
== LPFC_SLI_REV3
)
1367 mb
->un
.varCfgPort
.casabt
= 1;
1370 phba
->pcb
->type
= TYPE_NATIVE_SLI2
;
1371 phba
->pcb
->feature
= FEATURE_INITIAL_SLI2
;
1373 /* Setup Mailbox pointers */
1374 phba
->pcb
->mailBoxSize
= sizeof(MAILBOX_t
) + MAILBOX_EXT_SIZE
;
1375 offset
= (uint8_t *)phba
->mbox
- (uint8_t *)phba
->slim2p
.virt
;
1376 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1377 phba
->pcb
->mbAddrHigh
= putPaddrHigh(pdma_addr
);
1378 phba
->pcb
->mbAddrLow
= putPaddrLow(pdma_addr
);
1381 * Setup Host Group ring pointer.
1383 * For efficiency reasons, the ring get/put pointers can be
1384 * placed in adapter memory (SLIM) rather than in host memory.
1385 * This allows firmware to avoid PCI reads/writes when updating
1386 * and checking pointers.
1388 * The firmware recognizes the use of SLIM memory by comparing
1389 * the address of the get/put pointers structure with that of
1390 * the SLIM BAR (BAR0).
1392 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1393 * (the hardware's view of the base address), not the OS's
1394 * value of pci_resource_start() as the OS value may be a cookie
1395 * for ioremap/iomap.
1399 pci_read_config_dword(phba
->pcidev
, PCI_BASE_ADDRESS_0
, &bar_low
);
1400 pci_read_config_dword(phba
->pcidev
, PCI_BASE_ADDRESS_1
, &bar_high
);
1403 * Set up HGP - Port Memory
1405 * The port expects the host get/put pointers to reside in memory
1406 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1407 * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
1408 * words (0x40 bytes). This area is not reserved if HBQs are
1409 * configured in SLI-3.
1411 * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1420 * Reserved 0xa0-0xbf
1421 * If HBQs configured:
1422 * HBQ 0 Put ptr 0xc0
1423 * HBQ 1 Put ptr 0xc4
1424 * HBQ 2 Put ptr 0xc8
1426 * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1430 if (phba
->cfg_hostmem_hgp
&& phba
->sli_rev
!= 3) {
1431 phba
->host_gp
= (struct lpfc_hgp __iomem
*)
1432 &phba
->mbox
->us
.s2
.host
[0];
1433 phba
->hbq_put
= NULL
;
1434 offset
= (uint8_t *)&phba
->mbox
->us
.s2
.host
-
1435 (uint8_t *)phba
->slim2p
.virt
;
1436 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1437 phba
->pcb
->hgpAddrHigh
= putPaddrHigh(pdma_addr
);
1438 phba
->pcb
->hgpAddrLow
= putPaddrLow(pdma_addr
);
1440 /* Always Host Group Pointer is in SLIM */
1441 mb
->un
.varCfgPort
.hps
= 1;
1443 if (phba
->sli_rev
== 3) {
1444 phba
->host_gp
= &mb_slim
->us
.s3
.host
[0];
1445 phba
->hbq_put
= &mb_slim
->us
.s3
.hbq_put
[0];
1447 phba
->host_gp
= &mb_slim
->us
.s2
.host
[0];
1448 phba
->hbq_put
= NULL
;
1451 /* mask off BAR0's flag bits 0 - 3 */
1452 phba
->pcb
->hgpAddrLow
= (bar_low
& PCI_BASE_ADDRESS_MEM_MASK
) +
1453 (void __iomem
*)phba
->host_gp
-
1454 (void __iomem
*)phba
->MBslimaddr
;
1455 if (bar_low
& PCI_BASE_ADDRESS_MEM_TYPE_64
)
1456 phba
->pcb
->hgpAddrHigh
= bar_high
;
1458 phba
->pcb
->hgpAddrHigh
= 0;
1459 /* write HGP data to SLIM at the required longword offset */
1460 memset(&hgp
, 0, sizeof(struct lpfc_hgp
));
1462 for (i
= 0; i
< phba
->sli
.num_rings
; i
++) {
1463 lpfc_memcpy_to_slim(phba
->host_gp
+ i
, &hgp
,
1464 sizeof(*phba
->host_gp
));
1468 /* Setup Port Group offset */
1469 if (phba
->sli_rev
== 3)
1470 pgp_offset
= offsetof(struct lpfc_sli2_slim
,
1471 mbx
.us
.s3_pgp
.port
);
1473 pgp_offset
= offsetof(struct lpfc_sli2_slim
, mbx
.us
.s2
.port
);
1474 pdma_addr
= phba
->slim2p
.phys
+ pgp_offset
;
1475 phba
->pcb
->pgpAddrHigh
= putPaddrHigh(pdma_addr
);
1476 phba
->pcb
->pgpAddrLow
= putPaddrLow(pdma_addr
);
1478 /* Use callback routine to setp rings in the pcb */
1479 lpfc_config_pcb_setup(phba
);
1481 /* special handling for LC HBAs */
1482 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
1483 uint32_t hbainit
[5];
1485 lpfc_hba_init(phba
, hbainit
);
1487 memcpy(&mb
->un
.varCfgPort
.hbainit
, hbainit
, 20);
1490 /* Swap PCB if needed */
1491 lpfc_sli_pcimem_bcopy(phba
->pcb
, phba
->pcb
, sizeof(PCB_t
));
1495 * lpfc_kill_board - Prepare a mailbox command for killing board
1496 * @phba: pointer to lpfc hba data structure.
1497 * @pmb: pointer to the driver internal queue element for mailbox command.
1499 * The kill board mailbox command is used to tell firmware to perform a
1500 * graceful shutdown of a channel on a specified board to prepare for reset.
1501 * When the kill board mailbox command is received, the ER3 bit is set to 1
1502 * in the Host Status register and the ER Attention bit is set to 1 in the
1503 * Host Attention register of the HBA function that received the kill board
1506 * This routine prepares the mailbox command for killing the board in
1507 * preparation for a graceful shutdown.
1510 lpfc_kill_board(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
1512 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1514 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
1515 mb
->mbxCommand
= MBX_KILL_BOARD
;
1516 mb
->mbxOwner
= OWN_HOST
;
1521 * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
1522 * @phba: pointer to lpfc hba data structure.
1523 * @mbq: pointer to the driver internal queue element for mailbox command.
1525 * Driver maintains a internal mailbox command queue implemented as a linked
1526 * list. When a mailbox command is issued, it shall be put into the mailbox
1527 * command queue such that they shall be processed orderly as HBA can process
1528 * one mailbox command at a time.
1531 lpfc_mbox_put(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* mbq
)
1533 struct lpfc_sli
*psli
;
1537 list_add_tail(&mbq
->list
, &psli
->mboxq
);
1545 * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
1546 * @phba: pointer to lpfc hba data structure.
1548 * Driver maintains a internal mailbox command queue implemented as a linked
1549 * list. When a mailbox command is issued, it shall be put into the mailbox
1550 * command queue such that they shall be processed orderly as HBA can process
1551 * one mailbox command at a time. After HBA finished processing a mailbox
1552 * command, the driver will remove a pending mailbox command from the head of
1553 * the mailbox command queue and send to the HBA for processing.
1556 * pointer to the driver internal queue element for mailbox command.
1559 lpfc_mbox_get(struct lpfc_hba
* phba
)
1561 LPFC_MBOXQ_t
*mbq
= NULL
;
1562 struct lpfc_sli
*psli
= &phba
->sli
;
1564 list_remove_head((&psli
->mboxq
), mbq
, LPFC_MBOXQ_t
, list
);
1572 * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
1573 * @phba: pointer to lpfc hba data structure.
1574 * @mbq: pointer to the driver internal queue element for mailbox command.
1576 * This routine put the completed mailbox command into the mailbox command
1577 * complete list. This is the unlocked version of the routine. The mailbox
1578 * complete list is used by the driver worker thread to process mailbox
1579 * complete callback functions outside the driver interrupt handler.
1582 __lpfc_mbox_cmpl_put(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbq
)
1584 list_add_tail(&mbq
->list
, &phba
->sli
.mboxq_cmpl
);
1588 * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
1589 * @phba: pointer to lpfc hba data structure.
1590 * @mbq: pointer to the driver internal queue element for mailbox command.
1592 * This routine put the completed mailbox command into the mailbox command
1593 * complete list. This is the locked version of the routine. The mailbox
1594 * complete list is used by the driver worker thread to process mailbox
1595 * complete callback functions outside the driver interrupt handler.
1598 lpfc_mbox_cmpl_put(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbq
)
1600 unsigned long iflag
;
1602 /* This function expects to be called from interrupt context */
1603 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1604 __lpfc_mbox_cmpl_put(phba
, mbq
);
1605 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1610 * lpfc_mbox_cmd_check - Check the validality of a mailbox command
1611 * @phba: pointer to lpfc hba data structure.
1612 * @mboxq: pointer to the driver internal queue element for mailbox command.
1614 * This routine is to check whether a mailbox command is valid to be issued.
1615 * This check will be performed by both the mailbox issue API when a client
1616 * is to issue a mailbox command to the mailbox transport.
1618 * Return 0 - pass the check, -ENODEV - fail the check
1621 lpfc_mbox_cmd_check(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1623 /* Mailbox command that have a completion handler must also have a
1626 if (mboxq
->mbox_cmpl
&& mboxq
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
1627 mboxq
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
1628 if (!mboxq
->vport
) {
1629 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
1630 "1814 Mbox x%x failed, no vport\n",
1631 mboxq
->u
.mb
.mbxCommand
);
1640 * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
1641 * @phba: pointer to lpfc hba data structure.
1643 * This routine is to check whether the HBA device is ready for posting a
1644 * mailbox command. It is used by the mailbox transport API at the time the
1645 * to post a mailbox command to the device.
1647 * Return 0 - pass the check, -ENODEV - fail the check
1650 lpfc_mbox_dev_check(struct lpfc_hba
*phba
)
1652 /* If the PCI channel is in offline state, do not issue mbox */
1653 if (unlikely(pci_channel_offline(phba
->pcidev
)))
1656 /* If the HBA is in error state, do not issue mbox */
1657 if (phba
->link_state
== LPFC_HBA_ERROR
)
1664 * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
1665 * @phba: pointer to lpfc hba data structure.
1666 * @mboxq: pointer to the driver internal queue element for mailbox command.
1668 * This routine retrieves the proper timeout value according to the mailbox
1672 * Timeout value to be used for the given mailbox command
1675 lpfc_mbox_tmo_val(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1677 MAILBOX_t
*mbox
= &mboxq
->u
.mb
;
1678 uint8_t subsys
, opcode
;
1680 switch (mbox
->mbxCommand
) {
1681 case MBX_WRITE_NV
: /* 0x03 */
1682 case MBX_DUMP_MEMORY
: /* 0x17 */
1683 case MBX_UPDATE_CFG
: /* 0x1B */
1684 case MBX_DOWN_LOAD
: /* 0x1C */
1685 case MBX_DEL_LD_ENTRY
: /* 0x1D */
1686 case MBX_WRITE_VPARMS
: /* 0x32 */
1687 case MBX_LOAD_AREA
: /* 0x81 */
1688 case MBX_WRITE_WWN
: /* 0x98 */
1689 case MBX_LOAD_EXP_ROM
: /* 0x9C */
1690 case MBX_ACCESS_VDATA
: /* 0xA5 */
1691 return LPFC_MBOX_TMO_FLASH_CMD
;
1692 case MBX_SLI4_CONFIG
: /* 0x9b */
1693 subsys
= lpfc_sli_config_mbox_subsys_get(phba
, mboxq
);
1694 opcode
= lpfc_sli_config_mbox_opcode_get(phba
, mboxq
);
1695 if (subsys
== LPFC_MBOX_SUBSYSTEM_COMMON
) {
1697 case LPFC_MBOX_OPCODE_READ_OBJECT
:
1698 case LPFC_MBOX_OPCODE_WRITE_OBJECT
:
1699 case LPFC_MBOX_OPCODE_READ_OBJECT_LIST
:
1700 case LPFC_MBOX_OPCODE_DELETE_OBJECT
:
1701 case LPFC_MBOX_OPCODE_GET_PROFILE_LIST
:
1702 case LPFC_MBOX_OPCODE_SET_ACT_PROFILE
:
1703 case LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG
:
1704 case LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG
:
1705 case LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG
:
1706 case LPFC_MBOX_OPCODE_GET_PROFILE_CAPACITIES
:
1707 case LPFC_MBOX_OPCODE_SEND_ACTIVATION
:
1708 case LPFC_MBOX_OPCODE_RESET_LICENSES
:
1709 case LPFC_MBOX_OPCODE_SET_BOOT_CONFIG
:
1710 case LPFC_MBOX_OPCODE_GET_VPD_DATA
:
1711 case LPFC_MBOX_OPCODE_SET_PHYSICAL_LINK_CONFIG
:
1712 return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO
;
1715 if (subsys
== LPFC_MBOX_SUBSYSTEM_FCOE
) {
1717 case LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS
:
1718 return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO
;
1721 return LPFC_MBOX_SLI4_CONFIG_TMO
;
1723 return LPFC_MBOX_TMO
;
1727 * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
1728 * @mbox: pointer to lpfc mbox command.
1729 * @sgentry: sge entry index.
1730 * @phyaddr: physical address for the sge
1731 * @length: Length of the sge.
1733 * This routine sets up an entry in the non-embedded mailbox command at the sge
1737 lpfc_sli4_mbx_sge_set(struct lpfcMboxq
*mbox
, uint32_t sgentry
,
1738 dma_addr_t phyaddr
, uint32_t length
)
1740 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
1742 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
1743 &mbox
->u
.mqe
.un
.nembed_cmd
;
1744 nembed_sge
->sge
[sgentry
].pa_lo
= putPaddrLow(phyaddr
);
1745 nembed_sge
->sge
[sgentry
].pa_hi
= putPaddrHigh(phyaddr
);
1746 nembed_sge
->sge
[sgentry
].length
= length
;
1750 * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
1751 * @mbox: pointer to lpfc mbox command.
1752 * @sgentry: sge entry index.
1753 * @sge: pointer to lpfc mailbox sge to load into.
1755 * This routine gets an entry from the non-embedded mailbox command at the sge
1759 lpfc_sli4_mbx_sge_get(struct lpfcMboxq
*mbox
, uint32_t sgentry
,
1760 struct lpfc_mbx_sge
*sge
)
1762 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
1764 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
1765 &mbox
->u
.mqe
.un
.nembed_cmd
;
1766 sge
->pa_lo
= nembed_sge
->sge
[sgentry
].pa_lo
;
1767 sge
->pa_hi
= nembed_sge
->sge
[sgentry
].pa_hi
;
1768 sge
->length
= nembed_sge
->sge
[sgentry
].length
;
1772 * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
1773 * @phba: pointer to lpfc hba data structure.
1774 * @mbox: pointer to lpfc mbox command.
1776 * This routine cleans up and releases an SLI4 mailbox command that was
1777 * configured using lpfc_sli4_config. It accounts for the embedded and
1778 * non-embedded config types.
1781 lpfc_sli4_mbox_cmd_free(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
1783 struct lpfc_mbx_sli4_config
*sli4_cfg
;
1784 struct lpfc_mbx_sge sge
;
1786 uint32_t sgecount
, sgentry
;
1788 sli4_cfg
= &mbox
->u
.mqe
.un
.sli4_config
;
1790 /* For embedded mbox command, just free the mbox command */
1791 if (bf_get(lpfc_mbox_hdr_emb
, &sli4_cfg
->header
.cfg_mhdr
)) {
1792 mempool_free(mbox
, phba
->mbox_mem_pool
);
1796 /* For non-embedded mbox command, we need to free the pages first */
1797 sgecount
= bf_get(lpfc_mbox_hdr_sge_cnt
, &sli4_cfg
->header
.cfg_mhdr
);
1798 /* There is nothing we can do if there is no sge address array */
1799 if (unlikely(!mbox
->sge_array
)) {
1800 mempool_free(mbox
, phba
->mbox_mem_pool
);
1803 /* Each non-embedded DMA memory was allocated in the length of a page */
1804 for (sgentry
= 0; sgentry
< sgecount
; sgentry
++) {
1805 lpfc_sli4_mbx_sge_get(mbox
, sgentry
, &sge
);
1806 phyaddr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
1807 dma_free_coherent(&phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
1808 mbox
->sge_array
->addr
[sgentry
], phyaddr
);
1810 /* Reinitialize the context pointers to avoid stale usage. */
1811 mbox
->ctx_buf
= NULL
;
1812 memset(&mbox
->ctx_u
, 0, sizeof(mbox
->ctx_u
));
1813 kfree(mbox
->sge_array
);
1814 /* Finally, free the mailbox command itself */
1815 mempool_free(mbox
, phba
->mbox_mem_pool
);
1819 * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command
1820 * @phba: pointer to lpfc hba data structure.
1821 * @mbox: pointer to lpfc mbox command.
1822 * @subsystem: The sli4 config sub mailbox subsystem.
1823 * @opcode: The sli4 config sub mailbox command opcode.
1824 * @length: Length of the sli4 config mailbox command (including sub-header).
1825 * @emb: True if embedded mbox command should be setup.
1827 * This routine sets up the header fields of SLI4 specific mailbox command
1828 * for sending IOCTL command.
1830 * Return: the actual length of the mbox command allocated (mostly useful
1831 * for none embedded mailbox command).
1834 lpfc_sli4_config(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
,
1835 uint8_t subsystem
, uint8_t opcode
, uint32_t length
, bool emb
)
1837 struct lpfc_mbx_sli4_config
*sli4_config
;
1838 union lpfc_sli4_cfg_shdr
*cfg_shdr
= NULL
;
1841 uint32_t pagen
, pcount
;
1845 /* Set up SLI4 mailbox command header fields */
1846 memset(mbox
, 0, sizeof(*mbox
));
1847 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_SLI4_CONFIG
);
1849 /* Set up SLI4 ioctl command header fields */
1850 sli4_config
= &mbox
->u
.mqe
.un
.sli4_config
;
1852 /* Setup for the embedded mbox command */
1854 /* Set up main header fields */
1855 bf_set(lpfc_mbox_hdr_emb
, &sli4_config
->header
.cfg_mhdr
, 1);
1856 sli4_config
->header
.cfg_mhdr
.payload_length
= length
;
1857 /* Set up sub-header fields following main header */
1858 bf_set(lpfc_mbox_hdr_opcode
,
1859 &sli4_config
->header
.cfg_shdr
.request
, opcode
);
1860 bf_set(lpfc_mbox_hdr_subsystem
,
1861 &sli4_config
->header
.cfg_shdr
.request
, subsystem
);
1862 sli4_config
->header
.cfg_shdr
.request
.request_length
=
1863 length
- LPFC_MBX_CMD_HDR_LENGTH
;
1867 /* Setup for the non-embedded mbox command */
1868 pcount
= (SLI4_PAGE_ALIGN(length
))/SLI4_PAGE_SIZE
;
1869 pcount
= (pcount
> LPFC_SLI4_MBX_SGE_MAX_PAGES
) ?
1870 LPFC_SLI4_MBX_SGE_MAX_PAGES
: pcount
;
1871 /* Allocate record for keeping SGE virtual addresses */
1872 mbox
->sge_array
= kzalloc(sizeof(struct lpfc_mbx_nembed_sge_virt
),
1874 if (!mbox
->sge_array
) {
1875 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1876 "2527 Failed to allocate non-embedded SGE "
1880 for (pagen
= 0, alloc_len
= 0; pagen
< pcount
; pagen
++) {
1881 /* The DMA memory is always allocated in the length of a
1882 * page even though the last SGE might not fill up to a
1883 * page, this is used as a priori size of SLI4_PAGE_SIZE for
1884 * the later DMA memory free.
1886 viraddr
= dma_alloc_coherent(&phba
->pcidev
->dev
,
1887 SLI4_PAGE_SIZE
, &phyaddr
,
1889 /* In case of malloc fails, proceed with whatever we have */
1892 mbox
->sge_array
->addr
[pagen
] = viraddr
;
1893 /* Keep the first page for later sub-header construction */
1895 cfg_shdr
= (union lpfc_sli4_cfg_shdr
*)viraddr
;
1896 resid_len
= length
- alloc_len
;
1897 if (resid_len
> SLI4_PAGE_SIZE
) {
1898 lpfc_sli4_mbx_sge_set(mbox
, pagen
, phyaddr
,
1900 alloc_len
+= SLI4_PAGE_SIZE
;
1902 lpfc_sli4_mbx_sge_set(mbox
, pagen
, phyaddr
,
1908 /* Set up main header fields in mailbox command */
1909 sli4_config
->header
.cfg_mhdr
.payload_length
= alloc_len
;
1910 bf_set(lpfc_mbox_hdr_sge_cnt
, &sli4_config
->header
.cfg_mhdr
, pagen
);
1912 /* Set up sub-header fields into the first page */
1914 bf_set(lpfc_mbox_hdr_opcode
, &cfg_shdr
->request
, opcode
);
1915 bf_set(lpfc_mbox_hdr_subsystem
, &cfg_shdr
->request
, subsystem
);
1916 cfg_shdr
->request
.request_length
=
1917 alloc_len
- sizeof(union lpfc_sli4_cfg_shdr
);
1919 /* The sub-header is in DMA memory, which needs endian converstion */
1921 lpfc_sli_pcimem_bcopy(cfg_shdr
, cfg_shdr
,
1922 sizeof(union lpfc_sli4_cfg_shdr
));
1927 * lpfc_sli4_mbox_rsrc_extent - Initialize the opcode resource extent.
1928 * @phba: pointer to lpfc hba data structure.
1929 * @mbox: pointer to an allocated lpfc mbox resource.
1930 * @exts_count: the number of extents, if required, to allocate.
1931 * @rsrc_type: the resource extent type.
1932 * @emb: true if LPFC_SLI4_MBX_EMBED. false if LPFC_SLI4_MBX_NEMBED.
1934 * This routine completes the subcommand header for SLI4 resource extent
1935 * mailbox commands. It is called after lpfc_sli4_config. The caller must
1936 * pass an allocated mailbox and the attributes required to initialize the
1937 * mailbox correctly.
1939 * Return: the actual length of the mbox command allocated.
1942 lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
,
1943 uint16_t exts_count
, uint16_t rsrc_type
, bool emb
)
1946 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc_extnt
= NULL
;
1947 void *virtaddr
= NULL
;
1949 /* Set up SLI4 ioctl command header fields */
1950 if (emb
== LPFC_SLI4_MBX_NEMBED
) {
1951 /* Get the first SGE entry from the non-embedded DMA memory */
1952 virtaddr
= mbox
->sge_array
->addr
[0];
1953 if (virtaddr
== NULL
)
1955 n_rsrc_extnt
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
1959 * The resource type is common to all extent Opcodes and resides in the
1962 if (emb
== LPFC_SLI4_MBX_EMBED
)
1963 bf_set(lpfc_mbx_alloc_rsrc_extents_type
,
1964 &mbox
->u
.mqe
.un
.alloc_rsrc_extents
.u
.req
,
1967 /* This is DMA data. Byteswap is required. */
1968 bf_set(lpfc_mbx_alloc_rsrc_extents_type
,
1969 n_rsrc_extnt
, rsrc_type
);
1970 lpfc_sli_pcimem_bcopy(&n_rsrc_extnt
->word4
,
1971 &n_rsrc_extnt
->word4
,
1975 /* Complete the initialization for the particular Opcode. */
1976 opcode
= lpfc_sli_config_mbox_opcode_get(phba
, mbox
);
1978 case LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT
:
1979 if (emb
== LPFC_SLI4_MBX_EMBED
)
1980 bf_set(lpfc_mbx_alloc_rsrc_extents_cnt
,
1981 &mbox
->u
.mqe
.un
.alloc_rsrc_extents
.u
.req
,
1984 bf_set(lpfc_mbx_alloc_rsrc_extents_cnt
,
1985 n_rsrc_extnt
, exts_count
);
1987 case LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT
:
1988 case LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO
:
1989 case LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT
:
1990 /* Initialization is complete.*/
1993 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1994 "2929 Resource Extent Opcode x%x is "
1995 "unsupported\n", opcode
);
2003 * lpfc_sli_config_mbox_subsys_get - Get subsystem from a sli_config mbox cmd
2004 * @phba: pointer to lpfc hba data structure.
2005 * @mbox: pointer to lpfc mbox command queue entry.
2007 * This routine gets the subsystem from a SLI4 specific SLI_CONFIG mailbox
2008 * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if the
2009 * sub-header is not present, subsystem LPFC_MBOX_SUBSYSTEM_NA (0x0) shall
2013 lpfc_sli_config_mbox_subsys_get(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
2015 struct lpfc_mbx_sli4_config
*sli4_cfg
;
2016 union lpfc_sli4_cfg_shdr
*cfg_shdr
;
2018 if (mbox
->u
.mb
.mbxCommand
!= MBX_SLI4_CONFIG
)
2019 return LPFC_MBOX_SUBSYSTEM_NA
;
2020 sli4_cfg
= &mbox
->u
.mqe
.un
.sli4_config
;
2022 /* For embedded mbox command, get opcode from embedded sub-header*/
2023 if (bf_get(lpfc_mbox_hdr_emb
, &sli4_cfg
->header
.cfg_mhdr
)) {
2024 cfg_shdr
= &mbox
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
2025 return bf_get(lpfc_mbox_hdr_subsystem
, &cfg_shdr
->request
);
2028 /* For non-embedded mbox command, get opcode from first dma page */
2029 if (unlikely(!mbox
->sge_array
))
2030 return LPFC_MBOX_SUBSYSTEM_NA
;
2031 cfg_shdr
= (union lpfc_sli4_cfg_shdr
*)mbox
->sge_array
->addr
[0];
2032 return bf_get(lpfc_mbox_hdr_subsystem
, &cfg_shdr
->request
);
2036 * lpfc_sli_config_mbox_opcode_get - Get opcode from a sli_config mbox cmd
2037 * @phba: pointer to lpfc hba data structure.
2038 * @mbox: pointer to lpfc mbox command queue entry.
2040 * This routine gets the opcode from a SLI4 specific SLI_CONFIG mailbox
2041 * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if
2042 * the sub-header is not present, opcode LPFC_MBOX_OPCODE_NA (0x0) be
2046 lpfc_sli_config_mbox_opcode_get(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
2048 struct lpfc_mbx_sli4_config
*sli4_cfg
;
2049 union lpfc_sli4_cfg_shdr
*cfg_shdr
;
2051 if (mbox
->u
.mb
.mbxCommand
!= MBX_SLI4_CONFIG
)
2052 return LPFC_MBOX_OPCODE_NA
;
2053 sli4_cfg
= &mbox
->u
.mqe
.un
.sli4_config
;
2055 /* For embedded mbox command, get opcode from embedded sub-header*/
2056 if (bf_get(lpfc_mbox_hdr_emb
, &sli4_cfg
->header
.cfg_mhdr
)) {
2057 cfg_shdr
= &mbox
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
2058 return bf_get(lpfc_mbox_hdr_opcode
, &cfg_shdr
->request
);
2061 /* For non-embedded mbox command, get opcode from first dma page */
2062 if (unlikely(!mbox
->sge_array
))
2063 return LPFC_MBOX_OPCODE_NA
;
2064 cfg_shdr
= (union lpfc_sli4_cfg_shdr
*)mbox
->sge_array
->addr
[0];
2065 return bf_get(lpfc_mbox_hdr_opcode
, &cfg_shdr
->request
);
2069 * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd
2070 * @phba: pointer to lpfc hba data structure.
2071 * @mboxq: pointer to lpfc mbox command.
2072 * @fcf_index: index to fcf table.
2074 * This routine routine allocates and constructs non-embedded mailbox command
2075 * for reading a FCF table entry referred by @fcf_index.
2077 * Return: pointer to the mailbox command constructed if successful, otherwise
2081 lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba
*phba
,
2082 struct lpfcMboxq
*mboxq
,
2087 struct lpfc_mbx_sge sge
;
2088 uint32_t alloc_len
, req_len
;
2089 struct lpfc_mbx_read_fcf_tbl
*read_fcf
;
2094 req_len
= sizeof(struct fcf_record
) +
2095 sizeof(union lpfc_sli4_cfg_shdr
) + 2 * sizeof(uint32_t);
2097 /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
2098 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
2099 LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE
, req_len
,
2100 LPFC_SLI4_MBX_NEMBED
);
2102 if (alloc_len
< req_len
) {
2103 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
2104 "0291 Allocated DMA memory size (x%x) is "
2105 "less than the requested DMA memory "
2106 "size (x%x)\n", alloc_len
, req_len
);
2110 /* Get the first SGE entry from the non-embedded DMA memory. This
2111 * routine only uses a single SGE.
2113 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
2114 virt_addr
= mboxq
->sge_array
->addr
[0];
2115 read_fcf
= (struct lpfc_mbx_read_fcf_tbl
*)virt_addr
;
2117 /* Set up command fields */
2118 bf_set(lpfc_mbx_read_fcf_tbl_indx
, &read_fcf
->u
.request
, fcf_index
);
2119 /* Perform necessary endian conversion */
2120 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
2121 lpfc_sli_pcimem_bcopy(bytep
, bytep
, sizeof(uint32_t));
2127 * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
2128 * @phba: pointer to lpfc hba data structure.
2129 * @mboxq: pointer to lpfc mbox command.
2131 * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
2135 lpfc_request_features(struct lpfc_hba
*phba
, struct lpfcMboxq
*mboxq
)
2137 /* Set up SLI4 mailbox command header fields */
2138 memset(mboxq
, 0, sizeof(LPFC_MBOXQ_t
));
2139 bf_set(lpfc_mqe_command
, &mboxq
->u
.mqe
, MBX_SLI4_REQ_FTRS
);
2141 /* Set up host requested features. */
2142 bf_set(lpfc_mbx_rq_ftr_rq_fcpi
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
2143 bf_set(lpfc_mbx_rq_ftr_rq_perfh
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
2145 /* Enable DIF (block guard) only if configured to do so. */
2146 if (phba
->cfg_enable_bg
)
2147 bf_set(lpfc_mbx_rq_ftr_rq_dif
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
2149 /* Enable NPIV only if configured to do so. */
2150 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
)
2151 bf_set(lpfc_mbx_rq_ftr_rq_npiv
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
2153 if (phba
->nvmet_support
) {
2154 bf_set(lpfc_mbx_rq_ftr_rq_mrqp
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
2155 /* iaab/iaar NOT set for now */
2156 bf_set(lpfc_mbx_rq_ftr_rq_iaab
, &mboxq
->u
.mqe
.un
.req_ftrs
, 0);
2157 bf_set(lpfc_mbx_rq_ftr_rq_iaar
, &mboxq
->u
.mqe
.un
.req_ftrs
, 0);
2160 /* Enable Application Services Header for appheader VMID */
2161 if (phba
->cfg_vmid_app_header
) {
2162 bf_set(lpfc_mbx_rq_ftr_rq_ashdr
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
2163 bf_set(lpfc_ftr_ashdr
, &phba
->sli4_hba
.sli4_flags
, 1);
2169 * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
2170 * @mbox: pointer to lpfc mbox command to initialize.
2171 * @vport: Vport associated with the VF.
2173 * This routine initializes @mbox to all zeros and then fills in the mailbox
2174 * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
2175 * in the context of an FCF. The driver issues this command to setup a VFI
2176 * before issuing a FLOGI to login to the VSAN. The driver should also issue a
2177 * REG_VFI after a successful VSAN login.
2180 lpfc_init_vfi(struct lpfcMboxq
*mbox
, struct lpfc_vport
*vport
)
2182 struct lpfc_mbx_init_vfi
*init_vfi
;
2184 memset(mbox
, 0, sizeof(*mbox
));
2185 mbox
->vport
= vport
;
2186 init_vfi
= &mbox
->u
.mqe
.un
.init_vfi
;
2187 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_INIT_VFI
);
2188 bf_set(lpfc_init_vfi_vr
, init_vfi
, 1);
2189 bf_set(lpfc_init_vfi_vt
, init_vfi
, 1);
2190 bf_set(lpfc_init_vfi_vp
, init_vfi
, 1);
2191 bf_set(lpfc_init_vfi_vfi
, init_vfi
,
2192 vport
->phba
->sli4_hba
.vfi_ids
[vport
->vfi
]);
2193 bf_set(lpfc_init_vfi_vpi
, init_vfi
,
2194 vport
->phba
->vpi_ids
[vport
->vpi
]);
2195 bf_set(lpfc_init_vfi_fcfi
, init_vfi
,
2196 vport
->phba
->fcf
.fcfi
);
2200 * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
2201 * @mbox: pointer to lpfc mbox command to initialize.
2202 * @vport: vport associated with the VF.
2203 * @phys: BDE DMA bus address used to send the service parameters to the HBA.
2205 * This routine initializes @mbox to all zeros and then fills in the mailbox
2206 * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
2207 * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
2208 * fabrics identified by VFI in the context of an FCF.
2211 lpfc_reg_vfi(struct lpfcMboxq
*mbox
, struct lpfc_vport
*vport
, dma_addr_t phys
)
2213 struct lpfc_mbx_reg_vfi
*reg_vfi
;
2214 struct lpfc_hba
*phba
= vport
->phba
;
2215 uint8_t bbscn_fabric
= 0, bbscn_max
= 0, bbscn_def
= 0;
2217 memset(mbox
, 0, sizeof(*mbox
));
2218 reg_vfi
= &mbox
->u
.mqe
.un
.reg_vfi
;
2219 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_REG_VFI
);
2220 bf_set(lpfc_reg_vfi_vp
, reg_vfi
, 1);
2221 bf_set(lpfc_reg_vfi_vfi
, reg_vfi
,
2222 phba
->sli4_hba
.vfi_ids
[vport
->vfi
]);
2223 bf_set(lpfc_reg_vfi_fcfi
, reg_vfi
, phba
->fcf
.fcfi
);
2224 bf_set(lpfc_reg_vfi_vpi
, reg_vfi
, phba
->vpi_ids
[vport
->vpi
]);
2225 memcpy(reg_vfi
->wwn
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2226 reg_vfi
->wwn
[0] = cpu_to_le32(reg_vfi
->wwn
[0]);
2227 reg_vfi
->wwn
[1] = cpu_to_le32(reg_vfi
->wwn
[1]);
2228 reg_vfi
->e_d_tov
= phba
->fc_edtov
;
2229 reg_vfi
->r_a_tov
= phba
->fc_ratov
;
2231 reg_vfi
->bde
.addrHigh
= putPaddrHigh(phys
);
2232 reg_vfi
->bde
.addrLow
= putPaddrLow(phys
);
2233 reg_vfi
->bde
.tus
.f
.bdeSize
= sizeof(vport
->fc_sparam
);
2234 reg_vfi
->bde
.tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
2236 bf_set(lpfc_reg_vfi_nport_id
, reg_vfi
, vport
->fc_myDID
);
2238 /* Only FC supports upd bit */
2239 if ((phba
->sli4_hba
.lnk_info
.lnk_tp
== LPFC_LNK_TYPE_FC
) &&
2240 test_bit(FC_VFI_REGISTERED
, &vport
->fc_flag
) &&
2241 (!phba
->fc_topology_changed
))
2242 bf_set(lpfc_reg_vfi_upd
, reg_vfi
, 1);
2244 bf_set(lpfc_reg_vfi_bbcr
, reg_vfi
, 0);
2245 bf_set(lpfc_reg_vfi_bbscn
, reg_vfi
, 0);
2246 bbscn_fabric
= (phba
->fc_fabparam
.cmn
.bbRcvSizeMsb
>> 4) & 0xF;
2248 if (phba
->bbcredit_support
&& phba
->cfg_enable_bbcr
&&
2249 bbscn_fabric
!= 0) {
2250 bbscn_max
= bf_get(lpfc_bbscn_max
,
2251 &phba
->sli4_hba
.bbscn_params
);
2252 if (bbscn_fabric
<= bbscn_max
) {
2253 bbscn_def
= bf_get(lpfc_bbscn_def
,
2254 &phba
->sli4_hba
.bbscn_params
);
2256 if (bbscn_fabric
> bbscn_def
)
2257 bf_set(lpfc_reg_vfi_bbscn
, reg_vfi
,
2260 bf_set(lpfc_reg_vfi_bbscn
, reg_vfi
, bbscn_def
);
2262 bf_set(lpfc_reg_vfi_bbcr
, reg_vfi
, 1);
2265 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_MBOX
,
2266 "3134 Register VFI, mydid:x%x, fcfi:%d, "
2267 "vfi:%d, vpi:%d, fc_pname:%x%x fc_flag:x%lx "
2268 "port_state:x%x topology chg:%d bbscn_fabric :%d\n",
2271 phba
->sli4_hba
.vfi_ids
[vport
->vfi
],
2272 phba
->vpi_ids
[vport
->vpi
],
2273 reg_vfi
->wwn
[0], reg_vfi
->wwn
[1], vport
->fc_flag
,
2274 vport
->port_state
, phba
->fc_topology_changed
,
2279 * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
2280 * @phba: pointer to the hba structure to init the VPI for.
2281 * @mbox: pointer to lpfc mbox command to initialize.
2282 * @vpi: VPI to be initialized.
2284 * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
2285 * command to activate a virtual N_Port. The HBA assigns a MAC address to use
2286 * with the virtual N Port. The SLI Host issues this command before issuing a
2287 * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
2288 * successful virtual NPort login.
2291 lpfc_init_vpi(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
, uint16_t vpi
)
2293 memset(mbox
, 0, sizeof(*mbox
));
2294 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_INIT_VPI
);
2295 bf_set(lpfc_init_vpi_vpi
, &mbox
->u
.mqe
.un
.init_vpi
,
2296 phba
->vpi_ids
[vpi
]);
2297 bf_set(lpfc_init_vpi_vfi
, &mbox
->u
.mqe
.un
.init_vpi
,
2298 phba
->sli4_hba
.vfi_ids
[phba
->pport
->vfi
]);
2302 * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
2303 * @mbox: pointer to lpfc mbox command to initialize.
2304 * @vport: vport associated with the VF.
2306 * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
2307 * (logical NPort) into the inactive state. The SLI Host must have logged out
2308 * and unregistered all remote N_Ports to abort any activity on the virtual
2309 * fabric. The SLI Port posts the mailbox response after marking the virtual
2313 lpfc_unreg_vfi(struct lpfcMboxq
*mbox
, struct lpfc_vport
*vport
)
2315 memset(mbox
, 0, sizeof(*mbox
));
2316 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_UNREG_VFI
);
2317 bf_set(lpfc_unreg_vfi_vfi
, &mbox
->u
.mqe
.un
.unreg_vfi
,
2318 vport
->phba
->sli4_hba
.vfi_ids
[vport
->vfi
]);
2322 * lpfc_sli4_dump_cfg_rg23 - Dump sli4 port config region 23
2323 * @phba: pointer to the hba structure containing.
2324 * @mbox: pointer to lpfc mbox command to initialize.
2326 * This function create a SLI4 dump mailbox command to dump configure
2330 lpfc_sli4_dump_cfg_rg23(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
2332 struct lpfc_dmabuf
*mp
= NULL
;
2336 memset(mbox
, 0, sizeof(*mbox
));
2339 rc
= lpfc_mbox_rsrc_prep(phba
, mbox
);
2341 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
2342 "2569 %s: memory allocation failed\n",
2347 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
2348 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
2349 mb
->un
.varDmp
.region_id
= DMP_REGION_23
;
2350 mb
->un
.varDmp
.sli4_length
= DMP_RGN23_SIZE
;
2352 mb
->un
.varWords
[3] = putPaddrLow(mp
->phys
);
2353 mb
->un
.varWords
[4] = putPaddrHigh(mp
->phys
);
2358 lpfc_mbx_cmpl_rdp_link_stat(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2362 struct lpfc_rdp_context
*rdp_context
= mboxq
->ctx_u
.rdp
;
2368 memcpy(&rdp_context
->link_stat
, &mb
->un
.varRdLnk
, sizeof(READ_LNK_VAR
));
2373 lpfc_mbox_rsrc_cleanup(phba
, mboxq
, MBOX_THD_UNLOCKED
);
2374 rdp_context
->cmpl(phba
, rdp_context
, rc
);
2378 lpfc_mbx_cmpl_rdp_page_a2(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
2380 struct lpfc_dmabuf
*mp
= mbox
->ctx_buf
;
2381 struct lpfc_rdp_context
*rdp_context
= mbox
->ctx_u
.rdp
;
2383 if (bf_get(lpfc_mqe_status
, &mbox
->u
.mqe
))
2384 goto error_mbox_free
;
2386 lpfc_sli_bemem_bcopy(mp
->virt
, &rdp_context
->page_a2
,
2387 DMP_SFF_PAGE_A2_SIZE
);
2389 lpfc_read_lnk_stat(phba
, mbox
);
2390 mbox
->vport
= rdp_context
->ndlp
->vport
;
2392 /* Save the dma buffer for cleanup in the final completion. */
2394 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_rdp_link_stat
;
2395 mbox
->ctx_u
.rdp
= rdp_context
;
2396 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
) == MBX_NOT_FINISHED
)
2397 goto error_mbox_free
;
2402 lpfc_mbox_rsrc_cleanup(phba
, mbox
, MBOX_THD_UNLOCKED
);
2403 rdp_context
->cmpl(phba
, rdp_context
, FAILURE
);
2407 lpfc_mbx_cmpl_rdp_page_a0(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
2410 struct lpfc_dmabuf
*mp
= mbox
->ctx_buf
;
2411 struct lpfc_rdp_context
*rdp_context
= mbox
->ctx_u
.rdp
;
2413 if (bf_get(lpfc_mqe_status
, &mbox
->u
.mqe
))
2416 lpfc_sli_bemem_bcopy(mp
->virt
, &rdp_context
->page_a0
,
2417 DMP_SFF_PAGE_A0_SIZE
);
2419 memset(mbox
, 0, sizeof(*mbox
));
2421 memset(mp
->virt
, 0, DMP_SFF_PAGE_A2_SIZE
);
2422 INIT_LIST_HEAD(&mp
->list
);
2424 /* save address for completion */
2426 mbox
->vport
= rdp_context
->ndlp
->vport
;
2428 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_DUMP_MEMORY
);
2429 bf_set(lpfc_mbx_memory_dump_type3_type
,
2430 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_LMSD
);
2431 bf_set(lpfc_mbx_memory_dump_type3_link
,
2432 &mbox
->u
.mqe
.un
.mem_dump_type3
, phba
->sli4_hba
.physical_port
);
2433 bf_set(lpfc_mbx_memory_dump_type3_page_no
,
2434 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_PAGE_A2
);
2435 bf_set(lpfc_mbx_memory_dump_type3_length
,
2436 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_SFF_PAGE_A2_SIZE
);
2437 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_lo
= putPaddrLow(mp
->phys
);
2438 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_hi
= putPaddrHigh(mp
->phys
);
2440 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_rdp_page_a2
;
2441 mbox
->ctx_u
.rdp
= rdp_context
;
2442 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
2443 if (rc
== MBX_NOT_FINISHED
)
2449 lpfc_mbox_rsrc_cleanup(phba
, mbox
, MBOX_THD_UNLOCKED
);
2450 rdp_context
->cmpl(phba
, rdp_context
, FAILURE
);
2455 * lpfc_sli4_dump_page_a0 - Dump sli4 read SFP Diagnostic.
2456 * @phba: pointer to the hba structure containing.
2457 * @mbox: pointer to lpfc mbox command to initialize.
2459 * This function create a SLI4 dump mailbox command to dump configure
2463 lpfc_sli4_dump_page_a0(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
2466 struct lpfc_dmabuf
*mp
= NULL
;
2468 memset(mbox
, 0, sizeof(*mbox
));
2470 rc
= lpfc_mbox_rsrc_prep(phba
, mbox
);
2472 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
2473 "3569 dump type 3 page 0xA0 allocation failed\n");
2477 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_DUMP_MEMORY
);
2478 bf_set(lpfc_mbx_memory_dump_type3_type
,
2479 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_LMSD
);
2480 bf_set(lpfc_mbx_memory_dump_type3_link
,
2481 &mbox
->u
.mqe
.un
.mem_dump_type3
, phba
->sli4_hba
.physical_port
);
2482 bf_set(lpfc_mbx_memory_dump_type3_page_no
,
2483 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_PAGE_A0
);
2484 bf_set(lpfc_mbx_memory_dump_type3_length
,
2485 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_SFF_PAGE_A0_SIZE
);
2488 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_lo
= putPaddrLow(mp
->phys
);
2489 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_hi
= putPaddrHigh(mp
->phys
);
2495 * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
2496 * @phba: pointer to the hba structure containing the FCF index and RQ ID.
2497 * @mbox: pointer to lpfc mbox command to initialize.
2499 * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
2500 * SLI Host uses the command to activate an FCF after it has acquired FCF
2501 * information via a READ_FCF mailbox command. This mailbox command also is used
2502 * to indicate where received unsolicited frames from this FCF will be sent. By
2503 * default this routine will set up the FCF to forward all unsolicited frames
2504 * to the RQ ID passed in the @phba. This can be overridden by the caller for
2505 * more complicated setups.
2508 lpfc_reg_fcfi(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
2510 struct lpfc_mbx_reg_fcfi
*reg_fcfi
;
2512 memset(mbox
, 0, sizeof(*mbox
));
2513 reg_fcfi
= &mbox
->u
.mqe
.un
.reg_fcfi
;
2514 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_REG_FCFI
);
2515 if (phba
->nvmet_support
== 0) {
2516 bf_set(lpfc_reg_fcfi_rq_id0
, reg_fcfi
,
2517 phba
->sli4_hba
.hdr_rq
->queue_id
);
2518 /* Match everything - rq_id0 */
2519 bf_set(lpfc_reg_fcfi_type_match0
, reg_fcfi
, 0);
2520 bf_set(lpfc_reg_fcfi_type_mask0
, reg_fcfi
, 0);
2521 bf_set(lpfc_reg_fcfi_rctl_match0
, reg_fcfi
, 0);
2522 bf_set(lpfc_reg_fcfi_rctl_mask0
, reg_fcfi
, 0);
2524 bf_set(lpfc_reg_fcfi_rq_id1
, reg_fcfi
, REG_FCF_INVALID_QID
);
2526 /* addr mode is bit wise inverted value of fcf addr_mode */
2527 bf_set(lpfc_reg_fcfi_mam
, reg_fcfi
,
2528 (~phba
->fcf
.addr_mode
) & 0x3);
2530 /* This is ONLY for NVMET MRQ == 1 */
2531 if (phba
->cfg_nvmet_mrq
!= 1)
2534 bf_set(lpfc_reg_fcfi_rq_id0
, reg_fcfi
,
2535 phba
->sli4_hba
.nvmet_mrq_hdr
[0]->queue_id
);
2536 /* Match type FCP - rq_id0 */
2537 bf_set(lpfc_reg_fcfi_type_match0
, reg_fcfi
, FC_TYPE_FCP
);
2538 bf_set(lpfc_reg_fcfi_type_mask0
, reg_fcfi
, 0xff);
2539 bf_set(lpfc_reg_fcfi_rctl_match0
, reg_fcfi
,
2540 FC_RCTL_DD_UNSOL_CMD
);
2542 bf_set(lpfc_reg_fcfi_rq_id1
, reg_fcfi
,
2543 phba
->sli4_hba
.hdr_rq
->queue_id
);
2544 /* Match everything else - rq_id1 */
2545 bf_set(lpfc_reg_fcfi_type_match1
, reg_fcfi
, 0);
2546 bf_set(lpfc_reg_fcfi_type_mask1
, reg_fcfi
, 0);
2547 bf_set(lpfc_reg_fcfi_rctl_match1
, reg_fcfi
, 0);
2548 bf_set(lpfc_reg_fcfi_rctl_mask1
, reg_fcfi
, 0);
2550 bf_set(lpfc_reg_fcfi_rq_id2
, reg_fcfi
, REG_FCF_INVALID_QID
);
2551 bf_set(lpfc_reg_fcfi_rq_id3
, reg_fcfi
, REG_FCF_INVALID_QID
);
2552 bf_set(lpfc_reg_fcfi_info_index
, reg_fcfi
,
2553 phba
->fcf
.current_rec
.fcf_indx
);
2554 if (phba
->fcf
.current_rec
.vlan_id
!= LPFC_FCOE_NULL_VID
) {
2555 bf_set(lpfc_reg_fcfi_vv
, reg_fcfi
, 1);
2556 bf_set(lpfc_reg_fcfi_vlan_tag
, reg_fcfi
,
2557 phba
->fcf
.current_rec
.vlan_id
);
2562 * lpfc_reg_fcfi_mrq - Initialize the REG_FCFI_MRQ mailbox command
2563 * @phba: pointer to the hba structure containing the FCF index and RQ ID.
2564 * @mbox: pointer to lpfc mbox command to initialize.
2565 * @mode: 0 to register FCFI, 1 to register MRQs
2567 * The REG_FCFI_MRQ mailbox command supports Fibre Channel Forwarders (FCFs).
2568 * The SLI Host uses the command to activate an FCF after it has acquired FCF
2569 * information via a READ_FCF mailbox command. This mailbox command also is used
2570 * to indicate where received unsolicited frames from this FCF will be sent. By
2571 * default this routine will set up the FCF to forward all unsolicited frames
2572 * to the RQ ID passed in the @phba. This can be overridden by the caller for
2573 * more complicated setups.
2576 lpfc_reg_fcfi_mrq(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
, int mode
)
2578 struct lpfc_mbx_reg_fcfi_mrq
*reg_fcfi
;
2580 /* This is ONLY for MRQ */
2581 if (phba
->cfg_nvmet_mrq
<= 1)
2584 memset(mbox
, 0, sizeof(*mbox
));
2585 reg_fcfi
= &mbox
->u
.mqe
.un
.reg_fcfi_mrq
;
2586 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_REG_FCFI_MRQ
);
2588 bf_set(lpfc_reg_fcfi_mrq_info_index
, reg_fcfi
,
2589 phba
->fcf
.current_rec
.fcf_indx
);
2590 if (phba
->fcf
.current_rec
.vlan_id
!= LPFC_FCOE_NULL_VID
) {
2591 bf_set(lpfc_reg_fcfi_mrq_vv
, reg_fcfi
, 1);
2592 bf_set(lpfc_reg_fcfi_mrq_vlan_tag
, reg_fcfi
,
2593 phba
->fcf
.current_rec
.vlan_id
);
2598 bf_set(lpfc_reg_fcfi_mrq_rq_id0
, reg_fcfi
,
2599 phba
->sli4_hba
.nvmet_mrq_hdr
[0]->queue_id
);
2600 /* Match NVME frames of type FCP (protocol NVME) - rq_id0 */
2601 bf_set(lpfc_reg_fcfi_mrq_type_match0
, reg_fcfi
, FC_TYPE_FCP
);
2602 bf_set(lpfc_reg_fcfi_mrq_type_mask0
, reg_fcfi
, 0xff);
2603 bf_set(lpfc_reg_fcfi_mrq_rctl_match0
, reg_fcfi
, FC_RCTL_DD_UNSOL_CMD
);
2604 bf_set(lpfc_reg_fcfi_mrq_rctl_mask0
, reg_fcfi
, 0xff);
2605 bf_set(lpfc_reg_fcfi_mrq_ptc0
, reg_fcfi
, 1);
2606 bf_set(lpfc_reg_fcfi_mrq_pt0
, reg_fcfi
, 1);
2608 bf_set(lpfc_reg_fcfi_mrq_policy
, reg_fcfi
, 3); /* NVME connection id */
2609 bf_set(lpfc_reg_fcfi_mrq_mode
, reg_fcfi
, 1);
2610 bf_set(lpfc_reg_fcfi_mrq_filter
, reg_fcfi
, 1); /* rq_id0 */
2611 bf_set(lpfc_reg_fcfi_mrq_npairs
, reg_fcfi
, phba
->cfg_nvmet_mrq
);
2613 bf_set(lpfc_reg_fcfi_mrq_rq_id1
, reg_fcfi
,
2614 phba
->sli4_hba
.hdr_rq
->queue_id
);
2615 /* Match everything - rq_id1 */
2616 bf_set(lpfc_reg_fcfi_mrq_type_match1
, reg_fcfi
, 0);
2617 bf_set(lpfc_reg_fcfi_mrq_type_mask1
, reg_fcfi
, 0);
2618 bf_set(lpfc_reg_fcfi_mrq_rctl_match1
, reg_fcfi
, 0);
2619 bf_set(lpfc_reg_fcfi_mrq_rctl_mask1
, reg_fcfi
, 0);
2621 bf_set(lpfc_reg_fcfi_mrq_rq_id2
, reg_fcfi
, REG_FCF_INVALID_QID
);
2622 bf_set(lpfc_reg_fcfi_mrq_rq_id3
, reg_fcfi
, REG_FCF_INVALID_QID
);
2626 * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
2627 * @mbox: pointer to lpfc mbox command to initialize.
2628 * @fcfi: FCFI to be unregistered.
2630 * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
2631 * The SLI Host uses the command to inactivate an FCFI.
2634 lpfc_unreg_fcfi(struct lpfcMboxq
*mbox
, uint16_t fcfi
)
2636 memset(mbox
, 0, sizeof(*mbox
));
2637 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_UNREG_FCFI
);
2638 bf_set(lpfc_unreg_fcfi
, &mbox
->u
.mqe
.un
.unreg_fcfi
, fcfi
);
2642 * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
2643 * @mbox: pointer to lpfc mbox command to initialize.
2644 * @ndlp: The nodelist structure that describes the RPI to resume.
2646 * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
2650 lpfc_resume_rpi(struct lpfcMboxq
*mbox
, struct lpfc_nodelist
*ndlp
)
2652 struct lpfc_hba
*phba
= ndlp
->phba
;
2653 struct lpfc_mbx_resume_rpi
*resume_rpi
;
2655 memset(mbox
, 0, sizeof(*mbox
));
2656 resume_rpi
= &mbox
->u
.mqe
.un
.resume_rpi
;
2657 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_RESUME_RPI
);
2658 bf_set(lpfc_resume_rpi_index
, resume_rpi
,
2659 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
2660 bf_set(lpfc_resume_rpi_ii
, resume_rpi
, RESUME_INDEX_RPI
);
2661 resume_rpi
->event_tag
= ndlp
->phba
->fc_eventTag
;