4 * Core support: hpsb_packet management, packet handling and forwarding to
5 * highlevel or lowlevel code
7 * Copyright (C) 1999, 2000 Andreas E. Bombe
8 * 2002 Manfred Weihs <weihs@ict.tuwien.ac.at>
10 * This code is licensed under the GPL. See the file COPYING in the root
11 * directory of the kernel sources for details.
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)
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>
36 #include <asm/byteorder.h>
37 #include <asm/semaphore.h>
39 #include "ieee1394_types.h"
42 #include "ieee1394_core.h"
43 #include "highlevel.h"
44 #include "ieee1394_transactions.h"
49 #include "config_roms.h"
52 * Disable the nodemgr detection and config rom reading functionality.
54 static int disable_nodemgr = 0;
55 module_param(disable_nodemgr, int, 0444);
56 MODULE_PARM_DESC(disable_nodemgr, "Disable nodemgr functionality.");
58 /* We are GPL, so treat us special */
59 MODULE_LICENSE("GPL");
61 /* Some globals used */
62 const char *hpsb_speedto_str[] = { "S100", "S200", "S400", "S800", "S1600", "S3200" };
64 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
65 static void dump_packet(const char *text, quadlet_t *data, int size)
70 size = (size > 4 ? 4 : size);
72 printk(KERN_DEBUG "ieee1394: %s", text);
73 for (i = 0; i < size; i++)
74 printk(" %08x", data[i]);
78 #define dump_packet(x,y,z)
81 static void queue_packet_complete(struct hpsb_packet *packet);
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
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
93 void hpsb_set_packet_complete_task(struct hpsb_packet *packet,
94 void (*routine)(void *), void *data)
96 WARN_ON(packet->complete_routine != NULL);
97 packet->complete_routine = routine;
98 packet->complete_data = data;
103 * hpsb_alloc_packet - allocate new packet structure
104 * @data_size: size of the data block to be allocated
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.
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.
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.
119 * Return value: A pointer to a &struct hpsb_packet or NULL on allocation
122 struct hpsb_packet *hpsb_alloc_packet(size_t data_size)
124 struct hpsb_packet *packet = NULL;
127 data_size = ((data_size + 3) & ~3);
129 skb = alloc_skb(data_size + sizeof(*packet), GFP_ATOMIC);
133 memset(skb->data, 0, data_size + sizeof(*packet));
135 packet = (struct hpsb_packet *)skb->data;
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);
145 packet->data = (quadlet_t *)(skb->data + sizeof(*packet));
146 packet->data_size = data_size;
154 * hpsb_free_packet - free packet and data associated with it
155 * @packet: packet to free (is NULL safe)
157 * This function will free packet->data and finally the packet itself.
159 void hpsb_free_packet(struct hpsb_packet *packet)
161 if (packet && atomic_dec_and_test(&packet->refcnt)) {
162 BUG_ON(!list_empty(&packet->driver_list));
163 kfree_skb(packet->skb);
168 int hpsb_reset_bus(struct hpsb_host *host, int type)
170 if (!host->in_bus_reset) {
171 host->driver->devctl(host, RESET_BUS, type);
179 int hpsb_bus_reset(struct hpsb_host *host)
181 if (host->in_bus_reset) {
182 HPSB_NOTICE("%s called while bus reset already in progress",
187 abort_requests(host);
188 host->in_bus_reset = 1;
191 host->busmgr_id = -1;
194 host->node_count = 0;
195 host->selfid_count = 0;
202 * Verify num_of_selfids SelfIDs and return number of nodes. Return zero in
203 * case verification failed.
205 static int check_selfids(struct hpsb_host *host)
208 int rest_of_selfids = host->selfid_count;
209 struct selfid *sid = (struct selfid *)host->topology_map;
210 struct ext_selfid *esid;
213 host->nodes_active = 0;
215 while (rest_of_selfids--) {
216 if (!sid->extended) {
220 if (sid->phy_id != nodeid) {
221 HPSB_INFO("SelfIDs failed monotony check with "
226 if (sid->link_active) {
227 host->nodes_active++;
229 host->irm_id = LOCAL_BUS | sid->phy_id;
232 esid = (struct ext_selfid *)sid;
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);
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 "
258 sid = (struct selfid *)esid;
259 if ((sid->port0 == 0x2) || (sid->port1 == 0x2) || (sid->port2 == 0x2)) {
260 HPSB_INFO("SelfIDs failed root check");
264 host->node_count = nodeid + 1;
268 static void build_speed_map(struct hpsb_host *host, int nodecount)
270 u8 speedcap[nodecount];
271 u8 cldcnt[nodecount];
272 u8 *map = host->speed_map;
274 struct ext_selfid *esid;
277 for (i = 0; i < (nodecount * 64); i += 64) {
278 for (j = 0; j < nodecount; j++) {
279 map[i+j] = IEEE1394_SPEED_MAX;
283 for (i = 0; i < nodecount; i++) {
287 /* find direct children count and speed */
288 for (sid = (struct selfid *)&host->topology_map[host->selfid_count-1],
290 (void *)sid >= (void *)host->topology_map; sid--) {
292 esid = (struct ext_selfid *)sid;
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]++;
303 if (sid->port0 == 0x3) cldcnt[n]++;
304 if (sid->port1 == 0x3) cldcnt[n]++;
305 if (sid->port2 == 0x3) cldcnt[n]++;
307 speedcap[n] = sid->speed;
312 /* set self mapping */
313 for (i = 0; i < nodecount; i++) {
314 map[64*i + i] = speedcap[i];
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]);
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]);
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]);
342 void hpsb_selfid_received(struct hpsb_host *host, quadlet_t sid)
344 if (host->in_bus_reset) {
345 HPSB_VERBOSE("Including SelfID 0x%x", sid);
346 host->topology_map[host->selfid_count++] = sid;
348 HPSB_NOTICE("Spurious SelfID packet (0x%08x) received from bus %d",
349 sid, NODEID_TO_BUS(host->node_id));
353 void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot)
355 if (!host->in_bus_reset)
356 HPSB_NOTICE("SelfID completion called outside of bus reset!");
358 host->node_id = LOCAL_BUS | phyid;
359 host->is_root = isroot;
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);
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;
375 host->reset_retries = 0;
376 build_speed_map(host, host->node_count);
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);
382 /* irm_id is kept up to date by check_selfids() */
383 if (host->irm_id == host->node_id) {
391 host->driver->devctl(host, ACT_CYCLE_MASTER, 1);
394 atomic_inc(&host->generation);
395 host->in_bus_reset = 0;
396 highlevel_host_reset(host);
400 void hpsb_packet_sent(struct hpsb_host *host, struct hpsb_packet *packet,
405 spin_lock_irqsave(&host->pending_packet_queue.lock, flags);
407 packet->ack_code = ackcode;
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);
416 atomic_dec(&packet->refcnt); /* drop HC's reference */
417 /* here the packet must be on the host->pending_packet_queue */
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);
427 packet->state = hpsb_pending;
428 packet->sendtime = jiffies;
430 spin_unlock_irqrestore(&host->pending_packet_queue.lock, flags);
432 mod_timer(&host->timeout, jiffies + host->timeout_interval);
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)
441 * This function sends a PHY config packet on the bus through the specified host.
443 * Return value: 0 for success or error number otherwise.
445 int hpsb_send_phy_config(struct hpsb_host *host, int rootid, int gapcnt)
447 struct hpsb_packet *packet;
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",
457 packet = hpsb_alloc_packet(0);
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;
469 packet->header[0] |= rootid << 24 | 1 << 23;
471 packet->header[0] |= gapcnt << 16 | 1 << 22;
473 packet->header[1] = ~packet->header[0];
475 packet->generation = get_hpsb_generation(host);
477 retval = hpsb_send_packet_and_wait(packet);
478 hpsb_free_packet(packet);
484 * hpsb_send_packet - transmit a packet on the bus
485 * @packet: packet to send
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.
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.
495 * Return value: 0 on success, negative errno on failure.
497 int hpsb_send_packet(struct hpsb_packet *packet)
499 struct hpsb_host *host = packet->host;
501 if (host->is_shutdown)
503 if (host->in_bus_reset ||
504 (packet->generation != get_hpsb_generation(host)))
507 packet->state = hpsb_queued;
509 /* This just seems silly to me */
510 WARN_ON(packet->no_waiter && packet->expect_response);
512 if (!packet->no_waiter || packet->expect_response) {
513 atomic_inc(&packet->refcnt);
514 skb_queue_tail(&host->pending_packet_queue, packet->skb);
517 if (packet->node_id == host->node_id) {
518 /* it is a local request, so handle it locally */
521 size_t size = packet->data_size + packet->header_size;
523 data = kmalloc(size, GFP_ATOMIC);
525 HPSB_ERR("unable to allocate memory for concatenating header and data");
529 memcpy(data, packet->header, packet->header_size);
531 if (packet->data_size)
532 memcpy(((u8*)data) + packet->header_size, packet->data, packet->data_size);
534 dump_packet("send packet local:", packet->header,
535 packet->header_size);
537 hpsb_packet_sent(host, packet, packet->expect_response ? ACK_PENDING : ACK_COMPLETE);
538 hpsb_packet_received(host, data, size, 0);
545 if (packet->type == hpsb_async && packet->node_id != ALL_NODES) {
547 host->speed_map[NODEID_TO_NODE(host->node_id) * 64
548 + NODEID_TO_NODE(packet->node_id)];
551 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
552 switch (packet->speed_code) {
554 dump_packet("send packet 400:", packet->header,
555 packet->header_size);
558 dump_packet("send packet 200:", packet->header,
559 packet->header_size);
562 dump_packet("send packet 100:", packet->header,
563 packet->header_size);
567 return host->driver->transmit_packet(host, packet);
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. */
574 static void complete_packet(void *data)
576 complete((struct completion *) data);
579 int hpsb_send_packet_and_wait(struct hpsb_packet *packet)
581 struct completion done;
584 init_completion(&done);
585 hpsb_set_packet_complete_task(packet, complete_packet, &done);
586 retval = hpsb_send_packet(packet);
588 wait_for_completion(&done);
593 static void send_packet_nocare(struct hpsb_packet *packet)
595 if (hpsb_send_packet(packet) < 0) {
596 hpsb_free_packet(packet);
601 static void handle_packet_response(struct hpsb_host *host, int tcode,
602 quadlet_t *data, size_t size)
604 struct hpsb_packet *packet = NULL;
610 tlabel = (data[0] >> 10) & 0x3f;
612 spin_lock_irqsave(&host->pending_packet_queue.lock, flags);
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))){
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);
631 switch (packet->tcode) {
634 if (tcode != TCODE_WRITE_RESPONSE)
637 memcpy(packet->header, data, 12);
640 if (tcode != TCODE_READQ_RESPONSE)
643 memcpy(packet->header, data, 16);
646 if (tcode != TCODE_READB_RESPONSE)
649 BUG_ON(packet->skb->len - sizeof(*packet) < size - 16);
650 memcpy(packet->header, data, 16);
651 memcpy(packet->data, data + 4, size - 16);
653 case TCODE_LOCK_REQUEST:
654 if (tcode != TCODE_LOCK_RESPONSE)
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);
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);
671 __skb_unlink(skb, skb->list);
673 if (packet->state == hpsb_queued) {
674 packet->sendtime = jiffies;
675 packet->ack_code = ACK_PENDING;
678 packet->state = hpsb_complete;
679 spin_unlock_irqrestore(&host->pending_packet_queue.lock, flags);
681 queue_packet_complete(packet);
685 static struct hpsb_packet *create_reply_packet(struct hpsb_host *host,
686 quadlet_t *data, size_t dsize)
688 struct hpsb_packet *p;
690 p = hpsb_alloc_packet(dsize);
691 if (unlikely(p == NULL)) {
692 /* FIXME - send data_error response */
696 p->type = hpsb_async;
697 p->state = hpsb_unused;
699 p->node_id = data[1] >> 16;
700 p->tlabel = (data[0] >> 10) & 0x3f;
703 p->generation = get_hpsb_generation(host);
706 p->data[dsize / 4] = 0;
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
718 static void fill_async_readquad_resp(struct hpsb_packet *packet, int rcode,
721 PREP_ASYNC_HEAD_RCODE(TCODE_READQ_RESPONSE);
722 packet->header[3] = data;
723 packet->header_size = 16;
724 packet->data_size = 0;
727 static void fill_async_readblock_resp(struct hpsb_packet *packet, int rcode,
730 if (rcode != RCODE_COMPLETE)
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);
739 static void fill_async_write_resp(struct hpsb_packet *packet, int rcode)
741 PREP_ASYNC_HEAD_RCODE(TCODE_WRITE_RESPONSE);
742 packet->header[2] = 0;
743 packet->header_size = 12;
744 packet->data_size = 0;
747 static void fill_async_lock_resp(struct hpsb_packet *packet, int rcode, int extcode,
750 if (rcode != RCODE_COMPLETE)
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;
759 #define PREP_REPLY_PACKET(length) \
760 packet = create_reply_packet(host, data, length); \
761 if (packet == NULL) break
763 static void handle_incoming_packet(struct hpsb_host *host, int tcode,
764 quadlet_t *data, size_t size, int write_acked)
766 struct hpsb_packet *packet;
767 int length, rcode, extcode;
769 nodeid_t source = data[1] >> 16;
770 nodeid_t dest = data[0] >> 16;
771 u16 flags = (u16) data[0];
774 /* big FIXME - no error checking is done for an out of bounds length */
778 addr = (((u64)(data[1] & 0xffff)) << 32) | data[2];
779 rcode = highlevel_write(host, source, dest, data+3,
783 && (NODEID_TO_NODE(data[0] >> 16) != NODE_MASK)
785 /* not a broadcast write, reply */
786 PREP_REPLY_PACKET(0);
787 fill_async_write_resp(packet, rcode);
788 send_packet_nocare(packet);
793 addr = (((u64)(data[1] & 0xffff)) << 32) | data[2];
794 rcode = highlevel_write(host, source, dest, data+4,
795 addr, data[3]>>16, flags);
798 && (NODEID_TO_NODE(data[0] >> 16) != NODE_MASK)
800 /* not a broadcast write, reply */
801 PREP_REPLY_PACKET(0);
802 fill_async_write_resp(packet, rcode);
803 send_packet_nocare(packet);
808 addr = (((u64)(data[1] & 0xffff)) << 32) | data[2];
809 rcode = highlevel_read(host, source, &buffer, addr, 4, flags);
812 PREP_REPLY_PACKET(0);
813 fill_async_readquad_resp(packet, rcode, buffer);
814 send_packet_nocare(packet);
819 length = data[3] >> 16;
820 PREP_REPLY_PACKET(length);
822 addr = (((u64)(data[1] & 0xffff)) << 32) | data[2];
823 rcode = highlevel_read(host, source, packet->data, addr,
827 fill_async_readblock_resp(packet, rcode, length);
828 send_packet_nocare(packet);
830 hpsb_free_packet(packet);
834 case TCODE_LOCK_REQUEST:
835 length = data[3] >> 16;
836 extcode = data[3] & 0xffff;
837 addr = (((u64)(data[1] & 0xffff)) << 32) | data[2];
839 PREP_REPLY_PACKET(8);
841 if ((extcode == 0) || (extcode >= 7)) {
842 /* let switch default handle error */
848 rcode = highlevel_lock(host, source, packet->data, addr,
849 data[4], 0, extcode,flags);
850 fill_async_lock_resp(packet, rcode, extcode, 4);
853 if ((extcode != EXTCODE_FETCH_ADD)
854 && (extcode != EXTCODE_LITTLE_ADD)) {
855 rcode = highlevel_lock(host, source,
859 fill_async_lock_resp(packet, rcode, extcode, 4);
861 rcode = highlevel_lock64(host, source,
862 (octlet_t *)packet->data, addr,
863 *(octlet_t *)(data + 4), 0ULL,
865 fill_async_lock_resp(packet, rcode, extcode, 8);
869 rcode = highlevel_lock64(host, source,
870 (octlet_t *)packet->data, addr,
871 *(octlet_t *)(data + 6),
872 *(octlet_t *)(data + 4),
874 fill_async_lock_resp(packet, rcode, extcode, 8);
877 rcode = RCODE_TYPE_ERROR;
878 fill_async_lock_resp(packet, rcode,
883 send_packet_nocare(packet);
885 hpsb_free_packet(packet);
891 #undef PREP_REPLY_PACKET
894 void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
899 if (host->in_bus_reset) {
900 HPSB_INFO("received packet during reset; ignoring");
904 dump_packet("received packet:", data, size);
906 tcode = (data[0] >> 4) & 0xf;
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);
920 case TCODE_LOCK_REQUEST:
921 handle_incoming_packet(host, tcode, data, size, write_acked);
926 highlevel_iso_receive(host, data, size);
929 case TCODE_CYCLE_START:
930 /* simply ignore this packet if it is passed on */
934 HPSB_NOTICE("received packet with bogus transaction code %d",
941 void abort_requests(struct hpsb_host *host)
943 struct hpsb_packet *packet;
946 host->driver->devctl(host, CANCEL_REQUESTS, 0);
948 while ((skb = skb_dequeue(&host->pending_packet_queue)) != NULL) {
949 packet = (struct hpsb_packet *)skb->data;
951 packet->state = hpsb_complete;
952 packet->ack_code = ACKX_ABORTED;
953 queue_packet_complete(packet);
957 void abort_timedouts(unsigned long __opaque)
959 struct hpsb_host *host = (struct hpsb_host *)__opaque;
961 struct hpsb_packet *packet;
963 unsigned long expire;
965 spin_lock_irqsave(&host->csr.lock, flags);
966 expire = host->csr.expire;
967 spin_unlock_irqrestore(&host->csr.lock, flags);
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);
973 while (!skb_queue_empty(&host->pending_packet_queue)) {
974 skb = skb_peek(&host->pending_packet_queue);
976 packet = (struct hpsb_packet *)skb->data;
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);
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. */
991 if (!skb_queue_empty(&host->pending_packet_queue))
992 mod_timer(&host->timeout, jiffies + host->timeout_interval);
994 spin_unlock_irqrestore(&host->pending_packet_queue.lock, flags);
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
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);
1008 static void queue_packet_complete(struct hpsb_packet *packet)
1010 if (packet->no_waiter) {
1011 hpsb_free_packet(packet);
1014 if (packet->complete_routine != NULL) {
1015 skb_queue_tail(&hpsbpkt_queue, packet->skb);
1017 /* Signal the kernel thread to handle this */
1023 static int hpsbpkt_thread(void *__hi)
1025 struct sk_buff *skb;
1026 struct hpsb_packet *packet;
1027 void (*complete_routine)(void*);
1028 void *complete_data;
1030 daemonize("khpsbpkt");
1032 while (!down_interruptible(&khpsbpkt_sig)) {
1036 while ((skb = skb_dequeue(&hpsbpkt_queue)) != NULL) {
1037 packet = (struct hpsb_packet *)skb->data;
1039 complete_routine = packet->complete_routine;
1040 complete_data = packet->complete_data;
1042 packet->complete_routine = packet->complete_data = NULL;
1044 complete_routine(complete_data);
1048 complete_and_exit(&khpsbpkt_complete, 0);
1052 static int __init ieee1394_init(void)
1056 skb_queue_head_init(&hpsbpkt_queue);
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");
1064 khpsbpkt_pid = kernel_thread(hpsbpkt_thread, NULL, CLONE_KERNEL);
1065 if (khpsbpkt_pid < 0) {
1066 HPSB_ERR("Failed to start hpsbpkt thread!\n");
1068 goto exit_cleanup_config_roms;
1071 if (register_chrdev_region(IEEE1394_CORE_DEV, 256, "ieee1394")) {
1072 HPSB_ERR("unable to register character device major %d!\n", IEEE1394_MAJOR);
1074 goto exit_release_kernel_thread;
1077 /* actually this is a non-fatal error */
1078 ret = devfs_mk_dir("ieee1394");
1080 HPSB_ERR("unable to make devfs dir for device major %d!\n", IEEE1394_MAJOR);
1081 goto release_chrdev;
1084 ret = bus_register(&ieee1394_bus_type);
1086 HPSB_INFO("bus register failed");
1090 for (i = 0; fw_bus_attrs[i]; i++) {
1091 ret = bus_create_file(&ieee1394_bus_type, fw_bus_attrs[i]);
1094 bus_remove_file(&ieee1394_bus_type,
1097 bus_unregister(&ieee1394_bus_type);
1102 ret = class_register(&hpsb_host_class);
1104 goto release_all_bus;
1108 HPSB_INFO("init csr failed");
1113 if (disable_nodemgr) {
1114 HPSB_INFO("nodemgr functionality disabled");
1118 ret = init_ieee1394_nodemgr();
1120 HPSB_INFO("init nodemgr failed");
1129 class_unregister(&hpsb_host_class);
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);
1135 devfs_remove("ieee1394");
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);
1143 exit_cleanup_config_roms:
1144 hpsb_cleanup_config_roms();
1148 static void __exit ieee1394_cleanup(void)
1152 if (!disable_nodemgr)
1153 cleanup_ieee1394_nodemgr();
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);
1162 if (khpsbpkt_pid >= 0) {
1166 wait_for_completion(&khpsbpkt_complete);
1169 hpsb_cleanup_config_roms();
1171 unregister_chrdev_region(IEEE1394_CORE_DEV, 256);
1172 devfs_remove("ieee1394");
1175 module_init(ieee1394_init);
1176 module_exit(ieee1394_cleanup);
1178 /* Exported symbols */
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);
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);
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);
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);
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);
1255 EXPORT_SYMBOL(hpsb_update_config_rom);
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);
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);
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);