Lines Matching full:client
46 struct client { struct
71 static inline void client_get(struct client *client) in client_get() argument
73 kref_get(&client->kref); in client_get()
78 struct client *client = container_of(kref, struct client, kref); in client_release() local
80 fw_device_put(client->device); in client_release()
81 kfree(client); in client_release()
84 static void client_put(struct client *client) in client_put() argument
86 kref_put(&client->kref, client_release); in client_put()
90 typedef void (*client_resource_release_fn_t)(struct client *,
101 struct client *client; member
125 struct client *client; member
126 /* Schedule work and access todo only with client->lock held. */
136 static void release_iso_resource(struct client *, struct client_resource *);
140 client_get(r->client); in schedule_iso_resource()
142 client_put(r->client); in schedule_iso_resource()
168 struct client *client; member
198 struct client *client; member
239 struct client *client; in fw_device_op_open() local
250 client = kzalloc(sizeof(*client), GFP_KERNEL); in fw_device_op_open()
251 if (client == NULL) { in fw_device_op_open()
256 client->device = device; in fw_device_op_open()
257 spin_lock_init(&client->lock); in fw_device_op_open()
258 idr_init(&client->resource_idr); in fw_device_op_open()
259 INIT_LIST_HEAD(&client->event_list); in fw_device_op_open()
260 init_waitqueue_head(&client->wait); in fw_device_op_open()
261 init_waitqueue_head(&client->tx_flush_wait); in fw_device_op_open()
262 INIT_LIST_HEAD(&client->phy_receiver_link); in fw_device_op_open()
263 INIT_LIST_HEAD(&client->link); in fw_device_op_open()
264 kref_init(&client->kref); in fw_device_op_open()
266 file->private_data = client; in fw_device_op_open()
271 static void queue_event(struct client *client, struct event *event, in queue_event() argument
281 spin_lock_irqsave(&client->lock, flags); in queue_event()
282 if (client->in_shutdown) in queue_event()
285 list_add_tail(&event->link, &client->event_list); in queue_event()
286 spin_unlock_irqrestore(&client->lock, flags); in queue_event()
288 wake_up_interruptible(&client->wait); in queue_event()
291 static int dequeue_event(struct client *client, in dequeue_event() argument
298 ret = wait_event_interruptible(client->wait, in dequeue_event()
299 !list_empty(&client->event_list) || in dequeue_event()
300 fw_device_is_shutdown(client->device)); in dequeue_event()
304 if (list_empty(&client->event_list) && in dequeue_event()
305 fw_device_is_shutdown(client->device)) in dequeue_event()
308 spin_lock_irq(&client->lock); in dequeue_event()
309 event = list_first_entry(&client->event_list, struct event, link); in dequeue_event()
311 spin_unlock_irq(&client->lock); in dequeue_event()
333 struct client *client = file->private_data; in fw_device_op_read() local
335 return dequeue_event(client, buffer, count); in fw_device_op_read()
339 struct client *client) in fill_bus_reset_event() argument
341 struct fw_card *card = client->device->card; in fill_bus_reset_event()
345 event->closure = client->bus_reset_closure; in fill_bus_reset_event()
347 event->generation = client->device->generation; in fill_bus_reset_event()
348 event->node_id = client->device->node_id; in fill_bus_reset_event()
358 void (*callback)(struct client *client)) in for_each_client() argument
360 struct client *c; in for_each_client()
375 static void queue_bus_reset_event(struct client *client) in queue_bus_reset_event() argument
383 fill_bus_reset_event(&e->reset, client); in queue_bus_reset_event()
385 queue_event(client, &e->event, in queue_bus_reset_event()
388 spin_lock_irq(&client->lock); in queue_bus_reset_event()
389 idr_for_each(&client->resource_idr, schedule_reallocations, client); in queue_bus_reset_event()
390 spin_unlock_irq(&client->lock); in queue_bus_reset_event()
398 static void wake_up_client(struct client *client) in wake_up_client() argument
400 wake_up_interruptible(&client->wait); in wake_up_client()
431 static int ioctl_get_info(struct client *client, union ioctl_arg *arg) in ioctl_get_info() argument
437 client->version = a->version; in ioctl_get_info()
439 a->card = client->device->card->index; in ioctl_get_info()
445 size_t have = client->device->config_rom_length * 4; in ioctl_get_info()
448 client->device->config_rom, min(want, have)); in ioctl_get_info()
450 a->rom_length = client->device->config_rom_length * 4; in ioctl_get_info()
457 mutex_lock(&client->device->client_list_mutex); in ioctl_get_info()
459 client->bus_reset_closure = a->bus_reset_closure; in ioctl_get_info()
461 fill_bus_reset_event(&bus_reset, client); in ioctl_get_info()
465 if (ret == 0 && list_empty(&client->link)) in ioctl_get_info()
466 list_add_tail(&client->link, &client->device->client_list); in ioctl_get_info()
468 mutex_unlock(&client->device->client_list_mutex); in ioctl_get_info()
473 static int add_client_resource(struct client *client, in add_client_resource() argument
482 spin_lock_irqsave(&client->lock, flags); in add_client_resource()
484 if (client->in_shutdown) in add_client_resource()
487 ret = idr_alloc(&client->resource_idr, resource, 0, 0, in add_client_resource()
491 client_get(client); in add_client_resource()
495 spin_unlock_irqrestore(&client->lock, flags); in add_client_resource()
502 static int release_client_resource(struct client *client, u32 handle, in release_client_resource() argument
508 spin_lock_irq(&client->lock); in release_client_resource()
509 if (client->in_shutdown) in release_client_resource()
512 resource = idr_find(&client->resource_idr, handle); in release_client_resource()
514 idr_remove(&client->resource_idr, handle); in release_client_resource()
515 spin_unlock_irq(&client->lock); in release_client_resource()
523 resource->release(client, resource); in release_client_resource()
525 client_put(client); in release_client_resource()
530 static void release_transaction(struct client *client, in release_transaction() argument
540 struct client *client = e->client; in complete_transaction() local
548 spin_lock_irqsave(&client->lock, flags); in complete_transaction()
549 idr_remove(&client->resource_idr, e->r.resource.handle); in complete_transaction()
550 if (client->in_shutdown) in complete_transaction()
551 wake_up(&client->tx_flush_wait); in complete_transaction()
552 spin_unlock_irqrestore(&client->lock, flags); in complete_transaction()
565 queue_event(client, &e->event, rsp, sizeof(*rsp), in complete_transaction()
568 queue_event(client, &e->event, rsp, sizeof(*rsp) + rsp->length, in complete_transaction()
572 client_put(client); in complete_transaction()
575 static int init_request(struct client *client, in init_request() argument
594 e->client = client; in init_request()
606 ret = add_client_resource(client, &e->r.resource, GFP_KERNEL); in init_request()
610 fw_send_request(client->device->card, &e->r.transaction, in init_request()
622 static int ioctl_send_request(struct client *client, union ioctl_arg *arg) in ioctl_send_request() argument
641 return init_request(client, &arg->send_request, client->device->node_id, in ioctl_send_request()
642 client->device->max_speed); in ioctl_send_request()
650 static void release_request(struct client *client, in release_request() argument
677 /* card may be different from handler->client->device->card */ in handle_request()
703 ret = add_client_resource(handler->client, &r->resource, GFP_ATOMIC); in handle_request()
707 if (handler->client->version < FW_CDEV_VERSION_EVENT_REQUEST2) { in handle_request()
736 queue_event(handler->client, &e->event, in handle_request()
751 static void release_address_handler(struct client *client, in release_address_handler() argument
761 static int ioctl_allocate(struct client *client, union ioctl_arg *arg) in ioctl_allocate() argument
773 if (client->version < FW_CDEV_VERSION_ALLOCATE_REGION_END) in ioctl_allocate()
782 r->client = client; in ioctl_allocate()
792 ret = add_client_resource(client, &r->resource, GFP_KERNEL); in ioctl_allocate()
794 release_address_handler(client, &r->resource); in ioctl_allocate()
802 static int ioctl_deallocate(struct client *client, union ioctl_arg *arg) in ioctl_deallocate() argument
804 return release_client_resource(client, arg->deallocate.handle, in ioctl_deallocate()
808 static int ioctl_send_response(struct client *client, union ioctl_arg *arg) in ioctl_send_response() argument
815 if (release_client_resource(client, a->handle, in ioctl_send_response()
844 static int ioctl_initiate_bus_reset(struct client *client, union ioctl_arg *arg) in ioctl_initiate_bus_reset() argument
846 fw_schedule_bus_reset(client->device->card, true, in ioctl_initiate_bus_reset()
851 static void release_descriptor(struct client *client, in release_descriptor() argument
861 static int ioctl_add_descriptor(struct client *client, union ioctl_arg *arg) in ioctl_add_descriptor() argument
868 if (!client->device->is_local) in ioctl_add_descriptor()
893 ret = add_client_resource(client, &r->resource, GFP_KERNEL); in ioctl_add_descriptor()
907 static int ioctl_remove_descriptor(struct client *client, union ioctl_arg *arg) in ioctl_remove_descriptor() argument
909 return release_client_resource(client, arg->remove_descriptor.handle, in ioctl_remove_descriptor()
916 struct client *client = data; in iso_callback() local
924 e->interrupt.closure = client->iso_closure; in iso_callback()
928 queue_event(client, &e->event, &e->interrupt, in iso_callback()
935 struct client *client = data; in iso_mc_callback() local
943 e->interrupt.closure = client->iso_closure; in iso_mc_callback()
944 e->interrupt.completed = fw_iso_buffer_lookup(&client->buffer, in iso_mc_callback()
946 queue_event(client, &e->event, &e->interrupt, in iso_mc_callback()
958 static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg) in ioctl_create_iso_context() argument
994 context = fw_iso_context_create(client->device->card, a->type, in ioctl_create_iso_context()
995 a->channel, a->speed, a->header_size, cb, client); in ioctl_create_iso_context()
998 if (client->version < FW_CDEV_VERSION_AUTO_FLUSH_ISO_OVERFLOW) in ioctl_create_iso_context()
1002 spin_lock_irq(&client->lock); in ioctl_create_iso_context()
1003 if (client->iso_context != NULL) { in ioctl_create_iso_context()
1004 spin_unlock_irq(&client->lock); in ioctl_create_iso_context()
1009 if (!client->buffer_is_mapped) { in ioctl_create_iso_context()
1010 ret = fw_iso_buffer_map_dma(&client->buffer, in ioctl_create_iso_context()
1011 client->device->card, in ioctl_create_iso_context()
1014 spin_unlock_irq(&client->lock); in ioctl_create_iso_context()
1019 client->buffer_is_mapped = true; in ioctl_create_iso_context()
1021 client->iso_closure = a->closure; in ioctl_create_iso_context()
1022 client->iso_context = context; in ioctl_create_iso_context()
1023 spin_unlock_irq(&client->lock); in ioctl_create_iso_context()
1030 static int ioctl_set_iso_channels(struct client *client, union ioctl_arg *arg) in ioctl_set_iso_channels() argument
1033 struct fw_iso_context *ctx = client->iso_context; in ioctl_set_iso_channels()
1049 static int ioctl_queue_iso(struct client *client, union ioctl_arg *arg) in ioctl_queue_iso() argument
1053 struct fw_iso_context *ctx = client->iso_context; in ioctl_queue_iso()
1074 payload = (unsigned long)a->data - client->vm_start; in ioctl_queue_iso()
1075 buffer_end = client->buffer.page_count << PAGE_SHIFT; in ioctl_queue_iso()
1076 if (a->data == 0 || client->buffer.pages == NULL || in ioctl_queue_iso()
1133 &client->buffer, payload)) in ioctl_queue_iso()
1144 a->data = client->vm_start + payload; in ioctl_queue_iso()
1149 static int ioctl_start_iso(struct client *client, union ioctl_arg *arg) in ioctl_start_iso() argument
1160 if (client->iso_context == NULL || a->handle != 0) in ioctl_start_iso()
1163 if (client->iso_context->type == FW_ISO_CONTEXT_RECEIVE && in ioctl_start_iso()
1167 return fw_iso_context_start(client->iso_context, in ioctl_start_iso()
1171 static int ioctl_stop_iso(struct client *client, union ioctl_arg *arg) in ioctl_stop_iso() argument
1175 if (client->iso_context == NULL || a->handle != 0) in ioctl_stop_iso()
1178 return fw_iso_context_stop(client->iso_context); in ioctl_stop_iso()
1181 static int ioctl_flush_iso(struct client *client, union ioctl_arg *arg) in ioctl_flush_iso() argument
1185 if (client->iso_context == NULL || a->handle != 0) in ioctl_flush_iso()
1188 return fw_iso_context_flush_completions(client->iso_context); in ioctl_flush_iso()
1191 static int ioctl_get_cycle_timer2(struct client *client, union ioctl_arg *arg) in ioctl_get_cycle_timer2() argument
1194 struct fw_card *card = client->device->card; in ioctl_get_cycle_timer2()
1220 static int ioctl_get_cycle_timer(struct client *client, union ioctl_arg *arg) in ioctl_get_cycle_timer() argument
1226 ioctl_get_cycle_timer2(client, (union ioctl_arg *)&ct2); in ioctl_get_cycle_timer()
1239 struct client *client = r->client; in iso_resource_work() local
1243 spin_lock_irq(&client->lock); in iso_resource_work()
1244 generation = client->device->generation; in iso_resource_work()
1249 client->device->card->reset_jiffies + HZ)) { in iso_resource_work()
1261 spin_unlock_irq(&client->lock); in iso_resource_work()
1268 fw_iso_resource_manage(client->device->card, generation, in iso_resource_work()
1284 spin_lock_irq(&client->lock); in iso_resource_work()
1286 * Transit from allocation to reallocation, except if the client in iso_resource_work()
1293 * idr and prepare for deletion, unless the client is shutting down. in iso_resource_work()
1296 !client->in_shutdown && in iso_resource_work()
1297 idr_remove(&client->resource_idr, r->resource.handle)) { in iso_resource_work()
1298 client_put(client); in iso_resource_work()
1301 spin_unlock_irq(&client->lock); in iso_resource_work()
1320 queue_event(client, &e->event, in iso_resource_work()
1330 client_put(client); in iso_resource_work()
1333 static void release_iso_resource(struct client *client, in release_iso_resource() argument
1339 spin_lock_irq(&client->lock); in release_iso_resource()
1342 spin_unlock_irq(&client->lock); in release_iso_resource()
1345 static int init_iso_resource(struct client *client, in init_iso_resource() argument
1365 r->client = client; in init_iso_resource()
1380 ret = add_client_resource(client, &r->resource, GFP_KERNEL); in init_iso_resource()
1399 static int ioctl_allocate_iso_resource(struct client *client, in ioctl_allocate_iso_resource() argument
1402 return init_iso_resource(client, in ioctl_allocate_iso_resource()
1406 static int ioctl_deallocate_iso_resource(struct client *client, in ioctl_deallocate_iso_resource() argument
1409 return release_client_resource(client, in ioctl_deallocate_iso_resource()
1413 static int ioctl_allocate_iso_resource_once(struct client *client, in ioctl_allocate_iso_resource_once() argument
1416 return init_iso_resource(client, in ioctl_allocate_iso_resource_once()
1420 static int ioctl_deallocate_iso_resource_once(struct client *client, in ioctl_deallocate_iso_resource_once() argument
1423 return init_iso_resource(client, in ioctl_deallocate_iso_resource_once()
1432 static int ioctl_get_speed(struct client *client, union ioctl_arg *arg) in ioctl_get_speed() argument
1434 return client->device->max_speed; in ioctl_get_speed()
1437 static int ioctl_send_broadcast_request(struct client *client, in ioctl_send_broadcast_request() argument
1454 return init_request(client, a, LOCAL_BUS | 0x3f, SCODE_100); in ioctl_send_broadcast_request()
1457 static int ioctl_send_stream_packet(struct client *client, union ioctl_arg *arg) in ioctl_send_stream_packet() argument
1463 if (a->speed > client->device->card->link_speed || in ioctl_send_stream_packet()
1477 return init_request(client, &request, dest, a->speed); in ioctl_send_stream_packet()
1485 struct client *e_client; in outbound_phy_packet_callback()
1502 e_client = e->client; in outbound_phy_packet_callback()
1503 queue_event(e->client, &e->event, &e->phy_packet, in outbound_phy_packet_callback()
1508 static int ioctl_send_phy_packet(struct client *client, union ioctl_arg *arg) in ioctl_send_phy_packet() argument
1511 struct fw_card *card = client->device->card; in ioctl_send_phy_packet()
1515 if (!client->device->is_local) in ioctl_send_phy_packet()
1522 client_get(client); in ioctl_send_phy_packet()
1523 e->client = client; in ioctl_send_phy_packet()
1541 static int ioctl_receive_phy_packets(struct client *client, union ioctl_arg *arg) in ioctl_receive_phy_packets() argument
1544 struct fw_card *card = client->device->card; in ioctl_receive_phy_packets()
1547 if (!client->device->is_local) in ioctl_receive_phy_packets()
1552 list_move_tail(&client->phy_receiver_link, &card->phy_receiver_list); in ioctl_receive_phy_packets()
1553 client->phy_receiver_closure = a->closure; in ioctl_receive_phy_packets()
1562 struct client *client; in fw_cdev_handle_phy_packet() local
1568 list_for_each_entry(client, &card->phy_receiver_list, phy_receiver_link) { in fw_cdev_handle_phy_packet()
1573 e->phy_packet.closure = client->phy_receiver_closure; in fw_cdev_handle_phy_packet()
1579 queue_event(client, &e->event, in fw_cdev_handle_phy_packet()
1586 static int (* const ioctl_handlers[])(struct client *, union ioctl_arg *) = {
1614 static int dispatch_ioctl(struct client *client, in dispatch_ioctl() argument
1620 if (fw_device_is_shutdown(client->device)) in dispatch_ioctl()
1634 ret = ioctl_handlers[_IOC_NR(cmd)](client, &buffer); in dispatch_ioctl()
1653 struct client *client = file->private_data; in fw_device_op_mmap() local
1657 if (fw_device_is_shutdown(client->device)) in fw_device_op_mmap()
1661 if (client->buffer.pages != NULL) in fw_device_op_mmap()
1670 client->vm_start = vma->vm_start; in fw_device_op_mmap()
1676 ret = fw_iso_buffer_alloc(&client->buffer, page_count); in fw_device_op_mmap()
1680 spin_lock_irq(&client->lock); in fw_device_op_mmap()
1681 if (client->iso_context) { in fw_device_op_mmap()
1682 ret = fw_iso_buffer_map_dma(&client->buffer, in fw_device_op_mmap()
1683 client->device->card, in fw_device_op_mmap()
1684 iso_dma_direction(client->iso_context)); in fw_device_op_mmap()
1685 client->buffer_is_mapped = (ret == 0); in fw_device_op_mmap()
1687 spin_unlock_irq(&client->lock); in fw_device_op_mmap()
1691 ret = vm_map_pages_zero(vma, client->buffer.pages, in fw_device_op_mmap()
1692 client->buffer.page_count); in fw_device_op_mmap()
1698 fw_iso_buffer_destroy(&client->buffer, client->device->card); in fw_device_op_mmap()
1709 static int has_outbound_transactions(struct client *client) in has_outbound_transactions() argument
1713 spin_lock_irq(&client->lock); in has_outbound_transactions()
1714 ret = idr_for_each(&client->resource_idr, in has_outbound_transactions()
1716 spin_unlock_irq(&client->lock); in has_outbound_transactions()
1724 struct client *client = data; in shutdown_resource() local
1726 resource->release(client, resource); in shutdown_resource()
1727 client_put(client); in shutdown_resource()
1734 struct client *client = file->private_data; in fw_device_op_release() local
1737 spin_lock_irq(&client->device->card->lock); in fw_device_op_release()
1738 list_del(&client->phy_receiver_link); in fw_device_op_release()
1739 spin_unlock_irq(&client->device->card->lock); in fw_device_op_release()
1741 mutex_lock(&client->device->client_list_mutex); in fw_device_op_release()
1742 list_del(&client->link); in fw_device_op_release()
1743 mutex_unlock(&client->device->client_list_mutex); in fw_device_op_release()
1745 if (client->iso_context) in fw_device_op_release()
1746 fw_iso_context_destroy(client->iso_context); in fw_device_op_release()
1748 if (client->buffer.pages) in fw_device_op_release()
1749 fw_iso_buffer_destroy(&client->buffer, client->device->card); in fw_device_op_release()
1751 /* Freeze client->resource_idr and client->event_list */ in fw_device_op_release()
1752 spin_lock_irq(&client->lock); in fw_device_op_release()
1753 client->in_shutdown = true; in fw_device_op_release()
1754 spin_unlock_irq(&client->lock); in fw_device_op_release()
1756 wait_event(client->tx_flush_wait, !has_outbound_transactions(client)); in fw_device_op_release()
1758 idr_for_each(&client->resource_idr, shutdown_resource, client); in fw_device_op_release()
1759 idr_destroy(&client->resource_idr); in fw_device_op_release()
1761 list_for_each_entry_safe(event, next_event, &client->event_list, link) in fw_device_op_release()
1764 client_put(client); in fw_device_op_release()
1771 struct client *client = file->private_data; in fw_device_op_poll() local
1774 poll_wait(file, &client->wait, pt); in fw_device_op_poll()
1776 if (fw_device_is_shutdown(client->device)) in fw_device_op_poll()
1778 if (!list_empty(&client->event_list)) in fw_device_op_poll()