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_ordered_workqueue("%s:%d", 0, dev_name(&hd->dev), 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()
364 ret = hd->driver->cport_quiesce(hd, connection->hd_cport_id, in gb_connection_hd_cport_quiesce()
369 connection->name, ret); in gb_connection_hd_cport_quiesce()
376 static int gb_connection_hd_cport_clear(struct gb_connection *connection) in gb_connection_hd_cport_clear() argument
378 struct gb_host_device *hd = connection->hd; in gb_connection_hd_cport_clear()
384 ret = hd->driver->cport_clear(hd, connection->hd_cport_id); in gb_connection_hd_cport_clear()
387 connection->name, ret); in gb_connection_hd_cport_clear()
399 gb_connection_svc_connection_create(struct gb_connection *connection) in gb_connection_svc_connection_create() argument
401 struct gb_host_device *hd = connection->hd; in gb_connection_svc_connection_create()
406 if (gb_connection_is_static(connection)) in gb_connection_svc_connection_create()
409 intf = connection->intf; in gb_connection_svc_connection_create()
415 if (gb_connection_flow_control_disabled(connection)) { in gb_connection_svc_connection_create()
417 } else if (gb_connection_e2efc_enabled(connection)) { in gb_connection_svc_connection_create()
424 connection->hd_cport_id, in gb_connection_svc_connection_create()
426 connection->intf_cport_id, in gb_connection_svc_connection_create()
429 dev_err(&connection->hd->dev, in gb_connection_svc_connection_create()
431 connection->name, ret); in gb_connection_svc_connection_create()
439 gb_connection_svc_connection_destroy(struct gb_connection *connection) in gb_connection_svc_connection_destroy() argument
441 if (gb_connection_is_static(connection)) in gb_connection_svc_connection_destroy()
444 gb_svc_connection_destroy(connection->hd->svc, in gb_connection_svc_connection_destroy()
445 connection->hd->svc->ap_intf_id, in gb_connection_svc_connection_destroy()
446 connection->hd_cport_id, in gb_connection_svc_connection_destroy()
447 connection->intf->interface_id, in gb_connection_svc_connection_destroy()
448 connection->intf_cport_id); in gb_connection_svc_connection_destroy()
452 static int gb_connection_control_connected(struct gb_connection *connection) in gb_connection_control_connected() argument
455 u16 cport_id = connection->intf_cport_id; in gb_connection_control_connected()
458 if (gb_connection_is_static(connection)) in gb_connection_control_connected()
461 if (gb_connection_is_control(connection)) in gb_connection_control_connected()
464 control = connection->intf->control; in gb_connection_control_connected()
468 dev_err(&connection->bundle->dev, in gb_connection_control_connected()
477 gb_connection_control_disconnecting(struct gb_connection *connection) in gb_connection_control_disconnecting() argument
480 u16 cport_id = connection->intf_cport_id; in gb_connection_control_disconnecting()
483 if (gb_connection_is_static(connection)) in gb_connection_control_disconnecting()
486 control = connection->intf->control; in gb_connection_control_disconnecting()
490 dev_err(&connection->hd->dev, in gb_connection_control_disconnecting()
492 connection->name, ret); in gb_connection_control_disconnecting()
497 gb_connection_control_disconnected(struct gb_connection *connection) in gb_connection_control_disconnected() argument
500 u16 cport_id = connection->intf_cport_id; in gb_connection_control_disconnected()
503 if (gb_connection_is_static(connection)) in gb_connection_control_disconnected()
506 control = connection->intf->control; in gb_connection_control_disconnected()
508 if (gb_connection_is_control(connection)) { in gb_connection_control_disconnected()
509 if (connection->mode_switch) { in gb_connection_control_disconnected()
525 dev_warn(&connection->bundle->dev, in gb_connection_control_disconnected()
530 static int gb_connection_shutdown_operation(struct gb_connection *connection, in gb_connection_shutdown_operation() argument
537 operation = gb_operation_create_core(connection, in gb_connection_shutdown_operation()
554 static int gb_connection_cport_shutdown(struct gb_connection *connection, in gb_connection_cport_shutdown() argument
557 struct gb_host_device *hd = connection->hd; in gb_connection_cport_shutdown()
561 if (gb_connection_is_static(connection)) in gb_connection_cport_shutdown()
564 if (gb_connection_is_offloaded(connection)) { in gb_connection_cport_shutdown()
568 ret = drv->cport_shutdown(hd, connection->hd_cport_id, phase, in gb_connection_cport_shutdown()
571 ret = gb_connection_shutdown_operation(connection, phase); in gb_connection_cport_shutdown()
576 connection->name, phase, ret); in gb_connection_cport_shutdown()
584 gb_connection_cport_shutdown_phase_1(struct gb_connection *connection) in gb_connection_cport_shutdown_phase_1() argument
586 return gb_connection_cport_shutdown(connection, 1); in gb_connection_cport_shutdown_phase_1()
590 gb_connection_cport_shutdown_phase_2(struct gb_connection *connection) in gb_connection_cport_shutdown_phase_2() argument
592 return gb_connection_cport_shutdown(connection, 2); in gb_connection_cport_shutdown_phase_2()
601 static void gb_connection_cancel_operations(struct gb_connection *connection, in gb_connection_cancel_operations() argument
603 __must_hold(&connection->lock) in gb_connection_cancel_operations()
607 while (!list_empty(&connection->operations)) { in gb_connection_cancel_operations()
608 operation = list_last_entry(&connection->operations, in gb_connection_cancel_operations()
611 spin_unlock_irq(&connection->lock); in gb_connection_cancel_operations()
620 spin_lock_irq(&connection->lock); in gb_connection_cancel_operations()
630 gb_connection_flush_incoming_operations(struct gb_connection *connection, in gb_connection_flush_incoming_operations() argument
632 __must_hold(&connection->lock) in gb_connection_flush_incoming_operations()
637 while (!list_empty(&connection->operations)) { in gb_connection_flush_incoming_operations()
639 list_for_each_entry(operation, &connection->operations, in gb_connection_flush_incoming_operations()
651 spin_unlock_irq(&connection->lock); in gb_connection_flush_incoming_operations()
657 spin_lock_irq(&connection->lock); in gb_connection_flush_incoming_operations()
671 static int _gb_connection_enable(struct gb_connection *connection, bool rx) in _gb_connection_enable() argument
676 if (connection->state == GB_CONNECTION_STATE_ENABLED_TX) { in _gb_connection_enable()
677 if (!(connection->handler && rx)) in _gb_connection_enable()
680 spin_lock_irq(&connection->lock); in _gb_connection_enable()
681 connection->state = GB_CONNECTION_STATE_ENABLED; in _gb_connection_enable()
682 spin_unlock_irq(&connection->lock); in _gb_connection_enable()
687 ret = gb_connection_hd_cport_enable(connection); in _gb_connection_enable()
691 ret = gb_connection_svc_connection_create(connection); in _gb_connection_enable()
695 ret = gb_connection_hd_cport_connected(connection); in _gb_connection_enable()
699 spin_lock_irq(&connection->lock); in _gb_connection_enable()
700 if (connection->handler && rx) in _gb_connection_enable()
701 connection->state = GB_CONNECTION_STATE_ENABLED; in _gb_connection_enable()
703 connection->state = GB_CONNECTION_STATE_ENABLED_TX; in _gb_connection_enable()
704 spin_unlock_irq(&connection->lock); in _gb_connection_enable()
706 ret = gb_connection_control_connected(connection); in _gb_connection_enable()
713 spin_lock_irq(&connection->lock); in _gb_connection_enable()
714 connection->state = GB_CONNECTION_STATE_DISCONNECTING; in _gb_connection_enable()
715 gb_connection_cancel_operations(connection, -ESHUTDOWN); in _gb_connection_enable()
716 spin_unlock_irq(&connection->lock); in _gb_connection_enable()
719 gb_connection_hd_cport_flush(connection); in _gb_connection_enable()
721 gb_connection_control_disconnecting(connection); in _gb_connection_enable()
722 gb_connection_cport_shutdown_phase_1(connection); in _gb_connection_enable()
723 gb_connection_hd_cport_quiesce(connection); in _gb_connection_enable()
724 gb_connection_cport_shutdown_phase_2(connection); in _gb_connection_enable()
725 gb_connection_control_disconnected(connection); in _gb_connection_enable()
726 connection->state = GB_CONNECTION_STATE_DISABLED; in _gb_connection_enable()
728 gb_connection_svc_connection_destroy(connection); in _gb_connection_enable()
730 gb_connection_hd_cport_clear(connection); in _gb_connection_enable()
732 gb_connection_hd_cport_disable(connection); in _gb_connection_enable()
737 int gb_connection_enable(struct gb_connection *connection) in gb_connection_enable() argument
741 mutex_lock(&connection->mutex); in gb_connection_enable()
743 if (connection->state == GB_CONNECTION_STATE_ENABLED) in gb_connection_enable()
746 ret = _gb_connection_enable(connection, true); in gb_connection_enable()
748 trace_gb_connection_enable(connection); in gb_connection_enable()
751 mutex_unlock(&connection->mutex); in gb_connection_enable()
757 int gb_connection_enable_tx(struct gb_connection *connection) in gb_connection_enable_tx() argument
761 mutex_lock(&connection->mutex); in gb_connection_enable_tx()
763 if (connection->state == GB_CONNECTION_STATE_ENABLED) { in gb_connection_enable_tx()
768 if (connection->state == GB_CONNECTION_STATE_ENABLED_TX) in gb_connection_enable_tx()
771 ret = _gb_connection_enable(connection, false); in gb_connection_enable_tx()
773 trace_gb_connection_enable(connection); in gb_connection_enable_tx()
776 mutex_unlock(&connection->mutex); in gb_connection_enable_tx()
782 void gb_connection_disable_rx(struct gb_connection *connection) in gb_connection_disable_rx() argument
784 mutex_lock(&connection->mutex); in gb_connection_disable_rx()
786 spin_lock_irq(&connection->lock); in gb_connection_disable_rx()
787 if (connection->state != GB_CONNECTION_STATE_ENABLED) { in gb_connection_disable_rx()
788 spin_unlock_irq(&connection->lock); in gb_connection_disable_rx()
791 connection->state = GB_CONNECTION_STATE_ENABLED_TX; in gb_connection_disable_rx()
792 gb_connection_flush_incoming_operations(connection, -ESHUTDOWN); in gb_connection_disable_rx()
793 spin_unlock_irq(&connection->lock); in gb_connection_disable_rx()
795 trace_gb_connection_disable(connection); in gb_connection_disable_rx()
798 mutex_unlock(&connection->mutex); in gb_connection_disable_rx()
802 void gb_connection_mode_switch_prepare(struct gb_connection *connection) in gb_connection_mode_switch_prepare() argument
804 connection->mode_switch = true; in gb_connection_mode_switch_prepare()
807 void gb_connection_mode_switch_complete(struct gb_connection *connection) in gb_connection_mode_switch_complete() argument
809 gb_connection_svc_connection_destroy(connection); in gb_connection_mode_switch_complete()
810 gb_connection_hd_cport_clear(connection); in gb_connection_mode_switch_complete()
812 gb_connection_hd_cport_disable(connection); in gb_connection_mode_switch_complete()
814 connection->mode_switch = false; in gb_connection_mode_switch_complete()
817 void gb_connection_disable(struct gb_connection *connection) in gb_connection_disable() argument
819 mutex_lock(&connection->mutex); in gb_connection_disable()
821 if (connection->state == GB_CONNECTION_STATE_DISABLED) in gb_connection_disable()
824 trace_gb_connection_disable(connection); in gb_connection_disable()
826 spin_lock_irq(&connection->lock); in gb_connection_disable()
827 connection->state = GB_CONNECTION_STATE_DISCONNECTING; in gb_connection_disable()
828 gb_connection_cancel_operations(connection, -ESHUTDOWN); in gb_connection_disable()
829 spin_unlock_irq(&connection->lock); in gb_connection_disable()
831 gb_connection_hd_cport_flush(connection); in gb_connection_disable()
833 gb_connection_control_disconnecting(connection); in gb_connection_disable()
834 gb_connection_cport_shutdown_phase_1(connection); in gb_connection_disable()
835 gb_connection_hd_cport_quiesce(connection); in gb_connection_disable()
836 gb_connection_cport_shutdown_phase_2(connection); in gb_connection_disable()
837 gb_connection_control_disconnected(connection); in gb_connection_disable()
839 connection->state = GB_CONNECTION_STATE_DISABLED; in gb_connection_disable()
842 if (!connection->mode_switch) { in gb_connection_disable()
843 gb_connection_svc_connection_destroy(connection); in gb_connection_disable()
844 gb_connection_hd_cport_clear(connection); in gb_connection_disable()
846 gb_connection_hd_cport_disable(connection); in gb_connection_disable()
850 mutex_unlock(&connection->mutex); in gb_connection_disable()
855 void gb_connection_disable_forced(struct gb_connection *connection) in gb_connection_disable_forced() argument
857 mutex_lock(&connection->mutex); in gb_connection_disable_forced()
859 if (connection->state == GB_CONNECTION_STATE_DISABLED) in gb_connection_disable_forced()
862 trace_gb_connection_disable(connection); in gb_connection_disable_forced()
864 spin_lock_irq(&connection->lock); in gb_connection_disable_forced()
865 connection->state = GB_CONNECTION_STATE_DISABLED; in gb_connection_disable_forced()
866 gb_connection_cancel_operations(connection, -ESHUTDOWN); in gb_connection_disable_forced()
867 spin_unlock_irq(&connection->lock); in gb_connection_disable_forced()
869 gb_connection_hd_cport_flush(connection); in gb_connection_disable_forced()
871 gb_connection_svc_connection_destroy(connection); in gb_connection_disable_forced()
872 gb_connection_hd_cport_clear(connection); in gb_connection_disable_forced()
874 gb_connection_hd_cport_disable(connection); in gb_connection_disable_forced()
876 mutex_unlock(&connection->mutex); in gb_connection_disable_forced()
881 void gb_connection_destroy(struct gb_connection *connection) in gb_connection_destroy() argument
883 if (!connection) in gb_connection_destroy()
886 if (WARN_ON(connection->state != GB_CONNECTION_STATE_DISABLED)) in gb_connection_destroy()
887 gb_connection_disable(connection); in gb_connection_destroy()
892 list_del(&connection->bundle_links); in gb_connection_destroy()
893 list_del(&connection->hd_links); in gb_connection_destroy()
896 destroy_workqueue(connection->wq); in gb_connection_destroy()
898 gb_hd_cport_release(connection->hd, connection->hd_cport_id); in gb_connection_destroy()
899 connection->hd_cport_id = CPORT_ID_BAD; in gb_connection_destroy()
903 gb_connection_put(connection); in gb_connection_destroy()
907 void gb_connection_latency_tag_enable(struct gb_connection *connection) in gb_connection_latency_tag_enable() argument
909 struct gb_host_device *hd = connection->hd; in gb_connection_latency_tag_enable()
915 ret = hd->driver->latency_tag_enable(hd, connection->hd_cport_id); in gb_connection_latency_tag_enable()
917 dev_err(&connection->hd->dev, in gb_connection_latency_tag_enable()
919 connection->name, ret); in gb_connection_latency_tag_enable()
924 void gb_connection_latency_tag_disable(struct gb_connection *connection) in gb_connection_latency_tag_disable() argument
926 struct gb_host_device *hd = connection->hd; in gb_connection_latency_tag_disable()
932 ret = hd->driver->latency_tag_disable(hd, connection->hd_cport_id); in gb_connection_latency_tag_disable()
934 dev_err(&connection->hd->dev, in gb_connection_latency_tag_disable()
936 connection->name, ret); in gb_connection_latency_tag_disable()