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,
403 packet->ack_code = ackcode;
405 if (packet->no_waiter) {
406 /* must not have a tlabel allocated */
407 hpsb_free_packet(packet);
411 if (ackcode != ACK_PENDING || !packet->expect_response) {
412 atomic_dec(&packet->refcnt);
413 skb_unlink(packet->skb);
414 packet->state = hpsb_complete;
415 queue_packet_complete(packet);
419 if (packet->state == hpsb_complete) {
420 hpsb_free_packet(packet);
424 atomic_dec(&packet->refcnt);
425 packet->state = hpsb_pending;
426 packet->sendtime = jiffies;
428 mod_timer(&host->timeout, jiffies + host->timeout_interval);
432 * hpsb_send_phy_config - transmit a PHY configuration packet on the bus
433 * @host: host that PHY config packet gets sent through
434 * @rootid: root whose force_root bit should get set (-1 = don't set force_root)
435 * @gapcnt: gap count value to set (-1 = don't set gap count)
437 * This function sends a PHY config packet on the bus through the specified host.
439 * Return value: 0 for success or error number otherwise.
441 int hpsb_send_phy_config(struct hpsb_host *host, int rootid, int gapcnt)
443 struct hpsb_packet *packet;
446 if (rootid >= ALL_NODES || rootid < -1 || gapcnt > 0x3f || gapcnt < -1 ||
447 (rootid == -1 && gapcnt == -1)) {
448 HPSB_DEBUG("Invalid Parameter: rootid = %d gapcnt = %d",
453 packet = hpsb_alloc_packet(0);
458 packet->header_size = 8;
459 packet->data_size = 0;
460 packet->expect_response = 0;
461 packet->no_waiter = 0;
462 packet->type = hpsb_raw;
463 packet->header[0] = 0;
465 packet->header[0] |= rootid << 24 | 1 << 23;
467 packet->header[0] |= gapcnt << 16 | 1 << 22;
469 packet->header[1] = ~packet->header[0];
471 packet->generation = get_hpsb_generation(host);
473 retval = hpsb_send_packet_and_wait(packet);
474 hpsb_free_packet(packet);
480 * hpsb_send_packet - transmit a packet on the bus
481 * @packet: packet to send
483 * The packet is sent through the host specified in the packet->host field.
484 * Before sending, the packet's transmit speed is automatically determined
485 * using the local speed map when it is an async, non-broadcast packet.
487 * Possibilities for failure are that host is either not initialized, in bus
488 * reset, the packet's generation number doesn't match the current generation
489 * number or the host reports a transmit error.
491 * Return value: 0 on success, negative errno on failure.
493 int hpsb_send_packet(struct hpsb_packet *packet)
495 struct hpsb_host *host = packet->host;
497 if (host->is_shutdown)
499 if (host->in_bus_reset ||
500 (packet->generation != get_hpsb_generation(host)))
503 packet->state = hpsb_queued;
505 /* This just seems silly to me */
506 WARN_ON(packet->no_waiter && packet->expect_response);
508 if (!packet->no_waiter || packet->expect_response) {
509 atomic_inc(&packet->refcnt);
510 skb_queue_tail(&host->pending_packet_queue, packet->skb);
513 if (packet->node_id == host->node_id) {
514 /* it is a local request, so handle it locally */
517 size_t size = packet->data_size + packet->header_size;
519 data = kmalloc(size, GFP_ATOMIC);
521 HPSB_ERR("unable to allocate memory for concatenating header and data");
525 memcpy(data, packet->header, packet->header_size);
527 if (packet->data_size)
528 memcpy(((u8*)data) + packet->header_size, packet->data, packet->data_size);
530 dump_packet("send packet local:", packet->header,
531 packet->header_size);
533 hpsb_packet_sent(host, packet, packet->expect_response ? ACK_PENDING : ACK_COMPLETE);
534 hpsb_packet_received(host, data, size, 0);
541 if (packet->type == hpsb_async && packet->node_id != ALL_NODES) {
543 host->speed_map[NODEID_TO_NODE(host->node_id) * 64
544 + NODEID_TO_NODE(packet->node_id)];
547 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
548 switch (packet->speed_code) {
550 dump_packet("send packet 400:", packet->header,
551 packet->header_size);
554 dump_packet("send packet 200:", packet->header,
555 packet->header_size);
558 dump_packet("send packet 100:", packet->header,
559 packet->header_size);
563 return host->driver->transmit_packet(host, packet);
566 /* We could just use complete() directly as the packet complete
567 * callback, but this is more typesafe, in the sense that we get a
568 * compiler error if the prototype for complete() changes. */
570 static void complete_packet(void *data)
572 complete((struct completion *) data);
575 int hpsb_send_packet_and_wait(struct hpsb_packet *packet)
577 struct completion done;
580 init_completion(&done);
581 hpsb_set_packet_complete_task(packet, complete_packet, &done);
582 retval = hpsb_send_packet(packet);
584 wait_for_completion(&done);
589 static void send_packet_nocare(struct hpsb_packet *packet)
591 if (hpsb_send_packet(packet) < 0) {
592 hpsb_free_packet(packet);
597 static void handle_packet_response(struct hpsb_host *host, int tcode,
598 quadlet_t *data, size_t size)
600 struct hpsb_packet *packet = NULL;
606 tlabel = (data[0] >> 10) & 0x3f;
608 spin_lock_irqsave(&host->pending_packet_queue.lock, flags);
610 skb_queue_walk(&host->pending_packet_queue, skb) {
611 packet = (struct hpsb_packet *)skb->data;
612 if ((packet->tlabel == tlabel)
613 && (packet->node_id == (data[1] >> 16))){
620 if (packet == NULL) {
621 HPSB_DEBUG("unsolicited response packet received - no tlabel match");
622 dump_packet("contents:", data, 16);
623 spin_unlock_irqrestore(&host->pending_packet_queue.lock, flags);
627 switch (packet->tcode) {
630 if (tcode != TCODE_WRITE_RESPONSE)
633 memcpy(packet->header, data, 12);
636 if (tcode != TCODE_READQ_RESPONSE)
639 memcpy(packet->header, data, 16);
642 if (tcode != TCODE_READB_RESPONSE)
645 BUG_ON(packet->skb->len - sizeof(*packet) < size - 16);
646 memcpy(packet->header, data, 16);
647 memcpy(packet->data, data + 4, size - 16);
649 case TCODE_LOCK_REQUEST:
650 if (tcode != TCODE_LOCK_RESPONSE)
653 size = min((size - 16), (size_t)8);
654 BUG_ON(packet->skb->len - sizeof(*packet) < size);
655 memcpy(packet->header, data, 16);
656 memcpy(packet->data, data + 4, size);
661 HPSB_INFO("unsolicited response packet received - tcode mismatch");
662 dump_packet("contents:", data, 16);
663 spin_unlock_irqrestore(&host->pending_packet_queue.lock, flags);
667 __skb_unlink(skb, skb->list);
668 spin_unlock_irqrestore(&host->pending_packet_queue.lock, flags);
670 if (packet->state == hpsb_queued) {
671 packet->sendtime = jiffies;
672 packet->ack_code = ACK_PENDING;
675 packet->state = hpsb_complete;
676 queue_packet_complete(packet);
680 static struct hpsb_packet *create_reply_packet(struct hpsb_host *host,
681 quadlet_t *data, size_t dsize)
683 struct hpsb_packet *p;
685 p = hpsb_alloc_packet(dsize);
686 if (unlikely(p == NULL)) {
687 /* FIXME - send data_error response */
691 p->type = hpsb_async;
692 p->state = hpsb_unused;
694 p->node_id = data[1] >> 16;
695 p->tlabel = (data[0] >> 10) & 0x3f;
698 p->generation = get_hpsb_generation(host);
701 p->data[dsize / 4] = 0;
706 #define PREP_ASYNC_HEAD_RCODE(tc) \
707 packet->tcode = tc; \
708 packet->header[0] = (packet->node_id << 16) | (packet->tlabel << 10) \
709 | (1 << 8) | (tc << 4); \
710 packet->header[1] = (packet->host->node_id << 16) | (rcode << 12); \
711 packet->header[2] = 0
713 static void fill_async_readquad_resp(struct hpsb_packet *packet, int rcode,
716 PREP_ASYNC_HEAD_RCODE(TCODE_READQ_RESPONSE);
717 packet->header[3] = data;
718 packet->header_size = 16;
719 packet->data_size = 0;
722 static void fill_async_readblock_resp(struct hpsb_packet *packet, int rcode,
725 if (rcode != RCODE_COMPLETE)
728 PREP_ASYNC_HEAD_RCODE(TCODE_READB_RESPONSE);
729 packet->header[3] = length << 16;
730 packet->header_size = 16;
731 packet->data_size = length + (length % 4 ? 4 - (length % 4) : 0);
734 static void fill_async_write_resp(struct hpsb_packet *packet, int rcode)
736 PREP_ASYNC_HEAD_RCODE(TCODE_WRITE_RESPONSE);
737 packet->header[2] = 0;
738 packet->header_size = 12;
739 packet->data_size = 0;
742 static void fill_async_lock_resp(struct hpsb_packet *packet, int rcode, int extcode,
745 if (rcode != RCODE_COMPLETE)
748 PREP_ASYNC_HEAD_RCODE(TCODE_LOCK_RESPONSE);
749 packet->header[3] = (length << 16) | extcode;
750 packet->header_size = 16;
751 packet->data_size = length;
754 #define PREP_REPLY_PACKET(length) \
755 packet = create_reply_packet(host, data, length); \
756 if (packet == NULL) break
758 static void handle_incoming_packet(struct hpsb_host *host, int tcode,
759 quadlet_t *data, size_t size, int write_acked)
761 struct hpsb_packet *packet;
762 int length, rcode, extcode;
764 nodeid_t source = data[1] >> 16;
765 nodeid_t dest = data[0] >> 16;
766 u16 flags = (u16) data[0];
769 /* big FIXME - no error checking is done for an out of bounds length */
773 addr = (((u64)(data[1] & 0xffff)) << 32) | data[2];
774 rcode = highlevel_write(host, source, dest, data+3,
778 && (NODEID_TO_NODE(data[0] >> 16) != NODE_MASK)
780 /* not a broadcast write, reply */
781 PREP_REPLY_PACKET(0);
782 fill_async_write_resp(packet, rcode);
783 send_packet_nocare(packet);
788 addr = (((u64)(data[1] & 0xffff)) << 32) | data[2];
789 rcode = highlevel_write(host, source, dest, data+4,
790 addr, data[3]>>16, flags);
793 && (NODEID_TO_NODE(data[0] >> 16) != NODE_MASK)
795 /* not a broadcast write, reply */
796 PREP_REPLY_PACKET(0);
797 fill_async_write_resp(packet, rcode);
798 send_packet_nocare(packet);
803 addr = (((u64)(data[1] & 0xffff)) << 32) | data[2];
804 rcode = highlevel_read(host, source, &buffer, addr, 4, flags);
807 PREP_REPLY_PACKET(0);
808 fill_async_readquad_resp(packet, rcode, buffer);
809 send_packet_nocare(packet);
814 length = data[3] >> 16;
815 PREP_REPLY_PACKET(length);
817 addr = (((u64)(data[1] & 0xffff)) << 32) | data[2];
818 rcode = highlevel_read(host, source, packet->data, addr,
822 fill_async_readblock_resp(packet, rcode, length);
823 send_packet_nocare(packet);
825 hpsb_free_packet(packet);
829 case TCODE_LOCK_REQUEST:
830 length = data[3] >> 16;
831 extcode = data[3] & 0xffff;
832 addr = (((u64)(data[1] & 0xffff)) << 32) | data[2];
834 PREP_REPLY_PACKET(8);
836 if ((extcode == 0) || (extcode >= 7)) {
837 /* let switch default handle error */
843 rcode = highlevel_lock(host, source, packet->data, addr,
844 data[4], 0, extcode,flags);
845 fill_async_lock_resp(packet, rcode, extcode, 4);
848 if ((extcode != EXTCODE_FETCH_ADD)
849 && (extcode != EXTCODE_LITTLE_ADD)) {
850 rcode = highlevel_lock(host, source,
854 fill_async_lock_resp(packet, rcode, extcode, 4);
856 rcode = highlevel_lock64(host, source,
857 (octlet_t *)packet->data, addr,
858 *(octlet_t *)(data + 4), 0ULL,
860 fill_async_lock_resp(packet, rcode, extcode, 8);
864 rcode = highlevel_lock64(host, source,
865 (octlet_t *)packet->data, addr,
866 *(octlet_t *)(data + 6),
867 *(octlet_t *)(data + 4),
869 fill_async_lock_resp(packet, rcode, extcode, 8);
872 rcode = RCODE_TYPE_ERROR;
873 fill_async_lock_resp(packet, rcode,
878 send_packet_nocare(packet);
880 hpsb_free_packet(packet);
886 #undef PREP_REPLY_PACKET
889 void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
894 if (host->in_bus_reset) {
895 HPSB_INFO("received packet during reset; ignoring");
899 dump_packet("received packet:", data, size);
901 tcode = (data[0] >> 4) & 0xf;
904 case TCODE_WRITE_RESPONSE:
905 case TCODE_READQ_RESPONSE:
906 case TCODE_READB_RESPONSE:
907 case TCODE_LOCK_RESPONSE:
908 handle_packet_response(host, tcode, data, size);
915 case TCODE_LOCK_REQUEST:
916 handle_incoming_packet(host, tcode, data, size, write_acked);
921 highlevel_iso_receive(host, data, size);
924 case TCODE_CYCLE_START:
925 /* simply ignore this packet if it is passed on */
929 HPSB_NOTICE("received packet with bogus transaction code %d",
936 void abort_requests(struct hpsb_host *host)
938 struct hpsb_packet *packet;
941 host->driver->devctl(host, CANCEL_REQUESTS, 0);
943 while ((skb = skb_dequeue(&host->pending_packet_queue)) != NULL) {
944 packet = (struct hpsb_packet *)skb->data;
946 packet->state = hpsb_complete;
947 packet->ack_code = ACKX_ABORTED;
948 queue_packet_complete(packet);
952 void abort_timedouts(unsigned long __opaque)
954 struct hpsb_host *host = (struct hpsb_host *)__opaque;
956 struct hpsb_packet *packet;
958 unsigned long expire;
960 spin_lock_irqsave(&host->csr.lock, flags);
961 expire = host->csr.expire;
962 spin_unlock_irqrestore(&host->csr.lock, flags);
964 /* Hold the lock around this, since we aren't dequeuing all
965 * packets, just ones we need. */
966 spin_lock_irqsave(&host->pending_packet_queue.lock, flags);
968 while (!skb_queue_empty(&host->pending_packet_queue)) {
969 skb = skb_peek(&host->pending_packet_queue);
971 packet = (struct hpsb_packet *)skb->data;
973 if (time_before(packet->sendtime + expire, jiffies)) {
974 __skb_unlink(skb, skb->list);
975 packet->state = hpsb_complete;
976 packet->ack_code = ACKX_TIMEOUT;
977 queue_packet_complete(packet);
979 /* Since packets are added to the tail, the oldest
980 * ones are first, always. When we get to one that
981 * isn't timed out, the rest aren't either. */
986 if (!skb_queue_empty(&host->pending_packet_queue))
987 mod_timer(&host->timeout, jiffies + host->timeout_interval);
989 spin_unlock_irqrestore(&host->pending_packet_queue.lock, flags);
993 /* Kernel thread and vars, which handles packets that are completed. Only
994 * packets that have a "complete" function are sent here. This way, the
995 * completion is run out of kernel context, and doesn't block the rest of
997 static int khpsbpkt_pid = -1, khpsbpkt_kill;
998 static DECLARE_COMPLETION(khpsbpkt_complete);
999 struct sk_buff_head hpsbpkt_queue;
1000 static DECLARE_MUTEX_LOCKED(khpsbpkt_sig);
1003 static void queue_packet_complete(struct hpsb_packet *packet)
1005 if (packet->complete_routine != NULL) {
1006 skb_queue_tail(&hpsbpkt_queue, packet->skb);
1008 /* Signal the kernel thread to handle this */
1014 static int hpsbpkt_thread(void *__hi)
1016 struct sk_buff *skb;
1017 struct hpsb_packet *packet;
1018 void (*complete_routine)(void*);
1019 void *complete_data;
1021 daemonize("khpsbpkt");
1023 while (!down_interruptible(&khpsbpkt_sig)) {
1027 while ((skb = skb_dequeue(&hpsbpkt_queue)) != NULL) {
1028 packet = (struct hpsb_packet *)skb->data;
1030 complete_routine = packet->complete_routine;
1031 complete_data = packet->complete_data;
1033 packet->complete_routine = packet->complete_data = NULL;
1035 complete_routine(complete_data);
1039 complete_and_exit(&khpsbpkt_complete, 0);
1043 static int __init ieee1394_init(void)
1047 skb_queue_head_init(&hpsbpkt_queue);
1049 if (hpsb_init_config_roms()) {
1050 HPSB_ERR("Failed to initialize some config rom entries.\n");
1051 HPSB_ERR("Some features may not be available\n");
1054 khpsbpkt_pid = kernel_thread(hpsbpkt_thread, NULL, CLONE_KERNEL);
1055 if (khpsbpkt_pid < 0) {
1056 HPSB_ERR("Failed to start hpsbpkt thread!\n");
1060 devfs_mk_dir("ieee1394");
1062 if (register_chrdev_region(IEEE1394_CORE_DEV, 256, "ieee1394")) {
1063 HPSB_ERR("unable to register character device major %d!\n", IEEE1394_MAJOR);
1067 devfs_mk_dir("ieee1394");
1069 bus_register(&ieee1394_bus_type);
1070 for (i = 0; fw_bus_attrs[i]; i++)
1071 bus_create_file(&ieee1394_bus_type, fw_bus_attrs[i]);
1072 class_register(&hpsb_host_class);
1077 if (!disable_nodemgr)
1078 init_ieee1394_nodemgr();
1080 HPSB_INFO("nodemgr functionality disabled");
1085 static void __exit ieee1394_cleanup(void)
1089 if (!disable_nodemgr)
1090 cleanup_ieee1394_nodemgr();
1094 class_unregister(&hpsb_host_class);
1095 for (i = 0; fw_bus_attrs[i]; i++)
1096 bus_remove_file(&ieee1394_bus_type, fw_bus_attrs[i]);
1097 bus_unregister(&ieee1394_bus_type);
1099 if (khpsbpkt_pid >= 0) {
1103 wait_for_completion(&khpsbpkt_complete);
1106 hpsb_cleanup_config_roms();
1108 unregister_chrdev_region(IEEE1394_CORE_DEV, 256);
1109 devfs_remove("ieee1394");
1112 module_init(ieee1394_init);
1113 module_exit(ieee1394_cleanup);
1115 /* Exported symbols */
1118 EXPORT_SYMBOL(hpsb_alloc_host);
1119 EXPORT_SYMBOL(hpsb_add_host);
1120 EXPORT_SYMBOL(hpsb_remove_host);
1121 EXPORT_SYMBOL(hpsb_update_config_rom_image);
1123 /** ieee1394_core.c **/
1124 EXPORT_SYMBOL(hpsb_speedto_str);
1125 EXPORT_SYMBOL(hpsb_set_packet_complete_task);
1126 EXPORT_SYMBOL(hpsb_alloc_packet);
1127 EXPORT_SYMBOL(hpsb_free_packet);
1128 EXPORT_SYMBOL(hpsb_send_phy_config);
1129 EXPORT_SYMBOL(hpsb_send_packet);
1130 EXPORT_SYMBOL(hpsb_send_packet_and_wait);
1131 EXPORT_SYMBOL(hpsb_reset_bus);
1132 EXPORT_SYMBOL(hpsb_bus_reset);
1133 EXPORT_SYMBOL(hpsb_selfid_received);
1134 EXPORT_SYMBOL(hpsb_selfid_complete);
1135 EXPORT_SYMBOL(hpsb_packet_sent);
1136 EXPORT_SYMBOL(hpsb_packet_received);
1138 /** ieee1394_transactions.c **/
1139 EXPORT_SYMBOL(hpsb_get_tlabel);
1140 EXPORT_SYMBOL(hpsb_free_tlabel);
1141 EXPORT_SYMBOL(hpsb_make_readpacket);
1142 EXPORT_SYMBOL(hpsb_make_writepacket);
1143 EXPORT_SYMBOL(hpsb_make_streampacket);
1144 EXPORT_SYMBOL(hpsb_make_lockpacket);
1145 EXPORT_SYMBOL(hpsb_make_lock64packet);
1146 EXPORT_SYMBOL(hpsb_make_phypacket);
1147 EXPORT_SYMBOL(hpsb_make_isopacket);
1148 EXPORT_SYMBOL(hpsb_read);
1149 EXPORT_SYMBOL(hpsb_write);
1150 EXPORT_SYMBOL(hpsb_lock);
1151 EXPORT_SYMBOL(hpsb_lock64);
1152 EXPORT_SYMBOL(hpsb_send_gasp);
1153 EXPORT_SYMBOL(hpsb_packet_success);
1156 EXPORT_SYMBOL(hpsb_register_highlevel);
1157 EXPORT_SYMBOL(hpsb_unregister_highlevel);
1158 EXPORT_SYMBOL(hpsb_register_addrspace);
1159 EXPORT_SYMBOL(hpsb_unregister_addrspace);
1160 EXPORT_SYMBOL(hpsb_allocate_and_register_addrspace);
1161 EXPORT_SYMBOL(hpsb_listen_channel);
1162 EXPORT_SYMBOL(hpsb_unlisten_channel);
1163 EXPORT_SYMBOL(hpsb_get_hostinfo);
1164 EXPORT_SYMBOL(hpsb_get_host_bykey);
1165 EXPORT_SYMBOL(hpsb_create_hostinfo);
1166 EXPORT_SYMBOL(hpsb_destroy_hostinfo);
1167 EXPORT_SYMBOL(hpsb_set_hostinfo_key);
1168 EXPORT_SYMBOL(hpsb_get_hostinfo_key);
1169 EXPORT_SYMBOL(hpsb_get_hostinfo_bykey);
1170 EXPORT_SYMBOL(hpsb_set_hostinfo);
1171 EXPORT_SYMBOL(highlevel_read);
1172 EXPORT_SYMBOL(highlevel_write);
1173 EXPORT_SYMBOL(highlevel_lock);
1174 EXPORT_SYMBOL(highlevel_lock64);
1175 EXPORT_SYMBOL(highlevel_add_host);
1176 EXPORT_SYMBOL(highlevel_remove_host);
1177 EXPORT_SYMBOL(highlevel_host_reset);
1180 EXPORT_SYMBOL(hpsb_guid_get_entry);
1181 EXPORT_SYMBOL(hpsb_nodeid_get_entry);
1182 EXPORT_SYMBOL(hpsb_node_fill_packet);
1183 EXPORT_SYMBOL(hpsb_node_read);
1184 EXPORT_SYMBOL(hpsb_node_write);
1185 EXPORT_SYMBOL(hpsb_node_lock);
1186 EXPORT_SYMBOL(hpsb_register_protocol);
1187 EXPORT_SYMBOL(hpsb_unregister_protocol);
1188 EXPORT_SYMBOL(ieee1394_bus_type);
1189 EXPORT_SYMBOL(nodemgr_for_each_host);
1192 EXPORT_SYMBOL(hpsb_update_config_rom);
1195 EXPORT_SYMBOL(dma_prog_region_init);
1196 EXPORT_SYMBOL(dma_prog_region_alloc);
1197 EXPORT_SYMBOL(dma_prog_region_free);
1198 EXPORT_SYMBOL(dma_region_init);
1199 EXPORT_SYMBOL(dma_region_alloc);
1200 EXPORT_SYMBOL(dma_region_free);
1201 EXPORT_SYMBOL(dma_region_sync_for_cpu);
1202 EXPORT_SYMBOL(dma_region_sync_for_device);
1203 EXPORT_SYMBOL(dma_region_mmap);
1204 EXPORT_SYMBOL(dma_region_offset_to_bus);
1207 EXPORT_SYMBOL(hpsb_iso_xmit_init);
1208 EXPORT_SYMBOL(hpsb_iso_recv_init);
1209 EXPORT_SYMBOL(hpsb_iso_xmit_start);
1210 EXPORT_SYMBOL(hpsb_iso_recv_start);
1211 EXPORT_SYMBOL(hpsb_iso_recv_listen_channel);
1212 EXPORT_SYMBOL(hpsb_iso_recv_unlisten_channel);
1213 EXPORT_SYMBOL(hpsb_iso_recv_set_channel_mask);
1214 EXPORT_SYMBOL(hpsb_iso_stop);
1215 EXPORT_SYMBOL(hpsb_iso_shutdown);
1216 EXPORT_SYMBOL(hpsb_iso_xmit_queue_packet);
1217 EXPORT_SYMBOL(hpsb_iso_xmit_sync);
1218 EXPORT_SYMBOL(hpsb_iso_recv_release_packets);
1219 EXPORT_SYMBOL(hpsb_iso_n_ready);
1220 EXPORT_SYMBOL(hpsb_iso_packet_sent);
1221 EXPORT_SYMBOL(hpsb_iso_packet_received);
1222 EXPORT_SYMBOL(hpsb_iso_wake);
1223 EXPORT_SYMBOL(hpsb_iso_recv_flush);
1226 EXPORT_SYMBOL(csr1212_create_csr);
1227 EXPORT_SYMBOL(csr1212_init_local_csr);
1228 EXPORT_SYMBOL(csr1212_new_immediate);
1229 EXPORT_SYMBOL(csr1212_new_leaf);
1230 EXPORT_SYMBOL(csr1212_new_csr_offset);
1231 EXPORT_SYMBOL(csr1212_new_directory);
1232 EXPORT_SYMBOL(csr1212_associate_keyval);
1233 EXPORT_SYMBOL(csr1212_attach_keyval_to_directory);
1234 EXPORT_SYMBOL(csr1212_new_extended_immediate);
1235 EXPORT_SYMBOL(csr1212_new_extended_leaf);
1236 EXPORT_SYMBOL(csr1212_new_descriptor_leaf);
1237 EXPORT_SYMBOL(csr1212_new_textual_descriptor_leaf);
1238 EXPORT_SYMBOL(csr1212_new_string_descriptor_leaf);
1239 EXPORT_SYMBOL(csr1212_new_icon_descriptor_leaf);
1240 EXPORT_SYMBOL(csr1212_new_modifiable_descriptor_leaf);
1241 EXPORT_SYMBOL(csr1212_new_keyword_leaf);
1242 EXPORT_SYMBOL(csr1212_detach_keyval_from_directory);
1243 EXPORT_SYMBOL(csr1212_disassociate_keyval);
1244 EXPORT_SYMBOL(csr1212_release_keyval);
1245 EXPORT_SYMBOL(csr1212_destroy_csr);
1246 EXPORT_SYMBOL(csr1212_read);
1247 EXPORT_SYMBOL(csr1212_generate_positions);
1248 EXPORT_SYMBOL(csr1212_generate_layout_order);
1249 EXPORT_SYMBOL(csr1212_fill_cache);
1250 EXPORT_SYMBOL(csr1212_generate_csr_image);
1251 EXPORT_SYMBOL(csr1212_parse_keyval);
1252 EXPORT_SYMBOL(csr1212_parse_csr);
1253 EXPORT_SYMBOL(_csr1212_read_keyval);
1254 EXPORT_SYMBOL(_csr1212_destroy_keyval);