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/interrupt.h>
39 #include <linux/vmalloc.h>
40 #include <linux/cdev.h>
41 #include <asm/uaccess.h>
42 #include <asm/atomic.h>
43 #include <linux/compat.h>
46 #include "highlevel.h"
49 #include "ieee1394_core.h"
50 #include "ieee1394_hotplug.h"
51 #include "ieee1394_transactions.h"
52 #include "ieee1394_types.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...) do {} while (0)
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 #include <asm/current.h>
102 static void print_old_iso_deprecation(void)
106 if (p == current->pid)
109 printk(KERN_WARNING "raw1394: WARNING - Program \"%s\" uses unsupported"
110 " isochronous request types which will be removed in a next"
111 " kernel release\n", current->comm);
112 printk(KERN_WARNING "raw1394: Update your software to use libraw1394's"
113 " newer interface\n");
116 static struct pending_request *__alloc_pending_request(gfp_t flags)
118 struct pending_request *req;
120 req = kzalloc(sizeof(*req), flags);
122 INIT_LIST_HEAD(&req->list);
127 static inline struct pending_request *alloc_pending_request(void)
129 return __alloc_pending_request(GFP_KERNEL);
132 static void free_pending_request(struct pending_request *req)
135 if (atomic_dec_and_test(&req->ibs->refcount)) {
136 atomic_sub(req->ibs->data_size, &iso_buffer_size);
139 } else if (req->free_data) {
142 hpsb_free_packet(req->packet);
146 /* fi->reqlists_lock must be taken */
147 static void __queue_complete_req(struct pending_request *req)
149 struct file_info *fi = req->file_info;
151 list_move_tail(&req->list, &fi->req_complete);
152 wake_up(&fi->wait_complete);
155 static void queue_complete_req(struct pending_request *req)
158 struct file_info *fi = req->file_info;
160 spin_lock_irqsave(&fi->reqlists_lock, flags);
161 __queue_complete_req(req);
162 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
165 static void queue_complete_cb(struct pending_request *req)
167 struct hpsb_packet *packet = req->packet;
168 int rcode = (packet->header[1] >> 12) & 0xf;
170 switch (packet->ack_code) {
172 case ACKX_SEND_ERROR:
173 req->req.error = RAW1394_ERROR_SEND_ERROR;
176 req->req.error = RAW1394_ERROR_ABORTED;
179 req->req.error = RAW1394_ERROR_TIMEOUT;
182 req->req.error = (packet->ack_code << 16) | rcode;
186 if (!((packet->ack_code == ACK_PENDING) && (rcode == RCODE_COMPLETE))) {
190 if ((req->req.type == RAW1394_REQ_ASYNC_READ) ||
191 (req->req.type == RAW1394_REQ_ASYNC_WRITE) ||
192 (req->req.type == RAW1394_REQ_ASYNC_STREAM) ||
193 (req->req.type == RAW1394_REQ_LOCK) ||
194 (req->req.type == RAW1394_REQ_LOCK64))
195 hpsb_free_tlabel(packet);
197 queue_complete_req(req);
200 static void add_host(struct hpsb_host *host)
202 struct host_info *hi;
205 hi = kmalloc(sizeof(*hi), GFP_KERNEL);
208 INIT_LIST_HEAD(&hi->list);
210 INIT_LIST_HEAD(&hi->file_info_list);
212 spin_lock_irqsave(&host_info_lock, flags);
213 list_add_tail(&hi->list, &host_info_list);
215 spin_unlock_irqrestore(&host_info_lock, flags);
218 atomic_inc(&internal_generation);
221 static struct host_info *find_host_info(struct hpsb_host *host)
223 struct host_info *hi;
225 list_for_each_entry(hi, &host_info_list, list)
226 if (hi->host == host)
232 static void remove_host(struct hpsb_host *host)
234 struct host_info *hi;
237 spin_lock_irqsave(&host_info_lock, flags);
238 hi = find_host_info(host);
244 FIXME: address ranges should be removed
245 and fileinfo states should be initialized
246 (including setting generation to
247 internal-generation ...)
250 spin_unlock_irqrestore(&host_info_lock, flags);
253 printk(KERN_ERR "raw1394: attempt to remove unknown host "
260 atomic_inc(&internal_generation);
263 static void host_reset(struct hpsb_host *host)
266 struct host_info *hi;
267 struct file_info *fi;
268 struct pending_request *req;
270 spin_lock_irqsave(&host_info_lock, flags);
271 hi = find_host_info(host);
274 list_for_each_entry(fi, &hi->file_info_list, list) {
275 if (fi->notification == RAW1394_NOTIFY_ON) {
276 req = __alloc_pending_request(GFP_ATOMIC);
280 req->req.type = RAW1394_REQ_BUS_RESET;
281 req->req.generation =
282 get_hpsb_generation(host);
283 req->req.misc = (host->node_id << 16)
285 if (fi->protocol_version > 3) {
292 queue_complete_req(req);
297 spin_unlock_irqrestore(&host_info_lock, flags);
300 static void iso_receive(struct hpsb_host *host, int channel, quadlet_t * data,
304 struct host_info *hi;
305 struct file_info *fi;
306 struct pending_request *req, *req_next;
307 struct iso_block_store *ibs = NULL;
310 if ((atomic_read(&iso_buffer_size) + length) > iso_buffer_max) {
311 HPSB_INFO("dropped iso packet");
315 spin_lock_irqsave(&host_info_lock, flags);
316 hi = find_host_info(host);
319 list_for_each_entry(fi, &hi->file_info_list, list) {
320 if (!(fi->listen_channels & (1ULL << channel)))
323 req = __alloc_pending_request(GFP_ATOMIC);
328 ibs = kmalloc(sizeof(*ibs) + length,
335 atomic_add(length, &iso_buffer_size);
336 atomic_set(&ibs->refcount, 0);
337 ibs->data_size = length;
338 memcpy(ibs->data, data, length);
341 atomic_inc(&ibs->refcount);
345 req->data = ibs->data;
346 req->req.type = RAW1394_REQ_ISO_RECEIVE;
347 req->req.generation = get_hpsb_generation(host);
349 req->req.recvb = ptr2int(fi->iso_buffer);
350 req->req.length = min(length, fi->iso_buffer_length);
352 list_add_tail(&req->list, &reqs);
355 spin_unlock_irqrestore(&host_info_lock, flags);
357 list_for_each_entry_safe(req, req_next, &reqs, list)
358 queue_complete_req(req);
361 static void fcp_request(struct hpsb_host *host, int nodeid, int direction,
362 int cts, u8 * data, size_t length)
365 struct host_info *hi;
366 struct file_info *fi;
367 struct pending_request *req, *req_next;
368 struct iso_block_store *ibs = NULL;
371 if ((atomic_read(&iso_buffer_size) + length) > iso_buffer_max) {
372 HPSB_INFO("dropped fcp request");
376 spin_lock_irqsave(&host_info_lock, flags);
377 hi = find_host_info(host);
380 list_for_each_entry(fi, &hi->file_info_list, list) {
384 req = __alloc_pending_request(GFP_ATOMIC);
389 ibs = kmalloc(sizeof(*ibs) + length,
396 atomic_add(length, &iso_buffer_size);
397 atomic_set(&ibs->refcount, 0);
398 ibs->data_size = length;
399 memcpy(ibs->data, data, length);
402 atomic_inc(&ibs->refcount);
406 req->data = ibs->data;
407 req->req.type = RAW1394_REQ_FCP_REQUEST;
408 req->req.generation = get_hpsb_generation(host);
409 req->req.misc = nodeid | (direction << 16);
410 req->req.recvb = ptr2int(fi->fcp_buffer);
411 req->req.length = length;
413 list_add_tail(&req->list, &reqs);
416 spin_unlock_irqrestore(&host_info_lock, flags);
418 list_for_each_entry_safe(req, req_next, &reqs, list)
419 queue_complete_req(req);
423 struct compat_raw1394_req {
437 } __attribute__((packed));
439 static const char __user *raw1394_compat_write(const char __user *buf)
441 struct compat_raw1394_req __user *cr = (typeof(cr)) buf;
442 struct raw1394_request __user *r;
443 r = compat_alloc_user_space(sizeof(struct raw1394_request));
445 #define C(x) __copy_in_user(&r->x, &cr->x, sizeof(r->x))
447 if (copy_in_user(r, cr, sizeof(struct compat_raw1394_req)) ||
452 return ERR_PTR(-EFAULT);
453 return (const char __user *)r;
457 #define P(x) __put_user(r->x, &cr->x)
460 raw1394_compat_read(const char __user *buf, struct raw1394_request *r)
462 struct compat_raw1394_req __user *cr = (typeof(cr)) r;
463 if (!access_ok(VERIFY_WRITE, cr, sizeof(struct compat_raw1394_req)) ||
474 return sizeof(struct compat_raw1394_req);
480 /* get next completed request (caller must hold fi->reqlists_lock) */
481 static inline struct pending_request *__next_complete_req(struct file_info *fi)
483 struct list_head *lh;
484 struct pending_request *req = NULL;
486 if (!list_empty(&fi->req_complete)) {
487 lh = fi->req_complete.next;
489 req = list_entry(lh, struct pending_request, list);
494 /* atomically get next completed request */
495 static struct pending_request *next_complete_req(struct file_info *fi)
498 struct pending_request *req;
500 spin_lock_irqsave(&fi->reqlists_lock, flags);
501 req = __next_complete_req(fi);
502 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
506 static ssize_t raw1394_read(struct file *file, char __user * buffer,
507 size_t count, loff_t * offset_is_ignored)
509 struct file_info *fi = (struct file_info *)file->private_data;
510 struct pending_request *req;
514 if (count == sizeof(struct compat_raw1394_req)) {
518 if (count != sizeof(struct raw1394_request)) {
522 if (!access_ok(VERIFY_WRITE, buffer, count)) {
526 if (file->f_flags & O_NONBLOCK) {
527 if (!(req = next_complete_req(fi)))
531 * NB: We call the macro wait_event_interruptible() with a
532 * condition argument with side effect. This is only possible
533 * because the side effect does not occur until the condition
534 * became true, and wait_event_interruptible() won't evaluate
535 * the condition again after that.
537 if (wait_event_interruptible(fi->wait_complete,
538 (req = next_complete_req(fi))))
542 if (req->req.length) {
543 if (copy_to_user(int2ptr(req->req.recvb), req->data,
545 req->req.error = RAW1394_ERROR_MEMFAULT;
550 if (count == sizeof(struct compat_raw1394_req) &&
551 sizeof(struct compat_raw1394_req) !=
552 sizeof(struct raw1394_request)) {
553 ret = raw1394_compat_read(buffer, &req->req);
557 if (copy_to_user(buffer, &req->req, sizeof(req->req))) {
561 ret = (ssize_t) sizeof(struct raw1394_request);
564 free_pending_request(req);
568 static int state_opened(struct file_info *fi, struct pending_request *req)
570 if (req->req.type == RAW1394_REQ_INITIALIZE) {
571 switch (req->req.misc) {
572 case RAW1394_KERNELAPI_VERSION:
574 fi->state = initialized;
575 fi->protocol_version = req->req.misc;
576 req->req.error = RAW1394_ERROR_NONE;
577 req->req.generation = atomic_read(&internal_generation);
581 req->req.error = RAW1394_ERROR_COMPAT;
582 req->req.misc = RAW1394_KERNELAPI_VERSION;
585 req->req.error = RAW1394_ERROR_STATE_ORDER;
589 queue_complete_req(req);
590 return sizeof(struct raw1394_request);
593 static int state_initialized(struct file_info *fi, struct pending_request *req)
596 struct host_info *hi;
597 struct raw1394_khost_list *khl;
599 if (req->req.generation != atomic_read(&internal_generation)) {
600 req->req.error = RAW1394_ERROR_GENERATION;
601 req->req.generation = atomic_read(&internal_generation);
603 queue_complete_req(req);
604 return sizeof(struct raw1394_request);
607 switch (req->req.type) {
608 case RAW1394_REQ_LIST_CARDS:
609 spin_lock_irqsave(&host_info_lock, flags);
610 khl = kmalloc(sizeof(*khl) * host_count, GFP_ATOMIC);
613 req->req.misc = host_count;
614 req->data = (quadlet_t *) khl;
616 list_for_each_entry(hi, &host_info_list, list) {
617 khl->nodes = hi->host->node_count;
618 strcpy(khl->name, hi->host->driver->name);
622 spin_unlock_irqrestore(&host_info_lock, flags);
625 req->req.error = RAW1394_ERROR_NONE;
626 req->req.length = min(req->req.length,
628 (struct raw1394_khost_list)
636 case RAW1394_REQ_SET_CARD:
637 spin_lock_irqsave(&host_info_lock, flags);
638 if (req->req.misc >= host_count) {
639 req->req.error = RAW1394_ERROR_INVALID_ARG;
642 list_for_each_entry(hi, &host_info_list, list)
643 if (!req->req.misc--)
645 get_device(&hi->host->device); /* FIXME handle failure case */
646 list_add_tail(&fi->list, &hi->file_info_list);
648 /* prevent unloading of the host's low-level driver */
649 if (!try_module_get(hi->host->driver->owner)) {
650 req->req.error = RAW1394_ERROR_ABORTED;
655 fi->state = connected;
657 req->req.error = RAW1394_ERROR_NONE;
658 req->req.generation = get_hpsb_generation(fi->host);
659 req->req.misc = (fi->host->node_id << 16)
660 | fi->host->node_count;
661 if (fi->protocol_version > 3)
662 req->req.misc |= NODEID_TO_NODE(fi->host->irm_id) << 8;
664 spin_unlock_irqrestore(&host_info_lock, flags);
670 req->req.error = RAW1394_ERROR_STATE_ORDER;
675 queue_complete_req(req);
676 return sizeof(struct raw1394_request);
679 static void handle_iso_listen(struct file_info *fi, struct pending_request *req)
681 int channel = req->req.misc;
683 if ((channel > 63) || (channel < -64)) {
684 req->req.error = RAW1394_ERROR_INVALID_ARG;
685 } else if (channel >= 0) {
686 /* allocate channel req.misc */
687 if (fi->listen_channels & (1ULL << channel)) {
688 req->req.error = RAW1394_ERROR_ALREADY;
690 if (hpsb_listen_channel
691 (&raw1394_highlevel, fi->host, channel)) {
692 req->req.error = RAW1394_ERROR_ALREADY;
694 fi->listen_channels |= 1ULL << channel;
695 fi->iso_buffer = int2ptr(req->req.recvb);
696 fi->iso_buffer_length = req->req.length;
700 /* deallocate channel (one's complement neg) req.misc */
703 if (fi->listen_channels & (1ULL << channel)) {
704 hpsb_unlisten_channel(&raw1394_highlevel, fi->host,
706 fi->listen_channels &= ~(1ULL << channel);
708 req->req.error = RAW1394_ERROR_INVALID_ARG;
713 queue_complete_req(req);
716 static void handle_fcp_listen(struct file_info *fi, struct pending_request *req)
719 if (fi->fcp_buffer) {
720 req->req.error = RAW1394_ERROR_ALREADY;
722 fi->fcp_buffer = int2ptr(req->req.recvb);
725 if (!fi->fcp_buffer) {
726 req->req.error = RAW1394_ERROR_ALREADY;
728 fi->fcp_buffer = NULL;
733 queue_complete_req(req);
736 static int handle_async_request(struct file_info *fi,
737 struct pending_request *req, int node)
740 struct hpsb_packet *packet = NULL;
741 u64 addr = req->req.address & 0xffffffffffffULL;
743 switch (req->req.type) {
744 case RAW1394_REQ_ASYNC_READ:
745 DBGMSG("read_request called");
747 hpsb_make_readpacket(fi->host, node, addr, req->req.length);
752 if (req->req.length == 4)
753 req->data = &packet->header[3];
755 req->data = packet->data;
759 case RAW1394_REQ_ASYNC_WRITE:
760 DBGMSG("write_request called");
762 packet = hpsb_make_writepacket(fi->host, node, addr, NULL,
767 if (req->req.length == 4) {
769 (&packet->header[3], int2ptr(req->req.sendb),
771 req->req.error = RAW1394_ERROR_MEMFAULT;
774 (packet->data, int2ptr(req->req.sendb),
776 req->req.error = RAW1394_ERROR_MEMFAULT;
782 case RAW1394_REQ_ASYNC_STREAM:
783 DBGMSG("stream_request called");
786 hpsb_make_streampacket(fi->host, NULL, req->req.length,
787 node & 0x3f /*channel */ ,
788 (req->req.misc >> 16) & 0x3,
789 req->req.misc & 0xf);
793 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
795 req->req.error = RAW1394_ERROR_MEMFAULT;
800 case RAW1394_REQ_LOCK:
801 DBGMSG("lock_request called");
802 if ((req->req.misc == EXTCODE_FETCH_ADD)
803 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
804 if (req->req.length != 4) {
805 req->req.error = RAW1394_ERROR_INVALID_ARG;
809 if (req->req.length != 8) {
810 req->req.error = RAW1394_ERROR_INVALID_ARG;
815 packet = hpsb_make_lockpacket(fi->host, node, addr,
816 req->req.misc, NULL, 0);
820 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
822 req->req.error = RAW1394_ERROR_MEMFAULT;
826 req->data = packet->data;
830 case RAW1394_REQ_LOCK64:
831 DBGMSG("lock64_request called");
832 if ((req->req.misc == EXTCODE_FETCH_ADD)
833 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
834 if (req->req.length != 8) {
835 req->req.error = RAW1394_ERROR_INVALID_ARG;
839 if (req->req.length != 16) {
840 req->req.error = RAW1394_ERROR_INVALID_ARG;
844 packet = hpsb_make_lock64packet(fi->host, node, addr,
845 req->req.misc, NULL, 0);
849 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
851 req->req.error = RAW1394_ERROR_MEMFAULT;
855 req->data = packet->data;
860 req->req.error = RAW1394_ERROR_STATE_ORDER;
863 req->packet = packet;
865 if (req->req.error) {
867 queue_complete_req(req);
868 return sizeof(struct raw1394_request);
871 hpsb_set_packet_complete_task(packet,
872 (void (*)(void *))queue_complete_cb, req);
874 spin_lock_irqsave(&fi->reqlists_lock, flags);
875 list_add_tail(&req->list, &fi->req_pending);
876 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
878 packet->generation = req->req.generation;
880 if (hpsb_send_packet(packet) < 0) {
881 req->req.error = RAW1394_ERROR_SEND_ERROR;
883 hpsb_free_tlabel(packet);
884 queue_complete_req(req);
886 return sizeof(struct raw1394_request);
889 static int handle_iso_send(struct file_info *fi, struct pending_request *req,
893 struct hpsb_packet *packet;
895 packet = hpsb_make_isopacket(fi->host, req->req.length, channel & 0x3f,
896 (req->req.misc >> 16) & 0x3,
897 req->req.misc & 0xf);
901 packet->speed_code = req->req.address & 0x3;
903 req->packet = packet;
905 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
907 req->req.error = RAW1394_ERROR_MEMFAULT;
909 queue_complete_req(req);
910 return sizeof(struct raw1394_request);
914 hpsb_set_packet_complete_task(packet,
915 (void (*)(void *))queue_complete_req,
918 spin_lock_irqsave(&fi->reqlists_lock, flags);
919 list_add_tail(&req->list, &fi->req_pending);
920 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
922 /* Update the generation of the packet just before sending. */
923 packet->generation = req->req.generation;
925 if (hpsb_send_packet(packet) < 0) {
926 req->req.error = RAW1394_ERROR_SEND_ERROR;
927 queue_complete_req(req);
930 return sizeof(struct raw1394_request);
933 static int handle_async_send(struct file_info *fi, struct pending_request *req)
936 struct hpsb_packet *packet;
937 int header_length = req->req.misc & 0xffff;
938 int expect_response = req->req.misc >> 16;
941 if (header_length > req->req.length || header_length < 12 ||
942 header_length > FIELD_SIZEOF(struct hpsb_packet, header)) {
943 req->req.error = RAW1394_ERROR_INVALID_ARG;
945 queue_complete_req(req);
946 return sizeof(struct raw1394_request);
949 data_size = req->req.length - header_length;
950 packet = hpsb_alloc_packet(data_size);
951 req->packet = packet;
955 if (copy_from_user(packet->header, int2ptr(req->req.sendb),
957 req->req.error = RAW1394_ERROR_MEMFAULT;
959 queue_complete_req(req);
960 return sizeof(struct raw1394_request);
964 (packet->data, int2ptr(req->req.sendb) + header_length,
966 req->req.error = RAW1394_ERROR_MEMFAULT;
968 queue_complete_req(req);
969 return sizeof(struct raw1394_request);
972 packet->type = hpsb_async;
973 packet->node_id = packet->header[0] >> 16;
974 packet->tcode = (packet->header[0] >> 4) & 0xf;
975 packet->tlabel = (packet->header[0] >> 10) & 0x3f;
976 packet->host = fi->host;
977 packet->expect_response = expect_response;
978 packet->header_size = header_length;
979 packet->data_size = data_size;
982 hpsb_set_packet_complete_task(packet,
983 (void (*)(void *))queue_complete_cb, req);
985 spin_lock_irqsave(&fi->reqlists_lock, flags);
986 list_add_tail(&req->list, &fi->req_pending);
987 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
989 /* Update the generation of the packet just before sending. */
990 packet->generation = req->req.generation;
992 if (hpsb_send_packet(packet) < 0) {
993 req->req.error = RAW1394_ERROR_SEND_ERROR;
994 queue_complete_req(req);
997 return sizeof(struct raw1394_request);
1000 static int arm_read(struct hpsb_host *host, int nodeid, quadlet_t * buffer,
1001 u64 addr, size_t length, u16 flags)
1003 unsigned long irqflags;
1004 struct pending_request *req;
1005 struct host_info *hi;
1006 struct file_info *fi = NULL;
1007 struct list_head *entry;
1008 struct arm_addr *arm_addr = NULL;
1009 struct arm_request *arm_req = NULL;
1010 struct arm_response *arm_resp = NULL;
1011 int found = 0, size = 0, rcode = -1;
1012 struct arm_request_response *arm_req_resp = NULL;
1014 DBGMSG("arm_read called by node: %X"
1015 "addr: %4.4x %8.8x length: %Zu", nodeid,
1016 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
1018 spin_lock_irqsave(&host_info_lock, irqflags);
1019 hi = find_host_info(host); /* search address-entry */
1021 list_for_each_entry(fi, &hi->file_info_list, list) {
1022 entry = fi->addr_list.next;
1023 while (entry != &(fi->addr_list)) {
1025 list_entry(entry, struct arm_addr,
1027 if (((arm_addr->start) <= (addr))
1028 && ((arm_addr->end) >= (addr + length))) {
1032 entry = entry->next;
1041 printk(KERN_ERR "raw1394: arm_read FAILED addr_entry not found"
1042 " -> rcode_address_error\n");
1043 spin_unlock_irqrestore(&host_info_lock, irqflags);
1044 return (RCODE_ADDRESS_ERROR);
1046 DBGMSG("arm_read addr_entry FOUND");
1048 if (arm_addr->rec_length < length) {
1049 DBGMSG("arm_read blocklength too big -> rcode_data_error");
1050 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
1053 if (arm_addr->access_rights & ARM_READ) {
1054 if (!(arm_addr->client_transactions & ARM_READ)) {
1056 (arm_addr->addr_space_buffer) + (addr -
1060 DBGMSG("arm_read -> (rcode_complete)");
1061 rcode = RCODE_COMPLETE;
1064 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1065 DBGMSG("arm_read -> rcode_type_error (access denied)");
1068 if (arm_addr->notification_options & ARM_READ) {
1069 DBGMSG("arm_read -> entering notification-section");
1070 req = __alloc_pending_request(GFP_ATOMIC);
1072 DBGMSG("arm_read -> rcode_conflict_error");
1073 spin_unlock_irqrestore(&host_info_lock, irqflags);
1074 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1075 The request may be retried */
1077 if (rcode == RCODE_COMPLETE) {
1079 sizeof(struct arm_request) +
1080 sizeof(struct arm_response) +
1081 length * sizeof(byte_t) +
1082 sizeof(struct arm_request_response);
1085 sizeof(struct arm_request) +
1086 sizeof(struct arm_response) +
1087 sizeof(struct arm_request_response);
1089 req->data = kmalloc(size, GFP_ATOMIC);
1091 free_pending_request(req);
1092 DBGMSG("arm_read -> rcode_conflict_error");
1093 spin_unlock_irqrestore(&host_info_lock, irqflags);
1094 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1095 The request may be retried */
1098 req->file_info = fi;
1099 req->req.type = RAW1394_REQ_ARM;
1100 req->req.generation = get_hpsb_generation(host);
1102 (((length << 16) & (0xFFFF0000)) | (ARM_READ & 0xFF));
1103 req->req.tag = arm_addr->arm_tag;
1104 req->req.recvb = arm_addr->recvb;
1105 req->req.length = size;
1106 arm_req_resp = (struct arm_request_response *)(req->data);
1107 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1110 arm_request_response)));
1112 (struct arm_response *)((byte_t *) (arm_req) +
1113 (sizeof(struct arm_request)));
1114 arm_req->buffer = NULL;
1115 arm_resp->buffer = NULL;
1116 if (rcode == RCODE_COMPLETE) {
1118 (byte_t *) arm_resp + sizeof(struct arm_response);
1120 (arm_addr->addr_space_buffer) + (addr -
1125 int2ptr((arm_addr->recvb) +
1126 sizeof(struct arm_request_response) +
1127 sizeof(struct arm_request) +
1128 sizeof(struct arm_response));
1130 arm_resp->buffer_length =
1131 (rcode == RCODE_COMPLETE) ? length : 0;
1132 arm_resp->response_code = rcode;
1133 arm_req->buffer_length = 0;
1134 arm_req->generation = req->req.generation;
1135 arm_req->extended_transaction_code = 0;
1136 arm_req->destination_offset = addr;
1137 arm_req->source_nodeid = nodeid;
1138 arm_req->destination_nodeid = host->node_id;
1139 arm_req->tlabel = (flags >> 10) & 0x3f;
1140 arm_req->tcode = (flags >> 4) & 0x0f;
1141 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1143 arm_request_response));
1144 arm_req_resp->response =
1145 int2ptr((arm_addr->recvb) +
1146 sizeof(struct arm_request_response) +
1147 sizeof(struct arm_request));
1148 queue_complete_req(req);
1150 spin_unlock_irqrestore(&host_info_lock, irqflags);
1154 static int arm_write(struct hpsb_host *host, int nodeid, int destid,
1155 quadlet_t * data, u64 addr, size_t length, u16 flags)
1157 unsigned long irqflags;
1158 struct pending_request *req;
1159 struct host_info *hi;
1160 struct file_info *fi = NULL;
1161 struct list_head *entry;
1162 struct arm_addr *arm_addr = NULL;
1163 struct arm_request *arm_req = NULL;
1164 struct arm_response *arm_resp = NULL;
1165 int found = 0, size = 0, rcode = -1, length_conflict = 0;
1166 struct arm_request_response *arm_req_resp = NULL;
1168 DBGMSG("arm_write called by node: %X"
1169 "addr: %4.4x %8.8x length: %Zu", nodeid,
1170 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
1172 spin_lock_irqsave(&host_info_lock, irqflags);
1173 hi = find_host_info(host); /* search address-entry */
1175 list_for_each_entry(fi, &hi->file_info_list, list) {
1176 entry = fi->addr_list.next;
1177 while (entry != &(fi->addr_list)) {
1179 list_entry(entry, struct arm_addr,
1181 if (((arm_addr->start) <= (addr))
1182 && ((arm_addr->end) >= (addr + length))) {
1186 entry = entry->next;
1195 printk(KERN_ERR "raw1394: arm_write FAILED addr_entry not found"
1196 " -> rcode_address_error\n");
1197 spin_unlock_irqrestore(&host_info_lock, irqflags);
1198 return (RCODE_ADDRESS_ERROR);
1200 DBGMSG("arm_write addr_entry FOUND");
1202 if (arm_addr->rec_length < length) {
1203 DBGMSG("arm_write blocklength too big -> rcode_data_error");
1204 length_conflict = 1;
1205 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
1208 if (arm_addr->access_rights & ARM_WRITE) {
1209 if (!(arm_addr->client_transactions & ARM_WRITE)) {
1210 memcpy((arm_addr->addr_space_buffer) +
1211 (addr - (arm_addr->start)), data,
1213 DBGMSG("arm_write -> (rcode_complete)");
1214 rcode = RCODE_COMPLETE;
1217 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1218 DBGMSG("arm_write -> rcode_type_error (access denied)");
1221 if (arm_addr->notification_options & ARM_WRITE) {
1222 DBGMSG("arm_write -> entering notification-section");
1223 req = __alloc_pending_request(GFP_ATOMIC);
1225 DBGMSG("arm_write -> rcode_conflict_error");
1226 spin_unlock_irqrestore(&host_info_lock, irqflags);
1227 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1228 The request my be retried */
1231 sizeof(struct arm_request) + sizeof(struct arm_response) +
1232 (length) * sizeof(byte_t) +
1233 sizeof(struct arm_request_response);
1234 req->data = kmalloc(size, GFP_ATOMIC);
1236 free_pending_request(req);
1237 DBGMSG("arm_write -> rcode_conflict_error");
1238 spin_unlock_irqrestore(&host_info_lock, irqflags);
1239 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1240 The request may be retried */
1243 req->file_info = fi;
1244 req->req.type = RAW1394_REQ_ARM;
1245 req->req.generation = get_hpsb_generation(host);
1247 (((length << 16) & (0xFFFF0000)) | (ARM_WRITE & 0xFF));
1248 req->req.tag = arm_addr->arm_tag;
1249 req->req.recvb = arm_addr->recvb;
1250 req->req.length = size;
1251 arm_req_resp = (struct arm_request_response *)(req->data);
1252 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1255 arm_request_response)));
1257 (struct arm_response *)((byte_t *) (arm_req) +
1258 (sizeof(struct arm_request)));
1259 arm_resp->buffer = NULL;
1260 memcpy((byte_t *) arm_resp + sizeof(struct arm_response),
1262 arm_req->buffer = int2ptr((arm_addr->recvb) +
1263 sizeof(struct arm_request_response) +
1264 sizeof(struct arm_request) +
1265 sizeof(struct arm_response));
1266 arm_req->buffer_length = length;
1267 arm_req->generation = req->req.generation;
1268 arm_req->extended_transaction_code = 0;
1269 arm_req->destination_offset = addr;
1270 arm_req->source_nodeid = nodeid;
1271 arm_req->destination_nodeid = destid;
1272 arm_req->tlabel = (flags >> 10) & 0x3f;
1273 arm_req->tcode = (flags >> 4) & 0x0f;
1274 arm_resp->buffer_length = 0;
1275 arm_resp->response_code = rcode;
1276 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1278 arm_request_response));
1279 arm_req_resp->response =
1280 int2ptr((arm_addr->recvb) +
1281 sizeof(struct arm_request_response) +
1282 sizeof(struct arm_request));
1283 queue_complete_req(req);
1285 spin_unlock_irqrestore(&host_info_lock, irqflags);
1289 static int arm_lock(struct hpsb_host *host, int nodeid, quadlet_t * store,
1290 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
1293 unsigned long irqflags;
1294 struct pending_request *req;
1295 struct host_info *hi;
1296 struct file_info *fi = NULL;
1297 struct list_head *entry;
1298 struct arm_addr *arm_addr = NULL;
1299 struct arm_request *arm_req = NULL;
1300 struct arm_response *arm_resp = NULL;
1301 int found = 0, size = 0, rcode = -1;
1303 struct arm_request_response *arm_req_resp = NULL;
1305 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1306 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1307 DBGMSG("arm_lock called by node: %X "
1308 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X",
1309 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1310 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1313 DBGMSG("arm_lock called by node: %X "
1314 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X arg: %8.8X",
1315 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1316 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1317 be32_to_cpu(data), be32_to_cpu(arg));
1319 spin_lock_irqsave(&host_info_lock, irqflags);
1320 hi = find_host_info(host); /* search address-entry */
1322 list_for_each_entry(fi, &hi->file_info_list, list) {
1323 entry = fi->addr_list.next;
1324 while (entry != &(fi->addr_list)) {
1326 list_entry(entry, struct arm_addr,
1328 if (((arm_addr->start) <= (addr))
1329 && ((arm_addr->end) >=
1330 (addr + sizeof(*store)))) {
1334 entry = entry->next;
1343 printk(KERN_ERR "raw1394: arm_lock FAILED addr_entry not found"
1344 " -> rcode_address_error\n");
1345 spin_unlock_irqrestore(&host_info_lock, irqflags);
1346 return (RCODE_ADDRESS_ERROR);
1348 DBGMSG("arm_lock addr_entry FOUND");
1351 if (arm_addr->access_rights & ARM_LOCK) {
1352 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1354 (arm_addr->addr_space_buffer) + (addr -
1358 switch (ext_tcode) {
1359 case (EXTCODE_MASK_SWAP):
1360 new = data | (old & ~arg);
1362 case (EXTCODE_COMPARE_SWAP):
1369 case (EXTCODE_FETCH_ADD):
1371 cpu_to_be32(be32_to_cpu(data) +
1374 case (EXTCODE_LITTLE_ADD):
1376 cpu_to_le32(le32_to_cpu(data) +
1379 case (EXTCODE_BOUNDED_ADD):
1382 cpu_to_be32(be32_to_cpu
1390 case (EXTCODE_WRAP_ADD):
1393 cpu_to_be32(be32_to_cpu
1402 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1404 "raw1394: arm_lock FAILED "
1405 "ext_tcode not allowed -> rcode_type_error\n");
1409 DBGMSG("arm_lock -> (rcode_complete)");
1410 rcode = RCODE_COMPLETE;
1411 memcpy(store, &old, sizeof(*store));
1412 memcpy((arm_addr->addr_space_buffer) +
1413 (addr - (arm_addr->start)),
1414 &new, sizeof(*store));
1418 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1419 DBGMSG("arm_lock -> rcode_type_error (access denied)");
1422 if (arm_addr->notification_options & ARM_LOCK) {
1423 byte_t *buf1, *buf2;
1424 DBGMSG("arm_lock -> entering notification-section");
1425 req = __alloc_pending_request(GFP_ATOMIC);
1427 DBGMSG("arm_lock -> rcode_conflict_error");
1428 spin_unlock_irqrestore(&host_info_lock, irqflags);
1429 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1430 The request may be retried */
1432 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1433 req->data = kmalloc(size, GFP_ATOMIC);
1435 free_pending_request(req);
1436 DBGMSG("arm_lock -> rcode_conflict_error");
1437 spin_unlock_irqrestore(&host_info_lock, irqflags);
1438 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1439 The request may be retried */
1442 arm_req_resp = (struct arm_request_response *)(req->data);
1443 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1446 arm_request_response)));
1448 (struct arm_response *)((byte_t *) (arm_req) +
1449 (sizeof(struct arm_request)));
1450 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1451 buf2 = buf1 + 2 * sizeof(*store);
1452 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1453 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1454 arm_req->buffer_length = sizeof(*store);
1455 memcpy(buf1, &data, sizeof(*store));
1458 arm_req->buffer_length = 2 * sizeof(*store);
1459 memcpy(buf1, &arg, sizeof(*store));
1460 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1462 if (rcode == RCODE_COMPLETE) {
1463 arm_resp->buffer_length = sizeof(*store);
1464 memcpy(buf2, &old, sizeof(*store));
1466 arm_resp->buffer_length = 0;
1468 req->file_info = fi;
1469 req->req.type = RAW1394_REQ_ARM;
1470 req->req.generation = get_hpsb_generation(host);
1471 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1473 req->req.tag = arm_addr->arm_tag;
1474 req->req.recvb = arm_addr->recvb;
1475 req->req.length = size;
1476 arm_req->generation = req->req.generation;
1477 arm_req->extended_transaction_code = ext_tcode;
1478 arm_req->destination_offset = addr;
1479 arm_req->source_nodeid = nodeid;
1480 arm_req->destination_nodeid = host->node_id;
1481 arm_req->tlabel = (flags >> 10) & 0x3f;
1482 arm_req->tcode = (flags >> 4) & 0x0f;
1483 arm_resp->response_code = rcode;
1484 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1486 arm_request_response));
1487 arm_req_resp->response =
1488 int2ptr((arm_addr->recvb) +
1489 sizeof(struct arm_request_response) +
1490 sizeof(struct arm_request));
1492 int2ptr((arm_addr->recvb) +
1493 sizeof(struct arm_request_response) +
1494 sizeof(struct arm_request) +
1495 sizeof(struct arm_response));
1497 int2ptr((arm_addr->recvb) +
1498 sizeof(struct arm_request_response) +
1499 sizeof(struct arm_request) +
1500 sizeof(struct arm_response) + 2 * sizeof(*store));
1501 queue_complete_req(req);
1503 spin_unlock_irqrestore(&host_info_lock, irqflags);
1507 static int arm_lock64(struct hpsb_host *host, int nodeid, octlet_t * store,
1508 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
1511 unsigned long irqflags;
1512 struct pending_request *req;
1513 struct host_info *hi;
1514 struct file_info *fi = NULL;
1515 struct list_head *entry;
1516 struct arm_addr *arm_addr = NULL;
1517 struct arm_request *arm_req = NULL;
1518 struct arm_response *arm_resp = NULL;
1519 int found = 0, size = 0, rcode = -1;
1521 struct arm_request_response *arm_req_resp = NULL;
1523 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1524 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1525 DBGMSG("arm_lock64 called by node: %X "
1526 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X ",
1527 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1528 (u32) (addr & 0xFFFFFFFF),
1530 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1531 (u32) (be64_to_cpu(data) & 0xFFFFFFFF));
1533 DBGMSG("arm_lock64 called by node: %X "
1534 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X arg: "
1536 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1537 (u32) (addr & 0xFFFFFFFF),
1539 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1540 (u32) (be64_to_cpu(data) & 0xFFFFFFFF),
1541 (u32) ((be64_to_cpu(arg) >> 32) & 0xFFFFFFFF),
1542 (u32) (be64_to_cpu(arg) & 0xFFFFFFFF));
1544 spin_lock_irqsave(&host_info_lock, irqflags);
1545 hi = find_host_info(host); /* search addressentry in file_info's for host */
1547 list_for_each_entry(fi, &hi->file_info_list, list) {
1548 entry = fi->addr_list.next;
1549 while (entry != &(fi->addr_list)) {
1551 list_entry(entry, struct arm_addr,
1553 if (((arm_addr->start) <= (addr))
1554 && ((arm_addr->end) >=
1555 (addr + sizeof(*store)))) {
1559 entry = entry->next;
1569 "raw1394: arm_lock64 FAILED addr_entry not found"
1570 " -> rcode_address_error\n");
1571 spin_unlock_irqrestore(&host_info_lock, irqflags);
1572 return (RCODE_ADDRESS_ERROR);
1574 DBGMSG("arm_lock64 addr_entry FOUND");
1577 if (arm_addr->access_rights & ARM_LOCK) {
1578 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1580 (arm_addr->addr_space_buffer) + (addr -
1584 switch (ext_tcode) {
1585 case (EXTCODE_MASK_SWAP):
1586 new = data | (old & ~arg);
1588 case (EXTCODE_COMPARE_SWAP):
1595 case (EXTCODE_FETCH_ADD):
1597 cpu_to_be64(be64_to_cpu(data) +
1600 case (EXTCODE_LITTLE_ADD):
1602 cpu_to_le64(le64_to_cpu(data) +
1605 case (EXTCODE_BOUNDED_ADD):
1608 cpu_to_be64(be64_to_cpu
1616 case (EXTCODE_WRAP_ADD):
1619 cpu_to_be64(be64_to_cpu
1629 "raw1394: arm_lock64 FAILED "
1630 "ext_tcode not allowed -> rcode_type_error\n");
1631 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1636 ("arm_lock64 -> (rcode_complete)");
1637 rcode = RCODE_COMPLETE;
1638 memcpy(store, &old, sizeof(*store));
1639 memcpy((arm_addr->addr_space_buffer) +
1640 (addr - (arm_addr->start)),
1641 &new, sizeof(*store));
1645 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1647 ("arm_lock64 -> rcode_type_error (access denied)");
1650 if (arm_addr->notification_options & ARM_LOCK) {
1651 byte_t *buf1, *buf2;
1652 DBGMSG("arm_lock64 -> entering notification-section");
1653 req = __alloc_pending_request(GFP_ATOMIC);
1655 spin_unlock_irqrestore(&host_info_lock, irqflags);
1656 DBGMSG("arm_lock64 -> rcode_conflict_error");
1657 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1658 The request may be retried */
1660 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1661 req->data = kmalloc(size, GFP_ATOMIC);
1663 free_pending_request(req);
1664 spin_unlock_irqrestore(&host_info_lock, irqflags);
1665 DBGMSG("arm_lock64 -> rcode_conflict_error");
1666 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1667 The request may be retried */
1670 arm_req_resp = (struct arm_request_response *)(req->data);
1671 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1674 arm_request_response)));
1676 (struct arm_response *)((byte_t *) (arm_req) +
1677 (sizeof(struct arm_request)));
1678 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1679 buf2 = buf1 + 2 * sizeof(*store);
1680 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1681 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1682 arm_req->buffer_length = sizeof(*store);
1683 memcpy(buf1, &data, sizeof(*store));
1686 arm_req->buffer_length = 2 * sizeof(*store);
1687 memcpy(buf1, &arg, sizeof(*store));
1688 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1690 if (rcode == RCODE_COMPLETE) {
1691 arm_resp->buffer_length = sizeof(*store);
1692 memcpy(buf2, &old, sizeof(*store));
1694 arm_resp->buffer_length = 0;
1696 req->file_info = fi;
1697 req->req.type = RAW1394_REQ_ARM;
1698 req->req.generation = get_hpsb_generation(host);
1699 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1701 req->req.tag = arm_addr->arm_tag;
1702 req->req.recvb = arm_addr->recvb;
1703 req->req.length = size;
1704 arm_req->generation = req->req.generation;
1705 arm_req->extended_transaction_code = ext_tcode;
1706 arm_req->destination_offset = addr;
1707 arm_req->source_nodeid = nodeid;
1708 arm_req->destination_nodeid = host->node_id;
1709 arm_req->tlabel = (flags >> 10) & 0x3f;
1710 arm_req->tcode = (flags >> 4) & 0x0f;
1711 arm_resp->response_code = rcode;
1712 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1714 arm_request_response));
1715 arm_req_resp->response =
1716 int2ptr((arm_addr->recvb) +
1717 sizeof(struct arm_request_response) +
1718 sizeof(struct arm_request));
1720 int2ptr((arm_addr->recvb) +
1721 sizeof(struct arm_request_response) +
1722 sizeof(struct arm_request) +
1723 sizeof(struct arm_response));
1725 int2ptr((arm_addr->recvb) +
1726 sizeof(struct arm_request_response) +
1727 sizeof(struct arm_request) +
1728 sizeof(struct arm_response) + 2 * sizeof(*store));
1729 queue_complete_req(req);
1731 spin_unlock_irqrestore(&host_info_lock, irqflags);
1735 static int arm_register(struct file_info *fi, struct pending_request *req)
1738 struct arm_addr *addr;
1739 struct host_info *hi;
1740 struct file_info *fi_hlp = NULL;
1741 struct list_head *entry;
1742 struct arm_addr *arm_addr = NULL;
1743 int same_host, another_host;
1744 unsigned long flags;
1746 DBGMSG("arm_register called "
1747 "addr(Offset): %8.8x %8.8x length: %u "
1748 "rights: %2.2X notify: %2.2X "
1749 "max_blk_len: %4.4X",
1750 (u32) ((req->req.address >> 32) & 0xFFFF),
1751 (u32) (req->req.address & 0xFFFFFFFF),
1752 req->req.length, ((req->req.misc >> 8) & 0xFF),
1753 (req->req.misc & 0xFF), ((req->req.misc >> 16) & 0xFFFF));
1754 /* check addressrange */
1755 if ((((req->req.address) & ~(0xFFFFFFFFFFFFULL)) != 0) ||
1756 (((req->req.address + req->req.length) & ~(0xFFFFFFFFFFFFULL)) !=
1758 req->req.length = 0;
1761 /* addr-list-entry for fileinfo */
1762 addr = kmalloc(sizeof(*addr), GFP_KERNEL);
1764 req->req.length = 0;
1767 /* allocation of addr_space_buffer */
1768 addr->addr_space_buffer = vmalloc(req->req.length);
1769 if (!(addr->addr_space_buffer)) {
1771 req->req.length = 0;
1774 /* initialization of addr_space_buffer */
1775 if ((req->req.sendb) == (unsigned long)NULL) {
1777 memset(addr->addr_space_buffer, 0, req->req.length);
1779 /* init: user -> kernel */
1781 (addr->addr_space_buffer, int2ptr(req->req.sendb),
1783 vfree(addr->addr_space_buffer);
1788 INIT_LIST_HEAD(&addr->addr_list);
1789 addr->arm_tag = req->req.tag;
1790 addr->start = req->req.address;
1791 addr->end = req->req.address + req->req.length;
1792 addr->access_rights = (u8) (req->req.misc & 0x0F);
1793 addr->notification_options = (u8) ((req->req.misc >> 4) & 0x0F);
1794 addr->client_transactions = (u8) ((req->req.misc >> 8) & 0x0F);
1795 addr->access_rights |= addr->client_transactions;
1796 addr->notification_options |= addr->client_transactions;
1797 addr->recvb = req->req.recvb;
1798 addr->rec_length = (u16) ((req->req.misc >> 16) & 0xFFFF);
1800 spin_lock_irqsave(&host_info_lock, flags);
1801 hi = find_host_info(fi->host);
1804 /* same host with address-entry containing same addressrange ? */
1805 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1806 entry = fi_hlp->addr_list.next;
1807 while (entry != &(fi_hlp->addr_list)) {
1809 list_entry(entry, struct arm_addr, addr_list);
1810 if ((arm_addr->start == addr->start)
1811 && (arm_addr->end == addr->end)) {
1812 DBGMSG("same host ownes same "
1813 "addressrange -> EALREADY");
1817 entry = entry->next;
1824 /* addressrange occupied by same host */
1825 spin_unlock_irqrestore(&host_info_lock, flags);
1826 vfree(addr->addr_space_buffer);
1830 /* another host with valid address-entry containing same addressrange */
1831 list_for_each_entry(hi, &host_info_list, list) {
1832 if (hi->host != fi->host) {
1833 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1834 entry = fi_hlp->addr_list.next;
1835 while (entry != &(fi_hlp->addr_list)) {
1837 list_entry(entry, struct arm_addr,
1839 if ((arm_addr->start == addr->start)
1840 && (arm_addr->end == addr->end)) {
1842 ("another host ownes same "
1847 entry = entry->next;
1855 spin_unlock_irqrestore(&host_info_lock, flags);
1858 DBGMSG("another hosts entry is valid -> SUCCESS");
1859 if (copy_to_user(int2ptr(req->req.recvb),
1860 &addr->start, sizeof(u64))) {
1861 printk(KERN_ERR "raw1394: arm_register failed "
1862 " address-range-entry is invalid -> EFAULT !!!\n");
1863 vfree(addr->addr_space_buffer);
1867 free_pending_request(req); /* immediate success or fail */
1869 spin_lock_irqsave(&host_info_lock, flags);
1870 list_add_tail(&addr->addr_list, &fi->addr_list);
1871 spin_unlock_irqrestore(&host_info_lock, flags);
1872 return sizeof(struct raw1394_request);
1875 hpsb_register_addrspace(&raw1394_highlevel, fi->host, &arm_ops,
1877 req->req.address + req->req.length);
1880 spin_lock_irqsave(&host_info_lock, flags);
1881 list_add_tail(&addr->addr_list, &fi->addr_list);
1882 spin_unlock_irqrestore(&host_info_lock, flags);
1884 DBGMSG("arm_register failed errno: %d \n", retval);
1885 vfree(addr->addr_space_buffer);
1889 free_pending_request(req); /* immediate success or fail */
1890 return sizeof(struct raw1394_request);
1893 static int arm_unregister(struct file_info *fi, struct pending_request *req)
1897 struct list_head *entry;
1898 struct arm_addr *addr = NULL;
1899 struct host_info *hi;
1900 struct file_info *fi_hlp = NULL;
1901 struct arm_addr *arm_addr = NULL;
1903 unsigned long flags;
1905 DBGMSG("arm_Unregister called addr(Offset): "
1907 (u32) ((req->req.address >> 32) & 0xFFFF),
1908 (u32) (req->req.address & 0xFFFFFFFF));
1909 spin_lock_irqsave(&host_info_lock, flags);
1911 entry = fi->addr_list.next;
1912 while (entry != &(fi->addr_list)) {
1913 addr = list_entry(entry, struct arm_addr, addr_list);
1914 if (addr->start == req->req.address) {
1918 entry = entry->next;
1921 DBGMSG("arm_Unregister addr not found");
1922 spin_unlock_irqrestore(&host_info_lock, flags);
1925 DBGMSG("arm_Unregister addr found");
1927 /* another host with valid address-entry containing
1928 same addressrange */
1929 list_for_each_entry(hi, &host_info_list, list) {
1930 if (hi->host != fi->host) {
1931 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1932 entry = fi_hlp->addr_list.next;
1933 while (entry != &(fi_hlp->addr_list)) {
1934 arm_addr = list_entry(entry,
1937 if (arm_addr->start == addr->start) {
1938 DBGMSG("another host ownes "
1939 "same addressrange");
1943 entry = entry->next;
1952 DBGMSG("delete entry from list -> success");
1953 list_del(&addr->addr_list);
1954 spin_unlock_irqrestore(&host_info_lock, flags);
1955 vfree(addr->addr_space_buffer);
1957 free_pending_request(req); /* immediate success or fail */
1958 return sizeof(struct raw1394_request);
1961 hpsb_unregister_addrspace(&raw1394_highlevel, fi->host,
1964 printk(KERN_ERR "raw1394: arm_Unregister failed -> EINVAL\n");
1965 spin_unlock_irqrestore(&host_info_lock, flags);
1968 DBGMSG("delete entry from list -> success");
1969 list_del(&addr->addr_list);
1970 spin_unlock_irqrestore(&host_info_lock, flags);
1971 vfree(addr->addr_space_buffer);
1973 free_pending_request(req); /* immediate success or fail */
1974 return sizeof(struct raw1394_request);
1977 /* Copy data from ARM buffer(s) to user buffer. */
1978 static int arm_get_buf(struct file_info *fi, struct pending_request *req)
1980 struct arm_addr *arm_addr = NULL;
1981 unsigned long flags;
1982 unsigned long offset;
1984 struct list_head *entry;
1986 DBGMSG("arm_get_buf "
1987 "addr(Offset): %04X %08X length: %u",
1988 (u32) ((req->req.address >> 32) & 0xFFFF),
1989 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
1991 spin_lock_irqsave(&host_info_lock, flags);
1992 entry = fi->addr_list.next;
1993 while (entry != &(fi->addr_list)) {
1994 arm_addr = list_entry(entry, struct arm_addr, addr_list);
1995 if ((arm_addr->start <= req->req.address) &&
1996 (arm_addr->end > req->req.address)) {
1997 if (req->req.address + req->req.length <= arm_addr->end) {
1998 offset = req->req.address - arm_addr->start;
1999 spin_unlock_irqrestore(&host_info_lock, flags);
2002 ("arm_get_buf copy_to_user( %08X, %p, %u )",
2003 (u32) req->req.recvb,
2004 arm_addr->addr_space_buffer + offset,
2005 (u32) req->req.length);
2007 (int2ptr(req->req.recvb),
2008 arm_addr->addr_space_buffer + offset,
2012 /* We have to free the request, because we
2013 * queue no response, and therefore nobody
2015 free_pending_request(req);
2016 return sizeof(struct raw1394_request);
2018 DBGMSG("arm_get_buf request exceeded mapping");
2019 spin_unlock_irqrestore(&host_info_lock, flags);
2023 entry = entry->next;
2025 spin_unlock_irqrestore(&host_info_lock, flags);
2029 /* Copy data from user buffer to ARM buffer(s). */
2030 static int arm_set_buf(struct file_info *fi, struct pending_request *req)
2032 struct arm_addr *arm_addr = NULL;
2033 unsigned long flags;
2034 unsigned long offset;
2036 struct list_head *entry;
2038 DBGMSG("arm_set_buf "
2039 "addr(Offset): %04X %08X length: %u",
2040 (u32) ((req->req.address >> 32) & 0xFFFF),
2041 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
2043 spin_lock_irqsave(&host_info_lock, flags);
2044 entry = fi->addr_list.next;
2045 while (entry != &(fi->addr_list)) {
2046 arm_addr = list_entry(entry, struct arm_addr, addr_list);
2047 if ((arm_addr->start <= req->req.address) &&
2048 (arm_addr->end > req->req.address)) {
2049 if (req->req.address + req->req.length <= arm_addr->end) {
2050 offset = req->req.address - arm_addr->start;
2051 spin_unlock_irqrestore(&host_info_lock, flags);
2054 ("arm_set_buf copy_from_user( %p, %08X, %u )",
2055 arm_addr->addr_space_buffer + offset,
2056 (u32) req->req.sendb,
2057 (u32) req->req.length);
2059 (arm_addr->addr_space_buffer + offset,
2060 int2ptr(req->req.sendb),
2064 /* We have to free the request, because we
2065 * queue no response, and therefore nobody
2067 free_pending_request(req);
2068 return sizeof(struct raw1394_request);
2070 DBGMSG("arm_set_buf request exceeded mapping");
2071 spin_unlock_irqrestore(&host_info_lock, flags);
2075 entry = entry->next;
2077 spin_unlock_irqrestore(&host_info_lock, flags);
2081 static int reset_notification(struct file_info *fi, struct pending_request *req)
2083 DBGMSG("reset_notification called - switch %s ",
2084 (req->req.misc == RAW1394_NOTIFY_OFF) ? "OFF" : "ON");
2085 if ((req->req.misc == RAW1394_NOTIFY_OFF) ||
2086 (req->req.misc == RAW1394_NOTIFY_ON)) {
2087 fi->notification = (u8) req->req.misc;
2088 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2089 return sizeof(struct raw1394_request);
2091 /* error EINVAL (22) invalid argument */
2095 static int write_phypacket(struct file_info *fi, struct pending_request *req)
2097 struct hpsb_packet *packet = NULL;
2100 unsigned long flags;
2102 data = be32_to_cpu((u32) req->req.sendb);
2103 DBGMSG("write_phypacket called - quadlet 0x%8.8x ", data);
2104 packet = hpsb_make_phypacket(fi->host, data);
2107 req->req.length = 0;
2108 req->packet = packet;
2109 hpsb_set_packet_complete_task(packet,
2110 (void (*)(void *))queue_complete_cb, req);
2111 spin_lock_irqsave(&fi->reqlists_lock, flags);
2112 list_add_tail(&req->list, &fi->req_pending);
2113 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2114 packet->generation = req->req.generation;
2115 retval = hpsb_send_packet(packet);
2116 DBGMSG("write_phypacket send_packet called => retval: %d ", retval);
2118 req->req.error = RAW1394_ERROR_SEND_ERROR;
2119 req->req.length = 0;
2120 queue_complete_req(req);
2122 return sizeof(struct raw1394_request);
2125 static int get_config_rom(struct file_info *fi, struct pending_request *req)
2127 int ret = sizeof(struct raw1394_request);
2128 quadlet_t *data = kmalloc(req->req.length, GFP_KERNEL);
2135 csr1212_read(fi->host->csr.rom, CSR1212_CONFIG_ROM_SPACE_OFFSET,
2136 data, req->req.length);
2137 if (copy_to_user(int2ptr(req->req.recvb), data, req->req.length))
2140 (int2ptr(req->req.tag), &fi->host->csr.rom->cache_head->len,
2141 sizeof(fi->host->csr.rom->cache_head->len)))
2143 if (copy_to_user(int2ptr(req->req.address), &fi->host->csr.generation,
2144 sizeof(fi->host->csr.generation)))
2146 if (copy_to_user(int2ptr(req->req.sendb), &status, sizeof(status)))
2150 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2155 static int update_config_rom(struct file_info *fi, struct pending_request *req)
2157 int ret = sizeof(struct raw1394_request);
2158 quadlet_t *data = kmalloc(req->req.length, GFP_KERNEL);
2161 if (copy_from_user(data, int2ptr(req->req.sendb), req->req.length)) {
2164 int status = hpsb_update_config_rom(fi->host,
2165 data, req->req.length,
2166 (unsigned char)req->req.
2169 (int2ptr(req->req.recvb), &status, sizeof(status)))
2174 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2180 static int modify_config_rom(struct file_info *fi, struct pending_request *req)
2182 struct csr1212_keyval *kv;
2183 struct csr1212_csr_rom_cache *cache;
2184 struct csr1212_dentry *dentry;
2188 if (req->req.misc == ~0) {
2189 if (req->req.length == 0)
2192 /* Find an unused slot */
2194 dr < RAW1394_MAX_USER_CSR_DIRS && fi->csr1212_dirs[dr];
2197 if (dr == RAW1394_MAX_USER_CSR_DIRS)
2200 fi->csr1212_dirs[dr] =
2201 csr1212_new_directory(CSR1212_KV_ID_VENDOR);
2202 if (!fi->csr1212_dirs[dr])
2206 if (!fi->csr1212_dirs[dr])
2209 /* Delete old stuff */
2211 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2212 dentry; dentry = dentry->next) {
2213 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2218 if (req->req.length == 0) {
2219 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2220 fi->csr1212_dirs[dr] = NULL;
2222 hpsb_update_config_rom_image(fi->host);
2223 free_pending_request(req);
2224 return sizeof(struct raw1394_request);
2228 cache = csr1212_rom_cache_malloc(0, req->req.length);
2230 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2231 fi->csr1212_dirs[dr] = NULL;
2235 cache->filled_head = kmalloc(sizeof(*cache->filled_head), GFP_KERNEL);
2236 if (!cache->filled_head) {
2237 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2238 fi->csr1212_dirs[dr] = NULL;
2239 CSR1212_FREE(cache);
2242 cache->filled_tail = cache->filled_head;
2244 if (copy_from_user(cache->data, int2ptr(req->req.sendb),
2246 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2247 fi->csr1212_dirs[dr] = NULL;
2250 cache->len = req->req.length;
2251 cache->filled_head->offset_start = 0;
2252 cache->filled_head->offset_end = cache->size - 1;
2254 cache->layout_head = cache->layout_tail = fi->csr1212_dirs[dr];
2256 ret = CSR1212_SUCCESS;
2257 /* parse all the items */
2258 for (kv = cache->layout_head; ret == CSR1212_SUCCESS && kv;
2260 ret = csr1212_parse_keyval(kv, cache);
2263 /* attach top level items to the root directory */
2265 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2266 ret == CSR1212_SUCCESS && dentry; dentry = dentry->next) {
2268 csr1212_attach_keyval_to_directory(fi->host->csr.
2273 if (ret == CSR1212_SUCCESS) {
2274 ret = hpsb_update_config_rom_image(fi->host);
2276 if (ret >= 0 && copy_to_user(int2ptr(req->req.recvb),
2282 kfree(cache->filled_head);
2283 CSR1212_FREE(cache);
2286 /* we have to free the request, because we queue no response,
2287 * and therefore nobody will free it */
2288 free_pending_request(req);
2289 return sizeof(struct raw1394_request);
2292 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2293 dentry; dentry = dentry->next) {
2294 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2298 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2299 fi->csr1212_dirs[dr] = NULL;
2304 static int state_connected(struct file_info *fi, struct pending_request *req)
2306 int node = req->req.address >> 48;
2308 req->req.error = RAW1394_ERROR_NONE;
2310 switch (req->req.type) {
2312 case RAW1394_REQ_ECHO:
2313 queue_complete_req(req);
2314 return sizeof(struct raw1394_request);
2316 case RAW1394_REQ_ISO_SEND:
2317 print_old_iso_deprecation();
2318 return handle_iso_send(fi, req, node);
2320 case RAW1394_REQ_ARM_REGISTER:
2321 return arm_register(fi, req);
2323 case RAW1394_REQ_ARM_UNREGISTER:
2324 return arm_unregister(fi, req);
2326 case RAW1394_REQ_ARM_SET_BUF:
2327 return arm_set_buf(fi, req);
2329 case RAW1394_REQ_ARM_GET_BUF:
2330 return arm_get_buf(fi, req);
2332 case RAW1394_REQ_RESET_NOTIFY:
2333 return reset_notification(fi, req);
2335 case RAW1394_REQ_ISO_LISTEN:
2336 print_old_iso_deprecation();
2337 handle_iso_listen(fi, req);
2338 return sizeof(struct raw1394_request);
2340 case RAW1394_REQ_FCP_LISTEN:
2341 handle_fcp_listen(fi, req);
2342 return sizeof(struct raw1394_request);
2344 case RAW1394_REQ_RESET_BUS:
2345 if (req->req.misc == RAW1394_LONG_RESET) {
2346 DBGMSG("busreset called (type: LONG)");
2347 hpsb_reset_bus(fi->host, LONG_RESET);
2348 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2349 return sizeof(struct raw1394_request);
2351 if (req->req.misc == RAW1394_SHORT_RESET) {
2352 DBGMSG("busreset called (type: SHORT)");
2353 hpsb_reset_bus(fi->host, SHORT_RESET);
2354 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2355 return sizeof(struct raw1394_request);
2357 /* error EINVAL (22) invalid argument */
2359 case RAW1394_REQ_GET_ROM:
2360 return get_config_rom(fi, req);
2362 case RAW1394_REQ_UPDATE_ROM:
2363 return update_config_rom(fi, req);
2365 case RAW1394_REQ_MODIFY_ROM:
2366 return modify_config_rom(fi, req);
2369 if (req->req.generation != get_hpsb_generation(fi->host)) {
2370 req->req.error = RAW1394_ERROR_GENERATION;
2371 req->req.generation = get_hpsb_generation(fi->host);
2372 req->req.length = 0;
2373 queue_complete_req(req);
2374 return sizeof(struct raw1394_request);
2377 switch (req->req.type) {
2378 case RAW1394_REQ_PHYPACKET:
2379 return write_phypacket(fi, req);
2380 case RAW1394_REQ_ASYNC_SEND:
2381 return handle_async_send(fi, req);
2384 if (req->req.length == 0) {
2385 req->req.error = RAW1394_ERROR_INVALID_ARG;
2386 queue_complete_req(req);
2387 return sizeof(struct raw1394_request);
2390 return handle_async_request(fi, req, node);
2393 static ssize_t raw1394_write(struct file *file, const char __user * buffer,
2394 size_t count, loff_t * offset_is_ignored)
2396 struct file_info *fi = (struct file_info *)file->private_data;
2397 struct pending_request *req;
2400 #ifdef CONFIG_COMPAT
2401 if (count == sizeof(struct compat_raw1394_req) &&
2402 sizeof(struct compat_raw1394_req) !=
2403 sizeof(struct raw1394_request)) {
2404 buffer = raw1394_compat_write(buffer);
2406 return PTR_ERR(buffer);
2409 if (count != sizeof(struct raw1394_request)) {
2413 req = alloc_pending_request();
2417 req->file_info = fi;
2419 if (copy_from_user(&req->req, buffer, sizeof(struct raw1394_request))) {
2420 free_pending_request(req);
2424 switch (fi->state) {
2426 retval = state_opened(fi, req);
2430 retval = state_initialized(fi, req);
2434 retval = state_connected(fi, req);
2439 free_pending_request(req);
2445 /* rawiso operations */
2447 /* check if any RAW1394_REQ_RAWISO_ACTIVITY event is already in the
2448 * completion queue (reqlists_lock must be taken) */
2449 static inline int __rawiso_event_in_queue(struct file_info *fi)
2451 struct pending_request *req;
2453 list_for_each_entry(req, &fi->req_complete, list)
2454 if (req->req.type == RAW1394_REQ_RAWISO_ACTIVITY)
2460 /* put a RAWISO_ACTIVITY event in the queue, if one isn't there already */
2461 static void queue_rawiso_event(struct file_info *fi)
2463 unsigned long flags;
2465 spin_lock_irqsave(&fi->reqlists_lock, flags);
2467 /* only one ISO activity event may be in the queue */
2468 if (!__rawiso_event_in_queue(fi)) {
2469 struct pending_request *req =
2470 __alloc_pending_request(GFP_ATOMIC);
2473 req->file_info = fi;
2474 req->req.type = RAW1394_REQ_RAWISO_ACTIVITY;
2475 req->req.generation = get_hpsb_generation(fi->host);
2476 __queue_complete_req(req);
2478 /* on allocation failure, signal an overflow */
2479 if (fi->iso_handle) {
2480 atomic_inc(&fi->iso_handle->overflows);
2484 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2487 static void rawiso_activity_cb(struct hpsb_iso *iso)
2489 unsigned long flags;
2490 struct host_info *hi;
2491 struct file_info *fi;
2493 spin_lock_irqsave(&host_info_lock, flags);
2494 hi = find_host_info(iso->host);
2497 list_for_each_entry(fi, &hi->file_info_list, list) {
2498 if (fi->iso_handle == iso)
2499 queue_rawiso_event(fi);
2503 spin_unlock_irqrestore(&host_info_lock, flags);
2506 /* helper function - gather all the kernel iso status bits for returning to user-space */
2507 static void raw1394_iso_fill_status(struct hpsb_iso *iso,
2508 struct raw1394_iso_status *stat)
2510 stat->config.data_buf_size = iso->buf_size;
2511 stat->config.buf_packets = iso->buf_packets;
2512 stat->config.channel = iso->channel;
2513 stat->config.speed = iso->speed;
2514 stat->config.irq_interval = iso->irq_interval;
2515 stat->n_packets = hpsb_iso_n_ready(iso);
2516 stat->overflows = atomic_read(&iso->overflows);
2517 stat->xmit_cycle = iso->xmit_cycle;
2520 static int raw1394_iso_xmit_init(struct file_info *fi, void __user * uaddr)
2522 struct raw1394_iso_status stat;
2527 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2530 fi->iso_handle = hpsb_iso_xmit_init(fi->host,
2531 stat.config.data_buf_size,
2532 stat.config.buf_packets,
2533 stat.config.channel,
2535 stat.config.irq_interval,
2536 rawiso_activity_cb);
2537 if (!fi->iso_handle)
2540 fi->iso_state = RAW1394_ISO_XMIT;
2542 raw1394_iso_fill_status(fi->iso_handle, &stat);
2543 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2546 /* queue an event to get things started */
2547 rawiso_activity_cb(fi->iso_handle);
2552 static int raw1394_iso_recv_init(struct file_info *fi, void __user * uaddr)
2554 struct raw1394_iso_status stat;
2559 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2562 fi->iso_handle = hpsb_iso_recv_init(fi->host,
2563 stat.config.data_buf_size,
2564 stat.config.buf_packets,
2565 stat.config.channel,
2566 stat.config.dma_mode,
2567 stat.config.irq_interval,
2568 rawiso_activity_cb);
2569 if (!fi->iso_handle)
2572 fi->iso_state = RAW1394_ISO_RECV;
2574 raw1394_iso_fill_status(fi->iso_handle, &stat);
2575 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2580 static int raw1394_iso_get_status(struct file_info *fi, void __user * uaddr)
2582 struct raw1394_iso_status stat;
2583 struct hpsb_iso *iso = fi->iso_handle;
2585 raw1394_iso_fill_status(fi->iso_handle, &stat);
2586 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2589 /* reset overflow counter */
2590 atomic_set(&iso->overflows, 0);
2595 /* copy N packet_infos out of the ringbuffer into user-supplied array */
2596 static int raw1394_iso_recv_packets(struct file_info *fi, void __user * uaddr)
2598 struct raw1394_iso_packets upackets;
2599 unsigned int packet = fi->iso_handle->first_packet;
2602 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2605 if (upackets.n_packets > hpsb_iso_n_ready(fi->iso_handle))
2608 /* ensure user-supplied buffer is accessible and big enough */
2609 if (!access_ok(VERIFY_WRITE, upackets.infos,
2610 upackets.n_packets *
2611 sizeof(struct raw1394_iso_packet_info)))
2614 /* copy the packet_infos out */
2615 for (i = 0; i < upackets.n_packets; i++) {
2616 if (__copy_to_user(&upackets.infos[i],
2617 &fi->iso_handle->infos[packet],
2618 sizeof(struct raw1394_iso_packet_info)))
2621 packet = (packet + 1) % fi->iso_handle->buf_packets;
2627 /* copy N packet_infos from user to ringbuffer, and queue them for transmission */
2628 static int raw1394_iso_send_packets(struct file_info *fi, void __user * uaddr)
2630 struct raw1394_iso_packets upackets;
2633 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2636 if (upackets.n_packets >= fi->iso_handle->buf_packets)
2639 if (upackets.n_packets >= hpsb_iso_n_ready(fi->iso_handle))
2642 /* ensure user-supplied buffer is accessible and big enough */
2643 if (!access_ok(VERIFY_READ, upackets.infos,
2644 upackets.n_packets *
2645 sizeof(struct raw1394_iso_packet_info)))
2648 /* copy the infos structs in and queue the packets */
2649 for (i = 0; i < upackets.n_packets; i++) {
2650 struct raw1394_iso_packet_info info;
2652 if (__copy_from_user(&info, &upackets.infos[i],
2653 sizeof(struct raw1394_iso_packet_info)))
2656 rv = hpsb_iso_xmit_queue_packet(fi->iso_handle, info.offset,
2657 info.len, info.tag, info.sy);
2665 static void raw1394_iso_shutdown(struct file_info *fi)
2668 hpsb_iso_shutdown(fi->iso_handle);
2670 fi->iso_handle = NULL;
2671 fi->iso_state = RAW1394_ISO_INACTIVE;
2674 static int raw1394_read_cycle_timer(struct file_info *fi, void __user * uaddr)
2676 struct raw1394_cycle_timer ct;
2679 err = hpsb_read_cycle_timer(fi->host, &ct.cycle_timer, &ct.local_time);
2681 if (copy_to_user(uaddr, &ct, sizeof(ct)))
2686 /* mmap the rawiso xmit/recv buffer */
2687 static int raw1394_mmap(struct file *file, struct vm_area_struct *vma)
2689 struct file_info *fi = file->private_data;
2691 if (fi->iso_state == RAW1394_ISO_INACTIVE)
2694 return dma_region_mmap(&fi->iso_handle->data_buf, file, vma);
2697 /* ioctl is only used for rawiso operations */
2698 static int raw1394_ioctl(struct inode *inode, struct file *file,
2699 unsigned int cmd, unsigned long arg)
2701 struct file_info *fi = file->private_data;
2702 void __user *argp = (void __user *)arg;
2704 switch (fi->iso_state) {
2705 case RAW1394_ISO_INACTIVE:
2707 case RAW1394_IOC_ISO_XMIT_INIT:
2708 return raw1394_iso_xmit_init(fi, argp);
2709 case RAW1394_IOC_ISO_RECV_INIT:
2710 return raw1394_iso_recv_init(fi, argp);
2715 case RAW1394_ISO_RECV:
2717 case RAW1394_IOC_ISO_RECV_START:{
2718 /* copy args from user-space */
2721 (&args[0], argp, sizeof(args)))
2723 return hpsb_iso_recv_start(fi->iso_handle,
2727 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2728 hpsb_iso_stop(fi->iso_handle);
2730 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL:
2731 return hpsb_iso_recv_listen_channel(fi->iso_handle,
2733 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
2734 return hpsb_iso_recv_unlisten_channel(fi->iso_handle,
2736 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:{
2737 /* copy the u64 from user-space */
2739 if (copy_from_user(&mask, argp, sizeof(mask)))
2741 return hpsb_iso_recv_set_channel_mask(fi->
2745 case RAW1394_IOC_ISO_GET_STATUS:
2746 return raw1394_iso_get_status(fi, argp);
2747 case RAW1394_IOC_ISO_RECV_PACKETS:
2748 return raw1394_iso_recv_packets(fi, argp);
2749 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
2750 return hpsb_iso_recv_release_packets(fi->iso_handle,
2752 case RAW1394_IOC_ISO_RECV_FLUSH:
2753 return hpsb_iso_recv_flush(fi->iso_handle);
2754 case RAW1394_IOC_ISO_SHUTDOWN:
2755 raw1394_iso_shutdown(fi);
2757 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2758 queue_rawiso_event(fi);
2762 case RAW1394_ISO_XMIT:
2764 case RAW1394_IOC_ISO_XMIT_START:{
2765 /* copy two ints from user-space */
2768 (&args[0], argp, sizeof(args)))
2770 return hpsb_iso_xmit_start(fi->iso_handle,
2773 case RAW1394_IOC_ISO_XMIT_SYNC:
2774 return hpsb_iso_xmit_sync(fi->iso_handle);
2775 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2776 hpsb_iso_stop(fi->iso_handle);
2778 case RAW1394_IOC_ISO_GET_STATUS:
2779 return raw1394_iso_get_status(fi, argp);
2780 case RAW1394_IOC_ISO_XMIT_PACKETS:
2781 return raw1394_iso_send_packets(fi, argp);
2782 case RAW1394_IOC_ISO_SHUTDOWN:
2783 raw1394_iso_shutdown(fi);
2785 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2786 queue_rawiso_event(fi);
2794 /* state-independent commands */
2796 case RAW1394_IOC_GET_CYCLE_TIMER:
2797 return raw1394_read_cycle_timer(fi, argp);
2805 static unsigned int raw1394_poll(struct file *file, poll_table * pt)
2807 struct file_info *fi = file->private_data;
2808 unsigned int mask = POLLOUT | POLLWRNORM;
2809 unsigned long flags;
2811 poll_wait(file, &fi->wait_complete, pt);
2813 spin_lock_irqsave(&fi->reqlists_lock, flags);
2814 if (!list_empty(&fi->req_complete)) {
2815 mask |= POLLIN | POLLRDNORM;
2817 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2822 static int raw1394_open(struct inode *inode, struct file *file)
2824 struct file_info *fi;
2826 fi = kzalloc(sizeof(*fi), GFP_KERNEL);
2830 fi->notification = (u8) RAW1394_NOTIFY_ON; /* busreset notification */
2832 INIT_LIST_HEAD(&fi->list);
2834 INIT_LIST_HEAD(&fi->req_pending);
2835 INIT_LIST_HEAD(&fi->req_complete);
2836 spin_lock_init(&fi->reqlists_lock);
2837 init_waitqueue_head(&fi->wait_complete);
2838 INIT_LIST_HEAD(&fi->addr_list);
2840 file->private_data = fi;
2845 static int raw1394_release(struct inode *inode, struct file *file)
2847 struct file_info *fi = file->private_data;
2848 struct list_head *lh;
2849 struct pending_request *req;
2852 struct list_head *entry;
2853 struct arm_addr *addr = NULL;
2854 struct host_info *hi;
2855 struct file_info *fi_hlp = NULL;
2856 struct arm_addr *arm_addr = NULL;
2859 unsigned long flags;
2861 if (fi->iso_state != RAW1394_ISO_INACTIVE)
2862 raw1394_iso_shutdown(fi);
2864 for (i = 0; i < 64; i++) {
2865 if (fi->listen_channels & (1ULL << i)) {
2866 hpsb_unlisten_channel(&raw1394_highlevel, fi->host, i);
2870 spin_lock_irqsave(&host_info_lock, flags);
2871 fi->listen_channels = 0;
2874 /* set address-entries invalid */
2876 while (!list_empty(&fi->addr_list)) {
2878 lh = fi->addr_list.next;
2879 addr = list_entry(lh, struct arm_addr, addr_list);
2880 /* another host with valid address-entry containing
2881 same addressrange? */
2882 list_for_each_entry(hi, &host_info_list, list) {
2883 if (hi->host != fi->host) {
2884 list_for_each_entry(fi_hlp, &hi->file_info_list,
2886 entry = fi_hlp->addr_list.next;
2887 while (entry != &(fi_hlp->addr_list)) {
2888 arm_addr = list_entry(entry, struct
2891 if (arm_addr->start ==
2894 ("raw1394_release: "
2895 "another host ownes "
2896 "same addressrange");
2900 entry = entry->next;
2908 if (!another_host) {
2909 DBGMSG("raw1394_release: call hpsb_arm_unregister");
2911 hpsb_unregister_addrspace(&raw1394_highlevel,
2912 fi->host, addr->start);
2916 "raw1394_release arm_Unregister failed\n");
2919 DBGMSG("raw1394_release: delete addr_entry from list");
2920 list_del(&addr->addr_list);
2921 vfree(addr->addr_space_buffer);
2924 spin_unlock_irqrestore(&host_info_lock, flags);
2926 printk(KERN_ERR "raw1394: during addr_list-release "
2927 "error(s) occurred \n");
2931 /* This locked section guarantees that neither
2932 * complete nor pending requests exist once i!=0 */
2933 spin_lock_irqsave(&fi->reqlists_lock, flags);
2934 while ((req = __next_complete_req(fi)))
2935 free_pending_request(req);
2937 i = list_empty(&fi->req_pending);
2938 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2943 * Sleep until more requests can be freed.
2945 * NB: We call the macro wait_event() with a condition argument
2946 * with side effect. This is only possible because the side
2947 * effect does not occur until the condition became true, and
2948 * wait_event() won't evaluate the condition again after that.
2950 wait_event(fi->wait_complete, (req = next_complete_req(fi)));
2951 free_pending_request(req);
2954 /* Remove any sub-trees left by user space programs */
2955 for (i = 0; i < RAW1394_MAX_USER_CSR_DIRS; i++) {
2956 struct csr1212_dentry *dentry;
2957 if (!fi->csr1212_dirs[i])
2960 fi->csr1212_dirs[i]->value.directory.dentries_head; dentry;
2961 dentry = dentry->next) {
2962 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2966 csr1212_release_keyval(fi->csr1212_dirs[i]);
2967 fi->csr1212_dirs[i] = NULL;
2971 if ((csr_mod || fi->cfgrom_upd)
2972 && hpsb_update_config_rom_image(fi->host) < 0)
2974 ("Failed to generate Configuration ROM image for host %d",
2977 if (fi->state == connected) {
2978 spin_lock_irqsave(&host_info_lock, flags);
2979 list_del(&fi->list);
2980 spin_unlock_irqrestore(&host_info_lock, flags);
2982 put_device(&fi->host->device);
2985 spin_lock_irqsave(&host_info_lock, flags);
2987 module_put(fi->host->driver->owner);
2988 spin_unlock_irqrestore(&host_info_lock, flags);
2995 /*** HOTPLUG STUFF **********************************************************/
2997 * Export information about protocols/devices supported by this driver.
2999 static struct ieee1394_device_id raw1394_id_table[] = {
3001 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
3002 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
3003 .version = AVC_SW_VERSION_ENTRY & 0xffffff},
3005 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
3006 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
3007 .version = CAMERA_SW_VERSION_ENTRY & 0xffffff},
3009 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
3010 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
3011 .version = (CAMERA_SW_VERSION_ENTRY + 1) & 0xffffff},
3013 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
3014 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
3015 .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff},
3019 MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table);
3021 static struct hpsb_protocol_driver raw1394_driver = {
3023 .id_table = raw1394_id_table,
3026 /******************************************************************************/
3028 static struct hpsb_highlevel raw1394_highlevel = {
3029 .name = RAW1394_DEVICE_NAME,
3030 .add_host = add_host,
3031 .remove_host = remove_host,
3032 .host_reset = host_reset,
3033 .iso_receive = iso_receive,
3034 .fcp_request = fcp_request,
3037 static struct cdev raw1394_cdev;
3038 static const struct file_operations raw1394_fops = {
3039 .owner = THIS_MODULE,
3040 .read = raw1394_read,
3041 .write = raw1394_write,
3042 .mmap = raw1394_mmap,
3043 .ioctl = raw1394_ioctl,
3044 // .compat_ioctl = ... someone needs to do this
3045 .poll = raw1394_poll,
3046 .open = raw1394_open,
3047 .release = raw1394_release,
3050 static int __init init_raw1394(void)
3054 hpsb_register_highlevel(&raw1394_highlevel);
3057 (class_device_create
3058 (hpsb_protocol_class, NULL,
3059 MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16), NULL,
3060 RAW1394_DEVICE_NAME))) {
3065 cdev_init(&raw1394_cdev, &raw1394_fops);
3066 raw1394_cdev.owner = THIS_MODULE;
3067 kobject_set_name(&raw1394_cdev.kobj, RAW1394_DEVICE_NAME);
3068 ret = cdev_add(&raw1394_cdev, IEEE1394_RAW1394_DEV, 1);
3070 HPSB_ERR("raw1394 failed to register minor device block");
3074 HPSB_INFO("raw1394: /dev/%s device initialized", RAW1394_DEVICE_NAME);
3076 ret = hpsb_register_protocol(&raw1394_driver);
3078 HPSB_ERR("raw1394: failed to register protocol");
3079 cdev_del(&raw1394_cdev);
3086 class_device_destroy(hpsb_protocol_class,
3087 MKDEV(IEEE1394_MAJOR,
3088 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
3090 hpsb_unregister_highlevel(&raw1394_highlevel);
3095 static void __exit cleanup_raw1394(void)
3097 class_device_destroy(hpsb_protocol_class,
3098 MKDEV(IEEE1394_MAJOR,
3099 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
3100 cdev_del(&raw1394_cdev);
3101 hpsb_unregister_highlevel(&raw1394_highlevel);
3102 hpsb_unregister_protocol(&raw1394_driver);
3105 module_init(init_raw1394);
3106 module_exit(cleanup_raw1394);
3107 MODULE_LICENSE("GPL");