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()
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()
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()
124 for (i = 0; i < mbox->num_chans; i++) { in txdone_hrtimer()
125 struct mbox_chan *chan = &mbox->chans[i]; in txdone_hrtimer()
127 if (chan->active_req && chan->cl) { in txdone_hrtimer()
129 txdone = chan->mbox->ops->last_tx_done(chan); in txdone_hrtimer()
136 hrtimer_forward_now(hrtimer, ms_to_ktime(mbox->txpoll_period)); in txdone_hrtimer()
143 * mbox_chan_received_data - A way for controller driver to push data
155 if (chan->cl->rx_callback) in mbox_chan_received_data()
156 chan->cl->rx_callback(chan->cl, mssg); in mbox_chan_received_data()
161 * mbox_chan_txdone - A way for controller driver to notify the
164 * @r: Status of last TX - OK or ERROR
172 if (unlikely(!(chan->txdone_method & TXDONE_BY_IRQ))) { in mbox_chan_txdone()
173 dev_err(chan->mbox->dev, in mbox_chan_txdone()
183 * mbox_client_txdone - The way for a client to run the TX state machine.
189 * if the controller can't sense TX-Done.
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()
203 * mbox_client_peek_data - A way for client driver to pull data
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()
227 * mbox_send_message - For client to submit a message to be
236 * In non-blocking mode, the requests are buffered by the API and a
237 * non-negative token is returned for each queued request. If the request
238 * is not queued, a negative token is returned. Upon failure or successful
246 * Return: Non-negative integer for successful submission (non-blocking mode)
248 * Negative value denotes failure.
254 if (!chan || !chan->cl) in mbox_send_message()
255 return -EINVAL; in mbox_send_message()
259 dev_err(chan->mbox->dev, "Try increasing MBOX_TX_QUEUE_LEN\n"); 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()
276 t = -ETIME; in mbox_send_message()
286 * mbox_flush - flush a mailbox channel
291 * ->flush() callback to busy loop until a transmission has been completed.
297 * Returns: 0 on success or a negative error code on failure.
303 if (!chan->mbox->ops->flush) in mbox_flush()
304 return -ENOTSUPP; in mbox_flush()
306 ret = chan->mbox->ops->flush(chan, timeout); in mbox_flush()
315 * mbox_request_channel - Request a mailbox channel.
333 struct device *dev = cl->dev; in mbox_request_channel()
340 if (!dev || !dev->of_node) { in mbox_request_channel()
342 return ERR_PTR(-ENODEV); in mbox_request_channel()
347 if (of_parse_phandle_with_args(dev->of_node, "mboxes", in mbox_request_channel()
348 "#mbox-cells", index, &spec)) { in mbox_request_channel()
351 return ERR_PTR(-ENODEV); in mbox_request_channel()
354 chan = ERR_PTR(-EPROBE_DEFER); in mbox_request_channel()
356 if (mbox->dev->of_node == spec.np) { in mbox_request_channel()
357 chan = mbox->of_xlate(mbox, &spec); in mbox_request_channel()
369 if (chan->cl || !try_module_get(mbox->dev->driver->owner)) { in mbox_request_channel()
372 return ERR_PTR(-EBUSY); 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()
405 struct device_node *np = cl->dev->of_node; in mbox_request_channel_byname()
411 dev_err(cl->dev, "%s() currently only supports DT\n", __func__); in mbox_request_channel_byname()
412 return ERR_PTR(-EINVAL); in mbox_request_channel_byname()
415 if (!of_get_property(np, "mbox-names", NULL)) { in mbox_request_channel_byname()
416 dev_err(cl->dev, in mbox_request_channel_byname()
417 "%s() requires an \"mbox-names\" property\n", __func__); in mbox_request_channel_byname()
418 return ERR_PTR(-EINVAL); in mbox_request_channel_byname()
421 of_property_for_each_string(np, "mbox-names", prop, mbox_name) { in mbox_request_channel_byname()
427 dev_err(cl->dev, "%s() could not locate channel named \"%s\"\n", in mbox_request_channel_byname()
429 return ERR_PTR(-EINVAL); in mbox_request_channel_byname()
434 * mbox_free_channel - The client relinquishes control of a mailbox
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()
464 int ind = sp->args[0]; in of_mbox_index_xlate()
466 if (ind >= mbox->num_chans) in of_mbox_index_xlate()
467 return ERR_PTR(-EINVAL); in of_mbox_index_xlate()
469 return &mbox->chans[ind]; in of_mbox_index_xlate()
473 * mbox_controller_register - Register the mailbox controller
483 if (!mbox || !mbox->dev || !mbox->ops || !mbox->num_chans) in mbox_controller_register()
484 return -EINVAL; in mbox_controller_register()
486 if (mbox->txdone_irq) in mbox_controller_register()
488 else if (mbox->txdone_poll) in mbox_controller_register()
495 if (!mbox->ops->last_tx_done) { in mbox_controller_register()
496 dev_err(mbox->dev, "last_tx_done method is absent\n"); in mbox_controller_register()
497 return -EINVAL; in mbox_controller_register()
500 hrtimer_init(&mbox->poll_hrt, CLOCK_MONOTONIC, in mbox_controller_register()
502 mbox->poll_hrt.function = txdone_hrtimer; in mbox_controller_register()
505 for (i = 0; i < mbox->num_chans; i++) { in mbox_controller_register()
506 struct mbox_chan *chan = &mbox->chans[i]; in mbox_controller_register()
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()
514 if (!mbox->of_xlate) in mbox_controller_register()
515 mbox->of_xlate = of_mbox_index_xlate; in mbox_controller_register()
518 list_add_tail(&mbox->node, &mbox_cons); in mbox_controller_register()
526 * mbox_controller_unregister - Unregister the mailbox controller
538 list_del(&mbox->node); in mbox_controller_unregister()
540 for (i = 0; i < mbox->num_chans; i++) in mbox_controller_unregister()
541 mbox_free_channel(&mbox->chans[i]); in mbox_controller_unregister()
543 if (mbox->txdone_poll) in mbox_controller_unregister()
544 hrtimer_cancel(&mbox->poll_hrt); in mbox_controller_unregister()
568 * devm_mbox_controller_register() - managed mbox_controller_register()
572 * This function adds a device-managed resource that will make sure that the
575 * device-managed resources upon driver probe failure or driver removal.
577 * Returns 0 on success or a negative error code on failure.
588 return -ENOMEM; in devm_mbox_controller_register()
604 * devm_mbox_controller_unregister() - managed mbox_controller_unregister()
608 * This function unregisters the mailbox controller and removes the device-