1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2005 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
26 #include <scsi/scsi_device.h>
27 #include <scsi/scsi_transport_fc.h>
29 #include <scsi/scsi.h>
33 #include "lpfc_disc.h"
34 #include "lpfc_scsi.h"
36 #include "lpfc_logmsg.h"
37 #include "lpfc_crtn.h"
38 #include "lpfc_compat.h"
40 /**********************************************/
43 /**********************************************/
45 lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset)
53 /* Setup to dump VPD region */
54 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
55 mb->mbxCommand = MBX_DUMP_MEMORY;
57 mb->un.varDmp.type = DMP_NV_PARAMS;
58 mb->un.varDmp.entry_index = offset;
59 mb->un.varDmp.region_id = DMP_REGION_VPD;
60 mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
62 mb->un.varDmp.resp_offset = 0;
64 mb->mbxOwner = OWN_HOST;
68 /**********************************************/
69 /* lpfc_read_nv Issue a READ NVPARAM */
71 /**********************************************/
73 lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
78 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
79 mb->mbxCommand = MBX_READ_NV;
80 mb->mbxOwner = OWN_HOST;
84 /**********************************************/
85 /* lpfc_read_la Issue a READ LA */
87 /**********************************************/
89 lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
92 struct lpfc_sli *psli;
96 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
98 INIT_LIST_HEAD(&mp->list);
99 mb->mbxCommand = MBX_READ_LA64;
100 mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128;
101 mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
102 mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys);
104 /* Save address for later completion and set the owner to host so that
105 * the FW knows this mailbox is available for processing.
107 pmb->context1 = (uint8_t *) mp;
108 mb->mbxOwner = OWN_HOST;
112 /**********************************************/
113 /* lpfc_clear_la Issue a CLEAR LA */
114 /* mailbox command */
115 /**********************************************/
117 lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
122 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
124 mb->un.varClearLA.eventTag = phba->fc_eventTag;
125 mb->mbxCommand = MBX_CLEAR_LA;
126 mb->mbxOwner = OWN_HOST;
130 /**************************************************/
131 /* lpfc_config_link Issue a CONFIG LINK */
132 /* mailbox command */
133 /**************************************************/
135 lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
137 MAILBOX_t *mb = &pmb->mb;
138 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
141 * SLI-2, Coalescing Response Feature.
143 if (phba->cfg_cr_delay) {
144 mb->un.varCfgLnk.cr = 1;
145 mb->un.varCfgLnk.ci = 1;
146 mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
147 mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
150 mb->un.varCfgLnk.myId = phba->fc_myDID;
151 mb->un.varCfgLnk.edtov = phba->fc_edtov;
152 mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
153 mb->un.varCfgLnk.ratov = phba->fc_ratov;
154 mb->un.varCfgLnk.rttov = phba->fc_rttov;
155 mb->un.varCfgLnk.altov = phba->fc_altov;
156 mb->un.varCfgLnk.crtov = phba->fc_crtov;
157 mb->un.varCfgLnk.citov = phba->fc_citov;
160 mb->un.varCfgLnk.ack0_enable = 1;
162 mb->mbxCommand = MBX_CONFIG_LINK;
163 mb->mbxOwner = OWN_HOST;
167 /**********************************************/
168 /* lpfc_init_link Issue an INIT LINK */
169 /* mailbox command */
170 /**********************************************/
172 lpfc_init_link(struct lpfc_hba * phba,
173 LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
176 struct lpfc_sli *psli;
180 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
184 case FLAGS_TOPOLOGY_MODE_LOOP_PT:
185 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
186 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
188 case FLAGS_TOPOLOGY_MODE_PT_PT:
189 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
191 case FLAGS_TOPOLOGY_MODE_LOOP:
192 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
194 case FLAGS_TOPOLOGY_MODE_PT_LOOP:
195 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
196 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
201 * Setting up the link speed
204 if (vpd->rev.feaLevelHigh >= 0x02){
209 mb->un.varInitLnk.link_flags |=
211 mb->un.varInitLnk.link_speed = linkspeed;
213 case LINK_SPEED_AUTO:
215 mb->un.varInitLnk.link_speed =
222 mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
224 mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
225 mb->mbxOwner = OWN_HOST;
226 mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
230 /**********************************************/
231 /* lpfc_read_sparam Issue a READ SPARAM */
232 /* mailbox command */
233 /**********************************************/
235 lpfc_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
237 struct lpfc_dmabuf *mp;
239 struct lpfc_sli *psli;
243 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
245 mb->mbxOwner = OWN_HOST;
247 /* Get a buffer to hold the HBAs Service Parameters */
249 if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
250 ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) {
252 mb->mbxCommand = MBX_READ_SPARM64;
253 /* READ_SPARAM: no buffers */
254 lpfc_printf_log(phba,
257 "%d:0301 READ_SPARAM: no buffers\n",
261 INIT_LIST_HEAD(&mp->list);
262 mb->mbxCommand = MBX_READ_SPARM64;
263 mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
264 mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
265 mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
267 /* save address for completion */
273 /********************************************/
274 /* lpfc_unreg_did Issue a UNREG_DID */
275 /* mailbox command */
276 /********************************************/
278 lpfc_unreg_did(struct lpfc_hba * phba, uint32_t did, LPFC_MBOXQ_t * pmb)
283 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
285 mb->un.varUnregDID.did = did;
287 mb->mbxCommand = MBX_UNREG_D_ID;
288 mb->mbxOwner = OWN_HOST;
292 /***********************************************/
294 /* command to write slim */
295 /***********************************************/
297 lpfc_set_slim(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint32_t addr,
303 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
305 /* addr = 0x090597 is AUTO ABTS disable for ELS commands */
306 /* addr = 0x052198 is DELAYED ABTS enable for ELS commands */
309 * Always turn on DELAYED ABTS for ELS timeouts
311 if ((addr == 0x052198) && (value == 0))
314 mb->un.varWords[0] = addr;
315 mb->un.varWords[1] = value;
317 mb->mbxCommand = MBX_SET_SLIM;
318 mb->mbxOwner = OWN_HOST;
322 /**********************************************/
323 /* lpfc_read_nv Issue a READ CONFIG */
324 /* mailbox command */
325 /**********************************************/
327 lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
332 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
334 mb->mbxCommand = MBX_READ_CONFIG;
335 mb->mbxOwner = OWN_HOST;
339 /*************************************************/
340 /* lpfc_read_lnk_stat Issue a READ LINK STATUS */
341 /* mailbox command */
342 /*************************************************/
344 lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
349 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
351 mb->mbxCommand = MBX_READ_LNK_STAT;
352 mb->mbxOwner = OWN_HOST;
356 /********************************************/
357 /* lpfc_reg_login Issue a REG_LOGIN */
358 /* mailbox command */
359 /********************************************/
361 lpfc_reg_login(struct lpfc_hba * phba,
362 uint32_t did, uint8_t * param, LPFC_MBOXQ_t * pmb, uint32_t flag)
365 struct lpfc_dmabuf *mp;
367 struct lpfc_sli *psli;
371 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
373 mb->un.varRegLogin.rpi = 0;
374 mb->un.varRegLogin.did = did;
375 mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */
377 mb->mbxOwner = OWN_HOST;
379 /* Get a buffer to hold NPorts Service Parameters */
380 if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == NULL) ||
381 ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) {
383 mb->mbxCommand = MBX_REG_LOGIN64;
384 /* REG_LOGIN: no buffers */
385 lpfc_printf_log(phba,
388 "%d:0302 REG_LOGIN: no buffers Data x%x x%x\n",
390 (uint32_t) did, (uint32_t) flag);
393 INIT_LIST_HEAD(&mp->list);
396 /* Copy param's into a new buffer */
397 memcpy(sparam, param, sizeof (struct serv_parm));
399 /* save address for completion */
400 pmb->context1 = (uint8_t *) mp;
402 mb->mbxCommand = MBX_REG_LOGIN64;
403 mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
404 mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
405 mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
410 /**********************************************/
411 /* lpfc_unreg_login Issue a UNREG_LOGIN */
412 /* mailbox command */
413 /**********************************************/
415 lpfc_unreg_login(struct lpfc_hba * phba, uint32_t rpi, LPFC_MBOXQ_t * pmb)
420 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
422 mb->un.varUnregLogin.rpi = (uint16_t) rpi;
423 mb->un.varUnregLogin.rsvd1 = 0;
425 mb->mbxCommand = MBX_UNREG_LOGIN;
426 mb->mbxOwner = OWN_HOST;
431 lpfc_config_pcb_setup(struct lpfc_hba * phba)
433 struct lpfc_sli *psli = &phba->sli;
434 struct lpfc_sli_ring *pring;
435 PCB_t *pcbp = &phba->slim2p->pcb;
436 dma_addr_t pdma_addr;
441 pcbp->maxRing = (psli->num_rings - 1);
444 for (i = 0; i < psli->num_rings; i++) {
445 pring = &psli->ring[i];
446 /* A ring MUST have both cmd and rsp entries defined to be
448 if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
449 pcbp->rdsc[i].cmdEntries = 0;
450 pcbp->rdsc[i].rspEntries = 0;
451 pcbp->rdsc[i].cmdAddrHigh = 0;
452 pcbp->rdsc[i].rspAddrHigh = 0;
453 pcbp->rdsc[i].cmdAddrLow = 0;
454 pcbp->rdsc[i].rspAddrLow = 0;
455 pring->cmdringaddr = NULL;
456 pring->rspringaddr = NULL;
459 /* Command ring setup for ring */
461 (void *)&phba->slim2p->IOCBs[iocbCnt];
462 pcbp->rdsc[i].cmdEntries = pring->numCiocb;
464 offset = (uint8_t *)&phba->slim2p->IOCBs[iocbCnt] -
465 (uint8_t *)phba->slim2p;
466 pdma_addr = phba->slim2p_mapping + offset;
467 pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
468 pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
469 iocbCnt += pring->numCiocb;
471 /* Response ring setup for ring */
473 (void *)&phba->slim2p->IOCBs[iocbCnt];
475 pcbp->rdsc[i].rspEntries = pring->numRiocb;
476 offset = (uint8_t *)&phba->slim2p->IOCBs[iocbCnt] -
477 (uint8_t *)phba->slim2p;
478 pdma_addr = phba->slim2p_mapping + offset;
479 pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
480 pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
481 iocbCnt += pring->numRiocb;
486 lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
491 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
492 mb->un.varRdRev.cv = 1;
493 mb->mbxCommand = MBX_READ_REV;
494 mb->mbxOwner = OWN_HOST;
499 lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
502 MAILBOX_t *mb = &pmb->mb;
503 struct lpfc_sli *psli;
504 struct lpfc_sli_ring *pring;
506 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
508 mb->un.varCfgRing.ring = ring;
509 mb->un.varCfgRing.maxOrigXchg = 0;
510 mb->un.varCfgRing.maxRespXchg = 0;
511 mb->un.varCfgRing.recvNotify = 1;
514 pring = &psli->ring[ring];
515 mb->un.varCfgRing.numMask = pring->num_mask;
516 mb->mbxCommand = MBX_CONFIG_RING;
517 mb->mbxOwner = OWN_HOST;
519 /* Is this ring configured for a specific profile */
520 if (pring->prt[0].profile) {
521 mb->un.varCfgRing.profile = pring->prt[0].profile;
525 /* Otherwise we setup specific rctl / type masks for this ring */
526 for (i = 0; i < pring->num_mask; i++) {
527 mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
528 if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ)
529 mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
531 mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
532 mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
533 mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
540 lpfc_config_port(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
542 MAILBOX_t *mb = &pmb->mb;
543 dma_addr_t pdma_addr;
544 uint32_t bar_low, bar_high;
547 void __iomem *to_slim;
550 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
551 mb->mbxCommand = MBX_CONFIG_PORT;
552 mb->mbxOwner = OWN_HOST;
554 mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
556 offset = (uint8_t *)&phba->slim2p->pcb - (uint8_t *)phba->slim2p;
557 pdma_addr = phba->slim2p_mapping + offset;
558 mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
559 mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
562 phba->slim2p->pcb.type = TYPE_NATIVE_SLI2;
563 phba->slim2p->pcb.feature = FEATURE_INITIAL_SLI2;
565 /* Setup Mailbox pointers */
566 phba->slim2p->pcb.mailBoxSize = sizeof(MAILBOX_t);
567 offset = (uint8_t *)&phba->slim2p->mbx - (uint8_t *)phba->slim2p;
568 pdma_addr = phba->slim2p_mapping + offset;
569 phba->slim2p->pcb.mbAddrHigh = putPaddrHigh(pdma_addr);
570 phba->slim2p->pcb.mbAddrLow = putPaddrLow(pdma_addr);
573 * Setup Host Group ring pointer.
575 * For efficiency reasons, the ring get/put pointers can be
576 * placed in adapter memory (SLIM) rather than in host memory.
577 * This allows firmware to avoid PCI reads/writes when updating
578 * and checking pointers.
580 * The firmware recognizes the use of SLIM memory by comparing
581 * the address of the get/put pointers structure with that of
582 * the SLIM BAR (BAR0).
584 * Caution: be sure to use the PCI config space value of BAR0/BAR1
585 * (the hardware's view of the base address), not the OS's
586 * value of pci_resource_start() as the OS value may be a cookie
591 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
592 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
595 /* mask off BAR0's flag bits 0 - 3 */
596 phba->slim2p->pcb.hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
597 (SLIMOFF*sizeof(uint32_t));
598 if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
599 phba->slim2p->pcb.hgpAddrHigh = bar_high;
601 phba->slim2p->pcb.hgpAddrHigh = 0;
602 /* write HGP data to SLIM at the required longword offset */
603 memset(&hgp, 0, sizeof(struct lpfc_hgp));
604 to_slim = phba->MBslimaddr + (SLIMOFF*sizeof (uint32_t));
606 for (i=0; i < phba->sli.num_rings; i++) {
607 lpfc_memcpy_to_slim(to_slim, &hgp, sizeof(struct lpfc_hgp));
608 to_slim += sizeof (struct lpfc_hgp);
611 /* Setup Port Group ring pointer */
612 offset = (uint8_t *)&phba->slim2p->mbx.us.s2.port -
613 (uint8_t *)phba->slim2p;
614 pdma_addr = phba->slim2p_mapping + offset;
615 phba->slim2p->pcb.pgpAddrHigh = putPaddrHigh(pdma_addr);
616 phba->slim2p->pcb.pgpAddrLow = putPaddrLow(pdma_addr);
618 /* Use callback routine to setp rings in the pcb */
619 lpfc_config_pcb_setup(phba);
621 /* special handling for LC HBAs */
622 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
625 lpfc_hba_init(phba, hbainit);
627 memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
630 /* Swap PCB if needed */
631 lpfc_sli_pcimem_bcopy(&phba->slim2p->pcb, &phba->slim2p->pcb,
634 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
635 "%d:0405 Service Level Interface (SLI) 2 selected\n",
640 lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
642 struct lpfc_sli *psli;
646 list_add_tail(&mbq->list, &psli->mboxq);
654 lpfc_mbox_get(struct lpfc_hba * phba)
656 LPFC_MBOXQ_t *mbq = NULL;
657 struct lpfc_sli *psli = &phba->sli;
659 list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t,