xref: /openbmc/linux/net/mac802154/driver-ops.h (revision e363eca3)
1 #ifndef __MAC802154_DRVIER_OPS
2 #define __MAC802154_DRIVER_OPS
3 
4 #include <linux/types.h>
5 #include <linux/rtnetlink.h>
6 
7 #include <net/mac802154.h>
8 
9 #include "ieee802154_i.h"
10 
11 static inline int
12 drv_xmit_async(struct ieee802154_local *local, struct sk_buff *skb)
13 {
14 	return local->ops->xmit_async(&local->hw, skb);
15 }
16 
17 static inline int
18 drv_xmit_sync(struct ieee802154_local *local, struct sk_buff *skb)
19 {
20 	/* don't allow other operations while sync xmit */
21 	ASSERT_RTNL();
22 
23 	might_sleep();
24 
25 	return local->ops->xmit_sync(&local->hw, skb);
26 }
27 
28 static inline int drv_start(struct ieee802154_local *local)
29 {
30 	might_sleep();
31 
32 	local->started = true;
33 
34 	return local->ops->start(&local->hw);
35 }
36 
37 static inline void drv_stop(struct ieee802154_local *local)
38 {
39 	might_sleep();
40 
41 	local->ops->stop(&local->hw);
42 
43 	local->started = false;
44 }
45 
46 static inline int drv_set_channel(struct ieee802154_local *local,
47 				  const u8 page, const u8 channel)
48 {
49 	might_sleep();
50 
51 	return local->ops->set_channel(&local->hw, page, channel);
52 }
53 
54 static inline int drv_set_tx_power(struct ieee802154_local *local,
55 				   const s8 dbm)
56 {
57 	might_sleep();
58 
59 	if (!local->ops->set_txpower) {
60 		WARN_ON(1);
61 		return -EOPNOTSUPP;
62 	}
63 
64 	return local->ops->set_txpower(&local->hw, dbm);
65 }
66 
67 static inline int drv_set_cca_mode(struct ieee802154_local *local,
68 				   const u8 cca_mode)
69 {
70 	might_sleep();
71 
72 	if (!local->ops->set_cca_mode) {
73 		WARN_ON(1);
74 		return -EOPNOTSUPP;
75 	}
76 
77 	return local->ops->set_cca_mode(&local->hw, cca_mode);
78 }
79 
80 static inline int drv_set_lbt_mode(struct ieee802154_local *local,
81 				   const bool mode)
82 {
83 	might_sleep();
84 
85 	if (!local->ops->set_lbt) {
86 		WARN_ON(1);
87 		return -EOPNOTSUPP;
88 	}
89 
90 	return local->ops->set_lbt(&local->hw, mode);
91 }
92 
93 static inline int drv_set_cca_ed_level(struct ieee802154_local *local,
94 				       const s32 ed_level)
95 {
96 	might_sleep();
97 
98 	if (!local->ops->set_cca_ed_level) {
99 		WARN_ON(1);
100 		return -EOPNOTSUPP;
101 	}
102 
103 	return local->ops->set_cca_ed_level(&local->hw, ed_level);
104 }
105 
106 static inline int drv_set_pan_id(struct ieee802154_local *local,
107 				 const __le16 pan_id)
108 {
109 	struct ieee802154_hw_addr_filt filt;
110 
111 	might_sleep();
112 
113 	if (!local->ops->set_hw_addr_filt) {
114 		WARN_ON(1);
115 		return -EOPNOTSUPP;
116 	}
117 
118 	filt.pan_id = pan_id;
119 
120 	return local->ops->set_hw_addr_filt(&local->hw, &filt,
121 					    IEEE802154_AFILT_PANID_CHANGED);
122 }
123 
124 static inline int drv_set_extended_addr(struct ieee802154_local *local,
125 					const __le64 extended_addr)
126 {
127 	struct ieee802154_hw_addr_filt filt;
128 
129 	might_sleep();
130 
131 	if (!local->ops->set_hw_addr_filt) {
132 		WARN_ON(1);
133 		return -EOPNOTSUPP;
134 	}
135 
136 	filt.ieee_addr = extended_addr;
137 
138 	return local->ops->set_hw_addr_filt(&local->hw, &filt,
139 					    IEEE802154_AFILT_IEEEADDR_CHANGED);
140 }
141 
142 static inline int drv_set_short_addr(struct ieee802154_local *local,
143 				     const __le16 short_addr)
144 {
145 	struct ieee802154_hw_addr_filt filt;
146 
147 	might_sleep();
148 
149 	if (!local->ops->set_hw_addr_filt) {
150 		WARN_ON(1);
151 		return -EOPNOTSUPP;
152 	}
153 
154 	filt.short_addr = short_addr;
155 
156 	return local->ops->set_hw_addr_filt(&local->hw, &filt,
157 					    IEEE802154_AFILT_SADDR_CHANGED);
158 }
159 
160 static inline int drv_set_pan_coord(struct ieee802154_local *local,
161 				    const bool is_coord)
162 {
163 	struct ieee802154_hw_addr_filt filt;
164 
165 	might_sleep();
166 
167 	if (!local->ops->set_hw_addr_filt) {
168 		WARN_ON(1);
169 		return -EOPNOTSUPP;
170 	}
171 
172 	filt.pan_coord = is_coord;
173 
174 	return local->ops->set_hw_addr_filt(&local->hw, &filt,
175 					    IEEE802154_AFILT_PANC_CHANGED);
176 }
177 
178 static inline int drv_set_csma_params(struct ieee802154_local *local,
179 				      u8 min_be, u8 max_be,
180 				      u8 max_csma_backoffs)
181 {
182 	might_sleep();
183 
184 	if (!local->ops->set_csma_params) {
185 		WARN_ON(1);
186 		return -EOPNOTSUPP;
187 	}
188 
189 	return local->ops->set_csma_params(&local->hw, min_be, max_be,
190 					   max_csma_backoffs);
191 }
192 
193 static inline int drv_set_max_frame_retries(struct ieee802154_local *local,
194 					    s8 max_frame_retries)
195 {
196 	might_sleep();
197 
198 	if (!local->ops->set_frame_retries) {
199 		WARN_ON(1);
200 		return -EOPNOTSUPP;
201 	}
202 
203 	return local->ops->set_frame_retries(&local->hw, max_frame_retries);
204 }
205 
206 #endif /* __MAC802154_DRVIER_OPS */
207