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_wakeup_param - Prepare 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.
84 * This function create a dump memory mailbox command to dump wake up
88 lpfc_dump_wakeup_param(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
94 /* Save context so that we can restore after memset */
97 /* Setup to dump VPD region */
98 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
99 mb
->mbxCommand
= MBX_DUMP_MEMORY
;
100 mb
->mbxOwner
= OWN_HOST
;
101 mb
->un
.varDmp
.cv
= 1;
102 mb
->un
.varDmp
.type
= DMP_NV_PARAMS
;
103 mb
->un
.varDmp
.entry_index
= 0;
104 mb
->un
.varDmp
.region_id
= WAKE_UP_PARMS_REGION_ID
;
105 mb
->un
.varDmp
.word_cnt
= WAKE_UP_PARMS_WORD_SIZE
;
106 mb
->un
.varDmp
.co
= 0;
107 mb
->un
.varDmp
.resp_offset
= 0;
113 * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
114 * @phba: pointer to lpfc hba data structure.
115 * @pmb: pointer to the driver internal queue element for mailbox command.
117 * The read NVRAM mailbox command returns the HBA's non-volatile parameters
118 * that are used as defaults when the Fibre Channel link is brought on-line.
120 * This routine prepares the mailbox command for reading information stored
121 * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
124 lpfc_read_nv(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
129 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
130 mb
->mbxCommand
= MBX_READ_NV
;
131 mb
->mbxOwner
= OWN_HOST
;
136 * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
137 * @phba: pointer to lpfc hba data structure.
138 * @pmb: pointer to the driver internal queue element for mailbox command.
139 * @ring: ring number for the asynchronous event to be configured.
141 * The asynchronous event enable mailbox command is used to enable the
142 * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
143 * specifies the default ring to which events are posted.
145 * This routine prepares the mailbox command for enabling HBA asynchronous
146 * event support on a IOCB ring.
149 lpfc_config_async(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
,
155 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
156 mb
->mbxCommand
= MBX_ASYNCEVT_ENABLE
;
157 mb
->un
.varCfgAsyncEvent
.ring
= ring
;
158 mb
->mbxOwner
= OWN_HOST
;
163 * lpfc_heart_beat - Prepare a mailbox command for heart beat
164 * @phba: pointer to lpfc hba data structure.
165 * @pmb: pointer to the driver internal queue element for mailbox command.
167 * The heart beat mailbox command is used to detect an unresponsive HBA, which
168 * is defined as any device where no error attention is sent and both mailbox
169 * and rings are not processed.
171 * This routine prepares the mailbox command for issuing a heart beat in the
172 * form of mailbox command to the HBA. The timely completion of the heart
173 * beat mailbox command indicates the health of the HBA.
176 lpfc_heart_beat(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
181 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
182 mb
->mbxCommand
= MBX_HEARTBEAT
;
183 mb
->mbxOwner
= OWN_HOST
;
188 * lpfc_read_la - Prepare a mailbox command for reading HBA link attention
189 * @phba: pointer to lpfc hba data structure.
190 * @pmb: pointer to the driver internal queue element for mailbox command.
191 * @mp: DMA buffer memory for reading the link attention information into.
193 * The read link attention mailbox command is issued to read the Link Event
194 * Attention information indicated by the HBA port when the Link Event bit
195 * of the Host Attention (HSTATT) register is set to 1. A Link Event
196 * Attention occurs based on an exception detected at the Fibre Channel link
199 * This routine prepares the mailbox command for reading HBA link attention
200 * information. A DMA memory has been set aside and address passed to the
201 * HBA through @mp for the HBA to DMA link attention information into the
202 * memory as part of the execution of the mailbox command.
205 * 0 - Success (currently always return 0)
208 lpfc_read_la(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
, struct lpfc_dmabuf
*mp
)
211 struct lpfc_sli
*psli
;
215 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
217 INIT_LIST_HEAD(&mp
->list
);
218 mb
->mbxCommand
= MBX_READ_LA64
;
219 mb
->un
.varReadLA
.un
.lilpBde64
.tus
.f
.bdeSize
= 128;
220 mb
->un
.varReadLA
.un
.lilpBde64
.addrHigh
= putPaddrHigh(mp
->phys
);
221 mb
->un
.varReadLA
.un
.lilpBde64
.addrLow
= putPaddrLow(mp
->phys
);
223 /* Save address for later completion and set the owner to host so that
224 * the FW knows this mailbox is available for processing.
226 pmb
->context1
= (uint8_t *) mp
;
227 mb
->mbxOwner
= OWN_HOST
;
232 * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
233 * @phba: pointer to lpfc hba data structure.
234 * @pmb: pointer to the driver internal queue element for mailbox command.
236 * The clear link attention mailbox command is issued to clear the link event
237 * attention condition indicated by the Link Event bit of the Host Attention
238 * (HSTATT) register. The link event attention condition is cleared only if
239 * the event tag specified matches that of the current link event counter.
240 * The current event tag is read using the read link attention event mailbox
243 * This routine prepares the mailbox command for clearing HBA link attention
247 lpfc_clear_la(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
252 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
254 mb
->un
.varClearLA
.eventTag
= phba
->fc_eventTag
;
255 mb
->mbxCommand
= MBX_CLEAR_LA
;
256 mb
->mbxOwner
= OWN_HOST
;
261 * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
262 * @phba: pointer to lpfc hba data structure.
263 * @pmb: pointer to the driver internal queue element for mailbox command.
265 * The configure link mailbox command is used before the initialize link
266 * mailbox command to override default value and to configure link-oriented
267 * parameters such as DID address and various timers. Typically, this
268 * command would be used after an F_Port login to set the returned DID address
269 * and the fabric timeout values. This command is not valid before a configure
270 * port command has configured the HBA port.
272 * This routine prepares the mailbox command for configuring link on a HBA.
275 lpfc_config_link(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
277 struct lpfc_vport
*vport
= phba
->pport
;
278 MAILBOX_t
*mb
= &pmb
->mb
;
279 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
282 * SLI-2, Coalescing Response Feature.
284 if (phba
->cfg_cr_delay
) {
285 mb
->un
.varCfgLnk
.cr
= 1;
286 mb
->un
.varCfgLnk
.ci
= 1;
287 mb
->un
.varCfgLnk
.cr_delay
= phba
->cfg_cr_delay
;
288 mb
->un
.varCfgLnk
.cr_count
= phba
->cfg_cr_count
;
291 mb
->un
.varCfgLnk
.myId
= vport
->fc_myDID
;
292 mb
->un
.varCfgLnk
.edtov
= phba
->fc_edtov
;
293 mb
->un
.varCfgLnk
.arbtov
= phba
->fc_arbtov
;
294 mb
->un
.varCfgLnk
.ratov
= phba
->fc_ratov
;
295 mb
->un
.varCfgLnk
.rttov
= phba
->fc_rttov
;
296 mb
->un
.varCfgLnk
.altov
= phba
->fc_altov
;
297 mb
->un
.varCfgLnk
.crtov
= phba
->fc_crtov
;
298 mb
->un
.varCfgLnk
.citov
= phba
->fc_citov
;
301 mb
->un
.varCfgLnk
.ack0_enable
= 1;
303 mb
->mbxCommand
= MBX_CONFIG_LINK
;
304 mb
->mbxOwner
= OWN_HOST
;
309 * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
310 * @phba: pointer to lpfc hba data structure.
311 * @pmb: pointer to the driver internal queue element for mailbox command.
313 * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
314 * MSI-X multi-message interrupt vector association to interrupt attention
322 lpfc_config_msi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
324 MAILBOX_t
*mb
= &pmb
->mb
;
325 uint32_t attentionConditions
[2];
328 if (phba
->cfg_use_msi
!= 2) {
329 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
330 "0475 Not configured for supporting MSI-X "
331 "cfg_use_msi: 0x%x\n", phba
->cfg_use_msi
);
335 if (phba
->sli_rev
< 3) {
336 lpfc_printf_log(phba
, KERN_ERR
, LOG_INIT
,
337 "0476 HBA not supporting SLI-3 or later "
338 "SLI Revision: 0x%x\n", phba
->sli_rev
);
342 /* Clear mailbox command fields */
343 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
346 * SLI-3, Message Signaled Interrupt Fearure.
349 /* Multi-message attention configuration */
350 attentionConditions
[0] = (HA_R0ATT
| HA_R1ATT
| HA_R2ATT
| HA_ERATT
|
352 attentionConditions
[1] = 0;
354 mb
->un
.varCfgMSI
.attentionConditions
[0] = attentionConditions
[0];
355 mb
->un
.varCfgMSI
.attentionConditions
[1] = attentionConditions
[1];
358 * Set up message number to HA bit association
360 #ifdef __BIG_ENDIAN_BITFIELD
362 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R0_POS
] = 1;
363 /* RA1 (Other Protocol Extra Ring) */
364 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R1_POS
] = 1;
365 #else /* __LITTLE_ENDIAN_BITFIELD */
367 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R0_POS
^3] = 1;
368 /* RA1 (Other Protocol Extra Ring) */
369 mb
->un
.varCfgMSI
.messageNumberByHA
[HA_R1_POS
^3] = 1;
371 /* Multi-message interrupt autoclear configuration*/
372 mb
->un
.varCfgMSI
.autoClearHA
[0] = attentionConditions
[0];
373 mb
->un
.varCfgMSI
.autoClearHA
[1] = attentionConditions
[1];
375 /* For now, HBA autoclear does not work reliably, disable it */
376 mb
->un
.varCfgMSI
.autoClearHA
[0] = 0;
377 mb
->un
.varCfgMSI
.autoClearHA
[1] = 0;
379 /* Set command and owner bit */
380 mb
->mbxCommand
= MBX_CONFIG_MSI
;
381 mb
->mbxOwner
= OWN_HOST
;
387 * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
388 * @phba: pointer to lpfc hba data structure.
389 * @pmb: pointer to the driver internal queue element for mailbox command.
390 * @topology: the link topology for the link to be initialized to.
391 * @linkspeed: the link speed for the link to be initialized to.
393 * The initialize link mailbox command is used to initialize the Fibre
394 * Channel link. This command must follow a configure port command that
395 * establishes the mode of operation.
397 * This routine prepares the mailbox command for initializing link on a HBA
398 * with the specified link topology and speed.
401 lpfc_init_link(struct lpfc_hba
* phba
,
402 LPFC_MBOXQ_t
* pmb
, uint32_t topology
, uint32_t linkspeed
)
405 struct lpfc_sli
*psli
;
409 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
413 case FLAGS_TOPOLOGY_MODE_LOOP_PT
:
414 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_LOOP
;
415 mb
->un
.varInitLnk
.link_flags
|= FLAGS_TOPOLOGY_FAILOVER
;
417 case FLAGS_TOPOLOGY_MODE_PT_PT
:
418 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_PT_PT
;
420 case FLAGS_TOPOLOGY_MODE_LOOP
:
421 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_LOOP
;
423 case FLAGS_TOPOLOGY_MODE_PT_LOOP
:
424 mb
->un
.varInitLnk
.link_flags
= FLAGS_TOPOLOGY_MODE_PT_PT
;
425 mb
->un
.varInitLnk
.link_flags
|= FLAGS_TOPOLOGY_FAILOVER
;
428 mb
->un
.varInitLnk
.link_flags
= FLAGS_LOCAL_LB
;
432 /* Enable asynchronous ABTS responses from firmware */
433 mb
->un
.varInitLnk
.link_flags
|= FLAGS_IMED_ABORT
;
436 * Setting up the link speed
439 if (vpd
->rev
.feaLevelHigh
>= 0x02){
445 mb
->un
.varInitLnk
.link_flags
|=
447 mb
->un
.varInitLnk
.link_speed
= linkspeed
;
449 case LINK_SPEED_AUTO
:
451 mb
->un
.varInitLnk
.link_speed
=
458 mb
->un
.varInitLnk
.link_speed
= LINK_SPEED_AUTO
;
460 mb
->mbxCommand
= (volatile uint8_t)MBX_INIT_LINK
;
461 mb
->mbxOwner
= OWN_HOST
;
462 mb
->un
.varInitLnk
.fabric_AL_PA
= phba
->fc_pref_ALPA
;
467 * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
468 * @phba: pointer to lpfc hba data structure.
469 * @pmb: pointer to the driver internal queue element for mailbox command.
470 * @vpi: virtual N_Port identifier.
472 * The read service parameter mailbox command is used to read the HBA port
473 * service parameters. The service parameters are read into the buffer
474 * specified directly by a BDE in the mailbox command. These service
475 * parameters may then be used to build the payload of an N_Port/F_POrt
476 * login request and reply (LOGI/ACC).
478 * This routine prepares the mailbox command for reading HBA port service
479 * parameters. The DMA memory is allocated in this function and the addresses
480 * are populated into the mailbox command for the HBA to DMA the service
485 * 1 - DMA memory allocation failed
488 lpfc_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
, int vpi
)
490 struct lpfc_dmabuf
*mp
;
492 struct lpfc_sli
*psli
;
496 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
498 mb
->mbxOwner
= OWN_HOST
;
500 /* Get a buffer to hold the HBAs Service Parameters */
502 mp
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
504 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
505 if (!mp
|| !mp
->virt
) {
507 mb
->mbxCommand
= MBX_READ_SPARM64
;
508 /* READ_SPARAM: no buffers */
509 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
510 "0301 READ_SPARAM: no buffers\n");
513 INIT_LIST_HEAD(&mp
->list
);
514 mb
->mbxCommand
= MBX_READ_SPARM64
;
515 mb
->un
.varRdSparm
.un
.sp64
.tus
.f
.bdeSize
= sizeof (struct serv_parm
);
516 mb
->un
.varRdSparm
.un
.sp64
.addrHigh
= putPaddrHigh(mp
->phys
);
517 mb
->un
.varRdSparm
.un
.sp64
.addrLow
= putPaddrLow(mp
->phys
);
518 mb
->un
.varRdSparm
.vpi
= vpi
;
520 /* save address for completion */
527 * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
528 * @phba: pointer to lpfc hba data structure.
529 * @vpi: virtual N_Port identifier.
530 * @did: remote port identifier.
531 * @pmb: pointer to the driver internal queue element for mailbox command.
533 * The unregister DID mailbox command is used to unregister an N_Port/F_Port
534 * login for an unknown RPI by specifying the DID of a remote port. This
535 * command frees an RPI context in the HBA port. This has the effect of
536 * performing an implicit N_Port/F_Port logout.
538 * This routine prepares the mailbox command for unregistering a remote
539 * N_Port/F_Port (DID) login.
542 lpfc_unreg_did(struct lpfc_hba
* phba
, uint16_t vpi
, uint32_t did
,
548 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
550 mb
->un
.varUnregDID
.did
= did
;
551 mb
->un
.varUnregDID
.vpi
= vpi
;
553 mb
->mbxCommand
= MBX_UNREG_D_ID
;
554 mb
->mbxOwner
= OWN_HOST
;
559 * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
560 * @phba: pointer to lpfc hba data structure.
561 * @pmb: pointer to the driver internal queue element for mailbox command.
563 * The read configuration mailbox command is used to read the HBA port
564 * configuration parameters. This mailbox command provides a method for
565 * seeing any parameters that may have changed via various configuration
568 * This routine prepares the mailbox command for reading out HBA configuration
572 lpfc_read_config(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
577 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
579 mb
->mbxCommand
= MBX_READ_CONFIG
;
580 mb
->mbxOwner
= OWN_HOST
;
585 * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
586 * @phba: pointer to lpfc hba data structure.
587 * @pmb: pointer to the driver internal queue element for mailbox command.
589 * The read link status mailbox command is used to read the link status from
590 * the HBA. Link status includes all link-related error counters. These
591 * counters are maintained by the HBA and originated in the link hardware
592 * unit. Note that all of these counters wrap.
594 * This routine prepares the mailbox command for reading out HBA link status.
597 lpfc_read_lnk_stat(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
602 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
604 mb
->mbxCommand
= MBX_READ_LNK_STAT
;
605 mb
->mbxOwner
= OWN_HOST
;
610 * lpfc_reg_login - Prepare a mailbox command for registering remote login
611 * @phba: pointer to lpfc hba data structure.
612 * @vpi: virtual N_Port identifier.
613 * @did: remote port identifier.
614 * @param: pointer to memory holding the server parameters.
615 * @pmb: pointer to the driver internal queue element for mailbox command.
616 * @flag: action flag to be passed back for the complete function.
618 * The registration login mailbox command is used to register an N_Port or
619 * F_Port login. This registration allows the HBA to cache the remote N_Port
620 * service parameters internally and thereby make the appropriate FC-2
621 * decisions. The remote port service parameters are handed off by the driver
622 * to the HBA using a descriptor entry that directly identifies a buffer in
623 * host memory. In exchange, the HBA returns an RPI identifier.
625 * This routine prepares the mailbox command for registering remote port login.
626 * The function allocates DMA buffer for passing the service parameters to the
627 * HBA with the mailbox command.
631 * 1 - DMA memory allocation failed
634 lpfc_reg_login(struct lpfc_hba
*phba
, uint16_t vpi
, uint32_t did
,
635 uint8_t *param
, LPFC_MBOXQ_t
*pmb
, uint32_t flag
)
637 MAILBOX_t
*mb
= &pmb
->mb
;
639 struct lpfc_dmabuf
*mp
;
641 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
643 mb
->un
.varRegLogin
.rpi
= 0;
644 mb
->un
.varRegLogin
.vpi
= vpi
;
645 mb
->un
.varRegLogin
.did
= did
;
646 mb
->un
.varWords
[30] = flag
; /* Set flag to issue action on cmpl */
648 mb
->mbxOwner
= OWN_HOST
;
650 /* Get a buffer to hold NPorts Service Parameters */
651 mp
= kmalloc(sizeof (struct lpfc_dmabuf
), GFP_KERNEL
);
653 mp
->virt
= lpfc_mbuf_alloc(phba
, 0, &mp
->phys
);
654 if (!mp
|| !mp
->virt
) {
656 mb
->mbxCommand
= MBX_REG_LOGIN64
;
657 /* REG_LOGIN: no buffers */
658 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
,
659 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
660 "flag x%x\n", vpi
, did
, flag
);
663 INIT_LIST_HEAD(&mp
->list
);
666 /* Copy param's into a new buffer */
667 memcpy(sparam
, param
, sizeof (struct serv_parm
));
669 /* save address for completion */
670 pmb
->context1
= (uint8_t *) mp
;
672 mb
->mbxCommand
= MBX_REG_LOGIN64
;
673 mb
->un
.varRegLogin
.un
.sp64
.tus
.f
.bdeSize
= sizeof (struct serv_parm
);
674 mb
->un
.varRegLogin
.un
.sp64
.addrHigh
= putPaddrHigh(mp
->phys
);
675 mb
->un
.varRegLogin
.un
.sp64
.addrLow
= putPaddrLow(mp
->phys
);
681 * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
682 * @phba: pointer to lpfc hba data structure.
683 * @vpi: virtual N_Port identifier.
684 * @rpi: remote port identifier
685 * @pmb: pointer to the driver internal queue element for mailbox command.
687 * The unregistration login mailbox command is used to unregister an N_Port
688 * or F_Port login. This command frees an RPI context in the HBA. It has the
689 * effect of performing an implicit N_Port/F_Port logout.
691 * This routine prepares the mailbox command for unregistering remote port
695 lpfc_unreg_login(struct lpfc_hba
*phba
, uint16_t vpi
, uint32_t rpi
,
701 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
703 mb
->un
.varUnregLogin
.rpi
= (uint16_t) rpi
;
704 mb
->un
.varUnregLogin
.rsvd1
= 0;
705 mb
->un
.varUnregLogin
.vpi
= vpi
;
707 mb
->mbxCommand
= MBX_UNREG_LOGIN
;
708 mb
->mbxOwner
= OWN_HOST
;
713 * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
714 * @phba: pointer to lpfc hba data structure.
715 * @vpi: virtual N_Port identifier.
716 * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
717 * @pmb: pointer to the driver internal queue element for mailbox command.
719 * The registration vport identifier mailbox command is used to activate a
720 * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
721 * N_Port_ID against the information in the selected virtual N_Port context
722 * block and marks it active to allow normal processing of IOCB commands and
723 * received unsolicited exchanges.
725 * This routine prepares the mailbox command for registering a virtual N_Port.
728 lpfc_reg_vpi(struct lpfc_hba
*phba
, uint16_t vpi
, uint32_t sid
,
731 MAILBOX_t
*mb
= &pmb
->mb
;
733 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
735 mb
->un
.varRegVpi
.vpi
= vpi
;
736 mb
->un
.varRegVpi
.sid
= sid
;
738 mb
->mbxCommand
= MBX_REG_VPI
;
739 mb
->mbxOwner
= OWN_HOST
;
745 * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
746 * @phba: pointer to lpfc hba data structure.
747 * @vpi: virtual N_Port identifier.
748 * @pmb: pointer to the driver internal queue element for mailbox command.
750 * The unregistration vport identifier mailbox command is used to inactivate
751 * a virtual N_Port. The driver must have logged out and unregistered all
752 * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
753 * unregisters any default RPIs associated with the specified vpi, aborting
754 * any active exchanges. The HBA will post the mailbox response after making
755 * the virtual N_Port inactive.
757 * This routine prepares the mailbox command for unregistering a virtual
761 lpfc_unreg_vpi(struct lpfc_hba
*phba
, uint16_t vpi
, LPFC_MBOXQ_t
*pmb
)
763 MAILBOX_t
*mb
= &pmb
->mb
;
764 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
766 mb
->un
.varUnregVpi
.vpi
= vpi
;
768 mb
->mbxCommand
= MBX_UNREG_VPI
;
769 mb
->mbxOwner
= OWN_HOST
;
775 * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
776 * @phba: pointer to lpfc hba data structure.
778 * This routine sets up and initializes the IOCB rings in the Port Control
782 lpfc_config_pcb_setup(struct lpfc_hba
* phba
)
784 struct lpfc_sli
*psli
= &phba
->sli
;
785 struct lpfc_sli_ring
*pring
;
786 PCB_t
*pcbp
= phba
->pcb
;
787 dma_addr_t pdma_addr
;
789 uint32_t iocbCnt
= 0;
792 pcbp
->maxRing
= (psli
->num_rings
- 1);
794 for (i
= 0; i
< psli
->num_rings
; i
++) {
795 pring
= &psli
->ring
[i
];
797 pring
->sizeCiocb
= phba
->sli_rev
== 3 ? SLI3_IOCB_CMD_SIZE
:
799 pring
->sizeRiocb
= phba
->sli_rev
== 3 ? SLI3_IOCB_RSP_SIZE
:
801 /* A ring MUST have both cmd and rsp entries defined to be
803 if ((pring
->numCiocb
== 0) || (pring
->numRiocb
== 0)) {
804 pcbp
->rdsc
[i
].cmdEntries
= 0;
805 pcbp
->rdsc
[i
].rspEntries
= 0;
806 pcbp
->rdsc
[i
].cmdAddrHigh
= 0;
807 pcbp
->rdsc
[i
].rspAddrHigh
= 0;
808 pcbp
->rdsc
[i
].cmdAddrLow
= 0;
809 pcbp
->rdsc
[i
].rspAddrLow
= 0;
810 pring
->cmdringaddr
= NULL
;
811 pring
->rspringaddr
= NULL
;
814 /* Command ring setup for ring */
815 pring
->cmdringaddr
= (void *)&phba
->IOCBs
[iocbCnt
];
816 pcbp
->rdsc
[i
].cmdEntries
= pring
->numCiocb
;
818 offset
= (uint8_t *) &phba
->IOCBs
[iocbCnt
] -
819 (uint8_t *) phba
->slim2p
.virt
;
820 pdma_addr
= phba
->slim2p
.phys
+ offset
;
821 pcbp
->rdsc
[i
].cmdAddrHigh
= putPaddrHigh(pdma_addr
);
822 pcbp
->rdsc
[i
].cmdAddrLow
= putPaddrLow(pdma_addr
);
823 iocbCnt
+= pring
->numCiocb
;
825 /* Response ring setup for ring */
826 pring
->rspringaddr
= (void *) &phba
->IOCBs
[iocbCnt
];
828 pcbp
->rdsc
[i
].rspEntries
= pring
->numRiocb
;
829 offset
= (uint8_t *)&phba
->IOCBs
[iocbCnt
] -
830 (uint8_t *)phba
->slim2p
.virt
;
831 pdma_addr
= phba
->slim2p
.phys
+ offset
;
832 pcbp
->rdsc
[i
].rspAddrHigh
= putPaddrHigh(pdma_addr
);
833 pcbp
->rdsc
[i
].rspAddrLow
= putPaddrLow(pdma_addr
);
834 iocbCnt
+= pring
->numRiocb
;
839 * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
840 * @phba: pointer to lpfc hba data structure.
841 * @pmb: pointer to the driver internal queue element for mailbox command.
843 * The read revision mailbox command is used to read the revision levels of
844 * the HBA components. These components include hardware units, resident
845 * firmware, and available firmware. HBAs that supports SLI-3 mode of
846 * operation provide different response information depending on the version
847 * requested by the driver.
849 * This routine prepares the mailbox command for reading HBA revision
853 lpfc_read_rev(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
855 MAILBOX_t
*mb
= &pmb
->mb
;
856 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
857 mb
->un
.varRdRev
.cv
= 1;
858 mb
->un
.varRdRev
.v3req
= 1; /* Request SLI3 info */
859 mb
->mbxCommand
= MBX_READ_REV
;
860 mb
->mbxOwner
= OWN_HOST
;
865 * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
866 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
867 * @hbq_desc: pointer to the HBQ selection profile descriptor.
869 * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
870 * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
871 * the Sequence Length Test using the fields in the Selection Profile 2
872 * extension in words 20:31.
875 lpfc_build_hbq_profile2(struct config_hbq_var
*hbqmb
,
876 struct lpfc_hbq_init
*hbq_desc
)
878 hbqmb
->profiles
.profile2
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
879 hbqmb
->profiles
.profile2
.maxlen
= hbq_desc
->maxlen
;
880 hbqmb
->profiles
.profile2
.seqlenoff
= hbq_desc
->seqlenoff
;
884 * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
885 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
886 * @hbq_desc: pointer to the HBQ selection profile descriptor.
888 * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
889 * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
890 * the Sequence Length Test and Byte Field Test using the fields in the
891 * Selection Profile 3 extension in words 20:31.
894 lpfc_build_hbq_profile3(struct config_hbq_var
*hbqmb
,
895 struct lpfc_hbq_init
*hbq_desc
)
897 hbqmb
->profiles
.profile3
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
898 hbqmb
->profiles
.profile3
.maxlen
= hbq_desc
->maxlen
;
899 hbqmb
->profiles
.profile3
.cmdcodeoff
= hbq_desc
->cmdcodeoff
;
900 hbqmb
->profiles
.profile3
.seqlenoff
= hbq_desc
->seqlenoff
;
901 memcpy(&hbqmb
->profiles
.profile3
.cmdmatch
, hbq_desc
->cmdmatch
,
902 sizeof(hbqmb
->profiles
.profile3
.cmdmatch
));
906 * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
907 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
908 * @hbq_desc: pointer to the HBQ selection profile descriptor.
910 * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
911 * HBA tests the initial frame of an incoming sequence using the frame's
912 * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
913 * and Byte Field Test using the fields in the Selection Profile 5 extension
917 lpfc_build_hbq_profile5(struct config_hbq_var
*hbqmb
,
918 struct lpfc_hbq_init
*hbq_desc
)
920 hbqmb
->profiles
.profile5
.seqlenbcnt
= hbq_desc
->seqlenbcnt
;
921 hbqmb
->profiles
.profile5
.maxlen
= hbq_desc
->maxlen
;
922 hbqmb
->profiles
.profile5
.cmdcodeoff
= hbq_desc
->cmdcodeoff
;
923 hbqmb
->profiles
.profile5
.seqlenoff
= hbq_desc
->seqlenoff
;
924 memcpy(&hbqmb
->profiles
.profile5
.cmdmatch
, hbq_desc
->cmdmatch
,
925 sizeof(hbqmb
->profiles
.profile5
.cmdmatch
));
929 * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
930 * @phba: pointer to lpfc hba data structure.
931 * @id: HBQ identifier.
932 * @hbq_desc: pointer to the HBA descriptor data structure.
933 * @hbq_entry_index: index of the HBQ entry data structures.
934 * @pmb: pointer to the driver internal queue element for mailbox command.
936 * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
937 * an HBQ. The configuration binds events that require buffers to a particular
938 * ring and HBQ based on a selection profile.
940 * This routine prepares the mailbox command for configuring an HBQ.
943 lpfc_config_hbq(struct lpfc_hba
*phba
, uint32_t id
,
944 struct lpfc_hbq_init
*hbq_desc
,
945 uint32_t hbq_entry_index
, LPFC_MBOXQ_t
*pmb
)
948 MAILBOX_t
*mb
= &pmb
->mb
;
949 struct config_hbq_var
*hbqmb
= &mb
->un
.varCfgHbq
;
951 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
953 hbqmb
->entry_count
= hbq_desc
->entry_count
; /* # entries in HBQ */
954 hbqmb
->recvNotify
= hbq_desc
->rn
; /* Receive
956 hbqmb
->numMask
= hbq_desc
->mask_count
; /* # R_CTL/TYPE masks
958 hbqmb
->profile
= hbq_desc
->profile
; /* Selection profile:
961 hbqmb
->ringMask
= hbq_desc
->ring_mask
; /* Binds HBQ to a ring
964 hbqmb
->headerLen
= hbq_desc
->headerLen
; /* 0 if not profile 4
966 hbqmb
->logEntry
= hbq_desc
->logEntry
; /* Set to 1 if this
970 hbqmb
->hbqaddrLow
= putPaddrLow(phba
->hbqslimp
.phys
) +
971 hbq_entry_index
* sizeof(struct lpfc_hbq_entry
);
972 hbqmb
->hbqaddrHigh
= putPaddrHigh(phba
->hbqslimp
.phys
);
974 mb
->mbxCommand
= MBX_CONFIG_HBQ
;
975 mb
->mbxOwner
= OWN_HOST
;
977 /* Copy info for profiles 2,3,5. Other
978 * profiles this area is reserved
980 if (hbq_desc
->profile
== 2)
981 lpfc_build_hbq_profile2(hbqmb
, hbq_desc
);
982 else if (hbq_desc
->profile
== 3)
983 lpfc_build_hbq_profile3(hbqmb
, hbq_desc
);
984 else if (hbq_desc
->profile
== 5)
985 lpfc_build_hbq_profile5(hbqmb
, hbq_desc
);
987 /* Return if no rctl / type masks for this HBQ */
988 if (!hbq_desc
->mask_count
)
991 /* Otherwise we setup specific rctl / type masks for this HBQ */
992 for (i
= 0; i
< hbq_desc
->mask_count
; i
++) {
993 hbqmb
->hbqMasks
[i
].tmatch
= hbq_desc
->hbqMasks
[i
].tmatch
;
994 hbqmb
->hbqMasks
[i
].tmask
= hbq_desc
->hbqMasks
[i
].tmask
;
995 hbqmb
->hbqMasks
[i
].rctlmatch
= hbq_desc
->hbqMasks
[i
].rctlmatch
;
996 hbqmb
->hbqMasks
[i
].rctlmask
= hbq_desc
->hbqMasks
[i
].rctlmask
;
1003 * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
1004 * @phba: pointer to lpfc hba data structure.
1006 * @pmb: pointer to the driver internal queue element for mailbox command.
1008 * The configure ring mailbox command is used to configure an IOCB ring. This
1009 * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1010 * ring. This is used to map incoming sequences to a particular ring whose
1011 * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1012 * attempt to configure a ring whose number is greater than the number
1013 * specified in the Port Control Block (PCB). It is an error to issue the
1014 * configure ring command more than once with the same ring number. The HBA
1015 * returns an error if the driver attempts this.
1017 * This routine prepares the mailbox command for configuring IOCB ring.
1020 lpfc_config_ring(struct lpfc_hba
* phba
, int ring
, LPFC_MBOXQ_t
* pmb
)
1023 MAILBOX_t
*mb
= &pmb
->mb
;
1024 struct lpfc_sli
*psli
;
1025 struct lpfc_sli_ring
*pring
;
1027 memset(pmb
, 0, sizeof (LPFC_MBOXQ_t
));
1029 mb
->un
.varCfgRing
.ring
= ring
;
1030 mb
->un
.varCfgRing
.maxOrigXchg
= 0;
1031 mb
->un
.varCfgRing
.maxRespXchg
= 0;
1032 mb
->un
.varCfgRing
.recvNotify
= 1;
1035 pring
= &psli
->ring
[ring
];
1036 mb
->un
.varCfgRing
.numMask
= pring
->num_mask
;
1037 mb
->mbxCommand
= MBX_CONFIG_RING
;
1038 mb
->mbxOwner
= OWN_HOST
;
1040 /* Is this ring configured for a specific profile */
1041 if (pring
->prt
[0].profile
) {
1042 mb
->un
.varCfgRing
.profile
= pring
->prt
[0].profile
;
1046 /* Otherwise we setup specific rctl / type masks for this ring */
1047 for (i
= 0; i
< pring
->num_mask
; i
++) {
1048 mb
->un
.varCfgRing
.rrRegs
[i
].rval
= pring
->prt
[i
].rctl
;
1049 if (mb
->un
.varCfgRing
.rrRegs
[i
].rval
!= FC_ELS_REQ
)
1050 mb
->un
.varCfgRing
.rrRegs
[i
].rmask
= 0xff;
1052 mb
->un
.varCfgRing
.rrRegs
[i
].rmask
= 0xfe;
1053 mb
->un
.varCfgRing
.rrRegs
[i
].tval
= pring
->prt
[i
].type
;
1054 mb
->un
.varCfgRing
.rrRegs
[i
].tmask
= 0xff;
1061 * lpfc_config_port - Prepare a mailbox command for configuring port
1062 * @phba: pointer to lpfc hba data structure.
1063 * @pmb: pointer to the driver internal queue element for mailbox command.
1065 * The configure port mailbox command is used to identify the Port Control
1066 * Block (PCB) in the driver memory. After this command is issued, the
1067 * driver must not access the mailbox in the HBA without first resetting
1068 * the HBA. The HBA may copy the PCB information to internal storage for
1069 * subsequent use; the driver can not change the PCB information unless it
1072 * This routine prepares the mailbox command for configuring port.
1075 lpfc_config_port(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1077 MAILBOX_t __iomem
*mb_slim
= (MAILBOX_t __iomem
*) phba
->MBslimaddr
;
1078 MAILBOX_t
*mb
= &pmb
->mb
;
1079 dma_addr_t pdma_addr
;
1080 uint32_t bar_low
, bar_high
;
1082 struct lpfc_hgp hgp
;
1084 uint32_t pgp_offset
;
1086 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
1087 mb
->mbxCommand
= MBX_CONFIG_PORT
;
1088 mb
->mbxOwner
= OWN_HOST
;
1090 mb
->un
.varCfgPort
.pcbLen
= sizeof(PCB_t
);
1092 offset
= (uint8_t *)phba
->pcb
- (uint8_t *)phba
->slim2p
.virt
;
1093 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1094 mb
->un
.varCfgPort
.pcbLow
= putPaddrLow(pdma_addr
);
1095 mb
->un
.varCfgPort
.pcbHigh
= putPaddrHigh(pdma_addr
);
1097 /* Always Host Group Pointer is in SLIM */
1098 mb
->un
.varCfgPort
.hps
= 1;
1100 /* If HBA supports SLI=3 ask for it */
1102 if (phba
->sli_rev
== 3 && phba
->vpd
.sli3Feat
.cerbm
) {
1103 if (phba
->cfg_enable_bg
)
1104 mb
->un
.varCfgPort
.cbg
= 1; /* configure BlockGuard */
1105 mb
->un
.varCfgPort
.cerbm
= 1; /* Request HBQs */
1106 mb
->un
.varCfgPort
.ccrp
= 1; /* Command Ring Polling */
1107 mb
->un
.varCfgPort
.cinb
= 1; /* Interrupt Notification Block */
1108 mb
->un
.varCfgPort
.max_hbq
= lpfc_sli_hbq_count();
1109 if (phba
->max_vpi
&& phba
->cfg_enable_npiv
&&
1110 phba
->vpd
.sli3Feat
.cmv
) {
1111 mb
->un
.varCfgPort
.max_vpi
= phba
->max_vpi
;
1112 mb
->un
.varCfgPort
.cmv
= 1;
1114 mb
->un
.varCfgPort
.max_vpi
= phba
->max_vpi
= 0;
1117 mb
->un
.varCfgPort
.sli_mode
= phba
->sli_rev
;
1120 phba
->pcb
->type
= TYPE_NATIVE_SLI2
;
1121 phba
->pcb
->feature
= FEATURE_INITIAL_SLI2
;
1123 /* Setup Mailbox pointers */
1124 phba
->pcb
->mailBoxSize
= sizeof(MAILBOX_t
);
1125 offset
= (uint8_t *)phba
->mbox
- (uint8_t *)phba
->slim2p
.virt
;
1126 pdma_addr
= phba
->slim2p
.phys
+ offset
;
1127 phba
->pcb
->mbAddrHigh
= putPaddrHigh(pdma_addr
);
1128 phba
->pcb
->mbAddrLow
= putPaddrLow(pdma_addr
);
1131 * Setup Host Group ring pointer.
1133 * For efficiency reasons, the ring get/put pointers can be
1134 * placed in adapter memory (SLIM) rather than in host memory.
1135 * This allows firmware to avoid PCI reads/writes when updating
1136 * and checking pointers.
1138 * The firmware recognizes the use of SLIM memory by comparing
1139 * the address of the get/put pointers structure with that of
1140 * the SLIM BAR (BAR0).
1142 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1143 * (the hardware's view of the base address), not the OS's
1144 * value of pci_resource_start() as the OS value may be a cookie
1145 * for ioremap/iomap.
1149 pci_read_config_dword(phba
->pcidev
, PCI_BASE_ADDRESS_0
, &bar_low
);
1150 pci_read_config_dword(phba
->pcidev
, PCI_BASE_ADDRESS_1
, &bar_high
);
1153 * Set up HGP - Port Memory
1155 * The port expects the host get/put pointers to reside in memory
1156 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1157 * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
1158 * words (0x40 bytes). This area is not reserved if HBQs are
1159 * configured in SLI-3.
1161 * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1170 * Reserved 0xa0-0xbf
1171 * If HBQs configured:
1172 * HBQ 0 Put ptr 0xc0
1173 * HBQ 1 Put ptr 0xc4
1174 * HBQ 2 Put ptr 0xc8
1176 * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1180 if (phba
->sli_rev
== 3) {
1181 phba
->host_gp
= &mb_slim
->us
.s3
.host
[0];
1182 phba
->hbq_put
= &mb_slim
->us
.s3
.hbq_put
[0];
1184 phba
->host_gp
= &mb_slim
->us
.s2
.host
[0];
1185 phba
->hbq_put
= NULL
;
1188 /* mask off BAR0's flag bits 0 - 3 */
1189 phba
->pcb
->hgpAddrLow
= (bar_low
& PCI_BASE_ADDRESS_MEM_MASK
) +
1190 (void __iomem
*)phba
->host_gp
-
1191 (void __iomem
*)phba
->MBslimaddr
;
1192 if (bar_low
& PCI_BASE_ADDRESS_MEM_TYPE_64
)
1193 phba
->pcb
->hgpAddrHigh
= bar_high
;
1195 phba
->pcb
->hgpAddrHigh
= 0;
1196 /* write HGP data to SLIM at the required longword offset */
1197 memset(&hgp
, 0, sizeof(struct lpfc_hgp
));
1199 for (i
=0; i
< phba
->sli
.num_rings
; i
++) {
1200 lpfc_memcpy_to_slim(phba
->host_gp
+ i
, &hgp
,
1201 sizeof(*phba
->host_gp
));
1204 /* Setup Port Group offset */
1205 if (phba
->sli_rev
== 3)
1206 pgp_offset
= offsetof(struct lpfc_sli2_slim
,
1207 mbx
.us
.s3_pgp
.port
);
1209 pgp_offset
= offsetof(struct lpfc_sli2_slim
, mbx
.us
.s2
.port
);
1210 pdma_addr
= phba
->slim2p
.phys
+ pgp_offset
;
1211 phba
->pcb
->pgpAddrHigh
= putPaddrHigh(pdma_addr
);
1212 phba
->pcb
->pgpAddrLow
= putPaddrLow(pdma_addr
);
1214 /* Use callback routine to setp rings in the pcb */
1215 lpfc_config_pcb_setup(phba
);
1217 /* special handling for LC HBAs */
1218 if (lpfc_is_LC_HBA(phba
->pcidev
->device
)) {
1219 uint32_t hbainit
[5];
1221 lpfc_hba_init(phba
, hbainit
);
1223 memcpy(&mb
->un
.varCfgPort
.hbainit
, hbainit
, 20);
1226 /* Swap PCB if needed */
1227 lpfc_sli_pcimem_bcopy(phba
->pcb
, phba
->pcb
, sizeof(PCB_t
));
1231 * lpfc_kill_board - Prepare a mailbox command for killing board
1232 * @phba: pointer to lpfc hba data structure.
1233 * @pmb: pointer to the driver internal queue element for mailbox command.
1235 * The kill board mailbox command is used to tell firmware to perform a
1236 * graceful shutdown of a channel on a specified board to prepare for reset.
1237 * When the kill board mailbox command is received, the ER3 bit is set to 1
1238 * in the Host Status register and the ER Attention bit is set to 1 in the
1239 * Host Attention register of the HBA function that received the kill board
1242 * This routine prepares the mailbox command for killing the board in
1243 * preparation for a graceful shutdown.
1246 lpfc_kill_board(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* pmb
)
1248 MAILBOX_t
*mb
= &pmb
->mb
;
1250 memset(pmb
, 0, sizeof(LPFC_MBOXQ_t
));
1251 mb
->mbxCommand
= MBX_KILL_BOARD
;
1252 mb
->mbxOwner
= OWN_HOST
;
1257 * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
1258 * @phba: pointer to lpfc hba data structure.
1259 * @mbq: pointer to the driver internal queue element for mailbox command.
1261 * Driver maintains a internal mailbox command queue implemented as a linked
1262 * list. When a mailbox command is issued, it shall be put into the mailbox
1263 * command queue such that they shall be processed orderly as HBA can process
1264 * one mailbox command at a time.
1267 lpfc_mbox_put(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* mbq
)
1269 struct lpfc_sli
*psli
;
1273 list_add_tail(&mbq
->list
, &psli
->mboxq
);
1281 * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
1282 * @phba: pointer to lpfc hba data structure.
1284 * Driver maintains a internal mailbox command queue implemented as a linked
1285 * list. When a mailbox command is issued, it shall be put into the mailbox
1286 * command queue such that they shall be processed orderly as HBA can process
1287 * one mailbox command at a time. After HBA finished processing a mailbox
1288 * command, the driver will remove a pending mailbox command from the head of
1289 * the mailbox command queue and send to the HBA for processing.
1292 * pointer to the driver internal queue element for mailbox command.
1295 lpfc_mbox_get(struct lpfc_hba
* phba
)
1297 LPFC_MBOXQ_t
*mbq
= NULL
;
1298 struct lpfc_sli
*psli
= &phba
->sli
;
1300 list_remove_head((&psli
->mboxq
), mbq
, LPFC_MBOXQ_t
, list
);
1308 * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
1309 * @phba: pointer to lpfc hba data structure.
1310 * @mbq: pointer to the driver internal queue element for mailbox command.
1312 * This routine put the completed mailbox command into the mailbox command
1313 * complete list. This routine is called from driver interrupt handler
1314 * context.The mailbox complete list is used by the driver worker thread
1315 * to process mailbox complete callback functions outside the driver interrupt
1319 lpfc_mbox_cmpl_put(struct lpfc_hba
* phba
, LPFC_MBOXQ_t
* mbq
)
1321 unsigned long iflag
;
1323 /* This function expects to be called from interrupt context */
1324 spin_lock_irqsave(&phba
->hbalock
, iflag
);
1325 list_add_tail(&mbq
->list
, &phba
->sli
.mboxq_cmpl
);
1326 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
1331 * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
1332 * @phba: pointer to lpfc hba data structure.
1333 * @cmd: mailbox command code.
1335 * This routine retrieves the proper timeout value according to the mailbox
1339 * Timeout value to be used for the given mailbox command
1342 lpfc_mbox_tmo_val(struct lpfc_hba
*phba
, int cmd
)
1345 case MBX_WRITE_NV
: /* 0x03 */
1346 case MBX_UPDATE_CFG
: /* 0x1B */
1347 case MBX_DOWN_LOAD
: /* 0x1C */
1348 case MBX_DEL_LD_ENTRY
: /* 0x1D */
1349 case MBX_LOAD_AREA
: /* 0x81 */
1350 case MBX_WRITE_WWN
: /* 0x98 */
1351 case MBX_LOAD_EXP_ROM
: /* 0x9C */
1352 return LPFC_MBOX_TMO_FLASH_CMD
;
1354 return LPFC_MBOX_TMO
;