Merge master.kernel.org:/pub/scm/linux/kernel/git/wim/linux-2.6-watchdog
[linux-2.6] / drivers / ieee1394 / ieee1394_core.c
1 /*
2  * IEEE 1394 for Linux
3  *
4  * Core support: hpsb_packet management, packet handling and forwarding to
5  *               highlevel or lowlevel code
6  *
7  * Copyright (C) 1999, 2000 Andreas E. Bombe
8  *                     2002 Manfred Weihs <weihs@ict.tuwien.ac.at>
9  *
10  * This code is licensed under the GPL.  See the file COPYING in the root
11  * directory of the kernel sources for details.
12  *
13  *
14  * Contributions:
15  *
16  * Manfred Weihs <weihs@ict.tuwien.ac.at>
17  *        loopback functionality in hpsb_send_packet
18  *        allow highlevel drivers to disable automatic response generation
19  *              and to generate responses themselves (deferred)
20  *
21  */
22
23 #include <linux/kernel.h>
24 #include <linux/list.h>
25 #include <linux/string.h>
26 #include <linux/init.h>
27 #include <linux/slab.h>
28 #include <linux/interrupt.h>
29 #include <linux/module.h>
30 #include <linux/moduleparam.h>
31 #include <linux/bitops.h>
32 #include <linux/kdev_t.h>
33 #include <linux/skbuff.h>
34 #include <linux/suspend.h>
35 #include <linux/kthread.h>
36 #include <linux/preempt.h>
37 #include <linux/time.h>
38
39 #include <asm/system.h>
40 #include <asm/byteorder.h>
41
42 #include "ieee1394_types.h"
43 #include "ieee1394.h"
44 #include "hosts.h"
45 #include "ieee1394_core.h"
46 #include "highlevel.h"
47 #include "ieee1394_transactions.h"
48 #include "csr.h"
49 #include "nodemgr.h"
50 #include "dma.h"
51 #include "iso.h"
52 #include "config_roms.h"
53
54 /*
55  * Disable the nodemgr detection and config rom reading functionality.
56  */
57 static int disable_nodemgr;
58 module_param(disable_nodemgr, int, 0444);
59 MODULE_PARM_DESC(disable_nodemgr, "Disable nodemgr functionality.");
60
61 /* Disable Isochronous Resource Manager functionality */
62 int hpsb_disable_irm = 0;
63 module_param_named(disable_irm, hpsb_disable_irm, bool, 0444);
64 MODULE_PARM_DESC(disable_irm,
65                  "Disable Isochronous Resource Manager functionality.");
66
67 /* We are GPL, so treat us special */
68 MODULE_LICENSE("GPL");
69
70 /* Some globals used */
71 const char *hpsb_speedto_str[] = { "S100", "S200", "S400", "S800", "S1600", "S3200" };
72 struct class *hpsb_protocol_class;
73
74 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
75 static void dump_packet(const char *text, quadlet_t *data, int size, int speed)
76 {
77         int i;
78
79         size /= 4;
80         size = (size > 4 ? 4 : size);
81
82         printk(KERN_DEBUG "ieee1394: %s", text);
83         if (speed > -1 && speed < 6)
84                 printk(" at %s", hpsb_speedto_str[speed]);
85         printk(":");
86         for (i = 0; i < size; i++)
87                 printk(" %08x", data[i]);
88         printk("\n");
89 }
90 #else
91 #define dump_packet(a,b,c,d) do {} while (0)
92 #endif
93
94 static void abort_requests(struct hpsb_host *host);
95 static void queue_packet_complete(struct hpsb_packet *packet);
96
97
98 /**
99  * hpsb_set_packet_complete_task - set the task that runs when a packet
100  * completes. You cannot call this more than once on a single packet
101  * before it is sent.
102  *
103  * @packet: the packet whose completion we want the task added to
104  * @routine: function to call
105  * @data: data (if any) to pass to the above function
106  */
107 void hpsb_set_packet_complete_task(struct hpsb_packet *packet,
108                                    void (*routine)(void *), void *data)
109 {
110         WARN_ON(packet->complete_routine != NULL);
111         packet->complete_routine = routine;
112         packet->complete_data = data;
113         return;
114 }
115
116 /**
117  * hpsb_alloc_packet - allocate new packet structure
118  * @data_size: size of the data block to be allocated
119  *
120  * This function allocates, initializes and returns a new &struct hpsb_packet.
121  * It can be used in interrupt context.  A header block is always included, its
122  * size is big enough to contain all possible 1394 headers.  The data block is
123  * only allocated when @data_size is not zero.
124  *
125  * For packets for which responses will be received the @data_size has to be big
126  * enough to contain the response's data block since no further allocation
127  * occurs at response matching time.
128  *
129  * The packet's generation value will be set to the current generation number
130  * for ease of use.  Remember to overwrite it with your own recorded generation
131  * number if you can not be sure that your code will not race with a bus reset.
132  *
133  * Return value: A pointer to a &struct hpsb_packet or NULL on allocation
134  * failure.
135  */
136 struct hpsb_packet *hpsb_alloc_packet(size_t data_size)
137 {
138         struct hpsb_packet *packet = NULL;
139         struct sk_buff *skb;
140
141         data_size = ((data_size + 3) & ~3);
142
143         skb = alloc_skb(data_size + sizeof(*packet), GFP_ATOMIC);
144         if (skb == NULL)
145                 return NULL;
146
147         memset(skb->data, 0, data_size + sizeof(*packet));
148
149         packet = (struct hpsb_packet *)skb->data;
150         packet->skb = skb;
151
152         packet->header = packet->embedded_header;
153         packet->state = hpsb_unused;
154         packet->generation = -1;
155         INIT_LIST_HEAD(&packet->driver_list);
156         atomic_set(&packet->refcnt, 1);
157
158         if (data_size) {
159                 packet->data = (quadlet_t *)(skb->data + sizeof(*packet));
160                 packet->data_size = data_size;
161         }
162
163         return packet;
164 }
165
166
167 /**
168  * hpsb_free_packet - free packet and data associated with it
169  * @packet: packet to free (is NULL safe)
170  *
171  * This function will free packet->data and finally the packet itself.
172  */
173 void hpsb_free_packet(struct hpsb_packet *packet)
174 {
175         if (packet && atomic_dec_and_test(&packet->refcnt)) {
176                 BUG_ON(!list_empty(&packet->driver_list));
177                 kfree_skb(packet->skb);
178         }
179 }
180
181
182 int hpsb_reset_bus(struct hpsb_host *host, int type)
183 {
184         if (!host->in_bus_reset) {
185                 host->driver->devctl(host, RESET_BUS, type);
186                 return 0;
187         } else {
188                 return 1;
189         }
190 }
191
192 /**
193  * hpsb_read_cycle_timer - read cycle timer register and system time
194  * @host: host whose isochronous cycle timer register is read
195  * @cycle_timer: address of bitfield to return the register contents
196  * @local_time: address to return the system time
197  *
198  * The format of * @cycle_timer, is described in OHCI 1.1 clause 5.13. This
199  * format is also read from non-OHCI controllers. * @local_time contains the
200  * system time in microseconds since the Epoch, read at the moment when the
201  * cycle timer was read.
202  *
203  * Return value: 0 for success or error number otherwise.
204  */
205 int hpsb_read_cycle_timer(struct hpsb_host *host, u32 *cycle_timer,
206                           u64 *local_time)
207 {
208         int ctr;
209         struct timeval tv;
210         unsigned long flags;
211
212         if (!host || !cycle_timer || !local_time)
213                 return -EINVAL;
214
215         preempt_disable();
216         local_irq_save(flags);
217
218         ctr = host->driver->devctl(host, GET_CYCLE_COUNTER, 0);
219         if (ctr)
220                 do_gettimeofday(&tv);
221
222         local_irq_restore(flags);
223         preempt_enable();
224
225         if (!ctr)
226                 return -EIO;
227         *cycle_timer = ctr;
228         *local_time = tv.tv_sec * 1000000ULL + tv.tv_usec;
229         return 0;
230 }
231
232 int hpsb_bus_reset(struct hpsb_host *host)
233 {
234         if (host->in_bus_reset) {
235                 HPSB_NOTICE("%s called while bus reset already in progress",
236                             __FUNCTION__);
237                 return 1;
238         }
239
240         abort_requests(host);
241         host->in_bus_reset = 1;
242         host->irm_id = -1;
243         host->is_irm = 0;
244         host->busmgr_id = -1;
245         host->is_busmgr = 0;
246         host->is_cycmst = 0;
247         host->node_count = 0;
248         host->selfid_count = 0;
249
250         return 0;
251 }
252
253
254 /*
255  * Verify num_of_selfids SelfIDs and return number of nodes.  Return zero in
256  * case verification failed.
257  */
258 static int check_selfids(struct hpsb_host *host)
259 {
260         int nodeid = -1;
261         int rest_of_selfids = host->selfid_count;
262         struct selfid *sid = (struct selfid *)host->topology_map;
263         struct ext_selfid *esid;
264         int esid_seq = 23;
265
266         host->nodes_active = 0;
267
268         while (rest_of_selfids--) {
269                 if (!sid->extended) {
270                         nodeid++;
271                         esid_seq = 0;
272
273                         if (sid->phy_id != nodeid) {
274                                 HPSB_INFO("SelfIDs failed monotony check with "
275                                           "%d", sid->phy_id);
276                                 return 0;
277                         }
278
279                         if (sid->link_active) {
280                                 host->nodes_active++;
281                                 if (sid->contender)
282                                         host->irm_id = LOCAL_BUS | sid->phy_id;
283                         }
284                 } else {
285                         esid = (struct ext_selfid *)sid;
286
287                         if ((esid->phy_id != nodeid)
288                             || (esid->seq_nr != esid_seq)) {
289                                 HPSB_INFO("SelfIDs failed monotony check with "
290                                           "%d/%d", esid->phy_id, esid->seq_nr);
291                                 return 0;
292                         }
293                         esid_seq++;
294                 }
295                 sid++;
296         }
297
298         esid = (struct ext_selfid *)(sid - 1);
299         while (esid->extended) {
300                 if ((esid->porta == SELFID_PORT_PARENT) ||
301                     (esid->portb == SELFID_PORT_PARENT) ||
302                     (esid->portc == SELFID_PORT_PARENT) ||
303                     (esid->portd == SELFID_PORT_PARENT) ||
304                     (esid->porte == SELFID_PORT_PARENT) ||
305                     (esid->portf == SELFID_PORT_PARENT) ||
306                     (esid->portg == SELFID_PORT_PARENT) ||
307                     (esid->porth == SELFID_PORT_PARENT)) {
308                         HPSB_INFO("SelfIDs failed root check on "
309                                   "extended SelfID");
310                         return 0;
311                 }
312                 esid--;
313         }
314
315         sid = (struct selfid *)esid;
316         if ((sid->port0 == SELFID_PORT_PARENT) ||
317             (sid->port1 == SELFID_PORT_PARENT) ||
318             (sid->port2 == SELFID_PORT_PARENT)) {
319                 HPSB_INFO("SelfIDs failed root check");
320                 return 0;
321         }
322
323         host->node_count = nodeid + 1;
324         return 1;
325 }
326
327 static void build_speed_map(struct hpsb_host *host, int nodecount)
328 {
329         u8 cldcnt[nodecount];
330         u8 *map = host->speed_map;
331         u8 *speedcap = host->speed;
332         struct selfid *sid;
333         struct ext_selfid *esid;
334         int i, j, n;
335
336         for (i = 0; i < (nodecount * 64); i += 64) {
337                 for (j = 0; j < nodecount; j++) {
338                         map[i+j] = IEEE1394_SPEED_MAX;
339                 }
340         }
341
342         for (i = 0; i < nodecount; i++) {
343                 cldcnt[i] = 0;
344         }
345
346         /* find direct children count and speed */
347         for (sid = (struct selfid *)&host->topology_map[host->selfid_count-1],
348                      n = nodecount - 1;
349              (void *)sid >= (void *)host->topology_map; sid--) {
350                 if (sid->extended) {
351                         esid = (struct ext_selfid *)sid;
352
353                         if (esid->porta == SELFID_PORT_CHILD) cldcnt[n]++;
354                         if (esid->portb == SELFID_PORT_CHILD) cldcnt[n]++;
355                         if (esid->portc == SELFID_PORT_CHILD) cldcnt[n]++;
356                         if (esid->portd == SELFID_PORT_CHILD) cldcnt[n]++;
357                         if (esid->porte == SELFID_PORT_CHILD) cldcnt[n]++;
358                         if (esid->portf == SELFID_PORT_CHILD) cldcnt[n]++;
359                         if (esid->portg == SELFID_PORT_CHILD) cldcnt[n]++;
360                         if (esid->porth == SELFID_PORT_CHILD) cldcnt[n]++;
361                 } else {
362                         if (sid->port0 == SELFID_PORT_CHILD) cldcnt[n]++;
363                         if (sid->port1 == SELFID_PORT_CHILD) cldcnt[n]++;
364                         if (sid->port2 == SELFID_PORT_CHILD) cldcnt[n]++;
365
366                         speedcap[n] = sid->speed;
367                         n--;
368                 }
369         }
370
371         /* set self mapping */
372         for (i = 0; i < nodecount; i++) {
373                 map[64*i + i] = speedcap[i];
374         }
375
376         /* fix up direct children count to total children count;
377          * also fix up speedcaps for sibling and parent communication */
378         for (i = 1; i < nodecount; i++) {
379                 for (j = cldcnt[i], n = i - 1; j > 0; j--) {
380                         cldcnt[i] += cldcnt[n];
381                         speedcap[n] = min(speedcap[n], speedcap[i]);
382                         n -= cldcnt[n] + 1;
383                 }
384         }
385
386         for (n = 0; n < nodecount; n++) {
387                 for (i = n - cldcnt[n]; i <= n; i++) {
388                         for (j = 0; j < (n - cldcnt[n]); j++) {
389                                 map[j*64 + i] = map[i*64 + j] =
390                                         min(map[i*64 + j], speedcap[n]);
391                         }
392                         for (j = n + 1; j < nodecount; j++) {
393                                 map[j*64 + i] = map[i*64 + j] =
394                                         min(map[i*64 + j], speedcap[n]);
395                         }
396                 }
397         }
398
399 #if SELFID_SPEED_UNKNOWN != IEEE1394_SPEED_MAX
400         /* assume maximum speed for 1394b PHYs, nodemgr will correct it */
401         for (n = 0; n < nodecount; n++)
402                 if (speedcap[n] == SELFID_SPEED_UNKNOWN)
403                         speedcap[n] = IEEE1394_SPEED_MAX;
404 #endif
405 }
406
407
408 void hpsb_selfid_received(struct hpsb_host *host, quadlet_t sid)
409 {
410         if (host->in_bus_reset) {
411                 HPSB_VERBOSE("Including SelfID 0x%x", sid);
412                 host->topology_map[host->selfid_count++] = sid;
413         } else {
414                 HPSB_NOTICE("Spurious SelfID packet (0x%08x) received from bus %d",
415                             sid, NODEID_TO_BUS(host->node_id));
416         }
417 }
418
419 void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot)
420 {
421         if (!host->in_bus_reset)
422                 HPSB_NOTICE("SelfID completion called outside of bus reset!");
423
424         host->node_id = LOCAL_BUS | phyid;
425         host->is_root = isroot;
426
427         if (!check_selfids(host)) {
428                 if (host->reset_retries++ < 20) {
429                         /* selfid stage did not complete without error */
430                         HPSB_NOTICE("Error in SelfID stage, resetting");
431                         host->in_bus_reset = 0;
432                         /* this should work from ohci1394 now... */
433                         hpsb_reset_bus(host, LONG_RESET);
434                         return;
435                 } else {
436                         HPSB_NOTICE("Stopping out-of-control reset loop");
437                         HPSB_NOTICE("Warning - topology map and speed map will not be valid");
438                         host->reset_retries = 0;
439                 }
440         } else {
441                 host->reset_retries = 0;
442                 build_speed_map(host, host->node_count);
443         }
444
445         HPSB_VERBOSE("selfid_complete called with successful SelfID stage "
446                      "... irm_id: 0x%X node_id: 0x%X",host->irm_id,host->node_id);
447
448         /* irm_id is kept up to date by check_selfids() */
449         if (host->irm_id == host->node_id) {
450                 host->is_irm = 1;
451         } else {
452                 host->is_busmgr = 0;
453                 host->is_irm = 0;
454         }
455
456         if (isroot) {
457                 host->driver->devctl(host, ACT_CYCLE_MASTER, 1);
458                 host->is_cycmst = 1;
459         }
460         atomic_inc(&host->generation);
461         host->in_bus_reset = 0;
462         highlevel_host_reset(host);
463 }
464
465
466 void hpsb_packet_sent(struct hpsb_host *host, struct hpsb_packet *packet,
467                       int ackcode)
468 {
469         unsigned long flags;
470
471         spin_lock_irqsave(&host->pending_packet_queue.lock, flags);
472
473         packet->ack_code = ackcode;
474
475         if (packet->no_waiter || packet->state == hpsb_complete) {
476                 /* if packet->no_waiter, must not have a tlabel allocated */
477                 spin_unlock_irqrestore(&host->pending_packet_queue.lock, flags);
478                 hpsb_free_packet(packet);
479                 return;
480         }
481
482         atomic_dec(&packet->refcnt);    /* drop HC's reference */
483         /* here the packet must be on the host->pending_packet_queue */
484
485         if (ackcode != ACK_PENDING || !packet->expect_response) {
486                 packet->state = hpsb_complete;
487                 __skb_unlink(packet->skb, &host->pending_packet_queue);
488                 spin_unlock_irqrestore(&host->pending_packet_queue.lock, flags);
489                 queue_packet_complete(packet);
490                 return;
491         }
492
493         packet->state = hpsb_pending;
494         packet->sendtime = jiffies;
495
496         spin_unlock_irqrestore(&host->pending_packet_queue.lock, flags);
497
498         mod_timer(&host->timeout, jiffies + host->timeout_interval);
499 }
500
501 /**
502  * hpsb_send_phy_config - transmit a PHY configuration packet on the bus
503  * @host: host that PHY config packet gets sent through
504  * @rootid: root whose force_root bit should get set (-1 = don't set force_root)
505  * @gapcnt: gap count value to set (-1 = don't set gap count)
506  *
507  * This function sends a PHY config packet on the bus through the specified host.
508  *
509  * Return value: 0 for success or error number otherwise.
510  */
511 int hpsb_send_phy_config(struct hpsb_host *host, int rootid, int gapcnt)
512 {
513         struct hpsb_packet *packet;
514         quadlet_t d = 0;
515         int retval = 0;
516
517         if (rootid >= ALL_NODES || rootid < -1 || gapcnt > 0x3f || gapcnt < -1 ||
518            (rootid == -1 && gapcnt == -1)) {
519                 HPSB_DEBUG("Invalid Parameter: rootid = %d   gapcnt = %d",
520                            rootid, gapcnt);
521                 return -EINVAL;
522         }
523
524         if (rootid != -1)
525                 d |= PHYPACKET_PHYCONFIG_R | rootid << PHYPACKET_PORT_SHIFT;
526         if (gapcnt != -1)
527                 d |= PHYPACKET_PHYCONFIG_T | gapcnt << PHYPACKET_GAPCOUNT_SHIFT;
528
529         packet = hpsb_make_phypacket(host, d);
530         if (!packet)
531                 return -ENOMEM;
532
533         packet->generation = get_hpsb_generation(host);
534         retval = hpsb_send_packet_and_wait(packet);
535         hpsb_free_packet(packet);
536
537         return retval;
538 }
539
540 /**
541  * hpsb_send_packet - transmit a packet on the bus
542  * @packet: packet to send
543  *
544  * The packet is sent through the host specified in the packet->host field.
545  * Before sending, the packet's transmit speed is automatically determined
546  * using the local speed map when it is an async, non-broadcast packet.
547  *
548  * Possibilities for failure are that host is either not initialized, in bus
549  * reset, the packet's generation number doesn't match the current generation
550  * number or the host reports a transmit error.
551  *
552  * Return value: 0 on success, negative errno on failure.
553  */
554 int hpsb_send_packet(struct hpsb_packet *packet)
555 {
556         struct hpsb_host *host = packet->host;
557
558         if (host->is_shutdown)
559                 return -EINVAL;
560         if (host->in_bus_reset ||
561             (packet->generation != get_hpsb_generation(host)))
562                 return -EAGAIN;
563
564         packet->state = hpsb_queued;
565
566         /* This just seems silly to me */
567         WARN_ON(packet->no_waiter && packet->expect_response);
568
569         if (!packet->no_waiter || packet->expect_response) {
570                 atomic_inc(&packet->refcnt);
571                 /* Set the initial "sendtime" to 10 seconds from now, to
572                    prevent premature expiry.  If a packet takes more than
573                    10 seconds to hit the wire, we have bigger problems :) */
574                 packet->sendtime = jiffies + 10 * HZ;
575                 skb_queue_tail(&host->pending_packet_queue, packet->skb);
576         }
577
578         if (packet->node_id == host->node_id) {
579                 /* it is a local request, so handle it locally */
580
581                 quadlet_t *data;
582                 size_t size = packet->data_size + packet->header_size;
583
584                 data = kmalloc(size, GFP_ATOMIC);
585                 if (!data) {
586                         HPSB_ERR("unable to allocate memory for concatenating header and data");
587                         return -ENOMEM;
588                 }
589
590                 memcpy(data, packet->header, packet->header_size);
591
592                 if (packet->data_size)
593                         memcpy(((u8*)data) + packet->header_size, packet->data, packet->data_size);
594
595                 dump_packet("send packet local", packet->header, packet->header_size, -1);
596
597                 hpsb_packet_sent(host, packet, packet->expect_response ? ACK_PENDING : ACK_COMPLETE);
598                 hpsb_packet_received(host, data, size, 0);
599
600                 kfree(data);
601
602                 return 0;
603         }
604
605         if (packet->type == hpsb_async &&
606             NODEID_TO_NODE(packet->node_id) != ALL_NODES)
607                 packet->speed_code =
608                         host->speed[NODEID_TO_NODE(packet->node_id)];
609
610         dump_packet("send packet", packet->header, packet->header_size, packet->speed_code);
611
612         return host->driver->transmit_packet(host, packet);
613 }
614
615 /* We could just use complete() directly as the packet complete
616  * callback, but this is more typesafe, in the sense that we get a
617  * compiler error if the prototype for complete() changes. */
618
619 static void complete_packet(void *data)
620 {
621         complete((struct completion *) data);
622 }
623
624 int hpsb_send_packet_and_wait(struct hpsb_packet *packet)
625 {
626         struct completion done;
627         int retval;
628
629         init_completion(&done);
630         hpsb_set_packet_complete_task(packet, complete_packet, &done);
631         retval = hpsb_send_packet(packet);
632         if (retval == 0)
633                 wait_for_completion(&done);
634
635         return retval;
636 }
637
638 static void send_packet_nocare(struct hpsb_packet *packet)
639 {
640         if (hpsb_send_packet(packet) < 0) {
641                 hpsb_free_packet(packet);
642         }
643 }
644
645
646 static void handle_packet_response(struct hpsb_host *host, int tcode,
647                                    quadlet_t *data, size_t size)
648 {
649         struct hpsb_packet *packet = NULL;
650         struct sk_buff *skb;
651         int tcode_match = 0;
652         int tlabel;
653         unsigned long flags;
654
655         tlabel = (data[0] >> 10) & 0x3f;
656
657         spin_lock_irqsave(&host->pending_packet_queue.lock, flags);
658
659         skb_queue_walk(&host->pending_packet_queue, skb) {
660                 packet = (struct hpsb_packet *)skb->data;
661                 if ((packet->tlabel == tlabel)
662                     && (packet->node_id == (data[1] >> 16))){
663                         break;
664                 }
665
666                 packet = NULL;
667         }
668
669         if (packet == NULL) {
670                 HPSB_DEBUG("unsolicited response packet received - no tlabel match");
671                 dump_packet("contents", data, 16, -1);
672                 spin_unlock_irqrestore(&host->pending_packet_queue.lock, flags);
673                 return;
674         }
675
676         switch (packet->tcode) {
677         case TCODE_WRITEQ:
678         case TCODE_WRITEB:
679                 if (tcode != TCODE_WRITE_RESPONSE)
680                         break;
681                 tcode_match = 1;
682                 memcpy(packet->header, data, 12);
683                 break;
684         case TCODE_READQ:
685                 if (tcode != TCODE_READQ_RESPONSE)
686                         break;
687                 tcode_match = 1;
688                 memcpy(packet->header, data, 16);
689                 break;
690         case TCODE_READB:
691                 if (tcode != TCODE_READB_RESPONSE)
692                         break;
693                 tcode_match = 1;
694                 BUG_ON(packet->skb->len - sizeof(*packet) < size - 16);
695                 memcpy(packet->header, data, 16);
696                 memcpy(packet->data, data + 4, size - 16);
697                 break;
698         case TCODE_LOCK_REQUEST:
699                 if (tcode != TCODE_LOCK_RESPONSE)
700                         break;
701                 tcode_match = 1;
702                 size = min((size - 16), (size_t)8);
703                 BUG_ON(packet->skb->len - sizeof(*packet) < size);
704                 memcpy(packet->header, data, 16);
705                 memcpy(packet->data, data + 4, size);
706                 break;
707         }
708
709         if (!tcode_match) {
710                 spin_unlock_irqrestore(&host->pending_packet_queue.lock, flags);
711                 HPSB_INFO("unsolicited response packet received - tcode mismatch");
712                 dump_packet("contents", data, 16, -1);
713                 return;
714         }
715
716         __skb_unlink(skb, &host->pending_packet_queue);
717
718         if (packet->state == hpsb_queued) {
719                 packet->sendtime = jiffies;
720                 packet->ack_code = ACK_PENDING;
721         }
722
723         packet->state = hpsb_complete;
724         spin_unlock_irqrestore(&host->pending_packet_queue.lock, flags);
725
726         queue_packet_complete(packet);
727 }
728
729
730 static struct hpsb_packet *create_reply_packet(struct hpsb_host *host,
731                                                quadlet_t *data, size_t dsize)
732 {
733         struct hpsb_packet *p;
734
735         p = hpsb_alloc_packet(dsize);
736         if (unlikely(p == NULL)) {
737                 /* FIXME - send data_error response */
738                 return NULL;
739         }
740
741         p->type = hpsb_async;
742         p->state = hpsb_unused;
743         p->host = host;
744         p->node_id = data[1] >> 16;
745         p->tlabel = (data[0] >> 10) & 0x3f;
746         p->no_waiter = 1;
747
748         p->generation = get_hpsb_generation(host);
749
750         if (dsize % 4)
751                 p->data[dsize / 4] = 0;
752
753         return p;
754 }
755
756 #define PREP_ASYNC_HEAD_RCODE(tc) \
757         packet->tcode = tc; \
758         packet->header[0] = (packet->node_id << 16) | (packet->tlabel << 10) \
759                 | (1 << 8) | (tc << 4); \
760         packet->header[1] = (packet->host->node_id << 16) | (rcode << 12); \
761         packet->header[2] = 0
762
763 static void fill_async_readquad_resp(struct hpsb_packet *packet, int rcode,
764                               quadlet_t data)
765 {
766         PREP_ASYNC_HEAD_RCODE(TCODE_READQ_RESPONSE);
767         packet->header[3] = data;
768         packet->header_size = 16;
769         packet->data_size = 0;
770 }
771
772 static void fill_async_readblock_resp(struct hpsb_packet *packet, int rcode,
773                                int length)
774 {
775         if (rcode != RCODE_COMPLETE)
776                 length = 0;
777
778         PREP_ASYNC_HEAD_RCODE(TCODE_READB_RESPONSE);
779         packet->header[3] = length << 16;
780         packet->header_size = 16;
781         packet->data_size = length + (length % 4 ? 4 - (length % 4) : 0);
782 }
783
784 static void fill_async_write_resp(struct hpsb_packet *packet, int rcode)
785 {
786         PREP_ASYNC_HEAD_RCODE(TCODE_WRITE_RESPONSE);
787         packet->header[2] = 0;
788         packet->header_size = 12;
789         packet->data_size = 0;
790 }
791
792 static void fill_async_lock_resp(struct hpsb_packet *packet, int rcode, int extcode,
793                           int length)
794 {
795         if (rcode != RCODE_COMPLETE)
796                 length = 0;
797
798         PREP_ASYNC_HEAD_RCODE(TCODE_LOCK_RESPONSE);
799         packet->header[3] = (length << 16) | extcode;
800         packet->header_size = 16;
801         packet->data_size = length;
802 }
803
804 #define PREP_REPLY_PACKET(length) \
805                 packet = create_reply_packet(host, data, length); \
806                 if (packet == NULL) break
807
808 static void handle_incoming_packet(struct hpsb_host *host, int tcode,
809                                    quadlet_t *data, size_t size, int write_acked)
810 {
811         struct hpsb_packet *packet;
812         int length, rcode, extcode;
813         quadlet_t buffer;
814         nodeid_t source = data[1] >> 16;
815         nodeid_t dest = data[0] >> 16;
816         u16 flags = (u16) data[0];
817         u64 addr;
818
819         /* big FIXME - no error checking is done for an out of bounds length */
820
821         switch (tcode) {
822         case TCODE_WRITEQ:
823                 addr = (((u64)(data[1] & 0xffff)) << 32) | data[2];
824                 rcode = highlevel_write(host, source, dest, data+3,
825                                         addr, 4, flags);
826
827                 if (!write_acked
828                     && (NODEID_TO_NODE(data[0] >> 16) != NODE_MASK)
829                     && (rcode >= 0)) {
830                         /* not a broadcast write, reply */
831                         PREP_REPLY_PACKET(0);
832                         fill_async_write_resp(packet, rcode);
833                         send_packet_nocare(packet);
834                 }
835                 break;
836
837         case TCODE_WRITEB:
838                 addr = (((u64)(data[1] & 0xffff)) << 32) | data[2];
839                 rcode = highlevel_write(host, source, dest, data+4,
840                                         addr, data[3]>>16, flags);
841
842                 if (!write_acked
843                     && (NODEID_TO_NODE(data[0] >> 16) != NODE_MASK)
844                     && (rcode >= 0)) {
845                         /* not a broadcast write, reply */
846                         PREP_REPLY_PACKET(0);
847                         fill_async_write_resp(packet, rcode);
848                         send_packet_nocare(packet);
849                 }
850                 break;
851
852         case TCODE_READQ:
853                 addr = (((u64)(data[1] & 0xffff)) << 32) | data[2];
854                 rcode = highlevel_read(host, source, &buffer, addr, 4, flags);
855
856                 if (rcode >= 0) {
857                         PREP_REPLY_PACKET(0);
858                         fill_async_readquad_resp(packet, rcode, buffer);
859                         send_packet_nocare(packet);
860                 }
861                 break;
862
863         case TCODE_READB:
864                 length = data[3] >> 16;
865                 PREP_REPLY_PACKET(length);
866
867                 addr = (((u64)(data[1] & 0xffff)) << 32) | data[2];
868                 rcode = highlevel_read(host, source, packet->data, addr,
869                                        length, flags);
870
871                 if (rcode >= 0) {
872                         fill_async_readblock_resp(packet, rcode, length);
873                         send_packet_nocare(packet);
874                 } else {
875                         hpsb_free_packet(packet);
876                 }
877                 break;
878
879         case TCODE_LOCK_REQUEST:
880                 length = data[3] >> 16;
881                 extcode = data[3] & 0xffff;
882                 addr = (((u64)(data[1] & 0xffff)) << 32) | data[2];
883
884                 PREP_REPLY_PACKET(8);
885
886                 if ((extcode == 0) || (extcode >= 7)) {
887                         /* let switch default handle error */
888                         length = 0;
889                 }
890
891                 switch (length) {
892                 case 4:
893                         rcode = highlevel_lock(host, source, packet->data, addr,
894                                                data[4], 0, extcode,flags);
895                         fill_async_lock_resp(packet, rcode, extcode, 4);
896                         break;
897                 case 8:
898                         if ((extcode != EXTCODE_FETCH_ADD)
899                             && (extcode != EXTCODE_LITTLE_ADD)) {
900                                 rcode = highlevel_lock(host, source,
901                                                        packet->data, addr,
902                                                        data[5], data[4],
903                                                        extcode, flags);
904                                 fill_async_lock_resp(packet, rcode, extcode, 4);
905                         } else {
906                                 rcode = highlevel_lock64(host, source,
907                                              (octlet_t *)packet->data, addr,
908                                              *(octlet_t *)(data + 4), 0ULL,
909                                              extcode, flags);
910                                 fill_async_lock_resp(packet, rcode, extcode, 8);
911                         }
912                         break;
913                 case 16:
914                         rcode = highlevel_lock64(host, source,
915                                                  (octlet_t *)packet->data, addr,
916                                                  *(octlet_t *)(data + 6),
917                                                  *(octlet_t *)(data + 4),
918                                                  extcode, flags);
919                         fill_async_lock_resp(packet, rcode, extcode, 8);
920                         break;
921                 default:
922                         rcode = RCODE_TYPE_ERROR;
923                         fill_async_lock_resp(packet, rcode,
924                                              extcode, 0);
925                 }
926
927                 if (rcode >= 0) {
928                         send_packet_nocare(packet);
929                 } else {
930                         hpsb_free_packet(packet);
931                 }
932                 break;
933         }
934
935 }
936 #undef PREP_REPLY_PACKET
937
938
939 void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
940                           int write_acked)
941 {
942         int tcode;
943
944         if (host->in_bus_reset) {
945                 HPSB_INFO("received packet during reset; ignoring");
946                 return;
947         }
948
949         dump_packet("received packet", data, size, -1);
950
951         tcode = (data[0] >> 4) & 0xf;
952
953         switch (tcode) {
954         case TCODE_WRITE_RESPONSE:
955         case TCODE_READQ_RESPONSE:
956         case TCODE_READB_RESPONSE:
957         case TCODE_LOCK_RESPONSE:
958                 handle_packet_response(host, tcode, data, size);
959                 break;
960
961         case TCODE_WRITEQ:
962         case TCODE_WRITEB:
963         case TCODE_READQ:
964         case TCODE_READB:
965         case TCODE_LOCK_REQUEST:
966                 handle_incoming_packet(host, tcode, data, size, write_acked);
967                 break;
968
969
970         case TCODE_ISO_DATA:
971                 highlevel_iso_receive(host, data, size);
972                 break;
973
974         case TCODE_CYCLE_START:
975                 /* simply ignore this packet if it is passed on */
976                 break;
977
978         default:
979                 HPSB_NOTICE("received packet with bogus transaction code %d",
980                             tcode);
981                 break;
982         }
983 }
984
985
986 static void abort_requests(struct hpsb_host *host)
987 {
988         struct hpsb_packet *packet;
989         struct sk_buff *skb;
990
991         host->driver->devctl(host, CANCEL_REQUESTS, 0);
992
993         while ((skb = skb_dequeue(&host->pending_packet_queue)) != NULL) {
994                 packet = (struct hpsb_packet *)skb->data;
995
996                 packet->state = hpsb_complete;
997                 packet->ack_code = ACKX_ABORTED;
998                 queue_packet_complete(packet);
999         }
1000 }
1001
1002 void abort_timedouts(unsigned long __opaque)
1003 {
1004         struct hpsb_host *host = (struct hpsb_host *)__opaque;
1005         unsigned long flags;
1006         struct hpsb_packet *packet;
1007         struct sk_buff *skb;
1008         unsigned long expire;
1009
1010         spin_lock_irqsave(&host->csr.lock, flags);
1011         expire = host->csr.expire;
1012         spin_unlock_irqrestore(&host->csr.lock, flags);
1013
1014         /* Hold the lock around this, since we aren't dequeuing all
1015          * packets, just ones we need. */
1016         spin_lock_irqsave(&host->pending_packet_queue.lock, flags);
1017
1018         while (!skb_queue_empty(&host->pending_packet_queue)) {
1019                 skb = skb_peek(&host->pending_packet_queue);
1020
1021                 packet = (struct hpsb_packet *)skb->data;
1022
1023                 if (time_before(packet->sendtime + expire, jiffies)) {
1024                         __skb_unlink(skb, &host->pending_packet_queue);
1025                         packet->state = hpsb_complete;
1026                         packet->ack_code = ACKX_TIMEOUT;
1027                         queue_packet_complete(packet);
1028                 } else {
1029                         /* Since packets are added to the tail, the oldest
1030                          * ones are first, always. When we get to one that
1031                          * isn't timed out, the rest aren't either. */
1032                         break;
1033                 }
1034         }
1035
1036         if (!skb_queue_empty(&host->pending_packet_queue))
1037                 mod_timer(&host->timeout, jiffies + host->timeout_interval);
1038
1039         spin_unlock_irqrestore(&host->pending_packet_queue.lock, flags);
1040 }
1041
1042
1043 /* Kernel thread and vars, which handles packets that are completed. Only
1044  * packets that have a "complete" function are sent here. This way, the
1045  * completion is run out of kernel context, and doesn't block the rest of
1046  * the stack. */
1047 static struct task_struct *khpsbpkt_thread;
1048 static struct sk_buff_head hpsbpkt_queue;
1049
1050 static void queue_packet_complete(struct hpsb_packet *packet)
1051 {
1052         if (packet->no_waiter) {
1053                 hpsb_free_packet(packet);
1054                 return;
1055         }
1056         if (packet->complete_routine != NULL) {
1057                 skb_queue_tail(&hpsbpkt_queue, packet->skb);
1058                 wake_up_process(khpsbpkt_thread);
1059         }
1060         return;
1061 }
1062
1063 static int hpsbpkt_thread(void *__hi)
1064 {
1065         struct sk_buff *skb;
1066         struct hpsb_packet *packet;
1067         void (*complete_routine)(void*);
1068         void *complete_data;
1069
1070         current->flags |= PF_NOFREEZE;
1071
1072         while (!kthread_should_stop()) {
1073                 while ((skb = skb_dequeue(&hpsbpkt_queue)) != NULL) {
1074                         packet = (struct hpsb_packet *)skb->data;
1075
1076                         complete_routine = packet->complete_routine;
1077                         complete_data = packet->complete_data;
1078
1079                         packet->complete_routine = packet->complete_data = NULL;
1080
1081                         complete_routine(complete_data);
1082                 }
1083
1084                 set_current_state(TASK_INTERRUPTIBLE);
1085                 if (!skb_peek(&hpsbpkt_queue))
1086                         schedule();
1087                 __set_current_state(TASK_RUNNING);
1088         }
1089         return 0;
1090 }
1091
1092 static int __init ieee1394_init(void)
1093 {
1094         int i, ret;
1095
1096         skb_queue_head_init(&hpsbpkt_queue);
1097
1098         /* non-fatal error */
1099         if (hpsb_init_config_roms()) {
1100                 HPSB_ERR("Failed to initialize some config rom entries.\n");
1101                 HPSB_ERR("Some features may not be available\n");
1102         }
1103
1104         khpsbpkt_thread = kthread_run(hpsbpkt_thread, NULL, "khpsbpkt");
1105         if (IS_ERR(khpsbpkt_thread)) {
1106                 HPSB_ERR("Failed to start hpsbpkt thread!\n");
1107                 ret = PTR_ERR(khpsbpkt_thread);
1108                 goto exit_cleanup_config_roms;
1109         }
1110
1111         if (register_chrdev_region(IEEE1394_CORE_DEV, 256, "ieee1394")) {
1112                 HPSB_ERR("unable to register character device major %d!\n", IEEE1394_MAJOR);
1113                 ret = -ENODEV;
1114                 goto exit_release_kernel_thread;
1115         }
1116
1117         ret = bus_register(&ieee1394_bus_type);
1118         if (ret < 0) {
1119                 HPSB_INFO("bus register failed");
1120                 goto release_chrdev;
1121         }
1122
1123         for (i = 0; fw_bus_attrs[i]; i++) {
1124                 ret = bus_create_file(&ieee1394_bus_type, fw_bus_attrs[i]);
1125                 if (ret < 0) {
1126                         while (i >= 0) {
1127                                 bus_remove_file(&ieee1394_bus_type,
1128                                                 fw_bus_attrs[i--]);
1129                         }
1130                         bus_unregister(&ieee1394_bus_type);
1131                         goto release_chrdev;
1132                 }
1133         }
1134
1135         ret = class_register(&hpsb_host_class);
1136         if (ret < 0)
1137                 goto release_all_bus;
1138
1139         hpsb_protocol_class = class_create(THIS_MODULE, "ieee1394_protocol");
1140         if (IS_ERR(hpsb_protocol_class)) {
1141                 ret = PTR_ERR(hpsb_protocol_class);
1142                 goto release_class_host;
1143         }
1144
1145         ret = init_csr();
1146         if (ret) {
1147                 HPSB_INFO("init csr failed");
1148                 ret = -ENOMEM;
1149                 goto release_class_protocol;
1150         }
1151
1152         if (disable_nodemgr) {
1153                 HPSB_INFO("nodemgr and IRM functionality disabled");
1154                 /* We shouldn't contend for IRM with nodemgr disabled, since
1155                    nodemgr implements functionality required of ieee1394a-2000
1156                    IRMs */
1157                 hpsb_disable_irm = 1;
1158
1159                 return 0;
1160         }
1161
1162         if (hpsb_disable_irm) {
1163                 HPSB_INFO("IRM functionality disabled");
1164         }
1165
1166         ret = init_ieee1394_nodemgr();
1167         if (ret < 0) {
1168                 HPSB_INFO("init nodemgr failed");
1169                 goto cleanup_csr;
1170         }
1171
1172         return 0;
1173
1174 cleanup_csr:
1175         cleanup_csr();
1176 release_class_protocol:
1177         class_destroy(hpsb_protocol_class);
1178 release_class_host:
1179         class_unregister(&hpsb_host_class);
1180 release_all_bus:
1181         for (i = 0; fw_bus_attrs[i]; i++)
1182                 bus_remove_file(&ieee1394_bus_type, fw_bus_attrs[i]);
1183         bus_unregister(&ieee1394_bus_type);
1184 release_chrdev:
1185         unregister_chrdev_region(IEEE1394_CORE_DEV, 256);
1186 exit_release_kernel_thread:
1187         kthread_stop(khpsbpkt_thread);
1188 exit_cleanup_config_roms:
1189         hpsb_cleanup_config_roms();
1190         return ret;
1191 }
1192
1193 static void __exit ieee1394_cleanup(void)
1194 {
1195         int i;
1196
1197         if (!disable_nodemgr)
1198                 cleanup_ieee1394_nodemgr();
1199
1200         cleanup_csr();
1201
1202         class_destroy(hpsb_protocol_class);
1203         class_unregister(&hpsb_host_class);
1204         for (i = 0; fw_bus_attrs[i]; i++)
1205                 bus_remove_file(&ieee1394_bus_type, fw_bus_attrs[i]);
1206         bus_unregister(&ieee1394_bus_type);
1207
1208         kthread_stop(khpsbpkt_thread);
1209
1210         hpsb_cleanup_config_roms();
1211
1212         unregister_chrdev_region(IEEE1394_CORE_DEV, 256);
1213 }
1214
1215 fs_initcall(ieee1394_init); /* same as ohci1394 */
1216 module_exit(ieee1394_cleanup);
1217
1218 /* Exported symbols */
1219
1220 /** hosts.c **/
1221 EXPORT_SYMBOL(hpsb_alloc_host);
1222 EXPORT_SYMBOL(hpsb_add_host);
1223 EXPORT_SYMBOL(hpsb_resume_host);
1224 EXPORT_SYMBOL(hpsb_remove_host);
1225 EXPORT_SYMBOL(hpsb_update_config_rom_image);
1226
1227 /** ieee1394_core.c **/
1228 EXPORT_SYMBOL(hpsb_speedto_str);
1229 EXPORT_SYMBOL(hpsb_protocol_class);
1230 EXPORT_SYMBOL(hpsb_set_packet_complete_task);
1231 EXPORT_SYMBOL(hpsb_alloc_packet);
1232 EXPORT_SYMBOL(hpsb_free_packet);
1233 EXPORT_SYMBOL(hpsb_send_packet);
1234 EXPORT_SYMBOL(hpsb_reset_bus);
1235 EXPORT_SYMBOL(hpsb_read_cycle_timer);
1236 EXPORT_SYMBOL(hpsb_bus_reset);
1237 EXPORT_SYMBOL(hpsb_selfid_received);
1238 EXPORT_SYMBOL(hpsb_selfid_complete);
1239 EXPORT_SYMBOL(hpsb_packet_sent);
1240 EXPORT_SYMBOL(hpsb_packet_received);
1241 EXPORT_SYMBOL_GPL(hpsb_disable_irm);
1242
1243 /** ieee1394_transactions.c **/
1244 EXPORT_SYMBOL(hpsb_get_tlabel);
1245 EXPORT_SYMBOL(hpsb_free_tlabel);
1246 EXPORT_SYMBOL(hpsb_make_readpacket);
1247 EXPORT_SYMBOL(hpsb_make_writepacket);
1248 EXPORT_SYMBOL(hpsb_make_streampacket);
1249 EXPORT_SYMBOL(hpsb_make_lockpacket);
1250 EXPORT_SYMBOL(hpsb_make_lock64packet);
1251 EXPORT_SYMBOL(hpsb_make_phypacket);
1252 EXPORT_SYMBOL(hpsb_make_isopacket);
1253 EXPORT_SYMBOL(hpsb_read);
1254 EXPORT_SYMBOL(hpsb_write);
1255 EXPORT_SYMBOL(hpsb_packet_success);
1256
1257 /** highlevel.c **/
1258 EXPORT_SYMBOL(hpsb_register_highlevel);
1259 EXPORT_SYMBOL(hpsb_unregister_highlevel);
1260 EXPORT_SYMBOL(hpsb_register_addrspace);
1261 EXPORT_SYMBOL(hpsb_unregister_addrspace);
1262 EXPORT_SYMBOL(hpsb_allocate_and_register_addrspace);
1263 EXPORT_SYMBOL(hpsb_listen_channel);
1264 EXPORT_SYMBOL(hpsb_unlisten_channel);
1265 EXPORT_SYMBOL(hpsb_get_hostinfo);
1266 EXPORT_SYMBOL(hpsb_create_hostinfo);
1267 EXPORT_SYMBOL(hpsb_destroy_hostinfo);
1268 EXPORT_SYMBOL(hpsb_set_hostinfo_key);
1269 EXPORT_SYMBOL(hpsb_get_hostinfo_bykey);
1270 EXPORT_SYMBOL(hpsb_set_hostinfo);
1271 EXPORT_SYMBOL(highlevel_host_reset);
1272
1273 /** nodemgr.c **/
1274 EXPORT_SYMBOL(hpsb_node_fill_packet);
1275 EXPORT_SYMBOL(hpsb_node_write);
1276 EXPORT_SYMBOL(__hpsb_register_protocol);
1277 EXPORT_SYMBOL(hpsb_unregister_protocol);
1278
1279 /** csr.c **/
1280 EXPORT_SYMBOL(hpsb_update_config_rom);
1281
1282 /** dma.c **/
1283 EXPORT_SYMBOL(dma_prog_region_init);
1284 EXPORT_SYMBOL(dma_prog_region_alloc);
1285 EXPORT_SYMBOL(dma_prog_region_free);
1286 EXPORT_SYMBOL(dma_region_init);
1287 EXPORT_SYMBOL(dma_region_alloc);
1288 EXPORT_SYMBOL(dma_region_free);
1289 EXPORT_SYMBOL(dma_region_sync_for_cpu);
1290 EXPORT_SYMBOL(dma_region_sync_for_device);
1291 EXPORT_SYMBOL(dma_region_mmap);
1292 EXPORT_SYMBOL(dma_region_offset_to_bus);
1293
1294 /** iso.c **/
1295 EXPORT_SYMBOL(hpsb_iso_xmit_init);
1296 EXPORT_SYMBOL(hpsb_iso_recv_init);
1297 EXPORT_SYMBOL(hpsb_iso_xmit_start);
1298 EXPORT_SYMBOL(hpsb_iso_recv_start);
1299 EXPORT_SYMBOL(hpsb_iso_recv_listen_channel);
1300 EXPORT_SYMBOL(hpsb_iso_recv_unlisten_channel);
1301 EXPORT_SYMBOL(hpsb_iso_recv_set_channel_mask);
1302 EXPORT_SYMBOL(hpsb_iso_stop);
1303 EXPORT_SYMBOL(hpsb_iso_shutdown);
1304 EXPORT_SYMBOL(hpsb_iso_xmit_queue_packet);
1305 EXPORT_SYMBOL(hpsb_iso_xmit_sync);
1306 EXPORT_SYMBOL(hpsb_iso_recv_release_packets);
1307 EXPORT_SYMBOL(hpsb_iso_n_ready);
1308 EXPORT_SYMBOL(hpsb_iso_packet_sent);
1309 EXPORT_SYMBOL(hpsb_iso_packet_received);
1310 EXPORT_SYMBOL(hpsb_iso_wake);
1311 EXPORT_SYMBOL(hpsb_iso_recv_flush);
1312
1313 /** csr1212.c **/
1314 EXPORT_SYMBOL(csr1212_new_directory);
1315 EXPORT_SYMBOL(csr1212_attach_keyval_to_directory);
1316 EXPORT_SYMBOL(csr1212_detach_keyval_from_directory);
1317 EXPORT_SYMBOL(csr1212_release_keyval);
1318 EXPORT_SYMBOL(csr1212_read);
1319 EXPORT_SYMBOL(csr1212_parse_keyval);
1320 EXPORT_SYMBOL(_csr1212_read_keyval);
1321 EXPORT_SYMBOL(_csr1212_destroy_keyval);