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
= 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;
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 rcode
= RCODE_DATA_ERROR
; /* hardware error, data is unavailable */
1060 if (arm_addr
->access_rights
& ARM_WRITE
) {
1061 if (!(arm_addr
->client_transactions
& ARM_WRITE
)) {
1062 memcpy((arm_addr
->addr_space_buffer
) +
1063 (addr
- (arm_addr
->start
)), data
,
1065 DBGMSG("arm_write -> (rcode_complete)");
1066 rcode
= RCODE_COMPLETE
;
1069 rcode
= RCODE_TYPE_ERROR
; /* function not allowed */
1070 DBGMSG("arm_write -> rcode_type_error (access denied)");
1073 if (arm_addr
->notification_options
& ARM_WRITE
) {
1074 DBGMSG("arm_write -> entering notification-section");
1075 req
= __alloc_pending_request(GFP_ATOMIC
);
1077 DBGMSG("arm_write -> rcode_conflict_error");
1078 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1079 return (RCODE_CONFLICT_ERROR
); /* A resource conflict was detected.
1080 The request my be retried */
1083 sizeof(struct arm_request
) + sizeof(struct arm_response
) +
1084 (length
) * sizeof(byte_t
) +
1085 sizeof(struct arm_request_response
);
1086 req
->data
= kmalloc(size
, GFP_ATOMIC
);
1088 free_pending_request(req
);
1089 DBGMSG("arm_write -> rcode_conflict_error");
1090 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1091 return (RCODE_CONFLICT_ERROR
); /* A resource conflict was detected.
1092 The request may be retried */
1095 req
->file_info
= fi
;
1096 req
->req
.type
= RAW1394_REQ_ARM
;
1097 req
->req
.generation
= get_hpsb_generation(host
);
1099 (((length
<< 16) & (0xFFFF0000)) | (ARM_WRITE
& 0xFF));
1100 req
->req
.tag
= arm_addr
->arm_tag
;
1101 req
->req
.recvb
= arm_addr
->recvb
;
1102 req
->req
.length
= size
;
1103 arm_req_resp
= (struct arm_request_response
*)(req
->data
);
1104 arm_req
= (struct arm_request
*)((byte_t
*) (req
->data
) +
1107 arm_request_response
)));
1109 (struct arm_response
*)((byte_t
*) (arm_req
) +
1110 (sizeof(struct arm_request
)));
1111 arm_resp
->buffer
= NULL
;
1112 memcpy((byte_t
*) arm_resp
+ sizeof(struct arm_response
),
1114 arm_req
->buffer
= int2ptr((arm_addr
->recvb
) +
1115 sizeof(struct arm_request_response
) +
1116 sizeof(struct arm_request
) +
1117 sizeof(struct arm_response
));
1118 arm_req
->buffer_length
= length
;
1119 arm_req
->generation
= req
->req
.generation
;
1120 arm_req
->extended_transaction_code
= 0;
1121 arm_req
->destination_offset
= addr
;
1122 arm_req
->source_nodeid
= nodeid
;
1123 arm_req
->destination_nodeid
= destid
;
1124 arm_req
->tlabel
= (flags
>> 10) & 0x3f;
1125 arm_req
->tcode
= (flags
>> 4) & 0x0f;
1126 arm_resp
->buffer_length
= 0;
1127 arm_resp
->response_code
= rcode
;
1128 arm_req_resp
->request
= int2ptr((arm_addr
->recvb
) +
1130 arm_request_response
));
1131 arm_req_resp
->response
=
1132 int2ptr((arm_addr
->recvb
) +
1133 sizeof(struct arm_request_response
) +
1134 sizeof(struct arm_request
));
1135 queue_complete_req(req
);
1137 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1141 static int arm_lock(struct hpsb_host
*host
, int nodeid
, quadlet_t
* store
,
1142 u64 addr
, quadlet_t data
, quadlet_t arg
, int ext_tcode
,
1145 unsigned long irqflags
;
1146 struct pending_request
*req
;
1147 struct host_info
*hi
;
1148 struct file_info
*fi
= NULL
;
1149 struct list_head
*entry
;
1150 struct arm_addr
*arm_addr
= NULL
;
1151 struct arm_request
*arm_req
= NULL
;
1152 struct arm_response
*arm_resp
= NULL
;
1153 int found
= 0, size
= 0, rcode
= -1;
1155 struct arm_request_response
*arm_req_resp
= NULL
;
1157 if (((ext_tcode
& 0xFF) == EXTCODE_FETCH_ADD
) ||
1158 ((ext_tcode
& 0xFF) == EXTCODE_LITTLE_ADD
)) {
1159 DBGMSG("arm_lock called by node: %X "
1160 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X",
1161 nodeid
, (u16
) ((addr
>> 32) & 0xFFFF),
1162 (u32
) (addr
& 0xFFFFFFFF), ext_tcode
& 0xFF,
1165 DBGMSG("arm_lock called by node: %X "
1166 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X arg: %8.8X",
1167 nodeid
, (u16
) ((addr
>> 32) & 0xFFFF),
1168 (u32
) (addr
& 0xFFFFFFFF), ext_tcode
& 0xFF,
1169 be32_to_cpu(data
), be32_to_cpu(arg
));
1171 spin_lock_irqsave(&host_info_lock
, irqflags
);
1172 hi
= find_host_info(host
); /* search address-entry */
1174 list_for_each_entry(fi
, &hi
->file_info_list
, list
) {
1175 entry
= fi
->addr_list
.next
;
1176 while (entry
!= &(fi
->addr_list
)) {
1178 list_entry(entry
, struct arm_addr
,
1180 if (((arm_addr
->start
) <= (addr
))
1181 && ((arm_addr
->end
) >=
1182 (addr
+ sizeof(*store
)))) {
1186 entry
= entry
->next
;
1195 printk(KERN_ERR
"raw1394: arm_lock FAILED addr_entry not found"
1196 " -> rcode_address_error\n");
1197 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1198 return (RCODE_ADDRESS_ERROR
);
1200 DBGMSG("arm_lock addr_entry FOUND");
1203 if (arm_addr
->access_rights
& ARM_LOCK
) {
1204 if (!(arm_addr
->client_transactions
& ARM_LOCK
)) {
1206 (arm_addr
->addr_space_buffer
) + (addr
-
1210 switch (ext_tcode
) {
1211 case (EXTCODE_MASK_SWAP
):
1212 new = data
| (old
& ~arg
);
1214 case (EXTCODE_COMPARE_SWAP
):
1221 case (EXTCODE_FETCH_ADD
):
1223 cpu_to_be32(be32_to_cpu(data
) +
1226 case (EXTCODE_LITTLE_ADD
):
1228 cpu_to_le32(le32_to_cpu(data
) +
1231 case (EXTCODE_BOUNDED_ADD
):
1234 cpu_to_be32(be32_to_cpu
1242 case (EXTCODE_WRAP_ADD
):
1245 cpu_to_be32(be32_to_cpu
1254 rcode
= RCODE_TYPE_ERROR
; /* function not allowed */
1256 "raw1394: arm_lock FAILED "
1257 "ext_tcode not allowed -> rcode_type_error\n");
1261 DBGMSG("arm_lock -> (rcode_complete)");
1262 rcode
= RCODE_COMPLETE
;
1263 memcpy(store
, &old
, sizeof(*store
));
1264 memcpy((arm_addr
->addr_space_buffer
) +
1265 (addr
- (arm_addr
->start
)),
1266 &new, sizeof(*store
));
1270 rcode
= RCODE_TYPE_ERROR
; /* function not allowed */
1271 DBGMSG("arm_lock -> rcode_type_error (access denied)");
1274 if (arm_addr
->notification_options
& ARM_LOCK
) {
1275 byte_t
*buf1
, *buf2
;
1276 DBGMSG("arm_lock -> entering notification-section");
1277 req
= __alloc_pending_request(GFP_ATOMIC
);
1279 DBGMSG("arm_lock -> rcode_conflict_error");
1280 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1281 return (RCODE_CONFLICT_ERROR
); /* A resource conflict was detected.
1282 The request may be retried */
1284 size
= sizeof(struct arm_request
) + sizeof(struct arm_response
) + 3 * sizeof(*store
) + sizeof(struct arm_request_response
); /* maximum */
1285 req
->data
= kmalloc(size
, GFP_ATOMIC
);
1287 free_pending_request(req
);
1288 DBGMSG("arm_lock -> rcode_conflict_error");
1289 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1290 return (RCODE_CONFLICT_ERROR
); /* A resource conflict was detected.
1291 The request may be retried */
1294 arm_req_resp
= (struct arm_request_response
*)(req
->data
);
1295 arm_req
= (struct arm_request
*)((byte_t
*) (req
->data
) +
1298 arm_request_response
)));
1300 (struct arm_response
*)((byte_t
*) (arm_req
) +
1301 (sizeof(struct arm_request
)));
1302 buf1
= (byte_t
*) arm_resp
+ sizeof(struct arm_response
);
1303 buf2
= buf1
+ 2 * sizeof(*store
);
1304 if ((ext_tcode
== EXTCODE_FETCH_ADD
) ||
1305 (ext_tcode
== EXTCODE_LITTLE_ADD
)) {
1306 arm_req
->buffer_length
= sizeof(*store
);
1307 memcpy(buf1
, &data
, sizeof(*store
));
1310 arm_req
->buffer_length
= 2 * sizeof(*store
);
1311 memcpy(buf1
, &arg
, sizeof(*store
));
1312 memcpy(buf1
+ sizeof(*store
), &data
, sizeof(*store
));
1314 if (rcode
== RCODE_COMPLETE
) {
1315 arm_resp
->buffer_length
= sizeof(*store
);
1316 memcpy(buf2
, &old
, sizeof(*store
));
1318 arm_resp
->buffer_length
= 0;
1320 req
->file_info
= fi
;
1321 req
->req
.type
= RAW1394_REQ_ARM
;
1322 req
->req
.generation
= get_hpsb_generation(host
);
1323 req
->req
.misc
= ((((sizeof(*store
)) << 16) & (0xFFFF0000)) |
1325 req
->req
.tag
= arm_addr
->arm_tag
;
1326 req
->req
.recvb
= arm_addr
->recvb
;
1327 req
->req
.length
= size
;
1328 arm_req
->generation
= req
->req
.generation
;
1329 arm_req
->extended_transaction_code
= ext_tcode
;
1330 arm_req
->destination_offset
= addr
;
1331 arm_req
->source_nodeid
= nodeid
;
1332 arm_req
->destination_nodeid
= host
->node_id
;
1333 arm_req
->tlabel
= (flags
>> 10) & 0x3f;
1334 arm_req
->tcode
= (flags
>> 4) & 0x0f;
1335 arm_resp
->response_code
= rcode
;
1336 arm_req_resp
->request
= int2ptr((arm_addr
->recvb
) +
1338 arm_request_response
));
1339 arm_req_resp
->response
=
1340 int2ptr((arm_addr
->recvb
) +
1341 sizeof(struct arm_request_response
) +
1342 sizeof(struct arm_request
));
1344 int2ptr((arm_addr
->recvb
) +
1345 sizeof(struct arm_request_response
) +
1346 sizeof(struct arm_request
) +
1347 sizeof(struct arm_response
));
1349 int2ptr((arm_addr
->recvb
) +
1350 sizeof(struct arm_request_response
) +
1351 sizeof(struct arm_request
) +
1352 sizeof(struct arm_response
) + 2 * sizeof(*store
));
1353 queue_complete_req(req
);
1355 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1359 static int arm_lock64(struct hpsb_host
*host
, int nodeid
, octlet_t
* store
,
1360 u64 addr
, octlet_t data
, octlet_t arg
, int ext_tcode
,
1363 unsigned long irqflags
;
1364 struct pending_request
*req
;
1365 struct host_info
*hi
;
1366 struct file_info
*fi
= NULL
;
1367 struct list_head
*entry
;
1368 struct arm_addr
*arm_addr
= NULL
;
1369 struct arm_request
*arm_req
= NULL
;
1370 struct arm_response
*arm_resp
= NULL
;
1371 int found
= 0, size
= 0, rcode
= -1;
1373 struct arm_request_response
*arm_req_resp
= NULL
;
1375 if (((ext_tcode
& 0xFF) == EXTCODE_FETCH_ADD
) ||
1376 ((ext_tcode
& 0xFF) == EXTCODE_LITTLE_ADD
)) {
1377 DBGMSG("arm_lock64 called by node: %X "
1378 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X ",
1379 nodeid
, (u16
) ((addr
>> 32) & 0xFFFF),
1380 (u32
) (addr
& 0xFFFFFFFF),
1382 (u32
) ((be64_to_cpu(data
) >> 32) & 0xFFFFFFFF),
1383 (u32
) (be64_to_cpu(data
) & 0xFFFFFFFF));
1385 DBGMSG("arm_lock64 called by node: %X "
1386 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X arg: "
1388 nodeid
, (u16
) ((addr
>> 32) & 0xFFFF),
1389 (u32
) (addr
& 0xFFFFFFFF),
1391 (u32
) ((be64_to_cpu(data
) >> 32) & 0xFFFFFFFF),
1392 (u32
) (be64_to_cpu(data
) & 0xFFFFFFFF),
1393 (u32
) ((be64_to_cpu(arg
) >> 32) & 0xFFFFFFFF),
1394 (u32
) (be64_to_cpu(arg
) & 0xFFFFFFFF));
1396 spin_lock_irqsave(&host_info_lock
, irqflags
);
1397 hi
= find_host_info(host
); /* search addressentry in file_info's for host */
1399 list_for_each_entry(fi
, &hi
->file_info_list
, list
) {
1400 entry
= fi
->addr_list
.next
;
1401 while (entry
!= &(fi
->addr_list
)) {
1403 list_entry(entry
, struct arm_addr
,
1405 if (((arm_addr
->start
) <= (addr
))
1406 && ((arm_addr
->end
) >=
1407 (addr
+ sizeof(*store
)))) {
1411 entry
= entry
->next
;
1421 "raw1394: arm_lock64 FAILED addr_entry not found"
1422 " -> rcode_address_error\n");
1423 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1424 return (RCODE_ADDRESS_ERROR
);
1426 DBGMSG("arm_lock64 addr_entry FOUND");
1429 if (arm_addr
->access_rights
& ARM_LOCK
) {
1430 if (!(arm_addr
->client_transactions
& ARM_LOCK
)) {
1432 (arm_addr
->addr_space_buffer
) + (addr
-
1436 switch (ext_tcode
) {
1437 case (EXTCODE_MASK_SWAP
):
1438 new = data
| (old
& ~arg
);
1440 case (EXTCODE_COMPARE_SWAP
):
1447 case (EXTCODE_FETCH_ADD
):
1449 cpu_to_be64(be64_to_cpu(data
) +
1452 case (EXTCODE_LITTLE_ADD
):
1454 cpu_to_le64(le64_to_cpu(data
) +
1457 case (EXTCODE_BOUNDED_ADD
):
1460 cpu_to_be64(be64_to_cpu
1468 case (EXTCODE_WRAP_ADD
):
1471 cpu_to_be64(be64_to_cpu
1481 "raw1394: arm_lock64 FAILED "
1482 "ext_tcode not allowed -> rcode_type_error\n");
1483 rcode
= RCODE_TYPE_ERROR
; /* function not allowed */
1488 ("arm_lock64 -> (rcode_complete)");
1489 rcode
= RCODE_COMPLETE
;
1490 memcpy(store
, &old
, sizeof(*store
));
1491 memcpy((arm_addr
->addr_space_buffer
) +
1492 (addr
- (arm_addr
->start
)),
1493 &new, sizeof(*store
));
1497 rcode
= RCODE_TYPE_ERROR
; /* function not allowed */
1499 ("arm_lock64 -> rcode_type_error (access denied)");
1502 if (arm_addr
->notification_options
& ARM_LOCK
) {
1503 byte_t
*buf1
, *buf2
;
1504 DBGMSG("arm_lock64 -> entering notification-section");
1505 req
= __alloc_pending_request(GFP_ATOMIC
);
1507 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1508 DBGMSG("arm_lock64 -> rcode_conflict_error");
1509 return (RCODE_CONFLICT_ERROR
); /* A resource conflict was detected.
1510 The request may be retried */
1512 size
= sizeof(struct arm_request
) + sizeof(struct arm_response
) + 3 * sizeof(*store
) + sizeof(struct arm_request_response
); /* maximum */
1513 req
->data
= kmalloc(size
, GFP_ATOMIC
);
1515 free_pending_request(req
);
1516 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1517 DBGMSG("arm_lock64 -> rcode_conflict_error");
1518 return (RCODE_CONFLICT_ERROR
); /* A resource conflict was detected.
1519 The request may be retried */
1522 arm_req_resp
= (struct arm_request_response
*)(req
->data
);
1523 arm_req
= (struct arm_request
*)((byte_t
*) (req
->data
) +
1526 arm_request_response
)));
1528 (struct arm_response
*)((byte_t
*) (arm_req
) +
1529 (sizeof(struct arm_request
)));
1530 buf1
= (byte_t
*) arm_resp
+ sizeof(struct arm_response
);
1531 buf2
= buf1
+ 2 * sizeof(*store
);
1532 if ((ext_tcode
== EXTCODE_FETCH_ADD
) ||
1533 (ext_tcode
== EXTCODE_LITTLE_ADD
)) {
1534 arm_req
->buffer_length
= sizeof(*store
);
1535 memcpy(buf1
, &data
, sizeof(*store
));
1538 arm_req
->buffer_length
= 2 * sizeof(*store
);
1539 memcpy(buf1
, &arg
, sizeof(*store
));
1540 memcpy(buf1
+ sizeof(*store
), &data
, sizeof(*store
));
1542 if (rcode
== RCODE_COMPLETE
) {
1543 arm_resp
->buffer_length
= sizeof(*store
);
1544 memcpy(buf2
, &old
, sizeof(*store
));
1546 arm_resp
->buffer_length
= 0;
1548 req
->file_info
= fi
;
1549 req
->req
.type
= RAW1394_REQ_ARM
;
1550 req
->req
.generation
= get_hpsb_generation(host
);
1551 req
->req
.misc
= ((((sizeof(*store
)) << 16) & (0xFFFF0000)) |
1553 req
->req
.tag
= arm_addr
->arm_tag
;
1554 req
->req
.recvb
= arm_addr
->recvb
;
1555 req
->req
.length
= size
;
1556 arm_req
->generation
= req
->req
.generation
;
1557 arm_req
->extended_transaction_code
= ext_tcode
;
1558 arm_req
->destination_offset
= addr
;
1559 arm_req
->source_nodeid
= nodeid
;
1560 arm_req
->destination_nodeid
= host
->node_id
;
1561 arm_req
->tlabel
= (flags
>> 10) & 0x3f;
1562 arm_req
->tcode
= (flags
>> 4) & 0x0f;
1563 arm_resp
->response_code
= rcode
;
1564 arm_req_resp
->request
= int2ptr((arm_addr
->recvb
) +
1566 arm_request_response
));
1567 arm_req_resp
->response
=
1568 int2ptr((arm_addr
->recvb
) +
1569 sizeof(struct arm_request_response
) +
1570 sizeof(struct arm_request
));
1572 int2ptr((arm_addr
->recvb
) +
1573 sizeof(struct arm_request_response
) +
1574 sizeof(struct arm_request
) +
1575 sizeof(struct arm_response
));
1577 int2ptr((arm_addr
->recvb
) +
1578 sizeof(struct arm_request_response
) +
1579 sizeof(struct arm_request
) +
1580 sizeof(struct arm_response
) + 2 * sizeof(*store
));
1581 queue_complete_req(req
);
1583 spin_unlock_irqrestore(&host_info_lock
, irqflags
);
1587 static int arm_register(struct file_info
*fi
, struct pending_request
*req
)
1590 struct arm_addr
*addr
;
1591 struct host_info
*hi
;
1592 struct file_info
*fi_hlp
= NULL
;
1593 struct list_head
*entry
;
1594 struct arm_addr
*arm_addr
= NULL
;
1595 int same_host
, another_host
;
1596 unsigned long flags
;
1598 DBGMSG("arm_register called "
1599 "addr(Offset): %8.8x %8.8x length: %u "
1600 "rights: %2.2X notify: %2.2X "
1601 "max_blk_len: %4.4X",
1602 (u32
) ((req
->req
.address
>> 32) & 0xFFFF),
1603 (u32
) (req
->req
.address
& 0xFFFFFFFF),
1604 req
->req
.length
, ((req
->req
.misc
>> 8) & 0xFF),
1605 (req
->req
.misc
& 0xFF), ((req
->req
.misc
>> 16) & 0xFFFF));
1606 /* check addressrange */
1607 if ((((req
->req
.address
) & ~(0xFFFFFFFFFFFFULL
)) != 0) ||
1608 (((req
->req
.address
+ req
->req
.length
) & ~(0xFFFFFFFFFFFFULL
)) !=
1610 req
->req
.length
= 0;
1613 /* addr-list-entry for fileinfo */
1614 addr
= kmalloc(sizeof(*addr
), GFP_KERNEL
);
1616 req
->req
.length
= 0;
1619 /* allocation of addr_space_buffer */
1620 addr
->addr_space_buffer
= vmalloc(req
->req
.length
);
1621 if (!(addr
->addr_space_buffer
)) {
1623 req
->req
.length
= 0;
1626 /* initialization of addr_space_buffer */
1627 if ((req
->req
.sendb
) == (unsigned long)NULL
) {
1629 memset(addr
->addr_space_buffer
, 0, req
->req
.length
);
1631 /* init: user -> kernel */
1633 (addr
->addr_space_buffer
, int2ptr(req
->req
.sendb
),
1635 vfree(addr
->addr_space_buffer
);
1640 INIT_LIST_HEAD(&addr
->addr_list
);
1641 addr
->arm_tag
= req
->req
.tag
;
1642 addr
->start
= req
->req
.address
;
1643 addr
->end
= req
->req
.address
+ req
->req
.length
;
1644 addr
->access_rights
= (u8
) (req
->req
.misc
& 0x0F);
1645 addr
->notification_options
= (u8
) ((req
->req
.misc
>> 4) & 0x0F);
1646 addr
->client_transactions
= (u8
) ((req
->req
.misc
>> 8) & 0x0F);
1647 addr
->access_rights
|= addr
->client_transactions
;
1648 addr
->notification_options
|= addr
->client_transactions
;
1649 addr
->recvb
= req
->req
.recvb
;
1650 addr
->rec_length
= (u16
) ((req
->req
.misc
>> 16) & 0xFFFF);
1652 spin_lock_irqsave(&host_info_lock
, flags
);
1653 hi
= find_host_info(fi
->host
);
1656 /* same host with address-entry containing same addressrange ? */
1657 list_for_each_entry(fi_hlp
, &hi
->file_info_list
, list
) {
1658 entry
= fi_hlp
->addr_list
.next
;
1659 while (entry
!= &(fi_hlp
->addr_list
)) {
1661 list_entry(entry
, struct arm_addr
, addr_list
);
1662 if ((arm_addr
->start
== addr
->start
)
1663 && (arm_addr
->end
== addr
->end
)) {
1664 DBGMSG("same host ownes same "
1665 "addressrange -> EALREADY");
1669 entry
= entry
->next
;
1676 /* addressrange occupied by same host */
1677 spin_unlock_irqrestore(&host_info_lock
, flags
);
1678 vfree(addr
->addr_space_buffer
);
1682 /* another host with valid address-entry containing same addressrange */
1683 list_for_each_entry(hi
, &host_info_list
, list
) {
1684 if (hi
->host
!= fi
->host
) {
1685 list_for_each_entry(fi_hlp
, &hi
->file_info_list
, list
) {
1686 entry
= fi_hlp
->addr_list
.next
;
1687 while (entry
!= &(fi_hlp
->addr_list
)) {
1689 list_entry(entry
, struct arm_addr
,
1691 if ((arm_addr
->start
== addr
->start
)
1692 && (arm_addr
->end
== addr
->end
)) {
1694 ("another host ownes same "
1699 entry
= entry
->next
;
1707 spin_unlock_irqrestore(&host_info_lock
, flags
);
1710 DBGMSG("another hosts entry is valid -> SUCCESS");
1711 if (copy_to_user(int2ptr(req
->req
.recvb
),
1712 &addr
->start
, sizeof(u64
))) {
1713 printk(KERN_ERR
"raw1394: arm_register failed "
1714 " address-range-entry is invalid -> EFAULT !!!\n");
1715 vfree(addr
->addr_space_buffer
);
1719 free_pending_request(req
); /* immediate success or fail */
1721 spin_lock_irqsave(&host_info_lock
, flags
);
1722 list_add_tail(&addr
->addr_list
, &fi
->addr_list
);
1723 spin_unlock_irqrestore(&host_info_lock
, flags
);
1727 hpsb_register_addrspace(&raw1394_highlevel
, fi
->host
, &arm_ops
,
1729 req
->req
.address
+ req
->req
.length
);
1732 spin_lock_irqsave(&host_info_lock
, flags
);
1733 list_add_tail(&addr
->addr_list
, &fi
->addr_list
);
1734 spin_unlock_irqrestore(&host_info_lock
, flags
);
1736 DBGMSG("arm_register failed errno: %d \n", retval
);
1737 vfree(addr
->addr_space_buffer
);
1741 free_pending_request(req
); /* immediate success or fail */
1745 static int arm_unregister(struct file_info
*fi
, struct pending_request
*req
)
1749 struct list_head
*entry
;
1750 struct arm_addr
*addr
= NULL
;
1751 struct host_info
*hi
;
1752 struct file_info
*fi_hlp
= NULL
;
1753 struct arm_addr
*arm_addr
= NULL
;
1755 unsigned long flags
;
1757 DBGMSG("arm_Unregister called addr(Offset): "
1759 (u32
) ((req
->req
.address
>> 32) & 0xFFFF),
1760 (u32
) (req
->req
.address
& 0xFFFFFFFF));
1761 spin_lock_irqsave(&host_info_lock
, flags
);
1763 entry
= fi
->addr_list
.next
;
1764 while (entry
!= &(fi
->addr_list
)) {
1765 addr
= list_entry(entry
, struct arm_addr
, addr_list
);
1766 if (addr
->start
== req
->req
.address
) {
1770 entry
= entry
->next
;
1773 DBGMSG("arm_Unregister addr not found");
1774 spin_unlock_irqrestore(&host_info_lock
, flags
);
1777 DBGMSG("arm_Unregister addr found");
1779 /* another host with valid address-entry containing
1780 same addressrange */
1781 list_for_each_entry(hi
, &host_info_list
, list
) {
1782 if (hi
->host
!= fi
->host
) {
1783 list_for_each_entry(fi_hlp
, &hi
->file_info_list
, list
) {
1784 entry
= fi_hlp
->addr_list
.next
;
1785 while (entry
!= &(fi_hlp
->addr_list
)) {
1786 arm_addr
= list_entry(entry
,
1789 if (arm_addr
->start
== addr
->start
) {
1790 DBGMSG("another host ownes "
1791 "same addressrange");
1795 entry
= entry
->next
;
1804 DBGMSG("delete entry from list -> success");
1805 list_del(&addr
->addr_list
);
1806 spin_unlock_irqrestore(&host_info_lock
, flags
);
1807 vfree(addr
->addr_space_buffer
);
1809 free_pending_request(req
); /* immediate success or fail */
1813 hpsb_unregister_addrspace(&raw1394_highlevel
, fi
->host
,
1816 printk(KERN_ERR
"raw1394: arm_Unregister failed -> EINVAL\n");
1817 spin_unlock_irqrestore(&host_info_lock
, flags
);
1820 DBGMSG("delete entry from list -> success");
1821 list_del(&addr
->addr_list
);
1822 spin_unlock_irqrestore(&host_info_lock
, flags
);
1823 vfree(addr
->addr_space_buffer
);
1825 free_pending_request(req
); /* immediate success or fail */
1829 /* Copy data from ARM buffer(s) to user buffer. */
1830 static int arm_get_buf(struct file_info
*fi
, struct pending_request
*req
)
1832 struct arm_addr
*arm_addr
= NULL
;
1833 unsigned long flags
;
1834 unsigned long offset
;
1836 struct list_head
*entry
;
1838 DBGMSG("arm_get_buf "
1839 "addr(Offset): %04X %08X length: %u",
1840 (u32
) ((req
->req
.address
>> 32) & 0xFFFF),
1841 (u32
) (req
->req
.address
& 0xFFFFFFFF), (u32
) req
->req
.length
);
1843 spin_lock_irqsave(&host_info_lock
, flags
);
1844 entry
= fi
->addr_list
.next
;
1845 while (entry
!= &(fi
->addr_list
)) {
1846 arm_addr
= list_entry(entry
, struct arm_addr
, addr_list
);
1847 if ((arm_addr
->start
<= req
->req
.address
) &&
1848 (arm_addr
->end
> req
->req
.address
)) {
1849 if (req
->req
.address
+ req
->req
.length
<= arm_addr
->end
) {
1850 offset
= req
->req
.address
- arm_addr
->start
;
1851 spin_unlock_irqrestore(&host_info_lock
, flags
);
1854 ("arm_get_buf copy_to_user( %08X, %p, %u )",
1855 (u32
) req
->req
.recvb
,
1856 arm_addr
->addr_space_buffer
+ offset
,
1857 (u32
) req
->req
.length
);
1859 (int2ptr(req
->req
.recvb
),
1860 arm_addr
->addr_space_buffer
+ offset
,
1864 /* We have to free the request, because we
1865 * queue no response, and therefore nobody
1867 free_pending_request(req
);
1870 DBGMSG("arm_get_buf request exceeded mapping");
1871 spin_unlock_irqrestore(&host_info_lock
, flags
);
1875 entry
= entry
->next
;
1877 spin_unlock_irqrestore(&host_info_lock
, flags
);
1881 /* Copy data from user buffer to ARM buffer(s). */
1882 static int arm_set_buf(struct file_info
*fi
, struct pending_request
*req
)
1884 struct arm_addr
*arm_addr
= NULL
;
1885 unsigned long flags
;
1886 unsigned long offset
;
1888 struct list_head
*entry
;
1890 DBGMSG("arm_set_buf "
1891 "addr(Offset): %04X %08X length: %u",
1892 (u32
) ((req
->req
.address
>> 32) & 0xFFFF),
1893 (u32
) (req
->req
.address
& 0xFFFFFFFF), (u32
) req
->req
.length
);
1895 spin_lock_irqsave(&host_info_lock
, flags
);
1896 entry
= fi
->addr_list
.next
;
1897 while (entry
!= &(fi
->addr_list
)) {
1898 arm_addr
= list_entry(entry
, struct arm_addr
, addr_list
);
1899 if ((arm_addr
->start
<= req
->req
.address
) &&
1900 (arm_addr
->end
> req
->req
.address
)) {
1901 if (req
->req
.address
+ req
->req
.length
<= arm_addr
->end
) {
1902 offset
= req
->req
.address
- arm_addr
->start
;
1903 spin_unlock_irqrestore(&host_info_lock
, flags
);
1906 ("arm_set_buf copy_from_user( %p, %08X, %u )",
1907 arm_addr
->addr_space_buffer
+ offset
,
1908 (u32
) req
->req
.sendb
,
1909 (u32
) req
->req
.length
);
1911 (arm_addr
->addr_space_buffer
+ offset
,
1912 int2ptr(req
->req
.sendb
),
1916 /* We have to free the request, because we
1917 * queue no response, and therefore nobody
1919 free_pending_request(req
);
1922 DBGMSG("arm_set_buf request exceeded mapping");
1923 spin_unlock_irqrestore(&host_info_lock
, flags
);
1927 entry
= entry
->next
;
1929 spin_unlock_irqrestore(&host_info_lock
, flags
);
1933 static int reset_notification(struct file_info
*fi
, struct pending_request
*req
)
1935 DBGMSG("reset_notification called - switch %s ",
1936 (req
->req
.misc
== RAW1394_NOTIFY_OFF
) ? "OFF" : "ON");
1937 if ((req
->req
.misc
== RAW1394_NOTIFY_OFF
) ||
1938 (req
->req
.misc
== RAW1394_NOTIFY_ON
)) {
1939 fi
->notification
= (u8
) req
->req
.misc
;
1940 free_pending_request(req
); /* we have to free the request, because we queue no response, and therefore nobody will free it */
1943 /* error EINVAL (22) invalid argument */
1947 static int write_phypacket(struct file_info
*fi
, struct pending_request
*req
)
1949 struct hpsb_packet
*packet
= NULL
;
1952 unsigned long flags
;
1954 data
= be32_to_cpu((u32
) req
->req
.sendb
);
1955 DBGMSG("write_phypacket called - quadlet 0x%8.8x ", data
);
1956 packet
= hpsb_make_phypacket(fi
->host
, data
);
1959 req
->req
.length
= 0;
1960 req
->packet
= packet
;
1961 hpsb_set_packet_complete_task(packet
,
1962 (void (*)(void *))queue_complete_cb
, req
);
1963 spin_lock_irqsave(&fi
->reqlists_lock
, flags
);
1964 list_add_tail(&req
->list
, &fi
->req_pending
);
1965 spin_unlock_irqrestore(&fi
->reqlists_lock
, flags
);
1966 packet
->generation
= req
->req
.generation
;
1967 retval
= hpsb_send_packet(packet
);
1968 DBGMSG("write_phypacket send_packet called => retval: %d ", retval
);
1970 req
->req
.error
= RAW1394_ERROR_SEND_ERROR
;
1971 req
->req
.length
= 0;
1972 queue_complete_req(req
);
1977 static int get_config_rom(struct file_info
*fi
, struct pending_request
*req
)
1980 quadlet_t
*data
= kmalloc(req
->req
.length
, GFP_KERNEL
);
1987 csr1212_read(fi
->host
->csr
.rom
, CSR1212_CONFIG_ROM_SPACE_OFFSET
,
1988 data
, req
->req
.length
);
1989 if (copy_to_user(int2ptr(req
->req
.recvb
), data
, req
->req
.length
))
1992 (int2ptr(req
->req
.tag
), &fi
->host
->csr
.rom
->cache_head
->len
,
1993 sizeof(fi
->host
->csr
.rom
->cache_head
->len
)))
1995 if (copy_to_user(int2ptr(req
->req
.address
), &fi
->host
->csr
.generation
,
1996 sizeof(fi
->host
->csr
.generation
)))
1998 if (copy_to_user(int2ptr(req
->req
.sendb
), &status
, sizeof(status
)))
2002 free_pending_request(req
); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2007 static int update_config_rom(struct file_info
*fi
, struct pending_request
*req
)
2010 quadlet_t
*data
= kmalloc(req
->req
.length
, GFP_KERNEL
);
2013 if (copy_from_user(data
, int2ptr(req
->req
.sendb
), req
->req
.length
)) {
2016 int status
= hpsb_update_config_rom(fi
->host
,
2017 data
, req
->req
.length
,
2018 (unsigned char)req
->req
.
2021 (int2ptr(req
->req
.recvb
), &status
, sizeof(status
)))
2026 free_pending_request(req
); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2032 static int modify_config_rom(struct file_info
*fi
, struct pending_request
*req
)
2034 struct csr1212_keyval
*kv
;
2035 struct csr1212_csr_rom_cache
*cache
;
2036 struct csr1212_dentry
*dentry
;
2040 if (req
->req
.misc
== ~0) {
2041 if (req
->req
.length
== 0)
2044 /* Find an unused slot */
2046 dr
< RAW1394_MAX_USER_CSR_DIRS
&& fi
->csr1212_dirs
[dr
];
2049 if (dr
== RAW1394_MAX_USER_CSR_DIRS
)
2052 fi
->csr1212_dirs
[dr
] =
2053 csr1212_new_directory(CSR1212_KV_ID_VENDOR
);
2054 if (!fi
->csr1212_dirs
[dr
])
2058 if (!fi
->csr1212_dirs
[dr
])
2061 /* Delete old stuff */
2063 fi
->csr1212_dirs
[dr
]->value
.directory
.dentries_head
;
2064 dentry
; dentry
= dentry
->next
) {
2065 csr1212_detach_keyval_from_directory(fi
->host
->csr
.rom
->
2070 if (req
->req
.length
== 0) {
2071 csr1212_release_keyval(fi
->csr1212_dirs
[dr
]);
2072 fi
->csr1212_dirs
[dr
] = NULL
;
2074 hpsb_update_config_rom_image(fi
->host
);
2075 free_pending_request(req
);
2080 cache
= csr1212_rom_cache_malloc(0, req
->req
.length
);
2082 csr1212_release_keyval(fi
->csr1212_dirs
[dr
]);
2083 fi
->csr1212_dirs
[dr
] = NULL
;
2087 cache
->filled_head
= kmalloc(sizeof(*cache
->filled_head
), GFP_KERNEL
);
2088 if (!cache
->filled_head
) {
2089 csr1212_release_keyval(fi
->csr1212_dirs
[dr
]);
2090 fi
->csr1212_dirs
[dr
] = NULL
;
2091 CSR1212_FREE(cache
);
2094 cache
->filled_tail
= cache
->filled_head
;
2096 if (copy_from_user(cache
->data
, int2ptr(req
->req
.sendb
),
2098 csr1212_release_keyval(fi
->csr1212_dirs
[dr
]);
2099 fi
->csr1212_dirs
[dr
] = NULL
;
2102 cache
->len
= req
->req
.length
;
2103 cache
->filled_head
->offset_start
= 0;
2104 cache
->filled_head
->offset_end
= cache
->size
- 1;
2106 cache
->layout_head
= cache
->layout_tail
= fi
->csr1212_dirs
[dr
];
2108 ret
= CSR1212_SUCCESS
;
2109 /* parse all the items */
2110 for (kv
= cache
->layout_head
; ret
== CSR1212_SUCCESS
&& kv
;
2112 ret
= csr1212_parse_keyval(kv
, cache
);
2115 /* attach top level items to the root directory */
2117 fi
->csr1212_dirs
[dr
]->value
.directory
.dentries_head
;
2118 ret
== CSR1212_SUCCESS
&& dentry
; dentry
= dentry
->next
) {
2120 csr1212_attach_keyval_to_directory(fi
->host
->csr
.
2125 if (ret
== CSR1212_SUCCESS
) {
2126 ret
= hpsb_update_config_rom_image(fi
->host
);
2128 if (ret
>= 0 && copy_to_user(int2ptr(req
->req
.recvb
),
2134 kfree(cache
->filled_head
);
2135 CSR1212_FREE(cache
);
2138 /* we have to free the request, because we queue no response,
2139 * and therefore nobody will free it */
2140 free_pending_request(req
);
2144 fi
->csr1212_dirs
[dr
]->value
.directory
.dentries_head
;
2145 dentry
; dentry
= dentry
->next
) {
2146 csr1212_detach_keyval_from_directory(fi
->host
->csr
.rom
->
2150 csr1212_release_keyval(fi
->csr1212_dirs
[dr
]);
2151 fi
->csr1212_dirs
[dr
] = NULL
;
2156 static int state_connected(struct file_info
*fi
, struct pending_request
*req
)
2158 int node
= req
->req
.address
>> 48;
2160 req
->req
.error
= RAW1394_ERROR_NONE
;
2162 switch (req
->req
.type
) {
2164 case RAW1394_REQ_ECHO
:
2165 queue_complete_req(req
);
2168 case RAW1394_REQ_ARM_REGISTER
:
2169 return arm_register(fi
, req
);
2171 case RAW1394_REQ_ARM_UNREGISTER
:
2172 return arm_unregister(fi
, req
);
2174 case RAW1394_REQ_ARM_SET_BUF
:
2175 return arm_set_buf(fi
, req
);
2177 case RAW1394_REQ_ARM_GET_BUF
:
2178 return arm_get_buf(fi
, req
);
2180 case RAW1394_REQ_RESET_NOTIFY
:
2181 return reset_notification(fi
, req
);
2183 case RAW1394_REQ_ISO_SEND
:
2184 case RAW1394_REQ_ISO_LISTEN
:
2185 printk(KERN_DEBUG
"raw1394: old iso ABI has been removed\n");
2186 req
->req
.error
= RAW1394_ERROR_COMPAT
;
2187 req
->req
.misc
= RAW1394_KERNELAPI_VERSION
;
2188 queue_complete_req(req
);
2191 case RAW1394_REQ_FCP_LISTEN
:
2192 handle_fcp_listen(fi
, req
);
2195 case RAW1394_REQ_RESET_BUS
:
2196 if (req
->req
.misc
== RAW1394_LONG_RESET
) {
2197 DBGMSG("busreset called (type: LONG)");
2198 hpsb_reset_bus(fi
->host
, LONG_RESET
);
2199 free_pending_request(req
); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2202 if (req
->req
.misc
== RAW1394_SHORT_RESET
) {
2203 DBGMSG("busreset called (type: SHORT)");
2204 hpsb_reset_bus(fi
->host
, SHORT_RESET
);
2205 free_pending_request(req
); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2208 /* error EINVAL (22) invalid argument */
2210 case RAW1394_REQ_GET_ROM
:
2211 return get_config_rom(fi
, req
);
2213 case RAW1394_REQ_UPDATE_ROM
:
2214 return update_config_rom(fi
, req
);
2216 case RAW1394_REQ_MODIFY_ROM
:
2217 return modify_config_rom(fi
, req
);
2220 if (req
->req
.generation
!= get_hpsb_generation(fi
->host
)) {
2221 req
->req
.error
= RAW1394_ERROR_GENERATION
;
2222 req
->req
.generation
= get_hpsb_generation(fi
->host
);
2223 req
->req
.length
= 0;
2224 queue_complete_req(req
);
2228 switch (req
->req
.type
) {
2229 case RAW1394_REQ_PHYPACKET
:
2230 return write_phypacket(fi
, req
);
2231 case RAW1394_REQ_ASYNC_SEND
:
2232 return handle_async_send(fi
, req
);
2235 if (req
->req
.length
== 0) {
2236 req
->req
.error
= RAW1394_ERROR_INVALID_ARG
;
2237 queue_complete_req(req
);
2241 return handle_async_request(fi
, req
, node
);
2244 static ssize_t
raw1394_write(struct file
*file
, const char __user
* buffer
,
2245 size_t count
, loff_t
* offset_is_ignored
)
2247 struct file_info
*fi
= file
->private_data
;
2248 struct pending_request
*req
;
2249 ssize_t retval
= -EBADFD
;
2251 #ifdef CONFIG_COMPAT
2252 if (count
== sizeof(struct compat_raw1394_req
) &&
2253 sizeof(struct compat_raw1394_req
) !=
2254 sizeof(struct raw1394_request
)) {
2255 buffer
= raw1394_compat_write(buffer
);
2256 if (IS_ERR((__force
void *)buffer
))
2257 return PTR_ERR((__force
void *)buffer
);
2260 if (count
!= sizeof(struct raw1394_request
)) {
2264 req
= alloc_pending_request();
2268 req
->file_info
= fi
;
2270 if (copy_from_user(&req
->req
, buffer
, sizeof(struct raw1394_request
))) {
2271 free_pending_request(req
);
2275 if (!mutex_trylock(&fi
->state_mutex
)) {
2276 free_pending_request(req
);
2280 switch (fi
->state
) {
2282 retval
= state_opened(fi
, req
);
2286 retval
= state_initialized(fi
, req
);
2290 retval
= state_connected(fi
, req
);
2294 mutex_unlock(&fi
->state_mutex
);
2297 free_pending_request(req
);
2306 /* rawiso operations */
2308 /* check if any RAW1394_REQ_RAWISO_ACTIVITY event is already in the
2309 * completion queue (reqlists_lock must be taken) */
2310 static inline int __rawiso_event_in_queue(struct file_info
*fi
)
2312 struct pending_request
*req
;
2314 list_for_each_entry(req
, &fi
->req_complete
, list
)
2315 if (req
->req
.type
== RAW1394_REQ_RAWISO_ACTIVITY
)
2321 /* put a RAWISO_ACTIVITY event in the queue, if one isn't there already */
2322 static void queue_rawiso_event(struct file_info
*fi
)
2324 unsigned long flags
;
2326 spin_lock_irqsave(&fi
->reqlists_lock
, flags
);
2328 /* only one ISO activity event may be in the queue */
2329 if (!__rawiso_event_in_queue(fi
)) {
2330 struct pending_request
*req
=
2331 __alloc_pending_request(GFP_ATOMIC
);
2334 req
->file_info
= fi
;
2335 req
->req
.type
= RAW1394_REQ_RAWISO_ACTIVITY
;
2336 req
->req
.generation
= get_hpsb_generation(fi
->host
);
2337 __queue_complete_req(req
);
2339 /* on allocation failure, signal an overflow */
2340 if (fi
->iso_handle
) {
2341 atomic_inc(&fi
->iso_handle
->overflows
);
2345 spin_unlock_irqrestore(&fi
->reqlists_lock
, flags
);
2348 static void rawiso_activity_cb(struct hpsb_iso
*iso
)
2350 unsigned long flags
;
2351 struct host_info
*hi
;
2352 struct file_info
*fi
;
2354 spin_lock_irqsave(&host_info_lock
, flags
);
2355 hi
= find_host_info(iso
->host
);
2358 list_for_each_entry(fi
, &hi
->file_info_list
, list
) {
2359 if (fi
->iso_handle
== iso
)
2360 queue_rawiso_event(fi
);
2364 spin_unlock_irqrestore(&host_info_lock
, flags
);
2367 /* helper function - gather all the kernel iso status bits for returning to user-space */
2368 static void raw1394_iso_fill_status(struct hpsb_iso
*iso
,
2369 struct raw1394_iso_status
*stat
)
2371 int overflows
= atomic_read(&iso
->overflows
);
2372 int skips
= atomic_read(&iso
->skips
);
2374 stat
->config
.data_buf_size
= iso
->buf_size
;
2375 stat
->config
.buf_packets
= iso
->buf_packets
;
2376 stat
->config
.channel
= iso
->channel
;
2377 stat
->config
.speed
= iso
->speed
;
2378 stat
->config
.irq_interval
= iso
->irq_interval
;
2379 stat
->n_packets
= hpsb_iso_n_ready(iso
);
2380 stat
->overflows
= ((skips
& 0xFFFF) << 16) | ((overflows
& 0xFFFF));
2381 stat
->xmit_cycle
= iso
->xmit_cycle
;
2384 static int raw1394_iso_xmit_init(struct file_info
*fi
, void __user
* uaddr
)
2386 struct raw1394_iso_status stat
;
2391 if (copy_from_user(&stat
, uaddr
, sizeof(stat
)))
2394 fi
->iso_handle
= hpsb_iso_xmit_init(fi
->host
,
2395 stat
.config
.data_buf_size
,
2396 stat
.config
.buf_packets
,
2397 stat
.config
.channel
,
2399 stat
.config
.irq_interval
,
2400 rawiso_activity_cb
);
2401 if (!fi
->iso_handle
)
2404 fi
->iso_state
= RAW1394_ISO_XMIT
;
2406 raw1394_iso_fill_status(fi
->iso_handle
, &stat
);
2407 if (copy_to_user(uaddr
, &stat
, sizeof(stat
)))
2410 /* queue an event to get things started */
2411 rawiso_activity_cb(fi
->iso_handle
);
2416 static int raw1394_iso_recv_init(struct file_info
*fi
, void __user
* uaddr
)
2418 struct raw1394_iso_status stat
;
2423 if (copy_from_user(&stat
, uaddr
, sizeof(stat
)))
2426 fi
->iso_handle
= hpsb_iso_recv_init(fi
->host
,
2427 stat
.config
.data_buf_size
,
2428 stat
.config
.buf_packets
,
2429 stat
.config
.channel
,
2430 stat
.config
.dma_mode
,
2431 stat
.config
.irq_interval
,
2432 rawiso_activity_cb
);
2433 if (!fi
->iso_handle
)
2436 fi
->iso_state
= RAW1394_ISO_RECV
;
2438 raw1394_iso_fill_status(fi
->iso_handle
, &stat
);
2439 if (copy_to_user(uaddr
, &stat
, sizeof(stat
)))
2444 static int raw1394_iso_get_status(struct file_info
*fi
, void __user
* uaddr
)
2446 struct raw1394_iso_status stat
;
2447 struct hpsb_iso
*iso
= fi
->iso_handle
;
2449 raw1394_iso_fill_status(fi
->iso_handle
, &stat
);
2450 if (copy_to_user(uaddr
, &stat
, sizeof(stat
)))
2453 /* reset overflow counter */
2454 atomic_set(&iso
->overflows
, 0);
2455 /* reset skip counter */
2456 atomic_set(&iso
->skips
, 0);
2461 /* copy N packet_infos out of the ringbuffer into user-supplied array */
2462 static int raw1394_iso_recv_packets(struct file_info
*fi
, void __user
* uaddr
)
2464 struct raw1394_iso_packets upackets
;
2465 unsigned int packet
= fi
->iso_handle
->first_packet
;
2468 if (copy_from_user(&upackets
, uaddr
, sizeof(upackets
)))
2471 if (upackets
.n_packets
> hpsb_iso_n_ready(fi
->iso_handle
))
2474 /* ensure user-supplied buffer is accessible and big enough */
2475 if (!access_ok(VERIFY_WRITE
, upackets
.infos
,
2476 upackets
.n_packets
*
2477 sizeof(struct raw1394_iso_packet_info
)))
2480 /* copy the packet_infos out */
2481 for (i
= 0; i
< upackets
.n_packets
; i
++) {
2482 if (__copy_to_user(&upackets
.infos
[i
],
2483 &fi
->iso_handle
->infos
[packet
],
2484 sizeof(struct raw1394_iso_packet_info
)))
2487 packet
= (packet
+ 1) % fi
->iso_handle
->buf_packets
;
2493 /* copy N packet_infos from user to ringbuffer, and queue them for transmission */
2494 static int raw1394_iso_send_packets(struct file_info
*fi
, void __user
* uaddr
)
2496 struct raw1394_iso_packets upackets
;
2499 if (copy_from_user(&upackets
, uaddr
, sizeof(upackets
)))
2502 if (upackets
.n_packets
>= fi
->iso_handle
->buf_packets
)
2505 if (upackets
.n_packets
>= hpsb_iso_n_ready(fi
->iso_handle
))
2508 /* ensure user-supplied buffer is accessible and big enough */
2509 if (!access_ok(VERIFY_READ
, upackets
.infos
,
2510 upackets
.n_packets
*
2511 sizeof(struct raw1394_iso_packet_info
)))
2514 /* copy the infos structs in and queue the packets */
2515 for (i
= 0; i
< upackets
.n_packets
; i
++) {
2516 struct raw1394_iso_packet_info info
;
2518 if (__copy_from_user(&info
, &upackets
.infos
[i
],
2519 sizeof(struct raw1394_iso_packet_info
)))
2522 rv
= hpsb_iso_xmit_queue_packet(fi
->iso_handle
, info
.offset
,
2523 info
.len
, info
.tag
, info
.sy
);
2531 static void raw1394_iso_shutdown(struct file_info
*fi
)
2534 hpsb_iso_shutdown(fi
->iso_handle
);
2536 fi
->iso_handle
= NULL
;
2537 fi
->iso_state
= RAW1394_ISO_INACTIVE
;
2540 static int raw1394_read_cycle_timer(struct file_info
*fi
, void __user
* uaddr
)
2542 struct raw1394_cycle_timer ct
;
2545 err
= hpsb_read_cycle_timer(fi
->host
, &ct
.cycle_timer
, &ct
.local_time
);
2547 if (copy_to_user(uaddr
, &ct
, sizeof(ct
)))
2552 /* mmap the rawiso xmit/recv buffer */
2553 static int raw1394_mmap(struct file
*file
, struct vm_area_struct
*vma
)
2555 struct file_info
*fi
= file
->private_data
;
2558 if (!mutex_trylock(&fi
->state_mutex
))
2561 if (fi
->iso_state
== RAW1394_ISO_INACTIVE
)
2564 ret
= dma_region_mmap(&fi
->iso_handle
->data_buf
, file
, vma
);
2566 mutex_unlock(&fi
->state_mutex
);
2571 static long raw1394_ioctl_inactive(struct file_info
*fi
, unsigned int cmd
,
2575 case RAW1394_IOC_ISO_XMIT_INIT
:
2576 return raw1394_iso_xmit_init(fi
, argp
);
2577 case RAW1394_IOC_ISO_RECV_INIT
:
2578 return raw1394_iso_recv_init(fi
, argp
);
2584 static long raw1394_ioctl_recv(struct file_info
*fi
, unsigned int cmd
,
2587 void __user
*argp
= (void __user
*)arg
;
2590 case RAW1394_IOC_ISO_RECV_START
:{
2593 if (copy_from_user(&args
[0], argp
, sizeof(args
)))
2595 return hpsb_iso_recv_start(fi
->iso_handle
,
2596 args
[0], args
[1], args
[2]);
2598 case RAW1394_IOC_ISO_XMIT_RECV_STOP
:
2599 hpsb_iso_stop(fi
->iso_handle
);
2601 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL
:
2602 return hpsb_iso_recv_listen_channel(fi
->iso_handle
, arg
);
2603 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL
:
2604 return hpsb_iso_recv_unlisten_channel(fi
->iso_handle
, arg
);
2605 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK
:{
2608 if (copy_from_user(&mask
, argp
, sizeof(mask
)))
2610 return hpsb_iso_recv_set_channel_mask(fi
->iso_handle
,
2613 case RAW1394_IOC_ISO_GET_STATUS
:
2614 return raw1394_iso_get_status(fi
, argp
);
2615 case RAW1394_IOC_ISO_RECV_PACKETS
:
2616 return raw1394_iso_recv_packets(fi
, argp
);
2617 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS
:
2618 return hpsb_iso_recv_release_packets(fi
->iso_handle
, arg
);
2619 case RAW1394_IOC_ISO_RECV_FLUSH
:
2620 return hpsb_iso_recv_flush(fi
->iso_handle
);
2621 case RAW1394_IOC_ISO_SHUTDOWN
:
2622 raw1394_iso_shutdown(fi
);
2624 case RAW1394_IOC_ISO_QUEUE_ACTIVITY
:
2625 queue_rawiso_event(fi
);
2632 static long raw1394_ioctl_xmit(struct file_info
*fi
, unsigned int cmd
,
2636 case RAW1394_IOC_ISO_XMIT_START
:{
2639 if (copy_from_user(&args
[0], argp
, sizeof(args
)))
2641 return hpsb_iso_xmit_start(fi
->iso_handle
,
2644 case RAW1394_IOC_ISO_XMIT_SYNC
:
2645 return hpsb_iso_xmit_sync(fi
->iso_handle
);
2646 case RAW1394_IOC_ISO_XMIT_RECV_STOP
:
2647 hpsb_iso_stop(fi
->iso_handle
);
2649 case RAW1394_IOC_ISO_GET_STATUS
:
2650 return raw1394_iso_get_status(fi
, argp
);
2651 case RAW1394_IOC_ISO_XMIT_PACKETS
:
2652 return raw1394_iso_send_packets(fi
, argp
);
2653 case RAW1394_IOC_ISO_SHUTDOWN
:
2654 raw1394_iso_shutdown(fi
);
2656 case RAW1394_IOC_ISO_QUEUE_ACTIVITY
:
2657 queue_rawiso_event(fi
);
2664 /* ioctl is only used for rawiso operations */
2665 static long raw1394_ioctl(struct file
*file
, unsigned int cmd
,
2668 struct file_info
*fi
= file
->private_data
;
2669 void __user
*argp
= (void __user
*)arg
;
2672 /* state-independent commands */
2674 case RAW1394_IOC_GET_CYCLE_TIMER
:
2675 return raw1394_read_cycle_timer(fi
, argp
);
2680 if (!mutex_trylock(&fi
->state_mutex
))
2683 switch (fi
->iso_state
) {
2684 case RAW1394_ISO_INACTIVE
:
2685 ret
= raw1394_ioctl_inactive(fi
, cmd
, argp
);
2687 case RAW1394_ISO_RECV
:
2688 ret
= raw1394_ioctl_recv(fi
, cmd
, arg
);
2690 case RAW1394_ISO_XMIT
:
2691 ret
= raw1394_ioctl_xmit(fi
, cmd
, argp
);
2698 mutex_unlock(&fi
->state_mutex
);
2703 #ifdef CONFIG_COMPAT
2704 struct raw1394_iso_packets32
{
2706 compat_uptr_t infos
;
2707 } __attribute__((packed
));
2709 struct raw1394_cycle_timer32
{
2713 #if defined(CONFIG_X86_64) || defined(CONFIG_IA64)
2714 __attribute__((packed
))
2718 #define RAW1394_IOC_ISO_RECV_PACKETS32 \
2719 _IOW ('#', 0x25, struct raw1394_iso_packets32)
2720 #define RAW1394_IOC_ISO_XMIT_PACKETS32 \
2721 _IOW ('#', 0x27, struct raw1394_iso_packets32)
2722 #define RAW1394_IOC_GET_CYCLE_TIMER32 \
2723 _IOR ('#', 0x30, struct raw1394_cycle_timer32)
2725 static long raw1394_iso_xmit_recv_packets32(struct file
*file
, unsigned int cmd
,
2726 struct raw1394_iso_packets32 __user
*arg
)
2728 compat_uptr_t infos32
;
2731 struct raw1394_iso_packets __user
*dst
= compat_alloc_user_space(sizeof(struct raw1394_iso_packets
));
2733 if (!copy_in_user(&dst
->n_packets
, &arg
->n_packets
, sizeof arg
->n_packets
) &&
2734 !copy_from_user(&infos32
, &arg
->infos
, sizeof infos32
)) {
2735 infos
= compat_ptr(infos32
);
2736 if (!copy_to_user(&dst
->infos
, &infos
, sizeof infos
))
2737 err
= raw1394_ioctl(file
, cmd
, (unsigned long)dst
);
2742 static long raw1394_read_cycle_timer32(struct file_info
*fi
, void __user
* uaddr
)
2744 struct raw1394_cycle_timer32 ct
;
2747 err
= hpsb_read_cycle_timer(fi
->host
, &ct
.cycle_timer
, &ct
.local_time
);
2749 if (copy_to_user(uaddr
, &ct
, sizeof(ct
)))
2754 static long raw1394_compat_ioctl(struct file
*file
,
2755 unsigned int cmd
, unsigned long arg
)
2757 struct file_info
*fi
= file
->private_data
;
2758 void __user
*argp
= (void __user
*)arg
;
2762 /* These requests have same format as long as 'int' has same size. */
2763 case RAW1394_IOC_ISO_RECV_INIT
:
2764 case RAW1394_IOC_ISO_RECV_START
:
2765 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL
:
2766 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL
:
2767 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK
:
2768 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS
:
2769 case RAW1394_IOC_ISO_RECV_FLUSH
:
2770 case RAW1394_IOC_ISO_XMIT_RECV_STOP
:
2771 case RAW1394_IOC_ISO_XMIT_INIT
:
2772 case RAW1394_IOC_ISO_XMIT_START
:
2773 case RAW1394_IOC_ISO_XMIT_SYNC
:
2774 case RAW1394_IOC_ISO_GET_STATUS
:
2775 case RAW1394_IOC_ISO_SHUTDOWN
:
2776 case RAW1394_IOC_ISO_QUEUE_ACTIVITY
:
2777 err
= raw1394_ioctl(file
, cmd
, arg
);
2779 /* These request have different format. */
2780 case RAW1394_IOC_ISO_RECV_PACKETS32
:
2781 err
= raw1394_iso_xmit_recv_packets32(file
, RAW1394_IOC_ISO_RECV_PACKETS
, argp
);
2783 case RAW1394_IOC_ISO_XMIT_PACKETS32
:
2784 err
= raw1394_iso_xmit_recv_packets32(file
, RAW1394_IOC_ISO_XMIT_PACKETS
, argp
);
2786 case RAW1394_IOC_GET_CYCLE_TIMER32
:
2787 err
= raw1394_read_cycle_timer32(fi
, argp
);
2798 static unsigned int raw1394_poll(struct file
*file
, poll_table
* pt
)
2800 struct file_info
*fi
= file
->private_data
;
2801 unsigned int mask
= POLLOUT
| POLLWRNORM
;
2802 unsigned long flags
;
2804 poll_wait(file
, &fi
->wait_complete
, pt
);
2806 spin_lock_irqsave(&fi
->reqlists_lock
, flags
);
2807 if (!list_empty(&fi
->req_complete
)) {
2808 mask
|= POLLIN
| POLLRDNORM
;
2810 spin_unlock_irqrestore(&fi
->reqlists_lock
, flags
);
2815 static int raw1394_open(struct inode
*inode
, struct file
*file
)
2817 struct file_info
*fi
;
2819 fi
= kzalloc(sizeof(*fi
), GFP_KERNEL
);
2823 fi
->notification
= (u8
) RAW1394_NOTIFY_ON
; /* busreset notification */
2825 INIT_LIST_HEAD(&fi
->list
);
2826 mutex_init(&fi
->state_mutex
);
2828 INIT_LIST_HEAD(&fi
->req_pending
);
2829 INIT_LIST_HEAD(&fi
->req_complete
);
2830 spin_lock_init(&fi
->reqlists_lock
);
2831 init_waitqueue_head(&fi
->wait_complete
);
2832 INIT_LIST_HEAD(&fi
->addr_list
);
2834 file
->private_data
= fi
;
2836 return nonseekable_open(inode
, file
);
2839 static int raw1394_release(struct inode
*inode
, struct file
*file
)
2841 struct file_info
*fi
= file
->private_data
;
2842 struct list_head
*lh
;
2843 struct pending_request
*req
;
2846 struct list_head
*entry
;
2847 struct arm_addr
*addr
= NULL
;
2848 struct host_info
*hi
;
2849 struct file_info
*fi_hlp
= NULL
;
2850 struct arm_addr
*arm_addr
= NULL
;
2853 unsigned long flags
;
2855 if (fi
->iso_state
!= RAW1394_ISO_INACTIVE
)
2856 raw1394_iso_shutdown(fi
);
2858 spin_lock_irqsave(&host_info_lock
, flags
);
2861 /* set address-entries invalid */
2863 while (!list_empty(&fi
->addr_list
)) {
2865 lh
= fi
->addr_list
.next
;
2866 addr
= list_entry(lh
, struct arm_addr
, addr_list
);
2867 /* another host with valid address-entry containing
2868 same addressrange? */
2869 list_for_each_entry(hi
, &host_info_list
, list
) {
2870 if (hi
->host
!= fi
->host
) {
2871 list_for_each_entry(fi_hlp
, &hi
->file_info_list
,
2873 entry
= fi_hlp
->addr_list
.next
;
2874 while (entry
!= &(fi_hlp
->addr_list
)) {
2875 arm_addr
= list_entry(entry
, struct
2878 if (arm_addr
->start
==
2881 ("raw1394_release: "
2882 "another host ownes "
2883 "same addressrange");
2887 entry
= entry
->next
;
2895 if (!another_host
) {
2896 DBGMSG("raw1394_release: call hpsb_arm_unregister");
2898 hpsb_unregister_addrspace(&raw1394_highlevel
,
2899 fi
->host
, addr
->start
);
2903 "raw1394_release arm_Unregister failed\n");
2906 DBGMSG("raw1394_release: delete addr_entry from list");
2907 list_del(&addr
->addr_list
);
2908 vfree(addr
->addr_space_buffer
);
2911 spin_unlock_irqrestore(&host_info_lock
, flags
);
2913 printk(KERN_ERR
"raw1394: during addr_list-release "
2914 "error(s) occurred \n");
2918 /* This locked section guarantees that neither
2919 * complete nor pending requests exist once i!=0 */
2920 spin_lock_irqsave(&fi
->reqlists_lock
, flags
);
2921 while ((req
= __next_complete_req(fi
)))
2922 free_pending_request(req
);
2924 i
= list_empty(&fi
->req_pending
);
2925 spin_unlock_irqrestore(&fi
->reqlists_lock
, flags
);
2930 * Sleep until more requests can be freed.
2932 * NB: We call the macro wait_event() with a condition argument
2933 * with side effect. This is only possible because the side
2934 * effect does not occur until the condition became true, and
2935 * wait_event() won't evaluate the condition again after that.
2937 wait_event(fi
->wait_complete
, (req
= next_complete_req(fi
)));
2938 free_pending_request(req
);
2941 /* Remove any sub-trees left by user space programs */
2942 for (i
= 0; i
< RAW1394_MAX_USER_CSR_DIRS
; i
++) {
2943 struct csr1212_dentry
*dentry
;
2944 if (!fi
->csr1212_dirs
[i
])
2947 fi
->csr1212_dirs
[i
]->value
.directory
.dentries_head
; dentry
;
2948 dentry
= dentry
->next
) {
2949 csr1212_detach_keyval_from_directory(fi
->host
->csr
.rom
->
2953 csr1212_release_keyval(fi
->csr1212_dirs
[i
]);
2954 fi
->csr1212_dirs
[i
] = NULL
;
2958 if ((csr_mod
|| fi
->cfgrom_upd
)
2959 && hpsb_update_config_rom_image(fi
->host
) < 0)
2961 ("Failed to generate Configuration ROM image for host %d",
2964 if (fi
->state
== connected
) {
2965 spin_lock_irqsave(&host_info_lock
, flags
);
2966 list_del(&fi
->list
);
2967 spin_unlock_irqrestore(&host_info_lock
, flags
);
2969 put_device(&fi
->host
->device
);
2972 spin_lock_irqsave(&host_info_lock
, flags
);
2974 module_put(fi
->host
->driver
->owner
);
2975 spin_unlock_irqrestore(&host_info_lock
, flags
);
2982 /*** HOTPLUG STUFF **********************************************************/
2984 * Export information about protocols/devices supported by this driver.
2987 static const struct ieee1394_device_id raw1394_id_table
[] = {
2989 .match_flags
= IEEE1394_MATCH_SPECIFIER_ID
| IEEE1394_MATCH_VERSION
,
2990 .specifier_id
= AVC_UNIT_SPEC_ID_ENTRY
& 0xffffff,
2991 .version
= AVC_SW_VERSION_ENTRY
& 0xffffff},
2993 .match_flags
= IEEE1394_MATCH_SPECIFIER_ID
| IEEE1394_MATCH_VERSION
,
2994 .specifier_id
= CAMERA_UNIT_SPEC_ID_ENTRY
& 0xffffff,
2995 .version
= CAMERA_SW_VERSION_ENTRY
& 0xffffff},
2997 .match_flags
= IEEE1394_MATCH_SPECIFIER_ID
| IEEE1394_MATCH_VERSION
,
2998 .specifier_id
= CAMERA_UNIT_SPEC_ID_ENTRY
& 0xffffff,
2999 .version
= (CAMERA_SW_VERSION_ENTRY
+ 1) & 0xffffff},
3001 .match_flags
= IEEE1394_MATCH_SPECIFIER_ID
| IEEE1394_MATCH_VERSION
,
3002 .specifier_id
= CAMERA_UNIT_SPEC_ID_ENTRY
& 0xffffff,
3003 .version
= (CAMERA_SW_VERSION_ENTRY
+ 2) & 0xffffff},
3007 MODULE_DEVICE_TABLE(ieee1394
, raw1394_id_table
);
3010 static struct hpsb_protocol_driver raw1394_driver
= {
3014 /******************************************************************************/
3016 static struct hpsb_highlevel raw1394_highlevel
= {
3017 .name
= RAW1394_DEVICE_NAME
,
3018 .add_host
= add_host
,
3019 .remove_host
= remove_host
,
3020 .host_reset
= host_reset
,
3021 .fcp_request
= fcp_request
,
3024 static struct cdev raw1394_cdev
;
3025 static const struct file_operations raw1394_fops
= {
3026 .owner
= THIS_MODULE
,
3027 .read
= raw1394_read
,
3028 .write
= raw1394_write
,
3029 .mmap
= raw1394_mmap
,
3030 .unlocked_ioctl
= raw1394_ioctl
,
3031 #ifdef CONFIG_COMPAT
3032 .compat_ioctl
= raw1394_compat_ioctl
,
3034 .poll
= raw1394_poll
,
3035 .open
= raw1394_open
,
3036 .release
= raw1394_release
,
3037 .llseek
= no_llseek
,
3040 static int __init
init_raw1394(void)
3044 hpsb_register_highlevel(&raw1394_highlevel
);
3047 (device_create(hpsb_protocol_class
, NULL
,
3048 MKDEV(IEEE1394_MAJOR
,
3049 IEEE1394_MINOR_BLOCK_RAW1394
* 16),
3050 NULL
, RAW1394_DEVICE_NAME
))) {
3055 cdev_init(&raw1394_cdev
, &raw1394_fops
);
3056 raw1394_cdev
.owner
= THIS_MODULE
;
3057 ret
= cdev_add(&raw1394_cdev
, IEEE1394_RAW1394_DEV
, 1);
3059 HPSB_ERR("raw1394 failed to register minor device block");
3063 HPSB_INFO("raw1394: /dev/%s device initialized", RAW1394_DEVICE_NAME
);
3065 ret
= hpsb_register_protocol(&raw1394_driver
);
3067 HPSB_ERR("raw1394: failed to register protocol");
3068 cdev_del(&raw1394_cdev
);
3075 device_destroy(hpsb_protocol_class
,
3076 MKDEV(IEEE1394_MAJOR
,
3077 IEEE1394_MINOR_BLOCK_RAW1394
* 16));
3079 hpsb_unregister_highlevel(&raw1394_highlevel
);
3084 static void __exit
cleanup_raw1394(void)
3086 device_destroy(hpsb_protocol_class
,
3087 MKDEV(IEEE1394_MAJOR
,
3088 IEEE1394_MINOR_BLOCK_RAW1394
* 16));
3089 cdev_del(&raw1394_cdev
);
3090 hpsb_unregister_highlevel(&raw1394_highlevel
);
3091 hpsb_unregister_protocol(&raw1394_driver
);
3094 module_init(init_raw1394
);
3095 module_exit(cleanup_raw1394
);
3096 MODULE_LICENSE("GPL");