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/string.h>
33 #include <linux/slab.h>
35 #include <linux/poll.h>
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/smp_lock.h>
39 #include <linux/interrupt.h>
40 #include <linux/vmalloc.h>
41 #include <linux/cdev.h>
42 #include <asm/uaccess.h>
43 #include <asm/atomic.h>
44 #include <linux/compat.h>
48 #include "ieee1394_types.h"
49 #include "ieee1394_core.h"
52 #include "highlevel.h"
54 #include "ieee1394_transactions.h"
56 #include "raw1394-private.h"
58 #define int2ptr(x) ((void __user *)(unsigned long)x)
59 #define ptr2int(x) ((u64)(unsigned long)(void __user *)x)
61 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
66 #define DBGMSG(fmt, args...) \
67 printk(KERN_INFO "raw1394:" fmt "\n" , ## args)
69 #define DBGMSG(fmt, args...)
72 static LIST_HEAD(host_info_list);
73 static int host_count;
74 static DEFINE_SPINLOCK(host_info_lock);
75 static atomic_t internal_generation = ATOMIC_INIT(0);
77 static atomic_t iso_buffer_size;
78 static const int iso_buffer_max = 4 * 1024 * 1024; /* 4 MB */
80 static struct hpsb_highlevel raw1394_highlevel;
82 static int arm_read(struct hpsb_host *host, int nodeid, quadlet_t * buffer,
83 u64 addr, size_t length, u16 flags);
84 static int arm_write(struct hpsb_host *host, int nodeid, int destid,
85 quadlet_t * data, u64 addr, size_t length, u16 flags);
86 static int arm_lock(struct hpsb_host *host, int nodeid, quadlet_t * store,
87 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
89 static int arm_lock64(struct hpsb_host *host, int nodeid, octlet_t * store,
90 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
92 static struct hpsb_address_ops arm_ops = {
99 static void queue_complete_cb(struct pending_request *req);
101 static struct pending_request *__alloc_pending_request(gfp_t flags)
103 struct pending_request *req;
105 req = kzalloc(sizeof(*req), flags);
107 INIT_LIST_HEAD(&req->list);
112 static inline struct pending_request *alloc_pending_request(void)
114 return __alloc_pending_request(SLAB_KERNEL);
117 static void free_pending_request(struct pending_request *req)
120 if (atomic_dec_and_test(&req->ibs->refcount)) {
121 atomic_sub(req->ibs->data_size, &iso_buffer_size);
124 } else if (req->free_data) {
127 hpsb_free_packet(req->packet);
131 /* fi->reqlists_lock must be taken */
132 static void __queue_complete_req(struct pending_request *req)
134 struct file_info *fi = req->file_info;
135 list_move_tail(&req->list, &fi->req_complete);
137 up(&fi->complete_sem);
138 wake_up_interruptible(&fi->poll_wait_complete);
141 static void queue_complete_req(struct pending_request *req)
144 struct file_info *fi = req->file_info;
146 spin_lock_irqsave(&fi->reqlists_lock, flags);
147 __queue_complete_req(req);
148 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
151 static void queue_complete_cb(struct pending_request *req)
153 struct hpsb_packet *packet = req->packet;
154 int rcode = (packet->header[1] >> 12) & 0xf;
156 switch (packet->ack_code) {
158 case ACKX_SEND_ERROR:
159 req->req.error = RAW1394_ERROR_SEND_ERROR;
162 req->req.error = RAW1394_ERROR_ABORTED;
165 req->req.error = RAW1394_ERROR_TIMEOUT;
168 req->req.error = (packet->ack_code << 16) | rcode;
172 if (!((packet->ack_code == ACK_PENDING) && (rcode == RCODE_COMPLETE))) {
176 if ((req->req.type == RAW1394_REQ_ASYNC_READ) ||
177 (req->req.type == RAW1394_REQ_ASYNC_WRITE) ||
178 (req->req.type == RAW1394_REQ_ASYNC_STREAM) ||
179 (req->req.type == RAW1394_REQ_LOCK) ||
180 (req->req.type == RAW1394_REQ_LOCK64))
181 hpsb_free_tlabel(packet);
183 queue_complete_req(req);
186 static void add_host(struct hpsb_host *host)
188 struct host_info *hi;
191 hi = kmalloc(sizeof(*hi), GFP_KERNEL);
194 INIT_LIST_HEAD(&hi->list);
196 INIT_LIST_HEAD(&hi->file_info_list);
198 spin_lock_irqsave(&host_info_lock, flags);
199 list_add_tail(&hi->list, &host_info_list);
201 spin_unlock_irqrestore(&host_info_lock, flags);
204 atomic_inc(&internal_generation);
207 static struct host_info *find_host_info(struct hpsb_host *host)
209 struct host_info *hi;
211 list_for_each_entry(hi, &host_info_list, list)
212 if (hi->host == host)
218 static void remove_host(struct hpsb_host *host)
220 struct host_info *hi;
223 spin_lock_irqsave(&host_info_lock, flags);
224 hi = find_host_info(host);
230 FIXME: address ranges should be removed
231 and fileinfo states should be initialized
232 (including setting generation to
233 internal-generation ...)
236 spin_unlock_irqrestore(&host_info_lock, flags);
239 printk(KERN_ERR "raw1394: attempt to remove unknown host "
246 atomic_inc(&internal_generation);
249 static void host_reset(struct hpsb_host *host)
252 struct host_info *hi;
253 struct file_info *fi;
254 struct pending_request *req;
256 spin_lock_irqsave(&host_info_lock, flags);
257 hi = find_host_info(host);
260 list_for_each_entry(fi, &hi->file_info_list, list) {
261 if (fi->notification == RAW1394_NOTIFY_ON) {
262 req = __alloc_pending_request(SLAB_ATOMIC);
266 req->req.type = RAW1394_REQ_BUS_RESET;
267 req->req.generation =
268 get_hpsb_generation(host);
269 req->req.misc = (host->node_id << 16)
271 if (fi->protocol_version > 3) {
278 queue_complete_req(req);
283 spin_unlock_irqrestore(&host_info_lock, flags);
286 static void iso_receive(struct hpsb_host *host, int channel, quadlet_t * data,
290 struct host_info *hi;
291 struct file_info *fi;
292 struct pending_request *req, *req_next;
293 struct iso_block_store *ibs = NULL;
296 if ((atomic_read(&iso_buffer_size) + length) > iso_buffer_max) {
297 HPSB_INFO("dropped iso packet");
301 spin_lock_irqsave(&host_info_lock, flags);
302 hi = find_host_info(host);
305 list_for_each_entry(fi, &hi->file_info_list, list) {
306 if (!(fi->listen_channels & (1ULL << channel)))
309 req = __alloc_pending_request(SLAB_ATOMIC);
314 ibs = kmalloc(sizeof(*ibs) + length,
321 atomic_add(length, &iso_buffer_size);
322 atomic_set(&ibs->refcount, 0);
323 ibs->data_size = length;
324 memcpy(ibs->data, data, length);
327 atomic_inc(&ibs->refcount);
331 req->data = ibs->data;
332 req->req.type = RAW1394_REQ_ISO_RECEIVE;
333 req->req.generation = get_hpsb_generation(host);
335 req->req.recvb = ptr2int(fi->iso_buffer);
336 req->req.length = min(length, fi->iso_buffer_length);
338 list_add_tail(&req->list, &reqs);
341 spin_unlock_irqrestore(&host_info_lock, flags);
343 list_for_each_entry_safe(req, req_next, &reqs, list)
344 queue_complete_req(req);
347 static void fcp_request(struct hpsb_host *host, int nodeid, int direction,
348 int cts, u8 * data, size_t length)
351 struct host_info *hi;
352 struct file_info *fi;
353 struct pending_request *req, *req_next;
354 struct iso_block_store *ibs = NULL;
357 if ((atomic_read(&iso_buffer_size) + length) > iso_buffer_max) {
358 HPSB_INFO("dropped fcp request");
362 spin_lock_irqsave(&host_info_lock, flags);
363 hi = find_host_info(host);
366 list_for_each_entry(fi, &hi->file_info_list, list) {
370 req = __alloc_pending_request(SLAB_ATOMIC);
375 ibs = kmalloc(sizeof(*ibs) + length,
382 atomic_add(length, &iso_buffer_size);
383 atomic_set(&ibs->refcount, 0);
384 ibs->data_size = length;
385 memcpy(ibs->data, data, length);
388 atomic_inc(&ibs->refcount);
392 req->data = ibs->data;
393 req->req.type = RAW1394_REQ_FCP_REQUEST;
394 req->req.generation = get_hpsb_generation(host);
395 req->req.misc = nodeid | (direction << 16);
396 req->req.recvb = ptr2int(fi->fcp_buffer);
397 req->req.length = length;
399 list_add_tail(&req->list, &reqs);
402 spin_unlock_irqrestore(&host_info_lock, flags);
404 list_for_each_entry_safe(req, req_next, &reqs, list)
405 queue_complete_req(req);
409 struct compat_raw1394_req {
423 } __attribute__((packed));
425 static const char __user *raw1394_compat_write(const char __user *buf)
427 struct compat_raw1394_req __user *cr = (typeof(cr)) buf;
428 struct raw1394_request __user *r;
429 r = compat_alloc_user_space(sizeof(struct raw1394_request));
431 #define C(x) __copy_in_user(&r->x, &cr->x, sizeof(r->x))
433 if (copy_in_user(r, cr, sizeof(struct compat_raw1394_req)) ||
438 return ERR_PTR(-EFAULT);
439 return (const char __user *)r;
443 #define P(x) __put_user(r->x, &cr->x)
446 raw1394_compat_read(const char __user *buf, struct raw1394_request *r)
448 struct compat_raw1394_req __user *cr = (typeof(cr)) r;
449 if (!access_ok(VERIFY_WRITE, cr, sizeof(struct compat_raw1394_req)) ||
460 return sizeof(struct compat_raw1394_req);
467 static ssize_t raw1394_read(struct file *file, char __user * buffer,
468 size_t count, loff_t * offset_is_ignored)
471 struct file_info *fi = (struct file_info *)file->private_data;
472 struct list_head *lh;
473 struct pending_request *req;
477 if (count == sizeof(struct compat_raw1394_req)) {
481 if (count != sizeof(struct raw1394_request)) {
485 if (!access_ok(VERIFY_WRITE, buffer, count)) {
489 if (file->f_flags & O_NONBLOCK) {
490 if (down_trylock(&fi->complete_sem)) {
494 if (down_interruptible(&fi->complete_sem)) {
499 spin_lock_irqsave(&fi->reqlists_lock, flags);
500 lh = fi->req_complete.next;
502 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
504 req = list_entry(lh, struct pending_request, list);
506 if (req->req.length) {
507 if (copy_to_user(int2ptr(req->req.recvb), req->data,
509 req->req.error = RAW1394_ERROR_MEMFAULT;
514 if (count == sizeof(struct compat_raw1394_req) &&
515 sizeof(struct compat_raw1394_req) !=
516 sizeof(struct raw1394_request)) {
517 ret = raw1394_compat_read(buffer, &req->req);
521 if (copy_to_user(buffer, &req->req, sizeof(req->req))) {
525 ret = (ssize_t) sizeof(struct raw1394_request);
528 free_pending_request(req);
532 static int state_opened(struct file_info *fi, struct pending_request *req)
534 if (req->req.type == RAW1394_REQ_INITIALIZE) {
535 switch (req->req.misc) {
536 case RAW1394_KERNELAPI_VERSION:
538 fi->state = initialized;
539 fi->protocol_version = req->req.misc;
540 req->req.error = RAW1394_ERROR_NONE;
541 req->req.generation = atomic_read(&internal_generation);
545 req->req.error = RAW1394_ERROR_COMPAT;
546 req->req.misc = RAW1394_KERNELAPI_VERSION;
549 req->req.error = RAW1394_ERROR_STATE_ORDER;
553 queue_complete_req(req);
554 return sizeof(struct raw1394_request);
557 static int state_initialized(struct file_info *fi, struct pending_request *req)
560 struct host_info *hi;
561 struct raw1394_khost_list *khl;
563 if (req->req.generation != atomic_read(&internal_generation)) {
564 req->req.error = RAW1394_ERROR_GENERATION;
565 req->req.generation = atomic_read(&internal_generation);
567 queue_complete_req(req);
568 return sizeof(struct raw1394_request);
571 switch (req->req.type) {
572 case RAW1394_REQ_LIST_CARDS:
573 spin_lock_irqsave(&host_info_lock, flags);
574 khl = kmalloc(sizeof(*khl) * host_count, SLAB_ATOMIC);
577 req->req.misc = host_count;
578 req->data = (quadlet_t *) khl;
580 list_for_each_entry(hi, &host_info_list, list) {
581 khl->nodes = hi->host->node_count;
582 strcpy(khl->name, hi->host->driver->name);
586 spin_unlock_irqrestore(&host_info_lock, flags);
589 req->req.error = RAW1394_ERROR_NONE;
590 req->req.length = min(req->req.length,
592 (struct raw1394_khost_list)
600 case RAW1394_REQ_SET_CARD:
601 spin_lock_irqsave(&host_info_lock, flags);
602 if (req->req.misc < host_count) {
603 list_for_each_entry(hi, &host_info_list, list) {
604 if (!req->req.misc--)
607 get_device(&hi->host->device); // XXX Need to handle failure case
608 list_add_tail(&fi->list, &hi->file_info_list);
610 fi->state = connected;
612 req->req.error = RAW1394_ERROR_NONE;
613 req->req.generation = get_hpsb_generation(fi->host);
614 req->req.misc = (fi->host->node_id << 16)
615 | fi->host->node_count;
616 if (fi->protocol_version > 3) {
618 NODEID_TO_NODE(fi->host->irm_id) << 8;
621 req->req.error = RAW1394_ERROR_INVALID_ARG;
623 spin_unlock_irqrestore(&host_info_lock, flags);
629 req->req.error = RAW1394_ERROR_STATE_ORDER;
634 queue_complete_req(req);
635 return sizeof(struct raw1394_request);
638 static void handle_iso_listen(struct file_info *fi, struct pending_request *req)
640 int channel = req->req.misc;
642 if ((channel > 63) || (channel < -64)) {
643 req->req.error = RAW1394_ERROR_INVALID_ARG;
644 } else if (channel >= 0) {
645 /* allocate channel req.misc */
646 if (fi->listen_channels & (1ULL << channel)) {
647 req->req.error = RAW1394_ERROR_ALREADY;
649 if (hpsb_listen_channel
650 (&raw1394_highlevel, fi->host, channel)) {
651 req->req.error = RAW1394_ERROR_ALREADY;
653 fi->listen_channels |= 1ULL << channel;
654 fi->iso_buffer = int2ptr(req->req.recvb);
655 fi->iso_buffer_length = req->req.length;
659 /* deallocate channel (one's complement neg) req.misc */
662 if (fi->listen_channels & (1ULL << channel)) {
663 hpsb_unlisten_channel(&raw1394_highlevel, fi->host,
665 fi->listen_channels &= ~(1ULL << channel);
667 req->req.error = RAW1394_ERROR_INVALID_ARG;
672 queue_complete_req(req);
675 static void handle_fcp_listen(struct file_info *fi, struct pending_request *req)
678 if (fi->fcp_buffer) {
679 req->req.error = RAW1394_ERROR_ALREADY;
681 fi->fcp_buffer = int2ptr(req->req.recvb);
684 if (!fi->fcp_buffer) {
685 req->req.error = RAW1394_ERROR_ALREADY;
687 fi->fcp_buffer = NULL;
692 queue_complete_req(req);
695 static int handle_async_request(struct file_info *fi,
696 struct pending_request *req, int node)
699 struct hpsb_packet *packet = NULL;
700 u64 addr = req->req.address & 0xffffffffffffULL;
702 switch (req->req.type) {
703 case RAW1394_REQ_ASYNC_READ:
704 DBGMSG("read_request called");
706 hpsb_make_readpacket(fi->host, node, addr, req->req.length);
711 if (req->req.length == 4)
712 req->data = &packet->header[3];
714 req->data = packet->data;
718 case RAW1394_REQ_ASYNC_WRITE:
719 DBGMSG("write_request called");
721 packet = hpsb_make_writepacket(fi->host, node, addr, NULL,
726 if (req->req.length == 4) {
728 (&packet->header[3], int2ptr(req->req.sendb),
730 req->req.error = RAW1394_ERROR_MEMFAULT;
733 (packet->data, int2ptr(req->req.sendb),
735 req->req.error = RAW1394_ERROR_MEMFAULT;
741 case RAW1394_REQ_ASYNC_STREAM:
742 DBGMSG("stream_request called");
745 hpsb_make_streampacket(fi->host, NULL, req->req.length,
746 node & 0x3f /*channel */ ,
747 (req->req.misc >> 16) & 0x3,
748 req->req.misc & 0xf);
752 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
754 req->req.error = RAW1394_ERROR_MEMFAULT;
759 case RAW1394_REQ_LOCK:
760 DBGMSG("lock_request called");
761 if ((req->req.misc == EXTCODE_FETCH_ADD)
762 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
763 if (req->req.length != 4) {
764 req->req.error = RAW1394_ERROR_INVALID_ARG;
768 if (req->req.length != 8) {
769 req->req.error = RAW1394_ERROR_INVALID_ARG;
774 packet = hpsb_make_lockpacket(fi->host, node, addr,
775 req->req.misc, NULL, 0);
779 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
781 req->req.error = RAW1394_ERROR_MEMFAULT;
785 req->data = packet->data;
789 case RAW1394_REQ_LOCK64:
790 DBGMSG("lock64_request called");
791 if ((req->req.misc == EXTCODE_FETCH_ADD)
792 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
793 if (req->req.length != 8) {
794 req->req.error = RAW1394_ERROR_INVALID_ARG;
798 if (req->req.length != 16) {
799 req->req.error = RAW1394_ERROR_INVALID_ARG;
803 packet = hpsb_make_lock64packet(fi->host, node, addr,
804 req->req.misc, NULL, 0);
808 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
810 req->req.error = RAW1394_ERROR_MEMFAULT;
814 req->data = packet->data;
819 req->req.error = RAW1394_ERROR_STATE_ORDER;
822 req->packet = packet;
824 if (req->req.error) {
826 queue_complete_req(req);
827 return sizeof(struct raw1394_request);
830 hpsb_set_packet_complete_task(packet,
831 (void (*)(void *))queue_complete_cb, req);
833 spin_lock_irqsave(&fi->reqlists_lock, flags);
834 list_add_tail(&req->list, &fi->req_pending);
835 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
837 packet->generation = req->req.generation;
839 if (hpsb_send_packet(packet) < 0) {
840 req->req.error = RAW1394_ERROR_SEND_ERROR;
842 hpsb_free_tlabel(packet);
843 queue_complete_req(req);
845 return sizeof(struct raw1394_request);
848 static int handle_iso_send(struct file_info *fi, struct pending_request *req,
852 struct hpsb_packet *packet;
854 packet = hpsb_make_isopacket(fi->host, req->req.length, channel & 0x3f,
855 (req->req.misc >> 16) & 0x3,
856 req->req.misc & 0xf);
860 packet->speed_code = req->req.address & 0x3;
862 req->packet = packet;
864 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
866 req->req.error = RAW1394_ERROR_MEMFAULT;
868 queue_complete_req(req);
869 return sizeof(struct raw1394_request);
873 hpsb_set_packet_complete_task(packet,
874 (void (*)(void *))queue_complete_req,
877 spin_lock_irqsave(&fi->reqlists_lock, flags);
878 list_add_tail(&req->list, &fi->req_pending);
879 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
881 /* Update the generation of the packet just before sending. */
882 packet->generation = req->req.generation;
884 if (hpsb_send_packet(packet) < 0) {
885 req->req.error = RAW1394_ERROR_SEND_ERROR;
886 queue_complete_req(req);
889 return sizeof(struct raw1394_request);
892 static int handle_async_send(struct file_info *fi, struct pending_request *req)
895 struct hpsb_packet *packet;
896 int header_length = req->req.misc & 0xffff;
897 int expect_response = req->req.misc >> 16;
899 if ((header_length > req->req.length) || (header_length < 12)) {
900 req->req.error = RAW1394_ERROR_INVALID_ARG;
902 queue_complete_req(req);
903 return sizeof(struct raw1394_request);
906 packet = hpsb_alloc_packet(req->req.length - header_length);
907 req->packet = packet;
911 if (copy_from_user(packet->header, int2ptr(req->req.sendb),
913 req->req.error = RAW1394_ERROR_MEMFAULT;
915 queue_complete_req(req);
916 return sizeof(struct raw1394_request);
920 (packet->data, int2ptr(req->req.sendb) + header_length,
921 packet->data_size)) {
922 req->req.error = RAW1394_ERROR_MEMFAULT;
924 queue_complete_req(req);
925 return sizeof(struct raw1394_request);
928 packet->type = hpsb_async;
929 packet->node_id = packet->header[0] >> 16;
930 packet->tcode = (packet->header[0] >> 4) & 0xf;
931 packet->tlabel = (packet->header[0] >> 10) & 0x3f;
932 packet->host = fi->host;
933 packet->expect_response = expect_response;
934 packet->header_size = header_length;
935 packet->data_size = req->req.length - header_length;
938 hpsb_set_packet_complete_task(packet,
939 (void (*)(void *))queue_complete_cb, req);
941 spin_lock_irqsave(&fi->reqlists_lock, flags);
942 list_add_tail(&req->list, &fi->req_pending);
943 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
945 /* Update the generation of the packet just before sending. */
946 packet->generation = req->req.generation;
948 if (hpsb_send_packet(packet) < 0) {
949 req->req.error = RAW1394_ERROR_SEND_ERROR;
950 queue_complete_req(req);
953 return sizeof(struct raw1394_request);
956 static int arm_read(struct hpsb_host *host, int nodeid, quadlet_t * buffer,
957 u64 addr, size_t length, u16 flags)
959 unsigned long irqflags;
960 struct pending_request *req;
961 struct host_info *hi;
962 struct file_info *fi = NULL;
963 struct list_head *entry;
964 struct arm_addr *arm_addr = NULL;
965 struct arm_request *arm_req = NULL;
966 struct arm_response *arm_resp = NULL;
967 int found = 0, size = 0, rcode = -1;
968 struct arm_request_response *arm_req_resp = NULL;
970 DBGMSG("arm_read called by node: %X"
971 "addr: %4.4x %8.8x length: %Zu", nodeid,
972 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
974 spin_lock_irqsave(&host_info_lock, irqflags);
975 hi = find_host_info(host); /* search address-entry */
977 list_for_each_entry(fi, &hi->file_info_list, list) {
978 entry = fi->addr_list.next;
979 while (entry != &(fi->addr_list)) {
981 list_entry(entry, struct arm_addr,
983 if (((arm_addr->start) <= (addr))
984 && ((arm_addr->end) >= (addr + length))) {
997 printk(KERN_ERR "raw1394: arm_read FAILED addr_entry not found"
998 " -> rcode_address_error\n");
999 spin_unlock_irqrestore(&host_info_lock, irqflags);
1000 return (RCODE_ADDRESS_ERROR);
1002 DBGMSG("arm_read addr_entry FOUND");
1004 if (arm_addr->rec_length < length) {
1005 DBGMSG("arm_read blocklength too big -> rcode_data_error");
1006 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
1009 if (arm_addr->access_rights & ARM_READ) {
1010 if (!(arm_addr->client_transactions & ARM_READ)) {
1012 (arm_addr->addr_space_buffer) + (addr -
1016 DBGMSG("arm_read -> (rcode_complete)");
1017 rcode = RCODE_COMPLETE;
1020 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1021 DBGMSG("arm_read -> rcode_type_error (access denied)");
1024 if (arm_addr->notification_options & ARM_READ) {
1025 DBGMSG("arm_read -> entering notification-section");
1026 req = __alloc_pending_request(SLAB_ATOMIC);
1028 DBGMSG("arm_read -> rcode_conflict_error");
1029 spin_unlock_irqrestore(&host_info_lock, irqflags);
1030 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1031 The request may be retried */
1033 if (rcode == RCODE_COMPLETE) {
1035 sizeof(struct arm_request) +
1036 sizeof(struct arm_response) +
1037 length * sizeof(byte_t) +
1038 sizeof(struct arm_request_response);
1041 sizeof(struct arm_request) +
1042 sizeof(struct arm_response) +
1043 sizeof(struct arm_request_response);
1045 req->data = kmalloc(size, SLAB_ATOMIC);
1047 free_pending_request(req);
1048 DBGMSG("arm_read -> rcode_conflict_error");
1049 spin_unlock_irqrestore(&host_info_lock, irqflags);
1050 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1051 The request may be retried */
1054 req->file_info = fi;
1055 req->req.type = RAW1394_REQ_ARM;
1056 req->req.generation = get_hpsb_generation(host);
1058 (((length << 16) & (0xFFFF0000)) | (ARM_READ & 0xFF));
1059 req->req.tag = arm_addr->arm_tag;
1060 req->req.recvb = arm_addr->recvb;
1061 req->req.length = size;
1062 arm_req_resp = (struct arm_request_response *)(req->data);
1063 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1066 arm_request_response)));
1068 (struct arm_response *)((byte_t *) (arm_req) +
1069 (sizeof(struct arm_request)));
1070 arm_req->buffer = NULL;
1071 arm_resp->buffer = NULL;
1072 if (rcode == RCODE_COMPLETE) {
1074 (byte_t *) arm_resp + sizeof(struct arm_response);
1076 (arm_addr->addr_space_buffer) + (addr -
1081 int2ptr((arm_addr->recvb) +
1082 sizeof(struct arm_request_response) +
1083 sizeof(struct arm_request) +
1084 sizeof(struct arm_response));
1086 arm_resp->buffer_length =
1087 (rcode == RCODE_COMPLETE) ? length : 0;
1088 arm_resp->response_code = rcode;
1089 arm_req->buffer_length = 0;
1090 arm_req->generation = req->req.generation;
1091 arm_req->extended_transaction_code = 0;
1092 arm_req->destination_offset = addr;
1093 arm_req->source_nodeid = nodeid;
1094 arm_req->destination_nodeid = host->node_id;
1095 arm_req->tlabel = (flags >> 10) & 0x3f;
1096 arm_req->tcode = (flags >> 4) & 0x0f;
1097 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1099 arm_request_response));
1100 arm_req_resp->response =
1101 int2ptr((arm_addr->recvb) +
1102 sizeof(struct arm_request_response) +
1103 sizeof(struct arm_request));
1104 queue_complete_req(req);
1106 spin_unlock_irqrestore(&host_info_lock, irqflags);
1110 static int arm_write(struct hpsb_host *host, int nodeid, int destid,
1111 quadlet_t * data, u64 addr, size_t length, u16 flags)
1113 unsigned long irqflags;
1114 struct pending_request *req;
1115 struct host_info *hi;
1116 struct file_info *fi = NULL;
1117 struct list_head *entry;
1118 struct arm_addr *arm_addr = NULL;
1119 struct arm_request *arm_req = NULL;
1120 struct arm_response *arm_resp = NULL;
1121 int found = 0, size = 0, rcode = -1, length_conflict = 0;
1122 struct arm_request_response *arm_req_resp = NULL;
1124 DBGMSG("arm_write called by node: %X"
1125 "addr: %4.4x %8.8x length: %Zu", nodeid,
1126 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
1128 spin_lock_irqsave(&host_info_lock, irqflags);
1129 hi = find_host_info(host); /* search address-entry */
1131 list_for_each_entry(fi, &hi->file_info_list, list) {
1132 entry = fi->addr_list.next;
1133 while (entry != &(fi->addr_list)) {
1135 list_entry(entry, struct arm_addr,
1137 if (((arm_addr->start) <= (addr))
1138 && ((arm_addr->end) >= (addr + length))) {
1142 entry = entry->next;
1151 printk(KERN_ERR "raw1394: arm_write FAILED addr_entry not found"
1152 " -> rcode_address_error\n");
1153 spin_unlock_irqrestore(&host_info_lock, irqflags);
1154 return (RCODE_ADDRESS_ERROR);
1156 DBGMSG("arm_write addr_entry FOUND");
1158 if (arm_addr->rec_length < length) {
1159 DBGMSG("arm_write blocklength too big -> rcode_data_error");
1160 length_conflict = 1;
1161 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
1164 if (arm_addr->access_rights & ARM_WRITE) {
1165 if (!(arm_addr->client_transactions & ARM_WRITE)) {
1166 memcpy((arm_addr->addr_space_buffer) +
1167 (addr - (arm_addr->start)), data,
1169 DBGMSG("arm_write -> (rcode_complete)");
1170 rcode = RCODE_COMPLETE;
1173 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1174 DBGMSG("arm_write -> rcode_type_error (access denied)");
1177 if (arm_addr->notification_options & ARM_WRITE) {
1178 DBGMSG("arm_write -> entering notification-section");
1179 req = __alloc_pending_request(SLAB_ATOMIC);
1181 DBGMSG("arm_write -> rcode_conflict_error");
1182 spin_unlock_irqrestore(&host_info_lock, irqflags);
1183 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1184 The request my be retried */
1187 sizeof(struct arm_request) + sizeof(struct arm_response) +
1188 (length) * sizeof(byte_t) +
1189 sizeof(struct arm_request_response);
1190 req->data = kmalloc(size, SLAB_ATOMIC);
1192 free_pending_request(req);
1193 DBGMSG("arm_write -> rcode_conflict_error");
1194 spin_unlock_irqrestore(&host_info_lock, irqflags);
1195 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1196 The request may be retried */
1199 req->file_info = fi;
1200 req->req.type = RAW1394_REQ_ARM;
1201 req->req.generation = get_hpsb_generation(host);
1203 (((length << 16) & (0xFFFF0000)) | (ARM_WRITE & 0xFF));
1204 req->req.tag = arm_addr->arm_tag;
1205 req->req.recvb = arm_addr->recvb;
1206 req->req.length = size;
1207 arm_req_resp = (struct arm_request_response *)(req->data);
1208 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1211 arm_request_response)));
1213 (struct arm_response *)((byte_t *) (arm_req) +
1214 (sizeof(struct arm_request)));
1215 arm_resp->buffer = NULL;
1216 memcpy((byte_t *) arm_resp + sizeof(struct arm_response),
1218 arm_req->buffer = int2ptr((arm_addr->recvb) +
1219 sizeof(struct arm_request_response) +
1220 sizeof(struct arm_request) +
1221 sizeof(struct arm_response));
1222 arm_req->buffer_length = length;
1223 arm_req->generation = req->req.generation;
1224 arm_req->extended_transaction_code = 0;
1225 arm_req->destination_offset = addr;
1226 arm_req->source_nodeid = nodeid;
1227 arm_req->destination_nodeid = destid;
1228 arm_req->tlabel = (flags >> 10) & 0x3f;
1229 arm_req->tcode = (flags >> 4) & 0x0f;
1230 arm_resp->buffer_length = 0;
1231 arm_resp->response_code = rcode;
1232 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1234 arm_request_response));
1235 arm_req_resp->response =
1236 int2ptr((arm_addr->recvb) +
1237 sizeof(struct arm_request_response) +
1238 sizeof(struct arm_request));
1239 queue_complete_req(req);
1241 spin_unlock_irqrestore(&host_info_lock, irqflags);
1245 static int arm_lock(struct hpsb_host *host, int nodeid, quadlet_t * store,
1246 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
1249 unsigned long irqflags;
1250 struct pending_request *req;
1251 struct host_info *hi;
1252 struct file_info *fi = NULL;
1253 struct list_head *entry;
1254 struct arm_addr *arm_addr = NULL;
1255 struct arm_request *arm_req = NULL;
1256 struct arm_response *arm_resp = NULL;
1257 int found = 0, size = 0, rcode = -1;
1259 struct arm_request_response *arm_req_resp = NULL;
1261 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1262 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1263 DBGMSG("arm_lock called by node: %X "
1264 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X",
1265 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1266 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1269 DBGMSG("arm_lock called by node: %X "
1270 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X arg: %8.8X",
1271 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1272 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1273 be32_to_cpu(data), be32_to_cpu(arg));
1275 spin_lock_irqsave(&host_info_lock, irqflags);
1276 hi = find_host_info(host); /* search address-entry */
1278 list_for_each_entry(fi, &hi->file_info_list, list) {
1279 entry = fi->addr_list.next;
1280 while (entry != &(fi->addr_list)) {
1282 list_entry(entry, struct arm_addr,
1284 if (((arm_addr->start) <= (addr))
1285 && ((arm_addr->end) >=
1286 (addr + sizeof(*store)))) {
1290 entry = entry->next;
1299 printk(KERN_ERR "raw1394: arm_lock FAILED addr_entry not found"
1300 " -> rcode_address_error\n");
1301 spin_unlock_irqrestore(&host_info_lock, irqflags);
1302 return (RCODE_ADDRESS_ERROR);
1304 DBGMSG("arm_lock addr_entry FOUND");
1307 if (arm_addr->access_rights & ARM_LOCK) {
1308 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1310 (arm_addr->addr_space_buffer) + (addr -
1314 switch (ext_tcode) {
1315 case (EXTCODE_MASK_SWAP):
1316 new = data | (old & ~arg);
1318 case (EXTCODE_COMPARE_SWAP):
1325 case (EXTCODE_FETCH_ADD):
1327 cpu_to_be32(be32_to_cpu(data) +
1330 case (EXTCODE_LITTLE_ADD):
1332 cpu_to_le32(le32_to_cpu(data) +
1335 case (EXTCODE_BOUNDED_ADD):
1338 cpu_to_be32(be32_to_cpu
1346 case (EXTCODE_WRAP_ADD):
1349 cpu_to_be32(be32_to_cpu
1358 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1360 "raw1394: arm_lock FAILED "
1361 "ext_tcode not allowed -> rcode_type_error\n");
1365 DBGMSG("arm_lock -> (rcode_complete)");
1366 rcode = RCODE_COMPLETE;
1367 memcpy(store, &old, sizeof(*store));
1368 memcpy((arm_addr->addr_space_buffer) +
1369 (addr - (arm_addr->start)),
1370 &new, sizeof(*store));
1374 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1375 DBGMSG("arm_lock -> rcode_type_error (access denied)");
1378 if (arm_addr->notification_options & ARM_LOCK) {
1379 byte_t *buf1, *buf2;
1380 DBGMSG("arm_lock -> entering notification-section");
1381 req = __alloc_pending_request(SLAB_ATOMIC);
1383 DBGMSG("arm_lock -> rcode_conflict_error");
1384 spin_unlock_irqrestore(&host_info_lock, irqflags);
1385 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1386 The request may be retried */
1388 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1389 req->data = kmalloc(size, SLAB_ATOMIC);
1391 free_pending_request(req);
1392 DBGMSG("arm_lock -> rcode_conflict_error");
1393 spin_unlock_irqrestore(&host_info_lock, irqflags);
1394 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1395 The request may be retried */
1398 arm_req_resp = (struct arm_request_response *)(req->data);
1399 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1402 arm_request_response)));
1404 (struct arm_response *)((byte_t *) (arm_req) +
1405 (sizeof(struct arm_request)));
1406 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1407 buf2 = buf1 + 2 * sizeof(*store);
1408 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1409 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1410 arm_req->buffer_length = sizeof(*store);
1411 memcpy(buf1, &data, sizeof(*store));
1414 arm_req->buffer_length = 2 * sizeof(*store);
1415 memcpy(buf1, &arg, sizeof(*store));
1416 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1418 if (rcode == RCODE_COMPLETE) {
1419 arm_resp->buffer_length = sizeof(*store);
1420 memcpy(buf2, &old, sizeof(*store));
1422 arm_resp->buffer_length = 0;
1424 req->file_info = fi;
1425 req->req.type = RAW1394_REQ_ARM;
1426 req->req.generation = get_hpsb_generation(host);
1427 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1429 req->req.tag = arm_addr->arm_tag;
1430 req->req.recvb = arm_addr->recvb;
1431 req->req.length = size;
1432 arm_req->generation = req->req.generation;
1433 arm_req->extended_transaction_code = ext_tcode;
1434 arm_req->destination_offset = addr;
1435 arm_req->source_nodeid = nodeid;
1436 arm_req->destination_nodeid = host->node_id;
1437 arm_req->tlabel = (flags >> 10) & 0x3f;
1438 arm_req->tcode = (flags >> 4) & 0x0f;
1439 arm_resp->response_code = rcode;
1440 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1442 arm_request_response));
1443 arm_req_resp->response =
1444 int2ptr((arm_addr->recvb) +
1445 sizeof(struct arm_request_response) +
1446 sizeof(struct arm_request));
1448 int2ptr((arm_addr->recvb) +
1449 sizeof(struct arm_request_response) +
1450 sizeof(struct arm_request) +
1451 sizeof(struct arm_response));
1453 int2ptr((arm_addr->recvb) +
1454 sizeof(struct arm_request_response) +
1455 sizeof(struct arm_request) +
1456 sizeof(struct arm_response) + 2 * sizeof(*store));
1457 queue_complete_req(req);
1459 spin_unlock_irqrestore(&host_info_lock, irqflags);
1463 static int arm_lock64(struct hpsb_host *host, int nodeid, octlet_t * store,
1464 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
1467 unsigned long irqflags;
1468 struct pending_request *req;
1469 struct host_info *hi;
1470 struct file_info *fi = NULL;
1471 struct list_head *entry;
1472 struct arm_addr *arm_addr = NULL;
1473 struct arm_request *arm_req = NULL;
1474 struct arm_response *arm_resp = NULL;
1475 int found = 0, size = 0, rcode = -1;
1477 struct arm_request_response *arm_req_resp = NULL;
1479 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1480 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1481 DBGMSG("arm_lock64 called by node: %X "
1482 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X ",
1483 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1484 (u32) (addr & 0xFFFFFFFF),
1486 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1487 (u32) (be64_to_cpu(data) & 0xFFFFFFFF));
1489 DBGMSG("arm_lock64 called by node: %X "
1490 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X arg: "
1492 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1493 (u32) (addr & 0xFFFFFFFF),
1495 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1496 (u32) (be64_to_cpu(data) & 0xFFFFFFFF),
1497 (u32) ((be64_to_cpu(arg) >> 32) & 0xFFFFFFFF),
1498 (u32) (be64_to_cpu(arg) & 0xFFFFFFFF));
1500 spin_lock_irqsave(&host_info_lock, irqflags);
1501 hi = find_host_info(host); /* search addressentry in file_info's for host */
1503 list_for_each_entry(fi, &hi->file_info_list, list) {
1504 entry = fi->addr_list.next;
1505 while (entry != &(fi->addr_list)) {
1507 list_entry(entry, struct arm_addr,
1509 if (((arm_addr->start) <= (addr))
1510 && ((arm_addr->end) >=
1511 (addr + sizeof(*store)))) {
1515 entry = entry->next;
1525 "raw1394: arm_lock64 FAILED addr_entry not found"
1526 " -> rcode_address_error\n");
1527 spin_unlock_irqrestore(&host_info_lock, irqflags);
1528 return (RCODE_ADDRESS_ERROR);
1530 DBGMSG("arm_lock64 addr_entry FOUND");
1533 if (arm_addr->access_rights & ARM_LOCK) {
1534 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1536 (arm_addr->addr_space_buffer) + (addr -
1540 switch (ext_tcode) {
1541 case (EXTCODE_MASK_SWAP):
1542 new = data | (old & ~arg);
1544 case (EXTCODE_COMPARE_SWAP):
1551 case (EXTCODE_FETCH_ADD):
1553 cpu_to_be64(be64_to_cpu(data) +
1556 case (EXTCODE_LITTLE_ADD):
1558 cpu_to_le64(le64_to_cpu(data) +
1561 case (EXTCODE_BOUNDED_ADD):
1564 cpu_to_be64(be64_to_cpu
1572 case (EXTCODE_WRAP_ADD):
1575 cpu_to_be64(be64_to_cpu
1585 "raw1394: arm_lock64 FAILED "
1586 "ext_tcode not allowed -> rcode_type_error\n");
1587 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1592 ("arm_lock64 -> (rcode_complete)");
1593 rcode = RCODE_COMPLETE;
1594 memcpy(store, &old, sizeof(*store));
1595 memcpy((arm_addr->addr_space_buffer) +
1596 (addr - (arm_addr->start)),
1597 &new, sizeof(*store));
1601 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1603 ("arm_lock64 -> rcode_type_error (access denied)");
1606 if (arm_addr->notification_options & ARM_LOCK) {
1607 byte_t *buf1, *buf2;
1608 DBGMSG("arm_lock64 -> entering notification-section");
1609 req = __alloc_pending_request(SLAB_ATOMIC);
1611 spin_unlock_irqrestore(&host_info_lock, irqflags);
1612 DBGMSG("arm_lock64 -> rcode_conflict_error");
1613 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1614 The request may be retried */
1616 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1617 req->data = kmalloc(size, SLAB_ATOMIC);
1619 free_pending_request(req);
1620 spin_unlock_irqrestore(&host_info_lock, irqflags);
1621 DBGMSG("arm_lock64 -> rcode_conflict_error");
1622 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1623 The request may be retried */
1626 arm_req_resp = (struct arm_request_response *)(req->data);
1627 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1630 arm_request_response)));
1632 (struct arm_response *)((byte_t *) (arm_req) +
1633 (sizeof(struct arm_request)));
1634 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1635 buf2 = buf1 + 2 * sizeof(*store);
1636 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1637 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1638 arm_req->buffer_length = sizeof(*store);
1639 memcpy(buf1, &data, sizeof(*store));
1642 arm_req->buffer_length = 2 * sizeof(*store);
1643 memcpy(buf1, &arg, sizeof(*store));
1644 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1646 if (rcode == RCODE_COMPLETE) {
1647 arm_resp->buffer_length = sizeof(*store);
1648 memcpy(buf2, &old, sizeof(*store));
1650 arm_resp->buffer_length = 0;
1652 req->file_info = fi;
1653 req->req.type = RAW1394_REQ_ARM;
1654 req->req.generation = get_hpsb_generation(host);
1655 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1657 req->req.tag = arm_addr->arm_tag;
1658 req->req.recvb = arm_addr->recvb;
1659 req->req.length = size;
1660 arm_req->generation = req->req.generation;
1661 arm_req->extended_transaction_code = ext_tcode;
1662 arm_req->destination_offset = addr;
1663 arm_req->source_nodeid = nodeid;
1664 arm_req->destination_nodeid = host->node_id;
1665 arm_req->tlabel = (flags >> 10) & 0x3f;
1666 arm_req->tcode = (flags >> 4) & 0x0f;
1667 arm_resp->response_code = rcode;
1668 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1670 arm_request_response));
1671 arm_req_resp->response =
1672 int2ptr((arm_addr->recvb) +
1673 sizeof(struct arm_request_response) +
1674 sizeof(struct arm_request));
1676 int2ptr((arm_addr->recvb) +
1677 sizeof(struct arm_request_response) +
1678 sizeof(struct arm_request) +
1679 sizeof(struct arm_response));
1681 int2ptr((arm_addr->recvb) +
1682 sizeof(struct arm_request_response) +
1683 sizeof(struct arm_request) +
1684 sizeof(struct arm_response) + 2 * sizeof(*store));
1685 queue_complete_req(req);
1687 spin_unlock_irqrestore(&host_info_lock, irqflags);
1691 static int arm_register(struct file_info *fi, struct pending_request *req)
1694 struct arm_addr *addr;
1695 struct host_info *hi;
1696 struct file_info *fi_hlp = NULL;
1697 struct list_head *entry;
1698 struct arm_addr *arm_addr = NULL;
1699 int same_host, another_host;
1700 unsigned long flags;
1702 DBGMSG("arm_register called "
1703 "addr(Offset): %8.8x %8.8x length: %u "
1704 "rights: %2.2X notify: %2.2X "
1705 "max_blk_len: %4.4X",
1706 (u32) ((req->req.address >> 32) & 0xFFFF),
1707 (u32) (req->req.address & 0xFFFFFFFF),
1708 req->req.length, ((req->req.misc >> 8) & 0xFF),
1709 (req->req.misc & 0xFF), ((req->req.misc >> 16) & 0xFFFF));
1710 /* check addressrange */
1711 if ((((req->req.address) & ~(0xFFFFFFFFFFFFULL)) != 0) ||
1712 (((req->req.address + req->req.length) & ~(0xFFFFFFFFFFFFULL)) !=
1714 req->req.length = 0;
1717 /* addr-list-entry for fileinfo */
1718 addr = kmalloc(sizeof(*addr), SLAB_KERNEL);
1720 req->req.length = 0;
1723 /* allocation of addr_space_buffer */
1724 addr->addr_space_buffer = vmalloc(req->req.length);
1725 if (!(addr->addr_space_buffer)) {
1727 req->req.length = 0;
1730 /* initialization of addr_space_buffer */
1731 if ((req->req.sendb) == (unsigned long)NULL) {
1733 memset(addr->addr_space_buffer, 0, req->req.length);
1735 /* init: user -> kernel */
1737 (addr->addr_space_buffer, int2ptr(req->req.sendb),
1739 vfree(addr->addr_space_buffer);
1744 INIT_LIST_HEAD(&addr->addr_list);
1745 addr->arm_tag = req->req.tag;
1746 addr->start = req->req.address;
1747 addr->end = req->req.address + req->req.length;
1748 addr->access_rights = (u8) (req->req.misc & 0x0F);
1749 addr->notification_options = (u8) ((req->req.misc >> 4) & 0x0F);
1750 addr->client_transactions = (u8) ((req->req.misc >> 8) & 0x0F);
1751 addr->access_rights |= addr->client_transactions;
1752 addr->notification_options |= addr->client_transactions;
1753 addr->recvb = req->req.recvb;
1754 addr->rec_length = (u16) ((req->req.misc >> 16) & 0xFFFF);
1755 spin_lock_irqsave(&host_info_lock, flags);
1756 hi = find_host_info(fi->host);
1759 /* same host with address-entry containing same addressrange ? */
1760 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1761 entry = fi_hlp->addr_list.next;
1762 while (entry != &(fi_hlp->addr_list)) {
1764 list_entry(entry, struct arm_addr, addr_list);
1765 if ((arm_addr->start == addr->start)
1766 && (arm_addr->end == addr->end)) {
1767 DBGMSG("same host ownes same "
1768 "addressrange -> EALREADY");
1772 entry = entry->next;
1779 /* addressrange occupied by same host */
1780 vfree(addr->addr_space_buffer);
1782 spin_unlock_irqrestore(&host_info_lock, flags);
1785 /* another host with valid address-entry containing same addressrange */
1786 list_for_each_entry(hi, &host_info_list, list) {
1787 if (hi->host != fi->host) {
1788 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1789 entry = fi_hlp->addr_list.next;
1790 while (entry != &(fi_hlp->addr_list)) {
1792 list_entry(entry, struct arm_addr,
1794 if ((arm_addr->start == addr->start)
1795 && (arm_addr->end == addr->end)) {
1797 ("another host ownes same "
1802 entry = entry->next;
1811 DBGMSG("another hosts entry is valid -> SUCCESS");
1812 if (copy_to_user(int2ptr(req->req.recvb),
1813 &addr->start, sizeof(u64))) {
1814 printk(KERN_ERR "raw1394: arm_register failed "
1815 " address-range-entry is invalid -> EFAULT !!!\n");
1816 vfree(addr->addr_space_buffer);
1818 spin_unlock_irqrestore(&host_info_lock, flags);
1821 free_pending_request(req); /* immediate success or fail */
1823 list_add_tail(&addr->addr_list, &fi->addr_list);
1824 spin_unlock_irqrestore(&host_info_lock, flags);
1825 return sizeof(struct raw1394_request);
1828 hpsb_register_addrspace(&raw1394_highlevel, fi->host, &arm_ops,
1830 req->req.address + req->req.length);
1833 list_add_tail(&addr->addr_list, &fi->addr_list);
1835 DBGMSG("arm_register failed errno: %d \n", retval);
1836 vfree(addr->addr_space_buffer);
1838 spin_unlock_irqrestore(&host_info_lock, flags);
1841 spin_unlock_irqrestore(&host_info_lock, flags);
1842 free_pending_request(req); /* immediate success or fail */
1843 return sizeof(struct raw1394_request);
1846 static int arm_unregister(struct file_info *fi, struct pending_request *req)
1850 struct list_head *entry;
1851 struct arm_addr *addr = NULL;
1852 struct host_info *hi;
1853 struct file_info *fi_hlp = NULL;
1854 struct arm_addr *arm_addr = NULL;
1856 unsigned long flags;
1858 DBGMSG("arm_Unregister called addr(Offset): "
1860 (u32) ((req->req.address >> 32) & 0xFFFF),
1861 (u32) (req->req.address & 0xFFFFFFFF));
1862 spin_lock_irqsave(&host_info_lock, flags);
1864 entry = fi->addr_list.next;
1865 while (entry != &(fi->addr_list)) {
1866 addr = list_entry(entry, struct arm_addr, addr_list);
1867 if (addr->start == req->req.address) {
1871 entry = entry->next;
1874 DBGMSG("arm_Unregister addr not found");
1875 spin_unlock_irqrestore(&host_info_lock, flags);
1878 DBGMSG("arm_Unregister addr found");
1880 /* another host with valid address-entry containing
1881 same addressrange */
1882 list_for_each_entry(hi, &host_info_list, list) {
1883 if (hi->host != fi->host) {
1884 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1885 entry = fi_hlp->addr_list.next;
1886 while (entry != &(fi_hlp->addr_list)) {
1887 arm_addr = list_entry(entry,
1890 if (arm_addr->start == addr->start) {
1891 DBGMSG("another host ownes "
1892 "same addressrange");
1896 entry = entry->next;
1905 DBGMSG("delete entry from list -> success");
1906 list_del(&addr->addr_list);
1907 vfree(addr->addr_space_buffer);
1909 free_pending_request(req); /* immediate success or fail */
1910 spin_unlock_irqrestore(&host_info_lock, flags);
1911 return sizeof(struct raw1394_request);
1914 hpsb_unregister_addrspace(&raw1394_highlevel, fi->host,
1917 printk(KERN_ERR "raw1394: arm_Unregister failed -> EINVAL\n");
1918 spin_unlock_irqrestore(&host_info_lock, flags);
1921 DBGMSG("delete entry from list -> success");
1922 list_del(&addr->addr_list);
1923 spin_unlock_irqrestore(&host_info_lock, flags);
1924 vfree(addr->addr_space_buffer);
1926 free_pending_request(req); /* immediate success or fail */
1927 return sizeof(struct raw1394_request);
1930 /* Copy data from ARM buffer(s) to user buffer. */
1931 static int arm_get_buf(struct file_info *fi, struct pending_request *req)
1933 struct arm_addr *arm_addr = NULL;
1934 unsigned long flags;
1935 unsigned long offset;
1937 struct list_head *entry;
1939 DBGMSG("arm_get_buf "
1940 "addr(Offset): %04X %08X length: %u",
1941 (u32) ((req->req.address >> 32) & 0xFFFF),
1942 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
1944 spin_lock_irqsave(&host_info_lock, flags);
1945 entry = fi->addr_list.next;
1946 while (entry != &(fi->addr_list)) {
1947 arm_addr = list_entry(entry, struct arm_addr, addr_list);
1948 if ((arm_addr->start <= req->req.address) &&
1949 (arm_addr->end > req->req.address)) {
1950 if (req->req.address + req->req.length <= arm_addr->end) {
1951 offset = req->req.address - arm_addr->start;
1954 ("arm_get_buf copy_to_user( %08X, %p, %u )",
1955 (u32) req->req.recvb,
1956 arm_addr->addr_space_buffer + offset,
1957 (u32) req->req.length);
1960 (int2ptr(req->req.recvb),
1961 arm_addr->addr_space_buffer + offset,
1963 spin_unlock_irqrestore(&host_info_lock,
1968 spin_unlock_irqrestore(&host_info_lock, flags);
1969 /* We have to free the request, because we
1970 * queue no response, and therefore nobody
1972 free_pending_request(req);
1973 return sizeof(struct raw1394_request);
1975 DBGMSG("arm_get_buf request exceeded mapping");
1976 spin_unlock_irqrestore(&host_info_lock, flags);
1980 entry = entry->next;
1982 spin_unlock_irqrestore(&host_info_lock, flags);
1986 /* Copy data from user buffer to ARM buffer(s). */
1987 static int arm_set_buf(struct file_info *fi, struct pending_request *req)
1989 struct arm_addr *arm_addr = NULL;
1990 unsigned long flags;
1991 unsigned long offset;
1993 struct list_head *entry;
1995 DBGMSG("arm_set_buf "
1996 "addr(Offset): %04X %08X length: %u",
1997 (u32) ((req->req.address >> 32) & 0xFFFF),
1998 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
2000 spin_lock_irqsave(&host_info_lock, flags);
2001 entry = fi->addr_list.next;
2002 while (entry != &(fi->addr_list)) {
2003 arm_addr = list_entry(entry, struct arm_addr, addr_list);
2004 if ((arm_addr->start <= req->req.address) &&
2005 (arm_addr->end > req->req.address)) {
2006 if (req->req.address + req->req.length <= arm_addr->end) {
2007 offset = req->req.address - arm_addr->start;
2010 ("arm_set_buf copy_from_user( %p, %08X, %u )",
2011 arm_addr->addr_space_buffer + offset,
2012 (u32) req->req.sendb,
2013 (u32) req->req.length);
2016 (arm_addr->addr_space_buffer + offset,
2017 int2ptr(req->req.sendb),
2019 spin_unlock_irqrestore(&host_info_lock,
2024 spin_unlock_irqrestore(&host_info_lock, flags);
2025 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2026 return sizeof(struct raw1394_request);
2028 DBGMSG("arm_set_buf request exceeded mapping");
2029 spin_unlock_irqrestore(&host_info_lock, flags);
2033 entry = entry->next;
2035 spin_unlock_irqrestore(&host_info_lock, flags);
2039 static int reset_notification(struct file_info *fi, struct pending_request *req)
2041 DBGMSG("reset_notification called - switch %s ",
2042 (req->req.misc == RAW1394_NOTIFY_OFF) ? "OFF" : "ON");
2043 if ((req->req.misc == RAW1394_NOTIFY_OFF) ||
2044 (req->req.misc == RAW1394_NOTIFY_ON)) {
2045 fi->notification = (u8) req->req.misc;
2046 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2047 return sizeof(struct raw1394_request);
2049 /* error EINVAL (22) invalid argument */
2053 static int write_phypacket(struct file_info *fi, struct pending_request *req)
2055 struct hpsb_packet *packet = NULL;
2058 unsigned long flags;
2060 data = be32_to_cpu((u32) req->req.sendb);
2061 DBGMSG("write_phypacket called - quadlet 0x%8.8x ", data);
2062 packet = hpsb_make_phypacket(fi->host, data);
2065 req->req.length = 0;
2066 req->packet = packet;
2067 hpsb_set_packet_complete_task(packet,
2068 (void (*)(void *))queue_complete_cb, req);
2069 spin_lock_irqsave(&fi->reqlists_lock, flags);
2070 list_add_tail(&req->list, &fi->req_pending);
2071 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2072 packet->generation = req->req.generation;
2073 retval = hpsb_send_packet(packet);
2074 DBGMSG("write_phypacket send_packet called => retval: %d ", retval);
2076 req->req.error = RAW1394_ERROR_SEND_ERROR;
2077 req->req.length = 0;
2078 queue_complete_req(req);
2080 return sizeof(struct raw1394_request);
2083 static int get_config_rom(struct file_info *fi, struct pending_request *req)
2085 int ret = sizeof(struct raw1394_request);
2086 quadlet_t *data = kmalloc(req->req.length, SLAB_KERNEL);
2093 csr1212_read(fi->host->csr.rom, CSR1212_CONFIG_ROM_SPACE_OFFSET,
2094 data, req->req.length);
2095 if (copy_to_user(int2ptr(req->req.recvb), data, req->req.length))
2098 (int2ptr(req->req.tag), &fi->host->csr.rom->cache_head->len,
2099 sizeof(fi->host->csr.rom->cache_head->len)))
2101 if (copy_to_user(int2ptr(req->req.address), &fi->host->csr.generation,
2102 sizeof(fi->host->csr.generation)))
2104 if (copy_to_user(int2ptr(req->req.sendb), &status, sizeof(status)))
2108 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2113 static int update_config_rom(struct file_info *fi, struct pending_request *req)
2115 int ret = sizeof(struct raw1394_request);
2116 quadlet_t *data = kmalloc(req->req.length, SLAB_KERNEL);
2119 if (copy_from_user(data, int2ptr(req->req.sendb), req->req.length)) {
2122 int status = hpsb_update_config_rom(fi->host,
2123 data, req->req.length,
2124 (unsigned char)req->req.
2127 (int2ptr(req->req.recvb), &status, sizeof(status)))
2132 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2138 static int modify_config_rom(struct file_info *fi, struct pending_request *req)
2140 struct csr1212_keyval *kv;
2141 struct csr1212_csr_rom_cache *cache;
2142 struct csr1212_dentry *dentry;
2146 if (req->req.misc == ~0) {
2147 if (req->req.length == 0)
2150 /* Find an unused slot */
2152 dr < RAW1394_MAX_USER_CSR_DIRS && fi->csr1212_dirs[dr];
2155 if (dr == RAW1394_MAX_USER_CSR_DIRS)
2158 fi->csr1212_dirs[dr] =
2159 csr1212_new_directory(CSR1212_KV_ID_VENDOR);
2160 if (!fi->csr1212_dirs[dr])
2164 if (!fi->csr1212_dirs[dr])
2167 /* Delete old stuff */
2169 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2170 dentry; dentry = dentry->next) {
2171 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2176 if (req->req.length == 0) {
2177 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2178 fi->csr1212_dirs[dr] = NULL;
2180 hpsb_update_config_rom_image(fi->host);
2181 free_pending_request(req);
2182 return sizeof(struct raw1394_request);
2186 cache = csr1212_rom_cache_malloc(0, req->req.length);
2188 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2189 fi->csr1212_dirs[dr] = NULL;
2193 cache->filled_head = kmalloc(sizeof(*cache->filled_head), GFP_KERNEL);
2194 if (!cache->filled_head) {
2195 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2196 fi->csr1212_dirs[dr] = NULL;
2197 CSR1212_FREE(cache);
2200 cache->filled_tail = cache->filled_head;
2202 if (copy_from_user(cache->data, int2ptr(req->req.sendb),
2204 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2205 fi->csr1212_dirs[dr] = NULL;
2208 cache->len = req->req.length;
2209 cache->filled_head->offset_start = 0;
2210 cache->filled_head->offset_end = cache->size - 1;
2212 cache->layout_head = cache->layout_tail = fi->csr1212_dirs[dr];
2214 ret = CSR1212_SUCCESS;
2215 /* parse all the items */
2216 for (kv = cache->layout_head; ret == CSR1212_SUCCESS && kv;
2218 ret = csr1212_parse_keyval(kv, cache);
2221 /* attach top level items to the root directory */
2223 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2224 ret == CSR1212_SUCCESS && dentry; dentry = dentry->next) {
2226 csr1212_attach_keyval_to_directory(fi->host->csr.
2231 if (ret == CSR1212_SUCCESS) {
2232 ret = hpsb_update_config_rom_image(fi->host);
2234 if (ret >= 0 && copy_to_user(int2ptr(req->req.recvb),
2240 kfree(cache->filled_head);
2241 CSR1212_FREE(cache);
2244 /* we have to free the request, because we queue no response,
2245 * and therefore nobody will free it */
2246 free_pending_request(req);
2247 return sizeof(struct raw1394_request);
2250 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2251 dentry; dentry = dentry->next) {
2252 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2256 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2257 fi->csr1212_dirs[dr] = NULL;
2262 static int state_connected(struct file_info *fi, struct pending_request *req)
2264 int node = req->req.address >> 48;
2266 req->req.error = RAW1394_ERROR_NONE;
2268 switch (req->req.type) {
2270 case RAW1394_REQ_ECHO:
2271 queue_complete_req(req);
2272 return sizeof(struct raw1394_request);
2274 case RAW1394_REQ_ISO_SEND:
2275 return handle_iso_send(fi, req, node);
2277 case RAW1394_REQ_ARM_REGISTER:
2278 return arm_register(fi, req);
2280 case RAW1394_REQ_ARM_UNREGISTER:
2281 return arm_unregister(fi, req);
2283 case RAW1394_REQ_ARM_SET_BUF:
2284 return arm_set_buf(fi, req);
2286 case RAW1394_REQ_ARM_GET_BUF:
2287 return arm_get_buf(fi, req);
2289 case RAW1394_REQ_RESET_NOTIFY:
2290 return reset_notification(fi, req);
2292 case RAW1394_REQ_ISO_LISTEN:
2293 handle_iso_listen(fi, req);
2294 return sizeof(struct raw1394_request);
2296 case RAW1394_REQ_FCP_LISTEN:
2297 handle_fcp_listen(fi, req);
2298 return sizeof(struct raw1394_request);
2300 case RAW1394_REQ_RESET_BUS:
2301 if (req->req.misc == RAW1394_LONG_RESET) {
2302 DBGMSG("busreset called (type: LONG)");
2303 hpsb_reset_bus(fi->host, LONG_RESET);
2304 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2305 return sizeof(struct raw1394_request);
2307 if (req->req.misc == RAW1394_SHORT_RESET) {
2308 DBGMSG("busreset called (type: SHORT)");
2309 hpsb_reset_bus(fi->host, SHORT_RESET);
2310 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2311 return sizeof(struct raw1394_request);
2313 /* error EINVAL (22) invalid argument */
2315 case RAW1394_REQ_GET_ROM:
2316 return get_config_rom(fi, req);
2318 case RAW1394_REQ_UPDATE_ROM:
2319 return update_config_rom(fi, req);
2321 case RAW1394_REQ_MODIFY_ROM:
2322 return modify_config_rom(fi, req);
2325 if (req->req.generation != get_hpsb_generation(fi->host)) {
2326 req->req.error = RAW1394_ERROR_GENERATION;
2327 req->req.generation = get_hpsb_generation(fi->host);
2328 req->req.length = 0;
2329 queue_complete_req(req);
2330 return sizeof(struct raw1394_request);
2333 switch (req->req.type) {
2334 case RAW1394_REQ_PHYPACKET:
2335 return write_phypacket(fi, req);
2336 case RAW1394_REQ_ASYNC_SEND:
2337 return handle_async_send(fi, req);
2340 if (req->req.length == 0) {
2341 req->req.error = RAW1394_ERROR_INVALID_ARG;
2342 queue_complete_req(req);
2343 return sizeof(struct raw1394_request);
2346 return handle_async_request(fi, req, node);
2349 static ssize_t raw1394_write(struct file *file, const char __user * buffer,
2350 size_t count, loff_t * offset_is_ignored)
2352 struct file_info *fi = (struct file_info *)file->private_data;
2353 struct pending_request *req;
2356 #ifdef CONFIG_COMPAT
2357 if (count == sizeof(struct compat_raw1394_req) &&
2358 sizeof(struct compat_raw1394_req) !=
2359 sizeof(struct raw1394_request)) {
2360 buffer = raw1394_compat_write(buffer);
2362 return PTR_ERR(buffer);
2365 if (count != sizeof(struct raw1394_request)) {
2369 req = alloc_pending_request();
2373 req->file_info = fi;
2375 if (copy_from_user(&req->req, buffer, sizeof(struct raw1394_request))) {
2376 free_pending_request(req);
2380 switch (fi->state) {
2382 retval = state_opened(fi, req);
2386 retval = state_initialized(fi, req);
2390 retval = state_connected(fi, req);
2395 free_pending_request(req);
2401 /* rawiso operations */
2403 /* check if any RAW1394_REQ_RAWISO_ACTIVITY event is already in the
2404 * completion queue (reqlists_lock must be taken) */
2405 static inline int __rawiso_event_in_queue(struct file_info *fi)
2407 struct pending_request *req;
2409 list_for_each_entry(req, &fi->req_complete, list)
2410 if (req->req.type == RAW1394_REQ_RAWISO_ACTIVITY)
2416 /* put a RAWISO_ACTIVITY event in the queue, if one isn't there already */
2417 static void queue_rawiso_event(struct file_info *fi)
2419 unsigned long flags;
2421 spin_lock_irqsave(&fi->reqlists_lock, flags);
2423 /* only one ISO activity event may be in the queue */
2424 if (!__rawiso_event_in_queue(fi)) {
2425 struct pending_request *req =
2426 __alloc_pending_request(SLAB_ATOMIC);
2429 req->file_info = fi;
2430 req->req.type = RAW1394_REQ_RAWISO_ACTIVITY;
2431 req->req.generation = get_hpsb_generation(fi->host);
2432 __queue_complete_req(req);
2434 /* on allocation failure, signal an overflow */
2435 if (fi->iso_handle) {
2436 atomic_inc(&fi->iso_handle->overflows);
2440 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2443 static void rawiso_activity_cb(struct hpsb_iso *iso)
2445 unsigned long flags;
2446 struct host_info *hi;
2447 struct file_info *fi;
2449 spin_lock_irqsave(&host_info_lock, flags);
2450 hi = find_host_info(iso->host);
2453 list_for_each_entry(fi, &hi->file_info_list, list) {
2454 if (fi->iso_handle == iso)
2455 queue_rawiso_event(fi);
2459 spin_unlock_irqrestore(&host_info_lock, flags);
2462 /* helper function - gather all the kernel iso status bits for returning to user-space */
2463 static void raw1394_iso_fill_status(struct hpsb_iso *iso,
2464 struct raw1394_iso_status *stat)
2466 stat->config.data_buf_size = iso->buf_size;
2467 stat->config.buf_packets = iso->buf_packets;
2468 stat->config.channel = iso->channel;
2469 stat->config.speed = iso->speed;
2470 stat->config.irq_interval = iso->irq_interval;
2471 stat->n_packets = hpsb_iso_n_ready(iso);
2472 stat->overflows = atomic_read(&iso->overflows);
2473 stat->xmit_cycle = iso->xmit_cycle;
2476 static int raw1394_iso_xmit_init(struct file_info *fi, void __user * uaddr)
2478 struct raw1394_iso_status stat;
2483 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2486 fi->iso_handle = hpsb_iso_xmit_init(fi->host,
2487 stat.config.data_buf_size,
2488 stat.config.buf_packets,
2489 stat.config.channel,
2491 stat.config.irq_interval,
2492 rawiso_activity_cb);
2493 if (!fi->iso_handle)
2496 fi->iso_state = RAW1394_ISO_XMIT;
2498 raw1394_iso_fill_status(fi->iso_handle, &stat);
2499 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2502 /* queue an event to get things started */
2503 rawiso_activity_cb(fi->iso_handle);
2508 static int raw1394_iso_recv_init(struct file_info *fi, void __user * uaddr)
2510 struct raw1394_iso_status stat;
2515 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2518 fi->iso_handle = hpsb_iso_recv_init(fi->host,
2519 stat.config.data_buf_size,
2520 stat.config.buf_packets,
2521 stat.config.channel,
2522 stat.config.dma_mode,
2523 stat.config.irq_interval,
2524 rawiso_activity_cb);
2525 if (!fi->iso_handle)
2528 fi->iso_state = RAW1394_ISO_RECV;
2530 raw1394_iso_fill_status(fi->iso_handle, &stat);
2531 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2536 static int raw1394_iso_get_status(struct file_info *fi, void __user * uaddr)
2538 struct raw1394_iso_status stat;
2539 struct hpsb_iso *iso = fi->iso_handle;
2541 raw1394_iso_fill_status(fi->iso_handle, &stat);
2542 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2545 /* reset overflow counter */
2546 atomic_set(&iso->overflows, 0);
2551 /* copy N packet_infos out of the ringbuffer into user-supplied array */
2552 static int raw1394_iso_recv_packets(struct file_info *fi, void __user * uaddr)
2554 struct raw1394_iso_packets upackets;
2555 unsigned int packet = fi->iso_handle->first_packet;
2558 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2561 if (upackets.n_packets > hpsb_iso_n_ready(fi->iso_handle))
2564 /* ensure user-supplied buffer is accessible and big enough */
2565 if (!access_ok(VERIFY_WRITE, upackets.infos,
2566 upackets.n_packets *
2567 sizeof(struct raw1394_iso_packet_info)))
2570 /* copy the packet_infos out */
2571 for (i = 0; i < upackets.n_packets; i++) {
2572 if (__copy_to_user(&upackets.infos[i],
2573 &fi->iso_handle->infos[packet],
2574 sizeof(struct raw1394_iso_packet_info)))
2577 packet = (packet + 1) % fi->iso_handle->buf_packets;
2583 /* copy N packet_infos from user to ringbuffer, and queue them for transmission */
2584 static int raw1394_iso_send_packets(struct file_info *fi, void __user * uaddr)
2586 struct raw1394_iso_packets upackets;
2589 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2592 if (upackets.n_packets >= fi->iso_handle->buf_packets)
2595 if (upackets.n_packets >= hpsb_iso_n_ready(fi->iso_handle))
2598 /* ensure user-supplied buffer is accessible and big enough */
2599 if (!access_ok(VERIFY_READ, upackets.infos,
2600 upackets.n_packets *
2601 sizeof(struct raw1394_iso_packet_info)))
2604 /* copy the infos structs in and queue the packets */
2605 for (i = 0; i < upackets.n_packets; i++) {
2606 struct raw1394_iso_packet_info info;
2608 if (__copy_from_user(&info, &upackets.infos[i],
2609 sizeof(struct raw1394_iso_packet_info)))
2612 rv = hpsb_iso_xmit_queue_packet(fi->iso_handle, info.offset,
2613 info.len, info.tag, info.sy);
2621 static void raw1394_iso_shutdown(struct file_info *fi)
2624 hpsb_iso_shutdown(fi->iso_handle);
2626 fi->iso_handle = NULL;
2627 fi->iso_state = RAW1394_ISO_INACTIVE;
2630 /* mmap the rawiso xmit/recv buffer */
2631 static int raw1394_mmap(struct file *file, struct vm_area_struct *vma)
2633 struct file_info *fi = file->private_data;
2635 if (fi->iso_state == RAW1394_ISO_INACTIVE)
2638 return dma_region_mmap(&fi->iso_handle->data_buf, file, vma);
2641 /* ioctl is only used for rawiso operations */
2642 static int raw1394_ioctl(struct inode *inode, struct file *file,
2643 unsigned int cmd, unsigned long arg)
2645 struct file_info *fi = file->private_data;
2646 void __user *argp = (void __user *)arg;
2648 switch (fi->iso_state) {
2649 case RAW1394_ISO_INACTIVE:
2651 case RAW1394_IOC_ISO_XMIT_INIT:
2652 return raw1394_iso_xmit_init(fi, argp);
2653 case RAW1394_IOC_ISO_RECV_INIT:
2654 return raw1394_iso_recv_init(fi, argp);
2659 case RAW1394_ISO_RECV:
2661 case RAW1394_IOC_ISO_RECV_START:{
2662 /* copy args from user-space */
2665 (&args[0], argp, sizeof(args)))
2667 return hpsb_iso_recv_start(fi->iso_handle,
2671 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2672 hpsb_iso_stop(fi->iso_handle);
2674 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL:
2675 return hpsb_iso_recv_listen_channel(fi->iso_handle,
2677 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
2678 return hpsb_iso_recv_unlisten_channel(fi->iso_handle,
2680 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:{
2681 /* copy the u64 from user-space */
2683 if (copy_from_user(&mask, argp, sizeof(mask)))
2685 return hpsb_iso_recv_set_channel_mask(fi->
2689 case RAW1394_IOC_ISO_GET_STATUS:
2690 return raw1394_iso_get_status(fi, argp);
2691 case RAW1394_IOC_ISO_RECV_PACKETS:
2692 return raw1394_iso_recv_packets(fi, argp);
2693 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
2694 return hpsb_iso_recv_release_packets(fi->iso_handle,
2696 case RAW1394_IOC_ISO_RECV_FLUSH:
2697 return hpsb_iso_recv_flush(fi->iso_handle);
2698 case RAW1394_IOC_ISO_SHUTDOWN:
2699 raw1394_iso_shutdown(fi);
2701 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2702 queue_rawiso_event(fi);
2706 case RAW1394_ISO_XMIT:
2708 case RAW1394_IOC_ISO_XMIT_START:{
2709 /* copy two ints from user-space */
2712 (&args[0], argp, sizeof(args)))
2714 return hpsb_iso_xmit_start(fi->iso_handle,
2717 case RAW1394_IOC_ISO_XMIT_SYNC:
2718 return hpsb_iso_xmit_sync(fi->iso_handle);
2719 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2720 hpsb_iso_stop(fi->iso_handle);
2722 case RAW1394_IOC_ISO_GET_STATUS:
2723 return raw1394_iso_get_status(fi, argp);
2724 case RAW1394_IOC_ISO_XMIT_PACKETS:
2725 return raw1394_iso_send_packets(fi, argp);
2726 case RAW1394_IOC_ISO_SHUTDOWN:
2727 raw1394_iso_shutdown(fi);
2729 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2730 queue_rawiso_event(fi);
2741 static unsigned int raw1394_poll(struct file *file, poll_table * pt)
2743 struct file_info *fi = file->private_data;
2744 unsigned int mask = POLLOUT | POLLWRNORM;
2745 unsigned long flags;
2747 poll_wait(file, &fi->poll_wait_complete, pt);
2749 spin_lock_irqsave(&fi->reqlists_lock, flags);
2750 if (!list_empty(&fi->req_complete)) {
2751 mask |= POLLIN | POLLRDNORM;
2753 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2758 static int raw1394_open(struct inode *inode, struct file *file)
2760 struct file_info *fi;
2762 fi = kzalloc(sizeof(*fi), SLAB_KERNEL);
2766 fi->notification = (u8) RAW1394_NOTIFY_ON; /* busreset notification */
2768 INIT_LIST_HEAD(&fi->list);
2770 INIT_LIST_HEAD(&fi->req_pending);
2771 INIT_LIST_HEAD(&fi->req_complete);
2772 sema_init(&fi->complete_sem, 0);
2773 spin_lock_init(&fi->reqlists_lock);
2774 init_waitqueue_head(&fi->poll_wait_complete);
2775 INIT_LIST_HEAD(&fi->addr_list);
2777 file->private_data = fi;
2782 static int raw1394_release(struct inode *inode, struct file *file)
2784 struct file_info *fi = file->private_data;
2785 struct list_head *lh;
2786 struct pending_request *req;
2787 int done = 0, i, fail = 0;
2789 struct list_head *entry;
2790 struct arm_addr *addr = NULL;
2791 struct host_info *hi;
2792 struct file_info *fi_hlp = NULL;
2793 struct arm_addr *arm_addr = NULL;
2796 unsigned long flags;
2798 if (fi->iso_state != RAW1394_ISO_INACTIVE)
2799 raw1394_iso_shutdown(fi);
2801 for (i = 0; i < 64; i++) {
2802 if (fi->listen_channels & (1ULL << i)) {
2803 hpsb_unlisten_channel(&raw1394_highlevel, fi->host, i);
2807 spin_lock_irqsave(&host_info_lock, flags);
2808 fi->listen_channels = 0;
2811 /* set address-entries invalid */
2813 while (!list_empty(&fi->addr_list)) {
2815 lh = fi->addr_list.next;
2816 addr = list_entry(lh, struct arm_addr, addr_list);
2817 /* another host with valid address-entry containing
2818 same addressrange? */
2819 list_for_each_entry(hi, &host_info_list, list) {
2820 if (hi->host != fi->host) {
2821 list_for_each_entry(fi_hlp, &hi->file_info_list,
2823 entry = fi_hlp->addr_list.next;
2824 while (entry != &(fi_hlp->addr_list)) {
2825 arm_addr = list_entry(entry, struct
2828 if (arm_addr->start ==
2831 ("raw1394_release: "
2832 "another host ownes "
2833 "same addressrange");
2837 entry = entry->next;
2845 if (!another_host) {
2846 DBGMSG("raw1394_release: call hpsb_arm_unregister");
2848 hpsb_unregister_addrspace(&raw1394_highlevel,
2849 fi->host, addr->start);
2853 "raw1394_release arm_Unregister failed\n");
2856 DBGMSG("raw1394_release: delete addr_entry from list");
2857 list_del(&addr->addr_list);
2858 vfree(addr->addr_space_buffer);
2861 spin_unlock_irqrestore(&host_info_lock, flags);
2863 printk(KERN_ERR "raw1394: during addr_list-release "
2864 "error(s) occurred \n");
2868 spin_lock_irqsave(&fi->reqlists_lock, flags);
2870 while (!list_empty(&fi->req_complete)) {
2871 lh = fi->req_complete.next;
2874 req = list_entry(lh, struct pending_request, list);
2876 free_pending_request(req);
2879 if (list_empty(&fi->req_pending))
2882 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2885 down_interruptible(&fi->complete_sem);
2888 /* Remove any sub-trees left by user space programs */
2889 for (i = 0; i < RAW1394_MAX_USER_CSR_DIRS; i++) {
2890 struct csr1212_dentry *dentry;
2891 if (!fi->csr1212_dirs[i])
2894 fi->csr1212_dirs[i]->value.directory.dentries_head; dentry;
2895 dentry = dentry->next) {
2896 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2900 csr1212_release_keyval(fi->csr1212_dirs[i]);
2901 fi->csr1212_dirs[i] = NULL;
2905 if ((csr_mod || fi->cfgrom_upd)
2906 && hpsb_update_config_rom_image(fi->host) < 0)
2908 ("Failed to generate Configuration ROM image for host %d",
2911 if (fi->state == connected) {
2912 spin_lock_irqsave(&host_info_lock, flags);
2913 list_del(&fi->list);
2914 spin_unlock_irqrestore(&host_info_lock, flags);
2916 put_device(&fi->host->device);
2924 /*** HOTPLUG STUFF **********************************************************/
2926 * Export information about protocols/devices supported by this driver.
2928 static struct ieee1394_device_id raw1394_id_table[] = {
2930 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2931 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
2932 .version = AVC_SW_VERSION_ENTRY & 0xffffff},
2934 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2935 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2936 .version = CAMERA_SW_VERSION_ENTRY & 0xffffff},
2938 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2939 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2940 .version = (CAMERA_SW_VERSION_ENTRY + 1) & 0xffffff},
2942 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2943 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2944 .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff},
2948 MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table);
2950 static struct hpsb_protocol_driver raw1394_driver = {
2951 .name = "raw1394 Driver",
2952 .id_table = raw1394_id_table,
2955 .bus = &ieee1394_bus_type,
2959 /******************************************************************************/
2961 static struct hpsb_highlevel raw1394_highlevel = {
2962 .name = RAW1394_DEVICE_NAME,
2963 .add_host = add_host,
2964 .remove_host = remove_host,
2965 .host_reset = host_reset,
2966 .iso_receive = iso_receive,
2967 .fcp_request = fcp_request,
2970 static struct cdev raw1394_cdev;
2971 static struct file_operations raw1394_fops = {
2972 .owner = THIS_MODULE,
2973 .read = raw1394_read,
2974 .write = raw1394_write,
2975 .mmap = raw1394_mmap,
2976 .ioctl = raw1394_ioctl,
2977 // .compat_ioctl = ... someone needs to do this
2978 .poll = raw1394_poll,
2979 .open = raw1394_open,
2980 .release = raw1394_release,
2983 static int __init init_raw1394(void)
2987 hpsb_register_highlevel(&raw1394_highlevel);
2990 (class_device_create
2991 (hpsb_protocol_class, NULL,
2992 MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16), NULL,
2993 RAW1394_DEVICE_NAME))) {
2998 cdev_init(&raw1394_cdev, &raw1394_fops);
2999 raw1394_cdev.owner = THIS_MODULE;
3000 kobject_set_name(&raw1394_cdev.kobj, RAW1394_DEVICE_NAME);
3001 ret = cdev_add(&raw1394_cdev, IEEE1394_RAW1394_DEV, 1);
3003 HPSB_ERR("raw1394 failed to register minor device block");
3007 HPSB_INFO("raw1394: /dev/%s device initialized", RAW1394_DEVICE_NAME);
3009 ret = hpsb_register_protocol(&raw1394_driver);
3011 HPSB_ERR("raw1394: failed to register protocol");
3012 cdev_del(&raw1394_cdev);
3019 class_device_destroy(hpsb_protocol_class,
3020 MKDEV(IEEE1394_MAJOR,
3021 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
3023 hpsb_unregister_highlevel(&raw1394_highlevel);
3028 static void __exit cleanup_raw1394(void)
3030 class_device_destroy(hpsb_protocol_class,
3031 MKDEV(IEEE1394_MAJOR,
3032 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
3033 cdev_del(&raw1394_cdev);
3034 hpsb_unregister_highlevel(&raw1394_highlevel);
3035 hpsb_unregister_protocol(&raw1394_driver);
3038 module_init(init_raw1394);
3039 module_exit(cleanup_raw1394);
3040 MODULE_LICENSE("GPL");