aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/lpfc/lpfc_sli.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_sli.c')
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c698
1 files changed, 570 insertions, 128 deletions
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 1edac15eed40..6e0b42bcebe7 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -65,6 +65,25 @@ typedef enum _lpfc_iocb_type {
65 LPFC_ABORT_IOCB 65 LPFC_ABORT_IOCB
66} lpfc_iocb_type; 66} lpfc_iocb_type;
67 67
68/*
69 * SLI-2/SLI-3 provide different sized iocbs. Given a pointer to the start of
70 * the ring, and the slot number of the desired iocb entry, calc a pointer to
71 * that entry.
72 */
73static inline IOCB_t *
74lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
75{
76 return (IOCB_t *) (((char *) pring->cmdringaddr) +
77 pring->cmdidx * phba->iocb_cmd_size);
78}
79
80static inline IOCB_t *
81lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
82{
83 return (IOCB_t *) (((char *) pring->rspringaddr) +
84 pring->rspidx * phba->iocb_rsp_size);
85}
86
68static struct lpfc_iocbq * 87static struct lpfc_iocbq *
69__lpfc_sli_get_iocbq(struct lpfc_hba *phba) 88__lpfc_sli_get_iocbq(struct lpfc_hba *phba)
70{ 89{
@@ -180,6 +199,9 @@ lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
180 case CMD_RCV_ELS_REQ_CX: 199 case CMD_RCV_ELS_REQ_CX:
181 case CMD_RCV_SEQUENCE64_CX: 200 case CMD_RCV_SEQUENCE64_CX:
182 case CMD_RCV_ELS_REQ64_CX: 201 case CMD_RCV_ELS_REQ64_CX:
202 case CMD_IOCB_RCV_SEQ64_CX:
203 case CMD_IOCB_RCV_ELS64_CX:
204 case CMD_IOCB_RCV_CONT64_CX:
183 type = LPFC_UNSOL_IOCB; 205 type = LPFC_UNSOL_IOCB;
184 break; 206 break;
185 default: 207 default:
@@ -191,14 +213,19 @@ lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
191} 213}
192 214
193static int 215static int
194lpfc_sli_ring_map(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 216lpfc_sli_ring_map(struct lpfc_hba *phba)
195{ 217{
196 struct lpfc_sli *psli = &phba->sli; 218 struct lpfc_sli *psli = &phba->sli;
197 MAILBOX_t *pmbox = &pmb->mb; 219 LPFC_MBOXQ_t *pmb;
198 int i, rc; 220 MAILBOX_t *pmbox;
221 int i, rc, ret = 0;
199 222
223 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
224 if (!pmb)
225 return -ENOMEM;
226 pmbox = &pmb->mb;
227 phba->link_state = LPFC_INIT_MBX_CMDS;
200 for (i = 0; i < psli->num_rings; i++) { 228 for (i = 0; i < psli->num_rings; i++) {
201 phba->link_state = LPFC_INIT_MBX_CMDS;
202 lpfc_config_ring(phba, i, pmb); 229 lpfc_config_ring(phba, i, pmb);
203 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); 230 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
204 if (rc != MBX_SUCCESS) { 231 if (rc != MBX_SUCCESS) {
@@ -213,10 +240,12 @@ lpfc_sli_ring_map(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
213 pmbox->mbxStatus, 240 pmbox->mbxStatus,
214 i); 241 i);
215 phba->link_state = LPFC_HBA_ERROR; 242 phba->link_state = LPFC_HBA_ERROR;
216 return -ENXIO; 243 ret = -ENXIO;
244 break;
217 } 245 }
218 } 246 }
219 return 0; 247 mempool_free(pmb, phba->mbox_mem_pool);
248 return ret;
220} 249}
221 250
222static int 251static int
@@ -255,9 +284,10 @@ lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
255static IOCB_t * 284static IOCB_t *
256lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 285lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
257{ 286{
258 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno]; 287 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
288 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
289 &phba->slim2p->mbx.us.s2.port[pring->ringno];
259 uint32_t max_cmd_idx = pring->numCiocb; 290 uint32_t max_cmd_idx = pring->numCiocb;
260 IOCB_t *iocb = NULL;
261 291
262 if ((pring->next_cmdidx == pring->cmdidx) && 292 if ((pring->next_cmdidx == pring->cmdidx) &&
263 (++pring->next_cmdidx >= max_cmd_idx)) 293 (++pring->next_cmdidx >= max_cmd_idx))
@@ -291,9 +321,7 @@ lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
291 return NULL; 321 return NULL;
292 } 322 }
293 323
294 iocb = IOCB_ENTRY(pring->cmdringaddr, pring->cmdidx); 324 return lpfc_cmd_iocb(phba, pring);
295
296 return iocb;
297} 325}
298 326
299uint16_t 327uint16_t
@@ -390,8 +418,7 @@ lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
390 * driver will put a command into. 418 * driver will put a command into.
391 */ 419 */
392 pring->cmdidx = pring->next_cmdidx; 420 pring->cmdidx = pring->next_cmdidx;
393 writel(pring->cmdidx, phba->MBslimaddr 421 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
394 + (SLIMOFF + (pring->ringno * 2)) * 4);
395} 422}
396 423
397static void 424static void
@@ -462,7 +489,9 @@ lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
462static void 489static void
463lpfc_sli_turn_on_ring(struct lpfc_hba *phba, int ringno) 490lpfc_sli_turn_on_ring(struct lpfc_hba *phba, int ringno)
464{ 491{
465 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[ringno]; 492 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
493 &phba->slim2p->mbx.us.s3_pgp.port[ringno] :
494 &phba->slim2p->mbx.us.s2.port[ringno];
466 unsigned long iflags; 495 unsigned long iflags;
467 496
468 /* If the ring is active, flag it */ 497 /* If the ring is active, flag it */
@@ -481,6 +510,168 @@ lpfc_sli_turn_on_ring(struct lpfc_hba *phba, int ringno)
481 spin_unlock_irqrestore(&phba->hbalock, iflags); 510 spin_unlock_irqrestore(&phba->hbalock, iflags);
482} 511}
483 512
513struct lpfc_hbq_entry *
514lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
515{
516 struct hbq_s *hbqp = &phba->hbqs[hbqno];
517
518 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
519 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
520 hbqp->next_hbqPutIdx = 0;
521
522 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
523 uint32_t raw_index = readl(&phba->hbq_get[hbqno]);
524 uint32_t getidx = le32_to_cpu(raw_index);
525
526 hbqp->local_hbqGetIdx = getidx;
527
528 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
529 lpfc_printf_log(phba, KERN_ERR,
530 LOG_SLI,
531 "%d:1802 HBQ %d: local_hbqGetIdx "
532 "%u is > than hbqp->entry_count %u\n",
533 phba->brd_no, hbqno,
534 hbqp->local_hbqGetIdx,
535 hbqp->entry_count);
536
537 phba->link_state = LPFC_HBA_ERROR;
538 return NULL;
539 }
540
541 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
542 return NULL;
543 }
544
545 return (struct lpfc_hbq_entry *) phba->hbqslimp.virt + hbqp->hbqPutIdx;
546}
547
548void
549lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
550{
551 uint32_t i;
552
553 if (!phba->hbq_buffer_pool)
554 return;
555 /* Return all memory used by all HBQs */
556 for (i = 0; i < phba->hbq_buffer_count; i++) {
557 lpfc_hbq_free(phba, phba->hbq_buffer_pool[i].dbuf.virt,
558 phba->hbq_buffer_pool[i].dbuf.phys);
559 }
560 kfree(phba->hbq_buffer_pool);
561 phba->hbq_buffer_pool = NULL;
562}
563
564static void
565lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
566 struct hbq_dmabuf *hbq_buf_desc)
567{
568 struct lpfc_hbq_entry *hbqe;
569
570 /* Get next HBQ entry slot to use */
571 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
572 if (hbqe) {
573 struct hbq_s *hbqp = &phba->hbqs[hbqno];
574
575 hbqe->bde.addrHigh = putPaddrHigh(hbq_buf_desc->dbuf.phys);
576 hbqe->bde.addrLow = putPaddrLow(hbq_buf_desc->dbuf.phys);
577 hbqe->bde.tus.f.bdeSize = FCELSSIZE;
578 hbqe->bde.tus.f.bdeFlags = 0;
579 hbqe->buffer_tag = hbq_buf_desc->tag;
580 /* Sync SLIM */
581 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
582 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
583 /* flush */
584 readl(phba->hbq_put + hbqno);
585 phba->hbq_buff_count++;
586 }
587}
588
589static void
590lpfc_sli_fill_hbq(struct lpfc_hba *phba, uint32_t hbqno, uint32_t buffer_index)
591{
592 struct hbq_dmabuf *hbq_buf_desc;
593 uint32_t i;
594
595 for (i = 0; i < phba->hbqs[hbqno].entry_count; i++) {
596 /* Search hbqbufq, from the begining,
597 * looking for an unused entry
598 */
599 phba->hbq_buffer_pool[buffer_index + i].tag |= hbqno << 16;
600 hbq_buf_desc = phba->hbq_buffer_pool + buffer_index + i;
601 lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buf_desc);
602 }
603}
604
605int
606lpfc_sli_hbqbuf_fill_hbq(struct lpfc_hba *phba)
607{
608 return 0;
609}
610
611static int
612lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba)
613{
614 uint32_t buffer_index = 0;
615 uint32_t hbqno;
616
617 /* Populate HBQ entries */
618 for (hbqno = 0; hbqno < phba->hbq_count; ++hbqno) {
619 /* Find ring associated with HBQ */
620
621 lpfc_sli_fill_hbq(phba, hbqno, buffer_index);
622 buffer_index += phba->hbqs[hbqno].entry_count;
623 }
624 return 0;
625}
626
627struct hbq_dmabuf *
628lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
629{
630 if ((tag & 0xffff) < phba->hbq_buffer_count)
631 return phba->hbq_buffer_pool + (tag & 0xffff);
632
633 lpfc_printf_log(phba, KERN_ERR,
634 LOG_SLI,
635 "%d:1803 Bad hbq tag. Data: x%x x%x\n",
636 phba->brd_no, tag,
637 phba->hbq_buffer_count);
638 return NULL;
639}
640
641void
642lpfc_sli_hbqbuf_free(struct lpfc_hba *phba, void *virt, dma_addr_t phys)
643{
644 uint32_t i, hbqno;
645
646 for (i = 0; i < phba->hbq_buffer_count; i++) {
647 /* Search hbqbufq, from the begining, looking for a match on
648 phys */
649 if (phba->hbq_buffer_pool[i].dbuf.phys == phys) {
650 hbqno = phba->hbq_buffer_pool[i].tag >> 16;
651 lpfc_sli_hbq_to_firmware(phba, hbqno,
652 phba->hbq_buffer_pool + i);
653 return;
654 }
655 }
656
657 lpfc_printf_log(phba, KERN_ERR,
658 LOG_SLI,
659 "%d:1804 Cannot find virtual addr for "
660 "mapped buf. Data x%llx\n",
661 phba->brd_no, (unsigned long long) phys);
662}
663
664void
665lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *sp)
666{
667 uint32_t hbqno;
668
669 if (sp) {
670 hbqno = sp->tag >> 16;
671 lpfc_sli_hbq_to_firmware(phba, hbqno, sp);
672 }
673}
674
484static int 675static int
485lpfc_sli_chk_mbx_command(uint8_t mbxCommand) 676lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
486{ 677{
@@ -757,7 +948,9 @@ lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
757 match = 0; 948 match = 0;
758 irsp = &(saveq->iocb); 949 irsp = &(saveq->iocb);
759 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) 950 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX)
760 || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX)) { 951 || (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX)
952 || (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)
953 || (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX)) {
761 Rctl = FC_ELS_REQ; 954 Rctl = FC_ELS_REQ;
762 Type = FC_ELS_DATA; 955 Type = FC_ELS_DATA;
763 } else { 956 } else {
@@ -769,7 +962,8 @@ lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
769 962
770 /* Firmware Workaround */ 963 /* Firmware Workaround */
771 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) && 964 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
772 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX)) { 965 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
966 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
773 Rctl = FC_ELS_REQ; 967 Rctl = FC_ELS_REQ;
774 Type = FC_ELS_DATA; 968 Type = FC_ELS_DATA;
775 w5p->hcsw.Rctl = Rctl; 969 w5p->hcsw.Rctl = Rctl;
@@ -906,7 +1100,10 @@ lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
906static void 1100static void
907lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 1101lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
908{ 1102{
909 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno]; 1103 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1104 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1105 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1106
910 /* 1107 /*
911 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then 1108 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
912 * rsp ring <portRspMax> 1109 * rsp ring <portRspMax>
@@ -945,14 +1142,15 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
945 uint32_t portRspPut, portRspMax; 1142 uint32_t portRspPut, portRspMax;
946 int type; 1143 int type;
947 uint32_t rsp_cmpl = 0; 1144 uint32_t rsp_cmpl = 0;
948 void __iomem *to_slim;
949 uint32_t ha_copy; 1145 uint32_t ha_copy;
950 unsigned long iflags; 1146 unsigned long iflags;
951 1147
952 pring->stats.iocb_event++; 1148 pring->stats.iocb_event++;
953 1149
954 /* The driver assumes SLI-2 mode */ 1150 pgp = (phba->sli_rev == 3) ?
955 pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno]; 1151 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1152 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1153
956 1154
957 /* 1155 /*
958 * The next available response entry should never exceed the maximum 1156 * The next available response entry should never exceed the maximum
@@ -967,9 +1165,7 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
967 1165
968 rmb(); 1166 rmb();
969 while (pring->rspidx != portRspPut) { 1167 while (pring->rspidx != portRspPut) {
970 1168 entry = lpfc_resp_iocb(phba, pring);
971 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
972
973 if (++pring->rspidx >= portRspMax) 1169 if (++pring->rspidx >= portRspMax)
974 pring->rspidx = 0; 1170 pring->rspidx = 0;
975 1171
@@ -1050,9 +1246,7 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
1050 * been updated, sync the pgp->rspPutInx and fetch the new port 1246 * been updated, sync the pgp->rspPutInx and fetch the new port
1051 * response put pointer. 1247 * response put pointer.
1052 */ 1248 */
1053 to_slim = phba->MBslimaddr + 1249 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1054 (SLIMOFF + (pring->ringno * 2) + 1) * 4;
1055 writeb(pring->rspidx, to_slim);
1056 1250
1057 if (pring->rspidx == portRspPut) 1251 if (pring->rspidx == portRspPut)
1058 portRspPut = le32_to_cpu(pgp->rspPutInx); 1252 portRspPut = le32_to_cpu(pgp->rspPutInx);
@@ -1096,7 +1290,9 @@ static int
1096lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, 1290lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1097 struct lpfc_sli_ring *pring, uint32_t mask) 1291 struct lpfc_sli_ring *pring, uint32_t mask)
1098{ 1292{
1099 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno]; 1293 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1294 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1295 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1100 IOCB_t *irsp = NULL; 1296 IOCB_t *irsp = NULL;
1101 IOCB_t *entry = NULL; 1297 IOCB_t *entry = NULL;
1102 struct lpfc_iocbq *cmdiocbq = NULL; 1298 struct lpfc_iocbq *cmdiocbq = NULL;
@@ -1107,7 +1303,6 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1107 lpfc_iocb_type type; 1303 lpfc_iocb_type type;
1108 unsigned long iflag; 1304 unsigned long iflag;
1109 uint32_t rsp_cmpl = 0; 1305 uint32_t rsp_cmpl = 0;
1110 void __iomem *to_slim;
1111 1306
1112 spin_lock_irqsave(&phba->hbalock, iflag); 1307 spin_lock_irqsave(&phba->hbalock, iflag);
1113 pring->stats.iocb_event++; 1308 pring->stats.iocb_event++;
@@ -1131,14 +1326,14 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1131 * structure. The copy involves a byte-swap since the 1326 * structure. The copy involves a byte-swap since the
1132 * network byte order and pci byte orders are different. 1327 * network byte order and pci byte orders are different.
1133 */ 1328 */
1134 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx); 1329 entry = lpfc_resp_iocb(phba, pring);
1135 1330
1136 if (++pring->rspidx >= portRspMax) 1331 if (++pring->rspidx >= portRspMax)
1137 pring->rspidx = 0; 1332 pring->rspidx = 0;
1138 1333
1139 lpfc_sli_pcimem_bcopy((uint32_t *) entry, 1334 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1140 (uint32_t *) &rspiocbq.iocb, 1335 (uint32_t *) &rspiocbq.iocb,
1141 sizeof(IOCB_t)); 1336 phba->iocb_rsp_size);
1142 INIT_LIST_HEAD(&(rspiocbq.list)); 1337 INIT_LIST_HEAD(&(rspiocbq.list));
1143 irsp = &rspiocbq.iocb; 1338 irsp = &rspiocbq.iocb;
1144 1339
@@ -1222,9 +1417,7 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1222 * been updated, sync the pgp->rspPutInx and fetch the new port 1417 * been updated, sync the pgp->rspPutInx and fetch the new port
1223 * response put pointer. 1418 * response put pointer.
1224 */ 1419 */
1225 to_slim = phba->MBslimaddr + 1420 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1226 (SLIMOFF + (pring->ringno * 2) + 1) * 4;
1227 writel(pring->rspidx, to_slim);
1228 1421
1229 if (pring->rspidx == portRspPut) 1422 if (pring->rspidx == portRspPut)
1230 portRspPut = le32_to_cpu(pgp->rspPutInx); 1423 portRspPut = le32_to_cpu(pgp->rspPutInx);
@@ -1258,7 +1451,9 @@ int
1258lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, 1451lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1259 struct lpfc_sli_ring *pring, uint32_t mask) 1452 struct lpfc_sli_ring *pring, uint32_t mask)
1260{ 1453{
1261 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno]; 1454 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ?
1455 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1456 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1262 IOCB_t *entry; 1457 IOCB_t *entry;
1263 IOCB_t *irsp = NULL; 1458 IOCB_t *irsp = NULL;
1264 struct lpfc_iocbq *rspiocbp = NULL; 1459 struct lpfc_iocbq *rspiocbp = NULL;
@@ -1271,7 +1466,6 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1271 uint32_t portRspPut, portRspMax; 1466 uint32_t portRspPut, portRspMax;
1272 int rc = 1; 1467 int rc = 1;
1273 unsigned long iflag; 1468 unsigned long iflag;
1274 void __iomem *to_slim;
1275 1469
1276 spin_lock_irqsave(&phba->hbalock, iflag); 1470 spin_lock_irqsave(&phba->hbalock, iflag);
1277 pring->stats.iocb_event++; 1471 pring->stats.iocb_event++;
@@ -1287,9 +1481,7 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1287 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then 1481 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1288 * rsp ring <portRspMax> 1482 * rsp ring <portRspMax>
1289 */ 1483 */
1290 lpfc_printf_log(phba, 1484 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1291 KERN_ERR,
1292 LOG_SLI,
1293 "%d:0303 Ring %d handler: portRspPut %d " 1485 "%d:0303 Ring %d handler: portRspPut %d "
1294 "is bigger then rsp ring %d\n", 1486 "is bigger then rsp ring %d\n",
1295 phba->brd_no, 1487 phba->brd_no,
@@ -1319,7 +1511,8 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1319 * the ulpLe field is set, the entire Command has been 1511 * the ulpLe field is set, the entire Command has been
1320 * received. 1512 * received.
1321 */ 1513 */
1322 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx); 1514 entry = lpfc_resp_iocb(phba, pring);
1515
1323 rspiocbp = __lpfc_sli_get_iocbq(phba); 1516 rspiocbp = __lpfc_sli_get_iocbq(phba);
1324 if (rspiocbp == NULL) { 1517 if (rspiocbp == NULL) {
1325 printk(KERN_ERR "%s: out of buffers! Failing " 1518 printk(KERN_ERR "%s: out of buffers! Failing "
@@ -1327,15 +1520,14 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1327 break; 1520 break;
1328 } 1521 }
1329 1522
1330 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, sizeof(IOCB_t)); 1523 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
1524 phba->iocb_rsp_size);
1331 irsp = &rspiocbp->iocb; 1525 irsp = &rspiocbp->iocb;
1332 1526
1333 if (++pring->rspidx >= portRspMax) 1527 if (++pring->rspidx >= portRspMax)
1334 pring->rspidx = 0; 1528 pring->rspidx = 0;
1335 1529
1336 to_slim = phba->MBslimaddr + (SLIMOFF + (pring->ringno * 2) 1530 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1337 + 1) * 4;
1338 writel(pring->rspidx, to_slim);
1339 1531
1340 if (list_empty(&(pring->iocb_continueq))) { 1532 if (list_empty(&(pring->iocb_continueq))) {
1341 list_add(&rspiocbp->list, &(pring->iocb_continueq)); 1533 list_add(&rspiocbp->list, &(pring->iocb_continueq));
@@ -1361,21 +1553,31 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1361 1553
1362 if (irsp->ulpStatus) { 1554 if (irsp->ulpStatus) {
1363 /* Rsp ring <ringno> error: IOCB */ 1555 /* Rsp ring <ringno> error: IOCB */
1364 lpfc_printf_log(phba, 1556 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1365 KERN_WARNING, 1557 "%d:0328 Rsp Ring %d error: "
1366 LOG_SLI, 1558 "IOCB Data: "
1367 "%d:0328 Rsp Ring %d error: IOCB Data: " 1559 "x%x x%x x%x x%x "
1368 "x%x x%x x%x x%x x%x x%x x%x x%x\n", 1560 "x%x x%x x%x x%x "
1369 phba->brd_no, 1561 "x%x x%x x%x x%x "
1370 pring->ringno, 1562 "x%x x%x x%x x%x\n",
1371 irsp->un.ulpWord[0], 1563 phba->brd_no,
1372 irsp->un.ulpWord[1], 1564 pring->ringno,
1373 irsp->un.ulpWord[2], 1565 irsp->un.ulpWord[0],
1374 irsp->un.ulpWord[3], 1566 irsp->un.ulpWord[1],
1375 irsp->un.ulpWord[4], 1567 irsp->un.ulpWord[2],
1376 irsp->un.ulpWord[5], 1568 irsp->un.ulpWord[3],
1377 *(((uint32_t *) irsp) + 6), 1569 irsp->un.ulpWord[4],
1378 *(((uint32_t *) irsp) + 7)); 1570 irsp->un.ulpWord[5],
1571 *(((uint32_t *) irsp) + 6),
1572 *(((uint32_t *) irsp) + 7),
1573 *(((uint32_t *) irsp) + 8),
1574 *(((uint32_t *) irsp) + 9),
1575 *(((uint32_t *) irsp) + 10),
1576 *(((uint32_t *) irsp) + 11),
1577 *(((uint32_t *) irsp) + 12),
1578 *(((uint32_t *) irsp) + 13),
1579 *(((uint32_t *) irsp) + 14),
1580 *(((uint32_t *) irsp) + 15));
1379 } 1581 }
1380 1582
1381 /* 1583 /*
@@ -1659,13 +1861,9 @@ lpfc_sli_brdkill(struct lpfc_hba *phba)
1659 psli = &phba->sli; 1861 psli = &phba->sli;
1660 1862
1661 /* Kill HBA */ 1863 /* Kill HBA */
1662 lpfc_printf_log(phba, 1864 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1663 KERN_INFO,
1664 LOG_SLI,
1665 "%d:0329 Kill HBA Data: x%x x%x\n", 1865 "%d:0329 Kill HBA Data: x%x x%x\n",
1666 phba->brd_no, 1866 phba->brd_no, phba->pport->port_state, psli->sli_flag);
1667 phba->pport->port_state,
1668 psli->sli_flag);
1669 1867
1670 if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, 1868 if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
1671 GFP_KERNEL)) == 0) 1869 GFP_KERNEL)) == 0)
@@ -1857,13 +2055,10 @@ lpfc_sli_chipset_init(struct lpfc_hba *phba)
1857 if (i++ >= 20) { 2055 if (i++ >= 20) {
1858 /* Adapter failed to init, timeout, status reg 2056 /* Adapter failed to init, timeout, status reg
1859 <status> */ 2057 <status> */
1860 lpfc_printf_log(phba, 2058 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1861 KERN_ERR,
1862 LOG_INIT,
1863 "%d:0436 Adapter failed to init, " 2059 "%d:0436 Adapter failed to init, "
1864 "timeout, status reg x%x\n", 2060 "timeout, status reg x%x\n",
1865 phba->brd_no, 2061 phba->brd_no, status);
1866 status);
1867 phba->link_state = LPFC_HBA_ERROR; 2062 phba->link_state = LPFC_HBA_ERROR;
1868 return -ETIMEDOUT; 2063 return -ETIMEDOUT;
1869 } 2064 }
@@ -1873,9 +2068,7 @@ lpfc_sli_chipset_init(struct lpfc_hba *phba)
1873 /* ERROR: During chipset initialization */ 2068 /* ERROR: During chipset initialization */
1874 /* Adapter failed to init, chipset, status reg 2069 /* Adapter failed to init, chipset, status reg
1875 <status> */ 2070 <status> */
1876 lpfc_printf_log(phba, 2071 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1877 KERN_ERR,
1878 LOG_INIT,
1879 "%d:0437 Adapter failed to init, " 2072 "%d:0437 Adapter failed to init, "
1880 "chipset, status reg x%x\n", 2073 "chipset, status reg x%x\n",
1881 phba->brd_no, 2074 phba->brd_no,
@@ -1905,9 +2098,7 @@ lpfc_sli_chipset_init(struct lpfc_hba *phba)
1905 if (status & HS_FFERM) { 2098 if (status & HS_FFERM) {
1906 /* ERROR: During chipset initialization */ 2099 /* ERROR: During chipset initialization */
1907 /* Adapter failed to init, chipset, status reg <status> */ 2100 /* Adapter failed to init, chipset, status reg <status> */
1908 lpfc_printf_log(phba, 2101 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1909 KERN_ERR,
1910 LOG_INIT,
1911 "%d:0438 Adapter failed to init, chipset, " 2102 "%d:0438 Adapter failed to init, chipset, "
1912 "status reg x%x\n", 2103 "status reg x%x\n",
1913 phba->brd_no, 2104 phba->brd_no,
@@ -1926,8 +2117,145 @@ lpfc_sli_chipset_init(struct lpfc_hba *phba)
1926 return 0; 2117 return 0;
1927} 2118}
1928 2119
2120static struct hbq_dmabuf *
2121lpfc_alloc_hbq_buffers(struct lpfc_hba *phba, int count)
2122{
2123 struct hbq_dmabuf *hbq_buffer_pool;
2124 int i;
2125
2126 hbq_buffer_pool = kmalloc(count * sizeof(struct hbq_dmabuf),
2127 GFP_KERNEL);
2128 if (!hbq_buffer_pool)
2129 goto out;
2130
2131 for (i = 0; i < count; ++i) {
2132 hbq_buffer_pool[i].dbuf.virt =
2133 lpfc_hbq_alloc(phba, MEM_PRI,
2134 &hbq_buffer_pool[i].dbuf.phys);
2135 if (hbq_buffer_pool[i].dbuf.virt == NULL)
2136 goto alloc_failed;
2137 hbq_buffer_pool[i].tag = i;
2138 }
2139 goto out;
2140
2141alloc_failed:
2142 while (--i >= 0)
2143 lpfc_hbq_free(phba, hbq_buffer_pool[i].dbuf.virt,
2144 hbq_buffer_pool[i].dbuf.phys);
2145 kfree(hbq_buffer_pool);
2146 hbq_buffer_pool = NULL;
2147
2148out:
2149 phba->hbq_buffer_pool = hbq_buffer_pool;
2150 return hbq_buffer_pool;
2151}
2152
2153static struct lpfc_hbq_init lpfc_els_hbq = {
2154 .rn = 1,
2155 .entry_count = 1200,
2156 .mask_count = 0,
2157 .profile = 0,
2158 .ring_mask = 1 << LPFC_ELS_RING,
2159};
2160
2161static struct lpfc_hbq_init *lpfc_hbq_definitions[] = {
2162 &lpfc_els_hbq,
2163};
2164
2165static int
2166lpfc_sli_hbq_count(void)
2167{
2168 return ARRAY_SIZE(lpfc_hbq_definitions);
2169}
2170
2171static int
2172lpfc_sli_hbq_entry_count(void)
2173{
2174 int hbq_count = lpfc_sli_hbq_count();
2175 int count = 0;
2176 int i;
2177
2178 for (i = 0; i < hbq_count; ++i)
2179 count += lpfc_hbq_definitions[i]->entry_count;
2180 return count;
2181}
2182
1929int 2183int
1930lpfc_sli_hba_setup(struct lpfc_hba *phba) 2184lpfc_sli_hbq_size(void)
2185{
2186 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
2187}
2188
2189static int
2190lpfc_sli_hbq_setup(struct lpfc_hba *phba)
2191{
2192 int hbq_count = lpfc_sli_hbq_count();
2193 LPFC_MBOXQ_t *pmb;
2194 MAILBOX_t *pmbox;
2195 uint32_t hbqno;
2196 uint32_t hbq_entry_index;
2197 uint32_t hbq_buffer_count;
2198
2199 /* count hbq buffers */
2200 hbq_buffer_count = lpfc_sli_hbq_entry_count();
2201 if (!lpfc_alloc_hbq_buffers(phba, hbq_buffer_count))
2202 return -ENOMEM;
2203
2204 phba->hbq_buffer_count = hbq_buffer_count;
2205
2206 /* Get a Mailbox buffer to setup mailbox
2207 * commands for HBA initialization
2208 */
2209 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2210
2211 if (!pmb)
2212 return -ENOMEM;
2213
2214 pmbox = &pmb->mb;
2215
2216 /* Initialize the struct lpfc_sli_hbq structure for each hbq */
2217 phba->link_state = LPFC_INIT_MBX_CMDS;
2218
2219 hbq_entry_index = 0;
2220 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
2221 phba->hbqs[hbqno].next_hbqPutIdx = 0;
2222 phba->hbqs[hbqno].hbqPutIdx = 0;
2223 phba->hbqs[hbqno].local_hbqGetIdx = 0;
2224 phba->hbqs[hbqno].entry_count =
2225 lpfc_hbq_definitions[hbqno]->entry_count;
2226 lpfc_config_hbq(phba, lpfc_hbq_definitions[hbqno],
2227 hbq_entry_index, pmb);
2228 hbq_entry_index += phba->hbqs[hbqno].entry_count;
2229
2230 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
2231 /* Adapter failed to init, mbxCmd <cmd> CFG_RING,
2232 mbxStatus <status>, ring <num> */
2233
2234 lpfc_printf_log(phba, KERN_ERR,
2235 LOG_SLI,
2236 "%d:1805 Adapter failed to init. "
2237 "Data: x%x x%x x%x\n",
2238 phba->brd_no, pmbox->mbxCommand,
2239 pmbox->mbxStatus, hbqno);
2240
2241 phba->link_state = LPFC_HBA_ERROR;
2242 mempool_free(pmb, phba->mbox_mem_pool);
2243 /* Free all HBQ memory */
2244 lpfc_sli_hbqbuf_free_all(phba);
2245 return ENXIO;
2246 }
2247 }
2248 phba->hbq_count = hbq_count;
2249
2250 /* Initially populate or replenish the HBQs */
2251 lpfc_sli_hbqbuf_fill_hbqs(phba);
2252 mempool_free(pmb, phba->mbox_mem_pool);
2253
2254 return 0;
2255}
2256
2257static int
2258lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode)
1931{ 2259{
1932 LPFC_MBOXQ_t *pmb; 2260 LPFC_MBOXQ_t *pmb;
1933 uint32_t resetcount = 0, rc = 0, done = 0; 2261 uint32_t resetcount = 0, rc = 0, done = 0;
@@ -1938,6 +2266,7 @@ lpfc_sli_hba_setup(struct lpfc_hba *phba)
1938 return -ENOMEM; 2266 return -ENOMEM;
1939 } 2267 }
1940 2268
2269 phba->sli_rev = sli_mode;
1941 while (resetcount < 2 && !done) { 2270 while (resetcount < 2 && !done) {
1942 spin_lock_irq(&phba->hbalock); 2271 spin_lock_irq(&phba->hbalock);
1943 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; 2272 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
@@ -1954,14 +2283,14 @@ lpfc_sli_hba_setup(struct lpfc_hba *phba)
1954 spin_unlock_irq(&phba->hbalock); 2283 spin_unlock_irq(&phba->hbalock);
1955 resetcount++; 2284 resetcount++;
1956 2285
1957 /* Call pre CONFIG_PORT mailbox command initialization. A value of 0 2286 /* Call pre CONFIG_PORT mailbox command initialization. A
1958 * means the call was successful. Any other nonzero value is a failure, 2287 * value of 0 means the call was successful. Any other
1959 * but if ERESTART is returned, the driver may reset the HBA and try 2288 * nonzero value is a failure, but if ERESTART is returned,
1960 * again. 2289 * the driver may reset the HBA and try again.
1961 */ 2290 */
1962 rc = lpfc_config_port_prep(phba); 2291 rc = lpfc_config_port_prep(phba);
1963 if (rc == -ERESTART) { 2292 if (rc == -ERESTART) {
1964 phba->pport->port_state = 0; 2293 phba->link_state = LPFC_LINK_UNKNOWN;
1965 continue; 2294 continue;
1966 } else if (rc) { 2295 } else if (rc) {
1967 break; 2296 break;
@@ -1970,39 +2299,116 @@ lpfc_sli_hba_setup(struct lpfc_hba *phba)
1970 phba->link_state = LPFC_INIT_MBX_CMDS; 2299 phba->link_state = LPFC_INIT_MBX_CMDS;
1971 lpfc_config_port(phba, pmb); 2300 lpfc_config_port(phba, pmb);
1972 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); 2301 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1973 if (rc == MBX_SUCCESS) 2302 if (rc != MBX_SUCCESS) {
1974 done = 1;
1975 else {
1976 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 2303 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1977 "%d:0442 Adapter failed to init, mbxCmd x%x " 2304 "%d:0442 Adapter failed to init, "
1978 "CONFIG_PORT, mbxStatus x%x Data: x%x\n", 2305 "mbxCmd x%x CONFIG_PORT, mbxStatus "
1979 phba->brd_no, pmb->mb.mbxCommand, 2306 "x%x Data: x%x\n",
1980 pmb->mb.mbxStatus, 0); 2307 phba->brd_no, pmb->mb.mbxCommand,
2308 pmb->mb.mbxStatus, 0);
1981 spin_lock_irq(&phba->hbalock); 2309 spin_lock_irq(&phba->hbalock);
1982 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE; 2310 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
1983 spin_unlock_irq(&phba->hbalock); 2311 spin_unlock_irq(&phba->hbalock);
1984 rc = -ENXIO; 2312 rc = -ENXIO;
2313 } else {
2314 done = 1;
2315 /* DBG: Do we need max_vpi, reg_vpi for that matter
2316 phba->max_vpi = 0;
2317 */
1985 } 2318 }
1986 } 2319 }
1987 if (!done) 2320
2321 if (!done) {
2322 rc = -EINVAL;
2323 goto do_prep_failed;
2324 }
2325
2326 if ((pmb->mb.un.varCfgPort.sli_mode == 3) &&
2327 (!pmb->mb.un.varCfgPort.cMA)) {
2328 rc = -ENXIO;
2329 goto do_prep_failed;
2330 }
2331 return rc;
2332
2333 do_prep_failed:
2334 mempool_free(pmb, phba->mbox_mem_pool);
2335 return rc;
2336}
2337
2338int
2339lpfc_sli_hba_setup(struct lpfc_hba *phba)
2340{
2341 uint32_t rc;
2342 int mode = 3;
2343
2344 switch (lpfc_sli_mode) {
2345 case 2:
2346 mode = 2;
2347 break;
2348 case 0:
2349 case 3:
2350 break;
2351 default:
2352 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2353 "%d:1819 Unrecognized lpfc_sli_mode "
2354 "parameter: %d.\n",
2355 phba->brd_no, lpfc_sli_mode);
2356
2357 break;
2358 }
2359
2360 rc = lpfc_do_config_port(phba, mode);
2361 if (rc && lpfc_sli_mode == 3)
2362 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
2363 "%d:1820 Unable to select SLI-3. "
2364 "Not supported by adapter.\n",
2365 phba->brd_no);
2366 if (rc && mode != 2)
2367 rc = lpfc_do_config_port(phba, 2);
2368 if (rc)
1988 goto lpfc_sli_hba_setup_error; 2369 goto lpfc_sli_hba_setup_error;
1989 2370
1990 rc = lpfc_sli_ring_map(phba, pmb); 2371 if (phba->sli_rev == 3) {
2372 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
2373 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
2374 phba->sli3_options |= LPFC_SLI3_ENABLED;
2375 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
2376
2377 } else {
2378 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
2379 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
2380 phba->sli3_options = 0x0;
2381 }
2382
2383 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2384 "%d:0444 Firmware in SLI %x mode.\n",
2385 phba->brd_no, phba->sli_rev);
2386 rc = lpfc_sli_ring_map(phba);
1991 2387
1992 if (rc) 2388 if (rc)
1993 goto lpfc_sli_hba_setup_error; 2389 goto lpfc_sli_hba_setup_error;
1994 2390
2391 /* Init HBQs */
2392
2393 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2394 rc = lpfc_sli_hbq_setup(phba);
2395 if (rc)
2396 goto lpfc_sli_hba_setup_error;
2397 }
2398
1995 phba->sli.sli_flag |= LPFC_PROCESS_LA; 2399 phba->sli.sli_flag |= LPFC_PROCESS_LA;
1996 2400
1997 rc = lpfc_config_port_post(phba); 2401 rc = lpfc_config_port_post(phba);
1998 if (rc) 2402 if (rc)
1999 goto lpfc_sli_hba_setup_error; 2403 goto lpfc_sli_hba_setup_error;
2000 2404
2001 goto lpfc_sli_hba_setup_exit; 2405 return rc;
2002lpfc_sli_hba_setup_error: 2406
2407 lpfc_sli_hba_setup_error:
2003 phba->link_state = LPFC_HBA_ERROR; 2408 phba->link_state = LPFC_HBA_ERROR;
2004lpfc_sli_hba_setup_exit: 2409 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
2005 mempool_free(pmb, phba->mbox_mem_pool); 2410 "%d:0445 Firmware initialization failed\n",
2411 phba->brd_no);
2006 return rc; 2412 return rc;
2007} 2413}
2008 2414
@@ -2027,7 +2433,7 @@ lpfc_mbox_timeout(unsigned long ptr)
2027 uint32_t tmo_posted; 2433 uint32_t tmo_posted;
2028 2434
2029 spin_lock_irqsave(&phba->pport->work_port_lock, iflag); 2435 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
2030 tmo_posted = (phba->pport->work_port_events & WORKER_MBOX_TMO) == 0; 2436 tmo_posted = (phba->pport->work_port_events & WORKER_MBOX_TMO);
2031 if (!tmo_posted) 2437 if (!tmo_posted)
2032 phba->pport->work_port_events |= WORKER_MBOX_TMO; 2438 phba->pport->work_port_events |= WORKER_MBOX_TMO;
2033 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag); 2439 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
@@ -2051,9 +2457,7 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2051 } 2457 }
2052 2458
2053 /* Mbox cmd <mbxCommand> timeout */ 2459 /* Mbox cmd <mbxCommand> timeout */
2054 lpfc_printf_log(phba, 2460 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2055 KERN_ERR,
2056 LOG_MBOX | LOG_SLI,
2057 "%d:0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", 2461 "%d:0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
2058 phba->brd_no, 2462 phba->brd_no,
2059 mb->mbxCommand, 2463 mb->mbxCommand,
@@ -2105,13 +2509,25 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2105 volatile uint32_t word0, ldata; 2509 volatile uint32_t word0, ldata;
2106 void __iomem *to_slim; 2510 void __iomem *to_slim;
2107 2511
2512 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
2513 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
2514 if(!pmbox->vport) {
2515 lpfc_printf_log(phba, KERN_ERR,
2516 LOG_MBOX,
2517 "%d:1806 Mbox x%x failed. No vport\n",
2518 phba->brd_no,
2519 pmbox->mb.mbxCommand);
2520 dump_stack();
2521 return MBXERR_ERROR;
2522 }
2523 }
2524
2108 /* If the PCI channel is in offline state, do not post mbox. */ 2525 /* If the PCI channel is in offline state, do not post mbox. */
2109 if (unlikely(pci_channel_offline(phba->pcidev))) 2526 if (unlikely(pci_channel_offline(phba->pcidev)))
2110 return MBX_NOT_FINISHED; 2527 return MBX_NOT_FINISHED;
2111 2528
2112 spin_lock_irqsave(&phba->hbalock, drvr_flag); 2529 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2113 psli = &phba->sli; 2530 psli = &phba->sli;
2114
2115 mb = &pmbox->mb; 2531 mb = &pmbox->mb;
2116 status = MBX_SUCCESS; 2532 status = MBX_SUCCESS;
2117 2533
@@ -2172,15 +2588,11 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2172 lpfc_mbox_put(phba, pmbox); 2588 lpfc_mbox_put(phba, pmbox);
2173 2589
2174 /* Mbox cmd issue - BUSY */ 2590 /* Mbox cmd issue - BUSY */
2175 lpfc_printf_log(phba, 2591 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2176 KERN_INFO,
2177 LOG_MBOX | LOG_SLI,
2178 "%d:0308 Mbox cmd issue - BUSY Data: x%x x%x x%x x%x\n", 2592 "%d:0308 Mbox cmd issue - BUSY Data: x%x x%x x%x x%x\n",
2179 phba->brd_no, 2593 phba->brd_no,
2180 mb->mbxCommand, 2594 mb->mbxCommand, phba->pport->port_state,
2181 phba->pport->port_state, 2595 psli->sli_flag, flag);
2182 psli->sli_flag,
2183 flag);
2184 2596
2185 psli->slistat.mbox_busy++; 2597 psli->slistat.mbox_busy++;
2186 spin_unlock_irqrestore(&phba->hbalock, drvr_flag); 2598 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
@@ -2223,15 +2635,11 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2223 } 2635 }
2224 2636
2225 /* Mailbox cmd <cmd> issue */ 2637 /* Mailbox cmd <cmd> issue */
2226 lpfc_printf_log(phba, 2638 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
2227 KERN_INFO,
2228 LOG_MBOX | LOG_SLI,
2229 "%d:0309 Mailbox cmd x%x issue Data: x%x x%x x%x\n", 2639 "%d:0309 Mailbox cmd x%x issue Data: x%x x%x x%x\n",
2230 phba->brd_no, 2640 phba->brd_no,
2231 mb->mbxCommand, 2641 mb->mbxCommand, phba->pport->port_state,
2232 phba->pport->port_state, 2642 psli->sli_flag, flag);
2233 psli->sli_flag,
2234 flag);
2235 2643
2236 psli->slistat.mbox_cmd++; 2644 psli->slistat.mbox_cmd++;
2237 evtctr = psli->slistat.mbox_event; 2645 evtctr = psli->slistat.mbox_event;
@@ -2526,7 +2934,7 @@ lpfc_extra_ring_setup( struct lpfc_hba *phba)
2526int 2934int
2527lpfc_sli_setup(struct lpfc_hba *phba) 2935lpfc_sli_setup(struct lpfc_hba *phba)
2528{ 2936{
2529 int i, totiocb = 0; 2937 int i, totiocbsize = 0;
2530 struct lpfc_sli *psli = &phba->sli; 2938 struct lpfc_sli *psli = &phba->sli;
2531 struct lpfc_sli_ring *pring; 2939 struct lpfc_sli_ring *pring;
2532 2940
@@ -2551,9 +2959,15 @@ lpfc_sli_setup(struct lpfc_hba *phba)
2551 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES; 2959 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
2552 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES; 2960 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
2553 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES; 2961 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
2962 pring->sizeCiocb = (phba->sli_rev == 3) ?
2963 SLI3_IOCB_CMD_SIZE :
2964 SLI2_IOCB_CMD_SIZE;
2965 pring->sizeRiocb = (phba->sli_rev == 3) ?
2966 SLI3_IOCB_RSP_SIZE :
2967 SLI2_IOCB_RSP_SIZE;
2554 pring->iotag_ctr = 0; 2968 pring->iotag_ctr = 0;
2555 pring->iotag_max = 2969 pring->iotag_max =
2556 (phba->cfg_hba_queue_depth * 2); 2970 (phba->cfg_hba_queue_depth * 2);
2557 pring->fast_iotag = pring->iotag_max; 2971 pring->fast_iotag = pring->iotag_max;
2558 pring->num_mask = 0; 2972 pring->num_mask = 0;
2559 break; 2973 break;
@@ -2561,6 +2975,12 @@ lpfc_sli_setup(struct lpfc_hba *phba)
2561 /* numCiocb and numRiocb are used in config_port */ 2975 /* numCiocb and numRiocb are used in config_port */
2562 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; 2976 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
2563 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; 2977 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
2978 pring->sizeCiocb = (phba->sli_rev == 3) ?
2979 SLI3_IOCB_CMD_SIZE :
2980 SLI2_IOCB_CMD_SIZE;
2981 pring->sizeRiocb = (phba->sli_rev == 3) ?
2982 SLI3_IOCB_RSP_SIZE :
2983 SLI2_IOCB_RSP_SIZE;
2564 pring->iotag_max = phba->cfg_hba_queue_depth; 2984 pring->iotag_max = phba->cfg_hba_queue_depth;
2565 pring->num_mask = 0; 2985 pring->num_mask = 0;
2566 break; 2986 break;
@@ -2568,6 +2988,12 @@ lpfc_sli_setup(struct lpfc_hba *phba)
2568 /* numCiocb and numRiocb are used in config_port */ 2988 /* numCiocb and numRiocb are used in config_port */
2569 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES; 2989 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
2570 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES; 2990 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
2991 pring->sizeCiocb = (phba->sli_rev == 3) ?
2992 SLI3_IOCB_CMD_SIZE :
2993 SLI2_IOCB_CMD_SIZE;
2994 pring->sizeRiocb = (phba->sli_rev == 3) ?
2995 SLI3_IOCB_RSP_SIZE :
2996 SLI2_IOCB_RSP_SIZE;
2571 pring->fast_iotag = 0; 2997 pring->fast_iotag = 0;
2572 pring->iotag_ctr = 0; 2998 pring->iotag_ctr = 0;
2573 pring->iotag_max = 4096; 2999 pring->iotag_max = 4096;
@@ -2576,36 +3002,38 @@ lpfc_sli_setup(struct lpfc_hba *phba)
2576 pring->prt[0].rctl = FC_ELS_REQ; 3002 pring->prt[0].rctl = FC_ELS_REQ;
2577 pring->prt[0].type = FC_ELS_DATA; 3003 pring->prt[0].type = FC_ELS_DATA;
2578 pring->prt[0].lpfc_sli_rcv_unsol_event = 3004 pring->prt[0].lpfc_sli_rcv_unsol_event =
2579 lpfc_els_unsol_event; 3005 lpfc_els_unsol_event;
2580 pring->prt[1].profile = 0; /* Mask 1 */ 3006 pring->prt[1].profile = 0; /* Mask 1 */
2581 pring->prt[1].rctl = FC_ELS_RSP; 3007 pring->prt[1].rctl = FC_ELS_RSP;
2582 pring->prt[1].type = FC_ELS_DATA; 3008 pring->prt[1].type = FC_ELS_DATA;
2583 pring->prt[1].lpfc_sli_rcv_unsol_event = 3009 pring->prt[1].lpfc_sli_rcv_unsol_event =
2584 lpfc_els_unsol_event; 3010 lpfc_els_unsol_event;
2585 pring->prt[2].profile = 0; /* Mask 2 */ 3011 pring->prt[2].profile = 0; /* Mask 2 */
2586 /* NameServer Inquiry */ 3012 /* NameServer Inquiry */
2587 pring->prt[2].rctl = FC_UNSOL_CTL; 3013 pring->prt[2].rctl = FC_UNSOL_CTL;
2588 /* NameServer */ 3014 /* NameServer */
2589 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP; 3015 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
2590 pring->prt[2].lpfc_sli_rcv_unsol_event = 3016 pring->prt[2].lpfc_sli_rcv_unsol_event =
2591 lpfc_ct_unsol_event; 3017 lpfc_ct_unsol_event;
2592 pring->prt[3].profile = 0; /* Mask 3 */ 3018 pring->prt[3].profile = 0; /* Mask 3 */
2593 /* NameServer response */ 3019 /* NameServer response */
2594 pring->prt[3].rctl = FC_SOL_CTL; 3020 pring->prt[3].rctl = FC_SOL_CTL;
2595 /* NameServer */ 3021 /* NameServer */
2596 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP; 3022 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
2597 pring->prt[3].lpfc_sli_rcv_unsol_event = 3023 pring->prt[3].lpfc_sli_rcv_unsol_event =
2598 lpfc_ct_unsol_event; 3024 lpfc_ct_unsol_event;
2599 break; 3025 break;
2600 } 3026 }
2601 totiocb += (pring->numCiocb + pring->numRiocb); 3027 totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
3028 (pring->numRiocb * pring->sizeRiocb);
2602 } 3029 }
2603 if (totiocb > MAX_SLI2_IOCB) { 3030 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
2604 /* Too many cmd / rsp ring entries in SLI2 SLIM */ 3031 /* Too many cmd / rsp ring entries in SLI2 SLIM */
2605 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 3032 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2606 "%d:0462 Too many cmd / rsp ring entries in " 3033 "%d:0462 Too many cmd / rsp ring entries in "
2607 "SLI2 SLIM Data: x%x x%x\n", 3034 "SLI2 SLIM Data: x%x x%lx\n",
2608 phba->brd_no, totiocb, MAX_SLI2_IOCB); 3035 phba->brd_no, totiocbsize,
3036 (unsigned long) MAX_SLIM_IOCB_SIZE);
2609 } 3037 }
2610 if (phba->cfg_multi_ring_support == 2) 3038 if (phba->cfg_multi_ring_support == 2)
2611 lpfc_extra_ring_setup(phba); 3039 lpfc_extra_ring_setup(phba);
@@ -2689,6 +3117,7 @@ lpfc_sli_hba_down(struct lpfc_hba *phba)
2689 phba->pport->work_port_events &= ~WORKER_MBOX_TMO; 3117 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
2690 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags); 3118 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
2691 3119
3120 spin_lock_irqsave(&phba->hbalock, flags);
2692 pmb = psli->mbox_active; 3121 pmb = psli->mbox_active;
2693 if (pmb) { 3122 if (pmb) {
2694 psli->mbox_active = NULL; 3123 psli->mbox_active = NULL;
@@ -2708,6 +3137,9 @@ lpfc_sli_hba_down(struct lpfc_hba *phba)
2708 } 3137 }
2709 INIT_LIST_HEAD(&psli->mboxq); 3138 INIT_LIST_HEAD(&psli->mboxq);
2710 3139
3140 /* Free all HBQ memory */
3141 lpfc_sli_hbqbuf_free_all(phba);
3142
2711 return 1; 3143 return 1;
2712} 3144}
2713 3145
@@ -3075,11 +3507,9 @@ lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
3075 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0); 3507 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
3076 if (retval == IOCB_SUCCESS) { 3508 if (retval == IOCB_SUCCESS) {
3077 timeout_req = timeout * HZ; 3509 timeout_req = timeout * HZ;
3078 spin_unlock_irq(&phba->hbalock);
3079 timeleft = wait_event_timeout(done_q, 3510 timeleft = wait_event_timeout(done_q,
3080 piocb->iocb_flag & LPFC_IO_WAKE, 3511 piocb->iocb_flag & LPFC_IO_WAKE,
3081 timeout_req); 3512 timeout_req);
3082 spin_lock_irq(&phba->hbalock);
3083 3513
3084 if (piocb->iocb_flag & LPFC_IO_WAKE) { 3514 if (piocb->iocb_flag & LPFC_IO_WAKE) {
3085 lpfc_printf_log(phba, KERN_INFO, LOG_SLI, 3515 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
@@ -3164,13 +3594,25 @@ lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
3164{ 3594{
3165 struct lpfc_vport *vport = phba->pport; 3595 struct lpfc_vport *vport = phba->pport;
3166 int i = 0; 3596 int i = 0;
3597 uint32_t ha_copy;
3167 3598
3168 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) { 3599 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) {
3169 if (i++ > LPFC_MBOX_TMO * 1000) 3600 if (i++ > LPFC_MBOX_TMO * 1000)
3170 return 1; 3601 return 1;
3171 3602
3172 if (lpfc_sli_handle_mb_event(phba) == 0) 3603 /*
3173 i = 0; 3604 * Call lpfc_sli_handle_mb_event only if a mailbox cmd
3605 * did finish. This way we won't get the misleading
3606 * "Stray Mailbox Interrupt" message.
3607 */
3608 spin_lock_irq(&phba->hbalock);
3609 ha_copy = phba->work_ha;
3610 phba->work_ha &= ~HA_MBATT;
3611 spin_unlock_irq(&phba->hbalock);
3612
3613 if (ha_copy & HA_MBATT)
3614 if (lpfc_sli_handle_mb_event(phba) == 0)
3615 i = 0;
3174 3616
3175 msleep(1); 3617 msleep(1);
3176 } 3618 }