Merge branch 'drm-core-next' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied...
[sfrench/cifs-2.6.git] / drivers / scsi / lpfc / lpfc_mbox.c
1 /*******************************************************************
2  * This file is part of the Emulex Linux Device Driver for         *
3  * Fibre Channel Host Bus Adapters.                                *
4  * Copyright (C) 2004-2009 Emulex.  All rights reserved.           *
5  * EMULEX and SLI are trademarks of Emulex.                        *
6  * www.emulex.com                                                  *
7  * Portions Copyright (C) 2004-2005 Christoph Hellwig              *
8  *                                                                 *
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  *******************************************************************/
21
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
26
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_transport_fc.h>
29 #include <scsi/scsi.h>
30 #include <scsi/fc/fc_fs.h>
31
32 #include "lpfc_hw4.h"
33 #include "lpfc_hw.h"
34 #include "lpfc_sli.h"
35 #include "lpfc_sli4.h"
36 #include "lpfc_nl.h"
37 #include "lpfc_disc.h"
38 #include "lpfc_scsi.h"
39 #include "lpfc.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_compat.h"
43
44 /**
45  * lpfc_dump_static_vport - Dump HBA's static vport information.
46  * @phba: pointer to lpfc hba data structure.
47  * @pmb: pointer to the driver internal queue element for mailbox command.
48  * @offset: offset for dumping vport info.
49  *
50  * The dump mailbox command provides a method for the device driver to obtain
51  * various types of information from the HBA device.
52  *
53  * This routine prepares the mailbox command for dumping list of static
54  * vports to be created.
55  **/
56 int
57 lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb,
58                 uint16_t offset)
59 {
60         MAILBOX_t *mb;
61         struct lpfc_dmabuf *mp;
62
63         mb = &pmb->u.mb;
64
65         /* Setup to dump vport info region */
66         memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
67         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_VPORT;
71         mb->mbxOwner = OWN_HOST;
72
73         /* For SLI3 HBAs data is embedded in mailbox */
74         if (phba->sli_rev != LPFC_SLI_REV4) {
75                 mb->un.varDmp.cv = 1;
76                 mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t);
77                 return 0;
78         }
79
80         /* For SLI4 HBAs driver need to allocate memory */
81         mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
82         if (mp)
83                 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
84
85         if (!mp || !mp->virt) {
86                 kfree(mp);
87                 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
88                         "2605 lpfc_dump_static_vport: memory"
89                         " allocation failed\n");
90                 return 1;
91         }
92         memset(mp->virt, 0, LPFC_BPL_SIZE);
93         INIT_LIST_HEAD(&mp->list);
94         /* save address for completion */
95         pmb->context2 = (uint8_t *) mp;
96         mb->un.varWords[3] = putPaddrLow(mp->phys);
97         mb->un.varWords[4] = putPaddrHigh(mp->phys);
98         mb->un.varDmp.sli4_length = sizeof(struct static_vport_info);
99
100         return 0;
101 }
102
103 /**
104  * lpfc_down_link - Bring down HBAs link.
105  * @phba: pointer to lpfc hba data structure.
106  * @pmb: pointer to the driver internal queue element for mailbox command.
107  *
108  * This routine prepares a mailbox command to bring down HBA link.
109  **/
110 void
111 lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
112 {
113         MAILBOX_t *mb;
114         memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
115         mb = &pmb->u.mb;
116         mb->mbxCommand = MBX_DOWN_LINK;
117         mb->mbxOwner = OWN_HOST;
118 }
119
120 /**
121  * lpfc_dump_mem - Prepare a mailbox command for reading a region.
122  * @phba: pointer to lpfc hba data structure.
123  * @pmb: pointer to the driver internal queue element for mailbox command.
124  * @offset: offset into the region.
125  * @region_id: config region id.
126  *
127  * The dump mailbox command provides a method for the device driver to obtain
128  * various types of information from the HBA device.
129  *
130  * This routine prepares the mailbox command for dumping HBA's config region.
131  **/
132 void
133 lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset,
134                 uint16_t region_id)
135 {
136         MAILBOX_t *mb;
137         void *ctx;
138
139         mb = &pmb->u.mb;
140         ctx = pmb->context2;
141
142         /* Setup to dump VPD region */
143         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
144         mb->mbxCommand = MBX_DUMP_MEMORY;
145         mb->un.varDmp.cv = 1;
146         mb->un.varDmp.type = DMP_NV_PARAMS;
147         mb->un.varDmp.entry_index = offset;
148         mb->un.varDmp.region_id = region_id;
149         mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
150         mb->un.varDmp.co = 0;
151         mb->un.varDmp.resp_offset = 0;
152         pmb->context2 = ctx;
153         mb->mbxOwner = OWN_HOST;
154         return;
155 }
156
157 /**
158  * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
159  * @phba: pointer to lpfc hba data structure.
160  * @pmb: pointer to the driver internal queue element for mailbox command.
161  *
162  * This function create a dump memory mailbox command to dump wake up
163  * parameters.
164  */
165 void
166 lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
167 {
168         MAILBOX_t *mb;
169         void *ctx;
170
171         mb = &pmb->u.mb;
172         /* Save context so that we can restore after memset */
173         ctx = pmb->context2;
174
175         /* Setup to dump VPD region */
176         memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
177         mb->mbxCommand = MBX_DUMP_MEMORY;
178         mb->mbxOwner = OWN_HOST;
179         mb->un.varDmp.cv = 1;
180         mb->un.varDmp.type = DMP_NV_PARAMS;
181         mb->un.varDmp.entry_index = 0;
182         mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
183         mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
184         mb->un.varDmp.co = 0;
185         mb->un.varDmp.resp_offset = 0;
186         pmb->context2 = ctx;
187         return;
188 }
189
190 /**
191  * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
192  * @phba: pointer to lpfc hba data structure.
193  * @pmb: pointer to the driver internal queue element for mailbox command.
194  *
195  * The read NVRAM mailbox command returns the HBA's non-volatile parameters
196  * that are used as defaults when the Fibre Channel link is brought on-line.
197  *
198  * This routine prepares the mailbox command for reading information stored
199  * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
200  **/
201 void
202 lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
203 {
204         MAILBOX_t *mb;
205
206         mb = &pmb->u.mb;
207         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
208         mb->mbxCommand = MBX_READ_NV;
209         mb->mbxOwner = OWN_HOST;
210         return;
211 }
212
213 /**
214  * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
215  * @phba: pointer to lpfc hba data structure.
216  * @pmb: pointer to the driver internal queue element for mailbox command.
217  * @ring: ring number for the asynchronous event to be configured.
218  *
219  * The asynchronous event enable mailbox command is used to enable the
220  * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
221  * specifies the default ring to which events are posted.
222  *
223  * This routine prepares the mailbox command for enabling HBA asynchronous
224  * event support on a IOCB ring.
225  **/
226 void
227 lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
228                 uint32_t ring)
229 {
230         MAILBOX_t *mb;
231
232         mb = &pmb->u.mb;
233         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
234         mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
235         mb->un.varCfgAsyncEvent.ring = ring;
236         mb->mbxOwner = OWN_HOST;
237         return;
238 }
239
240 /**
241  * lpfc_heart_beat - Prepare a mailbox command for heart beat
242  * @phba: pointer to lpfc hba data structure.
243  * @pmb: pointer to the driver internal queue element for mailbox command.
244  *
245  * The heart beat mailbox command is used to detect an unresponsive HBA, which
246  * is defined as any device where no error attention is sent and both mailbox
247  * and rings are not processed.
248  *
249  * This routine prepares the mailbox command for issuing a heart beat in the
250  * form of mailbox command to the HBA. The timely completion of the heart
251  * beat mailbox command indicates the health of the HBA.
252  **/
253 void
254 lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
255 {
256         MAILBOX_t *mb;
257
258         mb = &pmb->u.mb;
259         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
260         mb->mbxCommand = MBX_HEARTBEAT;
261         mb->mbxOwner = OWN_HOST;
262         return;
263 }
264
265 /**
266  * lpfc_read_la - Prepare a mailbox command for reading HBA link attention
267  * @phba: pointer to lpfc hba data structure.
268  * @pmb: pointer to the driver internal queue element for mailbox command.
269  * @mp: DMA buffer memory for reading the link attention information into.
270  *
271  * The read link attention mailbox command is issued to read the Link Event
272  * Attention information indicated by the HBA port when the Link Event bit
273  * of the Host Attention (HSTATT) register is set to 1. A Link Event
274  * Attention occurs based on an exception detected at the Fibre Channel link
275  * interface.
276  *
277  * This routine prepares the mailbox command for reading HBA link attention
278  * information. A DMA memory has been set aside and address passed to the
279  * HBA through @mp for the HBA to DMA link attention information into the
280  * memory as part of the execution of the mailbox command.
281  *
282  * Return codes
283  *    0 - Success (currently always return 0)
284  **/
285 int
286 lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
287 {
288         MAILBOX_t *mb;
289         struct lpfc_sli *psli;
290
291         psli = &phba->sli;
292         mb = &pmb->u.mb;
293         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
294
295         INIT_LIST_HEAD(&mp->list);
296         mb->mbxCommand = MBX_READ_LA64;
297         mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128;
298         mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
299         mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys);
300
301         /* Save address for later completion and set the owner to host so that
302          * the FW knows this mailbox is available for processing.
303          */
304         pmb->context1 = (uint8_t *) mp;
305         mb->mbxOwner = OWN_HOST;
306         return (0);
307 }
308
309 /**
310  * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
311  * @phba: pointer to lpfc hba data structure.
312  * @pmb: pointer to the driver internal queue element for mailbox command.
313  *
314  * The clear link attention mailbox command is issued to clear the link event
315  * attention condition indicated by the Link Event bit of the Host Attention
316  * (HSTATT) register. The link event attention condition is cleared only if
317  * the event tag specified matches that of the current link event counter.
318  * The current event tag is read using the read link attention event mailbox
319  * command.
320  *
321  * This routine prepares the mailbox command for clearing HBA link attention
322  * information.
323  **/
324 void
325 lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
326 {
327         MAILBOX_t *mb;
328
329         mb = &pmb->u.mb;
330         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
331
332         mb->un.varClearLA.eventTag = phba->fc_eventTag;
333         mb->mbxCommand = MBX_CLEAR_LA;
334         mb->mbxOwner = OWN_HOST;
335         return;
336 }
337
338 /**
339  * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
340  * @phba: pointer to lpfc hba data structure.
341  * @pmb: pointer to the driver internal queue element for mailbox command.
342  *
343  * The configure link mailbox command is used before the initialize link
344  * mailbox command to override default value and to configure link-oriented
345  * parameters such as DID address and various timers. Typically, this
346  * command would be used after an F_Port login to set the returned DID address
347  * and the fabric timeout values. This command is not valid before a configure
348  * port command has configured the HBA port.
349  *
350  * This routine prepares the mailbox command for configuring link on a HBA.
351  **/
352 void
353 lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
354 {
355         struct lpfc_vport  *vport = phba->pport;
356         MAILBOX_t *mb = &pmb->u.mb;
357         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
358
359         /* NEW_FEATURE
360          * SLI-2, Coalescing Response Feature.
361          */
362         if (phba->cfg_cr_delay) {
363                 mb->un.varCfgLnk.cr = 1;
364                 mb->un.varCfgLnk.ci = 1;
365                 mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
366                 mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
367         }
368
369         mb->un.varCfgLnk.myId = vport->fc_myDID;
370         mb->un.varCfgLnk.edtov = phba->fc_edtov;
371         mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
372         mb->un.varCfgLnk.ratov = phba->fc_ratov;
373         mb->un.varCfgLnk.rttov = phba->fc_rttov;
374         mb->un.varCfgLnk.altov = phba->fc_altov;
375         mb->un.varCfgLnk.crtov = phba->fc_crtov;
376         mb->un.varCfgLnk.citov = phba->fc_citov;
377
378         if (phba->cfg_ack0)
379                 mb->un.varCfgLnk.ack0_enable = 1;
380
381         mb->mbxCommand = MBX_CONFIG_LINK;
382         mb->mbxOwner = OWN_HOST;
383         return;
384 }
385
386 /**
387  * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
388  * @phba: pointer to lpfc hba data structure.
389  * @pmb: pointer to the driver internal queue element for mailbox command.
390  *
391  * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
392  * MSI-X multi-message interrupt vector association to interrupt attention
393  * conditions.
394  *
395  * Return codes
396  *    0 - Success
397  *    -EINVAL - Failure
398  **/
399 int
400 lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
401 {
402         MAILBOX_t *mb = &pmb->u.mb;
403         uint32_t attentionConditions[2];
404
405         /* Sanity check */
406         if (phba->cfg_use_msi != 2) {
407                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
408                                 "0475 Not configured for supporting MSI-X "
409                                 "cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
410                 return -EINVAL;
411         }
412
413         if (phba->sli_rev < 3) {
414                 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
415                                 "0476 HBA not supporting SLI-3 or later "
416                                 "SLI Revision: 0x%x\n", phba->sli_rev);
417                 return -EINVAL;
418         }
419
420         /* Clear mailbox command fields */
421         memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
422
423         /*
424          * SLI-3, Message Signaled Interrupt Fearure.
425          */
426
427         /* Multi-message attention configuration */
428         attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
429                                   HA_LATT | HA_MBATT);
430         attentionConditions[1] = 0;
431
432         mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
433         mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
434
435         /*
436          * Set up message number to HA bit association
437          */
438 #ifdef __BIG_ENDIAN_BITFIELD
439         /* RA0 (FCP Ring) */
440         mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
441         /* RA1 (Other Protocol Extra Ring) */
442         mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
443 #else   /*  __LITTLE_ENDIAN_BITFIELD */
444         /* RA0 (FCP Ring) */
445         mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
446         /* RA1 (Other Protocol Extra Ring) */
447         mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
448 #endif
449         /* Multi-message interrupt autoclear configuration*/
450         mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
451         mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
452
453         /* For now, HBA autoclear does not work reliably, disable it */
454         mb->un.varCfgMSI.autoClearHA[0] = 0;
455         mb->un.varCfgMSI.autoClearHA[1] = 0;
456
457         /* Set command and owner bit */
458         mb->mbxCommand = MBX_CONFIG_MSI;
459         mb->mbxOwner = OWN_HOST;
460
461         return 0;
462 }
463
464 /**
465  * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
466  * @phba: pointer to lpfc hba data structure.
467  * @pmb: pointer to the driver internal queue element for mailbox command.
468  * @topology: the link topology for the link to be initialized to.
469  * @linkspeed: the link speed for the link to be initialized to.
470  *
471  * The initialize link mailbox command is used to initialize the Fibre
472  * Channel link. This command must follow a configure port command that
473  * establishes the mode of operation.
474  *
475  * This routine prepares the mailbox command for initializing link on a HBA
476  * with the specified link topology and speed.
477  **/
478 void
479 lpfc_init_link(struct lpfc_hba * phba,
480                LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
481 {
482         lpfc_vpd_t *vpd;
483         struct lpfc_sli *psli;
484         MAILBOX_t *mb;
485
486         mb = &pmb->u.mb;
487         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
488
489         psli = &phba->sli;
490         switch (topology) {
491         case FLAGS_TOPOLOGY_MODE_LOOP_PT:
492                 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
493                 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
494                 break;
495         case FLAGS_TOPOLOGY_MODE_PT_PT:
496                 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
497                 break;
498         case FLAGS_TOPOLOGY_MODE_LOOP:
499                 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
500                 break;
501         case FLAGS_TOPOLOGY_MODE_PT_LOOP:
502                 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
503                 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
504                 break;
505         case FLAGS_LOCAL_LB:
506                 mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
507                 break;
508         }
509
510         /* Enable asynchronous ABTS responses from firmware */
511         mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
512
513         /* NEW_FEATURE
514          * Setting up the link speed
515          */
516         vpd = &phba->vpd;
517         if (vpd->rev.feaLevelHigh >= 0x02){
518                 switch(linkspeed){
519                         case LINK_SPEED_1G:
520                         case LINK_SPEED_2G:
521                         case LINK_SPEED_4G:
522                         case LINK_SPEED_8G:
523                                 mb->un.varInitLnk.link_flags |=
524                                                         FLAGS_LINK_SPEED;
525                                 mb->un.varInitLnk.link_speed = linkspeed;
526                         break;
527                         case LINK_SPEED_AUTO:
528                         default:
529                                 mb->un.varInitLnk.link_speed =
530                                                         LINK_SPEED_AUTO;
531                         break;
532                 }
533
534         }
535         else
536                 mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
537
538         mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
539         mb->mbxOwner = OWN_HOST;
540         mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
541         return;
542 }
543
544 /**
545  * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
546  * @phba: pointer to lpfc hba data structure.
547  * @pmb: pointer to the driver internal queue element for mailbox command.
548  * @vpi: virtual N_Port identifier.
549  *
550  * The read service parameter mailbox command is used to read the HBA port
551  * service parameters. The service parameters are read into the buffer
552  * specified directly by a BDE in the mailbox command. These service
553  * parameters may then be used to build the payload of an N_Port/F_POrt
554  * login request and reply (LOGI/ACC).
555  *
556  * This routine prepares the mailbox command for reading HBA port service
557  * parameters. The DMA memory is allocated in this function and the addresses
558  * are populated into the mailbox command for the HBA to DMA the service
559  * parameters into.
560  *
561  * Return codes
562  *    0 - Success
563  *    1 - DMA memory allocation failed
564  **/
565 int
566 lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
567 {
568         struct lpfc_dmabuf *mp;
569         MAILBOX_t *mb;
570         struct lpfc_sli *psli;
571
572         psli = &phba->sli;
573         mb = &pmb->u.mb;
574         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
575
576         mb->mbxOwner = OWN_HOST;
577
578         /* Get a buffer to hold the HBAs Service Parameters */
579
580         mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
581         if (mp)
582                 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
583         if (!mp || !mp->virt) {
584                 kfree(mp);
585                 mb->mbxCommand = MBX_READ_SPARM64;
586                 /* READ_SPARAM: no buffers */
587                 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
588                                 "0301 READ_SPARAM: no buffers\n");
589                 return (1);
590         }
591         INIT_LIST_HEAD(&mp->list);
592         mb->mbxCommand = MBX_READ_SPARM64;
593         mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
594         mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
595         mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
596         mb->un.varRdSparm.vpi = vpi + phba->vpi_base;
597
598         /* save address for completion */
599         pmb->context1 = mp;
600
601         return (0);
602 }
603
604 /**
605  * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
606  * @phba: pointer to lpfc hba data structure.
607  * @vpi: virtual N_Port identifier.
608  * @did: remote port identifier.
609  * @pmb: pointer to the driver internal queue element for mailbox command.
610  *
611  * The unregister DID mailbox command is used to unregister an N_Port/F_Port
612  * login for an unknown RPI by specifying the DID of a remote port. This
613  * command frees an RPI context in the HBA port. This has the effect of
614  * performing an implicit N_Port/F_Port logout.
615  *
616  * This routine prepares the mailbox command for unregistering a remote
617  * N_Port/F_Port (DID) login.
618  **/
619 void
620 lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
621                LPFC_MBOXQ_t * pmb)
622 {
623         MAILBOX_t *mb;
624
625         mb = &pmb->u.mb;
626         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
627
628         mb->un.varUnregDID.did = did;
629         if (vpi != 0xffff)
630                 vpi += phba->vpi_base;
631         mb->un.varUnregDID.vpi = vpi;
632
633         mb->mbxCommand = MBX_UNREG_D_ID;
634         mb->mbxOwner = OWN_HOST;
635         return;
636 }
637
638 /**
639  * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
640  * @phba: pointer to lpfc hba data structure.
641  * @pmb: pointer to the driver internal queue element for mailbox command.
642  *
643  * The read configuration mailbox command is used to read the HBA port
644  * configuration parameters. This mailbox command provides a method for
645  * seeing any parameters that may have changed via various configuration
646  * mailbox commands.
647  *
648  * This routine prepares the mailbox command for reading out HBA configuration
649  * parameters.
650  **/
651 void
652 lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
653 {
654         MAILBOX_t *mb;
655
656         mb = &pmb->u.mb;
657         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
658
659         mb->mbxCommand = MBX_READ_CONFIG;
660         mb->mbxOwner = OWN_HOST;
661         return;
662 }
663
664 /**
665  * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
666  * @phba: pointer to lpfc hba data structure.
667  * @pmb: pointer to the driver internal queue element for mailbox command.
668  *
669  * The read link status mailbox command is used to read the link status from
670  * the HBA. Link status includes all link-related error counters. These
671  * counters are maintained by the HBA and originated in the link hardware
672  * unit. Note that all of these counters wrap.
673  *
674  * This routine prepares the mailbox command for reading out HBA link status.
675  **/
676 void
677 lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
678 {
679         MAILBOX_t *mb;
680
681         mb = &pmb->u.mb;
682         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
683
684         mb->mbxCommand = MBX_READ_LNK_STAT;
685         mb->mbxOwner = OWN_HOST;
686         return;
687 }
688
689 /**
690  * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
691  * @phba: pointer to lpfc hba data structure.
692  * @vpi: virtual N_Port identifier.
693  * @did: remote port identifier.
694  * @param: pointer to memory holding the server parameters.
695  * @pmb: pointer to the driver internal queue element for mailbox command.
696  * @flag: action flag to be passed back for the complete function.
697  *
698  * The registration login mailbox command is used to register an N_Port or
699  * F_Port login. This registration allows the HBA to cache the remote N_Port
700  * service parameters internally and thereby make the appropriate FC-2
701  * decisions. The remote port service parameters are handed off by the driver
702  * to the HBA using a descriptor entry that directly identifies a buffer in
703  * host memory. In exchange, the HBA returns an RPI identifier.
704  *
705  * This routine prepares the mailbox command for registering remote port login.
706  * The function allocates DMA buffer for passing the service parameters to the
707  * HBA with the mailbox command.
708  *
709  * Return codes
710  *    0 - Success
711  *    1 - DMA memory allocation failed
712  **/
713 int
714 lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
715                uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
716 {
717         MAILBOX_t *mb = &pmb->u.mb;
718         uint8_t *sparam;
719         struct lpfc_dmabuf *mp;
720
721         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
722
723         mb->un.varRegLogin.rpi = 0;
724         if (phba->sli_rev == LPFC_SLI_REV4) {
725                 mb->un.varRegLogin.rpi = lpfc_sli4_alloc_rpi(phba);
726                 if (mb->un.varRegLogin.rpi == LPFC_RPI_ALLOC_ERROR)
727                         return 1;
728         }
729
730         mb->un.varRegLogin.vpi = vpi + phba->vpi_base;
731         mb->un.varRegLogin.did = did;
732         mb->un.varWords[30] = flag;     /* Set flag to issue action on cmpl */
733
734         mb->mbxOwner = OWN_HOST;
735
736         /* Get a buffer to hold NPorts Service Parameters */
737         mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
738         if (mp)
739                 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
740         if (!mp || !mp->virt) {
741                 kfree(mp);
742                 mb->mbxCommand = MBX_REG_LOGIN64;
743                 /* REG_LOGIN: no buffers */
744                 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
745                                 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
746                                 "flag x%x\n", vpi, did, flag);
747                 return (1);
748         }
749         INIT_LIST_HEAD(&mp->list);
750         sparam = mp->virt;
751
752         /* Copy param's into a new buffer */
753         memcpy(sparam, param, sizeof (struct serv_parm));
754
755         /* save address for completion */
756         pmb->context1 = (uint8_t *) mp;
757
758         mb->mbxCommand = MBX_REG_LOGIN64;
759         mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
760         mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
761         mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
762
763         return (0);
764 }
765
766 /**
767  * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
768  * @phba: pointer to lpfc hba data structure.
769  * @vpi: virtual N_Port identifier.
770  * @rpi: remote port identifier
771  * @pmb: pointer to the driver internal queue element for mailbox command.
772  *
773  * The unregistration login mailbox command is used to unregister an N_Port
774  * or F_Port login. This command frees an RPI context in the HBA. It has the
775  * effect of performing an implicit N_Port/F_Port logout.
776  *
777  * This routine prepares the mailbox command for unregistering remote port
778  * login.
779  **/
780 void
781 lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
782                  LPFC_MBOXQ_t * pmb)
783 {
784         MAILBOX_t *mb;
785
786         mb = &pmb->u.mb;
787         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
788
789         mb->un.varUnregLogin.rpi = (uint16_t) rpi;
790         mb->un.varUnregLogin.rsvd1 = 0;
791         mb->un.varUnregLogin.vpi = vpi + phba->vpi_base;
792
793         mb->mbxCommand = MBX_UNREG_LOGIN;
794         mb->mbxOwner = OWN_HOST;
795
796         return;
797 }
798
799 /**
800  * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
801  * @phba: pointer to lpfc hba data structure.
802  * @vpi: virtual N_Port identifier.
803  * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
804  * @pmb: pointer to the driver internal queue element for mailbox command.
805  *
806  * The registration vport identifier mailbox command is used to activate a
807  * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
808  * N_Port_ID against the information in the selected virtual N_Port context
809  * block and marks it active to allow normal processing of IOCB commands and
810  * received unsolicited exchanges.
811  *
812  * This routine prepares the mailbox command for registering a virtual N_Port.
813  **/
814 void
815 lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
816 {
817         MAILBOX_t *mb = &pmb->u.mb;
818
819         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
820
821         mb->un.varRegVpi.vpi = vport->vpi + vport->phba->vpi_base;
822         mb->un.varRegVpi.sid = vport->fc_myDID;
823         mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
824         memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname,
825                sizeof(struct lpfc_name));
826         mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]);
827         mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]);
828
829         mb->mbxCommand = MBX_REG_VPI;
830         mb->mbxOwner = OWN_HOST;
831         return;
832
833 }
834
835 /**
836  * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
837  * @phba: pointer to lpfc hba data structure.
838  * @vpi: virtual N_Port identifier.
839  * @pmb: pointer to the driver internal queue element for mailbox command.
840  *
841  * The unregistration vport identifier mailbox command is used to inactivate
842  * a virtual N_Port. The driver must have logged out and unregistered all
843  * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
844  * unregisters any default RPIs associated with the specified vpi, aborting
845  * any active exchanges. The HBA will post the mailbox response after making
846  * the virtual N_Port inactive.
847  *
848  * This routine prepares the mailbox command for unregistering a virtual
849  * N_Port.
850  **/
851 void
852 lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
853 {
854         MAILBOX_t *mb = &pmb->u.mb;
855         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
856
857         if (phba->sli_rev < LPFC_SLI_REV4)
858                 mb->un.varUnregVpi.vpi = vpi + phba->vpi_base;
859         else
860                 mb->un.varUnregVpi.sli4_vpi = vpi + phba->vpi_base;
861
862         mb->mbxCommand = MBX_UNREG_VPI;
863         mb->mbxOwner = OWN_HOST;
864         return;
865
866 }
867
868 /**
869  * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
870  * @phba: pointer to lpfc hba data structure.
871  *
872  * This routine sets up and initializes the IOCB rings in the Port Control
873  * Block (PCB).
874  **/
875 static void
876 lpfc_config_pcb_setup(struct lpfc_hba * phba)
877 {
878         struct lpfc_sli *psli = &phba->sli;
879         struct lpfc_sli_ring *pring;
880         PCB_t *pcbp = phba->pcb;
881         dma_addr_t pdma_addr;
882         uint32_t offset;
883         uint32_t iocbCnt = 0;
884         int i;
885
886         pcbp->maxRing = (psli->num_rings - 1);
887
888         for (i = 0; i < psli->num_rings; i++) {
889                 pring = &psli->ring[i];
890
891                 pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
892                                                         SLI2_IOCB_CMD_SIZE;
893                 pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
894                                                         SLI2_IOCB_RSP_SIZE;
895                 /* A ring MUST have both cmd and rsp entries defined to be
896                    valid */
897                 if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
898                         pcbp->rdsc[i].cmdEntries = 0;
899                         pcbp->rdsc[i].rspEntries = 0;
900                         pcbp->rdsc[i].cmdAddrHigh = 0;
901                         pcbp->rdsc[i].rspAddrHigh = 0;
902                         pcbp->rdsc[i].cmdAddrLow = 0;
903                         pcbp->rdsc[i].rspAddrLow = 0;
904                         pring->cmdringaddr = NULL;
905                         pring->rspringaddr = NULL;
906                         continue;
907                 }
908                 /* Command ring setup for ring */
909                 pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
910                 pcbp->rdsc[i].cmdEntries = pring->numCiocb;
911
912                 offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
913                          (uint8_t *) phba->slim2p.virt;
914                 pdma_addr = phba->slim2p.phys + offset;
915                 pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
916                 pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
917                 iocbCnt += pring->numCiocb;
918
919                 /* Response ring setup for ring */
920                 pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt];
921
922                 pcbp->rdsc[i].rspEntries = pring->numRiocb;
923                 offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
924                          (uint8_t *)phba->slim2p.virt;
925                 pdma_addr = phba->slim2p.phys + offset;
926                 pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
927                 pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
928                 iocbCnt += pring->numRiocb;
929         }
930 }
931
932 /**
933  * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
934  * @phba: pointer to lpfc hba data structure.
935  * @pmb: pointer to the driver internal queue element for mailbox command.
936  *
937  * The read revision mailbox command is used to read the revision levels of
938  * the HBA components. These components include hardware units, resident
939  * firmware, and available firmware. HBAs that supports SLI-3 mode of
940  * operation provide different response information depending on the version
941  * requested by the driver.
942  *
943  * This routine prepares the mailbox command for reading HBA revision
944  * information.
945  **/
946 void
947 lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
948 {
949         MAILBOX_t *mb = &pmb->u.mb;
950         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
951         mb->un.varRdRev.cv = 1;
952         mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
953         mb->mbxCommand = MBX_READ_REV;
954         mb->mbxOwner = OWN_HOST;
955         return;
956 }
957
958 void
959 lpfc_sli4_swap_str(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
960 {
961         MAILBOX_t *mb = &pmb->u.mb;
962         struct lpfc_mqe *mqe;
963
964         switch (mb->mbxCommand) {
965         case  MBX_READ_REV:
966                  mqe = &pmb->u.mqe;
967                 lpfc_sli_pcimem_bcopy(mqe->un.read_rev.fw_name,
968                                  mqe->un.read_rev.fw_name, 16);
969                 lpfc_sli_pcimem_bcopy(mqe->un.read_rev.ulp_fw_name,
970                                  mqe->un.read_rev.ulp_fw_name, 16);
971                 break;
972         default:
973                 break;
974         }
975         return;
976 }
977
978 /**
979  * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
980  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
981  * @hbq_desc: pointer to the HBQ selection profile descriptor.
982  *
983  * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
984  * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
985  * the Sequence Length Test using the fields in the Selection Profile 2
986  * extension in words 20:31.
987  **/
988 static void
989 lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
990                         struct lpfc_hbq_init  *hbq_desc)
991 {
992         hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
993         hbqmb->profiles.profile2.maxlen     = hbq_desc->maxlen;
994         hbqmb->profiles.profile2.seqlenoff  = hbq_desc->seqlenoff;
995 }
996
997 /**
998  * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
999  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1000  * @hbq_desc: pointer to the HBQ selection profile descriptor.
1001  *
1002  * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
1003  * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
1004  * the Sequence Length Test and Byte Field Test using the fields in the
1005  * Selection Profile 3 extension in words 20:31.
1006  **/
1007 static void
1008 lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
1009                         struct lpfc_hbq_init  *hbq_desc)
1010 {
1011         hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
1012         hbqmb->profiles.profile3.maxlen     = hbq_desc->maxlen;
1013         hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
1014         hbqmb->profiles.profile3.seqlenoff  = hbq_desc->seqlenoff;
1015         memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
1016                sizeof(hbqmb->profiles.profile3.cmdmatch));
1017 }
1018
1019 /**
1020  * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
1021  * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
1022  * @hbq_desc: pointer to the HBQ selection profile descriptor.
1023  *
1024  * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
1025  * HBA tests the initial frame of an incoming sequence using the frame's
1026  * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
1027  * and Byte Field Test using the fields in the Selection Profile 5 extension
1028  * words 20:31.
1029  **/
1030 static void
1031 lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
1032                         struct lpfc_hbq_init  *hbq_desc)
1033 {
1034         hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
1035         hbqmb->profiles.profile5.maxlen     = hbq_desc->maxlen;
1036         hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
1037         hbqmb->profiles.profile5.seqlenoff  = hbq_desc->seqlenoff;
1038         memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
1039                sizeof(hbqmb->profiles.profile5.cmdmatch));
1040 }
1041
1042 /**
1043  * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
1044  * @phba: pointer to lpfc hba data structure.
1045  * @id: HBQ identifier.
1046  * @hbq_desc: pointer to the HBA descriptor data structure.
1047  * @hbq_entry_index: index of the HBQ entry data structures.
1048  * @pmb: pointer to the driver internal queue element for mailbox command.
1049  *
1050  * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
1051  * an HBQ. The configuration binds events that require buffers to a particular
1052  * ring and HBQ based on a selection profile.
1053  *
1054  * This routine prepares the mailbox command for configuring an HBQ.
1055  **/
1056 void
1057 lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
1058                  struct lpfc_hbq_init *hbq_desc,
1059                 uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
1060 {
1061         int i;
1062         MAILBOX_t *mb = &pmb->u.mb;
1063         struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
1064
1065         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1066         hbqmb->hbqId = id;
1067         hbqmb->entry_count = hbq_desc->entry_count;   /* # entries in HBQ */
1068         hbqmb->recvNotify = hbq_desc->rn;             /* Receive
1069                                                        * Notification */
1070         hbqmb->numMask    = hbq_desc->mask_count;     /* # R_CTL/TYPE masks
1071                                                        * # in words 0-19 */
1072         hbqmb->profile    = hbq_desc->profile;        /* Selection profile:
1073                                                        * 0 = all,
1074                                                        * 7 = logentry */
1075         hbqmb->ringMask   = hbq_desc->ring_mask;      /* Binds HBQ to a ring
1076                                                        * e.g. Ring0=b0001,
1077                                                        * ring2=b0100 */
1078         hbqmb->headerLen  = hbq_desc->headerLen;      /* 0 if not profile 4
1079                                                        * or 5 */
1080         hbqmb->logEntry   = hbq_desc->logEntry;       /* Set to 1 if this
1081                                                        * HBQ will be used
1082                                                        * for LogEntry
1083                                                        * buffers */
1084         hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
1085                 hbq_entry_index * sizeof(struct lpfc_hbq_entry);
1086         hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
1087
1088         mb->mbxCommand = MBX_CONFIG_HBQ;
1089         mb->mbxOwner = OWN_HOST;
1090
1091                                 /* Copy info for profiles 2,3,5. Other
1092                                  * profiles this area is reserved
1093                                  */
1094         if (hbq_desc->profile == 2)
1095                 lpfc_build_hbq_profile2(hbqmb, hbq_desc);
1096         else if (hbq_desc->profile == 3)
1097                 lpfc_build_hbq_profile3(hbqmb, hbq_desc);
1098         else if (hbq_desc->profile == 5)
1099                 lpfc_build_hbq_profile5(hbqmb, hbq_desc);
1100
1101         /* Return if no rctl / type masks for this HBQ */
1102         if (!hbq_desc->mask_count)
1103                 return;
1104
1105         /* Otherwise we setup specific rctl / type masks for this HBQ */
1106         for (i = 0; i < hbq_desc->mask_count; i++) {
1107                 hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
1108                 hbqmb->hbqMasks[i].tmask  = hbq_desc->hbqMasks[i].tmask;
1109                 hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
1110                 hbqmb->hbqMasks[i].rctlmask  = hbq_desc->hbqMasks[i].rctlmask;
1111         }
1112
1113         return;
1114 }
1115
1116 /**
1117  * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
1118  * @phba: pointer to lpfc hba data structure.
1119  * @ring:
1120  * @pmb: pointer to the driver internal queue element for mailbox command.
1121  *
1122  * The configure ring mailbox command is used to configure an IOCB ring. This
1123  * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1124  * ring. This is used to map incoming sequences to a particular ring whose
1125  * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1126  * attempt to configure a ring whose number is greater than the number
1127  * specified in the Port Control Block (PCB). It is an error to issue the
1128  * configure ring command more than once with the same ring number. The HBA
1129  * returns an error if the driver attempts this.
1130  *
1131  * This routine prepares the mailbox command for configuring IOCB ring.
1132  **/
1133 void
1134 lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
1135 {
1136         int i;
1137         MAILBOX_t *mb = &pmb->u.mb;
1138         struct lpfc_sli *psli;
1139         struct lpfc_sli_ring *pring;
1140
1141         memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1142
1143         mb->un.varCfgRing.ring = ring;
1144         mb->un.varCfgRing.maxOrigXchg = 0;
1145         mb->un.varCfgRing.maxRespXchg = 0;
1146         mb->un.varCfgRing.recvNotify = 1;
1147
1148         psli = &phba->sli;
1149         pring = &psli->ring[ring];
1150         mb->un.varCfgRing.numMask = pring->num_mask;
1151         mb->mbxCommand = MBX_CONFIG_RING;
1152         mb->mbxOwner = OWN_HOST;
1153
1154         /* Is this ring configured for a specific profile */
1155         if (pring->prt[0].profile) {
1156                 mb->un.varCfgRing.profile = pring->prt[0].profile;
1157                 return;
1158         }
1159
1160         /* Otherwise we setup specific rctl / type masks for this ring */
1161         for (i = 0; i < pring->num_mask; i++) {
1162                 mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
1163                 if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ)
1164                         mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
1165                 else
1166                         mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
1167                 mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
1168                 mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
1169         }
1170
1171         return;
1172 }
1173
1174 /**
1175  * lpfc_config_port - Prepare a mailbox command for configuring port
1176  * @phba: pointer to lpfc hba data structure.
1177  * @pmb: pointer to the driver internal queue element for mailbox command.
1178  *
1179  * The configure port mailbox command is used to identify the Port Control
1180  * Block (PCB) in the driver memory. After this command is issued, the
1181  * driver must not access the mailbox in the HBA without first resetting
1182  * the HBA. The HBA may copy the PCB information to internal storage for
1183  * subsequent use; the driver can not change the PCB information unless it
1184  * resets the HBA.
1185  *
1186  * This routine prepares the mailbox command for configuring port.
1187  **/
1188 void
1189 lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1190 {
1191         MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
1192         MAILBOX_t *mb = &pmb->u.mb;
1193         dma_addr_t pdma_addr;
1194         uint32_t bar_low, bar_high;
1195         size_t offset;
1196         struct lpfc_hgp hgp;
1197         int i;
1198         uint32_t pgp_offset;
1199
1200         memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1201         mb->mbxCommand = MBX_CONFIG_PORT;
1202         mb->mbxOwner = OWN_HOST;
1203
1204         mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
1205
1206         offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
1207         pdma_addr = phba->slim2p.phys + offset;
1208         mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
1209         mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
1210
1211         /* Always Host Group Pointer is in SLIM */
1212         mb->un.varCfgPort.hps = 1;
1213
1214         /* If HBA supports SLI=3 ask for it */
1215
1216         if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
1217                 if (phba->cfg_enable_bg)
1218                         mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
1219                 mb->un.varCfgPort.cdss = 1; /* Configure Security */
1220                 mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
1221                 mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
1222                 mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
1223                 if (phba->max_vpi && phba->cfg_enable_npiv &&
1224                     phba->vpd.sli3Feat.cmv) {
1225                         mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI;
1226                         mb->un.varCfgPort.cmv = 1;
1227                 } else
1228                         mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
1229         } else
1230                 phba->sli_rev = LPFC_SLI_REV2;
1231         mb->un.varCfgPort.sli_mode = phba->sli_rev;
1232
1233         /* Now setup pcb */
1234         phba->pcb->type = TYPE_NATIVE_SLI2;
1235         phba->pcb->feature = FEATURE_INITIAL_SLI2;
1236
1237         /* Setup Mailbox pointers */
1238         phba->pcb->mailBoxSize = sizeof(MAILBOX_t) + MAILBOX_EXT_SIZE;
1239         offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
1240         pdma_addr = phba->slim2p.phys + offset;
1241         phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
1242         phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
1243
1244         /*
1245          * Setup Host Group ring pointer.
1246          *
1247          * For efficiency reasons, the ring get/put pointers can be
1248          * placed in adapter memory (SLIM) rather than in host memory.
1249          * This allows firmware to avoid PCI reads/writes when updating
1250          * and checking pointers.
1251          *
1252          * The firmware recognizes the use of SLIM memory by comparing
1253          * the address of the get/put pointers structure with that of
1254          * the SLIM BAR (BAR0).
1255          *
1256          * Caution: be sure to use the PCI config space value of BAR0/BAR1
1257          * (the hardware's view of the base address), not the OS's
1258          * value of pci_resource_start() as the OS value may be a cookie
1259          * for ioremap/iomap.
1260          */
1261
1262
1263         pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
1264         pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
1265
1266         /*
1267          * Set up HGP - Port Memory
1268          *
1269          * The port expects the host get/put pointers to reside in memory
1270          * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1271          * area of SLIM.  In SLI-2 mode, there's an additional 16 reserved
1272          * words (0x40 bytes).  This area is not reserved if HBQs are
1273          * configured in SLI-3.
1274          *
1275          * CR0Put    - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1276          * RR0Get                      0xc4              0x84
1277          * CR1Put                      0xc8              0x88
1278          * RR1Get                      0xcc              0x8c
1279          * CR2Put                      0xd0              0x90
1280          * RR2Get                      0xd4              0x94
1281          * CR3Put                      0xd8              0x98
1282          * RR3Get                      0xdc              0x9c
1283          *
1284          * Reserved                    0xa0-0xbf
1285          *    If HBQs configured:
1286          *                         HBQ 0 Put ptr  0xc0
1287          *                         HBQ 1 Put ptr  0xc4
1288          *                         HBQ 2 Put ptr  0xc8
1289          *                         ......
1290          *                         HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1291          *
1292          */
1293
1294         if (phba->cfg_hostmem_hgp && phba->sli_rev != 3) {
1295                 phba->host_gp = &phba->mbox->us.s2.host[0];
1296                 phba->hbq_put = NULL;
1297                 offset = (uint8_t *)&phba->mbox->us.s2.host -
1298                         (uint8_t *)phba->slim2p.virt;
1299                 pdma_addr = phba->slim2p.phys + offset;
1300                 phba->pcb->hgpAddrHigh = putPaddrHigh(pdma_addr);
1301                 phba->pcb->hgpAddrLow = putPaddrLow(pdma_addr);
1302         } else {
1303                 /* Always Host Group Pointer is in SLIM */
1304                 mb->un.varCfgPort.hps = 1;
1305
1306                 if (phba->sli_rev == 3) {
1307                         phba->host_gp = &mb_slim->us.s3.host[0];
1308                         phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
1309                 } else {
1310                         phba->host_gp = &mb_slim->us.s2.host[0];
1311                         phba->hbq_put = NULL;
1312                 }
1313
1314                 /* mask off BAR0's flag bits 0 - 3 */
1315                 phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
1316                         (void __iomem *)phba->host_gp -
1317                         (void __iomem *)phba->MBslimaddr;
1318                 if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
1319                         phba->pcb->hgpAddrHigh = bar_high;
1320                 else
1321                         phba->pcb->hgpAddrHigh = 0;
1322                 /* write HGP data to SLIM at the required longword offset */
1323                 memset(&hgp, 0, sizeof(struct lpfc_hgp));
1324
1325                 for (i = 0; i < phba->sli.num_rings; i++) {
1326                         lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
1327                                     sizeof(*phba->host_gp));
1328                 }
1329         }
1330
1331         /* Setup Port Group offset */
1332         if (phba->sli_rev == 3)
1333                 pgp_offset = offsetof(struct lpfc_sli2_slim,
1334                                       mbx.us.s3_pgp.port);
1335         else
1336                 pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
1337         pdma_addr = phba->slim2p.phys + pgp_offset;
1338         phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
1339         phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
1340
1341         /* Use callback routine to setp rings in the pcb */
1342         lpfc_config_pcb_setup(phba);
1343
1344         /* special handling for LC HBAs */
1345         if (lpfc_is_LC_HBA(phba->pcidev->device)) {
1346                 uint32_t hbainit[5];
1347
1348                 lpfc_hba_init(phba, hbainit);
1349
1350                 memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
1351         }
1352
1353         /* Swap PCB if needed */
1354         lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
1355 }
1356
1357 /**
1358  * lpfc_kill_board - Prepare a mailbox command for killing board
1359  * @phba: pointer to lpfc hba data structure.
1360  * @pmb: pointer to the driver internal queue element for mailbox command.
1361  *
1362  * The kill board mailbox command is used to tell firmware to perform a
1363  * graceful shutdown of a channel on a specified board to prepare for reset.
1364  * When the kill board mailbox command is received, the ER3 bit is set to 1
1365  * in the Host Status register and the ER Attention bit is set to 1 in the
1366  * Host Attention register of the HBA function that received the kill board
1367  * command.
1368  *
1369  * This routine prepares the mailbox command for killing the board in
1370  * preparation for a graceful shutdown.
1371  **/
1372 void
1373 lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1374 {
1375         MAILBOX_t *mb = &pmb->u.mb;
1376
1377         memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1378         mb->mbxCommand = MBX_KILL_BOARD;
1379         mb->mbxOwner = OWN_HOST;
1380         return;
1381 }
1382
1383 /**
1384  * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
1385  * @phba: pointer to lpfc hba data structure.
1386  * @mbq: pointer to the driver internal queue element for mailbox command.
1387  *
1388  * Driver maintains a internal mailbox command queue implemented as a linked
1389  * list. When a mailbox command is issued, it shall be put into the mailbox
1390  * command queue such that they shall be processed orderly as HBA can process
1391  * one mailbox command at a time.
1392  **/
1393 void
1394 lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1395 {
1396         struct lpfc_sli *psli;
1397
1398         psli = &phba->sli;
1399
1400         list_add_tail(&mbq->list, &psli->mboxq);
1401
1402         psli->mboxq_cnt++;
1403
1404         return;
1405 }
1406
1407 /**
1408  * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
1409  * @phba: pointer to lpfc hba data structure.
1410  *
1411  * Driver maintains a internal mailbox command queue implemented as a linked
1412  * list. When a mailbox command is issued, it shall be put into the mailbox
1413  * command queue such that they shall be processed orderly as HBA can process
1414  * one mailbox command at a time. After HBA finished processing a mailbox
1415  * command, the driver will remove a pending mailbox command from the head of
1416  * the mailbox command queue and send to the HBA for processing.
1417  *
1418  * Return codes
1419  *    pointer to the driver internal queue element for mailbox command.
1420  **/
1421 LPFC_MBOXQ_t *
1422 lpfc_mbox_get(struct lpfc_hba * phba)
1423 {
1424         LPFC_MBOXQ_t *mbq = NULL;
1425         struct lpfc_sli *psli = &phba->sli;
1426
1427         list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
1428         if (mbq)
1429                 psli->mboxq_cnt--;
1430
1431         return mbq;
1432 }
1433
1434 /**
1435  * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
1436  * @phba: pointer to lpfc hba data structure.
1437  * @mbq: pointer to the driver internal queue element for mailbox command.
1438  *
1439  * This routine put the completed mailbox command into the mailbox command
1440  * complete list. This is the unlocked version of the routine. The mailbox
1441  * complete list is used by the driver worker thread to process mailbox
1442  * complete callback functions outside the driver interrupt handler.
1443  **/
1444 void
1445 __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
1446 {
1447         list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
1448 }
1449
1450 /**
1451  * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
1452  * @phba: pointer to lpfc hba data structure.
1453  * @mbq: pointer to the driver internal queue element for mailbox command.
1454  *
1455  * This routine put the completed mailbox command into the mailbox command
1456  * complete list. This is the locked version of the routine. The mailbox
1457  * complete list is used by the driver worker thread to process mailbox
1458  * complete callback functions outside the driver interrupt handler.
1459  **/
1460 void
1461 lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
1462 {
1463         unsigned long iflag;
1464
1465         /* This function expects to be called from interrupt context */
1466         spin_lock_irqsave(&phba->hbalock, iflag);
1467         __lpfc_mbox_cmpl_put(phba, mbq);
1468         spin_unlock_irqrestore(&phba->hbalock, iflag);
1469         return;
1470 }
1471
1472 /**
1473  * lpfc_mbox_cmd_check - Check the validality of a mailbox command
1474  * @phba: pointer to lpfc hba data structure.
1475  * @mboxq: pointer to the driver internal queue element for mailbox command.
1476  *
1477  * This routine is to check whether a mailbox command is valid to be issued.
1478  * This check will be performed by both the mailbox issue API when a client
1479  * is to issue a mailbox command to the mailbox transport.
1480  *
1481  * Return 0 - pass the check, -ENODEV - fail the check
1482  **/
1483 int
1484 lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1485 {
1486         /* Mailbox command that have a completion handler must also have a
1487          * vport specified.
1488          */
1489         if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
1490             mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
1491                 if (!mboxq->vport) {
1492                         lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
1493                                         "1814 Mbox x%x failed, no vport\n",
1494                                         mboxq->u.mb.mbxCommand);
1495                         dump_stack();
1496                         return -ENODEV;
1497                 }
1498         }
1499         return 0;
1500 }
1501
1502 /**
1503  * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
1504  * @phba: pointer to lpfc hba data structure.
1505  *
1506  * This routine is to check whether the HBA device is ready for posting a
1507  * mailbox command. It is used by the mailbox transport API at the time the
1508  * to post a mailbox command to the device.
1509  *
1510  * Return 0 - pass the check, -ENODEV - fail the check
1511  **/
1512 int
1513 lpfc_mbox_dev_check(struct lpfc_hba *phba)
1514 {
1515         /* If the PCI channel is in offline state, do not issue mbox */
1516         if (unlikely(pci_channel_offline(phba->pcidev)))
1517                 return -ENODEV;
1518
1519         /* If the HBA is in error state, do not issue mbox */
1520         if (phba->link_state == LPFC_HBA_ERROR)
1521                 return -ENODEV;
1522
1523         return 0;
1524 }
1525
1526 /**
1527  * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
1528  * @phba: pointer to lpfc hba data structure.
1529  * @cmd: mailbox command code.
1530  *
1531  * This routine retrieves the proper timeout value according to the mailbox
1532  * command code.
1533  *
1534  * Return codes
1535  *    Timeout value to be used for the given mailbox command
1536  **/
1537 int
1538 lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
1539 {
1540         switch (cmd) {
1541         case MBX_WRITE_NV:      /* 0x03 */
1542         case MBX_UPDATE_CFG:    /* 0x1B */
1543         case MBX_DOWN_LOAD:     /* 0x1C */
1544         case MBX_DEL_LD_ENTRY:  /* 0x1D */
1545         case MBX_LOAD_AREA:     /* 0x81 */
1546         case MBX_WRITE_WWN:     /* 0x98 */
1547         case MBX_LOAD_EXP_ROM:  /* 0x9C */
1548                 return LPFC_MBOX_TMO_FLASH_CMD;
1549         case MBX_SLI4_CONFIG:   /* 0x9b */
1550                 return LPFC_MBOX_SLI4_CONFIG_TMO;
1551         }
1552         return LPFC_MBOX_TMO;
1553 }
1554
1555 /**
1556  * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
1557  * @mbox: pointer to lpfc mbox command.
1558  * @sgentry: sge entry index.
1559  * @phyaddr: physical address for the sge
1560  * @length: Length of the sge.
1561  *
1562  * This routine sets up an entry in the non-embedded mailbox command at the sge
1563  * index location.
1564  **/
1565 void
1566 lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry,
1567                       dma_addr_t phyaddr, uint32_t length)
1568 {
1569         struct lpfc_mbx_nembed_cmd *nembed_sge;
1570
1571         nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1572                                 &mbox->u.mqe.un.nembed_cmd;
1573         nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr);
1574         nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr);
1575         nembed_sge->sge[sgentry].length = length;
1576 }
1577
1578 /**
1579  * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
1580  * @mbox: pointer to lpfc mbox command.
1581  * @sgentry: sge entry index.
1582  *
1583  * This routine gets an entry from the non-embedded mailbox command at the sge
1584  * index location.
1585  **/
1586 void
1587 lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry,
1588                       struct lpfc_mbx_sge *sge)
1589 {
1590         struct lpfc_mbx_nembed_cmd *nembed_sge;
1591
1592         nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1593                                 &mbox->u.mqe.un.nembed_cmd;
1594         sge->pa_lo = nembed_sge->sge[sgentry].pa_lo;
1595         sge->pa_hi = nembed_sge->sge[sgentry].pa_hi;
1596         sge->length = nembed_sge->sge[sgentry].length;
1597 }
1598
1599 /**
1600  * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
1601  * @phba: pointer to lpfc hba data structure.
1602  * @mbox: pointer to lpfc mbox command.
1603  *
1604  * This routine frees SLI4 specific mailbox command for sending IOCTL command.
1605  **/
1606 void
1607 lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1608 {
1609         struct lpfc_mbx_sli4_config *sli4_cfg;
1610         struct lpfc_mbx_sge sge;
1611         dma_addr_t phyaddr;
1612         uint32_t sgecount, sgentry;
1613
1614         sli4_cfg = &mbox->u.mqe.un.sli4_config;
1615
1616         /* For embedded mbox command, just free the mbox command */
1617         if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1618                 mempool_free(mbox, phba->mbox_mem_pool);
1619                 return;
1620         }
1621
1622         /* For non-embedded mbox command, we need to free the pages first */
1623         sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr);
1624         /* There is nothing we can do if there is no sge address array */
1625         if (unlikely(!mbox->sge_array)) {
1626                 mempool_free(mbox, phba->mbox_mem_pool);
1627                 return;
1628         }
1629         /* Each non-embedded DMA memory was allocated in the length of a page */
1630         for (sgentry = 0; sgentry < sgecount; sgentry++) {
1631                 lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge);
1632                 phyaddr = getPaddr(sge.pa_hi, sge.pa_lo);
1633                 dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
1634                                   mbox->sge_array->addr[sgentry], phyaddr);
1635         }
1636         /* Free the sge address array memory */
1637         kfree(mbox->sge_array);
1638         /* Finally, free the mailbox command itself */
1639         mempool_free(mbox, phba->mbox_mem_pool);
1640 }
1641
1642 /**
1643  * lpfc_sli4_config - Initialize the  SLI4 Config Mailbox command
1644  * @phba: pointer to lpfc hba data structure.
1645  * @mbox: pointer to lpfc mbox command.
1646  * @subsystem: The sli4 config sub mailbox subsystem.
1647  * @opcode: The sli4 config sub mailbox command opcode.
1648  * @length: Length of the sli4 config mailbox command.
1649  *
1650  * This routine sets up the header fields of SLI4 specific mailbox command
1651  * for sending IOCTL command.
1652  *
1653  * Return: the actual length of the mbox command allocated (mostly useful
1654  *         for none embedded mailbox command).
1655  **/
1656 int
1657 lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
1658                  uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb)
1659 {
1660         struct lpfc_mbx_sli4_config *sli4_config;
1661         union lpfc_sli4_cfg_shdr *cfg_shdr = NULL;
1662         uint32_t alloc_len;
1663         uint32_t resid_len;
1664         uint32_t pagen, pcount;
1665         void *viraddr;
1666         dma_addr_t phyaddr;
1667
1668         /* Set up SLI4 mailbox command header fields */
1669         memset(mbox, 0, sizeof(*mbox));
1670         bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG);
1671
1672         /* Set up SLI4 ioctl command header fields */
1673         sli4_config = &mbox->u.mqe.un.sli4_config;
1674
1675         /* Setup for the embedded mbox command */
1676         if (emb) {
1677                 /* Set up main header fields */
1678                 bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
1679                 sli4_config->header.cfg_mhdr.payload_length =
1680                                         LPFC_MBX_CMD_HDR_LENGTH + length;
1681                 /* Set up sub-header fields following main header */
1682                 bf_set(lpfc_mbox_hdr_opcode,
1683                         &sli4_config->header.cfg_shdr.request, opcode);
1684                 bf_set(lpfc_mbox_hdr_subsystem,
1685                         &sli4_config->header.cfg_shdr.request, subsystem);
1686                 sli4_config->header.cfg_shdr.request.request_length = length;
1687                 return length;
1688         }
1689
1690         /* Setup for the none-embedded mbox command */
1691         pcount = (PAGE_ALIGN(length))/SLI4_PAGE_SIZE;
1692         pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ?
1693                                 LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount;
1694         /* Allocate record for keeping SGE virtual addresses */
1695         mbox->sge_array = kmalloc(sizeof(struct lpfc_mbx_nembed_sge_virt),
1696                                   GFP_KERNEL);
1697         if (!mbox->sge_array) {
1698                 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1699                                 "2527 Failed to allocate non-embedded SGE "
1700                                 "array.\n");
1701                 return 0;
1702         }
1703         for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) {
1704                 /* The DMA memory is always allocated in the length of a
1705                  * page even though the last SGE might not fill up to a
1706                  * page, this is used as a priori size of SLI4_PAGE_SIZE for
1707                  * the later DMA memory free.
1708                  */
1709                 viraddr = dma_alloc_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE,
1710                                              &phyaddr, GFP_KERNEL);
1711                 /* In case of malloc fails, proceed with whatever we have */
1712                 if (!viraddr)
1713                         break;
1714                 memset(viraddr, 0, SLI4_PAGE_SIZE);
1715                 mbox->sge_array->addr[pagen] = viraddr;
1716                 /* Keep the first page for later sub-header construction */
1717                 if (pagen == 0)
1718                         cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr;
1719                 resid_len = length - alloc_len;
1720                 if (resid_len > SLI4_PAGE_SIZE) {
1721                         lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
1722                                               SLI4_PAGE_SIZE);
1723                         alloc_len += SLI4_PAGE_SIZE;
1724                 } else {
1725                         lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
1726                                               resid_len);
1727                         alloc_len = length;
1728                 }
1729         }
1730
1731         /* Set up main header fields in mailbox command */
1732         sli4_config->header.cfg_mhdr.payload_length = alloc_len;
1733         bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen);
1734
1735         /* Set up sub-header fields into the first page */
1736         if (pagen > 0) {
1737                 bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode);
1738                 bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem);
1739                 cfg_shdr->request.request_length =
1740                                 alloc_len - sizeof(union  lpfc_sli4_cfg_shdr);
1741         }
1742         /* The sub-header is in DMA memory, which needs endian converstion */
1743         if (cfg_shdr)
1744                 lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
1745                               sizeof(union  lpfc_sli4_cfg_shdr));
1746
1747         return alloc_len;
1748 }
1749
1750 /**
1751  * lpfc_sli4_mbox_opcode_get - Get the opcode from a sli4 mailbox command
1752  * @phba: pointer to lpfc hba data structure.
1753  * @mbox: pointer to lpfc mbox command.
1754  *
1755  * This routine gets the opcode from a SLI4 specific mailbox command for
1756  * sending IOCTL command. If the mailbox command is not MBX_SLI4_CONFIG
1757  * (0x9B) or if the IOCTL sub-header is not present, opcode 0x0 shall be
1758  * returned.
1759  **/
1760 uint8_t
1761 lpfc_sli4_mbox_opcode_get(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1762 {
1763         struct lpfc_mbx_sli4_config *sli4_cfg;
1764         union lpfc_sli4_cfg_shdr *cfg_shdr;
1765
1766         if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
1767                 return 0;
1768         sli4_cfg = &mbox->u.mqe.un.sli4_config;
1769
1770         /* For embedded mbox command, get opcode from embedded sub-header*/
1771         if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1772                 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
1773                 return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
1774         }
1775
1776         /* For non-embedded mbox command, get opcode from first dma page */
1777         if (unlikely(!mbox->sge_array))
1778                 return 0;
1779         cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
1780         return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
1781 }
1782
1783 /**
1784  * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd
1785  * @phba: pointer to lpfc hba data structure.
1786  * @fcf_index: index to fcf table.
1787  *
1788  * This routine routine allocates and constructs non-embedded mailbox command
1789  * for reading a FCF table entry refered by @fcf_index.
1790  *
1791  * Return: pointer to the mailbox command constructed if successful, otherwise
1792  * NULL.
1793  **/
1794 int
1795 lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *phba,
1796                            struct lpfcMboxq *mboxq,
1797                            uint16_t fcf_index)
1798 {
1799         void *virt_addr;
1800         dma_addr_t phys_addr;
1801         uint8_t *bytep;
1802         struct lpfc_mbx_sge sge;
1803         uint32_t alloc_len, req_len;
1804         struct lpfc_mbx_read_fcf_tbl *read_fcf;
1805
1806         if (!mboxq)
1807                 return -ENOMEM;
1808
1809         req_len = sizeof(struct fcf_record) +
1810                   sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t);
1811
1812         /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */
1813         alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
1814                         LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len,
1815                         LPFC_SLI4_MBX_NEMBED);
1816
1817         if (alloc_len < req_len) {
1818                 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1819                                 "0291 Allocated DMA memory size (x%x) is "
1820                                 "less than the requested DMA memory "
1821                                 "size (x%x)\n", alloc_len, req_len);
1822                 return -ENOMEM;
1823         }
1824
1825         /* Get the first SGE entry from the non-embedded DMA memory. This
1826          * routine only uses a single SGE.
1827          */
1828         lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1829         phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
1830         virt_addr = mboxq->sge_array->addr[0];
1831         read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1832
1833         /* Set up command fields */
1834         bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index);
1835         /* Perform necessary endian conversion */
1836         bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr);
1837         lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t));
1838
1839         return 0;
1840 }
1841
1842 /**
1843  * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
1844  * @mboxq: pointer to lpfc mbox command.
1845  *
1846  * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
1847  * mailbox command.
1848  **/
1849 void
1850 lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
1851 {
1852         /* Set up SLI4 mailbox command header fields */
1853         memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
1854         bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS);
1855
1856         /* Set up host requested features. */
1857         bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
1858
1859         /* Enable DIF (block guard) only if configured to do so. */
1860         if (phba->cfg_enable_bg)
1861                 bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1);
1862
1863         /* Enable NPIV only if configured to do so. */
1864         if (phba->max_vpi && phba->cfg_enable_npiv)
1865                 bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1);
1866
1867         return;
1868 }
1869
1870 /**
1871  * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
1872  * @mbox: pointer to lpfc mbox command to initialize.
1873  * @vport: Vport associated with the VF.
1874  *
1875  * This routine initializes @mbox to all zeros and then fills in the mailbox
1876  * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
1877  * in the context of an FCF. The driver issues this command to setup a VFI
1878  * before issuing a FLOGI to login to the VSAN. The driver should also issue a
1879  * REG_VFI after a successful VSAN login.
1880  **/
1881 void
1882 lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
1883 {
1884         struct lpfc_mbx_init_vfi *init_vfi;
1885
1886         memset(mbox, 0, sizeof(*mbox));
1887         init_vfi = &mbox->u.mqe.un.init_vfi;
1888         bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI);
1889         bf_set(lpfc_init_vfi_vr, init_vfi, 1);
1890         bf_set(lpfc_init_vfi_vt, init_vfi, 1);
1891         bf_set(lpfc_init_vfi_vfi, init_vfi, vport->vfi + vport->phba->vfi_base);
1892         bf_set(lpfc_init_vfi_fcfi, init_vfi, vport->phba->fcf.fcfi);
1893 }
1894
1895 /**
1896  * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
1897  * @mbox: pointer to lpfc mbox command to initialize.
1898  * @vport: vport associated with the VF.
1899  * @phys: BDE DMA bus address used to send the service parameters to the HBA.
1900  *
1901  * This routine initializes @mbox to all zeros and then fills in the mailbox
1902  * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
1903  * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
1904  * fabrics identified by VFI in the context of an FCF.
1905  **/
1906 void
1907 lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys)
1908 {
1909         struct lpfc_mbx_reg_vfi *reg_vfi;
1910
1911         memset(mbox, 0, sizeof(*mbox));
1912         reg_vfi = &mbox->u.mqe.un.reg_vfi;
1913         bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI);
1914         bf_set(lpfc_reg_vfi_vp, reg_vfi, 1);
1915         bf_set(lpfc_reg_vfi_vfi, reg_vfi, vport->vfi + vport->phba->vfi_base);
1916         bf_set(lpfc_reg_vfi_fcfi, reg_vfi, vport->phba->fcf.fcfi);
1917         bf_set(lpfc_reg_vfi_vpi, reg_vfi, vport->vpi + vport->phba->vpi_base);
1918         memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name));
1919         reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]);
1920         reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]);
1921         reg_vfi->e_d_tov = vport->phba->fc_edtov;
1922         reg_vfi->r_a_tov = vport->phba->fc_ratov;
1923         reg_vfi->bde.addrHigh = putPaddrHigh(phys);
1924         reg_vfi->bde.addrLow = putPaddrLow(phys);
1925         reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam);
1926         reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1927         bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID);
1928 }
1929
1930 /**
1931  * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
1932  * @phba: pointer to the hba structure to init the VPI for.
1933  * @mbox: pointer to lpfc mbox command to initialize.
1934  * @vpi: VPI to be initialized.
1935  *
1936  * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
1937  * command to activate a virtual N_Port. The HBA assigns a MAC address to use
1938  * with the virtual N Port.  The SLI Host issues this command before issuing a
1939  * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
1940  * successful virtual NPort login.
1941  **/
1942 void
1943 lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi)
1944 {
1945         memset(mbox, 0, sizeof(*mbox));
1946         bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI);
1947         bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi,
1948                vpi + phba->vpi_base);
1949         bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi,
1950                phba->pport->vfi + phba->vfi_base);
1951 }
1952
1953 /**
1954  * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
1955  * @mbox: pointer to lpfc mbox command to initialize.
1956  * @vport: vport associated with the VF.
1957  *
1958  * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
1959  * (logical NPort) into the inactive state. The SLI Host must have logged out
1960  * and unregistered all remote N_Ports to abort any activity on the virtual
1961  * fabric. The SLI Port posts the mailbox response after marking the virtual
1962  * fabric inactive.
1963  **/
1964 void
1965 lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
1966 {
1967         memset(mbox, 0, sizeof(*mbox));
1968         bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI);
1969         bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi,
1970                vport->vfi + vport->phba->vfi_base);
1971 }
1972
1973 /**
1974  * lpfc_dump_fcoe_param - Dump config region 23 to get FCoe parameters.
1975  * @phba: pointer to the hba structure containing.
1976  * @mbox: pointer to lpfc mbox command to initialize.
1977  *
1978  * This function create a SLI4 dump mailbox command to dump FCoE
1979  * parameters stored in region 23.
1980  **/
1981 int
1982 lpfc_dump_fcoe_param(struct lpfc_hba *phba,
1983                 struct lpfcMboxq *mbox)
1984 {
1985         struct lpfc_dmabuf *mp = NULL;
1986         MAILBOX_t *mb;
1987
1988         memset(mbox, 0, sizeof(*mbox));
1989         mb = &mbox->u.mb;
1990
1991         mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1992         if (mp)
1993                 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
1994
1995         if (!mp || !mp->virt) {
1996                 kfree(mp);
1997                 /* dump_fcoe_param failed to allocate memory */
1998                 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
1999                         "2569 lpfc_dump_fcoe_param: memory"
2000                         " allocation failed\n");
2001                 return 1;
2002         }
2003
2004         memset(mp->virt, 0, LPFC_BPL_SIZE);
2005         INIT_LIST_HEAD(&mp->list);
2006
2007         /* save address for completion */
2008         mbox->context1 = (uint8_t *) mp;
2009
2010         mb->mbxCommand = MBX_DUMP_MEMORY;
2011         mb->un.varDmp.type = DMP_NV_PARAMS;
2012         mb->un.varDmp.region_id = DMP_REGION_23;
2013         mb->un.varDmp.sli4_length = DMP_RGN23_SIZE;
2014         mb->un.varWords[3] = putPaddrLow(mp->phys);
2015         mb->un.varWords[4] = putPaddrHigh(mp->phys);
2016         return 0;
2017 }
2018
2019 /**
2020  * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
2021  * @phba: pointer to the hba structure containing the FCF index and RQ ID.
2022  * @mbox: pointer to lpfc mbox command to initialize.
2023  *
2024  * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
2025  * SLI Host uses the command to activate an FCF after it has acquired FCF
2026  * information via a READ_FCF mailbox command. This mailbox command also is used
2027  * to indicate where received unsolicited frames from this FCF will be sent. By
2028  * default this routine will set up the FCF to forward all unsolicited frames
2029  * the the RQ ID passed in the @phba. This can be overridden by the caller for
2030  * more complicated setups.
2031  **/
2032 void
2033 lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
2034 {
2035         struct lpfc_mbx_reg_fcfi *reg_fcfi;
2036
2037         memset(mbox, 0, sizeof(*mbox));
2038         reg_fcfi = &mbox->u.mqe.un.reg_fcfi;
2039         bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI);
2040         bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, phba->sli4_hba.hdr_rq->queue_id);
2041         bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
2042         bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
2043         bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
2044         bf_set(lpfc_reg_fcfi_info_index, reg_fcfi,
2045                phba->fcf.current_rec.fcf_indx);
2046         /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */
2047         bf_set(lpfc_reg_fcfi_mam, reg_fcfi, (~phba->fcf.addr_mode) & 0x3);
2048         if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) {
2049                 bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
2050                 bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi,
2051                        phba->fcf.current_rec.vlan_id);
2052         }
2053 }
2054
2055 /**
2056  * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
2057  * @mbox: pointer to lpfc mbox command to initialize.
2058  * @fcfi: FCFI to be unregistered.
2059  *
2060  * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
2061  * The SLI Host uses the command to inactivate an FCFI.
2062  **/
2063 void
2064 lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi)
2065 {
2066         memset(mbox, 0, sizeof(*mbox));
2067         bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI);
2068         bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi);
2069 }
2070
2071 /**
2072  * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
2073  * @mbox: pointer to lpfc mbox command to initialize.
2074  * @ndlp: The nodelist structure that describes the RPI to resume.
2075  *
2076  * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
2077  * link event.
2078  **/
2079 void
2080 lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
2081 {
2082         struct lpfc_mbx_resume_rpi *resume_rpi;
2083
2084         memset(mbox, 0, sizeof(*mbox));
2085         resume_rpi = &mbox->u.mqe.un.resume_rpi;
2086         bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI);
2087         bf_set(lpfc_resume_rpi_index, resume_rpi, ndlp->nlp_rpi);
2088         bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI);
2089         resume_rpi->event_tag = ndlp->phba->fc_eventTag;
2090 }
2091
2092 /**
2093  * lpfc_supported_pages - Initialize the PORT_CAPABILITIES supported pages
2094  *                        mailbox command.
2095  * @mbox: pointer to lpfc mbox command to initialize.
2096  *
2097  * The PORT_CAPABILITIES supported pages mailbox command is issued to
2098  * retrieve the particular feature pages supported by the port.
2099  **/
2100 void
2101 lpfc_supported_pages(struct lpfcMboxq *mbox)
2102 {
2103         struct lpfc_mbx_supp_pages *supp_pages;
2104
2105         memset(mbox, 0, sizeof(*mbox));
2106         supp_pages = &mbox->u.mqe.un.supp_pages;
2107         bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES);
2108         bf_set(cpn, supp_pages, LPFC_SUPP_PAGES);
2109 }
2110
2111 /**
2112  * lpfc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params
2113  *                    mailbox command.
2114  * @mbox: pointer to lpfc mbox command to initialize.
2115  *
2116  * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to
2117  * retrieve the particular SLI4 features supported by the port.
2118  **/
2119 void
2120 lpfc_sli4_params(struct lpfcMboxq *mbox)
2121 {
2122         struct lpfc_mbx_sli4_params *sli4_params;
2123
2124         memset(mbox, 0, sizeof(*mbox));
2125         sli4_params = &mbox->u.mqe.un.sli4_params;
2126         bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES);
2127         bf_set(cpn, sli4_params, LPFC_SLI4_PARAMETERS);
2128 }