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>
35 #include <linux/suspend.h>
37 #include <asm/byteorder.h>
38 #include <asm/semaphore.h>
40 #include "ieee1394_types.h"
43 #include "ieee1394_core.h"
44 #include "highlevel.h"
45 #include "ieee1394_transactions.h"
50 #include "config_roms.h"
53 * Disable the nodemgr detection and config rom reading functionality.
55 static int disable_nodemgr
;
56 module_param(disable_nodemgr
, int, 0444);
57 MODULE_PARM_DESC(disable_nodemgr
, "Disable nodemgr functionality.");
59 /* Disable Isochronous Resource Manager functionality */
60 int hpsb_disable_irm
= 0;
61 module_param_named(disable_irm
, hpsb_disable_irm
, bool, 0);
62 MODULE_PARM_DESC(disable_irm
,
63 "Disable Isochronous Resource Manager functionality.");
65 /* We are GPL, so treat us special */
66 MODULE_LICENSE("GPL");
68 /* Some globals used */
69 const char *hpsb_speedto_str
[] = { "S100", "S200", "S400", "S800", "S1600", "S3200" };
70 struct class *hpsb_protocol_class
;
72 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
73 static void dump_packet(const char *text
, quadlet_t
*data
, int size
, int speed
)
78 size
= (size
> 4 ? 4 : size
);
80 printk(KERN_DEBUG
"ieee1394: %s", text
);
81 if (speed
> -1 && speed
< 6)
82 printk(" at %s", hpsb_speedto_str
[speed
]);
84 for (i
= 0; i
< size
; i
++)
85 printk(" %08x", data
[i
]);
89 #define dump_packet(a,b,c,d)
92 static void abort_requests(struct hpsb_host
*host
);
93 static void queue_packet_complete(struct hpsb_packet
*packet
);
97 * hpsb_set_packet_complete_task - set the task that runs when a packet
98 * completes. You cannot call this more than once on a single packet
101 * @packet: the packet whose completion we want the task added to
102 * @routine: function to call
103 * @data: data (if any) to pass to the above function
105 void hpsb_set_packet_complete_task(struct hpsb_packet
*packet
,
106 void (*routine
)(void *), void *data
)
108 WARN_ON(packet
->complete_routine
!= NULL
);
109 packet
->complete_routine
= routine
;
110 packet
->complete_data
= data
;
115 * hpsb_alloc_packet - allocate new packet structure
116 * @data_size: size of the data block to be allocated
118 * This function allocates, initializes and returns a new &struct hpsb_packet.
119 * It can be used in interrupt context. A header block is always included, its
120 * size is big enough to contain all possible 1394 headers. The data block is
121 * only allocated when @data_size is not zero.
123 * For packets for which responses will be received the @data_size has to be big
124 * enough to contain the response's data block since no further allocation
125 * occurs at response matching time.
127 * The packet's generation value will be set to the current generation number
128 * for ease of use. Remember to overwrite it with your own recorded generation
129 * number if you can not be sure that your code will not race with a bus reset.
131 * Return value: A pointer to a &struct hpsb_packet or NULL on allocation
134 struct hpsb_packet
*hpsb_alloc_packet(size_t data_size
)
136 struct hpsb_packet
*packet
= NULL
;
139 data_size
= ((data_size
+ 3) & ~3);
141 skb
= alloc_skb(data_size
+ sizeof(*packet
), GFP_ATOMIC
);
145 memset(skb
->data
, 0, data_size
+ sizeof(*packet
));
147 packet
= (struct hpsb_packet
*)skb
->data
;
150 packet
->header
= packet
->embedded_header
;
151 packet
->state
= hpsb_unused
;
152 packet
->generation
= -1;
153 INIT_LIST_HEAD(&packet
->driver_list
);
154 atomic_set(&packet
->refcnt
, 1);
157 packet
->data
= (quadlet_t
*)(skb
->data
+ sizeof(*packet
));
158 packet
->data_size
= data_size
;
166 * hpsb_free_packet - free packet and data associated with it
167 * @packet: packet to free (is NULL safe)
169 * This function will free packet->data and finally the packet itself.
171 void hpsb_free_packet(struct hpsb_packet
*packet
)
173 if (packet
&& atomic_dec_and_test(&packet
->refcnt
)) {
174 BUG_ON(!list_empty(&packet
->driver_list
));
175 kfree_skb(packet
->skb
);
180 int hpsb_reset_bus(struct hpsb_host
*host
, int type
)
182 if (!host
->in_bus_reset
) {
183 host
->driver
->devctl(host
, RESET_BUS
, type
);
191 int hpsb_bus_reset(struct hpsb_host
*host
)
193 if (host
->in_bus_reset
) {
194 HPSB_NOTICE("%s called while bus reset already in progress",
199 abort_requests(host
);
200 host
->in_bus_reset
= 1;
203 host
->busmgr_id
= -1;
206 host
->node_count
= 0;
207 host
->selfid_count
= 0;
214 * Verify num_of_selfids SelfIDs and return number of nodes. Return zero in
215 * case verification failed.
217 static int check_selfids(struct hpsb_host
*host
)
220 int rest_of_selfids
= host
->selfid_count
;
221 struct selfid
*sid
= (struct selfid
*)host
->topology_map
;
222 struct ext_selfid
*esid
;
225 host
->nodes_active
= 0;
227 while (rest_of_selfids
--) {
228 if (!sid
->extended
) {
232 if (sid
->phy_id
!= nodeid
) {
233 HPSB_INFO("SelfIDs failed monotony check with "
238 if (sid
->link_active
) {
239 host
->nodes_active
++;
241 host
->irm_id
= LOCAL_BUS
| sid
->phy_id
;
244 esid
= (struct ext_selfid
*)sid
;
246 if ((esid
->phy_id
!= nodeid
)
247 || (esid
->seq_nr
!= esid_seq
)) {
248 HPSB_INFO("SelfIDs failed monotony check with "
249 "%d/%d", esid
->phy_id
, esid
->seq_nr
);
257 esid
= (struct ext_selfid
*)(sid
- 1);
258 while (esid
->extended
) {
259 if ((esid
->porta
== 0x2) || (esid
->portb
== 0x2)
260 || (esid
->portc
== 0x2) || (esid
->portd
== 0x2)
261 || (esid
->porte
== 0x2) || (esid
->portf
== 0x2)
262 || (esid
->portg
== 0x2) || (esid
->porth
== 0x2)) {
263 HPSB_INFO("SelfIDs failed root check on "
270 sid
= (struct selfid
*)esid
;
271 if ((sid
->port0
== 0x2) || (sid
->port1
== 0x2) || (sid
->port2
== 0x2)) {
272 HPSB_INFO("SelfIDs failed root check");
276 host
->node_count
= nodeid
+ 1;
280 static void build_speed_map(struct hpsb_host
*host
, int nodecount
)
282 u8 speedcap
[nodecount
];
283 u8 cldcnt
[nodecount
];
284 u8
*map
= host
->speed_map
;
286 struct ext_selfid
*esid
;
289 for (i
= 0; i
< (nodecount
* 64); i
+= 64) {
290 for (j
= 0; j
< nodecount
; j
++) {
291 map
[i
+j
] = IEEE1394_SPEED_MAX
;
295 for (i
= 0; i
< nodecount
; i
++) {
299 /* find direct children count and speed */
300 for (sid
= (struct selfid
*)&host
->topology_map
[host
->selfid_count
-1],
302 (void *)sid
>= (void *)host
->topology_map
; sid
--) {
304 esid
= (struct ext_selfid
*)sid
;
306 if (esid
->porta
== 0x3) cldcnt
[n
]++;
307 if (esid
->portb
== 0x3) cldcnt
[n
]++;
308 if (esid
->portc
== 0x3) cldcnt
[n
]++;
309 if (esid
->portd
== 0x3) cldcnt
[n
]++;
310 if (esid
->porte
== 0x3) cldcnt
[n
]++;
311 if (esid
->portf
== 0x3) cldcnt
[n
]++;
312 if (esid
->portg
== 0x3) cldcnt
[n
]++;
313 if (esid
->porth
== 0x3) cldcnt
[n
]++;
315 if (sid
->port0
== 0x3) cldcnt
[n
]++;
316 if (sid
->port1
== 0x3) cldcnt
[n
]++;
317 if (sid
->port2
== 0x3) cldcnt
[n
]++;
319 speedcap
[n
] = sid
->speed
;
324 /* set self mapping */
325 for (i
= 0; i
< nodecount
; i
++) {
326 map
[64*i
+ i
] = speedcap
[i
];
329 /* fix up direct children count to total children count;
330 * also fix up speedcaps for sibling and parent communication */
331 for (i
= 1; i
< nodecount
; i
++) {
332 for (j
= cldcnt
[i
], n
= i
- 1; j
> 0; j
--) {
333 cldcnt
[i
] += cldcnt
[n
];
334 speedcap
[n
] = min(speedcap
[n
], speedcap
[i
]);
339 for (n
= 0; n
< nodecount
; n
++) {
340 for (i
= n
- cldcnt
[n
]; i
<= n
; i
++) {
341 for (j
= 0; j
< (n
- cldcnt
[n
]); j
++) {
342 map
[j
*64 + i
] = map
[i
*64 + j
] =
343 min(map
[i
*64 + j
], speedcap
[n
]);
345 for (j
= n
+ 1; j
< nodecount
; j
++) {
346 map
[j
*64 + i
] = map
[i
*64 + j
] =
347 min(map
[i
*64 + j
], speedcap
[n
]);
354 void hpsb_selfid_received(struct hpsb_host
*host
, quadlet_t sid
)
356 if (host
->in_bus_reset
) {
357 HPSB_VERBOSE("Including SelfID 0x%x", sid
);
358 host
->topology_map
[host
->selfid_count
++] = sid
;
360 HPSB_NOTICE("Spurious SelfID packet (0x%08x) received from bus %d",
361 sid
, NODEID_TO_BUS(host
->node_id
));
365 void hpsb_selfid_complete(struct hpsb_host
*host
, int phyid
, int isroot
)
367 if (!host
->in_bus_reset
)
368 HPSB_NOTICE("SelfID completion called outside of bus reset!");
370 host
->node_id
= LOCAL_BUS
| phyid
;
371 host
->is_root
= isroot
;
373 if (!check_selfids(host
)) {
374 if (host
->reset_retries
++ < 20) {
375 /* selfid stage did not complete without error */
376 HPSB_NOTICE("Error in SelfID stage, resetting");
377 host
->in_bus_reset
= 0;
378 /* this should work from ohci1394 now... */
379 hpsb_reset_bus(host
, LONG_RESET
);
382 HPSB_NOTICE("Stopping out-of-control reset loop");
383 HPSB_NOTICE("Warning - topology map and speed map will not be valid");
384 host
->reset_retries
= 0;
387 host
->reset_retries
= 0;
388 build_speed_map(host
, host
->node_count
);
391 HPSB_VERBOSE("selfid_complete called with successful SelfID stage "
392 "... irm_id: 0x%X node_id: 0x%X",host
->irm_id
,host
->node_id
);
394 /* irm_id is kept up to date by check_selfids() */
395 if (host
->irm_id
== host
->node_id
) {
403 host
->driver
->devctl(host
, ACT_CYCLE_MASTER
, 1);
406 atomic_inc(&host
->generation
);
407 host
->in_bus_reset
= 0;
408 highlevel_host_reset(host
);
412 void hpsb_packet_sent(struct hpsb_host
*host
, struct hpsb_packet
*packet
,
417 spin_lock_irqsave(&host
->pending_packet_queue
.lock
, flags
);
419 packet
->ack_code
= ackcode
;
421 if (packet
->no_waiter
|| packet
->state
== hpsb_complete
) {
422 /* if packet->no_waiter, must not have a tlabel allocated */
423 spin_unlock_irqrestore(&host
->pending_packet_queue
.lock
, flags
);
424 hpsb_free_packet(packet
);
428 atomic_dec(&packet
->refcnt
); /* drop HC's reference */
429 /* here the packet must be on the host->pending_packet_queue */
431 if (ackcode
!= ACK_PENDING
|| !packet
->expect_response
) {
432 packet
->state
= hpsb_complete
;
433 __skb_unlink(packet
->skb
, &host
->pending_packet_queue
);
434 spin_unlock_irqrestore(&host
->pending_packet_queue
.lock
, flags
);
435 queue_packet_complete(packet
);
439 packet
->state
= hpsb_pending
;
440 packet
->sendtime
= jiffies
;
442 spin_unlock_irqrestore(&host
->pending_packet_queue
.lock
, flags
);
444 mod_timer(&host
->timeout
, jiffies
+ host
->timeout_interval
);
448 * hpsb_send_phy_config - transmit a PHY configuration packet on the bus
449 * @host: host that PHY config packet gets sent through
450 * @rootid: root whose force_root bit should get set (-1 = don't set force_root)
451 * @gapcnt: gap count value to set (-1 = don't set gap count)
453 * This function sends a PHY config packet on the bus through the specified host.
455 * Return value: 0 for success or error number otherwise.
457 int hpsb_send_phy_config(struct hpsb_host
*host
, int rootid
, int gapcnt
)
459 struct hpsb_packet
*packet
;
462 if (rootid
>= ALL_NODES
|| rootid
< -1 || gapcnt
> 0x3f || gapcnt
< -1 ||
463 (rootid
== -1 && gapcnt
== -1)) {
464 HPSB_DEBUG("Invalid Parameter: rootid = %d gapcnt = %d",
469 packet
= hpsb_alloc_packet(0);
474 packet
->header_size
= 8;
475 packet
->data_size
= 0;
476 packet
->expect_response
= 0;
477 packet
->no_waiter
= 0;
478 packet
->type
= hpsb_raw
;
479 packet
->header
[0] = 0;
481 packet
->header
[0] |= rootid
<< 24 | 1 << 23;
483 packet
->header
[0] |= gapcnt
<< 16 | 1 << 22;
485 packet
->header
[1] = ~packet
->header
[0];
487 packet
->generation
= get_hpsb_generation(host
);
489 retval
= hpsb_send_packet_and_wait(packet
);
490 hpsb_free_packet(packet
);
496 * hpsb_send_packet - transmit a packet on the bus
497 * @packet: packet to send
499 * The packet is sent through the host specified in the packet->host field.
500 * Before sending, the packet's transmit speed is automatically determined
501 * using the local speed map when it is an async, non-broadcast packet.
503 * Possibilities for failure are that host is either not initialized, in bus
504 * reset, the packet's generation number doesn't match the current generation
505 * number or the host reports a transmit error.
507 * Return value: 0 on success, negative errno on failure.
509 int hpsb_send_packet(struct hpsb_packet
*packet
)
511 struct hpsb_host
*host
= packet
->host
;
513 if (host
->is_shutdown
)
515 if (host
->in_bus_reset
||
516 (packet
->generation
!= get_hpsb_generation(host
)))
519 packet
->state
= hpsb_queued
;
521 /* This just seems silly to me */
522 WARN_ON(packet
->no_waiter
&& packet
->expect_response
);
524 if (!packet
->no_waiter
|| packet
->expect_response
) {
525 atomic_inc(&packet
->refcnt
);
526 /* Set the initial "sendtime" to 10 seconds from now, to
527 prevent premature expiry. If a packet takes more than
528 10 seconds to hit the wire, we have bigger problems :) */
529 packet
->sendtime
= jiffies
+ 10 * HZ
;
530 skb_queue_tail(&host
->pending_packet_queue
, packet
->skb
);
533 if (packet
->node_id
== host
->node_id
) {
534 /* it is a local request, so handle it locally */
537 size_t size
= packet
->data_size
+ packet
->header_size
;
539 data
= kmalloc(size
, GFP_ATOMIC
);
541 HPSB_ERR("unable to allocate memory for concatenating header and data");
545 memcpy(data
, packet
->header
, packet
->header_size
);
547 if (packet
->data_size
)
548 memcpy(((u8
*)data
) + packet
->header_size
, packet
->data
, packet
->data_size
);
550 dump_packet("send packet local", packet
->header
, packet
->header_size
, -1);
552 hpsb_packet_sent(host
, packet
, packet
->expect_response
? ACK_PENDING
: ACK_COMPLETE
);
553 hpsb_packet_received(host
, data
, size
, 0);
560 if (packet
->type
== hpsb_async
&& packet
->node_id
!= ALL_NODES
) {
562 host
->speed_map
[NODEID_TO_NODE(host
->node_id
) * 64
563 + NODEID_TO_NODE(packet
->node_id
)];
566 dump_packet("send packet", packet
->header
, packet
->header_size
, packet
->speed_code
);
568 return host
->driver
->transmit_packet(host
, packet
);
571 /* We could just use complete() directly as the packet complete
572 * callback, but this is more typesafe, in the sense that we get a
573 * compiler error if the prototype for complete() changes. */
575 static void complete_packet(void *data
)
577 complete((struct completion
*) data
);
580 int hpsb_send_packet_and_wait(struct hpsb_packet
*packet
)
582 struct completion done
;
585 init_completion(&done
);
586 hpsb_set_packet_complete_task(packet
, complete_packet
, &done
);
587 retval
= hpsb_send_packet(packet
);
589 wait_for_completion(&done
);
594 static void send_packet_nocare(struct hpsb_packet
*packet
)
596 if (hpsb_send_packet(packet
) < 0) {
597 hpsb_free_packet(packet
);
602 static void handle_packet_response(struct hpsb_host
*host
, int tcode
,
603 quadlet_t
*data
, size_t size
)
605 struct hpsb_packet
*packet
= NULL
;
611 tlabel
= (data
[0] >> 10) & 0x3f;
613 spin_lock_irqsave(&host
->pending_packet_queue
.lock
, flags
);
615 skb_queue_walk(&host
->pending_packet_queue
, skb
) {
616 packet
= (struct hpsb_packet
*)skb
->data
;
617 if ((packet
->tlabel
== tlabel
)
618 && (packet
->node_id
== (data
[1] >> 16))){
625 if (packet
== NULL
) {
626 HPSB_DEBUG("unsolicited response packet received - no tlabel match");
627 dump_packet("contents", data
, 16, -1);
628 spin_unlock_irqrestore(&host
->pending_packet_queue
.lock
, flags
);
632 switch (packet
->tcode
) {
635 if (tcode
!= TCODE_WRITE_RESPONSE
)
638 memcpy(packet
->header
, data
, 12);
641 if (tcode
!= TCODE_READQ_RESPONSE
)
644 memcpy(packet
->header
, data
, 16);
647 if (tcode
!= TCODE_READB_RESPONSE
)
650 BUG_ON(packet
->skb
->len
- sizeof(*packet
) < size
- 16);
651 memcpy(packet
->header
, data
, 16);
652 memcpy(packet
->data
, data
+ 4, size
- 16);
654 case TCODE_LOCK_REQUEST
:
655 if (tcode
!= TCODE_LOCK_RESPONSE
)
658 size
= min((size
- 16), (size_t)8);
659 BUG_ON(packet
->skb
->len
- sizeof(*packet
) < size
);
660 memcpy(packet
->header
, data
, 16);
661 memcpy(packet
->data
, data
+ 4, size
);
666 spin_unlock_irqrestore(&host
->pending_packet_queue
.lock
, flags
);
667 HPSB_INFO("unsolicited response packet received - tcode mismatch");
668 dump_packet("contents", data
, 16, -1);
672 __skb_unlink(skb
, &host
->pending_packet_queue
);
674 if (packet
->state
== hpsb_queued
) {
675 packet
->sendtime
= jiffies
;
676 packet
->ack_code
= ACK_PENDING
;
679 packet
->state
= hpsb_complete
;
680 spin_unlock_irqrestore(&host
->pending_packet_queue
.lock
, flags
);
682 queue_packet_complete(packet
);
686 static struct hpsb_packet
*create_reply_packet(struct hpsb_host
*host
,
687 quadlet_t
*data
, size_t dsize
)
689 struct hpsb_packet
*p
;
691 p
= hpsb_alloc_packet(dsize
);
692 if (unlikely(p
== NULL
)) {
693 /* FIXME - send data_error response */
697 p
->type
= hpsb_async
;
698 p
->state
= hpsb_unused
;
700 p
->node_id
= data
[1] >> 16;
701 p
->tlabel
= (data
[0] >> 10) & 0x3f;
704 p
->generation
= get_hpsb_generation(host
);
707 p
->data
[dsize
/ 4] = 0;
712 #define PREP_ASYNC_HEAD_RCODE(tc) \
713 packet->tcode = tc; \
714 packet->header[0] = (packet->node_id << 16) | (packet->tlabel << 10) \
715 | (1 << 8) | (tc << 4); \
716 packet->header[1] = (packet->host->node_id << 16) | (rcode << 12); \
717 packet->header[2] = 0
719 static void fill_async_readquad_resp(struct hpsb_packet
*packet
, int rcode
,
722 PREP_ASYNC_HEAD_RCODE(TCODE_READQ_RESPONSE
);
723 packet
->header
[3] = data
;
724 packet
->header_size
= 16;
725 packet
->data_size
= 0;
728 static void fill_async_readblock_resp(struct hpsb_packet
*packet
, int rcode
,
731 if (rcode
!= RCODE_COMPLETE
)
734 PREP_ASYNC_HEAD_RCODE(TCODE_READB_RESPONSE
);
735 packet
->header
[3] = length
<< 16;
736 packet
->header_size
= 16;
737 packet
->data_size
= length
+ (length
% 4 ? 4 - (length
% 4) : 0);
740 static void fill_async_write_resp(struct hpsb_packet
*packet
, int rcode
)
742 PREP_ASYNC_HEAD_RCODE(TCODE_WRITE_RESPONSE
);
743 packet
->header
[2] = 0;
744 packet
->header_size
= 12;
745 packet
->data_size
= 0;
748 static void fill_async_lock_resp(struct hpsb_packet
*packet
, int rcode
, int extcode
,
751 if (rcode
!= RCODE_COMPLETE
)
754 PREP_ASYNC_HEAD_RCODE(TCODE_LOCK_RESPONSE
);
755 packet
->header
[3] = (length
<< 16) | extcode
;
756 packet
->header_size
= 16;
757 packet
->data_size
= length
;
760 #define PREP_REPLY_PACKET(length) \
761 packet = create_reply_packet(host, data, length); \
762 if (packet == NULL) break
764 static void handle_incoming_packet(struct hpsb_host
*host
, int tcode
,
765 quadlet_t
*data
, size_t size
, int write_acked
)
767 struct hpsb_packet
*packet
;
768 int length
, rcode
, extcode
;
770 nodeid_t source
= data
[1] >> 16;
771 nodeid_t dest
= data
[0] >> 16;
772 u16 flags
= (u16
) data
[0];
775 /* big FIXME - no error checking is done for an out of bounds length */
779 addr
= (((u64
)(data
[1] & 0xffff)) << 32) | data
[2];
780 rcode
= highlevel_write(host
, source
, dest
, data
+3,
784 && (NODEID_TO_NODE(data
[0] >> 16) != NODE_MASK
)
786 /* not a broadcast write, reply */
787 PREP_REPLY_PACKET(0);
788 fill_async_write_resp(packet
, rcode
);
789 send_packet_nocare(packet
);
794 addr
= (((u64
)(data
[1] & 0xffff)) << 32) | data
[2];
795 rcode
= highlevel_write(host
, source
, dest
, data
+4,
796 addr
, data
[3]>>16, flags
);
799 && (NODEID_TO_NODE(data
[0] >> 16) != NODE_MASK
)
801 /* not a broadcast write, reply */
802 PREP_REPLY_PACKET(0);
803 fill_async_write_resp(packet
, rcode
);
804 send_packet_nocare(packet
);
809 addr
= (((u64
)(data
[1] & 0xffff)) << 32) | data
[2];
810 rcode
= highlevel_read(host
, source
, &buffer
, addr
, 4, flags
);
813 PREP_REPLY_PACKET(0);
814 fill_async_readquad_resp(packet
, rcode
, buffer
);
815 send_packet_nocare(packet
);
820 length
= data
[3] >> 16;
821 PREP_REPLY_PACKET(length
);
823 addr
= (((u64
)(data
[1] & 0xffff)) << 32) | data
[2];
824 rcode
= highlevel_read(host
, source
, packet
->data
, addr
,
828 fill_async_readblock_resp(packet
, rcode
, length
);
829 send_packet_nocare(packet
);
831 hpsb_free_packet(packet
);
835 case TCODE_LOCK_REQUEST
:
836 length
= data
[3] >> 16;
837 extcode
= data
[3] & 0xffff;
838 addr
= (((u64
)(data
[1] & 0xffff)) << 32) | data
[2];
840 PREP_REPLY_PACKET(8);
842 if ((extcode
== 0) || (extcode
>= 7)) {
843 /* let switch default handle error */
849 rcode
= highlevel_lock(host
, source
, packet
->data
, addr
,
850 data
[4], 0, extcode
,flags
);
851 fill_async_lock_resp(packet
, rcode
, extcode
, 4);
854 if ((extcode
!= EXTCODE_FETCH_ADD
)
855 && (extcode
!= EXTCODE_LITTLE_ADD
)) {
856 rcode
= highlevel_lock(host
, source
,
860 fill_async_lock_resp(packet
, rcode
, extcode
, 4);
862 rcode
= highlevel_lock64(host
, source
,
863 (octlet_t
*)packet
->data
, addr
,
864 *(octlet_t
*)(data
+ 4), 0ULL,
866 fill_async_lock_resp(packet
, rcode
, extcode
, 8);
870 rcode
= highlevel_lock64(host
, source
,
871 (octlet_t
*)packet
->data
, addr
,
872 *(octlet_t
*)(data
+ 6),
873 *(octlet_t
*)(data
+ 4),
875 fill_async_lock_resp(packet
, rcode
, extcode
, 8);
878 rcode
= RCODE_TYPE_ERROR
;
879 fill_async_lock_resp(packet
, rcode
,
884 send_packet_nocare(packet
);
886 hpsb_free_packet(packet
);
892 #undef PREP_REPLY_PACKET
895 void hpsb_packet_received(struct hpsb_host
*host
, quadlet_t
*data
, size_t size
,
900 if (host
->in_bus_reset
) {
901 HPSB_INFO("received packet during reset; ignoring");
905 dump_packet("received packet", data
, size
, -1);
907 tcode
= (data
[0] >> 4) & 0xf;
910 case TCODE_WRITE_RESPONSE
:
911 case TCODE_READQ_RESPONSE
:
912 case TCODE_READB_RESPONSE
:
913 case TCODE_LOCK_RESPONSE
:
914 handle_packet_response(host
, tcode
, data
, size
);
921 case TCODE_LOCK_REQUEST
:
922 handle_incoming_packet(host
, tcode
, data
, size
, write_acked
);
927 highlevel_iso_receive(host
, data
, size
);
930 case TCODE_CYCLE_START
:
931 /* simply ignore this packet if it is passed on */
935 HPSB_NOTICE("received packet with bogus transaction code %d",
942 static void abort_requests(struct hpsb_host
*host
)
944 struct hpsb_packet
*packet
;
947 host
->driver
->devctl(host
, CANCEL_REQUESTS
, 0);
949 while ((skb
= skb_dequeue(&host
->pending_packet_queue
)) != NULL
) {
950 packet
= (struct hpsb_packet
*)skb
->data
;
952 packet
->state
= hpsb_complete
;
953 packet
->ack_code
= ACKX_ABORTED
;
954 queue_packet_complete(packet
);
958 void abort_timedouts(unsigned long __opaque
)
960 struct hpsb_host
*host
= (struct hpsb_host
*)__opaque
;
962 struct hpsb_packet
*packet
;
964 unsigned long expire
;
966 spin_lock_irqsave(&host
->csr
.lock
, flags
);
967 expire
= host
->csr
.expire
;
968 spin_unlock_irqrestore(&host
->csr
.lock
, flags
);
970 /* Hold the lock around this, since we aren't dequeuing all
971 * packets, just ones we need. */
972 spin_lock_irqsave(&host
->pending_packet_queue
.lock
, flags
);
974 while (!skb_queue_empty(&host
->pending_packet_queue
)) {
975 skb
= skb_peek(&host
->pending_packet_queue
);
977 packet
= (struct hpsb_packet
*)skb
->data
;
979 if (time_before(packet
->sendtime
+ expire
, jiffies
)) {
980 __skb_unlink(skb
, &host
->pending_packet_queue
);
981 packet
->state
= hpsb_complete
;
982 packet
->ack_code
= ACKX_TIMEOUT
;
983 queue_packet_complete(packet
);
985 /* Since packets are added to the tail, the oldest
986 * ones are first, always. When we get to one that
987 * isn't timed out, the rest aren't either. */
992 if (!skb_queue_empty(&host
->pending_packet_queue
))
993 mod_timer(&host
->timeout
, jiffies
+ host
->timeout_interval
);
995 spin_unlock_irqrestore(&host
->pending_packet_queue
.lock
, flags
);
999 /* Kernel thread and vars, which handles packets that are completed. Only
1000 * packets that have a "complete" function are sent here. This way, the
1001 * completion is run out of kernel context, and doesn't block the rest of
1003 static int khpsbpkt_pid
= -1, khpsbpkt_kill
;
1004 static DECLARE_COMPLETION(khpsbpkt_complete
);
1005 static struct sk_buff_head hpsbpkt_queue
;
1006 static DECLARE_MUTEX_LOCKED(khpsbpkt_sig
);
1009 static void queue_packet_complete(struct hpsb_packet
*packet
)
1011 if (packet
->no_waiter
) {
1012 hpsb_free_packet(packet
);
1015 if (packet
->complete_routine
!= NULL
) {
1016 skb_queue_tail(&hpsbpkt_queue
, packet
->skb
);
1018 /* Signal the kernel thread to handle this */
1024 static int hpsbpkt_thread(void *__hi
)
1026 struct sk_buff
*skb
;
1027 struct hpsb_packet
*packet
;
1028 void (*complete_routine
)(void*);
1029 void *complete_data
;
1031 daemonize("khpsbpkt");
1034 if (down_interruptible(&khpsbpkt_sig
)) {
1035 if (try_to_freeze())
1037 printk("khpsbpkt: received unexpected signal?!\n" );
1044 while ((skb
= skb_dequeue(&hpsbpkt_queue
)) != NULL
) {
1045 packet
= (struct hpsb_packet
*)skb
->data
;
1047 complete_routine
= packet
->complete_routine
;
1048 complete_data
= packet
->complete_data
;
1050 packet
->complete_routine
= packet
->complete_data
= NULL
;
1052 complete_routine(complete_data
);
1056 complete_and_exit(&khpsbpkt_complete
, 0);
1059 static int __init
ieee1394_init(void)
1063 skb_queue_head_init(&hpsbpkt_queue
);
1065 /* non-fatal error */
1066 if (hpsb_init_config_roms()) {
1067 HPSB_ERR("Failed to initialize some config rom entries.\n");
1068 HPSB_ERR("Some features may not be available\n");
1071 khpsbpkt_pid
= kernel_thread(hpsbpkt_thread
, NULL
, CLONE_KERNEL
);
1072 if (khpsbpkt_pid
< 0) {
1073 HPSB_ERR("Failed to start hpsbpkt thread!\n");
1075 goto exit_cleanup_config_roms
;
1078 if (register_chrdev_region(IEEE1394_CORE_DEV
, 256, "ieee1394")) {
1079 HPSB_ERR("unable to register character device major %d!\n", IEEE1394_MAJOR
);
1081 goto exit_release_kernel_thread
;
1084 /* actually this is a non-fatal error */
1085 ret
= devfs_mk_dir("ieee1394");
1087 HPSB_ERR("unable to make devfs dir for device major %d!\n", IEEE1394_MAJOR
);
1088 goto release_chrdev
;
1091 ret
= bus_register(&ieee1394_bus_type
);
1093 HPSB_INFO("bus register failed");
1097 for (i
= 0; fw_bus_attrs
[i
]; i
++) {
1098 ret
= bus_create_file(&ieee1394_bus_type
, fw_bus_attrs
[i
]);
1101 bus_remove_file(&ieee1394_bus_type
,
1104 bus_unregister(&ieee1394_bus_type
);
1109 ret
= class_register(&hpsb_host_class
);
1111 goto release_all_bus
;
1113 hpsb_protocol_class
= class_create(THIS_MODULE
, "ieee1394_protocol");
1114 if (IS_ERR(hpsb_protocol_class
)) {
1115 ret
= PTR_ERR(hpsb_protocol_class
);
1116 goto release_class_host
;
1121 HPSB_INFO("init csr failed");
1123 goto release_class_protocol
;
1126 if (disable_nodemgr
) {
1127 HPSB_INFO("nodemgr and IRM functionality disabled");
1128 /* We shouldn't contend for IRM with nodemgr disabled, since
1129 nodemgr implements functionality required of ieee1394a-2000
1131 hpsb_disable_irm
= 1;
1136 if (hpsb_disable_irm
) {
1137 HPSB_INFO("IRM functionality disabled");
1140 ret
= init_ieee1394_nodemgr();
1142 HPSB_INFO("init nodemgr failed");
1150 release_class_protocol
:
1151 class_destroy(hpsb_protocol_class
);
1153 class_unregister(&hpsb_host_class
);
1155 for (i
= 0; fw_bus_attrs
[i
]; i
++)
1156 bus_remove_file(&ieee1394_bus_type
, fw_bus_attrs
[i
]);
1157 bus_unregister(&ieee1394_bus_type
);
1159 devfs_remove("ieee1394");
1161 unregister_chrdev_region(IEEE1394_CORE_DEV
, 256);
1162 exit_release_kernel_thread
:
1163 if (khpsbpkt_pid
>= 0) {
1164 kill_proc(khpsbpkt_pid
, SIGTERM
, 1);
1165 wait_for_completion(&khpsbpkt_complete
);
1167 exit_cleanup_config_roms
:
1168 hpsb_cleanup_config_roms();
1172 static void __exit
ieee1394_cleanup(void)
1176 if (!disable_nodemgr
)
1177 cleanup_ieee1394_nodemgr();
1181 class_destroy(hpsb_protocol_class
);
1182 class_unregister(&hpsb_host_class
);
1183 for (i
= 0; fw_bus_attrs
[i
]; i
++)
1184 bus_remove_file(&ieee1394_bus_type
, fw_bus_attrs
[i
]);
1185 bus_unregister(&ieee1394_bus_type
);
1187 if (khpsbpkt_pid
>= 0) {
1191 wait_for_completion(&khpsbpkt_complete
);
1194 hpsb_cleanup_config_roms();
1196 unregister_chrdev_region(IEEE1394_CORE_DEV
, 256);
1197 devfs_remove("ieee1394");
1200 module_init(ieee1394_init
);
1201 module_exit(ieee1394_cleanup
);
1203 /* Exported symbols */
1206 EXPORT_SYMBOL(hpsb_alloc_host
);
1207 EXPORT_SYMBOL(hpsb_add_host
);
1208 EXPORT_SYMBOL(hpsb_remove_host
);
1209 EXPORT_SYMBOL(hpsb_update_config_rom_image
);
1211 /** ieee1394_core.c **/
1212 EXPORT_SYMBOL(hpsb_speedto_str
);
1213 EXPORT_SYMBOL(hpsb_protocol_class
);
1214 EXPORT_SYMBOL(hpsb_set_packet_complete_task
);
1215 EXPORT_SYMBOL(hpsb_alloc_packet
);
1216 EXPORT_SYMBOL(hpsb_free_packet
);
1217 EXPORT_SYMBOL(hpsb_send_packet
);
1218 EXPORT_SYMBOL(hpsb_reset_bus
);
1219 EXPORT_SYMBOL(hpsb_bus_reset
);
1220 EXPORT_SYMBOL(hpsb_selfid_received
);
1221 EXPORT_SYMBOL(hpsb_selfid_complete
);
1222 EXPORT_SYMBOL(hpsb_packet_sent
);
1223 EXPORT_SYMBOL(hpsb_packet_received
);
1224 EXPORT_SYMBOL_GPL(hpsb_disable_irm
);
1225 #ifdef CONFIG_IEEE1394_EXPORT_FULL_API
1226 EXPORT_SYMBOL(hpsb_send_phy_config
);
1227 EXPORT_SYMBOL(hpsb_send_packet_and_wait
);
1230 /** ieee1394_transactions.c **/
1231 EXPORT_SYMBOL(hpsb_get_tlabel
);
1232 EXPORT_SYMBOL(hpsb_free_tlabel
);
1233 EXPORT_SYMBOL(hpsb_make_readpacket
);
1234 EXPORT_SYMBOL(hpsb_make_writepacket
);
1235 EXPORT_SYMBOL(hpsb_make_streampacket
);
1236 EXPORT_SYMBOL(hpsb_make_lockpacket
);
1237 EXPORT_SYMBOL(hpsb_make_lock64packet
);
1238 EXPORT_SYMBOL(hpsb_make_phypacket
);
1239 EXPORT_SYMBOL(hpsb_make_isopacket
);
1240 EXPORT_SYMBOL(hpsb_read
);
1241 EXPORT_SYMBOL(hpsb_write
);
1242 EXPORT_SYMBOL(hpsb_packet_success
);
1245 EXPORT_SYMBOL(hpsb_register_highlevel
);
1246 EXPORT_SYMBOL(hpsb_unregister_highlevel
);
1247 EXPORT_SYMBOL(hpsb_register_addrspace
);
1248 EXPORT_SYMBOL(hpsb_unregister_addrspace
);
1249 EXPORT_SYMBOL(hpsb_allocate_and_register_addrspace
);
1250 EXPORT_SYMBOL(hpsb_listen_channel
);
1251 EXPORT_SYMBOL(hpsb_unlisten_channel
);
1252 EXPORT_SYMBOL(hpsb_get_hostinfo
);
1253 EXPORT_SYMBOL(hpsb_create_hostinfo
);
1254 EXPORT_SYMBOL(hpsb_destroy_hostinfo
);
1255 EXPORT_SYMBOL(hpsb_set_hostinfo_key
);
1256 EXPORT_SYMBOL(hpsb_get_hostinfo_bykey
);
1257 EXPORT_SYMBOL(hpsb_set_hostinfo
);
1258 EXPORT_SYMBOL(highlevel_host_reset
);
1259 #ifdef CONFIG_IEEE1394_EXPORT_FULL_API
1260 EXPORT_SYMBOL(highlevel_add_host
);
1261 EXPORT_SYMBOL(highlevel_remove_host
);
1265 EXPORT_SYMBOL(hpsb_node_fill_packet
);
1266 EXPORT_SYMBOL(hpsb_node_write
);
1267 EXPORT_SYMBOL(hpsb_register_protocol
);
1268 EXPORT_SYMBOL(hpsb_unregister_protocol
);
1269 EXPORT_SYMBOL(ieee1394_bus_type
);
1270 #ifdef CONFIG_IEEE1394_EXPORT_FULL_API
1271 EXPORT_SYMBOL(nodemgr_for_each_host
);
1275 EXPORT_SYMBOL(hpsb_update_config_rom
);
1278 EXPORT_SYMBOL(dma_prog_region_init
);
1279 EXPORT_SYMBOL(dma_prog_region_alloc
);
1280 EXPORT_SYMBOL(dma_prog_region_free
);
1281 EXPORT_SYMBOL(dma_region_init
);
1282 EXPORT_SYMBOL(dma_region_alloc
);
1283 EXPORT_SYMBOL(dma_region_free
);
1284 EXPORT_SYMBOL(dma_region_sync_for_cpu
);
1285 EXPORT_SYMBOL(dma_region_sync_for_device
);
1286 EXPORT_SYMBOL(dma_region_mmap
);
1287 EXPORT_SYMBOL(dma_region_offset_to_bus
);
1290 EXPORT_SYMBOL(hpsb_iso_xmit_init
);
1291 EXPORT_SYMBOL(hpsb_iso_recv_init
);
1292 EXPORT_SYMBOL(hpsb_iso_xmit_start
);
1293 EXPORT_SYMBOL(hpsb_iso_recv_start
);
1294 EXPORT_SYMBOL(hpsb_iso_recv_listen_channel
);
1295 EXPORT_SYMBOL(hpsb_iso_recv_unlisten_channel
);
1296 EXPORT_SYMBOL(hpsb_iso_recv_set_channel_mask
);
1297 EXPORT_SYMBOL(hpsb_iso_stop
);
1298 EXPORT_SYMBOL(hpsb_iso_shutdown
);
1299 EXPORT_SYMBOL(hpsb_iso_xmit_queue_packet
);
1300 EXPORT_SYMBOL(hpsb_iso_xmit_sync
);
1301 EXPORT_SYMBOL(hpsb_iso_recv_release_packets
);
1302 EXPORT_SYMBOL(hpsb_iso_n_ready
);
1303 EXPORT_SYMBOL(hpsb_iso_packet_sent
);
1304 EXPORT_SYMBOL(hpsb_iso_packet_received
);
1305 EXPORT_SYMBOL(hpsb_iso_wake
);
1306 EXPORT_SYMBOL(hpsb_iso_recv_flush
);
1309 EXPORT_SYMBOL(csr1212_new_directory
);
1310 EXPORT_SYMBOL(csr1212_attach_keyval_to_directory
);
1311 EXPORT_SYMBOL(csr1212_detach_keyval_from_directory
);
1312 EXPORT_SYMBOL(csr1212_release_keyval
);
1313 EXPORT_SYMBOL(csr1212_read
);
1314 EXPORT_SYMBOL(csr1212_parse_keyval
);
1315 EXPORT_SYMBOL(_csr1212_read_keyval
);
1316 EXPORT_SYMBOL(_csr1212_destroy_keyval
);
1317 #ifdef CONFIG_IEEE1394_EXPORT_FULL_API
1318 EXPORT_SYMBOL(csr1212_create_csr
);
1319 EXPORT_SYMBOL(csr1212_init_local_csr
);
1320 EXPORT_SYMBOL(csr1212_new_immediate
);
1321 EXPORT_SYMBOL(csr1212_associate_keyval
);
1322 EXPORT_SYMBOL(csr1212_new_string_descriptor_leaf
);
1323 EXPORT_SYMBOL(csr1212_destroy_csr
);
1324 EXPORT_SYMBOL(csr1212_generate_csr_image
);
1325 EXPORT_SYMBOL(csr1212_parse_csr
);