xref: /openbmc/linux/drivers/scsi/lpfc/lpfc_mbox.c (revision d38dd52c)
1dea3101eS /*******************************************************************
2dea3101eS  * This file is part of the Emulex Linux Device Driver for         *
3c44ce173SJames.Smart@Emulex.Com  * Fibre Channel Host Bus Adapters.                                *
4f25e8e79SJames Smart  * Copyright (C) 2004-2015 Emulex.  All rights reserved.           *
5c44ce173SJames.Smart@Emulex.Com  * EMULEX and SLI are trademarks of Emulex.                        *
6dea3101eS  * www.emulex.com                                                  *
7c44ce173SJames.Smart@Emulex.Com  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
8dea3101eS  *                                                                 *
9dea3101eS  * This program is free software; you can redistribute it and/or   *
10c44ce173SJames.Smart@Emulex.Com  * modify it under the terms of version 2 of the GNU General       *
11c44ce173SJames.Smart@Emulex.Com  * Public License as published by the Free Software Foundation.    *
12c44ce173SJames.Smart@Emulex.Com  * This program is distributed in the hope that it will be useful. *
13c44ce173SJames.Smart@Emulex.Com  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
14c44ce173SJames.Smart@Emulex.Com  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
15c44ce173SJames.Smart@Emulex.Com  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
16c44ce173SJames.Smart@Emulex.Com  * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17c44ce173SJames.Smart@Emulex.Com  * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
18c44ce173SJames.Smart@Emulex.Com  * more details, a copy of which can be found in the file COPYING  *
19c44ce173SJames.Smart@Emulex.Com  * included with this package.                                     *
20dea3101eS  *******************************************************************/
21dea3101eS 
22dea3101eS #include <linux/blkdev.h>
23dea3101eS #include <linux/pci.h>
245a0e3ad6STejun Heo #include <linux/slab.h>
25dea3101eS #include <linux/interrupt.h>
26dea3101eS 
27f888ba3cSJames.Smart@Emulex.Com #include <scsi/scsi_device.h>
28f888ba3cSJames.Smart@Emulex.Com #include <scsi/scsi_transport_fc.h>
2991886523SJames.Smart@Emulex.Com #include <scsi/scsi.h>
306a9c52cfSJames Smart #include <scsi/fc/fc_fs.h>
3191886523SJames.Smart@Emulex.Com 
32da0436e9SJames Smart #include "lpfc_hw4.h"
33dea3101eS #include "lpfc_hw.h"
34dea3101eS #include "lpfc_sli.h"
35da0436e9SJames Smart #include "lpfc_sli4.h"
36ea2151b4SJames Smart #include "lpfc_nl.h"
37dea3101eS #include "lpfc_disc.h"
38dea3101eS #include "lpfc_scsi.h"
39dea3101eS #include "lpfc.h"
40dea3101eS #include "lpfc_logmsg.h"
41dea3101eS #include "lpfc_crtn.h"
42dea3101eS #include "lpfc_compat.h"
43dea3101eS 
44e59058c4SJames Smart /**
4521e9a0a5SJames Smart  * lpfc_dump_static_vport - Dump HBA's static vport information.
4621e9a0a5SJames Smart  * @phba: pointer to lpfc hba data structure.
4721e9a0a5SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
4821e9a0a5SJames Smart  * @offset: offset for dumping vport info.
4921e9a0a5SJames Smart  *
5021e9a0a5SJames Smart  * The dump mailbox command provides a method for the device driver to obtain
5121e9a0a5SJames Smart  * various types of information from the HBA device.
5221e9a0a5SJames Smart  *
5321e9a0a5SJames Smart  * This routine prepares the mailbox command for dumping list of static
5421e9a0a5SJames Smart  * vports to be created.
5521e9a0a5SJames Smart  **/
561c6834a7SJames Smart int
5721e9a0a5SJames Smart lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
5821e9a0a5SJames Smart 		uint16_t offset)
5921e9a0a5SJames Smart {
6021e9a0a5SJames Smart 	MAILBOX_t *mb;
611c6834a7SJames Smart 	struct lpfc_dmabuf *mp;
6221e9a0a5SJames Smart 
6321e9a0a5SJames Smart 	mb = &pmb->u.mb;
6421e9a0a5SJames Smart 
6521e9a0a5SJames Smart 	/* Setup to dump vport info region */
6621e9a0a5SJames Smart 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
6721e9a0a5SJames Smart 	mb->mbxCommand = MBX_DUMP_MEMORY;
6821e9a0a5SJames Smart 	mb->un.varDmp.type = DMP_NV_PARAMS;
6921e9a0a5SJames Smart 	mb->un.varDmp.entry_index = offset;
7021e9a0a5SJames Smart 	mb->un.varDmp.region_id = DMP_REGION_VPORT;
7121e9a0a5SJames Smart 	mb->mbxOwner = OWN_HOST;
7221e9a0a5SJames Smart 
731c6834a7SJames Smart 	/* For SLI3 HBAs data is embedded in mailbox */
741c6834a7SJames Smart 	if (phba->sli_rev != LPFC_SLI_REV4) {
751c6834a7SJames Smart 		mb->un.varDmp.cv = 1;
761c6834a7SJames Smart 		mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t);
771c6834a7SJames Smart 		return 0;
781c6834a7SJames Smart 	}
791c6834a7SJames Smart 
801c6834a7SJames Smart 	/* For SLI4 HBAs driver need to allocate memory */
811c6834a7SJames Smart 	mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
821c6834a7SJames Smart 	if (mp)
831c6834a7SJames Smart 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
841c6834a7SJames Smart 
851c6834a7SJames Smart 	if (!mp || !mp->virt) {
861c6834a7SJames Smart 		kfree(mp);
871c6834a7SJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
881c6834a7SJames Smart 			"2605 lpfc_dump_static_vport: memory"
891c6834a7SJames Smart 			" allocation failed\n");
901c6834a7SJames Smart 		return 1;
911c6834a7SJames Smart 	}
921c6834a7SJames Smart 	memset(mp->virt, 0, LPFC_BPL_SIZE);
931c6834a7SJames Smart 	INIT_LIST_HEAD(&mp->list);
941c6834a7SJames Smart 	/* save address for completion */
95cdcc2343SJames Smart 	pmb->context1 = (uint8_t *)mp;
961c6834a7SJames Smart 	mb->un.varWords[3] = putPaddrLow(mp->phys);
971c6834a7SJames Smart 	mb->un.varWords[4] = putPaddrHigh(mp->phys);
981c6834a7SJames Smart 	mb->un.varDmp.sli4_length = sizeof(struct static_vport_info);
991c6834a7SJames Smart 
1001c6834a7SJames Smart 	return 0;
10121e9a0a5SJames Smart }
10221e9a0a5SJames Smart 
10321e9a0a5SJames Smart /**
104a0c87cbdSJames Smart  * lpfc_down_link - Bring down HBAs link.
105e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
106e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
107a0c87cbdSJames Smart  *
108a0c87cbdSJames Smart  * This routine prepares a mailbox command to bring down HBA link.
109a0c87cbdSJames Smart  **/
110a0c87cbdSJames Smart void
111a0c87cbdSJames Smart lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
112a0c87cbdSJames Smart {
113a0c87cbdSJames Smart 	MAILBOX_t *mb;
114a0c87cbdSJames Smart 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
115a0c87cbdSJames Smart 	mb = &pmb->u.mb;
116a0c87cbdSJames Smart 	mb->mbxCommand = MBX_DOWN_LINK;
117a0c87cbdSJames Smart 	mb->mbxOwner = OWN_HOST;
118a0c87cbdSJames Smart }
119a0c87cbdSJames Smart 
120a0c87cbdSJames Smart /**
121a0c87cbdSJames Smart  * lpfc_dump_mem - Prepare a mailbox command for reading a region.
122a0c87cbdSJames Smart  * @phba: pointer to lpfc hba data structure.
123a0c87cbdSJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
124a0c87cbdSJames Smart  * @offset: offset into the region.
125a0c87cbdSJames Smart  * @region_id: config region id.
126e59058c4SJames Smart  *
127e59058c4SJames Smart  * The dump mailbox command provides a method for the device driver to obtain
128e59058c4SJames Smart  * various types of information from the HBA device.
129e59058c4SJames Smart  *
130a0c87cbdSJames Smart  * This routine prepares the mailbox command for dumping HBA's config region.
131e59058c4SJames Smart  **/
132dea3101eS void
133a0c87cbdSJames Smart lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset,
134a0c87cbdSJames Smart 		uint16_t region_id)
135dea3101eS {
136dea3101eS 	MAILBOX_t *mb;
137dea3101eS 	void *ctx;
138dea3101eS 
13904c68496SJames Smart 	mb = &pmb->u.mb;
140dea3101eS 	ctx = pmb->context2;
141dea3101eS 
142dea3101eS 	/* Setup to dump VPD region */
143dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
144dea3101eS 	mb->mbxCommand = MBX_DUMP_MEMORY;
145dea3101eS 	mb->un.varDmp.cv = 1;
146dea3101eS 	mb->un.varDmp.type = DMP_NV_PARAMS;
147dea3101eS 	mb->un.varDmp.entry_index = offset;
148a0c87cbdSJames Smart 	mb->un.varDmp.region_id = region_id;
149dea3101eS 	mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
150dea3101eS 	mb->un.varDmp.co = 0;
151dea3101eS 	mb->un.varDmp.resp_offset = 0;
152dea3101eS 	pmb->context2 = ctx;
153dea3101eS 	mb->mbxOwner = OWN_HOST;
154dea3101eS 	return;
155dea3101eS }
156dea3101eS 
157e59058c4SJames Smart /**
1583621a710SJames Smart  * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
15997207482SJames Smart  * @phba: pointer to lpfc hba data structure.
16097207482SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1613621a710SJames Smart  *
16297207482SJames Smart  * This function create a dump memory mailbox command to dump wake up
16397207482SJames Smart  * parameters.
16497207482SJames Smart  */
16597207482SJames Smart void
16697207482SJames Smart lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
16797207482SJames Smart {
16897207482SJames Smart 	MAILBOX_t *mb;
16997207482SJames Smart 	void *ctx;
17097207482SJames Smart 
17104c68496SJames Smart 	mb = &pmb->u.mb;
17297207482SJames Smart 	/* Save context so that we can restore after memset */
17397207482SJames Smart 	ctx = pmb->context2;
17497207482SJames Smart 
17597207482SJames Smart 	/* Setup to dump VPD region */
17697207482SJames Smart 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
17797207482SJames Smart 	mb->mbxCommand = MBX_DUMP_MEMORY;
17897207482SJames Smart 	mb->mbxOwner = OWN_HOST;
17997207482SJames Smart 	mb->un.varDmp.cv = 1;
18097207482SJames Smart 	mb->un.varDmp.type = DMP_NV_PARAMS;
1811d1c296fSJames Smart 	if (phba->sli_rev < LPFC_SLI_REV4)
18297207482SJames Smart 		mb->un.varDmp.entry_index = 0;
18397207482SJames Smart 	mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
18497207482SJames Smart 	mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
18597207482SJames Smart 	mb->un.varDmp.co = 0;
18697207482SJames Smart 	mb->un.varDmp.resp_offset = 0;
18797207482SJames Smart 	pmb->context2 = ctx;
18897207482SJames Smart 	return;
18997207482SJames Smart }
19097207482SJames Smart 
19197207482SJames Smart /**
1923621a710SJames Smart  * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
193e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
194e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
195e59058c4SJames Smart  *
196e59058c4SJames Smart  * The read NVRAM mailbox command returns the HBA's non-volatile parameters
197e59058c4SJames Smart  * that are used as defaults when the Fibre Channel link is brought on-line.
198e59058c4SJames Smart  *
199e59058c4SJames Smart  * This routine prepares the mailbox command for reading information stored
200e59058c4SJames Smart  * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
201e59058c4SJames Smart  **/
202dea3101eS void
203dea3101eS lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
204dea3101eS {
205dea3101eS 	MAILBOX_t *mb;
206dea3101eS 
20704c68496SJames Smart 	mb = &pmb->u.mb;
208dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
209dea3101eS 	mb->mbxCommand = MBX_READ_NV;
210dea3101eS 	mb->mbxOwner = OWN_HOST;
211dea3101eS 	return;
212dea3101eS }
213dea3101eS 
214e59058c4SJames Smart /**
2153621a710SJames Smart  * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
216e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
217e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
218e59058c4SJames Smart  * @ring: ring number for the asynchronous event to be configured.
219e59058c4SJames Smart  *
220e59058c4SJames Smart  * The asynchronous event enable mailbox command is used to enable the
221e59058c4SJames Smart  * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
222e59058c4SJames Smart  * specifies the default ring to which events are posted.
223e59058c4SJames Smart  *
224e59058c4SJames Smart  * This routine prepares the mailbox command for enabling HBA asynchronous
225e59058c4SJames Smart  * event support on a IOCB ring.
226e59058c4SJames Smart  **/
22757127f15SJames Smart void
22857127f15SJames Smart lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
22957127f15SJames Smart 		uint32_t ring)
23057127f15SJames Smart {
23157127f15SJames Smart 	MAILBOX_t *mb;
23257127f15SJames Smart 
23304c68496SJames Smart 	mb = &pmb->u.mb;
23457127f15SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
23557127f15SJames Smart 	mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
23657127f15SJames Smart 	mb->un.varCfgAsyncEvent.ring = ring;
23757127f15SJames Smart 	mb->mbxOwner = OWN_HOST;
23857127f15SJames Smart 	return;
23957127f15SJames Smart }
24057127f15SJames Smart 
241e59058c4SJames Smart /**
2423621a710SJames Smart  * lpfc_heart_beat - Prepare a mailbox command for heart beat
243e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
244e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
245e59058c4SJames Smart  *
246e59058c4SJames Smart  * The heart beat mailbox command is used to detect an unresponsive HBA, which
247e59058c4SJames Smart  * is defined as any device where no error attention is sent and both mailbox
248e59058c4SJames Smart  * and rings are not processed.
249e59058c4SJames Smart  *
250e59058c4SJames Smart  * This routine prepares the mailbox command for issuing a heart beat in the
251e59058c4SJames Smart  * form of mailbox command to the HBA. The timely completion of the heart
252e59058c4SJames Smart  * beat mailbox command indicates the health of the HBA.
253e59058c4SJames Smart  **/
254858c9f6cSJames Smart void
255858c9f6cSJames Smart lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
256858c9f6cSJames Smart {
257858c9f6cSJames Smart 	MAILBOX_t *mb;
258858c9f6cSJames Smart 
25904c68496SJames Smart 	mb = &pmb->u.mb;
260858c9f6cSJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
261858c9f6cSJames Smart 	mb->mbxCommand = MBX_HEARTBEAT;
262858c9f6cSJames Smart 	mb->mbxOwner = OWN_HOST;
263858c9f6cSJames Smart 	return;
264858c9f6cSJames Smart }
265858c9f6cSJames Smart 
266e59058c4SJames Smart /**
26776a95d75SJames Smart  * lpfc_read_topology - Prepare a mailbox command for reading HBA topology
268e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
269e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
270e59058c4SJames Smart  * @mp: DMA buffer memory for reading the link attention information into.
271e59058c4SJames Smart  *
27276a95d75SJames Smart  * The read topology mailbox command is issued to read the link topology
27376a95d75SJames Smart  * information indicated by the HBA port when the Link Event bit of the Host
27476a95d75SJames Smart  * Attention (HSTATT) register is set to 1 (For SLI-3) or when an FC Link
27576a95d75SJames Smart  * Attention ACQE is received from the port (For SLI-4). A Link Event
276e59058c4SJames Smart  * Attention occurs based on an exception detected at the Fibre Channel link
277e59058c4SJames Smart  * interface.
278e59058c4SJames Smart  *
27976a95d75SJames Smart  * This routine prepares the mailbox command for reading HBA link topology
280e59058c4SJames Smart  * information. A DMA memory has been set aside and address passed to the
281e59058c4SJames Smart  * HBA through @mp for the HBA to DMA link attention information into the
282e59058c4SJames Smart  * memory as part of the execution of the mailbox command.
283e59058c4SJames Smart  *
284e59058c4SJames Smart  * Return codes
285e59058c4SJames Smart  *    0 - Success (currently always return 0)
286e59058c4SJames Smart  **/
287dea3101eS int
28876a95d75SJames Smart lpfc_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
28976a95d75SJames Smart 		   struct lpfc_dmabuf *mp)
290dea3101eS {
291dea3101eS 	MAILBOX_t *mb;
292dea3101eS 
29304c68496SJames Smart 	mb = &pmb->u.mb;
294dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
295dea3101eS 
296dea3101eS 	INIT_LIST_HEAD(&mp->list);
29776a95d75SJames Smart 	mb->mbxCommand = MBX_READ_TOPOLOGY;
29876a95d75SJames Smart 	mb->un.varReadTop.lilpBde64.tus.f.bdeSize = LPFC_ALPA_MAP_SIZE;
29976a95d75SJames Smart 	mb->un.varReadTop.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
30076a95d75SJames Smart 	mb->un.varReadTop.lilpBde64.addrLow = putPaddrLow(mp->phys);
301dea3101eS 
302dea3101eS 	/* Save address for later completion and set the owner to host so that
303dea3101eS 	 * the FW knows this mailbox is available for processing.
304dea3101eS 	 */
305dea3101eS 	pmb->context1 = (uint8_t *)mp;
306dea3101eS 	mb->mbxOwner = OWN_HOST;
30792d7f7b0SJames Smart 	return (0);
308dea3101eS }
309dea3101eS 
310e59058c4SJames Smart /**
3113621a710SJames Smart  * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
312e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
313e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
314e59058c4SJames Smart  *
315e59058c4SJames Smart  * The clear link attention mailbox command is issued to clear the link event
316e59058c4SJames Smart  * attention condition indicated by the Link Event bit of the Host Attention
317e59058c4SJames Smart  * (HSTATT) register. The link event attention condition is cleared only if
318e59058c4SJames Smart  * the event tag specified matches that of the current link event counter.
319e59058c4SJames Smart  * The current event tag is read using the read link attention event mailbox
320e59058c4SJames Smart  * command.
321e59058c4SJames Smart  *
322e59058c4SJames Smart  * This routine prepares the mailbox command for clearing HBA link attention
323e59058c4SJames Smart  * information.
324e59058c4SJames Smart  **/
325dea3101eS void
326dea3101eS lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
327dea3101eS {
328dea3101eS 	MAILBOX_t *mb;
329dea3101eS 
33004c68496SJames Smart 	mb = &pmb->u.mb;
331dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
332dea3101eS 
333dea3101eS 	mb->un.varClearLA.eventTag = phba->fc_eventTag;
334dea3101eS 	mb->mbxCommand = MBX_CLEAR_LA;
335dea3101eS 	mb->mbxOwner = OWN_HOST;
336dea3101eS 	return;
337dea3101eS }
338dea3101eS 
339e59058c4SJames Smart /**
3403621a710SJames Smart  * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
341e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
342e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
343e59058c4SJames Smart  *
344e59058c4SJames Smart  * The configure link mailbox command is used before the initialize link
345e59058c4SJames Smart  * mailbox command to override default value and to configure link-oriented
346e59058c4SJames Smart  * parameters such as DID address and various timers. Typically, this
347e59058c4SJames Smart  * command would be used after an F_Port login to set the returned DID address
348e59058c4SJames Smart  * and the fabric timeout values. This command is not valid before a configure
349e59058c4SJames Smart  * port command has configured the HBA port.
350e59058c4SJames Smart  *
351e59058c4SJames Smart  * This routine prepares the mailbox command for configuring link on a HBA.
352e59058c4SJames Smart  **/
353dea3101eS void
354dea3101eS lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
355dea3101eS {
3562e0fef85SJames Smart 	struct lpfc_vport  *vport = phba->pport;
35704c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
358dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
359dea3101eS 
360dea3101eS 	/* NEW_FEATURE
361dea3101eS 	 * SLI-2, Coalescing Response Feature.
362dea3101eS 	 */
3631d1c296fSJames Smart 	if (phba->cfg_cr_delay && (phba->sli_rev < LPFC_SLI_REV4)) {
364dea3101eS 		mb->un.varCfgLnk.cr = 1;
365dea3101eS 		mb->un.varCfgLnk.ci = 1;
366dea3101eS 		mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
367dea3101eS 		mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
368dea3101eS 	}
369dea3101eS 
3702e0fef85SJames Smart 	mb->un.varCfgLnk.myId = vport->fc_myDID;
371dea3101eS 	mb->un.varCfgLnk.edtov = phba->fc_edtov;
372dea3101eS 	mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
373dea3101eS 	mb->un.varCfgLnk.ratov = phba->fc_ratov;
374dea3101eS 	mb->un.varCfgLnk.rttov = phba->fc_rttov;
375dea3101eS 	mb->un.varCfgLnk.altov = phba->fc_altov;
376dea3101eS 	mb->un.varCfgLnk.crtov = phba->fc_crtov;
377dea3101eS 	mb->un.varCfgLnk.citov = phba->fc_citov;
378dea3101eS 
3791d1c296fSJames Smart 	if (phba->cfg_ack0 && (phba->sli_rev < LPFC_SLI_REV4))
380dea3101eS 		mb->un.varCfgLnk.ack0_enable = 1;
381dea3101eS 
382dea3101eS 	mb->mbxCommand = MBX_CONFIG_LINK;
383dea3101eS 	mb->mbxOwner = OWN_HOST;
384dea3101eS 	return;
385dea3101eS }
386dea3101eS 
387e59058c4SJames Smart /**
3883621a710SJames Smart  * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
3899399627fSJames Smart  * @phba: pointer to lpfc hba data structure.
3909399627fSJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
3919399627fSJames Smart  *
3929399627fSJames Smart  * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
3939399627fSJames Smart  * MSI-X multi-message interrupt vector association to interrupt attention
3949399627fSJames Smart  * conditions.
3959399627fSJames Smart  *
3969399627fSJames Smart  * Return codes
3979399627fSJames Smart  *    0 - Success
3989399627fSJames Smart  *    -EINVAL - Failure
3999399627fSJames Smart  **/
4009399627fSJames Smart int
4019399627fSJames Smart lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4029399627fSJames Smart {
40304c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
4049399627fSJames Smart 	uint32_t attentionConditions[2];
4059399627fSJames Smart 
4069399627fSJames Smart 	/* Sanity check */
4079399627fSJames Smart 	if (phba->cfg_use_msi != 2) {
4089399627fSJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4099399627fSJames Smart 				"0475 Not configured for supporting MSI-X "
4109399627fSJames Smart 				"cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
4119399627fSJames Smart 		return -EINVAL;
4129399627fSJames Smart 	}
4139399627fSJames Smart 
4149399627fSJames Smart 	if (phba->sli_rev < 3) {
4159399627fSJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4169399627fSJames Smart 				"0476 HBA not supporting SLI-3 or later "
4179399627fSJames Smart 				"SLI Revision: 0x%x\n", phba->sli_rev);
4189399627fSJames Smart 		return -EINVAL;
4199399627fSJames Smart 	}
4209399627fSJames Smart 
4219399627fSJames Smart 	/* Clear mailbox command fields */
4229399627fSJames Smart 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
4239399627fSJames Smart 
4249399627fSJames Smart 	/*
4259399627fSJames Smart 	 * SLI-3, Message Signaled Interrupt Fearure.
4269399627fSJames Smart 	 */
4279399627fSJames Smart 
4289399627fSJames Smart 	/* Multi-message attention configuration */
4299399627fSJames Smart 	attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
4309399627fSJames Smart 				  HA_LATT | HA_MBATT);
4319399627fSJames Smart 	attentionConditions[1] = 0;
4329399627fSJames Smart 
4339399627fSJames Smart 	mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
4349399627fSJames Smart 	mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
4359399627fSJames Smart 
4369399627fSJames Smart 	/*
4379399627fSJames Smart 	 * Set up message number to HA bit association
4389399627fSJames Smart 	 */
4399399627fSJames Smart #ifdef __BIG_ENDIAN_BITFIELD
4409399627fSJames Smart 	/* RA0 (FCP Ring) */
4419399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
4429399627fSJames Smart 	/* RA1 (Other Protocol Extra Ring) */
4439399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
4449399627fSJames Smart #else   /*  __LITTLE_ENDIAN_BITFIELD */
4459399627fSJames Smart 	/* RA0 (FCP Ring) */
4469399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
4479399627fSJames Smart 	/* RA1 (Other Protocol Extra Ring) */
4489399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
4499399627fSJames Smart #endif
4509399627fSJames Smart 	/* Multi-message interrupt autoclear configuration*/
4519399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
4529399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
4539399627fSJames Smart 
4549399627fSJames Smart 	/* For now, HBA autoclear does not work reliably, disable it */
4559399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[0] = 0;
4569399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[1] = 0;
4579399627fSJames Smart 
4589399627fSJames Smart 	/* Set command and owner bit */
4599399627fSJames Smart 	mb->mbxCommand = MBX_CONFIG_MSI;
4609399627fSJames Smart 	mb->mbxOwner = OWN_HOST;
4619399627fSJames Smart 
4629399627fSJames Smart 	return 0;
4639399627fSJames Smart }
4649399627fSJames Smart 
4659399627fSJames Smart /**
4663621a710SJames Smart  * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
467e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
468e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
469e59058c4SJames Smart  * @topology: the link topology for the link to be initialized to.
470e59058c4SJames Smart  * @linkspeed: the link speed for the link to be initialized to.
471e59058c4SJames Smart  *
472e59058c4SJames Smart  * The initialize link mailbox command is used to initialize the Fibre
473e59058c4SJames Smart  * Channel link. This command must follow a configure port command that
474e59058c4SJames Smart  * establishes the mode of operation.
475e59058c4SJames Smart  *
476e59058c4SJames Smart  * This routine prepares the mailbox command for initializing link on a HBA
477e59058c4SJames Smart  * with the specified link topology and speed.
478e59058c4SJames Smart  **/
479dea3101eS void
480dea3101eS lpfc_init_link(struct lpfc_hba * phba,
481dea3101eS 	       LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
482dea3101eS {
483dea3101eS 	lpfc_vpd_t *vpd;
484dea3101eS 	MAILBOX_t *mb;
485dea3101eS 
48604c68496SJames Smart 	mb = &pmb->u.mb;
487dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
488dea3101eS 
489dea3101eS 	switch (topology) {
490dea3101eS 	case FLAGS_TOPOLOGY_MODE_LOOP_PT:
491dea3101eS 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
492dea3101eS 		mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
493dea3101eS 		break;
494dea3101eS 	case FLAGS_TOPOLOGY_MODE_PT_PT:
495dea3101eS 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
496dea3101eS 		break;
497dea3101eS 	case FLAGS_TOPOLOGY_MODE_LOOP:
498dea3101eS 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
499dea3101eS 		break;
500dea3101eS 	case FLAGS_TOPOLOGY_MODE_PT_LOOP:
501dea3101eS 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
502dea3101eS 		mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
503dea3101eS 		break;
504367c2713SJamie Wellnitz 	case FLAGS_LOCAL_LB:
505367c2713SJamie Wellnitz 		mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
506367c2713SJamie Wellnitz 		break;
507dea3101eS 	}
508dea3101eS 
509d38dd52cSJames Smart 	if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC &&
510d38dd52cSJames Smart 		mb->un.varInitLnk.link_flags & FLAGS_TOPOLOGY_MODE_LOOP) {
511d38dd52cSJames Smart 		/* Failover is not tried for Lancer G6 */
512d38dd52cSJames Smart 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
513d38dd52cSJames Smart 		phba->cfg_topology = FLAGS_TOPOLOGY_MODE_PT_PT;
514d38dd52cSJames Smart 	}
515d38dd52cSJames Smart 
5164b0b91d4SJames Smart 	/* Enable asynchronous ABTS responses from firmware */
5174b0b91d4SJames Smart 	mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
5184b0b91d4SJames Smart 
519dea3101eS 	/* NEW_FEATURE
520dea3101eS 	 * Setting up the link speed
521dea3101eS 	 */
522dea3101eS 	vpd = &phba->vpd;
523dea3101eS 	if (vpd->rev.feaLevelHigh >= 0x02){
524dea3101eS 		switch(linkspeed){
52576a95d75SJames Smart 		case LPFC_USER_LINK_SPEED_1G:
52676a95d75SJames Smart 			mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
52776a95d75SJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_1G;
528dea3101eS 			break;
52976a95d75SJames Smart 		case LPFC_USER_LINK_SPEED_2G:
53076a95d75SJames Smart 			mb->un.varInitLnk.link_flags |=	FLAGS_LINK_SPEED;
53176a95d75SJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_2G;
53276a95d75SJames Smart 			break;
53376a95d75SJames Smart 		case LPFC_USER_LINK_SPEED_4G:
53476a95d75SJames Smart 			mb->un.varInitLnk.link_flags |=	FLAGS_LINK_SPEED;
53576a95d75SJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_4G;
53676a95d75SJames Smart 			break;
53776a95d75SJames Smart 		case LPFC_USER_LINK_SPEED_8G:
53876a95d75SJames Smart 			mb->un.varInitLnk.link_flags |=	FLAGS_LINK_SPEED;
53976a95d75SJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_8G;
54076a95d75SJames Smart 			break;
54176a95d75SJames Smart 		case LPFC_USER_LINK_SPEED_10G:
54276a95d75SJames Smart 			mb->un.varInitLnk.link_flags |=	FLAGS_LINK_SPEED;
54376a95d75SJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_10G;
54476a95d75SJames Smart 			break;
54576a95d75SJames Smart 		case LPFC_USER_LINK_SPEED_16G:
54676a95d75SJames Smart 			mb->un.varInitLnk.link_flags |=	FLAGS_LINK_SPEED;
54776a95d75SJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_16G;
54876a95d75SJames Smart 			break;
549d38dd52cSJames Smart 		case LPFC_USER_LINK_SPEED_32G:
550d38dd52cSJames Smart 			mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
551d38dd52cSJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_32G;
552d38dd52cSJames Smart 			break;
55376a95d75SJames Smart 		case LPFC_USER_LINK_SPEED_AUTO:
554dea3101eS 		default:
55576a95d75SJames Smart 			mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
556dea3101eS 			break;
557dea3101eS 		}
558dea3101eS 
559dea3101eS 	}
560dea3101eS 	else
561dea3101eS 		mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
562dea3101eS 
563dea3101eS 	mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
564dea3101eS 	mb->mbxOwner = OWN_HOST;
565dea3101eS 	mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
566dea3101eS 	return;
567dea3101eS }
568dea3101eS 
569e59058c4SJames Smart /**
5703621a710SJames Smart  * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
571e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
572e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
573e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
574e59058c4SJames Smart  *
575e59058c4SJames Smart  * The read service parameter mailbox command is used to read the HBA port
576e59058c4SJames Smart  * service parameters. The service parameters are read into the buffer
577e59058c4SJames Smart  * specified directly by a BDE in the mailbox command. These service
578e59058c4SJames Smart  * parameters may then be used to build the payload of an N_Port/F_POrt
579e59058c4SJames Smart  * login request and reply (LOGI/ACC).
580e59058c4SJames Smart  *
581e59058c4SJames Smart  * This routine prepares the mailbox command for reading HBA port service
582e59058c4SJames Smart  * parameters. The DMA memory is allocated in this function and the addresses
583e59058c4SJames Smart  * are populated into the mailbox command for the HBA to DMA the service
584e59058c4SJames Smart  * parameters into.
585e59058c4SJames Smart  *
586e59058c4SJames Smart  * Return codes
587e59058c4SJames Smart  *    0 - Success
588e59058c4SJames Smart  *    1 - DMA memory allocation failed
589e59058c4SJames Smart  **/
590dea3101eS int
59192d7f7b0SJames Smart lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
592dea3101eS {
593dea3101eS 	struct lpfc_dmabuf *mp;
594dea3101eS 	MAILBOX_t *mb;
595dea3101eS 
59604c68496SJames Smart 	mb = &pmb->u.mb;
597dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
598dea3101eS 
599dea3101eS 	mb->mbxOwner = OWN_HOST;
600dea3101eS 
601dea3101eS 	/* Get a buffer to hold the HBAs Service Parameters */
602dea3101eS 
60398c9ea5cSJames Smart 	mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
60498c9ea5cSJames Smart 	if (mp)
60598c9ea5cSJames Smart 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
60698c9ea5cSJames Smart 	if (!mp || !mp->virt) {
607dea3101eS 		kfree(mp);
608dea3101eS 		mb->mbxCommand = MBX_READ_SPARM64;
609dea3101eS 		/* READ_SPARAM: no buffers */
610e8b62011SJames Smart 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
611e8b62011SJames Smart 			        "0301 READ_SPARAM: no buffers\n");
61292d7f7b0SJames Smart 		return (1);
613dea3101eS 	}
614dea3101eS 	INIT_LIST_HEAD(&mp->list);
615dea3101eS 	mb->mbxCommand = MBX_READ_SPARM64;
616dea3101eS 	mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
617dea3101eS 	mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
618dea3101eS 	mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
6196d368e53SJames Smart 	if (phba->sli_rev >= LPFC_SLI_REV3)
6206d368e53SJames Smart 		mb->un.varRdSparm.vpi = phba->vpi_ids[vpi];
621dea3101eS 
622dea3101eS 	/* save address for completion */
623dea3101eS 	pmb->context1 = mp;
624dea3101eS 
62592d7f7b0SJames Smart 	return (0);
626dea3101eS }
627dea3101eS 
628e59058c4SJames Smart /**
6293621a710SJames Smart  * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
630e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
631e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
632e59058c4SJames Smart  * @did: remote port identifier.
633e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
634e59058c4SJames Smart  *
635e59058c4SJames Smart  * The unregister DID mailbox command is used to unregister an N_Port/F_Port
636e59058c4SJames Smart  * login for an unknown RPI by specifying the DID of a remote port. This
637e59058c4SJames Smart  * command frees an RPI context in the HBA port. This has the effect of
638e59058c4SJames Smart  * performing an implicit N_Port/F_Port logout.
639e59058c4SJames Smart  *
640e59058c4SJames Smart  * This routine prepares the mailbox command for unregistering a remote
641e59058c4SJames Smart  * N_Port/F_Port (DID) login.
642e59058c4SJames Smart  **/
643dea3101eS void
64492d7f7b0SJames Smart lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
64592d7f7b0SJames Smart 	       LPFC_MBOXQ_t * pmb)
646dea3101eS {
647dea3101eS 	MAILBOX_t *mb;
648dea3101eS 
64904c68496SJames Smart 	mb = &pmb->u.mb;
650dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
651dea3101eS 
652dea3101eS 	mb->un.varUnregDID.did = did;
65392d7f7b0SJames Smart 	mb->un.varUnregDID.vpi = vpi;
6546d368e53SJames Smart 	if ((vpi != 0xffff) &&
6556d368e53SJames Smart 	    (phba->sli_rev == LPFC_SLI_REV4))
6566d368e53SJames Smart 		mb->un.varUnregDID.vpi = phba->vpi_ids[vpi];
657dea3101eS 
658dea3101eS 	mb->mbxCommand = MBX_UNREG_D_ID;
659dea3101eS 	mb->mbxOwner = OWN_HOST;
660dea3101eS 	return;
661dea3101eS }
662dea3101eS 
663e59058c4SJames Smart /**
6643621a710SJames Smart  * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
665e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
666e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
667e59058c4SJames Smart  *
668e59058c4SJames Smart  * The read configuration mailbox command is used to read the HBA port
669e59058c4SJames Smart  * configuration parameters. This mailbox command provides a method for
670e59058c4SJames Smart  * seeing any parameters that may have changed via various configuration
671e59058c4SJames Smart  * mailbox commands.
672e59058c4SJames Smart  *
673e59058c4SJames Smart  * This routine prepares the mailbox command for reading out HBA configuration
674e59058c4SJames Smart  * parameters.
675e59058c4SJames Smart  **/
676dea3101eS void
677dea3101eS lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
678dea3101eS {
679dea3101eS 	MAILBOX_t *mb;
680dea3101eS 
68104c68496SJames Smart 	mb = &pmb->u.mb;
682dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
683dea3101eS 
684dea3101eS 	mb->mbxCommand = MBX_READ_CONFIG;
685dea3101eS 	mb->mbxOwner = OWN_HOST;
686dea3101eS 	return;
687dea3101eS }
688dea3101eS 
689e59058c4SJames Smart /**
6903621a710SJames Smart  * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
691e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
692e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
693e59058c4SJames Smart  *
694e59058c4SJames Smart  * The read link status mailbox command is used to read the link status from
695e59058c4SJames Smart  * the HBA. Link status includes all link-related error counters. These
696e59058c4SJames Smart  * counters are maintained by the HBA and originated in the link hardware
697e59058c4SJames Smart  * unit. Note that all of these counters wrap.
698e59058c4SJames Smart  *
699e59058c4SJames Smart  * This routine prepares the mailbox command for reading out HBA link status.
700e59058c4SJames Smart  **/
7017bb3b137SJamie Wellnitz void
7027bb3b137SJamie Wellnitz lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
7037bb3b137SJamie Wellnitz {
7047bb3b137SJamie Wellnitz 	MAILBOX_t *mb;
7057bb3b137SJamie Wellnitz 
70604c68496SJames Smart 	mb = &pmb->u.mb;
7077bb3b137SJamie Wellnitz 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
7087bb3b137SJamie Wellnitz 
7097bb3b137SJamie Wellnitz 	mb->mbxCommand = MBX_READ_LNK_STAT;
7107bb3b137SJamie Wellnitz 	mb->mbxOwner = OWN_HOST;
7117bb3b137SJamie Wellnitz 	return;
7127bb3b137SJamie Wellnitz }
7137bb3b137SJamie Wellnitz 
714e59058c4SJames Smart /**
71504c68496SJames Smart  * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
716e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
717e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
718e59058c4SJames Smart  * @did: remote port identifier.
719e59058c4SJames Smart  * @param: pointer to memory holding the server parameters.
720e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
7214042629eSJames Smart  * @rpi: the rpi to use in the registration (usually only used for SLI4.
722e59058c4SJames Smart  *
723e59058c4SJames Smart  * The registration login mailbox command is used to register an N_Port or
724e59058c4SJames Smart  * F_Port login. This registration allows the HBA to cache the remote N_Port
725e59058c4SJames Smart  * service parameters internally and thereby make the appropriate FC-2
726e59058c4SJames Smart  * decisions. The remote port service parameters are handed off by the driver
727e59058c4SJames Smart  * to the HBA using a descriptor entry that directly identifies a buffer in
728e59058c4SJames Smart  * host memory. In exchange, the HBA returns an RPI identifier.
729e59058c4SJames Smart  *
730e59058c4SJames Smart  * This routine prepares the mailbox command for registering remote port login.
731e59058c4SJames Smart  * The function allocates DMA buffer for passing the service parameters to the
732e59058c4SJames Smart  * HBA with the mailbox command.
733e59058c4SJames Smart  *
734e59058c4SJames Smart  * Return codes
735e59058c4SJames Smart  *    0 - Success
736e59058c4SJames Smart  *    1 - DMA memory allocation failed
737e59058c4SJames Smart  **/
738dea3101eS int
73904c68496SJames Smart lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
7404042629eSJames Smart 	     uint8_t *param, LPFC_MBOXQ_t *pmb, uint16_t rpi)
741dea3101eS {
74204c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
743dea3101eS 	uint8_t *sparam;
744dea3101eS 	struct lpfc_dmabuf *mp;
745dea3101eS 
746dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
747dea3101eS 
748dea3101eS 	mb->un.varRegLogin.rpi = 0;
7496d368e53SJames Smart 	if (phba->sli_rev == LPFC_SLI_REV4)
7506d368e53SJames Smart 		mb->un.varRegLogin.rpi = phba->sli4_hba.rpi_ids[rpi];
7516d368e53SJames Smart 	if (phba->sli_rev >= LPFC_SLI_REV3)
7526d368e53SJames Smart 		mb->un.varRegLogin.vpi = phba->vpi_ids[vpi];
753dea3101eS 	mb->un.varRegLogin.did = did;
754dea3101eS 	mb->mbxOwner = OWN_HOST;
755dea3101eS 	/* Get a buffer to hold NPorts Service Parameters */
75698c9ea5cSJames Smart 	mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
75798c9ea5cSJames Smart 	if (mp)
75898c9ea5cSJames Smart 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
75998c9ea5cSJames Smart 	if (!mp || !mp->virt) {
760dea3101eS 		kfree(mp);
761dea3101eS 		mb->mbxCommand = MBX_REG_LOGIN64;
762dea3101eS 		/* REG_LOGIN: no buffers */
76392d7f7b0SJames Smart 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
764e8b62011SJames Smart 				"0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
7654042629eSJames Smart 				"rpi x%x\n", vpi, did, rpi);
7666d368e53SJames Smart 		return 1;
767dea3101eS 	}
768dea3101eS 	INIT_LIST_HEAD(&mp->list);
769dea3101eS 	sparam = mp->virt;
770dea3101eS 
771dea3101eS 	/* Copy param's into a new buffer */
772dea3101eS 	memcpy(sparam, param, sizeof (struct serv_parm));
773dea3101eS 
774dea3101eS 	/* save address for completion */
775dea3101eS 	pmb->context1 = (uint8_t *) mp;
776dea3101eS 
777dea3101eS 	mb->mbxCommand = MBX_REG_LOGIN64;
778dea3101eS 	mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
779dea3101eS 	mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
780dea3101eS 	mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
781dea3101eS 
7826d368e53SJames Smart 	return 0;
783dea3101eS }
784dea3101eS 
785e59058c4SJames Smart /**
7863621a710SJames Smart  * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
787e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
788e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
789e59058c4SJames Smart  * @rpi: remote port identifier
790e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
791e59058c4SJames Smart  *
792e59058c4SJames Smart  * The unregistration login mailbox command is used to unregister an N_Port
793e59058c4SJames Smart  * or F_Port login. This command frees an RPI context in the HBA. It has the
794e59058c4SJames Smart  * effect of performing an implicit N_Port/F_Port logout.
795e59058c4SJames Smart  *
796e59058c4SJames Smart  * This routine prepares the mailbox command for unregistering remote port
797e59058c4SJames Smart  * login.
7986d368e53SJames Smart  *
7996d368e53SJames Smart  * For SLI4 ports, the rpi passed to this function must be the physical
8006d368e53SJames Smart  * rpi value, not the logical index.
801e59058c4SJames Smart  **/
802dea3101eS void
80392d7f7b0SJames Smart lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
80492d7f7b0SJames Smart 		 LPFC_MBOXQ_t * pmb)
805dea3101eS {
806dea3101eS 	MAILBOX_t *mb;
807dea3101eS 
80804c68496SJames Smart 	mb = &pmb->u.mb;
809dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
810dea3101eS 
8116d368e53SJames Smart 	mb->un.varUnregLogin.rpi = rpi;
812dea3101eS 	mb->un.varUnregLogin.rsvd1 = 0;
8136d368e53SJames Smart 	if (phba->sli_rev >= LPFC_SLI_REV3)
8146d368e53SJames Smart 		mb->un.varUnregLogin.vpi = phba->vpi_ids[vpi];
815dea3101eS 
816dea3101eS 	mb->mbxCommand = MBX_UNREG_LOGIN;
817dea3101eS 	mb->mbxOwner = OWN_HOST;
81804c68496SJames Smart 
819dea3101eS 	return;
820dea3101eS }
821dea3101eS 
822e59058c4SJames Smart /**
8235af5eee7SJames Smart  * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA.
8245af5eee7SJames Smart  * @vport: pointer to a vport object.
8255af5eee7SJames Smart  *
8265af5eee7SJames Smart  * This routine sends mailbox command to unregister all active RPIs for
8275af5eee7SJames Smart  * a vport.
8285af5eee7SJames Smart  **/
8295af5eee7SJames Smart void
8305af5eee7SJames Smart lpfc_sli4_unreg_all_rpis(struct lpfc_vport *vport)
8315af5eee7SJames Smart {
8325af5eee7SJames Smart 	struct lpfc_hba  *phba  = vport->phba;
8335af5eee7SJames Smart 	LPFC_MBOXQ_t     *mbox;
8345af5eee7SJames Smart 	int rc;
8355af5eee7SJames Smart 
8365af5eee7SJames Smart 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8375af5eee7SJames Smart 	if (mbox) {
8386d368e53SJames Smart 		/*
8396d368e53SJames Smart 		 * For SLI4 functions, the rpi field is overloaded for
8406d368e53SJames Smart 		 * the vport context unreg all.  This routine passes
8416d368e53SJames Smart 		 * 0 for the rpi field in lpfc_unreg_login for compatibility
8426d368e53SJames Smart 		 * with SLI3 and then overrides the rpi field with the
8436d368e53SJames Smart 		 * expected value for SLI4.
8446d368e53SJames Smart 		 */
8456d368e53SJames Smart 		lpfc_unreg_login(phba, vport->vpi, phba->vpi_ids[vport->vpi],
8466d368e53SJames Smart 				 mbox);
8475af5eee7SJames Smart 		mbox->u.mb.un.varUnregLogin.rsvd1 = 0x4000;
8485af5eee7SJames Smart 		mbox->vport = vport;
8495af5eee7SJames Smart 		mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8505af5eee7SJames Smart 		mbox->context1 = NULL;
8515af5eee7SJames Smart 		rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
8525af5eee7SJames Smart 		if (rc == MBX_NOT_FINISHED)
8535af5eee7SJames Smart 			mempool_free(mbox, phba->mbox_mem_pool);
8545af5eee7SJames Smart 	}
8555af5eee7SJames Smart }
8565af5eee7SJames Smart 
8575af5eee7SJames Smart /**
8583621a710SJames Smart  * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
859e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
860e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
861e59058c4SJames Smart  * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
862e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
863e59058c4SJames Smart  *
864e59058c4SJames Smart  * The registration vport identifier mailbox command is used to activate a
865e59058c4SJames Smart  * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
866e59058c4SJames Smart  * N_Port_ID against the information in the selected virtual N_Port context
867e59058c4SJames Smart  * block and marks it active to allow normal processing of IOCB commands and
868e59058c4SJames Smart  * received unsolicited exchanges.
869e59058c4SJames Smart  *
870e59058c4SJames Smart  * This routine prepares the mailbox command for registering a virtual N_Port.
871e59058c4SJames Smart  **/
87292d7f7b0SJames Smart void
87304c68496SJames Smart lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
87492d7f7b0SJames Smart {
87504c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
87638b92ef8SJames Smart 	struct lpfc_hba *phba = vport->phba;
87792d7f7b0SJames Smart 
87892d7f7b0SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
87938b92ef8SJames Smart 	/*
88038b92ef8SJames Smart 	 * Set the re-reg VPI bit for f/w to update the MAC address.
88138b92ef8SJames Smart 	 */
88238b92ef8SJames Smart 	if ((phba->sli_rev == LPFC_SLI_REV4) &&
88338b92ef8SJames Smart 		!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI))
88438b92ef8SJames Smart 		mb->un.varRegVpi.upd = 1;
8856d368e53SJames Smart 
8866d368e53SJames Smart 	mb->un.varRegVpi.vpi = phba->vpi_ids[vport->vpi];
88704c68496SJames Smart 	mb->un.varRegVpi.sid = vport->fc_myDID;
8886d368e53SJames Smart 	if (phba->sli_rev == LPFC_SLI_REV4)
8896d368e53SJames Smart 		mb->un.varRegVpi.vfi = phba->sli4_hba.vfi_ids[vport->vfi];
8906d368e53SJames Smart 	else
89104c68496SJames Smart 		mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
892c868595dSJames Smart 	memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname,
893c868595dSJames Smart 	       sizeof(struct lpfc_name));
894c868595dSJames Smart 	mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]);
895c868595dSJames Smart 	mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]);
89692d7f7b0SJames Smart 
89792d7f7b0SJames Smart 	mb->mbxCommand = MBX_REG_VPI;
89892d7f7b0SJames Smart 	mb->mbxOwner = OWN_HOST;
89992d7f7b0SJames Smart 	return;
90092d7f7b0SJames Smart 
90192d7f7b0SJames Smart }
90292d7f7b0SJames Smart 
903e59058c4SJames Smart /**
9043621a710SJames Smart  * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
905e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
906e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
907e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
908e59058c4SJames Smart  *
909e59058c4SJames Smart  * The unregistration vport identifier mailbox command is used to inactivate
910e59058c4SJames Smart  * a virtual N_Port. The driver must have logged out and unregistered all
911e59058c4SJames Smart  * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
912e59058c4SJames Smart  * unregisters any default RPIs associated with the specified vpi, aborting
913e59058c4SJames Smart  * any active exchanges. The HBA will post the mailbox response after making
914e59058c4SJames Smart  * the virtual N_Port inactive.
915e59058c4SJames Smart  *
916e59058c4SJames Smart  * This routine prepares the mailbox command for unregistering a virtual
917e59058c4SJames Smart  * N_Port.
918e59058c4SJames Smart  **/
91992d7f7b0SJames Smart void
92092d7f7b0SJames Smart lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
92192d7f7b0SJames Smart {
92204c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
92392d7f7b0SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
92492d7f7b0SJames Smart 
9256d368e53SJames Smart 	if (phba->sli_rev == LPFC_SLI_REV3)
9266d368e53SJames Smart 		mb->un.varUnregVpi.vpi = phba->vpi_ids[vpi];
9276d368e53SJames Smart 	else if (phba->sli_rev >= LPFC_SLI_REV4)
9286d368e53SJames Smart 		mb->un.varUnregVpi.sli4_vpi = phba->vpi_ids[vpi];
92992d7f7b0SJames Smart 
93092d7f7b0SJames Smart 	mb->mbxCommand = MBX_UNREG_VPI;
93192d7f7b0SJames Smart 	mb->mbxOwner = OWN_HOST;
93292d7f7b0SJames Smart 	return;
93392d7f7b0SJames Smart 
93492d7f7b0SJames Smart }
93592d7f7b0SJames Smart 
936e59058c4SJames Smart /**
9373621a710SJames Smart  * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
938e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
939e59058c4SJames Smart  *
940e59058c4SJames Smart  * This routine sets up and initializes the IOCB rings in the Port Control
941e59058c4SJames Smart  * Block (PCB).
942e59058c4SJames Smart  **/
943dea3101eS static void
944dea3101eS lpfc_config_pcb_setup(struct lpfc_hba * phba)
945dea3101eS {
946dea3101eS 	struct lpfc_sli *psli = &phba->sli;
947dea3101eS 	struct lpfc_sli_ring *pring;
94834b02dcdSJames Smart 	PCB_t *pcbp = phba->pcb;
949dea3101eS 	dma_addr_t pdma_addr;
950dea3101eS 	uint32_t offset;
9512e0fef85SJames Smart 	uint32_t iocbCnt = 0;
952dea3101eS 	int i;
953dea3101eS 
954dea3101eS 	pcbp->maxRing = (psli->num_rings - 1);
955dea3101eS 
956dea3101eS 	for (i = 0; i < psli->num_rings; i++) {
957dea3101eS 		pring = &psli->ring[i];
9582e0fef85SJames Smart 
9597e56aa25SJames Smart 		pring->sli.sli3.sizeCiocb =
9607e56aa25SJames Smart 			phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE :
961ed957684SJames Smart 							SLI2_IOCB_CMD_SIZE;
9627e56aa25SJames Smart 		pring->sli.sli3.sizeRiocb =
9637e56aa25SJames Smart 			phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE :
964ed957684SJames Smart 							SLI2_IOCB_RSP_SIZE;
965dea3101eS 		/* A ring MUST have both cmd and rsp entries defined to be
966dea3101eS 		   valid */
9677e56aa25SJames Smart 		if ((pring->sli.sli3.numCiocb == 0) ||
9687e56aa25SJames Smart 			(pring->sli.sli3.numRiocb == 0)) {
969dea3101eS 			pcbp->rdsc[i].cmdEntries = 0;
970dea3101eS 			pcbp->rdsc[i].rspEntries = 0;
971dea3101eS 			pcbp->rdsc[i].cmdAddrHigh = 0;
972dea3101eS 			pcbp->rdsc[i].rspAddrHigh = 0;
973dea3101eS 			pcbp->rdsc[i].cmdAddrLow = 0;
974dea3101eS 			pcbp->rdsc[i].rspAddrLow = 0;
9757e56aa25SJames Smart 			pring->sli.sli3.cmdringaddr = NULL;
9767e56aa25SJames Smart 			pring->sli.sli3.rspringaddr = NULL;
977dea3101eS 			continue;
978dea3101eS 		}
979dea3101eS 		/* Command ring setup for ring */
9807e56aa25SJames Smart 		pring->sli.sli3.cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
9817e56aa25SJames Smart 		pcbp->rdsc[i].cmdEntries = pring->sli.sli3.numCiocb;
982dea3101eS 
98334b02dcdSJames Smart 		offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
98434b02dcdSJames Smart 			 (uint8_t *) phba->slim2p.virt;
98534b02dcdSJames Smart 		pdma_addr = phba->slim2p.phys + offset;
986dea3101eS 		pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
987dea3101eS 		pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
9887e56aa25SJames Smart 		iocbCnt += pring->sli.sli3.numCiocb;
989dea3101eS 
990dea3101eS 		/* Response ring setup for ring */
9917e56aa25SJames Smart 		pring->sli.sli3.rspringaddr = (void *) &phba->IOCBs[iocbCnt];
992dea3101eS 
9937e56aa25SJames Smart 		pcbp->rdsc[i].rspEntries = pring->sli.sli3.numRiocb;
99434b02dcdSJames Smart 		offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
99534b02dcdSJames Smart 			 (uint8_t *)phba->slim2p.virt;
99634b02dcdSJames Smart 		pdma_addr = phba->slim2p.phys + offset;
997dea3101eS 		pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
998dea3101eS 		pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
9997e56aa25SJames Smart 		iocbCnt += pring->sli.sli3.numRiocb;
1000dea3101eS 	}
1001dea3101eS }
1002dea3101eS 
1003e59058c4SJames Smart /**
10043621a710SJames Smart  * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
1005e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1006e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1007e59058c4SJames Smart  *
1008e59058c4SJames Smart  * The read revision mailbox command is used to read the revision levels of
1009e59058c4SJames Smart  * the HBA components. These components include hardware units, resident
1010e59058c4SJames Smart  * firmware, and available firmware. HBAs that supports SLI-3 mode of
1011e59058c4SJames Smart  * operation provide different response information depending on the version
1012e59058c4SJames Smart  * requested by the driver.
1013e59058c4SJames Smart  *
1014e59058c4SJames Smart  * This routine prepares the mailbox command for reading HBA revision
1015e59058c4SJames Smart  * information.
1016e59058c4SJames Smart  **/
1017dea3101eS void
1018dea3101eS lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1019dea3101eS {
102004c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
1021dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1022dea3101eS 	mb->un.varRdRev.cv = 1;
1023ed957684SJames Smart 	mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
1024dea3101eS 	mb->mbxCommand = MBX_READ_REV;
1025dea3101eS 	mb->mbxOwner = OWN_HOST;
1026dea3101eS 	return;
1027dea3101eS }
1028dea3101eS 
1029d7c47992SJames Smart void
1030d7c47992SJames Smart lpfc_sli4_swap_str(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1031d7c47992SJames Smart {
1032d7c47992SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
1033d7c47992SJames Smart 	struct lpfc_mqe *mqe;
1034d7c47992SJames Smart 
1035d7c47992SJames Smart 	switch (mb->mbxCommand) {
1036d7c47992SJames Smart 	case  MBX_READ_REV:
1037d7c47992SJames Smart 		 mqe = &pmb->u.mqe;
1038d7c47992SJames Smart 		lpfc_sli_pcimem_bcopy(mqe->un.read_rev.fw_name,
1039d7c47992SJames Smart 				 mqe->un.read_rev.fw_name, 16);
1040d7c47992SJames Smart 		lpfc_sli_pcimem_bcopy(mqe->un.read_rev.ulp_fw_name,
1041d7c47992SJames Smart 				 mqe->un.read_rev.ulp_fw_name, 16);
1042d7c47992SJames Smart 		break;
1043d7c47992SJames Smart 	default:
1044d7c47992SJames Smart 		break;
1045d7c47992SJames Smart 	}
1046d7c47992SJames Smart 	return;
1047d7c47992SJames Smart }
1048d7c47992SJames Smart 
1049e59058c4SJames Smart /**
10503621a710SJames Smart  * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
1051e59058c4SJames Smart  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1052e59058c4SJames Smart  * @hbq_desc: pointer to the HBQ selection profile descriptor.
1053e59058c4SJames Smart  *
1054e59058c4SJames Smart  * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
1055e59058c4SJames Smart  * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
1056e59058c4SJames Smart  * the Sequence Length Test using the fields in the Selection Profile 2
1057e59058c4SJames Smart  * extension in words 20:31.
1058e59058c4SJames Smart  **/
1059ed957684SJames Smart static void
1060ed957684SJames Smart lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
1061ed957684SJames Smart 			struct lpfc_hbq_init  *hbq_desc)
1062ed957684SJames Smart {
1063ed957684SJames Smart 	hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
1064ed957684SJames Smart 	hbqmb->profiles.profile2.maxlen     = hbq_desc->maxlen;
1065ed957684SJames Smart 	hbqmb->profiles.profile2.seqlenoff  = hbq_desc->seqlenoff;
1066ed957684SJames Smart }
1067ed957684SJames Smart 
1068e59058c4SJames Smart /**
10693621a710SJames Smart  * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
1070e59058c4SJames Smart  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1071e59058c4SJames Smart  * @hbq_desc: pointer to the HBQ selection profile descriptor.
1072e59058c4SJames Smart  *
1073e59058c4SJames Smart  * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
1074e59058c4SJames Smart  * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
1075e59058c4SJames Smart  * the Sequence Length Test and Byte Field Test using the fields in the
1076e59058c4SJames Smart  * Selection Profile 3 extension in words 20:31.
1077e59058c4SJames Smart  **/
1078ed957684SJames Smart static void
1079ed957684SJames Smart lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
1080ed957684SJames Smart 			struct lpfc_hbq_init  *hbq_desc)
1081ed957684SJames Smart {
1082ed957684SJames Smart 	hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
1083ed957684SJames Smart 	hbqmb->profiles.profile3.maxlen     = hbq_desc->maxlen;
1084ed957684SJames Smart 	hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
1085ed957684SJames Smart 	hbqmb->profiles.profile3.seqlenoff  = hbq_desc->seqlenoff;
1086ed957684SJames Smart 	memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
1087ed957684SJames Smart 	       sizeof(hbqmb->profiles.profile3.cmdmatch));
1088ed957684SJames Smart }
1089ed957684SJames Smart 
1090e59058c4SJames Smart /**
10913621a710SJames Smart  * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
1092e59058c4SJames Smart  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1093e59058c4SJames Smart  * @hbq_desc: pointer to the HBQ selection profile descriptor.
1094e59058c4SJames Smart  *
1095e59058c4SJames Smart  * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
1096e59058c4SJames Smart  * HBA tests the initial frame of an incoming sequence using the frame's
1097e59058c4SJames Smart  * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
1098e59058c4SJames Smart  * and Byte Field Test using the fields in the Selection Profile 5 extension
1099e59058c4SJames Smart  * words 20:31.
1100e59058c4SJames Smart  **/
1101ed957684SJames Smart static void
1102ed957684SJames Smart lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
1103ed957684SJames Smart 			struct lpfc_hbq_init  *hbq_desc)
1104ed957684SJames Smart {
1105ed957684SJames Smart 	hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
1106ed957684SJames Smart 	hbqmb->profiles.profile5.maxlen     = hbq_desc->maxlen;
1107ed957684SJames Smart 	hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
1108ed957684SJames Smart 	hbqmb->profiles.profile5.seqlenoff  = hbq_desc->seqlenoff;
1109ed957684SJames Smart 	memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
1110ed957684SJames Smart 	       sizeof(hbqmb->profiles.profile5.cmdmatch));
1111ed957684SJames Smart }
1112ed957684SJames Smart 
1113e59058c4SJames Smart /**
11143621a710SJames Smart  * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
1115e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1116e59058c4SJames Smart  * @id: HBQ identifier.
1117e59058c4SJames Smart  * @hbq_desc: pointer to the HBA descriptor data structure.
1118e59058c4SJames Smart  * @hbq_entry_index: index of the HBQ entry data structures.
1119e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1120e59058c4SJames Smart  *
1121e59058c4SJames Smart  * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
1122e59058c4SJames Smart  * an HBQ. The configuration binds events that require buffers to a particular
1123e59058c4SJames Smart  * ring and HBQ based on a selection profile.
1124e59058c4SJames Smart  *
1125e59058c4SJames Smart  * This routine prepares the mailbox command for configuring an HBQ.
1126e59058c4SJames Smart  **/
1127ed957684SJames Smart void
112851ef4c26SJames Smart lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
112951ef4c26SJames Smart 		 struct lpfc_hbq_init *hbq_desc,
1130ed957684SJames Smart 		uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
1131ed957684SJames Smart {
1132ed957684SJames Smart 	int i;
113304c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
1134ed957684SJames Smart 	struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
1135ed957684SJames Smart 
1136ed957684SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
113751ef4c26SJames Smart 	hbqmb->hbqId = id;
1138ed957684SJames Smart 	hbqmb->entry_count = hbq_desc->entry_count;   /* # entries in HBQ */
1139ed957684SJames Smart 	hbqmb->recvNotify = hbq_desc->rn;             /* Receive
1140ed957684SJames Smart 						       * Notification */
1141ed957684SJames Smart 	hbqmb->numMask    = hbq_desc->mask_count;     /* # R_CTL/TYPE masks
1142ed957684SJames Smart 						       * # in words 0-19 */
1143ed957684SJames Smart 	hbqmb->profile    = hbq_desc->profile;	      /* Selection profile:
1144ed957684SJames Smart 						       * 0 = all,
1145ed957684SJames Smart 						       * 7 = logentry */
1146ed957684SJames Smart 	hbqmb->ringMask   = hbq_desc->ring_mask;      /* Binds HBQ to a ring
1147ed957684SJames Smart 						       * e.g. Ring0=b0001,
1148ed957684SJames Smart 						       * ring2=b0100 */
1149ed957684SJames Smart 	hbqmb->headerLen  = hbq_desc->headerLen;      /* 0 if not profile 4
1150ed957684SJames Smart 						       * or 5 */
1151ed957684SJames Smart 	hbqmb->logEntry   = hbq_desc->logEntry;       /* Set to 1 if this
1152ed957684SJames Smart 						       * HBQ will be used
1153ed957684SJames Smart 						       * for LogEntry
1154ed957684SJames Smart 						       * buffers */
1155ed957684SJames Smart 	hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
1156ed957684SJames Smart 		hbq_entry_index * sizeof(struct lpfc_hbq_entry);
1157ed957684SJames Smart 	hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
1158ed957684SJames Smart 
1159ed957684SJames Smart 	mb->mbxCommand = MBX_CONFIG_HBQ;
1160ed957684SJames Smart 	mb->mbxOwner = OWN_HOST;
1161ed957684SJames Smart 
1162ed957684SJames Smart 				/* Copy info for profiles 2,3,5. Other
1163ed957684SJames Smart 				 * profiles this area is reserved
1164ed957684SJames Smart 				 */
1165ed957684SJames Smart 	if (hbq_desc->profile == 2)
1166ed957684SJames Smart 		lpfc_build_hbq_profile2(hbqmb, hbq_desc);
1167ed957684SJames Smart 	else if (hbq_desc->profile == 3)
1168ed957684SJames Smart 		lpfc_build_hbq_profile3(hbqmb, hbq_desc);
1169ed957684SJames Smart 	else if (hbq_desc->profile == 5)
1170ed957684SJames Smart 		lpfc_build_hbq_profile5(hbqmb, hbq_desc);
1171ed957684SJames Smart 
1172ed957684SJames Smart 	/* Return if no rctl / type masks for this HBQ */
1173ed957684SJames Smart 	if (!hbq_desc->mask_count)
1174ed957684SJames Smart 		return;
1175ed957684SJames Smart 
1176ed957684SJames Smart 	/* Otherwise we setup specific rctl / type masks for this HBQ */
1177ed957684SJames Smart 	for (i = 0; i < hbq_desc->mask_count; i++) {
1178ed957684SJames Smart 		hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
1179ed957684SJames Smart 		hbqmb->hbqMasks[i].tmask  = hbq_desc->hbqMasks[i].tmask;
1180ed957684SJames Smart 		hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
1181ed957684SJames Smart 		hbqmb->hbqMasks[i].rctlmask  = hbq_desc->hbqMasks[i].rctlmask;
1182ed957684SJames Smart 	}
1183ed957684SJames Smart 
1184ed957684SJames Smart 	return;
1185ed957684SJames Smart }
1186ed957684SJames Smart 
1187e59058c4SJames Smart /**
11883621a710SJames Smart  * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
1189e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1190e59058c4SJames Smart  * @ring:
1191e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1192e59058c4SJames Smart  *
1193e59058c4SJames Smart  * The configure ring mailbox command is used to configure an IOCB ring. This
1194e59058c4SJames Smart  * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1195e59058c4SJames Smart  * ring. This is used to map incoming sequences to a particular ring whose
1196e59058c4SJames Smart  * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1197e59058c4SJames Smart  * attempt to configure a ring whose number is greater than the number
1198e59058c4SJames Smart  * specified in the Port Control Block (PCB). It is an error to issue the
1199e59058c4SJames Smart  * configure ring command more than once with the same ring number. The HBA
1200e59058c4SJames Smart  * returns an error if the driver attempts this.
1201e59058c4SJames Smart  *
1202e59058c4SJames Smart  * This routine prepares the mailbox command for configuring IOCB ring.
1203e59058c4SJames Smart  **/
1204dea3101eS void
1205dea3101eS lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
1206dea3101eS {
1207dea3101eS 	int i;
120804c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
1209dea3101eS 	struct lpfc_sli *psli;
1210dea3101eS 	struct lpfc_sli_ring *pring;
1211dea3101eS 
1212dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1213dea3101eS 
1214dea3101eS 	mb->un.varCfgRing.ring = ring;
1215dea3101eS 	mb->un.varCfgRing.maxOrigXchg = 0;
1216dea3101eS 	mb->un.varCfgRing.maxRespXchg = 0;
1217dea3101eS 	mb->un.varCfgRing.recvNotify = 1;
1218dea3101eS 
1219dea3101eS 	psli = &phba->sli;
1220dea3101eS 	pring = &psli->ring[ring];
1221dea3101eS 	mb->un.varCfgRing.numMask = pring->num_mask;
1222dea3101eS 	mb->mbxCommand = MBX_CONFIG_RING;
1223dea3101eS 	mb->mbxOwner = OWN_HOST;
1224dea3101eS 
1225dea3101eS 	/* Is this ring configured for a specific profile */
1226dea3101eS 	if (pring->prt[0].profile) {
1227dea3101eS 		mb->un.varCfgRing.profile = pring->prt[0].profile;
1228dea3101eS 		return;
1229dea3101eS 	}
1230dea3101eS 
1231dea3101eS 	/* Otherwise we setup specific rctl / type masks for this ring */
1232dea3101eS 	for (i = 0; i < pring->num_mask; i++) {
1233dea3101eS 		mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
12346a9c52cfSJames Smart 		if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ)
1235dea3101eS 			mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
1236dea3101eS 		else
1237dea3101eS 			mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
1238dea3101eS 		mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
1239dea3101eS 		mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
1240dea3101eS 	}
1241dea3101eS 
1242dea3101eS 	return;
1243dea3101eS }
1244dea3101eS 
1245e59058c4SJames Smart /**
12463621a710SJames Smart  * lpfc_config_port - Prepare a mailbox command for configuring port
1247e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1248e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1249e59058c4SJames Smart  *
1250e59058c4SJames Smart  * The configure port mailbox command is used to identify the Port Control
1251e59058c4SJames Smart  * Block (PCB) in the driver memory. After this command is issued, the
1252e59058c4SJames Smart  * driver must not access the mailbox in the HBA without first resetting
1253e59058c4SJames Smart  * the HBA. The HBA may copy the PCB information to internal storage for
1254e59058c4SJames Smart  * subsequent use; the driver can not change the PCB information unless it
1255e59058c4SJames Smart  * resets the HBA.
1256e59058c4SJames Smart  *
1257e59058c4SJames Smart  * This routine prepares the mailbox command for configuring port.
1258e59058c4SJames Smart  **/
1259dea3101eS void
1260dea3101eS lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1261dea3101eS {
1262ed957684SJames Smart 	MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
126304c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
1264dea3101eS 	dma_addr_t pdma_addr;
1265dea3101eS 	uint32_t bar_low, bar_high;
1266dea3101eS 	size_t offset;
12674cc2da1dSJames.Smart@Emulex.Com 	struct lpfc_hgp hgp;
1268f91b392cSJames.Smart@Emulex.Com 	int i;
1269ed957684SJames Smart 	uint32_t pgp_offset;
1270dea3101eS 
1271dea3101eS 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1272dea3101eS 	mb->mbxCommand = MBX_CONFIG_PORT;
1273dea3101eS 	mb->mbxOwner = OWN_HOST;
1274dea3101eS 
1275dea3101eS 	mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
1276dea3101eS 
127734b02dcdSJames Smart 	offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
127834b02dcdSJames Smart 	pdma_addr = phba->slim2p.phys + offset;
1279dea3101eS 	mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
1280dea3101eS 	mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
1281dea3101eS 
128297207482SJames Smart 	/* Always Host Group Pointer is in SLIM */
128397207482SJames Smart 	mb->un.varCfgPort.hps = 1;
128497207482SJames Smart 
1285ed957684SJames Smart 	/* If HBA supports SLI=3 ask for it */
1286ed957684SJames Smart 
128704c68496SJames Smart 	if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
1288e2a0a9d6SJames Smart 		if (phba->cfg_enable_bg)
1289e2a0a9d6SJames Smart 			mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
1290ab56dc2eSJames Smart 		if (phba->cfg_enable_dss)
129104c68496SJames Smart 			mb->un.varCfgPort.cdss = 1; /* Configure Security */
1292ed957684SJames Smart 		mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
129334b02dcdSJames Smart 		mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
129451ef4c26SJames Smart 		mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
129578b2d852SJames Smart 		if (phba->max_vpi && phba->cfg_enable_npiv &&
129692d7f7b0SJames Smart 		    phba->vpd.sli3Feat.cmv) {
129704c68496SJames Smart 			mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI;
129892d7f7b0SJames Smart 			mb->un.varCfgPort.cmv = 1;
129992d7f7b0SJames Smart 		} else
130092d7f7b0SJames Smart 			mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
130192d7f7b0SJames Smart 	} else
130204c68496SJames Smart 		phba->sli_rev = LPFC_SLI_REV2;
130392d7f7b0SJames Smart 	mb->un.varCfgPort.sli_mode = phba->sli_rev;
1304ed957684SJames Smart 
1305cb69f7deSJames Smart 	/* If this is an SLI3 port, configure async status notification. */
1306cb69f7deSJames Smart 	if (phba->sli_rev == LPFC_SLI_REV3)
1307cb69f7deSJames Smart 		mb->un.varCfgPort.casabt = 1;
1308cb69f7deSJames Smart 
1309dea3101eS 	/* Now setup pcb */
131034b02dcdSJames Smart 	phba->pcb->type = TYPE_NATIVE_SLI2;
131134b02dcdSJames Smart 	phba->pcb->feature = FEATURE_INITIAL_SLI2;
1312dea3101eS 
1313dea3101eS 	/* Setup Mailbox pointers */
13147a470277SJames Smart 	phba->pcb->mailBoxSize = sizeof(MAILBOX_t) + MAILBOX_EXT_SIZE;
131534b02dcdSJames Smart 	offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
131634b02dcdSJames Smart 	pdma_addr = phba->slim2p.phys + offset;
131734b02dcdSJames Smart 	phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
131834b02dcdSJames Smart 	phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
1319dea3101eS 
1320dea3101eS 	/*
1321dea3101eS 	 * Setup Host Group ring pointer.
1322dea3101eS 	 *
1323dea3101eS 	 * For efficiency reasons, the ring get/put pointers can be
1324dea3101eS 	 * placed in adapter memory (SLIM) rather than in host memory.
1325dea3101eS 	 * This allows firmware to avoid PCI reads/writes when updating
1326dea3101eS 	 * and checking pointers.
1327dea3101eS 	 *
1328dea3101eS 	 * The firmware recognizes the use of SLIM memory by comparing
1329dea3101eS 	 * the address of the get/put pointers structure with that of
1330dea3101eS 	 * the SLIM BAR (BAR0).
1331dea3101eS 	 *
1332dea3101eS 	 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1333dea3101eS 	 * (the hardware's view of the base address), not the OS's
1334dea3101eS 	 * value of pci_resource_start() as the OS value may be a cookie
1335dea3101eS 	 * for ioremap/iomap.
1336dea3101eS 	 */
1337dea3101eS 
1338dea3101eS 
1339dea3101eS 	pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
1340dea3101eS 	pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
1341dea3101eS 
1342ed957684SJames Smart 	/*
1343ed957684SJames Smart 	 * Set up HGP - Port Memory
1344ed957684SJames Smart 	 *
1345ed957684SJames Smart 	 * The port expects the host get/put pointers to reside in memory
1346ed957684SJames Smart 	 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1347ed957684SJames Smart 	 * area of SLIM.  In SLI-2 mode, there's an additional 16 reserved
1348ed957684SJames Smart 	 * words (0x40 bytes).  This area is not reserved if HBQs are
1349ed957684SJames Smart 	 * configured in SLI-3.
1350ed957684SJames Smart 	 *
1351ed957684SJames Smart 	 * CR0Put    - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1352ed957684SJames Smart 	 * RR0Get                      0xc4              0x84
1353ed957684SJames Smart 	 * CR1Put                      0xc8              0x88
1354ed957684SJames Smart 	 * RR1Get                      0xcc              0x8c
1355ed957684SJames Smart 	 * CR2Put                      0xd0              0x90
1356ed957684SJames Smart 	 * RR2Get                      0xd4              0x94
1357ed957684SJames Smart 	 * CR3Put                      0xd8              0x98
1358ed957684SJames Smart 	 * RR3Get                      0xdc              0x9c
1359ed957684SJames Smart 	 *
1360ed957684SJames Smart 	 * Reserved                    0xa0-0xbf
1361ed957684SJames Smart 	 *    If HBQs configured:
1362ed957684SJames Smart 	 *                         HBQ 0 Put ptr  0xc0
1363ed957684SJames Smart 	 *                         HBQ 1 Put ptr  0xc4
1364ed957684SJames Smart 	 *                         HBQ 2 Put ptr  0xc8
1365ed957684SJames Smart 	 *                         ......
1366ed957684SJames Smart 	 *                         HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1367ed957684SJames Smart 	 *
1368ed957684SJames Smart 	 */
1369ed957684SJames Smart 
13707a470277SJames Smart 	if (phba->cfg_hostmem_hgp && phba->sli_rev != 3) {
13717a470277SJames Smart 		phba->host_gp = &phba->mbox->us.s2.host[0];
13727a470277SJames Smart 		phba->hbq_put = NULL;
13737a470277SJames Smart 		offset = (uint8_t *)&phba->mbox->us.s2.host -
13747a470277SJames Smart 			(uint8_t *)phba->slim2p.virt;
13757a470277SJames Smart 		pdma_addr = phba->slim2p.phys + offset;
13767a470277SJames Smart 		phba->pcb->hgpAddrHigh = putPaddrHigh(pdma_addr);
13777a470277SJames Smart 		phba->pcb->hgpAddrLow = putPaddrLow(pdma_addr);
13787a470277SJames Smart 	} else {
13797a470277SJames Smart 		/* Always Host Group Pointer is in SLIM */
13807a470277SJames Smart 		mb->un.varCfgPort.hps = 1;
13817a470277SJames Smart 
1382ed957684SJames Smart 		if (phba->sli_rev == 3) {
1383ed957684SJames Smart 			phba->host_gp = &mb_slim->us.s3.host[0];
1384ed957684SJames Smart 			phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
1385ed957684SJames Smart 		} else {
1386ed957684SJames Smart 			phba->host_gp = &mb_slim->us.s2.host[0];
1387ed957684SJames Smart 			phba->hbq_put = NULL;
1388ed957684SJames Smart 		}
1389dea3101eS 
1390dea3101eS 		/* mask off BAR0's flag bits 0 - 3 */
139134b02dcdSJames Smart 		phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
1392ed957684SJames Smart 			(void __iomem *)phba->host_gp -
1393ed957684SJames Smart 			(void __iomem *)phba->MBslimaddr;
1394dea3101eS 		if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
139534b02dcdSJames Smart 			phba->pcb->hgpAddrHigh = bar_high;
1396dea3101eS 		else
139734b02dcdSJames Smart 			phba->pcb->hgpAddrHigh = 0;
1398dea3101eS 		/* write HGP data to SLIM at the required longword offset */
13994cc2da1dSJames.Smart@Emulex.Com 		memset(&hgp, 0, sizeof(struct lpfc_hgp));
1400f91b392cSJames.Smart@Emulex.Com 
1401f91b392cSJames.Smart@Emulex.Com 		for (i = 0; i < phba->sli.num_rings; i++) {
1402ed957684SJames Smart 			lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
1403ed957684SJames Smart 				    sizeof(*phba->host_gp));
1404f91b392cSJames.Smart@Emulex.Com 		}
14057a470277SJames Smart 	}
1406dea3101eS 
14078f34f4ceSJames Smart 	/* Setup Port Group offset */
14088f34f4ceSJames Smart 	if (phba->sli_rev == 3)
140934b02dcdSJames Smart 		pgp_offset = offsetof(struct lpfc_sli2_slim,
141034b02dcdSJames Smart 				      mbx.us.s3_pgp.port);
14118f34f4ceSJames Smart 	else
141234b02dcdSJames Smart 		pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
141334b02dcdSJames Smart 	pdma_addr = phba->slim2p.phys + pgp_offset;
141434b02dcdSJames Smart 	phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
141534b02dcdSJames Smart 	phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
1416dea3101eS 
1417dea3101eS 	/* Use callback routine to setp rings in the pcb */
1418dea3101eS 	lpfc_config_pcb_setup(phba);
1419dea3101eS 
1420dea3101eS 	/* special handling for LC HBAs */
1421dea3101eS 	if (lpfc_is_LC_HBA(phba->pcidev->device)) {
1422dea3101eS 		uint32_t hbainit[5];
1423dea3101eS 
1424dea3101eS 		lpfc_hba_init(phba, hbainit);
1425dea3101eS 
1426dea3101eS 		memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
1427dea3101eS 	}
1428dea3101eS 
1429dea3101eS 	/* Swap PCB if needed */
143034b02dcdSJames Smart 	lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
1431dea3101eS }
1432dea3101eS 
1433e59058c4SJames Smart /**
14343621a710SJames Smart  * lpfc_kill_board - Prepare a mailbox command for killing board
1435e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1436e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1437e59058c4SJames Smart  *
1438e59058c4SJames Smart  * The kill board mailbox command is used to tell firmware to perform a
1439e59058c4SJames Smart  * graceful shutdown of a channel on a specified board to prepare for reset.
1440e59058c4SJames Smart  * When the kill board mailbox command is received, the ER3 bit is set to 1
1441e59058c4SJames Smart  * in the Host Status register and the ER Attention bit is set to 1 in the
1442e59058c4SJames Smart  * Host Attention register of the HBA function that received the kill board
1443e59058c4SJames Smart  * command.
1444e59058c4SJames Smart  *
1445e59058c4SJames Smart  * This routine prepares the mailbox command for killing the board in
1446e59058c4SJames Smart  * preparation for a graceful shutdown.
1447e59058c4SJames Smart  **/
1448dea3101eS void
144941415862SJamie Wellnitz lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
145041415862SJamie Wellnitz {
145104c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
145241415862SJamie Wellnitz 
145341415862SJamie Wellnitz 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
145441415862SJamie Wellnitz 	mb->mbxCommand = MBX_KILL_BOARD;
145541415862SJamie Wellnitz 	mb->mbxOwner = OWN_HOST;
145641415862SJamie Wellnitz 	return;
145741415862SJamie Wellnitz }
145841415862SJamie Wellnitz 
1459e59058c4SJames Smart /**
14603621a710SJames Smart  * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
1461e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1462e59058c4SJames Smart  * @mbq: pointer to the driver internal queue element for mailbox command.
1463e59058c4SJames Smart  *
1464e59058c4SJames Smart  * Driver maintains a internal mailbox command queue implemented as a linked
1465e59058c4SJames Smart  * list. When a mailbox command is issued, it shall be put into the mailbox
1466e59058c4SJames Smart  * command queue such that they shall be processed orderly as HBA can process
1467e59058c4SJames Smart  * one mailbox command at a time.
1468e59058c4SJames Smart  **/
146941415862SJamie Wellnitz void
1470dea3101eS lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1471dea3101eS {
1472dea3101eS 	struct lpfc_sli *psli;
1473dea3101eS 
1474dea3101eS 	psli = &phba->sli;
1475dea3101eS 
1476dea3101eS 	list_add_tail(&mbq->list, &psli->mboxq);
1477dea3101eS 
1478dea3101eS 	psli->mboxq_cnt++;
1479dea3101eS 
1480dea3101eS 	return;
1481dea3101eS }
1482dea3101eS 
1483e59058c4SJames Smart /**
14843621a710SJames Smart  * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
1485e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1486e59058c4SJames Smart  *
1487e59058c4SJames Smart  * Driver maintains a internal mailbox command queue implemented as a linked
1488e59058c4SJames Smart  * list. When a mailbox command is issued, it shall be put into the mailbox
1489e59058c4SJames Smart  * command queue such that they shall be processed orderly as HBA can process
1490e59058c4SJames Smart  * one mailbox command at a time. After HBA finished processing a mailbox
1491e59058c4SJames Smart  * command, the driver will remove a pending mailbox command from the head of
1492e59058c4SJames Smart  * the mailbox command queue and send to the HBA for processing.
1493e59058c4SJames Smart  *
1494e59058c4SJames Smart  * Return codes
1495e59058c4SJames Smart  *    pointer to the driver internal queue element for mailbox command.
1496e59058c4SJames Smart  **/
1497dea3101eS LPFC_MBOXQ_t *
1498dea3101eS lpfc_mbox_get(struct lpfc_hba * phba)
1499dea3101eS {
1500dea3101eS 	LPFC_MBOXQ_t *mbq = NULL;
1501dea3101eS 	struct lpfc_sli *psli = &phba->sli;
1502dea3101eS 
15032e0fef85SJames Smart 	list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
150492d7f7b0SJames Smart 	if (mbq)
1505dea3101eS 		psli->mboxq_cnt--;
1506dea3101eS 
1507dea3101eS 	return mbq;
1508dea3101eS }
1509a309a6b6SJames Smart 
1510e59058c4SJames Smart /**
151104c68496SJames Smart  * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
151204c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
151304c68496SJames Smart  * @mbq: pointer to the driver internal queue element for mailbox command.
151404c68496SJames Smart  *
151504c68496SJames Smart  * This routine put the completed mailbox command into the mailbox command
151604c68496SJames Smart  * complete list. This is the unlocked version of the routine. The mailbox
151704c68496SJames Smart  * complete list is used by the driver worker thread to process mailbox
151804c68496SJames Smart  * complete callback functions outside the driver interrupt handler.
151904c68496SJames Smart  **/
152004c68496SJames Smart void
152104c68496SJames Smart __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
152204c68496SJames Smart {
152304c68496SJames Smart 	list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
152404c68496SJames Smart }
152504c68496SJames Smart 
152604c68496SJames Smart /**
15273621a710SJames Smart  * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
1528e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1529e59058c4SJames Smart  * @mbq: pointer to the driver internal queue element for mailbox command.
1530e59058c4SJames Smart  *
1531e59058c4SJames Smart  * This routine put the completed mailbox command into the mailbox command
153204c68496SJames Smart  * complete list. This is the locked version of the routine. The mailbox
153304c68496SJames Smart  * complete list is used by the driver worker thread to process mailbox
153404c68496SJames Smart  * complete callback functions outside the driver interrupt handler.
1535e59058c4SJames Smart  **/
153692d7f7b0SJames Smart void
153792d7f7b0SJames Smart lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
153892d7f7b0SJames Smart {
15395b75da2fSJames Smart 	unsigned long iflag;
15405b75da2fSJames Smart 
1541b1c11812SJoe Perches 	/* This function expects to be called from interrupt context */
15425b75da2fSJames Smart 	spin_lock_irqsave(&phba->hbalock, iflag);
154304c68496SJames Smart 	__lpfc_mbox_cmpl_put(phba, mbq);
15445b75da2fSJames Smart 	spin_unlock_irqrestore(&phba->hbalock, iflag);
154592d7f7b0SJames Smart 	return;
154692d7f7b0SJames Smart }
154792d7f7b0SJames Smart 
1548e59058c4SJames Smart /**
154904c68496SJames Smart  * lpfc_mbox_cmd_check - Check the validality of a mailbox command
155004c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
155104c68496SJames Smart  * @mboxq: pointer to the driver internal queue element for mailbox command.
155204c68496SJames Smart  *
155304c68496SJames Smart  * This routine is to check whether a mailbox command is valid to be issued.
155404c68496SJames Smart  * This check will be performed by both the mailbox issue API when a client
155504c68496SJames Smart  * is to issue a mailbox command to the mailbox transport.
155604c68496SJames Smart  *
155704c68496SJames Smart  * Return 0 - pass the check, -ENODEV - fail the check
155804c68496SJames Smart  **/
155904c68496SJames Smart int
156004c68496SJames Smart lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
156104c68496SJames Smart {
156204c68496SJames Smart 	/* Mailbox command that have a completion handler must also have a
156304c68496SJames Smart 	 * vport specified.
156404c68496SJames Smart 	 */
156504c68496SJames Smart 	if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
156604c68496SJames Smart 	    mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
156704c68496SJames Smart 		if (!mboxq->vport) {
156804c68496SJames Smart 			lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
156904c68496SJames Smart 					"1814 Mbox x%x failed, no vport\n",
157004c68496SJames Smart 					mboxq->u.mb.mbxCommand);
157104c68496SJames Smart 			dump_stack();
157204c68496SJames Smart 			return -ENODEV;
157304c68496SJames Smart 		}
157404c68496SJames Smart 	}
157504c68496SJames Smart 	return 0;
157604c68496SJames Smart }
157704c68496SJames Smart 
157804c68496SJames Smart /**
157904c68496SJames Smart  * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
158004c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
158104c68496SJames Smart  *
158204c68496SJames Smart  * This routine is to check whether the HBA device is ready for posting a
158304c68496SJames Smart  * mailbox command. It is used by the mailbox transport API at the time the
158404c68496SJames Smart  * to post a mailbox command to the device.
158504c68496SJames Smart  *
158604c68496SJames Smart  * Return 0 - pass the check, -ENODEV - fail the check
158704c68496SJames Smart  **/
158804c68496SJames Smart int
158904c68496SJames Smart lpfc_mbox_dev_check(struct lpfc_hba *phba)
159004c68496SJames Smart {
159104c68496SJames Smart 	/* If the PCI channel is in offline state, do not issue mbox */
159204c68496SJames Smart 	if (unlikely(pci_channel_offline(phba->pcidev)))
159304c68496SJames Smart 		return -ENODEV;
159404c68496SJames Smart 
159504c68496SJames Smart 	/* If the HBA is in error state, do not issue mbox */
159604c68496SJames Smart 	if (phba->link_state == LPFC_HBA_ERROR)
159704c68496SJames Smart 		return -ENODEV;
159804c68496SJames Smart 
159904c68496SJames Smart 	return 0;
160004c68496SJames Smart }
160104c68496SJames Smart 
160204c68496SJames Smart /**
16033621a710SJames Smart  * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
1604e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1605e59058c4SJames Smart  * @cmd: mailbox command code.
1606e59058c4SJames Smart  *
1607e59058c4SJames Smart  * This routine retrieves the proper timeout value according to the mailbox
1608e59058c4SJames Smart  * command code.
1609e59058c4SJames Smart  *
1610e59058c4SJames Smart  * Return codes
1611e59058c4SJames Smart  *    Timeout value to be used for the given mailbox command
1612e59058c4SJames Smart  **/
1613a309a6b6SJames Smart int
1614a183a15fSJames Smart lpfc_mbox_tmo_val(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1615a309a6b6SJames Smart {
1616a183a15fSJames Smart 	MAILBOX_t *mbox = &mboxq->u.mb;
1617a183a15fSJames Smart 	uint8_t subsys, opcode;
1618a183a15fSJames Smart 
1619a183a15fSJames Smart 	switch (mbox->mbxCommand) {
1620a309a6b6SJames Smart 	case MBX_WRITE_NV:	/* 0x03 */
1621940eb687SJames Smart 	case MBX_DUMP_MEMORY:	/* 0x17 */
1622a309a6b6SJames Smart 	case MBX_UPDATE_CFG:	/* 0x1B */
1623a309a6b6SJames Smart 	case MBX_DOWN_LOAD:	/* 0x1C */
1624a309a6b6SJames Smart 	case MBX_DEL_LD_ENTRY:	/* 0x1D */
1625940eb687SJames Smart 	case MBX_WRITE_VPARMS:	/* 0x32 */
1626a309a6b6SJames Smart 	case MBX_LOAD_AREA:	/* 0x81 */
162709372820SJames Smart 	case MBX_WRITE_WWN:     /* 0x98 */
1628a309a6b6SJames Smart 	case MBX_LOAD_EXP_ROM:	/* 0x9C */
1629940eb687SJames Smart 	case MBX_ACCESS_VDATA:	/* 0xA5 */
1630a309a6b6SJames Smart 		return LPFC_MBOX_TMO_FLASH_CMD;
163104c68496SJames Smart 	case MBX_SLI4_CONFIG:	/* 0x9b */
1632a183a15fSJames Smart 		subsys = lpfc_sli_config_mbox_subsys_get(phba, mboxq);
1633a183a15fSJames Smart 		opcode = lpfc_sli_config_mbox_opcode_get(phba, mboxq);
1634a183a15fSJames Smart 		if (subsys == LPFC_MBOX_SUBSYSTEM_COMMON) {
1635a183a15fSJames Smart 			switch (opcode) {
1636a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_READ_OBJECT:
1637a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_WRITE_OBJECT:
1638a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_READ_OBJECT_LIST:
1639a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_DELETE_OBJECT:
1640a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_GET_PROFILE_LIST:
1641a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_SET_ACT_PROFILE:
1642940eb687SJames Smart 			case LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG:
1643a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG:
1644a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG:
1645940eb687SJames Smart 			case LPFC_MBOX_OPCODE_GET_PROFILE_CAPACITIES:
1646940eb687SJames Smart 			case LPFC_MBOX_OPCODE_SEND_ACTIVATION:
1647940eb687SJames Smart 			case LPFC_MBOX_OPCODE_RESET_LICENSES:
1648940eb687SJames Smart 			case LPFC_MBOX_OPCODE_SET_BOOT_CONFIG:
1649940eb687SJames Smart 			case LPFC_MBOX_OPCODE_GET_VPD_DATA:
1650940eb687SJames Smart 			case LPFC_MBOX_OPCODE_SET_PHYSICAL_LINK_CONFIG:
1651a183a15fSJames Smart 				return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO;
1652a183a15fSJames Smart 			}
1653a183a15fSJames Smart 		}
1654a183a15fSJames Smart 		if (subsys == LPFC_MBOX_SUBSYSTEM_FCOE) {
1655a183a15fSJames Smart 			switch (opcode) {
1656a183a15fSJames Smart 			case LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS:
1657a183a15fSJames Smart 				return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO;
1658a183a15fSJames Smart 			}
1659a183a15fSJames Smart 		}
166004c68496SJames Smart 		return LPFC_MBOX_SLI4_CONFIG_TMO;
1661a309a6b6SJames Smart 	}
1662a309a6b6SJames Smart 	return LPFC_MBOX_TMO;
1663a309a6b6SJames Smart }
166404c68496SJames Smart 
166504c68496SJames Smart /**
166604c68496SJames Smart  * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
166704c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
166804c68496SJames Smart  * @sgentry: sge entry index.
166904c68496SJames Smart  * @phyaddr: physical address for the sge
167004c68496SJames Smart  * @length: Length of the sge.
167104c68496SJames Smart  *
167204c68496SJames Smart  * This routine sets up an entry in the non-embedded mailbox command at the sge
167304c68496SJames Smart  * index location.
167404c68496SJames Smart  **/
167504c68496SJames Smart void
167604c68496SJames Smart lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry,
167704c68496SJames Smart 		      dma_addr_t phyaddr, uint32_t length)
167804c68496SJames Smart {
167904c68496SJames Smart 	struct lpfc_mbx_nembed_cmd *nembed_sge;
168004c68496SJames Smart 
168104c68496SJames Smart 	nembed_sge = (struct lpfc_mbx_nembed_cmd *)
168204c68496SJames Smart 				&mbox->u.mqe.un.nembed_cmd;
168304c68496SJames Smart 	nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr);
168404c68496SJames Smart 	nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr);
168504c68496SJames Smart 	nembed_sge->sge[sgentry].length = length;
168604c68496SJames Smart }
168704c68496SJames Smart 
168804c68496SJames Smart /**
168904c68496SJames Smart  * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
169004c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
169104c68496SJames Smart  * @sgentry: sge entry index.
169204c68496SJames Smart  *
169304c68496SJames Smart  * This routine gets an entry from the non-embedded mailbox command at the sge
169404c68496SJames Smart  * index location.
169504c68496SJames Smart  **/
169604c68496SJames Smart void
169704c68496SJames Smart lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry,
169804c68496SJames Smart 		      struct lpfc_mbx_sge *sge)
169904c68496SJames Smart {
170004c68496SJames Smart 	struct lpfc_mbx_nembed_cmd *nembed_sge;
170104c68496SJames Smart 
170204c68496SJames Smart 	nembed_sge = (struct lpfc_mbx_nembed_cmd *)
170304c68496SJames Smart 				&mbox->u.mqe.un.nembed_cmd;
170404c68496SJames Smart 	sge->pa_lo = nembed_sge->sge[sgentry].pa_lo;
170504c68496SJames Smart 	sge->pa_hi = nembed_sge->sge[sgentry].pa_hi;
170604c68496SJames Smart 	sge->length = nembed_sge->sge[sgentry].length;
170704c68496SJames Smart }
170804c68496SJames Smart 
170904c68496SJames Smart /**
171004c68496SJames Smart  * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
171104c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
171204c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
171304c68496SJames Smart  *
171404c68496SJames Smart  * This routine frees SLI4 specific mailbox command for sending IOCTL command.
171504c68496SJames Smart  **/
171604c68496SJames Smart void
171704c68496SJames Smart lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
171804c68496SJames Smart {
171904c68496SJames Smart 	struct lpfc_mbx_sli4_config *sli4_cfg;
172004c68496SJames Smart 	struct lpfc_mbx_sge sge;
172104c68496SJames Smart 	dma_addr_t phyaddr;
172204c68496SJames Smart 	uint32_t sgecount, sgentry;
172304c68496SJames Smart 
172404c68496SJames Smart 	sli4_cfg = &mbox->u.mqe.un.sli4_config;
172504c68496SJames Smart 
172604c68496SJames Smart 	/* For embedded mbox command, just free the mbox command */
172704c68496SJames Smart 	if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
172804c68496SJames Smart 		mempool_free(mbox, phba->mbox_mem_pool);
172904c68496SJames Smart 		return;
173004c68496SJames Smart 	}
173104c68496SJames Smart 
173204c68496SJames Smart 	/* For non-embedded mbox command, we need to free the pages first */
173304c68496SJames Smart 	sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr);
173404c68496SJames Smart 	/* There is nothing we can do if there is no sge address array */
173504c68496SJames Smart 	if (unlikely(!mbox->sge_array)) {
173604c68496SJames Smart 		mempool_free(mbox, phba->mbox_mem_pool);
173704c68496SJames Smart 		return;
173804c68496SJames Smart 	}
173904c68496SJames Smart 	/* Each non-embedded DMA memory was allocated in the length of a page */
174004c68496SJames Smart 	for (sgentry = 0; sgentry < sgecount; sgentry++) {
174104c68496SJames Smart 		lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge);
174204c68496SJames Smart 		phyaddr = getPaddr(sge.pa_hi, sge.pa_lo);
174349198b37SJames Smart 		dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
174404c68496SJames Smart 				  mbox->sge_array->addr[sgentry], phyaddr);
174504c68496SJames Smart 	}
174604c68496SJames Smart 	/* Free the sge address array memory */
174704c68496SJames Smart 	kfree(mbox->sge_array);
174804c68496SJames Smart 	/* Finally, free the mailbox command itself */
174904c68496SJames Smart 	mempool_free(mbox, phba->mbox_mem_pool);
175004c68496SJames Smart }
175104c68496SJames Smart 
175204c68496SJames Smart /**
175304c68496SJames Smart  * lpfc_sli4_config - Initialize the  SLI4 Config Mailbox command
175404c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
175504c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
175604c68496SJames Smart  * @subsystem: The sli4 config sub mailbox subsystem.
175704c68496SJames Smart  * @opcode: The sli4 config sub mailbox command opcode.
1758fedd3b7bSJames Smart  * @length: Length of the sli4 config mailbox command (including sub-header).
175904c68496SJames Smart  *
176004c68496SJames Smart  * This routine sets up the header fields of SLI4 specific mailbox command
176104c68496SJames Smart  * for sending IOCTL command.
176204c68496SJames Smart  *
176304c68496SJames Smart  * Return: the actual length of the mbox command allocated (mostly useful
176404c68496SJames Smart  *         for none embedded mailbox command).
176504c68496SJames Smart  **/
176604c68496SJames Smart int
176704c68496SJames Smart lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
176804c68496SJames Smart 		 uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb)
176904c68496SJames Smart {
177004c68496SJames Smart 	struct lpfc_mbx_sli4_config *sli4_config;
177104c68496SJames Smart 	union lpfc_sli4_cfg_shdr *cfg_shdr = NULL;
177204c68496SJames Smart 	uint32_t alloc_len;
177304c68496SJames Smart 	uint32_t resid_len;
177404c68496SJames Smart 	uint32_t pagen, pcount;
177504c68496SJames Smart 	void *viraddr;
177604c68496SJames Smart 	dma_addr_t phyaddr;
177704c68496SJames Smart 
177804c68496SJames Smart 	/* Set up SLI4 mailbox command header fields */
177904c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
178004c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG);
178104c68496SJames Smart 
178204c68496SJames Smart 	/* Set up SLI4 ioctl command header fields */
178304c68496SJames Smart 	sli4_config = &mbox->u.mqe.un.sli4_config;
178404c68496SJames Smart 
178504c68496SJames Smart 	/* Setup for the embedded mbox command */
178604c68496SJames Smart 	if (emb) {
178704c68496SJames Smart 		/* Set up main header fields */
178804c68496SJames Smart 		bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
1789fedd3b7bSJames Smart 		sli4_config->header.cfg_mhdr.payload_length = length;
179004c68496SJames Smart 		/* Set up sub-header fields following main header */
179104c68496SJames Smart 		bf_set(lpfc_mbox_hdr_opcode,
179204c68496SJames Smart 			&sli4_config->header.cfg_shdr.request, opcode);
179304c68496SJames Smart 		bf_set(lpfc_mbox_hdr_subsystem,
179404c68496SJames Smart 			&sli4_config->header.cfg_shdr.request, subsystem);
1795fedd3b7bSJames Smart 		sli4_config->header.cfg_shdr.request.request_length =
1796fedd3b7bSJames Smart 			length - LPFC_MBX_CMD_HDR_LENGTH;
179704c68496SJames Smart 		return length;
179804c68496SJames Smart 	}
179904c68496SJames Smart 
18006d368e53SJames Smart 	/* Setup for the non-embedded mbox command */
18019589b062SJames Smart 	pcount = (SLI4_PAGE_ALIGN(length))/SLI4_PAGE_SIZE;
180204c68496SJames Smart 	pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ?
180304c68496SJames Smart 				LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount;
180404c68496SJames Smart 	/* Allocate record for keeping SGE virtual addresses */
18056d368e53SJames Smart 	mbox->sge_array = kzalloc(sizeof(struct lpfc_mbx_nembed_sge_virt),
180604c68496SJames Smart 				  GFP_KERNEL);
18076a9c52cfSJames Smart 	if (!mbox->sge_array) {
18086a9c52cfSJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
18096a9c52cfSJames Smart 				"2527 Failed to allocate non-embedded SGE "
18106a9c52cfSJames Smart 				"array.\n");
181104c68496SJames Smart 		return 0;
18126a9c52cfSJames Smart 	}
181304c68496SJames Smart 	for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) {
181404c68496SJames Smart 		/* The DMA memory is always allocated in the length of a
181504c68496SJames Smart 		 * page even though the last SGE might not fill up to a
181649198b37SJames Smart 		 * page, this is used as a priori size of SLI4_PAGE_SIZE for
181704c68496SJames Smart 		 * the later DMA memory free.
181804c68496SJames Smart 		 */
18191aee383dSJoe Perches 		viraddr = dma_zalloc_coherent(&phba->pcidev->dev,
18201aee383dSJoe Perches 					      SLI4_PAGE_SIZE, &phyaddr,
18211aee383dSJoe Perches 					      GFP_KERNEL);
182204c68496SJames Smart 		/* In case of malloc fails, proceed with whatever we have */
182304c68496SJames Smart 		if (!viraddr)
182404c68496SJames Smart 			break;
182504c68496SJames Smart 		mbox->sge_array->addr[pagen] = viraddr;
182604c68496SJames Smart 		/* Keep the first page for later sub-header construction */
182704c68496SJames Smart 		if (pagen == 0)
182804c68496SJames Smart 			cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr;
182904c68496SJames Smart 		resid_len = length - alloc_len;
183049198b37SJames Smart 		if (resid_len > SLI4_PAGE_SIZE) {
183104c68496SJames Smart 			lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
183249198b37SJames Smart 					      SLI4_PAGE_SIZE);
183349198b37SJames Smart 			alloc_len += SLI4_PAGE_SIZE;
183404c68496SJames Smart 		} else {
183504c68496SJames Smart 			lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
183604c68496SJames Smart 					      resid_len);
183704c68496SJames Smart 			alloc_len = length;
183804c68496SJames Smart 		}
183904c68496SJames Smart 	}
184004c68496SJames Smart 
184104c68496SJames Smart 	/* Set up main header fields in mailbox command */
184204c68496SJames Smart 	sli4_config->header.cfg_mhdr.payload_length = alloc_len;
184304c68496SJames Smart 	bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen);
184404c68496SJames Smart 
184504c68496SJames Smart 	/* Set up sub-header fields into the first page */
184604c68496SJames Smart 	if (pagen > 0) {
184704c68496SJames Smart 		bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode);
184804c68496SJames Smart 		bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem);
184904c68496SJames Smart 		cfg_shdr->request.request_length =
185004c68496SJames Smart 				alloc_len - sizeof(union  lpfc_sli4_cfg_shdr);
185104c68496SJames Smart 	}
185204c68496SJames Smart 	/* The sub-header is in DMA memory, which needs endian converstion */
185372100cc4SJames Smart 	if (cfg_shdr)
185404c68496SJames Smart 		lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
185504c68496SJames Smart 				      sizeof(union  lpfc_sli4_cfg_shdr));
185604c68496SJames Smart 	return alloc_len;
185704c68496SJames Smart }
185804c68496SJames Smart 
185904c68496SJames Smart /**
18606d368e53SJames Smart  * lpfc_sli4_mbox_rsrc_extent - Initialize the opcode resource extent.
18616d368e53SJames Smart  * @phba: pointer to lpfc hba data structure.
18626d368e53SJames Smart  * @mbox: pointer to an allocated lpfc mbox resource.
18636d368e53SJames Smart  * @exts_count: the number of extents, if required, to allocate.
18646d368e53SJames Smart  * @rsrc_type: the resource extent type.
18656d368e53SJames Smart  * @emb: true if LPFC_SLI4_MBX_EMBED. false if LPFC_SLI4_MBX_NEMBED.
18666d368e53SJames Smart  *
18676d368e53SJames Smart  * This routine completes the subcommand header for SLI4 resource extent
18686d368e53SJames Smart  * mailbox commands.  It is called after lpfc_sli4_config.  The caller must
18696d368e53SJames Smart  * pass an allocated mailbox and the attributes required to initialize the
18706d368e53SJames Smart  * mailbox correctly.
18716d368e53SJames Smart  *
18726d368e53SJames Smart  * Return: the actual length of the mbox command allocated.
18736d368e53SJames Smart  **/
18746d368e53SJames Smart int
18756d368e53SJames Smart lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
18766d368e53SJames Smart 			   uint16_t exts_count, uint16_t rsrc_type, bool emb)
18776d368e53SJames Smart {
18786d368e53SJames Smart 	uint8_t opcode = 0;
18796d368e53SJames Smart 	struct lpfc_mbx_nembed_rsrc_extent *n_rsrc_extnt = NULL;
18806d368e53SJames Smart 	void *virtaddr = NULL;
18816d368e53SJames Smart 
18826d368e53SJames Smart 	/* Set up SLI4 ioctl command header fields */
18836d368e53SJames Smart 	if (emb == LPFC_SLI4_MBX_NEMBED) {
18846d368e53SJames Smart 		/* Get the first SGE entry from the non-embedded DMA memory */
18856d368e53SJames Smart 		virtaddr = mbox->sge_array->addr[0];
18866d368e53SJames Smart 		if (virtaddr == NULL)
18876d368e53SJames Smart 			return 1;
18886d368e53SJames Smart 		n_rsrc_extnt = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
18896d368e53SJames Smart 	}
18906d368e53SJames Smart 
18916d368e53SJames Smart 	/*
18926d368e53SJames Smart 	 * The resource type is common to all extent Opcodes and resides in the
18936d368e53SJames Smart 	 * same position.
18946d368e53SJames Smart 	 */
18956d368e53SJames Smart 	if (emb == LPFC_SLI4_MBX_EMBED)
18966d368e53SJames Smart 		bf_set(lpfc_mbx_alloc_rsrc_extents_type,
18976d368e53SJames Smart 		       &mbox->u.mqe.un.alloc_rsrc_extents.u.req,
18986d368e53SJames Smart 		       rsrc_type);
18996d368e53SJames Smart 	else {
19006d368e53SJames Smart 		/* This is DMA data.  Byteswap is required. */
19016d368e53SJames Smart 		bf_set(lpfc_mbx_alloc_rsrc_extents_type,
19026d368e53SJames Smart 		       n_rsrc_extnt, rsrc_type);
19036d368e53SJames Smart 		lpfc_sli_pcimem_bcopy(&n_rsrc_extnt->word4,
19046d368e53SJames Smart 				      &n_rsrc_extnt->word4,
19056d368e53SJames Smart 				      sizeof(uint32_t));
19066d368e53SJames Smart 	}
19076d368e53SJames Smart 
19086d368e53SJames Smart 	/* Complete the initialization for the particular Opcode. */
1909a183a15fSJames Smart 	opcode = lpfc_sli_config_mbox_opcode_get(phba, mbox);
19106d368e53SJames Smart 	switch (opcode) {
19116d368e53SJames Smart 	case LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT:
19126d368e53SJames Smart 		if (emb == LPFC_SLI4_MBX_EMBED)
19136d368e53SJames Smart 			bf_set(lpfc_mbx_alloc_rsrc_extents_cnt,
19146d368e53SJames Smart 			       &mbox->u.mqe.un.alloc_rsrc_extents.u.req,
19156d368e53SJames Smart 			       exts_count);
19166d368e53SJames Smart 		else
19176d368e53SJames Smart 			bf_set(lpfc_mbx_alloc_rsrc_extents_cnt,
19186d368e53SJames Smart 			       n_rsrc_extnt, exts_count);
19196d368e53SJames Smart 		break;
19206d368e53SJames Smart 	case LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT:
19216d368e53SJames Smart 	case LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO:
19226d368e53SJames Smart 	case LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT:
19236d368e53SJames Smart 		/* Initialization is complete.*/
19246d368e53SJames Smart 		break;
19256d368e53SJames Smart 	default:
19266d368e53SJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
19276d368e53SJames Smart 				"2929 Resource Extent Opcode x%x is "
19286d368e53SJames Smart 				"unsupported\n", opcode);
19296d368e53SJames Smart 		return 1;
19306d368e53SJames Smart 	}
19316d368e53SJames Smart 
19326d368e53SJames Smart 	return 0;
19336d368e53SJames Smart }
19346d368e53SJames Smart 
19356d368e53SJames Smart /**
1936a183a15fSJames Smart  * lpfc_sli_config_mbox_subsys_get - Get subsystem from a sli_config mbox cmd
193704c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
1938a183a15fSJames Smart  * @mbox: pointer to lpfc mbox command queue entry.
193904c68496SJames Smart  *
1940a183a15fSJames Smart  * This routine gets the subsystem from a SLI4 specific SLI_CONFIG mailbox
1941a183a15fSJames Smart  * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if the
1942a183a15fSJames Smart  * sub-header is not present, subsystem LPFC_MBOX_SUBSYSTEM_NA (0x0) shall
1943a183a15fSJames Smart  * be returned.
194404c68496SJames Smart  **/
194504c68496SJames Smart uint8_t
1946a183a15fSJames Smart lpfc_sli_config_mbox_subsys_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
194704c68496SJames Smart {
194804c68496SJames Smart 	struct lpfc_mbx_sli4_config *sli4_cfg;
194904c68496SJames Smart 	union lpfc_sli4_cfg_shdr *cfg_shdr;
195004c68496SJames Smart 
195104c68496SJames Smart 	if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
1952a183a15fSJames Smart 		return LPFC_MBOX_SUBSYSTEM_NA;
1953a183a15fSJames Smart 	sli4_cfg = &mbox->u.mqe.un.sli4_config;
1954a183a15fSJames Smart 
1955a183a15fSJames Smart 	/* For embedded mbox command, get opcode from embedded sub-header*/
1956a183a15fSJames Smart 	if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1957a183a15fSJames Smart 		cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
1958a183a15fSJames Smart 		return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request);
1959a183a15fSJames Smart 	}
1960a183a15fSJames Smart 
1961a183a15fSJames Smart 	/* For non-embedded mbox command, get opcode from first dma page */
1962a183a15fSJames Smart 	if (unlikely(!mbox->sge_array))
1963a183a15fSJames Smart 		return LPFC_MBOX_SUBSYSTEM_NA;
1964a183a15fSJames Smart 	cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
1965a183a15fSJames Smart 	return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request);
1966a183a15fSJames Smart }
1967a183a15fSJames Smart 
1968a183a15fSJames Smart /**
1969a183a15fSJames Smart  * lpfc_sli_config_mbox_opcode_get - Get opcode from a sli_config mbox cmd
1970a183a15fSJames Smart  * @phba: pointer to lpfc hba data structure.
1971a183a15fSJames Smart  * @mbox: pointer to lpfc mbox command queue entry.
1972a183a15fSJames Smart  *
1973a183a15fSJames Smart  * This routine gets the opcode from a SLI4 specific SLI_CONFIG mailbox
1974a183a15fSJames Smart  * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if
1975a183a15fSJames Smart  * the sub-header is not present, opcode LPFC_MBOX_OPCODE_NA (0x0) be
1976a183a15fSJames Smart  * returned.
1977a183a15fSJames Smart  **/
1978a183a15fSJames Smart uint8_t
1979a183a15fSJames Smart lpfc_sli_config_mbox_opcode_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
1980a183a15fSJames Smart {
1981a183a15fSJames Smart 	struct lpfc_mbx_sli4_config *sli4_cfg;
1982a183a15fSJames Smart 	union lpfc_sli4_cfg_shdr *cfg_shdr;
1983a183a15fSJames Smart 
1984a183a15fSJames Smart 	if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
1985a183a15fSJames Smart 		return LPFC_MBOX_OPCODE_NA;
198604c68496SJames Smart 	sli4_cfg = &mbox->u.mqe.un.sli4_config;
198704c68496SJames Smart 
198804c68496SJames Smart 	/* For embedded mbox command, get opcode from embedded sub-header*/
198904c68496SJames Smart 	if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
199004c68496SJames Smart 		cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
199104c68496SJames Smart 		return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
199204c68496SJames Smart 	}
199304c68496SJames Smart 
199404c68496SJames Smart 	/* For non-embedded mbox command, get opcode from first dma page */
199504c68496SJames Smart 	if (unlikely(!mbox->sge_array))
1996a183a15fSJames Smart 		return LPFC_MBOX_OPCODE_NA;
199704c68496SJames Smart 	cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
199804c68496SJames Smart 	return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
199904c68496SJames Smart }
200004c68496SJames Smart 
200104c68496SJames Smart /**
20020c9ab6f5SJames Smart  * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd
2003ecfd03c6SJames Smart  * @phba: pointer to lpfc hba data structure.
2004ecfd03c6SJames Smart  * @fcf_index: index to fcf table.
2005ecfd03c6SJames Smart  *
2006ecfd03c6SJames Smart  * This routine routine allocates and constructs non-embedded mailbox command
200725985edcSLucas De Marchi  * for reading a FCF table entry referred by @fcf_index.
2008ecfd03c6SJames Smart  *
2009ecfd03c6SJames Smart  * Return: pointer to the mailbox command constructed if successful, otherwise
2010ecfd03c6SJames Smart  * NULL.
2011ecfd03c6SJames Smart  **/
2012ecfd03c6SJames Smart int
20130c9ab6f5SJames Smart lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *phba,
2014ecfd03c6SJames Smart 			   struct lpfcMboxq *mboxq,
2015ecfd03c6SJames Smart 			   uint16_t fcf_index)
2016ecfd03c6SJames Smart {
2017ecfd03c6SJames Smart 	void *virt_addr;
2018ecfd03c6SJames Smart 	uint8_t *bytep;
2019ecfd03c6SJames Smart 	struct lpfc_mbx_sge sge;
2020ecfd03c6SJames Smart 	uint32_t alloc_len, req_len;
2021ecfd03c6SJames Smart 	struct lpfc_mbx_read_fcf_tbl *read_fcf;
2022ecfd03c6SJames Smart 
2023ecfd03c6SJames Smart 	if (!mboxq)
2024ecfd03c6SJames Smart 		return -ENOMEM;
2025ecfd03c6SJames Smart 
2026ecfd03c6SJames Smart 	req_len = sizeof(struct fcf_record) +
2027ecfd03c6SJames Smart 		  sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
2028ecfd03c6SJames Smart 
2029ecfd03c6SJames Smart 	/* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
2030ecfd03c6SJames Smart 	alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
2031ecfd03c6SJames Smart 			LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
2032ecfd03c6SJames Smart 			LPFC_SLI4_MBX_NEMBED);
2033ecfd03c6SJames Smart 
2034ecfd03c6SJames Smart 	if (alloc_len < req_len) {
2035ecfd03c6SJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2036ecfd03c6SJames Smart 				"0291 Allocated DMA memory size (x%x) is "
2037ecfd03c6SJames Smart 				"less than the requested DMA memory "
2038ecfd03c6SJames Smart 				"size (x%x)\n", alloc_len, req_len);
2039ecfd03c6SJames Smart 		return -ENOMEM;
2040ecfd03c6SJames Smart 	}
2041ecfd03c6SJames Smart 
2042ecfd03c6SJames Smart 	/* Get the first SGE entry from the non-embedded DMA memory. This
2043ecfd03c6SJames Smart 	 * routine only uses a single SGE.
2044ecfd03c6SJames Smart 	 */
2045ecfd03c6SJames Smart 	lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
2046ecfd03c6SJames Smart 	virt_addr = mboxq->sge_array->addr[0];
2047ecfd03c6SJames Smart 	read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
2048ecfd03c6SJames Smart 
2049ecfd03c6SJames Smart 	/* Set up command fields */
2050ecfd03c6SJames Smart 	bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
2051ecfd03c6SJames Smart 	/* Perform necessary endian conversion */
2052ecfd03c6SJames Smart 	bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
2053ecfd03c6SJames Smart 	lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
2054ecfd03c6SJames Smart 
2055ecfd03c6SJames Smart 	return 0;
2056ecfd03c6SJames Smart }
2057ecfd03c6SJames Smart 
2058ecfd03c6SJames Smart /**
205904c68496SJames Smart  * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
206004c68496SJames Smart  * @mboxq: pointer to lpfc mbox command.
206104c68496SJames Smart  *
206204c68496SJames Smart  * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
206304c68496SJames Smart  * mailbox command.
206404c68496SJames Smart  **/
206504c68496SJames Smart void
206604c68496SJames Smart lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
206704c68496SJames Smart {
206804c68496SJames Smart 	/* Set up SLI4 mailbox command header fields */
206904c68496SJames Smart 	memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
207004c68496SJames Smart 	bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS);
207104c68496SJames Smart 
207204c68496SJames Smart 	/* Set up host requested features. */
207304c68496SJames Smart 	bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
2074fedd3b7bSJames Smart 	bf_set(lpfc_mbx_rq_ftr_rq_perfh, &mboxq->u.mqe.un.req_ftrs, 1);
207504c68496SJames Smart 
207604c68496SJames Smart 	/* Enable DIF (block guard) only if configured to do so. */
207704c68496SJames Smart 	if (phba->cfg_enable_bg)
207804c68496SJames Smart 		bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1);
207904c68496SJames Smart 
208004c68496SJames Smart 	/* Enable NPIV only if configured to do so. */
208104c68496SJames Smart 	if (phba->max_vpi && phba->cfg_enable_npiv)
208204c68496SJames Smart 		bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1);
208304c68496SJames Smart 
208404c68496SJames Smart 	return;
208504c68496SJames Smart }
208604c68496SJames Smart 
208704c68496SJames Smart /**
208804c68496SJames Smart  * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
208904c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
209004c68496SJames Smart  * @vport: Vport associated with the VF.
209104c68496SJames Smart  *
209204c68496SJames Smart  * This routine initializes @mbox to all zeros and then fills in the mailbox
209304c68496SJames Smart  * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
209404c68496SJames Smart  * in the context of an FCF. The driver issues this command to setup a VFI
209504c68496SJames Smart  * before issuing a FLOGI to login to the VSAN. The driver should also issue a
209604c68496SJames Smart  * REG_VFI after a successful VSAN login.
209704c68496SJames Smart  **/
209804c68496SJames Smart void
209904c68496SJames Smart lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
210004c68496SJames Smart {
210104c68496SJames Smart 	struct lpfc_mbx_init_vfi *init_vfi;
210204c68496SJames Smart 
210304c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
210476a95d75SJames Smart 	mbox->vport = vport;
210504c68496SJames Smart 	init_vfi = &mbox->u.mqe.un.init_vfi;
210604c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI);
210704c68496SJames Smart 	bf_set(lpfc_init_vfi_vr, init_vfi, 1);
210804c68496SJames Smart 	bf_set(lpfc_init_vfi_vt, init_vfi, 1);
210976a95d75SJames Smart 	bf_set(lpfc_init_vfi_vp, init_vfi, 1);
21106d368e53SJames Smart 	bf_set(lpfc_init_vfi_vfi, init_vfi,
21116d368e53SJames Smart 	       vport->phba->sli4_hba.vfi_ids[vport->vfi]);
21127851fe2cSJames Smart 	bf_set(lpfc_init_vfi_vpi, init_vfi,
21136d368e53SJames Smart 	       vport->phba->vpi_ids[vport->vpi]);
21146d368e53SJames Smart 	bf_set(lpfc_init_vfi_fcfi, init_vfi,
21156d368e53SJames Smart 	       vport->phba->fcf.fcfi);
211604c68496SJames Smart }
211704c68496SJames Smart 
211804c68496SJames Smart /**
211904c68496SJames Smart  * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
212004c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
212104c68496SJames Smart  * @vport: vport associated with the VF.
212204c68496SJames Smart  * @phys: BDE DMA bus address used to send the service parameters to the HBA.
212304c68496SJames Smart  *
212404c68496SJames Smart  * This routine initializes @mbox to all zeros and then fills in the mailbox
212504c68496SJames Smart  * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
212604c68496SJames Smart  * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
212704c68496SJames Smart  * fabrics identified by VFI in the context of an FCF.
212804c68496SJames Smart  **/
212904c68496SJames Smart void
213004c68496SJames Smart lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys)
213104c68496SJames Smart {
213204c68496SJames Smart 	struct lpfc_mbx_reg_vfi *reg_vfi;
2133ae05ebe3SJames Smart 	struct lpfc_hba *phba = vport->phba;
213404c68496SJames Smart 
213504c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
213604c68496SJames Smart 	reg_vfi = &mbox->u.mqe.un.reg_vfi;
213704c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI);
213804c68496SJames Smart 	bf_set(lpfc_reg_vfi_vp, reg_vfi, 1);
21396d368e53SJames Smart 	bf_set(lpfc_reg_vfi_vfi, reg_vfi,
2140ae05ebe3SJames Smart 	       phba->sli4_hba.vfi_ids[vport->vfi]);
2141ae05ebe3SJames Smart 	bf_set(lpfc_reg_vfi_fcfi, reg_vfi, phba->fcf.fcfi);
2142ae05ebe3SJames Smart 	bf_set(lpfc_reg_vfi_vpi, reg_vfi, phba->vpi_ids[vport->vpi]);
2143c868595dSJames Smart 	memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name));
2144c868595dSJames Smart 	reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]);
2145c868595dSJames Smart 	reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]);
2146ae05ebe3SJames Smart 	reg_vfi->e_d_tov = phba->fc_edtov;
2147ae05ebe3SJames Smart 	reg_vfi->r_a_tov = phba->fc_ratov;
214804c68496SJames Smart 	reg_vfi->bde.addrHigh = putPaddrHigh(phys);
214904c68496SJames Smart 	reg_vfi->bde.addrLow = putPaddrLow(phys);
215004c68496SJames Smart 	reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam);
215104c68496SJames Smart 	reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
215204c68496SJames Smart 	bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID);
2153ae05ebe3SJames Smart 
2154ae05ebe3SJames Smart 	/* Only FC supports upd bit */
2155ae05ebe3SJames Smart 	if ((phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) &&
2156e74c03c8SJames Smart 	    (vport->fc_flag & FC_VFI_REGISTERED) &&
2157e74c03c8SJames Smart 	    (!phba->fc_topology_changed)) {
2158ae05ebe3SJames Smart 		bf_set(lpfc_reg_vfi_vp, reg_vfi, 0);
2159ae05ebe3SJames Smart 		bf_set(lpfc_reg_vfi_upd, reg_vfi, 1);
2160ae05ebe3SJames Smart 	}
21611b51197dSJames Smart 	lpfc_printf_vlog(vport, KERN_INFO, LOG_MBOX,
21621b51197dSJames Smart 			"3134 Register VFI, mydid:x%x, fcfi:%d, "
2163e74c03c8SJames Smart 			" vfi:%d, vpi:%d, fc_pname:%x%x fc_flag:x%x"
2164e74c03c8SJames Smart 			" port_state:x%x topology chg:%d\n",
21651b51197dSJames Smart 			vport->fc_myDID,
2166ae05ebe3SJames Smart 			phba->fcf.fcfi,
2167ae05ebe3SJames Smart 			phba->sli4_hba.vfi_ids[vport->vfi],
2168ae05ebe3SJames Smart 			phba->vpi_ids[vport->vpi],
2169e74c03c8SJames Smart 			reg_vfi->wwn[0], reg_vfi->wwn[1], vport->fc_flag,
2170e74c03c8SJames Smart 			vport->port_state, phba->fc_topology_changed);
217104c68496SJames Smart }
217204c68496SJames Smart 
217304c68496SJames Smart /**
217404c68496SJames Smart  * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
21751c6834a7SJames Smart  * @phba: pointer to the hba structure to init the VPI for.
217604c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
217704c68496SJames Smart  * @vpi: VPI to be initialized.
217804c68496SJames Smart  *
217904c68496SJames Smart  * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
218004c68496SJames Smart  * command to activate a virtual N_Port. The HBA assigns a MAC address to use
218104c68496SJames Smart  * with the virtual N Port.  The SLI Host issues this command before issuing a
218204c68496SJames Smart  * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
218304c68496SJames Smart  * successful virtual NPort login.
218404c68496SJames Smart  **/
218504c68496SJames Smart void
21861c6834a7SJames Smart lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi)
218704c68496SJames Smart {
218804c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
218904c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI);
21901c6834a7SJames Smart 	bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi,
21916d368e53SJames Smart 	       phba->vpi_ids[vpi]);
21921c6834a7SJames Smart 	bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi,
21936d368e53SJames Smart 	       phba->sli4_hba.vfi_ids[phba->pport->vfi]);
219404c68496SJames Smart }
219504c68496SJames Smart 
219604c68496SJames Smart /**
219704c68496SJames Smart  * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
219804c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
21996669f9bbSJames Smart  * @vport: vport associated with the VF.
220004c68496SJames Smart  *
220104c68496SJames Smart  * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
220204c68496SJames Smart  * (logical NPort) into the inactive state. The SLI Host must have logged out
220304c68496SJames Smart  * and unregistered all remote N_Ports to abort any activity on the virtual
220404c68496SJames Smart  * fabric. The SLI Port posts the mailbox response after marking the virtual
220504c68496SJames Smart  * fabric inactive.
220604c68496SJames Smart  **/
220704c68496SJames Smart void
22086669f9bbSJames Smart lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
220904c68496SJames Smart {
221004c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
221104c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI);
22126669f9bbSJames Smart 	bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi,
22136d368e53SJames Smart 	       vport->phba->sli4_hba.vfi_ids[vport->vfi]);
221404c68496SJames Smart }
221504c68496SJames Smart 
221604c68496SJames Smart /**
2217026abb87SJames Smart  * lpfc_sli4_dump_cfg_rg23 - Dump sli4 port config region 23
221804c68496SJames Smart  * @phba: pointer to the hba structure containing.
221904c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
222004c68496SJames Smart  *
2221026abb87SJames Smart  * This function create a SLI4 dump mailbox command to dump configure
2222026abb87SJames Smart  * region 23.
222304c68496SJames Smart  **/
222404c68496SJames Smart int
2225026abb87SJames Smart lpfc_sli4_dump_cfg_rg23(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
222604c68496SJames Smart {
222704c68496SJames Smart 	struct lpfc_dmabuf *mp = NULL;
222804c68496SJames Smart 	MAILBOX_t *mb;
222904c68496SJames Smart 
223004c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
223104c68496SJames Smart 	mb = &mbox->u.mb;
223204c68496SJames Smart 
223304c68496SJames Smart 	mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
223404c68496SJames Smart 	if (mp)
223504c68496SJames Smart 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
223604c68496SJames Smart 
223704c68496SJames Smart 	if (!mp || !mp->virt) {
223804c68496SJames Smart 		kfree(mp);
2239026abb87SJames Smart 		/* dump config region 23 failed to allocate memory */
224004c68496SJames Smart 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
2241026abb87SJames Smart 			"2569 lpfc dump config region 23: memory"
224204c68496SJames Smart 			" allocation failed\n");
224304c68496SJames Smart 		return 1;
224404c68496SJames Smart 	}
224504c68496SJames Smart 
224604c68496SJames Smart 	memset(mp->virt, 0, LPFC_BPL_SIZE);
224704c68496SJames Smart 	INIT_LIST_HEAD(&mp->list);
224804c68496SJames Smart 
224904c68496SJames Smart 	/* save address for completion */
225004c68496SJames Smart 	mbox->context1 = (uint8_t *) mp;
225104c68496SJames Smart 
225204c68496SJames Smart 	mb->mbxCommand = MBX_DUMP_MEMORY;
225304c68496SJames Smart 	mb->un.varDmp.type = DMP_NV_PARAMS;
2254a0c87cbdSJames Smart 	mb->un.varDmp.region_id = DMP_REGION_23;
2255a0c87cbdSJames Smart 	mb->un.varDmp.sli4_length = DMP_RGN23_SIZE;
225604c68496SJames Smart 	mb->un.varWords[3] = putPaddrLow(mp->phys);
225704c68496SJames Smart 	mb->un.varWords[4] = putPaddrHigh(mp->phys);
225804c68496SJames Smart 	return 0;
225904c68496SJames Smart }
226004c68496SJames Smart 
226186478875SJames Smart void
226286478875SJames Smart lpfc_mbx_cmpl_rdp_link_stat(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
226386478875SJames Smart {
226486478875SJames Smart 	MAILBOX_t *mb;
226586478875SJames Smart 	int rc = FAILURE;
226686478875SJames Smart 	struct lpfc_rdp_context *rdp_context =
226786478875SJames Smart 			(struct lpfc_rdp_context *)(mboxq->context2);
226886478875SJames Smart 
226986478875SJames Smart 	mb = &mboxq->u.mb;
227086478875SJames Smart 	if (mb->mbxStatus)
227186478875SJames Smart 		goto mbx_failed;
227286478875SJames Smart 
227386478875SJames Smart 	memcpy(&rdp_context->link_stat, &mb->un.varRdLnk, sizeof(READ_LNK_VAR));
227486478875SJames Smart 
227586478875SJames Smart 	rc = SUCCESS;
227686478875SJames Smart 
227786478875SJames Smart mbx_failed:
227886478875SJames Smart 	lpfc_sli4_mbox_cmd_free(phba, mboxq);
227986478875SJames Smart 	rdp_context->cmpl(phba, rdp_context, rc);
228086478875SJames Smart }
228186478875SJames Smart 
228286478875SJames Smart void
228386478875SJames Smart lpfc_mbx_cmpl_rdp_page_a2(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
228486478875SJames Smart {
228586478875SJames Smart 	struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) mbox->context1;
228686478875SJames Smart 	struct lpfc_rdp_context *rdp_context =
228786478875SJames Smart 			(struct lpfc_rdp_context *)(mbox->context2);
228886478875SJames Smart 
228986478875SJames Smart 	if (bf_get(lpfc_mqe_status, &mbox->u.mqe))
2290612872caSJohannes Thumshirn 		goto error_mbuf_free;
229186478875SJames Smart 
229286478875SJames Smart 	lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a2,
229386478875SJames Smart 				DMP_SFF_PAGE_A2_SIZE);
229486478875SJames Smart 
229586478875SJames Smart 	/* We don't need dma buffer for link stat. */
229686478875SJames Smart 	lpfc_mbuf_free(phba, mp->virt, mp->phys);
229786478875SJames Smart 	kfree(mp);
229886478875SJames Smart 
229986478875SJames Smart 	memset(mbox, 0, sizeof(*mbox));
230086478875SJames Smart 	lpfc_read_lnk_stat(phba, mbox);
230186478875SJames Smart 	mbox->vport = rdp_context->ndlp->vport;
230286478875SJames Smart 	mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_link_stat;
230386478875SJames Smart 	mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
230486478875SJames Smart 	if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == MBX_NOT_FINISHED)
2305612872caSJohannes Thumshirn 		goto error_cmd_free;
230686478875SJames Smart 
230786478875SJames Smart 	return;
230886478875SJames Smart 
2309612872caSJohannes Thumshirn error_mbuf_free:
231086478875SJames Smart 	lpfc_mbuf_free(phba, mp->virt, mp->phys);
231186478875SJames Smart 	kfree(mp);
2312612872caSJohannes Thumshirn error_cmd_free:
231386478875SJames Smart 	lpfc_sli4_mbox_cmd_free(phba, mbox);
231486478875SJames Smart 	rdp_context->cmpl(phba, rdp_context, FAILURE);
231586478875SJames Smart }
231686478875SJames Smart 
231786478875SJames Smart void
231886478875SJames Smart lpfc_mbx_cmpl_rdp_page_a0(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
231986478875SJames Smart {
232086478875SJames Smart 	int rc;
232186478875SJames Smart 	struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (mbox->context1);
232286478875SJames Smart 	struct lpfc_rdp_context *rdp_context =
232386478875SJames Smart 			(struct lpfc_rdp_context *)(mbox->context2);
232486478875SJames Smart 
232586478875SJames Smart 	if (bf_get(lpfc_mqe_status, &mbox->u.mqe))
232686478875SJames Smart 		goto error;
232786478875SJames Smart 
232886478875SJames Smart 	lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a0,
232986478875SJames Smart 				DMP_SFF_PAGE_A0_SIZE);
233086478875SJames Smart 
233186478875SJames Smart 	memset(mbox, 0, sizeof(*mbox));
233286478875SJames Smart 
233386478875SJames Smart 	memset(mp->virt, 0, DMP_SFF_PAGE_A2_SIZE);
233486478875SJames Smart 	INIT_LIST_HEAD(&mp->list);
233586478875SJames Smart 
233686478875SJames Smart 	/* save address for completion */
233786478875SJames Smart 	mbox->context1 = mp;
233886478875SJames Smart 	mbox->vport = rdp_context->ndlp->vport;
233986478875SJames Smart 
234086478875SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY);
234186478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_type,
234286478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, DMP_LMSD);
234386478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_link,
234486478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port);
234586478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_page_no,
234686478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A2);
234786478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_length,
234886478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A2_SIZE);
234986478875SJames Smart 	mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
235086478875SJames Smart 	mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
235186478875SJames Smart 
235286478875SJames Smart 	mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a2;
235386478875SJames Smart 	mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
235486478875SJames Smart 	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
235586478875SJames Smart 	if (rc == MBX_NOT_FINISHED)
235686478875SJames Smart 		goto error;
235786478875SJames Smart 
235886478875SJames Smart 	return;
235986478875SJames Smart 
236086478875SJames Smart error:
236186478875SJames Smart 	lpfc_mbuf_free(phba, mp->virt, mp->phys);
236286478875SJames Smart 	kfree(mp);
236386478875SJames Smart 	lpfc_sli4_mbox_cmd_free(phba, mbox);
236486478875SJames Smart 	rdp_context->cmpl(phba, rdp_context, FAILURE);
236586478875SJames Smart }
236686478875SJames Smart 
236786478875SJames Smart 
236886478875SJames Smart /*
236986478875SJames Smart  * lpfc_sli4_dump_sfp_pagea0 - Dump sli4 read SFP Diagnostic.
237086478875SJames Smart  * @phba: pointer to the hba structure containing.
237186478875SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
237286478875SJames Smart  *
237386478875SJames Smart  * This function create a SLI4 dump mailbox command to dump configure
237486478875SJames Smart  * type 3 page 0xA0.
237586478875SJames Smart  */
237686478875SJames Smart int
237786478875SJames Smart lpfc_sli4_dump_page_a0(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
237886478875SJames Smart {
237986478875SJames Smart 	struct lpfc_dmabuf *mp = NULL;
238086478875SJames Smart 
238186478875SJames Smart 	memset(mbox, 0, sizeof(*mbox));
238286478875SJames Smart 
238386478875SJames Smart 	mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
238486478875SJames Smart 	if (mp)
238586478875SJames Smart 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
238686478875SJames Smart 	if (!mp || !mp->virt) {
238786478875SJames Smart 		kfree(mp);
238886478875SJames Smart 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
238986478875SJames Smart 			"3569 dump type 3 page 0xA0 allocation failed\n");
239086478875SJames Smart 		return 1;
239186478875SJames Smart 	}
239286478875SJames Smart 
239386478875SJames Smart 	memset(mp->virt, 0, LPFC_BPL_SIZE);
239486478875SJames Smart 	INIT_LIST_HEAD(&mp->list);
239586478875SJames Smart 
239686478875SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY);
239786478875SJames Smart 	/* save address for completion */
239886478875SJames Smart 	mbox->context1 = mp;
239986478875SJames Smart 
240086478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_type,
240186478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, DMP_LMSD);
240286478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_link,
240386478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port);
240486478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_page_no,
240586478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A0);
240686478875SJames Smart 	bf_set(lpfc_mbx_memory_dump_type3_length,
240786478875SJames Smart 		&mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A0_SIZE);
240886478875SJames Smart 	mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
240986478875SJames Smart 	mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
241086478875SJames Smart 
241186478875SJames Smart 	return 0;
241286478875SJames Smart }
241386478875SJames Smart 
241404c68496SJames Smart /**
241504c68496SJames Smart  * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
241604c68496SJames Smart  * @phba: pointer to the hba structure containing the FCF index and RQ ID.
241704c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
241804c68496SJames Smart  *
241904c68496SJames Smart  * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
242004c68496SJames Smart  * SLI Host uses the command to activate an FCF after it has acquired FCF
242104c68496SJames Smart  * information via a READ_FCF mailbox command. This mailbox command also is used
242204c68496SJames Smart  * to indicate where received unsolicited frames from this FCF will be sent. By
242304c68496SJames Smart  * default this routine will set up the FCF to forward all unsolicited frames
242404c68496SJames Smart  * the the RQ ID passed in the @phba. This can be overridden by the caller for
242504c68496SJames Smart  * more complicated setups.
242604c68496SJames Smart  **/
242704c68496SJames Smart void
242804c68496SJames Smart lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
242904c68496SJames Smart {
243004c68496SJames Smart 	struct lpfc_mbx_reg_fcfi *reg_fcfi;
243104c68496SJames Smart 
243204c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
243304c68496SJames Smart 	reg_fcfi = &mbox->u.mqe.un.reg_fcfi;
243404c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI);
243504c68496SJames Smart 	bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, phba->sli4_hba.hdr_rq->queue_id);
243604c68496SJames Smart 	bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
243704c68496SJames Smart 	bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
243804c68496SJames Smart 	bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
2439ecfd03c6SJames Smart 	bf_set(lpfc_reg_fcfi_info_index, reg_fcfi,
2440ecfd03c6SJames Smart 	       phba->fcf.current_rec.fcf_indx);
244104c68496SJames Smart 	/* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */
2442ecfd03c6SJames Smart 	bf_set(lpfc_reg_fcfi_mam, reg_fcfi, (~phba->fcf.addr_mode) & 0x3);
24433804dc84SJames Smart 	if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) {
244404c68496SJames Smart 		bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
2445ecfd03c6SJames Smart 		bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi,
2446ecfd03c6SJames Smart 		       phba->fcf.current_rec.vlan_id);
244704c68496SJames Smart 	}
244804c68496SJames Smart }
244904c68496SJames Smart 
245004c68496SJames Smart /**
245104c68496SJames Smart  * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
245204c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
245304c68496SJames Smart  * @fcfi: FCFI to be unregistered.
245404c68496SJames Smart  *
245504c68496SJames Smart  * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
245604c68496SJames Smart  * The SLI Host uses the command to inactivate an FCFI.
245704c68496SJames Smart  **/
245804c68496SJames Smart void
245904c68496SJames Smart lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi)
246004c68496SJames Smart {
246104c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
246204c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI);
246304c68496SJames Smart 	bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi);
246404c68496SJames Smart }
246504c68496SJames Smart 
246604c68496SJames Smart /**
246704c68496SJames Smart  * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
246804c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
246904c68496SJames Smart  * @ndlp: The nodelist structure that describes the RPI to resume.
247004c68496SJames Smart  *
247104c68496SJames Smart  * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
247204c68496SJames Smart  * link event.
247304c68496SJames Smart  **/
247404c68496SJames Smart void
247504c68496SJames Smart lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
247604c68496SJames Smart {
24776d368e53SJames Smart 	struct lpfc_hba *phba = ndlp->phba;
247804c68496SJames Smart 	struct lpfc_mbx_resume_rpi *resume_rpi;
247904c68496SJames Smart 
248004c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
248104c68496SJames Smart 	resume_rpi = &mbox->u.mqe.un.resume_rpi;
248204c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI);
24836d368e53SJames Smart 	bf_set(lpfc_resume_rpi_index, resume_rpi,
24846d368e53SJames Smart 	       phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
24858fa38513SJames Smart 	bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI);
24868fa38513SJames Smart 	resume_rpi->event_tag = ndlp->phba->fc_eventTag;
248704c68496SJames Smart }
248828baac74SJames Smart 
248928baac74SJames Smart /**
249028baac74SJames Smart  * lpfc_supported_pages - Initialize the PORT_CAPABILITIES supported pages
249128baac74SJames Smart  *                        mailbox command.
249228baac74SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
249328baac74SJames Smart  *
249428baac74SJames Smart  * The PORT_CAPABILITIES supported pages mailbox command is issued to
249528baac74SJames Smart  * retrieve the particular feature pages supported by the port.
249628baac74SJames Smart  **/
249728baac74SJames Smart void
249828baac74SJames Smart lpfc_supported_pages(struct lpfcMboxq *mbox)
249928baac74SJames Smart {
250028baac74SJames Smart 	struct lpfc_mbx_supp_pages *supp_pages;
250128baac74SJames Smart 
250228baac74SJames Smart 	memset(mbox, 0, sizeof(*mbox));
250328baac74SJames Smart 	supp_pages = &mbox->u.mqe.un.supp_pages;
250428baac74SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES);
250528baac74SJames Smart 	bf_set(cpn, supp_pages, LPFC_SUPP_PAGES);
250628baac74SJames Smart }
250728baac74SJames Smart 
250828baac74SJames Smart /**
2509fedd3b7bSJames Smart  * lpfc_pc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params mbox cmd.
251028baac74SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
251128baac74SJames Smart  *
251228baac74SJames Smart  * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to
251328baac74SJames Smart  * retrieve the particular SLI4 features supported by the port.
251428baac74SJames Smart  **/
251528baac74SJames Smart void
2516fedd3b7bSJames Smart lpfc_pc_sli4_params(struct lpfcMboxq *mbox)
251728baac74SJames Smart {
2518fedd3b7bSJames Smart 	struct lpfc_mbx_pc_sli4_params *sli4_params;
251928baac74SJames Smart 
252028baac74SJames Smart 	memset(mbox, 0, sizeof(*mbox));
252128baac74SJames Smart 	sli4_params = &mbox->u.mqe.un.sli4_params;
252228baac74SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES);
252328baac74SJames Smart 	bf_set(cpn, sli4_params, LPFC_SLI4_PARAMETERS);
252428baac74SJames Smart }
2525