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()
85 if (!err && (chan->txdone_method & TXDONE_BY_POLL)) in msg_submit()
87 hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL); in msg_submit()
90 static void tx_tick(struct mbox_chan *chan, int r) in tx_tick() argument
95 spin_lock_irqsave(&chan->lock, flags); in tx_tick()
96 mssg = chan->active_req; in tx_tick()
97 chan->active_req = NULL; in tx_tick()
98 spin_unlock_irqrestore(&chan->lock, flags); in tx_tick()
101 msg_submit(chan); in tx_tick()
107 if (chan->cl->tx_done) in tx_tick()
108 chan->cl->tx_done(chan->cl, mssg, r); in tx_tick()
110 if (r != -ETIME && chan->cl->tx_block) in tx_tick()
111 complete(&chan->tx_complete); in tx_tick()
122 struct mbox_chan *chan = &mbox->chans[i]; in txdone_hrtimer() local
124 if (chan->active_req && chan->cl) { in txdone_hrtimer()
125 txdone = chan->mbox->ops->last_tx_done(chan); in txdone_hrtimer()
127 tx_tick(chan, 0); in txdone_hrtimer()
150 void mbox_chan_received_data(struct mbox_chan *chan, void *mssg) in mbox_chan_received_data() argument
153 if (chan->cl->rx_callback) in mbox_chan_received_data()
154 chan->cl->rx_callback(chan->cl, mssg); in mbox_chan_received_data()
168 void mbox_chan_txdone(struct mbox_chan *chan, int r) in mbox_chan_txdone() argument
170 if (unlikely(!(chan->txdone_method & TXDONE_BY_IRQ))) { in mbox_chan_txdone()
171 dev_err(chan->mbox->dev, in mbox_chan_txdone()
176 tx_tick(chan, r); in mbox_chan_txdone()
189 void mbox_client_txdone(struct mbox_chan *chan, int r) in mbox_client_txdone() argument
191 if (unlikely(!(chan->txdone_method & TXDONE_BY_ACK))) { in mbox_client_txdone()
192 dev_err(chan->mbox->dev, "Client can't run the TX ticker\n"); in mbox_client_txdone()
196 tx_tick(chan, r); in mbox_client_txdone()
215 bool mbox_client_peek_data(struct mbox_chan *chan) in mbox_client_peek_data() argument
217 if (chan->mbox->ops->peek_data) in mbox_client_peek_data()
218 return chan->mbox->ops->peek_data(chan); in mbox_client_peek_data()
248 int mbox_send_message(struct mbox_chan *chan, void *mssg) in mbox_send_message() argument
252 if (!chan || !chan->cl) in mbox_send_message()
255 t = add_to_rbuf(chan, mssg); in mbox_send_message()
257 dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n"); in mbox_send_message()
261 msg_submit(chan); in mbox_send_message()
263 if (chan->cl->tx_block) { in mbox_send_message()
267 if (!chan->cl->tx_tout) /* wait forever */ in mbox_send_message()
270 wait = msecs_to_jiffies(chan->cl->tx_tout); in mbox_send_message()
272 ret = wait_for_completion_timeout(&chan->tx_complete, wait); in mbox_send_message()
275 tx_tick(chan, t); in mbox_send_message()
297 int mbox_flush(struct mbox_chan *chan, unsigned long timeout) in mbox_flush() argument
301 if (!chan->mbox->ops->flush) in mbox_flush()
304 ret = chan->mbox->ops->flush(chan, timeout); in mbox_flush()
306 tx_tick(chan, ret); in mbox_flush()
334 struct mbox_chan *chan; in mbox_request_channel() local
352 chan = ERR_PTR(-EPROBE_DEFER); in mbox_request_channel()
355 chan = mbox->of_xlate(mbox, &spec); in mbox_request_channel()
356 if (!IS_ERR(chan)) in mbox_request_channel()
362 if (IS_ERR(chan)) { in mbox_request_channel()
364 return chan; in mbox_request_channel()
367 if (chan->cl || !try_module_get(mbox->dev->driver->owner)) { in mbox_request_channel()
373 spin_lock_irqsave(&chan->lock, flags); in mbox_request_channel()
374 chan->msg_free = 0; in mbox_request_channel()
375 chan->msg_count = 0; in mbox_request_channel()
376 chan->active_req = NULL; in mbox_request_channel()
377 chan->cl = cl; in mbox_request_channel()
378 init_completion(&chan->tx_complete); in mbox_request_channel()
380 if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) in mbox_request_channel()
381 chan->txdone_method = TXDONE_BY_ACK; in mbox_request_channel()
383 spin_unlock_irqrestore(&chan->lock, flags); in mbox_request_channel()
385 if (chan->mbox->ops->startup) { in mbox_request_channel()
386 ret = chan->mbox->ops->startup(chan); in mbox_request_channel()
390 mbox_free_channel(chan); in mbox_request_channel()
391 chan = ERR_PTR(ret); in mbox_request_channel()
396 return chan; in mbox_request_channel()
436 void mbox_free_channel(struct mbox_chan *chan) in mbox_free_channel() argument
440 if (!chan || !chan->cl) in mbox_free_channel()
443 if (chan->mbox->ops->shutdown) in mbox_free_channel()
444 chan->mbox->ops->shutdown(chan); in mbox_free_channel()
447 spin_lock_irqsave(&chan->lock, flags); in mbox_free_channel()
448 chan->cl = NULL; in mbox_free_channel()
449 chan->active_req = NULL; in mbox_free_channel()
450 if (chan->txdone_method == TXDONE_BY_ACK) in mbox_free_channel()
451 chan->txdone_method = TXDONE_BY_POLL; in mbox_free_channel()
453 module_put(chan->mbox->dev->driver->owner); in mbox_free_channel()
454 spin_unlock_irqrestore(&chan->lock, flags); in mbox_free_channel()
504 struct mbox_chan *chan = &mbox->chans[i]; in mbox_controller_register() local
506 chan->cl = NULL; in mbox_controller_register()
507 chan->mbox = mbox; in mbox_controller_register()
508 chan->txdone_method = txdone; in mbox_controller_register()
509 spin_lock_init(&chan->lock); in mbox_controller_register()