1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * SSH request transport layer.
8 #ifndef _SURFACE_AGGREGATOR_SSH_REQUEST_LAYER_H
9 #define _SURFACE_AGGREGATOR_SSH_REQUEST_LAYER_H
11 #include <linux/atomic.h>
12 #include <linux/ktime.h>
13 #include <linux/list.h>
14 #include <linux/spinlock.h>
15 #include <linux/workqueue.h>
17 #include <linux/surface_aggregator/serial_hub.h>
18 #include <linux/surface_aggregator/controller.h>
20 #include "ssh_packet_layer.h"
23 * enum ssh_rtl_state_flags - State-flags for &struct ssh_rtl.
25 * @SSH_RTL_SF_SHUTDOWN_BIT:
26 * Indicates that the request transport layer has been shut down or is
27 * being shut down and should not accept any new requests.
29 enum ssh_rtl_state_flags {
30 SSH_RTL_SF_SHUTDOWN_BIT,
34 * struct ssh_rtl_ops - Callback operations for request transport layer.
35 * @handle_event: Function called when a SSH event has been received. The
36 * specified function takes the request layer, received command
37 * struct, and corresponding payload as arguments. If the event
38 * has no payload, the payload span is empty (not %NULL).
41 void (*handle_event)(struct ssh_rtl *rtl, const struct ssh_command *cmd,
42 const struct ssam_span *data);
46 * struct ssh_rtl - SSH request transport layer.
47 * @ptl: Underlying packet transport layer.
48 * @state: State(-flags) of the transport layer.
49 * @queue: Request submission queue.
50 * @queue.lock: Lock for modifying the request submission queue.
51 * @queue.head: List-head of the request submission queue.
52 * @pending: Set/list of pending requests.
53 * @pending.lock: Lock for modifying the request set.
54 * @pending.head: List-head of the pending set/list.
55 * @pending.count: Number of currently pending requests.
56 * @tx: Transmitter subsystem.
57 * @tx.work: Transmitter work item.
58 * @rtx_timeout: Retransmission timeout subsystem.
59 * @rtx_timeout.lock: Lock for modifying the retransmission timeout reaper.
60 * @rtx_timeout.timeout: Timeout interval for retransmission.
61 * @rtx_timeout.expires: Time specifying when the reaper work is next scheduled.
62 * @rtx_timeout.reaper: Work performing timeout checks and subsequent actions.
63 * @ops: Request layer operations.
71 struct list_head head;
76 struct list_head head;
81 struct work_struct work;
88 struct delayed_work reaper;
91 struct ssh_rtl_ops ops;
94 #define rtl_dbg(r, fmt, ...) ptl_dbg(&(r)->ptl, fmt, ##__VA_ARGS__)
95 #define rtl_info(p, fmt, ...) ptl_info(&(p)->ptl, fmt, ##__VA_ARGS__)
96 #define rtl_warn(r, fmt, ...) ptl_warn(&(r)->ptl, fmt, ##__VA_ARGS__)
97 #define rtl_err(r, fmt, ...) ptl_err(&(r)->ptl, fmt, ##__VA_ARGS__)
98 #define rtl_dbg_cond(r, fmt, ...) __ssam_prcond(rtl_dbg, r, fmt, ##__VA_ARGS__)
100 #define to_ssh_rtl(ptr, member) \
101 container_of(ptr, struct ssh_rtl, member)
104 * ssh_rtl_get_device() - Get device associated with request transport layer.
105 * @rtl: The request transport layer.
107 * Return: Returns the device on which the given request transport layer
110 static inline struct device *ssh_rtl_get_device(struct ssh_rtl *rtl)
112 return ssh_ptl_get_device(&rtl->ptl);
116 * ssh_request_rtl() - Get request transport layer associated with request.
117 * @rqst: The request to get the request transport layer reference for.
119 * Return: Returns the &struct ssh_rtl associated with the given SSH request.
121 static inline struct ssh_rtl *ssh_request_rtl(struct ssh_request *rqst)
125 ptl = READ_ONCE(rqst->packet.ptl);
126 return likely(ptl) ? to_ssh_rtl(ptl, ptl) : NULL;
129 int ssh_rtl_submit(struct ssh_rtl *rtl, struct ssh_request *rqst);
130 bool ssh_rtl_cancel(struct ssh_request *rqst, bool pending);
132 int ssh_rtl_init(struct ssh_rtl *rtl, struct serdev_device *serdev,
133 const struct ssh_rtl_ops *ops);
135 int ssh_rtl_start(struct ssh_rtl *rtl);
136 int ssh_rtl_flush(struct ssh_rtl *rtl, unsigned long timeout);
137 void ssh_rtl_shutdown(struct ssh_rtl *rtl);
138 void ssh_rtl_destroy(struct ssh_rtl *rtl);
140 int ssh_request_init(struct ssh_request *rqst, enum ssam_request_flags flags,
141 const struct ssh_request_ops *ops);
143 #endif /* _SURFACE_AGGREGATOR_SSH_REQUEST_LAYER_H */