4 * Raw interface to the bus
6 * Copyright (C) 1999, 2000 Andreas E. Bombe
7 * 2001, 2002 Manfred Weihs <weihs@ict.tuwien.ac.at>
8 * 2002 Christian Toegel <christian.toegel@gmx.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 * configuration ROM manipulation
18 * address range mapping
19 * adaptation for new (transparent) loopback mechanism
20 * sending of arbitrary async packets
21 * Christian Toegel <christian.toegel@gmx.at>
22 * address range mapping
24 * transmit physical packet
25 * busreset notification control (switch on/off)
26 * busreset with selection of type (short/long)
30 #include <linux/kernel.h>
31 #include <linux/list.h>
32 #include <linux/sched.h>
33 #include <linux/string.h>
34 #include <linux/slab.h>
36 #include <linux/poll.h>
37 #include <linux/module.h>
38 #include <linux/mutex.h>
39 #include <linux/init.h>
40 #include <linux/interrupt.h>
41 #include <linux/vmalloc.h>
42 #include <linux/cdev.h>
43 #include <asm/uaccess.h>
44 #include <asm/atomic.h>
45 #include <linux/compat.h>
48 #include "highlevel.h"
51 #include "ieee1394_core.h"
52 #include "ieee1394_hotplug.h"
53 #include "ieee1394_transactions.h"
54 #include "ieee1394_types.h"
58 #include "raw1394-private.h"
60 #define int2ptr(x) ((void __user *)(unsigned long)x)
61 #define ptr2int(x) ((u64)(unsigned long)(void __user *)x)
63 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
68 #define DBGMSG(fmt, args...) \
69 printk(KERN_INFO "raw1394:" fmt "\n" , ## args)
71 #define DBGMSG(fmt, args...) do {} while (0)
74 static LIST_HEAD(host_info_list
);
75 static int host_count
;
76 static DEFINE_SPINLOCK(host_info_lock
);
77 static atomic_t internal_generation
= ATOMIC_INIT(0);
79 static atomic_t iso_buffer_size
;
80 static const int iso_buffer_max
= 4 * 1024 * 1024; /* 4 MB */
82 static struct hpsb_highlevel raw1394_highlevel
;
84 static int arm_read(struct hpsb_host
*host
, int nodeid
, quadlet_t
* buffer
,
85 u64 addr
, size_t length
, u16 flags
);
86 static int arm_write(struct hpsb_host
*host
, int nodeid
, int destid
,
87 quadlet_t
* data
, u64 addr
, size_t length
, u16 flags
);
88 static int arm_lock(struct hpsb_host
*host
, int nodeid
, quadlet_t
* store
,
89 u64 addr
, quadlet_t data
, quadlet_t arg
, int ext_tcode
,
91 static int arm_lock64(struct hpsb_host
*host
, int nodeid
, octlet_t
* store
,
92 u64 addr
, octlet_t data
, octlet_t arg
, int ext_tcode
,
94 static const struct hpsb_address_ops arm_ops
= {
101 static void queue_complete_cb(struct pending_request
*req
);
103 static struct pending_request
*__alloc_pending_request(gfp_t flags
)
105 struct pending_request
*req
;
107 req
= kzalloc(sizeof(*req
), flags
);
109 INIT_LIST_HEAD(&req
->list
);
114 static inline struct pending_request
*alloc_pending_request(void)
116 return __alloc_pending_request(GFP_KERNEL
);
119 static void free_pending_request(struct pending_request
*req
)
122 if (atomic_dec_and_test(&req
->ibs
->refcount
)) {
123 atomic_sub(req
->ibs
->data_size
, &iso_buffer_size
);
126 } else if (req
->free_data
) {
129 hpsb_free_packet(req
->packet
);
133 /* fi->reqlists_lock must be taken */
134 static void __queue_complete_req(struct pending_request
*req
)
136 struct file_info
*fi
= req
->file_info
;
138 list_move_tail(&req
->list
, &fi
->req_complete
);
139 wake_up(&fi
->wait_complete
);
142 static void queue_complete_req(struct pending_request
*req
)
145 struct file_info
*fi
= req
->file_info
;
147 spin_lock_irqsave(&fi
->reqlists_lock
, flags
);
148 __queue_complete_req(req
);
149 spin_unlock_irqrestore(&fi
->reqlists_lock
, flags
);
152 static void queue_complete_cb(struct pending_request
*req
)
154 struct hpsb_packet
*packet
= req
->packet
;
155 int rcode
= (packet
->header
[1] >> 12) & 0xf;
157 switch (packet
->ack_code
) {
159 case ACKX_SEND_ERROR
:
160 req
->req
.error
= RAW1394_ERROR_SEND_ERROR
;
163 req
->req
.error
= RAW1394_ERROR_ABORTED
;
166 req
->req
.error
= RAW1394_ERROR_TIMEOUT
;
169 req
->req
.error
= (packet
->ack_code
<< 16) | rcode
;
173 if (!((packet
->ack_code
== ACK_PENDING
) && (rcode
== RCODE_COMPLETE
))) {
177 if ((req
->req
.type
== RAW1394_REQ_ASYNC_READ
) ||
178 (req
->req
.type
== RAW1394_REQ_ASYNC_WRITE
) ||
179 (req
->req
.type
== RAW1394_REQ_ASYNC_STREAM
) ||
180 (req
->req
.type
== RAW1394_REQ_LOCK
) ||
181 (req
->req
.type
== RAW1394_REQ_LOCK64
))
182 hpsb_free_tlabel(packet
);
184 queue_complete_req(req
);
187 static void add_host(struct hpsb_host
*host
)
189 struct host_info
*hi
;
192 hi
= kmalloc(sizeof(*hi
), GFP_KERNEL
);
195 INIT_LIST_HEAD(&hi
->list
);
197 INIT_LIST_HEAD(&hi
->file_info_list
);
199 spin_lock_irqsave(&host_info_lock
, flags
);
200 list_add_tail(&hi
->list
, &host_info_list
);
202 spin_unlock_irqrestore(&host_info_lock
, flags
);
205 atomic_inc(&internal_generation
);
208 static struct host_info
*find_host_info(struct hpsb_host
*host
)
210 struct host_info
*hi
;
212 list_for_each_entry(hi
, &host_info_list
, list
)
213 if (hi
->host
== host
)
219 static void remove_host(struct hpsb_host
*host
)
221 struct host_info
*hi
;
224 spin_lock_irqsave(&host_info_lock
, flags
);
225 hi
= find_host_info(host
);
231 FIXME: address ranges should be removed
232 and fileinfo states should be initialized
233 (including setting generation to
234 internal-generation ...)
237 spin_unlock_irqrestore(&host_info_lock
, flags
);
240 printk(KERN_ERR
"raw1394: attempt to remove unknown host "
247 atomic_inc(&internal_generation
);
250 static void host_reset(struct hpsb_host
*host
)
253 struct host_info
*hi
;
254 struct file_info
*fi
;
255 struct pending_request
*req
;
257 spin_lock_irqsave(&host_info_lock
, flags
);
258 hi
= find_host_info(host
);
261 list_for_each_entry(fi
, &hi
->file_info_list
, list
) {
262 if (fi
->notification
== RAW1394_NOTIFY_ON
) {
263 req
= __alloc_pending_request(GFP_ATOMIC
);
267 req
->req
.type
= RAW1394_REQ_BUS_RESET
;
268 req
->req
.generation
=
269 get_hpsb_generation(host
);
270 req
->req
.misc
= (host
->node_id
<< 16)
272 if (fi
->protocol_version
> 3) {
279 queue_complete_req(req
);
284 spin_unlock_irqrestore(&host_info_lock
, flags
);
287 static void fcp_request(struct hpsb_host
*host
, int nodeid
, int direction
,
288 int cts
, u8
* data
, size_t length
)
291 struct host_info
*hi
;
292 struct file_info
*fi
;
293 struct pending_request
*req
, *req_next
;
294 struct iso_block_store
*ibs
= NULL
;
297 if ((atomic_read(&iso_buffer_size
) + length
) > iso_buffer_max
) {
298 HPSB_INFO("dropped fcp request");
302 spin_lock_irqsave(&host_info_lock
, flags
);
303 hi
= find_host_info(host
);
306 list_for_each_entry(fi
, &hi
->file_info_list
, list
) {
310 req
= __alloc_pending_request(GFP_ATOMIC
);
315 ibs
= kmalloc(sizeof(*ibs
) + length
,
322 atomic_add(length
, &iso_buffer_size
);
323 atomic_set(&ibs
->refcount
, 0);
324 ibs
->data_size
= length
;
325 memcpy(ibs
->data
, data
, length
);
328 atomic_inc(&ibs
->refcount
);
332 req
->data
= ibs
->data
;
333 req
->req
.type
= RAW1394_REQ_FCP_REQUEST
;
334 req
->req
.generation
= get_hpsb_generation(host
);
335 req
->req
.misc
= nodeid
| (direction
<< 16);
336 req
->req
.recvb
= ptr2int(fi
->fcp_buffer
);
337 req
->req
.length
= length
;
339 list_add_tail(&req
->list
, &reqs
);
342 spin_unlock_irqrestore(&host_info_lock
, flags
);
344 list_for_each_entry_safe(req
, req_next
, &reqs
, list
)
345 queue_complete_req(req
);
349 struct compat_raw1394_req
{
364 #if defined(CONFIG_X86_64) || defined(CONFIG_IA64)
365 __attribute__((packed
))
369 static const char __user
*raw1394_compat_write(const char __user
*buf
)
371 struct compat_raw1394_req __user
*cr
= (typeof(cr
)) buf
;
372 struct raw1394_request __user
*r
;
374 r
= compat_alloc_user_space(sizeof(struct raw1394_request
));
376 #define C(x) __copy_in_user(&r->x, &cr->x, sizeof(r->x))
378 if (copy_in_user(r
, cr
, sizeof(struct compat_raw1394_req
)) ||
383 return (__force
const char __user
*)ERR_PTR(-EFAULT
);
385 return (const char __user
*)r
;
389 #define P(x) __put_user(r->x, &cr->x)
392 raw1394_compat_read(const char __user
*buf
, struct raw1394_request
*r
)
394 struct compat_raw1394_req __user
*cr
= (typeof(cr
)) buf
;
396 if (!access_ok(VERIFY_WRITE
, cr
, sizeof(struct compat_raw1394_req
)) ||
408 return sizeof(struct compat_raw1394_req
);
414 /* get next completed request (caller must hold fi->reqlists_lock) */
415 static inline struct pending_request
*__next_complete_req(struct file_info
*fi
)
417 struct list_head
*lh
;
418 struct pending_request
*req
= NULL
;
420 if (!list_empty(&fi
->req_complete
)) {
421 lh
= fi
->req_complete
.next
;
423 req
= list_entry(lh
, struct pending_request
, list
);
428 /* atomically get next completed request */
429 static struct pending_request
*next_complete_req(struct file_info
*fi
)
432 struct pending_request
*req
;
434 spin_lock_irqsave(&fi
->reqlists_lock
, flags
);
435 req
= __next_complete_req(fi
);
436 spin_unlock_irqrestore(&fi
->reqlists_lock
, flags
);
440 static ssize_t
raw1394_read(struct file
*file
, char __user
* buffer
,
441 size_t count
, loff_t
* offset_is_ignored
)
443 struct file_info
*fi
= (struct file_info
*)file
->private_data
;
444 struct pending_request
*req
;
448 if (count
== sizeof(struct compat_raw1394_req
)) {
452 if (count
!= sizeof(struct raw1394_request
)) {
456 if (!access_ok(VERIFY_WRITE
, buffer
, count
)) {
460 if (file
->f_flags
& O_NONBLOCK
) {
461 if (!(req
= next_complete_req(fi
)))
465 * NB: We call the macro wait_event_interruptible() with a
466 * condition argument with side effect. This is only possible
467 * because the side effect does not occur until the condition
468 * became true, and wait_event_interruptible() won't evaluate
469 * the condition again after that.
471 if (wait_event_interruptible(fi
->wait_complete
,
472 (req
= next_complete_req(fi
))))
476 if (req
->req
.length
) {
477 if (copy_to_user(int2ptr(req
->req
.recvb
), req
->data
,
479 req
->req
.error
= RAW1394_ERROR_MEMFAULT
;
484 if (count
== sizeof(struct compat_raw1394_req
) &&
485 sizeof(struct compat_raw1394_req
) !=
486 sizeof(struct raw1394_request
)) {
487 ret
= raw1394_compat_read(buffer
, &req
->req
);
491 if (copy_to_user(buffer
, &req
->req
, sizeof(req
->req
))) {
495 ret
= (ssize_t
) sizeof(struct raw1394_request
);
498 free_pending_request(req
);
502 static int state_opened(struct file_info
*fi
, struct pending_request
*req
)
504 if (req
->req
.type
== RAW1394_REQ_INITIALIZE
) {
505 switch (req
->req
.misc
) {
506 case RAW1394_KERNELAPI_VERSION
:
508 fi
->state
= initialized
;
509 fi
->protocol_version
= req
->req
.misc
;
510 req
->req
.error
= RAW1394_ERROR_NONE
;
511 req
->req
.generation
= atomic_read(&internal_generation
);
515 req
->req
.error
= RAW1394_ERROR_COMPAT
;
516 req
->req
.misc
= RAW1394_KERNELAPI_VERSION
;
519 req
->req
.error
= RAW1394_ERROR_STATE_ORDER
;
523 queue_complete_req(req
);
527 static int state_initialized(struct file_info
*fi
, struct pending_request
*req
)
530 struct host_info
*hi
;
531 struct raw1394_khost_list
*khl
;
533 if (req
->req
.generation
!= atomic_read(&internal_generation
)) {
534 req
->req
.error
= RAW1394_ERROR_GENERATION
;
535 req
->req
.generation
= atomic_read(&internal_generation
);
537 queue_complete_req(req
);
541 switch (req
->req
.type
) {
542 case RAW1394_REQ_LIST_CARDS
:
543 spin_lock_irqsave(&host_info_lock
, flags
);
544 khl
= kmalloc(sizeof(*khl
) * host_count
, GFP_ATOMIC
);
547 req
->req
.misc
= host_count
;
548 req
->data
= (quadlet_t
*) khl
;
550 list_for_each_entry(hi
, &host_info_list
, list
) {
551 khl
->nodes
= hi
->host
->node_count
;
552 strcpy(khl
->name
, hi
->host
->driver
->name
);
556 spin_unlock_irqrestore(&host_info_lock
, flags
);
559 req
->req
.error
= RAW1394_ERROR_NONE
;
560 req
->req
.length
= min(req
->req
.length
,
562 (struct raw1394_khost_list
)
570 case RAW1394_REQ_SET_CARD
:
571 spin_lock_irqsave(&host_info_lock
, flags
);
572 if (req
->req
.misc
>= host_count
) {
573 req
->req
.error
= RAW1394_ERROR_INVALID_ARG
;
576 list_for_each_entry(hi
, &host_info_list
, list
)
577 if (!req
->req
.misc
--)
579 get_device(&hi
->host
->device
); /* FIXME handle failure case */
580 list_add_tail(&fi
->list
, &hi
->file_info_list
);
582 /* prevent unloading of the host's low-level driver */
583 if (!try_module_get(hi
->host
->driver
->owner
)) {
584 req
->req
.error
= RAW1394_ERROR_ABORTED
;
589 fi
->state
= connected
;
591 req
->req
.error
= RAW1394_ERROR_NONE
;
592 req
->req
.generation
= get_hpsb_generation(fi
->host
);
593 req
->req
.misc
= (fi
->host
->node_id
<< 16)
594 | fi
->host
->node_count
;
595 if (fi
->protocol_version
> 3)
596 req
->req
.misc
|= NODEID_TO_NODE(fi
->host
->irm_id
) << 8;
598 spin_unlock_irqrestore(&host_info_lock
, flags
);
604 req
->req
.error
= RAW1394_ERROR_STATE_ORDER
;
609 queue_complete_req(req
);
613 static void handle_fcp_listen(struct file_info
*fi
, struct pending_request
*req
)
616 if (fi
->fcp_buffer
) {
617 req
->req
.error
= RAW1394_ERROR_ALREADY
;
619 fi
->fcp_buffer
= int2ptr(req
->req
.recvb
);
622 if (!fi
->fcp_buffer
) {
623 req
->req
.error
= RAW1394_ERROR_ALREADY
;
625 fi
->fcp_buffer
= NULL
;
630 queue_complete_req(req
);
633 static int handle_async_request(struct file_info
*fi
,
634 struct pending_request
*req
, int node
)
637 struct hpsb_packet
*packet
= NULL
;
638 u64 addr
= req
->req
.address
& 0xffffffffffffULL
;
640 switch (req
->req
.type
) {
641 case RAW1394_REQ_ASYNC_READ
:
642 DBGMSG("read_request called");
644 hpsb_make_readpacket(fi
->host
, node
, addr
, req
->req
.length
);
649 if (req
->req
.length
== 4)
650 req
->data
= &packet
->header
[3];
652 req
->data
= packet
->data
;
656 case RAW1394_REQ_ASYNC_WRITE
:
657 DBGMSG("write_request called");
659 packet
= hpsb_make_writepacket(fi
->host
, node
, addr
, NULL
,
664 if (req
->req
.length
== 4) {
666 (&packet
->header
[3], int2ptr(req
->req
.sendb
),
668 req
->req
.error
= RAW1394_ERROR_MEMFAULT
;
671 (packet
->data
, int2ptr(req
->req
.sendb
),
673 req
->req
.error
= RAW1394_ERROR_MEMFAULT
;
679 case RAW1394_REQ_ASYNC_STREAM
:
680 DBGMSG("stream_request called");
683 hpsb_make_streampacket(fi
->host
, NULL
, req
->req
.length
,
684 node
& 0x3f /*channel */ ,
685 (req
->req
.misc
>> 16) & 0x3,
686 req
->req
.misc
& 0xf);
690 if (copy_from_user(packet
->data
, int2ptr(req
->req
.sendb
),
692 req
->req
.error
= RAW1394_ERROR_MEMFAULT
;
697 case RAW1394_REQ_LOCK
:
698 DBGMSG("lock_request called");
699 if ((req
->req
.misc
== EXTCODE_FETCH_ADD
)
700 || (req
->req
.misc
== EXTCODE_LITTLE_ADD
)) {
701 if (req
->req
.length
!= 4) {
702 req
->req
.error
= RAW1394_ERROR_INVALID_ARG
;
706 if (req
->req
.length
!= 8) {
707 req
->req
.error
= RAW1394_ERROR_INVALID_ARG
;
712 packet
= hpsb_make_lockpacket(fi
->host
, node
, addr
,
713 req
->req
.misc
, NULL
, 0);
717 if (copy_from_user(packet
->data
, int2ptr(req
->req
.sendb
),
719 req
->req
.error
= RAW1394_ERROR_MEMFAULT
;
723 req
->data
= packet
->data
;
727 case RAW1394_REQ_LOCK64
:
728 DBGMSG("lock64_request called");
729 if ((req
->req
.misc
== EXTCODE_FETCH_ADD
)
730 || (req
->req
.misc
== EXTCODE_LITTLE_ADD
)) {
731 if (req
->req
.length
!= 8) {
732 req
->req
.error
= RAW1394_ERROR_INVALID_ARG
;
736 if (req
->req
.length
!= 16) {
737 req
->req
.error
= RAW1394_ERROR_INVALID_ARG
;
741 packet
= hpsb_make_lock64packet(fi
->host
, node
, addr
,
742 req
->req
.misc
, NULL
, 0);
746 if (copy_from_user(packet
->data
, int2ptr(req
->req
.sendb
),
748 req
->req
.error
= RAW1394_ERROR_MEMFAULT
;
752 req
->data
= packet
->data
;
757 req
->req
.error
= RAW1394_ERROR_STATE_ORDER
;
760 req
->packet
= packet
;
762 if (req
->req
.error
) {
764 queue_complete_req(req
);
768 hpsb_set_packet_complete_task(packet
,
769 (void (*)(void *))queue_complete_cb
, req
);
771 spin_lock_irqsave(&fi
->reqlists_lock
, flags
);
772 list_add_tail(&req
->list
, &fi
->req_pending
);
773 spin_unlock_irqrestore(&fi
->reqlists_lock
, flags
);
775 packet
->generation
= req
->req
.generation
;
777 if (hpsb_send_packet(packet
) < 0) {
778 req
->req
.error
= RAW1394_ERROR_SEND_ERROR
;
780 hpsb_free_tlabel(packet
);
781 queue_complete_req(req
);
786 static int handle_async_send(struct file_info
*fi
, struct pending_request
*req
)
789 struct hpsb_packet
*packet
;
790 int header_length
= req
->req
.misc
& 0xffff;
791 int expect_response
= req
->req
.misc
>> 16;
794 if (header_length
> req
->req
.length
|| header_length
< 12 ||
795 header_length
> FIELD_SIZEOF(struct hpsb_packet
, header
)) {
796 req
->req
.error
= RAW1394_ERROR_INVALID_ARG
;
798 queue_complete_req(req
);
802 data_size
= req
->req
.length
- header_length
;
803 packet
= hpsb_alloc_packet(data_size
);
804 req
->packet
= packet
;
808 if (copy_from_user(packet
->header
, int2ptr(req
->req
.sendb
),
810 req
->req
.error
= RAW1394_ERROR_MEMFAULT
;
812 queue_complete_req(req
);
817 (packet
->data
, int2ptr(req
->req
.sendb
) + header_length
,
819 req
->req
.error
= RAW1394_ERROR_MEMFAULT
;
821 queue_complete_req(req
);
825 packet
->type
= hpsb_async
;
826 packet
->node_id
= packet
->header
[0] >> 16;
827 packet
->tcode
= (packet
->header
[0] >> 4) & 0xf;
828 packet
->tlabel
= (packet
->header
[0] >> 10) & 0x3f;
829 packet
->host
= fi
->host
;
830 packet
->expect_response
= expect_response
;
831 packet
->header_size
= header_length
;
832 packet
->data_size
= data_size
;
835 hpsb_set_packet_complete_task(packet
,
836 (void (*)(void *))queue_complete_cb
, req
);
838 spin_lock_irqsave(&fi
->reqlists_lock
, flags
);
839 list_add_tail(&req
->list
, &fi
->req_pending
);
840 spin_unlock_irqrestore(&fi
->reqlists_lock
, flags
);
842 /* Update the generation of the packet just before sending. */
843 packet
->generation
= req
->req
.generation
;
845 if (hpsb_send_packet(packet
) < 0) {
846 req
->req
.error
= RAW1394_ERROR_SEND_ERROR
;
847 queue_complete_req(req
);
853 static int arm_read(struct hpsb_host
*host
, int nodeid
, quadlet_t
* buffer
,
854 u64 addr
, size_t length
, u16 flags
)
856 unsigned long irqflags
;
857 struct pending_request
*req
;
858 struct host_info
*hi
;
859 struct file_info
*fi
= NULL
;
860 struct list_head
*entry
;
861 struct arm_addr
*arm_addr
= NULL
;
862 struct arm_request
*arm_req
= NULL
;
863 struct arm_response
*arm_resp
= NULL
;
864 int found
= 0, size
= 0, rcode
= -1;
865 struct arm_request_response
*arm_req_resp
= NULL
;
867 DBGMSG("arm_read called by node: %X "
868 "addr: %4.4x %8.8x length: %Zu", nodeid
,
869 (u16
) ((addr
>> 32) & 0xFFFF), (u32
) (addr
& 0xFFFFFFFF),
871 spin_lock_irqsave(&host_info_lock
, irqflags
);
872 hi
= find_host_info(host
); /* search address-entry */
874 list_for_each_entry(fi
, &hi
->file_info_list
, list
) {
875 entry
= fi
->addr_list
.next
;
876 while (entry
!= &(fi
->addr_list
)) {
878 list_entry(entry
, struct arm_addr
,
880 if (((arm_addr
->start
) <= (addr
))
881 && ((arm_addr
->end
) >= (addr
+ length
))) {
894 printk(KERN_ERR
"raw1394: arm_read FAILED addr_entry not found"
895 " -> rcode_address_error\n");
896 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
897 return (RCODE_ADDRESS_ERROR
);
899 DBGMSG("arm_read addr_entry FOUND");
901 if (arm_addr
->rec_length
< length
) {
902 DBGMSG("arm_read blocklength too big -> rcode_data_error");
903 rcode
= RCODE_DATA_ERROR
; /* hardware error, data is unavailable */
906 if (arm_addr
->access_rights
& ARM_READ
) {
907 if (!(arm_addr
->client_transactions
& ARM_READ
)) {
909 (arm_addr
->addr_space_buffer
) + (addr
-
913 DBGMSG("arm_read -> (rcode_complete)");
914 rcode
= RCODE_COMPLETE
;
917 rcode
= RCODE_TYPE_ERROR
; /* function not allowed */
918 DBGMSG("arm_read -> rcode_type_error (access denied)");
921 if (arm_addr
->notification_options
& ARM_READ
) {
922 DBGMSG("arm_read -> entering notification-section");
923 req
= __alloc_pending_request(GFP_ATOMIC
);
925 DBGMSG("arm_read -> rcode_conflict_error");
926 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
927 return (RCODE_CONFLICT_ERROR
); /* A resource conflict was detected.
928 The request may be retried */
930 if (rcode
== RCODE_COMPLETE
) {
932 sizeof(struct arm_request
) +
933 sizeof(struct arm_response
) +
934 length
* sizeof(byte_t
) +
935 sizeof(struct arm_request_response
);
938 sizeof(struct arm_request
) +
939 sizeof(struct arm_response
) +
940 sizeof(struct arm_request_response
);
942 req
->data
= kmalloc(size
, GFP_ATOMIC
);
944 free_pending_request(req
);
945 DBGMSG("arm_read -> rcode_conflict_error");
946 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
947 return (RCODE_CONFLICT_ERROR
); /* A resource conflict was detected.
948 The request may be retried */
952 req
->req
.type
= RAW1394_REQ_ARM
;
953 req
->req
.generation
= get_hpsb_generation(host
);
955 (((length
<< 16) & (0xFFFF0000)) | (ARM_READ
& 0xFF));
956 req
->req
.tag
= arm_addr
->arm_tag
;
957 req
->req
.recvb
= arm_addr
->recvb
;
958 req
->req
.length
= size
;
959 arm_req_resp
= (struct arm_request_response
*)(req
->data
);
960 arm_req
= (struct arm_request
*)((byte_t
*) (req
->data
) +
963 arm_request_response
)));
965 (struct arm_response
*)((byte_t
*) (arm_req
) +
966 (sizeof(struct arm_request
)));
967 arm_req
->buffer
= NULL
;
968 arm_resp
->buffer
= NULL
;
969 if (rcode
== RCODE_COMPLETE
) {
971 (byte_t
*) arm_resp
+ sizeof(struct arm_response
);
973 (arm_addr
->addr_space_buffer
) + (addr
-
978 int2ptr((arm_addr
->recvb
) +
979 sizeof(struct arm_request_response
) +
980 sizeof(struct arm_request
) +
981 sizeof(struct arm_response
));
983 arm_resp
->buffer_length
=
984 (rcode
== RCODE_COMPLETE
) ? length
: 0;
985 arm_resp
->response_code
= rcode
;
986 arm_req
->buffer_length
= 0;
987 arm_req
->generation
= req
->req
.generation
;
988 arm_req
->extended_transaction_code
= 0;
989 arm_req
->destination_offset
= addr
;
990 arm_req
->source_nodeid
= nodeid
;
991 arm_req
->destination_nodeid
= host
->node_id
;
992 arm_req
->tlabel
= (flags
>> 10) & 0x3f;
993 arm_req
->tcode
= (flags
>> 4) & 0x0f;
994 arm_req_resp
->request
= int2ptr((arm_addr
->recvb
) +
996 arm_request_response
));
997 arm_req_resp
->response
=
998 int2ptr((arm_addr
->recvb
) +
999 sizeof(struct arm_request_response
) +
1000 sizeof(struct arm_request
));
1001 queue_complete_req(req
);
1003 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1007 static int arm_write(struct hpsb_host
*host
, int nodeid
, int destid
,
1008 quadlet_t
* data
, u64 addr
, size_t length
, u16 flags
)
1010 unsigned long irqflags
;
1011 struct pending_request
*req
;
1012 struct host_info
*hi
;
1013 struct file_info
*fi
= NULL
;
1014 struct list_head
*entry
;
1015 struct arm_addr
*arm_addr
= NULL
;
1016 struct arm_request
*arm_req
= NULL
;
1017 struct arm_response
*arm_resp
= NULL
;
1018 int found
= 0, size
= 0, rcode
= -1, length_conflict
= 0;
1019 struct arm_request_response
*arm_req_resp
= NULL
;
1021 DBGMSG("arm_write called by node: %X "
1022 "addr: %4.4x %8.8x length: %Zu", nodeid
,
1023 (u16
) ((addr
>> 32) & 0xFFFF), (u32
) (addr
& 0xFFFFFFFF),
1025 spin_lock_irqsave(&host_info_lock
, irqflags
);
1026 hi
= find_host_info(host
); /* search address-entry */
1028 list_for_each_entry(fi
, &hi
->file_info_list
, list
) {
1029 entry
= fi
->addr_list
.next
;
1030 while (entry
!= &(fi
->addr_list
)) {
1032 list_entry(entry
, struct arm_addr
,
1034 if (((arm_addr
->start
) <= (addr
))
1035 && ((arm_addr
->end
) >= (addr
+ length
))) {
1039 entry
= entry
->next
;
1048 printk(KERN_ERR
"raw1394: arm_write FAILED addr_entry not found"
1049 " -> rcode_address_error\n");
1050 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1051 return (RCODE_ADDRESS_ERROR
);
1053 DBGMSG("arm_write addr_entry FOUND");
1055 if (arm_addr
->rec_length
< length
) {
1056 DBGMSG("arm_write blocklength too big -> rcode_data_error");
1057 length_conflict
= 1;
1058 rcode
= RCODE_DATA_ERROR
; /* hardware error, data is unavailable */
1061 if (arm_addr
->access_rights
& ARM_WRITE
) {
1062 if (!(arm_addr
->client_transactions
& ARM_WRITE
)) {
1063 memcpy((arm_addr
->addr_space_buffer
) +
1064 (addr
- (arm_addr
->start
)), data
,
1066 DBGMSG("arm_write -> (rcode_complete)");
1067 rcode
= RCODE_COMPLETE
;
1070 rcode
= RCODE_TYPE_ERROR
; /* function not allowed */
1071 DBGMSG("arm_write -> rcode_type_error (access denied)");
1074 if (arm_addr
->notification_options
& ARM_WRITE
) {
1075 DBGMSG("arm_write -> entering notification-section");
1076 req
= __alloc_pending_request(GFP_ATOMIC
);
1078 DBGMSG("arm_write -> rcode_conflict_error");
1079 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1080 return (RCODE_CONFLICT_ERROR
); /* A resource conflict was detected.
1081 The request my be retried */
1084 sizeof(struct arm_request
) + sizeof(struct arm_response
) +
1085 (length
) * sizeof(byte_t
) +
1086 sizeof(struct arm_request_response
);
1087 req
->data
= kmalloc(size
, GFP_ATOMIC
);
1089 free_pending_request(req
);
1090 DBGMSG("arm_write -> rcode_conflict_error");
1091 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1092 return (RCODE_CONFLICT_ERROR
); /* A resource conflict was detected.
1093 The request may be retried */
1096 req
->file_info
= fi
;
1097 req
->req
.type
= RAW1394_REQ_ARM
;
1098 req
->req
.generation
= get_hpsb_generation(host
);
1100 (((length
<< 16) & (0xFFFF0000)) | (ARM_WRITE
& 0xFF));
1101 req
->req
.tag
= arm_addr
->arm_tag
;
1102 req
->req
.recvb
= arm_addr
->recvb
;
1103 req
->req
.length
= size
;
1104 arm_req_resp
= (struct arm_request_response
*)(req
->data
);
1105 arm_req
= (struct arm_request
*)((byte_t
*) (req
->data
) +
1108 arm_request_response
)));
1110 (struct arm_response
*)((byte_t
*) (arm_req
) +
1111 (sizeof(struct arm_request
)));
1112 arm_resp
->buffer
= NULL
;
1113 memcpy((byte_t
*) arm_resp
+ sizeof(struct arm_response
),
1115 arm_req
->buffer
= int2ptr((arm_addr
->recvb
) +
1116 sizeof(struct arm_request_response
) +
1117 sizeof(struct arm_request
) +
1118 sizeof(struct arm_response
));
1119 arm_req
->buffer_length
= length
;
1120 arm_req
->generation
= req
->req
.generation
;
1121 arm_req
->extended_transaction_code
= 0;
1122 arm_req
->destination_offset
= addr
;
1123 arm_req
->source_nodeid
= nodeid
;
1124 arm_req
->destination_nodeid
= destid
;
1125 arm_req
->tlabel
= (flags
>> 10) & 0x3f;
1126 arm_req
->tcode
= (flags
>> 4) & 0x0f;
1127 arm_resp
->buffer_length
= 0;
1128 arm_resp
->response_code
= rcode
;
1129 arm_req_resp
->request
= int2ptr((arm_addr
->recvb
) +
1131 arm_request_response
));
1132 arm_req_resp
->response
=
1133 int2ptr((arm_addr
->recvb
) +
1134 sizeof(struct arm_request_response
) +
1135 sizeof(struct arm_request
));
1136 queue_complete_req(req
);
1138 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1142 static int arm_lock(struct hpsb_host
*host
, int nodeid
, quadlet_t
* store
,
1143 u64 addr
, quadlet_t data
, quadlet_t arg
, int ext_tcode
,
1146 unsigned long irqflags
;
1147 struct pending_request
*req
;
1148 struct host_info
*hi
;
1149 struct file_info
*fi
= NULL
;
1150 struct list_head
*entry
;
1151 struct arm_addr
*arm_addr
= NULL
;
1152 struct arm_request
*arm_req
= NULL
;
1153 struct arm_response
*arm_resp
= NULL
;
1154 int found
= 0, size
= 0, rcode
= -1;
1156 struct arm_request_response
*arm_req_resp
= NULL
;
1158 if (((ext_tcode
& 0xFF) == EXTCODE_FETCH_ADD
) ||
1159 ((ext_tcode
& 0xFF) == EXTCODE_LITTLE_ADD
)) {
1160 DBGMSG("arm_lock called by node: %X "
1161 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X",
1162 nodeid
, (u16
) ((addr
>> 32) & 0xFFFF),
1163 (u32
) (addr
& 0xFFFFFFFF), ext_tcode
& 0xFF,
1166 DBGMSG("arm_lock called by node: %X "
1167 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X arg: %8.8X",
1168 nodeid
, (u16
) ((addr
>> 32) & 0xFFFF),
1169 (u32
) (addr
& 0xFFFFFFFF), ext_tcode
& 0xFF,
1170 be32_to_cpu(data
), be32_to_cpu(arg
));
1172 spin_lock_irqsave(&host_info_lock
, irqflags
);
1173 hi
= find_host_info(host
); /* search address-entry */
1175 list_for_each_entry(fi
, &hi
->file_info_list
, list
) {
1176 entry
= fi
->addr_list
.next
;
1177 while (entry
!= &(fi
->addr_list
)) {
1179 list_entry(entry
, struct arm_addr
,
1181 if (((arm_addr
->start
) <= (addr
))
1182 && ((arm_addr
->end
) >=
1183 (addr
+ sizeof(*store
)))) {
1187 entry
= entry
->next
;
1196 printk(KERN_ERR
"raw1394: arm_lock FAILED addr_entry not found"
1197 " -> rcode_address_error\n");
1198 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1199 return (RCODE_ADDRESS_ERROR
);
1201 DBGMSG("arm_lock addr_entry FOUND");
1204 if (arm_addr
->access_rights
& ARM_LOCK
) {
1205 if (!(arm_addr
->client_transactions
& ARM_LOCK
)) {
1207 (arm_addr
->addr_space_buffer
) + (addr
-
1211 switch (ext_tcode
) {
1212 case (EXTCODE_MASK_SWAP
):
1213 new = data
| (old
& ~arg
);
1215 case (EXTCODE_COMPARE_SWAP
):
1222 case (EXTCODE_FETCH_ADD
):
1224 cpu_to_be32(be32_to_cpu(data
) +
1227 case (EXTCODE_LITTLE_ADD
):
1229 cpu_to_le32(le32_to_cpu(data
) +
1232 case (EXTCODE_BOUNDED_ADD
):
1235 cpu_to_be32(be32_to_cpu
1243 case (EXTCODE_WRAP_ADD
):
1246 cpu_to_be32(be32_to_cpu
1255 rcode
= RCODE_TYPE_ERROR
; /* function not allowed */
1257 "raw1394: arm_lock FAILED "
1258 "ext_tcode not allowed -> rcode_type_error\n");
1262 DBGMSG("arm_lock -> (rcode_complete)");
1263 rcode
= RCODE_COMPLETE
;
1264 memcpy(store
, &old
, sizeof(*store
));
1265 memcpy((arm_addr
->addr_space_buffer
) +
1266 (addr
- (arm_addr
->start
)),
1267 &new, sizeof(*store
));
1271 rcode
= RCODE_TYPE_ERROR
; /* function not allowed */
1272 DBGMSG("arm_lock -> rcode_type_error (access denied)");
1275 if (arm_addr
->notification_options
& ARM_LOCK
) {
1276 byte_t
*buf1
, *buf2
;
1277 DBGMSG("arm_lock -> entering notification-section");
1278 req
= __alloc_pending_request(GFP_ATOMIC
);
1280 DBGMSG("arm_lock -> rcode_conflict_error");
1281 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1282 return (RCODE_CONFLICT_ERROR
); /* A resource conflict was detected.
1283 The request may be retried */
1285 size
= sizeof(struct arm_request
) + sizeof(struct arm_response
) + 3 * sizeof(*store
) + sizeof(struct arm_request_response
); /* maximum */
1286 req
->data
= kmalloc(size
, GFP_ATOMIC
);
1288 free_pending_request(req
);
1289 DBGMSG("arm_lock -> rcode_conflict_error");
1290 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1291 return (RCODE_CONFLICT_ERROR
); /* A resource conflict was detected.
1292 The request may be retried */
1295 arm_req_resp
= (struct arm_request_response
*)(req
->data
);
1296 arm_req
= (struct arm_request
*)((byte_t
*) (req
->data
) +
1299 arm_request_response
)));
1301 (struct arm_response
*)((byte_t
*) (arm_req
) +
1302 (sizeof(struct arm_request
)));
1303 buf1
= (byte_t
*) arm_resp
+ sizeof(struct arm_response
);
1304 buf2
= buf1
+ 2 * sizeof(*store
);
1305 if ((ext_tcode
== EXTCODE_FETCH_ADD
) ||
1306 (ext_tcode
== EXTCODE_LITTLE_ADD
)) {
1307 arm_req
->buffer_length
= sizeof(*store
);
1308 memcpy(buf1
, &data
, sizeof(*store
));
1311 arm_req
->buffer_length
= 2 * sizeof(*store
);
1312 memcpy(buf1
, &arg
, sizeof(*store
));
1313 memcpy(buf1
+ sizeof(*store
), &data
, sizeof(*store
));
1315 if (rcode
== RCODE_COMPLETE
) {
1316 arm_resp
->buffer_length
= sizeof(*store
);
1317 memcpy(buf2
, &old
, sizeof(*store
));
1319 arm_resp
->buffer_length
= 0;
1321 req
->file_info
= fi
;
1322 req
->req
.type
= RAW1394_REQ_ARM
;
1323 req
->req
.generation
= get_hpsb_generation(host
);
1324 req
->req
.misc
= ((((sizeof(*store
)) << 16) & (0xFFFF0000)) |
1326 req
->req
.tag
= arm_addr
->arm_tag
;
1327 req
->req
.recvb
= arm_addr
->recvb
;
1328 req
->req
.length
= size
;
1329 arm_req
->generation
= req
->req
.generation
;
1330 arm_req
->extended_transaction_code
= ext_tcode
;
1331 arm_req
->destination_offset
= addr
;
1332 arm_req
->source_nodeid
= nodeid
;
1333 arm_req
->destination_nodeid
= host
->node_id
;
1334 arm_req
->tlabel
= (flags
>> 10) & 0x3f;
1335 arm_req
->tcode
= (flags
>> 4) & 0x0f;
1336 arm_resp
->response_code
= rcode
;
1337 arm_req_resp
->request
= int2ptr((arm_addr
->recvb
) +
1339 arm_request_response
));
1340 arm_req_resp
->response
=
1341 int2ptr((arm_addr
->recvb
) +
1342 sizeof(struct arm_request_response
) +
1343 sizeof(struct arm_request
));
1345 int2ptr((arm_addr
->recvb
) +
1346 sizeof(struct arm_request_response
) +
1347 sizeof(struct arm_request
) +
1348 sizeof(struct arm_response
));
1350 int2ptr((arm_addr
->recvb
) +
1351 sizeof(struct arm_request_response
) +
1352 sizeof(struct arm_request
) +
1353 sizeof(struct arm_response
) + 2 * sizeof(*store
));
1354 queue_complete_req(req
);
1356 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1360 static int arm_lock64(struct hpsb_host
*host
, int nodeid
, octlet_t
* store
,
1361 u64 addr
, octlet_t data
, octlet_t arg
, int ext_tcode
,
1364 unsigned long irqflags
;
1365 struct pending_request
*req
;
1366 struct host_info
*hi
;
1367 struct file_info
*fi
= NULL
;
1368 struct list_head
*entry
;
1369 struct arm_addr
*arm_addr
= NULL
;
1370 struct arm_request
*arm_req
= NULL
;
1371 struct arm_response
*arm_resp
= NULL
;
1372 int found
= 0, size
= 0, rcode
= -1;
1374 struct arm_request_response
*arm_req_resp
= NULL
;
1376 if (((ext_tcode
& 0xFF) == EXTCODE_FETCH_ADD
) ||
1377 ((ext_tcode
& 0xFF) == EXTCODE_LITTLE_ADD
)) {
1378 DBGMSG("arm_lock64 called by node: %X "
1379 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X ",
1380 nodeid
, (u16
) ((addr
>> 32) & 0xFFFF),
1381 (u32
) (addr
& 0xFFFFFFFF),
1383 (u32
) ((be64_to_cpu(data
) >> 32) & 0xFFFFFFFF),
1384 (u32
) (be64_to_cpu(data
) & 0xFFFFFFFF));
1386 DBGMSG("arm_lock64 called by node: %X "
1387 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X arg: "
1389 nodeid
, (u16
) ((addr
>> 32) & 0xFFFF),
1390 (u32
) (addr
& 0xFFFFFFFF),
1392 (u32
) ((be64_to_cpu(data
) >> 32) & 0xFFFFFFFF),
1393 (u32
) (be64_to_cpu(data
) & 0xFFFFFFFF),
1394 (u32
) ((be64_to_cpu(arg
) >> 32) & 0xFFFFFFFF),
1395 (u32
) (be64_to_cpu(arg
) & 0xFFFFFFFF));
1397 spin_lock_irqsave(&host_info_lock
, irqflags
);
1398 hi
= find_host_info(host
); /* search addressentry in file_info's for host */
1400 list_for_each_entry(fi
, &hi
->file_info_list
, list
) {
1401 entry
= fi
->addr_list
.next
;
1402 while (entry
!= &(fi
->addr_list
)) {
1404 list_entry(entry
, struct arm_addr
,
1406 if (((arm_addr
->start
) <= (addr
))
1407 && ((arm_addr
->end
) >=
1408 (addr
+ sizeof(*store
)))) {
1412 entry
= entry
->next
;
1422 "raw1394: arm_lock64 FAILED addr_entry not found"
1423 " -> rcode_address_error\n");
1424 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1425 return (RCODE_ADDRESS_ERROR
);
1427 DBGMSG("arm_lock64 addr_entry FOUND");
1430 if (arm_addr
->access_rights
& ARM_LOCK
) {
1431 if (!(arm_addr
->client_transactions
& ARM_LOCK
)) {
1433 (arm_addr
->addr_space_buffer
) + (addr
-
1437 switch (ext_tcode
) {
1438 case (EXTCODE_MASK_SWAP
):
1439 new = data
| (old
& ~arg
);
1441 case (EXTCODE_COMPARE_SWAP
):
1448 case (EXTCODE_FETCH_ADD
):
1450 cpu_to_be64(be64_to_cpu(data
) +
1453 case (EXTCODE_LITTLE_ADD
):
1455 cpu_to_le64(le64_to_cpu(data
) +
1458 case (EXTCODE_BOUNDED_ADD
):
1461 cpu_to_be64(be64_to_cpu
1469 case (EXTCODE_WRAP_ADD
):
1472 cpu_to_be64(be64_to_cpu
1482 "raw1394: arm_lock64 FAILED "
1483 "ext_tcode not allowed -> rcode_type_error\n");
1484 rcode
= RCODE_TYPE_ERROR
; /* function not allowed */
1489 ("arm_lock64 -> (rcode_complete)");
1490 rcode
= RCODE_COMPLETE
;
1491 memcpy(store
, &old
, sizeof(*store
));
1492 memcpy((arm_addr
->addr_space_buffer
) +
1493 (addr
- (arm_addr
->start
)),
1494 &new, sizeof(*store
));
1498 rcode
= RCODE_TYPE_ERROR
; /* function not allowed */
1500 ("arm_lock64 -> rcode_type_error (access denied)");
1503 if (arm_addr
->notification_options
& ARM_LOCK
) {
1504 byte_t
*buf1
, *buf2
;
1505 DBGMSG("arm_lock64 -> entering notification-section");
1506 req
= __alloc_pending_request(GFP_ATOMIC
);
1508 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1509 DBGMSG("arm_lock64 -> rcode_conflict_error");
1510 return (RCODE_CONFLICT_ERROR
); /* A resource conflict was detected.
1511 The request may be retried */
1513 size
= sizeof(struct arm_request
) + sizeof(struct arm_response
) + 3 * sizeof(*store
) + sizeof(struct arm_request_response
); /* maximum */
1514 req
->data
= kmalloc(size
, GFP_ATOMIC
);
1516 free_pending_request(req
);
1517 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1518 DBGMSG("arm_lock64 -> rcode_conflict_error");
1519 return (RCODE_CONFLICT_ERROR
); /* A resource conflict was detected.
1520 The request may be retried */
1523 arm_req_resp
= (struct arm_request_response
*)(req
->data
);
1524 arm_req
= (struct arm_request
*)((byte_t
*) (req
->data
) +
1527 arm_request_response
)));
1529 (struct arm_response
*)((byte_t
*) (arm_req
) +
1530 (sizeof(struct arm_request
)));
1531 buf1
= (byte_t
*) arm_resp
+ sizeof(struct arm_response
);
1532 buf2
= buf1
+ 2 * sizeof(*store
);
1533 if ((ext_tcode
== EXTCODE_FETCH_ADD
) ||
1534 (ext_tcode
== EXTCODE_LITTLE_ADD
)) {
1535 arm_req
->buffer_length
= sizeof(*store
);
1536 memcpy(buf1
, &data
, sizeof(*store
));
1539 arm_req
->buffer_length
= 2 * sizeof(*store
);
1540 memcpy(buf1
, &arg
, sizeof(*store
));
1541 memcpy(buf1
+ sizeof(*store
), &data
, sizeof(*store
));
1543 if (rcode
== RCODE_COMPLETE
) {
1544 arm_resp
->buffer_length
= sizeof(*store
);
1545 memcpy(buf2
, &old
, sizeof(*store
));
1547 arm_resp
->buffer_length
= 0;
1549 req
->file_info
= fi
;
1550 req
->req
.type
= RAW1394_REQ_ARM
;
1551 req
->req
.generation
= get_hpsb_generation(host
);
1552 req
->req
.misc
= ((((sizeof(*store
)) << 16) & (0xFFFF0000)) |
1554 req
->req
.tag
= arm_addr
->arm_tag
;
1555 req
->req
.recvb
= arm_addr
->recvb
;
1556 req
->req
.length
= size
;
1557 arm_req
->generation
= req
->req
.generation
;
1558 arm_req
->extended_transaction_code
= ext_tcode
;
1559 arm_req
->destination_offset
= addr
;
1560 arm_req
->source_nodeid
= nodeid
;
1561 arm_req
->destination_nodeid
= host
->node_id
;
1562 arm_req
->tlabel
= (flags
>> 10) & 0x3f;
1563 arm_req
->tcode
= (flags
>> 4) & 0x0f;
1564 arm_resp
->response_code
= rcode
;
1565 arm_req_resp
->request
= int2ptr((arm_addr
->recvb
) +
1567 arm_request_response
));
1568 arm_req_resp
->response
=
1569 int2ptr((arm_addr
->recvb
) +
1570 sizeof(struct arm_request_response
) +
1571 sizeof(struct arm_request
));
1573 int2ptr((arm_addr
->recvb
) +
1574 sizeof(struct arm_request_response
) +
1575 sizeof(struct arm_request
) +
1576 sizeof(struct arm_response
));
1578 int2ptr((arm_addr
->recvb
) +
1579 sizeof(struct arm_request_response
) +
1580 sizeof(struct arm_request
) +
1581 sizeof(struct arm_response
) + 2 * sizeof(*store
));
1582 queue_complete_req(req
);
1584 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1588 static int arm_register(struct file_info
*fi
, struct pending_request
*req
)
1591 struct arm_addr
*addr
;
1592 struct host_info
*hi
;
1593 struct file_info
*fi_hlp
= NULL
;
1594 struct list_head
*entry
;
1595 struct arm_addr
*arm_addr
= NULL
;
1596 int same_host
, another_host
;
1597 unsigned long flags
;
1599 DBGMSG("arm_register called "
1600 "addr(Offset): %8.8x %8.8x length: %u "
1601 "rights: %2.2X notify: %2.2X "
1602 "max_blk_len: %4.4X",
1603 (u32
) ((req
->req
.address
>> 32) & 0xFFFF),
1604 (u32
) (req
->req
.address
& 0xFFFFFFFF),
1605 req
->req
.length
, ((req
->req
.misc
>> 8) & 0xFF),
1606 (req
->req
.misc
& 0xFF), ((req
->req
.misc
>> 16) & 0xFFFF));
1607 /* check addressrange */
1608 if ((((req
->req
.address
) & ~(0xFFFFFFFFFFFFULL
)) != 0) ||
1609 (((req
->req
.address
+ req
->req
.length
) & ~(0xFFFFFFFFFFFFULL
)) !=
1611 req
->req
.length
= 0;
1614 /* addr-list-entry for fileinfo */
1615 addr
= kmalloc(sizeof(*addr
), GFP_KERNEL
);
1617 req
->req
.length
= 0;
1620 /* allocation of addr_space_buffer */
1621 addr
->addr_space_buffer
= vmalloc(req
->req
.length
);
1622 if (!(addr
->addr_space_buffer
)) {
1624 req
->req
.length
= 0;
1627 /* initialization of addr_space_buffer */
1628 if ((req
->req
.sendb
) == (unsigned long)NULL
) {
1630 memset(addr
->addr_space_buffer
, 0, req
->req
.length
);
1632 /* init: user -> kernel */
1634 (addr
->addr_space_buffer
, int2ptr(req
->req
.sendb
),
1636 vfree(addr
->addr_space_buffer
);
1641 INIT_LIST_HEAD(&addr
->addr_list
);
1642 addr
->arm_tag
= req
->req
.tag
;
1643 addr
->start
= req
->req
.address
;
1644 addr
->end
= req
->req
.address
+ req
->req
.length
;
1645 addr
->access_rights
= (u8
) (req
->req
.misc
& 0x0F);
1646 addr
->notification_options
= (u8
) ((req
->req
.misc
>> 4) & 0x0F);
1647 addr
->client_transactions
= (u8
) ((req
->req
.misc
>> 8) & 0x0F);
1648 addr
->access_rights
|= addr
->client_transactions
;
1649 addr
->notification_options
|= addr
->client_transactions
;
1650 addr
->recvb
= req
->req
.recvb
;
1651 addr
->rec_length
= (u16
) ((req
->req
.misc
>> 16) & 0xFFFF);
1653 spin_lock_irqsave(&host_info_lock
, flags
);
1654 hi
= find_host_info(fi
->host
);
1657 /* same host with address-entry containing same addressrange ? */
1658 list_for_each_entry(fi_hlp
, &hi
->file_info_list
, list
) {
1659 entry
= fi_hlp
->addr_list
.next
;
1660 while (entry
!= &(fi_hlp
->addr_list
)) {
1662 list_entry(entry
, struct arm_addr
, addr_list
);
1663 if ((arm_addr
->start
== addr
->start
)
1664 && (arm_addr
->end
== addr
->end
)) {
1665 DBGMSG("same host ownes same "
1666 "addressrange -> EALREADY");
1670 entry
= entry
->next
;
1677 /* addressrange occupied by same host */
1678 spin_unlock_irqrestore(&host_info_lock
, flags
);
1679 vfree(addr
->addr_space_buffer
);
1683 /* another host with valid address-entry containing same addressrange */
1684 list_for_each_entry(hi
, &host_info_list
, list
) {
1685 if (hi
->host
!= fi
->host
) {
1686 list_for_each_entry(fi_hlp
, &hi
->file_info_list
, list
) {
1687 entry
= fi_hlp
->addr_list
.next
;
1688 while (entry
!= &(fi_hlp
->addr_list
)) {
1690 list_entry(entry
, struct arm_addr
,
1692 if ((arm_addr
->start
== addr
->start
)
1693 && (arm_addr
->end
== addr
->end
)) {
1695 ("another host ownes same "
1700 entry
= entry
->next
;
1708 spin_unlock_irqrestore(&host_info_lock
, flags
);
1711 DBGMSG("another hosts entry is valid -> SUCCESS");
1712 if (copy_to_user(int2ptr(req
->req
.recvb
),
1713 &addr
->start
, sizeof(u64
))) {
1714 printk(KERN_ERR
"raw1394: arm_register failed "
1715 " address-range-entry is invalid -> EFAULT !!!\n");
1716 vfree(addr
->addr_space_buffer
);
1720 free_pending_request(req
); /* immediate success or fail */
1722 spin_lock_irqsave(&host_info_lock
, flags
);
1723 list_add_tail(&addr
->addr_list
, &fi
->addr_list
);
1724 spin_unlock_irqrestore(&host_info_lock
, flags
);
1728 hpsb_register_addrspace(&raw1394_highlevel
, fi
->host
, &arm_ops
,
1730 req
->req
.address
+ req
->req
.length
);
1733 spin_lock_irqsave(&host_info_lock
, flags
);
1734 list_add_tail(&addr
->addr_list
, &fi
->addr_list
);
1735 spin_unlock_irqrestore(&host_info_lock
, flags
);
1737 DBGMSG("arm_register failed errno: %d \n", retval
);
1738 vfree(addr
->addr_space_buffer
);
1742 free_pending_request(req
); /* immediate success or fail */
1746 static int arm_unregister(struct file_info
*fi
, struct pending_request
*req
)
1750 struct list_head
*entry
;
1751 struct arm_addr
*addr
= NULL
;
1752 struct host_info
*hi
;
1753 struct file_info
*fi_hlp
= NULL
;
1754 struct arm_addr
*arm_addr
= NULL
;
1756 unsigned long flags
;
1758 DBGMSG("arm_Unregister called addr(Offset): "
1760 (u32
) ((req
->req
.address
>> 32) & 0xFFFF),
1761 (u32
) (req
->req
.address
& 0xFFFFFFFF));
1762 spin_lock_irqsave(&host_info_lock
, flags
);
1764 entry
= fi
->addr_list
.next
;
1765 while (entry
!= &(fi
->addr_list
)) {
1766 addr
= list_entry(entry
, struct arm_addr
, addr_list
);
1767 if (addr
->start
== req
->req
.address
) {
1771 entry
= entry
->next
;
1774 DBGMSG("arm_Unregister addr not found");
1775 spin_unlock_irqrestore(&host_info_lock
, flags
);
1778 DBGMSG("arm_Unregister addr found");
1780 /* another host with valid address-entry containing
1781 same addressrange */
1782 list_for_each_entry(hi
, &host_info_list
, list
) {
1783 if (hi
->host
!= fi
->host
) {
1784 list_for_each_entry(fi_hlp
, &hi
->file_info_list
, list
) {
1785 entry
= fi_hlp
->addr_list
.next
;
1786 while (entry
!= &(fi_hlp
->addr_list
)) {
1787 arm_addr
= list_entry(entry
,
1790 if (arm_addr
->start
== addr
->start
) {
1791 DBGMSG("another host ownes "
1792 "same addressrange");
1796 entry
= entry
->next
;
1805 DBGMSG("delete entry from list -> success");
1806 list_del(&addr
->addr_list
);
1807 spin_unlock_irqrestore(&host_info_lock
, flags
);
1808 vfree(addr
->addr_space_buffer
);
1810 free_pending_request(req
); /* immediate success or fail */
1814 hpsb_unregister_addrspace(&raw1394_highlevel
, fi
->host
,
1817 printk(KERN_ERR
"raw1394: arm_Unregister failed -> EINVAL\n");
1818 spin_unlock_irqrestore(&host_info_lock
, flags
);
1821 DBGMSG("delete entry from list -> success");
1822 list_del(&addr
->addr_list
);
1823 spin_unlock_irqrestore(&host_info_lock
, flags
);
1824 vfree(addr
->addr_space_buffer
);
1826 free_pending_request(req
); /* immediate success or fail */
1830 /* Copy data from ARM buffer(s) to user buffer. */
1831 static int arm_get_buf(struct file_info
*fi
, struct pending_request
*req
)
1833 struct arm_addr
*arm_addr
= NULL
;
1834 unsigned long flags
;
1835 unsigned long offset
;
1837 struct list_head
*entry
;
1839 DBGMSG("arm_get_buf "
1840 "addr(Offset): %04X %08X length: %u",
1841 (u32
) ((req
->req
.address
>> 32) & 0xFFFF),
1842 (u32
) (req
->req
.address
& 0xFFFFFFFF), (u32
) req
->req
.length
);
1844 spin_lock_irqsave(&host_info_lock
, flags
);
1845 entry
= fi
->addr_list
.next
;
1846 while (entry
!= &(fi
->addr_list
)) {
1847 arm_addr
= list_entry(entry
, struct arm_addr
, addr_list
);
1848 if ((arm_addr
->start
<= req
->req
.address
) &&
1849 (arm_addr
->end
> req
->req
.address
)) {
1850 if (req
->req
.address
+ req
->req
.length
<= arm_addr
->end
) {
1851 offset
= req
->req
.address
- arm_addr
->start
;
1852 spin_unlock_irqrestore(&host_info_lock
, flags
);
1855 ("arm_get_buf copy_to_user( %08X, %p, %u )",
1856 (u32
) req
->req
.recvb
,
1857 arm_addr
->addr_space_buffer
+ offset
,
1858 (u32
) req
->req
.length
);
1860 (int2ptr(req
->req
.recvb
),
1861 arm_addr
->addr_space_buffer
+ offset
,
1865 /* We have to free the request, because we
1866 * queue no response, and therefore nobody
1868 free_pending_request(req
);
1871 DBGMSG("arm_get_buf request exceeded mapping");
1872 spin_unlock_irqrestore(&host_info_lock
, flags
);
1876 entry
= entry
->next
;
1878 spin_unlock_irqrestore(&host_info_lock
, flags
);
1882 /* Copy data from user buffer to ARM buffer(s). */
1883 static int arm_set_buf(struct file_info
*fi
, struct pending_request
*req
)
1885 struct arm_addr
*arm_addr
= NULL
;
1886 unsigned long flags
;
1887 unsigned long offset
;
1889 struct list_head
*entry
;
1891 DBGMSG("arm_set_buf "
1892 "addr(Offset): %04X %08X length: %u",
1893 (u32
) ((req
->req
.address
>> 32) & 0xFFFF),
1894 (u32
) (req
->req
.address
& 0xFFFFFFFF), (u32
) req
->req
.length
);
1896 spin_lock_irqsave(&host_info_lock
, flags
);
1897 entry
= fi
->addr_list
.next
;
1898 while (entry
!= &(fi
->addr_list
)) {
1899 arm_addr
= list_entry(entry
, struct arm_addr
, addr_list
);
1900 if ((arm_addr
->start
<= req
->req
.address
) &&
1901 (arm_addr
->end
> req
->req
.address
)) {
1902 if (req
->req
.address
+ req
->req
.length
<= arm_addr
->end
) {
1903 offset
= req
->req
.address
- arm_addr
->start
;
1904 spin_unlock_irqrestore(&host_info_lock
, flags
);
1907 ("arm_set_buf copy_from_user( %p, %08X, %u )",
1908 arm_addr
->addr_space_buffer
+ offset
,
1909 (u32
) req
->req
.sendb
,
1910 (u32
) req
->req
.length
);
1912 (arm_addr
->addr_space_buffer
+ offset
,
1913 int2ptr(req
->req
.sendb
),
1917 /* We have to free the request, because we
1918 * queue no response, and therefore nobody
1920 free_pending_request(req
);
1923 DBGMSG("arm_set_buf request exceeded mapping");
1924 spin_unlock_irqrestore(&host_info_lock
, flags
);
1928 entry
= entry
->next
;
1930 spin_unlock_irqrestore(&host_info_lock
, flags
);
1934 static int reset_notification(struct file_info
*fi
, struct pending_request
*req
)
1936 DBGMSG("reset_notification called - switch %s ",
1937 (req
->req
.misc
== RAW1394_NOTIFY_OFF
) ? "OFF" : "ON");
1938 if ((req
->req
.misc
== RAW1394_NOTIFY_OFF
) ||
1939 (req
->req
.misc
== RAW1394_NOTIFY_ON
)) {
1940 fi
->notification
= (u8
) req
->req
.misc
;
1941 free_pending_request(req
); /* we have to free the request, because we queue no response, and therefore nobody will free it */
1944 /* error EINVAL (22) invalid argument */
1948 static int write_phypacket(struct file_info
*fi
, struct pending_request
*req
)
1950 struct hpsb_packet
*packet
= NULL
;
1953 unsigned long flags
;
1955 data
= be32_to_cpu((u32
) req
->req
.sendb
);
1956 DBGMSG("write_phypacket called - quadlet 0x%8.8x ", data
);
1957 packet
= hpsb_make_phypacket(fi
->host
, data
);
1960 req
->req
.length
= 0;
1961 req
->packet
= packet
;
1962 hpsb_set_packet_complete_task(packet
,
1963 (void (*)(void *))queue_complete_cb
, req
);
1964 spin_lock_irqsave(&fi
->reqlists_lock
, flags
);
1965 list_add_tail(&req
->list
, &fi
->req_pending
);
1966 spin_unlock_irqrestore(&fi
->reqlists_lock
, flags
);
1967 packet
->generation
= req
->req
.generation
;
1968 retval
= hpsb_send_packet(packet
);
1969 DBGMSG("write_phypacket send_packet called => retval: %d ", retval
);
1971 req
->req
.error
= RAW1394_ERROR_SEND_ERROR
;
1972 req
->req
.length
= 0;
1973 queue_complete_req(req
);
1978 static int get_config_rom(struct file_info
*fi
, struct pending_request
*req
)
1981 quadlet_t
*data
= kmalloc(req
->req
.length
, GFP_KERNEL
);
1988 csr1212_read(fi
->host
->csr
.rom
, CSR1212_CONFIG_ROM_SPACE_OFFSET
,
1989 data
, req
->req
.length
);
1990 if (copy_to_user(int2ptr(req
->req
.recvb
), data
, req
->req
.length
))
1993 (int2ptr(req
->req
.tag
), &fi
->host
->csr
.rom
->cache_head
->len
,
1994 sizeof(fi
->host
->csr
.rom
->cache_head
->len
)))
1996 if (copy_to_user(int2ptr(req
->req
.address
), &fi
->host
->csr
.generation
,
1997 sizeof(fi
->host
->csr
.generation
)))
1999 if (copy_to_user(int2ptr(req
->req
.sendb
), &status
, sizeof(status
)))
2003 free_pending_request(req
); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2008 static int update_config_rom(struct file_info
*fi
, struct pending_request
*req
)
2011 quadlet_t
*data
= kmalloc(req
->req
.length
, GFP_KERNEL
);
2014 if (copy_from_user(data
, int2ptr(req
->req
.sendb
), req
->req
.length
)) {
2017 int status
= hpsb_update_config_rom(fi
->host
,
2018 data
, req
->req
.length
,
2019 (unsigned char)req
->req
.
2022 (int2ptr(req
->req
.recvb
), &status
, sizeof(status
)))
2027 free_pending_request(req
); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2033 static int modify_config_rom(struct file_info
*fi
, struct pending_request
*req
)
2035 struct csr1212_keyval
*kv
;
2036 struct csr1212_csr_rom_cache
*cache
;
2037 struct csr1212_dentry
*dentry
;
2041 if (req
->req
.misc
== ~0) {
2042 if (req
->req
.length
== 0)
2045 /* Find an unused slot */
2047 dr
< RAW1394_MAX_USER_CSR_DIRS
&& fi
->csr1212_dirs
[dr
];
2050 if (dr
== RAW1394_MAX_USER_CSR_DIRS
)
2053 fi
->csr1212_dirs
[dr
] =
2054 csr1212_new_directory(CSR1212_KV_ID_VENDOR
);
2055 if (!fi
->csr1212_dirs
[dr
])
2059 if (!fi
->csr1212_dirs
[dr
])
2062 /* Delete old stuff */
2064 fi
->csr1212_dirs
[dr
]->value
.directory
.dentries_head
;
2065 dentry
; dentry
= dentry
->next
) {
2066 csr1212_detach_keyval_from_directory(fi
->host
->csr
.rom
->
2071 if (req
->req
.length
== 0) {
2072 csr1212_release_keyval(fi
->csr1212_dirs
[dr
]);
2073 fi
->csr1212_dirs
[dr
] = NULL
;
2075 hpsb_update_config_rom_image(fi
->host
);
2076 free_pending_request(req
);
2081 cache
= csr1212_rom_cache_malloc(0, req
->req
.length
);
2083 csr1212_release_keyval(fi
->csr1212_dirs
[dr
]);
2084 fi
->csr1212_dirs
[dr
] = NULL
;
2088 cache
->filled_head
= kmalloc(sizeof(*cache
->filled_head
), GFP_KERNEL
);
2089 if (!cache
->filled_head
) {
2090 csr1212_release_keyval(fi
->csr1212_dirs
[dr
]);
2091 fi
->csr1212_dirs
[dr
] = NULL
;
2092 CSR1212_FREE(cache
);
2095 cache
->filled_tail
= cache
->filled_head
;
2097 if (copy_from_user(cache
->data
, int2ptr(req
->req
.sendb
),
2099 csr1212_release_keyval(fi
->csr1212_dirs
[dr
]);
2100 fi
->csr1212_dirs
[dr
] = NULL
;
2103 cache
->len
= req
->req
.length
;
2104 cache
->filled_head
->offset_start
= 0;
2105 cache
->filled_head
->offset_end
= cache
->size
- 1;
2107 cache
->layout_head
= cache
->layout_tail
= fi
->csr1212_dirs
[dr
];
2109 ret
= CSR1212_SUCCESS
;
2110 /* parse all the items */
2111 for (kv
= cache
->layout_head
; ret
== CSR1212_SUCCESS
&& kv
;
2113 ret
= csr1212_parse_keyval(kv
, cache
);
2116 /* attach top level items to the root directory */
2118 fi
->csr1212_dirs
[dr
]->value
.directory
.dentries_head
;
2119 ret
== CSR1212_SUCCESS
&& dentry
; dentry
= dentry
->next
) {
2121 csr1212_attach_keyval_to_directory(fi
->host
->csr
.
2126 if (ret
== CSR1212_SUCCESS
) {
2127 ret
= hpsb_update_config_rom_image(fi
->host
);
2129 if (ret
>= 0 && copy_to_user(int2ptr(req
->req
.recvb
),
2135 kfree(cache
->filled_head
);
2136 CSR1212_FREE(cache
);
2139 /* we have to free the request, because we queue no response,
2140 * and therefore nobody will free it */
2141 free_pending_request(req
);
2145 fi
->csr1212_dirs
[dr
]->value
.directory
.dentries_head
;
2146 dentry
; dentry
= dentry
->next
) {
2147 csr1212_detach_keyval_from_directory(fi
->host
->csr
.rom
->
2151 csr1212_release_keyval(fi
->csr1212_dirs
[dr
]);
2152 fi
->csr1212_dirs
[dr
] = NULL
;
2157 static int state_connected(struct file_info
*fi
, struct pending_request
*req
)
2159 int node
= req
->req
.address
>> 48;
2161 req
->req
.error
= RAW1394_ERROR_NONE
;
2163 switch (req
->req
.type
) {
2165 case RAW1394_REQ_ECHO
:
2166 queue_complete_req(req
);
2169 case RAW1394_REQ_ARM_REGISTER
:
2170 return arm_register(fi
, req
);
2172 case RAW1394_REQ_ARM_UNREGISTER
:
2173 return arm_unregister(fi
, req
);
2175 case RAW1394_REQ_ARM_SET_BUF
:
2176 return arm_set_buf(fi
, req
);
2178 case RAW1394_REQ_ARM_GET_BUF
:
2179 return arm_get_buf(fi
, req
);
2181 case RAW1394_REQ_RESET_NOTIFY
:
2182 return reset_notification(fi
, req
);
2184 case RAW1394_REQ_ISO_SEND
:
2185 case RAW1394_REQ_ISO_LISTEN
:
2186 printk(KERN_DEBUG
"raw1394: old iso ABI has been removed\n");
2187 req
->req
.error
= RAW1394_ERROR_COMPAT
;
2188 req
->req
.misc
= RAW1394_KERNELAPI_VERSION
;
2189 queue_complete_req(req
);
2192 case RAW1394_REQ_FCP_LISTEN
:
2193 handle_fcp_listen(fi
, req
);
2196 case RAW1394_REQ_RESET_BUS
:
2197 if (req
->req
.misc
== RAW1394_LONG_RESET
) {
2198 DBGMSG("busreset called (type: LONG)");
2199 hpsb_reset_bus(fi
->host
, LONG_RESET
);
2200 free_pending_request(req
); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2203 if (req
->req
.misc
== RAW1394_SHORT_RESET
) {
2204 DBGMSG("busreset called (type: SHORT)");
2205 hpsb_reset_bus(fi
->host
, SHORT_RESET
);
2206 free_pending_request(req
); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2209 /* error EINVAL (22) invalid argument */
2211 case RAW1394_REQ_GET_ROM
:
2212 return get_config_rom(fi
, req
);
2214 case RAW1394_REQ_UPDATE_ROM
:
2215 return update_config_rom(fi
, req
);
2217 case RAW1394_REQ_MODIFY_ROM
:
2218 return modify_config_rom(fi
, req
);
2221 if (req
->req
.generation
!= get_hpsb_generation(fi
->host
)) {
2222 req
->req
.error
= RAW1394_ERROR_GENERATION
;
2223 req
->req
.generation
= get_hpsb_generation(fi
->host
);
2224 req
->req
.length
= 0;
2225 queue_complete_req(req
);
2229 switch (req
->req
.type
) {
2230 case RAW1394_REQ_PHYPACKET
:
2231 return write_phypacket(fi
, req
);
2232 case RAW1394_REQ_ASYNC_SEND
:
2233 return handle_async_send(fi
, req
);
2236 if (req
->req
.length
== 0) {
2237 req
->req
.error
= RAW1394_ERROR_INVALID_ARG
;
2238 queue_complete_req(req
);
2242 return handle_async_request(fi
, req
, node
);
2245 static ssize_t
raw1394_write(struct file
*file
, const char __user
* buffer
,
2246 size_t count
, loff_t
* offset_is_ignored
)
2248 struct file_info
*fi
= (struct file_info
*)file
->private_data
;
2249 struct pending_request
*req
;
2250 ssize_t retval
= -EBADFD
;
2252 #ifdef CONFIG_COMPAT
2253 if (count
== sizeof(struct compat_raw1394_req
) &&
2254 sizeof(struct compat_raw1394_req
) !=
2255 sizeof(struct raw1394_request
)) {
2256 buffer
= raw1394_compat_write(buffer
);
2257 if (IS_ERR((__force
void *)buffer
))
2258 return PTR_ERR((__force
void *)buffer
);
2261 if (count
!= sizeof(struct raw1394_request
)) {
2265 req
= alloc_pending_request();
2269 req
->file_info
= fi
;
2271 if (copy_from_user(&req
->req
, buffer
, sizeof(struct raw1394_request
))) {
2272 free_pending_request(req
);
2276 if (!mutex_trylock(&fi
->state_mutex
)) {
2277 free_pending_request(req
);
2281 switch (fi
->state
) {
2283 retval
= state_opened(fi
, req
);
2287 retval
= state_initialized(fi
, req
);
2291 retval
= state_connected(fi
, req
);
2295 mutex_unlock(&fi
->state_mutex
);
2298 free_pending_request(req
);
2307 /* rawiso operations */
2309 /* check if any RAW1394_REQ_RAWISO_ACTIVITY event is already in the
2310 * completion queue (reqlists_lock must be taken) */
2311 static inline int __rawiso_event_in_queue(struct file_info
*fi
)
2313 struct pending_request
*req
;
2315 list_for_each_entry(req
, &fi
->req_complete
, list
)
2316 if (req
->req
.type
== RAW1394_REQ_RAWISO_ACTIVITY
)
2322 /* put a RAWISO_ACTIVITY event in the queue, if one isn't there already */
2323 static void queue_rawiso_event(struct file_info
*fi
)
2325 unsigned long flags
;
2327 spin_lock_irqsave(&fi
->reqlists_lock
, flags
);
2329 /* only one ISO activity event may be in the queue */
2330 if (!__rawiso_event_in_queue(fi
)) {
2331 struct pending_request
*req
=
2332 __alloc_pending_request(GFP_ATOMIC
);
2335 req
->file_info
= fi
;
2336 req
->req
.type
= RAW1394_REQ_RAWISO_ACTIVITY
;
2337 req
->req
.generation
= get_hpsb_generation(fi
->host
);
2338 __queue_complete_req(req
);
2340 /* on allocation failure, signal an overflow */
2341 if (fi
->iso_handle
) {
2342 atomic_inc(&fi
->iso_handle
->overflows
);
2346 spin_unlock_irqrestore(&fi
->reqlists_lock
, flags
);
2349 static void rawiso_activity_cb(struct hpsb_iso
*iso
)
2351 unsigned long flags
;
2352 struct host_info
*hi
;
2353 struct file_info
*fi
;
2355 spin_lock_irqsave(&host_info_lock
, flags
);
2356 hi
= find_host_info(iso
->host
);
2359 list_for_each_entry(fi
, &hi
->file_info_list
, list
) {
2360 if (fi
->iso_handle
== iso
)
2361 queue_rawiso_event(fi
);
2365 spin_unlock_irqrestore(&host_info_lock
, flags
);
2368 /* helper function - gather all the kernel iso status bits for returning to user-space */
2369 static void raw1394_iso_fill_status(struct hpsb_iso
*iso
,
2370 struct raw1394_iso_status
*stat
)
2372 int overflows
= atomic_read(&iso
->overflows
);
2373 int skips
= atomic_read(&iso
->skips
);
2375 stat
->config
.data_buf_size
= iso
->buf_size
;
2376 stat
->config
.buf_packets
= iso
->buf_packets
;
2377 stat
->config
.channel
= iso
->channel
;
2378 stat
->config
.speed
= iso
->speed
;
2379 stat
->config
.irq_interval
= iso
->irq_interval
;
2380 stat
->n_packets
= hpsb_iso_n_ready(iso
);
2381 stat
->overflows
= ((skips
& 0xFFFF) << 16) | ((overflows
& 0xFFFF));
2382 stat
->xmit_cycle
= iso
->xmit_cycle
;
2385 static int raw1394_iso_xmit_init(struct file_info
*fi
, void __user
* uaddr
)
2387 struct raw1394_iso_status stat
;
2392 if (copy_from_user(&stat
, uaddr
, sizeof(stat
)))
2395 fi
->iso_handle
= hpsb_iso_xmit_init(fi
->host
,
2396 stat
.config
.data_buf_size
,
2397 stat
.config
.buf_packets
,
2398 stat
.config
.channel
,
2400 stat
.config
.irq_interval
,
2401 rawiso_activity_cb
);
2402 if (!fi
->iso_handle
)
2405 fi
->iso_state
= RAW1394_ISO_XMIT
;
2407 raw1394_iso_fill_status(fi
->iso_handle
, &stat
);
2408 if (copy_to_user(uaddr
, &stat
, sizeof(stat
)))
2411 /* queue an event to get things started */
2412 rawiso_activity_cb(fi
->iso_handle
);
2417 static int raw1394_iso_recv_init(struct file_info
*fi
, void __user
* uaddr
)
2419 struct raw1394_iso_status stat
;
2424 if (copy_from_user(&stat
, uaddr
, sizeof(stat
)))
2427 fi
->iso_handle
= hpsb_iso_recv_init(fi
->host
,
2428 stat
.config
.data_buf_size
,
2429 stat
.config
.buf_packets
,
2430 stat
.config
.channel
,
2431 stat
.config
.dma_mode
,
2432 stat
.config
.irq_interval
,
2433 rawiso_activity_cb
);
2434 if (!fi
->iso_handle
)
2437 fi
->iso_state
= RAW1394_ISO_RECV
;
2439 raw1394_iso_fill_status(fi
->iso_handle
, &stat
);
2440 if (copy_to_user(uaddr
, &stat
, sizeof(stat
)))
2445 static int raw1394_iso_get_status(struct file_info
*fi
, void __user
* uaddr
)
2447 struct raw1394_iso_status stat
;
2448 struct hpsb_iso
*iso
= fi
->iso_handle
;
2450 raw1394_iso_fill_status(fi
->iso_handle
, &stat
);
2451 if (copy_to_user(uaddr
, &stat
, sizeof(stat
)))
2454 /* reset overflow counter */
2455 atomic_set(&iso
->overflows
, 0);
2456 /* reset skip counter */
2457 atomic_set(&iso
->skips
, 0);
2462 /* copy N packet_infos out of the ringbuffer into user-supplied array */
2463 static int raw1394_iso_recv_packets(struct file_info
*fi
, void __user
* uaddr
)
2465 struct raw1394_iso_packets upackets
;
2466 unsigned int packet
= fi
->iso_handle
->first_packet
;
2469 if (copy_from_user(&upackets
, uaddr
, sizeof(upackets
)))
2472 if (upackets
.n_packets
> hpsb_iso_n_ready(fi
->iso_handle
))
2475 /* ensure user-supplied buffer is accessible and big enough */
2476 if (!access_ok(VERIFY_WRITE
, upackets
.infos
,
2477 upackets
.n_packets
*
2478 sizeof(struct raw1394_iso_packet_info
)))
2481 /* copy the packet_infos out */
2482 for (i
= 0; i
< upackets
.n_packets
; i
++) {
2483 if (__copy_to_user(&upackets
.infos
[i
],
2484 &fi
->iso_handle
->infos
[packet
],
2485 sizeof(struct raw1394_iso_packet_info
)))
2488 packet
= (packet
+ 1) % fi
->iso_handle
->buf_packets
;
2494 /* copy N packet_infos from user to ringbuffer, and queue them for transmission */
2495 static int raw1394_iso_send_packets(struct file_info
*fi
, void __user
* uaddr
)
2497 struct raw1394_iso_packets upackets
;
2500 if (copy_from_user(&upackets
, uaddr
, sizeof(upackets
)))
2503 if (upackets
.n_packets
>= fi
->iso_handle
->buf_packets
)
2506 if (upackets
.n_packets
>= hpsb_iso_n_ready(fi
->iso_handle
))
2509 /* ensure user-supplied buffer is accessible and big enough */
2510 if (!access_ok(VERIFY_READ
, upackets
.infos
,
2511 upackets
.n_packets
*
2512 sizeof(struct raw1394_iso_packet_info
)))
2515 /* copy the infos structs in and queue the packets */
2516 for (i
= 0; i
< upackets
.n_packets
; i
++) {
2517 struct raw1394_iso_packet_info info
;
2519 if (__copy_from_user(&info
, &upackets
.infos
[i
],
2520 sizeof(struct raw1394_iso_packet_info
)))
2523 rv
= hpsb_iso_xmit_queue_packet(fi
->iso_handle
, info
.offset
,
2524 info
.len
, info
.tag
, info
.sy
);
2532 static void raw1394_iso_shutdown(struct file_info
*fi
)
2535 hpsb_iso_shutdown(fi
->iso_handle
);
2537 fi
->iso_handle
= NULL
;
2538 fi
->iso_state
= RAW1394_ISO_INACTIVE
;
2541 static int raw1394_read_cycle_timer(struct file_info
*fi
, void __user
* uaddr
)
2543 struct raw1394_cycle_timer ct
;
2546 err
= hpsb_read_cycle_timer(fi
->host
, &ct
.cycle_timer
, &ct
.local_time
);
2548 if (copy_to_user(uaddr
, &ct
, sizeof(ct
)))
2553 /* mmap the rawiso xmit/recv buffer */
2554 static int raw1394_mmap(struct file
*file
, struct vm_area_struct
*vma
)
2556 struct file_info
*fi
= file
->private_data
;
2559 if (!mutex_trylock(&fi
->state_mutex
))
2562 if (fi
->iso_state
== RAW1394_ISO_INACTIVE
)
2565 ret
= dma_region_mmap(&fi
->iso_handle
->data_buf
, file
, vma
);
2567 mutex_unlock(&fi
->state_mutex
);
2572 static long raw1394_ioctl_inactive(struct file_info
*fi
, unsigned int cmd
,
2576 case RAW1394_IOC_ISO_XMIT_INIT
:
2577 return raw1394_iso_xmit_init(fi
, argp
);
2578 case RAW1394_IOC_ISO_RECV_INIT
:
2579 return raw1394_iso_recv_init(fi
, argp
);
2585 static long raw1394_ioctl_recv(struct file_info
*fi
, unsigned int cmd
,
2588 void __user
*argp
= (void __user
*)arg
;
2591 case RAW1394_IOC_ISO_RECV_START
:{
2594 if (copy_from_user(&args
[0], argp
, sizeof(args
)))
2596 return hpsb_iso_recv_start(fi
->iso_handle
,
2597 args
[0], args
[1], args
[2]);
2599 case RAW1394_IOC_ISO_XMIT_RECV_STOP
:
2600 hpsb_iso_stop(fi
->iso_handle
);
2602 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL
:
2603 return hpsb_iso_recv_listen_channel(fi
->iso_handle
, arg
);
2604 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL
:
2605 return hpsb_iso_recv_unlisten_channel(fi
->iso_handle
, arg
);
2606 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK
:{
2609 if (copy_from_user(&mask
, argp
, sizeof(mask
)))
2611 return hpsb_iso_recv_set_channel_mask(fi
->iso_handle
,
2614 case RAW1394_IOC_ISO_GET_STATUS
:
2615 return raw1394_iso_get_status(fi
, argp
);
2616 case RAW1394_IOC_ISO_RECV_PACKETS
:
2617 return raw1394_iso_recv_packets(fi
, argp
);
2618 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS
:
2619 return hpsb_iso_recv_release_packets(fi
->iso_handle
, arg
);
2620 case RAW1394_IOC_ISO_RECV_FLUSH
:
2621 return hpsb_iso_recv_flush(fi
->iso_handle
);
2622 case RAW1394_IOC_ISO_SHUTDOWN
:
2623 raw1394_iso_shutdown(fi
);
2625 case RAW1394_IOC_ISO_QUEUE_ACTIVITY
:
2626 queue_rawiso_event(fi
);
2633 static long raw1394_ioctl_xmit(struct file_info
*fi
, unsigned int cmd
,
2637 case RAW1394_IOC_ISO_XMIT_START
:{
2640 if (copy_from_user(&args
[0], argp
, sizeof(args
)))
2642 return hpsb_iso_xmit_start(fi
->iso_handle
,
2645 case RAW1394_IOC_ISO_XMIT_SYNC
:
2646 return hpsb_iso_xmit_sync(fi
->iso_handle
);
2647 case RAW1394_IOC_ISO_XMIT_RECV_STOP
:
2648 hpsb_iso_stop(fi
->iso_handle
);
2650 case RAW1394_IOC_ISO_GET_STATUS
:
2651 return raw1394_iso_get_status(fi
, argp
);
2652 case RAW1394_IOC_ISO_XMIT_PACKETS
:
2653 return raw1394_iso_send_packets(fi
, argp
);
2654 case RAW1394_IOC_ISO_SHUTDOWN
:
2655 raw1394_iso_shutdown(fi
);
2657 case RAW1394_IOC_ISO_QUEUE_ACTIVITY
:
2658 queue_rawiso_event(fi
);
2665 /* ioctl is only used for rawiso operations */
2666 static long raw1394_ioctl(struct file
*file
, unsigned int cmd
,
2669 struct file_info
*fi
= file
->private_data
;
2670 void __user
*argp
= (void __user
*)arg
;
2673 /* state-independent commands */
2675 case RAW1394_IOC_GET_CYCLE_TIMER
:
2676 return raw1394_read_cycle_timer(fi
, argp
);
2681 if (!mutex_trylock(&fi
->state_mutex
))
2684 switch (fi
->iso_state
) {
2685 case RAW1394_ISO_INACTIVE
:
2686 ret
= raw1394_ioctl_inactive(fi
, cmd
, argp
);
2688 case RAW1394_ISO_RECV
:
2689 ret
= raw1394_ioctl_recv(fi
, cmd
, arg
);
2691 case RAW1394_ISO_XMIT
:
2692 ret
= raw1394_ioctl_xmit(fi
, cmd
, argp
);
2699 mutex_unlock(&fi
->state_mutex
);
2704 #ifdef CONFIG_COMPAT
2705 struct raw1394_iso_packets32
{
2707 compat_uptr_t infos
;
2708 } __attribute__((packed
));
2710 struct raw1394_cycle_timer32
{
2714 #if defined(CONFIG_X86_64) || defined(CONFIG_IA64)
2715 __attribute__((packed
))
2719 #define RAW1394_IOC_ISO_RECV_PACKETS32 \
2720 _IOW ('#', 0x25, struct raw1394_iso_packets32)
2721 #define RAW1394_IOC_ISO_XMIT_PACKETS32 \
2722 _IOW ('#', 0x27, struct raw1394_iso_packets32)
2723 #define RAW1394_IOC_GET_CYCLE_TIMER32 \
2724 _IOR ('#', 0x30, struct raw1394_cycle_timer32)
2726 static long raw1394_iso_xmit_recv_packets32(struct file
*file
, unsigned int cmd
,
2727 struct raw1394_iso_packets32 __user
*arg
)
2729 compat_uptr_t infos32
;
2732 struct raw1394_iso_packets __user
*dst
= compat_alloc_user_space(sizeof(struct raw1394_iso_packets
));
2734 if (!copy_in_user(&dst
->n_packets
, &arg
->n_packets
, sizeof arg
->n_packets
) &&
2735 !copy_from_user(&infos32
, &arg
->infos
, sizeof infos32
)) {
2736 infos
= compat_ptr(infos32
);
2737 if (!copy_to_user(&dst
->infos
, &infos
, sizeof infos
))
2738 err
= raw1394_ioctl(file
, cmd
, (unsigned long)dst
);
2743 static long raw1394_read_cycle_timer32(struct file_info
*fi
, void __user
* uaddr
)
2745 struct raw1394_cycle_timer32 ct
;
2748 err
= hpsb_read_cycle_timer(fi
->host
, &ct
.cycle_timer
, &ct
.local_time
);
2750 if (copy_to_user(uaddr
, &ct
, sizeof(ct
)))
2755 static long raw1394_compat_ioctl(struct file
*file
,
2756 unsigned int cmd
, unsigned long arg
)
2758 struct file_info
*fi
= file
->private_data
;
2759 void __user
*argp
= (void __user
*)arg
;
2763 /* These requests have same format as long as 'int' has same size. */
2764 case RAW1394_IOC_ISO_RECV_INIT
:
2765 case RAW1394_IOC_ISO_RECV_START
:
2766 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL
:
2767 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL
:
2768 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK
:
2769 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS
:
2770 case RAW1394_IOC_ISO_RECV_FLUSH
:
2771 case RAW1394_IOC_ISO_XMIT_RECV_STOP
:
2772 case RAW1394_IOC_ISO_XMIT_INIT
:
2773 case RAW1394_IOC_ISO_XMIT_START
:
2774 case RAW1394_IOC_ISO_XMIT_SYNC
:
2775 case RAW1394_IOC_ISO_GET_STATUS
:
2776 case RAW1394_IOC_ISO_SHUTDOWN
:
2777 case RAW1394_IOC_ISO_QUEUE_ACTIVITY
:
2778 err
= raw1394_ioctl(file
, cmd
, arg
);
2780 /* These request have different format. */
2781 case RAW1394_IOC_ISO_RECV_PACKETS32
:
2782 err
= raw1394_iso_xmit_recv_packets32(file
, RAW1394_IOC_ISO_RECV_PACKETS
, argp
);
2784 case RAW1394_IOC_ISO_XMIT_PACKETS32
:
2785 err
= raw1394_iso_xmit_recv_packets32(file
, RAW1394_IOC_ISO_XMIT_PACKETS
, argp
);
2787 case RAW1394_IOC_GET_CYCLE_TIMER32
:
2788 err
= raw1394_read_cycle_timer32(fi
, argp
);
2799 static unsigned int raw1394_poll(struct file
*file
, poll_table
* pt
)
2801 struct file_info
*fi
= file
->private_data
;
2802 unsigned int mask
= POLLOUT
| POLLWRNORM
;
2803 unsigned long flags
;
2805 poll_wait(file
, &fi
->wait_complete
, pt
);
2807 spin_lock_irqsave(&fi
->reqlists_lock
, flags
);
2808 if (!list_empty(&fi
->req_complete
)) {
2809 mask
|= POLLIN
| POLLRDNORM
;
2811 spin_unlock_irqrestore(&fi
->reqlists_lock
, flags
);
2816 static int raw1394_open(struct inode
*inode
, struct file
*file
)
2818 struct file_info
*fi
;
2820 fi
= kzalloc(sizeof(*fi
), GFP_KERNEL
);
2824 fi
->notification
= (u8
) RAW1394_NOTIFY_ON
; /* busreset notification */
2826 INIT_LIST_HEAD(&fi
->list
);
2827 mutex_init(&fi
->state_mutex
);
2829 INIT_LIST_HEAD(&fi
->req_pending
);
2830 INIT_LIST_HEAD(&fi
->req_complete
);
2831 spin_lock_init(&fi
->reqlists_lock
);
2832 init_waitqueue_head(&fi
->wait_complete
);
2833 INIT_LIST_HEAD(&fi
->addr_list
);
2835 file
->private_data
= fi
;
2837 return nonseekable_open(inode
, file
);
2840 static int raw1394_release(struct inode
*inode
, struct file
*file
)
2842 struct file_info
*fi
= file
->private_data
;
2843 struct list_head
*lh
;
2844 struct pending_request
*req
;
2847 struct list_head
*entry
;
2848 struct arm_addr
*addr
= NULL
;
2849 struct host_info
*hi
;
2850 struct file_info
*fi_hlp
= NULL
;
2851 struct arm_addr
*arm_addr
= NULL
;
2854 unsigned long flags
;
2856 if (fi
->iso_state
!= RAW1394_ISO_INACTIVE
)
2857 raw1394_iso_shutdown(fi
);
2859 spin_lock_irqsave(&host_info_lock
, flags
);
2862 /* set address-entries invalid */
2864 while (!list_empty(&fi
->addr_list
)) {
2866 lh
= fi
->addr_list
.next
;
2867 addr
= list_entry(lh
, struct arm_addr
, addr_list
);
2868 /* another host with valid address-entry containing
2869 same addressrange? */
2870 list_for_each_entry(hi
, &host_info_list
, list
) {
2871 if (hi
->host
!= fi
->host
) {
2872 list_for_each_entry(fi_hlp
, &hi
->file_info_list
,
2874 entry
= fi_hlp
->addr_list
.next
;
2875 while (entry
!= &(fi_hlp
->addr_list
)) {
2876 arm_addr
= list_entry(entry
, struct
2879 if (arm_addr
->start
==
2882 ("raw1394_release: "
2883 "another host ownes "
2884 "same addressrange");
2888 entry
= entry
->next
;
2896 if (!another_host
) {
2897 DBGMSG("raw1394_release: call hpsb_arm_unregister");
2899 hpsb_unregister_addrspace(&raw1394_highlevel
,
2900 fi
->host
, addr
->start
);
2904 "raw1394_release arm_Unregister failed\n");
2907 DBGMSG("raw1394_release: delete addr_entry from list");
2908 list_del(&addr
->addr_list
);
2909 vfree(addr
->addr_space_buffer
);
2912 spin_unlock_irqrestore(&host_info_lock
, flags
);
2914 printk(KERN_ERR
"raw1394: during addr_list-release "
2915 "error(s) occurred \n");
2919 /* This locked section guarantees that neither
2920 * complete nor pending requests exist once i!=0 */
2921 spin_lock_irqsave(&fi
->reqlists_lock
, flags
);
2922 while ((req
= __next_complete_req(fi
)))
2923 free_pending_request(req
);
2925 i
= list_empty(&fi
->req_pending
);
2926 spin_unlock_irqrestore(&fi
->reqlists_lock
, flags
);
2931 * Sleep until more requests can be freed.
2933 * NB: We call the macro wait_event() with a condition argument
2934 * with side effect. This is only possible because the side
2935 * effect does not occur until the condition became true, and
2936 * wait_event() won't evaluate the condition again after that.
2938 wait_event(fi
->wait_complete
, (req
= next_complete_req(fi
)));
2939 free_pending_request(req
);
2942 /* Remove any sub-trees left by user space programs */
2943 for (i
= 0; i
< RAW1394_MAX_USER_CSR_DIRS
; i
++) {
2944 struct csr1212_dentry
*dentry
;
2945 if (!fi
->csr1212_dirs
[i
])
2948 fi
->csr1212_dirs
[i
]->value
.directory
.dentries_head
; dentry
;
2949 dentry
= dentry
->next
) {
2950 csr1212_detach_keyval_from_directory(fi
->host
->csr
.rom
->
2954 csr1212_release_keyval(fi
->csr1212_dirs
[i
]);
2955 fi
->csr1212_dirs
[i
] = NULL
;
2959 if ((csr_mod
|| fi
->cfgrom_upd
)
2960 && hpsb_update_config_rom_image(fi
->host
) < 0)
2962 ("Failed to generate Configuration ROM image for host %d",
2965 if (fi
->state
== connected
) {
2966 spin_lock_irqsave(&host_info_lock
, flags
);
2967 list_del(&fi
->list
);
2968 spin_unlock_irqrestore(&host_info_lock
, flags
);
2970 put_device(&fi
->host
->device
);
2973 spin_lock_irqsave(&host_info_lock
, flags
);
2975 module_put(fi
->host
->driver
->owner
);
2976 spin_unlock_irqrestore(&host_info_lock
, flags
);
2983 /*** HOTPLUG STUFF **********************************************************/
2985 * Export information about protocols/devices supported by this driver.
2988 static const struct ieee1394_device_id raw1394_id_table
[] = {
2990 .match_flags
= IEEE1394_MATCH_SPECIFIER_ID
| IEEE1394_MATCH_VERSION
,
2991 .specifier_id
= AVC_UNIT_SPEC_ID_ENTRY
& 0xffffff,
2992 .version
= AVC_SW_VERSION_ENTRY
& 0xffffff},
2994 .match_flags
= IEEE1394_MATCH_SPECIFIER_ID
| IEEE1394_MATCH_VERSION
,
2995 .specifier_id
= CAMERA_UNIT_SPEC_ID_ENTRY
& 0xffffff,
2996 .version
= CAMERA_SW_VERSION_ENTRY
& 0xffffff},
2998 .match_flags
= IEEE1394_MATCH_SPECIFIER_ID
| IEEE1394_MATCH_VERSION
,
2999 .specifier_id
= CAMERA_UNIT_SPEC_ID_ENTRY
& 0xffffff,
3000 .version
= (CAMERA_SW_VERSION_ENTRY
+ 1) & 0xffffff},
3002 .match_flags
= IEEE1394_MATCH_SPECIFIER_ID
| IEEE1394_MATCH_VERSION
,
3003 .specifier_id
= CAMERA_UNIT_SPEC_ID_ENTRY
& 0xffffff,
3004 .version
= (CAMERA_SW_VERSION_ENTRY
+ 2) & 0xffffff},
3008 MODULE_DEVICE_TABLE(ieee1394
, raw1394_id_table
);
3011 static struct hpsb_protocol_driver raw1394_driver
= {
3015 /******************************************************************************/
3017 static struct hpsb_highlevel raw1394_highlevel
= {
3018 .name
= RAW1394_DEVICE_NAME
,
3019 .add_host
= add_host
,
3020 .remove_host
= remove_host
,
3021 .host_reset
= host_reset
,
3022 .fcp_request
= fcp_request
,
3025 static struct cdev raw1394_cdev
;
3026 static const struct file_operations raw1394_fops
= {
3027 .owner
= THIS_MODULE
,
3028 .read
= raw1394_read
,
3029 .write
= raw1394_write
,
3030 .mmap
= raw1394_mmap
,
3031 .unlocked_ioctl
= raw1394_ioctl
,
3032 #ifdef CONFIG_COMPAT
3033 .compat_ioctl
= raw1394_compat_ioctl
,
3035 .poll
= raw1394_poll
,
3036 .open
= raw1394_open
,
3037 .release
= raw1394_release
,
3038 .llseek
= no_llseek
,
3041 static int __init
init_raw1394(void)
3045 hpsb_register_highlevel(&raw1394_highlevel
);
3048 (device_create(hpsb_protocol_class
, NULL
,
3049 MKDEV(IEEE1394_MAJOR
,
3050 IEEE1394_MINOR_BLOCK_RAW1394
* 16),
3051 NULL
, RAW1394_DEVICE_NAME
))) {
3056 cdev_init(&raw1394_cdev
, &raw1394_fops
);
3057 raw1394_cdev
.owner
= THIS_MODULE
;
3058 ret
= cdev_add(&raw1394_cdev
, IEEE1394_RAW1394_DEV
, 1);
3060 HPSB_ERR("raw1394 failed to register minor device block");
3064 HPSB_INFO("raw1394: /dev/%s device initialized", RAW1394_DEVICE_NAME
);
3066 ret
= hpsb_register_protocol(&raw1394_driver
);
3068 HPSB_ERR("raw1394: failed to register protocol");
3069 cdev_del(&raw1394_cdev
);
3076 device_destroy(hpsb_protocol_class
,
3077 MKDEV(IEEE1394_MAJOR
,
3078 IEEE1394_MINOR_BLOCK_RAW1394
* 16));
3080 hpsb_unregister_highlevel(&raw1394_highlevel
);
3085 static void __exit
cleanup_raw1394(void)
3087 device_destroy(hpsb_protocol_class
,
3088 MKDEV(IEEE1394_MAJOR
,
3089 IEEE1394_MINOR_BLOCK_RAW1394
* 16));
3090 cdev_del(&raw1394_cdev
);
3091 hpsb_unregister_highlevel(&raw1394_highlevel
);
3092 hpsb_unregister_protocol(&raw1394_driver
);
3095 module_init(init_raw1394
);
3096 module_exit(cleanup_raw1394
);
3097 MODULE_LICENSE("GPL");