1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited 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_dump_static_vport - Dump HBA's static vport information.
48 * @phba: pointer to lpfc hba data structure.
49 * @pmb: pointer to the driver internal queue element for mailbox command.
50 * @offset: offset for dumping vport info.
52 * The dump mailbox command provides a method for the device driver to obtain
53 * various types of information from the HBA device.
55 * This routine prepares the mailbox command for dumping list of static
56 * vports to be created.
59 lpfc_dump_static_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
,
63 struct lpfc_dmabuf
*mp
;
67 /* Setup to dump vport info region */
68 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
69 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
70 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
71 mb
->un
.varDmp
.entry_index
= offset
;
72 mb
->un
.varDmp
.region_id
= DMP_REGION_VPORT
;
73 mb
->mbxOwner
= OWN_HOST
;
75 /* For SLI3 HBAs data is embedded in mailbox */
76 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
78 mb
->un
.varDmp
.word_cnt
= DMP_RSP_SIZE
/sizeof(uint32_t);
82 /* For SLI4 HBAs driver need to allocate memory */
83 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
85 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
87 if (!mp
|| !mp
->virt
) {
89 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
90 "2605 lpfc_dump_static_vport: memory"
91 " allocation failed\n");
94 memset(mp
->virt
, 0, LPFC_BPL_SIZE
);
95 INIT_LIST_HEAD(&mp
->list
);
96 /* save address for completion */
97 pmb
->context1
= (uint8_t *)mp
;
98 mb
->un
.varWords
[3] = putPaddrLow(mp
->phys
);
99 mb
->un
.varWords
[4] = putPaddrHigh(mp
->phys
);
100 mb
->un
.varDmp
.sli4_length
= sizeof(struct static_vport_info
);
106 * lpfc_down_link - Bring down HBAs link.
107 * @phba: pointer to lpfc hba data structure.
108 * @pmb: pointer to the driver internal queue element for mailbox command.
110 * This routine prepares a mailbox command to bring down HBA link.
113 lpfc_down_link(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
116 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
118 mb
->mbxCommand
= MBX_DOWN_LINK
;
119 mb
->mbxOwner
= OWN_HOST
;
123 * lpfc_dump_mem - Prepare a mailbox command for reading a region.
124 * @phba: pointer to lpfc hba data structure.
125 * @pmb: pointer to the driver internal queue element for mailbox command.
126 * @offset: offset into the region.
127 * @region_id: config region id.
129 * The dump mailbox command provides a method for the device driver to obtain
130 * various types of information from the HBA device.
132 * This routine prepares the mailbox command for dumping HBA's config region.
135 lpfc_dump_mem(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
, uint16_t offset
,
144 /* Setup to dump VPD region */
145 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
146 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
147 mb
->un
.varDmp
.cv
= 1;
148 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
149 mb
->un
.varDmp
.entry_index
= offset
;
150 mb
->un
.varDmp
.region_id
= region_id
;
151 mb
->un
.varDmp
.word_cnt
= (DMP_RSP_SIZE
/ sizeof (uint32_t));
152 mb
->un
.varDmp
.co
= 0;
153 mb
->un
.varDmp
.resp_offset
= 0;
155 mb
->mbxOwner
= OWN_HOST
;
160 * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
161 * @phba: pointer to lpfc hba data structure.
162 * @pmb: pointer to the driver internal queue element for mailbox command.
164 * This function create a dump memory mailbox command to dump wake up
168 lpfc_dump_wakeup_param(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
174 /* Save context so that we can restore after memset */
177 /* Setup to dump VPD region */
178 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
179 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
180 mb
->mbxOwner
= OWN_HOST
;
181 mb
->un
.varDmp
.cv
= 1;
182 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
183 if (phba
->sli_rev
< LPFC_SLI_REV4
)
184 mb
->un
.varDmp
.entry_index
= 0;
185 mb
->un
.varDmp
.region_id
= WAKE_UP_PARMS_REGION_ID
;
186 mb
->un
.varDmp
.word_cnt
= WAKE_UP_PARMS_WORD_SIZE
;
187 mb
->un
.varDmp
.co
= 0;
188 mb
->un
.varDmp
.resp_offset
= 0;
194 * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
195 * @phba: pointer to lpfc hba data structure.
196 * @pmb: pointer to the driver internal queue element for mailbox command.
198 * The read NVRAM mailbox command returns the HBA's non-volatile parameters
199 * that are used as defaults when the Fibre Channel link is brought on-line.
201 * This routine prepares the mailbox command for reading information stored
202 * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
205 lpfc_read_nv(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
210 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
211 mb
->mbxCommand
= MBX_READ_NV
;
212 mb
->mbxOwner
= OWN_HOST
;
217 * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
218 * @phba: pointer to lpfc hba data structure.
219 * @pmb: pointer to the driver internal queue element for mailbox command.
220 * @ring: ring number for the asynchronous event to be configured.
222 * The asynchronous event enable mailbox command is used to enable the
223 * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
224 * specifies the default ring to which events are posted.
226 * This routine prepares the mailbox command for enabling HBA asynchronous
227 * event support on a IOCB ring.
230 lpfc_config_async(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
,
236 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
237 mb
->mbxCommand
= MBX_ASYNCEVT_ENABLE
;
238 mb
->un
.varCfgAsyncEvent
.ring
= ring
;
239 mb
->mbxOwner
= OWN_HOST
;
244 * lpfc_heart_beat - Prepare a mailbox command for heart beat
245 * @phba: pointer to lpfc hba data structure.
246 * @pmb: pointer to the driver internal queue element for mailbox command.
248 * The heart beat mailbox command is used to detect an unresponsive HBA, which
249 * is defined as any device where no error attention is sent and both mailbox
250 * and rings are not processed.
252 * This routine prepares the mailbox command for issuing a heart beat in the
253 * form of mailbox command to the HBA. The timely completion of the heart
254 * beat mailbox command indicates the health of the HBA.
257 lpfc_heart_beat(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
262 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
263 mb
->mbxCommand
= MBX_HEARTBEAT
;
264 mb
->mbxOwner
= OWN_HOST
;
269 * lpfc_read_topology - Prepare a mailbox command for reading HBA topology
270 * @phba: pointer to lpfc hba data structure.
271 * @pmb: pointer to the driver internal queue element for mailbox command.
272 * @mp: DMA buffer memory for reading the link attention information into.
274 * The read topology mailbox command is issued to read the link topology
275 * information indicated by the HBA port when the Link Event bit of the Host
276 * Attention (HSTATT) register is set to 1 (For SLI-3) or when an FC Link
277 * Attention ACQE is received from the port (For SLI-4). A Link Event
278 * Attention occurs based on an exception detected at the Fibre Channel link
281 * This routine prepares the mailbox command for reading HBA link topology
282 * information. A DMA memory has been set aside and address passed to the
283 * HBA through @mp for the HBA to DMA link attention information into the
284 * memory as part of the execution of the mailbox command.
287 * 0 - Success (currently always return 0)
290 lpfc_read_topology(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
,
291 struct lpfc_dmabuf
*mp
)
296 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
298 INIT_LIST_HEAD(&mp
->list
);
299 mb
->mbxCommand
= MBX_READ_TOPOLOGY
;
300 mb
->un
.varReadTop
.lilpBde64
.tus
.f
.bdeSize
= LPFC_ALPA_MAP_SIZE
;
301 mb
->un
.varReadTop
.lilpBde64
.addrHigh
= putPaddrHigh(mp
->phys
);
302 mb
->un
.varReadTop
.lilpBde64
.addrLow
= putPaddrLow(mp
->phys
);
304 /* Save address for later completion and set the owner to host so that
305 * the FW knows this mailbox is available for processing.
307 pmb
->context1
= (uint8_t *)mp
;
308 mb
->mbxOwner
= OWN_HOST
;
313 * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
314 * @phba: pointer to lpfc hba data structure.
315 * @pmb: pointer to the driver internal queue element for mailbox command.
317 * The clear link attention mailbox command is issued to clear the link event
318 * attention condition indicated by the Link Event bit of the Host Attention
319 * (HSTATT) register. The link event attention condition is cleared only if
320 * the event tag specified matches that of the current link event counter.
321 * The current event tag is read using the read link attention event mailbox
324 * This routine prepares the mailbox command for clearing HBA link attention
328 lpfc_clear_la(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
333 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
335 mb
->un
.varClearLA
.eventTag
= phba
->fc_eventTag
;
336 mb
->mbxCommand
= MBX_CLEAR_LA
;
337 mb
->mbxOwner
= OWN_HOST
;
342 * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
343 * @phba: pointer to lpfc hba data structure.
344 * @pmb: pointer to the driver internal queue element for mailbox command.
346 * The configure link mailbox command is used before the initialize link
347 * mailbox command to override default value and to configure link-oriented
348 * parameters such as DID address and various timers. Typically, this
349 * command would be used after an F_Port login to set the returned DID address
350 * and the fabric timeout values. This command is not valid before a configure
351 * port command has configured the HBA port.
353 * This routine prepares the mailbox command for configuring link on a HBA.
356 lpfc_config_link(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
358 struct lpfc_vport
*vport
= phba
->pport
;
359 MAILBOX_t
*mb
= &pmb
->u
.mb
;
360 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
363 * SLI-2, Coalescing Response Feature.
365 if (phba
->cfg_cr_delay
&& (phba
->sli_rev
< LPFC_SLI_REV4
)) {
366 mb
->un
.varCfgLnk
.cr
= 1;
367 mb
->un
.varCfgLnk
.ci
= 1;
368 mb
->un
.varCfgLnk
.cr_delay
= phba
->cfg_cr_delay
;
369 mb
->un
.varCfgLnk
.cr_count
= phba
->cfg_cr_count
;
372 mb
->un
.varCfgLnk
.myId
= vport
->fc_myDID
;
373 mb
->un
.varCfgLnk
.edtov
= phba
->fc_edtov
;
374 mb
->un
.varCfgLnk
.arbtov
= phba
->fc_arbtov
;
375 mb
->un
.varCfgLnk
.ratov
= phba
->fc_ratov
;
376 mb
->un
.varCfgLnk
.rttov
= phba
->fc_rttov
;
377 mb
->un
.varCfgLnk
.altov
= phba
->fc_altov
;
378 mb
->un
.varCfgLnk
.crtov
= phba
->fc_crtov
;
379 mb
->un
.varCfgLnk
.cscn
= 0;
380 if (phba
->bbcredit_support
&& phba
->cfg_enable_bbcr
) {
381 mb
->un
.varCfgLnk
.cscn
= 1;
382 mb
->un
.varCfgLnk
.bbscn
= bf_get(lpfc_bbscn_def
,
383 &phba
->sli4_hba
.bbscn_params
);
386 if (phba
->cfg_ack0
&& (phba
->sli_rev
< LPFC_SLI_REV4
))
387 mb
->un
.varCfgLnk
.ack0_enable
= 1;
389 mb
->mbxCommand
= MBX_CONFIG_LINK
;
390 mb
->mbxOwner
= OWN_HOST
;
395 * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
396 * @phba: pointer to lpfc hba data structure.
397 * @pmb: pointer to the driver internal queue element for mailbox command.
399 * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
400 * MSI-X multi-message interrupt vector association to interrupt attention
408 lpfc_config_msi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
410 MAILBOX_t
*mb
= &pmb
->u
.mb
;
411 uint32_t attentionConditions
[2];
414 if (phba
->cfg_use_msi
!= 2) {
415 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
416 "0475 Not configured for supporting MSI-X "
417 "cfg_use_msi: 0x%x\n", phba
->cfg_use_msi
);
421 if (phba
->sli_rev
< 3) {
422 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
423 "0476 HBA not supporting SLI-3 or later "
424 "SLI Revision: 0x%x\n", phba
->sli_rev
);
428 /* Clear mailbox command fields */
429 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
432 * SLI-3, Message Signaled Interrupt Fearure.
435 /* Multi-message attention configuration */
436 attentionConditions
[0] = (HA_R0ATT
| HA_R1ATT
| HA_R2ATT
| HA_ERATT
|
438 attentionConditions
[1] = 0;
440 mb
->un
.varCfgMSI
.attentionConditions
[0] = attentionConditions
[0];
441 mb
->un
.varCfgMSI
.attentionConditions
[1] = attentionConditions
[1];
444 * Set up message number to HA bit association
446 #ifdef __BIG_ENDIAN_BITFIELD
448 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R0_POS
] = 1;
449 /* RA1 (Other Protocol Extra Ring) */
450 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R1_POS
] = 1;
451 #else /* __LITTLE_ENDIAN_BITFIELD */
453 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R0_POS
^3] = 1;
454 /* RA1 (Other Protocol Extra Ring) */
455 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R1_POS
^3] = 1;
457 /* Multi-message interrupt autoclear configuration*/
458 mb
->un
.varCfgMSI
.autoClearHA
[0] = attentionConditions
[0];
459 mb
->un
.varCfgMSI
.autoClearHA
[1] = attentionConditions
[1];
461 /* For now, HBA autoclear does not work reliably, disable it */
462 mb
->un
.varCfgMSI
.autoClearHA
[0] = 0;
463 mb
->un
.varCfgMSI
.autoClearHA
[1] = 0;
465 /* Set command and owner bit */
466 mb
->mbxCommand
= MBX_CONFIG_MSI
;
467 mb
->mbxOwner
= OWN_HOST
;
473 * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
474 * @phba: pointer to lpfc hba data structure.
475 * @pmb: pointer to the driver internal queue element for mailbox command.
476 * @topology: the link topology for the link to be initialized to.
477 * @linkspeed: the link speed for the link to be initialized to.
479 * The initialize link mailbox command is used to initialize the Fibre
480 * Channel link. This command must follow a configure port command that
481 * establishes the mode of operation.
483 * This routine prepares the mailbox command for initializing link on a HBA
484 * with the specified link topology and speed.
487 lpfc_init_link(struct lpfc_hba
* phba
,
488 LPFC_MBOXQ_t
* pmb
, uint32_t topology
, uint32_t linkspeed
)
494 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
497 case FLAGS_TOPOLOGY_MODE_LOOP_PT
:
498 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_LOOP
;
499 mb
->un
.varInitLnk
.link_flags
|= FLAGS_TOPOLOGY_FAILOVER
;
501 case FLAGS_TOPOLOGY_MODE_PT_PT
:
502 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_PT_PT
;
504 case FLAGS_TOPOLOGY_MODE_LOOP
:
505 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_LOOP
;
507 case FLAGS_TOPOLOGY_MODE_PT_LOOP
:
508 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_PT_PT
;
509 mb
->un
.varInitLnk
.link_flags
|= FLAGS_TOPOLOGY_FAILOVER
;
512 mb
->un
.varInitLnk
.link_flags
= FLAGS_LOCAL_LB
;
516 if (phba
->pcidev
->device
== PCI_DEVICE_ID_LANCER_G6_FC
&&
517 mb
->un
.varInitLnk
.link_flags
& FLAGS_TOPOLOGY_MODE_LOOP
) {
518 /* Failover is not tried for Lancer G6 */
519 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_PT_PT
;
520 phba
->cfg_topology
= FLAGS_TOPOLOGY_MODE_PT_PT
;
523 /* Enable asynchronous ABTS responses from firmware */
524 mb
->un
.varInitLnk
.link_flags
|= FLAGS_IMED_ABORT
;
527 * Setting up the link speed
530 if (vpd
->rev
.feaLevelHigh
>= 0x02){
532 case LPFC_USER_LINK_SPEED_1G
:
533 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
534 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_1G
;
536 case LPFC_USER_LINK_SPEED_2G
:
537 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
538 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_2G
;
540 case LPFC_USER_LINK_SPEED_4G
:
541 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
542 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_4G
;
544 case LPFC_USER_LINK_SPEED_8G
:
545 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
546 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_8G
;
548 case LPFC_USER_LINK_SPEED_10G
:
549 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
550 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_10G
;
552 case LPFC_USER_LINK_SPEED_16G
:
553 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
554 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_16G
;
556 case LPFC_USER_LINK_SPEED_32G
:
557 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
558 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_32G
;
560 case LPFC_USER_LINK_SPEED_64G
:
561 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
562 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_64G
;
564 case LPFC_USER_LINK_SPEED_AUTO
:
566 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_AUTO
;
572 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_AUTO
;
574 mb
->mbxCommand
= (volatile uint8_t)MBX_INIT_LINK
;
575 mb
->mbxOwner
= OWN_HOST
;
576 mb
->un
.varInitLnk
.fabric_AL_PA
= phba
->fc_pref_ALPA
;
581 * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
582 * @phba: pointer to lpfc hba data structure.
583 * @pmb: pointer to the driver internal queue element for mailbox command.
584 * @vpi: virtual N_Port identifier.
586 * The read service parameter mailbox command is used to read the HBA port
587 * service parameters. The service parameters are read into the buffer
588 * specified directly by a BDE in the mailbox command. These service
589 * parameters may then be used to build the payload of an N_Port/F_POrt
590 * login request and reply (LOGI/ACC).
592 * This routine prepares the mailbox command for reading HBA port service
593 * parameters. The DMA memory is allocated in this function and the addresses
594 * are populated into the mailbox command for the HBA to DMA the service
599 * 1 - DMA memory allocation failed
602 lpfc_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
, int vpi
)
604 struct lpfc_dmabuf
*mp
;
608 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
610 mb
->mbxOwner
= OWN_HOST
;
612 /* Get a buffer to hold the HBAs Service Parameters */
614 mp
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
616 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
617 if (!mp
|| !mp
->virt
) {
619 mb
->mbxCommand
= MBX_READ_SPARM64
;
620 /* READ_SPARAM: no buffers */
621 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
622 "0301 READ_SPARAM: no buffers\n");
625 INIT_LIST_HEAD(&mp
->list
);
626 mb
->mbxCommand
= MBX_READ_SPARM64
;
627 mb
->un
.varRdSparm
.un
.sp64
.tus
.f
.bdeSize
= sizeof (struct serv_parm
);
628 mb
->un
.varRdSparm
.un
.sp64
.addrHigh
= putPaddrHigh(mp
->phys
);
629 mb
->un
.varRdSparm
.un
.sp64
.addrLow
= putPaddrLow(mp
->phys
);
630 if (phba
->sli_rev
>= LPFC_SLI_REV3
)
631 mb
->un
.varRdSparm
.vpi
= phba
->vpi_ids
[vpi
];
633 /* save address for completion */
640 * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
641 * @phba: pointer to lpfc hba data structure.
642 * @vpi: virtual N_Port identifier.
643 * @did: remote port identifier.
644 * @pmb: pointer to the driver internal queue element for mailbox command.
646 * The unregister DID mailbox command is used to unregister an N_Port/F_Port
647 * login for an unknown RPI by specifying the DID of a remote port. This
648 * command frees an RPI context in the HBA port. This has the effect of
649 * performing an implicit N_Port/F_Port logout.
651 * This routine prepares the mailbox command for unregistering a remote
652 * N_Port/F_Port (DID) login.
655 lpfc_unreg_did(struct lpfc_hba
* phba
, uint16_t vpi
, uint32_t did
,
661 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
663 mb
->un
.varUnregDID
.did
= did
;
664 mb
->un
.varUnregDID
.vpi
= vpi
;
665 if ((vpi
!= 0xffff) &&
666 (phba
->sli_rev
== LPFC_SLI_REV4
))
667 mb
->un
.varUnregDID
.vpi
= phba
->vpi_ids
[vpi
];
669 mb
->mbxCommand
= MBX_UNREG_D_ID
;
670 mb
->mbxOwner
= OWN_HOST
;
675 * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
676 * @phba: pointer to lpfc hba data structure.
677 * @pmb: pointer to the driver internal queue element for mailbox command.
679 * The read configuration mailbox command is used to read the HBA port
680 * configuration parameters. This mailbox command provides a method for
681 * seeing any parameters that may have changed via various configuration
684 * This routine prepares the mailbox command for reading out HBA configuration
688 lpfc_read_config(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
693 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
695 mb
->mbxCommand
= MBX_READ_CONFIG
;
696 mb
->mbxOwner
= OWN_HOST
;
701 * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
702 * @phba: pointer to lpfc hba data structure.
703 * @pmb: pointer to the driver internal queue element for mailbox command.
705 * The read link status mailbox command is used to read the link status from
706 * the HBA. Link status includes all link-related error counters. These
707 * counters are maintained by the HBA and originated in the link hardware
708 * unit. Note that all of these counters wrap.
710 * This routine prepares the mailbox command for reading out HBA link status.
713 lpfc_read_lnk_stat(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
718 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
720 mb
->mbxCommand
= MBX_READ_LNK_STAT
;
721 mb
->mbxOwner
= OWN_HOST
;
726 * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
727 * @phba: pointer to lpfc hba data structure.
728 * @vpi: virtual N_Port identifier.
729 * @did: remote port identifier.
730 * @param: pointer to memory holding the server parameters.
731 * @pmb: pointer to the driver internal queue element for mailbox command.
732 * @rpi: the rpi to use in the registration (usually only used for SLI4.
734 * The registration login mailbox command is used to register an N_Port or
735 * F_Port login. This registration allows the HBA to cache the remote N_Port
736 * service parameters internally and thereby make the appropriate FC-2
737 * decisions. The remote port service parameters are handed off by the driver
738 * to the HBA using a descriptor entry that directly identifies a buffer in
739 * host memory. In exchange, the HBA returns an RPI identifier.
741 * This routine prepares the mailbox command for registering remote port login.
742 * The function allocates DMA buffer for passing the service parameters to the
743 * HBA with the mailbox command.
747 * 1 - DMA memory allocation failed
750 lpfc_reg_rpi(struct lpfc_hba
*phba
, uint16_t vpi
, uint32_t did
,
751 uint8_t *param
, LPFC_MBOXQ_t
*pmb
, uint16_t rpi
)
753 MAILBOX_t
*mb
= &pmb
->u
.mb
;
755 struct lpfc_dmabuf
*mp
;
757 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
759 mb
->un
.varRegLogin
.rpi
= 0;
760 if (phba
->sli_rev
== LPFC_SLI_REV4
)
761 mb
->un
.varRegLogin
.rpi
= phba
->sli4_hba
.rpi_ids
[rpi
];
762 if (phba
->sli_rev
>= LPFC_SLI_REV3
)
763 mb
->un
.varRegLogin
.vpi
= phba
->vpi_ids
[vpi
];
764 mb
->un
.varRegLogin
.did
= did
;
765 mb
->mbxOwner
= OWN_HOST
;
766 /* Get a buffer to hold NPorts Service Parameters */
767 mp
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
769 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
770 if (!mp
|| !mp
->virt
) {
772 mb
->mbxCommand
= MBX_REG_LOGIN64
;
773 /* REG_LOGIN: no buffers */
774 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
775 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
776 "rpi x%x\n", vpi
, did
, rpi
);
779 INIT_LIST_HEAD(&mp
->list
);
782 /* Copy param's into a new buffer */
783 memcpy(sparam
, param
, sizeof (struct serv_parm
));
785 /* save address for completion */
786 pmb
->context1
= (uint8_t *) mp
;
788 mb
->mbxCommand
= MBX_REG_LOGIN64
;
789 mb
->un
.varRegLogin
.un
.sp64
.tus
.f
.bdeSize
= sizeof (struct serv_parm
);
790 mb
->un
.varRegLogin
.un
.sp64
.addrHigh
= putPaddrHigh(mp
->phys
);
791 mb
->un
.varRegLogin
.un
.sp64
.addrLow
= putPaddrLow(mp
->phys
);
797 * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
798 * @phba: pointer to lpfc hba data structure.
799 * @vpi: virtual N_Port identifier.
800 * @rpi: remote port identifier
801 * @pmb: pointer to the driver internal queue element for mailbox command.
803 * The unregistration login mailbox command is used to unregister an N_Port
804 * or F_Port login. This command frees an RPI context in the HBA. It has the
805 * effect of performing an implicit N_Port/F_Port logout.
807 * This routine prepares the mailbox command for unregistering remote port
810 * For SLI4 ports, the rpi passed to this function must be the physical
811 * rpi value, not the logical index.
814 lpfc_unreg_login(struct lpfc_hba
*phba
, uint16_t vpi
, uint32_t rpi
,
820 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
822 mb
->un
.varUnregLogin
.rpi
= rpi
;
823 mb
->un
.varUnregLogin
.rsvd1
= 0;
824 if (phba
->sli_rev
>= LPFC_SLI_REV3
)
825 mb
->un
.varUnregLogin
.vpi
= phba
->vpi_ids
[vpi
];
827 mb
->mbxCommand
= MBX_UNREG_LOGIN
;
828 mb
->mbxOwner
= OWN_HOST
;
834 * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA.
835 * @vport: pointer to a vport object.
837 * This routine sends mailbox command to unregister all active RPIs for
841 lpfc_sli4_unreg_all_rpis(struct lpfc_vport
*vport
)
843 struct lpfc_hba
*phba
= vport
->phba
;
847 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
850 * For SLI4 functions, the rpi field is overloaded for
851 * the vport context unreg all. This routine passes
852 * 0 for the rpi field in lpfc_unreg_login for compatibility
853 * with SLI3 and then overrides the rpi field with the
854 * expected value for SLI4.
856 lpfc_unreg_login(phba
, vport
->vpi
, phba
->vpi_ids
[vport
->vpi
],
858 mbox
->u
.mb
.un
.varUnregLogin
.rsvd1
= 0x4000;
860 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
861 mbox
->context1
= NULL
;
862 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
863 if (rc
== MBX_NOT_FINISHED
)
864 mempool_free(mbox
, phba
->mbox_mem_pool
);
869 * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
870 * @phba: pointer to lpfc hba data structure.
871 * @vpi: virtual N_Port identifier.
872 * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
873 * @pmb: pointer to the driver internal queue element for mailbox command.
875 * The registration vport identifier mailbox command is used to activate a
876 * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
877 * N_Port_ID against the information in the selected virtual N_Port context
878 * block and marks it active to allow normal processing of IOCB commands and
879 * received unsolicited exchanges.
881 * This routine prepares the mailbox command for registering a virtual N_Port.
884 lpfc_reg_vpi(struct lpfc_vport
*vport
, LPFC_MBOXQ_t
*pmb
)
886 MAILBOX_t
*mb
= &pmb
->u
.mb
;
887 struct lpfc_hba
*phba
= vport
->phba
;
889 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
891 * Set the re-reg VPI bit for f/w to update the MAC address.
893 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
894 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
))
895 mb
->un
.varRegVpi
.upd
= 1;
897 mb
->un
.varRegVpi
.vpi
= phba
->vpi_ids
[vport
->vpi
];
898 mb
->un
.varRegVpi
.sid
= vport
->fc_myDID
;
899 if (phba
->sli_rev
== LPFC_SLI_REV4
)
900 mb
->un
.varRegVpi
.vfi
= phba
->sli4_hba
.vfi_ids
[vport
->vfi
];
902 mb
->un
.varRegVpi
.vfi
= vport
->vfi
+ vport
->phba
->vfi_base
;
903 memcpy(mb
->un
.varRegVpi
.wwn
, &vport
->fc_portname
,
904 sizeof(struct lpfc_name
));
905 mb
->un
.varRegVpi
.wwn
[0] = cpu_to_le32(mb
->un
.varRegVpi
.wwn
[0]);
906 mb
->un
.varRegVpi
.wwn
[1] = cpu_to_le32(mb
->un
.varRegVpi
.wwn
[1]);
908 mb
->mbxCommand
= MBX_REG_VPI
;
909 mb
->mbxOwner
= OWN_HOST
;
915 * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
916 * @phba: pointer to lpfc hba data structure.
917 * @vpi: virtual N_Port identifier.
918 * @pmb: pointer to the driver internal queue element for mailbox command.
920 * The unregistration vport identifier mailbox command is used to inactivate
921 * a virtual N_Port. The driver must have logged out and unregistered all
922 * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
923 * unregisters any default RPIs associated with the specified vpi, aborting
924 * any active exchanges. The HBA will post the mailbox response after making
925 * the virtual N_Port inactive.
927 * This routine prepares the mailbox command for unregistering a virtual
931 lpfc_unreg_vpi(struct lpfc_hba
*phba
, uint16_t vpi
, LPFC_MBOXQ_t
*pmb
)
933 MAILBOX_t
*mb
= &pmb
->u
.mb
;
934 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
936 if (phba
->sli_rev
== LPFC_SLI_REV3
)
937 mb
->un
.varUnregVpi
.vpi
= phba
->vpi_ids
[vpi
];
938 else if (phba
->sli_rev
>= LPFC_SLI_REV4
)
939 mb
->un
.varUnregVpi
.sli4_vpi
= phba
->vpi_ids
[vpi
];
941 mb
->mbxCommand
= MBX_UNREG_VPI
;
942 mb
->mbxOwner
= OWN_HOST
;
948 * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
949 * @phba: pointer to lpfc hba data structure.
951 * This routine sets up and initializes the IOCB rings in the Port Control
955 lpfc_config_pcb_setup(struct lpfc_hba
* phba
)
957 struct lpfc_sli
*psli
= &phba
->sli
;
958 struct lpfc_sli_ring
*pring
;
959 PCB_t
*pcbp
= phba
->pcb
;
960 dma_addr_t pdma_addr
;
962 uint32_t iocbCnt
= 0;
965 pcbp
->maxRing
= (psli
->num_rings
- 1);
967 for (i
= 0; i
< psli
->num_rings
; i
++) {
968 pring
= &psli
->sli3_ring
[i
];
970 pring
->sli
.sli3
.sizeCiocb
=
971 phba
->sli_rev
== 3 ? SLI3_IOCB_CMD_SIZE
:
973 pring
->sli
.sli3
.sizeRiocb
=
974 phba
->sli_rev
== 3 ? SLI3_IOCB_RSP_SIZE
:
976 /* A ring MUST have both cmd and rsp entries defined to be
978 if ((pring
->sli
.sli3
.numCiocb
== 0) ||
979 (pring
->sli
.sli3
.numRiocb
== 0)) {
980 pcbp
->rdsc
[i
].cmdEntries
= 0;
981 pcbp
->rdsc
[i
].rspEntries
= 0;
982 pcbp
->rdsc
[i
].cmdAddrHigh
= 0;
983 pcbp
->rdsc
[i
].rspAddrHigh
= 0;
984 pcbp
->rdsc
[i
].cmdAddrLow
= 0;
985 pcbp
->rdsc
[i
].rspAddrLow
= 0;
986 pring
->sli
.sli3
.cmdringaddr
= NULL
;
987 pring
->sli
.sli3
.rspringaddr
= NULL
;
990 /* Command ring setup for ring */
991 pring
->sli
.sli3
.cmdringaddr
= (void *)&phba
->IOCBs
[iocbCnt
];
992 pcbp
->rdsc
[i
].cmdEntries
= pring
->sli
.sli3
.numCiocb
;
994 offset
= (uint8_t *) &phba
->IOCBs
[iocbCnt
] -
995 (uint8_t *) phba
->slim2p
.virt
;
996 pdma_addr
= phba
->slim2p
.phys
+ offset
;
997 pcbp
->rdsc
[i
].cmdAddrHigh
= putPaddrHigh(pdma_addr
);
998 pcbp
->rdsc
[i
].cmdAddrLow
= putPaddrLow(pdma_addr
);
999 iocbCnt
+= pring
->sli
.sli3
.numCiocb
;
1001 /* Response ring setup for ring */
1002 pring
->sli
.sli3
.rspringaddr
= (void *) &phba
->IOCBs
[iocbCnt
];
1004 pcbp
->rdsc
[i
].rspEntries
= pring
->sli
.sli3
.numRiocb
;
1005 offset
= (uint8_t *)&phba
->IOCBs
[iocbCnt
] -
1006 (uint8_t *)phba
->slim2p
.virt
;
1007 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1008 pcbp
->rdsc
[i
].rspAddrHigh
= putPaddrHigh(pdma_addr
);
1009 pcbp
->rdsc
[i
].rspAddrLow
= putPaddrLow(pdma_addr
);
1010 iocbCnt
+= pring
->sli
.sli3
.numRiocb
;
1015 * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
1016 * @phba: pointer to lpfc hba data structure.
1017 * @pmb: pointer to the driver internal queue element for mailbox command.
1019 * The read revision mailbox command is used to read the revision levels of
1020 * the HBA components. These components include hardware units, resident
1021 * firmware, and available firmware. HBAs that supports SLI-3 mode of
1022 * operation provide different response information depending on the version
1023 * requested by the driver.
1025 * This routine prepares the mailbox command for reading HBA revision
1029 lpfc_read_rev(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
1031 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1032 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
1033 mb
->un
.varRdRev
.cv
= 1;
1034 mb
->un
.varRdRev
.v3req
= 1; /* Request SLI3 info */
1035 mb
->mbxCommand
= MBX_READ_REV
;
1036 mb
->mbxOwner
= OWN_HOST
;
1041 lpfc_sli4_swap_str(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1043 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1044 struct lpfc_mqe
*mqe
;
1046 switch (mb
->mbxCommand
) {
1049 lpfc_sli_pcimem_bcopy(mqe
->un
.read_rev
.fw_name
,
1050 mqe
->un
.read_rev
.fw_name
, 16);
1051 lpfc_sli_pcimem_bcopy(mqe
->un
.read_rev
.ulp_fw_name
,
1052 mqe
->un
.read_rev
.ulp_fw_name
, 16);
1061 * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
1062 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1063 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1065 * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
1066 * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
1067 * the Sequence Length Test using the fields in the Selection Profile 2
1068 * extension in words 20:31.
1071 lpfc_build_hbq_profile2(struct config_hbq_var
*hbqmb
,
1072 struct lpfc_hbq_init
*hbq_desc
)
1074 hbqmb
->profiles
.profile2
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
1075 hbqmb
->profiles
.profile2
.maxlen
= hbq_desc
->maxlen
;
1076 hbqmb
->profiles
.profile2
.seqlenoff
= hbq_desc
->seqlenoff
;
1080 * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
1081 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1082 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1084 * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
1085 * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
1086 * the Sequence Length Test and Byte Field Test using the fields in the
1087 * Selection Profile 3 extension in words 20:31.
1090 lpfc_build_hbq_profile3(struct config_hbq_var
*hbqmb
,
1091 struct lpfc_hbq_init
*hbq_desc
)
1093 hbqmb
->profiles
.profile3
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
1094 hbqmb
->profiles
.profile3
.maxlen
= hbq_desc
->maxlen
;
1095 hbqmb
->profiles
.profile3
.cmdcodeoff
= hbq_desc
->cmdcodeoff
;
1096 hbqmb
->profiles
.profile3
.seqlenoff
= hbq_desc
->seqlenoff
;
1097 memcpy(&hbqmb
->profiles
.profile3
.cmdmatch
, hbq_desc
->cmdmatch
,
1098 sizeof(hbqmb
->profiles
.profile3
.cmdmatch
));
1102 * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
1103 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1104 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1106 * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
1107 * HBA tests the initial frame of an incoming sequence using the frame's
1108 * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
1109 * and Byte Field Test using the fields in the Selection Profile 5 extension
1113 lpfc_build_hbq_profile5(struct config_hbq_var
*hbqmb
,
1114 struct lpfc_hbq_init
*hbq_desc
)
1116 hbqmb
->profiles
.profile5
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
1117 hbqmb
->profiles
.profile5
.maxlen
= hbq_desc
->maxlen
;
1118 hbqmb
->profiles
.profile5
.cmdcodeoff
= hbq_desc
->cmdcodeoff
;
1119 hbqmb
->profiles
.profile5
.seqlenoff
= hbq_desc
->seqlenoff
;
1120 memcpy(&hbqmb
->profiles
.profile5
.cmdmatch
, hbq_desc
->cmdmatch
,
1121 sizeof(hbqmb
->profiles
.profile5
.cmdmatch
));
1125 * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
1126 * @phba: pointer to lpfc hba data structure.
1127 * @id: HBQ identifier.
1128 * @hbq_desc: pointer to the HBA descriptor data structure.
1129 * @hbq_entry_index: index of the HBQ entry data structures.
1130 * @pmb: pointer to the driver internal queue element for mailbox command.
1132 * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
1133 * an HBQ. The configuration binds events that require buffers to a particular
1134 * ring and HBQ based on a selection profile.
1136 * This routine prepares the mailbox command for configuring an HBQ.
1139 lpfc_config_hbq(struct lpfc_hba
*phba
, uint32_t id
,
1140 struct lpfc_hbq_init
*hbq_desc
,
1141 uint32_t hbq_entry_index
, LPFC_MBOXQ_t
*pmb
)
1144 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1145 struct config_hbq_var
*hbqmb
= &mb
->un
.varCfgHbq
;
1147 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
1149 hbqmb
->entry_count
= hbq_desc
->entry_count
; /* # entries in HBQ */
1150 hbqmb
->recvNotify
= hbq_desc
->rn
; /* Receive
1152 hbqmb
->numMask
= hbq_desc
->mask_count
; /* # R_CTL/TYPE masks
1153 * # in words 0-19 */
1154 hbqmb
->profile
= hbq_desc
->profile
; /* Selection profile:
1157 hbqmb
->ringMask
= hbq_desc
->ring_mask
; /* Binds HBQ to a ring
1160 hbqmb
->headerLen
= hbq_desc
->headerLen
; /* 0 if not profile 4
1162 hbqmb
->logEntry
= hbq_desc
->logEntry
; /* Set to 1 if this
1166 hbqmb
->hbqaddrLow
= putPaddrLow(phba
->hbqslimp
.phys
) +
1167 hbq_entry_index
* sizeof(struct lpfc_hbq_entry
);
1168 hbqmb
->hbqaddrHigh
= putPaddrHigh(phba
->hbqslimp
.phys
);
1170 mb
->mbxCommand
= MBX_CONFIG_HBQ
;
1171 mb
->mbxOwner
= OWN_HOST
;
1173 /* Copy info for profiles 2,3,5. Other
1174 * profiles this area is reserved
1176 if (hbq_desc
->profile
== 2)
1177 lpfc_build_hbq_profile2(hbqmb
, hbq_desc
);
1178 else if (hbq_desc
->profile
== 3)
1179 lpfc_build_hbq_profile3(hbqmb
, hbq_desc
);
1180 else if (hbq_desc
->profile
== 5)
1181 lpfc_build_hbq_profile5(hbqmb
, hbq_desc
);
1183 /* Return if no rctl / type masks for this HBQ */
1184 if (!hbq_desc
->mask_count
)
1187 /* Otherwise we setup specific rctl / type masks for this HBQ */
1188 for (i
= 0; i
< hbq_desc
->mask_count
; i
++) {
1189 hbqmb
->hbqMasks
[i
].tmatch
= hbq_desc
->hbqMasks
[i
].tmatch
;
1190 hbqmb
->hbqMasks
[i
].tmask
= hbq_desc
->hbqMasks
[i
].tmask
;
1191 hbqmb
->hbqMasks
[i
].rctlmatch
= hbq_desc
->hbqMasks
[i
].rctlmatch
;
1192 hbqmb
->hbqMasks
[i
].rctlmask
= hbq_desc
->hbqMasks
[i
].rctlmask
;
1199 * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
1200 * @phba: pointer to lpfc hba data structure.
1202 * @pmb: pointer to the driver internal queue element for mailbox command.
1204 * The configure ring mailbox command is used to configure an IOCB ring. This
1205 * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1206 * ring. This is used to map incoming sequences to a particular ring whose
1207 * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1208 * attempt to configure a ring whose number is greater than the number
1209 * specified in the Port Control Block (PCB). It is an error to issue the
1210 * configure ring command more than once with the same ring number. The HBA
1211 * returns an error if the driver attempts this.
1213 * This routine prepares the mailbox command for configuring IOCB ring.
1216 lpfc_config_ring(struct lpfc_hba
* phba
, int ring
, LPFC_MBOXQ_t
* pmb
)
1219 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1220 struct lpfc_sli
*psli
;
1221 struct lpfc_sli_ring
*pring
;
1223 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
1225 mb
->un
.varCfgRing
.ring
= ring
;
1226 mb
->un
.varCfgRing
.maxOrigXchg
= 0;
1227 mb
->un
.varCfgRing
.maxRespXchg
= 0;
1228 mb
->un
.varCfgRing
.recvNotify
= 1;
1231 pring
= &psli
->sli3_ring
[ring
];
1232 mb
->un
.varCfgRing
.numMask
= pring
->num_mask
;
1233 mb
->mbxCommand
= MBX_CONFIG_RING
;
1234 mb
->mbxOwner
= OWN_HOST
;
1236 /* Is this ring configured for a specific profile */
1237 if (pring
->prt
[0].profile
) {
1238 mb
->un
.varCfgRing
.profile
= pring
->prt
[0].profile
;
1242 /* Otherwise we setup specific rctl / type masks for this ring */
1243 for (i
= 0; i
< pring
->num_mask
; i
++) {
1244 mb
->un
.varCfgRing
.rrRegs
[i
].rval
= pring
->prt
[i
].rctl
;
1245 if (mb
->un
.varCfgRing
.rrRegs
[i
].rval
!= FC_RCTL_ELS_REQ
)
1246 mb
->un
.varCfgRing
.rrRegs
[i
].rmask
= 0xff;
1248 mb
->un
.varCfgRing
.rrRegs
[i
].rmask
= 0xfe;
1249 mb
->un
.varCfgRing
.rrRegs
[i
].tval
= pring
->prt
[i
].type
;
1250 mb
->un
.varCfgRing
.rrRegs
[i
].tmask
= 0xff;
1257 * lpfc_config_port - Prepare a mailbox command for configuring port
1258 * @phba: pointer to lpfc hba data structure.
1259 * @pmb: pointer to the driver internal queue element for mailbox command.
1261 * The configure port mailbox command is used to identify the Port Control
1262 * Block (PCB) in the driver memory. After this command is issued, the
1263 * driver must not access the mailbox in the HBA without first resetting
1264 * the HBA. The HBA may copy the PCB information to internal storage for
1265 * subsequent use; the driver can not change the PCB information unless it
1268 * This routine prepares the mailbox command for configuring port.
1271 lpfc_config_port(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1273 MAILBOX_t __iomem
*mb_slim
= (MAILBOX_t __iomem
*) phba
->MBslimaddr
;
1274 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1275 dma_addr_t pdma_addr
;
1276 uint32_t bar_low
, bar_high
;
1278 struct lpfc_hgp hgp
;
1280 uint32_t pgp_offset
;
1282 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
1283 mb
->mbxCommand
= MBX_CONFIG_PORT
;
1284 mb
->mbxOwner
= OWN_HOST
;
1286 mb
->un
.varCfgPort
.pcbLen
= sizeof(PCB_t
);
1288 offset
= (uint8_t *)phba
->pcb
- (uint8_t *)phba
->slim2p
.virt
;
1289 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1290 mb
->un
.varCfgPort
.pcbLow
= putPaddrLow(pdma_addr
);
1291 mb
->un
.varCfgPort
.pcbHigh
= putPaddrHigh(pdma_addr
);
1293 /* Always Host Group Pointer is in SLIM */
1294 mb
->un
.varCfgPort
.hps
= 1;
1296 /* If HBA supports SLI=3 ask for it */
1298 if (phba
->sli_rev
== LPFC_SLI_REV3
&& phba
->vpd
.sli3Feat
.cerbm
) {
1299 if (phba
->cfg_enable_bg
)
1300 mb
->un
.varCfgPort
.cbg
= 1; /* configure BlockGuard */
1301 if (phba
->cfg_enable_dss
)
1302 mb
->un
.varCfgPort
.cdss
= 1; /* Configure Security */
1303 mb
->un
.varCfgPort
.cerbm
= 1; /* Request HBQs */
1304 mb
->un
.varCfgPort
.ccrp
= 1; /* Command Ring Polling */
1305 mb
->un
.varCfgPort
.max_hbq
= lpfc_sli_hbq_count();
1306 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
1307 phba
->vpd
.sli3Feat
.cmv
) {
1308 mb
->un
.varCfgPort
.max_vpi
= LPFC_MAX_VPI
;
1309 mb
->un
.varCfgPort
.cmv
= 1;
1311 mb
->un
.varCfgPort
.max_vpi
= phba
->max_vpi
= 0;
1313 phba
->sli_rev
= LPFC_SLI_REV2
;
1314 mb
->un
.varCfgPort
.sli_mode
= phba
->sli_rev
;
1316 /* If this is an SLI3 port, configure async status notification. */
1317 if (phba
->sli_rev
== LPFC_SLI_REV3
)
1318 mb
->un
.varCfgPort
.casabt
= 1;
1321 phba
->pcb
->type
= TYPE_NATIVE_SLI2
;
1322 phba
->pcb
->feature
= FEATURE_INITIAL_SLI2
;
1324 /* Setup Mailbox pointers */
1325 phba
->pcb
->mailBoxSize
= sizeof(MAILBOX_t
) + MAILBOX_EXT_SIZE
;
1326 offset
= (uint8_t *)phba
->mbox
- (uint8_t *)phba
->slim2p
.virt
;
1327 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1328 phba
->pcb
->mbAddrHigh
= putPaddrHigh(pdma_addr
);
1329 phba
->pcb
->mbAddrLow
= putPaddrLow(pdma_addr
);
1332 * Setup Host Group ring pointer.
1334 * For efficiency reasons, the ring get/put pointers can be
1335 * placed in adapter memory (SLIM) rather than in host memory.
1336 * This allows firmware to avoid PCI reads/writes when updating
1337 * and checking pointers.
1339 * The firmware recognizes the use of SLIM memory by comparing
1340 * the address of the get/put pointers structure with that of
1341 * the SLIM BAR (BAR0).
1343 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1344 * (the hardware's view of the base address), not the OS's
1345 * value of pci_resource_start() as the OS value may be a cookie
1346 * for ioremap/iomap.
1350 pci_read_config_dword(phba
->pcidev
, PCI_BASE_ADDRESS_0
, &bar_low
);
1351 pci_read_config_dword(phba
->pcidev
, PCI_BASE_ADDRESS_1
, &bar_high
);
1354 * Set up HGP - Port Memory
1356 * The port expects the host get/put pointers to reside in memory
1357 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1358 * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
1359 * words (0x40 bytes). This area is not reserved if HBQs are
1360 * configured in SLI-3.
1362 * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1371 * Reserved 0xa0-0xbf
1372 * If HBQs configured:
1373 * HBQ 0 Put ptr 0xc0
1374 * HBQ 1 Put ptr 0xc4
1375 * HBQ 2 Put ptr 0xc8
1377 * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1381 if (phba
->cfg_hostmem_hgp
&& phba
->sli_rev
!= 3) {
1382 phba
->host_gp
= &phba
->mbox
->us
.s2
.host
[0];
1383 phba
->hbq_put
= NULL
;
1384 offset
= (uint8_t *)&phba
->mbox
->us
.s2
.host
-
1385 (uint8_t *)phba
->slim2p
.virt
;
1386 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1387 phba
->pcb
->hgpAddrHigh
= putPaddrHigh(pdma_addr
);
1388 phba
->pcb
->hgpAddrLow
= putPaddrLow(pdma_addr
);
1390 /* Always Host Group Pointer is in SLIM */
1391 mb
->un
.varCfgPort
.hps
= 1;
1393 if (phba
->sli_rev
== 3) {
1394 phba
->host_gp
= &mb_slim
->us
.s3
.host
[0];
1395 phba
->hbq_put
= &mb_slim
->us
.s3
.hbq_put
[0];
1397 phba
->host_gp
= &mb_slim
->us
.s2
.host
[0];
1398 phba
->hbq_put
= NULL
;
1401 /* mask off BAR0's flag bits 0 - 3 */
1402 phba
->pcb
->hgpAddrLow
= (bar_low
& PCI_BASE_ADDRESS_MEM_MASK
) +
1403 (void __iomem
*)phba
->host_gp
-
1404 (void __iomem
*)phba
->MBslimaddr
;
1405 if (bar_low
& PCI_BASE_ADDRESS_MEM_TYPE_64
)
1406 phba
->pcb
->hgpAddrHigh
= bar_high
;
1408 phba
->pcb
->hgpAddrHigh
= 0;
1409 /* write HGP data to SLIM at the required longword offset */
1410 memset(&hgp
, 0, sizeof(struct lpfc_hgp
));
1412 for (i
= 0; i
< phba
->sli
.num_rings
; i
++) {
1413 lpfc_memcpy_to_slim(phba
->host_gp
+ i
, &hgp
,
1414 sizeof(*phba
->host_gp
));
1418 /* Setup Port Group offset */
1419 if (phba
->sli_rev
== 3)
1420 pgp_offset
= offsetof(struct lpfc_sli2_slim
,
1421 mbx
.us
.s3_pgp
.port
);
1423 pgp_offset
= offsetof(struct lpfc_sli2_slim
, mbx
.us
.s2
.port
);
1424 pdma_addr
= phba
->slim2p
.phys
+ pgp_offset
;
1425 phba
->pcb
->pgpAddrHigh
= putPaddrHigh(pdma_addr
);
1426 phba
->pcb
->pgpAddrLow
= putPaddrLow(pdma_addr
);
1428 /* Use callback routine to setp rings in the pcb */
1429 lpfc_config_pcb_setup(phba
);
1431 /* special handling for LC HBAs */
1432 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
1433 uint32_t hbainit
[5];
1435 lpfc_hba_init(phba
, hbainit
);
1437 memcpy(&mb
->un
.varCfgPort
.hbainit
, hbainit
, 20);
1440 /* Swap PCB if needed */
1441 lpfc_sli_pcimem_bcopy(phba
->pcb
, phba
->pcb
, sizeof(PCB_t
));
1445 * lpfc_kill_board - Prepare a mailbox command for killing board
1446 * @phba: pointer to lpfc hba data structure.
1447 * @pmb: pointer to the driver internal queue element for mailbox command.
1449 * The kill board mailbox command is used to tell firmware to perform a
1450 * graceful shutdown of a channel on a specified board to prepare for reset.
1451 * When the kill board mailbox command is received, the ER3 bit is set to 1
1452 * in the Host Status register and the ER Attention bit is set to 1 in the
1453 * Host Attention register of the HBA function that received the kill board
1456 * This routine prepares the mailbox command for killing the board in
1457 * preparation for a graceful shutdown.
1460 lpfc_kill_board(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
1462 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1464 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
1465 mb
->mbxCommand
= MBX_KILL_BOARD
;
1466 mb
->mbxOwner
= OWN_HOST
;
1471 * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
1472 * @phba: pointer to lpfc hba data structure.
1473 * @mbq: pointer to the driver internal queue element for mailbox command.
1475 * Driver maintains a internal mailbox command queue implemented as a linked
1476 * list. When a mailbox command is issued, it shall be put into the mailbox
1477 * command queue such that they shall be processed orderly as HBA can process
1478 * one mailbox command at a time.
1481 lpfc_mbox_put(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* mbq
)
1483 struct lpfc_sli
*psli
;
1487 list_add_tail(&mbq
->list
, &psli
->mboxq
);
1495 * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
1496 * @phba: pointer to lpfc hba data structure.
1498 * Driver maintains a internal mailbox command queue implemented as a linked
1499 * list. When a mailbox command is issued, it shall be put into the mailbox
1500 * command queue such that they shall be processed orderly as HBA can process
1501 * one mailbox command at a time. After HBA finished processing a mailbox
1502 * command, the driver will remove a pending mailbox command from the head of
1503 * the mailbox command queue and send to the HBA for processing.
1506 * pointer to the driver internal queue element for mailbox command.
1509 lpfc_mbox_get(struct lpfc_hba
* phba
)
1511 LPFC_MBOXQ_t
*mbq
= NULL
;
1512 struct lpfc_sli
*psli
= &phba
->sli
;
1514 list_remove_head((&psli
->mboxq
), mbq
, LPFC_MBOXQ_t
, list
);
1522 * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
1523 * @phba: pointer to lpfc hba data structure.
1524 * @mbq: pointer to the driver internal queue element for mailbox command.
1526 * This routine put the completed mailbox command into the mailbox command
1527 * complete list. This is the unlocked version of the routine. The mailbox
1528 * complete list is used by the driver worker thread to process mailbox
1529 * complete callback functions outside the driver interrupt handler.
1532 __lpfc_mbox_cmpl_put(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbq
)
1534 list_add_tail(&mbq
->list
, &phba
->sli
.mboxq_cmpl
);
1538 * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
1539 * @phba: pointer to lpfc hba data structure.
1540 * @mbq: pointer to the driver internal queue element for mailbox command.
1542 * This routine put the completed mailbox command into the mailbox command
1543 * complete list. This is the locked version of the routine. The mailbox
1544 * complete list is used by the driver worker thread to process mailbox
1545 * complete callback functions outside the driver interrupt handler.
1548 lpfc_mbox_cmpl_put(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbq
)
1550 unsigned long iflag
;
1552 /* This function expects to be called from interrupt context */
1553 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1554 __lpfc_mbox_cmpl_put(phba
, mbq
);
1555 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1560 * lpfc_mbox_cmd_check - Check the validality of a mailbox command
1561 * @phba: pointer to lpfc hba data structure.
1562 * @mboxq: pointer to the driver internal queue element for mailbox command.
1564 * This routine is to check whether a mailbox command is valid to be issued.
1565 * This check will be performed by both the mailbox issue API when a client
1566 * is to issue a mailbox command to the mailbox transport.
1568 * Return 0 - pass the check, -ENODEV - fail the check
1571 lpfc_mbox_cmd_check(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1573 /* Mailbox command that have a completion handler must also have a
1576 if (mboxq
->mbox_cmpl
&& mboxq
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
1577 mboxq
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
1578 if (!mboxq
->vport
) {
1579 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
1580 "1814 Mbox x%x failed, no vport\n",
1581 mboxq
->u
.mb
.mbxCommand
);
1590 * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
1591 * @phba: pointer to lpfc hba data structure.
1593 * This routine is to check whether the HBA device is ready for posting a
1594 * mailbox command. It is used by the mailbox transport API at the time the
1595 * to post a mailbox command to the device.
1597 * Return 0 - pass the check, -ENODEV - fail the check
1600 lpfc_mbox_dev_check(struct lpfc_hba
*phba
)
1602 /* If the PCI channel is in offline state, do not issue mbox */
1603 if (unlikely(pci_channel_offline(phba
->pcidev
)))
1606 /* If the HBA is in error state, do not issue mbox */
1607 if (phba
->link_state
== LPFC_HBA_ERROR
)
1614 * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
1615 * @phba: pointer to lpfc hba data structure.
1616 * @cmd: mailbox command code.
1618 * This routine retrieves the proper timeout value according to the mailbox
1622 * Timeout value to be used for the given mailbox command
1625 lpfc_mbox_tmo_val(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1627 MAILBOX_t
*mbox
= &mboxq
->u
.mb
;
1628 uint8_t subsys
, opcode
;
1630 switch (mbox
->mbxCommand
) {
1631 case MBX_WRITE_NV
: /* 0x03 */
1632 case MBX_DUMP_MEMORY
: /* 0x17 */
1633 case MBX_UPDATE_CFG
: /* 0x1B */
1634 case MBX_DOWN_LOAD
: /* 0x1C */
1635 case MBX_DEL_LD_ENTRY
: /* 0x1D */
1636 case MBX_WRITE_VPARMS
: /* 0x32 */
1637 case MBX_LOAD_AREA
: /* 0x81 */
1638 case MBX_WRITE_WWN
: /* 0x98 */
1639 case MBX_LOAD_EXP_ROM
: /* 0x9C */
1640 case MBX_ACCESS_VDATA
: /* 0xA5 */
1641 return LPFC_MBOX_TMO_FLASH_CMD
;
1642 case MBX_SLI4_CONFIG
: /* 0x9b */
1643 subsys
= lpfc_sli_config_mbox_subsys_get(phba
, mboxq
);
1644 opcode
= lpfc_sli_config_mbox_opcode_get(phba
, mboxq
);
1645 if (subsys
== LPFC_MBOX_SUBSYSTEM_COMMON
) {
1647 case LPFC_MBOX_OPCODE_READ_OBJECT
:
1648 case LPFC_MBOX_OPCODE_WRITE_OBJECT
:
1649 case LPFC_MBOX_OPCODE_READ_OBJECT_LIST
:
1650 case LPFC_MBOX_OPCODE_DELETE_OBJECT
:
1651 case LPFC_MBOX_OPCODE_GET_PROFILE_LIST
:
1652 case LPFC_MBOX_OPCODE_SET_ACT_PROFILE
:
1653 case LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG
:
1654 case LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG
:
1655 case LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG
:
1656 case LPFC_MBOX_OPCODE_GET_PROFILE_CAPACITIES
:
1657 case LPFC_MBOX_OPCODE_SEND_ACTIVATION
:
1658 case LPFC_MBOX_OPCODE_RESET_LICENSES
:
1659 case LPFC_MBOX_OPCODE_SET_BOOT_CONFIG
:
1660 case LPFC_MBOX_OPCODE_GET_VPD_DATA
:
1661 case LPFC_MBOX_OPCODE_SET_PHYSICAL_LINK_CONFIG
:
1662 return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO
;
1665 if (subsys
== LPFC_MBOX_SUBSYSTEM_FCOE
) {
1667 case LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS
:
1668 return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO
;
1671 return LPFC_MBOX_SLI4_CONFIG_TMO
;
1673 return LPFC_MBOX_TMO
;
1677 * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
1678 * @mbox: pointer to lpfc mbox command.
1679 * @sgentry: sge entry index.
1680 * @phyaddr: physical address for the sge
1681 * @length: Length of the sge.
1683 * This routine sets up an entry in the non-embedded mailbox command at the sge
1687 lpfc_sli4_mbx_sge_set(struct lpfcMboxq
*mbox
, uint32_t sgentry
,
1688 dma_addr_t phyaddr
, uint32_t length
)
1690 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
1692 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
1693 &mbox
->u
.mqe
.un
.nembed_cmd
;
1694 nembed_sge
->sge
[sgentry
].pa_lo
= putPaddrLow(phyaddr
);
1695 nembed_sge
->sge
[sgentry
].pa_hi
= putPaddrHigh(phyaddr
);
1696 nembed_sge
->sge
[sgentry
].length
= length
;
1700 * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
1701 * @mbox: pointer to lpfc mbox command.
1702 * @sgentry: sge entry index.
1704 * This routine gets an entry from the non-embedded mailbox command at the sge
1708 lpfc_sli4_mbx_sge_get(struct lpfcMboxq
*mbox
, uint32_t sgentry
,
1709 struct lpfc_mbx_sge
*sge
)
1711 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
1713 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
1714 &mbox
->u
.mqe
.un
.nembed_cmd
;
1715 sge
->pa_lo
= nembed_sge
->sge
[sgentry
].pa_lo
;
1716 sge
->pa_hi
= nembed_sge
->sge
[sgentry
].pa_hi
;
1717 sge
->length
= nembed_sge
->sge
[sgentry
].length
;
1721 * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
1722 * @phba: pointer to lpfc hba data structure.
1723 * @mbox: pointer to lpfc mbox command.
1725 * This routine frees SLI4 specific mailbox command for sending IOCTL command.
1728 lpfc_sli4_mbox_cmd_free(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
1730 struct lpfc_mbx_sli4_config
*sli4_cfg
;
1731 struct lpfc_mbx_sge sge
;
1733 uint32_t sgecount
, sgentry
;
1735 sli4_cfg
= &mbox
->u
.mqe
.un
.sli4_config
;
1737 /* For embedded mbox command, just free the mbox command */
1738 if (bf_get(lpfc_mbox_hdr_emb
, &sli4_cfg
->header
.cfg_mhdr
)) {
1739 mempool_free(mbox
, phba
->mbox_mem_pool
);
1743 /* For non-embedded mbox command, we need to free the pages first */
1744 sgecount
= bf_get(lpfc_mbox_hdr_sge_cnt
, &sli4_cfg
->header
.cfg_mhdr
);
1745 /* There is nothing we can do if there is no sge address array */
1746 if (unlikely(!mbox
->sge_array
)) {
1747 mempool_free(mbox
, phba
->mbox_mem_pool
);
1750 /* Each non-embedded DMA memory was allocated in the length of a page */
1751 for (sgentry
= 0; sgentry
< sgecount
; sgentry
++) {
1752 lpfc_sli4_mbx_sge_get(mbox
, sgentry
, &sge
);
1753 phyaddr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
1754 dma_free_coherent(&phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
1755 mbox
->sge_array
->addr
[sgentry
], phyaddr
);
1757 /* Free the sge address array memory */
1758 kfree(mbox
->sge_array
);
1759 /* Finally, free the mailbox command itself */
1760 mempool_free(mbox
, phba
->mbox_mem_pool
);
1764 * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command
1765 * @phba: pointer to lpfc hba data structure.
1766 * @mbox: pointer to lpfc mbox command.
1767 * @subsystem: The sli4 config sub mailbox subsystem.
1768 * @opcode: The sli4 config sub mailbox command opcode.
1769 * @length: Length of the sli4 config mailbox command (including sub-header).
1771 * This routine sets up the header fields of SLI4 specific mailbox command
1772 * for sending IOCTL command.
1774 * Return: the actual length of the mbox command allocated (mostly useful
1775 * for none embedded mailbox command).
1778 lpfc_sli4_config(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
,
1779 uint8_t subsystem
, uint8_t opcode
, uint32_t length
, bool emb
)
1781 struct lpfc_mbx_sli4_config
*sli4_config
;
1782 union lpfc_sli4_cfg_shdr
*cfg_shdr
= NULL
;
1785 uint32_t pagen
, pcount
;
1789 /* Set up SLI4 mailbox command header fields */
1790 memset(mbox
, 0, sizeof(*mbox
));
1791 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_SLI4_CONFIG
);
1793 /* Set up SLI4 ioctl command header fields */
1794 sli4_config
= &mbox
->u
.mqe
.un
.sli4_config
;
1796 /* Setup for the embedded mbox command */
1798 /* Set up main header fields */
1799 bf_set(lpfc_mbox_hdr_emb
, &sli4_config
->header
.cfg_mhdr
, 1);
1800 sli4_config
->header
.cfg_mhdr
.payload_length
= length
;
1801 /* Set up sub-header fields following main header */
1802 bf_set(lpfc_mbox_hdr_opcode
,
1803 &sli4_config
->header
.cfg_shdr
.request
, opcode
);
1804 bf_set(lpfc_mbox_hdr_subsystem
,
1805 &sli4_config
->header
.cfg_shdr
.request
, subsystem
);
1806 sli4_config
->header
.cfg_shdr
.request
.request_length
=
1807 length
- LPFC_MBX_CMD_HDR_LENGTH
;
1811 /* Setup for the non-embedded mbox command */
1812 pcount
= (SLI4_PAGE_ALIGN(length
))/SLI4_PAGE_SIZE
;
1813 pcount
= (pcount
> LPFC_SLI4_MBX_SGE_MAX_PAGES
) ?
1814 LPFC_SLI4_MBX_SGE_MAX_PAGES
: pcount
;
1815 /* Allocate record for keeping SGE virtual addresses */
1816 mbox
->sge_array
= kzalloc(sizeof(struct lpfc_mbx_nembed_sge_virt
),
1818 if (!mbox
->sge_array
) {
1819 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1820 "2527 Failed to allocate non-embedded SGE "
1824 for (pagen
= 0, alloc_len
= 0; pagen
< pcount
; pagen
++) {
1825 /* The DMA memory is always allocated in the length of a
1826 * page even though the last SGE might not fill up to a
1827 * page, this is used as a priori size of SLI4_PAGE_SIZE for
1828 * the later DMA memory free.
1830 viraddr
= dma_zalloc_coherent(&phba
->pcidev
->dev
,
1831 SLI4_PAGE_SIZE
, &phyaddr
,
1833 /* In case of malloc fails, proceed with whatever we have */
1836 mbox
->sge_array
->addr
[pagen
] = viraddr
;
1837 /* Keep the first page for later sub-header construction */
1839 cfg_shdr
= (union lpfc_sli4_cfg_shdr
*)viraddr
;
1840 resid_len
= length
- alloc_len
;
1841 if (resid_len
> SLI4_PAGE_SIZE
) {
1842 lpfc_sli4_mbx_sge_set(mbox
, pagen
, phyaddr
,
1844 alloc_len
+= SLI4_PAGE_SIZE
;
1846 lpfc_sli4_mbx_sge_set(mbox
, pagen
, phyaddr
,
1852 /* Set up main header fields in mailbox command */
1853 sli4_config
->header
.cfg_mhdr
.payload_length
= alloc_len
;
1854 bf_set(lpfc_mbox_hdr_sge_cnt
, &sli4_config
->header
.cfg_mhdr
, pagen
);
1856 /* Set up sub-header fields into the first page */
1858 bf_set(lpfc_mbox_hdr_opcode
, &cfg_shdr
->request
, opcode
);
1859 bf_set(lpfc_mbox_hdr_subsystem
, &cfg_shdr
->request
, subsystem
);
1860 cfg_shdr
->request
.request_length
=
1861 alloc_len
- sizeof(union lpfc_sli4_cfg_shdr
);
1863 /* The sub-header is in DMA memory, which needs endian converstion */
1865 lpfc_sli_pcimem_bcopy(cfg_shdr
, cfg_shdr
,
1866 sizeof(union lpfc_sli4_cfg_shdr
));
1871 * lpfc_sli4_mbox_rsrc_extent - Initialize the opcode resource extent.
1872 * @phba: pointer to lpfc hba data structure.
1873 * @mbox: pointer to an allocated lpfc mbox resource.
1874 * @exts_count: the number of extents, if required, to allocate.
1875 * @rsrc_type: the resource extent type.
1876 * @emb: true if LPFC_SLI4_MBX_EMBED. false if LPFC_SLI4_MBX_NEMBED.
1878 * This routine completes the subcommand header for SLI4 resource extent
1879 * mailbox commands. It is called after lpfc_sli4_config. The caller must
1880 * pass an allocated mailbox and the attributes required to initialize the
1881 * mailbox correctly.
1883 * Return: the actual length of the mbox command allocated.
1886 lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
,
1887 uint16_t exts_count
, uint16_t rsrc_type
, bool emb
)
1890 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc_extnt
= NULL
;
1891 void *virtaddr
= NULL
;
1893 /* Set up SLI4 ioctl command header fields */
1894 if (emb
== LPFC_SLI4_MBX_NEMBED
) {
1895 /* Get the first SGE entry from the non-embedded DMA memory */
1896 virtaddr
= mbox
->sge_array
->addr
[0];
1897 if (virtaddr
== NULL
)
1899 n_rsrc_extnt
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
1903 * The resource type is common to all extent Opcodes and resides in the
1906 if (emb
== LPFC_SLI4_MBX_EMBED
)
1907 bf_set(lpfc_mbx_alloc_rsrc_extents_type
,
1908 &mbox
->u
.mqe
.un
.alloc_rsrc_extents
.u
.req
,
1911 /* This is DMA data. Byteswap is required. */
1912 bf_set(lpfc_mbx_alloc_rsrc_extents_type
,
1913 n_rsrc_extnt
, rsrc_type
);
1914 lpfc_sli_pcimem_bcopy(&n_rsrc_extnt
->word4
,
1915 &n_rsrc_extnt
->word4
,
1919 /* Complete the initialization for the particular Opcode. */
1920 opcode
= lpfc_sli_config_mbox_opcode_get(phba
, mbox
);
1922 case LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT
:
1923 if (emb
== LPFC_SLI4_MBX_EMBED
)
1924 bf_set(lpfc_mbx_alloc_rsrc_extents_cnt
,
1925 &mbox
->u
.mqe
.un
.alloc_rsrc_extents
.u
.req
,
1928 bf_set(lpfc_mbx_alloc_rsrc_extents_cnt
,
1929 n_rsrc_extnt
, exts_count
);
1931 case LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT
:
1932 case LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO
:
1933 case LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT
:
1934 /* Initialization is complete.*/
1937 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1938 "2929 Resource Extent Opcode x%x is "
1939 "unsupported\n", opcode
);
1947 * lpfc_sli_config_mbox_subsys_get - Get subsystem from a sli_config mbox cmd
1948 * @phba: pointer to lpfc hba data structure.
1949 * @mbox: pointer to lpfc mbox command queue entry.
1951 * This routine gets the subsystem from a SLI4 specific SLI_CONFIG mailbox
1952 * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if the
1953 * sub-header is not present, subsystem LPFC_MBOX_SUBSYSTEM_NA (0x0) shall
1957 lpfc_sli_config_mbox_subsys_get(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
1959 struct lpfc_mbx_sli4_config
*sli4_cfg
;
1960 union lpfc_sli4_cfg_shdr
*cfg_shdr
;
1962 if (mbox
->u
.mb
.mbxCommand
!= MBX_SLI4_CONFIG
)
1963 return LPFC_MBOX_SUBSYSTEM_NA
;
1964 sli4_cfg
= &mbox
->u
.mqe
.un
.sli4_config
;
1966 /* For embedded mbox command, get opcode from embedded sub-header*/
1967 if (bf_get(lpfc_mbox_hdr_emb
, &sli4_cfg
->header
.cfg_mhdr
)) {
1968 cfg_shdr
= &mbox
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
1969 return bf_get(lpfc_mbox_hdr_subsystem
, &cfg_shdr
->request
);
1972 /* For non-embedded mbox command, get opcode from first dma page */
1973 if (unlikely(!mbox
->sge_array
))
1974 return LPFC_MBOX_SUBSYSTEM_NA
;
1975 cfg_shdr
= (union lpfc_sli4_cfg_shdr
*)mbox
->sge_array
->addr
[0];
1976 return bf_get(lpfc_mbox_hdr_subsystem
, &cfg_shdr
->request
);
1980 * lpfc_sli_config_mbox_opcode_get - Get opcode from a sli_config mbox cmd
1981 * @phba: pointer to lpfc hba data structure.
1982 * @mbox: pointer to lpfc mbox command queue entry.
1984 * This routine gets the opcode from a SLI4 specific SLI_CONFIG mailbox
1985 * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if
1986 * the sub-header is not present, opcode LPFC_MBOX_OPCODE_NA (0x0) be
1990 lpfc_sli_config_mbox_opcode_get(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
1992 struct lpfc_mbx_sli4_config
*sli4_cfg
;
1993 union lpfc_sli4_cfg_shdr
*cfg_shdr
;
1995 if (mbox
->u
.mb
.mbxCommand
!= MBX_SLI4_CONFIG
)
1996 return LPFC_MBOX_OPCODE_NA
;
1997 sli4_cfg
= &mbox
->u
.mqe
.un
.sli4_config
;
1999 /* For embedded mbox command, get opcode from embedded sub-header*/
2000 if (bf_get(lpfc_mbox_hdr_emb
, &sli4_cfg
->header
.cfg_mhdr
)) {
2001 cfg_shdr
= &mbox
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
2002 return bf_get(lpfc_mbox_hdr_opcode
, &cfg_shdr
->request
);
2005 /* For non-embedded mbox command, get opcode from first dma page */
2006 if (unlikely(!mbox
->sge_array
))
2007 return LPFC_MBOX_OPCODE_NA
;
2008 cfg_shdr
= (union lpfc_sli4_cfg_shdr
*)mbox
->sge_array
->addr
[0];
2009 return bf_get(lpfc_mbox_hdr_opcode
, &cfg_shdr
->request
);
2013 * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd
2014 * @phba: pointer to lpfc hba data structure.
2015 * @fcf_index: index to fcf table.
2017 * This routine routine allocates and constructs non-embedded mailbox command
2018 * for reading a FCF table entry referred by @fcf_index.
2020 * Return: pointer to the mailbox command constructed if successful, otherwise
2024 lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba
*phba
,
2025 struct lpfcMboxq
*mboxq
,
2030 struct lpfc_mbx_sge sge
;
2031 uint32_t alloc_len
, req_len
;
2032 struct lpfc_mbx_read_fcf_tbl
*read_fcf
;
2037 req_len
= sizeof(struct fcf_record
) +
2038 sizeof(union lpfc_sli4_cfg_shdr
) + 2 * sizeof(uint32_t);
2040 /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
2041 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
2042 LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE
, req_len
,
2043 LPFC_SLI4_MBX_NEMBED
);
2045 if (alloc_len
< req_len
) {
2046 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
2047 "0291 Allocated DMA memory size (x%x) is "
2048 "less than the requested DMA memory "
2049 "size (x%x)\n", alloc_len
, req_len
);
2053 /* Get the first SGE entry from the non-embedded DMA memory. This
2054 * routine only uses a single SGE.
2056 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
2057 virt_addr
= mboxq
->sge_array
->addr
[0];
2058 read_fcf
= (struct lpfc_mbx_read_fcf_tbl
*)virt_addr
;
2060 /* Set up command fields */
2061 bf_set(lpfc_mbx_read_fcf_tbl_indx
, &read_fcf
->u
.request
, fcf_index
);
2062 /* Perform necessary endian conversion */
2063 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
2064 lpfc_sli_pcimem_bcopy(bytep
, bytep
, sizeof(uint32_t));
2070 * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
2071 * @mboxq: pointer to lpfc mbox command.
2073 * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
2077 lpfc_request_features(struct lpfc_hba
*phba
, struct lpfcMboxq
*mboxq
)
2079 /* Set up SLI4 mailbox command header fields */
2080 memset(mboxq
, 0, sizeof(LPFC_MBOXQ_t
));
2081 bf_set(lpfc_mqe_command
, &mboxq
->u
.mqe
, MBX_SLI4_REQ_FTRS
);
2083 /* Set up host requested features. */
2084 bf_set(lpfc_mbx_rq_ftr_rq_fcpi
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
2085 bf_set(lpfc_mbx_rq_ftr_rq_perfh
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
2087 /* Enable DIF (block guard) only if configured to do so. */
2088 if (phba
->cfg_enable_bg
)
2089 bf_set(lpfc_mbx_rq_ftr_rq_dif
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
2091 /* Enable NPIV only if configured to do so. */
2092 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
)
2093 bf_set(lpfc_mbx_rq_ftr_rq_npiv
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
2095 if (phba
->nvmet_support
) {
2096 bf_set(lpfc_mbx_rq_ftr_rq_mrqp
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
2097 /* iaab/iaar NOT set for now */
2098 bf_set(lpfc_mbx_rq_ftr_rq_iaab
, &mboxq
->u
.mqe
.un
.req_ftrs
, 0);
2099 bf_set(lpfc_mbx_rq_ftr_rq_iaar
, &mboxq
->u
.mqe
.un
.req_ftrs
, 0);
2105 * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
2106 * @mbox: pointer to lpfc mbox command to initialize.
2107 * @vport: Vport associated with the VF.
2109 * This routine initializes @mbox to all zeros and then fills in the mailbox
2110 * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
2111 * in the context of an FCF. The driver issues this command to setup a VFI
2112 * before issuing a FLOGI to login to the VSAN. The driver should also issue a
2113 * REG_VFI after a successful VSAN login.
2116 lpfc_init_vfi(struct lpfcMboxq
*mbox
, struct lpfc_vport
*vport
)
2118 struct lpfc_mbx_init_vfi
*init_vfi
;
2120 memset(mbox
, 0, sizeof(*mbox
));
2121 mbox
->vport
= vport
;
2122 init_vfi
= &mbox
->u
.mqe
.un
.init_vfi
;
2123 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_INIT_VFI
);
2124 bf_set(lpfc_init_vfi_vr
, init_vfi
, 1);
2125 bf_set(lpfc_init_vfi_vt
, init_vfi
, 1);
2126 bf_set(lpfc_init_vfi_vp
, init_vfi
, 1);
2127 bf_set(lpfc_init_vfi_vfi
, init_vfi
,
2128 vport
->phba
->sli4_hba
.vfi_ids
[vport
->vfi
]);
2129 bf_set(lpfc_init_vfi_vpi
, init_vfi
,
2130 vport
->phba
->vpi_ids
[vport
->vpi
]);
2131 bf_set(lpfc_init_vfi_fcfi
, init_vfi
,
2132 vport
->phba
->fcf
.fcfi
);
2136 * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
2137 * @mbox: pointer to lpfc mbox command to initialize.
2138 * @vport: vport associated with the VF.
2139 * @phys: BDE DMA bus address used to send the service parameters to the HBA.
2141 * This routine initializes @mbox to all zeros and then fills in the mailbox
2142 * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
2143 * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
2144 * fabrics identified by VFI in the context of an FCF.
2147 lpfc_reg_vfi(struct lpfcMboxq
*mbox
, struct lpfc_vport
*vport
, dma_addr_t phys
)
2149 struct lpfc_mbx_reg_vfi
*reg_vfi
;
2150 struct lpfc_hba
*phba
= vport
->phba
;
2151 uint8_t bbscn_fabric
= 0, bbscn_max
= 0, bbscn_def
= 0;
2153 memset(mbox
, 0, sizeof(*mbox
));
2154 reg_vfi
= &mbox
->u
.mqe
.un
.reg_vfi
;
2155 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_REG_VFI
);
2156 bf_set(lpfc_reg_vfi_vp
, reg_vfi
, 1);
2157 bf_set(lpfc_reg_vfi_vfi
, reg_vfi
,
2158 phba
->sli4_hba
.vfi_ids
[vport
->vfi
]);
2159 bf_set(lpfc_reg_vfi_fcfi
, reg_vfi
, phba
->fcf
.fcfi
);
2160 bf_set(lpfc_reg_vfi_vpi
, reg_vfi
, phba
->vpi_ids
[vport
->vpi
]);
2161 memcpy(reg_vfi
->wwn
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2162 reg_vfi
->wwn
[0] = cpu_to_le32(reg_vfi
->wwn
[0]);
2163 reg_vfi
->wwn
[1] = cpu_to_le32(reg_vfi
->wwn
[1]);
2164 reg_vfi
->e_d_tov
= phba
->fc_edtov
;
2165 reg_vfi
->r_a_tov
= phba
->fc_ratov
;
2167 reg_vfi
->bde
.addrHigh
= putPaddrHigh(phys
);
2168 reg_vfi
->bde
.addrLow
= putPaddrLow(phys
);
2169 reg_vfi
->bde
.tus
.f
.bdeSize
= sizeof(vport
->fc_sparam
);
2170 reg_vfi
->bde
.tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
2172 bf_set(lpfc_reg_vfi_nport_id
, reg_vfi
, vport
->fc_myDID
);
2174 /* Only FC supports upd bit */
2175 if ((phba
->sli4_hba
.lnk_info
.lnk_tp
== LPFC_LNK_TYPE_FC
) &&
2176 (vport
->fc_flag
& FC_VFI_REGISTERED
) &&
2177 (!phba
->fc_topology_changed
))
2178 bf_set(lpfc_reg_vfi_upd
, reg_vfi
, 1);
2180 bf_set(lpfc_reg_vfi_bbcr
, reg_vfi
, 0);
2181 bf_set(lpfc_reg_vfi_bbscn
, reg_vfi
, 0);
2182 bbscn_fabric
= (phba
->fc_fabparam
.cmn
.bbRcvSizeMsb
>> 4) & 0xF;
2184 if (phba
->bbcredit_support
&& phba
->cfg_enable_bbcr
&&
2185 bbscn_fabric
!= 0) {
2186 bbscn_max
= bf_get(lpfc_bbscn_max
,
2187 &phba
->sli4_hba
.bbscn_params
);
2188 if (bbscn_fabric
<= bbscn_max
) {
2189 bbscn_def
= bf_get(lpfc_bbscn_def
,
2190 &phba
->sli4_hba
.bbscn_params
);
2192 if (bbscn_fabric
> bbscn_def
)
2193 bf_set(lpfc_reg_vfi_bbscn
, reg_vfi
,
2196 bf_set(lpfc_reg_vfi_bbscn
, reg_vfi
, bbscn_def
);
2198 bf_set(lpfc_reg_vfi_bbcr
, reg_vfi
, 1);
2201 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_MBOX
,
2202 "3134 Register VFI, mydid:x%x, fcfi:%d, "
2203 " vfi:%d, vpi:%d, fc_pname:%x%x fc_flag:x%x"
2204 " port_state:x%x topology chg:%d bbscn_fabric :%d\n",
2207 phba
->sli4_hba
.vfi_ids
[vport
->vfi
],
2208 phba
->vpi_ids
[vport
->vpi
],
2209 reg_vfi
->wwn
[0], reg_vfi
->wwn
[1], vport
->fc_flag
,
2210 vport
->port_state
, phba
->fc_topology_changed
,
2215 * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
2216 * @phba: pointer to the hba structure to init the VPI for.
2217 * @mbox: pointer to lpfc mbox command to initialize.
2218 * @vpi: VPI to be initialized.
2220 * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
2221 * command to activate a virtual N_Port. The HBA assigns a MAC address to use
2222 * with the virtual N Port. The SLI Host issues this command before issuing a
2223 * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
2224 * successful virtual NPort login.
2227 lpfc_init_vpi(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
, uint16_t vpi
)
2229 memset(mbox
, 0, sizeof(*mbox
));
2230 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_INIT_VPI
);
2231 bf_set(lpfc_init_vpi_vpi
, &mbox
->u
.mqe
.un
.init_vpi
,
2232 phba
->vpi_ids
[vpi
]);
2233 bf_set(lpfc_init_vpi_vfi
, &mbox
->u
.mqe
.un
.init_vpi
,
2234 phba
->sli4_hba
.vfi_ids
[phba
->pport
->vfi
]);
2238 * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
2239 * @mbox: pointer to lpfc mbox command to initialize.
2240 * @vport: vport associated with the VF.
2242 * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
2243 * (logical NPort) into the inactive state. The SLI Host must have logged out
2244 * and unregistered all remote N_Ports to abort any activity on the virtual
2245 * fabric. The SLI Port posts the mailbox response after marking the virtual
2249 lpfc_unreg_vfi(struct lpfcMboxq
*mbox
, struct lpfc_vport
*vport
)
2251 memset(mbox
, 0, sizeof(*mbox
));
2252 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_UNREG_VFI
);
2253 bf_set(lpfc_unreg_vfi_vfi
, &mbox
->u
.mqe
.un
.unreg_vfi
,
2254 vport
->phba
->sli4_hba
.vfi_ids
[vport
->vfi
]);
2258 * lpfc_sli4_dump_cfg_rg23 - Dump sli4 port config region 23
2259 * @phba: pointer to the hba structure containing.
2260 * @mbox: pointer to lpfc mbox command to initialize.
2262 * This function create a SLI4 dump mailbox command to dump configure
2266 lpfc_sli4_dump_cfg_rg23(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
2268 struct lpfc_dmabuf
*mp
= NULL
;
2271 memset(mbox
, 0, sizeof(*mbox
));
2274 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2276 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
2278 if (!mp
|| !mp
->virt
) {
2280 /* dump config region 23 failed to allocate memory */
2281 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
2282 "2569 lpfc dump config region 23: memory"
2283 " allocation failed\n");
2287 memset(mp
->virt
, 0, LPFC_BPL_SIZE
);
2288 INIT_LIST_HEAD(&mp
->list
);
2290 /* save address for completion */
2291 mbox
->context1
= (uint8_t *) mp
;
2293 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
2294 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
2295 mb
->un
.varDmp
.region_id
= DMP_REGION_23
;
2296 mb
->un
.varDmp
.sli4_length
= DMP_RGN23_SIZE
;
2297 mb
->un
.varWords
[3] = putPaddrLow(mp
->phys
);
2298 mb
->un
.varWords
[4] = putPaddrHigh(mp
->phys
);
2303 lpfc_mbx_cmpl_rdp_link_stat(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2307 struct lpfc_rdp_context
*rdp_context
=
2308 (struct lpfc_rdp_context
*)(mboxq
->context2
);
2314 memcpy(&rdp_context
->link_stat
, &mb
->un
.varRdLnk
, sizeof(READ_LNK_VAR
));
2319 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2320 rdp_context
->cmpl(phba
, rdp_context
, rc
);
2324 lpfc_mbx_cmpl_rdp_page_a2(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
2326 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
2327 struct lpfc_rdp_context
*rdp_context
=
2328 (struct lpfc_rdp_context
*)(mbox
->context2
);
2330 if (bf_get(lpfc_mqe_status
, &mbox
->u
.mqe
))
2331 goto error_mbuf_free
;
2333 lpfc_sli_bemem_bcopy(mp
->virt
, &rdp_context
->page_a2
,
2334 DMP_SFF_PAGE_A2_SIZE
);
2336 /* We don't need dma buffer for link stat. */
2337 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2340 memset(mbox
, 0, sizeof(*mbox
));
2341 lpfc_read_lnk_stat(phba
, mbox
);
2342 mbox
->vport
= rdp_context
->ndlp
->vport
;
2343 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_rdp_link_stat
;
2344 mbox
->context2
= (struct lpfc_rdp_context
*) rdp_context
;
2345 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
) == MBX_NOT_FINISHED
)
2346 goto error_cmd_free
;
2351 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2354 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
2355 rdp_context
->cmpl(phba
, rdp_context
, FAILURE
);
2359 lpfc_mbx_cmpl_rdp_page_a0(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
2362 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (mbox
->context1
);
2363 struct lpfc_rdp_context
*rdp_context
=
2364 (struct lpfc_rdp_context
*)(mbox
->context2
);
2366 if (bf_get(lpfc_mqe_status
, &mbox
->u
.mqe
))
2369 lpfc_sli_bemem_bcopy(mp
->virt
, &rdp_context
->page_a0
,
2370 DMP_SFF_PAGE_A0_SIZE
);
2372 memset(mbox
, 0, sizeof(*mbox
));
2374 memset(mp
->virt
, 0, DMP_SFF_PAGE_A2_SIZE
);
2375 INIT_LIST_HEAD(&mp
->list
);
2377 /* save address for completion */
2378 mbox
->context1
= mp
;
2379 mbox
->vport
= rdp_context
->ndlp
->vport
;
2381 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_DUMP_MEMORY
);
2382 bf_set(lpfc_mbx_memory_dump_type3_type
,
2383 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_LMSD
);
2384 bf_set(lpfc_mbx_memory_dump_type3_link
,
2385 &mbox
->u
.mqe
.un
.mem_dump_type3
, phba
->sli4_hba
.physical_port
);
2386 bf_set(lpfc_mbx_memory_dump_type3_page_no
,
2387 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_PAGE_A2
);
2388 bf_set(lpfc_mbx_memory_dump_type3_length
,
2389 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_SFF_PAGE_A2_SIZE
);
2390 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_lo
= putPaddrLow(mp
->phys
);
2391 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_hi
= putPaddrHigh(mp
->phys
);
2393 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_rdp_page_a2
;
2394 mbox
->context2
= (struct lpfc_rdp_context
*) rdp_context
;
2395 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
2396 if (rc
== MBX_NOT_FINISHED
)
2402 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2404 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
2405 rdp_context
->cmpl(phba
, rdp_context
, FAILURE
);
2410 * lpfc_sli4_dump_sfp_pagea0 - Dump sli4 read SFP Diagnostic.
2411 * @phba: pointer to the hba structure containing.
2412 * @mbox: pointer to lpfc mbox command to initialize.
2414 * This function create a SLI4 dump mailbox command to dump configure
2418 lpfc_sli4_dump_page_a0(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
2420 struct lpfc_dmabuf
*mp
= NULL
;
2422 memset(mbox
, 0, sizeof(*mbox
));
2424 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2426 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
2427 if (!mp
|| !mp
->virt
) {
2429 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
2430 "3569 dump type 3 page 0xA0 allocation failed\n");
2434 memset(mp
->virt
, 0, LPFC_BPL_SIZE
);
2435 INIT_LIST_HEAD(&mp
->list
);
2437 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_DUMP_MEMORY
);
2438 /* save address for completion */
2439 mbox
->context1
= mp
;
2441 bf_set(lpfc_mbx_memory_dump_type3_type
,
2442 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_LMSD
);
2443 bf_set(lpfc_mbx_memory_dump_type3_link
,
2444 &mbox
->u
.mqe
.un
.mem_dump_type3
, phba
->sli4_hba
.physical_port
);
2445 bf_set(lpfc_mbx_memory_dump_type3_page_no
,
2446 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_PAGE_A0
);
2447 bf_set(lpfc_mbx_memory_dump_type3_length
,
2448 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_SFF_PAGE_A0_SIZE
);
2449 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_lo
= putPaddrLow(mp
->phys
);
2450 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_hi
= putPaddrHigh(mp
->phys
);
2456 * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
2457 * @phba: pointer to the hba structure containing the FCF index and RQ ID.
2458 * @mbox: pointer to lpfc mbox command to initialize.
2460 * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
2461 * SLI Host uses the command to activate an FCF after it has acquired FCF
2462 * information via a READ_FCF mailbox command. This mailbox command also is used
2463 * to indicate where received unsolicited frames from this FCF will be sent. By
2464 * default this routine will set up the FCF to forward all unsolicited frames
2465 * the the RQ ID passed in the @phba. This can be overridden by the caller for
2466 * more complicated setups.
2469 lpfc_reg_fcfi(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
2471 struct lpfc_mbx_reg_fcfi
*reg_fcfi
;
2473 memset(mbox
, 0, sizeof(*mbox
));
2474 reg_fcfi
= &mbox
->u
.mqe
.un
.reg_fcfi
;
2475 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_REG_FCFI
);
2476 if (phba
->nvmet_support
== 0) {
2477 bf_set(lpfc_reg_fcfi_rq_id0
, reg_fcfi
,
2478 phba
->sli4_hba
.hdr_rq
->queue_id
);
2479 /* Match everything - rq_id0 */
2480 bf_set(lpfc_reg_fcfi_type_match0
, reg_fcfi
, 0);
2481 bf_set(lpfc_reg_fcfi_type_mask0
, reg_fcfi
, 0);
2482 bf_set(lpfc_reg_fcfi_rctl_match0
, reg_fcfi
, 0);
2483 bf_set(lpfc_reg_fcfi_rctl_mask0
, reg_fcfi
, 0);
2485 bf_set(lpfc_reg_fcfi_rq_id1
, reg_fcfi
, REG_FCF_INVALID_QID
);
2487 /* addr mode is bit wise inverted value of fcf addr_mode */
2488 bf_set(lpfc_reg_fcfi_mam
, reg_fcfi
,
2489 (~phba
->fcf
.addr_mode
) & 0x3);
2491 /* This is ONLY for NVMET MRQ == 1 */
2492 if (phba
->cfg_nvmet_mrq
!= 1)
2495 bf_set(lpfc_reg_fcfi_rq_id0
, reg_fcfi
,
2496 phba
->sli4_hba
.nvmet_mrq_hdr
[0]->queue_id
);
2497 /* Match type FCP - rq_id0 */
2498 bf_set(lpfc_reg_fcfi_type_match0
, reg_fcfi
, FC_TYPE_FCP
);
2499 bf_set(lpfc_reg_fcfi_type_mask0
, reg_fcfi
, 0xff);
2500 bf_set(lpfc_reg_fcfi_rctl_match0
, reg_fcfi
,
2501 FC_RCTL_DD_UNSOL_CMD
);
2503 bf_set(lpfc_reg_fcfi_rq_id1
, reg_fcfi
,
2504 phba
->sli4_hba
.hdr_rq
->queue_id
);
2505 /* Match everything else - rq_id1 */
2506 bf_set(lpfc_reg_fcfi_type_match1
, reg_fcfi
, 0);
2507 bf_set(lpfc_reg_fcfi_type_mask1
, reg_fcfi
, 0);
2508 bf_set(lpfc_reg_fcfi_rctl_match1
, reg_fcfi
, 0);
2509 bf_set(lpfc_reg_fcfi_rctl_mask1
, reg_fcfi
, 0);
2511 bf_set(lpfc_reg_fcfi_rq_id2
, reg_fcfi
, REG_FCF_INVALID_QID
);
2512 bf_set(lpfc_reg_fcfi_rq_id3
, reg_fcfi
, REG_FCF_INVALID_QID
);
2513 bf_set(lpfc_reg_fcfi_info_index
, reg_fcfi
,
2514 phba
->fcf
.current_rec
.fcf_indx
);
2515 if (phba
->fcf
.current_rec
.vlan_id
!= LPFC_FCOE_NULL_VID
) {
2516 bf_set(lpfc_reg_fcfi_vv
, reg_fcfi
, 1);
2517 bf_set(lpfc_reg_fcfi_vlan_tag
, reg_fcfi
,
2518 phba
->fcf
.current_rec
.vlan_id
);
2523 * lpfc_reg_fcfi_mrq - Initialize the REG_FCFI_MRQ mailbox command
2524 * @phba: pointer to the hba structure containing the FCF index and RQ ID.
2525 * @mbox: pointer to lpfc mbox command to initialize.
2526 * @mode: 0 to register FCFI, 1 to register MRQs
2528 * The REG_FCFI_MRQ mailbox command supports Fibre Channel Forwarders (FCFs).
2529 * The SLI Host uses the command to activate an FCF after it has acquired FCF
2530 * information via a READ_FCF mailbox command. This mailbox command also is used
2531 * to indicate where received unsolicited frames from this FCF will be sent. By
2532 * default this routine will set up the FCF to forward all unsolicited frames
2533 * the the RQ ID passed in the @phba. This can be overridden by the caller for
2534 * more complicated setups.
2537 lpfc_reg_fcfi_mrq(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
, int mode
)
2539 struct lpfc_mbx_reg_fcfi_mrq
*reg_fcfi
;
2541 /* This is ONLY for MRQ */
2542 if (phba
->cfg_nvmet_mrq
<= 1)
2545 memset(mbox
, 0, sizeof(*mbox
));
2546 reg_fcfi
= &mbox
->u
.mqe
.un
.reg_fcfi_mrq
;
2547 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_REG_FCFI_MRQ
);
2549 bf_set(lpfc_reg_fcfi_mrq_info_index
, reg_fcfi
,
2550 phba
->fcf
.current_rec
.fcf_indx
);
2551 if (phba
->fcf
.current_rec
.vlan_id
!= LPFC_FCOE_NULL_VID
) {
2552 bf_set(lpfc_reg_fcfi_mrq_vv
, reg_fcfi
, 1);
2553 bf_set(lpfc_reg_fcfi_mrq_vlan_tag
, reg_fcfi
,
2554 phba
->fcf
.current_rec
.vlan_id
);
2559 bf_set(lpfc_reg_fcfi_mrq_rq_id0
, reg_fcfi
,
2560 phba
->sli4_hba
.nvmet_mrq_hdr
[0]->queue_id
);
2561 /* Match NVME frames of type FCP (protocol NVME) - rq_id0 */
2562 bf_set(lpfc_reg_fcfi_mrq_type_match0
, reg_fcfi
, FC_TYPE_FCP
);
2563 bf_set(lpfc_reg_fcfi_mrq_type_mask0
, reg_fcfi
, 0xff);
2564 bf_set(lpfc_reg_fcfi_mrq_rctl_match0
, reg_fcfi
, FC_RCTL_DD_UNSOL_CMD
);
2565 bf_set(lpfc_reg_fcfi_mrq_rctl_mask0
, reg_fcfi
, 0xff);
2566 bf_set(lpfc_reg_fcfi_mrq_ptc0
, reg_fcfi
, 1);
2567 bf_set(lpfc_reg_fcfi_mrq_pt0
, reg_fcfi
, 1);
2569 bf_set(lpfc_reg_fcfi_mrq_policy
, reg_fcfi
, 3); /* NVME connection id */
2570 bf_set(lpfc_reg_fcfi_mrq_mode
, reg_fcfi
, 1);
2571 bf_set(lpfc_reg_fcfi_mrq_filter
, reg_fcfi
, 1); /* rq_id0 */
2572 bf_set(lpfc_reg_fcfi_mrq_npairs
, reg_fcfi
, phba
->cfg_nvmet_mrq
);
2574 bf_set(lpfc_reg_fcfi_mrq_rq_id1
, reg_fcfi
,
2575 phba
->sli4_hba
.hdr_rq
->queue_id
);
2576 /* Match everything - rq_id1 */
2577 bf_set(lpfc_reg_fcfi_mrq_type_match1
, reg_fcfi
, 0);
2578 bf_set(lpfc_reg_fcfi_mrq_type_mask1
, reg_fcfi
, 0);
2579 bf_set(lpfc_reg_fcfi_mrq_rctl_match1
, reg_fcfi
, 0);
2580 bf_set(lpfc_reg_fcfi_mrq_rctl_mask1
, reg_fcfi
, 0);
2582 bf_set(lpfc_reg_fcfi_mrq_rq_id2
, reg_fcfi
, REG_FCF_INVALID_QID
);
2583 bf_set(lpfc_reg_fcfi_mrq_rq_id3
, reg_fcfi
, REG_FCF_INVALID_QID
);
2587 * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
2588 * @mbox: pointer to lpfc mbox command to initialize.
2589 * @fcfi: FCFI to be unregistered.
2591 * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
2592 * The SLI Host uses the command to inactivate an FCFI.
2595 lpfc_unreg_fcfi(struct lpfcMboxq
*mbox
, uint16_t fcfi
)
2597 memset(mbox
, 0, sizeof(*mbox
));
2598 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_UNREG_FCFI
);
2599 bf_set(lpfc_unreg_fcfi
, &mbox
->u
.mqe
.un
.unreg_fcfi
, fcfi
);
2603 * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
2604 * @mbox: pointer to lpfc mbox command to initialize.
2605 * @ndlp: The nodelist structure that describes the RPI to resume.
2607 * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
2611 lpfc_resume_rpi(struct lpfcMboxq
*mbox
, struct lpfc_nodelist
*ndlp
)
2613 struct lpfc_hba
*phba
= ndlp
->phba
;
2614 struct lpfc_mbx_resume_rpi
*resume_rpi
;
2616 memset(mbox
, 0, sizeof(*mbox
));
2617 resume_rpi
= &mbox
->u
.mqe
.un
.resume_rpi
;
2618 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_RESUME_RPI
);
2619 bf_set(lpfc_resume_rpi_index
, resume_rpi
,
2620 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
2621 bf_set(lpfc_resume_rpi_ii
, resume_rpi
, RESUME_INDEX_RPI
);
2622 resume_rpi
->event_tag
= ndlp
->phba
->fc_eventTag
;
2626 * lpfc_supported_pages - Initialize the PORT_CAPABILITIES supported pages
2628 * @mbox: pointer to lpfc mbox command to initialize.
2630 * The PORT_CAPABILITIES supported pages mailbox command is issued to
2631 * retrieve the particular feature pages supported by the port.
2634 lpfc_supported_pages(struct lpfcMboxq
*mbox
)
2636 struct lpfc_mbx_supp_pages
*supp_pages
;
2638 memset(mbox
, 0, sizeof(*mbox
));
2639 supp_pages
= &mbox
->u
.mqe
.un
.supp_pages
;
2640 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_PORT_CAPABILITIES
);
2641 bf_set(cpn
, supp_pages
, LPFC_SUPP_PAGES
);
2645 * lpfc_pc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params mbox cmd.
2646 * @mbox: pointer to lpfc mbox command to initialize.
2648 * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to
2649 * retrieve the particular SLI4 features supported by the port.
2652 lpfc_pc_sli4_params(struct lpfcMboxq
*mbox
)
2654 struct lpfc_mbx_pc_sli4_params
*sli4_params
;
2656 memset(mbox
, 0, sizeof(*mbox
));
2657 sli4_params
= &mbox
->u
.mqe
.un
.sli4_params
;
2658 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_PORT_CAPABILITIES
);
2659 bf_set(cpn
, sli4_params
, LPFC_SLI4_PARAMETERS
);