2 * Char device for device raw access
4 * Copyright (C) 2005-2007 Kristian Hoegsberg <krh@bitplanet.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <linux/bug.h>
22 #include <linux/compat.h>
23 #include <linux/delay.h>
24 #include <linux/device.h>
25 #include <linux/errno.h>
26 #include <linux/firewire.h>
27 #include <linux/firewire-cdev.h>
28 #include <linux/idr.h>
29 #include <linux/irqflags.h>
30 #include <linux/jiffies.h>
31 #include <linux/kernel.h>
32 #include <linux/kref.h>
34 #include <linux/module.h>
35 #include <linux/mutex.h>
36 #include <linux/poll.h>
37 #include <linux/sched.h>
38 #include <linux/spinlock.h>
39 #include <linux/string.h>
40 #include <linux/time.h>
41 #include <linux/uaccess.h>
42 #include <linux/vmalloc.h>
43 #include <linux/wait.h>
44 #include <linux/workqueue.h>
46 #include <asm/system.h>
51 * ABI version history is documented in linux/firewire-cdev.h.
53 #define FW_CDEV_KERNEL_VERSION 4
54 #define FW_CDEV_VERSION_EVENT_REQUEST2 4
58 struct fw_device
*device
;
62 struct idr resource_idr
;
63 struct list_head event_list
;
64 wait_queue_head_t wait
;
65 u64 bus_reset_closure
;
67 struct fw_iso_context
*iso_context
;
69 struct fw_iso_buffer buffer
;
70 unsigned long vm_start
;
72 struct list_head link
;
76 static inline void client_get(struct client
*client
)
78 kref_get(&client
->kref
);
81 static void client_release(struct kref
*kref
)
83 struct client
*client
= container_of(kref
, struct client
, kref
);
85 fw_device_put(client
->device
);
89 static void client_put(struct client
*client
)
91 kref_put(&client
->kref
, client_release
);
94 struct client_resource
;
95 typedef void (*client_resource_release_fn_t
)(struct client
*,
96 struct client_resource
*);
97 struct client_resource
{
98 client_resource_release_fn_t release
;
102 struct address_handler_resource
{
103 struct client_resource resource
;
104 struct fw_address_handler handler
;
106 struct client
*client
;
109 struct outbound_transaction_resource
{
110 struct client_resource resource
;
111 struct fw_transaction transaction
;
114 struct inbound_transaction_resource
{
115 struct client_resource resource
;
116 struct fw_card
*card
;
117 struct fw_request
*request
;
122 struct descriptor_resource
{
123 struct client_resource resource
;
124 struct fw_descriptor descriptor
;
128 struct iso_resource
{
129 struct client_resource resource
;
130 struct client
*client
;
131 /* Schedule work and access todo only with client->lock held. */
132 struct delayed_work work
;
133 enum {ISO_RES_ALLOC
, ISO_RES_REALLOC
, ISO_RES_DEALLOC
,
134 ISO_RES_ALLOC_ONCE
, ISO_RES_DEALLOC_ONCE
,} todo
;
138 __be32 transaction_data
[2];
139 struct iso_resource_event
*e_alloc
, *e_dealloc
;
142 static void release_iso_resource(struct client
*, struct client_resource
*);
144 static void schedule_iso_resource(struct iso_resource
*r
, unsigned long delay
)
146 client_get(r
->client
);
147 if (!schedule_delayed_work(&r
->work
, delay
))
148 client_put(r
->client
);
151 static void schedule_if_iso_resource(struct client_resource
*resource
)
153 if (resource
->release
== release_iso_resource
)
154 schedule_iso_resource(container_of(resource
,
155 struct iso_resource
, resource
), 0);
159 * dequeue_event() just kfree()'s the event, so the event has to be
160 * the first field in a struct XYZ_event.
163 struct { void *data
; size_t size
; } v
[2];
164 struct list_head link
;
167 struct bus_reset_event
{
169 struct fw_cdev_event_bus_reset reset
;
172 struct outbound_transaction_event
{
174 struct client
*client
;
175 struct outbound_transaction_resource r
;
176 struct fw_cdev_event_response response
;
179 struct inbound_transaction_event
{
182 struct fw_cdev_event_request request
;
183 struct fw_cdev_event_request2 request2
;
187 struct iso_interrupt_event
{
189 struct fw_cdev_event_iso_interrupt interrupt
;
192 struct iso_resource_event
{
194 struct fw_cdev_event_iso_resource iso_resource
;
197 struct outbound_phy_packet_event
{
199 struct client
*client
;
201 struct fw_cdev_event_phy_packet phy_packet
;
204 static inline void __user
*u64_to_uptr(__u64 value
)
206 return (void __user
*)(unsigned long)value
;
209 static inline __u64
uptr_to_u64(void __user
*ptr
)
211 return (__u64
)(unsigned long)ptr
;
214 static int fw_device_op_open(struct inode
*inode
, struct file
*file
)
216 struct fw_device
*device
;
217 struct client
*client
;
219 device
= fw_device_get_by_devt(inode
->i_rdev
);
223 if (fw_device_is_shutdown(device
)) {
224 fw_device_put(device
);
228 client
= kzalloc(sizeof(*client
), GFP_KERNEL
);
229 if (client
== NULL
) {
230 fw_device_put(device
);
234 client
->device
= device
;
235 spin_lock_init(&client
->lock
);
236 idr_init(&client
->resource_idr
);
237 INIT_LIST_HEAD(&client
->event_list
);
238 init_waitqueue_head(&client
->wait
);
239 kref_init(&client
->kref
);
241 file
->private_data
= client
;
243 mutex_lock(&device
->client_list_mutex
);
244 list_add_tail(&client
->link
, &device
->client_list
);
245 mutex_unlock(&device
->client_list_mutex
);
247 return nonseekable_open(inode
, file
);
250 static void queue_event(struct client
*client
, struct event
*event
,
251 void *data0
, size_t size0
, void *data1
, size_t size1
)
255 event
->v
[0].data
= data0
;
256 event
->v
[0].size
= size0
;
257 event
->v
[1].data
= data1
;
258 event
->v
[1].size
= size1
;
260 spin_lock_irqsave(&client
->lock
, flags
);
261 if (client
->in_shutdown
)
264 list_add_tail(&event
->link
, &client
->event_list
);
265 spin_unlock_irqrestore(&client
->lock
, flags
);
267 wake_up_interruptible(&client
->wait
);
270 static int dequeue_event(struct client
*client
,
271 char __user
*buffer
, size_t count
)
277 ret
= wait_event_interruptible(client
->wait
,
278 !list_empty(&client
->event_list
) ||
279 fw_device_is_shutdown(client
->device
));
283 if (list_empty(&client
->event_list
) &&
284 fw_device_is_shutdown(client
->device
))
287 spin_lock_irq(&client
->lock
);
288 event
= list_first_entry(&client
->event_list
, struct event
, link
);
289 list_del(&event
->link
);
290 spin_unlock_irq(&client
->lock
);
293 for (i
= 0; i
< ARRAY_SIZE(event
->v
) && total
< count
; i
++) {
294 size
= min(event
->v
[i
].size
, count
- total
);
295 if (copy_to_user(buffer
+ total
, event
->v
[i
].data
, size
)) {
309 static ssize_t
fw_device_op_read(struct file
*file
, char __user
*buffer
,
310 size_t count
, loff_t
*offset
)
312 struct client
*client
= file
->private_data
;
314 return dequeue_event(client
, buffer
, count
);
317 static void fill_bus_reset_event(struct fw_cdev_event_bus_reset
*event
,
318 struct client
*client
)
320 struct fw_card
*card
= client
->device
->card
;
322 spin_lock_irq(&card
->lock
);
324 event
->closure
= client
->bus_reset_closure
;
325 event
->type
= FW_CDEV_EVENT_BUS_RESET
;
326 event
->generation
= client
->device
->generation
;
327 event
->node_id
= client
->device
->node_id
;
328 event
->local_node_id
= card
->local_node
->node_id
;
329 event
->bm_node_id
= card
->bm_node_id
;
330 event
->irm_node_id
= card
->irm_node
->node_id
;
331 event
->root_node_id
= card
->root_node
->node_id
;
333 spin_unlock_irq(&card
->lock
);
336 static void for_each_client(struct fw_device
*device
,
337 void (*callback
)(struct client
*client
))
341 mutex_lock(&device
->client_list_mutex
);
342 list_for_each_entry(c
, &device
->client_list
, link
)
344 mutex_unlock(&device
->client_list_mutex
);
347 static int schedule_reallocations(int id
, void *p
, void *data
)
349 schedule_if_iso_resource(p
);
354 static void queue_bus_reset_event(struct client
*client
)
356 struct bus_reset_event
*e
;
358 e
= kzalloc(sizeof(*e
), GFP_KERNEL
);
360 fw_notify("Out of memory when allocating bus reset event\n");
364 fill_bus_reset_event(&e
->reset
, client
);
366 queue_event(client
, &e
->event
,
367 &e
->reset
, sizeof(e
->reset
), NULL
, 0);
369 spin_lock_irq(&client
->lock
);
370 idr_for_each(&client
->resource_idr
, schedule_reallocations
, client
);
371 spin_unlock_irq(&client
->lock
);
374 void fw_device_cdev_update(struct fw_device
*device
)
376 for_each_client(device
, queue_bus_reset_event
);
379 static void wake_up_client(struct client
*client
)
381 wake_up_interruptible(&client
->wait
);
384 void fw_device_cdev_remove(struct fw_device
*device
)
386 for_each_client(device
, wake_up_client
);
390 struct fw_cdev_get_info get_info
;
391 struct fw_cdev_send_request send_request
;
392 struct fw_cdev_allocate allocate
;
393 struct fw_cdev_deallocate deallocate
;
394 struct fw_cdev_send_response send_response
;
395 struct fw_cdev_initiate_bus_reset initiate_bus_reset
;
396 struct fw_cdev_add_descriptor add_descriptor
;
397 struct fw_cdev_remove_descriptor remove_descriptor
;
398 struct fw_cdev_create_iso_context create_iso_context
;
399 struct fw_cdev_queue_iso queue_iso
;
400 struct fw_cdev_start_iso start_iso
;
401 struct fw_cdev_stop_iso stop_iso
;
402 struct fw_cdev_get_cycle_timer get_cycle_timer
;
403 struct fw_cdev_allocate_iso_resource allocate_iso_resource
;
404 struct fw_cdev_send_stream_packet send_stream_packet
;
405 struct fw_cdev_get_cycle_timer2 get_cycle_timer2
;
406 struct fw_cdev_send_phy_packet send_phy_packet
;
409 static int ioctl_get_info(struct client
*client
, union ioctl_arg
*arg
)
411 struct fw_cdev_get_info
*a
= &arg
->get_info
;
412 struct fw_cdev_event_bus_reset bus_reset
;
413 unsigned long ret
= 0;
415 client
->version
= a
->version
;
416 a
->version
= FW_CDEV_KERNEL_VERSION
;
417 a
->card
= client
->device
->card
->index
;
419 down_read(&fw_device_rwsem
);
422 size_t want
= a
->rom_length
;
423 size_t have
= client
->device
->config_rom_length
* 4;
425 ret
= copy_to_user(u64_to_uptr(a
->rom
),
426 client
->device
->config_rom
, min(want
, have
));
428 a
->rom_length
= client
->device
->config_rom_length
* 4;
430 up_read(&fw_device_rwsem
);
435 client
->bus_reset_closure
= a
->bus_reset_closure
;
436 if (a
->bus_reset
!= 0) {
437 fill_bus_reset_event(&bus_reset
, client
);
438 if (copy_to_user(u64_to_uptr(a
->bus_reset
),
439 &bus_reset
, sizeof(bus_reset
)))
446 static int add_client_resource(struct client
*client
,
447 struct client_resource
*resource
, gfp_t gfp_mask
)
453 if (idr_pre_get(&client
->resource_idr
, gfp_mask
) == 0)
456 spin_lock_irqsave(&client
->lock
, flags
);
457 if (client
->in_shutdown
)
460 ret
= idr_get_new(&client
->resource_idr
, resource
,
464 schedule_if_iso_resource(resource
);
466 spin_unlock_irqrestore(&client
->lock
, flags
);
471 return ret
< 0 ? ret
: 0;
474 static int release_client_resource(struct client
*client
, u32 handle
,
475 client_resource_release_fn_t release
,
476 struct client_resource
**return_resource
)
478 struct client_resource
*resource
;
480 spin_lock_irq(&client
->lock
);
481 if (client
->in_shutdown
)
484 resource
= idr_find(&client
->resource_idr
, handle
);
485 if (resource
&& resource
->release
== release
)
486 idr_remove(&client
->resource_idr
, handle
);
487 spin_unlock_irq(&client
->lock
);
489 if (!(resource
&& resource
->release
== release
))
493 *return_resource
= resource
;
495 resource
->release(client
, resource
);
502 static void release_transaction(struct client
*client
,
503 struct client_resource
*resource
)
505 struct outbound_transaction_resource
*r
= container_of(resource
,
506 struct outbound_transaction_resource
, resource
);
508 fw_cancel_transaction(client
->device
->card
, &r
->transaction
);
511 static void complete_transaction(struct fw_card
*card
, int rcode
,
512 void *payload
, size_t length
, void *data
)
514 struct outbound_transaction_event
*e
= data
;
515 struct fw_cdev_event_response
*rsp
= &e
->response
;
516 struct client
*client
= e
->client
;
519 if (length
< rsp
->length
)
520 rsp
->length
= length
;
521 if (rcode
== RCODE_COMPLETE
)
522 memcpy(rsp
->data
, payload
, rsp
->length
);
524 spin_lock_irqsave(&client
->lock
, flags
);
526 * 1. If called while in shutdown, the idr tree must be left untouched.
527 * The idr handle will be removed and the client reference will be
529 * 2. If the call chain was release_client_resource ->
530 * release_transaction -> complete_transaction (instead of a normal
531 * conclusion of the transaction), i.e. if this resource was already
532 * unregistered from the idr, the client reference will be dropped
533 * by release_client_resource and we must not drop it here.
535 if (!client
->in_shutdown
&&
536 idr_find(&client
->resource_idr
, e
->r
.resource
.handle
)) {
537 idr_remove(&client
->resource_idr
, e
->r
.resource
.handle
);
538 /* Drop the idr's reference */
541 spin_unlock_irqrestore(&client
->lock
, flags
);
543 rsp
->type
= FW_CDEV_EVENT_RESPONSE
;
547 * In the case that sizeof(*rsp) doesn't align with the position of the
548 * data, and the read is short, preserve an extra copy of the data
549 * to stay compatible with a pre-2.6.27 bug. Since the bug is harmless
550 * for short reads and some apps depended on it, this is both safe
551 * and prudent for compatibility.
553 if (rsp
->length
<= sizeof(*rsp
) - offsetof(typeof(*rsp
), data
))
554 queue_event(client
, &e
->event
, rsp
, sizeof(*rsp
),
555 rsp
->data
, rsp
->length
);
557 queue_event(client
, &e
->event
, rsp
, sizeof(*rsp
) + rsp
->length
,
560 /* Drop the transaction callback's reference */
564 static int init_request(struct client
*client
,
565 struct fw_cdev_send_request
*request
,
566 int destination_id
, int speed
)
568 struct outbound_transaction_event
*e
;
571 if (request
->tcode
!= TCODE_STREAM_DATA
&&
572 (request
->length
> 4096 || request
->length
> 512 << speed
))
575 if (request
->tcode
== TCODE_WRITE_QUADLET_REQUEST
&&
579 e
= kmalloc(sizeof(*e
) + request
->length
, GFP_KERNEL
);
584 e
->response
.length
= request
->length
;
585 e
->response
.closure
= request
->closure
;
588 copy_from_user(e
->response
.data
,
589 u64_to_uptr(request
->data
), request
->length
)) {
594 e
->r
.resource
.release
= release_transaction
;
595 ret
= add_client_resource(client
, &e
->r
.resource
, GFP_KERNEL
);
599 /* Get a reference for the transaction callback */
602 fw_send_request(client
->device
->card
, &e
->r
.transaction
,
603 request
->tcode
, destination_id
, request
->generation
,
604 speed
, request
->offset
, e
->response
.data
,
605 request
->length
, complete_transaction
, e
);
614 static int ioctl_send_request(struct client
*client
, union ioctl_arg
*arg
)
616 switch (arg
->send_request
.tcode
) {
617 case TCODE_WRITE_QUADLET_REQUEST
:
618 case TCODE_WRITE_BLOCK_REQUEST
:
619 case TCODE_READ_QUADLET_REQUEST
:
620 case TCODE_READ_BLOCK_REQUEST
:
621 case TCODE_LOCK_MASK_SWAP
:
622 case TCODE_LOCK_COMPARE_SWAP
:
623 case TCODE_LOCK_FETCH_ADD
:
624 case TCODE_LOCK_LITTLE_ADD
:
625 case TCODE_LOCK_BOUNDED_ADD
:
626 case TCODE_LOCK_WRAP_ADD
:
627 case TCODE_LOCK_VENDOR_DEPENDENT
:
633 return init_request(client
, &arg
->send_request
, client
->device
->node_id
,
634 client
->device
->max_speed
);
637 static inline bool is_fcp_request(struct fw_request
*request
)
639 return request
== NULL
;
642 static void release_request(struct client
*client
,
643 struct client_resource
*resource
)
645 struct inbound_transaction_resource
*r
= container_of(resource
,
646 struct inbound_transaction_resource
, resource
);
648 if (is_fcp_request(r
->request
))
651 fw_send_response(r
->card
, r
->request
, RCODE_CONFLICT_ERROR
);
653 fw_card_put(r
->card
);
657 static void handle_request(struct fw_card
*card
, struct fw_request
*request
,
658 int tcode
, int destination
, int source
,
659 int generation
, unsigned long long offset
,
660 void *payload
, size_t length
, void *callback_data
)
662 struct address_handler_resource
*handler
= callback_data
;
663 struct inbound_transaction_resource
*r
;
664 struct inbound_transaction_event
*e
;
666 void *fcp_frame
= NULL
;
669 /* card may be different from handler->client->device->card */
672 r
= kmalloc(sizeof(*r
), GFP_ATOMIC
);
673 e
= kmalloc(sizeof(*e
), GFP_ATOMIC
);
674 if (r
== NULL
|| e
== NULL
)
678 r
->request
= request
;
682 if (is_fcp_request(request
)) {
684 * FIXME: Let core-transaction.c manage a
685 * single reference-counted copy?
687 fcp_frame
= kmemdup(payload
, length
, GFP_ATOMIC
);
688 if (fcp_frame
== NULL
)
694 r
->resource
.release
= release_request
;
695 ret
= add_client_resource(handler
->client
, &r
->resource
, GFP_ATOMIC
);
699 if (handler
->client
->version
< FW_CDEV_VERSION_EVENT_REQUEST2
) {
700 struct fw_cdev_event_request
*req
= &e
->req
.request
;
703 tcode
= TCODE_LOCK_REQUEST
;
705 req
->type
= FW_CDEV_EVENT_REQUEST
;
707 req
->offset
= offset
;
708 req
->length
= length
;
709 req
->handle
= r
->resource
.handle
;
710 req
->closure
= handler
->closure
;
711 event_size0
= sizeof(*req
);
713 struct fw_cdev_event_request2
*req
= &e
->req
.request2
;
715 req
->type
= FW_CDEV_EVENT_REQUEST2
;
717 req
->offset
= offset
;
718 req
->source_node_id
= source
;
719 req
->destination_node_id
= destination
;
720 req
->card
= card
->index
;
721 req
->generation
= generation
;
722 req
->length
= length
;
723 req
->handle
= r
->resource
.handle
;
724 req
->closure
= handler
->closure
;
725 event_size0
= sizeof(*req
);
728 queue_event(handler
->client
, &e
->event
,
729 &e
->req
, event_size0
, r
->data
, length
);
737 if (!is_fcp_request(request
))
738 fw_send_response(card
, request
, RCODE_CONFLICT_ERROR
);
743 static void release_address_handler(struct client
*client
,
744 struct client_resource
*resource
)
746 struct address_handler_resource
*r
=
747 container_of(resource
, struct address_handler_resource
, resource
);
749 fw_core_remove_address_handler(&r
->handler
);
753 static int ioctl_allocate(struct client
*client
, union ioctl_arg
*arg
)
755 struct fw_cdev_allocate
*a
= &arg
->allocate
;
756 struct address_handler_resource
*r
;
757 struct fw_address_region region
;
760 r
= kmalloc(sizeof(*r
), GFP_KERNEL
);
764 region
.start
= a
->offset
;
765 region
.end
= a
->offset
+ a
->length
;
766 r
->handler
.length
= a
->length
;
767 r
->handler
.address_callback
= handle_request
;
768 r
->handler
.callback_data
= r
;
769 r
->closure
= a
->closure
;
772 ret
= fw_core_add_address_handler(&r
->handler
, ®ion
);
778 r
->resource
.release
= release_address_handler
;
779 ret
= add_client_resource(client
, &r
->resource
, GFP_KERNEL
);
781 release_address_handler(client
, &r
->resource
);
784 a
->handle
= r
->resource
.handle
;
789 static int ioctl_deallocate(struct client
*client
, union ioctl_arg
*arg
)
791 return release_client_resource(client
, arg
->deallocate
.handle
,
792 release_address_handler
, NULL
);
795 static int ioctl_send_response(struct client
*client
, union ioctl_arg
*arg
)
797 struct fw_cdev_send_response
*a
= &arg
->send_response
;
798 struct client_resource
*resource
;
799 struct inbound_transaction_resource
*r
;
802 if (release_client_resource(client
, a
->handle
,
803 release_request
, &resource
) < 0)
806 r
= container_of(resource
, struct inbound_transaction_resource
,
808 if (is_fcp_request(r
->request
))
811 if (a
->length
!= fw_get_response_length(r
->request
)) {
816 if (copy_from_user(r
->data
, u64_to_uptr(a
->data
), a
->length
)) {
821 fw_send_response(r
->card
, r
->request
, a
->rcode
);
823 fw_card_put(r
->card
);
829 static int ioctl_initiate_bus_reset(struct client
*client
, union ioctl_arg
*arg
)
831 fw_schedule_bus_reset(client
->device
->card
, true,
832 arg
->initiate_bus_reset
.type
== FW_CDEV_SHORT_RESET
);
836 static void release_descriptor(struct client
*client
,
837 struct client_resource
*resource
)
839 struct descriptor_resource
*r
=
840 container_of(resource
, struct descriptor_resource
, resource
);
842 fw_core_remove_descriptor(&r
->descriptor
);
846 static int ioctl_add_descriptor(struct client
*client
, union ioctl_arg
*arg
)
848 struct fw_cdev_add_descriptor
*a
= &arg
->add_descriptor
;
849 struct descriptor_resource
*r
;
852 /* Access policy: Allow this ioctl only on local nodes' device files. */
853 if (!client
->device
->is_local
)
859 r
= kmalloc(sizeof(*r
) + a
->length
* 4, GFP_KERNEL
);
863 if (copy_from_user(r
->data
, u64_to_uptr(a
->data
), a
->length
* 4)) {
868 r
->descriptor
.length
= a
->length
;
869 r
->descriptor
.immediate
= a
->immediate
;
870 r
->descriptor
.key
= a
->key
;
871 r
->descriptor
.data
= r
->data
;
873 ret
= fw_core_add_descriptor(&r
->descriptor
);
877 r
->resource
.release
= release_descriptor
;
878 ret
= add_client_resource(client
, &r
->resource
, GFP_KERNEL
);
880 fw_core_remove_descriptor(&r
->descriptor
);
883 a
->handle
= r
->resource
.handle
;
892 static int ioctl_remove_descriptor(struct client
*client
, union ioctl_arg
*arg
)
894 return release_client_resource(client
, arg
->remove_descriptor
.handle
,
895 release_descriptor
, NULL
);
898 static void iso_callback(struct fw_iso_context
*context
, u32 cycle
,
899 size_t header_length
, void *header
, void *data
)
901 struct client
*client
= data
;
902 struct iso_interrupt_event
*e
;
904 e
= kmalloc(sizeof(*e
) + header_length
, GFP_ATOMIC
);
908 e
->interrupt
.type
= FW_CDEV_EVENT_ISO_INTERRUPT
;
909 e
->interrupt
.closure
= client
->iso_closure
;
910 e
->interrupt
.cycle
= cycle
;
911 e
->interrupt
.header_length
= header_length
;
912 memcpy(e
->interrupt
.header
, header
, header_length
);
913 queue_event(client
, &e
->event
, &e
->interrupt
,
914 sizeof(e
->interrupt
) + header_length
, NULL
, 0);
917 static int ioctl_create_iso_context(struct client
*client
, union ioctl_arg
*arg
)
919 struct fw_cdev_create_iso_context
*a
= &arg
->create_iso_context
;
920 struct fw_iso_context
*context
;
922 BUILD_BUG_ON(FW_CDEV_ISO_CONTEXT_TRANSMIT
!= FW_ISO_CONTEXT_TRANSMIT
||
923 FW_CDEV_ISO_CONTEXT_RECEIVE
!= FW_ISO_CONTEXT_RECEIVE
);
929 case FW_ISO_CONTEXT_RECEIVE
:
930 if (a
->header_size
< 4 || (a
->header_size
& 3))
934 case FW_ISO_CONTEXT_TRANSMIT
:
935 if (a
->speed
> SCODE_3200
)
943 context
= fw_iso_context_create(client
->device
->card
, a
->type
,
944 a
->channel
, a
->speed
, a
->header_size
,
945 iso_callback
, client
);
947 return PTR_ERR(context
);
949 /* We only support one context at this time. */
950 spin_lock_irq(&client
->lock
);
951 if (client
->iso_context
!= NULL
) {
952 spin_unlock_irq(&client
->lock
);
953 fw_iso_context_destroy(context
);
956 client
->iso_closure
= a
->closure
;
957 client
->iso_context
= context
;
958 spin_unlock_irq(&client
->lock
);
965 /* Macros for decoding the iso packet control header. */
966 #define GET_PAYLOAD_LENGTH(v) ((v) & 0xffff)
967 #define GET_INTERRUPT(v) (((v) >> 16) & 0x01)
968 #define GET_SKIP(v) (((v) >> 17) & 0x01)
969 #define GET_TAG(v) (((v) >> 18) & 0x03)
970 #define GET_SY(v) (((v) >> 20) & 0x0f)
971 #define GET_HEADER_LENGTH(v) (((v) >> 24) & 0xff)
973 static int ioctl_queue_iso(struct client
*client
, union ioctl_arg
*arg
)
975 struct fw_cdev_queue_iso
*a
= &arg
->queue_iso
;
976 struct fw_cdev_iso_packet __user
*p
, *end
, *next
;
977 struct fw_iso_context
*ctx
= client
->iso_context
;
978 unsigned long payload
, buffer_end
, header_length
;
982 struct fw_iso_packet packet
;
986 if (ctx
== NULL
|| a
->handle
!= 0)
990 * If the user passes a non-NULL data pointer, has mmap()'ed
991 * the iso buffer, and the pointer points inside the buffer,
992 * we setup the payload pointers accordingly. Otherwise we
993 * set them both to 0, which will still let packets with
994 * payload_length == 0 through. In other words, if no packets
995 * use the indirect payload, the iso buffer need not be mapped
996 * and the a->data pointer is ignored.
999 payload
= (unsigned long)a
->data
- client
->vm_start
;
1000 buffer_end
= client
->buffer
.page_count
<< PAGE_SHIFT
;
1001 if (a
->data
== 0 || client
->buffer
.pages
== NULL
||
1002 payload
>= buffer_end
) {
1007 p
= (struct fw_cdev_iso_packet __user
*)u64_to_uptr(a
->packets
);
1009 if (!access_ok(VERIFY_READ
, p
, a
->size
))
1012 end
= (void __user
*)p
+ a
->size
;
1015 if (get_user(control
, &p
->control
))
1017 u
.packet
.payload_length
= GET_PAYLOAD_LENGTH(control
);
1018 u
.packet
.interrupt
= GET_INTERRUPT(control
);
1019 u
.packet
.skip
= GET_SKIP(control
);
1020 u
.packet
.tag
= GET_TAG(control
);
1021 u
.packet
.sy
= GET_SY(control
);
1022 u
.packet
.header_length
= GET_HEADER_LENGTH(control
);
1024 if (ctx
->type
== FW_ISO_CONTEXT_TRANSMIT
) {
1025 if (u
.packet
.header_length
% 4 != 0)
1027 header_length
= u
.packet
.header_length
;
1030 * We require that header_length is a multiple of
1031 * the fixed header size, ctx->header_size.
1033 if (ctx
->header_size
== 0) {
1034 if (u
.packet
.header_length
> 0)
1036 } else if (u
.packet
.header_length
== 0 ||
1037 u
.packet
.header_length
% ctx
->header_size
!= 0) {
1043 next
= (struct fw_cdev_iso_packet __user
*)
1044 &p
->header
[header_length
/ 4];
1047 if (__copy_from_user
1048 (u
.packet
.header
, p
->header
, header_length
))
1050 if (u
.packet
.skip
&& ctx
->type
== FW_ISO_CONTEXT_TRANSMIT
&&
1051 u
.packet
.header_length
+ u
.packet
.payload_length
> 0)
1053 if (payload
+ u
.packet
.payload_length
> buffer_end
)
1056 if (fw_iso_context_queue(ctx
, &u
.packet
,
1057 &client
->buffer
, payload
))
1061 payload
+= u
.packet
.payload_length
;
1065 a
->size
-= uptr_to_u64(p
) - a
->packets
;
1066 a
->packets
= uptr_to_u64(p
);
1067 a
->data
= client
->vm_start
+ payload
;
1072 static int ioctl_start_iso(struct client
*client
, union ioctl_arg
*arg
)
1074 struct fw_cdev_start_iso
*a
= &arg
->start_iso
;
1077 FW_CDEV_ISO_CONTEXT_MATCH_TAG0
!= FW_ISO_CONTEXT_MATCH_TAG0
||
1078 FW_CDEV_ISO_CONTEXT_MATCH_TAG1
!= FW_ISO_CONTEXT_MATCH_TAG1
||
1079 FW_CDEV_ISO_CONTEXT_MATCH_TAG2
!= FW_ISO_CONTEXT_MATCH_TAG2
||
1080 FW_CDEV_ISO_CONTEXT_MATCH_TAG3
!= FW_ISO_CONTEXT_MATCH_TAG3
||
1081 FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS
!= FW_ISO_CONTEXT_MATCH_ALL_TAGS
);
1083 if (client
->iso_context
== NULL
|| a
->handle
!= 0)
1086 if (client
->iso_context
->type
== FW_ISO_CONTEXT_RECEIVE
&&
1087 (a
->tags
== 0 || a
->tags
> 15 || a
->sync
> 15))
1090 return fw_iso_context_start(client
->iso_context
,
1091 a
->cycle
, a
->sync
, a
->tags
);
1094 static int ioctl_stop_iso(struct client
*client
, union ioctl_arg
*arg
)
1096 struct fw_cdev_stop_iso
*a
= &arg
->stop_iso
;
1098 if (client
->iso_context
== NULL
|| a
->handle
!= 0)
1101 return fw_iso_context_stop(client
->iso_context
);
1104 static int ioctl_get_cycle_timer2(struct client
*client
, union ioctl_arg
*arg
)
1106 struct fw_cdev_get_cycle_timer2
*a
= &arg
->get_cycle_timer2
;
1107 struct fw_card
*card
= client
->device
->card
;
1108 struct timespec ts
= {0, 0};
1112 local_irq_disable();
1114 cycle_time
= card
->driver
->read_csr(card
, CSR_CYCLE_TIME
);
1116 switch (a
->clk_id
) {
1117 case CLOCK_REALTIME
: getnstimeofday(&ts
); break;
1118 case CLOCK_MONOTONIC
: do_posix_clock_monotonic_gettime(&ts
); break;
1119 case CLOCK_MONOTONIC_RAW
: getrawmonotonic(&ts
); break;
1126 a
->tv_sec
= ts
.tv_sec
;
1127 a
->tv_nsec
= ts
.tv_nsec
;
1128 a
->cycle_timer
= cycle_time
;
1133 static int ioctl_get_cycle_timer(struct client
*client
, union ioctl_arg
*arg
)
1135 struct fw_cdev_get_cycle_timer
*a
= &arg
->get_cycle_timer
;
1136 struct fw_cdev_get_cycle_timer2 ct2
;
1138 ct2
.clk_id
= CLOCK_REALTIME
;
1139 ioctl_get_cycle_timer2(client
, (union ioctl_arg
*)&ct2
);
1141 a
->local_time
= ct2
.tv_sec
* USEC_PER_SEC
+ ct2
.tv_nsec
/ NSEC_PER_USEC
;
1142 a
->cycle_timer
= ct2
.cycle_timer
;
1147 static void iso_resource_work(struct work_struct
*work
)
1149 struct iso_resource_event
*e
;
1150 struct iso_resource
*r
=
1151 container_of(work
, struct iso_resource
, work
.work
);
1152 struct client
*client
= r
->client
;
1153 int generation
, channel
, bandwidth
, todo
;
1154 bool skip
, free
, success
;
1156 spin_lock_irq(&client
->lock
);
1157 generation
= client
->device
->generation
;
1159 /* Allow 1000ms grace period for other reallocations. */
1160 if (todo
== ISO_RES_ALLOC
&&
1161 time_is_after_jiffies(client
->device
->card
->reset_jiffies
+ HZ
)) {
1162 schedule_iso_resource(r
, DIV_ROUND_UP(HZ
, 3));
1165 /* We could be called twice within the same generation. */
1166 skip
= todo
== ISO_RES_REALLOC
&&
1167 r
->generation
== generation
;
1169 free
= todo
== ISO_RES_DEALLOC
||
1170 todo
== ISO_RES_ALLOC_ONCE
||
1171 todo
== ISO_RES_DEALLOC_ONCE
;
1172 r
->generation
= generation
;
1173 spin_unlock_irq(&client
->lock
);
1178 bandwidth
= r
->bandwidth
;
1180 fw_iso_resource_manage(client
->device
->card
, generation
,
1181 r
->channels
, &channel
, &bandwidth
,
1182 todo
== ISO_RES_ALLOC
||
1183 todo
== ISO_RES_REALLOC
||
1184 todo
== ISO_RES_ALLOC_ONCE
,
1185 r
->transaction_data
);
1187 * Is this generation outdated already? As long as this resource sticks
1188 * in the idr, it will be scheduled again for a newer generation or at
1191 if (channel
== -EAGAIN
&&
1192 (todo
== ISO_RES_ALLOC
|| todo
== ISO_RES_REALLOC
))
1195 success
= channel
>= 0 || bandwidth
> 0;
1197 spin_lock_irq(&client
->lock
);
1199 * Transit from allocation to reallocation, except if the client
1200 * requested deallocation in the meantime.
1202 if (r
->todo
== ISO_RES_ALLOC
)
1203 r
->todo
= ISO_RES_REALLOC
;
1205 * Allocation or reallocation failure? Pull this resource out of the
1206 * idr and prepare for deletion, unless the client is shutting down.
1208 if (r
->todo
== ISO_RES_REALLOC
&& !success
&&
1209 !client
->in_shutdown
&&
1210 idr_find(&client
->resource_idr
, r
->resource
.handle
)) {
1211 idr_remove(&client
->resource_idr
, r
->resource
.handle
);
1215 spin_unlock_irq(&client
->lock
);
1217 if (todo
== ISO_RES_ALLOC
&& channel
>= 0)
1218 r
->channels
= 1ULL << channel
;
1220 if (todo
== ISO_RES_REALLOC
&& success
)
1223 if (todo
== ISO_RES_ALLOC
|| todo
== ISO_RES_ALLOC_ONCE
) {
1228 r
->e_dealloc
= NULL
;
1230 e
->iso_resource
.handle
= r
->resource
.handle
;
1231 e
->iso_resource
.channel
= channel
;
1232 e
->iso_resource
.bandwidth
= bandwidth
;
1234 queue_event(client
, &e
->event
,
1235 &e
->iso_resource
, sizeof(e
->iso_resource
), NULL
, 0);
1238 cancel_delayed_work(&r
->work
);
1240 kfree(r
->e_dealloc
);
1247 static void release_iso_resource(struct client
*client
,
1248 struct client_resource
*resource
)
1250 struct iso_resource
*r
=
1251 container_of(resource
, struct iso_resource
, resource
);
1253 spin_lock_irq(&client
->lock
);
1254 r
->todo
= ISO_RES_DEALLOC
;
1255 schedule_iso_resource(r
, 0);
1256 spin_unlock_irq(&client
->lock
);
1259 static int init_iso_resource(struct client
*client
,
1260 struct fw_cdev_allocate_iso_resource
*request
, int todo
)
1262 struct iso_resource_event
*e1
, *e2
;
1263 struct iso_resource
*r
;
1266 if ((request
->channels
== 0 && request
->bandwidth
== 0) ||
1267 request
->bandwidth
> BANDWIDTH_AVAILABLE_INITIAL
||
1268 request
->bandwidth
< 0)
1271 r
= kmalloc(sizeof(*r
), GFP_KERNEL
);
1272 e1
= kmalloc(sizeof(*e1
), GFP_KERNEL
);
1273 e2
= kmalloc(sizeof(*e2
), GFP_KERNEL
);
1274 if (r
== NULL
|| e1
== NULL
|| e2
== NULL
) {
1279 INIT_DELAYED_WORK(&r
->work
, iso_resource_work
);
1283 r
->channels
= request
->channels
;
1284 r
->bandwidth
= request
->bandwidth
;
1288 e1
->iso_resource
.closure
= request
->closure
;
1289 e1
->iso_resource
.type
= FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED
;
1290 e2
->iso_resource
.closure
= request
->closure
;
1291 e2
->iso_resource
.type
= FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED
;
1293 if (todo
== ISO_RES_ALLOC
) {
1294 r
->resource
.release
= release_iso_resource
;
1295 ret
= add_client_resource(client
, &r
->resource
, GFP_KERNEL
);
1299 r
->resource
.release
= NULL
;
1300 r
->resource
.handle
= -1;
1301 schedule_iso_resource(r
, 0);
1303 request
->handle
= r
->resource
.handle
;
1314 static int ioctl_allocate_iso_resource(struct client
*client
,
1315 union ioctl_arg
*arg
)
1317 return init_iso_resource(client
,
1318 &arg
->allocate_iso_resource
, ISO_RES_ALLOC
);
1321 static int ioctl_deallocate_iso_resource(struct client
*client
,
1322 union ioctl_arg
*arg
)
1324 return release_client_resource(client
,
1325 arg
->deallocate
.handle
, release_iso_resource
, NULL
);
1328 static int ioctl_allocate_iso_resource_once(struct client
*client
,
1329 union ioctl_arg
*arg
)
1331 return init_iso_resource(client
,
1332 &arg
->allocate_iso_resource
, ISO_RES_ALLOC_ONCE
);
1335 static int ioctl_deallocate_iso_resource_once(struct client
*client
,
1336 union ioctl_arg
*arg
)
1338 return init_iso_resource(client
,
1339 &arg
->allocate_iso_resource
, ISO_RES_DEALLOC_ONCE
);
1343 * Returns a speed code: Maximum speed to or from this device,
1344 * limited by the device's link speed, the local node's link speed,
1345 * and all PHY port speeds between the two links.
1347 static int ioctl_get_speed(struct client
*client
, union ioctl_arg
*arg
)
1349 return client
->device
->max_speed
;
1352 static int ioctl_send_broadcast_request(struct client
*client
,
1353 union ioctl_arg
*arg
)
1355 struct fw_cdev_send_request
*a
= &arg
->send_request
;
1358 case TCODE_WRITE_QUADLET_REQUEST
:
1359 case TCODE_WRITE_BLOCK_REQUEST
:
1365 /* Security policy: Only allow accesses to Units Space. */
1366 if (a
->offset
< CSR_REGISTER_BASE
+ CSR_CONFIG_ROM_END
)
1369 return init_request(client
, a
, LOCAL_BUS
| 0x3f, SCODE_100
);
1372 static int ioctl_send_stream_packet(struct client
*client
, union ioctl_arg
*arg
)
1374 struct fw_cdev_send_stream_packet
*a
= &arg
->send_stream_packet
;
1375 struct fw_cdev_send_request request
;
1378 if (a
->speed
> client
->device
->card
->link_speed
||
1379 a
->length
> 1024 << a
->speed
)
1382 if (a
->tag
> 3 || a
->channel
> 63 || a
->sy
> 15)
1385 dest
= fw_stream_packet_destination_id(a
->tag
, a
->channel
, a
->sy
);
1386 request
.tcode
= TCODE_STREAM_DATA
;
1387 request
.length
= a
->length
;
1388 request
.closure
= a
->closure
;
1389 request
.data
= a
->data
;
1390 request
.generation
= a
->generation
;
1392 return init_request(client
, &request
, dest
, a
->speed
);
1395 static void outbound_phy_packet_callback(struct fw_packet
*packet
,
1396 struct fw_card
*card
, int status
)
1398 struct outbound_phy_packet_event
*e
=
1399 container_of(packet
, struct outbound_phy_packet_event
, p
);
1403 case ACK_COMPLETE
: e
->phy_packet
.rcode
= RCODE_COMPLETE
; break;
1404 /* should never happen with PHY packets: */
1405 case ACK_PENDING
: e
->phy_packet
.rcode
= RCODE_COMPLETE
; break;
1408 case ACK_BUSY_B
: e
->phy_packet
.rcode
= RCODE_BUSY
; break;
1409 case ACK_DATA_ERROR
: e
->phy_packet
.rcode
= RCODE_DATA_ERROR
; break;
1410 case ACK_TYPE_ERROR
: e
->phy_packet
.rcode
= RCODE_TYPE_ERROR
; break;
1411 /* stale generation; cancelled; on certain controllers: no ack */
1412 default: e
->phy_packet
.rcode
= status
; break;
1415 queue_event(e
->client
, &e
->event
,
1416 &e
->phy_packet
, sizeof(e
->phy_packet
), NULL
, 0);
1417 client_put(e
->client
);
1420 static int ioctl_send_phy_packet(struct client
*client
, union ioctl_arg
*arg
)
1422 struct fw_cdev_send_phy_packet
*a
= &arg
->send_phy_packet
;
1423 struct fw_card
*card
= client
->device
->card
;
1424 struct outbound_phy_packet_event
*e
;
1426 /* Access policy: Allow this ioctl only on local nodes' device files. */
1427 if (!client
->device
->is_local
)
1430 e
= kzalloc(sizeof(*e
), GFP_KERNEL
);
1436 e
->p
.speed
= SCODE_100
;
1437 e
->p
.generation
= a
->generation
;
1438 e
->p
.header
[0] = a
->data
[0];
1439 e
->p
.header
[1] = a
->data
[1];
1440 e
->p
.header_length
= 8;
1441 e
->p
.callback
= outbound_phy_packet_callback
;
1442 e
->phy_packet
.closure
= a
->closure
;
1443 e
->phy_packet
.type
= FW_CDEV_EVENT_PHY_PACKET_SENT
;
1445 card
->driver
->send_request(card
, &e
->p
);
1450 static int (* const ioctl_handlers
[])(struct client
*, union ioctl_arg
*) = {
1451 [0x00] = ioctl_get_info
,
1452 [0x01] = ioctl_send_request
,
1453 [0x02] = ioctl_allocate
,
1454 [0x03] = ioctl_deallocate
,
1455 [0x04] = ioctl_send_response
,
1456 [0x05] = ioctl_initiate_bus_reset
,
1457 [0x06] = ioctl_add_descriptor
,
1458 [0x07] = ioctl_remove_descriptor
,
1459 [0x08] = ioctl_create_iso_context
,
1460 [0x09] = ioctl_queue_iso
,
1461 [0x0a] = ioctl_start_iso
,
1462 [0x0b] = ioctl_stop_iso
,
1463 [0x0c] = ioctl_get_cycle_timer
,
1464 [0x0d] = ioctl_allocate_iso_resource
,
1465 [0x0e] = ioctl_deallocate_iso_resource
,
1466 [0x0f] = ioctl_allocate_iso_resource_once
,
1467 [0x10] = ioctl_deallocate_iso_resource_once
,
1468 [0x11] = ioctl_get_speed
,
1469 [0x12] = ioctl_send_broadcast_request
,
1470 [0x13] = ioctl_send_stream_packet
,
1471 [0x14] = ioctl_get_cycle_timer2
,
1472 [0x15] = ioctl_send_phy_packet
,
1475 static int dispatch_ioctl(struct client
*client
,
1476 unsigned int cmd
, void __user
*arg
)
1478 union ioctl_arg buffer
;
1481 if (fw_device_is_shutdown(client
->device
))
1484 if (_IOC_TYPE(cmd
) != '#' ||
1485 _IOC_NR(cmd
) >= ARRAY_SIZE(ioctl_handlers
) ||
1486 _IOC_SIZE(cmd
) > sizeof(buffer
))
1489 if (_IOC_DIR(cmd
) == _IOC_READ
)
1490 memset(&buffer
, 0, _IOC_SIZE(cmd
));
1492 if (_IOC_DIR(cmd
) & _IOC_WRITE
)
1493 if (copy_from_user(&buffer
, arg
, _IOC_SIZE(cmd
)))
1496 ret
= ioctl_handlers
[_IOC_NR(cmd
)](client
, &buffer
);
1500 if (_IOC_DIR(cmd
) & _IOC_READ
)
1501 if (copy_to_user(arg
, &buffer
, _IOC_SIZE(cmd
)))
1507 static long fw_device_op_ioctl(struct file
*file
,
1508 unsigned int cmd
, unsigned long arg
)
1510 return dispatch_ioctl(file
->private_data
, cmd
, (void __user
*)arg
);
1513 #ifdef CONFIG_COMPAT
1514 static long fw_device_op_compat_ioctl(struct file
*file
,
1515 unsigned int cmd
, unsigned long arg
)
1517 return dispatch_ioctl(file
->private_data
, cmd
, compat_ptr(arg
));
1521 static int fw_device_op_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1523 struct client
*client
= file
->private_data
;
1524 enum dma_data_direction direction
;
1526 int page_count
, ret
;
1528 if (fw_device_is_shutdown(client
->device
))
1531 /* FIXME: We could support multiple buffers, but we don't. */
1532 if (client
->buffer
.pages
!= NULL
)
1535 if (!(vma
->vm_flags
& VM_SHARED
))
1538 if (vma
->vm_start
& ~PAGE_MASK
)
1541 client
->vm_start
= vma
->vm_start
;
1542 size
= vma
->vm_end
- vma
->vm_start
;
1543 page_count
= size
>> PAGE_SHIFT
;
1544 if (size
& ~PAGE_MASK
)
1547 if (vma
->vm_flags
& VM_WRITE
)
1548 direction
= DMA_TO_DEVICE
;
1550 direction
= DMA_FROM_DEVICE
;
1552 ret
= fw_iso_buffer_init(&client
->buffer
, client
->device
->card
,
1553 page_count
, direction
);
1557 ret
= fw_iso_buffer_map(&client
->buffer
, vma
);
1559 fw_iso_buffer_destroy(&client
->buffer
, client
->device
->card
);
1564 static int shutdown_resource(int id
, void *p
, void *data
)
1566 struct client_resource
*resource
= p
;
1567 struct client
*client
= data
;
1569 resource
->release(client
, resource
);
1575 static int fw_device_op_release(struct inode
*inode
, struct file
*file
)
1577 struct client
*client
= file
->private_data
;
1578 struct event
*event
, *next_event
;
1580 mutex_lock(&client
->device
->client_list_mutex
);
1581 list_del(&client
->link
);
1582 mutex_unlock(&client
->device
->client_list_mutex
);
1584 if (client
->iso_context
)
1585 fw_iso_context_destroy(client
->iso_context
);
1587 if (client
->buffer
.pages
)
1588 fw_iso_buffer_destroy(&client
->buffer
, client
->device
->card
);
1590 /* Freeze client->resource_idr and client->event_list */
1591 spin_lock_irq(&client
->lock
);
1592 client
->in_shutdown
= true;
1593 spin_unlock_irq(&client
->lock
);
1595 idr_for_each(&client
->resource_idr
, shutdown_resource
, client
);
1596 idr_remove_all(&client
->resource_idr
);
1597 idr_destroy(&client
->resource_idr
);
1599 list_for_each_entry_safe(event
, next_event
, &client
->event_list
, link
)
1607 static unsigned int fw_device_op_poll(struct file
*file
, poll_table
* pt
)
1609 struct client
*client
= file
->private_data
;
1610 unsigned int mask
= 0;
1612 poll_wait(file
, &client
->wait
, pt
);
1614 if (fw_device_is_shutdown(client
->device
))
1615 mask
|= POLLHUP
| POLLERR
;
1616 if (!list_empty(&client
->event_list
))
1617 mask
|= POLLIN
| POLLRDNORM
;
1622 const struct file_operations fw_device_ops
= {
1623 .owner
= THIS_MODULE
,
1624 .llseek
= no_llseek
,
1625 .open
= fw_device_op_open
,
1626 .read
= fw_device_op_read
,
1627 .unlocked_ioctl
= fw_device_op_ioctl
,
1628 .mmap
= fw_device_op_mmap
,
1629 .release
= fw_device_op_release
,
1630 .poll
= fw_device_op_poll
,
1631 #ifdef CONFIG_COMPAT
1632 .compat_ioctl
= fw_device_op_compat_ioctl
,