xref: /OK3568_Linux_fs/kernel/drivers/scsi/lpfc/lpfc_mbox.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*******************************************************************
2*4882a593Smuzhiyun  * This file is part of the Emulex Linux Device Driver for         *
3*4882a593Smuzhiyun  * Fibre Channel Host Bus Adapters.                                *
4*4882a593Smuzhiyun  * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
5*4882a593Smuzhiyun  * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.     *
6*4882a593Smuzhiyun  * Copyright (C) 2004-2016 Emulex.  All rights reserved.           *
7*4882a593Smuzhiyun  * EMULEX and SLI are trademarks of Emulex.                        *
8*4882a593Smuzhiyun  * www.broadcom.com                                                *
9*4882a593Smuzhiyun  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
10*4882a593Smuzhiyun  *                                                                 *
11*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or   *
12*4882a593Smuzhiyun  * modify it under the terms of version 2 of the GNU General       *
13*4882a593Smuzhiyun  * Public License as published by the Free Software Foundation.    *
14*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful. *
15*4882a593Smuzhiyun  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
16*4882a593Smuzhiyun  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
17*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
18*4882a593Smuzhiyun  * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19*4882a593Smuzhiyun  * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
20*4882a593Smuzhiyun  * more details, a copy of which can be found in the file COPYING  *
21*4882a593Smuzhiyun  * included with this package.                                     *
22*4882a593Smuzhiyun  *******************************************************************/
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #include <linux/blkdev.h>
25*4882a593Smuzhiyun #include <linux/pci.h>
26*4882a593Smuzhiyun #include <linux/slab.h>
27*4882a593Smuzhiyun #include <linux/interrupt.h>
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #include <scsi/scsi_device.h>
30*4882a593Smuzhiyun #include <scsi/scsi_transport_fc.h>
31*4882a593Smuzhiyun #include <scsi/scsi.h>
32*4882a593Smuzhiyun #include <scsi/fc/fc_fs.h>
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #include "lpfc_hw4.h"
35*4882a593Smuzhiyun #include "lpfc_hw.h"
36*4882a593Smuzhiyun #include "lpfc_sli.h"
37*4882a593Smuzhiyun #include "lpfc_sli4.h"
38*4882a593Smuzhiyun #include "lpfc_nl.h"
39*4882a593Smuzhiyun #include "lpfc_disc.h"
40*4882a593Smuzhiyun #include "lpfc_scsi.h"
41*4882a593Smuzhiyun #include "lpfc.h"
42*4882a593Smuzhiyun #include "lpfc_logmsg.h"
43*4882a593Smuzhiyun #include "lpfc_crtn.h"
44*4882a593Smuzhiyun #include "lpfc_compat.h"
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun /**
47*4882a593Smuzhiyun  * lpfc_dump_static_vport - Dump HBA's static vport information.
48*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
49*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
50*4882a593Smuzhiyun  * @offset: offset for dumping vport info.
51*4882a593Smuzhiyun  *
52*4882a593Smuzhiyun  * The dump mailbox command provides a method for the device driver to obtain
53*4882a593Smuzhiyun  * various types of information from the HBA device.
54*4882a593Smuzhiyun  *
55*4882a593Smuzhiyun  * This routine prepares the mailbox command for dumping list of static
56*4882a593Smuzhiyun  * vports to be created.
57*4882a593Smuzhiyun  **/
58*4882a593Smuzhiyun int
lpfc_dump_static_vport(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb,uint16_t offset)59*4882a593Smuzhiyun lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
60*4882a593Smuzhiyun 		uint16_t offset)
61*4882a593Smuzhiyun {
62*4882a593Smuzhiyun 	MAILBOX_t *mb;
63*4882a593Smuzhiyun 	struct lpfc_dmabuf *mp;
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun 	mb = &pmb->u.mb;
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun 	/* Setup to dump vport info region */
68*4882a593Smuzhiyun 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
69*4882a593Smuzhiyun 	mb->mbxCommand = MBX_DUMP_MEMORY;
70*4882a593Smuzhiyun 	mb->un.varDmp.type = DMP_NV_PARAMS;
71*4882a593Smuzhiyun 	mb->un.varDmp.entry_index = offset;
72*4882a593Smuzhiyun 	mb->un.varDmp.region_id = DMP_REGION_VPORT;
73*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun 	/* For SLI3 HBAs data is embedded in mailbox */
76*4882a593Smuzhiyun 	if (phba->sli_rev != LPFC_SLI_REV4) {
77*4882a593Smuzhiyun 		mb->un.varDmp.cv = 1;
78*4882a593Smuzhiyun 		mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t);
79*4882a593Smuzhiyun 		return 0;
80*4882a593Smuzhiyun 	}
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun 	/* For SLI4 HBAs driver need to allocate memory */
83*4882a593Smuzhiyun 	mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
84*4882a593Smuzhiyun 	if (mp)
85*4882a593Smuzhiyun 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun 	if (!mp || !mp->virt) {
88*4882a593Smuzhiyun 		kfree(mp);
89*4882a593Smuzhiyun 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
90*4882a593Smuzhiyun 			"2605 lpfc_dump_static_vport: memory"
91*4882a593Smuzhiyun 			" allocation failed\n");
92*4882a593Smuzhiyun 		return 1;
93*4882a593Smuzhiyun 	}
94*4882a593Smuzhiyun 	memset(mp->virt, 0, LPFC_BPL_SIZE);
95*4882a593Smuzhiyun 	INIT_LIST_HEAD(&mp->list);
96*4882a593Smuzhiyun 	/* save address for completion */
97*4882a593Smuzhiyun 	pmb->ctx_buf = (uint8_t *)mp;
98*4882a593Smuzhiyun 	mb->un.varWords[3] = putPaddrLow(mp->phys);
99*4882a593Smuzhiyun 	mb->un.varWords[4] = putPaddrHigh(mp->phys);
100*4882a593Smuzhiyun 	mb->un.varDmp.sli4_length = sizeof(struct static_vport_info);
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun 	return 0;
103*4882a593Smuzhiyun }
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun /**
106*4882a593Smuzhiyun  * lpfc_down_link - Bring down HBAs link.
107*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
108*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
109*4882a593Smuzhiyun  *
110*4882a593Smuzhiyun  * This routine prepares a mailbox command to bring down HBA link.
111*4882a593Smuzhiyun  **/
112*4882a593Smuzhiyun void
lpfc_down_link(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)113*4882a593Smuzhiyun lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
114*4882a593Smuzhiyun {
115*4882a593Smuzhiyun 	MAILBOX_t *mb;
116*4882a593Smuzhiyun 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
117*4882a593Smuzhiyun 	mb = &pmb->u.mb;
118*4882a593Smuzhiyun 	mb->mbxCommand = MBX_DOWN_LINK;
119*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
120*4882a593Smuzhiyun }
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun /**
123*4882a593Smuzhiyun  * lpfc_dump_mem - Prepare a mailbox command for reading a region.
124*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
125*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
126*4882a593Smuzhiyun  * @offset: offset into the region.
127*4882a593Smuzhiyun  * @region_id: config region id.
128*4882a593Smuzhiyun  *
129*4882a593Smuzhiyun  * The dump mailbox command provides a method for the device driver to obtain
130*4882a593Smuzhiyun  * various types of information from the HBA device.
131*4882a593Smuzhiyun  *
132*4882a593Smuzhiyun  * This routine prepares the mailbox command for dumping HBA's config region.
133*4882a593Smuzhiyun  **/
134*4882a593Smuzhiyun void
lpfc_dump_mem(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb,uint16_t offset,uint16_t region_id)135*4882a593Smuzhiyun lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset,
136*4882a593Smuzhiyun 		uint16_t region_id)
137*4882a593Smuzhiyun {
138*4882a593Smuzhiyun 	MAILBOX_t *mb;
139*4882a593Smuzhiyun 	void *ctx;
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun 	mb = &pmb->u.mb;
142*4882a593Smuzhiyun 	ctx = pmb->ctx_buf;
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun 	/* Setup to dump VPD region */
145*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
146*4882a593Smuzhiyun 	mb->mbxCommand = MBX_DUMP_MEMORY;
147*4882a593Smuzhiyun 	mb->un.varDmp.cv = 1;
148*4882a593Smuzhiyun 	mb->un.varDmp.type = DMP_NV_PARAMS;
149*4882a593Smuzhiyun 	mb->un.varDmp.entry_index = offset;
150*4882a593Smuzhiyun 	mb->un.varDmp.region_id = region_id;
151*4882a593Smuzhiyun 	mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
152*4882a593Smuzhiyun 	mb->un.varDmp.co = 0;
153*4882a593Smuzhiyun 	mb->un.varDmp.resp_offset = 0;
154*4882a593Smuzhiyun 	pmb->ctx_buf = ctx;
155*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
156*4882a593Smuzhiyun 	return;
157*4882a593Smuzhiyun }
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun /**
160*4882a593Smuzhiyun  * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
161*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
162*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
163*4882a593Smuzhiyun  *
164*4882a593Smuzhiyun  * This function create a dump memory mailbox command to dump wake up
165*4882a593Smuzhiyun  * parameters.
166*4882a593Smuzhiyun  */
167*4882a593Smuzhiyun void
lpfc_dump_wakeup_param(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)168*4882a593Smuzhiyun lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
169*4882a593Smuzhiyun {
170*4882a593Smuzhiyun 	MAILBOX_t *mb;
171*4882a593Smuzhiyun 	void *ctx;
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun 	mb = &pmb->u.mb;
174*4882a593Smuzhiyun 	/* Save context so that we can restore after memset */
175*4882a593Smuzhiyun 	ctx = pmb->ctx_buf;
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun 	/* Setup to dump VPD region */
178*4882a593Smuzhiyun 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
179*4882a593Smuzhiyun 	mb->mbxCommand = MBX_DUMP_MEMORY;
180*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
181*4882a593Smuzhiyun 	mb->un.varDmp.cv = 1;
182*4882a593Smuzhiyun 	mb->un.varDmp.type = DMP_NV_PARAMS;
183*4882a593Smuzhiyun 	if (phba->sli_rev < LPFC_SLI_REV4)
184*4882a593Smuzhiyun 		mb->un.varDmp.entry_index = 0;
185*4882a593Smuzhiyun 	mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
186*4882a593Smuzhiyun 	mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
187*4882a593Smuzhiyun 	mb->un.varDmp.co = 0;
188*4882a593Smuzhiyun 	mb->un.varDmp.resp_offset = 0;
189*4882a593Smuzhiyun 	pmb->ctx_buf = ctx;
190*4882a593Smuzhiyun 	return;
191*4882a593Smuzhiyun }
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun /**
194*4882a593Smuzhiyun  * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
195*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
196*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
197*4882a593Smuzhiyun  *
198*4882a593Smuzhiyun  * The read NVRAM mailbox command returns the HBA's non-volatile parameters
199*4882a593Smuzhiyun  * that are used as defaults when the Fibre Channel link is brought on-line.
200*4882a593Smuzhiyun  *
201*4882a593Smuzhiyun  * This routine prepares the mailbox command for reading information stored
202*4882a593Smuzhiyun  * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
203*4882a593Smuzhiyun  **/
204*4882a593Smuzhiyun void
lpfc_read_nv(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)205*4882a593Smuzhiyun lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
206*4882a593Smuzhiyun {
207*4882a593Smuzhiyun 	MAILBOX_t *mb;
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun 	mb = &pmb->u.mb;
210*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
211*4882a593Smuzhiyun 	mb->mbxCommand = MBX_READ_NV;
212*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
213*4882a593Smuzhiyun 	return;
214*4882a593Smuzhiyun }
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun /**
217*4882a593Smuzhiyun  * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
218*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
219*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
220*4882a593Smuzhiyun  * @ring: ring number for the asynchronous event to be configured.
221*4882a593Smuzhiyun  *
222*4882a593Smuzhiyun  * The asynchronous event enable mailbox command is used to enable the
223*4882a593Smuzhiyun  * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
224*4882a593Smuzhiyun  * specifies the default ring to which events are posted.
225*4882a593Smuzhiyun  *
226*4882a593Smuzhiyun  * This routine prepares the mailbox command for enabling HBA asynchronous
227*4882a593Smuzhiyun  * event support on a IOCB ring.
228*4882a593Smuzhiyun  **/
229*4882a593Smuzhiyun void
lpfc_config_async(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb,uint32_t ring)230*4882a593Smuzhiyun lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
231*4882a593Smuzhiyun 		uint32_t ring)
232*4882a593Smuzhiyun {
233*4882a593Smuzhiyun 	MAILBOX_t *mb;
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun 	mb = &pmb->u.mb;
236*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
237*4882a593Smuzhiyun 	mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
238*4882a593Smuzhiyun 	mb->un.varCfgAsyncEvent.ring = ring;
239*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
240*4882a593Smuzhiyun 	return;
241*4882a593Smuzhiyun }
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun /**
244*4882a593Smuzhiyun  * lpfc_heart_beat - Prepare a mailbox command for heart beat
245*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
246*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
247*4882a593Smuzhiyun  *
248*4882a593Smuzhiyun  * The heart beat mailbox command is used to detect an unresponsive HBA, which
249*4882a593Smuzhiyun  * is defined as any device where no error attention is sent and both mailbox
250*4882a593Smuzhiyun  * and rings are not processed.
251*4882a593Smuzhiyun  *
252*4882a593Smuzhiyun  * This routine prepares the mailbox command for issuing a heart beat in the
253*4882a593Smuzhiyun  * form of mailbox command to the HBA. The timely completion of the heart
254*4882a593Smuzhiyun  * beat mailbox command indicates the health of the HBA.
255*4882a593Smuzhiyun  **/
256*4882a593Smuzhiyun void
lpfc_heart_beat(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)257*4882a593Smuzhiyun lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
258*4882a593Smuzhiyun {
259*4882a593Smuzhiyun 	MAILBOX_t *mb;
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun 	mb = &pmb->u.mb;
262*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
263*4882a593Smuzhiyun 	mb->mbxCommand = MBX_HEARTBEAT;
264*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
265*4882a593Smuzhiyun 	return;
266*4882a593Smuzhiyun }
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun /**
269*4882a593Smuzhiyun  * lpfc_read_topology - Prepare a mailbox command for reading HBA topology
270*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
271*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
272*4882a593Smuzhiyun  * @mp: DMA buffer memory for reading the link attention information into.
273*4882a593Smuzhiyun  *
274*4882a593Smuzhiyun  * The read topology mailbox command is issued to read the link topology
275*4882a593Smuzhiyun  * information indicated by the HBA port when the Link Event bit of the Host
276*4882a593Smuzhiyun  * Attention (HSTATT) register is set to 1 (For SLI-3) or when an FC Link
277*4882a593Smuzhiyun  * Attention ACQE is received from the port (For SLI-4). A Link Event
278*4882a593Smuzhiyun  * Attention occurs based on an exception detected at the Fibre Channel link
279*4882a593Smuzhiyun  * interface.
280*4882a593Smuzhiyun  *
281*4882a593Smuzhiyun  * This routine prepares the mailbox command for reading HBA link topology
282*4882a593Smuzhiyun  * information. A DMA memory has been set aside and address passed to the
283*4882a593Smuzhiyun  * HBA through @mp for the HBA to DMA link attention information into the
284*4882a593Smuzhiyun  * memory as part of the execution of the mailbox command.
285*4882a593Smuzhiyun  *
286*4882a593Smuzhiyun  * Return codes
287*4882a593Smuzhiyun  *    0 - Success (currently always return 0)
288*4882a593Smuzhiyun  **/
289*4882a593Smuzhiyun int
lpfc_read_topology(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb,struct lpfc_dmabuf * mp)290*4882a593Smuzhiyun lpfc_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
291*4882a593Smuzhiyun 		   struct lpfc_dmabuf *mp)
292*4882a593Smuzhiyun {
293*4882a593Smuzhiyun 	MAILBOX_t *mb;
294*4882a593Smuzhiyun 
295*4882a593Smuzhiyun 	mb = &pmb->u.mb;
296*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
297*4882a593Smuzhiyun 
298*4882a593Smuzhiyun 	INIT_LIST_HEAD(&mp->list);
299*4882a593Smuzhiyun 	mb->mbxCommand = MBX_READ_TOPOLOGY;
300*4882a593Smuzhiyun 	mb->un.varReadTop.lilpBde64.tus.f.bdeSize = LPFC_ALPA_MAP_SIZE;
301*4882a593Smuzhiyun 	mb->un.varReadTop.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
302*4882a593Smuzhiyun 	mb->un.varReadTop.lilpBde64.addrLow = putPaddrLow(mp->phys);
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun 	/* Save address for later completion and set the owner to host so that
305*4882a593Smuzhiyun 	 * the FW knows this mailbox is available for processing.
306*4882a593Smuzhiyun 	 */
307*4882a593Smuzhiyun 	pmb->ctx_buf = (uint8_t *)mp;
308*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
309*4882a593Smuzhiyun 	return (0);
310*4882a593Smuzhiyun }
311*4882a593Smuzhiyun 
312*4882a593Smuzhiyun /**
313*4882a593Smuzhiyun  * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
314*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
315*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
316*4882a593Smuzhiyun  *
317*4882a593Smuzhiyun  * The clear link attention mailbox command is issued to clear the link event
318*4882a593Smuzhiyun  * attention condition indicated by the Link Event bit of the Host Attention
319*4882a593Smuzhiyun  * (HSTATT) register. The link event attention condition is cleared only if
320*4882a593Smuzhiyun  * the event tag specified matches that of the current link event counter.
321*4882a593Smuzhiyun  * The current event tag is read using the read link attention event mailbox
322*4882a593Smuzhiyun  * command.
323*4882a593Smuzhiyun  *
324*4882a593Smuzhiyun  * This routine prepares the mailbox command for clearing HBA link attention
325*4882a593Smuzhiyun  * information.
326*4882a593Smuzhiyun  **/
327*4882a593Smuzhiyun void
lpfc_clear_la(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)328*4882a593Smuzhiyun lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
329*4882a593Smuzhiyun {
330*4882a593Smuzhiyun 	MAILBOX_t *mb;
331*4882a593Smuzhiyun 
332*4882a593Smuzhiyun 	mb = &pmb->u.mb;
333*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
334*4882a593Smuzhiyun 
335*4882a593Smuzhiyun 	mb->un.varClearLA.eventTag = phba->fc_eventTag;
336*4882a593Smuzhiyun 	mb->mbxCommand = MBX_CLEAR_LA;
337*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
338*4882a593Smuzhiyun 	return;
339*4882a593Smuzhiyun }
340*4882a593Smuzhiyun 
341*4882a593Smuzhiyun /**
342*4882a593Smuzhiyun  * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
343*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
344*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
345*4882a593Smuzhiyun  *
346*4882a593Smuzhiyun  * The configure link mailbox command is used before the initialize link
347*4882a593Smuzhiyun  * mailbox command to override default value and to configure link-oriented
348*4882a593Smuzhiyun  * parameters such as DID address and various timers. Typically, this
349*4882a593Smuzhiyun  * command would be used after an F_Port login to set the returned DID address
350*4882a593Smuzhiyun  * and the fabric timeout values. This command is not valid before a configure
351*4882a593Smuzhiyun  * port command has configured the HBA port.
352*4882a593Smuzhiyun  *
353*4882a593Smuzhiyun  * This routine prepares the mailbox command for configuring link on a HBA.
354*4882a593Smuzhiyun  **/
355*4882a593Smuzhiyun void
lpfc_config_link(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)356*4882a593Smuzhiyun lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
357*4882a593Smuzhiyun {
358*4882a593Smuzhiyun 	struct lpfc_vport  *vport = phba->pport;
359*4882a593Smuzhiyun 	MAILBOX_t *mb = &pmb->u.mb;
360*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun 	/* NEW_FEATURE
363*4882a593Smuzhiyun 	 * SLI-2, Coalescing Response Feature.
364*4882a593Smuzhiyun 	 */
365*4882a593Smuzhiyun 	if (phba->cfg_cr_delay && (phba->sli_rev < LPFC_SLI_REV4)) {
366*4882a593Smuzhiyun 		mb->un.varCfgLnk.cr = 1;
367*4882a593Smuzhiyun 		mb->un.varCfgLnk.ci = 1;
368*4882a593Smuzhiyun 		mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
369*4882a593Smuzhiyun 		mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
370*4882a593Smuzhiyun 	}
371*4882a593Smuzhiyun 
372*4882a593Smuzhiyun 	mb->un.varCfgLnk.myId = vport->fc_myDID;
373*4882a593Smuzhiyun 	mb->un.varCfgLnk.edtov = phba->fc_edtov;
374*4882a593Smuzhiyun 	mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
375*4882a593Smuzhiyun 	mb->un.varCfgLnk.ratov = phba->fc_ratov;
376*4882a593Smuzhiyun 	mb->un.varCfgLnk.rttov = phba->fc_rttov;
377*4882a593Smuzhiyun 	mb->un.varCfgLnk.altov = phba->fc_altov;
378*4882a593Smuzhiyun 	mb->un.varCfgLnk.crtov = phba->fc_crtov;
379*4882a593Smuzhiyun 	mb->un.varCfgLnk.cscn = 0;
380*4882a593Smuzhiyun 	if (phba->bbcredit_support && phba->cfg_enable_bbcr) {
381*4882a593Smuzhiyun 		mb->un.varCfgLnk.cscn = 1;
382*4882a593Smuzhiyun 		mb->un.varCfgLnk.bbscn = bf_get(lpfc_bbscn_def,
383*4882a593Smuzhiyun 						 &phba->sli4_hba.bbscn_params);
384*4882a593Smuzhiyun 	}
385*4882a593Smuzhiyun 
386*4882a593Smuzhiyun 	if (phba->cfg_ack0 && (phba->sli_rev < LPFC_SLI_REV4))
387*4882a593Smuzhiyun 		mb->un.varCfgLnk.ack0_enable = 1;
388*4882a593Smuzhiyun 
389*4882a593Smuzhiyun 	mb->mbxCommand = MBX_CONFIG_LINK;
390*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
391*4882a593Smuzhiyun 	return;
392*4882a593Smuzhiyun }
393*4882a593Smuzhiyun 
394*4882a593Smuzhiyun /**
395*4882a593Smuzhiyun  * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
396*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
397*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
398*4882a593Smuzhiyun  *
399*4882a593Smuzhiyun  * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
400*4882a593Smuzhiyun  * MSI-X multi-message interrupt vector association to interrupt attention
401*4882a593Smuzhiyun  * conditions.
402*4882a593Smuzhiyun  *
403*4882a593Smuzhiyun  * Return codes
404*4882a593Smuzhiyun  *    0 - Success
405*4882a593Smuzhiyun  *    -EINVAL - Failure
406*4882a593Smuzhiyun  **/
407*4882a593Smuzhiyun int
lpfc_config_msi(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)408*4882a593Smuzhiyun lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
409*4882a593Smuzhiyun {
410*4882a593Smuzhiyun 	MAILBOX_t *mb = &pmb->u.mb;
411*4882a593Smuzhiyun 	uint32_t attentionConditions[2];
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun 	/* Sanity check */
414*4882a593Smuzhiyun 	if (phba->cfg_use_msi != 2) {
415*4882a593Smuzhiyun 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
416*4882a593Smuzhiyun 				"0475 Not configured for supporting MSI-X "
417*4882a593Smuzhiyun 				"cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
418*4882a593Smuzhiyun 		return -EINVAL;
419*4882a593Smuzhiyun 	}
420*4882a593Smuzhiyun 
421*4882a593Smuzhiyun 	if (phba->sli_rev < 3) {
422*4882a593Smuzhiyun 		lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
423*4882a593Smuzhiyun 				"0476 HBA not supporting SLI-3 or later "
424*4882a593Smuzhiyun 				"SLI Revision: 0x%x\n", phba->sli_rev);
425*4882a593Smuzhiyun 		return -EINVAL;
426*4882a593Smuzhiyun 	}
427*4882a593Smuzhiyun 
428*4882a593Smuzhiyun 	/* Clear mailbox command fields */
429*4882a593Smuzhiyun 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
430*4882a593Smuzhiyun 
431*4882a593Smuzhiyun 	/*
432*4882a593Smuzhiyun 	 * SLI-3, Message Signaled Interrupt Fearure.
433*4882a593Smuzhiyun 	 */
434*4882a593Smuzhiyun 
435*4882a593Smuzhiyun 	/* Multi-message attention configuration */
436*4882a593Smuzhiyun 	attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
437*4882a593Smuzhiyun 				  HA_LATT | HA_MBATT);
438*4882a593Smuzhiyun 	attentionConditions[1] = 0;
439*4882a593Smuzhiyun 
440*4882a593Smuzhiyun 	mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
441*4882a593Smuzhiyun 	mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
442*4882a593Smuzhiyun 
443*4882a593Smuzhiyun 	/*
444*4882a593Smuzhiyun 	 * Set up message number to HA bit association
445*4882a593Smuzhiyun 	 */
446*4882a593Smuzhiyun #ifdef __BIG_ENDIAN_BITFIELD
447*4882a593Smuzhiyun 	/* RA0 (FCP Ring) */
448*4882a593Smuzhiyun 	mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
449*4882a593Smuzhiyun 	/* RA1 (Other Protocol Extra Ring) */
450*4882a593Smuzhiyun 	mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
451*4882a593Smuzhiyun #else   /*  __LITTLE_ENDIAN_BITFIELD */
452*4882a593Smuzhiyun 	/* RA0 (FCP Ring) */
453*4882a593Smuzhiyun 	mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
454*4882a593Smuzhiyun 	/* RA1 (Other Protocol Extra Ring) */
455*4882a593Smuzhiyun 	mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
456*4882a593Smuzhiyun #endif
457*4882a593Smuzhiyun 	/* Multi-message interrupt autoclear configuration*/
458*4882a593Smuzhiyun 	mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
459*4882a593Smuzhiyun 	mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
460*4882a593Smuzhiyun 
461*4882a593Smuzhiyun 	/* For now, HBA autoclear does not work reliably, disable it */
462*4882a593Smuzhiyun 	mb->un.varCfgMSI.autoClearHA[0] = 0;
463*4882a593Smuzhiyun 	mb->un.varCfgMSI.autoClearHA[1] = 0;
464*4882a593Smuzhiyun 
465*4882a593Smuzhiyun 	/* Set command and owner bit */
466*4882a593Smuzhiyun 	mb->mbxCommand = MBX_CONFIG_MSI;
467*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun 	return 0;
470*4882a593Smuzhiyun }
471*4882a593Smuzhiyun 
472*4882a593Smuzhiyun /**
473*4882a593Smuzhiyun  * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
474*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
475*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
476*4882a593Smuzhiyun  * @topology: the link topology for the link to be initialized to.
477*4882a593Smuzhiyun  * @linkspeed: the link speed for the link to be initialized to.
478*4882a593Smuzhiyun  *
479*4882a593Smuzhiyun  * The initialize link mailbox command is used to initialize the Fibre
480*4882a593Smuzhiyun  * Channel link. This command must follow a configure port command that
481*4882a593Smuzhiyun  * establishes the mode of operation.
482*4882a593Smuzhiyun  *
483*4882a593Smuzhiyun  * This routine prepares the mailbox command for initializing link on a HBA
484*4882a593Smuzhiyun  * with the specified link topology and speed.
485*4882a593Smuzhiyun  **/
486*4882a593Smuzhiyun void
lpfc_init_link(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb,uint32_t topology,uint32_t linkspeed)487*4882a593Smuzhiyun lpfc_init_link(struct lpfc_hba * phba,
488*4882a593Smuzhiyun 	       LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
489*4882a593Smuzhiyun {
490*4882a593Smuzhiyun 	lpfc_vpd_t *vpd;
491*4882a593Smuzhiyun 	MAILBOX_t *mb;
492*4882a593Smuzhiyun 
493*4882a593Smuzhiyun 	mb = &pmb->u.mb;
494*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
495*4882a593Smuzhiyun 
496*4882a593Smuzhiyun 	switch (topology) {
497*4882a593Smuzhiyun 	case FLAGS_TOPOLOGY_MODE_LOOP_PT:
498*4882a593Smuzhiyun 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
499*4882a593Smuzhiyun 		mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
500*4882a593Smuzhiyun 		break;
501*4882a593Smuzhiyun 	case FLAGS_TOPOLOGY_MODE_PT_PT:
502*4882a593Smuzhiyun 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
503*4882a593Smuzhiyun 		break;
504*4882a593Smuzhiyun 	case FLAGS_TOPOLOGY_MODE_LOOP:
505*4882a593Smuzhiyun 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
506*4882a593Smuzhiyun 		break;
507*4882a593Smuzhiyun 	case FLAGS_TOPOLOGY_MODE_PT_LOOP:
508*4882a593Smuzhiyun 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
509*4882a593Smuzhiyun 		mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
510*4882a593Smuzhiyun 		break;
511*4882a593Smuzhiyun 	case FLAGS_LOCAL_LB:
512*4882a593Smuzhiyun 		mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
513*4882a593Smuzhiyun 		break;
514*4882a593Smuzhiyun 	}
515*4882a593Smuzhiyun 
516*4882a593Smuzhiyun 	if ((phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC ||
517*4882a593Smuzhiyun 	     phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC) &&
518*4882a593Smuzhiyun 	    !(phba->sli4_hba.pc_sli4_params.pls) &&
519*4882a593Smuzhiyun 	    mb->un.varInitLnk.link_flags & FLAGS_TOPOLOGY_MODE_LOOP) {
520*4882a593Smuzhiyun 		mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
521*4882a593Smuzhiyun 		phba->cfg_topology = FLAGS_TOPOLOGY_MODE_PT_PT;
522*4882a593Smuzhiyun 	}
523*4882a593Smuzhiyun 
524*4882a593Smuzhiyun 	/* Enable asynchronous ABTS responses from firmware */
525*4882a593Smuzhiyun 	mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
526*4882a593Smuzhiyun 
527*4882a593Smuzhiyun 	/* NEW_FEATURE
528*4882a593Smuzhiyun 	 * Setting up the link speed
529*4882a593Smuzhiyun 	 */
530*4882a593Smuzhiyun 	vpd = &phba->vpd;
531*4882a593Smuzhiyun 	if (vpd->rev.feaLevelHigh >= 0x02){
532*4882a593Smuzhiyun 		switch(linkspeed){
533*4882a593Smuzhiyun 		case LPFC_USER_LINK_SPEED_1G:
534*4882a593Smuzhiyun 			mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
535*4882a593Smuzhiyun 			mb->un.varInitLnk.link_speed = LINK_SPEED_1G;
536*4882a593Smuzhiyun 			break;
537*4882a593Smuzhiyun 		case LPFC_USER_LINK_SPEED_2G:
538*4882a593Smuzhiyun 			mb->un.varInitLnk.link_flags |=	FLAGS_LINK_SPEED;
539*4882a593Smuzhiyun 			mb->un.varInitLnk.link_speed = LINK_SPEED_2G;
540*4882a593Smuzhiyun 			break;
541*4882a593Smuzhiyun 		case LPFC_USER_LINK_SPEED_4G:
542*4882a593Smuzhiyun 			mb->un.varInitLnk.link_flags |=	FLAGS_LINK_SPEED;
543*4882a593Smuzhiyun 			mb->un.varInitLnk.link_speed = LINK_SPEED_4G;
544*4882a593Smuzhiyun 			break;
545*4882a593Smuzhiyun 		case LPFC_USER_LINK_SPEED_8G:
546*4882a593Smuzhiyun 			mb->un.varInitLnk.link_flags |=	FLAGS_LINK_SPEED;
547*4882a593Smuzhiyun 			mb->un.varInitLnk.link_speed = LINK_SPEED_8G;
548*4882a593Smuzhiyun 			break;
549*4882a593Smuzhiyun 		case LPFC_USER_LINK_SPEED_10G:
550*4882a593Smuzhiyun 			mb->un.varInitLnk.link_flags |=	FLAGS_LINK_SPEED;
551*4882a593Smuzhiyun 			mb->un.varInitLnk.link_speed = LINK_SPEED_10G;
552*4882a593Smuzhiyun 			break;
553*4882a593Smuzhiyun 		case LPFC_USER_LINK_SPEED_16G:
554*4882a593Smuzhiyun 			mb->un.varInitLnk.link_flags |=	FLAGS_LINK_SPEED;
555*4882a593Smuzhiyun 			mb->un.varInitLnk.link_speed = LINK_SPEED_16G;
556*4882a593Smuzhiyun 			break;
557*4882a593Smuzhiyun 		case LPFC_USER_LINK_SPEED_32G:
558*4882a593Smuzhiyun 			mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
559*4882a593Smuzhiyun 			mb->un.varInitLnk.link_speed = LINK_SPEED_32G;
560*4882a593Smuzhiyun 			break;
561*4882a593Smuzhiyun 		case LPFC_USER_LINK_SPEED_64G:
562*4882a593Smuzhiyun 			mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
563*4882a593Smuzhiyun 			mb->un.varInitLnk.link_speed = LINK_SPEED_64G;
564*4882a593Smuzhiyun 			break;
565*4882a593Smuzhiyun 		case LPFC_USER_LINK_SPEED_AUTO:
566*4882a593Smuzhiyun 		default:
567*4882a593Smuzhiyun 			mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
568*4882a593Smuzhiyun 			break;
569*4882a593Smuzhiyun 		}
570*4882a593Smuzhiyun 
571*4882a593Smuzhiyun 	}
572*4882a593Smuzhiyun 	else
573*4882a593Smuzhiyun 		mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
574*4882a593Smuzhiyun 
575*4882a593Smuzhiyun 	mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
576*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
577*4882a593Smuzhiyun 	mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
578*4882a593Smuzhiyun 	return;
579*4882a593Smuzhiyun }
580*4882a593Smuzhiyun 
581*4882a593Smuzhiyun /**
582*4882a593Smuzhiyun  * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
583*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
584*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
585*4882a593Smuzhiyun  * @vpi: virtual N_Port identifier.
586*4882a593Smuzhiyun  *
587*4882a593Smuzhiyun  * The read service parameter mailbox command is used to read the HBA port
588*4882a593Smuzhiyun  * service parameters. The service parameters are read into the buffer
589*4882a593Smuzhiyun  * specified directly by a BDE in the mailbox command. These service
590*4882a593Smuzhiyun  * parameters may then be used to build the payload of an N_Port/F_POrt
591*4882a593Smuzhiyun  * login request and reply (LOGI/ACC).
592*4882a593Smuzhiyun  *
593*4882a593Smuzhiyun  * This routine prepares the mailbox command for reading HBA port service
594*4882a593Smuzhiyun  * parameters. The DMA memory is allocated in this function and the addresses
595*4882a593Smuzhiyun  * are populated into the mailbox command for the HBA to DMA the service
596*4882a593Smuzhiyun  * parameters into.
597*4882a593Smuzhiyun  *
598*4882a593Smuzhiyun  * Return codes
599*4882a593Smuzhiyun  *    0 - Success
600*4882a593Smuzhiyun  *    1 - DMA memory allocation failed
601*4882a593Smuzhiyun  **/
602*4882a593Smuzhiyun int
lpfc_read_sparam(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb,int vpi)603*4882a593Smuzhiyun lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
604*4882a593Smuzhiyun {
605*4882a593Smuzhiyun 	struct lpfc_dmabuf *mp;
606*4882a593Smuzhiyun 	MAILBOX_t *mb;
607*4882a593Smuzhiyun 
608*4882a593Smuzhiyun 	mb = &pmb->u.mb;
609*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
610*4882a593Smuzhiyun 
611*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
612*4882a593Smuzhiyun 
613*4882a593Smuzhiyun 	/* Get a buffer to hold the HBAs Service Parameters */
614*4882a593Smuzhiyun 
615*4882a593Smuzhiyun 	mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
616*4882a593Smuzhiyun 	if (mp)
617*4882a593Smuzhiyun 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
618*4882a593Smuzhiyun 	if (!mp || !mp->virt) {
619*4882a593Smuzhiyun 		kfree(mp);
620*4882a593Smuzhiyun 		mb->mbxCommand = MBX_READ_SPARM64;
621*4882a593Smuzhiyun 		/* READ_SPARAM: no buffers */
622*4882a593Smuzhiyun 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
623*4882a593Smuzhiyun 			        "0301 READ_SPARAM: no buffers\n");
624*4882a593Smuzhiyun 		return (1);
625*4882a593Smuzhiyun 	}
626*4882a593Smuzhiyun 	INIT_LIST_HEAD(&mp->list);
627*4882a593Smuzhiyun 	mb->mbxCommand = MBX_READ_SPARM64;
628*4882a593Smuzhiyun 	mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
629*4882a593Smuzhiyun 	mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
630*4882a593Smuzhiyun 	mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
631*4882a593Smuzhiyun 	if (phba->sli_rev >= LPFC_SLI_REV3)
632*4882a593Smuzhiyun 		mb->un.varRdSparm.vpi = phba->vpi_ids[vpi];
633*4882a593Smuzhiyun 
634*4882a593Smuzhiyun 	/* save address for completion */
635*4882a593Smuzhiyun 	pmb->ctx_buf = mp;
636*4882a593Smuzhiyun 
637*4882a593Smuzhiyun 	return (0);
638*4882a593Smuzhiyun }
639*4882a593Smuzhiyun 
640*4882a593Smuzhiyun /**
641*4882a593Smuzhiyun  * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
642*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
643*4882a593Smuzhiyun  * @vpi: virtual N_Port identifier.
644*4882a593Smuzhiyun  * @did: remote port identifier.
645*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
646*4882a593Smuzhiyun  *
647*4882a593Smuzhiyun  * The unregister DID mailbox command is used to unregister an N_Port/F_Port
648*4882a593Smuzhiyun  * login for an unknown RPI by specifying the DID of a remote port. This
649*4882a593Smuzhiyun  * command frees an RPI context in the HBA port. This has the effect of
650*4882a593Smuzhiyun  * performing an implicit N_Port/F_Port logout.
651*4882a593Smuzhiyun  *
652*4882a593Smuzhiyun  * This routine prepares the mailbox command for unregistering a remote
653*4882a593Smuzhiyun  * N_Port/F_Port (DID) login.
654*4882a593Smuzhiyun  **/
655*4882a593Smuzhiyun void
lpfc_unreg_did(struct lpfc_hba * phba,uint16_t vpi,uint32_t did,LPFC_MBOXQ_t * pmb)656*4882a593Smuzhiyun lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
657*4882a593Smuzhiyun 	       LPFC_MBOXQ_t * pmb)
658*4882a593Smuzhiyun {
659*4882a593Smuzhiyun 	MAILBOX_t *mb;
660*4882a593Smuzhiyun 
661*4882a593Smuzhiyun 	mb = &pmb->u.mb;
662*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
663*4882a593Smuzhiyun 
664*4882a593Smuzhiyun 	mb->un.varUnregDID.did = did;
665*4882a593Smuzhiyun 	mb->un.varUnregDID.vpi = vpi;
666*4882a593Smuzhiyun 	if ((vpi != 0xffff) &&
667*4882a593Smuzhiyun 	    (phba->sli_rev == LPFC_SLI_REV4))
668*4882a593Smuzhiyun 		mb->un.varUnregDID.vpi = phba->vpi_ids[vpi];
669*4882a593Smuzhiyun 
670*4882a593Smuzhiyun 	mb->mbxCommand = MBX_UNREG_D_ID;
671*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
672*4882a593Smuzhiyun 	return;
673*4882a593Smuzhiyun }
674*4882a593Smuzhiyun 
675*4882a593Smuzhiyun /**
676*4882a593Smuzhiyun  * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
677*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
678*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
679*4882a593Smuzhiyun  *
680*4882a593Smuzhiyun  * The read configuration mailbox command is used to read the HBA port
681*4882a593Smuzhiyun  * configuration parameters. This mailbox command provides a method for
682*4882a593Smuzhiyun  * seeing any parameters that may have changed via various configuration
683*4882a593Smuzhiyun  * mailbox commands.
684*4882a593Smuzhiyun  *
685*4882a593Smuzhiyun  * This routine prepares the mailbox command for reading out HBA configuration
686*4882a593Smuzhiyun  * parameters.
687*4882a593Smuzhiyun  **/
688*4882a593Smuzhiyun void
lpfc_read_config(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)689*4882a593Smuzhiyun lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
690*4882a593Smuzhiyun {
691*4882a593Smuzhiyun 	MAILBOX_t *mb;
692*4882a593Smuzhiyun 
693*4882a593Smuzhiyun 	mb = &pmb->u.mb;
694*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
695*4882a593Smuzhiyun 
696*4882a593Smuzhiyun 	mb->mbxCommand = MBX_READ_CONFIG;
697*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
698*4882a593Smuzhiyun 	return;
699*4882a593Smuzhiyun }
700*4882a593Smuzhiyun 
701*4882a593Smuzhiyun /**
702*4882a593Smuzhiyun  * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
703*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
704*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
705*4882a593Smuzhiyun  *
706*4882a593Smuzhiyun  * The read link status mailbox command is used to read the link status from
707*4882a593Smuzhiyun  * the HBA. Link status includes all link-related error counters. These
708*4882a593Smuzhiyun  * counters are maintained by the HBA and originated in the link hardware
709*4882a593Smuzhiyun  * unit. Note that all of these counters wrap.
710*4882a593Smuzhiyun  *
711*4882a593Smuzhiyun  * This routine prepares the mailbox command for reading out HBA link status.
712*4882a593Smuzhiyun  **/
713*4882a593Smuzhiyun void
lpfc_read_lnk_stat(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)714*4882a593Smuzhiyun lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
715*4882a593Smuzhiyun {
716*4882a593Smuzhiyun 	MAILBOX_t *mb;
717*4882a593Smuzhiyun 
718*4882a593Smuzhiyun 	mb = &pmb->u.mb;
719*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
720*4882a593Smuzhiyun 
721*4882a593Smuzhiyun 	mb->mbxCommand = MBX_READ_LNK_STAT;
722*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
723*4882a593Smuzhiyun 	return;
724*4882a593Smuzhiyun }
725*4882a593Smuzhiyun 
726*4882a593Smuzhiyun /**
727*4882a593Smuzhiyun  * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
728*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
729*4882a593Smuzhiyun  * @vpi: virtual N_Port identifier.
730*4882a593Smuzhiyun  * @did: remote port identifier.
731*4882a593Smuzhiyun  * @param: pointer to memory holding the server parameters.
732*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
733*4882a593Smuzhiyun  * @rpi: the rpi to use in the registration (usually only used for SLI4.
734*4882a593Smuzhiyun  *
735*4882a593Smuzhiyun  * The registration login mailbox command is used to register an N_Port or
736*4882a593Smuzhiyun  * F_Port login. This registration allows the HBA to cache the remote N_Port
737*4882a593Smuzhiyun  * service parameters internally and thereby make the appropriate FC-2
738*4882a593Smuzhiyun  * decisions. The remote port service parameters are handed off by the driver
739*4882a593Smuzhiyun  * to the HBA using a descriptor entry that directly identifies a buffer in
740*4882a593Smuzhiyun  * host memory. In exchange, the HBA returns an RPI identifier.
741*4882a593Smuzhiyun  *
742*4882a593Smuzhiyun  * This routine prepares the mailbox command for registering remote port login.
743*4882a593Smuzhiyun  * The function allocates DMA buffer for passing the service parameters to the
744*4882a593Smuzhiyun  * HBA with the mailbox command.
745*4882a593Smuzhiyun  *
746*4882a593Smuzhiyun  * Return codes
747*4882a593Smuzhiyun  *    0 - Success
748*4882a593Smuzhiyun  *    1 - DMA memory allocation failed
749*4882a593Smuzhiyun  **/
750*4882a593Smuzhiyun int
lpfc_reg_rpi(struct lpfc_hba * phba,uint16_t vpi,uint32_t did,uint8_t * param,LPFC_MBOXQ_t * pmb,uint16_t rpi)751*4882a593Smuzhiyun lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
752*4882a593Smuzhiyun 	     uint8_t *param, LPFC_MBOXQ_t *pmb, uint16_t rpi)
753*4882a593Smuzhiyun {
754*4882a593Smuzhiyun 	MAILBOX_t *mb = &pmb->u.mb;
755*4882a593Smuzhiyun 	uint8_t *sparam;
756*4882a593Smuzhiyun 	struct lpfc_dmabuf *mp;
757*4882a593Smuzhiyun 
758*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
759*4882a593Smuzhiyun 
760*4882a593Smuzhiyun 	mb->un.varRegLogin.rpi = 0;
761*4882a593Smuzhiyun 	if (phba->sli_rev == LPFC_SLI_REV4)
762*4882a593Smuzhiyun 		mb->un.varRegLogin.rpi = phba->sli4_hba.rpi_ids[rpi];
763*4882a593Smuzhiyun 	if (phba->sli_rev >= LPFC_SLI_REV3)
764*4882a593Smuzhiyun 		mb->un.varRegLogin.vpi = phba->vpi_ids[vpi];
765*4882a593Smuzhiyun 	mb->un.varRegLogin.did = did;
766*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
767*4882a593Smuzhiyun 	/* Get a buffer to hold NPorts Service Parameters */
768*4882a593Smuzhiyun 	mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
769*4882a593Smuzhiyun 	if (mp)
770*4882a593Smuzhiyun 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
771*4882a593Smuzhiyun 	if (!mp || !mp->virt) {
772*4882a593Smuzhiyun 		kfree(mp);
773*4882a593Smuzhiyun 		mb->mbxCommand = MBX_REG_LOGIN64;
774*4882a593Smuzhiyun 		/* REG_LOGIN: no buffers */
775*4882a593Smuzhiyun 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
776*4882a593Smuzhiyun 				"0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
777*4882a593Smuzhiyun 				"rpi x%x\n", vpi, did, rpi);
778*4882a593Smuzhiyun 		return 1;
779*4882a593Smuzhiyun 	}
780*4882a593Smuzhiyun 	INIT_LIST_HEAD(&mp->list);
781*4882a593Smuzhiyun 	sparam = mp->virt;
782*4882a593Smuzhiyun 
783*4882a593Smuzhiyun 	/* Copy param's into a new buffer */
784*4882a593Smuzhiyun 	memcpy(sparam, param, sizeof (struct serv_parm));
785*4882a593Smuzhiyun 
786*4882a593Smuzhiyun 	/* save address for completion */
787*4882a593Smuzhiyun 	pmb->ctx_buf = (uint8_t *)mp;
788*4882a593Smuzhiyun 
789*4882a593Smuzhiyun 	mb->mbxCommand = MBX_REG_LOGIN64;
790*4882a593Smuzhiyun 	mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
791*4882a593Smuzhiyun 	mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
792*4882a593Smuzhiyun 	mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
793*4882a593Smuzhiyun 
794*4882a593Smuzhiyun 	return 0;
795*4882a593Smuzhiyun }
796*4882a593Smuzhiyun 
797*4882a593Smuzhiyun /**
798*4882a593Smuzhiyun  * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
799*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
800*4882a593Smuzhiyun  * @vpi: virtual N_Port identifier.
801*4882a593Smuzhiyun  * @rpi: remote port identifier
802*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
803*4882a593Smuzhiyun  *
804*4882a593Smuzhiyun  * The unregistration login mailbox command is used to unregister an N_Port
805*4882a593Smuzhiyun  * or F_Port login. This command frees an RPI context in the HBA. It has the
806*4882a593Smuzhiyun  * effect of performing an implicit N_Port/F_Port logout.
807*4882a593Smuzhiyun  *
808*4882a593Smuzhiyun  * This routine prepares the mailbox command for unregistering remote port
809*4882a593Smuzhiyun  * login.
810*4882a593Smuzhiyun  *
811*4882a593Smuzhiyun  * For SLI4 ports, the rpi passed to this function must be the physical
812*4882a593Smuzhiyun  * rpi value, not the logical index.
813*4882a593Smuzhiyun  **/
814*4882a593Smuzhiyun void
lpfc_unreg_login(struct lpfc_hba * phba,uint16_t vpi,uint32_t rpi,LPFC_MBOXQ_t * pmb)815*4882a593Smuzhiyun lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
816*4882a593Smuzhiyun 		 LPFC_MBOXQ_t * pmb)
817*4882a593Smuzhiyun {
818*4882a593Smuzhiyun 	MAILBOX_t *mb;
819*4882a593Smuzhiyun 
820*4882a593Smuzhiyun 	mb = &pmb->u.mb;
821*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
822*4882a593Smuzhiyun 
823*4882a593Smuzhiyun 	mb->un.varUnregLogin.rpi = rpi;
824*4882a593Smuzhiyun 	mb->un.varUnregLogin.rsvd1 = 0;
825*4882a593Smuzhiyun 	if (phba->sli_rev >= LPFC_SLI_REV3)
826*4882a593Smuzhiyun 		mb->un.varUnregLogin.vpi = phba->vpi_ids[vpi];
827*4882a593Smuzhiyun 
828*4882a593Smuzhiyun 	mb->mbxCommand = MBX_UNREG_LOGIN;
829*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
830*4882a593Smuzhiyun 
831*4882a593Smuzhiyun 	return;
832*4882a593Smuzhiyun }
833*4882a593Smuzhiyun 
834*4882a593Smuzhiyun /**
835*4882a593Smuzhiyun  * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA.
836*4882a593Smuzhiyun  * @vport: pointer to a vport object.
837*4882a593Smuzhiyun  *
838*4882a593Smuzhiyun  * This routine sends mailbox command to unregister all active RPIs for
839*4882a593Smuzhiyun  * a vport.
840*4882a593Smuzhiyun  **/
841*4882a593Smuzhiyun void
lpfc_sli4_unreg_all_rpis(struct lpfc_vport * vport)842*4882a593Smuzhiyun lpfc_sli4_unreg_all_rpis(struct lpfc_vport *vport)
843*4882a593Smuzhiyun {
844*4882a593Smuzhiyun 	struct lpfc_hba  *phba  = vport->phba;
845*4882a593Smuzhiyun 	LPFC_MBOXQ_t     *mbox;
846*4882a593Smuzhiyun 	int rc;
847*4882a593Smuzhiyun 
848*4882a593Smuzhiyun 	mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
849*4882a593Smuzhiyun 	if (mbox) {
850*4882a593Smuzhiyun 		/*
851*4882a593Smuzhiyun 		 * For SLI4 functions, the rpi field is overloaded for
852*4882a593Smuzhiyun 		 * the vport context unreg all.  This routine passes
853*4882a593Smuzhiyun 		 * 0 for the rpi field in lpfc_unreg_login for compatibility
854*4882a593Smuzhiyun 		 * with SLI3 and then overrides the rpi field with the
855*4882a593Smuzhiyun 		 * expected value for SLI4.
856*4882a593Smuzhiyun 		 */
857*4882a593Smuzhiyun 		lpfc_unreg_login(phba, vport->vpi, phba->vpi_ids[vport->vpi],
858*4882a593Smuzhiyun 				 mbox);
859*4882a593Smuzhiyun 		mbox->u.mb.un.varUnregLogin.rsvd1 = 0x4000;
860*4882a593Smuzhiyun 		mbox->vport = vport;
861*4882a593Smuzhiyun 		mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
862*4882a593Smuzhiyun 		mbox->ctx_ndlp = NULL;
863*4882a593Smuzhiyun 		rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
864*4882a593Smuzhiyun 		if (rc == MBX_NOT_FINISHED)
865*4882a593Smuzhiyun 			mempool_free(mbox, phba->mbox_mem_pool);
866*4882a593Smuzhiyun 	}
867*4882a593Smuzhiyun }
868*4882a593Smuzhiyun 
869*4882a593Smuzhiyun /**
870*4882a593Smuzhiyun  * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
871*4882a593Smuzhiyun  * @vport: pointer to a vport object.
872*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
873*4882a593Smuzhiyun  *
874*4882a593Smuzhiyun  * The registration vport identifier mailbox command is used to activate a
875*4882a593Smuzhiyun  * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
876*4882a593Smuzhiyun  * N_Port_ID against the information in the selected virtual N_Port context
877*4882a593Smuzhiyun  * block and marks it active to allow normal processing of IOCB commands and
878*4882a593Smuzhiyun  * received unsolicited exchanges.
879*4882a593Smuzhiyun  *
880*4882a593Smuzhiyun  * This routine prepares the mailbox command for registering a virtual N_Port.
881*4882a593Smuzhiyun  **/
882*4882a593Smuzhiyun void
lpfc_reg_vpi(struct lpfc_vport * vport,LPFC_MBOXQ_t * pmb)883*4882a593Smuzhiyun lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
884*4882a593Smuzhiyun {
885*4882a593Smuzhiyun 	MAILBOX_t *mb = &pmb->u.mb;
886*4882a593Smuzhiyun 	struct lpfc_hba *phba = vport->phba;
887*4882a593Smuzhiyun 
888*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
889*4882a593Smuzhiyun 	/*
890*4882a593Smuzhiyun 	 * Set the re-reg VPI bit for f/w to update the MAC address.
891*4882a593Smuzhiyun 	 */
892*4882a593Smuzhiyun 	if ((phba->sli_rev == LPFC_SLI_REV4) &&
893*4882a593Smuzhiyun 		!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI))
894*4882a593Smuzhiyun 		mb->un.varRegVpi.upd = 1;
895*4882a593Smuzhiyun 
896*4882a593Smuzhiyun 	mb->un.varRegVpi.vpi = phba->vpi_ids[vport->vpi];
897*4882a593Smuzhiyun 	mb->un.varRegVpi.sid = vport->fc_myDID;
898*4882a593Smuzhiyun 	if (phba->sli_rev == LPFC_SLI_REV4)
899*4882a593Smuzhiyun 		mb->un.varRegVpi.vfi = phba->sli4_hba.vfi_ids[vport->vfi];
900*4882a593Smuzhiyun 	else
901*4882a593Smuzhiyun 		mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
902*4882a593Smuzhiyun 	memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname,
903*4882a593Smuzhiyun 	       sizeof(struct lpfc_name));
904*4882a593Smuzhiyun 	mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]);
905*4882a593Smuzhiyun 	mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]);
906*4882a593Smuzhiyun 
907*4882a593Smuzhiyun 	mb->mbxCommand = MBX_REG_VPI;
908*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
909*4882a593Smuzhiyun 	return;
910*4882a593Smuzhiyun 
911*4882a593Smuzhiyun }
912*4882a593Smuzhiyun 
913*4882a593Smuzhiyun /**
914*4882a593Smuzhiyun  * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
915*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
916*4882a593Smuzhiyun  * @vpi: virtual N_Port identifier.
917*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
918*4882a593Smuzhiyun  *
919*4882a593Smuzhiyun  * The unregistration vport identifier mailbox command is used to inactivate
920*4882a593Smuzhiyun  * a virtual N_Port. The driver must have logged out and unregistered all
921*4882a593Smuzhiyun  * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
922*4882a593Smuzhiyun  * unregisters any default RPIs associated with the specified vpi, aborting
923*4882a593Smuzhiyun  * any active exchanges. The HBA will post the mailbox response after making
924*4882a593Smuzhiyun  * the virtual N_Port inactive.
925*4882a593Smuzhiyun  *
926*4882a593Smuzhiyun  * This routine prepares the mailbox command for unregistering a virtual
927*4882a593Smuzhiyun  * N_Port.
928*4882a593Smuzhiyun  **/
929*4882a593Smuzhiyun void
lpfc_unreg_vpi(struct lpfc_hba * phba,uint16_t vpi,LPFC_MBOXQ_t * pmb)930*4882a593Smuzhiyun lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
931*4882a593Smuzhiyun {
932*4882a593Smuzhiyun 	MAILBOX_t *mb = &pmb->u.mb;
933*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
934*4882a593Smuzhiyun 
935*4882a593Smuzhiyun 	if (phba->sli_rev == LPFC_SLI_REV3)
936*4882a593Smuzhiyun 		mb->un.varUnregVpi.vpi = phba->vpi_ids[vpi];
937*4882a593Smuzhiyun 	else if (phba->sli_rev >= LPFC_SLI_REV4)
938*4882a593Smuzhiyun 		mb->un.varUnregVpi.sli4_vpi = phba->vpi_ids[vpi];
939*4882a593Smuzhiyun 
940*4882a593Smuzhiyun 	mb->mbxCommand = MBX_UNREG_VPI;
941*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
942*4882a593Smuzhiyun 	return;
943*4882a593Smuzhiyun 
944*4882a593Smuzhiyun }
945*4882a593Smuzhiyun 
946*4882a593Smuzhiyun /**
947*4882a593Smuzhiyun  * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
948*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
949*4882a593Smuzhiyun  *
950*4882a593Smuzhiyun  * This routine sets up and initializes the IOCB rings in the Port Control
951*4882a593Smuzhiyun  * Block (PCB).
952*4882a593Smuzhiyun  **/
953*4882a593Smuzhiyun static void
lpfc_config_pcb_setup(struct lpfc_hba * phba)954*4882a593Smuzhiyun lpfc_config_pcb_setup(struct lpfc_hba * phba)
955*4882a593Smuzhiyun {
956*4882a593Smuzhiyun 	struct lpfc_sli *psli = &phba->sli;
957*4882a593Smuzhiyun 	struct lpfc_sli_ring *pring;
958*4882a593Smuzhiyun 	PCB_t *pcbp = phba->pcb;
959*4882a593Smuzhiyun 	dma_addr_t pdma_addr;
960*4882a593Smuzhiyun 	uint32_t offset;
961*4882a593Smuzhiyun 	uint32_t iocbCnt = 0;
962*4882a593Smuzhiyun 	int i;
963*4882a593Smuzhiyun 
964*4882a593Smuzhiyun 	pcbp->maxRing = (psli->num_rings - 1);
965*4882a593Smuzhiyun 
966*4882a593Smuzhiyun 	for (i = 0; i < psli->num_rings; i++) {
967*4882a593Smuzhiyun 		pring = &psli->sli3_ring[i];
968*4882a593Smuzhiyun 
969*4882a593Smuzhiyun 		pring->sli.sli3.sizeCiocb =
970*4882a593Smuzhiyun 			phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE :
971*4882a593Smuzhiyun 							SLI2_IOCB_CMD_SIZE;
972*4882a593Smuzhiyun 		pring->sli.sli3.sizeRiocb =
973*4882a593Smuzhiyun 			phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE :
974*4882a593Smuzhiyun 							SLI2_IOCB_RSP_SIZE;
975*4882a593Smuzhiyun 		/* A ring MUST have both cmd and rsp entries defined to be
976*4882a593Smuzhiyun 		   valid */
977*4882a593Smuzhiyun 		if ((pring->sli.sli3.numCiocb == 0) ||
978*4882a593Smuzhiyun 			(pring->sli.sli3.numRiocb == 0)) {
979*4882a593Smuzhiyun 			pcbp->rdsc[i].cmdEntries = 0;
980*4882a593Smuzhiyun 			pcbp->rdsc[i].rspEntries = 0;
981*4882a593Smuzhiyun 			pcbp->rdsc[i].cmdAddrHigh = 0;
982*4882a593Smuzhiyun 			pcbp->rdsc[i].rspAddrHigh = 0;
983*4882a593Smuzhiyun 			pcbp->rdsc[i].cmdAddrLow = 0;
984*4882a593Smuzhiyun 			pcbp->rdsc[i].rspAddrLow = 0;
985*4882a593Smuzhiyun 			pring->sli.sli3.cmdringaddr = NULL;
986*4882a593Smuzhiyun 			pring->sli.sli3.rspringaddr = NULL;
987*4882a593Smuzhiyun 			continue;
988*4882a593Smuzhiyun 		}
989*4882a593Smuzhiyun 		/* Command ring setup for ring */
990*4882a593Smuzhiyun 		pring->sli.sli3.cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
991*4882a593Smuzhiyun 		pcbp->rdsc[i].cmdEntries = pring->sli.sli3.numCiocb;
992*4882a593Smuzhiyun 
993*4882a593Smuzhiyun 		offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
994*4882a593Smuzhiyun 			 (uint8_t *) phba->slim2p.virt;
995*4882a593Smuzhiyun 		pdma_addr = phba->slim2p.phys + offset;
996*4882a593Smuzhiyun 		pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
997*4882a593Smuzhiyun 		pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
998*4882a593Smuzhiyun 		iocbCnt += pring->sli.sli3.numCiocb;
999*4882a593Smuzhiyun 
1000*4882a593Smuzhiyun 		/* Response ring setup for ring */
1001*4882a593Smuzhiyun 		pring->sli.sli3.rspringaddr = (void *) &phba->IOCBs[iocbCnt];
1002*4882a593Smuzhiyun 
1003*4882a593Smuzhiyun 		pcbp->rdsc[i].rspEntries = pring->sli.sli3.numRiocb;
1004*4882a593Smuzhiyun 		offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
1005*4882a593Smuzhiyun 			 (uint8_t *)phba->slim2p.virt;
1006*4882a593Smuzhiyun 		pdma_addr = phba->slim2p.phys + offset;
1007*4882a593Smuzhiyun 		pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
1008*4882a593Smuzhiyun 		pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
1009*4882a593Smuzhiyun 		iocbCnt += pring->sli.sli3.numRiocb;
1010*4882a593Smuzhiyun 	}
1011*4882a593Smuzhiyun }
1012*4882a593Smuzhiyun 
1013*4882a593Smuzhiyun /**
1014*4882a593Smuzhiyun  * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
1015*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1016*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
1017*4882a593Smuzhiyun  *
1018*4882a593Smuzhiyun  * The read revision mailbox command is used to read the revision levels of
1019*4882a593Smuzhiyun  * the HBA components. These components include hardware units, resident
1020*4882a593Smuzhiyun  * firmware, and available firmware. HBAs that supports SLI-3 mode of
1021*4882a593Smuzhiyun  * operation provide different response information depending on the version
1022*4882a593Smuzhiyun  * requested by the driver.
1023*4882a593Smuzhiyun  *
1024*4882a593Smuzhiyun  * This routine prepares the mailbox command for reading HBA revision
1025*4882a593Smuzhiyun  * information.
1026*4882a593Smuzhiyun  **/
1027*4882a593Smuzhiyun void
lpfc_read_rev(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)1028*4882a593Smuzhiyun lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1029*4882a593Smuzhiyun {
1030*4882a593Smuzhiyun 	MAILBOX_t *mb = &pmb->u.mb;
1031*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1032*4882a593Smuzhiyun 	mb->un.varRdRev.cv = 1;
1033*4882a593Smuzhiyun 	mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
1034*4882a593Smuzhiyun 	mb->mbxCommand = MBX_READ_REV;
1035*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
1036*4882a593Smuzhiyun 	return;
1037*4882a593Smuzhiyun }
1038*4882a593Smuzhiyun 
1039*4882a593Smuzhiyun void
lpfc_sli4_swap_str(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)1040*4882a593Smuzhiyun lpfc_sli4_swap_str(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1041*4882a593Smuzhiyun {
1042*4882a593Smuzhiyun 	MAILBOX_t *mb = &pmb->u.mb;
1043*4882a593Smuzhiyun 	struct lpfc_mqe *mqe;
1044*4882a593Smuzhiyun 
1045*4882a593Smuzhiyun 	switch (mb->mbxCommand) {
1046*4882a593Smuzhiyun 	case  MBX_READ_REV:
1047*4882a593Smuzhiyun 		 mqe = &pmb->u.mqe;
1048*4882a593Smuzhiyun 		lpfc_sli_pcimem_bcopy(mqe->un.read_rev.fw_name,
1049*4882a593Smuzhiyun 				 mqe->un.read_rev.fw_name, 16);
1050*4882a593Smuzhiyun 		lpfc_sli_pcimem_bcopy(mqe->un.read_rev.ulp_fw_name,
1051*4882a593Smuzhiyun 				 mqe->un.read_rev.ulp_fw_name, 16);
1052*4882a593Smuzhiyun 		break;
1053*4882a593Smuzhiyun 	default:
1054*4882a593Smuzhiyun 		break;
1055*4882a593Smuzhiyun 	}
1056*4882a593Smuzhiyun 	return;
1057*4882a593Smuzhiyun }
1058*4882a593Smuzhiyun 
1059*4882a593Smuzhiyun /**
1060*4882a593Smuzhiyun  * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
1061*4882a593Smuzhiyun  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1062*4882a593Smuzhiyun  * @hbq_desc: pointer to the HBQ selection profile descriptor.
1063*4882a593Smuzhiyun  *
1064*4882a593Smuzhiyun  * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
1065*4882a593Smuzhiyun  * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
1066*4882a593Smuzhiyun  * the Sequence Length Test using the fields in the Selection Profile 2
1067*4882a593Smuzhiyun  * extension in words 20:31.
1068*4882a593Smuzhiyun  **/
1069*4882a593Smuzhiyun static void
lpfc_build_hbq_profile2(struct config_hbq_var * hbqmb,struct lpfc_hbq_init * hbq_desc)1070*4882a593Smuzhiyun lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
1071*4882a593Smuzhiyun 			struct lpfc_hbq_init  *hbq_desc)
1072*4882a593Smuzhiyun {
1073*4882a593Smuzhiyun 	hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
1074*4882a593Smuzhiyun 	hbqmb->profiles.profile2.maxlen     = hbq_desc->maxlen;
1075*4882a593Smuzhiyun 	hbqmb->profiles.profile2.seqlenoff  = hbq_desc->seqlenoff;
1076*4882a593Smuzhiyun }
1077*4882a593Smuzhiyun 
1078*4882a593Smuzhiyun /**
1079*4882a593Smuzhiyun  * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
1080*4882a593Smuzhiyun  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1081*4882a593Smuzhiyun  * @hbq_desc: pointer to the HBQ selection profile descriptor.
1082*4882a593Smuzhiyun  *
1083*4882a593Smuzhiyun  * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
1084*4882a593Smuzhiyun  * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
1085*4882a593Smuzhiyun  * the Sequence Length Test and Byte Field Test using the fields in the
1086*4882a593Smuzhiyun  * Selection Profile 3 extension in words 20:31.
1087*4882a593Smuzhiyun  **/
1088*4882a593Smuzhiyun static void
lpfc_build_hbq_profile3(struct config_hbq_var * hbqmb,struct lpfc_hbq_init * hbq_desc)1089*4882a593Smuzhiyun lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
1090*4882a593Smuzhiyun 			struct lpfc_hbq_init  *hbq_desc)
1091*4882a593Smuzhiyun {
1092*4882a593Smuzhiyun 	hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
1093*4882a593Smuzhiyun 	hbqmb->profiles.profile3.maxlen     = hbq_desc->maxlen;
1094*4882a593Smuzhiyun 	hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
1095*4882a593Smuzhiyun 	hbqmb->profiles.profile3.seqlenoff  = hbq_desc->seqlenoff;
1096*4882a593Smuzhiyun 	memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
1097*4882a593Smuzhiyun 	       sizeof(hbqmb->profiles.profile3.cmdmatch));
1098*4882a593Smuzhiyun }
1099*4882a593Smuzhiyun 
1100*4882a593Smuzhiyun /**
1101*4882a593Smuzhiyun  * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
1102*4882a593Smuzhiyun  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1103*4882a593Smuzhiyun  * @hbq_desc: pointer to the HBQ selection profile descriptor.
1104*4882a593Smuzhiyun  *
1105*4882a593Smuzhiyun  * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
1106*4882a593Smuzhiyun  * HBA tests the initial frame of an incoming sequence using the frame's
1107*4882a593Smuzhiyun  * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
1108*4882a593Smuzhiyun  * and Byte Field Test using the fields in the Selection Profile 5 extension
1109*4882a593Smuzhiyun  * words 20:31.
1110*4882a593Smuzhiyun  **/
1111*4882a593Smuzhiyun static void
lpfc_build_hbq_profile5(struct config_hbq_var * hbqmb,struct lpfc_hbq_init * hbq_desc)1112*4882a593Smuzhiyun lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
1113*4882a593Smuzhiyun 			struct lpfc_hbq_init  *hbq_desc)
1114*4882a593Smuzhiyun {
1115*4882a593Smuzhiyun 	hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
1116*4882a593Smuzhiyun 	hbqmb->profiles.profile5.maxlen     = hbq_desc->maxlen;
1117*4882a593Smuzhiyun 	hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
1118*4882a593Smuzhiyun 	hbqmb->profiles.profile5.seqlenoff  = hbq_desc->seqlenoff;
1119*4882a593Smuzhiyun 	memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
1120*4882a593Smuzhiyun 	       sizeof(hbqmb->profiles.profile5.cmdmatch));
1121*4882a593Smuzhiyun }
1122*4882a593Smuzhiyun 
1123*4882a593Smuzhiyun /**
1124*4882a593Smuzhiyun  * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
1125*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1126*4882a593Smuzhiyun  * @id: HBQ identifier.
1127*4882a593Smuzhiyun  * @hbq_desc: pointer to the HBA descriptor data structure.
1128*4882a593Smuzhiyun  * @hbq_entry_index: index of the HBQ entry data structures.
1129*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
1130*4882a593Smuzhiyun  *
1131*4882a593Smuzhiyun  * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
1132*4882a593Smuzhiyun  * an HBQ. The configuration binds events that require buffers to a particular
1133*4882a593Smuzhiyun  * ring and HBQ based on a selection profile.
1134*4882a593Smuzhiyun  *
1135*4882a593Smuzhiyun  * This routine prepares the mailbox command for configuring an HBQ.
1136*4882a593Smuzhiyun  **/
1137*4882a593Smuzhiyun void
lpfc_config_hbq(struct lpfc_hba * phba,uint32_t id,struct lpfc_hbq_init * hbq_desc,uint32_t hbq_entry_index,LPFC_MBOXQ_t * pmb)1138*4882a593Smuzhiyun lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
1139*4882a593Smuzhiyun 		 struct lpfc_hbq_init *hbq_desc,
1140*4882a593Smuzhiyun 		uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
1141*4882a593Smuzhiyun {
1142*4882a593Smuzhiyun 	int i;
1143*4882a593Smuzhiyun 	MAILBOX_t *mb = &pmb->u.mb;
1144*4882a593Smuzhiyun 	struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
1145*4882a593Smuzhiyun 
1146*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1147*4882a593Smuzhiyun 	hbqmb->hbqId = id;
1148*4882a593Smuzhiyun 	hbqmb->entry_count = hbq_desc->entry_count;   /* # entries in HBQ */
1149*4882a593Smuzhiyun 	hbqmb->recvNotify = hbq_desc->rn;             /* Receive
1150*4882a593Smuzhiyun 						       * Notification */
1151*4882a593Smuzhiyun 	hbqmb->numMask    = hbq_desc->mask_count;     /* # R_CTL/TYPE masks
1152*4882a593Smuzhiyun 						       * # in words 0-19 */
1153*4882a593Smuzhiyun 	hbqmb->profile    = hbq_desc->profile;	      /* Selection profile:
1154*4882a593Smuzhiyun 						       * 0 = all,
1155*4882a593Smuzhiyun 						       * 7 = logentry */
1156*4882a593Smuzhiyun 	hbqmb->ringMask   = hbq_desc->ring_mask;      /* Binds HBQ to a ring
1157*4882a593Smuzhiyun 						       * e.g. Ring0=b0001,
1158*4882a593Smuzhiyun 						       * ring2=b0100 */
1159*4882a593Smuzhiyun 	hbqmb->headerLen  = hbq_desc->headerLen;      /* 0 if not profile 4
1160*4882a593Smuzhiyun 						       * or 5 */
1161*4882a593Smuzhiyun 	hbqmb->logEntry   = hbq_desc->logEntry;       /* Set to 1 if this
1162*4882a593Smuzhiyun 						       * HBQ will be used
1163*4882a593Smuzhiyun 						       * for LogEntry
1164*4882a593Smuzhiyun 						       * buffers */
1165*4882a593Smuzhiyun 	hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
1166*4882a593Smuzhiyun 		hbq_entry_index * sizeof(struct lpfc_hbq_entry);
1167*4882a593Smuzhiyun 	hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
1168*4882a593Smuzhiyun 
1169*4882a593Smuzhiyun 	mb->mbxCommand = MBX_CONFIG_HBQ;
1170*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
1171*4882a593Smuzhiyun 
1172*4882a593Smuzhiyun 				/* Copy info for profiles 2,3,5. Other
1173*4882a593Smuzhiyun 				 * profiles this area is reserved
1174*4882a593Smuzhiyun 				 */
1175*4882a593Smuzhiyun 	if (hbq_desc->profile == 2)
1176*4882a593Smuzhiyun 		lpfc_build_hbq_profile2(hbqmb, hbq_desc);
1177*4882a593Smuzhiyun 	else if (hbq_desc->profile == 3)
1178*4882a593Smuzhiyun 		lpfc_build_hbq_profile3(hbqmb, hbq_desc);
1179*4882a593Smuzhiyun 	else if (hbq_desc->profile == 5)
1180*4882a593Smuzhiyun 		lpfc_build_hbq_profile5(hbqmb, hbq_desc);
1181*4882a593Smuzhiyun 
1182*4882a593Smuzhiyun 	/* Return if no rctl / type masks for this HBQ */
1183*4882a593Smuzhiyun 	if (!hbq_desc->mask_count)
1184*4882a593Smuzhiyun 		return;
1185*4882a593Smuzhiyun 
1186*4882a593Smuzhiyun 	/* Otherwise we setup specific rctl / type masks for this HBQ */
1187*4882a593Smuzhiyun 	for (i = 0; i < hbq_desc->mask_count; i++) {
1188*4882a593Smuzhiyun 		hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
1189*4882a593Smuzhiyun 		hbqmb->hbqMasks[i].tmask  = hbq_desc->hbqMasks[i].tmask;
1190*4882a593Smuzhiyun 		hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
1191*4882a593Smuzhiyun 		hbqmb->hbqMasks[i].rctlmask  = hbq_desc->hbqMasks[i].rctlmask;
1192*4882a593Smuzhiyun 	}
1193*4882a593Smuzhiyun 
1194*4882a593Smuzhiyun 	return;
1195*4882a593Smuzhiyun }
1196*4882a593Smuzhiyun 
1197*4882a593Smuzhiyun /**
1198*4882a593Smuzhiyun  * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
1199*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1200*4882a593Smuzhiyun  * @ring: ring number/index
1201*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
1202*4882a593Smuzhiyun  *
1203*4882a593Smuzhiyun  * The configure ring mailbox command is used to configure an IOCB ring. This
1204*4882a593Smuzhiyun  * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1205*4882a593Smuzhiyun  * ring. This is used to map incoming sequences to a particular ring whose
1206*4882a593Smuzhiyun  * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1207*4882a593Smuzhiyun  * attempt to configure a ring whose number is greater than the number
1208*4882a593Smuzhiyun  * specified in the Port Control Block (PCB). It is an error to issue the
1209*4882a593Smuzhiyun  * configure ring command more than once with the same ring number. The HBA
1210*4882a593Smuzhiyun  * returns an error if the driver attempts this.
1211*4882a593Smuzhiyun  *
1212*4882a593Smuzhiyun  * This routine prepares the mailbox command for configuring IOCB ring.
1213*4882a593Smuzhiyun  **/
1214*4882a593Smuzhiyun void
lpfc_config_ring(struct lpfc_hba * phba,int ring,LPFC_MBOXQ_t * pmb)1215*4882a593Smuzhiyun lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
1216*4882a593Smuzhiyun {
1217*4882a593Smuzhiyun 	int i;
1218*4882a593Smuzhiyun 	MAILBOX_t *mb = &pmb->u.mb;
1219*4882a593Smuzhiyun 	struct lpfc_sli *psli;
1220*4882a593Smuzhiyun 	struct lpfc_sli_ring *pring;
1221*4882a593Smuzhiyun 
1222*4882a593Smuzhiyun 	memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1223*4882a593Smuzhiyun 
1224*4882a593Smuzhiyun 	mb->un.varCfgRing.ring = ring;
1225*4882a593Smuzhiyun 	mb->un.varCfgRing.maxOrigXchg = 0;
1226*4882a593Smuzhiyun 	mb->un.varCfgRing.maxRespXchg = 0;
1227*4882a593Smuzhiyun 	mb->un.varCfgRing.recvNotify = 1;
1228*4882a593Smuzhiyun 
1229*4882a593Smuzhiyun 	psli = &phba->sli;
1230*4882a593Smuzhiyun 	pring = &psli->sli3_ring[ring];
1231*4882a593Smuzhiyun 	mb->un.varCfgRing.numMask = pring->num_mask;
1232*4882a593Smuzhiyun 	mb->mbxCommand = MBX_CONFIG_RING;
1233*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
1234*4882a593Smuzhiyun 
1235*4882a593Smuzhiyun 	/* Is this ring configured for a specific profile */
1236*4882a593Smuzhiyun 	if (pring->prt[0].profile) {
1237*4882a593Smuzhiyun 		mb->un.varCfgRing.profile = pring->prt[0].profile;
1238*4882a593Smuzhiyun 		return;
1239*4882a593Smuzhiyun 	}
1240*4882a593Smuzhiyun 
1241*4882a593Smuzhiyun 	/* Otherwise we setup specific rctl / type masks for this ring */
1242*4882a593Smuzhiyun 	for (i = 0; i < pring->num_mask; i++) {
1243*4882a593Smuzhiyun 		mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
1244*4882a593Smuzhiyun 		if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ)
1245*4882a593Smuzhiyun 			mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
1246*4882a593Smuzhiyun 		else
1247*4882a593Smuzhiyun 			mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
1248*4882a593Smuzhiyun 		mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
1249*4882a593Smuzhiyun 		mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
1250*4882a593Smuzhiyun 	}
1251*4882a593Smuzhiyun 
1252*4882a593Smuzhiyun 	return;
1253*4882a593Smuzhiyun }
1254*4882a593Smuzhiyun 
1255*4882a593Smuzhiyun /**
1256*4882a593Smuzhiyun  * lpfc_config_port - Prepare a mailbox command for configuring port
1257*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1258*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
1259*4882a593Smuzhiyun  *
1260*4882a593Smuzhiyun  * The configure port mailbox command is used to identify the Port Control
1261*4882a593Smuzhiyun  * Block (PCB) in the driver memory. After this command is issued, the
1262*4882a593Smuzhiyun  * driver must not access the mailbox in the HBA without first resetting
1263*4882a593Smuzhiyun  * the HBA. The HBA may copy the PCB information to internal storage for
1264*4882a593Smuzhiyun  * subsequent use; the driver can not change the PCB information unless it
1265*4882a593Smuzhiyun  * resets the HBA.
1266*4882a593Smuzhiyun  *
1267*4882a593Smuzhiyun  * This routine prepares the mailbox command for configuring port.
1268*4882a593Smuzhiyun  **/
1269*4882a593Smuzhiyun void
lpfc_config_port(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)1270*4882a593Smuzhiyun lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1271*4882a593Smuzhiyun {
1272*4882a593Smuzhiyun 	MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
1273*4882a593Smuzhiyun 	MAILBOX_t *mb = &pmb->u.mb;
1274*4882a593Smuzhiyun 	dma_addr_t pdma_addr;
1275*4882a593Smuzhiyun 	uint32_t bar_low, bar_high;
1276*4882a593Smuzhiyun 	size_t offset;
1277*4882a593Smuzhiyun 	struct lpfc_hgp hgp;
1278*4882a593Smuzhiyun 	int i;
1279*4882a593Smuzhiyun 	uint32_t pgp_offset;
1280*4882a593Smuzhiyun 
1281*4882a593Smuzhiyun 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1282*4882a593Smuzhiyun 	mb->mbxCommand = MBX_CONFIG_PORT;
1283*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
1284*4882a593Smuzhiyun 
1285*4882a593Smuzhiyun 	mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
1286*4882a593Smuzhiyun 
1287*4882a593Smuzhiyun 	offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
1288*4882a593Smuzhiyun 	pdma_addr = phba->slim2p.phys + offset;
1289*4882a593Smuzhiyun 	mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
1290*4882a593Smuzhiyun 	mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
1291*4882a593Smuzhiyun 
1292*4882a593Smuzhiyun 	/* Always Host Group Pointer is in SLIM */
1293*4882a593Smuzhiyun 	mb->un.varCfgPort.hps = 1;
1294*4882a593Smuzhiyun 
1295*4882a593Smuzhiyun 	/* If HBA supports SLI=3 ask for it */
1296*4882a593Smuzhiyun 
1297*4882a593Smuzhiyun 	if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
1298*4882a593Smuzhiyun 		if (phba->cfg_enable_bg)
1299*4882a593Smuzhiyun 			mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
1300*4882a593Smuzhiyun 		mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
1301*4882a593Smuzhiyun 		mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
1302*4882a593Smuzhiyun 		mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
1303*4882a593Smuzhiyun 		if (phba->max_vpi && phba->cfg_enable_npiv &&
1304*4882a593Smuzhiyun 		    phba->vpd.sli3Feat.cmv) {
1305*4882a593Smuzhiyun 			mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI;
1306*4882a593Smuzhiyun 			mb->un.varCfgPort.cmv = 1;
1307*4882a593Smuzhiyun 		} else
1308*4882a593Smuzhiyun 			mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
1309*4882a593Smuzhiyun 	} else
1310*4882a593Smuzhiyun 		phba->sli_rev = LPFC_SLI_REV2;
1311*4882a593Smuzhiyun 	mb->un.varCfgPort.sli_mode = phba->sli_rev;
1312*4882a593Smuzhiyun 
1313*4882a593Smuzhiyun 	/* If this is an SLI3 port, configure async status notification. */
1314*4882a593Smuzhiyun 	if (phba->sli_rev == LPFC_SLI_REV3)
1315*4882a593Smuzhiyun 		mb->un.varCfgPort.casabt = 1;
1316*4882a593Smuzhiyun 
1317*4882a593Smuzhiyun 	/* Now setup pcb */
1318*4882a593Smuzhiyun 	phba->pcb->type = TYPE_NATIVE_SLI2;
1319*4882a593Smuzhiyun 	phba->pcb->feature = FEATURE_INITIAL_SLI2;
1320*4882a593Smuzhiyun 
1321*4882a593Smuzhiyun 	/* Setup Mailbox pointers */
1322*4882a593Smuzhiyun 	phba->pcb->mailBoxSize = sizeof(MAILBOX_t) + MAILBOX_EXT_SIZE;
1323*4882a593Smuzhiyun 	offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
1324*4882a593Smuzhiyun 	pdma_addr = phba->slim2p.phys + offset;
1325*4882a593Smuzhiyun 	phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
1326*4882a593Smuzhiyun 	phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
1327*4882a593Smuzhiyun 
1328*4882a593Smuzhiyun 	/*
1329*4882a593Smuzhiyun 	 * Setup Host Group ring pointer.
1330*4882a593Smuzhiyun 	 *
1331*4882a593Smuzhiyun 	 * For efficiency reasons, the ring get/put pointers can be
1332*4882a593Smuzhiyun 	 * placed in adapter memory (SLIM) rather than in host memory.
1333*4882a593Smuzhiyun 	 * This allows firmware to avoid PCI reads/writes when updating
1334*4882a593Smuzhiyun 	 * and checking pointers.
1335*4882a593Smuzhiyun 	 *
1336*4882a593Smuzhiyun 	 * The firmware recognizes the use of SLIM memory by comparing
1337*4882a593Smuzhiyun 	 * the address of the get/put pointers structure with that of
1338*4882a593Smuzhiyun 	 * the SLIM BAR (BAR0).
1339*4882a593Smuzhiyun 	 *
1340*4882a593Smuzhiyun 	 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1341*4882a593Smuzhiyun 	 * (the hardware's view of the base address), not the OS's
1342*4882a593Smuzhiyun 	 * value of pci_resource_start() as the OS value may be a cookie
1343*4882a593Smuzhiyun 	 * for ioremap/iomap.
1344*4882a593Smuzhiyun 	 */
1345*4882a593Smuzhiyun 
1346*4882a593Smuzhiyun 
1347*4882a593Smuzhiyun 	pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
1348*4882a593Smuzhiyun 	pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
1349*4882a593Smuzhiyun 
1350*4882a593Smuzhiyun 	/*
1351*4882a593Smuzhiyun 	 * Set up HGP - Port Memory
1352*4882a593Smuzhiyun 	 *
1353*4882a593Smuzhiyun 	 * The port expects the host get/put pointers to reside in memory
1354*4882a593Smuzhiyun 	 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1355*4882a593Smuzhiyun 	 * area of SLIM.  In SLI-2 mode, there's an additional 16 reserved
1356*4882a593Smuzhiyun 	 * words (0x40 bytes).  This area is not reserved if HBQs are
1357*4882a593Smuzhiyun 	 * configured in SLI-3.
1358*4882a593Smuzhiyun 	 *
1359*4882a593Smuzhiyun 	 * CR0Put    - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1360*4882a593Smuzhiyun 	 * RR0Get                      0xc4              0x84
1361*4882a593Smuzhiyun 	 * CR1Put                      0xc8              0x88
1362*4882a593Smuzhiyun 	 * RR1Get                      0xcc              0x8c
1363*4882a593Smuzhiyun 	 * CR2Put                      0xd0              0x90
1364*4882a593Smuzhiyun 	 * RR2Get                      0xd4              0x94
1365*4882a593Smuzhiyun 	 * CR3Put                      0xd8              0x98
1366*4882a593Smuzhiyun 	 * RR3Get                      0xdc              0x9c
1367*4882a593Smuzhiyun 	 *
1368*4882a593Smuzhiyun 	 * Reserved                    0xa0-0xbf
1369*4882a593Smuzhiyun 	 *    If HBQs configured:
1370*4882a593Smuzhiyun 	 *                         HBQ 0 Put ptr  0xc0
1371*4882a593Smuzhiyun 	 *                         HBQ 1 Put ptr  0xc4
1372*4882a593Smuzhiyun 	 *                         HBQ 2 Put ptr  0xc8
1373*4882a593Smuzhiyun 	 *                         ......
1374*4882a593Smuzhiyun 	 *                         HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1375*4882a593Smuzhiyun 	 *
1376*4882a593Smuzhiyun 	 */
1377*4882a593Smuzhiyun 
1378*4882a593Smuzhiyun 	if (phba->cfg_hostmem_hgp && phba->sli_rev != 3) {
1379*4882a593Smuzhiyun 		phba->host_gp = (struct lpfc_hgp __iomem *)
1380*4882a593Smuzhiyun 				 &phba->mbox->us.s2.host[0];
1381*4882a593Smuzhiyun 		phba->hbq_put = NULL;
1382*4882a593Smuzhiyun 		offset = (uint8_t *)&phba->mbox->us.s2.host -
1383*4882a593Smuzhiyun 			(uint8_t *)phba->slim2p.virt;
1384*4882a593Smuzhiyun 		pdma_addr = phba->slim2p.phys + offset;
1385*4882a593Smuzhiyun 		phba->pcb->hgpAddrHigh = putPaddrHigh(pdma_addr);
1386*4882a593Smuzhiyun 		phba->pcb->hgpAddrLow = putPaddrLow(pdma_addr);
1387*4882a593Smuzhiyun 	} else {
1388*4882a593Smuzhiyun 		/* Always Host Group Pointer is in SLIM */
1389*4882a593Smuzhiyun 		mb->un.varCfgPort.hps = 1;
1390*4882a593Smuzhiyun 
1391*4882a593Smuzhiyun 		if (phba->sli_rev == 3) {
1392*4882a593Smuzhiyun 			phba->host_gp = &mb_slim->us.s3.host[0];
1393*4882a593Smuzhiyun 			phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
1394*4882a593Smuzhiyun 		} else {
1395*4882a593Smuzhiyun 			phba->host_gp = &mb_slim->us.s2.host[0];
1396*4882a593Smuzhiyun 			phba->hbq_put = NULL;
1397*4882a593Smuzhiyun 		}
1398*4882a593Smuzhiyun 
1399*4882a593Smuzhiyun 		/* mask off BAR0's flag bits 0 - 3 */
1400*4882a593Smuzhiyun 		phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
1401*4882a593Smuzhiyun 			(void __iomem *)phba->host_gp -
1402*4882a593Smuzhiyun 			(void __iomem *)phba->MBslimaddr;
1403*4882a593Smuzhiyun 		if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
1404*4882a593Smuzhiyun 			phba->pcb->hgpAddrHigh = bar_high;
1405*4882a593Smuzhiyun 		else
1406*4882a593Smuzhiyun 			phba->pcb->hgpAddrHigh = 0;
1407*4882a593Smuzhiyun 		/* write HGP data to SLIM at the required longword offset */
1408*4882a593Smuzhiyun 		memset(&hgp, 0, sizeof(struct lpfc_hgp));
1409*4882a593Smuzhiyun 
1410*4882a593Smuzhiyun 		for (i = 0; i < phba->sli.num_rings; i++) {
1411*4882a593Smuzhiyun 			lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
1412*4882a593Smuzhiyun 				    sizeof(*phba->host_gp));
1413*4882a593Smuzhiyun 		}
1414*4882a593Smuzhiyun 	}
1415*4882a593Smuzhiyun 
1416*4882a593Smuzhiyun 	/* Setup Port Group offset */
1417*4882a593Smuzhiyun 	if (phba->sli_rev == 3)
1418*4882a593Smuzhiyun 		pgp_offset = offsetof(struct lpfc_sli2_slim,
1419*4882a593Smuzhiyun 				      mbx.us.s3_pgp.port);
1420*4882a593Smuzhiyun 	else
1421*4882a593Smuzhiyun 		pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
1422*4882a593Smuzhiyun 	pdma_addr = phba->slim2p.phys + pgp_offset;
1423*4882a593Smuzhiyun 	phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
1424*4882a593Smuzhiyun 	phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
1425*4882a593Smuzhiyun 
1426*4882a593Smuzhiyun 	/* Use callback routine to setp rings in the pcb */
1427*4882a593Smuzhiyun 	lpfc_config_pcb_setup(phba);
1428*4882a593Smuzhiyun 
1429*4882a593Smuzhiyun 	/* special handling for LC HBAs */
1430*4882a593Smuzhiyun 	if (lpfc_is_LC_HBA(phba->pcidev->device)) {
1431*4882a593Smuzhiyun 		uint32_t hbainit[5];
1432*4882a593Smuzhiyun 
1433*4882a593Smuzhiyun 		lpfc_hba_init(phba, hbainit);
1434*4882a593Smuzhiyun 
1435*4882a593Smuzhiyun 		memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
1436*4882a593Smuzhiyun 	}
1437*4882a593Smuzhiyun 
1438*4882a593Smuzhiyun 	/* Swap PCB if needed */
1439*4882a593Smuzhiyun 	lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
1440*4882a593Smuzhiyun }
1441*4882a593Smuzhiyun 
1442*4882a593Smuzhiyun /**
1443*4882a593Smuzhiyun  * lpfc_kill_board - Prepare a mailbox command for killing board
1444*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1445*4882a593Smuzhiyun  * @pmb: pointer to the driver internal queue element for mailbox command.
1446*4882a593Smuzhiyun  *
1447*4882a593Smuzhiyun  * The kill board mailbox command is used to tell firmware to perform a
1448*4882a593Smuzhiyun  * graceful shutdown of a channel on a specified board to prepare for reset.
1449*4882a593Smuzhiyun  * When the kill board mailbox command is received, the ER3 bit is set to 1
1450*4882a593Smuzhiyun  * in the Host Status register and the ER Attention bit is set to 1 in the
1451*4882a593Smuzhiyun  * Host Attention register of the HBA function that received the kill board
1452*4882a593Smuzhiyun  * command.
1453*4882a593Smuzhiyun  *
1454*4882a593Smuzhiyun  * This routine prepares the mailbox command for killing the board in
1455*4882a593Smuzhiyun  * preparation for a graceful shutdown.
1456*4882a593Smuzhiyun  **/
1457*4882a593Smuzhiyun void
lpfc_kill_board(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)1458*4882a593Smuzhiyun lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1459*4882a593Smuzhiyun {
1460*4882a593Smuzhiyun 	MAILBOX_t *mb = &pmb->u.mb;
1461*4882a593Smuzhiyun 
1462*4882a593Smuzhiyun 	memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1463*4882a593Smuzhiyun 	mb->mbxCommand = MBX_KILL_BOARD;
1464*4882a593Smuzhiyun 	mb->mbxOwner = OWN_HOST;
1465*4882a593Smuzhiyun 	return;
1466*4882a593Smuzhiyun }
1467*4882a593Smuzhiyun 
1468*4882a593Smuzhiyun /**
1469*4882a593Smuzhiyun  * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
1470*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1471*4882a593Smuzhiyun  * @mbq: pointer to the driver internal queue element for mailbox command.
1472*4882a593Smuzhiyun  *
1473*4882a593Smuzhiyun  * Driver maintains a internal mailbox command queue implemented as a linked
1474*4882a593Smuzhiyun  * list. When a mailbox command is issued, it shall be put into the mailbox
1475*4882a593Smuzhiyun  * command queue such that they shall be processed orderly as HBA can process
1476*4882a593Smuzhiyun  * one mailbox command at a time.
1477*4882a593Smuzhiyun  **/
1478*4882a593Smuzhiyun void
lpfc_mbox_put(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbq)1479*4882a593Smuzhiyun lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1480*4882a593Smuzhiyun {
1481*4882a593Smuzhiyun 	struct lpfc_sli *psli;
1482*4882a593Smuzhiyun 
1483*4882a593Smuzhiyun 	psli = &phba->sli;
1484*4882a593Smuzhiyun 
1485*4882a593Smuzhiyun 	list_add_tail(&mbq->list, &psli->mboxq);
1486*4882a593Smuzhiyun 
1487*4882a593Smuzhiyun 	psli->mboxq_cnt++;
1488*4882a593Smuzhiyun 
1489*4882a593Smuzhiyun 	return;
1490*4882a593Smuzhiyun }
1491*4882a593Smuzhiyun 
1492*4882a593Smuzhiyun /**
1493*4882a593Smuzhiyun  * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
1494*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1495*4882a593Smuzhiyun  *
1496*4882a593Smuzhiyun  * Driver maintains a internal mailbox command queue implemented as a linked
1497*4882a593Smuzhiyun  * list. When a mailbox command is issued, it shall be put into the mailbox
1498*4882a593Smuzhiyun  * command queue such that they shall be processed orderly as HBA can process
1499*4882a593Smuzhiyun  * one mailbox command at a time. After HBA finished processing a mailbox
1500*4882a593Smuzhiyun  * command, the driver will remove a pending mailbox command from the head of
1501*4882a593Smuzhiyun  * the mailbox command queue and send to the HBA for processing.
1502*4882a593Smuzhiyun  *
1503*4882a593Smuzhiyun  * Return codes
1504*4882a593Smuzhiyun  *    pointer to the driver internal queue element for mailbox command.
1505*4882a593Smuzhiyun  **/
1506*4882a593Smuzhiyun LPFC_MBOXQ_t *
lpfc_mbox_get(struct lpfc_hba * phba)1507*4882a593Smuzhiyun lpfc_mbox_get(struct lpfc_hba * phba)
1508*4882a593Smuzhiyun {
1509*4882a593Smuzhiyun 	LPFC_MBOXQ_t *mbq = NULL;
1510*4882a593Smuzhiyun 	struct lpfc_sli *psli = &phba->sli;
1511*4882a593Smuzhiyun 
1512*4882a593Smuzhiyun 	list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
1513*4882a593Smuzhiyun 	if (mbq)
1514*4882a593Smuzhiyun 		psli->mboxq_cnt--;
1515*4882a593Smuzhiyun 
1516*4882a593Smuzhiyun 	return mbq;
1517*4882a593Smuzhiyun }
1518*4882a593Smuzhiyun 
1519*4882a593Smuzhiyun /**
1520*4882a593Smuzhiyun  * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
1521*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1522*4882a593Smuzhiyun  * @mbq: pointer to the driver internal queue element for mailbox command.
1523*4882a593Smuzhiyun  *
1524*4882a593Smuzhiyun  * This routine put the completed mailbox command into the mailbox command
1525*4882a593Smuzhiyun  * complete list. This is the unlocked version of the routine. The mailbox
1526*4882a593Smuzhiyun  * complete list is used by the driver worker thread to process mailbox
1527*4882a593Smuzhiyun  * complete callback functions outside the driver interrupt handler.
1528*4882a593Smuzhiyun  **/
1529*4882a593Smuzhiyun void
__lpfc_mbox_cmpl_put(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbq)1530*4882a593Smuzhiyun __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
1531*4882a593Smuzhiyun {
1532*4882a593Smuzhiyun 	list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
1533*4882a593Smuzhiyun }
1534*4882a593Smuzhiyun 
1535*4882a593Smuzhiyun /**
1536*4882a593Smuzhiyun  * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
1537*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1538*4882a593Smuzhiyun  * @mbq: pointer to the driver internal queue element for mailbox command.
1539*4882a593Smuzhiyun  *
1540*4882a593Smuzhiyun  * This routine put the completed mailbox command into the mailbox command
1541*4882a593Smuzhiyun  * complete list. This is the locked version of the routine. The mailbox
1542*4882a593Smuzhiyun  * complete list is used by the driver worker thread to process mailbox
1543*4882a593Smuzhiyun  * complete callback functions outside the driver interrupt handler.
1544*4882a593Smuzhiyun  **/
1545*4882a593Smuzhiyun void
lpfc_mbox_cmpl_put(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbq)1546*4882a593Smuzhiyun lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
1547*4882a593Smuzhiyun {
1548*4882a593Smuzhiyun 	unsigned long iflag;
1549*4882a593Smuzhiyun 
1550*4882a593Smuzhiyun 	/* This function expects to be called from interrupt context */
1551*4882a593Smuzhiyun 	spin_lock_irqsave(&phba->hbalock, iflag);
1552*4882a593Smuzhiyun 	__lpfc_mbox_cmpl_put(phba, mbq);
1553*4882a593Smuzhiyun 	spin_unlock_irqrestore(&phba->hbalock, iflag);
1554*4882a593Smuzhiyun 	return;
1555*4882a593Smuzhiyun }
1556*4882a593Smuzhiyun 
1557*4882a593Smuzhiyun /**
1558*4882a593Smuzhiyun  * lpfc_mbox_cmd_check - Check the validality of a mailbox command
1559*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1560*4882a593Smuzhiyun  * @mboxq: pointer to the driver internal queue element for mailbox command.
1561*4882a593Smuzhiyun  *
1562*4882a593Smuzhiyun  * This routine is to check whether a mailbox command is valid to be issued.
1563*4882a593Smuzhiyun  * This check will be performed by both the mailbox issue API when a client
1564*4882a593Smuzhiyun  * is to issue a mailbox command to the mailbox transport.
1565*4882a593Smuzhiyun  *
1566*4882a593Smuzhiyun  * Return 0 - pass the check, -ENODEV - fail the check
1567*4882a593Smuzhiyun  **/
1568*4882a593Smuzhiyun int
lpfc_mbox_cmd_check(struct lpfc_hba * phba,LPFC_MBOXQ_t * mboxq)1569*4882a593Smuzhiyun lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1570*4882a593Smuzhiyun {
1571*4882a593Smuzhiyun 	/* Mailbox command that have a completion handler must also have a
1572*4882a593Smuzhiyun 	 * vport specified.
1573*4882a593Smuzhiyun 	 */
1574*4882a593Smuzhiyun 	if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
1575*4882a593Smuzhiyun 	    mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
1576*4882a593Smuzhiyun 		if (!mboxq->vport) {
1577*4882a593Smuzhiyun 			lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
1578*4882a593Smuzhiyun 					"1814 Mbox x%x failed, no vport\n",
1579*4882a593Smuzhiyun 					mboxq->u.mb.mbxCommand);
1580*4882a593Smuzhiyun 			dump_stack();
1581*4882a593Smuzhiyun 			return -ENODEV;
1582*4882a593Smuzhiyun 		}
1583*4882a593Smuzhiyun 	}
1584*4882a593Smuzhiyun 	return 0;
1585*4882a593Smuzhiyun }
1586*4882a593Smuzhiyun 
1587*4882a593Smuzhiyun /**
1588*4882a593Smuzhiyun  * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
1589*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1590*4882a593Smuzhiyun  *
1591*4882a593Smuzhiyun  * This routine is to check whether the HBA device is ready for posting a
1592*4882a593Smuzhiyun  * mailbox command. It is used by the mailbox transport API at the time the
1593*4882a593Smuzhiyun  * to post a mailbox command to the device.
1594*4882a593Smuzhiyun  *
1595*4882a593Smuzhiyun  * Return 0 - pass the check, -ENODEV - fail the check
1596*4882a593Smuzhiyun  **/
1597*4882a593Smuzhiyun int
lpfc_mbox_dev_check(struct lpfc_hba * phba)1598*4882a593Smuzhiyun lpfc_mbox_dev_check(struct lpfc_hba *phba)
1599*4882a593Smuzhiyun {
1600*4882a593Smuzhiyun 	/* If the PCI channel is in offline state, do not issue mbox */
1601*4882a593Smuzhiyun 	if (unlikely(pci_channel_offline(phba->pcidev)))
1602*4882a593Smuzhiyun 		return -ENODEV;
1603*4882a593Smuzhiyun 
1604*4882a593Smuzhiyun 	/* If the HBA is in error state, do not issue mbox */
1605*4882a593Smuzhiyun 	if (phba->link_state == LPFC_HBA_ERROR)
1606*4882a593Smuzhiyun 		return -ENODEV;
1607*4882a593Smuzhiyun 
1608*4882a593Smuzhiyun 	return 0;
1609*4882a593Smuzhiyun }
1610*4882a593Smuzhiyun 
1611*4882a593Smuzhiyun /**
1612*4882a593Smuzhiyun  * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
1613*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1614*4882a593Smuzhiyun  * @mboxq: pointer to the driver internal queue element for mailbox command.
1615*4882a593Smuzhiyun  *
1616*4882a593Smuzhiyun  * This routine retrieves the proper timeout value according to the mailbox
1617*4882a593Smuzhiyun  * command code.
1618*4882a593Smuzhiyun  *
1619*4882a593Smuzhiyun  * Return codes
1620*4882a593Smuzhiyun  *    Timeout value to be used for the given mailbox command
1621*4882a593Smuzhiyun  **/
1622*4882a593Smuzhiyun int
lpfc_mbox_tmo_val(struct lpfc_hba * phba,LPFC_MBOXQ_t * mboxq)1623*4882a593Smuzhiyun lpfc_mbox_tmo_val(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1624*4882a593Smuzhiyun {
1625*4882a593Smuzhiyun 	MAILBOX_t *mbox = &mboxq->u.mb;
1626*4882a593Smuzhiyun 	uint8_t subsys, opcode;
1627*4882a593Smuzhiyun 
1628*4882a593Smuzhiyun 	switch (mbox->mbxCommand) {
1629*4882a593Smuzhiyun 	case MBX_WRITE_NV:	/* 0x03 */
1630*4882a593Smuzhiyun 	case MBX_DUMP_MEMORY:	/* 0x17 */
1631*4882a593Smuzhiyun 	case MBX_UPDATE_CFG:	/* 0x1B */
1632*4882a593Smuzhiyun 	case MBX_DOWN_LOAD:	/* 0x1C */
1633*4882a593Smuzhiyun 	case MBX_DEL_LD_ENTRY:	/* 0x1D */
1634*4882a593Smuzhiyun 	case MBX_WRITE_VPARMS:	/* 0x32 */
1635*4882a593Smuzhiyun 	case MBX_LOAD_AREA:	/* 0x81 */
1636*4882a593Smuzhiyun 	case MBX_WRITE_WWN:     /* 0x98 */
1637*4882a593Smuzhiyun 	case MBX_LOAD_EXP_ROM:	/* 0x9C */
1638*4882a593Smuzhiyun 	case MBX_ACCESS_VDATA:	/* 0xA5 */
1639*4882a593Smuzhiyun 		return LPFC_MBOX_TMO_FLASH_CMD;
1640*4882a593Smuzhiyun 	case MBX_SLI4_CONFIG:	/* 0x9b */
1641*4882a593Smuzhiyun 		subsys = lpfc_sli_config_mbox_subsys_get(phba, mboxq);
1642*4882a593Smuzhiyun 		opcode = lpfc_sli_config_mbox_opcode_get(phba, mboxq);
1643*4882a593Smuzhiyun 		if (subsys == LPFC_MBOX_SUBSYSTEM_COMMON) {
1644*4882a593Smuzhiyun 			switch (opcode) {
1645*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_READ_OBJECT:
1646*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_WRITE_OBJECT:
1647*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_READ_OBJECT_LIST:
1648*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_DELETE_OBJECT:
1649*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_GET_PROFILE_LIST:
1650*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_SET_ACT_PROFILE:
1651*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG:
1652*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG:
1653*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG:
1654*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_GET_PROFILE_CAPACITIES:
1655*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_SEND_ACTIVATION:
1656*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_RESET_LICENSES:
1657*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_SET_BOOT_CONFIG:
1658*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_GET_VPD_DATA:
1659*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_SET_PHYSICAL_LINK_CONFIG:
1660*4882a593Smuzhiyun 				return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO;
1661*4882a593Smuzhiyun 			}
1662*4882a593Smuzhiyun 		}
1663*4882a593Smuzhiyun 		if (subsys == LPFC_MBOX_SUBSYSTEM_FCOE) {
1664*4882a593Smuzhiyun 			switch (opcode) {
1665*4882a593Smuzhiyun 			case LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS:
1666*4882a593Smuzhiyun 				return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO;
1667*4882a593Smuzhiyun 			}
1668*4882a593Smuzhiyun 		}
1669*4882a593Smuzhiyun 		return LPFC_MBOX_SLI4_CONFIG_TMO;
1670*4882a593Smuzhiyun 	}
1671*4882a593Smuzhiyun 	return LPFC_MBOX_TMO;
1672*4882a593Smuzhiyun }
1673*4882a593Smuzhiyun 
1674*4882a593Smuzhiyun /**
1675*4882a593Smuzhiyun  * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
1676*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command.
1677*4882a593Smuzhiyun  * @sgentry: sge entry index.
1678*4882a593Smuzhiyun  * @phyaddr: physical address for the sge
1679*4882a593Smuzhiyun  * @length: Length of the sge.
1680*4882a593Smuzhiyun  *
1681*4882a593Smuzhiyun  * This routine sets up an entry in the non-embedded mailbox command at the sge
1682*4882a593Smuzhiyun  * index location.
1683*4882a593Smuzhiyun  **/
1684*4882a593Smuzhiyun void
lpfc_sli4_mbx_sge_set(struct lpfcMboxq * mbox,uint32_t sgentry,dma_addr_t phyaddr,uint32_t length)1685*4882a593Smuzhiyun lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry,
1686*4882a593Smuzhiyun 		      dma_addr_t phyaddr, uint32_t length)
1687*4882a593Smuzhiyun {
1688*4882a593Smuzhiyun 	struct lpfc_mbx_nembed_cmd *nembed_sge;
1689*4882a593Smuzhiyun 
1690*4882a593Smuzhiyun 	nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1691*4882a593Smuzhiyun 				&mbox->u.mqe.un.nembed_cmd;
1692*4882a593Smuzhiyun 	nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr);
1693*4882a593Smuzhiyun 	nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr);
1694*4882a593Smuzhiyun 	nembed_sge->sge[sgentry].length = length;
1695*4882a593Smuzhiyun }
1696*4882a593Smuzhiyun 
1697*4882a593Smuzhiyun /**
1698*4882a593Smuzhiyun  * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
1699*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command.
1700*4882a593Smuzhiyun  * @sgentry: sge entry index.
1701*4882a593Smuzhiyun  * @sge: pointer to lpfc mailbox sge to load into.
1702*4882a593Smuzhiyun  *
1703*4882a593Smuzhiyun  * This routine gets an entry from the non-embedded mailbox command at the sge
1704*4882a593Smuzhiyun  * index location.
1705*4882a593Smuzhiyun  **/
1706*4882a593Smuzhiyun void
lpfc_sli4_mbx_sge_get(struct lpfcMboxq * mbox,uint32_t sgentry,struct lpfc_mbx_sge * sge)1707*4882a593Smuzhiyun lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry,
1708*4882a593Smuzhiyun 		      struct lpfc_mbx_sge *sge)
1709*4882a593Smuzhiyun {
1710*4882a593Smuzhiyun 	struct lpfc_mbx_nembed_cmd *nembed_sge;
1711*4882a593Smuzhiyun 
1712*4882a593Smuzhiyun 	nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1713*4882a593Smuzhiyun 				&mbox->u.mqe.un.nembed_cmd;
1714*4882a593Smuzhiyun 	sge->pa_lo = nembed_sge->sge[sgentry].pa_lo;
1715*4882a593Smuzhiyun 	sge->pa_hi = nembed_sge->sge[sgentry].pa_hi;
1716*4882a593Smuzhiyun 	sge->length = nembed_sge->sge[sgentry].length;
1717*4882a593Smuzhiyun }
1718*4882a593Smuzhiyun 
1719*4882a593Smuzhiyun /**
1720*4882a593Smuzhiyun  * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
1721*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1722*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command.
1723*4882a593Smuzhiyun  *
1724*4882a593Smuzhiyun  * This routine frees SLI4 specific mailbox command for sending IOCTL command.
1725*4882a593Smuzhiyun  **/
1726*4882a593Smuzhiyun void
lpfc_sli4_mbox_cmd_free(struct lpfc_hba * phba,struct lpfcMboxq * mbox)1727*4882a593Smuzhiyun lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1728*4882a593Smuzhiyun {
1729*4882a593Smuzhiyun 	struct lpfc_mbx_sli4_config *sli4_cfg;
1730*4882a593Smuzhiyun 	struct lpfc_mbx_sge sge;
1731*4882a593Smuzhiyun 	dma_addr_t phyaddr;
1732*4882a593Smuzhiyun 	uint32_t sgecount, sgentry;
1733*4882a593Smuzhiyun 
1734*4882a593Smuzhiyun 	sli4_cfg = &mbox->u.mqe.un.sli4_config;
1735*4882a593Smuzhiyun 
1736*4882a593Smuzhiyun 	/* For embedded mbox command, just free the mbox command */
1737*4882a593Smuzhiyun 	if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1738*4882a593Smuzhiyun 		mempool_free(mbox, phba->mbox_mem_pool);
1739*4882a593Smuzhiyun 		return;
1740*4882a593Smuzhiyun 	}
1741*4882a593Smuzhiyun 
1742*4882a593Smuzhiyun 	/* For non-embedded mbox command, we need to free the pages first */
1743*4882a593Smuzhiyun 	sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr);
1744*4882a593Smuzhiyun 	/* There is nothing we can do if there is no sge address array */
1745*4882a593Smuzhiyun 	if (unlikely(!mbox->sge_array)) {
1746*4882a593Smuzhiyun 		mempool_free(mbox, phba->mbox_mem_pool);
1747*4882a593Smuzhiyun 		return;
1748*4882a593Smuzhiyun 	}
1749*4882a593Smuzhiyun 	/* Each non-embedded DMA memory was allocated in the length of a page */
1750*4882a593Smuzhiyun 	for (sgentry = 0; sgentry < sgecount; sgentry++) {
1751*4882a593Smuzhiyun 		lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge);
1752*4882a593Smuzhiyun 		phyaddr = getPaddr(sge.pa_hi, sge.pa_lo);
1753*4882a593Smuzhiyun 		dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
1754*4882a593Smuzhiyun 				  mbox->sge_array->addr[sgentry], phyaddr);
1755*4882a593Smuzhiyun 	}
1756*4882a593Smuzhiyun 	/* Free the sge address array memory */
1757*4882a593Smuzhiyun 	kfree(mbox->sge_array);
1758*4882a593Smuzhiyun 	/* Finally, free the mailbox command itself */
1759*4882a593Smuzhiyun 	mempool_free(mbox, phba->mbox_mem_pool);
1760*4882a593Smuzhiyun }
1761*4882a593Smuzhiyun 
1762*4882a593Smuzhiyun /**
1763*4882a593Smuzhiyun  * lpfc_sli4_config - Initialize the  SLI4 Config Mailbox command
1764*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1765*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command.
1766*4882a593Smuzhiyun  * @subsystem: The sli4 config sub mailbox subsystem.
1767*4882a593Smuzhiyun  * @opcode: The sli4 config sub mailbox command opcode.
1768*4882a593Smuzhiyun  * @length: Length of the sli4 config mailbox command (including sub-header).
1769*4882a593Smuzhiyun  * @emb: True if embedded mbox command should be setup.
1770*4882a593Smuzhiyun  *
1771*4882a593Smuzhiyun  * This routine sets up the header fields of SLI4 specific mailbox command
1772*4882a593Smuzhiyun  * for sending IOCTL command.
1773*4882a593Smuzhiyun  *
1774*4882a593Smuzhiyun  * Return: the actual length of the mbox command allocated (mostly useful
1775*4882a593Smuzhiyun  *         for none embedded mailbox command).
1776*4882a593Smuzhiyun  **/
1777*4882a593Smuzhiyun int
lpfc_sli4_config(struct lpfc_hba * phba,struct lpfcMboxq * mbox,uint8_t subsystem,uint8_t opcode,uint32_t length,bool emb)1778*4882a593Smuzhiyun lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
1779*4882a593Smuzhiyun 		 uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb)
1780*4882a593Smuzhiyun {
1781*4882a593Smuzhiyun 	struct lpfc_mbx_sli4_config *sli4_config;
1782*4882a593Smuzhiyun 	union lpfc_sli4_cfg_shdr *cfg_shdr = NULL;
1783*4882a593Smuzhiyun 	uint32_t alloc_len;
1784*4882a593Smuzhiyun 	uint32_t resid_len;
1785*4882a593Smuzhiyun 	uint32_t pagen, pcount;
1786*4882a593Smuzhiyun 	void *viraddr;
1787*4882a593Smuzhiyun 	dma_addr_t phyaddr;
1788*4882a593Smuzhiyun 
1789*4882a593Smuzhiyun 	/* Set up SLI4 mailbox command header fields */
1790*4882a593Smuzhiyun 	memset(mbox, 0, sizeof(*mbox));
1791*4882a593Smuzhiyun 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG);
1792*4882a593Smuzhiyun 
1793*4882a593Smuzhiyun 	/* Set up SLI4 ioctl command header fields */
1794*4882a593Smuzhiyun 	sli4_config = &mbox->u.mqe.un.sli4_config;
1795*4882a593Smuzhiyun 
1796*4882a593Smuzhiyun 	/* Setup for the embedded mbox command */
1797*4882a593Smuzhiyun 	if (emb) {
1798*4882a593Smuzhiyun 		/* Set up main header fields */
1799*4882a593Smuzhiyun 		bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
1800*4882a593Smuzhiyun 		sli4_config->header.cfg_mhdr.payload_length = length;
1801*4882a593Smuzhiyun 		/* Set up sub-header fields following main header */
1802*4882a593Smuzhiyun 		bf_set(lpfc_mbox_hdr_opcode,
1803*4882a593Smuzhiyun 			&sli4_config->header.cfg_shdr.request, opcode);
1804*4882a593Smuzhiyun 		bf_set(lpfc_mbox_hdr_subsystem,
1805*4882a593Smuzhiyun 			&sli4_config->header.cfg_shdr.request, subsystem);
1806*4882a593Smuzhiyun 		sli4_config->header.cfg_shdr.request.request_length =
1807*4882a593Smuzhiyun 			length - LPFC_MBX_CMD_HDR_LENGTH;
1808*4882a593Smuzhiyun 		return length;
1809*4882a593Smuzhiyun 	}
1810*4882a593Smuzhiyun 
1811*4882a593Smuzhiyun 	/* Setup for the non-embedded mbox command */
1812*4882a593Smuzhiyun 	pcount = (SLI4_PAGE_ALIGN(length))/SLI4_PAGE_SIZE;
1813*4882a593Smuzhiyun 	pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ?
1814*4882a593Smuzhiyun 				LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount;
1815*4882a593Smuzhiyun 	/* Allocate record for keeping SGE virtual addresses */
1816*4882a593Smuzhiyun 	mbox->sge_array = kzalloc(sizeof(struct lpfc_mbx_nembed_sge_virt),
1817*4882a593Smuzhiyun 				  GFP_KERNEL);
1818*4882a593Smuzhiyun 	if (!mbox->sge_array) {
1819*4882a593Smuzhiyun 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1820*4882a593Smuzhiyun 				"2527 Failed to allocate non-embedded SGE "
1821*4882a593Smuzhiyun 				"array.\n");
1822*4882a593Smuzhiyun 		return 0;
1823*4882a593Smuzhiyun 	}
1824*4882a593Smuzhiyun 	for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) {
1825*4882a593Smuzhiyun 		/* The DMA memory is always allocated in the length of a
1826*4882a593Smuzhiyun 		 * page even though the last SGE might not fill up to a
1827*4882a593Smuzhiyun 		 * page, this is used as a priori size of SLI4_PAGE_SIZE for
1828*4882a593Smuzhiyun 		 * the later DMA memory free.
1829*4882a593Smuzhiyun 		 */
1830*4882a593Smuzhiyun 		viraddr = dma_alloc_coherent(&phba->pcidev->dev,
1831*4882a593Smuzhiyun 					     SLI4_PAGE_SIZE, &phyaddr,
1832*4882a593Smuzhiyun 					     GFP_KERNEL);
1833*4882a593Smuzhiyun 		/* In case of malloc fails, proceed with whatever we have */
1834*4882a593Smuzhiyun 		if (!viraddr)
1835*4882a593Smuzhiyun 			break;
1836*4882a593Smuzhiyun 		mbox->sge_array->addr[pagen] = viraddr;
1837*4882a593Smuzhiyun 		/* Keep the first page for later sub-header construction */
1838*4882a593Smuzhiyun 		if (pagen == 0)
1839*4882a593Smuzhiyun 			cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr;
1840*4882a593Smuzhiyun 		resid_len = length - alloc_len;
1841*4882a593Smuzhiyun 		if (resid_len > SLI4_PAGE_SIZE) {
1842*4882a593Smuzhiyun 			lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
1843*4882a593Smuzhiyun 					      SLI4_PAGE_SIZE);
1844*4882a593Smuzhiyun 			alloc_len += SLI4_PAGE_SIZE;
1845*4882a593Smuzhiyun 		} else {
1846*4882a593Smuzhiyun 			lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
1847*4882a593Smuzhiyun 					      resid_len);
1848*4882a593Smuzhiyun 			alloc_len = length;
1849*4882a593Smuzhiyun 		}
1850*4882a593Smuzhiyun 	}
1851*4882a593Smuzhiyun 
1852*4882a593Smuzhiyun 	/* Set up main header fields in mailbox command */
1853*4882a593Smuzhiyun 	sli4_config->header.cfg_mhdr.payload_length = alloc_len;
1854*4882a593Smuzhiyun 	bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen);
1855*4882a593Smuzhiyun 
1856*4882a593Smuzhiyun 	/* Set up sub-header fields into the first page */
1857*4882a593Smuzhiyun 	if (pagen > 0) {
1858*4882a593Smuzhiyun 		bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode);
1859*4882a593Smuzhiyun 		bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem);
1860*4882a593Smuzhiyun 		cfg_shdr->request.request_length =
1861*4882a593Smuzhiyun 				alloc_len - sizeof(union  lpfc_sli4_cfg_shdr);
1862*4882a593Smuzhiyun 	}
1863*4882a593Smuzhiyun 	/* The sub-header is in DMA memory, which needs endian converstion */
1864*4882a593Smuzhiyun 	if (cfg_shdr)
1865*4882a593Smuzhiyun 		lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
1866*4882a593Smuzhiyun 				      sizeof(union  lpfc_sli4_cfg_shdr));
1867*4882a593Smuzhiyun 	return alloc_len;
1868*4882a593Smuzhiyun }
1869*4882a593Smuzhiyun 
1870*4882a593Smuzhiyun /**
1871*4882a593Smuzhiyun  * lpfc_sli4_mbox_rsrc_extent - Initialize the opcode resource extent.
1872*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1873*4882a593Smuzhiyun  * @mbox: pointer to an allocated lpfc mbox resource.
1874*4882a593Smuzhiyun  * @exts_count: the number of extents, if required, to allocate.
1875*4882a593Smuzhiyun  * @rsrc_type: the resource extent type.
1876*4882a593Smuzhiyun  * @emb: true if LPFC_SLI4_MBX_EMBED. false if LPFC_SLI4_MBX_NEMBED.
1877*4882a593Smuzhiyun  *
1878*4882a593Smuzhiyun  * This routine completes the subcommand header for SLI4 resource extent
1879*4882a593Smuzhiyun  * mailbox commands.  It is called after lpfc_sli4_config.  The caller must
1880*4882a593Smuzhiyun  * pass an allocated mailbox and the attributes required to initialize the
1881*4882a593Smuzhiyun  * mailbox correctly.
1882*4882a593Smuzhiyun  *
1883*4882a593Smuzhiyun  * Return: the actual length of the mbox command allocated.
1884*4882a593Smuzhiyun  **/
1885*4882a593Smuzhiyun int
lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba * phba,struct lpfcMboxq * mbox,uint16_t exts_count,uint16_t rsrc_type,bool emb)1886*4882a593Smuzhiyun lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
1887*4882a593Smuzhiyun 			   uint16_t exts_count, uint16_t rsrc_type, bool emb)
1888*4882a593Smuzhiyun {
1889*4882a593Smuzhiyun 	uint8_t opcode = 0;
1890*4882a593Smuzhiyun 	struct lpfc_mbx_nembed_rsrc_extent *n_rsrc_extnt = NULL;
1891*4882a593Smuzhiyun 	void *virtaddr = NULL;
1892*4882a593Smuzhiyun 
1893*4882a593Smuzhiyun 	/* Set up SLI4 ioctl command header fields */
1894*4882a593Smuzhiyun 	if (emb == LPFC_SLI4_MBX_NEMBED) {
1895*4882a593Smuzhiyun 		/* Get the first SGE entry from the non-embedded DMA memory */
1896*4882a593Smuzhiyun 		virtaddr = mbox->sge_array->addr[0];
1897*4882a593Smuzhiyun 		if (virtaddr == NULL)
1898*4882a593Smuzhiyun 			return 1;
1899*4882a593Smuzhiyun 		n_rsrc_extnt = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
1900*4882a593Smuzhiyun 	}
1901*4882a593Smuzhiyun 
1902*4882a593Smuzhiyun 	/*
1903*4882a593Smuzhiyun 	 * The resource type is common to all extent Opcodes and resides in the
1904*4882a593Smuzhiyun 	 * same position.
1905*4882a593Smuzhiyun 	 */
1906*4882a593Smuzhiyun 	if (emb == LPFC_SLI4_MBX_EMBED)
1907*4882a593Smuzhiyun 		bf_set(lpfc_mbx_alloc_rsrc_extents_type,
1908*4882a593Smuzhiyun 		       &mbox->u.mqe.un.alloc_rsrc_extents.u.req,
1909*4882a593Smuzhiyun 		       rsrc_type);
1910*4882a593Smuzhiyun 	else {
1911*4882a593Smuzhiyun 		/* This is DMA data.  Byteswap is required. */
1912*4882a593Smuzhiyun 		bf_set(lpfc_mbx_alloc_rsrc_extents_type,
1913*4882a593Smuzhiyun 		       n_rsrc_extnt, rsrc_type);
1914*4882a593Smuzhiyun 		lpfc_sli_pcimem_bcopy(&n_rsrc_extnt->word4,
1915*4882a593Smuzhiyun 				      &n_rsrc_extnt->word4,
1916*4882a593Smuzhiyun 				      sizeof(uint32_t));
1917*4882a593Smuzhiyun 	}
1918*4882a593Smuzhiyun 
1919*4882a593Smuzhiyun 	/* Complete the initialization for the particular Opcode. */
1920*4882a593Smuzhiyun 	opcode = lpfc_sli_config_mbox_opcode_get(phba, mbox);
1921*4882a593Smuzhiyun 	switch (opcode) {
1922*4882a593Smuzhiyun 	case LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT:
1923*4882a593Smuzhiyun 		if (emb == LPFC_SLI4_MBX_EMBED)
1924*4882a593Smuzhiyun 			bf_set(lpfc_mbx_alloc_rsrc_extents_cnt,
1925*4882a593Smuzhiyun 			       &mbox->u.mqe.un.alloc_rsrc_extents.u.req,
1926*4882a593Smuzhiyun 			       exts_count);
1927*4882a593Smuzhiyun 		else
1928*4882a593Smuzhiyun 			bf_set(lpfc_mbx_alloc_rsrc_extents_cnt,
1929*4882a593Smuzhiyun 			       n_rsrc_extnt, exts_count);
1930*4882a593Smuzhiyun 		break;
1931*4882a593Smuzhiyun 	case LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT:
1932*4882a593Smuzhiyun 	case LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO:
1933*4882a593Smuzhiyun 	case LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT:
1934*4882a593Smuzhiyun 		/* Initialization is complete.*/
1935*4882a593Smuzhiyun 		break;
1936*4882a593Smuzhiyun 	default:
1937*4882a593Smuzhiyun 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1938*4882a593Smuzhiyun 				"2929 Resource Extent Opcode x%x is "
1939*4882a593Smuzhiyun 				"unsupported\n", opcode);
1940*4882a593Smuzhiyun 		return 1;
1941*4882a593Smuzhiyun 	}
1942*4882a593Smuzhiyun 
1943*4882a593Smuzhiyun 	return 0;
1944*4882a593Smuzhiyun }
1945*4882a593Smuzhiyun 
1946*4882a593Smuzhiyun /**
1947*4882a593Smuzhiyun  * lpfc_sli_config_mbox_subsys_get - Get subsystem from a sli_config mbox cmd
1948*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1949*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command queue entry.
1950*4882a593Smuzhiyun  *
1951*4882a593Smuzhiyun  * This routine gets the subsystem from a SLI4 specific SLI_CONFIG mailbox
1952*4882a593Smuzhiyun  * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if the
1953*4882a593Smuzhiyun  * sub-header is not present, subsystem LPFC_MBOX_SUBSYSTEM_NA (0x0) shall
1954*4882a593Smuzhiyun  * be returned.
1955*4882a593Smuzhiyun  **/
1956*4882a593Smuzhiyun uint8_t
lpfc_sli_config_mbox_subsys_get(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbox)1957*4882a593Smuzhiyun lpfc_sli_config_mbox_subsys_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
1958*4882a593Smuzhiyun {
1959*4882a593Smuzhiyun 	struct lpfc_mbx_sli4_config *sli4_cfg;
1960*4882a593Smuzhiyun 	union lpfc_sli4_cfg_shdr *cfg_shdr;
1961*4882a593Smuzhiyun 
1962*4882a593Smuzhiyun 	if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
1963*4882a593Smuzhiyun 		return LPFC_MBOX_SUBSYSTEM_NA;
1964*4882a593Smuzhiyun 	sli4_cfg = &mbox->u.mqe.un.sli4_config;
1965*4882a593Smuzhiyun 
1966*4882a593Smuzhiyun 	/* For embedded mbox command, get opcode from embedded sub-header*/
1967*4882a593Smuzhiyun 	if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1968*4882a593Smuzhiyun 		cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
1969*4882a593Smuzhiyun 		return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request);
1970*4882a593Smuzhiyun 	}
1971*4882a593Smuzhiyun 
1972*4882a593Smuzhiyun 	/* For non-embedded mbox command, get opcode from first dma page */
1973*4882a593Smuzhiyun 	if (unlikely(!mbox->sge_array))
1974*4882a593Smuzhiyun 		return LPFC_MBOX_SUBSYSTEM_NA;
1975*4882a593Smuzhiyun 	cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
1976*4882a593Smuzhiyun 	return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request);
1977*4882a593Smuzhiyun }
1978*4882a593Smuzhiyun 
1979*4882a593Smuzhiyun /**
1980*4882a593Smuzhiyun  * lpfc_sli_config_mbox_opcode_get - Get opcode from a sli_config mbox cmd
1981*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
1982*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command queue entry.
1983*4882a593Smuzhiyun  *
1984*4882a593Smuzhiyun  * This routine gets the opcode from a SLI4 specific SLI_CONFIG mailbox
1985*4882a593Smuzhiyun  * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if
1986*4882a593Smuzhiyun  * the sub-header is not present, opcode LPFC_MBOX_OPCODE_NA (0x0) be
1987*4882a593Smuzhiyun  * returned.
1988*4882a593Smuzhiyun  **/
1989*4882a593Smuzhiyun uint8_t
lpfc_sli_config_mbox_opcode_get(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbox)1990*4882a593Smuzhiyun lpfc_sli_config_mbox_opcode_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
1991*4882a593Smuzhiyun {
1992*4882a593Smuzhiyun 	struct lpfc_mbx_sli4_config *sli4_cfg;
1993*4882a593Smuzhiyun 	union lpfc_sli4_cfg_shdr *cfg_shdr;
1994*4882a593Smuzhiyun 
1995*4882a593Smuzhiyun 	if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
1996*4882a593Smuzhiyun 		return LPFC_MBOX_OPCODE_NA;
1997*4882a593Smuzhiyun 	sli4_cfg = &mbox->u.mqe.un.sli4_config;
1998*4882a593Smuzhiyun 
1999*4882a593Smuzhiyun 	/* For embedded mbox command, get opcode from embedded sub-header*/
2000*4882a593Smuzhiyun 	if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
2001*4882a593Smuzhiyun 		cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
2002*4882a593Smuzhiyun 		return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
2003*4882a593Smuzhiyun 	}
2004*4882a593Smuzhiyun 
2005*4882a593Smuzhiyun 	/* For non-embedded mbox command, get opcode from first dma page */
2006*4882a593Smuzhiyun 	if (unlikely(!mbox->sge_array))
2007*4882a593Smuzhiyun 		return LPFC_MBOX_OPCODE_NA;
2008*4882a593Smuzhiyun 	cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
2009*4882a593Smuzhiyun 	return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
2010*4882a593Smuzhiyun }
2011*4882a593Smuzhiyun 
2012*4882a593Smuzhiyun /**
2013*4882a593Smuzhiyun  * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd
2014*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
2015*4882a593Smuzhiyun  * @mboxq: pointer to lpfc mbox command.
2016*4882a593Smuzhiyun  * @fcf_index: index to fcf table.
2017*4882a593Smuzhiyun  *
2018*4882a593Smuzhiyun  * This routine routine allocates and constructs non-embedded mailbox command
2019*4882a593Smuzhiyun  * for reading a FCF table entry referred by @fcf_index.
2020*4882a593Smuzhiyun  *
2021*4882a593Smuzhiyun  * Return: pointer to the mailbox command constructed if successful, otherwise
2022*4882a593Smuzhiyun  * NULL.
2023*4882a593Smuzhiyun  **/
2024*4882a593Smuzhiyun int
lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba * phba,struct lpfcMboxq * mboxq,uint16_t fcf_index)2025*4882a593Smuzhiyun lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *phba,
2026*4882a593Smuzhiyun 			   struct lpfcMboxq *mboxq,
2027*4882a593Smuzhiyun 			   uint16_t fcf_index)
2028*4882a593Smuzhiyun {
2029*4882a593Smuzhiyun 	void *virt_addr;
2030*4882a593Smuzhiyun 	uint8_t *bytep;
2031*4882a593Smuzhiyun 	struct lpfc_mbx_sge sge;
2032*4882a593Smuzhiyun 	uint32_t alloc_len, req_len;
2033*4882a593Smuzhiyun 	struct lpfc_mbx_read_fcf_tbl *read_fcf;
2034*4882a593Smuzhiyun 
2035*4882a593Smuzhiyun 	if (!mboxq)
2036*4882a593Smuzhiyun 		return -ENOMEM;
2037*4882a593Smuzhiyun 
2038*4882a593Smuzhiyun 	req_len = sizeof(struct fcf_record) +
2039*4882a593Smuzhiyun 		  sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
2040*4882a593Smuzhiyun 
2041*4882a593Smuzhiyun 	/* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
2042*4882a593Smuzhiyun 	alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
2043*4882a593Smuzhiyun 			LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
2044*4882a593Smuzhiyun 			LPFC_SLI4_MBX_NEMBED);
2045*4882a593Smuzhiyun 
2046*4882a593Smuzhiyun 	if (alloc_len < req_len) {
2047*4882a593Smuzhiyun 		lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2048*4882a593Smuzhiyun 				"0291 Allocated DMA memory size (x%x) is "
2049*4882a593Smuzhiyun 				"less than the requested DMA memory "
2050*4882a593Smuzhiyun 				"size (x%x)\n", alloc_len, req_len);
2051*4882a593Smuzhiyun 		return -ENOMEM;
2052*4882a593Smuzhiyun 	}
2053*4882a593Smuzhiyun 
2054*4882a593Smuzhiyun 	/* Get the first SGE entry from the non-embedded DMA memory. This
2055*4882a593Smuzhiyun 	 * routine only uses a single SGE.
2056*4882a593Smuzhiyun 	 */
2057*4882a593Smuzhiyun 	lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
2058*4882a593Smuzhiyun 	virt_addr = mboxq->sge_array->addr[0];
2059*4882a593Smuzhiyun 	read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
2060*4882a593Smuzhiyun 
2061*4882a593Smuzhiyun 	/* Set up command fields */
2062*4882a593Smuzhiyun 	bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
2063*4882a593Smuzhiyun 	/* Perform necessary endian conversion */
2064*4882a593Smuzhiyun 	bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
2065*4882a593Smuzhiyun 	lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
2066*4882a593Smuzhiyun 
2067*4882a593Smuzhiyun 	return 0;
2068*4882a593Smuzhiyun }
2069*4882a593Smuzhiyun 
2070*4882a593Smuzhiyun /**
2071*4882a593Smuzhiyun  * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
2072*4882a593Smuzhiyun  * @phba: pointer to lpfc hba data structure.
2073*4882a593Smuzhiyun  * @mboxq: pointer to lpfc mbox command.
2074*4882a593Smuzhiyun  *
2075*4882a593Smuzhiyun  * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
2076*4882a593Smuzhiyun  * mailbox command.
2077*4882a593Smuzhiyun  **/
2078*4882a593Smuzhiyun void
lpfc_request_features(struct lpfc_hba * phba,struct lpfcMboxq * mboxq)2079*4882a593Smuzhiyun lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
2080*4882a593Smuzhiyun {
2081*4882a593Smuzhiyun 	/* Set up SLI4 mailbox command header fields */
2082*4882a593Smuzhiyun 	memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
2083*4882a593Smuzhiyun 	bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS);
2084*4882a593Smuzhiyun 
2085*4882a593Smuzhiyun 	/* Set up host requested features. */
2086*4882a593Smuzhiyun 	bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
2087*4882a593Smuzhiyun 	bf_set(lpfc_mbx_rq_ftr_rq_perfh, &mboxq->u.mqe.un.req_ftrs, 1);
2088*4882a593Smuzhiyun 
2089*4882a593Smuzhiyun 	/* Enable DIF (block guard) only if configured to do so. */
2090*4882a593Smuzhiyun 	if (phba->cfg_enable_bg)
2091*4882a593Smuzhiyun 		bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1);
2092*4882a593Smuzhiyun 
2093*4882a593Smuzhiyun 	/* Enable NPIV only if configured to do so. */
2094*4882a593Smuzhiyun 	if (phba->max_vpi && phba->cfg_enable_npiv)
2095*4882a593Smuzhiyun 		bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1);
2096*4882a593Smuzhiyun 
2097*4882a593Smuzhiyun 	if (phba->nvmet_support) {
2098*4882a593Smuzhiyun 		bf_set(lpfc_mbx_rq_ftr_rq_mrqp, &mboxq->u.mqe.un.req_ftrs, 1);
2099*4882a593Smuzhiyun 		/* iaab/iaar NOT set for now */
2100*4882a593Smuzhiyun 		bf_set(lpfc_mbx_rq_ftr_rq_iaab, &mboxq->u.mqe.un.req_ftrs, 0);
2101*4882a593Smuzhiyun 		bf_set(lpfc_mbx_rq_ftr_rq_iaar, &mboxq->u.mqe.un.req_ftrs, 0);
2102*4882a593Smuzhiyun 	}
2103*4882a593Smuzhiyun 	return;
2104*4882a593Smuzhiyun }
2105*4882a593Smuzhiyun 
2106*4882a593Smuzhiyun /**
2107*4882a593Smuzhiyun  * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
2108*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command to initialize.
2109*4882a593Smuzhiyun  * @vport: Vport associated with the VF.
2110*4882a593Smuzhiyun  *
2111*4882a593Smuzhiyun  * This routine initializes @mbox to all zeros and then fills in the mailbox
2112*4882a593Smuzhiyun  * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
2113*4882a593Smuzhiyun  * in the context of an FCF. The driver issues this command to setup a VFI
2114*4882a593Smuzhiyun  * before issuing a FLOGI to login to the VSAN. The driver should also issue a
2115*4882a593Smuzhiyun  * REG_VFI after a successful VSAN login.
2116*4882a593Smuzhiyun  **/
2117*4882a593Smuzhiyun void
lpfc_init_vfi(struct lpfcMboxq * mbox,struct lpfc_vport * vport)2118*4882a593Smuzhiyun lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
2119*4882a593Smuzhiyun {
2120*4882a593Smuzhiyun 	struct lpfc_mbx_init_vfi *init_vfi;
2121*4882a593Smuzhiyun 
2122*4882a593Smuzhiyun 	memset(mbox, 0, sizeof(*mbox));
2123*4882a593Smuzhiyun 	mbox->vport = vport;
2124*4882a593Smuzhiyun 	init_vfi = &mbox->u.mqe.un.init_vfi;
2125*4882a593Smuzhiyun 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI);
2126*4882a593Smuzhiyun 	bf_set(lpfc_init_vfi_vr, init_vfi, 1);
2127*4882a593Smuzhiyun 	bf_set(lpfc_init_vfi_vt, init_vfi, 1);
2128*4882a593Smuzhiyun 	bf_set(lpfc_init_vfi_vp, init_vfi, 1);
2129*4882a593Smuzhiyun 	bf_set(lpfc_init_vfi_vfi, init_vfi,
2130*4882a593Smuzhiyun 	       vport->phba->sli4_hba.vfi_ids[vport->vfi]);
2131*4882a593Smuzhiyun 	bf_set(lpfc_init_vfi_vpi, init_vfi,
2132*4882a593Smuzhiyun 	       vport->phba->vpi_ids[vport->vpi]);
2133*4882a593Smuzhiyun 	bf_set(lpfc_init_vfi_fcfi, init_vfi,
2134*4882a593Smuzhiyun 	       vport->phba->fcf.fcfi);
2135*4882a593Smuzhiyun }
2136*4882a593Smuzhiyun 
2137*4882a593Smuzhiyun /**
2138*4882a593Smuzhiyun  * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
2139*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command to initialize.
2140*4882a593Smuzhiyun  * @vport: vport associated with the VF.
2141*4882a593Smuzhiyun  * @phys: BDE DMA bus address used to send the service parameters to the HBA.
2142*4882a593Smuzhiyun  *
2143*4882a593Smuzhiyun  * This routine initializes @mbox to all zeros and then fills in the mailbox
2144*4882a593Smuzhiyun  * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
2145*4882a593Smuzhiyun  * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
2146*4882a593Smuzhiyun  * fabrics identified by VFI in the context of an FCF.
2147*4882a593Smuzhiyun  **/
2148*4882a593Smuzhiyun void
lpfc_reg_vfi(struct lpfcMboxq * mbox,struct lpfc_vport * vport,dma_addr_t phys)2149*4882a593Smuzhiyun lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys)
2150*4882a593Smuzhiyun {
2151*4882a593Smuzhiyun 	struct lpfc_mbx_reg_vfi *reg_vfi;
2152*4882a593Smuzhiyun 	struct lpfc_hba *phba = vport->phba;
2153*4882a593Smuzhiyun 	uint8_t bbscn_fabric = 0, bbscn_max = 0, bbscn_def = 0;
2154*4882a593Smuzhiyun 
2155*4882a593Smuzhiyun 	memset(mbox, 0, sizeof(*mbox));
2156*4882a593Smuzhiyun 	reg_vfi = &mbox->u.mqe.un.reg_vfi;
2157*4882a593Smuzhiyun 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI);
2158*4882a593Smuzhiyun 	bf_set(lpfc_reg_vfi_vp, reg_vfi, 1);
2159*4882a593Smuzhiyun 	bf_set(lpfc_reg_vfi_vfi, reg_vfi,
2160*4882a593Smuzhiyun 	       phba->sli4_hba.vfi_ids[vport->vfi]);
2161*4882a593Smuzhiyun 	bf_set(lpfc_reg_vfi_fcfi, reg_vfi, phba->fcf.fcfi);
2162*4882a593Smuzhiyun 	bf_set(lpfc_reg_vfi_vpi, reg_vfi, phba->vpi_ids[vport->vpi]);
2163*4882a593Smuzhiyun 	memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name));
2164*4882a593Smuzhiyun 	reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]);
2165*4882a593Smuzhiyun 	reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]);
2166*4882a593Smuzhiyun 	reg_vfi->e_d_tov = phba->fc_edtov;
2167*4882a593Smuzhiyun 	reg_vfi->r_a_tov = phba->fc_ratov;
2168*4882a593Smuzhiyun 	if (phys) {
2169*4882a593Smuzhiyun 		reg_vfi->bde.addrHigh = putPaddrHigh(phys);
2170*4882a593Smuzhiyun 		reg_vfi->bde.addrLow = putPaddrLow(phys);
2171*4882a593Smuzhiyun 		reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam);
2172*4882a593Smuzhiyun 		reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
2173*4882a593Smuzhiyun 	}
2174*4882a593Smuzhiyun 	bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID);
2175*4882a593Smuzhiyun 
2176*4882a593Smuzhiyun 	/* Only FC supports upd bit */
2177*4882a593Smuzhiyun 	if ((phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) &&
2178*4882a593Smuzhiyun 	    (vport->fc_flag & FC_VFI_REGISTERED) &&
2179*4882a593Smuzhiyun 	    (!phba->fc_topology_changed))
2180*4882a593Smuzhiyun 		bf_set(lpfc_reg_vfi_upd, reg_vfi, 1);
2181*4882a593Smuzhiyun 
2182*4882a593Smuzhiyun 	bf_set(lpfc_reg_vfi_bbcr, reg_vfi, 0);
2183*4882a593Smuzhiyun 	bf_set(lpfc_reg_vfi_bbscn, reg_vfi, 0);
2184*4882a593Smuzhiyun 	bbscn_fabric = (phba->fc_fabparam.cmn.bbRcvSizeMsb >> 4) & 0xF;
2185*4882a593Smuzhiyun 
2186*4882a593Smuzhiyun 	if (phba->bbcredit_support && phba->cfg_enable_bbcr  &&
2187*4882a593Smuzhiyun 	    bbscn_fabric != 0) {
2188*4882a593Smuzhiyun 		bbscn_max = bf_get(lpfc_bbscn_max,
2189*4882a593Smuzhiyun 				   &phba->sli4_hba.bbscn_params);
2190*4882a593Smuzhiyun 		if (bbscn_fabric <= bbscn_max) {
2191*4882a593Smuzhiyun 			bbscn_def = bf_get(lpfc_bbscn_def,
2192*4882a593Smuzhiyun 					   &phba->sli4_hba.bbscn_params);
2193*4882a593Smuzhiyun 
2194*4882a593Smuzhiyun 			if (bbscn_fabric > bbscn_def)
2195*4882a593Smuzhiyun 				bf_set(lpfc_reg_vfi_bbscn, reg_vfi,
2196*4882a593Smuzhiyun 				       bbscn_fabric);
2197*4882a593Smuzhiyun 			else
2198*4882a593Smuzhiyun 				bf_set(lpfc_reg_vfi_bbscn, reg_vfi, bbscn_def);
2199*4882a593Smuzhiyun 
2200*4882a593Smuzhiyun 			bf_set(lpfc_reg_vfi_bbcr, reg_vfi, 1);
2201*4882a593Smuzhiyun 		}
2202*4882a593Smuzhiyun 	}
2203*4882a593Smuzhiyun 	lpfc_printf_vlog(vport, KERN_INFO, LOG_MBOX,
2204*4882a593Smuzhiyun 			"3134 Register VFI, mydid:x%x, fcfi:%d, "
2205*4882a593Smuzhiyun 			" vfi:%d, vpi:%d, fc_pname:%x%x fc_flag:x%x"
2206*4882a593Smuzhiyun 			" port_state:x%x topology chg:%d bbscn_fabric :%d\n",
2207*4882a593Smuzhiyun 			vport->fc_myDID,
2208*4882a593Smuzhiyun 			phba->fcf.fcfi,
2209*4882a593Smuzhiyun 			phba->sli4_hba.vfi_ids[vport->vfi],
2210*4882a593Smuzhiyun 			phba->vpi_ids[vport->vpi],
2211*4882a593Smuzhiyun 			reg_vfi->wwn[0], reg_vfi->wwn[1], vport->fc_flag,
2212*4882a593Smuzhiyun 			vport->port_state, phba->fc_topology_changed,
2213*4882a593Smuzhiyun 			bbscn_fabric);
2214*4882a593Smuzhiyun }
2215*4882a593Smuzhiyun 
2216*4882a593Smuzhiyun /**
2217*4882a593Smuzhiyun  * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
2218*4882a593Smuzhiyun  * @phba: pointer to the hba structure to init the VPI for.
2219*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command to initialize.
2220*4882a593Smuzhiyun  * @vpi: VPI to be initialized.
2221*4882a593Smuzhiyun  *
2222*4882a593Smuzhiyun  * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
2223*4882a593Smuzhiyun  * command to activate a virtual N_Port. The HBA assigns a MAC address to use
2224*4882a593Smuzhiyun  * with the virtual N Port.  The SLI Host issues this command before issuing a
2225*4882a593Smuzhiyun  * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
2226*4882a593Smuzhiyun  * successful virtual NPort login.
2227*4882a593Smuzhiyun  **/
2228*4882a593Smuzhiyun void
lpfc_init_vpi(struct lpfc_hba * phba,struct lpfcMboxq * mbox,uint16_t vpi)2229*4882a593Smuzhiyun lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi)
2230*4882a593Smuzhiyun {
2231*4882a593Smuzhiyun 	memset(mbox, 0, sizeof(*mbox));
2232*4882a593Smuzhiyun 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI);
2233*4882a593Smuzhiyun 	bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi,
2234*4882a593Smuzhiyun 	       phba->vpi_ids[vpi]);
2235*4882a593Smuzhiyun 	bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi,
2236*4882a593Smuzhiyun 	       phba->sli4_hba.vfi_ids[phba->pport->vfi]);
2237*4882a593Smuzhiyun }
2238*4882a593Smuzhiyun 
2239*4882a593Smuzhiyun /**
2240*4882a593Smuzhiyun  * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
2241*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command to initialize.
2242*4882a593Smuzhiyun  * @vport: vport associated with the VF.
2243*4882a593Smuzhiyun  *
2244*4882a593Smuzhiyun  * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
2245*4882a593Smuzhiyun  * (logical NPort) into the inactive state. The SLI Host must have logged out
2246*4882a593Smuzhiyun  * and unregistered all remote N_Ports to abort any activity on the virtual
2247*4882a593Smuzhiyun  * fabric. The SLI Port posts the mailbox response after marking the virtual
2248*4882a593Smuzhiyun  * fabric inactive.
2249*4882a593Smuzhiyun  **/
2250*4882a593Smuzhiyun void
lpfc_unreg_vfi(struct lpfcMboxq * mbox,struct lpfc_vport * vport)2251*4882a593Smuzhiyun lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
2252*4882a593Smuzhiyun {
2253*4882a593Smuzhiyun 	memset(mbox, 0, sizeof(*mbox));
2254*4882a593Smuzhiyun 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI);
2255*4882a593Smuzhiyun 	bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi,
2256*4882a593Smuzhiyun 	       vport->phba->sli4_hba.vfi_ids[vport->vfi]);
2257*4882a593Smuzhiyun }
2258*4882a593Smuzhiyun 
2259*4882a593Smuzhiyun /**
2260*4882a593Smuzhiyun  * lpfc_sli4_dump_cfg_rg23 - Dump sli4 port config region 23
2261*4882a593Smuzhiyun  * @phba: pointer to the hba structure containing.
2262*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command to initialize.
2263*4882a593Smuzhiyun  *
2264*4882a593Smuzhiyun  * This function create a SLI4 dump mailbox command to dump configure
2265*4882a593Smuzhiyun  * region 23.
2266*4882a593Smuzhiyun  **/
2267*4882a593Smuzhiyun int
lpfc_sli4_dump_cfg_rg23(struct lpfc_hba * phba,struct lpfcMboxq * mbox)2268*4882a593Smuzhiyun lpfc_sli4_dump_cfg_rg23(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
2269*4882a593Smuzhiyun {
2270*4882a593Smuzhiyun 	struct lpfc_dmabuf *mp = NULL;
2271*4882a593Smuzhiyun 	MAILBOX_t *mb;
2272*4882a593Smuzhiyun 
2273*4882a593Smuzhiyun 	memset(mbox, 0, sizeof(*mbox));
2274*4882a593Smuzhiyun 	mb = &mbox->u.mb;
2275*4882a593Smuzhiyun 
2276*4882a593Smuzhiyun 	mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2277*4882a593Smuzhiyun 	if (mp)
2278*4882a593Smuzhiyun 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
2279*4882a593Smuzhiyun 
2280*4882a593Smuzhiyun 	if (!mp || !mp->virt) {
2281*4882a593Smuzhiyun 		kfree(mp);
2282*4882a593Smuzhiyun 		/* dump config region 23 failed to allocate memory */
2283*4882a593Smuzhiyun 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
2284*4882a593Smuzhiyun 			"2569 lpfc dump config region 23: memory"
2285*4882a593Smuzhiyun 			" allocation failed\n");
2286*4882a593Smuzhiyun 		return 1;
2287*4882a593Smuzhiyun 	}
2288*4882a593Smuzhiyun 
2289*4882a593Smuzhiyun 	memset(mp->virt, 0, LPFC_BPL_SIZE);
2290*4882a593Smuzhiyun 	INIT_LIST_HEAD(&mp->list);
2291*4882a593Smuzhiyun 
2292*4882a593Smuzhiyun 	/* save address for completion */
2293*4882a593Smuzhiyun 	mbox->ctx_buf = (uint8_t *)mp;
2294*4882a593Smuzhiyun 
2295*4882a593Smuzhiyun 	mb->mbxCommand = MBX_DUMP_MEMORY;
2296*4882a593Smuzhiyun 	mb->un.varDmp.type = DMP_NV_PARAMS;
2297*4882a593Smuzhiyun 	mb->un.varDmp.region_id = DMP_REGION_23;
2298*4882a593Smuzhiyun 	mb->un.varDmp.sli4_length = DMP_RGN23_SIZE;
2299*4882a593Smuzhiyun 	mb->un.varWords[3] = putPaddrLow(mp->phys);
2300*4882a593Smuzhiyun 	mb->un.varWords[4] = putPaddrHigh(mp->phys);
2301*4882a593Smuzhiyun 	return 0;
2302*4882a593Smuzhiyun }
2303*4882a593Smuzhiyun 
2304*4882a593Smuzhiyun static void
lpfc_mbx_cmpl_rdp_link_stat(struct lpfc_hba * phba,LPFC_MBOXQ_t * mboxq)2305*4882a593Smuzhiyun lpfc_mbx_cmpl_rdp_link_stat(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2306*4882a593Smuzhiyun {
2307*4882a593Smuzhiyun 	MAILBOX_t *mb;
2308*4882a593Smuzhiyun 	int rc = FAILURE;
2309*4882a593Smuzhiyun 	struct lpfc_rdp_context *rdp_context =
2310*4882a593Smuzhiyun 			(struct lpfc_rdp_context *)(mboxq->ctx_ndlp);
2311*4882a593Smuzhiyun 
2312*4882a593Smuzhiyun 	mb = &mboxq->u.mb;
2313*4882a593Smuzhiyun 	if (mb->mbxStatus)
2314*4882a593Smuzhiyun 		goto mbx_failed;
2315*4882a593Smuzhiyun 
2316*4882a593Smuzhiyun 	memcpy(&rdp_context->link_stat, &mb->un.varRdLnk, sizeof(READ_LNK_VAR));
2317*4882a593Smuzhiyun 
2318*4882a593Smuzhiyun 	rc = SUCCESS;
2319*4882a593Smuzhiyun 
2320*4882a593Smuzhiyun mbx_failed:
2321*4882a593Smuzhiyun 	lpfc_sli4_mbox_cmd_free(phba, mboxq);
2322*4882a593Smuzhiyun 	rdp_context->cmpl(phba, rdp_context, rc);
2323*4882a593Smuzhiyun }
2324*4882a593Smuzhiyun 
2325*4882a593Smuzhiyun static void
lpfc_mbx_cmpl_rdp_page_a2(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbox)2326*4882a593Smuzhiyun lpfc_mbx_cmpl_rdp_page_a2(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
2327*4882a593Smuzhiyun {
2328*4882a593Smuzhiyun 	struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
2329*4882a593Smuzhiyun 	struct lpfc_rdp_context *rdp_context =
2330*4882a593Smuzhiyun 			(struct lpfc_rdp_context *)(mbox->ctx_ndlp);
2331*4882a593Smuzhiyun 
2332*4882a593Smuzhiyun 	if (bf_get(lpfc_mqe_status, &mbox->u.mqe))
2333*4882a593Smuzhiyun 		goto error_mbuf_free;
2334*4882a593Smuzhiyun 
2335*4882a593Smuzhiyun 	lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a2,
2336*4882a593Smuzhiyun 				DMP_SFF_PAGE_A2_SIZE);
2337*4882a593Smuzhiyun 
2338*4882a593Smuzhiyun 	/* We don't need dma buffer for link stat. */
2339*4882a593Smuzhiyun 	lpfc_mbuf_free(phba, mp->virt, mp->phys);
2340*4882a593Smuzhiyun 	kfree(mp);
2341*4882a593Smuzhiyun 
2342*4882a593Smuzhiyun 	memset(mbox, 0, sizeof(*mbox));
2343*4882a593Smuzhiyun 	lpfc_read_lnk_stat(phba, mbox);
2344*4882a593Smuzhiyun 	mbox->vport = rdp_context->ndlp->vport;
2345*4882a593Smuzhiyun 	mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_link_stat;
2346*4882a593Smuzhiyun 	mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
2347*4882a593Smuzhiyun 	if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == MBX_NOT_FINISHED)
2348*4882a593Smuzhiyun 		goto error_cmd_free;
2349*4882a593Smuzhiyun 
2350*4882a593Smuzhiyun 	return;
2351*4882a593Smuzhiyun 
2352*4882a593Smuzhiyun error_mbuf_free:
2353*4882a593Smuzhiyun 	lpfc_mbuf_free(phba, mp->virt, mp->phys);
2354*4882a593Smuzhiyun 	kfree(mp);
2355*4882a593Smuzhiyun error_cmd_free:
2356*4882a593Smuzhiyun 	lpfc_sli4_mbox_cmd_free(phba, mbox);
2357*4882a593Smuzhiyun 	rdp_context->cmpl(phba, rdp_context, FAILURE);
2358*4882a593Smuzhiyun }
2359*4882a593Smuzhiyun 
2360*4882a593Smuzhiyun void
lpfc_mbx_cmpl_rdp_page_a0(struct lpfc_hba * phba,LPFC_MBOXQ_t * mbox)2361*4882a593Smuzhiyun lpfc_mbx_cmpl_rdp_page_a0(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
2362*4882a593Smuzhiyun {
2363*4882a593Smuzhiyun 	int rc;
2364*4882a593Smuzhiyun 	struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(mbox->ctx_buf);
2365*4882a593Smuzhiyun 	struct lpfc_rdp_context *rdp_context =
2366*4882a593Smuzhiyun 			(struct lpfc_rdp_context *)(mbox->ctx_ndlp);
2367*4882a593Smuzhiyun 
2368*4882a593Smuzhiyun 	if (bf_get(lpfc_mqe_status, &mbox->u.mqe))
2369*4882a593Smuzhiyun 		goto error;
2370*4882a593Smuzhiyun 
2371*4882a593Smuzhiyun 	lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a0,
2372*4882a593Smuzhiyun 				DMP_SFF_PAGE_A0_SIZE);
2373*4882a593Smuzhiyun 
2374*4882a593Smuzhiyun 	memset(mbox, 0, sizeof(*mbox));
2375*4882a593Smuzhiyun 
2376*4882a593Smuzhiyun 	memset(mp->virt, 0, DMP_SFF_PAGE_A2_SIZE);
2377*4882a593Smuzhiyun 	INIT_LIST_HEAD(&mp->list);
2378*4882a593Smuzhiyun 
2379*4882a593Smuzhiyun 	/* save address for completion */
2380*4882a593Smuzhiyun 	mbox->ctx_buf = mp;
2381*4882a593Smuzhiyun 	mbox->vport = rdp_context->ndlp->vport;
2382*4882a593Smuzhiyun 
2383*4882a593Smuzhiyun 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY);
2384*4882a593Smuzhiyun 	bf_set(lpfc_mbx_memory_dump_type3_type,
2385*4882a593Smuzhiyun 		&mbox->u.mqe.un.mem_dump_type3, DMP_LMSD);
2386*4882a593Smuzhiyun 	bf_set(lpfc_mbx_memory_dump_type3_link,
2387*4882a593Smuzhiyun 		&mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port);
2388*4882a593Smuzhiyun 	bf_set(lpfc_mbx_memory_dump_type3_page_no,
2389*4882a593Smuzhiyun 		&mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A2);
2390*4882a593Smuzhiyun 	bf_set(lpfc_mbx_memory_dump_type3_length,
2391*4882a593Smuzhiyun 		&mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A2_SIZE);
2392*4882a593Smuzhiyun 	mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
2393*4882a593Smuzhiyun 	mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
2394*4882a593Smuzhiyun 
2395*4882a593Smuzhiyun 	mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a2;
2396*4882a593Smuzhiyun 	mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
2397*4882a593Smuzhiyun 	rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
2398*4882a593Smuzhiyun 	if (rc == MBX_NOT_FINISHED)
2399*4882a593Smuzhiyun 		goto error;
2400*4882a593Smuzhiyun 
2401*4882a593Smuzhiyun 	return;
2402*4882a593Smuzhiyun 
2403*4882a593Smuzhiyun error:
2404*4882a593Smuzhiyun 	lpfc_mbuf_free(phba, mp->virt, mp->phys);
2405*4882a593Smuzhiyun 	kfree(mp);
2406*4882a593Smuzhiyun 	lpfc_sli4_mbox_cmd_free(phba, mbox);
2407*4882a593Smuzhiyun 	rdp_context->cmpl(phba, rdp_context, FAILURE);
2408*4882a593Smuzhiyun }
2409*4882a593Smuzhiyun 
2410*4882a593Smuzhiyun 
2411*4882a593Smuzhiyun /*
2412*4882a593Smuzhiyun  * lpfc_sli4_dump_sfp_pagea0 - Dump sli4 read SFP Diagnostic.
2413*4882a593Smuzhiyun  * @phba: pointer to the hba structure containing.
2414*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command to initialize.
2415*4882a593Smuzhiyun  *
2416*4882a593Smuzhiyun  * This function create a SLI4 dump mailbox command to dump configure
2417*4882a593Smuzhiyun  * type 3 page 0xA0.
2418*4882a593Smuzhiyun  */
2419*4882a593Smuzhiyun int
lpfc_sli4_dump_page_a0(struct lpfc_hba * phba,struct lpfcMboxq * mbox)2420*4882a593Smuzhiyun lpfc_sli4_dump_page_a0(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
2421*4882a593Smuzhiyun {
2422*4882a593Smuzhiyun 	struct lpfc_dmabuf *mp = NULL;
2423*4882a593Smuzhiyun 
2424*4882a593Smuzhiyun 	memset(mbox, 0, sizeof(*mbox));
2425*4882a593Smuzhiyun 
2426*4882a593Smuzhiyun 	mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2427*4882a593Smuzhiyun 	if (mp)
2428*4882a593Smuzhiyun 		mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
2429*4882a593Smuzhiyun 	if (!mp || !mp->virt) {
2430*4882a593Smuzhiyun 		kfree(mp);
2431*4882a593Smuzhiyun 		lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
2432*4882a593Smuzhiyun 			"3569 dump type 3 page 0xA0 allocation failed\n");
2433*4882a593Smuzhiyun 		return 1;
2434*4882a593Smuzhiyun 	}
2435*4882a593Smuzhiyun 
2436*4882a593Smuzhiyun 	memset(mp->virt, 0, LPFC_BPL_SIZE);
2437*4882a593Smuzhiyun 	INIT_LIST_HEAD(&mp->list);
2438*4882a593Smuzhiyun 
2439*4882a593Smuzhiyun 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY);
2440*4882a593Smuzhiyun 	/* save address for completion */
2441*4882a593Smuzhiyun 	mbox->ctx_buf = mp;
2442*4882a593Smuzhiyun 
2443*4882a593Smuzhiyun 	bf_set(lpfc_mbx_memory_dump_type3_type,
2444*4882a593Smuzhiyun 		&mbox->u.mqe.un.mem_dump_type3, DMP_LMSD);
2445*4882a593Smuzhiyun 	bf_set(lpfc_mbx_memory_dump_type3_link,
2446*4882a593Smuzhiyun 		&mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port);
2447*4882a593Smuzhiyun 	bf_set(lpfc_mbx_memory_dump_type3_page_no,
2448*4882a593Smuzhiyun 		&mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A0);
2449*4882a593Smuzhiyun 	bf_set(lpfc_mbx_memory_dump_type3_length,
2450*4882a593Smuzhiyun 		&mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A0_SIZE);
2451*4882a593Smuzhiyun 	mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
2452*4882a593Smuzhiyun 	mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
2453*4882a593Smuzhiyun 
2454*4882a593Smuzhiyun 	return 0;
2455*4882a593Smuzhiyun }
2456*4882a593Smuzhiyun 
2457*4882a593Smuzhiyun /**
2458*4882a593Smuzhiyun  * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
2459*4882a593Smuzhiyun  * @phba: pointer to the hba structure containing the FCF index and RQ ID.
2460*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command to initialize.
2461*4882a593Smuzhiyun  *
2462*4882a593Smuzhiyun  * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
2463*4882a593Smuzhiyun  * SLI Host uses the command to activate an FCF after it has acquired FCF
2464*4882a593Smuzhiyun  * information via a READ_FCF mailbox command. This mailbox command also is used
2465*4882a593Smuzhiyun  * to indicate where received unsolicited frames from this FCF will be sent. By
2466*4882a593Smuzhiyun  * default this routine will set up the FCF to forward all unsolicited frames
2467*4882a593Smuzhiyun  * the the RQ ID passed in the @phba. This can be overridden by the caller for
2468*4882a593Smuzhiyun  * more complicated setups.
2469*4882a593Smuzhiyun  **/
2470*4882a593Smuzhiyun void
lpfc_reg_fcfi(struct lpfc_hba * phba,struct lpfcMboxq * mbox)2471*4882a593Smuzhiyun lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
2472*4882a593Smuzhiyun {
2473*4882a593Smuzhiyun 	struct lpfc_mbx_reg_fcfi *reg_fcfi;
2474*4882a593Smuzhiyun 
2475*4882a593Smuzhiyun 	memset(mbox, 0, sizeof(*mbox));
2476*4882a593Smuzhiyun 	reg_fcfi = &mbox->u.mqe.un.reg_fcfi;
2477*4882a593Smuzhiyun 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI);
2478*4882a593Smuzhiyun 	if (phba->nvmet_support == 0) {
2479*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi,
2480*4882a593Smuzhiyun 		       phba->sli4_hba.hdr_rq->queue_id);
2481*4882a593Smuzhiyun 		/* Match everything - rq_id0 */
2482*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, 0);
2483*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0);
2484*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi, 0);
2485*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_rctl_mask0, reg_fcfi, 0);
2486*4882a593Smuzhiyun 
2487*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
2488*4882a593Smuzhiyun 
2489*4882a593Smuzhiyun 		/* addr mode is bit wise inverted value of fcf addr_mode */
2490*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_mam, reg_fcfi,
2491*4882a593Smuzhiyun 		       (~phba->fcf.addr_mode) & 0x3);
2492*4882a593Smuzhiyun 	} else {
2493*4882a593Smuzhiyun 		/* This is ONLY for NVMET MRQ == 1 */
2494*4882a593Smuzhiyun 		if (phba->cfg_nvmet_mrq != 1)
2495*4882a593Smuzhiyun 			return;
2496*4882a593Smuzhiyun 
2497*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi,
2498*4882a593Smuzhiyun 		       phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id);
2499*4882a593Smuzhiyun 		/* Match type FCP - rq_id0 */
2500*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, FC_TYPE_FCP);
2501*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0xff);
2502*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi,
2503*4882a593Smuzhiyun 		       FC_RCTL_DD_UNSOL_CMD);
2504*4882a593Smuzhiyun 
2505*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi,
2506*4882a593Smuzhiyun 		       phba->sli4_hba.hdr_rq->queue_id);
2507*4882a593Smuzhiyun 		/* Match everything else - rq_id1 */
2508*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_type_match1, reg_fcfi, 0);
2509*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_type_mask1, reg_fcfi, 0);
2510*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_rctl_match1, reg_fcfi, 0);
2511*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_rctl_mask1, reg_fcfi, 0);
2512*4882a593Smuzhiyun 	}
2513*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
2514*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
2515*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_info_index, reg_fcfi,
2516*4882a593Smuzhiyun 	       phba->fcf.current_rec.fcf_indx);
2517*4882a593Smuzhiyun 	if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) {
2518*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
2519*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi,
2520*4882a593Smuzhiyun 		       phba->fcf.current_rec.vlan_id);
2521*4882a593Smuzhiyun 	}
2522*4882a593Smuzhiyun }
2523*4882a593Smuzhiyun 
2524*4882a593Smuzhiyun /**
2525*4882a593Smuzhiyun  * lpfc_reg_fcfi_mrq - Initialize the REG_FCFI_MRQ mailbox command
2526*4882a593Smuzhiyun  * @phba: pointer to the hba structure containing the FCF index and RQ ID.
2527*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command to initialize.
2528*4882a593Smuzhiyun  * @mode: 0 to register FCFI, 1 to register MRQs
2529*4882a593Smuzhiyun  *
2530*4882a593Smuzhiyun  * The REG_FCFI_MRQ mailbox command supports Fibre Channel Forwarders (FCFs).
2531*4882a593Smuzhiyun  * The SLI Host uses the command to activate an FCF after it has acquired FCF
2532*4882a593Smuzhiyun  * information via a READ_FCF mailbox command. This mailbox command also is used
2533*4882a593Smuzhiyun  * to indicate where received unsolicited frames from this FCF will be sent. By
2534*4882a593Smuzhiyun  * default this routine will set up the FCF to forward all unsolicited frames
2535*4882a593Smuzhiyun  * the the RQ ID passed in the @phba. This can be overridden by the caller for
2536*4882a593Smuzhiyun  * more complicated setups.
2537*4882a593Smuzhiyun  **/
2538*4882a593Smuzhiyun void
lpfc_reg_fcfi_mrq(struct lpfc_hba * phba,struct lpfcMboxq * mbox,int mode)2539*4882a593Smuzhiyun lpfc_reg_fcfi_mrq(struct lpfc_hba *phba, struct lpfcMboxq *mbox, int mode)
2540*4882a593Smuzhiyun {
2541*4882a593Smuzhiyun 	struct lpfc_mbx_reg_fcfi_mrq *reg_fcfi;
2542*4882a593Smuzhiyun 
2543*4882a593Smuzhiyun 	/* This is ONLY for MRQ */
2544*4882a593Smuzhiyun 	if (phba->cfg_nvmet_mrq <= 1)
2545*4882a593Smuzhiyun 		return;
2546*4882a593Smuzhiyun 
2547*4882a593Smuzhiyun 	memset(mbox, 0, sizeof(*mbox));
2548*4882a593Smuzhiyun 	reg_fcfi = &mbox->u.mqe.un.reg_fcfi_mrq;
2549*4882a593Smuzhiyun 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI_MRQ);
2550*4882a593Smuzhiyun 	if (mode == 0) {
2551*4882a593Smuzhiyun 		bf_set(lpfc_reg_fcfi_mrq_info_index, reg_fcfi,
2552*4882a593Smuzhiyun 		       phba->fcf.current_rec.fcf_indx);
2553*4882a593Smuzhiyun 		if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) {
2554*4882a593Smuzhiyun 			bf_set(lpfc_reg_fcfi_mrq_vv, reg_fcfi, 1);
2555*4882a593Smuzhiyun 			bf_set(lpfc_reg_fcfi_mrq_vlan_tag, reg_fcfi,
2556*4882a593Smuzhiyun 			       phba->fcf.current_rec.vlan_id);
2557*4882a593Smuzhiyun 		}
2558*4882a593Smuzhiyun 		return;
2559*4882a593Smuzhiyun 	}
2560*4882a593Smuzhiyun 
2561*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_rq_id0, reg_fcfi,
2562*4882a593Smuzhiyun 	       phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id);
2563*4882a593Smuzhiyun 	/* Match NVME frames of type FCP (protocol NVME) - rq_id0 */
2564*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_type_match0, reg_fcfi, FC_TYPE_FCP);
2565*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_type_mask0, reg_fcfi, 0xff);
2566*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_rctl_match0, reg_fcfi, FC_RCTL_DD_UNSOL_CMD);
2567*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_rctl_mask0, reg_fcfi, 0xff);
2568*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_ptc0, reg_fcfi, 1);
2569*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_pt0, reg_fcfi, 1);
2570*4882a593Smuzhiyun 
2571*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_policy, reg_fcfi, 3); /* NVME connection id */
2572*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_mode, reg_fcfi, 1);
2573*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_filter, reg_fcfi, 1); /* rq_id0 */
2574*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_npairs, reg_fcfi, phba->cfg_nvmet_mrq);
2575*4882a593Smuzhiyun 
2576*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_rq_id1, reg_fcfi,
2577*4882a593Smuzhiyun 	       phba->sli4_hba.hdr_rq->queue_id);
2578*4882a593Smuzhiyun 	/* Match everything - rq_id1 */
2579*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_type_match1, reg_fcfi, 0);
2580*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_type_mask1, reg_fcfi, 0);
2581*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_rctl_match1, reg_fcfi, 0);
2582*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_rctl_mask1, reg_fcfi, 0);
2583*4882a593Smuzhiyun 
2584*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
2585*4882a593Smuzhiyun 	bf_set(lpfc_reg_fcfi_mrq_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
2586*4882a593Smuzhiyun }
2587*4882a593Smuzhiyun 
2588*4882a593Smuzhiyun /**
2589*4882a593Smuzhiyun  * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
2590*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command to initialize.
2591*4882a593Smuzhiyun  * @fcfi: FCFI to be unregistered.
2592*4882a593Smuzhiyun  *
2593*4882a593Smuzhiyun  * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
2594*4882a593Smuzhiyun  * The SLI Host uses the command to inactivate an FCFI.
2595*4882a593Smuzhiyun  **/
2596*4882a593Smuzhiyun void
lpfc_unreg_fcfi(struct lpfcMboxq * mbox,uint16_t fcfi)2597*4882a593Smuzhiyun lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi)
2598*4882a593Smuzhiyun {
2599*4882a593Smuzhiyun 	memset(mbox, 0, sizeof(*mbox));
2600*4882a593Smuzhiyun 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI);
2601*4882a593Smuzhiyun 	bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi);
2602*4882a593Smuzhiyun }
2603*4882a593Smuzhiyun 
2604*4882a593Smuzhiyun /**
2605*4882a593Smuzhiyun  * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
2606*4882a593Smuzhiyun  * @mbox: pointer to lpfc mbox command to initialize.
2607*4882a593Smuzhiyun  * @ndlp: The nodelist structure that describes the RPI to resume.
2608*4882a593Smuzhiyun  *
2609*4882a593Smuzhiyun  * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
2610*4882a593Smuzhiyun  * link event.
2611*4882a593Smuzhiyun  **/
2612*4882a593Smuzhiyun void
lpfc_resume_rpi(struct lpfcMboxq * mbox,struct lpfc_nodelist * ndlp)2613*4882a593Smuzhiyun lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
2614*4882a593Smuzhiyun {
2615*4882a593Smuzhiyun 	struct lpfc_hba *phba = ndlp->phba;
2616*4882a593Smuzhiyun 	struct lpfc_mbx_resume_rpi *resume_rpi;
2617*4882a593Smuzhiyun 
2618*4882a593Smuzhiyun 	memset(mbox, 0, sizeof(*mbox));
2619*4882a593Smuzhiyun 	resume_rpi = &mbox->u.mqe.un.resume_rpi;
2620*4882a593Smuzhiyun 	bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI);
2621*4882a593Smuzhiyun 	bf_set(lpfc_resume_rpi_index, resume_rpi,
2622*4882a593Smuzhiyun 	       phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
2623*4882a593Smuzhiyun 	bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI);
2624*4882a593Smuzhiyun 	resume_rpi->event_tag = ndlp->phba->fc_eventTag;
2625*4882a593Smuzhiyun }
2626*4882a593Smuzhiyun 
2627