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 const 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;
373 r = compat_alloc_user_space(sizeof(struct raw1394_request));
375 #define C(x) __copy_in_user(&r->x, &cr->x, sizeof(r->x))
377 if (copy_in_user(r, cr, sizeof(struct compat_raw1394_req)) ||
382 return (__force const char __user *)ERR_PTR(-EFAULT);
384 return (const char __user *)r;
388 #define P(x) __put_user(r->x, &cr->x)
391 raw1394_compat_read(const char __user *buf, struct raw1394_request *r)
393 struct compat_raw1394_req __user *cr = (typeof(cr)) buf;
395 if (!access_ok(VERIFY_WRITE, cr, sizeof(struct compat_raw1394_req)) ||
407 return sizeof(struct compat_raw1394_req);
413 /* get next completed request (caller must hold fi->reqlists_lock) */
414 static inline struct pending_request *__next_complete_req(struct file_info *fi)
416 struct list_head *lh;
417 struct pending_request *req = NULL;
419 if (!list_empty(&fi->req_complete)) {
420 lh = fi->req_complete.next;
422 req = list_entry(lh, struct pending_request, list);
427 /* atomically get next completed request */
428 static struct pending_request *next_complete_req(struct file_info *fi)
431 struct pending_request *req;
433 spin_lock_irqsave(&fi->reqlists_lock, flags);
434 req = __next_complete_req(fi);
435 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
439 static ssize_t raw1394_read(struct file *file, char __user * buffer,
440 size_t count, loff_t * offset_is_ignored)
442 struct file_info *fi = (struct file_info *)file->private_data;
443 struct pending_request *req;
447 if (count == sizeof(struct compat_raw1394_req)) {
451 if (count != sizeof(struct raw1394_request)) {
455 if (!access_ok(VERIFY_WRITE, buffer, count)) {
459 if (file->f_flags & O_NONBLOCK) {
460 if (!(req = next_complete_req(fi)))
464 * NB: We call the macro wait_event_interruptible() with a
465 * condition argument with side effect. This is only possible
466 * because the side effect does not occur until the condition
467 * became true, and wait_event_interruptible() won't evaluate
468 * the condition again after that.
470 if (wait_event_interruptible(fi->wait_complete,
471 (req = next_complete_req(fi))))
475 if (req->req.length) {
476 if (copy_to_user(int2ptr(req->req.recvb), req->data,
478 req->req.error = RAW1394_ERROR_MEMFAULT;
483 if (count == sizeof(struct compat_raw1394_req) &&
484 sizeof(struct compat_raw1394_req) !=
485 sizeof(struct raw1394_request)) {
486 ret = raw1394_compat_read(buffer, &req->req);
490 if (copy_to_user(buffer, &req->req, sizeof(req->req))) {
494 ret = (ssize_t) sizeof(struct raw1394_request);
497 free_pending_request(req);
501 static int state_opened(struct file_info *fi, struct pending_request *req)
503 if (req->req.type == RAW1394_REQ_INITIALIZE) {
504 switch (req->req.misc) {
505 case RAW1394_KERNELAPI_VERSION:
507 fi->state = initialized;
508 fi->protocol_version = req->req.misc;
509 req->req.error = RAW1394_ERROR_NONE;
510 req->req.generation = atomic_read(&internal_generation);
514 req->req.error = RAW1394_ERROR_COMPAT;
515 req->req.misc = RAW1394_KERNELAPI_VERSION;
518 req->req.error = RAW1394_ERROR_STATE_ORDER;
522 queue_complete_req(req);
526 static int state_initialized(struct file_info *fi, struct pending_request *req)
529 struct host_info *hi;
530 struct raw1394_khost_list *khl;
532 if (req->req.generation != atomic_read(&internal_generation)) {
533 req->req.error = RAW1394_ERROR_GENERATION;
534 req->req.generation = atomic_read(&internal_generation);
536 queue_complete_req(req);
540 switch (req->req.type) {
541 case RAW1394_REQ_LIST_CARDS:
542 spin_lock_irqsave(&host_info_lock, flags);
543 khl = kmalloc(sizeof(*khl) * host_count, GFP_ATOMIC);
546 req->req.misc = host_count;
547 req->data = (quadlet_t *) khl;
549 list_for_each_entry(hi, &host_info_list, list) {
550 khl->nodes = hi->host->node_count;
551 strcpy(khl->name, hi->host->driver->name);
555 spin_unlock_irqrestore(&host_info_lock, flags);
558 req->req.error = RAW1394_ERROR_NONE;
559 req->req.length = min(req->req.length,
561 (struct raw1394_khost_list)
569 case RAW1394_REQ_SET_CARD:
570 spin_lock_irqsave(&host_info_lock, flags);
571 if (req->req.misc >= host_count) {
572 req->req.error = RAW1394_ERROR_INVALID_ARG;
575 list_for_each_entry(hi, &host_info_list, list)
576 if (!req->req.misc--)
578 get_device(&hi->host->device); /* FIXME handle failure case */
579 list_add_tail(&fi->list, &hi->file_info_list);
581 /* prevent unloading of the host's low-level driver */
582 if (!try_module_get(hi->host->driver->owner)) {
583 req->req.error = RAW1394_ERROR_ABORTED;
588 fi->state = connected;
590 req->req.error = RAW1394_ERROR_NONE;
591 req->req.generation = get_hpsb_generation(fi->host);
592 req->req.misc = (fi->host->node_id << 16)
593 | fi->host->node_count;
594 if (fi->protocol_version > 3)
595 req->req.misc |= NODEID_TO_NODE(fi->host->irm_id) << 8;
597 spin_unlock_irqrestore(&host_info_lock, flags);
603 req->req.error = RAW1394_ERROR_STATE_ORDER;
608 queue_complete_req(req);
612 static void handle_fcp_listen(struct file_info *fi, struct pending_request *req)
615 if (fi->fcp_buffer) {
616 req->req.error = RAW1394_ERROR_ALREADY;
618 fi->fcp_buffer = int2ptr(req->req.recvb);
621 if (!fi->fcp_buffer) {
622 req->req.error = RAW1394_ERROR_ALREADY;
624 fi->fcp_buffer = NULL;
629 queue_complete_req(req);
632 static int handle_async_request(struct file_info *fi,
633 struct pending_request *req, int node)
636 struct hpsb_packet *packet = NULL;
637 u64 addr = req->req.address & 0xffffffffffffULL;
639 switch (req->req.type) {
640 case RAW1394_REQ_ASYNC_READ:
641 DBGMSG("read_request called");
643 hpsb_make_readpacket(fi->host, node, addr, req->req.length);
648 if (req->req.length == 4)
649 req->data = &packet->header[3];
651 req->data = packet->data;
655 case RAW1394_REQ_ASYNC_WRITE:
656 DBGMSG("write_request called");
658 packet = hpsb_make_writepacket(fi->host, node, addr, NULL,
663 if (req->req.length == 4) {
665 (&packet->header[3], int2ptr(req->req.sendb),
667 req->req.error = RAW1394_ERROR_MEMFAULT;
670 (packet->data, int2ptr(req->req.sendb),
672 req->req.error = RAW1394_ERROR_MEMFAULT;
678 case RAW1394_REQ_ASYNC_STREAM:
679 DBGMSG("stream_request called");
682 hpsb_make_streampacket(fi->host, NULL, req->req.length,
683 node & 0x3f /*channel */ ,
684 (req->req.misc >> 16) & 0x3,
685 req->req.misc & 0xf);
689 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
691 req->req.error = RAW1394_ERROR_MEMFAULT;
696 case RAW1394_REQ_LOCK:
697 DBGMSG("lock_request called");
698 if ((req->req.misc == EXTCODE_FETCH_ADD)
699 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
700 if (req->req.length != 4) {
701 req->req.error = RAW1394_ERROR_INVALID_ARG;
705 if (req->req.length != 8) {
706 req->req.error = RAW1394_ERROR_INVALID_ARG;
711 packet = hpsb_make_lockpacket(fi->host, node, addr,
712 req->req.misc, NULL, 0);
716 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
718 req->req.error = RAW1394_ERROR_MEMFAULT;
722 req->data = packet->data;
726 case RAW1394_REQ_LOCK64:
727 DBGMSG("lock64_request called");
728 if ((req->req.misc == EXTCODE_FETCH_ADD)
729 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
730 if (req->req.length != 8) {
731 req->req.error = RAW1394_ERROR_INVALID_ARG;
735 if (req->req.length != 16) {
736 req->req.error = RAW1394_ERROR_INVALID_ARG;
740 packet = hpsb_make_lock64packet(fi->host, node, addr,
741 req->req.misc, NULL, 0);
745 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
747 req->req.error = RAW1394_ERROR_MEMFAULT;
751 req->data = packet->data;
756 req->req.error = RAW1394_ERROR_STATE_ORDER;
759 req->packet = packet;
761 if (req->req.error) {
763 queue_complete_req(req);
767 hpsb_set_packet_complete_task(packet,
768 (void (*)(void *))queue_complete_cb, req);
770 spin_lock_irqsave(&fi->reqlists_lock, flags);
771 list_add_tail(&req->list, &fi->req_pending);
772 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
774 packet->generation = req->req.generation;
776 if (hpsb_send_packet(packet) < 0) {
777 req->req.error = RAW1394_ERROR_SEND_ERROR;
779 hpsb_free_tlabel(packet);
780 queue_complete_req(req);
785 static int handle_async_send(struct file_info *fi, struct pending_request *req)
788 struct hpsb_packet *packet;
789 int header_length = req->req.misc & 0xffff;
790 int expect_response = req->req.misc >> 16;
793 if (header_length > req->req.length || header_length < 12 ||
794 header_length > FIELD_SIZEOF(struct hpsb_packet, header)) {
795 req->req.error = RAW1394_ERROR_INVALID_ARG;
797 queue_complete_req(req);
801 data_size = req->req.length - header_length;
802 packet = hpsb_alloc_packet(data_size);
803 req->packet = packet;
807 if (copy_from_user(packet->header, int2ptr(req->req.sendb),
809 req->req.error = RAW1394_ERROR_MEMFAULT;
811 queue_complete_req(req);
816 (packet->data, int2ptr(req->req.sendb) + header_length,
818 req->req.error = RAW1394_ERROR_MEMFAULT;
820 queue_complete_req(req);
824 packet->type = hpsb_async;
825 packet->node_id = packet->header[0] >> 16;
826 packet->tcode = (packet->header[0] >> 4) & 0xf;
827 packet->tlabel = (packet->header[0] >> 10) & 0x3f;
828 packet->host = fi->host;
829 packet->expect_response = expect_response;
830 packet->header_size = header_length;
831 packet->data_size = data_size;
834 hpsb_set_packet_complete_task(packet,
835 (void (*)(void *))queue_complete_cb, req);
837 spin_lock_irqsave(&fi->reqlists_lock, flags);
838 list_add_tail(&req->list, &fi->req_pending);
839 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
841 /* Update the generation of the packet just before sending. */
842 packet->generation = req->req.generation;
844 if (hpsb_send_packet(packet) < 0) {
845 req->req.error = RAW1394_ERROR_SEND_ERROR;
846 queue_complete_req(req);
852 static int arm_read(struct hpsb_host *host, int nodeid, quadlet_t * buffer,
853 u64 addr, size_t length, u16 flags)
855 unsigned long irqflags;
856 struct pending_request *req;
857 struct host_info *hi;
858 struct file_info *fi = NULL;
859 struct list_head *entry;
860 struct arm_addr *arm_addr = NULL;
861 struct arm_request *arm_req = NULL;
862 struct arm_response *arm_resp = NULL;
863 int found = 0, size = 0, rcode = -1;
864 struct arm_request_response *arm_req_resp = NULL;
866 DBGMSG("arm_read called by node: %X "
867 "addr: %4.4x %8.8x length: %Zu", nodeid,
868 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
870 spin_lock_irqsave(&host_info_lock, irqflags);
871 hi = find_host_info(host); /* search address-entry */
873 list_for_each_entry(fi, &hi->file_info_list, list) {
874 entry = fi->addr_list.next;
875 while (entry != &(fi->addr_list)) {
877 list_entry(entry, struct arm_addr,
879 if (((arm_addr->start) <= (addr))
880 && ((arm_addr->end) >= (addr + length))) {
893 printk(KERN_ERR "raw1394: arm_read FAILED addr_entry not found"
894 " -> rcode_address_error\n");
895 spin_unlock_irqrestore(&host_info_lock, irqflags);
896 return (RCODE_ADDRESS_ERROR);
898 DBGMSG("arm_read addr_entry FOUND");
900 if (arm_addr->rec_length < length) {
901 DBGMSG("arm_read blocklength too big -> rcode_data_error");
902 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
905 if (arm_addr->access_rights & ARM_READ) {
906 if (!(arm_addr->client_transactions & ARM_READ)) {
908 (arm_addr->addr_space_buffer) + (addr -
912 DBGMSG("arm_read -> (rcode_complete)");
913 rcode = RCODE_COMPLETE;
916 rcode = RCODE_TYPE_ERROR; /* function not allowed */
917 DBGMSG("arm_read -> rcode_type_error (access denied)");
920 if (arm_addr->notification_options & ARM_READ) {
921 DBGMSG("arm_read -> entering notification-section");
922 req = __alloc_pending_request(GFP_ATOMIC);
924 DBGMSG("arm_read -> rcode_conflict_error");
925 spin_unlock_irqrestore(&host_info_lock, irqflags);
926 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
927 The request may be retried */
929 if (rcode == RCODE_COMPLETE) {
931 sizeof(struct arm_request) +
932 sizeof(struct arm_response) +
933 length * sizeof(byte_t) +
934 sizeof(struct arm_request_response);
937 sizeof(struct arm_request) +
938 sizeof(struct arm_response) +
939 sizeof(struct arm_request_response);
941 req->data = kmalloc(size, GFP_ATOMIC);
943 free_pending_request(req);
944 DBGMSG("arm_read -> rcode_conflict_error");
945 spin_unlock_irqrestore(&host_info_lock, irqflags);
946 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
947 The request may be retried */
951 req->req.type = RAW1394_REQ_ARM;
952 req->req.generation = get_hpsb_generation(host);
954 (((length << 16) & (0xFFFF0000)) | (ARM_READ & 0xFF));
955 req->req.tag = arm_addr->arm_tag;
956 req->req.recvb = arm_addr->recvb;
957 req->req.length = size;
958 arm_req_resp = (struct arm_request_response *)(req->data);
959 arm_req = (struct arm_request *)((byte_t *) (req->data) +
962 arm_request_response)));
964 (struct arm_response *)((byte_t *) (arm_req) +
965 (sizeof(struct arm_request)));
966 arm_req->buffer = NULL;
967 arm_resp->buffer = NULL;
968 if (rcode == RCODE_COMPLETE) {
970 (byte_t *) arm_resp + sizeof(struct arm_response);
972 (arm_addr->addr_space_buffer) + (addr -
977 int2ptr((arm_addr->recvb) +
978 sizeof(struct arm_request_response) +
979 sizeof(struct arm_request) +
980 sizeof(struct arm_response));
982 arm_resp->buffer_length =
983 (rcode == RCODE_COMPLETE) ? length : 0;
984 arm_resp->response_code = rcode;
985 arm_req->buffer_length = 0;
986 arm_req->generation = req->req.generation;
987 arm_req->extended_transaction_code = 0;
988 arm_req->destination_offset = addr;
989 arm_req->source_nodeid = nodeid;
990 arm_req->destination_nodeid = host->node_id;
991 arm_req->tlabel = (flags >> 10) & 0x3f;
992 arm_req->tcode = (flags >> 4) & 0x0f;
993 arm_req_resp->request = int2ptr((arm_addr->recvb) +
995 arm_request_response));
996 arm_req_resp->response =
997 int2ptr((arm_addr->recvb) +
998 sizeof(struct arm_request_response) +
999 sizeof(struct arm_request));
1000 queue_complete_req(req);
1002 spin_unlock_irqrestore(&host_info_lock, irqflags);
1006 static int arm_write(struct hpsb_host *host, int nodeid, int destid,
1007 quadlet_t * data, u64 addr, size_t length, u16 flags)
1009 unsigned long irqflags;
1010 struct pending_request *req;
1011 struct host_info *hi;
1012 struct file_info *fi = NULL;
1013 struct list_head *entry;
1014 struct arm_addr *arm_addr = NULL;
1015 struct arm_request *arm_req = NULL;
1016 struct arm_response *arm_resp = NULL;
1017 int found = 0, size = 0, rcode = -1, length_conflict = 0;
1018 struct arm_request_response *arm_req_resp = NULL;
1020 DBGMSG("arm_write called by node: %X "
1021 "addr: %4.4x %8.8x length: %Zu", nodeid,
1022 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
1024 spin_lock_irqsave(&host_info_lock, irqflags);
1025 hi = find_host_info(host); /* search address-entry */
1027 list_for_each_entry(fi, &hi->file_info_list, list) {
1028 entry = fi->addr_list.next;
1029 while (entry != &(fi->addr_list)) {
1031 list_entry(entry, struct arm_addr,
1033 if (((arm_addr->start) <= (addr))
1034 && ((arm_addr->end) >= (addr + length))) {
1038 entry = entry->next;
1047 printk(KERN_ERR "raw1394: arm_write FAILED addr_entry not found"
1048 " -> rcode_address_error\n");
1049 spin_unlock_irqrestore(&host_info_lock, irqflags);
1050 return (RCODE_ADDRESS_ERROR);
1052 DBGMSG("arm_write addr_entry FOUND");
1054 if (arm_addr->rec_length < length) {
1055 DBGMSG("arm_write blocklength too big -> rcode_data_error");
1056 length_conflict = 1;
1057 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
1060 if (arm_addr->access_rights & ARM_WRITE) {
1061 if (!(arm_addr->client_transactions & ARM_WRITE)) {
1062 memcpy((arm_addr->addr_space_buffer) +
1063 (addr - (arm_addr->start)), data,
1065 DBGMSG("arm_write -> (rcode_complete)");
1066 rcode = RCODE_COMPLETE;
1069 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1070 DBGMSG("arm_write -> rcode_type_error (access denied)");
1073 if (arm_addr->notification_options & ARM_WRITE) {
1074 DBGMSG("arm_write -> entering notification-section");
1075 req = __alloc_pending_request(GFP_ATOMIC);
1077 DBGMSG("arm_write -> rcode_conflict_error");
1078 spin_unlock_irqrestore(&host_info_lock, irqflags);
1079 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1080 The request my be retried */
1083 sizeof(struct arm_request) + sizeof(struct arm_response) +
1084 (length) * sizeof(byte_t) +
1085 sizeof(struct arm_request_response);
1086 req->data = kmalloc(size, GFP_ATOMIC);
1088 free_pending_request(req);
1089 DBGMSG("arm_write -> rcode_conflict_error");
1090 spin_unlock_irqrestore(&host_info_lock, irqflags);
1091 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1092 The request may be retried */
1095 req->file_info = fi;
1096 req->req.type = RAW1394_REQ_ARM;
1097 req->req.generation = get_hpsb_generation(host);
1099 (((length << 16) & (0xFFFF0000)) | (ARM_WRITE & 0xFF));
1100 req->req.tag = arm_addr->arm_tag;
1101 req->req.recvb = arm_addr->recvb;
1102 req->req.length = size;
1103 arm_req_resp = (struct arm_request_response *)(req->data);
1104 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1107 arm_request_response)));
1109 (struct arm_response *)((byte_t *) (arm_req) +
1110 (sizeof(struct arm_request)));
1111 arm_resp->buffer = NULL;
1112 memcpy((byte_t *) arm_resp + sizeof(struct arm_response),
1114 arm_req->buffer = int2ptr((arm_addr->recvb) +
1115 sizeof(struct arm_request_response) +
1116 sizeof(struct arm_request) +
1117 sizeof(struct arm_response));
1118 arm_req->buffer_length = length;
1119 arm_req->generation = req->req.generation;
1120 arm_req->extended_transaction_code = 0;
1121 arm_req->destination_offset = addr;
1122 arm_req->source_nodeid = nodeid;
1123 arm_req->destination_nodeid = destid;
1124 arm_req->tlabel = (flags >> 10) & 0x3f;
1125 arm_req->tcode = (flags >> 4) & 0x0f;
1126 arm_resp->buffer_length = 0;
1127 arm_resp->response_code = rcode;
1128 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1130 arm_request_response));
1131 arm_req_resp->response =
1132 int2ptr((arm_addr->recvb) +
1133 sizeof(struct arm_request_response) +
1134 sizeof(struct arm_request));
1135 queue_complete_req(req);
1137 spin_unlock_irqrestore(&host_info_lock, irqflags);
1141 static int arm_lock(struct hpsb_host *host, int nodeid, quadlet_t * store,
1142 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
1145 unsigned long irqflags;
1146 struct pending_request *req;
1147 struct host_info *hi;
1148 struct file_info *fi = NULL;
1149 struct list_head *entry;
1150 struct arm_addr *arm_addr = NULL;
1151 struct arm_request *arm_req = NULL;
1152 struct arm_response *arm_resp = NULL;
1153 int found = 0, size = 0, rcode = -1;
1155 struct arm_request_response *arm_req_resp = NULL;
1157 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1158 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1159 DBGMSG("arm_lock called by node: %X "
1160 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X",
1161 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1162 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1165 DBGMSG("arm_lock called by node: %X "
1166 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X arg: %8.8X",
1167 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1168 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1169 be32_to_cpu(data), be32_to_cpu(arg));
1171 spin_lock_irqsave(&host_info_lock, irqflags);
1172 hi = find_host_info(host); /* search address-entry */
1174 list_for_each_entry(fi, &hi->file_info_list, list) {
1175 entry = fi->addr_list.next;
1176 while (entry != &(fi->addr_list)) {
1178 list_entry(entry, struct arm_addr,
1180 if (((arm_addr->start) <= (addr))
1181 && ((arm_addr->end) >=
1182 (addr + sizeof(*store)))) {
1186 entry = entry->next;
1195 printk(KERN_ERR "raw1394: arm_lock FAILED addr_entry not found"
1196 " -> rcode_address_error\n");
1197 spin_unlock_irqrestore(&host_info_lock, irqflags);
1198 return (RCODE_ADDRESS_ERROR);
1200 DBGMSG("arm_lock addr_entry FOUND");
1203 if (arm_addr->access_rights & ARM_LOCK) {
1204 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1206 (arm_addr->addr_space_buffer) + (addr -
1210 switch (ext_tcode) {
1211 case (EXTCODE_MASK_SWAP):
1212 new = data | (old & ~arg);
1214 case (EXTCODE_COMPARE_SWAP):
1221 case (EXTCODE_FETCH_ADD):
1223 cpu_to_be32(be32_to_cpu(data) +
1226 case (EXTCODE_LITTLE_ADD):
1228 cpu_to_le32(le32_to_cpu(data) +
1231 case (EXTCODE_BOUNDED_ADD):
1234 cpu_to_be32(be32_to_cpu
1242 case (EXTCODE_WRAP_ADD):
1245 cpu_to_be32(be32_to_cpu
1254 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1256 "raw1394: arm_lock FAILED "
1257 "ext_tcode not allowed -> rcode_type_error\n");
1261 DBGMSG("arm_lock -> (rcode_complete)");
1262 rcode = RCODE_COMPLETE;
1263 memcpy(store, &old, sizeof(*store));
1264 memcpy((arm_addr->addr_space_buffer) +
1265 (addr - (arm_addr->start)),
1266 &new, sizeof(*store));
1270 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1271 DBGMSG("arm_lock -> rcode_type_error (access denied)");
1274 if (arm_addr->notification_options & ARM_LOCK) {
1275 byte_t *buf1, *buf2;
1276 DBGMSG("arm_lock -> entering notification-section");
1277 req = __alloc_pending_request(GFP_ATOMIC);
1279 DBGMSG("arm_lock -> rcode_conflict_error");
1280 spin_unlock_irqrestore(&host_info_lock, irqflags);
1281 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1282 The request may be retried */
1284 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1285 req->data = kmalloc(size, GFP_ATOMIC);
1287 free_pending_request(req);
1288 DBGMSG("arm_lock -> rcode_conflict_error");
1289 spin_unlock_irqrestore(&host_info_lock, irqflags);
1290 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1291 The request may be retried */
1294 arm_req_resp = (struct arm_request_response *)(req->data);
1295 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1298 arm_request_response)));
1300 (struct arm_response *)((byte_t *) (arm_req) +
1301 (sizeof(struct arm_request)));
1302 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1303 buf2 = buf1 + 2 * sizeof(*store);
1304 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1305 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1306 arm_req->buffer_length = sizeof(*store);
1307 memcpy(buf1, &data, sizeof(*store));
1310 arm_req->buffer_length = 2 * sizeof(*store);
1311 memcpy(buf1, &arg, sizeof(*store));
1312 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1314 if (rcode == RCODE_COMPLETE) {
1315 arm_resp->buffer_length = sizeof(*store);
1316 memcpy(buf2, &old, sizeof(*store));
1318 arm_resp->buffer_length = 0;
1320 req->file_info = fi;
1321 req->req.type = RAW1394_REQ_ARM;
1322 req->req.generation = get_hpsb_generation(host);
1323 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1325 req->req.tag = arm_addr->arm_tag;
1326 req->req.recvb = arm_addr->recvb;
1327 req->req.length = size;
1328 arm_req->generation = req->req.generation;
1329 arm_req->extended_transaction_code = ext_tcode;
1330 arm_req->destination_offset = addr;
1331 arm_req->source_nodeid = nodeid;
1332 arm_req->destination_nodeid = host->node_id;
1333 arm_req->tlabel = (flags >> 10) & 0x3f;
1334 arm_req->tcode = (flags >> 4) & 0x0f;
1335 arm_resp->response_code = rcode;
1336 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1338 arm_request_response));
1339 arm_req_resp->response =
1340 int2ptr((arm_addr->recvb) +
1341 sizeof(struct arm_request_response) +
1342 sizeof(struct arm_request));
1344 int2ptr((arm_addr->recvb) +
1345 sizeof(struct arm_request_response) +
1346 sizeof(struct arm_request) +
1347 sizeof(struct arm_response));
1349 int2ptr((arm_addr->recvb) +
1350 sizeof(struct arm_request_response) +
1351 sizeof(struct arm_request) +
1352 sizeof(struct arm_response) + 2 * sizeof(*store));
1353 queue_complete_req(req);
1355 spin_unlock_irqrestore(&host_info_lock, irqflags);
1359 static int arm_lock64(struct hpsb_host *host, int nodeid, octlet_t * store,
1360 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
1363 unsigned long irqflags;
1364 struct pending_request *req;
1365 struct host_info *hi;
1366 struct file_info *fi = NULL;
1367 struct list_head *entry;
1368 struct arm_addr *arm_addr = NULL;
1369 struct arm_request *arm_req = NULL;
1370 struct arm_response *arm_resp = NULL;
1371 int found = 0, size = 0, rcode = -1;
1373 struct arm_request_response *arm_req_resp = NULL;
1375 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1376 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1377 DBGMSG("arm_lock64 called by node: %X "
1378 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X ",
1379 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1380 (u32) (addr & 0xFFFFFFFF),
1382 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1383 (u32) (be64_to_cpu(data) & 0xFFFFFFFF));
1385 DBGMSG("arm_lock64 called by node: %X "
1386 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X arg: "
1388 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1389 (u32) (addr & 0xFFFFFFFF),
1391 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1392 (u32) (be64_to_cpu(data) & 0xFFFFFFFF),
1393 (u32) ((be64_to_cpu(arg) >> 32) & 0xFFFFFFFF),
1394 (u32) (be64_to_cpu(arg) & 0xFFFFFFFF));
1396 spin_lock_irqsave(&host_info_lock, irqflags);
1397 hi = find_host_info(host); /* search addressentry in file_info's for host */
1399 list_for_each_entry(fi, &hi->file_info_list, list) {
1400 entry = fi->addr_list.next;
1401 while (entry != &(fi->addr_list)) {
1403 list_entry(entry, struct arm_addr,
1405 if (((arm_addr->start) <= (addr))
1406 && ((arm_addr->end) >=
1407 (addr + sizeof(*store)))) {
1411 entry = entry->next;
1421 "raw1394: arm_lock64 FAILED addr_entry not found"
1422 " -> rcode_address_error\n");
1423 spin_unlock_irqrestore(&host_info_lock, irqflags);
1424 return (RCODE_ADDRESS_ERROR);
1426 DBGMSG("arm_lock64 addr_entry FOUND");
1429 if (arm_addr->access_rights & ARM_LOCK) {
1430 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1432 (arm_addr->addr_space_buffer) + (addr -
1436 switch (ext_tcode) {
1437 case (EXTCODE_MASK_SWAP):
1438 new = data | (old & ~arg);
1440 case (EXTCODE_COMPARE_SWAP):
1447 case (EXTCODE_FETCH_ADD):
1449 cpu_to_be64(be64_to_cpu(data) +
1452 case (EXTCODE_LITTLE_ADD):
1454 cpu_to_le64(le64_to_cpu(data) +
1457 case (EXTCODE_BOUNDED_ADD):
1460 cpu_to_be64(be64_to_cpu
1468 case (EXTCODE_WRAP_ADD):
1471 cpu_to_be64(be64_to_cpu
1481 "raw1394: arm_lock64 FAILED "
1482 "ext_tcode not allowed -> rcode_type_error\n");
1483 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1488 ("arm_lock64 -> (rcode_complete)");
1489 rcode = RCODE_COMPLETE;
1490 memcpy(store, &old, sizeof(*store));
1491 memcpy((arm_addr->addr_space_buffer) +
1492 (addr - (arm_addr->start)),
1493 &new, sizeof(*store));
1497 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1499 ("arm_lock64 -> rcode_type_error (access denied)");
1502 if (arm_addr->notification_options & ARM_LOCK) {
1503 byte_t *buf1, *buf2;
1504 DBGMSG("arm_lock64 -> entering notification-section");
1505 req = __alloc_pending_request(GFP_ATOMIC);
1507 spin_unlock_irqrestore(&host_info_lock, irqflags);
1508 DBGMSG("arm_lock64 -> rcode_conflict_error");
1509 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1510 The request may be retried */
1512 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1513 req->data = kmalloc(size, GFP_ATOMIC);
1515 free_pending_request(req);
1516 spin_unlock_irqrestore(&host_info_lock, irqflags);
1517 DBGMSG("arm_lock64 -> rcode_conflict_error");
1518 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1519 The request may be retried */
1522 arm_req_resp = (struct arm_request_response *)(req->data);
1523 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1526 arm_request_response)));
1528 (struct arm_response *)((byte_t *) (arm_req) +
1529 (sizeof(struct arm_request)));
1530 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1531 buf2 = buf1 + 2 * sizeof(*store);
1532 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1533 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1534 arm_req->buffer_length = sizeof(*store);
1535 memcpy(buf1, &data, sizeof(*store));
1538 arm_req->buffer_length = 2 * sizeof(*store);
1539 memcpy(buf1, &arg, sizeof(*store));
1540 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1542 if (rcode == RCODE_COMPLETE) {
1543 arm_resp->buffer_length = sizeof(*store);
1544 memcpy(buf2, &old, sizeof(*store));
1546 arm_resp->buffer_length = 0;
1548 req->file_info = fi;
1549 req->req.type = RAW1394_REQ_ARM;
1550 req->req.generation = get_hpsb_generation(host);
1551 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1553 req->req.tag = arm_addr->arm_tag;
1554 req->req.recvb = arm_addr->recvb;
1555 req->req.length = size;
1556 arm_req->generation = req->req.generation;
1557 arm_req->extended_transaction_code = ext_tcode;
1558 arm_req->destination_offset = addr;
1559 arm_req->source_nodeid = nodeid;
1560 arm_req->destination_nodeid = host->node_id;
1561 arm_req->tlabel = (flags >> 10) & 0x3f;
1562 arm_req->tcode = (flags >> 4) & 0x0f;
1563 arm_resp->response_code = rcode;
1564 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1566 arm_request_response));
1567 arm_req_resp->response =
1568 int2ptr((arm_addr->recvb) +
1569 sizeof(struct arm_request_response) +
1570 sizeof(struct arm_request));
1572 int2ptr((arm_addr->recvb) +
1573 sizeof(struct arm_request_response) +
1574 sizeof(struct arm_request) +
1575 sizeof(struct arm_response));
1577 int2ptr((arm_addr->recvb) +
1578 sizeof(struct arm_request_response) +
1579 sizeof(struct arm_request) +
1580 sizeof(struct arm_response) + 2 * sizeof(*store));
1581 queue_complete_req(req);
1583 spin_unlock_irqrestore(&host_info_lock, irqflags);
1587 static int arm_register(struct file_info *fi, struct pending_request *req)
1590 struct arm_addr *addr;
1591 struct host_info *hi;
1592 struct file_info *fi_hlp = NULL;
1593 struct list_head *entry;
1594 struct arm_addr *arm_addr = NULL;
1595 int same_host, another_host;
1596 unsigned long flags;
1598 DBGMSG("arm_register called "
1599 "addr(Offset): %8.8x %8.8x length: %u "
1600 "rights: %2.2X notify: %2.2X "
1601 "max_blk_len: %4.4X",
1602 (u32) ((req->req.address >> 32) & 0xFFFF),
1603 (u32) (req->req.address & 0xFFFFFFFF),
1604 req->req.length, ((req->req.misc >> 8) & 0xFF),
1605 (req->req.misc & 0xFF), ((req->req.misc >> 16) & 0xFFFF));
1606 /* check addressrange */
1607 if ((((req->req.address) & ~(0xFFFFFFFFFFFFULL)) != 0) ||
1608 (((req->req.address + req->req.length) & ~(0xFFFFFFFFFFFFULL)) !=
1610 req->req.length = 0;
1613 /* addr-list-entry for fileinfo */
1614 addr = kmalloc(sizeof(*addr), GFP_KERNEL);
1616 req->req.length = 0;
1619 /* allocation of addr_space_buffer */
1620 addr->addr_space_buffer = vmalloc(req->req.length);
1621 if (!(addr->addr_space_buffer)) {
1623 req->req.length = 0;
1626 /* initialization of addr_space_buffer */
1627 if ((req->req.sendb) == (unsigned long)NULL) {
1629 memset(addr->addr_space_buffer, 0, req->req.length);
1631 /* init: user -> kernel */
1633 (addr->addr_space_buffer, int2ptr(req->req.sendb),
1635 vfree(addr->addr_space_buffer);
1640 INIT_LIST_HEAD(&addr->addr_list);
1641 addr->arm_tag = req->req.tag;
1642 addr->start = req->req.address;
1643 addr->end = req->req.address + req->req.length;
1644 addr->access_rights = (u8) (req->req.misc & 0x0F);
1645 addr->notification_options = (u8) ((req->req.misc >> 4) & 0x0F);
1646 addr->client_transactions = (u8) ((req->req.misc >> 8) & 0x0F);
1647 addr->access_rights |= addr->client_transactions;
1648 addr->notification_options |= addr->client_transactions;
1649 addr->recvb = req->req.recvb;
1650 addr->rec_length = (u16) ((req->req.misc >> 16) & 0xFFFF);
1652 spin_lock_irqsave(&host_info_lock, flags);
1653 hi = find_host_info(fi->host);
1656 /* same host with address-entry containing same addressrange ? */
1657 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1658 entry = fi_hlp->addr_list.next;
1659 while (entry != &(fi_hlp->addr_list)) {
1661 list_entry(entry, struct arm_addr, addr_list);
1662 if ((arm_addr->start == addr->start)
1663 && (arm_addr->end == addr->end)) {
1664 DBGMSG("same host ownes same "
1665 "addressrange -> EALREADY");
1669 entry = entry->next;
1676 /* addressrange occupied by same host */
1677 spin_unlock_irqrestore(&host_info_lock, flags);
1678 vfree(addr->addr_space_buffer);
1682 /* another host with valid address-entry containing same addressrange */
1683 list_for_each_entry(hi, &host_info_list, list) {
1684 if (hi->host != fi->host) {
1685 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1686 entry = fi_hlp->addr_list.next;
1687 while (entry != &(fi_hlp->addr_list)) {
1689 list_entry(entry, struct arm_addr,
1691 if ((arm_addr->start == addr->start)
1692 && (arm_addr->end == addr->end)) {
1694 ("another host ownes same "
1699 entry = entry->next;
1707 spin_unlock_irqrestore(&host_info_lock, flags);
1710 DBGMSG("another hosts entry is valid -> SUCCESS");
1711 if (copy_to_user(int2ptr(req->req.recvb),
1712 &addr->start, sizeof(u64))) {
1713 printk(KERN_ERR "raw1394: arm_register failed "
1714 " address-range-entry is invalid -> EFAULT !!!\n");
1715 vfree(addr->addr_space_buffer);
1719 free_pending_request(req); /* immediate success or fail */
1721 spin_lock_irqsave(&host_info_lock, flags);
1722 list_add_tail(&addr->addr_list, &fi->addr_list);
1723 spin_unlock_irqrestore(&host_info_lock, flags);
1727 hpsb_register_addrspace(&raw1394_highlevel, fi->host, &arm_ops,
1729 req->req.address + req->req.length);
1732 spin_lock_irqsave(&host_info_lock, flags);
1733 list_add_tail(&addr->addr_list, &fi->addr_list);
1734 spin_unlock_irqrestore(&host_info_lock, flags);
1736 DBGMSG("arm_register failed errno: %d \n", retval);
1737 vfree(addr->addr_space_buffer);
1741 free_pending_request(req); /* immediate success or fail */
1745 static int arm_unregister(struct file_info *fi, struct pending_request *req)
1749 struct list_head *entry;
1750 struct arm_addr *addr = NULL;
1751 struct host_info *hi;
1752 struct file_info *fi_hlp = NULL;
1753 struct arm_addr *arm_addr = NULL;
1755 unsigned long flags;
1757 DBGMSG("arm_Unregister called addr(Offset): "
1759 (u32) ((req->req.address >> 32) & 0xFFFF),
1760 (u32) (req->req.address & 0xFFFFFFFF));
1761 spin_lock_irqsave(&host_info_lock, flags);
1763 entry = fi->addr_list.next;
1764 while (entry != &(fi->addr_list)) {
1765 addr = list_entry(entry, struct arm_addr, addr_list);
1766 if (addr->start == req->req.address) {
1770 entry = entry->next;
1773 DBGMSG("arm_Unregister addr not found");
1774 spin_unlock_irqrestore(&host_info_lock, flags);
1777 DBGMSG("arm_Unregister addr found");
1779 /* another host with valid address-entry containing
1780 same addressrange */
1781 list_for_each_entry(hi, &host_info_list, list) {
1782 if (hi->host != fi->host) {
1783 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1784 entry = fi_hlp->addr_list.next;
1785 while (entry != &(fi_hlp->addr_list)) {
1786 arm_addr = list_entry(entry,
1789 if (arm_addr->start == addr->start) {
1790 DBGMSG("another host ownes "
1791 "same addressrange");
1795 entry = entry->next;
1804 DBGMSG("delete entry from list -> success");
1805 list_del(&addr->addr_list);
1806 spin_unlock_irqrestore(&host_info_lock, flags);
1807 vfree(addr->addr_space_buffer);
1809 free_pending_request(req); /* immediate success or fail */
1813 hpsb_unregister_addrspace(&raw1394_highlevel, fi->host,
1816 printk(KERN_ERR "raw1394: arm_Unregister failed -> EINVAL\n");
1817 spin_unlock_irqrestore(&host_info_lock, flags);
1820 DBGMSG("delete entry from list -> success");
1821 list_del(&addr->addr_list);
1822 spin_unlock_irqrestore(&host_info_lock, flags);
1823 vfree(addr->addr_space_buffer);
1825 free_pending_request(req); /* immediate success or fail */
1829 /* Copy data from ARM buffer(s) to user buffer. */
1830 static int arm_get_buf(struct file_info *fi, struct pending_request *req)
1832 struct arm_addr *arm_addr = NULL;
1833 unsigned long flags;
1834 unsigned long offset;
1836 struct list_head *entry;
1838 DBGMSG("arm_get_buf "
1839 "addr(Offset): %04X %08X length: %u",
1840 (u32) ((req->req.address >> 32) & 0xFFFF),
1841 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
1843 spin_lock_irqsave(&host_info_lock, flags);
1844 entry = fi->addr_list.next;
1845 while (entry != &(fi->addr_list)) {
1846 arm_addr = list_entry(entry, struct arm_addr, addr_list);
1847 if ((arm_addr->start <= req->req.address) &&
1848 (arm_addr->end > req->req.address)) {
1849 if (req->req.address + req->req.length <= arm_addr->end) {
1850 offset = req->req.address - arm_addr->start;
1851 spin_unlock_irqrestore(&host_info_lock, flags);
1854 ("arm_get_buf copy_to_user( %08X, %p, %u )",
1855 (u32) req->req.recvb,
1856 arm_addr->addr_space_buffer + offset,
1857 (u32) req->req.length);
1859 (int2ptr(req->req.recvb),
1860 arm_addr->addr_space_buffer + offset,
1864 /* We have to free the request, because we
1865 * queue no response, and therefore nobody
1867 free_pending_request(req);
1870 DBGMSG("arm_get_buf request exceeded mapping");
1871 spin_unlock_irqrestore(&host_info_lock, flags);
1875 entry = entry->next;
1877 spin_unlock_irqrestore(&host_info_lock, flags);
1881 /* Copy data from user buffer to ARM buffer(s). */
1882 static int arm_set_buf(struct file_info *fi, struct pending_request *req)
1884 struct arm_addr *arm_addr = NULL;
1885 unsigned long flags;
1886 unsigned long offset;
1888 struct list_head *entry;
1890 DBGMSG("arm_set_buf "
1891 "addr(Offset): %04X %08X length: %u",
1892 (u32) ((req->req.address >> 32) & 0xFFFF),
1893 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
1895 spin_lock_irqsave(&host_info_lock, flags);
1896 entry = fi->addr_list.next;
1897 while (entry != &(fi->addr_list)) {
1898 arm_addr = list_entry(entry, struct arm_addr, addr_list);
1899 if ((arm_addr->start <= req->req.address) &&
1900 (arm_addr->end > req->req.address)) {
1901 if (req->req.address + req->req.length <= arm_addr->end) {
1902 offset = req->req.address - arm_addr->start;
1903 spin_unlock_irqrestore(&host_info_lock, flags);
1906 ("arm_set_buf copy_from_user( %p, %08X, %u )",
1907 arm_addr->addr_space_buffer + offset,
1908 (u32) req->req.sendb,
1909 (u32) req->req.length);
1911 (arm_addr->addr_space_buffer + offset,
1912 int2ptr(req->req.sendb),
1916 /* We have to free the request, because we
1917 * queue no response, and therefore nobody
1919 free_pending_request(req);
1922 DBGMSG("arm_set_buf request exceeded mapping");
1923 spin_unlock_irqrestore(&host_info_lock, flags);
1927 entry = entry->next;
1929 spin_unlock_irqrestore(&host_info_lock, flags);
1933 static int reset_notification(struct file_info *fi, struct pending_request *req)
1935 DBGMSG("reset_notification called - switch %s ",
1936 (req->req.misc == RAW1394_NOTIFY_OFF) ? "OFF" : "ON");
1937 if ((req->req.misc == RAW1394_NOTIFY_OFF) ||
1938 (req->req.misc == RAW1394_NOTIFY_ON)) {
1939 fi->notification = (u8) req->req.misc;
1940 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
1943 /* error EINVAL (22) invalid argument */
1947 static int write_phypacket(struct file_info *fi, struct pending_request *req)
1949 struct hpsb_packet *packet = NULL;
1952 unsigned long flags;
1954 data = be32_to_cpu((u32) req->req.sendb);
1955 DBGMSG("write_phypacket called - quadlet 0x%8.8x ", data);
1956 packet = hpsb_make_phypacket(fi->host, data);
1959 req->req.length = 0;
1960 req->packet = packet;
1961 hpsb_set_packet_complete_task(packet,
1962 (void (*)(void *))queue_complete_cb, req);
1963 spin_lock_irqsave(&fi->reqlists_lock, flags);
1964 list_add_tail(&req->list, &fi->req_pending);
1965 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
1966 packet->generation = req->req.generation;
1967 retval = hpsb_send_packet(packet);
1968 DBGMSG("write_phypacket send_packet called => retval: %d ", retval);
1970 req->req.error = RAW1394_ERROR_SEND_ERROR;
1971 req->req.length = 0;
1972 queue_complete_req(req);
1977 static int get_config_rom(struct file_info *fi, struct pending_request *req)
1980 quadlet_t *data = kmalloc(req->req.length, GFP_KERNEL);
1987 csr1212_read(fi->host->csr.rom, CSR1212_CONFIG_ROM_SPACE_OFFSET,
1988 data, req->req.length);
1989 if (copy_to_user(int2ptr(req->req.recvb), data, req->req.length))
1992 (int2ptr(req->req.tag), &fi->host->csr.rom->cache_head->len,
1993 sizeof(fi->host->csr.rom->cache_head->len)))
1995 if (copy_to_user(int2ptr(req->req.address), &fi->host->csr.generation,
1996 sizeof(fi->host->csr.generation)))
1998 if (copy_to_user(int2ptr(req->req.sendb), &status, sizeof(status)))
2002 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2007 static int update_config_rom(struct file_info *fi, struct pending_request *req)
2010 quadlet_t *data = kmalloc(req->req.length, GFP_KERNEL);
2013 if (copy_from_user(data, int2ptr(req->req.sendb), req->req.length)) {
2016 int status = hpsb_update_config_rom(fi->host,
2017 data, req->req.length,
2018 (unsigned char)req->req.
2021 (int2ptr(req->req.recvb), &status, sizeof(status)))
2026 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2032 static int modify_config_rom(struct file_info *fi, struct pending_request *req)
2034 struct csr1212_keyval *kv;
2035 struct csr1212_csr_rom_cache *cache;
2036 struct csr1212_dentry *dentry;
2040 if (req->req.misc == ~0) {
2041 if (req->req.length == 0)
2044 /* Find an unused slot */
2046 dr < RAW1394_MAX_USER_CSR_DIRS && fi->csr1212_dirs[dr];
2049 if (dr == RAW1394_MAX_USER_CSR_DIRS)
2052 fi->csr1212_dirs[dr] =
2053 csr1212_new_directory(CSR1212_KV_ID_VENDOR);
2054 if (!fi->csr1212_dirs[dr])
2058 if (!fi->csr1212_dirs[dr])
2061 /* Delete old stuff */
2063 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2064 dentry; dentry = dentry->next) {
2065 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2070 if (req->req.length == 0) {
2071 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2072 fi->csr1212_dirs[dr] = NULL;
2074 hpsb_update_config_rom_image(fi->host);
2075 free_pending_request(req);
2080 cache = csr1212_rom_cache_malloc(0, req->req.length);
2082 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2083 fi->csr1212_dirs[dr] = NULL;
2087 cache->filled_head = kmalloc(sizeof(*cache->filled_head), GFP_KERNEL);
2088 if (!cache->filled_head) {
2089 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2090 fi->csr1212_dirs[dr] = NULL;
2091 CSR1212_FREE(cache);
2094 cache->filled_tail = cache->filled_head;
2096 if (copy_from_user(cache->data, int2ptr(req->req.sendb),
2098 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2099 fi->csr1212_dirs[dr] = NULL;
2102 cache->len = req->req.length;
2103 cache->filled_head->offset_start = 0;
2104 cache->filled_head->offset_end = cache->size - 1;
2106 cache->layout_head = cache->layout_tail = fi->csr1212_dirs[dr];
2108 ret = CSR1212_SUCCESS;
2109 /* parse all the items */
2110 for (kv = cache->layout_head; ret == CSR1212_SUCCESS && kv;
2112 ret = csr1212_parse_keyval(kv, cache);
2115 /* attach top level items to the root directory */
2117 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2118 ret == CSR1212_SUCCESS && dentry; dentry = dentry->next) {
2120 csr1212_attach_keyval_to_directory(fi->host->csr.
2125 if (ret == CSR1212_SUCCESS) {
2126 ret = hpsb_update_config_rom_image(fi->host);
2128 if (ret >= 0 && copy_to_user(int2ptr(req->req.recvb),
2134 kfree(cache->filled_head);
2135 CSR1212_FREE(cache);
2138 /* we have to free the request, because we queue no response,
2139 * and therefore nobody will free it */
2140 free_pending_request(req);
2144 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2145 dentry; dentry = dentry->next) {
2146 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2150 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2151 fi->csr1212_dirs[dr] = NULL;
2156 static int state_connected(struct file_info *fi, struct pending_request *req)
2158 int node = req->req.address >> 48;
2160 req->req.error = RAW1394_ERROR_NONE;
2162 switch (req->req.type) {
2164 case RAW1394_REQ_ECHO:
2165 queue_complete_req(req);
2168 case RAW1394_REQ_ARM_REGISTER:
2169 return arm_register(fi, req);
2171 case RAW1394_REQ_ARM_UNREGISTER:
2172 return arm_unregister(fi, req);
2174 case RAW1394_REQ_ARM_SET_BUF:
2175 return arm_set_buf(fi, req);
2177 case RAW1394_REQ_ARM_GET_BUF:
2178 return arm_get_buf(fi, req);
2180 case RAW1394_REQ_RESET_NOTIFY:
2181 return reset_notification(fi, req);
2183 case RAW1394_REQ_ISO_SEND:
2184 case RAW1394_REQ_ISO_LISTEN:
2185 printk(KERN_DEBUG "raw1394: old iso ABI has been removed\n");
2186 req->req.error = RAW1394_ERROR_COMPAT;
2187 req->req.misc = RAW1394_KERNELAPI_VERSION;
2188 queue_complete_req(req);
2191 case RAW1394_REQ_FCP_LISTEN:
2192 handle_fcp_listen(fi, req);
2195 case RAW1394_REQ_RESET_BUS:
2196 if (req->req.misc == RAW1394_LONG_RESET) {
2197 DBGMSG("busreset called (type: LONG)");
2198 hpsb_reset_bus(fi->host, LONG_RESET);
2199 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2202 if (req->req.misc == RAW1394_SHORT_RESET) {
2203 DBGMSG("busreset called (type: SHORT)");
2204 hpsb_reset_bus(fi->host, SHORT_RESET);
2205 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2208 /* error EINVAL (22) invalid argument */
2210 case RAW1394_REQ_GET_ROM:
2211 return get_config_rom(fi, req);
2213 case RAW1394_REQ_UPDATE_ROM:
2214 return update_config_rom(fi, req);
2216 case RAW1394_REQ_MODIFY_ROM:
2217 return modify_config_rom(fi, req);
2220 if (req->req.generation != get_hpsb_generation(fi->host)) {
2221 req->req.error = RAW1394_ERROR_GENERATION;
2222 req->req.generation = get_hpsb_generation(fi->host);
2223 req->req.length = 0;
2224 queue_complete_req(req);
2228 switch (req->req.type) {
2229 case RAW1394_REQ_PHYPACKET:
2230 return write_phypacket(fi, req);
2231 case RAW1394_REQ_ASYNC_SEND:
2232 return handle_async_send(fi, req);
2235 if (req->req.length == 0) {
2236 req->req.error = RAW1394_ERROR_INVALID_ARG;
2237 queue_complete_req(req);
2241 return handle_async_request(fi, req, node);
2244 static ssize_t raw1394_write(struct file *file, const char __user * buffer,
2245 size_t count, loff_t * offset_is_ignored)
2247 struct file_info *fi = (struct file_info *)file->private_data;
2248 struct pending_request *req;
2249 ssize_t retval = -EBADFD;
2251 #ifdef CONFIG_COMPAT
2252 if (count == sizeof(struct compat_raw1394_req) &&
2253 sizeof(struct compat_raw1394_req) !=
2254 sizeof(struct raw1394_request)) {
2255 buffer = raw1394_compat_write(buffer);
2256 if (IS_ERR((__force void *)buffer))
2257 return PTR_ERR((__force void *)buffer);
2260 if (count != sizeof(struct raw1394_request)) {
2264 req = alloc_pending_request();
2268 req->file_info = fi;
2270 if (copy_from_user(&req->req, buffer, sizeof(struct raw1394_request))) {
2271 free_pending_request(req);
2275 if (!mutex_trylock(&fi->state_mutex))
2278 switch (fi->state) {
2280 retval = state_opened(fi, req);
2284 retval = state_initialized(fi, req);
2288 retval = state_connected(fi, req);
2292 mutex_unlock(&fi->state_mutex);
2295 free_pending_request(req);
2304 /* rawiso operations */
2306 /* check if any RAW1394_REQ_RAWISO_ACTIVITY event is already in the
2307 * completion queue (reqlists_lock must be taken) */
2308 static inline int __rawiso_event_in_queue(struct file_info *fi)
2310 struct pending_request *req;
2312 list_for_each_entry(req, &fi->req_complete, list)
2313 if (req->req.type == RAW1394_REQ_RAWISO_ACTIVITY)
2319 /* put a RAWISO_ACTIVITY event in the queue, if one isn't there already */
2320 static void queue_rawiso_event(struct file_info *fi)
2322 unsigned long flags;
2324 spin_lock_irqsave(&fi->reqlists_lock, flags);
2326 /* only one ISO activity event may be in the queue */
2327 if (!__rawiso_event_in_queue(fi)) {
2328 struct pending_request *req =
2329 __alloc_pending_request(GFP_ATOMIC);
2332 req->file_info = fi;
2333 req->req.type = RAW1394_REQ_RAWISO_ACTIVITY;
2334 req->req.generation = get_hpsb_generation(fi->host);
2335 __queue_complete_req(req);
2337 /* on allocation failure, signal an overflow */
2338 if (fi->iso_handle) {
2339 atomic_inc(&fi->iso_handle->overflows);
2343 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2346 static void rawiso_activity_cb(struct hpsb_iso *iso)
2348 unsigned long flags;
2349 struct host_info *hi;
2350 struct file_info *fi;
2352 spin_lock_irqsave(&host_info_lock, flags);
2353 hi = find_host_info(iso->host);
2356 list_for_each_entry(fi, &hi->file_info_list, list) {
2357 if (fi->iso_handle == iso)
2358 queue_rawiso_event(fi);
2362 spin_unlock_irqrestore(&host_info_lock, flags);
2365 /* helper function - gather all the kernel iso status bits for returning to user-space */
2366 static void raw1394_iso_fill_status(struct hpsb_iso *iso,
2367 struct raw1394_iso_status *stat)
2369 int overflows = atomic_read(&iso->overflows);
2370 int skips = atomic_read(&iso->skips);
2372 stat->config.data_buf_size = iso->buf_size;
2373 stat->config.buf_packets = iso->buf_packets;
2374 stat->config.channel = iso->channel;
2375 stat->config.speed = iso->speed;
2376 stat->config.irq_interval = iso->irq_interval;
2377 stat->n_packets = hpsb_iso_n_ready(iso);
2378 stat->overflows = ((skips & 0xFFFF) << 16) | ((overflows & 0xFFFF));
2379 stat->xmit_cycle = iso->xmit_cycle;
2382 static int raw1394_iso_xmit_init(struct file_info *fi, void __user * uaddr)
2384 struct raw1394_iso_status stat;
2389 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2392 fi->iso_handle = hpsb_iso_xmit_init(fi->host,
2393 stat.config.data_buf_size,
2394 stat.config.buf_packets,
2395 stat.config.channel,
2397 stat.config.irq_interval,
2398 rawiso_activity_cb);
2399 if (!fi->iso_handle)
2402 fi->iso_state = RAW1394_ISO_XMIT;
2404 raw1394_iso_fill_status(fi->iso_handle, &stat);
2405 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2408 /* queue an event to get things started */
2409 rawiso_activity_cb(fi->iso_handle);
2414 static int raw1394_iso_recv_init(struct file_info *fi, void __user * uaddr)
2416 struct raw1394_iso_status stat;
2421 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2424 fi->iso_handle = hpsb_iso_recv_init(fi->host,
2425 stat.config.data_buf_size,
2426 stat.config.buf_packets,
2427 stat.config.channel,
2428 stat.config.dma_mode,
2429 stat.config.irq_interval,
2430 rawiso_activity_cb);
2431 if (!fi->iso_handle)
2434 fi->iso_state = RAW1394_ISO_RECV;
2436 raw1394_iso_fill_status(fi->iso_handle, &stat);
2437 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2442 static int raw1394_iso_get_status(struct file_info *fi, void __user * uaddr)
2444 struct raw1394_iso_status stat;
2445 struct hpsb_iso *iso = fi->iso_handle;
2447 raw1394_iso_fill_status(fi->iso_handle, &stat);
2448 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2451 /* reset overflow counter */
2452 atomic_set(&iso->overflows, 0);
2453 /* reset skip counter */
2454 atomic_set(&iso->skips, 0);
2459 /* copy N packet_infos out of the ringbuffer into user-supplied array */
2460 static int raw1394_iso_recv_packets(struct file_info *fi, void __user * uaddr)
2462 struct raw1394_iso_packets upackets;
2463 unsigned int packet = fi->iso_handle->first_packet;
2466 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2469 if (upackets.n_packets > hpsb_iso_n_ready(fi->iso_handle))
2472 /* ensure user-supplied buffer is accessible and big enough */
2473 if (!access_ok(VERIFY_WRITE, upackets.infos,
2474 upackets.n_packets *
2475 sizeof(struct raw1394_iso_packet_info)))
2478 /* copy the packet_infos out */
2479 for (i = 0; i < upackets.n_packets; i++) {
2480 if (__copy_to_user(&upackets.infos[i],
2481 &fi->iso_handle->infos[packet],
2482 sizeof(struct raw1394_iso_packet_info)))
2485 packet = (packet + 1) % fi->iso_handle->buf_packets;
2491 /* copy N packet_infos from user to ringbuffer, and queue them for transmission */
2492 static int raw1394_iso_send_packets(struct file_info *fi, void __user * uaddr)
2494 struct raw1394_iso_packets upackets;
2497 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2500 if (upackets.n_packets >= fi->iso_handle->buf_packets)
2503 if (upackets.n_packets >= hpsb_iso_n_ready(fi->iso_handle))
2506 /* ensure user-supplied buffer is accessible and big enough */
2507 if (!access_ok(VERIFY_READ, upackets.infos,
2508 upackets.n_packets *
2509 sizeof(struct raw1394_iso_packet_info)))
2512 /* copy the infos structs in and queue the packets */
2513 for (i = 0; i < upackets.n_packets; i++) {
2514 struct raw1394_iso_packet_info info;
2516 if (__copy_from_user(&info, &upackets.infos[i],
2517 sizeof(struct raw1394_iso_packet_info)))
2520 rv = hpsb_iso_xmit_queue_packet(fi->iso_handle, info.offset,
2521 info.len, info.tag, info.sy);
2529 static void raw1394_iso_shutdown(struct file_info *fi)
2532 hpsb_iso_shutdown(fi->iso_handle);
2534 fi->iso_handle = NULL;
2535 fi->iso_state = RAW1394_ISO_INACTIVE;
2538 static int raw1394_read_cycle_timer(struct file_info *fi, void __user * uaddr)
2540 struct raw1394_cycle_timer ct;
2543 err = hpsb_read_cycle_timer(fi->host, &ct.cycle_timer, &ct.local_time);
2545 if (copy_to_user(uaddr, &ct, sizeof(ct)))
2550 /* mmap the rawiso xmit/recv buffer */
2551 static int raw1394_mmap(struct file *file, struct vm_area_struct *vma)
2553 struct file_info *fi = file->private_data;
2556 if (!mutex_trylock(&fi->state_mutex))
2559 if (fi->iso_state == RAW1394_ISO_INACTIVE)
2562 ret = dma_region_mmap(&fi->iso_handle->data_buf, file, vma);
2564 mutex_unlock(&fi->state_mutex);
2569 static long raw1394_ioctl_inactive(struct file_info *fi, unsigned int cmd,
2573 case RAW1394_IOC_ISO_XMIT_INIT:
2574 return raw1394_iso_xmit_init(fi, argp);
2575 case RAW1394_IOC_ISO_RECV_INIT:
2576 return raw1394_iso_recv_init(fi, argp);
2582 static long raw1394_ioctl_recv(struct file_info *fi, unsigned int cmd,
2585 void __user *argp = (void __user *)arg;
2588 case RAW1394_IOC_ISO_RECV_START:{
2591 if (copy_from_user(&args[0], argp, sizeof(args)))
2593 return hpsb_iso_recv_start(fi->iso_handle,
2594 args[0], args[1], args[2]);
2596 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2597 hpsb_iso_stop(fi->iso_handle);
2599 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL:
2600 return hpsb_iso_recv_listen_channel(fi->iso_handle, arg);
2601 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
2602 return hpsb_iso_recv_unlisten_channel(fi->iso_handle, arg);
2603 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:{
2606 if (copy_from_user(&mask, argp, sizeof(mask)))
2608 return hpsb_iso_recv_set_channel_mask(fi->iso_handle,
2611 case RAW1394_IOC_ISO_GET_STATUS:
2612 return raw1394_iso_get_status(fi, argp);
2613 case RAW1394_IOC_ISO_RECV_PACKETS:
2614 return raw1394_iso_recv_packets(fi, argp);
2615 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
2616 return hpsb_iso_recv_release_packets(fi->iso_handle, arg);
2617 case RAW1394_IOC_ISO_RECV_FLUSH:
2618 return hpsb_iso_recv_flush(fi->iso_handle);
2619 case RAW1394_IOC_ISO_SHUTDOWN:
2620 raw1394_iso_shutdown(fi);
2622 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2623 queue_rawiso_event(fi);
2630 static long raw1394_ioctl_xmit(struct file_info *fi, unsigned int cmd,
2634 case RAW1394_IOC_ISO_XMIT_START:{
2637 if (copy_from_user(&args[0], argp, sizeof(args)))
2639 return hpsb_iso_xmit_start(fi->iso_handle,
2642 case RAW1394_IOC_ISO_XMIT_SYNC:
2643 return hpsb_iso_xmit_sync(fi->iso_handle);
2644 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2645 hpsb_iso_stop(fi->iso_handle);
2647 case RAW1394_IOC_ISO_GET_STATUS:
2648 return raw1394_iso_get_status(fi, argp);
2649 case RAW1394_IOC_ISO_XMIT_PACKETS:
2650 return raw1394_iso_send_packets(fi, argp);
2651 case RAW1394_IOC_ISO_SHUTDOWN:
2652 raw1394_iso_shutdown(fi);
2654 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2655 queue_rawiso_event(fi);
2662 /* ioctl is only used for rawiso operations */
2663 static long raw1394_ioctl(struct file *file, unsigned int cmd,
2666 struct file_info *fi = file->private_data;
2667 void __user *argp = (void __user *)arg;
2670 /* state-independent commands */
2672 case RAW1394_IOC_GET_CYCLE_TIMER:
2673 return raw1394_read_cycle_timer(fi, argp);
2678 if (!mutex_trylock(&fi->state_mutex))
2681 switch (fi->iso_state) {
2682 case RAW1394_ISO_INACTIVE:
2683 ret = raw1394_ioctl_inactive(fi, cmd, argp);
2685 case RAW1394_ISO_RECV:
2686 ret = raw1394_ioctl_recv(fi, cmd, arg);
2688 case RAW1394_ISO_XMIT:
2689 ret = raw1394_ioctl_xmit(fi, cmd, argp);
2696 mutex_unlock(&fi->state_mutex);
2701 #ifdef CONFIG_COMPAT
2702 struct raw1394_iso_packets32 {
2704 compat_uptr_t infos;
2705 } __attribute__((packed));
2707 struct raw1394_cycle_timer32 {
2711 #if defined(CONFIG_X86_64) || defined(CONFIG_IA64)
2712 __attribute__((packed))
2716 #define RAW1394_IOC_ISO_RECV_PACKETS32 \
2717 _IOW ('#', 0x25, struct raw1394_iso_packets32)
2718 #define RAW1394_IOC_ISO_XMIT_PACKETS32 \
2719 _IOW ('#', 0x27, struct raw1394_iso_packets32)
2720 #define RAW1394_IOC_GET_CYCLE_TIMER32 \
2721 _IOR ('#', 0x30, struct raw1394_cycle_timer32)
2723 static long raw1394_iso_xmit_recv_packets32(struct file *file, unsigned int cmd,
2724 struct raw1394_iso_packets32 __user *arg)
2726 compat_uptr_t infos32;
2729 struct raw1394_iso_packets __user *dst = compat_alloc_user_space(sizeof(struct raw1394_iso_packets));
2731 if (!copy_in_user(&dst->n_packets, &arg->n_packets, sizeof arg->n_packets) &&
2732 !copy_from_user(&infos32, &arg->infos, sizeof infos32)) {
2733 infos = compat_ptr(infos32);
2734 if (!copy_to_user(&dst->infos, &infos, sizeof infos))
2735 err = raw1394_ioctl(file, cmd, (unsigned long)dst);
2740 static long raw1394_read_cycle_timer32(struct file_info *fi, void __user * uaddr)
2742 struct raw1394_cycle_timer32 ct;
2745 err = hpsb_read_cycle_timer(fi->host, &ct.cycle_timer, &ct.local_time);
2747 if (copy_to_user(uaddr, &ct, sizeof(ct)))
2752 static long raw1394_compat_ioctl(struct file *file,
2753 unsigned int cmd, unsigned long arg)
2755 struct file_info *fi = file->private_data;
2756 void __user *argp = (void __user *)arg;
2760 /* These requests have same format as long as 'int' has same size. */
2761 case RAW1394_IOC_ISO_RECV_INIT:
2762 case RAW1394_IOC_ISO_RECV_START:
2763 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL:
2764 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
2765 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:
2766 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
2767 case RAW1394_IOC_ISO_RECV_FLUSH:
2768 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2769 case RAW1394_IOC_ISO_XMIT_INIT:
2770 case RAW1394_IOC_ISO_XMIT_START:
2771 case RAW1394_IOC_ISO_XMIT_SYNC:
2772 case RAW1394_IOC_ISO_GET_STATUS:
2773 case RAW1394_IOC_ISO_SHUTDOWN:
2774 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2775 err = raw1394_ioctl(file, cmd, arg);
2777 /* These request have different format. */
2778 case RAW1394_IOC_ISO_RECV_PACKETS32:
2779 err = raw1394_iso_xmit_recv_packets32(file, RAW1394_IOC_ISO_RECV_PACKETS, argp);
2781 case RAW1394_IOC_ISO_XMIT_PACKETS32:
2782 err = raw1394_iso_xmit_recv_packets32(file, RAW1394_IOC_ISO_XMIT_PACKETS, argp);
2784 case RAW1394_IOC_GET_CYCLE_TIMER32:
2785 err = raw1394_read_cycle_timer32(fi, argp);
2796 static unsigned int raw1394_poll(struct file *file, poll_table * pt)
2798 struct file_info *fi = file->private_data;
2799 unsigned int mask = POLLOUT | POLLWRNORM;
2800 unsigned long flags;
2802 poll_wait(file, &fi->wait_complete, pt);
2804 spin_lock_irqsave(&fi->reqlists_lock, flags);
2805 if (!list_empty(&fi->req_complete)) {
2806 mask |= POLLIN | POLLRDNORM;
2808 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2813 static int raw1394_open(struct inode *inode, struct file *file)
2815 struct file_info *fi;
2817 fi = kzalloc(sizeof(*fi), GFP_KERNEL);
2821 fi->notification = (u8) RAW1394_NOTIFY_ON; /* busreset notification */
2823 INIT_LIST_HEAD(&fi->list);
2824 mutex_init(&fi->state_mutex);
2826 INIT_LIST_HEAD(&fi->req_pending);
2827 INIT_LIST_HEAD(&fi->req_complete);
2828 spin_lock_init(&fi->reqlists_lock);
2829 init_waitqueue_head(&fi->wait_complete);
2830 INIT_LIST_HEAD(&fi->addr_list);
2832 file->private_data = fi;
2837 static int raw1394_release(struct inode *inode, struct file *file)
2839 struct file_info *fi = file->private_data;
2840 struct list_head *lh;
2841 struct pending_request *req;
2844 struct list_head *entry;
2845 struct arm_addr *addr = NULL;
2846 struct host_info *hi;
2847 struct file_info *fi_hlp = NULL;
2848 struct arm_addr *arm_addr = NULL;
2851 unsigned long flags;
2853 if (fi->iso_state != RAW1394_ISO_INACTIVE)
2854 raw1394_iso_shutdown(fi);
2856 spin_lock_irqsave(&host_info_lock, flags);
2859 /* set address-entries invalid */
2861 while (!list_empty(&fi->addr_list)) {
2863 lh = fi->addr_list.next;
2864 addr = list_entry(lh, struct arm_addr, addr_list);
2865 /* another host with valid address-entry containing
2866 same addressrange? */
2867 list_for_each_entry(hi, &host_info_list, list) {
2868 if (hi->host != fi->host) {
2869 list_for_each_entry(fi_hlp, &hi->file_info_list,
2871 entry = fi_hlp->addr_list.next;
2872 while (entry != &(fi_hlp->addr_list)) {
2873 arm_addr = list_entry(entry, struct
2876 if (arm_addr->start ==
2879 ("raw1394_release: "
2880 "another host ownes "
2881 "same addressrange");
2885 entry = entry->next;
2893 if (!another_host) {
2894 DBGMSG("raw1394_release: call hpsb_arm_unregister");
2896 hpsb_unregister_addrspace(&raw1394_highlevel,
2897 fi->host, addr->start);
2901 "raw1394_release arm_Unregister failed\n");
2904 DBGMSG("raw1394_release: delete addr_entry from list");
2905 list_del(&addr->addr_list);
2906 vfree(addr->addr_space_buffer);
2909 spin_unlock_irqrestore(&host_info_lock, flags);
2911 printk(KERN_ERR "raw1394: during addr_list-release "
2912 "error(s) occurred \n");
2916 /* This locked section guarantees that neither
2917 * complete nor pending requests exist once i!=0 */
2918 spin_lock_irqsave(&fi->reqlists_lock, flags);
2919 while ((req = __next_complete_req(fi)))
2920 free_pending_request(req);
2922 i = list_empty(&fi->req_pending);
2923 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2928 * Sleep until more requests can be freed.
2930 * NB: We call the macro wait_event() with a condition argument
2931 * with side effect. This is only possible because the side
2932 * effect does not occur until the condition became true, and
2933 * wait_event() won't evaluate the condition again after that.
2935 wait_event(fi->wait_complete, (req = next_complete_req(fi)));
2936 free_pending_request(req);
2939 /* Remove any sub-trees left by user space programs */
2940 for (i = 0; i < RAW1394_MAX_USER_CSR_DIRS; i++) {
2941 struct csr1212_dentry *dentry;
2942 if (!fi->csr1212_dirs[i])
2945 fi->csr1212_dirs[i]->value.directory.dentries_head; dentry;
2946 dentry = dentry->next) {
2947 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2951 csr1212_release_keyval(fi->csr1212_dirs[i]);
2952 fi->csr1212_dirs[i] = NULL;
2956 if ((csr_mod || fi->cfgrom_upd)
2957 && hpsb_update_config_rom_image(fi->host) < 0)
2959 ("Failed to generate Configuration ROM image for host %d",
2962 if (fi->state == connected) {
2963 spin_lock_irqsave(&host_info_lock, flags);
2964 list_del(&fi->list);
2965 spin_unlock_irqrestore(&host_info_lock, flags);
2967 put_device(&fi->host->device);
2970 spin_lock_irqsave(&host_info_lock, flags);
2972 module_put(fi->host->driver->owner);
2973 spin_unlock_irqrestore(&host_info_lock, flags);
2980 /*** HOTPLUG STUFF **********************************************************/
2982 * Export information about protocols/devices supported by this driver.
2985 static const struct ieee1394_device_id raw1394_id_table[] = {
2987 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2988 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
2989 .version = AVC_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 & 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 + 1) & 0xffffff},
2999 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
3000 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
3001 .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff},
3005 MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table);
3008 static struct hpsb_protocol_driver raw1394_driver = {
3012 /******************************************************************************/
3014 static struct hpsb_highlevel raw1394_highlevel = {
3015 .name = RAW1394_DEVICE_NAME,
3016 .add_host = add_host,
3017 .remove_host = remove_host,
3018 .host_reset = host_reset,
3019 .fcp_request = fcp_request,
3022 static struct cdev raw1394_cdev;
3023 static const struct file_operations raw1394_fops = {
3024 .owner = THIS_MODULE,
3025 .read = raw1394_read,
3026 .write = raw1394_write,
3027 .mmap = raw1394_mmap,
3028 .unlocked_ioctl = raw1394_ioctl,
3029 #ifdef CONFIG_COMPAT
3030 .compat_ioctl = raw1394_compat_ioctl,
3032 .poll = raw1394_poll,
3033 .open = raw1394_open,
3034 .release = raw1394_release,
3037 static int __init init_raw1394(void)
3041 hpsb_register_highlevel(&raw1394_highlevel);
3044 (device_create(hpsb_protocol_class, NULL,
3045 MKDEV(IEEE1394_MAJOR,
3046 IEEE1394_MINOR_BLOCK_RAW1394 * 16),
3047 NULL, RAW1394_DEVICE_NAME))) {
3052 cdev_init(&raw1394_cdev, &raw1394_fops);
3053 raw1394_cdev.owner = THIS_MODULE;
3054 ret = cdev_add(&raw1394_cdev, IEEE1394_RAW1394_DEV, 1);
3056 HPSB_ERR("raw1394 failed to register minor device block");
3060 HPSB_INFO("raw1394: /dev/%s device initialized", RAW1394_DEVICE_NAME);
3062 ret = hpsb_register_protocol(&raw1394_driver);
3064 HPSB_ERR("raw1394: failed to register protocol");
3065 cdev_del(&raw1394_cdev);
3072 device_destroy(hpsb_protocol_class,
3073 MKDEV(IEEE1394_MAJOR,
3074 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
3076 hpsb_unregister_highlevel(&raw1394_highlevel);
3081 static void __exit cleanup_raw1394(void)
3083 device_destroy(hpsb_protocol_class,
3084 MKDEV(IEEE1394_MAJOR,
3085 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
3086 cdev_del(&raw1394_cdev);
3087 hpsb_unregister_highlevel(&raw1394_highlevel);
3088 hpsb_unregister_protocol(&raw1394_driver);
3091 module_init(init_raw1394);
3092 module_exit(cleanup_raw1394);
3093 MODULE_LICENSE("GPL");