Lines Matching refs:connection
25 struct gb_connection *connection; in gb_connection_cport_in_use() local
27 list_for_each_entry(connection, &hd->connections, hd_links) { in gb_connection_cport_in_use()
28 if (connection->intf == intf && in gb_connection_cport_in_use()
29 connection->intf_cport_id == cport_id) in gb_connection_cport_in_use()
36 static void gb_connection_get(struct gb_connection *connection) in gb_connection_get() argument
38 kref_get(&connection->kref); in gb_connection_get()
40 trace_gb_connection_get(connection); in gb_connection_get()
43 static void gb_connection_put(struct gb_connection *connection) in gb_connection_put() argument
45 trace_gb_connection_put(connection); in gb_connection_put()
47 kref_put(&connection->kref, gb_connection_kref_release); in gb_connection_put()
56 struct gb_connection *connection; in gb_connection_hd_find() local
60 list_for_each_entry(connection, &hd->connections, hd_links) in gb_connection_hd_find()
61 if (connection->hd_cport_id == cport_id) { in gb_connection_hd_find()
62 gb_connection_get(connection); in gb_connection_hd_find()
65 connection = NULL; in gb_connection_hd_find()
69 return connection; in gb_connection_hd_find()
79 struct gb_connection *connection; in greybus_data_rcvd() local
83 connection = gb_connection_hd_find(hd, cport_id); in greybus_data_rcvd()
84 if (!connection) { in greybus_data_rcvd()
89 gb_connection_recv(connection, data, length); in greybus_data_rcvd()
90 gb_connection_put(connection); in greybus_data_rcvd()
96 struct gb_connection *connection; in gb_connection_kref_release() local
98 connection = container_of(kref, struct gb_connection, kref); in gb_connection_kref_release()
100 trace_gb_connection_release(connection); in gb_connection_kref_release()
102 kfree(connection); in gb_connection_kref_release()
105 static void gb_connection_init_name(struct gb_connection *connection) in gb_connection_init_name() argument
107 u16 hd_cport_id = connection->hd_cport_id; in gb_connection_init_name()
111 if (connection->intf) { in gb_connection_init_name()
112 intf_id = connection->intf->interface_id; in gb_connection_init_name()
113 cport_id = connection->intf_cport_id; in gb_connection_init_name()
116 snprintf(connection->name, sizeof(connection->name), in gb_connection_init_name()
150 struct gb_connection *connection; in _gb_connection_create() local
168 connection = kzalloc(sizeof(*connection), GFP_KERNEL); in _gb_connection_create()
169 if (!connection) { in _gb_connection_create()
174 connection->hd_cport_id = hd_cport_id; in _gb_connection_create()
175 connection->intf_cport_id = cport_id; in _gb_connection_create()
176 connection->hd = hd; in _gb_connection_create()
177 connection->intf = intf; in _gb_connection_create()
178 connection->bundle = bundle; in _gb_connection_create()
179 connection->handler = handler; in _gb_connection_create()
180 connection->flags = flags; in _gb_connection_create()
182 connection->flags |= GB_CONNECTION_FLAG_NO_FLOWCTRL; in _gb_connection_create()
183 connection->state = GB_CONNECTION_STATE_DISABLED; in _gb_connection_create()
185 atomic_set(&connection->op_cycle, 0); in _gb_connection_create()
186 mutex_init(&connection->mutex); in _gb_connection_create()
187 spin_lock_init(&connection->lock); in _gb_connection_create()
188 INIT_LIST_HEAD(&connection->operations); in _gb_connection_create()
190 connection->wq = alloc_workqueue("%s:%d", WQ_UNBOUND, 1, in _gb_connection_create()
192 if (!connection->wq) { in _gb_connection_create()
197 kref_init(&connection->kref); in _gb_connection_create()
199 gb_connection_init_name(connection); in _gb_connection_create()
202 list_add(&connection->hd_links, &hd->connections); in _gb_connection_create()
205 list_add(&connection->bundle_links, &bundle->connections); in _gb_connection_create()
207 INIT_LIST_HEAD(&connection->bundle_links); in _gb_connection_create()
213 trace_gb_connection_create(connection); in _gb_connection_create()
215 return connection; in _gb_connection_create()
218 kfree(connection); in _gb_connection_create()
279 static int gb_connection_hd_cport_enable(struct gb_connection *connection) in gb_connection_hd_cport_enable() argument
281 struct gb_host_device *hd = connection->hd; in gb_connection_hd_cport_enable()
287 ret = hd->driver->cport_enable(hd, connection->hd_cport_id, in gb_connection_hd_cport_enable()
288 connection->flags); in gb_connection_hd_cport_enable()
291 connection->name, ret); in gb_connection_hd_cport_enable()
298 static void gb_connection_hd_cport_disable(struct gb_connection *connection) in gb_connection_hd_cport_disable() argument
300 struct gb_host_device *hd = connection->hd; in gb_connection_hd_cport_disable()
306 ret = hd->driver->cport_disable(hd, connection->hd_cport_id); in gb_connection_hd_cport_disable()
309 connection->name, ret); in gb_connection_hd_cport_disable()
313 static int gb_connection_hd_cport_connected(struct gb_connection *connection) in gb_connection_hd_cport_connected() argument
315 struct gb_host_device *hd = connection->hd; in gb_connection_hd_cport_connected()
321 ret = hd->driver->cport_connected(hd, connection->hd_cport_id); in gb_connection_hd_cport_connected()
324 connection->name, ret); in gb_connection_hd_cport_connected()
331 static int gb_connection_hd_cport_flush(struct gb_connection *connection) in gb_connection_hd_cport_flush() argument
333 struct gb_host_device *hd = connection->hd; in gb_connection_hd_cport_flush()
339 ret = hd->driver->cport_flush(hd, connection->hd_cport_id); in gb_connection_hd_cport_flush()
342 connection->name, ret); in gb_connection_hd_cport_flush()
349 static int gb_connection_hd_cport_quiesce(struct gb_connection *connection) in gb_connection_hd_cport_quiesce() argument
351 struct gb_host_device *hd = connection->hd; in gb_connection_hd_cport_quiesce()
361 if (connection->mode_switch) in gb_connection_hd_cport_quiesce()
367 ret = hd->driver->cport_quiesce(hd, connection->hd_cport_id, in gb_connection_hd_cport_quiesce()
372 connection->name, ret); in gb_connection_hd_cport_quiesce()
379 static int gb_connection_hd_cport_clear(struct gb_connection *connection) in gb_connection_hd_cport_clear() argument
381 struct gb_host_device *hd = connection->hd; in gb_connection_hd_cport_clear()
387 ret = hd->driver->cport_clear(hd, connection->hd_cport_id); in gb_connection_hd_cport_clear()
390 connection->name, ret); in gb_connection_hd_cport_clear()
402 gb_connection_svc_connection_create(struct gb_connection *connection) in gb_connection_svc_connection_create() argument
404 struct gb_host_device *hd = connection->hd; in gb_connection_svc_connection_create()
409 if (gb_connection_is_static(connection)) in gb_connection_svc_connection_create()
412 intf = connection->intf; in gb_connection_svc_connection_create()
418 if (gb_connection_flow_control_disabled(connection)) { in gb_connection_svc_connection_create()
420 } else if (gb_connection_e2efc_enabled(connection)) { in gb_connection_svc_connection_create()
427 connection->hd_cport_id, in gb_connection_svc_connection_create()
429 connection->intf_cport_id, in gb_connection_svc_connection_create()
432 dev_err(&connection->hd->dev, in gb_connection_svc_connection_create()
434 connection->name, ret); in gb_connection_svc_connection_create()
442 gb_connection_svc_connection_destroy(struct gb_connection *connection) in gb_connection_svc_connection_destroy() argument
444 if (gb_connection_is_static(connection)) in gb_connection_svc_connection_destroy()
447 gb_svc_connection_destroy(connection->hd->svc, in gb_connection_svc_connection_destroy()
448 connection->hd->svc->ap_intf_id, in gb_connection_svc_connection_destroy()
449 connection->hd_cport_id, in gb_connection_svc_connection_destroy()
450 connection->intf->interface_id, in gb_connection_svc_connection_destroy()
451 connection->intf_cport_id); in gb_connection_svc_connection_destroy()
455 static int gb_connection_control_connected(struct gb_connection *connection) in gb_connection_control_connected() argument
458 u16 cport_id = connection->intf_cport_id; in gb_connection_control_connected()
461 if (gb_connection_is_static(connection)) in gb_connection_control_connected()
464 if (gb_connection_is_control(connection)) in gb_connection_control_connected()
467 control = connection->intf->control; in gb_connection_control_connected()
471 dev_err(&connection->bundle->dev, in gb_connection_control_connected()
480 gb_connection_control_disconnecting(struct gb_connection *connection) in gb_connection_control_disconnecting() argument
483 u16 cport_id = connection->intf_cport_id; in gb_connection_control_disconnecting()
486 if (gb_connection_is_static(connection)) in gb_connection_control_disconnecting()
489 control = connection->intf->control; in gb_connection_control_disconnecting()
493 dev_err(&connection->hd->dev, in gb_connection_control_disconnecting()
495 connection->name, ret); in gb_connection_control_disconnecting()
500 gb_connection_control_disconnected(struct gb_connection *connection) in gb_connection_control_disconnected() argument
503 u16 cport_id = connection->intf_cport_id; in gb_connection_control_disconnected()
506 if (gb_connection_is_static(connection)) in gb_connection_control_disconnected()
509 control = connection->intf->control; in gb_connection_control_disconnected()
511 if (gb_connection_is_control(connection)) { in gb_connection_control_disconnected()
512 if (connection->mode_switch) { in gb_connection_control_disconnected()
528 dev_warn(&connection->bundle->dev, in gb_connection_control_disconnected()
533 static int gb_connection_shutdown_operation(struct gb_connection *connection, in gb_connection_shutdown_operation() argument
540 operation = gb_operation_create_core(connection, in gb_connection_shutdown_operation()
557 static int gb_connection_cport_shutdown(struct gb_connection *connection, in gb_connection_cport_shutdown() argument
560 struct gb_host_device *hd = connection->hd; in gb_connection_cport_shutdown()
564 if (gb_connection_is_static(connection)) in gb_connection_cport_shutdown()
567 if (gb_connection_is_offloaded(connection)) { in gb_connection_cport_shutdown()
571 ret = drv->cport_shutdown(hd, connection->hd_cport_id, phase, in gb_connection_cport_shutdown()
574 ret = gb_connection_shutdown_operation(connection, phase); in gb_connection_cport_shutdown()
579 connection->name, phase, ret); in gb_connection_cport_shutdown()
587 gb_connection_cport_shutdown_phase_1(struct gb_connection *connection) in gb_connection_cport_shutdown_phase_1() argument
589 return gb_connection_cport_shutdown(connection, 1); in gb_connection_cport_shutdown_phase_1()
593 gb_connection_cport_shutdown_phase_2(struct gb_connection *connection) in gb_connection_cport_shutdown_phase_2() argument
595 return gb_connection_cport_shutdown(connection, 2); in gb_connection_cport_shutdown_phase_2()
604 static void gb_connection_cancel_operations(struct gb_connection *connection, in gb_connection_cancel_operations() argument
606 __must_hold(&connection->lock) in gb_connection_cancel_operations()
610 while (!list_empty(&connection->operations)) { in gb_connection_cancel_operations()
611 operation = list_last_entry(&connection->operations, in gb_connection_cancel_operations()
614 spin_unlock_irq(&connection->lock); in gb_connection_cancel_operations()
623 spin_lock_irq(&connection->lock); in gb_connection_cancel_operations()
633 gb_connection_flush_incoming_operations(struct gb_connection *connection, in gb_connection_flush_incoming_operations() argument
635 __must_hold(&connection->lock) in gb_connection_flush_incoming_operations()
640 while (!list_empty(&connection->operations)) { in gb_connection_flush_incoming_operations()
642 list_for_each_entry(operation, &connection->operations, in gb_connection_flush_incoming_operations()
654 spin_unlock_irq(&connection->lock); in gb_connection_flush_incoming_operations()
660 spin_lock_irq(&connection->lock); in gb_connection_flush_incoming_operations()
674 static int _gb_connection_enable(struct gb_connection *connection, bool rx) in _gb_connection_enable() argument
679 if (connection->state == GB_CONNECTION_STATE_ENABLED_TX) { in _gb_connection_enable()
680 if (!(connection->handler && rx)) in _gb_connection_enable()
683 spin_lock_irq(&connection->lock); in _gb_connection_enable()
684 connection->state = GB_CONNECTION_STATE_ENABLED; in _gb_connection_enable()
685 spin_unlock_irq(&connection->lock); in _gb_connection_enable()
690 ret = gb_connection_hd_cport_enable(connection); in _gb_connection_enable()
694 ret = gb_connection_svc_connection_create(connection); in _gb_connection_enable()
698 ret = gb_connection_hd_cport_connected(connection); in _gb_connection_enable()
702 spin_lock_irq(&connection->lock); in _gb_connection_enable()
703 if (connection->handler && rx) in _gb_connection_enable()
704 connection->state = GB_CONNECTION_STATE_ENABLED; in _gb_connection_enable()
706 connection->state = GB_CONNECTION_STATE_ENABLED_TX; in _gb_connection_enable()
707 spin_unlock_irq(&connection->lock); in _gb_connection_enable()
709 ret = gb_connection_control_connected(connection); in _gb_connection_enable()
716 spin_lock_irq(&connection->lock); in _gb_connection_enable()
717 connection->state = GB_CONNECTION_STATE_DISCONNECTING; in _gb_connection_enable()
718 gb_connection_cancel_operations(connection, -ESHUTDOWN); in _gb_connection_enable()
719 spin_unlock_irq(&connection->lock); in _gb_connection_enable()
722 gb_connection_hd_cport_flush(connection); in _gb_connection_enable()
724 gb_connection_control_disconnecting(connection); in _gb_connection_enable()
725 gb_connection_cport_shutdown_phase_1(connection); in _gb_connection_enable()
726 gb_connection_hd_cport_quiesce(connection); in _gb_connection_enable()
727 gb_connection_cport_shutdown_phase_2(connection); in _gb_connection_enable()
728 gb_connection_control_disconnected(connection); in _gb_connection_enable()
729 connection->state = GB_CONNECTION_STATE_DISABLED; in _gb_connection_enable()
731 gb_connection_svc_connection_destroy(connection); in _gb_connection_enable()
733 gb_connection_hd_cport_clear(connection); in _gb_connection_enable()
735 gb_connection_hd_cport_disable(connection); in _gb_connection_enable()
740 int gb_connection_enable(struct gb_connection *connection) in gb_connection_enable() argument
744 mutex_lock(&connection->mutex); in gb_connection_enable()
746 if (connection->state == GB_CONNECTION_STATE_ENABLED) in gb_connection_enable()
749 ret = _gb_connection_enable(connection, true); in gb_connection_enable()
751 trace_gb_connection_enable(connection); in gb_connection_enable()
754 mutex_unlock(&connection->mutex); in gb_connection_enable()
760 int gb_connection_enable_tx(struct gb_connection *connection) in gb_connection_enable_tx() argument
764 mutex_lock(&connection->mutex); in gb_connection_enable_tx()
766 if (connection->state == GB_CONNECTION_STATE_ENABLED) { in gb_connection_enable_tx()
771 if (connection->state == GB_CONNECTION_STATE_ENABLED_TX) in gb_connection_enable_tx()
774 ret = _gb_connection_enable(connection, false); in gb_connection_enable_tx()
776 trace_gb_connection_enable(connection); in gb_connection_enable_tx()
779 mutex_unlock(&connection->mutex); in gb_connection_enable_tx()
785 void gb_connection_disable_rx(struct gb_connection *connection) in gb_connection_disable_rx() argument
787 mutex_lock(&connection->mutex); in gb_connection_disable_rx()
789 spin_lock_irq(&connection->lock); in gb_connection_disable_rx()
790 if (connection->state != GB_CONNECTION_STATE_ENABLED) { in gb_connection_disable_rx()
791 spin_unlock_irq(&connection->lock); in gb_connection_disable_rx()
794 connection->state = GB_CONNECTION_STATE_ENABLED_TX; in gb_connection_disable_rx()
795 gb_connection_flush_incoming_operations(connection, -ESHUTDOWN); in gb_connection_disable_rx()
796 spin_unlock_irq(&connection->lock); in gb_connection_disable_rx()
798 trace_gb_connection_disable(connection); in gb_connection_disable_rx()
801 mutex_unlock(&connection->mutex); in gb_connection_disable_rx()
805 void gb_connection_mode_switch_prepare(struct gb_connection *connection) in gb_connection_mode_switch_prepare() argument
807 connection->mode_switch = true; in gb_connection_mode_switch_prepare()
810 void gb_connection_mode_switch_complete(struct gb_connection *connection) in gb_connection_mode_switch_complete() argument
812 gb_connection_svc_connection_destroy(connection); in gb_connection_mode_switch_complete()
813 gb_connection_hd_cport_clear(connection); in gb_connection_mode_switch_complete()
815 gb_connection_hd_cport_disable(connection); in gb_connection_mode_switch_complete()
817 connection->mode_switch = false; in gb_connection_mode_switch_complete()
820 void gb_connection_disable(struct gb_connection *connection) in gb_connection_disable() argument
822 mutex_lock(&connection->mutex); in gb_connection_disable()
824 if (connection->state == GB_CONNECTION_STATE_DISABLED) in gb_connection_disable()
827 trace_gb_connection_disable(connection); in gb_connection_disable()
829 spin_lock_irq(&connection->lock); in gb_connection_disable()
830 connection->state = GB_CONNECTION_STATE_DISCONNECTING; in gb_connection_disable()
831 gb_connection_cancel_operations(connection, -ESHUTDOWN); in gb_connection_disable()
832 spin_unlock_irq(&connection->lock); in gb_connection_disable()
834 gb_connection_hd_cport_flush(connection); in gb_connection_disable()
836 gb_connection_control_disconnecting(connection); in gb_connection_disable()
837 gb_connection_cport_shutdown_phase_1(connection); in gb_connection_disable()
838 gb_connection_hd_cport_quiesce(connection); in gb_connection_disable()
839 gb_connection_cport_shutdown_phase_2(connection); in gb_connection_disable()
840 gb_connection_control_disconnected(connection); in gb_connection_disable()
842 connection->state = GB_CONNECTION_STATE_DISABLED; in gb_connection_disable()
845 if (!connection->mode_switch) { in gb_connection_disable()
846 gb_connection_svc_connection_destroy(connection); in gb_connection_disable()
847 gb_connection_hd_cport_clear(connection); in gb_connection_disable()
849 gb_connection_hd_cport_disable(connection); in gb_connection_disable()
853 mutex_unlock(&connection->mutex); in gb_connection_disable()
858 void gb_connection_disable_forced(struct gb_connection *connection) in gb_connection_disable_forced() argument
860 mutex_lock(&connection->mutex); in gb_connection_disable_forced()
862 if (connection->state == GB_CONNECTION_STATE_DISABLED) in gb_connection_disable_forced()
865 trace_gb_connection_disable(connection); in gb_connection_disable_forced()
867 spin_lock_irq(&connection->lock); in gb_connection_disable_forced()
868 connection->state = GB_CONNECTION_STATE_DISABLED; in gb_connection_disable_forced()
869 gb_connection_cancel_operations(connection, -ESHUTDOWN); in gb_connection_disable_forced()
870 spin_unlock_irq(&connection->lock); in gb_connection_disable_forced()
872 gb_connection_hd_cport_flush(connection); in gb_connection_disable_forced()
874 gb_connection_svc_connection_destroy(connection); in gb_connection_disable_forced()
875 gb_connection_hd_cport_clear(connection); in gb_connection_disable_forced()
877 gb_connection_hd_cport_disable(connection); in gb_connection_disable_forced()
879 mutex_unlock(&connection->mutex); in gb_connection_disable_forced()
884 void gb_connection_destroy(struct gb_connection *connection) in gb_connection_destroy() argument
886 if (!connection) in gb_connection_destroy()
889 if (WARN_ON(connection->state != GB_CONNECTION_STATE_DISABLED)) in gb_connection_destroy()
890 gb_connection_disable(connection); in gb_connection_destroy()
895 list_del(&connection->bundle_links); in gb_connection_destroy()
896 list_del(&connection->hd_links); in gb_connection_destroy()
899 destroy_workqueue(connection->wq); in gb_connection_destroy()
901 gb_hd_cport_release(connection->hd, connection->hd_cport_id); in gb_connection_destroy()
902 connection->hd_cport_id = CPORT_ID_BAD; in gb_connection_destroy()
906 gb_connection_put(connection); in gb_connection_destroy()
910 void gb_connection_latency_tag_enable(struct gb_connection *connection) in gb_connection_latency_tag_enable() argument
912 struct gb_host_device *hd = connection->hd; in gb_connection_latency_tag_enable()
918 ret = hd->driver->latency_tag_enable(hd, connection->hd_cport_id); in gb_connection_latency_tag_enable()
920 dev_err(&connection->hd->dev, in gb_connection_latency_tag_enable()
922 connection->name, ret); in gb_connection_latency_tag_enable()
927 void gb_connection_latency_tag_disable(struct gb_connection *connection) in gb_connection_latency_tag_disable() argument
929 struct gb_host_device *hd = connection->hd; in gb_connection_latency_tag_disable()
935 ret = hd->driver->latency_tag_disable(hd, connection->hd_cport_id); in gb_connection_latency_tag_disable()
937 dev_err(&connection->hd->dev, in gb_connection_latency_tag_disable()
939 connection->name, ret); in gb_connection_latency_tag_disable()