xref: /openbmc/linux/drivers/scsi/lpfc/lpfc_mbox.c (revision 0c9ab6f5)
1dea3101eS /*******************************************************************
2dea3101eS  * This file is part of the Emulex Linux Device Driver for         *
3c44ce173SJames.Smart@Emulex.Com  * Fibre Channel Host Bus Adapters.                                *
4d8e93df1SJames Smart  * Copyright (C) 2004-2009 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>
24dea3101eS #include <linux/interrupt.h>
25dea3101eS 
26f888ba3cSJames.Smart@Emulex.Com #include <scsi/scsi_device.h>
27f888ba3cSJames.Smart@Emulex.Com #include <scsi/scsi_transport_fc.h>
2891886523SJames.Smart@Emulex.Com #include <scsi/scsi.h>
296a9c52cfSJames Smart #include <scsi/fc/fc_fs.h>
3091886523SJames.Smart@Emulex.Com 
31da0436e9SJames Smart #include "lpfc_hw4.h"
32dea3101eS #include "lpfc_hw.h"
33dea3101eS #include "lpfc_sli.h"
34da0436e9SJames Smart #include "lpfc_sli4.h"
35ea2151b4SJames Smart #include "lpfc_nl.h"
36dea3101eS #include "lpfc_disc.h"
37dea3101eS #include "lpfc_scsi.h"
38dea3101eS #include "lpfc.h"
39dea3101eS #include "lpfc_logmsg.h"
40dea3101eS #include "lpfc_crtn.h"
41dea3101eS #include "lpfc_compat.h"
42dea3101eS 
43e59058c4SJames Smart /**
4421e9a0a5SJames Smart  * lpfc_dump_static_vport - Dump HBA's static vport information.
4521e9a0a5SJames Smart  * @phba: pointer to lpfc hba data structure.
4621e9a0a5SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
4721e9a0a5SJames Smart  * @offset: offset for dumping vport info.
4821e9a0a5SJames Smart  *
4921e9a0a5SJames Smart  * The dump mailbox command provides a method for the device driver to obtain
5021e9a0a5SJames Smart  * various types of information from the HBA device.
5121e9a0a5SJames Smart  *
5221e9a0a5SJames Smart  * This routine prepares the mailbox command for dumping list of static
5321e9a0a5SJames Smart  * vports to be created.
5421e9a0a5SJames Smart  **/
551c6834a7SJames Smart int
5621e9a0a5SJames Smart lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
5721e9a0a5SJames Smart 		uint16_t offset)
5821e9a0a5SJames Smart {
5921e9a0a5SJames Smart 	MAILBOX_t *mb;
601c6834a7SJames Smart 	struct lpfc_dmabuf *mp;
6121e9a0a5SJames Smart 
6221e9a0a5SJames Smart 	mb = &pmb->u.mb;
6321e9a0a5SJames Smart 
6421e9a0a5SJames Smart 	/* Setup to dump vport info region */
6521e9a0a5SJames Smart 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
6621e9a0a5SJames Smart 	mb->mbxCommand = MBX_DUMP_MEMORY;
6721e9a0a5SJames Smart 	mb->un.varDmp.type = DMP_NV_PARAMS;
6821e9a0a5SJames Smart 	mb->un.varDmp.entry_index = offset;
6921e9a0a5SJames Smart 	mb->un.varDmp.region_id = DMP_REGION_VPORT;
7021e9a0a5SJames Smart 	mb->mbxOwner = OWN_HOST;
7121e9a0a5SJames Smart 
721c6834a7SJames Smart 	/* For SLI3 HBAs data is embedded in mailbox */
731c6834a7SJames Smart 	if (phba->sli_rev != LPFC_SLI_REV4) {
741c6834a7SJames Smart 		mb->un.varDmp.cv = 1;
751c6834a7SJames Smart 		mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t);
761c6834a7SJames Smart 		return 0;
771c6834a7SJames Smart 	}
781c6834a7SJames Smart 
791c6834a7SJames Smart 	/* For SLI4 HBAs driver need to allocate memory */
801c6834a7SJames Smart 	mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
811c6834a7SJames Smart 	if (mp)
821c6834a7SJames Smart 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
831c6834a7SJames Smart 
841c6834a7SJames Smart 	if (!mp || !mp->virt) {
851c6834a7SJames Smart 		kfree(mp);
861c6834a7SJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
871c6834a7SJames Smart 			"2605 lpfc_dump_static_vport: memory"
881c6834a7SJames Smart 			" allocation failed\n");
891c6834a7SJames Smart 		return 1;
901c6834a7SJames Smart 	}
911c6834a7SJames Smart 	memset(mp->virt, 0, LPFC_BPL_SIZE);
921c6834a7SJames Smart 	INIT_LIST_HEAD(&mp->list);
931c6834a7SJames Smart 	/* save address for completion */
941c6834a7SJames Smart 	pmb->context2 = (uint8_t *) mp;
951c6834a7SJames Smart 	mb->un.varWords[3] = putPaddrLow(mp->phys);
961c6834a7SJames Smart 	mb->un.varWords[4] = putPaddrHigh(mp->phys);
971c6834a7SJames Smart 	mb->un.varDmp.sli4_length = sizeof(struct static_vport_info);
981c6834a7SJames Smart 
991c6834a7SJames Smart 	return 0;
10021e9a0a5SJames Smart }
10121e9a0a5SJames Smart 
10221e9a0a5SJames Smart /**
103a0c87cbdSJames Smart  * lpfc_down_link - Bring down HBAs link.
104e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
105e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
106a0c87cbdSJames Smart  *
107a0c87cbdSJames Smart  * This routine prepares a mailbox command to bring down HBA link.
108a0c87cbdSJames Smart  **/
109a0c87cbdSJames Smart void
110a0c87cbdSJames Smart lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
111a0c87cbdSJames Smart {
112a0c87cbdSJames Smart 	MAILBOX_t *mb;
113a0c87cbdSJames Smart 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
114a0c87cbdSJames Smart 	mb = &pmb->u.mb;
115a0c87cbdSJames Smart 	mb->mbxCommand = MBX_DOWN_LINK;
116a0c87cbdSJames Smart 	mb->mbxOwner = OWN_HOST;
117a0c87cbdSJames Smart }
118a0c87cbdSJames Smart 
119a0c87cbdSJames Smart /**
120a0c87cbdSJames Smart  * lpfc_dump_mem - Prepare a mailbox command for reading a region.
121a0c87cbdSJames Smart  * @phba: pointer to lpfc hba data structure.
122a0c87cbdSJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
123a0c87cbdSJames Smart  * @offset: offset into the region.
124a0c87cbdSJames Smart  * @region_id: config region id.
125e59058c4SJames Smart  *
126e59058c4SJames Smart  * The dump mailbox command provides a method for the device driver to obtain
127e59058c4SJames Smart  * various types of information from the HBA device.
128e59058c4SJames Smart  *
129a0c87cbdSJames Smart  * This routine prepares the mailbox command for dumping HBA's config region.
130e59058c4SJames Smart  **/
131dea3101eS void
132a0c87cbdSJames Smart lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset,
133a0c87cbdSJames Smart 		uint16_t region_id)
134dea3101eS {
135dea3101eS 	MAILBOX_t *mb;
136dea3101eS 	void *ctx;
137dea3101eS 
13804c68496SJames Smart 	mb = &pmb->u.mb;
139dea3101eS 	ctx = pmb->context2;
140dea3101eS 
141dea3101eS 	/* Setup to dump VPD region */
142dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
143dea3101eS 	mb->mbxCommand = MBX_DUMP_MEMORY;
144dea3101eS 	mb->un.varDmp.cv = 1;
145dea3101eS 	mb->un.varDmp.type = DMP_NV_PARAMS;
146dea3101eS 	mb->un.varDmp.entry_index = offset;
147a0c87cbdSJames Smart 	mb->un.varDmp.region_id = region_id;
148dea3101eS 	mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
149dea3101eS 	mb->un.varDmp.co = 0;
150dea3101eS 	mb->un.varDmp.resp_offset = 0;
151dea3101eS 	pmb->context2 = ctx;
152dea3101eS 	mb->mbxOwner = OWN_HOST;
153dea3101eS 	return;
154dea3101eS }
155dea3101eS 
156e59058c4SJames Smart /**
1573621a710SJames Smart  * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
15897207482SJames Smart  * @phba: pointer to lpfc hba data structure.
15997207482SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1603621a710SJames Smart  *
16197207482SJames Smart  * This function create a dump memory mailbox command to dump wake up
16297207482SJames Smart  * parameters.
16397207482SJames Smart  */
16497207482SJames Smart void
16597207482SJames Smart lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
16697207482SJames Smart {
16797207482SJames Smart 	MAILBOX_t *mb;
16897207482SJames Smart 	void *ctx;
16997207482SJames Smart 
17004c68496SJames Smart 	mb = &pmb->u.mb;
17197207482SJames Smart 	/* Save context so that we can restore after memset */
17297207482SJames Smart 	ctx = pmb->context2;
17397207482SJames Smart 
17497207482SJames Smart 	/* Setup to dump VPD region */
17597207482SJames Smart 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
17697207482SJames Smart 	mb->mbxCommand = MBX_DUMP_MEMORY;
17797207482SJames Smart 	mb->mbxOwner = OWN_HOST;
17897207482SJames Smart 	mb->un.varDmp.cv = 1;
17997207482SJames Smart 	mb->un.varDmp.type = DMP_NV_PARAMS;
18097207482SJames Smart 	mb->un.varDmp.entry_index = 0;
18197207482SJames Smart 	mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
18297207482SJames Smart 	mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
18397207482SJames Smart 	mb->un.varDmp.co = 0;
18497207482SJames Smart 	mb->un.varDmp.resp_offset = 0;
18597207482SJames Smart 	pmb->context2 = ctx;
18697207482SJames Smart 	return;
18797207482SJames Smart }
18897207482SJames Smart 
18997207482SJames Smart /**
1903621a710SJames Smart  * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
191e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
192e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
193e59058c4SJames Smart  *
194e59058c4SJames Smart  * The read NVRAM mailbox command returns the HBA's non-volatile parameters
195e59058c4SJames Smart  * that are used as defaults when the Fibre Channel link is brought on-line.
196e59058c4SJames Smart  *
197e59058c4SJames Smart  * This routine prepares the mailbox command for reading information stored
198e59058c4SJames Smart  * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
199e59058c4SJames Smart  **/
200dea3101eS void
201dea3101eS lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
202dea3101eS {
203dea3101eS 	MAILBOX_t *mb;
204dea3101eS 
20504c68496SJames Smart 	mb = &pmb->u.mb;
206dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
207dea3101eS 	mb->mbxCommand = MBX_READ_NV;
208dea3101eS 	mb->mbxOwner = OWN_HOST;
209dea3101eS 	return;
210dea3101eS }
211dea3101eS 
212e59058c4SJames Smart /**
2133621a710SJames Smart  * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
214e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
215e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
216e59058c4SJames Smart  * @ring: ring number for the asynchronous event to be configured.
217e59058c4SJames Smart  *
218e59058c4SJames Smart  * The asynchronous event enable mailbox command is used to enable the
219e59058c4SJames Smart  * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
220e59058c4SJames Smart  * specifies the default ring to which events are posted.
221e59058c4SJames Smart  *
222e59058c4SJames Smart  * This routine prepares the mailbox command for enabling HBA asynchronous
223e59058c4SJames Smart  * event support on a IOCB ring.
224e59058c4SJames Smart  **/
22557127f15SJames Smart void
22657127f15SJames Smart lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
22757127f15SJames Smart 		uint32_t ring)
22857127f15SJames Smart {
22957127f15SJames Smart 	MAILBOX_t *mb;
23057127f15SJames Smart 
23104c68496SJames Smart 	mb = &pmb->u.mb;
23257127f15SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
23357127f15SJames Smart 	mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
23457127f15SJames Smart 	mb->un.varCfgAsyncEvent.ring = ring;
23557127f15SJames Smart 	mb->mbxOwner = OWN_HOST;
23657127f15SJames Smart 	return;
23757127f15SJames Smart }
23857127f15SJames Smart 
239e59058c4SJames Smart /**
2403621a710SJames Smart  * lpfc_heart_beat - Prepare a mailbox command for heart beat
241e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
242e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
243e59058c4SJames Smart  *
244e59058c4SJames Smart  * The heart beat mailbox command is used to detect an unresponsive HBA, which
245e59058c4SJames Smart  * is defined as any device where no error attention is sent and both mailbox
246e59058c4SJames Smart  * and rings are not processed.
247e59058c4SJames Smart  *
248e59058c4SJames Smart  * This routine prepares the mailbox command for issuing a heart beat in the
249e59058c4SJames Smart  * form of mailbox command to the HBA. The timely completion of the heart
250e59058c4SJames Smart  * beat mailbox command indicates the health of the HBA.
251e59058c4SJames Smart  **/
252858c9f6cSJames Smart void
253858c9f6cSJames Smart lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
254858c9f6cSJames Smart {
255858c9f6cSJames Smart 	MAILBOX_t *mb;
256858c9f6cSJames Smart 
25704c68496SJames Smart 	mb = &pmb->u.mb;
258858c9f6cSJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
259858c9f6cSJames Smart 	mb->mbxCommand = MBX_HEARTBEAT;
260858c9f6cSJames Smart 	mb->mbxOwner = OWN_HOST;
261858c9f6cSJames Smart 	return;
262858c9f6cSJames Smart }
263858c9f6cSJames Smart 
264e59058c4SJames Smart /**
2653621a710SJames Smart  * lpfc_read_la - Prepare a mailbox command for reading HBA link attention
266e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
267e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
268e59058c4SJames Smart  * @mp: DMA buffer memory for reading the link attention information into.
269e59058c4SJames Smart  *
270e59058c4SJames Smart  * The read link attention mailbox command is issued to read the Link Event
271e59058c4SJames Smart  * Attention information indicated by the HBA port when the Link Event bit
272e59058c4SJames Smart  * of the Host Attention (HSTATT) register is set to 1. A Link Event
273e59058c4SJames Smart  * Attention occurs based on an exception detected at the Fibre Channel link
274e59058c4SJames Smart  * interface.
275e59058c4SJames Smart  *
276e59058c4SJames Smart  * This routine prepares the mailbox command for reading HBA link attention
277e59058c4SJames Smart  * information. A DMA memory has been set aside and address passed to the
278e59058c4SJames Smart  * HBA through @mp for the HBA to DMA link attention information into the
279e59058c4SJames Smart  * memory as part of the execution of the mailbox command.
280e59058c4SJames Smart  *
281e59058c4SJames Smart  * Return codes
282e59058c4SJames Smart  *    0 - Success (currently always return 0)
283e59058c4SJames Smart  **/
284dea3101eS int
285dea3101eS lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
286dea3101eS {
287dea3101eS 	MAILBOX_t *mb;
288dea3101eS 	struct lpfc_sli *psli;
289dea3101eS 
290dea3101eS 	psli = &phba->sli;
29104c68496SJames Smart 	mb = &pmb->u.mb;
292dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
293dea3101eS 
294dea3101eS 	INIT_LIST_HEAD(&mp->list);
295dea3101eS 	mb->mbxCommand = MBX_READ_LA64;
296dea3101eS 	mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128;
297dea3101eS 	mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
298dea3101eS 	mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys);
299dea3101eS 
300dea3101eS 	/* Save address for later completion and set the owner to host so that
301dea3101eS 	 * the FW knows this mailbox is available for processing.
302dea3101eS 	 */
303dea3101eS 	pmb->context1 = (uint8_t *) mp;
304dea3101eS 	mb->mbxOwner = OWN_HOST;
30592d7f7b0SJames Smart 	return (0);
306dea3101eS }
307dea3101eS 
308e59058c4SJames Smart /**
3093621a710SJames Smart  * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
310e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
311e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
312e59058c4SJames Smart  *
313e59058c4SJames Smart  * The clear link attention mailbox command is issued to clear the link event
314e59058c4SJames Smart  * attention condition indicated by the Link Event bit of the Host Attention
315e59058c4SJames Smart  * (HSTATT) register. The link event attention condition is cleared only if
316e59058c4SJames Smart  * the event tag specified matches that of the current link event counter.
317e59058c4SJames Smart  * The current event tag is read using the read link attention event mailbox
318e59058c4SJames Smart  * command.
319e59058c4SJames Smart  *
320e59058c4SJames Smart  * This routine prepares the mailbox command for clearing HBA link attention
321e59058c4SJames Smart  * information.
322e59058c4SJames Smart  **/
323dea3101eS void
324dea3101eS lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
325dea3101eS {
326dea3101eS 	MAILBOX_t *mb;
327dea3101eS 
32804c68496SJames Smart 	mb = &pmb->u.mb;
329dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
330dea3101eS 
331dea3101eS 	mb->un.varClearLA.eventTag = phba->fc_eventTag;
332dea3101eS 	mb->mbxCommand = MBX_CLEAR_LA;
333dea3101eS 	mb->mbxOwner = OWN_HOST;
334dea3101eS 	return;
335dea3101eS }
336dea3101eS 
337e59058c4SJames Smart /**
3383621a710SJames Smart  * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
339e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
340e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
341e59058c4SJames Smart  *
342e59058c4SJames Smart  * The configure link mailbox command is used before the initialize link
343e59058c4SJames Smart  * mailbox command to override default value and to configure link-oriented
344e59058c4SJames Smart  * parameters such as DID address and various timers. Typically, this
345e59058c4SJames Smart  * command would be used after an F_Port login to set the returned DID address
346e59058c4SJames Smart  * and the fabric timeout values. This command is not valid before a configure
347e59058c4SJames Smart  * port command has configured the HBA port.
348e59058c4SJames Smart  *
349e59058c4SJames Smart  * This routine prepares the mailbox command for configuring link on a HBA.
350e59058c4SJames Smart  **/
351dea3101eS void
352dea3101eS lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
353dea3101eS {
3542e0fef85SJames Smart 	struct lpfc_vport  *vport = phba->pport;
35504c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
356dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
357dea3101eS 
358dea3101eS 	/* NEW_FEATURE
359dea3101eS 	 * SLI-2, Coalescing Response Feature.
360dea3101eS 	 */
361dea3101eS 	if (phba->cfg_cr_delay) {
362dea3101eS 		mb->un.varCfgLnk.cr = 1;
363dea3101eS 		mb->un.varCfgLnk.ci = 1;
364dea3101eS 		mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
365dea3101eS 		mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
366dea3101eS 	}
367dea3101eS 
3682e0fef85SJames Smart 	mb->un.varCfgLnk.myId = vport->fc_myDID;
369dea3101eS 	mb->un.varCfgLnk.edtov = phba->fc_edtov;
370dea3101eS 	mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
371dea3101eS 	mb->un.varCfgLnk.ratov = phba->fc_ratov;
372dea3101eS 	mb->un.varCfgLnk.rttov = phba->fc_rttov;
373dea3101eS 	mb->un.varCfgLnk.altov = phba->fc_altov;
374dea3101eS 	mb->un.varCfgLnk.crtov = phba->fc_crtov;
375dea3101eS 	mb->un.varCfgLnk.citov = phba->fc_citov;
376dea3101eS 
377dea3101eS 	if (phba->cfg_ack0)
378dea3101eS 		mb->un.varCfgLnk.ack0_enable = 1;
379dea3101eS 
380dea3101eS 	mb->mbxCommand = MBX_CONFIG_LINK;
381dea3101eS 	mb->mbxOwner = OWN_HOST;
382dea3101eS 	return;
383dea3101eS }
384dea3101eS 
385e59058c4SJames Smart /**
3863621a710SJames Smart  * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
3879399627fSJames Smart  * @phba: pointer to lpfc hba data structure.
3889399627fSJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
3899399627fSJames Smart  *
3909399627fSJames Smart  * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
3919399627fSJames Smart  * MSI-X multi-message interrupt vector association to interrupt attention
3929399627fSJames Smart  * conditions.
3939399627fSJames Smart  *
3949399627fSJames Smart  * Return codes
3959399627fSJames Smart  *    0 - Success
3969399627fSJames Smart  *    -EINVAL - Failure
3979399627fSJames Smart  **/
3989399627fSJames Smart int
3999399627fSJames Smart lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4009399627fSJames Smart {
40104c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
4029399627fSJames Smart 	uint32_t attentionConditions[2];
4039399627fSJames Smart 
4049399627fSJames Smart 	/* Sanity check */
4059399627fSJames Smart 	if (phba->cfg_use_msi != 2) {
4069399627fSJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4079399627fSJames Smart 				"0475 Not configured for supporting MSI-X "
4089399627fSJames Smart 				"cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
4099399627fSJames Smart 		return -EINVAL;
4109399627fSJames Smart 	}
4119399627fSJames Smart 
4129399627fSJames Smart 	if (phba->sli_rev < 3) {
4139399627fSJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4149399627fSJames Smart 				"0476 HBA not supporting SLI-3 or later "
4159399627fSJames Smart 				"SLI Revision: 0x%x\n", phba->sli_rev);
4169399627fSJames Smart 		return -EINVAL;
4179399627fSJames Smart 	}
4189399627fSJames Smart 
4199399627fSJames Smart 	/* Clear mailbox command fields */
4209399627fSJames Smart 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
4219399627fSJames Smart 
4229399627fSJames Smart 	/*
4239399627fSJames Smart 	 * SLI-3, Message Signaled Interrupt Fearure.
4249399627fSJames Smart 	 */
4259399627fSJames Smart 
4269399627fSJames Smart 	/* Multi-message attention configuration */
4279399627fSJames Smart 	attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
4289399627fSJames Smart 				  HA_LATT | HA_MBATT);
4299399627fSJames Smart 	attentionConditions[1] = 0;
4309399627fSJames Smart 
4319399627fSJames Smart 	mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
4329399627fSJames Smart 	mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
4339399627fSJames Smart 
4349399627fSJames Smart 	/*
4359399627fSJames Smart 	 * Set up message number to HA bit association
4369399627fSJames Smart 	 */
4379399627fSJames Smart #ifdef __BIG_ENDIAN_BITFIELD
4389399627fSJames Smart 	/* RA0 (FCP Ring) */
4399399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
4409399627fSJames Smart 	/* RA1 (Other Protocol Extra Ring) */
4419399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
4429399627fSJames Smart #else   /*  __LITTLE_ENDIAN_BITFIELD */
4439399627fSJames Smart 	/* RA0 (FCP Ring) */
4449399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
4459399627fSJames Smart 	/* RA1 (Other Protocol Extra Ring) */
4469399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
4479399627fSJames Smart #endif
4489399627fSJames Smart 	/* Multi-message interrupt autoclear configuration*/
4499399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
4509399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
4519399627fSJames Smart 
4529399627fSJames Smart 	/* For now, HBA autoclear does not work reliably, disable it */
4539399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[0] = 0;
4549399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[1] = 0;
4559399627fSJames Smart 
4569399627fSJames Smart 	/* Set command and owner bit */
4579399627fSJames Smart 	mb->mbxCommand = MBX_CONFIG_MSI;
4589399627fSJames Smart 	mb->mbxOwner = OWN_HOST;
4599399627fSJames Smart 
4609399627fSJames Smart 	return 0;
4619399627fSJames Smart }
4629399627fSJames Smart 
4639399627fSJames Smart /**
4643621a710SJames Smart  * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
465e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
466e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
467e59058c4SJames Smart  * @topology: the link topology for the link to be initialized to.
468e59058c4SJames Smart  * @linkspeed: the link speed for the link to be initialized to.
469e59058c4SJames Smart  *
470e59058c4SJames Smart  * The initialize link mailbox command is used to initialize the Fibre
471e59058c4SJames Smart  * Channel link. This command must follow a configure port command that
472e59058c4SJames Smart  * establishes the mode of operation.
473e59058c4SJames Smart  *
474e59058c4SJames Smart  * This routine prepares the mailbox command for initializing link on a HBA
475e59058c4SJames Smart  * with the specified link topology and speed.
476e59058c4SJames Smart  **/
477dea3101eS void
478dea3101eS lpfc_init_link(struct lpfc_hba * phba,
479dea3101eS 	       LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
480dea3101eS {
481dea3101eS 	lpfc_vpd_t *vpd;
482dea3101eS 	struct lpfc_sli *psli;
483dea3101eS 	MAILBOX_t *mb;
484dea3101eS 
48504c68496SJames Smart 	mb = &pmb->u.mb;
486dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
487dea3101eS 
488dea3101eS 	psli = &phba->sli;
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 
5094b0b91d4SJames Smart 	/* Enable asynchronous ABTS responses from firmware */
5104b0b91d4SJames Smart 	mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
5114b0b91d4SJames Smart 
512dea3101eS 	/* NEW_FEATURE
513dea3101eS 	 * Setting up the link speed
514dea3101eS 	 */
515dea3101eS 	vpd = &phba->vpd;
516dea3101eS 	if (vpd->rev.feaLevelHigh >= 0x02){
517dea3101eS 		switch(linkspeed){
518dea3101eS 			case LINK_SPEED_1G:
519dea3101eS 			case LINK_SPEED_2G:
520dea3101eS 			case LINK_SPEED_4G:
521b87eab38SJames Smart 			case LINK_SPEED_8G:
522dea3101eS 				mb->un.varInitLnk.link_flags |=
523dea3101eS 							FLAGS_LINK_SPEED;
524dea3101eS 				mb->un.varInitLnk.link_speed = linkspeed;
525dea3101eS 			break;
526dea3101eS 			case LINK_SPEED_AUTO:
527dea3101eS 			default:
528dea3101eS 				mb->un.varInitLnk.link_speed =
529dea3101eS 							LINK_SPEED_AUTO;
530dea3101eS 			break;
531dea3101eS 		}
532dea3101eS 
533dea3101eS 	}
534dea3101eS 	else
535dea3101eS 		mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
536dea3101eS 
537dea3101eS 	mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
538dea3101eS 	mb->mbxOwner = OWN_HOST;
539dea3101eS 	mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
540dea3101eS 	return;
541dea3101eS }
542dea3101eS 
543e59058c4SJames Smart /**
5443621a710SJames Smart  * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
545e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
546e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
547e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
548e59058c4SJames Smart  *
549e59058c4SJames Smart  * The read service parameter mailbox command is used to read the HBA port
550e59058c4SJames Smart  * service parameters. The service parameters are read into the buffer
551e59058c4SJames Smart  * specified directly by a BDE in the mailbox command. These service
552e59058c4SJames Smart  * parameters may then be used to build the payload of an N_Port/F_POrt
553e59058c4SJames Smart  * login request and reply (LOGI/ACC).
554e59058c4SJames Smart  *
555e59058c4SJames Smart  * This routine prepares the mailbox command for reading HBA port service
556e59058c4SJames Smart  * parameters. The DMA memory is allocated in this function and the addresses
557e59058c4SJames Smart  * are populated into the mailbox command for the HBA to DMA the service
558e59058c4SJames Smart  * parameters into.
559e59058c4SJames Smart  *
560e59058c4SJames Smart  * Return codes
561e59058c4SJames Smart  *    0 - Success
562e59058c4SJames Smart  *    1 - DMA memory allocation failed
563e59058c4SJames Smart  **/
564dea3101eS int
56592d7f7b0SJames Smart lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
566dea3101eS {
567dea3101eS 	struct lpfc_dmabuf *mp;
568dea3101eS 	MAILBOX_t *mb;
569dea3101eS 	struct lpfc_sli *psli;
570dea3101eS 
571dea3101eS 	psli = &phba->sli;
57204c68496SJames Smart 	mb = &pmb->u.mb;
573dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
574dea3101eS 
575dea3101eS 	mb->mbxOwner = OWN_HOST;
576dea3101eS 
577dea3101eS 	/* Get a buffer to hold the HBAs Service Parameters */
578dea3101eS 
57998c9ea5cSJames Smart 	mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
58098c9ea5cSJames Smart 	if (mp)
58198c9ea5cSJames Smart 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
58298c9ea5cSJames Smart 	if (!mp || !mp->virt) {
583dea3101eS 		kfree(mp);
584dea3101eS 		mb->mbxCommand = MBX_READ_SPARM64;
585dea3101eS 		/* READ_SPARAM: no buffers */
586e8b62011SJames Smart 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
587e8b62011SJames Smart 			        "0301 READ_SPARAM: no buffers\n");
58892d7f7b0SJames Smart 		return (1);
589dea3101eS 	}
590dea3101eS 	INIT_LIST_HEAD(&mp->list);
591dea3101eS 	mb->mbxCommand = MBX_READ_SPARM64;
592dea3101eS 	mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
593dea3101eS 	mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
594dea3101eS 	mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
59504c68496SJames Smart 	mb->un.varRdSparm.vpi = vpi + phba->vpi_base;
596dea3101eS 
597dea3101eS 	/* save address for completion */
598dea3101eS 	pmb->context1 = mp;
599dea3101eS 
60092d7f7b0SJames Smart 	return (0);
601dea3101eS }
602dea3101eS 
603e59058c4SJames Smart /**
6043621a710SJames Smart  * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
605e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
606e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
607e59058c4SJames Smart  * @did: remote port identifier.
608e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
609e59058c4SJames Smart  *
610e59058c4SJames Smart  * The unregister DID mailbox command is used to unregister an N_Port/F_Port
611e59058c4SJames Smart  * login for an unknown RPI by specifying the DID of a remote port. This
612e59058c4SJames Smart  * command frees an RPI context in the HBA port. This has the effect of
613e59058c4SJames Smart  * performing an implicit N_Port/F_Port logout.
614e59058c4SJames Smart  *
615e59058c4SJames Smart  * This routine prepares the mailbox command for unregistering a remote
616e59058c4SJames Smart  * N_Port/F_Port (DID) login.
617e59058c4SJames Smart  **/
618dea3101eS void
61992d7f7b0SJames Smart lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
62092d7f7b0SJames Smart 	       LPFC_MBOXQ_t * pmb)
621dea3101eS {
622dea3101eS 	MAILBOX_t *mb;
623dea3101eS 
62404c68496SJames Smart 	mb = &pmb->u.mb;
625dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
626dea3101eS 
627dea3101eS 	mb->un.varUnregDID.did = did;
62804c68496SJames Smart 	if (vpi != 0xffff)
62904c68496SJames Smart 		vpi += phba->vpi_base;
63092d7f7b0SJames Smart 	mb->un.varUnregDID.vpi = vpi;
631dea3101eS 
632dea3101eS 	mb->mbxCommand = MBX_UNREG_D_ID;
633dea3101eS 	mb->mbxOwner = OWN_HOST;
634dea3101eS 	return;
635dea3101eS }
636dea3101eS 
637e59058c4SJames Smart /**
6383621a710SJames Smart  * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
639e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
640e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
641e59058c4SJames Smart  *
642e59058c4SJames Smart  * The read configuration mailbox command is used to read the HBA port
643e59058c4SJames Smart  * configuration parameters. This mailbox command provides a method for
644e59058c4SJames Smart  * seeing any parameters that may have changed via various configuration
645e59058c4SJames Smart  * mailbox commands.
646e59058c4SJames Smart  *
647e59058c4SJames Smart  * This routine prepares the mailbox command for reading out HBA configuration
648e59058c4SJames Smart  * parameters.
649e59058c4SJames Smart  **/
650dea3101eS void
651dea3101eS lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
652dea3101eS {
653dea3101eS 	MAILBOX_t *mb;
654dea3101eS 
65504c68496SJames Smart 	mb = &pmb->u.mb;
656dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
657dea3101eS 
658dea3101eS 	mb->mbxCommand = MBX_READ_CONFIG;
659dea3101eS 	mb->mbxOwner = OWN_HOST;
660dea3101eS 	return;
661dea3101eS }
662dea3101eS 
663e59058c4SJames Smart /**
6643621a710SJames Smart  * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
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 link status mailbox command is used to read the link status from
669e59058c4SJames Smart  * the HBA. Link status includes all link-related error counters. These
670e59058c4SJames Smart  * counters are maintained by the HBA and originated in the link hardware
671e59058c4SJames Smart  * unit. Note that all of these counters wrap.
672e59058c4SJames Smart  *
673e59058c4SJames Smart  * This routine prepares the mailbox command for reading out HBA link status.
674e59058c4SJames Smart  **/
6757bb3b137SJamie Wellnitz void
6767bb3b137SJamie Wellnitz lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
6777bb3b137SJamie Wellnitz {
6787bb3b137SJamie Wellnitz 	MAILBOX_t *mb;
6797bb3b137SJamie Wellnitz 
68004c68496SJames Smart 	mb = &pmb->u.mb;
6817bb3b137SJamie Wellnitz 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
6827bb3b137SJamie Wellnitz 
6837bb3b137SJamie Wellnitz 	mb->mbxCommand = MBX_READ_LNK_STAT;
6847bb3b137SJamie Wellnitz 	mb->mbxOwner = OWN_HOST;
6857bb3b137SJamie Wellnitz 	return;
6867bb3b137SJamie Wellnitz }
6877bb3b137SJamie Wellnitz 
688e59058c4SJames Smart /**
68904c68496SJames Smart  * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
690e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
691e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
692e59058c4SJames Smart  * @did: remote port identifier.
693e59058c4SJames Smart  * @param: pointer to memory holding the server parameters.
694e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
695e59058c4SJames Smart  * @flag: action flag to be passed back for the complete function.
696e59058c4SJames Smart  *
697e59058c4SJames Smart  * The registration login mailbox command is used to register an N_Port or
698e59058c4SJames Smart  * F_Port login. This registration allows the HBA to cache the remote N_Port
699e59058c4SJames Smart  * service parameters internally and thereby make the appropriate FC-2
700e59058c4SJames Smart  * decisions. The remote port service parameters are handed off by the driver
701e59058c4SJames Smart  * to the HBA using a descriptor entry that directly identifies a buffer in
702e59058c4SJames Smart  * host memory. In exchange, the HBA returns an RPI identifier.
703e59058c4SJames Smart  *
704e59058c4SJames Smart  * This routine prepares the mailbox command for registering remote port login.
705e59058c4SJames Smart  * The function allocates DMA buffer for passing the service parameters to the
706e59058c4SJames Smart  * HBA with the mailbox command.
707e59058c4SJames Smart  *
708e59058c4SJames Smart  * Return codes
709e59058c4SJames Smart  *    0 - Success
710e59058c4SJames Smart  *    1 - DMA memory allocation failed
711e59058c4SJames Smart  **/
712dea3101eS int
71304c68496SJames Smart lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
71492d7f7b0SJames Smart 	       uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
715dea3101eS {
71604c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
717dea3101eS 	uint8_t *sparam;
718dea3101eS 	struct lpfc_dmabuf *mp;
719dea3101eS 
720dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
721dea3101eS 
722dea3101eS 	mb->un.varRegLogin.rpi = 0;
72304c68496SJames Smart 	if (phba->sli_rev == LPFC_SLI_REV4) {
72404c68496SJames Smart 		mb->un.varRegLogin.rpi = lpfc_sli4_alloc_rpi(phba);
72504c68496SJames Smart 		if (mb->un.varRegLogin.rpi == LPFC_RPI_ALLOC_ERROR)
72604c68496SJames Smart 			return 1;
72704c68496SJames Smart 	}
72804c68496SJames Smart 
72904c68496SJames Smart 	mb->un.varRegLogin.vpi = vpi + phba->vpi_base;
730dea3101eS 	mb->un.varRegLogin.did = did;
731dea3101eS 	mb->un.varWords[30] = flag;	/* Set flag to issue action on cmpl */
732dea3101eS 
733dea3101eS 	mb->mbxOwner = OWN_HOST;
734dea3101eS 
735dea3101eS 	/* Get a buffer to hold NPorts Service Parameters */
73698c9ea5cSJames Smart 	mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
73798c9ea5cSJames Smart 	if (mp)
73898c9ea5cSJames Smart 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
73998c9ea5cSJames Smart 	if (!mp || !mp->virt) {
740dea3101eS 		kfree(mp);
741dea3101eS 		mb->mbxCommand = MBX_REG_LOGIN64;
742dea3101eS 		/* REG_LOGIN: no buffers */
74392d7f7b0SJames Smart 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
744e8b62011SJames Smart 				"0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
745e8b62011SJames Smart 				"flag x%x\n", vpi, did, flag);
74692d7f7b0SJames Smart 		return (1);
747dea3101eS 	}
748dea3101eS 	INIT_LIST_HEAD(&mp->list);
749dea3101eS 	sparam = mp->virt;
750dea3101eS 
751dea3101eS 	/* Copy param's into a new buffer */
752dea3101eS 	memcpy(sparam, param, sizeof (struct serv_parm));
753dea3101eS 
754dea3101eS 	/* save address for completion */
755dea3101eS 	pmb->context1 = (uint8_t *) mp;
756dea3101eS 
757dea3101eS 	mb->mbxCommand = MBX_REG_LOGIN64;
758dea3101eS 	mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
759dea3101eS 	mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
760dea3101eS 	mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
761dea3101eS 
76292d7f7b0SJames Smart 	return (0);
763dea3101eS }
764dea3101eS 
765e59058c4SJames Smart /**
7663621a710SJames Smart  * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
767e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
768e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
769e59058c4SJames Smart  * @rpi: remote port identifier
770e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
771e59058c4SJames Smart  *
772e59058c4SJames Smart  * The unregistration login mailbox command is used to unregister an N_Port
773e59058c4SJames Smart  * or F_Port login. This command frees an RPI context in the HBA. It has the
774e59058c4SJames Smart  * effect of performing an implicit N_Port/F_Port logout.
775e59058c4SJames Smart  *
776e59058c4SJames Smart  * This routine prepares the mailbox command for unregistering remote port
777e59058c4SJames Smart  * login.
778e59058c4SJames Smart  **/
779dea3101eS void
78092d7f7b0SJames Smart lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
78192d7f7b0SJames Smart 		 LPFC_MBOXQ_t * pmb)
782dea3101eS {
783dea3101eS 	MAILBOX_t *mb;
784dea3101eS 
78504c68496SJames Smart 	mb = &pmb->u.mb;
786dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
787dea3101eS 
788dea3101eS 	mb->un.varUnregLogin.rpi = (uint16_t) rpi;
789dea3101eS 	mb->un.varUnregLogin.rsvd1 = 0;
79004c68496SJames Smart 	mb->un.varUnregLogin.vpi = vpi + phba->vpi_base;
791dea3101eS 
792dea3101eS 	mb->mbxCommand = MBX_UNREG_LOGIN;
793dea3101eS 	mb->mbxOwner = OWN_HOST;
79404c68496SJames Smart 
795dea3101eS 	return;
796dea3101eS }
797dea3101eS 
798e59058c4SJames Smart /**
7993621a710SJames Smart  * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
800e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
801e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
802e59058c4SJames Smart  * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
803e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
804e59058c4SJames Smart  *
805e59058c4SJames Smart  * The registration vport identifier mailbox command is used to activate a
806e59058c4SJames Smart  * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
807e59058c4SJames Smart  * N_Port_ID against the information in the selected virtual N_Port context
808e59058c4SJames Smart  * block and marks it active to allow normal processing of IOCB commands and
809e59058c4SJames Smart  * received unsolicited exchanges.
810e59058c4SJames Smart  *
811e59058c4SJames Smart  * This routine prepares the mailbox command for registering a virtual N_Port.
812e59058c4SJames Smart  **/
81392d7f7b0SJames Smart void
81404c68496SJames Smart lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
81592d7f7b0SJames Smart {
81604c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
81792d7f7b0SJames Smart 
81892d7f7b0SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
81992d7f7b0SJames Smart 
82004c68496SJames Smart 	mb->un.varRegVpi.vpi = vport->vpi + vport->phba->vpi_base;
82104c68496SJames Smart 	mb->un.varRegVpi.sid = vport->fc_myDID;
82204c68496SJames Smart 	mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
823c868595dSJames Smart 	memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname,
824c868595dSJames Smart 	       sizeof(struct lpfc_name));
825c868595dSJames Smart 	mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]);
826c868595dSJames Smart 	mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]);
82792d7f7b0SJames Smart 
82892d7f7b0SJames Smart 	mb->mbxCommand = MBX_REG_VPI;
82992d7f7b0SJames Smart 	mb->mbxOwner = OWN_HOST;
83092d7f7b0SJames Smart 	return;
83192d7f7b0SJames Smart 
83292d7f7b0SJames Smart }
83392d7f7b0SJames Smart 
834e59058c4SJames Smart /**
8353621a710SJames Smart  * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
836e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
837e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
838e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
839e59058c4SJames Smart  *
840e59058c4SJames Smart  * The unregistration vport identifier mailbox command is used to inactivate
841e59058c4SJames Smart  * a virtual N_Port. The driver must have logged out and unregistered all
842e59058c4SJames Smart  * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
843e59058c4SJames Smart  * unregisters any default RPIs associated with the specified vpi, aborting
844e59058c4SJames Smart  * any active exchanges. The HBA will post the mailbox response after making
845e59058c4SJames Smart  * the virtual N_Port inactive.
846e59058c4SJames Smart  *
847e59058c4SJames Smart  * This routine prepares the mailbox command for unregistering a virtual
848e59058c4SJames Smart  * N_Port.
849e59058c4SJames Smart  **/
85092d7f7b0SJames Smart void
85192d7f7b0SJames Smart lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
85292d7f7b0SJames Smart {
85304c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
85492d7f7b0SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
85592d7f7b0SJames Smart 
8566669f9bbSJames Smart 	if (phba->sli_rev < LPFC_SLI_REV4)
85704c68496SJames Smart 		mb->un.varUnregVpi.vpi = vpi + phba->vpi_base;
8586669f9bbSJames Smart 	else
8596669f9bbSJames Smart 		mb->un.varUnregVpi.sli4_vpi = vpi + phba->vpi_base;
86092d7f7b0SJames Smart 
86192d7f7b0SJames Smart 	mb->mbxCommand = MBX_UNREG_VPI;
86292d7f7b0SJames Smart 	mb->mbxOwner = OWN_HOST;
86392d7f7b0SJames Smart 	return;
86492d7f7b0SJames Smart 
86592d7f7b0SJames Smart }
86692d7f7b0SJames Smart 
867e59058c4SJames Smart /**
8683621a710SJames Smart  * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
869e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
870e59058c4SJames Smart  *
871e59058c4SJames Smart  * This routine sets up and initializes the IOCB rings in the Port Control
872e59058c4SJames Smart  * Block (PCB).
873e59058c4SJames Smart  **/
874dea3101eS static void
875dea3101eS lpfc_config_pcb_setup(struct lpfc_hba * phba)
876dea3101eS {
877dea3101eS 	struct lpfc_sli *psli = &phba->sli;
878dea3101eS 	struct lpfc_sli_ring *pring;
87934b02dcdSJames Smart 	PCB_t *pcbp = phba->pcb;
880dea3101eS 	dma_addr_t pdma_addr;
881dea3101eS 	uint32_t offset;
8822e0fef85SJames Smart 	uint32_t iocbCnt = 0;
883dea3101eS 	int i;
884dea3101eS 
885dea3101eS 	pcbp->maxRing = (psli->num_rings - 1);
886dea3101eS 
887dea3101eS 	for (i = 0; i < psli->num_rings; i++) {
888dea3101eS 		pring = &psli->ring[i];
8892e0fef85SJames Smart 
890ed957684SJames Smart 		pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
891ed957684SJames Smart 							SLI2_IOCB_CMD_SIZE;
892ed957684SJames Smart 		pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
893ed957684SJames Smart 							SLI2_IOCB_RSP_SIZE;
894dea3101eS 		/* A ring MUST have both cmd and rsp entries defined to be
895dea3101eS 		   valid */
896dea3101eS 		if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
897dea3101eS 			pcbp->rdsc[i].cmdEntries = 0;
898dea3101eS 			pcbp->rdsc[i].rspEntries = 0;
899dea3101eS 			pcbp->rdsc[i].cmdAddrHigh = 0;
900dea3101eS 			pcbp->rdsc[i].rspAddrHigh = 0;
901dea3101eS 			pcbp->rdsc[i].cmdAddrLow = 0;
902dea3101eS 			pcbp->rdsc[i].rspAddrLow = 0;
903dea3101eS 			pring->cmdringaddr = NULL;
904dea3101eS 			pring->rspringaddr = NULL;
905dea3101eS 			continue;
906dea3101eS 		}
907dea3101eS 		/* Command ring setup for ring */
90834b02dcdSJames Smart 		pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
909dea3101eS 		pcbp->rdsc[i].cmdEntries = pring->numCiocb;
910dea3101eS 
91134b02dcdSJames Smart 		offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
91234b02dcdSJames Smart 			 (uint8_t *) phba->slim2p.virt;
91334b02dcdSJames Smart 		pdma_addr = phba->slim2p.phys + offset;
914dea3101eS 		pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
915dea3101eS 		pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
916dea3101eS 		iocbCnt += pring->numCiocb;
917dea3101eS 
918dea3101eS 		/* Response ring setup for ring */
91934b02dcdSJames Smart 		pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt];
920dea3101eS 
921dea3101eS 		pcbp->rdsc[i].rspEntries = pring->numRiocb;
92234b02dcdSJames Smart 		offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
92334b02dcdSJames Smart 			 (uint8_t *)phba->slim2p.virt;
92434b02dcdSJames Smart 		pdma_addr = phba->slim2p.phys + offset;
925dea3101eS 		pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
926dea3101eS 		pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
927dea3101eS 		iocbCnt += pring->numRiocb;
928dea3101eS 	}
929dea3101eS }
930dea3101eS 
931e59058c4SJames Smart /**
9323621a710SJames Smart  * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
933e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
934e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
935e59058c4SJames Smart  *
936e59058c4SJames Smart  * The read revision mailbox command is used to read the revision levels of
937e59058c4SJames Smart  * the HBA components. These components include hardware units, resident
938e59058c4SJames Smart  * firmware, and available firmware. HBAs that supports SLI-3 mode of
939e59058c4SJames Smart  * operation provide different response information depending on the version
940e59058c4SJames Smart  * requested by the driver.
941e59058c4SJames Smart  *
942e59058c4SJames Smart  * This routine prepares the mailbox command for reading HBA revision
943e59058c4SJames Smart  * information.
944e59058c4SJames Smart  **/
945dea3101eS void
946dea3101eS lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
947dea3101eS {
94804c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
949dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
950dea3101eS 	mb->un.varRdRev.cv = 1;
951ed957684SJames Smart 	mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
952dea3101eS 	mb->mbxCommand = MBX_READ_REV;
953dea3101eS 	mb->mbxOwner = OWN_HOST;
954dea3101eS 	return;
955dea3101eS }
956dea3101eS 
957e59058c4SJames Smart /**
9583621a710SJames Smart  * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
959e59058c4SJames Smart  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
960e59058c4SJames Smart  * @hbq_desc: pointer to the HBQ selection profile descriptor.
961e59058c4SJames Smart  *
962e59058c4SJames Smart  * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
963e59058c4SJames Smart  * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
964e59058c4SJames Smart  * the Sequence Length Test using the fields in the Selection Profile 2
965e59058c4SJames Smart  * extension in words 20:31.
966e59058c4SJames Smart  **/
967ed957684SJames Smart static void
968ed957684SJames Smart lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
969ed957684SJames Smart 			struct lpfc_hbq_init  *hbq_desc)
970ed957684SJames Smart {
971ed957684SJames Smart 	hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
972ed957684SJames Smart 	hbqmb->profiles.profile2.maxlen     = hbq_desc->maxlen;
973ed957684SJames Smart 	hbqmb->profiles.profile2.seqlenoff  = hbq_desc->seqlenoff;
974ed957684SJames Smart }
975ed957684SJames Smart 
976e59058c4SJames Smart /**
9773621a710SJames Smart  * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
978e59058c4SJames Smart  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
979e59058c4SJames Smart  * @hbq_desc: pointer to the HBQ selection profile descriptor.
980e59058c4SJames Smart  *
981e59058c4SJames Smart  * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
982e59058c4SJames Smart  * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
983e59058c4SJames Smart  * the Sequence Length Test and Byte Field Test using the fields in the
984e59058c4SJames Smart  * Selection Profile 3 extension in words 20:31.
985e59058c4SJames Smart  **/
986ed957684SJames Smart static void
987ed957684SJames Smart lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
988ed957684SJames Smart 			struct lpfc_hbq_init  *hbq_desc)
989ed957684SJames Smart {
990ed957684SJames Smart 	hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
991ed957684SJames Smart 	hbqmb->profiles.profile3.maxlen     = hbq_desc->maxlen;
992ed957684SJames Smart 	hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
993ed957684SJames Smart 	hbqmb->profiles.profile3.seqlenoff  = hbq_desc->seqlenoff;
994ed957684SJames Smart 	memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
995ed957684SJames Smart 	       sizeof(hbqmb->profiles.profile3.cmdmatch));
996ed957684SJames Smart }
997ed957684SJames Smart 
998e59058c4SJames Smart /**
9993621a710SJames Smart  * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
1000e59058c4SJames Smart  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1001e59058c4SJames Smart  * @hbq_desc: pointer to the HBQ selection profile descriptor.
1002e59058c4SJames Smart  *
1003e59058c4SJames Smart  * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
1004e59058c4SJames Smart  * HBA tests the initial frame of an incoming sequence using the frame's
1005e59058c4SJames Smart  * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
1006e59058c4SJames Smart  * and Byte Field Test using the fields in the Selection Profile 5 extension
1007e59058c4SJames Smart  * words 20:31.
1008e59058c4SJames Smart  **/
1009ed957684SJames Smart static void
1010ed957684SJames Smart lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
1011ed957684SJames Smart 			struct lpfc_hbq_init  *hbq_desc)
1012ed957684SJames Smart {
1013ed957684SJames Smart 	hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
1014ed957684SJames Smart 	hbqmb->profiles.profile5.maxlen     = hbq_desc->maxlen;
1015ed957684SJames Smart 	hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
1016ed957684SJames Smart 	hbqmb->profiles.profile5.seqlenoff  = hbq_desc->seqlenoff;
1017ed957684SJames Smart 	memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
1018ed957684SJames Smart 	       sizeof(hbqmb->profiles.profile5.cmdmatch));
1019ed957684SJames Smart }
1020ed957684SJames Smart 
1021e59058c4SJames Smart /**
10223621a710SJames Smart  * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
1023e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1024e59058c4SJames Smart  * @id: HBQ identifier.
1025e59058c4SJames Smart  * @hbq_desc: pointer to the HBA descriptor data structure.
1026e59058c4SJames Smart  * @hbq_entry_index: index of the HBQ entry data structures.
1027e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1028e59058c4SJames Smart  *
1029e59058c4SJames Smart  * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
1030e59058c4SJames Smart  * an HBQ. The configuration binds events that require buffers to a particular
1031e59058c4SJames Smart  * ring and HBQ based on a selection profile.
1032e59058c4SJames Smart  *
1033e59058c4SJames Smart  * This routine prepares the mailbox command for configuring an HBQ.
1034e59058c4SJames Smart  **/
1035ed957684SJames Smart void
103651ef4c26SJames Smart lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
103751ef4c26SJames Smart 		 struct lpfc_hbq_init *hbq_desc,
1038ed957684SJames Smart 		uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
1039ed957684SJames Smart {
1040ed957684SJames Smart 	int i;
104104c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
1042ed957684SJames Smart 	struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
1043ed957684SJames Smart 
1044ed957684SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
104551ef4c26SJames Smart 	hbqmb->hbqId = id;
1046ed957684SJames Smart 	hbqmb->entry_count = hbq_desc->entry_count;   /* # entries in HBQ */
1047ed957684SJames Smart 	hbqmb->recvNotify = hbq_desc->rn;             /* Receive
1048ed957684SJames Smart 						       * Notification */
1049ed957684SJames Smart 	hbqmb->numMask    = hbq_desc->mask_count;     /* # R_CTL/TYPE masks
1050ed957684SJames Smart 						       * # in words 0-19 */
1051ed957684SJames Smart 	hbqmb->profile    = hbq_desc->profile;	      /* Selection profile:
1052ed957684SJames Smart 						       * 0 = all,
1053ed957684SJames Smart 						       * 7 = logentry */
1054ed957684SJames Smart 	hbqmb->ringMask   = hbq_desc->ring_mask;      /* Binds HBQ to a ring
1055ed957684SJames Smart 						       * e.g. Ring0=b0001,
1056ed957684SJames Smart 						       * ring2=b0100 */
1057ed957684SJames Smart 	hbqmb->headerLen  = hbq_desc->headerLen;      /* 0 if not profile 4
1058ed957684SJames Smart 						       * or 5 */
1059ed957684SJames Smart 	hbqmb->logEntry   = hbq_desc->logEntry;       /* Set to 1 if this
1060ed957684SJames Smart 						       * HBQ will be used
1061ed957684SJames Smart 						       * for LogEntry
1062ed957684SJames Smart 						       * buffers */
1063ed957684SJames Smart 	hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
1064ed957684SJames Smart 		hbq_entry_index * sizeof(struct lpfc_hbq_entry);
1065ed957684SJames Smart 	hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
1066ed957684SJames Smart 
1067ed957684SJames Smart 	mb->mbxCommand = MBX_CONFIG_HBQ;
1068ed957684SJames Smart 	mb->mbxOwner = OWN_HOST;
1069ed957684SJames Smart 
1070ed957684SJames Smart 				/* Copy info for profiles 2,3,5. Other
1071ed957684SJames Smart 				 * profiles this area is reserved
1072ed957684SJames Smart 				 */
1073ed957684SJames Smart 	if (hbq_desc->profile == 2)
1074ed957684SJames Smart 		lpfc_build_hbq_profile2(hbqmb, hbq_desc);
1075ed957684SJames Smart 	else if (hbq_desc->profile == 3)
1076ed957684SJames Smart 		lpfc_build_hbq_profile3(hbqmb, hbq_desc);
1077ed957684SJames Smart 	else if (hbq_desc->profile == 5)
1078ed957684SJames Smart 		lpfc_build_hbq_profile5(hbqmb, hbq_desc);
1079ed957684SJames Smart 
1080ed957684SJames Smart 	/* Return if no rctl / type masks for this HBQ */
1081ed957684SJames Smart 	if (!hbq_desc->mask_count)
1082ed957684SJames Smart 		return;
1083ed957684SJames Smart 
1084ed957684SJames Smart 	/* Otherwise we setup specific rctl / type masks for this HBQ */
1085ed957684SJames Smart 	for (i = 0; i < hbq_desc->mask_count; i++) {
1086ed957684SJames Smart 		hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
1087ed957684SJames Smart 		hbqmb->hbqMasks[i].tmask  = hbq_desc->hbqMasks[i].tmask;
1088ed957684SJames Smart 		hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
1089ed957684SJames Smart 		hbqmb->hbqMasks[i].rctlmask  = hbq_desc->hbqMasks[i].rctlmask;
1090ed957684SJames Smart 	}
1091ed957684SJames Smart 
1092ed957684SJames Smart 	return;
1093ed957684SJames Smart }
1094ed957684SJames Smart 
1095e59058c4SJames Smart /**
10963621a710SJames Smart  * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
1097e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1098e59058c4SJames Smart  * @ring:
1099e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1100e59058c4SJames Smart  *
1101e59058c4SJames Smart  * The configure ring mailbox command is used to configure an IOCB ring. This
1102e59058c4SJames Smart  * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1103e59058c4SJames Smart  * ring. This is used to map incoming sequences to a particular ring whose
1104e59058c4SJames Smart  * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1105e59058c4SJames Smart  * attempt to configure a ring whose number is greater than the number
1106e59058c4SJames Smart  * specified in the Port Control Block (PCB). It is an error to issue the
1107e59058c4SJames Smart  * configure ring command more than once with the same ring number. The HBA
1108e59058c4SJames Smart  * returns an error if the driver attempts this.
1109e59058c4SJames Smart  *
1110e59058c4SJames Smart  * This routine prepares the mailbox command for configuring IOCB ring.
1111e59058c4SJames Smart  **/
1112dea3101eS void
1113dea3101eS lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
1114dea3101eS {
1115dea3101eS 	int i;
111604c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
1117dea3101eS 	struct lpfc_sli *psli;
1118dea3101eS 	struct lpfc_sli_ring *pring;
1119dea3101eS 
1120dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1121dea3101eS 
1122dea3101eS 	mb->un.varCfgRing.ring = ring;
1123dea3101eS 	mb->un.varCfgRing.maxOrigXchg = 0;
1124dea3101eS 	mb->un.varCfgRing.maxRespXchg = 0;
1125dea3101eS 	mb->un.varCfgRing.recvNotify = 1;
1126dea3101eS 
1127dea3101eS 	psli = &phba->sli;
1128dea3101eS 	pring = &psli->ring[ring];
1129dea3101eS 	mb->un.varCfgRing.numMask = pring->num_mask;
1130dea3101eS 	mb->mbxCommand = MBX_CONFIG_RING;
1131dea3101eS 	mb->mbxOwner = OWN_HOST;
1132dea3101eS 
1133dea3101eS 	/* Is this ring configured for a specific profile */
1134dea3101eS 	if (pring->prt[0].profile) {
1135dea3101eS 		mb->un.varCfgRing.profile = pring->prt[0].profile;
1136dea3101eS 		return;
1137dea3101eS 	}
1138dea3101eS 
1139dea3101eS 	/* Otherwise we setup specific rctl / type masks for this ring */
1140dea3101eS 	for (i = 0; i < pring->num_mask; i++) {
1141dea3101eS 		mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
11426a9c52cfSJames Smart 		if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ)
1143dea3101eS 			mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
1144dea3101eS 		else
1145dea3101eS 			mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
1146dea3101eS 		mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
1147dea3101eS 		mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
1148dea3101eS 	}
1149dea3101eS 
1150dea3101eS 	return;
1151dea3101eS }
1152dea3101eS 
1153e59058c4SJames Smart /**
11543621a710SJames Smart  * lpfc_config_port - Prepare a mailbox command for configuring port
1155e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1156e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1157e59058c4SJames Smart  *
1158e59058c4SJames Smart  * The configure port mailbox command is used to identify the Port Control
1159e59058c4SJames Smart  * Block (PCB) in the driver memory. After this command is issued, the
1160e59058c4SJames Smart  * driver must not access the mailbox in the HBA without first resetting
1161e59058c4SJames Smart  * the HBA. The HBA may copy the PCB information to internal storage for
1162e59058c4SJames Smart  * subsequent use; the driver can not change the PCB information unless it
1163e59058c4SJames Smart  * resets the HBA.
1164e59058c4SJames Smart  *
1165e59058c4SJames Smart  * This routine prepares the mailbox command for configuring port.
1166e59058c4SJames Smart  **/
1167dea3101eS void
1168dea3101eS lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1169dea3101eS {
1170ed957684SJames Smart 	MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
117104c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
1172dea3101eS 	dma_addr_t pdma_addr;
1173dea3101eS 	uint32_t bar_low, bar_high;
1174dea3101eS 	size_t offset;
11754cc2da1dSJames.Smart@Emulex.Com 	struct lpfc_hgp hgp;
1176f91b392cSJames.Smart@Emulex.Com 	int i;
1177ed957684SJames Smart 	uint32_t pgp_offset;
1178dea3101eS 
1179dea3101eS 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1180dea3101eS 	mb->mbxCommand = MBX_CONFIG_PORT;
1181dea3101eS 	mb->mbxOwner = OWN_HOST;
1182dea3101eS 
1183dea3101eS 	mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
1184dea3101eS 
118534b02dcdSJames Smart 	offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
118634b02dcdSJames Smart 	pdma_addr = phba->slim2p.phys + offset;
1187dea3101eS 	mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
1188dea3101eS 	mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
1189dea3101eS 
119097207482SJames Smart 	/* Always Host Group Pointer is in SLIM */
119197207482SJames Smart 	mb->un.varCfgPort.hps = 1;
119297207482SJames Smart 
1193ed957684SJames Smart 	/* If HBA supports SLI=3 ask for it */
1194ed957684SJames Smart 
119504c68496SJames Smart 	if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
1196e2a0a9d6SJames Smart 		if (phba->cfg_enable_bg)
1197e2a0a9d6SJames Smart 			mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
119804c68496SJames Smart 		mb->un.varCfgPort.cdss = 1; /* Configure Security */
1199ed957684SJames Smart 		mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
120034b02dcdSJames Smart 		mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
120134b02dcdSJames Smart 		mb->un.varCfgPort.cinb = 1; /* Interrupt Notification Block */
120251ef4c26SJames Smart 		mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
120378b2d852SJames Smart 		if (phba->max_vpi && phba->cfg_enable_npiv &&
120492d7f7b0SJames Smart 		    phba->vpd.sli3Feat.cmv) {
120504c68496SJames Smart 			mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI;
120692d7f7b0SJames Smart 			mb->un.varCfgPort.cmv = 1;
120792d7f7b0SJames Smart 		} else
120892d7f7b0SJames Smart 			mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
120992d7f7b0SJames Smart 	} else
121004c68496SJames Smart 		phba->sli_rev = LPFC_SLI_REV2;
121192d7f7b0SJames Smart 	mb->un.varCfgPort.sli_mode = phba->sli_rev;
1212ed957684SJames Smart 
1213dea3101eS 	/* Now setup pcb */
121434b02dcdSJames Smart 	phba->pcb->type = TYPE_NATIVE_SLI2;
121534b02dcdSJames Smart 	phba->pcb->feature = FEATURE_INITIAL_SLI2;
1216dea3101eS 
1217dea3101eS 	/* Setup Mailbox pointers */
121834b02dcdSJames Smart 	phba->pcb->mailBoxSize = sizeof(MAILBOX_t);
121934b02dcdSJames Smart 	offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
122034b02dcdSJames Smart 	pdma_addr = phba->slim2p.phys + offset;
122134b02dcdSJames Smart 	phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
122234b02dcdSJames Smart 	phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
1223dea3101eS 
1224dea3101eS 	/*
1225dea3101eS 	 * Setup Host Group ring pointer.
1226dea3101eS 	 *
1227dea3101eS 	 * For efficiency reasons, the ring get/put pointers can be
1228dea3101eS 	 * placed in adapter memory (SLIM) rather than in host memory.
1229dea3101eS 	 * This allows firmware to avoid PCI reads/writes when updating
1230dea3101eS 	 * and checking pointers.
1231dea3101eS 	 *
1232dea3101eS 	 * The firmware recognizes the use of SLIM memory by comparing
1233dea3101eS 	 * the address of the get/put pointers structure with that of
1234dea3101eS 	 * the SLIM BAR (BAR0).
1235dea3101eS 	 *
1236dea3101eS 	 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1237dea3101eS 	 * (the hardware's view of the base address), not the OS's
1238dea3101eS 	 * value of pci_resource_start() as the OS value may be a cookie
1239dea3101eS 	 * for ioremap/iomap.
1240dea3101eS 	 */
1241dea3101eS 
1242dea3101eS 
1243dea3101eS 	pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
1244dea3101eS 	pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
1245dea3101eS 
1246ed957684SJames Smart 	/*
1247ed957684SJames Smart 	 * Set up HGP - Port Memory
1248ed957684SJames Smart 	 *
1249ed957684SJames Smart 	 * The port expects the host get/put pointers to reside in memory
1250ed957684SJames Smart 	 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1251ed957684SJames Smart 	 * area of SLIM.  In SLI-2 mode, there's an additional 16 reserved
1252ed957684SJames Smart 	 * words (0x40 bytes).  This area is not reserved if HBQs are
1253ed957684SJames Smart 	 * configured in SLI-3.
1254ed957684SJames Smart 	 *
1255ed957684SJames Smart 	 * CR0Put    - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1256ed957684SJames Smart 	 * RR0Get                      0xc4              0x84
1257ed957684SJames Smart 	 * CR1Put                      0xc8              0x88
1258ed957684SJames Smart 	 * RR1Get                      0xcc              0x8c
1259ed957684SJames Smart 	 * CR2Put                      0xd0              0x90
1260ed957684SJames Smart 	 * RR2Get                      0xd4              0x94
1261ed957684SJames Smart 	 * CR3Put                      0xd8              0x98
1262ed957684SJames Smart 	 * RR3Get                      0xdc              0x9c
1263ed957684SJames Smart 	 *
1264ed957684SJames Smart 	 * Reserved                    0xa0-0xbf
1265ed957684SJames Smart 	 *    If HBQs configured:
1266ed957684SJames Smart 	 *                         HBQ 0 Put ptr  0xc0
1267ed957684SJames Smart 	 *                         HBQ 1 Put ptr  0xc4
1268ed957684SJames Smart 	 *                         HBQ 2 Put ptr  0xc8
1269ed957684SJames Smart 	 *                         ......
1270ed957684SJames Smart 	 *                         HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1271ed957684SJames Smart 	 *
1272ed957684SJames Smart 	 */
1273ed957684SJames Smart 
1274ed957684SJames Smart 	if (phba->sli_rev == 3) {
1275ed957684SJames Smart 		phba->host_gp = &mb_slim->us.s3.host[0];
1276ed957684SJames Smart 		phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
1277ed957684SJames Smart 	} else {
1278ed957684SJames Smart 		phba->host_gp = &mb_slim->us.s2.host[0];
1279ed957684SJames Smart 		phba->hbq_put = NULL;
1280ed957684SJames Smart 	}
1281dea3101eS 
1282dea3101eS 	/* mask off BAR0's flag bits 0 - 3 */
128334b02dcdSJames Smart 	phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
1284ed957684SJames Smart 		(void __iomem *)phba->host_gp -
1285ed957684SJames Smart 		(void __iomem *)phba->MBslimaddr;
1286dea3101eS 	if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
128734b02dcdSJames Smart 		phba->pcb->hgpAddrHigh = bar_high;
1288dea3101eS 	else
128934b02dcdSJames Smart 		phba->pcb->hgpAddrHigh = 0;
1290dea3101eS 	/* write HGP data to SLIM at the required longword offset */
12914cc2da1dSJames.Smart@Emulex.Com 	memset(&hgp, 0, sizeof(struct lpfc_hgp));
1292f91b392cSJames.Smart@Emulex.Com 
1293f91b392cSJames.Smart@Emulex.Com 	for (i=0; i < phba->sli.num_rings; i++) {
1294ed957684SJames Smart 		lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
1295ed957684SJames Smart 				    sizeof(*phba->host_gp));
1296f91b392cSJames.Smart@Emulex.Com 	}
1297dea3101eS 
12988f34f4ceSJames Smart 	/* Setup Port Group offset */
12998f34f4ceSJames Smart 	if (phba->sli_rev == 3)
130034b02dcdSJames Smart 		pgp_offset = offsetof(struct lpfc_sli2_slim,
130134b02dcdSJames Smart 				      mbx.us.s3_pgp.port);
13028f34f4ceSJames Smart 	else
130334b02dcdSJames Smart 		pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
130434b02dcdSJames Smart 	pdma_addr = phba->slim2p.phys + pgp_offset;
130534b02dcdSJames Smart 	phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
130634b02dcdSJames Smart 	phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
1307dea3101eS 
1308dea3101eS 	/* Use callback routine to setp rings in the pcb */
1309dea3101eS 	lpfc_config_pcb_setup(phba);
1310dea3101eS 
1311dea3101eS 	/* special handling for LC HBAs */
1312dea3101eS 	if (lpfc_is_LC_HBA(phba->pcidev->device)) {
1313dea3101eS 		uint32_t hbainit[5];
1314dea3101eS 
1315dea3101eS 		lpfc_hba_init(phba, hbainit);
1316dea3101eS 
1317dea3101eS 		memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
1318dea3101eS 	}
1319dea3101eS 
1320dea3101eS 	/* Swap PCB if needed */
132134b02dcdSJames Smart 	lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
1322dea3101eS }
1323dea3101eS 
1324e59058c4SJames Smart /**
13253621a710SJames Smart  * lpfc_kill_board - Prepare a mailbox command for killing board
1326e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1327e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1328e59058c4SJames Smart  *
1329e59058c4SJames Smart  * The kill board mailbox command is used to tell firmware to perform a
1330e59058c4SJames Smart  * graceful shutdown of a channel on a specified board to prepare for reset.
1331e59058c4SJames Smart  * When the kill board mailbox command is received, the ER3 bit is set to 1
1332e59058c4SJames Smart  * in the Host Status register and the ER Attention bit is set to 1 in the
1333e59058c4SJames Smart  * Host Attention register of the HBA function that received the kill board
1334e59058c4SJames Smart  * command.
1335e59058c4SJames Smart  *
1336e59058c4SJames Smart  * This routine prepares the mailbox command for killing the board in
1337e59058c4SJames Smart  * preparation for a graceful shutdown.
1338e59058c4SJames Smart  **/
1339dea3101eS void
134041415862SJamie Wellnitz lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
134141415862SJamie Wellnitz {
134204c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
134341415862SJamie Wellnitz 
134441415862SJamie Wellnitz 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
134541415862SJamie Wellnitz 	mb->mbxCommand = MBX_KILL_BOARD;
134641415862SJamie Wellnitz 	mb->mbxOwner = OWN_HOST;
134741415862SJamie Wellnitz 	return;
134841415862SJamie Wellnitz }
134941415862SJamie Wellnitz 
1350e59058c4SJames Smart /**
13513621a710SJames Smart  * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
1352e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1353e59058c4SJames Smart  * @mbq: pointer to the driver internal queue element for mailbox command.
1354e59058c4SJames Smart  *
1355e59058c4SJames Smart  * Driver maintains a internal mailbox command queue implemented as a linked
1356e59058c4SJames Smart  * list. When a mailbox command is issued, it shall be put into the mailbox
1357e59058c4SJames Smart  * command queue such that they shall be processed orderly as HBA can process
1358e59058c4SJames Smart  * one mailbox command at a time.
1359e59058c4SJames Smart  **/
136041415862SJamie Wellnitz void
1361dea3101eS lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1362dea3101eS {
1363dea3101eS 	struct lpfc_sli *psli;
1364dea3101eS 
1365dea3101eS 	psli = &phba->sli;
1366dea3101eS 
1367dea3101eS 	list_add_tail(&mbq->list, &psli->mboxq);
1368dea3101eS 
1369dea3101eS 	psli->mboxq_cnt++;
1370dea3101eS 
1371dea3101eS 	return;
1372dea3101eS }
1373dea3101eS 
1374e59058c4SJames Smart /**
13753621a710SJames Smart  * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
1376e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1377e59058c4SJames Smart  *
1378e59058c4SJames Smart  * Driver maintains a internal mailbox command queue implemented as a linked
1379e59058c4SJames Smart  * list. When a mailbox command is issued, it shall be put into the mailbox
1380e59058c4SJames Smart  * command queue such that they shall be processed orderly as HBA can process
1381e59058c4SJames Smart  * one mailbox command at a time. After HBA finished processing a mailbox
1382e59058c4SJames Smart  * command, the driver will remove a pending mailbox command from the head of
1383e59058c4SJames Smart  * the mailbox command queue and send to the HBA for processing.
1384e59058c4SJames Smart  *
1385e59058c4SJames Smart  * Return codes
1386e59058c4SJames Smart  *    pointer to the driver internal queue element for mailbox command.
1387e59058c4SJames Smart  **/
1388dea3101eS LPFC_MBOXQ_t *
1389dea3101eS lpfc_mbox_get(struct lpfc_hba * phba)
1390dea3101eS {
1391dea3101eS 	LPFC_MBOXQ_t *mbq = NULL;
1392dea3101eS 	struct lpfc_sli *psli = &phba->sli;
1393dea3101eS 
13942e0fef85SJames Smart 	list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
139592d7f7b0SJames Smart 	if (mbq)
1396dea3101eS 		psli->mboxq_cnt--;
1397dea3101eS 
1398dea3101eS 	return mbq;
1399dea3101eS }
1400a309a6b6SJames Smart 
1401e59058c4SJames Smart /**
140204c68496SJames Smart  * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
140304c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
140404c68496SJames Smart  * @mbq: pointer to the driver internal queue element for mailbox command.
140504c68496SJames Smart  *
140604c68496SJames Smart  * This routine put the completed mailbox command into the mailbox command
140704c68496SJames Smart  * complete list. This is the unlocked version of the routine. The mailbox
140804c68496SJames Smart  * complete list is used by the driver worker thread to process mailbox
140904c68496SJames Smart  * complete callback functions outside the driver interrupt handler.
141004c68496SJames Smart  **/
141104c68496SJames Smart void
141204c68496SJames Smart __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
141304c68496SJames Smart {
141404c68496SJames Smart 	list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
141504c68496SJames Smart }
141604c68496SJames Smart 
141704c68496SJames Smart /**
14183621a710SJames Smart  * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
1419e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1420e59058c4SJames Smart  * @mbq: pointer to the driver internal queue element for mailbox command.
1421e59058c4SJames Smart  *
1422e59058c4SJames Smart  * This routine put the completed mailbox command into the mailbox command
142304c68496SJames Smart  * complete list. This is the locked version of the routine. The mailbox
142404c68496SJames Smart  * complete list is used by the driver worker thread to process mailbox
142504c68496SJames Smart  * complete callback functions outside the driver interrupt handler.
1426e59058c4SJames Smart  **/
142792d7f7b0SJames Smart void
142892d7f7b0SJames Smart lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
142992d7f7b0SJames Smart {
14305b75da2fSJames Smart 	unsigned long iflag;
14315b75da2fSJames Smart 
1432b1c11812SJoe Perches 	/* This function expects to be called from interrupt context */
14335b75da2fSJames Smart 	spin_lock_irqsave(&phba->hbalock, iflag);
143404c68496SJames Smart 	__lpfc_mbox_cmpl_put(phba, mbq);
14355b75da2fSJames Smart 	spin_unlock_irqrestore(&phba->hbalock, iflag);
143692d7f7b0SJames Smart 	return;
143792d7f7b0SJames Smart }
143892d7f7b0SJames Smart 
1439e59058c4SJames Smart /**
144004c68496SJames Smart  * lpfc_mbox_cmd_check - Check the validality of a mailbox command
144104c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
144204c68496SJames Smart  * @mboxq: pointer to the driver internal queue element for mailbox command.
144304c68496SJames Smart  *
144404c68496SJames Smart  * This routine is to check whether a mailbox command is valid to be issued.
144504c68496SJames Smart  * This check will be performed by both the mailbox issue API when a client
144604c68496SJames Smart  * is to issue a mailbox command to the mailbox transport.
144704c68496SJames Smart  *
144804c68496SJames Smart  * Return 0 - pass the check, -ENODEV - fail the check
144904c68496SJames Smart  **/
145004c68496SJames Smart int
145104c68496SJames Smart lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
145204c68496SJames Smart {
145304c68496SJames Smart 	/* Mailbox command that have a completion handler must also have a
145404c68496SJames Smart 	 * vport specified.
145504c68496SJames Smart 	 */
145604c68496SJames Smart 	if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
145704c68496SJames Smart 	    mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
145804c68496SJames Smart 		if (!mboxq->vport) {
145904c68496SJames Smart 			lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
146004c68496SJames Smart 					"1814 Mbox x%x failed, no vport\n",
146104c68496SJames Smart 					mboxq->u.mb.mbxCommand);
146204c68496SJames Smart 			dump_stack();
146304c68496SJames Smart 			return -ENODEV;
146404c68496SJames Smart 		}
146504c68496SJames Smart 	}
146604c68496SJames Smart 	return 0;
146704c68496SJames Smart }
146804c68496SJames Smart 
146904c68496SJames Smart /**
147004c68496SJames Smart  * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
147104c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
147204c68496SJames Smart  *
147304c68496SJames Smart  * This routine is to check whether the HBA device is ready for posting a
147404c68496SJames Smart  * mailbox command. It is used by the mailbox transport API at the time the
147504c68496SJames Smart  * to post a mailbox command to the device.
147604c68496SJames Smart  *
147704c68496SJames Smart  * Return 0 - pass the check, -ENODEV - fail the check
147804c68496SJames Smart  **/
147904c68496SJames Smart int
148004c68496SJames Smart lpfc_mbox_dev_check(struct lpfc_hba *phba)
148104c68496SJames Smart {
148204c68496SJames Smart 	/* If the PCI channel is in offline state, do not issue mbox */
148304c68496SJames Smart 	if (unlikely(pci_channel_offline(phba->pcidev)))
148404c68496SJames Smart 		return -ENODEV;
148504c68496SJames Smart 
148604c68496SJames Smart 	/* If the HBA is in error state, do not issue mbox */
148704c68496SJames Smart 	if (phba->link_state == LPFC_HBA_ERROR)
148804c68496SJames Smart 		return -ENODEV;
148904c68496SJames Smart 
149004c68496SJames Smart 	return 0;
149104c68496SJames Smart }
149204c68496SJames Smart 
149304c68496SJames Smart /**
14943621a710SJames Smart  * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
1495e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1496e59058c4SJames Smart  * @cmd: mailbox command code.
1497e59058c4SJames Smart  *
1498e59058c4SJames Smart  * This routine retrieves the proper timeout value according to the mailbox
1499e59058c4SJames Smart  * command code.
1500e59058c4SJames Smart  *
1501e59058c4SJames Smart  * Return codes
1502e59058c4SJames Smart  *    Timeout value to be used for the given mailbox command
1503e59058c4SJames Smart  **/
1504a309a6b6SJames Smart int
1505a309a6b6SJames Smart lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
1506a309a6b6SJames Smart {
1507a309a6b6SJames Smart 	switch (cmd) {
1508a309a6b6SJames Smart 	case MBX_WRITE_NV:	/* 0x03 */
1509a309a6b6SJames Smart 	case MBX_UPDATE_CFG:	/* 0x1B */
1510a309a6b6SJames Smart 	case MBX_DOWN_LOAD:	/* 0x1C */
1511a309a6b6SJames Smart 	case MBX_DEL_LD_ENTRY:	/* 0x1D */
1512a309a6b6SJames Smart 	case MBX_LOAD_AREA:	/* 0x81 */
151309372820SJames Smart 	case MBX_WRITE_WWN:     /* 0x98 */
1514a309a6b6SJames Smart 	case MBX_LOAD_EXP_ROM:	/* 0x9C */
1515a309a6b6SJames Smart 		return LPFC_MBOX_TMO_FLASH_CMD;
151604c68496SJames Smart 	case MBX_SLI4_CONFIG:	/* 0x9b */
151704c68496SJames Smart 		return LPFC_MBOX_SLI4_CONFIG_TMO;
1518a309a6b6SJames Smart 	}
1519a309a6b6SJames Smart 	return LPFC_MBOX_TMO;
1520a309a6b6SJames Smart }
152104c68496SJames Smart 
152204c68496SJames Smart /**
152304c68496SJames Smart  * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
152404c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
152504c68496SJames Smart  * @sgentry: sge entry index.
152604c68496SJames Smart  * @phyaddr: physical address for the sge
152704c68496SJames Smart  * @length: Length of the sge.
152804c68496SJames Smart  *
152904c68496SJames Smart  * This routine sets up an entry in the non-embedded mailbox command at the sge
153004c68496SJames Smart  * index location.
153104c68496SJames Smart  **/
153204c68496SJames Smart void
153304c68496SJames Smart lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry,
153404c68496SJames Smart 		      dma_addr_t phyaddr, uint32_t length)
153504c68496SJames Smart {
153604c68496SJames Smart 	struct lpfc_mbx_nembed_cmd *nembed_sge;
153704c68496SJames Smart 
153804c68496SJames Smart 	nembed_sge = (struct lpfc_mbx_nembed_cmd *)
153904c68496SJames Smart 				&mbox->u.mqe.un.nembed_cmd;
154004c68496SJames Smart 	nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr);
154104c68496SJames Smart 	nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr);
154204c68496SJames Smart 	nembed_sge->sge[sgentry].length = length;
154304c68496SJames Smart }
154404c68496SJames Smart 
154504c68496SJames Smart /**
154604c68496SJames Smart  * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
154704c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
154804c68496SJames Smart  * @sgentry: sge entry index.
154904c68496SJames Smart  *
155004c68496SJames Smart  * This routine gets an entry from the non-embedded mailbox command at the sge
155104c68496SJames Smart  * index location.
155204c68496SJames Smart  **/
155304c68496SJames Smart void
155404c68496SJames Smart lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry,
155504c68496SJames Smart 		      struct lpfc_mbx_sge *sge)
155604c68496SJames Smart {
155704c68496SJames Smart 	struct lpfc_mbx_nembed_cmd *nembed_sge;
155804c68496SJames Smart 
155904c68496SJames Smart 	nembed_sge = (struct lpfc_mbx_nembed_cmd *)
156004c68496SJames Smart 				&mbox->u.mqe.un.nembed_cmd;
156104c68496SJames Smart 	sge->pa_lo = nembed_sge->sge[sgentry].pa_lo;
156204c68496SJames Smart 	sge->pa_hi = nembed_sge->sge[sgentry].pa_hi;
156304c68496SJames Smart 	sge->length = nembed_sge->sge[sgentry].length;
156404c68496SJames Smart }
156504c68496SJames Smart 
156604c68496SJames Smart /**
156704c68496SJames Smart  * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
156804c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
156904c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
157004c68496SJames Smart  *
157104c68496SJames Smart  * This routine frees SLI4 specific mailbox command for sending IOCTL command.
157204c68496SJames Smart  **/
157304c68496SJames Smart void
157404c68496SJames Smart lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
157504c68496SJames Smart {
157604c68496SJames Smart 	struct lpfc_mbx_sli4_config *sli4_cfg;
157704c68496SJames Smart 	struct lpfc_mbx_sge sge;
157804c68496SJames Smart 	dma_addr_t phyaddr;
157904c68496SJames Smart 	uint32_t sgecount, sgentry;
158004c68496SJames Smart 
158104c68496SJames Smart 	sli4_cfg = &mbox->u.mqe.un.sli4_config;
158204c68496SJames Smart 
158304c68496SJames Smart 	/* For embedded mbox command, just free the mbox command */
158404c68496SJames Smart 	if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
158504c68496SJames Smart 		mempool_free(mbox, phba->mbox_mem_pool);
158604c68496SJames Smart 		return;
158704c68496SJames Smart 	}
158804c68496SJames Smart 
158904c68496SJames Smart 	/* For non-embedded mbox command, we need to free the pages first */
159004c68496SJames Smart 	sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr);
159104c68496SJames Smart 	/* There is nothing we can do if there is no sge address array */
159204c68496SJames Smart 	if (unlikely(!mbox->sge_array)) {
159304c68496SJames Smart 		mempool_free(mbox, phba->mbox_mem_pool);
159404c68496SJames Smart 		return;
159504c68496SJames Smart 	}
159604c68496SJames Smart 	/* Each non-embedded DMA memory was allocated in the length of a page */
159704c68496SJames Smart 	for (sgentry = 0; sgentry < sgecount; sgentry++) {
159804c68496SJames Smart 		lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge);
159904c68496SJames Smart 		phyaddr = getPaddr(sge.pa_hi, sge.pa_lo);
160004c68496SJames Smart 		dma_free_coherent(&phba->pcidev->dev, PAGE_SIZE,
160104c68496SJames Smart 				  mbox->sge_array->addr[sgentry], phyaddr);
160204c68496SJames Smart 	}
160304c68496SJames Smart 	/* Free the sge address array memory */
160404c68496SJames Smart 	kfree(mbox->sge_array);
160504c68496SJames Smart 	/* Finally, free the mailbox command itself */
160604c68496SJames Smart 	mempool_free(mbox, phba->mbox_mem_pool);
160704c68496SJames Smart }
160804c68496SJames Smart 
160904c68496SJames Smart /**
161004c68496SJames Smart  * lpfc_sli4_config - Initialize the  SLI4 Config Mailbox command
161104c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
161204c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
161304c68496SJames Smart  * @subsystem: The sli4 config sub mailbox subsystem.
161404c68496SJames Smart  * @opcode: The sli4 config sub mailbox command opcode.
161504c68496SJames Smart  * @length: Length of the sli4 config mailbox command.
161604c68496SJames Smart  *
161704c68496SJames Smart  * This routine sets up the header fields of SLI4 specific mailbox command
161804c68496SJames Smart  * for sending IOCTL command.
161904c68496SJames Smart  *
162004c68496SJames Smart  * Return: the actual length of the mbox command allocated (mostly useful
162104c68496SJames Smart  *         for none embedded mailbox command).
162204c68496SJames Smart  **/
162304c68496SJames Smart int
162404c68496SJames Smart lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
162504c68496SJames Smart 		 uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb)
162604c68496SJames Smart {
162704c68496SJames Smart 	struct lpfc_mbx_sli4_config *sli4_config;
162804c68496SJames Smart 	union lpfc_sli4_cfg_shdr *cfg_shdr = NULL;
162904c68496SJames Smart 	uint32_t alloc_len;
163004c68496SJames Smart 	uint32_t resid_len;
163104c68496SJames Smart 	uint32_t pagen, pcount;
163204c68496SJames Smart 	void *viraddr;
163304c68496SJames Smart 	dma_addr_t phyaddr;
163404c68496SJames Smart 
163504c68496SJames Smart 	/* Set up SLI4 mailbox command header fields */
163604c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
163704c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG);
163804c68496SJames Smart 
163904c68496SJames Smart 	/* Set up SLI4 ioctl command header fields */
164004c68496SJames Smart 	sli4_config = &mbox->u.mqe.un.sli4_config;
164104c68496SJames Smart 
164204c68496SJames Smart 	/* Setup for the embedded mbox command */
164304c68496SJames Smart 	if (emb) {
164404c68496SJames Smart 		/* Set up main header fields */
164504c68496SJames Smart 		bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
164604c68496SJames Smart 		sli4_config->header.cfg_mhdr.payload_length =
164704c68496SJames Smart 					LPFC_MBX_CMD_HDR_LENGTH + length;
164804c68496SJames Smart 		/* Set up sub-header fields following main header */
164904c68496SJames Smart 		bf_set(lpfc_mbox_hdr_opcode,
165004c68496SJames Smart 			&sli4_config->header.cfg_shdr.request, opcode);
165104c68496SJames Smart 		bf_set(lpfc_mbox_hdr_subsystem,
165204c68496SJames Smart 			&sli4_config->header.cfg_shdr.request, subsystem);
165304c68496SJames Smart 		sli4_config->header.cfg_shdr.request.request_length = length;
165404c68496SJames Smart 		return length;
165504c68496SJames Smart 	}
165604c68496SJames Smart 
165704c68496SJames Smart 	/* Setup for the none-embedded mbox command */
165804c68496SJames Smart 	pcount = (PAGE_ALIGN(length))/PAGE_SIZE;
165904c68496SJames Smart 	pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ?
166004c68496SJames Smart 				LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount;
166104c68496SJames Smart 	/* Allocate record for keeping SGE virtual addresses */
166204c68496SJames Smart 	mbox->sge_array = kmalloc(sizeof(struct lpfc_mbx_nembed_sge_virt),
166304c68496SJames Smart 				  GFP_KERNEL);
16646a9c52cfSJames Smart 	if (!mbox->sge_array) {
16656a9c52cfSJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
16666a9c52cfSJames Smart 				"2527 Failed to allocate non-embedded SGE "
16676a9c52cfSJames Smart 				"array.\n");
166804c68496SJames Smart 		return 0;
16696a9c52cfSJames Smart 	}
167004c68496SJames Smart 	for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) {
167104c68496SJames Smart 		/* The DMA memory is always allocated in the length of a
167204c68496SJames Smart 		 * page even though the last SGE might not fill up to a
167304c68496SJames Smart 		 * page, this is used as a priori size of PAGE_SIZE for
167404c68496SJames Smart 		 * the later DMA memory free.
167504c68496SJames Smart 		 */
167604c68496SJames Smart 		viraddr = dma_alloc_coherent(&phba->pcidev->dev, PAGE_SIZE,
167704c68496SJames Smart 					     &phyaddr, GFP_KERNEL);
167804c68496SJames Smart 		/* In case of malloc fails, proceed with whatever we have */
167904c68496SJames Smart 		if (!viraddr)
168004c68496SJames Smart 			break;
1681d11e31ddSJames Smart 		memset(viraddr, 0, PAGE_SIZE);
168204c68496SJames Smart 		mbox->sge_array->addr[pagen] = viraddr;
168304c68496SJames Smart 		/* Keep the first page for later sub-header construction */
168404c68496SJames Smart 		if (pagen == 0)
168504c68496SJames Smart 			cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr;
168604c68496SJames Smart 		resid_len = length - alloc_len;
168704c68496SJames Smart 		if (resid_len > PAGE_SIZE) {
168804c68496SJames Smart 			lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
168904c68496SJames Smart 					      PAGE_SIZE);
169004c68496SJames Smart 			alloc_len += PAGE_SIZE;
169104c68496SJames Smart 		} else {
169204c68496SJames Smart 			lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
169304c68496SJames Smart 					      resid_len);
169404c68496SJames Smart 			alloc_len = length;
169504c68496SJames Smart 		}
169604c68496SJames Smart 	}
169704c68496SJames Smart 
169804c68496SJames Smart 	/* Set up main header fields in mailbox command */
169904c68496SJames Smart 	sli4_config->header.cfg_mhdr.payload_length = alloc_len;
170004c68496SJames Smart 	bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen);
170104c68496SJames Smart 
170204c68496SJames Smart 	/* Set up sub-header fields into the first page */
170304c68496SJames Smart 	if (pagen > 0) {
170404c68496SJames Smart 		bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode);
170504c68496SJames Smart 		bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem);
170604c68496SJames Smart 		cfg_shdr->request.request_length =
170704c68496SJames Smart 				alloc_len - sizeof(union  lpfc_sli4_cfg_shdr);
170804c68496SJames Smart 	}
170904c68496SJames Smart 	/* The sub-header is in DMA memory, which needs endian converstion */
171072100cc4SJames Smart 	if (cfg_shdr)
171104c68496SJames Smart 		lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
171204c68496SJames Smart 			      sizeof(union  lpfc_sli4_cfg_shdr));
171304c68496SJames Smart 
171404c68496SJames Smart 	return alloc_len;
171504c68496SJames Smart }
171604c68496SJames Smart 
171704c68496SJames Smart /**
171804c68496SJames Smart  * lpfc_sli4_mbox_opcode_get - Get the opcode from a sli4 mailbox command
171904c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
172004c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
172104c68496SJames Smart  *
172204c68496SJames Smart  * This routine gets the opcode from a SLI4 specific mailbox command for
172304c68496SJames Smart  * sending IOCTL command. If the mailbox command is not MBX_SLI4_CONFIG
172404c68496SJames Smart  * (0x9B) or if the IOCTL sub-header is not present, opcode 0x0 shall be
172504c68496SJames Smart  * returned.
172604c68496SJames Smart  **/
172704c68496SJames Smart uint8_t
172804c68496SJames Smart lpfc_sli4_mbox_opcode_get(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
172904c68496SJames Smart {
173004c68496SJames Smart 	struct lpfc_mbx_sli4_config *sli4_cfg;
173104c68496SJames Smart 	union lpfc_sli4_cfg_shdr *cfg_shdr;
173204c68496SJames Smart 
173304c68496SJames Smart 	if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
173404c68496SJames Smart 		return 0;
173504c68496SJames Smart 	sli4_cfg = &mbox->u.mqe.un.sli4_config;
173604c68496SJames Smart 
173704c68496SJames Smart 	/* For embedded mbox command, get opcode from embedded sub-header*/
173804c68496SJames Smart 	if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
173904c68496SJames Smart 		cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
174004c68496SJames Smart 		return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
174104c68496SJames Smart 	}
174204c68496SJames Smart 
174304c68496SJames Smart 	/* For non-embedded mbox command, get opcode from first dma page */
174404c68496SJames Smart 	if (unlikely(!mbox->sge_array))
174504c68496SJames Smart 		return 0;
174604c68496SJames Smart 	cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
174704c68496SJames Smart 	return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
174804c68496SJames Smart }
174904c68496SJames Smart 
175004c68496SJames Smart /**
17510c9ab6f5SJames Smart  * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd
1752ecfd03c6SJames Smart  * @phba: pointer to lpfc hba data structure.
1753ecfd03c6SJames Smart  * @fcf_index: index to fcf table.
1754ecfd03c6SJames Smart  *
1755ecfd03c6SJames Smart  * This routine routine allocates and constructs non-embedded mailbox command
1756ecfd03c6SJames Smart  * for reading a FCF table entry refered by @fcf_index.
1757ecfd03c6SJames Smart  *
1758ecfd03c6SJames Smart  * Return: pointer to the mailbox command constructed if successful, otherwise
1759ecfd03c6SJames Smart  * NULL.
1760ecfd03c6SJames Smart  **/
1761ecfd03c6SJames Smart int
17620c9ab6f5SJames Smart lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *phba,
1763ecfd03c6SJames Smart 			   struct lpfcMboxq *mboxq,
1764ecfd03c6SJames Smart 			   uint16_t fcf_index)
1765ecfd03c6SJames Smart {
1766ecfd03c6SJames Smart 	void *virt_addr;
1767ecfd03c6SJames Smart 	dma_addr_t phys_addr;
1768ecfd03c6SJames Smart 	uint8_t *bytep;
1769ecfd03c6SJames Smart 	struct lpfc_mbx_sge sge;
1770ecfd03c6SJames Smart 	uint32_t alloc_len, req_len;
1771ecfd03c6SJames Smart 	struct lpfc_mbx_read_fcf_tbl *read_fcf;
1772ecfd03c6SJames Smart 
1773ecfd03c6SJames Smart 	if (!mboxq)
1774ecfd03c6SJames Smart 		return -ENOMEM;
1775ecfd03c6SJames Smart 
1776ecfd03c6SJames Smart 	req_len = sizeof(struct fcf_record) +
1777ecfd03c6SJames Smart 		  sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
1778ecfd03c6SJames Smart 
1779ecfd03c6SJames Smart 	/* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
1780ecfd03c6SJames Smart 	alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
1781ecfd03c6SJames Smart 			LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
1782ecfd03c6SJames Smart 			LPFC_SLI4_MBX_NEMBED);
1783ecfd03c6SJames Smart 
1784ecfd03c6SJames Smart 	if (alloc_len < req_len) {
1785ecfd03c6SJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1786ecfd03c6SJames Smart 				"0291 Allocated DMA memory size (x%x) is "
1787ecfd03c6SJames Smart 				"less than the requested DMA memory "
1788ecfd03c6SJames Smart 				"size (x%x)\n", alloc_len, req_len);
1789ecfd03c6SJames Smart 		return -ENOMEM;
1790ecfd03c6SJames Smart 	}
1791ecfd03c6SJames Smart 
1792ecfd03c6SJames Smart 	/* Get the first SGE entry from the non-embedded DMA memory. This
1793ecfd03c6SJames Smart 	 * routine only uses a single SGE.
1794ecfd03c6SJames Smart 	 */
1795ecfd03c6SJames Smart 	lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1796ecfd03c6SJames Smart 	phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
1797ecfd03c6SJames Smart 	virt_addr = mboxq->sge_array->addr[0];
1798ecfd03c6SJames Smart 	read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1799ecfd03c6SJames Smart 
1800ecfd03c6SJames Smart 	/* Set up command fields */
1801ecfd03c6SJames Smart 	bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
1802ecfd03c6SJames Smart 	/* Perform necessary endian conversion */
1803ecfd03c6SJames Smart 	bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
1804ecfd03c6SJames Smart 	lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
1805ecfd03c6SJames Smart 
1806ecfd03c6SJames Smart 	return 0;
1807ecfd03c6SJames Smart }
1808ecfd03c6SJames Smart 
1809ecfd03c6SJames Smart /**
181004c68496SJames Smart  * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
181104c68496SJames Smart  * @mboxq: pointer to lpfc mbox command.
181204c68496SJames Smart  *
181304c68496SJames Smart  * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
181404c68496SJames Smart  * mailbox command.
181504c68496SJames Smart  **/
181604c68496SJames Smart void
181704c68496SJames Smart lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
181804c68496SJames Smart {
181904c68496SJames Smart 	/* Set up SLI4 mailbox command header fields */
182004c68496SJames Smart 	memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
182104c68496SJames Smart 	bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS);
182204c68496SJames Smart 
182304c68496SJames Smart 	/* Set up host requested features. */
182404c68496SJames Smart 	bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
182504c68496SJames Smart 
182604c68496SJames Smart 	/* Enable DIF (block guard) only if configured to do so. */
182704c68496SJames Smart 	if (phba->cfg_enable_bg)
182804c68496SJames Smart 		bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1);
182904c68496SJames Smart 
183004c68496SJames Smart 	/* Enable NPIV only if configured to do so. */
183104c68496SJames Smart 	if (phba->max_vpi && phba->cfg_enable_npiv)
183204c68496SJames Smart 		bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1);
183304c68496SJames Smart 
183404c68496SJames Smart 	return;
183504c68496SJames Smart }
183604c68496SJames Smart 
183704c68496SJames Smart /**
183804c68496SJames Smart  * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
183904c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
184004c68496SJames Smart  * @vport: Vport associated with the VF.
184104c68496SJames Smart  *
184204c68496SJames Smart  * This routine initializes @mbox to all zeros and then fills in the mailbox
184304c68496SJames Smart  * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
184404c68496SJames Smart  * in the context of an FCF. The driver issues this command to setup a VFI
184504c68496SJames Smart  * before issuing a FLOGI to login to the VSAN. The driver should also issue a
184604c68496SJames Smart  * REG_VFI after a successful VSAN login.
184704c68496SJames Smart  **/
184804c68496SJames Smart void
184904c68496SJames Smart lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
185004c68496SJames Smart {
185104c68496SJames Smart 	struct lpfc_mbx_init_vfi *init_vfi;
185204c68496SJames Smart 
185304c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
185404c68496SJames Smart 	init_vfi = &mbox->u.mqe.un.init_vfi;
185504c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI);
185604c68496SJames Smart 	bf_set(lpfc_init_vfi_vr, init_vfi, 1);
185704c68496SJames Smart 	bf_set(lpfc_init_vfi_vt, init_vfi, 1);
185804c68496SJames Smart 	bf_set(lpfc_init_vfi_vfi, init_vfi, vport->vfi + vport->phba->vfi_base);
185904c68496SJames Smart 	bf_set(lpfc_init_vfi_fcfi, init_vfi, vport->phba->fcf.fcfi);
186004c68496SJames Smart }
186104c68496SJames Smart 
186204c68496SJames Smart /**
186304c68496SJames Smart  * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
186404c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
186504c68496SJames Smart  * @vport: vport associated with the VF.
186604c68496SJames Smart  * @phys: BDE DMA bus address used to send the service parameters to the HBA.
186704c68496SJames Smart  *
186804c68496SJames Smart  * This routine initializes @mbox to all zeros and then fills in the mailbox
186904c68496SJames Smart  * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
187004c68496SJames Smart  * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
187104c68496SJames Smart  * fabrics identified by VFI in the context of an FCF.
187204c68496SJames Smart  **/
187304c68496SJames Smart void
187404c68496SJames Smart lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys)
187504c68496SJames Smart {
187604c68496SJames Smart 	struct lpfc_mbx_reg_vfi *reg_vfi;
187704c68496SJames Smart 
187804c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
187904c68496SJames Smart 	reg_vfi = &mbox->u.mqe.un.reg_vfi;
188004c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI);
188104c68496SJames Smart 	bf_set(lpfc_reg_vfi_vp, reg_vfi, 1);
188204c68496SJames Smart 	bf_set(lpfc_reg_vfi_vfi, reg_vfi, vport->vfi + vport->phba->vfi_base);
188304c68496SJames Smart 	bf_set(lpfc_reg_vfi_fcfi, reg_vfi, vport->phba->fcf.fcfi);
188404c68496SJames Smart 	bf_set(lpfc_reg_vfi_vpi, reg_vfi, vport->vpi + vport->phba->vpi_base);
1885c868595dSJames Smart 	memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name));
1886c868595dSJames Smart 	reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]);
1887c868595dSJames Smart 	reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]);
188804c68496SJames Smart 	reg_vfi->bde.addrHigh = putPaddrHigh(phys);
188904c68496SJames Smart 	reg_vfi->bde.addrLow = putPaddrLow(phys);
189004c68496SJames Smart 	reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam);
189104c68496SJames Smart 	reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
189204c68496SJames Smart 	bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID);
189304c68496SJames Smart }
189404c68496SJames Smart 
189504c68496SJames Smart /**
189604c68496SJames Smart  * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
18971c6834a7SJames Smart  * @phba: pointer to the hba structure to init the VPI for.
189804c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
189904c68496SJames Smart  * @vpi: VPI to be initialized.
190004c68496SJames Smart  *
190104c68496SJames Smart  * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
190204c68496SJames Smart  * command to activate a virtual N_Port. The HBA assigns a MAC address to use
190304c68496SJames Smart  * with the virtual N Port.  The SLI Host issues this command before issuing a
190404c68496SJames Smart  * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
190504c68496SJames Smart  * successful virtual NPort login.
190604c68496SJames Smart  **/
190704c68496SJames Smart void
19081c6834a7SJames Smart lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi)
190904c68496SJames Smart {
191004c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
191104c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI);
19121c6834a7SJames Smart 	bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi,
19131c6834a7SJames Smart 	       vpi + phba->vpi_base);
19141c6834a7SJames Smart 	bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi,
19151c6834a7SJames Smart 	       phba->pport->vfi + phba->vfi_base);
191604c68496SJames Smart }
191704c68496SJames Smart 
191804c68496SJames Smart /**
191904c68496SJames Smart  * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
192004c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
19216669f9bbSJames Smart  * @vport: vport associated with the VF.
192204c68496SJames Smart  *
192304c68496SJames Smart  * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
192404c68496SJames Smart  * (logical NPort) into the inactive state. The SLI Host must have logged out
192504c68496SJames Smart  * and unregistered all remote N_Ports to abort any activity on the virtual
192604c68496SJames Smart  * fabric. The SLI Port posts the mailbox response after marking the virtual
192704c68496SJames Smart  * fabric inactive.
192804c68496SJames Smart  **/
192904c68496SJames Smart void
19306669f9bbSJames Smart lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
193104c68496SJames Smart {
193204c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
193304c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI);
19346669f9bbSJames Smart 	bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi,
19356669f9bbSJames Smart 	       vport->vfi + vport->phba->vfi_base);
193604c68496SJames Smart }
193704c68496SJames Smart 
193804c68496SJames Smart /**
193904c68496SJames Smart  * lpfc_dump_fcoe_param - Dump config region 23 to get FCoe parameters.
194004c68496SJames Smart  * @phba: pointer to the hba structure containing.
194104c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
194204c68496SJames Smart  *
194304c68496SJames Smart  * This function create a SLI4 dump mailbox command to dump FCoE
194404c68496SJames Smart  * parameters stored in region 23.
194504c68496SJames Smart  **/
194604c68496SJames Smart int
194704c68496SJames Smart lpfc_dump_fcoe_param(struct lpfc_hba *phba,
194804c68496SJames Smart 		struct lpfcMboxq *mbox)
194904c68496SJames Smart {
195004c68496SJames Smart 	struct lpfc_dmabuf *mp = NULL;
195104c68496SJames Smart 	MAILBOX_t *mb;
195204c68496SJames Smart 
195304c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
195404c68496SJames Smart 	mb = &mbox->u.mb;
195504c68496SJames Smart 
195604c68496SJames Smart 	mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
195704c68496SJames Smart 	if (mp)
195804c68496SJames Smart 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
195904c68496SJames Smart 
196004c68496SJames Smart 	if (!mp || !mp->virt) {
196104c68496SJames Smart 		kfree(mp);
196204c68496SJames Smart 		/* dump_fcoe_param failed to allocate memory */
196304c68496SJames Smart 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
196404c68496SJames Smart 			"2569 lpfc_dump_fcoe_param: memory"
196504c68496SJames Smart 			" allocation failed\n");
196604c68496SJames Smart 		return 1;
196704c68496SJames Smart 	}
196804c68496SJames Smart 
196904c68496SJames Smart 	memset(mp->virt, 0, LPFC_BPL_SIZE);
197004c68496SJames Smart 	INIT_LIST_HEAD(&mp->list);
197104c68496SJames Smart 
197204c68496SJames Smart 	/* save address for completion */
197304c68496SJames Smart 	mbox->context1 = (uint8_t *) mp;
197404c68496SJames Smart 
197504c68496SJames Smart 	mb->mbxCommand = MBX_DUMP_MEMORY;
197604c68496SJames Smart 	mb->un.varDmp.type = DMP_NV_PARAMS;
1977a0c87cbdSJames Smart 	mb->un.varDmp.region_id = DMP_REGION_23;
1978a0c87cbdSJames Smart 	mb->un.varDmp.sli4_length = DMP_RGN23_SIZE;
197904c68496SJames Smart 	mb->un.varWords[3] = putPaddrLow(mp->phys);
198004c68496SJames Smart 	mb->un.varWords[4] = putPaddrHigh(mp->phys);
198104c68496SJames Smart 	return 0;
198204c68496SJames Smart }
198304c68496SJames Smart 
198404c68496SJames Smart /**
198504c68496SJames Smart  * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
198604c68496SJames Smart  * @phba: pointer to the hba structure containing the FCF index and RQ ID.
198704c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
198804c68496SJames Smart  *
198904c68496SJames Smart  * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
199004c68496SJames Smart  * SLI Host uses the command to activate an FCF after it has acquired FCF
199104c68496SJames Smart  * information via a READ_FCF mailbox command. This mailbox command also is used
199204c68496SJames Smart  * to indicate where received unsolicited frames from this FCF will be sent. By
199304c68496SJames Smart  * default this routine will set up the FCF to forward all unsolicited frames
199404c68496SJames Smart  * the the RQ ID passed in the @phba. This can be overridden by the caller for
199504c68496SJames Smart  * more complicated setups.
199604c68496SJames Smart  **/
199704c68496SJames Smart void
199804c68496SJames Smart lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
199904c68496SJames Smart {
200004c68496SJames Smart 	struct lpfc_mbx_reg_fcfi *reg_fcfi;
200104c68496SJames Smart 
200204c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
200304c68496SJames Smart 	reg_fcfi = &mbox->u.mqe.un.reg_fcfi;
200404c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI);
200504c68496SJames Smart 	bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, phba->sli4_hba.hdr_rq->queue_id);
200604c68496SJames Smart 	bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
200704c68496SJames Smart 	bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
200804c68496SJames Smart 	bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
2009ecfd03c6SJames Smart 	bf_set(lpfc_reg_fcfi_info_index, reg_fcfi,
2010ecfd03c6SJames Smart 	       phba->fcf.current_rec.fcf_indx);
201104c68496SJames Smart 	/* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */
2012ecfd03c6SJames Smart 	bf_set(lpfc_reg_fcfi_mam, reg_fcfi, (~phba->fcf.addr_mode) & 0x3);
2013ecfd03c6SJames Smart 	if (phba->fcf.current_rec.vlan_id != 0xFFFF) {
201404c68496SJames Smart 		bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
2015ecfd03c6SJames Smart 		bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi,
2016ecfd03c6SJames Smart 		       phba->fcf.current_rec.vlan_id);
201704c68496SJames Smart 	}
201804c68496SJames Smart }
201904c68496SJames Smart 
202004c68496SJames Smart /**
202104c68496SJames Smart  * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
202204c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
202304c68496SJames Smart  * @fcfi: FCFI to be unregistered.
202404c68496SJames Smart  *
202504c68496SJames Smart  * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
202604c68496SJames Smart  * The SLI Host uses the command to inactivate an FCFI.
202704c68496SJames Smart  **/
202804c68496SJames Smart void
202904c68496SJames Smart lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi)
203004c68496SJames Smart {
203104c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
203204c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI);
203304c68496SJames Smart 	bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi);
203404c68496SJames Smart }
203504c68496SJames Smart 
203604c68496SJames Smart /**
203704c68496SJames Smart  * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
203804c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
203904c68496SJames Smart  * @ndlp: The nodelist structure that describes the RPI to resume.
204004c68496SJames Smart  *
204104c68496SJames Smart  * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
204204c68496SJames Smart  * link event.
204304c68496SJames Smart  **/
204404c68496SJames Smart void
204504c68496SJames Smart lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
204604c68496SJames Smart {
204704c68496SJames Smart 	struct lpfc_mbx_resume_rpi *resume_rpi;
204804c68496SJames Smart 
204904c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
205004c68496SJames Smart 	resume_rpi = &mbox->u.mqe.un.resume_rpi;
205104c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI);
20528fa38513SJames Smart 	bf_set(lpfc_resume_rpi_index, resume_rpi, ndlp->nlp_rpi);
20538fa38513SJames Smart 	bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI);
20548fa38513SJames Smart 	resume_rpi->event_tag = ndlp->phba->fc_eventTag;
205504c68496SJames Smart }
205628baac74SJames Smart 
205728baac74SJames Smart /**
205828baac74SJames Smart  * lpfc_supported_pages - Initialize the PORT_CAPABILITIES supported pages
205928baac74SJames Smart  *                        mailbox command.
206028baac74SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
206128baac74SJames Smart  *
206228baac74SJames Smart  * The PORT_CAPABILITIES supported pages mailbox command is issued to
206328baac74SJames Smart  * retrieve the particular feature pages supported by the port.
206428baac74SJames Smart  **/
206528baac74SJames Smart void
206628baac74SJames Smart lpfc_supported_pages(struct lpfcMboxq *mbox)
206728baac74SJames Smart {
206828baac74SJames Smart 	struct lpfc_mbx_supp_pages *supp_pages;
206928baac74SJames Smart 
207028baac74SJames Smart 	memset(mbox, 0, sizeof(*mbox));
207128baac74SJames Smart 	supp_pages = &mbox->u.mqe.un.supp_pages;
207228baac74SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES);
207328baac74SJames Smart 	bf_set(cpn, supp_pages, LPFC_SUPP_PAGES);
207428baac74SJames Smart }
207528baac74SJames Smart 
207628baac74SJames Smart /**
207728baac74SJames Smart  * lpfc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params
207828baac74SJames Smart  *                    mailbox command.
207928baac74SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
208028baac74SJames Smart  *
208128baac74SJames Smart  * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to
208228baac74SJames Smart  * retrieve the particular SLI4 features supported by the port.
208328baac74SJames Smart  **/
208428baac74SJames Smart void
208528baac74SJames Smart lpfc_sli4_params(struct lpfcMboxq *mbox)
208628baac74SJames Smart {
208728baac74SJames Smart 	struct lpfc_mbx_sli4_params *sli4_params;
208828baac74SJames Smart 
208928baac74SJames Smart 	memset(mbox, 0, sizeof(*mbox));
209028baac74SJames Smart 	sli4_params = &mbox->u.mqe.un.sli4_params;
209128baac74SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES);
209228baac74SJames Smart 	bf_set(cpn, sli4_params, LPFC_SLI4_PARAMETERS);
209328baac74SJames Smart }
2094