Lines Matching refs:chan
29 static int add_to_rbuf(struct mbox_chan *chan, void *mssg) in add_to_rbuf() argument
34 spin_lock_irqsave(&chan->lock, flags); in add_to_rbuf()
37 if (chan->msg_count == MBOX_TX_QUEUE_LEN) { in add_to_rbuf()
38 spin_unlock_irqrestore(&chan->lock, flags); in add_to_rbuf()
42 idx = chan->msg_free; in add_to_rbuf()
43 chan->msg_data[idx] = mssg; in add_to_rbuf()
44 chan->msg_count++; in add_to_rbuf()
47 chan->msg_free = 0; in add_to_rbuf()
49 chan->msg_free++; in add_to_rbuf()
51 spin_unlock_irqrestore(&chan->lock, flags); in add_to_rbuf()
56 static void msg_submit(struct mbox_chan *chan) in msg_submit() argument
63 spin_lock_irqsave(&chan->lock, flags); in msg_submit()
65 if (!chan->msg_count || chan->active_req) in msg_submit()
68 count = chan->msg_count; in msg_submit()
69 idx = chan->msg_free; in msg_submit()
75 data = chan->msg_data[idx]; in msg_submit()
77 if (chan->cl->tx_prepare) in msg_submit()
78 chan->cl->tx_prepare(chan->cl, data); in msg_submit()
80 err = chan->mbox->ops->send_data(chan, data); in msg_submit()
82 chan->active_req = data; in msg_submit()
83 chan->msg_count--; in msg_submit()
86 spin_unlock_irqrestore(&chan->lock, flags); in msg_submit()
88 if (!err && (chan->txdone_method & TXDONE_BY_POLL)) in msg_submit()
90 hrtimer_start(&chan->mbox->poll_hrt, ktime_set(0, 0), 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()
108 if (mssg && chan->cl->tx_done) in tx_tick()
109 chan->cl->tx_done(chan->cl, mssg, r); in tx_tick()
111 if (chan->cl->tx_block) in tx_tick()
112 complete(&chan->tx_complete); in tx_tick()
123 struct mbox_chan *chan = &mbox->chans[i]; in txdone_hrtimer() local
125 if (chan->active_req && chan->cl) { in txdone_hrtimer()
126 txdone = chan->mbox->ops->last_tx_done(chan); in txdone_hrtimer()
128 tx_tick(chan, 0); in txdone_hrtimer()
151 void mbox_chan_received_data(struct mbox_chan *chan, void *mssg) in mbox_chan_received_data() argument
154 if (chan->cl->rx_callback) in mbox_chan_received_data()
155 chan->cl->rx_callback(chan->cl, mssg); in mbox_chan_received_data()
169 void mbox_chan_txdone(struct mbox_chan *chan, int r) in mbox_chan_txdone() argument
171 if (unlikely(!(chan->txdone_method & TXDONE_BY_IRQ))) { in mbox_chan_txdone()
172 dev_err(chan->mbox->dev, in mbox_chan_txdone()
177 tx_tick(chan, r); in mbox_chan_txdone()
190 void mbox_client_txdone(struct mbox_chan *chan, int r) in mbox_client_txdone() argument
192 if (unlikely(!(chan->txdone_method & TXDONE_BY_ACK))) { in mbox_client_txdone()
193 dev_err(chan->mbox->dev, "Client can't run the TX ticker\n"); in mbox_client_txdone()
197 tx_tick(chan, r); in mbox_client_txdone()
216 bool mbox_client_peek_data(struct mbox_chan *chan) in mbox_client_peek_data() argument
218 if (chan->mbox->ops->peek_data) in mbox_client_peek_data()
219 return chan->mbox->ops->peek_data(chan); in mbox_client_peek_data()
249 int mbox_send_message(struct mbox_chan *chan, void *mssg) in mbox_send_message() argument
253 if (!chan || !chan->cl) in mbox_send_message()
256 t = add_to_rbuf(chan, mssg); in mbox_send_message()
258 dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n"); in mbox_send_message()
262 msg_submit(chan); in mbox_send_message()
264 if (chan->cl->tx_block && chan->active_req) { in mbox_send_message()
268 if (!chan->cl->tx_tout) /* wait forever */ in mbox_send_message()
271 wait = msecs_to_jiffies(chan->cl->tx_tout); in mbox_send_message()
273 ret = wait_for_completion_timeout(&chan->tx_complete, wait); in mbox_send_message()
276 tx_tick(chan, -EIO); in mbox_send_message()
306 struct mbox_chan *chan; in mbox_request_channel() local
324 chan = ERR_PTR(-EPROBE_DEFER); in mbox_request_channel()
327 chan = mbox->of_xlate(mbox, &spec); in mbox_request_channel()
333 if (IS_ERR(chan)) { in mbox_request_channel()
335 return chan; in mbox_request_channel()
338 if (chan->cl || !try_module_get(mbox->dev->driver->owner)) { in mbox_request_channel()
344 spin_lock_irqsave(&chan->lock, flags); in mbox_request_channel()
345 chan->msg_free = 0; in mbox_request_channel()
346 chan->msg_count = 0; in mbox_request_channel()
347 chan->active_req = NULL; in mbox_request_channel()
348 chan->cl = cl; in mbox_request_channel()
349 init_completion(&chan->tx_complete); in mbox_request_channel()
351 if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) in mbox_request_channel()
352 chan->txdone_method |= TXDONE_BY_ACK; in mbox_request_channel()
354 spin_unlock_irqrestore(&chan->lock, flags); in mbox_request_channel()
356 ret = chan->mbox->ops->startup(chan); in mbox_request_channel()
359 mbox_free_channel(chan); in mbox_request_channel()
360 chan = ERR_PTR(ret); in mbox_request_channel()
364 return chan; in mbox_request_channel()
402 void mbox_free_channel(struct mbox_chan *chan) in mbox_free_channel() argument
406 if (!chan || !chan->cl) in mbox_free_channel()
409 chan->mbox->ops->shutdown(chan); in mbox_free_channel()
412 spin_lock_irqsave(&chan->lock, flags); in mbox_free_channel()
413 chan->cl = NULL; in mbox_free_channel()
414 chan->active_req = NULL; in mbox_free_channel()
415 if (chan->txdone_method == (TXDONE_BY_POLL | TXDONE_BY_ACK)) in mbox_free_channel()
416 chan->txdone_method = TXDONE_BY_POLL; in mbox_free_channel()
418 module_put(chan->mbox->dev->driver->owner); in mbox_free_channel()
419 spin_unlock_irqrestore(&chan->lock, flags); in mbox_free_channel()
463 struct mbox_chan *chan = &mbox->chans[i]; in mbox_controller_register() local
465 chan->cl = NULL; in mbox_controller_register()
466 chan->mbox = mbox; in mbox_controller_register()
467 chan->txdone_method = txdone; in mbox_controller_register()
468 spin_lock_init(&chan->lock); in mbox_controller_register()