1 /* $NetBSD: gt.c,v 1.20 2009/05/12 12:18:45 cegger Exp $ */
4 * Copyright (c) 2002 Allegro Networks, Inc., Wasabi Systems, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the NetBSD Project by
18 * Allegro Networks, Inc., and Wasabi Systems, Inc.
19 * 4. The name of Allegro Networks, Inc. may not be used to endorse
20 * or promote products derived from this software without specific prior
22 * 5. The name of Wasabi Systems, Inc. may not be used to endorse
23 * or promote products derived from this software without specific prior
26 * THIS SOFTWARE IS PROVIDED BY ALLEGRO NETWORKS, INC. AND
27 * WASABI SYSTEMS, INC. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
28 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
29 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 * IN NO EVENT SHALL EITHER ALLEGRO NETWORKS, INC. OR WASABI SYSTEMS, INC.
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
41 * gt.c -- GT system controller driver
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: gt.c,v 1.20 2009/05/12 12:18:45 cegger Exp $");
47 #include "opt_marvell.h"
50 #include <sys/param.h>
51 #include <sys/types.h>
52 #include <sys/extent.h>
53 #include <sys/device.h>
54 #include <sys/kernel.h>
55 #include <sys/malloc.h>
57 #define _BUS_SPACE_PRIVATE
58 #define _BUS_DMA_PRIVATE
61 #include <powerpc/spr.h>
62 #include <powerpc/oea/hid.h>
64 #include <dev/marvell/gtreg.h>
65 #include <dev/marvell/gtintrreg.h>
66 #include <dev/marvell/gtvar.h>
67 #include <dev/marvell/gtethreg.h>
70 #include <sys/systm.h> /* for Debugger() */
73 #if ((GT_MPP_WATCHDOG & 0xf0f0f0f0) != 0)
74 # error /* unqualified: configuration botch! */
76 #if ((GT_MPP_WATCHDOG & GT_MPP_INTERRUPTS) != 0)
77 # error /* conflict: configuration botch! */
80 static void gt_comm_intr_enb(struct gt_softc
*);
81 static void gt_devbus_intr_enb(struct gt_softc
*);
83 static void gt_ecc_intr_enb(struct gt_softc
*);
87 void gt_init_hostid (struct gt_softc
*);
88 void gt_init_interrupt (struct gt_softc
*);
89 static int gt_comm_intr (void *);
91 void gt_watchdog_init(struct gt_softc
*);
92 void gt_watchdog_enable(void);
93 void gt_watchdog_disable(void);
94 void gt_watchdog_reset(void);
96 extern struct cfdriver gt_cd
;
98 static int gtfound
= 0;
100 static struct gt_softc
*gt_watchdog_sc
= 0;
101 static int gt_watchdog_state
= 0;
104 gt_cfprint (void *aux
, const char *pnp
)
106 struct gt_attach_args
*ga
= aux
;
109 aprint_normal("%s at %s", ga
->ga_name
, pnp
);
112 aprint_normal(" unit %d", ga
->ga_unit
);
118 gt_cfsearch(device_t parent
, cfdata_t cf
,
119 const int *ldesc
, void *aux
)
121 struct gt_softc
*gt
= (struct gt_softc
*) parent
;
122 struct gt_attach_args ga
;
124 ga
.ga_name
= cf
->cf_name
;
125 ga
.ga_dmat
= gt
->gt_dmat
;
126 ga
.ga_memt
= gt
->gt_memt
;
127 ga
.ga_memh
= gt
->gt_memh
;
128 ga
.ga_unit
= cf
->cf_loc
[GTCF_UNIT
];
130 if (config_match(parent
, cf
, &ga
) > 0)
131 config_attach(parent
, cf
, &ga
, gt_cfprint
);
137 gt_attach_common(struct gt_softc
*gt
)
139 uint32_t cpucfg
, cpumode
, cpumstr
;
141 uint32_t loaddr
, hiaddr
;
146 cpumode
= gt_read(gt
, GT_CPU_Mode
);
147 aprint_normal(": id %d", GT_CPUMode_MultiGTID_GET(cpumode
));
148 if (cpumode
& GT_CPUMode_MultiGT
)
149 aprint_normal (" (multi)");
150 switch (GT_CPUMode_CPUType_GET(cpumode
)) {
151 case 4: aprint_normal(", 60x bus"); break;
152 case 5: aprint_normal(", MPX bus"); break;
153 default: aprint_normal(", %#x(?) bus", GT_CPUMode_CPUType_GET(cpumode
)); break;
156 cpumstr
= gt_read(gt
, GT_CPU_Master_Ctl
);
157 cpumstr
&= ~(GT_CPUMstrCtl_CleanBlock
|GT_CPUMstrCtl_FlushBlock
);
159 cpumstr
|= GT_CPUMstrCtl_CleanBlock
|GT_CPUMstrCtl_FlushBlock
;
161 gt_write(gt
, GT_CPU_Master_Ctl
, cpumstr
);
163 switch (cpumstr
& (GT_CPUMstrCtl_CleanBlock
|GT_CPUMstrCtl_FlushBlock
)) {
165 case GT_CPUMstrCtl_CleanBlock
: aprint_normal(", snoop=clean"); break;
166 case GT_CPUMstrCtl_FlushBlock
: aprint_normal(", snoop=flush"); break;
167 case GT_CPUMstrCtl_CleanBlock
|GT_CPUMstrCtl_FlushBlock
:
168 aprint_normal(", snoop=clean&flush"); break;
170 aprint_normal(" wdog=%#x,%#x\n",
171 gt_read(gt
, GT_WDOG_Config
),
172 gt_read(gt
, GT_WDOG_Value
));
175 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_SCS0_Low_Decode
));
176 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_SCS0_High_Decode
));
177 aprint_normal_dev(>
->gt_dev
, " scs[0]=%#10x-%#10x\n", loaddr
, hiaddr
);
179 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_SCS1_Low_Decode
));
180 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_SCS1_High_Decode
));
181 aprint_normal_dev(>
->gt_dev
, " scs[1]=%#10x-%#10x\n", loaddr
, hiaddr
);
183 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_SCS2_Low_Decode
));
184 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_SCS2_High_Decode
));
185 aprint_normal_dev(>
->gt_dev
, " scs[2]=%#10x-%#10x\n", loaddr
, hiaddr
);
187 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_SCS3_Low_Decode
));
188 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_SCS3_High_Decode
));
189 aprint_normal_dev(>
->gt_dev
, " scs[3]=%#10x-%#10x\n", loaddr
, hiaddr
);
191 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_CS0_Low_Decode
));
192 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_CS0_High_Decode
));
193 aprint_normal_dev(>
->gt_dev
, " cs[0]=%#10x-%#10x\n", loaddr
, hiaddr
);
195 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_CS1_Low_Decode
));
196 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_CS1_High_Decode
));
197 aprint_normal_dev(>
->gt_dev
, " cs[1]=%#10x-%#10x\n", loaddr
, hiaddr
);
199 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_CS2_Low_Decode
));
200 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_CS2_High_Decode
));
201 aprint_normal_dev(>
->gt_dev
, " cs[2]=%#10x-%#10x\n", loaddr
, hiaddr
);
203 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_CS3_Low_Decode
));
204 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_CS3_High_Decode
));
205 aprint_normal_dev(>
->gt_dev
, " cs[3]=%#10x-%#10x\n", loaddr
, hiaddr
);
207 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_BootCS_Low_Decode
));
208 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_BootCS_High_Decode
));
209 aprint_normal_dev(>
->gt_dev
, " bootcs=%#10x-%#10x\n", loaddr
, hiaddr
);
211 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_PCI0_IO_Low_Decode
));
212 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_PCI0_IO_High_Decode
));
213 aprint_normal_dev(>
->gt_dev
, " pci0io=%#10x-%#10x ", loaddr
, hiaddr
);
215 loaddr
= gt_read(gt
, GT_PCI0_IO_Remap
);
216 aprint_normal("remap=%#010x\n", loaddr
);
218 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_PCI0_Mem0_Low_Decode
));
219 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_PCI0_Mem0_High_Decode
));
220 aprint_normal_dev(>
->gt_dev
, " pci0mem[0]=%#10x-%#10x ", loaddr
, hiaddr
);
222 loaddr
= gt_read(gt
, GT_PCI0_Mem0_Remap_Low
);
223 hiaddr
= gt_read(gt
, GT_PCI0_Mem0_Remap_High
);
224 aprint_normal("remap=%#010x.%#010x\n", hiaddr
, loaddr
);
226 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_PCI0_Mem1_Low_Decode
));
227 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_PCI0_Mem1_High_Decode
));
228 aprint_normal_dev(>
->gt_dev
, " pci0mem[1]=%#10x-%#10x ", loaddr
, hiaddr
);
230 loaddr
= gt_read(gt
, GT_PCI0_Mem1_Remap_Low
);
231 hiaddr
= gt_read(gt
, GT_PCI0_Mem1_Remap_High
);
232 aprint_normal("remap=%#010x.%#010x\n", hiaddr
, loaddr
);
234 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_PCI0_Mem2_Low_Decode
));
235 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_PCI0_Mem2_High_Decode
));
236 aprint_normal_dev(>
->gt_dev
, " pci0mem[2]=%#10x-%#10x ", loaddr
, hiaddr
);
238 loaddr
= gt_read(gt
, GT_PCI0_Mem2_Remap_Low
);
239 hiaddr
= gt_read(gt
, GT_PCI0_Mem2_Remap_High
);
240 aprint_normal("remap=%#010x.%#010x\n", hiaddr
, loaddr
);
242 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_PCI0_Mem3_Low_Decode
));
243 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_PCI0_Mem3_High_Decode
));
244 aprint_normal_dev(>
->gt_dev
, " pci0mem[3]=%#10x-%#10x ", loaddr
, hiaddr
);
246 loaddr
= gt_read(gt
, GT_PCI0_Mem3_Remap_Low
);
247 hiaddr
= gt_read(gt
, GT_PCI0_Mem3_Remap_High
);
248 aprint_normal("remap=%#010x.%#010x\n", hiaddr
, loaddr
);
250 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_PCI1_IO_Low_Decode
));
251 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_PCI1_IO_High_Decode
));
252 aprint_normal_dev(>
->gt_dev
, " pci1io=%#10x-%#10x ", loaddr
, hiaddr
);
254 loaddr
= gt_read(gt
, GT_PCI1_IO_Remap
);
255 aprint_normal("remap=%#010x\n", loaddr
);
257 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_PCI1_Mem0_Low_Decode
));
258 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_PCI1_Mem0_High_Decode
));
259 aprint_normal_dev(>
->gt_dev
, " pci1mem[0]=%#10x-%#10x ", loaddr
, hiaddr
);
261 loaddr
= gt_read(gt
, GT_PCI1_Mem0_Remap_Low
);
262 hiaddr
= gt_read(gt
, GT_PCI1_Mem0_Remap_High
);
263 aprint_normal("remap=%#010x.%#010x\n", hiaddr
, loaddr
);
265 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_PCI1_Mem1_Low_Decode
));
266 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_PCI1_Mem1_High_Decode
));
267 aprint_normal_dev(>
->gt_dev
, " pci1mem[1]=%#10x-%#10x ", loaddr
, hiaddr
);
269 loaddr
= gt_read(gt
, GT_PCI1_Mem1_Remap_Low
);
270 hiaddr
= gt_read(gt
, GT_PCI1_Mem1_Remap_High
);
271 aprint_normal("remap=%#010x.%#010x\n", hiaddr
, loaddr
);
273 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_PCI1_Mem2_Low_Decode
));
274 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_PCI1_Mem2_High_Decode
));
275 aprint_normal_dev(>
->gt_dev
, " pci1mem[2]=%#10x-%#10x ", loaddr
, hiaddr
);
277 loaddr
= gt_read(gt
, GT_PCI1_Mem2_Remap_Low
);
278 hiaddr
= gt_read(gt
, GT_PCI1_Mem2_Remap_High
);
279 aprint_normal("remap=%#010x.%#010x\n", hiaddr
, loaddr
);
281 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_PCI1_Mem3_Low_Decode
));
282 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_PCI1_Mem3_High_Decode
));
283 aprint_normal_dev(>
->gt_dev
, " pci1mem[3]=%#10x-%#10x ", loaddr
, hiaddr
);
285 loaddr
= gt_read(gt
, GT_PCI1_Mem3_Remap_Low
);
286 hiaddr
= gt_read(gt
, GT_PCI1_Mem3_Remap_High
);
287 aprint_normal("remap=%#010x.%#010x\n", hiaddr
, loaddr
);
289 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_Internal_Decode
));
290 aprint_normal_dev(>
->gt_dev
, " internal=%#10x-%#10x\n",
291 loaddr
, loaddr
+256*1024);
293 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_CPU0_Low_Decode
));
294 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_CPU0_High_Decode
));
295 aprint_normal_dev(>
->gt_dev
, " cpu0=%#10x-%#10x\n", loaddr
, hiaddr
);
297 loaddr
= GT_LowAddr_GET(gt_read(gt
, GT_CPU1_Low_Decode
));
298 hiaddr
= GT_HighAddr_GET(gt_read(gt
, GT_CPU1_High_Decode
));
299 aprint_normal_dev(>
->gt_dev
, " cpu1=%#10x-%#10x", loaddr
, hiaddr
);
302 aprint_normal_dev(>
->gt_dev
, "");
304 cpucfg
= gt_read(gt
, GT_CPU_Cfg
);
305 cpucfg
|= GT_CPUCfg_ConfSBDis
; /* per errata #46 */
306 cpucfg
|= GT_CPUCfg_AACKDelay
; /* per restriction #18 */
307 gt_write(gt
, GT_CPU_Cfg
, cpucfg
);
308 if (cpucfg
& GT_CPUCfg_Pipeline
)
309 aprint_normal(" pipeline");
310 if (cpucfg
& GT_CPUCfg_AACKDelay
)
311 aprint_normal(" aack-delay");
312 if (cpucfg
& GT_CPUCfg_RdOOO
)
313 aprint_normal(" read-ooo");
314 if (cpucfg
& GT_CPUCfg_IOSBDis
)
315 aprint_normal(" io-sb-dis");
316 if (cpucfg
& GT_CPUCfg_ConfSBDis
)
317 aprint_normal(" conf-sb-dis");
318 if (cpucfg
& GT_CPUCfg_ClkSync
)
319 aprint_normal(" clk-sync");
324 gt_watchdog_init(gt
);
326 gt_init_interrupt(gt
);
332 gt_comm_intr_enb(gt
);
333 gt_devbus_intr_enb(gt
);
335 gt_watchdog_disable();
336 config_search_ia(gt_cfsearch
, >
->gt_dev
, "gt", NULL
);
337 gt_watchdog_service();
338 gt_watchdog_enable();
342 gt_init_hostid(struct gt_softc
*gt
)
345 hostid
= 1; /* XXX: Used by i2c; needs work -- AKB */
349 gt_init_interrupt(struct gt_softc
*gt
)
351 u_int32_t mppirpts
= GT_MPP_INTERRUPTS
; /* from config */
358 gt_write(gt
, ICR_CIM_LO
, 0);
359 gt_write(gt
, ICR_CIM_HI
, 0);
362 * configure the GPP interrupts:
363 * - set the configured MPP pins in GPP mode
364 * - set the configured GPP pins to input, active low, interrupt enbl
367 printf("%s: mpp cfg ", device_xname(>
->gt_dev
));
368 for (regoff
= GT_MPP_Control0
; regoff
<= GT_MPP_Control3
; regoff
+= 4)
369 printf("%#x ", gt_read(gt
, regoff
));
370 printf(", mppirpts 0x%x\n", mppirpts
);
373 for (regoff
= GT_MPP_Control0
; regoff
<= GT_MPP_Control3
; regoff
+= 4) {
375 for (mppsel
= 0xf; mppsel
; mppsel
<<= 4) {
376 if (mppirpts
& mppbit
)
381 r
= gt_read(gt
, regoff
);
383 gt_write(gt
, regoff
, r
);
387 r
= gt_read(gt
, GT_GPP_IO_Control
);
389 gt_write(gt
, GT_GPP_IO_Control
, r
);
391 r
= gt_read(gt
, GT_GPP_Level_Control
);
393 gt_write(gt
, GT_GPP_Level_Control
, r
);
395 r
= gt_read(gt
, GT_GPP_Interrupt_Mask
);
397 gt_write(gt
, GT_GPP_Interrupt_Mask
, r
);
403 struct gt_softc
*sc
= device_lookup_private(>_cd
, 0);
404 return gt_read(sc
, GT_GPP_Value
); /* XXX */
409 gt_bs_extent_init(struct discovery_bus_space
*bs
, char *name
)
414 if (bs
->bs_nregion
== 0) {
415 bs
->bs_extent
= extent_create(name
, 0xffffffffUL
, 0xffffffffUL
,
416 M_DEVBUF
, NULL
, 0, EX_NOCOALESCE
|EX_WAITOK
);
417 KASSERT(bs
->bs_extent
!= NULL
);
421 * Find the top and bottoms of this bus space.
423 start
= bs
->bs_regions
[0].br_start
;
424 end
= bs
->bs_regions
[0].br_end
;
427 printf("gtpci_bs_extent_init: %s: region %d: %#lx-%#lx\n",
428 name
, 0, bs
->bs_regions
[0].br_start
,
429 bs
->bs_regions
[0].br_end
);
431 for (i
= 1; i
< bs
->bs_nregion
; i
++) {
432 if (bs
->bs_regions
[i
].br_start
< start
)
433 start
= bs
->bs_regions
[i
].br_start
;
434 if (bs
->bs_regions
[i
].br_end
> end
)
435 end
= bs
->bs_regions
[i
].br_end
;
438 printf("gtpci_bs_extent_init: %s: region %d:"
440 name
, i
, bs
->bs_regions
[i
].br_start
,
441 bs
->bs_regions
[i
].br_end
);
445 * Now that we have the top and bottom limits of this
446 * bus space, create the extent map that will manage this
451 printf("gtpci_bs_extent_init: %s: create: %#lx-%#lx\n",
454 bs
->bs_extent
= extent_create(name
, start
, end
, M_DEVBUF
,
455 NULL
, 0, EX_NOCOALESCE
|EX_WAITOK
);
456 KASSERT(bs
->bs_extent
!= NULL
);
458 /* If there was more than one bus space region, then there
459 * might gaps in between them. Allocate the gap so that
460 * they will not be legal addresses in the extent.
462 for (i
= 0; i
< bs
->bs_nregion
&& bs
->bs_nregion
> 1; i
++) {
463 /* Initial start is "infinity" and the inital end is
464 * is the end of this bus region.
467 end
= bs
->bs_regions
[i
].br_end
;
468 /* For each region, if it starts after this region but less
469 * than the saved start, use its start address. If the start
470 * address is one past the end address, then we're done
472 for (j
= 0; j
< bs
->bs_nregion
&& start
> end
+ 1; j
++) {
475 if (bs
->bs_regions
[j
].br_start
> end
&&
476 bs
->bs_regions
[j
].br_start
< start
)
477 start
= bs
->bs_regions
[j
].br_start
;
480 * If we found a gap, allocate it away.
482 if (start
!= ~0UL && start
!= end
+ 1) {
485 printf("gtpci_bs_extent_init: %s: alloc(hole): %#lx-%#lx\n",
486 name
, end
+ 1, start
- 1);
488 error
= extent_alloc_region(bs
->bs_extent
, end
+ 1,
489 start
- (end
+ 1), EX_NOWAIT
);
498 * unknown board, enable everything
500 # define GT_CommUnitIntr_DFLT GT_CommUnitIntr_S0|GT_CommUnitIntr_S1 \
501 |GT_CommUnitIntr_E0|GT_CommUnitIntr_E1 \
504 static const char * const gt_comm_subunit_name
[8] = {
516 gt_comm_intr(void *arg
)
518 struct gt_softc
*gt
= (struct gt_softc
*)arg
;
524 cause
= gt_read(gt
, GT_CommUnitIntr_Cause
);
525 gt_write(gt
, GT_CommUnitIntr_Cause
, ~cause
);
526 addr
= gt_read(gt
, GT_CommUnitIntr_ErrAddr
);
528 printf("%s: Comm Unit irpt, cause %#x addr %#x\n",
529 device_xname(>
->gt_dev
), cause
, addr
);
531 cause
&= GT_CommUnitIntr_DFLT
;
536 for (i
=0; i
<7; i
++) {
538 printf("%s: Comm Unit %s:", device_xname(>
->gt_dev
),
539 gt_comm_subunit_name
[i
]);
554 * gt_comm_intr_init - enable GT-64260 Comm Unit interrupts
557 gt_comm_intr_enb(struct gt_softc
*gt
)
561 cause
= gt_read(gt
, GT_CommUnitIntr_Cause
);
563 gt_write(gt
, GT_CommUnitIntr_Cause
, ~cause
);
564 gt_write(gt
, GT_CommUnitIntr_Mask
, GT_CommUnitIntr_DFLT
);
565 (void)gt_read(gt
, GT_CommUnitIntr_ErrAddr
);
567 intr_establish(IRQ_COMM
, IST_LEVEL
, IPL_VM
, gt_comm_intr
, gt
);
568 printf("%s: Comm Unit irpt at %d\n", device_xname(>
->gt_dev
), IRQ_COMM
);
572 static char *gt_ecc_intr_str
[4] = {
580 gt_ecc_intr(void *arg
)
582 struct gt_softc
*gt
= (struct gt_softc
*)arg
;
591 count
= gt_read(gt
, GT_ECC_Count
);
592 dlo
= gt_read(gt
, GT_ECC_Data_Lo
);
593 dhi
= gt_read(gt
, GT_ECC_Data_Hi
);
594 rec
= gt_read(gt
, GT_ECC_Rec
);
595 calc
= gt_read(gt
, GT_ECC_Calc
);
596 addr
= gt_read(gt
, GT_ECC_Addr
); /* read last! */
597 gt_write(gt
, GT_ECC_Addr
, 0); /* clear irpt */
601 printf("%s: ECC error: %s: "
602 "addr %#x data %#x.%#x rec %#x calc %#x cnt %#x\n",
603 device_xname(>
->gt_dev
), gt_ecc_intr_str
[err
],
604 addr
, dhi
, dlo
, rec
, calc
, count
);
613 * gt_ecc_intr_enb - enable GT-64260 ECC interrupts
616 gt_ecc_intr_enb(struct gt_softc
*gt
)
620 ctl
= gt_read(gt
, GT_ECC_Ctl
);
621 ctl
|= 1 << 16; /* XXX 1-bit threshold == 1 */
622 gt_write(gt
, GT_ECC_Ctl
, ctl
);
623 (void)gt_read(gt
, GT_ECC_Data_Lo
);
624 (void)gt_read(gt
, GT_ECC_Data_Hi
);
625 (void)gt_read(gt
, GT_ECC_Rec
);
626 (void)gt_read(gt
, GT_ECC_Calc
);
627 (void)gt_read(gt
, GT_ECC_Addr
); /* read last! */
628 gt_write(gt
, GT_ECC_Addr
, 0); /* clear irpt */
630 intr_establish(IRQ_ECC
, IST_LEVEL
, IPL_VM
, gt_ecc_intr
, gt
);
631 printf("%s: ECC irpt at %d\n", device_xname(>
->gt_dev
), IRQ_ECC
);
636 #ifndef GT_MPP_WATCHDOG
638 gt_watchdog_init(struct gt_softc
*gt
)
643 omsr
= extintr_disable();
645 printf("%s: watchdog", device_xname(>
->gt_dev
));
648 * handle case where firmware started watchdog
650 r
= gt_read(gt
, GT_WDOG_Config
);
651 printf(" status %#x,%#x:",
652 r
, gt_read(gt
, GT_WDOG_Value
));
653 if ((r
& 0x80000000) != 0) {
654 gt_watchdog_sc
= gt
; /* enabled */
655 gt_watchdog_state
= 1;
656 printf(" firmware-enabled\n");
657 gt_watchdog_service();
660 printf(" firmware-disabled\n");
663 extintr_restore(omsr
);
666 #else /* GT_MPP_WATCHDOG */
669 gt_watchdog_init(struct gt_softc
*gt
)
671 u_int32_t mpp_watchdog
= GT_MPP_WATCHDOG
; /* from config */
679 printf("%s: watchdog", device_xname(>
->gt_dev
));
681 if (mpp_watchdog
== 0) {
682 printf(" not configured\n");
687 if (afw_wdog_ctl
== 1) {
688 printf(" admin disabled\n");
693 omsr
= extintr_disable();
696 * if firmware started watchdog, we disable and start
697 * from scratch to get it in a known state.
699 * on GT-64260A we always see 0xffffffff
700 * in both the GT_WDOG_Config_Enb and GT_WDOG_Value regsiters.
701 * Use AFW-supplied flag to determine run state.
703 r
= gt_read(gt
, GT_WDOG_Config
);
705 if ((r
& GT_WDOG_Config_Enb
) != 0) {
706 gt_write(gt
, GT_WDOG_Config
,
707 (GT_WDOG_Config_Ctl1a
| GT_WDOG_Preset_DFLT
));
708 gt_write(gt
, GT_WDOG_Config
,
709 (GT_WDOG_Config_Ctl1b
| GT_WDOG_Preset_DFLT
));
713 if (afw_wdog_state
== 1) {
714 gt_write(gt
, GT_WDOG_Config
,
715 (GT_WDOG_Config_Ctl1a
| GT_WDOG_Preset_DFLT
));
716 gt_write(gt
, GT_WDOG_Config
,
717 (GT_WDOG_Config_Ctl1b
| GT_WDOG_Preset_DFLT
));
723 * "the watchdog timer can be activated only after
724 * configuring two MPP pins to act as WDE and WDNMI"
728 for (regoff
= GT_MPP_Control0
; regoff
<= GT_MPP_Control3
; regoff
+= 4) {
729 if ((mpp_watchdog
& cfgbits
) == cfgbits
) {
735 if ((mpp_watchdog
& cfgbits
) == cfgbits
) {
740 cfgbits
<<= 6; /* skip unqualified bits */
743 printf(" config error\n");
744 extintr_restore(omsr
);
748 r
= gt_read(gt
, regoff
);
751 gt_write(gt
, regoff
, r
);
752 printf(" mpp %#x %#x", regoff
, mppbits
);
754 gt_write(gt
, GT_WDOG_Value
, GT_WDOG_NMI_DFLT
);
756 gt_write(gt
, GT_WDOG_Config
,
757 (GT_WDOG_Config_Ctl1a
| GT_WDOG_Preset_DFLT
));
758 gt_write(gt
, GT_WDOG_Config
,
759 (GT_WDOG_Config_Ctl1b
| GT_WDOG_Preset_DFLT
));
762 r
= gt_read(gt
, GT_WDOG_Config
),
763 printf(" status %#x,%#x: %s",
764 r
, gt_read(gt
, GT_WDOG_Value
),
765 ((r
& GT_WDOG_Config_Enb
) != 0) ? "enabled" : "botch");
767 if ((r
& GT_WDOG_Config_Enb
) != 0) {
770 gt_watchdog_sc
= gt
; /* enabled */
771 gt_watchdog_state
= 1;
774 * configure EMCP in HID0 in case it's not already set
776 __asm
volatile("sync");
777 hid0
= mfspr(SPR_HID0
);
778 if ((hid0
& HID0_EMCP
) == 0) {
780 __asm
volatile("sync"); mtspr(SPR_HID0
, hid0
);
781 __asm
volatile("sync"); hid0
= mfspr(SPR_HID0
);
782 printf(", EMCP set");
787 extintr_restore(omsr
);
789 #endif /* GT_MPP_WATCHDOG */
792 u_int32_t
hid0_print(void);
797 __asm
volatile("sync; mfspr %0,1008;" : "=r"(hid0
));
798 printf("hid0: %#x\n", hid0
);
804 gt_watchdog_enable(void)
809 omsr
= extintr_disable();
811 if ((gt
!= NULL
) && (gt_watchdog_state
== 0)) {
812 gt_watchdog_state
= 1;
814 gt_write(gt
, GT_WDOG_Config
,
815 (GT_WDOG_Config_Ctl1a
| GT_WDOG_Preset_DFLT
));
816 gt_write(gt
, GT_WDOG_Config
,
817 (GT_WDOG_Config_Ctl1b
| GT_WDOG_Preset_DFLT
));
819 extintr_restore(omsr
);
823 gt_watchdog_disable(void)
828 omsr
= extintr_disable();
830 if ((gt
!= NULL
) && (gt_watchdog_state
!= 0)) {
831 gt_watchdog_state
= 0;
833 gt_write(gt
, GT_WDOG_Config
,
834 (GT_WDOG_Config_Ctl1a
| GT_WDOG_Preset_DFLT
));
835 gt_write(gt
, GT_WDOG_Config
,
836 (GT_WDOG_Config_Ctl1b
| GT_WDOG_Preset_DFLT
));
838 extintr_restore(omsr
);
842 int inhibit_watchdog_service
= 0;
845 gt_watchdog_service(void)
847 struct gt_softc
*gt
= gt_watchdog_sc
;
849 if ((gt
== NULL
) || (gt_watchdog_state
== 0))
850 return; /* not enabled */
852 if (inhibit_watchdog_service
)
856 gt_write(gt
, GT_WDOG_Config
,
857 (GT_WDOG_Config_Ctl2a
| GT_WDOG_Preset_DFLT
));
858 gt_write(gt
, GT_WDOG_Config
,
859 (GT_WDOG_Config_Ctl2b
| GT_WDOG_Preset_DFLT
));
863 * gt_watchdog_reset - force a watchdog reset using Preset_VAL=0
866 gt_watchdog_reset(void)
868 struct gt_softc
*gt
= gt_watchdog_sc
;
871 (void)extintr_disable();
872 r
= gt_read(gt
, GT_WDOG_Config
);
873 gt_write(gt
, GT_WDOG_Config
, (GT_WDOG_Config_Ctl1a
| 0));
874 gt_write(gt
, GT_WDOG_Config
, (GT_WDOG_Config_Ctl1b
| 0));
875 if ((r
& GT_WDOG_Config_Enb
) != 0) {
877 * was enabled, we just toggled it off, toggle on again
879 gt_write(gt
, GT_WDOG_Config
,
880 (GT_WDOG_Config_Ctl1a
| 0));
881 gt_write(gt
, GT_WDOG_Config
,
882 (GT_WDOG_Config_Ctl1b
| 0));
888 gt_devbus_intr(void *arg
)
890 struct gt_softc
*gt
= (struct gt_softc
*)arg
;
894 cause
= gt_read(gt
, GT_DEVBUS_ICAUSE
);
895 addr
= gt_read(gt
, GT_DEVBUS_ERR_ADDR
);
896 gt_write(gt
, GT_DEVBUS_ICAUSE
, 0); /* clear irpt */
898 if (cause
& GT_DEVBUS_DBurstErr
) {
899 printf("%s: Device Bus error: burst violation",
900 device_xname(>
->gt_dev
));
901 if ((cause
& GT_DEVBUS_Sel
) == 0)
902 printf(", addr %#x", addr
);
905 if (cause
& GT_DEVBUS_DRdyErr
) {
906 printf("%s: Device Bus error: ready timer expired",
907 device_xname(>
->gt_dev
));
908 if ((cause
& GT_DEVBUS_Sel
) != 0)
909 printf(", addr %#x\n", addr
);
917 * gt_ecc_intr_enb - enable GT-64260 ECC interrupts
920 gt_devbus_intr_enb(struct gt_softc
*gt
)
922 gt_write(gt
, GT_DEVBUS_IMASK
,
923 GT_DEVBUS_DBurstErr
|GT_DEVBUS_DRdyErr
);
924 (void)gt_read(gt
, GT_DEVBUS_ERR_ADDR
); /* clear addr */
925 gt_write(gt
, GT_ECC_Addr
, 0); /* clear irpt */
927 intr_establish(IRQ_DEV
, IST_LEVEL
, IPL_VM
, gt_devbus_intr
, gt
);
928 printf("%s: Device Bus Error irpt at %d\n",
929 device_xname(>
->gt_dev
), IRQ_DEV
);
940 struct gt_softc
* const gt
= (struct gt_softc
*) parent
;
946 data
= gt_read(gt
, ETH_ESMIR
);
947 } while ((data
& ETH_ESMIR_Busy
) && count
-- > 0);
950 printf("%s: mii read for phy %d reg %d busied out\n",
951 device_xname(child
), phy
, reg
);
952 return ETH_ESMIR_Value_GET(data
);
955 gt_write(gt
, ETH_ESMIR
, ETH_ESMIR_READ(phy
, reg
));
960 data
= gt_read(gt
, ETH_ESMIR
);
961 } while ((data
& ETH_ESMIR_ReadValid
) == 0 && count
-- > 0);
964 printf("%s: mii read for phy %d reg %d timed out\n",
965 device_xname(child
), phy
, reg
);
966 #if defined(GTMIIDEBUG)
967 printf("%s: mii_read(%d, %d): %#x data %#x\n",
968 device_xname(child
), phy
, reg
,
969 data
, ETH_ESMIR_Value_GET(data
));
971 return ETH_ESMIR_Value_GET(data
);
981 struct gt_softc
* const gt
= (struct gt_softc
*) parent
;
987 data
= gt_read(gt
, ETH_ESMIR
);
988 } while ((data
& ETH_ESMIR_Busy
) && count
-- > 0);
991 printf("%s: mii write for phy %d reg %d busied out (busy)\n",
992 device_xname(child
), phy
, reg
);
996 gt_write(gt
, ETH_ESMIR
,
997 ETH_ESMIR_WRITE(phy
, reg
, value
));
1002 data
= gt_read(gt
, ETH_ESMIR
);
1003 } while ((data
& ETH_ESMIR_Busy
) && count
-- > 0);
1006 printf("%s: mii write for phy %d reg %d timed out\n",
1007 device_xname(child
), phy
, reg
);
1008 #if defined(GTMIIDEBUG)
1009 printf("%s: mii_write(%d, %d, %#x)\n",
1010 device_xname(child
), phy
, reg
, value
);
1015 * Since the memory and pci spaces are mapped 1:1 we just need
1016 * to return unity here
1019 gt_dma_phys_to_bus_mem(bus_dma_tag_t t
, bus_addr_t a
)
1024 gt_dma_bus_mem_to_phys(bus_dma_tag_t t
, bus_addr_t a
)