Lines Matching defs:connection

25 	struct gb_connection *connection;
27 list_for_each_entry(connection, &hd->connections, hd_links) {
28 if (connection->intf == intf &&
29 connection->intf_cport_id == cport_id)
36 static void gb_connection_get(struct gb_connection *connection)
38 kref_get(&connection->kref);
40 trace_gb_connection_get(connection);
43 static void gb_connection_put(struct gb_connection *connection)
45 trace_gb_connection_put(connection);
47 kref_put(&connection->kref, gb_connection_kref_release);
51 * Returns a reference-counted pointer to the connection if found.
56 struct gb_connection *connection;
60 list_for_each_entry(connection, &hd->connections, hd_links)
61 if (connection->hd_cport_id == cport_id) {
62 gb_connection_get(connection);
65 connection = NULL;
69 return connection;
79 struct gb_connection *connection;
83 connection = gb_connection_hd_find(hd, cport_id);
84 if (!connection) {
86 "nonexistent connection (%zu bytes dropped)\n", length);
89 gb_connection_recv(connection, data, length);
90 gb_connection_put(connection);
96 struct gb_connection *connection;
98 connection = container_of(kref, struct gb_connection, kref);
100 trace_gb_connection_release(connection);
102 kfree(connection);
105 static void gb_connection_init_name(struct gb_connection *connection)
107 u16 hd_cport_id = connection->hd_cport_id;
111 if (connection->intf) {
112 intf_id = connection->intf->interface_id;
113 cport_id = connection->intf_cport_id;
116 snprintf(connection->name, sizeof(connection->name),
121 * _gb_connection_create() - create a Greybus connection
122 * @hd: host device of the connection
128 * @flags: connection flags
130 * Create a Greybus connection, representing the bidirectional link
134 * A connection also maintains the state of operations sent over the
135 * connection.
140 * Return: A pointer to the new connection if successful, or an ERR_PTR
150 struct gb_connection *connection;
168 connection = kzalloc(sizeof(*connection), GFP_KERNEL);
169 if (!connection) {
174 connection->hd_cport_id = hd_cport_id;
175 connection->intf_cport_id = cport_id;
176 connection->hd = hd;
177 connection->intf = intf;
178 connection->bundle = bundle;
179 connection->handler = handler;
180 connection->flags = flags;
182 connection->flags |= GB_CONNECTION_FLAG_NO_FLOWCTRL;
183 connection->state = GB_CONNECTION_STATE_DISABLED;
185 atomic_set(&connection->op_cycle, 0);
186 mutex_init(&connection->mutex);
187 spin_lock_init(&connection->lock);
188 INIT_LIST_HEAD(&connection->operations);
190 connection->wq = alloc_ordered_workqueue("%s:%d", 0, dev_name(&hd->dev),
192 if (!connection->wq) {
197 kref_init(&connection->kref);
199 gb_connection_init_name(connection);
202 list_add(&connection->hd_links, &hd->connections);
205 list_add(&connection->bundle_links, &bundle->connections);
207 INIT_LIST_HEAD(&connection->bundle_links);
213 trace_gb_connection_create(connection);
215 return connection;
218 kfree(connection);
279 static int gb_connection_hd_cport_enable(struct gb_connection *connection)
281 struct gb_host_device *hd = connection->hd;
287 ret = hd->driver->cport_enable(hd, connection->hd_cport_id,
288 connection->flags);
291 connection->name, ret);
298 static void gb_connection_hd_cport_disable(struct gb_connection *connection)
300 struct gb_host_device *hd = connection->hd;
306 ret = hd->driver->cport_disable(hd, connection->hd_cport_id);
309 connection->name, ret);
313 static int gb_connection_hd_cport_connected(struct gb_connection *connection)
315 struct gb_host_device *hd = connection->hd;
321 ret = hd->driver->cport_connected(hd, connection->hd_cport_id);
324 connection->name, ret);
331 static int gb_connection_hd_cport_flush(struct gb_connection *connection)
333 struct gb_host_device *hd = connection->hd;
339 ret = hd->driver->cport_flush(hd, connection->hd_cport_id);
342 connection->name, ret);
349 static int gb_connection_hd_cport_quiesce(struct gb_connection *connection)
351 struct gb_host_device *hd = connection->hd;
361 if (connection->mode_switch)
364 ret = hd->driver->cport_quiesce(hd, connection->hd_cport_id,
369 connection->name, ret);
376 static int gb_connection_hd_cport_clear(struct gb_connection *connection)
378 struct gb_host_device *hd = connection->hd;
384 ret = hd->driver->cport_clear(hd, connection->hd_cport_id);
387 connection->name, ret);
395 * Request the SVC to create a connection from AP's cport to interface's
399 gb_connection_svc_connection_create(struct gb_connection *connection)
401 struct gb_host_device *hd = connection->hd;
406 if (gb_connection_is_static(connection))
409 intf = connection->intf;
415 if (gb_connection_flow_control_disabled(connection)) {
417 } else if (gb_connection_e2efc_enabled(connection)) {
424 connection->hd_cport_id,
426 connection->intf_cport_id,
429 dev_err(&connection->hd->dev,
430 "%s: failed to create svc connection: %d\n",
431 connection->name, ret);
439 gb_connection_svc_connection_destroy(struct gb_connection *connection)
441 if (gb_connection_is_static(connection))
444 gb_svc_connection_destroy(connection->hd->svc,
445 connection->hd->svc->ap_intf_id,
446 connection->hd_cport_id,
447 connection->intf->interface_id,
448 connection->intf_cport_id);
452 static int gb_connection_control_connected(struct gb_connection *connection)
455 u16 cport_id = connection->intf_cport_id;
458 if (gb_connection_is_static(connection))
461 if (gb_connection_is_control(connection))
464 control = connection->intf->control;
468 dev_err(&connection->bundle->dev,
477 gb_connection_control_disconnecting(struct gb_connection *connection)
480 u16 cport_id = connection->intf_cport_id;
483 if (gb_connection_is_static(connection))
486 control = connection->intf->control;
490 dev_err(&connection->hd->dev,
492 connection->name, ret);
497 gb_connection_control_disconnected(struct gb_connection *connection)
500 u16 cport_id = connection->intf_cport_id;
503 if (gb_connection_is_static(connection))
506 control = connection->intf->control;
508 if (gb_connection_is_control(connection)) {
509 if (connection->mode_switch) {
525 dev_warn(&connection->bundle->dev,
530 static int gb_connection_shutdown_operation(struct gb_connection *connection,
537 operation = gb_operation_create_core(connection,
554 static int gb_connection_cport_shutdown(struct gb_connection *connection,
557 struct gb_host_device *hd = connection->hd;
561 if (gb_connection_is_static(connection))
564 if (gb_connection_is_offloaded(connection)) {
568 ret = drv->cport_shutdown(hd, connection->hd_cport_id, phase,
571 ret = gb_connection_shutdown_operation(connection, phase);
576 connection->name, phase, ret);
584 gb_connection_cport_shutdown_phase_1(struct gb_connection *connection)
586 return gb_connection_cport_shutdown(connection, 1);
590 gb_connection_cport_shutdown_phase_2(struct gb_connection *connection)
592 return gb_connection_cport_shutdown(connection, 2);
596 * Cancel all active operations on a connection.
598 * Locking: Called with connection lock held and state set to DISABLED or
601 static void gb_connection_cancel_operations(struct gb_connection *connection,
603 __must_hold(&connection->lock)
607 while (!list_empty(&connection->operations)) {
608 operation = list_last_entry(&connection->operations,
611 spin_unlock_irq(&connection->lock);
620 spin_lock_irq(&connection->lock);
625 * Cancel all active incoming operations on a connection.
627 * Locking: Called with connection lock held and state set to ENABLED_TX.
630 gb_connection_flush_incoming_operations(struct gb_connection *connection,
632 __must_hold(&connection->lock)
637 while (!list_empty(&connection->operations)) {
639 list_for_each_entry(operation, &connection->operations,
651 spin_unlock_irq(&connection->lock);
657 spin_lock_irq(&connection->lock);
662 * _gb_connection_enable() - enable a connection
663 * @connection: connection to enable
669 * Locking: Caller holds connection->mutex.
671 static int _gb_connection_enable(struct gb_connection *connection, bool rx)
676 if (connection->state == GB_CONNECTION_STATE_ENABLED_TX) {
677 if (!(connection->handler && rx))
680 spin_lock_irq(&connection->lock);
681 connection->state = GB_CONNECTION_STATE_ENABLED;
682 spin_unlock_irq(&connection->lock);
687 ret = gb_connection_hd_cport_enable(connection);
691 ret = gb_connection_svc_connection_create(connection);
695 ret = gb_connection_hd_cport_connected(connection);
699 spin_lock_irq(&connection->lock);
700 if (connection->handler && rx)
701 connection->state = GB_CONNECTION_STATE_ENABLED;
703 connection->state = GB_CONNECTION_STATE_ENABLED_TX;
704 spin_unlock_irq(&connection->lock);
706 ret = gb_connection_control_connected(connection);
713 spin_lock_irq(&connection->lock);
714 connection->state = GB_CONNECTION_STATE_DISCONNECTING;
715 gb_connection_cancel_operations(connection, -ESHUTDOWN);
716 spin_unlock_irq(&connection->lock);
719 gb_connection_hd_cport_flush(connection);
721 gb_connection_control_disconnecting(connection);
722 gb_connection_cport_shutdown_phase_1(connection);
723 gb_connection_hd_cport_quiesce(connection);
724 gb_connection_cport_shutdown_phase_2(connection);
725 gb_connection_control_disconnected(connection);
726 connection->state = GB_CONNECTION_STATE_DISABLED;
728 gb_connection_svc_connection_destroy(connection);
730 gb_connection_hd_cport_clear(connection);
732 gb_connection_hd_cport_disable(connection);
737 int gb_connection_enable(struct gb_connection *connection)
741 mutex_lock(&connection->mutex);
743 if (connection->state == GB_CONNECTION_STATE_ENABLED)
746 ret = _gb_connection_enable(connection, true);
748 trace_gb_connection_enable(connection);
751 mutex_unlock(&connection->mutex);
757 int gb_connection_enable_tx(struct gb_connection *connection)
761 mutex_lock(&connection->mutex);
763 if (connection->state == GB_CONNECTION_STATE_ENABLED) {
768 if (connection->state == GB_CONNECTION_STATE_ENABLED_TX)
771 ret = _gb_connection_enable(connection, false);
773 trace_gb_connection_enable(connection);
776 mutex_unlock(&connection->mutex);
782 void gb_connection_disable_rx(struct gb_connection *connection)
784 mutex_lock(&connection->mutex);
786 spin_lock_irq(&connection->lock);
787 if (connection->state != GB_CONNECTION_STATE_ENABLED) {
788 spin_unlock_irq(&connection->lock);
791 connection->state = GB_CONNECTION_STATE_ENABLED_TX;
792 gb_connection_flush_incoming_operations(connection, -ESHUTDOWN);
793 spin_unlock_irq(&connection->lock);
795 trace_gb_connection_disable(connection);
798 mutex_unlock(&connection->mutex);
802 void gb_connection_mode_switch_prepare(struct gb_connection *connection)
804 connection->mode_switch = true;
807 void gb_connection_mode_switch_complete(struct gb_connection *connection)
809 gb_connection_svc_connection_destroy(connection);
810 gb_connection_hd_cport_clear(connection);
812 gb_connection_hd_cport_disable(connection);
814 connection->mode_switch = false;
817 void gb_connection_disable(struct gb_connection *connection)
819 mutex_lock(&connection->mutex);
821 if (connection->state == GB_CONNECTION_STATE_DISABLED)
824 trace_gb_connection_disable(connection);
826 spin_lock_irq(&connection->lock);
827 connection->state = GB_CONNECTION_STATE_DISCONNECTING;
828 gb_connection_cancel_operations(connection, -ESHUTDOWN);
829 spin_unlock_irq(&connection->lock);
831 gb_connection_hd_cport_flush(connection);
833 gb_connection_control_disconnecting(connection);
834 gb_connection_cport_shutdown_phase_1(connection);
835 gb_connection_hd_cport_quiesce(connection);
836 gb_connection_cport_shutdown_phase_2(connection);
837 gb_connection_control_disconnected(connection);
839 connection->state = GB_CONNECTION_STATE_DISABLED;
841 /* control-connection tear down is deferred when mode switching */
842 if (!connection->mode_switch) {
843 gb_connection_svc_connection_destroy(connection);
844 gb_connection_hd_cport_clear(connection);
846 gb_connection_hd_cport_disable(connection);
850 mutex_unlock(&connection->mutex);
854 /* Disable a connection without communicating with the remote end. */
855 void gb_connection_disable_forced(struct gb_connection *connection)
857 mutex_lock(&connection->mutex);
859 if (connection->state == GB_CONNECTION_STATE_DISABLED)
862 trace_gb_connection_disable(connection);
864 spin_lock_irq(&connection->lock);
865 connection->state = GB_CONNECTION_STATE_DISABLED;
866 gb_connection_cancel_operations(connection, -ESHUTDOWN);
867 spin_unlock_irq(&connection->lock);
869 gb_connection_hd_cport_flush(connection);
871 gb_connection_svc_connection_destroy(connection);
872 gb_connection_hd_cport_clear(connection);
874 gb_connection_hd_cport_disable(connection);
876 mutex_unlock(&connection->mutex);
880 /* Caller must have disabled the connection before destroying it. */
881 void gb_connection_destroy(struct gb_connection *connection)
883 if (!connection)
886 if (WARN_ON(connection->state != GB_CONNECTION_STATE_DISABLED))
887 gb_connection_disable(connection);
892 list_del(&connection->bundle_links);
893 list_del(&connection->hd_links);
896 destroy_workqueue(connection->wq);
898 gb_hd_cport_release(connection->hd, connection->hd_cport_id);
899 connection->hd_cport_id = CPORT_ID_BAD;
903 gb_connection_put(connection);
907 void gb_connection_latency_tag_enable(struct gb_connection *connection)
909 struct gb_host_device *hd = connection->hd;
915 ret = hd->driver->latency_tag_enable(hd, connection->hd_cport_id);
917 dev_err(&connection->hd->dev,
919 connection->name, ret);
924 void gb_connection_latency_tag_disable(struct gb_connection *connection)
926 struct gb_host_device *hd = connection->hd;
932 ret = hd->driver->latency_tag_disable(hd, connection->hd_cport_id);
934 dev_err(&connection->hd->dev,
936 connection->name, ret);