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#include <linux/string.h>
31#include <linux/proc_fs.h>
32#include <linux/skbuff.h>
33#include <linux/capability.h>
34#include <linux/if.h>
35#include <linux/if_ether.h>
36#include <linux/if_arp.h>
37#include <linux/netdevice.h>
38#include <linux/init.h>
39#include <linux/tty.h>
40#include <linux/kmod.h>
41#include <linux/spinlock.h>
42#include <linux/slab.h>
43#include <linux/export.h>
44
45#include <asm/ioctls.h>
46#include <asm/uaccess.h>
47#include <asm/dma.h>
48#include <asm/io.h>
49
50#include <net/irda/irda_device.h>
51#include <net/irda/irlap.h>
52#include <net/irda/timer.h>
53#include <net/irda/wrapper.h>
54
55static void __irda_task_delete(struct irda_task *task);
56
57static hashbin_t *dongles = NULL;
58static hashbin_t *tasks = NULL;
59
60static void irda_task_timer_expired(void *data);
61
62int __init irda_device_init( void)
63{
64 dongles = hashbin_new(HB_NOLOCK);
65 if (dongles == NULL) {
66 IRDA_WARNING("IrDA: Can't allocate dongles hashbin!\n");
67 return -ENOMEM;
68 }
69 spin_lock_init(&dongles->hb_spinlock);
70
71 tasks = hashbin_new(HB_LOCK);
72 if (tasks == NULL) {
73 IRDA_WARNING("IrDA: Can't allocate tasks hashbin!\n");
74 hashbin_delete(dongles, NULL);
75 return -ENOMEM;
76 }
77
78
79
80
81 return 0;
82}
83
84static void leftover_dongle(void *arg)
85{
86 struct dongle_reg *reg = arg;
87 IRDA_WARNING("IrDA: Dongle type %x not unregistered\n",
88 reg->type);
89}
90
91void irda_device_cleanup(void)
92{
93 IRDA_DEBUG(4, "%s()\n", __func__);
94
95 hashbin_delete(tasks, (FREE_FUNC) __irda_task_delete);
96
97 hashbin_delete(dongles, leftover_dongle);
98}
99
100
101
102
103
104
105
106void irda_device_set_media_busy(struct net_device *dev, int status)
107{
108 struct irlap_cb *self;
109
110 IRDA_DEBUG(4, "%s(%s)\n", __func__, status ? "TRUE" : "FALSE");
111
112 self = (struct irlap_cb *) dev->atalk_ptr;
113
114
115
116
117
118
119
120
121 if (!self || self->magic != LAP_MAGIC)
122 return;
123
124 if (status) {
125 self->media_busy = TRUE;
126 if (status == SMALL)
127 irlap_start_mbusy_timer(self, SMALLBUSY_TIMEOUT);
128 else
129 irlap_start_mbusy_timer(self, MEDIABUSY_TIMEOUT);
130 IRDA_DEBUG( 4, "Media busy!\n");
131 } else {
132 self->media_busy = FALSE;
133 irlap_stop_mbusy_timer(self);
134 }
135}
136EXPORT_SYMBOL(irda_device_set_media_busy);
137
138
139
140
141
142
143
144
145int irda_device_is_receiving(struct net_device *dev)
146{
147 struct if_irda_req req;
148 int ret;
149
150 IRDA_DEBUG(2, "%s()\n", __func__);
151
152 if (!dev->netdev_ops->ndo_do_ioctl) {
153 IRDA_ERROR("%s: do_ioctl not impl. by device driver\n",
154 __func__);
155 return -1;
156 }
157
158 ret = (dev->netdev_ops->ndo_do_ioctl)(dev, (struct ifreq *) &req,
159 SIOCGRECEIVING);
160 if (ret < 0)
161 return ret;
162
163 return req.ifr_receiving;
164}
165
166static void __irda_task_delete(struct irda_task *task)
167{
168 del_timer(&task->timer);
169
170 kfree(task);
171}
172
173static void irda_task_delete(struct irda_task *task)
174{
175
176 hashbin_remove(tasks, (long) task, NULL);
177
178 __irda_task_delete(task);
179}
180
181
182
183
184
185
186
187
188
189static int irda_task_kick(struct irda_task *task)
190{
191 int finished = TRUE;
192 int count = 0;
193 int timeout;
194
195 IRDA_DEBUG(2, "%s()\n", __func__);
196
197 IRDA_ASSERT(task != NULL, return -1;);
198 IRDA_ASSERT(task->magic == IRDA_TASK_MAGIC, return -1;);
199
200
201 do {
202 timeout = task->function(task);
203 if (count++ > 100) {
204 IRDA_ERROR("%s: error in task handler!\n",
205 __func__);
206 irda_task_delete(task);
207 return TRUE;
208 }
209 } while ((timeout == 0) && (task->state != IRDA_TASK_DONE));
210
211 if (timeout < 0) {
212 IRDA_ERROR("%s: Error executing task!\n", __func__);
213 irda_task_delete(task);
214 return TRUE;
215 }
216
217
218 if (task->state == IRDA_TASK_DONE) {
219 del_timer(&task->timer);
220
221
222 if (task->finished)
223 task->finished(task);
224
225
226 if (task->parent) {
227
228 if (task->parent->state == IRDA_TASK_CHILD_WAIT) {
229 task->parent->state = IRDA_TASK_CHILD_DONE;
230
231
232 del_timer(&task->parent->timer);
233
234
235 irda_task_kick(task->parent);
236 }
237 }
238 irda_task_delete(task);
239 } else if (timeout > 0) {
240 irda_start_timer(&task->timer, timeout, (void *) task,
241 irda_task_timer_expired);
242 finished = FALSE;
243 } else {
244 IRDA_DEBUG(0, "%s(), not finished, and no timeout!\n",
245 __func__);
246 finished = FALSE;
247 }
248
249 return finished;
250}
251
252
253
254
255
256
257
258static void irda_task_timer_expired(void *data)
259{
260 struct irda_task *task;
261
262 IRDA_DEBUG(2, "%s()\n", __func__);
263
264 task = data;
265
266 irda_task_kick(task);
267}
268
269
270
271
272
273
274
275static void irda_device_setup(struct net_device *dev)
276{
277 dev->hard_header_len = 0;
278 dev->addr_len = LAP_ALEN;
279
280 dev->type = ARPHRD_IRDA;
281 dev->tx_queue_len = 8;
282
283 memset(dev->broadcast, 0xff, LAP_ALEN);
284
285 dev->mtu = 2048;
286 dev->flags = IFF_NOARP;
287}
288
289
290
291
292
293
294struct net_device *alloc_irdadev(int sizeof_priv)
295{
296 return alloc_netdev(sizeof_priv, "irda%d", irda_device_setup);
297}
298EXPORT_SYMBOL(alloc_irdadev);
299
300#ifdef CONFIG_ISA_DMA_API
301
302
303
304
305
306
307void irda_setup_dma(int channel, dma_addr_t buffer, int count, int mode)
308{
309 unsigned long flags;
310
311 flags = claim_dma_lock();
312
313 disable_dma(channel);
314 clear_dma_ff(channel);
315 set_dma_mode(channel, mode);
316 set_dma_addr(channel, buffer);
317 set_dma_count(channel, count);
318 enable_dma(channel);
319
320 release_dma_lock(flags);
321}
322EXPORT_SYMBOL(irda_setup_dma);
323#endif
324