xref: /openbmc/linux/drivers/scsi/lpfc/lpfc_mbox.c (revision d8e93df1)
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>
28f888ba3cSJames.Smart@Emulex.Com 
2991886523SJames.Smart@Emulex.Com #include <scsi/scsi.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 /**
443621a710SJames Smart  * lpfc_dump_mem - Prepare a mailbox command for retrieving HBA's VPD memory
45e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
46e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
47e59058c4SJames Smart  * @offset: offset for dumping VPD memory mailbox command.
48e59058c4SJames Smart  *
49e59058c4SJames Smart  * The dump mailbox command provides a method for the device driver to obtain
50e59058c4SJames Smart  * various types of information from the HBA device.
51e59058c4SJames Smart  *
52e59058c4SJames Smart  * This routine prepares the mailbox command for dumping HBA Vital Product
53e59058c4SJames Smart  * Data (VPD) memory. This mailbox command is to be used for retrieving a
54e59058c4SJames Smart  * portion (DMP_RSP_SIZE bytes) of a HBA's VPD from the HBA at an address
55e59058c4SJames Smart  * offset specified by the offset parameter.
56e59058c4SJames Smart  **/
57dea3101eS void
58dea3101eS lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset)
59dea3101eS {
60dea3101eS 	MAILBOX_t *mb;
61dea3101eS 	void *ctx;
62dea3101eS 
6304c68496SJames Smart 	mb = &pmb->u.mb;
64dea3101eS 	ctx = pmb->context2;
65dea3101eS 
66dea3101eS 	/* Setup to dump VPD region */
67dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
68dea3101eS 	mb->mbxCommand = MBX_DUMP_MEMORY;
69dea3101eS 	mb->un.varDmp.cv = 1;
70dea3101eS 	mb->un.varDmp.type = DMP_NV_PARAMS;
71dea3101eS 	mb->un.varDmp.entry_index = offset;
72dea3101eS 	mb->un.varDmp.region_id = DMP_REGION_VPD;
73dea3101eS 	mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
74dea3101eS 	mb->un.varDmp.co = 0;
75dea3101eS 	mb->un.varDmp.resp_offset = 0;
76dea3101eS 	pmb->context2 = ctx;
77dea3101eS 	mb->mbxOwner = OWN_HOST;
78dea3101eS 	return;
79dea3101eS }
80dea3101eS 
81e59058c4SJames Smart /**
823621a710SJames Smart  * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
8397207482SJames Smart  * @phba: pointer to lpfc hba data structure.
8497207482SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
853621a710SJames Smart  *
8697207482SJames Smart  * This function create a dump memory mailbox command to dump wake up
8797207482SJames Smart  * parameters.
8897207482SJames Smart  */
8997207482SJames Smart void
9097207482SJames Smart lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
9197207482SJames Smart {
9297207482SJames Smart 	MAILBOX_t *mb;
9397207482SJames Smart 	void *ctx;
9497207482SJames Smart 
9504c68496SJames Smart 	mb = &pmb->u.mb;
9697207482SJames Smart 	/* Save context so that we can restore after memset */
9797207482SJames Smart 	ctx = pmb->context2;
9897207482SJames Smart 
9997207482SJames Smart 	/* Setup to dump VPD region */
10097207482SJames Smart 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
10197207482SJames Smart 	mb->mbxCommand = MBX_DUMP_MEMORY;
10297207482SJames Smart 	mb->mbxOwner = OWN_HOST;
10397207482SJames Smart 	mb->un.varDmp.cv = 1;
10497207482SJames Smart 	mb->un.varDmp.type = DMP_NV_PARAMS;
10597207482SJames Smart 	mb->un.varDmp.entry_index = 0;
10697207482SJames Smart 	mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
10797207482SJames Smart 	mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
10897207482SJames Smart 	mb->un.varDmp.co = 0;
10997207482SJames Smart 	mb->un.varDmp.resp_offset = 0;
11097207482SJames Smart 	pmb->context2 = ctx;
11197207482SJames Smart 	return;
11297207482SJames Smart }
11397207482SJames Smart 
11497207482SJames Smart /**
1153621a710SJames Smart  * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
116e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
117e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
118e59058c4SJames Smart  *
119e59058c4SJames Smart  * The read NVRAM mailbox command returns the HBA's non-volatile parameters
120e59058c4SJames Smart  * that are used as defaults when the Fibre Channel link is brought on-line.
121e59058c4SJames Smart  *
122e59058c4SJames Smart  * This routine prepares the mailbox command for reading information stored
123e59058c4SJames Smart  * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
124e59058c4SJames Smart  **/
125dea3101eS void
126dea3101eS lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
127dea3101eS {
128dea3101eS 	MAILBOX_t *mb;
129dea3101eS 
13004c68496SJames Smart 	mb = &pmb->u.mb;
131dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
132dea3101eS 	mb->mbxCommand = MBX_READ_NV;
133dea3101eS 	mb->mbxOwner = OWN_HOST;
134dea3101eS 	return;
135dea3101eS }
136dea3101eS 
137e59058c4SJames Smart /**
1383621a710SJames Smart  * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
139e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
140e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
141e59058c4SJames Smart  * @ring: ring number for the asynchronous event to be configured.
142e59058c4SJames Smart  *
143e59058c4SJames Smart  * The asynchronous event enable mailbox command is used to enable the
144e59058c4SJames Smart  * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
145e59058c4SJames Smart  * specifies the default ring to which events are posted.
146e59058c4SJames Smart  *
147e59058c4SJames Smart  * This routine prepares the mailbox command for enabling HBA asynchronous
148e59058c4SJames Smart  * event support on a IOCB ring.
149e59058c4SJames Smart  **/
15057127f15SJames Smart void
15157127f15SJames Smart lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
15257127f15SJames Smart 		uint32_t ring)
15357127f15SJames Smart {
15457127f15SJames Smart 	MAILBOX_t *mb;
15557127f15SJames Smart 
15604c68496SJames Smart 	mb = &pmb->u.mb;
15757127f15SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
15857127f15SJames Smart 	mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
15957127f15SJames Smart 	mb->un.varCfgAsyncEvent.ring = ring;
16057127f15SJames Smart 	mb->mbxOwner = OWN_HOST;
16157127f15SJames Smart 	return;
16257127f15SJames Smart }
16357127f15SJames Smart 
164e59058c4SJames Smart /**
1653621a710SJames Smart  * lpfc_heart_beat - Prepare a mailbox command for heart beat
166e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
167e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
168e59058c4SJames Smart  *
169e59058c4SJames Smart  * The heart beat mailbox command is used to detect an unresponsive HBA, which
170e59058c4SJames Smart  * is defined as any device where no error attention is sent and both mailbox
171e59058c4SJames Smart  * and rings are not processed.
172e59058c4SJames Smart  *
173e59058c4SJames Smart  * This routine prepares the mailbox command for issuing a heart beat in the
174e59058c4SJames Smart  * form of mailbox command to the HBA. The timely completion of the heart
175e59058c4SJames Smart  * beat mailbox command indicates the health of the HBA.
176e59058c4SJames Smart  **/
177858c9f6cSJames Smart void
178858c9f6cSJames Smart lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
179858c9f6cSJames Smart {
180858c9f6cSJames Smart 	MAILBOX_t *mb;
181858c9f6cSJames Smart 
18204c68496SJames Smart 	mb = &pmb->u.mb;
183858c9f6cSJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
184858c9f6cSJames Smart 	mb->mbxCommand = MBX_HEARTBEAT;
185858c9f6cSJames Smart 	mb->mbxOwner = OWN_HOST;
186858c9f6cSJames Smart 	return;
187858c9f6cSJames Smart }
188858c9f6cSJames Smart 
189e59058c4SJames Smart /**
1903621a710SJames Smart  * lpfc_read_la - Prepare a mailbox command for reading HBA link attention
191e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
192e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
193e59058c4SJames Smart  * @mp: DMA buffer memory for reading the link attention information into.
194e59058c4SJames Smart  *
195e59058c4SJames Smart  * The read link attention mailbox command is issued to read the Link Event
196e59058c4SJames Smart  * Attention information indicated by the HBA port when the Link Event bit
197e59058c4SJames Smart  * of the Host Attention (HSTATT) register is set to 1. A Link Event
198e59058c4SJames Smart  * Attention occurs based on an exception detected at the Fibre Channel link
199e59058c4SJames Smart  * interface.
200e59058c4SJames Smart  *
201e59058c4SJames Smart  * This routine prepares the mailbox command for reading HBA link attention
202e59058c4SJames Smart  * information. A DMA memory has been set aside and address passed to the
203e59058c4SJames Smart  * HBA through @mp for the HBA to DMA link attention information into the
204e59058c4SJames Smart  * memory as part of the execution of the mailbox command.
205e59058c4SJames Smart  *
206e59058c4SJames Smart  * Return codes
207e59058c4SJames Smart  *    0 - Success (currently always return 0)
208e59058c4SJames Smart  **/
209dea3101eS int
210dea3101eS lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
211dea3101eS {
212dea3101eS 	MAILBOX_t *mb;
213dea3101eS 	struct lpfc_sli *psli;
214dea3101eS 
215dea3101eS 	psli = &phba->sli;
21604c68496SJames Smart 	mb = &pmb->u.mb;
217dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
218dea3101eS 
219dea3101eS 	INIT_LIST_HEAD(&mp->list);
220dea3101eS 	mb->mbxCommand = MBX_READ_LA64;
221dea3101eS 	mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128;
222dea3101eS 	mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
223dea3101eS 	mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys);
224dea3101eS 
225dea3101eS 	/* Save address for later completion and set the owner to host so that
226dea3101eS 	 * the FW knows this mailbox is available for processing.
227dea3101eS 	 */
228dea3101eS 	pmb->context1 = (uint8_t *) mp;
229dea3101eS 	mb->mbxOwner = OWN_HOST;
23092d7f7b0SJames Smart 	return (0);
231dea3101eS }
232dea3101eS 
233e59058c4SJames Smart /**
2343621a710SJames Smart  * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
235e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
236e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
237e59058c4SJames Smart  *
238e59058c4SJames Smart  * The clear link attention mailbox command is issued to clear the link event
239e59058c4SJames Smart  * attention condition indicated by the Link Event bit of the Host Attention
240e59058c4SJames Smart  * (HSTATT) register. The link event attention condition is cleared only if
241e59058c4SJames Smart  * the event tag specified matches that of the current link event counter.
242e59058c4SJames Smart  * The current event tag is read using the read link attention event mailbox
243e59058c4SJames Smart  * command.
244e59058c4SJames Smart  *
245e59058c4SJames Smart  * This routine prepares the mailbox command for clearing HBA link attention
246e59058c4SJames Smart  * information.
247e59058c4SJames Smart  **/
248dea3101eS void
249dea3101eS lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
250dea3101eS {
251dea3101eS 	MAILBOX_t *mb;
252dea3101eS 
25304c68496SJames Smart 	mb = &pmb->u.mb;
254dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
255dea3101eS 
256dea3101eS 	mb->un.varClearLA.eventTag = phba->fc_eventTag;
257dea3101eS 	mb->mbxCommand = MBX_CLEAR_LA;
258dea3101eS 	mb->mbxOwner = OWN_HOST;
259dea3101eS 	return;
260dea3101eS }
261dea3101eS 
262e59058c4SJames Smart /**
2633621a710SJames Smart  * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
264e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
265e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
266e59058c4SJames Smart  *
267e59058c4SJames Smart  * The configure link mailbox command is used before the initialize link
268e59058c4SJames Smart  * mailbox command to override default value and to configure link-oriented
269e59058c4SJames Smart  * parameters such as DID address and various timers. Typically, this
270e59058c4SJames Smart  * command would be used after an F_Port login to set the returned DID address
271e59058c4SJames Smart  * and the fabric timeout values. This command is not valid before a configure
272e59058c4SJames Smart  * port command has configured the HBA port.
273e59058c4SJames Smart  *
274e59058c4SJames Smart  * This routine prepares the mailbox command for configuring link on a HBA.
275e59058c4SJames Smart  **/
276dea3101eS void
277dea3101eS lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
278dea3101eS {
2792e0fef85SJames Smart 	struct lpfc_vport  *vport = phba->pport;
28004c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
281dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
282dea3101eS 
283dea3101eS 	/* NEW_FEATURE
284dea3101eS 	 * SLI-2, Coalescing Response Feature.
285dea3101eS 	 */
286dea3101eS 	if (phba->cfg_cr_delay) {
287dea3101eS 		mb->un.varCfgLnk.cr = 1;
288dea3101eS 		mb->un.varCfgLnk.ci = 1;
289dea3101eS 		mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
290dea3101eS 		mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
291dea3101eS 	}
292dea3101eS 
2932e0fef85SJames Smart 	mb->un.varCfgLnk.myId = vport->fc_myDID;
294dea3101eS 	mb->un.varCfgLnk.edtov = phba->fc_edtov;
295dea3101eS 	mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
296dea3101eS 	mb->un.varCfgLnk.ratov = phba->fc_ratov;
297dea3101eS 	mb->un.varCfgLnk.rttov = phba->fc_rttov;
298dea3101eS 	mb->un.varCfgLnk.altov = phba->fc_altov;
299dea3101eS 	mb->un.varCfgLnk.crtov = phba->fc_crtov;
300dea3101eS 	mb->un.varCfgLnk.citov = phba->fc_citov;
301dea3101eS 
302dea3101eS 	if (phba->cfg_ack0)
303dea3101eS 		mb->un.varCfgLnk.ack0_enable = 1;
304dea3101eS 
305dea3101eS 	mb->mbxCommand = MBX_CONFIG_LINK;
306dea3101eS 	mb->mbxOwner = OWN_HOST;
307dea3101eS 	return;
308dea3101eS }
309dea3101eS 
310e59058c4SJames Smart /**
3113621a710SJames Smart  * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
3129399627fSJames Smart  * @phba: pointer to lpfc hba data structure.
3139399627fSJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
3149399627fSJames Smart  *
3159399627fSJames Smart  * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
3169399627fSJames Smart  * MSI-X multi-message interrupt vector association to interrupt attention
3179399627fSJames Smart  * conditions.
3189399627fSJames Smart  *
3199399627fSJames Smart  * Return codes
3209399627fSJames Smart  *    0 - Success
3219399627fSJames Smart  *    -EINVAL - Failure
3229399627fSJames Smart  **/
3239399627fSJames Smart int
3249399627fSJames Smart lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3259399627fSJames Smart {
32604c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
3279399627fSJames Smart 	uint32_t attentionConditions[2];
3289399627fSJames Smart 
3299399627fSJames Smart 	/* Sanity check */
3309399627fSJames Smart 	if (phba->cfg_use_msi != 2) {
3319399627fSJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3329399627fSJames Smart 				"0475 Not configured for supporting MSI-X "
3339399627fSJames Smart 				"cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
3349399627fSJames Smart 		return -EINVAL;
3359399627fSJames Smart 	}
3369399627fSJames Smart 
3379399627fSJames Smart 	if (phba->sli_rev < 3) {
3389399627fSJames Smart 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3399399627fSJames Smart 				"0476 HBA not supporting SLI-3 or later "
3409399627fSJames Smart 				"SLI Revision: 0x%x\n", phba->sli_rev);
3419399627fSJames Smart 		return -EINVAL;
3429399627fSJames Smart 	}
3439399627fSJames Smart 
3449399627fSJames Smart 	/* Clear mailbox command fields */
3459399627fSJames Smart 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
3469399627fSJames Smart 
3479399627fSJames Smart 	/*
3489399627fSJames Smart 	 * SLI-3, Message Signaled Interrupt Fearure.
3499399627fSJames Smart 	 */
3509399627fSJames Smart 
3519399627fSJames Smart 	/* Multi-message attention configuration */
3529399627fSJames Smart 	attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
3539399627fSJames Smart 				  HA_LATT | HA_MBATT);
3549399627fSJames Smart 	attentionConditions[1] = 0;
3559399627fSJames Smart 
3569399627fSJames Smart 	mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
3579399627fSJames Smart 	mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
3589399627fSJames Smart 
3599399627fSJames Smart 	/*
3609399627fSJames Smart 	 * Set up message number to HA bit association
3619399627fSJames Smart 	 */
3629399627fSJames Smart #ifdef __BIG_ENDIAN_BITFIELD
3639399627fSJames Smart 	/* RA0 (FCP Ring) */
3649399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
3659399627fSJames Smart 	/* RA1 (Other Protocol Extra Ring) */
3669399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
3679399627fSJames Smart #else   /*  __LITTLE_ENDIAN_BITFIELD */
3689399627fSJames Smart 	/* RA0 (FCP Ring) */
3699399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
3709399627fSJames Smart 	/* RA1 (Other Protocol Extra Ring) */
3719399627fSJames Smart 	mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
3729399627fSJames Smart #endif
3739399627fSJames Smart 	/* Multi-message interrupt autoclear configuration*/
3749399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
3759399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
3769399627fSJames Smart 
3779399627fSJames Smart 	/* For now, HBA autoclear does not work reliably, disable it */
3789399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[0] = 0;
3799399627fSJames Smart 	mb->un.varCfgMSI.autoClearHA[1] = 0;
3809399627fSJames Smart 
3819399627fSJames Smart 	/* Set command and owner bit */
3829399627fSJames Smart 	mb->mbxCommand = MBX_CONFIG_MSI;
3839399627fSJames Smart 	mb->mbxOwner = OWN_HOST;
3849399627fSJames Smart 
3859399627fSJames Smart 	return 0;
3869399627fSJames Smart }
3879399627fSJames Smart 
3889399627fSJames Smart /**
3893621a710SJames Smart  * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
390e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
391e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
392e59058c4SJames Smart  * @topology: the link topology for the link to be initialized to.
393e59058c4SJames Smart  * @linkspeed: the link speed for the link to be initialized to.
394e59058c4SJames Smart  *
395e59058c4SJames Smart  * The initialize link mailbox command is used to initialize the Fibre
396e59058c4SJames Smart  * Channel link. This command must follow a configure port command that
397e59058c4SJames Smart  * establishes the mode of operation.
398e59058c4SJames Smart  *
399e59058c4SJames Smart  * This routine prepares the mailbox command for initializing link on a HBA
400e59058c4SJames Smart  * with the specified link topology and speed.
401e59058c4SJames Smart  **/
402dea3101eS void
403dea3101eS lpfc_init_link(struct lpfc_hba * phba,
404dea3101eS 	       LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
405dea3101eS {
406dea3101eS 	lpfc_vpd_t *vpd;
407dea3101eS 	struct lpfc_sli *psli;
408dea3101eS 	MAILBOX_t *mb;
409dea3101eS 
41004c68496SJames Smart 	mb = &pmb->u.mb;
411dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
412dea3101eS 
413dea3101eS 	psli = &phba->sli;
414dea3101eS 	switch (topology) {
415dea3101eS 	case FLAGS_TOPOLOGY_MODE_LOOP_PT:
416dea3101eS 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
417dea3101eS 		mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
418dea3101eS 		break;
419dea3101eS 	case FLAGS_TOPOLOGY_MODE_PT_PT:
420dea3101eS 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
421dea3101eS 		break;
422dea3101eS 	case FLAGS_TOPOLOGY_MODE_LOOP:
423dea3101eS 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
424dea3101eS 		break;
425dea3101eS 	case FLAGS_TOPOLOGY_MODE_PT_LOOP:
426dea3101eS 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
427dea3101eS 		mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
428dea3101eS 		break;
429367c2713SJamie Wellnitz 	case FLAGS_LOCAL_LB:
430367c2713SJamie Wellnitz 		mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
431367c2713SJamie Wellnitz 		break;
432dea3101eS 	}
433dea3101eS 
4344b0b91d4SJames Smart 	/* Enable asynchronous ABTS responses from firmware */
4354b0b91d4SJames Smart 	mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
4364b0b91d4SJames Smart 
437dea3101eS 	/* NEW_FEATURE
438dea3101eS 	 * Setting up the link speed
439dea3101eS 	 */
440dea3101eS 	vpd = &phba->vpd;
441dea3101eS 	if (vpd->rev.feaLevelHigh >= 0x02){
442dea3101eS 		switch(linkspeed){
443dea3101eS 			case LINK_SPEED_1G:
444dea3101eS 			case LINK_SPEED_2G:
445dea3101eS 			case LINK_SPEED_4G:
446b87eab38SJames Smart 			case LINK_SPEED_8G:
447dea3101eS 				mb->un.varInitLnk.link_flags |=
448dea3101eS 							FLAGS_LINK_SPEED;
449dea3101eS 				mb->un.varInitLnk.link_speed = linkspeed;
450dea3101eS 			break;
451dea3101eS 			case LINK_SPEED_AUTO:
452dea3101eS 			default:
453dea3101eS 				mb->un.varInitLnk.link_speed =
454dea3101eS 							LINK_SPEED_AUTO;
455dea3101eS 			break;
456dea3101eS 		}
457dea3101eS 
458dea3101eS 	}
459dea3101eS 	else
460dea3101eS 		mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
461dea3101eS 
462dea3101eS 	mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
463dea3101eS 	mb->mbxOwner = OWN_HOST;
464dea3101eS 	mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
465dea3101eS 	return;
466dea3101eS }
467dea3101eS 
468e59058c4SJames Smart /**
4693621a710SJames Smart  * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
470e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
471e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
472e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
473e59058c4SJames Smart  *
474e59058c4SJames Smart  * The read service parameter mailbox command is used to read the HBA port
475e59058c4SJames Smart  * service parameters. The service parameters are read into the buffer
476e59058c4SJames Smart  * specified directly by a BDE in the mailbox command. These service
477e59058c4SJames Smart  * parameters may then be used to build the payload of an N_Port/F_POrt
478e59058c4SJames Smart  * login request and reply (LOGI/ACC).
479e59058c4SJames Smart  *
480e59058c4SJames Smart  * This routine prepares the mailbox command for reading HBA port service
481e59058c4SJames Smart  * parameters. The DMA memory is allocated in this function and the addresses
482e59058c4SJames Smart  * are populated into the mailbox command for the HBA to DMA the service
483e59058c4SJames Smart  * parameters into.
484e59058c4SJames Smart  *
485e59058c4SJames Smart  * Return codes
486e59058c4SJames Smart  *    0 - Success
487e59058c4SJames Smart  *    1 - DMA memory allocation failed
488e59058c4SJames Smart  **/
489dea3101eS int
49092d7f7b0SJames Smart lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
491dea3101eS {
492dea3101eS 	struct lpfc_dmabuf *mp;
493dea3101eS 	MAILBOX_t *mb;
494dea3101eS 	struct lpfc_sli *psli;
495dea3101eS 
496dea3101eS 	psli = &phba->sli;
49704c68496SJames Smart 	mb = &pmb->u.mb;
498dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
499dea3101eS 
500dea3101eS 	mb->mbxOwner = OWN_HOST;
501dea3101eS 
502dea3101eS 	/* Get a buffer to hold the HBAs Service Parameters */
503dea3101eS 
50498c9ea5cSJames Smart 	mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
50598c9ea5cSJames Smart 	if (mp)
50698c9ea5cSJames Smart 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
50798c9ea5cSJames Smart 	if (!mp || !mp->virt) {
508dea3101eS 		kfree(mp);
509dea3101eS 		mb->mbxCommand = MBX_READ_SPARM64;
510dea3101eS 		/* READ_SPARAM: no buffers */
511e8b62011SJames Smart 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
512e8b62011SJames Smart 			        "0301 READ_SPARAM: no buffers\n");
51392d7f7b0SJames Smart 		return (1);
514dea3101eS 	}
515dea3101eS 	INIT_LIST_HEAD(&mp->list);
516dea3101eS 	mb->mbxCommand = MBX_READ_SPARM64;
517dea3101eS 	mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
518dea3101eS 	mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
519dea3101eS 	mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
52004c68496SJames Smart 	mb->un.varRdSparm.vpi = vpi + phba->vpi_base;
521dea3101eS 
522dea3101eS 	/* save address for completion */
523dea3101eS 	pmb->context1 = mp;
524dea3101eS 
52592d7f7b0SJames Smart 	return (0);
526dea3101eS }
527dea3101eS 
528e59058c4SJames Smart /**
5293621a710SJames Smart  * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
530e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
531e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
532e59058c4SJames Smart  * @did: remote port identifier.
533e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
534e59058c4SJames Smart  *
535e59058c4SJames Smart  * The unregister DID mailbox command is used to unregister an N_Port/F_Port
536e59058c4SJames Smart  * login for an unknown RPI by specifying the DID of a remote port. This
537e59058c4SJames Smart  * command frees an RPI context in the HBA port. This has the effect of
538e59058c4SJames Smart  * performing an implicit N_Port/F_Port logout.
539e59058c4SJames Smart  *
540e59058c4SJames Smart  * This routine prepares the mailbox command for unregistering a remote
541e59058c4SJames Smart  * N_Port/F_Port (DID) login.
542e59058c4SJames Smart  **/
543dea3101eS void
54492d7f7b0SJames Smart lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
54592d7f7b0SJames Smart 	       LPFC_MBOXQ_t * pmb)
546dea3101eS {
547dea3101eS 	MAILBOX_t *mb;
548dea3101eS 
54904c68496SJames Smart 	mb = &pmb->u.mb;
550dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
551dea3101eS 
552dea3101eS 	mb->un.varUnregDID.did = did;
55304c68496SJames Smart 	if (vpi != 0xffff)
55404c68496SJames Smart 		vpi += phba->vpi_base;
55592d7f7b0SJames Smart 	mb->un.varUnregDID.vpi = vpi;
556dea3101eS 
557dea3101eS 	mb->mbxCommand = MBX_UNREG_D_ID;
558dea3101eS 	mb->mbxOwner = OWN_HOST;
559dea3101eS 	return;
560dea3101eS }
561dea3101eS 
562e59058c4SJames Smart /**
5633621a710SJames Smart  * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
564e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
565e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
566e59058c4SJames Smart  *
567e59058c4SJames Smart  * The read configuration mailbox command is used to read the HBA port
568e59058c4SJames Smart  * configuration parameters. This mailbox command provides a method for
569e59058c4SJames Smart  * seeing any parameters that may have changed via various configuration
570e59058c4SJames Smart  * mailbox commands.
571e59058c4SJames Smart  *
572e59058c4SJames Smart  * This routine prepares the mailbox command for reading out HBA configuration
573e59058c4SJames Smart  * parameters.
574e59058c4SJames Smart  **/
575dea3101eS void
576dea3101eS lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
577dea3101eS {
578dea3101eS 	MAILBOX_t *mb;
579dea3101eS 
58004c68496SJames Smart 	mb = &pmb->u.mb;
581dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
582dea3101eS 
583dea3101eS 	mb->mbxCommand = MBX_READ_CONFIG;
584dea3101eS 	mb->mbxOwner = OWN_HOST;
585dea3101eS 	return;
586dea3101eS }
587dea3101eS 
588e59058c4SJames Smart /**
5893621a710SJames Smart  * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
590e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
591e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
592e59058c4SJames Smart  *
593e59058c4SJames Smart  * The read link status mailbox command is used to read the link status from
594e59058c4SJames Smart  * the HBA. Link status includes all link-related error counters. These
595e59058c4SJames Smart  * counters are maintained by the HBA and originated in the link hardware
596e59058c4SJames Smart  * unit. Note that all of these counters wrap.
597e59058c4SJames Smart  *
598e59058c4SJames Smart  * This routine prepares the mailbox command for reading out HBA link status.
599e59058c4SJames Smart  **/
6007bb3b137SJamie Wellnitz void
6017bb3b137SJamie Wellnitz lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
6027bb3b137SJamie Wellnitz {
6037bb3b137SJamie Wellnitz 	MAILBOX_t *mb;
6047bb3b137SJamie Wellnitz 
60504c68496SJames Smart 	mb = &pmb->u.mb;
6067bb3b137SJamie Wellnitz 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
6077bb3b137SJamie Wellnitz 
6087bb3b137SJamie Wellnitz 	mb->mbxCommand = MBX_READ_LNK_STAT;
6097bb3b137SJamie Wellnitz 	mb->mbxOwner = OWN_HOST;
6107bb3b137SJamie Wellnitz 	return;
6117bb3b137SJamie Wellnitz }
6127bb3b137SJamie Wellnitz 
613e59058c4SJames Smart /**
61404c68496SJames Smart  * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
615e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
616e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
617e59058c4SJames Smart  * @did: remote port identifier.
618e59058c4SJames Smart  * @param: pointer to memory holding the server parameters.
619e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
620e59058c4SJames Smart  * @flag: action flag to be passed back for the complete function.
621e59058c4SJames Smart  *
622e59058c4SJames Smart  * The registration login mailbox command is used to register an N_Port or
623e59058c4SJames Smart  * F_Port login. This registration allows the HBA to cache the remote N_Port
624e59058c4SJames Smart  * service parameters internally and thereby make the appropriate FC-2
625e59058c4SJames Smart  * decisions. The remote port service parameters are handed off by the driver
626e59058c4SJames Smart  * to the HBA using a descriptor entry that directly identifies a buffer in
627e59058c4SJames Smart  * host memory. In exchange, the HBA returns an RPI identifier.
628e59058c4SJames Smart  *
629e59058c4SJames Smart  * This routine prepares the mailbox command for registering remote port login.
630e59058c4SJames Smart  * The function allocates DMA buffer for passing the service parameters to the
631e59058c4SJames Smart  * HBA with the mailbox command.
632e59058c4SJames Smart  *
633e59058c4SJames Smart  * Return codes
634e59058c4SJames Smart  *    0 - Success
635e59058c4SJames Smart  *    1 - DMA memory allocation failed
636e59058c4SJames Smart  **/
637dea3101eS int
63804c68496SJames Smart lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
63992d7f7b0SJames Smart 	       uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
640dea3101eS {
64104c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
642dea3101eS 	uint8_t *sparam;
643dea3101eS 	struct lpfc_dmabuf *mp;
644dea3101eS 
645dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
646dea3101eS 
647dea3101eS 	mb->un.varRegLogin.rpi = 0;
64804c68496SJames Smart 	if (phba->sli_rev == LPFC_SLI_REV4) {
64904c68496SJames Smart 		mb->un.varRegLogin.rpi = lpfc_sli4_alloc_rpi(phba);
65004c68496SJames Smart 		if (mb->un.varRegLogin.rpi == LPFC_RPI_ALLOC_ERROR)
65104c68496SJames Smart 			return 1;
65204c68496SJames Smart 	}
65304c68496SJames Smart 
65404c68496SJames Smart 	mb->un.varRegLogin.vpi = vpi + phba->vpi_base;
655dea3101eS 	mb->un.varRegLogin.did = did;
656dea3101eS 	mb->un.varWords[30] = flag;	/* Set flag to issue action on cmpl */
657dea3101eS 
658dea3101eS 	mb->mbxOwner = OWN_HOST;
659dea3101eS 
660dea3101eS 	/* Get a buffer to hold NPorts Service Parameters */
66198c9ea5cSJames Smart 	mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
66298c9ea5cSJames Smart 	if (mp)
66398c9ea5cSJames Smart 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
66498c9ea5cSJames Smart 	if (!mp || !mp->virt) {
665dea3101eS 		kfree(mp);
666dea3101eS 		mb->mbxCommand = MBX_REG_LOGIN64;
667dea3101eS 		/* REG_LOGIN: no buffers */
66892d7f7b0SJames Smart 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
669e8b62011SJames Smart 				"0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
670e8b62011SJames Smart 				"flag x%x\n", vpi, did, flag);
67192d7f7b0SJames Smart 		return (1);
672dea3101eS 	}
673dea3101eS 	INIT_LIST_HEAD(&mp->list);
674dea3101eS 	sparam = mp->virt;
675dea3101eS 
676dea3101eS 	/* Copy param's into a new buffer */
677dea3101eS 	memcpy(sparam, param, sizeof (struct serv_parm));
678dea3101eS 
679dea3101eS 	/* save address for completion */
680dea3101eS 	pmb->context1 = (uint8_t *) mp;
681dea3101eS 
682dea3101eS 	mb->mbxCommand = MBX_REG_LOGIN64;
683dea3101eS 	mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
684dea3101eS 	mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
685dea3101eS 	mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
686dea3101eS 
68792d7f7b0SJames Smart 	return (0);
688dea3101eS }
689dea3101eS 
690e59058c4SJames Smart /**
6913621a710SJames Smart  * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
692e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
693e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
694e59058c4SJames Smart  * @rpi: remote port identifier
695e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
696e59058c4SJames Smart  *
697e59058c4SJames Smart  * The unregistration login mailbox command is used to unregister an N_Port
698e59058c4SJames Smart  * or F_Port login. This command frees an RPI context in the HBA. It has the
699e59058c4SJames Smart  * effect of performing an implicit N_Port/F_Port logout.
700e59058c4SJames Smart  *
701e59058c4SJames Smart  * This routine prepares the mailbox command for unregistering remote port
702e59058c4SJames Smart  * login.
703e59058c4SJames Smart  **/
704dea3101eS void
70592d7f7b0SJames Smart lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
70692d7f7b0SJames Smart 		 LPFC_MBOXQ_t * pmb)
707dea3101eS {
708dea3101eS 	MAILBOX_t *mb;
709dea3101eS 
71004c68496SJames Smart 	mb = &pmb->u.mb;
711dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
712dea3101eS 
713dea3101eS 	mb->un.varUnregLogin.rpi = (uint16_t) rpi;
714dea3101eS 	mb->un.varUnregLogin.rsvd1 = 0;
71504c68496SJames Smart 	mb->un.varUnregLogin.vpi = vpi + phba->vpi_base;
716dea3101eS 
717dea3101eS 	mb->mbxCommand = MBX_UNREG_LOGIN;
718dea3101eS 	mb->mbxOwner = OWN_HOST;
71904c68496SJames Smart 
720dea3101eS 	return;
721dea3101eS }
722dea3101eS 
723e59058c4SJames Smart /**
7243621a710SJames Smart  * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
725e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
726e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
727e59058c4SJames Smart  * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
728e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
729e59058c4SJames Smart  *
730e59058c4SJames Smart  * The registration vport identifier mailbox command is used to activate a
731e59058c4SJames Smart  * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
732e59058c4SJames Smart  * N_Port_ID against the information in the selected virtual N_Port context
733e59058c4SJames Smart  * block and marks it active to allow normal processing of IOCB commands and
734e59058c4SJames Smart  * received unsolicited exchanges.
735e59058c4SJames Smart  *
736e59058c4SJames Smart  * This routine prepares the mailbox command for registering a virtual N_Port.
737e59058c4SJames Smart  **/
73892d7f7b0SJames Smart void
73904c68496SJames Smart lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
74092d7f7b0SJames Smart {
74104c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
74292d7f7b0SJames Smart 
74392d7f7b0SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
74492d7f7b0SJames Smart 
74504c68496SJames Smart 	mb->un.varRegVpi.vpi = vport->vpi + vport->phba->vpi_base;
74604c68496SJames Smart 	mb->un.varRegVpi.sid = vport->fc_myDID;
74704c68496SJames Smart 	mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
74892d7f7b0SJames Smart 
74992d7f7b0SJames Smart 	mb->mbxCommand = MBX_REG_VPI;
75092d7f7b0SJames Smart 	mb->mbxOwner = OWN_HOST;
75192d7f7b0SJames Smart 	return;
75292d7f7b0SJames Smart 
75392d7f7b0SJames Smart }
75492d7f7b0SJames Smart 
755e59058c4SJames Smart /**
7563621a710SJames Smart  * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
757e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
758e59058c4SJames Smart  * @vpi: virtual N_Port identifier.
759e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
760e59058c4SJames Smart  *
761e59058c4SJames Smart  * The unregistration vport identifier mailbox command is used to inactivate
762e59058c4SJames Smart  * a virtual N_Port. The driver must have logged out and unregistered all
763e59058c4SJames Smart  * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
764e59058c4SJames Smart  * unregisters any default RPIs associated with the specified vpi, aborting
765e59058c4SJames Smart  * any active exchanges. The HBA will post the mailbox response after making
766e59058c4SJames Smart  * the virtual N_Port inactive.
767e59058c4SJames Smart  *
768e59058c4SJames Smart  * This routine prepares the mailbox command for unregistering a virtual
769e59058c4SJames Smart  * N_Port.
770e59058c4SJames Smart  **/
77192d7f7b0SJames Smart void
77292d7f7b0SJames Smart lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
77392d7f7b0SJames Smart {
77404c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
77592d7f7b0SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
77692d7f7b0SJames Smart 
77704c68496SJames Smart 	mb->un.varUnregVpi.vpi = vpi + phba->vpi_base;
77892d7f7b0SJames Smart 
77992d7f7b0SJames Smart 	mb->mbxCommand = MBX_UNREG_VPI;
78092d7f7b0SJames Smart 	mb->mbxOwner = OWN_HOST;
78192d7f7b0SJames Smart 	return;
78292d7f7b0SJames Smart 
78392d7f7b0SJames Smart }
78492d7f7b0SJames Smart 
785e59058c4SJames Smart /**
7863621a710SJames Smart  * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
787e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
788e59058c4SJames Smart  *
789e59058c4SJames Smart  * This routine sets up and initializes the IOCB rings in the Port Control
790e59058c4SJames Smart  * Block (PCB).
791e59058c4SJames Smart  **/
792dea3101eS static void
793dea3101eS lpfc_config_pcb_setup(struct lpfc_hba * phba)
794dea3101eS {
795dea3101eS 	struct lpfc_sli *psli = &phba->sli;
796dea3101eS 	struct lpfc_sli_ring *pring;
79734b02dcdSJames Smart 	PCB_t *pcbp = phba->pcb;
798dea3101eS 	dma_addr_t pdma_addr;
799dea3101eS 	uint32_t offset;
8002e0fef85SJames Smart 	uint32_t iocbCnt = 0;
801dea3101eS 	int i;
802dea3101eS 
803dea3101eS 	pcbp->maxRing = (psli->num_rings - 1);
804dea3101eS 
805dea3101eS 	for (i = 0; i < psli->num_rings; i++) {
806dea3101eS 		pring = &psli->ring[i];
8072e0fef85SJames Smart 
808ed957684SJames Smart 		pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
809ed957684SJames Smart 							SLI2_IOCB_CMD_SIZE;
810ed957684SJames Smart 		pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
811ed957684SJames Smart 							SLI2_IOCB_RSP_SIZE;
812dea3101eS 		/* A ring MUST have both cmd and rsp entries defined to be
813dea3101eS 		   valid */
814dea3101eS 		if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
815dea3101eS 			pcbp->rdsc[i].cmdEntries = 0;
816dea3101eS 			pcbp->rdsc[i].rspEntries = 0;
817dea3101eS 			pcbp->rdsc[i].cmdAddrHigh = 0;
818dea3101eS 			pcbp->rdsc[i].rspAddrHigh = 0;
819dea3101eS 			pcbp->rdsc[i].cmdAddrLow = 0;
820dea3101eS 			pcbp->rdsc[i].rspAddrLow = 0;
821dea3101eS 			pring->cmdringaddr = NULL;
822dea3101eS 			pring->rspringaddr = NULL;
823dea3101eS 			continue;
824dea3101eS 		}
825dea3101eS 		/* Command ring setup for ring */
82634b02dcdSJames Smart 		pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
827dea3101eS 		pcbp->rdsc[i].cmdEntries = pring->numCiocb;
828dea3101eS 
82934b02dcdSJames Smart 		offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
83034b02dcdSJames Smart 			 (uint8_t *) phba->slim2p.virt;
83134b02dcdSJames Smart 		pdma_addr = phba->slim2p.phys + offset;
832dea3101eS 		pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
833dea3101eS 		pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
834dea3101eS 		iocbCnt += pring->numCiocb;
835dea3101eS 
836dea3101eS 		/* Response ring setup for ring */
83734b02dcdSJames Smart 		pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt];
838dea3101eS 
839dea3101eS 		pcbp->rdsc[i].rspEntries = pring->numRiocb;
84034b02dcdSJames Smart 		offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
84134b02dcdSJames Smart 			 (uint8_t *)phba->slim2p.virt;
84234b02dcdSJames Smart 		pdma_addr = phba->slim2p.phys + offset;
843dea3101eS 		pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
844dea3101eS 		pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
845dea3101eS 		iocbCnt += pring->numRiocb;
846dea3101eS 	}
847dea3101eS }
848dea3101eS 
849e59058c4SJames Smart /**
8503621a710SJames Smart  * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
851e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
852e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
853e59058c4SJames Smart  *
854e59058c4SJames Smart  * The read revision mailbox command is used to read the revision levels of
855e59058c4SJames Smart  * the HBA components. These components include hardware units, resident
856e59058c4SJames Smart  * firmware, and available firmware. HBAs that supports SLI-3 mode of
857e59058c4SJames Smart  * operation provide different response information depending on the version
858e59058c4SJames Smart  * requested by the driver.
859e59058c4SJames Smart  *
860e59058c4SJames Smart  * This routine prepares the mailbox command for reading HBA revision
861e59058c4SJames Smart  * information.
862e59058c4SJames Smart  **/
863dea3101eS void
864dea3101eS lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
865dea3101eS {
86604c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
867dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
868dea3101eS 	mb->un.varRdRev.cv = 1;
869ed957684SJames Smart 	mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
870dea3101eS 	mb->mbxCommand = MBX_READ_REV;
871dea3101eS 	mb->mbxOwner = OWN_HOST;
872dea3101eS 	return;
873dea3101eS }
874dea3101eS 
875e59058c4SJames Smart /**
8763621a710SJames Smart  * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
877e59058c4SJames Smart  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
878e59058c4SJames Smart  * @hbq_desc: pointer to the HBQ selection profile descriptor.
879e59058c4SJames Smart  *
880e59058c4SJames Smart  * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
881e59058c4SJames Smart  * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
882e59058c4SJames Smart  * the Sequence Length Test using the fields in the Selection Profile 2
883e59058c4SJames Smart  * extension in words 20:31.
884e59058c4SJames Smart  **/
885ed957684SJames Smart static void
886ed957684SJames Smart lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
887ed957684SJames Smart 			struct lpfc_hbq_init  *hbq_desc)
888ed957684SJames Smart {
889ed957684SJames Smart 	hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
890ed957684SJames Smart 	hbqmb->profiles.profile2.maxlen     = hbq_desc->maxlen;
891ed957684SJames Smart 	hbqmb->profiles.profile2.seqlenoff  = hbq_desc->seqlenoff;
892ed957684SJames Smart }
893ed957684SJames Smart 
894e59058c4SJames Smart /**
8953621a710SJames Smart  * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
896e59058c4SJames Smart  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
897e59058c4SJames Smart  * @hbq_desc: pointer to the HBQ selection profile descriptor.
898e59058c4SJames Smart  *
899e59058c4SJames Smart  * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
900e59058c4SJames Smart  * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
901e59058c4SJames Smart  * the Sequence Length Test and Byte Field Test using the fields in the
902e59058c4SJames Smart  * Selection Profile 3 extension in words 20:31.
903e59058c4SJames Smart  **/
904ed957684SJames Smart static void
905ed957684SJames Smart lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
906ed957684SJames Smart 			struct lpfc_hbq_init  *hbq_desc)
907ed957684SJames Smart {
908ed957684SJames Smart 	hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
909ed957684SJames Smart 	hbqmb->profiles.profile3.maxlen     = hbq_desc->maxlen;
910ed957684SJames Smart 	hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
911ed957684SJames Smart 	hbqmb->profiles.profile3.seqlenoff  = hbq_desc->seqlenoff;
912ed957684SJames Smart 	memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
913ed957684SJames Smart 	       sizeof(hbqmb->profiles.profile3.cmdmatch));
914ed957684SJames Smart }
915ed957684SJames Smart 
916e59058c4SJames Smart /**
9173621a710SJames Smart  * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
918e59058c4SJames Smart  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
919e59058c4SJames Smart  * @hbq_desc: pointer to the HBQ selection profile descriptor.
920e59058c4SJames Smart  *
921e59058c4SJames Smart  * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
922e59058c4SJames Smart  * HBA tests the initial frame of an incoming sequence using the frame's
923e59058c4SJames Smart  * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
924e59058c4SJames Smart  * and Byte Field Test using the fields in the Selection Profile 5 extension
925e59058c4SJames Smart  * words 20:31.
926e59058c4SJames Smart  **/
927ed957684SJames Smart static void
928ed957684SJames Smart lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
929ed957684SJames Smart 			struct lpfc_hbq_init  *hbq_desc)
930ed957684SJames Smart {
931ed957684SJames Smart 	hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
932ed957684SJames Smart 	hbqmb->profiles.profile5.maxlen     = hbq_desc->maxlen;
933ed957684SJames Smart 	hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
934ed957684SJames Smart 	hbqmb->profiles.profile5.seqlenoff  = hbq_desc->seqlenoff;
935ed957684SJames Smart 	memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
936ed957684SJames Smart 	       sizeof(hbqmb->profiles.profile5.cmdmatch));
937ed957684SJames Smart }
938ed957684SJames Smart 
939e59058c4SJames Smart /**
9403621a710SJames Smart  * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
941e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
942e59058c4SJames Smart  * @id: HBQ identifier.
943e59058c4SJames Smart  * @hbq_desc: pointer to the HBA descriptor data structure.
944e59058c4SJames Smart  * @hbq_entry_index: index of the HBQ entry data structures.
945e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
946e59058c4SJames Smart  *
947e59058c4SJames Smart  * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
948e59058c4SJames Smart  * an HBQ. The configuration binds events that require buffers to a particular
949e59058c4SJames Smart  * ring and HBQ based on a selection profile.
950e59058c4SJames Smart  *
951e59058c4SJames Smart  * This routine prepares the mailbox command for configuring an HBQ.
952e59058c4SJames Smart  **/
953ed957684SJames Smart void
95451ef4c26SJames Smart lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
95551ef4c26SJames Smart 		 struct lpfc_hbq_init *hbq_desc,
956ed957684SJames Smart 		uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
957ed957684SJames Smart {
958ed957684SJames Smart 	int i;
95904c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
960ed957684SJames Smart 	struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
961ed957684SJames Smart 
962ed957684SJames Smart 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
96351ef4c26SJames Smart 	hbqmb->hbqId = id;
964ed957684SJames Smart 	hbqmb->entry_count = hbq_desc->entry_count;   /* # entries in HBQ */
965ed957684SJames Smart 	hbqmb->recvNotify = hbq_desc->rn;             /* Receive
966ed957684SJames Smart 						       * Notification */
967ed957684SJames Smart 	hbqmb->numMask    = hbq_desc->mask_count;     /* # R_CTL/TYPE masks
968ed957684SJames Smart 						       * # in words 0-19 */
969ed957684SJames Smart 	hbqmb->profile    = hbq_desc->profile;	      /* Selection profile:
970ed957684SJames Smart 						       * 0 = all,
971ed957684SJames Smart 						       * 7 = logentry */
972ed957684SJames Smart 	hbqmb->ringMask   = hbq_desc->ring_mask;      /* Binds HBQ to a ring
973ed957684SJames Smart 						       * e.g. Ring0=b0001,
974ed957684SJames Smart 						       * ring2=b0100 */
975ed957684SJames Smart 	hbqmb->headerLen  = hbq_desc->headerLen;      /* 0 if not profile 4
976ed957684SJames Smart 						       * or 5 */
977ed957684SJames Smart 	hbqmb->logEntry   = hbq_desc->logEntry;       /* Set to 1 if this
978ed957684SJames Smart 						       * HBQ will be used
979ed957684SJames Smart 						       * for LogEntry
980ed957684SJames Smart 						       * buffers */
981ed957684SJames Smart 	hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
982ed957684SJames Smart 		hbq_entry_index * sizeof(struct lpfc_hbq_entry);
983ed957684SJames Smart 	hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
984ed957684SJames Smart 
985ed957684SJames Smart 	mb->mbxCommand = MBX_CONFIG_HBQ;
986ed957684SJames Smart 	mb->mbxOwner = OWN_HOST;
987ed957684SJames Smart 
988ed957684SJames Smart 				/* Copy info for profiles 2,3,5. Other
989ed957684SJames Smart 				 * profiles this area is reserved
990ed957684SJames Smart 				 */
991ed957684SJames Smart 	if (hbq_desc->profile == 2)
992ed957684SJames Smart 		lpfc_build_hbq_profile2(hbqmb, hbq_desc);
993ed957684SJames Smart 	else if (hbq_desc->profile == 3)
994ed957684SJames Smart 		lpfc_build_hbq_profile3(hbqmb, hbq_desc);
995ed957684SJames Smart 	else if (hbq_desc->profile == 5)
996ed957684SJames Smart 		lpfc_build_hbq_profile5(hbqmb, hbq_desc);
997ed957684SJames Smart 
998ed957684SJames Smart 	/* Return if no rctl / type masks for this HBQ */
999ed957684SJames Smart 	if (!hbq_desc->mask_count)
1000ed957684SJames Smart 		return;
1001ed957684SJames Smart 
1002ed957684SJames Smart 	/* Otherwise we setup specific rctl / type masks for this HBQ */
1003ed957684SJames Smart 	for (i = 0; i < hbq_desc->mask_count; i++) {
1004ed957684SJames Smart 		hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
1005ed957684SJames Smart 		hbqmb->hbqMasks[i].tmask  = hbq_desc->hbqMasks[i].tmask;
1006ed957684SJames Smart 		hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
1007ed957684SJames Smart 		hbqmb->hbqMasks[i].rctlmask  = hbq_desc->hbqMasks[i].rctlmask;
1008ed957684SJames Smart 	}
1009ed957684SJames Smart 
1010ed957684SJames Smart 	return;
1011ed957684SJames Smart }
1012ed957684SJames Smart 
1013e59058c4SJames Smart /**
10143621a710SJames Smart  * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
1015e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1016e59058c4SJames Smart  * @ring:
1017e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1018e59058c4SJames Smart  *
1019e59058c4SJames Smart  * The configure ring mailbox command is used to configure an IOCB ring. This
1020e59058c4SJames Smart  * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1021e59058c4SJames Smart  * ring. This is used to map incoming sequences to a particular ring whose
1022e59058c4SJames Smart  * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1023e59058c4SJames Smart  * attempt to configure a ring whose number is greater than the number
1024e59058c4SJames Smart  * specified in the Port Control Block (PCB). It is an error to issue the
1025e59058c4SJames Smart  * configure ring command more than once with the same ring number. The HBA
1026e59058c4SJames Smart  * returns an error if the driver attempts this.
1027e59058c4SJames Smart  *
1028e59058c4SJames Smart  * This routine prepares the mailbox command for configuring IOCB ring.
1029e59058c4SJames Smart  **/
1030dea3101eS void
1031dea3101eS lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
1032dea3101eS {
1033dea3101eS 	int i;
103404c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
1035dea3101eS 	struct lpfc_sli *psli;
1036dea3101eS 	struct lpfc_sli_ring *pring;
1037dea3101eS 
1038dea3101eS 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1039dea3101eS 
1040dea3101eS 	mb->un.varCfgRing.ring = ring;
1041dea3101eS 	mb->un.varCfgRing.maxOrigXchg = 0;
1042dea3101eS 	mb->un.varCfgRing.maxRespXchg = 0;
1043dea3101eS 	mb->un.varCfgRing.recvNotify = 1;
1044dea3101eS 
1045dea3101eS 	psli = &phba->sli;
1046dea3101eS 	pring = &psli->ring[ring];
1047dea3101eS 	mb->un.varCfgRing.numMask = pring->num_mask;
1048dea3101eS 	mb->mbxCommand = MBX_CONFIG_RING;
1049dea3101eS 	mb->mbxOwner = OWN_HOST;
1050dea3101eS 
1051dea3101eS 	/* Is this ring configured for a specific profile */
1052dea3101eS 	if (pring->prt[0].profile) {
1053dea3101eS 		mb->un.varCfgRing.profile = pring->prt[0].profile;
1054dea3101eS 		return;
1055dea3101eS 	}
1056dea3101eS 
1057dea3101eS 	/* Otherwise we setup specific rctl / type masks for this ring */
1058dea3101eS 	for (i = 0; i < pring->num_mask; i++) {
1059dea3101eS 		mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
1060dea3101eS 		if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ)
1061dea3101eS 			mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
1062dea3101eS 		else
1063dea3101eS 			mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
1064dea3101eS 		mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
1065dea3101eS 		mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
1066dea3101eS 	}
1067dea3101eS 
1068dea3101eS 	return;
1069dea3101eS }
1070dea3101eS 
1071e59058c4SJames Smart /**
10723621a710SJames Smart  * lpfc_config_port - Prepare a mailbox command for configuring port
1073e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1074e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1075e59058c4SJames Smart  *
1076e59058c4SJames Smart  * The configure port mailbox command is used to identify the Port Control
1077e59058c4SJames Smart  * Block (PCB) in the driver memory. After this command is issued, the
1078e59058c4SJames Smart  * driver must not access the mailbox in the HBA without first resetting
1079e59058c4SJames Smart  * the HBA. The HBA may copy the PCB information to internal storage for
1080e59058c4SJames Smart  * subsequent use; the driver can not change the PCB information unless it
1081e59058c4SJames Smart  * resets the HBA.
1082e59058c4SJames Smart  *
1083e59058c4SJames Smart  * This routine prepares the mailbox command for configuring port.
1084e59058c4SJames Smart  **/
1085dea3101eS void
1086dea3101eS lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1087dea3101eS {
1088ed957684SJames Smart 	MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
108904c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
1090dea3101eS 	dma_addr_t pdma_addr;
1091dea3101eS 	uint32_t bar_low, bar_high;
1092dea3101eS 	size_t offset;
10934cc2da1dSJames.Smart@Emulex.Com 	struct lpfc_hgp hgp;
1094f91b392cSJames.Smart@Emulex.Com 	int i;
1095ed957684SJames Smart 	uint32_t pgp_offset;
1096dea3101eS 
1097dea3101eS 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1098dea3101eS 	mb->mbxCommand = MBX_CONFIG_PORT;
1099dea3101eS 	mb->mbxOwner = OWN_HOST;
1100dea3101eS 
1101dea3101eS 	mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
1102dea3101eS 
110334b02dcdSJames Smart 	offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
110434b02dcdSJames Smart 	pdma_addr = phba->slim2p.phys + offset;
1105dea3101eS 	mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
1106dea3101eS 	mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
1107dea3101eS 
110897207482SJames Smart 	/* Always Host Group Pointer is in SLIM */
110997207482SJames Smart 	mb->un.varCfgPort.hps = 1;
111097207482SJames Smart 
1111ed957684SJames Smart 	/* If HBA supports SLI=3 ask for it */
1112ed957684SJames Smart 
111304c68496SJames Smart 	if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
1114e2a0a9d6SJames Smart 		if (phba->cfg_enable_bg)
1115e2a0a9d6SJames Smart 			mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
111604c68496SJames Smart 		mb->un.varCfgPort.cdss = 1; /* Configure Security */
1117ed957684SJames Smart 		mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
111834b02dcdSJames Smart 		mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
111934b02dcdSJames Smart 		mb->un.varCfgPort.cinb = 1; /* Interrupt Notification Block */
112051ef4c26SJames Smart 		mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
112178b2d852SJames Smart 		if (phba->max_vpi && phba->cfg_enable_npiv &&
112292d7f7b0SJames Smart 		    phba->vpd.sli3Feat.cmv) {
112304c68496SJames Smart 			mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI;
112492d7f7b0SJames Smart 			mb->un.varCfgPort.cmv = 1;
112592d7f7b0SJames Smart 		} else
112692d7f7b0SJames Smart 			mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
112792d7f7b0SJames Smart 	} else
112804c68496SJames Smart 		phba->sli_rev = LPFC_SLI_REV2;
112992d7f7b0SJames Smart 	mb->un.varCfgPort.sli_mode = phba->sli_rev;
1130ed957684SJames Smart 
1131dea3101eS 	/* Now setup pcb */
113234b02dcdSJames Smart 	phba->pcb->type = TYPE_NATIVE_SLI2;
113334b02dcdSJames Smart 	phba->pcb->feature = FEATURE_INITIAL_SLI2;
1134dea3101eS 
1135dea3101eS 	/* Setup Mailbox pointers */
113634b02dcdSJames Smart 	phba->pcb->mailBoxSize = sizeof(MAILBOX_t);
113734b02dcdSJames Smart 	offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
113834b02dcdSJames Smart 	pdma_addr = phba->slim2p.phys + offset;
113934b02dcdSJames Smart 	phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
114034b02dcdSJames Smart 	phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
1141dea3101eS 
1142dea3101eS 	/*
1143dea3101eS 	 * Setup Host Group ring pointer.
1144dea3101eS 	 *
1145dea3101eS 	 * For efficiency reasons, the ring get/put pointers can be
1146dea3101eS 	 * placed in adapter memory (SLIM) rather than in host memory.
1147dea3101eS 	 * This allows firmware to avoid PCI reads/writes when updating
1148dea3101eS 	 * and checking pointers.
1149dea3101eS 	 *
1150dea3101eS 	 * The firmware recognizes the use of SLIM memory by comparing
1151dea3101eS 	 * the address of the get/put pointers structure with that of
1152dea3101eS 	 * the SLIM BAR (BAR0).
1153dea3101eS 	 *
1154dea3101eS 	 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1155dea3101eS 	 * (the hardware's view of the base address), not the OS's
1156dea3101eS 	 * value of pci_resource_start() as the OS value may be a cookie
1157dea3101eS 	 * for ioremap/iomap.
1158dea3101eS 	 */
1159dea3101eS 
1160dea3101eS 
1161dea3101eS 	pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
1162dea3101eS 	pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
1163dea3101eS 
1164ed957684SJames Smart 	/*
1165ed957684SJames Smart 	 * Set up HGP - Port Memory
1166ed957684SJames Smart 	 *
1167ed957684SJames Smart 	 * The port expects the host get/put pointers to reside in memory
1168ed957684SJames Smart 	 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1169ed957684SJames Smart 	 * area of SLIM.  In SLI-2 mode, there's an additional 16 reserved
1170ed957684SJames Smart 	 * words (0x40 bytes).  This area is not reserved if HBQs are
1171ed957684SJames Smart 	 * configured in SLI-3.
1172ed957684SJames Smart 	 *
1173ed957684SJames Smart 	 * CR0Put    - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1174ed957684SJames Smart 	 * RR0Get                      0xc4              0x84
1175ed957684SJames Smart 	 * CR1Put                      0xc8              0x88
1176ed957684SJames Smart 	 * RR1Get                      0xcc              0x8c
1177ed957684SJames Smart 	 * CR2Put                      0xd0              0x90
1178ed957684SJames Smart 	 * RR2Get                      0xd4              0x94
1179ed957684SJames Smart 	 * CR3Put                      0xd8              0x98
1180ed957684SJames Smart 	 * RR3Get                      0xdc              0x9c
1181ed957684SJames Smart 	 *
1182ed957684SJames Smart 	 * Reserved                    0xa0-0xbf
1183ed957684SJames Smart 	 *    If HBQs configured:
1184ed957684SJames Smart 	 *                         HBQ 0 Put ptr  0xc0
1185ed957684SJames Smart 	 *                         HBQ 1 Put ptr  0xc4
1186ed957684SJames Smart 	 *                         HBQ 2 Put ptr  0xc8
1187ed957684SJames Smart 	 *                         ......
1188ed957684SJames Smart 	 *                         HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1189ed957684SJames Smart 	 *
1190ed957684SJames Smart 	 */
1191ed957684SJames Smart 
1192ed957684SJames Smart 	if (phba->sli_rev == 3) {
1193ed957684SJames Smart 		phba->host_gp = &mb_slim->us.s3.host[0];
1194ed957684SJames Smart 		phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
1195ed957684SJames Smart 	} else {
1196ed957684SJames Smart 		phba->host_gp = &mb_slim->us.s2.host[0];
1197ed957684SJames Smart 		phba->hbq_put = NULL;
1198ed957684SJames Smart 	}
1199dea3101eS 
1200dea3101eS 	/* mask off BAR0's flag bits 0 - 3 */
120134b02dcdSJames Smart 	phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
1202ed957684SJames Smart 		(void __iomem *)phba->host_gp -
1203ed957684SJames Smart 		(void __iomem *)phba->MBslimaddr;
1204dea3101eS 	if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
120534b02dcdSJames Smart 		phba->pcb->hgpAddrHigh = bar_high;
1206dea3101eS 	else
120734b02dcdSJames Smart 		phba->pcb->hgpAddrHigh = 0;
1208dea3101eS 	/* write HGP data to SLIM at the required longword offset */
12094cc2da1dSJames.Smart@Emulex.Com 	memset(&hgp, 0, sizeof(struct lpfc_hgp));
1210f91b392cSJames.Smart@Emulex.Com 
1211f91b392cSJames.Smart@Emulex.Com 	for (i=0; i < phba->sli.num_rings; i++) {
1212ed957684SJames Smart 		lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
1213ed957684SJames Smart 				    sizeof(*phba->host_gp));
1214f91b392cSJames.Smart@Emulex.Com 	}
1215dea3101eS 
12168f34f4ceSJames Smart 	/* Setup Port Group offset */
12178f34f4ceSJames Smart 	if (phba->sli_rev == 3)
121834b02dcdSJames Smart 		pgp_offset = offsetof(struct lpfc_sli2_slim,
121934b02dcdSJames Smart 				      mbx.us.s3_pgp.port);
12208f34f4ceSJames Smart 	else
122134b02dcdSJames Smart 		pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
122234b02dcdSJames Smart 	pdma_addr = phba->slim2p.phys + pgp_offset;
122334b02dcdSJames Smart 	phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
122434b02dcdSJames Smart 	phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
1225dea3101eS 
1226dea3101eS 	/* Use callback routine to setp rings in the pcb */
1227dea3101eS 	lpfc_config_pcb_setup(phba);
1228dea3101eS 
1229dea3101eS 	/* special handling for LC HBAs */
1230dea3101eS 	if (lpfc_is_LC_HBA(phba->pcidev->device)) {
1231dea3101eS 		uint32_t hbainit[5];
1232dea3101eS 
1233dea3101eS 		lpfc_hba_init(phba, hbainit);
1234dea3101eS 
1235dea3101eS 		memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
1236dea3101eS 	}
1237dea3101eS 
1238dea3101eS 	/* Swap PCB if needed */
123934b02dcdSJames Smart 	lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
1240dea3101eS }
1241dea3101eS 
1242e59058c4SJames Smart /**
12433621a710SJames Smart  * lpfc_kill_board - Prepare a mailbox command for killing board
1244e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1245e59058c4SJames Smart  * @pmb: pointer to the driver internal queue element for mailbox command.
1246e59058c4SJames Smart  *
1247e59058c4SJames Smart  * The kill board mailbox command is used to tell firmware to perform a
1248e59058c4SJames Smart  * graceful shutdown of a channel on a specified board to prepare for reset.
1249e59058c4SJames Smart  * When the kill board mailbox command is received, the ER3 bit is set to 1
1250e59058c4SJames Smart  * in the Host Status register and the ER Attention bit is set to 1 in the
1251e59058c4SJames Smart  * Host Attention register of the HBA function that received the kill board
1252e59058c4SJames Smart  * command.
1253e59058c4SJames Smart  *
1254e59058c4SJames Smart  * This routine prepares the mailbox command for killing the board in
1255e59058c4SJames Smart  * preparation for a graceful shutdown.
1256e59058c4SJames Smart  **/
1257dea3101eS void
125841415862SJamie Wellnitz lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
125941415862SJamie Wellnitz {
126004c68496SJames Smart 	MAILBOX_t *mb = &pmb->u.mb;
126141415862SJamie Wellnitz 
126241415862SJamie Wellnitz 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
126341415862SJamie Wellnitz 	mb->mbxCommand = MBX_KILL_BOARD;
126441415862SJamie Wellnitz 	mb->mbxOwner = OWN_HOST;
126541415862SJamie Wellnitz 	return;
126641415862SJamie Wellnitz }
126741415862SJamie Wellnitz 
1268e59058c4SJames Smart /**
12693621a710SJames Smart  * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
1270e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1271e59058c4SJames Smart  * @mbq: pointer to the driver internal queue element for mailbox command.
1272e59058c4SJames Smart  *
1273e59058c4SJames Smart  * Driver maintains a internal mailbox command queue implemented as a linked
1274e59058c4SJames Smart  * list. When a mailbox command is issued, it shall be put into the mailbox
1275e59058c4SJames Smart  * command queue such that they shall be processed orderly as HBA can process
1276e59058c4SJames Smart  * one mailbox command at a time.
1277e59058c4SJames Smart  **/
127841415862SJamie Wellnitz void
1279dea3101eS lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1280dea3101eS {
1281dea3101eS 	struct lpfc_sli *psli;
1282dea3101eS 
1283dea3101eS 	psli = &phba->sli;
1284dea3101eS 
1285dea3101eS 	list_add_tail(&mbq->list, &psli->mboxq);
1286dea3101eS 
1287dea3101eS 	psli->mboxq_cnt++;
1288dea3101eS 
1289dea3101eS 	return;
1290dea3101eS }
1291dea3101eS 
1292e59058c4SJames Smart /**
12933621a710SJames Smart  * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
1294e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1295e59058c4SJames Smart  *
1296e59058c4SJames Smart  * Driver maintains a internal mailbox command queue implemented as a linked
1297e59058c4SJames Smart  * list. When a mailbox command is issued, it shall be put into the mailbox
1298e59058c4SJames Smart  * command queue such that they shall be processed orderly as HBA can process
1299e59058c4SJames Smart  * one mailbox command at a time. After HBA finished processing a mailbox
1300e59058c4SJames Smart  * command, the driver will remove a pending mailbox command from the head of
1301e59058c4SJames Smart  * the mailbox command queue and send to the HBA for processing.
1302e59058c4SJames Smart  *
1303e59058c4SJames Smart  * Return codes
1304e59058c4SJames Smart  *    pointer to the driver internal queue element for mailbox command.
1305e59058c4SJames Smart  **/
1306dea3101eS LPFC_MBOXQ_t *
1307dea3101eS lpfc_mbox_get(struct lpfc_hba * phba)
1308dea3101eS {
1309dea3101eS 	LPFC_MBOXQ_t *mbq = NULL;
1310dea3101eS 	struct lpfc_sli *psli = &phba->sli;
1311dea3101eS 
13122e0fef85SJames Smart 	list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
131392d7f7b0SJames Smart 	if (mbq)
1314dea3101eS 		psli->mboxq_cnt--;
1315dea3101eS 
1316dea3101eS 	return mbq;
1317dea3101eS }
1318a309a6b6SJames Smart 
1319e59058c4SJames Smart /**
132004c68496SJames Smart  * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
132104c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
132204c68496SJames Smart  * @mbq: pointer to the driver internal queue element for mailbox command.
132304c68496SJames Smart  *
132404c68496SJames Smart  * This routine put the completed mailbox command into the mailbox command
132504c68496SJames Smart  * complete list. This is the unlocked version of the routine. The mailbox
132604c68496SJames Smart  * complete list is used by the driver worker thread to process mailbox
132704c68496SJames Smart  * complete callback functions outside the driver interrupt handler.
132804c68496SJames Smart  **/
132904c68496SJames Smart void
133004c68496SJames Smart __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
133104c68496SJames Smart {
133204c68496SJames Smart 	list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
133304c68496SJames Smart }
133404c68496SJames Smart 
133504c68496SJames Smart /**
13363621a710SJames Smart  * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
1337e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1338e59058c4SJames Smart  * @mbq: pointer to the driver internal queue element for mailbox command.
1339e59058c4SJames Smart  *
1340e59058c4SJames Smart  * This routine put the completed mailbox command into the mailbox command
134104c68496SJames Smart  * complete list. This is the locked version of the routine. The mailbox
134204c68496SJames Smart  * complete list is used by the driver worker thread to process mailbox
134304c68496SJames Smart  * complete callback functions outside the driver interrupt handler.
1344e59058c4SJames Smart  **/
134592d7f7b0SJames Smart void
134692d7f7b0SJames Smart lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
134792d7f7b0SJames Smart {
13485b75da2fSJames Smart 	unsigned long iflag;
13495b75da2fSJames Smart 
1350b1c11812SJoe Perches 	/* This function expects to be called from interrupt context */
13515b75da2fSJames Smart 	spin_lock_irqsave(&phba->hbalock, iflag);
135204c68496SJames Smart 	__lpfc_mbox_cmpl_put(phba, mbq);
13535b75da2fSJames Smart 	spin_unlock_irqrestore(&phba->hbalock, iflag);
135492d7f7b0SJames Smart 	return;
135592d7f7b0SJames Smart }
135692d7f7b0SJames Smart 
1357e59058c4SJames Smart /**
135804c68496SJames Smart  * lpfc_mbox_cmd_check - Check the validality of a mailbox command
135904c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
136004c68496SJames Smart  * @mboxq: pointer to the driver internal queue element for mailbox command.
136104c68496SJames Smart  *
136204c68496SJames Smart  * This routine is to check whether a mailbox command is valid to be issued.
136304c68496SJames Smart  * This check will be performed by both the mailbox issue API when a client
136404c68496SJames Smart  * is to issue a mailbox command to the mailbox transport.
136504c68496SJames Smart  *
136604c68496SJames Smart  * Return 0 - pass the check, -ENODEV - fail the check
136704c68496SJames Smart  **/
136804c68496SJames Smart int
136904c68496SJames Smart lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
137004c68496SJames Smart {
137104c68496SJames Smart 	/* Mailbox command that have a completion handler must also have a
137204c68496SJames Smart 	 * vport specified.
137304c68496SJames Smart 	 */
137404c68496SJames Smart 	if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
137504c68496SJames Smart 	    mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
137604c68496SJames Smart 		if (!mboxq->vport) {
137704c68496SJames Smart 			lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
137804c68496SJames Smart 					"1814 Mbox x%x failed, no vport\n",
137904c68496SJames Smart 					mboxq->u.mb.mbxCommand);
138004c68496SJames Smart 			dump_stack();
138104c68496SJames Smart 			return -ENODEV;
138204c68496SJames Smart 		}
138304c68496SJames Smart 	}
138404c68496SJames Smart 	return 0;
138504c68496SJames Smart }
138604c68496SJames Smart 
138704c68496SJames Smart /**
138804c68496SJames Smart  * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
138904c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
139004c68496SJames Smart  *
139104c68496SJames Smart  * This routine is to check whether the HBA device is ready for posting a
139204c68496SJames Smart  * mailbox command. It is used by the mailbox transport API at the time the
139304c68496SJames Smart  * to post a mailbox command to the device.
139404c68496SJames Smart  *
139504c68496SJames Smart  * Return 0 - pass the check, -ENODEV - fail the check
139604c68496SJames Smart  **/
139704c68496SJames Smart int
139804c68496SJames Smart lpfc_mbox_dev_check(struct lpfc_hba *phba)
139904c68496SJames Smart {
140004c68496SJames Smart 	/* If the PCI channel is in offline state, do not issue mbox */
140104c68496SJames Smart 	if (unlikely(pci_channel_offline(phba->pcidev)))
140204c68496SJames Smart 		return -ENODEV;
140304c68496SJames Smart 
140404c68496SJames Smart 	/* If the HBA is in error state, do not issue mbox */
140504c68496SJames Smart 	if (phba->link_state == LPFC_HBA_ERROR)
140604c68496SJames Smart 		return -ENODEV;
140704c68496SJames Smart 
140804c68496SJames Smart 	return 0;
140904c68496SJames Smart }
141004c68496SJames Smart 
141104c68496SJames Smart /**
14123621a710SJames Smart  * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
1413e59058c4SJames Smart  * @phba: pointer to lpfc hba data structure.
1414e59058c4SJames Smart  * @cmd: mailbox command code.
1415e59058c4SJames Smart  *
1416e59058c4SJames Smart  * This routine retrieves the proper timeout value according to the mailbox
1417e59058c4SJames Smart  * command code.
1418e59058c4SJames Smart  *
1419e59058c4SJames Smart  * Return codes
1420e59058c4SJames Smart  *    Timeout value to be used for the given mailbox command
1421e59058c4SJames Smart  **/
1422a309a6b6SJames Smart int
1423a309a6b6SJames Smart lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
1424a309a6b6SJames Smart {
1425a309a6b6SJames Smart 	switch (cmd) {
1426a309a6b6SJames Smart 	case MBX_WRITE_NV:	/* 0x03 */
1427a309a6b6SJames Smart 	case MBX_UPDATE_CFG:	/* 0x1B */
1428a309a6b6SJames Smart 	case MBX_DOWN_LOAD:	/* 0x1C */
1429a309a6b6SJames Smart 	case MBX_DEL_LD_ENTRY:	/* 0x1D */
1430a309a6b6SJames Smart 	case MBX_LOAD_AREA:	/* 0x81 */
143109372820SJames Smart 	case MBX_WRITE_WWN:     /* 0x98 */
1432a309a6b6SJames Smart 	case MBX_LOAD_EXP_ROM:	/* 0x9C */
1433a309a6b6SJames Smart 		return LPFC_MBOX_TMO_FLASH_CMD;
143404c68496SJames Smart 	case MBX_SLI4_CONFIG:	/* 0x9b */
143504c68496SJames Smart 		return LPFC_MBOX_SLI4_CONFIG_TMO;
1436a309a6b6SJames Smart 	}
1437a309a6b6SJames Smart 	return LPFC_MBOX_TMO;
1438a309a6b6SJames Smart }
143904c68496SJames Smart 
144004c68496SJames Smart /**
144104c68496SJames Smart  * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
144204c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
144304c68496SJames Smart  * @sgentry: sge entry index.
144404c68496SJames Smart  * @phyaddr: physical address for the sge
144504c68496SJames Smart  * @length: Length of the sge.
144604c68496SJames Smart  *
144704c68496SJames Smart  * This routine sets up an entry in the non-embedded mailbox command at the sge
144804c68496SJames Smart  * index location.
144904c68496SJames Smart  **/
145004c68496SJames Smart void
145104c68496SJames Smart lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry,
145204c68496SJames Smart 		      dma_addr_t phyaddr, uint32_t length)
145304c68496SJames Smart {
145404c68496SJames Smart 	struct lpfc_mbx_nembed_cmd *nembed_sge;
145504c68496SJames Smart 
145604c68496SJames Smart 	nembed_sge = (struct lpfc_mbx_nembed_cmd *)
145704c68496SJames Smart 				&mbox->u.mqe.un.nembed_cmd;
145804c68496SJames Smart 	nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr);
145904c68496SJames Smart 	nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr);
146004c68496SJames Smart 	nembed_sge->sge[sgentry].length = length;
146104c68496SJames Smart }
146204c68496SJames Smart 
146304c68496SJames Smart /**
146404c68496SJames Smart  * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
146504c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
146604c68496SJames Smart  * @sgentry: sge entry index.
146704c68496SJames Smart  *
146804c68496SJames Smart  * This routine gets an entry from the non-embedded mailbox command at the sge
146904c68496SJames Smart  * index location.
147004c68496SJames Smart  **/
147104c68496SJames Smart void
147204c68496SJames Smart lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry,
147304c68496SJames Smart 		      struct lpfc_mbx_sge *sge)
147404c68496SJames Smart {
147504c68496SJames Smart 	struct lpfc_mbx_nembed_cmd *nembed_sge;
147604c68496SJames Smart 
147704c68496SJames Smart 	nembed_sge = (struct lpfc_mbx_nembed_cmd *)
147804c68496SJames Smart 				&mbox->u.mqe.un.nembed_cmd;
147904c68496SJames Smart 	sge->pa_lo = nembed_sge->sge[sgentry].pa_lo;
148004c68496SJames Smart 	sge->pa_hi = nembed_sge->sge[sgentry].pa_hi;
148104c68496SJames Smart 	sge->length = nembed_sge->sge[sgentry].length;
148204c68496SJames Smart }
148304c68496SJames Smart 
148404c68496SJames Smart /**
148504c68496SJames Smart  * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
148604c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
148704c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
148804c68496SJames Smart  *
148904c68496SJames Smart  * This routine frees SLI4 specific mailbox command for sending IOCTL command.
149004c68496SJames Smart  **/
149104c68496SJames Smart void
149204c68496SJames Smart lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
149304c68496SJames Smart {
149404c68496SJames Smart 	struct lpfc_mbx_sli4_config *sli4_cfg;
149504c68496SJames Smart 	struct lpfc_mbx_sge sge;
149604c68496SJames Smart 	dma_addr_t phyaddr;
149704c68496SJames Smart 	uint32_t sgecount, sgentry;
149804c68496SJames Smart 
149904c68496SJames Smart 	sli4_cfg = &mbox->u.mqe.un.sli4_config;
150004c68496SJames Smart 
150104c68496SJames Smart 	/* For embedded mbox command, just free the mbox command */
150204c68496SJames Smart 	if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
150304c68496SJames Smart 		mempool_free(mbox, phba->mbox_mem_pool);
150404c68496SJames Smart 		return;
150504c68496SJames Smart 	}
150604c68496SJames Smart 
150704c68496SJames Smart 	/* For non-embedded mbox command, we need to free the pages first */
150804c68496SJames Smart 	sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr);
150904c68496SJames Smart 	/* There is nothing we can do if there is no sge address array */
151004c68496SJames Smart 	if (unlikely(!mbox->sge_array)) {
151104c68496SJames Smart 		mempool_free(mbox, phba->mbox_mem_pool);
151204c68496SJames Smart 		return;
151304c68496SJames Smart 	}
151404c68496SJames Smart 	/* Each non-embedded DMA memory was allocated in the length of a page */
151504c68496SJames Smart 	for (sgentry = 0; sgentry < sgecount; sgentry++) {
151604c68496SJames Smart 		lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge);
151704c68496SJames Smart 		phyaddr = getPaddr(sge.pa_hi, sge.pa_lo);
151804c68496SJames Smart 		dma_free_coherent(&phba->pcidev->dev, PAGE_SIZE,
151904c68496SJames Smart 				  mbox->sge_array->addr[sgentry], phyaddr);
152004c68496SJames Smart 	}
152104c68496SJames Smart 	/* Free the sge address array memory */
152204c68496SJames Smart 	kfree(mbox->sge_array);
152304c68496SJames Smart 	/* Finally, free the mailbox command itself */
152404c68496SJames Smart 	mempool_free(mbox, phba->mbox_mem_pool);
152504c68496SJames Smart }
152604c68496SJames Smart 
152704c68496SJames Smart /**
152804c68496SJames Smart  * lpfc_sli4_config - Initialize the  SLI4 Config Mailbox command
152904c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
153004c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
153104c68496SJames Smart  * @subsystem: The sli4 config sub mailbox subsystem.
153204c68496SJames Smart  * @opcode: The sli4 config sub mailbox command opcode.
153304c68496SJames Smart  * @length: Length of the sli4 config mailbox command.
153404c68496SJames Smart  *
153504c68496SJames Smart  * This routine sets up the header fields of SLI4 specific mailbox command
153604c68496SJames Smart  * for sending IOCTL command.
153704c68496SJames Smart  *
153804c68496SJames Smart  * Return: the actual length of the mbox command allocated (mostly useful
153904c68496SJames Smart  *         for none embedded mailbox command).
154004c68496SJames Smart  **/
154104c68496SJames Smart int
154204c68496SJames Smart lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
154304c68496SJames Smart 		 uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb)
154404c68496SJames Smart {
154504c68496SJames Smart 	struct lpfc_mbx_sli4_config *sli4_config;
154604c68496SJames Smart 	union lpfc_sli4_cfg_shdr *cfg_shdr = NULL;
154704c68496SJames Smart 	uint32_t alloc_len;
154804c68496SJames Smart 	uint32_t resid_len;
154904c68496SJames Smart 	uint32_t pagen, pcount;
155004c68496SJames Smart 	void *viraddr;
155104c68496SJames Smart 	dma_addr_t phyaddr;
155204c68496SJames Smart 
155304c68496SJames Smart 	/* Set up SLI4 mailbox command header fields */
155404c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
155504c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG);
155604c68496SJames Smart 
155704c68496SJames Smart 	/* Set up SLI4 ioctl command header fields */
155804c68496SJames Smart 	sli4_config = &mbox->u.mqe.un.sli4_config;
155904c68496SJames Smart 
156004c68496SJames Smart 	/* Setup for the embedded mbox command */
156104c68496SJames Smart 	if (emb) {
156204c68496SJames Smart 		/* Set up main header fields */
156304c68496SJames Smart 		bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
156404c68496SJames Smart 		sli4_config->header.cfg_mhdr.payload_length =
156504c68496SJames Smart 					LPFC_MBX_CMD_HDR_LENGTH + length;
156604c68496SJames Smart 		/* Set up sub-header fields following main header */
156704c68496SJames Smart 		bf_set(lpfc_mbox_hdr_opcode,
156804c68496SJames Smart 			&sli4_config->header.cfg_shdr.request, opcode);
156904c68496SJames Smart 		bf_set(lpfc_mbox_hdr_subsystem,
157004c68496SJames Smart 			&sli4_config->header.cfg_shdr.request, subsystem);
157104c68496SJames Smart 		sli4_config->header.cfg_shdr.request.request_length = length;
157204c68496SJames Smart 		return length;
157304c68496SJames Smart 	}
157404c68496SJames Smart 
157504c68496SJames Smart 	/* Setup for the none-embedded mbox command */
157604c68496SJames Smart 	pcount = (PAGE_ALIGN(length))/PAGE_SIZE;
157704c68496SJames Smart 	pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ?
157804c68496SJames Smart 				LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount;
157904c68496SJames Smart 	/* Allocate record for keeping SGE virtual addresses */
158004c68496SJames Smart 	mbox->sge_array = kmalloc(sizeof(struct lpfc_mbx_nembed_sge_virt),
158104c68496SJames Smart 				  GFP_KERNEL);
158204c68496SJames Smart 	if (!mbox->sge_array)
158304c68496SJames Smart 		return 0;
158404c68496SJames Smart 
158504c68496SJames Smart 	for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) {
158604c68496SJames Smart 		/* The DMA memory is always allocated in the length of a
158704c68496SJames Smart 		 * page even though the last SGE might not fill up to a
158804c68496SJames Smart 		 * page, this is used as a priori size of PAGE_SIZE for
158904c68496SJames Smart 		 * the later DMA memory free.
159004c68496SJames Smart 		 */
159104c68496SJames Smart 		viraddr = dma_alloc_coherent(&phba->pcidev->dev, PAGE_SIZE,
159204c68496SJames Smart 					     &phyaddr, GFP_KERNEL);
159304c68496SJames Smart 		/* In case of malloc fails, proceed with whatever we have */
159404c68496SJames Smart 		if (!viraddr)
159504c68496SJames Smart 			break;
159604c68496SJames Smart 		mbox->sge_array->addr[pagen] = viraddr;
159704c68496SJames Smart 		/* Keep the first page for later sub-header construction */
159804c68496SJames Smart 		if (pagen == 0)
159904c68496SJames Smart 			cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr;
160004c68496SJames Smart 		resid_len = length - alloc_len;
160104c68496SJames Smart 		if (resid_len > PAGE_SIZE) {
160204c68496SJames Smart 			lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
160304c68496SJames Smart 					      PAGE_SIZE);
160404c68496SJames Smart 			alloc_len += PAGE_SIZE;
160504c68496SJames Smart 		} else {
160604c68496SJames Smart 			lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
160704c68496SJames Smart 					      resid_len);
160804c68496SJames Smart 			alloc_len = length;
160904c68496SJames Smart 		}
161004c68496SJames Smart 	}
161104c68496SJames Smart 
161204c68496SJames Smart 	/* Set up main header fields in mailbox command */
161304c68496SJames Smart 	sli4_config->header.cfg_mhdr.payload_length = alloc_len;
161404c68496SJames Smart 	bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen);
161504c68496SJames Smart 
161604c68496SJames Smart 	/* Set up sub-header fields into the first page */
161704c68496SJames Smart 	if (pagen > 0) {
161804c68496SJames Smart 		bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode);
161904c68496SJames Smart 		bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem);
162004c68496SJames Smart 		cfg_shdr->request.request_length =
162104c68496SJames Smart 				alloc_len - sizeof(union  lpfc_sli4_cfg_shdr);
162204c68496SJames Smart 	}
162304c68496SJames Smart 	/* The sub-header is in DMA memory, which needs endian converstion */
162404c68496SJames Smart 	lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
162504c68496SJames Smart 			      sizeof(union  lpfc_sli4_cfg_shdr));
162604c68496SJames Smart 
162704c68496SJames Smart 	return alloc_len;
162804c68496SJames Smart }
162904c68496SJames Smart 
163004c68496SJames Smart /**
163104c68496SJames Smart  * lpfc_sli4_mbox_opcode_get - Get the opcode from a sli4 mailbox command
163204c68496SJames Smart  * @phba: pointer to lpfc hba data structure.
163304c68496SJames Smart  * @mbox: pointer to lpfc mbox command.
163404c68496SJames Smart  *
163504c68496SJames Smart  * This routine gets the opcode from a SLI4 specific mailbox command for
163604c68496SJames Smart  * sending IOCTL command. If the mailbox command is not MBX_SLI4_CONFIG
163704c68496SJames Smart  * (0x9B) or if the IOCTL sub-header is not present, opcode 0x0 shall be
163804c68496SJames Smart  * returned.
163904c68496SJames Smart  **/
164004c68496SJames Smart uint8_t
164104c68496SJames Smart lpfc_sli4_mbox_opcode_get(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
164204c68496SJames Smart {
164304c68496SJames Smart 	struct lpfc_mbx_sli4_config *sli4_cfg;
164404c68496SJames Smart 	union lpfc_sli4_cfg_shdr *cfg_shdr;
164504c68496SJames Smart 
164604c68496SJames Smart 	if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
164704c68496SJames Smart 		return 0;
164804c68496SJames Smart 	sli4_cfg = &mbox->u.mqe.un.sli4_config;
164904c68496SJames Smart 
165004c68496SJames Smart 	/* For embedded mbox command, get opcode from embedded sub-header*/
165104c68496SJames Smart 	if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
165204c68496SJames Smart 		cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
165304c68496SJames Smart 		return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
165404c68496SJames Smart 	}
165504c68496SJames Smart 
165604c68496SJames Smart 	/* For non-embedded mbox command, get opcode from first dma page */
165704c68496SJames Smart 	if (unlikely(!mbox->sge_array))
165804c68496SJames Smart 		return 0;
165904c68496SJames Smart 	cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
166004c68496SJames Smart 	return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
166104c68496SJames Smart }
166204c68496SJames Smart 
166304c68496SJames Smart /**
166404c68496SJames Smart  * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
166504c68496SJames Smart  * @mboxq: pointer to lpfc mbox command.
166604c68496SJames Smart  *
166704c68496SJames Smart  * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
166804c68496SJames Smart  * mailbox command.
166904c68496SJames Smart  **/
167004c68496SJames Smart void
167104c68496SJames Smart lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
167204c68496SJames Smart {
167304c68496SJames Smart 	/* Set up SLI4 mailbox command header fields */
167404c68496SJames Smart 	memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
167504c68496SJames Smart 	bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS);
167604c68496SJames Smart 
167704c68496SJames Smart 	/* Set up host requested features. */
167804c68496SJames Smart 	bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
167904c68496SJames Smart 
168004c68496SJames Smart 	/* Virtual fabrics and FIPs are not supported yet. */
168104c68496SJames Smart 	bf_set(lpfc_mbx_rq_ftr_rq_ifip, &mboxq->u.mqe.un.req_ftrs, 0);
168204c68496SJames Smart 
168304c68496SJames Smart 	/* Enable DIF (block guard) only if configured to do so. */
168404c68496SJames Smart 	if (phba->cfg_enable_bg)
168504c68496SJames Smart 		bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1);
168604c68496SJames Smart 
168704c68496SJames Smart 	/* Enable NPIV only if configured to do so. */
168804c68496SJames Smart 	if (phba->max_vpi && phba->cfg_enable_npiv)
168904c68496SJames Smart 		bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1);
169004c68496SJames Smart 
169104c68496SJames Smart 	return;
169204c68496SJames Smart }
169304c68496SJames Smart 
169404c68496SJames Smart /**
169504c68496SJames Smart  * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
169604c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
169704c68496SJames Smart  * @vport: Vport associated with the VF.
169804c68496SJames Smart  *
169904c68496SJames Smart  * This routine initializes @mbox to all zeros and then fills in the mailbox
170004c68496SJames Smart  * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
170104c68496SJames Smart  * in the context of an FCF. The driver issues this command to setup a VFI
170204c68496SJames Smart  * before issuing a FLOGI to login to the VSAN. The driver should also issue a
170304c68496SJames Smart  * REG_VFI after a successful VSAN login.
170404c68496SJames Smart  **/
170504c68496SJames Smart void
170604c68496SJames Smart lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
170704c68496SJames Smart {
170804c68496SJames Smart 	struct lpfc_mbx_init_vfi *init_vfi;
170904c68496SJames Smart 
171004c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
171104c68496SJames Smart 	init_vfi = &mbox->u.mqe.un.init_vfi;
171204c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI);
171304c68496SJames Smart 	bf_set(lpfc_init_vfi_vr, init_vfi, 1);
171404c68496SJames Smart 	bf_set(lpfc_init_vfi_vt, init_vfi, 1);
171504c68496SJames Smart 	bf_set(lpfc_init_vfi_vfi, init_vfi, vport->vfi + vport->phba->vfi_base);
171604c68496SJames Smart 	bf_set(lpfc_init_vfi_fcfi, init_vfi, vport->phba->fcf.fcfi);
171704c68496SJames Smart }
171804c68496SJames Smart 
171904c68496SJames Smart /**
172004c68496SJames Smart  * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
172104c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
172204c68496SJames Smart  * @vport: vport associated with the VF.
172304c68496SJames Smart  * @phys: BDE DMA bus address used to send the service parameters to the HBA.
172404c68496SJames Smart  *
172504c68496SJames Smart  * This routine initializes @mbox to all zeros and then fills in the mailbox
172604c68496SJames Smart  * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
172704c68496SJames Smart  * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
172804c68496SJames Smart  * fabrics identified by VFI in the context of an FCF.
172904c68496SJames Smart  **/
173004c68496SJames Smart void
173104c68496SJames Smart lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys)
173204c68496SJames Smart {
173304c68496SJames Smart 	struct lpfc_mbx_reg_vfi *reg_vfi;
173404c68496SJames Smart 
173504c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
173604c68496SJames Smart 	reg_vfi = &mbox->u.mqe.un.reg_vfi;
173704c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI);
173804c68496SJames Smart 	bf_set(lpfc_reg_vfi_vp, reg_vfi, 1);
173904c68496SJames Smart 	bf_set(lpfc_reg_vfi_vfi, reg_vfi, vport->vfi + vport->phba->vfi_base);
174004c68496SJames Smart 	bf_set(lpfc_reg_vfi_fcfi, reg_vfi, vport->phba->fcf.fcfi);
174104c68496SJames Smart 	bf_set(lpfc_reg_vfi_vpi, reg_vfi, vport->vpi + vport->phba->vpi_base);
174204c68496SJames Smart 	reg_vfi->bde.addrHigh = putPaddrHigh(phys);
174304c68496SJames Smart 	reg_vfi->bde.addrLow = putPaddrLow(phys);
174404c68496SJames Smart 	reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam);
174504c68496SJames Smart 	reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
174604c68496SJames Smart 	bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID);
174704c68496SJames Smart }
174804c68496SJames Smart 
174904c68496SJames Smart /**
175004c68496SJames Smart  * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
175104c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
175204c68496SJames Smart  * @vpi: VPI to be initialized.
175304c68496SJames Smart  *
175404c68496SJames Smart  * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
175504c68496SJames Smart  * command to activate a virtual N_Port. The HBA assigns a MAC address to use
175604c68496SJames Smart  * with the virtual N Port.  The SLI Host issues this command before issuing a
175704c68496SJames Smart  * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
175804c68496SJames Smart  * successful virtual NPort login.
175904c68496SJames Smart  **/
176004c68496SJames Smart void
176104c68496SJames Smart lpfc_init_vpi(struct lpfcMboxq *mbox, uint16_t vpi)
176204c68496SJames Smart {
176304c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
176404c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI);
176504c68496SJames Smart 	bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi, vpi);
176604c68496SJames Smart }
176704c68496SJames Smart 
176804c68496SJames Smart /**
176904c68496SJames Smart  * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
177004c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
177104c68496SJames Smart  * @vfi: VFI to be unregistered.
177204c68496SJames Smart  *
177304c68496SJames Smart  * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
177404c68496SJames Smart  * (logical NPort) into the inactive state. The SLI Host must have logged out
177504c68496SJames Smart  * and unregistered all remote N_Ports to abort any activity on the virtual
177604c68496SJames Smart  * fabric. The SLI Port posts the mailbox response after marking the virtual
177704c68496SJames Smart  * fabric inactive.
177804c68496SJames Smart  **/
177904c68496SJames Smart void
178004c68496SJames Smart lpfc_unreg_vfi(struct lpfcMboxq *mbox, uint16_t vfi)
178104c68496SJames Smart {
178204c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
178304c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI);
178404c68496SJames Smart 	bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi, vfi);
178504c68496SJames Smart }
178604c68496SJames Smart 
178704c68496SJames Smart /**
178804c68496SJames Smart  * lpfc_dump_fcoe_param - Dump config region 23 to get FCoe parameters.
178904c68496SJames Smart  * @phba: pointer to the hba structure containing.
179004c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
179104c68496SJames Smart  *
179204c68496SJames Smart  * This function create a SLI4 dump mailbox command to dump FCoE
179304c68496SJames Smart  * parameters stored in region 23.
179404c68496SJames Smart  **/
179504c68496SJames Smart int
179604c68496SJames Smart lpfc_dump_fcoe_param(struct lpfc_hba *phba,
179704c68496SJames Smart 		struct lpfcMboxq *mbox)
179804c68496SJames Smart {
179904c68496SJames Smart 	struct lpfc_dmabuf *mp = NULL;
180004c68496SJames Smart 	MAILBOX_t *mb;
180104c68496SJames Smart 
180204c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
180304c68496SJames Smart 	mb = &mbox->u.mb;
180404c68496SJames Smart 
180504c68496SJames Smart 	mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
180604c68496SJames Smart 	if (mp)
180704c68496SJames Smart 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
180804c68496SJames Smart 
180904c68496SJames Smart 	if (!mp || !mp->virt) {
181004c68496SJames Smart 		kfree(mp);
181104c68496SJames Smart 		/* dump_fcoe_param failed to allocate memory */
181204c68496SJames Smart 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
181304c68496SJames Smart 			"2569 lpfc_dump_fcoe_param: memory"
181404c68496SJames Smart 			" allocation failed \n");
181504c68496SJames Smart 		return 1;
181604c68496SJames Smart 	}
181704c68496SJames Smart 
181804c68496SJames Smart 	memset(mp->virt, 0, LPFC_BPL_SIZE);
181904c68496SJames Smart 	INIT_LIST_HEAD(&mp->list);
182004c68496SJames Smart 
182104c68496SJames Smart 	/* save address for completion */
182204c68496SJames Smart 	mbox->context1 = (uint8_t *) mp;
182304c68496SJames Smart 
182404c68496SJames Smart 	mb->mbxCommand = MBX_DUMP_MEMORY;
182504c68496SJames Smart 	mb->un.varDmp.type = DMP_NV_PARAMS;
182604c68496SJames Smart 	mb->un.varDmp.region_id = DMP_REGION_FCOEPARAM;
182704c68496SJames Smart 	mb->un.varDmp.sli4_length = DMP_FCOEPARAM_RGN_SIZE;
182804c68496SJames Smart 	mb->un.varWords[3] = putPaddrLow(mp->phys);
182904c68496SJames Smart 	mb->un.varWords[4] = putPaddrHigh(mp->phys);
183004c68496SJames Smart 	return 0;
183104c68496SJames Smart }
183204c68496SJames Smart 
183304c68496SJames Smart /**
183404c68496SJames Smart  * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
183504c68496SJames Smart  * @phba: pointer to the hba structure containing the FCF index and RQ ID.
183604c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
183704c68496SJames Smart  *
183804c68496SJames Smart  * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
183904c68496SJames Smart  * SLI Host uses the command to activate an FCF after it has acquired FCF
184004c68496SJames Smart  * information via a READ_FCF mailbox command. This mailbox command also is used
184104c68496SJames Smart  * to indicate where received unsolicited frames from this FCF will be sent. By
184204c68496SJames Smart  * default this routine will set up the FCF to forward all unsolicited frames
184304c68496SJames Smart  * the the RQ ID passed in the @phba. This can be overridden by the caller for
184404c68496SJames Smart  * more complicated setups.
184504c68496SJames Smart  **/
184604c68496SJames Smart void
184704c68496SJames Smart lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
184804c68496SJames Smart {
184904c68496SJames Smart 	struct lpfc_mbx_reg_fcfi *reg_fcfi;
185004c68496SJames Smart 
185104c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
185204c68496SJames Smart 	reg_fcfi = &mbox->u.mqe.un.reg_fcfi;
185304c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI);
185404c68496SJames Smart 	bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, phba->sli4_hba.hdr_rq->queue_id);
185504c68496SJames Smart 	bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
185604c68496SJames Smart 	bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
185704c68496SJames Smart 	bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
185804c68496SJames Smart 	bf_set(lpfc_reg_fcfi_info_index, reg_fcfi, phba->fcf.fcf_indx);
185904c68496SJames Smart 	/* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */
186004c68496SJames Smart 	bf_set(lpfc_reg_fcfi_mam, reg_fcfi,
186104c68496SJames Smart 		(~phba->fcf.addr_mode) & 0x3);
186204c68496SJames Smart 	if (phba->fcf.fcf_flag & FCF_VALID_VLAN) {
186304c68496SJames Smart 		bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
186404c68496SJames Smart 		bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi, phba->fcf.vlan_id);
186504c68496SJames Smart 	}
186604c68496SJames Smart }
186704c68496SJames Smart 
186804c68496SJames Smart /**
186904c68496SJames Smart  * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
187004c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
187104c68496SJames Smart  * @fcfi: FCFI to be unregistered.
187204c68496SJames Smart  *
187304c68496SJames Smart  * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
187404c68496SJames Smart  * The SLI Host uses the command to inactivate an FCFI.
187504c68496SJames Smart  **/
187604c68496SJames Smart void
187704c68496SJames Smart lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi)
187804c68496SJames Smart {
187904c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
188004c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI);
188104c68496SJames Smart 	bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi);
188204c68496SJames Smart }
188304c68496SJames Smart 
188404c68496SJames Smart /**
188504c68496SJames Smart  * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
188604c68496SJames Smart  * @mbox: pointer to lpfc mbox command to initialize.
188704c68496SJames Smart  * @ndlp: The nodelist structure that describes the RPI to resume.
188804c68496SJames Smart  *
188904c68496SJames Smart  * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
189004c68496SJames Smart  * link event.
189104c68496SJames Smart  **/
189204c68496SJames Smart void
189304c68496SJames Smart lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
189404c68496SJames Smart {
189504c68496SJames Smart 	struct lpfc_mbx_resume_rpi *resume_rpi;
189604c68496SJames Smart 
189704c68496SJames Smart 	memset(mbox, 0, sizeof(*mbox));
189804c68496SJames Smart 	resume_rpi = &mbox->u.mqe.un.resume_rpi;
189904c68496SJames Smart 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI);
190004c68496SJames Smart 	bf_set(lpfc_resume_rpi_rpi, resume_rpi, ndlp->nlp_rpi);
190104c68496SJames Smart 	bf_set(lpfc_resume_rpi_vpi, resume_rpi,
190204c68496SJames Smart 	       ndlp->vport->vpi + ndlp->vport->phba->vpi_base);
190304c68496SJames Smart 	bf_set(lpfc_resume_rpi_vfi, resume_rpi,
190404c68496SJames Smart 	       ndlp->vport->vfi + ndlp->vport->phba->vfi_base);
190504c68496SJames Smart }
1906