Lines Matching refs:client
53 struct client { struct
78 static inline void client_get(struct client *client) in client_get() argument
80 kref_get(&client->kref); in client_get()
85 struct client *client = container_of(kref, struct client, kref); in client_release() local
87 fw_device_put(client->device); in client_release()
88 kfree(client); in client_release()
91 static void client_put(struct client *client) in client_put() argument
93 kref_put(&client->kref, client_release); in client_put()
97 typedef void (*client_resource_release_fn_t)(struct client *,
108 struct client *client; member
133 struct client *client; member
164 static void release_iso_resource(struct client *, struct client_resource *);
171 static void release_transaction(struct client *client,
181 client_get(r->client); in schedule_iso_resource()
183 client_put(r->client); in schedule_iso_resource()
202 struct client *client; member
236 struct client *client; member
283 struct client *client; in fw_device_op_open() local
294 client = kzalloc_obj(*client); in fw_device_op_open()
295 if (client == NULL) { in fw_device_op_open()
300 client->device = device; in fw_device_op_open()
301 spin_lock_init(&client->lock); in fw_device_op_open()
302 xa_init_flags(&client->resource_xa, XA_FLAGS_ALLOC1 | XA_FLAGS_LOCK_BH); in fw_device_op_open()
303 INIT_LIST_HEAD(&client->event_list); in fw_device_op_open()
304 init_waitqueue_head(&client->wait); in fw_device_op_open()
305 init_waitqueue_head(&client->tx_flush_wait); in fw_device_op_open()
306 INIT_LIST_HEAD(&client->phy_receiver_link); in fw_device_op_open()
307 INIT_LIST_HEAD(&client->link); in fw_device_op_open()
308 kref_init(&client->kref); in fw_device_op_open()
309 mutex_init(&client->iso_context_mutex); in fw_device_op_open()
311 file->private_data = client; in fw_device_op_open()
316 static void queue_event(struct client *client, struct event *event, in queue_event() argument
324 scoped_guard(spinlock_irqsave, &client->lock) { in queue_event()
325 if (client->in_shutdown) in queue_event()
328 list_add_tail(&event->link, &client->event_list); in queue_event()
331 wake_up_interruptible(&client->wait); in queue_event()
334 static int dequeue_event(struct client *client, in dequeue_event() argument
341 ret = wait_event_interruptible(client->wait, in dequeue_event()
342 !list_empty(&client->event_list) || in dequeue_event()
343 fw_device_is_shutdown(client->device)); in dequeue_event()
347 if (list_empty(&client->event_list) && in dequeue_event()
348 fw_device_is_shutdown(client->device)) in dequeue_event()
351 scoped_guard(spinlock_irq, &client->lock) { in dequeue_event()
352 event = list_first_entry(&client->event_list, struct event, link); in dequeue_event()
376 struct client *client = file->private_data; in fw_device_op_read() local
378 return dequeue_event(client, buffer, count); in fw_device_op_read()
382 struct client *client) in fill_bus_reset_event() argument
384 struct fw_card *card = client->device->card; in fill_bus_reset_event()
388 event->closure = client->bus_reset_closure; in fill_bus_reset_event()
390 event->generation = client->device->generation; in fill_bus_reset_event()
391 event->node_id = client->device->node_id; in fill_bus_reset_event()
399 void (*callback)(struct client *client)) in for_each_client() argument
401 struct client *c; in for_each_client()
409 static void queue_bus_reset_event(struct client *client) in queue_bus_reset_event() argument
419 fill_bus_reset_event(&e->reset, client); in queue_bus_reset_event()
421 queue_event(client, &e->event, in queue_bus_reset_event()
424 guard(spinlock_irq)(&client->lock); in queue_bus_reset_event()
426 xa_for_each(&client->resource_xa, index, resource) { in queue_bus_reset_event()
437 static void wake_up_client(struct client *client) in wake_up_client() argument
439 wake_up_interruptible(&client->wait); in wake_up_client()
470 static int ioctl_get_info(struct client *client, union ioctl_arg *arg) in ioctl_get_info() argument
476 client->version = a->version; in ioctl_get_info()
478 a->card = client->device->card->index; in ioctl_get_info()
483 size_t have = client->device->config_rom_length * 4; in ioctl_get_info()
485 ret = copy_to_user(u64_to_uptr(a->rom), client->device->config_rom, in ioctl_get_info()
490 a->rom_length = client->device->config_rom_length * 4; in ioctl_get_info()
493 guard(mutex)(&client->device->client_list_mutex); in ioctl_get_info()
495 client->bus_reset_closure = a->bus_reset_closure; in ioctl_get_info()
497 fill_bus_reset_event(&bus_reset, client); in ioctl_get_info()
501 if (ret == 0 && list_empty(&client->link)) in ioctl_get_info()
502 list_add_tail(&client->link, &client->device->client_list); in ioctl_get_info()
507 static int add_client_resource(struct client *client, struct client_resource *resource, in add_client_resource() argument
512 scoped_guard(spinlock_irqsave, &client->lock) { in add_client_resource()
515 if (client->in_shutdown) { in add_client_resource()
519 ret = xa_alloc(&client->resource_xa, &index, resource, xa_limit_32b, in add_client_resource()
522 ret = xa_alloc_bh(&client->resource_xa, &index, resource, in add_client_resource()
528 client_get(client); in add_client_resource()
537 static int release_client_resource(struct client *client, u32 handle, in release_client_resource() argument
544 scoped_guard(spinlock_irq, &client->lock) { in release_client_resource()
545 if (client->in_shutdown) in release_client_resource()
548 resource = xa_load(&client->resource_xa, index); in release_client_resource()
552 xa_erase(&client->resource_xa, handle); in release_client_resource()
558 resource->release(client, resource); in release_client_resource()
560 client_put(client); in release_client_resource()
565 static void release_transaction(struct client *client, in release_transaction() argument
574 struct client *client = e->client; in complete_transaction() local
577 scoped_guard(spinlock_irqsave, &client->lock) { in complete_transaction()
578 xa_erase(&client->resource_xa, index); in complete_transaction()
579 if (client->in_shutdown) in complete_transaction()
580 wake_up(&client->tx_flush_wait); in complete_transaction()
601 queue_event(client, &e->event, rsp, sizeof(*rsp), rsp->data, rsp->length); in complete_transaction()
603 queue_event(client, &e->event, rsp, sizeof(*rsp) + rsp->length, NULL, 0); in complete_transaction()
620 queue_event(client, &e->event, rsp, sizeof(*rsp) + rsp->length, NULL, 0); in complete_transaction()
630 client_put(client); in complete_transaction()
633 static int init_request(struct client *client, in init_request() argument
652 e->client = client; in init_request()
654 if (client->version < FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP) { in init_request()
676 ret = add_client_resource(client, &e->r.resource, GFP_KERNEL); in init_request()
680 fw_send_request_with_tstamp(client->device->card, &e->r.transaction, request->tcode, in init_request()
691 static int ioctl_send_request(struct client *client, union ioctl_arg *arg) in ioctl_send_request() argument
710 return init_request(client, &arg->send_request, client->device->node_id, in ioctl_send_request()
711 client->device->max_speed); in ioctl_send_request()
714 static void release_request(struct client *client, in release_request() argument
760 ret = add_client_resource(handler->client, &r->resource, GFP_ATOMIC); in handle_request()
764 if (handler->client->version < FW_CDEV_VERSION_EVENT_REQUEST2) { in handle_request()
777 } else if (handler->client->version < FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP) { in handle_request()
808 queue_event(handler->client, &e->event, in handle_request()
824 static void release_address_handler(struct client *client, in release_address_handler() argument
833 static int ioctl_allocate(struct client *client, union ioctl_arg *arg) in ioctl_allocate() argument
845 if (client->version < FW_CDEV_VERSION_ALLOCATE_REGION_END) in ioctl_allocate()
854 r->client = client; in ioctl_allocate()
864 ret = add_client_resource(client, &r->resource, GFP_KERNEL); in ioctl_allocate()
866 release_address_handler(client, &r->resource); in ioctl_allocate()
874 static int ioctl_deallocate(struct client *client, union ioctl_arg *arg) in ioctl_deallocate() argument
876 return release_client_resource(client, arg->deallocate.handle, in ioctl_deallocate()
880 static int ioctl_send_response(struct client *client, union ioctl_arg *arg) in ioctl_send_response() argument
887 if (release_client_resource(client, a->handle, in ioctl_send_response()
915 static int ioctl_initiate_bus_reset(struct client *client, union ioctl_arg *arg) in ioctl_initiate_bus_reset() argument
917 fw_schedule_bus_reset(client->device->card, true, in ioctl_initiate_bus_reset()
922 static void release_descriptor(struct client *client, in release_descriptor() argument
931 static int ioctl_add_descriptor(struct client *client, union ioctl_arg *arg) in ioctl_add_descriptor() argument
938 if (!client->device->is_local) in ioctl_add_descriptor()
964 ret = add_client_resource(client, &r->resource, GFP_KERNEL); in ioctl_add_descriptor()
978 static int ioctl_remove_descriptor(struct client *client, union ioctl_arg *arg) in ioctl_remove_descriptor() argument
980 return release_client_resource(client, arg->remove_descriptor.handle, in ioctl_remove_descriptor()
987 struct client *client = data; in iso_callback() local
995 e->interrupt.closure = client->iso_closure; in iso_callback()
999 queue_event(client, &e->event, &e->interrupt, in iso_callback()
1006 struct client *client = data; in iso_mc_callback() local
1014 e->interrupt.closure = client->iso_closure; in iso_mc_callback()
1015 e->interrupt.completed = fw_iso_buffer_lookup(&client->buffer, in iso_mc_callback()
1017 queue_event(client, &e->event, &e->interrupt, in iso_mc_callback()
1029 static int ioctl_create_iso_context(struct client *client, union ioctl_arg *arg) in ioctl_create_iso_context() argument
1060 context = fw_iso_mc_context_create(client->device->card, iso_mc_callback, client); in ioctl_create_iso_context()
1062 context = fw_iso_context_create(client->device->card, a->type, a->channel, a->speed, in ioctl_create_iso_context()
1063 a->header_size, iso_callback, client); in ioctl_create_iso_context()
1066 if (client->version < FW_CDEV_VERSION_AUTO_FLUSH_ISO_OVERFLOW) in ioctl_create_iso_context()
1070 scoped_guard(mutex, &client->iso_context_mutex) { in ioctl_create_iso_context()
1071 if (client->iso_context != NULL) { in ioctl_create_iso_context()
1078 if (client->buffer.pages && !client->buffer.dma_addrs) { in ioctl_create_iso_context()
1079 ret = fw_iso_buffer_map_dma(&client->buffer, client->device->card, in ioctl_create_iso_context()
1087 client->iso_closure = a->closure; in ioctl_create_iso_context()
1088 client->iso_context = context; in ioctl_create_iso_context()
1096 static int ioctl_set_iso_channels(struct client *client, union ioctl_arg *arg) in ioctl_set_iso_channels() argument
1099 struct fw_iso_context *ctx = client->iso_context; in ioctl_set_iso_channels()
1115 static int ioctl_queue_iso(struct client *client, union ioctl_arg *arg) in ioctl_queue_iso() argument
1119 struct fw_iso_context *ctx = client->iso_context; in ioctl_queue_iso()
1137 payload = (unsigned long)a->data - client->vm_start; in ioctl_queue_iso()
1138 buffer_end = client->buffer.page_count << PAGE_SHIFT; in ioctl_queue_iso()
1139 if (a->data == 0 || client->buffer.pages == NULL || in ioctl_queue_iso()
1195 if (fw_iso_context_queue(ctx, u, &client->buffer, payload)) in ioctl_queue_iso()
1206 a->data = client->vm_start + payload; in ioctl_queue_iso()
1211 static int ioctl_start_iso(struct client *client, union ioctl_arg *arg) in ioctl_start_iso() argument
1222 if (client->iso_context == NULL || a->handle != 0) in ioctl_start_iso()
1225 if (client->iso_context->type == FW_ISO_CONTEXT_RECEIVE && in ioctl_start_iso()
1229 return fw_iso_context_start(client->iso_context, in ioctl_start_iso()
1233 static int ioctl_stop_iso(struct client *client, union ioctl_arg *arg) in ioctl_stop_iso() argument
1237 if (client->iso_context == NULL || a->handle != 0) in ioctl_stop_iso()
1240 return fw_iso_context_stop(client->iso_context); in ioctl_stop_iso()
1243 static int ioctl_flush_iso(struct client *client, union ioctl_arg *arg) in ioctl_flush_iso() argument
1247 if (client->iso_context == NULL || a->handle != 0) in ioctl_flush_iso()
1250 return fw_iso_context_flush_completions(client->iso_context); in ioctl_flush_iso()
1253 static int ioctl_get_cycle_timer2(struct client *client, union ioctl_arg *arg) in ioctl_get_cycle_timer2() argument
1256 struct fw_card *card = client->device->card; in ioctl_get_cycle_timer2()
1282 static int ioctl_get_cycle_timer(struct client *client, union ioctl_arg *arg) in ioctl_get_cycle_timer() argument
1288 ioctl_get_cycle_timer2(client, (union ioctl_arg *)&ct2); in ioctl_get_cycle_timer()
1300 struct client *client = r->client; in iso_resource_work() local
1305 scoped_guard(spinlock_irq, &client->lock) { in iso_resource_work()
1306 generation = client->device->generation; in iso_resource_work()
1310 time_is_after_jiffies64(client->device->card->reset_jiffies + secs_to_jiffies(1))) { in iso_resource_work()
1329 fw_iso_resource_manage(client->device->card, generation, in iso_resource_work()
1345 scoped_guard(spinlock_irq, &client->lock) { in iso_resource_work()
1353 !client->in_shutdown && in iso_resource_work()
1354 xa_erase(&client->resource_xa, index)) { in iso_resource_work()
1355 client_put(client); in iso_resource_work()
1377 queue_event(client, &e->event, in iso_resource_work()
1387 client_put(client); in iso_resource_work()
1390 static void release_iso_resource(struct client *client, in release_iso_resource() argument
1395 guard(spinlock_irq)(&client->lock); in release_iso_resource()
1401 static int init_iso_resource(struct client *client, in init_iso_resource() argument
1421 r->client = client; in init_iso_resource()
1436 ret = add_client_resource(client, &r->resource, GFP_KERNEL); in init_iso_resource()
1455 static int ioctl_allocate_iso_resource(struct client *client, in ioctl_allocate_iso_resource() argument
1458 return init_iso_resource(client, in ioctl_allocate_iso_resource()
1462 static int ioctl_deallocate_iso_resource(struct client *client, in ioctl_deallocate_iso_resource() argument
1465 return release_client_resource(client, in ioctl_deallocate_iso_resource()
1469 static int ioctl_allocate_iso_resource_once(struct client *client, in ioctl_allocate_iso_resource_once() argument
1472 return init_iso_resource(client, in ioctl_allocate_iso_resource_once()
1476 static int ioctl_deallocate_iso_resource_once(struct client *client, in ioctl_deallocate_iso_resource_once() argument
1479 return init_iso_resource(client, in ioctl_deallocate_iso_resource_once()
1488 static int ioctl_get_speed(struct client *client, union ioctl_arg *arg) in ioctl_get_speed() argument
1490 return client->device->max_speed; in ioctl_get_speed()
1493 static int ioctl_send_broadcast_request(struct client *client, in ioctl_send_broadcast_request() argument
1510 return init_request(client, a, LOCAL_BUS | 0x3f, SCODE_100); in ioctl_send_broadcast_request()
1513 static int ioctl_send_stream_packet(struct client *client, union ioctl_arg *arg) in ioctl_send_stream_packet() argument
1519 if (a->speed > client->device->card->link_speed || in ioctl_send_stream_packet()
1533 return init_request(client, &request, dest, a->speed); in ioctl_send_stream_packet()
1541 struct client *e_client = e->client; in outbound_phy_packet_callback()
1580 queue_event(e->client, &e->event, &e->phy_packet, sizeof(*pp) + pp->length, in outbound_phy_packet_callback()
1590 queue_event(e->client, &e->event, &e->phy_packet, sizeof(*pp) + pp->length, in outbound_phy_packet_callback()
1602 static int ioctl_send_phy_packet(struct client *client, union ioctl_arg *arg) in ioctl_send_phy_packet() argument
1605 struct fw_card *card = client->device->card; in ioctl_send_phy_packet()
1609 if (!client->device->is_local) in ioctl_send_phy_packet()
1616 client_get(client); in ioctl_send_phy_packet()
1617 e->client = client; in ioctl_send_phy_packet()
1626 if (client->version < FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP) { in ioctl_send_phy_packet()
1652 static int ioctl_receive_phy_packets(struct client *client, union ioctl_arg *arg) in ioctl_receive_phy_packets() argument
1657 if (!client->device->is_local) in ioctl_receive_phy_packets()
1663 list_move_tail(&client->phy_receiver_link, &phy_receiver_list); in ioctl_receive_phy_packets()
1665 client->phy_receiver_closure = a->closure; in ioctl_receive_phy_packets()
1672 struct client *client; in fw_cdev_handle_phy_packet() local
1678 list_for_each_entry(client, &phy_receiver_list, phy_receiver_link) { in fw_cdev_handle_phy_packet()
1681 if (client->device->card != card) in fw_cdev_handle_phy_packet()
1688 if (client->version < FW_CDEV_VERSION_EVENT_ASYNC_TSTAMP) { in fw_cdev_handle_phy_packet()
1691 pp->closure = client->phy_receiver_closure; in fw_cdev_handle_phy_packet()
1697 queue_event(client, &e->event, &e->phy_packet, sizeof(*pp) + 8, NULL, 0); in fw_cdev_handle_phy_packet()
1702 pp->closure = client->phy_receiver_closure; in fw_cdev_handle_phy_packet()
1709 queue_event(client, &e->event, &e->phy_packet, sizeof(*pp) + 8, NULL, 0); in fw_cdev_handle_phy_packet()
1714 static int (* const ioctl_handlers[])(struct client *, union ioctl_arg *) = {
1742 static int dispatch_ioctl(struct client *client, in dispatch_ioctl() argument
1748 if (fw_device_is_shutdown(client->device)) in dispatch_ioctl()
1762 ret = ioctl_handlers[_IOC_NR(cmd)](client, &buffer); in dispatch_ioctl()
1781 struct client *client = file->private_data; in fw_device_op_mmap() local
1785 if (fw_device_is_shutdown(client->device)) in fw_device_op_mmap()
1789 if (client->buffer.pages != NULL) in fw_device_op_mmap()
1798 client->vm_start = vma->vm_start; in fw_device_op_mmap()
1804 ret = fw_iso_buffer_alloc(&client->buffer, page_count); in fw_device_op_mmap()
1808 scoped_guard(mutex, &client->iso_context_mutex) { in fw_device_op_mmap()
1811 if (client->iso_context) { in fw_device_op_mmap()
1812 ret = fw_iso_buffer_map_dma(&client->buffer, client->device->card, in fw_device_op_mmap()
1813 iso_dma_direction(client->iso_context)); in fw_device_op_mmap()
1819 ret = vm_map_pages_zero(vma, client->buffer.pages, in fw_device_op_mmap()
1820 client->buffer.page_count); in fw_device_op_mmap()
1826 fw_iso_buffer_destroy(&client->buffer, client->device->card); in fw_device_op_mmap()
1830 static bool has_outbound_transactions(struct client *client) in has_outbound_transactions() argument
1835 guard(spinlock_irq)(&client->lock); in has_outbound_transactions()
1837 xa_for_each(&client->resource_xa, index, resource) { in has_outbound_transactions()
1847 struct client *client = file->private_data; in fw_device_op_release() local
1855 list_del(&client->phy_receiver_link); in fw_device_op_release()
1857 scoped_guard(mutex, &client->device->client_list_mutex) in fw_device_op_release()
1858 list_del(&client->link); in fw_device_op_release()
1860 if (client->iso_context) in fw_device_op_release()
1861 fw_iso_context_destroy(client->iso_context); in fw_device_op_release()
1862 mutex_destroy(&client->iso_context_mutex); in fw_device_op_release()
1864 if (client->buffer.pages) in fw_device_op_release()
1865 fw_iso_buffer_destroy(&client->buffer, client->device->card); in fw_device_op_release()
1868 scoped_guard(spinlock_irq, &client->lock) in fw_device_op_release()
1869 client->in_shutdown = true; in fw_device_op_release()
1871 wait_event(client->tx_flush_wait, !has_outbound_transactions(client)); in fw_device_op_release()
1873 xa_for_each(&client->resource_xa, index, resource) { in fw_device_op_release()
1874 resource->release(client, resource); in fw_device_op_release()
1875 client_put(client); in fw_device_op_release()
1877 xa_destroy(&client->resource_xa); in fw_device_op_release()
1879 list_for_each_entry_safe(event, next_event, &client->event_list, link) in fw_device_op_release()
1882 client_put(client); in fw_device_op_release()
1889 struct client *client = file->private_data; in fw_device_op_poll() local
1892 poll_wait(file, &client->wait, pt); in fw_device_op_poll()
1894 if (fw_device_is_shutdown(client->device)) in fw_device_op_poll()
1896 if (!list_empty(&client->event_list)) in fw_device_op_poll()