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(int 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)
415 struct file_info *fi = (struct file_info *)file->private_data;
416 struct list_head *lh;
417 struct pending_request *req;
420 if (count != sizeof(struct raw1394_request)) {
424 if (!access_ok(VERIFY_WRITE, buffer, count)) {
428 if (file->f_flags & O_NONBLOCK) {
429 if (down_trylock(&fi->complete_sem)) {
433 if (down_interruptible(&fi->complete_sem)) {
438 spin_lock_irq(&fi->reqlists_lock);
439 lh = fi->req_complete.next;
441 spin_unlock_irq(&fi->reqlists_lock);
443 req = list_entry(lh, struct pending_request, list);
445 if (req->req.length) {
446 if (copy_to_user(int2ptr(req->req.recvb), req->data,
448 req->req.error = RAW1394_ERROR_MEMFAULT;
451 if (copy_to_user(buffer, &req->req, sizeof(req->req))) {
456 ret = (ssize_t) sizeof(struct raw1394_request);
458 free_pending_request(req);
462 static int state_opened(struct file_info *fi, struct pending_request *req)
464 if (req->req.type == RAW1394_REQ_INITIALIZE) {
465 switch (req->req.misc) {
466 case RAW1394_KERNELAPI_VERSION:
468 fi->state = initialized;
469 fi->protocol_version = req->req.misc;
470 req->req.error = RAW1394_ERROR_NONE;
471 req->req.generation = atomic_read(&internal_generation);
475 req->req.error = RAW1394_ERROR_COMPAT;
476 req->req.misc = RAW1394_KERNELAPI_VERSION;
479 req->req.error = RAW1394_ERROR_STATE_ORDER;
483 queue_complete_req(req);
484 return sizeof(struct raw1394_request);
487 static int state_initialized(struct file_info *fi, struct pending_request *req)
489 struct host_info *hi;
490 struct raw1394_khost_list *khl;
492 if (req->req.generation != atomic_read(&internal_generation)) {
493 req->req.error = RAW1394_ERROR_GENERATION;
494 req->req.generation = atomic_read(&internal_generation);
496 queue_complete_req(req);
497 return sizeof(struct raw1394_request);
500 switch (req->req.type) {
501 case RAW1394_REQ_LIST_CARDS:
502 spin_lock_irq(&host_info_lock);
503 khl = kmalloc(sizeof(struct raw1394_khost_list) * host_count,
507 req->req.misc = host_count;
508 req->data = (quadlet_t *) khl;
510 list_for_each_entry(hi, &host_info_list, list) {
511 khl->nodes = hi->host->node_count;
512 strcpy(khl->name, hi->host->driver->name);
516 spin_unlock_irq(&host_info_lock);
519 req->req.error = RAW1394_ERROR_NONE;
520 req->req.length = min(req->req.length,
522 (struct raw1394_khost_list)
530 case RAW1394_REQ_SET_CARD:
531 spin_lock_irq(&host_info_lock);
532 if (req->req.misc < host_count) {
533 list_for_each_entry(hi, &host_info_list, list) {
534 if (!req->req.misc--)
537 get_device(&hi->host->device); // XXX Need to handle failure case
538 list_add_tail(&fi->list, &hi->file_info_list);
540 fi->state = connected;
542 req->req.error = RAW1394_ERROR_NONE;
543 req->req.generation = get_hpsb_generation(fi->host);
544 req->req.misc = (fi->host->node_id << 16)
545 | fi->host->node_count;
546 if (fi->protocol_version > 3) {
548 NODEID_TO_NODE(fi->host->irm_id) << 8;
551 req->req.error = RAW1394_ERROR_INVALID_ARG;
553 spin_unlock_irq(&host_info_lock);
559 req->req.error = RAW1394_ERROR_STATE_ORDER;
564 queue_complete_req(req);
565 return sizeof(struct raw1394_request);
568 static void handle_iso_listen(struct file_info *fi, struct pending_request *req)
570 int channel = req->req.misc;
572 spin_lock_irq(&host_info_lock);
573 if ((channel > 63) || (channel < -64)) {
574 req->req.error = RAW1394_ERROR_INVALID_ARG;
575 } else if (channel >= 0) {
576 /* allocate channel req.misc */
577 if (fi->listen_channels & (1ULL << channel)) {
578 req->req.error = RAW1394_ERROR_ALREADY;
580 if (hpsb_listen_channel
581 (&raw1394_highlevel, fi->host, channel)) {
582 req->req.error = RAW1394_ERROR_ALREADY;
584 fi->listen_channels |= 1ULL << channel;
585 fi->iso_buffer = int2ptr(req->req.recvb);
586 fi->iso_buffer_length = req->req.length;
590 /* deallocate channel (one's complement neg) req.misc */
593 if (fi->listen_channels & (1ULL << channel)) {
594 hpsb_unlisten_channel(&raw1394_highlevel, fi->host,
596 fi->listen_channels &= ~(1ULL << channel);
598 req->req.error = RAW1394_ERROR_INVALID_ARG;
603 queue_complete_req(req);
604 spin_unlock_irq(&host_info_lock);
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)
630 struct hpsb_packet *packet = NULL;
631 u64 addr = req->req.address & 0xffffffffffffULL;
633 switch (req->req.type) {
634 case RAW1394_REQ_ASYNC_READ:
635 DBGMSG("read_request called");
637 hpsb_make_readpacket(fi->host, node, addr, req->req.length);
642 if (req->req.length == 4)
643 req->data = &packet->header[3];
645 req->data = packet->data;
649 case RAW1394_REQ_ASYNC_WRITE:
650 DBGMSG("write_request called");
652 packet = hpsb_make_writepacket(fi->host, node, addr, NULL,
657 if (req->req.length == 4) {
659 (&packet->header[3], int2ptr(req->req.sendb),
661 req->req.error = RAW1394_ERROR_MEMFAULT;
664 (packet->data, int2ptr(req->req.sendb),
666 req->req.error = RAW1394_ERROR_MEMFAULT;
672 case RAW1394_REQ_ASYNC_STREAM:
673 DBGMSG("stream_request called");
676 hpsb_make_streampacket(fi->host, NULL, req->req.length,
677 node & 0x3f /*channel */ ,
678 (req->req.misc >> 16) & 0x3,
679 req->req.misc & 0xf);
683 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
685 req->req.error = RAW1394_ERROR_MEMFAULT;
690 case RAW1394_REQ_LOCK:
691 DBGMSG("lock_request called");
692 if ((req->req.misc == EXTCODE_FETCH_ADD)
693 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
694 if (req->req.length != 4) {
695 req->req.error = RAW1394_ERROR_INVALID_ARG;
699 if (req->req.length != 8) {
700 req->req.error = RAW1394_ERROR_INVALID_ARG;
705 packet = hpsb_make_lockpacket(fi->host, node, addr,
706 req->req.misc, NULL, 0);
710 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
712 req->req.error = RAW1394_ERROR_MEMFAULT;
716 req->data = packet->data;
720 case RAW1394_REQ_LOCK64:
721 DBGMSG("lock64_request called");
722 if ((req->req.misc == EXTCODE_FETCH_ADD)
723 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
724 if (req->req.length != 8) {
725 req->req.error = RAW1394_ERROR_INVALID_ARG;
729 if (req->req.length != 16) {
730 req->req.error = RAW1394_ERROR_INVALID_ARG;
734 packet = hpsb_make_lock64packet(fi->host, node, addr,
735 req->req.misc, NULL, 0);
739 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
741 req->req.error = RAW1394_ERROR_MEMFAULT;
745 req->data = packet->data;
750 req->req.error = RAW1394_ERROR_STATE_ORDER;
753 req->packet = packet;
755 if (req->req.error) {
757 queue_complete_req(req);
758 return sizeof(struct raw1394_request);
761 hpsb_set_packet_complete_task(packet,
762 (void (*)(void *))queue_complete_cb, req);
764 spin_lock_irq(&fi->reqlists_lock);
765 list_add_tail(&req->list, &fi->req_pending);
766 spin_unlock_irq(&fi->reqlists_lock);
768 packet->generation = req->req.generation;
770 if (hpsb_send_packet(packet) < 0) {
771 req->req.error = RAW1394_ERROR_SEND_ERROR;
773 hpsb_free_tlabel(packet);
774 queue_complete_req(req);
776 return sizeof(struct raw1394_request);
779 static int handle_iso_send(struct file_info *fi, struct pending_request *req,
782 struct hpsb_packet *packet;
784 packet = hpsb_make_isopacket(fi->host, req->req.length, channel & 0x3f,
785 (req->req.misc >> 16) & 0x3,
786 req->req.misc & 0xf);
790 packet->speed_code = req->req.address & 0x3;
792 req->packet = packet;
794 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
796 req->req.error = RAW1394_ERROR_MEMFAULT;
798 queue_complete_req(req);
799 return sizeof(struct raw1394_request);
803 hpsb_set_packet_complete_task(packet,
804 (void (*)(void *))queue_complete_req,
807 spin_lock_irq(&fi->reqlists_lock);
808 list_add_tail(&req->list, &fi->req_pending);
809 spin_unlock_irq(&fi->reqlists_lock);
811 /* Update the generation of the packet just before sending. */
812 packet->generation = req->req.generation;
814 if (hpsb_send_packet(packet) < 0) {
815 req->req.error = RAW1394_ERROR_SEND_ERROR;
816 queue_complete_req(req);
819 return sizeof(struct raw1394_request);
822 static int handle_async_send(struct file_info *fi, struct pending_request *req)
824 struct hpsb_packet *packet;
825 int header_length = req->req.misc & 0xffff;
826 int expect_response = req->req.misc >> 16;
828 if ((header_length > req->req.length) || (header_length < 12)) {
829 req->req.error = RAW1394_ERROR_INVALID_ARG;
831 queue_complete_req(req);
832 return sizeof(struct raw1394_request);
835 packet = hpsb_alloc_packet(req->req.length - header_length);
836 req->packet = packet;
840 if (copy_from_user(packet->header, int2ptr(req->req.sendb),
842 req->req.error = RAW1394_ERROR_MEMFAULT;
844 queue_complete_req(req);
845 return sizeof(struct raw1394_request);
849 (packet->data, int2ptr(req->req.sendb) + header_length,
850 packet->data_size)) {
851 req->req.error = RAW1394_ERROR_MEMFAULT;
853 queue_complete_req(req);
854 return sizeof(struct raw1394_request);
857 packet->type = hpsb_async;
858 packet->node_id = packet->header[0] >> 16;
859 packet->tcode = (packet->header[0] >> 4) & 0xf;
860 packet->tlabel = (packet->header[0] >> 10) & 0x3f;
861 packet->host = fi->host;
862 packet->expect_response = expect_response;
863 packet->header_size = header_length;
864 packet->data_size = req->req.length - header_length;
867 hpsb_set_packet_complete_task(packet,
868 (void (*)(void *))queue_complete_cb, req);
870 spin_lock_irq(&fi->reqlists_lock);
871 list_add_tail(&req->list, &fi->req_pending);
872 spin_unlock_irq(&fi->reqlists_lock);
874 /* Update the generation of the packet just before sending. */
875 packet->generation = req->req.generation;
877 if (hpsb_send_packet(packet) < 0) {
878 req->req.error = RAW1394_ERROR_SEND_ERROR;
879 queue_complete_req(req);
882 return sizeof(struct raw1394_request);
885 static int arm_read(struct hpsb_host *host, int nodeid, quadlet_t * buffer,
886 u64 addr, size_t length, u16 flags)
888 struct pending_request *req;
889 struct host_info *hi;
890 struct file_info *fi = NULL;
891 struct list_head *entry;
892 struct arm_addr *arm_addr = NULL;
893 struct arm_request *arm_req = NULL;
894 struct arm_response *arm_resp = NULL;
895 int found = 0, size = 0, rcode = -1;
896 struct arm_request_response *arm_req_resp = NULL;
898 DBGMSG("arm_read called by node: %X"
899 "addr: %4.4x %8.8x length: %Zu", nodeid,
900 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
902 spin_lock(&host_info_lock);
903 hi = find_host_info(host); /* search address-entry */
905 list_for_each_entry(fi, &hi->file_info_list, list) {
906 entry = fi->addr_list.next;
907 while (entry != &(fi->addr_list)) {
909 list_entry(entry, struct arm_addr,
911 if (((arm_addr->start) <= (addr))
912 && ((arm_addr->end) >= (addr + length))) {
925 printk(KERN_ERR "raw1394: arm_read FAILED addr_entry not found"
926 " -> rcode_address_error\n");
927 spin_unlock(&host_info_lock);
928 return (RCODE_ADDRESS_ERROR);
930 DBGMSG("arm_read addr_entry FOUND");
932 if (arm_addr->rec_length < length) {
933 DBGMSG("arm_read blocklength too big -> rcode_data_error");
934 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
937 if (arm_addr->access_rights & ARM_READ) {
938 if (!(arm_addr->client_transactions & ARM_READ)) {
940 (arm_addr->addr_space_buffer) + (addr -
944 DBGMSG("arm_read -> (rcode_complete)");
945 rcode = RCODE_COMPLETE;
948 rcode = RCODE_TYPE_ERROR; /* function not allowed */
949 DBGMSG("arm_read -> rcode_type_error (access denied)");
952 if (arm_addr->notification_options & ARM_READ) {
953 DBGMSG("arm_read -> entering notification-section");
954 req = __alloc_pending_request(SLAB_ATOMIC);
956 DBGMSG("arm_read -> rcode_conflict_error");
957 spin_unlock(&host_info_lock);
958 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
959 The request may be retried */
961 if (rcode == RCODE_COMPLETE) {
963 sizeof(struct arm_request) +
964 sizeof(struct arm_response) +
965 length * sizeof(byte_t) +
966 sizeof(struct arm_request_response);
969 sizeof(struct arm_request) +
970 sizeof(struct arm_response) +
971 sizeof(struct arm_request_response);
973 req->data = kmalloc(size, SLAB_ATOMIC);
975 free_pending_request(req);
976 DBGMSG("arm_read -> rcode_conflict_error");
977 spin_unlock(&host_info_lock);
978 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
979 The request may be retried */
983 req->req.type = RAW1394_REQ_ARM;
984 req->req.generation = get_hpsb_generation(host);
986 (((length << 16) & (0xFFFF0000)) | (ARM_READ & 0xFF));
987 req->req.tag = arm_addr->arm_tag;
988 req->req.recvb = arm_addr->recvb;
989 req->req.length = size;
990 arm_req_resp = (struct arm_request_response *)(req->data);
991 arm_req = (struct arm_request *)((byte_t *) (req->data) +
994 arm_request_response)));
996 (struct arm_response *)((byte_t *) (arm_req) +
997 (sizeof(struct arm_request)));
998 arm_req->buffer = NULL;
999 arm_resp->buffer = NULL;
1000 if (rcode == RCODE_COMPLETE) {
1002 (byte_t *) arm_resp + sizeof(struct arm_response);
1004 (arm_addr->addr_space_buffer) + (addr -
1009 int2ptr((arm_addr->recvb) +
1010 sizeof(struct arm_request_response) +
1011 sizeof(struct arm_request) +
1012 sizeof(struct arm_response));
1014 arm_resp->buffer_length =
1015 (rcode == RCODE_COMPLETE) ? length : 0;
1016 arm_resp->response_code = rcode;
1017 arm_req->buffer_length = 0;
1018 arm_req->generation = req->req.generation;
1019 arm_req->extended_transaction_code = 0;
1020 arm_req->destination_offset = addr;
1021 arm_req->source_nodeid = nodeid;
1022 arm_req->destination_nodeid = host->node_id;
1023 arm_req->tlabel = (flags >> 10) & 0x3f;
1024 arm_req->tcode = (flags >> 4) & 0x0f;
1025 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1027 arm_request_response));
1028 arm_req_resp->response =
1029 int2ptr((arm_addr->recvb) +
1030 sizeof(struct arm_request_response) +
1031 sizeof(struct arm_request));
1032 queue_complete_req(req);
1034 spin_unlock(&host_info_lock);
1038 static int arm_write(struct hpsb_host *host, int nodeid, int destid,
1039 quadlet_t * data, u64 addr, size_t length, u16 flags)
1041 struct pending_request *req;
1042 struct host_info *hi;
1043 struct file_info *fi = NULL;
1044 struct list_head *entry;
1045 struct arm_addr *arm_addr = NULL;
1046 struct arm_request *arm_req = NULL;
1047 struct arm_response *arm_resp = NULL;
1048 int found = 0, size = 0, rcode = -1, length_conflict = 0;
1049 struct arm_request_response *arm_req_resp = NULL;
1051 DBGMSG("arm_write called by node: %X"
1052 "addr: %4.4x %8.8x length: %Zu", nodeid,
1053 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
1055 spin_lock(&host_info_lock);
1056 hi = find_host_info(host); /* search address-entry */
1058 list_for_each_entry(fi, &hi->file_info_list, list) {
1059 entry = fi->addr_list.next;
1060 while (entry != &(fi->addr_list)) {
1062 list_entry(entry, struct arm_addr,
1064 if (((arm_addr->start) <= (addr))
1065 && ((arm_addr->end) >= (addr + length))) {
1069 entry = entry->next;
1078 printk(KERN_ERR "raw1394: arm_write FAILED addr_entry not found"
1079 " -> rcode_address_error\n");
1080 spin_unlock(&host_info_lock);
1081 return (RCODE_ADDRESS_ERROR);
1083 DBGMSG("arm_write addr_entry FOUND");
1085 if (arm_addr->rec_length < length) {
1086 DBGMSG("arm_write blocklength too big -> rcode_data_error");
1087 length_conflict = 1;
1088 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
1091 if (arm_addr->access_rights & ARM_WRITE) {
1092 if (!(arm_addr->client_transactions & ARM_WRITE)) {
1093 memcpy((arm_addr->addr_space_buffer) +
1094 (addr - (arm_addr->start)), data,
1096 DBGMSG("arm_write -> (rcode_complete)");
1097 rcode = RCODE_COMPLETE;
1100 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1101 DBGMSG("arm_write -> rcode_type_error (access denied)");
1104 if (arm_addr->notification_options & ARM_WRITE) {
1105 DBGMSG("arm_write -> entering notification-section");
1106 req = __alloc_pending_request(SLAB_ATOMIC);
1108 DBGMSG("arm_write -> rcode_conflict_error");
1109 spin_unlock(&host_info_lock);
1110 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1111 The request my be retried */
1114 sizeof(struct arm_request) + sizeof(struct arm_response) +
1115 (length) * sizeof(byte_t) +
1116 sizeof(struct arm_request_response);
1117 req->data = kmalloc(size, SLAB_ATOMIC);
1119 free_pending_request(req);
1120 DBGMSG("arm_write -> rcode_conflict_error");
1121 spin_unlock(&host_info_lock);
1122 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1123 The request may be retried */
1126 req->file_info = fi;
1127 req->req.type = RAW1394_REQ_ARM;
1128 req->req.generation = get_hpsb_generation(host);
1130 (((length << 16) & (0xFFFF0000)) | (ARM_WRITE & 0xFF));
1131 req->req.tag = arm_addr->arm_tag;
1132 req->req.recvb = arm_addr->recvb;
1133 req->req.length = size;
1134 arm_req_resp = (struct arm_request_response *)(req->data);
1135 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1138 arm_request_response)));
1140 (struct arm_response *)((byte_t *) (arm_req) +
1141 (sizeof(struct arm_request)));
1142 arm_resp->buffer = NULL;
1143 memcpy((byte_t *) arm_resp + sizeof(struct arm_response),
1145 arm_req->buffer = int2ptr((arm_addr->recvb) +
1146 sizeof(struct arm_request_response) +
1147 sizeof(struct arm_request) +
1148 sizeof(struct arm_response));
1149 arm_req->buffer_length = length;
1150 arm_req->generation = req->req.generation;
1151 arm_req->extended_transaction_code = 0;
1152 arm_req->destination_offset = addr;
1153 arm_req->source_nodeid = nodeid;
1154 arm_req->destination_nodeid = destid;
1155 arm_req->tlabel = (flags >> 10) & 0x3f;
1156 arm_req->tcode = (flags >> 4) & 0x0f;
1157 arm_resp->buffer_length = 0;
1158 arm_resp->response_code = rcode;
1159 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1161 arm_request_response));
1162 arm_req_resp->response =
1163 int2ptr((arm_addr->recvb) +
1164 sizeof(struct arm_request_response) +
1165 sizeof(struct arm_request));
1166 queue_complete_req(req);
1168 spin_unlock(&host_info_lock);
1172 static int arm_lock(struct hpsb_host *host, int nodeid, quadlet_t * store,
1173 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
1176 struct pending_request *req;
1177 struct host_info *hi;
1178 struct file_info *fi = NULL;
1179 struct list_head *entry;
1180 struct arm_addr *arm_addr = NULL;
1181 struct arm_request *arm_req = NULL;
1182 struct arm_response *arm_resp = NULL;
1183 int found = 0, size = 0, rcode = -1;
1185 struct arm_request_response *arm_req_resp = NULL;
1187 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1188 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1189 DBGMSG("arm_lock called by node: %X "
1190 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X",
1191 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1192 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1195 DBGMSG("arm_lock called by node: %X "
1196 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X arg: %8.8X",
1197 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1198 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1199 be32_to_cpu(data), be32_to_cpu(arg));
1201 spin_lock(&host_info_lock);
1202 hi = find_host_info(host); /* search address-entry */
1204 list_for_each_entry(fi, &hi->file_info_list, list) {
1205 entry = fi->addr_list.next;
1206 while (entry != &(fi->addr_list)) {
1208 list_entry(entry, struct arm_addr,
1210 if (((arm_addr->start) <= (addr))
1211 && ((arm_addr->end) >=
1212 (addr + sizeof(*store)))) {
1216 entry = entry->next;
1225 printk(KERN_ERR "raw1394: arm_lock FAILED addr_entry not found"
1226 " -> rcode_address_error\n");
1227 spin_unlock(&host_info_lock);
1228 return (RCODE_ADDRESS_ERROR);
1230 DBGMSG("arm_lock addr_entry FOUND");
1233 if (arm_addr->access_rights & ARM_LOCK) {
1234 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1236 (arm_addr->addr_space_buffer) + (addr -
1240 switch (ext_tcode) {
1241 case (EXTCODE_MASK_SWAP):
1242 new = data | (old & ~arg);
1244 case (EXTCODE_COMPARE_SWAP):
1251 case (EXTCODE_FETCH_ADD):
1253 cpu_to_be32(be32_to_cpu(data) +
1256 case (EXTCODE_LITTLE_ADD):
1258 cpu_to_le32(le32_to_cpu(data) +
1261 case (EXTCODE_BOUNDED_ADD):
1264 cpu_to_be32(be32_to_cpu
1272 case (EXTCODE_WRAP_ADD):
1275 cpu_to_be32(be32_to_cpu
1284 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1286 "raw1394: arm_lock FAILED "
1287 "ext_tcode not allowed -> rcode_type_error\n");
1291 DBGMSG("arm_lock -> (rcode_complete)");
1292 rcode = RCODE_COMPLETE;
1293 memcpy(store, &old, sizeof(*store));
1294 memcpy((arm_addr->addr_space_buffer) +
1295 (addr - (arm_addr->start)),
1296 &new, sizeof(*store));
1300 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1301 DBGMSG("arm_lock -> rcode_type_error (access denied)");
1304 if (arm_addr->notification_options & ARM_LOCK) {
1305 byte_t *buf1, *buf2;
1306 DBGMSG("arm_lock -> entering notification-section");
1307 req = __alloc_pending_request(SLAB_ATOMIC);
1309 DBGMSG("arm_lock -> rcode_conflict_error");
1310 spin_unlock(&host_info_lock);
1311 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1312 The request may be retried */
1314 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1315 req->data = kmalloc(size, SLAB_ATOMIC);
1317 free_pending_request(req);
1318 DBGMSG("arm_lock -> rcode_conflict_error");
1319 spin_unlock(&host_info_lock);
1320 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1321 The request may be retried */
1324 arm_req_resp = (struct arm_request_response *)(req->data);
1325 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1328 arm_request_response)));
1330 (struct arm_response *)((byte_t *) (arm_req) +
1331 (sizeof(struct arm_request)));
1332 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1333 buf2 = buf1 + 2 * sizeof(*store);
1334 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1335 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1336 arm_req->buffer_length = sizeof(*store);
1337 memcpy(buf1, &data, sizeof(*store));
1340 arm_req->buffer_length = 2 * sizeof(*store);
1341 memcpy(buf1, &arg, sizeof(*store));
1342 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1344 if (rcode == RCODE_COMPLETE) {
1345 arm_resp->buffer_length = sizeof(*store);
1346 memcpy(buf2, &old, sizeof(*store));
1348 arm_resp->buffer_length = 0;
1350 req->file_info = fi;
1351 req->req.type = RAW1394_REQ_ARM;
1352 req->req.generation = get_hpsb_generation(host);
1353 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1355 req->req.tag = arm_addr->arm_tag;
1356 req->req.recvb = arm_addr->recvb;
1357 req->req.length = size;
1358 arm_req->generation = req->req.generation;
1359 arm_req->extended_transaction_code = ext_tcode;
1360 arm_req->destination_offset = addr;
1361 arm_req->source_nodeid = nodeid;
1362 arm_req->destination_nodeid = host->node_id;
1363 arm_req->tlabel = (flags >> 10) & 0x3f;
1364 arm_req->tcode = (flags >> 4) & 0x0f;
1365 arm_resp->response_code = rcode;
1366 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1368 arm_request_response));
1369 arm_req_resp->response =
1370 int2ptr((arm_addr->recvb) +
1371 sizeof(struct arm_request_response) +
1372 sizeof(struct arm_request));
1374 int2ptr((arm_addr->recvb) +
1375 sizeof(struct arm_request_response) +
1376 sizeof(struct arm_request) +
1377 sizeof(struct arm_response));
1379 int2ptr((arm_addr->recvb) +
1380 sizeof(struct arm_request_response) +
1381 sizeof(struct arm_request) +
1382 sizeof(struct arm_response) + 2 * sizeof(*store));
1383 queue_complete_req(req);
1385 spin_unlock(&host_info_lock);
1389 static int arm_lock64(struct hpsb_host *host, int nodeid, octlet_t * store,
1390 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
1393 struct pending_request *req;
1394 struct host_info *hi;
1395 struct file_info *fi = NULL;
1396 struct list_head *entry;
1397 struct arm_addr *arm_addr = NULL;
1398 struct arm_request *arm_req = NULL;
1399 struct arm_response *arm_resp = NULL;
1400 int found = 0, size = 0, rcode = -1;
1402 struct arm_request_response *arm_req_resp = NULL;
1404 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1405 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1406 DBGMSG("arm_lock64 called by node: %X "
1407 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X ",
1408 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1409 (u32) (addr & 0xFFFFFFFF),
1411 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1412 (u32) (be64_to_cpu(data) & 0xFFFFFFFF));
1414 DBGMSG("arm_lock64 called by node: %X "
1415 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X arg: "
1417 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1418 (u32) (addr & 0xFFFFFFFF),
1420 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1421 (u32) (be64_to_cpu(data) & 0xFFFFFFFF),
1422 (u32) ((be64_to_cpu(arg) >> 32) & 0xFFFFFFFF),
1423 (u32) (be64_to_cpu(arg) & 0xFFFFFFFF));
1425 spin_lock(&host_info_lock);
1426 hi = find_host_info(host); /* search addressentry in file_info's for host */
1428 list_for_each_entry(fi, &hi->file_info_list, list) {
1429 entry = fi->addr_list.next;
1430 while (entry != &(fi->addr_list)) {
1432 list_entry(entry, struct arm_addr,
1434 if (((arm_addr->start) <= (addr))
1435 && ((arm_addr->end) >=
1436 (addr + sizeof(*store)))) {
1440 entry = entry->next;
1450 "raw1394: arm_lock64 FAILED addr_entry not found"
1451 " -> rcode_address_error\n");
1452 spin_unlock(&host_info_lock);
1453 return (RCODE_ADDRESS_ERROR);
1455 DBGMSG("arm_lock64 addr_entry FOUND");
1458 if (arm_addr->access_rights & ARM_LOCK) {
1459 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1461 (arm_addr->addr_space_buffer) + (addr -
1465 switch (ext_tcode) {
1466 case (EXTCODE_MASK_SWAP):
1467 new = data | (old & ~arg);
1469 case (EXTCODE_COMPARE_SWAP):
1476 case (EXTCODE_FETCH_ADD):
1478 cpu_to_be64(be64_to_cpu(data) +
1481 case (EXTCODE_LITTLE_ADD):
1483 cpu_to_le64(le64_to_cpu(data) +
1486 case (EXTCODE_BOUNDED_ADD):
1489 cpu_to_be64(be64_to_cpu
1497 case (EXTCODE_WRAP_ADD):
1500 cpu_to_be64(be64_to_cpu
1510 "raw1394: arm_lock64 FAILED "
1511 "ext_tcode not allowed -> rcode_type_error\n");
1512 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1517 ("arm_lock64 -> (rcode_complete)");
1518 rcode = RCODE_COMPLETE;
1519 memcpy(store, &old, sizeof(*store));
1520 memcpy((arm_addr->addr_space_buffer) +
1521 (addr - (arm_addr->start)),
1522 &new, sizeof(*store));
1526 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1528 ("arm_lock64 -> rcode_type_error (access denied)");
1531 if (arm_addr->notification_options & ARM_LOCK) {
1532 byte_t *buf1, *buf2;
1533 DBGMSG("arm_lock64 -> entering notification-section");
1534 req = __alloc_pending_request(SLAB_ATOMIC);
1536 spin_unlock(&host_info_lock);
1537 DBGMSG("arm_lock64 -> rcode_conflict_error");
1538 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1539 The request may be retried */
1541 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1542 req->data = kmalloc(size, SLAB_ATOMIC);
1544 free_pending_request(req);
1545 spin_unlock(&host_info_lock);
1546 DBGMSG("arm_lock64 -> rcode_conflict_error");
1547 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1548 The request may be retried */
1551 arm_req_resp = (struct arm_request_response *)(req->data);
1552 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1555 arm_request_response)));
1557 (struct arm_response *)((byte_t *) (arm_req) +
1558 (sizeof(struct arm_request)));
1559 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1560 buf2 = buf1 + 2 * sizeof(*store);
1561 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1562 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1563 arm_req->buffer_length = sizeof(*store);
1564 memcpy(buf1, &data, sizeof(*store));
1567 arm_req->buffer_length = 2 * sizeof(*store);
1568 memcpy(buf1, &arg, sizeof(*store));
1569 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1571 if (rcode == RCODE_COMPLETE) {
1572 arm_resp->buffer_length = sizeof(*store);
1573 memcpy(buf2, &old, sizeof(*store));
1575 arm_resp->buffer_length = 0;
1577 req->file_info = fi;
1578 req->req.type = RAW1394_REQ_ARM;
1579 req->req.generation = get_hpsb_generation(host);
1580 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1582 req->req.tag = arm_addr->arm_tag;
1583 req->req.recvb = arm_addr->recvb;
1584 req->req.length = size;
1585 arm_req->generation = req->req.generation;
1586 arm_req->extended_transaction_code = ext_tcode;
1587 arm_req->destination_offset = addr;
1588 arm_req->source_nodeid = nodeid;
1589 arm_req->destination_nodeid = host->node_id;
1590 arm_req->tlabel = (flags >> 10) & 0x3f;
1591 arm_req->tcode = (flags >> 4) & 0x0f;
1592 arm_resp->response_code = rcode;
1593 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1595 arm_request_response));
1596 arm_req_resp->response =
1597 int2ptr((arm_addr->recvb) +
1598 sizeof(struct arm_request_response) +
1599 sizeof(struct arm_request));
1601 int2ptr((arm_addr->recvb) +
1602 sizeof(struct arm_request_response) +
1603 sizeof(struct arm_request) +
1604 sizeof(struct arm_response));
1606 int2ptr((arm_addr->recvb) +
1607 sizeof(struct arm_request_response) +
1608 sizeof(struct arm_request) +
1609 sizeof(struct arm_response) + 2 * sizeof(*store));
1610 queue_complete_req(req);
1612 spin_unlock(&host_info_lock);
1616 static int arm_register(struct file_info *fi, struct pending_request *req)
1619 struct arm_addr *addr;
1620 struct host_info *hi;
1621 struct file_info *fi_hlp = NULL;
1622 struct list_head *entry;
1623 struct arm_addr *arm_addr = NULL;
1624 int same_host, another_host;
1625 unsigned long flags;
1627 DBGMSG("arm_register called "
1628 "addr(Offset): %8.8x %8.8x length: %u "
1629 "rights: %2.2X notify: %2.2X "
1630 "max_blk_len: %4.4X",
1631 (u32) ((req->req.address >> 32) & 0xFFFF),
1632 (u32) (req->req.address & 0xFFFFFFFF),
1633 req->req.length, ((req->req.misc >> 8) & 0xFF),
1634 (req->req.misc & 0xFF), ((req->req.misc >> 16) & 0xFFFF));
1635 /* check addressrange */
1636 if ((((req->req.address) & ~(0xFFFFFFFFFFFFULL)) != 0) ||
1637 (((req->req.address + req->req.length) & ~(0xFFFFFFFFFFFFULL)) !=
1639 req->req.length = 0;
1642 /* addr-list-entry for fileinfo */
1643 addr = (struct arm_addr *)kmalloc(sizeof(struct arm_addr), SLAB_KERNEL);
1645 req->req.length = 0;
1648 /* allocation of addr_space_buffer */
1649 addr->addr_space_buffer = (u8 *) vmalloc(req->req.length);
1650 if (!(addr->addr_space_buffer)) {
1652 req->req.length = 0;
1655 /* initialization of addr_space_buffer */
1656 if ((req->req.sendb) == (unsigned long)NULL) {
1658 memset(addr->addr_space_buffer, 0, req->req.length);
1660 /* init: user -> kernel */
1662 (addr->addr_space_buffer, int2ptr(req->req.sendb),
1664 vfree(addr->addr_space_buffer);
1669 INIT_LIST_HEAD(&addr->addr_list);
1670 addr->arm_tag = req->req.tag;
1671 addr->start = req->req.address;
1672 addr->end = req->req.address + req->req.length;
1673 addr->access_rights = (u8) (req->req.misc & 0x0F);
1674 addr->notification_options = (u8) ((req->req.misc >> 4) & 0x0F);
1675 addr->client_transactions = (u8) ((req->req.misc >> 8) & 0x0F);
1676 addr->access_rights |= addr->client_transactions;
1677 addr->notification_options |= addr->client_transactions;
1678 addr->recvb = req->req.recvb;
1679 addr->rec_length = (u16) ((req->req.misc >> 16) & 0xFFFF);
1680 spin_lock_irqsave(&host_info_lock, flags);
1681 hi = find_host_info(fi->host);
1684 /* same host with address-entry containing same addressrange ? */
1685 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1686 entry = fi_hlp->addr_list.next;
1687 while (entry != &(fi_hlp->addr_list)) {
1689 list_entry(entry, struct arm_addr, addr_list);
1690 if ((arm_addr->start == addr->start)
1691 && (arm_addr->end == addr->end)) {
1692 DBGMSG("same host ownes same "
1693 "addressrange -> EALREADY");
1697 entry = entry->next;
1704 /* addressrange occupied by same host */
1705 vfree(addr->addr_space_buffer);
1707 spin_unlock_irqrestore(&host_info_lock, flags);
1710 /* another host with valid address-entry containing same addressrange */
1711 list_for_each_entry(hi, &host_info_list, list) {
1712 if (hi->host != fi->host) {
1713 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1714 entry = fi_hlp->addr_list.next;
1715 while (entry != &(fi_hlp->addr_list)) {
1717 list_entry(entry, struct arm_addr,
1719 if ((arm_addr->start == addr->start)
1720 && (arm_addr->end == addr->end)) {
1722 ("another host ownes same "
1727 entry = entry->next;
1736 DBGMSG("another hosts entry is valid -> SUCCESS");
1737 if (copy_to_user(int2ptr(req->req.recvb),
1738 &addr->start, sizeof(u64))) {
1739 printk(KERN_ERR "raw1394: arm_register failed "
1740 " address-range-entry is invalid -> EFAULT !!!\n");
1741 vfree(addr->addr_space_buffer);
1743 spin_unlock_irqrestore(&host_info_lock, flags);
1746 free_pending_request(req); /* immediate success or fail */
1748 list_add_tail(&addr->addr_list, &fi->addr_list);
1749 spin_unlock_irqrestore(&host_info_lock, flags);
1750 return sizeof(struct raw1394_request);
1753 hpsb_register_addrspace(&raw1394_highlevel, fi->host, &arm_ops,
1755 req->req.address + req->req.length);
1758 list_add_tail(&addr->addr_list, &fi->addr_list);
1760 DBGMSG("arm_register failed errno: %d \n", retval);
1761 vfree(addr->addr_space_buffer);
1763 spin_unlock_irqrestore(&host_info_lock, flags);
1766 spin_unlock_irqrestore(&host_info_lock, flags);
1767 free_pending_request(req); /* immediate success or fail */
1768 return sizeof(struct raw1394_request);
1771 static int arm_unregister(struct file_info *fi, struct pending_request *req)
1775 struct list_head *entry;
1776 struct arm_addr *addr = NULL;
1777 struct host_info *hi;
1778 struct file_info *fi_hlp = NULL;
1779 struct arm_addr *arm_addr = NULL;
1781 unsigned long flags;
1783 DBGMSG("arm_Unregister called addr(Offset): "
1785 (u32) ((req->req.address >> 32) & 0xFFFF),
1786 (u32) (req->req.address & 0xFFFFFFFF));
1787 spin_lock_irqsave(&host_info_lock, flags);
1789 entry = fi->addr_list.next;
1790 while (entry != &(fi->addr_list)) {
1791 addr = list_entry(entry, struct arm_addr, addr_list);
1792 if (addr->start == req->req.address) {
1796 entry = entry->next;
1799 DBGMSG("arm_Unregister addr not found");
1800 spin_unlock_irqrestore(&host_info_lock, flags);
1803 DBGMSG("arm_Unregister addr found");
1805 /* another host with valid address-entry containing
1806 same addressrange */
1807 list_for_each_entry(hi, &host_info_list, list) {
1808 if (hi->host != fi->host) {
1809 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1810 entry = fi_hlp->addr_list.next;
1811 while (entry != &(fi_hlp->addr_list)) {
1812 arm_addr = list_entry(entry,
1815 if (arm_addr->start == addr->start) {
1816 DBGMSG("another host ownes "
1817 "same addressrange");
1821 entry = entry->next;
1830 DBGMSG("delete entry from list -> success");
1831 list_del(&addr->addr_list);
1832 vfree(addr->addr_space_buffer);
1834 free_pending_request(req); /* immediate success or fail */
1835 spin_unlock_irqrestore(&host_info_lock, flags);
1836 return sizeof(struct raw1394_request);
1839 hpsb_unregister_addrspace(&raw1394_highlevel, fi->host,
1842 printk(KERN_ERR "raw1394: arm_Unregister failed -> EINVAL\n");
1843 spin_unlock_irqrestore(&host_info_lock, flags);
1846 DBGMSG("delete entry from list -> success");
1847 list_del(&addr->addr_list);
1848 spin_unlock_irqrestore(&host_info_lock, flags);
1849 vfree(addr->addr_space_buffer);
1851 free_pending_request(req); /* immediate success or fail */
1852 return sizeof(struct raw1394_request);
1855 /* Copy data from ARM buffer(s) to user buffer. */
1856 static int arm_get_buf(struct file_info *fi, struct pending_request *req)
1858 struct arm_addr *arm_addr = NULL;
1859 unsigned long flags;
1860 unsigned long offset;
1862 struct list_head *entry;
1864 DBGMSG("arm_get_buf "
1865 "addr(Offset): %04X %08X length: %u",
1866 (u32) ((req->req.address >> 32) & 0xFFFF),
1867 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
1869 spin_lock_irqsave(&host_info_lock, flags);
1870 entry = fi->addr_list.next;
1871 while (entry != &(fi->addr_list)) {
1872 arm_addr = list_entry(entry, struct arm_addr, addr_list);
1873 if ((arm_addr->start <= req->req.address) &&
1874 (arm_addr->end > req->req.address)) {
1875 if (req->req.address + req->req.length <= arm_addr->end) {
1876 offset = req->req.address - arm_addr->start;
1879 ("arm_get_buf copy_to_user( %08X, %p, %u )",
1880 (u32) req->req.recvb,
1881 arm_addr->addr_space_buffer + offset,
1882 (u32) req->req.length);
1885 (int2ptr(req->req.recvb),
1886 arm_addr->addr_space_buffer + offset,
1888 spin_unlock_irqrestore(&host_info_lock,
1893 spin_unlock_irqrestore(&host_info_lock, flags);
1894 /* We have to free the request, because we
1895 * queue no response, and therefore nobody
1897 free_pending_request(req);
1898 return sizeof(struct raw1394_request);
1900 DBGMSG("arm_get_buf request exceeded mapping");
1901 spin_unlock_irqrestore(&host_info_lock, flags);
1905 entry = entry->next;
1907 spin_unlock_irqrestore(&host_info_lock, flags);
1911 /* Copy data from user buffer to ARM buffer(s). */
1912 static int arm_set_buf(struct file_info *fi, struct pending_request *req)
1914 struct arm_addr *arm_addr = NULL;
1915 unsigned long flags;
1916 unsigned long offset;
1918 struct list_head *entry;
1920 DBGMSG("arm_set_buf "
1921 "addr(Offset): %04X %08X length: %u",
1922 (u32) ((req->req.address >> 32) & 0xFFFF),
1923 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
1925 spin_lock_irqsave(&host_info_lock, flags);
1926 entry = fi->addr_list.next;
1927 while (entry != &(fi->addr_list)) {
1928 arm_addr = list_entry(entry, struct arm_addr, addr_list);
1929 if ((arm_addr->start <= req->req.address) &&
1930 (arm_addr->end > req->req.address)) {
1931 if (req->req.address + req->req.length <= arm_addr->end) {
1932 offset = req->req.address - arm_addr->start;
1935 ("arm_set_buf copy_from_user( %p, %08X, %u )",
1936 arm_addr->addr_space_buffer + offset,
1937 (u32) req->req.sendb,
1938 (u32) req->req.length);
1941 (arm_addr->addr_space_buffer + offset,
1942 int2ptr(req->req.sendb),
1944 spin_unlock_irqrestore(&host_info_lock,
1949 spin_unlock_irqrestore(&host_info_lock, flags);
1950 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
1951 return sizeof(struct raw1394_request);
1953 DBGMSG("arm_set_buf request exceeded mapping");
1954 spin_unlock_irqrestore(&host_info_lock, flags);
1958 entry = entry->next;
1960 spin_unlock_irqrestore(&host_info_lock, flags);
1964 static int reset_notification(struct file_info *fi, struct pending_request *req)
1966 DBGMSG("reset_notification called - switch %s ",
1967 (req->req.misc == RAW1394_NOTIFY_OFF) ? "OFF" : "ON");
1968 if ((req->req.misc == RAW1394_NOTIFY_OFF) ||
1969 (req->req.misc == RAW1394_NOTIFY_ON)) {
1970 fi->notification = (u8) req->req.misc;
1971 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
1972 return sizeof(struct raw1394_request);
1974 /* error EINVAL (22) invalid argument */
1978 static int write_phypacket(struct file_info *fi, struct pending_request *req)
1980 struct hpsb_packet *packet = NULL;
1984 data = be32_to_cpu((u32) req->req.sendb);
1985 DBGMSG("write_phypacket called - quadlet 0x%8.8x ", data);
1986 packet = hpsb_make_phypacket(fi->host, data);
1989 req->req.length = 0;
1990 req->packet = packet;
1991 hpsb_set_packet_complete_task(packet,
1992 (void (*)(void *))queue_complete_cb, req);
1993 spin_lock_irq(&fi->reqlists_lock);
1994 list_add_tail(&req->list, &fi->req_pending);
1995 spin_unlock_irq(&fi->reqlists_lock);
1996 packet->generation = req->req.generation;
1997 retval = hpsb_send_packet(packet);
1998 DBGMSG("write_phypacket send_packet called => retval: %d ", retval);
2000 req->req.error = RAW1394_ERROR_SEND_ERROR;
2001 req->req.length = 0;
2002 queue_complete_req(req);
2004 return sizeof(struct raw1394_request);
2007 static int get_config_rom(struct file_info *fi, struct pending_request *req)
2009 int ret = sizeof(struct raw1394_request);
2010 quadlet_t *data = kmalloc(req->req.length, SLAB_KERNEL);
2017 csr1212_read(fi->host->csr.rom, CSR1212_CONFIG_ROM_SPACE_OFFSET,
2018 data, req->req.length);
2019 if (copy_to_user(int2ptr(req->req.recvb), data, req->req.length))
2022 (int2ptr(req->req.tag), &fi->host->csr.rom->cache_head->len,
2023 sizeof(fi->host->csr.rom->cache_head->len)))
2025 if (copy_to_user(int2ptr(req->req.address), &fi->host->csr.generation,
2026 sizeof(fi->host->csr.generation)))
2028 if (copy_to_user(int2ptr(req->req.sendb), &status, sizeof(status)))
2032 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2037 static int update_config_rom(struct file_info *fi, struct pending_request *req)
2039 int ret = sizeof(struct raw1394_request);
2040 quadlet_t *data = kmalloc(req->req.length, SLAB_KERNEL);
2043 if (copy_from_user(data, int2ptr(req->req.sendb), req->req.length)) {
2046 int status = hpsb_update_config_rom(fi->host,
2047 data, req->req.length,
2048 (unsigned char)req->req.
2051 (int2ptr(req->req.recvb), &status, sizeof(status)))
2056 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2062 static int modify_config_rom(struct file_info *fi, struct pending_request *req)
2064 struct csr1212_keyval *kv;
2065 struct csr1212_csr_rom_cache *cache;
2066 struct csr1212_dentry *dentry;
2070 if (req->req.misc == ~0) {
2071 if (req->req.length == 0)
2074 /* Find an unused slot */
2076 dr < RAW1394_MAX_USER_CSR_DIRS && fi->csr1212_dirs[dr];
2079 if (dr == RAW1394_MAX_USER_CSR_DIRS)
2082 fi->csr1212_dirs[dr] =
2083 csr1212_new_directory(CSR1212_KV_ID_VENDOR);
2084 if (!fi->csr1212_dirs[dr])
2088 if (!fi->csr1212_dirs[dr])
2091 /* Delete old stuff */
2093 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2094 dentry; dentry = dentry->next) {
2095 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2100 if (req->req.length == 0) {
2101 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2102 fi->csr1212_dirs[dr] = NULL;
2104 hpsb_update_config_rom_image(fi->host);
2105 free_pending_request(req);
2106 return sizeof(struct raw1394_request);
2110 cache = csr1212_rom_cache_malloc(0, req->req.length);
2112 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2113 fi->csr1212_dirs[dr] = NULL;
2117 cache->filled_head =
2118 kmalloc(sizeof(struct csr1212_cache_region), GFP_KERNEL);
2119 if (!cache->filled_head) {
2120 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2121 fi->csr1212_dirs[dr] = NULL;
2122 CSR1212_FREE(cache);
2125 cache->filled_tail = cache->filled_head;
2127 if (copy_from_user(cache->data, int2ptr(req->req.sendb),
2129 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2130 fi->csr1212_dirs[dr] = NULL;
2131 CSR1212_FREE(cache);
2134 cache->len = req->req.length;
2135 cache->filled_head->offset_start = 0;
2136 cache->filled_head->offset_end = cache->size - 1;
2138 cache->layout_head = cache->layout_tail = fi->csr1212_dirs[dr];
2140 ret = CSR1212_SUCCESS;
2141 /* parse all the items */
2142 for (kv = cache->layout_head; ret == CSR1212_SUCCESS && kv;
2144 ret = csr1212_parse_keyval(kv, cache);
2147 /* attach top level items to the root directory */
2149 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2150 ret == CSR1212_SUCCESS && dentry; dentry = dentry->next) {
2152 csr1212_attach_keyval_to_directory(fi->host->csr.
2157 if (ret == CSR1212_SUCCESS) {
2158 ret = hpsb_update_config_rom_image(fi->host);
2160 if (ret >= 0 && copy_to_user(int2ptr(req->req.recvb),
2166 kfree(cache->filled_head);
2170 /* we have to free the request, because we queue no response,
2171 * and therefore nobody will free it */
2172 free_pending_request(req);
2173 return sizeof(struct raw1394_request);
2176 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2177 dentry; dentry = dentry->next) {
2178 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2182 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2183 fi->csr1212_dirs[dr] = NULL;
2188 static int state_connected(struct file_info *fi, struct pending_request *req)
2190 int node = req->req.address >> 48;
2192 req->req.error = RAW1394_ERROR_NONE;
2194 switch (req->req.type) {
2196 case RAW1394_REQ_ECHO:
2197 queue_complete_req(req);
2198 return sizeof(struct raw1394_request);
2200 case RAW1394_REQ_ISO_SEND:
2201 return handle_iso_send(fi, req, node);
2203 case RAW1394_REQ_ARM_REGISTER:
2204 return arm_register(fi, req);
2206 case RAW1394_REQ_ARM_UNREGISTER:
2207 return arm_unregister(fi, req);
2209 case RAW1394_REQ_ARM_SET_BUF:
2210 return arm_set_buf(fi, req);
2212 case RAW1394_REQ_ARM_GET_BUF:
2213 return arm_get_buf(fi, req);
2215 case RAW1394_REQ_RESET_NOTIFY:
2216 return reset_notification(fi, req);
2218 case RAW1394_REQ_ISO_LISTEN:
2219 handle_iso_listen(fi, req);
2220 return sizeof(struct raw1394_request);
2222 case RAW1394_REQ_FCP_LISTEN:
2223 handle_fcp_listen(fi, req);
2224 return sizeof(struct raw1394_request);
2226 case RAW1394_REQ_RESET_BUS:
2227 if (req->req.misc == RAW1394_LONG_RESET) {
2228 DBGMSG("busreset called (type: LONG)");
2229 hpsb_reset_bus(fi->host, LONG_RESET);
2230 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2231 return sizeof(struct raw1394_request);
2233 if (req->req.misc == RAW1394_SHORT_RESET) {
2234 DBGMSG("busreset called (type: SHORT)");
2235 hpsb_reset_bus(fi->host, SHORT_RESET);
2236 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2237 return sizeof(struct raw1394_request);
2239 /* error EINVAL (22) invalid argument */
2241 case RAW1394_REQ_GET_ROM:
2242 return get_config_rom(fi, req);
2244 case RAW1394_REQ_UPDATE_ROM:
2245 return update_config_rom(fi, req);
2247 case RAW1394_REQ_MODIFY_ROM:
2248 return modify_config_rom(fi, req);
2251 if (req->req.generation != get_hpsb_generation(fi->host)) {
2252 req->req.error = RAW1394_ERROR_GENERATION;
2253 req->req.generation = get_hpsb_generation(fi->host);
2254 req->req.length = 0;
2255 queue_complete_req(req);
2256 return sizeof(struct raw1394_request);
2259 switch (req->req.type) {
2260 case RAW1394_REQ_PHYPACKET:
2261 return write_phypacket(fi, req);
2262 case RAW1394_REQ_ASYNC_SEND:
2263 return handle_async_send(fi, req);
2266 if (req->req.length == 0) {
2267 req->req.error = RAW1394_ERROR_INVALID_ARG;
2268 queue_complete_req(req);
2269 return sizeof(struct raw1394_request);
2272 return handle_async_request(fi, req, node);
2275 static ssize_t raw1394_write(struct file *file, const char __user * buffer,
2276 size_t count, loff_t * offset_is_ignored)
2278 struct file_info *fi = (struct file_info *)file->private_data;
2279 struct pending_request *req;
2282 if (count != sizeof(struct raw1394_request)) {
2286 req = alloc_pending_request();
2290 req->file_info = fi;
2292 if (copy_from_user(&req->req, buffer, sizeof(struct raw1394_request))) {
2293 free_pending_request(req);
2297 switch (fi->state) {
2299 retval = state_opened(fi, req);
2303 retval = state_initialized(fi, req);
2307 retval = state_connected(fi, req);
2312 free_pending_request(req);
2318 /* rawiso operations */
2320 /* check if any RAW1394_REQ_RAWISO_ACTIVITY event is already in the
2321 * completion queue (reqlists_lock must be taken) */
2322 static inline int __rawiso_event_in_queue(struct file_info *fi)
2324 struct pending_request *req;
2326 list_for_each_entry(req, &fi->req_complete, list)
2327 if (req->req.type == RAW1394_REQ_RAWISO_ACTIVITY)
2333 /* put a RAWISO_ACTIVITY event in the queue, if one isn't there already */
2334 static void queue_rawiso_event(struct file_info *fi)
2336 unsigned long flags;
2338 spin_lock_irqsave(&fi->reqlists_lock, flags);
2340 /* only one ISO activity event may be in the queue */
2341 if (!__rawiso_event_in_queue(fi)) {
2342 struct pending_request *req =
2343 __alloc_pending_request(SLAB_ATOMIC);
2346 req->file_info = fi;
2347 req->req.type = RAW1394_REQ_RAWISO_ACTIVITY;
2348 req->req.generation = get_hpsb_generation(fi->host);
2349 __queue_complete_req(req);
2351 /* on allocation failure, signal an overflow */
2352 if (fi->iso_handle) {
2353 atomic_inc(&fi->iso_handle->overflows);
2357 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2360 static void rawiso_activity_cb(struct hpsb_iso *iso)
2362 unsigned long flags;
2363 struct host_info *hi;
2364 struct file_info *fi;
2366 spin_lock_irqsave(&host_info_lock, flags);
2367 hi = find_host_info(iso->host);
2370 list_for_each_entry(fi, &hi->file_info_list, list) {
2371 if (fi->iso_handle == iso)
2372 queue_rawiso_event(fi);
2376 spin_unlock_irqrestore(&host_info_lock, flags);
2379 /* helper function - gather all the kernel iso status bits for returning to user-space */
2380 static void raw1394_iso_fill_status(struct hpsb_iso *iso,
2381 struct raw1394_iso_status *stat)
2383 stat->config.data_buf_size = iso->buf_size;
2384 stat->config.buf_packets = iso->buf_packets;
2385 stat->config.channel = iso->channel;
2386 stat->config.speed = iso->speed;
2387 stat->config.irq_interval = iso->irq_interval;
2388 stat->n_packets = hpsb_iso_n_ready(iso);
2389 stat->overflows = atomic_read(&iso->overflows);
2390 stat->xmit_cycle = iso->xmit_cycle;
2393 static int raw1394_iso_xmit_init(struct file_info *fi, void __user * uaddr)
2395 struct raw1394_iso_status stat;
2400 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2403 fi->iso_handle = hpsb_iso_xmit_init(fi->host,
2404 stat.config.data_buf_size,
2405 stat.config.buf_packets,
2406 stat.config.channel,
2408 stat.config.irq_interval,
2409 rawiso_activity_cb);
2410 if (!fi->iso_handle)
2413 fi->iso_state = RAW1394_ISO_XMIT;
2415 raw1394_iso_fill_status(fi->iso_handle, &stat);
2416 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2419 /* queue an event to get things started */
2420 rawiso_activity_cb(fi->iso_handle);
2425 static int raw1394_iso_recv_init(struct file_info *fi, void __user * uaddr)
2427 struct raw1394_iso_status stat;
2432 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2435 fi->iso_handle = hpsb_iso_recv_init(fi->host,
2436 stat.config.data_buf_size,
2437 stat.config.buf_packets,
2438 stat.config.channel,
2439 stat.config.dma_mode,
2440 stat.config.irq_interval,
2441 rawiso_activity_cb);
2442 if (!fi->iso_handle)
2445 fi->iso_state = RAW1394_ISO_RECV;
2447 raw1394_iso_fill_status(fi->iso_handle, &stat);
2448 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2453 static int raw1394_iso_get_status(struct file_info *fi, void __user * uaddr)
2455 struct raw1394_iso_status stat;
2456 struct hpsb_iso *iso = fi->iso_handle;
2458 raw1394_iso_fill_status(fi->iso_handle, &stat);
2459 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2462 /* reset overflow counter */
2463 atomic_set(&iso->overflows, 0);
2468 /* copy N packet_infos out of the ringbuffer into user-supplied array */
2469 static int raw1394_iso_recv_packets(struct file_info *fi, void __user * uaddr)
2471 struct raw1394_iso_packets upackets;
2472 unsigned int packet = fi->iso_handle->first_packet;
2475 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2478 if (upackets.n_packets > hpsb_iso_n_ready(fi->iso_handle))
2481 /* ensure user-supplied buffer is accessible and big enough */
2482 if (!access_ok(VERIFY_WRITE, upackets.infos,
2483 upackets.n_packets *
2484 sizeof(struct raw1394_iso_packet_info)))
2487 /* copy the packet_infos out */
2488 for (i = 0; i < upackets.n_packets; i++) {
2489 if (__copy_to_user(&upackets.infos[i],
2490 &fi->iso_handle->infos[packet],
2491 sizeof(struct raw1394_iso_packet_info)))
2494 packet = (packet + 1) % fi->iso_handle->buf_packets;
2500 /* copy N packet_infos from user to ringbuffer, and queue them for transmission */
2501 static int raw1394_iso_send_packets(struct file_info *fi, void __user * uaddr)
2503 struct raw1394_iso_packets upackets;
2506 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2509 if (upackets.n_packets > hpsb_iso_n_ready(fi->iso_handle))
2512 /* ensure user-supplied buffer is accessible and big enough */
2513 if (!access_ok(VERIFY_READ, upackets.infos,
2514 upackets.n_packets *
2515 sizeof(struct raw1394_iso_packet_info)))
2518 /* copy the infos structs in and queue the packets */
2519 for (i = 0; i < upackets.n_packets; i++) {
2520 struct raw1394_iso_packet_info info;
2522 if (__copy_from_user(&info, &upackets.infos[i],
2523 sizeof(struct raw1394_iso_packet_info)))
2526 rv = hpsb_iso_xmit_queue_packet(fi->iso_handle, info.offset,
2527 info.len, info.tag, info.sy);
2535 static void raw1394_iso_shutdown(struct file_info *fi)
2538 hpsb_iso_shutdown(fi->iso_handle);
2540 fi->iso_handle = NULL;
2541 fi->iso_state = RAW1394_ISO_INACTIVE;
2544 /* mmap the rawiso xmit/recv buffer */
2545 static int raw1394_mmap(struct file *file, struct vm_area_struct *vma)
2547 struct file_info *fi = file->private_data;
2549 if (fi->iso_state == RAW1394_ISO_INACTIVE)
2552 return dma_region_mmap(&fi->iso_handle->data_buf, file, vma);
2555 /* ioctl is only used for rawiso operations */
2556 static int raw1394_ioctl(struct inode *inode, struct file *file,
2557 unsigned int cmd, unsigned long arg)
2559 struct file_info *fi = file->private_data;
2560 void __user *argp = (void __user *)arg;
2562 switch (fi->iso_state) {
2563 case RAW1394_ISO_INACTIVE:
2565 case RAW1394_IOC_ISO_XMIT_INIT:
2566 return raw1394_iso_xmit_init(fi, argp);
2567 case RAW1394_IOC_ISO_RECV_INIT:
2568 return raw1394_iso_recv_init(fi, argp);
2573 case RAW1394_ISO_RECV:
2575 case RAW1394_IOC_ISO_RECV_START:{
2576 /* copy args from user-space */
2579 (&args[0], argp, sizeof(args)))
2581 return hpsb_iso_recv_start(fi->iso_handle,
2585 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2586 hpsb_iso_stop(fi->iso_handle);
2588 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL:
2589 return hpsb_iso_recv_listen_channel(fi->iso_handle,
2591 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
2592 return hpsb_iso_recv_unlisten_channel(fi->iso_handle,
2594 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:{
2595 /* copy the u64 from user-space */
2597 if (copy_from_user(&mask, argp, sizeof(mask)))
2599 return hpsb_iso_recv_set_channel_mask(fi->
2603 case RAW1394_IOC_ISO_GET_STATUS:
2604 return raw1394_iso_get_status(fi, argp);
2605 case RAW1394_IOC_ISO_RECV_PACKETS:
2606 return raw1394_iso_recv_packets(fi, argp);
2607 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
2608 return hpsb_iso_recv_release_packets(fi->iso_handle,
2610 case RAW1394_IOC_ISO_RECV_FLUSH:
2611 return hpsb_iso_recv_flush(fi->iso_handle);
2612 case RAW1394_IOC_ISO_SHUTDOWN:
2613 raw1394_iso_shutdown(fi);
2615 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2616 queue_rawiso_event(fi);
2620 case RAW1394_ISO_XMIT:
2622 case RAW1394_IOC_ISO_XMIT_START:{
2623 /* copy two ints from user-space */
2626 (&args[0], argp, sizeof(args)))
2628 return hpsb_iso_xmit_start(fi->iso_handle,
2631 case RAW1394_IOC_ISO_XMIT_SYNC:
2632 return hpsb_iso_xmit_sync(fi->iso_handle);
2633 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2634 hpsb_iso_stop(fi->iso_handle);
2636 case RAW1394_IOC_ISO_GET_STATUS:
2637 return raw1394_iso_get_status(fi, argp);
2638 case RAW1394_IOC_ISO_XMIT_PACKETS:
2639 return raw1394_iso_send_packets(fi, argp);
2640 case RAW1394_IOC_ISO_SHUTDOWN:
2641 raw1394_iso_shutdown(fi);
2643 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2644 queue_rawiso_event(fi);
2655 static unsigned int raw1394_poll(struct file *file, poll_table * pt)
2657 struct file_info *fi = file->private_data;
2658 unsigned int mask = POLLOUT | POLLWRNORM;
2660 poll_wait(file, &fi->poll_wait_complete, pt);
2662 spin_lock_irq(&fi->reqlists_lock);
2663 if (!list_empty(&fi->req_complete)) {
2664 mask |= POLLIN | POLLRDNORM;
2666 spin_unlock_irq(&fi->reqlists_lock);
2671 static int raw1394_open(struct inode *inode, struct file *file)
2673 struct file_info *fi;
2675 fi = kmalloc(sizeof(struct file_info), SLAB_KERNEL);
2679 memset(fi, 0, sizeof(struct file_info));
2680 fi->notification = (u8) RAW1394_NOTIFY_ON; /* busreset notification */
2682 INIT_LIST_HEAD(&fi->list);
2684 INIT_LIST_HEAD(&fi->req_pending);
2685 INIT_LIST_HEAD(&fi->req_complete);
2686 sema_init(&fi->complete_sem, 0);
2687 spin_lock_init(&fi->reqlists_lock);
2688 init_waitqueue_head(&fi->poll_wait_complete);
2689 INIT_LIST_HEAD(&fi->addr_list);
2691 file->private_data = fi;
2696 static int raw1394_release(struct inode *inode, struct file *file)
2698 struct file_info *fi = file->private_data;
2699 struct list_head *lh;
2700 struct pending_request *req;
2701 int done = 0, i, fail = 0;
2703 struct list_head *entry;
2704 struct arm_addr *addr = NULL;
2705 struct host_info *hi;
2706 struct file_info *fi_hlp = NULL;
2707 struct arm_addr *arm_addr = NULL;
2711 if (fi->iso_state != RAW1394_ISO_INACTIVE)
2712 raw1394_iso_shutdown(fi);
2714 for (i = 0; i < 64; i++) {
2715 if (fi->listen_channels & (1ULL << i)) {
2716 hpsb_unlisten_channel(&raw1394_highlevel, fi->host, i);
2720 spin_lock_irq(&host_info_lock);
2721 fi->listen_channels = 0;
2722 spin_unlock_irq(&host_info_lock);
2725 /* set address-entries invalid */
2726 spin_lock_irq(&host_info_lock);
2728 while (!list_empty(&fi->addr_list)) {
2730 lh = fi->addr_list.next;
2731 addr = list_entry(lh, struct arm_addr, addr_list);
2732 /* another host with valid address-entry containing
2733 same addressrange? */
2734 list_for_each_entry(hi, &host_info_list, list) {
2735 if (hi->host != fi->host) {
2736 list_for_each_entry(fi_hlp, &hi->file_info_list,
2738 entry = fi_hlp->addr_list.next;
2739 while (entry != &(fi_hlp->addr_list)) {
2740 arm_addr = list_entry(entry,
2744 if (arm_addr->start ==
2747 ("raw1394_release: "
2748 "another host ownes "
2749 "same addressrange");
2753 entry = entry->next;
2761 if (!another_host) {
2762 DBGMSG("raw1394_release: call hpsb_arm_unregister");
2764 hpsb_unregister_addrspace(&raw1394_highlevel,
2765 fi->host, addr->start);
2769 "raw1394_release arm_Unregister failed\n");
2772 DBGMSG("raw1394_release: delete addr_entry from list");
2773 list_del(&addr->addr_list);
2774 vfree(addr->addr_space_buffer);
2777 spin_unlock_irq(&host_info_lock);
2779 printk(KERN_ERR "raw1394: during addr_list-release "
2780 "error(s) occurred \n");
2784 spin_lock_irq(&fi->reqlists_lock);
2786 while (!list_empty(&fi->req_complete)) {
2787 lh = fi->req_complete.next;
2790 req = list_entry(lh, struct pending_request, list);
2792 free_pending_request(req);
2795 if (list_empty(&fi->req_pending))
2798 spin_unlock_irq(&fi->reqlists_lock);
2801 down_interruptible(&fi->complete_sem);
2804 /* Remove any sub-trees left by user space programs */
2805 for (i = 0; i < RAW1394_MAX_USER_CSR_DIRS; i++) {
2806 struct csr1212_dentry *dentry;
2807 if (!fi->csr1212_dirs[i])
2810 fi->csr1212_dirs[i]->value.directory.dentries_head; dentry;
2811 dentry = dentry->next) {
2812 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2816 csr1212_release_keyval(fi->csr1212_dirs[i]);
2817 fi->csr1212_dirs[i] = NULL;
2821 if ((csr_mod || fi->cfgrom_upd)
2822 && hpsb_update_config_rom_image(fi->host) < 0)
2824 ("Failed to generate Configuration ROM image for host %d",
2827 if (fi->state == connected) {
2828 spin_lock_irq(&host_info_lock);
2829 list_del(&fi->list);
2830 spin_unlock_irq(&host_info_lock);
2832 put_device(&fi->host->device);
2840 /*** HOTPLUG STUFF **********************************************************/
2842 * Export information about protocols/devices supported by this driver.
2844 static struct ieee1394_device_id raw1394_id_table[] = {
2846 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2847 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
2848 .version = AVC_SW_VERSION_ENTRY & 0xffffff},
2850 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2851 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2852 .version = CAMERA_SW_VERSION_ENTRY & 0xffffff},
2854 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2855 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2856 .version = (CAMERA_SW_VERSION_ENTRY + 1) & 0xffffff},
2858 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2859 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2860 .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff},
2864 MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table);
2866 static struct hpsb_protocol_driver raw1394_driver = {
2867 .name = "raw1394 Driver",
2868 .id_table = raw1394_id_table,
2871 .bus = &ieee1394_bus_type,
2875 /******************************************************************************/
2877 static struct hpsb_highlevel raw1394_highlevel = {
2878 .name = RAW1394_DEVICE_NAME,
2879 .add_host = add_host,
2880 .remove_host = remove_host,
2881 .host_reset = host_reset,
2882 .iso_receive = iso_receive,
2883 .fcp_request = fcp_request,
2886 static struct cdev raw1394_cdev;
2887 static struct file_operations raw1394_fops = {
2888 .owner = THIS_MODULE,
2889 .read = raw1394_read,
2890 .write = raw1394_write,
2891 .mmap = raw1394_mmap,
2892 .ioctl = raw1394_ioctl,
2893 .poll = raw1394_poll,
2894 .open = raw1394_open,
2895 .release = raw1394_release,
2898 static int __init init_raw1394(void)
2902 hpsb_register_highlevel(&raw1394_highlevel);
2904 if (IS_ERR(class_simple_device_add(hpsb_protocol_class, MKDEV(
2905 IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16),
2906 NULL, RAW1394_DEVICE_NAME))) {
2911 devfs_mk_cdev(MKDEV(
2912 IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16),
2913 S_IFCHR | S_IRUSR | S_IWUSR, RAW1394_DEVICE_NAME);
2915 cdev_init(&raw1394_cdev, &raw1394_fops);
2916 raw1394_cdev.owner = THIS_MODULE;
2917 kobject_set_name(&raw1394_cdev.kobj, RAW1394_DEVICE_NAME);
2918 ret = cdev_add(&raw1394_cdev, IEEE1394_RAW1394_DEV, 1);
2920 HPSB_ERR("raw1394 failed to register minor device block");
2924 HPSB_INFO("raw1394: /dev/%s device initialized", RAW1394_DEVICE_NAME);
2926 ret = hpsb_register_protocol(&raw1394_driver);
2928 HPSB_ERR("raw1394: failed to register protocol");
2929 cdev_del(&raw1394_cdev);
2936 devfs_remove(RAW1394_DEVICE_NAME);
2937 class_simple_device_remove(MKDEV(
2938 IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16));
2940 hpsb_unregister_highlevel(&raw1394_highlevel);
2945 static void __exit cleanup_raw1394(void)
2947 class_simple_device_remove(MKDEV(
2948 IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16));
2949 cdev_del(&raw1394_cdev);
2950 devfs_remove(RAW1394_DEVICE_NAME);
2951 hpsb_unregister_highlevel(&raw1394_highlevel);
2952 hpsb_unregister_protocol(&raw1394_driver);
2955 module_init(init_raw1394);
2956 module_exit(cleanup_raw1394);
2957 MODULE_LICENSE("GPL");
2958 MODULE_ALIAS_CHARDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16);