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