[SCSI] lpfc 8.3.2 : Addition of SLI4 Interface - Base Support
[deliverable/linux.git] / drivers / scsi / lpfc / lpfc_mbox.c
CommitLineData
dea3101e 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
c44ce173 3 * Fibre Channel Host Bus Adapters. *
9399627f 4 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
c44ce173 5 * EMULEX and SLI are trademarks of Emulex. *
dea3101e 6 * www.emulex.com *
c44ce173 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea3101e 8 * *
9 * This program is free software; you can redistribute it and/or *
c44ce173
JSEC
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. *
dea3101e 20 *******************************************************************/
21
dea3101e 22#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
f888ba3c
JSEC
26#include <scsi/scsi_device.h>
27#include <scsi/scsi_transport_fc.h>
28
91886523
JSEC
29#include <scsi/scsi.h>
30
da0436e9 31#include "lpfc_hw4.h"
dea3101e 32#include "lpfc_hw.h"
33#include "lpfc_sli.h"
da0436e9 34#include "lpfc_sli4.h"
ea2151b4 35#include "lpfc_nl.h"
dea3101e 36#include "lpfc_disc.h"
37#include "lpfc_scsi.h"
38#include "lpfc.h"
39#include "lpfc_logmsg.h"
40#include "lpfc_crtn.h"
41#include "lpfc_compat.h"
42
e59058c4 43/**
3621a710 44 * lpfc_dump_mem - Prepare a mailbox command for retrieving HBA's VPD memory
e59058c4
JS
45 * @phba: pointer to lpfc hba data structure.
46 * @pmb: pointer to the driver internal queue element for mailbox command.
47 * @offset: offset for dumping VPD memory mailbox command.
48 *
49 * The dump mailbox command provides a method for the device driver to obtain
50 * various types of information from the HBA device.
51 *
52 * This routine prepares the mailbox command for dumping HBA Vital Product
53 * Data (VPD) memory. This mailbox command is to be used for retrieving a
54 * portion (DMP_RSP_SIZE bytes) of a HBA's VPD from the HBA at an address
55 * offset specified by the offset parameter.
56 **/
dea3101e 57void
58lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset)
59{
60 MAILBOX_t *mb;
61 void *ctx;
62
63 mb = &pmb->mb;
64 ctx = pmb->context2;
65
66 /* Setup to dump VPD region */
67 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
68 mb->mbxCommand = MBX_DUMP_MEMORY;
69 mb->un.varDmp.cv = 1;
70 mb->un.varDmp.type = DMP_NV_PARAMS;
71 mb->un.varDmp.entry_index = offset;
72 mb->un.varDmp.region_id = DMP_REGION_VPD;
73 mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
74 mb->un.varDmp.co = 0;
75 mb->un.varDmp.resp_offset = 0;
76 pmb->context2 = ctx;
77 mb->mbxOwner = OWN_HOST;
78 return;
79}
80
97207482 81/**
3621a710 82 * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params
97207482
JS
83 * @phba: pointer to lpfc hba data structure.
84 * @pmb: pointer to the driver internal queue element for mailbox command.
3621a710 85 *
97207482
JS
86 * This function create a dump memory mailbox command to dump wake up
87 * parameters.
88 */
89void
90lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
91{
92 MAILBOX_t *mb;
93 void *ctx;
94
95 mb = &pmb->mb;
96 /* Save context so that we can restore after memset */
97 ctx = pmb->context2;
98
99 /* Setup to dump VPD region */
100 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
101 mb->mbxCommand = MBX_DUMP_MEMORY;
102 mb->mbxOwner = OWN_HOST;
103 mb->un.varDmp.cv = 1;
104 mb->un.varDmp.type = DMP_NV_PARAMS;
105 mb->un.varDmp.entry_index = 0;
106 mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID;
107 mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE;
108 mb->un.varDmp.co = 0;
109 mb->un.varDmp.resp_offset = 0;
110 pmb->context2 = ctx;
111 return;
112}
113
e59058c4 114/**
3621a710 115 * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param
e59058c4
JS
116 * @phba: pointer to lpfc hba data structure.
117 * @pmb: pointer to the driver internal queue element for mailbox command.
118 *
119 * The read NVRAM mailbox command returns the HBA's non-volatile parameters
120 * that are used as defaults when the Fibre Channel link is brought on-line.
121 *
122 * This routine prepares the mailbox command for reading information stored
123 * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN.
124 **/
dea3101e 125void
126lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
127{
128 MAILBOX_t *mb;
129
130 mb = &pmb->mb;
131 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
132 mb->mbxCommand = MBX_READ_NV;
133 mb->mbxOwner = OWN_HOST;
134 return;
135}
136
e59058c4 137/**
3621a710 138 * lpfc_config_async - Prepare a mailbox command for enabling HBA async event
e59058c4
JS
139 * @phba: pointer to lpfc hba data structure.
140 * @pmb: pointer to the driver internal queue element for mailbox command.
141 * @ring: ring number for the asynchronous event to be configured.
142 *
143 * The asynchronous event enable mailbox command is used to enable the
144 * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and
145 * specifies the default ring to which events are posted.
146 *
147 * This routine prepares the mailbox command for enabling HBA asynchronous
148 * event support on a IOCB ring.
149 **/
57127f15
JS
150void
151lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
152 uint32_t ring)
153{
154 MAILBOX_t *mb;
155
156 mb = &pmb->mb;
157 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
158 mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
159 mb->un.varCfgAsyncEvent.ring = ring;
160 mb->mbxOwner = OWN_HOST;
161 return;
162}
163
e59058c4 164/**
3621a710 165 * lpfc_heart_beat - Prepare a mailbox command for heart beat
e59058c4
JS
166 * @phba: pointer to lpfc hba data structure.
167 * @pmb: pointer to the driver internal queue element for mailbox command.
168 *
169 * The heart beat mailbox command is used to detect an unresponsive HBA, which
170 * is defined as any device where no error attention is sent and both mailbox
171 * and rings are not processed.
172 *
173 * This routine prepares the mailbox command for issuing a heart beat in the
174 * form of mailbox command to the HBA. The timely completion of the heart
175 * beat mailbox command indicates the health of the HBA.
176 **/
858c9f6c
JS
177void
178lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
179{
180 MAILBOX_t *mb;
181
182 mb = &pmb->mb;
183 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
184 mb->mbxCommand = MBX_HEARTBEAT;
185 mb->mbxOwner = OWN_HOST;
186 return;
187}
188
e59058c4 189/**
3621a710 190 * lpfc_read_la - Prepare a mailbox command for reading HBA link attention
e59058c4
JS
191 * @phba: pointer to lpfc hba data structure.
192 * @pmb: pointer to the driver internal queue element for mailbox command.
193 * @mp: DMA buffer memory for reading the link attention information into.
194 *
195 * The read link attention mailbox command is issued to read the Link Event
196 * Attention information indicated by the HBA port when the Link Event bit
197 * of the Host Attention (HSTATT) register is set to 1. A Link Event
198 * Attention occurs based on an exception detected at the Fibre Channel link
199 * interface.
200 *
201 * This routine prepares the mailbox command for reading HBA link attention
202 * information. A DMA memory has been set aside and address passed to the
203 * HBA through @mp for the HBA to DMA link attention information into the
204 * memory as part of the execution of the mailbox command.
205 *
206 * Return codes
207 * 0 - Success (currently always return 0)
208 **/
dea3101e 209int
210lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
211{
212 MAILBOX_t *mb;
213 struct lpfc_sli *psli;
214
215 psli = &phba->sli;
216 mb = &pmb->mb;
217 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
218
219 INIT_LIST_HEAD(&mp->list);
220 mb->mbxCommand = MBX_READ_LA64;
221 mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128;
222 mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
223 mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys);
224
225 /* Save address for later completion and set the owner to host so that
226 * the FW knows this mailbox is available for processing.
227 */
228 pmb->context1 = (uint8_t *) mp;
229 mb->mbxOwner = OWN_HOST;
92d7f7b0 230 return (0);
dea3101e 231}
232
e59058c4 233/**
3621a710 234 * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention
e59058c4
JS
235 * @phba: pointer to lpfc hba data structure.
236 * @pmb: pointer to the driver internal queue element for mailbox command.
237 *
238 * The clear link attention mailbox command is issued to clear the link event
239 * attention condition indicated by the Link Event bit of the Host Attention
240 * (HSTATT) register. The link event attention condition is cleared only if
241 * the event tag specified matches that of the current link event counter.
242 * The current event tag is read using the read link attention event mailbox
243 * command.
244 *
245 * This routine prepares the mailbox command for clearing HBA link attention
246 * information.
247 **/
dea3101e 248void
249lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
250{
251 MAILBOX_t *mb;
252
253 mb = &pmb->mb;
254 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
255
256 mb->un.varClearLA.eventTag = phba->fc_eventTag;
257 mb->mbxCommand = MBX_CLEAR_LA;
258 mb->mbxOwner = OWN_HOST;
259 return;
260}
261
e59058c4 262/**
3621a710 263 * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA
e59058c4
JS
264 * @phba: pointer to lpfc hba data structure.
265 * @pmb: pointer to the driver internal queue element for mailbox command.
266 *
267 * The configure link mailbox command is used before the initialize link
268 * mailbox command to override default value and to configure link-oriented
269 * parameters such as DID address and various timers. Typically, this
270 * command would be used after an F_Port login to set the returned DID address
271 * and the fabric timeout values. This command is not valid before a configure
272 * port command has configured the HBA port.
273 *
274 * This routine prepares the mailbox command for configuring link on a HBA.
275 **/
dea3101e 276void
277lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
278{
2e0fef85 279 struct lpfc_vport *vport = phba->pport;
dea3101e 280 MAILBOX_t *mb = &pmb->mb;
281 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
282
283 /* NEW_FEATURE
284 * SLI-2, Coalescing Response Feature.
285 */
286 if (phba->cfg_cr_delay) {
287 mb->un.varCfgLnk.cr = 1;
288 mb->un.varCfgLnk.ci = 1;
289 mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
290 mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
291 }
292
2e0fef85 293 mb->un.varCfgLnk.myId = vport->fc_myDID;
dea3101e 294 mb->un.varCfgLnk.edtov = phba->fc_edtov;
295 mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
296 mb->un.varCfgLnk.ratov = phba->fc_ratov;
297 mb->un.varCfgLnk.rttov = phba->fc_rttov;
298 mb->un.varCfgLnk.altov = phba->fc_altov;
299 mb->un.varCfgLnk.crtov = phba->fc_crtov;
300 mb->un.varCfgLnk.citov = phba->fc_citov;
301
302 if (phba->cfg_ack0)
303 mb->un.varCfgLnk.ack0_enable = 1;
304
305 mb->mbxCommand = MBX_CONFIG_LINK;
306 mb->mbxOwner = OWN_HOST;
307 return;
308}
309
9399627f 310/**
3621a710 311 * lpfc_config_msi - Prepare a mailbox command for configuring msi-x
9399627f
JS
312 * @phba: pointer to lpfc hba data structure.
313 * @pmb: pointer to the driver internal queue element for mailbox command.
314 *
315 * The configure MSI-X mailbox command is used to configure the HBA's SLI-3
316 * MSI-X multi-message interrupt vector association to interrupt attention
317 * conditions.
318 *
319 * Return codes
320 * 0 - Success
321 * -EINVAL - Failure
322 **/
323int
324lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
325{
326 MAILBOX_t *mb = &pmb->mb;
327 uint32_t attentionConditions[2];
328
329 /* Sanity check */
330 if (phba->cfg_use_msi != 2) {
331 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
332 "0475 Not configured for supporting MSI-X "
333 "cfg_use_msi: 0x%x\n", phba->cfg_use_msi);
334 return -EINVAL;
335 }
336
337 if (phba->sli_rev < 3) {
338 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
339 "0476 HBA not supporting SLI-3 or later "
340 "SLI Revision: 0x%x\n", phba->sli_rev);
341 return -EINVAL;
342 }
343
344 /* Clear mailbox command fields */
345 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
346
347 /*
348 * SLI-3, Message Signaled Interrupt Fearure.
349 */
350
351 /* Multi-message attention configuration */
352 attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT |
353 HA_LATT | HA_MBATT);
354 attentionConditions[1] = 0;
355
356 mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0];
357 mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1];
358
359 /*
360 * Set up message number to HA bit association
361 */
362#ifdef __BIG_ENDIAN_BITFIELD
363 /* RA0 (FCP Ring) */
364 mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1;
365 /* RA1 (Other Protocol Extra Ring) */
366 mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1;
367#else /* __LITTLE_ENDIAN_BITFIELD */
368 /* RA0 (FCP Ring) */
369 mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1;
370 /* RA1 (Other Protocol Extra Ring) */
371 mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1;
372#endif
373 /* Multi-message interrupt autoclear configuration*/
374 mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0];
375 mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1];
376
377 /* For now, HBA autoclear does not work reliably, disable it */
378 mb->un.varCfgMSI.autoClearHA[0] = 0;
379 mb->un.varCfgMSI.autoClearHA[1] = 0;
380
381 /* Set command and owner bit */
382 mb->mbxCommand = MBX_CONFIG_MSI;
383 mb->mbxOwner = OWN_HOST;
384
385 return 0;
386}
387
e59058c4 388/**
3621a710 389 * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA
e59058c4
JS
390 * @phba: pointer to lpfc hba data structure.
391 * @pmb: pointer to the driver internal queue element for mailbox command.
392 * @topology: the link topology for the link to be initialized to.
393 * @linkspeed: the link speed for the link to be initialized to.
394 *
395 * The initialize link mailbox command is used to initialize the Fibre
396 * Channel link. This command must follow a configure port command that
397 * establishes the mode of operation.
398 *
399 * This routine prepares the mailbox command for initializing link on a HBA
400 * with the specified link topology and speed.
401 **/
dea3101e 402void
403lpfc_init_link(struct lpfc_hba * phba,
404 LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
405{
406 lpfc_vpd_t *vpd;
407 struct lpfc_sli *psli;
408 MAILBOX_t *mb;
409
410 mb = &pmb->mb;
411 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
412
413 psli = &phba->sli;
414 switch (topology) {
415 case FLAGS_TOPOLOGY_MODE_LOOP_PT:
416 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
417 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
418 break;
419 case FLAGS_TOPOLOGY_MODE_PT_PT:
420 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
421 break;
422 case FLAGS_TOPOLOGY_MODE_LOOP:
423 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
424 break;
425 case FLAGS_TOPOLOGY_MODE_PT_LOOP:
426 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
427 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
428 break;
367c2713
JW
429 case FLAGS_LOCAL_LB:
430 mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
431 break;
dea3101e 432 }
433
4b0b91d4
JS
434 /* Enable asynchronous ABTS responses from firmware */
435 mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
436
dea3101e 437 /* NEW_FEATURE
438 * Setting up the link speed
439 */
440 vpd = &phba->vpd;
441 if (vpd->rev.feaLevelHigh >= 0x02){
92d7f7b0 442 switch(linkspeed){
dea3101e 443 case LINK_SPEED_1G:
444 case LINK_SPEED_2G:
445 case LINK_SPEED_4G:
b87eab38 446 case LINK_SPEED_8G:
dea3101e 447 mb->un.varInitLnk.link_flags |=
448 FLAGS_LINK_SPEED;
449 mb->un.varInitLnk.link_speed = linkspeed;
450 break;
451 case LINK_SPEED_AUTO:
452 default:
453 mb->un.varInitLnk.link_speed =
454 LINK_SPEED_AUTO;
455 break;
456 }
457
458 }
459 else
460 mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
461
462 mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
463 mb->mbxOwner = OWN_HOST;
464 mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
465 return;
466}
467
e59058c4 468/**
3621a710 469 * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters
e59058c4
JS
470 * @phba: pointer to lpfc hba data structure.
471 * @pmb: pointer to the driver internal queue element for mailbox command.
472 * @vpi: virtual N_Port identifier.
473 *
474 * The read service parameter mailbox command is used to read the HBA port
475 * service parameters. The service parameters are read into the buffer
476 * specified directly by a BDE in the mailbox command. These service
477 * parameters may then be used to build the payload of an N_Port/F_POrt
478 * login request and reply (LOGI/ACC).
479 *
480 * This routine prepares the mailbox command for reading HBA port service
481 * parameters. The DMA memory is allocated in this function and the addresses
482 * are populated into the mailbox command for the HBA to DMA the service
483 * parameters into.
484 *
485 * Return codes
486 * 0 - Success
487 * 1 - DMA memory allocation failed
488 **/
dea3101e 489int
92d7f7b0 490lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
dea3101e 491{
492 struct lpfc_dmabuf *mp;
493 MAILBOX_t *mb;
494 struct lpfc_sli *psli;
495
496 psli = &phba->sli;
497 mb = &pmb->mb;
498 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
499
500 mb->mbxOwner = OWN_HOST;
501
502 /* Get a buffer to hold the HBAs Service Parameters */
503
98c9ea5c
JS
504 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
505 if (mp)
506 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
507 if (!mp || !mp->virt) {
c9475cb0 508 kfree(mp);
dea3101e 509 mb->mbxCommand = MBX_READ_SPARM64;
510 /* READ_SPARAM: no buffers */
e8b62011
JS
511 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
512 "0301 READ_SPARAM: no buffers\n");
92d7f7b0 513 return (1);
dea3101e 514 }
515 INIT_LIST_HEAD(&mp->list);
516 mb->mbxCommand = MBX_READ_SPARM64;
517 mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
518 mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
519 mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
92d7f7b0 520 mb->un.varRdSparm.vpi = vpi;
dea3101e 521
522 /* save address for completion */
523 pmb->context1 = mp;
524
92d7f7b0 525 return (0);
dea3101e 526}
527
e59058c4 528/**
3621a710 529 * lpfc_unreg_did - Prepare a mailbox command for unregistering DID
e59058c4
JS
530 * @phba: pointer to lpfc hba data structure.
531 * @vpi: virtual N_Port identifier.
532 * @did: remote port identifier.
533 * @pmb: pointer to the driver internal queue element for mailbox command.
534 *
535 * The unregister DID mailbox command is used to unregister an N_Port/F_Port
536 * login for an unknown RPI by specifying the DID of a remote port. This
537 * command frees an RPI context in the HBA port. This has the effect of
538 * performing an implicit N_Port/F_Port logout.
539 *
540 * This routine prepares the mailbox command for unregistering a remote
541 * N_Port/F_Port (DID) login.
542 **/
dea3101e 543void
92d7f7b0
JS
544lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
545 LPFC_MBOXQ_t * pmb)
dea3101e 546{
547 MAILBOX_t *mb;
548
549 mb = &pmb->mb;
550 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
551
552 mb->un.varUnregDID.did = did;
92d7f7b0 553 mb->un.varUnregDID.vpi = vpi;
dea3101e 554
555 mb->mbxCommand = MBX_UNREG_D_ID;
556 mb->mbxOwner = OWN_HOST;
557 return;
558}
559
e59058c4 560/**
3621a710 561 * lpfc_read_config - Prepare a mailbox command for reading HBA configuration
e59058c4
JS
562 * @phba: pointer to lpfc hba data structure.
563 * @pmb: pointer to the driver internal queue element for mailbox command.
564 *
565 * The read configuration mailbox command is used to read the HBA port
566 * configuration parameters. This mailbox command provides a method for
567 * seeing any parameters that may have changed via various configuration
568 * mailbox commands.
569 *
570 * This routine prepares the mailbox command for reading out HBA configuration
571 * parameters.
572 **/
dea3101e 573void
574lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
575{
576 MAILBOX_t *mb;
577
578 mb = &pmb->mb;
579 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
580
581 mb->mbxCommand = MBX_READ_CONFIG;
582 mb->mbxOwner = OWN_HOST;
583 return;
584}
585
e59058c4 586/**
3621a710 587 * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats
e59058c4
JS
588 * @phba: pointer to lpfc hba data structure.
589 * @pmb: pointer to the driver internal queue element for mailbox command.
590 *
591 * The read link status mailbox command is used to read the link status from
592 * the HBA. Link status includes all link-related error counters. These
593 * counters are maintained by the HBA and originated in the link hardware
594 * unit. Note that all of these counters wrap.
595 *
596 * This routine prepares the mailbox command for reading out HBA link status.
597 **/
7bb3b137
JW
598void
599lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
600{
601 MAILBOX_t *mb;
602
603 mb = &pmb->mb;
604 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
605
606 mb->mbxCommand = MBX_READ_LNK_STAT;
607 mb->mbxOwner = OWN_HOST;
608 return;
609}
610
e59058c4 611/**
3621a710 612 * lpfc_reg_login - Prepare a mailbox command for registering remote login
e59058c4
JS
613 * @phba: pointer to lpfc hba data structure.
614 * @vpi: virtual N_Port identifier.
615 * @did: remote port identifier.
616 * @param: pointer to memory holding the server parameters.
617 * @pmb: pointer to the driver internal queue element for mailbox command.
618 * @flag: action flag to be passed back for the complete function.
619 *
620 * The registration login mailbox command is used to register an N_Port or
621 * F_Port login. This registration allows the HBA to cache the remote N_Port
622 * service parameters internally and thereby make the appropriate FC-2
623 * decisions. The remote port service parameters are handed off by the driver
624 * to the HBA using a descriptor entry that directly identifies a buffer in
625 * host memory. In exchange, the HBA returns an RPI identifier.
626 *
627 * This routine prepares the mailbox command for registering remote port login.
628 * The function allocates DMA buffer for passing the service parameters to the
629 * HBA with the mailbox command.
630 *
631 * Return codes
632 * 0 - Success
633 * 1 - DMA memory allocation failed
634 **/
dea3101e 635int
92d7f7b0
JS
636lpfc_reg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
637 uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
dea3101e 638{
2e0fef85 639 MAILBOX_t *mb = &pmb->mb;
dea3101e 640 uint8_t *sparam;
641 struct lpfc_dmabuf *mp;
dea3101e 642
dea3101e 643 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
644
645 mb->un.varRegLogin.rpi = 0;
92d7f7b0 646 mb->un.varRegLogin.vpi = vpi;
dea3101e 647 mb->un.varRegLogin.did = did;
648 mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */
649
650 mb->mbxOwner = OWN_HOST;
651
652 /* Get a buffer to hold NPorts Service Parameters */
98c9ea5c
JS
653 mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
654 if (mp)
655 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
656 if (!mp || !mp->virt) {
c9475cb0 657 kfree(mp);
dea3101e 658 mb->mbxCommand = MBX_REG_LOGIN64;
659 /* REG_LOGIN: no buffers */
92d7f7b0 660 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
e8b62011
JS
661 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
662 "flag x%x\n", vpi, did, flag);
92d7f7b0 663 return (1);
dea3101e 664 }
665 INIT_LIST_HEAD(&mp->list);
666 sparam = mp->virt;
667
668 /* Copy param's into a new buffer */
669 memcpy(sparam, param, sizeof (struct serv_parm));
670
671 /* save address for completion */
672 pmb->context1 = (uint8_t *) mp;
673
674 mb->mbxCommand = MBX_REG_LOGIN64;
675 mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
676 mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
677 mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
678
92d7f7b0 679 return (0);
dea3101e 680}
681
e59058c4 682/**
3621a710 683 * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login
e59058c4
JS
684 * @phba: pointer to lpfc hba data structure.
685 * @vpi: virtual N_Port identifier.
686 * @rpi: remote port identifier
687 * @pmb: pointer to the driver internal queue element for mailbox command.
688 *
689 * The unregistration login mailbox command is used to unregister an N_Port
690 * or F_Port login. This command frees an RPI context in the HBA. It has the
691 * effect of performing an implicit N_Port/F_Port logout.
692 *
693 * This routine prepares the mailbox command for unregistering remote port
694 * login.
695 **/
dea3101e 696void
92d7f7b0
JS
697lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
698 LPFC_MBOXQ_t * pmb)
dea3101e 699{
700 MAILBOX_t *mb;
701
702 mb = &pmb->mb;
703 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
704
705 mb->un.varUnregLogin.rpi = (uint16_t) rpi;
706 mb->un.varUnregLogin.rsvd1 = 0;
92d7f7b0 707 mb->un.varUnregLogin.vpi = vpi;
dea3101e 708
709 mb->mbxCommand = MBX_UNREG_LOGIN;
710 mb->mbxOwner = OWN_HOST;
711 return;
712}
713
e59058c4 714/**
3621a710 715 * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier
e59058c4
JS
716 * @phba: pointer to lpfc hba data structure.
717 * @vpi: virtual N_Port identifier.
718 * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port).
719 * @pmb: pointer to the driver internal queue element for mailbox command.
720 *
721 * The registration vport identifier mailbox command is used to activate a
722 * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the
723 * N_Port_ID against the information in the selected virtual N_Port context
724 * block and marks it active to allow normal processing of IOCB commands and
725 * received unsolicited exchanges.
726 *
727 * This routine prepares the mailbox command for registering a virtual N_Port.
728 **/
92d7f7b0
JS
729void
730lpfc_reg_vpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t sid,
731 LPFC_MBOXQ_t *pmb)
732{
733 MAILBOX_t *mb = &pmb->mb;
734
735 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
736
737 mb->un.varRegVpi.vpi = vpi;
738 mb->un.varRegVpi.sid = sid;
739
740 mb->mbxCommand = MBX_REG_VPI;
741 mb->mbxOwner = OWN_HOST;
742 return;
743
744}
745
e59058c4 746/**
3621a710 747 * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id
e59058c4
JS
748 * @phba: pointer to lpfc hba data structure.
749 * @vpi: virtual N_Port identifier.
750 * @pmb: pointer to the driver internal queue element for mailbox command.
751 *
752 * The unregistration vport identifier mailbox command is used to inactivate
753 * a virtual N_Port. The driver must have logged out and unregistered all
754 * remote N_Ports to abort any activity on the virtual N_Port. The HBA will
755 * unregisters any default RPIs associated with the specified vpi, aborting
756 * any active exchanges. The HBA will post the mailbox response after making
757 * the virtual N_Port inactive.
758 *
759 * This routine prepares the mailbox command for unregistering a virtual
760 * N_Port.
761 **/
92d7f7b0
JS
762void
763lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
764{
765 MAILBOX_t *mb = &pmb->mb;
766 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
767
768 mb->un.varUnregVpi.vpi = vpi;
769
770 mb->mbxCommand = MBX_UNREG_VPI;
771 mb->mbxOwner = OWN_HOST;
772 return;
773
774}
775
e59058c4 776/**
3621a710 777 * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB)
e59058c4
JS
778 * @phba: pointer to lpfc hba data structure.
779 *
780 * This routine sets up and initializes the IOCB rings in the Port Control
781 * Block (PCB).
782 **/
dea3101e 783static void
784lpfc_config_pcb_setup(struct lpfc_hba * phba)
785{
786 struct lpfc_sli *psli = &phba->sli;
787 struct lpfc_sli_ring *pring;
34b02dcd 788 PCB_t *pcbp = phba->pcb;
dea3101e 789 dma_addr_t pdma_addr;
790 uint32_t offset;
2e0fef85 791 uint32_t iocbCnt = 0;
dea3101e 792 int i;
793
dea3101e 794 pcbp->maxRing = (psli->num_rings - 1);
795
dea3101e 796 for (i = 0; i < psli->num_rings; i++) {
797 pring = &psli->ring[i];
2e0fef85 798
ed957684 799 pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
92d7f7b0 800 SLI2_IOCB_CMD_SIZE;
ed957684 801 pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
92d7f7b0 802 SLI2_IOCB_RSP_SIZE;
dea3101e 803 /* A ring MUST have both cmd and rsp entries defined to be
804 valid */
805 if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
806 pcbp->rdsc[i].cmdEntries = 0;
807 pcbp->rdsc[i].rspEntries = 0;
808 pcbp->rdsc[i].cmdAddrHigh = 0;
809 pcbp->rdsc[i].rspAddrHigh = 0;
810 pcbp->rdsc[i].cmdAddrLow = 0;
811 pcbp->rdsc[i].rspAddrLow = 0;
812 pring->cmdringaddr = NULL;
813 pring->rspringaddr = NULL;
814 continue;
815 }
816 /* Command ring setup for ring */
34b02dcd 817 pring->cmdringaddr = (void *)&phba->IOCBs[iocbCnt];
dea3101e 818 pcbp->rdsc[i].cmdEntries = pring->numCiocb;
819
34b02dcd
JS
820 offset = (uint8_t *) &phba->IOCBs[iocbCnt] -
821 (uint8_t *) phba->slim2p.virt;
822 pdma_addr = phba->slim2p.phys + offset;
dea3101e 823 pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
824 pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
825 iocbCnt += pring->numCiocb;
826
827 /* Response ring setup for ring */
34b02dcd 828 pring->rspringaddr = (void *) &phba->IOCBs[iocbCnt];
dea3101e 829
830 pcbp->rdsc[i].rspEntries = pring->numRiocb;
34b02dcd
JS
831 offset = (uint8_t *)&phba->IOCBs[iocbCnt] -
832 (uint8_t *)phba->slim2p.virt;
833 pdma_addr = phba->slim2p.phys + offset;
dea3101e 834 pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
835 pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
836 iocbCnt += pring->numRiocb;
837 }
838}
839
e59058c4 840/**
3621a710 841 * lpfc_read_rev - Prepare a mailbox command for reading HBA revision
e59058c4
JS
842 * @phba: pointer to lpfc hba data structure.
843 * @pmb: pointer to the driver internal queue element for mailbox command.
844 *
845 * The read revision mailbox command is used to read the revision levels of
846 * the HBA components. These components include hardware units, resident
847 * firmware, and available firmware. HBAs that supports SLI-3 mode of
848 * operation provide different response information depending on the version
849 * requested by the driver.
850 *
851 * This routine prepares the mailbox command for reading HBA revision
852 * information.
853 **/
dea3101e 854void
855lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
856{
2e0fef85 857 MAILBOX_t *mb = &pmb->mb;
dea3101e 858 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
859 mb->un.varRdRev.cv = 1;
ed957684 860 mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
dea3101e 861 mb->mbxCommand = MBX_READ_REV;
862 mb->mbxOwner = OWN_HOST;
863 return;
864}
865
e59058c4 866/**
3621a710 867 * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2
e59058c4
JS
868 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
869 * @hbq_desc: pointer to the HBQ selection profile descriptor.
870 *
871 * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA
872 * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs
873 * the Sequence Length Test using the fields in the Selection Profile 2
874 * extension in words 20:31.
875 **/
ed957684
JS
876static void
877lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
878 struct lpfc_hbq_init *hbq_desc)
879{
880 hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
881 hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
882 hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
883}
884
e59058c4 885/**
3621a710 886 * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3
e59058c4
JS
887 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
888 * @hbq_desc: pointer to the HBQ selection profile descriptor.
889 *
890 * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA
891 * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs
892 * the Sequence Length Test and Byte Field Test using the fields in the
893 * Selection Profile 3 extension in words 20:31.
894 **/
ed957684
JS
895static void
896lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
897 struct lpfc_hbq_init *hbq_desc)
898{
899 hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
900 hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
901 hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
902 hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
903 memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
904 sizeof(hbqmb->profiles.profile3.cmdmatch));
905}
906
e59058c4 907/**
3621a710 908 * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5
e59058c4
JS
909 * @hbqmb: pointer to the HBQ configuration data structure in mailbox command.
910 * @hbq_desc: pointer to the HBQ selection profile descriptor.
911 *
912 * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The
913 * HBA tests the initial frame of an incoming sequence using the frame's
914 * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test
915 * and Byte Field Test using the fields in the Selection Profile 5 extension
916 * words 20:31.
917 **/
ed957684
JS
918static void
919lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
920 struct lpfc_hbq_init *hbq_desc)
921{
922 hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
923 hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
924 hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
925 hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
926 memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
927 sizeof(hbqmb->profiles.profile5.cmdmatch));
928}
929
e59058c4 930/**
3621a710 931 * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ
e59058c4
JS
932 * @phba: pointer to lpfc hba data structure.
933 * @id: HBQ identifier.
934 * @hbq_desc: pointer to the HBA descriptor data structure.
935 * @hbq_entry_index: index of the HBQ entry data structures.
936 * @pmb: pointer to the driver internal queue element for mailbox command.
937 *
938 * The configure HBQ (Host Buffer Queue) mailbox command is used to configure
939 * an HBQ. The configuration binds events that require buffers to a particular
940 * ring and HBQ based on a selection profile.
941 *
942 * This routine prepares the mailbox command for configuring an HBQ.
943 **/
ed957684 944void
51ef4c26
JS
945lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
946 struct lpfc_hbq_init *hbq_desc,
ed957684
JS
947 uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
948{
949 int i;
950 MAILBOX_t *mb = &pmb->mb;
951 struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
952
953 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
51ef4c26 954 hbqmb->hbqId = id;
ed957684
JS
955 hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
956 hbqmb->recvNotify = hbq_desc->rn; /* Receive
957 * Notification */
958 hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
959 * # in words 0-19 */
92d7f7b0 960 hbqmb->profile = hbq_desc->profile; /* Selection profile:
ed957684
JS
961 * 0 = all,
962 * 7 = logentry */
963 hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
964 * e.g. Ring0=b0001,
965 * ring2=b0100 */
966 hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
967 * or 5 */
968 hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
969 * HBQ will be used
970 * for LogEntry
971 * buffers */
972 hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
973 hbq_entry_index * sizeof(struct lpfc_hbq_entry);
974 hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
975
976 mb->mbxCommand = MBX_CONFIG_HBQ;
977 mb->mbxOwner = OWN_HOST;
978
92d7f7b0
JS
979 /* Copy info for profiles 2,3,5. Other
980 * profiles this area is reserved
981 */
ed957684
JS
982 if (hbq_desc->profile == 2)
983 lpfc_build_hbq_profile2(hbqmb, hbq_desc);
984 else if (hbq_desc->profile == 3)
985 lpfc_build_hbq_profile3(hbqmb, hbq_desc);
986 else if (hbq_desc->profile == 5)
987 lpfc_build_hbq_profile5(hbqmb, hbq_desc);
988
989 /* Return if no rctl / type masks for this HBQ */
990 if (!hbq_desc->mask_count)
991 return;
992
993 /* Otherwise we setup specific rctl / type masks for this HBQ */
994 for (i = 0; i < hbq_desc->mask_count; i++) {
995 hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
996 hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
997 hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
998 hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
999 }
1000
1001 return;
1002}
1003
e59058c4 1004/**
3621a710 1005 * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring
e59058c4
JS
1006 * @phba: pointer to lpfc hba data structure.
1007 * @ring:
1008 * @pmb: pointer to the driver internal queue element for mailbox command.
1009 *
1010 * The configure ring mailbox command is used to configure an IOCB ring. This
1011 * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the
1012 * ring. This is used to map incoming sequences to a particular ring whose
1013 * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not
1014 * attempt to configure a ring whose number is greater than the number
1015 * specified in the Port Control Block (PCB). It is an error to issue the
1016 * configure ring command more than once with the same ring number. The HBA
1017 * returns an error if the driver attempts this.
1018 *
1019 * This routine prepares the mailbox command for configuring IOCB ring.
1020 **/
dea3101e 1021void
1022lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
1023{
1024 int i;
1025 MAILBOX_t *mb = &pmb->mb;
1026 struct lpfc_sli *psli;
1027 struct lpfc_sli_ring *pring;
1028
1029 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
1030
1031 mb->un.varCfgRing.ring = ring;
1032 mb->un.varCfgRing.maxOrigXchg = 0;
1033 mb->un.varCfgRing.maxRespXchg = 0;
1034 mb->un.varCfgRing.recvNotify = 1;
1035
1036 psli = &phba->sli;
1037 pring = &psli->ring[ring];
1038 mb->un.varCfgRing.numMask = pring->num_mask;
1039 mb->mbxCommand = MBX_CONFIG_RING;
1040 mb->mbxOwner = OWN_HOST;
1041
1042 /* Is this ring configured for a specific profile */
1043 if (pring->prt[0].profile) {
1044 mb->un.varCfgRing.profile = pring->prt[0].profile;
1045 return;
1046 }
1047
1048 /* Otherwise we setup specific rctl / type masks for this ring */
1049 for (i = 0; i < pring->num_mask; i++) {
1050 mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
1051 if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ)
1052 mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
1053 else
1054 mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
1055 mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
1056 mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
1057 }
1058
1059 return;
1060}
1061
e59058c4 1062/**
3621a710 1063 * lpfc_config_port - Prepare a mailbox command for configuring port
e59058c4
JS
1064 * @phba: pointer to lpfc hba data structure.
1065 * @pmb: pointer to the driver internal queue element for mailbox command.
1066 *
1067 * The configure port mailbox command is used to identify the Port Control
1068 * Block (PCB) in the driver memory. After this command is issued, the
1069 * driver must not access the mailbox in the HBA without first resetting
1070 * the HBA. The HBA may copy the PCB information to internal storage for
1071 * subsequent use; the driver can not change the PCB information unless it
1072 * resets the HBA.
1073 *
1074 * This routine prepares the mailbox command for configuring port.
1075 **/
dea3101e 1076void
92d7f7b0 1077lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea3101e 1078{
ed957684 1079 MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
dea3101e 1080 MAILBOX_t *mb = &pmb->mb;
1081 dma_addr_t pdma_addr;
1082 uint32_t bar_low, bar_high;
1083 size_t offset;
4cc2da1d 1084 struct lpfc_hgp hgp;
f91b392c 1085 int i;
ed957684 1086 uint32_t pgp_offset;
dea3101e 1087
1088 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1089 mb->mbxCommand = MBX_CONFIG_PORT;
1090 mb->mbxOwner = OWN_HOST;
1091
1092 mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
1093
34b02dcd
JS
1094 offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt;
1095 pdma_addr = phba->slim2p.phys + offset;
dea3101e 1096 mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
1097 mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
1098
97207482
JS
1099 /* Always Host Group Pointer is in SLIM */
1100 mb->un.varCfgPort.hps = 1;
1101
ed957684
JS
1102 /* If HBA supports SLI=3 ask for it */
1103
92d7f7b0 1104 if (phba->sli_rev == 3 && phba->vpd.sli3Feat.cerbm) {
e2a0a9d6
JS
1105 if (phba->cfg_enable_bg)
1106 mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
ed957684 1107 mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
34b02dcd
JS
1108 mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
1109 mb->un.varCfgPort.cinb = 1; /* Interrupt Notification Block */
51ef4c26 1110 mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
78b2d852 1111 if (phba->max_vpi && phba->cfg_enable_npiv &&
92d7f7b0
JS
1112 phba->vpd.sli3Feat.cmv) {
1113 mb->un.varCfgPort.max_vpi = phba->max_vpi;
1114 mb->un.varCfgPort.cmv = 1;
92d7f7b0
JS
1115 } else
1116 mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
1117 } else
1118 phba->sli_rev = 2;
1119 mb->un.varCfgPort.sli_mode = phba->sli_rev;
ed957684 1120
dea3101e 1121 /* Now setup pcb */
34b02dcd
JS
1122 phba->pcb->type = TYPE_NATIVE_SLI2;
1123 phba->pcb->feature = FEATURE_INITIAL_SLI2;
dea3101e 1124
1125 /* Setup Mailbox pointers */
34b02dcd
JS
1126 phba->pcb->mailBoxSize = sizeof(MAILBOX_t);
1127 offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt;
1128 pdma_addr = phba->slim2p.phys + offset;
1129 phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr);
1130 phba->pcb->mbAddrLow = putPaddrLow(pdma_addr);
dea3101e 1131
1132 /*
1133 * Setup Host Group ring pointer.
1134 *
1135 * For efficiency reasons, the ring get/put pointers can be
1136 * placed in adapter memory (SLIM) rather than in host memory.
1137 * This allows firmware to avoid PCI reads/writes when updating
1138 * and checking pointers.
1139 *
1140 * The firmware recognizes the use of SLIM memory by comparing
1141 * the address of the get/put pointers structure with that of
1142 * the SLIM BAR (BAR0).
1143 *
1144 * Caution: be sure to use the PCI config space value of BAR0/BAR1
1145 * (the hardware's view of the base address), not the OS's
1146 * value of pci_resource_start() as the OS value may be a cookie
1147 * for ioremap/iomap.
1148 */
1149
1150
1151 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
1152 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
1153
ed957684
JS
1154 /*
1155 * Set up HGP - Port Memory
1156 *
1157 * The port expects the host get/put pointers to reside in memory
1158 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
1159 * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
1160 * words (0x40 bytes). This area is not reserved if HBQs are
1161 * configured in SLI-3.
1162 *
1163 * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
1164 * RR0Get 0xc4 0x84
1165 * CR1Put 0xc8 0x88
1166 * RR1Get 0xcc 0x8c
1167 * CR2Put 0xd0 0x90
1168 * RR2Get 0xd4 0x94
1169 * CR3Put 0xd8 0x98
1170 * RR3Get 0xdc 0x9c
1171 *
1172 * Reserved 0xa0-0xbf
1173 * If HBQs configured:
1174 * HBQ 0 Put ptr 0xc0
1175 * HBQ 1 Put ptr 0xc4
1176 * HBQ 2 Put ptr 0xc8
1177 * ......
1178 * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
1179 *
1180 */
1181
1182 if (phba->sli_rev == 3) {
1183 phba->host_gp = &mb_slim->us.s3.host[0];
1184 phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
1185 } else {
1186 phba->host_gp = &mb_slim->us.s2.host[0];
1187 phba->hbq_put = NULL;
1188 }
dea3101e 1189
1190 /* mask off BAR0's flag bits 0 - 3 */
34b02dcd
JS
1191 phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
1192 (void __iomem *)phba->host_gp -
ed957684 1193 (void __iomem *)phba->MBslimaddr;
dea3101e 1194 if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
34b02dcd 1195 phba->pcb->hgpAddrHigh = bar_high;
dea3101e 1196 else
34b02dcd 1197 phba->pcb->hgpAddrHigh = 0;
dea3101e 1198 /* write HGP data to SLIM at the required longword offset */
4cc2da1d 1199 memset(&hgp, 0, sizeof(struct lpfc_hgp));
f91b392c
JSEC
1200
1201 for (i=0; i < phba->sli.num_rings; i++) {
ed957684
JS
1202 lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
1203 sizeof(*phba->host_gp));
f91b392c 1204 }
dea3101e 1205
8f34f4ce
JS
1206 /* Setup Port Group offset */
1207 if (phba->sli_rev == 3)
34b02dcd
JS
1208 pgp_offset = offsetof(struct lpfc_sli2_slim,
1209 mbx.us.s3_pgp.port);
8f34f4ce 1210 else
34b02dcd
JS
1211 pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port);
1212 pdma_addr = phba->slim2p.phys + pgp_offset;
1213 phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr);
1214 phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr);
dea3101e 1215
1216 /* Use callback routine to setp rings in the pcb */
1217 lpfc_config_pcb_setup(phba);
1218
1219 /* special handling for LC HBAs */
1220 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
1221 uint32_t hbainit[5];
1222
1223 lpfc_hba_init(phba, hbainit);
1224
1225 memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
1226 }
1227
1228 /* Swap PCB if needed */
34b02dcd 1229 lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t));
dea3101e 1230}
1231
e59058c4 1232/**
3621a710 1233 * lpfc_kill_board - Prepare a mailbox command for killing board
e59058c4
JS
1234 * @phba: pointer to lpfc hba data structure.
1235 * @pmb: pointer to the driver internal queue element for mailbox command.
1236 *
1237 * The kill board mailbox command is used to tell firmware to perform a
1238 * graceful shutdown of a channel on a specified board to prepare for reset.
1239 * When the kill board mailbox command is received, the ER3 bit is set to 1
1240 * in the Host Status register and the ER Attention bit is set to 1 in the
1241 * Host Attention register of the HBA function that received the kill board
1242 * command.
1243 *
1244 * This routine prepares the mailbox command for killing the board in
1245 * preparation for a graceful shutdown.
1246 **/
41415862
JW
1247void
1248lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1249{
1250 MAILBOX_t *mb = &pmb->mb;
1251
1252 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1253 mb->mbxCommand = MBX_KILL_BOARD;
1254 mb->mbxOwner = OWN_HOST;
1255 return;
1256}
1257
e59058c4 1258/**
3621a710 1259 * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue
e59058c4
JS
1260 * @phba: pointer to lpfc hba data structure.
1261 * @mbq: pointer to the driver internal queue element for mailbox command.
1262 *
1263 * Driver maintains a internal mailbox command queue implemented as a linked
1264 * list. When a mailbox command is issued, it shall be put into the mailbox
1265 * command queue such that they shall be processed orderly as HBA can process
1266 * one mailbox command at a time.
1267 **/
dea3101e 1268void
1269lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1270{
1271 struct lpfc_sli *psli;
1272
1273 psli = &phba->sli;
1274
1275 list_add_tail(&mbq->list, &psli->mboxq);
1276
1277 psli->mboxq_cnt++;
1278
1279 return;
1280}
1281
e59058c4 1282/**
3621a710 1283 * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue
e59058c4
JS
1284 * @phba: pointer to lpfc hba data structure.
1285 *
1286 * Driver maintains a internal mailbox command queue implemented as a linked
1287 * list. When a mailbox command is issued, it shall be put into the mailbox
1288 * command queue such that they shall be processed orderly as HBA can process
1289 * one mailbox command at a time. After HBA finished processing a mailbox
1290 * command, the driver will remove a pending mailbox command from the head of
1291 * the mailbox command queue and send to the HBA for processing.
1292 *
1293 * Return codes
1294 * pointer to the driver internal queue element for mailbox command.
1295 **/
dea3101e 1296LPFC_MBOXQ_t *
1297lpfc_mbox_get(struct lpfc_hba * phba)
1298{
1299 LPFC_MBOXQ_t *mbq = NULL;
1300 struct lpfc_sli *psli = &phba->sli;
1301
2e0fef85 1302 list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
92d7f7b0 1303 if (mbq)
dea3101e 1304 psli->mboxq_cnt--;
dea3101e 1305
1306 return mbq;
1307}
a309a6b6 1308
e59058c4 1309/**
3621a710 1310 * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
e59058c4
JS
1311 * @phba: pointer to lpfc hba data structure.
1312 * @mbq: pointer to the driver internal queue element for mailbox command.
1313 *
1314 * This routine put the completed mailbox command into the mailbox command
1315 * complete list. This routine is called from driver interrupt handler
1316 * context.The mailbox complete list is used by the driver worker thread
1317 * to process mailbox complete callback functions outside the driver interrupt
1318 * handler.
1319 **/
92d7f7b0
JS
1320void
1321lpfc_mbox_cmpl_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
1322{
5b75da2f
JS
1323 unsigned long iflag;
1324
b1c11812 1325 /* This function expects to be called from interrupt context */
5b75da2f 1326 spin_lock_irqsave(&phba->hbalock, iflag);
92d7f7b0 1327 list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
5b75da2f 1328 spin_unlock_irqrestore(&phba->hbalock, iflag);
92d7f7b0
JS
1329 return;
1330}
1331
e59058c4 1332/**
3621a710 1333 * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
e59058c4
JS
1334 * @phba: pointer to lpfc hba data structure.
1335 * @cmd: mailbox command code.
1336 *
1337 * This routine retrieves the proper timeout value according to the mailbox
1338 * command code.
1339 *
1340 * Return codes
1341 * Timeout value to be used for the given mailbox command
1342 **/
a309a6b6
JS
1343int
1344lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
1345{
1346 switch (cmd) {
1347 case MBX_WRITE_NV: /* 0x03 */
1348 case MBX_UPDATE_CFG: /* 0x1B */
1349 case MBX_DOWN_LOAD: /* 0x1C */
1350 case MBX_DEL_LD_ENTRY: /* 0x1D */
1351 case MBX_LOAD_AREA: /* 0x81 */
09372820 1352 case MBX_WRITE_WWN: /* 0x98 */
a309a6b6
JS
1353 case MBX_LOAD_EXP_ROM: /* 0x9C */
1354 return LPFC_MBOX_TMO_FLASH_CMD;
1355 }
1356 return LPFC_MBOX_TMO;
1357}
This page took 0.477972 seconds and 5 git commands to generate.