4 * Raw interface to the bus
6 * Copyright (C) 1999, 2000 Andreas E. Bombe
7 * 2001, 2002 Manfred Weihs <weihs@ict.tuwien.ac.at>
8 * 2002 Christian Toegel <christian.toegel@gmx.at>
10 * This code is licensed under the GPL. See the file COPYING in the root
11 * directory of the kernel sources for details.
16 * Manfred Weihs <weihs@ict.tuwien.ac.at>
17 * configuration ROM manipulation
18 * address range mapping
19 * adaptation for new (transparent) loopback mechanism
20 * sending of arbitrary async packets
21 * Christian Toegel <christian.toegel@gmx.at>
22 * address range mapping
24 * transmit physical packet
25 * busreset notification control (switch on/off)
26 * busreset with selection of type (short/long)
30 #include <linux/kernel.h>
31 #include <linux/list.h>
32 #include <linux/string.h>
33 #include <linux/slab.h>
35 #include <linux/poll.h>
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/interrupt.h>
39 #include <linux/vmalloc.h>
40 #include <linux/cdev.h>
41 #include <asm/uaccess.h>
42 #include <asm/atomic.h>
43 #include <linux/compat.h>
46 #include "highlevel.h"
49 #include "ieee1394_core.h"
50 #include "ieee1394_hotplug.h"
51 #include "ieee1394_transactions.h"
52 #include "ieee1394_types.h"
56 #include "raw1394-private.h"
58 #define int2ptr(x) ((void __user *)(unsigned long)x)
59 #define ptr2int(x) ((u64)(unsigned long)(void __user *)x)
61 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
66 #define DBGMSG(fmt, args...) \
67 printk(KERN_INFO "raw1394:" fmt "\n" , ## args)
69 #define DBGMSG(fmt, args...) do {} while (0)
72 static LIST_HEAD(host_info_list);
73 static int host_count;
74 static DEFINE_SPINLOCK(host_info_lock);
75 static atomic_t internal_generation = ATOMIC_INIT(0);
77 static atomic_t iso_buffer_size;
78 static const int iso_buffer_max = 4 * 1024 * 1024; /* 4 MB */
80 static struct hpsb_highlevel raw1394_highlevel;
82 static int arm_read(struct hpsb_host *host, int nodeid, quadlet_t * buffer,
83 u64 addr, size_t length, u16 flags);
84 static int arm_write(struct hpsb_host *host, int nodeid, int destid,
85 quadlet_t * data, u64 addr, size_t length, u16 flags);
86 static int arm_lock(struct hpsb_host *host, int nodeid, quadlet_t * store,
87 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
89 static int arm_lock64(struct hpsb_host *host, int nodeid, octlet_t * store,
90 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
92 static struct hpsb_address_ops arm_ops = {
99 static void queue_complete_cb(struct pending_request *req);
101 static struct pending_request *__alloc_pending_request(gfp_t flags)
103 struct pending_request *req;
105 req = kzalloc(sizeof(*req), flags);
107 INIT_LIST_HEAD(&req->list);
112 static inline struct pending_request *alloc_pending_request(void)
114 return __alloc_pending_request(GFP_KERNEL);
117 static void free_pending_request(struct pending_request *req)
120 if (atomic_dec_and_test(&req->ibs->refcount)) {
121 atomic_sub(req->ibs->data_size, &iso_buffer_size);
124 } else if (req->free_data) {
127 hpsb_free_packet(req->packet);
131 /* fi->reqlists_lock must be taken */
132 static void __queue_complete_req(struct pending_request *req)
134 struct file_info *fi = req->file_info;
136 list_move_tail(&req->list, &fi->req_complete);
137 wake_up(&fi->wait_complete);
140 static void queue_complete_req(struct pending_request *req)
143 struct file_info *fi = req->file_info;
145 spin_lock_irqsave(&fi->reqlists_lock, flags);
146 __queue_complete_req(req);
147 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
150 static void queue_complete_cb(struct pending_request *req)
152 struct hpsb_packet *packet = req->packet;
153 int rcode = (packet->header[1] >> 12) & 0xf;
155 switch (packet->ack_code) {
157 case ACKX_SEND_ERROR:
158 req->req.error = RAW1394_ERROR_SEND_ERROR;
161 req->req.error = RAW1394_ERROR_ABORTED;
164 req->req.error = RAW1394_ERROR_TIMEOUT;
167 req->req.error = (packet->ack_code << 16) | rcode;
171 if (!((packet->ack_code == ACK_PENDING) && (rcode == RCODE_COMPLETE))) {
175 if ((req->req.type == RAW1394_REQ_ASYNC_READ) ||
176 (req->req.type == RAW1394_REQ_ASYNC_WRITE) ||
177 (req->req.type == RAW1394_REQ_ASYNC_STREAM) ||
178 (req->req.type == RAW1394_REQ_LOCK) ||
179 (req->req.type == RAW1394_REQ_LOCK64))
180 hpsb_free_tlabel(packet);
182 queue_complete_req(req);
185 static void add_host(struct hpsb_host *host)
187 struct host_info *hi;
190 hi = kmalloc(sizeof(*hi), GFP_KERNEL);
193 INIT_LIST_HEAD(&hi->list);
195 INIT_LIST_HEAD(&hi->file_info_list);
197 spin_lock_irqsave(&host_info_lock, flags);
198 list_add_tail(&hi->list, &host_info_list);
200 spin_unlock_irqrestore(&host_info_lock, flags);
203 atomic_inc(&internal_generation);
206 static struct host_info *find_host_info(struct hpsb_host *host)
208 struct host_info *hi;
210 list_for_each_entry(hi, &host_info_list, list)
211 if (hi->host == host)
217 static void remove_host(struct hpsb_host *host)
219 struct host_info *hi;
222 spin_lock_irqsave(&host_info_lock, flags);
223 hi = find_host_info(host);
229 FIXME: address ranges should be removed
230 and fileinfo states should be initialized
231 (including setting generation to
232 internal-generation ...)
235 spin_unlock_irqrestore(&host_info_lock, flags);
238 printk(KERN_ERR "raw1394: attempt to remove unknown host "
245 atomic_inc(&internal_generation);
248 static void host_reset(struct hpsb_host *host)
251 struct host_info *hi;
252 struct file_info *fi;
253 struct pending_request *req;
255 spin_lock_irqsave(&host_info_lock, flags);
256 hi = find_host_info(host);
259 list_for_each_entry(fi, &hi->file_info_list, list) {
260 if (fi->notification == RAW1394_NOTIFY_ON) {
261 req = __alloc_pending_request(GFP_ATOMIC);
265 req->req.type = RAW1394_REQ_BUS_RESET;
266 req->req.generation =
267 get_hpsb_generation(host);
268 req->req.misc = (host->node_id << 16)
270 if (fi->protocol_version > 3) {
277 queue_complete_req(req);
282 spin_unlock_irqrestore(&host_info_lock, flags);
285 static void fcp_request(struct hpsb_host *host, int nodeid, int direction,
286 int cts, u8 * data, size_t length)
289 struct host_info *hi;
290 struct file_info *fi;
291 struct pending_request *req, *req_next;
292 struct iso_block_store *ibs = NULL;
295 if ((atomic_read(&iso_buffer_size) + length) > iso_buffer_max) {
296 HPSB_INFO("dropped fcp request");
300 spin_lock_irqsave(&host_info_lock, flags);
301 hi = find_host_info(host);
304 list_for_each_entry(fi, &hi->file_info_list, list) {
308 req = __alloc_pending_request(GFP_ATOMIC);
313 ibs = kmalloc(sizeof(*ibs) + length,
320 atomic_add(length, &iso_buffer_size);
321 atomic_set(&ibs->refcount, 0);
322 ibs->data_size = length;
323 memcpy(ibs->data, data, length);
326 atomic_inc(&ibs->refcount);
330 req->data = ibs->data;
331 req->req.type = RAW1394_REQ_FCP_REQUEST;
332 req->req.generation = get_hpsb_generation(host);
333 req->req.misc = nodeid | (direction << 16);
334 req->req.recvb = ptr2int(fi->fcp_buffer);
335 req->req.length = length;
337 list_add_tail(&req->list, &reqs);
340 spin_unlock_irqrestore(&host_info_lock, flags);
342 list_for_each_entry_safe(req, req_next, &reqs, list)
343 queue_complete_req(req);
347 struct compat_raw1394_req {
362 #if defined(CONFIG_X86_64) || defined(CONFIG_IA64)
363 __attribute__((packed))
367 static const char __user *raw1394_compat_write(const char __user *buf)
369 struct compat_raw1394_req __user *cr = (typeof(cr)) buf;
370 struct raw1394_request __user *r;
371 r = compat_alloc_user_space(sizeof(struct raw1394_request));
373 #define C(x) __copy_in_user(&r->x, &cr->x, sizeof(r->x))
375 if (copy_in_user(r, cr, sizeof(struct compat_raw1394_req)) ||
380 return ERR_PTR(-EFAULT);
381 return (const char __user *)r;
385 #define P(x) __put_user(r->x, &cr->x)
388 raw1394_compat_read(const char __user *buf, struct raw1394_request *r)
390 struct compat_raw1394_req __user *cr = (typeof(cr)) buf;
391 if (!access_ok(VERIFY_WRITE, cr, sizeof(struct compat_raw1394_req)) ||
402 return sizeof(struct compat_raw1394_req);
408 /* get next completed request (caller must hold fi->reqlists_lock) */
409 static inline struct pending_request *__next_complete_req(struct file_info *fi)
411 struct list_head *lh;
412 struct pending_request *req = NULL;
414 if (!list_empty(&fi->req_complete)) {
415 lh = fi->req_complete.next;
417 req = list_entry(lh, struct pending_request, list);
422 /* atomically get next completed request */
423 static struct pending_request *next_complete_req(struct file_info *fi)
426 struct pending_request *req;
428 spin_lock_irqsave(&fi->reqlists_lock, flags);
429 req = __next_complete_req(fi);
430 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
434 static ssize_t raw1394_read(struct file *file, char __user * buffer,
435 size_t count, loff_t * offset_is_ignored)
437 struct file_info *fi = (struct file_info *)file->private_data;
438 struct pending_request *req;
442 if (count == sizeof(struct compat_raw1394_req)) {
446 if (count != sizeof(struct raw1394_request)) {
450 if (!access_ok(VERIFY_WRITE, buffer, count)) {
454 if (file->f_flags & O_NONBLOCK) {
455 if (!(req = next_complete_req(fi)))
459 * NB: We call the macro wait_event_interruptible() with a
460 * condition argument with side effect. This is only possible
461 * because the side effect does not occur until the condition
462 * became true, and wait_event_interruptible() won't evaluate
463 * the condition again after that.
465 if (wait_event_interruptible(fi->wait_complete,
466 (req = next_complete_req(fi))))
470 if (req->req.length) {
471 if (copy_to_user(int2ptr(req->req.recvb), req->data,
473 req->req.error = RAW1394_ERROR_MEMFAULT;
478 if (count == sizeof(struct compat_raw1394_req) &&
479 sizeof(struct compat_raw1394_req) !=
480 sizeof(struct raw1394_request)) {
481 ret = raw1394_compat_read(buffer, &req->req);
485 if (copy_to_user(buffer, &req->req, sizeof(req->req))) {
489 ret = (ssize_t) sizeof(struct raw1394_request);
492 free_pending_request(req);
496 static int state_opened(struct file_info *fi, struct pending_request *req)
498 if (req->req.type == RAW1394_REQ_INITIALIZE) {
499 switch (req->req.misc) {
500 case RAW1394_KERNELAPI_VERSION:
502 fi->state = initialized;
503 fi->protocol_version = req->req.misc;
504 req->req.error = RAW1394_ERROR_NONE;
505 req->req.generation = atomic_read(&internal_generation);
509 req->req.error = RAW1394_ERROR_COMPAT;
510 req->req.misc = RAW1394_KERNELAPI_VERSION;
513 req->req.error = RAW1394_ERROR_STATE_ORDER;
517 queue_complete_req(req);
521 static int state_initialized(struct file_info *fi, struct pending_request *req)
524 struct host_info *hi;
525 struct raw1394_khost_list *khl;
527 if (req->req.generation != atomic_read(&internal_generation)) {
528 req->req.error = RAW1394_ERROR_GENERATION;
529 req->req.generation = atomic_read(&internal_generation);
531 queue_complete_req(req);
535 switch (req->req.type) {
536 case RAW1394_REQ_LIST_CARDS:
537 spin_lock_irqsave(&host_info_lock, flags);
538 khl = kmalloc(sizeof(*khl) * host_count, GFP_ATOMIC);
541 req->req.misc = host_count;
542 req->data = (quadlet_t *) khl;
544 list_for_each_entry(hi, &host_info_list, list) {
545 khl->nodes = hi->host->node_count;
546 strcpy(khl->name, hi->host->driver->name);
550 spin_unlock_irqrestore(&host_info_lock, flags);
553 req->req.error = RAW1394_ERROR_NONE;
554 req->req.length = min(req->req.length,
556 (struct raw1394_khost_list)
564 case RAW1394_REQ_SET_CARD:
565 spin_lock_irqsave(&host_info_lock, flags);
566 if (req->req.misc >= host_count) {
567 req->req.error = RAW1394_ERROR_INVALID_ARG;
570 list_for_each_entry(hi, &host_info_list, list)
571 if (!req->req.misc--)
573 get_device(&hi->host->device); /* FIXME handle failure case */
574 list_add_tail(&fi->list, &hi->file_info_list);
576 /* prevent unloading of the host's low-level driver */
577 if (!try_module_get(hi->host->driver->owner)) {
578 req->req.error = RAW1394_ERROR_ABORTED;
583 fi->state = connected;
585 req->req.error = RAW1394_ERROR_NONE;
586 req->req.generation = get_hpsb_generation(fi->host);
587 req->req.misc = (fi->host->node_id << 16)
588 | fi->host->node_count;
589 if (fi->protocol_version > 3)
590 req->req.misc |= NODEID_TO_NODE(fi->host->irm_id) << 8;
592 spin_unlock_irqrestore(&host_info_lock, flags);
598 req->req.error = RAW1394_ERROR_STATE_ORDER;
603 queue_complete_req(req);
607 static void handle_fcp_listen(struct file_info *fi, struct pending_request *req)
610 if (fi->fcp_buffer) {
611 req->req.error = RAW1394_ERROR_ALREADY;
613 fi->fcp_buffer = int2ptr(req->req.recvb);
616 if (!fi->fcp_buffer) {
617 req->req.error = RAW1394_ERROR_ALREADY;
619 fi->fcp_buffer = NULL;
624 queue_complete_req(req);
627 static int handle_async_request(struct file_info *fi,
628 struct pending_request *req, int node)
631 struct hpsb_packet *packet = NULL;
632 u64 addr = req->req.address & 0xffffffffffffULL;
634 switch (req->req.type) {
635 case RAW1394_REQ_ASYNC_READ:
636 DBGMSG("read_request called");
638 hpsb_make_readpacket(fi->host, node, addr, req->req.length);
643 if (req->req.length == 4)
644 req->data = &packet->header[3];
646 req->data = packet->data;
650 case RAW1394_REQ_ASYNC_WRITE:
651 DBGMSG("write_request called");
653 packet = hpsb_make_writepacket(fi->host, node, addr, NULL,
658 if (req->req.length == 4) {
660 (&packet->header[3], int2ptr(req->req.sendb),
662 req->req.error = RAW1394_ERROR_MEMFAULT;
665 (packet->data, int2ptr(req->req.sendb),
667 req->req.error = RAW1394_ERROR_MEMFAULT;
673 case RAW1394_REQ_ASYNC_STREAM:
674 DBGMSG("stream_request called");
677 hpsb_make_streampacket(fi->host, NULL, req->req.length,
678 node & 0x3f /*channel */ ,
679 (req->req.misc >> 16) & 0x3,
680 req->req.misc & 0xf);
684 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
686 req->req.error = RAW1394_ERROR_MEMFAULT;
691 case RAW1394_REQ_LOCK:
692 DBGMSG("lock_request called");
693 if ((req->req.misc == EXTCODE_FETCH_ADD)
694 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
695 if (req->req.length != 4) {
696 req->req.error = RAW1394_ERROR_INVALID_ARG;
700 if (req->req.length != 8) {
701 req->req.error = RAW1394_ERROR_INVALID_ARG;
706 packet = hpsb_make_lockpacket(fi->host, node, addr,
707 req->req.misc, NULL, 0);
711 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
713 req->req.error = RAW1394_ERROR_MEMFAULT;
717 req->data = packet->data;
721 case RAW1394_REQ_LOCK64:
722 DBGMSG("lock64_request called");
723 if ((req->req.misc == EXTCODE_FETCH_ADD)
724 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
725 if (req->req.length != 8) {
726 req->req.error = RAW1394_ERROR_INVALID_ARG;
730 if (req->req.length != 16) {
731 req->req.error = RAW1394_ERROR_INVALID_ARG;
735 packet = hpsb_make_lock64packet(fi->host, node, addr,
736 req->req.misc, NULL, 0);
740 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
742 req->req.error = RAW1394_ERROR_MEMFAULT;
746 req->data = packet->data;
751 req->req.error = RAW1394_ERROR_STATE_ORDER;
754 req->packet = packet;
756 if (req->req.error) {
758 queue_complete_req(req);
762 hpsb_set_packet_complete_task(packet,
763 (void (*)(void *))queue_complete_cb, req);
765 spin_lock_irqsave(&fi->reqlists_lock, flags);
766 list_add_tail(&req->list, &fi->req_pending);
767 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
769 packet->generation = req->req.generation;
771 if (hpsb_send_packet(packet) < 0) {
772 req->req.error = RAW1394_ERROR_SEND_ERROR;
774 hpsb_free_tlabel(packet);
775 queue_complete_req(req);
780 static int handle_async_send(struct file_info *fi, struct pending_request *req)
783 struct hpsb_packet *packet;
784 int header_length = req->req.misc & 0xffff;
785 int expect_response = req->req.misc >> 16;
788 if (header_length > req->req.length || header_length < 12 ||
789 header_length > FIELD_SIZEOF(struct hpsb_packet, header)) {
790 req->req.error = RAW1394_ERROR_INVALID_ARG;
792 queue_complete_req(req);
796 data_size = req->req.length - header_length;
797 packet = hpsb_alloc_packet(data_size);
798 req->packet = packet;
802 if (copy_from_user(packet->header, int2ptr(req->req.sendb),
804 req->req.error = RAW1394_ERROR_MEMFAULT;
806 queue_complete_req(req);
811 (packet->data, int2ptr(req->req.sendb) + header_length,
813 req->req.error = RAW1394_ERROR_MEMFAULT;
815 queue_complete_req(req);
819 packet->type = hpsb_async;
820 packet->node_id = packet->header[0] >> 16;
821 packet->tcode = (packet->header[0] >> 4) & 0xf;
822 packet->tlabel = (packet->header[0] >> 10) & 0x3f;
823 packet->host = fi->host;
824 packet->expect_response = expect_response;
825 packet->header_size = header_length;
826 packet->data_size = data_size;
829 hpsb_set_packet_complete_task(packet,
830 (void (*)(void *))queue_complete_cb, req);
832 spin_lock_irqsave(&fi->reqlists_lock, flags);
833 list_add_tail(&req->list, &fi->req_pending);
834 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
836 /* Update the generation of the packet just before sending. */
837 packet->generation = req->req.generation;
839 if (hpsb_send_packet(packet) < 0) {
840 req->req.error = RAW1394_ERROR_SEND_ERROR;
841 queue_complete_req(req);
847 static int arm_read(struct hpsb_host *host, int nodeid, quadlet_t * buffer,
848 u64 addr, size_t length, u16 flags)
850 unsigned long irqflags;
851 struct pending_request *req;
852 struct host_info *hi;
853 struct file_info *fi = NULL;
854 struct list_head *entry;
855 struct arm_addr *arm_addr = NULL;
856 struct arm_request *arm_req = NULL;
857 struct arm_response *arm_resp = NULL;
858 int found = 0, size = 0, rcode = -1;
859 struct arm_request_response *arm_req_resp = NULL;
861 DBGMSG("arm_read called by node: %X "
862 "addr: %4.4x %8.8x length: %Zu", nodeid,
863 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
865 spin_lock_irqsave(&host_info_lock, irqflags);
866 hi = find_host_info(host); /* search address-entry */
868 list_for_each_entry(fi, &hi->file_info_list, list) {
869 entry = fi->addr_list.next;
870 while (entry != &(fi->addr_list)) {
872 list_entry(entry, struct arm_addr,
874 if (((arm_addr->start) <= (addr))
875 && ((arm_addr->end) >= (addr + length))) {
888 printk(KERN_ERR "raw1394: arm_read FAILED addr_entry not found"
889 " -> rcode_address_error\n");
890 spin_unlock_irqrestore(&host_info_lock, irqflags);
891 return (RCODE_ADDRESS_ERROR);
893 DBGMSG("arm_read addr_entry FOUND");
895 if (arm_addr->rec_length < length) {
896 DBGMSG("arm_read blocklength too big -> rcode_data_error");
897 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
900 if (arm_addr->access_rights & ARM_READ) {
901 if (!(arm_addr->client_transactions & ARM_READ)) {
903 (arm_addr->addr_space_buffer) + (addr -
907 DBGMSG("arm_read -> (rcode_complete)");
908 rcode = RCODE_COMPLETE;
911 rcode = RCODE_TYPE_ERROR; /* function not allowed */
912 DBGMSG("arm_read -> rcode_type_error (access denied)");
915 if (arm_addr->notification_options & ARM_READ) {
916 DBGMSG("arm_read -> entering notification-section");
917 req = __alloc_pending_request(GFP_ATOMIC);
919 DBGMSG("arm_read -> rcode_conflict_error");
920 spin_unlock_irqrestore(&host_info_lock, irqflags);
921 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
922 The request may be retried */
924 if (rcode == RCODE_COMPLETE) {
926 sizeof(struct arm_request) +
927 sizeof(struct arm_response) +
928 length * sizeof(byte_t) +
929 sizeof(struct arm_request_response);
932 sizeof(struct arm_request) +
933 sizeof(struct arm_response) +
934 sizeof(struct arm_request_response);
936 req->data = kmalloc(size, GFP_ATOMIC);
938 free_pending_request(req);
939 DBGMSG("arm_read -> rcode_conflict_error");
940 spin_unlock_irqrestore(&host_info_lock, irqflags);
941 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
942 The request may be retried */
946 req->req.type = RAW1394_REQ_ARM;
947 req->req.generation = get_hpsb_generation(host);
949 (((length << 16) & (0xFFFF0000)) | (ARM_READ & 0xFF));
950 req->req.tag = arm_addr->arm_tag;
951 req->req.recvb = arm_addr->recvb;
952 req->req.length = size;
953 arm_req_resp = (struct arm_request_response *)(req->data);
954 arm_req = (struct arm_request *)((byte_t *) (req->data) +
957 arm_request_response)));
959 (struct arm_response *)((byte_t *) (arm_req) +
960 (sizeof(struct arm_request)));
961 arm_req->buffer = NULL;
962 arm_resp->buffer = NULL;
963 if (rcode == RCODE_COMPLETE) {
965 (byte_t *) arm_resp + sizeof(struct arm_response);
967 (arm_addr->addr_space_buffer) + (addr -
972 int2ptr((arm_addr->recvb) +
973 sizeof(struct arm_request_response) +
974 sizeof(struct arm_request) +
975 sizeof(struct arm_response));
977 arm_resp->buffer_length =
978 (rcode == RCODE_COMPLETE) ? length : 0;
979 arm_resp->response_code = rcode;
980 arm_req->buffer_length = 0;
981 arm_req->generation = req->req.generation;
982 arm_req->extended_transaction_code = 0;
983 arm_req->destination_offset = addr;
984 arm_req->source_nodeid = nodeid;
985 arm_req->destination_nodeid = host->node_id;
986 arm_req->tlabel = (flags >> 10) & 0x3f;
987 arm_req->tcode = (flags >> 4) & 0x0f;
988 arm_req_resp->request = int2ptr((arm_addr->recvb) +
990 arm_request_response));
991 arm_req_resp->response =
992 int2ptr((arm_addr->recvb) +
993 sizeof(struct arm_request_response) +
994 sizeof(struct arm_request));
995 queue_complete_req(req);
997 spin_unlock_irqrestore(&host_info_lock, irqflags);
1001 static int arm_write(struct hpsb_host *host, int nodeid, int destid,
1002 quadlet_t * data, u64 addr, size_t length, u16 flags)
1004 unsigned long irqflags;
1005 struct pending_request *req;
1006 struct host_info *hi;
1007 struct file_info *fi = NULL;
1008 struct list_head *entry;
1009 struct arm_addr *arm_addr = NULL;
1010 struct arm_request *arm_req = NULL;
1011 struct arm_response *arm_resp = NULL;
1012 int found = 0, size = 0, rcode = -1, length_conflict = 0;
1013 struct arm_request_response *arm_req_resp = NULL;
1015 DBGMSG("arm_write called by node: %X "
1016 "addr: %4.4x %8.8x length: %Zu", nodeid,
1017 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
1019 spin_lock_irqsave(&host_info_lock, irqflags);
1020 hi = find_host_info(host); /* search address-entry */
1022 list_for_each_entry(fi, &hi->file_info_list, list) {
1023 entry = fi->addr_list.next;
1024 while (entry != &(fi->addr_list)) {
1026 list_entry(entry, struct arm_addr,
1028 if (((arm_addr->start) <= (addr))
1029 && ((arm_addr->end) >= (addr + length))) {
1033 entry = entry->next;
1042 printk(KERN_ERR "raw1394: arm_write FAILED addr_entry not found"
1043 " -> rcode_address_error\n");
1044 spin_unlock_irqrestore(&host_info_lock, irqflags);
1045 return (RCODE_ADDRESS_ERROR);
1047 DBGMSG("arm_write addr_entry FOUND");
1049 if (arm_addr->rec_length < length) {
1050 DBGMSG("arm_write blocklength too big -> rcode_data_error");
1051 length_conflict = 1;
1052 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
1055 if (arm_addr->access_rights & ARM_WRITE) {
1056 if (!(arm_addr->client_transactions & ARM_WRITE)) {
1057 memcpy((arm_addr->addr_space_buffer) +
1058 (addr - (arm_addr->start)), data,
1060 DBGMSG("arm_write -> (rcode_complete)");
1061 rcode = RCODE_COMPLETE;
1064 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1065 DBGMSG("arm_write -> rcode_type_error (access denied)");
1068 if (arm_addr->notification_options & ARM_WRITE) {
1069 DBGMSG("arm_write -> entering notification-section");
1070 req = __alloc_pending_request(GFP_ATOMIC);
1072 DBGMSG("arm_write -> rcode_conflict_error");
1073 spin_unlock_irqrestore(&host_info_lock, irqflags);
1074 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1075 The request my be retried */
1078 sizeof(struct arm_request) + sizeof(struct arm_response) +
1079 (length) * sizeof(byte_t) +
1080 sizeof(struct arm_request_response);
1081 req->data = kmalloc(size, GFP_ATOMIC);
1083 free_pending_request(req);
1084 DBGMSG("arm_write -> rcode_conflict_error");
1085 spin_unlock_irqrestore(&host_info_lock, irqflags);
1086 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1087 The request may be retried */
1090 req->file_info = fi;
1091 req->req.type = RAW1394_REQ_ARM;
1092 req->req.generation = get_hpsb_generation(host);
1094 (((length << 16) & (0xFFFF0000)) | (ARM_WRITE & 0xFF));
1095 req->req.tag = arm_addr->arm_tag;
1096 req->req.recvb = arm_addr->recvb;
1097 req->req.length = size;
1098 arm_req_resp = (struct arm_request_response *)(req->data);
1099 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1102 arm_request_response)));
1104 (struct arm_response *)((byte_t *) (arm_req) +
1105 (sizeof(struct arm_request)));
1106 arm_resp->buffer = NULL;
1107 memcpy((byte_t *) arm_resp + sizeof(struct arm_response),
1109 arm_req->buffer = int2ptr((arm_addr->recvb) +
1110 sizeof(struct arm_request_response) +
1111 sizeof(struct arm_request) +
1112 sizeof(struct arm_response));
1113 arm_req->buffer_length = length;
1114 arm_req->generation = req->req.generation;
1115 arm_req->extended_transaction_code = 0;
1116 arm_req->destination_offset = addr;
1117 arm_req->source_nodeid = nodeid;
1118 arm_req->destination_nodeid = destid;
1119 arm_req->tlabel = (flags >> 10) & 0x3f;
1120 arm_req->tcode = (flags >> 4) & 0x0f;
1121 arm_resp->buffer_length = 0;
1122 arm_resp->response_code = rcode;
1123 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1125 arm_request_response));
1126 arm_req_resp->response =
1127 int2ptr((arm_addr->recvb) +
1128 sizeof(struct arm_request_response) +
1129 sizeof(struct arm_request));
1130 queue_complete_req(req);
1132 spin_unlock_irqrestore(&host_info_lock, irqflags);
1136 static int arm_lock(struct hpsb_host *host, int nodeid, quadlet_t * store,
1137 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
1140 unsigned long irqflags;
1141 struct pending_request *req;
1142 struct host_info *hi;
1143 struct file_info *fi = NULL;
1144 struct list_head *entry;
1145 struct arm_addr *arm_addr = NULL;
1146 struct arm_request *arm_req = NULL;
1147 struct arm_response *arm_resp = NULL;
1148 int found = 0, size = 0, rcode = -1;
1150 struct arm_request_response *arm_req_resp = NULL;
1152 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1153 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1154 DBGMSG("arm_lock called by node: %X "
1155 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X",
1156 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1157 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1160 DBGMSG("arm_lock called by node: %X "
1161 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X arg: %8.8X",
1162 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1163 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1164 be32_to_cpu(data), be32_to_cpu(arg));
1166 spin_lock_irqsave(&host_info_lock, irqflags);
1167 hi = find_host_info(host); /* search address-entry */
1169 list_for_each_entry(fi, &hi->file_info_list, list) {
1170 entry = fi->addr_list.next;
1171 while (entry != &(fi->addr_list)) {
1173 list_entry(entry, struct arm_addr,
1175 if (((arm_addr->start) <= (addr))
1176 && ((arm_addr->end) >=
1177 (addr + sizeof(*store)))) {
1181 entry = entry->next;
1190 printk(KERN_ERR "raw1394: arm_lock FAILED addr_entry not found"
1191 " -> rcode_address_error\n");
1192 spin_unlock_irqrestore(&host_info_lock, irqflags);
1193 return (RCODE_ADDRESS_ERROR);
1195 DBGMSG("arm_lock addr_entry FOUND");
1198 if (arm_addr->access_rights & ARM_LOCK) {
1199 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1201 (arm_addr->addr_space_buffer) + (addr -
1205 switch (ext_tcode) {
1206 case (EXTCODE_MASK_SWAP):
1207 new = data | (old & ~arg);
1209 case (EXTCODE_COMPARE_SWAP):
1216 case (EXTCODE_FETCH_ADD):
1218 cpu_to_be32(be32_to_cpu(data) +
1221 case (EXTCODE_LITTLE_ADD):
1223 cpu_to_le32(le32_to_cpu(data) +
1226 case (EXTCODE_BOUNDED_ADD):
1229 cpu_to_be32(be32_to_cpu
1237 case (EXTCODE_WRAP_ADD):
1240 cpu_to_be32(be32_to_cpu
1249 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1251 "raw1394: arm_lock FAILED "
1252 "ext_tcode not allowed -> rcode_type_error\n");
1256 DBGMSG("arm_lock -> (rcode_complete)");
1257 rcode = RCODE_COMPLETE;
1258 memcpy(store, &old, sizeof(*store));
1259 memcpy((arm_addr->addr_space_buffer) +
1260 (addr - (arm_addr->start)),
1261 &new, sizeof(*store));
1265 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1266 DBGMSG("arm_lock -> rcode_type_error (access denied)");
1269 if (arm_addr->notification_options & ARM_LOCK) {
1270 byte_t *buf1, *buf2;
1271 DBGMSG("arm_lock -> entering notification-section");
1272 req = __alloc_pending_request(GFP_ATOMIC);
1274 DBGMSG("arm_lock -> rcode_conflict_error");
1275 spin_unlock_irqrestore(&host_info_lock, irqflags);
1276 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1277 The request may be retried */
1279 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1280 req->data = kmalloc(size, GFP_ATOMIC);
1282 free_pending_request(req);
1283 DBGMSG("arm_lock -> rcode_conflict_error");
1284 spin_unlock_irqrestore(&host_info_lock, irqflags);
1285 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1286 The request may be retried */
1289 arm_req_resp = (struct arm_request_response *)(req->data);
1290 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1293 arm_request_response)));
1295 (struct arm_response *)((byte_t *) (arm_req) +
1296 (sizeof(struct arm_request)));
1297 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1298 buf2 = buf1 + 2 * sizeof(*store);
1299 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1300 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1301 arm_req->buffer_length = sizeof(*store);
1302 memcpy(buf1, &data, sizeof(*store));
1305 arm_req->buffer_length = 2 * sizeof(*store);
1306 memcpy(buf1, &arg, sizeof(*store));
1307 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1309 if (rcode == RCODE_COMPLETE) {
1310 arm_resp->buffer_length = sizeof(*store);
1311 memcpy(buf2, &old, sizeof(*store));
1313 arm_resp->buffer_length = 0;
1315 req->file_info = fi;
1316 req->req.type = RAW1394_REQ_ARM;
1317 req->req.generation = get_hpsb_generation(host);
1318 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1320 req->req.tag = arm_addr->arm_tag;
1321 req->req.recvb = arm_addr->recvb;
1322 req->req.length = size;
1323 arm_req->generation = req->req.generation;
1324 arm_req->extended_transaction_code = ext_tcode;
1325 arm_req->destination_offset = addr;
1326 arm_req->source_nodeid = nodeid;
1327 arm_req->destination_nodeid = host->node_id;
1328 arm_req->tlabel = (flags >> 10) & 0x3f;
1329 arm_req->tcode = (flags >> 4) & 0x0f;
1330 arm_resp->response_code = rcode;
1331 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1333 arm_request_response));
1334 arm_req_resp->response =
1335 int2ptr((arm_addr->recvb) +
1336 sizeof(struct arm_request_response) +
1337 sizeof(struct arm_request));
1339 int2ptr((arm_addr->recvb) +
1340 sizeof(struct arm_request_response) +
1341 sizeof(struct arm_request) +
1342 sizeof(struct arm_response));
1344 int2ptr((arm_addr->recvb) +
1345 sizeof(struct arm_request_response) +
1346 sizeof(struct arm_request) +
1347 sizeof(struct arm_response) + 2 * sizeof(*store));
1348 queue_complete_req(req);
1350 spin_unlock_irqrestore(&host_info_lock, irqflags);
1354 static int arm_lock64(struct hpsb_host *host, int nodeid, octlet_t * store,
1355 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
1358 unsigned long irqflags;
1359 struct pending_request *req;
1360 struct host_info *hi;
1361 struct file_info *fi = NULL;
1362 struct list_head *entry;
1363 struct arm_addr *arm_addr = NULL;
1364 struct arm_request *arm_req = NULL;
1365 struct arm_response *arm_resp = NULL;
1366 int found = 0, size = 0, rcode = -1;
1368 struct arm_request_response *arm_req_resp = NULL;
1370 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1371 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1372 DBGMSG("arm_lock64 called by node: %X "
1373 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X ",
1374 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1375 (u32) (addr & 0xFFFFFFFF),
1377 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1378 (u32) (be64_to_cpu(data) & 0xFFFFFFFF));
1380 DBGMSG("arm_lock64 called by node: %X "
1381 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X arg: "
1383 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1384 (u32) (addr & 0xFFFFFFFF),
1386 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1387 (u32) (be64_to_cpu(data) & 0xFFFFFFFF),
1388 (u32) ((be64_to_cpu(arg) >> 32) & 0xFFFFFFFF),
1389 (u32) (be64_to_cpu(arg) & 0xFFFFFFFF));
1391 spin_lock_irqsave(&host_info_lock, irqflags);
1392 hi = find_host_info(host); /* search addressentry in file_info's for host */
1394 list_for_each_entry(fi, &hi->file_info_list, list) {
1395 entry = fi->addr_list.next;
1396 while (entry != &(fi->addr_list)) {
1398 list_entry(entry, struct arm_addr,
1400 if (((arm_addr->start) <= (addr))
1401 && ((arm_addr->end) >=
1402 (addr + sizeof(*store)))) {
1406 entry = entry->next;
1416 "raw1394: arm_lock64 FAILED addr_entry not found"
1417 " -> rcode_address_error\n");
1418 spin_unlock_irqrestore(&host_info_lock, irqflags);
1419 return (RCODE_ADDRESS_ERROR);
1421 DBGMSG("arm_lock64 addr_entry FOUND");
1424 if (arm_addr->access_rights & ARM_LOCK) {
1425 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1427 (arm_addr->addr_space_buffer) + (addr -
1431 switch (ext_tcode) {
1432 case (EXTCODE_MASK_SWAP):
1433 new = data | (old & ~arg);
1435 case (EXTCODE_COMPARE_SWAP):
1442 case (EXTCODE_FETCH_ADD):
1444 cpu_to_be64(be64_to_cpu(data) +
1447 case (EXTCODE_LITTLE_ADD):
1449 cpu_to_le64(le64_to_cpu(data) +
1452 case (EXTCODE_BOUNDED_ADD):
1455 cpu_to_be64(be64_to_cpu
1463 case (EXTCODE_WRAP_ADD):
1466 cpu_to_be64(be64_to_cpu
1476 "raw1394: arm_lock64 FAILED "
1477 "ext_tcode not allowed -> rcode_type_error\n");
1478 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1483 ("arm_lock64 -> (rcode_complete)");
1484 rcode = RCODE_COMPLETE;
1485 memcpy(store, &old, sizeof(*store));
1486 memcpy((arm_addr->addr_space_buffer) +
1487 (addr - (arm_addr->start)),
1488 &new, sizeof(*store));
1492 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1494 ("arm_lock64 -> rcode_type_error (access denied)");
1497 if (arm_addr->notification_options & ARM_LOCK) {
1498 byte_t *buf1, *buf2;
1499 DBGMSG("arm_lock64 -> entering notification-section");
1500 req = __alloc_pending_request(GFP_ATOMIC);
1502 spin_unlock_irqrestore(&host_info_lock, irqflags);
1503 DBGMSG("arm_lock64 -> rcode_conflict_error");
1504 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1505 The request may be retried */
1507 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1508 req->data = kmalloc(size, GFP_ATOMIC);
1510 free_pending_request(req);
1511 spin_unlock_irqrestore(&host_info_lock, irqflags);
1512 DBGMSG("arm_lock64 -> rcode_conflict_error");
1513 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1514 The request may be retried */
1517 arm_req_resp = (struct arm_request_response *)(req->data);
1518 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1521 arm_request_response)));
1523 (struct arm_response *)((byte_t *) (arm_req) +
1524 (sizeof(struct arm_request)));
1525 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1526 buf2 = buf1 + 2 * sizeof(*store);
1527 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1528 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1529 arm_req->buffer_length = sizeof(*store);
1530 memcpy(buf1, &data, sizeof(*store));
1533 arm_req->buffer_length = 2 * sizeof(*store);
1534 memcpy(buf1, &arg, sizeof(*store));
1535 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1537 if (rcode == RCODE_COMPLETE) {
1538 arm_resp->buffer_length = sizeof(*store);
1539 memcpy(buf2, &old, sizeof(*store));
1541 arm_resp->buffer_length = 0;
1543 req->file_info = fi;
1544 req->req.type = RAW1394_REQ_ARM;
1545 req->req.generation = get_hpsb_generation(host);
1546 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1548 req->req.tag = arm_addr->arm_tag;
1549 req->req.recvb = arm_addr->recvb;
1550 req->req.length = size;
1551 arm_req->generation = req->req.generation;
1552 arm_req->extended_transaction_code = ext_tcode;
1553 arm_req->destination_offset = addr;
1554 arm_req->source_nodeid = nodeid;
1555 arm_req->destination_nodeid = host->node_id;
1556 arm_req->tlabel = (flags >> 10) & 0x3f;
1557 arm_req->tcode = (flags >> 4) & 0x0f;
1558 arm_resp->response_code = rcode;
1559 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1561 arm_request_response));
1562 arm_req_resp->response =
1563 int2ptr((arm_addr->recvb) +
1564 sizeof(struct arm_request_response) +
1565 sizeof(struct arm_request));
1567 int2ptr((arm_addr->recvb) +
1568 sizeof(struct arm_request_response) +
1569 sizeof(struct arm_request) +
1570 sizeof(struct arm_response));
1572 int2ptr((arm_addr->recvb) +
1573 sizeof(struct arm_request_response) +
1574 sizeof(struct arm_request) +
1575 sizeof(struct arm_response) + 2 * sizeof(*store));
1576 queue_complete_req(req);
1578 spin_unlock_irqrestore(&host_info_lock, irqflags);
1582 static int arm_register(struct file_info *fi, struct pending_request *req)
1585 struct arm_addr *addr;
1586 struct host_info *hi;
1587 struct file_info *fi_hlp = NULL;
1588 struct list_head *entry;
1589 struct arm_addr *arm_addr = NULL;
1590 int same_host, another_host;
1591 unsigned long flags;
1593 DBGMSG("arm_register called "
1594 "addr(Offset): %8.8x %8.8x length: %u "
1595 "rights: %2.2X notify: %2.2X "
1596 "max_blk_len: %4.4X",
1597 (u32) ((req->req.address >> 32) & 0xFFFF),
1598 (u32) (req->req.address & 0xFFFFFFFF),
1599 req->req.length, ((req->req.misc >> 8) & 0xFF),
1600 (req->req.misc & 0xFF), ((req->req.misc >> 16) & 0xFFFF));
1601 /* check addressrange */
1602 if ((((req->req.address) & ~(0xFFFFFFFFFFFFULL)) != 0) ||
1603 (((req->req.address + req->req.length) & ~(0xFFFFFFFFFFFFULL)) !=
1605 req->req.length = 0;
1608 /* addr-list-entry for fileinfo */
1609 addr = kmalloc(sizeof(*addr), GFP_KERNEL);
1611 req->req.length = 0;
1614 /* allocation of addr_space_buffer */
1615 addr->addr_space_buffer = vmalloc(req->req.length);
1616 if (!(addr->addr_space_buffer)) {
1618 req->req.length = 0;
1621 /* initialization of addr_space_buffer */
1622 if ((req->req.sendb) == (unsigned long)NULL) {
1624 memset(addr->addr_space_buffer, 0, req->req.length);
1626 /* init: user -> kernel */
1628 (addr->addr_space_buffer, int2ptr(req->req.sendb),
1630 vfree(addr->addr_space_buffer);
1635 INIT_LIST_HEAD(&addr->addr_list);
1636 addr->arm_tag = req->req.tag;
1637 addr->start = req->req.address;
1638 addr->end = req->req.address + req->req.length;
1639 addr->access_rights = (u8) (req->req.misc & 0x0F);
1640 addr->notification_options = (u8) ((req->req.misc >> 4) & 0x0F);
1641 addr->client_transactions = (u8) ((req->req.misc >> 8) & 0x0F);
1642 addr->access_rights |= addr->client_transactions;
1643 addr->notification_options |= addr->client_transactions;
1644 addr->recvb = req->req.recvb;
1645 addr->rec_length = (u16) ((req->req.misc >> 16) & 0xFFFF);
1647 spin_lock_irqsave(&host_info_lock, flags);
1648 hi = find_host_info(fi->host);
1651 /* same host with address-entry containing same addressrange ? */
1652 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1653 entry = fi_hlp->addr_list.next;
1654 while (entry != &(fi_hlp->addr_list)) {
1656 list_entry(entry, struct arm_addr, addr_list);
1657 if ((arm_addr->start == addr->start)
1658 && (arm_addr->end == addr->end)) {
1659 DBGMSG("same host ownes same "
1660 "addressrange -> EALREADY");
1664 entry = entry->next;
1671 /* addressrange occupied by same host */
1672 spin_unlock_irqrestore(&host_info_lock, flags);
1673 vfree(addr->addr_space_buffer);
1677 /* another host with valid address-entry containing same addressrange */
1678 list_for_each_entry(hi, &host_info_list, list) {
1679 if (hi->host != fi->host) {
1680 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1681 entry = fi_hlp->addr_list.next;
1682 while (entry != &(fi_hlp->addr_list)) {
1684 list_entry(entry, struct arm_addr,
1686 if ((arm_addr->start == addr->start)
1687 && (arm_addr->end == addr->end)) {
1689 ("another host ownes same "
1694 entry = entry->next;
1702 spin_unlock_irqrestore(&host_info_lock, flags);
1705 DBGMSG("another hosts entry is valid -> SUCCESS");
1706 if (copy_to_user(int2ptr(req->req.recvb),
1707 &addr->start, sizeof(u64))) {
1708 printk(KERN_ERR "raw1394: arm_register failed "
1709 " address-range-entry is invalid -> EFAULT !!!\n");
1710 vfree(addr->addr_space_buffer);
1714 free_pending_request(req); /* immediate success or fail */
1716 spin_lock_irqsave(&host_info_lock, flags);
1717 list_add_tail(&addr->addr_list, &fi->addr_list);
1718 spin_unlock_irqrestore(&host_info_lock, flags);
1722 hpsb_register_addrspace(&raw1394_highlevel, fi->host, &arm_ops,
1724 req->req.address + req->req.length);
1727 spin_lock_irqsave(&host_info_lock, flags);
1728 list_add_tail(&addr->addr_list, &fi->addr_list);
1729 spin_unlock_irqrestore(&host_info_lock, flags);
1731 DBGMSG("arm_register failed errno: %d \n", retval);
1732 vfree(addr->addr_space_buffer);
1736 free_pending_request(req); /* immediate success or fail */
1740 static int arm_unregister(struct file_info *fi, struct pending_request *req)
1744 struct list_head *entry;
1745 struct arm_addr *addr = NULL;
1746 struct host_info *hi;
1747 struct file_info *fi_hlp = NULL;
1748 struct arm_addr *arm_addr = NULL;
1750 unsigned long flags;
1752 DBGMSG("arm_Unregister called addr(Offset): "
1754 (u32) ((req->req.address >> 32) & 0xFFFF),
1755 (u32) (req->req.address & 0xFFFFFFFF));
1756 spin_lock_irqsave(&host_info_lock, flags);
1758 entry = fi->addr_list.next;
1759 while (entry != &(fi->addr_list)) {
1760 addr = list_entry(entry, struct arm_addr, addr_list);
1761 if (addr->start == req->req.address) {
1765 entry = entry->next;
1768 DBGMSG("arm_Unregister addr not found");
1769 spin_unlock_irqrestore(&host_info_lock, flags);
1772 DBGMSG("arm_Unregister addr found");
1774 /* another host with valid address-entry containing
1775 same addressrange */
1776 list_for_each_entry(hi, &host_info_list, list) {
1777 if (hi->host != fi->host) {
1778 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1779 entry = fi_hlp->addr_list.next;
1780 while (entry != &(fi_hlp->addr_list)) {
1781 arm_addr = list_entry(entry,
1784 if (arm_addr->start == addr->start) {
1785 DBGMSG("another host ownes "
1786 "same addressrange");
1790 entry = entry->next;
1799 DBGMSG("delete entry from list -> success");
1800 list_del(&addr->addr_list);
1801 spin_unlock_irqrestore(&host_info_lock, flags);
1802 vfree(addr->addr_space_buffer);
1804 free_pending_request(req); /* immediate success or fail */
1808 hpsb_unregister_addrspace(&raw1394_highlevel, fi->host,
1811 printk(KERN_ERR "raw1394: arm_Unregister failed -> EINVAL\n");
1812 spin_unlock_irqrestore(&host_info_lock, flags);
1815 DBGMSG("delete entry from list -> success");
1816 list_del(&addr->addr_list);
1817 spin_unlock_irqrestore(&host_info_lock, flags);
1818 vfree(addr->addr_space_buffer);
1820 free_pending_request(req); /* immediate success or fail */
1824 /* Copy data from ARM buffer(s) to user buffer. */
1825 static int arm_get_buf(struct file_info *fi, struct pending_request *req)
1827 struct arm_addr *arm_addr = NULL;
1828 unsigned long flags;
1829 unsigned long offset;
1831 struct list_head *entry;
1833 DBGMSG("arm_get_buf "
1834 "addr(Offset): %04X %08X length: %u",
1835 (u32) ((req->req.address >> 32) & 0xFFFF),
1836 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
1838 spin_lock_irqsave(&host_info_lock, flags);
1839 entry = fi->addr_list.next;
1840 while (entry != &(fi->addr_list)) {
1841 arm_addr = list_entry(entry, struct arm_addr, addr_list);
1842 if ((arm_addr->start <= req->req.address) &&
1843 (arm_addr->end > req->req.address)) {
1844 if (req->req.address + req->req.length <= arm_addr->end) {
1845 offset = req->req.address - arm_addr->start;
1846 spin_unlock_irqrestore(&host_info_lock, flags);
1849 ("arm_get_buf copy_to_user( %08X, %p, %u )",
1850 (u32) req->req.recvb,
1851 arm_addr->addr_space_buffer + offset,
1852 (u32) req->req.length);
1854 (int2ptr(req->req.recvb),
1855 arm_addr->addr_space_buffer + offset,
1859 /* We have to free the request, because we
1860 * queue no response, and therefore nobody
1862 free_pending_request(req);
1865 DBGMSG("arm_get_buf request exceeded mapping");
1866 spin_unlock_irqrestore(&host_info_lock, flags);
1870 entry = entry->next;
1872 spin_unlock_irqrestore(&host_info_lock, flags);
1876 /* Copy data from user buffer to ARM buffer(s). */
1877 static int arm_set_buf(struct file_info *fi, struct pending_request *req)
1879 struct arm_addr *arm_addr = NULL;
1880 unsigned long flags;
1881 unsigned long offset;
1883 struct list_head *entry;
1885 DBGMSG("arm_set_buf "
1886 "addr(Offset): %04X %08X length: %u",
1887 (u32) ((req->req.address >> 32) & 0xFFFF),
1888 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
1890 spin_lock_irqsave(&host_info_lock, flags);
1891 entry = fi->addr_list.next;
1892 while (entry != &(fi->addr_list)) {
1893 arm_addr = list_entry(entry, struct arm_addr, addr_list);
1894 if ((arm_addr->start <= req->req.address) &&
1895 (arm_addr->end > req->req.address)) {
1896 if (req->req.address + req->req.length <= arm_addr->end) {
1897 offset = req->req.address - arm_addr->start;
1898 spin_unlock_irqrestore(&host_info_lock, flags);
1901 ("arm_set_buf copy_from_user( %p, %08X, %u )",
1902 arm_addr->addr_space_buffer + offset,
1903 (u32) req->req.sendb,
1904 (u32) req->req.length);
1906 (arm_addr->addr_space_buffer + offset,
1907 int2ptr(req->req.sendb),
1911 /* We have to free the request, because we
1912 * queue no response, and therefore nobody
1914 free_pending_request(req);
1917 DBGMSG("arm_set_buf request exceeded mapping");
1918 spin_unlock_irqrestore(&host_info_lock, flags);
1922 entry = entry->next;
1924 spin_unlock_irqrestore(&host_info_lock, flags);
1928 static int reset_notification(struct file_info *fi, struct pending_request *req)
1930 DBGMSG("reset_notification called - switch %s ",
1931 (req->req.misc == RAW1394_NOTIFY_OFF) ? "OFF" : "ON");
1932 if ((req->req.misc == RAW1394_NOTIFY_OFF) ||
1933 (req->req.misc == RAW1394_NOTIFY_ON)) {
1934 fi->notification = (u8) req->req.misc;
1935 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
1938 /* error EINVAL (22) invalid argument */
1942 static int write_phypacket(struct file_info *fi, struct pending_request *req)
1944 struct hpsb_packet *packet = NULL;
1947 unsigned long flags;
1949 data = be32_to_cpu((u32) req->req.sendb);
1950 DBGMSG("write_phypacket called - quadlet 0x%8.8x ", data);
1951 packet = hpsb_make_phypacket(fi->host, data);
1954 req->req.length = 0;
1955 req->packet = packet;
1956 hpsb_set_packet_complete_task(packet,
1957 (void (*)(void *))queue_complete_cb, req);
1958 spin_lock_irqsave(&fi->reqlists_lock, flags);
1959 list_add_tail(&req->list, &fi->req_pending);
1960 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
1961 packet->generation = req->req.generation;
1962 retval = hpsb_send_packet(packet);
1963 DBGMSG("write_phypacket send_packet called => retval: %d ", retval);
1965 req->req.error = RAW1394_ERROR_SEND_ERROR;
1966 req->req.length = 0;
1967 queue_complete_req(req);
1972 static int get_config_rom(struct file_info *fi, struct pending_request *req)
1975 quadlet_t *data = kmalloc(req->req.length, GFP_KERNEL);
1982 csr1212_read(fi->host->csr.rom, CSR1212_CONFIG_ROM_SPACE_OFFSET,
1983 data, req->req.length);
1984 if (copy_to_user(int2ptr(req->req.recvb), data, req->req.length))
1987 (int2ptr(req->req.tag), &fi->host->csr.rom->cache_head->len,
1988 sizeof(fi->host->csr.rom->cache_head->len)))
1990 if (copy_to_user(int2ptr(req->req.address), &fi->host->csr.generation,
1991 sizeof(fi->host->csr.generation)))
1993 if (copy_to_user(int2ptr(req->req.sendb), &status, sizeof(status)))
1997 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2002 static int update_config_rom(struct file_info *fi, struct pending_request *req)
2005 quadlet_t *data = kmalloc(req->req.length, GFP_KERNEL);
2008 if (copy_from_user(data, int2ptr(req->req.sendb), req->req.length)) {
2011 int status = hpsb_update_config_rom(fi->host,
2012 data, req->req.length,
2013 (unsigned char)req->req.
2016 (int2ptr(req->req.recvb), &status, sizeof(status)))
2021 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2027 static int modify_config_rom(struct file_info *fi, struct pending_request *req)
2029 struct csr1212_keyval *kv;
2030 struct csr1212_csr_rom_cache *cache;
2031 struct csr1212_dentry *dentry;
2035 if (req->req.misc == ~0) {
2036 if (req->req.length == 0)
2039 /* Find an unused slot */
2041 dr < RAW1394_MAX_USER_CSR_DIRS && fi->csr1212_dirs[dr];
2044 if (dr == RAW1394_MAX_USER_CSR_DIRS)
2047 fi->csr1212_dirs[dr] =
2048 csr1212_new_directory(CSR1212_KV_ID_VENDOR);
2049 if (!fi->csr1212_dirs[dr])
2053 if (!fi->csr1212_dirs[dr])
2056 /* Delete old stuff */
2058 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2059 dentry; dentry = dentry->next) {
2060 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2065 if (req->req.length == 0) {
2066 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2067 fi->csr1212_dirs[dr] = NULL;
2069 hpsb_update_config_rom_image(fi->host);
2070 free_pending_request(req);
2075 cache = csr1212_rom_cache_malloc(0, req->req.length);
2077 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2078 fi->csr1212_dirs[dr] = NULL;
2082 cache->filled_head = kmalloc(sizeof(*cache->filled_head), GFP_KERNEL);
2083 if (!cache->filled_head) {
2084 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2085 fi->csr1212_dirs[dr] = NULL;
2086 CSR1212_FREE(cache);
2089 cache->filled_tail = cache->filled_head;
2091 if (copy_from_user(cache->data, int2ptr(req->req.sendb),
2093 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2094 fi->csr1212_dirs[dr] = NULL;
2097 cache->len = req->req.length;
2098 cache->filled_head->offset_start = 0;
2099 cache->filled_head->offset_end = cache->size - 1;
2101 cache->layout_head = cache->layout_tail = fi->csr1212_dirs[dr];
2103 ret = CSR1212_SUCCESS;
2104 /* parse all the items */
2105 for (kv = cache->layout_head; ret == CSR1212_SUCCESS && kv;
2107 ret = csr1212_parse_keyval(kv, cache);
2110 /* attach top level items to the root directory */
2112 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2113 ret == CSR1212_SUCCESS && dentry; dentry = dentry->next) {
2115 csr1212_attach_keyval_to_directory(fi->host->csr.
2120 if (ret == CSR1212_SUCCESS) {
2121 ret = hpsb_update_config_rom_image(fi->host);
2123 if (ret >= 0 && copy_to_user(int2ptr(req->req.recvb),
2129 kfree(cache->filled_head);
2130 CSR1212_FREE(cache);
2133 /* we have to free the request, because we queue no response,
2134 * and therefore nobody will free it */
2135 free_pending_request(req);
2139 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2140 dentry; dentry = dentry->next) {
2141 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2145 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2146 fi->csr1212_dirs[dr] = NULL;
2151 static int state_connected(struct file_info *fi, struct pending_request *req)
2153 int node = req->req.address >> 48;
2155 req->req.error = RAW1394_ERROR_NONE;
2157 switch (req->req.type) {
2159 case RAW1394_REQ_ECHO:
2160 queue_complete_req(req);
2163 case RAW1394_REQ_ARM_REGISTER:
2164 return arm_register(fi, req);
2166 case RAW1394_REQ_ARM_UNREGISTER:
2167 return arm_unregister(fi, req);
2169 case RAW1394_REQ_ARM_SET_BUF:
2170 return arm_set_buf(fi, req);
2172 case RAW1394_REQ_ARM_GET_BUF:
2173 return arm_get_buf(fi, req);
2175 case RAW1394_REQ_RESET_NOTIFY:
2176 return reset_notification(fi, req);
2178 case RAW1394_REQ_ISO_SEND:
2179 case RAW1394_REQ_ISO_LISTEN:
2180 printk(KERN_DEBUG "raw1394: old iso ABI has been removed\n");
2181 req->req.error = RAW1394_ERROR_COMPAT;
2182 req->req.misc = RAW1394_KERNELAPI_VERSION;
2183 queue_complete_req(req);
2186 case RAW1394_REQ_FCP_LISTEN:
2187 handle_fcp_listen(fi, req);
2190 case RAW1394_REQ_RESET_BUS:
2191 if (req->req.misc == RAW1394_LONG_RESET) {
2192 DBGMSG("busreset called (type: LONG)");
2193 hpsb_reset_bus(fi->host, LONG_RESET);
2194 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2197 if (req->req.misc == RAW1394_SHORT_RESET) {
2198 DBGMSG("busreset called (type: SHORT)");
2199 hpsb_reset_bus(fi->host, SHORT_RESET);
2200 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2203 /* error EINVAL (22) invalid argument */
2205 case RAW1394_REQ_GET_ROM:
2206 return get_config_rom(fi, req);
2208 case RAW1394_REQ_UPDATE_ROM:
2209 return update_config_rom(fi, req);
2211 case RAW1394_REQ_MODIFY_ROM:
2212 return modify_config_rom(fi, req);
2215 if (req->req.generation != get_hpsb_generation(fi->host)) {
2216 req->req.error = RAW1394_ERROR_GENERATION;
2217 req->req.generation = get_hpsb_generation(fi->host);
2218 req->req.length = 0;
2219 queue_complete_req(req);
2223 switch (req->req.type) {
2224 case RAW1394_REQ_PHYPACKET:
2225 return write_phypacket(fi, req);
2226 case RAW1394_REQ_ASYNC_SEND:
2227 return handle_async_send(fi, req);
2230 if (req->req.length == 0) {
2231 req->req.error = RAW1394_ERROR_INVALID_ARG;
2232 queue_complete_req(req);
2236 return handle_async_request(fi, req, node);
2239 static ssize_t raw1394_write(struct file *file, const char __user * buffer,
2240 size_t count, loff_t * offset_is_ignored)
2242 struct file_info *fi = (struct file_info *)file->private_data;
2243 struct pending_request *req;
2244 ssize_t retval = -EBADFD;
2246 #ifdef CONFIG_COMPAT
2247 if (count == sizeof(struct compat_raw1394_req) &&
2248 sizeof(struct compat_raw1394_req) !=
2249 sizeof(struct raw1394_request)) {
2250 buffer = raw1394_compat_write(buffer);
2252 return PTR_ERR(buffer);
2255 if (count != sizeof(struct raw1394_request)) {
2259 req = alloc_pending_request();
2263 req->file_info = fi;
2265 if (copy_from_user(&req->req, buffer, sizeof(struct raw1394_request))) {
2266 free_pending_request(req);
2270 switch (fi->state) {
2272 retval = state_opened(fi, req);
2276 retval = state_initialized(fi, req);
2280 retval = state_connected(fi, req);
2285 free_pending_request(req);
2294 /* rawiso operations */
2296 /* check if any RAW1394_REQ_RAWISO_ACTIVITY event is already in the
2297 * completion queue (reqlists_lock must be taken) */
2298 static inline int __rawiso_event_in_queue(struct file_info *fi)
2300 struct pending_request *req;
2302 list_for_each_entry(req, &fi->req_complete, list)
2303 if (req->req.type == RAW1394_REQ_RAWISO_ACTIVITY)
2309 /* put a RAWISO_ACTIVITY event in the queue, if one isn't there already */
2310 static void queue_rawiso_event(struct file_info *fi)
2312 unsigned long flags;
2314 spin_lock_irqsave(&fi->reqlists_lock, flags);
2316 /* only one ISO activity event may be in the queue */
2317 if (!__rawiso_event_in_queue(fi)) {
2318 struct pending_request *req =
2319 __alloc_pending_request(GFP_ATOMIC);
2322 req->file_info = fi;
2323 req->req.type = RAW1394_REQ_RAWISO_ACTIVITY;
2324 req->req.generation = get_hpsb_generation(fi->host);
2325 __queue_complete_req(req);
2327 /* on allocation failure, signal an overflow */
2328 if (fi->iso_handle) {
2329 atomic_inc(&fi->iso_handle->overflows);
2333 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2336 static void rawiso_activity_cb(struct hpsb_iso *iso)
2338 unsigned long flags;
2339 struct host_info *hi;
2340 struct file_info *fi;
2342 spin_lock_irqsave(&host_info_lock, flags);
2343 hi = find_host_info(iso->host);
2346 list_for_each_entry(fi, &hi->file_info_list, list) {
2347 if (fi->iso_handle == iso)
2348 queue_rawiso_event(fi);
2352 spin_unlock_irqrestore(&host_info_lock, flags);
2355 /* helper function - gather all the kernel iso status bits for returning to user-space */
2356 static void raw1394_iso_fill_status(struct hpsb_iso *iso,
2357 struct raw1394_iso_status *stat)
2359 stat->config.data_buf_size = iso->buf_size;
2360 stat->config.buf_packets = iso->buf_packets;
2361 stat->config.channel = iso->channel;
2362 stat->config.speed = iso->speed;
2363 stat->config.irq_interval = iso->irq_interval;
2364 stat->n_packets = hpsb_iso_n_ready(iso);
2365 stat->overflows = atomic_read(&iso->overflows);
2366 stat->xmit_cycle = iso->xmit_cycle;
2369 static int raw1394_iso_xmit_init(struct file_info *fi, void __user * uaddr)
2371 struct raw1394_iso_status stat;
2376 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2379 fi->iso_handle = hpsb_iso_xmit_init(fi->host,
2380 stat.config.data_buf_size,
2381 stat.config.buf_packets,
2382 stat.config.channel,
2384 stat.config.irq_interval,
2385 rawiso_activity_cb);
2386 if (!fi->iso_handle)
2389 fi->iso_state = RAW1394_ISO_XMIT;
2391 raw1394_iso_fill_status(fi->iso_handle, &stat);
2392 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2395 /* queue an event to get things started */
2396 rawiso_activity_cb(fi->iso_handle);
2401 static int raw1394_iso_recv_init(struct file_info *fi, void __user * uaddr)
2403 struct raw1394_iso_status stat;
2408 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2411 fi->iso_handle = hpsb_iso_recv_init(fi->host,
2412 stat.config.data_buf_size,
2413 stat.config.buf_packets,
2414 stat.config.channel,
2415 stat.config.dma_mode,
2416 stat.config.irq_interval,
2417 rawiso_activity_cb);
2418 if (!fi->iso_handle)
2421 fi->iso_state = RAW1394_ISO_RECV;
2423 raw1394_iso_fill_status(fi->iso_handle, &stat);
2424 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2429 static int raw1394_iso_get_status(struct file_info *fi, void __user * uaddr)
2431 struct raw1394_iso_status stat;
2432 struct hpsb_iso *iso = fi->iso_handle;
2434 raw1394_iso_fill_status(fi->iso_handle, &stat);
2435 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2438 /* reset overflow counter */
2439 atomic_set(&iso->overflows, 0);
2444 /* copy N packet_infos out of the ringbuffer into user-supplied array */
2445 static int raw1394_iso_recv_packets(struct file_info *fi, void __user * uaddr)
2447 struct raw1394_iso_packets upackets;
2448 unsigned int packet = fi->iso_handle->first_packet;
2451 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2454 if (upackets.n_packets > hpsb_iso_n_ready(fi->iso_handle))
2457 /* ensure user-supplied buffer is accessible and big enough */
2458 if (!access_ok(VERIFY_WRITE, upackets.infos,
2459 upackets.n_packets *
2460 sizeof(struct raw1394_iso_packet_info)))
2463 /* copy the packet_infos out */
2464 for (i = 0; i < upackets.n_packets; i++) {
2465 if (__copy_to_user(&upackets.infos[i],
2466 &fi->iso_handle->infos[packet],
2467 sizeof(struct raw1394_iso_packet_info)))
2470 packet = (packet + 1) % fi->iso_handle->buf_packets;
2476 /* copy N packet_infos from user to ringbuffer, and queue them for transmission */
2477 static int raw1394_iso_send_packets(struct file_info *fi, void __user * uaddr)
2479 struct raw1394_iso_packets upackets;
2482 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2485 if (upackets.n_packets >= fi->iso_handle->buf_packets)
2488 if (upackets.n_packets >= hpsb_iso_n_ready(fi->iso_handle))
2491 /* ensure user-supplied buffer is accessible and big enough */
2492 if (!access_ok(VERIFY_READ, upackets.infos,
2493 upackets.n_packets *
2494 sizeof(struct raw1394_iso_packet_info)))
2497 /* copy the infos structs in and queue the packets */
2498 for (i = 0; i < upackets.n_packets; i++) {
2499 struct raw1394_iso_packet_info info;
2501 if (__copy_from_user(&info, &upackets.infos[i],
2502 sizeof(struct raw1394_iso_packet_info)))
2505 rv = hpsb_iso_xmit_queue_packet(fi->iso_handle, info.offset,
2506 info.len, info.tag, info.sy);
2514 static void raw1394_iso_shutdown(struct file_info *fi)
2517 hpsb_iso_shutdown(fi->iso_handle);
2519 fi->iso_handle = NULL;
2520 fi->iso_state = RAW1394_ISO_INACTIVE;
2523 static int raw1394_read_cycle_timer(struct file_info *fi, void __user * uaddr)
2525 struct raw1394_cycle_timer ct;
2528 err = hpsb_read_cycle_timer(fi->host, &ct.cycle_timer, &ct.local_time);
2530 if (copy_to_user(uaddr, &ct, sizeof(ct)))
2535 /* mmap the rawiso xmit/recv buffer */
2536 static int raw1394_mmap(struct file *file, struct vm_area_struct *vma)
2538 struct file_info *fi = file->private_data;
2540 if (fi->iso_state == RAW1394_ISO_INACTIVE)
2543 return dma_region_mmap(&fi->iso_handle->data_buf, file, vma);
2546 /* ioctl is only used for rawiso operations */
2547 static int raw1394_ioctl(struct inode *inode, struct file *file,
2548 unsigned int cmd, unsigned long arg)
2550 struct file_info *fi = file->private_data;
2551 void __user *argp = (void __user *)arg;
2553 switch (fi->iso_state) {
2554 case RAW1394_ISO_INACTIVE:
2556 case RAW1394_IOC_ISO_XMIT_INIT:
2557 return raw1394_iso_xmit_init(fi, argp);
2558 case RAW1394_IOC_ISO_RECV_INIT:
2559 return raw1394_iso_recv_init(fi, argp);
2564 case RAW1394_ISO_RECV:
2566 case RAW1394_IOC_ISO_RECV_START:{
2567 /* copy args from user-space */
2570 (&args[0], argp, sizeof(args)))
2572 return hpsb_iso_recv_start(fi->iso_handle,
2576 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2577 hpsb_iso_stop(fi->iso_handle);
2579 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL:
2580 return hpsb_iso_recv_listen_channel(fi->iso_handle,
2582 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
2583 return hpsb_iso_recv_unlisten_channel(fi->iso_handle,
2585 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:{
2586 /* copy the u64 from user-space */
2588 if (copy_from_user(&mask, argp, sizeof(mask)))
2590 return hpsb_iso_recv_set_channel_mask(fi->
2594 case RAW1394_IOC_ISO_GET_STATUS:
2595 return raw1394_iso_get_status(fi, argp);
2596 case RAW1394_IOC_ISO_RECV_PACKETS:
2597 return raw1394_iso_recv_packets(fi, argp);
2598 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
2599 return hpsb_iso_recv_release_packets(fi->iso_handle,
2601 case RAW1394_IOC_ISO_RECV_FLUSH:
2602 return hpsb_iso_recv_flush(fi->iso_handle);
2603 case RAW1394_IOC_ISO_SHUTDOWN:
2604 raw1394_iso_shutdown(fi);
2606 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2607 queue_rawiso_event(fi);
2611 case RAW1394_ISO_XMIT:
2613 case RAW1394_IOC_ISO_XMIT_START:{
2614 /* copy two ints from user-space */
2617 (&args[0], argp, sizeof(args)))
2619 return hpsb_iso_xmit_start(fi->iso_handle,
2622 case RAW1394_IOC_ISO_XMIT_SYNC:
2623 return hpsb_iso_xmit_sync(fi->iso_handle);
2624 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2625 hpsb_iso_stop(fi->iso_handle);
2627 case RAW1394_IOC_ISO_GET_STATUS:
2628 return raw1394_iso_get_status(fi, argp);
2629 case RAW1394_IOC_ISO_XMIT_PACKETS:
2630 return raw1394_iso_send_packets(fi, argp);
2631 case RAW1394_IOC_ISO_SHUTDOWN:
2632 raw1394_iso_shutdown(fi);
2634 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2635 queue_rawiso_event(fi);
2643 /* state-independent commands */
2645 case RAW1394_IOC_GET_CYCLE_TIMER:
2646 return raw1394_read_cycle_timer(fi, argp);
2654 #ifdef CONFIG_COMPAT
2655 struct raw1394_iso_packets32 {
2657 compat_uptr_t infos;
2658 } __attribute__((packed));
2660 struct raw1394_cycle_timer32 {
2664 #if defined(CONFIG_X86_64) || defined(CONFIG_IA64)
2665 __attribute__((packed))
2669 #define RAW1394_IOC_ISO_RECV_PACKETS32 \
2670 _IOW ('#', 0x25, struct raw1394_iso_packets32)
2671 #define RAW1394_IOC_ISO_XMIT_PACKETS32 \
2672 _IOW ('#', 0x27, struct raw1394_iso_packets32)
2673 #define RAW1394_IOC_GET_CYCLE_TIMER32 \
2674 _IOR ('#', 0x30, struct raw1394_cycle_timer32)
2676 static long raw1394_iso_xmit_recv_packets32(struct file *file, unsigned int cmd,
2677 struct raw1394_iso_packets32 __user *arg)
2679 compat_uptr_t infos32;
2682 struct raw1394_iso_packets __user *dst = compat_alloc_user_space(sizeof(struct raw1394_iso_packets));
2684 if (!copy_in_user(&dst->n_packets, &arg->n_packets, sizeof arg->n_packets) &&
2685 !copy_from_user(&infos32, &arg->infos, sizeof infos32)) {
2686 infos = compat_ptr(infos32);
2687 if (!copy_to_user(&dst->infos, &infos, sizeof infos))
2688 err = raw1394_ioctl(NULL, file, cmd, (unsigned long)dst);
2693 static long raw1394_read_cycle_timer32(struct file_info *fi, void __user * uaddr)
2695 struct raw1394_cycle_timer32 ct;
2698 err = hpsb_read_cycle_timer(fi->host, &ct.cycle_timer, &ct.local_time);
2700 if (copy_to_user(uaddr, &ct, sizeof(ct)))
2705 static long raw1394_compat_ioctl(struct file *file,
2706 unsigned int cmd, unsigned long arg)
2708 struct file_info *fi = file->private_data;
2709 void __user *argp = (void __user *)arg;
2714 /* These requests have same format as long as 'int' has same size. */
2715 case RAW1394_IOC_ISO_RECV_INIT:
2716 case RAW1394_IOC_ISO_RECV_START:
2717 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL:
2718 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
2719 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:
2720 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
2721 case RAW1394_IOC_ISO_RECV_FLUSH:
2722 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2723 case RAW1394_IOC_ISO_XMIT_INIT:
2724 case RAW1394_IOC_ISO_XMIT_START:
2725 case RAW1394_IOC_ISO_XMIT_SYNC:
2726 case RAW1394_IOC_ISO_GET_STATUS:
2727 case RAW1394_IOC_ISO_SHUTDOWN:
2728 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2729 err = raw1394_ioctl(NULL, file, cmd, arg);
2731 /* These request have different format. */
2732 case RAW1394_IOC_ISO_RECV_PACKETS32:
2733 err = raw1394_iso_xmit_recv_packets32(file, RAW1394_IOC_ISO_RECV_PACKETS, argp);
2735 case RAW1394_IOC_ISO_XMIT_PACKETS32:
2736 err = raw1394_iso_xmit_recv_packets32(file, RAW1394_IOC_ISO_XMIT_PACKETS, argp);
2738 case RAW1394_IOC_GET_CYCLE_TIMER32:
2739 err = raw1394_read_cycle_timer32(fi, argp);
2751 static unsigned int raw1394_poll(struct file *file, poll_table * pt)
2753 struct file_info *fi = file->private_data;
2754 unsigned int mask = POLLOUT | POLLWRNORM;
2755 unsigned long flags;
2757 poll_wait(file, &fi->wait_complete, pt);
2759 spin_lock_irqsave(&fi->reqlists_lock, flags);
2760 if (!list_empty(&fi->req_complete)) {
2761 mask |= POLLIN | POLLRDNORM;
2763 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2768 static int raw1394_open(struct inode *inode, struct file *file)
2770 struct file_info *fi;
2772 fi = kzalloc(sizeof(*fi), GFP_KERNEL);
2776 fi->notification = (u8) RAW1394_NOTIFY_ON; /* busreset notification */
2778 INIT_LIST_HEAD(&fi->list);
2780 INIT_LIST_HEAD(&fi->req_pending);
2781 INIT_LIST_HEAD(&fi->req_complete);
2782 spin_lock_init(&fi->reqlists_lock);
2783 init_waitqueue_head(&fi->wait_complete);
2784 INIT_LIST_HEAD(&fi->addr_list);
2786 file->private_data = fi;
2791 static int raw1394_release(struct inode *inode, struct file *file)
2793 struct file_info *fi = file->private_data;
2794 struct list_head *lh;
2795 struct pending_request *req;
2798 struct list_head *entry;
2799 struct arm_addr *addr = NULL;
2800 struct host_info *hi;
2801 struct file_info *fi_hlp = NULL;
2802 struct arm_addr *arm_addr = NULL;
2805 unsigned long flags;
2807 if (fi->iso_state != RAW1394_ISO_INACTIVE)
2808 raw1394_iso_shutdown(fi);
2810 spin_lock_irqsave(&host_info_lock, flags);
2813 /* set address-entries invalid */
2815 while (!list_empty(&fi->addr_list)) {
2817 lh = fi->addr_list.next;
2818 addr = list_entry(lh, struct arm_addr, addr_list);
2819 /* another host with valid address-entry containing
2820 same addressrange? */
2821 list_for_each_entry(hi, &host_info_list, list) {
2822 if (hi->host != fi->host) {
2823 list_for_each_entry(fi_hlp, &hi->file_info_list,
2825 entry = fi_hlp->addr_list.next;
2826 while (entry != &(fi_hlp->addr_list)) {
2827 arm_addr = list_entry(entry, struct
2830 if (arm_addr->start ==
2833 ("raw1394_release: "
2834 "another host ownes "
2835 "same addressrange");
2839 entry = entry->next;
2847 if (!another_host) {
2848 DBGMSG("raw1394_release: call hpsb_arm_unregister");
2850 hpsb_unregister_addrspace(&raw1394_highlevel,
2851 fi->host, addr->start);
2855 "raw1394_release arm_Unregister failed\n");
2858 DBGMSG("raw1394_release: delete addr_entry from list");
2859 list_del(&addr->addr_list);
2860 vfree(addr->addr_space_buffer);
2863 spin_unlock_irqrestore(&host_info_lock, flags);
2865 printk(KERN_ERR "raw1394: during addr_list-release "
2866 "error(s) occurred \n");
2870 /* This locked section guarantees that neither
2871 * complete nor pending requests exist once i!=0 */
2872 spin_lock_irqsave(&fi->reqlists_lock, flags);
2873 while ((req = __next_complete_req(fi)))
2874 free_pending_request(req);
2876 i = list_empty(&fi->req_pending);
2877 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2882 * Sleep until more requests can be freed.
2884 * NB: We call the macro wait_event() with a condition argument
2885 * with side effect. This is only possible because the side
2886 * effect does not occur until the condition became true, and
2887 * wait_event() won't evaluate the condition again after that.
2889 wait_event(fi->wait_complete, (req = next_complete_req(fi)));
2890 free_pending_request(req);
2893 /* Remove any sub-trees left by user space programs */
2894 for (i = 0; i < RAW1394_MAX_USER_CSR_DIRS; i++) {
2895 struct csr1212_dentry *dentry;
2896 if (!fi->csr1212_dirs[i])
2899 fi->csr1212_dirs[i]->value.directory.dentries_head; dentry;
2900 dentry = dentry->next) {
2901 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2905 csr1212_release_keyval(fi->csr1212_dirs[i]);
2906 fi->csr1212_dirs[i] = NULL;
2910 if ((csr_mod || fi->cfgrom_upd)
2911 && hpsb_update_config_rom_image(fi->host) < 0)
2913 ("Failed to generate Configuration ROM image for host %d",
2916 if (fi->state == connected) {
2917 spin_lock_irqsave(&host_info_lock, flags);
2918 list_del(&fi->list);
2919 spin_unlock_irqrestore(&host_info_lock, flags);
2921 put_device(&fi->host->device);
2924 spin_lock_irqsave(&host_info_lock, flags);
2926 module_put(fi->host->driver->owner);
2927 spin_unlock_irqrestore(&host_info_lock, flags);
2934 /*** HOTPLUG STUFF **********************************************************/
2936 * Export information about protocols/devices supported by this driver.
2938 static struct ieee1394_device_id raw1394_id_table[] = {
2940 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2941 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
2942 .version = AVC_SW_VERSION_ENTRY & 0xffffff},
2944 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2945 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2946 .version = CAMERA_SW_VERSION_ENTRY & 0xffffff},
2948 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2949 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2950 .version = (CAMERA_SW_VERSION_ENTRY + 1) & 0xffffff},
2952 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2953 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2954 .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff},
2958 MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table);
2960 static struct hpsb_protocol_driver raw1394_driver = {
2962 .id_table = raw1394_id_table,
2965 /******************************************************************************/
2967 static struct hpsb_highlevel raw1394_highlevel = {
2968 .name = RAW1394_DEVICE_NAME,
2969 .add_host = add_host,
2970 .remove_host = remove_host,
2971 .host_reset = host_reset,
2972 .fcp_request = fcp_request,
2975 static struct cdev raw1394_cdev;
2976 static const struct file_operations raw1394_fops = {
2977 .owner = THIS_MODULE,
2978 .read = raw1394_read,
2979 .write = raw1394_write,
2980 .mmap = raw1394_mmap,
2981 .ioctl = raw1394_ioctl,
2982 #ifdef CONFIG_COMPAT
2983 .compat_ioctl = raw1394_compat_ioctl,
2985 .poll = raw1394_poll,
2986 .open = raw1394_open,
2987 .release = raw1394_release,
2990 static int __init init_raw1394(void)
2994 hpsb_register_highlevel(&raw1394_highlevel);
2998 hpsb_protocol_class, NULL,
2999 MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16),
3000 RAW1394_DEVICE_NAME))) {
3005 cdev_init(&raw1394_cdev, &raw1394_fops);
3006 raw1394_cdev.owner = THIS_MODULE;
3007 kobject_set_name(&raw1394_cdev.kobj, RAW1394_DEVICE_NAME);
3008 ret = cdev_add(&raw1394_cdev, IEEE1394_RAW1394_DEV, 1);
3010 HPSB_ERR("raw1394 failed to register minor device block");
3014 HPSB_INFO("raw1394: /dev/%s device initialized", RAW1394_DEVICE_NAME);
3016 ret = hpsb_register_protocol(&raw1394_driver);
3018 HPSB_ERR("raw1394: failed to register protocol");
3019 cdev_del(&raw1394_cdev);
3026 device_destroy(hpsb_protocol_class,
3027 MKDEV(IEEE1394_MAJOR,
3028 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
3030 hpsb_unregister_highlevel(&raw1394_highlevel);
3035 static void __exit cleanup_raw1394(void)
3037 device_destroy(hpsb_protocol_class,
3038 MKDEV(IEEE1394_MAJOR,
3039 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
3040 cdev_del(&raw1394_cdev);
3041 hpsb_unregister_highlevel(&raw1394_highlevel);
3042 hpsb_unregister_protocol(&raw1394_driver);
3045 module_init(init_raw1394);
3046 module_exit(cleanup_raw1394);
3047 MODULE_LICENSE("GPL");