1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2022 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi_device.h>
30 #include <scsi/scsi_transport_fc.h>
31 #include <scsi/scsi.h>
32 #include <scsi/fc/fc_fs.h>
37 #include "lpfc_sli4.h"
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_compat.h"
47 * lpfc_mbox_rsrc_prep - Prepare a mailbox with DMA buffer memory.
48 * @phba: pointer to lpfc hba data structure.
49 * @mbox: pointer to the driver internal queue element for mailbox command.
51 * A mailbox command consists of the pool memory for the command, @mbox, and
52 * one or more DMA buffers for the data transfer. This routine provides
53 * a standard framework for allocating the dma buffer and assigning to the
54 * @mbox. Callers should cleanup the mbox with a call to
55 * lpfc_mbox_rsrc_cleanup.
57 * The lpfc_mbuf_alloc routine acquires the hbalock so the caller is
58 * responsible to ensure the hbalock is released. Also note that the
59 * driver design is a single dmabuf/mbuf per mbox in the ctx_buf.
63 lpfc_mbox_rsrc_prep(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
65 struct lpfc_dmabuf *mp;
67 mp = kmalloc(sizeof(*mp), GFP_KERNEL);
71 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
77 memset(mp->virt, 0, LPFC_BPL_SIZE);
79 /* Initialization only. Driver does not use a list of dmabufs. */
80 INIT_LIST_HEAD(&mp->list);
86 * lpfc_mbox_rsrc_cleanup - Free the mailbox DMA buffer and virtual memory.
87 * @phba: pointer to lpfc hba data structure.
88 * @mbox: pointer to the driver internal queue element for mailbox command.
89 * @locked: value that indicates if the hbalock is held (1) or not (0).
91 * A mailbox command consists of the pool memory for the command, @mbox, and
92 * possibly a DMA buffer for the data transfer. This routine provides
93 * a standard framework for releasing any dma buffers and freeing all
94 * memory resources in it as well as releasing the @mbox back to the @phba pool.
95 * Callers should use this routine for cleanup for all mailboxes prepped with
96 * lpfc_mbox_rsrc_prep.
100 lpfc_mbox_rsrc_cleanup(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox,
101 enum lpfc_mbox_ctx locked)
103 struct lpfc_dmabuf *mp;
105 mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
106 mbox->ctx_buf = NULL;
108 /* Release the generic BPL buffer memory. */
110 if (locked == MBOX_THD_LOCKED)
111 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
113 lpfc_mbuf_free(phba, mp->virt, mp->phys);
117 mempool_free(mbox, phba->mbox_mem_pool);
121 * lpfc_dump_static_vport - Dump HBA's static vport information.
122 * @phba: pointer to lpfc hba data structure.
123 * @pmb: pointer to the driver internal queue element for mailbox command.
124 * @offset: offset for dumping vport info.
126 * The dump mailbox command provides a method for the device driver to obtain
127 * various types of information from the HBA device.
129 * This routine prepares the mailbox command for dumping list of static
130 * vports to be created.
133 lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
137 struct lpfc_dmabuf *mp;
142 /* Setup to dump vport info region */
143 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
144 mb->mbxCommand = MBX_DUMP_MEMORY;
145 mb->un.varDmp.type = DMP_NV_PARAMS;
146 mb->un.varDmp.entry_index = offset;
147 mb->un.varDmp.region_id = DMP_REGION_VPORT;
148 mb->mbxOwner = OWN_HOST;
150 /* For SLI3 HBAs data is embedded in mailbox */
151 if (phba->sli_rev != LPFC_SLI_REV4) {
152 mb->un.varDmp.cv = 1;
153 mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t);
157 rc = lpfc_mbox_rsrc_prep(phba, pmb);
159 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
160 "2605 %s: memory allocation failed\n",
166 mb->un.varWords[3] = putPaddrLow(mp->phys);
167 mb->un.varWords[4] = putPaddrHigh(mp->phys);
168 mb->un.varDmp.sli4_length = sizeof(struct static_vport_info);
174 * lpfc_down_link - Bring down HBAs link.
175 * @phba: pointer to lpfc hba data structure.
176 * @pmb: pointer to the driver internal queue element for mailbox command.
178 * This routine prepares a mailbox command to bring down HBA link.
181 lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
184 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
186 mb->mbxCommand = MBX_DOWN_LINK;
187 mb->mbxOwner = OWN_HOST;
191 * lpfc_dump_mem - Prepare a mailbox command for reading a region.
192 * @phba: pointer to lpfc hba data structure.
193 * @pmb: pointer to the driver internal queue element for mailbox command.
194 * @offset: offset into the region.
195 * @region_id: config region id.
197 * The dump mailbox command provides a method for the device driver to obtain
198 * various types of information from the HBA device.
200 * This routine prepares the mailbox command for dumping HBA's config region.
203 lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset,
212 /* Setup to dump VPD region */
213 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
214 mb->mbxCommand = MBX_DUMP_MEMORY;
215 mb->un.varDmp.cv = 1;
216 mb->un.varDmp.type = DMP_NV_PARAMS;
217 mb->un.varDmp.entry_index = offset;
218 mb->un.varDmp.region_id = region_id;
219 mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
220 mb->un.varDmp.co = 0;
221 mb->un.varDmp.resp_offset = 0;
223 mb->mbxOwner = OWN_HOST;
228 * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
229 * @phba: pointer to lpfc hba data structure.
230 * @pmb: pointer to the driver internal queue element for mailbox command.
232 * This function create a dump memory mailbox command to dump wake up
236 lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
242 /* Save context so that we can restore after memset */
245 /* Setup to dump VPD region */
246 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
247 mb->mbxCommand = MBX_DUMP_MEMORY;
248 mb->mbxOwner = OWN_HOST;
249 mb->un.varDmp.cv = 1;
250 mb->un.varDmp.type = DMP_NV_PARAMS;
251 if (phba->sli_rev < LPFC_SLI_REV4)
252 mb->un.varDmp.entry_index = 0;
253 mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
254 mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
255 mb->un.varDmp.co = 0;
256 mb->un.varDmp.resp_offset = 0;
262 * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
263 * @phba: pointer to lpfc hba data structure.
264 * @pmb: pointer to the driver internal queue element for mailbox command.
266 * The read NVRAM mailbox command returns the HBA's non-volatile parameters
267 * that are used as defaults when the Fibre Channel link is brought on-line.
269 * This routine prepares the mailbox command for reading information stored
270 * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
273 lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
278 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
279 mb->mbxCommand = MBX_READ_NV;
280 mb->mbxOwner = OWN_HOST;
285 * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
286 * @phba: pointer to lpfc hba data structure.
287 * @pmb: pointer to the driver internal queue element for mailbox command.
288 * @ring: ring number for the asynchronous event to be configured.
290 * The asynchronous event enable mailbox command is used to enable the
291 * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
292 * specifies the default ring to which events are posted.
294 * This routine prepares the mailbox command for enabling HBA asynchronous
295 * event support on a IOCB ring.
298 lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
304 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
305 mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
306 mb->un.varCfgAsyncEvent.ring = ring;
307 mb->mbxOwner = OWN_HOST;
312 * lpfc_heart_beat - Prepare a mailbox command for heart beat
313 * @phba: pointer to lpfc hba data structure.
314 * @pmb: pointer to the driver internal queue element for mailbox command.
316 * The heart beat mailbox command is used to detect an unresponsive HBA, which
317 * is defined as any device where no error attention is sent and both mailbox
318 * and rings are not processed.
320 * This routine prepares the mailbox command for issuing a heart beat in the
321 * form of mailbox command to the HBA. The timely completion of the heart
322 * beat mailbox command indicates the health of the HBA.
325 lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
330 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
331 mb->mbxCommand = MBX_HEARTBEAT;
332 mb->mbxOwner = OWN_HOST;
337 * lpfc_read_topology - Prepare a mailbox command for reading HBA topology
338 * @phba: pointer to lpfc hba data structure.
339 * @pmb: pointer to the driver internal queue element for mailbox command.
340 * @mp: DMA buffer memory for reading the link attention information into.
342 * The read topology mailbox command is issued to read the link topology
343 * information indicated by the HBA port when the Link Event bit of the Host
344 * Attention (HSTATT) register is set to 1 (For SLI-3) or when an FC Link
345 * Attention ACQE is received from the port (For SLI-4). A Link Event
346 * Attention occurs based on an exception detected at the Fibre Channel link
349 * This routine prepares the mailbox command for reading HBA link topology
350 * information. A DMA memory has been set aside and address passed to the
351 * HBA through @mp for the HBA to DMA link attention information into the
352 * memory as part of the execution of the mailbox command.
355 * 0 - Success (currently always return 0)
358 lpfc_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
359 struct lpfc_dmabuf *mp)
364 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
366 INIT_LIST_HEAD(&mp->list);
367 mb->mbxCommand = MBX_READ_TOPOLOGY;
368 mb->un.varReadTop.lilpBde64.tus.f.bdeSize = LPFC_ALPA_MAP_SIZE;
369 mb->un.varReadTop.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
370 mb->un.varReadTop.lilpBde64.addrLow = putPaddrLow(mp->phys);
372 /* Save address for later completion and set the owner to host so that
373 * the FW knows this mailbox is available for processing.
375 pmb->ctx_buf = (uint8_t *)mp;
376 mb->mbxOwner = OWN_HOST;
381 * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
382 * @phba: pointer to lpfc hba data structure.
383 * @pmb: pointer to the driver internal queue element for mailbox command.
385 * The clear link attention mailbox command is issued to clear the link event
386 * attention condition indicated by the Link Event bit of the Host Attention
387 * (HSTATT) register. The link event attention condition is cleared only if
388 * the event tag specified matches that of the current link event counter.
389 * The current event tag is read using the read link attention event mailbox
392 * This routine prepares the mailbox command for clearing HBA link attention
396 lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
401 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
403 mb->un.varClearLA.eventTag = phba->fc_eventTag;
404 mb->mbxCommand = MBX_CLEAR_LA;
405 mb->mbxOwner = OWN_HOST;
410 * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
411 * @phba: pointer to lpfc hba data structure.
412 * @pmb: pointer to the driver internal queue element for mailbox command.
414 * The configure link mailbox command is used before the initialize link
415 * mailbox command to override default value and to configure link-oriented
416 * parameters such as DID address and various timers. Typically, this
417 * command would be used after an F_Port login to set the returned DID address
418 * and the fabric timeout values. This command is not valid before a configure
419 * port command has configured the HBA port.
421 * This routine prepares the mailbox command for configuring link on a HBA.
424 lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
426 struct lpfc_vport *vport = phba->pport;
427 MAILBOX_t *mb = &pmb->u.mb;
428 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
431 * SLI-2, Coalescing Response Feature.
433 if (phba->cfg_cr_delay && (phba->sli_rev < LPFC_SLI_REV4)) {
434 mb->un.varCfgLnk.cr = 1;
435 mb->un.varCfgLnk.ci = 1;
436 mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
437 mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
440 mb->un.varCfgLnk.myId = vport->fc_myDID;
441 mb->un.varCfgLnk.edtov = phba->fc_edtov;
442 mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
443 mb->un.varCfgLnk.ratov = phba->fc_ratov;
444 mb->un.varCfgLnk.rttov = phba->fc_rttov;
445 mb->un.varCfgLnk.altov = phba->fc_altov;
446 mb->un.varCfgLnk.crtov = phba->fc_crtov;
447 mb->un.varCfgLnk.cscn = 0;
448 if (phba->bbcredit_support && phba->cfg_enable_bbcr) {
449 mb->un.varCfgLnk.cscn = 1;
450 mb->un.varCfgLnk.bbscn = bf_get(lpfc_bbscn_def,
451 &phba->sli4_hba.bbscn_params);
454 if (phba->cfg_ack0 && (phba->sli_rev < LPFC_SLI_REV4))
455 mb->un.varCfgLnk.ack0_enable = 1;
457 mb->mbxCommand = MBX_CONFIG_LINK;
458 mb->mbxOwner = OWN_HOST;
463 * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
464 * @phba: pointer to lpfc hba data structure.
465 * @pmb: pointer to the driver internal queue element for mailbox command.
467 * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
468 * MSI-X multi-message interrupt vector association to interrupt attention
476 lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
478 MAILBOX_t *mb = &pmb->u.mb;
479 uint32_t attentionConditions[2];
482 if (phba->cfg_use_msi != 2) {
483 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
484 "0475 Not configured for supporting MSI-X "
485 "cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
489 if (phba->sli_rev < 3) {
490 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
491 "0476 HBA not supporting SLI-3 or later "
492 "SLI Revision: 0x%x\n", phba->sli_rev);
496 /* Clear mailbox command fields */
497 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
500 * SLI-3, Message Signaled Interrupt Feature.
503 /* Multi-message attention configuration */
504 attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
506 attentionConditions[1] = 0;
508 mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
509 mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
512 * Set up message number to HA bit association
514 #ifdef __BIG_ENDIAN_BITFIELD
516 mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
517 /* RA1 (Other Protocol Extra Ring) */
518 mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
519 #else /* __LITTLE_ENDIAN_BITFIELD */
521 mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
522 /* RA1 (Other Protocol Extra Ring) */
523 mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
525 /* Multi-message interrupt autoclear configuration*/
526 mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
527 mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
529 /* For now, HBA autoclear does not work reliably, disable it */
530 mb->un.varCfgMSI.autoClearHA[0] = 0;
531 mb->un.varCfgMSI.autoClearHA[1] = 0;
533 /* Set command and owner bit */
534 mb->mbxCommand = MBX_CONFIG_MSI;
535 mb->mbxOwner = OWN_HOST;
541 * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
542 * @phba: pointer to lpfc hba data structure.
543 * @pmb: pointer to the driver internal queue element for mailbox command.
544 * @topology: the link topology for the link to be initialized to.
545 * @linkspeed: the link speed for the link to be initialized to.
547 * The initialize link mailbox command is used to initialize the Fibre
548 * Channel link. This command must follow a configure port command that
549 * establishes the mode of operation.
551 * This routine prepares the mailbox command for initializing link on a HBA
552 * with the specified link topology and speed.
555 lpfc_init_link(struct lpfc_hba * phba,
556 LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
562 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
565 case FLAGS_TOPOLOGY_MODE_LOOP_PT:
566 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
567 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
569 case FLAGS_TOPOLOGY_MODE_PT_PT:
570 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
572 case FLAGS_TOPOLOGY_MODE_LOOP:
573 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
575 case FLAGS_TOPOLOGY_MODE_PT_LOOP:
576 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
577 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
580 mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
584 /* Topology handling for ASIC_GEN_NUM 0xC and later */
585 if ((phba->sli4_hba.pc_sli4_params.sli_family == LPFC_SLI_INTF_FAMILY_G6 ||
586 phba->sli4_hba.pc_sli4_params.if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
587 !(phba->sli4_hba.pc_sli4_params.pls) &&
588 mb->un.varInitLnk.link_flags & FLAGS_TOPOLOGY_MODE_LOOP) {
589 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
590 phba->cfg_topology = FLAGS_TOPOLOGY_MODE_PT_PT;
593 /* Enable asynchronous ABTS responses from firmware */
594 if (phba->sli_rev == LPFC_SLI_REV3 && !phba->cfg_fcp_wait_abts_rsp)
595 mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
598 * Setting up the link speed
601 if (vpd->rev.feaLevelHigh >= 0x02){
603 case LPFC_USER_LINK_SPEED_1G:
604 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
605 mb->un.varInitLnk.link_speed = LINK_SPEED_1G;
607 case LPFC_USER_LINK_SPEED_2G:
608 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
609 mb->un.varInitLnk.link_speed = LINK_SPEED_2G;
611 case LPFC_USER_LINK_SPEED_4G:
612 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
613 mb->un.varInitLnk.link_speed = LINK_SPEED_4G;
615 case LPFC_USER_LINK_SPEED_8G:
616 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
617 mb->un.varInitLnk.link_speed = LINK_SPEED_8G;
619 case LPFC_USER_LINK_SPEED_10G:
620 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
621 mb->un.varInitLnk.link_speed = LINK_SPEED_10G;
623 case LPFC_USER_LINK_SPEED_16G:
624 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
625 mb->un.varInitLnk.link_speed = LINK_SPEED_16G;
627 case LPFC_USER_LINK_SPEED_32G:
628 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
629 mb->un.varInitLnk.link_speed = LINK_SPEED_32G;
631 case LPFC_USER_LINK_SPEED_64G:
632 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
633 mb->un.varInitLnk.link_speed = LINK_SPEED_64G;
635 case LPFC_USER_LINK_SPEED_AUTO:
637 mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
643 mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
645 mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
646 mb->mbxOwner = OWN_HOST;
647 mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
652 * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
653 * @phba: pointer to lpfc hba data structure.
654 * @pmb: pointer to the driver internal queue element for mailbox command.
655 * @vpi: virtual N_Port identifier.
657 * The read service parameter mailbox command is used to read the HBA port
658 * service parameters. The service parameters are read into the buffer
659 * specified directly by a BDE in the mailbox command. These service
660 * parameters may then be used to build the payload of an N_Port/F_POrt
661 * login request and reply (LOGI/ACC).
663 * This routine prepares the mailbox command for reading HBA port service
664 * parameters. The DMA memory is allocated in this function and the addresses
665 * are populated into the mailbox command for the HBA to DMA the service
670 * 1 - DMA memory allocation failed
673 lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
675 struct lpfc_dmabuf *mp;
679 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
681 /* Get a buffer to hold the HBAs Service Parameters */
682 rc = lpfc_mbox_rsrc_prep(phba, pmb);
684 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
685 "0301 READ_SPARAM: no buffers\n");
691 mb->mbxOwner = OWN_HOST;
692 mb->mbxCommand = MBX_READ_SPARM64;
693 mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
694 mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
695 mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
696 if (phba->sli_rev >= LPFC_SLI_REV3)
697 mb->un.varRdSparm.vpi = phba->vpi_ids[vpi];
703 * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
704 * @phba: pointer to lpfc hba data structure.
705 * @vpi: virtual N_Port identifier.
706 * @did: remote port identifier.
707 * @pmb: pointer to the driver internal queue element for mailbox command.
709 * The unregister DID mailbox command is used to unregister an N_Port/F_Port
710 * login for an unknown RPI by specifying the DID of a remote port. This
711 * command frees an RPI context in the HBA port. This has the effect of
712 * performing an implicit N_Port/F_Port logout.
714 * This routine prepares the mailbox command for unregistering a remote
715 * N_Port/F_Port (DID) login.
718 lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
724 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
726 mb->un.varUnregDID.did = did;
727 mb->un.varUnregDID.vpi = vpi;
728 if ((vpi != 0xffff) &&
729 (phba->sli_rev == LPFC_SLI_REV4))
730 mb->un.varUnregDID.vpi = phba->vpi_ids[vpi];
732 mb->mbxCommand = MBX_UNREG_D_ID;
733 mb->mbxOwner = OWN_HOST;
738 * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
739 * @phba: pointer to lpfc hba data structure.
740 * @pmb: pointer to the driver internal queue element for mailbox command.
742 * The read configuration mailbox command is used to read the HBA port
743 * configuration parameters. This mailbox command provides a method for
744 * seeing any parameters that may have changed via various configuration
747 * This routine prepares the mailbox command for reading out HBA configuration
751 lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
756 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
758 mb->mbxCommand = MBX_READ_CONFIG;
759 mb->mbxOwner = OWN_HOST;
764 * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
765 * @phba: pointer to lpfc hba data structure.
766 * @pmb: pointer to the driver internal queue element for mailbox command.
768 * The read link status mailbox command is used to read the link status from
769 * the HBA. Link status includes all link-related error counters. These
770 * counters are maintained by the HBA and originated in the link hardware
771 * unit. Note that all of these counters wrap.
773 * This routine prepares the mailbox command for reading out HBA link status.
776 lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
781 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
783 mb->mbxCommand = MBX_READ_LNK_STAT;
784 mb->mbxOwner = OWN_HOST;
789 * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
790 * @phba: pointer to lpfc hba data structure.
791 * @vpi: virtual N_Port identifier.
792 * @did: remote port identifier.
793 * @param: pointer to memory holding the server parameters.
794 * @pmb: pointer to the driver internal queue element for mailbox command.
795 * @rpi: the rpi to use in the registration (usually only used for SLI4.
797 * The registration login mailbox command is used to register an N_Port or
798 * F_Port login. This registration allows the HBA to cache the remote N_Port
799 * service parameters internally and thereby make the appropriate FC-2
800 * decisions. The remote port service parameters are handed off by the driver
801 * to the HBA using a descriptor entry that directly identifies a buffer in
802 * host memory. In exchange, the HBA returns an RPI identifier.
804 * This routine prepares the mailbox command for registering remote port login.
805 * The function allocates DMA buffer for passing the service parameters to the
806 * HBA with the mailbox command.
810 * 1 - DMA memory allocation failed
813 lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
814 uint8_t *param, LPFC_MBOXQ_t *pmb, uint16_t rpi)
816 MAILBOX_t *mb = &pmb->u.mb;
818 struct lpfc_dmabuf *mp;
821 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
823 mb->un.varRegLogin.rpi = 0;
824 if (phba->sli_rev == LPFC_SLI_REV4)
825 mb->un.varRegLogin.rpi = phba->sli4_hba.rpi_ids[rpi];
826 if (phba->sli_rev >= LPFC_SLI_REV3)
827 mb->un.varRegLogin.vpi = phba->vpi_ids[vpi];
828 mb->un.varRegLogin.did = did;
829 mb->mbxOwner = OWN_HOST;
831 /* Get a buffer to hold NPorts Service Parameters */
832 rc = lpfc_mbox_rsrc_prep(phba, pmb);
834 mb->mbxCommand = MBX_REG_LOGIN64;
835 /* REG_LOGIN: no buffers */
836 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
837 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
838 "rpi x%x\n", vpi, did, rpi);
842 /* Copy param's into a new buffer */
845 memcpy(sparam, param, sizeof (struct serv_parm));
847 /* Finish initializing the mailbox. */
848 mb->mbxCommand = MBX_REG_LOGIN64;
849 mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
850 mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
851 mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
857 * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
858 * @phba: pointer to lpfc hba data structure.
859 * @vpi: virtual N_Port identifier.
860 * @rpi: remote port identifier
861 * @pmb: pointer to the driver internal queue element for mailbox command.
863 * The unregistration login mailbox command is used to unregister an N_Port
864 * or F_Port login. This command frees an RPI context in the HBA. It has the
865 * effect of performing an implicit N_Port/F_Port logout.
867 * This routine prepares the mailbox command for unregistering remote port
870 * For SLI4 ports, the rpi passed to this function must be the physical
871 * rpi value, not the logical index.
874 lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
880 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
882 mb->un.varUnregLogin.rpi = rpi;
883 mb->un.varUnregLogin.rsvd1 = 0;
884 if (phba->sli_rev >= LPFC_SLI_REV3)
885 mb->un.varUnregLogin.vpi = phba->vpi_ids[vpi];
887 mb->mbxCommand = MBX_UNREG_LOGIN;
888 mb->mbxOwner = OWN_HOST;
894 * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA.
895 * @vport: pointer to a vport object.
897 * This routine sends mailbox command to unregister all active RPIs for
901 lpfc_sli4_unreg_all_rpis(struct lpfc_vport *vport)
903 struct lpfc_hba *phba = vport->phba;
907 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
910 * For SLI4 functions, the rpi field is overloaded for
911 * the vport context unreg all. This routine passes
912 * 0 for the rpi field in lpfc_unreg_login for compatibility
913 * with SLI3 and then overrides the rpi field with the
914 * expected value for SLI4.
916 lpfc_unreg_login(phba, vport->vpi, phba->vpi_ids[vport->vpi],
918 mbox->u.mb.un.varUnregLogin.rsvd1 = 0x4000;
920 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
921 mbox->ctx_ndlp = NULL;
922 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
923 if (rc == MBX_NOT_FINISHED)
924 mempool_free(mbox, phba->mbox_mem_pool);
929 * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
930 * @vport: pointer to a vport object.
931 * @pmb: pointer to the driver internal queue element for mailbox command.
933 * The registration vport identifier mailbox command is used to activate a
934 * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
935 * N_Port_ID against the information in the selected virtual N_Port context
936 * block and marks it active to allow normal processing of IOCB commands and
937 * received unsolicited exchanges.
939 * This routine prepares the mailbox command for registering a virtual N_Port.
942 lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
944 MAILBOX_t *mb = &pmb->u.mb;
945 struct lpfc_hba *phba = vport->phba;
947 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
949 * Set the re-reg VPI bit for f/w to update the MAC address.
951 if ((phba->sli_rev == LPFC_SLI_REV4) &&
952 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI))
953 mb->un.varRegVpi.upd = 1;
955 mb->un.varRegVpi.vpi = phba->vpi_ids[vport->vpi];
956 mb->un.varRegVpi.sid = vport->fc_myDID;
957 if (phba->sli_rev == LPFC_SLI_REV4)
958 mb->un.varRegVpi.vfi = phba->sli4_hba.vfi_ids[vport->vfi];
960 mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
961 memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname,
962 sizeof(struct lpfc_name));
963 mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]);
964 mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]);
966 mb->mbxCommand = MBX_REG_VPI;
967 mb->mbxOwner = OWN_HOST;
973 * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
974 * @phba: pointer to lpfc hba data structure.
975 * @vpi: virtual N_Port identifier.
976 * @pmb: pointer to the driver internal queue element for mailbox command.
978 * The unregistration vport identifier mailbox command is used to inactivate
979 * a virtual N_Port. The driver must have logged out and unregistered all
980 * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
981 * unregisters any default RPIs associated with the specified vpi, aborting
982 * any active exchanges. The HBA will post the mailbox response after making
983 * the virtual N_Port inactive.
985 * This routine prepares the mailbox command for unregistering a virtual
989 lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
991 MAILBOX_t *mb = &pmb->u.mb;
992 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
994 if (phba->sli_rev == LPFC_SLI_REV3)
995 mb->un.varUnregVpi.vpi = phba->vpi_ids[vpi];
996 else if (phba->sli_rev >= LPFC_SLI_REV4)
997 mb->un.varUnregVpi.sli4_vpi = phba->vpi_ids[vpi];
999 mb->mbxCommand = MBX_UNREG_VPI;
1000 mb->mbxOwner = OWN_HOST;
1006 * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
1007 * @phba: pointer to lpfc hba data structure.
1009 * This routine sets up and initializes the IOCB rings in the Port Control
1013 lpfc_config_pcb_setup(struct lpfc_hba * phba)
1015 struct lpfc_sli *psli = &phba->sli;
1016 struct lpfc_sli_ring *pring;
1017 PCB_t *pcbp = phba->pcb;
1018 dma_addr_t pdma_addr;
1020 uint32_t iocbCnt = 0;
1023 pcbp->maxRing = (psli->num_rings - 1);
1025 for (i = 0; i < psli->num_rings; i++) {
1026 pring = &psli->sli3_ring[i];
1028 pring->sli.sli3.sizeCiocb =
1029 phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE :
1031 pring->sli.sli3.sizeRiocb =
1032 phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE :
1034 /* A ring MUST have both cmd and rsp entries defined to be
1036 if ((pring->sli.sli3.numCiocb == 0) ||
1037 (pring->sli.sli3.numRiocb == 0)) {
1038 pcbp->rdsc[i].cmdEntries = 0;
1039 pcbp->rdsc[i].rspEntries = 0;
1040 pcbp->rdsc[i].cmdAddrHigh = 0;
1041 pcbp->rdsc[i].rspAddrHigh = 0;
1042 pcbp->rdsc[i].cmdAddrLow = 0;
1043 pcbp->rdsc[i].rspAddrLow = 0;
1044 pring->sli.sli3.cmdringaddr = NULL;
1045 pring->sli.sli3.rspringaddr = NULL;
1048 /* Command ring setup for ring */
1049 pring->sli.sli3.cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
1050 pcbp->rdsc[i].cmdEntries = pring->sli.sli3.numCiocb;
1052 offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
1053 (uint8_t *) phba->slim2p.virt;
1054 pdma_addr = phba->slim2p.phys + offset;
1055 pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
1056 pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
1057 iocbCnt += pring->sli.sli3.numCiocb;
1059 /* Response ring setup for ring */
1060 pring->sli.sli3.rspringaddr = (void *) &phba->IOCBs[iocbCnt];
1062 pcbp->rdsc[i].rspEntries = pring->sli.sli3.numRiocb;
1063 offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
1064 (uint8_t *)phba->slim2p.virt;
1065 pdma_addr = phba->slim2p.phys + offset;
1066 pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
1067 pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
1068 iocbCnt += pring->sli.sli3.numRiocb;
1073 * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
1074 * @phba: pointer to lpfc hba data structure.
1075 * @pmb: pointer to the driver internal queue element for mailbox command.
1077 * The read revision mailbox command is used to read the revision levels of
1078 * the HBA components. These components include hardware units, resident
1079 * firmware, and available firmware. HBAs that supports SLI-3 mode of
1080 * operation provide different response information depending on the version
1081 * requested by the driver.
1083 * This routine prepares the mailbox command for reading HBA revision
1087 lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1089 MAILBOX_t *mb = &pmb->u.mb;
1090 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1091 mb->un.varRdRev.cv = 1;
1092 mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
1093 mb->mbxCommand = MBX_READ_REV;
1094 mb->mbxOwner = OWN_HOST;
1099 lpfc_sli4_swap_str(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1101 MAILBOX_t *mb = &pmb->u.mb;
1102 struct lpfc_mqe *mqe;
1104 switch (mb->mbxCommand) {
1107 lpfc_sli_pcimem_bcopy(mqe->un.read_rev.fw_name,
1108 mqe->un.read_rev.fw_name, 16);
1109 lpfc_sli_pcimem_bcopy(mqe->un.read_rev.ulp_fw_name,
1110 mqe->un.read_rev.ulp_fw_name, 16);
1119 * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
1120 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1121 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1123 * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
1124 * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
1125 * the Sequence Length Test using the fields in the Selection Profile 2
1126 * extension in words 20:31.
1129 lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
1130 struct lpfc_hbq_init *hbq_desc)
1132 hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
1133 hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
1134 hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
1138 * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
1139 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1140 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1142 * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
1143 * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
1144 * the Sequence Length Test and Byte Field Test using the fields in the
1145 * Selection Profile 3 extension in words 20:31.
1148 lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
1149 struct lpfc_hbq_init *hbq_desc)
1151 hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
1152 hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
1153 hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
1154 hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
1155 memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
1156 sizeof(hbqmb->profiles.profile3.cmdmatch));
1160 * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
1161 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1162 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1164 * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
1165 * HBA tests the initial frame of an incoming sequence using the frame's
1166 * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
1167 * and Byte Field Test using the fields in the Selection Profile 5 extension
1171 lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
1172 struct lpfc_hbq_init *hbq_desc)
1174 hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
1175 hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
1176 hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
1177 hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
1178 memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
1179 sizeof(hbqmb->profiles.profile5.cmdmatch));
1183 * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
1184 * @phba: pointer to lpfc hba data structure.
1185 * @id: HBQ identifier.
1186 * @hbq_desc: pointer to the HBA descriptor data structure.
1187 * @hbq_entry_index: index of the HBQ entry data structures.
1188 * @pmb: pointer to the driver internal queue element for mailbox command.
1190 * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
1191 * an HBQ. The configuration binds events that require buffers to a particular
1192 * ring and HBQ based on a selection profile.
1194 * This routine prepares the mailbox command for configuring an HBQ.
1197 lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
1198 struct lpfc_hbq_init *hbq_desc,
1199 uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
1202 MAILBOX_t *mb = &pmb->u.mb;
1203 struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
1205 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1207 hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
1208 hbqmb->recvNotify = hbq_desc->rn; /* Receive
1210 hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
1211 * # in words 0-19 */
1212 hbqmb->profile = hbq_desc->profile; /* Selection profile:
1215 hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
1218 hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
1220 hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
1224 hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
1225 hbq_entry_index * sizeof(struct lpfc_hbq_entry);
1226 hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
1228 mb->mbxCommand = MBX_CONFIG_HBQ;
1229 mb->mbxOwner = OWN_HOST;
1231 /* Copy info for profiles 2,3,5. Other
1232 * profiles this area is reserved
1234 if (hbq_desc->profile == 2)
1235 lpfc_build_hbq_profile2(hbqmb, hbq_desc);
1236 else if (hbq_desc->profile == 3)
1237 lpfc_build_hbq_profile3(hbqmb, hbq_desc);
1238 else if (hbq_desc->profile == 5)
1239 lpfc_build_hbq_profile5(hbqmb, hbq_desc);
1241 /* Return if no rctl / type masks for this HBQ */
1242 if (!hbq_desc->mask_count)
1245 /* Otherwise we setup specific rctl / type masks for this HBQ */
1246 for (i = 0; i < hbq_desc->mask_count; i++) {
1247 hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
1248 hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
1249 hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
1250 hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
1257 * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
1258 * @phba: pointer to lpfc hba data structure.
1259 * @ring: ring number/index
1260 * @pmb: pointer to the driver internal queue element for mailbox command.
1262 * The configure ring mailbox command is used to configure an IOCB ring. This
1263 * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1264 * ring. This is used to map incoming sequences to a particular ring whose
1265 * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1266 * attempt to configure a ring whose number is greater than the number
1267 * specified in the Port Control Block (PCB). It is an error to issue the
1268 * configure ring command more than once with the same ring number. The HBA
1269 * returns an error if the driver attempts this.
1271 * This routine prepares the mailbox command for configuring IOCB ring.
1274 lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
1277 MAILBOX_t *mb = &pmb->u.mb;
1278 struct lpfc_sli *psli;
1279 struct lpfc_sli_ring *pring;
1281 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1283 mb->un.varCfgRing.ring = ring;
1284 mb->un.varCfgRing.maxOrigXchg = 0;
1285 mb->un.varCfgRing.maxRespXchg = 0;
1286 mb->un.varCfgRing.recvNotify = 1;
1289 pring = &psli->sli3_ring[ring];
1290 mb->un.varCfgRing.numMask = pring->num_mask;
1291 mb->mbxCommand = MBX_CONFIG_RING;
1292 mb->mbxOwner = OWN_HOST;
1294 /* Is this ring configured for a specific profile */
1295 if (pring->prt[0].profile) {
1296 mb->un.varCfgRing.profile = pring->prt[0].profile;
1300 /* Otherwise we setup specific rctl / type masks for this ring */
1301 for (i = 0; i < pring->num_mask; i++) {
1302 mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
1303 if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ)
1304 mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
1306 mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
1307 mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
1308 mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
1315 * lpfc_config_port - Prepare a mailbox command for configuring port
1316 * @phba: pointer to lpfc hba data structure.
1317 * @pmb: pointer to the driver internal queue element for mailbox command.
1319 * The configure port mailbox command is used to identify the Port Control
1320 * Block (PCB) in the driver memory. After this command is issued, the
1321 * driver must not access the mailbox in the HBA without first resetting
1322 * the HBA. The HBA may copy the PCB information to internal storage for
1323 * subsequent use; the driver can not change the PCB information unless it
1326 * This routine prepares the mailbox command for configuring port.
1329 lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1331 MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
1332 MAILBOX_t *mb = &pmb->u.mb;
1333 dma_addr_t pdma_addr;
1334 uint32_t bar_low, bar_high;
1336 struct lpfc_hgp hgp;
1338 uint32_t pgp_offset;
1340 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1341 mb->mbxCommand = MBX_CONFIG_PORT;
1342 mb->mbxOwner = OWN_HOST;
1344 mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
1346 offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
1347 pdma_addr = phba->slim2p.phys + offset;
1348 mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
1349 mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
1351 /* Always Host Group Pointer is in SLIM */
1352 mb->un.varCfgPort.hps = 1;
1354 /* If HBA supports SLI=3 ask for it */
1356 if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
1357 if (phba->cfg_enable_bg)
1358 mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
1359 mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
1360 mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
1361 mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
1362 if (phba->max_vpi && phba->cfg_enable_npiv &&
1363 phba->vpd.sli3Feat.cmv) {
1364 mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI;
1365 mb->un.varCfgPort.cmv = 1;
1367 mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
1369 phba->sli_rev = LPFC_SLI_REV2;
1370 mb->un.varCfgPort.sli_mode = phba->sli_rev;
1372 /* If this is an SLI3 port, configure async status notification. */
1373 if (phba->sli_rev == LPFC_SLI_REV3)
1374 mb->un.varCfgPort.casabt = 1;
1377 phba->pcb->type = TYPE_NATIVE_SLI2;
1378 phba->pcb->feature = FEATURE_INITIAL_SLI2;
1380 /* Setup Mailbox pointers */
1381 phba->pcb->mailBoxSize = sizeof(MAILBOX_t) + MAILBOX_EXT_SIZE;
1382 offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
1383 pdma_addr = phba->slim2p.phys + offset;
1384 phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
1385 phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
1388 * Setup Host Group ring pointer.
1390 * For efficiency reasons, the ring get/put pointers can be
1391 * placed in adapter memory (SLIM) rather than in host memory.
1392 * This allows firmware to avoid PCI reads/writes when updating
1393 * and checking pointers.
1395 * The firmware recognizes the use of SLIM memory by comparing
1396 * the address of the get/put pointers structure with that of
1397 * the SLIM BAR (BAR0).
1399 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1400 * (the hardware's view of the base address), not the OS's
1401 * value of pci_resource_start() as the OS value may be a cookie
1402 * for ioremap/iomap.
1406 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
1407 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
1410 * Set up HGP - Port Memory
1412 * The port expects the host get/put pointers to reside in memory
1413 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1414 * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
1415 * words (0x40 bytes). This area is not reserved if HBQs are
1416 * configured in SLI-3.
1418 * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1427 * Reserved 0xa0-0xbf
1428 * If HBQs configured:
1429 * HBQ 0 Put ptr 0xc0
1430 * HBQ 1 Put ptr 0xc4
1431 * HBQ 2 Put ptr 0xc8
1433 * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1437 if (phba->cfg_hostmem_hgp && phba->sli_rev != 3) {
1438 phba->host_gp = (struct lpfc_hgp __iomem *)
1439 &phba->mbox->us.s2.host[0];
1440 phba->hbq_put = NULL;
1441 offset = (uint8_t *)&phba->mbox->us.s2.host -
1442 (uint8_t *)phba->slim2p.virt;
1443 pdma_addr = phba->slim2p.phys + offset;
1444 phba->pcb->hgpAddrHigh = putPaddrHigh(pdma_addr);
1445 phba->pcb->hgpAddrLow = putPaddrLow(pdma_addr);
1447 /* Always Host Group Pointer is in SLIM */
1448 mb->un.varCfgPort.hps = 1;
1450 if (phba->sli_rev == 3) {
1451 phba->host_gp = &mb_slim->us.s3.host[0];
1452 phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
1454 phba->host_gp = &mb_slim->us.s2.host[0];
1455 phba->hbq_put = NULL;
1458 /* mask off BAR0's flag bits 0 - 3 */
1459 phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
1460 (void __iomem *)phba->host_gp -
1461 (void __iomem *)phba->MBslimaddr;
1462 if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
1463 phba->pcb->hgpAddrHigh = bar_high;
1465 phba->pcb->hgpAddrHigh = 0;
1466 /* write HGP data to SLIM at the required longword offset */
1467 memset(&hgp, 0, sizeof(struct lpfc_hgp));
1469 for (i = 0; i < phba->sli.num_rings; i++) {
1470 lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
1471 sizeof(*phba->host_gp));
1475 /* Setup Port Group offset */
1476 if (phba->sli_rev == 3)
1477 pgp_offset = offsetof(struct lpfc_sli2_slim,
1478 mbx.us.s3_pgp.port);
1480 pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
1481 pdma_addr = phba->slim2p.phys + pgp_offset;
1482 phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
1483 phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
1485 /* Use callback routine to setp rings in the pcb */
1486 lpfc_config_pcb_setup(phba);
1488 /* special handling for LC HBAs */
1489 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
1490 uint32_t hbainit[5];
1492 lpfc_hba_init(phba, hbainit);
1494 memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
1497 /* Swap PCB if needed */
1498 lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
1502 * lpfc_kill_board - Prepare a mailbox command for killing board
1503 * @phba: pointer to lpfc hba data structure.
1504 * @pmb: pointer to the driver internal queue element for mailbox command.
1506 * The kill board mailbox command is used to tell firmware to perform a
1507 * graceful shutdown of a channel on a specified board to prepare for reset.
1508 * When the kill board mailbox command is received, the ER3 bit is set to 1
1509 * in the Host Status register and the ER Attention bit is set to 1 in the
1510 * Host Attention register of the HBA function that received the kill board
1513 * This routine prepares the mailbox command for killing the board in
1514 * preparation for a graceful shutdown.
1517 lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1519 MAILBOX_t *mb = &pmb->u.mb;
1521 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1522 mb->mbxCommand = MBX_KILL_BOARD;
1523 mb->mbxOwner = OWN_HOST;
1528 * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
1529 * @phba: pointer to lpfc hba data structure.
1530 * @mbq: pointer to the driver internal queue element for mailbox command.
1532 * Driver maintains a internal mailbox command queue implemented as a linked
1533 * list. When a mailbox command is issued, it shall be put into the mailbox
1534 * command queue such that they shall be processed orderly as HBA can process
1535 * one mailbox command at a time.
1538 lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1540 struct lpfc_sli *psli;
1544 list_add_tail(&mbq->list, &psli->mboxq);
1552 * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
1553 * @phba: pointer to lpfc hba data structure.
1555 * Driver maintains a internal mailbox command queue implemented as a linked
1556 * list. When a mailbox command is issued, it shall be put into the mailbox
1557 * command queue such that they shall be processed orderly as HBA can process
1558 * one mailbox command at a time. After HBA finished processing a mailbox
1559 * command, the driver will remove a pending mailbox command from the head of
1560 * the mailbox command queue and send to the HBA for processing.
1563 * pointer to the driver internal queue element for mailbox command.
1566 lpfc_mbox_get(struct lpfc_hba * phba)
1568 LPFC_MBOXQ_t *mbq = NULL;
1569 struct lpfc_sli *psli = &phba->sli;
1571 list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
1579 * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
1580 * @phba: pointer to lpfc hba data structure.
1581 * @mbq: pointer to the driver internal queue element for mailbox command.
1583 * This routine put the completed mailbox command into the mailbox command
1584 * complete list. This is the unlocked version of the routine. The mailbox
1585 * complete list is used by the driver worker thread to process mailbox
1586 * complete callback functions outside the driver interrupt handler.
1589 __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
1591 list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
1595 * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
1596 * @phba: pointer to lpfc hba data structure.
1597 * @mbq: pointer to the driver internal queue element for mailbox command.
1599 * This routine put the completed mailbox command into the mailbox command
1600 * complete list. This is the locked version of the routine. The mailbox
1601 * complete list is used by the driver worker thread to process mailbox
1602 * complete callback functions outside the driver interrupt handler.
1605 lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
1607 unsigned long iflag;
1609 /* This function expects to be called from interrupt context */
1610 spin_lock_irqsave(&phba->hbalock, iflag);
1611 __lpfc_mbox_cmpl_put(phba, mbq);
1612 spin_unlock_irqrestore(&phba->hbalock, iflag);
1617 * lpfc_mbox_cmd_check - Check the validality of a mailbox command
1618 * @phba: pointer to lpfc hba data structure.
1619 * @mboxq: pointer to the driver internal queue element for mailbox command.
1621 * This routine is to check whether a mailbox command is valid to be issued.
1622 * This check will be performed by both the mailbox issue API when a client
1623 * is to issue a mailbox command to the mailbox transport.
1625 * Return 0 - pass the check, -ENODEV - fail the check
1628 lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1630 /* Mailbox command that have a completion handler must also have a
1633 if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
1634 mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
1635 if (!mboxq->vport) {
1636 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
1637 "1814 Mbox x%x failed, no vport\n",
1638 mboxq->u.mb.mbxCommand);
1647 * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
1648 * @phba: pointer to lpfc hba data structure.
1650 * This routine is to check whether the HBA device is ready for posting a
1651 * mailbox command. It is used by the mailbox transport API at the time the
1652 * to post a mailbox command to the device.
1654 * Return 0 - pass the check, -ENODEV - fail the check
1657 lpfc_mbox_dev_check(struct lpfc_hba *phba)
1659 /* If the PCI channel is in offline state, do not issue mbox */
1660 if (unlikely(pci_channel_offline(phba->pcidev)))
1663 /* If the HBA is in error state, do not issue mbox */
1664 if (phba->link_state == LPFC_HBA_ERROR)
1671 * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
1672 * @phba: pointer to lpfc hba data structure.
1673 * @mboxq: pointer to the driver internal queue element for mailbox command.
1675 * This routine retrieves the proper timeout value according to the mailbox
1679 * Timeout value to be used for the given mailbox command
1682 lpfc_mbox_tmo_val(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1684 MAILBOX_t *mbox = &mboxq->u.mb;
1685 uint8_t subsys, opcode;
1687 switch (mbox->mbxCommand) {
1688 case MBX_WRITE_NV: /* 0x03 */
1689 case MBX_DUMP_MEMORY: /* 0x17 */
1690 case MBX_UPDATE_CFG: /* 0x1B */
1691 case MBX_DOWN_LOAD: /* 0x1C */
1692 case MBX_DEL_LD_ENTRY: /* 0x1D */
1693 case MBX_WRITE_VPARMS: /* 0x32 */
1694 case MBX_LOAD_AREA: /* 0x81 */
1695 case MBX_WRITE_WWN: /* 0x98 */
1696 case MBX_LOAD_EXP_ROM: /* 0x9C */
1697 case MBX_ACCESS_VDATA: /* 0xA5 */
1698 return LPFC_MBOX_TMO_FLASH_CMD;
1699 case MBX_SLI4_CONFIG: /* 0x9b */
1700 subsys = lpfc_sli_config_mbox_subsys_get(phba, mboxq);
1701 opcode = lpfc_sli_config_mbox_opcode_get(phba, mboxq);
1702 if (subsys == LPFC_MBOX_SUBSYSTEM_COMMON) {
1704 case LPFC_MBOX_OPCODE_READ_OBJECT:
1705 case LPFC_MBOX_OPCODE_WRITE_OBJECT:
1706 case LPFC_MBOX_OPCODE_READ_OBJECT_LIST:
1707 case LPFC_MBOX_OPCODE_DELETE_OBJECT:
1708 case LPFC_MBOX_OPCODE_GET_PROFILE_LIST:
1709 case LPFC_MBOX_OPCODE_SET_ACT_PROFILE:
1710 case LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG:
1711 case LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG:
1712 case LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG:
1713 case LPFC_MBOX_OPCODE_GET_PROFILE_CAPACITIES:
1714 case LPFC_MBOX_OPCODE_SEND_ACTIVATION:
1715 case LPFC_MBOX_OPCODE_RESET_LICENSES:
1716 case LPFC_MBOX_OPCODE_SET_BOOT_CONFIG:
1717 case LPFC_MBOX_OPCODE_GET_VPD_DATA:
1718 case LPFC_MBOX_OPCODE_SET_PHYSICAL_LINK_CONFIG:
1719 return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO;
1722 if (subsys == LPFC_MBOX_SUBSYSTEM_FCOE) {
1724 case LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS:
1725 return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO;
1728 return LPFC_MBOX_SLI4_CONFIG_TMO;
1730 return LPFC_MBOX_TMO;
1734 * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
1735 * @mbox: pointer to lpfc mbox command.
1736 * @sgentry: sge entry index.
1737 * @phyaddr: physical address for the sge
1738 * @length: Length of the sge.
1740 * This routine sets up an entry in the non-embedded mailbox command at the sge
1744 lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry,
1745 dma_addr_t phyaddr, uint32_t length)
1747 struct lpfc_mbx_nembed_cmd *nembed_sge;
1749 nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1750 &mbox->u.mqe.un.nembed_cmd;
1751 nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr);
1752 nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr);
1753 nembed_sge->sge[sgentry].length = length;
1757 * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
1758 * @mbox: pointer to lpfc mbox command.
1759 * @sgentry: sge entry index.
1760 * @sge: pointer to lpfc mailbox sge to load into.
1762 * This routine gets an entry from the non-embedded mailbox command at the sge
1766 lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry,
1767 struct lpfc_mbx_sge *sge)
1769 struct lpfc_mbx_nembed_cmd *nembed_sge;
1771 nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1772 &mbox->u.mqe.un.nembed_cmd;
1773 sge->pa_lo = nembed_sge->sge[sgentry].pa_lo;
1774 sge->pa_hi = nembed_sge->sge[sgentry].pa_hi;
1775 sge->length = nembed_sge->sge[sgentry].length;
1779 * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
1780 * @phba: pointer to lpfc hba data structure.
1781 * @mbox: pointer to lpfc mbox command.
1783 * This routine cleans up and releases an SLI4 mailbox command that was
1784 * configured using lpfc_sli4_config. It accounts for the embedded and
1785 * non-embedded config types.
1788 lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1790 struct lpfc_mbx_sli4_config *sli4_cfg;
1791 struct lpfc_mbx_sge sge;
1793 uint32_t sgecount, sgentry;
1795 sli4_cfg = &mbox->u.mqe.un.sli4_config;
1797 /* For embedded mbox command, just free the mbox command */
1798 if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1799 mempool_free(mbox, phba->mbox_mem_pool);
1803 /* For non-embedded mbox command, we need to free the pages first */
1804 sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr);
1805 /* There is nothing we can do if there is no sge address array */
1806 if (unlikely(!mbox->sge_array)) {
1807 mempool_free(mbox, phba->mbox_mem_pool);
1810 /* Each non-embedded DMA memory was allocated in the length of a page */
1811 for (sgentry = 0; sgentry < sgecount; sgentry++) {
1812 lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge);
1813 phyaddr = getPaddr(sge.pa_hi, sge.pa_lo);
1814 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
1815 mbox->sge_array->addr[sgentry], phyaddr);
1817 /* Free the sge address array memory */
1818 kfree(mbox->sge_array);
1819 /* Finally, free the mailbox command itself */
1820 mempool_free(mbox, phba->mbox_mem_pool);
1824 * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command
1825 * @phba: pointer to lpfc hba data structure.
1826 * @mbox: pointer to lpfc mbox command.
1827 * @subsystem: The sli4 config sub mailbox subsystem.
1828 * @opcode: The sli4 config sub mailbox command opcode.
1829 * @length: Length of the sli4 config mailbox command (including sub-header).
1830 * @emb: True if embedded mbox command should be setup.
1832 * This routine sets up the header fields of SLI4 specific mailbox command
1833 * for sending IOCTL command.
1835 * Return: the actual length of the mbox command allocated (mostly useful
1836 * for none embedded mailbox command).
1839 lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
1840 uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb)
1842 struct lpfc_mbx_sli4_config *sli4_config;
1843 union lpfc_sli4_cfg_shdr *cfg_shdr = NULL;
1846 uint32_t pagen, pcount;
1850 /* Set up SLI4 mailbox command header fields */
1851 memset(mbox, 0, sizeof(*mbox));
1852 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG);
1854 /* Set up SLI4 ioctl command header fields */
1855 sli4_config = &mbox->u.mqe.un.sli4_config;
1857 /* Setup for the embedded mbox command */
1859 /* Set up main header fields */
1860 bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
1861 sli4_config->header.cfg_mhdr.payload_length = length;
1862 /* Set up sub-header fields following main header */
1863 bf_set(lpfc_mbox_hdr_opcode,
1864 &sli4_config->header.cfg_shdr.request, opcode);
1865 bf_set(lpfc_mbox_hdr_subsystem,
1866 &sli4_config->header.cfg_shdr.request, subsystem);
1867 sli4_config->header.cfg_shdr.request.request_length =
1868 length - LPFC_MBX_CMD_HDR_LENGTH;
1872 /* Setup for the non-embedded mbox command */
1873 pcount = (SLI4_PAGE_ALIGN(length))/SLI4_PAGE_SIZE;
1874 pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ?
1875 LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount;
1876 /* Allocate record for keeping SGE virtual addresses */
1877 mbox->sge_array = kzalloc(sizeof(struct lpfc_mbx_nembed_sge_virt),
1879 if (!mbox->sge_array) {
1880 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1881 "2527 Failed to allocate non-embedded SGE "
1885 for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) {
1886 /* The DMA memory is always allocated in the length of a
1887 * page even though the last SGE might not fill up to a
1888 * page, this is used as a priori size of SLI4_PAGE_SIZE for
1889 * the later DMA memory free.
1891 viraddr = dma_alloc_coherent(&phba->pcidev->dev,
1892 SLI4_PAGE_SIZE, &phyaddr,
1894 /* In case of malloc fails, proceed with whatever we have */
1897 mbox->sge_array->addr[pagen] = viraddr;
1898 /* Keep the first page for later sub-header construction */
1900 cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr;
1901 resid_len = length - alloc_len;
1902 if (resid_len > SLI4_PAGE_SIZE) {
1903 lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
1905 alloc_len += SLI4_PAGE_SIZE;
1907 lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
1913 /* Set up main header fields in mailbox command */
1914 sli4_config->header.cfg_mhdr.payload_length = alloc_len;
1915 bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen);
1917 /* Set up sub-header fields into the first page */
1919 bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode);
1920 bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem);
1921 cfg_shdr->request.request_length =
1922 alloc_len - sizeof(union lpfc_sli4_cfg_shdr);
1924 /* The sub-header is in DMA memory, which needs endian converstion */
1926 lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
1927 sizeof(union lpfc_sli4_cfg_shdr));
1932 * lpfc_sli4_mbox_rsrc_extent - Initialize the opcode resource extent.
1933 * @phba: pointer to lpfc hba data structure.
1934 * @mbox: pointer to an allocated lpfc mbox resource.
1935 * @exts_count: the number of extents, if required, to allocate.
1936 * @rsrc_type: the resource extent type.
1937 * @emb: true if LPFC_SLI4_MBX_EMBED. false if LPFC_SLI4_MBX_NEMBED.
1939 * This routine completes the subcommand header for SLI4 resource extent
1940 * mailbox commands. It is called after lpfc_sli4_config. The caller must
1941 * pass an allocated mailbox and the attributes required to initialize the
1942 * mailbox correctly.
1944 * Return: the actual length of the mbox command allocated.
1947 lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
1948 uint16_t exts_count, uint16_t rsrc_type, bool emb)
1951 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc_extnt = NULL;
1952 void *virtaddr = NULL;
1954 /* Set up SLI4 ioctl command header fields */
1955 if (emb == LPFC_SLI4_MBX_NEMBED) {
1956 /* Get the first SGE entry from the non-embedded DMA memory */
1957 virtaddr = mbox->sge_array->addr[0];
1958 if (virtaddr == NULL)
1960 n_rsrc_extnt = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
1964 * The resource type is common to all extent Opcodes and resides in the
1967 if (emb == LPFC_SLI4_MBX_EMBED)
1968 bf_set(lpfc_mbx_alloc_rsrc_extents_type,
1969 &mbox->u.mqe.un.alloc_rsrc_extents.u.req,
1972 /* This is DMA data. Byteswap is required. */
1973 bf_set(lpfc_mbx_alloc_rsrc_extents_type,
1974 n_rsrc_extnt, rsrc_type);
1975 lpfc_sli_pcimem_bcopy(&n_rsrc_extnt->word4,
1976 &n_rsrc_extnt->word4,
1980 /* Complete the initialization for the particular Opcode. */
1981 opcode = lpfc_sli_config_mbox_opcode_get(phba, mbox);
1983 case LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT:
1984 if (emb == LPFC_SLI4_MBX_EMBED)
1985 bf_set(lpfc_mbx_alloc_rsrc_extents_cnt,
1986 &mbox->u.mqe.un.alloc_rsrc_extents.u.req,
1989 bf_set(lpfc_mbx_alloc_rsrc_extents_cnt,
1990 n_rsrc_extnt, exts_count);
1992 case LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT:
1993 case LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO:
1994 case LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT:
1995 /* Initialization is complete.*/
1998 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1999 "2929 Resource Extent Opcode x%x is "
2000 "unsupported\n", opcode);
2008 * lpfc_sli_config_mbox_subsys_get - Get subsystem from a sli_config mbox cmd
2009 * @phba: pointer to lpfc hba data structure.
2010 * @mbox: pointer to lpfc mbox command queue entry.
2012 * This routine gets the subsystem from a SLI4 specific SLI_CONFIG mailbox
2013 * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if the
2014 * sub-header is not present, subsystem LPFC_MBOX_SUBSYSTEM_NA (0x0) shall
2018 lpfc_sli_config_mbox_subsys_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
2020 struct lpfc_mbx_sli4_config *sli4_cfg;
2021 union lpfc_sli4_cfg_shdr *cfg_shdr;
2023 if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
2024 return LPFC_MBOX_SUBSYSTEM_NA;
2025 sli4_cfg = &mbox->u.mqe.un.sli4_config;
2027 /* For embedded mbox command, get opcode from embedded sub-header*/
2028 if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
2029 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
2030 return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request);
2033 /* For non-embedded mbox command, get opcode from first dma page */
2034 if (unlikely(!mbox->sge_array))
2035 return LPFC_MBOX_SUBSYSTEM_NA;
2036 cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
2037 return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request);
2041 * lpfc_sli_config_mbox_opcode_get - Get opcode from a sli_config mbox cmd
2042 * @phba: pointer to lpfc hba data structure.
2043 * @mbox: pointer to lpfc mbox command queue entry.
2045 * This routine gets the opcode from a SLI4 specific SLI_CONFIG mailbox
2046 * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if
2047 * the sub-header is not present, opcode LPFC_MBOX_OPCODE_NA (0x0) be
2051 lpfc_sli_config_mbox_opcode_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
2053 struct lpfc_mbx_sli4_config *sli4_cfg;
2054 union lpfc_sli4_cfg_shdr *cfg_shdr;
2056 if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
2057 return LPFC_MBOX_OPCODE_NA;
2058 sli4_cfg = &mbox->u.mqe.un.sli4_config;
2060 /* For embedded mbox command, get opcode from embedded sub-header*/
2061 if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
2062 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
2063 return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
2066 /* For non-embedded mbox command, get opcode from first dma page */
2067 if (unlikely(!mbox->sge_array))
2068 return LPFC_MBOX_OPCODE_NA;
2069 cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
2070 return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
2074 * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd
2075 * @phba: pointer to lpfc hba data structure.
2076 * @mboxq: pointer to lpfc mbox command.
2077 * @fcf_index: index to fcf table.
2079 * This routine routine allocates and constructs non-embedded mailbox command
2080 * for reading a FCF table entry referred by @fcf_index.
2082 * Return: pointer to the mailbox command constructed if successful, otherwise
2086 lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *phba,
2087 struct lpfcMboxq *mboxq,
2092 struct lpfc_mbx_sge sge;
2093 uint32_t alloc_len, req_len;
2094 struct lpfc_mbx_read_fcf_tbl *read_fcf;
2099 req_len = sizeof(struct fcf_record) +
2100 sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
2102 /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
2103 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
2104 LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
2105 LPFC_SLI4_MBX_NEMBED);
2107 if (alloc_len < req_len) {
2108 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2109 "0291 Allocated DMA memory size (x%x) is "
2110 "less than the requested DMA memory "
2111 "size (x%x)\n", alloc_len, req_len);
2115 /* Get the first SGE entry from the non-embedded DMA memory. This
2116 * routine only uses a single SGE.
2118 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
2119 virt_addr = mboxq->sge_array->addr[0];
2120 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
2122 /* Set up command fields */
2123 bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
2124 /* Perform necessary endian conversion */
2125 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
2126 lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
2132 * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
2133 * @phba: pointer to lpfc hba data structure.
2134 * @mboxq: pointer to lpfc mbox command.
2136 * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
2140 lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
2142 /* Set up SLI4 mailbox command header fields */
2143 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
2144 bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS);
2146 /* Set up host requested features. */
2147 bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
2148 bf_set(lpfc_mbx_rq_ftr_rq_perfh, &mboxq->u.mqe.un.req_ftrs, 1);
2150 /* Enable DIF (block guard) only if configured to do so. */
2151 if (phba->cfg_enable_bg)
2152 bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1);
2154 /* Enable NPIV only if configured to do so. */
2155 if (phba->max_vpi && phba->cfg_enable_npiv)
2156 bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1);
2158 if (phba->nvmet_support) {
2159 bf_set(lpfc_mbx_rq_ftr_rq_mrqp, &mboxq->u.mqe.un.req_ftrs, 1);
2160 /* iaab/iaar NOT set for now */
2161 bf_set(lpfc_mbx_rq_ftr_rq_iaab, &mboxq->u.mqe.un.req_ftrs, 0);
2162 bf_set(lpfc_mbx_rq_ftr_rq_iaar, &mboxq->u.mqe.un.req_ftrs, 0);
2165 /* Enable Application Services Header for appheader VMID */
2166 if (phba->cfg_vmid_app_header) {
2167 bf_set(lpfc_mbx_rq_ftr_rq_ashdr, &mboxq->u.mqe.un.req_ftrs, 1);
2168 bf_set(lpfc_ftr_ashdr, &phba->sli4_hba.sli4_flags, 1);
2174 * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
2175 * @mbox: pointer to lpfc mbox command to initialize.
2176 * @vport: Vport associated with the VF.
2178 * This routine initializes @mbox to all zeros and then fills in the mailbox
2179 * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
2180 * in the context of an FCF. The driver issues this command to setup a VFI
2181 * before issuing a FLOGI to login to the VSAN. The driver should also issue a
2182 * REG_VFI after a successful VSAN login.
2185 lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
2187 struct lpfc_mbx_init_vfi *init_vfi;
2189 memset(mbox, 0, sizeof(*mbox));
2190 mbox->vport = vport;
2191 init_vfi = &mbox->u.mqe.un.init_vfi;
2192 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI);
2193 bf_set(lpfc_init_vfi_vr, init_vfi, 1);
2194 bf_set(lpfc_init_vfi_vt, init_vfi, 1);
2195 bf_set(lpfc_init_vfi_vp, init_vfi, 1);
2196 bf_set(lpfc_init_vfi_vfi, init_vfi,
2197 vport->phba->sli4_hba.vfi_ids[vport->vfi]);
2198 bf_set(lpfc_init_vfi_vpi, init_vfi,
2199 vport->phba->vpi_ids[vport->vpi]);
2200 bf_set(lpfc_init_vfi_fcfi, init_vfi,
2201 vport->phba->fcf.fcfi);
2205 * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
2206 * @mbox: pointer to lpfc mbox command to initialize.
2207 * @vport: vport associated with the VF.
2208 * @phys: BDE DMA bus address used to send the service parameters to the HBA.
2210 * This routine initializes @mbox to all zeros and then fills in the mailbox
2211 * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
2212 * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
2213 * fabrics identified by VFI in the context of an FCF.
2216 lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys)
2218 struct lpfc_mbx_reg_vfi *reg_vfi;
2219 struct lpfc_hba *phba = vport->phba;
2220 uint8_t bbscn_fabric = 0, bbscn_max = 0, bbscn_def = 0;
2222 memset(mbox, 0, sizeof(*mbox));
2223 reg_vfi = &mbox->u.mqe.un.reg_vfi;
2224 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI);
2225 bf_set(lpfc_reg_vfi_vp, reg_vfi, 1);
2226 bf_set(lpfc_reg_vfi_vfi, reg_vfi,
2227 phba->sli4_hba.vfi_ids[vport->vfi]);
2228 bf_set(lpfc_reg_vfi_fcfi, reg_vfi, phba->fcf.fcfi);
2229 bf_set(lpfc_reg_vfi_vpi, reg_vfi, phba->vpi_ids[vport->vpi]);
2230 memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name));
2231 reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]);
2232 reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]);
2233 reg_vfi->e_d_tov = phba->fc_edtov;
2234 reg_vfi->r_a_tov = phba->fc_ratov;
2236 reg_vfi->bde.addrHigh = putPaddrHigh(phys);
2237 reg_vfi->bde.addrLow = putPaddrLow(phys);
2238 reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam);
2239 reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
2241 bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID);
2243 /* Only FC supports upd bit */
2244 if ((phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) &&
2245 (vport->fc_flag & FC_VFI_REGISTERED) &&
2246 (!phba->fc_topology_changed))
2247 bf_set(lpfc_reg_vfi_upd, reg_vfi, 1);
2249 bf_set(lpfc_reg_vfi_bbcr, reg_vfi, 0);
2250 bf_set(lpfc_reg_vfi_bbscn, reg_vfi, 0);
2251 bbscn_fabric = (phba->fc_fabparam.cmn.bbRcvSizeMsb >> 4) & 0xF;
2253 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
2254 bbscn_fabric != 0) {
2255 bbscn_max = bf_get(lpfc_bbscn_max,
2256 &phba->sli4_hba.bbscn_params);
2257 if (bbscn_fabric <= bbscn_max) {
2258 bbscn_def = bf_get(lpfc_bbscn_def,
2259 &phba->sli4_hba.bbscn_params);
2261 if (bbscn_fabric > bbscn_def)
2262 bf_set(lpfc_reg_vfi_bbscn, reg_vfi,
2265 bf_set(lpfc_reg_vfi_bbscn, reg_vfi, bbscn_def);
2267 bf_set(lpfc_reg_vfi_bbcr, reg_vfi, 1);
2270 lpfc_printf_vlog(vport, KERN_INFO, LOG_MBOX,
2271 "3134 Register VFI, mydid:x%x, fcfi:%d, "
2272 " vfi:%d, vpi:%d, fc_pname:%x%x fc_flag:x%x"
2273 " port_state:x%x topology chg:%d bbscn_fabric :%d\n",
2276 phba->sli4_hba.vfi_ids[vport->vfi],
2277 phba->vpi_ids[vport->vpi],
2278 reg_vfi->wwn[0], reg_vfi->wwn[1], vport->fc_flag,
2279 vport->port_state, phba->fc_topology_changed,
2284 * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
2285 * @phba: pointer to the hba structure to init the VPI for.
2286 * @mbox: pointer to lpfc mbox command to initialize.
2287 * @vpi: VPI to be initialized.
2289 * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
2290 * command to activate a virtual N_Port. The HBA assigns a MAC address to use
2291 * with the virtual N Port. The SLI Host issues this command before issuing a
2292 * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
2293 * successful virtual NPort login.
2296 lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi)
2298 memset(mbox, 0, sizeof(*mbox));
2299 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI);
2300 bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi,
2301 phba->vpi_ids[vpi]);
2302 bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi,
2303 phba->sli4_hba.vfi_ids[phba->pport->vfi]);
2307 * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
2308 * @mbox: pointer to lpfc mbox command to initialize.
2309 * @vport: vport associated with the VF.
2311 * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
2312 * (logical NPort) into the inactive state. The SLI Host must have logged out
2313 * and unregistered all remote N_Ports to abort any activity on the virtual
2314 * fabric. The SLI Port posts the mailbox response after marking the virtual
2318 lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
2320 memset(mbox, 0, sizeof(*mbox));
2321 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI);
2322 bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi,
2323 vport->phba->sli4_hba.vfi_ids[vport->vfi]);
2327 * lpfc_sli4_dump_cfg_rg23 - Dump sli4 port config region 23
2328 * @phba: pointer to the hba structure containing.
2329 * @mbox: pointer to lpfc mbox command to initialize.
2331 * This function create a SLI4 dump mailbox command to dump configure
2335 lpfc_sli4_dump_cfg_rg23(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
2337 struct lpfc_dmabuf *mp = NULL;
2341 memset(mbox, 0, sizeof(*mbox));
2344 rc = lpfc_mbox_rsrc_prep(phba, mbox);
2346 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
2347 "2569 %s: memory allocation failed\n",
2352 mb->mbxCommand = MBX_DUMP_MEMORY;
2353 mb->un.varDmp.type = DMP_NV_PARAMS;
2354 mb->un.varDmp.region_id = DMP_REGION_23;
2355 mb->un.varDmp.sli4_length = DMP_RGN23_SIZE;
2357 mb->un.varWords[3] = putPaddrLow(mp->phys);
2358 mb->un.varWords[4] = putPaddrHigh(mp->phys);
2363 lpfc_mbx_cmpl_rdp_link_stat(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2367 struct lpfc_rdp_context *rdp_context =
2368 (struct lpfc_rdp_context *)(mboxq->ctx_ndlp);
2374 memcpy(&rdp_context->link_stat, &mb->un.varRdLnk, sizeof(READ_LNK_VAR));
2379 lpfc_mbox_rsrc_cleanup(phba, mboxq, MBOX_THD_UNLOCKED);
2380 rdp_context->cmpl(phba, rdp_context, rc);
2384 lpfc_mbx_cmpl_rdp_page_a2(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
2386 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
2387 struct lpfc_rdp_context *rdp_context =
2388 (struct lpfc_rdp_context *)(mbox->ctx_ndlp);
2390 if (bf_get(lpfc_mqe_status, &mbox->u.mqe))
2391 goto error_mbox_free;
2393 lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a2,
2394 DMP_SFF_PAGE_A2_SIZE);
2396 lpfc_read_lnk_stat(phba, mbox);
2397 mbox->vport = rdp_context->ndlp->vport;
2399 /* Save the dma buffer for cleanup in the final completion. */
2401 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_link_stat;
2402 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
2403 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == MBX_NOT_FINISHED)
2404 goto error_mbox_free;
2409 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
2410 rdp_context->cmpl(phba, rdp_context, FAILURE);
2414 lpfc_mbx_cmpl_rdp_page_a0(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
2417 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(mbox->ctx_buf);
2418 struct lpfc_rdp_context *rdp_context =
2419 (struct lpfc_rdp_context *)(mbox->ctx_ndlp);
2421 if (bf_get(lpfc_mqe_status, &mbox->u.mqe))
2424 lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a0,
2425 DMP_SFF_PAGE_A0_SIZE);
2427 memset(mbox, 0, sizeof(*mbox));
2429 memset(mp->virt, 0, DMP_SFF_PAGE_A2_SIZE);
2430 INIT_LIST_HEAD(&mp->list);
2432 /* save address for completion */
2434 mbox->vport = rdp_context->ndlp->vport;
2436 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY);
2437 bf_set(lpfc_mbx_memory_dump_type3_type,
2438 &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD);
2439 bf_set(lpfc_mbx_memory_dump_type3_link,
2440 &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port);
2441 bf_set(lpfc_mbx_memory_dump_type3_page_no,
2442 &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A2);
2443 bf_set(lpfc_mbx_memory_dump_type3_length,
2444 &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A2_SIZE);
2445 mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
2446 mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
2448 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a2;
2449 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
2450 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
2451 if (rc == MBX_NOT_FINISHED)
2457 lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
2458 rdp_context->cmpl(phba, rdp_context, FAILURE);
2463 * lpfc_sli4_dump_page_a0 - Dump sli4 read SFP Diagnostic.
2464 * @phba: pointer to the hba structure containing.
2465 * @mbox: pointer to lpfc mbox command to initialize.
2467 * This function create a SLI4 dump mailbox command to dump configure
2471 lpfc_sli4_dump_page_a0(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
2474 struct lpfc_dmabuf *mp = NULL;
2476 memset(mbox, 0, sizeof(*mbox));
2478 rc = lpfc_mbox_rsrc_prep(phba, mbox);
2480 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
2481 "3569 dump type 3 page 0xA0 allocation failed\n");
2485 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY);
2486 bf_set(lpfc_mbx_memory_dump_type3_type,
2487 &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD);
2488 bf_set(lpfc_mbx_memory_dump_type3_link,
2489 &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port);
2490 bf_set(lpfc_mbx_memory_dump_type3_page_no,
2491 &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A0);
2492 bf_set(lpfc_mbx_memory_dump_type3_length,
2493 &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A0_SIZE);
2496 mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
2497 mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
2503 * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
2504 * @phba: pointer to the hba structure containing the FCF index and RQ ID.
2505 * @mbox: pointer to lpfc mbox command to initialize.
2507 * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
2508 * SLI Host uses the command to activate an FCF after it has acquired FCF
2509 * information via a READ_FCF mailbox command. This mailbox command also is used
2510 * to indicate where received unsolicited frames from this FCF will be sent. By
2511 * default this routine will set up the FCF to forward all unsolicited frames
2512 * to the RQ ID passed in the @phba. This can be overridden by the caller for
2513 * more complicated setups.
2516 lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
2518 struct lpfc_mbx_reg_fcfi *reg_fcfi;
2520 memset(mbox, 0, sizeof(*mbox));
2521 reg_fcfi = &mbox->u.mqe.un.reg_fcfi;
2522 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI);
2523 if (phba->nvmet_support == 0) {
2524 bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi,
2525 phba->sli4_hba.hdr_rq->queue_id);
2526 /* Match everything - rq_id0 */
2527 bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, 0);
2528 bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0);
2529 bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi, 0);
2530 bf_set(lpfc_reg_fcfi_rctl_mask0, reg_fcfi, 0);
2532 bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
2534 /* addr mode is bit wise inverted value of fcf addr_mode */
2535 bf_set(lpfc_reg_fcfi_mam, reg_fcfi,
2536 (~phba->fcf.addr_mode) & 0x3);
2538 /* This is ONLY for NVMET MRQ == 1 */
2539 if (phba->cfg_nvmet_mrq != 1)
2542 bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi,
2543 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id);
2544 /* Match type FCP - rq_id0 */
2545 bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, FC_TYPE_FCP);
2546 bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0xff);
2547 bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi,
2548 FC_RCTL_DD_UNSOL_CMD);
2550 bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi,
2551 phba->sli4_hba.hdr_rq->queue_id);
2552 /* Match everything else - rq_id1 */
2553 bf_set(lpfc_reg_fcfi_type_match1, reg_fcfi, 0);
2554 bf_set(lpfc_reg_fcfi_type_mask1, reg_fcfi, 0);
2555 bf_set(lpfc_reg_fcfi_rctl_match1, reg_fcfi, 0);
2556 bf_set(lpfc_reg_fcfi_rctl_mask1, reg_fcfi, 0);
2558 bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
2559 bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
2560 bf_set(lpfc_reg_fcfi_info_index, reg_fcfi,
2561 phba->fcf.current_rec.fcf_indx);
2562 if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) {
2563 bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
2564 bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi,
2565 phba->fcf.current_rec.vlan_id);
2570 * lpfc_reg_fcfi_mrq - Initialize the REG_FCFI_MRQ mailbox command
2571 * @phba: pointer to the hba structure containing the FCF index and RQ ID.
2572 * @mbox: pointer to lpfc mbox command to initialize.
2573 * @mode: 0 to register FCFI, 1 to register MRQs
2575 * The REG_FCFI_MRQ mailbox command supports Fibre Channel Forwarders (FCFs).
2576 * The SLI Host uses the command to activate an FCF after it has acquired FCF
2577 * information via a READ_FCF mailbox command. This mailbox command also is used
2578 * to indicate where received unsolicited frames from this FCF will be sent. By
2579 * default this routine will set up the FCF to forward all unsolicited frames
2580 * to the RQ ID passed in the @phba. This can be overridden by the caller for
2581 * more complicated setups.
2584 lpfc_reg_fcfi_mrq(struct lpfc_hba *phba, struct lpfcMboxq *mbox, int mode)
2586 struct lpfc_mbx_reg_fcfi_mrq *reg_fcfi;
2588 /* This is ONLY for MRQ */
2589 if (phba->cfg_nvmet_mrq <= 1)
2592 memset(mbox, 0, sizeof(*mbox));
2593 reg_fcfi = &mbox->u.mqe.un.reg_fcfi_mrq;
2594 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI_MRQ);
2596 bf_set(lpfc_reg_fcfi_mrq_info_index, reg_fcfi,
2597 phba->fcf.current_rec.fcf_indx);
2598 if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) {
2599 bf_set(lpfc_reg_fcfi_mrq_vv, reg_fcfi, 1);
2600 bf_set(lpfc_reg_fcfi_mrq_vlan_tag, reg_fcfi,
2601 phba->fcf.current_rec.vlan_id);
2606 bf_set(lpfc_reg_fcfi_mrq_rq_id0, reg_fcfi,
2607 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id);
2608 /* Match NVME frames of type FCP (protocol NVME) - rq_id0 */
2609 bf_set(lpfc_reg_fcfi_mrq_type_match0, reg_fcfi, FC_TYPE_FCP);
2610 bf_set(lpfc_reg_fcfi_mrq_type_mask0, reg_fcfi, 0xff);
2611 bf_set(lpfc_reg_fcfi_mrq_rctl_match0, reg_fcfi, FC_RCTL_DD_UNSOL_CMD);
2612 bf_set(lpfc_reg_fcfi_mrq_rctl_mask0, reg_fcfi, 0xff);
2613 bf_set(lpfc_reg_fcfi_mrq_ptc0, reg_fcfi, 1);
2614 bf_set(lpfc_reg_fcfi_mrq_pt0, reg_fcfi, 1);
2616 bf_set(lpfc_reg_fcfi_mrq_policy, reg_fcfi, 3); /* NVME connection id */
2617 bf_set(lpfc_reg_fcfi_mrq_mode, reg_fcfi, 1);
2618 bf_set(lpfc_reg_fcfi_mrq_filter, reg_fcfi, 1); /* rq_id0 */
2619 bf_set(lpfc_reg_fcfi_mrq_npairs, reg_fcfi, phba->cfg_nvmet_mrq);
2621 bf_set(lpfc_reg_fcfi_mrq_rq_id1, reg_fcfi,
2622 phba->sli4_hba.hdr_rq->queue_id);
2623 /* Match everything - rq_id1 */
2624 bf_set(lpfc_reg_fcfi_mrq_type_match1, reg_fcfi, 0);
2625 bf_set(lpfc_reg_fcfi_mrq_type_mask1, reg_fcfi, 0);
2626 bf_set(lpfc_reg_fcfi_mrq_rctl_match1, reg_fcfi, 0);
2627 bf_set(lpfc_reg_fcfi_mrq_rctl_mask1, reg_fcfi, 0);
2629 bf_set(lpfc_reg_fcfi_mrq_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
2630 bf_set(lpfc_reg_fcfi_mrq_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
2634 * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
2635 * @mbox: pointer to lpfc mbox command to initialize.
2636 * @fcfi: FCFI to be unregistered.
2638 * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
2639 * The SLI Host uses the command to inactivate an FCFI.
2642 lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi)
2644 memset(mbox, 0, sizeof(*mbox));
2645 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI);
2646 bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi);
2650 * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
2651 * @mbox: pointer to lpfc mbox command to initialize.
2652 * @ndlp: The nodelist structure that describes the RPI to resume.
2654 * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
2658 lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
2660 struct lpfc_hba *phba = ndlp->phba;
2661 struct lpfc_mbx_resume_rpi *resume_rpi;
2663 memset(mbox, 0, sizeof(*mbox));
2664 resume_rpi = &mbox->u.mqe.un.resume_rpi;
2665 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI);
2666 bf_set(lpfc_resume_rpi_index, resume_rpi,
2667 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
2668 bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI);
2669 resume_rpi->event_tag = ndlp->phba->fc_eventTag;