blob: 6c1d8b3fe8cc3af8167d118e6319cfac9387e961 [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>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -040026#include <scsi/scsi_device.h>
27#include <scsi/scsi_transport_fc.h>
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040028#include <scsi/scsi.h>
James Smart6a9c52c2009-10-02 15:16:51 -040029#include <scsi/fc/fc_fs.h>
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040030
James Smartda0436e2009-05-22 14:51:39 -040031#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050032#include "lpfc_hw.h"
33#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040034#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040035#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050036#include "lpfc_disc.h"
37#include "lpfc_scsi.h"
38#include "lpfc.h"
39#include "lpfc_logmsg.h"
40#include "lpfc_crtn.h"
41#include "lpfc_compat.h"
42
James Smarte59058c2008-08-24 21:49:00 -040043/**
James Smart21e9a0a2009-05-22 14:53:21 -040044 * lpfc_dump_static_vport - Dump HBA's static vport information.
45 * @phba: pointer to lpfc hba data structure.
46 * @pmb: pointer to the driver internal queue element for mailbox command.
47 * @offset: offset for dumping vport info.
48 *
49 * The dump mailbox command provides a method for the device driver to obtain
50 * various types of information from the HBA device.
51 *
52 * This routine prepares the mailbox command for dumping list of static
53 * vports to be created.
54 **/
James Smart1c6834a2009-07-19 10:01:26 -040055int
James Smart21e9a0a2009-05-22 14:53:21 -040056lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
57 uint16_t offset)
58{
59 MAILBOX_t *mb;
James Smart1c6834a2009-07-19 10:01:26 -040060 struct lpfc_dmabuf *mp;
James Smart21e9a0a2009-05-22 14:53:21 -040061
62 mb = &pmb->u.mb;
James Smart21e9a0a2009-05-22 14:53:21 -040063
64 /* Setup to dump vport info region */
65 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
66 mb->mbxCommand = MBX_DUMP_MEMORY;
James Smart21e9a0a2009-05-22 14:53:21 -040067 mb->un.varDmp.type = DMP_NV_PARAMS;
68 mb->un.varDmp.entry_index = offset;
69 mb->un.varDmp.region_id = DMP_REGION_VPORT;
James Smart21e9a0a2009-05-22 14:53:21 -040070 mb->mbxOwner = OWN_HOST;
71
James Smart1c6834a2009-07-19 10:01:26 -040072 /* For SLI3 HBAs data is embedded in mailbox */
73 if (phba->sli_rev != LPFC_SLI_REV4) {
74 mb->un.varDmp.cv = 1;
75 mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t);
76 return 0;
77 }
78
79 /* For SLI4 HBAs driver need to allocate memory */
80 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
81 if (mp)
82 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
83
84 if (!mp || !mp->virt) {
85 kfree(mp);
86 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
87 "2605 lpfc_dump_static_vport: memory"
88 " allocation failed\n");
89 return 1;
90 }
91 memset(mp->virt, 0, LPFC_BPL_SIZE);
92 INIT_LIST_HEAD(&mp->list);
93 /* save address for completion */
94 pmb->context2 = (uint8_t *) mp;
95 mb->un.varWords[3] = putPaddrLow(mp->phys);
96 mb->un.varWords[4] = putPaddrHigh(mp->phys);
97 mb->un.varDmp.sli4_length = sizeof(struct static_vport_info);
98
99 return 0;
James Smart21e9a0a2009-05-22 14:53:21 -0400100}
101
102/**
James Smarta0c87cb2009-07-19 10:01:10 -0400103 * lpfc_down_link - Bring down HBAs link.
James Smarte59058c2008-08-24 21:49:00 -0400104 * @phba: pointer to lpfc hba data structure.
105 * @pmb: pointer to the driver internal queue element for mailbox command.
James Smarta0c87cb2009-07-19 10:01:10 -0400106 *
107 * This routine prepares a mailbox command to bring down HBA link.
108 **/
109void
110lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
111{
112 MAILBOX_t *mb;
113 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
114 mb = &pmb->u.mb;
115 mb->mbxCommand = MBX_DOWN_LINK;
116 mb->mbxOwner = OWN_HOST;
117}
118
119/**
120 * lpfc_dump_mem - Prepare a mailbox command for reading a region.
121 * @phba: pointer to lpfc hba data structure.
122 * @pmb: pointer to the driver internal queue element for mailbox command.
123 * @offset: offset into the region.
124 * @region_id: config region id.
James Smarte59058c2008-08-24 21:49:00 -0400125 *
126 * The dump mailbox command provides a method for the device driver to obtain
127 * various types of information from the HBA device.
128 *
James Smarta0c87cb2009-07-19 10:01:10 -0400129 * This routine prepares the mailbox command for dumping HBA's config region.
James Smarte59058c2008-08-24 21:49:00 -0400130 **/
dea31012005-04-17 16:05:31 -0500131void
James Smarta0c87cb2009-07-19 10:01:10 -0400132lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset,
133 uint16_t region_id)
dea31012005-04-17 16:05:31 -0500134{
135 MAILBOX_t *mb;
136 void *ctx;
137
James Smart04c68492009-05-22 14:52:52 -0400138 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500139 ctx = pmb->context2;
140
141 /* Setup to dump VPD region */
142 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
143 mb->mbxCommand = MBX_DUMP_MEMORY;
144 mb->un.varDmp.cv = 1;
145 mb->un.varDmp.type = DMP_NV_PARAMS;
146 mb->un.varDmp.entry_index = offset;
James Smarta0c87cb2009-07-19 10:01:10 -0400147 mb->un.varDmp.region_id = region_id;
dea31012005-04-17 16:05:31 -0500148 mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
149 mb->un.varDmp.co = 0;
150 mb->un.varDmp.resp_offset = 0;
151 pmb->context2 = ctx;
152 mb->mbxOwner = OWN_HOST;
153 return;
154}
155
James Smarte59058c2008-08-24 21:49:00 -0400156/**
James Smart3621a712009-04-06 18:47:14 -0400157 * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
James Smart97207482008-12-04 22:39:19 -0500158 * @phba: pointer to lpfc hba data structure.
159 * @pmb: pointer to the driver internal queue element for mailbox command.
James Smart3621a712009-04-06 18:47:14 -0400160 *
James Smart97207482008-12-04 22:39:19 -0500161 * This function create a dump memory mailbox command to dump wake up
162 * parameters.
163 */
164void
165lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
166{
167 MAILBOX_t *mb;
168 void *ctx;
169
James Smart04c68492009-05-22 14:52:52 -0400170 mb = &pmb->u.mb;
James Smart97207482008-12-04 22:39:19 -0500171 /* Save context so that we can restore after memset */
172 ctx = pmb->context2;
173
174 /* Setup to dump VPD region */
175 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
176 mb->mbxCommand = MBX_DUMP_MEMORY;
177 mb->mbxOwner = OWN_HOST;
178 mb->un.varDmp.cv = 1;
179 mb->un.varDmp.type = DMP_NV_PARAMS;
180 mb->un.varDmp.entry_index = 0;
181 mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
182 mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
183 mb->un.varDmp.co = 0;
184 mb->un.varDmp.resp_offset = 0;
185 pmb->context2 = ctx;
186 return;
187}
188
189/**
James Smart3621a712009-04-06 18:47:14 -0400190 * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
James Smarte59058c2008-08-24 21:49:00 -0400191 * @phba: pointer to lpfc hba data structure.
192 * @pmb: pointer to the driver internal queue element for mailbox command.
193 *
194 * The read NVRAM mailbox command returns the HBA's non-volatile parameters
195 * that are used as defaults when the Fibre Channel link is brought on-line.
196 *
197 * This routine prepares the mailbox command for reading information stored
198 * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
199 **/
dea31012005-04-17 16:05:31 -0500200void
201lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
202{
203 MAILBOX_t *mb;
204
James Smart04c68492009-05-22 14:52:52 -0400205 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500206 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
207 mb->mbxCommand = MBX_READ_NV;
208 mb->mbxOwner = OWN_HOST;
209 return;
210}
211
James Smarte59058c2008-08-24 21:49:00 -0400212/**
James Smart3621a712009-04-06 18:47:14 -0400213 * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
James Smarte59058c2008-08-24 21:49:00 -0400214 * @phba: pointer to lpfc hba data structure.
215 * @pmb: pointer to the driver internal queue element for mailbox command.
216 * @ring: ring number for the asynchronous event to be configured.
217 *
218 * The asynchronous event enable mailbox command is used to enable the
219 * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
220 * specifies the default ring to which events are posted.
221 *
222 * This routine prepares the mailbox command for enabling HBA asynchronous
223 * event support on a IOCB ring.
224 **/
James Smart57127f12007-10-27 13:37:05 -0400225void
226lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
227 uint32_t ring)
228{
229 MAILBOX_t *mb;
230
James Smart04c68492009-05-22 14:52:52 -0400231 mb = &pmb->u.mb;
James Smart57127f12007-10-27 13:37:05 -0400232 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
233 mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
234 mb->un.varCfgAsyncEvent.ring = ring;
235 mb->mbxOwner = OWN_HOST;
236 return;
237}
238
James Smarte59058c2008-08-24 21:49:00 -0400239/**
James Smart3621a712009-04-06 18:47:14 -0400240 * lpfc_heart_beat - Prepare a mailbox command for heart beat
James Smarte59058c2008-08-24 21:49:00 -0400241 * @phba: pointer to lpfc hba data structure.
242 * @pmb: pointer to the driver internal queue element for mailbox command.
243 *
244 * The heart beat mailbox command is used to detect an unresponsive HBA, which
245 * is defined as any device where no error attention is sent and both mailbox
246 * and rings are not processed.
247 *
248 * This routine prepares the mailbox command for issuing a heart beat in the
249 * form of mailbox command to the HBA. The timely completion of the heart
250 * beat mailbox command indicates the health of the HBA.
251 **/
James Smart858c9f62007-06-17 19:56:39 -0500252void
253lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
254{
255 MAILBOX_t *mb;
256
James Smart04c68492009-05-22 14:52:52 -0400257 mb = &pmb->u.mb;
James Smart858c9f62007-06-17 19:56:39 -0500258 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
259 mb->mbxCommand = MBX_HEARTBEAT;
260 mb->mbxOwner = OWN_HOST;
261 return;
262}
263
James Smarte59058c2008-08-24 21:49:00 -0400264/**
James Smart3621a712009-04-06 18:47:14 -0400265 * lpfc_read_la - Prepare a mailbox command for reading HBA link attention
James Smarte59058c2008-08-24 21:49:00 -0400266 * @phba: pointer to lpfc hba data structure.
267 * @pmb: pointer to the driver internal queue element for mailbox command.
268 * @mp: DMA buffer memory for reading the link attention information into.
269 *
270 * The read link attention mailbox command is issued to read the Link Event
271 * Attention information indicated by the HBA port when the Link Event bit
272 * of the Host Attention (HSTATT) register is set to 1. A Link Event
273 * Attention occurs based on an exception detected at the Fibre Channel link
274 * interface.
275 *
276 * This routine prepares the mailbox command for reading HBA link attention
277 * information. A DMA memory has been set aside and address passed to the
278 * HBA through @mp for the HBA to DMA link attention information into the
279 * memory as part of the execution of the mailbox command.
280 *
281 * Return codes
282 * 0 - Success (currently always return 0)
283 **/
dea31012005-04-17 16:05:31 -0500284int
285lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
286{
287 MAILBOX_t *mb;
288 struct lpfc_sli *psli;
289
290 psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -0400291 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500292 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
293
294 INIT_LIST_HEAD(&mp->list);
295 mb->mbxCommand = MBX_READ_LA64;
296 mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128;
297 mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
298 mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys);
299
300 /* Save address for later completion and set the owner to host so that
301 * the FW knows this mailbox is available for processing.
302 */
303 pmb->context1 = (uint8_t *) mp;
304 mb->mbxOwner = OWN_HOST;
James Smart92d7f7b2007-06-17 19:56:38 -0500305 return (0);
dea31012005-04-17 16:05:31 -0500306}
307
James Smarte59058c2008-08-24 21:49:00 -0400308/**
James Smart3621a712009-04-06 18:47:14 -0400309 * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
James Smarte59058c2008-08-24 21:49:00 -0400310 * @phba: pointer to lpfc hba data structure.
311 * @pmb: pointer to the driver internal queue element for mailbox command.
312 *
313 * The clear link attention mailbox command is issued to clear the link event
314 * attention condition indicated by the Link Event bit of the Host Attention
315 * (HSTATT) register. The link event attention condition is cleared only if
316 * the event tag specified matches that of the current link event counter.
317 * The current event tag is read using the read link attention event mailbox
318 * command.
319 *
320 * This routine prepares the mailbox command for clearing HBA link attention
321 * information.
322 **/
dea31012005-04-17 16:05:31 -0500323void
324lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
325{
326 MAILBOX_t *mb;
327
James Smart04c68492009-05-22 14:52:52 -0400328 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500329 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
330
331 mb->un.varClearLA.eventTag = phba->fc_eventTag;
332 mb->mbxCommand = MBX_CLEAR_LA;
333 mb->mbxOwner = OWN_HOST;
334 return;
335}
336
James Smarte59058c2008-08-24 21:49:00 -0400337/**
James Smart3621a712009-04-06 18:47:14 -0400338 * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
James Smarte59058c2008-08-24 21:49:00 -0400339 * @phba: pointer to lpfc hba data structure.
340 * @pmb: pointer to the driver internal queue element for mailbox command.
341 *
342 * The configure link mailbox command is used before the initialize link
343 * mailbox command to override default value and to configure link-oriented
344 * parameters such as DID address and various timers. Typically, this
345 * command would be used after an F_Port login to set the returned DID address
346 * and the fabric timeout values. This command is not valid before a configure
347 * port command has configured the HBA port.
348 *
349 * This routine prepares the mailbox command for configuring link on a HBA.
350 **/
dea31012005-04-17 16:05:31 -0500351void
352lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
353{
James Smart2e0fef82007-06-17 19:56:36 -0500354 struct lpfc_vport *vport = phba->pport;
James Smart04c68492009-05-22 14:52:52 -0400355 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500356 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
357
358 /* NEW_FEATURE
359 * SLI-2, Coalescing Response Feature.
360 */
361 if (phba->cfg_cr_delay) {
362 mb->un.varCfgLnk.cr = 1;
363 mb->un.varCfgLnk.ci = 1;
364 mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
365 mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
366 }
367
James Smart2e0fef82007-06-17 19:56:36 -0500368 mb->un.varCfgLnk.myId = vport->fc_myDID;
dea31012005-04-17 16:05:31 -0500369 mb->un.varCfgLnk.edtov = phba->fc_edtov;
370 mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
371 mb->un.varCfgLnk.ratov = phba->fc_ratov;
372 mb->un.varCfgLnk.rttov = phba->fc_rttov;
373 mb->un.varCfgLnk.altov = phba->fc_altov;
374 mb->un.varCfgLnk.crtov = phba->fc_crtov;
375 mb->un.varCfgLnk.citov = phba->fc_citov;
376
377 if (phba->cfg_ack0)
378 mb->un.varCfgLnk.ack0_enable = 1;
379
380 mb->mbxCommand = MBX_CONFIG_LINK;
381 mb->mbxOwner = OWN_HOST;
382 return;
383}
384
James Smarte59058c2008-08-24 21:49:00 -0400385/**
James Smart3621a712009-04-06 18:47:14 -0400386 * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
James Smart93996272008-08-24 21:50:30 -0400387 * @phba: pointer to lpfc hba data structure.
388 * @pmb: pointer to the driver internal queue element for mailbox command.
389 *
390 * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
391 * MSI-X multi-message interrupt vector association to interrupt attention
392 * conditions.
393 *
394 * Return codes
395 * 0 - Success
396 * -EINVAL - Failure
397 **/
398int
399lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
400{
James Smart04c68492009-05-22 14:52:52 -0400401 MAILBOX_t *mb = &pmb->u.mb;
James Smart93996272008-08-24 21:50:30 -0400402 uint32_t attentionConditions[2];
403
404 /* Sanity check */
405 if (phba->cfg_use_msi != 2) {
406 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
407 "0475 Not configured for supporting MSI-X "
408 "cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
409 return -EINVAL;
410 }
411
412 if (phba->sli_rev < 3) {
413 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
414 "0476 HBA not supporting SLI-3 or later "
415 "SLI Revision: 0x%x\n", phba->sli_rev);
416 return -EINVAL;
417 }
418
419 /* Clear mailbox command fields */
420 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
421
422 /*
423 * SLI-3, Message Signaled Interrupt Fearure.
424 */
425
426 /* Multi-message attention configuration */
427 attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
428 HA_LATT | HA_MBATT);
429 attentionConditions[1] = 0;
430
431 mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
432 mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
433
434 /*
435 * Set up message number to HA bit association
436 */
437#ifdef __BIG_ENDIAN_BITFIELD
438 /* RA0 (FCP Ring) */
439 mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
440 /* RA1 (Other Protocol Extra Ring) */
441 mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
442#else /* __LITTLE_ENDIAN_BITFIELD */
443 /* RA0 (FCP Ring) */
444 mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
445 /* RA1 (Other Protocol Extra Ring) */
446 mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
447#endif
448 /* Multi-message interrupt autoclear configuration*/
449 mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
450 mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
451
452 /* For now, HBA autoclear does not work reliably, disable it */
453 mb->un.varCfgMSI.autoClearHA[0] = 0;
454 mb->un.varCfgMSI.autoClearHA[1] = 0;
455
456 /* Set command and owner bit */
457 mb->mbxCommand = MBX_CONFIG_MSI;
458 mb->mbxOwner = OWN_HOST;
459
460 return 0;
461}
462
463/**
James Smart3621a712009-04-06 18:47:14 -0400464 * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
James Smarte59058c2008-08-24 21:49:00 -0400465 * @phba: pointer to lpfc hba data structure.
466 * @pmb: pointer to the driver internal queue element for mailbox command.
467 * @topology: the link topology for the link to be initialized to.
468 * @linkspeed: the link speed for the link to be initialized to.
469 *
470 * The initialize link mailbox command is used to initialize the Fibre
471 * Channel link. This command must follow a configure port command that
472 * establishes the mode of operation.
473 *
474 * This routine prepares the mailbox command for initializing link on a HBA
475 * with the specified link topology and speed.
476 **/
dea31012005-04-17 16:05:31 -0500477void
478lpfc_init_link(struct lpfc_hba * phba,
479 LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
480{
481 lpfc_vpd_t *vpd;
482 struct lpfc_sli *psli;
483 MAILBOX_t *mb;
484
James Smart04c68492009-05-22 14:52:52 -0400485 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500486 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
487
488 psli = &phba->sli;
489 switch (topology) {
490 case FLAGS_TOPOLOGY_MODE_LOOP_PT:
491 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
492 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
493 break;
494 case FLAGS_TOPOLOGY_MODE_PT_PT:
495 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
496 break;
497 case FLAGS_TOPOLOGY_MODE_LOOP:
498 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
499 break;
500 case FLAGS_TOPOLOGY_MODE_PT_LOOP:
501 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
502 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
503 break;
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500504 case FLAGS_LOCAL_LB:
505 mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
506 break;
dea31012005-04-17 16:05:31 -0500507 }
508
James Smart4b0b91d2006-04-15 11:53:00 -0400509 /* Enable asynchronous ABTS responses from firmware */
510 mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
511
dea31012005-04-17 16:05:31 -0500512 /* NEW_FEATURE
513 * Setting up the link speed
514 */
515 vpd = &phba->vpd;
516 if (vpd->rev.feaLevelHigh >= 0x02){
James Smart92d7f7b2007-06-17 19:56:38 -0500517 switch(linkspeed){
dea31012005-04-17 16:05:31 -0500518 case LINK_SPEED_1G:
519 case LINK_SPEED_2G:
520 case LINK_SPEED_4G:
James Smartb87eab32007-04-25 09:53:28 -0400521 case LINK_SPEED_8G:
dea31012005-04-17 16:05:31 -0500522 mb->un.varInitLnk.link_flags |=
523 FLAGS_LINK_SPEED;
524 mb->un.varInitLnk.link_speed = linkspeed;
525 break;
526 case LINK_SPEED_AUTO:
527 default:
528 mb->un.varInitLnk.link_speed =
529 LINK_SPEED_AUTO;
530 break;
531 }
532
533 }
534 else
535 mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
536
537 mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
538 mb->mbxOwner = OWN_HOST;
539 mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
540 return;
541}
542
James Smarte59058c2008-08-24 21:49:00 -0400543/**
James Smart3621a712009-04-06 18:47:14 -0400544 * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
James Smarte59058c2008-08-24 21:49:00 -0400545 * @phba: pointer to lpfc hba data structure.
546 * @pmb: pointer to the driver internal queue element for mailbox command.
547 * @vpi: virtual N_Port identifier.
548 *
549 * The read service parameter mailbox command is used to read the HBA port
550 * service parameters. The service parameters are read into the buffer
551 * specified directly by a BDE in the mailbox command. These service
552 * parameters may then be used to build the payload of an N_Port/F_POrt
553 * login request and reply (LOGI/ACC).
554 *
555 * This routine prepares the mailbox command for reading HBA port service
556 * parameters. The DMA memory is allocated in this function and the addresses
557 * are populated into the mailbox command for the HBA to DMA the service
558 * parameters into.
559 *
560 * Return codes
561 * 0 - Success
562 * 1 - DMA memory allocation failed
563 **/
dea31012005-04-17 16:05:31 -0500564int
James Smart92d7f7b2007-06-17 19:56:38 -0500565lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
dea31012005-04-17 16:05:31 -0500566{
567 struct lpfc_dmabuf *mp;
568 MAILBOX_t *mb;
569 struct lpfc_sli *psli;
570
571 psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -0400572 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500573 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
574
575 mb->mbxOwner = OWN_HOST;
576
577 /* Get a buffer to hold the HBAs Service Parameters */
578
James Smart98c9ea52007-10-27 13:37:33 -0400579 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
580 if (mp)
581 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
582 if (!mp || !mp->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800583 kfree(mp);
dea31012005-04-17 16:05:31 -0500584 mb->mbxCommand = MBX_READ_SPARM64;
585 /* READ_SPARAM: no buffers */
James Smarte8b62012007-08-02 11:10:09 -0400586 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
587 "0301 READ_SPARAM: no buffers\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500588 return (1);
dea31012005-04-17 16:05:31 -0500589 }
590 INIT_LIST_HEAD(&mp->list);
591 mb->mbxCommand = MBX_READ_SPARM64;
592 mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
593 mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
594 mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
James Smart04c68492009-05-22 14:52:52 -0400595 mb->un.varRdSparm.vpi = vpi + phba->vpi_base;
dea31012005-04-17 16:05:31 -0500596
597 /* save address for completion */
598 pmb->context1 = mp;
599
James Smart92d7f7b2007-06-17 19:56:38 -0500600 return (0);
dea31012005-04-17 16:05:31 -0500601}
602
James Smarte59058c2008-08-24 21:49:00 -0400603/**
James Smart3621a712009-04-06 18:47:14 -0400604 * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
James Smarte59058c2008-08-24 21:49:00 -0400605 * @phba: pointer to lpfc hba data structure.
606 * @vpi: virtual N_Port identifier.
607 * @did: remote port identifier.
608 * @pmb: pointer to the driver internal queue element for mailbox command.
609 *
610 * The unregister DID mailbox command is used to unregister an N_Port/F_Port
611 * login for an unknown RPI by specifying the DID of a remote port. This
612 * command frees an RPI context in the HBA port. This has the effect of
613 * performing an implicit N_Port/F_Port logout.
614 *
615 * This routine prepares the mailbox command for unregistering a remote
616 * N_Port/F_Port (DID) login.
617 **/
dea31012005-04-17 16:05:31 -0500618void
James Smart92d7f7b2007-06-17 19:56:38 -0500619lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
620 LPFC_MBOXQ_t * pmb)
dea31012005-04-17 16:05:31 -0500621{
622 MAILBOX_t *mb;
623
James Smart04c68492009-05-22 14:52:52 -0400624 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500625 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
626
627 mb->un.varUnregDID.did = did;
James Smart04c68492009-05-22 14:52:52 -0400628 if (vpi != 0xffff)
629 vpi += phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500630 mb->un.varUnregDID.vpi = vpi;
dea31012005-04-17 16:05:31 -0500631
632 mb->mbxCommand = MBX_UNREG_D_ID;
633 mb->mbxOwner = OWN_HOST;
634 return;
635}
636
James Smarte59058c2008-08-24 21:49:00 -0400637/**
James Smart3621a712009-04-06 18:47:14 -0400638 * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
James Smarte59058c2008-08-24 21:49:00 -0400639 * @phba: pointer to lpfc hba data structure.
640 * @pmb: pointer to the driver internal queue element for mailbox command.
641 *
642 * The read configuration mailbox command is used to read the HBA port
643 * configuration parameters. This mailbox command provides a method for
644 * seeing any parameters that may have changed via various configuration
645 * mailbox commands.
646 *
647 * This routine prepares the mailbox command for reading out HBA configuration
648 * parameters.
649 **/
dea31012005-04-17 16:05:31 -0500650void
651lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
652{
653 MAILBOX_t *mb;
654
James Smart04c68492009-05-22 14:52:52 -0400655 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500656 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
657
658 mb->mbxCommand = MBX_READ_CONFIG;
659 mb->mbxOwner = OWN_HOST;
660 return;
661}
662
James Smarte59058c2008-08-24 21:49:00 -0400663/**
James Smart3621a712009-04-06 18:47:14 -0400664 * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
James Smarte59058c2008-08-24 21:49:00 -0400665 * @phba: pointer to lpfc hba data structure.
666 * @pmb: pointer to the driver internal queue element for mailbox command.
667 *
668 * The read link status mailbox command is used to read the link status from
669 * the HBA. Link status includes all link-related error counters. These
670 * counters are maintained by the HBA and originated in the link hardware
671 * unit. Note that all of these counters wrap.
672 *
673 * This routine prepares the mailbox command for reading out HBA link status.
674 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -0500675void
676lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
677{
678 MAILBOX_t *mb;
679
James Smart04c68492009-05-22 14:52:52 -0400680 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -0500681 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
682
683 mb->mbxCommand = MBX_READ_LNK_STAT;
684 mb->mbxOwner = OWN_HOST;
685 return;
686}
687
James Smarte59058c2008-08-24 21:49:00 -0400688/**
James Smart04c68492009-05-22 14:52:52 -0400689 * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
James Smarte59058c2008-08-24 21:49:00 -0400690 * @phba: pointer to lpfc hba data structure.
691 * @vpi: virtual N_Port identifier.
692 * @did: remote port identifier.
693 * @param: pointer to memory holding the server parameters.
694 * @pmb: pointer to the driver internal queue element for mailbox command.
695 * @flag: action flag to be passed back for the complete function.
696 *
697 * The registration login mailbox command is used to register an N_Port or
698 * F_Port login. This registration allows the HBA to cache the remote N_Port
699 * service parameters internally and thereby make the appropriate FC-2
700 * decisions. The remote port service parameters are handed off by the driver
701 * to the HBA using a descriptor entry that directly identifies a buffer in
702 * host memory. In exchange, the HBA returns an RPI identifier.
703 *
704 * This routine prepares the mailbox command for registering remote port login.
705 * The function allocates DMA buffer for passing the service parameters to the
706 * HBA with the mailbox command.
707 *
708 * Return codes
709 * 0 - Success
710 * 1 - DMA memory allocation failed
711 **/
dea31012005-04-17 16:05:31 -0500712int
James Smart04c68492009-05-22 14:52:52 -0400713lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
James Smart92d7f7b2007-06-17 19:56:38 -0500714 uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
dea31012005-04-17 16:05:31 -0500715{
James Smart04c68492009-05-22 14:52:52 -0400716 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500717 uint8_t *sparam;
718 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -0500719
dea31012005-04-17 16:05:31 -0500720 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
721
722 mb->un.varRegLogin.rpi = 0;
James Smart04c68492009-05-22 14:52:52 -0400723 if (phba->sli_rev == LPFC_SLI_REV4) {
724 mb->un.varRegLogin.rpi = lpfc_sli4_alloc_rpi(phba);
725 if (mb->un.varRegLogin.rpi == LPFC_RPI_ALLOC_ERROR)
726 return 1;
727 }
728
729 mb->un.varRegLogin.vpi = vpi + phba->vpi_base;
dea31012005-04-17 16:05:31 -0500730 mb->un.varRegLogin.did = did;
731 mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */
732
733 mb->mbxOwner = OWN_HOST;
734
735 /* Get a buffer to hold NPorts Service Parameters */
James Smart98c9ea52007-10-27 13:37:33 -0400736 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
737 if (mp)
738 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
739 if (!mp || !mp->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800740 kfree(mp);
dea31012005-04-17 16:05:31 -0500741 mb->mbxCommand = MBX_REG_LOGIN64;
742 /* REG_LOGIN: no buffers */
James Smart92d7f7b2007-06-17 19:56:38 -0500743 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400744 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
745 "flag x%x\n", vpi, did, flag);
James Smart92d7f7b2007-06-17 19:56:38 -0500746 return (1);
dea31012005-04-17 16:05:31 -0500747 }
748 INIT_LIST_HEAD(&mp->list);
749 sparam = mp->virt;
750
751 /* Copy param's into a new buffer */
752 memcpy(sparam, param, sizeof (struct serv_parm));
753
754 /* save address for completion */
755 pmb->context1 = (uint8_t *) mp;
756
757 mb->mbxCommand = MBX_REG_LOGIN64;
758 mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
759 mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
760 mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
761
James Smart92d7f7b2007-06-17 19:56:38 -0500762 return (0);
dea31012005-04-17 16:05:31 -0500763}
764
James Smarte59058c2008-08-24 21:49:00 -0400765/**
James Smart3621a712009-04-06 18:47:14 -0400766 * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
James Smarte59058c2008-08-24 21:49:00 -0400767 * @phba: pointer to lpfc hba data structure.
768 * @vpi: virtual N_Port identifier.
769 * @rpi: remote port identifier
770 * @pmb: pointer to the driver internal queue element for mailbox command.
771 *
772 * The unregistration login mailbox command is used to unregister an N_Port
773 * or F_Port login. This command frees an RPI context in the HBA. It has the
774 * effect of performing an implicit N_Port/F_Port logout.
775 *
776 * This routine prepares the mailbox command for unregistering remote port
777 * login.
778 **/
dea31012005-04-17 16:05:31 -0500779void
James Smart92d7f7b2007-06-17 19:56:38 -0500780lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
781 LPFC_MBOXQ_t * pmb)
dea31012005-04-17 16:05:31 -0500782{
783 MAILBOX_t *mb;
784
James Smart04c68492009-05-22 14:52:52 -0400785 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500786 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
787
788 mb->un.varUnregLogin.rpi = (uint16_t) rpi;
789 mb->un.varUnregLogin.rsvd1 = 0;
James Smart04c68492009-05-22 14:52:52 -0400790 mb->un.varUnregLogin.vpi = vpi + phba->vpi_base;
dea31012005-04-17 16:05:31 -0500791
792 mb->mbxCommand = MBX_UNREG_LOGIN;
793 mb->mbxOwner = OWN_HOST;
James Smart04c68492009-05-22 14:52:52 -0400794
dea31012005-04-17 16:05:31 -0500795 return;
796}
797
James Smarte59058c2008-08-24 21:49:00 -0400798/**
James Smart3621a712009-04-06 18:47:14 -0400799 * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
James Smarte59058c2008-08-24 21:49:00 -0400800 * @phba: pointer to lpfc hba data structure.
801 * @vpi: virtual N_Port identifier.
802 * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
803 * @pmb: pointer to the driver internal queue element for mailbox command.
804 *
805 * The registration vport identifier mailbox command is used to activate a
806 * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
807 * N_Port_ID against the information in the selected virtual N_Port context
808 * block and marks it active to allow normal processing of IOCB commands and
809 * received unsolicited exchanges.
810 *
811 * This routine prepares the mailbox command for registering a virtual N_Port.
812 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500813void
James Smart04c68492009-05-22 14:52:52 -0400814lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
James Smart92d7f7b2007-06-17 19:56:38 -0500815{
James Smart04c68492009-05-22 14:52:52 -0400816 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500817
818 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
819
James Smart04c68492009-05-22 14:52:52 -0400820 mb->un.varRegVpi.vpi = vport->vpi + vport->phba->vpi_base;
821 mb->un.varRegVpi.sid = vport->fc_myDID;
822 mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
James Smartc8685952009-11-18 15:39:16 -0500823 memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname,
824 sizeof(struct lpfc_name));
825 mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]);
826 mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]);
James Smart92d7f7b2007-06-17 19:56:38 -0500827
828 mb->mbxCommand = MBX_REG_VPI;
829 mb->mbxOwner = OWN_HOST;
830 return;
831
832}
833
James Smarte59058c2008-08-24 21:49:00 -0400834/**
James Smart3621a712009-04-06 18:47:14 -0400835 * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
James Smarte59058c2008-08-24 21:49:00 -0400836 * @phba: pointer to lpfc hba data structure.
837 * @vpi: virtual N_Port identifier.
838 * @pmb: pointer to the driver internal queue element for mailbox command.
839 *
840 * The unregistration vport identifier mailbox command is used to inactivate
841 * a virtual N_Port. The driver must have logged out and unregistered all
842 * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
843 * unregisters any default RPIs associated with the specified vpi, aborting
844 * any active exchanges. The HBA will post the mailbox response after making
845 * the virtual N_Port inactive.
846 *
847 * This routine prepares the mailbox command for unregistering a virtual
848 * N_Port.
849 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500850void
851lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
852{
James Smart04c68492009-05-22 14:52:52 -0400853 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500854 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
855
James Smart6669f9b2009-10-02 15:16:45 -0400856 if (phba->sli_rev < LPFC_SLI_REV4)
857 mb->un.varUnregVpi.vpi = vpi + phba->vpi_base;
858 else
859 mb->un.varUnregVpi.sli4_vpi = vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500860
861 mb->mbxCommand = MBX_UNREG_VPI;
862 mb->mbxOwner = OWN_HOST;
863 return;
864
865}
866
James Smarte59058c2008-08-24 21:49:00 -0400867/**
James Smart3621a712009-04-06 18:47:14 -0400868 * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
James Smarte59058c2008-08-24 21:49:00 -0400869 * @phba: pointer to lpfc hba data structure.
870 *
871 * This routine sets up and initializes the IOCB rings in the Port Control
872 * Block (PCB).
873 **/
dea31012005-04-17 16:05:31 -0500874static void
875lpfc_config_pcb_setup(struct lpfc_hba * phba)
876{
877 struct lpfc_sli *psli = &phba->sli;
878 struct lpfc_sli_ring *pring;
James Smart34b02dc2008-08-24 21:49:55 -0400879 PCB_t *pcbp = phba->pcb;
dea31012005-04-17 16:05:31 -0500880 dma_addr_t pdma_addr;
881 uint32_t offset;
James Smart2e0fef82007-06-17 19:56:36 -0500882 uint32_t iocbCnt = 0;
dea31012005-04-17 16:05:31 -0500883 int i;
884
dea31012005-04-17 16:05:31 -0500885 pcbp->maxRing = (psli->num_rings - 1);
886
dea31012005-04-17 16:05:31 -0500887 for (i = 0; i < psli->num_rings; i++) {
888 pring = &psli->ring[i];
James Smart2e0fef82007-06-17 19:56:36 -0500889
James Smarted957682007-06-17 19:56:37 -0500890 pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
James Smart92d7f7b2007-06-17 19:56:38 -0500891 SLI2_IOCB_CMD_SIZE;
James Smarted957682007-06-17 19:56:37 -0500892 pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
James Smart92d7f7b2007-06-17 19:56:38 -0500893 SLI2_IOCB_RSP_SIZE;
dea31012005-04-17 16:05:31 -0500894 /* A ring MUST have both cmd and rsp entries defined to be
895 valid */
896 if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
897 pcbp->rdsc[i].cmdEntries = 0;
898 pcbp->rdsc[i].rspEntries = 0;
899 pcbp->rdsc[i].cmdAddrHigh = 0;
900 pcbp->rdsc[i].rspAddrHigh = 0;
901 pcbp->rdsc[i].cmdAddrLow = 0;
902 pcbp->rdsc[i].rspAddrLow = 0;
903 pring->cmdringaddr = NULL;
904 pring->rspringaddr = NULL;
905 continue;
906 }
907 /* Command ring setup for ring */
James Smart34b02dc2008-08-24 21:49:55 -0400908 pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
dea31012005-04-17 16:05:31 -0500909 pcbp->rdsc[i].cmdEntries = pring->numCiocb;
910
James Smart34b02dc2008-08-24 21:49:55 -0400911 offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
912 (uint8_t *) phba->slim2p.virt;
913 pdma_addr = phba->slim2p.phys + offset;
dea31012005-04-17 16:05:31 -0500914 pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
915 pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
916 iocbCnt += pring->numCiocb;
917
918 /* Response ring setup for ring */
James Smart34b02dc2008-08-24 21:49:55 -0400919 pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt];
dea31012005-04-17 16:05:31 -0500920
921 pcbp->rdsc[i].rspEntries = pring->numRiocb;
James Smart34b02dc2008-08-24 21:49:55 -0400922 offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
923 (uint8_t *)phba->slim2p.virt;
924 pdma_addr = phba->slim2p.phys + offset;
dea31012005-04-17 16:05:31 -0500925 pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
926 pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
927 iocbCnt += pring->numRiocb;
928 }
929}
930
James Smarte59058c2008-08-24 21:49:00 -0400931/**
James Smart3621a712009-04-06 18:47:14 -0400932 * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
James Smarte59058c2008-08-24 21:49:00 -0400933 * @phba: pointer to lpfc hba data structure.
934 * @pmb: pointer to the driver internal queue element for mailbox command.
935 *
936 * The read revision mailbox command is used to read the revision levels of
937 * the HBA components. These components include hardware units, resident
938 * firmware, and available firmware. HBAs that supports SLI-3 mode of
939 * operation provide different response information depending on the version
940 * requested by the driver.
941 *
942 * This routine prepares the mailbox command for reading HBA revision
943 * information.
944 **/
dea31012005-04-17 16:05:31 -0500945void
946lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
947{
James Smart04c68492009-05-22 14:52:52 -0400948 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500949 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
950 mb->un.varRdRev.cv = 1;
James Smarted957682007-06-17 19:56:37 -0500951 mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
dea31012005-04-17 16:05:31 -0500952 mb->mbxCommand = MBX_READ_REV;
953 mb->mbxOwner = OWN_HOST;
954 return;
955}
956
James Smarte59058c2008-08-24 21:49:00 -0400957/**
James Smart3621a712009-04-06 18:47:14 -0400958 * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
James Smarte59058c2008-08-24 21:49:00 -0400959 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
960 * @hbq_desc: pointer to the HBQ selection profile descriptor.
961 *
962 * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
963 * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
964 * the Sequence Length Test using the fields in the Selection Profile 2
965 * extension in words 20:31.
966 **/
James Smarted957682007-06-17 19:56:37 -0500967static void
968lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
969 struct lpfc_hbq_init *hbq_desc)
970{
971 hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
972 hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
973 hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
974}
975
James Smarte59058c2008-08-24 21:49:00 -0400976/**
James Smart3621a712009-04-06 18:47:14 -0400977 * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
James Smarte59058c2008-08-24 21:49:00 -0400978 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
979 * @hbq_desc: pointer to the HBQ selection profile descriptor.
980 *
981 * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
982 * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
983 * the Sequence Length Test and Byte Field Test using the fields in the
984 * Selection Profile 3 extension in words 20:31.
985 **/
James Smarted957682007-06-17 19:56:37 -0500986static void
987lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
988 struct lpfc_hbq_init *hbq_desc)
989{
990 hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
991 hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
992 hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
993 hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
994 memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
995 sizeof(hbqmb->profiles.profile3.cmdmatch));
996}
997
James Smarte59058c2008-08-24 21:49:00 -0400998/**
James Smart3621a712009-04-06 18:47:14 -0400999 * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
James Smarte59058c2008-08-24 21:49:00 -04001000 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1001 * @hbq_desc: pointer to the HBQ selection profile descriptor.
1002 *
1003 * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
1004 * HBA tests the initial frame of an incoming sequence using the frame's
1005 * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
1006 * and Byte Field Test using the fields in the Selection Profile 5 extension
1007 * words 20:31.
1008 **/
James Smarted957682007-06-17 19:56:37 -05001009static void
1010lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
1011 struct lpfc_hbq_init *hbq_desc)
1012{
1013 hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
1014 hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
1015 hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
1016 hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
1017 memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
1018 sizeof(hbqmb->profiles.profile5.cmdmatch));
1019}
1020
James Smarte59058c2008-08-24 21:49:00 -04001021/**
James Smart3621a712009-04-06 18:47:14 -04001022 * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
James Smarte59058c2008-08-24 21:49:00 -04001023 * @phba: pointer to lpfc hba data structure.
1024 * @id: HBQ identifier.
1025 * @hbq_desc: pointer to the HBA descriptor data structure.
1026 * @hbq_entry_index: index of the HBQ entry data structures.
1027 * @pmb: pointer to the driver internal queue element for mailbox command.
1028 *
1029 * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
1030 * an HBQ. The configuration binds events that require buffers to a particular
1031 * ring and HBQ based on a selection profile.
1032 *
1033 * This routine prepares the mailbox command for configuring an HBQ.
1034 **/
James Smarted957682007-06-17 19:56:37 -05001035void
James Smart51ef4c22007-08-02 11:10:31 -04001036lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
1037 struct lpfc_hbq_init *hbq_desc,
James Smarted957682007-06-17 19:56:37 -05001038 uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
1039{
1040 int i;
James Smart04c68492009-05-22 14:52:52 -04001041 MAILBOX_t *mb = &pmb->u.mb;
James Smarted957682007-06-17 19:56:37 -05001042 struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
1043
1044 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
James Smart51ef4c22007-08-02 11:10:31 -04001045 hbqmb->hbqId = id;
James Smarted957682007-06-17 19:56:37 -05001046 hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
1047 hbqmb->recvNotify = hbq_desc->rn; /* Receive
1048 * Notification */
1049 hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
1050 * # in words 0-19 */
James Smart92d7f7b2007-06-17 19:56:38 -05001051 hbqmb->profile = hbq_desc->profile; /* Selection profile:
James Smarted957682007-06-17 19:56:37 -05001052 * 0 = all,
1053 * 7 = logentry */
1054 hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
1055 * e.g. Ring0=b0001,
1056 * ring2=b0100 */
1057 hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
1058 * or 5 */
1059 hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
1060 * HBQ will be used
1061 * for LogEntry
1062 * buffers */
1063 hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
1064 hbq_entry_index * sizeof(struct lpfc_hbq_entry);
1065 hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
1066
1067 mb->mbxCommand = MBX_CONFIG_HBQ;
1068 mb->mbxOwner = OWN_HOST;
1069
James Smart92d7f7b2007-06-17 19:56:38 -05001070 /* Copy info for profiles 2,3,5. Other
1071 * profiles this area is reserved
1072 */
James Smarted957682007-06-17 19:56:37 -05001073 if (hbq_desc->profile == 2)
1074 lpfc_build_hbq_profile2(hbqmb, hbq_desc);
1075 else if (hbq_desc->profile == 3)
1076 lpfc_build_hbq_profile3(hbqmb, hbq_desc);
1077 else if (hbq_desc->profile == 5)
1078 lpfc_build_hbq_profile5(hbqmb, hbq_desc);
1079
1080 /* Return if no rctl / type masks for this HBQ */
1081 if (!hbq_desc->mask_count)
1082 return;
1083
1084 /* Otherwise we setup specific rctl / type masks for this HBQ */
1085 for (i = 0; i < hbq_desc->mask_count; i++) {
1086 hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
1087 hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
1088 hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
1089 hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
1090 }
1091
1092 return;
1093}
1094
James Smarte59058c2008-08-24 21:49:00 -04001095/**
James Smart3621a712009-04-06 18:47:14 -04001096 * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04001097 * @phba: pointer to lpfc hba data structure.
1098 * @ring:
1099 * @pmb: pointer to the driver internal queue element for mailbox command.
1100 *
1101 * The configure ring mailbox command is used to configure an IOCB ring. This
1102 * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1103 * ring. This is used to map incoming sequences to a particular ring whose
1104 * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1105 * attempt to configure a ring whose number is greater than the number
1106 * specified in the Port Control Block (PCB). It is an error to issue the
1107 * configure ring command more than once with the same ring number. The HBA
1108 * returns an error if the driver attempts this.
1109 *
1110 * This routine prepares the mailbox command for configuring IOCB ring.
1111 **/
dea31012005-04-17 16:05:31 -05001112void
1113lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
1114{
1115 int i;
James Smart04c68492009-05-22 14:52:52 -04001116 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001117 struct lpfc_sli *psli;
1118 struct lpfc_sli_ring *pring;
1119
1120 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1121
1122 mb->un.varCfgRing.ring = ring;
1123 mb->un.varCfgRing.maxOrigXchg = 0;
1124 mb->un.varCfgRing.maxRespXchg = 0;
1125 mb->un.varCfgRing.recvNotify = 1;
1126
1127 psli = &phba->sli;
1128 pring = &psli->ring[ring];
1129 mb->un.varCfgRing.numMask = pring->num_mask;
1130 mb->mbxCommand = MBX_CONFIG_RING;
1131 mb->mbxOwner = OWN_HOST;
1132
1133 /* Is this ring configured for a specific profile */
1134 if (pring->prt[0].profile) {
1135 mb->un.varCfgRing.profile = pring->prt[0].profile;
1136 return;
1137 }
1138
1139 /* Otherwise we setup specific rctl / type masks for this ring */
1140 for (i = 0; i < pring->num_mask; i++) {
1141 mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
James Smart6a9c52c2009-10-02 15:16:51 -04001142 if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ)
dea31012005-04-17 16:05:31 -05001143 mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
1144 else
1145 mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
1146 mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
1147 mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
1148 }
1149
1150 return;
1151}
1152
James Smarte59058c2008-08-24 21:49:00 -04001153/**
James Smart3621a712009-04-06 18:47:14 -04001154 * lpfc_config_port - Prepare a mailbox command for configuring port
James Smarte59058c2008-08-24 21:49:00 -04001155 * @phba: pointer to lpfc hba data structure.
1156 * @pmb: pointer to the driver internal queue element for mailbox command.
1157 *
1158 * The configure port mailbox command is used to identify the Port Control
1159 * Block (PCB) in the driver memory. After this command is issued, the
1160 * driver must not access the mailbox in the HBA without first resetting
1161 * the HBA. The HBA may copy the PCB information to internal storage for
1162 * subsequent use; the driver can not change the PCB information unless it
1163 * resets the HBA.
1164 *
1165 * This routine prepares the mailbox command for configuring port.
1166 **/
dea31012005-04-17 16:05:31 -05001167void
James Smart92d7f7b2007-06-17 19:56:38 -05001168lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001169{
James Smarted957682007-06-17 19:56:37 -05001170 MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
James Smart04c68492009-05-22 14:52:52 -04001171 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001172 dma_addr_t pdma_addr;
1173 uint32_t bar_low, bar_high;
1174 size_t offset;
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04001175 struct lpfc_hgp hgp;
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001176 int i;
James Smarted957682007-06-17 19:56:37 -05001177 uint32_t pgp_offset;
dea31012005-04-17 16:05:31 -05001178
1179 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1180 mb->mbxCommand = MBX_CONFIG_PORT;
1181 mb->mbxOwner = OWN_HOST;
1182
1183 mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
1184
James Smart34b02dc2008-08-24 21:49:55 -04001185 offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
1186 pdma_addr = phba->slim2p.phys + offset;
dea31012005-04-17 16:05:31 -05001187 mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
1188 mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
1189
James Smart97207482008-12-04 22:39:19 -05001190 /* Always Host Group Pointer is in SLIM */
1191 mb->un.varCfgPort.hps = 1;
1192
James Smarted957682007-06-17 19:56:37 -05001193 /* If HBA supports SLI=3 ask for it */
1194
James Smart04c68492009-05-22 14:52:52 -04001195 if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
James Smarte2a0a9d2008-12-04 22:40:02 -05001196 if (phba->cfg_enable_bg)
1197 mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
James Smart04c68492009-05-22 14:52:52 -04001198 mb->un.varCfgPort.cdss = 1; /* Configure Security */
James Smarted957682007-06-17 19:56:37 -05001199 mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
James Smart34b02dc2008-08-24 21:49:55 -04001200 mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
1201 mb->un.varCfgPort.cinb = 1; /* Interrupt Notification Block */
James Smart51ef4c22007-08-02 11:10:31 -04001202 mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
James Smart78b2d852007-08-02 11:10:21 -04001203 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smart92d7f7b2007-06-17 19:56:38 -05001204 phba->vpd.sli3Feat.cmv) {
James Smart04c68492009-05-22 14:52:52 -04001205 mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI;
James Smart92d7f7b2007-06-17 19:56:38 -05001206 mb->un.varCfgPort.cmv = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001207 } else
1208 mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
1209 } else
James Smart04c68492009-05-22 14:52:52 -04001210 phba->sli_rev = LPFC_SLI_REV2;
James Smart92d7f7b2007-06-17 19:56:38 -05001211 mb->un.varCfgPort.sli_mode = phba->sli_rev;
James Smarted957682007-06-17 19:56:37 -05001212
dea31012005-04-17 16:05:31 -05001213 /* Now setup pcb */
James Smart34b02dc2008-08-24 21:49:55 -04001214 phba->pcb->type = TYPE_NATIVE_SLI2;
1215 phba->pcb->feature = FEATURE_INITIAL_SLI2;
dea31012005-04-17 16:05:31 -05001216
1217 /* Setup Mailbox pointers */
James Smart34b02dc2008-08-24 21:49:55 -04001218 phba->pcb->mailBoxSize = sizeof(MAILBOX_t);
1219 offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
1220 pdma_addr = phba->slim2p.phys + offset;
1221 phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
1222 phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
dea31012005-04-17 16:05:31 -05001223
1224 /*
1225 * Setup Host Group ring pointer.
1226 *
1227 * For efficiency reasons, the ring get/put pointers can be
1228 * placed in adapter memory (SLIM) rather than in host memory.
1229 * This allows firmware to avoid PCI reads/writes when updating
1230 * and checking pointers.
1231 *
1232 * The firmware recognizes the use of SLIM memory by comparing
1233 * the address of the get/put pointers structure with that of
1234 * the SLIM BAR (BAR0).
1235 *
1236 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1237 * (the hardware's view of the base address), not the OS's
1238 * value of pci_resource_start() as the OS value may be a cookie
1239 * for ioremap/iomap.
1240 */
1241
1242
1243 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
1244 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
1245
James Smarted957682007-06-17 19:56:37 -05001246 /*
1247 * Set up HGP - Port Memory
1248 *
1249 * The port expects the host get/put pointers to reside in memory
1250 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1251 * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
1252 * words (0x40 bytes). This area is not reserved if HBQs are
1253 * configured in SLI-3.
1254 *
1255 * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1256 * RR0Get 0xc4 0x84
1257 * CR1Put 0xc8 0x88
1258 * RR1Get 0xcc 0x8c
1259 * CR2Put 0xd0 0x90
1260 * RR2Get 0xd4 0x94
1261 * CR3Put 0xd8 0x98
1262 * RR3Get 0xdc 0x9c
1263 *
1264 * Reserved 0xa0-0xbf
1265 * If HBQs configured:
1266 * HBQ 0 Put ptr 0xc0
1267 * HBQ 1 Put ptr 0xc4
1268 * HBQ 2 Put ptr 0xc8
1269 * ......
1270 * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1271 *
1272 */
1273
1274 if (phba->sli_rev == 3) {
1275 phba->host_gp = &mb_slim->us.s3.host[0];
1276 phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
1277 } else {
1278 phba->host_gp = &mb_slim->us.s2.host[0];
1279 phba->hbq_put = NULL;
1280 }
dea31012005-04-17 16:05:31 -05001281
1282 /* mask off BAR0's flag bits 0 - 3 */
James Smart34b02dc2008-08-24 21:49:55 -04001283 phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
1284 (void __iomem *)phba->host_gp -
James Smarted957682007-06-17 19:56:37 -05001285 (void __iomem *)phba->MBslimaddr;
dea31012005-04-17 16:05:31 -05001286 if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
James Smart34b02dc2008-08-24 21:49:55 -04001287 phba->pcb->hgpAddrHigh = bar_high;
dea31012005-04-17 16:05:31 -05001288 else
James Smart34b02dc2008-08-24 21:49:55 -04001289 phba->pcb->hgpAddrHigh = 0;
dea31012005-04-17 16:05:31 -05001290 /* write HGP data to SLIM at the required longword offset */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04001291 memset(&hgp, 0, sizeof(struct lpfc_hgp));
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001292
1293 for (i=0; i < phba->sli.num_rings; i++) {
James Smarted957682007-06-17 19:56:37 -05001294 lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
1295 sizeof(*phba->host_gp));
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001296 }
dea31012005-04-17 16:05:31 -05001297
James Smart8f34f4c2008-12-04 22:39:23 -05001298 /* Setup Port Group offset */
1299 if (phba->sli_rev == 3)
James Smart34b02dc2008-08-24 21:49:55 -04001300 pgp_offset = offsetof(struct lpfc_sli2_slim,
1301 mbx.us.s3_pgp.port);
James Smart8f34f4c2008-12-04 22:39:23 -05001302 else
James Smart34b02dc2008-08-24 21:49:55 -04001303 pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
1304 pdma_addr = phba->slim2p.phys + pgp_offset;
1305 phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
1306 phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
dea31012005-04-17 16:05:31 -05001307
1308 /* Use callback routine to setp rings in the pcb */
1309 lpfc_config_pcb_setup(phba);
1310
1311 /* special handling for LC HBAs */
1312 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
1313 uint32_t hbainit[5];
1314
1315 lpfc_hba_init(phba, hbainit);
1316
1317 memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
1318 }
1319
1320 /* Swap PCB if needed */
James Smart34b02dc2008-08-24 21:49:55 -04001321 lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
dea31012005-04-17 16:05:31 -05001322}
1323
James Smarte59058c2008-08-24 21:49:00 -04001324/**
James Smart3621a712009-04-06 18:47:14 -04001325 * lpfc_kill_board - Prepare a mailbox command for killing board
James Smarte59058c2008-08-24 21:49:00 -04001326 * @phba: pointer to lpfc hba data structure.
1327 * @pmb: pointer to the driver internal queue element for mailbox command.
1328 *
1329 * The kill board mailbox command is used to tell firmware to perform a
1330 * graceful shutdown of a channel on a specified board to prepare for reset.
1331 * When the kill board mailbox command is received, the ER3 bit is set to 1
1332 * in the Host Status register and the ER Attention bit is set to 1 in the
1333 * Host Attention register of the HBA function that received the kill board
1334 * command.
1335 *
1336 * This routine prepares the mailbox command for killing the board in
1337 * preparation for a graceful shutdown.
1338 **/
dea31012005-04-17 16:05:31 -05001339void
Jamie Wellnitz41415862006-02-28 19:25:27 -05001340lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1341{
James Smart04c68492009-05-22 14:52:52 -04001342 MAILBOX_t *mb = &pmb->u.mb;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001343
1344 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1345 mb->mbxCommand = MBX_KILL_BOARD;
1346 mb->mbxOwner = OWN_HOST;
1347 return;
1348}
1349
James Smarte59058c2008-08-24 21:49:00 -04001350/**
James Smart3621a712009-04-06 18:47:14 -04001351 * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
James Smarte59058c2008-08-24 21:49:00 -04001352 * @phba: pointer to lpfc hba data structure.
1353 * @mbq: pointer to the driver internal queue element for mailbox command.
1354 *
1355 * Driver maintains a internal mailbox command queue implemented as a linked
1356 * list. When a mailbox command is issued, it shall be put into the mailbox
1357 * command queue such that they shall be processed orderly as HBA can process
1358 * one mailbox command at a time.
1359 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001360void
dea31012005-04-17 16:05:31 -05001361lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1362{
1363 struct lpfc_sli *psli;
1364
1365 psli = &phba->sli;
1366
1367 list_add_tail(&mbq->list, &psli->mboxq);
1368
1369 psli->mboxq_cnt++;
1370
1371 return;
1372}
1373
James Smarte59058c2008-08-24 21:49:00 -04001374/**
James Smart3621a712009-04-06 18:47:14 -04001375 * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
James Smarte59058c2008-08-24 21:49:00 -04001376 * @phba: pointer to lpfc hba data structure.
1377 *
1378 * Driver maintains a internal mailbox command queue implemented as a linked
1379 * list. When a mailbox command is issued, it shall be put into the mailbox
1380 * command queue such that they shall be processed orderly as HBA can process
1381 * one mailbox command at a time. After HBA finished processing a mailbox
1382 * command, the driver will remove a pending mailbox command from the head of
1383 * the mailbox command queue and send to the HBA for processing.
1384 *
1385 * Return codes
1386 * pointer to the driver internal queue element for mailbox command.
1387 **/
dea31012005-04-17 16:05:31 -05001388LPFC_MBOXQ_t *
1389lpfc_mbox_get(struct lpfc_hba * phba)
1390{
1391 LPFC_MBOXQ_t *mbq = NULL;
1392 struct lpfc_sli *psli = &phba->sli;
1393
James Smart2e0fef82007-06-17 19:56:36 -05001394 list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
James Smart92d7f7b2007-06-17 19:56:38 -05001395 if (mbq)
dea31012005-04-17 16:05:31 -05001396 psli->mboxq_cnt--;
dea31012005-04-17 16:05:31 -05001397
1398 return mbq;
1399}
James Smarta309a6b2006-08-01 07:33:43 -04001400
James Smarte59058c2008-08-24 21:49:00 -04001401/**
James Smart04c68492009-05-22 14:52:52 -04001402 * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
1403 * @phba: pointer to lpfc hba data structure.
1404 * @mbq: pointer to the driver internal queue element for mailbox command.
1405 *
1406 * This routine put the completed mailbox command into the mailbox command
1407 * complete list. This is the unlocked version of the routine. The mailbox
1408 * complete list is used by the driver worker thread to process mailbox
1409 * complete callback functions outside the driver interrupt handler.
1410 **/
1411void
1412__lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
1413{
1414 list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
1415}
1416
1417/**
James Smart3621a712009-04-06 18:47:14 -04001418 * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
James Smarte59058c2008-08-24 21:49:00 -04001419 * @phba: pointer to lpfc hba data structure.
1420 * @mbq: pointer to the driver internal queue element for mailbox command.
1421 *
1422 * This routine put the completed mailbox command into the mailbox command
James Smart04c68492009-05-22 14:52:52 -04001423 * complete list. This is the locked version of the routine. The mailbox
1424 * complete list is used by the driver worker thread to process mailbox
1425 * complete callback functions outside the driver interrupt handler.
James Smarte59058c2008-08-24 21:49:00 -04001426 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001427void
James Smart04c68492009-05-22 14:52:52 -04001428lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
James Smart92d7f7b2007-06-17 19:56:38 -05001429{
James Smart5b75da22008-12-04 22:39:35 -05001430 unsigned long iflag;
1431
Joe Perchesb1c11812008-02-03 17:28:22 +02001432 /* This function expects to be called from interrupt context */
James Smart5b75da22008-12-04 22:39:35 -05001433 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart04c68492009-05-22 14:52:52 -04001434 __lpfc_mbox_cmpl_put(phba, mbq);
James Smart5b75da22008-12-04 22:39:35 -05001435 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05001436 return;
1437}
1438
James Smarte59058c2008-08-24 21:49:00 -04001439/**
James Smart04c68492009-05-22 14:52:52 -04001440 * lpfc_mbox_cmd_check - Check the validality of a mailbox command
1441 * @phba: pointer to lpfc hba data structure.
1442 * @mboxq: pointer to the driver internal queue element for mailbox command.
1443 *
1444 * This routine is to check whether a mailbox command is valid to be issued.
1445 * This check will be performed by both the mailbox issue API when a client
1446 * is to issue a mailbox command to the mailbox transport.
1447 *
1448 * Return 0 - pass the check, -ENODEV - fail the check
1449 **/
1450int
1451lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1452{
1453 /* Mailbox command that have a completion handler must also have a
1454 * vport specified.
1455 */
1456 if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
1457 mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
1458 if (!mboxq->vport) {
1459 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
1460 "1814 Mbox x%x failed, no vport\n",
1461 mboxq->u.mb.mbxCommand);
1462 dump_stack();
1463 return -ENODEV;
1464 }
1465 }
1466 return 0;
1467}
1468
1469/**
1470 * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
1471 * @phba: pointer to lpfc hba data structure.
1472 *
1473 * This routine is to check whether the HBA device is ready for posting a
1474 * mailbox command. It is used by the mailbox transport API at the time the
1475 * to post a mailbox command to the device.
1476 *
1477 * Return 0 - pass the check, -ENODEV - fail the check
1478 **/
1479int
1480lpfc_mbox_dev_check(struct lpfc_hba *phba)
1481{
1482 /* If the PCI channel is in offline state, do not issue mbox */
1483 if (unlikely(pci_channel_offline(phba->pcidev)))
1484 return -ENODEV;
1485
1486 /* If the HBA is in error state, do not issue mbox */
1487 if (phba->link_state == LPFC_HBA_ERROR)
1488 return -ENODEV;
1489
1490 return 0;
1491}
1492
1493/**
James Smart3621a712009-04-06 18:47:14 -04001494 * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
James Smarte59058c2008-08-24 21:49:00 -04001495 * @phba: pointer to lpfc hba data structure.
1496 * @cmd: mailbox command code.
1497 *
1498 * This routine retrieves the proper timeout value according to the mailbox
1499 * command code.
1500 *
1501 * Return codes
1502 * Timeout value to be used for the given mailbox command
1503 **/
James Smarta309a6b2006-08-01 07:33:43 -04001504int
1505lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
1506{
1507 switch (cmd) {
1508 case MBX_WRITE_NV: /* 0x03 */
1509 case MBX_UPDATE_CFG: /* 0x1B */
1510 case MBX_DOWN_LOAD: /* 0x1C */
1511 case MBX_DEL_LD_ENTRY: /* 0x1D */
1512 case MBX_LOAD_AREA: /* 0x81 */
James Smart09372822008-01-11 01:52:54 -05001513 case MBX_WRITE_WWN: /* 0x98 */
James Smarta309a6b2006-08-01 07:33:43 -04001514 case MBX_LOAD_EXP_ROM: /* 0x9C */
1515 return LPFC_MBOX_TMO_FLASH_CMD;
James Smart04c68492009-05-22 14:52:52 -04001516 case MBX_SLI4_CONFIG: /* 0x9b */
1517 return LPFC_MBOX_SLI4_CONFIG_TMO;
James Smarta309a6b2006-08-01 07:33:43 -04001518 }
1519 return LPFC_MBOX_TMO;
1520}
James Smart04c68492009-05-22 14:52:52 -04001521
1522/**
1523 * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
1524 * @mbox: pointer to lpfc mbox command.
1525 * @sgentry: sge entry index.
1526 * @phyaddr: physical address for the sge
1527 * @length: Length of the sge.
1528 *
1529 * This routine sets up an entry in the non-embedded mailbox command at the sge
1530 * index location.
1531 **/
1532void
1533lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry,
1534 dma_addr_t phyaddr, uint32_t length)
1535{
1536 struct lpfc_mbx_nembed_cmd *nembed_sge;
1537
1538 nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1539 &mbox->u.mqe.un.nembed_cmd;
1540 nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr);
1541 nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr);
1542 nembed_sge->sge[sgentry].length = length;
1543}
1544
1545/**
1546 * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
1547 * @mbox: pointer to lpfc mbox command.
1548 * @sgentry: sge entry index.
1549 *
1550 * This routine gets an entry from the non-embedded mailbox command at the sge
1551 * index location.
1552 **/
1553void
1554lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry,
1555 struct lpfc_mbx_sge *sge)
1556{
1557 struct lpfc_mbx_nembed_cmd *nembed_sge;
1558
1559 nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1560 &mbox->u.mqe.un.nembed_cmd;
1561 sge->pa_lo = nembed_sge->sge[sgentry].pa_lo;
1562 sge->pa_hi = nembed_sge->sge[sgentry].pa_hi;
1563 sge->length = nembed_sge->sge[sgentry].length;
1564}
1565
1566/**
1567 * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
1568 * @phba: pointer to lpfc hba data structure.
1569 * @mbox: pointer to lpfc mbox command.
1570 *
1571 * This routine frees SLI4 specific mailbox command for sending IOCTL command.
1572 **/
1573void
1574lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1575{
1576 struct lpfc_mbx_sli4_config *sli4_cfg;
1577 struct lpfc_mbx_sge sge;
1578 dma_addr_t phyaddr;
1579 uint32_t sgecount, sgentry;
1580
1581 sli4_cfg = &mbox->u.mqe.un.sli4_config;
1582
1583 /* For embedded mbox command, just free the mbox command */
1584 if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1585 mempool_free(mbox, phba->mbox_mem_pool);
1586 return;
1587 }
1588
1589 /* For non-embedded mbox command, we need to free the pages first */
1590 sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr);
1591 /* There is nothing we can do if there is no sge address array */
1592 if (unlikely(!mbox->sge_array)) {
1593 mempool_free(mbox, phba->mbox_mem_pool);
1594 return;
1595 }
1596 /* Each non-embedded DMA memory was allocated in the length of a page */
1597 for (sgentry = 0; sgentry < sgecount; sgentry++) {
1598 lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge);
1599 phyaddr = getPaddr(sge.pa_hi, sge.pa_lo);
1600 dma_free_coherent(&phba->pcidev->dev, PAGE_SIZE,
1601 mbox->sge_array->addr[sgentry], phyaddr);
1602 }
1603 /* Free the sge address array memory */
1604 kfree(mbox->sge_array);
1605 /* Finally, free the mailbox command itself */
1606 mempool_free(mbox, phba->mbox_mem_pool);
1607}
1608
1609/**
1610 * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command
1611 * @phba: pointer to lpfc hba data structure.
1612 * @mbox: pointer to lpfc mbox command.
1613 * @subsystem: The sli4 config sub mailbox subsystem.
1614 * @opcode: The sli4 config sub mailbox command opcode.
1615 * @length: Length of the sli4 config mailbox command.
1616 *
1617 * This routine sets up the header fields of SLI4 specific mailbox command
1618 * for sending IOCTL command.
1619 *
1620 * Return: the actual length of the mbox command allocated (mostly useful
1621 * for none embedded mailbox command).
1622 **/
1623int
1624lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
1625 uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb)
1626{
1627 struct lpfc_mbx_sli4_config *sli4_config;
1628 union lpfc_sli4_cfg_shdr *cfg_shdr = NULL;
1629 uint32_t alloc_len;
1630 uint32_t resid_len;
1631 uint32_t pagen, pcount;
1632 void *viraddr;
1633 dma_addr_t phyaddr;
1634
1635 /* Set up SLI4 mailbox command header fields */
1636 memset(mbox, 0, sizeof(*mbox));
1637 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG);
1638
1639 /* Set up SLI4 ioctl command header fields */
1640 sli4_config = &mbox->u.mqe.un.sli4_config;
1641
1642 /* Setup for the embedded mbox command */
1643 if (emb) {
1644 /* Set up main header fields */
1645 bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
1646 sli4_config->header.cfg_mhdr.payload_length =
1647 LPFC_MBX_CMD_HDR_LENGTH + length;
1648 /* Set up sub-header fields following main header */
1649 bf_set(lpfc_mbox_hdr_opcode,
1650 &sli4_config->header.cfg_shdr.request, opcode);
1651 bf_set(lpfc_mbox_hdr_subsystem,
1652 &sli4_config->header.cfg_shdr.request, subsystem);
1653 sli4_config->header.cfg_shdr.request.request_length = length;
1654 return length;
1655 }
1656
1657 /* Setup for the none-embedded mbox command */
1658 pcount = (PAGE_ALIGN(length))/PAGE_SIZE;
1659 pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ?
1660 LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount;
1661 /* Allocate record for keeping SGE virtual addresses */
1662 mbox->sge_array = kmalloc(sizeof(struct lpfc_mbx_nembed_sge_virt),
1663 GFP_KERNEL);
James Smart6a9c52c2009-10-02 15:16:51 -04001664 if (!mbox->sge_array) {
1665 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1666 "2527 Failed to allocate non-embedded SGE "
1667 "array.\n");
James Smart04c68492009-05-22 14:52:52 -04001668 return 0;
James Smart6a9c52c2009-10-02 15:16:51 -04001669 }
James Smart04c68492009-05-22 14:52:52 -04001670 for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) {
1671 /* The DMA memory is always allocated in the length of a
1672 * page even though the last SGE might not fill up to a
1673 * page, this is used as a priori size of PAGE_SIZE for
1674 * the later DMA memory free.
1675 */
1676 viraddr = dma_alloc_coherent(&phba->pcidev->dev, PAGE_SIZE,
1677 &phyaddr, GFP_KERNEL);
1678 /* In case of malloc fails, proceed with whatever we have */
1679 if (!viraddr)
1680 break;
James Smartd11e31d2009-06-10 17:23:06 -04001681 memset(viraddr, 0, PAGE_SIZE);
James Smart04c68492009-05-22 14:52:52 -04001682 mbox->sge_array->addr[pagen] = viraddr;
1683 /* Keep the first page for later sub-header construction */
1684 if (pagen == 0)
1685 cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr;
1686 resid_len = length - alloc_len;
1687 if (resid_len > PAGE_SIZE) {
1688 lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
1689 PAGE_SIZE);
1690 alloc_len += PAGE_SIZE;
1691 } else {
1692 lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
1693 resid_len);
1694 alloc_len = length;
1695 }
1696 }
1697
1698 /* Set up main header fields in mailbox command */
1699 sli4_config->header.cfg_mhdr.payload_length = alloc_len;
1700 bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen);
1701
1702 /* Set up sub-header fields into the first page */
1703 if (pagen > 0) {
1704 bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode);
1705 bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem);
1706 cfg_shdr->request.request_length =
1707 alloc_len - sizeof(union lpfc_sli4_cfg_shdr);
1708 }
1709 /* The sub-header is in DMA memory, which needs endian converstion */
1710 lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
1711 sizeof(union lpfc_sli4_cfg_shdr));
1712
1713 return alloc_len;
1714}
1715
1716/**
1717 * lpfc_sli4_mbox_opcode_get - Get the opcode from a sli4 mailbox command
1718 * @phba: pointer to lpfc hba data structure.
1719 * @mbox: pointer to lpfc mbox command.
1720 *
1721 * This routine gets the opcode from a SLI4 specific mailbox command for
1722 * sending IOCTL command. If the mailbox command is not MBX_SLI4_CONFIG
1723 * (0x9B) or if the IOCTL sub-header is not present, opcode 0x0 shall be
1724 * returned.
1725 **/
1726uint8_t
1727lpfc_sli4_mbox_opcode_get(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1728{
1729 struct lpfc_mbx_sli4_config *sli4_cfg;
1730 union lpfc_sli4_cfg_shdr *cfg_shdr;
1731
1732 if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
1733 return 0;
1734 sli4_cfg = &mbox->u.mqe.un.sli4_config;
1735
1736 /* For embedded mbox command, get opcode from embedded sub-header*/
1737 if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1738 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
1739 return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
1740 }
1741
1742 /* For non-embedded mbox command, get opcode from first dma page */
1743 if (unlikely(!mbox->sge_array))
1744 return 0;
1745 cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
1746 return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
1747}
1748
1749/**
James Smartecfd03c2010-02-12 14:41:27 -05001750 * lpfc_sli4_mbx_read_fcf_record - Allocate and construct read fcf mbox cmd
1751 * @phba: pointer to lpfc hba data structure.
1752 * @fcf_index: index to fcf table.
1753 *
1754 * This routine routine allocates and constructs non-embedded mailbox command
1755 * for reading a FCF table entry refered by @fcf_index.
1756 *
1757 * Return: pointer to the mailbox command constructed if successful, otherwise
1758 * NULL.
1759 **/
1760int
1761lpfc_sli4_mbx_read_fcf_record(struct lpfc_hba *phba,
1762 struct lpfcMboxq *mboxq,
1763 uint16_t fcf_index)
1764{
1765 void *virt_addr;
1766 dma_addr_t phys_addr;
1767 uint8_t *bytep;
1768 struct lpfc_mbx_sge sge;
1769 uint32_t alloc_len, req_len;
1770 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1771
1772 if (!mboxq)
1773 return -ENOMEM;
1774
1775 req_len = sizeof(struct fcf_record) +
1776 sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
1777
1778 /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
1779 alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
1780 LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
1781 LPFC_SLI4_MBX_NEMBED);
1782
1783 if (alloc_len < req_len) {
1784 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1785 "0291 Allocated DMA memory size (x%x) is "
1786 "less than the requested DMA memory "
1787 "size (x%x)\n", alloc_len, req_len);
1788 return -ENOMEM;
1789 }
1790
1791 /* Get the first SGE entry from the non-embedded DMA memory. This
1792 * routine only uses a single SGE.
1793 */
1794 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1795 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
1796 virt_addr = mboxq->sge_array->addr[0];
1797 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1798
1799 /* Set up command fields */
1800 bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
1801 /* Perform necessary endian conversion */
1802 bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
1803 lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
1804
1805 return 0;
1806}
1807
1808/**
James Smart04c68492009-05-22 14:52:52 -04001809 * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
1810 * @mboxq: pointer to lpfc mbox command.
1811 *
1812 * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
1813 * mailbox command.
1814 **/
1815void
1816lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
1817{
1818 /* Set up SLI4 mailbox command header fields */
1819 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
1820 bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS);
1821
1822 /* Set up host requested features. */
1823 bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
1824
James Smart04c68492009-05-22 14:52:52 -04001825 /* Enable DIF (block guard) only if configured to do so. */
1826 if (phba->cfg_enable_bg)
1827 bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1);
1828
1829 /* Enable NPIV only if configured to do so. */
1830 if (phba->max_vpi && phba->cfg_enable_npiv)
1831 bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1);
1832
1833 return;
1834}
1835
1836/**
1837 * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
1838 * @mbox: pointer to lpfc mbox command to initialize.
1839 * @vport: Vport associated with the VF.
1840 *
1841 * This routine initializes @mbox to all zeros and then fills in the mailbox
1842 * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
1843 * in the context of an FCF. The driver issues this command to setup a VFI
1844 * before issuing a FLOGI to login to the VSAN. The driver should also issue a
1845 * REG_VFI after a successful VSAN login.
1846 **/
1847void
1848lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
1849{
1850 struct lpfc_mbx_init_vfi *init_vfi;
1851
1852 memset(mbox, 0, sizeof(*mbox));
1853 init_vfi = &mbox->u.mqe.un.init_vfi;
1854 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI);
1855 bf_set(lpfc_init_vfi_vr, init_vfi, 1);
1856 bf_set(lpfc_init_vfi_vt, init_vfi, 1);
1857 bf_set(lpfc_init_vfi_vfi, init_vfi, vport->vfi + vport->phba->vfi_base);
1858 bf_set(lpfc_init_vfi_fcfi, init_vfi, vport->phba->fcf.fcfi);
1859}
1860
1861/**
1862 * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
1863 * @mbox: pointer to lpfc mbox command to initialize.
1864 * @vport: vport associated with the VF.
1865 * @phys: BDE DMA bus address used to send the service parameters to the HBA.
1866 *
1867 * This routine initializes @mbox to all zeros and then fills in the mailbox
1868 * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
1869 * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
1870 * fabrics identified by VFI in the context of an FCF.
1871 **/
1872void
1873lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys)
1874{
1875 struct lpfc_mbx_reg_vfi *reg_vfi;
1876
1877 memset(mbox, 0, sizeof(*mbox));
1878 reg_vfi = &mbox->u.mqe.un.reg_vfi;
1879 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI);
1880 bf_set(lpfc_reg_vfi_vp, reg_vfi, 1);
1881 bf_set(lpfc_reg_vfi_vfi, reg_vfi, vport->vfi + vport->phba->vfi_base);
1882 bf_set(lpfc_reg_vfi_fcfi, reg_vfi, vport->phba->fcf.fcfi);
1883 bf_set(lpfc_reg_vfi_vpi, reg_vfi, vport->vpi + vport->phba->vpi_base);
James Smartc8685952009-11-18 15:39:16 -05001884 memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name));
1885 reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]);
1886 reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]);
James Smart04c68492009-05-22 14:52:52 -04001887 reg_vfi->bde.addrHigh = putPaddrHigh(phys);
1888 reg_vfi->bde.addrLow = putPaddrLow(phys);
1889 reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam);
1890 reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1891 bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID);
1892}
1893
1894/**
1895 * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
James Smart1c6834a2009-07-19 10:01:26 -04001896 * @phba: pointer to the hba structure to init the VPI for.
James Smart04c68492009-05-22 14:52:52 -04001897 * @mbox: pointer to lpfc mbox command to initialize.
1898 * @vpi: VPI to be initialized.
1899 *
1900 * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
1901 * command to activate a virtual N_Port. The HBA assigns a MAC address to use
1902 * with the virtual N Port. The SLI Host issues this command before issuing a
1903 * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
1904 * successful virtual NPort login.
1905 **/
1906void
James Smart1c6834a2009-07-19 10:01:26 -04001907lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi)
James Smart04c68492009-05-22 14:52:52 -04001908{
1909 memset(mbox, 0, sizeof(*mbox));
1910 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI);
James Smart1c6834a2009-07-19 10:01:26 -04001911 bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi,
1912 vpi + phba->vpi_base);
1913 bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi,
1914 phba->pport->vfi + phba->vfi_base);
James Smart04c68492009-05-22 14:52:52 -04001915}
1916
1917/**
1918 * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
1919 * @mbox: pointer to lpfc mbox command to initialize.
James Smart6669f9b2009-10-02 15:16:45 -04001920 * @vport: vport associated with the VF.
James Smart04c68492009-05-22 14:52:52 -04001921 *
1922 * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
1923 * (logical NPort) into the inactive state. The SLI Host must have logged out
1924 * and unregistered all remote N_Ports to abort any activity on the virtual
1925 * fabric. The SLI Port posts the mailbox response after marking the virtual
1926 * fabric inactive.
1927 **/
1928void
James Smart6669f9b2009-10-02 15:16:45 -04001929lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
James Smart04c68492009-05-22 14:52:52 -04001930{
1931 memset(mbox, 0, sizeof(*mbox));
1932 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI);
James Smart6669f9b2009-10-02 15:16:45 -04001933 bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi,
1934 vport->vfi + vport->phba->vfi_base);
James Smart04c68492009-05-22 14:52:52 -04001935}
1936
1937/**
1938 * lpfc_dump_fcoe_param - Dump config region 23 to get FCoe parameters.
1939 * @phba: pointer to the hba structure containing.
1940 * @mbox: pointer to lpfc mbox command to initialize.
1941 *
1942 * This function create a SLI4 dump mailbox command to dump FCoE
1943 * parameters stored in region 23.
1944 **/
1945int
1946lpfc_dump_fcoe_param(struct lpfc_hba *phba,
1947 struct lpfcMboxq *mbox)
1948{
1949 struct lpfc_dmabuf *mp = NULL;
1950 MAILBOX_t *mb;
1951
1952 memset(mbox, 0, sizeof(*mbox));
1953 mb = &mbox->u.mb;
1954
1955 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1956 if (mp)
1957 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
1958
1959 if (!mp || !mp->virt) {
1960 kfree(mp);
1961 /* dump_fcoe_param failed to allocate memory */
1962 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
1963 "2569 lpfc_dump_fcoe_param: memory"
James Smarte4e74272009-07-19 10:01:38 -04001964 " allocation failed\n");
James Smart04c68492009-05-22 14:52:52 -04001965 return 1;
1966 }
1967
1968 memset(mp->virt, 0, LPFC_BPL_SIZE);
1969 INIT_LIST_HEAD(&mp->list);
1970
1971 /* save address for completion */
1972 mbox->context1 = (uint8_t *) mp;
1973
1974 mb->mbxCommand = MBX_DUMP_MEMORY;
1975 mb->un.varDmp.type = DMP_NV_PARAMS;
James Smarta0c87cb2009-07-19 10:01:10 -04001976 mb->un.varDmp.region_id = DMP_REGION_23;
1977 mb->un.varDmp.sli4_length = DMP_RGN23_SIZE;
James Smart04c68492009-05-22 14:52:52 -04001978 mb->un.varWords[3] = putPaddrLow(mp->phys);
1979 mb->un.varWords[4] = putPaddrHigh(mp->phys);
1980 return 0;
1981}
1982
1983/**
1984 * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
1985 * @phba: pointer to the hba structure containing the FCF index and RQ ID.
1986 * @mbox: pointer to lpfc mbox command to initialize.
1987 *
1988 * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
1989 * SLI Host uses the command to activate an FCF after it has acquired FCF
1990 * information via a READ_FCF mailbox command. This mailbox command also is used
1991 * to indicate where received unsolicited frames from this FCF will be sent. By
1992 * default this routine will set up the FCF to forward all unsolicited frames
1993 * the the RQ ID passed in the @phba. This can be overridden by the caller for
1994 * more complicated setups.
1995 **/
1996void
1997lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1998{
1999 struct lpfc_mbx_reg_fcfi *reg_fcfi;
2000
2001 memset(mbox, 0, sizeof(*mbox));
2002 reg_fcfi = &mbox->u.mqe.un.reg_fcfi;
2003 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI);
2004 bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, phba->sli4_hba.hdr_rq->queue_id);
2005 bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
2006 bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
2007 bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
James Smartecfd03c2010-02-12 14:41:27 -05002008 bf_set(lpfc_reg_fcfi_info_index, reg_fcfi,
2009 phba->fcf.current_rec.fcf_indx);
James Smart04c68492009-05-22 14:52:52 -04002010 /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */
James Smartecfd03c2010-02-12 14:41:27 -05002011 bf_set(lpfc_reg_fcfi_mam, reg_fcfi, (~phba->fcf.addr_mode) & 0x3);
2012 if (phba->fcf.current_rec.vlan_id != 0xFFFF) {
James Smart04c68492009-05-22 14:52:52 -04002013 bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
James Smartecfd03c2010-02-12 14:41:27 -05002014 bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi,
2015 phba->fcf.current_rec.vlan_id);
James Smart04c68492009-05-22 14:52:52 -04002016 }
2017}
2018
2019/**
2020 * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
2021 * @mbox: pointer to lpfc mbox command to initialize.
2022 * @fcfi: FCFI to be unregistered.
2023 *
2024 * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
2025 * The SLI Host uses the command to inactivate an FCFI.
2026 **/
2027void
2028lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi)
2029{
2030 memset(mbox, 0, sizeof(*mbox));
2031 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI);
2032 bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi);
2033}
2034
2035/**
2036 * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
2037 * @mbox: pointer to lpfc mbox command to initialize.
2038 * @ndlp: The nodelist structure that describes the RPI to resume.
2039 *
2040 * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
2041 * link event.
2042 **/
2043void
2044lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
2045{
2046 struct lpfc_mbx_resume_rpi *resume_rpi;
2047
2048 memset(mbox, 0, sizeof(*mbox));
2049 resume_rpi = &mbox->u.mqe.un.resume_rpi;
2050 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI);
James Smart8fa38512009-07-19 10:01:03 -04002051 bf_set(lpfc_resume_rpi_index, resume_rpi, ndlp->nlp_rpi);
2052 bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI);
2053 resume_rpi->event_tag = ndlp->phba->fc_eventTag;
James Smart04c68492009-05-22 14:52:52 -04002054}
James Smart28baac72010-02-12 14:42:03 -05002055
2056/**
2057 * lpfc_supported_pages - Initialize the PORT_CAPABILITIES supported pages
2058 * mailbox command.
2059 * @mbox: pointer to lpfc mbox command to initialize.
2060 *
2061 * The PORT_CAPABILITIES supported pages mailbox command is issued to
2062 * retrieve the particular feature pages supported by the port.
2063 **/
2064void
2065lpfc_supported_pages(struct lpfcMboxq *mbox)
2066{
2067 struct lpfc_mbx_supp_pages *supp_pages;
2068
2069 memset(mbox, 0, sizeof(*mbox));
2070 supp_pages = &mbox->u.mqe.un.supp_pages;
2071 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES);
2072 bf_set(cpn, supp_pages, LPFC_SUPP_PAGES);
2073}
2074
2075/**
2076 * lpfc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params
2077 * mailbox command.
2078 * @mbox: pointer to lpfc mbox command to initialize.
2079 *
2080 * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to
2081 * retrieve the particular SLI4 features supported by the port.
2082 **/
2083void
2084lpfc_sli4_params(struct lpfcMboxq *mbox)
2085{
2086 struct lpfc_mbx_sli4_params *sli4_params;
2087
2088 memset(mbox, 0, sizeof(*mbox));
2089 sli4_params = &mbox->u.mqe.un.sli4_params;
2090 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES);
2091 bf_set(cpn, sli4_params, LPFC_SLI4_PARAMETERS);
2092}