This source file includes following definitions.
- pccard_read_tuple
- pccard_loop_tuple
- pcmcia_io_cfg_data_width
- pcmcia_do_loop_config
- pcmcia_loop_config
- pcmcia_do_loop_tuple
- pcmcia_loop_tuple
- pcmcia_do_get_tuple
- pcmcia_get_tuple
- pcmcia_do_get_mac
- pcmcia_get_mac_from_cis
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/netdevice.h>
17
18 #include <pcmcia/cisreg.h>
19 #include <pcmcia/cistpl.h>
20 #include <pcmcia/ss.h>
21 #include <pcmcia/ds.h>
22 #include "cs_internal.h"
23
24
25
26
27
28
29
30
31
32
33
34 int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function,
35 cisdata_t code, void *parse)
36 {
37 tuple_t tuple;
38 cisdata_t *buf;
39 int ret;
40
41 buf = kmalloc(256, GFP_KERNEL);
42 if (buf == NULL) {
43 dev_warn(&s->dev, "no memory to read tuple\n");
44 return -ENOMEM;
45 }
46 tuple.DesiredTuple = code;
47 tuple.Attributes = 0;
48 if (function == BIND_FN_ALL)
49 tuple.Attributes = TUPLE_RETURN_COMMON;
50 ret = pccard_get_first_tuple(s, function, &tuple);
51 if (ret != 0)
52 goto done;
53 tuple.TupleData = buf;
54 tuple.TupleOffset = 0;
55 tuple.TupleDataMax = 255;
56 ret = pccard_get_tuple_data(s, &tuple);
57 if (ret != 0)
58 goto done;
59 ret = pcmcia_parse_tuple(&tuple, parse);
60 done:
61 kfree(buf);
62 return ret;
63 }
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81 int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function,
82 cisdata_t code, cisparse_t *parse, void *priv_data,
83 int (*loop_tuple) (tuple_t *tuple,
84 cisparse_t *parse,
85 void *priv_data))
86 {
87 tuple_t tuple;
88 cisdata_t *buf;
89 int ret;
90
91 buf = kzalloc(256, GFP_KERNEL);
92 if (buf == NULL) {
93 dev_warn(&s->dev, "no memory to read tuple\n");
94 return -ENOMEM;
95 }
96
97 tuple.TupleData = buf;
98 tuple.TupleDataMax = 255;
99 tuple.TupleOffset = 0;
100 tuple.DesiredTuple = code;
101 tuple.Attributes = 0;
102
103 ret = pccard_get_first_tuple(s, function, &tuple);
104 while (!ret) {
105 if (pccard_get_tuple_data(s, &tuple))
106 goto next_entry;
107
108 if (parse)
109 if (pcmcia_parse_tuple(&tuple, parse))
110 goto next_entry;
111
112 ret = loop_tuple(&tuple, parse, priv_data);
113 if (!ret)
114 break;
115
116 next_entry:
117 ret = pccard_get_next_tuple(s, function, &tuple);
118 }
119
120 kfree(buf);
121 return ret;
122 }
123
124
125
126
127
128 static int pcmcia_io_cfg_data_width(unsigned int flags)
129 {
130 if (!(flags & CISTPL_IO_8BIT))
131 return IO_DATA_PATH_WIDTH_16;
132 if (!(flags & CISTPL_IO_16BIT))
133 return IO_DATA_PATH_WIDTH_8;
134 return IO_DATA_PATH_WIDTH_AUTO;
135 }
136
137
138 struct pcmcia_cfg_mem {
139 struct pcmcia_device *p_dev;
140 int (*conf_check) (struct pcmcia_device *p_dev, void *priv_data);
141 void *priv_data;
142 cisparse_t parse;
143 cistpl_cftable_entry_t dflt;
144 };
145
146
147
148
149
150
151
152
153 static int pcmcia_do_loop_config(tuple_t *tuple, cisparse_t *parse, void *priv)
154 {
155 struct pcmcia_cfg_mem *cfg_mem = priv;
156 struct pcmcia_device *p_dev = cfg_mem->p_dev;
157 cistpl_cftable_entry_t *cfg = &parse->cftable_entry;
158 cistpl_cftable_entry_t *dflt = &cfg_mem->dflt;
159 unsigned int flags = p_dev->config_flags;
160 unsigned int vcc = p_dev->socket->socket.Vcc;
161
162 dev_dbg(&p_dev->dev, "testing configuration %x, autoconf %x\n",
163 cfg->index, flags);
164
165
166 cfg_mem->p_dev->config_index = cfg->index;
167 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
168 cfg_mem->dflt = *cfg;
169
170
171 if (flags & CONF_AUTO_CHECK_VCC) {
172 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
173 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
174 return -ENODEV;
175 } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
176 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000)
177 return -ENODEV;
178 }
179 }
180
181
182 if (flags & CONF_AUTO_SET_VPP) {
183 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
184 p_dev->vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
185 else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
186 p_dev->vpp =
187 dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
188 }
189
190
191 if ((flags & CONF_AUTO_AUDIO) && (cfg->flags & CISTPL_CFTABLE_AUDIO))
192 p_dev->config_flags |= CONF_ENABLE_SPKR;
193
194
195
196 if (flags & CONF_AUTO_SET_IO) {
197 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
198 int i = 0;
199
200 p_dev->resource[0]->start = p_dev->resource[0]->end = 0;
201 p_dev->resource[1]->start = p_dev->resource[1]->end = 0;
202 if (io->nwin == 0)
203 return -ENODEV;
204
205 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
206 p_dev->resource[0]->flags |=
207 pcmcia_io_cfg_data_width(io->flags);
208 if (io->nwin > 1) {
209
210
211
212 i = (io->win[1].len > io->win[0].len);
213 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
214 p_dev->resource[1]->start = io->win[1-i].base;
215 p_dev->resource[1]->end = io->win[1-i].len;
216 }
217 p_dev->resource[0]->start = io->win[i].base;
218 p_dev->resource[0]->end = io->win[i].len;
219 p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
220 }
221
222
223 if (flags & CONF_AUTO_SET_IOMEM) {
224
225 cistpl_mem_t *mem = (cfg->mem.nwin) ? &cfg->mem : &dflt->mem;
226
227 p_dev->resource[2]->start = p_dev->resource[2]->end = 0;
228 if (mem->nwin == 0)
229 return -ENODEV;
230
231 p_dev->resource[2]->start = mem->win[0].host_addr;
232 p_dev->resource[2]->end = mem->win[0].len;
233 if (p_dev->resource[2]->end < 0x1000)
234 p_dev->resource[2]->end = 0x1000;
235 p_dev->card_addr = mem->win[0].card_addr;
236 }
237
238 dev_dbg(&p_dev->dev,
239 "checking configuration %x: %pr %pr %pr (%d lines)\n",
240 p_dev->config_index, p_dev->resource[0], p_dev->resource[1],
241 p_dev->resource[2], p_dev->io_lines);
242
243 return cfg_mem->conf_check(p_dev, cfg_mem->priv_data);
244 }
245
246
247
248
249
250
251
252
253
254
255
256
257
258 int pcmcia_loop_config(struct pcmcia_device *p_dev,
259 int (*conf_check) (struct pcmcia_device *p_dev,
260 void *priv_data),
261 void *priv_data)
262 {
263 struct pcmcia_cfg_mem *cfg_mem;
264 int ret;
265
266 cfg_mem = kzalloc(sizeof(struct pcmcia_cfg_mem), GFP_KERNEL);
267 if (cfg_mem == NULL)
268 return -ENOMEM;
269
270 cfg_mem->p_dev = p_dev;
271 cfg_mem->conf_check = conf_check;
272 cfg_mem->priv_data = priv_data;
273
274 ret = pccard_loop_tuple(p_dev->socket, p_dev->func,
275 CISTPL_CFTABLE_ENTRY, &cfg_mem->parse,
276 cfg_mem, pcmcia_do_loop_config);
277
278 kfree(cfg_mem);
279 return ret;
280 }
281 EXPORT_SYMBOL(pcmcia_loop_config);
282
283
284 struct pcmcia_loop_mem {
285 struct pcmcia_device *p_dev;
286 void *priv_data;
287 int (*loop_tuple) (struct pcmcia_device *p_dev,
288 tuple_t *tuple,
289 void *priv_data);
290 };
291
292
293
294
295
296
297
298
299 static int pcmcia_do_loop_tuple(tuple_t *tuple, cisparse_t *parse, void *priv)
300 {
301 struct pcmcia_loop_mem *loop = priv;
302
303 return loop->loop_tuple(loop->p_dev, tuple, loop->priv_data);
304 };
305
306
307
308
309
310
311
312
313
314
315
316
317
318 int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
319 int (*loop_tuple) (struct pcmcia_device *p_dev,
320 tuple_t *tuple,
321 void *priv_data),
322 void *priv_data)
323 {
324 struct pcmcia_loop_mem loop = {
325 .p_dev = p_dev,
326 .loop_tuple = loop_tuple,
327 .priv_data = priv_data};
328
329 return pccard_loop_tuple(p_dev->socket, p_dev->func, code, NULL,
330 &loop, pcmcia_do_loop_tuple);
331 }
332 EXPORT_SYMBOL(pcmcia_loop_tuple);
333
334
335 struct pcmcia_loop_get {
336 size_t len;
337 cisdata_t **buf;
338 };
339
340
341
342
343
344
345
346
347
348
349 static int pcmcia_do_get_tuple(struct pcmcia_device *p_dev, tuple_t *tuple,
350 void *priv)
351 {
352 struct pcmcia_loop_get *get = priv;
353
354 *get->buf = kzalloc(tuple->TupleDataLen, GFP_KERNEL);
355 if (*get->buf) {
356 get->len = tuple->TupleDataLen;
357 memcpy(*get->buf, tuple->TupleData, tuple->TupleDataLen);
358 } else
359 dev_dbg(&p_dev->dev, "do_get_tuple: out of memory\n");
360 return 0;
361 }
362
363
364
365
366
367
368
369
370
371
372
373 size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code,
374 unsigned char **buf)
375 {
376 struct pcmcia_loop_get get = {
377 .len = 0,
378 .buf = buf,
379 };
380
381 *get.buf = NULL;
382 pcmcia_loop_tuple(p_dev, code, pcmcia_do_get_tuple, &get);
383
384 return get.len;
385 }
386 EXPORT_SYMBOL(pcmcia_get_tuple);
387
388
389
390
391
392
393
394
395
396
397 static int pcmcia_do_get_mac(struct pcmcia_device *p_dev, tuple_t *tuple,
398 void *priv)
399 {
400 struct net_device *dev = priv;
401 int i;
402
403 if (tuple->TupleData[0] != CISTPL_FUNCE_LAN_NODE_ID)
404 return -EINVAL;
405 if (tuple->TupleDataLen < ETH_ALEN + 2) {
406 dev_warn(&p_dev->dev, "Invalid CIS tuple length for "
407 "LAN_NODE_ID\n");
408 return -EINVAL;
409 }
410
411 if (tuple->TupleData[1] != ETH_ALEN) {
412 dev_warn(&p_dev->dev, "Invalid header for LAN_NODE_ID\n");
413 return -EINVAL;
414 }
415 for (i = 0; i < 6; i++)
416 dev->dev_addr[i] = tuple->TupleData[i+2];
417 return 0;
418 }
419
420
421
422
423
424
425
426
427
428
429 int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev, struct net_device *dev)
430 {
431 return pcmcia_loop_tuple(p_dev, CISTPL_FUNCE, pcmcia_do_get_mac, dev);
432 }
433 EXPORT_SYMBOL(pcmcia_get_mac_from_cis);
434