1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * 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. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
26 #include <scsi/scsi_device.h>
27 #include <scsi/scsi_transport_fc.h>
29 #include <scsi/scsi.h>
34 #include "lpfc_disc.h"
35 #include "lpfc_scsi.h"
37 #include "lpfc_logmsg.h"
38 #include "lpfc_crtn.h"
39 #include "lpfc_compat.h"
42 * lpfc_dump_mem: Prepare a mailbox command for retrieving HBA's VPD memory.
43 * @phba: pointer to lpfc hba data structure.
44 * @pmb: pointer to the driver internal queue element for mailbox command.
45 * @offset: offset for dumping VPD memory mailbox command.
47 * The dump mailbox command provides a method for the device driver to obtain
48 * various types of information from the HBA device.
50 * This routine prepares the mailbox command for dumping HBA Vital Product
51 * Data (VPD) memory. This mailbox command is to be used for retrieving a
52 * portion (DMP_RSP_SIZE bytes) of a HBA's VPD from the HBA at an address
53 * offset specified by the offset parameter.
56 lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset)
64 /* Setup to dump VPD region */
65 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
66 mb->mbxCommand = MBX_DUMP_MEMORY;
68 mb->un.varDmp.type = DMP_NV_PARAMS;
69 mb->un.varDmp.entry_index = offset;
70 mb->un.varDmp.region_id = DMP_REGION_VPD;
71 mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
73 mb->un.varDmp.resp_offset = 0;
75 mb->mbxOwner = OWN_HOST;
80 * lpfc_dump_mem: Prepare a mailbox command for retrieving wakeup params.
81 * @phba: pointer to lpfc hba data structure.
82 * @pmb: pointer to the driver internal queue element for mailbox command.
83 * This function create a dump memory mailbox command to dump wake up
87 lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
93 /* Save context so that we can restore after memset */
96 /* Setup to dump VPD region */
97 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
98 mb->mbxCommand = MBX_DUMP_MEMORY;
99 mb->mbxOwner = OWN_HOST;
100 mb->un.varDmp.cv = 1;
101 mb->un.varDmp.type = DMP_NV_PARAMS;
102 mb->un.varDmp.entry_index = 0;
103 mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
104 mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
105 mb->un.varDmp.co = 0;
106 mb->un.varDmp.resp_offset = 0;
112 * lpfc_read_nv: Prepare a mailbox command for reading HBA's NVRAM param.
113 * @phba: pointer to lpfc hba data structure.
114 * @pmb: pointer to the driver internal queue element for mailbox command.
116 * The read NVRAM mailbox command returns the HBA's non-volatile parameters
117 * that are used as defaults when the Fibre Channel link is brought on-line.
119 * This routine prepares the mailbox command for reading information stored
120 * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
123 lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
128 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
129 mb->mbxCommand = MBX_READ_NV;
130 mb->mbxOwner = OWN_HOST;
135 * lpfc_config_async: Prepare a mailbox command for enabling HBA async event.
136 * @phba: pointer to lpfc hba data structure.
137 * @pmb: pointer to the driver internal queue element for mailbox command.
138 * @ring: ring number for the asynchronous event to be configured.
140 * The asynchronous event enable mailbox command is used to enable the
141 * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
142 * specifies the default ring to which events are posted.
144 * This routine prepares the mailbox command for enabling HBA asynchronous
145 * event support on a IOCB ring.
148 lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
154 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
155 mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
156 mb->un.varCfgAsyncEvent.ring = ring;
157 mb->mbxOwner = OWN_HOST;
162 * lpfc_heart_beat: Prepare a mailbox command for heart beat.
163 * @phba: pointer to lpfc hba data structure.
164 * @pmb: pointer to the driver internal queue element for mailbox command.
166 * The heart beat mailbox command is used to detect an unresponsive HBA, which
167 * is defined as any device where no error attention is sent and both mailbox
168 * and rings are not processed.
170 * This routine prepares the mailbox command for issuing a heart beat in the
171 * form of mailbox command to the HBA. The timely completion of the heart
172 * beat mailbox command indicates the health of the HBA.
175 lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
180 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
181 mb->mbxCommand = MBX_HEARTBEAT;
182 mb->mbxOwner = OWN_HOST;
187 * lpfc_read_la: Prepare a mailbox command for reading HBA link attention.
188 * @phba: pointer to lpfc hba data structure.
189 * @pmb: pointer to the driver internal queue element for mailbox command.
190 * @mp: DMA buffer memory for reading the link attention information into.
192 * The read link attention mailbox command is issued to read the Link Event
193 * Attention information indicated by the HBA port when the Link Event bit
194 * of the Host Attention (HSTATT) register is set to 1. A Link Event
195 * Attention occurs based on an exception detected at the Fibre Channel link
198 * This routine prepares the mailbox command for reading HBA link attention
199 * information. A DMA memory has been set aside and address passed to the
200 * HBA through @mp for the HBA to DMA link attention information into the
201 * memory as part of the execution of the mailbox command.
204 * 0 - Success (currently always return 0)
207 lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
210 struct lpfc_sli *psli;
214 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
216 INIT_LIST_HEAD(&mp->list);
217 mb->mbxCommand = MBX_READ_LA64;
218 mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128;
219 mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
220 mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys);
222 /* Save address for later completion and set the owner to host so that
223 * the FW knows this mailbox is available for processing.
225 pmb->context1 = (uint8_t *) mp;
226 mb->mbxOwner = OWN_HOST;
231 * lpfc_clear_la: Prepare a mailbox command for clearing HBA link attention.
232 * @phba: pointer to lpfc hba data structure.
233 * @pmb: pointer to the driver internal queue element for mailbox command.
235 * The clear link attention mailbox command is issued to clear the link event
236 * attention condition indicated by the Link Event bit of the Host Attention
237 * (HSTATT) register. The link event attention condition is cleared only if
238 * the event tag specified matches that of the current link event counter.
239 * The current event tag is read using the read link attention event mailbox
242 * This routine prepares the mailbox command for clearing HBA link attention
246 lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
251 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
253 mb->un.varClearLA.eventTag = phba->fc_eventTag;
254 mb->mbxCommand = MBX_CLEAR_LA;
255 mb->mbxOwner = OWN_HOST;
260 * lpfc_config_link: Prepare a mailbox command for configuring link on a HBA.
261 * @phba: pointer to lpfc hba data structure.
262 * @pmb: pointer to the driver internal queue element for mailbox command.
264 * The configure link mailbox command is used before the initialize link
265 * mailbox command to override default value and to configure link-oriented
266 * parameters such as DID address and various timers. Typically, this
267 * command would be used after an F_Port login to set the returned DID address
268 * and the fabric timeout values. This command is not valid before a configure
269 * port command has configured the HBA port.
271 * This routine prepares the mailbox command for configuring link on a HBA.
274 lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
276 struct lpfc_vport *vport = phba->pport;
277 MAILBOX_t *mb = &pmb->mb;
278 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
281 * SLI-2, Coalescing Response Feature.
283 if (phba->cfg_cr_delay) {
284 mb->un.varCfgLnk.cr = 1;
285 mb->un.varCfgLnk.ci = 1;
286 mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
287 mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
290 mb->un.varCfgLnk.myId = vport->fc_myDID;
291 mb->un.varCfgLnk.edtov = phba->fc_edtov;
292 mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
293 mb->un.varCfgLnk.ratov = phba->fc_ratov;
294 mb->un.varCfgLnk.rttov = phba->fc_rttov;
295 mb->un.varCfgLnk.altov = phba->fc_altov;
296 mb->un.varCfgLnk.crtov = phba->fc_crtov;
297 mb->un.varCfgLnk.citov = phba->fc_citov;
300 mb->un.varCfgLnk.ack0_enable = 1;
302 mb->mbxCommand = MBX_CONFIG_LINK;
303 mb->mbxOwner = OWN_HOST;
308 * lpfc_config_msi: Prepare a mailbox command for configuring msi-x.
309 * @phba: pointer to lpfc hba data structure.
310 * @pmb: pointer to the driver internal queue element for mailbox command.
312 * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
313 * MSI-X multi-message interrupt vector association to interrupt attention
321 lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
323 MAILBOX_t *mb = &pmb->mb;
324 uint32_t attentionConditions[2];
327 if (phba->cfg_use_msi != 2) {
328 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
329 "0475 Not configured for supporting MSI-X "
330 "cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
334 if (phba->sli_rev < 3) {
335 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
336 "0476 HBA not supporting SLI-3 or later "
337 "SLI Revision: 0x%x\n", phba->sli_rev);
341 /* Clear mailbox command fields */
342 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
345 * SLI-3, Message Signaled Interrupt Fearure.
348 /* Multi-message attention configuration */
349 attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
351 attentionConditions[1] = 0;
353 mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
354 mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
357 * Set up message number to HA bit association
359 #ifdef __BIG_ENDIAN_BITFIELD
361 mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
362 /* RA1 (Other Protocol Extra Ring) */
363 mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
364 #else /* __LITTLE_ENDIAN_BITFIELD */
366 mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
367 /* RA1 (Other Protocol Extra Ring) */
368 mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
370 /* Multi-message interrupt autoclear configuration*/
371 mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
372 mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
374 /* For now, HBA autoclear does not work reliably, disable it */
375 mb->un.varCfgMSI.autoClearHA[0] = 0;
376 mb->un.varCfgMSI.autoClearHA[1] = 0;
378 /* Set command and owner bit */
379 mb->mbxCommand = MBX_CONFIG_MSI;
380 mb->mbxOwner = OWN_HOST;
386 * lpfc_init_link: Prepare a mailbox command for initialize link on a HBA.
387 * @phba: pointer to lpfc hba data structure.
388 * @pmb: pointer to the driver internal queue element for mailbox command.
389 * @topology: the link topology for the link to be initialized to.
390 * @linkspeed: the link speed for the link to be initialized to.
392 * The initialize link mailbox command is used to initialize the Fibre
393 * Channel link. This command must follow a configure port command that
394 * establishes the mode of operation.
396 * This routine prepares the mailbox command for initializing link on a HBA
397 * with the specified link topology and speed.
400 lpfc_init_link(struct lpfc_hba * phba,
401 LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
404 struct lpfc_sli *psli;
408 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
412 case FLAGS_TOPOLOGY_MODE_LOOP_PT:
413 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
414 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
416 case FLAGS_TOPOLOGY_MODE_PT_PT:
417 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
419 case FLAGS_TOPOLOGY_MODE_LOOP:
420 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
422 case FLAGS_TOPOLOGY_MODE_PT_LOOP:
423 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
424 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
427 mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
431 /* Enable asynchronous ABTS responses from firmware */
432 mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
435 * Setting up the link speed
438 if (vpd->rev.feaLevelHigh >= 0x02){
444 mb->un.varInitLnk.link_flags |=
446 mb->un.varInitLnk.link_speed = linkspeed;
448 case LINK_SPEED_AUTO:
450 mb->un.varInitLnk.link_speed =
457 mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
459 mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
460 mb->mbxOwner = OWN_HOST;
461 mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
466 * lpfc_read_sparam: Prepare a mailbox command for reading HBA parameters.
467 * @phba: pointer to lpfc hba data structure.
468 * @pmb: pointer to the driver internal queue element for mailbox command.
469 * @vpi: virtual N_Port identifier.
471 * The read service parameter mailbox command is used to read the HBA port
472 * service parameters. The service parameters are read into the buffer
473 * specified directly by a BDE in the mailbox command. These service
474 * parameters may then be used to build the payload of an N_Port/F_POrt
475 * login request and reply (LOGI/ACC).
477 * This routine prepares the mailbox command for reading HBA port service
478 * parameters. The DMA memory is allocated in this function and the addresses
479 * are populated into the mailbox command for the HBA to DMA the service
484 * 1 - DMA memory allocation failed
487 lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
489 struct lpfc_dmabuf *mp;
491 struct lpfc_sli *psli;
495 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
497 mb->mbxOwner = OWN_HOST;
499 /* Get a buffer to hold the HBAs Service Parameters */
501 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
503 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
504 if (!mp || !mp->virt) {
506 mb->mbxCommand = MBX_READ_SPARM64;
507 /* READ_SPARAM: no buffers */
508 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
509 "0301 READ_SPARAM: no buffers\n");
512 INIT_LIST_HEAD(&mp->list);
513 mb->mbxCommand = MBX_READ_SPARM64;
514 mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
515 mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
516 mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
517 mb->un.varRdSparm.vpi = vpi;
519 /* save address for completion */
526 * lpfc_unreg_did: Prepare a mailbox command for unregistering DID.
527 * @phba: pointer to lpfc hba data structure.
528 * @vpi: virtual N_Port identifier.
529 * @did: remote port identifier.
530 * @pmb: pointer to the driver internal queue element for mailbox command.
532 * The unregister DID mailbox command is used to unregister an N_Port/F_Port
533 * login for an unknown RPI by specifying the DID of a remote port. This
534 * command frees an RPI context in the HBA port. This has the effect of
535 * performing an implicit N_Port/F_Port logout.
537 * This routine prepares the mailbox command for unregistering a remote
538 * N_Port/F_Port (DID) login.
541 lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
547 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
549 mb->un.varUnregDID.did = did;
550 mb->un.varUnregDID.vpi = vpi;
552 mb->mbxCommand = MBX_UNREG_D_ID;
553 mb->mbxOwner = OWN_HOST;
558 * lpfc_read_config: Prepare a mailbox command for reading HBA configuration.
559 * @phba: pointer to lpfc hba data structure.
560 * @pmb: pointer to the driver internal queue element for mailbox command.
562 * The read configuration mailbox command is used to read the HBA port
563 * configuration parameters. This mailbox command provides a method for
564 * seeing any parameters that may have changed via various configuration
567 * This routine prepares the mailbox command for reading out HBA configuration
571 lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
576 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
578 mb->mbxCommand = MBX_READ_CONFIG;
579 mb->mbxOwner = OWN_HOST;
584 * lpfc_read_lnk_stat: Prepare a mailbox command for reading HBA link stats.
585 * @phba: pointer to lpfc hba data structure.
586 * @pmb: pointer to the driver internal queue element for mailbox command.
588 * The read link status mailbox command is used to read the link status from
589 * the HBA. Link status includes all link-related error counters. These
590 * counters are maintained by the HBA and originated in the link hardware
591 * unit. Note that all of these counters wrap.
593 * This routine prepares the mailbox command for reading out HBA link status.
596 lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
601 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
603 mb->mbxCommand = MBX_READ_LNK_STAT;
604 mb->mbxOwner = OWN_HOST;
609 * lpfc_reg_login: Prepare a mailbox command for registering remote login.
610 * @phba: pointer to lpfc hba data structure.
611 * @vpi: virtual N_Port identifier.
612 * @did: remote port identifier.
613 * @param: pointer to memory holding the server parameters.
614 * @pmb: pointer to the driver internal queue element for mailbox command.
615 * @flag: action flag to be passed back for the complete function.
617 * The registration login mailbox command is used to register an N_Port or
618 * F_Port login. This registration allows the HBA to cache the remote N_Port
619 * service parameters internally and thereby make the appropriate FC-2
620 * decisions. The remote port service parameters are handed off by the driver
621 * to the HBA using a descriptor entry that directly identifies a buffer in
622 * host memory. In exchange, the HBA returns an RPI identifier.
624 * This routine prepares the mailbox command for registering remote port login.
625 * The function allocates DMA buffer for passing the service parameters to the
626 * HBA with the mailbox command.
630 * 1 - DMA memory allocation failed
633 lpfc_reg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
634 uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
636 MAILBOX_t *mb = &pmb->mb;
638 struct lpfc_dmabuf *mp;
640 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
642 mb->un.varRegLogin.rpi = 0;
643 mb->un.varRegLogin.vpi = vpi;
644 mb->un.varRegLogin.did = did;
645 mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */
647 mb->mbxOwner = OWN_HOST;
649 /* Get a buffer to hold NPorts Service Parameters */
650 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
652 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
653 if (!mp || !mp->virt) {
655 mb->mbxCommand = MBX_REG_LOGIN64;
656 /* REG_LOGIN: no buffers */
657 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
658 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
659 "flag x%x\n", vpi, did, flag);
662 INIT_LIST_HEAD(&mp->list);
665 /* Copy param's into a new buffer */
666 memcpy(sparam, param, sizeof (struct serv_parm));
668 /* save address for completion */
669 pmb->context1 = (uint8_t *) mp;
671 mb->mbxCommand = MBX_REG_LOGIN64;
672 mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
673 mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
674 mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
680 * lpfc_unreg_login: Prepare a mailbox command for unregistering remote login.
681 * @phba: pointer to lpfc hba data structure.
682 * @vpi: virtual N_Port identifier.
683 * @rpi: remote port identifier
684 * @pmb: pointer to the driver internal queue element for mailbox command.
686 * The unregistration login mailbox command is used to unregister an N_Port
687 * or F_Port login. This command frees an RPI context in the HBA. It has the
688 * effect of performing an implicit N_Port/F_Port logout.
690 * This routine prepares the mailbox command for unregistering remote port
694 lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
700 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
702 mb->un.varUnregLogin.rpi = (uint16_t) rpi;
703 mb->un.varUnregLogin.rsvd1 = 0;
704 mb->un.varUnregLogin.vpi = vpi;
706 mb->mbxCommand = MBX_UNREG_LOGIN;
707 mb->mbxOwner = OWN_HOST;
712 * lpfc_reg_vpi: Prepare a mailbox command for registering vport identifier.
713 * @phba: pointer to lpfc hba data structure.
714 * @vpi: virtual N_Port identifier.
715 * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
716 * @pmb: pointer to the driver internal queue element for mailbox command.
718 * The registration vport identifier mailbox command is used to activate a
719 * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
720 * N_Port_ID against the information in the selected virtual N_Port context
721 * block and marks it active to allow normal processing of IOCB commands and
722 * received unsolicited exchanges.
724 * This routine prepares the mailbox command for registering a virtual N_Port.
727 lpfc_reg_vpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t sid,
730 MAILBOX_t *mb = &pmb->mb;
732 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
734 mb->un.varRegVpi.vpi = vpi;
735 mb->un.varRegVpi.sid = sid;
737 mb->mbxCommand = MBX_REG_VPI;
738 mb->mbxOwner = OWN_HOST;
744 * lpfc_unreg_vpi: Prepare a mailbox command for unregistering vport id.
745 * @phba: pointer to lpfc hba data structure.
746 * @vpi: virtual N_Port identifier.
747 * @pmb: pointer to the driver internal queue element for mailbox command.
749 * The unregistration vport identifier mailbox command is used to inactivate
750 * a virtual N_Port. The driver must have logged out and unregistered all
751 * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
752 * unregisters any default RPIs associated with the specified vpi, aborting
753 * any active exchanges. The HBA will post the mailbox response after making
754 * the virtual N_Port inactive.
756 * This routine prepares the mailbox command for unregistering a virtual
760 lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
762 MAILBOX_t *mb = &pmb->mb;
763 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
765 mb->un.varUnregVpi.vpi = vpi;
767 mb->mbxCommand = MBX_UNREG_VPI;
768 mb->mbxOwner = OWN_HOST;
774 * lpfc_config_pcb_setup: Set up IOCB rings in the Port Control Block (PCB)
775 * @phba: pointer to lpfc hba data structure.
777 * This routine sets up and initializes the IOCB rings in the Port Control
781 lpfc_config_pcb_setup(struct lpfc_hba * phba)
783 struct lpfc_sli *psli = &phba->sli;
784 struct lpfc_sli_ring *pring;
785 PCB_t *pcbp = phba->pcb;
786 dma_addr_t pdma_addr;
788 uint32_t iocbCnt = 0;
791 pcbp->maxRing = (psli->num_rings - 1);
793 for (i = 0; i < psli->num_rings; i++) {
794 pring = &psli->ring[i];
796 pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
798 pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
800 /* A ring MUST have both cmd and rsp entries defined to be
802 if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
803 pcbp->rdsc[i].cmdEntries = 0;
804 pcbp->rdsc[i].rspEntries = 0;
805 pcbp->rdsc[i].cmdAddrHigh = 0;
806 pcbp->rdsc[i].rspAddrHigh = 0;
807 pcbp->rdsc[i].cmdAddrLow = 0;
808 pcbp->rdsc[i].rspAddrLow = 0;
809 pring->cmdringaddr = NULL;
810 pring->rspringaddr = NULL;
813 /* Command ring setup for ring */
814 pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
815 pcbp->rdsc[i].cmdEntries = pring->numCiocb;
817 offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
818 (uint8_t *) phba->slim2p.virt;
819 pdma_addr = phba->slim2p.phys + offset;
820 pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
821 pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
822 iocbCnt += pring->numCiocb;
824 /* Response ring setup for ring */
825 pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt];
827 pcbp->rdsc[i].rspEntries = pring->numRiocb;
828 offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
829 (uint8_t *)phba->slim2p.virt;
830 pdma_addr = phba->slim2p.phys + offset;
831 pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
832 pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
833 iocbCnt += pring->numRiocb;
838 * lpfc_read_rev: Prepare a mailbox command for reading HBA revision.
839 * @phba: pointer to lpfc hba data structure.
840 * @pmb: pointer to the driver internal queue element for mailbox command.
842 * The read revision mailbox command is used to read the revision levels of
843 * the HBA components. These components include hardware units, resident
844 * firmware, and available firmware. HBAs that supports SLI-3 mode of
845 * operation provide different response information depending on the version
846 * requested by the driver.
848 * This routine prepares the mailbox command for reading HBA revision
852 lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
854 MAILBOX_t *mb = &pmb->mb;
855 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
856 mb->un.varRdRev.cv = 1;
857 mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
858 mb->mbxCommand = MBX_READ_REV;
859 mb->mbxOwner = OWN_HOST;
864 * lpfc_build_hbq_profile2: Set up the HBQ Selection Profile 2.
865 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
866 * @hbq_desc: pointer to the HBQ selection profile descriptor.
868 * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
869 * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
870 * the Sequence Length Test using the fields in the Selection Profile 2
871 * extension in words 20:31.
874 lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
875 struct lpfc_hbq_init *hbq_desc)
877 hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
878 hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
879 hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
883 * lpfc_build_hbq_profile3: Set up the HBQ Selection Profile 3.
884 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
885 * @hbq_desc: pointer to the HBQ selection profile descriptor.
887 * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
888 * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
889 * the Sequence Length Test and Byte Field Test using the fields in the
890 * Selection Profile 3 extension in words 20:31.
893 lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
894 struct lpfc_hbq_init *hbq_desc)
896 hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
897 hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
898 hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
899 hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
900 memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
901 sizeof(hbqmb->profiles.profile3.cmdmatch));
905 * lpfc_build_hbq_profile5: Set up the HBQ Selection Profile 5.
906 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
907 * @hbq_desc: pointer to the HBQ selection profile descriptor.
909 * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
910 * HBA tests the initial frame of an incoming sequence using the frame's
911 * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
912 * and Byte Field Test using the fields in the Selection Profile 5 extension
916 lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
917 struct lpfc_hbq_init *hbq_desc)
919 hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
920 hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
921 hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
922 hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
923 memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
924 sizeof(hbqmb->profiles.profile5.cmdmatch));
928 * lpfc_config_hbq: Prepare a mailbox command for configuring an HBQ.
929 * @phba: pointer to lpfc hba data structure.
930 * @id: HBQ identifier.
931 * @hbq_desc: pointer to the HBA descriptor data structure.
932 * @hbq_entry_index: index of the HBQ entry data structures.
933 * @pmb: pointer to the driver internal queue element for mailbox command.
935 * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
936 * an HBQ. The configuration binds events that require buffers to a particular
937 * ring and HBQ based on a selection profile.
939 * This routine prepares the mailbox command for configuring an HBQ.
942 lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
943 struct lpfc_hbq_init *hbq_desc,
944 uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
947 MAILBOX_t *mb = &pmb->mb;
948 struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
950 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
952 hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
953 hbqmb->recvNotify = hbq_desc->rn; /* Receive
955 hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
957 hbqmb->profile = hbq_desc->profile; /* Selection profile:
960 hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
963 hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
965 hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
969 hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
970 hbq_entry_index * sizeof(struct lpfc_hbq_entry);
971 hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
973 mb->mbxCommand = MBX_CONFIG_HBQ;
974 mb->mbxOwner = OWN_HOST;
976 /* Copy info for profiles 2,3,5. Other
977 * profiles this area is reserved
979 if (hbq_desc->profile == 2)
980 lpfc_build_hbq_profile2(hbqmb, hbq_desc);
981 else if (hbq_desc->profile == 3)
982 lpfc_build_hbq_profile3(hbqmb, hbq_desc);
983 else if (hbq_desc->profile == 5)
984 lpfc_build_hbq_profile5(hbqmb, hbq_desc);
986 /* Return if no rctl / type masks for this HBQ */
987 if (!hbq_desc->mask_count)
990 /* Otherwise we setup specific rctl / type masks for this HBQ */
991 for (i = 0; i < hbq_desc->mask_count; i++) {
992 hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
993 hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
994 hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
995 hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
1002 * lpfc_config_ring: Prepare a mailbox command for configuring an IOCB ring.
1003 * @phba: pointer to lpfc hba data structure.
1005 * @pmb: pointer to the driver internal queue element for mailbox command.
1007 * The configure ring mailbox command is used to configure an IOCB ring. This
1008 * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1009 * ring. This is used to map incoming sequences to a particular ring whose
1010 * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1011 * attempt to configure a ring whose number is greater than the number
1012 * specified in the Port Control Block (PCB). It is an error to issue the
1013 * configure ring command more than once with the same ring number. The HBA
1014 * returns an error if the driver attempts this.
1016 * This routine prepares the mailbox command for configuring IOCB ring.
1019 lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
1022 MAILBOX_t *mb = &pmb->mb;
1023 struct lpfc_sli *psli;
1024 struct lpfc_sli_ring *pring;
1026 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1028 mb->un.varCfgRing.ring = ring;
1029 mb->un.varCfgRing.maxOrigXchg = 0;
1030 mb->un.varCfgRing.maxRespXchg = 0;
1031 mb->un.varCfgRing.recvNotify = 1;
1034 pring = &psli->ring[ring];
1035 mb->un.varCfgRing.numMask = pring->num_mask;
1036 mb->mbxCommand = MBX_CONFIG_RING;
1037 mb->mbxOwner = OWN_HOST;
1039 /* Is this ring configured for a specific profile */
1040 if (pring->prt[0].profile) {
1041 mb->un.varCfgRing.profile = pring->prt[0].profile;
1045 /* Otherwise we setup specific rctl / type masks for this ring */
1046 for (i = 0; i < pring->num_mask; i++) {
1047 mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
1048 if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ)
1049 mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
1051 mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
1052 mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
1053 mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
1060 * lpfc_config_port: Prepare a mailbox command for configuring port.
1061 * @phba: pointer to lpfc hba data structure.
1062 * @pmb: pointer to the driver internal queue element for mailbox command.
1064 * The configure port mailbox command is used to identify the Port Control
1065 * Block (PCB) in the driver memory. After this command is issued, the
1066 * driver must not access the mailbox in the HBA without first resetting
1067 * the HBA. The HBA may copy the PCB information to internal storage for
1068 * subsequent use; the driver can not change the PCB information unless it
1071 * This routine prepares the mailbox command for configuring port.
1074 lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1076 MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
1077 MAILBOX_t *mb = &pmb->mb;
1078 dma_addr_t pdma_addr;
1079 uint32_t bar_low, bar_high;
1081 struct lpfc_hgp hgp;
1083 uint32_t pgp_offset;
1085 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1086 mb->mbxCommand = MBX_CONFIG_PORT;
1087 mb->mbxOwner = OWN_HOST;
1089 mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
1091 offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
1092 pdma_addr = phba->slim2p.phys + offset;
1093 mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
1094 mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
1096 /* Always Host Group Pointer is in SLIM */
1097 mb->un.varCfgPort.hps = 1;
1099 /* If HBA supports SLI=3 ask for it */
1101 if (phba->sli_rev == 3 && phba->vpd.sli3Feat.cerbm) {
1102 if (phba->cfg_enable_bg)
1103 mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
1104 mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
1105 mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
1106 mb->un.varCfgPort.cinb = 1; /* Interrupt Notification Block */
1107 mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
1108 if (phba->max_vpi && phba->cfg_enable_npiv &&
1109 phba->vpd.sli3Feat.cmv) {
1110 mb->un.varCfgPort.max_vpi = phba->max_vpi;
1111 mb->un.varCfgPort.cmv = 1;
1113 mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
1116 mb->un.varCfgPort.sli_mode = phba->sli_rev;
1119 phba->pcb->type = TYPE_NATIVE_SLI2;
1120 phba->pcb->feature = FEATURE_INITIAL_SLI2;
1122 /* Setup Mailbox pointers */
1123 phba->pcb->mailBoxSize = sizeof(MAILBOX_t);
1124 offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
1125 pdma_addr = phba->slim2p.phys + offset;
1126 phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
1127 phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
1130 * Setup Host Group ring pointer.
1132 * For efficiency reasons, the ring get/put pointers can be
1133 * placed in adapter memory (SLIM) rather than in host memory.
1134 * This allows firmware to avoid PCI reads/writes when updating
1135 * and checking pointers.
1137 * The firmware recognizes the use of SLIM memory by comparing
1138 * the address of the get/put pointers structure with that of
1139 * the SLIM BAR (BAR0).
1141 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1142 * (the hardware's view of the base address), not the OS's
1143 * value of pci_resource_start() as the OS value may be a cookie
1144 * for ioremap/iomap.
1148 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
1149 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
1152 * Set up HGP - Port Memory
1154 * The port expects the host get/put pointers to reside in memory
1155 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1156 * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
1157 * words (0x40 bytes). This area is not reserved if HBQs are
1158 * configured in SLI-3.
1160 * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1169 * Reserved 0xa0-0xbf
1170 * If HBQs configured:
1171 * HBQ 0 Put ptr 0xc0
1172 * HBQ 1 Put ptr 0xc4
1173 * HBQ 2 Put ptr 0xc8
1175 * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1179 if (phba->sli_rev == 3) {
1180 phba->host_gp = &mb_slim->us.s3.host[0];
1181 phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
1183 phba->host_gp = &mb_slim->us.s2.host[0];
1184 phba->hbq_put = NULL;
1187 /* mask off BAR0's flag bits 0 - 3 */
1188 phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
1189 (void __iomem *)phba->host_gp -
1190 (void __iomem *)phba->MBslimaddr;
1191 if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
1192 phba->pcb->hgpAddrHigh = bar_high;
1194 phba->pcb->hgpAddrHigh = 0;
1195 /* write HGP data to SLIM at the required longword offset */
1196 memset(&hgp, 0, sizeof(struct lpfc_hgp));
1198 for (i=0; i < phba->sli.num_rings; i++) {
1199 lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
1200 sizeof(*phba->host_gp));
1203 /* Setup Port Group offset */
1204 if (phba->sli_rev == 3)
1205 pgp_offset = offsetof(struct lpfc_sli2_slim,
1206 mbx.us.s3_pgp.port);
1208 pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
1209 pdma_addr = phba->slim2p.phys + pgp_offset;
1210 phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
1211 phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
1213 /* Use callback routine to setp rings in the pcb */
1214 lpfc_config_pcb_setup(phba);
1216 /* special handling for LC HBAs */
1217 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
1218 uint32_t hbainit[5];
1220 lpfc_hba_init(phba, hbainit);
1222 memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
1225 /* Swap PCB if needed */
1226 lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
1230 * lpfc_kill_board: Prepare a mailbox command for killing board.
1231 * @phba: pointer to lpfc hba data structure.
1232 * @pmb: pointer to the driver internal queue element for mailbox command.
1234 * The kill board mailbox command is used to tell firmware to perform a
1235 * graceful shutdown of a channel on a specified board to prepare for reset.
1236 * When the kill board mailbox command is received, the ER3 bit is set to 1
1237 * in the Host Status register and the ER Attention bit is set to 1 in the
1238 * Host Attention register of the HBA function that received the kill board
1241 * This routine prepares the mailbox command for killing the board in
1242 * preparation for a graceful shutdown.
1245 lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1247 MAILBOX_t *mb = &pmb->mb;
1249 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1250 mb->mbxCommand = MBX_KILL_BOARD;
1251 mb->mbxOwner = OWN_HOST;
1256 * lpfc_mbox_put: Put a mailbox cmd into the tail of driver's mailbox queue.
1257 * @phba: pointer to lpfc hba data structure.
1258 * @mbq: pointer to the driver internal queue element for mailbox command.
1260 * Driver maintains a internal mailbox command queue implemented as a linked
1261 * list. When a mailbox command is issued, it shall be put into the mailbox
1262 * command queue such that they shall be processed orderly as HBA can process
1263 * one mailbox command at a time.
1266 lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1268 struct lpfc_sli *psli;
1272 list_add_tail(&mbq->list, &psli->mboxq);
1280 * lpfc_mbox_get: Remove a mailbox cmd from the head of driver's mailbox queue.
1281 * @phba: pointer to lpfc hba data structure.
1283 * Driver maintains a internal mailbox command queue implemented as a linked
1284 * list. When a mailbox command is issued, it shall be put into the mailbox
1285 * command queue such that they shall be processed orderly as HBA can process
1286 * one mailbox command at a time. After HBA finished processing a mailbox
1287 * command, the driver will remove a pending mailbox command from the head of
1288 * the mailbox command queue and send to the HBA for processing.
1291 * pointer to the driver internal queue element for mailbox command.
1294 lpfc_mbox_get(struct lpfc_hba * phba)
1296 LPFC_MBOXQ_t *mbq = NULL;
1297 struct lpfc_sli *psli = &phba->sli;
1299 list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
1307 * lpfc_mbox_cmpl_put: Put mailbox command into mailbox command complete list.
1308 * @phba: pointer to lpfc hba data structure.
1309 * @mbq: pointer to the driver internal queue element for mailbox command.
1311 * This routine put the completed mailbox command into the mailbox command
1312 * complete list. This routine is called from driver interrupt handler
1313 * context.The mailbox complete list is used by the driver worker thread
1314 * to process mailbox complete callback functions outside the driver interrupt
1318 lpfc_mbox_cmpl_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1320 unsigned long iflag;
1322 /* This function expects to be called from interrupt context */
1323 spin_lock_irqsave(&phba->hbalock, iflag);
1324 list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
1325 spin_unlock_irqrestore(&phba->hbalock, iflag);
1330 * lpfc_mbox_tmo_val: Retrieve mailbox command timeout value.
1331 * @phba: pointer to lpfc hba data structure.
1332 * @cmd: mailbox command code.
1334 * This routine retrieves the proper timeout value according to the mailbox
1338 * Timeout value to be used for the given mailbox command
1341 lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
1344 case MBX_WRITE_NV: /* 0x03 */
1345 case MBX_UPDATE_CFG: /* 0x1B */
1346 case MBX_DOWN_LOAD: /* 0x1C */
1347 case MBX_DEL_LD_ENTRY: /* 0x1D */
1348 case MBX_LOAD_AREA: /* 0x81 */
1349 case MBX_WRITE_WWN: /* 0x98 */
1350 case MBX_LOAD_EXP_ROM: /* 0x9C */
1351 return LPFC_MBOX_TMO_FLASH_CMD;
1353 return LPFC_MBOX_TMO;