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/mutex.h>
38 #include <linux/init.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>
47 #include "highlevel.h"
50 #include "ieee1394_core.h"
51 #include "ieee1394_hotplug.h"
52 #include "ieee1394_transactions.h"
53 #include "ieee1394_types.h"
57 #include "raw1394-private.h"
59 #define int2ptr(x) ((void __user *)(unsigned long)x)
60 #define ptr2int(x) ((u64)(unsigned long)(void __user *)x)
62 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
67 #define DBGMSG(fmt, args...) \
68 printk(KERN_INFO "raw1394:" fmt "\n" , ## args)
70 #define DBGMSG(fmt, args...) do {} while (0)
73 static LIST_HEAD(host_info_list);
74 static int host_count;
75 static DEFINE_SPINLOCK(host_info_lock);
76 static atomic_t internal_generation = ATOMIC_INIT(0);
78 static atomic_t iso_buffer_size;
79 static const int iso_buffer_max = 4 * 1024 * 1024; /* 4 MB */
81 static struct hpsb_highlevel raw1394_highlevel;
83 static int arm_read(struct hpsb_host *host, int nodeid, quadlet_t * buffer,
84 u64 addr, size_t length, u16 flags);
85 static int arm_write(struct hpsb_host *host, int nodeid, int destid,
86 quadlet_t * data, u64 addr, size_t length, u16 flags);
87 static int arm_lock(struct hpsb_host *host, int nodeid, quadlet_t * store,
88 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
90 static int arm_lock64(struct hpsb_host *host, int nodeid, octlet_t * store,
91 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
93 static struct hpsb_address_ops arm_ops = {
100 static void queue_complete_cb(struct pending_request *req);
102 static struct pending_request *__alloc_pending_request(gfp_t flags)
104 struct pending_request *req;
106 req = kzalloc(sizeof(*req), flags);
108 INIT_LIST_HEAD(&req->list);
113 static inline struct pending_request *alloc_pending_request(void)
115 return __alloc_pending_request(GFP_KERNEL);
118 static void free_pending_request(struct pending_request *req)
121 if (atomic_dec_and_test(&req->ibs->refcount)) {
122 atomic_sub(req->ibs->data_size, &iso_buffer_size);
125 } else if (req->free_data) {
128 hpsb_free_packet(req->packet);
132 /* fi->reqlists_lock must be taken */
133 static void __queue_complete_req(struct pending_request *req)
135 struct file_info *fi = req->file_info;
137 list_move_tail(&req->list, &fi->req_complete);
138 wake_up(&fi->wait_complete);
141 static void queue_complete_req(struct pending_request *req)
144 struct file_info *fi = req->file_info;
146 spin_lock_irqsave(&fi->reqlists_lock, flags);
147 __queue_complete_req(req);
148 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
151 static void queue_complete_cb(struct pending_request *req)
153 struct hpsb_packet *packet = req->packet;
154 int rcode = (packet->header[1] >> 12) & 0xf;
156 switch (packet->ack_code) {
158 case ACKX_SEND_ERROR:
159 req->req.error = RAW1394_ERROR_SEND_ERROR;
162 req->req.error = RAW1394_ERROR_ABORTED;
165 req->req.error = RAW1394_ERROR_TIMEOUT;
168 req->req.error = (packet->ack_code << 16) | rcode;
172 if (!((packet->ack_code == ACK_PENDING) && (rcode == RCODE_COMPLETE))) {
176 if ((req->req.type == RAW1394_REQ_ASYNC_READ) ||
177 (req->req.type == RAW1394_REQ_ASYNC_WRITE) ||
178 (req->req.type == RAW1394_REQ_ASYNC_STREAM) ||
179 (req->req.type == RAW1394_REQ_LOCK) ||
180 (req->req.type == RAW1394_REQ_LOCK64))
181 hpsb_free_tlabel(packet);
183 queue_complete_req(req);
186 static void add_host(struct hpsb_host *host)
188 struct host_info *hi;
191 hi = kmalloc(sizeof(*hi), GFP_KERNEL);
194 INIT_LIST_HEAD(&hi->list);
196 INIT_LIST_HEAD(&hi->file_info_list);
198 spin_lock_irqsave(&host_info_lock, flags);
199 list_add_tail(&hi->list, &host_info_list);
201 spin_unlock_irqrestore(&host_info_lock, flags);
204 atomic_inc(&internal_generation);
207 static struct host_info *find_host_info(struct hpsb_host *host)
209 struct host_info *hi;
211 list_for_each_entry(hi, &host_info_list, list)
212 if (hi->host == host)
218 static void remove_host(struct hpsb_host *host)
220 struct host_info *hi;
223 spin_lock_irqsave(&host_info_lock, flags);
224 hi = find_host_info(host);
230 FIXME: address ranges should be removed
231 and fileinfo states should be initialized
232 (including setting generation to
233 internal-generation ...)
236 spin_unlock_irqrestore(&host_info_lock, flags);
239 printk(KERN_ERR "raw1394: attempt to remove unknown host "
246 atomic_inc(&internal_generation);
249 static void host_reset(struct hpsb_host *host)
252 struct host_info *hi;
253 struct file_info *fi;
254 struct pending_request *req;
256 spin_lock_irqsave(&host_info_lock, flags);
257 hi = find_host_info(host);
260 list_for_each_entry(fi, &hi->file_info_list, list) {
261 if (fi->notification == RAW1394_NOTIFY_ON) {
262 req = __alloc_pending_request(GFP_ATOMIC);
266 req->req.type = RAW1394_REQ_BUS_RESET;
267 req->req.generation =
268 get_hpsb_generation(host);
269 req->req.misc = (host->node_id << 16)
271 if (fi->protocol_version > 3) {
278 queue_complete_req(req);
283 spin_unlock_irqrestore(&host_info_lock, flags);
286 static void fcp_request(struct hpsb_host *host, int nodeid, int direction,
287 int cts, u8 * data, size_t length)
290 struct host_info *hi;
291 struct file_info *fi;
292 struct pending_request *req, *req_next;
293 struct iso_block_store *ibs = NULL;
296 if ((atomic_read(&iso_buffer_size) + length) > iso_buffer_max) {
297 HPSB_INFO("dropped fcp request");
301 spin_lock_irqsave(&host_info_lock, flags);
302 hi = find_host_info(host);
305 list_for_each_entry(fi, &hi->file_info_list, list) {
309 req = __alloc_pending_request(GFP_ATOMIC);
314 ibs = kmalloc(sizeof(*ibs) + length,
321 atomic_add(length, &iso_buffer_size);
322 atomic_set(&ibs->refcount, 0);
323 ibs->data_size = length;
324 memcpy(ibs->data, data, length);
327 atomic_inc(&ibs->refcount);
331 req->data = ibs->data;
332 req->req.type = RAW1394_REQ_FCP_REQUEST;
333 req->req.generation = get_hpsb_generation(host);
334 req->req.misc = nodeid | (direction << 16);
335 req->req.recvb = ptr2int(fi->fcp_buffer);
336 req->req.length = length;
338 list_add_tail(&req->list, &reqs);
341 spin_unlock_irqrestore(&host_info_lock, flags);
343 list_for_each_entry_safe(req, req_next, &reqs, list)
344 queue_complete_req(req);
348 struct compat_raw1394_req {
363 #if defined(CONFIG_X86_64) || defined(CONFIG_IA64)
364 __attribute__((packed))
368 static const char __user *raw1394_compat_write(const char __user *buf)
370 struct compat_raw1394_req __user *cr = (typeof(cr)) buf;
371 struct raw1394_request __user *r;
372 r = compat_alloc_user_space(sizeof(struct raw1394_request));
374 #define C(x) __copy_in_user(&r->x, &cr->x, sizeof(r->x))
376 if (copy_in_user(r, cr, sizeof(struct compat_raw1394_req)) ||
381 return ERR_PTR(-EFAULT);
382 return (const char __user *)r;
386 #define P(x) __put_user(r->x, &cr->x)
389 raw1394_compat_read(const char __user *buf, struct raw1394_request *r)
391 struct compat_raw1394_req __user *cr = (typeof(cr)) buf;
392 if (!access_ok(VERIFY_WRITE, cr, sizeof(struct compat_raw1394_req)) ||
403 return sizeof(struct compat_raw1394_req);
409 /* get next completed request (caller must hold fi->reqlists_lock) */
410 static inline struct pending_request *__next_complete_req(struct file_info *fi)
412 struct list_head *lh;
413 struct pending_request *req = NULL;
415 if (!list_empty(&fi->req_complete)) {
416 lh = fi->req_complete.next;
418 req = list_entry(lh, struct pending_request, list);
423 /* atomically get next completed request */
424 static struct pending_request *next_complete_req(struct file_info *fi)
427 struct pending_request *req;
429 spin_lock_irqsave(&fi->reqlists_lock, flags);
430 req = __next_complete_req(fi);
431 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
435 static ssize_t raw1394_read(struct file *file, char __user * buffer,
436 size_t count, loff_t * offset_is_ignored)
438 struct file_info *fi = (struct file_info *)file->private_data;
439 struct pending_request *req;
443 if (count == sizeof(struct compat_raw1394_req)) {
447 if (count != sizeof(struct raw1394_request)) {
451 if (!access_ok(VERIFY_WRITE, buffer, count)) {
455 if (file->f_flags & O_NONBLOCK) {
456 if (!(req = next_complete_req(fi)))
460 * NB: We call the macro wait_event_interruptible() with a
461 * condition argument with side effect. This is only possible
462 * because the side effect does not occur until the condition
463 * became true, and wait_event_interruptible() won't evaluate
464 * the condition again after that.
466 if (wait_event_interruptible(fi->wait_complete,
467 (req = next_complete_req(fi))))
471 if (req->req.length) {
472 if (copy_to_user(int2ptr(req->req.recvb), req->data,
474 req->req.error = RAW1394_ERROR_MEMFAULT;
479 if (count == sizeof(struct compat_raw1394_req) &&
480 sizeof(struct compat_raw1394_req) !=
481 sizeof(struct raw1394_request)) {
482 ret = raw1394_compat_read(buffer, &req->req);
486 if (copy_to_user(buffer, &req->req, sizeof(req->req))) {
490 ret = (ssize_t) sizeof(struct raw1394_request);
493 free_pending_request(req);
497 static int state_opened(struct file_info *fi, struct pending_request *req)
499 if (req->req.type == RAW1394_REQ_INITIALIZE) {
500 switch (req->req.misc) {
501 case RAW1394_KERNELAPI_VERSION:
503 fi->state = initialized;
504 fi->protocol_version = req->req.misc;
505 req->req.error = RAW1394_ERROR_NONE;
506 req->req.generation = atomic_read(&internal_generation);
510 req->req.error = RAW1394_ERROR_COMPAT;
511 req->req.misc = RAW1394_KERNELAPI_VERSION;
514 req->req.error = RAW1394_ERROR_STATE_ORDER;
518 queue_complete_req(req);
522 static int state_initialized(struct file_info *fi, struct pending_request *req)
525 struct host_info *hi;
526 struct raw1394_khost_list *khl;
528 if (req->req.generation != atomic_read(&internal_generation)) {
529 req->req.error = RAW1394_ERROR_GENERATION;
530 req->req.generation = atomic_read(&internal_generation);
532 queue_complete_req(req);
536 switch (req->req.type) {
537 case RAW1394_REQ_LIST_CARDS:
538 spin_lock_irqsave(&host_info_lock, flags);
539 khl = kmalloc(sizeof(*khl) * host_count, GFP_ATOMIC);
542 req->req.misc = host_count;
543 req->data = (quadlet_t *) khl;
545 list_for_each_entry(hi, &host_info_list, list) {
546 khl->nodes = hi->host->node_count;
547 strcpy(khl->name, hi->host->driver->name);
551 spin_unlock_irqrestore(&host_info_lock, flags);
554 req->req.error = RAW1394_ERROR_NONE;
555 req->req.length = min(req->req.length,
557 (struct raw1394_khost_list)
565 case RAW1394_REQ_SET_CARD:
566 spin_lock_irqsave(&host_info_lock, flags);
567 if (req->req.misc >= host_count) {
568 req->req.error = RAW1394_ERROR_INVALID_ARG;
571 list_for_each_entry(hi, &host_info_list, list)
572 if (!req->req.misc--)
574 get_device(&hi->host->device); /* FIXME handle failure case */
575 list_add_tail(&fi->list, &hi->file_info_list);
577 /* prevent unloading of the host's low-level driver */
578 if (!try_module_get(hi->host->driver->owner)) {
579 req->req.error = RAW1394_ERROR_ABORTED;
584 fi->state = connected;
586 req->req.error = RAW1394_ERROR_NONE;
587 req->req.generation = get_hpsb_generation(fi->host);
588 req->req.misc = (fi->host->node_id << 16)
589 | fi->host->node_count;
590 if (fi->protocol_version > 3)
591 req->req.misc |= NODEID_TO_NODE(fi->host->irm_id) << 8;
593 spin_unlock_irqrestore(&host_info_lock, flags);
599 req->req.error = RAW1394_ERROR_STATE_ORDER;
604 queue_complete_req(req);
608 static void handle_fcp_listen(struct file_info *fi, struct pending_request *req)
611 if (fi->fcp_buffer) {
612 req->req.error = RAW1394_ERROR_ALREADY;
614 fi->fcp_buffer = int2ptr(req->req.recvb);
617 if (!fi->fcp_buffer) {
618 req->req.error = RAW1394_ERROR_ALREADY;
620 fi->fcp_buffer = NULL;
625 queue_complete_req(req);
628 static int handle_async_request(struct file_info *fi,
629 struct pending_request *req, int node)
632 struct hpsb_packet *packet = NULL;
633 u64 addr = req->req.address & 0xffffffffffffULL;
635 switch (req->req.type) {
636 case RAW1394_REQ_ASYNC_READ:
637 DBGMSG("read_request called");
639 hpsb_make_readpacket(fi->host, node, addr, req->req.length);
644 if (req->req.length == 4)
645 req->data = &packet->header[3];
647 req->data = packet->data;
651 case RAW1394_REQ_ASYNC_WRITE:
652 DBGMSG("write_request called");
654 packet = hpsb_make_writepacket(fi->host, node, addr, NULL,
659 if (req->req.length == 4) {
661 (&packet->header[3], int2ptr(req->req.sendb),
663 req->req.error = RAW1394_ERROR_MEMFAULT;
666 (packet->data, int2ptr(req->req.sendb),
668 req->req.error = RAW1394_ERROR_MEMFAULT;
674 case RAW1394_REQ_ASYNC_STREAM:
675 DBGMSG("stream_request called");
678 hpsb_make_streampacket(fi->host, NULL, req->req.length,
679 node & 0x3f /*channel */ ,
680 (req->req.misc >> 16) & 0x3,
681 req->req.misc & 0xf);
685 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
687 req->req.error = RAW1394_ERROR_MEMFAULT;
692 case RAW1394_REQ_LOCK:
693 DBGMSG("lock_request called");
694 if ((req->req.misc == EXTCODE_FETCH_ADD)
695 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
696 if (req->req.length != 4) {
697 req->req.error = RAW1394_ERROR_INVALID_ARG;
701 if (req->req.length != 8) {
702 req->req.error = RAW1394_ERROR_INVALID_ARG;
707 packet = hpsb_make_lockpacket(fi->host, node, addr,
708 req->req.misc, NULL, 0);
712 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
714 req->req.error = RAW1394_ERROR_MEMFAULT;
718 req->data = packet->data;
722 case RAW1394_REQ_LOCK64:
723 DBGMSG("lock64_request called");
724 if ((req->req.misc == EXTCODE_FETCH_ADD)
725 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
726 if (req->req.length != 8) {
727 req->req.error = RAW1394_ERROR_INVALID_ARG;
731 if (req->req.length != 16) {
732 req->req.error = RAW1394_ERROR_INVALID_ARG;
736 packet = hpsb_make_lock64packet(fi->host, node, addr,
737 req->req.misc, NULL, 0);
741 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
743 req->req.error = RAW1394_ERROR_MEMFAULT;
747 req->data = packet->data;
752 req->req.error = RAW1394_ERROR_STATE_ORDER;
755 req->packet = packet;
757 if (req->req.error) {
759 queue_complete_req(req);
763 hpsb_set_packet_complete_task(packet,
764 (void (*)(void *))queue_complete_cb, req);
766 spin_lock_irqsave(&fi->reqlists_lock, flags);
767 list_add_tail(&req->list, &fi->req_pending);
768 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
770 packet->generation = req->req.generation;
772 if (hpsb_send_packet(packet) < 0) {
773 req->req.error = RAW1394_ERROR_SEND_ERROR;
775 hpsb_free_tlabel(packet);
776 queue_complete_req(req);
781 static int handle_async_send(struct file_info *fi, struct pending_request *req)
784 struct hpsb_packet *packet;
785 int header_length = req->req.misc & 0xffff;
786 int expect_response = req->req.misc >> 16;
789 if (header_length > req->req.length || header_length < 12 ||
790 header_length > FIELD_SIZEOF(struct hpsb_packet, header)) {
791 req->req.error = RAW1394_ERROR_INVALID_ARG;
793 queue_complete_req(req);
797 data_size = req->req.length - header_length;
798 packet = hpsb_alloc_packet(data_size);
799 req->packet = packet;
803 if (copy_from_user(packet->header, int2ptr(req->req.sendb),
805 req->req.error = RAW1394_ERROR_MEMFAULT;
807 queue_complete_req(req);
812 (packet->data, int2ptr(req->req.sendb) + header_length,
814 req->req.error = RAW1394_ERROR_MEMFAULT;
816 queue_complete_req(req);
820 packet->type = hpsb_async;
821 packet->node_id = packet->header[0] >> 16;
822 packet->tcode = (packet->header[0] >> 4) & 0xf;
823 packet->tlabel = (packet->header[0] >> 10) & 0x3f;
824 packet->host = fi->host;
825 packet->expect_response = expect_response;
826 packet->header_size = header_length;
827 packet->data_size = data_size;
830 hpsb_set_packet_complete_task(packet,
831 (void (*)(void *))queue_complete_cb, req);
833 spin_lock_irqsave(&fi->reqlists_lock, flags);
834 list_add_tail(&req->list, &fi->req_pending);
835 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
837 /* Update the generation of the packet just before sending. */
838 packet->generation = req->req.generation;
840 if (hpsb_send_packet(packet) < 0) {
841 req->req.error = RAW1394_ERROR_SEND_ERROR;
842 queue_complete_req(req);
848 static int arm_read(struct hpsb_host *host, int nodeid, quadlet_t * buffer,
849 u64 addr, size_t length, u16 flags)
851 unsigned long irqflags;
852 struct pending_request *req;
853 struct host_info *hi;
854 struct file_info *fi = NULL;
855 struct list_head *entry;
856 struct arm_addr *arm_addr = NULL;
857 struct arm_request *arm_req = NULL;
858 struct arm_response *arm_resp = NULL;
859 int found = 0, size = 0, rcode = -1;
860 struct arm_request_response *arm_req_resp = NULL;
862 DBGMSG("arm_read called by node: %X "
863 "addr: %4.4x %8.8x length: %Zu", nodeid,
864 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
866 spin_lock_irqsave(&host_info_lock, irqflags);
867 hi = find_host_info(host); /* search address-entry */
869 list_for_each_entry(fi, &hi->file_info_list, list) {
870 entry = fi->addr_list.next;
871 while (entry != &(fi->addr_list)) {
873 list_entry(entry, struct arm_addr,
875 if (((arm_addr->start) <= (addr))
876 && ((arm_addr->end) >= (addr + length))) {
889 printk(KERN_ERR "raw1394: arm_read FAILED addr_entry not found"
890 " -> rcode_address_error\n");
891 spin_unlock_irqrestore(&host_info_lock, irqflags);
892 return (RCODE_ADDRESS_ERROR);
894 DBGMSG("arm_read addr_entry FOUND");
896 if (arm_addr->rec_length < length) {
897 DBGMSG("arm_read blocklength too big -> rcode_data_error");
898 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
901 if (arm_addr->access_rights & ARM_READ) {
902 if (!(arm_addr->client_transactions & ARM_READ)) {
904 (arm_addr->addr_space_buffer) + (addr -
908 DBGMSG("arm_read -> (rcode_complete)");
909 rcode = RCODE_COMPLETE;
912 rcode = RCODE_TYPE_ERROR; /* function not allowed */
913 DBGMSG("arm_read -> rcode_type_error (access denied)");
916 if (arm_addr->notification_options & ARM_READ) {
917 DBGMSG("arm_read -> entering notification-section");
918 req = __alloc_pending_request(GFP_ATOMIC);
920 DBGMSG("arm_read -> rcode_conflict_error");
921 spin_unlock_irqrestore(&host_info_lock, irqflags);
922 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
923 The request may be retried */
925 if (rcode == RCODE_COMPLETE) {
927 sizeof(struct arm_request) +
928 sizeof(struct arm_response) +
929 length * sizeof(byte_t) +
930 sizeof(struct arm_request_response);
933 sizeof(struct arm_request) +
934 sizeof(struct arm_response) +
935 sizeof(struct arm_request_response);
937 req->data = kmalloc(size, GFP_ATOMIC);
939 free_pending_request(req);
940 DBGMSG("arm_read -> rcode_conflict_error");
941 spin_unlock_irqrestore(&host_info_lock, irqflags);
942 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
943 The request may be retried */
947 req->req.type = RAW1394_REQ_ARM;
948 req->req.generation = get_hpsb_generation(host);
950 (((length << 16) & (0xFFFF0000)) | (ARM_READ & 0xFF));
951 req->req.tag = arm_addr->arm_tag;
952 req->req.recvb = arm_addr->recvb;
953 req->req.length = size;
954 arm_req_resp = (struct arm_request_response *)(req->data);
955 arm_req = (struct arm_request *)((byte_t *) (req->data) +
958 arm_request_response)));
960 (struct arm_response *)((byte_t *) (arm_req) +
961 (sizeof(struct arm_request)));
962 arm_req->buffer = NULL;
963 arm_resp->buffer = NULL;
964 if (rcode == RCODE_COMPLETE) {
966 (byte_t *) arm_resp + sizeof(struct arm_response);
968 (arm_addr->addr_space_buffer) + (addr -
973 int2ptr((arm_addr->recvb) +
974 sizeof(struct arm_request_response) +
975 sizeof(struct arm_request) +
976 sizeof(struct arm_response));
978 arm_resp->buffer_length =
979 (rcode == RCODE_COMPLETE) ? length : 0;
980 arm_resp->response_code = rcode;
981 arm_req->buffer_length = 0;
982 arm_req->generation = req->req.generation;
983 arm_req->extended_transaction_code = 0;
984 arm_req->destination_offset = addr;
985 arm_req->source_nodeid = nodeid;
986 arm_req->destination_nodeid = host->node_id;
987 arm_req->tlabel = (flags >> 10) & 0x3f;
988 arm_req->tcode = (flags >> 4) & 0x0f;
989 arm_req_resp->request = int2ptr((arm_addr->recvb) +
991 arm_request_response));
992 arm_req_resp->response =
993 int2ptr((arm_addr->recvb) +
994 sizeof(struct arm_request_response) +
995 sizeof(struct arm_request));
996 queue_complete_req(req);
998 spin_unlock_irqrestore(&host_info_lock, irqflags);
1002 static int arm_write(struct hpsb_host *host, int nodeid, int destid,
1003 quadlet_t * data, u64 addr, size_t length, u16 flags)
1005 unsigned long irqflags;
1006 struct pending_request *req;
1007 struct host_info *hi;
1008 struct file_info *fi = NULL;
1009 struct list_head *entry;
1010 struct arm_addr *arm_addr = NULL;
1011 struct arm_request *arm_req = NULL;
1012 struct arm_response *arm_resp = NULL;
1013 int found = 0, size = 0, rcode = -1, length_conflict = 0;
1014 struct arm_request_response *arm_req_resp = NULL;
1016 DBGMSG("arm_write called by node: %X "
1017 "addr: %4.4x %8.8x length: %Zu", nodeid,
1018 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
1020 spin_lock_irqsave(&host_info_lock, irqflags);
1021 hi = find_host_info(host); /* search address-entry */
1023 list_for_each_entry(fi, &hi->file_info_list, list) {
1024 entry = fi->addr_list.next;
1025 while (entry != &(fi->addr_list)) {
1027 list_entry(entry, struct arm_addr,
1029 if (((arm_addr->start) <= (addr))
1030 && ((arm_addr->end) >= (addr + length))) {
1034 entry = entry->next;
1043 printk(KERN_ERR "raw1394: arm_write FAILED addr_entry not found"
1044 " -> rcode_address_error\n");
1045 spin_unlock_irqrestore(&host_info_lock, irqflags);
1046 return (RCODE_ADDRESS_ERROR);
1048 DBGMSG("arm_write addr_entry FOUND");
1050 if (arm_addr->rec_length < length) {
1051 DBGMSG("arm_write blocklength too big -> rcode_data_error");
1052 length_conflict = 1;
1053 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
1056 if (arm_addr->access_rights & ARM_WRITE) {
1057 if (!(arm_addr->client_transactions & ARM_WRITE)) {
1058 memcpy((arm_addr->addr_space_buffer) +
1059 (addr - (arm_addr->start)), data,
1061 DBGMSG("arm_write -> (rcode_complete)");
1062 rcode = RCODE_COMPLETE;
1065 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1066 DBGMSG("arm_write -> rcode_type_error (access denied)");
1069 if (arm_addr->notification_options & ARM_WRITE) {
1070 DBGMSG("arm_write -> entering notification-section");
1071 req = __alloc_pending_request(GFP_ATOMIC);
1073 DBGMSG("arm_write -> rcode_conflict_error");
1074 spin_unlock_irqrestore(&host_info_lock, irqflags);
1075 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1076 The request my be retried */
1079 sizeof(struct arm_request) + sizeof(struct arm_response) +
1080 (length) * sizeof(byte_t) +
1081 sizeof(struct arm_request_response);
1082 req->data = kmalloc(size, GFP_ATOMIC);
1084 free_pending_request(req);
1085 DBGMSG("arm_write -> rcode_conflict_error");
1086 spin_unlock_irqrestore(&host_info_lock, irqflags);
1087 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1088 The request may be retried */
1091 req->file_info = fi;
1092 req->req.type = RAW1394_REQ_ARM;
1093 req->req.generation = get_hpsb_generation(host);
1095 (((length << 16) & (0xFFFF0000)) | (ARM_WRITE & 0xFF));
1096 req->req.tag = arm_addr->arm_tag;
1097 req->req.recvb = arm_addr->recvb;
1098 req->req.length = size;
1099 arm_req_resp = (struct arm_request_response *)(req->data);
1100 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1103 arm_request_response)));
1105 (struct arm_response *)((byte_t *) (arm_req) +
1106 (sizeof(struct arm_request)));
1107 arm_resp->buffer = NULL;
1108 memcpy((byte_t *) arm_resp + sizeof(struct arm_response),
1110 arm_req->buffer = int2ptr((arm_addr->recvb) +
1111 sizeof(struct arm_request_response) +
1112 sizeof(struct arm_request) +
1113 sizeof(struct arm_response));
1114 arm_req->buffer_length = length;
1115 arm_req->generation = req->req.generation;
1116 arm_req->extended_transaction_code = 0;
1117 arm_req->destination_offset = addr;
1118 arm_req->source_nodeid = nodeid;
1119 arm_req->destination_nodeid = destid;
1120 arm_req->tlabel = (flags >> 10) & 0x3f;
1121 arm_req->tcode = (flags >> 4) & 0x0f;
1122 arm_resp->buffer_length = 0;
1123 arm_resp->response_code = rcode;
1124 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1126 arm_request_response));
1127 arm_req_resp->response =
1128 int2ptr((arm_addr->recvb) +
1129 sizeof(struct arm_request_response) +
1130 sizeof(struct arm_request));
1131 queue_complete_req(req);
1133 spin_unlock_irqrestore(&host_info_lock, irqflags);
1137 static int arm_lock(struct hpsb_host *host, int nodeid, quadlet_t * store,
1138 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
1141 unsigned long irqflags;
1142 struct pending_request *req;
1143 struct host_info *hi;
1144 struct file_info *fi = NULL;
1145 struct list_head *entry;
1146 struct arm_addr *arm_addr = NULL;
1147 struct arm_request *arm_req = NULL;
1148 struct arm_response *arm_resp = NULL;
1149 int found = 0, size = 0, rcode = -1;
1151 struct arm_request_response *arm_req_resp = NULL;
1153 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1154 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1155 DBGMSG("arm_lock called by node: %X "
1156 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X",
1157 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1158 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1161 DBGMSG("arm_lock called by node: %X "
1162 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X arg: %8.8X",
1163 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1164 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1165 be32_to_cpu(data), be32_to_cpu(arg));
1167 spin_lock_irqsave(&host_info_lock, irqflags);
1168 hi = find_host_info(host); /* search address-entry */
1170 list_for_each_entry(fi, &hi->file_info_list, list) {
1171 entry = fi->addr_list.next;
1172 while (entry != &(fi->addr_list)) {
1174 list_entry(entry, struct arm_addr,
1176 if (((arm_addr->start) <= (addr))
1177 && ((arm_addr->end) >=
1178 (addr + sizeof(*store)))) {
1182 entry = entry->next;
1191 printk(KERN_ERR "raw1394: arm_lock FAILED addr_entry not found"
1192 " -> rcode_address_error\n");
1193 spin_unlock_irqrestore(&host_info_lock, irqflags);
1194 return (RCODE_ADDRESS_ERROR);
1196 DBGMSG("arm_lock addr_entry FOUND");
1199 if (arm_addr->access_rights & ARM_LOCK) {
1200 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1202 (arm_addr->addr_space_buffer) + (addr -
1206 switch (ext_tcode) {
1207 case (EXTCODE_MASK_SWAP):
1208 new = data | (old & ~arg);
1210 case (EXTCODE_COMPARE_SWAP):
1217 case (EXTCODE_FETCH_ADD):
1219 cpu_to_be32(be32_to_cpu(data) +
1222 case (EXTCODE_LITTLE_ADD):
1224 cpu_to_le32(le32_to_cpu(data) +
1227 case (EXTCODE_BOUNDED_ADD):
1230 cpu_to_be32(be32_to_cpu
1238 case (EXTCODE_WRAP_ADD):
1241 cpu_to_be32(be32_to_cpu
1250 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1252 "raw1394: arm_lock FAILED "
1253 "ext_tcode not allowed -> rcode_type_error\n");
1257 DBGMSG("arm_lock -> (rcode_complete)");
1258 rcode = RCODE_COMPLETE;
1259 memcpy(store, &old, sizeof(*store));
1260 memcpy((arm_addr->addr_space_buffer) +
1261 (addr - (arm_addr->start)),
1262 &new, sizeof(*store));
1266 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1267 DBGMSG("arm_lock -> rcode_type_error (access denied)");
1270 if (arm_addr->notification_options & ARM_LOCK) {
1271 byte_t *buf1, *buf2;
1272 DBGMSG("arm_lock -> entering notification-section");
1273 req = __alloc_pending_request(GFP_ATOMIC);
1275 DBGMSG("arm_lock -> rcode_conflict_error");
1276 spin_unlock_irqrestore(&host_info_lock, irqflags);
1277 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1278 The request may be retried */
1280 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1281 req->data = kmalloc(size, GFP_ATOMIC);
1283 free_pending_request(req);
1284 DBGMSG("arm_lock -> rcode_conflict_error");
1285 spin_unlock_irqrestore(&host_info_lock, irqflags);
1286 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1287 The request may be retried */
1290 arm_req_resp = (struct arm_request_response *)(req->data);
1291 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1294 arm_request_response)));
1296 (struct arm_response *)((byte_t *) (arm_req) +
1297 (sizeof(struct arm_request)));
1298 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1299 buf2 = buf1 + 2 * sizeof(*store);
1300 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1301 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1302 arm_req->buffer_length = sizeof(*store);
1303 memcpy(buf1, &data, sizeof(*store));
1306 arm_req->buffer_length = 2 * sizeof(*store);
1307 memcpy(buf1, &arg, sizeof(*store));
1308 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1310 if (rcode == RCODE_COMPLETE) {
1311 arm_resp->buffer_length = sizeof(*store);
1312 memcpy(buf2, &old, sizeof(*store));
1314 arm_resp->buffer_length = 0;
1316 req->file_info = fi;
1317 req->req.type = RAW1394_REQ_ARM;
1318 req->req.generation = get_hpsb_generation(host);
1319 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1321 req->req.tag = arm_addr->arm_tag;
1322 req->req.recvb = arm_addr->recvb;
1323 req->req.length = size;
1324 arm_req->generation = req->req.generation;
1325 arm_req->extended_transaction_code = ext_tcode;
1326 arm_req->destination_offset = addr;
1327 arm_req->source_nodeid = nodeid;
1328 arm_req->destination_nodeid = host->node_id;
1329 arm_req->tlabel = (flags >> 10) & 0x3f;
1330 arm_req->tcode = (flags >> 4) & 0x0f;
1331 arm_resp->response_code = rcode;
1332 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1334 arm_request_response));
1335 arm_req_resp->response =
1336 int2ptr((arm_addr->recvb) +
1337 sizeof(struct arm_request_response) +
1338 sizeof(struct arm_request));
1340 int2ptr((arm_addr->recvb) +
1341 sizeof(struct arm_request_response) +
1342 sizeof(struct arm_request) +
1343 sizeof(struct arm_response));
1345 int2ptr((arm_addr->recvb) +
1346 sizeof(struct arm_request_response) +
1347 sizeof(struct arm_request) +
1348 sizeof(struct arm_response) + 2 * sizeof(*store));
1349 queue_complete_req(req);
1351 spin_unlock_irqrestore(&host_info_lock, irqflags);
1355 static int arm_lock64(struct hpsb_host *host, int nodeid, octlet_t * store,
1356 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
1359 unsigned long irqflags;
1360 struct pending_request *req;
1361 struct host_info *hi;
1362 struct file_info *fi = NULL;
1363 struct list_head *entry;
1364 struct arm_addr *arm_addr = NULL;
1365 struct arm_request *arm_req = NULL;
1366 struct arm_response *arm_resp = NULL;
1367 int found = 0, size = 0, rcode = -1;
1369 struct arm_request_response *arm_req_resp = NULL;
1371 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1372 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1373 DBGMSG("arm_lock64 called by node: %X "
1374 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X ",
1375 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1376 (u32) (addr & 0xFFFFFFFF),
1378 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1379 (u32) (be64_to_cpu(data) & 0xFFFFFFFF));
1381 DBGMSG("arm_lock64 called by node: %X "
1382 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X arg: "
1384 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1385 (u32) (addr & 0xFFFFFFFF),
1387 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1388 (u32) (be64_to_cpu(data) & 0xFFFFFFFF),
1389 (u32) ((be64_to_cpu(arg) >> 32) & 0xFFFFFFFF),
1390 (u32) (be64_to_cpu(arg) & 0xFFFFFFFF));
1392 spin_lock_irqsave(&host_info_lock, irqflags);
1393 hi = find_host_info(host); /* search addressentry in file_info's for host */
1395 list_for_each_entry(fi, &hi->file_info_list, list) {
1396 entry = fi->addr_list.next;
1397 while (entry != &(fi->addr_list)) {
1399 list_entry(entry, struct arm_addr,
1401 if (((arm_addr->start) <= (addr))
1402 && ((arm_addr->end) >=
1403 (addr + sizeof(*store)))) {
1407 entry = entry->next;
1417 "raw1394: arm_lock64 FAILED addr_entry not found"
1418 " -> rcode_address_error\n");
1419 spin_unlock_irqrestore(&host_info_lock, irqflags);
1420 return (RCODE_ADDRESS_ERROR);
1422 DBGMSG("arm_lock64 addr_entry FOUND");
1425 if (arm_addr->access_rights & ARM_LOCK) {
1426 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1428 (arm_addr->addr_space_buffer) + (addr -
1432 switch (ext_tcode) {
1433 case (EXTCODE_MASK_SWAP):
1434 new = data | (old & ~arg);
1436 case (EXTCODE_COMPARE_SWAP):
1443 case (EXTCODE_FETCH_ADD):
1445 cpu_to_be64(be64_to_cpu(data) +
1448 case (EXTCODE_LITTLE_ADD):
1450 cpu_to_le64(le64_to_cpu(data) +
1453 case (EXTCODE_BOUNDED_ADD):
1456 cpu_to_be64(be64_to_cpu
1464 case (EXTCODE_WRAP_ADD):
1467 cpu_to_be64(be64_to_cpu
1477 "raw1394: arm_lock64 FAILED "
1478 "ext_tcode not allowed -> rcode_type_error\n");
1479 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1484 ("arm_lock64 -> (rcode_complete)");
1485 rcode = RCODE_COMPLETE;
1486 memcpy(store, &old, sizeof(*store));
1487 memcpy((arm_addr->addr_space_buffer) +
1488 (addr - (arm_addr->start)),
1489 &new, sizeof(*store));
1493 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1495 ("arm_lock64 -> rcode_type_error (access denied)");
1498 if (arm_addr->notification_options & ARM_LOCK) {
1499 byte_t *buf1, *buf2;
1500 DBGMSG("arm_lock64 -> entering notification-section");
1501 req = __alloc_pending_request(GFP_ATOMIC);
1503 spin_unlock_irqrestore(&host_info_lock, irqflags);
1504 DBGMSG("arm_lock64 -> rcode_conflict_error");
1505 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1506 The request may be retried */
1508 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1509 req->data = kmalloc(size, GFP_ATOMIC);
1511 free_pending_request(req);
1512 spin_unlock_irqrestore(&host_info_lock, irqflags);
1513 DBGMSG("arm_lock64 -> rcode_conflict_error");
1514 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1515 The request may be retried */
1518 arm_req_resp = (struct arm_request_response *)(req->data);
1519 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1522 arm_request_response)));
1524 (struct arm_response *)((byte_t *) (arm_req) +
1525 (sizeof(struct arm_request)));
1526 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1527 buf2 = buf1 + 2 * sizeof(*store);
1528 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1529 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1530 arm_req->buffer_length = sizeof(*store);
1531 memcpy(buf1, &data, sizeof(*store));
1534 arm_req->buffer_length = 2 * sizeof(*store);
1535 memcpy(buf1, &arg, sizeof(*store));
1536 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1538 if (rcode == RCODE_COMPLETE) {
1539 arm_resp->buffer_length = sizeof(*store);
1540 memcpy(buf2, &old, sizeof(*store));
1542 arm_resp->buffer_length = 0;
1544 req->file_info = fi;
1545 req->req.type = RAW1394_REQ_ARM;
1546 req->req.generation = get_hpsb_generation(host);
1547 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1549 req->req.tag = arm_addr->arm_tag;
1550 req->req.recvb = arm_addr->recvb;
1551 req->req.length = size;
1552 arm_req->generation = req->req.generation;
1553 arm_req->extended_transaction_code = ext_tcode;
1554 arm_req->destination_offset = addr;
1555 arm_req->source_nodeid = nodeid;
1556 arm_req->destination_nodeid = host->node_id;
1557 arm_req->tlabel = (flags >> 10) & 0x3f;
1558 arm_req->tcode = (flags >> 4) & 0x0f;
1559 arm_resp->response_code = rcode;
1560 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1562 arm_request_response));
1563 arm_req_resp->response =
1564 int2ptr((arm_addr->recvb) +
1565 sizeof(struct arm_request_response) +
1566 sizeof(struct arm_request));
1568 int2ptr((arm_addr->recvb) +
1569 sizeof(struct arm_request_response) +
1570 sizeof(struct arm_request) +
1571 sizeof(struct arm_response));
1573 int2ptr((arm_addr->recvb) +
1574 sizeof(struct arm_request_response) +
1575 sizeof(struct arm_request) +
1576 sizeof(struct arm_response) + 2 * sizeof(*store));
1577 queue_complete_req(req);
1579 spin_unlock_irqrestore(&host_info_lock, irqflags);
1583 static int arm_register(struct file_info *fi, struct pending_request *req)
1586 struct arm_addr *addr;
1587 struct host_info *hi;
1588 struct file_info *fi_hlp = NULL;
1589 struct list_head *entry;
1590 struct arm_addr *arm_addr = NULL;
1591 int same_host, another_host;
1592 unsigned long flags;
1594 DBGMSG("arm_register called "
1595 "addr(Offset): %8.8x %8.8x length: %u "
1596 "rights: %2.2X notify: %2.2X "
1597 "max_blk_len: %4.4X",
1598 (u32) ((req->req.address >> 32) & 0xFFFF),
1599 (u32) (req->req.address & 0xFFFFFFFF),
1600 req->req.length, ((req->req.misc >> 8) & 0xFF),
1601 (req->req.misc & 0xFF), ((req->req.misc >> 16) & 0xFFFF));
1602 /* check addressrange */
1603 if ((((req->req.address) & ~(0xFFFFFFFFFFFFULL)) != 0) ||
1604 (((req->req.address + req->req.length) & ~(0xFFFFFFFFFFFFULL)) !=
1606 req->req.length = 0;
1609 /* addr-list-entry for fileinfo */
1610 addr = kmalloc(sizeof(*addr), GFP_KERNEL);
1612 req->req.length = 0;
1615 /* allocation of addr_space_buffer */
1616 addr->addr_space_buffer = vmalloc(req->req.length);
1617 if (!(addr->addr_space_buffer)) {
1619 req->req.length = 0;
1622 /* initialization of addr_space_buffer */
1623 if ((req->req.sendb) == (unsigned long)NULL) {
1625 memset(addr->addr_space_buffer, 0, req->req.length);
1627 /* init: user -> kernel */
1629 (addr->addr_space_buffer, int2ptr(req->req.sendb),
1631 vfree(addr->addr_space_buffer);
1636 INIT_LIST_HEAD(&addr->addr_list);
1637 addr->arm_tag = req->req.tag;
1638 addr->start = req->req.address;
1639 addr->end = req->req.address + req->req.length;
1640 addr->access_rights = (u8) (req->req.misc & 0x0F);
1641 addr->notification_options = (u8) ((req->req.misc >> 4) & 0x0F);
1642 addr->client_transactions = (u8) ((req->req.misc >> 8) & 0x0F);
1643 addr->access_rights |= addr->client_transactions;
1644 addr->notification_options |= addr->client_transactions;
1645 addr->recvb = req->req.recvb;
1646 addr->rec_length = (u16) ((req->req.misc >> 16) & 0xFFFF);
1648 spin_lock_irqsave(&host_info_lock, flags);
1649 hi = find_host_info(fi->host);
1652 /* same host with address-entry containing same addressrange ? */
1653 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1654 entry = fi_hlp->addr_list.next;
1655 while (entry != &(fi_hlp->addr_list)) {
1657 list_entry(entry, struct arm_addr, addr_list);
1658 if ((arm_addr->start == addr->start)
1659 && (arm_addr->end == addr->end)) {
1660 DBGMSG("same host ownes same "
1661 "addressrange -> EALREADY");
1665 entry = entry->next;
1672 /* addressrange occupied by same host */
1673 spin_unlock_irqrestore(&host_info_lock, flags);
1674 vfree(addr->addr_space_buffer);
1678 /* another host with valid address-entry containing same addressrange */
1679 list_for_each_entry(hi, &host_info_list, list) {
1680 if (hi->host != fi->host) {
1681 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1682 entry = fi_hlp->addr_list.next;
1683 while (entry != &(fi_hlp->addr_list)) {
1685 list_entry(entry, struct arm_addr,
1687 if ((arm_addr->start == addr->start)
1688 && (arm_addr->end == addr->end)) {
1690 ("another host ownes same "
1695 entry = entry->next;
1703 spin_unlock_irqrestore(&host_info_lock, flags);
1706 DBGMSG("another hosts entry is valid -> SUCCESS");
1707 if (copy_to_user(int2ptr(req->req.recvb),
1708 &addr->start, sizeof(u64))) {
1709 printk(KERN_ERR "raw1394: arm_register failed "
1710 " address-range-entry is invalid -> EFAULT !!!\n");
1711 vfree(addr->addr_space_buffer);
1715 free_pending_request(req); /* immediate success or fail */
1717 spin_lock_irqsave(&host_info_lock, flags);
1718 list_add_tail(&addr->addr_list, &fi->addr_list);
1719 spin_unlock_irqrestore(&host_info_lock, flags);
1723 hpsb_register_addrspace(&raw1394_highlevel, fi->host, &arm_ops,
1725 req->req.address + req->req.length);
1728 spin_lock_irqsave(&host_info_lock, flags);
1729 list_add_tail(&addr->addr_list, &fi->addr_list);
1730 spin_unlock_irqrestore(&host_info_lock, flags);
1732 DBGMSG("arm_register failed errno: %d \n", retval);
1733 vfree(addr->addr_space_buffer);
1737 free_pending_request(req); /* immediate success or fail */
1741 static int arm_unregister(struct file_info *fi, struct pending_request *req)
1745 struct list_head *entry;
1746 struct arm_addr *addr = NULL;
1747 struct host_info *hi;
1748 struct file_info *fi_hlp = NULL;
1749 struct arm_addr *arm_addr = NULL;
1751 unsigned long flags;
1753 DBGMSG("arm_Unregister called addr(Offset): "
1755 (u32) ((req->req.address >> 32) & 0xFFFF),
1756 (u32) (req->req.address & 0xFFFFFFFF));
1757 spin_lock_irqsave(&host_info_lock, flags);
1759 entry = fi->addr_list.next;
1760 while (entry != &(fi->addr_list)) {
1761 addr = list_entry(entry, struct arm_addr, addr_list);
1762 if (addr->start == req->req.address) {
1766 entry = entry->next;
1769 DBGMSG("arm_Unregister addr not found");
1770 spin_unlock_irqrestore(&host_info_lock, flags);
1773 DBGMSG("arm_Unregister addr found");
1775 /* another host with valid address-entry containing
1776 same addressrange */
1777 list_for_each_entry(hi, &host_info_list, list) {
1778 if (hi->host != fi->host) {
1779 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1780 entry = fi_hlp->addr_list.next;
1781 while (entry != &(fi_hlp->addr_list)) {
1782 arm_addr = list_entry(entry,
1785 if (arm_addr->start == addr->start) {
1786 DBGMSG("another host ownes "
1787 "same addressrange");
1791 entry = entry->next;
1800 DBGMSG("delete entry from list -> success");
1801 list_del(&addr->addr_list);
1802 spin_unlock_irqrestore(&host_info_lock, flags);
1803 vfree(addr->addr_space_buffer);
1805 free_pending_request(req); /* immediate success or fail */
1809 hpsb_unregister_addrspace(&raw1394_highlevel, fi->host,
1812 printk(KERN_ERR "raw1394: arm_Unregister failed -> EINVAL\n");
1813 spin_unlock_irqrestore(&host_info_lock, flags);
1816 DBGMSG("delete entry from list -> success");
1817 list_del(&addr->addr_list);
1818 spin_unlock_irqrestore(&host_info_lock, flags);
1819 vfree(addr->addr_space_buffer);
1821 free_pending_request(req); /* immediate success or fail */
1825 /* Copy data from ARM buffer(s) to user buffer. */
1826 static int arm_get_buf(struct file_info *fi, struct pending_request *req)
1828 struct arm_addr *arm_addr = NULL;
1829 unsigned long flags;
1830 unsigned long offset;
1832 struct list_head *entry;
1834 DBGMSG("arm_get_buf "
1835 "addr(Offset): %04X %08X length: %u",
1836 (u32) ((req->req.address >> 32) & 0xFFFF),
1837 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
1839 spin_lock_irqsave(&host_info_lock, flags);
1840 entry = fi->addr_list.next;
1841 while (entry != &(fi->addr_list)) {
1842 arm_addr = list_entry(entry, struct arm_addr, addr_list);
1843 if ((arm_addr->start <= req->req.address) &&
1844 (arm_addr->end > req->req.address)) {
1845 if (req->req.address + req->req.length <= arm_addr->end) {
1846 offset = req->req.address - arm_addr->start;
1847 spin_unlock_irqrestore(&host_info_lock, flags);
1850 ("arm_get_buf copy_to_user( %08X, %p, %u )",
1851 (u32) req->req.recvb,
1852 arm_addr->addr_space_buffer + offset,
1853 (u32) req->req.length);
1855 (int2ptr(req->req.recvb),
1856 arm_addr->addr_space_buffer + offset,
1860 /* We have to free the request, because we
1861 * queue no response, and therefore nobody
1863 free_pending_request(req);
1866 DBGMSG("arm_get_buf request exceeded mapping");
1867 spin_unlock_irqrestore(&host_info_lock, flags);
1871 entry = entry->next;
1873 spin_unlock_irqrestore(&host_info_lock, flags);
1877 /* Copy data from user buffer to ARM buffer(s). */
1878 static int arm_set_buf(struct file_info *fi, struct pending_request *req)
1880 struct arm_addr *arm_addr = NULL;
1881 unsigned long flags;
1882 unsigned long offset;
1884 struct list_head *entry;
1886 DBGMSG("arm_set_buf "
1887 "addr(Offset): %04X %08X length: %u",
1888 (u32) ((req->req.address >> 32) & 0xFFFF),
1889 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
1891 spin_lock_irqsave(&host_info_lock, flags);
1892 entry = fi->addr_list.next;
1893 while (entry != &(fi->addr_list)) {
1894 arm_addr = list_entry(entry, struct arm_addr, addr_list);
1895 if ((arm_addr->start <= req->req.address) &&
1896 (arm_addr->end > req->req.address)) {
1897 if (req->req.address + req->req.length <= arm_addr->end) {
1898 offset = req->req.address - arm_addr->start;
1899 spin_unlock_irqrestore(&host_info_lock, flags);
1902 ("arm_set_buf copy_from_user( %p, %08X, %u )",
1903 arm_addr->addr_space_buffer + offset,
1904 (u32) req->req.sendb,
1905 (u32) req->req.length);
1907 (arm_addr->addr_space_buffer + offset,
1908 int2ptr(req->req.sendb),
1912 /* We have to free the request, because we
1913 * queue no response, and therefore nobody
1915 free_pending_request(req);
1918 DBGMSG("arm_set_buf request exceeded mapping");
1919 spin_unlock_irqrestore(&host_info_lock, flags);
1923 entry = entry->next;
1925 spin_unlock_irqrestore(&host_info_lock, flags);
1929 static int reset_notification(struct file_info *fi, struct pending_request *req)
1931 DBGMSG("reset_notification called - switch %s ",
1932 (req->req.misc == RAW1394_NOTIFY_OFF) ? "OFF" : "ON");
1933 if ((req->req.misc == RAW1394_NOTIFY_OFF) ||
1934 (req->req.misc == RAW1394_NOTIFY_ON)) {
1935 fi->notification = (u8) req->req.misc;
1936 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
1939 /* error EINVAL (22) invalid argument */
1943 static int write_phypacket(struct file_info *fi, struct pending_request *req)
1945 struct hpsb_packet *packet = NULL;
1948 unsigned long flags;
1950 data = be32_to_cpu((u32) req->req.sendb);
1951 DBGMSG("write_phypacket called - quadlet 0x%8.8x ", data);
1952 packet = hpsb_make_phypacket(fi->host, data);
1955 req->req.length = 0;
1956 req->packet = packet;
1957 hpsb_set_packet_complete_task(packet,
1958 (void (*)(void *))queue_complete_cb, req);
1959 spin_lock_irqsave(&fi->reqlists_lock, flags);
1960 list_add_tail(&req->list, &fi->req_pending);
1961 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
1962 packet->generation = req->req.generation;
1963 retval = hpsb_send_packet(packet);
1964 DBGMSG("write_phypacket send_packet called => retval: %d ", retval);
1966 req->req.error = RAW1394_ERROR_SEND_ERROR;
1967 req->req.length = 0;
1968 queue_complete_req(req);
1973 static int get_config_rom(struct file_info *fi, struct pending_request *req)
1976 quadlet_t *data = kmalloc(req->req.length, GFP_KERNEL);
1983 csr1212_read(fi->host->csr.rom, CSR1212_CONFIG_ROM_SPACE_OFFSET,
1984 data, req->req.length);
1985 if (copy_to_user(int2ptr(req->req.recvb), data, req->req.length))
1988 (int2ptr(req->req.tag), &fi->host->csr.rom->cache_head->len,
1989 sizeof(fi->host->csr.rom->cache_head->len)))
1991 if (copy_to_user(int2ptr(req->req.address), &fi->host->csr.generation,
1992 sizeof(fi->host->csr.generation)))
1994 if (copy_to_user(int2ptr(req->req.sendb), &status, sizeof(status)))
1998 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2003 static int update_config_rom(struct file_info *fi, struct pending_request *req)
2006 quadlet_t *data = kmalloc(req->req.length, GFP_KERNEL);
2009 if (copy_from_user(data, int2ptr(req->req.sendb), req->req.length)) {
2012 int status = hpsb_update_config_rom(fi->host,
2013 data, req->req.length,
2014 (unsigned char)req->req.
2017 (int2ptr(req->req.recvb), &status, sizeof(status)))
2022 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2028 static int modify_config_rom(struct file_info *fi, struct pending_request *req)
2030 struct csr1212_keyval *kv;
2031 struct csr1212_csr_rom_cache *cache;
2032 struct csr1212_dentry *dentry;
2036 if (req->req.misc == ~0) {
2037 if (req->req.length == 0)
2040 /* Find an unused slot */
2042 dr < RAW1394_MAX_USER_CSR_DIRS && fi->csr1212_dirs[dr];
2045 if (dr == RAW1394_MAX_USER_CSR_DIRS)
2048 fi->csr1212_dirs[dr] =
2049 csr1212_new_directory(CSR1212_KV_ID_VENDOR);
2050 if (!fi->csr1212_dirs[dr])
2054 if (!fi->csr1212_dirs[dr])
2057 /* Delete old stuff */
2059 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2060 dentry; dentry = dentry->next) {
2061 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2066 if (req->req.length == 0) {
2067 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2068 fi->csr1212_dirs[dr] = NULL;
2070 hpsb_update_config_rom_image(fi->host);
2071 free_pending_request(req);
2076 cache = csr1212_rom_cache_malloc(0, req->req.length);
2078 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2079 fi->csr1212_dirs[dr] = NULL;
2083 cache->filled_head = kmalloc(sizeof(*cache->filled_head), GFP_KERNEL);
2084 if (!cache->filled_head) {
2085 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2086 fi->csr1212_dirs[dr] = NULL;
2087 CSR1212_FREE(cache);
2090 cache->filled_tail = cache->filled_head;
2092 if (copy_from_user(cache->data, int2ptr(req->req.sendb),
2094 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2095 fi->csr1212_dirs[dr] = NULL;
2098 cache->len = req->req.length;
2099 cache->filled_head->offset_start = 0;
2100 cache->filled_head->offset_end = cache->size - 1;
2102 cache->layout_head = cache->layout_tail = fi->csr1212_dirs[dr];
2104 ret = CSR1212_SUCCESS;
2105 /* parse all the items */
2106 for (kv = cache->layout_head; ret == CSR1212_SUCCESS && kv;
2108 ret = csr1212_parse_keyval(kv, cache);
2111 /* attach top level items to the root directory */
2113 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2114 ret == CSR1212_SUCCESS && dentry; dentry = dentry->next) {
2116 csr1212_attach_keyval_to_directory(fi->host->csr.
2121 if (ret == CSR1212_SUCCESS) {
2122 ret = hpsb_update_config_rom_image(fi->host);
2124 if (ret >= 0 && copy_to_user(int2ptr(req->req.recvb),
2130 kfree(cache->filled_head);
2131 CSR1212_FREE(cache);
2134 /* we have to free the request, because we queue no response,
2135 * and therefore nobody will free it */
2136 free_pending_request(req);
2140 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2141 dentry; dentry = dentry->next) {
2142 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2146 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2147 fi->csr1212_dirs[dr] = NULL;
2152 static int state_connected(struct file_info *fi, struct pending_request *req)
2154 int node = req->req.address >> 48;
2156 req->req.error = RAW1394_ERROR_NONE;
2158 switch (req->req.type) {
2160 case RAW1394_REQ_ECHO:
2161 queue_complete_req(req);
2164 case RAW1394_REQ_ARM_REGISTER:
2165 return arm_register(fi, req);
2167 case RAW1394_REQ_ARM_UNREGISTER:
2168 return arm_unregister(fi, req);
2170 case RAW1394_REQ_ARM_SET_BUF:
2171 return arm_set_buf(fi, req);
2173 case RAW1394_REQ_ARM_GET_BUF:
2174 return arm_get_buf(fi, req);
2176 case RAW1394_REQ_RESET_NOTIFY:
2177 return reset_notification(fi, req);
2179 case RAW1394_REQ_ISO_SEND:
2180 case RAW1394_REQ_ISO_LISTEN:
2181 printk(KERN_DEBUG "raw1394: old iso ABI has been removed\n");
2182 req->req.error = RAW1394_ERROR_COMPAT;
2183 req->req.misc = RAW1394_KERNELAPI_VERSION;
2184 queue_complete_req(req);
2187 case RAW1394_REQ_FCP_LISTEN:
2188 handle_fcp_listen(fi, req);
2191 case RAW1394_REQ_RESET_BUS:
2192 if (req->req.misc == RAW1394_LONG_RESET) {
2193 DBGMSG("busreset called (type: LONG)");
2194 hpsb_reset_bus(fi->host, LONG_RESET);
2195 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2198 if (req->req.misc == RAW1394_SHORT_RESET) {
2199 DBGMSG("busreset called (type: SHORT)");
2200 hpsb_reset_bus(fi->host, SHORT_RESET);
2201 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2204 /* error EINVAL (22) invalid argument */
2206 case RAW1394_REQ_GET_ROM:
2207 return get_config_rom(fi, req);
2209 case RAW1394_REQ_UPDATE_ROM:
2210 return update_config_rom(fi, req);
2212 case RAW1394_REQ_MODIFY_ROM:
2213 return modify_config_rom(fi, req);
2216 if (req->req.generation != get_hpsb_generation(fi->host)) {
2217 req->req.error = RAW1394_ERROR_GENERATION;
2218 req->req.generation = get_hpsb_generation(fi->host);
2219 req->req.length = 0;
2220 queue_complete_req(req);
2224 switch (req->req.type) {
2225 case RAW1394_REQ_PHYPACKET:
2226 return write_phypacket(fi, req);
2227 case RAW1394_REQ_ASYNC_SEND:
2228 return handle_async_send(fi, req);
2231 if (req->req.length == 0) {
2232 req->req.error = RAW1394_ERROR_INVALID_ARG;
2233 queue_complete_req(req);
2237 return handle_async_request(fi, req, node);
2240 static ssize_t raw1394_write(struct file *file, const char __user * buffer,
2241 size_t count, loff_t * offset_is_ignored)
2243 struct file_info *fi = (struct file_info *)file->private_data;
2244 struct pending_request *req;
2245 ssize_t retval = -EBADFD;
2247 #ifdef CONFIG_COMPAT
2248 if (count == sizeof(struct compat_raw1394_req) &&
2249 sizeof(struct compat_raw1394_req) !=
2250 sizeof(struct raw1394_request)) {
2251 buffer = raw1394_compat_write(buffer);
2253 return PTR_ERR(buffer);
2256 if (count != sizeof(struct raw1394_request)) {
2260 req = alloc_pending_request();
2264 req->file_info = fi;
2266 if (copy_from_user(&req->req, buffer, sizeof(struct raw1394_request))) {
2267 free_pending_request(req);
2271 if (!mutex_trylock(&fi->state_mutex))
2274 switch (fi->state) {
2276 retval = state_opened(fi, req);
2280 retval = state_initialized(fi, req);
2284 retval = state_connected(fi, req);
2288 mutex_unlock(&fi->state_mutex);
2291 free_pending_request(req);
2300 /* rawiso operations */
2302 /* check if any RAW1394_REQ_RAWISO_ACTIVITY event is already in the
2303 * completion queue (reqlists_lock must be taken) */
2304 static inline int __rawiso_event_in_queue(struct file_info *fi)
2306 struct pending_request *req;
2308 list_for_each_entry(req, &fi->req_complete, list)
2309 if (req->req.type == RAW1394_REQ_RAWISO_ACTIVITY)
2315 /* put a RAWISO_ACTIVITY event in the queue, if one isn't there already */
2316 static void queue_rawiso_event(struct file_info *fi)
2318 unsigned long flags;
2320 spin_lock_irqsave(&fi->reqlists_lock, flags);
2322 /* only one ISO activity event may be in the queue */
2323 if (!__rawiso_event_in_queue(fi)) {
2324 struct pending_request *req =
2325 __alloc_pending_request(GFP_ATOMIC);
2328 req->file_info = fi;
2329 req->req.type = RAW1394_REQ_RAWISO_ACTIVITY;
2330 req->req.generation = get_hpsb_generation(fi->host);
2331 __queue_complete_req(req);
2333 /* on allocation failure, signal an overflow */
2334 if (fi->iso_handle) {
2335 atomic_inc(&fi->iso_handle->overflows);
2339 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2342 static void rawiso_activity_cb(struct hpsb_iso *iso)
2344 unsigned long flags;
2345 struct host_info *hi;
2346 struct file_info *fi;
2348 spin_lock_irqsave(&host_info_lock, flags);
2349 hi = find_host_info(iso->host);
2352 list_for_each_entry(fi, &hi->file_info_list, list) {
2353 if (fi->iso_handle == iso)
2354 queue_rawiso_event(fi);
2358 spin_unlock_irqrestore(&host_info_lock, flags);
2361 /* helper function - gather all the kernel iso status bits for returning to user-space */
2362 static void raw1394_iso_fill_status(struct hpsb_iso *iso,
2363 struct raw1394_iso_status *stat)
2365 int overflows = atomic_read(&iso->overflows);
2366 int skips = atomic_read(&iso->skips);
2368 stat->config.data_buf_size = iso->buf_size;
2369 stat->config.buf_packets = iso->buf_packets;
2370 stat->config.channel = iso->channel;
2371 stat->config.speed = iso->speed;
2372 stat->config.irq_interval = iso->irq_interval;
2373 stat->n_packets = hpsb_iso_n_ready(iso);
2374 stat->overflows = ((skips & 0xFFFF) << 16) | ((overflows & 0xFFFF));
2375 stat->xmit_cycle = iso->xmit_cycle;
2378 static int raw1394_iso_xmit_init(struct file_info *fi, void __user * uaddr)
2380 struct raw1394_iso_status stat;
2385 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2388 fi->iso_handle = hpsb_iso_xmit_init(fi->host,
2389 stat.config.data_buf_size,
2390 stat.config.buf_packets,
2391 stat.config.channel,
2393 stat.config.irq_interval,
2394 rawiso_activity_cb);
2395 if (!fi->iso_handle)
2398 fi->iso_state = RAW1394_ISO_XMIT;
2400 raw1394_iso_fill_status(fi->iso_handle, &stat);
2401 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2404 /* queue an event to get things started */
2405 rawiso_activity_cb(fi->iso_handle);
2410 static int raw1394_iso_recv_init(struct file_info *fi, void __user * uaddr)
2412 struct raw1394_iso_status stat;
2417 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2420 fi->iso_handle = hpsb_iso_recv_init(fi->host,
2421 stat.config.data_buf_size,
2422 stat.config.buf_packets,
2423 stat.config.channel,
2424 stat.config.dma_mode,
2425 stat.config.irq_interval,
2426 rawiso_activity_cb);
2427 if (!fi->iso_handle)
2430 fi->iso_state = RAW1394_ISO_RECV;
2432 raw1394_iso_fill_status(fi->iso_handle, &stat);
2433 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2438 static int raw1394_iso_get_status(struct file_info *fi, void __user * uaddr)
2440 struct raw1394_iso_status stat;
2441 struct hpsb_iso *iso = fi->iso_handle;
2443 raw1394_iso_fill_status(fi->iso_handle, &stat);
2444 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2447 /* reset overflow counter */
2448 atomic_set(&iso->overflows, 0);
2449 /* reset skip counter */
2450 atomic_set(&iso->skips, 0);
2455 /* copy N packet_infos out of the ringbuffer into user-supplied array */
2456 static int raw1394_iso_recv_packets(struct file_info *fi, void __user * uaddr)
2458 struct raw1394_iso_packets upackets;
2459 unsigned int packet = fi->iso_handle->first_packet;
2462 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2465 if (upackets.n_packets > hpsb_iso_n_ready(fi->iso_handle))
2468 /* ensure user-supplied buffer is accessible and big enough */
2469 if (!access_ok(VERIFY_WRITE, upackets.infos,
2470 upackets.n_packets *
2471 sizeof(struct raw1394_iso_packet_info)))
2474 /* copy the packet_infos out */
2475 for (i = 0; i < upackets.n_packets; i++) {
2476 if (__copy_to_user(&upackets.infos[i],
2477 &fi->iso_handle->infos[packet],
2478 sizeof(struct raw1394_iso_packet_info)))
2481 packet = (packet + 1) % fi->iso_handle->buf_packets;
2487 /* copy N packet_infos from user to ringbuffer, and queue them for transmission */
2488 static int raw1394_iso_send_packets(struct file_info *fi, void __user * uaddr)
2490 struct raw1394_iso_packets upackets;
2493 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2496 if (upackets.n_packets >= fi->iso_handle->buf_packets)
2499 if (upackets.n_packets >= hpsb_iso_n_ready(fi->iso_handle))
2502 /* ensure user-supplied buffer is accessible and big enough */
2503 if (!access_ok(VERIFY_READ, upackets.infos,
2504 upackets.n_packets *
2505 sizeof(struct raw1394_iso_packet_info)))
2508 /* copy the infos structs in and queue the packets */
2509 for (i = 0; i < upackets.n_packets; i++) {
2510 struct raw1394_iso_packet_info info;
2512 if (__copy_from_user(&info, &upackets.infos[i],
2513 sizeof(struct raw1394_iso_packet_info)))
2516 rv = hpsb_iso_xmit_queue_packet(fi->iso_handle, info.offset,
2517 info.len, info.tag, info.sy);
2525 static void raw1394_iso_shutdown(struct file_info *fi)
2528 hpsb_iso_shutdown(fi->iso_handle);
2530 fi->iso_handle = NULL;
2531 fi->iso_state = RAW1394_ISO_INACTIVE;
2534 static int raw1394_read_cycle_timer(struct file_info *fi, void __user * uaddr)
2536 struct raw1394_cycle_timer ct;
2539 err = hpsb_read_cycle_timer(fi->host, &ct.cycle_timer, &ct.local_time);
2541 if (copy_to_user(uaddr, &ct, sizeof(ct)))
2546 /* mmap the rawiso xmit/recv buffer */
2547 static int raw1394_mmap(struct file *file, struct vm_area_struct *vma)
2549 struct file_info *fi = file->private_data;
2552 if (!mutex_trylock(&fi->state_mutex))
2555 if (fi->iso_state == RAW1394_ISO_INACTIVE)
2558 ret = dma_region_mmap(&fi->iso_handle->data_buf, file, vma);
2560 mutex_unlock(&fi->state_mutex);
2565 static long raw1394_ioctl_inactive(struct file_info *fi, unsigned int cmd,
2569 case RAW1394_IOC_ISO_XMIT_INIT:
2570 return raw1394_iso_xmit_init(fi, argp);
2571 case RAW1394_IOC_ISO_RECV_INIT:
2572 return raw1394_iso_recv_init(fi, argp);
2578 static long raw1394_ioctl_recv(struct file_info *fi, unsigned int cmd,
2581 void __user *argp = (void __user *)arg;
2584 case RAW1394_IOC_ISO_RECV_START:{
2587 if (copy_from_user(&args[0], argp, sizeof(args)))
2589 return hpsb_iso_recv_start(fi->iso_handle,
2590 args[0], args[1], args[2]);
2592 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2593 hpsb_iso_stop(fi->iso_handle);
2595 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL:
2596 return hpsb_iso_recv_listen_channel(fi->iso_handle, arg);
2597 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
2598 return hpsb_iso_recv_unlisten_channel(fi->iso_handle, arg);
2599 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:{
2602 if (copy_from_user(&mask, argp, sizeof(mask)))
2604 return hpsb_iso_recv_set_channel_mask(fi->iso_handle,
2607 case RAW1394_IOC_ISO_GET_STATUS:
2608 return raw1394_iso_get_status(fi, argp);
2609 case RAW1394_IOC_ISO_RECV_PACKETS:
2610 return raw1394_iso_recv_packets(fi, argp);
2611 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
2612 return hpsb_iso_recv_release_packets(fi->iso_handle, arg);
2613 case RAW1394_IOC_ISO_RECV_FLUSH:
2614 return hpsb_iso_recv_flush(fi->iso_handle);
2615 case RAW1394_IOC_ISO_SHUTDOWN:
2616 raw1394_iso_shutdown(fi);
2618 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2619 queue_rawiso_event(fi);
2626 static long raw1394_ioctl_xmit(struct file_info *fi, unsigned int cmd,
2630 case RAW1394_IOC_ISO_XMIT_START:{
2633 if (copy_from_user(&args[0], argp, sizeof(args)))
2635 return hpsb_iso_xmit_start(fi->iso_handle,
2638 case RAW1394_IOC_ISO_XMIT_SYNC:
2639 return hpsb_iso_xmit_sync(fi->iso_handle);
2640 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2641 hpsb_iso_stop(fi->iso_handle);
2643 case RAW1394_IOC_ISO_GET_STATUS:
2644 return raw1394_iso_get_status(fi, argp);
2645 case RAW1394_IOC_ISO_XMIT_PACKETS:
2646 return raw1394_iso_send_packets(fi, argp);
2647 case RAW1394_IOC_ISO_SHUTDOWN:
2648 raw1394_iso_shutdown(fi);
2650 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2651 queue_rawiso_event(fi);
2658 /* ioctl is only used for rawiso operations */
2659 static long raw1394_ioctl(struct file *file, unsigned int cmd,
2662 struct file_info *fi = file->private_data;
2663 void __user *argp = (void __user *)arg;
2666 /* state-independent commands */
2668 case RAW1394_IOC_GET_CYCLE_TIMER:
2669 return raw1394_read_cycle_timer(fi, argp);
2674 if (!mutex_trylock(&fi->state_mutex))
2677 switch (fi->iso_state) {
2678 case RAW1394_ISO_INACTIVE:
2679 ret = raw1394_ioctl_inactive(fi, cmd, argp);
2681 case RAW1394_ISO_RECV:
2682 ret = raw1394_ioctl_recv(fi, cmd, arg);
2684 case RAW1394_ISO_XMIT:
2685 ret = raw1394_ioctl_xmit(fi, cmd, argp);
2692 mutex_unlock(&fi->state_mutex);
2697 #ifdef CONFIG_COMPAT
2698 struct raw1394_iso_packets32 {
2700 compat_uptr_t infos;
2701 } __attribute__((packed));
2703 struct raw1394_cycle_timer32 {
2707 #if defined(CONFIG_X86_64) || defined(CONFIG_IA64)
2708 __attribute__((packed))
2712 #define RAW1394_IOC_ISO_RECV_PACKETS32 \
2713 _IOW ('#', 0x25, struct raw1394_iso_packets32)
2714 #define RAW1394_IOC_ISO_XMIT_PACKETS32 \
2715 _IOW ('#', 0x27, struct raw1394_iso_packets32)
2716 #define RAW1394_IOC_GET_CYCLE_TIMER32 \
2717 _IOR ('#', 0x30, struct raw1394_cycle_timer32)
2719 static long raw1394_iso_xmit_recv_packets32(struct file *file, unsigned int cmd,
2720 struct raw1394_iso_packets32 __user *arg)
2722 compat_uptr_t infos32;
2725 struct raw1394_iso_packets __user *dst = compat_alloc_user_space(sizeof(struct raw1394_iso_packets));
2727 if (!copy_in_user(&dst->n_packets, &arg->n_packets, sizeof arg->n_packets) &&
2728 !copy_from_user(&infos32, &arg->infos, sizeof infos32)) {
2729 infos = compat_ptr(infos32);
2730 if (!copy_to_user(&dst->infos, &infos, sizeof infos))
2731 err = raw1394_ioctl(file, cmd, (unsigned long)dst);
2736 static long raw1394_read_cycle_timer32(struct file_info *fi, void __user * uaddr)
2738 struct raw1394_cycle_timer32 ct;
2741 err = hpsb_read_cycle_timer(fi->host, &ct.cycle_timer, &ct.local_time);
2743 if (copy_to_user(uaddr, &ct, sizeof(ct)))
2748 static long raw1394_compat_ioctl(struct file *file,
2749 unsigned int cmd, unsigned long arg)
2751 struct file_info *fi = file->private_data;
2752 void __user *argp = (void __user *)arg;
2756 /* These requests have same format as long as 'int' has same size. */
2757 case RAW1394_IOC_ISO_RECV_INIT:
2758 case RAW1394_IOC_ISO_RECV_START:
2759 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL:
2760 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
2761 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:
2762 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
2763 case RAW1394_IOC_ISO_RECV_FLUSH:
2764 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2765 case RAW1394_IOC_ISO_XMIT_INIT:
2766 case RAW1394_IOC_ISO_XMIT_START:
2767 case RAW1394_IOC_ISO_XMIT_SYNC:
2768 case RAW1394_IOC_ISO_GET_STATUS:
2769 case RAW1394_IOC_ISO_SHUTDOWN:
2770 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2771 err = raw1394_ioctl(file, cmd, arg);
2773 /* These request have different format. */
2774 case RAW1394_IOC_ISO_RECV_PACKETS32:
2775 err = raw1394_iso_xmit_recv_packets32(file, RAW1394_IOC_ISO_RECV_PACKETS, argp);
2777 case RAW1394_IOC_ISO_XMIT_PACKETS32:
2778 err = raw1394_iso_xmit_recv_packets32(file, RAW1394_IOC_ISO_XMIT_PACKETS, argp);
2780 case RAW1394_IOC_GET_CYCLE_TIMER32:
2781 err = raw1394_read_cycle_timer32(fi, argp);
2792 static unsigned int raw1394_poll(struct file *file, poll_table * pt)
2794 struct file_info *fi = file->private_data;
2795 unsigned int mask = POLLOUT | POLLWRNORM;
2796 unsigned long flags;
2798 poll_wait(file, &fi->wait_complete, pt);
2800 spin_lock_irqsave(&fi->reqlists_lock, flags);
2801 if (!list_empty(&fi->req_complete)) {
2802 mask |= POLLIN | POLLRDNORM;
2804 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2809 static int raw1394_open(struct inode *inode, struct file *file)
2811 struct file_info *fi;
2813 fi = kzalloc(sizeof(*fi), GFP_KERNEL);
2817 fi->notification = (u8) RAW1394_NOTIFY_ON; /* busreset notification */
2819 INIT_LIST_HEAD(&fi->list);
2820 mutex_init(&fi->state_mutex);
2822 INIT_LIST_HEAD(&fi->req_pending);
2823 INIT_LIST_HEAD(&fi->req_complete);
2824 spin_lock_init(&fi->reqlists_lock);
2825 init_waitqueue_head(&fi->wait_complete);
2826 INIT_LIST_HEAD(&fi->addr_list);
2828 file->private_data = fi;
2833 static int raw1394_release(struct inode *inode, struct file *file)
2835 struct file_info *fi = file->private_data;
2836 struct list_head *lh;
2837 struct pending_request *req;
2840 struct list_head *entry;
2841 struct arm_addr *addr = NULL;
2842 struct host_info *hi;
2843 struct file_info *fi_hlp = NULL;
2844 struct arm_addr *arm_addr = NULL;
2847 unsigned long flags;
2849 if (fi->iso_state != RAW1394_ISO_INACTIVE)
2850 raw1394_iso_shutdown(fi);
2852 spin_lock_irqsave(&host_info_lock, flags);
2855 /* set address-entries invalid */
2857 while (!list_empty(&fi->addr_list)) {
2859 lh = fi->addr_list.next;
2860 addr = list_entry(lh, struct arm_addr, addr_list);
2861 /* another host with valid address-entry containing
2862 same addressrange? */
2863 list_for_each_entry(hi, &host_info_list, list) {
2864 if (hi->host != fi->host) {
2865 list_for_each_entry(fi_hlp, &hi->file_info_list,
2867 entry = fi_hlp->addr_list.next;
2868 while (entry != &(fi_hlp->addr_list)) {
2869 arm_addr = list_entry(entry, struct
2872 if (arm_addr->start ==
2875 ("raw1394_release: "
2876 "another host ownes "
2877 "same addressrange");
2881 entry = entry->next;
2889 if (!another_host) {
2890 DBGMSG("raw1394_release: call hpsb_arm_unregister");
2892 hpsb_unregister_addrspace(&raw1394_highlevel,
2893 fi->host, addr->start);
2897 "raw1394_release arm_Unregister failed\n");
2900 DBGMSG("raw1394_release: delete addr_entry from list");
2901 list_del(&addr->addr_list);
2902 vfree(addr->addr_space_buffer);
2905 spin_unlock_irqrestore(&host_info_lock, flags);
2907 printk(KERN_ERR "raw1394: during addr_list-release "
2908 "error(s) occurred \n");
2912 /* This locked section guarantees that neither
2913 * complete nor pending requests exist once i!=0 */
2914 spin_lock_irqsave(&fi->reqlists_lock, flags);
2915 while ((req = __next_complete_req(fi)))
2916 free_pending_request(req);
2918 i = list_empty(&fi->req_pending);
2919 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2924 * Sleep until more requests can be freed.
2926 * NB: We call the macro wait_event() with a condition argument
2927 * with side effect. This is only possible because the side
2928 * effect does not occur until the condition became true, and
2929 * wait_event() won't evaluate the condition again after that.
2931 wait_event(fi->wait_complete, (req = next_complete_req(fi)));
2932 free_pending_request(req);
2935 /* Remove any sub-trees left by user space programs */
2936 for (i = 0; i < RAW1394_MAX_USER_CSR_DIRS; i++) {
2937 struct csr1212_dentry *dentry;
2938 if (!fi->csr1212_dirs[i])
2941 fi->csr1212_dirs[i]->value.directory.dentries_head; dentry;
2942 dentry = dentry->next) {
2943 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2947 csr1212_release_keyval(fi->csr1212_dirs[i]);
2948 fi->csr1212_dirs[i] = NULL;
2952 if ((csr_mod || fi->cfgrom_upd)
2953 && hpsb_update_config_rom_image(fi->host) < 0)
2955 ("Failed to generate Configuration ROM image for host %d",
2958 if (fi->state == connected) {
2959 spin_lock_irqsave(&host_info_lock, flags);
2960 list_del(&fi->list);
2961 spin_unlock_irqrestore(&host_info_lock, flags);
2963 put_device(&fi->host->device);
2966 spin_lock_irqsave(&host_info_lock, flags);
2968 module_put(fi->host->driver->owner);
2969 spin_unlock_irqrestore(&host_info_lock, flags);
2976 /*** HOTPLUG STUFF **********************************************************/
2978 * Export information about protocols/devices supported by this driver.
2981 static struct ieee1394_device_id raw1394_id_table[] = {
2983 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2984 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
2985 .version = AVC_SW_VERSION_ENTRY & 0xffffff},
2987 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2988 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2989 .version = CAMERA_SW_VERSION_ENTRY & 0xffffff},
2991 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2992 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2993 .version = (CAMERA_SW_VERSION_ENTRY + 1) & 0xffffff},
2995 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2996 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2997 .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff},
3001 MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table);
3004 static struct hpsb_protocol_driver raw1394_driver = {
3008 /******************************************************************************/
3010 static struct hpsb_highlevel raw1394_highlevel = {
3011 .name = RAW1394_DEVICE_NAME,
3012 .add_host = add_host,
3013 .remove_host = remove_host,
3014 .host_reset = host_reset,
3015 .fcp_request = fcp_request,
3018 static struct cdev raw1394_cdev;
3019 static const struct file_operations raw1394_fops = {
3020 .owner = THIS_MODULE,
3021 .read = raw1394_read,
3022 .write = raw1394_write,
3023 .mmap = raw1394_mmap,
3024 .unlocked_ioctl = raw1394_ioctl,
3025 #ifdef CONFIG_COMPAT
3026 .compat_ioctl = raw1394_compat_ioctl,
3028 .poll = raw1394_poll,
3029 .open = raw1394_open,
3030 .release = raw1394_release,
3033 static int __init init_raw1394(void)
3037 hpsb_register_highlevel(&raw1394_highlevel);
3040 (device_create(hpsb_protocol_class, NULL,
3041 MKDEV(IEEE1394_MAJOR,
3042 IEEE1394_MINOR_BLOCK_RAW1394 * 16),
3043 NULL, RAW1394_DEVICE_NAME))) {
3048 cdev_init(&raw1394_cdev, &raw1394_fops);
3049 raw1394_cdev.owner = THIS_MODULE;
3050 ret = cdev_add(&raw1394_cdev, IEEE1394_RAW1394_DEV, 1);
3052 HPSB_ERR("raw1394 failed to register minor device block");
3056 HPSB_INFO("raw1394: /dev/%s device initialized", RAW1394_DEVICE_NAME);
3058 ret = hpsb_register_protocol(&raw1394_driver);
3060 HPSB_ERR("raw1394: failed to register protocol");
3061 cdev_del(&raw1394_cdev);
3068 device_destroy(hpsb_protocol_class,
3069 MKDEV(IEEE1394_MAJOR,
3070 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
3072 hpsb_unregister_highlevel(&raw1394_highlevel);
3077 static void __exit cleanup_raw1394(void)
3079 device_destroy(hpsb_protocol_class,
3080 MKDEV(IEEE1394_MAJOR,
3081 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
3082 cdev_del(&raw1394_cdev);
3083 hpsb_unregister_highlevel(&raw1394_highlevel);
3084 hpsb_unregister_protocol(&raw1394_driver);
3087 module_init(init_raw1394);
3088 module_exit(cleanup_raw1394);
3089 MODULE_LICENSE("GPL");