blob: 1b40a3bbd1cd6043c08ee6b78ac695c3288529d9 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartcf270812021-04-11 18:31:27 -07004 * Copyright (C) 2017-2021 Broadcom. All Rights Reserved. The term *
James Smart4ae2ebd2018-06-26 08:24:31 -07005 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
James Smart50611572016-03-31 14:12:34 -07006 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * EMULEX and SLI are trademarks of Emulex. *
James Smartd080abe2017-02-12 13:52:39 -08008 * www.broadcom.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04009 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -050010 * *
11 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040012 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
dea31012005-04-17 16:05:31 -050022 *******************************************************************/
23
dea31012005-04-17 16:05:31 -050024#include <linux/blkdev.h>
25#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050027#include <linux/interrupt.h>
28
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -040029#include <scsi/scsi_device.h>
30#include <scsi/scsi_transport_fc.h>
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040031#include <scsi/scsi.h>
James Smart6a9c52c2009-10-02 15:16:51 -040032#include <scsi/fc/fc_fs.h>
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040033
James Smartda0436e2009-05-22 14:51:39 -040034#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050035#include "lpfc_hw.h"
36#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040037#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040038#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050039#include "lpfc_disc.h"
40#include "lpfc_scsi.h"
41#include "lpfc.h"
42#include "lpfc_logmsg.h"
43#include "lpfc_crtn.h"
44#include "lpfc_compat.h"
45
James Smarte59058c2008-08-24 21:49:00 -040046/**
James Smart21e9a0a2009-05-22 14:53:21 -040047 * lpfc_dump_static_vport - Dump HBA's static vport information.
48 * @phba: pointer to lpfc hba data structure.
49 * @pmb: pointer to the driver internal queue element for mailbox command.
50 * @offset: offset for dumping vport info.
51 *
52 * The dump mailbox command provides a method for the device driver to obtain
53 * various types of information from the HBA device.
54 *
55 * This routine prepares the mailbox command for dumping list of static
56 * vports to be created.
57 **/
James Smart1c6834a2009-07-19 10:01:26 -040058int
James Smart21e9a0a2009-05-22 14:53:21 -040059lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
60 uint16_t offset)
61{
62 MAILBOX_t *mb;
James Smart1c6834a2009-07-19 10:01:26 -040063 struct lpfc_dmabuf *mp;
James Smart21e9a0a2009-05-22 14:53:21 -040064
65 mb = &pmb->u.mb;
James Smart21e9a0a2009-05-22 14:53:21 -040066
67 /* Setup to dump vport info region */
68 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
69 mb->mbxCommand = MBX_DUMP_MEMORY;
James Smart21e9a0a2009-05-22 14:53:21 -040070 mb->un.varDmp.type = DMP_NV_PARAMS;
71 mb->un.varDmp.entry_index = offset;
72 mb->un.varDmp.region_id = DMP_REGION_VPORT;
James Smart21e9a0a2009-05-22 14:53:21 -040073 mb->mbxOwner = OWN_HOST;
74
James Smart1c6834a2009-07-19 10:01:26 -040075 /* For SLI3 HBAs data is embedded in mailbox */
76 if (phba->sli_rev != LPFC_SLI_REV4) {
77 mb->un.varDmp.cv = 1;
78 mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t);
79 return 0;
80 }
81
82 /* For SLI4 HBAs driver need to allocate memory */
83 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
84 if (mp)
85 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
86
87 if (!mp || !mp->virt) {
88 kfree(mp);
89 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
90 "2605 lpfc_dump_static_vport: memory"
91 " allocation failed\n");
92 return 1;
93 }
94 memset(mp->virt, 0, LPFC_BPL_SIZE);
95 INIT_LIST_HEAD(&mp->list);
96 /* save address for completion */
James Smart3e1f0712018-11-29 16:09:29 -080097 pmb->ctx_buf = (uint8_t *)mp;
James Smart1c6834a2009-07-19 10:01:26 -040098 mb->un.varWords[3] = putPaddrLow(mp->phys);
99 mb->un.varWords[4] = putPaddrHigh(mp->phys);
100 mb->un.varDmp.sli4_length = sizeof(struct static_vport_info);
101
102 return 0;
James Smart21e9a0a2009-05-22 14:53:21 -0400103}
104
105/**
James Smarta0c87cb2009-07-19 10:01:10 -0400106 * lpfc_down_link - Bring down HBAs link.
James Smarte59058c2008-08-24 21:49:00 -0400107 * @phba: pointer to lpfc hba data structure.
108 * @pmb: pointer to the driver internal queue element for mailbox command.
James Smarta0c87cb2009-07-19 10:01:10 -0400109 *
110 * This routine prepares a mailbox command to bring down HBA link.
111 **/
112void
113lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
114{
115 MAILBOX_t *mb;
116 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
117 mb = &pmb->u.mb;
118 mb->mbxCommand = MBX_DOWN_LINK;
119 mb->mbxOwner = OWN_HOST;
120}
121
122/**
123 * lpfc_dump_mem - Prepare a mailbox command for reading a region.
124 * @phba: pointer to lpfc hba data structure.
125 * @pmb: pointer to the driver internal queue element for mailbox command.
126 * @offset: offset into the region.
127 * @region_id: config region id.
James Smarte59058c2008-08-24 21:49:00 -0400128 *
129 * The dump mailbox command provides a method for the device driver to obtain
130 * various types of information from the HBA device.
131 *
James Smarta0c87cb2009-07-19 10:01:10 -0400132 * This routine prepares the mailbox command for dumping HBA's config region.
James Smarte59058c2008-08-24 21:49:00 -0400133 **/
dea31012005-04-17 16:05:31 -0500134void
James Smarta0c87cb2009-07-19 10:01:10 -0400135lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset,
136 uint16_t region_id)
dea31012005-04-17 16:05:31 -0500137{
138 MAILBOX_t *mb;
139 void *ctx;
140
James Smart04c68492009-05-22 14:52:52 -0400141 mb = &pmb->u.mb;
James Smart3e1f0712018-11-29 16:09:29 -0800142 ctx = pmb->ctx_buf;
dea31012005-04-17 16:05:31 -0500143
144 /* Setup to dump VPD region */
145 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
146 mb->mbxCommand = MBX_DUMP_MEMORY;
147 mb->un.varDmp.cv = 1;
148 mb->un.varDmp.type = DMP_NV_PARAMS;
149 mb->un.varDmp.entry_index = offset;
James Smarta0c87cb2009-07-19 10:01:10 -0400150 mb->un.varDmp.region_id = region_id;
dea31012005-04-17 16:05:31 -0500151 mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
152 mb->un.varDmp.co = 0;
153 mb->un.varDmp.resp_offset = 0;
James Smart3e1f0712018-11-29 16:09:29 -0800154 pmb->ctx_buf = ctx;
dea31012005-04-17 16:05:31 -0500155 mb->mbxOwner = OWN_HOST;
156 return;
157}
158
James Smarte59058c2008-08-24 21:49:00 -0400159/**
James Smart3621a712009-04-06 18:47:14 -0400160 * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
James Smart97207482008-12-04 22:39:19 -0500161 * @phba: pointer to lpfc hba data structure.
162 * @pmb: pointer to the driver internal queue element for mailbox command.
James Smart3621a712009-04-06 18:47:14 -0400163 *
James Smart97207482008-12-04 22:39:19 -0500164 * This function create a dump memory mailbox command to dump wake up
165 * parameters.
166 */
167void
168lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
169{
170 MAILBOX_t *mb;
171 void *ctx;
172
James Smart04c68492009-05-22 14:52:52 -0400173 mb = &pmb->u.mb;
James Smart97207482008-12-04 22:39:19 -0500174 /* Save context so that we can restore after memset */
James Smart3e1f0712018-11-29 16:09:29 -0800175 ctx = pmb->ctx_buf;
James Smart97207482008-12-04 22:39:19 -0500176
177 /* Setup to dump VPD region */
178 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
179 mb->mbxCommand = MBX_DUMP_MEMORY;
180 mb->mbxOwner = OWN_HOST;
181 mb->un.varDmp.cv = 1;
182 mb->un.varDmp.type = DMP_NV_PARAMS;
James Smart1d1c2962013-07-15 18:33:04 -0400183 if (phba->sli_rev < LPFC_SLI_REV4)
184 mb->un.varDmp.entry_index = 0;
James Smart97207482008-12-04 22:39:19 -0500185 mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
186 mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
187 mb->un.varDmp.co = 0;
188 mb->un.varDmp.resp_offset = 0;
James Smart3e1f0712018-11-29 16:09:29 -0800189 pmb->ctx_buf = ctx;
James Smart97207482008-12-04 22:39:19 -0500190 return;
191}
192
193/**
James Smart3621a712009-04-06 18:47:14 -0400194 * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
James Smarte59058c2008-08-24 21:49:00 -0400195 * @phba: pointer to lpfc hba data structure.
196 * @pmb: pointer to the driver internal queue element for mailbox command.
197 *
198 * The read NVRAM mailbox command returns the HBA's non-volatile parameters
199 * that are used as defaults when the Fibre Channel link is brought on-line.
200 *
201 * This routine prepares the mailbox command for reading information stored
202 * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
203 **/
dea31012005-04-17 16:05:31 -0500204void
205lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
206{
207 MAILBOX_t *mb;
208
James Smart04c68492009-05-22 14:52:52 -0400209 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500210 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
211 mb->mbxCommand = MBX_READ_NV;
212 mb->mbxOwner = OWN_HOST;
213 return;
214}
215
James Smarte59058c2008-08-24 21:49:00 -0400216/**
James Smart3621a712009-04-06 18:47:14 -0400217 * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
James Smarte59058c2008-08-24 21:49:00 -0400218 * @phba: pointer to lpfc hba data structure.
219 * @pmb: pointer to the driver internal queue element for mailbox command.
220 * @ring: ring number for the asynchronous event to be configured.
221 *
222 * The asynchronous event enable mailbox command is used to enable the
223 * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
224 * specifies the default ring to which events are posted.
225 *
226 * This routine prepares the mailbox command for enabling HBA asynchronous
227 * event support on a IOCB ring.
228 **/
James Smart57127f12007-10-27 13:37:05 -0400229void
230lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
231 uint32_t ring)
232{
233 MAILBOX_t *mb;
234
James Smart04c68492009-05-22 14:52:52 -0400235 mb = &pmb->u.mb;
James Smart57127f12007-10-27 13:37:05 -0400236 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
237 mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
238 mb->un.varCfgAsyncEvent.ring = ring;
239 mb->mbxOwner = OWN_HOST;
240 return;
241}
242
James Smarte59058c2008-08-24 21:49:00 -0400243/**
James Smart3621a712009-04-06 18:47:14 -0400244 * lpfc_heart_beat - Prepare a mailbox command for heart beat
James Smarte59058c2008-08-24 21:49:00 -0400245 * @phba: pointer to lpfc hba data structure.
246 * @pmb: pointer to the driver internal queue element for mailbox command.
247 *
248 * The heart beat mailbox command is used to detect an unresponsive HBA, which
249 * is defined as any device where no error attention is sent and both mailbox
250 * and rings are not processed.
251 *
252 * This routine prepares the mailbox command for issuing a heart beat in the
253 * form of mailbox command to the HBA. The timely completion of the heart
254 * beat mailbox command indicates the health of the HBA.
255 **/
James Smart858c9f62007-06-17 19:56:39 -0500256void
257lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
258{
259 MAILBOX_t *mb;
260
James Smart04c68492009-05-22 14:52:52 -0400261 mb = &pmb->u.mb;
James Smart858c9f62007-06-17 19:56:39 -0500262 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
263 mb->mbxCommand = MBX_HEARTBEAT;
264 mb->mbxOwner = OWN_HOST;
265 return;
266}
267
James Smarte59058c2008-08-24 21:49:00 -0400268/**
James Smart76a95d72010-11-20 23:11:48 -0500269 * lpfc_read_topology - Prepare a mailbox command for reading HBA topology
James Smarte59058c2008-08-24 21:49:00 -0400270 * @phba: pointer to lpfc hba data structure.
271 * @pmb: pointer to the driver internal queue element for mailbox command.
272 * @mp: DMA buffer memory for reading the link attention information into.
273 *
James Smart76a95d72010-11-20 23:11:48 -0500274 * The read topology mailbox command is issued to read the link topology
275 * information indicated by the HBA port when the Link Event bit of the Host
276 * Attention (HSTATT) register is set to 1 (For SLI-3) or when an FC Link
277 * Attention ACQE is received from the port (For SLI-4). A Link Event
James Smarte59058c2008-08-24 21:49:00 -0400278 * Attention occurs based on an exception detected at the Fibre Channel link
279 * interface.
280 *
James Smart76a95d72010-11-20 23:11:48 -0500281 * This routine prepares the mailbox command for reading HBA link topology
James Smarte59058c2008-08-24 21:49:00 -0400282 * information. A DMA memory has been set aside and address passed to the
283 * HBA through @mp for the HBA to DMA link attention information into the
284 * memory as part of the execution of the mailbox command.
285 *
286 * Return codes
287 * 0 - Success (currently always return 0)
288 **/
dea31012005-04-17 16:05:31 -0500289int
James Smart76a95d72010-11-20 23:11:48 -0500290lpfc_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
291 struct lpfc_dmabuf *mp)
dea31012005-04-17 16:05:31 -0500292{
293 MAILBOX_t *mb;
dea31012005-04-17 16:05:31 -0500294
James Smart04c68492009-05-22 14:52:52 -0400295 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500296 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
297
298 INIT_LIST_HEAD(&mp->list);
James Smart76a95d72010-11-20 23:11:48 -0500299 mb->mbxCommand = MBX_READ_TOPOLOGY;
300 mb->un.varReadTop.lilpBde64.tus.f.bdeSize = LPFC_ALPA_MAP_SIZE;
301 mb->un.varReadTop.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
302 mb->un.varReadTop.lilpBde64.addrLow = putPaddrLow(mp->phys);
dea31012005-04-17 16:05:31 -0500303
304 /* Save address for later completion and set the owner to host so that
305 * the FW knows this mailbox is available for processing.
306 */
James Smart3e1f0712018-11-29 16:09:29 -0800307 pmb->ctx_buf = (uint8_t *)mp;
dea31012005-04-17 16:05:31 -0500308 mb->mbxOwner = OWN_HOST;
James Smart92d7f7b2007-06-17 19:56:38 -0500309 return (0);
dea31012005-04-17 16:05:31 -0500310}
311
James Smarte59058c2008-08-24 21:49:00 -0400312/**
James Smart3621a712009-04-06 18:47:14 -0400313 * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
James Smarte59058c2008-08-24 21:49:00 -0400314 * @phba: pointer to lpfc hba data structure.
315 * @pmb: pointer to the driver internal queue element for mailbox command.
316 *
317 * The clear link attention mailbox command is issued to clear the link event
318 * attention condition indicated by the Link Event bit of the Host Attention
319 * (HSTATT) register. The link event attention condition is cleared only if
320 * the event tag specified matches that of the current link event counter.
321 * The current event tag is read using the read link attention event mailbox
322 * command.
323 *
324 * This routine prepares the mailbox command for clearing HBA link attention
325 * information.
326 **/
dea31012005-04-17 16:05:31 -0500327void
328lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
329{
330 MAILBOX_t *mb;
331
James Smart04c68492009-05-22 14:52:52 -0400332 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500333 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
334
335 mb->un.varClearLA.eventTag = phba->fc_eventTag;
336 mb->mbxCommand = MBX_CLEAR_LA;
337 mb->mbxOwner = OWN_HOST;
338 return;
339}
340
James Smarte59058c2008-08-24 21:49:00 -0400341/**
James Smart3621a712009-04-06 18:47:14 -0400342 * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
James Smarte59058c2008-08-24 21:49:00 -0400343 * @phba: pointer to lpfc hba data structure.
344 * @pmb: pointer to the driver internal queue element for mailbox command.
345 *
346 * The configure link mailbox command is used before the initialize link
347 * mailbox command to override default value and to configure link-oriented
348 * parameters such as DID address and various timers. Typically, this
349 * command would be used after an F_Port login to set the returned DID address
350 * and the fabric timeout values. This command is not valid before a configure
351 * port command has configured the HBA port.
352 *
353 * This routine prepares the mailbox command for configuring link on a HBA.
354 **/
dea31012005-04-17 16:05:31 -0500355void
356lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
357{
James Smart2e0fef82007-06-17 19:56:36 -0500358 struct lpfc_vport *vport = phba->pport;
James Smart04c68492009-05-22 14:52:52 -0400359 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500360 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
361
362 /* NEW_FEATURE
363 * SLI-2, Coalescing Response Feature.
364 */
James Smart1d1c2962013-07-15 18:33:04 -0400365 if (phba->cfg_cr_delay && (phba->sli_rev < LPFC_SLI_REV4)) {
dea31012005-04-17 16:05:31 -0500366 mb->un.varCfgLnk.cr = 1;
367 mb->un.varCfgLnk.ci = 1;
368 mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
369 mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
370 }
371
James Smart2e0fef82007-06-17 19:56:36 -0500372 mb->un.varCfgLnk.myId = vport->fc_myDID;
dea31012005-04-17 16:05:31 -0500373 mb->un.varCfgLnk.edtov = phba->fc_edtov;
374 mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
375 mb->un.varCfgLnk.ratov = phba->fc_ratov;
376 mb->un.varCfgLnk.rttov = phba->fc_rttov;
377 mb->un.varCfgLnk.altov = phba->fc_altov;
378 mb->un.varCfgLnk.crtov = phba->fc_crtov;
James Smart44fd7fe2017-08-23 16:55:47 -0700379 mb->un.varCfgLnk.cscn = 0;
380 if (phba->bbcredit_support && phba->cfg_enable_bbcr) {
381 mb->un.varCfgLnk.cscn = 1;
382 mb->un.varCfgLnk.bbscn = bf_get(lpfc_bbscn_def,
383 &phba->sli4_hba.bbscn_params);
384 }
dea31012005-04-17 16:05:31 -0500385
James Smart1d1c2962013-07-15 18:33:04 -0400386 if (phba->cfg_ack0 && (phba->sli_rev < LPFC_SLI_REV4))
dea31012005-04-17 16:05:31 -0500387 mb->un.varCfgLnk.ack0_enable = 1;
388
389 mb->mbxCommand = MBX_CONFIG_LINK;
390 mb->mbxOwner = OWN_HOST;
391 return;
392}
393
James Smarte59058c2008-08-24 21:49:00 -0400394/**
James Smart3621a712009-04-06 18:47:14 -0400395 * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
James Smart93996272008-08-24 21:50:30 -0400396 * @phba: pointer to lpfc hba data structure.
397 * @pmb: pointer to the driver internal queue element for mailbox command.
398 *
399 * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
400 * MSI-X multi-message interrupt vector association to interrupt attention
401 * conditions.
402 *
403 * Return codes
404 * 0 - Success
405 * -EINVAL - Failure
406 **/
407int
408lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
409{
James Smart04c68492009-05-22 14:52:52 -0400410 MAILBOX_t *mb = &pmb->u.mb;
James Smart93996272008-08-24 21:50:30 -0400411 uint32_t attentionConditions[2];
412
413 /* Sanity check */
414 if (phba->cfg_use_msi != 2) {
415 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
416 "0475 Not configured for supporting MSI-X "
417 "cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
418 return -EINVAL;
419 }
420
421 if (phba->sli_rev < 3) {
422 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
423 "0476 HBA not supporting SLI-3 or later "
424 "SLI Revision: 0x%x\n", phba->sli_rev);
425 return -EINVAL;
426 }
427
428 /* Clear mailbox command fields */
429 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
430
431 /*
432 * SLI-3, Message Signaled Interrupt Fearure.
433 */
434
435 /* Multi-message attention configuration */
436 attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
437 HA_LATT | HA_MBATT);
438 attentionConditions[1] = 0;
439
440 mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
441 mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
442
443 /*
444 * Set up message number to HA bit association
445 */
446#ifdef __BIG_ENDIAN_BITFIELD
447 /* RA0 (FCP Ring) */
448 mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
449 /* RA1 (Other Protocol Extra Ring) */
450 mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
451#else /* __LITTLE_ENDIAN_BITFIELD */
452 /* RA0 (FCP Ring) */
453 mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
454 /* RA1 (Other Protocol Extra Ring) */
455 mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
456#endif
457 /* Multi-message interrupt autoclear configuration*/
458 mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
459 mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
460
461 /* For now, HBA autoclear does not work reliably, disable it */
462 mb->un.varCfgMSI.autoClearHA[0] = 0;
463 mb->un.varCfgMSI.autoClearHA[1] = 0;
464
465 /* Set command and owner bit */
466 mb->mbxCommand = MBX_CONFIG_MSI;
467 mb->mbxOwner = OWN_HOST;
468
469 return 0;
470}
471
472/**
James Smart3621a712009-04-06 18:47:14 -0400473 * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
James Smarte59058c2008-08-24 21:49:00 -0400474 * @phba: pointer to lpfc hba data structure.
475 * @pmb: pointer to the driver internal queue element for mailbox command.
476 * @topology: the link topology for the link to be initialized to.
477 * @linkspeed: the link speed for the link to be initialized to.
478 *
479 * The initialize link mailbox command is used to initialize the Fibre
480 * Channel link. This command must follow a configure port command that
481 * establishes the mode of operation.
482 *
483 * This routine prepares the mailbox command for initializing link on a HBA
484 * with the specified link topology and speed.
485 **/
dea31012005-04-17 16:05:31 -0500486void
487lpfc_init_link(struct lpfc_hba * phba,
488 LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
489{
490 lpfc_vpd_t *vpd;
dea31012005-04-17 16:05:31 -0500491 MAILBOX_t *mb;
492
James Smart04c68492009-05-22 14:52:52 -0400493 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500494 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
495
dea31012005-04-17 16:05:31 -0500496 switch (topology) {
497 case FLAGS_TOPOLOGY_MODE_LOOP_PT:
498 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
499 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
500 break;
501 case FLAGS_TOPOLOGY_MODE_PT_PT:
502 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
503 break;
504 case FLAGS_TOPOLOGY_MODE_LOOP:
505 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
506 break;
507 case FLAGS_TOPOLOGY_MODE_PT_LOOP:
508 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
509 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
510 break;
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500511 case FLAGS_LOCAL_LB:
512 mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
513 break;
dea31012005-04-17 16:05:31 -0500514 }
515
James Smart76558b22018-11-29 16:09:38 -0800516 if ((phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC ||
517 phba->pcidev->device == PCI_DEVICE_ID_LANCER_G7_FC) &&
James Smart83c6cb12019-10-18 14:18:30 -0700518 !(phba->sli4_hba.pc_sli4_params.pls) &&
James Smart76558b22018-11-29 16:09:38 -0800519 mb->un.varInitLnk.link_flags & FLAGS_TOPOLOGY_MODE_LOOP) {
James Smartd38dd522015-08-31 16:48:17 -0400520 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
521 phba->cfg_topology = FLAGS_TOPOLOGY_MODE_PT_PT;
522 }
523
James Smart4b0b91d2006-04-15 11:53:00 -0400524 /* Enable asynchronous ABTS responses from firmware */
525 mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
526
dea31012005-04-17 16:05:31 -0500527 /* NEW_FEATURE
528 * Setting up the link speed
529 */
530 vpd = &phba->vpd;
531 if (vpd->rev.feaLevelHigh >= 0x02){
James Smart92d7f7b2007-06-17 19:56:38 -0500532 switch(linkspeed){
James Smart76a95d72010-11-20 23:11:48 -0500533 case LPFC_USER_LINK_SPEED_1G:
534 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
535 mb->un.varInitLnk.link_speed = LINK_SPEED_1G;
dea31012005-04-17 16:05:31 -0500536 break;
James Smart76a95d72010-11-20 23:11:48 -0500537 case LPFC_USER_LINK_SPEED_2G:
538 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
539 mb->un.varInitLnk.link_speed = LINK_SPEED_2G;
540 break;
541 case LPFC_USER_LINK_SPEED_4G:
542 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
543 mb->un.varInitLnk.link_speed = LINK_SPEED_4G;
544 break;
545 case LPFC_USER_LINK_SPEED_8G:
546 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
547 mb->un.varInitLnk.link_speed = LINK_SPEED_8G;
548 break;
549 case LPFC_USER_LINK_SPEED_10G:
550 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
551 mb->un.varInitLnk.link_speed = LINK_SPEED_10G;
552 break;
553 case LPFC_USER_LINK_SPEED_16G:
554 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
555 mb->un.varInitLnk.link_speed = LINK_SPEED_16G;
556 break;
James Smartd38dd522015-08-31 16:48:17 -0400557 case LPFC_USER_LINK_SPEED_32G:
558 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
559 mb->un.varInitLnk.link_speed = LINK_SPEED_32G;
560 break;
James Smartfbd8a6b2018-02-22 08:18:45 -0800561 case LPFC_USER_LINK_SPEED_64G:
562 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
563 mb->un.varInitLnk.link_speed = LINK_SPEED_64G;
564 break;
James Smart76a95d72010-11-20 23:11:48 -0500565 case LPFC_USER_LINK_SPEED_AUTO:
566 default:
567 mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
dea31012005-04-17 16:05:31 -0500568 break;
569 }
570
571 }
572 else
573 mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
574
575 mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
576 mb->mbxOwner = OWN_HOST;
577 mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
578 return;
579}
580
James Smarte59058c2008-08-24 21:49:00 -0400581/**
James Smart3621a712009-04-06 18:47:14 -0400582 * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
James Smarte59058c2008-08-24 21:49:00 -0400583 * @phba: pointer to lpfc hba data structure.
584 * @pmb: pointer to the driver internal queue element for mailbox command.
585 * @vpi: virtual N_Port identifier.
586 *
587 * The read service parameter mailbox command is used to read the HBA port
588 * service parameters. The service parameters are read into the buffer
589 * specified directly by a BDE in the mailbox command. These service
590 * parameters may then be used to build the payload of an N_Port/F_POrt
591 * login request and reply (LOGI/ACC).
592 *
593 * This routine prepares the mailbox command for reading HBA port service
594 * parameters. The DMA memory is allocated in this function and the addresses
595 * are populated into the mailbox command for the HBA to DMA the service
596 * parameters into.
597 *
598 * Return codes
599 * 0 - Success
600 * 1 - DMA memory allocation failed
601 **/
dea31012005-04-17 16:05:31 -0500602int
James Smart92d7f7b2007-06-17 19:56:38 -0500603lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
dea31012005-04-17 16:05:31 -0500604{
605 struct lpfc_dmabuf *mp;
606 MAILBOX_t *mb;
dea31012005-04-17 16:05:31 -0500607
James Smart04c68492009-05-22 14:52:52 -0400608 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500609 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
610
611 mb->mbxOwner = OWN_HOST;
612
613 /* Get a buffer to hold the HBAs Service Parameters */
614
James Smart98c9ea52007-10-27 13:37:33 -0400615 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
616 if (mp)
617 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
618 if (!mp || !mp->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800619 kfree(mp);
dea31012005-04-17 16:05:31 -0500620 mb->mbxCommand = MBX_READ_SPARM64;
621 /* READ_SPARAM: no buffers */
James Smarte8b62012007-08-02 11:10:09 -0400622 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
623 "0301 READ_SPARAM: no buffers\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500624 return (1);
dea31012005-04-17 16:05:31 -0500625 }
626 INIT_LIST_HEAD(&mp->list);
627 mb->mbxCommand = MBX_READ_SPARM64;
628 mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
629 mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
630 mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
James Smart6d368e52011-05-24 11:44:12 -0400631 if (phba->sli_rev >= LPFC_SLI_REV3)
632 mb->un.varRdSparm.vpi = phba->vpi_ids[vpi];
dea31012005-04-17 16:05:31 -0500633
634 /* save address for completion */
James Smart3e1f0712018-11-29 16:09:29 -0800635 pmb->ctx_buf = mp;
dea31012005-04-17 16:05:31 -0500636
James Smart92d7f7b2007-06-17 19:56:38 -0500637 return (0);
dea31012005-04-17 16:05:31 -0500638}
639
James Smarte59058c2008-08-24 21:49:00 -0400640/**
James Smart3621a712009-04-06 18:47:14 -0400641 * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
James Smarte59058c2008-08-24 21:49:00 -0400642 * @phba: pointer to lpfc hba data structure.
643 * @vpi: virtual N_Port identifier.
644 * @did: remote port identifier.
645 * @pmb: pointer to the driver internal queue element for mailbox command.
646 *
647 * The unregister DID mailbox command is used to unregister an N_Port/F_Port
648 * login for an unknown RPI by specifying the DID of a remote port. This
649 * command frees an RPI context in the HBA port. This has the effect of
650 * performing an implicit N_Port/F_Port logout.
651 *
652 * This routine prepares the mailbox command for unregistering a remote
653 * N_Port/F_Port (DID) login.
654 **/
dea31012005-04-17 16:05:31 -0500655void
James Smart92d7f7b2007-06-17 19:56:38 -0500656lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
657 LPFC_MBOXQ_t * pmb)
dea31012005-04-17 16:05:31 -0500658{
659 MAILBOX_t *mb;
660
James Smart04c68492009-05-22 14:52:52 -0400661 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500662 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
663
664 mb->un.varUnregDID.did = did;
James Smart92d7f7b2007-06-17 19:56:38 -0500665 mb->un.varUnregDID.vpi = vpi;
James Smart6d368e52011-05-24 11:44:12 -0400666 if ((vpi != 0xffff) &&
667 (phba->sli_rev == LPFC_SLI_REV4))
668 mb->un.varUnregDID.vpi = phba->vpi_ids[vpi];
dea31012005-04-17 16:05:31 -0500669
670 mb->mbxCommand = MBX_UNREG_D_ID;
671 mb->mbxOwner = OWN_HOST;
672 return;
673}
674
James Smarte59058c2008-08-24 21:49:00 -0400675/**
James Smart3621a712009-04-06 18:47:14 -0400676 * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
James Smarte59058c2008-08-24 21:49:00 -0400677 * @phba: pointer to lpfc hba data structure.
678 * @pmb: pointer to the driver internal queue element for mailbox command.
679 *
680 * The read configuration mailbox command is used to read the HBA port
681 * configuration parameters. This mailbox command provides a method for
682 * seeing any parameters that may have changed via various configuration
683 * mailbox commands.
684 *
685 * This routine prepares the mailbox command for reading out HBA configuration
686 * parameters.
687 **/
dea31012005-04-17 16:05:31 -0500688void
689lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
690{
691 MAILBOX_t *mb;
692
James Smart04c68492009-05-22 14:52:52 -0400693 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500694 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
695
696 mb->mbxCommand = MBX_READ_CONFIG;
697 mb->mbxOwner = OWN_HOST;
698 return;
699}
700
James Smarte59058c2008-08-24 21:49:00 -0400701/**
James Smart3621a712009-04-06 18:47:14 -0400702 * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
James Smarte59058c2008-08-24 21:49:00 -0400703 * @phba: pointer to lpfc hba data structure.
704 * @pmb: pointer to the driver internal queue element for mailbox command.
705 *
706 * The read link status mailbox command is used to read the link status from
707 * the HBA. Link status includes all link-related error counters. These
708 * counters are maintained by the HBA and originated in the link hardware
709 * unit. Note that all of these counters wrap.
710 *
711 * This routine prepares the mailbox command for reading out HBA link status.
712 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -0500713void
714lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
715{
716 MAILBOX_t *mb;
717
James Smart04c68492009-05-22 14:52:52 -0400718 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -0500719 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
720
721 mb->mbxCommand = MBX_READ_LNK_STAT;
722 mb->mbxOwner = OWN_HOST;
723 return;
724}
725
James Smarte59058c2008-08-24 21:49:00 -0400726/**
James Smart04c68492009-05-22 14:52:52 -0400727 * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
James Smarte59058c2008-08-24 21:49:00 -0400728 * @phba: pointer to lpfc hba data structure.
729 * @vpi: virtual N_Port identifier.
730 * @did: remote port identifier.
731 * @param: pointer to memory holding the server parameters.
732 * @pmb: pointer to the driver internal queue element for mailbox command.
James Smart40426292010-12-15 17:58:10 -0500733 * @rpi: the rpi to use in the registration (usually only used for SLI4.
James Smarte59058c2008-08-24 21:49:00 -0400734 *
735 * The registration login mailbox command is used to register an N_Port or
736 * F_Port login. This registration allows the HBA to cache the remote N_Port
737 * service parameters internally and thereby make the appropriate FC-2
738 * decisions. The remote port service parameters are handed off by the driver
739 * to the HBA using a descriptor entry that directly identifies a buffer in
740 * host memory. In exchange, the HBA returns an RPI identifier.
741 *
742 * This routine prepares the mailbox command for registering remote port login.
743 * The function allocates DMA buffer for passing the service parameters to the
744 * HBA with the mailbox command.
745 *
746 * Return codes
747 * 0 - Success
748 * 1 - DMA memory allocation failed
749 **/
dea31012005-04-17 16:05:31 -0500750int
James Smart04c68492009-05-22 14:52:52 -0400751lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
James Smart40426292010-12-15 17:58:10 -0500752 uint8_t *param, LPFC_MBOXQ_t *pmb, uint16_t rpi)
dea31012005-04-17 16:05:31 -0500753{
James Smart04c68492009-05-22 14:52:52 -0400754 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500755 uint8_t *sparam;
756 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -0500757
dea31012005-04-17 16:05:31 -0500758 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
759
760 mb->un.varRegLogin.rpi = 0;
James Smart6d368e52011-05-24 11:44:12 -0400761 if (phba->sli_rev == LPFC_SLI_REV4)
762 mb->un.varRegLogin.rpi = phba->sli4_hba.rpi_ids[rpi];
763 if (phba->sli_rev >= LPFC_SLI_REV3)
764 mb->un.varRegLogin.vpi = phba->vpi_ids[vpi];
dea31012005-04-17 16:05:31 -0500765 mb->un.varRegLogin.did = did;
dea31012005-04-17 16:05:31 -0500766 mb->mbxOwner = OWN_HOST;
dea31012005-04-17 16:05:31 -0500767 /* Get a buffer to hold NPorts Service Parameters */
James Smart98c9ea52007-10-27 13:37:33 -0400768 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
769 if (mp)
770 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
771 if (!mp || !mp->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800772 kfree(mp);
dea31012005-04-17 16:05:31 -0500773 mb->mbxCommand = MBX_REG_LOGIN64;
774 /* REG_LOGIN: no buffers */
James Smart92d7f7b2007-06-17 19:56:38 -0500775 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400776 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
James Smart40426292010-12-15 17:58:10 -0500777 "rpi x%x\n", vpi, did, rpi);
James Smart6d368e52011-05-24 11:44:12 -0400778 return 1;
dea31012005-04-17 16:05:31 -0500779 }
780 INIT_LIST_HEAD(&mp->list);
781 sparam = mp->virt;
782
783 /* Copy param's into a new buffer */
784 memcpy(sparam, param, sizeof (struct serv_parm));
785
786 /* save address for completion */
James Smart3e1f0712018-11-29 16:09:29 -0800787 pmb->ctx_buf = (uint8_t *)mp;
dea31012005-04-17 16:05:31 -0500788
789 mb->mbxCommand = MBX_REG_LOGIN64;
790 mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
791 mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
792 mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
793
James Smart6d368e52011-05-24 11:44:12 -0400794 return 0;
dea31012005-04-17 16:05:31 -0500795}
796
James Smarte59058c2008-08-24 21:49:00 -0400797/**
James Smart3621a712009-04-06 18:47:14 -0400798 * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
James Smarte59058c2008-08-24 21:49:00 -0400799 * @phba: pointer to lpfc hba data structure.
800 * @vpi: virtual N_Port identifier.
801 * @rpi: remote port identifier
802 * @pmb: pointer to the driver internal queue element for mailbox command.
803 *
804 * The unregistration login mailbox command is used to unregister an N_Port
805 * or F_Port login. This command frees an RPI context in the HBA. It has the
806 * effect of performing an implicit N_Port/F_Port logout.
807 *
808 * This routine prepares the mailbox command for unregistering remote port
809 * login.
James Smart6d368e52011-05-24 11:44:12 -0400810 *
811 * For SLI4 ports, the rpi passed to this function must be the physical
812 * rpi value, not the logical index.
James Smarte59058c2008-08-24 21:49:00 -0400813 **/
dea31012005-04-17 16:05:31 -0500814void
James Smart92d7f7b2007-06-17 19:56:38 -0500815lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
816 LPFC_MBOXQ_t * pmb)
dea31012005-04-17 16:05:31 -0500817{
818 MAILBOX_t *mb;
819
James Smart04c68492009-05-22 14:52:52 -0400820 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500821 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
822
James Smart6d368e52011-05-24 11:44:12 -0400823 mb->un.varUnregLogin.rpi = rpi;
dea31012005-04-17 16:05:31 -0500824 mb->un.varUnregLogin.rsvd1 = 0;
James Smart6d368e52011-05-24 11:44:12 -0400825 if (phba->sli_rev >= LPFC_SLI_REV3)
826 mb->un.varUnregLogin.vpi = phba->vpi_ids[vpi];
dea31012005-04-17 16:05:31 -0500827
828 mb->mbxCommand = MBX_UNREG_LOGIN;
829 mb->mbxOwner = OWN_HOST;
James Smart04c68492009-05-22 14:52:52 -0400830
dea31012005-04-17 16:05:31 -0500831 return;
832}
833
James Smarte59058c2008-08-24 21:49:00 -0400834/**
James Smart5af5eee2010-10-22 11:06:38 -0400835 * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA.
836 * @vport: pointer to a vport object.
837 *
838 * This routine sends mailbox command to unregister all active RPIs for
839 * a vport.
840 **/
841void
842lpfc_sli4_unreg_all_rpis(struct lpfc_vport *vport)
843{
844 struct lpfc_hba *phba = vport->phba;
845 LPFC_MBOXQ_t *mbox;
846 int rc;
847
848 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
849 if (mbox) {
James Smart6d368e52011-05-24 11:44:12 -0400850 /*
851 * For SLI4 functions, the rpi field is overloaded for
852 * the vport context unreg all. This routine passes
853 * 0 for the rpi field in lpfc_unreg_login for compatibility
854 * with SLI3 and then overrides the rpi field with the
855 * expected value for SLI4.
856 */
857 lpfc_unreg_login(phba, vport->vpi, phba->vpi_ids[vport->vpi],
858 mbox);
859 mbox->u.mb.un.varUnregLogin.rsvd1 = 0x4000;
James Smart5af5eee2010-10-22 11:06:38 -0400860 mbox->vport = vport;
861 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart3e1f0712018-11-29 16:09:29 -0800862 mbox->ctx_ndlp = NULL;
James Smart5af5eee2010-10-22 11:06:38 -0400863 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
864 if (rc == MBX_NOT_FINISHED)
865 mempool_free(mbox, phba->mbox_mem_pool);
866 }
867}
868
869/**
James Smart3621a712009-04-06 18:47:14 -0400870 * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
Lee Jones012d0192020-07-23 13:24:24 +0100871 * @vport: pointer to a vport object.
James Smarte59058c2008-08-24 21:49:00 -0400872 * @pmb: pointer to the driver internal queue element for mailbox command.
873 *
874 * The registration vport identifier mailbox command is used to activate a
875 * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
876 * N_Port_ID against the information in the selected virtual N_Port context
877 * block and marks it active to allow normal processing of IOCB commands and
878 * received unsolicited exchanges.
879 *
880 * This routine prepares the mailbox command for registering a virtual N_Port.
881 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500882void
James Smart04c68492009-05-22 14:52:52 -0400883lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
James Smart92d7f7b2007-06-17 19:56:38 -0500884{
James Smart04c68492009-05-22 14:52:52 -0400885 MAILBOX_t *mb = &pmb->u.mb;
James Smart38b92ef2010-08-04 16:11:39 -0400886 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500887
888 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
James Smart38b92ef2010-08-04 16:11:39 -0400889 /*
890 * Set the re-reg VPI bit for f/w to update the MAC address.
891 */
892 if ((phba->sli_rev == LPFC_SLI_REV4) &&
893 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI))
894 mb->un.varRegVpi.upd = 1;
James Smart6d368e52011-05-24 11:44:12 -0400895
896 mb->un.varRegVpi.vpi = phba->vpi_ids[vport->vpi];
James Smart04c68492009-05-22 14:52:52 -0400897 mb->un.varRegVpi.sid = vport->fc_myDID;
James Smart6d368e52011-05-24 11:44:12 -0400898 if (phba->sli_rev == LPFC_SLI_REV4)
899 mb->un.varRegVpi.vfi = phba->sli4_hba.vfi_ids[vport->vfi];
900 else
901 mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
James Smartc8685952009-11-18 15:39:16 -0500902 memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname,
903 sizeof(struct lpfc_name));
904 mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]);
905 mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]);
James Smart92d7f7b2007-06-17 19:56:38 -0500906
907 mb->mbxCommand = MBX_REG_VPI;
908 mb->mbxOwner = OWN_HOST;
909 return;
910
911}
912
James Smarte59058c2008-08-24 21:49:00 -0400913/**
James Smart3621a712009-04-06 18:47:14 -0400914 * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
James Smarte59058c2008-08-24 21:49:00 -0400915 * @phba: pointer to lpfc hba data structure.
916 * @vpi: virtual N_Port identifier.
917 * @pmb: pointer to the driver internal queue element for mailbox command.
918 *
919 * The unregistration vport identifier mailbox command is used to inactivate
920 * a virtual N_Port. The driver must have logged out and unregistered all
921 * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
922 * unregisters any default RPIs associated with the specified vpi, aborting
923 * any active exchanges. The HBA will post the mailbox response after making
924 * the virtual N_Port inactive.
925 *
926 * This routine prepares the mailbox command for unregistering a virtual
927 * N_Port.
928 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500929void
930lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
931{
James Smart04c68492009-05-22 14:52:52 -0400932 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500933 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
934
James Smart6d368e52011-05-24 11:44:12 -0400935 if (phba->sli_rev == LPFC_SLI_REV3)
936 mb->un.varUnregVpi.vpi = phba->vpi_ids[vpi];
937 else if (phba->sli_rev >= LPFC_SLI_REV4)
938 mb->un.varUnregVpi.sli4_vpi = phba->vpi_ids[vpi];
James Smart92d7f7b2007-06-17 19:56:38 -0500939
940 mb->mbxCommand = MBX_UNREG_VPI;
941 mb->mbxOwner = OWN_HOST;
942 return;
943
944}
945
James Smarte59058c2008-08-24 21:49:00 -0400946/**
James Smart3621a712009-04-06 18:47:14 -0400947 * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
James Smarte59058c2008-08-24 21:49:00 -0400948 * @phba: pointer to lpfc hba data structure.
949 *
950 * This routine sets up and initializes the IOCB rings in the Port Control
951 * Block (PCB).
952 **/
dea31012005-04-17 16:05:31 -0500953static void
954lpfc_config_pcb_setup(struct lpfc_hba * phba)
955{
956 struct lpfc_sli *psli = &phba->sli;
957 struct lpfc_sli_ring *pring;
James Smart34b02dc2008-08-24 21:49:55 -0400958 PCB_t *pcbp = phba->pcb;
dea31012005-04-17 16:05:31 -0500959 dma_addr_t pdma_addr;
960 uint32_t offset;
James Smart2e0fef82007-06-17 19:56:36 -0500961 uint32_t iocbCnt = 0;
dea31012005-04-17 16:05:31 -0500962 int i;
963
dea31012005-04-17 16:05:31 -0500964 pcbp->maxRing = (psli->num_rings - 1);
965
dea31012005-04-17 16:05:31 -0500966 for (i = 0; i < psli->num_rings; i++) {
James Smart895427b2017-02-12 13:52:30 -0800967 pring = &psli->sli3_ring[i];
James Smart2e0fef82007-06-17 19:56:36 -0500968
James Smart7e56aa22012-08-03 12:35:34 -0400969 pring->sli.sli3.sizeCiocb =
970 phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE :
James Smart92d7f7b2007-06-17 19:56:38 -0500971 SLI2_IOCB_CMD_SIZE;
James Smart7e56aa22012-08-03 12:35:34 -0400972 pring->sli.sli3.sizeRiocb =
973 phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE :
James Smart92d7f7b2007-06-17 19:56:38 -0500974 SLI2_IOCB_RSP_SIZE;
dea31012005-04-17 16:05:31 -0500975 /* A ring MUST have both cmd and rsp entries defined to be
976 valid */
James Smart7e56aa22012-08-03 12:35:34 -0400977 if ((pring->sli.sli3.numCiocb == 0) ||
978 (pring->sli.sli3.numRiocb == 0)) {
dea31012005-04-17 16:05:31 -0500979 pcbp->rdsc[i].cmdEntries = 0;
980 pcbp->rdsc[i].rspEntries = 0;
981 pcbp->rdsc[i].cmdAddrHigh = 0;
982 pcbp->rdsc[i].rspAddrHigh = 0;
983 pcbp->rdsc[i].cmdAddrLow = 0;
984 pcbp->rdsc[i].rspAddrLow = 0;
James Smart7e56aa22012-08-03 12:35:34 -0400985 pring->sli.sli3.cmdringaddr = NULL;
986 pring->sli.sli3.rspringaddr = NULL;
dea31012005-04-17 16:05:31 -0500987 continue;
988 }
989 /* Command ring setup for ring */
James Smart7e56aa22012-08-03 12:35:34 -0400990 pring->sli.sli3.cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
991 pcbp->rdsc[i].cmdEntries = pring->sli.sli3.numCiocb;
dea31012005-04-17 16:05:31 -0500992
James Smart34b02dc2008-08-24 21:49:55 -0400993 offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
994 (uint8_t *) phba->slim2p.virt;
995 pdma_addr = phba->slim2p.phys + offset;
dea31012005-04-17 16:05:31 -0500996 pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
997 pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
James Smart7e56aa22012-08-03 12:35:34 -0400998 iocbCnt += pring->sli.sli3.numCiocb;
dea31012005-04-17 16:05:31 -0500999
1000 /* Response ring setup for ring */
James Smart7e56aa22012-08-03 12:35:34 -04001001 pring->sli.sli3.rspringaddr = (void *) &phba->IOCBs[iocbCnt];
dea31012005-04-17 16:05:31 -05001002
James Smart7e56aa22012-08-03 12:35:34 -04001003 pcbp->rdsc[i].rspEntries = pring->sli.sli3.numRiocb;
James Smart34b02dc2008-08-24 21:49:55 -04001004 offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
1005 (uint8_t *)phba->slim2p.virt;
1006 pdma_addr = phba->slim2p.phys + offset;
dea31012005-04-17 16:05:31 -05001007 pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
1008 pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
James Smart7e56aa22012-08-03 12:35:34 -04001009 iocbCnt += pring->sli.sli3.numRiocb;
dea31012005-04-17 16:05:31 -05001010 }
1011}
1012
James Smarte59058c2008-08-24 21:49:00 -04001013/**
James Smart3621a712009-04-06 18:47:14 -04001014 * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
James Smarte59058c2008-08-24 21:49:00 -04001015 * @phba: pointer to lpfc hba data structure.
1016 * @pmb: pointer to the driver internal queue element for mailbox command.
1017 *
1018 * The read revision mailbox command is used to read the revision levels of
1019 * the HBA components. These components include hardware units, resident
1020 * firmware, and available firmware. HBAs that supports SLI-3 mode of
1021 * operation provide different response information depending on the version
1022 * requested by the driver.
1023 *
1024 * This routine prepares the mailbox command for reading HBA revision
1025 * information.
1026 **/
dea31012005-04-17 16:05:31 -05001027void
1028lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1029{
James Smart04c68492009-05-22 14:52:52 -04001030 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001031 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1032 mb->un.varRdRev.cv = 1;
James Smarted957682007-06-17 19:56:37 -05001033 mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
dea31012005-04-17 16:05:31 -05001034 mb->mbxCommand = MBX_READ_REV;
1035 mb->mbxOwner = OWN_HOST;
1036 return;
1037}
1038
James Smartd7c47992010-06-08 18:31:54 -04001039void
1040lpfc_sli4_swap_str(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1041{
1042 MAILBOX_t *mb = &pmb->u.mb;
1043 struct lpfc_mqe *mqe;
1044
1045 switch (mb->mbxCommand) {
1046 case MBX_READ_REV:
1047 mqe = &pmb->u.mqe;
1048 lpfc_sli_pcimem_bcopy(mqe->un.read_rev.fw_name,
1049 mqe->un.read_rev.fw_name, 16);
1050 lpfc_sli_pcimem_bcopy(mqe->un.read_rev.ulp_fw_name,
1051 mqe->un.read_rev.ulp_fw_name, 16);
1052 break;
1053 default:
1054 break;
1055 }
1056 return;
1057}
1058
James Smarte59058c2008-08-24 21:49:00 -04001059/**
James Smart3621a712009-04-06 18:47:14 -04001060 * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
James Smarte59058c2008-08-24 21:49:00 -04001061 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1062 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1063 *
1064 * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
1065 * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
1066 * the Sequence Length Test using the fields in the Selection Profile 2
1067 * extension in words 20:31.
1068 **/
James Smarted957682007-06-17 19:56:37 -05001069static void
1070lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
1071 struct lpfc_hbq_init *hbq_desc)
1072{
1073 hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
1074 hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
1075 hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
1076}
1077
James Smarte59058c2008-08-24 21:49:00 -04001078/**
James Smart3621a712009-04-06 18:47:14 -04001079 * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
James Smarte59058c2008-08-24 21:49:00 -04001080 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1081 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1082 *
1083 * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
1084 * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
1085 * the Sequence Length Test and Byte Field Test using the fields in the
1086 * Selection Profile 3 extension in words 20:31.
1087 **/
James Smarted957682007-06-17 19:56:37 -05001088static void
1089lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
1090 struct lpfc_hbq_init *hbq_desc)
1091{
1092 hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
1093 hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
1094 hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
1095 hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
1096 memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
1097 sizeof(hbqmb->profiles.profile3.cmdmatch));
1098}
1099
James Smarte59058c2008-08-24 21:49:00 -04001100/**
James Smart3621a712009-04-06 18:47:14 -04001101 * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
James Smarte59058c2008-08-24 21:49:00 -04001102 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1103 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1104 *
1105 * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
1106 * HBA tests the initial frame of an incoming sequence using the frame's
1107 * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
1108 * and Byte Field Test using the fields in the Selection Profile 5 extension
1109 * words 20:31.
1110 **/
James Smarted957682007-06-17 19:56:37 -05001111static void
1112lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
1113 struct lpfc_hbq_init *hbq_desc)
1114{
1115 hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
1116 hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
1117 hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
1118 hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
1119 memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
1120 sizeof(hbqmb->profiles.profile5.cmdmatch));
1121}
1122
James Smarte59058c2008-08-24 21:49:00 -04001123/**
James Smart3621a712009-04-06 18:47:14 -04001124 * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
James Smarte59058c2008-08-24 21:49:00 -04001125 * @phba: pointer to lpfc hba data structure.
1126 * @id: HBQ identifier.
1127 * @hbq_desc: pointer to the HBA descriptor data structure.
1128 * @hbq_entry_index: index of the HBQ entry data structures.
1129 * @pmb: pointer to the driver internal queue element for mailbox command.
1130 *
1131 * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
1132 * an HBQ. The configuration binds events that require buffers to a particular
1133 * ring and HBQ based on a selection profile.
1134 *
1135 * This routine prepares the mailbox command for configuring an HBQ.
1136 **/
James Smarted957682007-06-17 19:56:37 -05001137void
James Smart51ef4c22007-08-02 11:10:31 -04001138lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
1139 struct lpfc_hbq_init *hbq_desc,
James Smarted957682007-06-17 19:56:37 -05001140 uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
1141{
1142 int i;
James Smart04c68492009-05-22 14:52:52 -04001143 MAILBOX_t *mb = &pmb->u.mb;
James Smarted957682007-06-17 19:56:37 -05001144 struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
1145
1146 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
James Smart51ef4c22007-08-02 11:10:31 -04001147 hbqmb->hbqId = id;
James Smarted957682007-06-17 19:56:37 -05001148 hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
1149 hbqmb->recvNotify = hbq_desc->rn; /* Receive
1150 * Notification */
1151 hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
1152 * # in words 0-19 */
James Smart92d7f7b2007-06-17 19:56:38 -05001153 hbqmb->profile = hbq_desc->profile; /* Selection profile:
James Smarted957682007-06-17 19:56:37 -05001154 * 0 = all,
1155 * 7 = logentry */
1156 hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
1157 * e.g. Ring0=b0001,
1158 * ring2=b0100 */
1159 hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
1160 * or 5 */
1161 hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
1162 * HBQ will be used
1163 * for LogEntry
1164 * buffers */
1165 hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
1166 hbq_entry_index * sizeof(struct lpfc_hbq_entry);
1167 hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
1168
1169 mb->mbxCommand = MBX_CONFIG_HBQ;
1170 mb->mbxOwner = OWN_HOST;
1171
James Smart92d7f7b2007-06-17 19:56:38 -05001172 /* Copy info for profiles 2,3,5. Other
1173 * profiles this area is reserved
1174 */
James Smarted957682007-06-17 19:56:37 -05001175 if (hbq_desc->profile == 2)
1176 lpfc_build_hbq_profile2(hbqmb, hbq_desc);
1177 else if (hbq_desc->profile == 3)
1178 lpfc_build_hbq_profile3(hbqmb, hbq_desc);
1179 else if (hbq_desc->profile == 5)
1180 lpfc_build_hbq_profile5(hbqmb, hbq_desc);
1181
1182 /* Return if no rctl / type masks for this HBQ */
1183 if (!hbq_desc->mask_count)
1184 return;
1185
1186 /* Otherwise we setup specific rctl / type masks for this HBQ */
1187 for (i = 0; i < hbq_desc->mask_count; i++) {
1188 hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
1189 hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
1190 hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
1191 hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
1192 }
1193
1194 return;
1195}
1196
James Smarte59058c2008-08-24 21:49:00 -04001197/**
James Smart3621a712009-04-06 18:47:14 -04001198 * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04001199 * @phba: pointer to lpfc hba data structure.
Lee Jones012d0192020-07-23 13:24:24 +01001200 * @ring: ring number/index
James Smarte59058c2008-08-24 21:49:00 -04001201 * @pmb: pointer to the driver internal queue element for mailbox command.
1202 *
1203 * The configure ring mailbox command is used to configure an IOCB ring. This
1204 * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1205 * ring. This is used to map incoming sequences to a particular ring whose
1206 * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1207 * attempt to configure a ring whose number is greater than the number
1208 * specified in the Port Control Block (PCB). It is an error to issue the
1209 * configure ring command more than once with the same ring number. The HBA
1210 * returns an error if the driver attempts this.
1211 *
1212 * This routine prepares the mailbox command for configuring IOCB ring.
1213 **/
dea31012005-04-17 16:05:31 -05001214void
1215lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
1216{
1217 int i;
James Smart04c68492009-05-22 14:52:52 -04001218 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001219 struct lpfc_sli *psli;
1220 struct lpfc_sli_ring *pring;
1221
1222 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1223
1224 mb->un.varCfgRing.ring = ring;
1225 mb->un.varCfgRing.maxOrigXchg = 0;
1226 mb->un.varCfgRing.maxRespXchg = 0;
1227 mb->un.varCfgRing.recvNotify = 1;
1228
1229 psli = &phba->sli;
James Smart895427b2017-02-12 13:52:30 -08001230 pring = &psli->sli3_ring[ring];
dea31012005-04-17 16:05:31 -05001231 mb->un.varCfgRing.numMask = pring->num_mask;
1232 mb->mbxCommand = MBX_CONFIG_RING;
1233 mb->mbxOwner = OWN_HOST;
1234
1235 /* Is this ring configured for a specific profile */
1236 if (pring->prt[0].profile) {
1237 mb->un.varCfgRing.profile = pring->prt[0].profile;
1238 return;
1239 }
1240
1241 /* Otherwise we setup specific rctl / type masks for this ring */
1242 for (i = 0; i < pring->num_mask; i++) {
1243 mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
James Smart6a9c52c2009-10-02 15:16:51 -04001244 if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ)
dea31012005-04-17 16:05:31 -05001245 mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
1246 else
1247 mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
1248 mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
1249 mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
1250 }
1251
1252 return;
1253}
1254
James Smarte59058c2008-08-24 21:49:00 -04001255/**
James Smart3621a712009-04-06 18:47:14 -04001256 * lpfc_config_port - Prepare a mailbox command for configuring port
James Smarte59058c2008-08-24 21:49:00 -04001257 * @phba: pointer to lpfc hba data structure.
1258 * @pmb: pointer to the driver internal queue element for mailbox command.
1259 *
1260 * The configure port mailbox command is used to identify the Port Control
1261 * Block (PCB) in the driver memory. After this command is issued, the
1262 * driver must not access the mailbox in the HBA without first resetting
1263 * the HBA. The HBA may copy the PCB information to internal storage for
1264 * subsequent use; the driver can not change the PCB information unless it
1265 * resets the HBA.
1266 *
1267 * This routine prepares the mailbox command for configuring port.
1268 **/
dea31012005-04-17 16:05:31 -05001269void
James Smart92d7f7b2007-06-17 19:56:38 -05001270lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001271{
James Smarted957682007-06-17 19:56:37 -05001272 MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
James Smart04c68492009-05-22 14:52:52 -04001273 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001274 dma_addr_t pdma_addr;
1275 uint32_t bar_low, bar_high;
1276 size_t offset;
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04001277 struct lpfc_hgp hgp;
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001278 int i;
James Smarted957682007-06-17 19:56:37 -05001279 uint32_t pgp_offset;
dea31012005-04-17 16:05:31 -05001280
1281 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1282 mb->mbxCommand = MBX_CONFIG_PORT;
1283 mb->mbxOwner = OWN_HOST;
1284
1285 mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
1286
James Smart34b02dc2008-08-24 21:49:55 -04001287 offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
1288 pdma_addr = phba->slim2p.phys + offset;
dea31012005-04-17 16:05:31 -05001289 mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
1290 mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
1291
James Smart97207482008-12-04 22:39:19 -05001292 /* Always Host Group Pointer is in SLIM */
1293 mb->un.varCfgPort.hps = 1;
1294
James Smarted957682007-06-17 19:56:37 -05001295 /* If HBA supports SLI=3 ask for it */
1296
James Smart04c68492009-05-22 14:52:52 -04001297 if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
James Smarte2a0a9d2008-12-04 22:40:02 -05001298 if (phba->cfg_enable_bg)
1299 mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
James Smarted957682007-06-17 19:56:37 -05001300 mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
James Smart34b02dc2008-08-24 21:49:55 -04001301 mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
James Smart51ef4c22007-08-02 11:10:31 -04001302 mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
James Smart78b2d852007-08-02 11:10:21 -04001303 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smart92d7f7b2007-06-17 19:56:38 -05001304 phba->vpd.sli3Feat.cmv) {
James Smart04c68492009-05-22 14:52:52 -04001305 mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI;
James Smart92d7f7b2007-06-17 19:56:38 -05001306 mb->un.varCfgPort.cmv = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001307 } else
1308 mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
1309 } else
James Smart04c68492009-05-22 14:52:52 -04001310 phba->sli_rev = LPFC_SLI_REV2;
James Smart92d7f7b2007-06-17 19:56:38 -05001311 mb->un.varCfgPort.sli_mode = phba->sli_rev;
James Smarted957682007-06-17 19:56:37 -05001312
James Smartcb69f7d2011-12-13 13:21:57 -05001313 /* If this is an SLI3 port, configure async status notification. */
1314 if (phba->sli_rev == LPFC_SLI_REV3)
1315 mb->un.varCfgPort.casabt = 1;
1316
dea31012005-04-17 16:05:31 -05001317 /* Now setup pcb */
James Smart34b02dc2008-08-24 21:49:55 -04001318 phba->pcb->type = TYPE_NATIVE_SLI2;
1319 phba->pcb->feature = FEATURE_INITIAL_SLI2;
dea31012005-04-17 16:05:31 -05001320
1321 /* Setup Mailbox pointers */
James Smart7a470272010-03-15 11:25:20 -04001322 phba->pcb->mailBoxSize = sizeof(MAILBOX_t) + MAILBOX_EXT_SIZE;
James Smart34b02dc2008-08-24 21:49:55 -04001323 offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
1324 pdma_addr = phba->slim2p.phys + offset;
1325 phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
1326 phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
dea31012005-04-17 16:05:31 -05001327
1328 /*
1329 * Setup Host Group ring pointer.
1330 *
1331 * For efficiency reasons, the ring get/put pointers can be
1332 * placed in adapter memory (SLIM) rather than in host memory.
1333 * This allows firmware to avoid PCI reads/writes when updating
1334 * and checking pointers.
1335 *
1336 * The firmware recognizes the use of SLIM memory by comparing
1337 * the address of the get/put pointers structure with that of
1338 * the SLIM BAR (BAR0).
1339 *
1340 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1341 * (the hardware's view of the base address), not the OS's
1342 * value of pci_resource_start() as the OS value may be a cookie
1343 * for ioremap/iomap.
1344 */
1345
1346
1347 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
1348 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
1349
James Smarted957682007-06-17 19:56:37 -05001350 /*
1351 * Set up HGP - Port Memory
1352 *
1353 * The port expects the host get/put pointers to reside in memory
1354 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1355 * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
1356 * words (0x40 bytes). This area is not reserved if HBQs are
1357 * configured in SLI-3.
1358 *
1359 * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1360 * RR0Get 0xc4 0x84
1361 * CR1Put 0xc8 0x88
1362 * RR1Get 0xcc 0x8c
1363 * CR2Put 0xd0 0x90
1364 * RR2Get 0xd4 0x94
1365 * CR3Put 0xd8 0x98
1366 * RR3Get 0xdc 0x9c
1367 *
1368 * Reserved 0xa0-0xbf
1369 * If HBQs configured:
1370 * HBQ 0 Put ptr 0xc0
1371 * HBQ 1 Put ptr 0xc4
1372 * HBQ 2 Put ptr 0xc8
1373 * ......
1374 * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1375 *
1376 */
1377
James Smart7a470272010-03-15 11:25:20 -04001378 if (phba->cfg_hostmem_hgp && phba->sli_rev != 3) {
Dick Kennedya7fc0712020-05-01 14:43:08 -07001379 phba->host_gp = (struct lpfc_hgp __iomem *)
1380 &phba->mbox->us.s2.host[0];
James Smarted957682007-06-17 19:56:37 -05001381 phba->hbq_put = NULL;
James Smart7a470272010-03-15 11:25:20 -04001382 offset = (uint8_t *)&phba->mbox->us.s2.host -
1383 (uint8_t *)phba->slim2p.virt;
1384 pdma_addr = phba->slim2p.phys + offset;
1385 phba->pcb->hgpAddrHigh = putPaddrHigh(pdma_addr);
1386 phba->pcb->hgpAddrLow = putPaddrLow(pdma_addr);
1387 } else {
1388 /* Always Host Group Pointer is in SLIM */
1389 mb->un.varCfgPort.hps = 1;
dea31012005-04-17 16:05:31 -05001390
James Smart7a470272010-03-15 11:25:20 -04001391 if (phba->sli_rev == 3) {
1392 phba->host_gp = &mb_slim->us.s3.host[0];
1393 phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
1394 } else {
1395 phba->host_gp = &mb_slim->us.s2.host[0];
1396 phba->hbq_put = NULL;
1397 }
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001398
James Smart7a470272010-03-15 11:25:20 -04001399 /* mask off BAR0's flag bits 0 - 3 */
1400 phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
1401 (void __iomem *)phba->host_gp -
1402 (void __iomem *)phba->MBslimaddr;
1403 if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
1404 phba->pcb->hgpAddrHigh = bar_high;
1405 else
1406 phba->pcb->hgpAddrHigh = 0;
1407 /* write HGP data to SLIM at the required longword offset */
1408 memset(&hgp, 0, sizeof(struct lpfc_hgp));
1409
1410 for (i = 0; i < phba->sli.num_rings; i++) {
1411 lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
James Smarted957682007-06-17 19:56:37 -05001412 sizeof(*phba->host_gp));
James Smart7a470272010-03-15 11:25:20 -04001413 }
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001414 }
dea31012005-04-17 16:05:31 -05001415
James Smart8f34f4c2008-12-04 22:39:23 -05001416 /* Setup Port Group offset */
1417 if (phba->sli_rev == 3)
James Smart34b02dc2008-08-24 21:49:55 -04001418 pgp_offset = offsetof(struct lpfc_sli2_slim,
1419 mbx.us.s3_pgp.port);
James Smart8f34f4c2008-12-04 22:39:23 -05001420 else
James Smart34b02dc2008-08-24 21:49:55 -04001421 pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
1422 pdma_addr = phba->slim2p.phys + pgp_offset;
1423 phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
1424 phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
dea31012005-04-17 16:05:31 -05001425
1426 /* Use callback routine to setp rings in the pcb */
1427 lpfc_config_pcb_setup(phba);
1428
1429 /* special handling for LC HBAs */
1430 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
1431 uint32_t hbainit[5];
1432
1433 lpfc_hba_init(phba, hbainit);
1434
1435 memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
1436 }
1437
1438 /* Swap PCB if needed */
James Smart34b02dc2008-08-24 21:49:55 -04001439 lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
dea31012005-04-17 16:05:31 -05001440}
1441
James Smarte59058c2008-08-24 21:49:00 -04001442/**
James Smart3621a712009-04-06 18:47:14 -04001443 * lpfc_kill_board - Prepare a mailbox command for killing board
James Smarte59058c2008-08-24 21:49:00 -04001444 * @phba: pointer to lpfc hba data structure.
1445 * @pmb: pointer to the driver internal queue element for mailbox command.
1446 *
1447 * The kill board mailbox command is used to tell firmware to perform a
1448 * graceful shutdown of a channel on a specified board to prepare for reset.
1449 * When the kill board mailbox command is received, the ER3 bit is set to 1
1450 * in the Host Status register and the ER Attention bit is set to 1 in the
1451 * Host Attention register of the HBA function that received the kill board
1452 * command.
1453 *
1454 * This routine prepares the mailbox command for killing the board in
1455 * preparation for a graceful shutdown.
1456 **/
dea31012005-04-17 16:05:31 -05001457void
Jamie Wellnitz41415862006-02-28 19:25:27 -05001458lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1459{
James Smart04c68492009-05-22 14:52:52 -04001460 MAILBOX_t *mb = &pmb->u.mb;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001461
1462 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1463 mb->mbxCommand = MBX_KILL_BOARD;
1464 mb->mbxOwner = OWN_HOST;
1465 return;
1466}
1467
James Smarte59058c2008-08-24 21:49:00 -04001468/**
James Smart3621a712009-04-06 18:47:14 -04001469 * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
James Smarte59058c2008-08-24 21:49:00 -04001470 * @phba: pointer to lpfc hba data structure.
1471 * @mbq: pointer to the driver internal queue element for mailbox command.
1472 *
1473 * Driver maintains a internal mailbox command queue implemented as a linked
1474 * list. When a mailbox command is issued, it shall be put into the mailbox
1475 * command queue such that they shall be processed orderly as HBA can process
1476 * one mailbox command at a time.
1477 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001478void
dea31012005-04-17 16:05:31 -05001479lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1480{
1481 struct lpfc_sli *psli;
1482
1483 psli = &phba->sli;
1484
1485 list_add_tail(&mbq->list, &psli->mboxq);
1486
1487 psli->mboxq_cnt++;
1488
1489 return;
1490}
1491
James Smarte59058c2008-08-24 21:49:00 -04001492/**
James Smart3621a712009-04-06 18:47:14 -04001493 * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
James Smarte59058c2008-08-24 21:49:00 -04001494 * @phba: pointer to lpfc hba data structure.
1495 *
1496 * Driver maintains a internal mailbox command queue implemented as a linked
1497 * list. When a mailbox command is issued, it shall be put into the mailbox
1498 * command queue such that they shall be processed orderly as HBA can process
1499 * one mailbox command at a time. After HBA finished processing a mailbox
1500 * command, the driver will remove a pending mailbox command from the head of
1501 * the mailbox command queue and send to the HBA for processing.
1502 *
1503 * Return codes
1504 * pointer to the driver internal queue element for mailbox command.
1505 **/
dea31012005-04-17 16:05:31 -05001506LPFC_MBOXQ_t *
1507lpfc_mbox_get(struct lpfc_hba * phba)
1508{
1509 LPFC_MBOXQ_t *mbq = NULL;
1510 struct lpfc_sli *psli = &phba->sli;
1511
James Smart2e0fef82007-06-17 19:56:36 -05001512 list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
James Smart92d7f7b2007-06-17 19:56:38 -05001513 if (mbq)
dea31012005-04-17 16:05:31 -05001514 psli->mboxq_cnt--;
dea31012005-04-17 16:05:31 -05001515
1516 return mbq;
1517}
James Smarta309a6b2006-08-01 07:33:43 -04001518
James Smarte59058c2008-08-24 21:49:00 -04001519/**
James Smart04c68492009-05-22 14:52:52 -04001520 * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
1521 * @phba: pointer to lpfc hba data structure.
1522 * @mbq: pointer to the driver internal queue element for mailbox command.
1523 *
1524 * This routine put the completed mailbox command into the mailbox command
1525 * complete list. This is the unlocked version of the routine. The mailbox
1526 * complete list is used by the driver worker thread to process mailbox
1527 * complete callback functions outside the driver interrupt handler.
1528 **/
1529void
1530__lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
1531{
1532 list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
1533}
1534
1535/**
James Smart3621a712009-04-06 18:47:14 -04001536 * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
James Smarte59058c2008-08-24 21:49:00 -04001537 * @phba: pointer to lpfc hba data structure.
1538 * @mbq: pointer to the driver internal queue element for mailbox command.
1539 *
1540 * This routine put the completed mailbox command into the mailbox command
James Smart04c68492009-05-22 14:52:52 -04001541 * complete list. This is the locked version of the routine. The mailbox
1542 * complete list is used by the driver worker thread to process mailbox
1543 * complete callback functions outside the driver interrupt handler.
James Smarte59058c2008-08-24 21:49:00 -04001544 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001545void
James Smart04c68492009-05-22 14:52:52 -04001546lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
James Smart92d7f7b2007-06-17 19:56:38 -05001547{
James Smart5b75da22008-12-04 22:39:35 -05001548 unsigned long iflag;
1549
Joe Perchesb1c11812008-02-03 17:28:22 +02001550 /* This function expects to be called from interrupt context */
James Smart5b75da22008-12-04 22:39:35 -05001551 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart04c68492009-05-22 14:52:52 -04001552 __lpfc_mbox_cmpl_put(phba, mbq);
James Smart5b75da22008-12-04 22:39:35 -05001553 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05001554 return;
1555}
1556
James Smarte59058c2008-08-24 21:49:00 -04001557/**
James Smart04c68492009-05-22 14:52:52 -04001558 * lpfc_mbox_cmd_check - Check the validality of a mailbox command
1559 * @phba: pointer to lpfc hba data structure.
1560 * @mboxq: pointer to the driver internal queue element for mailbox command.
1561 *
1562 * This routine is to check whether a mailbox command is valid to be issued.
1563 * This check will be performed by both the mailbox issue API when a client
1564 * is to issue a mailbox command to the mailbox transport.
1565 *
1566 * Return 0 - pass the check, -ENODEV - fail the check
1567 **/
1568int
1569lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1570{
1571 /* Mailbox command that have a completion handler must also have a
1572 * vport specified.
1573 */
1574 if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
1575 mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
1576 if (!mboxq->vport) {
1577 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
1578 "1814 Mbox x%x failed, no vport\n",
1579 mboxq->u.mb.mbxCommand);
1580 dump_stack();
1581 return -ENODEV;
1582 }
1583 }
1584 return 0;
1585}
1586
1587/**
1588 * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
1589 * @phba: pointer to lpfc hba data structure.
1590 *
1591 * This routine is to check whether the HBA device is ready for posting a
1592 * mailbox command. It is used by the mailbox transport API at the time the
1593 * to post a mailbox command to the device.
1594 *
1595 * Return 0 - pass the check, -ENODEV - fail the check
1596 **/
1597int
1598lpfc_mbox_dev_check(struct lpfc_hba *phba)
1599{
1600 /* If the PCI channel is in offline state, do not issue mbox */
1601 if (unlikely(pci_channel_offline(phba->pcidev)))
1602 return -ENODEV;
1603
1604 /* If the HBA is in error state, do not issue mbox */
1605 if (phba->link_state == LPFC_HBA_ERROR)
1606 return -ENODEV;
1607
1608 return 0;
1609}
1610
1611/**
James Smart3621a712009-04-06 18:47:14 -04001612 * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
James Smarte59058c2008-08-24 21:49:00 -04001613 * @phba: pointer to lpfc hba data structure.
Lee Jones012d0192020-07-23 13:24:24 +01001614 * @mboxq: pointer to the driver internal queue element for mailbox command.
James Smarte59058c2008-08-24 21:49:00 -04001615 *
1616 * This routine retrieves the proper timeout value according to the mailbox
1617 * command code.
1618 *
1619 * Return codes
1620 * Timeout value to be used for the given mailbox command
1621 **/
James Smarta309a6b2006-08-01 07:33:43 -04001622int
James Smarta183a152011-10-10 21:32:43 -04001623lpfc_mbox_tmo_val(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
James Smarta309a6b2006-08-01 07:33:43 -04001624{
James Smarta183a152011-10-10 21:32:43 -04001625 MAILBOX_t *mbox = &mboxq->u.mb;
1626 uint8_t subsys, opcode;
1627
1628 switch (mbox->mbxCommand) {
James Smarta309a6b2006-08-01 07:33:43 -04001629 case MBX_WRITE_NV: /* 0x03 */
James Smart940eb682012-08-03 12:37:08 -04001630 case MBX_DUMP_MEMORY: /* 0x17 */
James Smarta309a6b2006-08-01 07:33:43 -04001631 case MBX_UPDATE_CFG: /* 0x1B */
1632 case MBX_DOWN_LOAD: /* 0x1C */
1633 case MBX_DEL_LD_ENTRY: /* 0x1D */
James Smart940eb682012-08-03 12:37:08 -04001634 case MBX_WRITE_VPARMS: /* 0x32 */
James Smarta309a6b2006-08-01 07:33:43 -04001635 case MBX_LOAD_AREA: /* 0x81 */
James Smart09372822008-01-11 01:52:54 -05001636 case MBX_WRITE_WWN: /* 0x98 */
James Smarta309a6b2006-08-01 07:33:43 -04001637 case MBX_LOAD_EXP_ROM: /* 0x9C */
James Smart940eb682012-08-03 12:37:08 -04001638 case MBX_ACCESS_VDATA: /* 0xA5 */
James Smarta309a6b2006-08-01 07:33:43 -04001639 return LPFC_MBOX_TMO_FLASH_CMD;
James Smart04c68492009-05-22 14:52:52 -04001640 case MBX_SLI4_CONFIG: /* 0x9b */
James Smarta183a152011-10-10 21:32:43 -04001641 subsys = lpfc_sli_config_mbox_subsys_get(phba, mboxq);
1642 opcode = lpfc_sli_config_mbox_opcode_get(phba, mboxq);
1643 if (subsys == LPFC_MBOX_SUBSYSTEM_COMMON) {
1644 switch (opcode) {
1645 case LPFC_MBOX_OPCODE_READ_OBJECT:
1646 case LPFC_MBOX_OPCODE_WRITE_OBJECT:
1647 case LPFC_MBOX_OPCODE_READ_OBJECT_LIST:
1648 case LPFC_MBOX_OPCODE_DELETE_OBJECT:
James Smarta183a152011-10-10 21:32:43 -04001649 case LPFC_MBOX_OPCODE_GET_PROFILE_LIST:
1650 case LPFC_MBOX_OPCODE_SET_ACT_PROFILE:
James Smart940eb682012-08-03 12:37:08 -04001651 case LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG:
James Smarta183a152011-10-10 21:32:43 -04001652 case LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG:
1653 case LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG:
James Smart940eb682012-08-03 12:37:08 -04001654 case LPFC_MBOX_OPCODE_GET_PROFILE_CAPACITIES:
1655 case LPFC_MBOX_OPCODE_SEND_ACTIVATION:
1656 case LPFC_MBOX_OPCODE_RESET_LICENSES:
1657 case LPFC_MBOX_OPCODE_SET_BOOT_CONFIG:
1658 case LPFC_MBOX_OPCODE_GET_VPD_DATA:
1659 case LPFC_MBOX_OPCODE_SET_PHYSICAL_LINK_CONFIG:
James Smarta183a152011-10-10 21:32:43 -04001660 return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO;
1661 }
1662 }
1663 if (subsys == LPFC_MBOX_SUBSYSTEM_FCOE) {
1664 switch (opcode) {
1665 case LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS:
1666 return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO;
1667 }
1668 }
James Smart04c68492009-05-22 14:52:52 -04001669 return LPFC_MBOX_SLI4_CONFIG_TMO;
James Smarta309a6b2006-08-01 07:33:43 -04001670 }
1671 return LPFC_MBOX_TMO;
1672}
James Smart04c68492009-05-22 14:52:52 -04001673
1674/**
1675 * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
1676 * @mbox: pointer to lpfc mbox command.
1677 * @sgentry: sge entry index.
1678 * @phyaddr: physical address for the sge
1679 * @length: Length of the sge.
1680 *
1681 * This routine sets up an entry in the non-embedded mailbox command at the sge
1682 * index location.
1683 **/
1684void
1685lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry,
1686 dma_addr_t phyaddr, uint32_t length)
1687{
1688 struct lpfc_mbx_nembed_cmd *nembed_sge;
1689
1690 nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1691 &mbox->u.mqe.un.nembed_cmd;
1692 nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr);
1693 nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr);
1694 nembed_sge->sge[sgentry].length = length;
1695}
1696
1697/**
1698 * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
1699 * @mbox: pointer to lpfc mbox command.
1700 * @sgentry: sge entry index.
Lee Jones012d0192020-07-23 13:24:24 +01001701 * @sge: pointer to lpfc mailbox sge to load into.
James Smart04c68492009-05-22 14:52:52 -04001702 *
1703 * This routine gets an entry from the non-embedded mailbox command at the sge
1704 * index location.
1705 **/
1706void
1707lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry,
1708 struct lpfc_mbx_sge *sge)
1709{
1710 struct lpfc_mbx_nembed_cmd *nembed_sge;
1711
1712 nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1713 &mbox->u.mqe.un.nembed_cmd;
1714 sge->pa_lo = nembed_sge->sge[sgentry].pa_lo;
1715 sge->pa_hi = nembed_sge->sge[sgentry].pa_hi;
1716 sge->length = nembed_sge->sge[sgentry].length;
1717}
1718
1719/**
1720 * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
1721 * @phba: pointer to lpfc hba data structure.
1722 * @mbox: pointer to lpfc mbox command.
1723 *
1724 * This routine frees SLI4 specific mailbox command for sending IOCTL command.
1725 **/
1726void
1727lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1728{
1729 struct lpfc_mbx_sli4_config *sli4_cfg;
1730 struct lpfc_mbx_sge sge;
1731 dma_addr_t phyaddr;
1732 uint32_t sgecount, sgentry;
1733
1734 sli4_cfg = &mbox->u.mqe.un.sli4_config;
1735
1736 /* For embedded mbox command, just free the mbox command */
1737 if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1738 mempool_free(mbox, phba->mbox_mem_pool);
1739 return;
1740 }
1741
1742 /* For non-embedded mbox command, we need to free the pages first */
1743 sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr);
1744 /* There is nothing we can do if there is no sge address array */
1745 if (unlikely(!mbox->sge_array)) {
1746 mempool_free(mbox, phba->mbox_mem_pool);
1747 return;
1748 }
1749 /* Each non-embedded DMA memory was allocated in the length of a page */
1750 for (sgentry = 0; sgentry < sgecount; sgentry++) {
1751 lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge);
1752 phyaddr = getPaddr(sge.pa_hi, sge.pa_lo);
James Smart49198b32010-04-06 15:04:33 -04001753 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
James Smart04c68492009-05-22 14:52:52 -04001754 mbox->sge_array->addr[sgentry], phyaddr);
1755 }
1756 /* Free the sge address array memory */
1757 kfree(mbox->sge_array);
1758 /* Finally, free the mailbox command itself */
1759 mempool_free(mbox, phba->mbox_mem_pool);
1760}
1761
1762/**
1763 * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command
1764 * @phba: pointer to lpfc hba data structure.
1765 * @mbox: pointer to lpfc mbox command.
1766 * @subsystem: The sli4 config sub mailbox subsystem.
1767 * @opcode: The sli4 config sub mailbox command opcode.
James Smartfedd3b72011-02-16 12:39:24 -05001768 * @length: Length of the sli4 config mailbox command (including sub-header).
Lee Jones012d0192020-07-23 13:24:24 +01001769 * @emb: True if embedded mbox command should be setup.
James Smart04c68492009-05-22 14:52:52 -04001770 *
1771 * This routine sets up the header fields of SLI4 specific mailbox command
1772 * for sending IOCTL command.
1773 *
1774 * Return: the actual length of the mbox command allocated (mostly useful
1775 * for none embedded mailbox command).
1776 **/
1777int
1778lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
1779 uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb)
1780{
1781 struct lpfc_mbx_sli4_config *sli4_config;
1782 union lpfc_sli4_cfg_shdr *cfg_shdr = NULL;
1783 uint32_t alloc_len;
1784 uint32_t resid_len;
1785 uint32_t pagen, pcount;
1786 void *viraddr;
1787 dma_addr_t phyaddr;
1788
1789 /* Set up SLI4 mailbox command header fields */
1790 memset(mbox, 0, sizeof(*mbox));
1791 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG);
1792
1793 /* Set up SLI4 ioctl command header fields */
1794 sli4_config = &mbox->u.mqe.un.sli4_config;
1795
1796 /* Setup for the embedded mbox command */
1797 if (emb) {
1798 /* Set up main header fields */
1799 bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
James Smartfedd3b72011-02-16 12:39:24 -05001800 sli4_config->header.cfg_mhdr.payload_length = length;
James Smart04c68492009-05-22 14:52:52 -04001801 /* Set up sub-header fields following main header */
1802 bf_set(lpfc_mbox_hdr_opcode,
1803 &sli4_config->header.cfg_shdr.request, opcode);
1804 bf_set(lpfc_mbox_hdr_subsystem,
1805 &sli4_config->header.cfg_shdr.request, subsystem);
James Smartfedd3b72011-02-16 12:39:24 -05001806 sli4_config->header.cfg_shdr.request.request_length =
1807 length - LPFC_MBX_CMD_HDR_LENGTH;
James Smart04c68492009-05-22 14:52:52 -04001808 return length;
1809 }
1810
James Smart6d368e52011-05-24 11:44:12 -04001811 /* Setup for the non-embedded mbox command */
James Smart9589b0622011-04-16 11:03:17 -04001812 pcount = (SLI4_PAGE_ALIGN(length))/SLI4_PAGE_SIZE;
James Smart04c68492009-05-22 14:52:52 -04001813 pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ?
1814 LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount;
1815 /* Allocate record for keeping SGE virtual addresses */
James Smart6d368e52011-05-24 11:44:12 -04001816 mbox->sge_array = kzalloc(sizeof(struct lpfc_mbx_nembed_sge_virt),
James Smart04c68492009-05-22 14:52:52 -04001817 GFP_KERNEL);
James Smart6a9c52c2009-10-02 15:16:51 -04001818 if (!mbox->sge_array) {
1819 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1820 "2527 Failed to allocate non-embedded SGE "
1821 "array.\n");
James Smart04c68492009-05-22 14:52:52 -04001822 return 0;
James Smart6a9c52c2009-10-02 15:16:51 -04001823 }
James Smart04c68492009-05-22 14:52:52 -04001824 for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) {
1825 /* The DMA memory is always allocated in the length of a
1826 * page even though the last SGE might not fill up to a
James Smart49198b32010-04-06 15:04:33 -04001827 * page, this is used as a priori size of SLI4_PAGE_SIZE for
James Smart04c68492009-05-22 14:52:52 -04001828 * the later DMA memory free.
1829 */
Luis Chamberlain750afb02019-01-04 09:23:09 +01001830 viraddr = dma_alloc_coherent(&phba->pcidev->dev,
1831 SLI4_PAGE_SIZE, &phyaddr,
1832 GFP_KERNEL);
James Smart04c68492009-05-22 14:52:52 -04001833 /* In case of malloc fails, proceed with whatever we have */
1834 if (!viraddr)
1835 break;
1836 mbox->sge_array->addr[pagen] = viraddr;
1837 /* Keep the first page for later sub-header construction */
1838 if (pagen == 0)
1839 cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr;
1840 resid_len = length - alloc_len;
James Smart49198b32010-04-06 15:04:33 -04001841 if (resid_len > SLI4_PAGE_SIZE) {
James Smart04c68492009-05-22 14:52:52 -04001842 lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
James Smart49198b32010-04-06 15:04:33 -04001843 SLI4_PAGE_SIZE);
1844 alloc_len += SLI4_PAGE_SIZE;
James Smart04c68492009-05-22 14:52:52 -04001845 } else {
1846 lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
1847 resid_len);
1848 alloc_len = length;
1849 }
1850 }
1851
1852 /* Set up main header fields in mailbox command */
1853 sli4_config->header.cfg_mhdr.payload_length = alloc_len;
1854 bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen);
1855
1856 /* Set up sub-header fields into the first page */
1857 if (pagen > 0) {
1858 bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode);
1859 bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem);
1860 cfg_shdr->request.request_length =
1861 alloc_len - sizeof(union lpfc_sli4_cfg_shdr);
1862 }
1863 /* The sub-header is in DMA memory, which needs endian converstion */
James Smart72100cc2010-02-12 14:43:01 -05001864 if (cfg_shdr)
1865 lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
James Smart6d368e52011-05-24 11:44:12 -04001866 sizeof(union lpfc_sli4_cfg_shdr));
James Smart04c68492009-05-22 14:52:52 -04001867 return alloc_len;
1868}
1869
1870/**
James Smart6d368e52011-05-24 11:44:12 -04001871 * lpfc_sli4_mbox_rsrc_extent - Initialize the opcode resource extent.
1872 * @phba: pointer to lpfc hba data structure.
1873 * @mbox: pointer to an allocated lpfc mbox resource.
1874 * @exts_count: the number of extents, if required, to allocate.
1875 * @rsrc_type: the resource extent type.
1876 * @emb: true if LPFC_SLI4_MBX_EMBED. false if LPFC_SLI4_MBX_NEMBED.
1877 *
1878 * This routine completes the subcommand header for SLI4 resource extent
1879 * mailbox commands. It is called after lpfc_sli4_config. The caller must
1880 * pass an allocated mailbox and the attributes required to initialize the
1881 * mailbox correctly.
1882 *
1883 * Return: the actual length of the mbox command allocated.
1884 **/
1885int
1886lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
1887 uint16_t exts_count, uint16_t rsrc_type, bool emb)
1888{
1889 uint8_t opcode = 0;
1890 struct lpfc_mbx_nembed_rsrc_extent *n_rsrc_extnt = NULL;
1891 void *virtaddr = NULL;
1892
1893 /* Set up SLI4 ioctl command header fields */
1894 if (emb == LPFC_SLI4_MBX_NEMBED) {
1895 /* Get the first SGE entry from the non-embedded DMA memory */
1896 virtaddr = mbox->sge_array->addr[0];
1897 if (virtaddr == NULL)
1898 return 1;
1899 n_rsrc_extnt = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr;
1900 }
1901
1902 /*
1903 * The resource type is common to all extent Opcodes and resides in the
1904 * same position.
1905 */
1906 if (emb == LPFC_SLI4_MBX_EMBED)
1907 bf_set(lpfc_mbx_alloc_rsrc_extents_type,
1908 &mbox->u.mqe.un.alloc_rsrc_extents.u.req,
1909 rsrc_type);
1910 else {
1911 /* This is DMA data. Byteswap is required. */
1912 bf_set(lpfc_mbx_alloc_rsrc_extents_type,
1913 n_rsrc_extnt, rsrc_type);
1914 lpfc_sli_pcimem_bcopy(&n_rsrc_extnt->word4,
1915 &n_rsrc_extnt->word4,
1916 sizeof(uint32_t));
1917 }
1918
1919 /* Complete the initialization for the particular Opcode. */
James Smarta183a152011-10-10 21:32:43 -04001920 opcode = lpfc_sli_config_mbox_opcode_get(phba, mbox);
James Smart6d368e52011-05-24 11:44:12 -04001921 switch (opcode) {
1922 case LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT:
1923 if (emb == LPFC_SLI4_MBX_EMBED)
1924 bf_set(lpfc_mbx_alloc_rsrc_extents_cnt,
1925 &mbox->u.mqe.un.alloc_rsrc_extents.u.req,
1926 exts_count);
1927 else
1928 bf_set(lpfc_mbx_alloc_rsrc_extents_cnt,
1929 n_rsrc_extnt, exts_count);
1930 break;
1931 case LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT:
1932 case LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO:
1933 case LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT:
1934 /* Initialization is complete.*/
1935 break;
1936 default:
1937 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1938 "2929 Resource Extent Opcode x%x is "
1939 "unsupported\n", opcode);
1940 return 1;
1941 }
1942
1943 return 0;
1944}
1945
1946/**
James Smarta183a152011-10-10 21:32:43 -04001947 * lpfc_sli_config_mbox_subsys_get - Get subsystem from a sli_config mbox cmd
James Smart04c68492009-05-22 14:52:52 -04001948 * @phba: pointer to lpfc hba data structure.
James Smarta183a152011-10-10 21:32:43 -04001949 * @mbox: pointer to lpfc mbox command queue entry.
James Smart04c68492009-05-22 14:52:52 -04001950 *
James Smarta183a152011-10-10 21:32:43 -04001951 * This routine gets the subsystem from a SLI4 specific SLI_CONFIG mailbox
1952 * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if the
1953 * sub-header is not present, subsystem LPFC_MBOX_SUBSYSTEM_NA (0x0) shall
1954 * be returned.
James Smart04c68492009-05-22 14:52:52 -04001955 **/
1956uint8_t
James Smarta183a152011-10-10 21:32:43 -04001957lpfc_sli_config_mbox_subsys_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
James Smart04c68492009-05-22 14:52:52 -04001958{
1959 struct lpfc_mbx_sli4_config *sli4_cfg;
1960 union lpfc_sli4_cfg_shdr *cfg_shdr;
1961
1962 if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
James Smarta183a152011-10-10 21:32:43 -04001963 return LPFC_MBOX_SUBSYSTEM_NA;
1964 sli4_cfg = &mbox->u.mqe.un.sli4_config;
1965
1966 /* For embedded mbox command, get opcode from embedded sub-header*/
1967 if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1968 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
1969 return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request);
1970 }
1971
1972 /* For non-embedded mbox command, get opcode from first dma page */
1973 if (unlikely(!mbox->sge_array))
1974 return LPFC_MBOX_SUBSYSTEM_NA;
1975 cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
1976 return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request);
1977}
1978
1979/**
1980 * lpfc_sli_config_mbox_opcode_get - Get opcode from a sli_config mbox cmd
1981 * @phba: pointer to lpfc hba data structure.
1982 * @mbox: pointer to lpfc mbox command queue entry.
1983 *
1984 * This routine gets the opcode from a SLI4 specific SLI_CONFIG mailbox
1985 * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if
1986 * the sub-header is not present, opcode LPFC_MBOX_OPCODE_NA (0x0) be
1987 * returned.
1988 **/
1989uint8_t
1990lpfc_sli_config_mbox_opcode_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
1991{
1992 struct lpfc_mbx_sli4_config *sli4_cfg;
1993 union lpfc_sli4_cfg_shdr *cfg_shdr;
1994
1995 if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
1996 return LPFC_MBOX_OPCODE_NA;
James Smart04c68492009-05-22 14:52:52 -04001997 sli4_cfg = &mbox->u.mqe.un.sli4_config;
1998
1999 /* For embedded mbox command, get opcode from embedded sub-header*/
2000 if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
2001 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
2002 return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
2003 }
2004
2005 /* For non-embedded mbox command, get opcode from first dma page */
2006 if (unlikely(!mbox->sge_array))
James Smarta183a152011-10-10 21:32:43 -04002007 return LPFC_MBOX_OPCODE_NA;
James Smart04c68492009-05-22 14:52:52 -04002008 cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
2009 return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
2010}
2011
2012/**
James Smart0c9ab6f2010-02-26 14:15:57 -05002013 * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd
James Smartecfd03c2010-02-12 14:41:27 -05002014 * @phba: pointer to lpfc hba data structure.
Lee Jones012d0192020-07-23 13:24:24 +01002015 * @mboxq: pointer to lpfc mbox command.
James Smartecfd03c2010-02-12 14:41:27 -05002016 * @fcf_index: index to fcf table.
2017 *
2018 * This routine routine allocates and constructs non-embedded mailbox command
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002019 * for reading a FCF table entry referred by @fcf_index.
James Smartecfd03c2010-02-12 14:41:27 -05002020 *
2021 * Return: pointer to the mailbox command constructed if successful, otherwise
2022 * NULL.
2023 **/
2024int
James Smart0c9ab6f2010-02-26 14:15:57 -05002025lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *phba,
2026 struct lpfcMboxq *mboxq,
2027 uint16_t fcf_index)
James Smartecfd03c2010-02-12 14:41:27 -05002028{
2029 void *virt_addr;
James Smartecfd03c2010-02-12 14:41:27 -05002030 uint8_t *bytep;
2031 struct lpfc_mbx_sge sge;
2032 uint32_t alloc_len, req_len;
2033 struct lpfc_mbx_read_fcf_tbl *read_fcf;
2034
2035 if (!mboxq)
2036 return -ENOMEM;
2037
2038 req_len = sizeof(struct fcf_record) +
2039 sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
2040
2041 /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
2042 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
2043 LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
2044 LPFC_SLI4_MBX_NEMBED);
2045
2046 if (alloc_len < req_len) {
2047 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
2048 "0291 Allocated DMA memory size (x%x) is "
2049 "less than the requested DMA memory "
2050 "size (x%x)\n", alloc_len, req_len);
2051 return -ENOMEM;
2052 }
2053
2054 /* Get the first SGE entry from the non-embedded DMA memory. This
2055 * routine only uses a single SGE.
2056 */
2057 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
James Smartecfd03c2010-02-12 14:41:27 -05002058 virt_addr = mboxq->sge_array->addr[0];
2059 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
2060
2061 /* Set up command fields */
2062 bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
2063 /* Perform necessary endian conversion */
2064 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
2065 lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
2066
2067 return 0;
2068}
2069
2070/**
James Smart04c68492009-05-22 14:52:52 -04002071 * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
Lee Jones012d0192020-07-23 13:24:24 +01002072 * @phba: pointer to lpfc hba data structure.
James Smart04c68492009-05-22 14:52:52 -04002073 * @mboxq: pointer to lpfc mbox command.
2074 *
2075 * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
2076 * mailbox command.
2077 **/
2078void
2079lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
2080{
2081 /* Set up SLI4 mailbox command header fields */
2082 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
2083 bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS);
2084
2085 /* Set up host requested features. */
2086 bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
James Smartfedd3b72011-02-16 12:39:24 -05002087 bf_set(lpfc_mbx_rq_ftr_rq_perfh, &mboxq->u.mqe.un.req_ftrs, 1);
James Smart04c68492009-05-22 14:52:52 -04002088
James Smart04c68492009-05-22 14:52:52 -04002089 /* Enable DIF (block guard) only if configured to do so. */
2090 if (phba->cfg_enable_bg)
2091 bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1);
2092
2093 /* Enable NPIV only if configured to do so. */
2094 if (phba->max_vpi && phba->cfg_enable_npiv)
2095 bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1);
2096
James Smart86c67372017-04-21 16:05:04 -07002097 if (phba->nvmet_support) {
James Smart2d7dbc42017-02-12 13:52:35 -08002098 bf_set(lpfc_mbx_rq_ftr_rq_mrqp, &mboxq->u.mqe.un.req_ftrs, 1);
James Smart86c67372017-04-21 16:05:04 -07002099 /* iaab/iaar NOT set for now */
Colin Ian King258f84f2019-02-12 15:29:45 +00002100 bf_set(lpfc_mbx_rq_ftr_rq_iaab, &mboxq->u.mqe.un.req_ftrs, 0);
2101 bf_set(lpfc_mbx_rq_ftr_rq_iaar, &mboxq->u.mqe.un.req_ftrs, 0);
James Smart86c67372017-04-21 16:05:04 -07002102 }
James Smart04c68492009-05-22 14:52:52 -04002103 return;
2104}
2105
2106/**
2107 * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
2108 * @mbox: pointer to lpfc mbox command to initialize.
2109 * @vport: Vport associated with the VF.
2110 *
2111 * This routine initializes @mbox to all zeros and then fills in the mailbox
2112 * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
2113 * in the context of an FCF. The driver issues this command to setup a VFI
2114 * before issuing a FLOGI to login to the VSAN. The driver should also issue a
2115 * REG_VFI after a successful VSAN login.
2116 **/
2117void
2118lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
2119{
2120 struct lpfc_mbx_init_vfi *init_vfi;
2121
2122 memset(mbox, 0, sizeof(*mbox));
James Smart76a95d72010-11-20 23:11:48 -05002123 mbox->vport = vport;
James Smart04c68492009-05-22 14:52:52 -04002124 init_vfi = &mbox->u.mqe.un.init_vfi;
2125 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI);
2126 bf_set(lpfc_init_vfi_vr, init_vfi, 1);
2127 bf_set(lpfc_init_vfi_vt, init_vfi, 1);
James Smart76a95d72010-11-20 23:11:48 -05002128 bf_set(lpfc_init_vfi_vp, init_vfi, 1);
James Smart6d368e52011-05-24 11:44:12 -04002129 bf_set(lpfc_init_vfi_vfi, init_vfi,
2130 vport->phba->sli4_hba.vfi_ids[vport->vfi]);
James Smart7851fe22011-07-22 18:36:52 -04002131 bf_set(lpfc_init_vfi_vpi, init_vfi,
James Smart6d368e52011-05-24 11:44:12 -04002132 vport->phba->vpi_ids[vport->vpi]);
2133 bf_set(lpfc_init_vfi_fcfi, init_vfi,
2134 vport->phba->fcf.fcfi);
James Smart04c68492009-05-22 14:52:52 -04002135}
2136
2137/**
2138 * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
2139 * @mbox: pointer to lpfc mbox command to initialize.
2140 * @vport: vport associated with the VF.
2141 * @phys: BDE DMA bus address used to send the service parameters to the HBA.
2142 *
2143 * This routine initializes @mbox to all zeros and then fills in the mailbox
2144 * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
2145 * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
2146 * fabrics identified by VFI in the context of an FCF.
2147 **/
2148void
2149lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys)
2150{
2151 struct lpfc_mbx_reg_vfi *reg_vfi;
James Smartae05ebe2013-03-01 16:35:38 -05002152 struct lpfc_hba *phba = vport->phba;
James Smart44fd7fe2017-08-23 16:55:47 -07002153 uint8_t bbscn_fabric = 0, bbscn_max = 0, bbscn_def = 0;
James Smart04c68492009-05-22 14:52:52 -04002154
2155 memset(mbox, 0, sizeof(*mbox));
2156 reg_vfi = &mbox->u.mqe.un.reg_vfi;
2157 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI);
2158 bf_set(lpfc_reg_vfi_vp, reg_vfi, 1);
James Smart6d368e52011-05-24 11:44:12 -04002159 bf_set(lpfc_reg_vfi_vfi, reg_vfi,
James Smartae05ebe2013-03-01 16:35:38 -05002160 phba->sli4_hba.vfi_ids[vport->vfi]);
2161 bf_set(lpfc_reg_vfi_fcfi, reg_vfi, phba->fcf.fcfi);
2162 bf_set(lpfc_reg_vfi_vpi, reg_vfi, phba->vpi_ids[vport->vpi]);
James Smartc8685952009-11-18 15:39:16 -05002163 memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name));
2164 reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]);
2165 reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]);
James Smartae05ebe2013-03-01 16:35:38 -05002166 reg_vfi->e_d_tov = phba->fc_edtov;
2167 reg_vfi->r_a_tov = phba->fc_ratov;
James Smartae09c762016-03-31 14:12:28 -07002168 if (phys) {
2169 reg_vfi->bde.addrHigh = putPaddrHigh(phys);
2170 reg_vfi->bde.addrLow = putPaddrLow(phys);
2171 reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam);
2172 reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
2173 }
James Smart04c68492009-05-22 14:52:52 -04002174 bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID);
James Smartae05ebe2013-03-01 16:35:38 -05002175
2176 /* Only FC supports upd bit */
2177 if ((phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) &&
James Smarte74c03c2013-04-17 20:15:19 -04002178 (vport->fc_flag & FC_VFI_REGISTERED) &&
James Smart2c3b2a82018-01-30 15:58:50 -08002179 (!phba->fc_topology_changed))
James Smartae05ebe2013-03-01 16:35:38 -05002180 bf_set(lpfc_reg_vfi_upd, reg_vfi, 1);
James Smart44fd7fe2017-08-23 16:55:47 -07002181
2182 bf_set(lpfc_reg_vfi_bbcr, reg_vfi, 0);
2183 bf_set(lpfc_reg_vfi_bbscn, reg_vfi, 0);
2184 bbscn_fabric = (phba->fc_fabparam.cmn.bbRcvSizeMsb >> 4) & 0xF;
2185
2186 if (phba->bbcredit_support && phba->cfg_enable_bbcr &&
2187 bbscn_fabric != 0) {
2188 bbscn_max = bf_get(lpfc_bbscn_max,
2189 &phba->sli4_hba.bbscn_params);
2190 if (bbscn_fabric <= bbscn_max) {
2191 bbscn_def = bf_get(lpfc_bbscn_def,
2192 &phba->sli4_hba.bbscn_params);
2193
2194 if (bbscn_fabric > bbscn_def)
2195 bf_set(lpfc_reg_vfi_bbscn, reg_vfi,
2196 bbscn_fabric);
2197 else
2198 bf_set(lpfc_reg_vfi_bbscn, reg_vfi, bbscn_def);
2199
2200 bf_set(lpfc_reg_vfi_bbcr, reg_vfi, 1);
2201 }
2202 }
James Smart1b511972011-12-13 13:23:09 -05002203 lpfc_printf_vlog(vport, KERN_INFO, LOG_MBOX,
2204 "3134 Register VFI, mydid:x%x, fcfi:%d, "
James Smarte74c03c2013-04-17 20:15:19 -04002205 " vfi:%d, vpi:%d, fc_pname:%x%x fc_flag:x%x"
James Smart44fd7fe2017-08-23 16:55:47 -07002206 " port_state:x%x topology chg:%d bbscn_fabric :%d\n",
James Smart1b511972011-12-13 13:23:09 -05002207 vport->fc_myDID,
James Smartae05ebe2013-03-01 16:35:38 -05002208 phba->fcf.fcfi,
2209 phba->sli4_hba.vfi_ids[vport->vfi],
2210 phba->vpi_ids[vport->vpi],
James Smarte74c03c2013-04-17 20:15:19 -04002211 reg_vfi->wwn[0], reg_vfi->wwn[1], vport->fc_flag,
James Smart44fd7fe2017-08-23 16:55:47 -07002212 vport->port_state, phba->fc_topology_changed,
2213 bbscn_fabric);
James Smart04c68492009-05-22 14:52:52 -04002214}
2215
2216/**
2217 * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
James Smart1c6834a2009-07-19 10:01:26 -04002218 * @phba: pointer to the hba structure to init the VPI for.
James Smart04c68492009-05-22 14:52:52 -04002219 * @mbox: pointer to lpfc mbox command to initialize.
2220 * @vpi: VPI to be initialized.
2221 *
2222 * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
2223 * command to activate a virtual N_Port. The HBA assigns a MAC address to use
2224 * with the virtual N Port. The SLI Host issues this command before issuing a
2225 * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
2226 * successful virtual NPort login.
2227 **/
2228void
James Smart1c6834a2009-07-19 10:01:26 -04002229lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi)
James Smart04c68492009-05-22 14:52:52 -04002230{
2231 memset(mbox, 0, sizeof(*mbox));
2232 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI);
James Smart1c6834a2009-07-19 10:01:26 -04002233 bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi,
James Smart6d368e52011-05-24 11:44:12 -04002234 phba->vpi_ids[vpi]);
James Smart1c6834a2009-07-19 10:01:26 -04002235 bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi,
James Smart6d368e52011-05-24 11:44:12 -04002236 phba->sli4_hba.vfi_ids[phba->pport->vfi]);
James Smart04c68492009-05-22 14:52:52 -04002237}
2238
2239/**
2240 * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
2241 * @mbox: pointer to lpfc mbox command to initialize.
James Smart6669f9b2009-10-02 15:16:45 -04002242 * @vport: vport associated with the VF.
James Smart04c68492009-05-22 14:52:52 -04002243 *
2244 * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
2245 * (logical NPort) into the inactive state. The SLI Host must have logged out
2246 * and unregistered all remote N_Ports to abort any activity on the virtual
2247 * fabric. The SLI Port posts the mailbox response after marking the virtual
2248 * fabric inactive.
2249 **/
2250void
James Smart6669f9b2009-10-02 15:16:45 -04002251lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
James Smart04c68492009-05-22 14:52:52 -04002252{
2253 memset(mbox, 0, sizeof(*mbox));
2254 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI);
James Smart6669f9b2009-10-02 15:16:45 -04002255 bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi,
James Smart6d368e52011-05-24 11:44:12 -04002256 vport->phba->sli4_hba.vfi_ids[vport->vfi]);
James Smart04c68492009-05-22 14:52:52 -04002257}
2258
2259/**
James Smart026abb82011-12-13 13:20:45 -05002260 * lpfc_sli4_dump_cfg_rg23 - Dump sli4 port config region 23
James Smart04c68492009-05-22 14:52:52 -04002261 * @phba: pointer to the hba structure containing.
2262 * @mbox: pointer to lpfc mbox command to initialize.
2263 *
James Smart026abb82011-12-13 13:20:45 -05002264 * This function create a SLI4 dump mailbox command to dump configure
2265 * region 23.
James Smart04c68492009-05-22 14:52:52 -04002266 **/
2267int
James Smart026abb82011-12-13 13:20:45 -05002268lpfc_sli4_dump_cfg_rg23(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
James Smart04c68492009-05-22 14:52:52 -04002269{
2270 struct lpfc_dmabuf *mp = NULL;
2271 MAILBOX_t *mb;
2272
2273 memset(mbox, 0, sizeof(*mbox));
2274 mb = &mbox->u.mb;
2275
2276 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2277 if (mp)
2278 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
2279
2280 if (!mp || !mp->virt) {
2281 kfree(mp);
James Smart026abb82011-12-13 13:20:45 -05002282 /* dump config region 23 failed to allocate memory */
James Smart04c68492009-05-22 14:52:52 -04002283 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
James Smart026abb82011-12-13 13:20:45 -05002284 "2569 lpfc dump config region 23: memory"
James Smarte4e74272009-07-19 10:01:38 -04002285 " allocation failed\n");
James Smart04c68492009-05-22 14:52:52 -04002286 return 1;
2287 }
2288
2289 memset(mp->virt, 0, LPFC_BPL_SIZE);
2290 INIT_LIST_HEAD(&mp->list);
2291
2292 /* save address for completion */
James Smart3e1f0712018-11-29 16:09:29 -08002293 mbox->ctx_buf = (uint8_t *)mp;
James Smart04c68492009-05-22 14:52:52 -04002294
2295 mb->mbxCommand = MBX_DUMP_MEMORY;
2296 mb->un.varDmp.type = DMP_NV_PARAMS;
James Smarta0c87cb2009-07-19 10:01:10 -04002297 mb->un.varDmp.region_id = DMP_REGION_23;
2298 mb->un.varDmp.sli4_length = DMP_RGN23_SIZE;
James Smart04c68492009-05-22 14:52:52 -04002299 mb->un.varWords[3] = putPaddrLow(mp->phys);
2300 mb->un.varWords[4] = putPaddrHigh(mp->phys);
2301 return 0;
2302}
2303
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002304static void
James Smart86478872015-05-21 13:55:21 -04002305lpfc_mbx_cmpl_rdp_link_stat(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2306{
2307 MAILBOX_t *mb;
2308 int rc = FAILURE;
2309 struct lpfc_rdp_context *rdp_context =
James Smart3e1f0712018-11-29 16:09:29 -08002310 (struct lpfc_rdp_context *)(mboxq->ctx_ndlp);
James Smart86478872015-05-21 13:55:21 -04002311
2312 mb = &mboxq->u.mb;
2313 if (mb->mbxStatus)
2314 goto mbx_failed;
2315
2316 memcpy(&rdp_context->link_stat, &mb->un.varRdLnk, sizeof(READ_LNK_VAR));
2317
2318 rc = SUCCESS;
2319
2320mbx_failed:
2321 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2322 rdp_context->cmpl(phba, rdp_context, rc);
2323}
2324
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08002325static void
James Smart86478872015-05-21 13:55:21 -04002326lpfc_mbx_cmpl_rdp_page_a2(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
2327{
James Smart3e1f0712018-11-29 16:09:29 -08002328 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
James Smart86478872015-05-21 13:55:21 -04002329 struct lpfc_rdp_context *rdp_context =
James Smart3e1f0712018-11-29 16:09:29 -08002330 (struct lpfc_rdp_context *)(mbox->ctx_ndlp);
James Smart86478872015-05-21 13:55:21 -04002331
2332 if (bf_get(lpfc_mqe_status, &mbox->u.mqe))
Johannes Thumshirn612872c2015-08-17 13:03:02 +02002333 goto error_mbuf_free;
James Smart86478872015-05-21 13:55:21 -04002334
2335 lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a2,
2336 DMP_SFF_PAGE_A2_SIZE);
2337
2338 /* We don't need dma buffer for link stat. */
2339 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2340 kfree(mp);
2341
2342 memset(mbox, 0, sizeof(*mbox));
2343 lpfc_read_lnk_stat(phba, mbox);
2344 mbox->vport = rdp_context->ndlp->vport;
2345 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_link_stat;
James Smart3e1f0712018-11-29 16:09:29 -08002346 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
James Smart86478872015-05-21 13:55:21 -04002347 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) == MBX_NOT_FINISHED)
Johannes Thumshirn612872c2015-08-17 13:03:02 +02002348 goto error_cmd_free;
James Smart86478872015-05-21 13:55:21 -04002349
2350 return;
2351
Johannes Thumshirn612872c2015-08-17 13:03:02 +02002352error_mbuf_free:
James Smart86478872015-05-21 13:55:21 -04002353 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2354 kfree(mp);
Johannes Thumshirn612872c2015-08-17 13:03:02 +02002355error_cmd_free:
James Smart86478872015-05-21 13:55:21 -04002356 lpfc_sli4_mbox_cmd_free(phba, mbox);
2357 rdp_context->cmpl(phba, rdp_context, FAILURE);
2358}
2359
2360void
2361lpfc_mbx_cmpl_rdp_page_a0(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox)
2362{
2363 int rc;
James Smart3e1f0712018-11-29 16:09:29 -08002364 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(mbox->ctx_buf);
James Smart86478872015-05-21 13:55:21 -04002365 struct lpfc_rdp_context *rdp_context =
James Smart3e1f0712018-11-29 16:09:29 -08002366 (struct lpfc_rdp_context *)(mbox->ctx_ndlp);
James Smart86478872015-05-21 13:55:21 -04002367
2368 if (bf_get(lpfc_mqe_status, &mbox->u.mqe))
2369 goto error;
2370
2371 lpfc_sli_bemem_bcopy(mp->virt, &rdp_context->page_a0,
2372 DMP_SFF_PAGE_A0_SIZE);
2373
2374 memset(mbox, 0, sizeof(*mbox));
2375
2376 memset(mp->virt, 0, DMP_SFF_PAGE_A2_SIZE);
2377 INIT_LIST_HEAD(&mp->list);
2378
2379 /* save address for completion */
James Smart3e1f0712018-11-29 16:09:29 -08002380 mbox->ctx_buf = mp;
James Smart86478872015-05-21 13:55:21 -04002381 mbox->vport = rdp_context->ndlp->vport;
2382
2383 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY);
2384 bf_set(lpfc_mbx_memory_dump_type3_type,
2385 &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD);
2386 bf_set(lpfc_mbx_memory_dump_type3_link,
2387 &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port);
2388 bf_set(lpfc_mbx_memory_dump_type3_page_no,
2389 &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A2);
2390 bf_set(lpfc_mbx_memory_dump_type3_length,
2391 &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A2_SIZE);
2392 mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
2393 mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
2394
2395 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a2;
James Smart3e1f0712018-11-29 16:09:29 -08002396 mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
James Smart86478872015-05-21 13:55:21 -04002397 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
2398 if (rc == MBX_NOT_FINISHED)
2399 goto error;
2400
2401 return;
2402
2403error:
2404 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2405 kfree(mp);
2406 lpfc_sli4_mbox_cmd_free(phba, mbox);
2407 rdp_context->cmpl(phba, rdp_context, FAILURE);
2408}
2409
2410
2411/*
Eric Curtin0196e372021-01-19 20:50:22 +00002412 * lpfc_sli4_dump_page_a0 - Dump sli4 read SFP Diagnostic.
James Smart86478872015-05-21 13:55:21 -04002413 * @phba: pointer to the hba structure containing.
2414 * @mbox: pointer to lpfc mbox command to initialize.
2415 *
2416 * This function create a SLI4 dump mailbox command to dump configure
2417 * type 3 page 0xA0.
2418 */
2419int
2420lpfc_sli4_dump_page_a0(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
2421{
2422 struct lpfc_dmabuf *mp = NULL;
2423
2424 memset(mbox, 0, sizeof(*mbox));
2425
2426 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2427 if (mp)
2428 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
2429 if (!mp || !mp->virt) {
2430 kfree(mp);
2431 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
2432 "3569 dump type 3 page 0xA0 allocation failed\n");
2433 return 1;
2434 }
2435
2436 memset(mp->virt, 0, LPFC_BPL_SIZE);
2437 INIT_LIST_HEAD(&mp->list);
2438
2439 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_DUMP_MEMORY);
2440 /* save address for completion */
James Smart3e1f0712018-11-29 16:09:29 -08002441 mbox->ctx_buf = mp;
James Smart86478872015-05-21 13:55:21 -04002442
2443 bf_set(lpfc_mbx_memory_dump_type3_type,
2444 &mbox->u.mqe.un.mem_dump_type3, DMP_LMSD);
2445 bf_set(lpfc_mbx_memory_dump_type3_link,
2446 &mbox->u.mqe.un.mem_dump_type3, phba->sli4_hba.physical_port);
2447 bf_set(lpfc_mbx_memory_dump_type3_page_no,
2448 &mbox->u.mqe.un.mem_dump_type3, DMP_PAGE_A0);
2449 bf_set(lpfc_mbx_memory_dump_type3_length,
2450 &mbox->u.mqe.un.mem_dump_type3, DMP_SFF_PAGE_A0_SIZE);
2451 mbox->u.mqe.un.mem_dump_type3.addr_lo = putPaddrLow(mp->phys);
2452 mbox->u.mqe.un.mem_dump_type3.addr_hi = putPaddrHigh(mp->phys);
2453
2454 return 0;
2455}
2456
James Smart04c68492009-05-22 14:52:52 -04002457/**
2458 * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
2459 * @phba: pointer to the hba structure containing the FCF index and RQ ID.
2460 * @mbox: pointer to lpfc mbox command to initialize.
2461 *
2462 * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
2463 * SLI Host uses the command to activate an FCF after it has acquired FCF
2464 * information via a READ_FCF mailbox command. This mailbox command also is used
2465 * to indicate where received unsolicited frames from this FCF will be sent. By
2466 * default this routine will set up the FCF to forward all unsolicited frames
2467 * the the RQ ID passed in the @phba. This can be overridden by the caller for
2468 * more complicated setups.
2469 **/
2470void
2471lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
2472{
2473 struct lpfc_mbx_reg_fcfi *reg_fcfi;
2474
2475 memset(mbox, 0, sizeof(*mbox));
2476 reg_fcfi = &mbox->u.mqe.un.reg_fcfi;
2477 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI);
James Smart895427b2017-02-12 13:52:30 -08002478 if (phba->nvmet_support == 0) {
2479 bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi,
2480 phba->sli4_hba.hdr_rq->queue_id);
2481 /* Match everything - rq_id0 */
2482 bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, 0);
2483 bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0);
2484 bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi, 0);
2485 bf_set(lpfc_reg_fcfi_rctl_mask0, reg_fcfi, 0);
2486
2487 bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
2488
2489 /* addr mode is bit wise inverted value of fcf addr_mode */
2490 bf_set(lpfc_reg_fcfi_mam, reg_fcfi,
2491 (~phba->fcf.addr_mode) & 0x3);
James Smart2d7dbc42017-02-12 13:52:35 -08002492 } else {
2493 /* This is ONLY for NVMET MRQ == 1 */
2494 if (phba->cfg_nvmet_mrq != 1)
2495 return;
2496
2497 bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi,
2498 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id);
2499 /* Match type FCP - rq_id0 */
2500 bf_set(lpfc_reg_fcfi_type_match0, reg_fcfi, FC_TYPE_FCP);
2501 bf_set(lpfc_reg_fcfi_type_mask0, reg_fcfi, 0xff);
2502 bf_set(lpfc_reg_fcfi_rctl_match0, reg_fcfi,
2503 FC_RCTL_DD_UNSOL_CMD);
2504
2505 bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi,
2506 phba->sli4_hba.hdr_rq->queue_id);
2507 /* Match everything else - rq_id1 */
2508 bf_set(lpfc_reg_fcfi_type_match1, reg_fcfi, 0);
2509 bf_set(lpfc_reg_fcfi_type_mask1, reg_fcfi, 0);
2510 bf_set(lpfc_reg_fcfi_rctl_match1, reg_fcfi, 0);
2511 bf_set(lpfc_reg_fcfi_rctl_mask1, reg_fcfi, 0);
James Smart895427b2017-02-12 13:52:30 -08002512 }
James Smart04c68492009-05-22 14:52:52 -04002513 bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
2514 bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
James Smartecfd03c2010-02-12 14:41:27 -05002515 bf_set(lpfc_reg_fcfi_info_index, reg_fcfi,
2516 phba->fcf.current_rec.fcf_indx);
James Smart3804dc82010-07-14 15:31:37 -04002517 if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) {
James Smart04c68492009-05-22 14:52:52 -04002518 bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
James Smartecfd03c2010-02-12 14:41:27 -05002519 bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi,
2520 phba->fcf.current_rec.vlan_id);
James Smart04c68492009-05-22 14:52:52 -04002521 }
2522}
2523
2524/**
James Smart2d7dbc42017-02-12 13:52:35 -08002525 * lpfc_reg_fcfi_mrq - Initialize the REG_FCFI_MRQ mailbox command
2526 * @phba: pointer to the hba structure containing the FCF index and RQ ID.
2527 * @mbox: pointer to lpfc mbox command to initialize.
2528 * @mode: 0 to register FCFI, 1 to register MRQs
2529 *
2530 * The REG_FCFI_MRQ mailbox command supports Fibre Channel Forwarders (FCFs).
2531 * The SLI Host uses the command to activate an FCF after it has acquired FCF
2532 * information via a READ_FCF mailbox command. This mailbox command also is used
2533 * to indicate where received unsolicited frames from this FCF will be sent. By
2534 * default this routine will set up the FCF to forward all unsolicited frames
2535 * the the RQ ID passed in the @phba. This can be overridden by the caller for
2536 * more complicated setups.
2537 **/
2538void
2539lpfc_reg_fcfi_mrq(struct lpfc_hba *phba, struct lpfcMboxq *mbox, int mode)
2540{
2541 struct lpfc_mbx_reg_fcfi_mrq *reg_fcfi;
2542
2543 /* This is ONLY for MRQ */
2544 if (phba->cfg_nvmet_mrq <= 1)
2545 return;
2546
2547 memset(mbox, 0, sizeof(*mbox));
2548 reg_fcfi = &mbox->u.mqe.un.reg_fcfi_mrq;
2549 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI_MRQ);
2550 if (mode == 0) {
2551 bf_set(lpfc_reg_fcfi_mrq_info_index, reg_fcfi,
2552 phba->fcf.current_rec.fcf_indx);
2553 if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) {
2554 bf_set(lpfc_reg_fcfi_mrq_vv, reg_fcfi, 1);
2555 bf_set(lpfc_reg_fcfi_mrq_vlan_tag, reg_fcfi,
2556 phba->fcf.current_rec.vlan_id);
2557 }
2558 return;
2559 }
2560
2561 bf_set(lpfc_reg_fcfi_mrq_rq_id0, reg_fcfi,
2562 phba->sli4_hba.nvmet_mrq_hdr[0]->queue_id);
2563 /* Match NVME frames of type FCP (protocol NVME) - rq_id0 */
2564 bf_set(lpfc_reg_fcfi_mrq_type_match0, reg_fcfi, FC_TYPE_FCP);
2565 bf_set(lpfc_reg_fcfi_mrq_type_mask0, reg_fcfi, 0xff);
2566 bf_set(lpfc_reg_fcfi_mrq_rctl_match0, reg_fcfi, FC_RCTL_DD_UNSOL_CMD);
2567 bf_set(lpfc_reg_fcfi_mrq_rctl_mask0, reg_fcfi, 0xff);
2568 bf_set(lpfc_reg_fcfi_mrq_ptc0, reg_fcfi, 1);
2569 bf_set(lpfc_reg_fcfi_mrq_pt0, reg_fcfi, 1);
2570
2571 bf_set(lpfc_reg_fcfi_mrq_policy, reg_fcfi, 3); /* NVME connection id */
2572 bf_set(lpfc_reg_fcfi_mrq_mode, reg_fcfi, 1);
2573 bf_set(lpfc_reg_fcfi_mrq_filter, reg_fcfi, 1); /* rq_id0 */
2574 bf_set(lpfc_reg_fcfi_mrq_npairs, reg_fcfi, phba->cfg_nvmet_mrq);
2575
2576 bf_set(lpfc_reg_fcfi_mrq_rq_id1, reg_fcfi,
2577 phba->sli4_hba.hdr_rq->queue_id);
2578 /* Match everything - rq_id1 */
2579 bf_set(lpfc_reg_fcfi_mrq_type_match1, reg_fcfi, 0);
2580 bf_set(lpfc_reg_fcfi_mrq_type_mask1, reg_fcfi, 0);
2581 bf_set(lpfc_reg_fcfi_mrq_rctl_match1, reg_fcfi, 0);
2582 bf_set(lpfc_reg_fcfi_mrq_rctl_mask1, reg_fcfi, 0);
2583
2584 bf_set(lpfc_reg_fcfi_mrq_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
2585 bf_set(lpfc_reg_fcfi_mrq_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
2586}
2587
2588/**
James Smart04c68492009-05-22 14:52:52 -04002589 * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
2590 * @mbox: pointer to lpfc mbox command to initialize.
2591 * @fcfi: FCFI to be unregistered.
2592 *
2593 * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
2594 * The SLI Host uses the command to inactivate an FCFI.
2595 **/
2596void
2597lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi)
2598{
2599 memset(mbox, 0, sizeof(*mbox));
2600 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI);
2601 bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi);
2602}
2603
2604/**
2605 * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
2606 * @mbox: pointer to lpfc mbox command to initialize.
2607 * @ndlp: The nodelist structure that describes the RPI to resume.
2608 *
2609 * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
2610 * link event.
2611 **/
2612void
2613lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
2614{
James Smart6d368e52011-05-24 11:44:12 -04002615 struct lpfc_hba *phba = ndlp->phba;
James Smart04c68492009-05-22 14:52:52 -04002616 struct lpfc_mbx_resume_rpi *resume_rpi;
2617
2618 memset(mbox, 0, sizeof(*mbox));
2619 resume_rpi = &mbox->u.mqe.un.resume_rpi;
2620 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI);
James Smart6d368e52011-05-24 11:44:12 -04002621 bf_set(lpfc_resume_rpi_index, resume_rpi,
2622 phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]);
James Smart8fa38512009-07-19 10:01:03 -04002623 bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI);
2624 resume_rpi->event_tag = ndlp->phba->fc_eventTag;
James Smart04c68492009-05-22 14:52:52 -04002625}
James Smart28baac72010-02-12 14:42:03 -05002626