1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
26 #include <scsi/scsi_device.h>
27 #include <scsi/scsi_transport_fc.h>
29 #include <scsi/scsi.h>
34 #include "lpfc_sli4.h"
36 #include "lpfc_disc.h"
37 #include "lpfc_scsi.h"
39 #include "lpfc_logmsg.h"
40 #include "lpfc_crtn.h"
41 #include "lpfc_compat.h"
44 * lpfc_dump_static_vport - Dump HBA's static vport information.
45 * @phba: pointer to lpfc hba data structure.
46 * @pmb: pointer to the driver internal queue element for mailbox command.
47 * @offset: offset for dumping vport info.
49 * The dump mailbox command provides a method for the device driver to obtain
50 * various types of information from the HBA device.
52 * This routine prepares the mailbox command for dumping list of static
53 * vports to be created.
56 lpfc_dump_static_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
,
65 /* Setup to dump vport info region */
66 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
67 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
69 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
70 mb
->un
.varDmp
.entry_index
= offset
;
71 mb
->un
.varDmp
.region_id
= DMP_REGION_VPORT
;
72 mb
->un
.varDmp
.word_cnt
= DMP_RSP_SIZE
/sizeof(uint32_t);
74 mb
->un
.varDmp
.resp_offset
= 0;
76 mb
->mbxOwner
= OWN_HOST
;
82 * lpfc_dump_mem - Prepare a mailbox command for retrieving HBA's VPD memory
83 * @phba: pointer to lpfc hba data structure.
84 * @pmb: pointer to the driver internal queue element for mailbox command.
85 * @offset: offset for dumping VPD memory mailbox command.
87 * The dump mailbox command provides a method for the device driver to obtain
88 * various types of information from the HBA device.
90 * This routine prepares the mailbox command for dumping HBA Vital Product
91 * Data (VPD) memory. This mailbox command is to be used for retrieving a
92 * portion (DMP_RSP_SIZE bytes) of a HBA's VPD from the HBA at an address
93 * offset specified by the offset parameter.
96 lpfc_dump_mem(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
, uint16_t offset
)
104 /* Setup to dump VPD region */
105 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
106 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
107 mb
->un
.varDmp
.cv
= 1;
108 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
109 mb
->un
.varDmp
.entry_index
= offset
;
110 mb
->un
.varDmp
.region_id
= DMP_REGION_VPD
;
111 mb
->un
.varDmp
.word_cnt
= (DMP_RSP_SIZE
/ sizeof (uint32_t));
112 mb
->un
.varDmp
.co
= 0;
113 mb
->un
.varDmp
.resp_offset
= 0;
115 mb
->mbxOwner
= OWN_HOST
;
120 * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
121 * @phba: pointer to lpfc hba data structure.
122 * @pmb: pointer to the driver internal queue element for mailbox command.
124 * This function create a dump memory mailbox command to dump wake up
128 lpfc_dump_wakeup_param(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
134 /* Save context so that we can restore after memset */
137 /* Setup to dump VPD region */
138 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
139 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
140 mb
->mbxOwner
= OWN_HOST
;
141 mb
->un
.varDmp
.cv
= 1;
142 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
143 mb
->un
.varDmp
.entry_index
= 0;
144 mb
->un
.varDmp
.region_id
= WAKE_UP_PARMS_REGION_ID
;
145 mb
->un
.varDmp
.word_cnt
= WAKE_UP_PARMS_WORD_SIZE
;
146 mb
->un
.varDmp
.co
= 0;
147 mb
->un
.varDmp
.resp_offset
= 0;
153 * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
154 * @phba: pointer to lpfc hba data structure.
155 * @pmb: pointer to the driver internal queue element for mailbox command.
157 * The read NVRAM mailbox command returns the HBA's non-volatile parameters
158 * that are used as defaults when the Fibre Channel link is brought on-line.
160 * This routine prepares the mailbox command for reading information stored
161 * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
164 lpfc_read_nv(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
169 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
170 mb
->mbxCommand
= MBX_READ_NV
;
171 mb
->mbxOwner
= OWN_HOST
;
176 * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
177 * @phba: pointer to lpfc hba data structure.
178 * @pmb: pointer to the driver internal queue element for mailbox command.
179 * @ring: ring number for the asynchronous event to be configured.
181 * The asynchronous event enable mailbox command is used to enable the
182 * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
183 * specifies the default ring to which events are posted.
185 * This routine prepares the mailbox command for enabling HBA asynchronous
186 * event support on a IOCB ring.
189 lpfc_config_async(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
,
195 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
196 mb
->mbxCommand
= MBX_ASYNCEVT_ENABLE
;
197 mb
->un
.varCfgAsyncEvent
.ring
= ring
;
198 mb
->mbxOwner
= OWN_HOST
;
203 * lpfc_heart_beat - Prepare a mailbox command for heart beat
204 * @phba: pointer to lpfc hba data structure.
205 * @pmb: pointer to the driver internal queue element for mailbox command.
207 * The heart beat mailbox command is used to detect an unresponsive HBA, which
208 * is defined as any device where no error attention is sent and both mailbox
209 * and rings are not processed.
211 * This routine prepares the mailbox command for issuing a heart beat in the
212 * form of mailbox command to the HBA. The timely completion of the heart
213 * beat mailbox command indicates the health of the HBA.
216 lpfc_heart_beat(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
221 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
222 mb
->mbxCommand
= MBX_HEARTBEAT
;
223 mb
->mbxOwner
= OWN_HOST
;
228 * lpfc_read_la - Prepare a mailbox command for reading HBA link attention
229 * @phba: pointer to lpfc hba data structure.
230 * @pmb: pointer to the driver internal queue element for mailbox command.
231 * @mp: DMA buffer memory for reading the link attention information into.
233 * The read link attention mailbox command is issued to read the Link Event
234 * Attention information indicated by the HBA port when the Link Event bit
235 * of the Host Attention (HSTATT) register is set to 1. A Link Event
236 * Attention occurs based on an exception detected at the Fibre Channel link
239 * This routine prepares the mailbox command for reading HBA link attention
240 * information. A DMA memory has been set aside and address passed to the
241 * HBA through @mp for the HBA to DMA link attention information into the
242 * memory as part of the execution of the mailbox command.
245 * 0 - Success (currently always return 0)
248 lpfc_read_la(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
, struct lpfc_dmabuf
*mp
)
251 struct lpfc_sli
*psli
;
255 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
257 INIT_LIST_HEAD(&mp
->list
);
258 mb
->mbxCommand
= MBX_READ_LA64
;
259 mb
->un
.varReadLA
.un
.lilpBde64
.tus
.f
.bdeSize
= 128;
260 mb
->un
.varReadLA
.un
.lilpBde64
.addrHigh
= putPaddrHigh(mp
->phys
);
261 mb
->un
.varReadLA
.un
.lilpBde64
.addrLow
= putPaddrLow(mp
->phys
);
263 /* Save address for later completion and set the owner to host so that
264 * the FW knows this mailbox is available for processing.
266 pmb
->context1
= (uint8_t *) mp
;
267 mb
->mbxOwner
= OWN_HOST
;
272 * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
273 * @phba: pointer to lpfc hba data structure.
274 * @pmb: pointer to the driver internal queue element for mailbox command.
276 * The clear link attention mailbox command is issued to clear the link event
277 * attention condition indicated by the Link Event bit of the Host Attention
278 * (HSTATT) register. The link event attention condition is cleared only if
279 * the event tag specified matches that of the current link event counter.
280 * The current event tag is read using the read link attention event mailbox
283 * This routine prepares the mailbox command for clearing HBA link attention
287 lpfc_clear_la(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
292 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
294 mb
->un
.varClearLA
.eventTag
= phba
->fc_eventTag
;
295 mb
->mbxCommand
= MBX_CLEAR_LA
;
296 mb
->mbxOwner
= OWN_HOST
;
301 * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
302 * @phba: pointer to lpfc hba data structure.
303 * @pmb: pointer to the driver internal queue element for mailbox command.
305 * The configure link mailbox command is used before the initialize link
306 * mailbox command to override default value and to configure link-oriented
307 * parameters such as DID address and various timers. Typically, this
308 * command would be used after an F_Port login to set the returned DID address
309 * and the fabric timeout values. This command is not valid before a configure
310 * port command has configured the HBA port.
312 * This routine prepares the mailbox command for configuring link on a HBA.
315 lpfc_config_link(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
317 struct lpfc_vport
*vport
= phba
->pport
;
318 MAILBOX_t
*mb
= &pmb
->u
.mb
;
319 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
322 * SLI-2, Coalescing Response Feature.
324 if (phba
->cfg_cr_delay
) {
325 mb
->un
.varCfgLnk
.cr
= 1;
326 mb
->un
.varCfgLnk
.ci
= 1;
327 mb
->un
.varCfgLnk
.cr_delay
= phba
->cfg_cr_delay
;
328 mb
->un
.varCfgLnk
.cr_count
= phba
->cfg_cr_count
;
331 mb
->un
.varCfgLnk
.myId
= vport
->fc_myDID
;
332 mb
->un
.varCfgLnk
.edtov
= phba
->fc_edtov
;
333 mb
->un
.varCfgLnk
.arbtov
= phba
->fc_arbtov
;
334 mb
->un
.varCfgLnk
.ratov
= phba
->fc_ratov
;
335 mb
->un
.varCfgLnk
.rttov
= phba
->fc_rttov
;
336 mb
->un
.varCfgLnk
.altov
= phba
->fc_altov
;
337 mb
->un
.varCfgLnk
.crtov
= phba
->fc_crtov
;
338 mb
->un
.varCfgLnk
.citov
= phba
->fc_citov
;
341 mb
->un
.varCfgLnk
.ack0_enable
= 1;
343 mb
->mbxCommand
= MBX_CONFIG_LINK
;
344 mb
->mbxOwner
= OWN_HOST
;
349 * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
350 * @phba: pointer to lpfc hba data structure.
351 * @pmb: pointer to the driver internal queue element for mailbox command.
353 * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
354 * MSI-X multi-message interrupt vector association to interrupt attention
362 lpfc_config_msi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
364 MAILBOX_t
*mb
= &pmb
->u
.mb
;
365 uint32_t attentionConditions
[2];
368 if (phba
->cfg_use_msi
!= 2) {
369 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
370 "0475 Not configured for supporting MSI-X "
371 "cfg_use_msi: 0x%x\n", phba
->cfg_use_msi
);
375 if (phba
->sli_rev
< 3) {
376 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
377 "0476 HBA not supporting SLI-3 or later "
378 "SLI Revision: 0x%x\n", phba
->sli_rev
);
382 /* Clear mailbox command fields */
383 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
386 * SLI-3, Message Signaled Interrupt Fearure.
389 /* Multi-message attention configuration */
390 attentionConditions
[0] = (HA_R0ATT
| HA_R1ATT
| HA_R2ATT
| HA_ERATT
|
392 attentionConditions
[1] = 0;
394 mb
->un
.varCfgMSI
.attentionConditions
[0] = attentionConditions
[0];
395 mb
->un
.varCfgMSI
.attentionConditions
[1] = attentionConditions
[1];
398 * Set up message number to HA bit association
400 #ifdef __BIG_ENDIAN_BITFIELD
402 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R0_POS
] = 1;
403 /* RA1 (Other Protocol Extra Ring) */
404 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R1_POS
] = 1;
405 #else /* __LITTLE_ENDIAN_BITFIELD */
407 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R0_POS
^3] = 1;
408 /* RA1 (Other Protocol Extra Ring) */
409 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R1_POS
^3] = 1;
411 /* Multi-message interrupt autoclear configuration*/
412 mb
->un
.varCfgMSI
.autoClearHA
[0] = attentionConditions
[0];
413 mb
->un
.varCfgMSI
.autoClearHA
[1] = attentionConditions
[1];
415 /* For now, HBA autoclear does not work reliably, disable it */
416 mb
->un
.varCfgMSI
.autoClearHA
[0] = 0;
417 mb
->un
.varCfgMSI
.autoClearHA
[1] = 0;
419 /* Set command and owner bit */
420 mb
->mbxCommand
= MBX_CONFIG_MSI
;
421 mb
->mbxOwner
= OWN_HOST
;
427 * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
428 * @phba: pointer to lpfc hba data structure.
429 * @pmb: pointer to the driver internal queue element for mailbox command.
430 * @topology: the link topology for the link to be initialized to.
431 * @linkspeed: the link speed for the link to be initialized to.
433 * The initialize link mailbox command is used to initialize the Fibre
434 * Channel link. This command must follow a configure port command that
435 * establishes the mode of operation.
437 * This routine prepares the mailbox command for initializing link on a HBA
438 * with the specified link topology and speed.
441 lpfc_init_link(struct lpfc_hba
* phba
,
442 LPFC_MBOXQ_t
* pmb
, uint32_t topology
, uint32_t linkspeed
)
445 struct lpfc_sli
*psli
;
449 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
453 case FLAGS_TOPOLOGY_MODE_LOOP_PT
:
454 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_LOOP
;
455 mb
->un
.varInitLnk
.link_flags
|= FLAGS_TOPOLOGY_FAILOVER
;
457 case FLAGS_TOPOLOGY_MODE_PT_PT
:
458 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_PT_PT
;
460 case FLAGS_TOPOLOGY_MODE_LOOP
:
461 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_LOOP
;
463 case FLAGS_TOPOLOGY_MODE_PT_LOOP
:
464 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_PT_PT
;
465 mb
->un
.varInitLnk
.link_flags
|= FLAGS_TOPOLOGY_FAILOVER
;
468 mb
->un
.varInitLnk
.link_flags
= FLAGS_LOCAL_LB
;
472 /* Enable asynchronous ABTS responses from firmware */
473 mb
->un
.varInitLnk
.link_flags
|= FLAGS_IMED_ABORT
;
476 * Setting up the link speed
479 if (vpd
->rev
.feaLevelHigh
>= 0x02){
485 mb
->un
.varInitLnk
.link_flags
|=
487 mb
->un
.varInitLnk
.link_speed
= linkspeed
;
489 case LINK_SPEED_AUTO
:
491 mb
->un
.varInitLnk
.link_speed
=
498 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_AUTO
;
500 mb
->mbxCommand
= (volatile uint8_t)MBX_INIT_LINK
;
501 mb
->mbxOwner
= OWN_HOST
;
502 mb
->un
.varInitLnk
.fabric_AL_PA
= phba
->fc_pref_ALPA
;
507 * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
508 * @phba: pointer to lpfc hba data structure.
509 * @pmb: pointer to the driver internal queue element for mailbox command.
510 * @vpi: virtual N_Port identifier.
512 * The read service parameter mailbox command is used to read the HBA port
513 * service parameters. The service parameters are read into the buffer
514 * specified directly by a BDE in the mailbox command. These service
515 * parameters may then be used to build the payload of an N_Port/F_POrt
516 * login request and reply (LOGI/ACC).
518 * This routine prepares the mailbox command for reading HBA port service
519 * parameters. The DMA memory is allocated in this function and the addresses
520 * are populated into the mailbox command for the HBA to DMA the service
525 * 1 - DMA memory allocation failed
528 lpfc_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
, int vpi
)
530 struct lpfc_dmabuf
*mp
;
532 struct lpfc_sli
*psli
;
536 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
538 mb
->mbxOwner
= OWN_HOST
;
540 /* Get a buffer to hold the HBAs Service Parameters */
542 mp
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
544 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
545 if (!mp
|| !mp
->virt
) {
547 mb
->mbxCommand
= MBX_READ_SPARM64
;
548 /* READ_SPARAM: no buffers */
549 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
550 "0301 READ_SPARAM: no buffers\n");
553 INIT_LIST_HEAD(&mp
->list
);
554 mb
->mbxCommand
= MBX_READ_SPARM64
;
555 mb
->un
.varRdSparm
.un
.sp64
.tus
.f
.bdeSize
= sizeof (struct serv_parm
);
556 mb
->un
.varRdSparm
.un
.sp64
.addrHigh
= putPaddrHigh(mp
->phys
);
557 mb
->un
.varRdSparm
.un
.sp64
.addrLow
= putPaddrLow(mp
->phys
);
558 mb
->un
.varRdSparm
.vpi
= vpi
+ phba
->vpi_base
;
560 /* save address for completion */
567 * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
568 * @phba: pointer to lpfc hba data structure.
569 * @vpi: virtual N_Port identifier.
570 * @did: remote port identifier.
571 * @pmb: pointer to the driver internal queue element for mailbox command.
573 * The unregister DID mailbox command is used to unregister an N_Port/F_Port
574 * login for an unknown RPI by specifying the DID of a remote port. This
575 * command frees an RPI context in the HBA port. This has the effect of
576 * performing an implicit N_Port/F_Port logout.
578 * This routine prepares the mailbox command for unregistering a remote
579 * N_Port/F_Port (DID) login.
582 lpfc_unreg_did(struct lpfc_hba
* phba
, uint16_t vpi
, uint32_t did
,
588 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
590 mb
->un
.varUnregDID
.did
= did
;
592 vpi
+= phba
->vpi_base
;
593 mb
->un
.varUnregDID
.vpi
= vpi
;
595 mb
->mbxCommand
= MBX_UNREG_D_ID
;
596 mb
->mbxOwner
= OWN_HOST
;
601 * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
602 * @phba: pointer to lpfc hba data structure.
603 * @pmb: pointer to the driver internal queue element for mailbox command.
605 * The read configuration mailbox command is used to read the HBA port
606 * configuration parameters. This mailbox command provides a method for
607 * seeing any parameters that may have changed via various configuration
610 * This routine prepares the mailbox command for reading out HBA configuration
614 lpfc_read_config(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
619 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
621 mb
->mbxCommand
= MBX_READ_CONFIG
;
622 mb
->mbxOwner
= OWN_HOST
;
627 * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
628 * @phba: pointer to lpfc hba data structure.
629 * @pmb: pointer to the driver internal queue element for mailbox command.
631 * The read link status mailbox command is used to read the link status from
632 * the HBA. Link status includes all link-related error counters. These
633 * counters are maintained by the HBA and originated in the link hardware
634 * unit. Note that all of these counters wrap.
636 * This routine prepares the mailbox command for reading out HBA link status.
639 lpfc_read_lnk_stat(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
644 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
646 mb
->mbxCommand
= MBX_READ_LNK_STAT
;
647 mb
->mbxOwner
= OWN_HOST
;
652 * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
653 * @phba: pointer to lpfc hba data structure.
654 * @vpi: virtual N_Port identifier.
655 * @did: remote port identifier.
656 * @param: pointer to memory holding the server parameters.
657 * @pmb: pointer to the driver internal queue element for mailbox command.
658 * @flag: action flag to be passed back for the complete function.
660 * The registration login mailbox command is used to register an N_Port or
661 * F_Port login. This registration allows the HBA to cache the remote N_Port
662 * service parameters internally and thereby make the appropriate FC-2
663 * decisions. The remote port service parameters are handed off by the driver
664 * to the HBA using a descriptor entry that directly identifies a buffer in
665 * host memory. In exchange, the HBA returns an RPI identifier.
667 * This routine prepares the mailbox command for registering remote port login.
668 * The function allocates DMA buffer for passing the service parameters to the
669 * HBA with the mailbox command.
673 * 1 - DMA memory allocation failed
676 lpfc_reg_rpi(struct lpfc_hba
*phba
, uint16_t vpi
, uint32_t did
,
677 uint8_t *param
, LPFC_MBOXQ_t
*pmb
, uint32_t flag
)
679 MAILBOX_t
*mb
= &pmb
->u
.mb
;
681 struct lpfc_dmabuf
*mp
;
683 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
685 mb
->un
.varRegLogin
.rpi
= 0;
686 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
687 mb
->un
.varRegLogin
.rpi
= lpfc_sli4_alloc_rpi(phba
);
688 if (mb
->un
.varRegLogin
.rpi
== LPFC_RPI_ALLOC_ERROR
)
692 mb
->un
.varRegLogin
.vpi
= vpi
+ phba
->vpi_base
;
693 mb
->un
.varRegLogin
.did
= did
;
694 mb
->un
.varWords
[30] = flag
; /* Set flag to issue action on cmpl */
696 mb
->mbxOwner
= OWN_HOST
;
698 /* Get a buffer to hold NPorts Service Parameters */
699 mp
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
701 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
702 if (!mp
|| !mp
->virt
) {
704 mb
->mbxCommand
= MBX_REG_LOGIN64
;
705 /* REG_LOGIN: no buffers */
706 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
707 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
708 "flag x%x\n", vpi
, did
, flag
);
711 INIT_LIST_HEAD(&mp
->list
);
714 /* Copy param's into a new buffer */
715 memcpy(sparam
, param
, sizeof (struct serv_parm
));
717 /* save address for completion */
718 pmb
->context1
= (uint8_t *) mp
;
720 mb
->mbxCommand
= MBX_REG_LOGIN64
;
721 mb
->un
.varRegLogin
.un
.sp64
.tus
.f
.bdeSize
= sizeof (struct serv_parm
);
722 mb
->un
.varRegLogin
.un
.sp64
.addrHigh
= putPaddrHigh(mp
->phys
);
723 mb
->un
.varRegLogin
.un
.sp64
.addrLow
= putPaddrLow(mp
->phys
);
729 * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
730 * @phba: pointer to lpfc hba data structure.
731 * @vpi: virtual N_Port identifier.
732 * @rpi: remote port identifier
733 * @pmb: pointer to the driver internal queue element for mailbox command.
735 * The unregistration login mailbox command is used to unregister an N_Port
736 * or F_Port login. This command frees an RPI context in the HBA. It has the
737 * effect of performing an implicit N_Port/F_Port logout.
739 * This routine prepares the mailbox command for unregistering remote port
743 lpfc_unreg_login(struct lpfc_hba
*phba
, uint16_t vpi
, uint32_t rpi
,
749 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
751 mb
->un
.varUnregLogin
.rpi
= (uint16_t) rpi
;
752 mb
->un
.varUnregLogin
.rsvd1
= 0;
753 mb
->un
.varUnregLogin
.vpi
= vpi
+ phba
->vpi_base
;
755 mb
->mbxCommand
= MBX_UNREG_LOGIN
;
756 mb
->mbxOwner
= OWN_HOST
;
762 * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
763 * @phba: pointer to lpfc hba data structure.
764 * @vpi: virtual N_Port identifier.
765 * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
766 * @pmb: pointer to the driver internal queue element for mailbox command.
768 * The registration vport identifier mailbox command is used to activate a
769 * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
770 * N_Port_ID against the information in the selected virtual N_Port context
771 * block and marks it active to allow normal processing of IOCB commands and
772 * received unsolicited exchanges.
774 * This routine prepares the mailbox command for registering a virtual N_Port.
777 lpfc_reg_vpi(struct lpfc_vport
*vport
, LPFC_MBOXQ_t
*pmb
)
779 MAILBOX_t
*mb
= &pmb
->u
.mb
;
781 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
783 mb
->un
.varRegVpi
.vpi
= vport
->vpi
+ vport
->phba
->vpi_base
;
784 mb
->un
.varRegVpi
.sid
= vport
->fc_myDID
;
785 mb
->un
.varRegVpi
.vfi
= vport
->vfi
+ vport
->phba
->vfi_base
;
787 mb
->mbxCommand
= MBX_REG_VPI
;
788 mb
->mbxOwner
= OWN_HOST
;
794 * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
795 * @phba: pointer to lpfc hba data structure.
796 * @vpi: virtual N_Port identifier.
797 * @pmb: pointer to the driver internal queue element for mailbox command.
799 * The unregistration vport identifier mailbox command is used to inactivate
800 * a virtual N_Port. The driver must have logged out and unregistered all
801 * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
802 * unregisters any default RPIs associated with the specified vpi, aborting
803 * any active exchanges. The HBA will post the mailbox response after making
804 * the virtual N_Port inactive.
806 * This routine prepares the mailbox command for unregistering a virtual
810 lpfc_unreg_vpi(struct lpfc_hba
*phba
, uint16_t vpi
, LPFC_MBOXQ_t
*pmb
)
812 MAILBOX_t
*mb
= &pmb
->u
.mb
;
813 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
815 mb
->un
.varUnregVpi
.vpi
= vpi
+ phba
->vpi_base
;
817 mb
->mbxCommand
= MBX_UNREG_VPI
;
818 mb
->mbxOwner
= OWN_HOST
;
824 * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
825 * @phba: pointer to lpfc hba data structure.
827 * This routine sets up and initializes the IOCB rings in the Port Control
831 lpfc_config_pcb_setup(struct lpfc_hba
* phba
)
833 struct lpfc_sli
*psli
= &phba
->sli
;
834 struct lpfc_sli_ring
*pring
;
835 PCB_t
*pcbp
= phba
->pcb
;
836 dma_addr_t pdma_addr
;
838 uint32_t iocbCnt
= 0;
841 pcbp
->maxRing
= (psli
->num_rings
- 1);
843 for (i
= 0; i
< psli
->num_rings
; i
++) {
844 pring
= &psli
->ring
[i
];
846 pring
->sizeCiocb
= phba
->sli_rev
== 3 ? SLI3_IOCB_CMD_SIZE
:
848 pring
->sizeRiocb
= phba
->sli_rev
== 3 ? SLI3_IOCB_RSP_SIZE
:
850 /* A ring MUST have both cmd and rsp entries defined to be
852 if ((pring
->numCiocb
== 0) || (pring
->numRiocb
== 0)) {
853 pcbp
->rdsc
[i
].cmdEntries
= 0;
854 pcbp
->rdsc
[i
].rspEntries
= 0;
855 pcbp
->rdsc
[i
].cmdAddrHigh
= 0;
856 pcbp
->rdsc
[i
].rspAddrHigh
= 0;
857 pcbp
->rdsc
[i
].cmdAddrLow
= 0;
858 pcbp
->rdsc
[i
].rspAddrLow
= 0;
859 pring
->cmdringaddr
= NULL
;
860 pring
->rspringaddr
= NULL
;
863 /* Command ring setup for ring */
864 pring
->cmdringaddr
= (void *)&phba
->IOCBs
[iocbCnt
];
865 pcbp
->rdsc
[i
].cmdEntries
= pring
->numCiocb
;
867 offset
= (uint8_t *) &phba
->IOCBs
[iocbCnt
] -
868 (uint8_t *) phba
->slim2p
.virt
;
869 pdma_addr
= phba
->slim2p
.phys
+ offset
;
870 pcbp
->rdsc
[i
].cmdAddrHigh
= putPaddrHigh(pdma_addr
);
871 pcbp
->rdsc
[i
].cmdAddrLow
= putPaddrLow(pdma_addr
);
872 iocbCnt
+= pring
->numCiocb
;
874 /* Response ring setup for ring */
875 pring
->rspringaddr
= (void *) &phba
->IOCBs
[iocbCnt
];
877 pcbp
->rdsc
[i
].rspEntries
= pring
->numRiocb
;
878 offset
= (uint8_t *)&phba
->IOCBs
[iocbCnt
] -
879 (uint8_t *)phba
->slim2p
.virt
;
880 pdma_addr
= phba
->slim2p
.phys
+ offset
;
881 pcbp
->rdsc
[i
].rspAddrHigh
= putPaddrHigh(pdma_addr
);
882 pcbp
->rdsc
[i
].rspAddrLow
= putPaddrLow(pdma_addr
);
883 iocbCnt
+= pring
->numRiocb
;
888 * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
889 * @phba: pointer to lpfc hba data structure.
890 * @pmb: pointer to the driver internal queue element for mailbox command.
892 * The read revision mailbox command is used to read the revision levels of
893 * the HBA components. These components include hardware units, resident
894 * firmware, and available firmware. HBAs that supports SLI-3 mode of
895 * operation provide different response information depending on the version
896 * requested by the driver.
898 * This routine prepares the mailbox command for reading HBA revision
902 lpfc_read_rev(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
904 MAILBOX_t
*mb
= &pmb
->u
.mb
;
905 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
906 mb
->un
.varRdRev
.cv
= 1;
907 mb
->un
.varRdRev
.v3req
= 1; /* Request SLI3 info */
908 mb
->mbxCommand
= MBX_READ_REV
;
909 mb
->mbxOwner
= OWN_HOST
;
914 * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
915 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
916 * @hbq_desc: pointer to the HBQ selection profile descriptor.
918 * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
919 * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
920 * the Sequence Length Test using the fields in the Selection Profile 2
921 * extension in words 20:31.
924 lpfc_build_hbq_profile2(struct config_hbq_var
*hbqmb
,
925 struct lpfc_hbq_init
*hbq_desc
)
927 hbqmb
->profiles
.profile2
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
928 hbqmb
->profiles
.profile2
.maxlen
= hbq_desc
->maxlen
;
929 hbqmb
->profiles
.profile2
.seqlenoff
= hbq_desc
->seqlenoff
;
933 * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
934 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
935 * @hbq_desc: pointer to the HBQ selection profile descriptor.
937 * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
938 * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
939 * the Sequence Length Test and Byte Field Test using the fields in the
940 * Selection Profile 3 extension in words 20:31.
943 lpfc_build_hbq_profile3(struct config_hbq_var
*hbqmb
,
944 struct lpfc_hbq_init
*hbq_desc
)
946 hbqmb
->profiles
.profile3
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
947 hbqmb
->profiles
.profile3
.maxlen
= hbq_desc
->maxlen
;
948 hbqmb
->profiles
.profile3
.cmdcodeoff
= hbq_desc
->cmdcodeoff
;
949 hbqmb
->profiles
.profile3
.seqlenoff
= hbq_desc
->seqlenoff
;
950 memcpy(&hbqmb
->profiles
.profile3
.cmdmatch
, hbq_desc
->cmdmatch
,
951 sizeof(hbqmb
->profiles
.profile3
.cmdmatch
));
955 * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
956 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
957 * @hbq_desc: pointer to the HBQ selection profile descriptor.
959 * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
960 * HBA tests the initial frame of an incoming sequence using the frame's
961 * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
962 * and Byte Field Test using the fields in the Selection Profile 5 extension
966 lpfc_build_hbq_profile5(struct config_hbq_var
*hbqmb
,
967 struct lpfc_hbq_init
*hbq_desc
)
969 hbqmb
->profiles
.profile5
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
970 hbqmb
->profiles
.profile5
.maxlen
= hbq_desc
->maxlen
;
971 hbqmb
->profiles
.profile5
.cmdcodeoff
= hbq_desc
->cmdcodeoff
;
972 hbqmb
->profiles
.profile5
.seqlenoff
= hbq_desc
->seqlenoff
;
973 memcpy(&hbqmb
->profiles
.profile5
.cmdmatch
, hbq_desc
->cmdmatch
,
974 sizeof(hbqmb
->profiles
.profile5
.cmdmatch
));
978 * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
979 * @phba: pointer to lpfc hba data structure.
980 * @id: HBQ identifier.
981 * @hbq_desc: pointer to the HBA descriptor data structure.
982 * @hbq_entry_index: index of the HBQ entry data structures.
983 * @pmb: pointer to the driver internal queue element for mailbox command.
985 * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
986 * an HBQ. The configuration binds events that require buffers to a particular
987 * ring and HBQ based on a selection profile.
989 * This routine prepares the mailbox command for configuring an HBQ.
992 lpfc_config_hbq(struct lpfc_hba
*phba
, uint32_t id
,
993 struct lpfc_hbq_init
*hbq_desc
,
994 uint32_t hbq_entry_index
, LPFC_MBOXQ_t
*pmb
)
997 MAILBOX_t
*mb
= &pmb
->u
.mb
;
998 struct config_hbq_var
*hbqmb
= &mb
->un
.varCfgHbq
;
1000 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
1002 hbqmb
->entry_count
= hbq_desc
->entry_count
; /* # entries in HBQ */
1003 hbqmb
->recvNotify
= hbq_desc
->rn
; /* Receive
1005 hbqmb
->numMask
= hbq_desc
->mask_count
; /* # R_CTL/TYPE masks
1006 * # in words 0-19 */
1007 hbqmb
->profile
= hbq_desc
->profile
; /* Selection profile:
1010 hbqmb
->ringMask
= hbq_desc
->ring_mask
; /* Binds HBQ to a ring
1013 hbqmb
->headerLen
= hbq_desc
->headerLen
; /* 0 if not profile 4
1015 hbqmb
->logEntry
= hbq_desc
->logEntry
; /* Set to 1 if this
1019 hbqmb
->hbqaddrLow
= putPaddrLow(phba
->hbqslimp
.phys
) +
1020 hbq_entry_index
* sizeof(struct lpfc_hbq_entry
);
1021 hbqmb
->hbqaddrHigh
= putPaddrHigh(phba
->hbqslimp
.phys
);
1023 mb
->mbxCommand
= MBX_CONFIG_HBQ
;
1024 mb
->mbxOwner
= OWN_HOST
;
1026 /* Copy info for profiles 2,3,5. Other
1027 * profiles this area is reserved
1029 if (hbq_desc
->profile
== 2)
1030 lpfc_build_hbq_profile2(hbqmb
, hbq_desc
);
1031 else if (hbq_desc
->profile
== 3)
1032 lpfc_build_hbq_profile3(hbqmb
, hbq_desc
);
1033 else if (hbq_desc
->profile
== 5)
1034 lpfc_build_hbq_profile5(hbqmb
, hbq_desc
);
1036 /* Return if no rctl / type masks for this HBQ */
1037 if (!hbq_desc
->mask_count
)
1040 /* Otherwise we setup specific rctl / type masks for this HBQ */
1041 for (i
= 0; i
< hbq_desc
->mask_count
; i
++) {
1042 hbqmb
->hbqMasks
[i
].tmatch
= hbq_desc
->hbqMasks
[i
].tmatch
;
1043 hbqmb
->hbqMasks
[i
].tmask
= hbq_desc
->hbqMasks
[i
].tmask
;
1044 hbqmb
->hbqMasks
[i
].rctlmatch
= hbq_desc
->hbqMasks
[i
].rctlmatch
;
1045 hbqmb
->hbqMasks
[i
].rctlmask
= hbq_desc
->hbqMasks
[i
].rctlmask
;
1052 * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
1053 * @phba: pointer to lpfc hba data structure.
1055 * @pmb: pointer to the driver internal queue element for mailbox command.
1057 * The configure ring mailbox command is used to configure an IOCB ring. This
1058 * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1059 * ring. This is used to map incoming sequences to a particular ring whose
1060 * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1061 * attempt to configure a ring whose number is greater than the number
1062 * specified in the Port Control Block (PCB). It is an error to issue the
1063 * configure ring command more than once with the same ring number. The HBA
1064 * returns an error if the driver attempts this.
1066 * This routine prepares the mailbox command for configuring IOCB ring.
1069 lpfc_config_ring(struct lpfc_hba
* phba
, int ring
, LPFC_MBOXQ_t
* pmb
)
1072 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1073 struct lpfc_sli
*psli
;
1074 struct lpfc_sli_ring
*pring
;
1076 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
1078 mb
->un
.varCfgRing
.ring
= ring
;
1079 mb
->un
.varCfgRing
.maxOrigXchg
= 0;
1080 mb
->un
.varCfgRing
.maxRespXchg
= 0;
1081 mb
->un
.varCfgRing
.recvNotify
= 1;
1084 pring
= &psli
->ring
[ring
];
1085 mb
->un
.varCfgRing
.numMask
= pring
->num_mask
;
1086 mb
->mbxCommand
= MBX_CONFIG_RING
;
1087 mb
->mbxOwner
= OWN_HOST
;
1089 /* Is this ring configured for a specific profile */
1090 if (pring
->prt
[0].profile
) {
1091 mb
->un
.varCfgRing
.profile
= pring
->prt
[0].profile
;
1095 /* Otherwise we setup specific rctl / type masks for this ring */
1096 for (i
= 0; i
< pring
->num_mask
; i
++) {
1097 mb
->un
.varCfgRing
.rrRegs
[i
].rval
= pring
->prt
[i
].rctl
;
1098 if (mb
->un
.varCfgRing
.rrRegs
[i
].rval
!= FC_ELS_REQ
)
1099 mb
->un
.varCfgRing
.rrRegs
[i
].rmask
= 0xff;
1101 mb
->un
.varCfgRing
.rrRegs
[i
].rmask
= 0xfe;
1102 mb
->un
.varCfgRing
.rrRegs
[i
].tval
= pring
->prt
[i
].type
;
1103 mb
->un
.varCfgRing
.rrRegs
[i
].tmask
= 0xff;
1110 * lpfc_config_port - Prepare a mailbox command for configuring port
1111 * @phba: pointer to lpfc hba data structure.
1112 * @pmb: pointer to the driver internal queue element for mailbox command.
1114 * The configure port mailbox command is used to identify the Port Control
1115 * Block (PCB) in the driver memory. After this command is issued, the
1116 * driver must not access the mailbox in the HBA without first resetting
1117 * the HBA. The HBA may copy the PCB information to internal storage for
1118 * subsequent use; the driver can not change the PCB information unless it
1121 * This routine prepares the mailbox command for configuring port.
1124 lpfc_config_port(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1126 MAILBOX_t __iomem
*mb_slim
= (MAILBOX_t __iomem
*) phba
->MBslimaddr
;
1127 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1128 dma_addr_t pdma_addr
;
1129 uint32_t bar_low
, bar_high
;
1131 struct lpfc_hgp hgp
;
1133 uint32_t pgp_offset
;
1135 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
1136 mb
->mbxCommand
= MBX_CONFIG_PORT
;
1137 mb
->mbxOwner
= OWN_HOST
;
1139 mb
->un
.varCfgPort
.pcbLen
= sizeof(PCB_t
);
1141 offset
= (uint8_t *)phba
->pcb
- (uint8_t *)phba
->slim2p
.virt
;
1142 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1143 mb
->un
.varCfgPort
.pcbLow
= putPaddrLow(pdma_addr
);
1144 mb
->un
.varCfgPort
.pcbHigh
= putPaddrHigh(pdma_addr
);
1146 /* Always Host Group Pointer is in SLIM */
1147 mb
->un
.varCfgPort
.hps
= 1;
1149 /* If HBA supports SLI=3 ask for it */
1151 if (phba
->sli_rev
== LPFC_SLI_REV3
&& phba
->vpd
.sli3Feat
.cerbm
) {
1152 if (phba
->cfg_enable_bg
)
1153 mb
->un
.varCfgPort
.cbg
= 1; /* configure BlockGuard */
1154 mb
->un
.varCfgPort
.cdss
= 1; /* Configure Security */
1155 mb
->un
.varCfgPort
.cerbm
= 1; /* Request HBQs */
1156 mb
->un
.varCfgPort
.ccrp
= 1; /* Command Ring Polling */
1157 mb
->un
.varCfgPort
.cinb
= 1; /* Interrupt Notification Block */
1158 mb
->un
.varCfgPort
.max_hbq
= lpfc_sli_hbq_count();
1159 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
1160 phba
->vpd
.sli3Feat
.cmv
) {
1161 mb
->un
.varCfgPort
.max_vpi
= LPFC_MAX_VPI
;
1162 mb
->un
.varCfgPort
.cmv
= 1;
1164 mb
->un
.varCfgPort
.max_vpi
= phba
->max_vpi
= 0;
1166 phba
->sli_rev
= LPFC_SLI_REV2
;
1167 mb
->un
.varCfgPort
.sli_mode
= phba
->sli_rev
;
1170 phba
->pcb
->type
= TYPE_NATIVE_SLI2
;
1171 phba
->pcb
->feature
= FEATURE_INITIAL_SLI2
;
1173 /* Setup Mailbox pointers */
1174 phba
->pcb
->mailBoxSize
= sizeof(MAILBOX_t
);
1175 offset
= (uint8_t *)phba
->mbox
- (uint8_t *)phba
->slim2p
.virt
;
1176 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1177 phba
->pcb
->mbAddrHigh
= putPaddrHigh(pdma_addr
);
1178 phba
->pcb
->mbAddrLow
= putPaddrLow(pdma_addr
);
1181 * Setup Host Group ring pointer.
1183 * For efficiency reasons, the ring get/put pointers can be
1184 * placed in adapter memory (SLIM) rather than in host memory.
1185 * This allows firmware to avoid PCI reads/writes when updating
1186 * and checking pointers.
1188 * The firmware recognizes the use of SLIM memory by comparing
1189 * the address of the get/put pointers structure with that of
1190 * the SLIM BAR (BAR0).
1192 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1193 * (the hardware's view of the base address), not the OS's
1194 * value of pci_resource_start() as the OS value may be a cookie
1195 * for ioremap/iomap.
1199 pci_read_config_dword(phba
->pcidev
, PCI_BASE_ADDRESS_0
, &bar_low
);
1200 pci_read_config_dword(phba
->pcidev
, PCI_BASE_ADDRESS_1
, &bar_high
);
1203 * Set up HGP - Port Memory
1205 * The port expects the host get/put pointers to reside in memory
1206 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1207 * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
1208 * words (0x40 bytes). This area is not reserved if HBQs are
1209 * configured in SLI-3.
1211 * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1220 * Reserved 0xa0-0xbf
1221 * If HBQs configured:
1222 * HBQ 0 Put ptr 0xc0
1223 * HBQ 1 Put ptr 0xc4
1224 * HBQ 2 Put ptr 0xc8
1226 * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1230 if (phba
->sli_rev
== 3) {
1231 phba
->host_gp
= &mb_slim
->us
.s3
.host
[0];
1232 phba
->hbq_put
= &mb_slim
->us
.s3
.hbq_put
[0];
1234 phba
->host_gp
= &mb_slim
->us
.s2
.host
[0];
1235 phba
->hbq_put
= NULL
;
1238 /* mask off BAR0's flag bits 0 - 3 */
1239 phba
->pcb
->hgpAddrLow
= (bar_low
& PCI_BASE_ADDRESS_MEM_MASK
) +
1240 (void __iomem
*)phba
->host_gp
-
1241 (void __iomem
*)phba
->MBslimaddr
;
1242 if (bar_low
& PCI_BASE_ADDRESS_MEM_TYPE_64
)
1243 phba
->pcb
->hgpAddrHigh
= bar_high
;
1245 phba
->pcb
->hgpAddrHigh
= 0;
1246 /* write HGP data to SLIM at the required longword offset */
1247 memset(&hgp
, 0, sizeof(struct lpfc_hgp
));
1249 for (i
=0; i
< phba
->sli
.num_rings
; i
++) {
1250 lpfc_memcpy_to_slim(phba
->host_gp
+ i
, &hgp
,
1251 sizeof(*phba
->host_gp
));
1254 /* Setup Port Group offset */
1255 if (phba
->sli_rev
== 3)
1256 pgp_offset
= offsetof(struct lpfc_sli2_slim
,
1257 mbx
.us
.s3_pgp
.port
);
1259 pgp_offset
= offsetof(struct lpfc_sli2_slim
, mbx
.us
.s2
.port
);
1260 pdma_addr
= phba
->slim2p
.phys
+ pgp_offset
;
1261 phba
->pcb
->pgpAddrHigh
= putPaddrHigh(pdma_addr
);
1262 phba
->pcb
->pgpAddrLow
= putPaddrLow(pdma_addr
);
1264 /* Use callback routine to setp rings in the pcb */
1265 lpfc_config_pcb_setup(phba
);
1267 /* special handling for LC HBAs */
1268 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
1269 uint32_t hbainit
[5];
1271 lpfc_hba_init(phba
, hbainit
);
1273 memcpy(&mb
->un
.varCfgPort
.hbainit
, hbainit
, 20);
1276 /* Swap PCB if needed */
1277 lpfc_sli_pcimem_bcopy(phba
->pcb
, phba
->pcb
, sizeof(PCB_t
));
1281 * lpfc_kill_board - Prepare a mailbox command for killing board
1282 * @phba: pointer to lpfc hba data structure.
1283 * @pmb: pointer to the driver internal queue element for mailbox command.
1285 * The kill board mailbox command is used to tell firmware to perform a
1286 * graceful shutdown of a channel on a specified board to prepare for reset.
1287 * When the kill board mailbox command is received, the ER3 bit is set to 1
1288 * in the Host Status register and the ER Attention bit is set to 1 in the
1289 * Host Attention register of the HBA function that received the kill board
1292 * This routine prepares the mailbox command for killing the board in
1293 * preparation for a graceful shutdown.
1296 lpfc_kill_board(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
1298 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1300 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
1301 mb
->mbxCommand
= MBX_KILL_BOARD
;
1302 mb
->mbxOwner
= OWN_HOST
;
1307 * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
1308 * @phba: pointer to lpfc hba data structure.
1309 * @mbq: pointer to the driver internal queue element for mailbox command.
1311 * Driver maintains a internal mailbox command queue implemented as a linked
1312 * list. When a mailbox command is issued, it shall be put into the mailbox
1313 * command queue such that they shall be processed orderly as HBA can process
1314 * one mailbox command at a time.
1317 lpfc_mbox_put(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* mbq
)
1319 struct lpfc_sli
*psli
;
1323 list_add_tail(&mbq
->list
, &psli
->mboxq
);
1331 * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
1332 * @phba: pointer to lpfc hba data structure.
1334 * Driver maintains a internal mailbox command queue implemented as a linked
1335 * list. When a mailbox command is issued, it shall be put into the mailbox
1336 * command queue such that they shall be processed orderly as HBA can process
1337 * one mailbox command at a time. After HBA finished processing a mailbox
1338 * command, the driver will remove a pending mailbox command from the head of
1339 * the mailbox command queue and send to the HBA for processing.
1342 * pointer to the driver internal queue element for mailbox command.
1345 lpfc_mbox_get(struct lpfc_hba
* phba
)
1347 LPFC_MBOXQ_t
*mbq
= NULL
;
1348 struct lpfc_sli
*psli
= &phba
->sli
;
1350 list_remove_head((&psli
->mboxq
), mbq
, LPFC_MBOXQ_t
, list
);
1358 * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
1359 * @phba: pointer to lpfc hba data structure.
1360 * @mbq: pointer to the driver internal queue element for mailbox command.
1362 * This routine put the completed mailbox command into the mailbox command
1363 * complete list. This is the unlocked version of the routine. The mailbox
1364 * complete list is used by the driver worker thread to process mailbox
1365 * complete callback functions outside the driver interrupt handler.
1368 __lpfc_mbox_cmpl_put(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbq
)
1370 list_add_tail(&mbq
->list
, &phba
->sli
.mboxq_cmpl
);
1374 * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
1375 * @phba: pointer to lpfc hba data structure.
1376 * @mbq: pointer to the driver internal queue element for mailbox command.
1378 * This routine put the completed mailbox command into the mailbox command
1379 * complete list. This is the locked version of the routine. The mailbox
1380 * complete list is used by the driver worker thread to process mailbox
1381 * complete callback functions outside the driver interrupt handler.
1384 lpfc_mbox_cmpl_put(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbq
)
1386 unsigned long iflag
;
1388 /* This function expects to be called from interrupt context */
1389 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1390 __lpfc_mbox_cmpl_put(phba
, mbq
);
1391 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1396 * lpfc_mbox_cmd_check - Check the validality of a mailbox command
1397 * @phba: pointer to lpfc hba data structure.
1398 * @mboxq: pointer to the driver internal queue element for mailbox command.
1400 * This routine is to check whether a mailbox command is valid to be issued.
1401 * This check will be performed by both the mailbox issue API when a client
1402 * is to issue a mailbox command to the mailbox transport.
1404 * Return 0 - pass the check, -ENODEV - fail the check
1407 lpfc_mbox_cmd_check(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1409 /* Mailbox command that have a completion handler must also have a
1412 if (mboxq
->mbox_cmpl
&& mboxq
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
1413 mboxq
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
1414 if (!mboxq
->vport
) {
1415 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
1416 "1814 Mbox x%x failed, no vport\n",
1417 mboxq
->u
.mb
.mbxCommand
);
1426 * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
1427 * @phba: pointer to lpfc hba data structure.
1429 * This routine is to check whether the HBA device is ready for posting a
1430 * mailbox command. It is used by the mailbox transport API at the time the
1431 * to post a mailbox command to the device.
1433 * Return 0 - pass the check, -ENODEV - fail the check
1436 lpfc_mbox_dev_check(struct lpfc_hba
*phba
)
1438 /* If the PCI channel is in offline state, do not issue mbox */
1439 if (unlikely(pci_channel_offline(phba
->pcidev
)))
1442 /* If the HBA is in error state, do not issue mbox */
1443 if (phba
->link_state
== LPFC_HBA_ERROR
)
1450 * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
1451 * @phba: pointer to lpfc hba data structure.
1452 * @cmd: mailbox command code.
1454 * This routine retrieves the proper timeout value according to the mailbox
1458 * Timeout value to be used for the given mailbox command
1461 lpfc_mbox_tmo_val(struct lpfc_hba
*phba
, int cmd
)
1464 case MBX_WRITE_NV
: /* 0x03 */
1465 case MBX_UPDATE_CFG
: /* 0x1B */
1466 case MBX_DOWN_LOAD
: /* 0x1C */
1467 case MBX_DEL_LD_ENTRY
: /* 0x1D */
1468 case MBX_LOAD_AREA
: /* 0x81 */
1469 case MBX_WRITE_WWN
: /* 0x98 */
1470 case MBX_LOAD_EXP_ROM
: /* 0x9C */
1471 return LPFC_MBOX_TMO_FLASH_CMD
;
1472 case MBX_SLI4_CONFIG
: /* 0x9b */
1473 return LPFC_MBOX_SLI4_CONFIG_TMO
;
1475 return LPFC_MBOX_TMO
;
1479 * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
1480 * @mbox: pointer to lpfc mbox command.
1481 * @sgentry: sge entry index.
1482 * @phyaddr: physical address for the sge
1483 * @length: Length of the sge.
1485 * This routine sets up an entry in the non-embedded mailbox command at the sge
1489 lpfc_sli4_mbx_sge_set(struct lpfcMboxq
*mbox
, uint32_t sgentry
,
1490 dma_addr_t phyaddr
, uint32_t length
)
1492 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
1494 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
1495 &mbox
->u
.mqe
.un
.nembed_cmd
;
1496 nembed_sge
->sge
[sgentry
].pa_lo
= putPaddrLow(phyaddr
);
1497 nembed_sge
->sge
[sgentry
].pa_hi
= putPaddrHigh(phyaddr
);
1498 nembed_sge
->sge
[sgentry
].length
= length
;
1502 * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
1503 * @mbox: pointer to lpfc mbox command.
1504 * @sgentry: sge entry index.
1506 * This routine gets an entry from the non-embedded mailbox command at the sge
1510 lpfc_sli4_mbx_sge_get(struct lpfcMboxq
*mbox
, uint32_t sgentry
,
1511 struct lpfc_mbx_sge
*sge
)
1513 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
1515 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
1516 &mbox
->u
.mqe
.un
.nembed_cmd
;
1517 sge
->pa_lo
= nembed_sge
->sge
[sgentry
].pa_lo
;
1518 sge
->pa_hi
= nembed_sge
->sge
[sgentry
].pa_hi
;
1519 sge
->length
= nembed_sge
->sge
[sgentry
].length
;
1523 * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
1524 * @phba: pointer to lpfc hba data structure.
1525 * @mbox: pointer to lpfc mbox command.
1527 * This routine frees SLI4 specific mailbox command for sending IOCTL command.
1530 lpfc_sli4_mbox_cmd_free(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
1532 struct lpfc_mbx_sli4_config
*sli4_cfg
;
1533 struct lpfc_mbx_sge sge
;
1535 uint32_t sgecount
, sgentry
;
1537 sli4_cfg
= &mbox
->u
.mqe
.un
.sli4_config
;
1539 /* For embedded mbox command, just free the mbox command */
1540 if (bf_get(lpfc_mbox_hdr_emb
, &sli4_cfg
->header
.cfg_mhdr
)) {
1541 mempool_free(mbox
, phba
->mbox_mem_pool
);
1545 /* For non-embedded mbox command, we need to free the pages first */
1546 sgecount
= bf_get(lpfc_mbox_hdr_sge_cnt
, &sli4_cfg
->header
.cfg_mhdr
);
1547 /* There is nothing we can do if there is no sge address array */
1548 if (unlikely(!mbox
->sge_array
)) {
1549 mempool_free(mbox
, phba
->mbox_mem_pool
);
1552 /* Each non-embedded DMA memory was allocated in the length of a page */
1553 for (sgentry
= 0; sgentry
< sgecount
; sgentry
++) {
1554 lpfc_sli4_mbx_sge_get(mbox
, sgentry
, &sge
);
1555 phyaddr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
1556 dma_free_coherent(&phba
->pcidev
->dev
, PAGE_SIZE
,
1557 mbox
->sge_array
->addr
[sgentry
], phyaddr
);
1559 /* Free the sge address array memory */
1560 kfree(mbox
->sge_array
);
1561 /* Finally, free the mailbox command itself */
1562 mempool_free(mbox
, phba
->mbox_mem_pool
);
1566 * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command
1567 * @phba: pointer to lpfc hba data structure.
1568 * @mbox: pointer to lpfc mbox command.
1569 * @subsystem: The sli4 config sub mailbox subsystem.
1570 * @opcode: The sli4 config sub mailbox command opcode.
1571 * @length: Length of the sli4 config mailbox command.
1573 * This routine sets up the header fields of SLI4 specific mailbox command
1574 * for sending IOCTL command.
1576 * Return: the actual length of the mbox command allocated (mostly useful
1577 * for none embedded mailbox command).
1580 lpfc_sli4_config(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
,
1581 uint8_t subsystem
, uint8_t opcode
, uint32_t length
, bool emb
)
1583 struct lpfc_mbx_sli4_config
*sli4_config
;
1584 union lpfc_sli4_cfg_shdr
*cfg_shdr
= NULL
;
1587 uint32_t pagen
, pcount
;
1591 /* Set up SLI4 mailbox command header fields */
1592 memset(mbox
, 0, sizeof(*mbox
));
1593 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_SLI4_CONFIG
);
1595 /* Set up SLI4 ioctl command header fields */
1596 sli4_config
= &mbox
->u
.mqe
.un
.sli4_config
;
1598 /* Setup for the embedded mbox command */
1600 /* Set up main header fields */
1601 bf_set(lpfc_mbox_hdr_emb
, &sli4_config
->header
.cfg_mhdr
, 1);
1602 sli4_config
->header
.cfg_mhdr
.payload_length
=
1603 LPFC_MBX_CMD_HDR_LENGTH
+ length
;
1604 /* Set up sub-header fields following main header */
1605 bf_set(lpfc_mbox_hdr_opcode
,
1606 &sli4_config
->header
.cfg_shdr
.request
, opcode
);
1607 bf_set(lpfc_mbox_hdr_subsystem
,
1608 &sli4_config
->header
.cfg_shdr
.request
, subsystem
);
1609 sli4_config
->header
.cfg_shdr
.request
.request_length
= length
;
1613 /* Setup for the none-embedded mbox command */
1614 pcount
= (PAGE_ALIGN(length
))/PAGE_SIZE
;
1615 pcount
= (pcount
> LPFC_SLI4_MBX_SGE_MAX_PAGES
) ?
1616 LPFC_SLI4_MBX_SGE_MAX_PAGES
: pcount
;
1617 /* Allocate record for keeping SGE virtual addresses */
1618 mbox
->sge_array
= kmalloc(sizeof(struct lpfc_mbx_nembed_sge_virt
),
1620 if (!mbox
->sge_array
)
1623 for (pagen
= 0, alloc_len
= 0; pagen
< pcount
; pagen
++) {
1624 /* The DMA memory is always allocated in the length of a
1625 * page even though the last SGE might not fill up to a
1626 * page, this is used as a priori size of PAGE_SIZE for
1627 * the later DMA memory free.
1629 viraddr
= dma_alloc_coherent(&phba
->pcidev
->dev
, PAGE_SIZE
,
1630 &phyaddr
, GFP_KERNEL
);
1631 /* In case of malloc fails, proceed with whatever we have */
1634 memset(viraddr
, 0, PAGE_SIZE
);
1635 mbox
->sge_array
->addr
[pagen
] = viraddr
;
1636 /* Keep the first page for later sub-header construction */
1638 cfg_shdr
= (union lpfc_sli4_cfg_shdr
*)viraddr
;
1639 resid_len
= length
- alloc_len
;
1640 if (resid_len
> PAGE_SIZE
) {
1641 lpfc_sli4_mbx_sge_set(mbox
, pagen
, phyaddr
,
1643 alloc_len
+= PAGE_SIZE
;
1645 lpfc_sli4_mbx_sge_set(mbox
, pagen
, phyaddr
,
1651 /* Set up main header fields in mailbox command */
1652 sli4_config
->header
.cfg_mhdr
.payload_length
= alloc_len
;
1653 bf_set(lpfc_mbox_hdr_sge_cnt
, &sli4_config
->header
.cfg_mhdr
, pagen
);
1655 /* Set up sub-header fields into the first page */
1657 bf_set(lpfc_mbox_hdr_opcode
, &cfg_shdr
->request
, opcode
);
1658 bf_set(lpfc_mbox_hdr_subsystem
, &cfg_shdr
->request
, subsystem
);
1659 cfg_shdr
->request
.request_length
=
1660 alloc_len
- sizeof(union lpfc_sli4_cfg_shdr
);
1662 /* The sub-header is in DMA memory, which needs endian converstion */
1663 lpfc_sli_pcimem_bcopy(cfg_shdr
, cfg_shdr
,
1664 sizeof(union lpfc_sli4_cfg_shdr
));
1670 * lpfc_sli4_mbox_opcode_get - Get the opcode from a sli4 mailbox command
1671 * @phba: pointer to lpfc hba data structure.
1672 * @mbox: pointer to lpfc mbox command.
1674 * This routine gets the opcode from a SLI4 specific mailbox command for
1675 * sending IOCTL command. If the mailbox command is not MBX_SLI4_CONFIG
1676 * (0x9B) or if the IOCTL sub-header is not present, opcode 0x0 shall be
1680 lpfc_sli4_mbox_opcode_get(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
1682 struct lpfc_mbx_sli4_config
*sli4_cfg
;
1683 union lpfc_sli4_cfg_shdr
*cfg_shdr
;
1685 if (mbox
->u
.mb
.mbxCommand
!= MBX_SLI4_CONFIG
)
1687 sli4_cfg
= &mbox
->u
.mqe
.un
.sli4_config
;
1689 /* For embedded mbox command, get opcode from embedded sub-header*/
1690 if (bf_get(lpfc_mbox_hdr_emb
, &sli4_cfg
->header
.cfg_mhdr
)) {
1691 cfg_shdr
= &mbox
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
1692 return bf_get(lpfc_mbox_hdr_opcode
, &cfg_shdr
->request
);
1695 /* For non-embedded mbox command, get opcode from first dma page */
1696 if (unlikely(!mbox
->sge_array
))
1698 cfg_shdr
= (union lpfc_sli4_cfg_shdr
*)mbox
->sge_array
->addr
[0];
1699 return bf_get(lpfc_mbox_hdr_opcode
, &cfg_shdr
->request
);
1703 * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
1704 * @mboxq: pointer to lpfc mbox command.
1706 * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
1710 lpfc_request_features(struct lpfc_hba
*phba
, struct lpfcMboxq
*mboxq
)
1712 /* Set up SLI4 mailbox command header fields */
1713 memset(mboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1714 bf_set(lpfc_mqe_command
, &mboxq
->u
.mqe
, MBX_SLI4_REQ_FTRS
);
1716 /* Set up host requested features. */
1717 bf_set(lpfc_mbx_rq_ftr_rq_fcpi
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
1719 if (phba
->cfg_enable_fip
)
1720 bf_set(lpfc_mbx_rq_ftr_rq_ifip
, &mboxq
->u
.mqe
.un
.req_ftrs
, 0);
1722 bf_set(lpfc_mbx_rq_ftr_rq_ifip
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
1724 /* Enable DIF (block guard) only if configured to do so. */
1725 if (phba
->cfg_enable_bg
)
1726 bf_set(lpfc_mbx_rq_ftr_rq_dif
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
1728 /* Enable NPIV only if configured to do so. */
1729 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
)
1730 bf_set(lpfc_mbx_rq_ftr_rq_npiv
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
1736 * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
1737 * @mbox: pointer to lpfc mbox command to initialize.
1738 * @vport: Vport associated with the VF.
1740 * This routine initializes @mbox to all zeros and then fills in the mailbox
1741 * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
1742 * in the context of an FCF. The driver issues this command to setup a VFI
1743 * before issuing a FLOGI to login to the VSAN. The driver should also issue a
1744 * REG_VFI after a successful VSAN login.
1747 lpfc_init_vfi(struct lpfcMboxq
*mbox
, struct lpfc_vport
*vport
)
1749 struct lpfc_mbx_init_vfi
*init_vfi
;
1751 memset(mbox
, 0, sizeof(*mbox
));
1752 init_vfi
= &mbox
->u
.mqe
.un
.init_vfi
;
1753 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_INIT_VFI
);
1754 bf_set(lpfc_init_vfi_vr
, init_vfi
, 1);
1755 bf_set(lpfc_init_vfi_vt
, init_vfi
, 1);
1756 bf_set(lpfc_init_vfi_vfi
, init_vfi
, vport
->vfi
+ vport
->phba
->vfi_base
);
1757 bf_set(lpfc_init_vfi_fcfi
, init_vfi
, vport
->phba
->fcf
.fcfi
);
1761 * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
1762 * @mbox: pointer to lpfc mbox command to initialize.
1763 * @vport: vport associated with the VF.
1764 * @phys: BDE DMA bus address used to send the service parameters to the HBA.
1766 * This routine initializes @mbox to all zeros and then fills in the mailbox
1767 * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
1768 * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
1769 * fabrics identified by VFI in the context of an FCF.
1772 lpfc_reg_vfi(struct lpfcMboxq
*mbox
, struct lpfc_vport
*vport
, dma_addr_t phys
)
1774 struct lpfc_mbx_reg_vfi
*reg_vfi
;
1776 memset(mbox
, 0, sizeof(*mbox
));
1777 reg_vfi
= &mbox
->u
.mqe
.un
.reg_vfi
;
1778 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_REG_VFI
);
1779 bf_set(lpfc_reg_vfi_vp
, reg_vfi
, 1);
1780 bf_set(lpfc_reg_vfi_vfi
, reg_vfi
, vport
->vfi
+ vport
->phba
->vfi_base
);
1781 bf_set(lpfc_reg_vfi_fcfi
, reg_vfi
, vport
->phba
->fcf
.fcfi
);
1782 bf_set(lpfc_reg_vfi_vpi
, reg_vfi
, vport
->vpi
+ vport
->phba
->vpi_base
);
1783 reg_vfi
->bde
.addrHigh
= putPaddrHigh(phys
);
1784 reg_vfi
->bde
.addrLow
= putPaddrLow(phys
);
1785 reg_vfi
->bde
.tus
.f
.bdeSize
= sizeof(vport
->fc_sparam
);
1786 reg_vfi
->bde
.tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1787 bf_set(lpfc_reg_vfi_nport_id
, reg_vfi
, vport
->fc_myDID
);
1791 * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
1792 * @mbox: pointer to lpfc mbox command to initialize.
1793 * @vpi: VPI to be initialized.
1795 * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
1796 * command to activate a virtual N_Port. The HBA assigns a MAC address to use
1797 * with the virtual N Port. The SLI Host issues this command before issuing a
1798 * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
1799 * successful virtual NPort login.
1802 lpfc_init_vpi(struct lpfcMboxq
*mbox
, uint16_t vpi
)
1804 memset(mbox
, 0, sizeof(*mbox
));
1805 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_INIT_VPI
);
1806 bf_set(lpfc_init_vpi_vpi
, &mbox
->u
.mqe
.un
.init_vpi
, vpi
);
1810 * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
1811 * @mbox: pointer to lpfc mbox command to initialize.
1812 * @vfi: VFI to be unregistered.
1814 * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
1815 * (logical NPort) into the inactive state. The SLI Host must have logged out
1816 * and unregistered all remote N_Ports to abort any activity on the virtual
1817 * fabric. The SLI Port posts the mailbox response after marking the virtual
1821 lpfc_unreg_vfi(struct lpfcMboxq
*mbox
, uint16_t vfi
)
1823 memset(mbox
, 0, sizeof(*mbox
));
1824 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_UNREG_VFI
);
1825 bf_set(lpfc_unreg_vfi_vfi
, &mbox
->u
.mqe
.un
.unreg_vfi
, vfi
);
1829 * lpfc_dump_fcoe_param - Dump config region 23 to get FCoe parameters.
1830 * @phba: pointer to the hba structure containing.
1831 * @mbox: pointer to lpfc mbox command to initialize.
1833 * This function create a SLI4 dump mailbox command to dump FCoE
1834 * parameters stored in region 23.
1837 lpfc_dump_fcoe_param(struct lpfc_hba
*phba
,
1838 struct lpfcMboxq
*mbox
)
1840 struct lpfc_dmabuf
*mp
= NULL
;
1843 memset(mbox
, 0, sizeof(*mbox
));
1846 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1848 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
1850 if (!mp
|| !mp
->virt
) {
1852 /* dump_fcoe_param failed to allocate memory */
1853 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
1854 "2569 lpfc_dump_fcoe_param: memory"
1855 " allocation failed \n");
1859 memset(mp
->virt
, 0, LPFC_BPL_SIZE
);
1860 INIT_LIST_HEAD(&mp
->list
);
1862 /* save address for completion */
1863 mbox
->context1
= (uint8_t *) mp
;
1865 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
1866 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
1867 mb
->un
.varDmp
.region_id
= DMP_REGION_FCOEPARAM
;
1868 mb
->un
.varDmp
.sli4_length
= DMP_FCOEPARAM_RGN_SIZE
;
1869 mb
->un
.varWords
[3] = putPaddrLow(mp
->phys
);
1870 mb
->un
.varWords
[4] = putPaddrHigh(mp
->phys
);
1875 * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
1876 * @phba: pointer to the hba structure containing the FCF index and RQ ID.
1877 * @mbox: pointer to lpfc mbox command to initialize.
1879 * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
1880 * SLI Host uses the command to activate an FCF after it has acquired FCF
1881 * information via a READ_FCF mailbox command. This mailbox command also is used
1882 * to indicate where received unsolicited frames from this FCF will be sent. By
1883 * default this routine will set up the FCF to forward all unsolicited frames
1884 * the the RQ ID passed in the @phba. This can be overridden by the caller for
1885 * more complicated setups.
1888 lpfc_reg_fcfi(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
1890 struct lpfc_mbx_reg_fcfi
*reg_fcfi
;
1892 memset(mbox
, 0, sizeof(*mbox
));
1893 reg_fcfi
= &mbox
->u
.mqe
.un
.reg_fcfi
;
1894 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_REG_FCFI
);
1895 bf_set(lpfc_reg_fcfi_rq_id0
, reg_fcfi
, phba
->sli4_hba
.hdr_rq
->queue_id
);
1896 bf_set(lpfc_reg_fcfi_rq_id1
, reg_fcfi
, REG_FCF_INVALID_QID
);
1897 bf_set(lpfc_reg_fcfi_rq_id2
, reg_fcfi
, REG_FCF_INVALID_QID
);
1898 bf_set(lpfc_reg_fcfi_rq_id3
, reg_fcfi
, REG_FCF_INVALID_QID
);
1899 bf_set(lpfc_reg_fcfi_info_index
, reg_fcfi
, phba
->fcf
.fcf_indx
);
1900 /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */
1901 bf_set(lpfc_reg_fcfi_mam
, reg_fcfi
,
1902 (~phba
->fcf
.addr_mode
) & 0x3);
1903 if (phba
->fcf
.fcf_flag
& FCF_VALID_VLAN
) {
1904 bf_set(lpfc_reg_fcfi_vv
, reg_fcfi
, 1);
1905 bf_set(lpfc_reg_fcfi_vlan_tag
, reg_fcfi
, phba
->fcf
.vlan_id
);
1910 * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
1911 * @mbox: pointer to lpfc mbox command to initialize.
1912 * @fcfi: FCFI to be unregistered.
1914 * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
1915 * The SLI Host uses the command to inactivate an FCFI.
1918 lpfc_unreg_fcfi(struct lpfcMboxq
*mbox
, uint16_t fcfi
)
1920 memset(mbox
, 0, sizeof(*mbox
));
1921 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_UNREG_FCFI
);
1922 bf_set(lpfc_unreg_fcfi
, &mbox
->u
.mqe
.un
.unreg_fcfi
, fcfi
);
1926 * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
1927 * @mbox: pointer to lpfc mbox command to initialize.
1928 * @ndlp: The nodelist structure that describes the RPI to resume.
1930 * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
1934 lpfc_resume_rpi(struct lpfcMboxq
*mbox
, struct lpfc_nodelist
*ndlp
)
1936 struct lpfc_mbx_resume_rpi
*resume_rpi
;
1938 memset(mbox
, 0, sizeof(*mbox
));
1939 resume_rpi
= &mbox
->u
.mqe
.un
.resume_rpi
;
1940 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_RESUME_RPI
);
1941 bf_set(lpfc_resume_rpi_rpi
, resume_rpi
, ndlp
->nlp_rpi
);
1942 bf_set(lpfc_resume_rpi_vpi
, resume_rpi
,
1943 ndlp
->vport
->vpi
+ ndlp
->vport
->phba
->vpi_base
);
1944 bf_set(lpfc_resume_rpi_vfi
, resume_rpi
,
1945 ndlp
->vport
->vfi
+ ndlp
->vport
->phba
->vfi_base
);