2 * Core IEEE1394 transaction logic
4 * Copyright (C) 2004-2006 Kristian Hoegsberg <krh@bitplanet.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <linux/completion.h>
22 #include <linux/idr.h>
23 #include <linux/kernel.h>
24 #include <linux/kref.h>
25 #include <linux/module.h>
26 #include <linux/mutex.h>
27 #include <linux/init.h>
28 #include <linux/interrupt.h>
29 #include <linux/pci.h>
30 #include <linux/delay.h>
31 #include <linux/poll.h>
32 #include <linux/list.h>
33 #include <linux/kthread.h>
34 #include <asm/uaccess.h>
36 #include "fw-transaction.h"
37 #include "fw-topology.h"
38 #include "fw-device.h"
40 #define HEADER_PRI(pri) ((pri) << 0)
41 #define HEADER_TCODE(tcode) ((tcode) << 4)
42 #define HEADER_RETRY(retry) ((retry) << 8)
43 #define HEADER_TLABEL(tlabel) ((tlabel) << 10)
44 #define HEADER_DESTINATION(destination) ((destination) << 16)
45 #define HEADER_SOURCE(source) ((source) << 16)
46 #define HEADER_RCODE(rcode) ((rcode) << 12)
47 #define HEADER_OFFSET_HIGH(offset_high) ((offset_high) << 0)
48 #define HEADER_DATA_LENGTH(length) ((length) << 16)
49 #define HEADER_EXTENDED_TCODE(tcode) ((tcode) << 0)
51 #define HEADER_GET_TCODE(q) (((q) >> 4) & 0x0f)
52 #define HEADER_GET_TLABEL(q) (((q) >> 10) & 0x3f)
53 #define HEADER_GET_RCODE(q) (((q) >> 12) & 0x0f)
54 #define HEADER_GET_DESTINATION(q) (((q) >> 16) & 0xffff)
55 #define HEADER_GET_SOURCE(q) (((q) >> 16) & 0xffff)
56 #define HEADER_GET_OFFSET_HIGH(q) (((q) >> 0) & 0xffff)
57 #define HEADER_GET_DATA_LENGTH(q) (((q) >> 16) & 0xffff)
58 #define HEADER_GET_EXTENDED_TCODE(q) (((q) >> 0) & 0xffff)
60 #define HEADER_DESTINATION_IS_BROADCAST(q) \
61 (((q) & HEADER_DESTINATION(0x3f)) == HEADER_DESTINATION(0x3f))
63 #define PHY_CONFIG_GAP_COUNT(gap_count) (((gap_count) << 16) | (1 << 22))
64 #define PHY_CONFIG_ROOT_ID(node_id) ((((node_id) & 0x3f) << 24) | (1 << 23))
65 #define PHY_IDENTIFIER(id) ((id) << 30)
67 static int close_transaction(struct fw_transaction
*transaction
,
68 struct fw_card
*card
, int rcode
,
69 u32
*payload
, size_t length
)
71 struct fw_transaction
*t
;
74 spin_lock_irqsave(&card
->lock
, flags
);
75 list_for_each_entry(t
, &card
->transaction_list
, link
) {
76 if (t
== transaction
) {
78 card
->tlabel_mask
&= ~(1 << t
->tlabel
);
82 spin_unlock_irqrestore(&card
->lock
, flags
);
84 if (&t
->link
!= &card
->transaction_list
) {
85 t
->callback(card
, rcode
, payload
, length
, t
->callback_data
);
93 * Only valid for transactions that are potentially pending (ie have
96 int fw_cancel_transaction(struct fw_card
*card
,
97 struct fw_transaction
*transaction
)
100 * Cancel the packet transmission if it's still queued. That
101 * will call the packet transmission callback which cancels
105 if (card
->driver
->cancel_packet(card
, &transaction
->packet
) == 0)
109 * If the request packet has already been sent, we need to see
110 * if the transaction is still pending and remove it in that case.
113 return close_transaction(transaction
, card
, RCODE_CANCELLED
, NULL
, 0);
115 EXPORT_SYMBOL(fw_cancel_transaction
);
117 static void transmit_complete_callback(struct fw_packet
*packet
,
118 struct fw_card
*card
, int status
)
120 struct fw_transaction
*t
=
121 container_of(packet
, struct fw_transaction
, packet
);
125 close_transaction(t
, card
, RCODE_COMPLETE
, NULL
, 0);
128 t
->timestamp
= packet
->timestamp
;
133 close_transaction(t
, card
, RCODE_BUSY
, NULL
, 0);
136 close_transaction(t
, card
, RCODE_DATA_ERROR
, NULL
, 0);
139 close_transaction(t
, card
, RCODE_TYPE_ERROR
, NULL
, 0);
143 * In this case the ack is really a juju specific
144 * rcode, so just forward that to the callback.
146 close_transaction(t
, card
, status
, NULL
, 0);
151 static void fw_fill_request(struct fw_packet
*packet
, int tcode
, int tlabel
,
152 int destination_id
, int source_id
, int generation
, int speed
,
153 unsigned long long offset
, void *payload
, size_t length
)
157 if (tcode
== TCODE_STREAM_DATA
) {
159 HEADER_DATA_LENGTH(length
) |
161 HEADER_TCODE(TCODE_STREAM_DATA
);
162 packet
->header_length
= 4;
163 packet
->payload
= payload
;
164 packet
->payload_length
= length
;
170 ext_tcode
= tcode
& ~0x10;
171 tcode
= TCODE_LOCK_REQUEST
;
176 HEADER_RETRY(RETRY_X
) |
177 HEADER_TLABEL(tlabel
) |
178 HEADER_TCODE(tcode
) |
179 HEADER_DESTINATION(destination_id
);
181 HEADER_OFFSET_HIGH(offset
>> 32) | HEADER_SOURCE(source_id
);
186 case TCODE_WRITE_QUADLET_REQUEST
:
187 packet
->header
[3] = *(u32
*)payload
;
188 packet
->header_length
= 16;
189 packet
->payload_length
= 0;
192 case TCODE_LOCK_REQUEST
:
193 case TCODE_WRITE_BLOCK_REQUEST
:
195 HEADER_DATA_LENGTH(length
) |
196 HEADER_EXTENDED_TCODE(ext_tcode
);
197 packet
->header_length
= 16;
198 packet
->payload
= payload
;
199 packet
->payload_length
= length
;
202 case TCODE_READ_QUADLET_REQUEST
:
203 packet
->header_length
= 12;
204 packet
->payload_length
= 0;
207 case TCODE_READ_BLOCK_REQUEST
:
209 HEADER_DATA_LENGTH(length
) |
210 HEADER_EXTENDED_TCODE(ext_tcode
);
211 packet
->header_length
= 16;
212 packet
->payload_length
= 0;
216 packet
->speed
= speed
;
217 packet
->generation
= generation
;
219 packet
->payload_bus
= 0;
223 * This function provides low-level access to the IEEE1394 transaction
224 * logic. Most C programs would use either fw_read(), fw_write() or
225 * fw_lock() instead - those function are convenience wrappers for
226 * this function. The fw_send_request() function is primarily
227 * provided as a flexible, one-stop entry point for languages bindings
228 * and protocol bindings.
230 * FIXME: Document this function further, in particular the possible
231 * values for rcode in the callback. In short, we map ACK_COMPLETE to
232 * RCODE_COMPLETE, internal errors set errno and set rcode to
233 * RCODE_SEND_ERROR (which is out of range for standard ieee1394
234 * rcodes). All other rcodes are forwarded unchanged. For all
235 * errors, payload is NULL, length is 0.
237 * Can not expect the callback to be called before the function
238 * returns, though this does happen in some cases (ACK_COMPLETE and
241 * The payload is only used for write requests and must not be freed
242 * until the callback has been called.
244 * @param card the card from which to send the request
245 * @param tcode the tcode for this transaction. Do not use
246 * TCODE_LOCK_REQUEST directly, instead use TCODE_LOCK_MASK_SWAP
247 * etc. to specify tcode and ext_tcode.
248 * @param node_id the destination node ID (bus ID and PHY ID concatenated)
249 * @param generation the generation for which node_id is valid
250 * @param speed the speed to use for sending the request
251 * @param offset the 48 bit offset on the destination node
252 * @param payload the data payload for the request subaction
253 * @param length the length in bytes of the data to read
254 * @param callback function to be called when the transaction is completed
255 * @param callback_data pointer to arbitrary data, which will be
256 * passed to the callback
258 * In case of asynchronous stream packets i.e. TCODE_STREAM_DATA, the caller
259 * needs to synthesize @destination_id with fw_stream_packet_destination_id().
261 void fw_send_request(struct fw_card
*card
, struct fw_transaction
*t
, int tcode
,
262 int destination_id
, int generation
, int speed
,
263 unsigned long long offset
, void *payload
, size_t length
,
264 fw_transaction_callback_t callback
, void *callback_data
)
270 * Bump the flush timer up 100ms first of all so we
271 * don't race with a flush timer callback.
274 mod_timer(&card
->flush_timer
, jiffies
+ DIV_ROUND_UP(HZ
, 10));
277 * Allocate tlabel from the bitmap and put the transaction on
278 * the list while holding the card spinlock.
281 spin_lock_irqsave(&card
->lock
, flags
);
283 tlabel
= card
->current_tlabel
;
284 if (card
->tlabel_mask
& (1 << tlabel
)) {
285 spin_unlock_irqrestore(&card
->lock
, flags
);
286 callback(card
, RCODE_SEND_ERROR
, NULL
, 0, callback_data
);
290 card
->current_tlabel
= (card
->current_tlabel
+ 1) & 0x1f;
291 card
->tlabel_mask
|= (1 << tlabel
);
293 t
->node_id
= destination_id
;
295 t
->callback
= callback
;
296 t
->callback_data
= callback_data
;
298 fw_fill_request(&t
->packet
, tcode
, t
->tlabel
,
299 destination_id
, card
->node_id
, generation
,
300 speed
, offset
, payload
, length
);
301 t
->packet
.callback
= transmit_complete_callback
;
303 list_add_tail(&t
->link
, &card
->transaction_list
);
305 spin_unlock_irqrestore(&card
->lock
, flags
);
307 card
->driver
->send_request(card
, &t
->packet
);
309 EXPORT_SYMBOL(fw_send_request
);
311 struct transaction_callback_data
{
312 struct completion done
;
317 static void transaction_callback(struct fw_card
*card
, int rcode
,
318 void *payload
, size_t length
, void *data
)
320 struct transaction_callback_data
*d
= data
;
322 if (rcode
== RCODE_COMPLETE
)
323 memcpy(d
->payload
, payload
, length
);
329 * fw_run_transaction - send request and sleep until transaction is completed
333 int fw_run_transaction(struct fw_card
*card
, int tcode
, int destination_id
,
334 int generation
, int speed
, unsigned long long offset
,
335 void *payload
, size_t length
)
337 struct transaction_callback_data d
;
338 struct fw_transaction t
;
340 init_completion(&d
.done
);
342 fw_send_request(card
, &t
, tcode
, destination_id
, generation
, speed
,
343 offset
, payload
, length
, transaction_callback
, &d
);
344 wait_for_completion(&d
.done
);
348 EXPORT_SYMBOL(fw_run_transaction
);
350 static DEFINE_MUTEX(phy_config_mutex
);
351 static DECLARE_COMPLETION(phy_config_done
);
353 static void transmit_phy_packet_callback(struct fw_packet
*packet
,
354 struct fw_card
*card
, int status
)
356 complete(&phy_config_done
);
359 static struct fw_packet phy_config_packet
= {
363 .callback
= transmit_phy_packet_callback
,
366 void fw_send_phy_config(struct fw_card
*card
,
367 int node_id
, int generation
, int gap_count
)
369 long timeout
= DIV_ROUND_UP(HZ
, 10);
370 u32 data
= PHY_IDENTIFIER(PHY_PACKET_CONFIG
) |
371 PHY_CONFIG_ROOT_ID(node_id
) |
372 PHY_CONFIG_GAP_COUNT(gap_count
);
374 mutex_lock(&phy_config_mutex
);
376 phy_config_packet
.header
[0] = data
;
377 phy_config_packet
.header
[1] = ~data
;
378 phy_config_packet
.generation
= generation
;
379 INIT_COMPLETION(phy_config_done
);
381 card
->driver
->send_request(card
, &phy_config_packet
);
382 wait_for_completion_timeout(&phy_config_done
, timeout
);
384 mutex_unlock(&phy_config_mutex
);
387 void fw_flush_transactions(struct fw_card
*card
)
389 struct fw_transaction
*t
, *next
;
390 struct list_head list
;
393 INIT_LIST_HEAD(&list
);
394 spin_lock_irqsave(&card
->lock
, flags
);
395 list_splice_init(&card
->transaction_list
, &list
);
396 card
->tlabel_mask
= 0;
397 spin_unlock_irqrestore(&card
->lock
, flags
);
399 list_for_each_entry_safe(t
, next
, &list
, link
) {
400 card
->driver
->cancel_packet(card
, &t
->packet
);
403 * At this point cancel_packet will never call the
404 * transaction callback, since we just took all the
405 * transactions out of the list. So do it here.
407 t
->callback(card
, RCODE_CANCELLED
, NULL
, 0, t
->callback_data
);
411 static struct fw_address_handler
*lookup_overlapping_address_handler(
412 struct list_head
*list
, unsigned long long offset
, size_t length
)
414 struct fw_address_handler
*handler
;
416 list_for_each_entry(handler
, list
, link
) {
417 if (handler
->offset
< offset
+ length
&&
418 offset
< handler
->offset
+ handler
->length
)
425 static struct fw_address_handler
*lookup_enclosing_address_handler(
426 struct list_head
*list
, unsigned long long offset
, size_t length
)
428 struct fw_address_handler
*handler
;
430 list_for_each_entry(handler
, list
, link
) {
431 if (handler
->offset
<= offset
&&
432 offset
+ length
<= handler
->offset
+ handler
->length
)
439 static DEFINE_SPINLOCK(address_handler_lock
);
440 static LIST_HEAD(address_handler_list
);
442 const struct fw_address_region fw_high_memory_region
=
443 { .start
= 0x000100000000ULL
, .end
= 0xffffe0000000ULL
, };
444 EXPORT_SYMBOL(fw_high_memory_region
);
447 const struct fw_address_region fw_low_memory_region
=
448 { .start
= 0x000000000000ULL
, .end
= 0x000100000000ULL
, };
449 const struct fw_address_region fw_private_region
=
450 { .start
= 0xffffe0000000ULL
, .end
= 0xfffff0000000ULL
, };
451 const struct fw_address_region fw_csr_region
=
452 { .start
= CSR_REGISTER_BASE
,
453 .end
= CSR_REGISTER_BASE
| CSR_CONFIG_ROM_END
, };
454 const struct fw_address_region fw_unit_space_region
=
455 { .start
= 0xfffff0000900ULL
, .end
= 0x1000000000000ULL
, };
459 * fw_core_add_address_handler - register for incoming requests
461 * @region: region in the IEEE 1212 node space address range
463 * region->start, ->end, and handler->length have to be quadlet-aligned.
465 * When a request is received that falls within the specified address range,
466 * the specified callback is invoked. The parameters passed to the callback
467 * give the details of the particular request.
469 * Return value: 0 on success, non-zero otherwise.
470 * The start offset of the handler's address region is determined by
471 * fw_core_add_address_handler() and is returned in handler->offset.
473 int fw_core_add_address_handler(struct fw_address_handler
*handler
,
474 const struct fw_address_region
*region
)
476 struct fw_address_handler
*other
;
480 if (region
->start
& 0xffff000000000003ULL
||
481 region
->end
& 0xffff000000000003ULL
||
482 region
->start
>= region
->end
||
483 handler
->length
& 3 ||
484 handler
->length
== 0)
487 spin_lock_irqsave(&address_handler_lock
, flags
);
489 handler
->offset
= region
->start
;
490 while (handler
->offset
+ handler
->length
<= region
->end
) {
492 lookup_overlapping_address_handler(&address_handler_list
,
496 handler
->offset
+= other
->length
;
498 list_add_tail(&handler
->link
, &address_handler_list
);
504 spin_unlock_irqrestore(&address_handler_lock
, flags
);
508 EXPORT_SYMBOL(fw_core_add_address_handler
);
511 * fw_core_remove_address_handler - unregister an address handler
513 void fw_core_remove_address_handler(struct fw_address_handler
*handler
)
517 spin_lock_irqsave(&address_handler_lock
, flags
);
518 list_del(&handler
->link
);
519 spin_unlock_irqrestore(&address_handler_lock
, flags
);
521 EXPORT_SYMBOL(fw_core_remove_address_handler
);
524 struct fw_packet response
;
525 u32 request_header
[4];
531 static void free_response_callback(struct fw_packet
*packet
,
532 struct fw_card
*card
, int status
)
534 struct fw_request
*request
;
536 request
= container_of(packet
, struct fw_request
, response
);
540 void fw_fill_response(struct fw_packet
*response
, u32
*request_header
,
541 int rcode
, void *payload
, size_t length
)
543 int tcode
, tlabel
, extended_tcode
, source
, destination
;
545 tcode
= HEADER_GET_TCODE(request_header
[0]);
546 tlabel
= HEADER_GET_TLABEL(request_header
[0]);
547 source
= HEADER_GET_DESTINATION(request_header
[0]);
548 destination
= HEADER_GET_SOURCE(request_header
[1]);
549 extended_tcode
= HEADER_GET_EXTENDED_TCODE(request_header
[3]);
551 response
->header
[0] =
552 HEADER_RETRY(RETRY_1
) |
553 HEADER_TLABEL(tlabel
) |
554 HEADER_DESTINATION(destination
);
555 response
->header
[1] =
556 HEADER_SOURCE(source
) |
558 response
->header
[2] = 0;
561 case TCODE_WRITE_QUADLET_REQUEST
:
562 case TCODE_WRITE_BLOCK_REQUEST
:
563 response
->header
[0] |= HEADER_TCODE(TCODE_WRITE_RESPONSE
);
564 response
->header_length
= 12;
565 response
->payload_length
= 0;
568 case TCODE_READ_QUADLET_REQUEST
:
569 response
->header
[0] |=
570 HEADER_TCODE(TCODE_READ_QUADLET_RESPONSE
);
572 response
->header
[3] = *(u32
*)payload
;
574 response
->header
[3] = 0;
575 response
->header_length
= 16;
576 response
->payload_length
= 0;
579 case TCODE_READ_BLOCK_REQUEST
:
580 case TCODE_LOCK_REQUEST
:
581 response
->header
[0] |= HEADER_TCODE(tcode
+ 2);
582 response
->header
[3] =
583 HEADER_DATA_LENGTH(length
) |
584 HEADER_EXTENDED_TCODE(extended_tcode
);
585 response
->header_length
= 16;
586 response
->payload
= payload
;
587 response
->payload_length
= length
;
595 response
->payload_bus
= 0;
597 EXPORT_SYMBOL(fw_fill_response
);
599 static struct fw_request
*allocate_request(struct fw_packet
*p
)
601 struct fw_request
*request
;
603 int request_tcode
, t
;
605 request_tcode
= HEADER_GET_TCODE(p
->header
[0]);
606 switch (request_tcode
) {
607 case TCODE_WRITE_QUADLET_REQUEST
:
608 data
= &p
->header
[3];
612 case TCODE_WRITE_BLOCK_REQUEST
:
613 case TCODE_LOCK_REQUEST
:
615 length
= HEADER_GET_DATA_LENGTH(p
->header
[3]);
618 case TCODE_READ_QUADLET_REQUEST
:
623 case TCODE_READ_BLOCK_REQUEST
:
625 length
= HEADER_GET_DATA_LENGTH(p
->header
[3]);
629 fw_error("ERROR - corrupt request received - %08x %08x %08x\n",
630 p
->header
[0], p
->header
[1], p
->header
[2]);
634 request
= kmalloc(sizeof(*request
) + length
, GFP_ATOMIC
);
638 t
= (p
->timestamp
& 0x1fff) + 4000;
640 t
= (p
->timestamp
& ~0x1fff) + 0x2000 + t
- 8000;
642 t
= (p
->timestamp
& ~0x1fff) + t
;
644 request
->response
.speed
= p
->speed
;
645 request
->response
.timestamp
= t
;
646 request
->response
.generation
= p
->generation
;
647 request
->response
.ack
= 0;
648 request
->response
.callback
= free_response_callback
;
649 request
->ack
= p
->ack
;
650 request
->length
= length
;
652 memcpy(request
->data
, data
, length
);
654 memcpy(request
->request_header
, p
->header
, sizeof(p
->header
));
659 void fw_send_response(struct fw_card
*card
,
660 struct fw_request
*request
, int rcode
)
662 /* unified transaction or broadcast transaction: don't respond */
663 if (request
->ack
!= ACK_PENDING
||
664 HEADER_DESTINATION_IS_BROADCAST(request
->request_header
[0])) {
669 if (rcode
== RCODE_COMPLETE
)
670 fw_fill_response(&request
->response
, request
->request_header
,
671 rcode
, request
->data
, request
->length
);
673 fw_fill_response(&request
->response
, request
->request_header
,
676 card
->driver
->send_response(card
, &request
->response
);
678 EXPORT_SYMBOL(fw_send_response
);
680 void fw_core_handle_request(struct fw_card
*card
, struct fw_packet
*p
)
682 struct fw_address_handler
*handler
;
683 struct fw_request
*request
;
684 unsigned long long offset
;
686 int tcode
, destination
, source
;
688 if (p
->ack
!= ACK_PENDING
&& p
->ack
!= ACK_COMPLETE
)
691 request
= allocate_request(p
);
692 if (request
== NULL
) {
693 /* FIXME: send statically allocated busy packet. */
698 ((unsigned long long)
699 HEADER_GET_OFFSET_HIGH(p
->header
[1]) << 32) | p
->header
[2];
700 tcode
= HEADER_GET_TCODE(p
->header
[0]);
701 destination
= HEADER_GET_DESTINATION(p
->header
[0]);
702 source
= HEADER_GET_SOURCE(p
->header
[1]);
704 spin_lock_irqsave(&address_handler_lock
, flags
);
705 handler
= lookup_enclosing_address_handler(&address_handler_list
,
706 offset
, request
->length
);
707 spin_unlock_irqrestore(&address_handler_lock
, flags
);
710 * FIXME: lookup the fw_node corresponding to the sender of
711 * this request and pass that to the address handler instead
712 * of the node ID. We may also want to move the address
713 * allocations to fw_node so we only do this callback if the
714 * upper layers registered it for this node.
718 fw_send_response(card
, request
, RCODE_ADDRESS_ERROR
);
720 handler
->address_callback(card
, request
,
721 tcode
, destination
, source
,
722 p
->generation
, p
->speed
, offset
,
723 request
->data
, request
->length
,
724 handler
->callback_data
);
726 EXPORT_SYMBOL(fw_core_handle_request
);
728 void fw_core_handle_response(struct fw_card
*card
, struct fw_packet
*p
)
730 struct fw_transaction
*t
;
734 int tcode
, tlabel
, destination
, source
, rcode
;
736 tcode
= HEADER_GET_TCODE(p
->header
[0]);
737 tlabel
= HEADER_GET_TLABEL(p
->header
[0]);
738 destination
= HEADER_GET_DESTINATION(p
->header
[0]);
739 source
= HEADER_GET_SOURCE(p
->header
[1]);
740 rcode
= HEADER_GET_RCODE(p
->header
[1]);
742 spin_lock_irqsave(&card
->lock
, flags
);
743 list_for_each_entry(t
, &card
->transaction_list
, link
) {
744 if (t
->node_id
== source
&& t
->tlabel
== tlabel
) {
746 card
->tlabel_mask
&= ~(1 << t
->tlabel
);
750 spin_unlock_irqrestore(&card
->lock
, flags
);
752 if (&t
->link
== &card
->transaction_list
) {
753 fw_notify("Unsolicited response (source %x, tlabel %x)\n",
759 * FIXME: sanity check packet, is length correct, does tcodes
760 * and addresses match.
764 case TCODE_READ_QUADLET_RESPONSE
:
765 data
= (u32
*) &p
->header
[3];
769 case TCODE_WRITE_RESPONSE
:
774 case TCODE_READ_BLOCK_RESPONSE
:
775 case TCODE_LOCK_RESPONSE
:
777 data_length
= HEADER_GET_DATA_LENGTH(p
->header
[3]);
781 /* Should never happen, this is just to shut up gcc. */
788 * The response handler may be executed while the request handler
789 * is still pending. Cancel the request handler.
791 card
->driver
->cancel_packet(card
, &t
->packet
);
793 t
->callback(card
, rcode
, data
, data_length
, t
->callback_data
);
795 EXPORT_SYMBOL(fw_core_handle_response
);
797 static const struct fw_address_region topology_map_region
=
798 { .start
= CSR_REGISTER_BASE
| CSR_TOPOLOGY_MAP
,
799 .end
= CSR_REGISTER_BASE
| CSR_TOPOLOGY_MAP_END
, };
801 static void handle_topology_map(struct fw_card
*card
, struct fw_request
*request
,
802 int tcode
, int destination
, int source
, int generation
,
803 int speed
, unsigned long long offset
,
804 void *payload
, size_t length
, void *callback_data
)
809 if (!TCODE_IS_READ_REQUEST(tcode
)) {
810 fw_send_response(card
, request
, RCODE_TYPE_ERROR
);
814 if ((offset
& 3) > 0 || (length
& 3) > 0) {
815 fw_send_response(card
, request
, RCODE_ADDRESS_ERROR
);
819 start
= (offset
- topology_map_region
.start
) / 4;
820 end
= start
+ length
/ 4;
823 for (i
= 0; i
< length
/ 4; i
++)
824 map
[i
] = cpu_to_be32(card
->topology_map
[start
+ i
]);
826 fw_send_response(card
, request
, RCODE_COMPLETE
);
829 static struct fw_address_handler topology_map
= {
831 .address_callback
= handle_topology_map
,
834 static const struct fw_address_region registers_region
=
835 { .start
= CSR_REGISTER_BASE
,
836 .end
= CSR_REGISTER_BASE
| CSR_CONFIG_ROM
, };
838 static void handle_registers(struct fw_card
*card
, struct fw_request
*request
,
839 int tcode
, int destination
, int source
, int generation
,
840 int speed
, unsigned long long offset
,
841 void *payload
, size_t length
, void *callback_data
)
843 int reg
= offset
& ~CSR_REGISTER_BASE
;
844 unsigned long long bus_time
;
845 __be32
*data
= payload
;
846 int rcode
= RCODE_COMPLETE
;
851 if (!TCODE_IS_READ_REQUEST(tcode
) || length
!= 4) {
852 rcode
= RCODE_TYPE_ERROR
;
856 bus_time
= card
->driver
->get_bus_time(card
);
857 if (reg
== CSR_CYCLE_TIME
)
858 *data
= cpu_to_be32(bus_time
);
860 *data
= cpu_to_be32(bus_time
>> 25);
863 case CSR_BROADCAST_CHANNEL
:
864 if (tcode
== TCODE_READ_QUADLET_REQUEST
)
865 *data
= cpu_to_be32(card
->broadcast_channel
);
866 else if (tcode
== TCODE_WRITE_QUADLET_REQUEST
)
867 card
->broadcast_channel
=
868 (be32_to_cpu(*data
) & BROADCAST_CHANNEL_VALID
) |
869 BROADCAST_CHANNEL_INITIAL
;
871 rcode
= RCODE_TYPE_ERROR
;
874 case CSR_BUS_MANAGER_ID
:
875 case CSR_BANDWIDTH_AVAILABLE
:
876 case CSR_CHANNELS_AVAILABLE_HI
:
877 case CSR_CHANNELS_AVAILABLE_LO
:
879 * FIXME: these are handled by the OHCI hardware and
880 * the stack never sees these request. If we add
881 * support for a new type of controller that doesn't
882 * handle this in hardware we need to deal with these
888 case CSR_BUSY_TIMEOUT
:
889 /* FIXME: Implement this. */
892 rcode
= RCODE_ADDRESS_ERROR
;
896 fw_send_response(card
, request
, rcode
);
899 static struct fw_address_handler registers
= {
901 .address_callback
= handle_registers
,
904 MODULE_AUTHOR("Kristian Hoegsberg <krh@bitplanet.net>");
905 MODULE_DESCRIPTION("Core IEEE1394 transaction logic");
906 MODULE_LICENSE("GPL");
908 static const u32 vendor_textual_descriptor
[] = {
909 /* textual descriptor leaf () */
913 0x4c696e75, /* L i n u */
914 0x78204669, /* x F i */
915 0x72657769, /* r e w i */
916 0x72650000, /* r e */
919 static const u32 model_textual_descriptor
[] = {
920 /* model descriptor leaf () */
924 0x4a756a75, /* J u j u */
927 static struct fw_descriptor vendor_id_descriptor
= {
928 .length
= ARRAY_SIZE(vendor_textual_descriptor
),
929 .immediate
= 0x03d00d1e,
931 .data
= vendor_textual_descriptor
,
934 static struct fw_descriptor model_id_descriptor
= {
935 .length
= ARRAY_SIZE(model_textual_descriptor
),
936 .immediate
= 0x17000001,
938 .data
= model_textual_descriptor
,
941 static int __init
fw_core_init(void)
945 ret
= bus_register(&fw_bus_type
);
949 fw_cdev_major
= register_chrdev(0, "firewire", &fw_device_ops
);
950 if (fw_cdev_major
< 0) {
951 bus_unregister(&fw_bus_type
);
952 return fw_cdev_major
;
955 fw_core_add_address_handler(&topology_map
, &topology_map_region
);
956 fw_core_add_address_handler(®isters
, ®isters_region
);
957 fw_core_add_descriptor(&vendor_id_descriptor
);
958 fw_core_add_descriptor(&model_id_descriptor
);
963 static void __exit
fw_core_cleanup(void)
965 unregister_chrdev(fw_cdev_major
, "firewire");
966 bus_unregister(&fw_bus_type
);
967 idr_destroy(&fw_device_idr
);
970 module_init(fw_core_init
);
971 module_exit(fw_core_cleanup
);