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#include <linux/config.h>
33#include <linux/string.h>
34#include <linux/proc_fs.h>
35#include <linux/skbuff.h>
36#include <linux/if.h>
37#include <linux/if_ether.h>
38#include <linux/if_arp.h>
39#include <linux/netdevice.h>
40#include <linux/init.h>
41#include <linux/tty.h>
42#include <linux/kmod.h>
43#include <linux/wireless.h>
44#include <linux/spinlock.h>
45
46#include <asm/ioctls.h>
47#include <asm/segment.h>
48#include <asm/uaccess.h>
49#include <asm/dma.h>
50#include <asm/io.h>
51
52#include <net/pkt_sched.h>
53
54#include <net/irda/irda_device.h>
55#include <net/irda/irlap.h>
56#include <net/irda/timer.h>
57#include <net/irda/wrapper.h>
58
59extern int irtty_init(void);
60extern int nsc_ircc_init(void);
61extern int ircc_init(void);
62extern int toshoboe_init(void);
63extern int litelink_init(void);
64extern int w83977af_init(void);
65extern int esi_init(void);
66extern int tekram_init(void);
67extern int actisys_init(void);
68extern int girbil_init(void);
69extern int sa1100_irda_init(void);
70extern int ep7211_ir_init(void);
71extern int mcp2120_init(void);
72
73static void __irda_task_delete(struct irda_task *task);
74
75static hashbin_t *dongles = NULL;
76static hashbin_t *tasks = NULL;
77
78const char *infrared_mode[] = {
79 "IRDA_IRLAP",
80 "IRDA_RAW",
81 "SHARP_ASK",
82 "TV_REMOTE",
83};
84
85#ifdef CONFIG_IRDA_DEBUG
86static const char *task_state[] = {
87 "IRDA_TASK_INIT",
88 "IRDA_TASK_DONE",
89 "IRDA_TASK_WAIT",
90 "IRDA_TASK_WAIT1",
91 "IRDA_TASK_WAIT2",
92 "IRDA_TASK_WAIT3",
93 "IRDA_TASK_CHILD_INIT",
94 "IRDA_TASK_CHILD_WAIT",
95 "IRDA_TASK_CHILD_DONE",
96};
97#endif
98
99static void irda_task_timer_expired(void *data);
100
101#ifdef CONFIG_PROC_FS
102int irda_device_proc_read(char *buf, char **start, off_t offset, int len,
103 int unused);
104
105#endif
106
107int __init irda_device_init( void)
108{
109 dongles = hashbin_new(HB_GLOBAL);
110 if (dongles == NULL) {
111 printk(KERN_WARNING
112 "IrDA: Can't allocate dongles hashbin!\n");
113 return -ENOMEM;
114 }
115
116 tasks = hashbin_new(HB_GLOBAL);
117 if (tasks == NULL) {
118 printk(KERN_WARNING
119 "IrDA: Can't allocate tasks hashbin!\n");
120 return -ENOMEM;
121 }
122
123
124
125
126
127
128
129
130#ifdef CONFIG_IRTTY_SIR
131 irtty_init();
132#endif
133#ifdef CONFIG_WINBOND_FIR
134 w83977af_init();
135#endif
136#ifdef CONFIG_SA1100_FIR
137 sa1100_irda_init();
138#endif
139#ifdef CONFIG_NSC_FIR
140 nsc_ircc_init();
141#endif
142#ifdef CONFIG_TOSHIBA_OLD
143 toshoboe_init();
144#endif
145#ifdef CONFIG_SMC_IRCC_FIR
146 ircc_init();
147#endif
148#ifdef CONFIG_ESI_DONGLE
149 esi_init();
150#endif
151#ifdef CONFIG_TEKRAM_DONGLE
152 tekram_init();
153#endif
154#ifdef CONFIG_ACTISYS_DONGLE
155 actisys_init();
156#endif
157#ifdef CONFIG_GIRBIL_DONGLE
158 girbil_init();
159#endif
160#ifdef CONFIG_LITELINK_DONGLE
161 litelink_init();
162#endif
163#ifdef CONFIG_OLD_BELKIN
164 old_belkin_init();
165#endif
166#ifdef CONFIG_EP7211_IR
167 ep7211_ir_init();
168#endif
169#ifdef CONFIG_MCP2120_DONGLE
170 mcp2120_init();
171#endif
172 return 0;
173}
174
175void irda_device_cleanup(void)
176{
177 IRDA_DEBUG(4, "%s()\n", __FUNCTION__);
178
179 hashbin_delete(tasks, (FREE_FUNC) __irda_task_delete);
180 hashbin_delete(dongles, NULL);
181}
182
183
184
185
186
187
188
189void irda_device_set_media_busy(struct net_device *dev, int status)
190{
191 struct irlap_cb *self;
192
193 IRDA_DEBUG(4, "%s(%s)\n", __FUNCTION__, status ? "TRUE" : "FALSE");
194
195 self = (struct irlap_cb *) dev->atalk_ptr;
196
197 ASSERT(self != NULL, return;);
198 ASSERT(self->magic == LAP_MAGIC, return;);
199
200 if (status) {
201 self->media_busy = TRUE;
202 if (status == SMALL)
203 irlap_start_mbusy_timer(self, SMALLBUSY_TIMEOUT);
204 else
205 irlap_start_mbusy_timer(self, MEDIABUSY_TIMEOUT);
206 IRDA_DEBUG( 4, "Media busy!\n");
207 } else {
208 self->media_busy = FALSE;
209 irlap_stop_mbusy_timer(self);
210 }
211}
212
213int irda_device_set_dtr_rts(struct net_device *dev, int dtr, int rts)
214{
215 struct if_irda_req req;
216 int ret;
217
218 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
219
220 if (!dev->do_ioctl) {
221 ERROR("%s(), do_ioctl not impl. by "
222 "device driver\n", __FUNCTION__);
223 return -1;
224 }
225
226 req.ifr_dtr = dtr;
227 req.ifr_rts = rts;
228
229 ret = dev->do_ioctl(dev, (struct ifreq *) &req, SIOCSDTRRTS);
230
231 return ret;
232}
233
234int irda_device_change_speed(struct net_device *dev, __u32 speed)
235{
236 struct if_irda_req req;
237 int ret;
238
239 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
240
241 if (!dev->do_ioctl) {
242 ERROR("%s(), do_ioctl not impl. by "
243 "device driver\n", __FUNCTION__);
244 return -1;
245 }
246
247 req.ifr_baudrate = speed;
248
249 ret = dev->do_ioctl(dev, (struct ifreq *) &req, SIOCSBANDWIDTH);
250
251 return ret;
252}
253
254
255
256
257
258
259
260int irda_device_is_receiving(struct net_device *dev)
261{
262 struct if_irda_req req;
263 int ret;
264
265 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
266
267 if (!dev->do_ioctl) {
268 ERROR("%s(), do_ioctl not impl. by "
269 "device driver\n", __FUNCTION__);
270 return -1;
271 }
272
273 ret = dev->do_ioctl(dev, (struct ifreq *) &req, SIOCGRECEIVING);
274 if (ret < 0)
275 return ret;
276
277 return req.ifr_receiving;
278}
279
280void irda_task_next_state(struct irda_task *task, IRDA_TASK_STATE state)
281{
282 IRDA_DEBUG(2, "%s(), state = %s\n", __FUNCTION__, task_state[state]);
283
284 task->state = state;
285}
286
287static void __irda_task_delete(struct irda_task *task)
288{
289 del_timer(&task->timer);
290
291 kfree(task);
292}
293
294void irda_task_delete(struct irda_task *task)
295{
296
297 hashbin_remove(tasks, (int) task, NULL);
298
299 __irda_task_delete(task);
300}
301
302
303
304
305
306
307
308
309
310int irda_task_kick(struct irda_task *task)
311{
312 int finished = TRUE;
313 int count = 0;
314 int timeout;
315
316 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
317
318 ASSERT(task != NULL, return -1;);
319 ASSERT(task->magic == IRDA_TASK_MAGIC, return -1;);
320
321
322 do {
323 timeout = task->function(task);
324 if (count++ > 100) {
325 ERROR("%s(), error in task handler!\n", __FUNCTION__);
326 irda_task_delete(task);
327 return TRUE;
328 }
329 } while ((timeout == 0) && (task->state != IRDA_TASK_DONE));
330
331 if (timeout < 0) {
332 ERROR("%s(), Error executing task!\n", __FUNCTION__);
333 irda_task_delete(task);
334 return TRUE;
335 }
336
337
338 if (task->state == IRDA_TASK_DONE) {
339 del_timer(&task->timer);
340
341
342 if (task->finished)
343 task->finished(task);
344
345
346 if (task->parent) {
347
348 if (task->parent->state == IRDA_TASK_CHILD_WAIT) {
349 task->parent->state = IRDA_TASK_CHILD_DONE;
350
351
352 del_timer(&task->parent->timer);
353
354
355 irda_task_kick(task->parent);
356 }
357 }
358 irda_task_delete(task);
359 } else if (timeout > 0) {
360 irda_start_timer(&task->timer, timeout, (void *) task,
361 irda_task_timer_expired);
362 finished = FALSE;
363 } else {
364 IRDA_DEBUG(0, "%s(), not finished, and no timeout!\n", __FUNCTION__);
365 finished = FALSE;
366 }
367
368 return finished;
369}
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385struct irda_task *irda_task_execute(void *instance,
386 IRDA_TASK_CALLBACK function,
387 IRDA_TASK_CALLBACK finished,
388 struct irda_task *parent, void *param)
389{
390 struct irda_task *task;
391 int ret;
392
393 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
394
395 task = kmalloc(sizeof(struct irda_task), GFP_ATOMIC);
396 if (!task)
397 return NULL;
398
399 task->state = IRDA_TASK_INIT;
400 task->instance = instance;
401 task->function = function;
402 task->finished = finished;
403 task->parent = parent;
404 task->param = param;
405 task->magic = IRDA_TASK_MAGIC;
406
407 init_timer(&task->timer);
408
409
410 hashbin_insert(tasks, (irda_queue_t *) task, (int) task, NULL);
411
412
413 ret = irda_task_kick(task);
414 if (ret)
415 return NULL;
416 else
417 return task;
418}
419
420
421
422
423
424
425
426static void irda_task_timer_expired(void *data)
427{
428 struct irda_task *task;
429
430 IRDA_DEBUG(2, "%s()\n", __FUNCTION__);
431
432 task = (struct irda_task *) data;
433
434 irda_task_kick(task);
435}
436
437
438
439
440
441
442
443int irda_device_setup(struct net_device *dev)
444{
445 ASSERT(dev != NULL, return -1;);
446
447 dev->hard_header_len = 0;
448 dev->addr_len = 0;
449
450 dev->features |= NETIF_F_DYNALLOC;
451
452
453 dev->type = ARPHRD_IRDA;
454 dev->tx_queue_len = 8;
455
456 memset(dev->broadcast, 0xff, 4);
457
458 dev->mtu = 2048;
459 dev->flags = IFF_NOARP;
460 return 0;
461}
462
463
464
465
466
467
468
469
470int irda_device_txqueue_empty(struct net_device *dev)
471{
472 if (skb_queue_len(&dev->qdisc->q))
473 return FALSE;
474
475 return TRUE;
476}
477
478
479
480
481
482
483
484
485
486dongle_t *irda_device_dongle_init(struct net_device *dev, int type)
487{
488 struct dongle_reg *reg;
489 dongle_t *dongle;
490
491 ASSERT(dev != NULL, return NULL;);
492
493#ifdef CONFIG_KMOD
494 {
495 char modname[32];
496 ASSERT(!in_interrupt(), return NULL;);
497
498 sprintf(modname, "irda-dongle-%d", type);
499 request_module(modname);
500 }
501#endif
502
503 if (!(reg = hashbin_find(dongles, type, NULL))) {
504 ERROR("IrDA: Unable to find requested dongle\n");
505 return NULL;
506 }
507
508
509 dongle = kmalloc(sizeof(dongle_t), GFP_KERNEL);
510 if (!dongle)
511 return NULL;
512
513 memset(dongle, 0, sizeof(dongle_t));
514
515
516 dongle->issue = reg;
517 dongle->dev = dev;
518
519 return dongle;
520}
521
522
523
524
525
526
527
528int irda_device_dongle_cleanup(dongle_t *dongle)
529{
530 ASSERT(dongle != NULL, return -1;);
531
532 dongle->issue->close(dongle);
533
534 kfree(dongle);
535
536 return 0;
537}
538
539
540
541
542
543
544
545int irda_device_register_dongle(struct dongle_reg *new)
546{
547
548 if (hashbin_find(dongles, new->type, NULL)) {
549 MESSAGE("%s(), Dongle already registered\n", __FUNCTION__);
550 return 0;
551 }
552
553
554 hashbin_insert(dongles, (irda_queue_t *) new, new->type, NULL);
555
556 return 0;
557}
558
559
560
561
562
563
564
565void irda_device_unregister_dongle(struct dongle_reg *dongle)
566{
567 struct dongle *node;
568
569 node = hashbin_remove(dongles, dongle->type, NULL);
570 if (!node) {
571 ERROR("%s(), dongle not found!\n", __FUNCTION__);
572 return;
573 }
574}
575
576
577
578
579
580
581
582
583int irda_device_set_mode(struct net_device* dev, int mode)
584{
585 struct if_irda_req req;
586 int ret;
587
588 IRDA_DEBUG(0, "%s()\n", __FUNCTION__);
589
590 if (!dev->do_ioctl) {
591 ERROR("%s(), set_raw_mode not impl. by "
592 "device driver\n", __FUNCTION__);
593 return -1;
594 }
595
596 req.ifr_mode = mode;
597
598 ret = dev->do_ioctl(dev, (struct ifreq *) &req, SIOCSMODE);
599
600 return ret;
601}
602
603
604
605
606
607
608
609void setup_dma(int channel, char *buffer, int count, int mode)
610{
611 unsigned long flags;
612
613 flags = claim_dma_lock();
614
615 disable_dma(channel);
616 clear_dma_ff(channel);
617 set_dma_mode(channel, mode);
618 set_dma_addr(channel, virt_to_bus(buffer));
619 set_dma_count(channel, count);
620 enable_dma(channel);
621
622 release_dma_lock(flags);
623}
624