[brcm47xx] fix ssb irq setup, allows ubsec_ssb devices on Asus WL500GP and Netgear...
[openwrt.git] / target / linux / brcm47xx / patches-2.6.28 / 816-ssb_fix_irq_setup.patch
1 the current ssb irq setup (in ssb_mipscore_init) have some problem :
2 it configure some device on some irq without checking that the irq is not taken by an other device.
3
4 For example in my case PCI host is on irq 0 and IPSEC on irq 3.
5 The current code :
6 - store in dev->irq that IPSEC irq is 3+2
7 - do a set_irq 0->3 on PCI host
8
9 But now IPSEC irq is not routed anymore to the mips code and dev->irq is wrong. This cause problem described in [1].
10
11 This patch try to solve the problem by making set_irq configure the device we want to take the irq on the shared irq0.
12 The previous example become :
13 - store in dev->irq that IPSEC irq is 3+2
14 - do a set_irq 0->3 on PCI host :
15 - irq 3 is already taken by IPSEC. do a set_irq 3->0 on IPSEC
16
17
18 I also added some code to print the irq configuration before and after irq setup to allow easier debugging. And I add extra checking in ssb_mips_irq to report device without irq or device with not routed irq.
19
20
21 [1] http://www.danm.de/files/src/bcm5365p/REPORTED_DEVICES
22
23 Signed-off-by: Matthieu CASTET <castet.matthieu@free.fr>
24 Index: linux-2.6/drivers/ssb/driver_mipscore.c
25 ===================================================================
26 --- linux-2.6.orig/drivers/ssb/driver_mipscore.c 2009-05-25 19:47:26.000000000 +0200
27 +++ linux-2.6/drivers/ssb/driver_mipscore.c 2009-05-25 19:47:42.000000000 +0200
28 @@ -49,29 +49,54 @@
29
30 static inline u32 ssb_irqflag(struct ssb_device *dev)
31 {
32 - return ssb_read32(dev, SSB_TPSFLAG) & SSB_TPSFLAG_BPFLAG;
33 + u32 tpsflag = ssb_read32(dev, SSB_TPSFLAG);
34 + if (tpsflag)
35 + return ssb_read32(dev, SSB_TPSFLAG) & SSB_TPSFLAG_BPFLAG;
36 + else
37 + /* not irq supported */
38 + return 0x3f;
39 +}
40 +
41 +static struct ssb_device *find_device(struct ssb_device *rdev, int irqflag)
42 +{
43 + struct ssb_bus *bus = rdev->bus;
44 + int i;
45 + for (i = 0; i < bus->nr_devices; i++) {
46 + struct ssb_device *dev;
47 + dev = &(bus->devices[i]);
48 + if (ssb_irqflag(dev) == irqflag)
49 + return dev;
50 + }
51 + return NULL;
52 }
53
54 /* Get the MIPS IRQ assignment for a specified device.
55 * If unassigned, 0 is returned.
56 + * If disabled, 5 is returned.
57 + * If not supported, 6 is returned.
58 */
59 unsigned int ssb_mips_irq(struct ssb_device *dev)
60 {
61 struct ssb_bus *bus = dev->bus;
62 + struct ssb_device *mdev = bus->mipscore.dev;
63 u32 irqflag;
64 u32 ipsflag;
65 u32 tmp;
66 unsigned int irq;
67
68 irqflag = ssb_irqflag(dev);
69 + if (irqflag == 0x3f)
70 + return 6;
71 ipsflag = ssb_read32(bus->mipscore.dev, SSB_IPSFLAG);
72 for (irq = 1; irq <= 4; irq++) {
73 tmp = ((ipsflag & ipsflag_irq_mask[irq]) >> ipsflag_irq_shift[irq]);
74 if (tmp == irqflag)
75 break;
76 }
77 - if (irq == 5)
78 - irq = 0;
79 + if (irq == 5) {
80 + if ((1 << irqflag) & ssb_read32(mdev, SSB_INTVEC))
81 + irq = 0;
82 + }
83
84 return irq;
85 }
86 @@ -97,25 +122,56 @@
87 struct ssb_device *mdev = bus->mipscore.dev;
88 u32 irqflag = ssb_irqflag(dev);
89
90 + BUG_ON(oldirq == 6);
91 +
92 dev->irq = irq + 2;
93
94 - ssb_dprintk(KERN_INFO PFX
95 - "set_irq: core 0x%04x, irq %d => %d\n",
96 - dev->id.coreid, oldirq, irq);
97 /* clear the old irq */
98 if (oldirq == 0)
99 ssb_write32(mdev, SSB_INTVEC, (~(1 << irqflag) & ssb_read32(mdev, SSB_INTVEC)));
100 - else
101 + else if (oldirq != 5)
102 clear_irq(bus, oldirq);
103
104 /* assign the new one */
105 if (irq == 0) {
106 ssb_write32(mdev, SSB_INTVEC, ((1 << irqflag) | ssb_read32(mdev, SSB_INTVEC)));
107 } else {
108 + u32 ipsflag = ssb_read32(mdev, SSB_IPSFLAG);
109 + if ((ipsflag & ipsflag_irq_mask[irq]) != ipsflag_irq_mask[irq]) {
110 + u32 oldipsflag = (ipsflag & ipsflag_irq_mask[irq]) >> ipsflag_irq_shift[irq];
111 + struct ssb_device *olddev = find_device(dev, oldipsflag);
112 + if (olddev)
113 + set_irq(olddev, 0);
114 + }
115 irqflag <<= ipsflag_irq_shift[irq];
116 - irqflag |= (ssb_read32(mdev, SSB_IPSFLAG) & ~ipsflag_irq_mask[irq]);
117 + irqflag |= (ipsflag & ~ipsflag_irq_mask[irq]);
118 ssb_write32(mdev, SSB_IPSFLAG, irqflag);
119 }
120 + ssb_dprintk(KERN_INFO PFX
121 + "set_irq: core 0x%04x, irq %d => %d\n",
122 + dev->id.coreid, oldirq+2, irq+2);
123 +}
124 +
125 +static void print_irq(struct ssb_device *dev, unsigned int irq)
126 +{
127 + int i;
128 + static const char *irq_name[] = {"2(S)", "3", "4", "5", "6", "D", "I"};
129 + ssb_dprintk(KERN_INFO PFX
130 + "core 0x%04x, irq :", dev->id.coreid);
131 + for (i = 0; i <= 6; i++) {
132 + ssb_dprintk(" %s%s", irq_name[i], i==irq?"*":" ");
133 + }
134 + ssb_dprintk("\n");
135 +}
136 +
137 +static void dump_irq(struct ssb_bus *bus)
138 +{
139 + int i;
140 + for (i = 0; i < bus->nr_devices; i++) {
141 + struct ssb_device *dev;
142 + dev = &(bus->devices[i]);
143 + print_irq(dev, ssb_mips_irq(dev));
144 + }
145 }
146
147 static void ssb_mips_serial_init(struct ssb_mipscore *mcore)
148 @@ -195,18 +251,26 @@
149 else if (bus->chipco.dev)
150 ssb_chipco_timing_init(&bus->chipco, ns);
151
152 + dump_irq(bus);
153 /* Assign IRQs to all cores on the bus, start with irq line 2, because serial usually takes 1 */
154 for (irq = 2, i = 0; i < bus->nr_devices; i++) {
155 + int mips_irq;
156 dev = &(bus->devices[i]);
157 - dev->irq = ssb_mips_irq(dev) + 2;
158 + mips_irq = ssb_mips_irq(dev);
159 + if (mips_irq > 4)
160 + dev->irq = 0;
161 + else
162 + dev->irq = mips_irq + 2;
163 + if (dev->irq > 5)
164 + continue;
165 switch (dev->id.coreid) {
166 case SSB_DEV_USB11_HOST:
167 /* shouldn't need a separate irq line for non-4710, most of them have a proper
168 * external usb controller on the pci */
169 if ((bus->chip_id == 0x4710) && (irq <= 4)) {
170 set_irq(dev, irq++);
171 - break;
172 }
173 + break;
174 /* fallthrough */
175 case SSB_DEV_PCI:
176 case SSB_DEV_ETHERNET:
177 @@ -220,6 +284,8 @@
178 }
179 }
180 }
181 + ssb_dprintk(KERN_INFO PFX "after irq reconfiguration\n");
182 + dump_irq(bus);
183
184 ssb_mips_serial_init(mcore);
185 ssb_mips_flash_detect(mcore);
This page took 0.046235 seconds and 5 git commands to generate.