Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Greybus connections
0004  *
0005  * Copyright 2014 Google Inc.
0006  * Copyright 2014 Linaro Ltd.
0007  */
0008 
0009 #ifndef __CONNECTION_H
0010 #define __CONNECTION_H
0011 
0012 #include <linux/bits.h>
0013 #include <linux/list.h>
0014 #include <linux/kfifo.h>
0015 #include <linux/kref.h>
0016 #include <linux/workqueue.h>
0017 
0018 #define GB_CONNECTION_FLAG_CSD      BIT(0)
0019 #define GB_CONNECTION_FLAG_NO_FLOWCTRL  BIT(1)
0020 #define GB_CONNECTION_FLAG_OFFLOADED    BIT(2)
0021 #define GB_CONNECTION_FLAG_CDSI1    BIT(3)
0022 #define GB_CONNECTION_FLAG_CONTROL  BIT(4)
0023 #define GB_CONNECTION_FLAG_HIGH_PRIO    BIT(5)
0024 
0025 #define GB_CONNECTION_FLAG_CORE_MASK    GB_CONNECTION_FLAG_CONTROL
0026 
0027 enum gb_connection_state {
0028     GB_CONNECTION_STATE_DISABLED        = 0,
0029     GB_CONNECTION_STATE_ENABLED_TX      = 1,
0030     GB_CONNECTION_STATE_ENABLED     = 2,
0031     GB_CONNECTION_STATE_DISCONNECTING   = 3,
0032 };
0033 
0034 struct gb_operation;
0035 
0036 typedef int (*gb_request_handler_t)(struct gb_operation *);
0037 
0038 struct gb_connection {
0039     struct gb_host_device       *hd;
0040     struct gb_interface     *intf;
0041     struct gb_bundle        *bundle;
0042     struct kref         kref;
0043     u16             hd_cport_id;
0044     u16             intf_cport_id;
0045 
0046     struct list_head        hd_links;
0047     struct list_head        bundle_links;
0048 
0049     gb_request_handler_t        handler;
0050     unsigned long           flags;
0051 
0052     struct mutex            mutex;
0053     spinlock_t          lock;
0054     enum gb_connection_state    state;
0055     struct list_head        operations;
0056 
0057     char                name[16];
0058     struct workqueue_struct     *wq;
0059 
0060     atomic_t            op_cycle;
0061 
0062     void                *private;
0063 
0064     bool                mode_switch;
0065 };
0066 
0067 struct gb_connection *gb_connection_create_static(struct gb_host_device *hd,
0068                 u16 hd_cport_id, gb_request_handler_t handler);
0069 struct gb_connection *gb_connection_create_control(struct gb_interface *intf);
0070 struct gb_connection *gb_connection_create(struct gb_bundle *bundle,
0071                 u16 cport_id, gb_request_handler_t handler);
0072 struct gb_connection *gb_connection_create_flags(struct gb_bundle *bundle,
0073                 u16 cport_id, gb_request_handler_t handler,
0074                 unsigned long flags);
0075 struct gb_connection *gb_connection_create_offloaded(struct gb_bundle *bundle,
0076                 u16 cport_id, unsigned long flags);
0077 void gb_connection_destroy(struct gb_connection *connection);
0078 
0079 static inline bool gb_connection_is_static(struct gb_connection *connection)
0080 {
0081     return !connection->intf;
0082 }
0083 
0084 int gb_connection_enable(struct gb_connection *connection);
0085 int gb_connection_enable_tx(struct gb_connection *connection);
0086 void gb_connection_disable_rx(struct gb_connection *connection);
0087 void gb_connection_disable(struct gb_connection *connection);
0088 void gb_connection_disable_forced(struct gb_connection *connection);
0089 
0090 void gb_connection_mode_switch_prepare(struct gb_connection *connection);
0091 void gb_connection_mode_switch_complete(struct gb_connection *connection);
0092 
0093 void greybus_data_rcvd(struct gb_host_device *hd, u16 cport_id,
0094                u8 *data, size_t length);
0095 
0096 void gb_connection_latency_tag_enable(struct gb_connection *connection);
0097 void gb_connection_latency_tag_disable(struct gb_connection *connection);
0098 
0099 static inline bool gb_connection_e2efc_enabled(struct gb_connection *connection)
0100 {
0101     return !(connection->flags & GB_CONNECTION_FLAG_CSD);
0102 }
0103 
0104 static inline bool
0105 gb_connection_flow_control_disabled(struct gb_connection *connection)
0106 {
0107     return connection->flags & GB_CONNECTION_FLAG_NO_FLOWCTRL;
0108 }
0109 
0110 static inline bool gb_connection_is_offloaded(struct gb_connection *connection)
0111 {
0112     return connection->flags & GB_CONNECTION_FLAG_OFFLOADED;
0113 }
0114 
0115 static inline bool gb_connection_is_control(struct gb_connection *connection)
0116 {
0117     return connection->flags & GB_CONNECTION_FLAG_CONTROL;
0118 }
0119 
0120 static inline void *gb_connection_get_data(struct gb_connection *connection)
0121 {
0122     return connection->private;
0123 }
0124 
0125 static inline void gb_connection_set_data(struct gb_connection *connection,
0126                       void *data)
0127 {
0128     connection->private = data;
0129 }
0130 
0131 #endif /* __CONNECTION_H */