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