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/slab.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_transport_fc.h>
29 #include <scsi/scsi.h>
30 #include <scsi/fc/fc_fs.h>
35 #include "lpfc_sli4.h"
37 #include "lpfc_disc.h"
38 #include "lpfc_scsi.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_compat.h"
45 * lpfc_dump_static_vport - Dump HBA's static vport information.
46 * @phba: pointer to lpfc hba data structure.
47 * @pmb: pointer to the driver internal queue element for mailbox command.
48 * @offset: offset for dumping vport info.
50 * The dump mailbox command provides a method for the device driver to obtain
51 * various types of information from the HBA device.
53 * This routine prepares the mailbox command for dumping list of static
54 * vports to be created.
57 lpfc_dump_static_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
,
61 struct lpfc_dmabuf
*mp
;
65 /* Setup to dump vport info region */
66 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
67 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
68 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
69 mb
->un
.varDmp
.entry_index
= offset
;
70 mb
->un
.varDmp
.region_id
= DMP_REGION_VPORT
;
71 mb
->mbxOwner
= OWN_HOST
;
73 /* For SLI3 HBAs data is embedded in mailbox */
74 if (phba
->sli_rev
!= LPFC_SLI_REV4
) {
76 mb
->un
.varDmp
.word_cnt
= DMP_RSP_SIZE
/sizeof(uint32_t);
80 /* For SLI4 HBAs driver need to allocate memory */
81 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
83 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
85 if (!mp
|| !mp
->virt
) {
87 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
88 "2605 lpfc_dump_static_vport: memory"
89 " allocation failed\n");
92 memset(mp
->virt
, 0, LPFC_BPL_SIZE
);
93 INIT_LIST_HEAD(&mp
->list
);
94 /* save address for completion */
95 pmb
->context2
= (uint8_t *) mp
;
96 mb
->un
.varWords
[3] = putPaddrLow(mp
->phys
);
97 mb
->un
.varWords
[4] = putPaddrHigh(mp
->phys
);
98 mb
->un
.varDmp
.sli4_length
= sizeof(struct static_vport_info
);
104 * lpfc_down_link - Bring down HBAs link.
105 * @phba: pointer to lpfc hba data structure.
106 * @pmb: pointer to the driver internal queue element for mailbox command.
108 * This routine prepares a mailbox command to bring down HBA link.
111 lpfc_down_link(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
114 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
116 mb
->mbxCommand
= MBX_DOWN_LINK
;
117 mb
->mbxOwner
= OWN_HOST
;
121 * lpfc_dump_mem - Prepare a mailbox command for reading a region.
122 * @phba: pointer to lpfc hba data structure.
123 * @pmb: pointer to the driver internal queue element for mailbox command.
124 * @offset: offset into the region.
125 * @region_id: config region id.
127 * The dump mailbox command provides a method for the device driver to obtain
128 * various types of information from the HBA device.
130 * This routine prepares the mailbox command for dumping HBA's config region.
133 lpfc_dump_mem(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
, uint16_t offset
,
142 /* Setup to dump VPD region */
143 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
144 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
145 mb
->un
.varDmp
.cv
= 1;
146 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
147 mb
->un
.varDmp
.entry_index
= offset
;
148 mb
->un
.varDmp
.region_id
= region_id
;
149 mb
->un
.varDmp
.word_cnt
= (DMP_RSP_SIZE
/ sizeof (uint32_t));
150 mb
->un
.varDmp
.co
= 0;
151 mb
->un
.varDmp
.resp_offset
= 0;
153 mb
->mbxOwner
= OWN_HOST
;
158 * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
159 * @phba: pointer to lpfc hba data structure.
160 * @pmb: pointer to the driver internal queue element for mailbox command.
162 * This function create a dump memory mailbox command to dump wake up
166 lpfc_dump_wakeup_param(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
172 /* Save context so that we can restore after memset */
175 /* Setup to dump VPD region */
176 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
177 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
178 mb
->mbxOwner
= OWN_HOST
;
179 mb
->un
.varDmp
.cv
= 1;
180 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
181 mb
->un
.varDmp
.entry_index
= 0;
182 mb
->un
.varDmp
.region_id
= WAKE_UP_PARMS_REGION_ID
;
183 mb
->un
.varDmp
.word_cnt
= WAKE_UP_PARMS_WORD_SIZE
;
184 mb
->un
.varDmp
.co
= 0;
185 mb
->un
.varDmp
.resp_offset
= 0;
191 * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
192 * @phba: pointer to lpfc hba data structure.
193 * @pmb: pointer to the driver internal queue element for mailbox command.
195 * The read NVRAM mailbox command returns the HBA's non-volatile parameters
196 * that are used as defaults when the Fibre Channel link is brought on-line.
198 * This routine prepares the mailbox command for reading information stored
199 * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
202 lpfc_read_nv(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
207 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
208 mb
->mbxCommand
= MBX_READ_NV
;
209 mb
->mbxOwner
= OWN_HOST
;
214 * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
215 * @phba: pointer to lpfc hba data structure.
216 * @pmb: pointer to the driver internal queue element for mailbox command.
217 * @ring: ring number for the asynchronous event to be configured.
219 * The asynchronous event enable mailbox command is used to enable the
220 * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
221 * specifies the default ring to which events are posted.
223 * This routine prepares the mailbox command for enabling HBA asynchronous
224 * event support on a IOCB ring.
227 lpfc_config_async(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
,
233 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
234 mb
->mbxCommand
= MBX_ASYNCEVT_ENABLE
;
235 mb
->un
.varCfgAsyncEvent
.ring
= ring
;
236 mb
->mbxOwner
= OWN_HOST
;
241 * lpfc_heart_beat - Prepare a mailbox command for heart beat
242 * @phba: pointer to lpfc hba data structure.
243 * @pmb: pointer to the driver internal queue element for mailbox command.
245 * The heart beat mailbox command is used to detect an unresponsive HBA, which
246 * is defined as any device where no error attention is sent and both mailbox
247 * and rings are not processed.
249 * This routine prepares the mailbox command for issuing a heart beat in the
250 * form of mailbox command to the HBA. The timely completion of the heart
251 * beat mailbox command indicates the health of the HBA.
254 lpfc_heart_beat(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
259 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
260 mb
->mbxCommand
= MBX_HEARTBEAT
;
261 mb
->mbxOwner
= OWN_HOST
;
266 * lpfc_read_la - Prepare a mailbox command for reading HBA link attention
267 * @phba: pointer to lpfc hba data structure.
268 * @pmb: pointer to the driver internal queue element for mailbox command.
269 * @mp: DMA buffer memory for reading the link attention information into.
271 * The read link attention mailbox command is issued to read the Link Event
272 * Attention information indicated by the HBA port when the Link Event bit
273 * of the Host Attention (HSTATT) register is set to 1. A Link Event
274 * Attention occurs based on an exception detected at the Fibre Channel link
277 * This routine prepares the mailbox command for reading HBA link attention
278 * information. A DMA memory has been set aside and address passed to the
279 * HBA through @mp for the HBA to DMA link attention information into the
280 * memory as part of the execution of the mailbox command.
283 * 0 - Success (currently always return 0)
286 lpfc_read_la(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
, struct lpfc_dmabuf
*mp
)
289 struct lpfc_sli
*psli
;
293 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
295 INIT_LIST_HEAD(&mp
->list
);
296 mb
->mbxCommand
= MBX_READ_LA64
;
297 mb
->un
.varReadLA
.un
.lilpBde64
.tus
.f
.bdeSize
= 128;
298 mb
->un
.varReadLA
.un
.lilpBde64
.addrHigh
= putPaddrHigh(mp
->phys
);
299 mb
->un
.varReadLA
.un
.lilpBde64
.addrLow
= putPaddrLow(mp
->phys
);
301 /* Save address for later completion and set the owner to host so that
302 * the FW knows this mailbox is available for processing.
304 pmb
->context1
= (uint8_t *) mp
;
305 mb
->mbxOwner
= OWN_HOST
;
310 * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
311 * @phba: pointer to lpfc hba data structure.
312 * @pmb: pointer to the driver internal queue element for mailbox command.
314 * The clear link attention mailbox command is issued to clear the link event
315 * attention condition indicated by the Link Event bit of the Host Attention
316 * (HSTATT) register. The link event attention condition is cleared only if
317 * the event tag specified matches that of the current link event counter.
318 * The current event tag is read using the read link attention event mailbox
321 * This routine prepares the mailbox command for clearing HBA link attention
325 lpfc_clear_la(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
330 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
332 mb
->un
.varClearLA
.eventTag
= phba
->fc_eventTag
;
333 mb
->mbxCommand
= MBX_CLEAR_LA
;
334 mb
->mbxOwner
= OWN_HOST
;
339 * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
340 * @phba: pointer to lpfc hba data structure.
341 * @pmb: pointer to the driver internal queue element for mailbox command.
343 * The configure link mailbox command is used before the initialize link
344 * mailbox command to override default value and to configure link-oriented
345 * parameters such as DID address and various timers. Typically, this
346 * command would be used after an F_Port login to set the returned DID address
347 * and the fabric timeout values. This command is not valid before a configure
348 * port command has configured the HBA port.
350 * This routine prepares the mailbox command for configuring link on a HBA.
353 lpfc_config_link(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
355 struct lpfc_vport
*vport
= phba
->pport
;
356 MAILBOX_t
*mb
= &pmb
->u
.mb
;
357 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
360 * SLI-2, Coalescing Response Feature.
362 if (phba
->cfg_cr_delay
) {
363 mb
->un
.varCfgLnk
.cr
= 1;
364 mb
->un
.varCfgLnk
.ci
= 1;
365 mb
->un
.varCfgLnk
.cr_delay
= phba
->cfg_cr_delay
;
366 mb
->un
.varCfgLnk
.cr_count
= phba
->cfg_cr_count
;
369 mb
->un
.varCfgLnk
.myId
= vport
->fc_myDID
;
370 mb
->un
.varCfgLnk
.edtov
= phba
->fc_edtov
;
371 mb
->un
.varCfgLnk
.arbtov
= phba
->fc_arbtov
;
372 mb
->un
.varCfgLnk
.ratov
= phba
->fc_ratov
;
373 mb
->un
.varCfgLnk
.rttov
= phba
->fc_rttov
;
374 mb
->un
.varCfgLnk
.altov
= phba
->fc_altov
;
375 mb
->un
.varCfgLnk
.crtov
= phba
->fc_crtov
;
376 mb
->un
.varCfgLnk
.citov
= phba
->fc_citov
;
379 mb
->un
.varCfgLnk
.ack0_enable
= 1;
381 mb
->mbxCommand
= MBX_CONFIG_LINK
;
382 mb
->mbxOwner
= OWN_HOST
;
387 * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
388 * @phba: pointer to lpfc hba data structure.
389 * @pmb: pointer to the driver internal queue element for mailbox command.
391 * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
392 * MSI-X multi-message interrupt vector association to interrupt attention
400 lpfc_config_msi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
402 MAILBOX_t
*mb
= &pmb
->u
.mb
;
403 uint32_t attentionConditions
[2];
406 if (phba
->cfg_use_msi
!= 2) {
407 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
408 "0475 Not configured for supporting MSI-X "
409 "cfg_use_msi: 0x%x\n", phba
->cfg_use_msi
);
413 if (phba
->sli_rev
< 3) {
414 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
415 "0476 HBA not supporting SLI-3 or later "
416 "SLI Revision: 0x%x\n", phba
->sli_rev
);
420 /* Clear mailbox command fields */
421 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
424 * SLI-3, Message Signaled Interrupt Fearure.
427 /* Multi-message attention configuration */
428 attentionConditions
[0] = (HA_R0ATT
| HA_R1ATT
| HA_R2ATT
| HA_ERATT
|
430 attentionConditions
[1] = 0;
432 mb
->un
.varCfgMSI
.attentionConditions
[0] = attentionConditions
[0];
433 mb
->un
.varCfgMSI
.attentionConditions
[1] = attentionConditions
[1];
436 * Set up message number to HA bit association
438 #ifdef __BIG_ENDIAN_BITFIELD
440 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R0_POS
] = 1;
441 /* RA1 (Other Protocol Extra Ring) */
442 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R1_POS
] = 1;
443 #else /* __LITTLE_ENDIAN_BITFIELD */
445 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R0_POS
^3] = 1;
446 /* RA1 (Other Protocol Extra Ring) */
447 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R1_POS
^3] = 1;
449 /* Multi-message interrupt autoclear configuration*/
450 mb
->un
.varCfgMSI
.autoClearHA
[0] = attentionConditions
[0];
451 mb
->un
.varCfgMSI
.autoClearHA
[1] = attentionConditions
[1];
453 /* For now, HBA autoclear does not work reliably, disable it */
454 mb
->un
.varCfgMSI
.autoClearHA
[0] = 0;
455 mb
->un
.varCfgMSI
.autoClearHA
[1] = 0;
457 /* Set command and owner bit */
458 mb
->mbxCommand
= MBX_CONFIG_MSI
;
459 mb
->mbxOwner
= OWN_HOST
;
465 * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
466 * @phba: pointer to lpfc hba data structure.
467 * @pmb: pointer to the driver internal queue element for mailbox command.
468 * @topology: the link topology for the link to be initialized to.
469 * @linkspeed: the link speed for the link to be initialized to.
471 * The initialize link mailbox command is used to initialize the Fibre
472 * Channel link. This command must follow a configure port command that
473 * establishes the mode of operation.
475 * This routine prepares the mailbox command for initializing link on a HBA
476 * with the specified link topology and speed.
479 lpfc_init_link(struct lpfc_hba
* phba
,
480 LPFC_MBOXQ_t
* pmb
, uint32_t topology
, uint32_t linkspeed
)
483 struct lpfc_sli
*psli
;
487 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
491 case FLAGS_TOPOLOGY_MODE_LOOP_PT
:
492 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_LOOP
;
493 mb
->un
.varInitLnk
.link_flags
|= FLAGS_TOPOLOGY_FAILOVER
;
495 case FLAGS_TOPOLOGY_MODE_PT_PT
:
496 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_PT_PT
;
498 case FLAGS_TOPOLOGY_MODE_LOOP
:
499 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_LOOP
;
501 case FLAGS_TOPOLOGY_MODE_PT_LOOP
:
502 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_PT_PT
;
503 mb
->un
.varInitLnk
.link_flags
|= FLAGS_TOPOLOGY_FAILOVER
;
506 mb
->un
.varInitLnk
.link_flags
= FLAGS_LOCAL_LB
;
510 /* Enable asynchronous ABTS responses from firmware */
511 mb
->un
.varInitLnk
.link_flags
|= FLAGS_IMED_ABORT
;
514 * Setting up the link speed
517 if (vpd
->rev
.feaLevelHigh
>= 0x02){
523 mb
->un
.varInitLnk
.link_flags
|=
525 mb
->un
.varInitLnk
.link_speed
= linkspeed
;
527 case LINK_SPEED_AUTO
:
529 mb
->un
.varInitLnk
.link_speed
=
536 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_AUTO
;
538 mb
->mbxCommand
= (volatile uint8_t)MBX_INIT_LINK
;
539 mb
->mbxOwner
= OWN_HOST
;
540 mb
->un
.varInitLnk
.fabric_AL_PA
= phba
->fc_pref_ALPA
;
545 * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
546 * @phba: pointer to lpfc hba data structure.
547 * @pmb: pointer to the driver internal queue element for mailbox command.
548 * @vpi: virtual N_Port identifier.
550 * The read service parameter mailbox command is used to read the HBA port
551 * service parameters. The service parameters are read into the buffer
552 * specified directly by a BDE in the mailbox command. These service
553 * parameters may then be used to build the payload of an N_Port/F_POrt
554 * login request and reply (LOGI/ACC).
556 * This routine prepares the mailbox command for reading HBA port service
557 * parameters. The DMA memory is allocated in this function and the addresses
558 * are populated into the mailbox command for the HBA to DMA the service
563 * 1 - DMA memory allocation failed
566 lpfc_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
, int vpi
)
568 struct lpfc_dmabuf
*mp
;
570 struct lpfc_sli
*psli
;
574 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
576 mb
->mbxOwner
= OWN_HOST
;
578 /* Get a buffer to hold the HBAs Service Parameters */
580 mp
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
582 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
583 if (!mp
|| !mp
->virt
) {
585 mb
->mbxCommand
= MBX_READ_SPARM64
;
586 /* READ_SPARAM: no buffers */
587 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
588 "0301 READ_SPARAM: no buffers\n");
591 INIT_LIST_HEAD(&mp
->list
);
592 mb
->mbxCommand
= MBX_READ_SPARM64
;
593 mb
->un
.varRdSparm
.un
.sp64
.tus
.f
.bdeSize
= sizeof (struct serv_parm
);
594 mb
->un
.varRdSparm
.un
.sp64
.addrHigh
= putPaddrHigh(mp
->phys
);
595 mb
->un
.varRdSparm
.un
.sp64
.addrLow
= putPaddrLow(mp
->phys
);
596 mb
->un
.varRdSparm
.vpi
= vpi
+ phba
->vpi_base
;
598 /* save address for completion */
605 * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
606 * @phba: pointer to lpfc hba data structure.
607 * @vpi: virtual N_Port identifier.
608 * @did: remote port identifier.
609 * @pmb: pointer to the driver internal queue element for mailbox command.
611 * The unregister DID mailbox command is used to unregister an N_Port/F_Port
612 * login for an unknown RPI by specifying the DID of a remote port. This
613 * command frees an RPI context in the HBA port. This has the effect of
614 * performing an implicit N_Port/F_Port logout.
616 * This routine prepares the mailbox command for unregistering a remote
617 * N_Port/F_Port (DID) login.
620 lpfc_unreg_did(struct lpfc_hba
* phba
, uint16_t vpi
, uint32_t did
,
626 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
628 mb
->un
.varUnregDID
.did
= did
;
630 vpi
+= phba
->vpi_base
;
631 mb
->un
.varUnregDID
.vpi
= vpi
;
633 mb
->mbxCommand
= MBX_UNREG_D_ID
;
634 mb
->mbxOwner
= OWN_HOST
;
639 * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
640 * @phba: pointer to lpfc hba data structure.
641 * @pmb: pointer to the driver internal queue element for mailbox command.
643 * The read configuration mailbox command is used to read the HBA port
644 * configuration parameters. This mailbox command provides a method for
645 * seeing any parameters that may have changed via various configuration
648 * This routine prepares the mailbox command for reading out HBA configuration
652 lpfc_read_config(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
657 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
659 mb
->mbxCommand
= MBX_READ_CONFIG
;
660 mb
->mbxOwner
= OWN_HOST
;
665 * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
666 * @phba: pointer to lpfc hba data structure.
667 * @pmb: pointer to the driver internal queue element for mailbox command.
669 * The read link status mailbox command is used to read the link status from
670 * the HBA. Link status includes all link-related error counters. These
671 * counters are maintained by the HBA and originated in the link hardware
672 * unit. Note that all of these counters wrap.
674 * This routine prepares the mailbox command for reading out HBA link status.
677 lpfc_read_lnk_stat(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
682 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
684 mb
->mbxCommand
= MBX_READ_LNK_STAT
;
685 mb
->mbxOwner
= OWN_HOST
;
690 * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
691 * @phba: pointer to lpfc hba data structure.
692 * @vpi: virtual N_Port identifier.
693 * @did: remote port identifier.
694 * @param: pointer to memory holding the server parameters.
695 * @pmb: pointer to the driver internal queue element for mailbox command.
696 * @flag: action flag to be passed back for the complete function.
698 * The registration login mailbox command is used to register an N_Port or
699 * F_Port login. This registration allows the HBA to cache the remote N_Port
700 * service parameters internally and thereby make the appropriate FC-2
701 * decisions. The remote port service parameters are handed off by the driver
702 * to the HBA using a descriptor entry that directly identifies a buffer in
703 * host memory. In exchange, the HBA returns an RPI identifier.
705 * This routine prepares the mailbox command for registering remote port login.
706 * The function allocates DMA buffer for passing the service parameters to the
707 * HBA with the mailbox command.
711 * 1 - DMA memory allocation failed
714 lpfc_reg_rpi(struct lpfc_hba
*phba
, uint16_t vpi
, uint32_t did
,
715 uint8_t *param
, LPFC_MBOXQ_t
*pmb
, uint32_t flag
)
717 MAILBOX_t
*mb
= &pmb
->u
.mb
;
719 struct lpfc_dmabuf
*mp
;
721 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
723 mb
->un
.varRegLogin
.rpi
= 0;
724 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
725 mb
->un
.varRegLogin
.rpi
= lpfc_sli4_alloc_rpi(phba
);
726 if (mb
->un
.varRegLogin
.rpi
== LPFC_RPI_ALLOC_ERROR
)
730 mb
->un
.varRegLogin
.vpi
= vpi
+ phba
->vpi_base
;
731 mb
->un
.varRegLogin
.did
= did
;
732 mb
->un
.varWords
[30] = flag
; /* Set flag to issue action on cmpl */
734 mb
->mbxOwner
= OWN_HOST
;
736 /* Get a buffer to hold NPorts Service Parameters */
737 mp
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
739 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
740 if (!mp
|| !mp
->virt
) {
742 mb
->mbxCommand
= MBX_REG_LOGIN64
;
743 /* REG_LOGIN: no buffers */
744 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
745 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
746 "flag x%x\n", vpi
, did
, flag
);
749 INIT_LIST_HEAD(&mp
->list
);
752 /* Copy param's into a new buffer */
753 memcpy(sparam
, param
, sizeof (struct serv_parm
));
755 /* save address for completion */
756 pmb
->context1
= (uint8_t *) mp
;
758 mb
->mbxCommand
= MBX_REG_LOGIN64
;
759 mb
->un
.varRegLogin
.un
.sp64
.tus
.f
.bdeSize
= sizeof (struct serv_parm
);
760 mb
->un
.varRegLogin
.un
.sp64
.addrHigh
= putPaddrHigh(mp
->phys
);
761 mb
->un
.varRegLogin
.un
.sp64
.addrLow
= putPaddrLow(mp
->phys
);
767 * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
768 * @phba: pointer to lpfc hba data structure.
769 * @vpi: virtual N_Port identifier.
770 * @rpi: remote port identifier
771 * @pmb: pointer to the driver internal queue element for mailbox command.
773 * The unregistration login mailbox command is used to unregister an N_Port
774 * or F_Port login. This command frees an RPI context in the HBA. It has the
775 * effect of performing an implicit N_Port/F_Port logout.
777 * This routine prepares the mailbox command for unregistering remote port
781 lpfc_unreg_login(struct lpfc_hba
*phba
, uint16_t vpi
, uint32_t rpi
,
787 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
789 mb
->un
.varUnregLogin
.rpi
= (uint16_t) rpi
;
790 mb
->un
.varUnregLogin
.rsvd1
= 0;
791 mb
->un
.varUnregLogin
.vpi
= vpi
+ phba
->vpi_base
;
793 mb
->mbxCommand
= MBX_UNREG_LOGIN
;
794 mb
->mbxOwner
= OWN_HOST
;
800 * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
801 * @phba: pointer to lpfc hba data structure.
802 * @vpi: virtual N_Port identifier.
803 * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
804 * @pmb: pointer to the driver internal queue element for mailbox command.
806 * The registration vport identifier mailbox command is used to activate a
807 * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
808 * N_Port_ID against the information in the selected virtual N_Port context
809 * block and marks it active to allow normal processing of IOCB commands and
810 * received unsolicited exchanges.
812 * This routine prepares the mailbox command for registering a virtual N_Port.
815 lpfc_reg_vpi(struct lpfc_vport
*vport
, LPFC_MBOXQ_t
*pmb
)
817 MAILBOX_t
*mb
= &pmb
->u
.mb
;
818 struct lpfc_hba
*phba
= vport
->phba
;
820 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
822 * Set the re-reg VPI bit for f/w to update the MAC address.
824 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
825 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
))
826 mb
->un
.varRegVpi
.upd
= 1;
827 mb
->un
.varRegVpi
.vpi
= vport
->vpi
+ vport
->phba
->vpi_base
;
828 mb
->un
.varRegVpi
.sid
= vport
->fc_myDID
;
829 mb
->un
.varRegVpi
.vfi
= vport
->vfi
+ vport
->phba
->vfi_base
;
830 memcpy(mb
->un
.varRegVpi
.wwn
, &vport
->fc_portname
,
831 sizeof(struct lpfc_name
));
832 mb
->un
.varRegVpi
.wwn
[0] = cpu_to_le32(mb
->un
.varRegVpi
.wwn
[0]);
833 mb
->un
.varRegVpi
.wwn
[1] = cpu_to_le32(mb
->un
.varRegVpi
.wwn
[1]);
835 mb
->mbxCommand
= MBX_REG_VPI
;
836 mb
->mbxOwner
= OWN_HOST
;
842 * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
843 * @phba: pointer to lpfc hba data structure.
844 * @vpi: virtual N_Port identifier.
845 * @pmb: pointer to the driver internal queue element for mailbox command.
847 * The unregistration vport identifier mailbox command is used to inactivate
848 * a virtual N_Port. The driver must have logged out and unregistered all
849 * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
850 * unregisters any default RPIs associated with the specified vpi, aborting
851 * any active exchanges. The HBA will post the mailbox response after making
852 * the virtual N_Port inactive.
854 * This routine prepares the mailbox command for unregistering a virtual
858 lpfc_unreg_vpi(struct lpfc_hba
*phba
, uint16_t vpi
, LPFC_MBOXQ_t
*pmb
)
860 MAILBOX_t
*mb
= &pmb
->u
.mb
;
861 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
863 if (phba
->sli_rev
< LPFC_SLI_REV4
)
864 mb
->un
.varUnregVpi
.vpi
= vpi
+ phba
->vpi_base
;
866 mb
->un
.varUnregVpi
.sli4_vpi
= vpi
+ phba
->vpi_base
;
868 mb
->mbxCommand
= MBX_UNREG_VPI
;
869 mb
->mbxOwner
= OWN_HOST
;
875 * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
876 * @phba: pointer to lpfc hba data structure.
878 * This routine sets up and initializes the IOCB rings in the Port Control
882 lpfc_config_pcb_setup(struct lpfc_hba
* phba
)
884 struct lpfc_sli
*psli
= &phba
->sli
;
885 struct lpfc_sli_ring
*pring
;
886 PCB_t
*pcbp
= phba
->pcb
;
887 dma_addr_t pdma_addr
;
889 uint32_t iocbCnt
= 0;
892 pcbp
->maxRing
= (psli
->num_rings
- 1);
894 for (i
= 0; i
< psli
->num_rings
; i
++) {
895 pring
= &psli
->ring
[i
];
897 pring
->sizeCiocb
= phba
->sli_rev
== 3 ? SLI3_IOCB_CMD_SIZE
:
899 pring
->sizeRiocb
= phba
->sli_rev
== 3 ? SLI3_IOCB_RSP_SIZE
:
901 /* A ring MUST have both cmd and rsp entries defined to be
903 if ((pring
->numCiocb
== 0) || (pring
->numRiocb
== 0)) {
904 pcbp
->rdsc
[i
].cmdEntries
= 0;
905 pcbp
->rdsc
[i
].rspEntries
= 0;
906 pcbp
->rdsc
[i
].cmdAddrHigh
= 0;
907 pcbp
->rdsc
[i
].rspAddrHigh
= 0;
908 pcbp
->rdsc
[i
].cmdAddrLow
= 0;
909 pcbp
->rdsc
[i
].rspAddrLow
= 0;
910 pring
->cmdringaddr
= NULL
;
911 pring
->rspringaddr
= NULL
;
914 /* Command ring setup for ring */
915 pring
->cmdringaddr
= (void *)&phba
->IOCBs
[iocbCnt
];
916 pcbp
->rdsc
[i
].cmdEntries
= pring
->numCiocb
;
918 offset
= (uint8_t *) &phba
->IOCBs
[iocbCnt
] -
919 (uint8_t *) phba
->slim2p
.virt
;
920 pdma_addr
= phba
->slim2p
.phys
+ offset
;
921 pcbp
->rdsc
[i
].cmdAddrHigh
= putPaddrHigh(pdma_addr
);
922 pcbp
->rdsc
[i
].cmdAddrLow
= putPaddrLow(pdma_addr
);
923 iocbCnt
+= pring
->numCiocb
;
925 /* Response ring setup for ring */
926 pring
->rspringaddr
= (void *) &phba
->IOCBs
[iocbCnt
];
928 pcbp
->rdsc
[i
].rspEntries
= pring
->numRiocb
;
929 offset
= (uint8_t *)&phba
->IOCBs
[iocbCnt
] -
930 (uint8_t *)phba
->slim2p
.virt
;
931 pdma_addr
= phba
->slim2p
.phys
+ offset
;
932 pcbp
->rdsc
[i
].rspAddrHigh
= putPaddrHigh(pdma_addr
);
933 pcbp
->rdsc
[i
].rspAddrLow
= putPaddrLow(pdma_addr
);
934 iocbCnt
+= pring
->numRiocb
;
939 * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
940 * @phba: pointer to lpfc hba data structure.
941 * @pmb: pointer to the driver internal queue element for mailbox command.
943 * The read revision mailbox command is used to read the revision levels of
944 * the HBA components. These components include hardware units, resident
945 * firmware, and available firmware. HBAs that supports SLI-3 mode of
946 * operation provide different response information depending on the version
947 * requested by the driver.
949 * This routine prepares the mailbox command for reading HBA revision
953 lpfc_read_rev(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
955 MAILBOX_t
*mb
= &pmb
->u
.mb
;
956 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
957 mb
->un
.varRdRev
.cv
= 1;
958 mb
->un
.varRdRev
.v3req
= 1; /* Request SLI3 info */
959 mb
->mbxCommand
= MBX_READ_REV
;
960 mb
->mbxOwner
= OWN_HOST
;
965 lpfc_sli4_swap_str(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
967 MAILBOX_t
*mb
= &pmb
->u
.mb
;
968 struct lpfc_mqe
*mqe
;
970 switch (mb
->mbxCommand
) {
973 lpfc_sli_pcimem_bcopy(mqe
->un
.read_rev
.fw_name
,
974 mqe
->un
.read_rev
.fw_name
, 16);
975 lpfc_sli_pcimem_bcopy(mqe
->un
.read_rev
.ulp_fw_name
,
976 mqe
->un
.read_rev
.ulp_fw_name
, 16);
985 * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
986 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
987 * @hbq_desc: pointer to the HBQ selection profile descriptor.
989 * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
990 * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
991 * the Sequence Length Test using the fields in the Selection Profile 2
992 * extension in words 20:31.
995 lpfc_build_hbq_profile2(struct config_hbq_var
*hbqmb
,
996 struct lpfc_hbq_init
*hbq_desc
)
998 hbqmb
->profiles
.profile2
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
999 hbqmb
->profiles
.profile2
.maxlen
= hbq_desc
->maxlen
;
1000 hbqmb
->profiles
.profile2
.seqlenoff
= hbq_desc
->seqlenoff
;
1004 * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
1005 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1006 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1008 * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
1009 * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
1010 * the Sequence Length Test and Byte Field Test using the fields in the
1011 * Selection Profile 3 extension in words 20:31.
1014 lpfc_build_hbq_profile3(struct config_hbq_var
*hbqmb
,
1015 struct lpfc_hbq_init
*hbq_desc
)
1017 hbqmb
->profiles
.profile3
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
1018 hbqmb
->profiles
.profile3
.maxlen
= hbq_desc
->maxlen
;
1019 hbqmb
->profiles
.profile3
.cmdcodeoff
= hbq_desc
->cmdcodeoff
;
1020 hbqmb
->profiles
.profile3
.seqlenoff
= hbq_desc
->seqlenoff
;
1021 memcpy(&hbqmb
->profiles
.profile3
.cmdmatch
, hbq_desc
->cmdmatch
,
1022 sizeof(hbqmb
->profiles
.profile3
.cmdmatch
));
1026 * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
1027 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1028 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1030 * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
1031 * HBA tests the initial frame of an incoming sequence using the frame's
1032 * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
1033 * and Byte Field Test using the fields in the Selection Profile 5 extension
1037 lpfc_build_hbq_profile5(struct config_hbq_var
*hbqmb
,
1038 struct lpfc_hbq_init
*hbq_desc
)
1040 hbqmb
->profiles
.profile5
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
1041 hbqmb
->profiles
.profile5
.maxlen
= hbq_desc
->maxlen
;
1042 hbqmb
->profiles
.profile5
.cmdcodeoff
= hbq_desc
->cmdcodeoff
;
1043 hbqmb
->profiles
.profile5
.seqlenoff
= hbq_desc
->seqlenoff
;
1044 memcpy(&hbqmb
->profiles
.profile5
.cmdmatch
, hbq_desc
->cmdmatch
,
1045 sizeof(hbqmb
->profiles
.profile5
.cmdmatch
));
1049 * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
1050 * @phba: pointer to lpfc hba data structure.
1051 * @id: HBQ identifier.
1052 * @hbq_desc: pointer to the HBA descriptor data structure.
1053 * @hbq_entry_index: index of the HBQ entry data structures.
1054 * @pmb: pointer to the driver internal queue element for mailbox command.
1056 * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
1057 * an HBQ. The configuration binds events that require buffers to a particular
1058 * ring and HBQ based on a selection profile.
1060 * This routine prepares the mailbox command for configuring an HBQ.
1063 lpfc_config_hbq(struct lpfc_hba
*phba
, uint32_t id
,
1064 struct lpfc_hbq_init
*hbq_desc
,
1065 uint32_t hbq_entry_index
, LPFC_MBOXQ_t
*pmb
)
1068 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1069 struct config_hbq_var
*hbqmb
= &mb
->un
.varCfgHbq
;
1071 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
1073 hbqmb
->entry_count
= hbq_desc
->entry_count
; /* # entries in HBQ */
1074 hbqmb
->recvNotify
= hbq_desc
->rn
; /* Receive
1076 hbqmb
->numMask
= hbq_desc
->mask_count
; /* # R_CTL/TYPE masks
1077 * # in words 0-19 */
1078 hbqmb
->profile
= hbq_desc
->profile
; /* Selection profile:
1081 hbqmb
->ringMask
= hbq_desc
->ring_mask
; /* Binds HBQ to a ring
1084 hbqmb
->headerLen
= hbq_desc
->headerLen
; /* 0 if not profile 4
1086 hbqmb
->logEntry
= hbq_desc
->logEntry
; /* Set to 1 if this
1090 hbqmb
->hbqaddrLow
= putPaddrLow(phba
->hbqslimp
.phys
) +
1091 hbq_entry_index
* sizeof(struct lpfc_hbq_entry
);
1092 hbqmb
->hbqaddrHigh
= putPaddrHigh(phba
->hbqslimp
.phys
);
1094 mb
->mbxCommand
= MBX_CONFIG_HBQ
;
1095 mb
->mbxOwner
= OWN_HOST
;
1097 /* Copy info for profiles 2,3,5. Other
1098 * profiles this area is reserved
1100 if (hbq_desc
->profile
== 2)
1101 lpfc_build_hbq_profile2(hbqmb
, hbq_desc
);
1102 else if (hbq_desc
->profile
== 3)
1103 lpfc_build_hbq_profile3(hbqmb
, hbq_desc
);
1104 else if (hbq_desc
->profile
== 5)
1105 lpfc_build_hbq_profile5(hbqmb
, hbq_desc
);
1107 /* Return if no rctl / type masks for this HBQ */
1108 if (!hbq_desc
->mask_count
)
1111 /* Otherwise we setup specific rctl / type masks for this HBQ */
1112 for (i
= 0; i
< hbq_desc
->mask_count
; i
++) {
1113 hbqmb
->hbqMasks
[i
].tmatch
= hbq_desc
->hbqMasks
[i
].tmatch
;
1114 hbqmb
->hbqMasks
[i
].tmask
= hbq_desc
->hbqMasks
[i
].tmask
;
1115 hbqmb
->hbqMasks
[i
].rctlmatch
= hbq_desc
->hbqMasks
[i
].rctlmatch
;
1116 hbqmb
->hbqMasks
[i
].rctlmask
= hbq_desc
->hbqMasks
[i
].rctlmask
;
1123 * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
1124 * @phba: pointer to lpfc hba data structure.
1126 * @pmb: pointer to the driver internal queue element for mailbox command.
1128 * The configure ring mailbox command is used to configure an IOCB ring. This
1129 * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1130 * ring. This is used to map incoming sequences to a particular ring whose
1131 * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1132 * attempt to configure a ring whose number is greater than the number
1133 * specified in the Port Control Block (PCB). It is an error to issue the
1134 * configure ring command more than once with the same ring number. The HBA
1135 * returns an error if the driver attempts this.
1137 * This routine prepares the mailbox command for configuring IOCB ring.
1140 lpfc_config_ring(struct lpfc_hba
* phba
, int ring
, LPFC_MBOXQ_t
* pmb
)
1143 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1144 struct lpfc_sli
*psli
;
1145 struct lpfc_sli_ring
*pring
;
1147 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
1149 mb
->un
.varCfgRing
.ring
= ring
;
1150 mb
->un
.varCfgRing
.maxOrigXchg
= 0;
1151 mb
->un
.varCfgRing
.maxRespXchg
= 0;
1152 mb
->un
.varCfgRing
.recvNotify
= 1;
1155 pring
= &psli
->ring
[ring
];
1156 mb
->un
.varCfgRing
.numMask
= pring
->num_mask
;
1157 mb
->mbxCommand
= MBX_CONFIG_RING
;
1158 mb
->mbxOwner
= OWN_HOST
;
1160 /* Is this ring configured for a specific profile */
1161 if (pring
->prt
[0].profile
) {
1162 mb
->un
.varCfgRing
.profile
= pring
->prt
[0].profile
;
1166 /* Otherwise we setup specific rctl / type masks for this ring */
1167 for (i
= 0; i
< pring
->num_mask
; i
++) {
1168 mb
->un
.varCfgRing
.rrRegs
[i
].rval
= pring
->prt
[i
].rctl
;
1169 if (mb
->un
.varCfgRing
.rrRegs
[i
].rval
!= FC_RCTL_ELS_REQ
)
1170 mb
->un
.varCfgRing
.rrRegs
[i
].rmask
= 0xff;
1172 mb
->un
.varCfgRing
.rrRegs
[i
].rmask
= 0xfe;
1173 mb
->un
.varCfgRing
.rrRegs
[i
].tval
= pring
->prt
[i
].type
;
1174 mb
->un
.varCfgRing
.rrRegs
[i
].tmask
= 0xff;
1181 * lpfc_config_port - Prepare a mailbox command for configuring port
1182 * @phba: pointer to lpfc hba data structure.
1183 * @pmb: pointer to the driver internal queue element for mailbox command.
1185 * The configure port mailbox command is used to identify the Port Control
1186 * Block (PCB) in the driver memory. After this command is issued, the
1187 * driver must not access the mailbox in the HBA without first resetting
1188 * the HBA. The HBA may copy the PCB information to internal storage for
1189 * subsequent use; the driver can not change the PCB information unless it
1192 * This routine prepares the mailbox command for configuring port.
1195 lpfc_config_port(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1197 MAILBOX_t __iomem
*mb_slim
= (MAILBOX_t __iomem
*) phba
->MBslimaddr
;
1198 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1199 dma_addr_t pdma_addr
;
1200 uint32_t bar_low
, bar_high
;
1202 struct lpfc_hgp hgp
;
1204 uint32_t pgp_offset
;
1206 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
1207 mb
->mbxCommand
= MBX_CONFIG_PORT
;
1208 mb
->mbxOwner
= OWN_HOST
;
1210 mb
->un
.varCfgPort
.pcbLen
= sizeof(PCB_t
);
1212 offset
= (uint8_t *)phba
->pcb
- (uint8_t *)phba
->slim2p
.virt
;
1213 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1214 mb
->un
.varCfgPort
.pcbLow
= putPaddrLow(pdma_addr
);
1215 mb
->un
.varCfgPort
.pcbHigh
= putPaddrHigh(pdma_addr
);
1217 /* Always Host Group Pointer is in SLIM */
1218 mb
->un
.varCfgPort
.hps
= 1;
1220 /* If HBA supports SLI=3 ask for it */
1222 if (phba
->sli_rev
== LPFC_SLI_REV3
&& phba
->vpd
.sli3Feat
.cerbm
) {
1223 if (phba
->cfg_enable_bg
)
1224 mb
->un
.varCfgPort
.cbg
= 1; /* configure BlockGuard */
1225 mb
->un
.varCfgPort
.cdss
= 1; /* Configure Security */
1226 mb
->un
.varCfgPort
.cerbm
= 1; /* Request HBQs */
1227 mb
->un
.varCfgPort
.ccrp
= 1; /* Command Ring Polling */
1228 mb
->un
.varCfgPort
.max_hbq
= lpfc_sli_hbq_count();
1229 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
1230 phba
->vpd
.sli3Feat
.cmv
) {
1231 mb
->un
.varCfgPort
.max_vpi
= LPFC_MAX_VPI
;
1232 mb
->un
.varCfgPort
.cmv
= 1;
1234 mb
->un
.varCfgPort
.max_vpi
= phba
->max_vpi
= 0;
1236 phba
->sli_rev
= LPFC_SLI_REV2
;
1237 mb
->un
.varCfgPort
.sli_mode
= phba
->sli_rev
;
1240 phba
->pcb
->type
= TYPE_NATIVE_SLI2
;
1241 phba
->pcb
->feature
= FEATURE_INITIAL_SLI2
;
1243 /* Setup Mailbox pointers */
1244 phba
->pcb
->mailBoxSize
= sizeof(MAILBOX_t
) + MAILBOX_EXT_SIZE
;
1245 offset
= (uint8_t *)phba
->mbox
- (uint8_t *)phba
->slim2p
.virt
;
1246 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1247 phba
->pcb
->mbAddrHigh
= putPaddrHigh(pdma_addr
);
1248 phba
->pcb
->mbAddrLow
= putPaddrLow(pdma_addr
);
1251 * Setup Host Group ring pointer.
1253 * For efficiency reasons, the ring get/put pointers can be
1254 * placed in adapter memory (SLIM) rather than in host memory.
1255 * This allows firmware to avoid PCI reads/writes when updating
1256 * and checking pointers.
1258 * The firmware recognizes the use of SLIM memory by comparing
1259 * the address of the get/put pointers structure with that of
1260 * the SLIM BAR (BAR0).
1262 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1263 * (the hardware's view of the base address), not the OS's
1264 * value of pci_resource_start() as the OS value may be a cookie
1265 * for ioremap/iomap.
1269 pci_read_config_dword(phba
->pcidev
, PCI_BASE_ADDRESS_0
, &bar_low
);
1270 pci_read_config_dword(phba
->pcidev
, PCI_BASE_ADDRESS_1
, &bar_high
);
1273 * Set up HGP - Port Memory
1275 * The port expects the host get/put pointers to reside in memory
1276 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1277 * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
1278 * words (0x40 bytes). This area is not reserved if HBQs are
1279 * configured in SLI-3.
1281 * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1290 * Reserved 0xa0-0xbf
1291 * If HBQs configured:
1292 * HBQ 0 Put ptr 0xc0
1293 * HBQ 1 Put ptr 0xc4
1294 * HBQ 2 Put ptr 0xc8
1296 * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1300 if (phba
->cfg_hostmem_hgp
&& phba
->sli_rev
!= 3) {
1301 phba
->host_gp
= &phba
->mbox
->us
.s2
.host
[0];
1302 phba
->hbq_put
= NULL
;
1303 offset
= (uint8_t *)&phba
->mbox
->us
.s2
.host
-
1304 (uint8_t *)phba
->slim2p
.virt
;
1305 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1306 phba
->pcb
->hgpAddrHigh
= putPaddrHigh(pdma_addr
);
1307 phba
->pcb
->hgpAddrLow
= putPaddrLow(pdma_addr
);
1309 /* Always Host Group Pointer is in SLIM */
1310 mb
->un
.varCfgPort
.hps
= 1;
1312 if (phba
->sli_rev
== 3) {
1313 phba
->host_gp
= &mb_slim
->us
.s3
.host
[0];
1314 phba
->hbq_put
= &mb_slim
->us
.s3
.hbq_put
[0];
1316 phba
->host_gp
= &mb_slim
->us
.s2
.host
[0];
1317 phba
->hbq_put
= NULL
;
1320 /* mask off BAR0's flag bits 0 - 3 */
1321 phba
->pcb
->hgpAddrLow
= (bar_low
& PCI_BASE_ADDRESS_MEM_MASK
) +
1322 (void __iomem
*)phba
->host_gp
-
1323 (void __iomem
*)phba
->MBslimaddr
;
1324 if (bar_low
& PCI_BASE_ADDRESS_MEM_TYPE_64
)
1325 phba
->pcb
->hgpAddrHigh
= bar_high
;
1327 phba
->pcb
->hgpAddrHigh
= 0;
1328 /* write HGP data to SLIM at the required longword offset */
1329 memset(&hgp
, 0, sizeof(struct lpfc_hgp
));
1331 for (i
= 0; i
< phba
->sli
.num_rings
; i
++) {
1332 lpfc_memcpy_to_slim(phba
->host_gp
+ i
, &hgp
,
1333 sizeof(*phba
->host_gp
));
1337 /* Setup Port Group offset */
1338 if (phba
->sli_rev
== 3)
1339 pgp_offset
= offsetof(struct lpfc_sli2_slim
,
1340 mbx
.us
.s3_pgp
.port
);
1342 pgp_offset
= offsetof(struct lpfc_sli2_slim
, mbx
.us
.s2
.port
);
1343 pdma_addr
= phba
->slim2p
.phys
+ pgp_offset
;
1344 phba
->pcb
->pgpAddrHigh
= putPaddrHigh(pdma_addr
);
1345 phba
->pcb
->pgpAddrLow
= putPaddrLow(pdma_addr
);
1347 /* Use callback routine to setp rings in the pcb */
1348 lpfc_config_pcb_setup(phba
);
1350 /* special handling for LC HBAs */
1351 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
1352 uint32_t hbainit
[5];
1354 lpfc_hba_init(phba
, hbainit
);
1356 memcpy(&mb
->un
.varCfgPort
.hbainit
, hbainit
, 20);
1359 /* Swap PCB if needed */
1360 lpfc_sli_pcimem_bcopy(phba
->pcb
, phba
->pcb
, sizeof(PCB_t
));
1364 * lpfc_kill_board - Prepare a mailbox command for killing board
1365 * @phba: pointer to lpfc hba data structure.
1366 * @pmb: pointer to the driver internal queue element for mailbox command.
1368 * The kill board mailbox command is used to tell firmware to perform a
1369 * graceful shutdown of a channel on a specified board to prepare for reset.
1370 * When the kill board mailbox command is received, the ER3 bit is set to 1
1371 * in the Host Status register and the ER Attention bit is set to 1 in the
1372 * Host Attention register of the HBA function that received the kill board
1375 * This routine prepares the mailbox command for killing the board in
1376 * preparation for a graceful shutdown.
1379 lpfc_kill_board(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
1381 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1383 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
1384 mb
->mbxCommand
= MBX_KILL_BOARD
;
1385 mb
->mbxOwner
= OWN_HOST
;
1390 * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
1391 * @phba: pointer to lpfc hba data structure.
1392 * @mbq: pointer to the driver internal queue element for mailbox command.
1394 * Driver maintains a internal mailbox command queue implemented as a linked
1395 * list. When a mailbox command is issued, it shall be put into the mailbox
1396 * command queue such that they shall be processed orderly as HBA can process
1397 * one mailbox command at a time.
1400 lpfc_mbox_put(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* mbq
)
1402 struct lpfc_sli
*psli
;
1406 list_add_tail(&mbq
->list
, &psli
->mboxq
);
1414 * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
1415 * @phba: pointer to lpfc hba data structure.
1417 * Driver maintains a internal mailbox command queue implemented as a linked
1418 * list. When a mailbox command is issued, it shall be put into the mailbox
1419 * command queue such that they shall be processed orderly as HBA can process
1420 * one mailbox command at a time. After HBA finished processing a mailbox
1421 * command, the driver will remove a pending mailbox command from the head of
1422 * the mailbox command queue and send to the HBA for processing.
1425 * pointer to the driver internal queue element for mailbox command.
1428 lpfc_mbox_get(struct lpfc_hba
* phba
)
1430 LPFC_MBOXQ_t
*mbq
= NULL
;
1431 struct lpfc_sli
*psli
= &phba
->sli
;
1433 list_remove_head((&psli
->mboxq
), mbq
, LPFC_MBOXQ_t
, list
);
1441 * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
1442 * @phba: pointer to lpfc hba data structure.
1443 * @mbq: pointer to the driver internal queue element for mailbox command.
1445 * This routine put the completed mailbox command into the mailbox command
1446 * complete list. This is the unlocked version of the routine. The mailbox
1447 * complete list is used by the driver worker thread to process mailbox
1448 * complete callback functions outside the driver interrupt handler.
1451 __lpfc_mbox_cmpl_put(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbq
)
1453 list_add_tail(&mbq
->list
, &phba
->sli
.mboxq_cmpl
);
1457 * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
1458 * @phba: pointer to lpfc hba data structure.
1459 * @mbq: pointer to the driver internal queue element for mailbox command.
1461 * This routine put the completed mailbox command into the mailbox command
1462 * complete list. This is the locked version of the routine. The mailbox
1463 * complete list is used by the driver worker thread to process mailbox
1464 * complete callback functions outside the driver interrupt handler.
1467 lpfc_mbox_cmpl_put(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbq
)
1469 unsigned long iflag
;
1471 /* This function expects to be called from interrupt context */
1472 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1473 __lpfc_mbox_cmpl_put(phba
, mbq
);
1474 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1479 * lpfc_mbox_cmd_check - Check the validality of a mailbox command
1480 * @phba: pointer to lpfc hba data structure.
1481 * @mboxq: pointer to the driver internal queue element for mailbox command.
1483 * This routine is to check whether a mailbox command is valid to be issued.
1484 * This check will be performed by both the mailbox issue API when a client
1485 * is to issue a mailbox command to the mailbox transport.
1487 * Return 0 - pass the check, -ENODEV - fail the check
1490 lpfc_mbox_cmd_check(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1492 /* Mailbox command that have a completion handler must also have a
1495 if (mboxq
->mbox_cmpl
&& mboxq
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
1496 mboxq
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
1497 if (!mboxq
->vport
) {
1498 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
1499 "1814 Mbox x%x failed, no vport\n",
1500 mboxq
->u
.mb
.mbxCommand
);
1509 * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
1510 * @phba: pointer to lpfc hba data structure.
1512 * This routine is to check whether the HBA device is ready for posting a
1513 * mailbox command. It is used by the mailbox transport API at the time the
1514 * to post a mailbox command to the device.
1516 * Return 0 - pass the check, -ENODEV - fail the check
1519 lpfc_mbox_dev_check(struct lpfc_hba
*phba
)
1521 /* If the PCI channel is in offline state, do not issue mbox */
1522 if (unlikely(pci_channel_offline(phba
->pcidev
)))
1525 /* If the HBA is in error state, do not issue mbox */
1526 if (phba
->link_state
== LPFC_HBA_ERROR
)
1533 * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
1534 * @phba: pointer to lpfc hba data structure.
1535 * @cmd: mailbox command code.
1537 * This routine retrieves the proper timeout value according to the mailbox
1541 * Timeout value to be used for the given mailbox command
1544 lpfc_mbox_tmo_val(struct lpfc_hba
*phba
, int cmd
)
1547 case MBX_WRITE_NV
: /* 0x03 */
1548 case MBX_UPDATE_CFG
: /* 0x1B */
1549 case MBX_DOWN_LOAD
: /* 0x1C */
1550 case MBX_DEL_LD_ENTRY
: /* 0x1D */
1551 case MBX_LOAD_AREA
: /* 0x81 */
1552 case MBX_WRITE_WWN
: /* 0x98 */
1553 case MBX_LOAD_EXP_ROM
: /* 0x9C */
1554 return LPFC_MBOX_TMO_FLASH_CMD
;
1555 case MBX_SLI4_CONFIG
: /* 0x9b */
1556 return LPFC_MBOX_SLI4_CONFIG_TMO
;
1558 return LPFC_MBOX_TMO
;
1562 * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
1563 * @mbox: pointer to lpfc mbox command.
1564 * @sgentry: sge entry index.
1565 * @phyaddr: physical address for the sge
1566 * @length: Length of the sge.
1568 * This routine sets up an entry in the non-embedded mailbox command at the sge
1572 lpfc_sli4_mbx_sge_set(struct lpfcMboxq
*mbox
, uint32_t sgentry
,
1573 dma_addr_t phyaddr
, uint32_t length
)
1575 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
1577 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
1578 &mbox
->u
.mqe
.un
.nembed_cmd
;
1579 nembed_sge
->sge
[sgentry
].pa_lo
= putPaddrLow(phyaddr
);
1580 nembed_sge
->sge
[sgentry
].pa_hi
= putPaddrHigh(phyaddr
);
1581 nembed_sge
->sge
[sgentry
].length
= length
;
1585 * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
1586 * @mbox: pointer to lpfc mbox command.
1587 * @sgentry: sge entry index.
1589 * This routine gets an entry from the non-embedded mailbox command at the sge
1593 lpfc_sli4_mbx_sge_get(struct lpfcMboxq
*mbox
, uint32_t sgentry
,
1594 struct lpfc_mbx_sge
*sge
)
1596 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
1598 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
1599 &mbox
->u
.mqe
.un
.nembed_cmd
;
1600 sge
->pa_lo
= nembed_sge
->sge
[sgentry
].pa_lo
;
1601 sge
->pa_hi
= nembed_sge
->sge
[sgentry
].pa_hi
;
1602 sge
->length
= nembed_sge
->sge
[sgentry
].length
;
1606 * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
1607 * @phba: pointer to lpfc hba data structure.
1608 * @mbox: pointer to lpfc mbox command.
1610 * This routine frees SLI4 specific mailbox command for sending IOCTL command.
1613 lpfc_sli4_mbox_cmd_free(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
1615 struct lpfc_mbx_sli4_config
*sli4_cfg
;
1616 struct lpfc_mbx_sge sge
;
1618 uint32_t sgecount
, sgentry
;
1620 sli4_cfg
= &mbox
->u
.mqe
.un
.sli4_config
;
1622 /* For embedded mbox command, just free the mbox command */
1623 if (bf_get(lpfc_mbox_hdr_emb
, &sli4_cfg
->header
.cfg_mhdr
)) {
1624 mempool_free(mbox
, phba
->mbox_mem_pool
);
1628 /* For non-embedded mbox command, we need to free the pages first */
1629 sgecount
= bf_get(lpfc_mbox_hdr_sge_cnt
, &sli4_cfg
->header
.cfg_mhdr
);
1630 /* There is nothing we can do if there is no sge address array */
1631 if (unlikely(!mbox
->sge_array
)) {
1632 mempool_free(mbox
, phba
->mbox_mem_pool
);
1635 /* Each non-embedded DMA memory was allocated in the length of a page */
1636 for (sgentry
= 0; sgentry
< sgecount
; sgentry
++) {
1637 lpfc_sli4_mbx_sge_get(mbox
, sgentry
, &sge
);
1638 phyaddr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
1639 dma_free_coherent(&phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
1640 mbox
->sge_array
->addr
[sgentry
], phyaddr
);
1642 /* Free the sge address array memory */
1643 kfree(mbox
->sge_array
);
1644 /* Finally, free the mailbox command itself */
1645 mempool_free(mbox
, phba
->mbox_mem_pool
);
1649 * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command
1650 * @phba: pointer to lpfc hba data structure.
1651 * @mbox: pointer to lpfc mbox command.
1652 * @subsystem: The sli4 config sub mailbox subsystem.
1653 * @opcode: The sli4 config sub mailbox command opcode.
1654 * @length: Length of the sli4 config mailbox command.
1656 * This routine sets up the header fields of SLI4 specific mailbox command
1657 * for sending IOCTL command.
1659 * Return: the actual length of the mbox command allocated (mostly useful
1660 * for none embedded mailbox command).
1663 lpfc_sli4_config(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
,
1664 uint8_t subsystem
, uint8_t opcode
, uint32_t length
, bool emb
)
1666 struct lpfc_mbx_sli4_config
*sli4_config
;
1667 union lpfc_sli4_cfg_shdr
*cfg_shdr
= NULL
;
1670 uint32_t pagen
, pcount
;
1674 /* Set up SLI4 mailbox command header fields */
1675 memset(mbox
, 0, sizeof(*mbox
));
1676 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_SLI4_CONFIG
);
1678 /* Set up SLI4 ioctl command header fields */
1679 sli4_config
= &mbox
->u
.mqe
.un
.sli4_config
;
1681 /* Setup for the embedded mbox command */
1683 /* Set up main header fields */
1684 bf_set(lpfc_mbox_hdr_emb
, &sli4_config
->header
.cfg_mhdr
, 1);
1685 sli4_config
->header
.cfg_mhdr
.payload_length
=
1686 LPFC_MBX_CMD_HDR_LENGTH
+ length
;
1687 /* Set up sub-header fields following main header */
1688 bf_set(lpfc_mbox_hdr_opcode
,
1689 &sli4_config
->header
.cfg_shdr
.request
, opcode
);
1690 bf_set(lpfc_mbox_hdr_subsystem
,
1691 &sli4_config
->header
.cfg_shdr
.request
, subsystem
);
1692 sli4_config
->header
.cfg_shdr
.request
.request_length
= length
;
1696 /* Setup for the none-embedded mbox command */
1697 pcount
= (PAGE_ALIGN(length
))/SLI4_PAGE_SIZE
;
1698 pcount
= (pcount
> LPFC_SLI4_MBX_SGE_MAX_PAGES
) ?
1699 LPFC_SLI4_MBX_SGE_MAX_PAGES
: pcount
;
1700 /* Allocate record for keeping SGE virtual addresses */
1701 mbox
->sge_array
= kmalloc(sizeof(struct lpfc_mbx_nembed_sge_virt
),
1703 if (!mbox
->sge_array
) {
1704 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1705 "2527 Failed to allocate non-embedded SGE "
1709 for (pagen
= 0, alloc_len
= 0; pagen
< pcount
; pagen
++) {
1710 /* The DMA memory is always allocated in the length of a
1711 * page even though the last SGE might not fill up to a
1712 * page, this is used as a priori size of SLI4_PAGE_SIZE for
1713 * the later DMA memory free.
1715 viraddr
= dma_alloc_coherent(&phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
1716 &phyaddr
, GFP_KERNEL
);
1717 /* In case of malloc fails, proceed with whatever we have */
1720 memset(viraddr
, 0, SLI4_PAGE_SIZE
);
1721 mbox
->sge_array
->addr
[pagen
] = viraddr
;
1722 /* Keep the first page for later sub-header construction */
1724 cfg_shdr
= (union lpfc_sli4_cfg_shdr
*)viraddr
;
1725 resid_len
= length
- alloc_len
;
1726 if (resid_len
> SLI4_PAGE_SIZE
) {
1727 lpfc_sli4_mbx_sge_set(mbox
, pagen
, phyaddr
,
1729 alloc_len
+= SLI4_PAGE_SIZE
;
1731 lpfc_sli4_mbx_sge_set(mbox
, pagen
, phyaddr
,
1737 /* Set up main header fields in mailbox command */
1738 sli4_config
->header
.cfg_mhdr
.payload_length
= alloc_len
;
1739 bf_set(lpfc_mbox_hdr_sge_cnt
, &sli4_config
->header
.cfg_mhdr
, pagen
);
1741 /* Set up sub-header fields into the first page */
1743 bf_set(lpfc_mbox_hdr_opcode
, &cfg_shdr
->request
, opcode
);
1744 bf_set(lpfc_mbox_hdr_subsystem
, &cfg_shdr
->request
, subsystem
);
1745 cfg_shdr
->request
.request_length
=
1746 alloc_len
- sizeof(union lpfc_sli4_cfg_shdr
);
1748 /* The sub-header is in DMA memory, which needs endian converstion */
1750 lpfc_sli_pcimem_bcopy(cfg_shdr
, cfg_shdr
,
1751 sizeof(union lpfc_sli4_cfg_shdr
));
1757 * lpfc_sli4_mbox_opcode_get - Get the opcode from a sli4 mailbox command
1758 * @phba: pointer to lpfc hba data structure.
1759 * @mbox: pointer to lpfc mbox command.
1761 * This routine gets the opcode from a SLI4 specific mailbox command for
1762 * sending IOCTL command. If the mailbox command is not MBX_SLI4_CONFIG
1763 * (0x9B) or if the IOCTL sub-header is not present, opcode 0x0 shall be
1767 lpfc_sli4_mbox_opcode_get(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
1769 struct lpfc_mbx_sli4_config
*sli4_cfg
;
1770 union lpfc_sli4_cfg_shdr
*cfg_shdr
;
1772 if (mbox
->u
.mb
.mbxCommand
!= MBX_SLI4_CONFIG
)
1774 sli4_cfg
= &mbox
->u
.mqe
.un
.sli4_config
;
1776 /* For embedded mbox command, get opcode from embedded sub-header*/
1777 if (bf_get(lpfc_mbox_hdr_emb
, &sli4_cfg
->header
.cfg_mhdr
)) {
1778 cfg_shdr
= &mbox
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
1779 return bf_get(lpfc_mbox_hdr_opcode
, &cfg_shdr
->request
);
1782 /* For non-embedded mbox command, get opcode from first dma page */
1783 if (unlikely(!mbox
->sge_array
))
1785 cfg_shdr
= (union lpfc_sli4_cfg_shdr
*)mbox
->sge_array
->addr
[0];
1786 return bf_get(lpfc_mbox_hdr_opcode
, &cfg_shdr
->request
);
1790 * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd
1791 * @phba: pointer to lpfc hba data structure.
1792 * @fcf_index: index to fcf table.
1794 * This routine routine allocates and constructs non-embedded mailbox command
1795 * for reading a FCF table entry refered by @fcf_index.
1797 * Return: pointer to the mailbox command constructed if successful, otherwise
1801 lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba
*phba
,
1802 struct lpfcMboxq
*mboxq
,
1806 dma_addr_t phys_addr
;
1808 struct lpfc_mbx_sge sge
;
1809 uint32_t alloc_len
, req_len
;
1810 struct lpfc_mbx_read_fcf_tbl
*read_fcf
;
1815 req_len
= sizeof(struct fcf_record
) +
1816 sizeof(union lpfc_sli4_cfg_shdr
) + 2 * sizeof(uint32_t);
1818 /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
1819 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
1820 LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE
, req_len
,
1821 LPFC_SLI4_MBX_NEMBED
);
1823 if (alloc_len
< req_len
) {
1824 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1825 "0291 Allocated DMA memory size (x%x) is "
1826 "less than the requested DMA memory "
1827 "size (x%x)\n", alloc_len
, req_len
);
1831 /* Get the first SGE entry from the non-embedded DMA memory. This
1832 * routine only uses a single SGE.
1834 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
1835 phys_addr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
1836 virt_addr
= mboxq
->sge_array
->addr
[0];
1837 read_fcf
= (struct lpfc_mbx_read_fcf_tbl
*)virt_addr
;
1839 /* Set up command fields */
1840 bf_set(lpfc_mbx_read_fcf_tbl_indx
, &read_fcf
->u
.request
, fcf_index
);
1841 /* Perform necessary endian conversion */
1842 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
1843 lpfc_sli_pcimem_bcopy(bytep
, bytep
, sizeof(uint32_t));
1849 * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
1850 * @mboxq: pointer to lpfc mbox command.
1852 * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
1856 lpfc_request_features(struct lpfc_hba
*phba
, struct lpfcMboxq
*mboxq
)
1858 /* Set up SLI4 mailbox command header fields */
1859 memset(mboxq
, 0, sizeof(LPFC_MBOXQ_t
));
1860 bf_set(lpfc_mqe_command
, &mboxq
->u
.mqe
, MBX_SLI4_REQ_FTRS
);
1862 /* Set up host requested features. */
1863 bf_set(lpfc_mbx_rq_ftr_rq_fcpi
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
1865 /* Enable DIF (block guard) only if configured to do so. */
1866 if (phba
->cfg_enable_bg
)
1867 bf_set(lpfc_mbx_rq_ftr_rq_dif
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
1869 /* Enable NPIV only if configured to do so. */
1870 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
)
1871 bf_set(lpfc_mbx_rq_ftr_rq_npiv
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
1877 * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
1878 * @mbox: pointer to lpfc mbox command to initialize.
1879 * @vport: Vport associated with the VF.
1881 * This routine initializes @mbox to all zeros and then fills in the mailbox
1882 * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
1883 * in the context of an FCF. The driver issues this command to setup a VFI
1884 * before issuing a FLOGI to login to the VSAN. The driver should also issue a
1885 * REG_VFI after a successful VSAN login.
1888 lpfc_init_vfi(struct lpfcMboxq
*mbox
, struct lpfc_vport
*vport
)
1890 struct lpfc_mbx_init_vfi
*init_vfi
;
1892 memset(mbox
, 0, sizeof(*mbox
));
1893 init_vfi
= &mbox
->u
.mqe
.un
.init_vfi
;
1894 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_INIT_VFI
);
1895 bf_set(lpfc_init_vfi_vr
, init_vfi
, 1);
1896 bf_set(lpfc_init_vfi_vt
, init_vfi
, 1);
1897 bf_set(lpfc_init_vfi_vfi
, init_vfi
, vport
->vfi
+ vport
->phba
->vfi_base
);
1898 bf_set(lpfc_init_vfi_fcfi
, init_vfi
, vport
->phba
->fcf
.fcfi
);
1902 * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
1903 * @mbox: pointer to lpfc mbox command to initialize.
1904 * @vport: vport associated with the VF.
1905 * @phys: BDE DMA bus address used to send the service parameters to the HBA.
1907 * This routine initializes @mbox to all zeros and then fills in the mailbox
1908 * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
1909 * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
1910 * fabrics identified by VFI in the context of an FCF.
1913 lpfc_reg_vfi(struct lpfcMboxq
*mbox
, struct lpfc_vport
*vport
, dma_addr_t phys
)
1915 struct lpfc_mbx_reg_vfi
*reg_vfi
;
1917 memset(mbox
, 0, sizeof(*mbox
));
1918 reg_vfi
= &mbox
->u
.mqe
.un
.reg_vfi
;
1919 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_REG_VFI
);
1920 bf_set(lpfc_reg_vfi_vp
, reg_vfi
, 1);
1921 bf_set(lpfc_reg_vfi_vfi
, reg_vfi
, vport
->vfi
+ vport
->phba
->vfi_base
);
1922 bf_set(lpfc_reg_vfi_fcfi
, reg_vfi
, vport
->phba
->fcf
.fcfi
);
1923 bf_set(lpfc_reg_vfi_vpi
, reg_vfi
, vport
->vpi
+ vport
->phba
->vpi_base
);
1924 memcpy(reg_vfi
->wwn
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
1925 reg_vfi
->wwn
[0] = cpu_to_le32(reg_vfi
->wwn
[0]);
1926 reg_vfi
->wwn
[1] = cpu_to_le32(reg_vfi
->wwn
[1]);
1927 reg_vfi
->e_d_tov
= vport
->phba
->fc_edtov
;
1928 reg_vfi
->r_a_tov
= vport
->phba
->fc_ratov
;
1929 reg_vfi
->bde
.addrHigh
= putPaddrHigh(phys
);
1930 reg_vfi
->bde
.addrLow
= putPaddrLow(phys
);
1931 reg_vfi
->bde
.tus
.f
.bdeSize
= sizeof(vport
->fc_sparam
);
1932 reg_vfi
->bde
.tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
1933 bf_set(lpfc_reg_vfi_nport_id
, reg_vfi
, vport
->fc_myDID
);
1937 * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
1938 * @phba: pointer to the hba structure to init the VPI for.
1939 * @mbox: pointer to lpfc mbox command to initialize.
1940 * @vpi: VPI to be initialized.
1942 * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
1943 * command to activate a virtual N_Port. The HBA assigns a MAC address to use
1944 * with the virtual N Port. The SLI Host issues this command before issuing a
1945 * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
1946 * successful virtual NPort login.
1949 lpfc_init_vpi(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
, uint16_t vpi
)
1951 memset(mbox
, 0, sizeof(*mbox
));
1952 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_INIT_VPI
);
1953 bf_set(lpfc_init_vpi_vpi
, &mbox
->u
.mqe
.un
.init_vpi
,
1954 vpi
+ phba
->vpi_base
);
1955 bf_set(lpfc_init_vpi_vfi
, &mbox
->u
.mqe
.un
.init_vpi
,
1956 phba
->pport
->vfi
+ phba
->vfi_base
);
1960 * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
1961 * @mbox: pointer to lpfc mbox command to initialize.
1962 * @vport: vport associated with the VF.
1964 * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
1965 * (logical NPort) into the inactive state. The SLI Host must have logged out
1966 * and unregistered all remote N_Ports to abort any activity on the virtual
1967 * fabric. The SLI Port posts the mailbox response after marking the virtual
1971 lpfc_unreg_vfi(struct lpfcMboxq
*mbox
, struct lpfc_vport
*vport
)
1973 memset(mbox
, 0, sizeof(*mbox
));
1974 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_UNREG_VFI
);
1975 bf_set(lpfc_unreg_vfi_vfi
, &mbox
->u
.mqe
.un
.unreg_vfi
,
1976 vport
->vfi
+ vport
->phba
->vfi_base
);
1980 * lpfc_dump_fcoe_param - Dump config region 23 to get FCoe parameters.
1981 * @phba: pointer to the hba structure containing.
1982 * @mbox: pointer to lpfc mbox command to initialize.
1984 * This function create a SLI4 dump mailbox command to dump FCoE
1985 * parameters stored in region 23.
1988 lpfc_dump_fcoe_param(struct lpfc_hba
*phba
,
1989 struct lpfcMboxq
*mbox
)
1991 struct lpfc_dmabuf
*mp
= NULL
;
1994 memset(mbox
, 0, sizeof(*mbox
));
1997 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
1999 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
2001 if (!mp
|| !mp
->virt
) {
2003 /* dump_fcoe_param failed to allocate memory */
2004 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
2005 "2569 lpfc_dump_fcoe_param: memory"
2006 " allocation failed\n");
2010 memset(mp
->virt
, 0, LPFC_BPL_SIZE
);
2011 INIT_LIST_HEAD(&mp
->list
);
2013 /* save address for completion */
2014 mbox
->context1
= (uint8_t *) mp
;
2016 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
2017 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
2018 mb
->un
.varDmp
.region_id
= DMP_REGION_23
;
2019 mb
->un
.varDmp
.sli4_length
= DMP_RGN23_SIZE
;
2020 mb
->un
.varWords
[3] = putPaddrLow(mp
->phys
);
2021 mb
->un
.varWords
[4] = putPaddrHigh(mp
->phys
);
2026 * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
2027 * @phba: pointer to the hba structure containing the FCF index and RQ ID.
2028 * @mbox: pointer to lpfc mbox command to initialize.
2030 * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
2031 * SLI Host uses the command to activate an FCF after it has acquired FCF
2032 * information via a READ_FCF mailbox command. This mailbox command also is used
2033 * to indicate where received unsolicited frames from this FCF will be sent. By
2034 * default this routine will set up the FCF to forward all unsolicited frames
2035 * the the RQ ID passed in the @phba. This can be overridden by the caller for
2036 * more complicated setups.
2039 lpfc_reg_fcfi(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
2041 struct lpfc_mbx_reg_fcfi
*reg_fcfi
;
2043 memset(mbox
, 0, sizeof(*mbox
));
2044 reg_fcfi
= &mbox
->u
.mqe
.un
.reg_fcfi
;
2045 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_REG_FCFI
);
2046 bf_set(lpfc_reg_fcfi_rq_id0
, reg_fcfi
, phba
->sli4_hba
.hdr_rq
->queue_id
);
2047 bf_set(lpfc_reg_fcfi_rq_id1
, reg_fcfi
, REG_FCF_INVALID_QID
);
2048 bf_set(lpfc_reg_fcfi_rq_id2
, reg_fcfi
, REG_FCF_INVALID_QID
);
2049 bf_set(lpfc_reg_fcfi_rq_id3
, reg_fcfi
, REG_FCF_INVALID_QID
);
2050 bf_set(lpfc_reg_fcfi_info_index
, reg_fcfi
,
2051 phba
->fcf
.current_rec
.fcf_indx
);
2052 /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */
2053 bf_set(lpfc_reg_fcfi_mam
, reg_fcfi
, (~phba
->fcf
.addr_mode
) & 0x3);
2054 if (phba
->fcf
.current_rec
.vlan_id
!= LPFC_FCOE_NULL_VID
) {
2055 bf_set(lpfc_reg_fcfi_vv
, reg_fcfi
, 1);
2056 bf_set(lpfc_reg_fcfi_vlan_tag
, reg_fcfi
,
2057 phba
->fcf
.current_rec
.vlan_id
);
2062 * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
2063 * @mbox: pointer to lpfc mbox command to initialize.
2064 * @fcfi: FCFI to be unregistered.
2066 * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
2067 * The SLI Host uses the command to inactivate an FCFI.
2070 lpfc_unreg_fcfi(struct lpfcMboxq
*mbox
, uint16_t fcfi
)
2072 memset(mbox
, 0, sizeof(*mbox
));
2073 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_UNREG_FCFI
);
2074 bf_set(lpfc_unreg_fcfi
, &mbox
->u
.mqe
.un
.unreg_fcfi
, fcfi
);
2078 * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
2079 * @mbox: pointer to lpfc mbox command to initialize.
2080 * @ndlp: The nodelist structure that describes the RPI to resume.
2082 * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
2086 lpfc_resume_rpi(struct lpfcMboxq
*mbox
, struct lpfc_nodelist
*ndlp
)
2088 struct lpfc_mbx_resume_rpi
*resume_rpi
;
2090 memset(mbox
, 0, sizeof(*mbox
));
2091 resume_rpi
= &mbox
->u
.mqe
.un
.resume_rpi
;
2092 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_RESUME_RPI
);
2093 bf_set(lpfc_resume_rpi_index
, resume_rpi
, ndlp
->nlp_rpi
);
2094 bf_set(lpfc_resume_rpi_ii
, resume_rpi
, RESUME_INDEX_RPI
);
2095 resume_rpi
->event_tag
= ndlp
->phba
->fc_eventTag
;
2099 * lpfc_supported_pages - Initialize the PORT_CAPABILITIES supported pages
2101 * @mbox: pointer to lpfc mbox command to initialize.
2103 * The PORT_CAPABILITIES supported pages mailbox command is issued to
2104 * retrieve the particular feature pages supported by the port.
2107 lpfc_supported_pages(struct lpfcMboxq
*mbox
)
2109 struct lpfc_mbx_supp_pages
*supp_pages
;
2111 memset(mbox
, 0, sizeof(*mbox
));
2112 supp_pages
= &mbox
->u
.mqe
.un
.supp_pages
;
2113 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_PORT_CAPABILITIES
);
2114 bf_set(cpn
, supp_pages
, LPFC_SUPP_PAGES
);
2118 * lpfc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params
2120 * @mbox: pointer to lpfc mbox command to initialize.
2122 * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to
2123 * retrieve the particular SLI4 features supported by the port.
2126 lpfc_sli4_params(struct lpfcMboxq
*mbox
)
2128 struct lpfc_mbx_sli4_params
*sli4_params
;
2130 memset(mbox
, 0, sizeof(*mbox
));
2131 sli4_params
= &mbox
->u
.mqe
.un
.sli4_params
;
2132 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_PORT_CAPABILITIES
);
2133 bf_set(cpn
, sli4_params
, LPFC_SLI4_PARAMETERS
);