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_del(&req->list);
136 list_add_tail(&req->list, &fi->req_complete);
138 up(&fi->complete_sem);
139 wake_up_interruptible(&fi->poll_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(SLAB_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 iso_receive(struct hpsb_host *host, int channel, quadlet_t * data,
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 iso packet");
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) {
307 if (!(fi->listen_channels & (1ULL << channel)))
310 req = __alloc_pending_request(SLAB_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_ISO_RECEIVE;
334 req->req.generation = get_hpsb_generation(host);
336 req->req.recvb = ptr2int(fi->iso_buffer);
337 req->req.length = min(length, fi->iso_buffer_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);
348 static void fcp_request(struct hpsb_host *host, int nodeid, int direction,
349 int cts, u8 * data, size_t length)
352 struct host_info *hi;
353 struct file_info *fi;
354 struct pending_request *req, *req_next;
355 struct iso_block_store *ibs = NULL;
358 if ((atomic_read(&iso_buffer_size) + length) > iso_buffer_max) {
359 HPSB_INFO("dropped fcp request");
363 spin_lock_irqsave(&host_info_lock, flags);
364 hi = find_host_info(host);
367 list_for_each_entry(fi, &hi->file_info_list, list) {
371 req = __alloc_pending_request(SLAB_ATOMIC);
376 ibs = kmalloc(sizeof(*ibs) + length,
383 atomic_add(length, &iso_buffer_size);
384 atomic_set(&ibs->refcount, 0);
385 ibs->data_size = length;
386 memcpy(ibs->data, data, length);
389 atomic_inc(&ibs->refcount);
393 req->data = ibs->data;
394 req->req.type = RAW1394_REQ_FCP_REQUEST;
395 req->req.generation = get_hpsb_generation(host);
396 req->req.misc = nodeid | (direction << 16);
397 req->req.recvb = ptr2int(fi->fcp_buffer);
398 req->req.length = length;
400 list_add_tail(&req->list, &reqs);
403 spin_unlock_irqrestore(&host_info_lock, flags);
405 list_for_each_entry_safe(req, req_next, &reqs, list)
406 queue_complete_req(req);
410 struct compat_raw1394_req {
424 } __attribute__((packed));
426 static const char __user *raw1394_compat_write(const char __user *buf)
428 struct compat_raw1394_req __user *cr = (typeof(cr)) buf;
429 struct raw1394_request __user *r;
430 r = compat_alloc_user_space(sizeof(struct raw1394_request));
432 #define C(x) __copy_in_user(&r->x, &cr->x, sizeof(r->x))
434 if (copy_in_user(r, cr, sizeof(struct compat_raw1394_req)) ||
439 return ERR_PTR(-EFAULT);
440 return (const char __user *)r;
444 #define P(x) __put_user(r->x, &cr->x)
447 raw1394_compat_read(const char __user *buf, struct raw1394_request *r)
449 struct compat_raw1394_req __user *cr = (typeof(cr)) r;
450 if (!access_ok(VERIFY_WRITE,cr,sizeof(struct compat_raw1394_req)) ||
461 return sizeof(struct compat_raw1394_req);
468 static ssize_t raw1394_read(struct file *file, char __user * buffer,
469 size_t count, loff_t * offset_is_ignored)
472 struct file_info *fi = (struct file_info *)file->private_data;
473 struct list_head *lh;
474 struct pending_request *req;
478 if (count == sizeof(struct compat_raw1394_req)) {
482 if (count != sizeof(struct raw1394_request)) {
486 if (!access_ok(VERIFY_WRITE, buffer, count)) {
490 if (file->f_flags & O_NONBLOCK) {
491 if (down_trylock(&fi->complete_sem)) {
495 if (down_interruptible(&fi->complete_sem)) {
500 spin_lock_irqsave(&fi->reqlists_lock, flags);
501 lh = fi->req_complete.next;
503 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
505 req = list_entry(lh, struct pending_request, list);
507 if (req->req.length) {
508 if (copy_to_user(int2ptr(req->req.recvb), req->data,
510 req->req.error = RAW1394_ERROR_MEMFAULT;
515 if (count == sizeof(struct compat_raw1394_req) &&
516 sizeof(struct compat_raw1394_req) !=
517 sizeof(struct raw1394_request)) {
518 ret = raw1394_compat_read(buffer, &req->req);
523 if (copy_to_user(buffer, &req->req, sizeof(req->req))) {
527 ret = (ssize_t) sizeof(struct raw1394_request);
530 free_pending_request(req);
534 static int state_opened(struct file_info *fi, struct pending_request *req)
536 if (req->req.type == RAW1394_REQ_INITIALIZE) {
537 switch (req->req.misc) {
538 case RAW1394_KERNELAPI_VERSION:
540 fi->state = initialized;
541 fi->protocol_version = req->req.misc;
542 req->req.error = RAW1394_ERROR_NONE;
543 req->req.generation = atomic_read(&internal_generation);
547 req->req.error = RAW1394_ERROR_COMPAT;
548 req->req.misc = RAW1394_KERNELAPI_VERSION;
551 req->req.error = RAW1394_ERROR_STATE_ORDER;
555 queue_complete_req(req);
556 return sizeof(struct raw1394_request);
559 static int state_initialized(struct file_info *fi, struct pending_request *req)
562 struct host_info *hi;
563 struct raw1394_khost_list *khl;
565 if (req->req.generation != atomic_read(&internal_generation)) {
566 req->req.error = RAW1394_ERROR_GENERATION;
567 req->req.generation = atomic_read(&internal_generation);
569 queue_complete_req(req);
570 return sizeof(struct raw1394_request);
573 switch (req->req.type) {
574 case RAW1394_REQ_LIST_CARDS:
575 spin_lock_irqsave(&host_info_lock, flags);
576 khl = kmalloc(sizeof(*khl) * host_count, SLAB_ATOMIC);
579 req->req.misc = host_count;
580 req->data = (quadlet_t *) khl;
582 list_for_each_entry(hi, &host_info_list, list) {
583 khl->nodes = hi->host->node_count;
584 strcpy(khl->name, hi->host->driver->name);
588 spin_unlock_irqrestore(&host_info_lock, flags);
591 req->req.error = RAW1394_ERROR_NONE;
592 req->req.length = min(req->req.length,
594 (struct raw1394_khost_list)
602 case RAW1394_REQ_SET_CARD:
603 spin_lock_irqsave(&host_info_lock, flags);
604 if (req->req.misc < host_count) {
605 list_for_each_entry(hi, &host_info_list, list) {
606 if (!req->req.misc--)
609 get_device(&hi->host->device); // XXX Need to handle failure case
610 list_add_tail(&fi->list, &hi->file_info_list);
612 fi->state = connected;
614 req->req.error = RAW1394_ERROR_NONE;
615 req->req.generation = get_hpsb_generation(fi->host);
616 req->req.misc = (fi->host->node_id << 16)
617 | fi->host->node_count;
618 if (fi->protocol_version > 3) {
620 NODEID_TO_NODE(fi->host->irm_id) << 8;
623 req->req.error = RAW1394_ERROR_INVALID_ARG;
625 spin_unlock_irqrestore(&host_info_lock, flags);
631 req->req.error = RAW1394_ERROR_STATE_ORDER;
636 queue_complete_req(req);
637 return sizeof(struct raw1394_request);
640 static void handle_iso_listen(struct file_info *fi, struct pending_request *req)
642 int channel = req->req.misc;
644 if ((channel > 63) || (channel < -64)) {
645 req->req.error = RAW1394_ERROR_INVALID_ARG;
646 } else if (channel >= 0) {
647 /* allocate channel req.misc */
648 if (fi->listen_channels & (1ULL << channel)) {
649 req->req.error = RAW1394_ERROR_ALREADY;
651 if (hpsb_listen_channel
652 (&raw1394_highlevel, fi->host, channel)) {
653 req->req.error = RAW1394_ERROR_ALREADY;
655 fi->listen_channels |= 1ULL << channel;
656 fi->iso_buffer = int2ptr(req->req.recvb);
657 fi->iso_buffer_length = req->req.length;
661 /* deallocate channel (one's complement neg) req.misc */
664 if (fi->listen_channels & (1ULL << channel)) {
665 hpsb_unlisten_channel(&raw1394_highlevel, fi->host,
667 fi->listen_channels &= ~(1ULL << channel);
669 req->req.error = RAW1394_ERROR_INVALID_ARG;
674 queue_complete_req(req);
677 static void handle_fcp_listen(struct file_info *fi, struct pending_request *req)
680 if (fi->fcp_buffer) {
681 req->req.error = RAW1394_ERROR_ALREADY;
683 fi->fcp_buffer = int2ptr(req->req.recvb);
686 if (!fi->fcp_buffer) {
687 req->req.error = RAW1394_ERROR_ALREADY;
689 fi->fcp_buffer = NULL;
694 queue_complete_req(req);
697 static int handle_async_request(struct file_info *fi,
698 struct pending_request *req, int node)
701 struct hpsb_packet *packet = NULL;
702 u64 addr = req->req.address & 0xffffffffffffULL;
704 switch (req->req.type) {
705 case RAW1394_REQ_ASYNC_READ:
706 DBGMSG("read_request called");
708 hpsb_make_readpacket(fi->host, node, addr, req->req.length);
713 if (req->req.length == 4)
714 req->data = &packet->header[3];
716 req->data = packet->data;
720 case RAW1394_REQ_ASYNC_WRITE:
721 DBGMSG("write_request called");
723 packet = hpsb_make_writepacket(fi->host, node, addr, NULL,
728 if (req->req.length == 4) {
730 (&packet->header[3], int2ptr(req->req.sendb),
732 req->req.error = RAW1394_ERROR_MEMFAULT;
735 (packet->data, int2ptr(req->req.sendb),
737 req->req.error = RAW1394_ERROR_MEMFAULT;
743 case RAW1394_REQ_ASYNC_STREAM:
744 DBGMSG("stream_request called");
747 hpsb_make_streampacket(fi->host, NULL, req->req.length,
748 node & 0x3f /*channel */ ,
749 (req->req.misc >> 16) & 0x3,
750 req->req.misc & 0xf);
754 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
756 req->req.error = RAW1394_ERROR_MEMFAULT;
761 case RAW1394_REQ_LOCK:
762 DBGMSG("lock_request called");
763 if ((req->req.misc == EXTCODE_FETCH_ADD)
764 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
765 if (req->req.length != 4) {
766 req->req.error = RAW1394_ERROR_INVALID_ARG;
770 if (req->req.length != 8) {
771 req->req.error = RAW1394_ERROR_INVALID_ARG;
776 packet = hpsb_make_lockpacket(fi->host, node, addr,
777 req->req.misc, NULL, 0);
781 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
783 req->req.error = RAW1394_ERROR_MEMFAULT;
787 req->data = packet->data;
791 case RAW1394_REQ_LOCK64:
792 DBGMSG("lock64_request called");
793 if ((req->req.misc == EXTCODE_FETCH_ADD)
794 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
795 if (req->req.length != 8) {
796 req->req.error = RAW1394_ERROR_INVALID_ARG;
800 if (req->req.length != 16) {
801 req->req.error = RAW1394_ERROR_INVALID_ARG;
805 packet = hpsb_make_lock64packet(fi->host, node, addr,
806 req->req.misc, NULL, 0);
810 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
812 req->req.error = RAW1394_ERROR_MEMFAULT;
816 req->data = packet->data;
821 req->req.error = RAW1394_ERROR_STATE_ORDER;
824 req->packet = packet;
826 if (req->req.error) {
828 queue_complete_req(req);
829 return sizeof(struct raw1394_request);
832 hpsb_set_packet_complete_task(packet,
833 (void (*)(void *))queue_complete_cb, req);
835 spin_lock_irqsave(&fi->reqlists_lock, flags);
836 list_add_tail(&req->list, &fi->req_pending);
837 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
839 packet->generation = req->req.generation;
841 if (hpsb_send_packet(packet) < 0) {
842 req->req.error = RAW1394_ERROR_SEND_ERROR;
844 hpsb_free_tlabel(packet);
845 queue_complete_req(req);
847 return sizeof(struct raw1394_request);
850 static int handle_iso_send(struct file_info *fi, struct pending_request *req,
854 struct hpsb_packet *packet;
856 packet = hpsb_make_isopacket(fi->host, req->req.length, channel & 0x3f,
857 (req->req.misc >> 16) & 0x3,
858 req->req.misc & 0xf);
862 packet->speed_code = req->req.address & 0x3;
864 req->packet = packet;
866 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
868 req->req.error = RAW1394_ERROR_MEMFAULT;
870 queue_complete_req(req);
871 return sizeof(struct raw1394_request);
875 hpsb_set_packet_complete_task(packet,
876 (void (*)(void *))queue_complete_req,
879 spin_lock_irqsave(&fi->reqlists_lock, flags);
880 list_add_tail(&req->list, &fi->req_pending);
881 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
883 /* Update the generation of the packet just before sending. */
884 packet->generation = req->req.generation;
886 if (hpsb_send_packet(packet) < 0) {
887 req->req.error = RAW1394_ERROR_SEND_ERROR;
888 queue_complete_req(req);
891 return sizeof(struct raw1394_request);
894 static int handle_async_send(struct file_info *fi, struct pending_request *req)
897 struct hpsb_packet *packet;
898 int header_length = req->req.misc & 0xffff;
899 int expect_response = req->req.misc >> 16;
901 if ((header_length > req->req.length) || (header_length < 12)) {
902 req->req.error = RAW1394_ERROR_INVALID_ARG;
904 queue_complete_req(req);
905 return sizeof(struct raw1394_request);
908 packet = hpsb_alloc_packet(req->req.length - header_length);
909 req->packet = packet;
913 if (copy_from_user(packet->header, int2ptr(req->req.sendb),
915 req->req.error = RAW1394_ERROR_MEMFAULT;
917 queue_complete_req(req);
918 return sizeof(struct raw1394_request);
922 (packet->data, int2ptr(req->req.sendb) + header_length,
923 packet->data_size)) {
924 req->req.error = RAW1394_ERROR_MEMFAULT;
926 queue_complete_req(req);
927 return sizeof(struct raw1394_request);
930 packet->type = hpsb_async;
931 packet->node_id = packet->header[0] >> 16;
932 packet->tcode = (packet->header[0] >> 4) & 0xf;
933 packet->tlabel = (packet->header[0] >> 10) & 0x3f;
934 packet->host = fi->host;
935 packet->expect_response = expect_response;
936 packet->header_size = header_length;
937 packet->data_size = req->req.length - header_length;
940 hpsb_set_packet_complete_task(packet,
941 (void (*)(void *))queue_complete_cb, req);
943 spin_lock_irqsave(&fi->reqlists_lock, flags);
944 list_add_tail(&req->list, &fi->req_pending);
945 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
947 /* Update the generation of the packet just before sending. */
948 packet->generation = req->req.generation;
950 if (hpsb_send_packet(packet) < 0) {
951 req->req.error = RAW1394_ERROR_SEND_ERROR;
952 queue_complete_req(req);
955 return sizeof(struct raw1394_request);
958 static int arm_read(struct hpsb_host *host, int nodeid, quadlet_t * buffer,
959 u64 addr, size_t length, u16 flags)
961 unsigned long irqflags;
962 struct pending_request *req;
963 struct host_info *hi;
964 struct file_info *fi = NULL;
965 struct list_head *entry;
966 struct arm_addr *arm_addr = NULL;
967 struct arm_request *arm_req = NULL;
968 struct arm_response *arm_resp = NULL;
969 int found = 0, size = 0, rcode = -1;
970 struct arm_request_response *arm_req_resp = NULL;
972 DBGMSG("arm_read called by node: %X"
973 "addr: %4.4x %8.8x length: %Zu", nodeid,
974 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
976 spin_lock_irqsave(&host_info_lock, irqflags);
977 hi = find_host_info(host); /* search address-entry */
979 list_for_each_entry(fi, &hi->file_info_list, list) {
980 entry = fi->addr_list.next;
981 while (entry != &(fi->addr_list)) {
983 list_entry(entry, struct arm_addr,
985 if (((arm_addr->start) <= (addr))
986 && ((arm_addr->end) >= (addr + length))) {
999 printk(KERN_ERR "raw1394: arm_read FAILED addr_entry not found"
1000 " -> rcode_address_error\n");
1001 spin_unlock_irqrestore(&host_info_lock, irqflags);
1002 return (RCODE_ADDRESS_ERROR);
1004 DBGMSG("arm_read addr_entry FOUND");
1006 if (arm_addr->rec_length < length) {
1007 DBGMSG("arm_read blocklength too big -> rcode_data_error");
1008 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
1011 if (arm_addr->access_rights & ARM_READ) {
1012 if (!(arm_addr->client_transactions & ARM_READ)) {
1014 (arm_addr->addr_space_buffer) + (addr -
1018 DBGMSG("arm_read -> (rcode_complete)");
1019 rcode = RCODE_COMPLETE;
1022 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1023 DBGMSG("arm_read -> rcode_type_error (access denied)");
1026 if (arm_addr->notification_options & ARM_READ) {
1027 DBGMSG("arm_read -> entering notification-section");
1028 req = __alloc_pending_request(SLAB_ATOMIC);
1030 DBGMSG("arm_read -> rcode_conflict_error");
1031 spin_unlock_irqrestore(&host_info_lock, irqflags);
1032 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1033 The request may be retried */
1035 if (rcode == RCODE_COMPLETE) {
1037 sizeof(struct arm_request) +
1038 sizeof(struct arm_response) +
1039 length * sizeof(byte_t) +
1040 sizeof(struct arm_request_response);
1043 sizeof(struct arm_request) +
1044 sizeof(struct arm_response) +
1045 sizeof(struct arm_request_response);
1047 req->data = kmalloc(size, SLAB_ATOMIC);
1049 free_pending_request(req);
1050 DBGMSG("arm_read -> rcode_conflict_error");
1051 spin_unlock_irqrestore(&host_info_lock, irqflags);
1052 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1053 The request may be retried */
1056 req->file_info = fi;
1057 req->req.type = RAW1394_REQ_ARM;
1058 req->req.generation = get_hpsb_generation(host);
1060 (((length << 16) & (0xFFFF0000)) | (ARM_READ & 0xFF));
1061 req->req.tag = arm_addr->arm_tag;
1062 req->req.recvb = arm_addr->recvb;
1063 req->req.length = size;
1064 arm_req_resp = (struct arm_request_response *)(req->data);
1065 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1068 arm_request_response)));
1070 (struct arm_response *)((byte_t *) (arm_req) +
1071 (sizeof(struct arm_request)));
1072 arm_req->buffer = NULL;
1073 arm_resp->buffer = NULL;
1074 if (rcode == RCODE_COMPLETE) {
1076 (byte_t *) arm_resp + sizeof(struct arm_response);
1078 (arm_addr->addr_space_buffer) + (addr -
1083 int2ptr((arm_addr->recvb) +
1084 sizeof(struct arm_request_response) +
1085 sizeof(struct arm_request) +
1086 sizeof(struct arm_response));
1088 arm_resp->buffer_length =
1089 (rcode == RCODE_COMPLETE) ? length : 0;
1090 arm_resp->response_code = rcode;
1091 arm_req->buffer_length = 0;
1092 arm_req->generation = req->req.generation;
1093 arm_req->extended_transaction_code = 0;
1094 arm_req->destination_offset = addr;
1095 arm_req->source_nodeid = nodeid;
1096 arm_req->destination_nodeid = host->node_id;
1097 arm_req->tlabel = (flags >> 10) & 0x3f;
1098 arm_req->tcode = (flags >> 4) & 0x0f;
1099 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1101 arm_request_response));
1102 arm_req_resp->response =
1103 int2ptr((arm_addr->recvb) +
1104 sizeof(struct arm_request_response) +
1105 sizeof(struct arm_request));
1106 queue_complete_req(req);
1108 spin_unlock_irqrestore(&host_info_lock, irqflags);
1112 static int arm_write(struct hpsb_host *host, int nodeid, int destid,
1113 quadlet_t * data, u64 addr, size_t length, u16 flags)
1115 unsigned long irqflags;
1116 struct pending_request *req;
1117 struct host_info *hi;
1118 struct file_info *fi = NULL;
1119 struct list_head *entry;
1120 struct arm_addr *arm_addr = NULL;
1121 struct arm_request *arm_req = NULL;
1122 struct arm_response *arm_resp = NULL;
1123 int found = 0, size = 0, rcode = -1, length_conflict = 0;
1124 struct arm_request_response *arm_req_resp = NULL;
1126 DBGMSG("arm_write called by node: %X"
1127 "addr: %4.4x %8.8x length: %Zu", nodeid,
1128 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
1130 spin_lock_irqsave(&host_info_lock, irqflags);
1131 hi = find_host_info(host); /* search address-entry */
1133 list_for_each_entry(fi, &hi->file_info_list, list) {
1134 entry = fi->addr_list.next;
1135 while (entry != &(fi->addr_list)) {
1137 list_entry(entry, struct arm_addr,
1139 if (((arm_addr->start) <= (addr))
1140 && ((arm_addr->end) >= (addr + length))) {
1144 entry = entry->next;
1153 printk(KERN_ERR "raw1394: arm_write FAILED addr_entry not found"
1154 " -> rcode_address_error\n");
1155 spin_unlock_irqrestore(&host_info_lock, irqflags);
1156 return (RCODE_ADDRESS_ERROR);
1158 DBGMSG("arm_write addr_entry FOUND");
1160 if (arm_addr->rec_length < length) {
1161 DBGMSG("arm_write blocklength too big -> rcode_data_error");
1162 length_conflict = 1;
1163 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
1166 if (arm_addr->access_rights & ARM_WRITE) {
1167 if (!(arm_addr->client_transactions & ARM_WRITE)) {
1168 memcpy((arm_addr->addr_space_buffer) +
1169 (addr - (arm_addr->start)), data,
1171 DBGMSG("arm_write -> (rcode_complete)");
1172 rcode = RCODE_COMPLETE;
1175 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1176 DBGMSG("arm_write -> rcode_type_error (access denied)");
1179 if (arm_addr->notification_options & ARM_WRITE) {
1180 DBGMSG("arm_write -> entering notification-section");
1181 req = __alloc_pending_request(SLAB_ATOMIC);
1183 DBGMSG("arm_write -> rcode_conflict_error");
1184 spin_unlock_irqrestore(&host_info_lock, irqflags);
1185 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1186 The request my be retried */
1189 sizeof(struct arm_request) + sizeof(struct arm_response) +
1190 (length) * sizeof(byte_t) +
1191 sizeof(struct arm_request_response);
1192 req->data = kmalloc(size, SLAB_ATOMIC);
1194 free_pending_request(req);
1195 DBGMSG("arm_write -> rcode_conflict_error");
1196 spin_unlock_irqrestore(&host_info_lock, irqflags);
1197 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1198 The request may be retried */
1201 req->file_info = fi;
1202 req->req.type = RAW1394_REQ_ARM;
1203 req->req.generation = get_hpsb_generation(host);
1205 (((length << 16) & (0xFFFF0000)) | (ARM_WRITE & 0xFF));
1206 req->req.tag = arm_addr->arm_tag;
1207 req->req.recvb = arm_addr->recvb;
1208 req->req.length = size;
1209 arm_req_resp = (struct arm_request_response *)(req->data);
1210 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1213 arm_request_response)));
1215 (struct arm_response *)((byte_t *) (arm_req) +
1216 (sizeof(struct arm_request)));
1217 arm_resp->buffer = NULL;
1218 memcpy((byte_t *) arm_resp + sizeof(struct arm_response),
1220 arm_req->buffer = int2ptr((arm_addr->recvb) +
1221 sizeof(struct arm_request_response) +
1222 sizeof(struct arm_request) +
1223 sizeof(struct arm_response));
1224 arm_req->buffer_length = length;
1225 arm_req->generation = req->req.generation;
1226 arm_req->extended_transaction_code = 0;
1227 arm_req->destination_offset = addr;
1228 arm_req->source_nodeid = nodeid;
1229 arm_req->destination_nodeid = destid;
1230 arm_req->tlabel = (flags >> 10) & 0x3f;
1231 arm_req->tcode = (flags >> 4) & 0x0f;
1232 arm_resp->buffer_length = 0;
1233 arm_resp->response_code = rcode;
1234 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1236 arm_request_response));
1237 arm_req_resp->response =
1238 int2ptr((arm_addr->recvb) +
1239 sizeof(struct arm_request_response) +
1240 sizeof(struct arm_request));
1241 queue_complete_req(req);
1243 spin_unlock_irqrestore(&host_info_lock, irqflags);
1247 static int arm_lock(struct hpsb_host *host, int nodeid, quadlet_t * store,
1248 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
1251 unsigned long irqflags;
1252 struct pending_request *req;
1253 struct host_info *hi;
1254 struct file_info *fi = NULL;
1255 struct list_head *entry;
1256 struct arm_addr *arm_addr = NULL;
1257 struct arm_request *arm_req = NULL;
1258 struct arm_response *arm_resp = NULL;
1259 int found = 0, size = 0, rcode = -1;
1261 struct arm_request_response *arm_req_resp = NULL;
1263 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1264 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1265 DBGMSG("arm_lock called by node: %X "
1266 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X",
1267 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1268 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1271 DBGMSG("arm_lock called by node: %X "
1272 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X arg: %8.8X",
1273 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1274 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1275 be32_to_cpu(data), be32_to_cpu(arg));
1277 spin_lock_irqsave(&host_info_lock, irqflags);
1278 hi = find_host_info(host); /* search address-entry */
1280 list_for_each_entry(fi, &hi->file_info_list, list) {
1281 entry = fi->addr_list.next;
1282 while (entry != &(fi->addr_list)) {
1284 list_entry(entry, struct arm_addr,
1286 if (((arm_addr->start) <= (addr))
1287 && ((arm_addr->end) >=
1288 (addr + sizeof(*store)))) {
1292 entry = entry->next;
1301 printk(KERN_ERR "raw1394: arm_lock FAILED addr_entry not found"
1302 " -> rcode_address_error\n");
1303 spin_unlock_irqrestore(&host_info_lock, irqflags);
1304 return (RCODE_ADDRESS_ERROR);
1306 DBGMSG("arm_lock addr_entry FOUND");
1309 if (arm_addr->access_rights & ARM_LOCK) {
1310 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1312 (arm_addr->addr_space_buffer) + (addr -
1316 switch (ext_tcode) {
1317 case (EXTCODE_MASK_SWAP):
1318 new = data | (old & ~arg);
1320 case (EXTCODE_COMPARE_SWAP):
1327 case (EXTCODE_FETCH_ADD):
1329 cpu_to_be32(be32_to_cpu(data) +
1332 case (EXTCODE_LITTLE_ADD):
1334 cpu_to_le32(le32_to_cpu(data) +
1337 case (EXTCODE_BOUNDED_ADD):
1340 cpu_to_be32(be32_to_cpu
1348 case (EXTCODE_WRAP_ADD):
1351 cpu_to_be32(be32_to_cpu
1360 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1362 "raw1394: arm_lock FAILED "
1363 "ext_tcode not allowed -> rcode_type_error\n");
1367 DBGMSG("arm_lock -> (rcode_complete)");
1368 rcode = RCODE_COMPLETE;
1369 memcpy(store, &old, sizeof(*store));
1370 memcpy((arm_addr->addr_space_buffer) +
1371 (addr - (arm_addr->start)),
1372 &new, sizeof(*store));
1376 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1377 DBGMSG("arm_lock -> rcode_type_error (access denied)");
1380 if (arm_addr->notification_options & ARM_LOCK) {
1381 byte_t *buf1, *buf2;
1382 DBGMSG("arm_lock -> entering notification-section");
1383 req = __alloc_pending_request(SLAB_ATOMIC);
1385 DBGMSG("arm_lock -> rcode_conflict_error");
1386 spin_unlock_irqrestore(&host_info_lock, irqflags);
1387 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1388 The request may be retried */
1390 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1391 req->data = kmalloc(size, SLAB_ATOMIC);
1393 free_pending_request(req);
1394 DBGMSG("arm_lock -> rcode_conflict_error");
1395 spin_unlock_irqrestore(&host_info_lock, irqflags);
1396 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1397 The request may be retried */
1400 arm_req_resp = (struct arm_request_response *)(req->data);
1401 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1404 arm_request_response)));
1406 (struct arm_response *)((byte_t *) (arm_req) +
1407 (sizeof(struct arm_request)));
1408 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1409 buf2 = buf1 + 2 * sizeof(*store);
1410 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1411 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1412 arm_req->buffer_length = sizeof(*store);
1413 memcpy(buf1, &data, sizeof(*store));
1416 arm_req->buffer_length = 2 * sizeof(*store);
1417 memcpy(buf1, &arg, sizeof(*store));
1418 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1420 if (rcode == RCODE_COMPLETE) {
1421 arm_resp->buffer_length = sizeof(*store);
1422 memcpy(buf2, &old, sizeof(*store));
1424 arm_resp->buffer_length = 0;
1426 req->file_info = fi;
1427 req->req.type = RAW1394_REQ_ARM;
1428 req->req.generation = get_hpsb_generation(host);
1429 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1431 req->req.tag = arm_addr->arm_tag;
1432 req->req.recvb = arm_addr->recvb;
1433 req->req.length = size;
1434 arm_req->generation = req->req.generation;
1435 arm_req->extended_transaction_code = ext_tcode;
1436 arm_req->destination_offset = addr;
1437 arm_req->source_nodeid = nodeid;
1438 arm_req->destination_nodeid = host->node_id;
1439 arm_req->tlabel = (flags >> 10) & 0x3f;
1440 arm_req->tcode = (flags >> 4) & 0x0f;
1441 arm_resp->response_code = rcode;
1442 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1444 arm_request_response));
1445 arm_req_resp->response =
1446 int2ptr((arm_addr->recvb) +
1447 sizeof(struct arm_request_response) +
1448 sizeof(struct arm_request));
1450 int2ptr((arm_addr->recvb) +
1451 sizeof(struct arm_request_response) +
1452 sizeof(struct arm_request) +
1453 sizeof(struct arm_response));
1455 int2ptr((arm_addr->recvb) +
1456 sizeof(struct arm_request_response) +
1457 sizeof(struct arm_request) +
1458 sizeof(struct arm_response) + 2 * sizeof(*store));
1459 queue_complete_req(req);
1461 spin_unlock_irqrestore(&host_info_lock, irqflags);
1465 static int arm_lock64(struct hpsb_host *host, int nodeid, octlet_t * store,
1466 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
1469 unsigned long irqflags;
1470 struct pending_request *req;
1471 struct host_info *hi;
1472 struct file_info *fi = NULL;
1473 struct list_head *entry;
1474 struct arm_addr *arm_addr = NULL;
1475 struct arm_request *arm_req = NULL;
1476 struct arm_response *arm_resp = NULL;
1477 int found = 0, size = 0, rcode = -1;
1479 struct arm_request_response *arm_req_resp = NULL;
1481 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1482 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1483 DBGMSG("arm_lock64 called by node: %X "
1484 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X ",
1485 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1486 (u32) (addr & 0xFFFFFFFF),
1488 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1489 (u32) (be64_to_cpu(data) & 0xFFFFFFFF));
1491 DBGMSG("arm_lock64 called by node: %X "
1492 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X arg: "
1494 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1495 (u32) (addr & 0xFFFFFFFF),
1497 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1498 (u32) (be64_to_cpu(data) & 0xFFFFFFFF),
1499 (u32) ((be64_to_cpu(arg) >> 32) & 0xFFFFFFFF),
1500 (u32) (be64_to_cpu(arg) & 0xFFFFFFFF));
1502 spin_lock_irqsave(&host_info_lock, irqflags);
1503 hi = find_host_info(host); /* search addressentry in file_info's for host */
1505 list_for_each_entry(fi, &hi->file_info_list, list) {
1506 entry = fi->addr_list.next;
1507 while (entry != &(fi->addr_list)) {
1509 list_entry(entry, struct arm_addr,
1511 if (((arm_addr->start) <= (addr))
1512 && ((arm_addr->end) >=
1513 (addr + sizeof(*store)))) {
1517 entry = entry->next;
1527 "raw1394: arm_lock64 FAILED addr_entry not found"
1528 " -> rcode_address_error\n");
1529 spin_unlock_irqrestore(&host_info_lock, irqflags);
1530 return (RCODE_ADDRESS_ERROR);
1532 DBGMSG("arm_lock64 addr_entry FOUND");
1535 if (arm_addr->access_rights & ARM_LOCK) {
1536 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1538 (arm_addr->addr_space_buffer) + (addr -
1542 switch (ext_tcode) {
1543 case (EXTCODE_MASK_SWAP):
1544 new = data | (old & ~arg);
1546 case (EXTCODE_COMPARE_SWAP):
1553 case (EXTCODE_FETCH_ADD):
1555 cpu_to_be64(be64_to_cpu(data) +
1558 case (EXTCODE_LITTLE_ADD):
1560 cpu_to_le64(le64_to_cpu(data) +
1563 case (EXTCODE_BOUNDED_ADD):
1566 cpu_to_be64(be64_to_cpu
1574 case (EXTCODE_WRAP_ADD):
1577 cpu_to_be64(be64_to_cpu
1587 "raw1394: arm_lock64 FAILED "
1588 "ext_tcode not allowed -> rcode_type_error\n");
1589 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1594 ("arm_lock64 -> (rcode_complete)");
1595 rcode = RCODE_COMPLETE;
1596 memcpy(store, &old, sizeof(*store));
1597 memcpy((arm_addr->addr_space_buffer) +
1598 (addr - (arm_addr->start)),
1599 &new, sizeof(*store));
1603 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1605 ("arm_lock64 -> rcode_type_error (access denied)");
1608 if (arm_addr->notification_options & ARM_LOCK) {
1609 byte_t *buf1, *buf2;
1610 DBGMSG("arm_lock64 -> entering notification-section");
1611 req = __alloc_pending_request(SLAB_ATOMIC);
1613 spin_unlock_irqrestore(&host_info_lock, irqflags);
1614 DBGMSG("arm_lock64 -> rcode_conflict_error");
1615 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1616 The request may be retried */
1618 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1619 req->data = kmalloc(size, SLAB_ATOMIC);
1621 free_pending_request(req);
1622 spin_unlock_irqrestore(&host_info_lock, irqflags);
1623 DBGMSG("arm_lock64 -> rcode_conflict_error");
1624 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1625 The request may be retried */
1628 arm_req_resp = (struct arm_request_response *)(req->data);
1629 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1632 arm_request_response)));
1634 (struct arm_response *)((byte_t *) (arm_req) +
1635 (sizeof(struct arm_request)));
1636 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1637 buf2 = buf1 + 2 * sizeof(*store);
1638 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1639 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1640 arm_req->buffer_length = sizeof(*store);
1641 memcpy(buf1, &data, sizeof(*store));
1644 arm_req->buffer_length = 2 * sizeof(*store);
1645 memcpy(buf1, &arg, sizeof(*store));
1646 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1648 if (rcode == RCODE_COMPLETE) {
1649 arm_resp->buffer_length = sizeof(*store);
1650 memcpy(buf2, &old, sizeof(*store));
1652 arm_resp->buffer_length = 0;
1654 req->file_info = fi;
1655 req->req.type = RAW1394_REQ_ARM;
1656 req->req.generation = get_hpsb_generation(host);
1657 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1659 req->req.tag = arm_addr->arm_tag;
1660 req->req.recvb = arm_addr->recvb;
1661 req->req.length = size;
1662 arm_req->generation = req->req.generation;
1663 arm_req->extended_transaction_code = ext_tcode;
1664 arm_req->destination_offset = addr;
1665 arm_req->source_nodeid = nodeid;
1666 arm_req->destination_nodeid = host->node_id;
1667 arm_req->tlabel = (flags >> 10) & 0x3f;
1668 arm_req->tcode = (flags >> 4) & 0x0f;
1669 arm_resp->response_code = rcode;
1670 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1672 arm_request_response));
1673 arm_req_resp->response =
1674 int2ptr((arm_addr->recvb) +
1675 sizeof(struct arm_request_response) +
1676 sizeof(struct arm_request));
1678 int2ptr((arm_addr->recvb) +
1679 sizeof(struct arm_request_response) +
1680 sizeof(struct arm_request) +
1681 sizeof(struct arm_response));
1683 int2ptr((arm_addr->recvb) +
1684 sizeof(struct arm_request_response) +
1685 sizeof(struct arm_request) +
1686 sizeof(struct arm_response) + 2 * sizeof(*store));
1687 queue_complete_req(req);
1689 spin_unlock_irqrestore(&host_info_lock, irqflags);
1693 static int arm_register(struct file_info *fi, struct pending_request *req)
1696 struct arm_addr *addr;
1697 struct host_info *hi;
1698 struct file_info *fi_hlp = NULL;
1699 struct list_head *entry;
1700 struct arm_addr *arm_addr = NULL;
1701 int same_host, another_host;
1702 unsigned long flags;
1704 DBGMSG("arm_register called "
1705 "addr(Offset): %8.8x %8.8x length: %u "
1706 "rights: %2.2X notify: %2.2X "
1707 "max_blk_len: %4.4X",
1708 (u32) ((req->req.address >> 32) & 0xFFFF),
1709 (u32) (req->req.address & 0xFFFFFFFF),
1710 req->req.length, ((req->req.misc >> 8) & 0xFF),
1711 (req->req.misc & 0xFF), ((req->req.misc >> 16) & 0xFFFF));
1712 /* check addressrange */
1713 if ((((req->req.address) & ~(0xFFFFFFFFFFFFULL)) != 0) ||
1714 (((req->req.address + req->req.length) & ~(0xFFFFFFFFFFFFULL)) !=
1716 req->req.length = 0;
1719 /* addr-list-entry for fileinfo */
1720 addr = kmalloc(sizeof(*addr), SLAB_KERNEL);
1722 req->req.length = 0;
1725 /* allocation of addr_space_buffer */
1726 addr->addr_space_buffer = vmalloc(req->req.length);
1727 if (!(addr->addr_space_buffer)) {
1729 req->req.length = 0;
1732 /* initialization of addr_space_buffer */
1733 if ((req->req.sendb) == (unsigned long)NULL) {
1735 memset(addr->addr_space_buffer, 0, req->req.length);
1737 /* init: user -> kernel */
1739 (addr->addr_space_buffer, int2ptr(req->req.sendb),
1741 vfree(addr->addr_space_buffer);
1746 INIT_LIST_HEAD(&addr->addr_list);
1747 addr->arm_tag = req->req.tag;
1748 addr->start = req->req.address;
1749 addr->end = req->req.address + req->req.length;
1750 addr->access_rights = (u8) (req->req.misc & 0x0F);
1751 addr->notification_options = (u8) ((req->req.misc >> 4) & 0x0F);
1752 addr->client_transactions = (u8) ((req->req.misc >> 8) & 0x0F);
1753 addr->access_rights |= addr->client_transactions;
1754 addr->notification_options |= addr->client_transactions;
1755 addr->recvb = req->req.recvb;
1756 addr->rec_length = (u16) ((req->req.misc >> 16) & 0xFFFF);
1757 spin_lock_irqsave(&host_info_lock, flags);
1758 hi = find_host_info(fi->host);
1761 /* same host with address-entry containing same addressrange ? */
1762 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1763 entry = fi_hlp->addr_list.next;
1764 while (entry != &(fi_hlp->addr_list)) {
1766 list_entry(entry, struct arm_addr, addr_list);
1767 if ((arm_addr->start == addr->start)
1768 && (arm_addr->end == addr->end)) {
1769 DBGMSG("same host ownes same "
1770 "addressrange -> EALREADY");
1774 entry = entry->next;
1781 /* addressrange occupied by same host */
1782 vfree(addr->addr_space_buffer);
1784 spin_unlock_irqrestore(&host_info_lock, flags);
1787 /* another host with valid address-entry containing same addressrange */
1788 list_for_each_entry(hi, &host_info_list, list) {
1789 if (hi->host != fi->host) {
1790 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1791 entry = fi_hlp->addr_list.next;
1792 while (entry != &(fi_hlp->addr_list)) {
1794 list_entry(entry, struct arm_addr,
1796 if ((arm_addr->start == addr->start)
1797 && (arm_addr->end == addr->end)) {
1799 ("another host ownes same "
1804 entry = entry->next;
1813 DBGMSG("another hosts entry is valid -> SUCCESS");
1814 if (copy_to_user(int2ptr(req->req.recvb),
1815 &addr->start, sizeof(u64))) {
1816 printk(KERN_ERR "raw1394: arm_register failed "
1817 " address-range-entry is invalid -> EFAULT !!!\n");
1818 vfree(addr->addr_space_buffer);
1820 spin_unlock_irqrestore(&host_info_lock, flags);
1823 free_pending_request(req); /* immediate success or fail */
1825 list_add_tail(&addr->addr_list, &fi->addr_list);
1826 spin_unlock_irqrestore(&host_info_lock, flags);
1827 return sizeof(struct raw1394_request);
1830 hpsb_register_addrspace(&raw1394_highlevel, fi->host, &arm_ops,
1832 req->req.address + req->req.length);
1835 list_add_tail(&addr->addr_list, &fi->addr_list);
1837 DBGMSG("arm_register failed errno: %d \n", retval);
1838 vfree(addr->addr_space_buffer);
1840 spin_unlock_irqrestore(&host_info_lock, flags);
1843 spin_unlock_irqrestore(&host_info_lock, flags);
1844 free_pending_request(req); /* immediate success or fail */
1845 return sizeof(struct raw1394_request);
1848 static int arm_unregister(struct file_info *fi, struct pending_request *req)
1852 struct list_head *entry;
1853 struct arm_addr *addr = NULL;
1854 struct host_info *hi;
1855 struct file_info *fi_hlp = NULL;
1856 struct arm_addr *arm_addr = NULL;
1858 unsigned long flags;
1860 DBGMSG("arm_Unregister called addr(Offset): "
1862 (u32) ((req->req.address >> 32) & 0xFFFF),
1863 (u32) (req->req.address & 0xFFFFFFFF));
1864 spin_lock_irqsave(&host_info_lock, flags);
1866 entry = fi->addr_list.next;
1867 while (entry != &(fi->addr_list)) {
1868 addr = list_entry(entry, struct arm_addr, addr_list);
1869 if (addr->start == req->req.address) {
1873 entry = entry->next;
1876 DBGMSG("arm_Unregister addr not found");
1877 spin_unlock_irqrestore(&host_info_lock, flags);
1880 DBGMSG("arm_Unregister addr found");
1882 /* another host with valid address-entry containing
1883 same addressrange */
1884 list_for_each_entry(hi, &host_info_list, list) {
1885 if (hi->host != fi->host) {
1886 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1887 entry = fi_hlp->addr_list.next;
1888 while (entry != &(fi_hlp->addr_list)) {
1889 arm_addr = list_entry(entry,
1892 if (arm_addr->start == addr->start) {
1893 DBGMSG("another host ownes "
1894 "same addressrange");
1898 entry = entry->next;
1907 DBGMSG("delete entry from list -> success");
1908 list_del(&addr->addr_list);
1909 vfree(addr->addr_space_buffer);
1911 free_pending_request(req); /* immediate success or fail */
1912 spin_unlock_irqrestore(&host_info_lock, flags);
1913 return sizeof(struct raw1394_request);
1916 hpsb_unregister_addrspace(&raw1394_highlevel, fi->host,
1919 printk(KERN_ERR "raw1394: arm_Unregister failed -> EINVAL\n");
1920 spin_unlock_irqrestore(&host_info_lock, flags);
1923 DBGMSG("delete entry from list -> success");
1924 list_del(&addr->addr_list);
1925 spin_unlock_irqrestore(&host_info_lock, flags);
1926 vfree(addr->addr_space_buffer);
1928 free_pending_request(req); /* immediate success or fail */
1929 return sizeof(struct raw1394_request);
1932 /* Copy data from ARM buffer(s) to user buffer. */
1933 static int arm_get_buf(struct file_info *fi, struct pending_request *req)
1935 struct arm_addr *arm_addr = NULL;
1936 unsigned long flags;
1937 unsigned long offset;
1939 struct list_head *entry;
1941 DBGMSG("arm_get_buf "
1942 "addr(Offset): %04X %08X length: %u",
1943 (u32) ((req->req.address >> 32) & 0xFFFF),
1944 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
1946 spin_lock_irqsave(&host_info_lock, flags);
1947 entry = fi->addr_list.next;
1948 while (entry != &(fi->addr_list)) {
1949 arm_addr = list_entry(entry, struct arm_addr, addr_list);
1950 if ((arm_addr->start <= req->req.address) &&
1951 (arm_addr->end > req->req.address)) {
1952 if (req->req.address + req->req.length <= arm_addr->end) {
1953 offset = req->req.address - arm_addr->start;
1956 ("arm_get_buf copy_to_user( %08X, %p, %u )",
1957 (u32) req->req.recvb,
1958 arm_addr->addr_space_buffer + offset,
1959 (u32) req->req.length);
1962 (int2ptr(req->req.recvb),
1963 arm_addr->addr_space_buffer + offset,
1965 spin_unlock_irqrestore(&host_info_lock,
1970 spin_unlock_irqrestore(&host_info_lock, flags);
1971 /* We have to free the request, because we
1972 * queue no response, and therefore nobody
1974 free_pending_request(req);
1975 return sizeof(struct raw1394_request);
1977 DBGMSG("arm_get_buf request exceeded mapping");
1978 spin_unlock_irqrestore(&host_info_lock, flags);
1982 entry = entry->next;
1984 spin_unlock_irqrestore(&host_info_lock, flags);
1988 /* Copy data from user buffer to ARM buffer(s). */
1989 static int arm_set_buf(struct file_info *fi, struct pending_request *req)
1991 struct arm_addr *arm_addr = NULL;
1992 unsigned long flags;
1993 unsigned long offset;
1995 struct list_head *entry;
1997 DBGMSG("arm_set_buf "
1998 "addr(Offset): %04X %08X length: %u",
1999 (u32) ((req->req.address >> 32) & 0xFFFF),
2000 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
2002 spin_lock_irqsave(&host_info_lock, flags);
2003 entry = fi->addr_list.next;
2004 while (entry != &(fi->addr_list)) {
2005 arm_addr = list_entry(entry, struct arm_addr, addr_list);
2006 if ((arm_addr->start <= req->req.address) &&
2007 (arm_addr->end > req->req.address)) {
2008 if (req->req.address + req->req.length <= arm_addr->end) {
2009 offset = req->req.address - arm_addr->start;
2012 ("arm_set_buf copy_from_user( %p, %08X, %u )",
2013 arm_addr->addr_space_buffer + offset,
2014 (u32) req->req.sendb,
2015 (u32) req->req.length);
2018 (arm_addr->addr_space_buffer + offset,
2019 int2ptr(req->req.sendb),
2021 spin_unlock_irqrestore(&host_info_lock,
2026 spin_unlock_irqrestore(&host_info_lock, flags);
2027 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2028 return sizeof(struct raw1394_request);
2030 DBGMSG("arm_set_buf request exceeded mapping");
2031 spin_unlock_irqrestore(&host_info_lock, flags);
2035 entry = entry->next;
2037 spin_unlock_irqrestore(&host_info_lock, flags);
2041 static int reset_notification(struct file_info *fi, struct pending_request *req)
2043 DBGMSG("reset_notification called - switch %s ",
2044 (req->req.misc == RAW1394_NOTIFY_OFF) ? "OFF" : "ON");
2045 if ((req->req.misc == RAW1394_NOTIFY_OFF) ||
2046 (req->req.misc == RAW1394_NOTIFY_ON)) {
2047 fi->notification = (u8) req->req.misc;
2048 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2049 return sizeof(struct raw1394_request);
2051 /* error EINVAL (22) invalid argument */
2055 static int write_phypacket(struct file_info *fi, struct pending_request *req)
2057 struct hpsb_packet *packet = NULL;
2060 unsigned long flags;
2062 data = be32_to_cpu((u32) req->req.sendb);
2063 DBGMSG("write_phypacket called - quadlet 0x%8.8x ", data);
2064 packet = hpsb_make_phypacket(fi->host, data);
2067 req->req.length = 0;
2068 req->packet = packet;
2069 hpsb_set_packet_complete_task(packet,
2070 (void (*)(void *))queue_complete_cb, req);
2071 spin_lock_irqsave(&fi->reqlists_lock, flags);
2072 list_add_tail(&req->list, &fi->req_pending);
2073 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2074 packet->generation = req->req.generation;
2075 retval = hpsb_send_packet(packet);
2076 DBGMSG("write_phypacket send_packet called => retval: %d ", retval);
2078 req->req.error = RAW1394_ERROR_SEND_ERROR;
2079 req->req.length = 0;
2080 queue_complete_req(req);
2082 return sizeof(struct raw1394_request);
2085 static int get_config_rom(struct file_info *fi, struct pending_request *req)
2087 int ret = sizeof(struct raw1394_request);
2088 quadlet_t *data = kmalloc(req->req.length, SLAB_KERNEL);
2095 csr1212_read(fi->host->csr.rom, CSR1212_CONFIG_ROM_SPACE_OFFSET,
2096 data, req->req.length);
2097 if (copy_to_user(int2ptr(req->req.recvb), data, req->req.length))
2100 (int2ptr(req->req.tag), &fi->host->csr.rom->cache_head->len,
2101 sizeof(fi->host->csr.rom->cache_head->len)))
2103 if (copy_to_user(int2ptr(req->req.address), &fi->host->csr.generation,
2104 sizeof(fi->host->csr.generation)))
2106 if (copy_to_user(int2ptr(req->req.sendb), &status, sizeof(status)))
2110 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2115 static int update_config_rom(struct file_info *fi, struct pending_request *req)
2117 int ret = sizeof(struct raw1394_request);
2118 quadlet_t *data = kmalloc(req->req.length, SLAB_KERNEL);
2121 if (copy_from_user(data, int2ptr(req->req.sendb), req->req.length)) {
2124 int status = hpsb_update_config_rom(fi->host,
2125 data, req->req.length,
2126 (unsigned char)req->req.
2129 (int2ptr(req->req.recvb), &status, sizeof(status)))
2134 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2140 static int modify_config_rom(struct file_info *fi, struct pending_request *req)
2142 struct csr1212_keyval *kv;
2143 struct csr1212_csr_rom_cache *cache;
2144 struct csr1212_dentry *dentry;
2148 if (req->req.misc == ~0) {
2149 if (req->req.length == 0)
2152 /* Find an unused slot */
2154 dr < RAW1394_MAX_USER_CSR_DIRS && fi->csr1212_dirs[dr];
2157 if (dr == RAW1394_MAX_USER_CSR_DIRS)
2160 fi->csr1212_dirs[dr] =
2161 csr1212_new_directory(CSR1212_KV_ID_VENDOR);
2162 if (!fi->csr1212_dirs[dr])
2166 if (!fi->csr1212_dirs[dr])
2169 /* Delete old stuff */
2171 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2172 dentry; dentry = dentry->next) {
2173 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2178 if (req->req.length == 0) {
2179 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2180 fi->csr1212_dirs[dr] = NULL;
2182 hpsb_update_config_rom_image(fi->host);
2183 free_pending_request(req);
2184 return sizeof(struct raw1394_request);
2188 cache = csr1212_rom_cache_malloc(0, req->req.length);
2190 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2191 fi->csr1212_dirs[dr] = NULL;
2195 cache->filled_head = kmalloc(sizeof(*cache->filled_head), GFP_KERNEL);
2196 if (!cache->filled_head) {
2197 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2198 fi->csr1212_dirs[dr] = NULL;
2199 CSR1212_FREE(cache);
2202 cache->filled_tail = cache->filled_head;
2204 if (copy_from_user(cache->data, int2ptr(req->req.sendb),
2206 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2207 fi->csr1212_dirs[dr] = NULL;
2210 cache->len = req->req.length;
2211 cache->filled_head->offset_start = 0;
2212 cache->filled_head->offset_end = cache->size - 1;
2214 cache->layout_head = cache->layout_tail = fi->csr1212_dirs[dr];
2216 ret = CSR1212_SUCCESS;
2217 /* parse all the items */
2218 for (kv = cache->layout_head; ret == CSR1212_SUCCESS && kv;
2220 ret = csr1212_parse_keyval(kv, cache);
2223 /* attach top level items to the root directory */
2225 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2226 ret == CSR1212_SUCCESS && dentry; dentry = dentry->next) {
2228 csr1212_attach_keyval_to_directory(fi->host->csr.
2233 if (ret == CSR1212_SUCCESS) {
2234 ret = hpsb_update_config_rom_image(fi->host);
2236 if (ret >= 0 && copy_to_user(int2ptr(req->req.recvb),
2242 kfree(cache->filled_head);
2243 CSR1212_FREE(cache);
2246 /* we have to free the request, because we queue no response,
2247 * and therefore nobody will free it */
2248 free_pending_request(req);
2249 return sizeof(struct raw1394_request);
2252 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2253 dentry; dentry = dentry->next) {
2254 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2258 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2259 fi->csr1212_dirs[dr] = NULL;
2264 static int state_connected(struct file_info *fi, struct pending_request *req)
2266 int node = req->req.address >> 48;
2268 req->req.error = RAW1394_ERROR_NONE;
2270 switch (req->req.type) {
2272 case RAW1394_REQ_ECHO:
2273 queue_complete_req(req);
2274 return sizeof(struct raw1394_request);
2276 case RAW1394_REQ_ISO_SEND:
2277 return handle_iso_send(fi, req, node);
2279 case RAW1394_REQ_ARM_REGISTER:
2280 return arm_register(fi, req);
2282 case RAW1394_REQ_ARM_UNREGISTER:
2283 return arm_unregister(fi, req);
2285 case RAW1394_REQ_ARM_SET_BUF:
2286 return arm_set_buf(fi, req);
2288 case RAW1394_REQ_ARM_GET_BUF:
2289 return arm_get_buf(fi, req);
2291 case RAW1394_REQ_RESET_NOTIFY:
2292 return reset_notification(fi, req);
2294 case RAW1394_REQ_ISO_LISTEN:
2295 handle_iso_listen(fi, req);
2296 return sizeof(struct raw1394_request);
2298 case RAW1394_REQ_FCP_LISTEN:
2299 handle_fcp_listen(fi, req);
2300 return sizeof(struct raw1394_request);
2302 case RAW1394_REQ_RESET_BUS:
2303 if (req->req.misc == RAW1394_LONG_RESET) {
2304 DBGMSG("busreset called (type: LONG)");
2305 hpsb_reset_bus(fi->host, LONG_RESET);
2306 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2307 return sizeof(struct raw1394_request);
2309 if (req->req.misc == RAW1394_SHORT_RESET) {
2310 DBGMSG("busreset called (type: SHORT)");
2311 hpsb_reset_bus(fi->host, SHORT_RESET);
2312 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2313 return sizeof(struct raw1394_request);
2315 /* error EINVAL (22) invalid argument */
2317 case RAW1394_REQ_GET_ROM:
2318 return get_config_rom(fi, req);
2320 case RAW1394_REQ_UPDATE_ROM:
2321 return update_config_rom(fi, req);
2323 case RAW1394_REQ_MODIFY_ROM:
2324 return modify_config_rom(fi, req);
2327 if (req->req.generation != get_hpsb_generation(fi->host)) {
2328 req->req.error = RAW1394_ERROR_GENERATION;
2329 req->req.generation = get_hpsb_generation(fi->host);
2330 req->req.length = 0;
2331 queue_complete_req(req);
2332 return sizeof(struct raw1394_request);
2335 switch (req->req.type) {
2336 case RAW1394_REQ_PHYPACKET:
2337 return write_phypacket(fi, req);
2338 case RAW1394_REQ_ASYNC_SEND:
2339 return handle_async_send(fi, req);
2342 if (req->req.length == 0) {
2343 req->req.error = RAW1394_ERROR_INVALID_ARG;
2344 queue_complete_req(req);
2345 return sizeof(struct raw1394_request);
2348 return handle_async_request(fi, req, node);
2352 static ssize_t raw1394_write(struct file *file, const char __user * buffer,
2353 size_t count, loff_t * offset_is_ignored)
2355 struct file_info *fi = (struct file_info *)file->private_data;
2356 struct pending_request *req;
2359 #ifdef CONFIG_COMPAT
2360 if (count == sizeof(struct compat_raw1394_req) &&
2361 sizeof(struct compat_raw1394_req) !=
2362 sizeof(struct raw1394_request)) {
2363 buffer = raw1394_compat_write(buffer);
2365 return PTR_ERR(buffer);
2368 if (count != sizeof(struct raw1394_request)) {
2372 req = alloc_pending_request();
2376 req->file_info = fi;
2378 if (copy_from_user(&req->req, buffer, sizeof(struct raw1394_request))) {
2379 free_pending_request(req);
2383 switch (fi->state) {
2385 retval = state_opened(fi, req);
2389 retval = state_initialized(fi, req);
2393 retval = state_connected(fi, req);
2398 free_pending_request(req);
2404 /* rawiso operations */
2406 /* check if any RAW1394_REQ_RAWISO_ACTIVITY event is already in the
2407 * completion queue (reqlists_lock must be taken) */
2408 static inline int __rawiso_event_in_queue(struct file_info *fi)
2410 struct pending_request *req;
2412 list_for_each_entry(req, &fi->req_complete, list)
2413 if (req->req.type == RAW1394_REQ_RAWISO_ACTIVITY)
2419 /* put a RAWISO_ACTIVITY event in the queue, if one isn't there already */
2420 static void queue_rawiso_event(struct file_info *fi)
2422 unsigned long flags;
2424 spin_lock_irqsave(&fi->reqlists_lock, flags);
2426 /* only one ISO activity event may be in the queue */
2427 if (!__rawiso_event_in_queue(fi)) {
2428 struct pending_request *req =
2429 __alloc_pending_request(SLAB_ATOMIC);
2432 req->file_info = fi;
2433 req->req.type = RAW1394_REQ_RAWISO_ACTIVITY;
2434 req->req.generation = get_hpsb_generation(fi->host);
2435 __queue_complete_req(req);
2437 /* on allocation failure, signal an overflow */
2438 if (fi->iso_handle) {
2439 atomic_inc(&fi->iso_handle->overflows);
2443 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2446 static void rawiso_activity_cb(struct hpsb_iso *iso)
2448 unsigned long flags;
2449 struct host_info *hi;
2450 struct file_info *fi;
2452 spin_lock_irqsave(&host_info_lock, flags);
2453 hi = find_host_info(iso->host);
2456 list_for_each_entry(fi, &hi->file_info_list, list) {
2457 if (fi->iso_handle == iso)
2458 queue_rawiso_event(fi);
2462 spin_unlock_irqrestore(&host_info_lock, flags);
2465 /* helper function - gather all the kernel iso status bits for returning to user-space */
2466 static void raw1394_iso_fill_status(struct hpsb_iso *iso,
2467 struct raw1394_iso_status *stat)
2469 stat->config.data_buf_size = iso->buf_size;
2470 stat->config.buf_packets = iso->buf_packets;
2471 stat->config.channel = iso->channel;
2472 stat->config.speed = iso->speed;
2473 stat->config.irq_interval = iso->irq_interval;
2474 stat->n_packets = hpsb_iso_n_ready(iso);
2475 stat->overflows = atomic_read(&iso->overflows);
2476 stat->xmit_cycle = iso->xmit_cycle;
2479 static int raw1394_iso_xmit_init(struct file_info *fi, void __user * uaddr)
2481 struct raw1394_iso_status stat;
2486 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2489 fi->iso_handle = hpsb_iso_xmit_init(fi->host,
2490 stat.config.data_buf_size,
2491 stat.config.buf_packets,
2492 stat.config.channel,
2494 stat.config.irq_interval,
2495 rawiso_activity_cb);
2496 if (!fi->iso_handle)
2499 fi->iso_state = RAW1394_ISO_XMIT;
2501 raw1394_iso_fill_status(fi->iso_handle, &stat);
2502 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2505 /* queue an event to get things started */
2506 rawiso_activity_cb(fi->iso_handle);
2511 static int raw1394_iso_recv_init(struct file_info *fi, void __user * uaddr)
2513 struct raw1394_iso_status stat;
2518 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2521 fi->iso_handle = hpsb_iso_recv_init(fi->host,
2522 stat.config.data_buf_size,
2523 stat.config.buf_packets,
2524 stat.config.channel,
2525 stat.config.dma_mode,
2526 stat.config.irq_interval,
2527 rawiso_activity_cb);
2528 if (!fi->iso_handle)
2531 fi->iso_state = RAW1394_ISO_RECV;
2533 raw1394_iso_fill_status(fi->iso_handle, &stat);
2534 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2539 static int raw1394_iso_get_status(struct file_info *fi, void __user * uaddr)
2541 struct raw1394_iso_status stat;
2542 struct hpsb_iso *iso = fi->iso_handle;
2544 raw1394_iso_fill_status(fi->iso_handle, &stat);
2545 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2548 /* reset overflow counter */
2549 atomic_set(&iso->overflows, 0);
2554 /* copy N packet_infos out of the ringbuffer into user-supplied array */
2555 static int raw1394_iso_recv_packets(struct file_info *fi, void __user * uaddr)
2557 struct raw1394_iso_packets upackets;
2558 unsigned int packet = fi->iso_handle->first_packet;
2561 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2564 if (upackets.n_packets > hpsb_iso_n_ready(fi->iso_handle))
2567 /* ensure user-supplied buffer is accessible and big enough */
2568 if (!access_ok(VERIFY_WRITE, upackets.infos,
2569 upackets.n_packets *
2570 sizeof(struct raw1394_iso_packet_info)))
2573 /* copy the packet_infos out */
2574 for (i = 0; i < upackets.n_packets; i++) {
2575 if (__copy_to_user(&upackets.infos[i],
2576 &fi->iso_handle->infos[packet],
2577 sizeof(struct raw1394_iso_packet_info)))
2580 packet = (packet + 1) % fi->iso_handle->buf_packets;
2586 /* copy N packet_infos from user to ringbuffer, and queue them for transmission */
2587 static int raw1394_iso_send_packets(struct file_info *fi, void __user * uaddr)
2589 struct raw1394_iso_packets upackets;
2592 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2595 if (upackets.n_packets >= fi->iso_handle->buf_packets)
2598 if (upackets.n_packets >= hpsb_iso_n_ready(fi->iso_handle))
2601 /* ensure user-supplied buffer is accessible and big enough */
2602 if (!access_ok(VERIFY_READ, upackets.infos,
2603 upackets.n_packets *
2604 sizeof(struct raw1394_iso_packet_info)))
2607 /* copy the infos structs in and queue the packets */
2608 for (i = 0; i < upackets.n_packets; i++) {
2609 struct raw1394_iso_packet_info info;
2611 if (__copy_from_user(&info, &upackets.infos[i],
2612 sizeof(struct raw1394_iso_packet_info)))
2615 rv = hpsb_iso_xmit_queue_packet(fi->iso_handle, info.offset,
2616 info.len, info.tag, info.sy);
2624 static void raw1394_iso_shutdown(struct file_info *fi)
2627 hpsb_iso_shutdown(fi->iso_handle);
2629 fi->iso_handle = NULL;
2630 fi->iso_state = RAW1394_ISO_INACTIVE;
2633 /* mmap the rawiso xmit/recv buffer */
2634 static int raw1394_mmap(struct file *file, struct vm_area_struct *vma)
2636 struct file_info *fi = file->private_data;
2638 if (fi->iso_state == RAW1394_ISO_INACTIVE)
2641 return dma_region_mmap(&fi->iso_handle->data_buf, file, vma);
2644 /* ioctl is only used for rawiso operations */
2645 static int raw1394_ioctl(struct inode *inode, struct file *file,
2646 unsigned int cmd, unsigned long arg)
2648 struct file_info *fi = file->private_data;
2649 void __user *argp = (void __user *)arg;
2651 switch (fi->iso_state) {
2652 case RAW1394_ISO_INACTIVE:
2654 case RAW1394_IOC_ISO_XMIT_INIT:
2655 return raw1394_iso_xmit_init(fi, argp);
2656 case RAW1394_IOC_ISO_RECV_INIT:
2657 return raw1394_iso_recv_init(fi, argp);
2662 case RAW1394_ISO_RECV:
2664 case RAW1394_IOC_ISO_RECV_START:{
2665 /* copy args from user-space */
2668 (&args[0], argp, sizeof(args)))
2670 return hpsb_iso_recv_start(fi->iso_handle,
2674 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2675 hpsb_iso_stop(fi->iso_handle);
2677 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL:
2678 return hpsb_iso_recv_listen_channel(fi->iso_handle,
2680 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
2681 return hpsb_iso_recv_unlisten_channel(fi->iso_handle,
2683 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:{
2684 /* copy the u64 from user-space */
2686 if (copy_from_user(&mask, argp, sizeof(mask)))
2688 return hpsb_iso_recv_set_channel_mask(fi->
2692 case RAW1394_IOC_ISO_GET_STATUS:
2693 return raw1394_iso_get_status(fi, argp);
2694 case RAW1394_IOC_ISO_RECV_PACKETS:
2695 return raw1394_iso_recv_packets(fi, argp);
2696 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
2697 return hpsb_iso_recv_release_packets(fi->iso_handle,
2699 case RAW1394_IOC_ISO_RECV_FLUSH:
2700 return hpsb_iso_recv_flush(fi->iso_handle);
2701 case RAW1394_IOC_ISO_SHUTDOWN:
2702 raw1394_iso_shutdown(fi);
2704 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2705 queue_rawiso_event(fi);
2709 case RAW1394_ISO_XMIT:
2711 case RAW1394_IOC_ISO_XMIT_START:{
2712 /* copy two ints from user-space */
2715 (&args[0], argp, sizeof(args)))
2717 return hpsb_iso_xmit_start(fi->iso_handle,
2720 case RAW1394_IOC_ISO_XMIT_SYNC:
2721 return hpsb_iso_xmit_sync(fi->iso_handle);
2722 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2723 hpsb_iso_stop(fi->iso_handle);
2725 case RAW1394_IOC_ISO_GET_STATUS:
2726 return raw1394_iso_get_status(fi, argp);
2727 case RAW1394_IOC_ISO_XMIT_PACKETS:
2728 return raw1394_iso_send_packets(fi, argp);
2729 case RAW1394_IOC_ISO_SHUTDOWN:
2730 raw1394_iso_shutdown(fi);
2732 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2733 queue_rawiso_event(fi);
2744 static unsigned int raw1394_poll(struct file *file, poll_table * pt)
2746 struct file_info *fi = file->private_data;
2747 unsigned int mask = POLLOUT | POLLWRNORM;
2748 unsigned long flags;
2750 poll_wait(file, &fi->poll_wait_complete, pt);
2752 spin_lock_irqsave(&fi->reqlists_lock, flags);
2753 if (!list_empty(&fi->req_complete)) {
2754 mask |= POLLIN | POLLRDNORM;
2756 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2761 static int raw1394_open(struct inode *inode, struct file *file)
2763 struct file_info *fi;
2765 fi = kzalloc(sizeof(*fi), SLAB_KERNEL);
2769 fi->notification = (u8) RAW1394_NOTIFY_ON; /* busreset notification */
2771 INIT_LIST_HEAD(&fi->list);
2773 INIT_LIST_HEAD(&fi->req_pending);
2774 INIT_LIST_HEAD(&fi->req_complete);
2775 sema_init(&fi->complete_sem, 0);
2776 spin_lock_init(&fi->reqlists_lock);
2777 init_waitqueue_head(&fi->poll_wait_complete);
2778 INIT_LIST_HEAD(&fi->addr_list);
2780 file->private_data = fi;
2785 static int raw1394_release(struct inode *inode, struct file *file)
2787 struct file_info *fi = file->private_data;
2788 struct list_head *lh;
2789 struct pending_request *req;
2790 int done = 0, i, fail = 0;
2792 struct list_head *entry;
2793 struct arm_addr *addr = NULL;
2794 struct host_info *hi;
2795 struct file_info *fi_hlp = NULL;
2796 struct arm_addr *arm_addr = NULL;
2799 unsigned long flags;
2801 if (fi->iso_state != RAW1394_ISO_INACTIVE)
2802 raw1394_iso_shutdown(fi);
2804 for (i = 0; i < 64; i++) {
2805 if (fi->listen_channels & (1ULL << i)) {
2806 hpsb_unlisten_channel(&raw1394_highlevel, fi->host, i);
2810 spin_lock_irqsave(&host_info_lock, flags);
2811 fi->listen_channels = 0;
2814 /* set address-entries invalid */
2816 while (!list_empty(&fi->addr_list)) {
2818 lh = fi->addr_list.next;
2819 addr = list_entry(lh, struct arm_addr, addr_list);
2820 /* another host with valid address-entry containing
2821 same addressrange? */
2822 list_for_each_entry(hi, &host_info_list, list) {
2823 if (hi->host != fi->host) {
2824 list_for_each_entry(fi_hlp, &hi->file_info_list,
2826 entry = fi_hlp->addr_list.next;
2827 while (entry != &(fi_hlp->addr_list)) {
2828 arm_addr = list_entry(entry, struct
2831 if (arm_addr->start ==
2834 ("raw1394_release: "
2835 "another host ownes "
2836 "same addressrange");
2840 entry = entry->next;
2848 if (!another_host) {
2849 DBGMSG("raw1394_release: call hpsb_arm_unregister");
2851 hpsb_unregister_addrspace(&raw1394_highlevel,
2852 fi->host, addr->start);
2856 "raw1394_release arm_Unregister failed\n");
2859 DBGMSG("raw1394_release: delete addr_entry from list");
2860 list_del(&addr->addr_list);
2861 vfree(addr->addr_space_buffer);
2864 spin_unlock_irqrestore(&host_info_lock, flags);
2866 printk(KERN_ERR "raw1394: during addr_list-release "
2867 "error(s) occurred \n");
2871 spin_lock_irqsave(&fi->reqlists_lock, flags);
2873 while (!list_empty(&fi->req_complete)) {
2874 lh = fi->req_complete.next;
2877 req = list_entry(lh, struct pending_request, list);
2879 free_pending_request(req);
2882 if (list_empty(&fi->req_pending))
2885 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2888 down_interruptible(&fi->complete_sem);
2891 /* Remove any sub-trees left by user space programs */
2892 for (i = 0; i < RAW1394_MAX_USER_CSR_DIRS; i++) {
2893 struct csr1212_dentry *dentry;
2894 if (!fi->csr1212_dirs[i])
2897 fi->csr1212_dirs[i]->value.directory.dentries_head; dentry;
2898 dentry = dentry->next) {
2899 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2903 csr1212_release_keyval(fi->csr1212_dirs[i]);
2904 fi->csr1212_dirs[i] = NULL;
2908 if ((csr_mod || fi->cfgrom_upd)
2909 && hpsb_update_config_rom_image(fi->host) < 0)
2911 ("Failed to generate Configuration ROM image for host %d",
2914 if (fi->state == connected) {
2915 spin_lock_irqsave(&host_info_lock, flags);
2916 list_del(&fi->list);
2917 spin_unlock_irqrestore(&host_info_lock, flags);
2919 put_device(&fi->host->device);
2927 /*** HOTPLUG STUFF **********************************************************/
2929 * Export information about protocols/devices supported by this driver.
2931 static struct ieee1394_device_id raw1394_id_table[] = {
2933 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2934 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
2935 .version = AVC_SW_VERSION_ENTRY & 0xffffff},
2937 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2938 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2939 .version = CAMERA_SW_VERSION_ENTRY & 0xffffff},
2941 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2942 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2943 .version = (CAMERA_SW_VERSION_ENTRY + 1) & 0xffffff},
2945 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2946 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2947 .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff},
2951 MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table);
2953 static struct hpsb_protocol_driver raw1394_driver = {
2954 .name = "raw1394 Driver",
2955 .id_table = raw1394_id_table,
2958 .bus = &ieee1394_bus_type,
2962 /******************************************************************************/
2964 static struct hpsb_highlevel raw1394_highlevel = {
2965 .name = RAW1394_DEVICE_NAME,
2966 .add_host = add_host,
2967 .remove_host = remove_host,
2968 .host_reset = host_reset,
2969 .iso_receive = iso_receive,
2970 .fcp_request = fcp_request,
2973 static struct cdev raw1394_cdev;
2974 static struct file_operations raw1394_fops = {
2975 .owner = THIS_MODULE,
2976 .read = raw1394_read,
2977 .write = raw1394_write,
2978 .mmap = raw1394_mmap,
2979 .ioctl = raw1394_ioctl,
2980 // .compat_ioctl = ... someone needs to do this
2981 .poll = raw1394_poll,
2982 .open = raw1394_open,
2983 .release = raw1394_release,
2986 static int __init init_raw1394(void)
2990 hpsb_register_highlevel(&raw1394_highlevel);
2993 (class_device_create
2994 (hpsb_protocol_class, NULL,
2995 MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16), NULL,
2996 RAW1394_DEVICE_NAME))) {
3001 cdev_init(&raw1394_cdev, &raw1394_fops);
3002 raw1394_cdev.owner = THIS_MODULE;
3003 kobject_set_name(&raw1394_cdev.kobj, RAW1394_DEVICE_NAME);
3004 ret = cdev_add(&raw1394_cdev, IEEE1394_RAW1394_DEV, 1);
3006 HPSB_ERR("raw1394 failed to register minor device block");
3010 HPSB_INFO("raw1394: /dev/%s device initialized", RAW1394_DEVICE_NAME);
3012 ret = hpsb_register_protocol(&raw1394_driver);
3014 HPSB_ERR("raw1394: failed to register protocol");
3015 cdev_del(&raw1394_cdev);
3022 class_device_destroy(hpsb_protocol_class,
3023 MKDEV(IEEE1394_MAJOR,
3024 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
3026 hpsb_unregister_highlevel(&raw1394_highlevel);
3031 static void __exit cleanup_raw1394(void)
3033 class_device_destroy(hpsb_protocol_class,
3034 MKDEV(IEEE1394_MAJOR,
3035 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
3036 cdev_del(&raw1394_cdev);
3037 hpsb_unregister_highlevel(&raw1394_highlevel);
3038 hpsb_unregister_protocol(&raw1394_driver);
3041 module_init(init_raw1394);
3042 module_exit(cleanup_raw1394);
3043 MODULE_LICENSE("GPL");