xref: /openbmc/linux/drivers/scsi/lpfc/lpfc_mbox.c (revision 442336a5)
1dea3101eS /*******************************************************************
2dea3101eS  * This file is part of the Emulex Linux Device Driver for         *
3c44ce173SJames.Smart@Emulex.Com  * Fibre Channel Host Bus Adapters.                                *
466c20a97SJames Smart  * Copyright (C) 2017-2022 Broadcom. All Rights Reserved. The term *
54ae2ebdeSJames Smart  * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.     *
650611577SJames Smart  * Copyright (C) 2004-2016 Emulex.  All rights reserved.           *
7c44ce173SJames.Smart@Emulex.Com  * EMULEX and SLI are trademarks of Emulex.                        *
8d080abe0SJames Smart  * www.broadcom.com                                                *
9c44ce173SJames.Smart@Emulex.Com  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
10dea3101eS  *                                                                 *
11dea3101eS  * This program is free software; you can redistribute it and/or   *
12c44ce173SJames.Smart@Emulex.Com  * modify it under the terms of version 2 of the GNU General       *
13c44ce173SJames.Smart@Emulex.Com  * Public License as published by the Free Software Foundation.    *
14c44ce173SJames.Smart@Emulex.Com  * This program is distributed in the hope that it will be useful. *
15c44ce173SJames.Smart@Emulex.Com  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
16c44ce173SJames.Smart@Emulex.Com  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
17c44ce173SJames.Smart@Emulex.Com  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
18c44ce173SJames.Smart@Emulex.Com  * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19c44ce173SJames.Smart@Emulex.Com  * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
20c44ce173SJames.Smart@Emulex.Com  * more details, a copy of which can be found in the file COPYING  *
21c44ce173SJames.Smart@Emulex.Com  * included with this package.                                     *
22dea3101eS  *******************************************************************/
23dea3101eS 
24dea3101eS #include <linux/blkdev.h>
25dea3101eS #include <linux/pci.h>
265a0e3ad6STejun Heo #include <linux/slab.h>
27dea3101eS #include <linux/interrupt.h>
28dea3101eS 
29f888ba3cSJames.Smart@Emulex.Com #include <scsi/scsi_device.h>
30f888ba3cSJames.Smart@Emulex.Com #include <scsi/scsi_transport_fc.h>
3191886523SJames.Smart@Emulex.Com #include <scsi/scsi.h>
326a9c52cfSJames Smart #include <scsi/fc/fc_fs.h>
3391886523SJames.Smart@Emulex.Com 
34da0436e9SJames Smart #include "lpfc_hw4.h"
35dea3101eS #include "lpfc_hw.h"
36dea3101eS #include "lpfc_sli.h"
37da0436e9SJames Smart #include "lpfc_sli4.h"
38ea2151b4SJames Smart #include "lpfc_nl.h"
39dea3101eS #include "lpfc_disc.h"
40dea3101eS #include "lpfc_scsi.h"
41dea3101eS #include "lpfc.h"
42dea3101eS #include "lpfc_logmsg.h"
43dea3101eS #include "lpfc_crtn.h"
44dea3101eS #include "lpfc_compat.h"
45dea3101eS 
46e59058c4SJames Smart /**
47ef47575fSJames Smart  * lpfc_mbox_rsrc_prep - Prepare a mailbox with DMA buffer memory.
48ef47575fSJames Smart  * @phba: pointer to lpfc hba data structure.
49ef47575fSJames Smart  * @mbox: pointer to the driver internal queue element for mailbox command.
50ef47575fSJames Smart  *
51ef47575fSJames Smart  * A mailbox command consists of the pool memory for the command, @mbox, and
52ef47575fSJames Smart  * one or more DMA buffers for the data transfer.  This routine provides
53ef47575fSJames Smart  * a standard framework for allocating the dma buffer and assigning to the
54ef47575fSJames Smart  * @mbox.  Callers should cleanup the mbox with a call to
55ef47575fSJames Smart  * lpfc_mbox_rsrc_cleanup.
56ef47575fSJames Smart  *
57ef47575fSJames Smart  * The lpfc_mbuf_alloc routine acquires the hbalock so the caller is
58ef47575fSJames Smart  * responsible to ensure the hbalock is released.  Also note that the
59ef47575fSJames Smart  * driver design is a single dmabuf/mbuf per mbox in the ctx_buf.
60ef47575fSJames Smart  *
61ef47575fSJames Smart  **/
62ef47575fSJames Smart int
lpfc_mbox_rsrc_prep(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbox)63ef47575fSJames Smart lpfc_mbox_rsrc_prep(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
64ef47575fSJames Smart {
65ef47575fSJames Smart 	struct lpfc_dmabuf *mp;
66ef47575fSJames Smart 
67ef47575fSJames Smart 	mp = kmalloc(sizeof(*mp), GFP_KERNEL);
68ef47575fSJames Smart 	if (!mp)
69ef47575fSJames Smart 		return -ENOMEM;
70ef47575fSJames Smart 
71ef47575fSJames Smart 	mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
72ef47575fSJames Smart 	if (!mp->virt) {
73ef47575fSJames Smart 		kfree(mp);
74ef47575fSJames Smart 		return -ENOMEM;
75ef47575fSJames Smart 	}
76ef47575fSJames Smart 
77ef47575fSJames Smart 	memset(mp->virt, 0, LPFC_BPL_SIZE);
78ef47575fSJames Smart 
79ef47575fSJames Smart 	/* Initialization only.  Driver does not use a list of dmabufs. */
80ef47575fSJames Smart 	INIT_LIST_HEAD(&mp->list);
81ef47575fSJames Smart 	mbox->ctx_buf = mp;
82ef47575fSJames Smart 	return 0;
83ef47575fSJames Smart }
84ef47575fSJames Smart 
85ef47575fSJames Smart /**
86ef47575fSJames Smart  * lpfc_mbox_rsrc_cleanup - Free the mailbox DMA buffer and virtual memory.
87ef47575fSJames Smart  * @phba: pointer to lpfc hba data structure.
88ef47575fSJames Smart  * @mbox: pointer to the driver internal queue element for mailbox command.
89ef47575fSJames Smart  * @locked: value that indicates if the hbalock is held (1) or not (0).
90ef47575fSJames Smart  *
91ef47575fSJames Smart  * A mailbox command consists of the pool memory for the command, @mbox, and
92ef47575fSJames Smart  * possibly a DMA buffer for the data transfer.  This routine provides
93ef47575fSJames Smart  * a standard framework for releasing any dma buffers and freeing all
94ef47575fSJames Smart  * memory resources in it as well as releasing the @mbox back to the @phba pool.
95ef47575fSJames Smart  * Callers should use this routine for cleanup for all mailboxes prepped with
96ef47575fSJames Smart  * lpfc_mbox_rsrc_prep.
97ef47575fSJames Smart  *
98ef47575fSJames Smart  **/
99ef47575fSJames Smart void
lpfc_mbox_rsrc_cleanup(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbox,enum lpfc_mbox_ctx locked)100ef47575fSJames Smart lpfc_mbox_rsrc_cleanup(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox,
101ef47575fSJames Smart 		       enum lpfc_mbox_ctx locked)
102ef47575fSJames Smart {
103ef47575fSJames Smart 	struct lpfc_dmabuf *mp;
104ef47575fSJames Smart 
105ef47575fSJames Smart 	mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
106ef47575fSJames Smart 	mbox->ctx_buf = NULL;
107ef47575fSJames Smart 
108ef47575fSJames Smart 	/* Release the generic BPL buffer memory.  */
109ef47575fSJames Smart 	if (mp) {
110ef47575fSJames Smart 		if (locked == MBOX_THD_LOCKED)
111ef47575fSJames Smart 			__lpfc_mbuf_free(phba, mp->virt, mp->phys);
112ef47575fSJames Smart 		else
113ef47575fSJames Smart 			lpfc_mbuf_free(phba, mp->virt, mp->phys);
114ef47575fSJames Smart 		kfree(mp);
115ef47575fSJames Smart 	}
116ef47575fSJames Smart 
117ef47575fSJames Smart 	mempool_free(mbox, phba->mbox_mem_pool);
118ef47575fSJames Smart }
119ef47575fSJames Smart 
120ef47575fSJames Smart /**
12121e9a0a5SJames Smart  * lpfc_dump_static_vport - Dump HBA's static vport information.
12221e9a0a5SJames Smart  * @phba: pointer to lpfc hba data structure.
12321e9a0a5SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
12421e9a0a5SJames Smart  * @offset: offset for dumping vport info.
12521e9a0a5SJames Smart  *
12621e9a0a5SJames Smart  * The dump mailbox command provides a method for the device driver to obtain
12721e9a0a5SJames Smart  * various types of information from the HBA device.
12821e9a0a5SJames Smart  *
12921e9a0a5SJames Smart  * This routine prepares the mailbox command for dumping list of static
13021e9a0a5SJames Smart  * vports to be created.
13121e9a0a5SJames Smart  **/
1321c6834a7SJames Smart int
lpfc_dump_static_vport(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb,uint16_t offset)13321e9a0a5SJames Smart lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
13421e9a0a5SJames Smart 		uint16_t offset)
13521e9a0a5SJames Smart {
13621e9a0a5SJames Smart 	MAILBOX_t *mb;
1371c6834a7SJames Smart 	struct lpfc_dmabuf *mp;
138ef47575fSJames Smart 	int rc;
13921e9a0a5SJames Smart 
14021e9a0a5SJames Smart 	mb = &pmb->u.mb;
14121e9a0a5SJames Smart 
14221e9a0a5SJames Smart 	/* Setup to dump vport info region */
14321e9a0a5SJames Smart 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
14421e9a0a5SJames Smart 	mb->mbxCommand = MBX_DUMP_MEMORY;
14521e9a0a5SJames Smart 	mb->un.varDmp.type = DMP_NV_PARAMS;
14621e9a0a5SJames Smart 	mb->un.varDmp.entry_index = offset;
14721e9a0a5SJames Smart 	mb->un.varDmp.region_id = DMP_REGION_VPORT;
14821e9a0a5SJames Smart 	mb->mbxOwner = OWN_HOST;
14921e9a0a5SJames Smart 
1501c6834a7SJames Smart 	/* For SLI3 HBAs data is embedded in mailbox */
1511c6834a7SJames Smart 	if (phba->sli_rev != LPFC_SLI_REV4) {
1521c6834a7SJames Smart 		mb->un.varDmp.cv = 1;
1531c6834a7SJames Smart 		mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t);
1541c6834a7SJames Smart 		return 0;
1551c6834a7SJames Smart 	}
1561c6834a7SJames Smart 
157ef47575fSJames Smart 	rc = lpfc_mbox_rsrc_prep(phba, pmb);
158ef47575fSJames Smart 	if (rc) {
1591c6834a7SJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
160ef47575fSJames Smart 				"2605 %s: memory allocation failed\n",
161ef47575fSJames Smart 				__func__);
1621c6834a7SJames Smart 		return 1;
1631c6834a7SJames Smart 	}
164ef47575fSJames Smart 
165ef47575fSJames Smart 	mp = pmb->ctx_buf;
1661c6834a7SJames Smart 	mb->un.varWords[3] = putPaddrLow(mp->phys);
1671c6834a7SJames Smart 	mb->un.varWords[4] = putPaddrHigh(mp->phys);
1681c6834a7SJames Smart 	mb->un.varDmp.sli4_length = sizeof(struct static_vport_info);
1691c6834a7SJames Smart 
1701c6834a7SJames Smart 	return 0;
17121e9a0a5SJames Smart }
17221e9a0a5SJames Smart 
17321e9a0a5SJames Smart /**
174a0c87cbdSJames Smart  * lpfc_down_link - Bring down HBAs link.
175e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
176e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
177a0c87cbdSJames Smart  *
178a0c87cbdSJames Smart  * This routine prepares a mailbox command to bring down HBA link.
179a0c87cbdSJames Smart  **/
180a0c87cbdSJames Smart void
lpfc_down_link(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)181a0c87cbdSJames Smart lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
182a0c87cbdSJames Smart {
183a0c87cbdSJames Smart 	MAILBOX_t *mb;
184a0c87cbdSJames Smart 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
185a0c87cbdSJames Smart 	mb = &pmb->u.mb;
186a0c87cbdSJames Smart 	mb->mbxCommand = MBX_DOWN_LINK;
187a0c87cbdSJames Smart 	mb->mbxOwner = OWN_HOST;
188a0c87cbdSJames Smart }
189a0c87cbdSJames Smart 
190a0c87cbdSJames Smart /**
191a0c87cbdSJames Smart  * lpfc_dump_mem - Prepare a mailbox command for reading a region.
192a0c87cbdSJames Smart  * @phba: pointer to lpfc hba data structure.
193a0c87cbdSJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
194a0c87cbdSJames Smart  * @offset: offset into the region.
195a0c87cbdSJames Smart  * @region_id: config region id.
196e59058c4SJames Smart  *
197e59058c4SJames Smart  * The dump mailbox command provides a method for the device driver to obtain
198e59058c4SJames Smart  * various types of information from the HBA device.
199e59058c4SJames Smart  *
200a0c87cbdSJames Smart  * This routine prepares the mailbox command for dumping HBA's config region.
201e59058c4SJames Smart  **/
202dea3101eS void
lpfc_dump_mem(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb,uint16_t offset,uint16_t region_id)203a0c87cbdSJames Smart lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset,
204a0c87cbdSJames Smart 		uint16_t region_id)
205dea3101eS {
206dea3101eS 	MAILBOX_t *mb;
207dea3101eS 	void *ctx;
208dea3101eS 
20904c68496SJames Smart 	mb = &pmb->u.mb;
2103e1f0718SJames Smart 	ctx = pmb->ctx_buf;
211dea3101eS 
212dea3101eS 	/* Setup to dump VPD region */
213dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
214dea3101eS 	mb->mbxCommand = MBX_DUMP_MEMORY;
215dea3101eS 	mb->un.varDmp.cv = 1;
216dea3101eS 	mb->un.varDmp.type = DMP_NV_PARAMS;
217dea3101eS 	mb->un.varDmp.entry_index = offset;
218a0c87cbdSJames Smart 	mb->un.varDmp.region_id = region_id;
219dea3101eS 	mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
220dea3101eS 	mb->un.varDmp.co = 0;
221dea3101eS 	mb->un.varDmp.resp_offset = 0;
2223e1f0718SJames Smart 	pmb->ctx_buf = ctx;
223dea3101eS 	mb->mbxOwner = OWN_HOST;
224dea3101eS 	return;
225dea3101eS }
226dea3101eS 
227e59058c4SJames Smart /**
2283621a710SJames Smart  * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
22997207482SJames Smart  * @phba: pointer to lpfc hba data structure.
23097207482SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
2313621a710SJames Smart  *
23297207482SJames Smart  * This function create a dump memory mailbox command to dump wake up
23397207482SJames Smart  * parameters.
23497207482SJames Smart  */
23597207482SJames Smart void
lpfc_dump_wakeup_param(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)23697207482SJames Smart lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
23797207482SJames Smart {
23897207482SJames Smart 	MAILBOX_t *mb;
23997207482SJames Smart 	void *ctx;
24097207482SJames Smart 
24104c68496SJames Smart 	mb = &pmb->u.mb;
24297207482SJames Smart 	/* Save context so that we can restore after memset */
2433e1f0718SJames Smart 	ctx = pmb->ctx_buf;
24497207482SJames Smart 
24597207482SJames Smart 	/* Setup to dump VPD region */
24697207482SJames Smart 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
24797207482SJames Smart 	mb->mbxCommand = MBX_DUMP_MEMORY;
24897207482SJames Smart 	mb->mbxOwner = OWN_HOST;
24997207482SJames Smart 	mb->un.varDmp.cv = 1;
25097207482SJames Smart 	mb->un.varDmp.type = DMP_NV_PARAMS;
2511d1c296fSJames Smart 	if (phba->sli_rev < LPFC_SLI_REV4)
25297207482SJames Smart 		mb->un.varDmp.entry_index = 0;
25397207482SJames Smart 	mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
25497207482SJames Smart 	mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
25597207482SJames Smart 	mb->un.varDmp.co = 0;
25697207482SJames Smart 	mb->un.varDmp.resp_offset = 0;
2573e1f0718SJames Smart 	pmb->ctx_buf = ctx;
25897207482SJames Smart 	return;
25997207482SJames Smart }
26097207482SJames Smart 
26197207482SJames Smart /**
2623621a710SJames Smart  * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
263e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
264e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
265e59058c4SJames Smart  *
266e59058c4SJames Smart  * The read NVRAM mailbox command returns the HBA's non-volatile parameters
267e59058c4SJames Smart  * that are used as defaults when the Fibre Channel link is brought on-line.
268e59058c4SJames Smart  *
269e59058c4SJames Smart  * This routine prepares the mailbox command for reading information stored
270e59058c4SJames Smart  * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
271e59058c4SJames Smart  **/
272dea3101eS void
lpfc_read_nv(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)273dea3101eS lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
274dea3101eS {
275dea3101eS 	MAILBOX_t *mb;
276dea3101eS 
27704c68496SJames Smart 	mb = &pmb->u.mb;
278dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
279dea3101eS 	mb->mbxCommand = MBX_READ_NV;
280dea3101eS 	mb->mbxOwner = OWN_HOST;
281dea3101eS 	return;
282dea3101eS }
283dea3101eS 
284e59058c4SJames Smart /**
2853621a710SJames Smart  * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
286e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
287e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
288e59058c4SJames Smart  * @ring: ring number for the asynchronous event to be configured.
289e59058c4SJames Smart  *
290e59058c4SJames Smart  * The asynchronous event enable mailbox command is used to enable the
291e59058c4SJames Smart  * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
292e59058c4SJames Smart  * specifies the default ring to which events are posted.
293e59058c4SJames Smart  *
294e59058c4SJames Smart  * This routine prepares the mailbox command for enabling HBA asynchronous
295e59058c4SJames Smart  * event support on a IOCB ring.
296e59058c4SJames Smart  **/
29757127f15SJames Smart void
lpfc_config_async(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb,uint32_t ring)29857127f15SJames Smart lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
29957127f15SJames Smart 		uint32_t ring)
30057127f15SJames Smart {
30157127f15SJames Smart 	MAILBOX_t *mb;
30257127f15SJames Smart 
30304c68496SJames Smart 	mb = &pmb->u.mb;
30457127f15SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
30557127f15SJames Smart 	mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
30657127f15SJames Smart 	mb->un.varCfgAsyncEvent.ring = ring;
30757127f15SJames Smart 	mb->mbxOwner = OWN_HOST;
30857127f15SJames Smart 	return;
30957127f15SJames Smart }
31057127f15SJames Smart 
311e59058c4SJames Smart /**
3123621a710SJames Smart  * lpfc_heart_beat - Prepare a mailbox command for heart beat
313e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
314e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
315e59058c4SJames Smart  *
316e59058c4SJames Smart  * The heart beat mailbox command is used to detect an unresponsive HBA, which
317e59058c4SJames Smart  * is defined as any device where no error attention is sent and both mailbox
318e59058c4SJames Smart  * and rings are not processed.
319e59058c4SJames Smart  *
320e59058c4SJames Smart  * This routine prepares the mailbox command for issuing a heart beat in the
321e59058c4SJames Smart  * form of mailbox command to the HBA. The timely completion of the heart
322e59058c4SJames Smart  * beat mailbox command indicates the health of the HBA.
323e59058c4SJames Smart  **/
324858c9f6cSJames Smart void
lpfc_heart_beat(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)325858c9f6cSJames Smart lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
326858c9f6cSJames Smart {
327858c9f6cSJames Smart 	MAILBOX_t *mb;
328858c9f6cSJames Smart 
32904c68496SJames Smart 	mb = &pmb->u.mb;
330858c9f6cSJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
331858c9f6cSJames Smart 	mb->mbxCommand = MBX_HEARTBEAT;
332858c9f6cSJames Smart 	mb->mbxOwner = OWN_HOST;
333858c9f6cSJames Smart 	return;
334858c9f6cSJames Smart }
335858c9f6cSJames Smart 
336e59058c4SJames Smart /**
33776a95d75SJames Smart  * lpfc_read_topology - Prepare a mailbox command for reading HBA topology
338e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
339e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
340e59058c4SJames Smart  * @mp: DMA buffer memory for reading the link attention information into.
341e59058c4SJames Smart  *
34276a95d75SJames Smart  * The read topology mailbox command is issued to read the link topology
34376a95d75SJames Smart  * information indicated by the HBA port when the Link Event bit of the Host
34476a95d75SJames Smart  * Attention (HSTATT) register is set to 1 (For SLI-3) or when an FC Link
34576a95d75SJames Smart  * Attention ACQE is received from the port (For SLI-4). A Link Event
346e59058c4SJames Smart  * Attention occurs based on an exception detected at the Fibre Channel link
347e59058c4SJames Smart  * interface.
348e59058c4SJames Smart  *
34976a95d75SJames Smart  * This routine prepares the mailbox command for reading HBA link topology
350e59058c4SJames Smart  * information. A DMA memory has been set aside and address passed to the
351e59058c4SJames Smart  * HBA through @mp for the HBA to DMA link attention information into the
352e59058c4SJames Smart  * memory as part of the execution of the mailbox command.
353e59058c4SJames Smart  *
354e59058c4SJames Smart  * Return codes
355e59058c4SJames Smart  *    0 - Success (currently always return 0)
356e59058c4SJames Smart  **/
357dea3101eS int
lpfc_read_topology(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb,struct lpfc_dmabuf * mp)35876a95d75SJames Smart lpfc_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
35976a95d75SJames Smart 		   struct lpfc_dmabuf *mp)
360dea3101eS {
361dea3101eS 	MAILBOX_t *mb;
362dea3101eS 
36304c68496SJames Smart 	mb = &pmb->u.mb;
364dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
365dea3101eS 
366dea3101eS 	INIT_LIST_HEAD(&mp->list);
36776a95d75SJames Smart 	mb->mbxCommand = MBX_READ_TOPOLOGY;
36876a95d75SJames Smart 	mb->un.varReadTop.lilpBde64.tus.f.bdeSize = LPFC_ALPA_MAP_SIZE;
36976a95d75SJames Smart 	mb->un.varReadTop.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
37076a95d75SJames Smart 	mb->un.varReadTop.lilpBde64.addrLow = putPaddrLow(mp->phys);
371dea3101eS 
372dea3101eS 	/* Save address for later completion and set the owner to host so that
373dea3101eS 	 * the FW knows this mailbox is available for processing.
374dea3101eS 	 */
3753e1f0718SJames Smart 	pmb->ctx_buf = (uint8_t *)mp;
376dea3101eS 	mb->mbxOwner = OWN_HOST;
37792d7f7b0SJames Smart 	return (0);
378dea3101eS }
379dea3101eS 
380e59058c4SJames Smart /**
3813621a710SJames Smart  * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
382e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
383e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
384e59058c4SJames Smart  *
385e59058c4SJames Smart  * The clear link attention mailbox command is issued to clear the link event
386e59058c4SJames Smart  * attention condition indicated by the Link Event bit of the Host Attention
387e59058c4SJames Smart  * (HSTATT) register. The link event attention condition is cleared only if
388e59058c4SJames Smart  * the event tag specified matches that of the current link event counter.
389e59058c4SJames Smart  * The current event tag is read using the read link attention event mailbox
390e59058c4SJames Smart  * command.
391e59058c4SJames Smart  *
392e59058c4SJames Smart  * This routine prepares the mailbox command for clearing HBA link attention
393e59058c4SJames Smart  * information.
394e59058c4SJames Smart  **/
395dea3101eS void
lpfc_clear_la(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)396dea3101eS lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
397dea3101eS {
398dea3101eS 	MAILBOX_t *mb;
399dea3101eS 
40004c68496SJames Smart 	mb = &pmb->u.mb;
401dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
402dea3101eS 
403dea3101eS 	mb->un.varClearLA.eventTag = phba->fc_eventTag;
404dea3101eS 	mb->mbxCommand = MBX_CLEAR_LA;
405dea3101eS 	mb->mbxOwner = OWN_HOST;
406dea3101eS 	return;
407dea3101eS }
408dea3101eS 
409e59058c4SJames Smart /**
4103621a710SJames Smart  * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
411e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
412e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
413e59058c4SJames Smart  *
414e59058c4SJames Smart  * The configure link mailbox command is used before the initialize link
415e59058c4SJames Smart  * mailbox command to override default value and to configure link-oriented
416e59058c4SJames Smart  * parameters such as DID address and various timers. Typically, this
417e59058c4SJames Smart  * command would be used after an F_Port login to set the returned DID address
418e59058c4SJames Smart  * and the fabric timeout values. This command is not valid before a configure
419e59058c4SJames Smart  * port command has configured the HBA port.
420e59058c4SJames Smart  *
421e59058c4SJames Smart  * This routine prepares the mailbox command for configuring link on a HBA.
422e59058c4SJames Smart  **/
423dea3101eS void
lpfc_config_link(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)424dea3101eS lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
425dea3101eS {
4262e0fef85SJames Smart 	struct lpfc_vport  *vport = phba->pport;
42704c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
428dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
429dea3101eS 
430dea3101eS 	/* NEW_FEATURE
431dea3101eS 	 * SLI-2, Coalescing Response Feature.
432dea3101eS 	 */
4331d1c296fSJames Smart 	if (phba->cfg_cr_delay && (phba->sli_rev < LPFC_SLI_REV4)) {
434dea3101eS 		mb->un.varCfgLnk.cr = 1;
435dea3101eS 		mb->un.varCfgLnk.ci = 1;
436dea3101eS 		mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
437dea3101eS 		mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
438dea3101eS 	}
439dea3101eS 
4402e0fef85SJames Smart 	mb->un.varCfgLnk.myId = vport->fc_myDID;
441dea3101eS 	mb->un.varCfgLnk.edtov = phba->fc_edtov;
442dea3101eS 	mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
443dea3101eS 	mb->un.varCfgLnk.ratov = phba->fc_ratov;
444dea3101eS 	mb->un.varCfgLnk.rttov = phba->fc_rttov;
445dea3101eS 	mb->un.varCfgLnk.altov = phba->fc_altov;
446dea3101eS 	mb->un.varCfgLnk.crtov = phba->fc_crtov;
44744fd7fe3SJames Smart 	mb->un.varCfgLnk.cscn = 0;
44844fd7fe3SJames Smart 	if (phba->bbcredit_support && phba->cfg_enable_bbcr) {
44944fd7fe3SJames Smart 		mb->un.varCfgLnk.cscn = 1;
45044fd7fe3SJames Smart 		mb->un.varCfgLnk.bbscn = bf_get(lpfc_bbscn_def,
45144fd7fe3SJames Smart 						 &phba->sli4_hba.bbscn_params);
45244fd7fe3SJames Smart 	}
453dea3101eS 
4541d1c296fSJames Smart 	if (phba->cfg_ack0 && (phba->sli_rev < LPFC_SLI_REV4))
455dea3101eS 		mb->un.varCfgLnk.ack0_enable = 1;
456dea3101eS 
457dea3101eS 	mb->mbxCommand = MBX_CONFIG_LINK;
458dea3101eS 	mb->mbxOwner = OWN_HOST;
459dea3101eS 	return;
460dea3101eS }
461dea3101eS 
462e59058c4SJames Smart /**
4633621a710SJames Smart  * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
4649399627fSJames Smart  * @phba: pointer to lpfc hba data structure.
4659399627fSJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
4669399627fSJames Smart  *
4679399627fSJames Smart  * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
4689399627fSJames Smart  * MSI-X multi-message interrupt vector association to interrupt attention
4699399627fSJames Smart  * conditions.
4709399627fSJames Smart  *
4719399627fSJames Smart  * Return codes
4729399627fSJames Smart  *    0 - Success
4739399627fSJames Smart  *    -EINVAL - Failure
4749399627fSJames Smart  **/
4759399627fSJames Smart int
lpfc_config_msi(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)4769399627fSJames Smart lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4779399627fSJames Smart {
47804c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
4799399627fSJames Smart 	uint32_t attentionConditions[2];
4809399627fSJames Smart 
4819399627fSJames Smart 	/* Sanity check */
4829399627fSJames Smart 	if (phba->cfg_use_msi != 2) {
4839399627fSJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4849399627fSJames Smart 				"0475 Not configured for supporting MSI-X "
4859399627fSJames Smart 				"cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
4869399627fSJames Smart 		return -EINVAL;
4879399627fSJames Smart 	}
4889399627fSJames Smart 
4899399627fSJames Smart 	if (phba->sli_rev < 3) {
4909399627fSJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4919399627fSJames Smart 				"0476 HBA not supporting SLI-3 or later "
4929399627fSJames Smart 				"SLI Revision: 0x%x\n", phba->sli_rev);
4939399627fSJames Smart 		return -EINVAL;
4949399627fSJames Smart 	}
4959399627fSJames Smart 
4969399627fSJames Smart 	/* Clear mailbox command fields */
4979399627fSJames Smart 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
4989399627fSJames Smart 
4999399627fSJames Smart 	/*
5009a866e6aSJulia Lawall 	 * SLI-3, Message Signaled Interrupt Feature.
5019399627fSJames Smart 	 */
5029399627fSJames Smart 
5039399627fSJames Smart 	/* Multi-message attention configuration */
5049399627fSJames Smart 	attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
5059399627fSJames Smart 				  HA_LATT | HA_MBATT);
5069399627fSJames Smart 	attentionConditions[1] = 0;
5079399627fSJames Smart 
5089399627fSJames Smart 	mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
5099399627fSJames Smart 	mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
5109399627fSJames Smart 
5119399627fSJames Smart 	/*
5129399627fSJames Smart 	 * Set up message number to HA bit association
5139399627fSJames Smart 	 */
5149399627fSJames Smart #ifdef __BIG_ENDIAN_BITFIELD
5159399627fSJames Smart 	/* RA0 (FCP Ring) */
5169399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
5179399627fSJames Smart 	/* RA1 (Other Protocol Extra Ring) */
5189399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
5199399627fSJames Smart #else   /*  __LITTLE_ENDIAN_BITFIELD */
5209399627fSJames Smart 	/* RA0 (FCP Ring) */
5219399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
5229399627fSJames Smart 	/* RA1 (Other Protocol Extra Ring) */
5239399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
5249399627fSJames Smart #endif
5259399627fSJames Smart 	/* Multi-message interrupt autoclear configuration*/
5269399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
5279399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
5289399627fSJames Smart 
5299399627fSJames Smart 	/* For now, HBA autoclear does not work reliably, disable it */
5309399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[0] = 0;
5319399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[1] = 0;
5329399627fSJames Smart 
5339399627fSJames Smart 	/* Set command and owner bit */
5349399627fSJames Smart 	mb->mbxCommand = MBX_CONFIG_MSI;
5359399627fSJames Smart 	mb->mbxOwner = OWN_HOST;
5369399627fSJames Smart 
5379399627fSJames Smart 	return 0;
5389399627fSJames Smart }
5399399627fSJames Smart 
5409399627fSJames Smart /**
5413621a710SJames Smart  * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
542e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
543e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
544e59058c4SJames Smart  * @topology: the link topology for the link to be initialized to.
545e59058c4SJames Smart  * @linkspeed: the link speed for the link to be initialized to.
546e59058c4SJames Smart  *
547e59058c4SJames Smart  * The initialize link mailbox command is used to initialize the Fibre
548e59058c4SJames Smart  * Channel link. This command must follow a configure port command that
549e59058c4SJames Smart  * establishes the mode of operation.
550e59058c4SJames Smart  *
551e59058c4SJames Smart  * This routine prepares the mailbox command for initializing link on a HBA
552e59058c4SJames Smart  * with the specified link topology and speed.
553e59058c4SJames Smart  **/
554dea3101eS void
lpfc_init_link(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb,uint32_t topology,uint32_t linkspeed)555dea3101eS lpfc_init_link(struct lpfc_hba * phba,
556dea3101eS 	       LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
557dea3101eS {
558dea3101eS 	lpfc_vpd_t *vpd;
559dea3101eS 	MAILBOX_t *mb;
560dea3101eS 
56104c68496SJames Smart 	mb = &pmb->u.mb;
562dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
563dea3101eS 
564dea3101eS 	switch (topology) {
565dea3101eS 	case FLAGS_TOPOLOGY_MODE_LOOP_PT:
566dea3101eS 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
567dea3101eS 		mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
568dea3101eS 		break;
569dea3101eS 	case FLAGS_TOPOLOGY_MODE_PT_PT:
570dea3101eS 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
571dea3101eS 		break;
572dea3101eS 	case FLAGS_TOPOLOGY_MODE_LOOP:
573dea3101eS 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
574dea3101eS 		break;
575dea3101eS 	case FLAGS_TOPOLOGY_MODE_PT_LOOP:
576dea3101eS 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
577dea3101eS 		mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
578dea3101eS 		break;
579367c2713SJamie Wellnitz 	case FLAGS_LOCAL_LB:
580367c2713SJamie Wellnitz 		mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
581367c2713SJamie Wellnitz 		break;
582dea3101eS 	}
583dea3101eS 
584f6c5e6c4SJames Smart 	/* Topology handling for ASIC_GEN_NUM 0xC and later */
585f6c5e6c4SJames Smart 	if ((phba->sli4_hba.pc_sli4_params.sli_family == LPFC_SLI_INTF_FAMILY_G6 ||
586f6c5e6c4SJames Smart 	     phba->sli4_hba.pc_sli4_params.if_type == LPFC_SLI_INTF_IF_TYPE_6) &&
58783c6cb1aSJames Smart 	    !(phba->sli4_hba.pc_sli4_params.pls) &&
588d38dd52cSJames Smart 	    mb->un.varInitLnk.link_flags & FLAGS_TOPOLOGY_MODE_LOOP) {
589d38dd52cSJames Smart 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
590d38dd52cSJames Smart 		phba->cfg_topology = FLAGS_TOPOLOGY_MODE_PT_PT;
591d38dd52cSJames Smart 	}
592d38dd52cSJames Smart 
5934b0b91d4SJames Smart 	/* Enable asynchronous ABTS responses from firmware */
5943e49af93SJames Smart 	if (phba->sli_rev == LPFC_SLI_REV3 && !phba->cfg_fcp_wait_abts_rsp)
5954b0b91d4SJames Smart 		mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
5964b0b91d4SJames Smart 
597dea3101eS 	/* NEW_FEATURE
598dea3101eS 	 * Setting up the link speed
599dea3101eS 	 */
600dea3101eS 	vpd = &phba->vpd;
601dea3101eS 	if (vpd->rev.feaLevelHigh >= 0x02){
602dea3101eS 		switch(linkspeed){
60376a95d75SJames Smart 		case LPFC_USER_LINK_SPEED_1G:
60476a95d75SJames Smart 			mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
60576a95d75SJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_1G;
606dea3101eS 			break;
60776a95d75SJames Smart 		case LPFC_USER_LINK_SPEED_2G:
60876a95d75SJames Smart 			mb->un.varInitLnk.link_flags |=	FLAGS_LINK_SPEED;
60976a95d75SJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_2G;
61076a95d75SJames Smart 			break;
61176a95d75SJames Smart 		case LPFC_USER_LINK_SPEED_4G:
61276a95d75SJames Smart 			mb->un.varInitLnk.link_flags |=	FLAGS_LINK_SPEED;
61376a95d75SJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_4G;
61476a95d75SJames Smart 			break;
61576a95d75SJames Smart 		case LPFC_USER_LINK_SPEED_8G:
61676a95d75SJames Smart 			mb->un.varInitLnk.link_flags |=	FLAGS_LINK_SPEED;
61776a95d75SJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_8G;
61876a95d75SJames Smart 			break;
61976a95d75SJames Smart 		case LPFC_USER_LINK_SPEED_10G:
62076a95d75SJames Smart 			mb->un.varInitLnk.link_flags |=	FLAGS_LINK_SPEED;
62176a95d75SJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_10G;
62276a95d75SJames Smart 			break;
62376a95d75SJames Smart 		case LPFC_USER_LINK_SPEED_16G:
62476a95d75SJames Smart 			mb->un.varInitLnk.link_flags |=	FLAGS_LINK_SPEED;
62576a95d75SJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_16G;
62676a95d75SJames Smart 			break;
627d38dd52cSJames Smart 		case LPFC_USER_LINK_SPEED_32G:
628d38dd52cSJames Smart 			mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
629d38dd52cSJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_32G;
630d38dd52cSJames Smart 			break;
631fbd8a6baSJames Smart 		case LPFC_USER_LINK_SPEED_64G:
632fbd8a6baSJames Smart 			mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
633fbd8a6baSJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_64G;
634fbd8a6baSJames Smart 			break;
63576a95d75SJames Smart 		case LPFC_USER_LINK_SPEED_AUTO:
636dea3101eS 		default:
63776a95d75SJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
638dea3101eS 			break;
639dea3101eS 		}
640dea3101eS 
641dea3101eS 	}
642dea3101eS 	else
643dea3101eS 		mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
644dea3101eS 
645dea3101eS 	mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
646dea3101eS 	mb->mbxOwner = OWN_HOST;
647dea3101eS 	mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
648dea3101eS 	return;
649dea3101eS }
650dea3101eS 
651e59058c4SJames Smart /**
6523621a710SJames Smart  * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
653e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
654e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
655e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
656e59058c4SJames Smart  *
657e59058c4SJames Smart  * The read service parameter mailbox command is used to read the HBA port
658e59058c4SJames Smart  * service parameters. The service parameters are read into the buffer
659e59058c4SJames Smart  * specified directly by a BDE in the mailbox command. These service
660e59058c4SJames Smart  * parameters may then be used to build the payload of an N_Port/F_POrt
661e59058c4SJames Smart  * login request and reply (LOGI/ACC).
662e59058c4SJames Smart  *
663e59058c4SJames Smart  * This routine prepares the mailbox command for reading HBA port service
664e59058c4SJames Smart  * parameters. The DMA memory is allocated in this function and the addresses
665e59058c4SJames Smart  * are populated into the mailbox command for the HBA to DMA the service
666e59058c4SJames Smart  * parameters into.
667e59058c4SJames Smart  *
668e59058c4SJames Smart  * Return codes
669e59058c4SJames Smart  *    0 - Success
670e59058c4SJames Smart  *    1 - DMA memory allocation failed
671e59058c4SJames Smart  **/
672dea3101eS int
lpfc_read_sparam(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb,int vpi)67392d7f7b0SJames Smart lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
674dea3101eS {
675dea3101eS 	struct lpfc_dmabuf *mp;
676dea3101eS 	MAILBOX_t *mb;
677ef47575fSJames Smart 	int rc;
678dea3101eS 
679dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
680dea3101eS 
681dea3101eS 	/* Get a buffer to hold the HBAs Service Parameters */
682ef47575fSJames Smart 	rc = lpfc_mbox_rsrc_prep(phba, pmb);
683ef47575fSJames Smart 	if (rc) {
684e8b62011SJames Smart 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
685e8b62011SJames Smart 			        "0301 READ_SPARAM: no buffers\n");
686ef47575fSJames Smart 		return 1;
687dea3101eS 	}
688ef47575fSJames Smart 
689ef47575fSJames Smart 	mp = pmb->ctx_buf;
690ef47575fSJames Smart 	mb = &pmb->u.mb;
691ef47575fSJames Smart 	mb->mbxOwner = OWN_HOST;
692dea3101eS 	mb->mbxCommand = MBX_READ_SPARM64;
693dea3101eS 	mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
694dea3101eS 	mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
695dea3101eS 	mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
6966d368e53SJames Smart 	if (phba->sli_rev >= LPFC_SLI_REV3)
6976d368e53SJames Smart 		mb->un.varRdSparm.vpi = phba->vpi_ids[vpi];
698dea3101eS 
69992d7f7b0SJames Smart 	return (0);
700dea3101eS }
701dea3101eS 
702e59058c4SJames Smart /**
7033621a710SJames Smart  * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
704e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
705e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
706e59058c4SJames Smart  * @did: remote port identifier.
707e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
708e59058c4SJames Smart  *
709e59058c4SJames Smart  * The unregister DID mailbox command is used to unregister an N_Port/F_Port
710e59058c4SJames Smart  * login for an unknown RPI by specifying the DID of a remote port. This
711e59058c4SJames Smart  * command frees an RPI context in the HBA port. This has the effect of
712e59058c4SJames Smart  * performing an implicit N_Port/F_Port logout.
713e59058c4SJames Smart  *
714e59058c4SJames Smart  * This routine prepares the mailbox command for unregistering a remote
715e59058c4SJames Smart  * N_Port/F_Port (DID) login.
716e59058c4SJames Smart  **/
717dea3101eS void
lpfc_unreg_did(struct lpfc_hba * phba,uint16_t vpi,uint32_t did,LPFC_MBOXQ_t * pmb)71892d7f7b0SJames Smart lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
71992d7f7b0SJames Smart 	       LPFC_MBOXQ_t * pmb)
720dea3101eS {
721dea3101eS 	MAILBOX_t *mb;
722dea3101eS 
72304c68496SJames Smart 	mb = &pmb->u.mb;
724dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
725dea3101eS 
726dea3101eS 	mb->un.varUnregDID.did = did;
72792d7f7b0SJames Smart 	mb->un.varUnregDID.vpi = vpi;
7286d368e53SJames Smart 	if ((vpi != 0xffff) &&
7296d368e53SJames Smart 	    (phba->sli_rev == LPFC_SLI_REV4))
7306d368e53SJames Smart 		mb->un.varUnregDID.vpi = phba->vpi_ids[vpi];
731dea3101eS 
732dea3101eS 	mb->mbxCommand = MBX_UNREG_D_ID;
733dea3101eS 	mb->mbxOwner = OWN_HOST;
734dea3101eS 	return;
735dea3101eS }
736dea3101eS 
737e59058c4SJames Smart /**
7383621a710SJames Smart  * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
739e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
740e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
741e59058c4SJames Smart  *
742e59058c4SJames Smart  * The read configuration mailbox command is used to read the HBA port
743e59058c4SJames Smart  * configuration parameters. This mailbox command provides a method for
744e59058c4SJames Smart  * seeing any parameters that may have changed via various configuration
745e59058c4SJames Smart  * mailbox commands.
746e59058c4SJames Smart  *
747e59058c4SJames Smart  * This routine prepares the mailbox command for reading out HBA configuration
748e59058c4SJames Smart  * parameters.
749e59058c4SJames Smart  **/
750dea3101eS void
lpfc_read_config(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)751dea3101eS lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
752dea3101eS {
753dea3101eS 	MAILBOX_t *mb;
754dea3101eS 
75504c68496SJames Smart 	mb = &pmb->u.mb;
756dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
757dea3101eS 
758dea3101eS 	mb->mbxCommand = MBX_READ_CONFIG;
759dea3101eS 	mb->mbxOwner = OWN_HOST;
760dea3101eS 	return;
761dea3101eS }
762dea3101eS 
763e59058c4SJames Smart /**
7643621a710SJames Smart  * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
765e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
766e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
767e59058c4SJames Smart  *
768e59058c4SJames Smart  * The read link status mailbox command is used to read the link status from
769e59058c4SJames Smart  * the HBA. Link status includes all link-related error counters. These
770e59058c4SJames Smart  * counters are maintained by the HBA and originated in the link hardware
771e59058c4SJames Smart  * unit. Note that all of these counters wrap.
772e59058c4SJames Smart  *
773e59058c4SJames Smart  * This routine prepares the mailbox command for reading out HBA link status.
774e59058c4SJames Smart  **/
7757bb3b137SJamie Wellnitz void
lpfc_read_lnk_stat(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)7767bb3b137SJamie Wellnitz lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
7777bb3b137SJamie Wellnitz {
7787bb3b137SJamie Wellnitz 	MAILBOX_t *mb;
7797bb3b137SJamie Wellnitz 
78004c68496SJames Smart 	mb = &pmb->u.mb;
7817bb3b137SJamie Wellnitz 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
7827bb3b137SJamie Wellnitz 
7837bb3b137SJamie Wellnitz 	mb->mbxCommand = MBX_READ_LNK_STAT;
7847bb3b137SJamie Wellnitz 	mb->mbxOwner = OWN_HOST;
7857bb3b137SJamie Wellnitz 	return;
7867bb3b137SJamie Wellnitz }
7877bb3b137SJamie Wellnitz 
788e59058c4SJames Smart /**
78904c68496SJames Smart  * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
790e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
791e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
792e59058c4SJames Smart  * @did: remote port identifier.
793e59058c4SJames Smart  * @param: pointer to memory holding the server parameters.
794e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
7954042629eSJames Smart  * @rpi: the rpi to use in the registration (usually only used for SLI4.
796e59058c4SJames Smart  *
797e59058c4SJames Smart  * The registration login mailbox command is used to register an N_Port or
798e59058c4SJames Smart  * F_Port login. This registration allows the HBA to cache the remote N_Port
799e59058c4SJames Smart  * service parameters internally and thereby make the appropriate FC-2
800e59058c4SJames Smart  * decisions. The remote port service parameters are handed off by the driver
801e59058c4SJames Smart  * to the HBA using a descriptor entry that directly identifies a buffer in
802e59058c4SJames Smart  * host memory. In exchange, the HBA returns an RPI identifier.
803e59058c4SJames Smart  *
804e59058c4SJames Smart  * This routine prepares the mailbox command for registering remote port login.
805e59058c4SJames Smart  * The function allocates DMA buffer for passing the service parameters to the
806e59058c4SJames Smart  * HBA with the mailbox command.
807e59058c4SJames Smart  *
808e59058c4SJames Smart  * Return codes
809e59058c4SJames Smart  *    0 - Success
810e59058c4SJames Smart  *    1 - DMA memory allocation failed
811e59058c4SJames Smart  **/
812dea3101eS int
lpfc_reg_rpi(struct lpfc_hba * phba,uint16_t vpi,uint32_t did,uint8_t * param,LPFC_MBOXQ_t * pmb,uint16_t rpi)81304c68496SJames Smart lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
8144042629eSJames Smart 	     uint8_t *param, LPFC_MBOXQ_t *pmb, uint16_t rpi)
815dea3101eS {
81604c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
817dea3101eS 	uint8_t *sparam;
818dea3101eS 	struct lpfc_dmabuf *mp;
819ef47575fSJames Smart 	int rc;
820dea3101eS 
821dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
822dea3101eS 
823dea3101eS 	mb->un.varRegLogin.rpi = 0;
8246d368e53SJames Smart 	if (phba->sli_rev == LPFC_SLI_REV4)
8256d368e53SJames Smart 		mb->un.varRegLogin.rpi = phba->sli4_hba.rpi_ids[rpi];
8266d368e53SJames Smart 	if (phba->sli_rev >= LPFC_SLI_REV3)
8276d368e53SJames Smart 		mb->un.varRegLogin.vpi = phba->vpi_ids[vpi];
828dea3101eS 	mb->un.varRegLogin.did = did;
829dea3101eS 	mb->mbxOwner = OWN_HOST;
830ef47575fSJames Smart 
831dea3101eS 	/* Get a buffer to hold NPorts Service Parameters */
832ef47575fSJames Smart 	rc = lpfc_mbox_rsrc_prep(phba, pmb);
833ef47575fSJames Smart 	if (rc) {
834dea3101eS 		mb->mbxCommand = MBX_REG_LOGIN64;
835dea3101eS 		/* REG_LOGIN: no buffers */
83692d7f7b0SJames Smart 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
837e8b62011SJames Smart 				"0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
8384042629eSJames Smart 				"rpi x%x\n", vpi, did, rpi);
8396d368e53SJames Smart 		return 1;
840dea3101eS 	}
841dea3101eS 
842dea3101eS 	/* Copy param's into a new buffer */
843ef47575fSJames Smart 	mp = pmb->ctx_buf;
844ef47575fSJames Smart 	sparam = mp->virt;
845dea3101eS 	memcpy(sparam, param, sizeof (struct serv_parm));
846dea3101eS 
847ef47575fSJames Smart 	/* Finish initializing the mailbox. */
848dea3101eS 	mb->mbxCommand = MBX_REG_LOGIN64;
849dea3101eS 	mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
850dea3101eS 	mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
851dea3101eS 	mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
852dea3101eS 
8536d368e53SJames Smart 	return 0;
854dea3101eS }
855dea3101eS 
856e59058c4SJames Smart /**
8573621a710SJames Smart  * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
858e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
859e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
860e59058c4SJames Smart  * @rpi: remote port identifier
861e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
862e59058c4SJames Smart  *
863e59058c4SJames Smart  * The unregistration login mailbox command is used to unregister an N_Port
864e59058c4SJames Smart  * or F_Port login. This command frees an RPI context in the HBA. It has the
865e59058c4SJames Smart  * effect of performing an implicit N_Port/F_Port logout.
866e59058c4SJames Smart  *
867e59058c4SJames Smart  * This routine prepares the mailbox command for unregistering remote port
868e59058c4SJames Smart  * login.
8696d368e53SJames Smart  *
8706d368e53SJames Smart  * For SLI4 ports, the rpi passed to this function must be the physical
8716d368e53SJames Smart  * rpi value, not the logical index.
872e59058c4SJames Smart  **/
873dea3101eS void
lpfc_unreg_login(struct lpfc_hba * phba,uint16_t vpi,uint32_t rpi,LPFC_MBOXQ_t * pmb)87492d7f7b0SJames Smart lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
87592d7f7b0SJames Smart 		 LPFC_MBOXQ_t * pmb)
876dea3101eS {
877dea3101eS 	MAILBOX_t *mb;
878dea3101eS 
87904c68496SJames Smart 	mb = &pmb->u.mb;
880dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
881dea3101eS 
8826d368e53SJames Smart 	mb->un.varUnregLogin.rpi = rpi;
883dea3101eS 	mb->un.varUnregLogin.rsvd1 = 0;
8846d368e53SJames Smart 	if (phba->sli_rev >= LPFC_SLI_REV3)
8856d368e53SJames Smart 		mb->un.varUnregLogin.vpi = phba->vpi_ids[vpi];
886dea3101eS 
887dea3101eS 	mb->mbxCommand = MBX_UNREG_LOGIN;
888dea3101eS 	mb->mbxOwner = OWN_HOST;
88904c68496SJames Smart 
890dea3101eS 	return;
891dea3101eS }
892dea3101eS 
893e59058c4SJames Smart /**
8945af5eee7SJames Smart  * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA.
8955af5eee7SJames Smart  * @vport: pointer to a vport object.
8965af5eee7SJames Smart  *
8975af5eee7SJames Smart  * This routine sends mailbox command to unregister all active RPIs for
8985af5eee7SJames Smart  * a vport.
8995af5eee7SJames Smart  **/
9005af5eee7SJames Smart void
lpfc_sli4_unreg_all_rpis(struct lpfc_vport * vport)9015af5eee7SJames Smart lpfc_sli4_unreg_all_rpis(struct lpfc_vport *vport)
9025af5eee7SJames Smart {
9035af5eee7SJames Smart 	struct lpfc_hba  *phba  = vport->phba;
9045af5eee7SJames Smart 	LPFC_MBOXQ_t     *mbox;
9055af5eee7SJames Smart 	int rc;
9065af5eee7SJames Smart 
9075af5eee7SJames Smart 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9085af5eee7SJames Smart 	if (mbox) {
9096d368e53SJames Smart 		/*
9106d368e53SJames Smart 		 * For SLI4 functions, the rpi field is overloaded for
9116d368e53SJames Smart 		 * the vport context unreg all.  This routine passes
9126d368e53SJames Smart 		 * 0 for the rpi field in lpfc_unreg_login for compatibility
9136d368e53SJames Smart 		 * with SLI3 and then overrides the rpi field with the
9146d368e53SJames Smart 		 * expected value for SLI4.
9156d368e53SJames Smart 		 */
9166d368e53SJames Smart 		lpfc_unreg_login(phba, vport->vpi, phba->vpi_ids[vport->vpi],
9176d368e53SJames Smart 				 mbox);
9185af5eee7SJames Smart 		mbox->u.mb.un.varUnregLogin.rsvd1 = 0x4000;
9195af5eee7SJames Smart 		mbox->vport = vport;
9205af5eee7SJames Smart 		mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
9213e1f0718SJames Smart 		mbox->ctx_ndlp = NULL;
9225af5eee7SJames Smart 		rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
9235af5eee7SJames Smart 		if (rc == MBX_NOT_FINISHED)
9245af5eee7SJames Smart 			mempool_free(mbox, phba->mbox_mem_pool);
9255af5eee7SJames Smart 	}
9265af5eee7SJames Smart }
9275af5eee7SJames Smart 
9285af5eee7SJames Smart /**
9293621a710SJames Smart  * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
930012d019fSLee Jones  * @vport: pointer to a vport object.
931e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
932e59058c4SJames Smart  *
933e59058c4SJames Smart  * The registration vport identifier mailbox command is used to activate a
934e59058c4SJames Smart  * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
935e59058c4SJames Smart  * N_Port_ID against the information in the selected virtual N_Port context
936e59058c4SJames Smart  * block and marks it active to allow normal processing of IOCB commands and
937e59058c4SJames Smart  * received unsolicited exchanges.
938e59058c4SJames Smart  *
939e59058c4SJames Smart  * This routine prepares the mailbox command for registering a virtual N_Port.
940e59058c4SJames Smart  **/
94192d7f7b0SJames Smart void
lpfc_reg_vpi(struct lpfc_vport * vport,LPFC_MBOXQ_t * pmb)94204c68496SJames Smart lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
94392d7f7b0SJames Smart {
94404c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
94538b92ef8SJames Smart 	struct lpfc_hba *phba = vport->phba;
94692d7f7b0SJames Smart 
94792d7f7b0SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
94838b92ef8SJames Smart 	/*
94938b92ef8SJames Smart 	 * Set the re-reg VPI bit for f/w to update the MAC address.
95038b92ef8SJames Smart 	 */
95138b92ef8SJames Smart 	if ((phba->sli_rev == LPFC_SLI_REV4) &&
95238b92ef8SJames Smart 		!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI))
95338b92ef8SJames Smart 		mb->un.varRegVpi.upd = 1;
9546d368e53SJames Smart 
9556d368e53SJames Smart 	mb->un.varRegVpi.vpi = phba->vpi_ids[vport->vpi];
95604c68496SJames Smart 	mb->un.varRegVpi.sid = vport->fc_myDID;
9576d368e53SJames Smart 	if (phba->sli_rev == LPFC_SLI_REV4)
9586d368e53SJames Smart 		mb->un.varRegVpi.vfi = phba->sli4_hba.vfi_ids[vport->vfi];
9596d368e53SJames Smart 	else
96004c68496SJames Smart 		mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
961c868595dSJames Smart 	memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname,
962c868595dSJames Smart 	       sizeof(struct lpfc_name));
963c868595dSJames Smart 	mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]);
964c868595dSJames Smart 	mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]);
96592d7f7b0SJames Smart 
96692d7f7b0SJames Smart 	mb->mbxCommand = MBX_REG_VPI;
96792d7f7b0SJames Smart 	mb->mbxOwner = OWN_HOST;
96892d7f7b0SJames Smart 	return;
96992d7f7b0SJames Smart 
97092d7f7b0SJames Smart }
97192d7f7b0SJames Smart 
972e59058c4SJames Smart /**
9733621a710SJames Smart  * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
974e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
975e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
976e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
977e59058c4SJames Smart  *
978e59058c4SJames Smart  * The unregistration vport identifier mailbox command is used to inactivate
979e59058c4SJames Smart  * a virtual N_Port. The driver must have logged out and unregistered all
980e59058c4SJames Smart  * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
981e59058c4SJames Smart  * unregisters any default RPIs associated with the specified vpi, aborting
982e59058c4SJames Smart  * any active exchanges. The HBA will post the mailbox response after making
983e59058c4SJames Smart  * the virtual N_Port inactive.
984e59058c4SJames Smart  *
985e59058c4SJames Smart  * This routine prepares the mailbox command for unregistering a virtual
986e59058c4SJames Smart  * N_Port.
987e59058c4SJames Smart  **/
98892d7f7b0SJames Smart void
lpfc_unreg_vpi(struct lpfc_hba * phba,uint16_t vpi,LPFC_MBOXQ_t * pmb)98992d7f7b0SJames Smart lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
99092d7f7b0SJames Smart {
99104c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
99292d7f7b0SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
99392d7f7b0SJames Smart 
9946d368e53SJames Smart 	if (phba->sli_rev == LPFC_SLI_REV3)
9956d368e53SJames Smart 		mb->un.varUnregVpi.vpi = phba->vpi_ids[vpi];
9966d368e53SJames Smart 	else if (phba->sli_rev >= LPFC_SLI_REV4)
9976d368e53SJames Smart 		mb->un.varUnregVpi.sli4_vpi = phba->vpi_ids[vpi];
99892d7f7b0SJames Smart 
99992d7f7b0SJames Smart 	mb->mbxCommand = MBX_UNREG_VPI;
100092d7f7b0SJames Smart 	mb->mbxOwner = OWN_HOST;
100192d7f7b0SJames Smart 	return;
100292d7f7b0SJames Smart 
100392d7f7b0SJames Smart }
100492d7f7b0SJames Smart 
1005e59058c4SJames Smart /**
10063621a710SJames Smart  * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
1007e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1008e59058c4SJames Smart  *
1009e59058c4SJames Smart  * This routine sets up and initializes the IOCB rings in the Port Control
1010e59058c4SJames Smart  * Block (PCB).
1011e59058c4SJames Smart  **/
1012dea3101eS static void
lpfc_config_pcb_setup(struct lpfc_hba * phba)1013dea3101eS lpfc_config_pcb_setup(struct lpfc_hba * phba)
1014dea3101eS {
1015dea3101eS 	struct lpfc_sli *psli = &phba->sli;
1016dea3101eS 	struct lpfc_sli_ring *pring;
101734b02dcdSJames Smart 	PCB_t *pcbp = phba->pcb;
1018dea3101eS 	dma_addr_t pdma_addr;
1019dea3101eS 	uint32_t offset;
10202e0fef85SJames Smart 	uint32_t iocbCnt = 0;
1021dea3101eS 	int i;
1022dea3101eS 
1023dea3101eS 	pcbp->maxRing = (psli->num_rings - 1);
1024dea3101eS 
1025dea3101eS 	for (i = 0; i < psli->num_rings; i++) {
1026895427bdSJames Smart 		pring = &psli->sli3_ring[i];
10272e0fef85SJames Smart 
10287e56aa25SJames Smart 		pring->sli.sli3.sizeCiocb =
10297e56aa25SJames Smart 			phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE :
1030ed957684SJames Smart 							SLI2_IOCB_CMD_SIZE;
10317e56aa25SJames Smart 		pring->sli.sli3.sizeRiocb =
10327e56aa25SJames Smart 			phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE :
1033ed957684SJames Smart 							SLI2_IOCB_RSP_SIZE;
1034dea3101eS 		/* A ring MUST have both cmd and rsp entries defined to be
1035dea3101eS 		   valid */
10367e56aa25SJames Smart 		if ((pring->sli.sli3.numCiocb == 0) ||
10377e56aa25SJames Smart 			(pring->sli.sli3.numRiocb == 0)) {
1038dea3101eS 			pcbp->rdsc[i].cmdEntries = 0;
1039dea3101eS 			pcbp->rdsc[i].rspEntries = 0;
1040dea3101eS 			pcbp->rdsc[i].cmdAddrHigh = 0;
1041dea3101eS 			pcbp->rdsc[i].rspAddrHigh = 0;
1042dea3101eS 			pcbp->rdsc[i].cmdAddrLow = 0;
1043dea3101eS 			pcbp->rdsc[i].rspAddrLow = 0;
10447e56aa25SJames Smart 			pring->sli.sli3.cmdringaddr = NULL;
10457e56aa25SJames Smart 			pring->sli.sli3.rspringaddr = NULL;
1046dea3101eS 			continue;
1047dea3101eS 		}
1048dea3101eS 		/* Command ring setup for ring */
10497e56aa25SJames Smart 		pring->sli.sli3.cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
10507e56aa25SJames Smart 		pcbp->rdsc[i].cmdEntries = pring->sli.sli3.numCiocb;
1051dea3101eS 
105234b02dcdSJames Smart 		offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
105334b02dcdSJames Smart 			 (uint8_t *) phba->slim2p.virt;
105434b02dcdSJames Smart 		pdma_addr = phba->slim2p.phys + offset;
1055dea3101eS 		pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
1056dea3101eS 		pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
10577e56aa25SJames Smart 		iocbCnt += pring->sli.sli3.numCiocb;
1058dea3101eS 
1059dea3101eS 		/* Response ring setup for ring */
10607e56aa25SJames Smart 		pring->sli.sli3.rspringaddr = (void *) &phba->IOCBs[iocbCnt];
1061dea3101eS 
10627e56aa25SJames Smart 		pcbp->rdsc[i].rspEntries = pring->sli.sli3.numRiocb;
106334b02dcdSJames Smart 		offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
106434b02dcdSJames Smart 			 (uint8_t *)phba->slim2p.virt;
106534b02dcdSJames Smart 		pdma_addr = phba->slim2p.phys + offset;
1066dea3101eS 		pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
1067dea3101eS 		pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
10687e56aa25SJames Smart 		iocbCnt += pring->sli.sli3.numRiocb;
1069dea3101eS 	}
1070dea3101eS }
1071dea3101eS 
1072e59058c4SJames Smart /**
10733621a710SJames Smart  * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
1074e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1075e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1076e59058c4SJames Smart  *
1077e59058c4SJames Smart  * The read revision mailbox command is used to read the revision levels of
1078e59058c4SJames Smart  * the HBA components. These components include hardware units, resident
1079e59058c4SJames Smart  * firmware, and available firmware. HBAs that supports SLI-3 mode of
1080e59058c4SJames Smart  * operation provide different response information depending on the version
1081e59058c4SJames Smart  * requested by the driver.
1082e59058c4SJames Smart  *
1083e59058c4SJames Smart  * This routine prepares the mailbox command for reading HBA revision
1084e59058c4SJames Smart  * information.
1085e59058c4SJames Smart  **/
1086dea3101eS void
lpfc_read_rev(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)1087dea3101eS lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1088dea3101eS {
108904c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
1090dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1091dea3101eS 	mb->un.varRdRev.cv = 1;
1092ed957684SJames Smart 	mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
1093dea3101eS 	mb->mbxCommand = MBX_READ_REV;
1094dea3101eS 	mb->mbxOwner = OWN_HOST;
1095dea3101eS 	return;
1096dea3101eS }
1097dea3101eS 
1098d7c47992SJames Smart void
lpfc_sli4_swap_str(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)1099d7c47992SJames Smart lpfc_sli4_swap_str(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1100d7c47992SJames Smart {
1101d7c47992SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
1102d7c47992SJames Smart 	struct lpfc_mqe *mqe;
1103d7c47992SJames Smart 
1104d7c47992SJames Smart 	switch (mb->mbxCommand) {
1105d7c47992SJames Smart 	case  MBX_READ_REV:
1106d7c47992SJames Smart 		 mqe = &pmb->u.mqe;
1107d7c47992SJames Smart 		lpfc_sli_pcimem_bcopy(mqe->un.read_rev.fw_name,
1108d7c47992SJames Smart 				 mqe->un.read_rev.fw_name, 16);
1109d7c47992SJames Smart 		lpfc_sli_pcimem_bcopy(mqe->un.read_rev.ulp_fw_name,
1110d7c47992SJames Smart 				 mqe->un.read_rev.ulp_fw_name, 16);
1111d7c47992SJames Smart 		break;
1112d7c47992SJames Smart 	default:
1113d7c47992SJames Smart 		break;
1114d7c47992SJames Smart 	}
1115d7c47992SJames Smart 	return;
1116d7c47992SJames Smart }
1117d7c47992SJames Smart 
1118e59058c4SJames Smart /**
11193621a710SJames Smart  * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
1120e59058c4SJames Smart  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1121e59058c4SJames Smart  * @hbq_desc: pointer to the HBQ selection profile descriptor.
1122e59058c4SJames Smart  *
1123e59058c4SJames Smart  * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
1124e59058c4SJames Smart  * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
1125e59058c4SJames Smart  * the Sequence Length Test using the fields in the Selection Profile 2
1126e59058c4SJames Smart  * extension in words 20:31.
1127e59058c4SJames Smart  **/
1128ed957684SJames Smart static void
lpfc_build_hbq_profile2(struct config_hbq_var * hbqmb,struct lpfc_hbq_init * hbq_desc)1129ed957684SJames Smart lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
1130ed957684SJames Smart 			struct lpfc_hbq_init  *hbq_desc)
1131ed957684SJames Smart {
1132ed957684SJames Smart 	hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
1133ed957684SJames Smart 	hbqmb->profiles.profile2.maxlen     = hbq_desc->maxlen;
1134ed957684SJames Smart 	hbqmb->profiles.profile2.seqlenoff  = hbq_desc->seqlenoff;
1135ed957684SJames Smart }
1136ed957684SJames Smart 
1137e59058c4SJames Smart /**
11383621a710SJames Smart  * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
1139e59058c4SJames Smart  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1140e59058c4SJames Smart  * @hbq_desc: pointer to the HBQ selection profile descriptor.
1141e59058c4SJames Smart  *
1142e59058c4SJames Smart  * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
1143e59058c4SJames Smart  * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
1144e59058c4SJames Smart  * the Sequence Length Test and Byte Field Test using the fields in the
1145e59058c4SJames Smart  * Selection Profile 3 extension in words 20:31.
1146e59058c4SJames Smart  **/
1147ed957684SJames Smart static void
lpfc_build_hbq_profile3(struct config_hbq_var * hbqmb,struct lpfc_hbq_init * hbq_desc)1148ed957684SJames Smart lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
1149ed957684SJames Smart 			struct lpfc_hbq_init  *hbq_desc)
1150ed957684SJames Smart {
1151ed957684SJames Smart 	hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
1152ed957684SJames Smart 	hbqmb->profiles.profile3.maxlen     = hbq_desc->maxlen;
1153ed957684SJames Smart 	hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
1154ed957684SJames Smart 	hbqmb->profiles.profile3.seqlenoff  = hbq_desc->seqlenoff;
1155ed957684SJames Smart 	memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
1156ed957684SJames Smart 	       sizeof(hbqmb->profiles.profile3.cmdmatch));
1157ed957684SJames Smart }
1158ed957684SJames Smart 
1159e59058c4SJames Smart /**
11603621a710SJames Smart  * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
1161e59058c4SJames Smart  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1162e59058c4SJames Smart  * @hbq_desc: pointer to the HBQ selection profile descriptor.
1163e59058c4SJames Smart  *
1164e59058c4SJames Smart  * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
1165e59058c4SJames Smart  * HBA tests the initial frame of an incoming sequence using the frame's
1166e59058c4SJames Smart  * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
1167e59058c4SJames Smart  * and Byte Field Test using the fields in the Selection Profile 5 extension
1168e59058c4SJames Smart  * words 20:31.
1169e59058c4SJames Smart  **/
1170ed957684SJames Smart static void
lpfc_build_hbq_profile5(struct config_hbq_var * hbqmb,struct lpfc_hbq_init * hbq_desc)1171ed957684SJames Smart lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
1172ed957684SJames Smart 			struct lpfc_hbq_init  *hbq_desc)
1173ed957684SJames Smart {
1174ed957684SJames Smart 	hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
1175ed957684SJames Smart 	hbqmb->profiles.profile5.maxlen     = hbq_desc->maxlen;
1176ed957684SJames Smart 	hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
1177ed957684SJames Smart 	hbqmb->profiles.profile5.seqlenoff  = hbq_desc->seqlenoff;
1178ed957684SJames Smart 	memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
1179ed957684SJames Smart 	       sizeof(hbqmb->profiles.profile5.cmdmatch));
1180ed957684SJames Smart }
1181ed957684SJames Smart 
1182e59058c4SJames Smart /**
11833621a710SJames Smart  * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
1184e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1185e59058c4SJames Smart  * @id: HBQ identifier.
1186e59058c4SJames Smart  * @hbq_desc: pointer to the HBA descriptor data structure.
1187e59058c4SJames Smart  * @hbq_entry_index: index of the HBQ entry data structures.
1188e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1189e59058c4SJames Smart  *
1190e59058c4SJames Smart  * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
1191e59058c4SJames Smart  * an HBQ. The configuration binds events that require buffers to a particular
1192e59058c4SJames Smart  * ring and HBQ based on a selection profile.
1193e59058c4SJames Smart  *
1194e59058c4SJames Smart  * This routine prepares the mailbox command for configuring an HBQ.
1195e59058c4SJames Smart  **/
1196ed957684SJames Smart void
lpfc_config_hbq(struct lpfc_hba * phba,uint32_t id,struct lpfc_hbq_init * hbq_desc,uint32_t hbq_entry_index,LPFC_MBOXQ_t * pmb)119751ef4c26SJames Smart lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
119851ef4c26SJames Smart 		 struct lpfc_hbq_init *hbq_desc,
1199ed957684SJames Smart 		uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
1200ed957684SJames Smart {
1201ed957684SJames Smart 	int i;
120204c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
1203ed957684SJames Smart 	struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
1204ed957684SJames Smart 
1205ed957684SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
120651ef4c26SJames Smart 	hbqmb->hbqId = id;
1207ed957684SJames Smart 	hbqmb->entry_count = hbq_desc->entry_count;   /* # entries in HBQ */
1208ed957684SJames Smart 	hbqmb->recvNotify = hbq_desc->rn;             /* Receive
1209ed957684SJames Smart 						       * Notification */
1210ed957684SJames Smart 	hbqmb->numMask    = hbq_desc->mask_count;     /* # R_CTL/TYPE masks
1211ed957684SJames Smart 						       * # in words 0-19 */
1212ed957684SJames Smart 	hbqmb->profile    = hbq_desc->profile;	      /* Selection profile:
1213ed957684SJames Smart 						       * 0 = all,
1214ed957684SJames Smart 						       * 7 = logentry */
1215ed957684SJames Smart 	hbqmb->ringMask   = hbq_desc->ring_mask;      /* Binds HBQ to a ring
1216ed957684SJames Smart 						       * e.g. Ring0=b0001,
1217ed957684SJames Smart 						       * ring2=b0100 */
1218ed957684SJames Smart 	hbqmb->headerLen  = hbq_desc->headerLen;      /* 0 if not profile 4
1219ed957684SJames Smart 						       * or 5 */
1220ed957684SJames Smart 	hbqmb->logEntry   = hbq_desc->logEntry;       /* Set to 1 if this
1221ed957684SJames Smart 						       * HBQ will be used
1222ed957684SJames Smart 						       * for LogEntry
1223ed957684SJames Smart 						       * buffers */
1224ed957684SJames Smart 	hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
1225ed957684SJames Smart 		hbq_entry_index * sizeof(struct lpfc_hbq_entry);
1226ed957684SJames Smart 	hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
1227ed957684SJames Smart 
1228ed957684SJames Smart 	mb->mbxCommand = MBX_CONFIG_HBQ;
1229ed957684SJames Smart 	mb->mbxOwner = OWN_HOST;
1230ed957684SJames Smart 
1231ed957684SJames Smart 				/* Copy info for profiles 2,3,5. Other
1232ed957684SJames Smart 				 * profiles this area is reserved
1233ed957684SJames Smart 				 */
1234ed957684SJames Smart 	if (hbq_desc->profile == 2)
1235ed957684SJames Smart 		lpfc_build_hbq_profile2(hbqmb, hbq_desc);
1236ed957684SJames Smart 	else if (hbq_desc->profile == 3)
1237ed957684SJames Smart 		lpfc_build_hbq_profile3(hbqmb, hbq_desc);
1238ed957684SJames Smart 	else if (hbq_desc->profile == 5)
1239ed957684SJames Smart 		lpfc_build_hbq_profile5(hbqmb, hbq_desc);
1240ed957684SJames Smart 
1241ed957684SJames Smart 	/* Return if no rctl / type masks for this HBQ */
1242ed957684SJames Smart 	if (!hbq_desc->mask_count)
1243ed957684SJames Smart 		return;
1244ed957684SJames Smart 
1245ed957684SJames Smart 	/* Otherwise we setup specific rctl / type masks for this HBQ */
1246ed957684SJames Smart 	for (i = 0; i < hbq_desc->mask_count; i++) {
1247ed957684SJames Smart 		hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
1248ed957684SJames Smart 		hbqmb->hbqMasks[i].tmask  = hbq_desc->hbqMasks[i].tmask;
1249ed957684SJames Smart 		hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
1250ed957684SJames Smart 		hbqmb->hbqMasks[i].rctlmask  = hbq_desc->hbqMasks[i].rctlmask;
1251ed957684SJames Smart 	}
1252ed957684SJames Smart 
1253ed957684SJames Smart 	return;
1254ed957684SJames Smart }
1255ed957684SJames Smart 
1256e59058c4SJames Smart /**
12573621a710SJames Smart  * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
1258e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1259012d019fSLee Jones  * @ring: ring number/index
1260e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1261e59058c4SJames Smart  *
1262e59058c4SJames Smart  * The configure ring mailbox command is used to configure an IOCB ring. This
1263e59058c4SJames Smart  * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1264e59058c4SJames Smart  * ring. This is used to map incoming sequences to a particular ring whose
1265e59058c4SJames Smart  * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1266e59058c4SJames Smart  * attempt to configure a ring whose number is greater than the number
1267e59058c4SJames Smart  * specified in the Port Control Block (PCB). It is an error to issue the
1268e59058c4SJames Smart  * configure ring command more than once with the same ring number. The HBA
1269e59058c4SJames Smart  * returns an error if the driver attempts this.
1270e59058c4SJames Smart  *
1271e59058c4SJames Smart  * This routine prepares the mailbox command for configuring IOCB ring.
1272e59058c4SJames Smart  **/
1273dea3101eS void
lpfc_config_ring(struct lpfc_hba * phba,int ring,LPFC_MBOXQ_t * pmb)1274dea3101eS lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
1275dea3101eS {
1276dea3101eS 	int i;
127704c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
1278dea3101eS 	struct lpfc_sli *psli;
1279dea3101eS 	struct lpfc_sli_ring *pring;
1280dea3101eS 
1281dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1282dea3101eS 
1283dea3101eS 	mb->un.varCfgRing.ring = ring;
1284dea3101eS 	mb->un.varCfgRing.maxOrigXchg = 0;
1285dea3101eS 	mb->un.varCfgRing.maxRespXchg = 0;
1286dea3101eS 	mb->un.varCfgRing.recvNotify = 1;
1287dea3101eS 
1288dea3101eS 	psli = &phba->sli;
1289895427bdSJames Smart 	pring = &psli->sli3_ring[ring];
1290dea3101eS 	mb->un.varCfgRing.numMask = pring->num_mask;
1291dea3101eS 	mb->mbxCommand = MBX_CONFIG_RING;
1292dea3101eS 	mb->mbxOwner = OWN_HOST;
1293dea3101eS 
1294dea3101eS 	/* Is this ring configured for a specific profile */
1295dea3101eS 	if (pring->prt[0].profile) {
1296dea3101eS 		mb->un.varCfgRing.profile = pring->prt[0].profile;
1297dea3101eS 		return;
1298dea3101eS 	}
1299dea3101eS 
1300dea3101eS 	/* Otherwise we setup specific rctl / type masks for this ring */
1301dea3101eS 	for (i = 0; i < pring->num_mask; i++) {
1302dea3101eS 		mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
13036a9c52cfSJames Smart 		if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ)
1304dea3101eS 			mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
1305dea3101eS 		else
1306dea3101eS 			mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
1307dea3101eS 		mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
1308dea3101eS 		mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
1309dea3101eS 	}
1310dea3101eS 
1311dea3101eS 	return;
1312dea3101eS }
1313dea3101eS 
1314e59058c4SJames Smart /**
13153621a710SJames Smart  * lpfc_config_port - Prepare a mailbox command for configuring port
1316e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1317e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1318e59058c4SJames Smart  *
1319e59058c4SJames Smart  * The configure port mailbox command is used to identify the Port Control
1320e59058c4SJames Smart  * Block (PCB) in the driver memory. After this command is issued, the
1321e59058c4SJames Smart  * driver must not access the mailbox in the HBA without first resetting
1322e59058c4SJames Smart  * the HBA. The HBA may copy the PCB information to internal storage for
1323e59058c4SJames Smart  * subsequent use; the driver can not change the PCB information unless it
1324e59058c4SJames Smart  * resets the HBA.
1325e59058c4SJames Smart  *
1326e59058c4SJames Smart  * This routine prepares the mailbox command for configuring port.
1327e59058c4SJames Smart  **/
1328dea3101eS void
lpfc_config_port(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)1329dea3101eS lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1330dea3101eS {
1331ed957684SJames Smart 	MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
133204c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
1333dea3101eS 	dma_addr_t pdma_addr;
1334dea3101eS 	uint32_t bar_low, bar_high;
1335dea3101eS 	size_t offset;
13364cc2da1dSJames.Smart@Emulex.Com 	struct lpfc_hgp hgp;
1337f91b392cSJames.Smart@Emulex.Com 	int i;
1338ed957684SJames Smart 	uint32_t pgp_offset;
1339dea3101eS 
1340dea3101eS 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1341dea3101eS 	mb->mbxCommand = MBX_CONFIG_PORT;
1342dea3101eS 	mb->mbxOwner = OWN_HOST;
1343dea3101eS 
1344dea3101eS 	mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
1345dea3101eS 
134634b02dcdSJames Smart 	offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
134734b02dcdSJames Smart 	pdma_addr = phba->slim2p.phys + offset;
1348dea3101eS 	mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
1349dea3101eS 	mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
1350dea3101eS 
135197207482SJames Smart 	/* Always Host Group Pointer is in SLIM */
135297207482SJames Smart 	mb->un.varCfgPort.hps = 1;
135397207482SJames Smart 
1354ed957684SJames Smart 	/* If HBA supports SLI=3 ask for it */
1355ed957684SJames Smart 
135604c68496SJames Smart 	if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
1357e2a0a9d6SJames Smart 		if (phba->cfg_enable_bg)
1358e2a0a9d6SJames Smart 			mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
1359ed957684SJames Smart 		mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
136034b02dcdSJames Smart 		mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
136151ef4c26SJames Smart 		mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
136278b2d852SJames Smart 		if (phba->max_vpi && phba->cfg_enable_npiv &&
136392d7f7b0SJames Smart 		    phba->vpd.sli3Feat.cmv) {
136404c68496SJames Smart 			mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI;
136592d7f7b0SJames Smart 			mb->un.varCfgPort.cmv = 1;
136692d7f7b0SJames Smart 		} else
136792d7f7b0SJames Smart 			mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
136892d7f7b0SJames Smart 	} else
136904c68496SJames Smart 		phba->sli_rev = LPFC_SLI_REV2;
137092d7f7b0SJames Smart 	mb->un.varCfgPort.sli_mode = phba->sli_rev;
1371ed957684SJames Smart 
1372cb69f7deSJames Smart 	/* If this is an SLI3 port, configure async status notification. */
1373cb69f7deSJames Smart 	if (phba->sli_rev == LPFC_SLI_REV3)
1374cb69f7deSJames Smart 		mb->un.varCfgPort.casabt = 1;
1375cb69f7deSJames Smart 
1376dea3101eS 	/* Now setup pcb */
137734b02dcdSJames Smart 	phba->pcb->type = TYPE_NATIVE_SLI2;
137834b02dcdSJames Smart 	phba->pcb->feature = FEATURE_INITIAL_SLI2;
1379dea3101eS 
1380dea3101eS 	/* Setup Mailbox pointers */
13817a470277SJames Smart 	phba->pcb->mailBoxSize = sizeof(MAILBOX_t) + MAILBOX_EXT_SIZE;
138234b02dcdSJames Smart 	offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
138334b02dcdSJames Smart 	pdma_addr = phba->slim2p.phys + offset;
138434b02dcdSJames Smart 	phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
138534b02dcdSJames Smart 	phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
1386dea3101eS 
1387dea3101eS 	/*
1388dea3101eS 	 * Setup Host Group ring pointer.
1389dea3101eS 	 *
1390dea3101eS 	 * For efficiency reasons, the ring get/put pointers can be
1391dea3101eS 	 * placed in adapter memory (SLIM) rather than in host memory.
1392dea3101eS 	 * This allows firmware to avoid PCI reads/writes when updating
1393dea3101eS 	 * and checking pointers.
1394dea3101eS 	 *
1395dea3101eS 	 * The firmware recognizes the use of SLIM memory by comparing
1396dea3101eS 	 * the address of the get/put pointers structure with that of
1397dea3101eS 	 * the SLIM BAR (BAR0).
1398dea3101eS 	 *
1399dea3101eS 	 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1400dea3101eS 	 * (the hardware's view of the base address), not the OS's
1401dea3101eS 	 * value of pci_resource_start() as the OS value may be a cookie
1402dea3101eS 	 * for ioremap/iomap.
1403dea3101eS 	 */
1404dea3101eS 
1405dea3101eS 
1406dea3101eS 	pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
1407dea3101eS 	pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
1408dea3101eS 
1409ed957684SJames Smart 	/*
1410ed957684SJames Smart 	 * Set up HGP - Port Memory
1411ed957684SJames Smart 	 *
1412ed957684SJames Smart 	 * The port expects the host get/put pointers to reside in memory
1413ed957684SJames Smart 	 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1414ed957684SJames Smart 	 * area of SLIM.  In SLI-2 mode, there's an additional 16 reserved
1415ed957684SJames Smart 	 * words (0x40 bytes).  This area is not reserved if HBQs are
1416ed957684SJames Smart 	 * configured in SLI-3.
1417ed957684SJames Smart 	 *
1418ed957684SJames Smart 	 * CR0Put    - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1419ed957684SJames Smart 	 * RR0Get                      0xc4              0x84
1420ed957684SJames Smart 	 * CR1Put                      0xc8              0x88
1421ed957684SJames Smart 	 * RR1Get                      0xcc              0x8c
1422ed957684SJames Smart 	 * CR2Put                      0xd0              0x90
1423ed957684SJames Smart 	 * RR2Get                      0xd4              0x94
1424ed957684SJames Smart 	 * CR3Put                      0xd8              0x98
1425ed957684SJames Smart 	 * RR3Get                      0xdc              0x9c
1426ed957684SJames Smart 	 *
1427ed957684SJames Smart 	 * Reserved                    0xa0-0xbf
1428ed957684SJames Smart 	 *    If HBQs configured:
1429ed957684SJames Smart 	 *                         HBQ 0 Put ptr  0xc0
1430ed957684SJames Smart 	 *                         HBQ 1 Put ptr  0xc4
1431ed957684SJames Smart 	 *                         HBQ 2 Put ptr  0xc8
1432ed957684SJames Smart 	 *                         ......
1433ed957684SJames Smart 	 *                         HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1434ed957684SJames Smart 	 *
1435ed957684SJames Smart 	 */
1436ed957684SJames Smart 
14377a470277SJames Smart 	if (phba->cfg_hostmem_hgp && phba->sli_rev != 3) {
1438a7fc071aSDick Kennedy 		phba->host_gp = (struct lpfc_hgp __iomem *)
1439a7fc071aSDick Kennedy 				 &phba->mbox->us.s2.host[0];
14407a470277SJames Smart 		phba->hbq_put = NULL;
14417a470277SJames Smart 		offset = (uint8_t *)&phba->mbox->us.s2.host -
14427a470277SJames Smart 			(uint8_t *)phba->slim2p.virt;
14437a470277SJames Smart 		pdma_addr = phba->slim2p.phys + offset;
14447a470277SJames Smart 		phba->pcb->hgpAddrHigh = putPaddrHigh(pdma_addr);
14457a470277SJames Smart 		phba->pcb->hgpAddrLow = putPaddrLow(pdma_addr);
14467a470277SJames Smart 	} else {
14477a470277SJames Smart 		/* Always Host Group Pointer is in SLIM */
14487a470277SJames Smart 		mb->un.varCfgPort.hps = 1;
14497a470277SJames Smart 
1450ed957684SJames Smart 		if (phba->sli_rev == 3) {
1451ed957684SJames Smart 			phba->host_gp = &mb_slim->us.s3.host[0];
1452ed957684SJames Smart 			phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
1453ed957684SJames Smart 		} else {
1454ed957684SJames Smart 			phba->host_gp = &mb_slim->us.s2.host[0];
1455ed957684SJames Smart 			phba->hbq_put = NULL;
1456ed957684SJames Smart 		}
1457dea3101eS 
1458dea3101eS 		/* mask off BAR0's flag bits 0 - 3 */
145934b02dcdSJames Smart 		phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
1460ed957684SJames Smart 			(void __iomem *)phba->host_gp -
1461ed957684SJames Smart 			(void __iomem *)phba->MBslimaddr;
1462dea3101eS 		if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
146334b02dcdSJames Smart 			phba->pcb->hgpAddrHigh = bar_high;
1464dea3101eS 		else
146534b02dcdSJames Smart 			phba->pcb->hgpAddrHigh = 0;
1466dea3101eS 		/* write HGP data to SLIM at the required longword offset */
14674cc2da1dSJames.Smart@Emulex.Com 		memset(&hgp, 0, sizeof(struct lpfc_hgp));
1468f91b392cSJames.Smart@Emulex.Com 
1469f91b392cSJames.Smart@Emulex.Com 		for (i = 0; i < phba->sli.num_rings; i++) {
1470ed957684SJames Smart 			lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
1471ed957684SJames Smart 				    sizeof(*phba->host_gp));
1472f91b392cSJames.Smart@Emulex.Com 		}
14737a470277SJames Smart 	}
1474dea3101eS 
14758f34f4ceSJames Smart 	/* Setup Port Group offset */
14768f34f4ceSJames Smart 	if (phba->sli_rev == 3)
147734b02dcdSJames Smart 		pgp_offset = offsetof(struct lpfc_sli2_slim,
147834b02dcdSJames Smart 				      mbx.us.s3_pgp.port);
14798f34f4ceSJames Smart 	else
148034b02dcdSJames Smart 		pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
148134b02dcdSJames Smart 	pdma_addr = phba->slim2p.phys + pgp_offset;
148234b02dcdSJames Smart 	phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
148334b02dcdSJames Smart 	phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
1484dea3101eS 
1485dea3101eS 	/* Use callback routine to setp rings in the pcb */
1486dea3101eS 	lpfc_config_pcb_setup(phba);
1487dea3101eS 
1488dea3101eS 	/* special handling for LC HBAs */
1489dea3101eS 	if (lpfc_is_LC_HBA(phba->pcidev->device)) {
1490dea3101eS 		uint32_t hbainit[5];
1491dea3101eS 
1492dea3101eS 		lpfc_hba_init(phba, hbainit);
1493dea3101eS 
1494dea3101eS 		memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
1495dea3101eS 	}
1496dea3101eS 
1497dea3101eS 	/* Swap PCB if needed */
149834b02dcdSJames Smart 	lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
1499dea3101eS }
1500dea3101eS 
1501e59058c4SJames Smart /**
15023621a710SJames Smart  * lpfc_kill_board - Prepare a mailbox command for killing board
1503e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1504e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1505e59058c4SJames Smart  *
1506e59058c4SJames Smart  * The kill board mailbox command is used to tell firmware to perform a
1507e59058c4SJames Smart  * graceful shutdown of a channel on a specified board to prepare for reset.
1508e59058c4SJames Smart  * When the kill board mailbox command is received, the ER3 bit is set to 1
1509e59058c4SJames Smart  * in the Host Status register and the ER Attention bit is set to 1 in the
1510e59058c4SJames Smart  * Host Attention register of the HBA function that received the kill board
1511e59058c4SJames Smart  * command.
1512e59058c4SJames Smart  *
1513e59058c4SJames Smart  * This routine prepares the mailbox command for killing the board in
1514e59058c4SJames Smart  * preparation for a graceful shutdown.
1515e59058c4SJames Smart  **/
1516dea3101eS void
lpfc_kill_board(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)151741415862SJamie Wellnitz lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
151841415862SJamie Wellnitz {
151904c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
152041415862SJamie Wellnitz 
152141415862SJamie Wellnitz 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
152241415862SJamie Wellnitz 	mb->mbxCommand = MBX_KILL_BOARD;
152341415862SJamie Wellnitz 	mb->mbxOwner = OWN_HOST;
152441415862SJamie Wellnitz 	return;
152541415862SJamie Wellnitz }
152641415862SJamie Wellnitz 
1527e59058c4SJames Smart /**
15283621a710SJames Smart  * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
1529e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1530e59058c4SJames Smart  * @mbq: pointer to the driver internal queue element for mailbox command.
1531e59058c4SJames Smart  *
1532e59058c4SJames Smart  * Driver maintains a internal mailbox command queue implemented as a linked
1533e59058c4SJames Smart  * list. When a mailbox command is issued, it shall be put into the mailbox
1534e59058c4SJames Smart  * command queue such that they shall be processed orderly as HBA can process
1535e59058c4SJames Smart  * one mailbox command at a time.
1536e59058c4SJames Smart  **/
153741415862SJamie Wellnitz void
lpfc_mbox_put(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbq)1538dea3101eS lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1539dea3101eS {
1540dea3101eS 	struct lpfc_sli *psli;
1541dea3101eS 
1542dea3101eS 	psli = &phba->sli;
1543dea3101eS 
1544dea3101eS 	list_add_tail(&mbq->list, &psli->mboxq);
1545dea3101eS 
1546dea3101eS 	psli->mboxq_cnt++;
1547dea3101eS 
1548dea3101eS 	return;
1549dea3101eS }
1550dea3101eS 
1551e59058c4SJames Smart /**
15523621a710SJames Smart  * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
1553e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1554e59058c4SJames Smart  *
1555e59058c4SJames Smart  * Driver maintains a internal mailbox command queue implemented as a linked
1556e59058c4SJames Smart  * list. When a mailbox command is issued, it shall be put into the mailbox
1557e59058c4SJames Smart  * command queue such that they shall be processed orderly as HBA can process
1558e59058c4SJames Smart  * one mailbox command at a time. After HBA finished processing a mailbox
1559e59058c4SJames Smart  * command, the driver will remove a pending mailbox command from the head of
1560e59058c4SJames Smart  * the mailbox command queue and send to the HBA for processing.
1561e59058c4SJames Smart  *
1562e59058c4SJames Smart  * Return codes
1563e59058c4SJames Smart  *    pointer to the driver internal queue element for mailbox command.
1564e59058c4SJames Smart  **/
1565dea3101eS LPFC_MBOXQ_t *
lpfc_mbox_get(struct lpfc_hba * phba)1566dea3101eS lpfc_mbox_get(struct lpfc_hba * phba)
1567dea3101eS {
1568dea3101eS 	LPFC_MBOXQ_t *mbq = NULL;
1569dea3101eS 	struct lpfc_sli *psli = &phba->sli;
1570dea3101eS 
15712e0fef85SJames Smart 	list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
157292d7f7b0SJames Smart 	if (mbq)
1573dea3101eS 		psli->mboxq_cnt--;
1574dea3101eS 
1575dea3101eS 	return mbq;
1576dea3101eS }
1577a309a6b6SJames Smart 
1578e59058c4SJames Smart /**
157904c68496SJames Smart  * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
158004c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
158104c68496SJames Smart  * @mbq: pointer to the driver internal queue element for mailbox command.
158204c68496SJames Smart  *
158304c68496SJames Smart  * This routine put the completed mailbox command into the mailbox command
158404c68496SJames Smart  * complete list. This is the unlocked version of the routine. The mailbox
158504c68496SJames Smart  * complete list is used by the driver worker thread to process mailbox
158604c68496SJames Smart  * complete callback functions outside the driver interrupt handler.
158704c68496SJames Smart  **/
158804c68496SJames Smart void
__lpfc_mbox_cmpl_put(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbq)158904c68496SJames Smart __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
159004c68496SJames Smart {
159104c68496SJames Smart 	list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
159204c68496SJames Smart }
159304c68496SJames Smart 
159404c68496SJames Smart /**
15953621a710SJames Smart  * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
1596e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1597e59058c4SJames Smart  * @mbq: pointer to the driver internal queue element for mailbox command.
1598e59058c4SJames Smart  *
1599e59058c4SJames Smart  * This routine put the completed mailbox command into the mailbox command
160004c68496SJames Smart  * complete list. This is the locked version of the routine. The mailbox
160104c68496SJames Smart  * complete list is used by the driver worker thread to process mailbox
160204c68496SJames Smart  * complete callback functions outside the driver interrupt handler.
1603e59058c4SJames Smart  **/
160492d7f7b0SJames Smart void
lpfc_mbox_cmpl_put(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbq)160592d7f7b0SJames Smart lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
160692d7f7b0SJames Smart {
16075b75da2fSJames Smart 	unsigned long iflag;
16085b75da2fSJames Smart 
1609b1c11812SJoe Perches 	/* This function expects to be called from interrupt context */
16105b75da2fSJames Smart 	spin_lock_irqsave(&phba->hbalock, iflag);
161104c68496SJames Smart 	__lpfc_mbox_cmpl_put(phba, mbq);
16125b75da2fSJames Smart 	spin_unlock_irqrestore(&phba->hbalock, iflag);
161392d7f7b0SJames Smart 	return;
161492d7f7b0SJames Smart }
161592d7f7b0SJames Smart 
1616e59058c4SJames Smart /**
161704c68496SJames Smart  * lpfc_mbox_cmd_check - Check the validality of a mailbox command
161804c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
161904c68496SJames Smart  * @mboxq: pointer to the driver internal queue element for mailbox command.
162004c68496SJames Smart  *
162104c68496SJames Smart  * This routine is to check whether a mailbox command is valid to be issued.
162204c68496SJames Smart  * This check will be performed by both the mailbox issue API when a client
162304c68496SJames Smart  * is to issue a mailbox command to the mailbox transport.
162404c68496SJames Smart  *
162504c68496SJames Smart  * Return 0 - pass the check, -ENODEV - fail the check
162604c68496SJames Smart  **/
162704c68496SJames Smart int
lpfc_mbox_cmd_check(struct lpfc_hba * phba,LPFC_MBOXQ_t * mboxq)162804c68496SJames Smart lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
162904c68496SJames Smart {
163004c68496SJames Smart 	/* Mailbox command that have a completion handler must also have a
163104c68496SJames Smart 	 * vport specified.
163204c68496SJames Smart 	 */
163304c68496SJames Smart 	if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
163404c68496SJames Smart 	    mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
163504c68496SJames Smart 		if (!mboxq->vport) {
163604c68496SJames Smart 			lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
163704c68496SJames Smart 					"1814 Mbox x%x failed, no vport\n",
163804c68496SJames Smart 					mboxq->u.mb.mbxCommand);
163904c68496SJames Smart 			dump_stack();
164004c68496SJames Smart 			return -ENODEV;
164104c68496SJames Smart 		}
164204c68496SJames Smart 	}
164304c68496SJames Smart 	return 0;
164404c68496SJames Smart }
164504c68496SJames Smart 
164604c68496SJames Smart /**
164704c68496SJames Smart  * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
164804c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
164904c68496SJames Smart  *
165004c68496SJames Smart  * This routine is to check whether the HBA device is ready for posting a
165104c68496SJames Smart  * mailbox command. It is used by the mailbox transport API at the time the
165204c68496SJames Smart  * to post a mailbox command to the device.
165304c68496SJames Smart  *
165404c68496SJames Smart  * Return 0 - pass the check, -ENODEV - fail the check
165504c68496SJames Smart  **/
165604c68496SJames Smart int
lpfc_mbox_dev_check(struct lpfc_hba * phba)165704c68496SJames Smart lpfc_mbox_dev_check(struct lpfc_hba *phba)
165804c68496SJames Smart {
165904c68496SJames Smart 	/* If the PCI channel is in offline state, do not issue mbox */
166004c68496SJames Smart 	if (unlikely(pci_channel_offline(phba->pcidev)))
166104c68496SJames Smart 		return -ENODEV;
166204c68496SJames Smart 
166304c68496SJames Smart 	/* If the HBA is in error state, do not issue mbox */
166404c68496SJames Smart 	if (phba->link_state == LPFC_HBA_ERROR)
166504c68496SJames Smart 		return -ENODEV;
166604c68496SJames Smart 
166704c68496SJames Smart 	return 0;
166804c68496SJames Smart }
166904c68496SJames Smart 
167004c68496SJames Smart /**
16713621a710SJames Smart  * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
1672e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1673012d019fSLee Jones  * @mboxq: pointer to the driver internal queue element for mailbox command.
1674e59058c4SJames Smart  *
1675e59058c4SJames Smart  * This routine retrieves the proper timeout value according to the mailbox
1676e59058c4SJames Smart  * command code.
1677e59058c4SJames Smart  *
1678e59058c4SJames Smart  * Return codes
1679e59058c4SJames Smart  *    Timeout value to be used for the given mailbox command
1680e59058c4SJames Smart  **/
1681a309a6b6SJames Smart int
lpfc_mbox_tmo_val(struct lpfc_hba * phba,LPFC_MBOXQ_t * mboxq)1682a183a15fSJames Smart lpfc_mbox_tmo_val(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1683a309a6b6SJames Smart {
1684a183a15fSJames Smart 	MAILBOX_t *mbox = &mboxq->u.mb;
1685a183a15fSJames Smart 	uint8_t subsys, opcode;
1686a183a15fSJames Smart 
1687a183a15fSJames Smart 	switch (mbox->mbxCommand) {
1688a309a6b6SJames Smart 	case MBX_WRITE_NV:	/* 0x03 */
1689940eb687SJames Smart 	case MBX_DUMP_MEMORY:	/* 0x17 */
1690a309a6b6SJames Smart 	case MBX_UPDATE_CFG:	/* 0x1B */
1691a309a6b6SJames Smart 	case MBX_DOWN_LOAD:	/* 0x1C */
1692a309a6b6SJames Smart 	case MBX_DEL_LD_ENTRY:	/* 0x1D */
1693940eb687SJames Smart 	case MBX_WRITE_VPARMS:	/* 0x32 */
1694a309a6b6SJames Smart 	case MBX_LOAD_AREA:	/* 0x81 */
169509372820SJames Smart 	case MBX_WRITE_WWN:     /* 0x98 */
1696a309a6b6SJames Smart 	case MBX_LOAD_EXP_ROM:	/* 0x9C */
1697940eb687SJames Smart 	case MBX_ACCESS_VDATA:	/* 0xA5 */
1698a309a6b6SJames Smart 		return LPFC_MBOX_TMO_FLASH_CMD;
169904c68496SJames Smart 	case MBX_SLI4_CONFIG:	/* 0x9b */
1700a183a15fSJames Smart 		subsys = lpfc_sli_config_mbox_subsys_get(phba, mboxq);
1701a183a15fSJames Smart 		opcode = lpfc_sli_config_mbox_opcode_get(phba, mboxq);
1702a183a15fSJames Smart 		if (subsys == LPFC_MBOX_SUBSYSTEM_COMMON) {
1703a183a15fSJames Smart 			switch (opcode) {
1704a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_READ_OBJECT:
1705a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_WRITE_OBJECT:
1706a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_READ_OBJECT_LIST:
1707a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_DELETE_OBJECT:
1708a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_GET_PROFILE_LIST:
1709a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_SET_ACT_PROFILE:
1710940eb687SJames Smart 			case LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG:
1711a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG:
1712a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG:
1713940eb687SJames Smart 			case LPFC_MBOX_OPCODE_GET_PROFILE_CAPACITIES:
1714940eb687SJames Smart 			case LPFC_MBOX_OPCODE_SEND_ACTIVATION:
1715940eb687SJames Smart 			case LPFC_MBOX_OPCODE_RESET_LICENSES:
1716940eb687SJames Smart 			case LPFC_MBOX_OPCODE_SET_BOOT_CONFIG:
1717940eb687SJames Smart 			case LPFC_MBOX_OPCODE_GET_VPD_DATA:
1718940eb687SJames Smart 			case LPFC_MBOX_OPCODE_SET_PHYSICAL_LINK_CONFIG:
1719a183a15fSJames Smart 				return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO;
1720a183a15fSJames Smart 			}
1721a183a15fSJames Smart 		}
1722a183a15fSJames Smart 		if (subsys == LPFC_MBOX_SUBSYSTEM_FCOE) {
1723a183a15fSJames Smart 			switch (opcode) {
1724a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS:
1725a183a15fSJames Smart 				return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO;
1726a183a15fSJames Smart 			}
1727a183a15fSJames Smart 		}
172804c68496SJames Smart 		return LPFC_MBOX_SLI4_CONFIG_TMO;
1729a309a6b6SJames Smart 	}
1730a309a6b6SJames Smart 	return LPFC_MBOX_TMO;
1731a309a6b6SJames Smart }
173204c68496SJames Smart 
173304c68496SJames Smart /**
173404c68496SJames Smart  * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
173504c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
173604c68496SJames Smart  * @sgentry: sge entry index.
173704c68496SJames Smart  * @phyaddr: physical address for the sge
173804c68496SJames Smart  * @length: Length of the sge.
173904c68496SJames Smart  *
174004c68496SJames Smart  * This routine sets up an entry in the non-embedded mailbox command at the sge
174104c68496SJames Smart  * index location.
174204c68496SJames Smart  **/
174304c68496SJames Smart void
lpfc_sli4_mbx_sge_set(struct lpfcMboxq * mbox,uint32_t sgentry,dma_addr_t phyaddr,uint32_t length)174404c68496SJames Smart lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry,
174504c68496SJames Smart 		      dma_addr_t phyaddr, uint32_t length)
174604c68496SJames Smart {
174704c68496SJames Smart 	struct lpfc_mbx_nembed_cmd *nembed_sge;
174804c68496SJames Smart 
174904c68496SJames Smart 	nembed_sge = (struct lpfc_mbx_nembed_cmd *)
175004c68496SJames Smart 				&mbox->u.mqe.un.nembed_cmd;
175104c68496SJames Smart 	nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr);
175204c68496SJames Smart 	nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr);
175304c68496SJames Smart 	nembed_sge->sge[sgentry].length = length;
175404c68496SJames Smart }
175504c68496SJames Smart 
175604c68496SJames Smart /**
175704c68496SJames Smart  * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
175804c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
175904c68496SJames Smart  * @sgentry: sge entry index.
1760012d019fSLee Jones  * @sge: pointer to lpfc mailbox sge to load into.
176104c68496SJames Smart  *
176204c68496SJames Smart  * This routine gets an entry from the non-embedded mailbox command at the sge
176304c68496SJames Smart  * index location.
176404c68496SJames Smart  **/
176504c68496SJames Smart void
lpfc_sli4_mbx_sge_get(struct lpfcMboxq * mbox,uint32_t sgentry,struct lpfc_mbx_sge * sge)176604c68496SJames Smart lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry,
176704c68496SJames Smart 		      struct lpfc_mbx_sge *sge)
176804c68496SJames Smart {
176904c68496SJames Smart 	struct lpfc_mbx_nembed_cmd *nembed_sge;
177004c68496SJames Smart 
177104c68496SJames Smart 	nembed_sge = (struct lpfc_mbx_nembed_cmd *)
177204c68496SJames Smart 				&mbox->u.mqe.un.nembed_cmd;
177304c68496SJames Smart 	sge->pa_lo = nembed_sge->sge[sgentry].pa_lo;
177404c68496SJames Smart 	sge->pa_hi = nembed_sge->sge[sgentry].pa_hi;
177504c68496SJames Smart 	sge->length = nembed_sge->sge[sgentry].length;
177604c68496SJames Smart }
177704c68496SJames Smart 
177804c68496SJames Smart /**
177904c68496SJames Smart  * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
178004c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
178104c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
178204c68496SJames Smart  *
1783ef47575fSJames Smart  * This routine cleans up and releases an SLI4 mailbox command that was
1784ef47575fSJames Smart  * configured using lpfc_sli4_config.  It accounts for the embedded and
1785ef47575fSJames Smart  * non-embedded config types.
178604c68496SJames Smart  **/
178704c68496SJames Smart void
lpfc_sli4_mbox_cmd_free(struct lpfc_hba * phba,struct lpfcMboxq * mbox)178804c68496SJames Smart lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
178904c68496SJames Smart {
179004c68496SJames Smart 	struct lpfc_mbx_sli4_config *sli4_cfg;
179104c68496SJames Smart 	struct lpfc_mbx_sge sge;
179204c68496SJames Smart 	dma_addr_t phyaddr;
179304c68496SJames Smart 	uint32_t sgecount, sgentry;
179404c68496SJames Smart 
179504c68496SJames Smart 	sli4_cfg = &mbox->u.mqe.un.sli4_config;
179604c68496SJames Smart 
179704c68496SJames Smart 	/* For embedded mbox command, just free the mbox command */
179804c68496SJames Smart 	if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
179904c68496SJames Smart 		mempool_free(mbox, phba->mbox_mem_pool);
180004c68496SJames Smart 		return;
180104c68496SJames Smart 	}
180204c68496SJames Smart 
180304c68496SJames Smart 	/* For non-embedded mbox command, we need to free the pages first */
180404c68496SJames Smart 	sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr);
180504c68496SJames Smart 	/* There is nothing we can do if there is no sge address array */
180604c68496SJames Smart 	if (unlikely(!mbox->sge_array)) {
180704c68496SJames Smart 		mempool_free(mbox, phba->mbox_mem_pool);
180804c68496SJames Smart 		return;
180904c68496SJames Smart 	}
181004c68496SJames Smart 	/* Each non-embedded DMA memory was allocated in the length of a page */
181104c68496SJames Smart 	for (sgentry = 0; sgentry < sgecount; sgentry++) {
181204c68496SJames Smart 		lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge);
181304c68496SJames Smart 		phyaddr = getPaddr(sge.pa_hi, sge.pa_lo);
181449198b37SJames Smart 		dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
181504c68496SJames Smart 				  mbox->sge_array->addr[sgentry], phyaddr);
181604c68496SJames Smart 	}
181704c68496SJames Smart 	/* Free the sge address array memory */
181804c68496SJames Smart 	kfree(mbox->sge_array);
181904c68496SJames Smart 	/* Finally, free the mailbox command itself */
182004c68496SJames Smart 	mempool_free(mbox, phba->mbox_mem_pool);
182104c68496SJames Smart }
182204c68496SJames Smart 
182304c68496SJames Smart /**
182404c68496SJames Smart  * lpfc_sli4_config - Initialize the  SLI4 Config Mailbox command
182504c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
182604c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
182704c68496SJames Smart  * @subsystem: The sli4 config sub mailbox subsystem.
182804c68496SJames Smart  * @opcode: The sli4 config sub mailbox command opcode.
1829fedd3b7bSJames Smart  * @length: Length of the sli4 config mailbox command (including sub-header).
1830012d019fSLee Jones  * @emb: True if embedded mbox command should be setup.
183104c68496SJames Smart  *
183204c68496SJames Smart  * This routine sets up the header fields of SLI4 specific mailbox command
183304c68496SJames Smart  * for sending IOCTL command.
183404c68496SJames Smart  *
183504c68496SJames Smart  * Return: the actual length of the mbox command allocated (mostly useful
183604c68496SJames Smart  *         for none embedded mailbox command).
183704c68496SJames Smart  **/
183804c68496SJames Smart int
lpfc_sli4_config(struct lpfc_hba * phba,struct lpfcMboxq * mbox,uint8_t subsystem,uint8_t opcode,uint32_t length,bool emb)183904c68496SJames Smart lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
184004c68496SJames Smart 		 uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb)
184104c68496SJames Smart {
184204c68496SJames Smart 	struct lpfc_mbx_sli4_config *sli4_config;
184304c68496SJames Smart 	union lpfc_sli4_cfg_shdr *cfg_shdr = NULL;
184404c68496SJames Smart 	uint32_t alloc_len;
184504c68496SJames Smart 	uint32_t resid_len;
184604c68496SJames Smart 	uint32_t pagen, pcount;
184704c68496SJames Smart 	void *viraddr;
184804c68496SJames Smart 	dma_addr_t phyaddr;
184904c68496SJames Smart 
185004c68496SJames Smart 	/* Set up SLI4 mailbox command header fields */
185104c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
185204c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG);
185304c68496SJames Smart 
185404c68496SJames Smart 	/* Set up SLI4 ioctl command header fields */
185504c68496SJames Smart 	sli4_config = &mbox->u.mqe.un.sli4_config;
185604c68496SJames Smart 
185704c68496SJames Smart 	/* Setup for the embedded mbox command */
185804c68496SJames Smart 	if (emb) {
185904c68496SJames Smart 		/* Set up main header fields */
186004c68496SJames Smart 		bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
1861fedd3b7bSJames Smart 		sli4_config->header.cfg_mhdr.payload_length = length;
186204c68496SJames Smart 		/* Set up sub-header fields following main header */
186304c68496SJames Smart 		bf_set(lpfc_mbox_hdr_opcode,
186404c68496SJames Smart 			&sli4_config->header.cfg_shdr.request, opcode);
186504c68496SJames Smart 		bf_set(lpfc_mbox_hdr_subsystem,
186604c68496SJames Smart 			&sli4_config->header.cfg_shdr.request, subsystem);
1867fedd3b7bSJames Smart 		sli4_config->header.cfg_shdr.request.request_length =
1868fedd3b7bSJames Smart 			length - LPFC_MBX_CMD_HDR_LENGTH;
186904c68496SJames Smart 		return length;
187004c68496SJames Smart 	}
187104c68496SJames Smart 
18726d368e53SJames Smart 	/* Setup for the non-embedded mbox command */
18739589b062SJames Smart 	pcount = (SLI4_PAGE_ALIGN(length))/SLI4_PAGE_SIZE;
187404c68496SJames Smart 	pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ?
187504c68496SJames Smart 				LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount;
187604c68496SJames Smart 	/* Allocate record for keeping SGE virtual addresses */
18776d368e53SJames Smart 	mbox->sge_array = kzalloc(sizeof(struct lpfc_mbx_nembed_sge_virt),
187804c68496SJames Smart 				  GFP_KERNEL);
18796a9c52cfSJames Smart 	if (!mbox->sge_array) {
18806a9c52cfSJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
18816a9c52cfSJames Smart 				"2527 Failed to allocate non-embedded SGE "
18826a9c52cfSJames Smart 				"array.\n");
188304c68496SJames Smart 		return 0;
18846a9c52cfSJames Smart 	}
188504c68496SJames Smart 	for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) {
188604c68496SJames Smart 		/* The DMA memory is always allocated in the length of a
188704c68496SJames Smart 		 * page even though the last SGE might not fill up to a
188849198b37SJames Smart 		 * page, this is used as a priori size of SLI4_PAGE_SIZE for
188904c68496SJames Smart 		 * the later DMA memory free.
189004c68496SJames Smart 		 */
1891750afb08SLuis Chamberlain 		viraddr = dma_alloc_coherent(&phba->pcidev->dev,
18921aee383dSJoe Perches 					     SLI4_PAGE_SIZE, &phyaddr,
18931aee383dSJoe Perches 					     GFP_KERNEL);
189404c68496SJames Smart 		/* In case of malloc fails, proceed with whatever we have */
189504c68496SJames Smart 		if (!viraddr)
189604c68496SJames Smart 			break;
189704c68496SJames Smart 		mbox->sge_array->addr[pagen] = viraddr;
189804c68496SJames Smart 		/* Keep the first page for later sub-header construction */
189904c68496SJames Smart 		if (pagen == 0)
190004c68496SJames Smart 			cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr;
190104c68496SJames Smart 		resid_len = length - alloc_len;
190249198b37SJames Smart 		if (resid_len > SLI4_PAGE_SIZE) {
190304c68496SJames Smart 			lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
190449198b37SJames Smart 					      SLI4_PAGE_SIZE);
190549198b37SJames Smart 			alloc_len += SLI4_PAGE_SIZE;
190604c68496SJames Smart 		} else {
190704c68496SJames Smart 			lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
190804c68496SJames Smart 					      resid_len);
190904c68496SJames Smart 			alloc_len = length;
191004c68496SJames Smart 		}
191104c68496SJames Smart 	}
191204c68496SJames Smart 
191304c68496SJames Smart 	/* Set up main header fields in mailbox command */
191404c68496SJames Smart 	sli4_config->header.cfg_mhdr.payload_length = alloc_len;
191504c68496SJames Smart 	bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen);
191604c68496SJames Smart 
191704c68496SJames Smart 	/* Set up sub-header fields into the first page */
191804c68496SJames Smart 	if (pagen > 0) {
191904c68496SJames Smart 		bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode);
192004c68496SJames Smart 		bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem);
192104c68496SJames Smart 		cfg_shdr->request.request_length =
192204c68496SJames Smart 				alloc_len - sizeof(union  lpfc_sli4_cfg_shdr);
192304c68496SJames Smart 	}
192404c68496SJames Smart 	/* The sub-header is in DMA memory, which needs endian converstion */
192572100cc4SJames Smart 	if (cfg_shdr)
192604c68496SJames Smart 		lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
192704c68496SJames Smart 				      sizeof(union  lpfc_sli4_cfg_shdr));
192804c68496SJames Smart 	return alloc_len;
192904c68496SJames Smart }
193004c68496SJames Smart 
193104c68496SJames Smart /**
19326d368e53SJames Smart  * lpfc_sli4_mbox_rsrc_extent - Initialize the opcode resource extent.
19336d368e53SJames Smart  * @phba: pointer to lpfc hba data structure.
19346d368e53SJames Smart  * @mbox: pointer to an allocated lpfc mbox resource.
19356d368e53SJames Smart  * @exts_count: the number of extents, if required, to allocate.
19366d368e53SJames Smart  * @rsrc_type: the resource extent type.
19376d368e53SJames Smart  * @emb: true if LPFC_SLI4_MBX_EMBED. false if LPFC_SLI4_MBX_NEMBED.
19386d368e53SJames Smart  *
19396d368e53SJames Smart  * This routine completes the subcommand header for SLI4 resource extent
19406d368e53SJames Smart  * mailbox commands.  It is called after lpfc_sli4_config.  The caller must
19416d368e53SJames Smart  * pass an allocated mailbox and the attributes required to initialize the
19426d368e53SJames Smart  * mailbox correctly.
19436d368e53SJames Smart  *
19446d368e53SJames Smart  * Return: the actual length of the mbox command allocated.
19456d368e53SJames Smart  **/
19466d368e53SJames Smart int
lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba * phba,struct lpfcMboxq * mbox,uint16_t exts_count,uint16_t rsrc_type,bool emb)19476d368e53SJames Smart lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
19486d368e53SJames Smart 			   uint16_t exts_count, uint16_t rsrc_type, bool emb)
19496d368e53SJames Smart {
19506d368e53SJames Smart 	uint8_t opcode = 0;
19516d368e53SJames Smart 	struct lpfc_mbx_nembed_rsrc_extent *n_rsrc_extnt = NULL;
19526d368e53SJames Smart 	void *virtaddr = NULL;
19536d368e53SJames Smart 
19546d368e53SJames Smart 	/* Set up SLI4 ioctl command header fields */
19556d368e53SJames Smart 	if (emb == LPFC_SLI4_MBX_NEMBED) {
19566d368e53SJames Smart 		/* Get the first SGE entry from the non-embedded DMA memory */
19576d368e53SJames Smart 		virtaddr = mbox->sge_array->addr[0];
19586d368e53SJames Smart 		if (virtaddr == NULL)
19596d368e53SJames Smart 			return 1;
19606d368e53SJames Smart 		n_rsrc_extnt = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
19616d368e53SJames Smart 	}
19626d368e53SJames Smart 
19636d368e53SJames Smart 	/*
19646d368e53SJames Smart 	 * The resource type is common to all extent Opcodes and resides in the
19656d368e53SJames Smart 	 * same position.
19666d368e53SJames Smart 	 */
19676d368e53SJames Smart 	if (emb == LPFC_SLI4_MBX_EMBED)
19686d368e53SJames Smart 		bf_set(lpfc_mbx_alloc_rsrc_extents_type,
19696d368e53SJames Smart 		       &mbox->u.mqe.un.alloc_rsrc_extents.u.req,
19706d368e53SJames Smart 		       rsrc_type);
19716d368e53SJames Smart 	else {
19726d368e53SJames Smart 		/* This is DMA data.  Byteswap is required. */
19736d368e53SJames Smart 		bf_set(lpfc_mbx_alloc_rsrc_extents_type,
19746d368e53SJames Smart 		       n_rsrc_extnt, rsrc_type);
19756d368e53SJames Smart 		lpfc_sli_pcimem_bcopy(&n_rsrc_extnt->word4,
19766d368e53SJames Smart 				      &n_rsrc_extnt->word4,
19776d368e53SJames Smart 				      sizeof(uint32_t));
19786d368e53SJames Smart 	}
19796d368e53SJames Smart 
19806d368e53SJames Smart 	/* Complete the initialization for the particular Opcode. */
1981a183a15fSJames Smart 	opcode = lpfc_sli_config_mbox_opcode_get(phba, mbox);
19826d368e53SJames Smart 	switch (opcode) {
19836d368e53SJames Smart 	case LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT:
19846d368e53SJames Smart 		if (emb == LPFC_SLI4_MBX_EMBED)
19856d368e53SJames Smart 			bf_set(lpfc_mbx_alloc_rsrc_extents_cnt,
19866d368e53SJames Smart 			       &mbox->u.mqe.un.alloc_rsrc_extents.u.req,
19876d368e53SJames Smart 			       exts_count);
19886d368e53SJames Smart 		else
19896d368e53SJames Smart 			bf_set(lpfc_mbx_alloc_rsrc_extents_cnt,
19906d368e53SJames Smart 			       n_rsrc_extnt, exts_count);
19916d368e53SJames Smart 		break;
19926d368e53SJames Smart 	case LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT:
19936d368e53SJames Smart 	case LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO:
19946d368e53SJames Smart 	case LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT:
19956d368e53SJames Smart 		/* Initialization is complete.*/
19966d368e53SJames Smart 		break;
19976d368e53SJames Smart 	default:
19986d368e53SJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
19996d368e53SJames Smart 				"2929 Resource Extent Opcode x%x is "
20006d368e53SJames Smart 				"unsupported\n", opcode);
20016d368e53SJames Smart 		return 1;
20026d368e53SJames Smart 	}
20036d368e53SJames Smart 
20046d368e53SJames Smart 	return 0;
20056d368e53SJames Smart }
20066d368e53SJames Smart 
20076d368e53SJames Smart /**
2008a183a15fSJames Smart  * lpfc_sli_config_mbox_subsys_get - Get subsystem from a sli_config mbox cmd
200904c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
2010a183a15fSJames Smart  * @mbox: pointer to lpfc mbox command queue entry.
201104c68496SJames Smart  *
2012a183a15fSJames Smart  * This routine gets the subsystem from a SLI4 specific SLI_CONFIG mailbox
2013a183a15fSJames Smart  * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if the
2014a183a15fSJames Smart  * sub-header is not present, subsystem LPFC_MBOX_SUBSYSTEM_NA (0x0) shall
2015a183a15fSJames Smart  * be returned.
201604c68496SJames Smart  **/
201704c68496SJames Smart uint8_t
lpfc_sli_config_mbox_subsys_get(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbox)2018a183a15fSJames Smart lpfc_sli_config_mbox_subsys_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
201904c68496SJames Smart {
202004c68496SJames Smart 	struct lpfc_mbx_sli4_config *sli4_cfg;
202104c68496SJames Smart 	union lpfc_sli4_cfg_shdr *cfg_shdr;
202204c68496SJames Smart 
202304c68496SJames Smart 	if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
2024a183a15fSJames Smart 		return LPFC_MBOX_SUBSYSTEM_NA;
2025a183a15fSJames Smart 	sli4_cfg = &mbox->u.mqe.un.sli4_config;
2026a183a15fSJames Smart 
2027a183a15fSJames Smart 	/* For embedded mbox command, get opcode from embedded sub-header*/
2028a183a15fSJames Smart 	if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
2029a183a15fSJames Smart 		cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
2030a183a15fSJames Smart 		return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request);
2031a183a15fSJames Smart 	}
2032a183a15fSJames Smart 
2033a183a15fSJames Smart 	/* For non-embedded mbox command, get opcode from first dma page */
2034a183a15fSJames Smart 	if (unlikely(!mbox->sge_array))
2035a183a15fSJames Smart 		return LPFC_MBOX_SUBSYSTEM_NA;
2036a183a15fSJames Smart 	cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
2037a183a15fSJames Smart 	return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request);
2038a183a15fSJames Smart }
2039a183a15fSJames Smart 
2040a183a15fSJames Smart /**
2041a183a15fSJames Smart  * lpfc_sli_config_mbox_opcode_get - Get opcode from a sli_config mbox cmd
2042a183a15fSJames Smart  * @phba: pointer to lpfc hba data structure.
2043a183a15fSJames Smart  * @mbox: pointer to lpfc mbox command queue entry.
2044a183a15fSJames Smart  *
2045a183a15fSJames Smart  * This routine gets the opcode from a SLI4 specific SLI_CONFIG mailbox
2046a183a15fSJames Smart  * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if
2047a183a15fSJames Smart  * the sub-header is not present, opcode LPFC_MBOX_OPCODE_NA (0x0) be
2048a183a15fSJames Smart  * returned.
2049a183a15fSJames Smart  **/
2050a183a15fSJames Smart uint8_t
lpfc_sli_config_mbox_opcode_get(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbox)2051a183a15fSJames Smart lpfc_sli_config_mbox_opcode_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
2052a183a15fSJames Smart {
2053a183a15fSJames Smart 	struct lpfc_mbx_sli4_config *sli4_cfg;
2054a183a15fSJames Smart 	union lpfc_sli4_cfg_shdr *cfg_shdr;
2055a183a15fSJames Smart 
2056a183a15fSJames Smart 	if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
2057a183a15fSJames Smart 		return LPFC_MBOX_OPCODE_NA;
205804c68496SJames Smart 	sli4_cfg = &mbox->u.mqe.un.sli4_config;
205904c68496SJames Smart 
206004c68496SJames Smart 	/* For embedded mbox command, get opcode from embedded sub-header*/
206104c68496SJames Smart 	if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
206204c68496SJames Smart 		cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
206304c68496SJames Smart 		return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
206404c68496SJames Smart 	}
206504c68496SJames Smart 
206604c68496SJames Smart 	/* For non-embedded mbox command, get opcode from first dma page */
206704c68496SJames Smart 	if (unlikely(!mbox->sge_array))
2068a183a15fSJames Smart 		return LPFC_MBOX_OPCODE_NA;
206904c68496SJames Smart 	cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
207004c68496SJames Smart 	return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
207104c68496SJames Smart }
207204c68496SJames Smart 
207304c68496SJames Smart /**
20740c9ab6f5SJames Smart  * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd
2075ecfd03c6SJames Smart  * @phba: pointer to lpfc hba data structure.
2076012d019fSLee Jones  * @mboxq: pointer to lpfc mbox command.
2077ecfd03c6SJames Smart  * @fcf_index: index to fcf table.
2078ecfd03c6SJames Smart  *
2079ecfd03c6SJames Smart  * This routine routine allocates and constructs non-embedded mailbox command
208025985edcSLucas De Marchi  * for reading a FCF table entry referred by @fcf_index.
2081ecfd03c6SJames Smart  *
2082ecfd03c6SJames Smart  * Return: pointer to the mailbox command constructed if successful, otherwise
2083ecfd03c6SJames Smart  * NULL.
2084ecfd03c6SJames Smart  **/
2085ecfd03c6SJames Smart int
lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba * phba,struct lpfcMboxq * mboxq,uint16_t fcf_index)20860c9ab6f5SJames Smart lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *phba,
2087ecfd03c6SJames Smart 			   struct lpfcMboxq *mboxq,
2088ecfd03c6SJames Smart 			   uint16_t fcf_index)
2089ecfd03c6SJames Smart {
2090ecfd03c6SJames Smart 	void *virt_addr;
2091ecfd03c6SJames Smart 	uint8_t *bytep;
2092ecfd03c6SJames Smart 	struct lpfc_mbx_sge sge;
2093ecfd03c6SJames Smart 	uint32_t alloc_len, req_len;
2094ecfd03c6SJames Smart 	struct lpfc_mbx_read_fcf_tbl *read_fcf;
2095ecfd03c6SJames Smart 
2096ecfd03c6SJames Smart 	if (!mboxq)
2097ecfd03c6SJames Smart 		return -ENOMEM;
2098ecfd03c6SJames Smart 
2099ecfd03c6SJames Smart 	req_len = sizeof(struct fcf_record) +
2100ecfd03c6SJames Smart 		  sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
2101ecfd03c6SJames Smart 
2102ecfd03c6SJames Smart 	/* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
2103ecfd03c6SJames Smart 	alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
2104ecfd03c6SJames Smart 			LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
2105ecfd03c6SJames Smart 			LPFC_SLI4_MBX_NEMBED);
2106ecfd03c6SJames Smart 
2107ecfd03c6SJames Smart 	if (alloc_len < req_len) {
2108ecfd03c6SJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2109ecfd03c6SJames Smart 				"0291 Allocated DMA memory size (x%x) is "
2110ecfd03c6SJames Smart 				"less than the requested DMA memory "
2111ecfd03c6SJames Smart 				"size (x%x)\n", alloc_len, req_len);
2112ecfd03c6SJames Smart 		return -ENOMEM;
2113ecfd03c6SJames Smart 	}
2114ecfd03c6SJames Smart 
2115ecfd03c6SJames Smart 	/* Get the first SGE entry from the non-embedded DMA memory. This
2116ecfd03c6SJames Smart 	 * routine only uses a single SGE.
2117ecfd03c6SJames Smart 	 */
2118ecfd03c6SJames Smart 	lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
2119ecfd03c6SJames Smart 	virt_addr = mboxq->sge_array->addr[0];
2120ecfd03c6SJames Smart 	read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
2121ecfd03c6SJames Smart 
2122ecfd03c6SJames Smart 	/* Set up command fields */
2123ecfd03c6SJames Smart 	bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
2124ecfd03c6SJames Smart 	/* Perform necessary endian conversion */
2125ecfd03c6SJames Smart 	bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
2126ecfd03c6SJames Smart 	lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
2127ecfd03c6SJames Smart 
2128ecfd03c6SJames Smart 	return 0;
2129ecfd03c6SJames Smart }
2130ecfd03c6SJames Smart 
2131ecfd03c6SJames Smart /**
213204c68496SJames Smart  * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
2133012d019fSLee Jones  * @phba: pointer to lpfc hba data structure.
213404c68496SJames Smart  * @mboxq: pointer to lpfc mbox command.
213504c68496SJames Smart  *
213604c68496SJames Smart  * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
213704c68496SJames Smart  * mailbox command.
213804c68496SJames Smart  **/
213904c68496SJames Smart void
lpfc_request_features(struct lpfc_hba * phba,struct lpfcMboxq * mboxq)214004c68496SJames Smart lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
214104c68496SJames Smart {
214204c68496SJames Smart 	/* Set up SLI4 mailbox command header fields */
214304c68496SJames Smart 	memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
214404c68496SJames Smart 	bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS);
214504c68496SJames Smart 
214604c68496SJames Smart 	/* Set up host requested features. */
214704c68496SJames Smart 	bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
2148fedd3b7bSJames Smart 	bf_set(lpfc_mbx_rq_ftr_rq_perfh, &mboxq->u.mqe.un.req_ftrs, 1);
214904c68496SJames Smart 
215004c68496SJames Smart 	/* Enable DIF (block guard) only if configured to do so. */
215104c68496SJames Smart 	if (phba->cfg_enable_bg)
215204c68496SJames Smart 		bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1);
215304c68496SJames Smart 
215404c68496SJames Smart 	/* Enable NPIV only if configured to do so. */
215504c68496SJames Smart 	if (phba->max_vpi && phba->cfg_enable_npiv)
215604c68496SJames Smart 		bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1);
215704c68496SJames Smart 
215886c67379SJames Smart 	if (phba->nvmet_support) {
21592d7dbc4cSJames Smart 		bf_set(lpfc_mbx_rq_ftr_rq_mrqp, &mboxq->u.mqe.un.req_ftrs, 1);
216086c67379SJames Smart 		/* iaab/iaar NOT set for now */
216186c67379SJames Smart 		bf_set(lpfc_mbx_rq_ftr_rq_iaab, &mboxq->u.mqe.un.req_ftrs, 0);
216286c67379SJames Smart 		bf_set(lpfc_mbx_rq_ftr_rq_iaar, &mboxq->u.mqe.un.req_ftrs, 0);
216386c67379SJames Smart 	}
21645e633302SGaurav Srivastava 
21655e633302SGaurav Srivastava 	/* Enable Application Services Header for appheader VMID */
21665e633302SGaurav Srivastava 	if (phba->cfg_vmid_app_header) {
21675e633302SGaurav Srivastava 		bf_set(lpfc_mbx_rq_ftr_rq_ashdr, &mboxq->u.mqe.un.req_ftrs, 1);
21685e633302SGaurav Srivastava 		bf_set(lpfc_ftr_ashdr, &phba->sli4_hba.sli4_flags, 1);
21695e633302SGaurav Srivastava 	}
217004c68496SJames Smart 	return;
217104c68496SJames Smart }
217204c68496SJames Smart 
217304c68496SJames Smart /**
217404c68496SJames Smart  * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
217504c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
217604c68496SJames Smart  * @vport: Vport associated with the VF.
217704c68496SJames Smart  *
217804c68496SJames Smart  * This routine initializes @mbox to all zeros and then fills in the mailbox
217904c68496SJames Smart  * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
218004c68496SJames Smart  * in the context of an FCF. The driver issues this command to setup a VFI
218104c68496SJames Smart  * before issuing a FLOGI to login to the VSAN. The driver should also issue a
218204c68496SJames Smart  * REG_VFI after a successful VSAN login.
218304c68496SJames Smart  **/
218404c68496SJames Smart void
lpfc_init_vfi(struct lpfcMboxq * mbox,struct lpfc_vport * vport)218504c68496SJames Smart lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
218604c68496SJames Smart {
218704c68496SJames Smart 	struct lpfc_mbx_init_vfi *init_vfi;
218804c68496SJames Smart 
218904c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
219076a95d75SJames Smart 	mbox->vport = vport;
219104c68496SJames Smart 	init_vfi = &mbox->u.mqe.un.init_vfi;
219204c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI);
219304c68496SJames Smart 	bf_set(lpfc_init_vfi_vr, init_vfi, 1);
219404c68496SJames Smart 	bf_set(lpfc_init_vfi_vt, init_vfi, 1);
219576a95d75SJames Smart 	bf_set(lpfc_init_vfi_vp, init_vfi, 1);
21966d368e53SJames Smart 	bf_set(lpfc_init_vfi_vfi, init_vfi,
21976d368e53SJames Smart 	       vport->phba->sli4_hba.vfi_ids[vport->vfi]);
21987851fe2cSJames Smart 	bf_set(lpfc_init_vfi_vpi, init_vfi,
21996d368e53SJames Smart 	       vport->phba->vpi_ids[vport->vpi]);
22006d368e53SJames Smart 	bf_set(lpfc_init_vfi_fcfi, init_vfi,
22016d368e53SJames Smart 	       vport->phba->fcf.fcfi);
220204c68496SJames Smart }
220304c68496SJames Smart 
220404c68496SJames Smart /**
220504c68496SJames Smart  * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
220604c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
220704c68496SJames Smart  * @vport: vport associated with the VF.
220804c68496SJames Smart  * @phys: BDE DMA bus address used to send the service parameters to the HBA.
220904c68496SJames Smart  *
221004c68496SJames Smart  * This routine initializes @mbox to all zeros and then fills in the mailbox
221104c68496SJames Smart  * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
221204c68496SJames Smart  * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
221304c68496SJames Smart  * fabrics identified by VFI in the context of an FCF.
221404c68496SJames Smart  **/
221504c68496SJames Smart void
lpfc_reg_vfi(struct lpfcMboxq * mbox,struct lpfc_vport * vport,dma_addr_t phys)221604c68496SJames Smart lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys)
221704c68496SJames Smart {
221804c68496SJames Smart 	struct lpfc_mbx_reg_vfi *reg_vfi;
2219ae05ebe3SJames Smart 	struct lpfc_hba *phba = vport->phba;
222044fd7fe3SJames Smart 	uint8_t bbscn_fabric = 0, bbscn_max = 0, bbscn_def = 0;
222104c68496SJames Smart 
222204c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
222304c68496SJames Smart 	reg_vfi = &mbox->u.mqe.un.reg_vfi;
222404c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI);
222504c68496SJames Smart 	bf_set(lpfc_reg_vfi_vp, reg_vfi, 1);
22266d368e53SJames Smart 	bf_set(lpfc_reg_vfi_vfi, reg_vfi,
2227ae05ebe3SJames Smart 	       phba->sli4_hba.vfi_ids[vport->vfi]);
2228ae05ebe3SJames Smart 	bf_set(lpfc_reg_vfi_fcfi, reg_vfi, phba->fcf.fcfi);
2229ae05ebe3SJames Smart 	bf_set(lpfc_reg_vfi_vpi, reg_vfi, phba->vpi_ids[vport->vpi]);
2230c868595dSJames Smart 	memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name));
2231c868595dSJames Smart 	reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]);
2232c868595dSJames Smart 	reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]);
2233ae05ebe3SJames Smart 	reg_vfi->e_d_tov = phba->fc_edtov;
2234ae05ebe3SJames Smart 	reg_vfi->r_a_tov = phba->fc_ratov;
2235ae09c765SJames Smart 	if (phys) {
223604c68496SJames Smart 		reg_vfi->bde.addrHigh = putPaddrHigh(phys);
223704c68496SJames Smart 		reg_vfi->bde.addrLow = putPaddrLow(phys);
223804c68496SJames Smart 		reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam);
223904c68496SJames Smart 		reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
2240ae09c765SJames Smart 	}
224104c68496SJames Smart 	bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID);
2242ae05ebe3SJames Smart 
2243ae05ebe3SJames Smart 	/* Only FC supports upd bit */
2244ae05ebe3SJames Smart 	if ((phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) &&
2245e74c03c8SJames Smart 	    (vport->fc_flag & FC_VFI_REGISTERED) &&
22462c3b2a8fSJames Smart 	    (!phba->fc_topology_changed))
2247ae05ebe3SJames Smart 		bf_set(lpfc_reg_vfi_upd, reg_vfi, 1);
224844fd7fe3SJames Smart 
224944fd7fe3SJames Smart 	bf_set(lpfc_reg_vfi_bbcr, reg_vfi, 0);
225044fd7fe3SJames Smart 	bf_set(lpfc_reg_vfi_bbscn, reg_vfi, 0);
225144fd7fe3SJames Smart 	bbscn_fabric = (phba->fc_fabparam.cmn.bbRcvSizeMsb >> 4) & 0xF;
225244fd7fe3SJames Smart 
225344fd7fe3SJames Smart 	if (phba->bbcredit_support && phba->cfg_enable_bbcr  &&
225444fd7fe3SJames Smart 	    bbscn_fabric != 0) {
225544fd7fe3SJames Smart 		bbscn_max = bf_get(lpfc_bbscn_max,
225644fd7fe3SJames Smart 				   &phba->sli4_hba.bbscn_params);
225744fd7fe3SJames Smart 		if (bbscn_fabric <= bbscn_max) {
225844fd7fe3SJames Smart 			bbscn_def = bf_get(lpfc_bbscn_def,
225944fd7fe3SJames Smart 					   &phba->sli4_hba.bbscn_params);
226044fd7fe3SJames Smart 
226144fd7fe3SJames Smart 			if (bbscn_fabric > bbscn_def)
226244fd7fe3SJames Smart 				bf_set(lpfc_reg_vfi_bbscn, reg_vfi,
226344fd7fe3SJames Smart 				       bbscn_fabric);
226444fd7fe3SJames Smart 			else
226544fd7fe3SJames Smart 				bf_set(lpfc_reg_vfi_bbscn, reg_vfi, bbscn_def);
226644fd7fe3SJames Smart 
226744fd7fe3SJames Smart 			bf_set(lpfc_reg_vfi_bbcr, reg_vfi, 1);
226844fd7fe3SJames Smart 		}
226944fd7fe3SJames Smart 	}
22701b51197dSJames Smart 	lpfc_printf_vlog(vport, KERN_INFO, LOG_MBOX,
22711b51197dSJames Smart 			"3134 Register VFI, mydid:x%x, fcfi:%d, "
2272e74c03c8SJames Smart 			" vfi:%d, vpi:%d, fc_pname:%x%x fc_flag:x%x"
227344fd7fe3SJames Smart 			" port_state:x%x topology chg:%d bbscn_fabric :%d\n",
22741b51197dSJames Smart 			vport->fc_myDID,
2275ae05ebe3SJames Smart 			phba->fcf.fcfi,
2276ae05ebe3SJames Smart 			phba->sli4_hba.vfi_ids[vport->vfi],
2277ae05ebe3SJames Smart 			phba->vpi_ids[vport->vpi],
2278e74c03c8SJames Smart 			reg_vfi->wwn[0], reg_vfi->wwn[1], vport->fc_flag,
227944fd7fe3SJames Smart 			vport->port_state, phba->fc_topology_changed,
228044fd7fe3SJames Smart 			bbscn_fabric);
228104c68496SJames Smart }
228204c68496SJames Smart 
228304c68496SJames Smart /**
228404c68496SJames Smart  * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
22851c6834a7SJames Smart  * @phba: pointer to the hba structure to init the VPI for.
228604c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
228704c68496SJames Smart  * @vpi: VPI to be initialized.
228804c68496SJames Smart  *
228904c68496SJames Smart  * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
229004c68496SJames Smart  * command to activate a virtual N_Port. The HBA assigns a MAC address to use
229104c68496SJames Smart  * with the virtual N Port.  The SLI Host issues this command before issuing a
229204c68496SJames Smart  * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
229304c68496SJames Smart  * successful virtual NPort login.
229404c68496SJames Smart  **/
229504c68496SJames Smart void
lpfc_init_vpi(struct lpfc_hba * phba,struct lpfcMboxq * mbox,uint16_t vpi)22961c6834a7SJames Smart lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi)
229704c68496SJames Smart {
229804c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
229904c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI);
23001c6834a7SJames Smart 	bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi,
23016d368e53SJames Smart 	       phba->vpi_ids[vpi]);
23021c6834a7SJames Smart 	bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi,
23036d368e53SJames Smart 	       phba->sli4_hba.vfi_ids[phba->pport->vfi]);
230404c68496SJames Smart }
230504c68496SJames Smart 
230604c68496SJames Smart /**
230704c68496SJames Smart  * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
230804c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
23096669f9bbSJames Smart  * @vport: vport associated with the VF.
231004c68496SJames Smart  *
231104c68496SJames Smart  * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
231204c68496SJames Smart  * (logical NPort) into the inactive state. The SLI Host must have logged out
231304c68496SJames Smart  * and unregistered all remote N_Ports to abort any activity on the virtual
231404c68496SJames Smart  * fabric. The SLI Port posts the mailbox response after marking the virtual
231504c68496SJames Smart  * fabric inactive.
231604c68496SJames Smart  **/
231704c68496SJames Smart void
lpfc_unreg_vfi(struct lpfcMboxq * mbox,struct lpfc_vport * vport)23186669f9bbSJames Smart lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
231904c68496SJames Smart {
232004c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
232104c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI);
23226669f9bbSJames Smart 	bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi,
23236d368e53SJames Smart 	       vport->phba->sli4_hba.vfi_ids[vport->vfi]);
232404c68496SJames Smart }
232504c68496SJames Smart 
232604c68496SJames Smart /**
2327026abb87SJames Smart  * lpfc_sli4_dump_cfg_rg23 - Dump sli4 port config region 23
232804c68496SJames Smart  * @phba: pointer to the hba structure containing.
232904c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
233004c68496SJames Smart  *
2331026abb87SJames Smart  * This function create a SLI4 dump mailbox command to dump configure
2332026abb87SJames Smart  * region 23.
233304c68496SJames Smart  **/
233404c68496SJames Smart int
lpfc_sli4_dump_cfg_rg23(struct lpfc_hba * phba,struct lpfcMboxq * mbox)2335026abb87SJames Smart lpfc_sli4_dump_cfg_rg23(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
233604c68496SJames Smart {
233704c68496SJames Smart 	struct lpfc_dmabuf *mp = NULL;
233804c68496SJames Smart 	MAILBOX_t *mb;
2339ef47575fSJames Smart 	int rc;
234004c68496SJames Smart 
234104c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
234204c68496SJames Smart 	mb = &mbox->u.mb;
234304c68496SJames Smart 
2344ef47575fSJames Smart 	rc = lpfc_mbox_rsrc_prep(phba, mbox);
2345ef47575fSJames Smart 	if (rc) {
234604c68496SJames Smart 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
2347ef47575fSJames Smart 				"2569 %s: memory allocation failed\n",
2348ef47575fSJames Smart 				__func__);
234904c68496SJames Smart 		return 1;
235004c68496SJames Smart 	}
235104c68496SJames Smart 
235204c68496SJames Smart 	mb->mbxCommand = MBX_DUMP_MEMORY;
235304c68496SJames Smart 	mb->un.varDmp.type = DMP_NV_PARAMS;
2354a0c87cbdSJames Smart 	mb->un.varDmp.region_id = DMP_REGION_23;
2355a0c87cbdSJames Smart 	mb->un.varDmp.sli4_length = DMP_RGN23_SIZE;
2356ef47575fSJames Smart 	mp = mbox->ctx_buf;
235704c68496SJames Smart 	mb->un.varWords[3] = putPaddrLow(mp->phys);
235804c68496SJames Smart 	mb->un.varWords[4] = putPaddrHigh(mp->phys);
235904c68496SJames Smart 	return 0;
236004c68496SJames Smart }
236104c68496SJames Smart 
2362bd4b3e5cSBaoyou Xie static void
lpfc_mbx_cmpl_rdp_link_stat(struct lpfc_hba * phba,LPFC_MBOXQ_t * mboxq)236386478875SJames Smart lpfc_mbx_cmpl_rdp_link_stat(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
236486478875SJames Smart {
236586478875SJames Smart 	MAILBOX_t *mb;
236686478875SJames Smart 	int rc = FAILURE;
236786478875SJames Smart 	struct lpfc_rdp_context *rdp_context =
23683e1f0718SJames Smart 			(struct lpfc_rdp_context *)(mboxq->ctx_ndlp);
236986478875SJames Smart 
237086478875SJames Smart 	mb = &mboxq->u.mb;
237186478875SJames Smart 	if (mb->mbxStatus)
237286478875SJames Smart 		goto mbx_failed;
237386478875SJames Smart 
237486478875SJames Smart 	memcpy(&rdp_context->link_stat, &mb->un.varRdLnk, sizeof(READ_LNK_VAR));
237586478875SJames Smart 
237686478875SJames Smart 	rc = SUCCESS;
237786478875SJames Smart 
237886478875SJames Smart mbx_failed:
2379ef47575fSJames Smart 	lpfc_mbox_rsrc_cleanup(phba, mboxq, MBOX_THD_UNLOCKED);
238086478875SJames Smart 	rdp_context->cmpl(phba, rdp_context, rc);
238186478875SJames Smart }
238286478875SJames Smart 
2383bd4b3e5cSBaoyou Xie static void
lpfc_mbx_cmpl_rdp_page_a2(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbox)238486478875SJames Smart lpfc_mbx_cmpl_rdp_page_a2(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
238586478875SJames Smart {
23863e1f0718SJames Smart 	struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
238786478875SJames Smart 	struct lpfc_rdp_context *rdp_context =
23883e1f0718SJames Smart 			(struct lpfc_rdp_context *)(mbox->ctx_ndlp);
238986478875SJames Smart 
239086478875SJames Smart 	if (bf_get(lpfc_mqe_status, &mbox->u.mqe))
2391ef47575fSJames Smart 		goto error_mbox_free;
239286478875SJames Smart 
239386478875SJames Smart 	lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a2,
239486478875SJames Smart 				DMP_SFF_PAGE_A2_SIZE);
239586478875SJames Smart 
239686478875SJames Smart 	lpfc_read_lnk_stat(phba, mbox);
239786478875SJames Smart 	mbox->vport = rdp_context->ndlp->vport;
2398ef47575fSJames Smart 
2399ef47575fSJames Smart 	/* Save the dma buffer for cleanup in the final completion. */
2400ef47575fSJames Smart 	mbox->ctx_buf = mp;
240186478875SJames Smart 	mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_link_stat;
24023e1f0718SJames Smart 	mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
240386478875SJames Smart 	if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == MBX_NOT_FINISHED)
2404ef47575fSJames Smart 		goto error_mbox_free;
240586478875SJames Smart 
240686478875SJames Smart 	return;
240786478875SJames Smart 
2408ef47575fSJames Smart error_mbox_free:
2409ef47575fSJames Smart 	lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
241086478875SJames Smart 	rdp_context->cmpl(phba, rdp_context, FAILURE);
241186478875SJames Smart }
241286478875SJames Smart 
241386478875SJames Smart void
lpfc_mbx_cmpl_rdp_page_a0(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbox)241486478875SJames Smart lpfc_mbx_cmpl_rdp_page_a0(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
241586478875SJames Smart {
241686478875SJames Smart 	int rc;
24173e1f0718SJames Smart 	struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(mbox->ctx_buf);
241886478875SJames Smart 	struct lpfc_rdp_context *rdp_context =
24193e1f0718SJames Smart 			(struct lpfc_rdp_context *)(mbox->ctx_ndlp);
242086478875SJames Smart 
242186478875SJames Smart 	if (bf_get(lpfc_mqe_status, &mbox->u.mqe))
242286478875SJames Smart 		goto error;
242386478875SJames Smart 
242486478875SJames Smart 	lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a0,
242586478875SJames Smart 				DMP_SFF_PAGE_A0_SIZE);
242686478875SJames Smart 
242786478875SJames Smart 	memset(mbox, 0, sizeof(*mbox));
242886478875SJames Smart 
242986478875SJames Smart 	memset(mp->virt, 0, DMP_SFF_PAGE_A2_SIZE);
243086478875SJames Smart 	INIT_LIST_HEAD(&mp->list);
243186478875SJames Smart 
243286478875SJames Smart 	/* save address for completion */
24333e1f0718SJames Smart 	mbox->ctx_buf = mp;
243486478875SJames Smart 	mbox->vport = rdp_context->ndlp->vport;
243586478875SJames Smart 
243686478875SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY);
243786478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_type,
243886478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, DMP_LMSD);
243986478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_link,
244086478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port);
244186478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_page_no,
244286478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A2);
244386478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_length,
244486478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A2_SIZE);
244586478875SJames Smart 	mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
244686478875SJames Smart 	mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
244786478875SJames Smart 
244886478875SJames Smart 	mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a2;
24493e1f0718SJames Smart 	mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
245086478875SJames Smart 	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
245186478875SJames Smart 	if (rc == MBX_NOT_FINISHED)
245286478875SJames Smart 		goto error;
245386478875SJames Smart 
245486478875SJames Smart 	return;
245586478875SJames Smart 
245686478875SJames Smart error:
2457ef47575fSJames Smart 	lpfc_mbox_rsrc_cleanup(phba, mbox, MBOX_THD_UNLOCKED);
245886478875SJames Smart 	rdp_context->cmpl(phba, rdp_context, FAILURE);
245986478875SJames Smart }
246086478875SJames Smart 
246186478875SJames Smart 
246286478875SJames Smart /*
24630196e379SEric Curtin  * lpfc_sli4_dump_page_a0 - Dump sli4 read SFP Diagnostic.
246486478875SJames Smart  * @phba: pointer to the hba structure containing.
246586478875SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
246686478875SJames Smart  *
246786478875SJames Smart  * This function create a SLI4 dump mailbox command to dump configure
246886478875SJames Smart  * type 3 page 0xA0.
246986478875SJames Smart  */
247086478875SJames Smart int
lpfc_sli4_dump_page_a0(struct lpfc_hba * phba,struct lpfcMboxq * mbox)247186478875SJames Smart lpfc_sli4_dump_page_a0(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
247286478875SJames Smart {
2473ef47575fSJames Smart 	int rc;
247486478875SJames Smart 	struct lpfc_dmabuf *mp = NULL;
247586478875SJames Smart 
247686478875SJames Smart 	memset(mbox, 0, sizeof(*mbox));
247786478875SJames Smart 
2478ef47575fSJames Smart 	rc = lpfc_mbox_rsrc_prep(phba, mbox);
2479ef47575fSJames Smart 	if (rc) {
248086478875SJames Smart 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
248186478875SJames Smart 			"3569 dump type 3 page 0xA0 allocation failed\n");
248286478875SJames Smart 		return 1;
248386478875SJames Smart 	}
248486478875SJames Smart 
248586478875SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY);
248686478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_type,
248786478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, DMP_LMSD);
248886478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_link,
248986478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port);
249086478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_page_no,
249186478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A0);
249286478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_length,
249386478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A0_SIZE);
2494ef47575fSJames Smart 
2495ef47575fSJames Smart 	mp = mbox->ctx_buf;
249686478875SJames Smart 	mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
249786478875SJames Smart 	mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
249886478875SJames Smart 
249986478875SJames Smart 	return 0;
250086478875SJames Smart }
250186478875SJames Smart 
250204c68496SJames Smart /**
250304c68496SJames Smart  * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
250404c68496SJames Smart  * @phba: pointer to the hba structure containing the FCF index and RQ ID.
250504c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
250604c68496SJames Smart  *
250704c68496SJames Smart  * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
250804c68496SJames Smart  * SLI Host uses the command to activate an FCF after it has acquired FCF
250904c68496SJames Smart  * information via a READ_FCF mailbox command. This mailbox command also is used
251004c68496SJames Smart  * to indicate where received unsolicited frames from this FCF will be sent. By
251104c68496SJames Smart  * default this routine will set up the FCF to forward all unsolicited frames
2512*442336a5SBo Liu  * to the RQ ID passed in the @phba. This can be overridden by the caller for
251304c68496SJames Smart  * more complicated setups.
251404c68496SJames Smart  **/
251504c68496SJames Smart void
lpfc_reg_fcfi(struct lpfc_hba * phba,struct lpfcMboxq * mbox)251604c68496SJames Smart lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
251704c68496SJames Smart {
251804c68496SJames Smart 	struct lpfc_mbx_reg_fcfi *reg_fcfi;
251904c68496SJames Smart 
252004c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
252104c68496SJames Smart 	reg_fcfi = &mbox->u.mqe.un.reg_fcfi;
252204c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI);
2523895427bdSJames Smart 	if (phba->nvmet_support == 0) {
2524895427bdSJames Smart 		bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi,
2525895427bdSJames Smart 		       phba->sli4_hba.hdr_rq->queue_id);
2526895427bdSJames Smart 		/* Match everything - rq_id0 */
2527895427bdSJames Smart 		bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, 0);
2528895427bdSJames Smart 		bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0);
2529895427bdSJames Smart 		bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi, 0);
2530895427bdSJames Smart 		bf_set(lpfc_reg_fcfi_rctl_mask0, reg_fcfi, 0);
2531895427bdSJames Smart 
253204c68496SJames Smart 		bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
2533895427bdSJames Smart 
2534895427bdSJames Smart 		/* addr mode is bit wise inverted value of fcf addr_mode */
2535895427bdSJames Smart 		bf_set(lpfc_reg_fcfi_mam, reg_fcfi,
2536895427bdSJames Smart 		       (~phba->fcf.addr_mode) & 0x3);
25372d7dbc4cSJames Smart 	} else {
25382d7dbc4cSJames Smart 		/* This is ONLY for NVMET MRQ == 1 */
25392d7dbc4cSJames Smart 		if (phba->cfg_nvmet_mrq != 1)
25402d7dbc4cSJames Smart 			return;
25412d7dbc4cSJames Smart 
25422d7dbc4cSJames Smart 		bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi,
25432d7dbc4cSJames Smart 		       phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id);
25442d7dbc4cSJames Smart 		/* Match type FCP - rq_id0 */
25452d7dbc4cSJames Smart 		bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, FC_TYPE_FCP);
25462d7dbc4cSJames Smart 		bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0xff);
25472d7dbc4cSJames Smart 		bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi,
25482d7dbc4cSJames Smart 		       FC_RCTL_DD_UNSOL_CMD);
25492d7dbc4cSJames Smart 
25502d7dbc4cSJames Smart 		bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi,
25512d7dbc4cSJames Smart 		       phba->sli4_hba.hdr_rq->queue_id);
25522d7dbc4cSJames Smart 		/* Match everything else - rq_id1 */
25532d7dbc4cSJames Smart 		bf_set(lpfc_reg_fcfi_type_match1, reg_fcfi, 0);
25542d7dbc4cSJames Smart 		bf_set(lpfc_reg_fcfi_type_mask1, reg_fcfi, 0);
25552d7dbc4cSJames Smart 		bf_set(lpfc_reg_fcfi_rctl_match1, reg_fcfi, 0);
25562d7dbc4cSJames Smart 		bf_set(lpfc_reg_fcfi_rctl_mask1, reg_fcfi, 0);
2557895427bdSJames Smart 	}
255804c68496SJames Smart 	bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
255904c68496SJames Smart 	bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
2560ecfd03c6SJames Smart 	bf_set(lpfc_reg_fcfi_info_index, reg_fcfi,
2561ecfd03c6SJames Smart 	       phba->fcf.current_rec.fcf_indx);
25623804dc84SJames Smart 	if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) {
256304c68496SJames Smart 		bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
2564ecfd03c6SJames Smart 		bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi,
2565ecfd03c6SJames Smart 		       phba->fcf.current_rec.vlan_id);
256604c68496SJames Smart 	}
256704c68496SJames Smart }
256804c68496SJames Smart 
256904c68496SJames Smart /**
25702d7dbc4cSJames Smart  * lpfc_reg_fcfi_mrq - Initialize the REG_FCFI_MRQ mailbox command
25712d7dbc4cSJames Smart  * @phba: pointer to the hba structure containing the FCF index and RQ ID.
25722d7dbc4cSJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
25732d7dbc4cSJames Smart  * @mode: 0 to register FCFI, 1 to register MRQs
25742d7dbc4cSJames Smart  *
25752d7dbc4cSJames Smart  * The REG_FCFI_MRQ mailbox command supports Fibre Channel Forwarders (FCFs).
25762d7dbc4cSJames Smart  * The SLI Host uses the command to activate an FCF after it has acquired FCF
25772d7dbc4cSJames Smart  * information via a READ_FCF mailbox command. This mailbox command also is used
25782d7dbc4cSJames Smart  * to indicate where received unsolicited frames from this FCF will be sent. By
25792d7dbc4cSJames Smart  * default this routine will set up the FCF to forward all unsolicited frames
2580*442336a5SBo Liu  * to the RQ ID passed in the @phba. This can be overridden by the caller for
25812d7dbc4cSJames Smart  * more complicated setups.
25822d7dbc4cSJames Smart  **/
25832d7dbc4cSJames Smart void
lpfc_reg_fcfi_mrq(struct lpfc_hba * phba,struct lpfcMboxq * mbox,int mode)25842d7dbc4cSJames Smart lpfc_reg_fcfi_mrq(struct lpfc_hba *phba, struct lpfcMboxq *mbox, int mode)
25852d7dbc4cSJames Smart {
25862d7dbc4cSJames Smart 	struct lpfc_mbx_reg_fcfi_mrq *reg_fcfi;
25872d7dbc4cSJames Smart 
25882d7dbc4cSJames Smart 	/* This is ONLY for MRQ */
25892d7dbc4cSJames Smart 	if (phba->cfg_nvmet_mrq <= 1)
25902d7dbc4cSJames Smart 		return;
25912d7dbc4cSJames Smart 
25922d7dbc4cSJames Smart 	memset(mbox, 0, sizeof(*mbox));
25932d7dbc4cSJames Smart 	reg_fcfi = &mbox->u.mqe.un.reg_fcfi_mrq;
25942d7dbc4cSJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI_MRQ);
25952d7dbc4cSJames Smart 	if (mode == 0) {
25962d7dbc4cSJames Smart 		bf_set(lpfc_reg_fcfi_mrq_info_index, reg_fcfi,
25972d7dbc4cSJames Smart 		       phba->fcf.current_rec.fcf_indx);
25982d7dbc4cSJames Smart 		if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) {
25992d7dbc4cSJames Smart 			bf_set(lpfc_reg_fcfi_mrq_vv, reg_fcfi, 1);
26002d7dbc4cSJames Smart 			bf_set(lpfc_reg_fcfi_mrq_vlan_tag, reg_fcfi,
26012d7dbc4cSJames Smart 			       phba->fcf.current_rec.vlan_id);
26022d7dbc4cSJames Smart 		}
26032d7dbc4cSJames Smart 		return;
26042d7dbc4cSJames Smart 	}
26052d7dbc4cSJames Smart 
26062d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_rq_id0, reg_fcfi,
26072d7dbc4cSJames Smart 	       phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id);
26082d7dbc4cSJames Smart 	/* Match NVME frames of type FCP (protocol NVME) - rq_id0 */
26092d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_type_match0, reg_fcfi, FC_TYPE_FCP);
26102d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_type_mask0, reg_fcfi, 0xff);
26112d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_rctl_match0, reg_fcfi, FC_RCTL_DD_UNSOL_CMD);
26122d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_rctl_mask0, reg_fcfi, 0xff);
26132d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_ptc0, reg_fcfi, 1);
26142d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_pt0, reg_fcfi, 1);
26152d7dbc4cSJames Smart 
26162d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_policy, reg_fcfi, 3); /* NVME connection id */
26172d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_mode, reg_fcfi, 1);
26182d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_filter, reg_fcfi, 1); /* rq_id0 */
26192d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_npairs, reg_fcfi, phba->cfg_nvmet_mrq);
26202d7dbc4cSJames Smart 
26212d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_rq_id1, reg_fcfi,
26222d7dbc4cSJames Smart 	       phba->sli4_hba.hdr_rq->queue_id);
26232d7dbc4cSJames Smart 	/* Match everything - rq_id1 */
26242d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_type_match1, reg_fcfi, 0);
26252d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_type_mask1, reg_fcfi, 0);
26262d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_rctl_match1, reg_fcfi, 0);
26272d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_rctl_mask1, reg_fcfi, 0);
26282d7dbc4cSJames Smart 
26292d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
26302d7dbc4cSJames Smart 	bf_set(lpfc_reg_fcfi_mrq_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
26312d7dbc4cSJames Smart }
26322d7dbc4cSJames Smart 
26332d7dbc4cSJames Smart /**
263404c68496SJames Smart  * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
263504c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
263604c68496SJames Smart  * @fcfi: FCFI to be unregistered.
263704c68496SJames Smart  *
263804c68496SJames Smart  * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
263904c68496SJames Smart  * The SLI Host uses the command to inactivate an FCFI.
264004c68496SJames Smart  **/
264104c68496SJames Smart void
lpfc_unreg_fcfi(struct lpfcMboxq * mbox,uint16_t fcfi)264204c68496SJames Smart lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi)
264304c68496SJames Smart {
264404c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
264504c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI);
264604c68496SJames Smart 	bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi);
264704c68496SJames Smart }
264804c68496SJames Smart 
264904c68496SJames Smart /**
265004c68496SJames Smart  * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
265104c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
265204c68496SJames Smart  * @ndlp: The nodelist structure that describes the RPI to resume.
265304c68496SJames Smart  *
265404c68496SJames Smart  * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
265504c68496SJames Smart  * link event.
265604c68496SJames Smart  **/
265704c68496SJames Smart void
lpfc_resume_rpi(struct lpfcMboxq * mbox,struct lpfc_nodelist * ndlp)265804c68496SJames Smart lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
265904c68496SJames Smart {
26606d368e53SJames Smart 	struct lpfc_hba *phba = ndlp->phba;
266104c68496SJames Smart 	struct lpfc_mbx_resume_rpi *resume_rpi;
266204c68496SJames Smart 
266304c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
266404c68496SJames Smart 	resume_rpi = &mbox->u.mqe.un.resume_rpi;
266504c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI);
26666d368e53SJames Smart 	bf_set(lpfc_resume_rpi_index, resume_rpi,
26676d368e53SJames Smart 	       phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
26688fa38513SJames Smart 	bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI);
26698fa38513SJames Smart 	resume_rpi->event_tag = ndlp->phba->fc_eventTag;
267004c68496SJames Smart }
267128baac74SJames Smart 
2672