gsi.c (94ad8f3ac6aff5acde3f6c4719997efc61e0dccf) gsi.c (6ffddf3b3d182d886d754cfafdf909ccb14f464b)
1// SPDX-License-Identifier: GPL-2.0
2
3/* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
4 * Copyright (C) 2018-2020 Linaro Ltd.
5 */
6
7#include <linux/types.h>
8#include <linux/bits.h>

--- 491 unchanged lines hidden (view full) ---

500 if (state != GSI_CHANNEL_STATE_NOT_ALLOCATED) {
501 dev_err(dev, "channel %u bad state %u before alloc\n",
502 channel_id, state);
503 return -EINVAL;
504 }
505
506 ret = gsi_channel_command(channel, GSI_CH_ALLOCATE);
507
1// SPDX-License-Identifier: GPL-2.0
2
3/* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
4 * Copyright (C) 2018-2020 Linaro Ltd.
5 */
6
7#include <linux/types.h>
8#include <linux/bits.h>

--- 491 unchanged lines hidden (view full) ---

500 if (state != GSI_CHANNEL_STATE_NOT_ALLOCATED) {
501 dev_err(dev, "channel %u bad state %u before alloc\n",
502 channel_id, state);
503 return -EINVAL;
504 }
505
506 ret = gsi_channel_command(channel, GSI_CH_ALLOCATE);
507
508 /* Channel state will normally have been updated */
508 /* If successful the channel state will have changed */
509 state = gsi_channel_state(channel);
509 state = gsi_channel_state(channel);
510 if (!ret && state != GSI_CHANNEL_STATE_ALLOCATED) {
511 dev_err(dev, "channel %u bad state %u after alloc\n",
512 channel_id, state);
513 ret = -EIO;
514 }
510 if (state == GSI_CHANNEL_STATE_ALLOCATED)
511 return 0;
515
512
516 return ret;
513 dev_err(dev, "channel %u bad state %u after alloc\n",
514 channel_id, state);
515
516 return -EIO;
517}
518
519/* Start an ALLOCATED channel */
520static int gsi_channel_start_command(struct gsi_channel *channel)
521{
522 struct device *dev = channel->gsi->dev;
523 enum gsi_channel_state state;
524 int ret;
525
526 state = gsi_channel_state(channel);
527 if (state != GSI_CHANNEL_STATE_ALLOCATED &&
528 state != GSI_CHANNEL_STATE_STOPPED) {
529 dev_err(dev, "channel %u bad state %u before start\n",
530 gsi_channel_id(channel), state);
531 return -EINVAL;
532 }
533
534 ret = gsi_channel_command(channel, GSI_CH_START);
535
517}
518
519/* Start an ALLOCATED channel */
520static int gsi_channel_start_command(struct gsi_channel *channel)
521{
522 struct device *dev = channel->gsi->dev;
523 enum gsi_channel_state state;
524 int ret;
525
526 state = gsi_channel_state(channel);
527 if (state != GSI_CHANNEL_STATE_ALLOCATED &&
528 state != GSI_CHANNEL_STATE_STOPPED) {
529 dev_err(dev, "channel %u bad state %u before start\n",
530 gsi_channel_id(channel), state);
531 return -EINVAL;
532 }
533
534 ret = gsi_channel_command(channel, GSI_CH_START);
535
536 /* Channel state will normally have been updated */
536 /* If successful the channel state will have changed */
537 state = gsi_channel_state(channel);
537 state = gsi_channel_state(channel);
538 if (!ret && state != GSI_CHANNEL_STATE_STARTED) {
539 dev_err(dev, "channel %u bad state %u after start\n",
540 gsi_channel_id(channel), state);
541 ret = -EIO;
542 }
538 if (state == GSI_CHANNEL_STATE_STARTED)
539 return 0;
543
540
544 return ret;
541 dev_err(dev, "channel %u bad state %u after start\n",
542 gsi_channel_id(channel), state);
543
544 return -EIO;
545}
546
547/* Stop a GSI channel in STARTED state */
548static int gsi_channel_stop_command(struct gsi_channel *channel)
549{
550 struct device *dev = channel->gsi->dev;
551 enum gsi_channel_state state;
552 int ret;

--- 10 unchanged lines hidden (view full) ---

563 state != GSI_CHANNEL_STATE_STOP_IN_PROC) {
564 dev_err(dev, "channel %u bad state %u before stop\n",
565 gsi_channel_id(channel), state);
566 return -EINVAL;
567 }
568
569 ret = gsi_channel_command(channel, GSI_CH_STOP);
570
545}
546
547/* Stop a GSI channel in STARTED state */
548static int gsi_channel_stop_command(struct gsi_channel *channel)
549{
550 struct device *dev = channel->gsi->dev;
551 enum gsi_channel_state state;
552 int ret;

--- 10 unchanged lines hidden (view full) ---

563 state != GSI_CHANNEL_STATE_STOP_IN_PROC) {
564 dev_err(dev, "channel %u bad state %u before stop\n",
565 gsi_channel_id(channel), state);
566 return -EINVAL;
567 }
568
569 ret = gsi_channel_command(channel, GSI_CH_STOP);
570
571 /* Channel state will normally have been updated */
571 /* If successful the channel state will have changed */
572 state = gsi_channel_state(channel);
572 state = gsi_channel_state(channel);
573 if (ret || state == GSI_CHANNEL_STATE_STOPPED)
574 return ret;
573 if (state == GSI_CHANNEL_STATE_STOPPED)
574 return 0;
575
576 /* We may have to try again if stop is in progress */
577 if (state == GSI_CHANNEL_STATE_STOP_IN_PROC)
578 return -EAGAIN;
579
580 dev_err(dev, "channel %u bad state %u after stop\n",
581 gsi_channel_id(channel), state);
582

--- 16 unchanged lines hidden (view full) ---

599 if (state != GSI_CHANNEL_STATE_ALLOCATED)
600 dev_err(dev, "channel %u bad state %u before reset\n",
601 gsi_channel_id(channel), state);
602 return;
603 }
604
605 ret = gsi_channel_command(channel, GSI_CH_RESET);
606
575
576 /* We may have to try again if stop is in progress */
577 if (state == GSI_CHANNEL_STATE_STOP_IN_PROC)
578 return -EAGAIN;
579
580 dev_err(dev, "channel %u bad state %u after stop\n",
581 gsi_channel_id(channel), state);
582

--- 16 unchanged lines hidden (view full) ---

599 if (state != GSI_CHANNEL_STATE_ALLOCATED)
600 dev_err(dev, "channel %u bad state %u before reset\n",
601 gsi_channel_id(channel), state);
602 return;
603 }
604
605 ret = gsi_channel_command(channel, GSI_CH_RESET);
606
607 /* Channel state will normally have been updated */
607 /* If successful the channel state will have changed */
608 state = gsi_channel_state(channel);
608 state = gsi_channel_state(channel);
609 if (!ret && state != GSI_CHANNEL_STATE_ALLOCATED)
609 if (state != GSI_CHANNEL_STATE_ALLOCATED)
610 dev_err(dev, "channel %u bad state %u after reset\n",
611 gsi_channel_id(channel), state);
612}
613
614/* Deallocate an ALLOCATED GSI channel */
615static void gsi_channel_de_alloc_command(struct gsi *gsi, u32 channel_id)
616{
617 struct gsi_channel *channel = &gsi->channel[channel_id];

--- 5 unchanged lines hidden (view full) ---

623 if (state != GSI_CHANNEL_STATE_ALLOCATED) {
624 dev_err(dev, "channel %u bad state %u before dealloc\n",
625 channel_id, state);
626 return;
627 }
628
629 ret = gsi_channel_command(channel, GSI_CH_DE_ALLOC);
630
610 dev_err(dev, "channel %u bad state %u after reset\n",
611 gsi_channel_id(channel), state);
612}
613
614/* Deallocate an ALLOCATED GSI channel */
615static void gsi_channel_de_alloc_command(struct gsi *gsi, u32 channel_id)
616{
617 struct gsi_channel *channel = &gsi->channel[channel_id];

--- 5 unchanged lines hidden (view full) ---

623 if (state != GSI_CHANNEL_STATE_ALLOCATED) {
624 dev_err(dev, "channel %u bad state %u before dealloc\n",
625 channel_id, state);
626 return;
627 }
628
629 ret = gsi_channel_command(channel, GSI_CH_DE_ALLOC);
630
631 /* Channel state will normally have been updated */
631 /* If successful the channel state will have changed */
632 state = gsi_channel_state(channel);
632 state = gsi_channel_state(channel);
633 if (!ret && state != GSI_CHANNEL_STATE_NOT_ALLOCATED)
633
634 if (state != GSI_CHANNEL_STATE_NOT_ALLOCATED)
634 dev_err(dev, "channel %u bad state %u after dealloc\n",
635 channel_id, state);
636}
637
638/* Ring an event ring doorbell, reporting the last entry processed by the AP.
639 * The index argument (modulo the ring count) is the first unfilled entry, so
640 * we supply one less than that with the doorbell. Update the event ring
641 * index field with the value provided.

--- 1577 unchanged lines hidden ---
635 dev_err(dev, "channel %u bad state %u after dealloc\n",
636 channel_id, state);
637}
638
639/* Ring an event ring doorbell, reporting the last entry processed by the AP.
640 * The index argument (modulo the ring count) is the first unfilled entry, so
641 * we supply one less than that with the doorbell. Update the event ring
642 * index field with the value provided.

--- 1577 unchanged lines hidden ---