brcm47xx: update bcma and ssb to master-2011-07-21
[openwrt/openwrt.git] / target / linux / brcm47xx / patches-3.0 / 0001-bcma-move-parsing-of-EEPROM-into-own-function.patch
1 From e6defe46ea936ebb309c9cab4f7fd14bdc0c5416 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sat, 11 Jun 2011 16:47:38 +0200
4 Subject: [PATCH 01/22] bcma: move parsing of EEPROM into own function.
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 Move the parsing of the EEPROM data in scan function for one core into
10 an own function. Now we are able to use it in some other scan function
11 as well.
12
13 Acked-by: Rafał Miłecki <zajec5@gmail.com>
14 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
15 ---
16 drivers/bcma/scan.c | 230 ++++++++++++++++++++++++++-------------------------
17 1 files changed, 118 insertions(+), 112 deletions(-)
18
19 --- a/drivers/bcma/scan.c
20 +++ b/drivers/bcma/scan.c
21 @@ -200,16 +200,124 @@ static s32 bcma_erom_get_addr_desc(struc
22 return addrl;
23 }
24
25 +static int bcma_get_next_core(struct bcma_bus *bus, u32 __iomem **eromptr,
26 + struct bcma_device *core)
27 +{
28 + s32 tmp;
29 + u8 i, j;
30 + s32 cia, cib;
31 + u8 ports[2], wrappers[2];
32 +
33 + /* get CIs */
34 + cia = bcma_erom_get_ci(bus, eromptr);
35 + if (cia < 0) {
36 + bcma_erom_push_ent(eromptr);
37 + if (bcma_erom_is_end(bus, eromptr))
38 + return -ESPIPE;
39 + return -EILSEQ;
40 + }
41 + cib = bcma_erom_get_ci(bus, eromptr);
42 + if (cib < 0)
43 + return -EILSEQ;
44 +
45 + /* parse CIs */
46 + core->id.class = (cia & SCAN_CIA_CLASS) >> SCAN_CIA_CLASS_SHIFT;
47 + core->id.id = (cia & SCAN_CIA_ID) >> SCAN_CIA_ID_SHIFT;
48 + core->id.manuf = (cia & SCAN_CIA_MANUF) >> SCAN_CIA_MANUF_SHIFT;
49 + ports[0] = (cib & SCAN_CIB_NMP) >> SCAN_CIB_NMP_SHIFT;
50 + ports[1] = (cib & SCAN_CIB_NSP) >> SCAN_CIB_NSP_SHIFT;
51 + wrappers[0] = (cib & SCAN_CIB_NMW) >> SCAN_CIB_NMW_SHIFT;
52 + wrappers[1] = (cib & SCAN_CIB_NSW) >> SCAN_CIB_NSW_SHIFT;
53 + core->id.rev = (cib & SCAN_CIB_REV) >> SCAN_CIB_REV_SHIFT;
54 +
55 + if (((core->id.manuf == BCMA_MANUF_ARM) &&
56 + (core->id.id == 0xFFF)) ||
57 + (ports[1] == 0)) {
58 + bcma_erom_skip_component(bus, eromptr);
59 + return -ENXIO;
60 + }
61 +
62 + /* check if component is a core at all */
63 + if (wrappers[0] + wrappers[1] == 0) {
64 + /* we could save addrl of the router
65 + if (cid == BCMA_CORE_OOB_ROUTER)
66 + */
67 + bcma_erom_skip_component(bus, eromptr);
68 + return -ENXIO;
69 + }
70 +
71 + if (bcma_erom_is_bridge(bus, eromptr)) {
72 + bcma_erom_skip_component(bus, eromptr);
73 + return -ENXIO;
74 + }
75 +
76 + /* get & parse master ports */
77 + for (i = 0; i < ports[0]; i++) {
78 + u32 mst_port_d = bcma_erom_get_mst_port(bus, eromptr);
79 + if (mst_port_d < 0)
80 + return -EILSEQ;
81 + }
82 +
83 + /* get & parse slave ports */
84 + for (i = 0; i < ports[1]; i++) {
85 + for (j = 0; ; j++) {
86 + tmp = bcma_erom_get_addr_desc(bus, eromptr,
87 + SCAN_ADDR_TYPE_SLAVE, i);
88 + if (tmp < 0) {
89 + /* no more entries for port _i_ */
90 + /* pr_debug("erom: slave port %d "
91 + * "has %d descriptors\n", i, j); */
92 + break;
93 + } else {
94 + if (i == 0 && j == 0)
95 + core->addr = tmp;
96 + }
97 + }
98 + }
99 +
100 + /* get & parse master wrappers */
101 + for (i = 0; i < wrappers[0]; i++) {
102 + for (j = 0; ; j++) {
103 + tmp = bcma_erom_get_addr_desc(bus, eromptr,
104 + SCAN_ADDR_TYPE_MWRAP, i);
105 + if (tmp < 0) {
106 + /* no more entries for port _i_ */
107 + /* pr_debug("erom: master wrapper %d "
108 + * "has %d descriptors\n", i, j); */
109 + break;
110 + } else {
111 + if (i == 0 && j == 0)
112 + core->wrap = tmp;
113 + }
114 + }
115 + }
116 +
117 + /* get & parse slave wrappers */
118 + for (i = 0; i < wrappers[1]; i++) {
119 + u8 hack = (ports[1] == 1) ? 0 : 1;
120 + for (j = 0; ; j++) {
121 + tmp = bcma_erom_get_addr_desc(bus, eromptr,
122 + SCAN_ADDR_TYPE_SWRAP, i + hack);
123 + if (tmp < 0) {
124 + /* no more entries for port _i_ */
125 + /* pr_debug("erom: master wrapper %d "
126 + * has %d descriptors\n", i, j); */
127 + break;
128 + } else {
129 + if (wrappers[0] == 0 && !i && !j)
130 + core->wrap = tmp;
131 + }
132 + }
133 + }
134 + return 0;
135 +}
136 +
137 int bcma_bus_scan(struct bcma_bus *bus)
138 {
139 u32 erombase;
140 u32 __iomem *eromptr, *eromend;
141
142 - s32 cia, cib;
143 - u8 ports[2], wrappers[2];
144 -
145 s32 tmp;
146 - u8 i, j;
147
148 int err;
149
150 @@ -236,112 +344,13 @@ int bcma_bus_scan(struct bcma_bus *bus)
151 INIT_LIST_HEAD(&core->list);
152 core->bus = bus;
153
154 - /* get CIs */
155 - cia = bcma_erom_get_ci(bus, &eromptr);
156 - if (cia < 0) {
157 - bcma_erom_push_ent(&eromptr);
158 - if (bcma_erom_is_end(bus, &eromptr))
159 - break;
160 - err= -EILSEQ;
161 - goto out;
162 - }
163 - cib = bcma_erom_get_ci(bus, &eromptr);
164 - if (cib < 0) {
165 - err= -EILSEQ;
166 - goto out;
167 - }
168 -
169 - /* parse CIs */
170 - core->id.class = (cia & SCAN_CIA_CLASS) >> SCAN_CIA_CLASS_SHIFT;
171 - core->id.id = (cia & SCAN_CIA_ID) >> SCAN_CIA_ID_SHIFT;
172 - core->id.manuf = (cia & SCAN_CIA_MANUF) >> SCAN_CIA_MANUF_SHIFT;
173 - ports[0] = (cib & SCAN_CIB_NMP) >> SCAN_CIB_NMP_SHIFT;
174 - ports[1] = (cib & SCAN_CIB_NSP) >> SCAN_CIB_NSP_SHIFT;
175 - wrappers[0] = (cib & SCAN_CIB_NMW) >> SCAN_CIB_NMW_SHIFT;
176 - wrappers[1] = (cib & SCAN_CIB_NSW) >> SCAN_CIB_NSW_SHIFT;
177 - core->id.rev = (cib & SCAN_CIB_REV) >> SCAN_CIB_REV_SHIFT;
178 -
179 - if (((core->id.manuf == BCMA_MANUF_ARM) &&
180 - (core->id.id == 0xFFF)) ||
181 - (ports[1] == 0)) {
182 - bcma_erom_skip_component(bus, &eromptr);
183 + err = bcma_get_next_core(bus, &eromptr, core);
184 + if (err == -ENXIO)
185 continue;
186 - }
187 -
188 - /* check if component is a core at all */
189 - if (wrappers[0] + wrappers[1] == 0) {
190 - /* we could save addrl of the router
191 - if (cid == BCMA_CORE_OOB_ROUTER)
192 - */
193 - bcma_erom_skip_component(bus, &eromptr);
194 - continue;
195 - }
196 -
197 - if (bcma_erom_is_bridge(bus, &eromptr)) {
198 - bcma_erom_skip_component(bus, &eromptr);
199 - continue;
200 - }
201 -
202 - /* get & parse master ports */
203 - for (i = 0; i < ports[0]; i++) {
204 - u32 mst_port_d = bcma_erom_get_mst_port(bus, &eromptr);
205 - if (mst_port_d < 0) {
206 - err= -EILSEQ;
207 - goto out;
208 - }
209 - }
210 -
211 - /* get & parse slave ports */
212 - for (i = 0; i < ports[1]; i++) {
213 - for (j = 0; ; j++) {
214 - tmp = bcma_erom_get_addr_desc(bus, &eromptr,
215 - SCAN_ADDR_TYPE_SLAVE, i);
216 - if (tmp < 0) {
217 - /* no more entries for port _i_ */
218 - /* pr_debug("erom: slave port %d "
219 - * "has %d descriptors\n", i, j); */
220 - break;
221 - } else {
222 - if (i == 0 && j == 0)
223 - core->addr = tmp;
224 - }
225 - }
226 - }
227 -
228 - /* get & parse master wrappers */
229 - for (i = 0; i < wrappers[0]; i++) {
230 - for (j = 0; ; j++) {
231 - tmp = bcma_erom_get_addr_desc(bus, &eromptr,
232 - SCAN_ADDR_TYPE_MWRAP, i);
233 - if (tmp < 0) {
234 - /* no more entries for port _i_ */
235 - /* pr_debug("erom: master wrapper %d "
236 - * "has %d descriptors\n", i, j); */
237 - break;
238 - } else {
239 - if (i == 0 && j == 0)
240 - core->wrap = tmp;
241 - }
242 - }
243 - }
244 -
245 - /* get & parse slave wrappers */
246 - for (i = 0; i < wrappers[1]; i++) {
247 - u8 hack = (ports[1] == 1) ? 0 : 1;
248 - for (j = 0; ; j++) {
249 - tmp = bcma_erom_get_addr_desc(bus, &eromptr,
250 - SCAN_ADDR_TYPE_SWRAP, i + hack);
251 - if (tmp < 0) {
252 - /* no more entries for port _i_ */
253 - /* pr_debug("erom: master wrapper %d "
254 - * has %d descriptors\n", i, j); */
255 - break;
256 - } else {
257 - if (wrappers[0] == 0 && !i && !j)
258 - core->wrap = tmp;
259 - }
260 - }
261 - }
262 + else if (err == -ESPIPE)
263 + break;
264 + else if (err < 0)
265 + return err;
266
267 pr_info("Core %d found: %s "
268 "(manuf 0x%03X, id 0x%03X, rev 0x%02X, class 0x%X)\n",
269 @@ -351,9 +360,6 @@ int bcma_bus_scan(struct bcma_bus *bus)
270
271 core->core_index = bus->nr_cores++;
272 list_add(&core->list, &bus->cores);
273 - continue;
274 -out:
275 - return err;
276 }
277
278 return 0;