Lines Matching refs:chan

31 static int add_to_rbuf(struct mbox_chan *chan, void *mssg)  in add_to_rbuf()  argument
36 spin_lock_irqsave(&chan->lock, flags); in add_to_rbuf()
39 if (chan->msg_count == MBOX_TX_QUEUE_LEN) { in add_to_rbuf()
40 spin_unlock_irqrestore(&chan->lock, flags); in add_to_rbuf()
44 idx = chan->msg_free; in add_to_rbuf()
45 chan->msg_data[idx] = mssg; in add_to_rbuf()
46 chan->msg_count++; in add_to_rbuf()
49 chan->msg_free = 0; in add_to_rbuf()
51 chan->msg_free++; in add_to_rbuf()
53 spin_unlock_irqrestore(&chan->lock, flags); in add_to_rbuf()
58 static void msg_submit(struct mbox_chan *chan) in msg_submit() argument
65 spin_lock_irqsave(&chan->lock, flags); in msg_submit()
67 if (!chan->msg_count || chan->active_req) in msg_submit()
70 count = chan->msg_count; in msg_submit()
71 idx = chan->msg_free; in msg_submit()
77 data = chan->msg_data[idx]; in msg_submit()
79 if (chan->cl->tx_prepare) in msg_submit()
80 chan->cl->tx_prepare(chan->cl, data); in msg_submit()
82 err = chan->mbox->ops->send_data(chan, data); in msg_submit()
84 chan->active_req = data; in msg_submit()
85 chan->msg_count--; in msg_submit()
88 spin_unlock_irqrestore(&chan->lock, flags); in msg_submit()
90 if (!err && (chan->txdone_method & TXDONE_BY_POLL)) in msg_submit()
91 poll_txdone((unsigned long)chan->mbox); 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()
122 struct mbox_chan *chan = &mbox->chans[i]; in poll_txdone() local
124 if (chan->active_req && chan->cl) { in poll_txdone()
125 txdone = chan->mbox->ops->last_tx_done(chan); in poll_txdone()
127 tx_tick(chan, 0); in poll_txdone()
148 void mbox_chan_received_data(struct mbox_chan *chan, void *mssg) in mbox_chan_received_data() argument
151 if (chan->cl->rx_callback) in mbox_chan_received_data()
152 chan->cl->rx_callback(chan->cl, mssg); in mbox_chan_received_data()
166 void mbox_chan_txdone(struct mbox_chan *chan, int r) in mbox_chan_txdone() argument
168 if (unlikely(!(chan->txdone_method & TXDONE_BY_IRQ))) { in mbox_chan_txdone()
169 dev_err(chan->mbox->dev, in mbox_chan_txdone()
174 tx_tick(chan, r); in mbox_chan_txdone()
187 void mbox_client_txdone(struct mbox_chan *chan, int r) in mbox_client_txdone() argument
189 if (unlikely(!(chan->txdone_method & TXDONE_BY_ACK))) { in mbox_client_txdone()
190 dev_err(chan->mbox->dev, "Client can't run the TX ticker\n"); in mbox_client_txdone()
194 tx_tick(chan, r); in mbox_client_txdone()
213 bool mbox_client_peek_data(struct mbox_chan *chan) in mbox_client_peek_data() argument
215 if (chan->mbox->ops->peek_data) in mbox_client_peek_data()
216 return chan->mbox->ops->peek_data(chan); in mbox_client_peek_data()
246 int mbox_send_message(struct mbox_chan *chan, void *mssg) in mbox_send_message() argument
250 if (!chan || !chan->cl) in mbox_send_message()
253 t = add_to_rbuf(chan, mssg); in mbox_send_message()
255 dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n"); in mbox_send_message()
259 msg_submit(chan); in mbox_send_message()
261 if (chan->cl->tx_block && chan->active_req) { in mbox_send_message()
265 if (!chan->cl->tx_tout) /* wait forever */ in mbox_send_message()
268 wait = msecs_to_jiffies(chan->cl->tx_tout); in mbox_send_message()
270 ret = wait_for_completion_timeout(&chan->tx_complete, wait); in mbox_send_message()
273 tx_tick(chan, -EIO); in mbox_send_message()
303 struct mbox_chan *chan; in mbox_request_channel() local
321 chan = NULL; in mbox_request_channel()
324 chan = mbox->of_xlate(mbox, &spec); in mbox_request_channel()
330 if (!chan || chan->cl || !try_module_get(mbox->dev->driver->owner)) { in mbox_request_channel()
336 spin_lock_irqsave(&chan->lock, flags); in mbox_request_channel()
337 chan->msg_free = 0; in mbox_request_channel()
338 chan->msg_count = 0; in mbox_request_channel()
339 chan->active_req = NULL; in mbox_request_channel()
340 chan->cl = cl; in mbox_request_channel()
341 init_completion(&chan->tx_complete); in mbox_request_channel()
343 if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) in mbox_request_channel()
344 chan->txdone_method |= TXDONE_BY_ACK; in mbox_request_channel()
346 spin_unlock_irqrestore(&chan->lock, flags); in mbox_request_channel()
348 ret = chan->mbox->ops->startup(chan); in mbox_request_channel()
351 mbox_free_channel(chan); in mbox_request_channel()
352 chan = ERR_PTR(ret); in mbox_request_channel()
356 return chan; in mbox_request_channel()
365 void mbox_free_channel(struct mbox_chan *chan) in mbox_free_channel() argument
369 if (!chan || !chan->cl) in mbox_free_channel()
372 chan->mbox->ops->shutdown(chan); in mbox_free_channel()
375 spin_lock_irqsave(&chan->lock, flags); in mbox_free_channel()
376 chan->cl = NULL; in mbox_free_channel()
377 chan->active_req = NULL; in mbox_free_channel()
378 if (chan->txdone_method == (TXDONE_BY_POLL | TXDONE_BY_ACK)) in mbox_free_channel()
379 chan->txdone_method = TXDONE_BY_POLL; in mbox_free_channel()
381 module_put(chan->mbox->dev->driver->owner); in mbox_free_channel()
382 spin_unlock_irqrestore(&chan->lock, flags); in mbox_free_channel()
426 struct mbox_chan *chan = &mbox->chans[i]; in mbox_controller_register() local
428 chan->cl = NULL; in mbox_controller_register()
429 chan->mbox = mbox; in mbox_controller_register()
430 chan->txdone_method = txdone; in mbox_controller_register()
431 spin_lock_init(&chan->lock); in mbox_controller_register()