blob: 6aeb1c668e223d2f034ec204060ddfd58c39332b [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 Smart93996272008-08-24 21:50:30 -04004 * Copyright (C) 2004-2008 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>
28
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040029#include <scsi/scsi.h>
30
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 Smart3621a712009-04-06 18:47:14 -040044 * lpfc_dump_mem - Prepare a mailbox command for retrieving HBA's VPD memory
James Smarte59058c2008-08-24 21:49:00 -040045 * @phba: pointer to lpfc hba data structure.
46 * @pmb: pointer to the driver internal queue element for mailbox command.
47 * @offset: offset for dumping VPD memory mailbox command.
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 HBA Vital Product
53 * Data (VPD) memory. This mailbox command is to be used for retrieving a
54 * portion (DMP_RSP_SIZE bytes) of a HBA's VPD from the HBA at an address
55 * offset specified by the offset parameter.
56 **/
dea31012005-04-17 16:05:31 -050057void
58lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset)
59{
60 MAILBOX_t *mb;
61 void *ctx;
62
James Smart04c68492009-05-22 14:52:52 -040063 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -050064 ctx = pmb->context2;
65
66 /* Setup to dump VPD region */
67 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
68 mb->mbxCommand = MBX_DUMP_MEMORY;
69 mb->un.varDmp.cv = 1;
70 mb->un.varDmp.type = DMP_NV_PARAMS;
71 mb->un.varDmp.entry_index = offset;
72 mb->un.varDmp.region_id = DMP_REGION_VPD;
73 mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
74 mb->un.varDmp.co = 0;
75 mb->un.varDmp.resp_offset = 0;
76 pmb->context2 = ctx;
77 mb->mbxOwner = OWN_HOST;
78 return;
79}
80
James Smarte59058c2008-08-24 21:49:00 -040081/**
James Smart3621a712009-04-06 18:47:14 -040082 * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
James Smart97207482008-12-04 22:39:19 -050083 * @phba: pointer to lpfc hba data structure.
84 * @pmb: pointer to the driver internal queue element for mailbox command.
James Smart3621a712009-04-06 18:47:14 -040085 *
James Smart97207482008-12-04 22:39:19 -050086 * This function create a dump memory mailbox command to dump wake up
87 * parameters.
88 */
89void
90lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
91{
92 MAILBOX_t *mb;
93 void *ctx;
94
James Smart04c68492009-05-22 14:52:52 -040095 mb = &pmb->u.mb;
James Smart97207482008-12-04 22:39:19 -050096 /* Save context so that we can restore after memset */
97 ctx = pmb->context2;
98
99 /* Setup to dump VPD region */
100 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
101 mb->mbxCommand = MBX_DUMP_MEMORY;
102 mb->mbxOwner = OWN_HOST;
103 mb->un.varDmp.cv = 1;
104 mb->un.varDmp.type = DMP_NV_PARAMS;
105 mb->un.varDmp.entry_index = 0;
106 mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
107 mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
108 mb->un.varDmp.co = 0;
109 mb->un.varDmp.resp_offset = 0;
110 pmb->context2 = ctx;
111 return;
112}
113
114/**
James Smart3621a712009-04-06 18:47:14 -0400115 * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
James Smarte59058c2008-08-24 21:49:00 -0400116 * @phba: pointer to lpfc hba data structure.
117 * @pmb: pointer to the driver internal queue element for mailbox command.
118 *
119 * The read NVRAM mailbox command returns the HBA's non-volatile parameters
120 * that are used as defaults when the Fibre Channel link is brought on-line.
121 *
122 * This routine prepares the mailbox command for reading information stored
123 * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
124 **/
dea31012005-04-17 16:05:31 -0500125void
126lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
127{
128 MAILBOX_t *mb;
129
James Smart04c68492009-05-22 14:52:52 -0400130 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500131 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
132 mb->mbxCommand = MBX_READ_NV;
133 mb->mbxOwner = OWN_HOST;
134 return;
135}
136
James Smarte59058c2008-08-24 21:49:00 -0400137/**
James Smart3621a712009-04-06 18:47:14 -0400138 * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
James Smarte59058c2008-08-24 21:49:00 -0400139 * @phba: pointer to lpfc hba data structure.
140 * @pmb: pointer to the driver internal queue element for mailbox command.
141 * @ring: ring number for the asynchronous event to be configured.
142 *
143 * The asynchronous event enable mailbox command is used to enable the
144 * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
145 * specifies the default ring to which events are posted.
146 *
147 * This routine prepares the mailbox command for enabling HBA asynchronous
148 * event support on a IOCB ring.
149 **/
James Smart57127f12007-10-27 13:37:05 -0400150void
151lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
152 uint32_t ring)
153{
154 MAILBOX_t *mb;
155
James Smart04c68492009-05-22 14:52:52 -0400156 mb = &pmb->u.mb;
James Smart57127f12007-10-27 13:37:05 -0400157 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
158 mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
159 mb->un.varCfgAsyncEvent.ring = ring;
160 mb->mbxOwner = OWN_HOST;
161 return;
162}
163
James Smarte59058c2008-08-24 21:49:00 -0400164/**
James Smart3621a712009-04-06 18:47:14 -0400165 * lpfc_heart_beat - Prepare a mailbox command for heart beat
James Smarte59058c2008-08-24 21:49:00 -0400166 * @phba: pointer to lpfc hba data structure.
167 * @pmb: pointer to the driver internal queue element for mailbox command.
168 *
169 * The heart beat mailbox command is used to detect an unresponsive HBA, which
170 * is defined as any device where no error attention is sent and both mailbox
171 * and rings are not processed.
172 *
173 * This routine prepares the mailbox command for issuing a heart beat in the
174 * form of mailbox command to the HBA. The timely completion of the heart
175 * beat mailbox command indicates the health of the HBA.
176 **/
James Smart858c9f62007-06-17 19:56:39 -0500177void
178lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
179{
180 MAILBOX_t *mb;
181
James Smart04c68492009-05-22 14:52:52 -0400182 mb = &pmb->u.mb;
James Smart858c9f62007-06-17 19:56:39 -0500183 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
184 mb->mbxCommand = MBX_HEARTBEAT;
185 mb->mbxOwner = OWN_HOST;
186 return;
187}
188
James Smarte59058c2008-08-24 21:49:00 -0400189/**
James Smart3621a712009-04-06 18:47:14 -0400190 * lpfc_read_la - Prepare a mailbox command for reading HBA link attention
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 * @mp: DMA buffer memory for reading the link attention information into.
194 *
195 * The read link attention mailbox command is issued to read the Link Event
196 * Attention information indicated by the HBA port when the Link Event bit
197 * of the Host Attention (HSTATT) register is set to 1. A Link Event
198 * Attention occurs based on an exception detected at the Fibre Channel link
199 * interface.
200 *
201 * This routine prepares the mailbox command for reading HBA link attention
202 * information. A DMA memory has been set aside and address passed to the
203 * HBA through @mp for the HBA to DMA link attention information into the
204 * memory as part of the execution of the mailbox command.
205 *
206 * Return codes
207 * 0 - Success (currently always return 0)
208 **/
dea31012005-04-17 16:05:31 -0500209int
210lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
211{
212 MAILBOX_t *mb;
213 struct lpfc_sli *psli;
214
215 psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -0400216 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500217 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
218
219 INIT_LIST_HEAD(&mp->list);
220 mb->mbxCommand = MBX_READ_LA64;
221 mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128;
222 mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
223 mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys);
224
225 /* Save address for later completion and set the owner to host so that
226 * the FW knows this mailbox is available for processing.
227 */
228 pmb->context1 = (uint8_t *) mp;
229 mb->mbxOwner = OWN_HOST;
James Smart92d7f7b2007-06-17 19:56:38 -0500230 return (0);
dea31012005-04-17 16:05:31 -0500231}
232
James Smarte59058c2008-08-24 21:49:00 -0400233/**
James Smart3621a712009-04-06 18:47:14 -0400234 * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
James Smarte59058c2008-08-24 21:49:00 -0400235 * @phba: pointer to lpfc hba data structure.
236 * @pmb: pointer to the driver internal queue element for mailbox command.
237 *
238 * The clear link attention mailbox command is issued to clear the link event
239 * attention condition indicated by the Link Event bit of the Host Attention
240 * (HSTATT) register. The link event attention condition is cleared only if
241 * the event tag specified matches that of the current link event counter.
242 * The current event tag is read using the read link attention event mailbox
243 * command.
244 *
245 * This routine prepares the mailbox command for clearing HBA link attention
246 * information.
247 **/
dea31012005-04-17 16:05:31 -0500248void
249lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
250{
251 MAILBOX_t *mb;
252
James Smart04c68492009-05-22 14:52:52 -0400253 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500254 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
255
256 mb->un.varClearLA.eventTag = phba->fc_eventTag;
257 mb->mbxCommand = MBX_CLEAR_LA;
258 mb->mbxOwner = OWN_HOST;
259 return;
260}
261
James Smarte59058c2008-08-24 21:49:00 -0400262/**
James Smart3621a712009-04-06 18:47:14 -0400263 * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
James Smarte59058c2008-08-24 21:49:00 -0400264 * @phba: pointer to lpfc hba data structure.
265 * @pmb: pointer to the driver internal queue element for mailbox command.
266 *
267 * The configure link mailbox command is used before the initialize link
268 * mailbox command to override default value and to configure link-oriented
269 * parameters such as DID address and various timers. Typically, this
270 * command would be used after an F_Port login to set the returned DID address
271 * and the fabric timeout values. This command is not valid before a configure
272 * port command has configured the HBA port.
273 *
274 * This routine prepares the mailbox command for configuring link on a HBA.
275 **/
dea31012005-04-17 16:05:31 -0500276void
277lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
278{
James Smart2e0fef82007-06-17 19:56:36 -0500279 struct lpfc_vport *vport = phba->pport;
James Smart04c68492009-05-22 14:52:52 -0400280 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500281 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
282
283 /* NEW_FEATURE
284 * SLI-2, Coalescing Response Feature.
285 */
286 if (phba->cfg_cr_delay) {
287 mb->un.varCfgLnk.cr = 1;
288 mb->un.varCfgLnk.ci = 1;
289 mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
290 mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
291 }
292
James Smart2e0fef82007-06-17 19:56:36 -0500293 mb->un.varCfgLnk.myId = vport->fc_myDID;
dea31012005-04-17 16:05:31 -0500294 mb->un.varCfgLnk.edtov = phba->fc_edtov;
295 mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
296 mb->un.varCfgLnk.ratov = phba->fc_ratov;
297 mb->un.varCfgLnk.rttov = phba->fc_rttov;
298 mb->un.varCfgLnk.altov = phba->fc_altov;
299 mb->un.varCfgLnk.crtov = phba->fc_crtov;
300 mb->un.varCfgLnk.citov = phba->fc_citov;
301
302 if (phba->cfg_ack0)
303 mb->un.varCfgLnk.ack0_enable = 1;
304
305 mb->mbxCommand = MBX_CONFIG_LINK;
306 mb->mbxOwner = OWN_HOST;
307 return;
308}
309
James Smarte59058c2008-08-24 21:49:00 -0400310/**
James Smart3621a712009-04-06 18:47:14 -0400311 * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
James Smart93996272008-08-24 21:50:30 -0400312 * @phba: pointer to lpfc hba data structure.
313 * @pmb: pointer to the driver internal queue element for mailbox command.
314 *
315 * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
316 * MSI-X multi-message interrupt vector association to interrupt attention
317 * conditions.
318 *
319 * Return codes
320 * 0 - Success
321 * -EINVAL - Failure
322 **/
323int
324lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
325{
James Smart04c68492009-05-22 14:52:52 -0400326 MAILBOX_t *mb = &pmb->u.mb;
James Smart93996272008-08-24 21:50:30 -0400327 uint32_t attentionConditions[2];
328
329 /* Sanity check */
330 if (phba->cfg_use_msi != 2) {
331 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
332 "0475 Not configured for supporting MSI-X "
333 "cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
334 return -EINVAL;
335 }
336
337 if (phba->sli_rev < 3) {
338 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
339 "0476 HBA not supporting SLI-3 or later "
340 "SLI Revision: 0x%x\n", phba->sli_rev);
341 return -EINVAL;
342 }
343
344 /* Clear mailbox command fields */
345 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
346
347 /*
348 * SLI-3, Message Signaled Interrupt Fearure.
349 */
350
351 /* Multi-message attention configuration */
352 attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
353 HA_LATT | HA_MBATT);
354 attentionConditions[1] = 0;
355
356 mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
357 mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
358
359 /*
360 * Set up message number to HA bit association
361 */
362#ifdef __BIG_ENDIAN_BITFIELD
363 /* RA0 (FCP Ring) */
364 mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
365 /* RA1 (Other Protocol Extra Ring) */
366 mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
367#else /* __LITTLE_ENDIAN_BITFIELD */
368 /* RA0 (FCP Ring) */
369 mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
370 /* RA1 (Other Protocol Extra Ring) */
371 mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
372#endif
373 /* Multi-message interrupt autoclear configuration*/
374 mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
375 mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
376
377 /* For now, HBA autoclear does not work reliably, disable it */
378 mb->un.varCfgMSI.autoClearHA[0] = 0;
379 mb->un.varCfgMSI.autoClearHA[1] = 0;
380
381 /* Set command and owner bit */
382 mb->mbxCommand = MBX_CONFIG_MSI;
383 mb->mbxOwner = OWN_HOST;
384
385 return 0;
386}
387
388/**
James Smart3621a712009-04-06 18:47:14 -0400389 * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
James Smarte59058c2008-08-24 21:49:00 -0400390 * @phba: pointer to lpfc hba data structure.
391 * @pmb: pointer to the driver internal queue element for mailbox command.
392 * @topology: the link topology for the link to be initialized to.
393 * @linkspeed: the link speed for the link to be initialized to.
394 *
395 * The initialize link mailbox command is used to initialize the Fibre
396 * Channel link. This command must follow a configure port command that
397 * establishes the mode of operation.
398 *
399 * This routine prepares the mailbox command for initializing link on a HBA
400 * with the specified link topology and speed.
401 **/
dea31012005-04-17 16:05:31 -0500402void
403lpfc_init_link(struct lpfc_hba * phba,
404 LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
405{
406 lpfc_vpd_t *vpd;
407 struct lpfc_sli *psli;
408 MAILBOX_t *mb;
409
James Smart04c68492009-05-22 14:52:52 -0400410 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500411 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
412
413 psli = &phba->sli;
414 switch (topology) {
415 case FLAGS_TOPOLOGY_MODE_LOOP_PT:
416 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
417 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
418 break;
419 case FLAGS_TOPOLOGY_MODE_PT_PT:
420 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
421 break;
422 case FLAGS_TOPOLOGY_MODE_LOOP:
423 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
424 break;
425 case FLAGS_TOPOLOGY_MODE_PT_LOOP:
426 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
427 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
428 break;
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500429 case FLAGS_LOCAL_LB:
430 mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
431 break;
dea31012005-04-17 16:05:31 -0500432 }
433
James Smart4b0b91d2006-04-15 11:53:00 -0400434 /* Enable asynchronous ABTS responses from firmware */
435 mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
436
dea31012005-04-17 16:05:31 -0500437 /* NEW_FEATURE
438 * Setting up the link speed
439 */
440 vpd = &phba->vpd;
441 if (vpd->rev.feaLevelHigh >= 0x02){
James Smart92d7f7b2007-06-17 19:56:38 -0500442 switch(linkspeed){
dea31012005-04-17 16:05:31 -0500443 case LINK_SPEED_1G:
444 case LINK_SPEED_2G:
445 case LINK_SPEED_4G:
James Smartb87eab32007-04-25 09:53:28 -0400446 case LINK_SPEED_8G:
dea31012005-04-17 16:05:31 -0500447 mb->un.varInitLnk.link_flags |=
448 FLAGS_LINK_SPEED;
449 mb->un.varInitLnk.link_speed = linkspeed;
450 break;
451 case LINK_SPEED_AUTO:
452 default:
453 mb->un.varInitLnk.link_speed =
454 LINK_SPEED_AUTO;
455 break;
456 }
457
458 }
459 else
460 mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
461
462 mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
463 mb->mbxOwner = OWN_HOST;
464 mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
465 return;
466}
467
James Smarte59058c2008-08-24 21:49:00 -0400468/**
James Smart3621a712009-04-06 18:47:14 -0400469 * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
James Smarte59058c2008-08-24 21:49:00 -0400470 * @phba: pointer to lpfc hba data structure.
471 * @pmb: pointer to the driver internal queue element for mailbox command.
472 * @vpi: virtual N_Port identifier.
473 *
474 * The read service parameter mailbox command is used to read the HBA port
475 * service parameters. The service parameters are read into the buffer
476 * specified directly by a BDE in the mailbox command. These service
477 * parameters may then be used to build the payload of an N_Port/F_POrt
478 * login request and reply (LOGI/ACC).
479 *
480 * This routine prepares the mailbox command for reading HBA port service
481 * parameters. The DMA memory is allocated in this function and the addresses
482 * are populated into the mailbox command for the HBA to DMA the service
483 * parameters into.
484 *
485 * Return codes
486 * 0 - Success
487 * 1 - DMA memory allocation failed
488 **/
dea31012005-04-17 16:05:31 -0500489int
James Smart92d7f7b2007-06-17 19:56:38 -0500490lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
dea31012005-04-17 16:05:31 -0500491{
492 struct lpfc_dmabuf *mp;
493 MAILBOX_t *mb;
494 struct lpfc_sli *psli;
495
496 psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -0400497 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500498 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
499
500 mb->mbxOwner = OWN_HOST;
501
502 /* Get a buffer to hold the HBAs Service Parameters */
503
James Smart98c9ea52007-10-27 13:37:33 -0400504 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
505 if (mp)
506 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
507 if (!mp || !mp->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800508 kfree(mp);
dea31012005-04-17 16:05:31 -0500509 mb->mbxCommand = MBX_READ_SPARM64;
510 /* READ_SPARAM: no buffers */
James Smarte8b62012007-08-02 11:10:09 -0400511 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
512 "0301 READ_SPARAM: no buffers\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500513 return (1);
dea31012005-04-17 16:05:31 -0500514 }
515 INIT_LIST_HEAD(&mp->list);
516 mb->mbxCommand = MBX_READ_SPARM64;
517 mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
518 mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
519 mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
James Smart04c68492009-05-22 14:52:52 -0400520 mb->un.varRdSparm.vpi = vpi + phba->vpi_base;
dea31012005-04-17 16:05:31 -0500521
522 /* save address for completion */
523 pmb->context1 = mp;
524
James Smart92d7f7b2007-06-17 19:56:38 -0500525 return (0);
dea31012005-04-17 16:05:31 -0500526}
527
James Smarte59058c2008-08-24 21:49:00 -0400528/**
James Smart3621a712009-04-06 18:47:14 -0400529 * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
James Smarte59058c2008-08-24 21:49:00 -0400530 * @phba: pointer to lpfc hba data structure.
531 * @vpi: virtual N_Port identifier.
532 * @did: remote port identifier.
533 * @pmb: pointer to the driver internal queue element for mailbox command.
534 *
535 * The unregister DID mailbox command is used to unregister an N_Port/F_Port
536 * login for an unknown RPI by specifying the DID of a remote port. This
537 * command frees an RPI context in the HBA port. This has the effect of
538 * performing an implicit N_Port/F_Port logout.
539 *
540 * This routine prepares the mailbox command for unregistering a remote
541 * N_Port/F_Port (DID) login.
542 **/
dea31012005-04-17 16:05:31 -0500543void
James Smart92d7f7b2007-06-17 19:56:38 -0500544lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
545 LPFC_MBOXQ_t * pmb)
dea31012005-04-17 16:05:31 -0500546{
547 MAILBOX_t *mb;
548
James Smart04c68492009-05-22 14:52:52 -0400549 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500550 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
551
552 mb->un.varUnregDID.did = did;
James Smart04c68492009-05-22 14:52:52 -0400553 if (vpi != 0xffff)
554 vpi += phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500555 mb->un.varUnregDID.vpi = vpi;
dea31012005-04-17 16:05:31 -0500556
557 mb->mbxCommand = MBX_UNREG_D_ID;
558 mb->mbxOwner = OWN_HOST;
559 return;
560}
561
James Smarte59058c2008-08-24 21:49:00 -0400562/**
James Smart3621a712009-04-06 18:47:14 -0400563 * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
James Smarte59058c2008-08-24 21:49:00 -0400564 * @phba: pointer to lpfc hba data structure.
565 * @pmb: pointer to the driver internal queue element for mailbox command.
566 *
567 * The read configuration mailbox command is used to read the HBA port
568 * configuration parameters. This mailbox command provides a method for
569 * seeing any parameters that may have changed via various configuration
570 * mailbox commands.
571 *
572 * This routine prepares the mailbox command for reading out HBA configuration
573 * parameters.
574 **/
dea31012005-04-17 16:05:31 -0500575void
576lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
577{
578 MAILBOX_t *mb;
579
James Smart04c68492009-05-22 14:52:52 -0400580 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500581 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
582
583 mb->mbxCommand = MBX_READ_CONFIG;
584 mb->mbxOwner = OWN_HOST;
585 return;
586}
587
James Smarte59058c2008-08-24 21:49:00 -0400588/**
James Smart3621a712009-04-06 18:47:14 -0400589 * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
James Smarte59058c2008-08-24 21:49:00 -0400590 * @phba: pointer to lpfc hba data structure.
591 * @pmb: pointer to the driver internal queue element for mailbox command.
592 *
593 * The read link status mailbox command is used to read the link status from
594 * the HBA. Link status includes all link-related error counters. These
595 * counters are maintained by the HBA and originated in the link hardware
596 * unit. Note that all of these counters wrap.
597 *
598 * This routine prepares the mailbox command for reading out HBA link status.
599 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -0500600void
601lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
602{
603 MAILBOX_t *mb;
604
James Smart04c68492009-05-22 14:52:52 -0400605 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -0500606 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
607
608 mb->mbxCommand = MBX_READ_LNK_STAT;
609 mb->mbxOwner = OWN_HOST;
610 return;
611}
612
James Smarte59058c2008-08-24 21:49:00 -0400613/**
James Smart04c68492009-05-22 14:52:52 -0400614 * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
James Smarte59058c2008-08-24 21:49:00 -0400615 * @phba: pointer to lpfc hba data structure.
616 * @vpi: virtual N_Port identifier.
617 * @did: remote port identifier.
618 * @param: pointer to memory holding the server parameters.
619 * @pmb: pointer to the driver internal queue element for mailbox command.
620 * @flag: action flag to be passed back for the complete function.
621 *
622 * The registration login mailbox command is used to register an N_Port or
623 * F_Port login. This registration allows the HBA to cache the remote N_Port
624 * service parameters internally and thereby make the appropriate FC-2
625 * decisions. The remote port service parameters are handed off by the driver
626 * to the HBA using a descriptor entry that directly identifies a buffer in
627 * host memory. In exchange, the HBA returns an RPI identifier.
628 *
629 * This routine prepares the mailbox command for registering remote port login.
630 * The function allocates DMA buffer for passing the service parameters to the
631 * HBA with the mailbox command.
632 *
633 * Return codes
634 * 0 - Success
635 * 1 - DMA memory allocation failed
636 **/
dea31012005-04-17 16:05:31 -0500637int
James Smart04c68492009-05-22 14:52:52 -0400638lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
James Smart92d7f7b2007-06-17 19:56:38 -0500639 uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
dea31012005-04-17 16:05:31 -0500640{
James Smart04c68492009-05-22 14:52:52 -0400641 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500642 uint8_t *sparam;
643 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -0500644
dea31012005-04-17 16:05:31 -0500645 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
646
647 mb->un.varRegLogin.rpi = 0;
James Smart04c68492009-05-22 14:52:52 -0400648 if (phba->sli_rev == LPFC_SLI_REV4) {
649 mb->un.varRegLogin.rpi = lpfc_sli4_alloc_rpi(phba);
650 if (mb->un.varRegLogin.rpi == LPFC_RPI_ALLOC_ERROR)
651 return 1;
652 }
653
654 mb->un.varRegLogin.vpi = vpi + phba->vpi_base;
dea31012005-04-17 16:05:31 -0500655 mb->un.varRegLogin.did = did;
656 mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */
657
658 mb->mbxOwner = OWN_HOST;
659
660 /* Get a buffer to hold NPorts Service Parameters */
James Smart98c9ea52007-10-27 13:37:33 -0400661 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
662 if (mp)
663 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
664 if (!mp || !mp->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800665 kfree(mp);
dea31012005-04-17 16:05:31 -0500666 mb->mbxCommand = MBX_REG_LOGIN64;
667 /* REG_LOGIN: no buffers */
James Smart92d7f7b2007-06-17 19:56:38 -0500668 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400669 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
670 "flag x%x\n", vpi, did, flag);
James Smart92d7f7b2007-06-17 19:56:38 -0500671 return (1);
dea31012005-04-17 16:05:31 -0500672 }
673 INIT_LIST_HEAD(&mp->list);
674 sparam = mp->virt;
675
676 /* Copy param's into a new buffer */
677 memcpy(sparam, param, sizeof (struct serv_parm));
678
679 /* save address for completion */
680 pmb->context1 = (uint8_t *) mp;
681
682 mb->mbxCommand = MBX_REG_LOGIN64;
683 mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
684 mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
685 mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
686
James Smart92d7f7b2007-06-17 19:56:38 -0500687 return (0);
dea31012005-04-17 16:05:31 -0500688}
689
James Smarte59058c2008-08-24 21:49:00 -0400690/**
James Smart3621a712009-04-06 18:47:14 -0400691 * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
James Smarte59058c2008-08-24 21:49:00 -0400692 * @phba: pointer to lpfc hba data structure.
693 * @vpi: virtual N_Port identifier.
694 * @rpi: remote port identifier
695 * @pmb: pointer to the driver internal queue element for mailbox command.
696 *
697 * The unregistration login mailbox command is used to unregister an N_Port
698 * or F_Port login. This command frees an RPI context in the HBA. It has the
699 * effect of performing an implicit N_Port/F_Port logout.
700 *
701 * This routine prepares the mailbox command for unregistering remote port
702 * login.
703 **/
dea31012005-04-17 16:05:31 -0500704void
James Smart92d7f7b2007-06-17 19:56:38 -0500705lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
706 LPFC_MBOXQ_t * pmb)
dea31012005-04-17 16:05:31 -0500707{
708 MAILBOX_t *mb;
709
James Smart04c68492009-05-22 14:52:52 -0400710 mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500711 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
712
713 mb->un.varUnregLogin.rpi = (uint16_t) rpi;
714 mb->un.varUnregLogin.rsvd1 = 0;
James Smart04c68492009-05-22 14:52:52 -0400715 mb->un.varUnregLogin.vpi = vpi + phba->vpi_base;
dea31012005-04-17 16:05:31 -0500716
717 mb->mbxCommand = MBX_UNREG_LOGIN;
718 mb->mbxOwner = OWN_HOST;
James Smart04c68492009-05-22 14:52:52 -0400719
dea31012005-04-17 16:05:31 -0500720 return;
721}
722
James Smarte59058c2008-08-24 21:49:00 -0400723/**
James Smart3621a712009-04-06 18:47:14 -0400724 * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
James Smarte59058c2008-08-24 21:49:00 -0400725 * @phba: pointer to lpfc hba data structure.
726 * @vpi: virtual N_Port identifier.
727 * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
728 * @pmb: pointer to the driver internal queue element for mailbox command.
729 *
730 * The registration vport identifier mailbox command is used to activate a
731 * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
732 * N_Port_ID against the information in the selected virtual N_Port context
733 * block and marks it active to allow normal processing of IOCB commands and
734 * received unsolicited exchanges.
735 *
736 * This routine prepares the mailbox command for registering a virtual N_Port.
737 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500738void
James Smart04c68492009-05-22 14:52:52 -0400739lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
James Smart92d7f7b2007-06-17 19:56:38 -0500740{
James Smart04c68492009-05-22 14:52:52 -0400741 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500742
743 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
744
James Smart04c68492009-05-22 14:52:52 -0400745 mb->un.varRegVpi.vpi = vport->vpi + vport->phba->vpi_base;
746 mb->un.varRegVpi.sid = vport->fc_myDID;
747 mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500748
749 mb->mbxCommand = MBX_REG_VPI;
750 mb->mbxOwner = OWN_HOST;
751 return;
752
753}
754
James Smarte59058c2008-08-24 21:49:00 -0400755/**
James Smart3621a712009-04-06 18:47:14 -0400756 * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
James Smarte59058c2008-08-24 21:49:00 -0400757 * @phba: pointer to lpfc hba data structure.
758 * @vpi: virtual N_Port identifier.
759 * @pmb: pointer to the driver internal queue element for mailbox command.
760 *
761 * The unregistration vport identifier mailbox command is used to inactivate
762 * a virtual N_Port. The driver must have logged out and unregistered all
763 * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
764 * unregisters any default RPIs associated with the specified vpi, aborting
765 * any active exchanges. The HBA will post the mailbox response after making
766 * the virtual N_Port inactive.
767 *
768 * This routine prepares the mailbox command for unregistering a virtual
769 * N_Port.
770 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500771void
772lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
773{
James Smart04c68492009-05-22 14:52:52 -0400774 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -0500775 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
776
James Smart04c68492009-05-22 14:52:52 -0400777 mb->un.varUnregVpi.vpi = vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500778
779 mb->mbxCommand = MBX_UNREG_VPI;
780 mb->mbxOwner = OWN_HOST;
781 return;
782
783}
784
James Smarte59058c2008-08-24 21:49:00 -0400785/**
James Smart3621a712009-04-06 18:47:14 -0400786 * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
James Smarte59058c2008-08-24 21:49:00 -0400787 * @phba: pointer to lpfc hba data structure.
788 *
789 * This routine sets up and initializes the IOCB rings in the Port Control
790 * Block (PCB).
791 **/
dea31012005-04-17 16:05:31 -0500792static void
793lpfc_config_pcb_setup(struct lpfc_hba * phba)
794{
795 struct lpfc_sli *psli = &phba->sli;
796 struct lpfc_sli_ring *pring;
James Smart34b02dc2008-08-24 21:49:55 -0400797 PCB_t *pcbp = phba->pcb;
dea31012005-04-17 16:05:31 -0500798 dma_addr_t pdma_addr;
799 uint32_t offset;
James Smart2e0fef82007-06-17 19:56:36 -0500800 uint32_t iocbCnt = 0;
dea31012005-04-17 16:05:31 -0500801 int i;
802
dea31012005-04-17 16:05:31 -0500803 pcbp->maxRing = (psli->num_rings - 1);
804
dea31012005-04-17 16:05:31 -0500805 for (i = 0; i < psli->num_rings; i++) {
806 pring = &psli->ring[i];
James Smart2e0fef82007-06-17 19:56:36 -0500807
James Smarted957682007-06-17 19:56:37 -0500808 pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
James Smart92d7f7b2007-06-17 19:56:38 -0500809 SLI2_IOCB_CMD_SIZE;
James Smarted957682007-06-17 19:56:37 -0500810 pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
James Smart92d7f7b2007-06-17 19:56:38 -0500811 SLI2_IOCB_RSP_SIZE;
dea31012005-04-17 16:05:31 -0500812 /* A ring MUST have both cmd and rsp entries defined to be
813 valid */
814 if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
815 pcbp->rdsc[i].cmdEntries = 0;
816 pcbp->rdsc[i].rspEntries = 0;
817 pcbp->rdsc[i].cmdAddrHigh = 0;
818 pcbp->rdsc[i].rspAddrHigh = 0;
819 pcbp->rdsc[i].cmdAddrLow = 0;
820 pcbp->rdsc[i].rspAddrLow = 0;
821 pring->cmdringaddr = NULL;
822 pring->rspringaddr = NULL;
823 continue;
824 }
825 /* Command ring setup for ring */
James Smart34b02dc2008-08-24 21:49:55 -0400826 pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
dea31012005-04-17 16:05:31 -0500827 pcbp->rdsc[i].cmdEntries = pring->numCiocb;
828
James Smart34b02dc2008-08-24 21:49:55 -0400829 offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
830 (uint8_t *) phba->slim2p.virt;
831 pdma_addr = phba->slim2p.phys + offset;
dea31012005-04-17 16:05:31 -0500832 pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
833 pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
834 iocbCnt += pring->numCiocb;
835
836 /* Response ring setup for ring */
James Smart34b02dc2008-08-24 21:49:55 -0400837 pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt];
dea31012005-04-17 16:05:31 -0500838
839 pcbp->rdsc[i].rspEntries = pring->numRiocb;
James Smart34b02dc2008-08-24 21:49:55 -0400840 offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
841 (uint8_t *)phba->slim2p.virt;
842 pdma_addr = phba->slim2p.phys + offset;
dea31012005-04-17 16:05:31 -0500843 pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
844 pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
845 iocbCnt += pring->numRiocb;
846 }
847}
848
James Smarte59058c2008-08-24 21:49:00 -0400849/**
James Smart3621a712009-04-06 18:47:14 -0400850 * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
James Smarte59058c2008-08-24 21:49:00 -0400851 * @phba: pointer to lpfc hba data structure.
852 * @pmb: pointer to the driver internal queue element for mailbox command.
853 *
854 * The read revision mailbox command is used to read the revision levels of
855 * the HBA components. These components include hardware units, resident
856 * firmware, and available firmware. HBAs that supports SLI-3 mode of
857 * operation provide different response information depending on the version
858 * requested by the driver.
859 *
860 * This routine prepares the mailbox command for reading HBA revision
861 * information.
862 **/
dea31012005-04-17 16:05:31 -0500863void
864lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
865{
James Smart04c68492009-05-22 14:52:52 -0400866 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500867 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
868 mb->un.varRdRev.cv = 1;
James Smarted957682007-06-17 19:56:37 -0500869 mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
dea31012005-04-17 16:05:31 -0500870 mb->mbxCommand = MBX_READ_REV;
871 mb->mbxOwner = OWN_HOST;
872 return;
873}
874
James Smarte59058c2008-08-24 21:49:00 -0400875/**
James Smart3621a712009-04-06 18:47:14 -0400876 * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
James Smarte59058c2008-08-24 21:49:00 -0400877 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
878 * @hbq_desc: pointer to the HBQ selection profile descriptor.
879 *
880 * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
881 * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
882 * the Sequence Length Test using the fields in the Selection Profile 2
883 * extension in words 20:31.
884 **/
James Smarted957682007-06-17 19:56:37 -0500885static void
886lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
887 struct lpfc_hbq_init *hbq_desc)
888{
889 hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
890 hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
891 hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
892}
893
James Smarte59058c2008-08-24 21:49:00 -0400894/**
James Smart3621a712009-04-06 18:47:14 -0400895 * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
James Smarte59058c2008-08-24 21:49:00 -0400896 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
897 * @hbq_desc: pointer to the HBQ selection profile descriptor.
898 *
899 * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
900 * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
901 * the Sequence Length Test and Byte Field Test using the fields in the
902 * Selection Profile 3 extension in words 20:31.
903 **/
James Smarted957682007-06-17 19:56:37 -0500904static void
905lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
906 struct lpfc_hbq_init *hbq_desc)
907{
908 hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
909 hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
910 hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
911 hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
912 memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
913 sizeof(hbqmb->profiles.profile3.cmdmatch));
914}
915
James Smarte59058c2008-08-24 21:49:00 -0400916/**
James Smart3621a712009-04-06 18:47:14 -0400917 * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
James Smarte59058c2008-08-24 21:49:00 -0400918 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
919 * @hbq_desc: pointer to the HBQ selection profile descriptor.
920 *
921 * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
922 * HBA tests the initial frame of an incoming sequence using the frame's
923 * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
924 * and Byte Field Test using the fields in the Selection Profile 5 extension
925 * words 20:31.
926 **/
James Smarted957682007-06-17 19:56:37 -0500927static void
928lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
929 struct lpfc_hbq_init *hbq_desc)
930{
931 hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
932 hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
933 hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
934 hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
935 memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
936 sizeof(hbqmb->profiles.profile5.cmdmatch));
937}
938
James Smarte59058c2008-08-24 21:49:00 -0400939/**
James Smart3621a712009-04-06 18:47:14 -0400940 * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
James Smarte59058c2008-08-24 21:49:00 -0400941 * @phba: pointer to lpfc hba data structure.
942 * @id: HBQ identifier.
943 * @hbq_desc: pointer to the HBA descriptor data structure.
944 * @hbq_entry_index: index of the HBQ entry data structures.
945 * @pmb: pointer to the driver internal queue element for mailbox command.
946 *
947 * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
948 * an HBQ. The configuration binds events that require buffers to a particular
949 * ring and HBQ based on a selection profile.
950 *
951 * This routine prepares the mailbox command for configuring an HBQ.
952 **/
James Smarted957682007-06-17 19:56:37 -0500953void
James Smart51ef4c22007-08-02 11:10:31 -0400954lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
955 struct lpfc_hbq_init *hbq_desc,
James Smarted957682007-06-17 19:56:37 -0500956 uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
957{
958 int i;
James Smart04c68492009-05-22 14:52:52 -0400959 MAILBOX_t *mb = &pmb->u.mb;
James Smarted957682007-06-17 19:56:37 -0500960 struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
961
962 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
James Smart51ef4c22007-08-02 11:10:31 -0400963 hbqmb->hbqId = id;
James Smarted957682007-06-17 19:56:37 -0500964 hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
965 hbqmb->recvNotify = hbq_desc->rn; /* Receive
966 * Notification */
967 hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
968 * # in words 0-19 */
James Smart92d7f7b2007-06-17 19:56:38 -0500969 hbqmb->profile = hbq_desc->profile; /* Selection profile:
James Smarted957682007-06-17 19:56:37 -0500970 * 0 = all,
971 * 7 = logentry */
972 hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
973 * e.g. Ring0=b0001,
974 * ring2=b0100 */
975 hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
976 * or 5 */
977 hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
978 * HBQ will be used
979 * for LogEntry
980 * buffers */
981 hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
982 hbq_entry_index * sizeof(struct lpfc_hbq_entry);
983 hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
984
985 mb->mbxCommand = MBX_CONFIG_HBQ;
986 mb->mbxOwner = OWN_HOST;
987
James Smart92d7f7b2007-06-17 19:56:38 -0500988 /* Copy info for profiles 2,3,5. Other
989 * profiles this area is reserved
990 */
James Smarted957682007-06-17 19:56:37 -0500991 if (hbq_desc->profile == 2)
992 lpfc_build_hbq_profile2(hbqmb, hbq_desc);
993 else if (hbq_desc->profile == 3)
994 lpfc_build_hbq_profile3(hbqmb, hbq_desc);
995 else if (hbq_desc->profile == 5)
996 lpfc_build_hbq_profile5(hbqmb, hbq_desc);
997
998 /* Return if no rctl / type masks for this HBQ */
999 if (!hbq_desc->mask_count)
1000 return;
1001
1002 /* Otherwise we setup specific rctl / type masks for this HBQ */
1003 for (i = 0; i < hbq_desc->mask_count; i++) {
1004 hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
1005 hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
1006 hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
1007 hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
1008 }
1009
1010 return;
1011}
1012
James Smarte59058c2008-08-24 21:49:00 -04001013/**
James Smart3621a712009-04-06 18:47:14 -04001014 * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04001015 * @phba: pointer to lpfc hba data structure.
1016 * @ring:
1017 * @pmb: pointer to the driver internal queue element for mailbox command.
1018 *
1019 * The configure ring mailbox command is used to configure an IOCB ring. This
1020 * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1021 * ring. This is used to map incoming sequences to a particular ring whose
1022 * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1023 * attempt to configure a ring whose number is greater than the number
1024 * specified in the Port Control Block (PCB). It is an error to issue the
1025 * configure ring command more than once with the same ring number. The HBA
1026 * returns an error if the driver attempts this.
1027 *
1028 * This routine prepares the mailbox command for configuring IOCB ring.
1029 **/
dea31012005-04-17 16:05:31 -05001030void
1031lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
1032{
1033 int i;
James Smart04c68492009-05-22 14:52:52 -04001034 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001035 struct lpfc_sli *psli;
1036 struct lpfc_sli_ring *pring;
1037
1038 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1039
1040 mb->un.varCfgRing.ring = ring;
1041 mb->un.varCfgRing.maxOrigXchg = 0;
1042 mb->un.varCfgRing.maxRespXchg = 0;
1043 mb->un.varCfgRing.recvNotify = 1;
1044
1045 psli = &phba->sli;
1046 pring = &psli->ring[ring];
1047 mb->un.varCfgRing.numMask = pring->num_mask;
1048 mb->mbxCommand = MBX_CONFIG_RING;
1049 mb->mbxOwner = OWN_HOST;
1050
1051 /* Is this ring configured for a specific profile */
1052 if (pring->prt[0].profile) {
1053 mb->un.varCfgRing.profile = pring->prt[0].profile;
1054 return;
1055 }
1056
1057 /* Otherwise we setup specific rctl / type masks for this ring */
1058 for (i = 0; i < pring->num_mask; i++) {
1059 mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
1060 if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ)
1061 mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
1062 else
1063 mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
1064 mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
1065 mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
1066 }
1067
1068 return;
1069}
1070
James Smarte59058c2008-08-24 21:49:00 -04001071/**
James Smart3621a712009-04-06 18:47:14 -04001072 * lpfc_config_port - Prepare a mailbox command for configuring port
James Smarte59058c2008-08-24 21:49:00 -04001073 * @phba: pointer to lpfc hba data structure.
1074 * @pmb: pointer to the driver internal queue element for mailbox command.
1075 *
1076 * The configure port mailbox command is used to identify the Port Control
1077 * Block (PCB) in the driver memory. After this command is issued, the
1078 * driver must not access the mailbox in the HBA without first resetting
1079 * the HBA. The HBA may copy the PCB information to internal storage for
1080 * subsequent use; the driver can not change the PCB information unless it
1081 * resets the HBA.
1082 *
1083 * This routine prepares the mailbox command for configuring port.
1084 **/
dea31012005-04-17 16:05:31 -05001085void
James Smart92d7f7b2007-06-17 19:56:38 -05001086lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001087{
James Smarted957682007-06-17 19:56:37 -05001088 MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
James Smart04c68492009-05-22 14:52:52 -04001089 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001090 dma_addr_t pdma_addr;
1091 uint32_t bar_low, bar_high;
1092 size_t offset;
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04001093 struct lpfc_hgp hgp;
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001094 int i;
James Smarted957682007-06-17 19:56:37 -05001095 uint32_t pgp_offset;
dea31012005-04-17 16:05:31 -05001096
1097 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1098 mb->mbxCommand = MBX_CONFIG_PORT;
1099 mb->mbxOwner = OWN_HOST;
1100
1101 mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
1102
James Smart34b02dc2008-08-24 21:49:55 -04001103 offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
1104 pdma_addr = phba->slim2p.phys + offset;
dea31012005-04-17 16:05:31 -05001105 mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
1106 mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
1107
James Smart97207482008-12-04 22:39:19 -05001108 /* Always Host Group Pointer is in SLIM */
1109 mb->un.varCfgPort.hps = 1;
1110
James Smarted957682007-06-17 19:56:37 -05001111 /* If HBA supports SLI=3 ask for it */
1112
James Smart04c68492009-05-22 14:52:52 -04001113 if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
James Smarte2a0a9d2008-12-04 22:40:02 -05001114 if (phba->cfg_enable_bg)
1115 mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
James Smart04c68492009-05-22 14:52:52 -04001116 mb->un.varCfgPort.cdss = 1; /* Configure Security */
James Smarted957682007-06-17 19:56:37 -05001117 mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
James Smart34b02dc2008-08-24 21:49:55 -04001118 mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
1119 mb->un.varCfgPort.cinb = 1; /* Interrupt Notification Block */
James Smart51ef4c22007-08-02 11:10:31 -04001120 mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
James Smart78b2d852007-08-02 11:10:21 -04001121 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smart92d7f7b2007-06-17 19:56:38 -05001122 phba->vpd.sli3Feat.cmv) {
James Smart04c68492009-05-22 14:52:52 -04001123 mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI;
James Smart92d7f7b2007-06-17 19:56:38 -05001124 mb->un.varCfgPort.cmv = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001125 } else
1126 mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
1127 } else
James Smart04c68492009-05-22 14:52:52 -04001128 phba->sli_rev = LPFC_SLI_REV2;
James Smart92d7f7b2007-06-17 19:56:38 -05001129 mb->un.varCfgPort.sli_mode = phba->sli_rev;
James Smarted957682007-06-17 19:56:37 -05001130
dea31012005-04-17 16:05:31 -05001131 /* Now setup pcb */
James Smart34b02dc2008-08-24 21:49:55 -04001132 phba->pcb->type = TYPE_NATIVE_SLI2;
1133 phba->pcb->feature = FEATURE_INITIAL_SLI2;
dea31012005-04-17 16:05:31 -05001134
1135 /* Setup Mailbox pointers */
James Smart34b02dc2008-08-24 21:49:55 -04001136 phba->pcb->mailBoxSize = sizeof(MAILBOX_t);
1137 offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
1138 pdma_addr = phba->slim2p.phys + offset;
1139 phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
1140 phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
dea31012005-04-17 16:05:31 -05001141
1142 /*
1143 * Setup Host Group ring pointer.
1144 *
1145 * For efficiency reasons, the ring get/put pointers can be
1146 * placed in adapter memory (SLIM) rather than in host memory.
1147 * This allows firmware to avoid PCI reads/writes when updating
1148 * and checking pointers.
1149 *
1150 * The firmware recognizes the use of SLIM memory by comparing
1151 * the address of the get/put pointers structure with that of
1152 * the SLIM BAR (BAR0).
1153 *
1154 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1155 * (the hardware's view of the base address), not the OS's
1156 * value of pci_resource_start() as the OS value may be a cookie
1157 * for ioremap/iomap.
1158 */
1159
1160
1161 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
1162 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
1163
James Smarted957682007-06-17 19:56:37 -05001164 /*
1165 * Set up HGP - Port Memory
1166 *
1167 * The port expects the host get/put pointers to reside in memory
1168 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1169 * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
1170 * words (0x40 bytes). This area is not reserved if HBQs are
1171 * configured in SLI-3.
1172 *
1173 * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1174 * RR0Get 0xc4 0x84
1175 * CR1Put 0xc8 0x88
1176 * RR1Get 0xcc 0x8c
1177 * CR2Put 0xd0 0x90
1178 * RR2Get 0xd4 0x94
1179 * CR3Put 0xd8 0x98
1180 * RR3Get 0xdc 0x9c
1181 *
1182 * Reserved 0xa0-0xbf
1183 * If HBQs configured:
1184 * HBQ 0 Put ptr 0xc0
1185 * HBQ 1 Put ptr 0xc4
1186 * HBQ 2 Put ptr 0xc8
1187 * ......
1188 * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1189 *
1190 */
1191
1192 if (phba->sli_rev == 3) {
1193 phba->host_gp = &mb_slim->us.s3.host[0];
1194 phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
1195 } else {
1196 phba->host_gp = &mb_slim->us.s2.host[0];
1197 phba->hbq_put = NULL;
1198 }
dea31012005-04-17 16:05:31 -05001199
1200 /* mask off BAR0's flag bits 0 - 3 */
James Smart34b02dc2008-08-24 21:49:55 -04001201 phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
1202 (void __iomem *)phba->host_gp -
James Smarted957682007-06-17 19:56:37 -05001203 (void __iomem *)phba->MBslimaddr;
dea31012005-04-17 16:05:31 -05001204 if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
James Smart34b02dc2008-08-24 21:49:55 -04001205 phba->pcb->hgpAddrHigh = bar_high;
dea31012005-04-17 16:05:31 -05001206 else
James Smart34b02dc2008-08-24 21:49:55 -04001207 phba->pcb->hgpAddrHigh = 0;
dea31012005-04-17 16:05:31 -05001208 /* write HGP data to SLIM at the required longword offset */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04001209 memset(&hgp, 0, sizeof(struct lpfc_hgp));
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001210
1211 for (i=0; i < phba->sli.num_rings; i++) {
James Smarted957682007-06-17 19:56:37 -05001212 lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
1213 sizeof(*phba->host_gp));
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001214 }
dea31012005-04-17 16:05:31 -05001215
James Smart8f34f4c2008-12-04 22:39:23 -05001216 /* Setup Port Group offset */
1217 if (phba->sli_rev == 3)
James Smart34b02dc2008-08-24 21:49:55 -04001218 pgp_offset = offsetof(struct lpfc_sli2_slim,
1219 mbx.us.s3_pgp.port);
James Smart8f34f4c2008-12-04 22:39:23 -05001220 else
James Smart34b02dc2008-08-24 21:49:55 -04001221 pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
1222 pdma_addr = phba->slim2p.phys + pgp_offset;
1223 phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
1224 phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
dea31012005-04-17 16:05:31 -05001225
1226 /* Use callback routine to setp rings in the pcb */
1227 lpfc_config_pcb_setup(phba);
1228
1229 /* special handling for LC HBAs */
1230 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
1231 uint32_t hbainit[5];
1232
1233 lpfc_hba_init(phba, hbainit);
1234
1235 memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
1236 }
1237
1238 /* Swap PCB if needed */
James Smart34b02dc2008-08-24 21:49:55 -04001239 lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
dea31012005-04-17 16:05:31 -05001240}
1241
James Smarte59058c2008-08-24 21:49:00 -04001242/**
James Smart3621a712009-04-06 18:47:14 -04001243 * lpfc_kill_board - Prepare a mailbox command for killing board
James Smarte59058c2008-08-24 21:49:00 -04001244 * @phba: pointer to lpfc hba data structure.
1245 * @pmb: pointer to the driver internal queue element for mailbox command.
1246 *
1247 * The kill board mailbox command is used to tell firmware to perform a
1248 * graceful shutdown of a channel on a specified board to prepare for reset.
1249 * When the kill board mailbox command is received, the ER3 bit is set to 1
1250 * in the Host Status register and the ER Attention bit is set to 1 in the
1251 * Host Attention register of the HBA function that received the kill board
1252 * command.
1253 *
1254 * This routine prepares the mailbox command for killing the board in
1255 * preparation for a graceful shutdown.
1256 **/
dea31012005-04-17 16:05:31 -05001257void
Jamie Wellnitz41415862006-02-28 19:25:27 -05001258lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1259{
James Smart04c68492009-05-22 14:52:52 -04001260 MAILBOX_t *mb = &pmb->u.mb;
Jamie Wellnitz41415862006-02-28 19:25:27 -05001261
1262 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1263 mb->mbxCommand = MBX_KILL_BOARD;
1264 mb->mbxOwner = OWN_HOST;
1265 return;
1266}
1267
James Smarte59058c2008-08-24 21:49:00 -04001268/**
James Smart3621a712009-04-06 18:47:14 -04001269 * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
James Smarte59058c2008-08-24 21:49:00 -04001270 * @phba: pointer to lpfc hba data structure.
1271 * @mbq: pointer to the driver internal queue element for mailbox command.
1272 *
1273 * Driver maintains a internal mailbox command queue implemented as a linked
1274 * list. When a mailbox command is issued, it shall be put into the mailbox
1275 * command queue such that they shall be processed orderly as HBA can process
1276 * one mailbox command at a time.
1277 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001278void
dea31012005-04-17 16:05:31 -05001279lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1280{
1281 struct lpfc_sli *psli;
1282
1283 psli = &phba->sli;
1284
1285 list_add_tail(&mbq->list, &psli->mboxq);
1286
1287 psli->mboxq_cnt++;
1288
1289 return;
1290}
1291
James Smarte59058c2008-08-24 21:49:00 -04001292/**
James Smart3621a712009-04-06 18:47:14 -04001293 * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
James Smarte59058c2008-08-24 21:49:00 -04001294 * @phba: pointer to lpfc hba data structure.
1295 *
1296 * Driver maintains a internal mailbox command queue implemented as a linked
1297 * list. When a mailbox command is issued, it shall be put into the mailbox
1298 * command queue such that they shall be processed orderly as HBA can process
1299 * one mailbox command at a time. After HBA finished processing a mailbox
1300 * command, the driver will remove a pending mailbox command from the head of
1301 * the mailbox command queue and send to the HBA for processing.
1302 *
1303 * Return codes
1304 * pointer to the driver internal queue element for mailbox command.
1305 **/
dea31012005-04-17 16:05:31 -05001306LPFC_MBOXQ_t *
1307lpfc_mbox_get(struct lpfc_hba * phba)
1308{
1309 LPFC_MBOXQ_t *mbq = NULL;
1310 struct lpfc_sli *psli = &phba->sli;
1311
James Smart2e0fef82007-06-17 19:56:36 -05001312 list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
James Smart92d7f7b2007-06-17 19:56:38 -05001313 if (mbq)
dea31012005-04-17 16:05:31 -05001314 psli->mboxq_cnt--;
dea31012005-04-17 16:05:31 -05001315
1316 return mbq;
1317}
James Smarta309a6b2006-08-01 07:33:43 -04001318
James Smarte59058c2008-08-24 21:49:00 -04001319/**
James Smart04c68492009-05-22 14:52:52 -04001320 * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
1321 * @phba: pointer to lpfc hba data structure.
1322 * @mbq: pointer to the driver internal queue element for mailbox command.
1323 *
1324 * This routine put the completed mailbox command into the mailbox command
1325 * complete list. This is the unlocked version of the routine. The mailbox
1326 * complete list is used by the driver worker thread to process mailbox
1327 * complete callback functions outside the driver interrupt handler.
1328 **/
1329void
1330__lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
1331{
1332 list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
1333}
1334
1335/**
James Smart3621a712009-04-06 18:47:14 -04001336 * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
James Smarte59058c2008-08-24 21:49:00 -04001337 * @phba: pointer to lpfc hba data structure.
1338 * @mbq: pointer to the driver internal queue element for mailbox command.
1339 *
1340 * This routine put the completed mailbox command into the mailbox command
James Smart04c68492009-05-22 14:52:52 -04001341 * complete list. This is the locked version of the routine. The mailbox
1342 * complete list is used by the driver worker thread to process mailbox
1343 * complete callback functions outside the driver interrupt handler.
James Smarte59058c2008-08-24 21:49:00 -04001344 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001345void
James Smart04c68492009-05-22 14:52:52 -04001346lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
James Smart92d7f7b2007-06-17 19:56:38 -05001347{
James Smart5b75da22008-12-04 22:39:35 -05001348 unsigned long iflag;
1349
Joe Perchesb1c11812008-02-03 17:28:22 +02001350 /* This function expects to be called from interrupt context */
James Smart5b75da22008-12-04 22:39:35 -05001351 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart04c68492009-05-22 14:52:52 -04001352 __lpfc_mbox_cmpl_put(phba, mbq);
James Smart5b75da22008-12-04 22:39:35 -05001353 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05001354 return;
1355}
1356
James Smarte59058c2008-08-24 21:49:00 -04001357/**
James Smart04c68492009-05-22 14:52:52 -04001358 * lpfc_mbox_cmd_check - Check the validality of a mailbox command
1359 * @phba: pointer to lpfc hba data structure.
1360 * @mboxq: pointer to the driver internal queue element for mailbox command.
1361 *
1362 * This routine is to check whether a mailbox command is valid to be issued.
1363 * This check will be performed by both the mailbox issue API when a client
1364 * is to issue a mailbox command to the mailbox transport.
1365 *
1366 * Return 0 - pass the check, -ENODEV - fail the check
1367 **/
1368int
1369lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1370{
1371 /* Mailbox command that have a completion handler must also have a
1372 * vport specified.
1373 */
1374 if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
1375 mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
1376 if (!mboxq->vport) {
1377 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
1378 "1814 Mbox x%x failed, no vport\n",
1379 mboxq->u.mb.mbxCommand);
1380 dump_stack();
1381 return -ENODEV;
1382 }
1383 }
1384 return 0;
1385}
1386
1387/**
1388 * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
1389 * @phba: pointer to lpfc hba data structure.
1390 *
1391 * This routine is to check whether the HBA device is ready for posting a
1392 * mailbox command. It is used by the mailbox transport API at the time the
1393 * to post a mailbox command to the device.
1394 *
1395 * Return 0 - pass the check, -ENODEV - fail the check
1396 **/
1397int
1398lpfc_mbox_dev_check(struct lpfc_hba *phba)
1399{
1400 /* If the PCI channel is in offline state, do not issue mbox */
1401 if (unlikely(pci_channel_offline(phba->pcidev)))
1402 return -ENODEV;
1403
1404 /* If the HBA is in error state, do not issue mbox */
1405 if (phba->link_state == LPFC_HBA_ERROR)
1406 return -ENODEV;
1407
1408 return 0;
1409}
1410
1411/**
James Smart3621a712009-04-06 18:47:14 -04001412 * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
James Smarte59058c2008-08-24 21:49:00 -04001413 * @phba: pointer to lpfc hba data structure.
1414 * @cmd: mailbox command code.
1415 *
1416 * This routine retrieves the proper timeout value according to the mailbox
1417 * command code.
1418 *
1419 * Return codes
1420 * Timeout value to be used for the given mailbox command
1421 **/
James Smarta309a6b2006-08-01 07:33:43 -04001422int
1423lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
1424{
1425 switch (cmd) {
1426 case MBX_WRITE_NV: /* 0x03 */
1427 case MBX_UPDATE_CFG: /* 0x1B */
1428 case MBX_DOWN_LOAD: /* 0x1C */
1429 case MBX_DEL_LD_ENTRY: /* 0x1D */
1430 case MBX_LOAD_AREA: /* 0x81 */
James Smart09372822008-01-11 01:52:54 -05001431 case MBX_WRITE_WWN: /* 0x98 */
James Smarta309a6b2006-08-01 07:33:43 -04001432 case MBX_LOAD_EXP_ROM: /* 0x9C */
1433 return LPFC_MBOX_TMO_FLASH_CMD;
James Smart04c68492009-05-22 14:52:52 -04001434 case MBX_SLI4_CONFIG: /* 0x9b */
1435 return LPFC_MBOX_SLI4_CONFIG_TMO;
James Smarta309a6b2006-08-01 07:33:43 -04001436 }
1437 return LPFC_MBOX_TMO;
1438}
James Smart04c68492009-05-22 14:52:52 -04001439
1440/**
1441 * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
1442 * @mbox: pointer to lpfc mbox command.
1443 * @sgentry: sge entry index.
1444 * @phyaddr: physical address for the sge
1445 * @length: Length of the sge.
1446 *
1447 * This routine sets up an entry in the non-embedded mailbox command at the sge
1448 * index location.
1449 **/
1450void
1451lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry,
1452 dma_addr_t phyaddr, uint32_t length)
1453{
1454 struct lpfc_mbx_nembed_cmd *nembed_sge;
1455
1456 nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1457 &mbox->u.mqe.un.nembed_cmd;
1458 nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr);
1459 nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr);
1460 nembed_sge->sge[sgentry].length = length;
1461}
1462
1463/**
1464 * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
1465 * @mbox: pointer to lpfc mbox command.
1466 * @sgentry: sge entry index.
1467 *
1468 * This routine gets an entry from the non-embedded mailbox command at the sge
1469 * index location.
1470 **/
1471void
1472lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry,
1473 struct lpfc_mbx_sge *sge)
1474{
1475 struct lpfc_mbx_nembed_cmd *nembed_sge;
1476
1477 nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1478 &mbox->u.mqe.un.nembed_cmd;
1479 sge->pa_lo = nembed_sge->sge[sgentry].pa_lo;
1480 sge->pa_hi = nembed_sge->sge[sgentry].pa_hi;
1481 sge->length = nembed_sge->sge[sgentry].length;
1482}
1483
1484/**
1485 * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
1486 * @phba: pointer to lpfc hba data structure.
1487 * @mbox: pointer to lpfc mbox command.
1488 *
1489 * This routine frees SLI4 specific mailbox command for sending IOCTL command.
1490 **/
1491void
1492lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1493{
1494 struct lpfc_mbx_sli4_config *sli4_cfg;
1495 struct lpfc_mbx_sge sge;
1496 dma_addr_t phyaddr;
1497 uint32_t sgecount, sgentry;
1498
1499 sli4_cfg = &mbox->u.mqe.un.sli4_config;
1500
1501 /* For embedded mbox command, just free the mbox command */
1502 if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1503 mempool_free(mbox, phba->mbox_mem_pool);
1504 return;
1505 }
1506
1507 /* For non-embedded mbox command, we need to free the pages first */
1508 sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr);
1509 /* There is nothing we can do if there is no sge address array */
1510 if (unlikely(!mbox->sge_array)) {
1511 mempool_free(mbox, phba->mbox_mem_pool);
1512 return;
1513 }
1514 /* Each non-embedded DMA memory was allocated in the length of a page */
1515 for (sgentry = 0; sgentry < sgecount; sgentry++) {
1516 lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge);
1517 phyaddr = getPaddr(sge.pa_hi, sge.pa_lo);
1518 dma_free_coherent(&phba->pcidev->dev, PAGE_SIZE,
1519 mbox->sge_array->addr[sgentry], phyaddr);
1520 }
1521 /* Free the sge address array memory */
1522 kfree(mbox->sge_array);
1523 /* Finally, free the mailbox command itself */
1524 mempool_free(mbox, phba->mbox_mem_pool);
1525}
1526
1527/**
1528 * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command
1529 * @phba: pointer to lpfc hba data structure.
1530 * @mbox: pointer to lpfc mbox command.
1531 * @subsystem: The sli4 config sub mailbox subsystem.
1532 * @opcode: The sli4 config sub mailbox command opcode.
1533 * @length: Length of the sli4 config mailbox command.
1534 *
1535 * This routine sets up the header fields of SLI4 specific mailbox command
1536 * for sending IOCTL command.
1537 *
1538 * Return: the actual length of the mbox command allocated (mostly useful
1539 * for none embedded mailbox command).
1540 **/
1541int
1542lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
1543 uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb)
1544{
1545 struct lpfc_mbx_sli4_config *sli4_config;
1546 union lpfc_sli4_cfg_shdr *cfg_shdr = NULL;
1547 uint32_t alloc_len;
1548 uint32_t resid_len;
1549 uint32_t pagen, pcount;
1550 void *viraddr;
1551 dma_addr_t phyaddr;
1552
1553 /* Set up SLI4 mailbox command header fields */
1554 memset(mbox, 0, sizeof(*mbox));
1555 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG);
1556
1557 /* Set up SLI4 ioctl command header fields */
1558 sli4_config = &mbox->u.mqe.un.sli4_config;
1559
1560 /* Setup for the embedded mbox command */
1561 if (emb) {
1562 /* Set up main header fields */
1563 bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
1564 sli4_config->header.cfg_mhdr.payload_length =
1565 LPFC_MBX_CMD_HDR_LENGTH + length;
1566 /* Set up sub-header fields following main header */
1567 bf_set(lpfc_mbox_hdr_opcode,
1568 &sli4_config->header.cfg_shdr.request, opcode);
1569 bf_set(lpfc_mbox_hdr_subsystem,
1570 &sli4_config->header.cfg_shdr.request, subsystem);
1571 sli4_config->header.cfg_shdr.request.request_length = length;
1572 return length;
1573 }
1574
1575 /* Setup for the none-embedded mbox command */
1576 pcount = (PAGE_ALIGN(length))/PAGE_SIZE;
1577 pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ?
1578 LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount;
1579 /* Allocate record for keeping SGE virtual addresses */
1580 mbox->sge_array = kmalloc(sizeof(struct lpfc_mbx_nembed_sge_virt),
1581 GFP_KERNEL);
1582 if (!mbox->sge_array)
1583 return 0;
1584
1585 for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) {
1586 /* The DMA memory is always allocated in the length of a
1587 * page even though the last SGE might not fill up to a
1588 * page, this is used as a priori size of PAGE_SIZE for
1589 * the later DMA memory free.
1590 */
1591 viraddr = dma_alloc_coherent(&phba->pcidev->dev, PAGE_SIZE,
1592 &phyaddr, GFP_KERNEL);
1593 /* In case of malloc fails, proceed with whatever we have */
1594 if (!viraddr)
1595 break;
1596 mbox->sge_array->addr[pagen] = viraddr;
1597 /* Keep the first page for later sub-header construction */
1598 if (pagen == 0)
1599 cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr;
1600 resid_len = length - alloc_len;
1601 if (resid_len > PAGE_SIZE) {
1602 lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
1603 PAGE_SIZE);
1604 alloc_len += PAGE_SIZE;
1605 } else {
1606 lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
1607 resid_len);
1608 alloc_len = length;
1609 }
1610 }
1611
1612 /* Set up main header fields in mailbox command */
1613 sli4_config->header.cfg_mhdr.payload_length = alloc_len;
1614 bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen);
1615
1616 /* Set up sub-header fields into the first page */
1617 if (pagen > 0) {
1618 bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode);
1619 bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem);
1620 cfg_shdr->request.request_length =
1621 alloc_len - sizeof(union lpfc_sli4_cfg_shdr);
1622 }
1623 /* The sub-header is in DMA memory, which needs endian converstion */
1624 lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
1625 sizeof(union lpfc_sli4_cfg_shdr));
1626
1627 return alloc_len;
1628}
1629
1630/**
1631 * lpfc_sli4_mbox_opcode_get - Get the opcode from a sli4 mailbox command
1632 * @phba: pointer to lpfc hba data structure.
1633 * @mbox: pointer to lpfc mbox command.
1634 *
1635 * This routine gets the opcode from a SLI4 specific mailbox command for
1636 * sending IOCTL command. If the mailbox command is not MBX_SLI4_CONFIG
1637 * (0x9B) or if the IOCTL sub-header is not present, opcode 0x0 shall be
1638 * returned.
1639 **/
1640uint8_t
1641lpfc_sli4_mbox_opcode_get(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1642{
1643 struct lpfc_mbx_sli4_config *sli4_cfg;
1644 union lpfc_sli4_cfg_shdr *cfg_shdr;
1645
1646 if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
1647 return 0;
1648 sli4_cfg = &mbox->u.mqe.un.sli4_config;
1649
1650 /* For embedded mbox command, get opcode from embedded sub-header*/
1651 if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1652 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
1653 return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
1654 }
1655
1656 /* For non-embedded mbox command, get opcode from first dma page */
1657 if (unlikely(!mbox->sge_array))
1658 return 0;
1659 cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
1660 return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
1661}
1662
1663/**
1664 * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
1665 * @mboxq: pointer to lpfc mbox command.
1666 *
1667 * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
1668 * mailbox command.
1669 **/
1670void
1671lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
1672{
1673 /* Set up SLI4 mailbox command header fields */
1674 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
1675 bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS);
1676
1677 /* Set up host requested features. */
1678 bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
1679
1680 /* Virtual fabrics and FIPs are not supported yet. */
1681 bf_set(lpfc_mbx_rq_ftr_rq_ifip, &mboxq->u.mqe.un.req_ftrs, 0);
1682
1683 /* Enable DIF (block guard) only if configured to do so. */
1684 if (phba->cfg_enable_bg)
1685 bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1);
1686
1687 /* Enable NPIV only if configured to do so. */
1688 if (phba->max_vpi && phba->cfg_enable_npiv)
1689 bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1);
1690
1691 return;
1692}
1693
1694/**
1695 * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
1696 * @mbox: pointer to lpfc mbox command to initialize.
1697 * @vport: Vport associated with the VF.
1698 *
1699 * This routine initializes @mbox to all zeros and then fills in the mailbox
1700 * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
1701 * in the context of an FCF. The driver issues this command to setup a VFI
1702 * before issuing a FLOGI to login to the VSAN. The driver should also issue a
1703 * REG_VFI after a successful VSAN login.
1704 **/
1705void
1706lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
1707{
1708 struct lpfc_mbx_init_vfi *init_vfi;
1709
1710 memset(mbox, 0, sizeof(*mbox));
1711 init_vfi = &mbox->u.mqe.un.init_vfi;
1712 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI);
1713 bf_set(lpfc_init_vfi_vr, init_vfi, 1);
1714 bf_set(lpfc_init_vfi_vt, init_vfi, 1);
1715 bf_set(lpfc_init_vfi_vfi, init_vfi, vport->vfi + vport->phba->vfi_base);
1716 bf_set(lpfc_init_vfi_fcfi, init_vfi, vport->phba->fcf.fcfi);
1717}
1718
1719/**
1720 * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
1721 * @mbox: pointer to lpfc mbox command to initialize.
1722 * @vport: vport associated with the VF.
1723 * @phys: BDE DMA bus address used to send the service parameters to the HBA.
1724 *
1725 * This routine initializes @mbox to all zeros and then fills in the mailbox
1726 * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
1727 * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
1728 * fabrics identified by VFI in the context of an FCF.
1729 **/
1730void
1731lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys)
1732{
1733 struct lpfc_mbx_reg_vfi *reg_vfi;
1734
1735 memset(mbox, 0, sizeof(*mbox));
1736 reg_vfi = &mbox->u.mqe.un.reg_vfi;
1737 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI);
1738 bf_set(lpfc_reg_vfi_vp, reg_vfi, 1);
1739 bf_set(lpfc_reg_vfi_vfi, reg_vfi, vport->vfi + vport->phba->vfi_base);
1740 bf_set(lpfc_reg_vfi_fcfi, reg_vfi, vport->phba->fcf.fcfi);
1741 bf_set(lpfc_reg_vfi_vpi, reg_vfi, vport->vpi + vport->phba->vpi_base);
1742 reg_vfi->bde.addrHigh = putPaddrHigh(phys);
1743 reg_vfi->bde.addrLow = putPaddrLow(phys);
1744 reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam);
1745 reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1746 bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID);
1747}
1748
1749/**
1750 * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
1751 * @mbox: pointer to lpfc mbox command to initialize.
1752 * @vpi: VPI to be initialized.
1753 *
1754 * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
1755 * command to activate a virtual N_Port. The HBA assigns a MAC address to use
1756 * with the virtual N Port. The SLI Host issues this command before issuing a
1757 * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
1758 * successful virtual NPort login.
1759 **/
1760void
1761lpfc_init_vpi(struct lpfcMboxq *mbox, uint16_t vpi)
1762{
1763 memset(mbox, 0, sizeof(*mbox));
1764 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI);
1765 bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi, vpi);
1766}
1767
1768/**
1769 * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
1770 * @mbox: pointer to lpfc mbox command to initialize.
1771 * @vfi: VFI to be unregistered.
1772 *
1773 * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
1774 * (logical NPort) into the inactive state. The SLI Host must have logged out
1775 * and unregistered all remote N_Ports to abort any activity on the virtual
1776 * fabric. The SLI Port posts the mailbox response after marking the virtual
1777 * fabric inactive.
1778 **/
1779void
1780lpfc_unreg_vfi(struct lpfcMboxq *mbox, uint16_t vfi)
1781{
1782 memset(mbox, 0, sizeof(*mbox));
1783 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI);
1784 bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi, vfi);
1785}
1786
1787/**
1788 * lpfc_dump_fcoe_param - Dump config region 23 to get FCoe parameters.
1789 * @phba: pointer to the hba structure containing.
1790 * @mbox: pointer to lpfc mbox command to initialize.
1791 *
1792 * This function create a SLI4 dump mailbox command to dump FCoE
1793 * parameters stored in region 23.
1794 **/
1795int
1796lpfc_dump_fcoe_param(struct lpfc_hba *phba,
1797 struct lpfcMboxq *mbox)
1798{
1799 struct lpfc_dmabuf *mp = NULL;
1800 MAILBOX_t *mb;
1801
1802 memset(mbox, 0, sizeof(*mbox));
1803 mb = &mbox->u.mb;
1804
1805 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1806 if (mp)
1807 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
1808
1809 if (!mp || !mp->virt) {
1810 kfree(mp);
1811 /* dump_fcoe_param failed to allocate memory */
1812 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
1813 "2569 lpfc_dump_fcoe_param: memory"
1814 " allocation failed \n");
1815 return 1;
1816 }
1817
1818 memset(mp->virt, 0, LPFC_BPL_SIZE);
1819 INIT_LIST_HEAD(&mp->list);
1820
1821 /* save address for completion */
1822 mbox->context1 = (uint8_t *) mp;
1823
1824 mb->mbxCommand = MBX_DUMP_MEMORY;
1825 mb->un.varDmp.type = DMP_NV_PARAMS;
1826 mb->un.varDmp.region_id = DMP_REGION_FCOEPARAM;
1827 mb->un.varDmp.sli4_length = DMP_FCOEPARAM_RGN_SIZE;
1828 mb->un.varWords[3] = putPaddrLow(mp->phys);
1829 mb->un.varWords[4] = putPaddrHigh(mp->phys);
1830 return 0;
1831}
1832
1833/**
1834 * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
1835 * @phba: pointer to the hba structure containing the FCF index and RQ ID.
1836 * @mbox: pointer to lpfc mbox command to initialize.
1837 *
1838 * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
1839 * SLI Host uses the command to activate an FCF after it has acquired FCF
1840 * information via a READ_FCF mailbox command. This mailbox command also is used
1841 * to indicate where received unsolicited frames from this FCF will be sent. By
1842 * default this routine will set up the FCF to forward all unsolicited frames
1843 * the the RQ ID passed in the @phba. This can be overridden by the caller for
1844 * more complicated setups.
1845 **/
1846void
1847lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1848{
1849 struct lpfc_mbx_reg_fcfi *reg_fcfi;
1850
1851 memset(mbox, 0, sizeof(*mbox));
1852 reg_fcfi = &mbox->u.mqe.un.reg_fcfi;
1853 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI);
1854 bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, phba->sli4_hba.hdr_rq->queue_id);
1855 bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
1856 bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
1857 bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
1858 bf_set(lpfc_reg_fcfi_info_index, reg_fcfi, phba->fcf.fcf_indx);
1859 /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */
1860 bf_set(lpfc_reg_fcfi_mam, reg_fcfi,
1861 (~phba->fcf.addr_mode) & 0x3);
1862 if (phba->fcf.fcf_flag & FCF_VALID_VLAN) {
1863 bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
1864 bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi, phba->fcf.vlan_id);
1865 }
1866}
1867
1868/**
1869 * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
1870 * @mbox: pointer to lpfc mbox command to initialize.
1871 * @fcfi: FCFI to be unregistered.
1872 *
1873 * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
1874 * The SLI Host uses the command to inactivate an FCFI.
1875 **/
1876void
1877lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi)
1878{
1879 memset(mbox, 0, sizeof(*mbox));
1880 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI);
1881 bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi);
1882}
1883
1884/**
1885 * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
1886 * @mbox: pointer to lpfc mbox command to initialize.
1887 * @ndlp: The nodelist structure that describes the RPI to resume.
1888 *
1889 * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
1890 * link event.
1891 **/
1892void
1893lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
1894{
1895 struct lpfc_mbx_resume_rpi *resume_rpi;
1896
1897 memset(mbox, 0, sizeof(*mbox));
1898 resume_rpi = &mbox->u.mqe.un.resume_rpi;
1899 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI);
1900 bf_set(lpfc_resume_rpi_rpi, resume_rpi, ndlp->nlp_rpi);
1901 bf_set(lpfc_resume_rpi_vpi, resume_rpi,
1902 ndlp->vport->vpi + ndlp->vport->phba->vpi_base);
1903 bf_set(lpfc_resume_rpi_vfi, resume_rpi,
1904 ndlp->vport->vfi + ndlp->vport->phba->vfi_base);
1905}