Lines Matching refs:chan

26 static int add_to_rbuf(struct mbox_chan *chan, void *mssg)  in add_to_rbuf()  argument
31 spin_lock_irqsave(&chan->lock, flags); in add_to_rbuf()
34 if (chan->msg_count == MBOX_TX_QUEUE_LEN) { in add_to_rbuf()
35 spin_unlock_irqrestore(&chan->lock, flags); in add_to_rbuf()
39 idx = chan->msg_free; in add_to_rbuf()
40 chan->msg_data[idx] = mssg; in add_to_rbuf()
41 chan->msg_count++; in add_to_rbuf()
44 chan->msg_free = 0; in add_to_rbuf()
46 chan->msg_free++; in add_to_rbuf()
48 spin_unlock_irqrestore(&chan->lock, flags); in add_to_rbuf()
53 static void msg_submit(struct mbox_chan *chan) in msg_submit() argument
60 spin_lock_irqsave(&chan->lock, flags); in msg_submit()
62 if (!chan->msg_count || chan->active_req) in msg_submit()
65 count = chan->msg_count; in msg_submit()
66 idx = chan->msg_free; in msg_submit()
72 data = chan->msg_data[idx]; in msg_submit()
74 if (chan->cl->tx_prepare) in msg_submit()
75 chan->cl->tx_prepare(chan->cl, data); in msg_submit()
77 err = chan->mbox->ops->send_data(chan, data); in msg_submit()
79 chan->active_req = data; in msg_submit()
80 chan->msg_count--; in msg_submit()
83 spin_unlock_irqrestore(&chan->lock, flags); in msg_submit()
86 if (!err && (chan->txdone_method & TXDONE_BY_POLL)) { in msg_submit()
88 if (!hrtimer_active(&chan->mbox->poll_hrt)) in msg_submit()
89 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()
129 txdone = chan->mbox->ops->last_tx_done(chan); in txdone_hrtimer()
131 tx_tick(chan, 0); in txdone_hrtimer()
152 void mbox_chan_received_data(struct mbox_chan *chan, void *mssg) in mbox_chan_received_data() argument
155 if (chan->cl->rx_callback) in mbox_chan_received_data()
156 chan->cl->rx_callback(chan->cl, mssg); in mbox_chan_received_data()
170 void mbox_chan_txdone(struct mbox_chan *chan, int r) in mbox_chan_txdone() argument
172 if (unlikely(!(chan->txdone_method & TXDONE_BY_IRQ))) { in mbox_chan_txdone()
173 dev_err(chan->mbox->dev, in mbox_chan_txdone()
178 tx_tick(chan, r); in mbox_chan_txdone()
191 void mbox_client_txdone(struct mbox_chan *chan, int r) in mbox_client_txdone() argument
193 if (unlikely(!(chan->txdone_method & TXDONE_BY_ACK))) { in mbox_client_txdone()
194 dev_err(chan->mbox->dev, "Client can't run the TX ticker\n"); in mbox_client_txdone()
198 tx_tick(chan, r); in mbox_client_txdone()
217 bool mbox_client_peek_data(struct mbox_chan *chan) in mbox_client_peek_data() argument
219 if (chan->mbox->ops->peek_data) in mbox_client_peek_data()
220 return chan->mbox->ops->peek_data(chan); in mbox_client_peek_data()
250 int mbox_send_message(struct mbox_chan *chan, void *mssg) in mbox_send_message() argument
254 if (!chan || !chan->cl) in mbox_send_message()
257 t = add_to_rbuf(chan, mssg); in mbox_send_message()
259 dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n"); in mbox_send_message()
263 msg_submit(chan); in mbox_send_message()
265 if (chan->cl->tx_block) { in mbox_send_message()
269 if (!chan->cl->tx_tout) /* wait forever */ in mbox_send_message()
272 wait = msecs_to_jiffies(chan->cl->tx_tout); in mbox_send_message()
274 ret = wait_for_completion_timeout(&chan->tx_complete, wait); in mbox_send_message()
277 tx_tick(chan, t); in mbox_send_message()
299 int mbox_flush(struct mbox_chan *chan, unsigned long timeout) in mbox_flush() argument
303 if (!chan->mbox->ops->flush) in mbox_flush()
306 ret = chan->mbox->ops->flush(chan, timeout); in mbox_flush()
308 tx_tick(chan, ret); in mbox_flush()
336 struct mbox_chan *chan; in mbox_request_channel() local
354 chan = ERR_PTR(-EPROBE_DEFER); in mbox_request_channel()
357 chan = mbox->of_xlate(mbox, &spec); in mbox_request_channel()
358 if (!IS_ERR(chan)) in mbox_request_channel()
364 if (IS_ERR(chan)) { in mbox_request_channel()
366 return chan; in mbox_request_channel()
369 if (chan->cl || !try_module_get(mbox->dev->driver->owner)) { in mbox_request_channel()
375 spin_lock_irqsave(&chan->lock, flags); in mbox_request_channel()
376 chan->msg_free = 0; in mbox_request_channel()
377 chan->msg_count = 0; in mbox_request_channel()
378 chan->active_req = NULL; in mbox_request_channel()
379 chan->cl = cl; in mbox_request_channel()
380 init_completion(&chan->tx_complete); in mbox_request_channel()
382 if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) in mbox_request_channel()
383 chan->txdone_method = TXDONE_BY_ACK; in mbox_request_channel()
385 spin_unlock_irqrestore(&chan->lock, flags); in mbox_request_channel()
387 if (chan->mbox->ops->startup) { in mbox_request_channel()
388 ret = chan->mbox->ops->startup(chan); in mbox_request_channel()
392 mbox_free_channel(chan); in mbox_request_channel()
393 chan = ERR_PTR(ret); in mbox_request_channel()
398 return chan; in mbox_request_channel()
438 void mbox_free_channel(struct mbox_chan *chan) in mbox_free_channel() argument
442 if (!chan || !chan->cl) in mbox_free_channel()
445 if (chan->mbox->ops->shutdown) in mbox_free_channel()
446 chan->mbox->ops->shutdown(chan); in mbox_free_channel()
449 spin_lock_irqsave(&chan->lock, flags); in mbox_free_channel()
450 chan->cl = NULL; in mbox_free_channel()
451 chan->active_req = NULL; in mbox_free_channel()
452 if (chan->txdone_method == TXDONE_BY_ACK) in mbox_free_channel()
453 chan->txdone_method = TXDONE_BY_POLL; in mbox_free_channel()
455 module_put(chan->mbox->dev->driver->owner); in mbox_free_channel()
456 spin_unlock_irqrestore(&chan->lock, flags); in mbox_free_channel()
506 struct mbox_chan *chan = &mbox->chans[i]; in mbox_controller_register() local
508 chan->cl = NULL; in mbox_controller_register()
509 chan->mbox = mbox; in mbox_controller_register()
510 chan->txdone_method = txdone; in mbox_controller_register()
511 spin_lock_init(&chan->lock); in mbox_controller_register()