Lines Matching +full:ctrl +full:- +full:len

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2011-2017, The Linux Foundation
11 * slim_msg_response() - Deliver Message response received from a device to the
14 * @ctrl: Controller handle
16 * @len: Length of the reply
20 * This helps in making the API asynchronous, and controller-driver doesn't need
24 void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 len) in slim_msg_response() argument
30 spin_lock_irqsave(&ctrl->txn_lock, flags); in slim_msg_response()
31 txn = idr_find(&ctrl->tid_idr, tid); in slim_msg_response()
32 spin_unlock_irqrestore(&ctrl->txn_lock, flags); in slim_msg_response()
37 msg = txn->msg; in slim_msg_response()
38 if (msg == NULL || msg->rbuf == NULL) { in slim_msg_response()
39 dev_err(ctrl->dev, "Got response to invalid TID:%d, len:%d\n", in slim_msg_response()
40 tid, len); in slim_msg_response()
44 slim_free_txn_tid(ctrl, txn); in slim_msg_response()
45 memcpy(msg->rbuf, reply, len); in slim_msg_response()
46 if (txn->comp) in slim_msg_response()
47 complete(txn->comp); in slim_msg_response()
49 /* Remove runtime-pm vote now that response was received for TID txn */ in slim_msg_response()
50 pm_runtime_mark_last_busy(ctrl->dev); in slim_msg_response()
51 pm_runtime_put_autosuspend(ctrl->dev); in slim_msg_response()
56 * slim_alloc_txn_tid() - Allocate a tid to txn
58 * @ctrl: Controller handle
61 * Return: zero on success with valid txn->tid and error code on failures.
63 int slim_alloc_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn) in slim_alloc_txn_tid() argument
68 spin_lock_irqsave(&ctrl->txn_lock, flags); in slim_alloc_txn_tid()
69 ret = idr_alloc_cyclic(&ctrl->tid_idr, txn, 1, in slim_alloc_txn_tid()
72 spin_unlock_irqrestore(&ctrl->txn_lock, flags); in slim_alloc_txn_tid()
75 txn->tid = ret; in slim_alloc_txn_tid()
76 spin_unlock_irqrestore(&ctrl->txn_lock, flags); in slim_alloc_txn_tid()
82 * slim_free_txn_tid() - Free tid of txn
84 * @ctrl: Controller handle
87 void slim_free_txn_tid(struct slim_controller *ctrl, struct slim_msg_txn *txn) in slim_free_txn_tid() argument
91 spin_lock_irqsave(&ctrl->txn_lock, flags); in slim_free_txn_tid()
92 idr_remove(&ctrl->tid_idr, txn->tid); in slim_free_txn_tid()
93 spin_unlock_irqrestore(&ctrl->txn_lock, flags); in slim_free_txn_tid()
98 * slim_do_transfer() - Process a SLIMbus-messaging transaction
100 * @ctrl: Controller handle
107 * Return: -ETIMEDOUT: If transmission of this message timed out
110 int slim_do_transfer(struct slim_controller *ctrl, struct slim_msg_txn *txn) in slim_do_transfer() argument
117 * do not vote for runtime-PM if the transactions are part of clock in slim_do_transfer()
120 if (ctrl->sched.clk_state == SLIM_CLK_ENTERING_PAUSE && in slim_do_transfer()
121 (txn->mt == SLIM_MSG_MT_CORE && in slim_do_transfer()
122 txn->mc >= SLIM_MSG_MC_BEGIN_RECONFIGURATION && in slim_do_transfer()
123 txn->mc <= SLIM_MSG_MC_RECONFIGURE_NOW)) in slim_do_transfer()
127 ret = pm_runtime_get_sync(ctrl->dev); in slim_do_transfer()
128 if (ctrl->sched.clk_state != SLIM_CLK_ACTIVE) { in slim_do_transfer()
129 dev_err(ctrl->dev, "ctrl wrong state:%d, ret:%d\n", in slim_do_transfer()
130 ctrl->sched.clk_state, ret); in slim_do_transfer()
135 txn->tid = 0; in slim_do_transfer()
136 need_tid = slim_tid_txn(txn->mt, txn->mc); in slim_do_transfer()
139 ret = slim_alloc_txn_tid(ctrl, txn); in slim_do_transfer()
143 if (!txn->msg->comp) in slim_do_transfer()
144 txn->comp = &done; in slim_do_transfer()
146 txn->comp = txn->comp; in slim_do_transfer()
149 ret = ctrl->xfer_msg(ctrl, txn); in slim_do_transfer()
151 if (!ret && need_tid && !txn->msg->comp) { in slim_do_transfer()
152 unsigned long ms = txn->rl + HZ; in slim_do_transfer()
154 timeout = wait_for_completion_timeout(txn->comp, in slim_do_transfer()
157 ret = -ETIMEDOUT; in slim_do_transfer()
158 slim_free_txn_tid(ctrl, txn); in slim_do_transfer()
163 dev_err(ctrl->dev, "Tx:MT:0x%x, MC:0x%x, LA:0x%x failed:%d\n", in slim_do_transfer()
164 txn->mt, txn->mc, txn->la, ret); in slim_do_transfer()
167 if (!clk_pause_msg && (txn->tid == 0 || ret == -ETIMEDOUT)) { in slim_do_transfer()
169 * remove runtime-pm vote if this was TX only, or in slim_do_transfer()
172 pm_runtime_mark_last_busy(ctrl->dev); in slim_do_transfer()
173 pm_runtime_put_autosuspend(ctrl->dev); in slim_do_transfer()
179 static int slim_val_inf_sanity(struct slim_controller *ctrl, in slim_val_inf_sanity() argument
182 if (!msg || msg->num_bytes > 16 || in slim_val_inf_sanity()
183 (msg->start_offset + msg->num_bytes) > 0xC00) in slim_val_inf_sanity()
188 if (msg->rbuf != NULL) in slim_val_inf_sanity()
194 if (msg->wbuf != NULL) in slim_val_inf_sanity()
200 if (msg->rbuf != NULL && msg->wbuf != NULL) in slim_val_inf_sanity()
206 dev_err(ctrl->dev, "Sanity check failed:msg:offset:0x%x, mc:%d\n", in slim_val_inf_sanity()
207 msg->start_offset, mc); in slim_val_inf_sanity()
208 return -EINVAL; in slim_val_inf_sanity()
219 return sizetocode[code - 1]; in slim_slicesize()
223 * slim_xfer_msg() - Transfer a value info message on slim device
231 * Return: -ETIMEDOUT: If transmission of this message timed out
236 DEFINE_SLIM_LDEST_TXN(txn_stack, mc, 6, sbdev->laddr, msg); in slim_xfer_msg()
238 struct slim_controller *ctrl = sbdev->ctrl; in slim_xfer_msg() local
242 if (!ctrl) in slim_xfer_msg()
243 return -EINVAL; in slim_xfer_msg()
245 ret = slim_val_inf_sanity(ctrl, msg, mc); in slim_xfer_msg()
249 sl = slim_slicesize(msg->num_bytes); in slim_xfer_msg()
251 dev_dbg(ctrl->dev, "SB xfer msg:os:%x, len:%d, MC:%x, sl:%x\n", in slim_xfer_msg()
252 msg->start_offset, msg->num_bytes, mc, sl); in slim_xfer_msg()
254 txn->ec = ((sl | (1 << 3)) | ((msg->start_offset & 0xFFF) << 4)); in slim_xfer_msg()
261 txn->rl += msg->num_bytes; in slim_xfer_msg()
267 if (slim_tid_txn(txn->mt, txn->mc)) in slim_xfer_msg()
268 txn->rl++; in slim_xfer_msg()
270 return slim_do_transfer(ctrl, txn); in slim_xfer_msg()
277 msg->start_offset = addr; in slim_fill_msg()
278 msg->num_bytes = count; in slim_fill_msg()
279 msg->rbuf = rbuf; in slim_fill_msg()
280 msg->wbuf = wbuf; in slim_fill_msg()
281 msg->comp = NULL; in slim_fill_msg()
285 * slim_read() - Read SLIMbus value element
292 * Return: -EINVAL for Invalid parameters, -ETIMEDOUT If transmission of
307 * slim_readb() - Read byte from SLIMbus value element
328 * slim_write() - Write SLIMbus value element
335 * Return: -EINVAL for Invalid parameters, -ETIMEDOUT If transmission of
350 * slim_writeb() - Write byte to SLIMbus value element
356 * Return: -EINVAL for Invalid parameters, -ETIMEDOUT If transmission of