summaryrefslogtreecommitdiff
path: root/mac/fproc_rx.c
blob: cfa2b7b1238c0a338779dcc7534f8bfd851ff0ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * This file is part of the UWB stack for linux.
 *
 * Copyright (c) 2020-2021 Qorvo US, Inc.
 *
 * This software is provided under the GNU General Public License, version 2
 * (GPLv2), as well as under a Qorvo commercial license.
 *
 * You may choose to use this software under the terms of the GPLv2 License,
 * version 2 ("GPLv2"), as published by the Free Software Foundation.
 * You should have received a copy of the GPLv2 along with this program.  If
 * not, see <http://www.gnu.org/licenses/>.
 *
 * This program is distributed under the GPLv2 in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GPLv2 for more
 * details.
 *
 * If you cannot meet the requirements of the GPLv2, you may not use this
 * software for any purpose without first obtaining a commercial license from
 * Qorvo. Please contact Qorvo to inquire about licensing terms.
 */
#include <linux/errno.h>

#include "mcps802154_i.h"
#include "llhw-ops.h"

static void
mcps802154_fproc_rx_wait_tx_done_tx_done(struct mcps802154_local *local)
{
	/* End current access and ask for next one. */
	mcps802154_fproc_access_done(local, false);
	mcps802154_fproc_access_now(local);
}

static void
mcps802154_fproc_rx_wait_tx_done_schedule_change(struct mcps802154_local *local)
{
	/* Nothing, wait for tx_done. */
}

static const struct mcps802154_fproc_state mcps802154_fproc_rx_wait_tx_done = {
	.name = "rx_wait_tx_done",
	.tx_done = mcps802154_fproc_rx_wait_tx_done_tx_done,
	.schedule_change = mcps802154_fproc_rx_wait_tx_done_schedule_change,
};

static void mcps802154_fproc_rx_rx_frame(struct mcps802154_local *local)
{
	struct mcps802154_access *access = local->fproc.access;
	int r;

	/* Read frame. */
	struct sk_buff *skb = NULL;
	struct mcps802154_rx_frame_info info = {
		.flags = MCPS802154_RX_FRAME_INFO_LQI,
	};
	r = llhw_rx_get_frame(local, &skb, &info);
	if (!r) {
		access->ops->rx_frame(access, 0, skb, &info,
				      MCPS802154_RX_ERROR_NONE);
		/* If auto-ack was sent, wait for tx_done. */
		if (info.flags & MCPS802154_RX_FRAME_INFO_AACK) {
			mcps802154_fproc_change_state(
				local, &mcps802154_fproc_rx_wait_tx_done);
			return;
		}
	}
	mcps802154_fproc_access_done(local, !!r);

	if (r && r != -EBUSY)
		mcps802154_fproc_broken_handle(local);
	else
		/* Next access. */
		mcps802154_fproc_access_now(local);
}

static void mcps802154_fproc_rx_rx_error(struct mcps802154_local *local,
					 enum mcps802154_rx_error_type error)
{
	mcps802154_fproc_access_done(local, true);

	/* Next access. */
	mcps802154_fproc_access_now(local);
}

static void mcps802154_fproc_rx_schedule_change(struct mcps802154_local *local)
{
	int r;

	/* Disable RX. */
	r = llhw_rx_disable(local);
	if (r == -EBUSY)
		/* Wait for RX result. */
		return;

	mcps802154_fproc_access_done(local, !!r);
	if (r)
		mcps802154_fproc_broken_handle(local);
	else
		/* Next access. */
		mcps802154_fproc_access_now(local);
}

static const struct mcps802154_fproc_state mcps802154_fproc_rx = {
	.name = "rx",
	.rx_frame = mcps802154_fproc_rx_rx_frame,
	.rx_error = mcps802154_fproc_rx_rx_error,
	.schedule_change = mcps802154_fproc_rx_schedule_change,
};

int mcps802154_fproc_rx_handle(struct mcps802154_local *local,
			       struct mcps802154_access *access)
{
	int r;
	struct mcps802154_rx_info rx_info = {
		.flags = MCPS802154_RX_INFO_AACK,
		.timeout_dtu = -1,
	};
	r = llhw_rx_enable(local, &rx_info, 0, 0);
	if (r)
		return r;

	mcps802154_fproc_change_state(local, &mcps802154_fproc_rx);

	return 0;
}