Lines Matching +full:non +full:- +full:negative

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2013-2014 Linaro Ltd.
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()
36 return -ENOBUFS; 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()
43 if (idx == MBOX_TX_QUEUE_LEN - 1) 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()
58 int err = -EBUSY; in msg_submit()
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()
68 idx -= count; in msg_submit()
70 idx += MBOX_TX_QUEUE_LEN - count; 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 spin_lock_irqsave(&chan->mbox->poll_hrt_lock, flags); in msg_submit()
88 hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL); in msg_submit()
89 spin_unlock_irqrestore(&chan->mbox->poll_hrt_lock, flags); in msg_submit()
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()
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 for (i = 0; i < mbox->num_chans; i++) { in txdone_hrtimer()
126 struct mbox_chan *chan = &mbox->chans[i]; in txdone_hrtimer()
128 if (chan->active_req && chan->cl) { in txdone_hrtimer()
129 txdone = chan->mbox->ops->last_tx_done(chan); in txdone_hrtimer()
138 spin_lock_irqsave(&mbox->poll_hrt_lock, flags); in txdone_hrtimer()
140 hrtimer_forward_now(hrtimer, ms_to_ktime(mbox->txpoll_period)); in txdone_hrtimer()
141 spin_unlock_irqrestore(&mbox->poll_hrt_lock, flags); in txdone_hrtimer()
149 * mbox_chan_received_data - A way for controller driver to push data
161 if (chan->cl->rx_callback) in mbox_chan_received_data()
162 chan->cl->rx_callback(chan->cl, mssg); in mbox_chan_received_data()
167 * mbox_chan_txdone - A way for controller driver to notify the
170 * @r: Status of last TX - OK or ERROR
178 if (unlikely(!(chan->txdone_method & TXDONE_BY_IRQ))) { in mbox_chan_txdone()
179 dev_err(chan->mbox->dev, in mbox_chan_txdone()
189 * mbox_client_txdone - The way for a client to run the TX state machine.
195 * if the controller can't sense TX-Done.
199 if (unlikely(!(chan->txdone_method & TXDONE_BY_ACK))) { in mbox_client_txdone()
200 dev_err(chan->mbox->dev, "Client can't run the TX ticker\n"); in mbox_client_txdone()
209 * mbox_client_peek_data - A way for client driver to pull data
225 if (chan->mbox->ops->peek_data) in mbox_client_peek_data()
226 return chan->mbox->ops->peek_data(chan); in mbox_client_peek_data()
233 * mbox_send_message - For client to submit a message to be
242 * In non-blocking mode, the requests are buffered by the API and a
243 * non-negative token is returned for each queued request. If the request
244 * is not queued, a negative token is returned. Upon failure or successful
252 * Return: Non-negative integer for successful submission (non-blocking mode)
254 * Negative value denotes failure.
260 if (!chan || !chan->cl) in mbox_send_message()
261 return -EINVAL; in mbox_send_message()
265 dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n"); in mbox_send_message()
271 if (chan->cl->tx_block) { in mbox_send_message()
275 if (!chan->cl->tx_tout) /* wait forever */ in mbox_send_message()
278 wait = msecs_to_jiffies(chan->cl->tx_tout); in mbox_send_message()
280 ret = wait_for_completion_timeout(&chan->tx_complete, wait); in mbox_send_message()
282 t = -ETIME; in mbox_send_message()
292 * mbox_flush - flush a mailbox channel
297 * ->flush() callback to busy loop until a transmission has been completed.
303 * Returns: 0 on success or a negative error code on failure.
309 if (!chan->mbox->ops->flush) in mbox_flush()
310 return -ENOTSUPP; in mbox_flush()
312 ret = chan->mbox->ops->flush(chan, timeout); in mbox_flush()
321 * mbox_request_channel - Request a mailbox channel.
339 struct device *dev = cl->dev; in mbox_request_channel()
346 if (!dev || !dev->of_node) { in mbox_request_channel()
348 return ERR_PTR(-ENODEV); in mbox_request_channel()
353 if (of_parse_phandle_with_args(dev->of_node, "mboxes", in mbox_request_channel()
354 "#mbox-cells", index, &spec)) { in mbox_request_channel()
357 return ERR_PTR(-ENODEV); in mbox_request_channel()
360 chan = ERR_PTR(-EPROBE_DEFER); in mbox_request_channel()
362 if (mbox->dev->of_node == spec.np) { in mbox_request_channel()
363 chan = mbox->of_xlate(mbox, &spec); in mbox_request_channel()
375 if (chan->cl || !try_module_get(mbox->dev->driver->owner)) { in mbox_request_channel()
378 return ERR_PTR(-EBUSY); in mbox_request_channel()
381 spin_lock_irqsave(&chan->lock, flags); in mbox_request_channel()
382 chan->msg_free = 0; in mbox_request_channel()
383 chan->msg_count = 0; in mbox_request_channel()
384 chan->active_req = NULL; in mbox_request_channel()
385 chan->cl = cl; in mbox_request_channel()
386 init_completion(&chan->tx_complete); in mbox_request_channel()
388 if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) in mbox_request_channel()
389 chan->txdone_method = TXDONE_BY_ACK; in mbox_request_channel()
391 spin_unlock_irqrestore(&chan->lock, flags); in mbox_request_channel()
393 if (chan->mbox->ops->startup) { in mbox_request_channel()
394 ret = chan->mbox->ops->startup(chan); in mbox_request_channel()
411 struct device_node *np = cl->dev->of_node; in mbox_request_channel_byname()
417 dev_err(cl->dev, "%s() currently only supports DT\n", __func__); in mbox_request_channel_byname()
418 return ERR_PTR(-EINVAL); in mbox_request_channel_byname()
421 if (!of_get_property(np, "mbox-names", NULL)) { in mbox_request_channel_byname()
422 dev_err(cl->dev, in mbox_request_channel_byname()
423 "%s() requires an \"mbox-names\" property\n", __func__); in mbox_request_channel_byname()
424 return ERR_PTR(-EINVAL); in mbox_request_channel_byname()
427 of_property_for_each_string(np, "mbox-names", prop, mbox_name) { in mbox_request_channel_byname()
433 dev_err(cl->dev, "%s() could not locate channel named \"%s\"\n", in mbox_request_channel_byname()
435 return ERR_PTR(-EINVAL); in mbox_request_channel_byname()
440 * mbox_free_channel - The client relinquishes control of a mailbox
448 if (!chan || !chan->cl) in mbox_free_channel()
451 if (chan->mbox->ops->shutdown) in mbox_free_channel()
452 chan->mbox->ops->shutdown(chan); in mbox_free_channel()
455 spin_lock_irqsave(&chan->lock, flags); in mbox_free_channel()
456 chan->cl = NULL; in mbox_free_channel()
457 chan->active_req = NULL; in mbox_free_channel()
458 if (chan->txdone_method == TXDONE_BY_ACK) in mbox_free_channel()
459 chan->txdone_method = TXDONE_BY_POLL; in mbox_free_channel()
461 module_put(chan->mbox->dev->driver->owner); in mbox_free_channel()
462 spin_unlock_irqrestore(&chan->lock, flags); in mbox_free_channel()
470 int ind = sp->args[0]; in of_mbox_index_xlate()
472 if (ind >= mbox->num_chans) in of_mbox_index_xlate()
473 return ERR_PTR(-EINVAL); in of_mbox_index_xlate()
475 return &mbox->chans[ind]; in of_mbox_index_xlate()
479 * mbox_controller_register - Register the mailbox controller
489 if (!mbox || !mbox->dev || !mbox->ops || !mbox->num_chans) in mbox_controller_register()
490 return -EINVAL; in mbox_controller_register()
492 if (mbox->txdone_irq) in mbox_controller_register()
494 else if (mbox->txdone_poll) in mbox_controller_register()
501 if (!mbox->ops->last_tx_done) { in mbox_controller_register()
502 dev_err(mbox->dev, "last_tx_done method is absent\n"); in mbox_controller_register()
503 return -EINVAL; in mbox_controller_register()
506 hrtimer_init(&mbox->poll_hrt, CLOCK_MONOTONIC, in mbox_controller_register()
508 mbox->poll_hrt.function = txdone_hrtimer; in mbox_controller_register()
509 spin_lock_init(&mbox->poll_hrt_lock); in mbox_controller_register()
512 for (i = 0; i < mbox->num_chans; i++) { in mbox_controller_register()
513 struct mbox_chan *chan = &mbox->chans[i]; in mbox_controller_register()
515 chan->cl = NULL; in mbox_controller_register()
516 chan->mbox = mbox; in mbox_controller_register()
517 chan->txdone_method = txdone; in mbox_controller_register()
518 spin_lock_init(&chan->lock); in mbox_controller_register()
521 if (!mbox->of_xlate) in mbox_controller_register()
522 mbox->of_xlate = of_mbox_index_xlate; in mbox_controller_register()
525 list_add_tail(&mbox->node, &mbox_cons); in mbox_controller_register()
533 * mbox_controller_unregister - Unregister the mailbox controller
545 list_del(&mbox->node); in mbox_controller_unregister()
547 for (i = 0; i < mbox->num_chans; i++) in mbox_controller_unregister()
548 mbox_free_channel(&mbox->chans[i]); in mbox_controller_unregister()
550 if (mbox->txdone_poll) in mbox_controller_unregister()
551 hrtimer_cancel(&mbox->poll_hrt); in mbox_controller_unregister()
575 * devm_mbox_controller_register() - managed mbox_controller_register()
579 * This function adds a device-managed resource that will make sure that the
582 * device-managed resources upon driver probe failure or driver removal.
584 * Returns 0 on success or a negative error code on failure.
595 return -ENOMEM; in devm_mbox_controller_register()
611 * devm_mbox_controller_unregister() - managed mbox_controller_unregister()
615 * This function unregisters the mailbox controller and removes the device-