1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* CMU-CH Interrupt Block
*/
#include <sys/types.h>
#include <sys/kmem.h>
#include <sys/async.h>
#include <sys/systm.h>
#include <sys/spl.h>
#include <sys/sunddi.h>
#include <sys/machsystm.h>
#include <sys/ddi_impldefs.h>
#include <sys/pcicmu/pcicmu.h>
static uint_t pcmu_ib_intr_reset(void *arg);
extern uint64_t xc_tick_jump_limit;
void
pcmu_ib_create(pcmu_t *pcmu_p)
{
pcmu_ib_t *pib_p;
uintptr_t a;
int i;
/*
* Allocate interrupt block state structure and link it to
* the pci state structure.
*/
pib_p = kmem_zalloc(sizeof (pcmu_ib_t), KM_SLEEP);
pcmu_p->pcmu_ib_p = pib_p;
pib_p->pib_pcmu_p = pcmu_p;
a = pcmu_ib_setup(pib_p);
/*
* Determine virtual addresses of interrupt mapping, clear and diag
* registers that have common offsets.
*/
pib_p->pib_intr_retry_timer_reg =
(uint64_t *)(a + PCMU_IB_INTR_RETRY_TIMER_OFFSET);
pib_p->pib_obio_intr_state_diag_reg =
(uint64_t *)(a + PCMU_IB_OBIO_INTR_STATE_DIAG_REG);
PCMU_DBG2(PCMU_DBG_ATTACH, pcmu_p->pcmu_dip,
"pcmu_ib_create: obio_imr=%x, obio_cir=%x\n",
pib_p->pib_obio_intr_map_regs, pib_p->pib_obio_clear_intr_regs);
PCMU_DBG2(PCMU_DBG_ATTACH, pcmu_p->pcmu_dip,
"pcmu_ib_create: retry_timer=%x, obio_diag=%x\n",
pib_p->pib_intr_retry_timer_reg,
pib_p->pib_obio_intr_state_diag_reg);
pib_p->pib_ino_lst = (pcmu_ib_ino_info_t *)NULL;
mutex_init(&pib_p->pib_intr_lock, NULL, MUTEX_DRIVER, NULL);
mutex_init(&pib_p->pib_ino_lst_mutex, NULL, MUTEX_DRIVER, NULL);
PCMU_DBG1(PCMU_DBG_ATTACH, pcmu_p->pcmu_dip,
"pcmu_ib_create: numproxy=%x\n", pcmu_p->pcmu_numproxy);
for (i = 1; i <= pcmu_p->pcmu_numproxy; i++) {
set_intr_mapping_reg(pcmu_p->pcmu_id,
(uint64_t *)pib_p->pib_upa_imr[i - 1], i);
}
pcmu_ib_configure(pib_p);
bus_func_register(BF_TYPE_RESINTR, pcmu_ib_intr_reset, pib_p);
}
void
pcmu_ib_destroy(pcmu_t *pcmu_p)
{
pcmu_ib_t *pib_p = pcmu_p->pcmu_ib_p;
PCMU_DBG0(PCMU_DBG_IB, pcmu_p->pcmu_dip, "pcmu_ib_destroy\n");
bus_func_unregister(BF_TYPE_RESINTR, pcmu_ib_intr_reset, pib_p);
intr_dist_rem_weighted(pcmu_ib_intr_dist_all, pib_p);
mutex_destroy(&pib_p->pib_ino_lst_mutex);
mutex_destroy(&pib_p->pib_intr_lock);
pcmu_ib_free_ino_all(pib_p);
kmem_free(pib_p, sizeof (pcmu_ib_t));
pcmu_p->pcmu_ib_p = NULL;
}
void
pcmu_ib_configure(pcmu_ib_t *pib_p)
{
*pib_p->pib_intr_retry_timer_reg = pcmu_intr_retry_intv;
}
/*
* can only used for CMU-CH internal interrupts ue, pbm
*/
void
pcmu_ib_intr_enable(pcmu_t *pcmu_p, pcmu_ib_ino_t ino)
{
pcmu_ib_t *pib_p = pcmu_p->pcmu_ib_p;
pcmu_ib_mondo_t mondo = PCMU_IB_INO_TO_MONDO(pib_p, ino);
volatile uint64_t *imr_p = ib_intr_map_reg_addr(pib_p, ino);
uint_t cpu_id;
/*
* Determine the cpu for the interrupt.
*/
mutex_enter(&pib_p->pib_intr_lock);
cpu_id = intr_dist_cpuid();
cpu_id = u2u_translate_tgtid(pcmu_p, cpu_id, imr_p);
PCMU_DBG2(PCMU_DBG_IB, pcmu_p->pcmu_dip,
"pcmu_ib_intr_enable: ino=%x cpu_id=%x\n", ino, cpu_id);
*imr_p = ib_get_map_reg(mondo, cpu_id);
PCMU_IB_INO_INTR_CLEAR(ib_clear_intr_reg_addr(pib_p, ino));
mutex_exit(&pib_p->pib_intr_lock);
}
/*
* Disable the interrupt via its interrupt mapping register.
* Can only be used for internal interrupts: ue, pbm.
* If called under interrupt context, wait should be set to 0
*/
void
pcmu_ib_intr_disable(pcmu_ib_t *pib_p, pcmu_ib_ino_t ino, int wait)
{
volatile uint64_t *imr_p = ib_intr_map_reg_addr(pib_p, ino);
volatile uint64_t *state_reg_p = PCMU_IB_INO_INTR_STATE_REG(pib_p, ino);
hrtime_t start_time;
hrtime_t prev, curr, interval, jump;
hrtime_t intr_timeout;
/* disable the interrupt */
mutex_enter(&pib_p->pib_intr_lock);
PCMU_IB_INO_INTR_OFF(imr_p);
*imr_p; /* flush previous write */
mutex_exit(&pib_p->pib_intr_lock);
if (!wait)
goto wait_done;
intr_timeout = pcmu_intrpend_timeout;
jump = TICK_TO_NSEC(xc_tick_jump_limit);
start_time = curr = gethrtime();
/* busy wait if there is interrupt being processed */
while (PCMU_IB_INO_INTR_PENDING(state_reg_p, ino) && !panicstr) {
/*
* If we have a really large jump in hrtime, it is most
* probably because we entered the debugger (or OBP,
* in general). So, we adjust the timeout accordingly
* to prevent declaring an interrupt timeout. The
* master-interrupt mechanism in OBP should deliver
* the interrupts properly.
*/
prev = curr;
curr = gethrtime();
interval = curr - prev;
if (interval > jump)
intr_timeout += interval;
if (curr - start_time > intr_timeout) {
pcmu_pbm_t *pcbm_p = pib_p->pib_pcmu_p->pcmu_pcbm_p;
cmn_err(CE_WARN,
"%s:%s: pcmu_ib_intr_disable timeout %x",
pcbm_p->pcbm_nameinst_str,
pcbm_p->pcbm_nameaddr_str, ino);
break;
}
}
wait_done:
PCMU_IB_INO_INTR_PEND(ib_clear_intr_reg_addr(pib_p, ino));
u2u_ittrans_cleanup((u2u_ittrans_data_t *)
(PCMU_IB2CB(pib_p)->pcb_ittrans_cookie), imr_p);
}
/* can only used for CMU-CH internal interrupts ue, pbm */
void
pcmu_ib_nintr_clear(pcmu_ib_t *pib_p, pcmu_ib_ino_t ino)
{
uint64_t *clr_reg = ib_clear_intr_reg_addr(pib_p, ino);
PCMU_IB_INO_INTR_CLEAR(clr_reg);
}
/*
* distribute PBM and UPA interrupts. ino is set to 0 by caller if we
* are dealing with UPA interrupts (without inos).
*/
void
pcmu_ib_intr_dist_nintr(pcmu_ib_t *pib_p, pcmu_ib_ino_t ino,
volatile uint64_t *imr_p)
{
volatile uint64_t imr = *imr_p;
uint32_t cpu_id;
if (!PCMU_IB_INO_INTR_ISON(imr))
return;
cpu_id = intr_dist_cpuid();
if (ino) {
cpu_id = u2u_translate_tgtid(pib_p->pib_pcmu_p, cpu_id, imr_p);
}
if (ib_map_reg_get_cpu(*imr_p) == cpu_id) {
return;
}
*imr_p = ib_get_map_reg(PCMU_IB_IMR2MONDO(imr), cpu_id);
imr = *imr_p; /* flush previous write */
}
static void
pcmu_ib_intr_dist(pcmu_ib_t *pib_p, pcmu_ib_ino_info_t *ino_p)
{
uint32_t cpu_id = ino_p->pino_cpuid;
pcmu_ib_ino_t ino = ino_p->pino_ino;
volatile uint64_t imr, *imr_p, *state_reg;
hrtime_t start_time;
hrtime_t prev, curr, interval, jump;
hrtime_t intr_timeout;
ASSERT(MUTEX_HELD(&pib_p->pib_ino_lst_mutex));
imr_p = ib_intr_map_reg_addr(pib_p, ino);
state_reg = PCMU_IB_INO_INTR_STATE_REG(pib_p, ino);
/* disable interrupt, this could disrupt devices sharing our slot */
PCMU_IB_INO_INTR_OFF(imr_p);
imr = *imr_p; /* flush previous write */
/* busy wait if there is interrupt being processed */
intr_timeout = pcmu_intrpend_timeout;
jump = TICK_TO_NSEC(xc_tick_jump_limit);
start_time = curr = gethrtime();
while (PCMU_IB_INO_INTR_PENDING(state_reg, ino) && !panicstr) {
/*
* If we have a really large jump in hrtime, it is most
* probably because we entered the debugger (or OBP,
* in general). So, we adjust the timeout accordingly
* to prevent declaring an interrupt timeout. The
* master-interrupt mechanism in OBP should deliver
* the interrupts properly.
*/
prev = curr;
curr = gethrtime();
interval = curr - prev;
if (interval > jump)
intr_timeout += interval;
if (curr - start_time > intr_timeout) {
pcmu_pbm_t *pcbm_p = pib_p->pib_pcmu_p->pcmu_pcbm_p;
cmn_err(CE_WARN,
"%s:%s: pcmu_ib_intr_dist(%p,%x) timeout",
pcbm_p->pcbm_nameinst_str,
pcbm_p->pcbm_nameaddr_str,
(void *)imr_p, PCMU_IB_INO_TO_MONDO(pib_p, ino));
break;
}
}
cpu_id = u2u_translate_tgtid(pib_p->pib_pcmu_p, cpu_id, imr_p);
*imr_p = ib_get_map_reg(PCMU_IB_IMR2MONDO(imr), cpu_id);
imr = *imr_p; /* flush previous write */
}
/*
* Redistribute interrupts of the specified weight. The first call has a weight
* of weight_max, which can be used to trigger initialization for
* redistribution. The inos with weight [weight_max, inf.) should be processed
* on the "weight == weight_max" call. This first call is followed by calls
* of decreasing weights, inos of that weight should be processed. The final
* call specifies a weight of zero, this can be used to trigger processing of
* stragglers.
*/
void
pcmu_ib_intr_dist_all(void *arg, int32_t weight_max, int32_t weight)
{
pcmu_ib_t *pib_p = (pcmu_ib_t *)arg;
pcmu_ib_ino_info_t *ino_p;
ih_t *ih_lst;
int32_t dweight;
int i;
mutex_enter(&pib_p->pib_ino_lst_mutex);
/* Perform special processing for first call of a redistribution. */
if (weight == weight_max) {
for (ino_p = pib_p->pib_ino_lst; ino_p;
ino_p = ino_p->pino_next) {
/*
* Clear pino_established of each ino on first call.
* The pino_established field may be used by a pci
* nexus driver's pcmu_intr_dist_cpuid implementation
* when detection of established pci slot-cpu binding
* for multi function pci cards.
*/
ino_p->pino_established = 0;
/*
* recompute the pino_intr_weight based on the device
* weight of all devinfo nodes sharing the ino (this
* will allow us to pick up new weights established by
* i_ddi_set_intr_weight()).
*/
ino_p->pino_intr_weight = 0;
for (i = 0, ih_lst = ino_p->pino_ih_head;
i < ino_p->pino_ih_size;
i++, ih_lst = ih_lst->ih_next) {
dweight = i_ddi_get_intr_weight(ih_lst->ih_dip);
if (dweight > 0)
ino_p->pino_intr_weight += dweight;
}
}
}
for (ino_p = pib_p->pib_ino_lst; ino_p; ino_p = ino_p->pino_next) {
/*
* Get the weight of the ino and determine if we are going to
* process call. We wait until an pcmu_ib_intr_dist_all call of
* the proper weight occurs to support redistribution of all
* heavy weighted interrupts first (across all nexus driver
* instances). This is done to ensure optimal
* INTR_WEIGHTED_DIST behavior.
*/
if ((weight == ino_p->pino_intr_weight) ||
((weight >= weight_max) &&
(ino_p->pino_intr_weight >= weight_max))) {
/* select cpuid to target and mark ino established */
ino_p->pino_cpuid = pcmu_intr_dist_cpuid(pib_p, ino_p);
ino_p->pino_established = 1;
/* Add device weight of ino devinfos to targeted cpu. */
for (i = 0, ih_lst = ino_p->pino_ih_head;
i < ino_p->pino_ih_size;
i++, ih_lst = ih_lst->ih_next) {
dweight = i_ddi_get_intr_weight(ih_lst->ih_dip);
intr_dist_cpuid_add_device_weight(
ino_p->pino_cpuid, ih_lst->ih_dip, dweight);
}
/* program the hardware */
pcmu_ib_intr_dist(pib_p, ino_p);
}
}
mutex_exit(&pib_p->pib_ino_lst_mutex);
}
/*
* Reset interrupts to IDLE. This function is called during
* panic handling after redistributing interrupts; it's needed to
* support dumping to network devices after 'sync' from OBP.
*
* N.B. This routine runs in a context where all other threads
* are permanently suspended.
*/
static uint_t
pcmu_ib_intr_reset(void *arg)
{
pcmu_ib_t *pib_p = (pcmu_ib_t *)arg;
pcmu_ib_ino_t ino;
uint64_t *clr_reg;
/*
* Note that we only actually care about interrupts that are
* potentially from network devices.
*/
for (ino = 0; ino <= pib_p->pib_max_ino; ino++) {
clr_reg = ib_clear_intr_reg_addr(pib_p, ino);
PCMU_IB_INO_INTR_CLEAR(clr_reg);
}
return (BF_NONE);
}
void
pcmu_ib_suspend(pcmu_ib_t *pib_p)
{
pcmu_ib_ino_info_t *ip;
/* save ino_lst interrupts' mapping registers content */
mutex_enter(&pib_p->pib_ino_lst_mutex);
for (ip = pib_p->pib_ino_lst; ip; ip = ip->pino_next) {
ip->pino_map_reg_save = *ip->pino_map_reg;
}
mutex_exit(&pib_p->pib_ino_lst_mutex);
}
void
pcmu_ib_resume(pcmu_ib_t *pib_p)
{
pcmu_ib_ino_info_t *ip;
/* restore ino_lst interrupts' mapping registers content */
mutex_enter(&pib_p->pib_ino_lst_mutex);
for (ip = pib_p->pib_ino_lst; ip; ip = ip->pino_next) {
PCMU_IB_INO_INTR_CLEAR(ip->pino_clr_reg); /* set intr to idle */
*ip->pino_map_reg = ip->pino_map_reg_save; /* restore IMR */
}
mutex_exit(&pib_p->pib_ino_lst_mutex);
}
/*
* locate ino_info structure on pib_p->pib_ino_lst according to ino#
* returns NULL if not found.
*/
pcmu_ib_ino_info_t *
pcmu_ib_locate_ino(pcmu_ib_t *pib_p, pcmu_ib_ino_t ino_num)
{
pcmu_ib_ino_info_t *ino_p = pib_p->pib_ino_lst;
ASSERT(MUTEX_HELD(&pib_p->pib_ino_lst_mutex));
for (; ino_p && ino_p->pino_ino != ino_num; ino_p = ino_p->pino_next)
;
return (ino_p);
}
#define PCMU_IB_INO_TO_SLOT(ino) \
(PCMU_IB_IS_OBIO_INO(ino) ? 0xff : ((ino) & 0x1f) >> 2)
pcmu_ib_ino_info_t *
pcmu_ib_new_ino(pcmu_ib_t *pib_p, pcmu_ib_ino_t ino_num, ih_t *ih_p)
{
pcmu_ib_ino_info_t *ino_p = kmem_alloc(sizeof (pcmu_ib_ino_info_t),
KM_SLEEP);
ino_p->pino_ino = ino_num;
ino_p->pino_slot_no = PCMU_IB_INO_TO_SLOT(ino_num);
ino_p->pino_ib_p = pib_p;
ino_p->pino_clr_reg = ib_clear_intr_reg_addr(pib_p, ino_num);
ino_p->pino_map_reg = ib_intr_map_reg_addr(pib_p, ino_num);
ino_p->pino_unclaimed = 0;
/*
* cannot disable interrupt since we might share slot
* PCMU_IB_INO_INTR_OFF(ino_p->pino_map_reg);
*/
ih_p->ih_next = ih_p;
ino_p->pino_ih_head = ih_p;
ino_p->pino_ih_tail = ih_p;
ino_p->pino_ih_start = ih_p;
ino_p->pino_ih_size = 1;
ino_p->pino_next = pib_p->pib_ino_lst;
pib_p->pib_ino_lst = ino_p;
return (ino_p);
}
/* the ino_p is retrieved by previous call to pcmu_ib_locate_ino() */
void
pcmu_ib_delete_ino(pcmu_ib_t *pib_p, pcmu_ib_ino_info_t *ino_p)
{
pcmu_ib_ino_info_t *list = pib_p->pib_ino_lst;
ASSERT(MUTEX_HELD(&pib_p->pib_ino_lst_mutex));
if (list == ino_p) {
pib_p->pib_ino_lst = list->pino_next;
} else {
for (; list->pino_next != ino_p; list = list->pino_next)
;
list->pino_next = ino_p->pino_next;
}
}
/* free all ino when we are detaching */
void
pcmu_ib_free_ino_all(pcmu_ib_t *pib_p)
{
pcmu_ib_ino_info_t *tmp = pib_p->pib_ino_lst;
pcmu_ib_ino_info_t *next = NULL;
while (tmp) {
next = tmp->pino_next;
kmem_free(tmp, sizeof (pcmu_ib_ino_info_t));
tmp = next;
}
}
void
pcmu_ib_ino_add_intr(pcmu_t *pcmu_p, pcmu_ib_ino_info_t *ino_p, ih_t *ih_p)
{
pcmu_ib_ino_t ino = ino_p->pino_ino;
pcmu_ib_t *pib_p = ino_p->pino_ib_p;
volatile uint64_t *state_reg = PCMU_IB_INO_INTR_STATE_REG(pib_p, ino);
hrtime_t start_time;
hrtime_t prev, curr, interval, jump;
hrtime_t intr_timeout;
ASSERT(pib_p == pcmu_p->pcmu_ib_p);
ASSERT(MUTEX_HELD(&pib_p->pib_ino_lst_mutex));
/* disable interrupt, this could disrupt devices sharing our slot */
PCMU_IB_INO_INTR_OFF(ino_p->pino_map_reg);
*ino_p->pino_map_reg;
/* do NOT modify the link list until after the busy wait */
/*
* busy wait if there is interrupt being processed.
* either the pending state will be cleared by the interrupt wrapper
* or the interrupt will be marked as blocked indicating that it was
* jabbering.
*/
intr_timeout = pcmu_intrpend_timeout;
jump = TICK_TO_NSEC(xc_tick_jump_limit);
start_time = curr = gethrtime();
while ((ino_p->pino_unclaimed <= pcmu_unclaimed_intr_max) &&
PCMU_IB_INO_INTR_PENDING(state_reg, ino) && !panicstr) {
/*
* If we have a really large jump in hrtime, it is most
* probably because we entered the debugger (or OBP,
* in general). So, we adjust the timeout accordingly
* to prevent declaring an interrupt timeout. The
* master-interrupt mechanism in OBP should deliver
* the interrupts properly.
*/
prev = curr;
curr = gethrtime();
interval = curr - prev;
if (interval > jump)
intr_timeout += interval;
if (curr - start_time > intr_timeout) {
pcmu_pbm_t *pcbm_p = pcmu_p->pcmu_pcbm_p;
cmn_err(CE_WARN,
"%s:%s: pcmu_ib_ino_add_intr %x timeout",
pcbm_p->pcbm_nameinst_str,
pcbm_p->pcbm_nameaddr_str, ino);
break;
}
}
/* link up pcmu_ispec_t portion of the ppd */
ih_p->ih_next = ino_p->pino_ih_head;
ino_p->pino_ih_tail->ih_next = ih_p;
ino_p->pino_ih_tail = ih_p;
ino_p->pino_ih_start = ino_p->pino_ih_head;
ino_p->pino_ih_size++;
/*
* if the interrupt was previously blocked (left in pending state)
* because of jabber we need to clear the pending state in case the
* jabber has gone away.
*/
if (ino_p->pino_unclaimed > pcmu_unclaimed_intr_max) {
cmn_err(CE_WARN,
"%s%d: pcmu_ib_ino_add_intr: ino 0x%x has been unblocked",
ddi_driver_name(pcmu_p->pcmu_dip),
ddi_get_instance(pcmu_p->pcmu_dip),
ino_p->pino_ino);
ino_p->pino_unclaimed = 0;
PCMU_IB_INO_INTR_CLEAR(ino_p->pino_clr_reg);
}
/* re-enable interrupt */
PCMU_IB_INO_INTR_ON(ino_p->pino_map_reg);
*ino_p->pino_map_reg;
}
/*
* removes pcmu_ispec_t from the ino's link list.
* uses hardware mutex to lock out interrupt threads.
* Side effects: interrupt belongs to that ino is turned off on return.
* if we are sharing PCI slot with other inos, the caller needs
* to turn it back on.
*/
int
pcmu_ib_ino_rem_intr(pcmu_t *pcmu_p, pcmu_ib_ino_info_t *ino_p, ih_t *ih_p)
{
int i;
pcmu_ib_ino_t ino = ino_p->pino_ino;
ih_t *ih_lst = ino_p->pino_ih_head;
volatile uint64_t *state_reg =
PCMU_IB_INO_INTR_STATE_REG(ino_p->pino_ib_p, ino);
hrtime_t start_time;
hrtime_t prev, curr, interval, jump;
hrtime_t intr_timeout;
ASSERT(MUTEX_HELD(&ino_p->pino_ib_p->pib_ino_lst_mutex));
/* disable interrupt, this could disrupt devices sharing our slot */
PCMU_IB_INO_INTR_OFF(ino_p->pino_map_reg);
*ino_p->pino_map_reg;
/* do NOT modify the link list until after the busy wait */
/*
* busy wait if there is interrupt being processed.
* either the pending state will be cleared by the interrupt wrapper
* or the interrupt will be marked as blocked indicating that it was
* jabbering.
*/
intr_timeout = pcmu_intrpend_timeout;
jump = TICK_TO_NSEC(xc_tick_jump_limit);
start_time = curr = gethrtime();
while ((ino_p->pino_unclaimed <= pcmu_unclaimed_intr_max) &&
PCMU_IB_INO_INTR_PENDING(state_reg, ino) && !panicstr) {
/*
* If we have a really large jump in hrtime, it is most
* probably because we entered the debugger (or OBP,
* in general). So, we adjust the timeout accordingly
* to prevent declaring an interrupt timeout. The
* master-interrupt mechanism in OBP should deliver
* the interrupts properly.
*/
prev = curr;
curr = gethrtime();
interval = curr - prev;
if (interval > jump)
intr_timeout += interval;
if (curr - start_time > intr_timeout) {
pcmu_pbm_t *pcbm_p = pcmu_p->pcmu_pcbm_p;
cmn_err(CE_WARN,
"%s:%s: pcmu_ib_ino_rem_intr %x timeout",
pcbm_p->pcbm_nameinst_str,
pcbm_p->pcbm_nameaddr_str, ino);
PCMU_IB_INO_INTR_ON(ino_p->pino_map_reg);
*ino_p->pino_map_reg;
return (DDI_FAILURE);
}
}
if (ino_p->pino_ih_size == 1) {
if (ih_lst != ih_p)
goto not_found;
/* no need to set head/tail as ino_p will be freed */
goto reset;
}
/*
* if the interrupt was previously blocked (left in pending state)
* because of jabber we need to clear the pending state in case the
* jabber has gone away.
*/
if (ino_p->pino_unclaimed > pcmu_unclaimed_intr_max) {
cmn_err(CE_WARN,
"%s%d: pcmu_ib_ino_rem_intr: ino 0x%x has been unblocked",
ddi_driver_name(pcmu_p->pcmu_dip),
ddi_get_instance(pcmu_p->pcmu_dip),
ino_p->pino_ino);
ino_p->pino_unclaimed = 0;
PCMU_IB_INO_INTR_CLEAR(ino_p->pino_clr_reg);
}
/* search the link list for ih_p */
for (i = 0; (i < ino_p->pino_ih_size) && (ih_lst->ih_next != ih_p);
i++, ih_lst = ih_lst->ih_next)
;
if (ih_lst->ih_next != ih_p) {
goto not_found;
}
/* remove ih_p from the link list and maintain the head/tail */
ih_lst->ih_next = ih_p->ih_next;
if (ino_p->pino_ih_head == ih_p) {
ino_p->pino_ih_head = ih_p->ih_next;
}
if (ino_p->pino_ih_tail == ih_p) {
ino_p->pino_ih_tail = ih_lst;
}
ino_p->pino_ih_start = ino_p->pino_ih_head;
reset:
if (ih_p->ih_config_handle) {
pci_config_teardown(&ih_p->ih_config_handle);
}
kmem_free(ih_p, sizeof (ih_t));
ino_p->pino_ih_size--;
return (DDI_SUCCESS);
not_found:
PCMU_DBG2(PCMU_DBG_R_INTX, ino_p->pino_ib_p->pib_pcmu_p->pcmu_dip,
"ino_p=%x does not have ih_p=%x\n", ino_p, ih_p);
return (DDI_SUCCESS);
}
ih_t *
pcmu_ib_ino_locate_intr(pcmu_ib_ino_info_t *ino_p,
dev_info_t *rdip, uint32_t inum)
{
ih_t *ih_lst = ino_p->pino_ih_head;
int i;
for (i = 0; i < ino_p->pino_ih_size; i++, ih_lst = ih_lst->ih_next) {
if (ih_lst->ih_dip == rdip && ih_lst->ih_inum == inum) {
return (ih_lst);
}
}
return ((ih_t *)NULL);
}
ih_t *
pcmu_ib_alloc_ih(dev_info_t *rdip, uint32_t inum,
uint_t (*int_handler)(caddr_t int_handler_arg1, caddr_t int_handler_arg2),
caddr_t int_handler_arg1,
caddr_t int_handler_arg2)
{
ih_t *ih_p;
ih_p = kmem_alloc(sizeof (ih_t), KM_SLEEP);
ih_p->ih_dip = rdip;
ih_p->ih_inum = inum;
ih_p->ih_intr_state = PCMU_INTR_STATE_DISABLE;
ih_p->ih_handler = int_handler;
ih_p->ih_handler_arg1 = int_handler_arg1;
ih_p->ih_handler_arg2 = int_handler_arg2;
ih_p->ih_config_handle = NULL;
return (ih_p);
}
int
pcmu_ib_update_intr_state(pcmu_t *pcmu_p, dev_info_t *rdip,
ddi_intr_handle_impl_t *hdlp, uint_t new_intr_state)
{
pcmu_ib_t *pib_p = pcmu_p->pcmu_ib_p;
pcmu_ib_ino_info_t *ino_p;
pcmu_ib_mondo_t mondo;
ih_t *ih_p;
int ret = DDI_FAILURE;
mutex_enter(&pib_p->pib_ino_lst_mutex);
if ((mondo = PCMU_IB_INO_TO_MONDO(pcmu_p->pcmu_ib_p,
PCMU_IB_MONDO_TO_INO((int32_t)hdlp->ih_vector))) == 0) {
mutex_exit(&pib_p->pib_ino_lst_mutex);
return (ret);
}
if (ino_p = pcmu_ib_locate_ino(pib_p, PCMU_IB_MONDO_TO_INO(mondo))) {
if (ih_p = pcmu_ib_ino_locate_intr(ino_p,
rdip, hdlp->ih_inum)) {
ih_p->ih_intr_state = new_intr_state;
ret = DDI_SUCCESS;
}
}
mutex_exit(&pib_p->pib_ino_lst_mutex);
return (ret);
}
|