blob: 7f5899b70bd2253de9762238b8c35df5b2d627dc [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
63 mb = &pmb->mb;
64 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
95 mb = &pmb->mb;
96 /* 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
130 mb = &pmb->mb;
131 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
156 mb = &pmb->mb;
157 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
182 mb = &pmb->mb;
183 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;
216 mb = &pmb->mb;
217 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
253 mb = &pmb->mb;
254 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;
dea31012005-04-17 16:05:31 -0500280 MAILBOX_t *mb = &pmb->mb;
281 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{
326 MAILBOX_t *mb = &pmb->mb;
327 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
410 mb = &pmb->mb;
411 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;
497 mb = &pmb->mb;
498 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 Smart92d7f7b2007-06-17 19:56:38 -0500520 mb->un.varRdSparm.vpi = vpi;
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
549 mb = &pmb->mb;
550 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
551
552 mb->un.varUnregDID.did = did;
James Smart92d7f7b2007-06-17 19:56:38 -0500553 mb->un.varUnregDID.vpi = vpi;
dea31012005-04-17 16:05:31 -0500554
555 mb->mbxCommand = MBX_UNREG_D_ID;
556 mb->mbxOwner = OWN_HOST;
557 return;
558}
559
James Smarte59058c2008-08-24 21:49:00 -0400560/**
James Smart3621a712009-04-06 18:47:14 -0400561 * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
James Smarte59058c2008-08-24 21:49:00 -0400562 * @phba: pointer to lpfc hba data structure.
563 * @pmb: pointer to the driver internal queue element for mailbox command.
564 *
565 * The read configuration mailbox command is used to read the HBA port
566 * configuration parameters. This mailbox command provides a method for
567 * seeing any parameters that may have changed via various configuration
568 * mailbox commands.
569 *
570 * This routine prepares the mailbox command for reading out HBA configuration
571 * parameters.
572 **/
dea31012005-04-17 16:05:31 -0500573void
574lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
575{
576 MAILBOX_t *mb;
577
578 mb = &pmb->mb;
579 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
580
581 mb->mbxCommand = MBX_READ_CONFIG;
582 mb->mbxOwner = OWN_HOST;
583 return;
584}
585
James Smarte59058c2008-08-24 21:49:00 -0400586/**
James Smart3621a712009-04-06 18:47:14 -0400587 * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
James Smarte59058c2008-08-24 21:49:00 -0400588 * @phba: pointer to lpfc hba data structure.
589 * @pmb: pointer to the driver internal queue element for mailbox command.
590 *
591 * The read link status mailbox command is used to read the link status from
592 * the HBA. Link status includes all link-related error counters. These
593 * counters are maintained by the HBA and originated in the link hardware
594 * unit. Note that all of these counters wrap.
595 *
596 * This routine prepares the mailbox command for reading out HBA link status.
597 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -0500598void
599lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
600{
601 MAILBOX_t *mb;
602
603 mb = &pmb->mb;
604 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
605
606 mb->mbxCommand = MBX_READ_LNK_STAT;
607 mb->mbxOwner = OWN_HOST;
608 return;
609}
610
James Smarte59058c2008-08-24 21:49:00 -0400611/**
James Smart3621a712009-04-06 18:47:14 -0400612 * lpfc_reg_login - Prepare a mailbox command for registering remote login
James Smarte59058c2008-08-24 21:49:00 -0400613 * @phba: pointer to lpfc hba data structure.
614 * @vpi: virtual N_Port identifier.
615 * @did: remote port identifier.
616 * @param: pointer to memory holding the server parameters.
617 * @pmb: pointer to the driver internal queue element for mailbox command.
618 * @flag: action flag to be passed back for the complete function.
619 *
620 * The registration login mailbox command is used to register an N_Port or
621 * F_Port login. This registration allows the HBA to cache the remote N_Port
622 * service parameters internally and thereby make the appropriate FC-2
623 * decisions. The remote port service parameters are handed off by the driver
624 * to the HBA using a descriptor entry that directly identifies a buffer in
625 * host memory. In exchange, the HBA returns an RPI identifier.
626 *
627 * This routine prepares the mailbox command for registering remote port login.
628 * The function allocates DMA buffer for passing the service parameters to the
629 * HBA with the mailbox command.
630 *
631 * Return codes
632 * 0 - Success
633 * 1 - DMA memory allocation failed
634 **/
dea31012005-04-17 16:05:31 -0500635int
James Smart92d7f7b2007-06-17 19:56:38 -0500636lpfc_reg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
637 uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
dea31012005-04-17 16:05:31 -0500638{
James Smart2e0fef82007-06-17 19:56:36 -0500639 MAILBOX_t *mb = &pmb->mb;
dea31012005-04-17 16:05:31 -0500640 uint8_t *sparam;
641 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -0500642
dea31012005-04-17 16:05:31 -0500643 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
644
645 mb->un.varRegLogin.rpi = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500646 mb->un.varRegLogin.vpi = vpi;
dea31012005-04-17 16:05:31 -0500647 mb->un.varRegLogin.did = did;
648 mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */
649
650 mb->mbxOwner = OWN_HOST;
651
652 /* Get a buffer to hold NPorts Service Parameters */
James Smart98c9ea52007-10-27 13:37:33 -0400653 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
654 if (mp)
655 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
656 if (!mp || !mp->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800657 kfree(mp);
dea31012005-04-17 16:05:31 -0500658 mb->mbxCommand = MBX_REG_LOGIN64;
659 /* REG_LOGIN: no buffers */
James Smart92d7f7b2007-06-17 19:56:38 -0500660 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400661 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
662 "flag x%x\n", vpi, did, flag);
James Smart92d7f7b2007-06-17 19:56:38 -0500663 return (1);
dea31012005-04-17 16:05:31 -0500664 }
665 INIT_LIST_HEAD(&mp->list);
666 sparam = mp->virt;
667
668 /* Copy param's into a new buffer */
669 memcpy(sparam, param, sizeof (struct serv_parm));
670
671 /* save address for completion */
672 pmb->context1 = (uint8_t *) mp;
673
674 mb->mbxCommand = MBX_REG_LOGIN64;
675 mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
676 mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
677 mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
678
James Smart92d7f7b2007-06-17 19:56:38 -0500679 return (0);
dea31012005-04-17 16:05:31 -0500680}
681
James Smarte59058c2008-08-24 21:49:00 -0400682/**
James Smart3621a712009-04-06 18:47:14 -0400683 * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
James Smarte59058c2008-08-24 21:49:00 -0400684 * @phba: pointer to lpfc hba data structure.
685 * @vpi: virtual N_Port identifier.
686 * @rpi: remote port identifier
687 * @pmb: pointer to the driver internal queue element for mailbox command.
688 *
689 * The unregistration login mailbox command is used to unregister an N_Port
690 * or F_Port login. This command frees an RPI context in the HBA. It has the
691 * effect of performing an implicit N_Port/F_Port logout.
692 *
693 * This routine prepares the mailbox command for unregistering remote port
694 * login.
695 **/
dea31012005-04-17 16:05:31 -0500696void
James Smart92d7f7b2007-06-17 19:56:38 -0500697lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
698 LPFC_MBOXQ_t * pmb)
dea31012005-04-17 16:05:31 -0500699{
700 MAILBOX_t *mb;
701
702 mb = &pmb->mb;
703 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
704
705 mb->un.varUnregLogin.rpi = (uint16_t) rpi;
706 mb->un.varUnregLogin.rsvd1 = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500707 mb->un.varUnregLogin.vpi = vpi;
dea31012005-04-17 16:05:31 -0500708
709 mb->mbxCommand = MBX_UNREG_LOGIN;
710 mb->mbxOwner = OWN_HOST;
711 return;
712}
713
James Smarte59058c2008-08-24 21:49:00 -0400714/**
James Smart3621a712009-04-06 18:47:14 -0400715 * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
James Smarte59058c2008-08-24 21:49:00 -0400716 * @phba: pointer to lpfc hba data structure.
717 * @vpi: virtual N_Port identifier.
718 * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
719 * @pmb: pointer to the driver internal queue element for mailbox command.
720 *
721 * The registration vport identifier mailbox command is used to activate a
722 * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
723 * N_Port_ID against the information in the selected virtual N_Port context
724 * block and marks it active to allow normal processing of IOCB commands and
725 * received unsolicited exchanges.
726 *
727 * This routine prepares the mailbox command for registering a virtual N_Port.
728 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500729void
730lpfc_reg_vpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t sid,
731 LPFC_MBOXQ_t *pmb)
732{
733 MAILBOX_t *mb = &pmb->mb;
734
735 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
736
737 mb->un.varRegVpi.vpi = vpi;
738 mb->un.varRegVpi.sid = sid;
739
740 mb->mbxCommand = MBX_REG_VPI;
741 mb->mbxOwner = OWN_HOST;
742 return;
743
744}
745
James Smarte59058c2008-08-24 21:49:00 -0400746/**
James Smart3621a712009-04-06 18:47:14 -0400747 * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
James Smarte59058c2008-08-24 21:49:00 -0400748 * @phba: pointer to lpfc hba data structure.
749 * @vpi: virtual N_Port identifier.
750 * @pmb: pointer to the driver internal queue element for mailbox command.
751 *
752 * The unregistration vport identifier mailbox command is used to inactivate
753 * a virtual N_Port. The driver must have logged out and unregistered all
754 * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
755 * unregisters any default RPIs associated with the specified vpi, aborting
756 * any active exchanges. The HBA will post the mailbox response after making
757 * the virtual N_Port inactive.
758 *
759 * This routine prepares the mailbox command for unregistering a virtual
760 * N_Port.
761 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500762void
763lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
764{
765 MAILBOX_t *mb = &pmb->mb;
766 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
767
768 mb->un.varUnregVpi.vpi = vpi;
769
770 mb->mbxCommand = MBX_UNREG_VPI;
771 mb->mbxOwner = OWN_HOST;
772 return;
773
774}
775
James Smarte59058c2008-08-24 21:49:00 -0400776/**
James Smart3621a712009-04-06 18:47:14 -0400777 * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
James Smarte59058c2008-08-24 21:49:00 -0400778 * @phba: pointer to lpfc hba data structure.
779 *
780 * This routine sets up and initializes the IOCB rings in the Port Control
781 * Block (PCB).
782 **/
dea31012005-04-17 16:05:31 -0500783static void
784lpfc_config_pcb_setup(struct lpfc_hba * phba)
785{
786 struct lpfc_sli *psli = &phba->sli;
787 struct lpfc_sli_ring *pring;
James Smart34b02dc2008-08-24 21:49:55 -0400788 PCB_t *pcbp = phba->pcb;
dea31012005-04-17 16:05:31 -0500789 dma_addr_t pdma_addr;
790 uint32_t offset;
James Smart2e0fef82007-06-17 19:56:36 -0500791 uint32_t iocbCnt = 0;
dea31012005-04-17 16:05:31 -0500792 int i;
793
dea31012005-04-17 16:05:31 -0500794 pcbp->maxRing = (psli->num_rings - 1);
795
dea31012005-04-17 16:05:31 -0500796 for (i = 0; i < psli->num_rings; i++) {
797 pring = &psli->ring[i];
James Smart2e0fef82007-06-17 19:56:36 -0500798
James Smarted957682007-06-17 19:56:37 -0500799 pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
James Smart92d7f7b2007-06-17 19:56:38 -0500800 SLI2_IOCB_CMD_SIZE;
James Smarted957682007-06-17 19:56:37 -0500801 pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
James Smart92d7f7b2007-06-17 19:56:38 -0500802 SLI2_IOCB_RSP_SIZE;
dea31012005-04-17 16:05:31 -0500803 /* A ring MUST have both cmd and rsp entries defined to be
804 valid */
805 if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
806 pcbp->rdsc[i].cmdEntries = 0;
807 pcbp->rdsc[i].rspEntries = 0;
808 pcbp->rdsc[i].cmdAddrHigh = 0;
809 pcbp->rdsc[i].rspAddrHigh = 0;
810 pcbp->rdsc[i].cmdAddrLow = 0;
811 pcbp->rdsc[i].rspAddrLow = 0;
812 pring->cmdringaddr = NULL;
813 pring->rspringaddr = NULL;
814 continue;
815 }
816 /* Command ring setup for ring */
James Smart34b02dc2008-08-24 21:49:55 -0400817 pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
dea31012005-04-17 16:05:31 -0500818 pcbp->rdsc[i].cmdEntries = pring->numCiocb;
819
James Smart34b02dc2008-08-24 21:49:55 -0400820 offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
821 (uint8_t *) phba->slim2p.virt;
822 pdma_addr = phba->slim2p.phys + offset;
dea31012005-04-17 16:05:31 -0500823 pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
824 pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
825 iocbCnt += pring->numCiocb;
826
827 /* Response ring setup for ring */
James Smart34b02dc2008-08-24 21:49:55 -0400828 pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt];
dea31012005-04-17 16:05:31 -0500829
830 pcbp->rdsc[i].rspEntries = pring->numRiocb;
James Smart34b02dc2008-08-24 21:49:55 -0400831 offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
832 (uint8_t *)phba->slim2p.virt;
833 pdma_addr = phba->slim2p.phys + offset;
dea31012005-04-17 16:05:31 -0500834 pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
835 pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
836 iocbCnt += pring->numRiocb;
837 }
838}
839
James Smarte59058c2008-08-24 21:49:00 -0400840/**
James Smart3621a712009-04-06 18:47:14 -0400841 * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
James Smarte59058c2008-08-24 21:49:00 -0400842 * @phba: pointer to lpfc hba data structure.
843 * @pmb: pointer to the driver internal queue element for mailbox command.
844 *
845 * The read revision mailbox command is used to read the revision levels of
846 * the HBA components. These components include hardware units, resident
847 * firmware, and available firmware. HBAs that supports SLI-3 mode of
848 * operation provide different response information depending on the version
849 * requested by the driver.
850 *
851 * This routine prepares the mailbox command for reading HBA revision
852 * information.
853 **/
dea31012005-04-17 16:05:31 -0500854void
855lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
856{
James Smart2e0fef82007-06-17 19:56:36 -0500857 MAILBOX_t *mb = &pmb->mb;
dea31012005-04-17 16:05:31 -0500858 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
859 mb->un.varRdRev.cv = 1;
James Smarted957682007-06-17 19:56:37 -0500860 mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
dea31012005-04-17 16:05:31 -0500861 mb->mbxCommand = MBX_READ_REV;
862 mb->mbxOwner = OWN_HOST;
863 return;
864}
865
James Smarte59058c2008-08-24 21:49:00 -0400866/**
James Smart3621a712009-04-06 18:47:14 -0400867 * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
James Smarte59058c2008-08-24 21:49:00 -0400868 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
869 * @hbq_desc: pointer to the HBQ selection profile descriptor.
870 *
871 * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
872 * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
873 * the Sequence Length Test using the fields in the Selection Profile 2
874 * extension in words 20:31.
875 **/
James Smarted957682007-06-17 19:56:37 -0500876static void
877lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
878 struct lpfc_hbq_init *hbq_desc)
879{
880 hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
881 hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
882 hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
883}
884
James Smarte59058c2008-08-24 21:49:00 -0400885/**
James Smart3621a712009-04-06 18:47:14 -0400886 * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
James Smarte59058c2008-08-24 21:49:00 -0400887 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
888 * @hbq_desc: pointer to the HBQ selection profile descriptor.
889 *
890 * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
891 * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
892 * the Sequence Length Test and Byte Field Test using the fields in the
893 * Selection Profile 3 extension in words 20:31.
894 **/
James Smarted957682007-06-17 19:56:37 -0500895static void
896lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
897 struct lpfc_hbq_init *hbq_desc)
898{
899 hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
900 hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
901 hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
902 hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
903 memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
904 sizeof(hbqmb->profiles.profile3.cmdmatch));
905}
906
James Smarte59058c2008-08-24 21:49:00 -0400907/**
James Smart3621a712009-04-06 18:47:14 -0400908 * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
James Smarte59058c2008-08-24 21:49:00 -0400909 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
910 * @hbq_desc: pointer to the HBQ selection profile descriptor.
911 *
912 * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
913 * HBA tests the initial frame of an incoming sequence using the frame's
914 * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
915 * and Byte Field Test using the fields in the Selection Profile 5 extension
916 * words 20:31.
917 **/
James Smarted957682007-06-17 19:56:37 -0500918static void
919lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
920 struct lpfc_hbq_init *hbq_desc)
921{
922 hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
923 hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
924 hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
925 hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
926 memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
927 sizeof(hbqmb->profiles.profile5.cmdmatch));
928}
929
James Smarte59058c2008-08-24 21:49:00 -0400930/**
James Smart3621a712009-04-06 18:47:14 -0400931 * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
James Smarte59058c2008-08-24 21:49:00 -0400932 * @phba: pointer to lpfc hba data structure.
933 * @id: HBQ identifier.
934 * @hbq_desc: pointer to the HBA descriptor data structure.
935 * @hbq_entry_index: index of the HBQ entry data structures.
936 * @pmb: pointer to the driver internal queue element for mailbox command.
937 *
938 * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
939 * an HBQ. The configuration binds events that require buffers to a particular
940 * ring and HBQ based on a selection profile.
941 *
942 * This routine prepares the mailbox command for configuring an HBQ.
943 **/
James Smarted957682007-06-17 19:56:37 -0500944void
James Smart51ef4c22007-08-02 11:10:31 -0400945lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
946 struct lpfc_hbq_init *hbq_desc,
James Smarted957682007-06-17 19:56:37 -0500947 uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
948{
949 int i;
950 MAILBOX_t *mb = &pmb->mb;
951 struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
952
953 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
James Smart51ef4c22007-08-02 11:10:31 -0400954 hbqmb->hbqId = id;
James Smarted957682007-06-17 19:56:37 -0500955 hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
956 hbqmb->recvNotify = hbq_desc->rn; /* Receive
957 * Notification */
958 hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
959 * # in words 0-19 */
James Smart92d7f7b2007-06-17 19:56:38 -0500960 hbqmb->profile = hbq_desc->profile; /* Selection profile:
James Smarted957682007-06-17 19:56:37 -0500961 * 0 = all,
962 * 7 = logentry */
963 hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
964 * e.g. Ring0=b0001,
965 * ring2=b0100 */
966 hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
967 * or 5 */
968 hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
969 * HBQ will be used
970 * for LogEntry
971 * buffers */
972 hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
973 hbq_entry_index * sizeof(struct lpfc_hbq_entry);
974 hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
975
976 mb->mbxCommand = MBX_CONFIG_HBQ;
977 mb->mbxOwner = OWN_HOST;
978
James Smart92d7f7b2007-06-17 19:56:38 -0500979 /* Copy info for profiles 2,3,5. Other
980 * profiles this area is reserved
981 */
James Smarted957682007-06-17 19:56:37 -0500982 if (hbq_desc->profile == 2)
983 lpfc_build_hbq_profile2(hbqmb, hbq_desc);
984 else if (hbq_desc->profile == 3)
985 lpfc_build_hbq_profile3(hbqmb, hbq_desc);
986 else if (hbq_desc->profile == 5)
987 lpfc_build_hbq_profile5(hbqmb, hbq_desc);
988
989 /* Return if no rctl / type masks for this HBQ */
990 if (!hbq_desc->mask_count)
991 return;
992
993 /* Otherwise we setup specific rctl / type masks for this HBQ */
994 for (i = 0; i < hbq_desc->mask_count; i++) {
995 hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
996 hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
997 hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
998 hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
999 }
1000
1001 return;
1002}
1003
James Smarte59058c2008-08-24 21:49:00 -04001004/**
James Smart3621a712009-04-06 18:47:14 -04001005 * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
James Smarte59058c2008-08-24 21:49:00 -04001006 * @phba: pointer to lpfc hba data structure.
1007 * @ring:
1008 * @pmb: pointer to the driver internal queue element for mailbox command.
1009 *
1010 * The configure ring mailbox command is used to configure an IOCB ring. This
1011 * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1012 * ring. This is used to map incoming sequences to a particular ring whose
1013 * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1014 * attempt to configure a ring whose number is greater than the number
1015 * specified in the Port Control Block (PCB). It is an error to issue the
1016 * configure ring command more than once with the same ring number. The HBA
1017 * returns an error if the driver attempts this.
1018 *
1019 * This routine prepares the mailbox command for configuring IOCB ring.
1020 **/
dea31012005-04-17 16:05:31 -05001021void
1022lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
1023{
1024 int i;
1025 MAILBOX_t *mb = &pmb->mb;
1026 struct lpfc_sli *psli;
1027 struct lpfc_sli_ring *pring;
1028
1029 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1030
1031 mb->un.varCfgRing.ring = ring;
1032 mb->un.varCfgRing.maxOrigXchg = 0;
1033 mb->un.varCfgRing.maxRespXchg = 0;
1034 mb->un.varCfgRing.recvNotify = 1;
1035
1036 psli = &phba->sli;
1037 pring = &psli->ring[ring];
1038 mb->un.varCfgRing.numMask = pring->num_mask;
1039 mb->mbxCommand = MBX_CONFIG_RING;
1040 mb->mbxOwner = OWN_HOST;
1041
1042 /* Is this ring configured for a specific profile */
1043 if (pring->prt[0].profile) {
1044 mb->un.varCfgRing.profile = pring->prt[0].profile;
1045 return;
1046 }
1047
1048 /* Otherwise we setup specific rctl / type masks for this ring */
1049 for (i = 0; i < pring->num_mask; i++) {
1050 mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
1051 if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ)
1052 mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
1053 else
1054 mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
1055 mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
1056 mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
1057 }
1058
1059 return;
1060}
1061
James Smarte59058c2008-08-24 21:49:00 -04001062/**
James Smart3621a712009-04-06 18:47:14 -04001063 * lpfc_config_port - Prepare a mailbox command for configuring port
James Smarte59058c2008-08-24 21:49:00 -04001064 * @phba: pointer to lpfc hba data structure.
1065 * @pmb: pointer to the driver internal queue element for mailbox command.
1066 *
1067 * The configure port mailbox command is used to identify the Port Control
1068 * Block (PCB) in the driver memory. After this command is issued, the
1069 * driver must not access the mailbox in the HBA without first resetting
1070 * the HBA. The HBA may copy the PCB information to internal storage for
1071 * subsequent use; the driver can not change the PCB information unless it
1072 * resets the HBA.
1073 *
1074 * This routine prepares the mailbox command for configuring port.
1075 **/
dea31012005-04-17 16:05:31 -05001076void
James Smart92d7f7b2007-06-17 19:56:38 -05001077lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001078{
James Smarted957682007-06-17 19:56:37 -05001079 MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
dea31012005-04-17 16:05:31 -05001080 MAILBOX_t *mb = &pmb->mb;
1081 dma_addr_t pdma_addr;
1082 uint32_t bar_low, bar_high;
1083 size_t offset;
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04001084 struct lpfc_hgp hgp;
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001085 int i;
James Smarted957682007-06-17 19:56:37 -05001086 uint32_t pgp_offset;
dea31012005-04-17 16:05:31 -05001087
1088 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1089 mb->mbxCommand = MBX_CONFIG_PORT;
1090 mb->mbxOwner = OWN_HOST;
1091
1092 mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
1093
James Smart34b02dc2008-08-24 21:49:55 -04001094 offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
1095 pdma_addr = phba->slim2p.phys + offset;
dea31012005-04-17 16:05:31 -05001096 mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
1097 mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
1098
James Smart97207482008-12-04 22:39:19 -05001099 /* Always Host Group Pointer is in SLIM */
1100 mb->un.varCfgPort.hps = 1;
1101
James Smarted957682007-06-17 19:56:37 -05001102 /* If HBA supports SLI=3 ask for it */
1103
James Smart92d7f7b2007-06-17 19:56:38 -05001104 if (phba->sli_rev == 3 && phba->vpd.sli3Feat.cerbm) {
James Smarte2a0a9d2008-12-04 22:40:02 -05001105 if (phba->cfg_enable_bg)
1106 mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
James Smarted957682007-06-17 19:56:37 -05001107 mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
James Smart34b02dc2008-08-24 21:49:55 -04001108 mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
1109 mb->un.varCfgPort.cinb = 1; /* Interrupt Notification Block */
James Smart51ef4c22007-08-02 11:10:31 -04001110 mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
James Smart78b2d852007-08-02 11:10:21 -04001111 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smart92d7f7b2007-06-17 19:56:38 -05001112 phba->vpd.sli3Feat.cmv) {
1113 mb->un.varCfgPort.max_vpi = phba->max_vpi;
1114 mb->un.varCfgPort.cmv = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001115 } else
1116 mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
1117 } else
1118 phba->sli_rev = 2;
1119 mb->un.varCfgPort.sli_mode = phba->sli_rev;
James Smarted957682007-06-17 19:56:37 -05001120
dea31012005-04-17 16:05:31 -05001121 /* Now setup pcb */
James Smart34b02dc2008-08-24 21:49:55 -04001122 phba->pcb->type = TYPE_NATIVE_SLI2;
1123 phba->pcb->feature = FEATURE_INITIAL_SLI2;
dea31012005-04-17 16:05:31 -05001124
1125 /* Setup Mailbox pointers */
James Smart34b02dc2008-08-24 21:49:55 -04001126 phba->pcb->mailBoxSize = sizeof(MAILBOX_t);
1127 offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
1128 pdma_addr = phba->slim2p.phys + offset;
1129 phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
1130 phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
dea31012005-04-17 16:05:31 -05001131
1132 /*
1133 * Setup Host Group ring pointer.
1134 *
1135 * For efficiency reasons, the ring get/put pointers can be
1136 * placed in adapter memory (SLIM) rather than in host memory.
1137 * This allows firmware to avoid PCI reads/writes when updating
1138 * and checking pointers.
1139 *
1140 * The firmware recognizes the use of SLIM memory by comparing
1141 * the address of the get/put pointers structure with that of
1142 * the SLIM BAR (BAR0).
1143 *
1144 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1145 * (the hardware's view of the base address), not the OS's
1146 * value of pci_resource_start() as the OS value may be a cookie
1147 * for ioremap/iomap.
1148 */
1149
1150
1151 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
1152 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
1153
James Smarted957682007-06-17 19:56:37 -05001154 /*
1155 * Set up HGP - Port Memory
1156 *
1157 * The port expects the host get/put pointers to reside in memory
1158 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1159 * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
1160 * words (0x40 bytes). This area is not reserved if HBQs are
1161 * configured in SLI-3.
1162 *
1163 * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1164 * RR0Get 0xc4 0x84
1165 * CR1Put 0xc8 0x88
1166 * RR1Get 0xcc 0x8c
1167 * CR2Put 0xd0 0x90
1168 * RR2Get 0xd4 0x94
1169 * CR3Put 0xd8 0x98
1170 * RR3Get 0xdc 0x9c
1171 *
1172 * Reserved 0xa0-0xbf
1173 * If HBQs configured:
1174 * HBQ 0 Put ptr 0xc0
1175 * HBQ 1 Put ptr 0xc4
1176 * HBQ 2 Put ptr 0xc8
1177 * ......
1178 * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1179 *
1180 */
1181
1182 if (phba->sli_rev == 3) {
1183 phba->host_gp = &mb_slim->us.s3.host[0];
1184 phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
1185 } else {
1186 phba->host_gp = &mb_slim->us.s2.host[0];
1187 phba->hbq_put = NULL;
1188 }
dea31012005-04-17 16:05:31 -05001189
1190 /* mask off BAR0's flag bits 0 - 3 */
James Smart34b02dc2008-08-24 21:49:55 -04001191 phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
1192 (void __iomem *)phba->host_gp -
James Smarted957682007-06-17 19:56:37 -05001193 (void __iomem *)phba->MBslimaddr;
dea31012005-04-17 16:05:31 -05001194 if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
James Smart34b02dc2008-08-24 21:49:55 -04001195 phba->pcb->hgpAddrHigh = bar_high;
dea31012005-04-17 16:05:31 -05001196 else
James Smart34b02dc2008-08-24 21:49:55 -04001197 phba->pcb->hgpAddrHigh = 0;
dea31012005-04-17 16:05:31 -05001198 /* write HGP data to SLIM at the required longword offset */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -04001199 memset(&hgp, 0, sizeof(struct lpfc_hgp));
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001200
1201 for (i=0; i < phba->sli.num_rings; i++) {
James Smarted957682007-06-17 19:56:37 -05001202 lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
1203 sizeof(*phba->host_gp));
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -04001204 }
dea31012005-04-17 16:05:31 -05001205
James Smart8f34f4c2008-12-04 22:39:23 -05001206 /* Setup Port Group offset */
1207 if (phba->sli_rev == 3)
James Smart34b02dc2008-08-24 21:49:55 -04001208 pgp_offset = offsetof(struct lpfc_sli2_slim,
1209 mbx.us.s3_pgp.port);
James Smart8f34f4c2008-12-04 22:39:23 -05001210 else
James Smart34b02dc2008-08-24 21:49:55 -04001211 pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
1212 pdma_addr = phba->slim2p.phys + pgp_offset;
1213 phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
1214 phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
dea31012005-04-17 16:05:31 -05001215
1216 /* Use callback routine to setp rings in the pcb */
1217 lpfc_config_pcb_setup(phba);
1218
1219 /* special handling for LC HBAs */
1220 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
1221 uint32_t hbainit[5];
1222
1223 lpfc_hba_init(phba, hbainit);
1224
1225 memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
1226 }
1227
1228 /* Swap PCB if needed */
James Smart34b02dc2008-08-24 21:49:55 -04001229 lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
dea31012005-04-17 16:05:31 -05001230}
1231
James Smarte59058c2008-08-24 21:49:00 -04001232/**
James Smart3621a712009-04-06 18:47:14 -04001233 * lpfc_kill_board - Prepare a mailbox command for killing board
James Smarte59058c2008-08-24 21:49:00 -04001234 * @phba: pointer to lpfc hba data structure.
1235 * @pmb: pointer to the driver internal queue element for mailbox command.
1236 *
1237 * The kill board mailbox command is used to tell firmware to perform a
1238 * graceful shutdown of a channel on a specified board to prepare for reset.
1239 * When the kill board mailbox command is received, the ER3 bit is set to 1
1240 * in the Host Status register and the ER Attention bit is set to 1 in the
1241 * Host Attention register of the HBA function that received the kill board
1242 * command.
1243 *
1244 * This routine prepares the mailbox command for killing the board in
1245 * preparation for a graceful shutdown.
1246 **/
dea31012005-04-17 16:05:31 -05001247void
Jamie Wellnitz41415862006-02-28 19:25:27 -05001248lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1249{
1250 MAILBOX_t *mb = &pmb->mb;
1251
1252 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1253 mb->mbxCommand = MBX_KILL_BOARD;
1254 mb->mbxOwner = OWN_HOST;
1255 return;
1256}
1257
James Smarte59058c2008-08-24 21:49:00 -04001258/**
James Smart3621a712009-04-06 18:47:14 -04001259 * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
James Smarte59058c2008-08-24 21:49:00 -04001260 * @phba: pointer to lpfc hba data structure.
1261 * @mbq: pointer to the driver internal queue element for mailbox command.
1262 *
1263 * Driver maintains a internal mailbox command queue implemented as a linked
1264 * list. When a mailbox command is issued, it shall be put into the mailbox
1265 * command queue such that they shall be processed orderly as HBA can process
1266 * one mailbox command at a time.
1267 **/
Jamie Wellnitz41415862006-02-28 19:25:27 -05001268void
dea31012005-04-17 16:05:31 -05001269lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1270{
1271 struct lpfc_sli *psli;
1272
1273 psli = &phba->sli;
1274
1275 list_add_tail(&mbq->list, &psli->mboxq);
1276
1277 psli->mboxq_cnt++;
1278
1279 return;
1280}
1281
James Smarte59058c2008-08-24 21:49:00 -04001282/**
James Smart3621a712009-04-06 18:47:14 -04001283 * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
James Smarte59058c2008-08-24 21:49:00 -04001284 * @phba: pointer to lpfc hba data structure.
1285 *
1286 * Driver maintains a internal mailbox command queue implemented as a linked
1287 * list. When a mailbox command is issued, it shall be put into the mailbox
1288 * command queue such that they shall be processed orderly as HBA can process
1289 * one mailbox command at a time. After HBA finished processing a mailbox
1290 * command, the driver will remove a pending mailbox command from the head of
1291 * the mailbox command queue and send to the HBA for processing.
1292 *
1293 * Return codes
1294 * pointer to the driver internal queue element for mailbox command.
1295 **/
dea31012005-04-17 16:05:31 -05001296LPFC_MBOXQ_t *
1297lpfc_mbox_get(struct lpfc_hba * phba)
1298{
1299 LPFC_MBOXQ_t *mbq = NULL;
1300 struct lpfc_sli *psli = &phba->sli;
1301
James Smart2e0fef82007-06-17 19:56:36 -05001302 list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
James Smart92d7f7b2007-06-17 19:56:38 -05001303 if (mbq)
dea31012005-04-17 16:05:31 -05001304 psli->mboxq_cnt--;
dea31012005-04-17 16:05:31 -05001305
1306 return mbq;
1307}
James Smarta309a6b2006-08-01 07:33:43 -04001308
James Smarte59058c2008-08-24 21:49:00 -04001309/**
James Smart3621a712009-04-06 18:47:14 -04001310 * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
James Smarte59058c2008-08-24 21:49:00 -04001311 * @phba: pointer to lpfc hba data structure.
1312 * @mbq: pointer to the driver internal queue element for mailbox command.
1313 *
1314 * This routine put the completed mailbox command into the mailbox command
1315 * complete list. This routine is called from driver interrupt handler
1316 * context.The mailbox complete list is used by the driver worker thread
1317 * to process mailbox complete callback functions outside the driver interrupt
1318 * handler.
1319 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001320void
1321lpfc_mbox_cmpl_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1322{
James Smart5b75da22008-12-04 22:39:35 -05001323 unsigned long iflag;
1324
Joe Perchesb1c11812008-02-03 17:28:22 +02001325 /* This function expects to be called from interrupt context */
James Smart5b75da22008-12-04 22:39:35 -05001326 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05001327 list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
James Smart5b75da22008-12-04 22:39:35 -05001328 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05001329 return;
1330}
1331
James Smarte59058c2008-08-24 21:49:00 -04001332/**
James Smart3621a712009-04-06 18:47:14 -04001333 * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
James Smarte59058c2008-08-24 21:49:00 -04001334 * @phba: pointer to lpfc hba data structure.
1335 * @cmd: mailbox command code.
1336 *
1337 * This routine retrieves the proper timeout value according to the mailbox
1338 * command code.
1339 *
1340 * Return codes
1341 * Timeout value to be used for the given mailbox command
1342 **/
James Smarta309a6b2006-08-01 07:33:43 -04001343int
1344lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
1345{
1346 switch (cmd) {
1347 case MBX_WRITE_NV: /* 0x03 */
1348 case MBX_UPDATE_CFG: /* 0x1B */
1349 case MBX_DOWN_LOAD: /* 0x1C */
1350 case MBX_DEL_LD_ENTRY: /* 0x1D */
1351 case MBX_LOAD_AREA: /* 0x81 */
James Smart09372822008-01-11 01:52:54 -05001352 case MBX_WRITE_WWN: /* 0x98 */
James Smarta309a6b2006-08-01 07:33:43 -04001353 case MBX_LOAD_EXP_ROM: /* 0x9C */
1354 return LPFC_MBOX_TMO_FLASH_CMD;
1355 }
1356 return LPFC_MBOX_TMO;
1357}