4 * Raw interface to the bus
6 * Copyright (C) 1999, 2000 Andreas E. Bombe
7 * 2001, 2002 Manfred Weihs <weihs@ict.tuwien.ac.at>
8 * 2002 Christian Toegel <christian.toegel@gmx.at>
10 * This code is licensed under the GPL. See the file COPYING in the root
11 * directory of the kernel sources for details.
16 * Manfred Weihs <weihs@ict.tuwien.ac.at>
17 * configuration ROM manipulation
18 * address range mapping
19 * adaptation for new (transparent) loopback mechanism
20 * sending of arbitrary async packets
21 * Christian Toegel <christian.toegel@gmx.at>
22 * address range mapping
24 * transmit physical packet
25 * busreset notification control (switch on/off)
26 * busreset with selection of type (short/long)
30 #include <linux/kernel.h>
31 #include <linux/list.h>
32 #include <linux/string.h>
33 #include <linux/slab.h>
35 #include <linux/poll.h>
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/smp_lock.h>
39 #include <linux/interrupt.h>
40 #include <linux/vmalloc.h>
41 #include <linux/cdev.h>
42 #include <asm/uaccess.h>
43 #include <asm/atomic.h>
44 #include <linux/devfs_fs_kernel.h>
48 #include "ieee1394_types.h"
49 #include "ieee1394_core.h"
52 #include "highlevel.h"
54 #include "ieee1394_transactions.h"
56 #include "raw1394-private.h"
58 #define int2ptr(x) ((void __user *)(unsigned long)x)
59 #define ptr2int(x) ((u64)(unsigned long)(void __user *)x)
61 #ifdef CONFIG_IEEE1394_VERBOSEDEBUG
66 #define DBGMSG(fmt, args...) \
67 printk(KERN_INFO "raw1394:" fmt "\n" , ## args)
69 #define DBGMSG(fmt, args...)
72 static LIST_HEAD(host_info_list);
73 static int host_count;
74 static DEFINE_SPINLOCK(host_info_lock);
75 static atomic_t internal_generation = ATOMIC_INIT(0);
77 static atomic_t iso_buffer_size;
78 static const int iso_buffer_max = 4 * 1024 * 1024; /* 4 MB */
80 static struct hpsb_highlevel raw1394_highlevel;
82 static int arm_read(struct hpsb_host *host, int nodeid, quadlet_t * buffer,
83 u64 addr, size_t length, u16 flags);
84 static int arm_write(struct hpsb_host *host, int nodeid, int destid,
85 quadlet_t * data, u64 addr, size_t length, u16 flags);
86 static int arm_lock(struct hpsb_host *host, int nodeid, quadlet_t * store,
87 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
89 static int arm_lock64(struct hpsb_host *host, int nodeid, octlet_t * store,
90 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
92 static struct hpsb_address_ops arm_ops = {
99 static void queue_complete_cb(struct pending_request *req);
101 static struct pending_request *__alloc_pending_request(gfp_t flags)
103 struct pending_request *req;
105 req = (struct pending_request *)kmalloc(sizeof(struct pending_request),
108 memset(req, 0, sizeof(struct pending_request));
109 INIT_LIST_HEAD(&req->list);
115 static inline struct pending_request *alloc_pending_request(void)
117 return __alloc_pending_request(SLAB_KERNEL);
120 static void free_pending_request(struct pending_request *req)
123 if (atomic_dec_and_test(&req->ibs->refcount)) {
124 atomic_sub(req->ibs->data_size, &iso_buffer_size);
127 } else if (req->free_data) {
130 hpsb_free_packet(req->packet);
134 /* fi->reqlists_lock must be taken */
135 static void __queue_complete_req(struct pending_request *req)
137 struct file_info *fi = req->file_info;
138 list_del(&req->list);
139 list_add_tail(&req->list, &fi->req_complete);
141 up(&fi->complete_sem);
142 wake_up_interruptible(&fi->poll_wait_complete);
145 static void queue_complete_req(struct pending_request *req)
148 struct file_info *fi = req->file_info;
150 spin_lock_irqsave(&fi->reqlists_lock, flags);
151 __queue_complete_req(req);
152 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
155 static void queue_complete_cb(struct pending_request *req)
157 struct hpsb_packet *packet = req->packet;
158 int rcode = (packet->header[1] >> 12) & 0xf;
160 switch (packet->ack_code) {
162 case ACKX_SEND_ERROR:
163 req->req.error = RAW1394_ERROR_SEND_ERROR;
166 req->req.error = RAW1394_ERROR_ABORTED;
169 req->req.error = RAW1394_ERROR_TIMEOUT;
172 req->req.error = (packet->ack_code << 16) | rcode;
176 if (!((packet->ack_code == ACK_PENDING) && (rcode == RCODE_COMPLETE))) {
180 if ((req->req.type == RAW1394_REQ_ASYNC_READ) ||
181 (req->req.type == RAW1394_REQ_ASYNC_WRITE) ||
182 (req->req.type == RAW1394_REQ_ASYNC_STREAM) ||
183 (req->req.type == RAW1394_REQ_LOCK) ||
184 (req->req.type == RAW1394_REQ_LOCK64))
185 hpsb_free_tlabel(packet);
187 queue_complete_req(req);
190 static void add_host(struct hpsb_host *host)
192 struct host_info *hi;
195 hi = (struct host_info *)kmalloc(sizeof(struct host_info), GFP_KERNEL);
198 INIT_LIST_HEAD(&hi->list);
200 INIT_LIST_HEAD(&hi->file_info_list);
202 spin_lock_irqsave(&host_info_lock, flags);
203 list_add_tail(&hi->list, &host_info_list);
205 spin_unlock_irqrestore(&host_info_lock, flags);
208 atomic_inc(&internal_generation);
211 static struct host_info *find_host_info(struct hpsb_host *host)
213 struct host_info *hi;
215 list_for_each_entry(hi, &host_info_list, list)
216 if (hi->host == host)
222 static void remove_host(struct hpsb_host *host)
224 struct host_info *hi;
227 spin_lock_irqsave(&host_info_lock, flags);
228 hi = find_host_info(host);
234 FIXME: address ranges should be removed
235 and fileinfo states should be initialized
236 (including setting generation to
237 internal-generation ...)
240 spin_unlock_irqrestore(&host_info_lock, flags);
243 printk(KERN_ERR "raw1394: attempt to remove unknown host "
250 atomic_inc(&internal_generation);
253 static void host_reset(struct hpsb_host *host)
256 struct host_info *hi;
257 struct file_info *fi;
258 struct pending_request *req;
260 spin_lock_irqsave(&host_info_lock, flags);
261 hi = find_host_info(host);
264 list_for_each_entry(fi, &hi->file_info_list, list) {
265 if (fi->notification == RAW1394_NOTIFY_ON) {
266 req = __alloc_pending_request(SLAB_ATOMIC);
270 req->req.type = RAW1394_REQ_BUS_RESET;
271 req->req.generation =
272 get_hpsb_generation(host);
273 req->req.misc = (host->node_id << 16)
275 if (fi->protocol_version > 3) {
282 queue_complete_req(req);
287 spin_unlock_irqrestore(&host_info_lock, flags);
290 static void iso_receive(struct hpsb_host *host, int channel, quadlet_t * data,
294 struct host_info *hi;
295 struct file_info *fi;
296 struct pending_request *req, *req_next;
297 struct iso_block_store *ibs = NULL;
300 if ((atomic_read(&iso_buffer_size) + length) > iso_buffer_max) {
301 HPSB_INFO("dropped iso packet");
305 spin_lock_irqsave(&host_info_lock, flags);
306 hi = find_host_info(host);
309 list_for_each_entry(fi, &hi->file_info_list, list) {
310 if (!(fi->listen_channels & (1ULL << channel)))
313 req = __alloc_pending_request(SLAB_ATOMIC);
318 ibs = kmalloc(sizeof(struct iso_block_store)
319 + length, SLAB_ATOMIC);
325 atomic_add(length, &iso_buffer_size);
326 atomic_set(&ibs->refcount, 0);
327 ibs->data_size = length;
328 memcpy(ibs->data, data, length);
331 atomic_inc(&ibs->refcount);
335 req->data = ibs->data;
336 req->req.type = RAW1394_REQ_ISO_RECEIVE;
337 req->req.generation = get_hpsb_generation(host);
339 req->req.recvb = ptr2int(fi->iso_buffer);
340 req->req.length = min(length, fi->iso_buffer_length);
342 list_add_tail(&req->list, &reqs);
345 spin_unlock_irqrestore(&host_info_lock, flags);
347 list_for_each_entry_safe(req, req_next, &reqs, list)
348 queue_complete_req(req);
351 static void fcp_request(struct hpsb_host *host, int nodeid, int direction,
352 int cts, u8 * data, size_t length)
355 struct host_info *hi;
356 struct file_info *fi;
357 struct pending_request *req, *req_next;
358 struct iso_block_store *ibs = NULL;
361 if ((atomic_read(&iso_buffer_size) + length) > iso_buffer_max) {
362 HPSB_INFO("dropped fcp request");
366 spin_lock_irqsave(&host_info_lock, flags);
367 hi = find_host_info(host);
370 list_for_each_entry(fi, &hi->file_info_list, list) {
374 req = __alloc_pending_request(SLAB_ATOMIC);
379 ibs = kmalloc(sizeof(struct iso_block_store)
380 + length, SLAB_ATOMIC);
386 atomic_add(length, &iso_buffer_size);
387 atomic_set(&ibs->refcount, 0);
388 ibs->data_size = length;
389 memcpy(ibs->data, data, length);
392 atomic_inc(&ibs->refcount);
396 req->data = ibs->data;
397 req->req.type = RAW1394_REQ_FCP_REQUEST;
398 req->req.generation = get_hpsb_generation(host);
399 req->req.misc = nodeid | (direction << 16);
400 req->req.recvb = ptr2int(fi->fcp_buffer);
401 req->req.length = length;
403 list_add_tail(&req->list, &reqs);
406 spin_unlock_irqrestore(&host_info_lock, flags);
408 list_for_each_entry_safe(req, req_next, &reqs, list)
409 queue_complete_req(req);
412 static ssize_t raw1394_read(struct file *file, char __user * buffer,
413 size_t count, loff_t * offset_is_ignored)
416 struct file_info *fi = (struct file_info *)file->private_data;
417 struct list_head *lh;
418 struct pending_request *req;
421 if (count != sizeof(struct raw1394_request)) {
425 if (!access_ok(VERIFY_WRITE, buffer, count)) {
429 if (file->f_flags & O_NONBLOCK) {
430 if (down_trylock(&fi->complete_sem)) {
434 if (down_interruptible(&fi->complete_sem)) {
439 spin_lock_irqsave(&fi->reqlists_lock, flags);
440 lh = fi->req_complete.next;
442 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
444 req = list_entry(lh, struct pending_request, list);
446 if (req->req.length) {
447 if (copy_to_user(int2ptr(req->req.recvb), req->data,
449 req->req.error = RAW1394_ERROR_MEMFAULT;
452 if (copy_to_user(buffer, &req->req, sizeof(req->req))) {
457 ret = (ssize_t) sizeof(struct raw1394_request);
459 free_pending_request(req);
463 static int state_opened(struct file_info *fi, struct pending_request *req)
465 if (req->req.type == RAW1394_REQ_INITIALIZE) {
466 switch (req->req.misc) {
467 case RAW1394_KERNELAPI_VERSION:
469 fi->state = initialized;
470 fi->protocol_version = req->req.misc;
471 req->req.error = RAW1394_ERROR_NONE;
472 req->req.generation = atomic_read(&internal_generation);
476 req->req.error = RAW1394_ERROR_COMPAT;
477 req->req.misc = RAW1394_KERNELAPI_VERSION;
480 req->req.error = RAW1394_ERROR_STATE_ORDER;
484 queue_complete_req(req);
485 return sizeof(struct raw1394_request);
488 static int state_initialized(struct file_info *fi, struct pending_request *req)
491 struct host_info *hi;
492 struct raw1394_khost_list *khl;
494 if (req->req.generation != atomic_read(&internal_generation)) {
495 req->req.error = RAW1394_ERROR_GENERATION;
496 req->req.generation = atomic_read(&internal_generation);
498 queue_complete_req(req);
499 return sizeof(struct raw1394_request);
502 switch (req->req.type) {
503 case RAW1394_REQ_LIST_CARDS:
504 spin_lock_irqsave(&host_info_lock, flags);
505 khl = kmalloc(sizeof(struct raw1394_khost_list) * host_count,
509 req->req.misc = host_count;
510 req->data = (quadlet_t *) khl;
512 list_for_each_entry(hi, &host_info_list, list) {
513 khl->nodes = hi->host->node_count;
514 strcpy(khl->name, hi->host->driver->name);
518 spin_unlock_irqrestore(&host_info_lock, flags);
521 req->req.error = RAW1394_ERROR_NONE;
522 req->req.length = min(req->req.length,
524 (struct raw1394_khost_list)
532 case RAW1394_REQ_SET_CARD:
533 spin_lock_irqsave(&host_info_lock, flags);
534 if (req->req.misc < host_count) {
535 list_for_each_entry(hi, &host_info_list, list) {
536 if (!req->req.misc--)
539 get_device(&hi->host->device); // XXX Need to handle failure case
540 list_add_tail(&fi->list, &hi->file_info_list);
542 fi->state = connected;
544 req->req.error = RAW1394_ERROR_NONE;
545 req->req.generation = get_hpsb_generation(fi->host);
546 req->req.misc = (fi->host->node_id << 16)
547 | fi->host->node_count;
548 if (fi->protocol_version > 3) {
550 NODEID_TO_NODE(fi->host->irm_id) << 8;
553 req->req.error = RAW1394_ERROR_INVALID_ARG;
555 spin_unlock_irqrestore(&host_info_lock, flags);
561 req->req.error = RAW1394_ERROR_STATE_ORDER;
566 queue_complete_req(req);
567 return sizeof(struct raw1394_request);
570 static void handle_iso_listen(struct file_info *fi, struct pending_request *req)
572 int channel = req->req.misc;
574 if ((channel > 63) || (channel < -64)) {
575 req->req.error = RAW1394_ERROR_INVALID_ARG;
576 } else if (channel >= 0) {
577 /* allocate channel req.misc */
578 if (fi->listen_channels & (1ULL << channel)) {
579 req->req.error = RAW1394_ERROR_ALREADY;
581 if (hpsb_listen_channel
582 (&raw1394_highlevel, fi->host, channel)) {
583 req->req.error = RAW1394_ERROR_ALREADY;
585 fi->listen_channels |= 1ULL << channel;
586 fi->iso_buffer = int2ptr(req->req.recvb);
587 fi->iso_buffer_length = req->req.length;
591 /* deallocate channel (one's complement neg) req.misc */
594 if (fi->listen_channels & (1ULL << channel)) {
595 hpsb_unlisten_channel(&raw1394_highlevel, fi->host,
597 fi->listen_channels &= ~(1ULL << channel);
599 req->req.error = RAW1394_ERROR_INVALID_ARG;
604 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);
759 return sizeof(struct raw1394_request);
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);
777 return sizeof(struct raw1394_request);
780 static int handle_iso_send(struct file_info *fi, struct pending_request *req,
784 struct hpsb_packet *packet;
786 packet = hpsb_make_isopacket(fi->host, req->req.length, channel & 0x3f,
787 (req->req.misc >> 16) & 0x3,
788 req->req.misc & 0xf);
792 packet->speed_code = req->req.address & 0x3;
794 req->packet = packet;
796 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
798 req->req.error = RAW1394_ERROR_MEMFAULT;
800 queue_complete_req(req);
801 return sizeof(struct raw1394_request);
805 hpsb_set_packet_complete_task(packet,
806 (void (*)(void *))queue_complete_req,
809 spin_lock_irqsave(&fi->reqlists_lock, flags);
810 list_add_tail(&req->list, &fi->req_pending);
811 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
813 /* Update the generation of the packet just before sending. */
814 packet->generation = req->req.generation;
816 if (hpsb_send_packet(packet) < 0) {
817 req->req.error = RAW1394_ERROR_SEND_ERROR;
818 queue_complete_req(req);
821 return sizeof(struct raw1394_request);
824 static int handle_async_send(struct file_info *fi, struct pending_request *req)
827 struct hpsb_packet *packet;
828 int header_length = req->req.misc & 0xffff;
829 int expect_response = req->req.misc >> 16;
831 if ((header_length > req->req.length) || (header_length < 12)) {
832 req->req.error = RAW1394_ERROR_INVALID_ARG;
834 queue_complete_req(req);
835 return sizeof(struct raw1394_request);
838 packet = hpsb_alloc_packet(req->req.length - header_length);
839 req->packet = packet;
843 if (copy_from_user(packet->header, int2ptr(req->req.sendb),
845 req->req.error = RAW1394_ERROR_MEMFAULT;
847 queue_complete_req(req);
848 return sizeof(struct raw1394_request);
852 (packet->data, int2ptr(req->req.sendb) + header_length,
853 packet->data_size)) {
854 req->req.error = RAW1394_ERROR_MEMFAULT;
856 queue_complete_req(req);
857 return sizeof(struct raw1394_request);
860 packet->type = hpsb_async;
861 packet->node_id = packet->header[0] >> 16;
862 packet->tcode = (packet->header[0] >> 4) & 0xf;
863 packet->tlabel = (packet->header[0] >> 10) & 0x3f;
864 packet->host = fi->host;
865 packet->expect_response = expect_response;
866 packet->header_size = header_length;
867 packet->data_size = req->req.length - header_length;
870 hpsb_set_packet_complete_task(packet,
871 (void (*)(void *))queue_complete_cb, req);
873 spin_lock_irqsave(&fi->reqlists_lock, flags);
874 list_add_tail(&req->list, &fi->req_pending);
875 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
877 /* Update the generation of the packet just before sending. */
878 packet->generation = req->req.generation;
880 if (hpsb_send_packet(packet) < 0) {
881 req->req.error = RAW1394_ERROR_SEND_ERROR;
882 queue_complete_req(req);
885 return sizeof(struct raw1394_request);
888 static int arm_read(struct hpsb_host *host, int nodeid, quadlet_t * buffer,
889 u64 addr, size_t length, u16 flags)
891 unsigned long irqflags;
892 struct pending_request *req;
893 struct host_info *hi;
894 struct file_info *fi = NULL;
895 struct list_head *entry;
896 struct arm_addr *arm_addr = NULL;
897 struct arm_request *arm_req = NULL;
898 struct arm_response *arm_resp = NULL;
899 int found = 0, size = 0, rcode = -1;
900 struct arm_request_response *arm_req_resp = NULL;
902 DBGMSG("arm_read called by node: %X"
903 "addr: %4.4x %8.8x length: %Zu", nodeid,
904 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
906 spin_lock_irqsave(&host_info_lock, irqflags);
907 hi = find_host_info(host); /* search address-entry */
909 list_for_each_entry(fi, &hi->file_info_list, list) {
910 entry = fi->addr_list.next;
911 while (entry != &(fi->addr_list)) {
913 list_entry(entry, struct arm_addr,
915 if (((arm_addr->start) <= (addr))
916 && ((arm_addr->end) >= (addr + length))) {
929 printk(KERN_ERR "raw1394: arm_read FAILED addr_entry not found"
930 " -> rcode_address_error\n");
931 spin_unlock_irqrestore(&host_info_lock, irqflags);
932 return (RCODE_ADDRESS_ERROR);
934 DBGMSG("arm_read addr_entry FOUND");
936 if (arm_addr->rec_length < length) {
937 DBGMSG("arm_read blocklength too big -> rcode_data_error");
938 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
941 if (arm_addr->access_rights & ARM_READ) {
942 if (!(arm_addr->client_transactions & ARM_READ)) {
944 (arm_addr->addr_space_buffer) + (addr -
948 DBGMSG("arm_read -> (rcode_complete)");
949 rcode = RCODE_COMPLETE;
952 rcode = RCODE_TYPE_ERROR; /* function not allowed */
953 DBGMSG("arm_read -> rcode_type_error (access denied)");
956 if (arm_addr->notification_options & ARM_READ) {
957 DBGMSG("arm_read -> entering notification-section");
958 req = __alloc_pending_request(SLAB_ATOMIC);
960 DBGMSG("arm_read -> rcode_conflict_error");
961 spin_unlock_irqrestore(&host_info_lock, irqflags);
962 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
963 The request may be retried */
965 if (rcode == RCODE_COMPLETE) {
967 sizeof(struct arm_request) +
968 sizeof(struct arm_response) +
969 length * sizeof(byte_t) +
970 sizeof(struct arm_request_response);
973 sizeof(struct arm_request) +
974 sizeof(struct arm_response) +
975 sizeof(struct arm_request_response);
977 req->data = kmalloc(size, SLAB_ATOMIC);
979 free_pending_request(req);
980 DBGMSG("arm_read -> rcode_conflict_error");
981 spin_unlock_irqrestore(&host_info_lock, irqflags);
982 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
983 The request may be retried */
987 req->req.type = RAW1394_REQ_ARM;
988 req->req.generation = get_hpsb_generation(host);
990 (((length << 16) & (0xFFFF0000)) | (ARM_READ & 0xFF));
991 req->req.tag = arm_addr->arm_tag;
992 req->req.recvb = arm_addr->recvb;
993 req->req.length = size;
994 arm_req_resp = (struct arm_request_response *)(req->data);
995 arm_req = (struct arm_request *)((byte_t *) (req->data) +
998 arm_request_response)));
1000 (struct arm_response *)((byte_t *) (arm_req) +
1001 (sizeof(struct arm_request)));
1002 arm_req->buffer = NULL;
1003 arm_resp->buffer = NULL;
1004 if (rcode == RCODE_COMPLETE) {
1006 (byte_t *) arm_resp + sizeof(struct arm_response);
1008 (arm_addr->addr_space_buffer) + (addr -
1013 int2ptr((arm_addr->recvb) +
1014 sizeof(struct arm_request_response) +
1015 sizeof(struct arm_request) +
1016 sizeof(struct arm_response));
1018 arm_resp->buffer_length =
1019 (rcode == RCODE_COMPLETE) ? length : 0;
1020 arm_resp->response_code = rcode;
1021 arm_req->buffer_length = 0;
1022 arm_req->generation = req->req.generation;
1023 arm_req->extended_transaction_code = 0;
1024 arm_req->destination_offset = addr;
1025 arm_req->source_nodeid = nodeid;
1026 arm_req->destination_nodeid = host->node_id;
1027 arm_req->tlabel = (flags >> 10) & 0x3f;
1028 arm_req->tcode = (flags >> 4) & 0x0f;
1029 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1031 arm_request_response));
1032 arm_req_resp->response =
1033 int2ptr((arm_addr->recvb) +
1034 sizeof(struct arm_request_response) +
1035 sizeof(struct arm_request));
1036 queue_complete_req(req);
1038 spin_unlock_irqrestore(&host_info_lock, irqflags);
1042 static int arm_write(struct hpsb_host *host, int nodeid, int destid,
1043 quadlet_t * data, u64 addr, size_t length, u16 flags)
1045 unsigned long irqflags;
1046 struct pending_request *req;
1047 struct host_info *hi;
1048 struct file_info *fi = NULL;
1049 struct list_head *entry;
1050 struct arm_addr *arm_addr = NULL;
1051 struct arm_request *arm_req = NULL;
1052 struct arm_response *arm_resp = NULL;
1053 int found = 0, size = 0, rcode = -1, length_conflict = 0;
1054 struct arm_request_response *arm_req_resp = NULL;
1056 DBGMSG("arm_write called by node: %X"
1057 "addr: %4.4x %8.8x length: %Zu", nodeid,
1058 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
1060 spin_lock_irqsave(&host_info_lock, irqflags);
1061 hi = find_host_info(host); /* search address-entry */
1063 list_for_each_entry(fi, &hi->file_info_list, list) {
1064 entry = fi->addr_list.next;
1065 while (entry != &(fi->addr_list)) {
1067 list_entry(entry, struct arm_addr,
1069 if (((arm_addr->start) <= (addr))
1070 && ((arm_addr->end) >= (addr + length))) {
1074 entry = entry->next;
1083 printk(KERN_ERR "raw1394: arm_write FAILED addr_entry not found"
1084 " -> rcode_address_error\n");
1085 spin_unlock_irqrestore(&host_info_lock, irqflags);
1086 return (RCODE_ADDRESS_ERROR);
1088 DBGMSG("arm_write addr_entry FOUND");
1090 if (arm_addr->rec_length < length) {
1091 DBGMSG("arm_write blocklength too big -> rcode_data_error");
1092 length_conflict = 1;
1093 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
1096 if (arm_addr->access_rights & ARM_WRITE) {
1097 if (!(arm_addr->client_transactions & ARM_WRITE)) {
1098 memcpy((arm_addr->addr_space_buffer) +
1099 (addr - (arm_addr->start)), data,
1101 DBGMSG("arm_write -> (rcode_complete)");
1102 rcode = RCODE_COMPLETE;
1105 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1106 DBGMSG("arm_write -> rcode_type_error (access denied)");
1109 if (arm_addr->notification_options & ARM_WRITE) {
1110 DBGMSG("arm_write -> entering notification-section");
1111 req = __alloc_pending_request(SLAB_ATOMIC);
1113 DBGMSG("arm_write -> rcode_conflict_error");
1114 spin_unlock_irqrestore(&host_info_lock, irqflags);
1115 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1116 The request my be retried */
1119 sizeof(struct arm_request) + sizeof(struct arm_response) +
1120 (length) * sizeof(byte_t) +
1121 sizeof(struct arm_request_response);
1122 req->data = kmalloc(size, SLAB_ATOMIC);
1124 free_pending_request(req);
1125 DBGMSG("arm_write -> rcode_conflict_error");
1126 spin_unlock_irqrestore(&host_info_lock, irqflags);
1127 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1128 The request may be retried */
1131 req->file_info = fi;
1132 req->req.type = RAW1394_REQ_ARM;
1133 req->req.generation = get_hpsb_generation(host);
1135 (((length << 16) & (0xFFFF0000)) | (ARM_WRITE & 0xFF));
1136 req->req.tag = arm_addr->arm_tag;
1137 req->req.recvb = arm_addr->recvb;
1138 req->req.length = size;
1139 arm_req_resp = (struct arm_request_response *)(req->data);
1140 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1143 arm_request_response)));
1145 (struct arm_response *)((byte_t *) (arm_req) +
1146 (sizeof(struct arm_request)));
1147 arm_resp->buffer = NULL;
1148 memcpy((byte_t *) arm_resp + sizeof(struct arm_response),
1150 arm_req->buffer = int2ptr((arm_addr->recvb) +
1151 sizeof(struct arm_request_response) +
1152 sizeof(struct arm_request) +
1153 sizeof(struct arm_response));
1154 arm_req->buffer_length = length;
1155 arm_req->generation = req->req.generation;
1156 arm_req->extended_transaction_code = 0;
1157 arm_req->destination_offset = addr;
1158 arm_req->source_nodeid = nodeid;
1159 arm_req->destination_nodeid = destid;
1160 arm_req->tlabel = (flags >> 10) & 0x3f;
1161 arm_req->tcode = (flags >> 4) & 0x0f;
1162 arm_resp->buffer_length = 0;
1163 arm_resp->response_code = rcode;
1164 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1166 arm_request_response));
1167 arm_req_resp->response =
1168 int2ptr((arm_addr->recvb) +
1169 sizeof(struct arm_request_response) +
1170 sizeof(struct arm_request));
1171 queue_complete_req(req);
1173 spin_unlock_irqrestore(&host_info_lock, irqflags);
1177 static int arm_lock(struct hpsb_host *host, int nodeid, quadlet_t * store,
1178 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
1181 unsigned long irqflags;
1182 struct pending_request *req;
1183 struct host_info *hi;
1184 struct file_info *fi = NULL;
1185 struct list_head *entry;
1186 struct arm_addr *arm_addr = NULL;
1187 struct arm_request *arm_req = NULL;
1188 struct arm_response *arm_resp = NULL;
1189 int found = 0, size = 0, rcode = -1;
1191 struct arm_request_response *arm_req_resp = NULL;
1193 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1194 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1195 DBGMSG("arm_lock called by node: %X "
1196 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X",
1197 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1198 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1201 DBGMSG("arm_lock called by node: %X "
1202 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X arg: %8.8X",
1203 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1204 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1205 be32_to_cpu(data), be32_to_cpu(arg));
1207 spin_lock_irqsave(&host_info_lock, irqflags);
1208 hi = find_host_info(host); /* search address-entry */
1210 list_for_each_entry(fi, &hi->file_info_list, list) {
1211 entry = fi->addr_list.next;
1212 while (entry != &(fi->addr_list)) {
1214 list_entry(entry, struct arm_addr,
1216 if (((arm_addr->start) <= (addr))
1217 && ((arm_addr->end) >=
1218 (addr + sizeof(*store)))) {
1222 entry = entry->next;
1231 printk(KERN_ERR "raw1394: arm_lock FAILED addr_entry not found"
1232 " -> rcode_address_error\n");
1233 spin_unlock_irqrestore(&host_info_lock, irqflags);
1234 return (RCODE_ADDRESS_ERROR);
1236 DBGMSG("arm_lock addr_entry FOUND");
1239 if (arm_addr->access_rights & ARM_LOCK) {
1240 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1242 (arm_addr->addr_space_buffer) + (addr -
1246 switch (ext_tcode) {
1247 case (EXTCODE_MASK_SWAP):
1248 new = data | (old & ~arg);
1250 case (EXTCODE_COMPARE_SWAP):
1257 case (EXTCODE_FETCH_ADD):
1259 cpu_to_be32(be32_to_cpu(data) +
1262 case (EXTCODE_LITTLE_ADD):
1264 cpu_to_le32(le32_to_cpu(data) +
1267 case (EXTCODE_BOUNDED_ADD):
1270 cpu_to_be32(be32_to_cpu
1278 case (EXTCODE_WRAP_ADD):
1281 cpu_to_be32(be32_to_cpu
1290 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1292 "raw1394: arm_lock FAILED "
1293 "ext_tcode not allowed -> rcode_type_error\n");
1297 DBGMSG("arm_lock -> (rcode_complete)");
1298 rcode = RCODE_COMPLETE;
1299 memcpy(store, &old, sizeof(*store));
1300 memcpy((arm_addr->addr_space_buffer) +
1301 (addr - (arm_addr->start)),
1302 &new, sizeof(*store));
1306 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1307 DBGMSG("arm_lock -> rcode_type_error (access denied)");
1310 if (arm_addr->notification_options & ARM_LOCK) {
1311 byte_t *buf1, *buf2;
1312 DBGMSG("arm_lock -> entering notification-section");
1313 req = __alloc_pending_request(SLAB_ATOMIC);
1315 DBGMSG("arm_lock -> rcode_conflict_error");
1316 spin_unlock_irqrestore(&host_info_lock, irqflags);
1317 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1318 The request may be retried */
1320 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1321 req->data = kmalloc(size, SLAB_ATOMIC);
1323 free_pending_request(req);
1324 DBGMSG("arm_lock -> rcode_conflict_error");
1325 spin_unlock_irqrestore(&host_info_lock, irqflags);
1326 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1327 The request may be retried */
1330 arm_req_resp = (struct arm_request_response *)(req->data);
1331 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1334 arm_request_response)));
1336 (struct arm_response *)((byte_t *) (arm_req) +
1337 (sizeof(struct arm_request)));
1338 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1339 buf2 = buf1 + 2 * sizeof(*store);
1340 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1341 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1342 arm_req->buffer_length = sizeof(*store);
1343 memcpy(buf1, &data, sizeof(*store));
1346 arm_req->buffer_length = 2 * sizeof(*store);
1347 memcpy(buf1, &arg, sizeof(*store));
1348 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1350 if (rcode == RCODE_COMPLETE) {
1351 arm_resp->buffer_length = sizeof(*store);
1352 memcpy(buf2, &old, sizeof(*store));
1354 arm_resp->buffer_length = 0;
1356 req->file_info = fi;
1357 req->req.type = RAW1394_REQ_ARM;
1358 req->req.generation = get_hpsb_generation(host);
1359 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1361 req->req.tag = arm_addr->arm_tag;
1362 req->req.recvb = arm_addr->recvb;
1363 req->req.length = size;
1364 arm_req->generation = req->req.generation;
1365 arm_req->extended_transaction_code = ext_tcode;
1366 arm_req->destination_offset = addr;
1367 arm_req->source_nodeid = nodeid;
1368 arm_req->destination_nodeid = host->node_id;
1369 arm_req->tlabel = (flags >> 10) & 0x3f;
1370 arm_req->tcode = (flags >> 4) & 0x0f;
1371 arm_resp->response_code = rcode;
1372 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1374 arm_request_response));
1375 arm_req_resp->response =
1376 int2ptr((arm_addr->recvb) +
1377 sizeof(struct arm_request_response) +
1378 sizeof(struct arm_request));
1380 int2ptr((arm_addr->recvb) +
1381 sizeof(struct arm_request_response) +
1382 sizeof(struct arm_request) +
1383 sizeof(struct arm_response));
1385 int2ptr((arm_addr->recvb) +
1386 sizeof(struct arm_request_response) +
1387 sizeof(struct arm_request) +
1388 sizeof(struct arm_response) + 2 * sizeof(*store));
1389 queue_complete_req(req);
1391 spin_unlock_irqrestore(&host_info_lock, irqflags);
1395 static int arm_lock64(struct hpsb_host *host, int nodeid, octlet_t * store,
1396 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
1399 unsigned long irqflags;
1400 struct pending_request *req;
1401 struct host_info *hi;
1402 struct file_info *fi = NULL;
1403 struct list_head *entry;
1404 struct arm_addr *arm_addr = NULL;
1405 struct arm_request *arm_req = NULL;
1406 struct arm_response *arm_resp = NULL;
1407 int found = 0, size = 0, rcode = -1;
1409 struct arm_request_response *arm_req_resp = NULL;
1411 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1412 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1413 DBGMSG("arm_lock64 called by node: %X "
1414 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X ",
1415 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1416 (u32) (addr & 0xFFFFFFFF),
1418 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1419 (u32) (be64_to_cpu(data) & 0xFFFFFFFF));
1421 DBGMSG("arm_lock64 called by node: %X "
1422 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X arg: "
1424 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1425 (u32) (addr & 0xFFFFFFFF),
1427 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1428 (u32) (be64_to_cpu(data) & 0xFFFFFFFF),
1429 (u32) ((be64_to_cpu(arg) >> 32) & 0xFFFFFFFF),
1430 (u32) (be64_to_cpu(arg) & 0xFFFFFFFF));
1432 spin_lock_irqsave(&host_info_lock, irqflags);
1433 hi = find_host_info(host); /* search addressentry in file_info's for host */
1435 list_for_each_entry(fi, &hi->file_info_list, list) {
1436 entry = fi->addr_list.next;
1437 while (entry != &(fi->addr_list)) {
1439 list_entry(entry, struct arm_addr,
1441 if (((arm_addr->start) <= (addr))
1442 && ((arm_addr->end) >=
1443 (addr + sizeof(*store)))) {
1447 entry = entry->next;
1457 "raw1394: arm_lock64 FAILED addr_entry not found"
1458 " -> rcode_address_error\n");
1459 spin_unlock_irqrestore(&host_info_lock, irqflags);
1460 return (RCODE_ADDRESS_ERROR);
1462 DBGMSG("arm_lock64 addr_entry FOUND");
1465 if (arm_addr->access_rights & ARM_LOCK) {
1466 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1468 (arm_addr->addr_space_buffer) + (addr -
1472 switch (ext_tcode) {
1473 case (EXTCODE_MASK_SWAP):
1474 new = data | (old & ~arg);
1476 case (EXTCODE_COMPARE_SWAP):
1483 case (EXTCODE_FETCH_ADD):
1485 cpu_to_be64(be64_to_cpu(data) +
1488 case (EXTCODE_LITTLE_ADD):
1490 cpu_to_le64(le64_to_cpu(data) +
1493 case (EXTCODE_BOUNDED_ADD):
1496 cpu_to_be64(be64_to_cpu
1504 case (EXTCODE_WRAP_ADD):
1507 cpu_to_be64(be64_to_cpu
1517 "raw1394: arm_lock64 FAILED "
1518 "ext_tcode not allowed -> rcode_type_error\n");
1519 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1524 ("arm_lock64 -> (rcode_complete)");
1525 rcode = RCODE_COMPLETE;
1526 memcpy(store, &old, sizeof(*store));
1527 memcpy((arm_addr->addr_space_buffer) +
1528 (addr - (arm_addr->start)),
1529 &new, sizeof(*store));
1533 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1535 ("arm_lock64 -> rcode_type_error (access denied)");
1538 if (arm_addr->notification_options & ARM_LOCK) {
1539 byte_t *buf1, *buf2;
1540 DBGMSG("arm_lock64 -> entering notification-section");
1541 req = __alloc_pending_request(SLAB_ATOMIC);
1543 spin_unlock_irqrestore(&host_info_lock, irqflags);
1544 DBGMSG("arm_lock64 -> rcode_conflict_error");
1545 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1546 The request may be retried */
1548 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1549 req->data = kmalloc(size, SLAB_ATOMIC);
1551 free_pending_request(req);
1552 spin_unlock_irqrestore(&host_info_lock, irqflags);
1553 DBGMSG("arm_lock64 -> rcode_conflict_error");
1554 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1555 The request may be retried */
1558 arm_req_resp = (struct arm_request_response *)(req->data);
1559 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1562 arm_request_response)));
1564 (struct arm_response *)((byte_t *) (arm_req) +
1565 (sizeof(struct arm_request)));
1566 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1567 buf2 = buf1 + 2 * sizeof(*store);
1568 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1569 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1570 arm_req->buffer_length = sizeof(*store);
1571 memcpy(buf1, &data, sizeof(*store));
1574 arm_req->buffer_length = 2 * sizeof(*store);
1575 memcpy(buf1, &arg, sizeof(*store));
1576 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1578 if (rcode == RCODE_COMPLETE) {
1579 arm_resp->buffer_length = sizeof(*store);
1580 memcpy(buf2, &old, sizeof(*store));
1582 arm_resp->buffer_length = 0;
1584 req->file_info = fi;
1585 req->req.type = RAW1394_REQ_ARM;
1586 req->req.generation = get_hpsb_generation(host);
1587 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1589 req->req.tag = arm_addr->arm_tag;
1590 req->req.recvb = arm_addr->recvb;
1591 req->req.length = size;
1592 arm_req->generation = req->req.generation;
1593 arm_req->extended_transaction_code = ext_tcode;
1594 arm_req->destination_offset = addr;
1595 arm_req->source_nodeid = nodeid;
1596 arm_req->destination_nodeid = host->node_id;
1597 arm_req->tlabel = (flags >> 10) & 0x3f;
1598 arm_req->tcode = (flags >> 4) & 0x0f;
1599 arm_resp->response_code = rcode;
1600 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1602 arm_request_response));
1603 arm_req_resp->response =
1604 int2ptr((arm_addr->recvb) +
1605 sizeof(struct arm_request_response) +
1606 sizeof(struct arm_request));
1608 int2ptr((arm_addr->recvb) +
1609 sizeof(struct arm_request_response) +
1610 sizeof(struct arm_request) +
1611 sizeof(struct arm_response));
1613 int2ptr((arm_addr->recvb) +
1614 sizeof(struct arm_request_response) +
1615 sizeof(struct arm_request) +
1616 sizeof(struct arm_response) + 2 * sizeof(*store));
1617 queue_complete_req(req);
1619 spin_unlock_irqrestore(&host_info_lock, irqflags);
1623 static int arm_register(struct file_info *fi, struct pending_request *req)
1626 struct arm_addr *addr;
1627 struct host_info *hi;
1628 struct file_info *fi_hlp = NULL;
1629 struct list_head *entry;
1630 struct arm_addr *arm_addr = NULL;
1631 int same_host, another_host;
1632 unsigned long flags;
1634 DBGMSG("arm_register called "
1635 "addr(Offset): %8.8x %8.8x length: %u "
1636 "rights: %2.2X notify: %2.2X "
1637 "max_blk_len: %4.4X",
1638 (u32) ((req->req.address >> 32) & 0xFFFF),
1639 (u32) (req->req.address & 0xFFFFFFFF),
1640 req->req.length, ((req->req.misc >> 8) & 0xFF),
1641 (req->req.misc & 0xFF), ((req->req.misc >> 16) & 0xFFFF));
1642 /* check addressrange */
1643 if ((((req->req.address) & ~(0xFFFFFFFFFFFFULL)) != 0) ||
1644 (((req->req.address + req->req.length) & ~(0xFFFFFFFFFFFFULL)) !=
1646 req->req.length = 0;
1649 /* addr-list-entry for fileinfo */
1650 addr = (struct arm_addr *)kmalloc(sizeof(struct arm_addr), SLAB_KERNEL);
1652 req->req.length = 0;
1655 /* allocation of addr_space_buffer */
1656 addr->addr_space_buffer = (u8 *) vmalloc(req->req.length);
1657 if (!(addr->addr_space_buffer)) {
1659 req->req.length = 0;
1662 /* initialization of addr_space_buffer */
1663 if ((req->req.sendb) == (unsigned long)NULL) {
1665 memset(addr->addr_space_buffer, 0, req->req.length);
1667 /* init: user -> kernel */
1669 (addr->addr_space_buffer, int2ptr(req->req.sendb),
1671 vfree(addr->addr_space_buffer);
1676 INIT_LIST_HEAD(&addr->addr_list);
1677 addr->arm_tag = req->req.tag;
1678 addr->start = req->req.address;
1679 addr->end = req->req.address + req->req.length;
1680 addr->access_rights = (u8) (req->req.misc & 0x0F);
1681 addr->notification_options = (u8) ((req->req.misc >> 4) & 0x0F);
1682 addr->client_transactions = (u8) ((req->req.misc >> 8) & 0x0F);
1683 addr->access_rights |= addr->client_transactions;
1684 addr->notification_options |= addr->client_transactions;
1685 addr->recvb = req->req.recvb;
1686 addr->rec_length = (u16) ((req->req.misc >> 16) & 0xFFFF);
1687 spin_lock_irqsave(&host_info_lock, flags);
1688 hi = find_host_info(fi->host);
1691 /* same host with address-entry containing same addressrange ? */
1692 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1693 entry = fi_hlp->addr_list.next;
1694 while (entry != &(fi_hlp->addr_list)) {
1696 list_entry(entry, struct arm_addr, addr_list);
1697 if ((arm_addr->start == addr->start)
1698 && (arm_addr->end == addr->end)) {
1699 DBGMSG("same host ownes same "
1700 "addressrange -> EALREADY");
1704 entry = entry->next;
1711 /* addressrange occupied by same host */
1712 vfree(addr->addr_space_buffer);
1714 spin_unlock_irqrestore(&host_info_lock, flags);
1717 /* another host with valid address-entry containing same addressrange */
1718 list_for_each_entry(hi, &host_info_list, list) {
1719 if (hi->host != fi->host) {
1720 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1721 entry = fi_hlp->addr_list.next;
1722 while (entry != &(fi_hlp->addr_list)) {
1724 list_entry(entry, struct arm_addr,
1726 if ((arm_addr->start == addr->start)
1727 && (arm_addr->end == addr->end)) {
1729 ("another host ownes same "
1734 entry = entry->next;
1743 DBGMSG("another hosts entry is valid -> SUCCESS");
1744 if (copy_to_user(int2ptr(req->req.recvb),
1745 &addr->start, sizeof(u64))) {
1746 printk(KERN_ERR "raw1394: arm_register failed "
1747 " address-range-entry is invalid -> EFAULT !!!\n");
1748 vfree(addr->addr_space_buffer);
1750 spin_unlock_irqrestore(&host_info_lock, flags);
1753 free_pending_request(req); /* immediate success or fail */
1755 list_add_tail(&addr->addr_list, &fi->addr_list);
1756 spin_unlock_irqrestore(&host_info_lock, flags);
1757 return sizeof(struct raw1394_request);
1760 hpsb_register_addrspace(&raw1394_highlevel, fi->host, &arm_ops,
1762 req->req.address + req->req.length);
1765 list_add_tail(&addr->addr_list, &fi->addr_list);
1767 DBGMSG("arm_register failed errno: %d \n", retval);
1768 vfree(addr->addr_space_buffer);
1770 spin_unlock_irqrestore(&host_info_lock, flags);
1773 spin_unlock_irqrestore(&host_info_lock, flags);
1774 free_pending_request(req); /* immediate success or fail */
1775 return sizeof(struct raw1394_request);
1778 static int arm_unregister(struct file_info *fi, struct pending_request *req)
1782 struct list_head *entry;
1783 struct arm_addr *addr = NULL;
1784 struct host_info *hi;
1785 struct file_info *fi_hlp = NULL;
1786 struct arm_addr *arm_addr = NULL;
1788 unsigned long flags;
1790 DBGMSG("arm_Unregister called addr(Offset): "
1792 (u32) ((req->req.address >> 32) & 0xFFFF),
1793 (u32) (req->req.address & 0xFFFFFFFF));
1794 spin_lock_irqsave(&host_info_lock, flags);
1796 entry = fi->addr_list.next;
1797 while (entry != &(fi->addr_list)) {
1798 addr = list_entry(entry, struct arm_addr, addr_list);
1799 if (addr->start == req->req.address) {
1803 entry = entry->next;
1806 DBGMSG("arm_Unregister addr not found");
1807 spin_unlock_irqrestore(&host_info_lock, flags);
1810 DBGMSG("arm_Unregister addr found");
1812 /* another host with valid address-entry containing
1813 same addressrange */
1814 list_for_each_entry(hi, &host_info_list, list) {
1815 if (hi->host != fi->host) {
1816 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1817 entry = fi_hlp->addr_list.next;
1818 while (entry != &(fi_hlp->addr_list)) {
1819 arm_addr = list_entry(entry,
1822 if (arm_addr->start == addr->start) {
1823 DBGMSG("another host ownes "
1824 "same addressrange");
1828 entry = entry->next;
1837 DBGMSG("delete entry from list -> success");
1838 list_del(&addr->addr_list);
1839 vfree(addr->addr_space_buffer);
1841 free_pending_request(req); /* immediate success or fail */
1842 spin_unlock_irqrestore(&host_info_lock, flags);
1843 return sizeof(struct raw1394_request);
1846 hpsb_unregister_addrspace(&raw1394_highlevel, fi->host,
1849 printk(KERN_ERR "raw1394: arm_Unregister failed -> EINVAL\n");
1850 spin_unlock_irqrestore(&host_info_lock, flags);
1853 DBGMSG("delete entry from list -> success");
1854 list_del(&addr->addr_list);
1855 spin_unlock_irqrestore(&host_info_lock, flags);
1856 vfree(addr->addr_space_buffer);
1858 free_pending_request(req); /* immediate success or fail */
1859 return sizeof(struct raw1394_request);
1862 /* Copy data from ARM buffer(s) to user buffer. */
1863 static int arm_get_buf(struct file_info *fi, struct pending_request *req)
1865 struct arm_addr *arm_addr = NULL;
1866 unsigned long flags;
1867 unsigned long offset;
1869 struct list_head *entry;
1871 DBGMSG("arm_get_buf "
1872 "addr(Offset): %04X %08X length: %u",
1873 (u32) ((req->req.address >> 32) & 0xFFFF),
1874 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
1876 spin_lock_irqsave(&host_info_lock, flags);
1877 entry = fi->addr_list.next;
1878 while (entry != &(fi->addr_list)) {
1879 arm_addr = list_entry(entry, struct arm_addr, addr_list);
1880 if ((arm_addr->start <= req->req.address) &&
1881 (arm_addr->end > req->req.address)) {
1882 if (req->req.address + req->req.length <= arm_addr->end) {
1883 offset = req->req.address - arm_addr->start;
1886 ("arm_get_buf copy_to_user( %08X, %p, %u )",
1887 (u32) req->req.recvb,
1888 arm_addr->addr_space_buffer + offset,
1889 (u32) req->req.length);
1892 (int2ptr(req->req.recvb),
1893 arm_addr->addr_space_buffer + offset,
1895 spin_unlock_irqrestore(&host_info_lock,
1900 spin_unlock_irqrestore(&host_info_lock, flags);
1901 /* We have to free the request, because we
1902 * queue no response, and therefore nobody
1904 free_pending_request(req);
1905 return sizeof(struct raw1394_request);
1907 DBGMSG("arm_get_buf request exceeded mapping");
1908 spin_unlock_irqrestore(&host_info_lock, flags);
1912 entry = entry->next;
1914 spin_unlock_irqrestore(&host_info_lock, flags);
1918 /* Copy data from user buffer to ARM buffer(s). */
1919 static int arm_set_buf(struct file_info *fi, struct pending_request *req)
1921 struct arm_addr *arm_addr = NULL;
1922 unsigned long flags;
1923 unsigned long offset;
1925 struct list_head *entry;
1927 DBGMSG("arm_set_buf "
1928 "addr(Offset): %04X %08X length: %u",
1929 (u32) ((req->req.address >> 32) & 0xFFFF),
1930 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
1932 spin_lock_irqsave(&host_info_lock, flags);
1933 entry = fi->addr_list.next;
1934 while (entry != &(fi->addr_list)) {
1935 arm_addr = list_entry(entry, struct arm_addr, addr_list);
1936 if ((arm_addr->start <= req->req.address) &&
1937 (arm_addr->end > req->req.address)) {
1938 if (req->req.address + req->req.length <= arm_addr->end) {
1939 offset = req->req.address - arm_addr->start;
1942 ("arm_set_buf copy_from_user( %p, %08X, %u )",
1943 arm_addr->addr_space_buffer + offset,
1944 (u32) req->req.sendb,
1945 (u32) req->req.length);
1948 (arm_addr->addr_space_buffer + offset,
1949 int2ptr(req->req.sendb),
1951 spin_unlock_irqrestore(&host_info_lock,
1956 spin_unlock_irqrestore(&host_info_lock, flags);
1957 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
1958 return sizeof(struct raw1394_request);
1960 DBGMSG("arm_set_buf request exceeded mapping");
1961 spin_unlock_irqrestore(&host_info_lock, flags);
1965 entry = entry->next;
1967 spin_unlock_irqrestore(&host_info_lock, flags);
1971 static int reset_notification(struct file_info *fi, struct pending_request *req)
1973 DBGMSG("reset_notification called - switch %s ",
1974 (req->req.misc == RAW1394_NOTIFY_OFF) ? "OFF" : "ON");
1975 if ((req->req.misc == RAW1394_NOTIFY_OFF) ||
1976 (req->req.misc == RAW1394_NOTIFY_ON)) {
1977 fi->notification = (u8) req->req.misc;
1978 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
1979 return sizeof(struct raw1394_request);
1981 /* error EINVAL (22) invalid argument */
1985 static int write_phypacket(struct file_info *fi, struct pending_request *req)
1987 struct hpsb_packet *packet = NULL;
1990 unsigned long flags;
1992 data = be32_to_cpu((u32) req->req.sendb);
1993 DBGMSG("write_phypacket called - quadlet 0x%8.8x ", data);
1994 packet = hpsb_make_phypacket(fi->host, data);
1997 req->req.length = 0;
1998 req->packet = packet;
1999 hpsb_set_packet_complete_task(packet,
2000 (void (*)(void *))queue_complete_cb, req);
2001 spin_lock_irqsave(&fi->reqlists_lock, flags);
2002 list_add_tail(&req->list, &fi->req_pending);
2003 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2004 packet->generation = req->req.generation;
2005 retval = hpsb_send_packet(packet);
2006 DBGMSG("write_phypacket send_packet called => retval: %d ", retval);
2008 req->req.error = RAW1394_ERROR_SEND_ERROR;
2009 req->req.length = 0;
2010 queue_complete_req(req);
2012 return sizeof(struct raw1394_request);
2015 static int get_config_rom(struct file_info *fi, struct pending_request *req)
2017 int ret = sizeof(struct raw1394_request);
2018 quadlet_t *data = kmalloc(req->req.length, SLAB_KERNEL);
2025 csr1212_read(fi->host->csr.rom, CSR1212_CONFIG_ROM_SPACE_OFFSET,
2026 data, req->req.length);
2027 if (copy_to_user(int2ptr(req->req.recvb), data, req->req.length))
2030 (int2ptr(req->req.tag), &fi->host->csr.rom->cache_head->len,
2031 sizeof(fi->host->csr.rom->cache_head->len)))
2033 if (copy_to_user(int2ptr(req->req.address), &fi->host->csr.generation,
2034 sizeof(fi->host->csr.generation)))
2036 if (copy_to_user(int2ptr(req->req.sendb), &status, sizeof(status)))
2040 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2045 static int update_config_rom(struct file_info *fi, struct pending_request *req)
2047 int ret = sizeof(struct raw1394_request);
2048 quadlet_t *data = kmalloc(req->req.length, SLAB_KERNEL);
2051 if (copy_from_user(data, int2ptr(req->req.sendb), req->req.length)) {
2054 int status = hpsb_update_config_rom(fi->host,
2055 data, req->req.length,
2056 (unsigned char)req->req.
2059 (int2ptr(req->req.recvb), &status, sizeof(status)))
2064 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2070 static int modify_config_rom(struct file_info *fi, struct pending_request *req)
2072 struct csr1212_keyval *kv;
2073 struct csr1212_csr_rom_cache *cache;
2074 struct csr1212_dentry *dentry;
2078 if (req->req.misc == ~0) {
2079 if (req->req.length == 0)
2082 /* Find an unused slot */
2084 dr < RAW1394_MAX_USER_CSR_DIRS && fi->csr1212_dirs[dr];
2087 if (dr == RAW1394_MAX_USER_CSR_DIRS)
2090 fi->csr1212_dirs[dr] =
2091 csr1212_new_directory(CSR1212_KV_ID_VENDOR);
2092 if (!fi->csr1212_dirs[dr])
2096 if (!fi->csr1212_dirs[dr])
2099 /* Delete old stuff */
2101 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2102 dentry; dentry = dentry->next) {
2103 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2108 if (req->req.length == 0) {
2109 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2110 fi->csr1212_dirs[dr] = NULL;
2112 hpsb_update_config_rom_image(fi->host);
2113 free_pending_request(req);
2114 return sizeof(struct raw1394_request);
2118 cache = csr1212_rom_cache_malloc(0, req->req.length);
2120 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2121 fi->csr1212_dirs[dr] = NULL;
2125 cache->filled_head =
2126 kmalloc(sizeof(struct csr1212_cache_region), GFP_KERNEL);
2127 if (!cache->filled_head) {
2128 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2129 fi->csr1212_dirs[dr] = NULL;
2130 CSR1212_FREE(cache);
2133 cache->filled_tail = cache->filled_head;
2135 if (copy_from_user(cache->data, int2ptr(req->req.sendb),
2137 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2138 fi->csr1212_dirs[dr] = NULL;
2139 CSR1212_FREE(cache);
2142 cache->len = req->req.length;
2143 cache->filled_head->offset_start = 0;
2144 cache->filled_head->offset_end = cache->size - 1;
2146 cache->layout_head = cache->layout_tail = fi->csr1212_dirs[dr];
2148 ret = CSR1212_SUCCESS;
2149 /* parse all the items */
2150 for (kv = cache->layout_head; ret == CSR1212_SUCCESS && kv;
2152 ret = csr1212_parse_keyval(kv, cache);
2155 /* attach top level items to the root directory */
2157 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2158 ret == CSR1212_SUCCESS && dentry; dentry = dentry->next) {
2160 csr1212_attach_keyval_to_directory(fi->host->csr.
2165 if (ret == CSR1212_SUCCESS) {
2166 ret = hpsb_update_config_rom_image(fi->host);
2168 if (ret >= 0 && copy_to_user(int2ptr(req->req.recvb),
2174 kfree(cache->filled_head);
2178 /* we have to free the request, because we queue no response,
2179 * and therefore nobody will free it */
2180 free_pending_request(req);
2181 return sizeof(struct raw1394_request);
2184 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2185 dentry; dentry = dentry->next) {
2186 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2190 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2191 fi->csr1212_dirs[dr] = NULL;
2196 static int state_connected(struct file_info *fi, struct pending_request *req)
2198 int node = req->req.address >> 48;
2200 req->req.error = RAW1394_ERROR_NONE;
2202 switch (req->req.type) {
2204 case RAW1394_REQ_ECHO:
2205 queue_complete_req(req);
2206 return sizeof(struct raw1394_request);
2208 case RAW1394_REQ_ISO_SEND:
2209 return handle_iso_send(fi, req, node);
2211 case RAW1394_REQ_ARM_REGISTER:
2212 return arm_register(fi, req);
2214 case RAW1394_REQ_ARM_UNREGISTER:
2215 return arm_unregister(fi, req);
2217 case RAW1394_REQ_ARM_SET_BUF:
2218 return arm_set_buf(fi, req);
2220 case RAW1394_REQ_ARM_GET_BUF:
2221 return arm_get_buf(fi, req);
2223 case RAW1394_REQ_RESET_NOTIFY:
2224 return reset_notification(fi, req);
2226 case RAW1394_REQ_ISO_LISTEN:
2227 handle_iso_listen(fi, req);
2228 return sizeof(struct raw1394_request);
2230 case RAW1394_REQ_FCP_LISTEN:
2231 handle_fcp_listen(fi, req);
2232 return sizeof(struct raw1394_request);
2234 case RAW1394_REQ_RESET_BUS:
2235 if (req->req.misc == RAW1394_LONG_RESET) {
2236 DBGMSG("busreset called (type: LONG)");
2237 hpsb_reset_bus(fi->host, LONG_RESET);
2238 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2239 return sizeof(struct raw1394_request);
2241 if (req->req.misc == RAW1394_SHORT_RESET) {
2242 DBGMSG("busreset called (type: SHORT)");
2243 hpsb_reset_bus(fi->host, SHORT_RESET);
2244 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2245 return sizeof(struct raw1394_request);
2247 /* error EINVAL (22) invalid argument */
2249 case RAW1394_REQ_GET_ROM:
2250 return get_config_rom(fi, req);
2252 case RAW1394_REQ_UPDATE_ROM:
2253 return update_config_rom(fi, req);
2255 case RAW1394_REQ_MODIFY_ROM:
2256 return modify_config_rom(fi, req);
2259 if (req->req.generation != get_hpsb_generation(fi->host)) {
2260 req->req.error = RAW1394_ERROR_GENERATION;
2261 req->req.generation = get_hpsb_generation(fi->host);
2262 req->req.length = 0;
2263 queue_complete_req(req);
2264 return sizeof(struct raw1394_request);
2267 switch (req->req.type) {
2268 case RAW1394_REQ_PHYPACKET:
2269 return write_phypacket(fi, req);
2270 case RAW1394_REQ_ASYNC_SEND:
2271 return handle_async_send(fi, req);
2274 if (req->req.length == 0) {
2275 req->req.error = RAW1394_ERROR_INVALID_ARG;
2276 queue_complete_req(req);
2277 return sizeof(struct raw1394_request);
2280 return handle_async_request(fi, req, node);
2283 static ssize_t raw1394_write(struct file *file, const char __user * buffer,
2284 size_t count, loff_t * offset_is_ignored)
2286 struct file_info *fi = (struct file_info *)file->private_data;
2287 struct pending_request *req;
2290 if (count != sizeof(struct raw1394_request)) {
2294 req = alloc_pending_request();
2298 req->file_info = fi;
2300 if (copy_from_user(&req->req, buffer, sizeof(struct raw1394_request))) {
2301 free_pending_request(req);
2305 switch (fi->state) {
2307 retval = state_opened(fi, req);
2311 retval = state_initialized(fi, req);
2315 retval = state_connected(fi, req);
2320 free_pending_request(req);
2326 /* rawiso operations */
2328 /* check if any RAW1394_REQ_RAWISO_ACTIVITY event is already in the
2329 * completion queue (reqlists_lock must be taken) */
2330 static inline int __rawiso_event_in_queue(struct file_info *fi)
2332 struct pending_request *req;
2334 list_for_each_entry(req, &fi->req_complete, list)
2335 if (req->req.type == RAW1394_REQ_RAWISO_ACTIVITY)
2341 /* put a RAWISO_ACTIVITY event in the queue, if one isn't there already */
2342 static void queue_rawiso_event(struct file_info *fi)
2344 unsigned long flags;
2346 spin_lock_irqsave(&fi->reqlists_lock, flags);
2348 /* only one ISO activity event may be in the queue */
2349 if (!__rawiso_event_in_queue(fi)) {
2350 struct pending_request *req =
2351 __alloc_pending_request(SLAB_ATOMIC);
2354 req->file_info = fi;
2355 req->req.type = RAW1394_REQ_RAWISO_ACTIVITY;
2356 req->req.generation = get_hpsb_generation(fi->host);
2357 __queue_complete_req(req);
2359 /* on allocation failure, signal an overflow */
2360 if (fi->iso_handle) {
2361 atomic_inc(&fi->iso_handle->overflows);
2365 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2368 static void rawiso_activity_cb(struct hpsb_iso *iso)
2370 unsigned long flags;
2371 struct host_info *hi;
2372 struct file_info *fi;
2374 spin_lock_irqsave(&host_info_lock, flags);
2375 hi = find_host_info(iso->host);
2378 list_for_each_entry(fi, &hi->file_info_list, list) {
2379 if (fi->iso_handle == iso)
2380 queue_rawiso_event(fi);
2384 spin_unlock_irqrestore(&host_info_lock, flags);
2387 /* helper function - gather all the kernel iso status bits for returning to user-space */
2388 static void raw1394_iso_fill_status(struct hpsb_iso *iso,
2389 struct raw1394_iso_status *stat)
2391 stat->config.data_buf_size = iso->buf_size;
2392 stat->config.buf_packets = iso->buf_packets;
2393 stat->config.channel = iso->channel;
2394 stat->config.speed = iso->speed;
2395 stat->config.irq_interval = iso->irq_interval;
2396 stat->n_packets = hpsb_iso_n_ready(iso);
2397 stat->overflows = atomic_read(&iso->overflows);
2398 stat->xmit_cycle = iso->xmit_cycle;
2401 static int raw1394_iso_xmit_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_xmit_init(fi->host,
2412 stat.config.data_buf_size,
2413 stat.config.buf_packets,
2414 stat.config.channel,
2416 stat.config.irq_interval,
2417 rawiso_activity_cb);
2418 if (!fi->iso_handle)
2421 fi->iso_state = RAW1394_ISO_XMIT;
2423 raw1394_iso_fill_status(fi->iso_handle, &stat);
2424 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2427 /* queue an event to get things started */
2428 rawiso_activity_cb(fi->iso_handle);
2433 static int raw1394_iso_recv_init(struct file_info *fi, void __user * uaddr)
2435 struct raw1394_iso_status stat;
2440 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2443 fi->iso_handle = hpsb_iso_recv_init(fi->host,
2444 stat.config.data_buf_size,
2445 stat.config.buf_packets,
2446 stat.config.channel,
2447 stat.config.dma_mode,
2448 stat.config.irq_interval,
2449 rawiso_activity_cb);
2450 if (!fi->iso_handle)
2453 fi->iso_state = RAW1394_ISO_RECV;
2455 raw1394_iso_fill_status(fi->iso_handle, &stat);
2456 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2461 static int raw1394_iso_get_status(struct file_info *fi, void __user * uaddr)
2463 struct raw1394_iso_status stat;
2464 struct hpsb_iso *iso = fi->iso_handle;
2466 raw1394_iso_fill_status(fi->iso_handle, &stat);
2467 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2470 /* reset overflow counter */
2471 atomic_set(&iso->overflows, 0);
2476 /* copy N packet_infos out of the ringbuffer into user-supplied array */
2477 static int raw1394_iso_recv_packets(struct file_info *fi, void __user * uaddr)
2479 struct raw1394_iso_packets upackets;
2480 unsigned int packet = fi->iso_handle->first_packet;
2483 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2486 if (upackets.n_packets > hpsb_iso_n_ready(fi->iso_handle))
2489 /* ensure user-supplied buffer is accessible and big enough */
2490 if (!access_ok(VERIFY_WRITE, upackets.infos,
2491 upackets.n_packets *
2492 sizeof(struct raw1394_iso_packet_info)))
2495 /* copy the packet_infos out */
2496 for (i = 0; i < upackets.n_packets; i++) {
2497 if (__copy_to_user(&upackets.infos[i],
2498 &fi->iso_handle->infos[packet],
2499 sizeof(struct raw1394_iso_packet_info)))
2502 packet = (packet + 1) % fi->iso_handle->buf_packets;
2508 /* copy N packet_infos from user to ringbuffer, and queue them for transmission */
2509 static int raw1394_iso_send_packets(struct file_info *fi, void __user * uaddr)
2511 struct raw1394_iso_packets upackets;
2514 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2517 if (upackets.n_packets >= fi->iso_handle->buf_packets)
2520 if (upackets.n_packets >= hpsb_iso_n_ready(fi->iso_handle))
2523 /* ensure user-supplied buffer is accessible and big enough */
2524 if (!access_ok(VERIFY_READ, upackets.infos,
2525 upackets.n_packets *
2526 sizeof(struct raw1394_iso_packet_info)))
2529 /* copy the infos structs in and queue the packets */
2530 for (i = 0; i < upackets.n_packets; i++) {
2531 struct raw1394_iso_packet_info info;
2533 if (__copy_from_user(&info, &upackets.infos[i],
2534 sizeof(struct raw1394_iso_packet_info)))
2537 rv = hpsb_iso_xmit_queue_packet(fi->iso_handle, info.offset,
2538 info.len, info.tag, info.sy);
2546 static void raw1394_iso_shutdown(struct file_info *fi)
2549 hpsb_iso_shutdown(fi->iso_handle);
2551 fi->iso_handle = NULL;
2552 fi->iso_state = RAW1394_ISO_INACTIVE;
2555 /* mmap the rawiso xmit/recv buffer */
2556 static int raw1394_mmap(struct file *file, struct vm_area_struct *vma)
2558 struct file_info *fi = file->private_data;
2560 if (fi->iso_state == RAW1394_ISO_INACTIVE)
2563 return dma_region_mmap(&fi->iso_handle->data_buf, file, vma);
2566 /* ioctl is only used for rawiso operations */
2567 static int raw1394_ioctl(struct inode *inode, struct file *file,
2568 unsigned int cmd, unsigned long arg)
2570 struct file_info *fi = file->private_data;
2571 void __user *argp = (void __user *)arg;
2573 switch (fi->iso_state) {
2574 case RAW1394_ISO_INACTIVE:
2576 case RAW1394_IOC_ISO_XMIT_INIT:
2577 return raw1394_iso_xmit_init(fi, argp);
2578 case RAW1394_IOC_ISO_RECV_INIT:
2579 return raw1394_iso_recv_init(fi, argp);
2584 case RAW1394_ISO_RECV:
2586 case RAW1394_IOC_ISO_RECV_START:{
2587 /* copy args from user-space */
2590 (&args[0], argp, sizeof(args)))
2592 return hpsb_iso_recv_start(fi->iso_handle,
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,
2602 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
2603 return hpsb_iso_recv_unlisten_channel(fi->iso_handle,
2605 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:{
2606 /* copy the u64 from user-space */
2608 if (copy_from_user(&mask, argp, sizeof(mask)))
2610 return hpsb_iso_recv_set_channel_mask(fi->
2614 case RAW1394_IOC_ISO_GET_STATUS:
2615 return raw1394_iso_get_status(fi, argp);
2616 case RAW1394_IOC_ISO_RECV_PACKETS:
2617 return raw1394_iso_recv_packets(fi, argp);
2618 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
2619 return hpsb_iso_recv_release_packets(fi->iso_handle,
2621 case RAW1394_IOC_ISO_RECV_FLUSH:
2622 return hpsb_iso_recv_flush(fi->iso_handle);
2623 case RAW1394_IOC_ISO_SHUTDOWN:
2624 raw1394_iso_shutdown(fi);
2626 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2627 queue_rawiso_event(fi);
2631 case RAW1394_ISO_XMIT:
2633 case RAW1394_IOC_ISO_XMIT_START:{
2634 /* copy two ints from user-space */
2637 (&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);
2666 static unsigned int raw1394_poll(struct file *file, poll_table * pt)
2668 struct file_info *fi = file->private_data;
2669 unsigned int mask = POLLOUT | POLLWRNORM;
2670 unsigned long flags;
2672 poll_wait(file, &fi->poll_wait_complete, pt);
2674 spin_lock_irqsave(&fi->reqlists_lock, flags);
2675 if (!list_empty(&fi->req_complete)) {
2676 mask |= POLLIN | POLLRDNORM;
2678 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2683 static int raw1394_open(struct inode *inode, struct file *file)
2685 struct file_info *fi;
2687 fi = kmalloc(sizeof(struct file_info), SLAB_KERNEL);
2691 memset(fi, 0, sizeof(struct file_info));
2692 fi->notification = (u8) RAW1394_NOTIFY_ON; /* busreset notification */
2694 INIT_LIST_HEAD(&fi->list);
2696 INIT_LIST_HEAD(&fi->req_pending);
2697 INIT_LIST_HEAD(&fi->req_complete);
2698 sema_init(&fi->complete_sem, 0);
2699 spin_lock_init(&fi->reqlists_lock);
2700 init_waitqueue_head(&fi->poll_wait_complete);
2701 INIT_LIST_HEAD(&fi->addr_list);
2703 file->private_data = fi;
2708 static int raw1394_release(struct inode *inode, struct file *file)
2710 struct file_info *fi = file->private_data;
2711 struct list_head *lh;
2712 struct pending_request *req;
2713 int done = 0, i, fail = 0;
2715 struct list_head *entry;
2716 struct arm_addr *addr = NULL;
2717 struct host_info *hi;
2718 struct file_info *fi_hlp = NULL;
2719 struct arm_addr *arm_addr = NULL;
2722 unsigned long flags;
2724 if (fi->iso_state != RAW1394_ISO_INACTIVE)
2725 raw1394_iso_shutdown(fi);
2727 for (i = 0; i < 64; i++) {
2728 if (fi->listen_channels & (1ULL << i)) {
2729 hpsb_unlisten_channel(&raw1394_highlevel, fi->host, i);
2733 spin_lock_irqsave(&host_info_lock, flags);
2734 fi->listen_channels = 0;
2737 /* set address-entries invalid */
2739 while (!list_empty(&fi->addr_list)) {
2741 lh = fi->addr_list.next;
2742 addr = list_entry(lh, struct arm_addr, addr_list);
2743 /* another host with valid address-entry containing
2744 same addressrange? */
2745 list_for_each_entry(hi, &host_info_list, list) {
2746 if (hi->host != fi->host) {
2747 list_for_each_entry(fi_hlp, &hi->file_info_list,
2749 entry = fi_hlp->addr_list.next;
2750 while (entry != &(fi_hlp->addr_list)) {
2751 arm_addr = list_entry(entry,
2755 if (arm_addr->start ==
2758 ("raw1394_release: "
2759 "another host ownes "
2760 "same addressrange");
2764 entry = entry->next;
2772 if (!another_host) {
2773 DBGMSG("raw1394_release: call hpsb_arm_unregister");
2775 hpsb_unregister_addrspace(&raw1394_highlevel,
2776 fi->host, addr->start);
2780 "raw1394_release arm_Unregister failed\n");
2783 DBGMSG("raw1394_release: delete addr_entry from list");
2784 list_del(&addr->addr_list);
2785 vfree(addr->addr_space_buffer);
2788 spin_unlock_irqrestore(&host_info_lock, flags);
2790 printk(KERN_ERR "raw1394: during addr_list-release "
2791 "error(s) occurred \n");
2795 spin_lock_irqsave(&fi->reqlists_lock, flags);
2797 while (!list_empty(&fi->req_complete)) {
2798 lh = fi->req_complete.next;
2801 req = list_entry(lh, struct pending_request, list);
2803 free_pending_request(req);
2806 if (list_empty(&fi->req_pending))
2809 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2812 down_interruptible(&fi->complete_sem);
2815 /* Remove any sub-trees left by user space programs */
2816 for (i = 0; i < RAW1394_MAX_USER_CSR_DIRS; i++) {
2817 struct csr1212_dentry *dentry;
2818 if (!fi->csr1212_dirs[i])
2821 fi->csr1212_dirs[i]->value.directory.dentries_head; dentry;
2822 dentry = dentry->next) {
2823 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2827 csr1212_release_keyval(fi->csr1212_dirs[i]);
2828 fi->csr1212_dirs[i] = NULL;
2832 if ((csr_mod || fi->cfgrom_upd)
2833 && hpsb_update_config_rom_image(fi->host) < 0)
2835 ("Failed to generate Configuration ROM image for host %d",
2838 if (fi->state == connected) {
2839 spin_lock_irqsave(&host_info_lock, flags);
2840 list_del(&fi->list);
2841 spin_unlock_irqrestore(&host_info_lock, flags);
2843 put_device(&fi->host->device);
2851 /*** HOTPLUG STUFF **********************************************************/
2853 * Export information about protocols/devices supported by this driver.
2855 static struct ieee1394_device_id raw1394_id_table[] = {
2857 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2858 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
2859 .version = AVC_SW_VERSION_ENTRY & 0xffffff},
2861 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2862 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2863 .version = CAMERA_SW_VERSION_ENTRY & 0xffffff},
2865 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2866 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2867 .version = (CAMERA_SW_VERSION_ENTRY + 1) & 0xffffff},
2869 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2870 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2871 .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff},
2875 MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table);
2877 static struct hpsb_protocol_driver raw1394_driver = {
2878 .name = "raw1394 Driver",
2879 .id_table = raw1394_id_table,
2882 .bus = &ieee1394_bus_type,
2886 /******************************************************************************/
2888 static struct hpsb_highlevel raw1394_highlevel = {
2889 .name = RAW1394_DEVICE_NAME,
2890 .add_host = add_host,
2891 .remove_host = remove_host,
2892 .host_reset = host_reset,
2893 .iso_receive = iso_receive,
2894 .fcp_request = fcp_request,
2897 static struct cdev raw1394_cdev;
2898 static struct file_operations raw1394_fops = {
2899 .owner = THIS_MODULE,
2900 .read = raw1394_read,
2901 .write = raw1394_write,
2902 .mmap = raw1394_mmap,
2903 .ioctl = raw1394_ioctl,
2904 .poll = raw1394_poll,
2905 .open = raw1394_open,
2906 .release = raw1394_release,
2909 static int __init init_raw1394(void)
2913 hpsb_register_highlevel(&raw1394_highlevel);
2915 if (IS_ERR(class_device_create(hpsb_protocol_class, MKDEV(
2916 IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16),
2917 NULL, RAW1394_DEVICE_NAME))) {
2922 devfs_mk_cdev(MKDEV(
2923 IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16),
2924 S_IFCHR | S_IRUSR | S_IWUSR, RAW1394_DEVICE_NAME);
2926 cdev_init(&raw1394_cdev, &raw1394_fops);
2927 raw1394_cdev.owner = THIS_MODULE;
2928 kobject_set_name(&raw1394_cdev.kobj, RAW1394_DEVICE_NAME);
2929 ret = cdev_add(&raw1394_cdev, IEEE1394_RAW1394_DEV, 1);
2931 HPSB_ERR("raw1394 failed to register minor device block");
2935 HPSB_INFO("raw1394: /dev/%s device initialized", RAW1394_DEVICE_NAME);
2937 ret = hpsb_register_protocol(&raw1394_driver);
2939 HPSB_ERR("raw1394: failed to register protocol");
2940 cdev_del(&raw1394_cdev);
2947 devfs_remove(RAW1394_DEVICE_NAME);
2948 class_device_destroy(hpsb_protocol_class,
2949 MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16));
2951 hpsb_unregister_highlevel(&raw1394_highlevel);
2956 static void __exit cleanup_raw1394(void)
2958 class_device_destroy(hpsb_protocol_class,
2959 MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16));
2960 cdev_del(&raw1394_cdev);
2961 devfs_remove(RAW1394_DEVICE_NAME);
2962 hpsb_unregister_highlevel(&raw1394_highlevel);
2963 hpsb_unregister_protocol(&raw1394_driver);
2966 module_init(init_raw1394);
2967 module_exit(cleanup_raw1394);
2968 MODULE_LICENSE("GPL");