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 = kzalloc(sizeof(*req), flags);
107 INIT_LIST_HEAD(&req->list);
112 static inline struct pending_request *alloc_pending_request(void)
114 return __alloc_pending_request(SLAB_KERNEL);
117 static void free_pending_request(struct pending_request *req)
120 if (atomic_dec_and_test(&req->ibs->refcount)) {
121 atomic_sub(req->ibs->data_size, &iso_buffer_size);
124 } else if (req->free_data) {
127 hpsb_free_packet(req->packet);
131 /* fi->reqlists_lock must be taken */
132 static void __queue_complete_req(struct pending_request *req)
134 struct file_info *fi = req->file_info;
135 list_del(&req->list);
136 list_add_tail(&req->list, &fi->req_complete);
138 up(&fi->complete_sem);
139 wake_up_interruptible(&fi->poll_wait_complete);
142 static void queue_complete_req(struct pending_request *req)
145 struct file_info *fi = req->file_info;
147 spin_lock_irqsave(&fi->reqlists_lock, flags);
148 __queue_complete_req(req);
149 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
152 static void queue_complete_cb(struct pending_request *req)
154 struct hpsb_packet *packet = req->packet;
155 int rcode = (packet->header[1] >> 12) & 0xf;
157 switch (packet->ack_code) {
159 case ACKX_SEND_ERROR:
160 req->req.error = RAW1394_ERROR_SEND_ERROR;
163 req->req.error = RAW1394_ERROR_ABORTED;
166 req->req.error = RAW1394_ERROR_TIMEOUT;
169 req->req.error = (packet->ack_code << 16) | rcode;
173 if (!((packet->ack_code == ACK_PENDING) && (rcode == RCODE_COMPLETE))) {
177 if ((req->req.type == RAW1394_REQ_ASYNC_READ) ||
178 (req->req.type == RAW1394_REQ_ASYNC_WRITE) ||
179 (req->req.type == RAW1394_REQ_ASYNC_STREAM) ||
180 (req->req.type == RAW1394_REQ_LOCK) ||
181 (req->req.type == RAW1394_REQ_LOCK64))
182 hpsb_free_tlabel(packet);
184 queue_complete_req(req);
187 static void add_host(struct hpsb_host *host)
189 struct host_info *hi;
192 hi = kmalloc(sizeof(*hi), GFP_KERNEL);
195 INIT_LIST_HEAD(&hi->list);
197 INIT_LIST_HEAD(&hi->file_info_list);
199 spin_lock_irqsave(&host_info_lock, flags);
200 list_add_tail(&hi->list, &host_info_list);
202 spin_unlock_irqrestore(&host_info_lock, flags);
205 atomic_inc(&internal_generation);
208 static struct host_info *find_host_info(struct hpsb_host *host)
210 struct host_info *hi;
212 list_for_each_entry(hi, &host_info_list, list)
213 if (hi->host == host)
219 static void remove_host(struct hpsb_host *host)
221 struct host_info *hi;
224 spin_lock_irqsave(&host_info_lock, flags);
225 hi = find_host_info(host);
231 FIXME: address ranges should be removed
232 and fileinfo states should be initialized
233 (including setting generation to
234 internal-generation ...)
237 spin_unlock_irqrestore(&host_info_lock, flags);
240 printk(KERN_ERR "raw1394: attempt to remove unknown host "
247 atomic_inc(&internal_generation);
250 static void host_reset(struct hpsb_host *host)
253 struct host_info *hi;
254 struct file_info *fi;
255 struct pending_request *req;
257 spin_lock_irqsave(&host_info_lock, flags);
258 hi = find_host_info(host);
261 list_for_each_entry(fi, &hi->file_info_list, list) {
262 if (fi->notification == RAW1394_NOTIFY_ON) {
263 req = __alloc_pending_request(SLAB_ATOMIC);
267 req->req.type = RAW1394_REQ_BUS_RESET;
268 req->req.generation =
269 get_hpsb_generation(host);
270 req->req.misc = (host->node_id << 16)
272 if (fi->protocol_version > 3) {
279 queue_complete_req(req);
284 spin_unlock_irqrestore(&host_info_lock, flags);
287 static void iso_receive(struct hpsb_host *host, int channel, quadlet_t * data,
291 struct host_info *hi;
292 struct file_info *fi;
293 struct pending_request *req, *req_next;
294 struct iso_block_store *ibs = NULL;
297 if ((atomic_read(&iso_buffer_size) + length) > iso_buffer_max) {
298 HPSB_INFO("dropped iso packet");
302 spin_lock_irqsave(&host_info_lock, flags);
303 hi = find_host_info(host);
306 list_for_each_entry(fi, &hi->file_info_list, list) {
307 if (!(fi->listen_channels & (1ULL << channel)))
310 req = __alloc_pending_request(SLAB_ATOMIC);
315 ibs = kmalloc(sizeof(*ibs) + length,
322 atomic_add(length, &iso_buffer_size);
323 atomic_set(&ibs->refcount, 0);
324 ibs->data_size = length;
325 memcpy(ibs->data, data, length);
328 atomic_inc(&ibs->refcount);
332 req->data = ibs->data;
333 req->req.type = RAW1394_REQ_ISO_RECEIVE;
334 req->req.generation = get_hpsb_generation(host);
336 req->req.recvb = ptr2int(fi->iso_buffer);
337 req->req.length = min(length, fi->iso_buffer_length);
339 list_add_tail(&req->list, &reqs);
342 spin_unlock_irqrestore(&host_info_lock, flags);
344 list_for_each_entry_safe(req, req_next, &reqs, list)
345 queue_complete_req(req);
348 static void fcp_request(struct hpsb_host *host, int nodeid, int direction,
349 int cts, u8 * data, size_t length)
352 struct host_info *hi;
353 struct file_info *fi;
354 struct pending_request *req, *req_next;
355 struct iso_block_store *ibs = NULL;
358 if ((atomic_read(&iso_buffer_size) + length) > iso_buffer_max) {
359 HPSB_INFO("dropped fcp request");
363 spin_lock_irqsave(&host_info_lock, flags);
364 hi = find_host_info(host);
367 list_for_each_entry(fi, &hi->file_info_list, list) {
371 req = __alloc_pending_request(SLAB_ATOMIC);
376 ibs = kmalloc(sizeof(*ibs) + length,
383 atomic_add(length, &iso_buffer_size);
384 atomic_set(&ibs->refcount, 0);
385 ibs->data_size = length;
386 memcpy(ibs->data, data, length);
389 atomic_inc(&ibs->refcount);
393 req->data = ibs->data;
394 req->req.type = RAW1394_REQ_FCP_REQUEST;
395 req->req.generation = get_hpsb_generation(host);
396 req->req.misc = nodeid | (direction << 16);
397 req->req.recvb = ptr2int(fi->fcp_buffer);
398 req->req.length = length;
400 list_add_tail(&req->list, &reqs);
403 spin_unlock_irqrestore(&host_info_lock, flags);
405 list_for_each_entry_safe(req, req_next, &reqs, list)
406 queue_complete_req(req);
409 static ssize_t raw1394_read(struct file *file, char __user * buffer,
410 size_t count, loff_t * offset_is_ignored)
413 struct file_info *fi = (struct file_info *)file->private_data;
414 struct list_head *lh;
415 struct pending_request *req;
418 if (count != sizeof(struct raw1394_request)) {
422 if (!access_ok(VERIFY_WRITE, buffer, count)) {
426 if (file->f_flags & O_NONBLOCK) {
427 if (down_trylock(&fi->complete_sem)) {
431 if (down_interruptible(&fi->complete_sem)) {
436 spin_lock_irqsave(&fi->reqlists_lock, flags);
437 lh = fi->req_complete.next;
439 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
441 req = list_entry(lh, struct pending_request, list);
443 if (req->req.length) {
444 if (copy_to_user(int2ptr(req->req.recvb), req->data,
446 req->req.error = RAW1394_ERROR_MEMFAULT;
449 if (copy_to_user(buffer, &req->req, sizeof(req->req))) {
454 ret = (ssize_t) sizeof(struct raw1394_request);
456 free_pending_request(req);
460 static int state_opened(struct file_info *fi, struct pending_request *req)
462 if (req->req.type == RAW1394_REQ_INITIALIZE) {
463 switch (req->req.misc) {
464 case RAW1394_KERNELAPI_VERSION:
466 fi->state = initialized;
467 fi->protocol_version = req->req.misc;
468 req->req.error = RAW1394_ERROR_NONE;
469 req->req.generation = atomic_read(&internal_generation);
473 req->req.error = RAW1394_ERROR_COMPAT;
474 req->req.misc = RAW1394_KERNELAPI_VERSION;
477 req->req.error = RAW1394_ERROR_STATE_ORDER;
481 queue_complete_req(req);
482 return sizeof(struct raw1394_request);
485 static int state_initialized(struct file_info *fi, struct pending_request *req)
488 struct host_info *hi;
489 struct raw1394_khost_list *khl;
491 if (req->req.generation != atomic_read(&internal_generation)) {
492 req->req.error = RAW1394_ERROR_GENERATION;
493 req->req.generation = atomic_read(&internal_generation);
495 queue_complete_req(req);
496 return sizeof(struct raw1394_request);
499 switch (req->req.type) {
500 case RAW1394_REQ_LIST_CARDS:
501 spin_lock_irqsave(&host_info_lock, flags);
502 khl = kmalloc(sizeof(*khl) * host_count, SLAB_ATOMIC);
505 req->req.misc = host_count;
506 req->data = (quadlet_t *) khl;
508 list_for_each_entry(hi, &host_info_list, list) {
509 khl->nodes = hi->host->node_count;
510 strcpy(khl->name, hi->host->driver->name);
514 spin_unlock_irqrestore(&host_info_lock, flags);
517 req->req.error = RAW1394_ERROR_NONE;
518 req->req.length = min(req->req.length,
520 (struct raw1394_khost_list)
528 case RAW1394_REQ_SET_CARD:
529 spin_lock_irqsave(&host_info_lock, flags);
530 if (req->req.misc < host_count) {
531 list_for_each_entry(hi, &host_info_list, list) {
532 if (!req->req.misc--)
535 get_device(&hi->host->device); // XXX Need to handle failure case
536 list_add_tail(&fi->list, &hi->file_info_list);
538 fi->state = connected;
540 req->req.error = RAW1394_ERROR_NONE;
541 req->req.generation = get_hpsb_generation(fi->host);
542 req->req.misc = (fi->host->node_id << 16)
543 | fi->host->node_count;
544 if (fi->protocol_version > 3) {
546 NODEID_TO_NODE(fi->host->irm_id) << 8;
549 req->req.error = RAW1394_ERROR_INVALID_ARG;
551 spin_unlock_irqrestore(&host_info_lock, flags);
557 req->req.error = RAW1394_ERROR_STATE_ORDER;
562 queue_complete_req(req);
563 return sizeof(struct raw1394_request);
566 static void handle_iso_listen(struct file_info *fi, struct pending_request *req)
568 int channel = req->req.misc;
570 if ((channel > 63) || (channel < -64)) {
571 req->req.error = RAW1394_ERROR_INVALID_ARG;
572 } else if (channel >= 0) {
573 /* allocate channel req.misc */
574 if (fi->listen_channels & (1ULL << channel)) {
575 req->req.error = RAW1394_ERROR_ALREADY;
577 if (hpsb_listen_channel
578 (&raw1394_highlevel, fi->host, channel)) {
579 req->req.error = RAW1394_ERROR_ALREADY;
581 fi->listen_channels |= 1ULL << channel;
582 fi->iso_buffer = int2ptr(req->req.recvb);
583 fi->iso_buffer_length = req->req.length;
587 /* deallocate channel (one's complement neg) req.misc */
590 if (fi->listen_channels & (1ULL << channel)) {
591 hpsb_unlisten_channel(&raw1394_highlevel, fi->host,
593 fi->listen_channels &= ~(1ULL << channel);
595 req->req.error = RAW1394_ERROR_INVALID_ARG;
600 queue_complete_req(req);
603 static void handle_fcp_listen(struct file_info *fi, struct pending_request *req)
606 if (fi->fcp_buffer) {
607 req->req.error = RAW1394_ERROR_ALREADY;
609 fi->fcp_buffer = int2ptr(req->req.recvb);
612 if (!fi->fcp_buffer) {
613 req->req.error = RAW1394_ERROR_ALREADY;
615 fi->fcp_buffer = NULL;
620 queue_complete_req(req);
623 static int handle_async_request(struct file_info *fi,
624 struct pending_request *req, int node)
627 struct hpsb_packet *packet = NULL;
628 u64 addr = req->req.address & 0xffffffffffffULL;
630 switch (req->req.type) {
631 case RAW1394_REQ_ASYNC_READ:
632 DBGMSG("read_request called");
634 hpsb_make_readpacket(fi->host, node, addr, req->req.length);
639 if (req->req.length == 4)
640 req->data = &packet->header[3];
642 req->data = packet->data;
646 case RAW1394_REQ_ASYNC_WRITE:
647 DBGMSG("write_request called");
649 packet = hpsb_make_writepacket(fi->host, node, addr, NULL,
654 if (req->req.length == 4) {
656 (&packet->header[3], int2ptr(req->req.sendb),
658 req->req.error = RAW1394_ERROR_MEMFAULT;
661 (packet->data, int2ptr(req->req.sendb),
663 req->req.error = RAW1394_ERROR_MEMFAULT;
669 case RAW1394_REQ_ASYNC_STREAM:
670 DBGMSG("stream_request called");
673 hpsb_make_streampacket(fi->host, NULL, req->req.length,
674 node & 0x3f /*channel */ ,
675 (req->req.misc >> 16) & 0x3,
676 req->req.misc & 0xf);
680 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
682 req->req.error = RAW1394_ERROR_MEMFAULT;
687 case RAW1394_REQ_LOCK:
688 DBGMSG("lock_request called");
689 if ((req->req.misc == EXTCODE_FETCH_ADD)
690 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
691 if (req->req.length != 4) {
692 req->req.error = RAW1394_ERROR_INVALID_ARG;
696 if (req->req.length != 8) {
697 req->req.error = RAW1394_ERROR_INVALID_ARG;
702 packet = hpsb_make_lockpacket(fi->host, node, addr,
703 req->req.misc, NULL, 0);
707 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
709 req->req.error = RAW1394_ERROR_MEMFAULT;
713 req->data = packet->data;
717 case RAW1394_REQ_LOCK64:
718 DBGMSG("lock64_request called");
719 if ((req->req.misc == EXTCODE_FETCH_ADD)
720 || (req->req.misc == EXTCODE_LITTLE_ADD)) {
721 if (req->req.length != 8) {
722 req->req.error = RAW1394_ERROR_INVALID_ARG;
726 if (req->req.length != 16) {
727 req->req.error = RAW1394_ERROR_INVALID_ARG;
731 packet = hpsb_make_lock64packet(fi->host, node, addr,
732 req->req.misc, NULL, 0);
736 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
738 req->req.error = RAW1394_ERROR_MEMFAULT;
742 req->data = packet->data;
747 req->req.error = RAW1394_ERROR_STATE_ORDER;
750 req->packet = packet;
752 if (req->req.error) {
754 queue_complete_req(req);
755 return sizeof(struct raw1394_request);
758 hpsb_set_packet_complete_task(packet,
759 (void (*)(void *))queue_complete_cb, req);
761 spin_lock_irqsave(&fi->reqlists_lock, flags);
762 list_add_tail(&req->list, &fi->req_pending);
763 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
765 packet->generation = req->req.generation;
767 if (hpsb_send_packet(packet) < 0) {
768 req->req.error = RAW1394_ERROR_SEND_ERROR;
770 hpsb_free_tlabel(packet);
771 queue_complete_req(req);
773 return sizeof(struct raw1394_request);
776 static int handle_iso_send(struct file_info *fi, struct pending_request *req,
780 struct hpsb_packet *packet;
782 packet = hpsb_make_isopacket(fi->host, req->req.length, channel & 0x3f,
783 (req->req.misc >> 16) & 0x3,
784 req->req.misc & 0xf);
788 packet->speed_code = req->req.address & 0x3;
790 req->packet = packet;
792 if (copy_from_user(packet->data, int2ptr(req->req.sendb),
794 req->req.error = RAW1394_ERROR_MEMFAULT;
796 queue_complete_req(req);
797 return sizeof(struct raw1394_request);
801 hpsb_set_packet_complete_task(packet,
802 (void (*)(void *))queue_complete_req,
805 spin_lock_irqsave(&fi->reqlists_lock, flags);
806 list_add_tail(&req->list, &fi->req_pending);
807 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
809 /* Update the generation of the packet just before sending. */
810 packet->generation = req->req.generation;
812 if (hpsb_send_packet(packet) < 0) {
813 req->req.error = RAW1394_ERROR_SEND_ERROR;
814 queue_complete_req(req);
817 return sizeof(struct raw1394_request);
820 static int handle_async_send(struct file_info *fi, struct pending_request *req)
823 struct hpsb_packet *packet;
824 int header_length = req->req.misc & 0xffff;
825 int expect_response = req->req.misc >> 16;
827 if ((header_length > req->req.length) || (header_length < 12)) {
828 req->req.error = RAW1394_ERROR_INVALID_ARG;
830 queue_complete_req(req);
831 return sizeof(struct raw1394_request);
834 packet = hpsb_alloc_packet(req->req.length - header_length);
835 req->packet = packet;
839 if (copy_from_user(packet->header, int2ptr(req->req.sendb),
841 req->req.error = RAW1394_ERROR_MEMFAULT;
843 queue_complete_req(req);
844 return sizeof(struct raw1394_request);
848 (packet->data, int2ptr(req->req.sendb) + header_length,
849 packet->data_size)) {
850 req->req.error = RAW1394_ERROR_MEMFAULT;
852 queue_complete_req(req);
853 return sizeof(struct raw1394_request);
856 packet->type = hpsb_async;
857 packet->node_id = packet->header[0] >> 16;
858 packet->tcode = (packet->header[0] >> 4) & 0xf;
859 packet->tlabel = (packet->header[0] >> 10) & 0x3f;
860 packet->host = fi->host;
861 packet->expect_response = expect_response;
862 packet->header_size = header_length;
863 packet->data_size = req->req.length - header_length;
866 hpsb_set_packet_complete_task(packet,
867 (void (*)(void *))queue_complete_cb, req);
869 spin_lock_irqsave(&fi->reqlists_lock, flags);
870 list_add_tail(&req->list, &fi->req_pending);
871 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
873 /* Update the generation of the packet just before sending. */
874 packet->generation = req->req.generation;
876 if (hpsb_send_packet(packet) < 0) {
877 req->req.error = RAW1394_ERROR_SEND_ERROR;
878 queue_complete_req(req);
881 return sizeof(struct raw1394_request);
884 static int arm_read(struct hpsb_host *host, int nodeid, quadlet_t * buffer,
885 u64 addr, size_t length, u16 flags)
887 unsigned long irqflags;
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_irqsave(&host_info_lock, irqflags);
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_irqrestore(&host_info_lock, irqflags);
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_irqrestore(&host_info_lock, irqflags);
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_irqrestore(&host_info_lock, irqflags);
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_irqrestore(&host_info_lock, irqflags);
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 unsigned long irqflags;
1042 struct pending_request *req;
1043 struct host_info *hi;
1044 struct file_info *fi = NULL;
1045 struct list_head *entry;
1046 struct arm_addr *arm_addr = NULL;
1047 struct arm_request *arm_req = NULL;
1048 struct arm_response *arm_resp = NULL;
1049 int found = 0, size = 0, rcode = -1, length_conflict = 0;
1050 struct arm_request_response *arm_req_resp = NULL;
1052 DBGMSG("arm_write called by node: %X"
1053 "addr: %4.4x %8.8x length: %Zu", nodeid,
1054 (u16) ((addr >> 32) & 0xFFFF), (u32) (addr & 0xFFFFFFFF),
1056 spin_lock_irqsave(&host_info_lock, irqflags);
1057 hi = find_host_info(host); /* search address-entry */
1059 list_for_each_entry(fi, &hi->file_info_list, list) {
1060 entry = fi->addr_list.next;
1061 while (entry != &(fi->addr_list)) {
1063 list_entry(entry, struct arm_addr,
1065 if (((arm_addr->start) <= (addr))
1066 && ((arm_addr->end) >= (addr + length))) {
1070 entry = entry->next;
1079 printk(KERN_ERR "raw1394: arm_write FAILED addr_entry not found"
1080 " -> rcode_address_error\n");
1081 spin_unlock_irqrestore(&host_info_lock, irqflags);
1082 return (RCODE_ADDRESS_ERROR);
1084 DBGMSG("arm_write addr_entry FOUND");
1086 if (arm_addr->rec_length < length) {
1087 DBGMSG("arm_write blocklength too big -> rcode_data_error");
1088 length_conflict = 1;
1089 rcode = RCODE_DATA_ERROR; /* hardware error, data is unavailable */
1092 if (arm_addr->access_rights & ARM_WRITE) {
1093 if (!(arm_addr->client_transactions & ARM_WRITE)) {
1094 memcpy((arm_addr->addr_space_buffer) +
1095 (addr - (arm_addr->start)), data,
1097 DBGMSG("arm_write -> (rcode_complete)");
1098 rcode = RCODE_COMPLETE;
1101 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1102 DBGMSG("arm_write -> rcode_type_error (access denied)");
1105 if (arm_addr->notification_options & ARM_WRITE) {
1106 DBGMSG("arm_write -> entering notification-section");
1107 req = __alloc_pending_request(SLAB_ATOMIC);
1109 DBGMSG("arm_write -> rcode_conflict_error");
1110 spin_unlock_irqrestore(&host_info_lock, irqflags);
1111 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1112 The request my be retried */
1115 sizeof(struct arm_request) + sizeof(struct arm_response) +
1116 (length) * sizeof(byte_t) +
1117 sizeof(struct arm_request_response);
1118 req->data = kmalloc(size, SLAB_ATOMIC);
1120 free_pending_request(req);
1121 DBGMSG("arm_write -> rcode_conflict_error");
1122 spin_unlock_irqrestore(&host_info_lock, irqflags);
1123 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1124 The request may be retried */
1127 req->file_info = fi;
1128 req->req.type = RAW1394_REQ_ARM;
1129 req->req.generation = get_hpsb_generation(host);
1131 (((length << 16) & (0xFFFF0000)) | (ARM_WRITE & 0xFF));
1132 req->req.tag = arm_addr->arm_tag;
1133 req->req.recvb = arm_addr->recvb;
1134 req->req.length = size;
1135 arm_req_resp = (struct arm_request_response *)(req->data);
1136 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1139 arm_request_response)));
1141 (struct arm_response *)((byte_t *) (arm_req) +
1142 (sizeof(struct arm_request)));
1143 arm_resp->buffer = NULL;
1144 memcpy((byte_t *) arm_resp + sizeof(struct arm_response),
1146 arm_req->buffer = int2ptr((arm_addr->recvb) +
1147 sizeof(struct arm_request_response) +
1148 sizeof(struct arm_request) +
1149 sizeof(struct arm_response));
1150 arm_req->buffer_length = length;
1151 arm_req->generation = req->req.generation;
1152 arm_req->extended_transaction_code = 0;
1153 arm_req->destination_offset = addr;
1154 arm_req->source_nodeid = nodeid;
1155 arm_req->destination_nodeid = destid;
1156 arm_req->tlabel = (flags >> 10) & 0x3f;
1157 arm_req->tcode = (flags >> 4) & 0x0f;
1158 arm_resp->buffer_length = 0;
1159 arm_resp->response_code = rcode;
1160 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1162 arm_request_response));
1163 arm_req_resp->response =
1164 int2ptr((arm_addr->recvb) +
1165 sizeof(struct arm_request_response) +
1166 sizeof(struct arm_request));
1167 queue_complete_req(req);
1169 spin_unlock_irqrestore(&host_info_lock, irqflags);
1173 static int arm_lock(struct hpsb_host *host, int nodeid, quadlet_t * store,
1174 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
1177 unsigned long irqflags;
1178 struct pending_request *req;
1179 struct host_info *hi;
1180 struct file_info *fi = NULL;
1181 struct list_head *entry;
1182 struct arm_addr *arm_addr = NULL;
1183 struct arm_request *arm_req = NULL;
1184 struct arm_response *arm_resp = NULL;
1185 int found = 0, size = 0, rcode = -1;
1187 struct arm_request_response *arm_req_resp = NULL;
1189 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1190 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1191 DBGMSG("arm_lock called by node: %X "
1192 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X",
1193 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1194 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1197 DBGMSG("arm_lock called by node: %X "
1198 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X arg: %8.8X",
1199 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1200 (u32) (addr & 0xFFFFFFFF), ext_tcode & 0xFF,
1201 be32_to_cpu(data), be32_to_cpu(arg));
1203 spin_lock_irqsave(&host_info_lock, irqflags);
1204 hi = find_host_info(host); /* search address-entry */
1206 list_for_each_entry(fi, &hi->file_info_list, list) {
1207 entry = fi->addr_list.next;
1208 while (entry != &(fi->addr_list)) {
1210 list_entry(entry, struct arm_addr,
1212 if (((arm_addr->start) <= (addr))
1213 && ((arm_addr->end) >=
1214 (addr + sizeof(*store)))) {
1218 entry = entry->next;
1227 printk(KERN_ERR "raw1394: arm_lock FAILED addr_entry not found"
1228 " -> rcode_address_error\n");
1229 spin_unlock_irqrestore(&host_info_lock, irqflags);
1230 return (RCODE_ADDRESS_ERROR);
1232 DBGMSG("arm_lock addr_entry FOUND");
1235 if (arm_addr->access_rights & ARM_LOCK) {
1236 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1238 (arm_addr->addr_space_buffer) + (addr -
1242 switch (ext_tcode) {
1243 case (EXTCODE_MASK_SWAP):
1244 new = data | (old & ~arg);
1246 case (EXTCODE_COMPARE_SWAP):
1253 case (EXTCODE_FETCH_ADD):
1255 cpu_to_be32(be32_to_cpu(data) +
1258 case (EXTCODE_LITTLE_ADD):
1260 cpu_to_le32(le32_to_cpu(data) +
1263 case (EXTCODE_BOUNDED_ADD):
1266 cpu_to_be32(be32_to_cpu
1274 case (EXTCODE_WRAP_ADD):
1277 cpu_to_be32(be32_to_cpu
1286 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1288 "raw1394: arm_lock FAILED "
1289 "ext_tcode not allowed -> rcode_type_error\n");
1293 DBGMSG("arm_lock -> (rcode_complete)");
1294 rcode = RCODE_COMPLETE;
1295 memcpy(store, &old, sizeof(*store));
1296 memcpy((arm_addr->addr_space_buffer) +
1297 (addr - (arm_addr->start)),
1298 &new, sizeof(*store));
1302 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1303 DBGMSG("arm_lock -> rcode_type_error (access denied)");
1306 if (arm_addr->notification_options & ARM_LOCK) {
1307 byte_t *buf1, *buf2;
1308 DBGMSG("arm_lock -> entering notification-section");
1309 req = __alloc_pending_request(SLAB_ATOMIC);
1311 DBGMSG("arm_lock -> rcode_conflict_error");
1312 spin_unlock_irqrestore(&host_info_lock, irqflags);
1313 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1314 The request may be retried */
1316 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1317 req->data = kmalloc(size, SLAB_ATOMIC);
1319 free_pending_request(req);
1320 DBGMSG("arm_lock -> rcode_conflict_error");
1321 spin_unlock_irqrestore(&host_info_lock, irqflags);
1322 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1323 The request may be retried */
1326 arm_req_resp = (struct arm_request_response *)(req->data);
1327 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1330 arm_request_response)));
1332 (struct arm_response *)((byte_t *) (arm_req) +
1333 (sizeof(struct arm_request)));
1334 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1335 buf2 = buf1 + 2 * sizeof(*store);
1336 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1337 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1338 arm_req->buffer_length = sizeof(*store);
1339 memcpy(buf1, &data, sizeof(*store));
1342 arm_req->buffer_length = 2 * sizeof(*store);
1343 memcpy(buf1, &arg, sizeof(*store));
1344 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1346 if (rcode == RCODE_COMPLETE) {
1347 arm_resp->buffer_length = sizeof(*store);
1348 memcpy(buf2, &old, sizeof(*store));
1350 arm_resp->buffer_length = 0;
1352 req->file_info = fi;
1353 req->req.type = RAW1394_REQ_ARM;
1354 req->req.generation = get_hpsb_generation(host);
1355 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1357 req->req.tag = arm_addr->arm_tag;
1358 req->req.recvb = arm_addr->recvb;
1359 req->req.length = size;
1360 arm_req->generation = req->req.generation;
1361 arm_req->extended_transaction_code = ext_tcode;
1362 arm_req->destination_offset = addr;
1363 arm_req->source_nodeid = nodeid;
1364 arm_req->destination_nodeid = host->node_id;
1365 arm_req->tlabel = (flags >> 10) & 0x3f;
1366 arm_req->tcode = (flags >> 4) & 0x0f;
1367 arm_resp->response_code = rcode;
1368 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1370 arm_request_response));
1371 arm_req_resp->response =
1372 int2ptr((arm_addr->recvb) +
1373 sizeof(struct arm_request_response) +
1374 sizeof(struct arm_request));
1376 int2ptr((arm_addr->recvb) +
1377 sizeof(struct arm_request_response) +
1378 sizeof(struct arm_request) +
1379 sizeof(struct arm_response));
1381 int2ptr((arm_addr->recvb) +
1382 sizeof(struct arm_request_response) +
1383 sizeof(struct arm_request) +
1384 sizeof(struct arm_response) + 2 * sizeof(*store));
1385 queue_complete_req(req);
1387 spin_unlock_irqrestore(&host_info_lock, irqflags);
1391 static int arm_lock64(struct hpsb_host *host, int nodeid, octlet_t * store,
1392 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
1395 unsigned long irqflags;
1396 struct pending_request *req;
1397 struct host_info *hi;
1398 struct file_info *fi = NULL;
1399 struct list_head *entry;
1400 struct arm_addr *arm_addr = NULL;
1401 struct arm_request *arm_req = NULL;
1402 struct arm_response *arm_resp = NULL;
1403 int found = 0, size = 0, rcode = -1;
1405 struct arm_request_response *arm_req_resp = NULL;
1407 if (((ext_tcode & 0xFF) == EXTCODE_FETCH_ADD) ||
1408 ((ext_tcode & 0xFF) == EXTCODE_LITTLE_ADD)) {
1409 DBGMSG("arm_lock64 called by node: %X "
1410 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X ",
1411 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1412 (u32) (addr & 0xFFFFFFFF),
1414 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1415 (u32) (be64_to_cpu(data) & 0xFFFFFFFF));
1417 DBGMSG("arm_lock64 called by node: %X "
1418 "addr: %4.4x %8.8x extcode: %2.2X data: %8.8X %8.8X arg: "
1420 nodeid, (u16) ((addr >> 32) & 0xFFFF),
1421 (u32) (addr & 0xFFFFFFFF),
1423 (u32) ((be64_to_cpu(data) >> 32) & 0xFFFFFFFF),
1424 (u32) (be64_to_cpu(data) & 0xFFFFFFFF),
1425 (u32) ((be64_to_cpu(arg) >> 32) & 0xFFFFFFFF),
1426 (u32) (be64_to_cpu(arg) & 0xFFFFFFFF));
1428 spin_lock_irqsave(&host_info_lock, irqflags);
1429 hi = find_host_info(host); /* search addressentry in file_info's for host */
1431 list_for_each_entry(fi, &hi->file_info_list, list) {
1432 entry = fi->addr_list.next;
1433 while (entry != &(fi->addr_list)) {
1435 list_entry(entry, struct arm_addr,
1437 if (((arm_addr->start) <= (addr))
1438 && ((arm_addr->end) >=
1439 (addr + sizeof(*store)))) {
1443 entry = entry->next;
1453 "raw1394: arm_lock64 FAILED addr_entry not found"
1454 " -> rcode_address_error\n");
1455 spin_unlock_irqrestore(&host_info_lock, irqflags);
1456 return (RCODE_ADDRESS_ERROR);
1458 DBGMSG("arm_lock64 addr_entry FOUND");
1461 if (arm_addr->access_rights & ARM_LOCK) {
1462 if (!(arm_addr->client_transactions & ARM_LOCK)) {
1464 (arm_addr->addr_space_buffer) + (addr -
1468 switch (ext_tcode) {
1469 case (EXTCODE_MASK_SWAP):
1470 new = data | (old & ~arg);
1472 case (EXTCODE_COMPARE_SWAP):
1479 case (EXTCODE_FETCH_ADD):
1481 cpu_to_be64(be64_to_cpu(data) +
1484 case (EXTCODE_LITTLE_ADD):
1486 cpu_to_le64(le64_to_cpu(data) +
1489 case (EXTCODE_BOUNDED_ADD):
1492 cpu_to_be64(be64_to_cpu
1500 case (EXTCODE_WRAP_ADD):
1503 cpu_to_be64(be64_to_cpu
1513 "raw1394: arm_lock64 FAILED "
1514 "ext_tcode not allowed -> rcode_type_error\n");
1515 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1520 ("arm_lock64 -> (rcode_complete)");
1521 rcode = RCODE_COMPLETE;
1522 memcpy(store, &old, sizeof(*store));
1523 memcpy((arm_addr->addr_space_buffer) +
1524 (addr - (arm_addr->start)),
1525 &new, sizeof(*store));
1529 rcode = RCODE_TYPE_ERROR; /* function not allowed */
1531 ("arm_lock64 -> rcode_type_error (access denied)");
1534 if (arm_addr->notification_options & ARM_LOCK) {
1535 byte_t *buf1, *buf2;
1536 DBGMSG("arm_lock64 -> entering notification-section");
1537 req = __alloc_pending_request(SLAB_ATOMIC);
1539 spin_unlock_irqrestore(&host_info_lock, irqflags);
1540 DBGMSG("arm_lock64 -> rcode_conflict_error");
1541 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1542 The request may be retried */
1544 size = sizeof(struct arm_request) + sizeof(struct arm_response) + 3 * sizeof(*store) + sizeof(struct arm_request_response); /* maximum */
1545 req->data = kmalloc(size, SLAB_ATOMIC);
1547 free_pending_request(req);
1548 spin_unlock_irqrestore(&host_info_lock, irqflags);
1549 DBGMSG("arm_lock64 -> rcode_conflict_error");
1550 return (RCODE_CONFLICT_ERROR); /* A resource conflict was detected.
1551 The request may be retried */
1554 arm_req_resp = (struct arm_request_response *)(req->data);
1555 arm_req = (struct arm_request *)((byte_t *) (req->data) +
1558 arm_request_response)));
1560 (struct arm_response *)((byte_t *) (arm_req) +
1561 (sizeof(struct arm_request)));
1562 buf1 = (byte_t *) arm_resp + sizeof(struct arm_response);
1563 buf2 = buf1 + 2 * sizeof(*store);
1564 if ((ext_tcode == EXTCODE_FETCH_ADD) ||
1565 (ext_tcode == EXTCODE_LITTLE_ADD)) {
1566 arm_req->buffer_length = sizeof(*store);
1567 memcpy(buf1, &data, sizeof(*store));
1570 arm_req->buffer_length = 2 * sizeof(*store);
1571 memcpy(buf1, &arg, sizeof(*store));
1572 memcpy(buf1 + sizeof(*store), &data, sizeof(*store));
1574 if (rcode == RCODE_COMPLETE) {
1575 arm_resp->buffer_length = sizeof(*store);
1576 memcpy(buf2, &old, sizeof(*store));
1578 arm_resp->buffer_length = 0;
1580 req->file_info = fi;
1581 req->req.type = RAW1394_REQ_ARM;
1582 req->req.generation = get_hpsb_generation(host);
1583 req->req.misc = ((((sizeof(*store)) << 16) & (0xFFFF0000)) |
1585 req->req.tag = arm_addr->arm_tag;
1586 req->req.recvb = arm_addr->recvb;
1587 req->req.length = size;
1588 arm_req->generation = req->req.generation;
1589 arm_req->extended_transaction_code = ext_tcode;
1590 arm_req->destination_offset = addr;
1591 arm_req->source_nodeid = nodeid;
1592 arm_req->destination_nodeid = host->node_id;
1593 arm_req->tlabel = (flags >> 10) & 0x3f;
1594 arm_req->tcode = (flags >> 4) & 0x0f;
1595 arm_resp->response_code = rcode;
1596 arm_req_resp->request = int2ptr((arm_addr->recvb) +
1598 arm_request_response));
1599 arm_req_resp->response =
1600 int2ptr((arm_addr->recvb) +
1601 sizeof(struct arm_request_response) +
1602 sizeof(struct arm_request));
1604 int2ptr((arm_addr->recvb) +
1605 sizeof(struct arm_request_response) +
1606 sizeof(struct arm_request) +
1607 sizeof(struct arm_response));
1609 int2ptr((arm_addr->recvb) +
1610 sizeof(struct arm_request_response) +
1611 sizeof(struct arm_request) +
1612 sizeof(struct arm_response) + 2 * sizeof(*store));
1613 queue_complete_req(req);
1615 spin_unlock_irqrestore(&host_info_lock, irqflags);
1619 static int arm_register(struct file_info *fi, struct pending_request *req)
1622 struct arm_addr *addr;
1623 struct host_info *hi;
1624 struct file_info *fi_hlp = NULL;
1625 struct list_head *entry;
1626 struct arm_addr *arm_addr = NULL;
1627 int same_host, another_host;
1628 unsigned long flags;
1630 DBGMSG("arm_register called "
1631 "addr(Offset): %8.8x %8.8x length: %u "
1632 "rights: %2.2X notify: %2.2X "
1633 "max_blk_len: %4.4X",
1634 (u32) ((req->req.address >> 32) & 0xFFFF),
1635 (u32) (req->req.address & 0xFFFFFFFF),
1636 req->req.length, ((req->req.misc >> 8) & 0xFF),
1637 (req->req.misc & 0xFF), ((req->req.misc >> 16) & 0xFFFF));
1638 /* check addressrange */
1639 if ((((req->req.address) & ~(0xFFFFFFFFFFFFULL)) != 0) ||
1640 (((req->req.address + req->req.length) & ~(0xFFFFFFFFFFFFULL)) !=
1642 req->req.length = 0;
1645 /* addr-list-entry for fileinfo */
1646 addr = kmalloc(sizeof(*addr), SLAB_KERNEL);
1648 req->req.length = 0;
1651 /* allocation of addr_space_buffer */
1652 addr->addr_space_buffer = vmalloc(req->req.length);
1653 if (!(addr->addr_space_buffer)) {
1655 req->req.length = 0;
1658 /* initialization of addr_space_buffer */
1659 if ((req->req.sendb) == (unsigned long)NULL) {
1661 memset(addr->addr_space_buffer, 0, req->req.length);
1663 /* init: user -> kernel */
1665 (addr->addr_space_buffer, int2ptr(req->req.sendb),
1667 vfree(addr->addr_space_buffer);
1672 INIT_LIST_HEAD(&addr->addr_list);
1673 addr->arm_tag = req->req.tag;
1674 addr->start = req->req.address;
1675 addr->end = req->req.address + req->req.length;
1676 addr->access_rights = (u8) (req->req.misc & 0x0F);
1677 addr->notification_options = (u8) ((req->req.misc >> 4) & 0x0F);
1678 addr->client_transactions = (u8) ((req->req.misc >> 8) & 0x0F);
1679 addr->access_rights |= addr->client_transactions;
1680 addr->notification_options |= addr->client_transactions;
1681 addr->recvb = req->req.recvb;
1682 addr->rec_length = (u16) ((req->req.misc >> 16) & 0xFFFF);
1683 spin_lock_irqsave(&host_info_lock, flags);
1684 hi = find_host_info(fi->host);
1687 /* same host with address-entry containing same addressrange ? */
1688 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1689 entry = fi_hlp->addr_list.next;
1690 while (entry != &(fi_hlp->addr_list)) {
1692 list_entry(entry, struct arm_addr, addr_list);
1693 if ((arm_addr->start == addr->start)
1694 && (arm_addr->end == addr->end)) {
1695 DBGMSG("same host ownes same "
1696 "addressrange -> EALREADY");
1700 entry = entry->next;
1707 /* addressrange occupied by same host */
1708 vfree(addr->addr_space_buffer);
1710 spin_unlock_irqrestore(&host_info_lock, flags);
1713 /* another host with valid address-entry containing same addressrange */
1714 list_for_each_entry(hi, &host_info_list, list) {
1715 if (hi->host != fi->host) {
1716 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1717 entry = fi_hlp->addr_list.next;
1718 while (entry != &(fi_hlp->addr_list)) {
1720 list_entry(entry, struct arm_addr,
1722 if ((arm_addr->start == addr->start)
1723 && (arm_addr->end == addr->end)) {
1725 ("another host ownes same "
1730 entry = entry->next;
1739 DBGMSG("another hosts entry is valid -> SUCCESS");
1740 if (copy_to_user(int2ptr(req->req.recvb),
1741 &addr->start, sizeof(u64))) {
1742 printk(KERN_ERR "raw1394: arm_register failed "
1743 " address-range-entry is invalid -> EFAULT !!!\n");
1744 vfree(addr->addr_space_buffer);
1746 spin_unlock_irqrestore(&host_info_lock, flags);
1749 free_pending_request(req); /* immediate success or fail */
1751 list_add_tail(&addr->addr_list, &fi->addr_list);
1752 spin_unlock_irqrestore(&host_info_lock, flags);
1753 return sizeof(struct raw1394_request);
1756 hpsb_register_addrspace(&raw1394_highlevel, fi->host, &arm_ops,
1758 req->req.address + req->req.length);
1761 list_add_tail(&addr->addr_list, &fi->addr_list);
1763 DBGMSG("arm_register failed errno: %d \n", retval);
1764 vfree(addr->addr_space_buffer);
1766 spin_unlock_irqrestore(&host_info_lock, flags);
1769 spin_unlock_irqrestore(&host_info_lock, flags);
1770 free_pending_request(req); /* immediate success or fail */
1771 return sizeof(struct raw1394_request);
1774 static int arm_unregister(struct file_info *fi, struct pending_request *req)
1778 struct list_head *entry;
1779 struct arm_addr *addr = NULL;
1780 struct host_info *hi;
1781 struct file_info *fi_hlp = NULL;
1782 struct arm_addr *arm_addr = NULL;
1784 unsigned long flags;
1786 DBGMSG("arm_Unregister called addr(Offset): "
1788 (u32) ((req->req.address >> 32) & 0xFFFF),
1789 (u32) (req->req.address & 0xFFFFFFFF));
1790 spin_lock_irqsave(&host_info_lock, flags);
1792 entry = fi->addr_list.next;
1793 while (entry != &(fi->addr_list)) {
1794 addr = list_entry(entry, struct arm_addr, addr_list);
1795 if (addr->start == req->req.address) {
1799 entry = entry->next;
1802 DBGMSG("arm_Unregister addr not found");
1803 spin_unlock_irqrestore(&host_info_lock, flags);
1806 DBGMSG("arm_Unregister addr found");
1808 /* another host with valid address-entry containing
1809 same addressrange */
1810 list_for_each_entry(hi, &host_info_list, list) {
1811 if (hi->host != fi->host) {
1812 list_for_each_entry(fi_hlp, &hi->file_info_list, list) {
1813 entry = fi_hlp->addr_list.next;
1814 while (entry != &(fi_hlp->addr_list)) {
1815 arm_addr = list_entry(entry,
1818 if (arm_addr->start == addr->start) {
1819 DBGMSG("another host ownes "
1820 "same addressrange");
1824 entry = entry->next;
1833 DBGMSG("delete entry from list -> success");
1834 list_del(&addr->addr_list);
1835 vfree(addr->addr_space_buffer);
1837 free_pending_request(req); /* immediate success or fail */
1838 spin_unlock_irqrestore(&host_info_lock, flags);
1839 return sizeof(struct raw1394_request);
1842 hpsb_unregister_addrspace(&raw1394_highlevel, fi->host,
1845 printk(KERN_ERR "raw1394: arm_Unregister failed -> EINVAL\n");
1846 spin_unlock_irqrestore(&host_info_lock, flags);
1849 DBGMSG("delete entry from list -> success");
1850 list_del(&addr->addr_list);
1851 spin_unlock_irqrestore(&host_info_lock, flags);
1852 vfree(addr->addr_space_buffer);
1854 free_pending_request(req); /* immediate success or fail */
1855 return sizeof(struct raw1394_request);
1858 /* Copy data from ARM buffer(s) to user buffer. */
1859 static int arm_get_buf(struct file_info *fi, struct pending_request *req)
1861 struct arm_addr *arm_addr = NULL;
1862 unsigned long flags;
1863 unsigned long offset;
1865 struct list_head *entry;
1867 DBGMSG("arm_get_buf "
1868 "addr(Offset): %04X %08X length: %u",
1869 (u32) ((req->req.address >> 32) & 0xFFFF),
1870 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
1872 spin_lock_irqsave(&host_info_lock, flags);
1873 entry = fi->addr_list.next;
1874 while (entry != &(fi->addr_list)) {
1875 arm_addr = list_entry(entry, struct arm_addr, addr_list);
1876 if ((arm_addr->start <= req->req.address) &&
1877 (arm_addr->end > req->req.address)) {
1878 if (req->req.address + req->req.length <= arm_addr->end) {
1879 offset = req->req.address - arm_addr->start;
1882 ("arm_get_buf copy_to_user( %08X, %p, %u )",
1883 (u32) req->req.recvb,
1884 arm_addr->addr_space_buffer + offset,
1885 (u32) req->req.length);
1888 (int2ptr(req->req.recvb),
1889 arm_addr->addr_space_buffer + offset,
1891 spin_unlock_irqrestore(&host_info_lock,
1896 spin_unlock_irqrestore(&host_info_lock, flags);
1897 /* We have to free the request, because we
1898 * queue no response, and therefore nobody
1900 free_pending_request(req);
1901 return sizeof(struct raw1394_request);
1903 DBGMSG("arm_get_buf request exceeded mapping");
1904 spin_unlock_irqrestore(&host_info_lock, flags);
1908 entry = entry->next;
1910 spin_unlock_irqrestore(&host_info_lock, flags);
1914 /* Copy data from user buffer to ARM buffer(s). */
1915 static int arm_set_buf(struct file_info *fi, struct pending_request *req)
1917 struct arm_addr *arm_addr = NULL;
1918 unsigned long flags;
1919 unsigned long offset;
1921 struct list_head *entry;
1923 DBGMSG("arm_set_buf "
1924 "addr(Offset): %04X %08X length: %u",
1925 (u32) ((req->req.address >> 32) & 0xFFFF),
1926 (u32) (req->req.address & 0xFFFFFFFF), (u32) req->req.length);
1928 spin_lock_irqsave(&host_info_lock, flags);
1929 entry = fi->addr_list.next;
1930 while (entry != &(fi->addr_list)) {
1931 arm_addr = list_entry(entry, struct arm_addr, addr_list);
1932 if ((arm_addr->start <= req->req.address) &&
1933 (arm_addr->end > req->req.address)) {
1934 if (req->req.address + req->req.length <= arm_addr->end) {
1935 offset = req->req.address - arm_addr->start;
1938 ("arm_set_buf copy_from_user( %p, %08X, %u )",
1939 arm_addr->addr_space_buffer + offset,
1940 (u32) req->req.sendb,
1941 (u32) req->req.length);
1944 (arm_addr->addr_space_buffer + offset,
1945 int2ptr(req->req.sendb),
1947 spin_unlock_irqrestore(&host_info_lock,
1952 spin_unlock_irqrestore(&host_info_lock, flags);
1953 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
1954 return sizeof(struct raw1394_request);
1956 DBGMSG("arm_set_buf request exceeded mapping");
1957 spin_unlock_irqrestore(&host_info_lock, flags);
1961 entry = entry->next;
1963 spin_unlock_irqrestore(&host_info_lock, flags);
1967 static int reset_notification(struct file_info *fi, struct pending_request *req)
1969 DBGMSG("reset_notification called - switch %s ",
1970 (req->req.misc == RAW1394_NOTIFY_OFF) ? "OFF" : "ON");
1971 if ((req->req.misc == RAW1394_NOTIFY_OFF) ||
1972 (req->req.misc == RAW1394_NOTIFY_ON)) {
1973 fi->notification = (u8) req->req.misc;
1974 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
1975 return sizeof(struct raw1394_request);
1977 /* error EINVAL (22) invalid argument */
1981 static int write_phypacket(struct file_info *fi, struct pending_request *req)
1983 struct hpsb_packet *packet = NULL;
1986 unsigned long flags;
1988 data = be32_to_cpu((u32) req->req.sendb);
1989 DBGMSG("write_phypacket called - quadlet 0x%8.8x ", data);
1990 packet = hpsb_make_phypacket(fi->host, data);
1993 req->req.length = 0;
1994 req->packet = packet;
1995 hpsb_set_packet_complete_task(packet,
1996 (void (*)(void *))queue_complete_cb, req);
1997 spin_lock_irqsave(&fi->reqlists_lock, flags);
1998 list_add_tail(&req->list, &fi->req_pending);
1999 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2000 packet->generation = req->req.generation;
2001 retval = hpsb_send_packet(packet);
2002 DBGMSG("write_phypacket send_packet called => retval: %d ", retval);
2004 req->req.error = RAW1394_ERROR_SEND_ERROR;
2005 req->req.length = 0;
2006 queue_complete_req(req);
2008 return sizeof(struct raw1394_request);
2011 static int get_config_rom(struct file_info *fi, struct pending_request *req)
2013 int ret = sizeof(struct raw1394_request);
2014 quadlet_t *data = kmalloc(req->req.length, SLAB_KERNEL);
2021 csr1212_read(fi->host->csr.rom, CSR1212_CONFIG_ROM_SPACE_OFFSET,
2022 data, req->req.length);
2023 if (copy_to_user(int2ptr(req->req.recvb), data, req->req.length))
2026 (int2ptr(req->req.tag), &fi->host->csr.rom->cache_head->len,
2027 sizeof(fi->host->csr.rom->cache_head->len)))
2029 if (copy_to_user(int2ptr(req->req.address), &fi->host->csr.generation,
2030 sizeof(fi->host->csr.generation)))
2032 if (copy_to_user(int2ptr(req->req.sendb), &status, sizeof(status)))
2036 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2041 static int update_config_rom(struct file_info *fi, struct pending_request *req)
2043 int ret = sizeof(struct raw1394_request);
2044 quadlet_t *data = kmalloc(req->req.length, SLAB_KERNEL);
2047 if (copy_from_user(data, int2ptr(req->req.sendb), req->req.length)) {
2050 int status = hpsb_update_config_rom(fi->host,
2051 data, req->req.length,
2052 (unsigned char)req->req.
2055 (int2ptr(req->req.recvb), &status, sizeof(status)))
2060 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2066 static int modify_config_rom(struct file_info *fi, struct pending_request *req)
2068 struct csr1212_keyval *kv;
2069 struct csr1212_csr_rom_cache *cache;
2070 struct csr1212_dentry *dentry;
2074 if (req->req.misc == ~0) {
2075 if (req->req.length == 0)
2078 /* Find an unused slot */
2080 dr < RAW1394_MAX_USER_CSR_DIRS && fi->csr1212_dirs[dr];
2083 if (dr == RAW1394_MAX_USER_CSR_DIRS)
2086 fi->csr1212_dirs[dr] =
2087 csr1212_new_directory(CSR1212_KV_ID_VENDOR);
2088 if (!fi->csr1212_dirs[dr])
2092 if (!fi->csr1212_dirs[dr])
2095 /* Delete old stuff */
2097 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2098 dentry; dentry = dentry->next) {
2099 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2104 if (req->req.length == 0) {
2105 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2106 fi->csr1212_dirs[dr] = NULL;
2108 hpsb_update_config_rom_image(fi->host);
2109 free_pending_request(req);
2110 return sizeof(struct raw1394_request);
2114 cache = csr1212_rom_cache_malloc(0, req->req.length);
2116 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2117 fi->csr1212_dirs[dr] = NULL;
2121 cache->filled_head = kmalloc(sizeof(*cache->filled_head), GFP_KERNEL);
2122 if (!cache->filled_head) {
2123 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2124 fi->csr1212_dirs[dr] = NULL;
2125 CSR1212_FREE(cache);
2128 cache->filled_tail = cache->filled_head;
2130 if (copy_from_user(cache->data, int2ptr(req->req.sendb),
2132 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2133 fi->csr1212_dirs[dr] = NULL;
2136 cache->len = req->req.length;
2137 cache->filled_head->offset_start = 0;
2138 cache->filled_head->offset_end = cache->size - 1;
2140 cache->layout_head = cache->layout_tail = fi->csr1212_dirs[dr];
2142 ret = CSR1212_SUCCESS;
2143 /* parse all the items */
2144 for (kv = cache->layout_head; ret == CSR1212_SUCCESS && kv;
2146 ret = csr1212_parse_keyval(kv, cache);
2149 /* attach top level items to the root directory */
2151 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2152 ret == CSR1212_SUCCESS && dentry; dentry = dentry->next) {
2154 csr1212_attach_keyval_to_directory(fi->host->csr.
2159 if (ret == CSR1212_SUCCESS) {
2160 ret = hpsb_update_config_rom_image(fi->host);
2162 if (ret >= 0 && copy_to_user(int2ptr(req->req.recvb),
2168 kfree(cache->filled_head);
2169 CSR1212_FREE(cache);
2172 /* we have to free the request, because we queue no response,
2173 * and therefore nobody will free it */
2174 free_pending_request(req);
2175 return sizeof(struct raw1394_request);
2178 fi->csr1212_dirs[dr]->value.directory.dentries_head;
2179 dentry; dentry = dentry->next) {
2180 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2184 csr1212_release_keyval(fi->csr1212_dirs[dr]);
2185 fi->csr1212_dirs[dr] = NULL;
2190 static int state_connected(struct file_info *fi, struct pending_request *req)
2192 int node = req->req.address >> 48;
2194 req->req.error = RAW1394_ERROR_NONE;
2196 switch (req->req.type) {
2198 case RAW1394_REQ_ECHO:
2199 queue_complete_req(req);
2200 return sizeof(struct raw1394_request);
2202 case RAW1394_REQ_ISO_SEND:
2203 return handle_iso_send(fi, req, node);
2205 case RAW1394_REQ_ARM_REGISTER:
2206 return arm_register(fi, req);
2208 case RAW1394_REQ_ARM_UNREGISTER:
2209 return arm_unregister(fi, req);
2211 case RAW1394_REQ_ARM_SET_BUF:
2212 return arm_set_buf(fi, req);
2214 case RAW1394_REQ_ARM_GET_BUF:
2215 return arm_get_buf(fi, req);
2217 case RAW1394_REQ_RESET_NOTIFY:
2218 return reset_notification(fi, req);
2220 case RAW1394_REQ_ISO_LISTEN:
2221 handle_iso_listen(fi, req);
2222 return sizeof(struct raw1394_request);
2224 case RAW1394_REQ_FCP_LISTEN:
2225 handle_fcp_listen(fi, req);
2226 return sizeof(struct raw1394_request);
2228 case RAW1394_REQ_RESET_BUS:
2229 if (req->req.misc == RAW1394_LONG_RESET) {
2230 DBGMSG("busreset called (type: LONG)");
2231 hpsb_reset_bus(fi->host, LONG_RESET);
2232 free_pending_request(req); /* we have to free the request, because we queue no response, and therefore nobody will free it */
2233 return sizeof(struct raw1394_request);
2235 if (req->req.misc == RAW1394_SHORT_RESET) {
2236 DBGMSG("busreset called (type: SHORT)");
2237 hpsb_reset_bus(fi->host, SHORT_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 /* error EINVAL (22) invalid argument */
2243 case RAW1394_REQ_GET_ROM:
2244 return get_config_rom(fi, req);
2246 case RAW1394_REQ_UPDATE_ROM:
2247 return update_config_rom(fi, req);
2249 case RAW1394_REQ_MODIFY_ROM:
2250 return modify_config_rom(fi, req);
2253 if (req->req.generation != get_hpsb_generation(fi->host)) {
2254 req->req.error = RAW1394_ERROR_GENERATION;
2255 req->req.generation = get_hpsb_generation(fi->host);
2256 req->req.length = 0;
2257 queue_complete_req(req);
2258 return sizeof(struct raw1394_request);
2261 switch (req->req.type) {
2262 case RAW1394_REQ_PHYPACKET:
2263 return write_phypacket(fi, req);
2264 case RAW1394_REQ_ASYNC_SEND:
2265 return handle_async_send(fi, req);
2268 if (req->req.length == 0) {
2269 req->req.error = RAW1394_ERROR_INVALID_ARG;
2270 queue_complete_req(req);
2271 return sizeof(struct raw1394_request);
2274 return handle_async_request(fi, req, node);
2277 static ssize_t raw1394_write(struct file *file, const char __user * buffer,
2278 size_t count, loff_t * offset_is_ignored)
2280 struct file_info *fi = (struct file_info *)file->private_data;
2281 struct pending_request *req;
2284 if (count != sizeof(struct raw1394_request)) {
2288 req = alloc_pending_request();
2292 req->file_info = fi;
2294 if (copy_from_user(&req->req, buffer, sizeof(struct raw1394_request))) {
2295 free_pending_request(req);
2299 switch (fi->state) {
2301 retval = state_opened(fi, req);
2305 retval = state_initialized(fi, req);
2309 retval = state_connected(fi, req);
2314 free_pending_request(req);
2320 /* rawiso operations */
2322 /* check if any RAW1394_REQ_RAWISO_ACTIVITY event is already in the
2323 * completion queue (reqlists_lock must be taken) */
2324 static inline int __rawiso_event_in_queue(struct file_info *fi)
2326 struct pending_request *req;
2328 list_for_each_entry(req, &fi->req_complete, list)
2329 if (req->req.type == RAW1394_REQ_RAWISO_ACTIVITY)
2335 /* put a RAWISO_ACTIVITY event in the queue, if one isn't there already */
2336 static void queue_rawiso_event(struct file_info *fi)
2338 unsigned long flags;
2340 spin_lock_irqsave(&fi->reqlists_lock, flags);
2342 /* only one ISO activity event may be in the queue */
2343 if (!__rawiso_event_in_queue(fi)) {
2344 struct pending_request *req =
2345 __alloc_pending_request(SLAB_ATOMIC);
2348 req->file_info = fi;
2349 req->req.type = RAW1394_REQ_RAWISO_ACTIVITY;
2350 req->req.generation = get_hpsb_generation(fi->host);
2351 __queue_complete_req(req);
2353 /* on allocation failure, signal an overflow */
2354 if (fi->iso_handle) {
2355 atomic_inc(&fi->iso_handle->overflows);
2359 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2362 static void rawiso_activity_cb(struct hpsb_iso *iso)
2364 unsigned long flags;
2365 struct host_info *hi;
2366 struct file_info *fi;
2368 spin_lock_irqsave(&host_info_lock, flags);
2369 hi = find_host_info(iso->host);
2372 list_for_each_entry(fi, &hi->file_info_list, list) {
2373 if (fi->iso_handle == iso)
2374 queue_rawiso_event(fi);
2378 spin_unlock_irqrestore(&host_info_lock, flags);
2381 /* helper function - gather all the kernel iso status bits for returning to user-space */
2382 static void raw1394_iso_fill_status(struct hpsb_iso *iso,
2383 struct raw1394_iso_status *stat)
2385 stat->config.data_buf_size = iso->buf_size;
2386 stat->config.buf_packets = iso->buf_packets;
2387 stat->config.channel = iso->channel;
2388 stat->config.speed = iso->speed;
2389 stat->config.irq_interval = iso->irq_interval;
2390 stat->n_packets = hpsb_iso_n_ready(iso);
2391 stat->overflows = atomic_read(&iso->overflows);
2392 stat->xmit_cycle = iso->xmit_cycle;
2395 static int raw1394_iso_xmit_init(struct file_info *fi, void __user * uaddr)
2397 struct raw1394_iso_status stat;
2402 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2405 fi->iso_handle = hpsb_iso_xmit_init(fi->host,
2406 stat.config.data_buf_size,
2407 stat.config.buf_packets,
2408 stat.config.channel,
2410 stat.config.irq_interval,
2411 rawiso_activity_cb);
2412 if (!fi->iso_handle)
2415 fi->iso_state = RAW1394_ISO_XMIT;
2417 raw1394_iso_fill_status(fi->iso_handle, &stat);
2418 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2421 /* queue an event to get things started */
2422 rawiso_activity_cb(fi->iso_handle);
2427 static int raw1394_iso_recv_init(struct file_info *fi, void __user * uaddr)
2429 struct raw1394_iso_status stat;
2434 if (copy_from_user(&stat, uaddr, sizeof(stat)))
2437 fi->iso_handle = hpsb_iso_recv_init(fi->host,
2438 stat.config.data_buf_size,
2439 stat.config.buf_packets,
2440 stat.config.channel,
2441 stat.config.dma_mode,
2442 stat.config.irq_interval,
2443 rawiso_activity_cb);
2444 if (!fi->iso_handle)
2447 fi->iso_state = RAW1394_ISO_RECV;
2449 raw1394_iso_fill_status(fi->iso_handle, &stat);
2450 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2455 static int raw1394_iso_get_status(struct file_info *fi, void __user * uaddr)
2457 struct raw1394_iso_status stat;
2458 struct hpsb_iso *iso = fi->iso_handle;
2460 raw1394_iso_fill_status(fi->iso_handle, &stat);
2461 if (copy_to_user(uaddr, &stat, sizeof(stat)))
2464 /* reset overflow counter */
2465 atomic_set(&iso->overflows, 0);
2470 /* copy N packet_infos out of the ringbuffer into user-supplied array */
2471 static int raw1394_iso_recv_packets(struct file_info *fi, void __user * uaddr)
2473 struct raw1394_iso_packets upackets;
2474 unsigned int packet = fi->iso_handle->first_packet;
2477 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2480 if (upackets.n_packets > hpsb_iso_n_ready(fi->iso_handle))
2483 /* ensure user-supplied buffer is accessible and big enough */
2484 if (!access_ok(VERIFY_WRITE, upackets.infos,
2485 upackets.n_packets *
2486 sizeof(struct raw1394_iso_packet_info)))
2489 /* copy the packet_infos out */
2490 for (i = 0; i < upackets.n_packets; i++) {
2491 if (__copy_to_user(&upackets.infos[i],
2492 &fi->iso_handle->infos[packet],
2493 sizeof(struct raw1394_iso_packet_info)))
2496 packet = (packet + 1) % fi->iso_handle->buf_packets;
2502 /* copy N packet_infos from user to ringbuffer, and queue them for transmission */
2503 static int raw1394_iso_send_packets(struct file_info *fi, void __user * uaddr)
2505 struct raw1394_iso_packets upackets;
2508 if (copy_from_user(&upackets, uaddr, sizeof(upackets)))
2511 if (upackets.n_packets >= fi->iso_handle->buf_packets)
2514 if (upackets.n_packets >= hpsb_iso_n_ready(fi->iso_handle))
2517 /* ensure user-supplied buffer is accessible and big enough */
2518 if (!access_ok(VERIFY_READ, upackets.infos,
2519 upackets.n_packets *
2520 sizeof(struct raw1394_iso_packet_info)))
2523 /* copy the infos structs in and queue the packets */
2524 for (i = 0; i < upackets.n_packets; i++) {
2525 struct raw1394_iso_packet_info info;
2527 if (__copy_from_user(&info, &upackets.infos[i],
2528 sizeof(struct raw1394_iso_packet_info)))
2531 rv = hpsb_iso_xmit_queue_packet(fi->iso_handle, info.offset,
2532 info.len, info.tag, info.sy);
2540 static void raw1394_iso_shutdown(struct file_info *fi)
2543 hpsb_iso_shutdown(fi->iso_handle);
2545 fi->iso_handle = NULL;
2546 fi->iso_state = RAW1394_ISO_INACTIVE;
2549 /* mmap the rawiso xmit/recv buffer */
2550 static int raw1394_mmap(struct file *file, struct vm_area_struct *vma)
2552 struct file_info *fi = file->private_data;
2554 if (fi->iso_state == RAW1394_ISO_INACTIVE)
2557 return dma_region_mmap(&fi->iso_handle->data_buf, file, vma);
2560 /* ioctl is only used for rawiso operations */
2561 static int raw1394_ioctl(struct inode *inode, struct file *file,
2562 unsigned int cmd, unsigned long arg)
2564 struct file_info *fi = file->private_data;
2565 void __user *argp = (void __user *)arg;
2567 switch (fi->iso_state) {
2568 case RAW1394_ISO_INACTIVE:
2570 case RAW1394_IOC_ISO_XMIT_INIT:
2571 return raw1394_iso_xmit_init(fi, argp);
2572 case RAW1394_IOC_ISO_RECV_INIT:
2573 return raw1394_iso_recv_init(fi, argp);
2578 case RAW1394_ISO_RECV:
2580 case RAW1394_IOC_ISO_RECV_START:{
2581 /* copy args from user-space */
2584 (&args[0], argp, sizeof(args)))
2586 return hpsb_iso_recv_start(fi->iso_handle,
2590 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2591 hpsb_iso_stop(fi->iso_handle);
2593 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL:
2594 return hpsb_iso_recv_listen_channel(fi->iso_handle,
2596 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
2597 return hpsb_iso_recv_unlisten_channel(fi->iso_handle,
2599 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:{
2600 /* copy the u64 from user-space */
2602 if (copy_from_user(&mask, argp, sizeof(mask)))
2604 return hpsb_iso_recv_set_channel_mask(fi->
2608 case RAW1394_IOC_ISO_GET_STATUS:
2609 return raw1394_iso_get_status(fi, argp);
2610 case RAW1394_IOC_ISO_RECV_PACKETS:
2611 return raw1394_iso_recv_packets(fi, argp);
2612 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
2613 return hpsb_iso_recv_release_packets(fi->iso_handle,
2615 case RAW1394_IOC_ISO_RECV_FLUSH:
2616 return hpsb_iso_recv_flush(fi->iso_handle);
2617 case RAW1394_IOC_ISO_SHUTDOWN:
2618 raw1394_iso_shutdown(fi);
2620 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2621 queue_rawiso_event(fi);
2625 case RAW1394_ISO_XMIT:
2627 case RAW1394_IOC_ISO_XMIT_START:{
2628 /* copy two ints from user-space */
2631 (&args[0], argp, sizeof(args)))
2633 return hpsb_iso_xmit_start(fi->iso_handle,
2636 case RAW1394_IOC_ISO_XMIT_SYNC:
2637 return hpsb_iso_xmit_sync(fi->iso_handle);
2638 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2639 hpsb_iso_stop(fi->iso_handle);
2641 case RAW1394_IOC_ISO_GET_STATUS:
2642 return raw1394_iso_get_status(fi, argp);
2643 case RAW1394_IOC_ISO_XMIT_PACKETS:
2644 return raw1394_iso_send_packets(fi, argp);
2645 case RAW1394_IOC_ISO_SHUTDOWN:
2646 raw1394_iso_shutdown(fi);
2648 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2649 queue_rawiso_event(fi);
2660 static unsigned int raw1394_poll(struct file *file, poll_table * pt)
2662 struct file_info *fi = file->private_data;
2663 unsigned int mask = POLLOUT | POLLWRNORM;
2664 unsigned long flags;
2666 poll_wait(file, &fi->poll_wait_complete, pt);
2668 spin_lock_irqsave(&fi->reqlists_lock, flags);
2669 if (!list_empty(&fi->req_complete)) {
2670 mask |= POLLIN | POLLRDNORM;
2672 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2677 static int raw1394_open(struct inode *inode, struct file *file)
2679 struct file_info *fi;
2681 fi = kzalloc(sizeof(*fi), SLAB_KERNEL);
2685 fi->notification = (u8) RAW1394_NOTIFY_ON; /* busreset notification */
2687 INIT_LIST_HEAD(&fi->list);
2689 INIT_LIST_HEAD(&fi->req_pending);
2690 INIT_LIST_HEAD(&fi->req_complete);
2691 sema_init(&fi->complete_sem, 0);
2692 spin_lock_init(&fi->reqlists_lock);
2693 init_waitqueue_head(&fi->poll_wait_complete);
2694 INIT_LIST_HEAD(&fi->addr_list);
2696 file->private_data = fi;
2701 static int raw1394_release(struct inode *inode, struct file *file)
2703 struct file_info *fi = file->private_data;
2704 struct list_head *lh;
2705 struct pending_request *req;
2706 int done = 0, i, fail = 0;
2708 struct list_head *entry;
2709 struct arm_addr *addr = NULL;
2710 struct host_info *hi;
2711 struct file_info *fi_hlp = NULL;
2712 struct arm_addr *arm_addr = NULL;
2715 unsigned long flags;
2717 if (fi->iso_state != RAW1394_ISO_INACTIVE)
2718 raw1394_iso_shutdown(fi);
2720 for (i = 0; i < 64; i++) {
2721 if (fi->listen_channels & (1ULL << i)) {
2722 hpsb_unlisten_channel(&raw1394_highlevel, fi->host, i);
2726 spin_lock_irqsave(&host_info_lock, flags);
2727 fi->listen_channels = 0;
2730 /* set address-entries invalid */
2732 while (!list_empty(&fi->addr_list)) {
2734 lh = fi->addr_list.next;
2735 addr = list_entry(lh, struct arm_addr, addr_list);
2736 /* another host with valid address-entry containing
2737 same addressrange? */
2738 list_for_each_entry(hi, &host_info_list, list) {
2739 if (hi->host != fi->host) {
2740 list_for_each_entry(fi_hlp, &hi->file_info_list,
2742 entry = fi_hlp->addr_list.next;
2743 while (entry != &(fi_hlp->addr_list)) {
2744 arm_addr = list_entry(entry, struct
2747 if (arm_addr->start ==
2750 ("raw1394_release: "
2751 "another host ownes "
2752 "same addressrange");
2756 entry = entry->next;
2764 if (!another_host) {
2765 DBGMSG("raw1394_release: call hpsb_arm_unregister");
2767 hpsb_unregister_addrspace(&raw1394_highlevel,
2768 fi->host, addr->start);
2772 "raw1394_release arm_Unregister failed\n");
2775 DBGMSG("raw1394_release: delete addr_entry from list");
2776 list_del(&addr->addr_list);
2777 vfree(addr->addr_space_buffer);
2780 spin_unlock_irqrestore(&host_info_lock, flags);
2782 printk(KERN_ERR "raw1394: during addr_list-release "
2783 "error(s) occurred \n");
2787 spin_lock_irqsave(&fi->reqlists_lock, flags);
2789 while (!list_empty(&fi->req_complete)) {
2790 lh = fi->req_complete.next;
2793 req = list_entry(lh, struct pending_request, list);
2795 free_pending_request(req);
2798 if (list_empty(&fi->req_pending))
2801 spin_unlock_irqrestore(&fi->reqlists_lock, flags);
2804 down_interruptible(&fi->complete_sem);
2807 /* Remove any sub-trees left by user space programs */
2808 for (i = 0; i < RAW1394_MAX_USER_CSR_DIRS; i++) {
2809 struct csr1212_dentry *dentry;
2810 if (!fi->csr1212_dirs[i])
2813 fi->csr1212_dirs[i]->value.directory.dentries_head; dentry;
2814 dentry = dentry->next) {
2815 csr1212_detach_keyval_from_directory(fi->host->csr.rom->
2819 csr1212_release_keyval(fi->csr1212_dirs[i]);
2820 fi->csr1212_dirs[i] = NULL;
2824 if ((csr_mod || fi->cfgrom_upd)
2825 && hpsb_update_config_rom_image(fi->host) < 0)
2827 ("Failed to generate Configuration ROM image for host %d",
2830 if (fi->state == connected) {
2831 spin_lock_irqsave(&host_info_lock, flags);
2832 list_del(&fi->list);
2833 spin_unlock_irqrestore(&host_info_lock, flags);
2835 put_device(&fi->host->device);
2843 /*** HOTPLUG STUFF **********************************************************/
2845 * Export information about protocols/devices supported by this driver.
2847 static struct ieee1394_device_id raw1394_id_table[] = {
2849 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2850 .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
2851 .version = AVC_SW_VERSION_ENTRY & 0xffffff},
2853 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2854 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2855 .version = CAMERA_SW_VERSION_ENTRY & 0xffffff},
2857 .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
2858 .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
2859 .version = (CAMERA_SW_VERSION_ENTRY + 1) & 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 + 2) & 0xffffff},
2867 MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table);
2869 static struct hpsb_protocol_driver raw1394_driver = {
2870 .name = "raw1394 Driver",
2871 .id_table = raw1394_id_table,
2874 .bus = &ieee1394_bus_type,
2878 /******************************************************************************/
2880 static struct hpsb_highlevel raw1394_highlevel = {
2881 .name = RAW1394_DEVICE_NAME,
2882 .add_host = add_host,
2883 .remove_host = remove_host,
2884 .host_reset = host_reset,
2885 .iso_receive = iso_receive,
2886 .fcp_request = fcp_request,
2889 static struct cdev raw1394_cdev;
2890 static struct file_operations raw1394_fops = {
2891 .owner = THIS_MODULE,
2892 .read = raw1394_read,
2893 .write = raw1394_write,
2894 .mmap = raw1394_mmap,
2895 .ioctl = raw1394_ioctl,
2896 .poll = raw1394_poll,
2897 .open = raw1394_open,
2898 .release = raw1394_release,
2901 static int __init init_raw1394(void)
2905 hpsb_register_highlevel(&raw1394_highlevel);
2908 (class_device_create
2909 (hpsb_protocol_class, NULL,
2910 MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16), NULL,
2911 RAW1394_DEVICE_NAME))) {
2916 devfs_mk_cdev(MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16),
2917 S_IFCHR | S_IRUSR | S_IWUSR, RAW1394_DEVICE_NAME);
2919 cdev_init(&raw1394_cdev, &raw1394_fops);
2920 raw1394_cdev.owner = THIS_MODULE;
2921 kobject_set_name(&raw1394_cdev.kobj, RAW1394_DEVICE_NAME);
2922 ret = cdev_add(&raw1394_cdev, IEEE1394_RAW1394_DEV, 1);
2924 HPSB_ERR("raw1394 failed to register minor device block");
2928 HPSB_INFO("raw1394: /dev/%s device initialized", RAW1394_DEVICE_NAME);
2930 ret = hpsb_register_protocol(&raw1394_driver);
2932 HPSB_ERR("raw1394: failed to register protocol");
2933 cdev_del(&raw1394_cdev);
2940 devfs_remove(RAW1394_DEVICE_NAME);
2941 class_device_destroy(hpsb_protocol_class,
2942 MKDEV(IEEE1394_MAJOR,
2943 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
2945 hpsb_unregister_highlevel(&raw1394_highlevel);
2950 static void __exit cleanup_raw1394(void)
2952 class_device_destroy(hpsb_protocol_class,
2953 MKDEV(IEEE1394_MAJOR,
2954 IEEE1394_MINOR_BLOCK_RAW1394 * 16));
2955 cdev_del(&raw1394_cdev);
2956 devfs_remove(RAW1394_DEVICE_NAME);
2957 hpsb_unregister_highlevel(&raw1394_highlevel);
2958 hpsb_unregister_protocol(&raw1394_driver);
2961 module_init(init_raw1394);
2962 module_exit(cleanup_raw1394);
2963 MODULE_LICENSE("GPL");