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, 0, HRTIMER_MODE_REL); in msg_submit()
93 static void tx_tick(struct mbox_chan *chan, int r) in tx_tick() argument
98 spin_lock_irqsave(&chan->lock, flags); in tx_tick()
99 mssg = chan->active_req; in tx_tick()
100 chan->active_req = NULL; in tx_tick()
101 spin_unlock_irqrestore(&chan->lock, flags); in tx_tick()
104 msg_submit(chan); in tx_tick()
110 if (chan->cl->tx_done) in tx_tick()
111 chan->cl->tx_done(chan->cl, mssg, r); in tx_tick()
113 if (r != -ETIME && chan->cl->tx_block) in tx_tick()
114 complete(&chan->tx_complete); in tx_tick()
125 struct mbox_chan *chan = &mbox->chans[i]; in txdone_hrtimer() local
127 if (chan->active_req && chan->cl) { in txdone_hrtimer()
128 txdone = chan->mbox->ops->last_tx_done(chan); in txdone_hrtimer()
130 tx_tick(chan, 0); in txdone_hrtimer()
153 void mbox_chan_received_data(struct mbox_chan *chan, void *mssg) in mbox_chan_received_data() argument
156 if (chan->cl->rx_callback) in mbox_chan_received_data()
157 chan->cl->rx_callback(chan->cl, mssg); in mbox_chan_received_data()
171 void mbox_chan_txdone(struct mbox_chan *chan, int r) in mbox_chan_txdone() argument
173 if (unlikely(!(chan->txdone_method & TXDONE_BY_IRQ))) { in mbox_chan_txdone()
174 dev_err(chan->mbox->dev, in mbox_chan_txdone()
179 tx_tick(chan, r); in mbox_chan_txdone()
192 void mbox_client_txdone(struct mbox_chan *chan, int r) in mbox_client_txdone() argument
194 if (unlikely(!(chan->txdone_method & TXDONE_BY_ACK))) { in mbox_client_txdone()
195 dev_err(chan->mbox->dev, "Client can't run the TX ticker\n"); in mbox_client_txdone()
199 tx_tick(chan, r); in mbox_client_txdone()
218 bool mbox_client_peek_data(struct mbox_chan *chan) in mbox_client_peek_data() argument
220 if (chan->mbox->ops->peek_data) in mbox_client_peek_data()
221 return chan->mbox->ops->peek_data(chan); in mbox_client_peek_data()
251 int mbox_send_message(struct mbox_chan *chan, void *mssg) in mbox_send_message() argument
255 if (!chan || !chan->cl) in mbox_send_message()
258 t = add_to_rbuf(chan, mssg); in mbox_send_message()
260 dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n"); in mbox_send_message()
264 msg_submit(chan); in mbox_send_message()
266 if (chan->cl->tx_block) { in mbox_send_message()
270 if (!chan->cl->tx_tout) /* wait forever */ in mbox_send_message()
273 wait = msecs_to_jiffies(chan->cl->tx_tout); in mbox_send_message()
275 ret = wait_for_completion_timeout(&chan->tx_complete, wait); in mbox_send_message()
278 tx_tick(chan, t); in mbox_send_message()
308 struct mbox_chan *chan; in mbox_request_channel() local
326 chan = ERR_PTR(-EPROBE_DEFER); in mbox_request_channel()
329 chan = mbox->of_xlate(mbox, &spec); in mbox_request_channel()
335 if (IS_ERR(chan)) { in mbox_request_channel()
337 return chan; in mbox_request_channel()
340 if (chan->cl || !try_module_get(mbox->dev->driver->owner)) { in mbox_request_channel()
346 spin_lock_irqsave(&chan->lock, flags); in mbox_request_channel()
347 chan->msg_free = 0; in mbox_request_channel()
348 chan->msg_count = 0; in mbox_request_channel()
349 chan->active_req = NULL; in mbox_request_channel()
350 chan->cl = cl; in mbox_request_channel()
351 init_completion(&chan->tx_complete); in mbox_request_channel()
353 if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) in mbox_request_channel()
354 chan->txdone_method = TXDONE_BY_ACK; in mbox_request_channel()
356 spin_unlock_irqrestore(&chan->lock, flags); in mbox_request_channel()
358 if (chan->mbox->ops->startup) { in mbox_request_channel()
359 ret = chan->mbox->ops->startup(chan); in mbox_request_channel()
363 mbox_free_channel(chan); in mbox_request_channel()
364 chan = ERR_PTR(ret); in mbox_request_channel()
369 return chan; in mbox_request_channel()
407 void mbox_free_channel(struct mbox_chan *chan) in mbox_free_channel() argument
411 if (!chan || !chan->cl) in mbox_free_channel()
414 if (chan->mbox->ops->shutdown) in mbox_free_channel()
415 chan->mbox->ops->shutdown(chan); in mbox_free_channel()
418 spin_lock_irqsave(&chan->lock, flags); in mbox_free_channel()
419 chan->cl = NULL; in mbox_free_channel()
420 chan->active_req = NULL; in mbox_free_channel()
421 if (chan->txdone_method == TXDONE_BY_ACK) in mbox_free_channel()
422 chan->txdone_method = TXDONE_BY_POLL; in mbox_free_channel()
424 module_put(chan->mbox->dev->driver->owner); in mbox_free_channel()
425 spin_unlock_irqrestore(&chan->lock, flags); in mbox_free_channel()
475 struct mbox_chan *chan = &mbox->chans[i]; in mbox_controller_register() local
477 chan->cl = NULL; in mbox_controller_register()
478 chan->mbox = mbox; in mbox_controller_register()
479 chan->txdone_method = txdone; in mbox_controller_register()
480 spin_lock_init(&chan->lock); in mbox_controller_register()