summaryrefslogtreecommitdiff
path: root/mac/fproc_vendor.c
blob: f067e163bf500fb0fa749194bdb5198fa64fac63 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * 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"

static void
mcps802154_fproc_vendor_handle_callback_return(struct mcps802154_local *local,
					       int r)
{
	struct mcps802154_access *access = local->fproc.access;
	/* Fetch/copy needed data before access_done.
	 * Avoid usage of access pointer after access done call. */
	int duration_dtu = access->duration_dtu;
	u32 next_access_dtu = access->timestamp_dtu + duration_dtu;
	/* Filter-out the 'stop' request as error. */
	bool error = r != 1;

	if (!r)
		return;

	access->error = r;
	mcps802154_fproc_access_done(local, error);
	if (error) {
		mcps802154_fproc_broken_handle(local);
	} else if (duration_dtu) {
		mcps802154_fproc_access(local, next_access_dtu);
	} else {
		mcps802154_fproc_access_now(local);
	}
}

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

	if (access->vendor_ops->rx_frame)
		r = access->vendor_ops->rx_frame(access);
	else
		r = -EOPNOTSUPP;
	mcps802154_fproc_vendor_handle_callback_return(local, r);
}

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

	if (access->vendor_ops->rx_timeout)
		r = access->vendor_ops->rx_timeout(access);
	else
		r = -EOPNOTSUPP;
	mcps802154_fproc_vendor_handle_callback_return(local, r);
}

static void
mcps802154_fproc_vendor_rx_error(struct mcps802154_local *local,
				 enum mcps802154_rx_error_type error)
{
	struct mcps802154_access *access = local->fproc.access;
	int r;

	if (access->vendor_ops->rx_error)
		r = access->vendor_ops->rx_error(access, error);
	else
		r = -EOPNOTSUPP;
	mcps802154_fproc_vendor_handle_callback_return(local, r);
}

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

	if (access->vendor_ops->tx_done)
		r = access->vendor_ops->tx_done(access);
	else
		r = -EOPNOTSUPP;
	mcps802154_fproc_vendor_handle_callback_return(local, r);
}

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

	if (access->vendor_ops->broken)
		r = access->vendor_ops->broken(access);
	else
		r = -EOPNOTSUPP;
	mcps802154_fproc_vendor_handle_callback_return(local, r);
}

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

	if (access->vendor_ops->timer_expired) {
		int r;

		r = access->vendor_ops->timer_expired(access);
		mcps802154_fproc_vendor_handle_callback_return(local, r);
	}
}

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

	if (access->vendor_ops->schedule_change) {
		int r;

		r = access->vendor_ops->schedule_change(access);
		mcps802154_fproc_vendor_handle_callback_return(local, r);
	}
}

static const struct mcps802154_fproc_state mcps802154_fproc_vendor = {
	.name = "vendor",
	.rx_frame = mcps802154_fproc_vendor_rx_frame,
	.rx_timeout = mcps802154_fproc_vendor_rx_timeout,
	.rx_error = mcps802154_fproc_vendor_rx_error,
	.tx_done = mcps802154_fproc_vendor_tx_done,
	.broken = mcps802154_fproc_vendor_broken,
	.timer_expired = mcps802154_fproc_vendor_timer_expired,
	.schedule_change = mcps802154_fproc_vendor_schedule_change,
};

int mcps802154_fproc_vendor_handle(struct mcps802154_local *local,
				   struct mcps802154_access *access)
{
	mcps802154_fproc_change_state(local, &mcps802154_fproc_vendor);

	if (access->vendor_ops->handle) {
		return access->vendor_ops->handle(access);
	}
	return 0;
}