1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25#include <linux/delay.h>
26
27#include <scsi/scsi.h>
28#include <scsi/scsi_cmnd.h>
29#include <scsi/scsi_device.h>
30#include <scsi/scsi_host.h>
31#include <scsi/scsi_transport_fc.h>
32
33#include "lpfc_hw.h"
34#include "lpfc_sli.h"
35#include "lpfc_nl.h"
36#include "lpfc_disc.h"
37#include "lpfc_scsi.h"
38#include "lpfc.h"
39#include "lpfc_crtn.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_compat.h"
42#include "lpfc_debugfs.h"
43
44
45
46
47
48
49#define LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag) \
50 lpfc_printf_log(phba, \
51 KERN_INFO, \
52 LOG_MBOX | LOG_SLI, \
53 "(%d):0311 Mailbox command x%x cannot " \
54 "issue Data: x%x x%x x%x\n", \
55 pmbox->vport ? pmbox->vport->vpi : 0, \
56 pmbox->mb.mbxCommand, \
57 phba->pport->port_state, \
58 psli->sli_flag, \
59 flag)
60
61
62
63typedef enum _lpfc_iocb_type {
64 LPFC_UNKNOWN_IOCB,
65 LPFC_UNSOL_IOCB,
66 LPFC_SOL_IOCB,
67 LPFC_ABORT_IOCB
68} lpfc_iocb_type;
69
70
71
72
73
74
75
76
77
78
79
80static inline IOCB_t *
81lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
82{
83 return (IOCB_t *) (((char *) pring->cmdringaddr) +
84 pring->cmdidx * phba->iocb_cmd_size);
85}
86
87
88
89
90
91
92
93
94
95
96
97static inline IOCB_t *
98lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
99{
100 return (IOCB_t *) (((char *) pring->rspringaddr) +
101 pring->rspidx * phba->iocb_rsp_size);
102}
103
104
105
106
107
108
109
110
111
112
113static struct lpfc_iocbq *
114__lpfc_sli_get_iocbq(struct lpfc_hba *phba)
115{
116 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
117 struct lpfc_iocbq * iocbq = NULL;
118
119 list_remove_head(lpfc_iocb_list, iocbq, struct lpfc_iocbq, list);
120 return iocbq;
121}
122
123
124
125
126
127
128
129
130
131
132struct lpfc_iocbq *
133lpfc_sli_get_iocbq(struct lpfc_hba *phba)
134{
135 struct lpfc_iocbq * iocbq = NULL;
136 unsigned long iflags;
137
138 spin_lock_irqsave(&phba->hbalock, iflags);
139 iocbq = __lpfc_sli_get_iocbq(phba);
140 spin_unlock_irqrestore(&phba->hbalock, iflags);
141 return iocbq;
142}
143
144
145
146
147
148
149
150
151
152
153
154static void
155__lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
156{
157 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
158
159
160
161
162 memset((char*)iocbq + start_clean, 0, sizeof(*iocbq) - start_clean);
163 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
164}
165
166
167
168
169
170
171
172
173
174void
175lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
176{
177 unsigned long iflags;
178
179
180
181
182 spin_lock_irqsave(&phba->hbalock, iflags);
183 __lpfc_sli_release_iocbq(phba, iocbq);
184 spin_unlock_irqrestore(&phba->hbalock, iflags);
185}
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202static lpfc_iocb_type
203lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
204{
205 lpfc_iocb_type type = LPFC_UNKNOWN_IOCB;
206
207 if (iocb_cmnd > CMD_MAX_IOCB_CMD)
208 return 0;
209
210 switch (iocb_cmnd) {
211 case CMD_XMIT_SEQUENCE_CR:
212 case CMD_XMIT_SEQUENCE_CX:
213 case CMD_XMIT_BCAST_CN:
214 case CMD_XMIT_BCAST_CX:
215 case CMD_ELS_REQUEST_CR:
216 case CMD_ELS_REQUEST_CX:
217 case CMD_CREATE_XRI_CR:
218 case CMD_CREATE_XRI_CX:
219 case CMD_GET_RPI_CN:
220 case CMD_XMIT_ELS_RSP_CX:
221 case CMD_GET_RPI_CR:
222 case CMD_FCP_IWRITE_CR:
223 case CMD_FCP_IWRITE_CX:
224 case CMD_FCP_IREAD_CR:
225 case CMD_FCP_IREAD_CX:
226 case CMD_FCP_ICMND_CR:
227 case CMD_FCP_ICMND_CX:
228 case CMD_FCP_TSEND_CX:
229 case CMD_FCP_TRSP_CX:
230 case CMD_FCP_TRECEIVE_CX:
231 case CMD_FCP_AUTO_TRSP_CX:
232 case CMD_ADAPTER_MSG:
233 case CMD_ADAPTER_DUMP:
234 case CMD_XMIT_SEQUENCE64_CR:
235 case CMD_XMIT_SEQUENCE64_CX:
236 case CMD_XMIT_BCAST64_CN:
237 case CMD_XMIT_BCAST64_CX:
238 case CMD_ELS_REQUEST64_CR:
239 case CMD_ELS_REQUEST64_CX:
240 case CMD_FCP_IWRITE64_CR:
241 case CMD_FCP_IWRITE64_CX:
242 case CMD_FCP_IREAD64_CR:
243 case CMD_FCP_IREAD64_CX:
244 case CMD_FCP_ICMND64_CR:
245 case CMD_FCP_ICMND64_CX:
246 case CMD_FCP_TSEND64_CX:
247 case CMD_FCP_TRSP64_CX:
248 case CMD_FCP_TRECEIVE64_CX:
249 case CMD_GEN_REQUEST64_CR:
250 case CMD_GEN_REQUEST64_CX:
251 case CMD_XMIT_ELS_RSP64_CX:
252 type = LPFC_SOL_IOCB;
253 break;
254 case CMD_ABORT_XRI_CN:
255 case CMD_ABORT_XRI_CX:
256 case CMD_CLOSE_XRI_CN:
257 case CMD_CLOSE_XRI_CX:
258 case CMD_XRI_ABORTED_CX:
259 case CMD_ABORT_MXRI64_CN:
260 type = LPFC_ABORT_IOCB;
261 break;
262 case CMD_RCV_SEQUENCE_CX:
263 case CMD_RCV_ELS_REQ_CX:
264 case CMD_RCV_SEQUENCE64_CX:
265 case CMD_RCV_ELS_REQ64_CX:
266 case CMD_ASYNC_STATUS:
267 case CMD_IOCB_RCV_SEQ64_CX:
268 case CMD_IOCB_RCV_ELS64_CX:
269 case CMD_IOCB_RCV_CONT64_CX:
270 case CMD_IOCB_RET_XRI64_CX:
271 type = LPFC_UNSOL_IOCB;
272 break;
273 case CMD_IOCB_XMIT_MSEQ64_CR:
274 case CMD_IOCB_XMIT_MSEQ64_CX:
275 case CMD_IOCB_RCV_SEQ_LIST64_CX:
276 case CMD_IOCB_RCV_ELS_LIST64_CX:
277 case CMD_IOCB_CLOSE_EXTENDED_CN:
278 case CMD_IOCB_ABORT_EXTENDED_CN:
279 case CMD_IOCB_RET_HBQE64_CN:
280 case CMD_IOCB_FCP_IBIDIR64_CR:
281 case CMD_IOCB_FCP_IBIDIR64_CX:
282 case CMD_IOCB_FCP_ITASKMGT64_CX:
283 case CMD_IOCB_LOGENTRY_CN:
284 case CMD_IOCB_LOGENTRY_ASYNC_CN:
285 printk("%s - Unhandled SLI-3 Command x%x\n",
286 __func__, iocb_cmnd);
287 type = LPFC_UNKNOWN_IOCB;
288 break;
289 default:
290 type = LPFC_UNKNOWN_IOCB;
291 break;
292 }
293
294 return type;
295}
296
297
298
299
300
301
302
303
304
305
306
307
308static int
309lpfc_sli_ring_map(struct lpfc_hba *phba)
310{
311 struct lpfc_sli *psli = &phba->sli;
312 LPFC_MBOXQ_t *pmb;
313 MAILBOX_t *pmbox;
314 int i, rc, ret = 0;
315
316 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
317 if (!pmb)
318 return -ENOMEM;
319 pmbox = &pmb->mb;
320 phba->link_state = LPFC_INIT_MBX_CMDS;
321 for (i = 0; i < psli->num_rings; i++) {
322 lpfc_config_ring(phba, i, pmb);
323 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
324 if (rc != MBX_SUCCESS) {
325 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
326 "0446 Adapter failed to init (%d), "
327 "mbxCmd x%x CFG_RING, mbxStatus x%x, "
328 "ring %d\n",
329 rc, pmbox->mbxCommand,
330 pmbox->mbxStatus, i);
331 phba->link_state = LPFC_HBA_ERROR;
332 ret = -ENXIO;
333 break;
334 }
335 }
336 mempool_free(pmb, phba->mbox_mem_pool);
337 return ret;
338}
339
340
341
342
343
344
345
346
347
348
349
350
351
352static int
353lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
354 struct lpfc_iocbq *piocb)
355{
356 list_add_tail(&piocb->list, &pring->txcmplq);
357 pring->txcmplq_cnt++;
358 if ((unlikely(pring->ringno == LPFC_ELS_RING)) &&
359 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
360 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
361 if (!piocb->vport)
362 BUG();
363 else
364 mod_timer(&piocb->vport->els_tmofunc,
365 jiffies + HZ * (phba->fc_ratov << 1));
366 }
367
368
369 return 0;
370}
371
372
373
374
375
376
377
378
379
380
381
382static struct lpfc_iocbq *
383lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
384{
385 struct lpfc_iocbq *cmd_iocb;
386
387 list_remove_head((&pring->txq), cmd_iocb, struct lpfc_iocbq, list);
388 if (cmd_iocb != NULL)
389 pring->txq_cnt--;
390 return cmd_iocb;
391}
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407static IOCB_t *
408lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
409{
410 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
411 uint32_t max_cmd_idx = pring->numCiocb;
412 if ((pring->next_cmdidx == pring->cmdidx) &&
413 (++pring->next_cmdidx >= max_cmd_idx))
414 pring->next_cmdidx = 0;
415
416 if (unlikely(pring->local_getidx == pring->next_cmdidx)) {
417
418 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
419
420 if (unlikely(pring->local_getidx >= max_cmd_idx)) {
421 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
422 "0315 Ring %d issue: portCmdGet %d "
423 "is bigger then cmd ring %d\n",
424 pring->ringno,
425 pring->local_getidx, max_cmd_idx);
426
427 phba->link_state = LPFC_HBA_ERROR;
428
429
430
431
432 phba->work_ha |= HA_ERATT;
433 phba->work_hs = HS_FFER3;
434
435 lpfc_worker_wake_up(phba);
436
437 return NULL;
438 }
439
440 if (pring->local_getidx == pring->next_cmdidx)
441 return NULL;
442 }
443
444 return lpfc_cmd_iocb(phba, pring);
445}
446
447
448
449
450
451
452
453
454
455
456
457
458
459uint16_t
460lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
461{
462 struct lpfc_iocbq **new_arr;
463 struct lpfc_iocbq **old_arr;
464 size_t new_len;
465 struct lpfc_sli *psli = &phba->sli;
466 uint16_t iotag;
467
468 spin_lock_irq(&phba->hbalock);
469 iotag = psli->last_iotag;
470 if(++iotag < psli->iocbq_lookup_len) {
471 psli->last_iotag = iotag;
472 psli->iocbq_lookup[iotag] = iocbq;
473 spin_unlock_irq(&phba->hbalock);
474 iocbq->iotag = iotag;
475 return iotag;
476 } else if (psli->iocbq_lookup_len < (0xffff
477 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
478 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
479 spin_unlock_irq(&phba->hbalock);
480 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
481 GFP_KERNEL);
482 if (new_arr) {
483 spin_lock_irq(&phba->hbalock);
484 old_arr = psli->iocbq_lookup;
485 if (new_len <= psli->iocbq_lookup_len) {
486
487 kfree(new_arr);
488 iotag = psli->last_iotag;
489 if(++iotag < psli->iocbq_lookup_len) {
490 psli->last_iotag = iotag;
491 psli->iocbq_lookup[iotag] = iocbq;
492 spin_unlock_irq(&phba->hbalock);
493 iocbq->iotag = iotag;
494 return iotag;
495 }
496 spin_unlock_irq(&phba->hbalock);
497 return 0;
498 }
499 if (psli->iocbq_lookup)
500 memcpy(new_arr, old_arr,
501 ((psli->last_iotag + 1) *
502 sizeof (struct lpfc_iocbq *)));
503 psli->iocbq_lookup = new_arr;
504 psli->iocbq_lookup_len = new_len;
505 psli->last_iotag = iotag;
506 psli->iocbq_lookup[iotag] = iocbq;
507 spin_unlock_irq(&phba->hbalock);
508 iocbq->iotag = iotag;
509 kfree(old_arr);
510 return iotag;
511 }
512 } else
513 spin_unlock_irq(&phba->hbalock);
514
515 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
516 "0318 Failed to allocate IOTAG.last IOTAG is %d\n",
517 psli->last_iotag);
518
519 return 0;
520}
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536static void
537lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
538 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
539{
540
541
542
543 nextiocb->iocb.ulpIoTag = (nextiocb->iocb_cmpl) ? nextiocb->iotag : 0;
544
545 if (pring->ringno == LPFC_ELS_RING) {
546 lpfc_debugfs_slow_ring_trc(phba,
547 "IOCB cmd ring: wd4:x%08x wd6:x%08x wd7:x%08x",
548 *(((uint32_t *) &nextiocb->iocb) + 4),
549 *(((uint32_t *) &nextiocb->iocb) + 6),
550 *(((uint32_t *) &nextiocb->iocb) + 7));
551 }
552
553
554
555
556 lpfc_sli_pcimem_bcopy(&nextiocb->iocb, iocb, phba->iocb_cmd_size);
557 wmb();
558 pring->stats.iocb_cmd++;
559
560
561
562
563
564
565 if (nextiocb->iocb_cmpl)
566 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
567 else
568 __lpfc_sli_release_iocbq(phba, nextiocb);
569
570
571
572
573
574 pring->cmdidx = pring->next_cmdidx;
575 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
576}
577
578
579
580
581
582
583
584
585
586
587
588
589
590static void
591lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
592{
593 int ringno = pring->ringno;
594
595 pring->flag |= LPFC_CALL_RING_AVAILABLE;
596
597 wmb();
598
599
600
601
602
603 writel((CA_R0ATT|CA_R0CE_REQ) << (ringno*4), phba->CAregaddr);
604 readl(phba->CAregaddr);
605
606 pring->stats.iocb_cmd_full++;
607}
608
609
610
611
612
613
614
615
616
617
618static void
619lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
620{
621 int ringno = pring->ringno;
622
623
624
625
626 if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
627 wmb();
628 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
629 readl(phba->CAregaddr);
630 }
631}
632
633
634
635
636
637
638
639
640
641
642static void
643lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
644{
645 IOCB_t *iocb;
646 struct lpfc_iocbq *nextiocb;
647
648
649
650
651
652
653
654
655 if (pring->txq_cnt &&
656 lpfc_is_link_up(phba) &&
657 (pring->ringno != phba->sli.fcp_ring ||
658 phba->sli.sli_flag & LPFC_PROCESS_LA)) {
659
660 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
661 (nextiocb = lpfc_sli_ringtx_get(phba, pring)))
662 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
663
664 if (iocb)
665 lpfc_sli_update_ring(phba, pring);
666 else
667 lpfc_sli_update_full_ring(phba, pring);
668 }
669
670 return;
671}
672
673
674
675
676
677
678
679
680
681
682
683static struct lpfc_hbq_entry *
684lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
685{
686 struct hbq_s *hbqp = &phba->hbqs[hbqno];
687
688 if (hbqp->next_hbqPutIdx == hbqp->hbqPutIdx &&
689 ++hbqp->next_hbqPutIdx >= hbqp->entry_count)
690 hbqp->next_hbqPutIdx = 0;
691
692 if (unlikely(hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)) {
693 uint32_t raw_index = phba->hbq_get[hbqno];
694 uint32_t getidx = le32_to_cpu(raw_index);
695
696 hbqp->local_hbqGetIdx = getidx;
697
698 if (unlikely(hbqp->local_hbqGetIdx >= hbqp->entry_count)) {
699 lpfc_printf_log(phba, KERN_ERR,
700 LOG_SLI | LOG_VPORT,
701 "1802 HBQ %d: local_hbqGetIdx "
702 "%u is > than hbqp->entry_count %u\n",
703 hbqno, hbqp->local_hbqGetIdx,
704 hbqp->entry_count);
705
706 phba->link_state = LPFC_HBA_ERROR;
707 return NULL;
708 }
709
710 if (hbqp->local_hbqGetIdx == hbqp->next_hbqPutIdx)
711 return NULL;
712 }
713
714 return (struct lpfc_hbq_entry *) phba->hbqs[hbqno].hbq_virt +
715 hbqp->hbqPutIdx;
716}
717
718
719
720
721
722
723
724
725
726
727void
728lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
729{
730 struct lpfc_dmabuf *dmabuf, *next_dmabuf;
731 struct hbq_dmabuf *hbq_buf;
732 unsigned long flags;
733 int i, hbq_count;
734 uint32_t hbqno;
735
736 hbq_count = lpfc_sli_hbq_count();
737
738 spin_lock_irqsave(&phba->hbalock, flags);
739 for (i = 0; i < hbq_count; ++i) {
740 list_for_each_entry_safe(dmabuf, next_dmabuf,
741 &phba->hbqs[i].hbq_buffer_list, list) {
742 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
743 list_del(&hbq_buf->dbuf.list);
744 (phba->hbqs[i].hbq_free_buffer)(phba, hbq_buf);
745 }
746 phba->hbqs[i].buffer_count = 0;
747 }
748
749 list_for_each_entry_safe(dmabuf, next_dmabuf,
750 &phba->hbqbuf_in_list, list) {
751 hbq_buf = container_of(dmabuf, struct hbq_dmabuf, dbuf);
752 list_del(&hbq_buf->dbuf.list);
753 if (hbq_buf->tag == -1) {
754 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
755 (phba, hbq_buf);
756 } else {
757 hbqno = hbq_buf->tag >> 16;
758 if (hbqno >= LPFC_MAX_HBQS)
759 (phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer)
760 (phba, hbq_buf);
761 else
762 (phba->hbqs[hbqno].hbq_free_buffer)(phba,
763 hbq_buf);
764 }
765 }
766
767
768 phba->hbq_in_use = 0;
769 spin_unlock_irqrestore(&phba->hbalock, flags);
770}
771
772
773
774
775
776
777
778
779
780
781
782
783
784static struct lpfc_hbq_entry *
785lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
786 struct hbq_dmabuf *hbq_buf)
787{
788 struct lpfc_hbq_entry *hbqe;
789 dma_addr_t physaddr = hbq_buf->dbuf.phys;
790
791
792 hbqe = lpfc_sli_next_hbq_slot(phba, hbqno);
793 if (hbqe) {
794 struct hbq_s *hbqp = &phba->hbqs[hbqno];
795
796 hbqe->bde.addrHigh = le32_to_cpu(putPaddrHigh(physaddr));
797 hbqe->bde.addrLow = le32_to_cpu(putPaddrLow(physaddr));
798 hbqe->bde.tus.f.bdeSize = hbq_buf->size;
799 hbqe->bde.tus.f.bdeFlags = 0;
800 hbqe->bde.tus.w = le32_to_cpu(hbqe->bde.tus.w);
801 hbqe->buffer_tag = le32_to_cpu(hbq_buf->tag);
802
803 hbqp->hbqPutIdx = hbqp->next_hbqPutIdx;
804 writel(hbqp->hbqPutIdx, phba->hbq_put + hbqno);
805
806 readl(phba->hbq_put + hbqno);
807 list_add_tail(&hbq_buf->dbuf.list, &hbqp->hbq_buffer_list);
808 }
809 return hbqe;
810}
811
812
813static struct lpfc_hbq_init lpfc_els_hbq = {
814 .rn = 1,
815 .entry_count = 200,
816 .mask_count = 0,
817 .profile = 0,
818 .ring_mask = (1 << LPFC_ELS_RING),
819 .buffer_count = 0,
820 .init_count = 20,
821 .add_count = 5,
822};
823
824
825static struct lpfc_hbq_init lpfc_extra_hbq = {
826 .rn = 1,
827 .entry_count = 200,
828 .mask_count = 0,
829 .profile = 0,
830 .ring_mask = (1 << LPFC_EXTRA_RING),
831 .buffer_count = 0,
832 .init_count = 0,
833 .add_count = 5,
834};
835
836
837struct lpfc_hbq_init *lpfc_hbq_defs[] = {
838 &lpfc_els_hbq,
839 &lpfc_extra_hbq,
840};
841
842
843
844
845
846
847
848
849
850
851
852static int
853lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
854{
855 uint32_t i, posted = 0;
856 unsigned long flags;
857 struct hbq_dmabuf *hbq_buffer;
858 LIST_HEAD(hbq_buf_list);
859 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
860 return 0;
861
862 if ((phba->hbqs[hbqno].buffer_count + count) >
863 lpfc_hbq_defs[hbqno]->entry_count)
864 count = lpfc_hbq_defs[hbqno]->entry_count -
865 phba->hbqs[hbqno].buffer_count;
866 if (!count)
867 return 0;
868
869 for (i = 0; i < count; i++) {
870 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
871 if (!hbq_buffer)
872 break;
873 list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
874 }
875
876 spin_lock_irqsave(&phba->hbalock, flags);
877 if (!phba->hbq_in_use)
878 goto err;
879 while (!list_empty(&hbq_buf_list)) {
880 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
881 dbuf.list);
882 hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
883 (hbqno << 16));
884 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
885 phba->hbqs[hbqno].buffer_count++;
886 posted++;
887 } else
888 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
889 }
890 spin_unlock_irqrestore(&phba->hbalock, flags);
891 return posted;
892err:
893 spin_unlock_irqrestore(&phba->hbalock, flags);
894 while (!list_empty(&hbq_buf_list)) {
895 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
896 dbuf.list);
897 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
898 }
899 return 0;
900}
901
902
903
904
905
906
907
908
909
910
911int
912lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
913{
914 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
915 lpfc_hbq_defs[qno]->add_count));
916}
917
918
919
920
921
922
923
924
925
926
927static int
928lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
929{
930 return(lpfc_sli_hbqbuf_fill_hbqs(phba, qno,
931 lpfc_hbq_defs[qno]->init_count));
932}
933
934
935
936
937
938
939
940
941
942
943
944static struct hbq_dmabuf *
945lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
946{
947 struct lpfc_dmabuf *d_buf;
948 struct hbq_dmabuf *hbq_buf;
949 uint32_t hbqno;
950
951 hbqno = tag >> 16;
952 if (hbqno >= LPFC_MAX_HBQS)
953 return NULL;
954
955 list_for_each_entry(d_buf, &phba->hbqs[hbqno].hbq_buffer_list, list) {
956 hbq_buf = container_of(d_buf, struct hbq_dmabuf, dbuf);
957 if (hbq_buf->tag == tag) {
958 return hbq_buf;
959 }
960 }
961 lpfc_printf_log(phba, KERN_ERR, LOG_SLI | LOG_VPORT,
962 "1803 Bad hbq tag. Data: x%x x%x\n",
963 tag, phba->hbqs[tag >> 16].buffer_count);
964 return NULL;
965}
966
967
968
969
970
971
972
973
974
975
976void
977lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
978{
979 uint32_t hbqno;
980
981 if (hbq_buffer) {
982 hbqno = hbq_buffer->tag >> 16;
983 if (!lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
984 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
985 }
986 }
987}
988
989
990
991
992
993
994
995
996
997
998static int
999lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
1000{
1001 uint8_t ret;
1002
1003 switch (mbxCommand) {
1004 case MBX_LOAD_SM:
1005 case MBX_READ_NV:
1006 case MBX_WRITE_NV:
1007 case MBX_WRITE_VPARMS:
1008 case MBX_RUN_BIU_DIAG:
1009 case MBX_INIT_LINK:
1010 case MBX_DOWN_LINK:
1011 case MBX_CONFIG_LINK:
1012 case MBX_CONFIG_RING:
1013 case MBX_RESET_RING:
1014 case MBX_READ_CONFIG:
1015 case MBX_READ_RCONFIG:
1016 case MBX_READ_SPARM:
1017 case MBX_READ_STATUS:
1018 case MBX_READ_RPI:
1019 case MBX_READ_XRI:
1020 case MBX_READ_REV:
1021 case MBX_READ_LNK_STAT:
1022 case MBX_REG_LOGIN:
1023 case MBX_UNREG_LOGIN:
1024 case MBX_READ_LA:
1025 case MBX_CLEAR_LA:
1026 case MBX_DUMP_MEMORY:
1027 case MBX_DUMP_CONTEXT:
1028 case MBX_RUN_DIAGS:
1029 case MBX_RESTART:
1030 case MBX_UPDATE_CFG:
1031 case MBX_DOWN_LOAD:
1032 case MBX_DEL_LD_ENTRY:
1033 case MBX_RUN_PROGRAM:
1034 case MBX_SET_MASK:
1035 case MBX_SET_VARIABLE:
1036 case MBX_UNREG_D_ID:
1037 case MBX_KILL_BOARD:
1038 case MBX_CONFIG_FARP:
1039 case MBX_BEACON:
1040 case MBX_LOAD_AREA:
1041 case MBX_RUN_BIU_DIAG64:
1042 case MBX_CONFIG_PORT:
1043 case MBX_READ_SPARM64:
1044 case MBX_READ_RPI64:
1045 case MBX_REG_LOGIN64:
1046 case MBX_READ_LA64:
1047 case MBX_WRITE_WWN:
1048 case MBX_SET_DEBUG:
1049 case MBX_LOAD_EXP_ROM:
1050 case MBX_ASYNCEVT_ENABLE:
1051 case MBX_REG_VPI:
1052 case MBX_UNREG_VPI:
1053 case MBX_HEARTBEAT:
1054 case MBX_PORT_CAPABILITIES:
1055 case MBX_PORT_IOV_CONTROL:
1056 ret = mbxCommand;
1057 break;
1058 default:
1059 ret = MBX_SHUTDOWN;
1060 break;
1061 }
1062 return ret;
1063}
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077static void
1078lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
1079{
1080 wait_queue_head_t *pdone_q;
1081 unsigned long drvr_flag;
1082
1083
1084
1085
1086
1087 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
1088 spin_lock_irqsave(&phba->hbalock, drvr_flag);
1089 pdone_q = (wait_queue_head_t *) pmboxq->context1;
1090 if (pdone_q)
1091 wake_up_interruptible(pdone_q);
1092 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
1093 return;
1094}
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107void
1108lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1109{
1110 struct lpfc_dmabuf *mp;
1111 uint16_t rpi;
1112 int rc;
1113
1114 mp = (struct lpfc_dmabuf *) (pmb->context1);
1115
1116 if (mp) {
1117 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1118 kfree(mp);
1119 }
1120
1121
1122
1123
1124
1125 if (!(phba->pport->load_flag & FC_UNLOADING) &&
1126 pmb->mb.mbxCommand == MBX_REG_LOGIN64 &&
1127 !pmb->mb.mbxStatus) {
1128
1129 rpi = pmb->mb.un.varWords[0];
1130 lpfc_unreg_login(phba, pmb->mb.un.varRegLogin.vpi, rpi, pmb);
1131 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1132 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1133 if (rc != MBX_NOT_FINISHED)
1134 return;
1135 }
1136
1137 mempool_free(pmb, phba->mbox_mem_pool);
1138 return;
1139}
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154int
1155lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
1156{
1157 MAILBOX_t *pmbox;
1158 LPFC_MBOXQ_t *pmb;
1159 int rc;
1160 LIST_HEAD(cmplq);
1161
1162 phba->sli.slistat.mbox_event++;
1163
1164
1165 spin_lock_irq(&phba->hbalock);
1166 list_splice_init(&phba->sli.mboxq_cmpl, &cmplq);
1167 spin_unlock_irq(&phba->hbalock);
1168
1169
1170 do {
1171 list_remove_head(&cmplq, pmb, LPFC_MBOXQ_t, list);
1172 if (pmb == NULL)
1173 break;
1174
1175 pmbox = &pmb->mb;
1176
1177 if (pmbox->mbxCommand != MBX_HEARTBEAT) {
1178 if (pmb->vport) {
1179 lpfc_debugfs_disc_trc(pmb->vport,
1180 LPFC_DISC_TRC_MBOX_VPORT,
1181 "MBOX cmpl vport: cmd:x%x mb:x%x x%x",
1182 (uint32_t)pmbox->mbxCommand,
1183 pmbox->un.varWords[0],
1184 pmbox->un.varWords[1]);
1185 }
1186 else {
1187 lpfc_debugfs_disc_trc(phba->pport,
1188 LPFC_DISC_TRC_MBOX,
1189 "MBOX cmpl: cmd:x%x mb:x%x x%x",
1190 (uint32_t)pmbox->mbxCommand,
1191 pmbox->un.varWords[0],
1192 pmbox->un.varWords[1]);
1193 }
1194 }
1195
1196
1197
1198
1199 if (lpfc_sli_chk_mbx_command(pmbox->mbxCommand) ==
1200 MBX_SHUTDOWN) {
1201
1202 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
1203 "(%d):0323 Unknown Mailbox command "
1204 "%x Cmpl\n",
1205 pmb->vport ? pmb->vport->vpi : 0,
1206 pmbox->mbxCommand);
1207 phba->link_state = LPFC_HBA_ERROR;
1208 phba->work_hs = HS_FFER3;
1209 lpfc_handle_eratt(phba);
1210 continue;
1211 }
1212
1213 if (pmbox->mbxStatus) {
1214 phba->sli.slistat.mbox_stat_err++;
1215 if (pmbox->mbxStatus == MBXERR_NO_RESOURCES) {
1216
1217 lpfc_printf_log(phba, KERN_INFO,
1218 LOG_MBOX | LOG_SLI,
1219 "(%d):0305 Mbox cmd cmpl "
1220 "error - RETRYing Data: x%x "
1221 "x%x x%x x%x\n",
1222 pmb->vport ? pmb->vport->vpi :0,
1223 pmbox->mbxCommand,
1224 pmbox->mbxStatus,
1225 pmbox->un.varWords[0],
1226 pmb->vport->port_state);
1227 pmbox->mbxStatus = 0;
1228 pmbox->mbxOwner = OWN_HOST;
1229 spin_lock_irq(&phba->hbalock);
1230 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1231 spin_unlock_irq(&phba->hbalock);
1232 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
1233 if (rc == MBX_SUCCESS)
1234 continue;
1235 }
1236 }
1237
1238
1239 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
1240 "(%d):0307 Mailbox cmd x%x Cmpl x%p "
1241 "Data: x%x x%x x%x x%x x%x x%x x%x x%x x%x\n",
1242 pmb->vport ? pmb->vport->vpi : 0,
1243 pmbox->mbxCommand,
1244 pmb->mbox_cmpl,
1245 *((uint32_t *) pmbox),
1246 pmbox->un.varWords[0],
1247 pmbox->un.varWords[1],
1248 pmbox->un.varWords[2],
1249 pmbox->un.varWords[3],
1250 pmbox->un.varWords[4],
1251 pmbox->un.varWords[5],
1252 pmbox->un.varWords[6],
1253 pmbox->un.varWords[7]);
1254
1255 if (pmb->mbox_cmpl)
1256 pmb->mbox_cmpl(phba,pmb);
1257 } while (1);
1258 return 0;
1259}
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273static struct lpfc_dmabuf *
1274lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag)
1275{
1276 struct hbq_dmabuf *hbq_entry, *new_hbq_entry;
1277 uint32_t hbqno;
1278 void *virt;
1279 dma_addr_t phys;
1280 unsigned long flags;
1281
1282 hbqno = tag >> 16;
1283 new_hbq_entry = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
1284
1285 spin_lock_irqsave(&phba->hbalock, flags);
1286 if (!phba->hbq_in_use) {
1287 if (new_hbq_entry)
1288 (phba->hbqs[hbqno].hbq_free_buffer)(phba,
1289 new_hbq_entry);
1290 spin_unlock_irqrestore(&phba->hbalock, flags);
1291 return NULL;
1292 }
1293
1294 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
1295 if (hbq_entry == NULL) {
1296 if (new_hbq_entry)
1297 (phba->hbqs[hbqno].hbq_free_buffer)(phba,
1298 new_hbq_entry);
1299 spin_unlock_irqrestore(&phba->hbalock, flags);
1300 return NULL;
1301 }
1302 list_del(&hbq_entry->dbuf.list);
1303
1304 if (new_hbq_entry == NULL) {
1305 list_add_tail(&hbq_entry->dbuf.list, &phba->hbqbuf_in_list);
1306 spin_unlock_irqrestore(&phba->hbalock, flags);
1307 return &hbq_entry->dbuf;
1308 }
1309 new_hbq_entry->tag = -1;
1310 phys = new_hbq_entry->dbuf.phys;
1311 virt = new_hbq_entry->dbuf.virt;
1312 new_hbq_entry->dbuf.phys = hbq_entry->dbuf.phys;
1313 new_hbq_entry->dbuf.virt = hbq_entry->dbuf.virt;
1314 hbq_entry->dbuf.phys = phys;
1315 hbq_entry->dbuf.virt = virt;
1316 lpfc_sli_free_hbq(phba, hbq_entry);
1317 list_add_tail(&new_hbq_entry->dbuf.list, &phba->hbqbuf_in_list);
1318 spin_unlock_irqrestore(&phba->hbalock, flags);
1319
1320 return &new_hbq_entry->dbuf;
1321}
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335static struct lpfc_dmabuf *
1336lpfc_sli_get_buff(struct lpfc_hba *phba,
1337 struct lpfc_sli_ring *pring,
1338 uint32_t tag)
1339{
1340 if (tag & QUE_BUFTAG_BIT)
1341 return lpfc_sli_ring_taggedbuf_get(phba, pring, tag);
1342 else
1343 return lpfc_sli_replace_hbqbuff(phba, tag);
1344}
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361static int
1362lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1363 struct lpfc_iocbq *saveq)
1364{
1365 IOCB_t * irsp;
1366 WORD5 * w5p;
1367 uint32_t Rctl, Type;
1368 uint32_t match, i;
1369 struct lpfc_iocbq *iocbq;
1370 struct lpfc_dmabuf *dmzbuf;
1371
1372 match = 0;
1373 irsp = &(saveq->iocb);
1374
1375 if (irsp->ulpStatus == IOSTAT_NEED_BUFFER)
1376 return 1;
1377 if (irsp->ulpCommand == CMD_ASYNC_STATUS) {
1378 if (pring->lpfc_sli_rcv_async_status)
1379 pring->lpfc_sli_rcv_async_status(phba, pring, saveq);
1380 else
1381 lpfc_printf_log(phba,
1382 KERN_WARNING,
1383 LOG_SLI,
1384 "0316 Ring %d handler: unexpected "
1385 "ASYNC_STATUS iocb received evt_code "
1386 "0x%x\n",
1387 pring->ringno,
1388 irsp->un.asyncstat.evt_code);
1389 return 1;
1390 }
1391
1392 if ((irsp->ulpCommand == CMD_IOCB_RET_XRI64_CX) &&
1393 (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)) {
1394 if (irsp->ulpBdeCount > 0) {
1395 dmzbuf = lpfc_sli_get_buff(phba, pring,
1396 irsp->un.ulpWord[3]);
1397 lpfc_in_buf_free(phba, dmzbuf);
1398 }
1399
1400 if (irsp->ulpBdeCount > 1) {
1401 dmzbuf = lpfc_sli_get_buff(phba, pring,
1402 irsp->unsli3.sli3Words[3]);
1403 lpfc_in_buf_free(phba, dmzbuf);
1404 }
1405
1406 if (irsp->ulpBdeCount > 2) {
1407 dmzbuf = lpfc_sli_get_buff(phba, pring,
1408 irsp->unsli3.sli3Words[7]);
1409 lpfc_in_buf_free(phba, dmzbuf);
1410 }
1411
1412 return 1;
1413 }
1414
1415 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
1416 if (irsp->ulpBdeCount != 0) {
1417 saveq->context2 = lpfc_sli_get_buff(phba, pring,
1418 irsp->un.ulpWord[3]);
1419 if (!saveq->context2)
1420 lpfc_printf_log(phba,
1421 KERN_ERR,
1422 LOG_SLI,
1423 "0341 Ring %d Cannot find buffer for "
1424 "an unsolicited iocb. tag 0x%x\n",
1425 pring->ringno,
1426 irsp->un.ulpWord[3]);
1427 }
1428 if (irsp->ulpBdeCount == 2) {
1429 saveq->context3 = lpfc_sli_get_buff(phba, pring,
1430 irsp->unsli3.sli3Words[7]);
1431 if (!saveq->context3)
1432 lpfc_printf_log(phba,
1433 KERN_ERR,
1434 LOG_SLI,
1435 "0342 Ring %d Cannot find buffer for an"
1436 " unsolicited iocb. tag 0x%x\n",
1437 pring->ringno,
1438 irsp->unsli3.sli3Words[7]);
1439 }
1440 list_for_each_entry(iocbq, &saveq->list, list) {
1441 irsp = &(iocbq->iocb);
1442 if (irsp->ulpBdeCount != 0) {
1443 iocbq->context2 = lpfc_sli_get_buff(phba, pring,
1444 irsp->un.ulpWord[3]);
1445 if (!iocbq->context2)
1446 lpfc_printf_log(phba,
1447 KERN_ERR,
1448 LOG_SLI,
1449 "0343 Ring %d Cannot find "
1450 "buffer for an unsolicited iocb"
1451 ". tag 0x%x\n", pring->ringno,
1452 irsp->un.ulpWord[3]);
1453 }
1454 if (irsp->ulpBdeCount == 2) {
1455 iocbq->context3 = lpfc_sli_get_buff(phba, pring,
1456 irsp->unsli3.sli3Words[7]);
1457 if (!iocbq->context3)
1458 lpfc_printf_log(phba,
1459 KERN_ERR,
1460 LOG_SLI,
1461 "0344 Ring %d Cannot find "
1462 "buffer for an unsolicited "
1463 "iocb. tag 0x%x\n",
1464 pring->ringno,
1465 irsp->unsli3.sli3Words[7]);
1466 }
1467 }
1468 }
1469 if (irsp->ulpBdeCount != 0 &&
1470 (irsp->ulpCommand == CMD_IOCB_RCV_CONT64_CX ||
1471 irsp->ulpStatus == IOSTAT_INTERMED_RSP)) {
1472 int found = 0;
1473
1474
1475 list_for_each_entry(iocbq, &pring->iocb_continue_saveq, clist) {
1476 if (iocbq->iocb.ulpContext == saveq->iocb.ulpContext) {
1477 list_add_tail(&saveq->list, &iocbq->list);
1478 found = 1;
1479 break;
1480 }
1481 }
1482 if (!found)
1483 list_add_tail(&saveq->clist,
1484 &pring->iocb_continue_saveq);
1485 if (saveq->iocb.ulpStatus != IOSTAT_INTERMED_RSP) {
1486 list_del_init(&iocbq->clist);
1487 saveq = iocbq;
1488 irsp = &(saveq->iocb);
1489 } else
1490 return 0;
1491 }
1492 if ((irsp->ulpCommand == CMD_RCV_ELS_REQ64_CX) ||
1493 (irsp->ulpCommand == CMD_RCV_ELS_REQ_CX) ||
1494 (irsp->ulpCommand == CMD_IOCB_RCV_ELS64_CX)) {
1495 Rctl = FC_ELS_REQ;
1496 Type = FC_ELS_DATA;
1497 } else {
1498 w5p = (WORD5 *)&(saveq->iocb.un.ulpWord[5]);
1499 Rctl = w5p->hcsw.Rctl;
1500 Type = w5p->hcsw.Type;
1501
1502
1503 if ((Rctl == 0) && (pring->ringno == LPFC_ELS_RING) &&
1504 (irsp->ulpCommand == CMD_RCV_SEQUENCE64_CX ||
1505 irsp->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
1506 Rctl = FC_ELS_REQ;
1507 Type = FC_ELS_DATA;
1508 w5p->hcsw.Rctl = Rctl;
1509 w5p->hcsw.Type = Type;
1510 }
1511 }
1512
1513
1514 if (pring->prt[0].profile) {
1515 if (pring->prt[0].lpfc_sli_rcv_unsol_event)
1516 (pring->prt[0].lpfc_sli_rcv_unsol_event) (phba, pring,
1517 saveq);
1518 match = 1;
1519 } else {
1520
1521
1522 for (i = 0; i < pring->num_mask; i++) {
1523 if ((pring->prt[i].rctl == Rctl)
1524 && (pring->prt[i].type == Type)) {
1525 if (pring->prt[i].lpfc_sli_rcv_unsol_event)
1526 (pring->prt[i].lpfc_sli_rcv_unsol_event)
1527 (phba, pring, saveq);
1528 match = 1;
1529 break;
1530 }
1531 }
1532 }
1533 if (match == 0) {
1534
1535
1536
1537 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1538 "0313 Ring %d handler: unexpected Rctl x%x "
1539 "Type x%x received\n",
1540 pring->ringno, Rctl, Type);
1541 }
1542 return 1;
1543}
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557static struct lpfc_iocbq *
1558lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
1559 struct lpfc_sli_ring *pring,
1560 struct lpfc_iocbq *prspiocb)
1561{
1562 struct lpfc_iocbq *cmd_iocb = NULL;
1563 uint16_t iotag;
1564
1565 iotag = prspiocb->iocb.ulpIoTag;
1566
1567 if (iotag != 0 && iotag <= phba->sli.last_iotag) {
1568 cmd_iocb = phba->sli.iocbq_lookup[iotag];
1569 list_del_init(&cmd_iocb->list);
1570 pring->txcmplq_cnt--;
1571 return cmd_iocb;
1572 }
1573
1574 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1575 "0317 iotag x%x is out off "
1576 "range: max iotag x%x wd0 x%x\n",
1577 iotag, phba->sli.last_iotag,
1578 *(((uint32_t *) &prspiocb->iocb) + 7));
1579 return NULL;
1580}
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599static int
1600lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1601 struct lpfc_iocbq *saveq)
1602{
1603 struct lpfc_iocbq *cmdiocbp;
1604 int rc = 1;
1605 unsigned long iflag;
1606
1607
1608 spin_lock_irqsave(&phba->hbalock, iflag);
1609 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
1610 spin_unlock_irqrestore(&phba->hbalock, iflag);
1611
1612 if (cmdiocbp) {
1613 if (cmdiocbp->iocb_cmpl) {
1614
1615
1616
1617
1618 if (saveq->iocb.ulpStatus &&
1619 (pring->ringno == LPFC_ELS_RING) &&
1620 (cmdiocbp->iocb.ulpCommand ==
1621 CMD_ELS_REQUEST64_CR))
1622 lpfc_send_els_failure_event(phba,
1623 cmdiocbp, saveq);
1624
1625
1626
1627
1628
1629 if (pring->ringno == LPFC_ELS_RING) {
1630 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
1631 cmdiocbp->iocb_flag &=
1632 ~LPFC_DRIVER_ABORTED;
1633 saveq->iocb.ulpStatus =
1634 IOSTAT_LOCAL_REJECT;
1635 saveq->iocb.un.ulpWord[4] =
1636 IOERR_SLI_ABORTED;
1637
1638
1639
1640
1641
1642 saveq->iocb_flag |= LPFC_DELAY_MEM_FREE;
1643 }
1644 }
1645 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
1646 } else
1647 lpfc_sli_release_iocbq(phba, cmdiocbp);
1648 } else {
1649
1650
1651
1652
1653
1654 if (pring->ringno != LPFC_ELS_RING) {
1655
1656
1657
1658
1659 lpfc_printf_vlog(cmdiocbp->vport, KERN_WARNING, LOG_SLI,
1660 "0322 Ring %d handler: "
1661 "unexpected completion IoTag x%x "
1662 "Data: x%x x%x x%x x%x\n",
1663 pring->ringno,
1664 saveq->iocb.ulpIoTag,
1665 saveq->iocb.ulpStatus,
1666 saveq->iocb.un.ulpWord[4],
1667 saveq->iocb.ulpCommand,
1668 saveq->iocb.ulpContext);
1669 }
1670 }
1671
1672 return rc;
1673}
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685static void
1686lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1687{
1688 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
1689
1690
1691
1692
1693 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1694 "0312 Ring %d handler: portRspPut %d "
1695 "is bigger then rsp ring %d\n",
1696 pring->ringno, le32_to_cpu(pgp->rspPutInx),
1697 pring->numRiocb);
1698
1699 phba->link_state = LPFC_HBA_ERROR;
1700
1701
1702
1703
1704
1705 phba->work_ha |= HA_ERATT;
1706 phba->work_hs = HS_FFER3;
1707
1708 lpfc_worker_wake_up(phba);
1709
1710 return;
1711}
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723void lpfc_poll_eratt(unsigned long ptr)
1724{
1725 struct lpfc_hba *phba;
1726 uint32_t eratt = 0;
1727
1728 phba = (struct lpfc_hba *)ptr;
1729
1730
1731 eratt = lpfc_sli_check_eratt(phba);
1732
1733 if (eratt)
1734
1735 lpfc_worker_wake_up(phba);
1736 else
1737
1738 mod_timer(&phba->eratt_poll, jiffies +
1739 HZ * LPFC_ERATT_POLL_INTERVAL);
1740 return;
1741}
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
1759{
1760 struct lpfc_sli *psli = &phba->sli;
1761 struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
1762 IOCB_t *irsp = NULL;
1763 IOCB_t *entry = NULL;
1764 struct lpfc_iocbq *cmdiocbq = NULL;
1765 struct lpfc_iocbq rspiocbq;
1766 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
1767 uint32_t status;
1768 uint32_t portRspPut, portRspMax;
1769 int type;
1770 uint32_t rsp_cmpl = 0;
1771 uint32_t ha_copy;
1772 unsigned long iflags;
1773
1774 pring->stats.iocb_event++;
1775
1776
1777
1778
1779
1780 portRspMax = pring->numRiocb;
1781 portRspPut = le32_to_cpu(pgp->rspPutInx);
1782 if (unlikely(portRspPut >= portRspMax)) {
1783 lpfc_sli_rsp_pointers_error(phba, pring);
1784 return;
1785 }
1786
1787 rmb();
1788 while (pring->rspidx != portRspPut) {
1789 entry = lpfc_resp_iocb(phba, pring);
1790 if (++pring->rspidx >= portRspMax)
1791 pring->rspidx = 0;
1792
1793 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1794 (uint32_t *) &rspiocbq.iocb,
1795 phba->iocb_rsp_size);
1796 irsp = &rspiocbq.iocb;
1797 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1798 pring->stats.iocb_rsp++;
1799 rsp_cmpl++;
1800
1801 if (unlikely(irsp->ulpStatus)) {
1802
1803 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1804 "0326 Rsp Ring %d error: IOCB Data: "
1805 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1806 pring->ringno,
1807 irsp->un.ulpWord[0],
1808 irsp->un.ulpWord[1],
1809 irsp->un.ulpWord[2],
1810 irsp->un.ulpWord[3],
1811 irsp->un.ulpWord[4],
1812 irsp->un.ulpWord[5],
1813 *(uint32_t *)&irsp->un1,
1814 *((uint32_t *)&irsp->un1 + 1));
1815 }
1816
1817 switch (type) {
1818 case LPFC_ABORT_IOCB:
1819 case LPFC_SOL_IOCB:
1820
1821
1822
1823
1824 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
1825 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1826 "0314 IOCB cmd 0x%x "
1827 "processed. Skipping "
1828 "completion",
1829 irsp->ulpCommand);
1830 break;
1831 }
1832
1833 spin_lock_irqsave(&phba->hbalock, iflags);
1834 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1835 &rspiocbq);
1836 spin_unlock_irqrestore(&phba->hbalock, iflags);
1837 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1838 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1839 &rspiocbq);
1840 }
1841 break;
1842 default:
1843 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
1844 char adaptermsg[LPFC_MAX_ADPTMSG];
1845 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
1846 memcpy(&adaptermsg[0], (uint8_t *) irsp,
1847 MAX_MSG_DATA);
1848 dev_warn(&((phba->pcidev)->dev),
1849 "lpfc%d: %s\n",
1850 phba->brd_no, adaptermsg);
1851 } else {
1852
1853 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
1854 "0321 Unknown IOCB command "
1855 "Data: x%x, x%x x%x x%x x%x\n",
1856 type, irsp->ulpCommand,
1857 irsp->ulpStatus,
1858 irsp->ulpIoTag,
1859 irsp->ulpContext);
1860 }
1861 break;
1862 }
1863
1864
1865
1866
1867
1868
1869
1870 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
1871
1872 if (pring->rspidx == portRspPut)
1873 portRspPut = le32_to_cpu(pgp->rspPutInx);
1874 }
1875
1876 ha_copy = readl(phba->HAregaddr);
1877 ha_copy >>= (LPFC_FCP_RING * 4);
1878
1879 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
1880 spin_lock_irqsave(&phba->hbalock, iflags);
1881 pring->stats.iocb_rsp_full++;
1882 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
1883 writel(status, phba->CAregaddr);
1884 readl(phba->CAregaddr);
1885 spin_unlock_irqrestore(&phba->hbalock, iflags);
1886 }
1887 if ((ha_copy & HA_R0CE_RSP) &&
1888 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1889 spin_lock_irqsave(&phba->hbalock, iflags);
1890 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1891 pring->stats.iocb_cmd_empty++;
1892
1893
1894 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
1895 lpfc_sli_resume_iocb(phba, pring);
1896
1897 if ((pring->lpfc_sli_cmd_available))
1898 (pring->lpfc_sli_cmd_available) (phba, pring);
1899
1900 spin_unlock_irqrestore(&phba->hbalock, iflags);
1901 }
1902
1903 return;
1904}
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923static int
1924lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1925 struct lpfc_sli_ring *pring, uint32_t mask)
1926{
1927 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
1928 IOCB_t *irsp = NULL;
1929 IOCB_t *entry = NULL;
1930 struct lpfc_iocbq *cmdiocbq = NULL;
1931 struct lpfc_iocbq rspiocbq;
1932 uint32_t status;
1933 uint32_t portRspPut, portRspMax;
1934 int rc = 1;
1935 lpfc_iocb_type type;
1936 unsigned long iflag;
1937 uint32_t rsp_cmpl = 0;
1938
1939 spin_lock_irqsave(&phba->hbalock, iflag);
1940 pring->stats.iocb_event++;
1941
1942
1943
1944
1945
1946 portRspMax = pring->numRiocb;
1947 portRspPut = le32_to_cpu(pgp->rspPutInx);
1948 if (unlikely(portRspPut >= portRspMax)) {
1949 lpfc_sli_rsp_pointers_error(phba, pring);
1950 spin_unlock_irqrestore(&phba->hbalock, iflag);
1951 return 1;
1952 }
1953
1954 rmb();
1955 while (pring->rspidx != portRspPut) {
1956
1957
1958
1959
1960
1961 entry = lpfc_resp_iocb(phba, pring);
1962 phba->last_completion_time = jiffies;
1963
1964 if (++pring->rspidx >= portRspMax)
1965 pring->rspidx = 0;
1966
1967 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1968 (uint32_t *) &rspiocbq.iocb,
1969 phba->iocb_rsp_size);
1970 INIT_LIST_HEAD(&(rspiocbq.list));
1971 irsp = &rspiocbq.iocb;
1972
1973 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
1974 pring->stats.iocb_rsp++;
1975 rsp_cmpl++;
1976
1977 if (unlikely(irsp->ulpStatus)) {
1978
1979
1980
1981
1982 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1983 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
1984 spin_unlock_irqrestore(&phba->hbalock, iflag);
1985 lpfc_adjust_queue_depth(phba);
1986 spin_lock_irqsave(&phba->hbalock, iflag);
1987 }
1988
1989
1990 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
1991 "0336 Rsp Ring %d error: IOCB Data: "
1992 "x%x x%x x%x x%x x%x x%x x%x x%x\n",
1993 pring->ringno,
1994 irsp->un.ulpWord[0],
1995 irsp->un.ulpWord[1],
1996 irsp->un.ulpWord[2],
1997 irsp->un.ulpWord[3],
1998 irsp->un.ulpWord[4],
1999 irsp->un.ulpWord[5],
2000 *(uint32_t *)&irsp->un1,
2001 *((uint32_t *)&irsp->un1 + 1));
2002 }
2003
2004 switch (type) {
2005 case LPFC_ABORT_IOCB:
2006 case LPFC_SOL_IOCB:
2007
2008
2009
2010
2011 if (unlikely(irsp->ulpCommand == CMD_XRI_ABORTED_CX)) {
2012 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2013 "0333 IOCB cmd 0x%x"
2014 " processed. Skipping"
2015 " completion\n",
2016 irsp->ulpCommand);
2017 break;
2018 }
2019
2020 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
2021 &rspiocbq);
2022 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
2023 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
2024 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
2025 &rspiocbq);
2026 } else {
2027 spin_unlock_irqrestore(&phba->hbalock,
2028 iflag);
2029 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
2030 &rspiocbq);
2031 spin_lock_irqsave(&phba->hbalock,
2032 iflag);
2033 }
2034 }
2035 break;
2036 case LPFC_UNSOL_IOCB:
2037 spin_unlock_irqrestore(&phba->hbalock, iflag);
2038 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
2039 spin_lock_irqsave(&phba->hbalock, iflag);
2040 break;
2041 default:
2042 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
2043 char adaptermsg[LPFC_MAX_ADPTMSG];
2044 memset(adaptermsg, 0, LPFC_MAX_ADPTMSG);
2045 memcpy(&adaptermsg[0], (uint8_t *) irsp,
2046 MAX_MSG_DATA);
2047 dev_warn(&((phba->pcidev)->dev),
2048 "lpfc%d: %s\n",
2049 phba->brd_no, adaptermsg);
2050 } else {
2051
2052 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2053 "0334 Unknown IOCB command "
2054 "Data: x%x, x%x x%x x%x x%x\n",
2055 type, irsp->ulpCommand,
2056 irsp->ulpStatus,
2057 irsp->ulpIoTag,
2058 irsp->ulpContext);
2059 }
2060 break;
2061 }
2062
2063
2064
2065
2066
2067
2068
2069 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
2070
2071 if (pring->rspidx == portRspPut)
2072 portRspPut = le32_to_cpu(pgp->rspPutInx);
2073 }
2074
2075 if ((rsp_cmpl > 0) && (mask & HA_R0RE_REQ)) {
2076 pring->stats.iocb_rsp_full++;
2077 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
2078 writel(status, phba->CAregaddr);
2079 readl(phba->CAregaddr);
2080 }
2081 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
2082 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
2083 pring->stats.iocb_cmd_empty++;
2084
2085
2086 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
2087 lpfc_sli_resume_iocb(phba, pring);
2088
2089 if ((pring->lpfc_sli_cmd_available))
2090 (pring->lpfc_sli_cmd_available) (phba, pring);
2091
2092 }
2093
2094 spin_unlock_irqrestore(&phba->hbalock, iflag);
2095 return rc;
2096}
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115int
2116lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
2117 struct lpfc_sli_ring *pring, uint32_t mask)
2118{
2119 struct lpfc_pgp *pgp;
2120 IOCB_t *entry;
2121 IOCB_t *irsp = NULL;
2122 struct lpfc_iocbq *rspiocbp = NULL;
2123 struct lpfc_iocbq *next_iocb;
2124 struct lpfc_iocbq *cmdiocbp;
2125 struct lpfc_iocbq *saveq;
2126 uint8_t iocb_cmd_type;
2127 lpfc_iocb_type type;
2128 uint32_t status, free_saveq;
2129 uint32_t portRspPut, portRspMax;
2130 int rc = 1;
2131 unsigned long iflag;
2132
2133 pgp = &phba->port_gp[pring->ringno];
2134 spin_lock_irqsave(&phba->hbalock, iflag);
2135 pring->stats.iocb_event++;
2136
2137
2138
2139
2140
2141 portRspMax = pring->numRiocb;
2142 portRspPut = le32_to_cpu(pgp->rspPutInx);
2143 if (portRspPut >= portRspMax) {
2144
2145
2146
2147
2148 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2149 "0303 Ring %d handler: portRspPut %d "
2150 "is bigger then rsp ring %d\n",
2151 pring->ringno, portRspPut, portRspMax);
2152
2153 phba->link_state = LPFC_HBA_ERROR;
2154 spin_unlock_irqrestore(&phba->hbalock, iflag);
2155
2156 phba->work_hs = HS_FFER3;
2157 lpfc_handle_eratt(phba);
2158
2159 return 1;
2160 }
2161
2162 rmb();
2163 while (pring->rspidx != portRspPut) {
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177 entry = lpfc_resp_iocb(phba, pring);
2178
2179 phba->last_completion_time = jiffies;
2180 rspiocbp = __lpfc_sli_get_iocbq(phba);
2181 if (rspiocbp == NULL) {
2182 printk(KERN_ERR "%s: out of buffers! Failing "
2183 "completion.\n", __func__);
2184 break;
2185 }
2186
2187 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb,
2188 phba->iocb_rsp_size);
2189 irsp = &rspiocbp->iocb;
2190
2191 if (++pring->rspidx >= portRspMax)
2192 pring->rspidx = 0;
2193
2194 if (pring->ringno == LPFC_ELS_RING) {
2195 lpfc_debugfs_slow_ring_trc(phba,
2196 "IOCB rsp ring: wd4:x%08x wd6:x%08x wd7:x%08x",
2197 *(((uint32_t *) irsp) + 4),
2198 *(((uint32_t *) irsp) + 6),
2199 *(((uint32_t *) irsp) + 7));
2200 }
2201
2202 writel(pring->rspidx, &phba->host_gp[pring->ringno].rspGetInx);
2203
2204 list_add_tail(&rspiocbp->list, &(pring->iocb_continueq));
2205
2206 pring->iocb_continueq_cnt++;
2207 if (irsp->ulpLe) {
2208
2209
2210
2211
2212 free_saveq = 1;
2213 saveq = list_get_first(&pring->iocb_continueq,
2214 struct lpfc_iocbq, list);
2215 irsp = &(saveq->iocb);
2216 list_del_init(&pring->iocb_continueq);
2217 pring->iocb_continueq_cnt = 0;
2218
2219 pring->stats.iocb_rsp++;
2220
2221
2222
2223
2224
2225 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
2226 (irsp->un.ulpWord[4] == IOERR_NO_RESOURCES)) {
2227 spin_unlock_irqrestore(&phba->hbalock, iflag);
2228 lpfc_adjust_queue_depth(phba);
2229 spin_lock_irqsave(&phba->hbalock, iflag);
2230 }
2231
2232 if (irsp->ulpStatus) {
2233
2234 lpfc_printf_log(phba, KERN_WARNING, LOG_SLI,
2235 "0328 Rsp Ring %d error: "
2236 "IOCB Data: "
2237 "x%x x%x x%x x%x "
2238 "x%x x%x x%x x%x "
2239 "x%x x%x x%x x%x "
2240 "x%x x%x x%x x%x\n",
2241 pring->ringno,
2242 irsp->un.ulpWord[0],
2243 irsp->un.ulpWord[1],
2244 irsp->un.ulpWord[2],
2245 irsp->un.ulpWord[3],
2246 irsp->un.ulpWord[4],
2247 irsp->un.ulpWord[5],
2248 *(((uint32_t *) irsp) + 6),
2249 *(((uint32_t *) irsp) + 7),
2250 *(((uint32_t *) irsp) + 8),
2251 *(((uint32_t *) irsp) + 9),
2252 *(((uint32_t *) irsp) + 10),
2253 *(((uint32_t *) irsp) + 11),
2254 *(((uint32_t *) irsp) + 12),
2255 *(((uint32_t *) irsp) + 13),
2256 *(((uint32_t *) irsp) + 14),
2257 *(((uint32_t *) irsp) + 15));
2258 }
2259
2260
2261
2262
2263
2264
2265
2266 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
2267 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
2268 if (type == LPFC_SOL_IOCB) {
2269 spin_unlock_irqrestore(&phba->hbalock, iflag);
2270 rc = lpfc_sli_process_sol_iocb(phba, pring,
2271 saveq);
2272 spin_lock_irqsave(&phba->hbalock, iflag);
2273 } else if (type == LPFC_UNSOL_IOCB) {
2274 spin_unlock_irqrestore(&phba->hbalock, iflag);
2275 rc = lpfc_sli_process_unsol_iocb(phba, pring,
2276 saveq);
2277 spin_lock_irqsave(&phba->hbalock, iflag);
2278 if (!rc)
2279 free_saveq = 0;
2280 } else if (type == LPFC_ABORT_IOCB) {
2281 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
2282 ((cmdiocbp =
2283 lpfc_sli_iocbq_lookup(phba, pring,
2284 saveq)))) {
2285
2286
2287 if (cmdiocbp->iocb_cmpl) {
2288 spin_unlock_irqrestore(
2289 &phba->hbalock,
2290 iflag);
2291 (cmdiocbp->iocb_cmpl) (phba,
2292 cmdiocbp, saveq);
2293 spin_lock_irqsave(
2294 &phba->hbalock,
2295 iflag);
2296 } else
2297 __lpfc_sli_release_iocbq(phba,
2298 cmdiocbp);
2299 }
2300 } else if (type == LPFC_UNKNOWN_IOCB) {
2301 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
2302
2303 char adaptermsg[LPFC_MAX_ADPTMSG];
2304
2305 memset(adaptermsg, 0,
2306 LPFC_MAX_ADPTMSG);
2307 memcpy(&adaptermsg[0], (uint8_t *) irsp,
2308 MAX_MSG_DATA);
2309 dev_warn(&((phba->pcidev)->dev),
2310 "lpfc%d: %s\n",
2311 phba->brd_no, adaptermsg);
2312 } else {
2313
2314 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2315 "0335 Unknown IOCB "
2316 "command Data: x%x "
2317 "x%x x%x x%x\n",
2318 irsp->ulpCommand,
2319 irsp->ulpStatus,
2320 irsp->ulpIoTag,
2321 irsp->ulpContext);
2322 }
2323 }
2324
2325 if (free_saveq) {
2326 list_for_each_entry_safe(rspiocbp, next_iocb,
2327 &saveq->list, list) {
2328 list_del(&rspiocbp->list);
2329 __lpfc_sli_release_iocbq(phba,
2330 rspiocbp);
2331 }
2332 __lpfc_sli_release_iocbq(phba, saveq);
2333 }
2334 rspiocbp = NULL;
2335 }
2336
2337
2338
2339
2340
2341
2342 if (pring->rspidx == portRspPut) {
2343 portRspPut = le32_to_cpu(pgp->rspPutInx);
2344 }
2345 }
2346
2347 if ((rspiocbp != NULL) && (mask & HA_R0RE_REQ)) {
2348
2349 pring->stats.iocb_rsp_full++;
2350
2351 status = ((CA_R0ATT | CA_R0RE_RSP) << (pring->ringno * 4));
2352 writel(status, phba->CAregaddr);
2353 readl(phba->CAregaddr);
2354 }
2355 if ((mask & HA_R0CE_RSP) && (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
2356 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
2357 pring->stats.iocb_cmd_empty++;
2358
2359
2360 pring->local_getidx = le32_to_cpu(pgp->cmdGetInx);
2361 lpfc_sli_resume_iocb(phba, pring);
2362
2363 if ((pring->lpfc_sli_cmd_available))
2364 (pring->lpfc_sli_cmd_available) (phba, pring);
2365
2366 }
2367
2368 spin_unlock_irqrestore(&phba->hbalock, iflag);
2369 return rc;
2370}
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382void
2383lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
2384{
2385 LIST_HEAD(completions);
2386 struct lpfc_iocbq *iocb, *next_iocb;
2387 IOCB_t *cmd = NULL;
2388
2389 if (pring->ringno == LPFC_ELS_RING) {
2390 lpfc_fabric_abort_hba(phba);
2391 }
2392
2393
2394
2395
2396 spin_lock_irq(&phba->hbalock);
2397 list_splice_init(&pring->txq, &completions);
2398 pring->txq_cnt = 0;
2399
2400
2401 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
2402 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
2403
2404 spin_unlock_irq(&phba->hbalock);
2405
2406 while (!list_empty(&completions)) {
2407 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
2408 cmd = &iocb->iocb;
2409 list_del_init(&iocb->list);
2410
2411 if (!iocb->iocb_cmpl)
2412 lpfc_sli_release_iocbq(phba, iocb);
2413 else {
2414 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2415 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2416 (iocb->iocb_cmpl) (phba, iocb, iocb);
2417 }
2418 }
2419}
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431void
2432lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
2433{
2434 LIST_HEAD(txq);
2435 LIST_HEAD(txcmplq);
2436 struct lpfc_iocbq *iocb;
2437 IOCB_t *cmd = NULL;
2438 struct lpfc_sli *psli = &phba->sli;
2439 struct lpfc_sli_ring *pring;
2440
2441
2442 pring = &psli->ring[psli->fcp_ring];
2443
2444 spin_lock_irq(&phba->hbalock);
2445
2446 list_splice_init(&pring->txq, &txq);
2447 pring->txq_cnt = 0;
2448
2449
2450 list_splice_init(&pring->txcmplq, &txcmplq);
2451 pring->txcmplq_cnt = 0;
2452 spin_unlock_irq(&phba->hbalock);
2453
2454
2455 while (!list_empty(&txq)) {
2456 iocb = list_get_first(&txq, struct lpfc_iocbq, list);
2457 cmd = &iocb->iocb;
2458 list_del_init(&iocb->list);
2459
2460 if (!iocb->iocb_cmpl)
2461 lpfc_sli_release_iocbq(phba, iocb);
2462 else {
2463 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2464 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
2465 (iocb->iocb_cmpl) (phba, iocb, iocb);
2466 }
2467 }
2468
2469
2470 while (!list_empty(&txcmplq)) {
2471 iocb = list_get_first(&txcmplq, struct lpfc_iocbq, list);
2472 cmd = &iocb->iocb;
2473 list_del_init(&iocb->list);
2474
2475 if (!iocb->iocb_cmpl)
2476 lpfc_sli_release_iocbq(phba, iocb);
2477 else {
2478 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2479 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
2480 (iocb->iocb_cmpl) (phba, iocb, iocb);
2481 }
2482 }
2483}
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498int
2499lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
2500{
2501 uint32_t status;
2502 int i = 0;
2503 int retval = 0;
2504
2505
2506 status = readl(phba->HSregaddr);
2507
2508
2509
2510
2511
2512
2513
2514 while (((status & mask) != mask) &&
2515 !(status & HS_FFERM) &&
2516 i++ < 20) {
2517
2518 if (i <= 5)
2519 msleep(10);
2520 else if (i <= 10)
2521 msleep(500);
2522 else
2523 msleep(2500);
2524
2525 if (i == 15) {
2526
2527 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2528 lpfc_sli_brdrestart(phba);
2529 }
2530
2531 status = readl(phba->HSregaddr);
2532 }
2533
2534
2535 if ((status & HS_FFERM) || (i >= 20)) {
2536 phba->link_state = LPFC_HBA_ERROR;
2537 retval = 1;
2538 }
2539
2540 return retval;
2541}
2542
2543#define BARRIER_TEST_PATTERN (0xdeadbeef)
2544
2545
2546
2547
2548
2549
2550
2551
2552void lpfc_reset_barrier(struct lpfc_hba *phba)
2553{
2554 uint32_t __iomem *resp_buf;
2555 uint32_t __iomem *mbox_buf;
2556 volatile uint32_t mbox;
2557 uint32_t hc_copy;
2558 int i;
2559 uint8_t hdrtype;
2560
2561 pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
2562 if (hdrtype != 0x80 ||
2563 (FC_JEDEC_ID(phba->vpd.rev.biuRev) != HELIOS_JEDEC_ID &&
2564 FC_JEDEC_ID(phba->vpd.rev.biuRev) != THOR_JEDEC_ID))
2565 return;
2566
2567
2568
2569
2570
2571 resp_buf = phba->MBslimaddr;
2572
2573
2574 hc_copy = readl(phba->HCregaddr);
2575 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
2576 readl(phba->HCregaddr);
2577 phba->link_flag |= LS_IGNORE_ERATT;
2578
2579 if (readl(phba->HAregaddr) & HA_ERATT) {
2580
2581 writel(HA_ERATT, phba->HAregaddr);
2582 phba->pport->stopped = 1;
2583 }
2584
2585 mbox = 0;
2586 ((MAILBOX_t *)&mbox)->mbxCommand = MBX_KILL_BOARD;
2587 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_CHIP;
2588
2589 writel(BARRIER_TEST_PATTERN, (resp_buf + 1));
2590 mbox_buf = phba->MBslimaddr;
2591 writel(mbox, mbox_buf);
2592
2593 for (i = 0;
2594 readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN) && i < 50; i++)
2595 mdelay(1);
2596
2597 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
2598 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
2599 phba->pport->stopped)
2600 goto restore_hc;
2601 else
2602 goto clear_errat;
2603 }
2604
2605 ((MAILBOX_t *)&mbox)->mbxOwner = OWN_HOST;
2606 for (i = 0; readl(resp_buf) != mbox && i < 500; i++)
2607 mdelay(1);
2608
2609clear_errat:
2610
2611 while (!(readl(phba->HAregaddr) & HA_ERATT) && ++i < 500)
2612 mdelay(1);
2613
2614 if (readl(phba->HAregaddr) & HA_ERATT) {
2615 writel(HA_ERATT, phba->HAregaddr);
2616 phba->pport->stopped = 1;
2617 }
2618
2619restore_hc:
2620 phba->link_flag &= ~LS_IGNORE_ERATT;
2621 writel(hc_copy, phba->HCregaddr);
2622 readl(phba->HCregaddr);
2623}
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636int
2637lpfc_sli_brdkill(struct lpfc_hba *phba)
2638{
2639 struct lpfc_sli *psli;
2640 LPFC_MBOXQ_t *pmb;
2641 uint32_t status;
2642 uint32_t ha_copy;
2643 int retval;
2644 int i = 0;
2645
2646 psli = &phba->sli;
2647
2648
2649 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2650 "0329 Kill HBA Data: x%x x%x\n",
2651 phba->pport->port_state, psli->sli_flag);
2652
2653 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2654 if (!pmb)
2655 return 1;
2656
2657
2658 spin_lock_irq(&phba->hbalock);
2659 status = readl(phba->HCregaddr);
2660 status &= ~HC_ERINT_ENA;
2661 writel(status, phba->HCregaddr);
2662 readl(phba->HCregaddr);
2663 phba->link_flag |= LS_IGNORE_ERATT;
2664 spin_unlock_irq(&phba->hbalock);
2665
2666 lpfc_kill_board(phba, pmb);
2667 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2668 retval = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
2669
2670 if (retval != MBX_SUCCESS) {
2671 if (retval != MBX_BUSY)
2672 mempool_free(pmb, phba->mbox_mem_pool);
2673 spin_lock_irq(&phba->hbalock);
2674 phba->link_flag &= ~LS_IGNORE_ERATT;
2675 spin_unlock_irq(&phba->hbalock);
2676 return 1;
2677 }
2678
2679 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2680
2681 mempool_free(pmb, phba->mbox_mem_pool);
2682
2683
2684
2685
2686
2687
2688 ha_copy = readl(phba->HAregaddr);
2689
2690 while ((i++ < 30) && !(ha_copy & HA_ERATT)) {
2691 mdelay(100);
2692 ha_copy = readl(phba->HAregaddr);
2693 }
2694
2695 del_timer_sync(&psli->mbox_tmo);
2696 if (ha_copy & HA_ERATT) {
2697 writel(HA_ERATT, phba->HAregaddr);
2698 phba->pport->stopped = 1;
2699 }
2700 spin_lock_irq(&phba->hbalock);
2701 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2702 phba->link_flag &= ~LS_IGNORE_ERATT;
2703 spin_unlock_irq(&phba->hbalock);
2704
2705 psli->mbox_active = NULL;
2706 lpfc_hba_down_post(phba);
2707 phba->link_state = LPFC_HBA_ERROR;
2708
2709 return ha_copy & HA_ERATT ? 0 : 1;
2710}
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723int
2724lpfc_sli_brdreset(struct lpfc_hba *phba)
2725{
2726 struct lpfc_sli *psli;
2727 struct lpfc_sli_ring *pring;
2728 uint16_t cfg_value;
2729 int i;
2730
2731 psli = &phba->sli;
2732
2733
2734 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2735 "0325 Reset HBA Data: x%x x%x\n",
2736 phba->pport->port_state, psli->sli_flag);
2737
2738
2739 phba->fc_eventTag = 0;
2740 phba->pport->fc_myDID = 0;
2741 phba->pport->fc_prevDID = 0;
2742
2743
2744 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
2745 pci_write_config_word(phba->pcidev, PCI_COMMAND,
2746 (cfg_value &
2747 ~(PCI_COMMAND_PARITY | PCI_COMMAND_SERR)));
2748
2749 psli->sli_flag &= ~(LPFC_SLI2_ACTIVE | LPFC_PROCESS_LA);
2750
2751 writel(HC_INITFF, phba->HCregaddr);
2752 mdelay(1);
2753 readl(phba->HCregaddr);
2754 writel(0, phba->HCregaddr);
2755 readl(phba->HCregaddr);
2756
2757
2758 pci_write_config_word(phba->pcidev, PCI_COMMAND, cfg_value);
2759
2760
2761 for (i = 0; i < psli->num_rings; i++) {
2762 pring = &psli->ring[i];
2763 pring->flag = 0;
2764 pring->rspidx = 0;
2765 pring->next_cmdidx = 0;
2766 pring->local_getidx = 0;
2767 pring->cmdidx = 0;
2768 pring->missbufcnt = 0;
2769 }
2770
2771 phba->link_state = LPFC_WARM_START;
2772 return 0;
2773}
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788int
2789lpfc_sli_brdrestart(struct lpfc_hba *phba)
2790{
2791 MAILBOX_t *mb;
2792 struct lpfc_sli *psli;
2793 uint16_t skip_post;
2794 volatile uint32_t word0;
2795 void __iomem *to_slim;
2796
2797 spin_lock_irq(&phba->hbalock);
2798
2799 psli = &phba->sli;
2800
2801
2802 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2803 "0337 Restart HBA Data: x%x x%x\n",
2804 phba->pport->port_state, psli->sli_flag);
2805
2806 word0 = 0;
2807 mb = (MAILBOX_t *) &word0;
2808 mb->mbxCommand = MBX_RESTART;
2809 mb->mbxHc = 1;
2810
2811 lpfc_reset_barrier(phba);
2812
2813 to_slim = phba->MBslimaddr;
2814 writel(*(uint32_t *) mb, to_slim);
2815 readl(to_slim);
2816
2817
2818 if (phba->pport->port_state) {
2819 skip_post = 1;
2820 word0 = 1;
2821 } else {
2822 skip_post = 0;
2823 word0 = 0;
2824 }
2825 to_slim = phba->MBslimaddr + sizeof (uint32_t);
2826 writel(*(uint32_t *) mb, to_slim);
2827 readl(to_slim);
2828
2829 lpfc_sli_brdreset(phba);
2830 phba->pport->stopped = 0;
2831 phba->link_state = LPFC_INIT_START;
2832
2833 spin_unlock_irq(&phba->hbalock);
2834
2835 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
2836 psli->stats_start = get_seconds();
2837
2838 if (skip_post)
2839 mdelay(100);
2840 else
2841 mdelay(2000);
2842
2843 lpfc_hba_down_post(phba);
2844
2845 return 0;
2846}
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858static int
2859lpfc_sli_chipset_init(struct lpfc_hba *phba)
2860{
2861 uint32_t status, i = 0;
2862
2863
2864 status = readl(phba->HSregaddr);
2865
2866
2867 i = 0;
2868 while ((status & (HS_FFRDY | HS_MBRDY)) != (HS_FFRDY | HS_MBRDY)) {
2869
2870
2871
2872
2873
2874 if (i++ >= 20) {
2875
2876
2877 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2878 "0436 Adapter failed to init, "
2879 "timeout, status reg x%x, "
2880 "FW Data: A8 x%x AC x%x\n", status,
2881 readl(phba->MBslimaddr + 0xa8),
2882 readl(phba->MBslimaddr + 0xac));
2883 phba->link_state = LPFC_HBA_ERROR;
2884 return -ETIMEDOUT;
2885 }
2886
2887
2888 if (status & HS_FFERM) {
2889
2890
2891
2892 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2893 "0437 Adapter failed to init, "
2894 "chipset, status reg x%x, "
2895 "FW Data: A8 x%x AC x%x\n", status,
2896 readl(phba->MBslimaddr + 0xa8),
2897 readl(phba->MBslimaddr + 0xac));
2898 phba->link_state = LPFC_HBA_ERROR;
2899 return -EIO;
2900 }
2901
2902 if (i <= 5) {
2903 msleep(10);
2904 } else if (i <= 10) {
2905 msleep(500);
2906 } else {
2907 msleep(2500);
2908 }
2909
2910 if (i == 15) {
2911
2912 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
2913 lpfc_sli_brdrestart(phba);
2914 }
2915
2916 status = readl(phba->HSregaddr);
2917 }
2918
2919
2920 if (status & HS_FFERM) {
2921
2922
2923 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2924 "0438 Adapter failed to init, chipset, "
2925 "status reg x%x, "
2926 "FW Data: A8 x%x AC x%x\n", status,
2927 readl(phba->MBslimaddr + 0xa8),
2928 readl(phba->MBslimaddr + 0xac));
2929 phba->link_state = LPFC_HBA_ERROR;
2930 return -EIO;
2931 }
2932
2933
2934 writel(0, phba->HCregaddr);
2935 readl(phba->HCregaddr);
2936
2937
2938 writel(0xffffffff, phba->HAregaddr);
2939 readl(phba->HAregaddr);
2940 return 0;
2941}
2942
2943
2944
2945
2946
2947
2948
2949int
2950lpfc_sli_hbq_count(void)
2951{
2952 return ARRAY_SIZE(lpfc_hbq_defs);
2953}
2954
2955
2956
2957
2958
2959
2960
2961
2962static int
2963lpfc_sli_hbq_entry_count(void)
2964{
2965 int hbq_count = lpfc_sli_hbq_count();
2966 int count = 0;
2967 int i;
2968
2969 for (i = 0; i < hbq_count; ++i)
2970 count += lpfc_hbq_defs[i]->entry_count;
2971 return count;
2972}
2973
2974
2975
2976
2977
2978
2979
2980int
2981lpfc_sli_hbq_size(void)
2982{
2983 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
2984}
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995static int
2996lpfc_sli_hbq_setup(struct lpfc_hba *phba)
2997{
2998 int hbq_count = lpfc_sli_hbq_count();
2999 LPFC_MBOXQ_t *pmb;
3000 MAILBOX_t *pmbox;
3001 uint32_t hbqno;
3002 uint32_t hbq_entry_index;
3003
3004
3005
3006
3007 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3008
3009 if (!pmb)
3010 return -ENOMEM;
3011
3012 pmbox = &pmb->mb;
3013
3014
3015 phba->link_state = LPFC_INIT_MBX_CMDS;
3016 phba->hbq_in_use = 1;
3017
3018 hbq_entry_index = 0;
3019 for (hbqno = 0; hbqno < hbq_count; ++hbqno) {
3020 phba->hbqs[hbqno].next_hbqPutIdx = 0;
3021 phba->hbqs[hbqno].hbqPutIdx = 0;
3022 phba->hbqs[hbqno].local_hbqGetIdx = 0;
3023 phba->hbqs[hbqno].entry_count =
3024 lpfc_hbq_defs[hbqno]->entry_count;
3025 lpfc_config_hbq(phba, hbqno, lpfc_hbq_defs[hbqno],
3026 hbq_entry_index, pmb);
3027 hbq_entry_index += phba->hbqs[hbqno].entry_count;
3028
3029 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
3030
3031
3032
3033 lpfc_printf_log(phba, KERN_ERR,
3034 LOG_SLI | LOG_VPORT,
3035 "1805 Adapter failed to init. "
3036 "Data: x%x x%x x%x\n",
3037 pmbox->mbxCommand,
3038 pmbox->mbxStatus, hbqno);
3039
3040 phba->link_state = LPFC_HBA_ERROR;
3041 mempool_free(pmb, phba->mbox_mem_pool);
3042 return ENXIO;
3043 }
3044 }
3045 phba->hbq_count = hbq_count;
3046
3047 mempool_free(pmb, phba->mbox_mem_pool);
3048
3049
3050 for (hbqno = 0; hbqno < hbq_count; ++hbqno)
3051 lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
3052 return 0;
3053}
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068int
3069lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
3070{
3071 LPFC_MBOXQ_t *pmb;
3072 uint32_t resetcount = 0, rc = 0, done = 0;
3073
3074 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3075 if (!pmb) {
3076 phba->link_state = LPFC_HBA_ERROR;
3077 return -ENOMEM;
3078 }
3079
3080 phba->sli_rev = sli_mode;
3081 while (resetcount < 2 && !done) {
3082 spin_lock_irq(&phba->hbalock);
3083 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
3084 spin_unlock_irq(&phba->hbalock);
3085 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
3086 lpfc_sli_brdrestart(phba);
3087 msleep(2500);
3088 rc = lpfc_sli_chipset_init(phba);
3089 if (rc)
3090 break;
3091
3092 spin_lock_irq(&phba->hbalock);
3093 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3094 spin_unlock_irq(&phba->hbalock);
3095 resetcount++;
3096
3097
3098
3099
3100
3101
3102 rc = lpfc_config_port_prep(phba);
3103 if (rc == -ERESTART) {
3104 phba->link_state = LPFC_LINK_UNKNOWN;
3105 continue;
3106 } else if (rc)
3107 break;
3108 phba->link_state = LPFC_INIT_MBX_CMDS;
3109 lpfc_config_port(phba, pmb);
3110 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
3111 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
3112 LPFC_SLI3_HBQ_ENABLED |
3113 LPFC_SLI3_CRP_ENABLED |
3114 LPFC_SLI3_INB_ENABLED);
3115 if (rc != MBX_SUCCESS) {
3116 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3117 "0442 Adapter failed to init, mbxCmd x%x "
3118 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
3119 pmb->mb.mbxCommand, pmb->mb.mbxStatus, 0);
3120 spin_lock_irq(&phba->hbalock);
3121 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
3122 spin_unlock_irq(&phba->hbalock);
3123 rc = -ENXIO;
3124 } else
3125 done = 1;
3126 }
3127 if (!done) {
3128 rc = -EINVAL;
3129 goto do_prep_failed;
3130 }
3131 if (pmb->mb.un.varCfgPort.sli_mode == 3) {
3132 if (!pmb->mb.un.varCfgPort.cMA) {
3133 rc = -ENXIO;
3134 goto do_prep_failed;
3135 }
3136 if (phba->max_vpi && pmb->mb.un.varCfgPort.gmv) {
3137 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3138 phba->max_vpi = pmb->mb.un.varCfgPort.max_vpi;
3139 } else
3140 phba->max_vpi = 0;
3141 if (pmb->mb.un.varCfgPort.gerbm)
3142 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
3143 if (pmb->mb.un.varCfgPort.gcrp)
3144 phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
3145 if (pmb->mb.un.varCfgPort.ginb) {
3146 phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
3147 phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
3148 phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
3149 phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
3150 phba->inb_last_counter =
3151 phba->mbox->us.s3_inb_pgp.counter;
3152 } else {
3153 phba->port_gp = phba->mbox->us.s3_pgp.port;
3154 phba->inb_ha_copy = NULL;
3155 phba->inb_counter = NULL;
3156 }
3157 } else {
3158 phba->port_gp = phba->mbox->us.s2.port;
3159 phba->inb_ha_copy = NULL;
3160 phba->inb_counter = NULL;
3161 phba->max_vpi = 0;
3162 }
3163do_prep_failed:
3164 mempool_free(pmb, phba->mbox_mem_pool);
3165 return rc;
3166}
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182int
3183lpfc_sli_hba_setup(struct lpfc_hba *phba)
3184{
3185 uint32_t rc;
3186 int mode = 3;
3187
3188 switch (lpfc_sli_mode) {
3189 case 2:
3190 if (phba->cfg_enable_npiv) {
3191 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
3192 "1824 NPIV enabled: Override lpfc_sli_mode "
3193 "parameter (%d) to auto (0).\n",
3194 lpfc_sli_mode);
3195 break;
3196 }
3197 mode = 2;
3198 break;
3199 case 0:
3200 case 3:
3201 break;
3202 default:
3203 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
3204 "1819 Unrecognized lpfc_sli_mode "
3205 "parameter: %d.\n", lpfc_sli_mode);
3206
3207 break;
3208 }
3209
3210 rc = lpfc_sli_config_port(phba, mode);
3211
3212 if (rc && lpfc_sli_mode == 3)
3213 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
3214 "1820 Unable to select SLI-3. "
3215 "Not supported by adapter.\n");
3216 if (rc && mode != 2)
3217 rc = lpfc_sli_config_port(phba, 2);
3218 if (rc)
3219 goto lpfc_sli_hba_setup_error;
3220
3221 if (phba->sli_rev == 3) {
3222 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
3223 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
3224 } else {
3225 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
3226 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
3227 phba->sli3_options = 0;
3228 }
3229
3230 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3231 "0444 Firmware in SLI %x mode. Max_vpi %d\n",
3232 phba->sli_rev, phba->max_vpi);
3233 rc = lpfc_sli_ring_map(phba);
3234
3235 if (rc)
3236 goto lpfc_sli_hba_setup_error;
3237
3238
3239 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
3240 rc = lpfc_sli_hbq_setup(phba);
3241 if (rc)
3242 goto lpfc_sli_hba_setup_error;
3243 }
3244
3245 phba->sli.sli_flag |= LPFC_PROCESS_LA;
3246
3247 rc = lpfc_config_port_post(phba);
3248 if (rc)
3249 goto lpfc_sli_hba_setup_error;
3250
3251 return rc;
3252
3253lpfc_sli_hba_setup_error:
3254 phba->link_state = LPFC_HBA_ERROR;
3255 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
3256 "0445 Firmware initialization failed\n");
3257 return rc;
3258}
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273void
3274lpfc_mbox_timeout(unsigned long ptr)
3275{
3276 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
3277 unsigned long iflag;
3278 uint32_t tmo_posted;
3279
3280 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
3281 tmo_posted = phba->pport->work_port_events & WORKER_MBOX_TMO;
3282 if (!tmo_posted)
3283 phba->pport->work_port_events |= WORKER_MBOX_TMO;
3284 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
3285
3286 if (!tmo_posted)
3287 lpfc_worker_wake_up(phba);
3288 return;
3289}
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300void
3301lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
3302{
3303 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
3304 MAILBOX_t *mb = &pmbox->mb;
3305 struct lpfc_sli *psli = &phba->sli;
3306 struct lpfc_sli_ring *pring;
3307
3308 if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) {
3309 return;
3310 }
3311
3312
3313 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
3314 "0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
3315 mb->mbxCommand,
3316 phba->pport->port_state,
3317 phba->sli.sli_flag,
3318 phba->sli.mbox_active);
3319
3320
3321
3322
3323
3324 spin_lock_irq(&phba->pport->work_port_lock);
3325 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
3326 spin_unlock_irq(&phba->pport->work_port_lock);
3327 spin_lock_irq(&phba->hbalock);
3328 phba->link_state = LPFC_LINK_UNKNOWN;
3329 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
3330 spin_unlock_irq(&phba->hbalock);
3331
3332 pring = &psli->ring[psli->fcp_ring];
3333 lpfc_sli_abort_iocb_ring(phba, pring);
3334
3335 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
3336 "0345 Resetting board due to mailbox timeout\n");
3337
3338
3339
3340
3341
3342 if (!phba->cfg_enable_hba_reset) {
3343 phba->link_state = LPFC_HBA_ERROR;
3344 return;
3345 }
3346 lpfc_offline_prep(phba);
3347 lpfc_offline(phba);
3348 lpfc_sli_brdrestart(phba);
3349 lpfc_online(phba);
3350 lpfc_unblock_mgmt_io(phba);
3351 return;
3352}
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380int
3381lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
3382{
3383 MAILBOX_t *mb;
3384 struct lpfc_sli *psli = &phba->sli;
3385 uint32_t status, evtctr;
3386 uint32_t ha_copy;
3387 int i;
3388 unsigned long timeout;
3389 unsigned long drvr_flag = 0;
3390 uint32_t word0, ldata;
3391 void __iomem *to_slim;
3392 int processing_queue = 0;
3393
3394 spin_lock_irqsave(&phba->hbalock, drvr_flag);
3395 if (!pmbox) {
3396
3397 processing_queue = 1;
3398 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3399 pmbox = lpfc_mbox_get(phba);
3400 if (!pmbox) {
3401 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
3402 return MBX_SUCCESS;
3403 }
3404 }
3405
3406 if (pmbox->mbox_cmpl && pmbox->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
3407 pmbox->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
3408 if(!pmbox->vport) {
3409 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
3410 lpfc_printf_log(phba, KERN_ERR,
3411 LOG_MBOX | LOG_VPORT,
3412 "1806 Mbox x%x failed. No vport\n",
3413 pmbox->mb.mbxCommand);
3414 dump_stack();
3415 goto out_not_finished;
3416 }
3417 }
3418
3419
3420 if (unlikely(pci_channel_offline(phba->pcidev))) {
3421 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
3422 goto out_not_finished;
3423 }
3424
3425 psli = &phba->sli;
3426
3427 mb = &pmbox->mb;
3428 status = MBX_SUCCESS;
3429
3430 if (phba->link_state == LPFC_HBA_ERROR) {
3431 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
3432
3433
3434 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
3435 goto out_not_finished;
3436 }
3437
3438 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
3439 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
3440 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
3441 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
3442 goto out_not_finished;
3443 }
3444
3445 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
3446
3447
3448
3449
3450
3451 if (flag & MBX_POLL) {
3452 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
3453
3454
3455 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
3456 goto out_not_finished;
3457 }
3458
3459 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
3460 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
3461
3462 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
3463 goto out_not_finished;
3464 }
3465
3466
3467
3468
3469 lpfc_mbox_put(phba, pmbox);
3470
3471
3472 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
3473 "(%d):0308 Mbox cmd issue - BUSY Data: "
3474 "x%x x%x x%x x%x\n",
3475 pmbox->vport ? pmbox->vport->vpi : 0xffffff,
3476 mb->mbxCommand, phba->pport->port_state,
3477 psli->sli_flag, flag);
3478
3479 psli->slistat.mbox_busy++;
3480 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
3481
3482 if (pmbox->vport) {
3483 lpfc_debugfs_disc_trc(pmbox->vport,
3484 LPFC_DISC_TRC_MBOX_VPORT,
3485 "MBOX Bsy vport: cmd:x%x mb:x%x x%x",
3486 (uint32_t)mb->mbxCommand,
3487 mb->un.varWords[0], mb->un.varWords[1]);
3488 }
3489 else {
3490 lpfc_debugfs_disc_trc(phba->pport,
3491 LPFC_DISC_TRC_MBOX,
3492 "MBOX Bsy: cmd:x%x mb:x%x x%x",
3493 (uint32_t)mb->mbxCommand,
3494 mb->un.varWords[0], mb->un.varWords[1]);
3495 }
3496
3497 return MBX_BUSY;
3498 }
3499
3500 psli->sli_flag |= LPFC_SLI_MBOX_ACTIVE;
3501
3502
3503 if (flag != MBX_POLL) {
3504 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
3505 (mb->mbxCommand != MBX_KILL_BOARD)) {
3506 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3507 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
3508
3509 LOG_MBOX_CANNOT_ISSUE_DATA(phba, pmbox, psli, flag);
3510 goto out_not_finished;
3511 }
3512
3513 mod_timer(&psli->mbox_tmo, (jiffies +
3514 (HZ * lpfc_mbox_tmo_val(phba, mb->mbxCommand))));
3515 }
3516
3517
3518 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX | LOG_SLI,
3519 "(%d):0309 Mailbox cmd x%x issue Data: x%x x%x "
3520 "x%x\n",
3521 pmbox->vport ? pmbox->vport->vpi : 0,
3522 mb->mbxCommand, phba->pport->port_state,
3523 psli->sli_flag, flag);
3524
3525 if (mb->mbxCommand != MBX_HEARTBEAT) {
3526 if (pmbox->vport) {
3527 lpfc_debugfs_disc_trc(pmbox->vport,
3528 LPFC_DISC_TRC_MBOX_VPORT,
3529 "MBOX Send vport: cmd:x%x mb:x%x x%x",
3530 (uint32_t)mb->mbxCommand,
3531 mb->un.varWords[0], mb->un.varWords[1]);
3532 }
3533 else {
3534 lpfc_debugfs_disc_trc(phba->pport,
3535 LPFC_DISC_TRC_MBOX,
3536 "MBOX Send: cmd:x%x mb:x%x x%x",
3537 (uint32_t)mb->mbxCommand,
3538 mb->un.varWords[0], mb->un.varWords[1]);
3539 }
3540 }
3541
3542 psli->slistat.mbox_cmd++;
3543 evtctr = psli->slistat.mbox_event;
3544
3545
3546 mb->mbxOwner = OWN_CHIP;
3547
3548 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
3549
3550 lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
3551 } else {
3552 if (mb->mbxCommand == MBX_CONFIG_PORT) {
3553
3554 lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
3555 }
3556
3557
3558
3559 to_slim = phba->MBslimaddr + sizeof (uint32_t);
3560 lpfc_memcpy_to_slim(to_slim, &mb->un.varWords[0],
3561 MAILBOX_CMD_SIZE - sizeof (uint32_t));
3562
3563
3564 ldata = *((uint32_t *)mb);
3565 to_slim = phba->MBslimaddr;
3566 writel(ldata, to_slim);
3567 readl(to_slim);
3568
3569 if (mb->mbxCommand == MBX_CONFIG_PORT) {
3570
3571 psli->sli_flag |= LPFC_SLI2_ACTIVE;
3572 }
3573 }
3574
3575 wmb();
3576
3577 switch (flag) {
3578 case MBX_NOWAIT:
3579
3580 psli->mbox_active = pmbox;
3581
3582 writel(CA_MBATT, phba->CAregaddr);
3583 readl(phba->CAregaddr);
3584
3585 break;
3586
3587 case MBX_POLL:
3588
3589 psli->mbox_active = NULL;
3590
3591 writel(CA_MBATT, phba->CAregaddr);
3592 readl(phba->CAregaddr);
3593
3594 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
3595
3596 word0 = *((uint32_t *)phba->mbox);
3597 word0 = le32_to_cpu(word0);
3598 } else {
3599
3600 word0 = readl(phba->MBslimaddr);
3601 }
3602
3603
3604 ha_copy = readl(phba->HAregaddr);
3605 timeout = msecs_to_jiffies(lpfc_mbox_tmo_val(phba,
3606 mb->mbxCommand) *
3607 1000) + jiffies;
3608 i = 0;
3609
3610 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
3611 (!(ha_copy & HA_MBATT) &&
3612 (phba->link_state > LPFC_WARM_START))) {
3613 if (time_after(jiffies, timeout)) {
3614 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3615 spin_unlock_irqrestore(&phba->hbalock,
3616 drvr_flag);
3617 goto out_not_finished;
3618 }
3619
3620
3621
3622 if (((word0 & OWN_CHIP) != OWN_CHIP)
3623 && (evtctr != psli->slistat.mbox_event))
3624 break;
3625
3626 if (i++ > 10) {
3627 spin_unlock_irqrestore(&phba->hbalock,
3628 drvr_flag);
3629 msleep(1);
3630 spin_lock_irqsave(&phba->hbalock, drvr_flag);
3631 }
3632
3633 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
3634
3635 word0 = *((uint32_t *)phba->mbox);
3636 word0 = le32_to_cpu(word0);
3637 if (mb->mbxCommand == MBX_CONFIG_PORT) {
3638 MAILBOX_t *slimmb;
3639 uint32_t slimword0;
3640
3641 slimword0 = readl(phba->MBslimaddr);
3642 slimmb = (MAILBOX_t *) & slimword0;
3643 if (((slimword0 & OWN_CHIP) != OWN_CHIP)
3644 && slimmb->mbxStatus) {
3645 psli->sli_flag &=
3646 ~LPFC_SLI2_ACTIVE;
3647 word0 = slimword0;
3648 }
3649 }
3650 } else {
3651
3652 word0 = readl(phba->MBslimaddr);
3653 }
3654
3655 ha_copy = readl(phba->HAregaddr);
3656 }
3657
3658 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
3659
3660 lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
3661 } else {
3662
3663 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
3664 MAILBOX_CMD_SIZE);
3665 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
3666 pmbox->context2) {
3667 lpfc_memcpy_from_slim((void *)pmbox->context2,
3668 phba->MBslimaddr + DMP_RSP_OFFSET,
3669 mb->un.varDmp.word_cnt);
3670 }
3671 }
3672
3673 writel(HA_MBATT, phba->HAregaddr);
3674 readl(phba->HAregaddr);
3675
3676 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
3677 status = mb->mbxStatus;
3678 }
3679
3680 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
3681 return status;
3682
3683out_not_finished:
3684 if (processing_queue) {
3685 pmbox->mb.mbxStatus = MBX_NOT_FINISHED;
3686 lpfc_mbox_cmpl_put(phba, pmbox);
3687 }
3688 return MBX_NOT_FINISHED;
3689}
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701static void
3702__lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3703 struct lpfc_iocbq *piocb)
3704{
3705
3706 list_add_tail(&piocb->list, &pring->txq);
3707 pring->txq_cnt++;
3708}
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727static struct lpfc_iocbq *
3728lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3729 struct lpfc_iocbq **piocb)
3730{
3731 struct lpfc_iocbq * nextiocb;
3732
3733 nextiocb = lpfc_sli_ringtx_get(phba, pring);
3734 if (!nextiocb) {
3735 nextiocb = *piocb;
3736 *piocb = NULL;
3737 }
3738
3739 return nextiocb;
3740}
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766static int
3767__lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3768 struct lpfc_iocbq *piocb, uint32_t flag)
3769{
3770 struct lpfc_iocbq *nextiocb;
3771 IOCB_t *iocb;
3772
3773 if (piocb->iocb_cmpl && (!piocb->vport) &&
3774 (piocb->iocb.ulpCommand != CMD_ABORT_XRI_CN) &&
3775 (piocb->iocb.ulpCommand != CMD_CLOSE_XRI_CN)) {
3776 lpfc_printf_log(phba, KERN_ERR,
3777 LOG_SLI | LOG_VPORT,
3778 "1807 IOCB x%x failed. No vport\n",
3779 piocb->iocb.ulpCommand);
3780 dump_stack();
3781 return IOCB_ERROR;
3782 }
3783
3784
3785
3786 if (unlikely(pci_channel_offline(phba->pcidev)))
3787 return IOCB_ERROR;
3788
3789
3790
3791
3792 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
3793 return IOCB_ERROR;
3794
3795
3796
3797
3798
3799 if (unlikely(pring->flag & LPFC_STOP_IOCB_EVENT))
3800 goto iocb_busy;
3801
3802 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
3803
3804
3805
3806
3807 switch (piocb->iocb.ulpCommand) {
3808 case CMD_GEN_REQUEST64_CR:
3809 case CMD_GEN_REQUEST64_CX:
3810 if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
3811 (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
3812 FC_FCP_CMND) ||
3813 (piocb->iocb.un.genreq64.w5.hcsw.Type !=
3814 MENLO_TRANSPORT_TYPE))
3815
3816 goto iocb_busy;
3817 break;
3818 case CMD_QUE_RING_BUF_CN:
3819 case CMD_QUE_RING_BUF64_CN:
3820
3821
3822
3823
3824 if (piocb->iocb_cmpl)
3825 piocb->iocb_cmpl = NULL;
3826
3827 case CMD_CREATE_XRI_CR:
3828 case CMD_CLOSE_XRI_CN:
3829 case CMD_CLOSE_XRI_CX:
3830 break;
3831 default:
3832 goto iocb_busy;
3833 }
3834
3835
3836
3837
3838
3839 } else if (unlikely(pring->ringno == phba->sli.fcp_ring &&
3840 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) {
3841 goto iocb_busy;
3842 }
3843
3844 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
3845 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
3846 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
3847
3848 if (iocb)
3849 lpfc_sli_update_ring(phba, pring);
3850 else
3851 lpfc_sli_update_full_ring(phba, pring);
3852
3853 if (!piocb)
3854 return IOCB_SUCCESS;
3855
3856 goto out_busy;
3857
3858 iocb_busy:
3859 pring->stats.iocb_cmd_delay++;
3860
3861 out_busy:
3862
3863 if (!(flag & SLI_IOCB_RET_IOCB)) {
3864 __lpfc_sli_ringtx_put(phba, pring, piocb);
3865 return IOCB_SUCCESS;
3866 }
3867
3868 return IOCB_BUSY;
3869}
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885int
3886lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3887 struct lpfc_iocbq *piocb, uint32_t flag)
3888{
3889 unsigned long iflags;
3890 int rc;
3891
3892 spin_lock_irqsave(&phba->hbalock, iflags);
3893 rc = __lpfc_sli_issue_iocb(phba, pring, piocb, flag);
3894 spin_unlock_irqrestore(&phba->hbalock, iflags);
3895
3896 return rc;
3897}
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910static int
3911lpfc_extra_ring_setup( struct lpfc_hba *phba)
3912{
3913 struct lpfc_sli *psli;
3914 struct lpfc_sli_ring *pring;
3915
3916 psli = &phba->sli;
3917
3918
3919
3920
3921 pring = &psli->ring[psli->fcp_ring];
3922 pring->numCiocb -= SLI2_IOCB_CMD_R1XTRA_ENTRIES;
3923 pring->numRiocb -= SLI2_IOCB_RSP_R1XTRA_ENTRIES;
3924 pring->numCiocb -= SLI2_IOCB_CMD_R3XTRA_ENTRIES;
3925 pring->numRiocb -= SLI2_IOCB_RSP_R3XTRA_ENTRIES;
3926
3927
3928 pring = &psli->ring[psli->extra_ring];
3929
3930 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
3931 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
3932 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
3933 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
3934
3935
3936 pring->iotag_max = 4096;
3937 pring->num_mask = 1;
3938 pring->prt[0].profile = 0;
3939 pring->prt[0].rctl = phba->cfg_multi_ring_rctl;
3940 pring->prt[0].type = phba->cfg_multi_ring_type;
3941 pring->prt[0].lpfc_sli_rcv_unsol_event = NULL;
3942 return 0;
3943}
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958static void
3959lpfc_sli_async_event_handler(struct lpfc_hba * phba,
3960 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
3961{
3962 IOCB_t *icmd;
3963 uint16_t evt_code;
3964 uint16_t temp;
3965 struct temp_event temp_event_data;
3966 struct Scsi_Host *shost;
3967
3968 icmd = &iocbq->iocb;
3969 evt_code = icmd->un.asyncstat.evt_code;
3970 temp = icmd->ulpContext;
3971
3972 if ((evt_code != ASYNC_TEMP_WARN) &&
3973 (evt_code != ASYNC_TEMP_SAFE)) {
3974 lpfc_printf_log(phba,
3975 KERN_ERR,
3976 LOG_SLI,
3977 "0346 Ring %d handler: unexpected ASYNC_STATUS"
3978 " evt_code 0x%x\n",
3979 pring->ringno,
3980 icmd->un.asyncstat.evt_code);
3981 return;
3982 }
3983 temp_event_data.data = (uint32_t)temp;
3984 temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
3985 if (evt_code == ASYNC_TEMP_WARN) {
3986 temp_event_data.event_code = LPFC_THRESHOLD_TEMP;
3987 lpfc_printf_log(phba,
3988 KERN_ERR,
3989 LOG_TEMP,
3990 "0347 Adapter is very hot, please take "
3991 "corrective action. temperature : %d Celsius\n",
3992 temp);
3993 }
3994 if (evt_code == ASYNC_TEMP_SAFE) {
3995 temp_event_data.event_code = LPFC_NORMAL_TEMP;
3996 lpfc_printf_log(phba,
3997 KERN_ERR,
3998 LOG_TEMP,
3999 "0340 Adapter temperature is OK now. "
4000 "temperature : %d Celsius\n",
4001 temp);
4002 }
4003
4004
4005 shost = lpfc_shost_from_vport(phba->pport);
4006 fc_host_post_vendor_event(shost, fc_get_event_number(),
4007 sizeof(temp_event_data), (char *) &temp_event_data,
4008 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
4009
4010}
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024int
4025lpfc_sli_setup(struct lpfc_hba *phba)
4026{
4027 int i, totiocbsize = 0;
4028 struct lpfc_sli *psli = &phba->sli;
4029 struct lpfc_sli_ring *pring;
4030
4031 psli->num_rings = MAX_CONFIGURED_RINGS;
4032 psli->sli_flag = 0;
4033 psli->fcp_ring = LPFC_FCP_RING;
4034 psli->next_ring = LPFC_FCP_NEXT_RING;
4035 psli->extra_ring = LPFC_EXTRA_RING;
4036
4037 psli->iocbq_lookup = NULL;
4038 psli->iocbq_lookup_len = 0;
4039 psli->last_iotag = 0;
4040
4041 for (i = 0; i < psli->num_rings; i++) {
4042 pring = &psli->ring[i];
4043 switch (i) {
4044 case LPFC_FCP_RING:
4045
4046 pring->numCiocb = SLI2_IOCB_CMD_R0_ENTRIES;
4047 pring->numRiocb = SLI2_IOCB_RSP_R0_ENTRIES;
4048 pring->numCiocb += SLI2_IOCB_CMD_R1XTRA_ENTRIES;
4049 pring->numRiocb += SLI2_IOCB_RSP_R1XTRA_ENTRIES;
4050 pring->numCiocb += SLI2_IOCB_CMD_R3XTRA_ENTRIES;
4051 pring->numRiocb += SLI2_IOCB_RSP_R3XTRA_ENTRIES;
4052 pring->sizeCiocb = (phba->sli_rev == 3) ?
4053 SLI3_IOCB_CMD_SIZE :
4054 SLI2_IOCB_CMD_SIZE;
4055 pring->sizeRiocb = (phba->sli_rev == 3) ?
4056 SLI3_IOCB_RSP_SIZE :
4057 SLI2_IOCB_RSP_SIZE;
4058 pring->iotag_ctr = 0;
4059 pring->iotag_max =
4060 (phba->cfg_hba_queue_depth * 2);
4061 pring->fast_iotag = pring->iotag_max;
4062 pring->num_mask = 0;
4063 break;
4064 case LPFC_EXTRA_RING:
4065
4066 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
4067 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
4068 pring->sizeCiocb = (phba->sli_rev == 3) ?
4069 SLI3_IOCB_CMD_SIZE :
4070 SLI2_IOCB_CMD_SIZE;
4071 pring->sizeRiocb = (phba->sli_rev == 3) ?
4072 SLI3_IOCB_RSP_SIZE :
4073 SLI2_IOCB_RSP_SIZE;
4074 pring->iotag_max = phba->cfg_hba_queue_depth;
4075 pring->num_mask = 0;
4076 break;
4077 case LPFC_ELS_RING:
4078
4079 pring->numCiocb = SLI2_IOCB_CMD_R2_ENTRIES;
4080 pring->numRiocb = SLI2_IOCB_RSP_R2_ENTRIES;
4081 pring->sizeCiocb = (phba->sli_rev == 3) ?
4082 SLI3_IOCB_CMD_SIZE :
4083 SLI2_IOCB_CMD_SIZE;
4084 pring->sizeRiocb = (phba->sli_rev == 3) ?
4085 SLI3_IOCB_RSP_SIZE :
4086 SLI2_IOCB_RSP_SIZE;
4087 pring->fast_iotag = 0;
4088 pring->iotag_ctr = 0;
4089 pring->iotag_max = 4096;
4090 pring->lpfc_sli_rcv_async_status =
4091 lpfc_sli_async_event_handler;
4092 pring->num_mask = 4;
4093 pring->prt[0].profile = 0;
4094 pring->prt[0].rctl = FC_ELS_REQ;
4095 pring->prt[0].type = FC_ELS_DATA;
4096 pring->prt[0].lpfc_sli_rcv_unsol_event =
4097 lpfc_els_unsol_event;
4098 pring->prt[1].profile = 0;
4099 pring->prt[1].rctl = FC_ELS_RSP;
4100 pring->prt[1].type = FC_ELS_DATA;
4101 pring->prt[1].lpfc_sli_rcv_unsol_event =
4102 lpfc_els_unsol_event;
4103 pring->prt[2].profile = 0;
4104
4105 pring->prt[2].rctl = FC_UNSOL_CTL;
4106
4107 pring->prt[2].type = FC_COMMON_TRANSPORT_ULP;
4108 pring->prt[2].lpfc_sli_rcv_unsol_event =
4109 lpfc_ct_unsol_event;
4110 pring->prt[3].profile = 0;
4111
4112 pring->prt[3].rctl = FC_SOL_CTL;
4113
4114 pring->prt[3].type = FC_COMMON_TRANSPORT_ULP;
4115 pring->prt[3].lpfc_sli_rcv_unsol_event =
4116 lpfc_ct_unsol_event;
4117 break;
4118 }
4119 totiocbsize += (pring->numCiocb * pring->sizeCiocb) +
4120 (pring->numRiocb * pring->sizeRiocb);
4121 }
4122 if (totiocbsize > MAX_SLIM_IOCB_SIZE) {
4123
4124 printk(KERN_ERR "%d:0462 Too many cmd / rsp ring entries in "
4125 "SLI2 SLIM Data: x%x x%lx\n",
4126 phba->brd_no, totiocbsize,
4127 (unsigned long) MAX_SLIM_IOCB_SIZE);
4128 }
4129 if (phba->cfg_multi_ring_support == 2)
4130 lpfc_extra_ring_setup(phba);
4131
4132 return 0;
4133}
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146int
4147lpfc_sli_queue_setup(struct lpfc_hba *phba)
4148{
4149 struct lpfc_sli *psli;
4150 struct lpfc_sli_ring *pring;
4151 int i;
4152
4153 psli = &phba->sli;
4154 spin_lock_irq(&phba->hbalock);
4155 INIT_LIST_HEAD(&psli->mboxq);
4156 INIT_LIST_HEAD(&psli->mboxq_cmpl);
4157
4158 for (i = 0; i < psli->num_rings; i++) {
4159 pring = &psli->ring[i];
4160 pring->ringno = i;
4161 pring->next_cmdidx = 0;
4162 pring->local_getidx = 0;
4163 pring->cmdidx = 0;
4164 INIT_LIST_HEAD(&pring->txq);
4165 INIT_LIST_HEAD(&pring->txcmplq);
4166 INIT_LIST_HEAD(&pring->iocb_continueq);
4167 INIT_LIST_HEAD(&pring->iocb_continue_saveq);
4168 INIT_LIST_HEAD(&pring->postbufq);
4169 }
4170 spin_unlock_irq(&phba->hbalock);
4171 return 1;
4172}
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191int
4192lpfc_sli_host_down(struct lpfc_vport *vport)
4193{
4194 LIST_HEAD(completions);
4195 struct lpfc_hba *phba = vport->phba;
4196 struct lpfc_sli *psli = &phba->sli;
4197 struct lpfc_sli_ring *pring;
4198 struct lpfc_iocbq *iocb, *next_iocb;
4199 int i;
4200 unsigned long flags = 0;
4201 uint16_t prev_pring_flag;
4202
4203 lpfc_cleanup_discovery_resources(vport);
4204
4205 spin_lock_irqsave(&phba->hbalock, flags);
4206 for (i = 0; i < psli->num_rings; i++) {
4207 pring = &psli->ring[i];
4208 prev_pring_flag = pring->flag;
4209
4210 if (pring->ringno == LPFC_ELS_RING) {
4211 pring->flag |= LPFC_DEFERRED_RING_EVENT;
4212
4213 set_bit(LPFC_DATA_READY, &phba->data_flags);
4214 }
4215
4216
4217
4218
4219 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
4220 if (iocb->vport != vport)
4221 continue;
4222 list_move_tail(&iocb->list, &completions);
4223 pring->txq_cnt--;
4224 }
4225
4226
4227 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq,
4228 list) {
4229 if (iocb->vport != vport)
4230 continue;
4231 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
4232 }
4233
4234 pring->flag = prev_pring_flag;
4235 }
4236
4237 spin_unlock_irqrestore(&phba->hbalock, flags);
4238
4239 while (!list_empty(&completions)) {
4240 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
4241
4242 if (!iocb->iocb_cmpl)
4243 lpfc_sli_release_iocbq(phba, iocb);
4244 else {
4245 iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
4246 iocb->iocb.un.ulpWord[4] = IOERR_SLI_DOWN;
4247 (iocb->iocb_cmpl) (phba, iocb, iocb);
4248 }
4249 }
4250 return 1;
4251}
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268int
4269lpfc_sli_hba_down(struct lpfc_hba *phba)
4270{
4271 LIST_HEAD(completions);
4272 struct lpfc_sli *psli = &phba->sli;
4273 struct lpfc_sli_ring *pring;
4274 struct lpfc_dmabuf *buf_ptr;
4275 LPFC_MBOXQ_t *pmb;
4276 struct lpfc_iocbq *iocb;
4277 IOCB_t *cmd = NULL;
4278 int i;
4279 unsigned long flags = 0;
4280
4281 lpfc_hba_down_prep(phba);
4282
4283 lpfc_fabric_abort_hba(phba);
4284
4285 spin_lock_irqsave(&phba->hbalock, flags);
4286 for (i = 0; i < psli->num_rings; i++) {
4287 pring = &psli->ring[i];
4288
4289 if (pring->ringno == LPFC_ELS_RING) {
4290 pring->flag |= LPFC_DEFERRED_RING_EVENT;
4291
4292 set_bit(LPFC_DATA_READY, &phba->data_flags);
4293 }
4294
4295
4296
4297
4298
4299 list_splice_init(&pring->txq, &completions);
4300 pring->txq_cnt = 0;
4301
4302 }
4303 spin_unlock_irqrestore(&phba->hbalock, flags);
4304
4305 while (!list_empty(&completions)) {
4306 list_remove_head(&completions, iocb, struct lpfc_iocbq, list);
4307 cmd = &iocb->iocb;
4308
4309 if (!iocb->iocb_cmpl)
4310 lpfc_sli_release_iocbq(phba, iocb);
4311 else {
4312 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4313 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
4314 (iocb->iocb_cmpl) (phba, iocb, iocb);
4315 }
4316 }
4317
4318 spin_lock_irqsave(&phba->hbalock, flags);
4319 list_splice_init(&phba->elsbuf, &completions);
4320 phba->elsbuf_cnt = 0;
4321 phba->elsbuf_prev_cnt = 0;
4322 spin_unlock_irqrestore(&phba->hbalock, flags);
4323
4324 while (!list_empty(&completions)) {
4325 list_remove_head(&completions, buf_ptr,
4326 struct lpfc_dmabuf, list);
4327 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4328 kfree(buf_ptr);
4329 }
4330
4331
4332 del_timer_sync(&psli->mbox_tmo);
4333 spin_lock_irqsave(&phba->hbalock, flags);
4334
4335 spin_lock(&phba->pport->work_port_lock);
4336 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
4337 spin_unlock(&phba->pport->work_port_lock);
4338
4339
4340 list_splice_init(&phba->sli.mboxq, &completions);
4341 if (psli->mbox_active) {
4342 list_add_tail(&psli->mbox_active->list, &completions);
4343 psli->mbox_active = NULL;
4344 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
4345 }
4346 list_splice_init(&phba->sli.mboxq_cmpl, &completions);
4347 spin_unlock_irqrestore(&phba->hbalock, flags);
4348
4349 while (!list_empty(&completions)) {
4350 list_remove_head(&completions, pmb, LPFC_MBOXQ_t, list);
4351 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
4352 if (pmb->mbox_cmpl)
4353 pmb->mbox_cmpl(phba,pmb);
4354 }
4355 return 1;
4356}
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370void
4371lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
4372{
4373 uint32_t *src = srcp;
4374 uint32_t *dest = destp;
4375 uint32_t ldata;
4376 int i;
4377
4378 for (i = 0; i < (int)cnt; i += sizeof (uint32_t)) {
4379 ldata = *src;
4380 ldata = le32_to_cpu(ldata);
4381 *dest = ldata;
4382 src++;
4383 dest++;
4384 }
4385}
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398int
4399lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4400 struct lpfc_dmabuf *mp)
4401{
4402
4403
4404 spin_lock_irq(&phba->hbalock);
4405 list_add_tail(&mp->list, &pring->postbufq);
4406 pring->postbufq_cnt++;
4407 spin_unlock_irq(&phba->hbalock);
4408 return 0;
4409}
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423uint32_t
4424lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
4425{
4426 spin_lock_irq(&phba->hbalock);
4427 phba->buffer_tag_count++;
4428
4429
4430
4431
4432 phba->buffer_tag_count |= QUE_BUFTAG_BIT;
4433 spin_unlock_irq(&phba->hbalock);
4434 return phba->buffer_tag_count;
4435}
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453struct lpfc_dmabuf *
4454lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4455 uint32_t tag)
4456{
4457 struct lpfc_dmabuf *mp, *next_mp;
4458 struct list_head *slp = &pring->postbufq;
4459
4460
4461 spin_lock_irq(&phba->hbalock);
4462 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
4463 if (mp->buffer_tag == tag) {
4464 list_del_init(&mp->list);
4465 pring->postbufq_cnt--;
4466 spin_unlock_irq(&phba->hbalock);
4467 return mp;
4468 }
4469 }
4470
4471 spin_unlock_irq(&phba->hbalock);
4472 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4473 "0402 Cannot find virtual addr for buffer tag on "
4474 "ring %d Data x%lx x%p x%p x%x\n",
4475 pring->ringno, (unsigned long) tag,
4476 slp->next, slp->prev, pring->postbufq_cnt);
4477
4478 return NULL;
4479}
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498struct lpfc_dmabuf *
4499lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4500 dma_addr_t phys)
4501{
4502 struct lpfc_dmabuf *mp, *next_mp;
4503 struct list_head *slp = &pring->postbufq;
4504
4505
4506 spin_lock_irq(&phba->hbalock);
4507 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
4508 if (mp->phys == phys) {
4509 list_del_init(&mp->list);
4510 pring->postbufq_cnt--;
4511 spin_unlock_irq(&phba->hbalock);
4512 return mp;
4513 }
4514 }
4515
4516 spin_unlock_irq(&phba->hbalock);
4517 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4518 "0410 Cannot find virtual addr for mapped buf on "
4519 "ring %d Data x%llx x%p x%p x%x\n",
4520 pring->ringno, (unsigned long long)phys,
4521 slp->next, slp->prev, pring->postbufq_cnt);
4522 return NULL;
4523}
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536static void
4537lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4538 struct lpfc_iocbq *rspiocb)
4539{
4540 IOCB_t *irsp = &rspiocb->iocb;
4541 uint16_t abort_iotag, abort_context;
4542 struct lpfc_iocbq *abort_iocb;
4543 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4544
4545 abort_iocb = NULL;
4546
4547 if (irsp->ulpStatus) {
4548 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
4549 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
4550
4551 spin_lock_irq(&phba->hbalock);
4552 if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
4553 abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
4554
4555 lpfc_printf_log(phba, KERN_INFO, LOG_ELS | LOG_SLI,
4556 "0327 Cannot abort els iocb %p "
4557 "with tag %x context %x, abort status %x, "
4558 "abort code %x\n",
4559 abort_iocb, abort_iotag, abort_context,
4560 irsp->ulpStatus, irsp->un.ulpWord[4]);
4561
4562
4563
4564
4565
4566 if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
4567 spin_unlock_irq(&phba->hbalock);
4568 lpfc_sli_release_iocbq(phba, cmdiocb);
4569 return;
4570 }
4571
4572
4573
4574
4575 if (!abort_iocb ||
4576 abort_iocb->iocb.ulpContext != abort_context ||
4577 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
4578 spin_unlock_irq(&phba->hbalock);
4579 else {
4580 list_del_init(&abort_iocb->list);
4581 pring->txcmplq_cnt--;
4582 spin_unlock_irq(&phba->hbalock);
4583
4584
4585
4586
4587
4588 abort_iocb->iocb_flag |= LPFC_DELAY_MEM_FREE;
4589
4590 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
4591 abort_iocb->iocb.ulpStatus = IOSTAT_LOCAL_REJECT;
4592 abort_iocb->iocb.un.ulpWord[4] = IOERR_SLI_ABORTED;
4593 (abort_iocb->iocb_cmpl)(phba, abort_iocb, abort_iocb);
4594 }
4595 }
4596
4597 lpfc_sli_release_iocbq(phba, cmdiocb);
4598 return;
4599}
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612static void
4613lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4614 struct lpfc_iocbq *rspiocb)
4615{
4616 IOCB_t *irsp = &rspiocb->iocb;
4617
4618
4619 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
4620 "0139 Ignoring ELS cmd tag x%x completion Data: "
4621 "x%x x%x x%x\n",
4622 irsp->ulpIoTag, irsp->ulpStatus,
4623 irsp->un.ulpWord[4], irsp->ulpTimeout);
4624 if (cmdiocb->iocb.ulpCommand == CMD_GEN_REQUEST64_CR)
4625 lpfc_ct_free_iocb(phba, cmdiocb);
4626 else
4627 lpfc_els_free_iocb(phba, cmdiocb);
4628 return;
4629}
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642int
4643lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4644 struct lpfc_iocbq *cmdiocb)
4645{
4646 struct lpfc_vport *vport = cmdiocb->vport;
4647 struct lpfc_iocbq *abtsiocbp;
4648 IOCB_t *icmd = NULL;
4649 IOCB_t *iabt = NULL;
4650 int retval = IOCB_ERROR;
4651
4652
4653
4654
4655
4656
4657 icmd = &cmdiocb->iocb;
4658 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
4659 icmd->ulpCommand == CMD_CLOSE_XRI_CN ||
4660 (cmdiocb->iocb_flag & LPFC_DRIVER_ABORTED) != 0)
4661 return 0;
4662
4663
4664
4665
4666 if ((vport->load_flag & FC_UNLOADING) &&
4667 (pring->ringno == LPFC_ELS_RING)) {
4668 if (cmdiocb->iocb_flag & LPFC_IO_FABRIC)
4669 cmdiocb->fabric_iocb_cmpl = lpfc_ignore_els_cmpl;
4670 else
4671 cmdiocb->iocb_cmpl = lpfc_ignore_els_cmpl;
4672 goto abort_iotag_exit;
4673 }
4674
4675
4676 abtsiocbp = __lpfc_sli_get_iocbq(phba);
4677 if (abtsiocbp == NULL)
4678 return 0;
4679
4680
4681
4682
4683 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
4684
4685 iabt = &abtsiocbp->iocb;
4686 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
4687 iabt->un.acxri.abortContextTag = icmd->ulpContext;
4688 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
4689 iabt->ulpLe = 1;
4690 iabt->ulpClass = icmd->ulpClass;
4691
4692 if (phba->link_state >= LPFC_LINK_UP)
4693 iabt->ulpCommand = CMD_ABORT_XRI_CN;
4694 else
4695 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
4696
4697 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
4698
4699 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI,
4700 "0339 Abort xri x%x, original iotag x%x, "
4701 "abort cmd iotag x%x\n",
4702 iabt->un.acxri.abortContextTag,
4703 iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
4704 retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
4705
4706 if (retval)
4707 __lpfc_sli_release_iocbq(phba, abtsiocbp);
4708abort_iotag_exit:
4709
4710
4711
4712
4713
4714 return retval;
4715}
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740static int
4741lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
4742 uint16_t tgt_id, uint64_t lun_id,
4743 lpfc_ctx_cmd ctx_cmd)
4744{
4745 struct lpfc_scsi_buf *lpfc_cmd;
4746 int rc = 1;
4747
4748 if (!(iocbq->iocb_flag & LPFC_IO_FCP))
4749 return rc;
4750
4751 if (iocbq->vport != vport)
4752 return rc;
4753
4754 lpfc_cmd = container_of(iocbq, struct lpfc_scsi_buf, cur_iocbq);
4755
4756 if (lpfc_cmd->pCmd == NULL)
4757 return rc;
4758
4759 switch (ctx_cmd) {
4760 case LPFC_CTX_LUN:
4761 if ((lpfc_cmd->rdata->pnode) &&
4762 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id) &&
4763 (scsilun_to_int(&lpfc_cmd->fcp_cmnd->fcp_lun) == lun_id))
4764 rc = 0;
4765 break;
4766 case LPFC_CTX_TGT:
4767 if ((lpfc_cmd->rdata->pnode) &&
4768 (lpfc_cmd->rdata->pnode->nlp_sid == tgt_id))
4769 rc = 0;
4770 break;
4771 case LPFC_CTX_HOST:
4772 rc = 0;
4773 break;
4774 default:
4775 printk(KERN_ERR "%s: Unknown context cmd type, value %d\n",
4776 __func__, ctx_cmd);
4777 break;
4778 }
4779
4780 return rc;
4781}
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802int
4803lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
4804 lpfc_ctx_cmd ctx_cmd)
4805{
4806 struct lpfc_hba *phba = vport->phba;
4807 struct lpfc_iocbq *iocbq;
4808 int sum, i;
4809
4810 for (i = 1, sum = 0; i <= phba->sli.last_iotag; i++) {
4811 iocbq = phba->sli.iocbq_lookup[i];
4812
4813 if (lpfc_sli_validate_fcp_iocb (iocbq, vport, tgt_id, lun_id,
4814 ctx_cmd) == 0)
4815 sum++;
4816 }
4817
4818 return sum;
4819}
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832void
4833lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4834 struct lpfc_iocbq *rspiocb)
4835{
4836 lpfc_sli_release_iocbq(phba, cmdiocb);
4837 return;
4838}
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862int
4863lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
4864 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
4865{
4866 struct lpfc_hba *phba = vport->phba;
4867 struct lpfc_iocbq *iocbq;
4868 struct lpfc_iocbq *abtsiocb;
4869 IOCB_t *cmd = NULL;
4870 int errcnt = 0, ret_val = 0;
4871 int i;
4872
4873 for (i = 1; i <= phba->sli.last_iotag; i++) {
4874 iocbq = phba->sli.iocbq_lookup[i];
4875
4876 if (lpfc_sli_validate_fcp_iocb(iocbq, vport, tgt_id, lun_id,
4877 abort_cmd) != 0)
4878 continue;
4879
4880
4881 abtsiocb = lpfc_sli_get_iocbq(phba);
4882 if (abtsiocb == NULL) {
4883 errcnt++;
4884 continue;
4885 }
4886
4887 cmd = &iocbq->iocb;
4888 abtsiocb->iocb.un.acxri.abortType = ABORT_TYPE_ABTS;
4889 abtsiocb->iocb.un.acxri.abortContextTag = cmd->ulpContext;
4890 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
4891 abtsiocb->iocb.ulpLe = 1;
4892 abtsiocb->iocb.ulpClass = cmd->ulpClass;
4893 abtsiocb->vport = phba->pport;
4894
4895 if (lpfc_is_link_up(phba))
4896 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
4897 else
4898 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
4899
4900
4901 abtsiocb->iocb_cmpl = lpfc_sli_abort_fcp_cmpl;
4902 ret_val = lpfc_sli_issue_iocb(phba, pring, abtsiocb, 0);
4903 if (ret_val == IOCB_ERROR) {
4904 lpfc_sli_release_iocbq(phba, abtsiocb);
4905 errcnt++;
4906 continue;
4907 }
4908 }
4909
4910 return errcnt;
4911}
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931static void
4932lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
4933 struct lpfc_iocbq *cmdiocbq,
4934 struct lpfc_iocbq *rspiocbq)
4935{
4936 wait_queue_head_t *pdone_q;
4937 unsigned long iflags;
4938
4939 spin_lock_irqsave(&phba->hbalock, iflags);
4940 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
4941 if (cmdiocbq->context2 && rspiocbq)
4942 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
4943 &rspiocbq->iocb, sizeof(IOCB_t));
4944
4945 pdone_q = cmdiocbq->context_un.wait_queue;
4946 if (pdone_q)
4947 wake_up(pdone_q);
4948 spin_unlock_irqrestore(&phba->hbalock, iflags);
4949 return;
4950}
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982int
4983lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
4984 struct lpfc_sli_ring *pring,
4985 struct lpfc_iocbq *piocb,
4986 struct lpfc_iocbq *prspiocbq,
4987 uint32_t timeout)
4988{
4989 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
4990 long timeleft, timeout_req = 0;
4991 int retval = IOCB_SUCCESS;
4992 uint32_t creg_val;
4993
4994
4995
4996
4997
4998 if (prspiocbq) {
4999 if (piocb->context2)
5000 return IOCB_ERROR;
5001 piocb->context2 = prspiocbq;
5002 }
5003
5004 piocb->iocb_cmpl = lpfc_sli_wake_iocb_wait;
5005 piocb->context_un.wait_queue = &done_q;
5006 piocb->iocb_flag &= ~LPFC_IO_WAKE;
5007
5008 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
5009 creg_val = readl(phba->HCregaddr);
5010 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
5011 writel(creg_val, phba->HCregaddr);
5012 readl(phba->HCregaddr);
5013 }
5014
5015 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
5016 if (retval == IOCB_SUCCESS) {
5017 timeout_req = timeout * HZ;
5018 timeleft = wait_event_timeout(done_q,
5019 piocb->iocb_flag & LPFC_IO_WAKE,
5020 timeout_req);
5021
5022 if (piocb->iocb_flag & LPFC_IO_WAKE) {
5023 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5024 "0331 IOCB wake signaled\n");
5025 } else if (timeleft == 0) {
5026 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5027 "0338 IOCB wait timeout error - no "
5028 "wake response Data x%x\n", timeout);
5029 retval = IOCB_TIMEDOUT;
5030 } else {
5031 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5032 "0330 IOCB wake NOT set, "
5033 "Data x%x x%lx\n",
5034 timeout, (timeleft / jiffies));
5035 retval = IOCB_TIMEDOUT;
5036 }
5037 } else {
5038 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
5039 "0332 IOCB wait issue failed, Data x%x\n",
5040 retval);
5041 retval = IOCB_ERROR;
5042 }
5043
5044 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
5045 creg_val = readl(phba->HCregaddr);
5046 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
5047 writel(creg_val, phba->HCregaddr);
5048 readl(phba->HCregaddr);
5049 }
5050
5051 if (prspiocbq)
5052 piocb->context2 = NULL;
5053
5054 piocb->context_un.wait_queue = NULL;
5055 piocb->iocb_cmpl = NULL;
5056 return retval;
5057}
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085int
5086lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
5087 uint32_t timeout)
5088{
5089 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
5090 int retval;
5091 unsigned long flag;
5092
5093
5094 if (pmboxq->context1)
5095 return MBX_NOT_FINISHED;
5096
5097 pmboxq->mbox_flag &= ~LPFC_MBX_WAKE;
5098
5099 pmboxq->mbox_cmpl = lpfc_sli_wake_mbox_wait;
5100
5101 pmboxq->context1 = &done_q;
5102
5103
5104 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
5105
5106 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
5107 wait_event_interruptible_timeout(done_q,
5108 pmboxq->mbox_flag & LPFC_MBX_WAKE,
5109 timeout * HZ);
5110
5111 spin_lock_irqsave(&phba->hbalock, flag);
5112 pmboxq->context1 = NULL;
5113
5114
5115
5116
5117 if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
5118 retval = MBX_SUCCESS;
5119 else {
5120 retval = MBX_TIMEOUT;
5121 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5122 }
5123 spin_unlock_irqrestore(&phba->hbalock, flag);
5124 }
5125
5126 return retval;
5127}
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141int
5142lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
5143{
5144 struct lpfc_vport *vport = phba->pport;
5145 int i = 0;
5146 uint32_t ha_copy;
5147
5148 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) {
5149 if (i++ > LPFC_MBOX_TMO * 1000)
5150 return 1;
5151
5152
5153
5154
5155
5156
5157 spin_lock_irq(&phba->hbalock);
5158 ha_copy = phba->work_ha;
5159 phba->work_ha &= ~HA_MBATT;
5160 spin_unlock_irq(&phba->hbalock);
5161
5162 if (ha_copy & HA_MBATT)
5163 if (lpfc_sli_handle_mb_event(phba) == 0)
5164 i = 0;
5165
5166 msleep(1);
5167 }
5168
5169 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
5170}
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182int
5183lpfc_sli_check_eratt(struct lpfc_hba *phba)
5184{
5185 uint32_t ha_copy;
5186
5187
5188
5189
5190 if (phba->link_flag & LS_IGNORE_ERATT)
5191 return 0;
5192
5193
5194 spin_lock_irq(&phba->hbalock);
5195 if (phba->hba_flag & HBA_ERATT_HANDLED) {
5196
5197 spin_unlock_irq(&phba->hbalock);
5198 return 0;
5199 }
5200
5201
5202 ha_copy = readl(phba->HAregaddr);
5203 if (ha_copy & HA_ERATT) {
5204
5205 lpfc_sli_read_hs(phba);
5206
5207 phba->work_ha |= HA_ERATT;
5208
5209 phba->hba_flag |= HBA_ERATT_HANDLED;
5210 spin_unlock_irq(&phba->hbalock);
5211 return 1;
5212 }
5213 spin_unlock_irq(&phba->hbalock);
5214 return 0;
5215}
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238irqreturn_t
5239lpfc_sp_intr_handler(int irq, void *dev_id)
5240{
5241 struct lpfc_hba *phba;
5242 uint32_t ha_copy;
5243 uint32_t work_ha_copy;
5244 unsigned long status;
5245 uint32_t control;
5246
5247 MAILBOX_t *mbox, *pmbox;
5248 struct lpfc_vport *vport;
5249 struct lpfc_nodelist *ndlp;
5250 struct lpfc_dmabuf *mp;
5251 LPFC_MBOXQ_t *pmb;
5252 int rc;
5253
5254
5255
5256
5257
5258 phba = (struct lpfc_hba *)dev_id;
5259
5260 if (unlikely(!phba))
5261 return IRQ_NONE;
5262
5263
5264
5265
5266
5267 if (phba->intr_type == MSIX) {
5268
5269 if (unlikely(pci_channel_offline(phba->pcidev)))
5270 return IRQ_NONE;
5271
5272 phba->sli.slistat.sli_intr++;
5273
5274 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
5275 return IRQ_NONE;
5276
5277 spin_lock(&phba->hbalock);
5278 ha_copy = readl(phba->HAregaddr);
5279
5280
5281
5282 if (phba->link_flag & LS_IGNORE_ERATT)
5283 ha_copy &= ~HA_ERATT;
5284
5285 if (ha_copy & HA_ERATT) {
5286 if (phba->hba_flag & HBA_ERATT_HANDLED)
5287
5288 ha_copy &= ~HA_ERATT;
5289 else
5290
5291 phba->hba_flag |= HBA_ERATT_HANDLED;
5292 }
5293
5294 writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
5295 phba->HAregaddr);
5296 readl(phba->HAregaddr);
5297 spin_unlock(&phba->hbalock);
5298 } else
5299 ha_copy = phba->ha_copy;
5300
5301 work_ha_copy = ha_copy & phba->work_ha_mask;
5302
5303 if (work_ha_copy) {
5304 if (work_ha_copy & HA_LATT) {
5305 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
5306
5307
5308
5309
5310 spin_lock(&phba->hbalock);
5311 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
5312 control = readl(phba->HCregaddr);
5313 control &= ~HC_LAINT_ENA;
5314 writel(control, phba->HCregaddr);
5315 readl(phba->HCregaddr);
5316 spin_unlock(&phba->hbalock);
5317 }
5318 else
5319 work_ha_copy &= ~HA_LATT;
5320 }
5321
5322 if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
5323
5324
5325
5326
5327 status = (work_ha_copy &
5328 (HA_RXMASK << (4*LPFC_ELS_RING)));
5329 status >>= (4*LPFC_ELS_RING);
5330 if (status & HA_RXMASK) {
5331 spin_lock(&phba->hbalock);
5332 control = readl(phba->HCregaddr);
5333
5334 lpfc_debugfs_slow_ring_trc(phba,
5335 "ISR slow ring: ctl:x%x stat:x%x isrcnt:x%x",
5336 control, status,
5337 (uint32_t)phba->sli.slistat.sli_intr);
5338
5339 if (control & (HC_R0INT_ENA << LPFC_ELS_RING)) {
5340 lpfc_debugfs_slow_ring_trc(phba,
5341 "ISR Disable ring:"
5342 "pwork:x%x hawork:x%x wait:x%x",
5343 phba->work_ha, work_ha_copy,
5344 (uint32_t)((unsigned long)
5345 &phba->work_waitq));
5346
5347 control &=
5348 ~(HC_R0INT_ENA << LPFC_ELS_RING);
5349 writel(control, phba->HCregaddr);
5350 readl(phba->HCregaddr);
5351 }
5352 else {
5353 lpfc_debugfs_slow_ring_trc(phba,
5354 "ISR slow ring: pwork:"
5355 "x%x hawork:x%x wait:x%x",
5356 phba->work_ha, work_ha_copy,
5357 (uint32_t)((unsigned long)
5358 &phba->work_waitq));
5359 }
5360 spin_unlock(&phba->hbalock);
5361 }
5362 }
5363 spin_lock(&phba->hbalock);
5364 if (work_ha_copy & HA_ERATT)
5365 lpfc_sli_read_hs(phba);
5366 if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
5367 pmb = phba->sli.mbox_active;
5368 pmbox = &pmb->mb;
5369 mbox = phba->mbox;
5370 vport = pmb->vport;
5371
5372
5373 lpfc_sli_pcimem_bcopy(mbox, pmbox, sizeof(uint32_t));
5374 if (pmbox->mbxOwner != OWN_HOST) {
5375 spin_unlock(&phba->hbalock);
5376
5377
5378
5379
5380 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
5381 LOG_SLI,
5382 "(%d):0304 Stray Mailbox "
5383 "Interrupt mbxCommand x%x "
5384 "mbxStatus x%x\n",
5385 (vport ? vport->vpi : 0),
5386 pmbox->mbxCommand,
5387 pmbox->mbxStatus);
5388
5389 work_ha_copy &= ~HA_MBATT;
5390 } else {
5391 phba->sli.mbox_active = NULL;
5392 spin_unlock(&phba->hbalock);
5393 phba->last_completion_time = jiffies;
5394 del_timer(&phba->sli.mbox_tmo);
5395 if (pmb->mbox_cmpl) {
5396 lpfc_sli_pcimem_bcopy(mbox, pmbox,
5397 MAILBOX_CMD_SIZE);
5398 }
5399 if (pmb->mbox_flag & LPFC_MBX_IMED_UNREG) {
5400 pmb->mbox_flag &= ~LPFC_MBX_IMED_UNREG;
5401
5402 lpfc_debugfs_disc_trc(vport,
5403 LPFC_DISC_TRC_MBOX_VPORT,
5404 "MBOX dflt rpi: : "
5405 "status:x%x rpi:x%x",
5406 (uint32_t)pmbox->mbxStatus,
5407 pmbox->un.varWords[0], 0);
5408
5409 if (!pmbox->mbxStatus) {
5410 mp = (struct lpfc_dmabuf *)
5411 (pmb->context1);
5412 ndlp = (struct lpfc_nodelist *)
5413 pmb->context2;
5414
5415
5416
5417
5418
5419
5420 lpfc_unreg_login(phba,
5421 vport->vpi,
5422 pmbox->un.varWords[0],
5423 pmb);
5424 pmb->mbox_cmpl =
5425 lpfc_mbx_cmpl_dflt_rpi;
5426 pmb->context1 = mp;
5427 pmb->context2 = ndlp;
5428 pmb->vport = vport;
5429 rc = lpfc_sli_issue_mbox(phba,
5430 pmb,
5431 MBX_NOWAIT);
5432 if (rc != MBX_BUSY)
5433 lpfc_printf_log(phba,
5434 KERN_ERR,
5435 LOG_MBOX | LOG_SLI,
5436 "0350 rc should have"
5437 "been MBX_BUSY");
5438 goto send_current_mbox;
5439 }
5440 }
5441 spin_lock(&phba->pport->work_port_lock);
5442 phba->pport->work_port_events &=
5443 ~WORKER_MBOX_TMO;
5444 spin_unlock(&phba->pport->work_port_lock);
5445 lpfc_mbox_cmpl_put(phba, pmb);
5446 }
5447 } else
5448 spin_unlock(&phba->hbalock);
5449
5450 if ((work_ha_copy & HA_MBATT) &&
5451 (phba->sli.mbox_active == NULL)) {
5452send_current_mbox:
5453
5454 do {
5455 rc = lpfc_sli_issue_mbox(phba, NULL,
5456 MBX_NOWAIT);
5457 } while (rc == MBX_NOT_FINISHED);
5458 if (rc != MBX_SUCCESS)
5459 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX |
5460 LOG_SLI, "0349 rc should be "
5461 "MBX_SUCCESS");
5462 }
5463
5464 spin_lock(&phba->hbalock);
5465 phba->work_ha |= work_ha_copy;
5466 spin_unlock(&phba->hbalock);
5467 lpfc_worker_wake_up(phba);
5468 }
5469 return IRQ_HANDLED;
5470
5471}
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492irqreturn_t
5493lpfc_fp_intr_handler(int irq, void *dev_id)
5494{
5495 struct lpfc_hba *phba;
5496 uint32_t ha_copy;
5497 unsigned long status;
5498
5499
5500
5501
5502 phba = (struct lpfc_hba *) dev_id;
5503
5504 if (unlikely(!phba))
5505 return IRQ_NONE;
5506
5507
5508
5509
5510
5511 if (phba->intr_type == MSIX) {
5512
5513 if (unlikely(pci_channel_offline(phba->pcidev)))
5514 return IRQ_NONE;
5515
5516 phba->sli.slistat.sli_intr++;
5517
5518 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
5519 return IRQ_NONE;
5520
5521 ha_copy = readl(phba->HAregaddr);
5522
5523 spin_lock(&phba->hbalock);
5524 writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
5525 phba->HAregaddr);
5526 readl(phba->HAregaddr);
5527 spin_unlock(&phba->hbalock);
5528 } else
5529 ha_copy = phba->ha_copy;
5530
5531
5532
5533
5534 ha_copy &= ~(phba->work_ha_mask);
5535
5536 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
5537 status >>= (4*LPFC_FCP_RING);
5538 if (status & HA_RXMASK)
5539 lpfc_sli_handle_fast_ring_event(phba,
5540 &phba->sli.ring[LPFC_FCP_RING],
5541 status);
5542
5543 if (phba->cfg_multi_ring_support == 2) {
5544
5545
5546
5547
5548 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
5549 status >>= (4*LPFC_EXTRA_RING);
5550 if (status & HA_RXMASK) {
5551 lpfc_sli_handle_fast_ring_event(phba,
5552 &phba->sli.ring[LPFC_EXTRA_RING],
5553 status);
5554 }
5555 }
5556 return IRQ_HANDLED;
5557}
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575irqreturn_t
5576lpfc_intr_handler(int irq, void *dev_id)
5577{
5578 struct lpfc_hba *phba;
5579 irqreturn_t sp_irq_rc, fp_irq_rc;
5580 unsigned long status1, status2;
5581
5582
5583
5584
5585
5586 phba = (struct lpfc_hba *) dev_id;
5587
5588 if (unlikely(!phba))
5589 return IRQ_NONE;
5590
5591
5592 if (unlikely(pci_channel_offline(phba->pcidev)))
5593 return IRQ_NONE;
5594
5595
5596 phba->sli.slistat.sli_intr++;
5597
5598
5599 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
5600 return IRQ_NONE;
5601
5602 spin_lock(&phba->hbalock);
5603 phba->ha_copy = readl(phba->HAregaddr);
5604 if (unlikely(!phba->ha_copy)) {
5605 spin_unlock(&phba->hbalock);
5606 return IRQ_NONE;
5607 } else if (phba->ha_copy & HA_ERATT) {
5608 if (phba->hba_flag & HBA_ERATT_HANDLED)
5609
5610 phba->ha_copy &= ~HA_ERATT;
5611 else
5612
5613 phba->hba_flag |= HBA_ERATT_HANDLED;
5614 }
5615
5616
5617 writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
5618 readl(phba->HAregaddr);
5619 spin_unlock(&phba->hbalock);
5620
5621
5622
5623
5624
5625
5626 status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
5627
5628
5629 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
5630 status2 >>= (4*LPFC_ELS_RING);
5631
5632 if (status1 || (status2 & HA_RXMASK))
5633 sp_irq_rc = lpfc_sp_intr_handler(irq, dev_id);
5634 else
5635 sp_irq_rc = IRQ_NONE;
5636
5637
5638
5639
5640
5641
5642 status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
5643 status1 >>= (4*LPFC_FCP_RING);
5644
5645
5646 if (phba->cfg_multi_ring_support == 2) {
5647 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
5648 status2 >>= (4*LPFC_EXTRA_RING);
5649 } else
5650 status2 = 0;
5651
5652 if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
5653 fp_irq_rc = lpfc_fp_intr_handler(irq, dev_id);
5654 else
5655 fp_irq_rc = IRQ_NONE;
5656
5657
5658 return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
5659}