1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Linux WiMAX
4*4882a593Smuzhiyun * Kernel space API for accessing WiMAX devices
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 2007-2008 Intel Corporation <linux-wimax@intel.com>
7*4882a593Smuzhiyun * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * The WiMAX stack provides an API for controlling and managing the
10*4882a593Smuzhiyun * system's WiMAX devices. This API affects the control plane; the
11*4882a593Smuzhiyun * data plane is accessed via the network stack (netdev).
12*4882a593Smuzhiyun *
13*4882a593Smuzhiyun * Parts of the WiMAX stack API and notifications are exported to
14*4882a593Smuzhiyun * user space via Generic Netlink. In user space, libwimax (part of
15*4882a593Smuzhiyun * the wimax-tools package) provides a shim layer for accessing those
16*4882a593Smuzhiyun * calls.
17*4882a593Smuzhiyun *
18*4882a593Smuzhiyun * The API is standarized for all WiMAX devices and different drivers
19*4882a593Smuzhiyun * implement the backend support for it. However, device-specific
20*4882a593Smuzhiyun * messaging pipes are provided that can be used to issue commands and
21*4882a593Smuzhiyun * receive notifications in free form.
22*4882a593Smuzhiyun *
23*4882a593Smuzhiyun * Currently the messaging pipes are the only means of control as it
24*4882a593Smuzhiyun * is not known (due to the lack of more devices in the market) what
25*4882a593Smuzhiyun * will be a good abstraction layer. Expect this to change as more
26*4882a593Smuzhiyun * devices show in the market. This API is designed to be growable in
27*4882a593Smuzhiyun * order to address this problem.
28*4882a593Smuzhiyun *
29*4882a593Smuzhiyun * USAGE
30*4882a593Smuzhiyun *
31*4882a593Smuzhiyun * Embed a `struct wimax_dev` at the beginning of the device's
32*4882a593Smuzhiyun * private structure, initialize and register it. For details, see
33*4882a593Smuzhiyun * `struct wimax_dev`s documentation.
34*4882a593Smuzhiyun *
35*4882a593Smuzhiyun * Once this is done, wimax-tools's libwimaxll can be used to
36*4882a593Smuzhiyun * communicate with the driver from user space. You user space
37*4882a593Smuzhiyun * application does not have to forcibily use libwimaxll and can talk
38*4882a593Smuzhiyun * the generic netlink protocol directly if desired.
39*4882a593Smuzhiyun *
40*4882a593Smuzhiyun * Remember this is a very low level API that will to provide all of
41*4882a593Smuzhiyun * WiMAX features. Other daemons and services running in user space
42*4882a593Smuzhiyun * are the expected clients of it. They offer a higher level API that
43*4882a593Smuzhiyun * applications should use (an example of this is the Intel's WiMAX
44*4882a593Smuzhiyun * Network Service for the i2400m).
45*4882a593Smuzhiyun *
46*4882a593Smuzhiyun * DESIGN
47*4882a593Smuzhiyun *
48*4882a593Smuzhiyun * Although not set on final stone, this very basic interface is
49*4882a593Smuzhiyun * mostly completed. Remember this is meant to grow as new common
50*4882a593Smuzhiyun * operations are decided upon. New operations will be added to the
51*4882a593Smuzhiyun * interface, intent being on keeping backwards compatibility as much
52*4882a593Smuzhiyun * as possible.
53*4882a593Smuzhiyun *
54*4882a593Smuzhiyun * This layer implements a set of calls to control a WiMAX device,
55*4882a593Smuzhiyun * exposing a frontend to the rest of the kernel and user space (via
56*4882a593Smuzhiyun * generic netlink) and a backend implementation in the driver through
57*4882a593Smuzhiyun * function pointers.
58*4882a593Smuzhiyun *
59*4882a593Smuzhiyun * WiMAX devices have a state, and a kernel-only API allows the
60*4882a593Smuzhiyun * drivers to manipulate that state. State transitions are atomic, and
61*4882a593Smuzhiyun * only some of them are allowed (see `enum wimax_st`).
62*4882a593Smuzhiyun *
63*4882a593Smuzhiyun * Most API calls will set the state automatically; in most cases
64*4882a593Smuzhiyun * drivers have to only report state changes due to external
65*4882a593Smuzhiyun * conditions.
66*4882a593Smuzhiyun *
67*4882a593Smuzhiyun * All API operations are 'atomic', serialized through a mutex in the
68*4882a593Smuzhiyun * `struct wimax_dev`.
69*4882a593Smuzhiyun *
70*4882a593Smuzhiyun * EXPORTING TO USER SPACE THROUGH GENERIC NETLINK
71*4882a593Smuzhiyun *
72*4882a593Smuzhiyun * The API is exported to user space using generic netlink (other
73*4882a593Smuzhiyun * methods can be added as needed).
74*4882a593Smuzhiyun *
75*4882a593Smuzhiyun * There is a Generic Netlink Family named "WiMAX", where interfaces
76*4882a593Smuzhiyun * supporting the WiMAX interface receive commands and broadcast their
77*4882a593Smuzhiyun * signals over a multicast group named "msg".
78*4882a593Smuzhiyun *
79*4882a593Smuzhiyun * Mapping to the source/destination interface is done by an interface
80*4882a593Smuzhiyun * index attribute.
81*4882a593Smuzhiyun *
82*4882a593Smuzhiyun * For user-to-kernel traffic (commands) we use a function call
83*4882a593Smuzhiyun * marshalling mechanism, where a message X with attributes A, B, C
84*4882a593Smuzhiyun * sent from user space to kernel space means executing the WiMAX API
85*4882a593Smuzhiyun * call wimax_X(A, B, C), sending the results back as a message.
86*4882a593Smuzhiyun *
87*4882a593Smuzhiyun * Kernel-to-user (notifications or signals) communication is sent
88*4882a593Smuzhiyun * over multicast groups. This allows to have multiple applications
89*4882a593Smuzhiyun * monitoring them.
90*4882a593Smuzhiyun *
91*4882a593Smuzhiyun * Each command/signal gets assigned it's own attribute policy. This
92*4882a593Smuzhiyun * way the validator will verify that all the attributes in there are
93*4882a593Smuzhiyun * only the ones that should be for each command/signal. Thing of an
94*4882a593Smuzhiyun * attribute mapping to a type+argumentname for each command/signal.
95*4882a593Smuzhiyun *
96*4882a593Smuzhiyun * If we had a single policy for *all* commands/signals, after running
97*4882a593Smuzhiyun * the validator we'd have to check "does this attribute belong in
98*4882a593Smuzhiyun * here"? for each one. It can be done manually, but it's just easier
99*4882a593Smuzhiyun * to have the validator do that job with multiple policies. As well,
100*4882a593Smuzhiyun * it makes it easier to later expand each command/signal signature
101*4882a593Smuzhiyun * without affecting others and keeping the namespace more or less
102*4882a593Smuzhiyun * sane. Not that it is too complicated, but it makes it even easier.
103*4882a593Smuzhiyun *
104*4882a593Smuzhiyun * No state information is maintained in the kernel for each user
105*4882a593Smuzhiyun * space connection (the connection is stateless).
106*4882a593Smuzhiyun *
107*4882a593Smuzhiyun * TESTING FOR THE INTERFACE AND VERSIONING
108*4882a593Smuzhiyun *
109*4882a593Smuzhiyun * If network interface X is a WiMAX device, there will be a Generic
110*4882a593Smuzhiyun * Netlink family named "WiMAX X" and the device will present a
111*4882a593Smuzhiyun * "wimax" directory in it's network sysfs directory
112*4882a593Smuzhiyun * (/sys/class/net/DEVICE/wimax) [used by HAL].
113*4882a593Smuzhiyun *
114*4882a593Smuzhiyun * The inexistence of any of these means the device does not support
115*4882a593Smuzhiyun * this WiMAX API.
116*4882a593Smuzhiyun *
117*4882a593Smuzhiyun * By querying the generic netlink controller, versioning information
118*4882a593Smuzhiyun * and the multicast groups available can be found. Applications using
119*4882a593Smuzhiyun * the interface can either rely on that or use the generic netlink
120*4882a593Smuzhiyun * controller to figure out which generic netlink commands/signals are
121*4882a593Smuzhiyun * supported.
122*4882a593Smuzhiyun *
123*4882a593Smuzhiyun * NOTE: this versioning is a last resort to avoid hard
124*4882a593Smuzhiyun * incompatibilities. It is the intention of the design of this
125*4882a593Smuzhiyun * stack not to introduce backward incompatible changes.
126*4882a593Smuzhiyun *
127*4882a593Smuzhiyun * The version code has to fit in one byte (restrictions imposed by
128*4882a593Smuzhiyun * generic netlink); we use `version / 10` for the major version and
129*4882a593Smuzhiyun * `version % 10` for the minor. This gives 9 minors for each major
130*4882a593Smuzhiyun * and 25 majors.
131*4882a593Smuzhiyun *
132*4882a593Smuzhiyun * The version change protocol is as follow:
133*4882a593Smuzhiyun *
134*4882a593Smuzhiyun * - Major versions: needs to be increased if an existing message/API
135*4882a593Smuzhiyun * call is changed or removed. Doesn't need to be changed if a new
136*4882a593Smuzhiyun * message is added.
137*4882a593Smuzhiyun *
138*4882a593Smuzhiyun * - Minor version: needs to be increased if new messages/API calls are
139*4882a593Smuzhiyun * being added or some other consideration that doesn't impact the
140*4882a593Smuzhiyun * user-kernel interface too much (like some kind of bug fix) and
141*4882a593Smuzhiyun * that is kind of left up in the air to common sense.
142*4882a593Smuzhiyun *
143*4882a593Smuzhiyun * User space code should not try to work if the major version it was
144*4882a593Smuzhiyun * compiled for differs from what the kernel offers. As well, if the
145*4882a593Smuzhiyun * minor version of the kernel interface is lower than the one user
146*4882a593Smuzhiyun * space is expecting (the one it was compiled for), the kernel
147*4882a593Smuzhiyun * might be missing API calls; user space shall be ready to handle
148*4882a593Smuzhiyun * said condition. Use the generic netlink controller operations to
149*4882a593Smuzhiyun * find which ones are supported and which not.
150*4882a593Smuzhiyun *
151*4882a593Smuzhiyun * libwimaxll:wimaxll_open() takes care of checking versions.
152*4882a593Smuzhiyun *
153*4882a593Smuzhiyun * THE OPERATIONS:
154*4882a593Smuzhiyun *
155*4882a593Smuzhiyun * Each operation is defined in its on file (drivers/net/wimax/op-*.c)
156*4882a593Smuzhiyun * for clarity. The parts needed for an operation are:
157*4882a593Smuzhiyun *
158*4882a593Smuzhiyun * - a function pointer in `struct wimax_dev`: optional, as the
159*4882a593Smuzhiyun * operation might be implemented by the stack and not by the
160*4882a593Smuzhiyun * driver.
161*4882a593Smuzhiyun *
162*4882a593Smuzhiyun * All function pointers are named wimax_dev->op_*(), and drivers
163*4882a593Smuzhiyun * must implement them except where noted otherwise.
164*4882a593Smuzhiyun *
165*4882a593Smuzhiyun * - When exported to user space, a `struct nla_policy` to define the
166*4882a593Smuzhiyun * attributes of the generic netlink command and a `struct genl_ops`
167*4882a593Smuzhiyun * to define the operation.
168*4882a593Smuzhiyun *
169*4882a593Smuzhiyun * All the declarations for the operation codes (WIMAX_GNL_OP_<NAME>)
170*4882a593Smuzhiyun * and generic netlink attributes (WIMAX_GNL_<NAME>_*) are declared in
171*4882a593Smuzhiyun * include/linux/wimax.h; this file is intended to be cloned by user
172*4882a593Smuzhiyun * space to gain access to those declarations.
173*4882a593Smuzhiyun *
174*4882a593Smuzhiyun * A few caveats to remember:
175*4882a593Smuzhiyun *
176*4882a593Smuzhiyun * - Need to define attribute numbers starting in 1; otherwise it
177*4882a593Smuzhiyun * fails.
178*4882a593Smuzhiyun *
179*4882a593Smuzhiyun * - the `struct genl_family` requires a maximum attribute id; when
180*4882a593Smuzhiyun * defining the `struct nla_policy` for each message, it has to have
181*4882a593Smuzhiyun * an array size of WIMAX_GNL_ATTR_MAX+1.
182*4882a593Smuzhiyun *
183*4882a593Smuzhiyun * The op_*() function pointers will not be called if the wimax_dev is
184*4882a593Smuzhiyun * in a state <= %WIMAX_ST_UNINITIALIZED. The exception is:
185*4882a593Smuzhiyun *
186*4882a593Smuzhiyun * - op_reset: can be called at any time after wimax_dev_add() has
187*4882a593Smuzhiyun * been called.
188*4882a593Smuzhiyun *
189*4882a593Smuzhiyun * THE PIPE INTERFACE:
190*4882a593Smuzhiyun *
191*4882a593Smuzhiyun * This interface is kept intentionally simple. The driver can send
192*4882a593Smuzhiyun * and receive free-form messages to/from user space through a
193*4882a593Smuzhiyun * pipe. See drivers/net/wimax/op-msg.c for details.
194*4882a593Smuzhiyun *
195*4882a593Smuzhiyun * The kernel-to-user messages are sent with
196*4882a593Smuzhiyun * wimax_msg(). user-to-kernel messages are delivered via
197*4882a593Smuzhiyun * wimax_dev->op_msg_from_user().
198*4882a593Smuzhiyun *
199*4882a593Smuzhiyun * RFKILL:
200*4882a593Smuzhiyun *
201*4882a593Smuzhiyun * RFKILL support is built into the wimax_dev layer; the driver just
202*4882a593Smuzhiyun * needs to call wimax_report_rfkill_{hw,sw}() to inform of changes in
203*4882a593Smuzhiyun * the hardware or software RF kill switches. When the stack wants to
204*4882a593Smuzhiyun * turn the radio off, it will call wimax_dev->op_rfkill_sw_toggle(),
205*4882a593Smuzhiyun * which the driver implements.
206*4882a593Smuzhiyun *
207*4882a593Smuzhiyun * User space can set the software RF Kill switch by calling
208*4882a593Smuzhiyun * wimax_rfkill().
209*4882a593Smuzhiyun *
210*4882a593Smuzhiyun * The code for now only supports devices that don't require polling;
211*4882a593Smuzhiyun * If the device needs to be polled, create a self-rearming delayed
212*4882a593Smuzhiyun * work struct for polling or look into adding polled support to the
213*4882a593Smuzhiyun * WiMAX stack.
214*4882a593Smuzhiyun *
215*4882a593Smuzhiyun * When initializing the hardware (_probe), after calling
216*4882a593Smuzhiyun * wimax_dev_add(), query the device for it's RF Kill switches status
217*4882a593Smuzhiyun * and feed it back to the WiMAX stack using
218*4882a593Smuzhiyun * wimax_report_rfkill_{hw,sw}(). If any switch is missing, always
219*4882a593Smuzhiyun * report it as ON.
220*4882a593Smuzhiyun *
221*4882a593Smuzhiyun * NOTE: the wimax stack uses an inverted terminology to that of the
222*4882a593Smuzhiyun * RFKILL subsystem:
223*4882a593Smuzhiyun *
224*4882a593Smuzhiyun * - ON: radio is ON, RFKILL is DISABLED or OFF.
225*4882a593Smuzhiyun * - OFF: radio is OFF, RFKILL is ENABLED or ON.
226*4882a593Smuzhiyun *
227*4882a593Smuzhiyun * MISCELLANEOUS OPS:
228*4882a593Smuzhiyun *
229*4882a593Smuzhiyun * wimax_reset() can be used to reset the device to power on state; by
230*4882a593Smuzhiyun * default it issues a warm reset that maintains the same device
231*4882a593Smuzhiyun * node. If that is not possible, it falls back to a cold reset
232*4882a593Smuzhiyun * (device reconnect). The driver implements the backend to this
233*4882a593Smuzhiyun * through wimax_dev->op_reset().
234*4882a593Smuzhiyun */
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun #ifndef __NET__WIMAX_H__
237*4882a593Smuzhiyun #define __NET__WIMAX_H__
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun #include <linux/wimax.h>
240*4882a593Smuzhiyun #include <net/genetlink.h>
241*4882a593Smuzhiyun #include <linux/netdevice.h>
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun struct net_device;
244*4882a593Smuzhiyun struct genl_info;
245*4882a593Smuzhiyun struct wimax_dev;
246*4882a593Smuzhiyun
247*4882a593Smuzhiyun /**
248*4882a593Smuzhiyun * struct wimax_dev - Generic WiMAX device
249*4882a593Smuzhiyun *
250*4882a593Smuzhiyun * @net_dev: [fill] Pointer to the &struct net_device this WiMAX
251*4882a593Smuzhiyun * device implements.
252*4882a593Smuzhiyun *
253*4882a593Smuzhiyun * @op_msg_from_user: [fill] Driver-specific operation to
254*4882a593Smuzhiyun * handle a raw message from user space to the driver. The
255*4882a593Smuzhiyun * driver can send messages to user space using with
256*4882a593Smuzhiyun * wimax_msg_to_user().
257*4882a593Smuzhiyun *
258*4882a593Smuzhiyun * @op_rfkill_sw_toggle: [fill] Driver-specific operation to act on
259*4882a593Smuzhiyun * userspace (or any other agent) requesting the WiMAX device to
260*4882a593Smuzhiyun * change the RF Kill software switch (WIMAX_RF_ON or
261*4882a593Smuzhiyun * WIMAX_RF_OFF).
262*4882a593Smuzhiyun * If such hardware support is not present, it is assumed the
263*4882a593Smuzhiyun * radio cannot be switched off and it is always on (and the stack
264*4882a593Smuzhiyun * will error out when trying to switch it off). In such case,
265*4882a593Smuzhiyun * this function pointer can be left as NULL.
266*4882a593Smuzhiyun *
267*4882a593Smuzhiyun * @op_reset: [fill] Driver specific operation to reset the
268*4882a593Smuzhiyun * device.
269*4882a593Smuzhiyun * This operation should always attempt first a warm reset that
270*4882a593Smuzhiyun * does not disconnect the device from the bus and return 0.
271*4882a593Smuzhiyun * If that fails, it should resort to some sort of cold or bus
272*4882a593Smuzhiyun * reset (even if it implies a bus disconnection and device
273*4882a593Smuzhiyun * disappearance). In that case, -ENODEV should be returned to
274*4882a593Smuzhiyun * indicate the device is gone.
275*4882a593Smuzhiyun * This operation has to be synchronous, and return only when the
276*4882a593Smuzhiyun * reset is complete. In case of having had to resort to bus/cold
277*4882a593Smuzhiyun * reset implying a device disconnection, the call is allowed to
278*4882a593Smuzhiyun * return immediately.
279*4882a593Smuzhiyun * NOTE: wimax_dev->mutex is NOT locked when this op is being
280*4882a593Smuzhiyun * called; however, wimax_dev->mutex_reset IS locked to ensure
281*4882a593Smuzhiyun * serialization of calls to wimax_reset().
282*4882a593Smuzhiyun * See wimax_reset()'s documentation.
283*4882a593Smuzhiyun *
284*4882a593Smuzhiyun * @name: [fill] A way to identify this device. We need to register a
285*4882a593Smuzhiyun * name with many subsystems (rfkill, workqueue creation, etc).
286*4882a593Smuzhiyun * We can't use the network device name as that
287*4882a593Smuzhiyun * might change and in some instances we don't know it yet (until
288*4882a593Smuzhiyun * we don't call register_netdev()). So we generate an unique one
289*4882a593Smuzhiyun * using the driver name and device bus id, place it here and use
290*4882a593Smuzhiyun * it across the board. Recommended naming:
291*4882a593Smuzhiyun * DRIVERNAME-BUSNAME:BUSID (dev->bus->name, dev->bus_id).
292*4882a593Smuzhiyun *
293*4882a593Smuzhiyun * @id_table_node: [private] link to the list of wimax devices kept by
294*4882a593Smuzhiyun * id-table.c. Protected by it's own spinlock.
295*4882a593Smuzhiyun *
296*4882a593Smuzhiyun * @mutex: [private] Serializes all concurrent access and execution of
297*4882a593Smuzhiyun * operations.
298*4882a593Smuzhiyun *
299*4882a593Smuzhiyun * @mutex_reset: [private] Serializes reset operations. Needs to be a
300*4882a593Smuzhiyun * different mutex because as part of the reset operation, the
301*4882a593Smuzhiyun * driver has to call back into the stack to do things such as
302*4882a593Smuzhiyun * state change, that require wimax_dev->mutex.
303*4882a593Smuzhiyun *
304*4882a593Smuzhiyun * @state: [private] Current state of the WiMAX device.
305*4882a593Smuzhiyun *
306*4882a593Smuzhiyun * @rfkill: [private] integration into the RF-Kill infrastructure.
307*4882a593Smuzhiyun *
308*4882a593Smuzhiyun * @rf_sw: [private] State of the software radio switch (OFF/ON)
309*4882a593Smuzhiyun *
310*4882a593Smuzhiyun * @rf_hw: [private] State of the hardware radio switch (OFF/ON)
311*4882a593Smuzhiyun *
312*4882a593Smuzhiyun * @debugfs_dentry: [private] Used to hook up a debugfs entry. This
313*4882a593Smuzhiyun * shows up in the debugfs root as wimax\:DEVICENAME.
314*4882a593Smuzhiyun *
315*4882a593Smuzhiyun * Description:
316*4882a593Smuzhiyun * This structure defines a common interface to access all WiMAX
317*4882a593Smuzhiyun * devices from different vendors and provides a common API as well as
318*4882a593Smuzhiyun * a free-form device-specific messaging channel.
319*4882a593Smuzhiyun *
320*4882a593Smuzhiyun * Usage:
321*4882a593Smuzhiyun * 1. Embed a &struct wimax_dev at *the beginning* the network
322*4882a593Smuzhiyun * device structure so that netdev_priv() points to it.
323*4882a593Smuzhiyun *
324*4882a593Smuzhiyun * 2. memset() it to zero
325*4882a593Smuzhiyun *
326*4882a593Smuzhiyun * 3. Initialize with wimax_dev_init(). This will leave the WiMAX
327*4882a593Smuzhiyun * device in the %__WIMAX_ST_NULL state.
328*4882a593Smuzhiyun *
329*4882a593Smuzhiyun * 4. Fill all the fields marked with [fill]; once called
330*4882a593Smuzhiyun * wimax_dev_add(), those fields CANNOT be modified.
331*4882a593Smuzhiyun *
332*4882a593Smuzhiyun * 5. Call wimax_dev_add() *after* registering the network
333*4882a593Smuzhiyun * device. This will leave the WiMAX device in the %WIMAX_ST_DOWN
334*4882a593Smuzhiyun * state.
335*4882a593Smuzhiyun * Protect the driver's net_device->open() against succeeding if
336*4882a593Smuzhiyun * the wimax device state is lower than %WIMAX_ST_DOWN.
337*4882a593Smuzhiyun *
338*4882a593Smuzhiyun * 6. Select when the device is going to be turned on/initialized;
339*4882a593Smuzhiyun * for example, it could be initialized on 'ifconfig up' (when the
340*4882a593Smuzhiyun * netdev op 'open()' is called on the driver).
341*4882a593Smuzhiyun *
342*4882a593Smuzhiyun * When the device is initialized (at `ifconfig up` time, or right
343*4882a593Smuzhiyun * after calling wimax_dev_add() from _probe(), make sure the
344*4882a593Smuzhiyun * following steps are taken
345*4882a593Smuzhiyun *
346*4882a593Smuzhiyun * a. Move the device to %WIMAX_ST_UNINITIALIZED. This is needed so
347*4882a593Smuzhiyun * some API calls that shouldn't work until the device is ready
348*4882a593Smuzhiyun * can be blocked.
349*4882a593Smuzhiyun *
350*4882a593Smuzhiyun * b. Initialize the device. Make sure to turn the SW radio switch
351*4882a593Smuzhiyun * off and move the device to state %WIMAX_ST_RADIO_OFF when
352*4882a593Smuzhiyun * done. When just initialized, a device should be left in RADIO
353*4882a593Smuzhiyun * OFF state until user space devices to turn it on.
354*4882a593Smuzhiyun *
355*4882a593Smuzhiyun * c. Query the device for the state of the hardware rfkill switch
356*4882a593Smuzhiyun * and call wimax_rfkill_report_hw() and wimax_rfkill_report_sw()
357*4882a593Smuzhiyun * as needed. See below.
358*4882a593Smuzhiyun *
359*4882a593Smuzhiyun * wimax_dev_rm() undoes before unregistering the network device. Once
360*4882a593Smuzhiyun * wimax_dev_add() is called, the driver can get called on the
361*4882a593Smuzhiyun * wimax_dev->op_* function pointers
362*4882a593Smuzhiyun *
363*4882a593Smuzhiyun * CONCURRENCY:
364*4882a593Smuzhiyun *
365*4882a593Smuzhiyun * The stack provides a mutex for each device that will disallow API
366*4882a593Smuzhiyun * calls happening concurrently; thus, op calls into the driver
367*4882a593Smuzhiyun * through the wimax_dev->op*() function pointers will always be
368*4882a593Smuzhiyun * serialized and *never* concurrent.
369*4882a593Smuzhiyun *
370*4882a593Smuzhiyun * For locking, take wimax_dev->mutex is taken; (most) operations in
371*4882a593Smuzhiyun * the API have to check for wimax_dev_is_ready() to return 0 before
372*4882a593Smuzhiyun * continuing (this is done internally).
373*4882a593Smuzhiyun *
374*4882a593Smuzhiyun * REFERENCE COUNTING:
375*4882a593Smuzhiyun *
376*4882a593Smuzhiyun * The WiMAX device is reference counted by the associated network
377*4882a593Smuzhiyun * device. The only operation that can be used to reference the device
378*4882a593Smuzhiyun * is wimax_dev_get_by_genl_info(), and the reference it acquires has
379*4882a593Smuzhiyun * to be released with dev_put(wimax_dev->net_dev).
380*4882a593Smuzhiyun *
381*4882a593Smuzhiyun * RFKILL:
382*4882a593Smuzhiyun *
383*4882a593Smuzhiyun * At startup, both HW and SW radio switchess are assumed to be off.
384*4882a593Smuzhiyun *
385*4882a593Smuzhiyun * At initialization time [after calling wimax_dev_add()], have the
386*4882a593Smuzhiyun * driver query the device for the status of the software and hardware
387*4882a593Smuzhiyun * RF kill switches and call wimax_report_rfkill_hw() and
388*4882a593Smuzhiyun * wimax_rfkill_report_sw() to indicate their state. If any is
389*4882a593Smuzhiyun * missing, just call it to indicate it is ON (radio always on).
390*4882a593Smuzhiyun *
391*4882a593Smuzhiyun * Whenever the driver detects a change in the state of the RF kill
392*4882a593Smuzhiyun * switches, it should call wimax_report_rfkill_hw() or
393*4882a593Smuzhiyun * wimax_report_rfkill_sw() to report it to the stack.
394*4882a593Smuzhiyun */
395*4882a593Smuzhiyun struct wimax_dev {
396*4882a593Smuzhiyun struct net_device *net_dev;
397*4882a593Smuzhiyun struct list_head id_table_node;
398*4882a593Smuzhiyun struct mutex mutex; /* Protects all members and API calls */
399*4882a593Smuzhiyun struct mutex mutex_reset;
400*4882a593Smuzhiyun enum wimax_st state;
401*4882a593Smuzhiyun
402*4882a593Smuzhiyun int (*op_msg_from_user)(struct wimax_dev *wimax_dev,
403*4882a593Smuzhiyun const char *,
404*4882a593Smuzhiyun const void *, size_t,
405*4882a593Smuzhiyun const struct genl_info *info);
406*4882a593Smuzhiyun int (*op_rfkill_sw_toggle)(struct wimax_dev *wimax_dev,
407*4882a593Smuzhiyun enum wimax_rf_state);
408*4882a593Smuzhiyun int (*op_reset)(struct wimax_dev *wimax_dev);
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun struct rfkill *rfkill;
411*4882a593Smuzhiyun unsigned int rf_hw;
412*4882a593Smuzhiyun unsigned int rf_sw;
413*4882a593Smuzhiyun char name[32];
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun struct dentry *debugfs_dentry;
416*4882a593Smuzhiyun };
417*4882a593Smuzhiyun
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun /*
421*4882a593Smuzhiyun * WiMAX stack public API for device drivers
422*4882a593Smuzhiyun * -----------------------------------------
423*4882a593Smuzhiyun *
424*4882a593Smuzhiyun * These functions are not exported to user space.
425*4882a593Smuzhiyun */
426*4882a593Smuzhiyun void wimax_dev_init(struct wimax_dev *);
427*4882a593Smuzhiyun int wimax_dev_add(struct wimax_dev *, struct net_device *);
428*4882a593Smuzhiyun void wimax_dev_rm(struct wimax_dev *);
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun static inline
net_dev_to_wimax(struct net_device * net_dev)431*4882a593Smuzhiyun struct wimax_dev *net_dev_to_wimax(struct net_device *net_dev)
432*4882a593Smuzhiyun {
433*4882a593Smuzhiyun return netdev_priv(net_dev);
434*4882a593Smuzhiyun }
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun static inline
wimax_dev_to_dev(struct wimax_dev * wimax_dev)437*4882a593Smuzhiyun struct device *wimax_dev_to_dev(struct wimax_dev *wimax_dev)
438*4882a593Smuzhiyun {
439*4882a593Smuzhiyun return wimax_dev->net_dev->dev.parent;
440*4882a593Smuzhiyun }
441*4882a593Smuzhiyun
442*4882a593Smuzhiyun void wimax_state_change(struct wimax_dev *, enum wimax_st);
443*4882a593Smuzhiyun enum wimax_st wimax_state_get(struct wimax_dev *);
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun /*
446*4882a593Smuzhiyun * Radio Switch state reporting.
447*4882a593Smuzhiyun *
448*4882a593Smuzhiyun * enum wimax_rf_state is declared in linux/wimax.h so the exports
449*4882a593Smuzhiyun * to user space can use it.
450*4882a593Smuzhiyun */
451*4882a593Smuzhiyun void wimax_report_rfkill_hw(struct wimax_dev *, enum wimax_rf_state);
452*4882a593Smuzhiyun void wimax_report_rfkill_sw(struct wimax_dev *, enum wimax_rf_state);
453*4882a593Smuzhiyun
454*4882a593Smuzhiyun
455*4882a593Smuzhiyun /*
456*4882a593Smuzhiyun * Free-form messaging to/from user space
457*4882a593Smuzhiyun *
458*4882a593Smuzhiyun * Sending a message:
459*4882a593Smuzhiyun *
460*4882a593Smuzhiyun * wimax_msg(wimax_dev, pipe_name, buf, buf_size, GFP_KERNEL);
461*4882a593Smuzhiyun *
462*4882a593Smuzhiyun * Broken up:
463*4882a593Smuzhiyun *
464*4882a593Smuzhiyun * skb = wimax_msg_alloc(wimax_dev, pipe_name, buf_size, GFP_KERNEL);
465*4882a593Smuzhiyun * ...fill up skb...
466*4882a593Smuzhiyun * wimax_msg_send(wimax_dev, pipe_name, skb);
467*4882a593Smuzhiyun *
468*4882a593Smuzhiyun * Be sure not to modify skb->data in the middle (ie: don't use
469*4882a593Smuzhiyun * skb_push()/skb_pull()/skb_reserve() on the skb).
470*4882a593Smuzhiyun *
471*4882a593Smuzhiyun * "pipe_name" is any string, that can be interpreted as the name of
472*4882a593Smuzhiyun * the pipe or recipient; the interpretation of it is driver
473*4882a593Smuzhiyun * specific, so the recipient can multiplex it as wished. It can be
474*4882a593Smuzhiyun * NULL, it won't be used - an example is using a "diagnostics" tag to
475*4882a593Smuzhiyun * send diagnostics information that a device-specific diagnostics
476*4882a593Smuzhiyun * tool would be interested in.
477*4882a593Smuzhiyun */
478*4882a593Smuzhiyun struct sk_buff *wimax_msg_alloc(struct wimax_dev *, const char *, const void *,
479*4882a593Smuzhiyun size_t, gfp_t);
480*4882a593Smuzhiyun int wimax_msg_send(struct wimax_dev *, struct sk_buff *);
481*4882a593Smuzhiyun int wimax_msg(struct wimax_dev *, const char *, const void *, size_t, gfp_t);
482*4882a593Smuzhiyun
483*4882a593Smuzhiyun const void *wimax_msg_data_len(struct sk_buff *, size_t *);
484*4882a593Smuzhiyun const void *wimax_msg_data(struct sk_buff *);
485*4882a593Smuzhiyun ssize_t wimax_msg_len(struct sk_buff *);
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun
488*4882a593Smuzhiyun /*
489*4882a593Smuzhiyun * WiMAX stack user space API
490*4882a593Smuzhiyun * --------------------------
491*4882a593Smuzhiyun *
492*4882a593Smuzhiyun * This API is what gets exported to user space for general
493*4882a593Smuzhiyun * operations. As well, they can be called from within the kernel,
494*4882a593Smuzhiyun * (with a properly referenced `struct wimax_dev`).
495*4882a593Smuzhiyun *
496*4882a593Smuzhiyun * Properly referenced means: the 'struct net_device' that embeds the
497*4882a593Smuzhiyun * device's control structure and (as such) the 'struct wimax_dev' is
498*4882a593Smuzhiyun * referenced by the caller.
499*4882a593Smuzhiyun */
500*4882a593Smuzhiyun int wimax_rfkill(struct wimax_dev *, enum wimax_rf_state);
501*4882a593Smuzhiyun int wimax_reset(struct wimax_dev *);
502*4882a593Smuzhiyun
503*4882a593Smuzhiyun #endif /* #ifndef __NET__WIMAX_H__ */
504