Lines Matching refs:chan
27 static int add_to_rbuf(struct mbox_chan *chan, void *mssg) in add_to_rbuf() argument
32 spin_lock_irqsave(&chan->lock, flags); in add_to_rbuf()
35 if (chan->msg_count == MBOX_TX_QUEUE_LEN) { in add_to_rbuf()
36 spin_unlock_irqrestore(&chan->lock, flags); in add_to_rbuf()
40 idx = chan->msg_free; in add_to_rbuf()
41 chan->msg_data[idx] = mssg; in add_to_rbuf()
42 chan->msg_count++; in add_to_rbuf()
45 chan->msg_free = 0; in add_to_rbuf()
47 chan->msg_free++; in add_to_rbuf()
49 spin_unlock_irqrestore(&chan->lock, flags); in add_to_rbuf()
54 static void msg_submit(struct mbox_chan *chan) in msg_submit() argument
61 spin_lock_irqsave(&chan->lock, flags); in msg_submit()
63 if (!chan->msg_count || chan->active_req) in msg_submit()
66 count = chan->msg_count; in msg_submit()
67 idx = chan->msg_free; in msg_submit()
73 data = chan->msg_data[idx]; in msg_submit()
75 if (chan->cl->tx_prepare) in msg_submit()
76 chan->cl->tx_prepare(chan->cl, data); in msg_submit()
78 err = chan->mbox->ops->send_data(chan, data); in msg_submit()
80 chan->active_req = data; in msg_submit()
81 chan->msg_count--; in msg_submit()
84 spin_unlock_irqrestore(&chan->lock, flags); in msg_submit()
86 if (!err && (chan->txdone_method & TXDONE_BY_POLL)) { in msg_submit()
88 spin_lock_irqsave(&chan->mbox->poll_hrt_lock, flags); in msg_submit()
89 hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL); in msg_submit()
90 spin_unlock_irqrestore(&chan->mbox->poll_hrt_lock, flags); in msg_submit()
94 static void tx_tick(struct mbox_chan *chan, int r) in tx_tick() argument
99 spin_lock_irqsave(&chan->lock, flags); in tx_tick()
100 mssg = chan->active_req; in tx_tick()
101 chan->active_req = NULL; in tx_tick()
102 spin_unlock_irqrestore(&chan->lock, flags); in tx_tick()
105 msg_submit(chan); in tx_tick()
111 if (chan->cl->tx_done) in tx_tick()
112 chan->cl->tx_done(chan->cl, mssg, r); in tx_tick()
114 if (r != -ETIME && chan->cl->tx_block) in tx_tick()
115 complete(&chan->tx_complete); in tx_tick()
127 struct mbox_chan *chan = &mbox->chans[i]; in txdone_hrtimer() local
129 if (chan->active_req && chan->cl) { in txdone_hrtimer()
130 txdone = chan->mbox->ops->last_tx_done(chan); in txdone_hrtimer()
132 tx_tick(chan, 0); in txdone_hrtimer()
159 void mbox_chan_received_data(struct mbox_chan *chan, void *mssg) in mbox_chan_received_data() argument
162 if (chan->cl->rx_callback) in mbox_chan_received_data()
163 chan->cl->rx_callback(chan->cl, mssg); in mbox_chan_received_data()
177 void mbox_chan_txdone(struct mbox_chan *chan, int r) in mbox_chan_txdone() argument
179 if (unlikely(!(chan->txdone_method & TXDONE_BY_IRQ))) { in mbox_chan_txdone()
180 dev_err(chan->mbox->dev, in mbox_chan_txdone()
185 tx_tick(chan, r); in mbox_chan_txdone()
198 void mbox_client_txdone(struct mbox_chan *chan, int r) in mbox_client_txdone() argument
200 if (unlikely(!(chan->txdone_method & TXDONE_BY_ACK))) { in mbox_client_txdone()
201 dev_err(chan->mbox->dev, "Client can't run the TX ticker\n"); in mbox_client_txdone()
205 tx_tick(chan, r); in mbox_client_txdone()
224 bool mbox_client_peek_data(struct mbox_chan *chan) in mbox_client_peek_data() argument
226 if (chan->mbox->ops->peek_data) in mbox_client_peek_data()
227 return chan->mbox->ops->peek_data(chan); in mbox_client_peek_data()
257 int mbox_send_message(struct mbox_chan *chan, void *mssg) in mbox_send_message() argument
261 if (!chan || !chan->cl) in mbox_send_message()
264 t = add_to_rbuf(chan, mssg); in mbox_send_message()
266 dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n"); in mbox_send_message()
270 msg_submit(chan); in mbox_send_message()
272 if (chan->cl->tx_block) { in mbox_send_message()
276 if (!chan->cl->tx_tout) /* wait forever */ in mbox_send_message()
279 wait = msecs_to_jiffies(chan->cl->tx_tout); in mbox_send_message()
281 ret = wait_for_completion_timeout(&chan->tx_complete, wait); in mbox_send_message()
284 tx_tick(chan, t); in mbox_send_message()
306 int mbox_flush(struct mbox_chan *chan, unsigned long timeout) in mbox_flush() argument
310 if (!chan->mbox->ops->flush) in mbox_flush()
313 ret = chan->mbox->ops->flush(chan, timeout); in mbox_flush()
315 tx_tick(chan, ret); in mbox_flush()
321 static int __mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl) in __mbox_bind_client() argument
327 if (chan->cl || !try_module_get(chan->mbox->dev->driver->owner)) { in __mbox_bind_client()
332 spin_lock_irqsave(&chan->lock, flags); in __mbox_bind_client()
333 chan->msg_free = 0; in __mbox_bind_client()
334 chan->msg_count = 0; in __mbox_bind_client()
335 chan->active_req = NULL; in __mbox_bind_client()
336 chan->cl = cl; in __mbox_bind_client()
337 init_completion(&chan->tx_complete); in __mbox_bind_client()
339 if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) in __mbox_bind_client()
340 chan->txdone_method = TXDONE_BY_ACK; in __mbox_bind_client()
342 spin_unlock_irqrestore(&chan->lock, flags); in __mbox_bind_client()
344 if (chan->mbox->ops->startup) { in __mbox_bind_client()
345 ret = chan->mbox->ops->startup(chan); in __mbox_bind_client()
349 mbox_free_channel(chan); in __mbox_bind_client()
374 int mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl) in mbox_bind_client() argument
379 ret = __mbox_bind_client(chan, cl); in mbox_bind_client()
408 struct mbox_chan *chan; in mbox_request_channel() local
425 chan = ERR_PTR(-EPROBE_DEFER); in mbox_request_channel()
428 chan = mbox->of_xlate(mbox, &spec); in mbox_request_channel()
429 if (!IS_ERR(chan)) in mbox_request_channel()
435 if (IS_ERR(chan)) { in mbox_request_channel()
437 return chan; in mbox_request_channel()
440 ret = __mbox_bind_client(chan, cl); in mbox_request_channel()
442 chan = ERR_PTR(ret); in mbox_request_channel()
445 return chan; in mbox_request_channel()
485 void mbox_free_channel(struct mbox_chan *chan) in mbox_free_channel() argument
489 if (!chan || !chan->cl) in mbox_free_channel()
492 if (chan->mbox->ops->shutdown) in mbox_free_channel()
493 chan->mbox->ops->shutdown(chan); in mbox_free_channel()
496 spin_lock_irqsave(&chan->lock, flags); in mbox_free_channel()
497 chan->cl = NULL; in mbox_free_channel()
498 chan->active_req = NULL; in mbox_free_channel()
499 if (chan->txdone_method == TXDONE_BY_ACK) in mbox_free_channel()
500 chan->txdone_method = TXDONE_BY_POLL; in mbox_free_channel()
502 module_put(chan->mbox->dev->driver->owner); in mbox_free_channel()
503 spin_unlock_irqrestore(&chan->lock, flags); in mbox_free_channel()
554 struct mbox_chan *chan = &mbox->chans[i]; in mbox_controller_register() local
556 chan->cl = NULL; in mbox_controller_register()
557 chan->mbox = mbox; in mbox_controller_register()
558 chan->txdone_method = txdone; in mbox_controller_register()
559 spin_lock_init(&chan->lock); in mbox_controller_register()