1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2015 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
->context1
= (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 if (phba
->sli_rev
< LPFC_SLI_REV4
)
182 mb
->un
.varDmp
.entry_index
= 0;
183 mb
->un
.varDmp
.region_id
= WAKE_UP_PARMS_REGION_ID
;
184 mb
->un
.varDmp
.word_cnt
= WAKE_UP_PARMS_WORD_SIZE
;
185 mb
->un
.varDmp
.co
= 0;
186 mb
->un
.varDmp
.resp_offset
= 0;
192 * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
193 * @phba: pointer to lpfc hba data structure.
194 * @pmb: pointer to the driver internal queue element for mailbox command.
196 * The read NVRAM mailbox command returns the HBA's non-volatile parameters
197 * that are used as defaults when the Fibre Channel link is brought on-line.
199 * This routine prepares the mailbox command for reading information stored
200 * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
203 lpfc_read_nv(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
208 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
209 mb
->mbxCommand
= MBX_READ_NV
;
210 mb
->mbxOwner
= OWN_HOST
;
215 * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
216 * @phba: pointer to lpfc hba data structure.
217 * @pmb: pointer to the driver internal queue element for mailbox command.
218 * @ring: ring number for the asynchronous event to be configured.
220 * The asynchronous event enable mailbox command is used to enable the
221 * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
222 * specifies the default ring to which events are posted.
224 * This routine prepares the mailbox command for enabling HBA asynchronous
225 * event support on a IOCB ring.
228 lpfc_config_async(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
,
234 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
235 mb
->mbxCommand
= MBX_ASYNCEVT_ENABLE
;
236 mb
->un
.varCfgAsyncEvent
.ring
= ring
;
237 mb
->mbxOwner
= OWN_HOST
;
242 * lpfc_heart_beat - Prepare a mailbox command for heart beat
243 * @phba: pointer to lpfc hba data structure.
244 * @pmb: pointer to the driver internal queue element for mailbox command.
246 * The heart beat mailbox command is used to detect an unresponsive HBA, which
247 * is defined as any device where no error attention is sent and both mailbox
248 * and rings are not processed.
250 * This routine prepares the mailbox command for issuing a heart beat in the
251 * form of mailbox command to the HBA. The timely completion of the heart
252 * beat mailbox command indicates the health of the HBA.
255 lpfc_heart_beat(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
260 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
261 mb
->mbxCommand
= MBX_HEARTBEAT
;
262 mb
->mbxOwner
= OWN_HOST
;
267 * lpfc_read_topology - Prepare a mailbox command for reading HBA topology
268 * @phba: pointer to lpfc hba data structure.
269 * @pmb: pointer to the driver internal queue element for mailbox command.
270 * @mp: DMA buffer memory for reading the link attention information into.
272 * The read topology mailbox command is issued to read the link topology
273 * information indicated by the HBA port when the Link Event bit of the Host
274 * Attention (HSTATT) register is set to 1 (For SLI-3) or when an FC Link
275 * Attention ACQE is received from the port (For SLI-4). A Link Event
276 * Attention occurs based on an exception detected at the Fibre Channel link
279 * This routine prepares the mailbox command for reading HBA link topology
280 * information. A DMA memory has been set aside and address passed to the
281 * HBA through @mp for the HBA to DMA link attention information into the
282 * memory as part of the execution of the mailbox command.
285 * 0 - Success (currently always return 0)
288 lpfc_read_topology(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
,
289 struct lpfc_dmabuf
*mp
)
294 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
296 INIT_LIST_HEAD(&mp
->list
);
297 mb
->mbxCommand
= MBX_READ_TOPOLOGY
;
298 mb
->un
.varReadTop
.lilpBde64
.tus
.f
.bdeSize
= LPFC_ALPA_MAP_SIZE
;
299 mb
->un
.varReadTop
.lilpBde64
.addrHigh
= putPaddrHigh(mp
->phys
);
300 mb
->un
.varReadTop
.lilpBde64
.addrLow
= putPaddrLow(mp
->phys
);
302 /* Save address for later completion and set the owner to host so that
303 * the FW knows this mailbox is available for processing.
305 pmb
->context1
= (uint8_t *)mp
;
306 mb
->mbxOwner
= OWN_HOST
;
311 * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
312 * @phba: pointer to lpfc hba data structure.
313 * @pmb: pointer to the driver internal queue element for mailbox command.
315 * The clear link attention mailbox command is issued to clear the link event
316 * attention condition indicated by the Link Event bit of the Host Attention
317 * (HSTATT) register. The link event attention condition is cleared only if
318 * the event tag specified matches that of the current link event counter.
319 * The current event tag is read using the read link attention event mailbox
322 * This routine prepares the mailbox command for clearing HBA link attention
326 lpfc_clear_la(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
331 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
333 mb
->un
.varClearLA
.eventTag
= phba
->fc_eventTag
;
334 mb
->mbxCommand
= MBX_CLEAR_LA
;
335 mb
->mbxOwner
= OWN_HOST
;
340 * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
341 * @phba: pointer to lpfc hba data structure.
342 * @pmb: pointer to the driver internal queue element for mailbox command.
344 * The configure link mailbox command is used before the initialize link
345 * mailbox command to override default value and to configure link-oriented
346 * parameters such as DID address and various timers. Typically, this
347 * command would be used after an F_Port login to set the returned DID address
348 * and the fabric timeout values. This command is not valid before a configure
349 * port command has configured the HBA port.
351 * This routine prepares the mailbox command for configuring link on a HBA.
354 lpfc_config_link(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
356 struct lpfc_vport
*vport
= phba
->pport
;
357 MAILBOX_t
*mb
= &pmb
->u
.mb
;
358 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
361 * SLI-2, Coalescing Response Feature.
363 if (phba
->cfg_cr_delay
&& (phba
->sli_rev
< LPFC_SLI_REV4
)) {
364 mb
->un
.varCfgLnk
.cr
= 1;
365 mb
->un
.varCfgLnk
.ci
= 1;
366 mb
->un
.varCfgLnk
.cr_delay
= phba
->cfg_cr_delay
;
367 mb
->un
.varCfgLnk
.cr_count
= phba
->cfg_cr_count
;
370 mb
->un
.varCfgLnk
.myId
= vport
->fc_myDID
;
371 mb
->un
.varCfgLnk
.edtov
= phba
->fc_edtov
;
372 mb
->un
.varCfgLnk
.arbtov
= phba
->fc_arbtov
;
373 mb
->un
.varCfgLnk
.ratov
= phba
->fc_ratov
;
374 mb
->un
.varCfgLnk
.rttov
= phba
->fc_rttov
;
375 mb
->un
.varCfgLnk
.altov
= phba
->fc_altov
;
376 mb
->un
.varCfgLnk
.crtov
= phba
->fc_crtov
;
377 mb
->un
.varCfgLnk
.citov
= phba
->fc_citov
;
379 if (phba
->cfg_ack0
&& (phba
->sli_rev
< LPFC_SLI_REV4
))
380 mb
->un
.varCfgLnk
.ack0_enable
= 1;
382 mb
->mbxCommand
= MBX_CONFIG_LINK
;
383 mb
->mbxOwner
= OWN_HOST
;
388 * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
389 * @phba: pointer to lpfc hba data structure.
390 * @pmb: pointer to the driver internal queue element for mailbox command.
392 * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
393 * MSI-X multi-message interrupt vector association to interrupt attention
401 lpfc_config_msi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
403 MAILBOX_t
*mb
= &pmb
->u
.mb
;
404 uint32_t attentionConditions
[2];
407 if (phba
->cfg_use_msi
!= 2) {
408 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
409 "0475 Not configured for supporting MSI-X "
410 "cfg_use_msi: 0x%x\n", phba
->cfg_use_msi
);
414 if (phba
->sli_rev
< 3) {
415 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
416 "0476 HBA not supporting SLI-3 or later "
417 "SLI Revision: 0x%x\n", phba
->sli_rev
);
421 /* Clear mailbox command fields */
422 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
425 * SLI-3, Message Signaled Interrupt Fearure.
428 /* Multi-message attention configuration */
429 attentionConditions
[0] = (HA_R0ATT
| HA_R1ATT
| HA_R2ATT
| HA_ERATT
|
431 attentionConditions
[1] = 0;
433 mb
->un
.varCfgMSI
.attentionConditions
[0] = attentionConditions
[0];
434 mb
->un
.varCfgMSI
.attentionConditions
[1] = attentionConditions
[1];
437 * Set up message number to HA bit association
439 #ifdef __BIG_ENDIAN_BITFIELD
441 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R0_POS
] = 1;
442 /* RA1 (Other Protocol Extra Ring) */
443 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R1_POS
] = 1;
444 #else /* __LITTLE_ENDIAN_BITFIELD */
446 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R0_POS
^3] = 1;
447 /* RA1 (Other Protocol Extra Ring) */
448 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R1_POS
^3] = 1;
450 /* Multi-message interrupt autoclear configuration*/
451 mb
->un
.varCfgMSI
.autoClearHA
[0] = attentionConditions
[0];
452 mb
->un
.varCfgMSI
.autoClearHA
[1] = attentionConditions
[1];
454 /* For now, HBA autoclear does not work reliably, disable it */
455 mb
->un
.varCfgMSI
.autoClearHA
[0] = 0;
456 mb
->un
.varCfgMSI
.autoClearHA
[1] = 0;
458 /* Set command and owner bit */
459 mb
->mbxCommand
= MBX_CONFIG_MSI
;
460 mb
->mbxOwner
= OWN_HOST
;
466 * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
467 * @phba: pointer to lpfc hba data structure.
468 * @pmb: pointer to the driver internal queue element for mailbox command.
469 * @topology: the link topology for the link to be initialized to.
470 * @linkspeed: the link speed for the link to be initialized to.
472 * The initialize link mailbox command is used to initialize the Fibre
473 * Channel link. This command must follow a configure port command that
474 * establishes the mode of operation.
476 * This routine prepares the mailbox command for initializing link on a HBA
477 * with the specified link topology and speed.
480 lpfc_init_link(struct lpfc_hba
* phba
,
481 LPFC_MBOXQ_t
* pmb
, uint32_t topology
, uint32_t linkspeed
)
487 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
490 case FLAGS_TOPOLOGY_MODE_LOOP_PT
:
491 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_LOOP
;
492 mb
->un
.varInitLnk
.link_flags
|= FLAGS_TOPOLOGY_FAILOVER
;
494 case FLAGS_TOPOLOGY_MODE_PT_PT
:
495 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_PT_PT
;
497 case FLAGS_TOPOLOGY_MODE_LOOP
:
498 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_LOOP
;
500 case FLAGS_TOPOLOGY_MODE_PT_LOOP
:
501 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_PT_PT
;
502 mb
->un
.varInitLnk
.link_flags
|= FLAGS_TOPOLOGY_FAILOVER
;
505 mb
->un
.varInitLnk
.link_flags
= FLAGS_LOCAL_LB
;
509 if (phba
->pcidev
->device
== PCI_DEVICE_ID_LANCER_G6_FC
&&
510 mb
->un
.varInitLnk
.link_flags
& FLAGS_TOPOLOGY_MODE_LOOP
) {
511 /* Failover is not tried for Lancer G6 */
512 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_PT_PT
;
513 phba
->cfg_topology
= FLAGS_TOPOLOGY_MODE_PT_PT
;
516 /* Enable asynchronous ABTS responses from firmware */
517 mb
->un
.varInitLnk
.link_flags
|= FLAGS_IMED_ABORT
;
520 * Setting up the link speed
523 if (vpd
->rev
.feaLevelHigh
>= 0x02){
525 case LPFC_USER_LINK_SPEED_1G
:
526 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
527 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_1G
;
529 case LPFC_USER_LINK_SPEED_2G
:
530 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
531 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_2G
;
533 case LPFC_USER_LINK_SPEED_4G
:
534 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
535 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_4G
;
537 case LPFC_USER_LINK_SPEED_8G
:
538 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
539 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_8G
;
541 case LPFC_USER_LINK_SPEED_10G
:
542 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
543 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_10G
;
545 case LPFC_USER_LINK_SPEED_16G
:
546 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
547 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_16G
;
549 case LPFC_USER_LINK_SPEED_32G
:
550 mb
->un
.varInitLnk
.link_flags
|= FLAGS_LINK_SPEED
;
551 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_32G
;
553 case LPFC_USER_LINK_SPEED_AUTO
:
555 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_AUTO
;
561 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_AUTO
;
563 mb
->mbxCommand
= (volatile uint8_t)MBX_INIT_LINK
;
564 mb
->mbxOwner
= OWN_HOST
;
565 mb
->un
.varInitLnk
.fabric_AL_PA
= phba
->fc_pref_ALPA
;
570 * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
571 * @phba: pointer to lpfc hba data structure.
572 * @pmb: pointer to the driver internal queue element for mailbox command.
573 * @vpi: virtual N_Port identifier.
575 * The read service parameter mailbox command is used to read the HBA port
576 * service parameters. The service parameters are read into the buffer
577 * specified directly by a BDE in the mailbox command. These service
578 * parameters may then be used to build the payload of an N_Port/F_POrt
579 * login request and reply (LOGI/ACC).
581 * This routine prepares the mailbox command for reading HBA port service
582 * parameters. The DMA memory is allocated in this function and the addresses
583 * are populated into the mailbox command for the HBA to DMA the service
588 * 1 - DMA memory allocation failed
591 lpfc_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
, int vpi
)
593 struct lpfc_dmabuf
*mp
;
597 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
599 mb
->mbxOwner
= OWN_HOST
;
601 /* Get a buffer to hold the HBAs Service Parameters */
603 mp
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
605 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
606 if (!mp
|| !mp
->virt
) {
608 mb
->mbxCommand
= MBX_READ_SPARM64
;
609 /* READ_SPARAM: no buffers */
610 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
611 "0301 READ_SPARAM: no buffers\n");
614 INIT_LIST_HEAD(&mp
->list
);
615 mb
->mbxCommand
= MBX_READ_SPARM64
;
616 mb
->un
.varRdSparm
.un
.sp64
.tus
.f
.bdeSize
= sizeof (struct serv_parm
);
617 mb
->un
.varRdSparm
.un
.sp64
.addrHigh
= putPaddrHigh(mp
->phys
);
618 mb
->un
.varRdSparm
.un
.sp64
.addrLow
= putPaddrLow(mp
->phys
);
619 if (phba
->sli_rev
>= LPFC_SLI_REV3
)
620 mb
->un
.varRdSparm
.vpi
= phba
->vpi_ids
[vpi
];
622 /* save address for completion */
629 * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
630 * @phba: pointer to lpfc hba data structure.
631 * @vpi: virtual N_Port identifier.
632 * @did: remote port identifier.
633 * @pmb: pointer to the driver internal queue element for mailbox command.
635 * The unregister DID mailbox command is used to unregister an N_Port/F_Port
636 * login for an unknown RPI by specifying the DID of a remote port. This
637 * command frees an RPI context in the HBA port. This has the effect of
638 * performing an implicit N_Port/F_Port logout.
640 * This routine prepares the mailbox command for unregistering a remote
641 * N_Port/F_Port (DID) login.
644 lpfc_unreg_did(struct lpfc_hba
* phba
, uint16_t vpi
, uint32_t did
,
650 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
652 mb
->un
.varUnregDID
.did
= did
;
653 mb
->un
.varUnregDID
.vpi
= vpi
;
654 if ((vpi
!= 0xffff) &&
655 (phba
->sli_rev
== LPFC_SLI_REV4
))
656 mb
->un
.varUnregDID
.vpi
= phba
->vpi_ids
[vpi
];
658 mb
->mbxCommand
= MBX_UNREG_D_ID
;
659 mb
->mbxOwner
= OWN_HOST
;
664 * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
665 * @phba: pointer to lpfc hba data structure.
666 * @pmb: pointer to the driver internal queue element for mailbox command.
668 * The read configuration mailbox command is used to read the HBA port
669 * configuration parameters. This mailbox command provides a method for
670 * seeing any parameters that may have changed via various configuration
673 * This routine prepares the mailbox command for reading out HBA configuration
677 lpfc_read_config(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
682 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
684 mb
->mbxCommand
= MBX_READ_CONFIG
;
685 mb
->mbxOwner
= OWN_HOST
;
690 * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
691 * @phba: pointer to lpfc hba data structure.
692 * @pmb: pointer to the driver internal queue element for mailbox command.
694 * The read link status mailbox command is used to read the link status from
695 * the HBA. Link status includes all link-related error counters. These
696 * counters are maintained by the HBA and originated in the link hardware
697 * unit. Note that all of these counters wrap.
699 * This routine prepares the mailbox command for reading out HBA link status.
702 lpfc_read_lnk_stat(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
707 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
709 mb
->mbxCommand
= MBX_READ_LNK_STAT
;
710 mb
->mbxOwner
= OWN_HOST
;
715 * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
716 * @phba: pointer to lpfc hba data structure.
717 * @vpi: virtual N_Port identifier.
718 * @did: remote port identifier.
719 * @param: pointer to memory holding the server parameters.
720 * @pmb: pointer to the driver internal queue element for mailbox command.
721 * @rpi: the rpi to use in the registration (usually only used for SLI4.
723 * The registration login mailbox command is used to register an N_Port or
724 * F_Port login. This registration allows the HBA to cache the remote N_Port
725 * service parameters internally and thereby make the appropriate FC-2
726 * decisions. The remote port service parameters are handed off by the driver
727 * to the HBA using a descriptor entry that directly identifies a buffer in
728 * host memory. In exchange, the HBA returns an RPI identifier.
730 * This routine prepares the mailbox command for registering remote port login.
731 * The function allocates DMA buffer for passing the service parameters to the
732 * HBA with the mailbox command.
736 * 1 - DMA memory allocation failed
739 lpfc_reg_rpi(struct lpfc_hba
*phba
, uint16_t vpi
, uint32_t did
,
740 uint8_t *param
, LPFC_MBOXQ_t
*pmb
, uint16_t rpi
)
742 MAILBOX_t
*mb
= &pmb
->u
.mb
;
744 struct lpfc_dmabuf
*mp
;
746 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
748 mb
->un
.varRegLogin
.rpi
= 0;
749 if (phba
->sli_rev
== LPFC_SLI_REV4
)
750 mb
->un
.varRegLogin
.rpi
= phba
->sli4_hba
.rpi_ids
[rpi
];
751 if (phba
->sli_rev
>= LPFC_SLI_REV3
)
752 mb
->un
.varRegLogin
.vpi
= phba
->vpi_ids
[vpi
];
753 mb
->un
.varRegLogin
.did
= did
;
754 mb
->mbxOwner
= OWN_HOST
;
755 /* Get a buffer to hold NPorts Service Parameters */
756 mp
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
758 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
759 if (!mp
|| !mp
->virt
) {
761 mb
->mbxCommand
= MBX_REG_LOGIN64
;
762 /* REG_LOGIN: no buffers */
763 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
764 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
765 "rpi x%x\n", vpi
, did
, rpi
);
768 INIT_LIST_HEAD(&mp
->list
);
771 /* Copy param's into a new buffer */
772 memcpy(sparam
, param
, sizeof (struct serv_parm
));
774 /* save address for completion */
775 pmb
->context1
= (uint8_t *) mp
;
777 mb
->mbxCommand
= MBX_REG_LOGIN64
;
778 mb
->un
.varRegLogin
.un
.sp64
.tus
.f
.bdeSize
= sizeof (struct serv_parm
);
779 mb
->un
.varRegLogin
.un
.sp64
.addrHigh
= putPaddrHigh(mp
->phys
);
780 mb
->un
.varRegLogin
.un
.sp64
.addrLow
= putPaddrLow(mp
->phys
);
786 * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
787 * @phba: pointer to lpfc hba data structure.
788 * @vpi: virtual N_Port identifier.
789 * @rpi: remote port identifier
790 * @pmb: pointer to the driver internal queue element for mailbox command.
792 * The unregistration login mailbox command is used to unregister an N_Port
793 * or F_Port login. This command frees an RPI context in the HBA. It has the
794 * effect of performing an implicit N_Port/F_Port logout.
796 * This routine prepares the mailbox command for unregistering remote port
799 * For SLI4 ports, the rpi passed to this function must be the physical
800 * rpi value, not the logical index.
803 lpfc_unreg_login(struct lpfc_hba
*phba
, uint16_t vpi
, uint32_t rpi
,
809 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
811 mb
->un
.varUnregLogin
.rpi
= rpi
;
812 mb
->un
.varUnregLogin
.rsvd1
= 0;
813 if (phba
->sli_rev
>= LPFC_SLI_REV3
)
814 mb
->un
.varUnregLogin
.vpi
= phba
->vpi_ids
[vpi
];
816 mb
->mbxCommand
= MBX_UNREG_LOGIN
;
817 mb
->mbxOwner
= OWN_HOST
;
823 * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA.
824 * @vport: pointer to a vport object.
826 * This routine sends mailbox command to unregister all active RPIs for
830 lpfc_sli4_unreg_all_rpis(struct lpfc_vport
*vport
)
832 struct lpfc_hba
*phba
= vport
->phba
;
836 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
839 * For SLI4 functions, the rpi field is overloaded for
840 * the vport context unreg all. This routine passes
841 * 0 for the rpi field in lpfc_unreg_login for compatibility
842 * with SLI3 and then overrides the rpi field with the
843 * expected value for SLI4.
845 lpfc_unreg_login(phba
, vport
->vpi
, phba
->vpi_ids
[vport
->vpi
],
847 mbox
->u
.mb
.un
.varUnregLogin
.rsvd1
= 0x4000;
849 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
850 mbox
->context1
= NULL
;
851 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
852 if (rc
== MBX_NOT_FINISHED
)
853 mempool_free(mbox
, phba
->mbox_mem_pool
);
858 * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
859 * @phba: pointer to lpfc hba data structure.
860 * @vpi: virtual N_Port identifier.
861 * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
862 * @pmb: pointer to the driver internal queue element for mailbox command.
864 * The registration vport identifier mailbox command is used to activate a
865 * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
866 * N_Port_ID against the information in the selected virtual N_Port context
867 * block and marks it active to allow normal processing of IOCB commands and
868 * received unsolicited exchanges.
870 * This routine prepares the mailbox command for registering a virtual N_Port.
873 lpfc_reg_vpi(struct lpfc_vport
*vport
, LPFC_MBOXQ_t
*pmb
)
875 MAILBOX_t
*mb
= &pmb
->u
.mb
;
876 struct lpfc_hba
*phba
= vport
->phba
;
878 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
880 * Set the re-reg VPI bit for f/w to update the MAC address.
882 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
883 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
))
884 mb
->un
.varRegVpi
.upd
= 1;
886 mb
->un
.varRegVpi
.vpi
= phba
->vpi_ids
[vport
->vpi
];
887 mb
->un
.varRegVpi
.sid
= vport
->fc_myDID
;
888 if (phba
->sli_rev
== LPFC_SLI_REV4
)
889 mb
->un
.varRegVpi
.vfi
= phba
->sli4_hba
.vfi_ids
[vport
->vfi
];
891 mb
->un
.varRegVpi
.vfi
= vport
->vfi
+ vport
->phba
->vfi_base
;
892 memcpy(mb
->un
.varRegVpi
.wwn
, &vport
->fc_portname
,
893 sizeof(struct lpfc_name
));
894 mb
->un
.varRegVpi
.wwn
[0] = cpu_to_le32(mb
->un
.varRegVpi
.wwn
[0]);
895 mb
->un
.varRegVpi
.wwn
[1] = cpu_to_le32(mb
->un
.varRegVpi
.wwn
[1]);
897 mb
->mbxCommand
= MBX_REG_VPI
;
898 mb
->mbxOwner
= OWN_HOST
;
904 * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
905 * @phba: pointer to lpfc hba data structure.
906 * @vpi: virtual N_Port identifier.
907 * @pmb: pointer to the driver internal queue element for mailbox command.
909 * The unregistration vport identifier mailbox command is used to inactivate
910 * a virtual N_Port. The driver must have logged out and unregistered all
911 * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
912 * unregisters any default RPIs associated with the specified vpi, aborting
913 * any active exchanges. The HBA will post the mailbox response after making
914 * the virtual N_Port inactive.
916 * This routine prepares the mailbox command for unregistering a virtual
920 lpfc_unreg_vpi(struct lpfc_hba
*phba
, uint16_t vpi
, LPFC_MBOXQ_t
*pmb
)
922 MAILBOX_t
*mb
= &pmb
->u
.mb
;
923 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
925 if (phba
->sli_rev
== LPFC_SLI_REV3
)
926 mb
->un
.varUnregVpi
.vpi
= phba
->vpi_ids
[vpi
];
927 else if (phba
->sli_rev
>= LPFC_SLI_REV4
)
928 mb
->un
.varUnregVpi
.sli4_vpi
= phba
->vpi_ids
[vpi
];
930 mb
->mbxCommand
= MBX_UNREG_VPI
;
931 mb
->mbxOwner
= OWN_HOST
;
937 * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
938 * @phba: pointer to lpfc hba data structure.
940 * This routine sets up and initializes the IOCB rings in the Port Control
944 lpfc_config_pcb_setup(struct lpfc_hba
* phba
)
946 struct lpfc_sli
*psli
= &phba
->sli
;
947 struct lpfc_sli_ring
*pring
;
948 PCB_t
*pcbp
= phba
->pcb
;
949 dma_addr_t pdma_addr
;
951 uint32_t iocbCnt
= 0;
954 pcbp
->maxRing
= (psli
->num_rings
- 1);
956 for (i
= 0; i
< psli
->num_rings
; i
++) {
957 pring
= &psli
->ring
[i
];
959 pring
->sli
.sli3
.sizeCiocb
=
960 phba
->sli_rev
== 3 ? SLI3_IOCB_CMD_SIZE
:
962 pring
->sli
.sli3
.sizeRiocb
=
963 phba
->sli_rev
== 3 ? SLI3_IOCB_RSP_SIZE
:
965 /* A ring MUST have both cmd and rsp entries defined to be
967 if ((pring
->sli
.sli3
.numCiocb
== 0) ||
968 (pring
->sli
.sli3
.numRiocb
== 0)) {
969 pcbp
->rdsc
[i
].cmdEntries
= 0;
970 pcbp
->rdsc
[i
].rspEntries
= 0;
971 pcbp
->rdsc
[i
].cmdAddrHigh
= 0;
972 pcbp
->rdsc
[i
].rspAddrHigh
= 0;
973 pcbp
->rdsc
[i
].cmdAddrLow
= 0;
974 pcbp
->rdsc
[i
].rspAddrLow
= 0;
975 pring
->sli
.sli3
.cmdringaddr
= NULL
;
976 pring
->sli
.sli3
.rspringaddr
= NULL
;
979 /* Command ring setup for ring */
980 pring
->sli
.sli3
.cmdringaddr
= (void *)&phba
->IOCBs
[iocbCnt
];
981 pcbp
->rdsc
[i
].cmdEntries
= pring
->sli
.sli3
.numCiocb
;
983 offset
= (uint8_t *) &phba
->IOCBs
[iocbCnt
] -
984 (uint8_t *) phba
->slim2p
.virt
;
985 pdma_addr
= phba
->slim2p
.phys
+ offset
;
986 pcbp
->rdsc
[i
].cmdAddrHigh
= putPaddrHigh(pdma_addr
);
987 pcbp
->rdsc
[i
].cmdAddrLow
= putPaddrLow(pdma_addr
);
988 iocbCnt
+= pring
->sli
.sli3
.numCiocb
;
990 /* Response ring setup for ring */
991 pring
->sli
.sli3
.rspringaddr
= (void *) &phba
->IOCBs
[iocbCnt
];
993 pcbp
->rdsc
[i
].rspEntries
= pring
->sli
.sli3
.numRiocb
;
994 offset
= (uint8_t *)&phba
->IOCBs
[iocbCnt
] -
995 (uint8_t *)phba
->slim2p
.virt
;
996 pdma_addr
= phba
->slim2p
.phys
+ offset
;
997 pcbp
->rdsc
[i
].rspAddrHigh
= putPaddrHigh(pdma_addr
);
998 pcbp
->rdsc
[i
].rspAddrLow
= putPaddrLow(pdma_addr
);
999 iocbCnt
+= pring
->sli
.sli3
.numRiocb
;
1004 * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
1005 * @phba: pointer to lpfc hba data structure.
1006 * @pmb: pointer to the driver internal queue element for mailbox command.
1008 * The read revision mailbox command is used to read the revision levels of
1009 * the HBA components. These components include hardware units, resident
1010 * firmware, and available firmware. HBAs that supports SLI-3 mode of
1011 * operation provide different response information depending on the version
1012 * requested by the driver.
1014 * This routine prepares the mailbox command for reading HBA revision
1018 lpfc_read_rev(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
1020 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1021 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
1022 mb
->un
.varRdRev
.cv
= 1;
1023 mb
->un
.varRdRev
.v3req
= 1; /* Request SLI3 info */
1024 mb
->mbxCommand
= MBX_READ_REV
;
1025 mb
->mbxOwner
= OWN_HOST
;
1030 lpfc_sli4_swap_str(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1032 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1033 struct lpfc_mqe
*mqe
;
1035 switch (mb
->mbxCommand
) {
1038 lpfc_sli_pcimem_bcopy(mqe
->un
.read_rev
.fw_name
,
1039 mqe
->un
.read_rev
.fw_name
, 16);
1040 lpfc_sli_pcimem_bcopy(mqe
->un
.read_rev
.ulp_fw_name
,
1041 mqe
->un
.read_rev
.ulp_fw_name
, 16);
1050 * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
1051 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1052 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1054 * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
1055 * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
1056 * the Sequence Length Test using the fields in the Selection Profile 2
1057 * extension in words 20:31.
1060 lpfc_build_hbq_profile2(struct config_hbq_var
*hbqmb
,
1061 struct lpfc_hbq_init
*hbq_desc
)
1063 hbqmb
->profiles
.profile2
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
1064 hbqmb
->profiles
.profile2
.maxlen
= hbq_desc
->maxlen
;
1065 hbqmb
->profiles
.profile2
.seqlenoff
= hbq_desc
->seqlenoff
;
1069 * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
1070 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1071 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1073 * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
1074 * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
1075 * the Sequence Length Test and Byte Field Test using the fields in the
1076 * Selection Profile 3 extension in words 20:31.
1079 lpfc_build_hbq_profile3(struct config_hbq_var
*hbqmb
,
1080 struct lpfc_hbq_init
*hbq_desc
)
1082 hbqmb
->profiles
.profile3
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
1083 hbqmb
->profiles
.profile3
.maxlen
= hbq_desc
->maxlen
;
1084 hbqmb
->profiles
.profile3
.cmdcodeoff
= hbq_desc
->cmdcodeoff
;
1085 hbqmb
->profiles
.profile3
.seqlenoff
= hbq_desc
->seqlenoff
;
1086 memcpy(&hbqmb
->profiles
.profile3
.cmdmatch
, hbq_desc
->cmdmatch
,
1087 sizeof(hbqmb
->profiles
.profile3
.cmdmatch
));
1091 * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
1092 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1093 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1095 * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
1096 * HBA tests the initial frame of an incoming sequence using the frame's
1097 * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
1098 * and Byte Field Test using the fields in the Selection Profile 5 extension
1102 lpfc_build_hbq_profile5(struct config_hbq_var
*hbqmb
,
1103 struct lpfc_hbq_init
*hbq_desc
)
1105 hbqmb
->profiles
.profile5
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
1106 hbqmb
->profiles
.profile5
.maxlen
= hbq_desc
->maxlen
;
1107 hbqmb
->profiles
.profile5
.cmdcodeoff
= hbq_desc
->cmdcodeoff
;
1108 hbqmb
->profiles
.profile5
.seqlenoff
= hbq_desc
->seqlenoff
;
1109 memcpy(&hbqmb
->profiles
.profile5
.cmdmatch
, hbq_desc
->cmdmatch
,
1110 sizeof(hbqmb
->profiles
.profile5
.cmdmatch
));
1114 * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
1115 * @phba: pointer to lpfc hba data structure.
1116 * @id: HBQ identifier.
1117 * @hbq_desc: pointer to the HBA descriptor data structure.
1118 * @hbq_entry_index: index of the HBQ entry data structures.
1119 * @pmb: pointer to the driver internal queue element for mailbox command.
1121 * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
1122 * an HBQ. The configuration binds events that require buffers to a particular
1123 * ring and HBQ based on a selection profile.
1125 * This routine prepares the mailbox command for configuring an HBQ.
1128 lpfc_config_hbq(struct lpfc_hba
*phba
, uint32_t id
,
1129 struct lpfc_hbq_init
*hbq_desc
,
1130 uint32_t hbq_entry_index
, LPFC_MBOXQ_t
*pmb
)
1133 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1134 struct config_hbq_var
*hbqmb
= &mb
->un
.varCfgHbq
;
1136 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
1138 hbqmb
->entry_count
= hbq_desc
->entry_count
; /* # entries in HBQ */
1139 hbqmb
->recvNotify
= hbq_desc
->rn
; /* Receive
1141 hbqmb
->numMask
= hbq_desc
->mask_count
; /* # R_CTL/TYPE masks
1142 * # in words 0-19 */
1143 hbqmb
->profile
= hbq_desc
->profile
; /* Selection profile:
1146 hbqmb
->ringMask
= hbq_desc
->ring_mask
; /* Binds HBQ to a ring
1149 hbqmb
->headerLen
= hbq_desc
->headerLen
; /* 0 if not profile 4
1151 hbqmb
->logEntry
= hbq_desc
->logEntry
; /* Set to 1 if this
1155 hbqmb
->hbqaddrLow
= putPaddrLow(phba
->hbqslimp
.phys
) +
1156 hbq_entry_index
* sizeof(struct lpfc_hbq_entry
);
1157 hbqmb
->hbqaddrHigh
= putPaddrHigh(phba
->hbqslimp
.phys
);
1159 mb
->mbxCommand
= MBX_CONFIG_HBQ
;
1160 mb
->mbxOwner
= OWN_HOST
;
1162 /* Copy info for profiles 2,3,5. Other
1163 * profiles this area is reserved
1165 if (hbq_desc
->profile
== 2)
1166 lpfc_build_hbq_profile2(hbqmb
, hbq_desc
);
1167 else if (hbq_desc
->profile
== 3)
1168 lpfc_build_hbq_profile3(hbqmb
, hbq_desc
);
1169 else if (hbq_desc
->profile
== 5)
1170 lpfc_build_hbq_profile5(hbqmb
, hbq_desc
);
1172 /* Return if no rctl / type masks for this HBQ */
1173 if (!hbq_desc
->mask_count
)
1176 /* Otherwise we setup specific rctl / type masks for this HBQ */
1177 for (i
= 0; i
< hbq_desc
->mask_count
; i
++) {
1178 hbqmb
->hbqMasks
[i
].tmatch
= hbq_desc
->hbqMasks
[i
].tmatch
;
1179 hbqmb
->hbqMasks
[i
].tmask
= hbq_desc
->hbqMasks
[i
].tmask
;
1180 hbqmb
->hbqMasks
[i
].rctlmatch
= hbq_desc
->hbqMasks
[i
].rctlmatch
;
1181 hbqmb
->hbqMasks
[i
].rctlmask
= hbq_desc
->hbqMasks
[i
].rctlmask
;
1188 * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
1189 * @phba: pointer to lpfc hba data structure.
1191 * @pmb: pointer to the driver internal queue element for mailbox command.
1193 * The configure ring mailbox command is used to configure an IOCB ring. This
1194 * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1195 * ring. This is used to map incoming sequences to a particular ring whose
1196 * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1197 * attempt to configure a ring whose number is greater than the number
1198 * specified in the Port Control Block (PCB). It is an error to issue the
1199 * configure ring command more than once with the same ring number. The HBA
1200 * returns an error if the driver attempts this.
1202 * This routine prepares the mailbox command for configuring IOCB ring.
1205 lpfc_config_ring(struct lpfc_hba
* phba
, int ring
, LPFC_MBOXQ_t
* pmb
)
1208 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1209 struct lpfc_sli
*psli
;
1210 struct lpfc_sli_ring
*pring
;
1212 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
1214 mb
->un
.varCfgRing
.ring
= ring
;
1215 mb
->un
.varCfgRing
.maxOrigXchg
= 0;
1216 mb
->un
.varCfgRing
.maxRespXchg
= 0;
1217 mb
->un
.varCfgRing
.recvNotify
= 1;
1220 pring
= &psli
->ring
[ring
];
1221 mb
->un
.varCfgRing
.numMask
= pring
->num_mask
;
1222 mb
->mbxCommand
= MBX_CONFIG_RING
;
1223 mb
->mbxOwner
= OWN_HOST
;
1225 /* Is this ring configured for a specific profile */
1226 if (pring
->prt
[0].profile
) {
1227 mb
->un
.varCfgRing
.profile
= pring
->prt
[0].profile
;
1231 /* Otherwise we setup specific rctl / type masks for this ring */
1232 for (i
= 0; i
< pring
->num_mask
; i
++) {
1233 mb
->un
.varCfgRing
.rrRegs
[i
].rval
= pring
->prt
[i
].rctl
;
1234 if (mb
->un
.varCfgRing
.rrRegs
[i
].rval
!= FC_RCTL_ELS_REQ
)
1235 mb
->un
.varCfgRing
.rrRegs
[i
].rmask
= 0xff;
1237 mb
->un
.varCfgRing
.rrRegs
[i
].rmask
= 0xfe;
1238 mb
->un
.varCfgRing
.rrRegs
[i
].tval
= pring
->prt
[i
].type
;
1239 mb
->un
.varCfgRing
.rrRegs
[i
].tmask
= 0xff;
1246 * lpfc_config_port - Prepare a mailbox command for configuring port
1247 * @phba: pointer to lpfc hba data structure.
1248 * @pmb: pointer to the driver internal queue element for mailbox command.
1250 * The configure port mailbox command is used to identify the Port Control
1251 * Block (PCB) in the driver memory. After this command is issued, the
1252 * driver must not access the mailbox in the HBA without first resetting
1253 * the HBA. The HBA may copy the PCB information to internal storage for
1254 * subsequent use; the driver can not change the PCB information unless it
1257 * This routine prepares the mailbox command for configuring port.
1260 lpfc_config_port(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1262 MAILBOX_t __iomem
*mb_slim
= (MAILBOX_t __iomem
*) phba
->MBslimaddr
;
1263 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1264 dma_addr_t pdma_addr
;
1265 uint32_t bar_low
, bar_high
;
1267 struct lpfc_hgp hgp
;
1269 uint32_t pgp_offset
;
1271 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
1272 mb
->mbxCommand
= MBX_CONFIG_PORT
;
1273 mb
->mbxOwner
= OWN_HOST
;
1275 mb
->un
.varCfgPort
.pcbLen
= sizeof(PCB_t
);
1277 offset
= (uint8_t *)phba
->pcb
- (uint8_t *)phba
->slim2p
.virt
;
1278 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1279 mb
->un
.varCfgPort
.pcbLow
= putPaddrLow(pdma_addr
);
1280 mb
->un
.varCfgPort
.pcbHigh
= putPaddrHigh(pdma_addr
);
1282 /* Always Host Group Pointer is in SLIM */
1283 mb
->un
.varCfgPort
.hps
= 1;
1285 /* If HBA supports SLI=3 ask for it */
1287 if (phba
->sli_rev
== LPFC_SLI_REV3
&& phba
->vpd
.sli3Feat
.cerbm
) {
1288 if (phba
->cfg_enable_bg
)
1289 mb
->un
.varCfgPort
.cbg
= 1; /* configure BlockGuard */
1290 if (phba
->cfg_enable_dss
)
1291 mb
->un
.varCfgPort
.cdss
= 1; /* Configure Security */
1292 mb
->un
.varCfgPort
.cerbm
= 1; /* Request HBQs */
1293 mb
->un
.varCfgPort
.ccrp
= 1; /* Command Ring Polling */
1294 mb
->un
.varCfgPort
.max_hbq
= lpfc_sli_hbq_count();
1295 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
1296 phba
->vpd
.sli3Feat
.cmv
) {
1297 mb
->un
.varCfgPort
.max_vpi
= LPFC_MAX_VPI
;
1298 mb
->un
.varCfgPort
.cmv
= 1;
1300 mb
->un
.varCfgPort
.max_vpi
= phba
->max_vpi
= 0;
1302 phba
->sli_rev
= LPFC_SLI_REV2
;
1303 mb
->un
.varCfgPort
.sli_mode
= phba
->sli_rev
;
1305 /* If this is an SLI3 port, configure async status notification. */
1306 if (phba
->sli_rev
== LPFC_SLI_REV3
)
1307 mb
->un
.varCfgPort
.casabt
= 1;
1310 phba
->pcb
->type
= TYPE_NATIVE_SLI2
;
1311 phba
->pcb
->feature
= FEATURE_INITIAL_SLI2
;
1313 /* Setup Mailbox pointers */
1314 phba
->pcb
->mailBoxSize
= sizeof(MAILBOX_t
) + MAILBOX_EXT_SIZE
;
1315 offset
= (uint8_t *)phba
->mbox
- (uint8_t *)phba
->slim2p
.virt
;
1316 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1317 phba
->pcb
->mbAddrHigh
= putPaddrHigh(pdma_addr
);
1318 phba
->pcb
->mbAddrLow
= putPaddrLow(pdma_addr
);
1321 * Setup Host Group ring pointer.
1323 * For efficiency reasons, the ring get/put pointers can be
1324 * placed in adapter memory (SLIM) rather than in host memory.
1325 * This allows firmware to avoid PCI reads/writes when updating
1326 * and checking pointers.
1328 * The firmware recognizes the use of SLIM memory by comparing
1329 * the address of the get/put pointers structure with that of
1330 * the SLIM BAR (BAR0).
1332 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1333 * (the hardware's view of the base address), not the OS's
1334 * value of pci_resource_start() as the OS value may be a cookie
1335 * for ioremap/iomap.
1339 pci_read_config_dword(phba
->pcidev
, PCI_BASE_ADDRESS_0
, &bar_low
);
1340 pci_read_config_dword(phba
->pcidev
, PCI_BASE_ADDRESS_1
, &bar_high
);
1343 * Set up HGP - Port Memory
1345 * The port expects the host get/put pointers to reside in memory
1346 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1347 * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
1348 * words (0x40 bytes). This area is not reserved if HBQs are
1349 * configured in SLI-3.
1351 * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1360 * Reserved 0xa0-0xbf
1361 * If HBQs configured:
1362 * HBQ 0 Put ptr 0xc0
1363 * HBQ 1 Put ptr 0xc4
1364 * HBQ 2 Put ptr 0xc8
1366 * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1370 if (phba
->cfg_hostmem_hgp
&& phba
->sli_rev
!= 3) {
1371 phba
->host_gp
= &phba
->mbox
->us
.s2
.host
[0];
1372 phba
->hbq_put
= NULL
;
1373 offset
= (uint8_t *)&phba
->mbox
->us
.s2
.host
-
1374 (uint8_t *)phba
->slim2p
.virt
;
1375 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1376 phba
->pcb
->hgpAddrHigh
= putPaddrHigh(pdma_addr
);
1377 phba
->pcb
->hgpAddrLow
= putPaddrLow(pdma_addr
);
1379 /* Always Host Group Pointer is in SLIM */
1380 mb
->un
.varCfgPort
.hps
= 1;
1382 if (phba
->sli_rev
== 3) {
1383 phba
->host_gp
= &mb_slim
->us
.s3
.host
[0];
1384 phba
->hbq_put
= &mb_slim
->us
.s3
.hbq_put
[0];
1386 phba
->host_gp
= &mb_slim
->us
.s2
.host
[0];
1387 phba
->hbq_put
= NULL
;
1390 /* mask off BAR0's flag bits 0 - 3 */
1391 phba
->pcb
->hgpAddrLow
= (bar_low
& PCI_BASE_ADDRESS_MEM_MASK
) +
1392 (void __iomem
*)phba
->host_gp
-
1393 (void __iomem
*)phba
->MBslimaddr
;
1394 if (bar_low
& PCI_BASE_ADDRESS_MEM_TYPE_64
)
1395 phba
->pcb
->hgpAddrHigh
= bar_high
;
1397 phba
->pcb
->hgpAddrHigh
= 0;
1398 /* write HGP data to SLIM at the required longword offset */
1399 memset(&hgp
, 0, sizeof(struct lpfc_hgp
));
1401 for (i
= 0; i
< phba
->sli
.num_rings
; i
++) {
1402 lpfc_memcpy_to_slim(phba
->host_gp
+ i
, &hgp
,
1403 sizeof(*phba
->host_gp
));
1407 /* Setup Port Group offset */
1408 if (phba
->sli_rev
== 3)
1409 pgp_offset
= offsetof(struct lpfc_sli2_slim
,
1410 mbx
.us
.s3_pgp
.port
);
1412 pgp_offset
= offsetof(struct lpfc_sli2_slim
, mbx
.us
.s2
.port
);
1413 pdma_addr
= phba
->slim2p
.phys
+ pgp_offset
;
1414 phba
->pcb
->pgpAddrHigh
= putPaddrHigh(pdma_addr
);
1415 phba
->pcb
->pgpAddrLow
= putPaddrLow(pdma_addr
);
1417 /* Use callback routine to setp rings in the pcb */
1418 lpfc_config_pcb_setup(phba
);
1420 /* special handling for LC HBAs */
1421 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
1422 uint32_t hbainit
[5];
1424 lpfc_hba_init(phba
, hbainit
);
1426 memcpy(&mb
->un
.varCfgPort
.hbainit
, hbainit
, 20);
1429 /* Swap PCB if needed */
1430 lpfc_sli_pcimem_bcopy(phba
->pcb
, phba
->pcb
, sizeof(PCB_t
));
1434 * lpfc_kill_board - Prepare a mailbox command for killing board
1435 * @phba: pointer to lpfc hba data structure.
1436 * @pmb: pointer to the driver internal queue element for mailbox command.
1438 * The kill board mailbox command is used to tell firmware to perform a
1439 * graceful shutdown of a channel on a specified board to prepare for reset.
1440 * When the kill board mailbox command is received, the ER3 bit is set to 1
1441 * in the Host Status register and the ER Attention bit is set to 1 in the
1442 * Host Attention register of the HBA function that received the kill board
1445 * This routine prepares the mailbox command for killing the board in
1446 * preparation for a graceful shutdown.
1449 lpfc_kill_board(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
1451 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1453 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
1454 mb
->mbxCommand
= MBX_KILL_BOARD
;
1455 mb
->mbxOwner
= OWN_HOST
;
1460 * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
1461 * @phba: pointer to lpfc hba data structure.
1462 * @mbq: pointer to the driver internal queue element for mailbox command.
1464 * Driver maintains a internal mailbox command queue implemented as a linked
1465 * list. When a mailbox command is issued, it shall be put into the mailbox
1466 * command queue such that they shall be processed orderly as HBA can process
1467 * one mailbox command at a time.
1470 lpfc_mbox_put(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* mbq
)
1472 struct lpfc_sli
*psli
;
1476 list_add_tail(&mbq
->list
, &psli
->mboxq
);
1484 * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
1485 * @phba: pointer to lpfc hba data structure.
1487 * Driver maintains a internal mailbox command queue implemented as a linked
1488 * list. When a mailbox command is issued, it shall be put into the mailbox
1489 * command queue such that they shall be processed orderly as HBA can process
1490 * one mailbox command at a time. After HBA finished processing a mailbox
1491 * command, the driver will remove a pending mailbox command from the head of
1492 * the mailbox command queue and send to the HBA for processing.
1495 * pointer to the driver internal queue element for mailbox command.
1498 lpfc_mbox_get(struct lpfc_hba
* phba
)
1500 LPFC_MBOXQ_t
*mbq
= NULL
;
1501 struct lpfc_sli
*psli
= &phba
->sli
;
1503 list_remove_head((&psli
->mboxq
), mbq
, LPFC_MBOXQ_t
, list
);
1511 * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
1512 * @phba: pointer to lpfc hba data structure.
1513 * @mbq: pointer to the driver internal queue element for mailbox command.
1515 * This routine put the completed mailbox command into the mailbox command
1516 * complete list. This is the unlocked version of the routine. The mailbox
1517 * complete list is used by the driver worker thread to process mailbox
1518 * complete callback functions outside the driver interrupt handler.
1521 __lpfc_mbox_cmpl_put(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbq
)
1523 list_add_tail(&mbq
->list
, &phba
->sli
.mboxq_cmpl
);
1527 * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
1528 * @phba: pointer to lpfc hba data structure.
1529 * @mbq: pointer to the driver internal queue element for mailbox command.
1531 * This routine put the completed mailbox command into the mailbox command
1532 * complete list. This is the locked version of the routine. The mailbox
1533 * complete list is used by the driver worker thread to process mailbox
1534 * complete callback functions outside the driver interrupt handler.
1537 lpfc_mbox_cmpl_put(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbq
)
1539 unsigned long iflag
;
1541 /* This function expects to be called from interrupt context */
1542 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1543 __lpfc_mbox_cmpl_put(phba
, mbq
);
1544 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1549 * lpfc_mbox_cmd_check - Check the validality of a mailbox command
1550 * @phba: pointer to lpfc hba data structure.
1551 * @mboxq: pointer to the driver internal queue element for mailbox command.
1553 * This routine is to check whether a mailbox command is valid to be issued.
1554 * This check will be performed by both the mailbox issue API when a client
1555 * is to issue a mailbox command to the mailbox transport.
1557 * Return 0 - pass the check, -ENODEV - fail the check
1560 lpfc_mbox_cmd_check(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1562 /* Mailbox command that have a completion handler must also have a
1565 if (mboxq
->mbox_cmpl
&& mboxq
->mbox_cmpl
!= lpfc_sli_def_mbox_cmpl
&&
1566 mboxq
->mbox_cmpl
!= lpfc_sli_wake_mbox_wait
) {
1567 if (!mboxq
->vport
) {
1568 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
1569 "1814 Mbox x%x failed, no vport\n",
1570 mboxq
->u
.mb
.mbxCommand
);
1579 * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
1580 * @phba: pointer to lpfc hba data structure.
1582 * This routine is to check whether the HBA device is ready for posting a
1583 * mailbox command. It is used by the mailbox transport API at the time the
1584 * to post a mailbox command to the device.
1586 * Return 0 - pass the check, -ENODEV - fail the check
1589 lpfc_mbox_dev_check(struct lpfc_hba
*phba
)
1591 /* If the PCI channel is in offline state, do not issue mbox */
1592 if (unlikely(pci_channel_offline(phba
->pcidev
)))
1595 /* If the HBA is in error state, do not issue mbox */
1596 if (phba
->link_state
== LPFC_HBA_ERROR
)
1603 * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
1604 * @phba: pointer to lpfc hba data structure.
1605 * @cmd: mailbox command code.
1607 * This routine retrieves the proper timeout value according to the mailbox
1611 * Timeout value to be used for the given mailbox command
1614 lpfc_mbox_tmo_val(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
1616 MAILBOX_t
*mbox
= &mboxq
->u
.mb
;
1617 uint8_t subsys
, opcode
;
1619 switch (mbox
->mbxCommand
) {
1620 case MBX_WRITE_NV
: /* 0x03 */
1621 case MBX_DUMP_MEMORY
: /* 0x17 */
1622 case MBX_UPDATE_CFG
: /* 0x1B */
1623 case MBX_DOWN_LOAD
: /* 0x1C */
1624 case MBX_DEL_LD_ENTRY
: /* 0x1D */
1625 case MBX_WRITE_VPARMS
: /* 0x32 */
1626 case MBX_LOAD_AREA
: /* 0x81 */
1627 case MBX_WRITE_WWN
: /* 0x98 */
1628 case MBX_LOAD_EXP_ROM
: /* 0x9C */
1629 case MBX_ACCESS_VDATA
: /* 0xA5 */
1630 return LPFC_MBOX_TMO_FLASH_CMD
;
1631 case MBX_SLI4_CONFIG
: /* 0x9b */
1632 subsys
= lpfc_sli_config_mbox_subsys_get(phba
, mboxq
);
1633 opcode
= lpfc_sli_config_mbox_opcode_get(phba
, mboxq
);
1634 if (subsys
== LPFC_MBOX_SUBSYSTEM_COMMON
) {
1636 case LPFC_MBOX_OPCODE_READ_OBJECT
:
1637 case LPFC_MBOX_OPCODE_WRITE_OBJECT
:
1638 case LPFC_MBOX_OPCODE_READ_OBJECT_LIST
:
1639 case LPFC_MBOX_OPCODE_DELETE_OBJECT
:
1640 case LPFC_MBOX_OPCODE_GET_PROFILE_LIST
:
1641 case LPFC_MBOX_OPCODE_SET_ACT_PROFILE
:
1642 case LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG
:
1643 case LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG
:
1644 case LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG
:
1645 case LPFC_MBOX_OPCODE_GET_PROFILE_CAPACITIES
:
1646 case LPFC_MBOX_OPCODE_SEND_ACTIVATION
:
1647 case LPFC_MBOX_OPCODE_RESET_LICENSES
:
1648 case LPFC_MBOX_OPCODE_SET_BOOT_CONFIG
:
1649 case LPFC_MBOX_OPCODE_GET_VPD_DATA
:
1650 case LPFC_MBOX_OPCODE_SET_PHYSICAL_LINK_CONFIG
:
1651 return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO
;
1654 if (subsys
== LPFC_MBOX_SUBSYSTEM_FCOE
) {
1656 case LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS
:
1657 return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO
;
1660 return LPFC_MBOX_SLI4_CONFIG_TMO
;
1662 return LPFC_MBOX_TMO
;
1666 * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
1667 * @mbox: pointer to lpfc mbox command.
1668 * @sgentry: sge entry index.
1669 * @phyaddr: physical address for the sge
1670 * @length: Length of the sge.
1672 * This routine sets up an entry in the non-embedded mailbox command at the sge
1676 lpfc_sli4_mbx_sge_set(struct lpfcMboxq
*mbox
, uint32_t sgentry
,
1677 dma_addr_t phyaddr
, uint32_t length
)
1679 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
1681 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
1682 &mbox
->u
.mqe
.un
.nembed_cmd
;
1683 nembed_sge
->sge
[sgentry
].pa_lo
= putPaddrLow(phyaddr
);
1684 nembed_sge
->sge
[sgentry
].pa_hi
= putPaddrHigh(phyaddr
);
1685 nembed_sge
->sge
[sgentry
].length
= length
;
1689 * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
1690 * @mbox: pointer to lpfc mbox command.
1691 * @sgentry: sge entry index.
1693 * This routine gets an entry from the non-embedded mailbox command at the sge
1697 lpfc_sli4_mbx_sge_get(struct lpfcMboxq
*mbox
, uint32_t sgentry
,
1698 struct lpfc_mbx_sge
*sge
)
1700 struct lpfc_mbx_nembed_cmd
*nembed_sge
;
1702 nembed_sge
= (struct lpfc_mbx_nembed_cmd
*)
1703 &mbox
->u
.mqe
.un
.nembed_cmd
;
1704 sge
->pa_lo
= nembed_sge
->sge
[sgentry
].pa_lo
;
1705 sge
->pa_hi
= nembed_sge
->sge
[sgentry
].pa_hi
;
1706 sge
->length
= nembed_sge
->sge
[sgentry
].length
;
1710 * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
1711 * @phba: pointer to lpfc hba data structure.
1712 * @mbox: pointer to lpfc mbox command.
1714 * This routine frees SLI4 specific mailbox command for sending IOCTL command.
1717 lpfc_sli4_mbox_cmd_free(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
1719 struct lpfc_mbx_sli4_config
*sli4_cfg
;
1720 struct lpfc_mbx_sge sge
;
1722 uint32_t sgecount
, sgentry
;
1724 sli4_cfg
= &mbox
->u
.mqe
.un
.sli4_config
;
1726 /* For embedded mbox command, just free the mbox command */
1727 if (bf_get(lpfc_mbox_hdr_emb
, &sli4_cfg
->header
.cfg_mhdr
)) {
1728 mempool_free(mbox
, phba
->mbox_mem_pool
);
1732 /* For non-embedded mbox command, we need to free the pages first */
1733 sgecount
= bf_get(lpfc_mbox_hdr_sge_cnt
, &sli4_cfg
->header
.cfg_mhdr
);
1734 /* There is nothing we can do if there is no sge address array */
1735 if (unlikely(!mbox
->sge_array
)) {
1736 mempool_free(mbox
, phba
->mbox_mem_pool
);
1739 /* Each non-embedded DMA memory was allocated in the length of a page */
1740 for (sgentry
= 0; sgentry
< sgecount
; sgentry
++) {
1741 lpfc_sli4_mbx_sge_get(mbox
, sgentry
, &sge
);
1742 phyaddr
= getPaddr(sge
.pa_hi
, sge
.pa_lo
);
1743 dma_free_coherent(&phba
->pcidev
->dev
, SLI4_PAGE_SIZE
,
1744 mbox
->sge_array
->addr
[sgentry
], phyaddr
);
1746 /* Free the sge address array memory */
1747 kfree(mbox
->sge_array
);
1748 /* Finally, free the mailbox command itself */
1749 mempool_free(mbox
, phba
->mbox_mem_pool
);
1753 * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command
1754 * @phba: pointer to lpfc hba data structure.
1755 * @mbox: pointer to lpfc mbox command.
1756 * @subsystem: The sli4 config sub mailbox subsystem.
1757 * @opcode: The sli4 config sub mailbox command opcode.
1758 * @length: Length of the sli4 config mailbox command (including sub-header).
1760 * This routine sets up the header fields of SLI4 specific mailbox command
1761 * for sending IOCTL command.
1763 * Return: the actual length of the mbox command allocated (mostly useful
1764 * for none embedded mailbox command).
1767 lpfc_sli4_config(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
,
1768 uint8_t subsystem
, uint8_t opcode
, uint32_t length
, bool emb
)
1770 struct lpfc_mbx_sli4_config
*sli4_config
;
1771 union lpfc_sli4_cfg_shdr
*cfg_shdr
= NULL
;
1774 uint32_t pagen
, pcount
;
1778 /* Set up SLI4 mailbox command header fields */
1779 memset(mbox
, 0, sizeof(*mbox
));
1780 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_SLI4_CONFIG
);
1782 /* Set up SLI4 ioctl command header fields */
1783 sli4_config
= &mbox
->u
.mqe
.un
.sli4_config
;
1785 /* Setup for the embedded mbox command */
1787 /* Set up main header fields */
1788 bf_set(lpfc_mbox_hdr_emb
, &sli4_config
->header
.cfg_mhdr
, 1);
1789 sli4_config
->header
.cfg_mhdr
.payload_length
= length
;
1790 /* Set up sub-header fields following main header */
1791 bf_set(lpfc_mbox_hdr_opcode
,
1792 &sli4_config
->header
.cfg_shdr
.request
, opcode
);
1793 bf_set(lpfc_mbox_hdr_subsystem
,
1794 &sli4_config
->header
.cfg_shdr
.request
, subsystem
);
1795 sli4_config
->header
.cfg_shdr
.request
.request_length
=
1796 length
- LPFC_MBX_CMD_HDR_LENGTH
;
1800 /* Setup for the non-embedded mbox command */
1801 pcount
= (SLI4_PAGE_ALIGN(length
))/SLI4_PAGE_SIZE
;
1802 pcount
= (pcount
> LPFC_SLI4_MBX_SGE_MAX_PAGES
) ?
1803 LPFC_SLI4_MBX_SGE_MAX_PAGES
: pcount
;
1804 /* Allocate record for keeping SGE virtual addresses */
1805 mbox
->sge_array
= kzalloc(sizeof(struct lpfc_mbx_nembed_sge_virt
),
1807 if (!mbox
->sge_array
) {
1808 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1809 "2527 Failed to allocate non-embedded SGE "
1813 for (pagen
= 0, alloc_len
= 0; pagen
< pcount
; pagen
++) {
1814 /* The DMA memory is always allocated in the length of a
1815 * page even though the last SGE might not fill up to a
1816 * page, this is used as a priori size of SLI4_PAGE_SIZE for
1817 * the later DMA memory free.
1819 viraddr
= dma_zalloc_coherent(&phba
->pcidev
->dev
,
1820 SLI4_PAGE_SIZE
, &phyaddr
,
1822 /* In case of malloc fails, proceed with whatever we have */
1825 mbox
->sge_array
->addr
[pagen
] = viraddr
;
1826 /* Keep the first page for later sub-header construction */
1828 cfg_shdr
= (union lpfc_sli4_cfg_shdr
*)viraddr
;
1829 resid_len
= length
- alloc_len
;
1830 if (resid_len
> SLI4_PAGE_SIZE
) {
1831 lpfc_sli4_mbx_sge_set(mbox
, pagen
, phyaddr
,
1833 alloc_len
+= SLI4_PAGE_SIZE
;
1835 lpfc_sli4_mbx_sge_set(mbox
, pagen
, phyaddr
,
1841 /* Set up main header fields in mailbox command */
1842 sli4_config
->header
.cfg_mhdr
.payload_length
= alloc_len
;
1843 bf_set(lpfc_mbox_hdr_sge_cnt
, &sli4_config
->header
.cfg_mhdr
, pagen
);
1845 /* Set up sub-header fields into the first page */
1847 bf_set(lpfc_mbox_hdr_opcode
, &cfg_shdr
->request
, opcode
);
1848 bf_set(lpfc_mbox_hdr_subsystem
, &cfg_shdr
->request
, subsystem
);
1849 cfg_shdr
->request
.request_length
=
1850 alloc_len
- sizeof(union lpfc_sli4_cfg_shdr
);
1852 /* The sub-header is in DMA memory, which needs endian converstion */
1854 lpfc_sli_pcimem_bcopy(cfg_shdr
, cfg_shdr
,
1855 sizeof(union lpfc_sli4_cfg_shdr
));
1860 * lpfc_sli4_mbox_rsrc_extent - Initialize the opcode resource extent.
1861 * @phba: pointer to lpfc hba data structure.
1862 * @mbox: pointer to an allocated lpfc mbox resource.
1863 * @exts_count: the number of extents, if required, to allocate.
1864 * @rsrc_type: the resource extent type.
1865 * @emb: true if LPFC_SLI4_MBX_EMBED. false if LPFC_SLI4_MBX_NEMBED.
1867 * This routine completes the subcommand header for SLI4 resource extent
1868 * mailbox commands. It is called after lpfc_sli4_config. The caller must
1869 * pass an allocated mailbox and the attributes required to initialize the
1870 * mailbox correctly.
1872 * Return: the actual length of the mbox command allocated.
1875 lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
,
1876 uint16_t exts_count
, uint16_t rsrc_type
, bool emb
)
1879 struct lpfc_mbx_nembed_rsrc_extent
*n_rsrc_extnt
= NULL
;
1880 void *virtaddr
= NULL
;
1882 /* Set up SLI4 ioctl command header fields */
1883 if (emb
== LPFC_SLI4_MBX_NEMBED
) {
1884 /* Get the first SGE entry from the non-embedded DMA memory */
1885 virtaddr
= mbox
->sge_array
->addr
[0];
1886 if (virtaddr
== NULL
)
1888 n_rsrc_extnt
= (struct lpfc_mbx_nembed_rsrc_extent
*) virtaddr
;
1892 * The resource type is common to all extent Opcodes and resides in the
1895 if (emb
== LPFC_SLI4_MBX_EMBED
)
1896 bf_set(lpfc_mbx_alloc_rsrc_extents_type
,
1897 &mbox
->u
.mqe
.un
.alloc_rsrc_extents
.u
.req
,
1900 /* This is DMA data. Byteswap is required. */
1901 bf_set(lpfc_mbx_alloc_rsrc_extents_type
,
1902 n_rsrc_extnt
, rsrc_type
);
1903 lpfc_sli_pcimem_bcopy(&n_rsrc_extnt
->word4
,
1904 &n_rsrc_extnt
->word4
,
1908 /* Complete the initialization for the particular Opcode. */
1909 opcode
= lpfc_sli_config_mbox_opcode_get(phba
, mbox
);
1911 case LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT
:
1912 if (emb
== LPFC_SLI4_MBX_EMBED
)
1913 bf_set(lpfc_mbx_alloc_rsrc_extents_cnt
,
1914 &mbox
->u
.mqe
.un
.alloc_rsrc_extents
.u
.req
,
1917 bf_set(lpfc_mbx_alloc_rsrc_extents_cnt
,
1918 n_rsrc_extnt
, exts_count
);
1920 case LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT
:
1921 case LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO
:
1922 case LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT
:
1923 /* Initialization is complete.*/
1926 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
1927 "2929 Resource Extent Opcode x%x is "
1928 "unsupported\n", opcode
);
1936 * lpfc_sli_config_mbox_subsys_get - Get subsystem from a sli_config mbox cmd
1937 * @phba: pointer to lpfc hba data structure.
1938 * @mbox: pointer to lpfc mbox command queue entry.
1940 * This routine gets the subsystem from a SLI4 specific SLI_CONFIG mailbox
1941 * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if the
1942 * sub-header is not present, subsystem LPFC_MBOX_SUBSYSTEM_NA (0x0) shall
1946 lpfc_sli_config_mbox_subsys_get(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
1948 struct lpfc_mbx_sli4_config
*sli4_cfg
;
1949 union lpfc_sli4_cfg_shdr
*cfg_shdr
;
1951 if (mbox
->u
.mb
.mbxCommand
!= MBX_SLI4_CONFIG
)
1952 return LPFC_MBOX_SUBSYSTEM_NA
;
1953 sli4_cfg
= &mbox
->u
.mqe
.un
.sli4_config
;
1955 /* For embedded mbox command, get opcode from embedded sub-header*/
1956 if (bf_get(lpfc_mbox_hdr_emb
, &sli4_cfg
->header
.cfg_mhdr
)) {
1957 cfg_shdr
= &mbox
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
1958 return bf_get(lpfc_mbox_hdr_subsystem
, &cfg_shdr
->request
);
1961 /* For non-embedded mbox command, get opcode from first dma page */
1962 if (unlikely(!mbox
->sge_array
))
1963 return LPFC_MBOX_SUBSYSTEM_NA
;
1964 cfg_shdr
= (union lpfc_sli4_cfg_shdr
*)mbox
->sge_array
->addr
[0];
1965 return bf_get(lpfc_mbox_hdr_subsystem
, &cfg_shdr
->request
);
1969 * lpfc_sli_config_mbox_opcode_get - Get opcode from a sli_config mbox cmd
1970 * @phba: pointer to lpfc hba data structure.
1971 * @mbox: pointer to lpfc mbox command queue entry.
1973 * This routine gets the opcode from a SLI4 specific SLI_CONFIG mailbox
1974 * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if
1975 * the sub-header is not present, opcode LPFC_MBOX_OPCODE_NA (0x0) be
1979 lpfc_sli_config_mbox_opcode_get(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
1981 struct lpfc_mbx_sli4_config
*sli4_cfg
;
1982 union lpfc_sli4_cfg_shdr
*cfg_shdr
;
1984 if (mbox
->u
.mb
.mbxCommand
!= MBX_SLI4_CONFIG
)
1985 return LPFC_MBOX_OPCODE_NA
;
1986 sli4_cfg
= &mbox
->u
.mqe
.un
.sli4_config
;
1988 /* For embedded mbox command, get opcode from embedded sub-header*/
1989 if (bf_get(lpfc_mbox_hdr_emb
, &sli4_cfg
->header
.cfg_mhdr
)) {
1990 cfg_shdr
= &mbox
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
1991 return bf_get(lpfc_mbox_hdr_opcode
, &cfg_shdr
->request
);
1994 /* For non-embedded mbox command, get opcode from first dma page */
1995 if (unlikely(!mbox
->sge_array
))
1996 return LPFC_MBOX_OPCODE_NA
;
1997 cfg_shdr
= (union lpfc_sli4_cfg_shdr
*)mbox
->sge_array
->addr
[0];
1998 return bf_get(lpfc_mbox_hdr_opcode
, &cfg_shdr
->request
);
2002 * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd
2003 * @phba: pointer to lpfc hba data structure.
2004 * @fcf_index: index to fcf table.
2006 * This routine routine allocates and constructs non-embedded mailbox command
2007 * for reading a FCF table entry referred by @fcf_index.
2009 * Return: pointer to the mailbox command constructed if successful, otherwise
2013 lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba
*phba
,
2014 struct lpfcMboxq
*mboxq
,
2019 struct lpfc_mbx_sge sge
;
2020 uint32_t alloc_len
, req_len
;
2021 struct lpfc_mbx_read_fcf_tbl
*read_fcf
;
2026 req_len
= sizeof(struct fcf_record
) +
2027 sizeof(union lpfc_sli4_cfg_shdr
) + 2 * sizeof(uint32_t);
2029 /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
2030 alloc_len
= lpfc_sli4_config(phba
, mboxq
, LPFC_MBOX_SUBSYSTEM_FCOE
,
2031 LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE
, req_len
,
2032 LPFC_SLI4_MBX_NEMBED
);
2034 if (alloc_len
< req_len
) {
2035 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
2036 "0291 Allocated DMA memory size (x%x) is "
2037 "less than the requested DMA memory "
2038 "size (x%x)\n", alloc_len
, req_len
);
2042 /* Get the first SGE entry from the non-embedded DMA memory. This
2043 * routine only uses a single SGE.
2045 lpfc_sli4_mbx_sge_get(mboxq
, 0, &sge
);
2046 virt_addr
= mboxq
->sge_array
->addr
[0];
2047 read_fcf
= (struct lpfc_mbx_read_fcf_tbl
*)virt_addr
;
2049 /* Set up command fields */
2050 bf_set(lpfc_mbx_read_fcf_tbl_indx
, &read_fcf
->u
.request
, fcf_index
);
2051 /* Perform necessary endian conversion */
2052 bytep
= virt_addr
+ sizeof(union lpfc_sli4_cfg_shdr
);
2053 lpfc_sli_pcimem_bcopy(bytep
, bytep
, sizeof(uint32_t));
2059 * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
2060 * @mboxq: pointer to lpfc mbox command.
2062 * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
2066 lpfc_request_features(struct lpfc_hba
*phba
, struct lpfcMboxq
*mboxq
)
2068 /* Set up SLI4 mailbox command header fields */
2069 memset(mboxq
, 0, sizeof(LPFC_MBOXQ_t
));
2070 bf_set(lpfc_mqe_command
, &mboxq
->u
.mqe
, MBX_SLI4_REQ_FTRS
);
2072 /* Set up host requested features. */
2073 bf_set(lpfc_mbx_rq_ftr_rq_fcpi
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
2074 bf_set(lpfc_mbx_rq_ftr_rq_perfh
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
2076 /* Enable DIF (block guard) only if configured to do so. */
2077 if (phba
->cfg_enable_bg
)
2078 bf_set(lpfc_mbx_rq_ftr_rq_dif
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
2080 /* Enable NPIV only if configured to do so. */
2081 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
)
2082 bf_set(lpfc_mbx_rq_ftr_rq_npiv
, &mboxq
->u
.mqe
.un
.req_ftrs
, 1);
2088 * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
2089 * @mbox: pointer to lpfc mbox command to initialize.
2090 * @vport: Vport associated with the VF.
2092 * This routine initializes @mbox to all zeros and then fills in the mailbox
2093 * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
2094 * in the context of an FCF. The driver issues this command to setup a VFI
2095 * before issuing a FLOGI to login to the VSAN. The driver should also issue a
2096 * REG_VFI after a successful VSAN login.
2099 lpfc_init_vfi(struct lpfcMboxq
*mbox
, struct lpfc_vport
*vport
)
2101 struct lpfc_mbx_init_vfi
*init_vfi
;
2103 memset(mbox
, 0, sizeof(*mbox
));
2104 mbox
->vport
= vport
;
2105 init_vfi
= &mbox
->u
.mqe
.un
.init_vfi
;
2106 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_INIT_VFI
);
2107 bf_set(lpfc_init_vfi_vr
, init_vfi
, 1);
2108 bf_set(lpfc_init_vfi_vt
, init_vfi
, 1);
2109 bf_set(lpfc_init_vfi_vp
, init_vfi
, 1);
2110 bf_set(lpfc_init_vfi_vfi
, init_vfi
,
2111 vport
->phba
->sli4_hba
.vfi_ids
[vport
->vfi
]);
2112 bf_set(lpfc_init_vfi_vpi
, init_vfi
,
2113 vport
->phba
->vpi_ids
[vport
->vpi
]);
2114 bf_set(lpfc_init_vfi_fcfi
, init_vfi
,
2115 vport
->phba
->fcf
.fcfi
);
2119 * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
2120 * @mbox: pointer to lpfc mbox command to initialize.
2121 * @vport: vport associated with the VF.
2122 * @phys: BDE DMA bus address used to send the service parameters to the HBA.
2124 * This routine initializes @mbox to all zeros and then fills in the mailbox
2125 * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
2126 * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
2127 * fabrics identified by VFI in the context of an FCF.
2130 lpfc_reg_vfi(struct lpfcMboxq
*mbox
, struct lpfc_vport
*vport
, dma_addr_t phys
)
2132 struct lpfc_mbx_reg_vfi
*reg_vfi
;
2133 struct lpfc_hba
*phba
= vport
->phba
;
2135 memset(mbox
, 0, sizeof(*mbox
));
2136 reg_vfi
= &mbox
->u
.mqe
.un
.reg_vfi
;
2137 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_REG_VFI
);
2138 bf_set(lpfc_reg_vfi_vp
, reg_vfi
, 1);
2139 bf_set(lpfc_reg_vfi_vfi
, reg_vfi
,
2140 phba
->sli4_hba
.vfi_ids
[vport
->vfi
]);
2141 bf_set(lpfc_reg_vfi_fcfi
, reg_vfi
, phba
->fcf
.fcfi
);
2142 bf_set(lpfc_reg_vfi_vpi
, reg_vfi
, phba
->vpi_ids
[vport
->vpi
]);
2143 memcpy(reg_vfi
->wwn
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2144 reg_vfi
->wwn
[0] = cpu_to_le32(reg_vfi
->wwn
[0]);
2145 reg_vfi
->wwn
[1] = cpu_to_le32(reg_vfi
->wwn
[1]);
2146 reg_vfi
->e_d_tov
= phba
->fc_edtov
;
2147 reg_vfi
->r_a_tov
= phba
->fc_ratov
;
2148 reg_vfi
->bde
.addrHigh
= putPaddrHigh(phys
);
2149 reg_vfi
->bde
.addrLow
= putPaddrLow(phys
);
2150 reg_vfi
->bde
.tus
.f
.bdeSize
= sizeof(vport
->fc_sparam
);
2151 reg_vfi
->bde
.tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
2152 bf_set(lpfc_reg_vfi_nport_id
, reg_vfi
, vport
->fc_myDID
);
2154 /* Only FC supports upd bit */
2155 if ((phba
->sli4_hba
.lnk_info
.lnk_tp
== LPFC_LNK_TYPE_FC
) &&
2156 (vport
->fc_flag
& FC_VFI_REGISTERED
) &&
2157 (!phba
->fc_topology_changed
)) {
2158 bf_set(lpfc_reg_vfi_vp
, reg_vfi
, 0);
2159 bf_set(lpfc_reg_vfi_upd
, reg_vfi
, 1);
2161 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_MBOX
,
2162 "3134 Register VFI, mydid:x%x, fcfi:%d, "
2163 " vfi:%d, vpi:%d, fc_pname:%x%x fc_flag:x%x"
2164 " port_state:x%x topology chg:%d\n",
2167 phba
->sli4_hba
.vfi_ids
[vport
->vfi
],
2168 phba
->vpi_ids
[vport
->vpi
],
2169 reg_vfi
->wwn
[0], reg_vfi
->wwn
[1], vport
->fc_flag
,
2170 vport
->port_state
, phba
->fc_topology_changed
);
2174 * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
2175 * @phba: pointer to the hba structure to init the VPI for.
2176 * @mbox: pointer to lpfc mbox command to initialize.
2177 * @vpi: VPI to be initialized.
2179 * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
2180 * command to activate a virtual N_Port. The HBA assigns a MAC address to use
2181 * with the virtual N Port. The SLI Host issues this command before issuing a
2182 * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
2183 * successful virtual NPort login.
2186 lpfc_init_vpi(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
, uint16_t vpi
)
2188 memset(mbox
, 0, sizeof(*mbox
));
2189 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_INIT_VPI
);
2190 bf_set(lpfc_init_vpi_vpi
, &mbox
->u
.mqe
.un
.init_vpi
,
2191 phba
->vpi_ids
[vpi
]);
2192 bf_set(lpfc_init_vpi_vfi
, &mbox
->u
.mqe
.un
.init_vpi
,
2193 phba
->sli4_hba
.vfi_ids
[phba
->pport
->vfi
]);
2197 * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
2198 * @mbox: pointer to lpfc mbox command to initialize.
2199 * @vport: vport associated with the VF.
2201 * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
2202 * (logical NPort) into the inactive state. The SLI Host must have logged out
2203 * and unregistered all remote N_Ports to abort any activity on the virtual
2204 * fabric. The SLI Port posts the mailbox response after marking the virtual
2208 lpfc_unreg_vfi(struct lpfcMboxq
*mbox
, struct lpfc_vport
*vport
)
2210 memset(mbox
, 0, sizeof(*mbox
));
2211 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_UNREG_VFI
);
2212 bf_set(lpfc_unreg_vfi_vfi
, &mbox
->u
.mqe
.un
.unreg_vfi
,
2213 vport
->phba
->sli4_hba
.vfi_ids
[vport
->vfi
]);
2217 * lpfc_sli4_dump_cfg_rg23 - Dump sli4 port config region 23
2218 * @phba: pointer to the hba structure containing.
2219 * @mbox: pointer to lpfc mbox command to initialize.
2221 * This function create a SLI4 dump mailbox command to dump configure
2225 lpfc_sli4_dump_cfg_rg23(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
2227 struct lpfc_dmabuf
*mp
= NULL
;
2230 memset(mbox
, 0, sizeof(*mbox
));
2233 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2235 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
2237 if (!mp
|| !mp
->virt
) {
2239 /* dump config region 23 failed to allocate memory */
2240 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
2241 "2569 lpfc dump config region 23: memory"
2242 " allocation failed\n");
2246 memset(mp
->virt
, 0, LPFC_BPL_SIZE
);
2247 INIT_LIST_HEAD(&mp
->list
);
2249 /* save address for completion */
2250 mbox
->context1
= (uint8_t *) mp
;
2252 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
2253 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
2254 mb
->un
.varDmp
.region_id
= DMP_REGION_23
;
2255 mb
->un
.varDmp
.sli4_length
= DMP_RGN23_SIZE
;
2256 mb
->un
.varWords
[3] = putPaddrLow(mp
->phys
);
2257 mb
->un
.varWords
[4] = putPaddrHigh(mp
->phys
);
2262 lpfc_mbx_cmpl_rdp_link_stat(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
2266 struct lpfc_rdp_context
*rdp_context
=
2267 (struct lpfc_rdp_context
*)(mboxq
->context2
);
2273 memcpy(&rdp_context
->link_stat
, &mb
->un
.varRdLnk
, sizeof(READ_LNK_VAR
));
2278 lpfc_sli4_mbox_cmd_free(phba
, mboxq
);
2279 rdp_context
->cmpl(phba
, rdp_context
, rc
);
2283 lpfc_mbx_cmpl_rdp_page_a2(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
2285 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
2286 struct lpfc_rdp_context
*rdp_context
=
2287 (struct lpfc_rdp_context
*)(mbox
->context2
);
2289 if (bf_get(lpfc_mqe_status
, &mbox
->u
.mqe
))
2290 goto error_mbuf_free
;
2292 lpfc_sli_bemem_bcopy(mp
->virt
, &rdp_context
->page_a2
,
2293 DMP_SFF_PAGE_A2_SIZE
);
2295 /* We don't need dma buffer for link stat. */
2296 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2299 memset(mbox
, 0, sizeof(*mbox
));
2300 lpfc_read_lnk_stat(phba
, mbox
);
2301 mbox
->vport
= rdp_context
->ndlp
->vport
;
2302 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_rdp_link_stat
;
2303 mbox
->context2
= (struct lpfc_rdp_context
*) rdp_context
;
2304 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
) == MBX_NOT_FINISHED
)
2305 goto error_cmd_free
;
2310 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2313 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
2314 rdp_context
->cmpl(phba
, rdp_context
, FAILURE
);
2318 lpfc_mbx_cmpl_rdp_page_a0(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mbox
)
2321 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (mbox
->context1
);
2322 struct lpfc_rdp_context
*rdp_context
=
2323 (struct lpfc_rdp_context
*)(mbox
->context2
);
2325 if (bf_get(lpfc_mqe_status
, &mbox
->u
.mqe
))
2328 lpfc_sli_bemem_bcopy(mp
->virt
, &rdp_context
->page_a0
,
2329 DMP_SFF_PAGE_A0_SIZE
);
2331 memset(mbox
, 0, sizeof(*mbox
));
2333 memset(mp
->virt
, 0, DMP_SFF_PAGE_A2_SIZE
);
2334 INIT_LIST_HEAD(&mp
->list
);
2336 /* save address for completion */
2337 mbox
->context1
= mp
;
2338 mbox
->vport
= rdp_context
->ndlp
->vport
;
2340 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_DUMP_MEMORY
);
2341 bf_set(lpfc_mbx_memory_dump_type3_type
,
2342 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_LMSD
);
2343 bf_set(lpfc_mbx_memory_dump_type3_link
,
2344 &mbox
->u
.mqe
.un
.mem_dump_type3
, phba
->sli4_hba
.physical_port
);
2345 bf_set(lpfc_mbx_memory_dump_type3_page_no
,
2346 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_PAGE_A2
);
2347 bf_set(lpfc_mbx_memory_dump_type3_length
,
2348 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_SFF_PAGE_A2_SIZE
);
2349 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_lo
= putPaddrLow(mp
->phys
);
2350 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_hi
= putPaddrHigh(mp
->phys
);
2352 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_rdp_page_a2
;
2353 mbox
->context2
= (struct lpfc_rdp_context
*) rdp_context
;
2354 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
2355 if (rc
== MBX_NOT_FINISHED
)
2361 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2363 lpfc_sli4_mbox_cmd_free(phba
, mbox
);
2364 rdp_context
->cmpl(phba
, rdp_context
, FAILURE
);
2369 * lpfc_sli4_dump_sfp_pagea0 - Dump sli4 read SFP Diagnostic.
2370 * @phba: pointer to the hba structure containing.
2371 * @mbox: pointer to lpfc mbox command to initialize.
2373 * This function create a SLI4 dump mailbox command to dump configure
2377 lpfc_sli4_dump_page_a0(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
2379 struct lpfc_dmabuf
*mp
= NULL
;
2381 memset(mbox
, 0, sizeof(*mbox
));
2383 mp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
2385 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
2386 if (!mp
|| !mp
->virt
) {
2388 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
2389 "3569 dump type 3 page 0xA0 allocation failed\n");
2393 memset(mp
->virt
, 0, LPFC_BPL_SIZE
);
2394 INIT_LIST_HEAD(&mp
->list
);
2396 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_DUMP_MEMORY
);
2397 /* save address for completion */
2398 mbox
->context1
= mp
;
2400 bf_set(lpfc_mbx_memory_dump_type3_type
,
2401 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_LMSD
);
2402 bf_set(lpfc_mbx_memory_dump_type3_link
,
2403 &mbox
->u
.mqe
.un
.mem_dump_type3
, phba
->sli4_hba
.physical_port
);
2404 bf_set(lpfc_mbx_memory_dump_type3_page_no
,
2405 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_PAGE_A0
);
2406 bf_set(lpfc_mbx_memory_dump_type3_length
,
2407 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_SFF_PAGE_A0_SIZE
);
2408 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_lo
= putPaddrLow(mp
->phys
);
2409 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_hi
= putPaddrHigh(mp
->phys
);
2415 * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
2416 * @phba: pointer to the hba structure containing the FCF index and RQ ID.
2417 * @mbox: pointer to lpfc mbox command to initialize.
2419 * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
2420 * SLI Host uses the command to activate an FCF after it has acquired FCF
2421 * information via a READ_FCF mailbox command. This mailbox command also is used
2422 * to indicate where received unsolicited frames from this FCF will be sent. By
2423 * default this routine will set up the FCF to forward all unsolicited frames
2424 * the the RQ ID passed in the @phba. This can be overridden by the caller for
2425 * more complicated setups.
2428 lpfc_reg_fcfi(struct lpfc_hba
*phba
, struct lpfcMboxq
*mbox
)
2430 struct lpfc_mbx_reg_fcfi
*reg_fcfi
;
2432 memset(mbox
, 0, sizeof(*mbox
));
2433 reg_fcfi
= &mbox
->u
.mqe
.un
.reg_fcfi
;
2434 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_REG_FCFI
);
2435 bf_set(lpfc_reg_fcfi_rq_id0
, reg_fcfi
, phba
->sli4_hba
.hdr_rq
->queue_id
);
2436 bf_set(lpfc_reg_fcfi_rq_id1
, reg_fcfi
, REG_FCF_INVALID_QID
);
2437 bf_set(lpfc_reg_fcfi_rq_id2
, reg_fcfi
, REG_FCF_INVALID_QID
);
2438 bf_set(lpfc_reg_fcfi_rq_id3
, reg_fcfi
, REG_FCF_INVALID_QID
);
2439 bf_set(lpfc_reg_fcfi_info_index
, reg_fcfi
,
2440 phba
->fcf
.current_rec
.fcf_indx
);
2441 /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */
2442 bf_set(lpfc_reg_fcfi_mam
, reg_fcfi
, (~phba
->fcf
.addr_mode
) & 0x3);
2443 if (phba
->fcf
.current_rec
.vlan_id
!= LPFC_FCOE_NULL_VID
) {
2444 bf_set(lpfc_reg_fcfi_vv
, reg_fcfi
, 1);
2445 bf_set(lpfc_reg_fcfi_vlan_tag
, reg_fcfi
,
2446 phba
->fcf
.current_rec
.vlan_id
);
2451 * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
2452 * @mbox: pointer to lpfc mbox command to initialize.
2453 * @fcfi: FCFI to be unregistered.
2455 * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
2456 * The SLI Host uses the command to inactivate an FCFI.
2459 lpfc_unreg_fcfi(struct lpfcMboxq
*mbox
, uint16_t fcfi
)
2461 memset(mbox
, 0, sizeof(*mbox
));
2462 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_UNREG_FCFI
);
2463 bf_set(lpfc_unreg_fcfi
, &mbox
->u
.mqe
.un
.unreg_fcfi
, fcfi
);
2467 * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
2468 * @mbox: pointer to lpfc mbox command to initialize.
2469 * @ndlp: The nodelist structure that describes the RPI to resume.
2471 * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
2475 lpfc_resume_rpi(struct lpfcMboxq
*mbox
, struct lpfc_nodelist
*ndlp
)
2477 struct lpfc_hba
*phba
= ndlp
->phba
;
2478 struct lpfc_mbx_resume_rpi
*resume_rpi
;
2480 memset(mbox
, 0, sizeof(*mbox
));
2481 resume_rpi
= &mbox
->u
.mqe
.un
.resume_rpi
;
2482 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_RESUME_RPI
);
2483 bf_set(lpfc_resume_rpi_index
, resume_rpi
,
2484 phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
]);
2485 bf_set(lpfc_resume_rpi_ii
, resume_rpi
, RESUME_INDEX_RPI
);
2486 resume_rpi
->event_tag
= ndlp
->phba
->fc_eventTag
;
2490 * lpfc_supported_pages - Initialize the PORT_CAPABILITIES supported pages
2492 * @mbox: pointer to lpfc mbox command to initialize.
2494 * The PORT_CAPABILITIES supported pages mailbox command is issued to
2495 * retrieve the particular feature pages supported by the port.
2498 lpfc_supported_pages(struct lpfcMboxq
*mbox
)
2500 struct lpfc_mbx_supp_pages
*supp_pages
;
2502 memset(mbox
, 0, sizeof(*mbox
));
2503 supp_pages
= &mbox
->u
.mqe
.un
.supp_pages
;
2504 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_PORT_CAPABILITIES
);
2505 bf_set(cpn
, supp_pages
, LPFC_SUPP_PAGES
);
2509 * lpfc_pc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params mbox cmd.
2510 * @mbox: pointer to lpfc mbox command to initialize.
2512 * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to
2513 * retrieve the particular SLI4 features supported by the port.
2516 lpfc_pc_sli4_params(struct lpfcMboxq
*mbox
)
2518 struct lpfc_mbx_pc_sli4_params
*sli4_params
;
2520 memset(mbox
, 0, sizeof(*mbox
));
2521 sli4_params
= &mbox
->u
.mqe
.un
.sli4_params
;
2522 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_PORT_CAPABILITIES
);
2523 bf_set(cpn
, sli4_params
, LPFC_SLI4_PARAMETERS
);