blob: b1dab92628eecc3db8b581a504bc9dfda594a18b [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 Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -040027#include <scsi/scsi_device.h>
28#include <scsi/scsi_transport_fc.h>
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040029#include <scsi/scsi.h>
James Smart6a9c52c2009-10-02 15:16:51 -040030#include <scsi/fc/fc_fs.h>
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040031
James Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
42#include "lpfc_compat.h"
43
James Smarte59058c2008-08-24 21:49:00 -040044/**
James Smart21e9a0a2009-05-22 14:53:21 -040045 * lpfc_dump_static_vport - Dump HBA's static vport information.
46 * @phba: pointer to lpfc hba data structure.
47 * @pmb: pointer to the driver internal queue element for mailbox command.
48 * @offset: offset for dumping vport info.
49 *
50 * The dump mailbox command provides a method for the device driver to obtain
51 * various types of information from the HBA device.
52 *
53 * This routine prepares the mailbox command for dumping list of static
54 * vports to be created.
55 **/
James Smart1c6834a2009-07-19 10:01:26 -040056int
James Smart21e9a0a2009-05-22 14:53:21 -040057lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
58 uint16_t offset)
59{
60 MAILBOX_t *mb;
James Smart1c6834a2009-07-19 10:01:26 -040061 struct lpfc_dmabuf *mp;
James Smart21e9a0a2009-05-22 14:53:21 -040062
63 mb = &pmb->u.mb;
James Smart21e9a0a2009-05-22 14:53:21 -040064
65 /* Setup to dump vport info region */
66 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
67 mb->mbxCommand = MBX_DUMP_MEMORY;
James Smart21e9a0a2009-05-22 14:53:21 -040068 mb->un.varDmp.type = DMP_NV_PARAMS;
69 mb->un.varDmp.entry_index = offset;
70 mb->un.varDmp.region_id = DMP_REGION_VPORT;
James Smart21e9a0a2009-05-22 14:53:21 -040071 mb->mbxOwner = OWN_HOST;
72
James Smart1c6834a2009-07-19 10:01:26 -040073 /* For SLI3 HBAs data is embedded in mailbox */
74 if (phba->sli_rev != LPFC_SLI_REV4) {
75 mb->un.varDmp.cv = 1;
76 mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t);
77 return 0;
78 }
79
80 /* For SLI4 HBAs driver need to allocate memory */
81 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
82 if (mp)
83 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
84
85 if (!mp || !mp->virt) {
86 kfree(mp);
87 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
88 "2605 lpfc_dump_static_vport: memory"
89 " allocation failed\n");
90 return 1;
91 }
92 memset(mp->virt, 0, LPFC_BPL_SIZE);
93 INIT_LIST_HEAD(&mp->list);
94 /* save address for completion */
95 pmb->context2 = (uint8_t *) mp;
96 mb->un.varWords[3] = putPaddrLow(mp->phys);
97 mb->un.varWords[4] = putPaddrHigh(mp->phys);
98 mb->un.varDmp.sli4_length = sizeof(struct static_vport_info);
99
100 return 0;
James Smart21e9a0a2009-05-22 14:53:21 -0400101}
102
103/**
James Smarta0c87cb2009-07-19 10:01:10 -0400104 * lpfc_down_link - Bring down HBAs link.
James Smarte59058c2008-08-24 21:49:00 -0400105 * @phba: pointer to lpfc hba data structure.
106 * @pmb: pointer to the driver internal queue element for mailbox command.
James Smarta0c87cb2009-07-19 10:01:10 -0400107 *
108 * This routine prepares a mailbox command to bring down HBA link.
109 **/
110void
111lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
112{
113 MAILBOX_t *mb;
114 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
115 mb = &pmb->u.mb;
116 mb->mbxCommand = MBX_DOWN_LINK;
117 mb->mbxOwner = OWN_HOST;
118}
119
120/**
121 * lpfc_dump_mem - Prepare a mailbox command for reading a region.
122 * @phba: pointer to lpfc hba data structure.
123 * @pmb: pointer to the driver internal queue element for mailbox command.
124 * @offset: offset into the region.
125 * @region_id: config region id.
James Smarte59058c2008-08-24 21:49:00 -0400126 *
127 * The dump mailbox command provides a method for the device driver to obtain
128 * various types of information from the HBA device.
129 *
James Smarta0c87cb2009-07-19 10:01:10 -0400130 * This routine prepares the mailbox command for dumping HBA's config region.
James Smarte59058c2008-08-24 21:49:00 -0400131 **/
dea31012005-04-17 16:05:31 -0500132void
James Smarta0c87cb2009-07-19 10:01:10 -0400133lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset,
134 uint16_t region_id)
dea31012005-04-17 16:05:31 -0500135{
136 MAILBOX_t *mb;
137 void *ctx;
138
James Smart04c68492009-05-22 14:52:52 -0400139 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500140 ctx = pmb->context2;
141
142 /* Setup to dump VPD region */
143 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
144 mb->mbxCommand = MBX_DUMP_MEMORY;
145 mb->un.varDmp.cv = 1;
146 mb->un.varDmp.type = DMP_NV_PARAMS;
147 mb->un.varDmp.entry_index = offset;
James Smarta0c87cb2009-07-19 10:01:10 -0400148 mb->un.varDmp.region_id = region_id;
dea31012005-04-17 16:05:31 -0500149 mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
150 mb->un.varDmp.co = 0;
151 mb->un.varDmp.resp_offset = 0;
152 pmb->context2 = ctx;
153 mb->mbxOwner = OWN_HOST;
154 return;
155}
156
James Smarte59058c2008-08-24 21:49:00 -0400157/**
James Smart3621a712009-04-06 18:47:14 -0400158 * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
James Smart97207482008-12-04 22:39:19 -0500159 * @phba: pointer to lpfc hba data structure.
160 * @pmb: pointer to the driver internal queue element for mailbox command.
James Smart3621a712009-04-06 18:47:14 -0400161 *
James Smart97207482008-12-04 22:39:19 -0500162 * This function create a dump memory mailbox command to dump wake up
163 * parameters.
164 */
165void
166lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
167{
168 MAILBOX_t *mb;
169 void *ctx;
170
James Smart04c68492009-05-22 14:52:52 -0400171 mb = &pmb->u.mb;
James Smart97207482008-12-04 22:39:19 -0500172 /* Save context so that we can restore after memset */
173 ctx = pmb->context2;
174
175 /* Setup to dump VPD region */
176 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
177 mb->mbxCommand = MBX_DUMP_MEMORY;
178 mb->mbxOwner = OWN_HOST;
179 mb->un.varDmp.cv = 1;
180 mb->un.varDmp.type = DMP_NV_PARAMS;
181 mb->un.varDmp.entry_index = 0;
182 mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
183 mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
184 mb->un.varDmp.co = 0;
185 mb->un.varDmp.resp_offset = 0;
186 pmb->context2 = ctx;
187 return;
188}
189
190/**
James Smart3621a712009-04-06 18:47:14 -0400191 * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
James Smarte59058c2008-08-24 21:49:00 -0400192 * @phba: pointer to lpfc hba data structure.
193 * @pmb: pointer to the driver internal queue element for mailbox command.
194 *
195 * The read NVRAM mailbox command returns the HBA's non-volatile parameters
196 * that are used as defaults when the Fibre Channel link is brought on-line.
197 *
198 * This routine prepares the mailbox command for reading information stored
199 * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
200 **/
dea31012005-04-17 16:05:31 -0500201void
202lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
203{
204 MAILBOX_t *mb;
205
James Smart04c68492009-05-22 14:52:52 -0400206 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500207 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
208 mb->mbxCommand = MBX_READ_NV;
209 mb->mbxOwner = OWN_HOST;
210 return;
211}
212
James Smarte59058c2008-08-24 21:49:00 -0400213/**
James Smart3621a712009-04-06 18:47:14 -0400214 * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
James Smarte59058c2008-08-24 21:49:00 -0400215 * @phba: pointer to lpfc hba data structure.
216 * @pmb: pointer to the driver internal queue element for mailbox command.
217 * @ring: ring number for the asynchronous event to be configured.
218 *
219 * The asynchronous event enable mailbox command is used to enable the
220 * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
221 * specifies the default ring to which events are posted.
222 *
223 * This routine prepares the mailbox command for enabling HBA asynchronous
224 * event support on a IOCB ring.
225 **/
James Smart57127f12007-10-27 13:37:05 -0400226void
227lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
228 uint32_t ring)
229{
230 MAILBOX_t *mb;
231
James Smart04c68492009-05-22 14:52:52 -0400232 mb = &pmb->u.mb;
James Smart57127f12007-10-27 13:37:05 -0400233 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
234 mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
235 mb->un.varCfgAsyncEvent.ring = ring;
236 mb->mbxOwner = OWN_HOST;
237 return;
238}
239
James Smarte59058c2008-08-24 21:49:00 -0400240/**
James Smart3621a712009-04-06 18:47:14 -0400241 * lpfc_heart_beat - Prepare a mailbox command for heart beat
James Smarte59058c2008-08-24 21:49:00 -0400242 * @phba: pointer to lpfc hba data structure.
243 * @pmb: pointer to the driver internal queue element for mailbox command.
244 *
245 * The heart beat mailbox command is used to detect an unresponsive HBA, which
246 * is defined as any device where no error attention is sent and both mailbox
247 * and rings are not processed.
248 *
249 * This routine prepares the mailbox command for issuing a heart beat in the
250 * form of mailbox command to the HBA. The timely completion of the heart
251 * beat mailbox command indicates the health of the HBA.
252 **/
James Smart858c9f62007-06-17 19:56:39 -0500253void
254lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
255{
256 MAILBOX_t *mb;
257
James Smart04c68492009-05-22 14:52:52 -0400258 mb = &pmb->u.mb;
James Smart858c9f62007-06-17 19:56:39 -0500259 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
260 mb->mbxCommand = MBX_HEARTBEAT;
261 mb->mbxOwner = OWN_HOST;
262 return;
263}
264
James Smarte59058c2008-08-24 21:49:00 -0400265/**
James Smart76a95d72010-11-20 23:11:48 -0500266 * lpfc_read_topology - Prepare a mailbox command for reading HBA topology
James Smarte59058c2008-08-24 21:49:00 -0400267 * @phba: pointer to lpfc hba data structure.
268 * @pmb: pointer to the driver internal queue element for mailbox command.
269 * @mp: DMA buffer memory for reading the link attention information into.
270 *
James Smart76a95d72010-11-20 23:11:48 -0500271 * The read topology mailbox command is issued to read the link topology
272 * information indicated by the HBA port when the Link Event bit of the Host
273 * Attention (HSTATT) register is set to 1 (For SLI-3) or when an FC Link
274 * Attention ACQE is received from the port (For SLI-4). A Link Event
James Smarte59058c2008-08-24 21:49:00 -0400275 * Attention occurs based on an exception detected at the Fibre Channel link
276 * interface.
277 *
James Smart76a95d72010-11-20 23:11:48 -0500278 * This routine prepares the mailbox command for reading HBA link topology
James Smarte59058c2008-08-24 21:49:00 -0400279 * information. A DMA memory has been set aside and address passed to the
280 * HBA through @mp for the HBA to DMA link attention information into the
281 * memory as part of the execution of the mailbox command.
282 *
283 * Return codes
284 * 0 - Success (currently always return 0)
285 **/
dea31012005-04-17 16:05:31 -0500286int
James Smart76a95d72010-11-20 23:11:48 -0500287lpfc_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
288 struct lpfc_dmabuf *mp)
dea31012005-04-17 16:05:31 -0500289{
290 MAILBOX_t *mb;
291 struct lpfc_sli *psli;
292
293 psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -0400294 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500295 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
296
297 INIT_LIST_HEAD(&mp->list);
James Smart76a95d72010-11-20 23:11:48 -0500298 mb->mbxCommand = MBX_READ_TOPOLOGY;
299 mb->un.varReadTop.lilpBde64.tus.f.bdeSize = LPFC_ALPA_MAP_SIZE;
300 mb->un.varReadTop.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
301 mb->un.varReadTop.lilpBde64.addrLow = putPaddrLow(mp->phys);
dea31012005-04-17 16:05:31 -0500302
303 /* Save address for later completion and set the owner to host so that
304 * the FW knows this mailbox is available for processing.
305 */
James Smart76a95d72010-11-20 23:11:48 -0500306 pmb->context1 = (uint8_t *)mp;
dea31012005-04-17 16:05:31 -0500307 mb->mbxOwner = OWN_HOST;
James Smart92d7f7b2007-06-17 19:56:38 -0500308 return (0);
dea31012005-04-17 16:05:31 -0500309}
310
James Smarte59058c2008-08-24 21:49:00 -0400311/**
James Smart3621a712009-04-06 18:47:14 -0400312 * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
James Smarte59058c2008-08-24 21:49:00 -0400313 * @phba: pointer to lpfc hba data structure.
314 * @pmb: pointer to the driver internal queue element for mailbox command.
315 *
316 * The clear link attention mailbox command is issued to clear the link event
317 * attention condition indicated by the Link Event bit of the Host Attention
318 * (HSTATT) register. The link event attention condition is cleared only if
319 * the event tag specified matches that of the current link event counter.
320 * The current event tag is read using the read link attention event mailbox
321 * command.
322 *
323 * This routine prepares the mailbox command for clearing HBA link attention
324 * information.
325 **/
dea31012005-04-17 16:05:31 -0500326void
327lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
328{
329 MAILBOX_t *mb;
330
James Smart04c68492009-05-22 14:52:52 -0400331 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500332 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
333
334 mb->un.varClearLA.eventTag = phba->fc_eventTag;
335 mb->mbxCommand = MBX_CLEAR_LA;
336 mb->mbxOwner = OWN_HOST;
337 return;
338}
339
James Smarte59058c2008-08-24 21:49:00 -0400340/**
James Smart3621a712009-04-06 18:47:14 -0400341 * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
James Smarte59058c2008-08-24 21:49:00 -0400342 * @phba: pointer to lpfc hba data structure.
343 * @pmb: pointer to the driver internal queue element for mailbox command.
344 *
345 * The configure link mailbox command is used before the initialize link
346 * mailbox command to override default value and to configure link-oriented
347 * parameters such as DID address and various timers. Typically, this
348 * command would be used after an F_Port login to set the returned DID address
349 * and the fabric timeout values. This command is not valid before a configure
350 * port command has configured the HBA port.
351 *
352 * This routine prepares the mailbox command for configuring link on a HBA.
353 **/
dea31012005-04-17 16:05:31 -0500354void
355lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
356{
James Smart2e0fef82007-06-17 19:56:36 -0500357 struct lpfc_vport *vport = phba->pport;
James Smart04c68492009-05-22 14:52:52 -0400358 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500359 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
360
361 /* NEW_FEATURE
362 * SLI-2, Coalescing Response Feature.
363 */
364 if (phba->cfg_cr_delay) {
365 mb->un.varCfgLnk.cr = 1;
366 mb->un.varCfgLnk.ci = 1;
367 mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
368 mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
369 }
370
James Smart2e0fef82007-06-17 19:56:36 -0500371 mb->un.varCfgLnk.myId = vport->fc_myDID;
dea31012005-04-17 16:05:31 -0500372 mb->un.varCfgLnk.edtov = phba->fc_edtov;
373 mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
374 mb->un.varCfgLnk.ratov = phba->fc_ratov;
375 mb->un.varCfgLnk.rttov = phba->fc_rttov;
376 mb->un.varCfgLnk.altov = phba->fc_altov;
377 mb->un.varCfgLnk.crtov = phba->fc_crtov;
378 mb->un.varCfgLnk.citov = phba->fc_citov;
379
380 if (phba->cfg_ack0)
381 mb->un.varCfgLnk.ack0_enable = 1;
382
383 mb->mbxCommand = MBX_CONFIG_LINK;
384 mb->mbxOwner = OWN_HOST;
385 return;
386}
387
James Smarte59058c2008-08-24 21:49:00 -0400388/**
James Smart3621a712009-04-06 18:47:14 -0400389 * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
James Smart93996272008-08-24 21:50:30 -0400390 * @phba: pointer to lpfc hba data structure.
391 * @pmb: pointer to the driver internal queue element for mailbox command.
392 *
393 * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
394 * MSI-X multi-message interrupt vector association to interrupt attention
395 * conditions.
396 *
397 * Return codes
398 * 0 - Success
399 * -EINVAL - Failure
400 **/
401int
402lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
403{
James Smart04c68492009-05-22 14:52:52 -0400404 MAILBOX_t *mb = &pmb->u.mb;
James Smart93996272008-08-24 21:50:30 -0400405 uint32_t attentionConditions[2];
406
407 /* Sanity check */
408 if (phba->cfg_use_msi != 2) {
409 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
410 "0475 Not configured for supporting MSI-X "
411 "cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
412 return -EINVAL;
413 }
414
415 if (phba->sli_rev < 3) {
416 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
417 "0476 HBA not supporting SLI-3 or later "
418 "SLI Revision: 0x%x\n", phba->sli_rev);
419 return -EINVAL;
420 }
421
422 /* Clear mailbox command fields */
423 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
424
425 /*
426 * SLI-3, Message Signaled Interrupt Fearure.
427 */
428
429 /* Multi-message attention configuration */
430 attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
431 HA_LATT | HA_MBATT);
432 attentionConditions[1] = 0;
433
434 mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
435 mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
436
437 /*
438 * Set up message number to HA bit association
439 */
440#ifdef __BIG_ENDIAN_BITFIELD
441 /* RA0 (FCP Ring) */
442 mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
443 /* RA1 (Other Protocol Extra Ring) */
444 mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
445#else /* __LITTLE_ENDIAN_BITFIELD */
446 /* RA0 (FCP Ring) */
447 mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
448 /* RA1 (Other Protocol Extra Ring) */
449 mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
450#endif
451 /* Multi-message interrupt autoclear configuration*/
452 mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
453 mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
454
455 /* For now, HBA autoclear does not work reliably, disable it */
456 mb->un.varCfgMSI.autoClearHA[0] = 0;
457 mb->un.varCfgMSI.autoClearHA[1] = 0;
458
459 /* Set command and owner bit */
460 mb->mbxCommand = MBX_CONFIG_MSI;
461 mb->mbxOwner = OWN_HOST;
462
463 return 0;
464}
465
466/**
James Smart3621a712009-04-06 18:47:14 -0400467 * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
James Smarte59058c2008-08-24 21:49:00 -0400468 * @phba: pointer to lpfc hba data structure.
469 * @pmb: pointer to the driver internal queue element for mailbox command.
470 * @topology: the link topology for the link to be initialized to.
471 * @linkspeed: the link speed for the link to be initialized to.
472 *
473 * The initialize link mailbox command is used to initialize the Fibre
474 * Channel link. This command must follow a configure port command that
475 * establishes the mode of operation.
476 *
477 * This routine prepares the mailbox command for initializing link on a HBA
478 * with the specified link topology and speed.
479 **/
dea31012005-04-17 16:05:31 -0500480void
481lpfc_init_link(struct lpfc_hba * phba,
482 LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
483{
484 lpfc_vpd_t *vpd;
485 struct lpfc_sli *psli;
486 MAILBOX_t *mb;
487
James Smart04c68492009-05-22 14:52:52 -0400488 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500489 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
490
491 psli = &phba->sli;
492 switch (topology) {
493 case FLAGS_TOPOLOGY_MODE_LOOP_PT:
494 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
495 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
496 break;
497 case FLAGS_TOPOLOGY_MODE_PT_PT:
498 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
499 break;
500 case FLAGS_TOPOLOGY_MODE_LOOP:
501 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
502 break;
503 case FLAGS_TOPOLOGY_MODE_PT_LOOP:
504 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
505 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
506 break;
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500507 case FLAGS_LOCAL_LB:
508 mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
509 break;
dea31012005-04-17 16:05:31 -0500510 }
511
James Smart4b0b91d2006-04-15 11:53:00 -0400512 /* Enable asynchronous ABTS responses from firmware */
513 mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
514
dea31012005-04-17 16:05:31 -0500515 /* NEW_FEATURE
516 * Setting up the link speed
517 */
518 vpd = &phba->vpd;
519 if (vpd->rev.feaLevelHigh >= 0x02){
James Smart92d7f7b2007-06-17 19:56:38 -0500520 switch(linkspeed){
James Smart76a95d72010-11-20 23:11:48 -0500521 case LPFC_USER_LINK_SPEED_1G:
522 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
523 mb->un.varInitLnk.link_speed = LINK_SPEED_1G;
dea31012005-04-17 16:05:31 -0500524 break;
James Smart76a95d72010-11-20 23:11:48 -0500525 case LPFC_USER_LINK_SPEED_2G:
526 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
527 mb->un.varInitLnk.link_speed = LINK_SPEED_2G;
528 break;
529 case LPFC_USER_LINK_SPEED_4G:
530 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
531 mb->un.varInitLnk.link_speed = LINK_SPEED_4G;
532 break;
533 case LPFC_USER_LINK_SPEED_8G:
534 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
535 mb->un.varInitLnk.link_speed = LINK_SPEED_8G;
536 break;
537 case LPFC_USER_LINK_SPEED_10G:
538 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
539 mb->un.varInitLnk.link_speed = LINK_SPEED_10G;
540 break;
541 case LPFC_USER_LINK_SPEED_16G:
542 mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED;
543 mb->un.varInitLnk.link_speed = LINK_SPEED_16G;
544 break;
545 case LPFC_USER_LINK_SPEED_AUTO:
546 default:
547 mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
dea31012005-04-17 16:05:31 -0500548 break;
549 }
550
551 }
552 else
553 mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
554
555 mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
556 mb->mbxOwner = OWN_HOST;
557 mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
558 return;
559}
560
James Smarte59058c2008-08-24 21:49:00 -0400561/**
James Smart3621a712009-04-06 18:47:14 -0400562 * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
James Smarte59058c2008-08-24 21:49:00 -0400563 * @phba: pointer to lpfc hba data structure.
564 * @pmb: pointer to the driver internal queue element for mailbox command.
565 * @vpi: virtual N_Port identifier.
566 *
567 * The read service parameter mailbox command is used to read the HBA port
568 * service parameters. The service parameters are read into the buffer
569 * specified directly by a BDE in the mailbox command. These service
570 * parameters may then be used to build the payload of an N_Port/F_POrt
571 * login request and reply (LOGI/ACC).
572 *
573 * This routine prepares the mailbox command for reading HBA port service
574 * parameters. The DMA memory is allocated in this function and the addresses
575 * are populated into the mailbox command for the HBA to DMA the service
576 * parameters into.
577 *
578 * Return codes
579 * 0 - Success
580 * 1 - DMA memory allocation failed
581 **/
dea31012005-04-17 16:05:31 -0500582int
James Smart92d7f7b2007-06-17 19:56:38 -0500583lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
dea31012005-04-17 16:05:31 -0500584{
585 struct lpfc_dmabuf *mp;
586 MAILBOX_t *mb;
587 struct lpfc_sli *psli;
588
589 psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -0400590 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500591 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
592
593 mb->mbxOwner = OWN_HOST;
594
595 /* Get a buffer to hold the HBAs Service Parameters */
596
James Smart98c9ea52007-10-27 13:37:33 -0400597 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
598 if (mp)
599 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
600 if (!mp || !mp->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800601 kfree(mp);
dea31012005-04-17 16:05:31 -0500602 mb->mbxCommand = MBX_READ_SPARM64;
603 /* READ_SPARAM: no buffers */
James Smarte8b62012007-08-02 11:10:09 -0400604 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
605 "0301 READ_SPARAM: no buffers\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500606 return (1);
dea31012005-04-17 16:05:31 -0500607 }
608 INIT_LIST_HEAD(&mp->list);
609 mb->mbxCommand = MBX_READ_SPARM64;
610 mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
611 mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
612 mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
James Smart04c68492009-05-22 14:52:52 -0400613 mb->un.varRdSparm.vpi = vpi + phba->vpi_base;
dea31012005-04-17 16:05:31 -0500614
615 /* save address for completion */
616 pmb->context1 = mp;
617
James Smart92d7f7b2007-06-17 19:56:38 -0500618 return (0);
dea31012005-04-17 16:05:31 -0500619}
620
James Smarte59058c2008-08-24 21:49:00 -0400621/**
James Smart3621a712009-04-06 18:47:14 -0400622 * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
James Smarte59058c2008-08-24 21:49:00 -0400623 * @phba: pointer to lpfc hba data structure.
624 * @vpi: virtual N_Port identifier.
625 * @did: remote port identifier.
626 * @pmb: pointer to the driver internal queue element for mailbox command.
627 *
628 * The unregister DID mailbox command is used to unregister an N_Port/F_Port
629 * login for an unknown RPI by specifying the DID of a remote port. This
630 * command frees an RPI context in the HBA port. This has the effect of
631 * performing an implicit N_Port/F_Port logout.
632 *
633 * This routine prepares the mailbox command for unregistering a remote
634 * N_Port/F_Port (DID) login.
635 **/
dea31012005-04-17 16:05:31 -0500636void
James Smart92d7f7b2007-06-17 19:56:38 -0500637lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
638 LPFC_MBOXQ_t * pmb)
dea31012005-04-17 16:05:31 -0500639{
640 MAILBOX_t *mb;
641
James Smart04c68492009-05-22 14:52:52 -0400642 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500643 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
644
645 mb->un.varUnregDID.did = did;
James Smart04c68492009-05-22 14:52:52 -0400646 if (vpi != 0xffff)
647 vpi += phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500648 mb->un.varUnregDID.vpi = vpi;
dea31012005-04-17 16:05:31 -0500649
650 mb->mbxCommand = MBX_UNREG_D_ID;
651 mb->mbxOwner = OWN_HOST;
652 return;
653}
654
James Smarte59058c2008-08-24 21:49:00 -0400655/**
James Smart3621a712009-04-06 18:47:14 -0400656 * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
James Smarte59058c2008-08-24 21:49:00 -0400657 * @phba: pointer to lpfc hba data structure.
658 * @pmb: pointer to the driver internal queue element for mailbox command.
659 *
660 * The read configuration mailbox command is used to read the HBA port
661 * configuration parameters. This mailbox command provides a method for
662 * seeing any parameters that may have changed via various configuration
663 * mailbox commands.
664 *
665 * This routine prepares the mailbox command for reading out HBA configuration
666 * parameters.
667 **/
dea31012005-04-17 16:05:31 -0500668void
669lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
670{
671 MAILBOX_t *mb;
672
James Smart04c68492009-05-22 14:52:52 -0400673 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500674 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
675
676 mb->mbxCommand = MBX_READ_CONFIG;
677 mb->mbxOwner = OWN_HOST;
678 return;
679}
680
James Smarte59058c2008-08-24 21:49:00 -0400681/**
James Smart3621a712009-04-06 18:47:14 -0400682 * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
James Smarte59058c2008-08-24 21:49:00 -0400683 * @phba: pointer to lpfc hba data structure.
684 * @pmb: pointer to the driver internal queue element for mailbox command.
685 *
686 * The read link status mailbox command is used to read the link status from
687 * the HBA. Link status includes all link-related error counters. These
688 * counters are maintained by the HBA and originated in the link hardware
689 * unit. Note that all of these counters wrap.
690 *
691 * This routine prepares the mailbox command for reading out HBA link status.
692 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -0500693void
694lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
695{
696 MAILBOX_t *mb;
697
James Smart04c68492009-05-22 14:52:52 -0400698 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -0500699 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
700
701 mb->mbxCommand = MBX_READ_LNK_STAT;
702 mb->mbxOwner = OWN_HOST;
703 return;
704}
705
James Smarte59058c2008-08-24 21:49:00 -0400706/**
James Smart04c68492009-05-22 14:52:52 -0400707 * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
James Smarte59058c2008-08-24 21:49:00 -0400708 * @phba: pointer to lpfc hba data structure.
709 * @vpi: virtual N_Port identifier.
710 * @did: remote port identifier.
711 * @param: pointer to memory holding the server parameters.
712 * @pmb: pointer to the driver internal queue element for mailbox command.
713 * @flag: action flag to be passed back for the complete function.
714 *
715 * The registration login mailbox command is used to register an N_Port or
716 * F_Port login. This registration allows the HBA to cache the remote N_Port
717 * service parameters internally and thereby make the appropriate FC-2
718 * decisions. The remote port service parameters are handed off by the driver
719 * to the HBA using a descriptor entry that directly identifies a buffer in
720 * host memory. In exchange, the HBA returns an RPI identifier.
721 *
722 * This routine prepares the mailbox command for registering remote port login.
723 * The function allocates DMA buffer for passing the service parameters to the
724 * HBA with the mailbox command.
725 *
726 * Return codes
727 * 0 - Success
728 * 1 - DMA memory allocation failed
729 **/
dea31012005-04-17 16:05:31 -0500730int
James Smart04c68492009-05-22 14:52:52 -0400731lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
James Smart92d7f7b2007-06-17 19:56:38 -0500732 uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
dea31012005-04-17 16:05:31 -0500733{
James Smart04c68492009-05-22 14:52:52 -0400734 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500735 uint8_t *sparam;
736 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -0500737
dea31012005-04-17 16:05:31 -0500738 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
739
740 mb->un.varRegLogin.rpi = 0;
James Smart04c68492009-05-22 14:52:52 -0400741 if (phba->sli_rev == LPFC_SLI_REV4) {
742 mb->un.varRegLogin.rpi = lpfc_sli4_alloc_rpi(phba);
743 if (mb->un.varRegLogin.rpi == LPFC_RPI_ALLOC_ERROR)
744 return 1;
745 }
746
747 mb->un.varRegLogin.vpi = vpi + phba->vpi_base;
dea31012005-04-17 16:05:31 -0500748 mb->un.varRegLogin.did = did;
749 mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */
750
751 mb->mbxOwner = OWN_HOST;
752
753 /* Get a buffer to hold NPorts Service Parameters */
James Smart98c9ea52007-10-27 13:37:33 -0400754 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
755 if (mp)
756 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
757 if (!mp || !mp->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800758 kfree(mp);
dea31012005-04-17 16:05:31 -0500759 mb->mbxCommand = MBX_REG_LOGIN64;
760 /* REG_LOGIN: no buffers */
James Smart92d7f7b2007-06-17 19:56:38 -0500761 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400762 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
763 "flag x%x\n", vpi, did, flag);
James Smart92d7f7b2007-06-17 19:56:38 -0500764 return (1);
dea31012005-04-17 16:05:31 -0500765 }
766 INIT_LIST_HEAD(&mp->list);
767 sparam = mp->virt;
768
769 /* Copy param's into a new buffer */
770 memcpy(sparam, param, sizeof (struct serv_parm));
771
772 /* save address for completion */
773 pmb->context1 = (uint8_t *) mp;
774
775 mb->mbxCommand = MBX_REG_LOGIN64;
776 mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
777 mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
778 mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
779
James Smart92d7f7b2007-06-17 19:56:38 -0500780 return (0);
dea31012005-04-17 16:05:31 -0500781}
782
James Smarte59058c2008-08-24 21:49:00 -0400783/**
James Smart3621a712009-04-06 18:47:14 -0400784 * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
James Smarte59058c2008-08-24 21:49:00 -0400785 * @phba: pointer to lpfc hba data structure.
786 * @vpi: virtual N_Port identifier.
787 * @rpi: remote port identifier
788 * @pmb: pointer to the driver internal queue element for mailbox command.
789 *
790 * The unregistration login mailbox command is used to unregister an N_Port
791 * or F_Port login. This command frees an RPI context in the HBA. It has the
792 * effect of performing an implicit N_Port/F_Port logout.
793 *
794 * This routine prepares the mailbox command for unregistering remote port
795 * login.
796 **/
dea31012005-04-17 16:05:31 -0500797void
James Smart92d7f7b2007-06-17 19:56:38 -0500798lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
799 LPFC_MBOXQ_t * pmb)
dea31012005-04-17 16:05:31 -0500800{
801 MAILBOX_t *mb;
802
James Smart04c68492009-05-22 14:52:52 -0400803 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500804 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
805
806 mb->un.varUnregLogin.rpi = (uint16_t) rpi;
807 mb->un.varUnregLogin.rsvd1 = 0;
James Smart04c68492009-05-22 14:52:52 -0400808 mb->un.varUnregLogin.vpi = vpi + phba->vpi_base;
dea31012005-04-17 16:05:31 -0500809
810 mb->mbxCommand = MBX_UNREG_LOGIN;
811 mb->mbxOwner = OWN_HOST;
James Smart04c68492009-05-22 14:52:52 -0400812
dea31012005-04-17 16:05:31 -0500813 return;
814}
815
James Smarte59058c2008-08-24 21:49:00 -0400816/**
James Smart5af5eee2010-10-22 11:06:38 -0400817 * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA.
818 * @vport: pointer to a vport object.
819 *
820 * This routine sends mailbox command to unregister all active RPIs for
821 * a vport.
822 **/
823void
824lpfc_sli4_unreg_all_rpis(struct lpfc_vport *vport)
825{
826 struct lpfc_hba *phba = vport->phba;
827 LPFC_MBOXQ_t *mbox;
828 int rc;
829
830 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
831 if (mbox) {
832 lpfc_unreg_login(phba, vport->vpi,
833 vport->vpi + phba->vpi_base, mbox);
834 mbox->u.mb.un.varUnregLogin.rsvd1 = 0x4000 ;
835 mbox->vport = vport;
836 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
837 mbox->context1 = NULL;
838 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
839 if (rc == MBX_NOT_FINISHED)
840 mempool_free(mbox, phba->mbox_mem_pool);
841 }
842}
843
844/**
James Smart3621a712009-04-06 18:47:14 -0400845 * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
James Smarte59058c2008-08-24 21:49:00 -0400846 * @phba: pointer to lpfc hba data structure.
847 * @vpi: virtual N_Port identifier.
848 * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
849 * @pmb: pointer to the driver internal queue element for mailbox command.
850 *
851 * The registration vport identifier mailbox command is used to activate a
852 * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
853 * N_Port_ID against the information in the selected virtual N_Port context
854 * block and marks it active to allow normal processing of IOCB commands and
855 * received unsolicited exchanges.
856 *
857 * This routine prepares the mailbox command for registering a virtual N_Port.
858 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500859void
James Smart04c68492009-05-22 14:52:52 -0400860lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
James Smart92d7f7b2007-06-17 19:56:38 -0500861{
James Smart04c68492009-05-22 14:52:52 -0400862 MAILBOX_t *mb = &pmb->u.mb;
James Smart38b92ef2010-08-04 16:11:39 -0400863 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500864
865 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
James Smart38b92ef2010-08-04 16:11:39 -0400866 /*
867 * Set the re-reg VPI bit for f/w to update the MAC address.
868 */
869 if ((phba->sli_rev == LPFC_SLI_REV4) &&
870 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI))
871 mb->un.varRegVpi.upd = 1;
James Smart04c68492009-05-22 14:52:52 -0400872 mb->un.varRegVpi.vpi = vport->vpi + vport->phba->vpi_base;
873 mb->un.varRegVpi.sid = vport->fc_myDID;
874 mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
James Smartc8685952009-11-18 15:39:16 -0500875 memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname,
876 sizeof(struct lpfc_name));
877 mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]);
878 mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]);
James Smart92d7f7b2007-06-17 19:56:38 -0500879
880 mb->mbxCommand = MBX_REG_VPI;
881 mb->mbxOwner = OWN_HOST;
882 return;
883
884}
885
James Smarte59058c2008-08-24 21:49:00 -0400886/**
James Smart3621a712009-04-06 18:47:14 -0400887 * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
James Smarte59058c2008-08-24 21:49:00 -0400888 * @phba: pointer to lpfc hba data structure.
889 * @vpi: virtual N_Port identifier.
890 * @pmb: pointer to the driver internal queue element for mailbox command.
891 *
892 * The unregistration vport identifier mailbox command is used to inactivate
893 * a virtual N_Port. The driver must have logged out and unregistered all
894 * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
895 * unregisters any default RPIs associated with the specified vpi, aborting
896 * any active exchanges. The HBA will post the mailbox response after making
897 * the virtual N_Port inactive.
898 *
899 * This routine prepares the mailbox command for unregistering a virtual
900 * N_Port.
901 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500902void
903lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
904{
James Smart04c68492009-05-22 14:52:52 -0400905 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500906 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
907
James Smart6669f9b2009-10-02 15:16:45 -0400908 if (phba->sli_rev < LPFC_SLI_REV4)
909 mb->un.varUnregVpi.vpi = vpi + phba->vpi_base;
910 else
911 mb->un.varUnregVpi.sli4_vpi = vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500912
913 mb->mbxCommand = MBX_UNREG_VPI;
914 mb->mbxOwner = OWN_HOST;
915 return;
916
917}
918
James Smarte59058c2008-08-24 21:49:00 -0400919/**
James Smart3621a712009-04-06 18:47:14 -0400920 * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
James Smarte59058c2008-08-24 21:49:00 -0400921 * @phba: pointer to lpfc hba data structure.
922 *
923 * This routine sets up and initializes the IOCB rings in the Port Control
924 * Block (PCB).
925 **/
dea31012005-04-17 16:05:31 -0500926static void
927lpfc_config_pcb_setup(struct lpfc_hba * phba)
928{
929 struct lpfc_sli *psli = &phba->sli;
930 struct lpfc_sli_ring *pring;
James Smart34b02dc2008-08-24 21:49:55 -0400931 PCB_t *pcbp = phba->pcb;
dea31012005-04-17 16:05:31 -0500932 dma_addr_t pdma_addr;
933 uint32_t offset;
James Smart2e0fef82007-06-17 19:56:36 -0500934 uint32_t iocbCnt = 0;
dea31012005-04-17 16:05:31 -0500935 int i;
936
dea31012005-04-17 16:05:31 -0500937 pcbp->maxRing = (psli->num_rings - 1);
938
dea31012005-04-17 16:05:31 -0500939 for (i = 0; i < psli->num_rings; i++) {
940 pring = &psli->ring[i];
James Smart2e0fef82007-06-17 19:56:36 -0500941
James Smarted957682007-06-17 19:56:37 -0500942 pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
James Smart92d7f7b2007-06-17 19:56:38 -0500943 SLI2_IOCB_CMD_SIZE;
James Smarted957682007-06-17 19:56:37 -0500944 pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
James Smart92d7f7b2007-06-17 19:56:38 -0500945 SLI2_IOCB_RSP_SIZE;
dea31012005-04-17 16:05:31 -0500946 /* A ring MUST have both cmd and rsp entries defined to be
947 valid */
948 if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
949 pcbp->rdsc[i].cmdEntries = 0;
950 pcbp->rdsc[i].rspEntries = 0;
951 pcbp->rdsc[i].cmdAddrHigh = 0;
952 pcbp->rdsc[i].rspAddrHigh = 0;
953 pcbp->rdsc[i].cmdAddrLow = 0;
954 pcbp->rdsc[i].rspAddrLow = 0;
955 pring->cmdringaddr = NULL;
956 pring->rspringaddr = NULL;
957 continue;
958 }
959 /* Command ring setup for ring */
James Smart34b02dc2008-08-24 21:49:55 -0400960 pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
dea31012005-04-17 16:05:31 -0500961 pcbp->rdsc[i].cmdEntries = pring->numCiocb;
962
James Smart34b02dc2008-08-24 21:49:55 -0400963 offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
964 (uint8_t *) phba->slim2p.virt;
965 pdma_addr = phba->slim2p.phys + offset;
dea31012005-04-17 16:05:31 -0500966 pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
967 pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
968 iocbCnt += pring->numCiocb;
969
970 /* Response ring setup for ring */
James Smart34b02dc2008-08-24 21:49:55 -0400971 pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt];
dea31012005-04-17 16:05:31 -0500972
973 pcbp->rdsc[i].rspEntries = pring->numRiocb;
James Smart34b02dc2008-08-24 21:49:55 -0400974 offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
975 (uint8_t *)phba->slim2p.virt;
976 pdma_addr = phba->slim2p.phys + offset;
dea31012005-04-17 16:05:31 -0500977 pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
978 pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
979 iocbCnt += pring->numRiocb;
980 }
981}
982
James Smarte59058c2008-08-24 21:49:00 -0400983/**
James Smart3621a712009-04-06 18:47:14 -0400984 * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
James Smarte59058c2008-08-24 21:49:00 -0400985 * @phba: pointer to lpfc hba data structure.
986 * @pmb: pointer to the driver internal queue element for mailbox command.
987 *
988 * The read revision mailbox command is used to read the revision levels of
989 * the HBA components. These components include hardware units, resident
990 * firmware, and available firmware. HBAs that supports SLI-3 mode of
991 * operation provide different response information depending on the version
992 * requested by the driver.
993 *
994 * This routine prepares the mailbox command for reading HBA revision
995 * information.
996 **/
dea31012005-04-17 16:05:31 -0500997void
998lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
999{
James Smart04c68492009-05-22 14:52:52 -04001000 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001001 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1002 mb->un.varRdRev.cv = 1;
James Smarted957682007-06-17 19:56:37 -05001003 mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
dea31012005-04-17 16:05:31 -05001004 mb->mbxCommand = MBX_READ_REV;
1005 mb->mbxOwner = OWN_HOST;
1006 return;
1007}
1008
James Smartd7c47992010-06-08 18:31:54 -04001009void
1010lpfc_sli4_swap_str(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1011{
1012 MAILBOX_t *mb = &pmb->u.mb;
1013 struct lpfc_mqe *mqe;
1014
1015 switch (mb->mbxCommand) {
1016 case MBX_READ_REV:
1017 mqe = &pmb->u.mqe;
1018 lpfc_sli_pcimem_bcopy(mqe->un.read_rev.fw_name,
1019 mqe->un.read_rev.fw_name, 16);
1020 lpfc_sli_pcimem_bcopy(mqe->un.read_rev.ulp_fw_name,
1021 mqe->un.read_rev.ulp_fw_name, 16);
1022 break;
1023 default:
1024 break;
1025 }
1026 return;
1027}
1028
James Smarte59058c2008-08-24 21:49:00 -04001029/**
James Smart3621a712009-04-06 18:47:14 -04001030 * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
James Smarte59058c2008-08-24 21:49:00 -04001031 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1032 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1033 *
1034 * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
1035 * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
1036 * the Sequence Length Test using the fields in the Selection Profile 2
1037 * extension in words 20:31.
1038 **/
James Smarted957682007-06-17 19:56:37 -05001039static void
1040lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
1041 struct lpfc_hbq_init *hbq_desc)
1042{
1043 hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
1044 hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
1045 hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
1046}
1047
James Smarte59058c2008-08-24 21:49:00 -04001048/**
James Smart3621a712009-04-06 18:47:14 -04001049 * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
James Smarte59058c2008-08-24 21:49:00 -04001050 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1051 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1052 *
1053 * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
1054 * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
1055 * the Sequence Length Test and Byte Field Test using the fields in the
1056 * Selection Profile 3 extension in words 20:31.
1057 **/
James Smarted957682007-06-17 19:56:37 -05001058static void
1059lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
1060 struct lpfc_hbq_init *hbq_desc)
1061{
1062 hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
1063 hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
1064 hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
1065 hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
1066 memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
1067 sizeof(hbqmb->profiles.profile3.cmdmatch));
1068}
1069
James Smarte59058c2008-08-24 21:49:00 -04001070/**
James Smart3621a712009-04-06 18:47:14 -04001071 * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
James Smarte59058c2008-08-24 21:49:00 -04001072 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1073 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1074 *
1075 * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
1076 * HBA tests the initial frame of an incoming sequence using the frame's
1077 * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
1078 * and Byte Field Test using the fields in the Selection Profile 5 extension
1079 * words 20:31.
1080 **/
James Smarted957682007-06-17 19:56:37 -05001081static void
1082lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
1083 struct lpfc_hbq_init *hbq_desc)
1084{
1085 hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
1086 hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
1087 hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
1088 hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
1089 memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
1090 sizeof(hbqmb->profiles.profile5.cmdmatch));
1091}
1092
James Smarte59058c2008-08-24 21:49:00 -04001093/**
James Smart3621a712009-04-06 18:47:14 -04001094 * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
James Smarte59058c2008-08-24 21:49:00 -04001095 * @phba: pointer to lpfc hba data structure.
1096 * @id: HBQ identifier.
1097 * @hbq_desc: pointer to the HBA descriptor data structure.
1098 * @hbq_entry_index: index of the HBQ entry data structures.
1099 * @pmb: pointer to the driver internal queue element for mailbox command.
1100 *
1101 * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
1102 * an HBQ. The configuration binds events that require buffers to a particular
1103 * ring and HBQ based on a selection profile.
1104 *
1105 * This routine prepares the mailbox command for configuring an HBQ.
1106 **/
James Smarted957682007-06-17 19:56:37 -05001107void
James Smart51ef4c22007-08-02 11:10:31 -04001108lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
1109 struct lpfc_hbq_init *hbq_desc,
James Smarted957682007-06-17 19:56:37 -05001110 uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
1111{
1112 int i;
James Smart04c68492009-05-22 14:52:52 -04001113 MAILBOX_t *mb = &pmb->u.mb;
James Smarted957682007-06-17 19:56:37 -05001114 struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
1115
1116 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
James Smart51ef4c22007-08-02 11:10:31 -04001117 hbqmb->hbqId = id;
James Smarted957682007-06-17 19:56:37 -05001118 hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
1119 hbqmb->recvNotify = hbq_desc->rn; /* Receive
1120 * Notification */
1121 hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
1122 * # in words 0-19 */
James Smart92d7f7b2007-06-17 19:56:38 -05001123 hbqmb->profile = hbq_desc->profile; /* Selection profile:
James Smarted957682007-06-17 19:56:37 -05001124 * 0 = all,
1125 * 7 = logentry */
1126 hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
1127 * e.g. Ring0=b0001,
1128 * ring2=b0100 */
1129 hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
1130 * or 5 */
1131 hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
1132 * HBQ will be used
1133 * for LogEntry
1134 * buffers */
1135 hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
1136 hbq_entry_index * sizeof(struct lpfc_hbq_entry);
1137 hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
1138
1139 mb->mbxCommand = MBX_CONFIG_HBQ;
1140 mb->mbxOwner = OWN_HOST;
1141
James Smart92d7f7b2007-06-17 19:56:38 -05001142 /* Copy info for profiles 2,3,5. Other
1143 * profiles this area is reserved
1144 */
James Smarted957682007-06-17 19:56:37 -05001145 if (hbq_desc->profile == 2)
1146 lpfc_build_hbq_profile2(hbqmb, hbq_desc);
1147 else if (hbq_desc->profile == 3)
1148 lpfc_build_hbq_profile3(hbqmb, hbq_desc);
1149 else if (hbq_desc->profile == 5)
1150 lpfc_build_hbq_profile5(hbqmb, hbq_desc);
1151
1152 /* Return if no rctl / type masks for this HBQ */
1153 if (!hbq_desc->mask_count)
1154 return;
1155
1156 /* Otherwise we setup specific rctl / type masks for this HBQ */
1157 for (i = 0; i < hbq_desc->mask_count; i++) {
1158 hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
1159 hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
1160 hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
1161 hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
1162 }
1163
1164 return;
1165}
1166
James Smarte59058c2008-08-24 21:49:00 -04001167/**
James Smart3621a712009-04-06 18:47:14 -04001168 * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04001169 * @phba: pointer to lpfc hba data structure.
1170 * @ring:
1171 * @pmb: pointer to the driver internal queue element for mailbox command.
1172 *
1173 * The configure ring mailbox command is used to configure an IOCB ring. This
1174 * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1175 * ring. This is used to map incoming sequences to a particular ring whose
1176 * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1177 * attempt to configure a ring whose number is greater than the number
1178 * specified in the Port Control Block (PCB). It is an error to issue the
1179 * configure ring command more than once with the same ring number. The HBA
1180 * returns an error if the driver attempts this.
1181 *
1182 * This routine prepares the mailbox command for configuring IOCB ring.
1183 **/
dea31012005-04-17 16:05:31 -05001184void
1185lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
1186{
1187 int i;
James Smart04c68492009-05-22 14:52:52 -04001188 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001189 struct lpfc_sli *psli;
1190 struct lpfc_sli_ring *pring;
1191
1192 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1193
1194 mb->un.varCfgRing.ring = ring;
1195 mb->un.varCfgRing.maxOrigXchg = 0;
1196 mb->un.varCfgRing.maxRespXchg = 0;
1197 mb->un.varCfgRing.recvNotify = 1;
1198
1199 psli = &phba->sli;
1200 pring = &psli->ring[ring];
1201 mb->un.varCfgRing.numMask = pring->num_mask;
1202 mb->mbxCommand = MBX_CONFIG_RING;
1203 mb->mbxOwner = OWN_HOST;
1204
1205 /* Is this ring configured for a specific profile */
1206 if (pring->prt[0].profile) {
1207 mb->un.varCfgRing.profile = pring->prt[0].profile;
1208 return;
1209 }
1210
1211 /* Otherwise we setup specific rctl / type masks for this ring */
1212 for (i = 0; i < pring->num_mask; i++) {
1213 mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
James Smart6a9c52c2009-10-02 15:16:51 -04001214 if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ)
dea31012005-04-17 16:05:31 -05001215 mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
1216 else
1217 mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
1218 mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
1219 mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
1220 }
1221
1222 return;
1223}
1224
James Smarte59058c2008-08-24 21:49:00 -04001225/**
James Smart3621a712009-04-06 18:47:14 -04001226 * lpfc_config_port - Prepare a mailbox command for configuring port
James Smarte59058c2008-08-24 21:49:00 -04001227 * @phba: pointer to lpfc hba data structure.
1228 * @pmb: pointer to the driver internal queue element for mailbox command.
1229 *
1230 * The configure port mailbox command is used to identify the Port Control
1231 * Block (PCB) in the driver memory. After this command is issued, the
1232 * driver must not access the mailbox in the HBA without first resetting
1233 * the HBA. The HBA may copy the PCB information to internal storage for
1234 * subsequent use; the driver can not change the PCB information unless it
1235 * resets the HBA.
1236 *
1237 * This routine prepares the mailbox command for configuring port.
1238 **/
dea31012005-04-17 16:05:31 -05001239void
James Smart92d7f7b2007-06-17 19:56:38 -05001240lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001241{
James Smarted957682007-06-17 19:56:37 -05001242 MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
James Smart04c68492009-05-22 14:52:52 -04001243 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001244 dma_addr_t pdma_addr;
1245 uint32_t bar_low, bar_high;
1246 size_t offset;
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04001247 struct lpfc_hgp hgp;
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001248 int i;
James Smarted957682007-06-17 19:56:37 -05001249 uint32_t pgp_offset;
dea31012005-04-17 16:05:31 -05001250
1251 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1252 mb->mbxCommand = MBX_CONFIG_PORT;
1253 mb->mbxOwner = OWN_HOST;
1254
1255 mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
1256
James Smart34b02dc2008-08-24 21:49:55 -04001257 offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
1258 pdma_addr = phba->slim2p.phys + offset;
dea31012005-04-17 16:05:31 -05001259 mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
1260 mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
1261
James Smart97207482008-12-04 22:39:19 -05001262 /* Always Host Group Pointer is in SLIM */
1263 mb->un.varCfgPort.hps = 1;
1264
James Smarted957682007-06-17 19:56:37 -05001265 /* If HBA supports SLI=3 ask for it */
1266
James Smart04c68492009-05-22 14:52:52 -04001267 if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
James Smarte2a0a9d2008-12-04 22:40:02 -05001268 if (phba->cfg_enable_bg)
1269 mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
James Smart04c68492009-05-22 14:52:52 -04001270 mb->un.varCfgPort.cdss = 1; /* Configure Security */
James Smarted957682007-06-17 19:56:37 -05001271 mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
James Smart34b02dc2008-08-24 21:49:55 -04001272 mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
James Smart51ef4c22007-08-02 11:10:31 -04001273 mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
James Smart78b2d852007-08-02 11:10:21 -04001274 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smart92d7f7b2007-06-17 19:56:38 -05001275 phba->vpd.sli3Feat.cmv) {
James Smart04c68492009-05-22 14:52:52 -04001276 mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI;
James Smart92d7f7b2007-06-17 19:56:38 -05001277 mb->un.varCfgPort.cmv = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001278 } else
1279 mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
1280 } else
James Smart04c68492009-05-22 14:52:52 -04001281 phba->sli_rev = LPFC_SLI_REV2;
James Smart92d7f7b2007-06-17 19:56:38 -05001282 mb->un.varCfgPort.sli_mode = phba->sli_rev;
James Smarted957682007-06-17 19:56:37 -05001283
dea31012005-04-17 16:05:31 -05001284 /* Now setup pcb */
James Smart34b02dc2008-08-24 21:49:55 -04001285 phba->pcb->type = TYPE_NATIVE_SLI2;
1286 phba->pcb->feature = FEATURE_INITIAL_SLI2;
dea31012005-04-17 16:05:31 -05001287
1288 /* Setup Mailbox pointers */
James Smart7a470272010-03-15 11:25:20 -04001289 phba->pcb->mailBoxSize = sizeof(MAILBOX_t) + MAILBOX_EXT_SIZE;
James Smart34b02dc2008-08-24 21:49:55 -04001290 offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
1291 pdma_addr = phba->slim2p.phys + offset;
1292 phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
1293 phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
dea31012005-04-17 16:05:31 -05001294
1295 /*
1296 * Setup Host Group ring pointer.
1297 *
1298 * For efficiency reasons, the ring get/put pointers can be
1299 * placed in adapter memory (SLIM) rather than in host memory.
1300 * This allows firmware to avoid PCI reads/writes when updating
1301 * and checking pointers.
1302 *
1303 * The firmware recognizes the use of SLIM memory by comparing
1304 * the address of the get/put pointers structure with that of
1305 * the SLIM BAR (BAR0).
1306 *
1307 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1308 * (the hardware's view of the base address), not the OS's
1309 * value of pci_resource_start() as the OS value may be a cookie
1310 * for ioremap/iomap.
1311 */
1312
1313
1314 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
1315 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
1316
James Smarted957682007-06-17 19:56:37 -05001317 /*
1318 * Set up HGP - Port Memory
1319 *
1320 * The port expects the host get/put pointers to reside in memory
1321 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1322 * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
1323 * words (0x40 bytes). This area is not reserved if HBQs are
1324 * configured in SLI-3.
1325 *
1326 * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1327 * RR0Get 0xc4 0x84
1328 * CR1Put 0xc8 0x88
1329 * RR1Get 0xcc 0x8c
1330 * CR2Put 0xd0 0x90
1331 * RR2Get 0xd4 0x94
1332 * CR3Put 0xd8 0x98
1333 * RR3Get 0xdc 0x9c
1334 *
1335 * Reserved 0xa0-0xbf
1336 * If HBQs configured:
1337 * HBQ 0 Put ptr 0xc0
1338 * HBQ 1 Put ptr 0xc4
1339 * HBQ 2 Put ptr 0xc8
1340 * ......
1341 * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1342 *
1343 */
1344
James Smart7a470272010-03-15 11:25:20 -04001345 if (phba->cfg_hostmem_hgp && phba->sli_rev != 3) {
1346 phba->host_gp = &phba->mbox->us.s2.host[0];
James Smarted957682007-06-17 19:56:37 -05001347 phba->hbq_put = NULL;
James Smart7a470272010-03-15 11:25:20 -04001348 offset = (uint8_t *)&phba->mbox->us.s2.host -
1349 (uint8_t *)phba->slim2p.virt;
1350 pdma_addr = phba->slim2p.phys + offset;
1351 phba->pcb->hgpAddrHigh = putPaddrHigh(pdma_addr);
1352 phba->pcb->hgpAddrLow = putPaddrLow(pdma_addr);
1353 } else {
1354 /* Always Host Group Pointer is in SLIM */
1355 mb->un.varCfgPort.hps = 1;
dea31012005-04-17 16:05:31 -05001356
James Smart7a470272010-03-15 11:25:20 -04001357 if (phba->sli_rev == 3) {
1358 phba->host_gp = &mb_slim->us.s3.host[0];
1359 phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
1360 } else {
1361 phba->host_gp = &mb_slim->us.s2.host[0];
1362 phba->hbq_put = NULL;
1363 }
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001364
James Smart7a470272010-03-15 11:25:20 -04001365 /* mask off BAR0's flag bits 0 - 3 */
1366 phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
1367 (void __iomem *)phba->host_gp -
1368 (void __iomem *)phba->MBslimaddr;
1369 if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
1370 phba->pcb->hgpAddrHigh = bar_high;
1371 else
1372 phba->pcb->hgpAddrHigh = 0;
1373 /* write HGP data to SLIM at the required longword offset */
1374 memset(&hgp, 0, sizeof(struct lpfc_hgp));
1375
1376 for (i = 0; i < phba->sli.num_rings; i++) {
1377 lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
James Smarted957682007-06-17 19:56:37 -05001378 sizeof(*phba->host_gp));
James Smart7a470272010-03-15 11:25:20 -04001379 }
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001380 }
dea31012005-04-17 16:05:31 -05001381
James Smart8f34f4c2008-12-04 22:39:23 -05001382 /* Setup Port Group offset */
1383 if (phba->sli_rev == 3)
James Smart34b02dc2008-08-24 21:49:55 -04001384 pgp_offset = offsetof(struct lpfc_sli2_slim,
1385 mbx.us.s3_pgp.port);
James Smart8f34f4c2008-12-04 22:39:23 -05001386 else
James Smart34b02dc2008-08-24 21:49:55 -04001387 pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
1388 pdma_addr = phba->slim2p.phys + pgp_offset;
1389 phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
1390 phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
dea31012005-04-17 16:05:31 -05001391
1392 /* Use callback routine to setp rings in the pcb */
1393 lpfc_config_pcb_setup(phba);
1394
1395 /* special handling for LC HBAs */
1396 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
1397 uint32_t hbainit[5];
1398
1399 lpfc_hba_init(phba, hbainit);
1400
1401 memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
1402 }
1403
1404 /* Swap PCB if needed */
James Smart34b02dc2008-08-24 21:49:55 -04001405 lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
dea31012005-04-17 16:05:31 -05001406}
1407
James Smarte59058c2008-08-24 21:49:00 -04001408/**
James Smart3621a712009-04-06 18:47:14 -04001409 * lpfc_kill_board - Prepare a mailbox command for killing board
James Smarte59058c2008-08-24 21:49:00 -04001410 * @phba: pointer to lpfc hba data structure.
1411 * @pmb: pointer to the driver internal queue element for mailbox command.
1412 *
1413 * The kill board mailbox command is used to tell firmware to perform a
1414 * graceful shutdown of a channel on a specified board to prepare for reset.
1415 * When the kill board mailbox command is received, the ER3 bit is set to 1
1416 * in the Host Status register and the ER Attention bit is set to 1 in the
1417 * Host Attention register of the HBA function that received the kill board
1418 * command.
1419 *
1420 * This routine prepares the mailbox command for killing the board in
1421 * preparation for a graceful shutdown.
1422 **/
dea31012005-04-17 16:05:31 -05001423void
Jamie Wellnitz41415862006-02-28 19:25:27 -05001424lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1425{
James Smart04c68492009-05-22 14:52:52 -04001426 MAILBOX_t *mb = &pmb->u.mb;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001427
1428 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1429 mb->mbxCommand = MBX_KILL_BOARD;
1430 mb->mbxOwner = OWN_HOST;
1431 return;
1432}
1433
James Smarte59058c2008-08-24 21:49:00 -04001434/**
James Smart3621a712009-04-06 18:47:14 -04001435 * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
James Smarte59058c2008-08-24 21:49:00 -04001436 * @phba: pointer to lpfc hba data structure.
1437 * @mbq: pointer to the driver internal queue element for mailbox command.
1438 *
1439 * Driver maintains a internal mailbox command queue implemented as a linked
1440 * list. When a mailbox command is issued, it shall be put into the mailbox
1441 * command queue such that they shall be processed orderly as HBA can process
1442 * one mailbox command at a time.
1443 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001444void
dea31012005-04-17 16:05:31 -05001445lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1446{
1447 struct lpfc_sli *psli;
1448
1449 psli = &phba->sli;
1450
1451 list_add_tail(&mbq->list, &psli->mboxq);
1452
1453 psli->mboxq_cnt++;
1454
1455 return;
1456}
1457
James Smarte59058c2008-08-24 21:49:00 -04001458/**
James Smart3621a712009-04-06 18:47:14 -04001459 * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
James Smarte59058c2008-08-24 21:49:00 -04001460 * @phba: pointer to lpfc hba data structure.
1461 *
1462 * Driver maintains a internal mailbox command queue implemented as a linked
1463 * list. When a mailbox command is issued, it shall be put into the mailbox
1464 * command queue such that they shall be processed orderly as HBA can process
1465 * one mailbox command at a time. After HBA finished processing a mailbox
1466 * command, the driver will remove a pending mailbox command from the head of
1467 * the mailbox command queue and send to the HBA for processing.
1468 *
1469 * Return codes
1470 * pointer to the driver internal queue element for mailbox command.
1471 **/
dea31012005-04-17 16:05:31 -05001472LPFC_MBOXQ_t *
1473lpfc_mbox_get(struct lpfc_hba * phba)
1474{
1475 LPFC_MBOXQ_t *mbq = NULL;
1476 struct lpfc_sli *psli = &phba->sli;
1477
James Smart2e0fef82007-06-17 19:56:36 -05001478 list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
James Smart92d7f7b2007-06-17 19:56:38 -05001479 if (mbq)
dea31012005-04-17 16:05:31 -05001480 psli->mboxq_cnt--;
dea31012005-04-17 16:05:31 -05001481
1482 return mbq;
1483}
James Smarta309a6b2006-08-01 07:33:43 -04001484
James Smarte59058c2008-08-24 21:49:00 -04001485/**
James Smart04c68492009-05-22 14:52:52 -04001486 * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
1487 * @phba: pointer to lpfc hba data structure.
1488 * @mbq: pointer to the driver internal queue element for mailbox command.
1489 *
1490 * This routine put the completed mailbox command into the mailbox command
1491 * complete list. This is the unlocked version of the routine. The mailbox
1492 * complete list is used by the driver worker thread to process mailbox
1493 * complete callback functions outside the driver interrupt handler.
1494 **/
1495void
1496__lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
1497{
1498 list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
1499}
1500
1501/**
James Smart3621a712009-04-06 18:47:14 -04001502 * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
James Smarte59058c2008-08-24 21:49:00 -04001503 * @phba: pointer to lpfc hba data structure.
1504 * @mbq: pointer to the driver internal queue element for mailbox command.
1505 *
1506 * This routine put the completed mailbox command into the mailbox command
James Smart04c68492009-05-22 14:52:52 -04001507 * complete list. This is the locked version of the routine. The mailbox
1508 * complete list is used by the driver worker thread to process mailbox
1509 * complete callback functions outside the driver interrupt handler.
James Smarte59058c2008-08-24 21:49:00 -04001510 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001511void
James Smart04c68492009-05-22 14:52:52 -04001512lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
James Smart92d7f7b2007-06-17 19:56:38 -05001513{
James Smart5b75da22008-12-04 22:39:35 -05001514 unsigned long iflag;
1515
Joe Perchesb1c11812008-02-03 17:28:22 +02001516 /* This function expects to be called from interrupt context */
James Smart5b75da22008-12-04 22:39:35 -05001517 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart04c68492009-05-22 14:52:52 -04001518 __lpfc_mbox_cmpl_put(phba, mbq);
James Smart5b75da22008-12-04 22:39:35 -05001519 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05001520 return;
1521}
1522
James Smarte59058c2008-08-24 21:49:00 -04001523/**
James Smart04c68492009-05-22 14:52:52 -04001524 * lpfc_mbox_cmd_check - Check the validality of a mailbox command
1525 * @phba: pointer to lpfc hba data structure.
1526 * @mboxq: pointer to the driver internal queue element for mailbox command.
1527 *
1528 * This routine is to check whether a mailbox command is valid to be issued.
1529 * This check will be performed by both the mailbox issue API when a client
1530 * is to issue a mailbox command to the mailbox transport.
1531 *
1532 * Return 0 - pass the check, -ENODEV - fail the check
1533 **/
1534int
1535lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1536{
1537 /* Mailbox command that have a completion handler must also have a
1538 * vport specified.
1539 */
1540 if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
1541 mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
1542 if (!mboxq->vport) {
1543 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
1544 "1814 Mbox x%x failed, no vport\n",
1545 mboxq->u.mb.mbxCommand);
1546 dump_stack();
1547 return -ENODEV;
1548 }
1549 }
1550 return 0;
1551}
1552
1553/**
1554 * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
1555 * @phba: pointer to lpfc hba data structure.
1556 *
1557 * This routine is to check whether the HBA device is ready for posting a
1558 * mailbox command. It is used by the mailbox transport API at the time the
1559 * to post a mailbox command to the device.
1560 *
1561 * Return 0 - pass the check, -ENODEV - fail the check
1562 **/
1563int
1564lpfc_mbox_dev_check(struct lpfc_hba *phba)
1565{
1566 /* If the PCI channel is in offline state, do not issue mbox */
1567 if (unlikely(pci_channel_offline(phba->pcidev)))
1568 return -ENODEV;
1569
1570 /* If the HBA is in error state, do not issue mbox */
1571 if (phba->link_state == LPFC_HBA_ERROR)
1572 return -ENODEV;
1573
1574 return 0;
1575}
1576
1577/**
James Smart3621a712009-04-06 18:47:14 -04001578 * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
James Smarte59058c2008-08-24 21:49:00 -04001579 * @phba: pointer to lpfc hba data structure.
1580 * @cmd: mailbox command code.
1581 *
1582 * This routine retrieves the proper timeout value according to the mailbox
1583 * command code.
1584 *
1585 * Return codes
1586 * Timeout value to be used for the given mailbox command
1587 **/
James Smarta309a6b2006-08-01 07:33:43 -04001588int
1589lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
1590{
1591 switch (cmd) {
1592 case MBX_WRITE_NV: /* 0x03 */
1593 case MBX_UPDATE_CFG: /* 0x1B */
1594 case MBX_DOWN_LOAD: /* 0x1C */
1595 case MBX_DEL_LD_ENTRY: /* 0x1D */
1596 case MBX_LOAD_AREA: /* 0x81 */
James Smart09372822008-01-11 01:52:54 -05001597 case MBX_WRITE_WWN: /* 0x98 */
James Smarta309a6b2006-08-01 07:33:43 -04001598 case MBX_LOAD_EXP_ROM: /* 0x9C */
1599 return LPFC_MBOX_TMO_FLASH_CMD;
James Smart04c68492009-05-22 14:52:52 -04001600 case MBX_SLI4_CONFIG: /* 0x9b */
1601 return LPFC_MBOX_SLI4_CONFIG_TMO;
James Smarta309a6b2006-08-01 07:33:43 -04001602 }
1603 return LPFC_MBOX_TMO;
1604}
James Smart04c68492009-05-22 14:52:52 -04001605
1606/**
1607 * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
1608 * @mbox: pointer to lpfc mbox command.
1609 * @sgentry: sge entry index.
1610 * @phyaddr: physical address for the sge
1611 * @length: Length of the sge.
1612 *
1613 * This routine sets up an entry in the non-embedded mailbox command at the sge
1614 * index location.
1615 **/
1616void
1617lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry,
1618 dma_addr_t phyaddr, uint32_t length)
1619{
1620 struct lpfc_mbx_nembed_cmd *nembed_sge;
1621
1622 nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1623 &mbox->u.mqe.un.nembed_cmd;
1624 nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr);
1625 nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr);
1626 nembed_sge->sge[sgentry].length = length;
1627}
1628
1629/**
1630 * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
1631 * @mbox: pointer to lpfc mbox command.
1632 * @sgentry: sge entry index.
1633 *
1634 * This routine gets an entry from the non-embedded mailbox command at the sge
1635 * index location.
1636 **/
1637void
1638lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry,
1639 struct lpfc_mbx_sge *sge)
1640{
1641 struct lpfc_mbx_nembed_cmd *nembed_sge;
1642
1643 nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1644 &mbox->u.mqe.un.nembed_cmd;
1645 sge->pa_lo = nembed_sge->sge[sgentry].pa_lo;
1646 sge->pa_hi = nembed_sge->sge[sgentry].pa_hi;
1647 sge->length = nembed_sge->sge[sgentry].length;
1648}
1649
1650/**
1651 * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
1652 * @phba: pointer to lpfc hba data structure.
1653 * @mbox: pointer to lpfc mbox command.
1654 *
1655 * This routine frees SLI4 specific mailbox command for sending IOCTL command.
1656 **/
1657void
1658lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1659{
1660 struct lpfc_mbx_sli4_config *sli4_cfg;
1661 struct lpfc_mbx_sge sge;
1662 dma_addr_t phyaddr;
1663 uint32_t sgecount, sgentry;
1664
1665 sli4_cfg = &mbox->u.mqe.un.sli4_config;
1666
1667 /* For embedded mbox command, just free the mbox command */
1668 if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1669 mempool_free(mbox, phba->mbox_mem_pool);
1670 return;
1671 }
1672
1673 /* For non-embedded mbox command, we need to free the pages first */
1674 sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr);
1675 /* There is nothing we can do if there is no sge address array */
1676 if (unlikely(!mbox->sge_array)) {
1677 mempool_free(mbox, phba->mbox_mem_pool);
1678 return;
1679 }
1680 /* Each non-embedded DMA memory was allocated in the length of a page */
1681 for (sgentry = 0; sgentry < sgecount; sgentry++) {
1682 lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge);
1683 phyaddr = getPaddr(sge.pa_hi, sge.pa_lo);
James Smart49198b32010-04-06 15:04:33 -04001684 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
James Smart04c68492009-05-22 14:52:52 -04001685 mbox->sge_array->addr[sgentry], phyaddr);
1686 }
1687 /* Free the sge address array memory */
1688 kfree(mbox->sge_array);
1689 /* Finally, free the mailbox command itself */
1690 mempool_free(mbox, phba->mbox_mem_pool);
1691}
1692
1693/**
1694 * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command
1695 * @phba: pointer to lpfc hba data structure.
1696 * @mbox: pointer to lpfc mbox command.
1697 * @subsystem: The sli4 config sub mailbox subsystem.
1698 * @opcode: The sli4 config sub mailbox command opcode.
1699 * @length: Length of the sli4 config mailbox command.
1700 *
1701 * This routine sets up the header fields of SLI4 specific mailbox command
1702 * for sending IOCTL command.
1703 *
1704 * Return: the actual length of the mbox command allocated (mostly useful
1705 * for none embedded mailbox command).
1706 **/
1707int
1708lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
1709 uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb)
1710{
1711 struct lpfc_mbx_sli4_config *sli4_config;
1712 union lpfc_sli4_cfg_shdr *cfg_shdr = NULL;
1713 uint32_t alloc_len;
1714 uint32_t resid_len;
1715 uint32_t pagen, pcount;
1716 void *viraddr;
1717 dma_addr_t phyaddr;
1718
1719 /* Set up SLI4 mailbox command header fields */
1720 memset(mbox, 0, sizeof(*mbox));
1721 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG);
1722
1723 /* Set up SLI4 ioctl command header fields */
1724 sli4_config = &mbox->u.mqe.un.sli4_config;
1725
1726 /* Setup for the embedded mbox command */
1727 if (emb) {
1728 /* Set up main header fields */
1729 bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
1730 sli4_config->header.cfg_mhdr.payload_length =
1731 LPFC_MBX_CMD_HDR_LENGTH + length;
1732 /* Set up sub-header fields following main header */
1733 bf_set(lpfc_mbox_hdr_opcode,
1734 &sli4_config->header.cfg_shdr.request, opcode);
1735 bf_set(lpfc_mbox_hdr_subsystem,
1736 &sli4_config->header.cfg_shdr.request, subsystem);
1737 sli4_config->header.cfg_shdr.request.request_length = length;
1738 return length;
1739 }
1740
1741 /* Setup for the none-embedded mbox command */
James Smart49198b32010-04-06 15:04:33 -04001742 pcount = (PAGE_ALIGN(length))/SLI4_PAGE_SIZE;
James Smart04c68492009-05-22 14:52:52 -04001743 pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ?
1744 LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount;
1745 /* Allocate record for keeping SGE virtual addresses */
1746 mbox->sge_array = kmalloc(sizeof(struct lpfc_mbx_nembed_sge_virt),
1747 GFP_KERNEL);
James Smart6a9c52c2009-10-02 15:16:51 -04001748 if (!mbox->sge_array) {
1749 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1750 "2527 Failed to allocate non-embedded SGE "
1751 "array.\n");
James Smart04c68492009-05-22 14:52:52 -04001752 return 0;
James Smart6a9c52c2009-10-02 15:16:51 -04001753 }
James Smart04c68492009-05-22 14:52:52 -04001754 for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) {
1755 /* The DMA memory is always allocated in the length of a
1756 * page even though the last SGE might not fill up to a
James Smart49198b32010-04-06 15:04:33 -04001757 * page, this is used as a priori size of SLI4_PAGE_SIZE for
James Smart04c68492009-05-22 14:52:52 -04001758 * the later DMA memory free.
1759 */
James Smart49198b32010-04-06 15:04:33 -04001760 viraddr = dma_alloc_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
James Smart04c68492009-05-22 14:52:52 -04001761 &phyaddr, GFP_KERNEL);
1762 /* In case of malloc fails, proceed with whatever we have */
1763 if (!viraddr)
1764 break;
James Smart49198b32010-04-06 15:04:33 -04001765 memset(viraddr, 0, SLI4_PAGE_SIZE);
James Smart04c68492009-05-22 14:52:52 -04001766 mbox->sge_array->addr[pagen] = viraddr;
1767 /* Keep the first page for later sub-header construction */
1768 if (pagen == 0)
1769 cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr;
1770 resid_len = length - alloc_len;
James Smart49198b32010-04-06 15:04:33 -04001771 if (resid_len > SLI4_PAGE_SIZE) {
James Smart04c68492009-05-22 14:52:52 -04001772 lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
James Smart49198b32010-04-06 15:04:33 -04001773 SLI4_PAGE_SIZE);
1774 alloc_len += SLI4_PAGE_SIZE;
James Smart04c68492009-05-22 14:52:52 -04001775 } else {
1776 lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
1777 resid_len);
1778 alloc_len = length;
1779 }
1780 }
1781
1782 /* Set up main header fields in mailbox command */
1783 sli4_config->header.cfg_mhdr.payload_length = alloc_len;
1784 bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen);
1785
1786 /* Set up sub-header fields into the first page */
1787 if (pagen > 0) {
1788 bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode);
1789 bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem);
1790 cfg_shdr->request.request_length =
1791 alloc_len - sizeof(union lpfc_sli4_cfg_shdr);
1792 }
1793 /* The sub-header is in DMA memory, which needs endian converstion */
James Smart72100cc2010-02-12 14:43:01 -05001794 if (cfg_shdr)
1795 lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
James Smart04c68492009-05-22 14:52:52 -04001796 sizeof(union lpfc_sli4_cfg_shdr));
1797
1798 return alloc_len;
1799}
1800
1801/**
1802 * lpfc_sli4_mbox_opcode_get - Get the opcode from a sli4 mailbox command
1803 * @phba: pointer to lpfc hba data structure.
1804 * @mbox: pointer to lpfc mbox command.
1805 *
1806 * This routine gets the opcode from a SLI4 specific mailbox command for
1807 * sending IOCTL command. If the mailbox command is not MBX_SLI4_CONFIG
1808 * (0x9B) or if the IOCTL sub-header is not present, opcode 0x0 shall be
1809 * returned.
1810 **/
1811uint8_t
1812lpfc_sli4_mbox_opcode_get(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1813{
1814 struct lpfc_mbx_sli4_config *sli4_cfg;
1815 union lpfc_sli4_cfg_shdr *cfg_shdr;
1816
1817 if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
1818 return 0;
1819 sli4_cfg = &mbox->u.mqe.un.sli4_config;
1820
1821 /* For embedded mbox command, get opcode from embedded sub-header*/
1822 if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1823 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
1824 return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
1825 }
1826
1827 /* For non-embedded mbox command, get opcode from first dma page */
1828 if (unlikely(!mbox->sge_array))
1829 return 0;
1830 cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
1831 return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
1832}
1833
1834/**
James Smart0c9ab6f2010-02-26 14:15:57 -05001835 * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd
James Smartecfd03c2010-02-12 14:41:27 -05001836 * @phba: pointer to lpfc hba data structure.
1837 * @fcf_index: index to fcf table.
1838 *
1839 * This routine routine allocates and constructs non-embedded mailbox command
1840 * for reading a FCF table entry refered by @fcf_index.
1841 *
1842 * Return: pointer to the mailbox command constructed if successful, otherwise
1843 * NULL.
1844 **/
1845int
James Smart0c9ab6f2010-02-26 14:15:57 -05001846lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *phba,
1847 struct lpfcMboxq *mboxq,
1848 uint16_t fcf_index)
James Smartecfd03c2010-02-12 14:41:27 -05001849{
1850 void *virt_addr;
1851 dma_addr_t phys_addr;
1852 uint8_t *bytep;
1853 struct lpfc_mbx_sge sge;
1854 uint32_t alloc_len, req_len;
1855 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1856
1857 if (!mboxq)
1858 return -ENOMEM;
1859
1860 req_len = sizeof(struct fcf_record) +
1861 sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
1862
1863 /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
1864 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
1865 LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
1866 LPFC_SLI4_MBX_NEMBED);
1867
1868 if (alloc_len < req_len) {
1869 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1870 "0291 Allocated DMA memory size (x%x) is "
1871 "less than the requested DMA memory "
1872 "size (x%x)\n", alloc_len, req_len);
1873 return -ENOMEM;
1874 }
1875
1876 /* Get the first SGE entry from the non-embedded DMA memory. This
1877 * routine only uses a single SGE.
1878 */
1879 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1880 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
1881 virt_addr = mboxq->sge_array->addr[0];
1882 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1883
1884 /* Set up command fields */
1885 bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
1886 /* Perform necessary endian conversion */
1887 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
1888 lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
1889
1890 return 0;
1891}
1892
1893/**
James Smart04c68492009-05-22 14:52:52 -04001894 * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
1895 * @mboxq: pointer to lpfc mbox command.
1896 *
1897 * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
1898 * mailbox command.
1899 **/
1900void
1901lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
1902{
1903 /* Set up SLI4 mailbox command header fields */
1904 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
1905 bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS);
1906
1907 /* Set up host requested features. */
1908 bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
1909
James Smart04c68492009-05-22 14:52:52 -04001910 /* Enable DIF (block guard) only if configured to do so. */
1911 if (phba->cfg_enable_bg)
1912 bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1);
1913
1914 /* Enable NPIV only if configured to do so. */
1915 if (phba->max_vpi && phba->cfg_enable_npiv)
1916 bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1);
1917
1918 return;
1919}
1920
1921/**
1922 * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
1923 * @mbox: pointer to lpfc mbox command to initialize.
1924 * @vport: Vport associated with the VF.
1925 *
1926 * This routine initializes @mbox to all zeros and then fills in the mailbox
1927 * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
1928 * in the context of an FCF. The driver issues this command to setup a VFI
1929 * before issuing a FLOGI to login to the VSAN. The driver should also issue a
1930 * REG_VFI after a successful VSAN login.
1931 **/
1932void
1933lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
1934{
1935 struct lpfc_mbx_init_vfi *init_vfi;
1936
1937 memset(mbox, 0, sizeof(*mbox));
James Smart76a95d72010-11-20 23:11:48 -05001938 mbox->vport = vport;
James Smart04c68492009-05-22 14:52:52 -04001939 init_vfi = &mbox->u.mqe.un.init_vfi;
1940 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI);
1941 bf_set(lpfc_init_vfi_vr, init_vfi, 1);
1942 bf_set(lpfc_init_vfi_vt, init_vfi, 1);
James Smart76a95d72010-11-20 23:11:48 -05001943 bf_set(lpfc_init_vfi_vp, init_vfi, 1);
James Smart04c68492009-05-22 14:52:52 -04001944 bf_set(lpfc_init_vfi_vfi, init_vfi, vport->vfi + vport->phba->vfi_base);
James Smart76a95d72010-11-20 23:11:48 -05001945 bf_set(lpfc_init_vpi_vpi, init_vfi, vport->vpi + vport->phba->vpi_base);
James Smart04c68492009-05-22 14:52:52 -04001946 bf_set(lpfc_init_vfi_fcfi, init_vfi, vport->phba->fcf.fcfi);
1947}
1948
1949/**
1950 * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
1951 * @mbox: pointer to lpfc mbox command to initialize.
1952 * @vport: vport associated with the VF.
1953 * @phys: BDE DMA bus address used to send the service parameters to the HBA.
1954 *
1955 * This routine initializes @mbox to all zeros and then fills in the mailbox
1956 * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
1957 * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
1958 * fabrics identified by VFI in the context of an FCF.
1959 **/
1960void
1961lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys)
1962{
1963 struct lpfc_mbx_reg_vfi *reg_vfi;
1964
1965 memset(mbox, 0, sizeof(*mbox));
1966 reg_vfi = &mbox->u.mqe.un.reg_vfi;
1967 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI);
1968 bf_set(lpfc_reg_vfi_vp, reg_vfi, 1);
1969 bf_set(lpfc_reg_vfi_vfi, reg_vfi, vport->vfi + vport->phba->vfi_base);
1970 bf_set(lpfc_reg_vfi_fcfi, reg_vfi, vport->phba->fcf.fcfi);
1971 bf_set(lpfc_reg_vfi_vpi, reg_vfi, vport->vpi + vport->phba->vpi_base);
James Smartc8685952009-11-18 15:39:16 -05001972 memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name));
1973 reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]);
1974 reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]);
James Smartb19a0612010-04-06 14:48:51 -04001975 reg_vfi->e_d_tov = vport->phba->fc_edtov;
1976 reg_vfi->r_a_tov = vport->phba->fc_ratov;
James Smart04c68492009-05-22 14:52:52 -04001977 reg_vfi->bde.addrHigh = putPaddrHigh(phys);
1978 reg_vfi->bde.addrLow = putPaddrLow(phys);
1979 reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam);
1980 reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1981 bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID);
1982}
1983
1984/**
1985 * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
James Smart1c6834a2009-07-19 10:01:26 -04001986 * @phba: pointer to the hba structure to init the VPI for.
James Smart04c68492009-05-22 14:52:52 -04001987 * @mbox: pointer to lpfc mbox command to initialize.
1988 * @vpi: VPI to be initialized.
1989 *
1990 * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
1991 * command to activate a virtual N_Port. The HBA assigns a MAC address to use
1992 * with the virtual N Port. The SLI Host issues this command before issuing a
1993 * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
1994 * successful virtual NPort login.
1995 **/
1996void
James Smart1c6834a2009-07-19 10:01:26 -04001997lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi)
James Smart04c68492009-05-22 14:52:52 -04001998{
1999 memset(mbox, 0, sizeof(*mbox));
2000 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI);
James Smart1c6834a2009-07-19 10:01:26 -04002001 bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi,
2002 vpi + phba->vpi_base);
2003 bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi,
2004 phba->pport->vfi + phba->vfi_base);
James Smart04c68492009-05-22 14:52:52 -04002005}
2006
2007/**
2008 * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
2009 * @mbox: pointer to lpfc mbox command to initialize.
James Smart6669f9b2009-10-02 15:16:45 -04002010 * @vport: vport associated with the VF.
James Smart04c68492009-05-22 14:52:52 -04002011 *
2012 * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
2013 * (logical NPort) into the inactive state. The SLI Host must have logged out
2014 * and unregistered all remote N_Ports to abort any activity on the virtual
2015 * fabric. The SLI Port posts the mailbox response after marking the virtual
2016 * fabric inactive.
2017 **/
2018void
James Smart6669f9b2009-10-02 15:16:45 -04002019lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
James Smart04c68492009-05-22 14:52:52 -04002020{
2021 memset(mbox, 0, sizeof(*mbox));
2022 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI);
James Smart6669f9b2009-10-02 15:16:45 -04002023 bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi,
2024 vport->vfi + vport->phba->vfi_base);
James Smart04c68492009-05-22 14:52:52 -04002025}
2026
2027/**
2028 * lpfc_dump_fcoe_param - Dump config region 23 to get FCoe parameters.
2029 * @phba: pointer to the hba structure containing.
2030 * @mbox: pointer to lpfc mbox command to initialize.
2031 *
2032 * This function create a SLI4 dump mailbox command to dump FCoE
2033 * parameters stored in region 23.
2034 **/
2035int
2036lpfc_dump_fcoe_param(struct lpfc_hba *phba,
2037 struct lpfcMboxq *mbox)
2038{
2039 struct lpfc_dmabuf *mp = NULL;
2040 MAILBOX_t *mb;
2041
2042 memset(mbox, 0, sizeof(*mbox));
2043 mb = &mbox->u.mb;
2044
2045 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2046 if (mp)
2047 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
2048
2049 if (!mp || !mp->virt) {
2050 kfree(mp);
2051 /* dump_fcoe_param failed to allocate memory */
2052 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
2053 "2569 lpfc_dump_fcoe_param: memory"
James Smarte4e74272009-07-19 10:01:38 -04002054 " allocation failed\n");
James Smart04c68492009-05-22 14:52:52 -04002055 return 1;
2056 }
2057
2058 memset(mp->virt, 0, LPFC_BPL_SIZE);
2059 INIT_LIST_HEAD(&mp->list);
2060
2061 /* save address for completion */
2062 mbox->context1 = (uint8_t *) mp;
2063
2064 mb->mbxCommand = MBX_DUMP_MEMORY;
2065 mb->un.varDmp.type = DMP_NV_PARAMS;
James Smarta0c87cb2009-07-19 10:01:10 -04002066 mb->un.varDmp.region_id = DMP_REGION_23;
2067 mb->un.varDmp.sli4_length = DMP_RGN23_SIZE;
James Smart04c68492009-05-22 14:52:52 -04002068 mb->un.varWords[3] = putPaddrLow(mp->phys);
2069 mb->un.varWords[4] = putPaddrHigh(mp->phys);
2070 return 0;
2071}
2072
2073/**
2074 * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
2075 * @phba: pointer to the hba structure containing the FCF index and RQ ID.
2076 * @mbox: pointer to lpfc mbox command to initialize.
2077 *
2078 * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
2079 * SLI Host uses the command to activate an FCF after it has acquired FCF
2080 * information via a READ_FCF mailbox command. This mailbox command also is used
2081 * to indicate where received unsolicited frames from this FCF will be sent. By
2082 * default this routine will set up the FCF to forward all unsolicited frames
2083 * the the RQ ID passed in the @phba. This can be overridden by the caller for
2084 * more complicated setups.
2085 **/
2086void
2087lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
2088{
2089 struct lpfc_mbx_reg_fcfi *reg_fcfi;
2090
2091 memset(mbox, 0, sizeof(*mbox));
2092 reg_fcfi = &mbox->u.mqe.un.reg_fcfi;
2093 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI);
2094 bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, phba->sli4_hba.hdr_rq->queue_id);
2095 bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
2096 bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
2097 bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
James Smartecfd03c2010-02-12 14:41:27 -05002098 bf_set(lpfc_reg_fcfi_info_index, reg_fcfi,
2099 phba->fcf.current_rec.fcf_indx);
James Smart04c68492009-05-22 14:52:52 -04002100 /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */
James Smartecfd03c2010-02-12 14:41:27 -05002101 bf_set(lpfc_reg_fcfi_mam, reg_fcfi, (~phba->fcf.addr_mode) & 0x3);
James Smart3804dc82010-07-14 15:31:37 -04002102 if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) {
James Smart04c68492009-05-22 14:52:52 -04002103 bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
James Smartecfd03c2010-02-12 14:41:27 -05002104 bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi,
2105 phba->fcf.current_rec.vlan_id);
James Smart04c68492009-05-22 14:52:52 -04002106 }
2107}
2108
2109/**
2110 * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
2111 * @mbox: pointer to lpfc mbox command to initialize.
2112 * @fcfi: FCFI to be unregistered.
2113 *
2114 * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
2115 * The SLI Host uses the command to inactivate an FCFI.
2116 **/
2117void
2118lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi)
2119{
2120 memset(mbox, 0, sizeof(*mbox));
2121 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI);
2122 bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi);
2123}
2124
2125/**
2126 * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
2127 * @mbox: pointer to lpfc mbox command to initialize.
2128 * @ndlp: The nodelist structure that describes the RPI to resume.
2129 *
2130 * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
2131 * link event.
2132 **/
2133void
2134lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
2135{
2136 struct lpfc_mbx_resume_rpi *resume_rpi;
2137
2138 memset(mbox, 0, sizeof(*mbox));
2139 resume_rpi = &mbox->u.mqe.un.resume_rpi;
2140 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI);
James Smart8fa38512009-07-19 10:01:03 -04002141 bf_set(lpfc_resume_rpi_index, resume_rpi, ndlp->nlp_rpi);
2142 bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI);
2143 resume_rpi->event_tag = ndlp->phba->fc_eventTag;
James Smart04c68492009-05-22 14:52:52 -04002144}
James Smart28baac72010-02-12 14:42:03 -05002145
2146/**
2147 * lpfc_supported_pages - Initialize the PORT_CAPABILITIES supported pages
2148 * mailbox command.
2149 * @mbox: pointer to lpfc mbox command to initialize.
2150 *
2151 * The PORT_CAPABILITIES supported pages mailbox command is issued to
2152 * retrieve the particular feature pages supported by the port.
2153 **/
2154void
2155lpfc_supported_pages(struct lpfcMboxq *mbox)
2156{
2157 struct lpfc_mbx_supp_pages *supp_pages;
2158
2159 memset(mbox, 0, sizeof(*mbox));
2160 supp_pages = &mbox->u.mqe.un.supp_pages;
2161 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES);
2162 bf_set(cpn, supp_pages, LPFC_SUPP_PAGES);
2163}
2164
2165/**
2166 * lpfc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params
2167 * mailbox command.
2168 * @mbox: pointer to lpfc mbox command to initialize.
2169 *
2170 * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to
2171 * retrieve the particular SLI4 features supported by the port.
2172 **/
2173void
2174lpfc_sli4_params(struct lpfcMboxq *mbox)
2175{
2176 struct lpfc_mbx_sli4_params *sli4_params;
2177
2178 memset(mbox, 0, sizeof(*mbox));
2179 sli4_params = &mbox->u.mqe.un.sli4_params;
2180 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES);
2181 bf_set(cpn, sli4_params, LPFC_SLI4_PARAMETERS);
2182}