1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Intel Wireless WiMAX Connection 2400m
3*4882a593Smuzhiyun * Declarations for bus-generic internal APIs
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or without
9*4882a593Smuzhiyun * modification, are permitted provided that the following conditions
10*4882a593Smuzhiyun * are met:
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * * Redistributions of source code must retain the above copyright
13*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer.
14*4882a593Smuzhiyun * * Redistributions in binary form must reproduce the above copyright
15*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer in
16*4882a593Smuzhiyun * the documentation and/or other materials provided with the
17*4882a593Smuzhiyun * distribution.
18*4882a593Smuzhiyun * * Neither the name of Intel Corporation nor the names of its
19*4882a593Smuzhiyun * contributors may be used to endorse or promote products derived
20*4882a593Smuzhiyun * from this software without specific prior written permission.
21*4882a593Smuzhiyun *
22*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23*4882a593Smuzhiyun * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24*4882a593Smuzhiyun * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25*4882a593Smuzhiyun * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26*4882a593Smuzhiyun * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27*4882a593Smuzhiyun * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28*4882a593Smuzhiyun * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29*4882a593Smuzhiyun * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30*4882a593Smuzhiyun * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31*4882a593Smuzhiyun * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32*4882a593Smuzhiyun * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33*4882a593Smuzhiyun *
34*4882a593Smuzhiyun *
35*4882a593Smuzhiyun * Intel Corporation <linux-wimax@intel.com>
36*4882a593Smuzhiyun * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
37*4882a593Smuzhiyun * Yanir Lubetkin <yanirx.lubetkin@intel.com>
38*4882a593Smuzhiyun * - Initial implementation
39*4882a593Smuzhiyun *
40*4882a593Smuzhiyun *
41*4882a593Smuzhiyun * GENERAL DRIVER ARCHITECTURE
42*4882a593Smuzhiyun *
43*4882a593Smuzhiyun * The i2400m driver is split in the following two major parts:
44*4882a593Smuzhiyun *
45*4882a593Smuzhiyun * - bus specific driver
46*4882a593Smuzhiyun * - bus generic driver (this part)
47*4882a593Smuzhiyun *
48*4882a593Smuzhiyun * The bus specific driver sets up stuff specific to the bus the
49*4882a593Smuzhiyun * device is connected to (USB, PCI, tam-tam...non-authoritative
50*4882a593Smuzhiyun * nor binding list) which is basically the device-model management
51*4882a593Smuzhiyun * (probe/disconnect, etc), moving data from device to kernel and
52*4882a593Smuzhiyun * back, doing the power saving details and reseting the device.
53*4882a593Smuzhiyun *
54*4882a593Smuzhiyun * For details on each bus-specific driver, see it's include file,
55*4882a593Smuzhiyun * i2400m-BUSNAME.h
56*4882a593Smuzhiyun *
57*4882a593Smuzhiyun * The bus-generic functionality break up is:
58*4882a593Smuzhiyun *
59*4882a593Smuzhiyun * - Firmware upload: fw.c - takes care of uploading firmware to the
60*4882a593Smuzhiyun * device. bus-specific driver just needs to provides a way to
61*4882a593Smuzhiyun * execute boot-mode commands and to reset the device.
62*4882a593Smuzhiyun *
63*4882a593Smuzhiyun * - RX handling: rx.c - receives data from the bus-specific code and
64*4882a593Smuzhiyun * feeds it to the network or WiMAX stack or uses it to modify
65*4882a593Smuzhiyun * the driver state. bus-specific driver only has to receive
66*4882a593Smuzhiyun * frames and pass them to this module.
67*4882a593Smuzhiyun *
68*4882a593Smuzhiyun * - TX handling: tx.c - manages the TX FIFO queue and provides means
69*4882a593Smuzhiyun * for the bus-specific TX code to pull data from the FIFO
70*4882a593Smuzhiyun * queue. bus-specific code just pulls frames from this module
71*4882a593Smuzhiyun * to sends them to the device.
72*4882a593Smuzhiyun *
73*4882a593Smuzhiyun * - netdev glue: netdev.c - interface with Linux networking
74*4882a593Smuzhiyun * stack. Pass around data frames, and configure when the
75*4882a593Smuzhiyun * device is up and running or shutdown (through ifconfig up /
76*4882a593Smuzhiyun * down). Bus-generic only.
77*4882a593Smuzhiyun *
78*4882a593Smuzhiyun * - control ops: control.c - implements various commands for
79*4882a593Smuzhiyun * controlling the device. bus-generic only.
80*4882a593Smuzhiyun *
81*4882a593Smuzhiyun * - device model glue: driver.c - implements helpers for the
82*4882a593Smuzhiyun * device-model glue done by the bus-specific layer
83*4882a593Smuzhiyun * (setup/release the driver resources), turning the device on
84*4882a593Smuzhiyun * and off, handling the device reboots/resets and a few simple
85*4882a593Smuzhiyun * WiMAX stack ops.
86*4882a593Smuzhiyun *
87*4882a593Smuzhiyun * Code is also broken up in linux-glue / device-glue.
88*4882a593Smuzhiyun *
89*4882a593Smuzhiyun * Linux glue contains functions that deal mostly with gluing with the
90*4882a593Smuzhiyun * rest of the Linux kernel.
91*4882a593Smuzhiyun *
92*4882a593Smuzhiyun * Device-glue are functions that deal mostly with the way the device
93*4882a593Smuzhiyun * does things and talk the device's language.
94*4882a593Smuzhiyun *
95*4882a593Smuzhiyun * device-glue code is licensed BSD so other open source OSes can take
96*4882a593Smuzhiyun * it to implement their drivers.
97*4882a593Smuzhiyun *
98*4882a593Smuzhiyun *
99*4882a593Smuzhiyun * APIs AND HEADER FILES
100*4882a593Smuzhiyun *
101*4882a593Smuzhiyun * This bus generic code exports three APIs:
102*4882a593Smuzhiyun *
103*4882a593Smuzhiyun * - HDI (host-device interface) definitions common to all busses
104*4882a593Smuzhiyun * (include/linux/wimax/i2400m.h); these can be also used by user
105*4882a593Smuzhiyun * space code.
106*4882a593Smuzhiyun * - internal API for the bus-generic code
107*4882a593Smuzhiyun * - external API for the bus-specific drivers
108*4882a593Smuzhiyun *
109*4882a593Smuzhiyun *
110*4882a593Smuzhiyun * LIFE CYCLE:
111*4882a593Smuzhiyun *
112*4882a593Smuzhiyun * When the bus-specific driver probes, it allocates a network device
113*4882a593Smuzhiyun * with enough space for it's data structue, that must contain a
114*4882a593Smuzhiyun * &struct i2400m at the top.
115*4882a593Smuzhiyun *
116*4882a593Smuzhiyun * On probe, it needs to fill the i2400m members marked as [fill], as
117*4882a593Smuzhiyun * well as i2400m->wimax_dev.net_dev and call i2400m_setup(). The
118*4882a593Smuzhiyun * i2400m driver will only register with the WiMAX and network stacks;
119*4882a593Smuzhiyun * the only access done to the device is to read the MAC address so we
120*4882a593Smuzhiyun * can register a network device.
121*4882a593Smuzhiyun *
122*4882a593Smuzhiyun * The high-level call flow is:
123*4882a593Smuzhiyun *
124*4882a593Smuzhiyun * bus_probe()
125*4882a593Smuzhiyun * i2400m_setup()
126*4882a593Smuzhiyun * i2400m->bus_setup()
127*4882a593Smuzhiyun * boot rom initialization / read mac addr
128*4882a593Smuzhiyun * network / WiMAX stacks registration
129*4882a593Smuzhiyun * i2400m_dev_start()
130*4882a593Smuzhiyun * i2400m->bus_dev_start()
131*4882a593Smuzhiyun * i2400m_dev_initialize()
132*4882a593Smuzhiyun *
133*4882a593Smuzhiyun * The reverse applies for a disconnect() call:
134*4882a593Smuzhiyun *
135*4882a593Smuzhiyun * bus_disconnect()
136*4882a593Smuzhiyun * i2400m_release()
137*4882a593Smuzhiyun * i2400m_dev_stop()
138*4882a593Smuzhiyun * i2400m_dev_shutdown()
139*4882a593Smuzhiyun * i2400m->bus_dev_stop()
140*4882a593Smuzhiyun * network / WiMAX stack unregistration
141*4882a593Smuzhiyun * i2400m->bus_release()
142*4882a593Smuzhiyun *
143*4882a593Smuzhiyun * At this point, control and data communications are possible.
144*4882a593Smuzhiyun *
145*4882a593Smuzhiyun * While the device is up, it might reset. The bus-specific driver has
146*4882a593Smuzhiyun * to catch that situation and call i2400m_dev_reset_handle() to deal
147*4882a593Smuzhiyun * with it (reset the internal driver structures and go back to square
148*4882a593Smuzhiyun * one).
149*4882a593Smuzhiyun */
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun #ifndef __I2400M_H__
152*4882a593Smuzhiyun #define __I2400M_H__
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun #include <linux/usb.h>
155*4882a593Smuzhiyun #include <linux/netdevice.h>
156*4882a593Smuzhiyun #include <linux/completion.h>
157*4882a593Smuzhiyun #include <linux/rwsem.h>
158*4882a593Smuzhiyun #include <linux/atomic.h>
159*4882a593Smuzhiyun #include <net/wimax.h>
160*4882a593Smuzhiyun #include <linux/wimax/i2400m.h>
161*4882a593Smuzhiyun #include <asm/byteorder.h>
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun enum {
164*4882a593Smuzhiyun /* netdev interface */
165*4882a593Smuzhiyun /*
166*4882a593Smuzhiyun * Out of NWG spec (R1_v1.2.2), 3.3.3 ASN Bearer Plane MTU Size
167*4882a593Smuzhiyun *
168*4882a593Smuzhiyun * The MTU is 1400 or less
169*4882a593Smuzhiyun */
170*4882a593Smuzhiyun I2400M_MAX_MTU = 1400,
171*4882a593Smuzhiyun };
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun /* Misc constants */
174*4882a593Smuzhiyun enum {
175*4882a593Smuzhiyun /* Size of the Boot Mode Command buffer */
176*4882a593Smuzhiyun I2400M_BM_CMD_BUF_SIZE = 16 * 1024,
177*4882a593Smuzhiyun I2400M_BM_ACK_BUF_SIZE = 256,
178*4882a593Smuzhiyun };
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun enum {
181*4882a593Smuzhiyun /* Maximum number of bus reset can be retried */
182*4882a593Smuzhiyun I2400M_BUS_RESET_RETRIES = 3,
183*4882a593Smuzhiyun };
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun /**
186*4882a593Smuzhiyun * struct i2400m_poke_table - Hardware poke table for the Intel 2400m
187*4882a593Smuzhiyun *
188*4882a593Smuzhiyun * This structure will be used to create a device specific poke table
189*4882a593Smuzhiyun * to put the device in a consistent state at boot time.
190*4882a593Smuzhiyun *
191*4882a593Smuzhiyun * @address: The device address to poke
192*4882a593Smuzhiyun *
193*4882a593Smuzhiyun * @data: The data value to poke to the device address
194*4882a593Smuzhiyun *
195*4882a593Smuzhiyun */
196*4882a593Smuzhiyun struct i2400m_poke_table{
197*4882a593Smuzhiyun __le32 address;
198*4882a593Smuzhiyun __le32 data;
199*4882a593Smuzhiyun };
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun #define I2400M_FW_POKE(a, d) { \
202*4882a593Smuzhiyun .address = cpu_to_le32(a), \
203*4882a593Smuzhiyun .data = cpu_to_le32(d) \
204*4882a593Smuzhiyun }
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun /**
208*4882a593Smuzhiyun * i2400m_reset_type - methods to reset a device
209*4882a593Smuzhiyun *
210*4882a593Smuzhiyun * @I2400M_RT_WARM: Reset without device disconnection, device handles
211*4882a593Smuzhiyun * are kept valid but state is back to power on, with firmware
212*4882a593Smuzhiyun * re-uploaded.
213*4882a593Smuzhiyun * @I2400M_RT_COLD: Tell the device to disconnect itself from the bus
214*4882a593Smuzhiyun * and reconnect. Renders all device handles invalid.
215*4882a593Smuzhiyun * @I2400M_RT_BUS: Tells the bus to reset the device; last measure
216*4882a593Smuzhiyun * used when both types above don't work.
217*4882a593Smuzhiyun */
218*4882a593Smuzhiyun enum i2400m_reset_type {
219*4882a593Smuzhiyun I2400M_RT_WARM, /* first measure */
220*4882a593Smuzhiyun I2400M_RT_COLD, /* second measure */
221*4882a593Smuzhiyun I2400M_RT_BUS, /* call in artillery */
222*4882a593Smuzhiyun };
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun struct i2400m_reset_ctx;
225*4882a593Smuzhiyun struct i2400m_roq;
226*4882a593Smuzhiyun struct i2400m_barker_db;
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun /**
229*4882a593Smuzhiyun * struct i2400m - descriptor for an Intel 2400m
230*4882a593Smuzhiyun *
231*4882a593Smuzhiyun * Members marked with [fill] must be filled out/initialized before
232*4882a593Smuzhiyun * calling i2400m_setup().
233*4882a593Smuzhiyun *
234*4882a593Smuzhiyun * Note the @bus_setup/@bus_release, @bus_dev_start/@bus_dev_release
235*4882a593Smuzhiyun * call pairs are very much doing almost the same, and depending on
236*4882a593Smuzhiyun * the underlying bus, some stuff has to be put in one or the
237*4882a593Smuzhiyun * other. The idea of setup/release is that they setup the minimal
238*4882a593Smuzhiyun * amount needed for loading firmware, where us dev_start/stop setup
239*4882a593Smuzhiyun * the rest needed to do full data/control traffic.
240*4882a593Smuzhiyun *
241*4882a593Smuzhiyun * @bus_tx_block_size: [fill] USB imposes a 16 block size, but other
242*4882a593Smuzhiyun * busses will differ. So we have a tx_blk_size variable that the
243*4882a593Smuzhiyun * bus layer sets to tell the engine how much of that we need.
244*4882a593Smuzhiyun *
245*4882a593Smuzhiyun * @bus_tx_room_min: [fill] Minimum room required while allocating
246*4882a593Smuzhiyun * TX queue's buffer space for message header. USB requires
247*4882a593Smuzhiyun * 16 bytes. Refer to bus specific driver code for details.
248*4882a593Smuzhiyun *
249*4882a593Smuzhiyun * @bus_pl_size_max: [fill] Maximum payload size.
250*4882a593Smuzhiyun *
251*4882a593Smuzhiyun * @bus_setup: [optional fill] Function called by the bus-generic code
252*4882a593Smuzhiyun * [i2400m_setup()] to setup the basic bus-specific communications
253*4882a593Smuzhiyun * to the the device needed to load firmware. See LIFE CYCLE above.
254*4882a593Smuzhiyun *
255*4882a593Smuzhiyun * NOTE: Doesn't need to upload the firmware, as that is taken
256*4882a593Smuzhiyun * care of by the bus-generic code.
257*4882a593Smuzhiyun *
258*4882a593Smuzhiyun * @bus_release: [optional fill] Function called by the bus-generic
259*4882a593Smuzhiyun * code [i2400m_release()] to shutdown the basic bus-specific
260*4882a593Smuzhiyun * communications to the the device needed to load firmware. See
261*4882a593Smuzhiyun * LIFE CYCLE above.
262*4882a593Smuzhiyun *
263*4882a593Smuzhiyun * This function does not need to reset the device, just tear down
264*4882a593Smuzhiyun * all the host resources created to handle communication with
265*4882a593Smuzhiyun * the device.
266*4882a593Smuzhiyun *
267*4882a593Smuzhiyun * @bus_dev_start: [optional fill] Function called by the bus-generic
268*4882a593Smuzhiyun * code [i2400m_dev_start()] to do things needed to start the
269*4882a593Smuzhiyun * device. See LIFE CYCLE above.
270*4882a593Smuzhiyun *
271*4882a593Smuzhiyun * NOTE: Doesn't need to upload the firmware, as that is taken
272*4882a593Smuzhiyun * care of by the bus-generic code.
273*4882a593Smuzhiyun *
274*4882a593Smuzhiyun * @bus_dev_stop: [optional fill] Function called by the bus-generic
275*4882a593Smuzhiyun * code [i2400m_dev_stop()] to do things needed for stopping the
276*4882a593Smuzhiyun * device. See LIFE CYCLE above.
277*4882a593Smuzhiyun *
278*4882a593Smuzhiyun * This function does not need to reset the device, just tear down
279*4882a593Smuzhiyun * all the host resources created to handle communication with
280*4882a593Smuzhiyun * the device.
281*4882a593Smuzhiyun *
282*4882a593Smuzhiyun * @bus_tx_kick: [fill] Function called by the bus-generic code to let
283*4882a593Smuzhiyun * the bus-specific code know that there is data available in the
284*4882a593Smuzhiyun * TX FIFO for transmission to the device.
285*4882a593Smuzhiyun *
286*4882a593Smuzhiyun * This function cannot sleep.
287*4882a593Smuzhiyun *
288*4882a593Smuzhiyun * @bus_reset: [fill] Function called by the bus-generic code to reset
289*4882a593Smuzhiyun * the device in in various ways. Doesn't need to wait for the
290*4882a593Smuzhiyun * reset to finish.
291*4882a593Smuzhiyun *
292*4882a593Smuzhiyun * If warm or cold reset fail, this function is expected to do a
293*4882a593Smuzhiyun * bus-specific reset (eg: USB reset) to get the device to a
294*4882a593Smuzhiyun * working state (even if it implies device disconecction).
295*4882a593Smuzhiyun *
296*4882a593Smuzhiyun * Note the warm reset is used by the firmware uploader to
297*4882a593Smuzhiyun * reinitialize the device.
298*4882a593Smuzhiyun *
299*4882a593Smuzhiyun * IMPORTANT: this is called very early in the device setup
300*4882a593Smuzhiyun * process, so it cannot rely on common infrastructure being laid
301*4882a593Smuzhiyun * out.
302*4882a593Smuzhiyun *
303*4882a593Smuzhiyun * IMPORTANT: don't call reset on RT_BUS with i2400m->init_mutex
304*4882a593Smuzhiyun * held, as the .pre/.post reset handlers will deadlock.
305*4882a593Smuzhiyun *
306*4882a593Smuzhiyun * @bus_bm_retries: [fill] How many times shall a firmware upload /
307*4882a593Smuzhiyun * device initialization be retried? Different models of the same
308*4882a593Smuzhiyun * device might need different values, hence it is set by the
309*4882a593Smuzhiyun * bus-specific driver. Note this value is used in two places,
310*4882a593Smuzhiyun * i2400m_fw_dnload() and __i2400m_dev_start(); they won't become
311*4882a593Smuzhiyun * multiplicative (__i2400m_dev_start() calling N times
312*4882a593Smuzhiyun * i2400m_fw_dnload() and this trying N times to download the
313*4882a593Smuzhiyun * firmware), as if __i2400m_dev_start() only retries if the
314*4882a593Smuzhiyun * firmware crashed while initializing the device (not in a
315*4882a593Smuzhiyun * general case).
316*4882a593Smuzhiyun *
317*4882a593Smuzhiyun * @bus_bm_cmd_send: [fill] Function called to send a boot-mode
318*4882a593Smuzhiyun * command. Flags are defined in 'enum i2400m_bm_cmd_flags'. This
319*4882a593Smuzhiyun * is synchronous and has to return 0 if ok or < 0 errno code in
320*4882a593Smuzhiyun * any error condition.
321*4882a593Smuzhiyun *
322*4882a593Smuzhiyun * @bus_bm_wait_for_ack: [fill] Function called to wait for a
323*4882a593Smuzhiyun * boot-mode notification (that can be a response to a previously
324*4882a593Smuzhiyun * issued command or an asynchronous one). Will read until all the
325*4882a593Smuzhiyun * indicated size is read or timeout. Reading more or less data
326*4882a593Smuzhiyun * than asked for is an error condition. Return 0 if ok, < 0 errno
327*4882a593Smuzhiyun * code on error.
328*4882a593Smuzhiyun *
329*4882a593Smuzhiyun * The caller to this function will check if the response is a
330*4882a593Smuzhiyun * barker that indicates the device going into reset mode.
331*4882a593Smuzhiyun *
332*4882a593Smuzhiyun * @bus_fw_names: [fill] a NULL-terminated array with the names of the
333*4882a593Smuzhiyun * firmware images to try loading. This is made a list so we can
334*4882a593Smuzhiyun * support backward compatibility of firmware releases (eg: if we
335*4882a593Smuzhiyun * can't find the default v1.4, we try v1.3). In general, the name
336*4882a593Smuzhiyun * should be i2400m-fw-X-VERSION.sbcf, where X is the bus name.
337*4882a593Smuzhiyun * The list is tried in order and the first one that loads is
338*4882a593Smuzhiyun * used. The fw loader will set i2400m->fw_name to point to the
339*4882a593Smuzhiyun * active firmware image.
340*4882a593Smuzhiyun *
341*4882a593Smuzhiyun * @bus_bm_mac_addr_impaired: [fill] Set to true if the device's MAC
342*4882a593Smuzhiyun * address provided in boot mode is kind of broken and needs to
343*4882a593Smuzhiyun * be re-read later on.
344*4882a593Smuzhiyun *
345*4882a593Smuzhiyun * @bus_bm_pokes_table: [fill/optional] A table of device addresses
346*4882a593Smuzhiyun * and values that will be poked at device init time to move the
347*4882a593Smuzhiyun * device to the correct state for the type of boot/firmware being
348*4882a593Smuzhiyun * used. This table MUST be terminated with (0x000000,
349*4882a593Smuzhiyun * 0x00000000) or bad things will happen.
350*4882a593Smuzhiyun *
351*4882a593Smuzhiyun *
352*4882a593Smuzhiyun * @wimax_dev: WiMAX generic device for linkage into the kernel WiMAX
353*4882a593Smuzhiyun * stack. Due to the way a net_device is allocated, we need to
354*4882a593Smuzhiyun * force this to be the first field so that we can get from
355*4882a593Smuzhiyun * netdev_priv() the right pointer.
356*4882a593Smuzhiyun *
357*4882a593Smuzhiyun * @updown: the device is up and ready for transmitting control and
358*4882a593Smuzhiyun * data packets. This implies @ready (communication infrastructure
359*4882a593Smuzhiyun * with the device is ready) and the device's firmware has been
360*4882a593Smuzhiyun * loaded and the device initialized.
361*4882a593Smuzhiyun *
362*4882a593Smuzhiyun * Write to it only inside a i2400m->init_mutex protected area
363*4882a593Smuzhiyun * followed with a wmb(); rmb() before accesing (unless locked
364*4882a593Smuzhiyun * inside i2400m->init_mutex). Read access can be loose like that
365*4882a593Smuzhiyun * [just using rmb()] because the paths that use this also do
366*4882a593Smuzhiyun * other error checks later on.
367*4882a593Smuzhiyun *
368*4882a593Smuzhiyun * @ready: Communication infrastructure with the device is ready, data
369*4882a593Smuzhiyun * frames can start to be passed around (this is lighter than
370*4882a593Smuzhiyun * using the WiMAX state for certain hot paths).
371*4882a593Smuzhiyun *
372*4882a593Smuzhiyun * Write to it only inside a i2400m->init_mutex protected area
373*4882a593Smuzhiyun * followed with a wmb(); rmb() before accesing (unless locked
374*4882a593Smuzhiyun * inside i2400m->init_mutex). Read access can be loose like that
375*4882a593Smuzhiyun * [just using rmb()] because the paths that use this also do
376*4882a593Smuzhiyun * other error checks later on.
377*4882a593Smuzhiyun *
378*4882a593Smuzhiyun * @rx_reorder: 1 if RX reordering is enabled; this can only be
379*4882a593Smuzhiyun * set at probe time.
380*4882a593Smuzhiyun *
381*4882a593Smuzhiyun * @state: device's state (as reported by it)
382*4882a593Smuzhiyun *
383*4882a593Smuzhiyun * @state_wq: waitqueue that is woken up whenever the state changes
384*4882a593Smuzhiyun *
385*4882a593Smuzhiyun * @tx_lock: spinlock to protect TX members
386*4882a593Smuzhiyun *
387*4882a593Smuzhiyun * @tx_buf: FIFO buffer for TX; we queue data here
388*4882a593Smuzhiyun *
389*4882a593Smuzhiyun * @tx_in: FIFO index for incoming data. Note this doesn't wrap around
390*4882a593Smuzhiyun * and it is always greater than @tx_out.
391*4882a593Smuzhiyun *
392*4882a593Smuzhiyun * @tx_out: FIFO index for outgoing data
393*4882a593Smuzhiyun *
394*4882a593Smuzhiyun * @tx_msg: current TX message that is active in the FIFO for
395*4882a593Smuzhiyun * appending payloads.
396*4882a593Smuzhiyun *
397*4882a593Smuzhiyun * @tx_sequence: current sequence number for TX messages from the
398*4882a593Smuzhiyun * device to the host.
399*4882a593Smuzhiyun *
400*4882a593Smuzhiyun * @tx_msg_size: size of the current message being transmitted by the
401*4882a593Smuzhiyun * bus-specific code.
402*4882a593Smuzhiyun *
403*4882a593Smuzhiyun * @tx_pl_num: total number of payloads sent
404*4882a593Smuzhiyun *
405*4882a593Smuzhiyun * @tx_pl_max: maximum number of payloads sent in a TX message
406*4882a593Smuzhiyun *
407*4882a593Smuzhiyun * @tx_pl_min: minimum number of payloads sent in a TX message
408*4882a593Smuzhiyun *
409*4882a593Smuzhiyun * @tx_num: number of TX messages sent
410*4882a593Smuzhiyun *
411*4882a593Smuzhiyun * @tx_size_acc: number of bytes in all TX messages sent
412*4882a593Smuzhiyun * (this is different to net_dev's statistics as it also counts
413*4882a593Smuzhiyun * control messages).
414*4882a593Smuzhiyun *
415*4882a593Smuzhiyun * @tx_size_min: smallest TX message sent.
416*4882a593Smuzhiyun *
417*4882a593Smuzhiyun * @tx_size_max: biggest TX message sent.
418*4882a593Smuzhiyun *
419*4882a593Smuzhiyun * @rx_lock: spinlock to protect RX members and rx_roq_refcount.
420*4882a593Smuzhiyun *
421*4882a593Smuzhiyun * @rx_pl_num: total number of payloads received
422*4882a593Smuzhiyun *
423*4882a593Smuzhiyun * @rx_pl_max: maximum number of payloads received in a RX message
424*4882a593Smuzhiyun *
425*4882a593Smuzhiyun * @rx_pl_min: minimum number of payloads received in a RX message
426*4882a593Smuzhiyun *
427*4882a593Smuzhiyun * @rx_num: number of RX messages received
428*4882a593Smuzhiyun *
429*4882a593Smuzhiyun * @rx_size_acc: number of bytes in all RX messages received
430*4882a593Smuzhiyun * (this is different to net_dev's statistics as it also counts
431*4882a593Smuzhiyun * control messages).
432*4882a593Smuzhiyun *
433*4882a593Smuzhiyun * @rx_size_min: smallest RX message received.
434*4882a593Smuzhiyun *
435*4882a593Smuzhiyun * @rx_size_max: buggest RX message received.
436*4882a593Smuzhiyun *
437*4882a593Smuzhiyun * @rx_roq: RX ReOrder queues. (fw >= v1.4) When packets are received
438*4882a593Smuzhiyun * out of order, the device will ask the driver to hold certain
439*4882a593Smuzhiyun * packets until the ones that are received out of order can be
440*4882a593Smuzhiyun * delivered. Then the driver can release them to the host. See
441*4882a593Smuzhiyun * drivers/net/i2400m/rx.c for details.
442*4882a593Smuzhiyun *
443*4882a593Smuzhiyun * @rx_roq_refcount: refcount rx_roq. This refcounts any access to
444*4882a593Smuzhiyun * rx_roq thus preventing rx_roq being destroyed when rx_roq
445*4882a593Smuzhiyun * is being accessed. rx_roq_refcount is protected by rx_lock.
446*4882a593Smuzhiyun *
447*4882a593Smuzhiyun * @rx_reports: reports received from the device that couldn't be
448*4882a593Smuzhiyun * processed because the driver wasn't still ready; when ready,
449*4882a593Smuzhiyun * they are pulled from here and chewed.
450*4882a593Smuzhiyun *
451*4882a593Smuzhiyun * @rx_reports_ws: Work struct used to kick a scan of the RX reports
452*4882a593Smuzhiyun * list and to process each.
453*4882a593Smuzhiyun *
454*4882a593Smuzhiyun * @src_mac_addr: MAC address used to make ethernet packets be coming
455*4882a593Smuzhiyun * from. This is generated at i2400m_setup() time and used during
456*4882a593Smuzhiyun * the life cycle of the instance. See i2400m_fake_eth_header().
457*4882a593Smuzhiyun *
458*4882a593Smuzhiyun * @init_mutex: Mutex used for serializing the device bringup
459*4882a593Smuzhiyun * sequence; this way if the device reboots in the middle, we
460*4882a593Smuzhiyun * don't try to do a bringup again while we are tearing down the
461*4882a593Smuzhiyun * one that failed.
462*4882a593Smuzhiyun *
463*4882a593Smuzhiyun * Can't reuse @msg_mutex because from within the bringup sequence
464*4882a593Smuzhiyun * we need to send messages to the device and thus use @msg_mutex.
465*4882a593Smuzhiyun *
466*4882a593Smuzhiyun * @msg_mutex: mutex used to send control commands to the device (we
467*4882a593Smuzhiyun * only allow one at a time, per host-device interface design).
468*4882a593Smuzhiyun *
469*4882a593Smuzhiyun * @msg_completion: used to wait for an ack to a control command sent
470*4882a593Smuzhiyun * to the device.
471*4882a593Smuzhiyun *
472*4882a593Smuzhiyun * @ack_skb: used to store the actual ack to a control command if the
473*4882a593Smuzhiyun * reception of the command was successful. Otherwise, a ERR_PTR()
474*4882a593Smuzhiyun * errno code that indicates what failed with the ack reception.
475*4882a593Smuzhiyun *
476*4882a593Smuzhiyun * Only valid after @msg_completion is woken up. Only updateable
477*4882a593Smuzhiyun * if @msg_completion is armed. Only touched by
478*4882a593Smuzhiyun * i2400m_msg_to_dev().
479*4882a593Smuzhiyun *
480*4882a593Smuzhiyun * Protected by @rx_lock. In theory the command execution flow is
481*4882a593Smuzhiyun * sequential, but in case the device sends an out-of-phase or
482*4882a593Smuzhiyun * very delayed response, we need to avoid it trampling current
483*4882a593Smuzhiyun * execution.
484*4882a593Smuzhiyun *
485*4882a593Smuzhiyun * @bm_cmd_buf: boot mode command buffer for composing firmware upload
486*4882a593Smuzhiyun * commands.
487*4882a593Smuzhiyun *
488*4882a593Smuzhiyun * USB can't r/w to stack, vmalloc, etc...as well, we end up
489*4882a593Smuzhiyun * having to alloc/free a lot to compose commands, so we use these
490*4882a593Smuzhiyun * for stagging and not having to realloc all the time.
491*4882a593Smuzhiyun *
492*4882a593Smuzhiyun * This assumes the code always runs serialized. Only one thread
493*4882a593Smuzhiyun * can call i2400m_bm_cmd() at the same time.
494*4882a593Smuzhiyun *
495*4882a593Smuzhiyun * @bm_ack_buf: boot mode acknoledge buffer for staging reception of
496*4882a593Smuzhiyun * responses to commands.
497*4882a593Smuzhiyun *
498*4882a593Smuzhiyun * See @bm_cmd_buf.
499*4882a593Smuzhiyun *
500*4882a593Smuzhiyun * @work_queue: work queue for processing device reports. This
501*4882a593Smuzhiyun * workqueue cannot be used for processing TX or RX to the device,
502*4882a593Smuzhiyun * as from it we'll process device reports, which might require
503*4882a593Smuzhiyun * further communication with the device.
504*4882a593Smuzhiyun *
505*4882a593Smuzhiyun * @debugfs_dentry: hookup for debugfs files.
506*4882a593Smuzhiyun * These have to be in a separate directory, a child of
507*4882a593Smuzhiyun * (wimax_dev->debugfs_dentry) so they can be removed when the
508*4882a593Smuzhiyun * module unloads, as we don't keep each dentry.
509*4882a593Smuzhiyun *
510*4882a593Smuzhiyun * @fw_name: name of the firmware image that is currently being used.
511*4882a593Smuzhiyun *
512*4882a593Smuzhiyun * @fw_version: version of the firmware interface, Major.minor,
513*4882a593Smuzhiyun * encoded in the high word and low word (major << 16 | minor).
514*4882a593Smuzhiyun *
515*4882a593Smuzhiyun * @fw_hdrs: NULL terminated array of pointers to the firmware
516*4882a593Smuzhiyun * headers. This is only available during firmware load time.
517*4882a593Smuzhiyun *
518*4882a593Smuzhiyun * @fw_cached: Used to cache firmware when the system goes to
519*4882a593Smuzhiyun * suspend/standby/hibernation (as on resume we can't read it). If
520*4882a593Smuzhiyun * NULL, no firmware was cached, read it. If ~0, you can't read
521*4882a593Smuzhiyun * any firmware files (the system still didn't come out of suspend
522*4882a593Smuzhiyun * and failed to cache one), so abort; otherwise, a valid cached
523*4882a593Smuzhiyun * firmware to be used. Access to this variable is protected by
524*4882a593Smuzhiyun * the spinlock i2400m->rx_lock.
525*4882a593Smuzhiyun *
526*4882a593Smuzhiyun * @barker: barker type that the device uses; this is initialized by
527*4882a593Smuzhiyun * i2400m_is_boot_barker() the first time it is called. Then it
528*4882a593Smuzhiyun * won't change during the life cycle of the device and every time
529*4882a593Smuzhiyun * a boot barker is received, it is just verified for it being the
530*4882a593Smuzhiyun * same.
531*4882a593Smuzhiyun *
532*4882a593Smuzhiyun * @pm_notifier: used to register for PM events
533*4882a593Smuzhiyun *
534*4882a593Smuzhiyun * @bus_reset_retries: counter for the number of bus resets attempted for
535*4882a593Smuzhiyun * this boot. It's not for tracking the number of bus resets during
536*4882a593Smuzhiyun * the whole driver life cycle (from insmod to rmmod) but for the
537*4882a593Smuzhiyun * number of dev_start() executed until dev_start() returns a success
538*4882a593Smuzhiyun * (ie: a good boot means a dev_stop() followed by a successful
539*4882a593Smuzhiyun * dev_start()). dev_reset_handler() increments this counter whenever
540*4882a593Smuzhiyun * it is triggering a bus reset. It checks this counter to decide if a
541*4882a593Smuzhiyun * subsequent bus reset should be retried. dev_reset_handler() retries
542*4882a593Smuzhiyun * the bus reset until dev_start() succeeds or the counter reaches
543*4882a593Smuzhiyun * I2400M_BUS_RESET_RETRIES. The counter is cleared to 0 in
544*4882a593Smuzhiyun * dev_reset_handle() when dev_start() returns a success,
545*4882a593Smuzhiyun * ie: a successul boot is completed.
546*4882a593Smuzhiyun *
547*4882a593Smuzhiyun * @alive: flag to denote if the device *should* be alive. This flag is
548*4882a593Smuzhiyun * everything like @updown (see doc for @updown) except reflecting
549*4882a593Smuzhiyun * the device state *we expect* rather than the actual state as denoted
550*4882a593Smuzhiyun * by @updown. It is set 1 whenever @updown is set 1 in dev_start().
551*4882a593Smuzhiyun * Then the device is expected to be alive all the time
552*4882a593Smuzhiyun * (i2400m->alive remains 1) until the driver is removed. Therefore
553*4882a593Smuzhiyun * all the device reboot events detected can be still handled properly
554*4882a593Smuzhiyun * by either dev_reset_handle() or .pre_reset/.post_reset as long as
555*4882a593Smuzhiyun * the driver presents. It is set 0 along with @updown in dev_stop().
556*4882a593Smuzhiyun *
557*4882a593Smuzhiyun * @error_recovery: flag to denote if we are ready to take an error recovery.
558*4882a593Smuzhiyun * 0 for ready to take an error recovery; 1 for not ready. It is
559*4882a593Smuzhiyun * initialized to 1 while probe() since we don't tend to take any error
560*4882a593Smuzhiyun * recovery during probe(). It is decremented by 1 whenever dev_start()
561*4882a593Smuzhiyun * succeeds to indicate we are ready to take error recovery from now on.
562*4882a593Smuzhiyun * It is checked every time we wanna schedule an error recovery. If an
563*4882a593Smuzhiyun * error recovery is already in place (error_recovery was set 1), we
564*4882a593Smuzhiyun * should not schedule another one until the last one is done.
565*4882a593Smuzhiyun */
566*4882a593Smuzhiyun struct i2400m {
567*4882a593Smuzhiyun struct wimax_dev wimax_dev; /* FIRST! See doc */
568*4882a593Smuzhiyun
569*4882a593Smuzhiyun unsigned updown:1; /* Network device is up or down */
570*4882a593Smuzhiyun unsigned boot_mode:1; /* is the device in boot mode? */
571*4882a593Smuzhiyun unsigned sboot:1; /* signed or unsigned fw boot */
572*4882a593Smuzhiyun unsigned ready:1; /* Device comm infrastructure ready */
573*4882a593Smuzhiyun unsigned rx_reorder:1; /* RX reorder is enabled */
574*4882a593Smuzhiyun u8 trace_msg_from_user; /* echo rx msgs to 'trace' pipe */
575*4882a593Smuzhiyun /* typed u8 so /sys/kernel/debug/u8 can tweak */
576*4882a593Smuzhiyun enum i2400m_system_state state;
577*4882a593Smuzhiyun wait_queue_head_t state_wq; /* Woken up when on state updates */
578*4882a593Smuzhiyun
579*4882a593Smuzhiyun size_t bus_tx_block_size;
580*4882a593Smuzhiyun size_t bus_tx_room_min;
581*4882a593Smuzhiyun size_t bus_pl_size_max;
582*4882a593Smuzhiyun unsigned bus_bm_retries;
583*4882a593Smuzhiyun
584*4882a593Smuzhiyun int (*bus_setup)(struct i2400m *);
585*4882a593Smuzhiyun int (*bus_dev_start)(struct i2400m *);
586*4882a593Smuzhiyun void (*bus_dev_stop)(struct i2400m *);
587*4882a593Smuzhiyun void (*bus_release)(struct i2400m *);
588*4882a593Smuzhiyun void (*bus_tx_kick)(struct i2400m *);
589*4882a593Smuzhiyun int (*bus_reset)(struct i2400m *, enum i2400m_reset_type);
590*4882a593Smuzhiyun ssize_t (*bus_bm_cmd_send)(struct i2400m *,
591*4882a593Smuzhiyun const struct i2400m_bootrom_header *,
592*4882a593Smuzhiyun size_t, int flags);
593*4882a593Smuzhiyun ssize_t (*bus_bm_wait_for_ack)(struct i2400m *,
594*4882a593Smuzhiyun struct i2400m_bootrom_header *, size_t);
595*4882a593Smuzhiyun const char **bus_fw_names;
596*4882a593Smuzhiyun unsigned bus_bm_mac_addr_impaired:1;
597*4882a593Smuzhiyun const struct i2400m_poke_table *bus_bm_pokes_table;
598*4882a593Smuzhiyun
599*4882a593Smuzhiyun spinlock_t tx_lock; /* protect TX state */
600*4882a593Smuzhiyun void *tx_buf;
601*4882a593Smuzhiyun size_t tx_in, tx_out;
602*4882a593Smuzhiyun struct i2400m_msg_hdr *tx_msg;
603*4882a593Smuzhiyun size_t tx_sequence, tx_msg_size;
604*4882a593Smuzhiyun /* TX stats */
605*4882a593Smuzhiyun unsigned tx_pl_num, tx_pl_max, tx_pl_min,
606*4882a593Smuzhiyun tx_num, tx_size_acc, tx_size_min, tx_size_max;
607*4882a593Smuzhiyun
608*4882a593Smuzhiyun /* RX stuff */
609*4882a593Smuzhiyun /* protect RX state and rx_roq_refcount */
610*4882a593Smuzhiyun spinlock_t rx_lock;
611*4882a593Smuzhiyun unsigned rx_pl_num, rx_pl_max, rx_pl_min,
612*4882a593Smuzhiyun rx_num, rx_size_acc, rx_size_min, rx_size_max;
613*4882a593Smuzhiyun struct i2400m_roq *rx_roq; /* access is refcounted */
614*4882a593Smuzhiyun struct kref rx_roq_refcount; /* refcount access to rx_roq */
615*4882a593Smuzhiyun u8 src_mac_addr[ETH_HLEN];
616*4882a593Smuzhiyun struct list_head rx_reports; /* under rx_lock! */
617*4882a593Smuzhiyun struct work_struct rx_report_ws;
618*4882a593Smuzhiyun
619*4882a593Smuzhiyun struct mutex msg_mutex; /* serialize command execution */
620*4882a593Smuzhiyun struct completion msg_completion;
621*4882a593Smuzhiyun struct sk_buff *ack_skb; /* protected by rx_lock */
622*4882a593Smuzhiyun
623*4882a593Smuzhiyun void *bm_ack_buf; /* for receiving acks over USB */
624*4882a593Smuzhiyun void *bm_cmd_buf; /* for issuing commands over USB */
625*4882a593Smuzhiyun
626*4882a593Smuzhiyun struct workqueue_struct *work_queue;
627*4882a593Smuzhiyun
628*4882a593Smuzhiyun struct mutex init_mutex; /* protect bringup seq */
629*4882a593Smuzhiyun struct i2400m_reset_ctx *reset_ctx; /* protected by init_mutex */
630*4882a593Smuzhiyun
631*4882a593Smuzhiyun struct work_struct wake_tx_ws;
632*4882a593Smuzhiyun struct sk_buff *wake_tx_skb;
633*4882a593Smuzhiyun
634*4882a593Smuzhiyun struct work_struct reset_ws;
635*4882a593Smuzhiyun const char *reset_reason;
636*4882a593Smuzhiyun
637*4882a593Smuzhiyun struct work_struct recovery_ws;
638*4882a593Smuzhiyun
639*4882a593Smuzhiyun struct dentry *debugfs_dentry;
640*4882a593Smuzhiyun const char *fw_name; /* name of the current firmware image */
641*4882a593Smuzhiyun unsigned long fw_version; /* version of the firmware interface */
642*4882a593Smuzhiyun const struct i2400m_bcf_hdr **fw_hdrs;
643*4882a593Smuzhiyun struct i2400m_fw *fw_cached; /* protected by rx_lock */
644*4882a593Smuzhiyun struct i2400m_barker_db *barker;
645*4882a593Smuzhiyun
646*4882a593Smuzhiyun struct notifier_block pm_notifier;
647*4882a593Smuzhiyun
648*4882a593Smuzhiyun /* counting bus reset retries in this boot */
649*4882a593Smuzhiyun atomic_t bus_reset_retries;
650*4882a593Smuzhiyun
651*4882a593Smuzhiyun /* if the device is expected to be alive */
652*4882a593Smuzhiyun unsigned alive;
653*4882a593Smuzhiyun
654*4882a593Smuzhiyun /* 0 if we are ready for error recovery; 1 if not ready */
655*4882a593Smuzhiyun atomic_t error_recovery;
656*4882a593Smuzhiyun
657*4882a593Smuzhiyun };
658*4882a593Smuzhiyun
659*4882a593Smuzhiyun
660*4882a593Smuzhiyun /*
661*4882a593Smuzhiyun * Bus-generic internal APIs
662*4882a593Smuzhiyun * -------------------------
663*4882a593Smuzhiyun */
664*4882a593Smuzhiyun
665*4882a593Smuzhiyun static inline
wimax_dev_to_i2400m(struct wimax_dev * wimax_dev)666*4882a593Smuzhiyun struct i2400m *wimax_dev_to_i2400m(struct wimax_dev *wimax_dev)
667*4882a593Smuzhiyun {
668*4882a593Smuzhiyun return container_of(wimax_dev, struct i2400m, wimax_dev);
669*4882a593Smuzhiyun }
670*4882a593Smuzhiyun
671*4882a593Smuzhiyun static inline
net_dev_to_i2400m(struct net_device * net_dev)672*4882a593Smuzhiyun struct i2400m *net_dev_to_i2400m(struct net_device *net_dev)
673*4882a593Smuzhiyun {
674*4882a593Smuzhiyun return wimax_dev_to_i2400m(netdev_priv(net_dev));
675*4882a593Smuzhiyun }
676*4882a593Smuzhiyun
677*4882a593Smuzhiyun /*
678*4882a593Smuzhiyun * Boot mode support
679*4882a593Smuzhiyun */
680*4882a593Smuzhiyun
681*4882a593Smuzhiyun /**
682*4882a593Smuzhiyun * i2400m_bm_cmd_flags - flags to i2400m_bm_cmd()
683*4882a593Smuzhiyun *
684*4882a593Smuzhiyun * @I2400M_BM_CMD_RAW: send the command block as-is, without doing any
685*4882a593Smuzhiyun * extra processing for adding CRC.
686*4882a593Smuzhiyun */
687*4882a593Smuzhiyun enum i2400m_bm_cmd_flags {
688*4882a593Smuzhiyun I2400M_BM_CMD_RAW = 1 << 2,
689*4882a593Smuzhiyun };
690*4882a593Smuzhiyun
691*4882a593Smuzhiyun /**
692*4882a593Smuzhiyun * i2400m_bri - Boot-ROM indicators
693*4882a593Smuzhiyun *
694*4882a593Smuzhiyun * Flags for i2400m_bootrom_init() and i2400m_dev_bootstrap() [which
695*4882a593Smuzhiyun * are passed from things like i2400m_setup()]. Can be combined with
696*4882a593Smuzhiyun * |.
697*4882a593Smuzhiyun *
698*4882a593Smuzhiyun * @I2400M_BRI_SOFT: The device rebooted already and a reboot
699*4882a593Smuzhiyun * barker received, proceed directly to ack the boot sequence.
700*4882a593Smuzhiyun * @I2400M_BRI_NO_REBOOT: Do not reboot the device and proceed
701*4882a593Smuzhiyun * directly to wait for a reboot barker from the device.
702*4882a593Smuzhiyun * @I2400M_BRI_MAC_REINIT: We need to reinitialize the boot
703*4882a593Smuzhiyun * rom after reading the MAC address. This is quite a dirty hack,
704*4882a593Smuzhiyun * if you ask me -- the device requires the bootrom to be
705*4882a593Smuzhiyun * initialized after reading the MAC address.
706*4882a593Smuzhiyun */
707*4882a593Smuzhiyun enum i2400m_bri {
708*4882a593Smuzhiyun I2400M_BRI_SOFT = 1 << 1,
709*4882a593Smuzhiyun I2400M_BRI_NO_REBOOT = 1 << 2,
710*4882a593Smuzhiyun I2400M_BRI_MAC_REINIT = 1 << 3,
711*4882a593Smuzhiyun };
712*4882a593Smuzhiyun
713*4882a593Smuzhiyun void i2400m_bm_cmd_prepare(struct i2400m_bootrom_header *);
714*4882a593Smuzhiyun int i2400m_dev_bootstrap(struct i2400m *, enum i2400m_bri);
715*4882a593Smuzhiyun int i2400m_read_mac_addr(struct i2400m *);
716*4882a593Smuzhiyun int i2400m_bootrom_init(struct i2400m *, enum i2400m_bri);
717*4882a593Smuzhiyun int i2400m_is_boot_barker(struct i2400m *, const void *, size_t);
718*4882a593Smuzhiyun static inline
i2400m_is_d2h_barker(const void * buf)719*4882a593Smuzhiyun int i2400m_is_d2h_barker(const void *buf)
720*4882a593Smuzhiyun {
721*4882a593Smuzhiyun const __le32 *barker = buf;
722*4882a593Smuzhiyun return le32_to_cpu(*barker) == I2400M_D2H_MSG_BARKER;
723*4882a593Smuzhiyun }
724*4882a593Smuzhiyun void i2400m_unknown_barker(struct i2400m *, const void *, size_t);
725*4882a593Smuzhiyun
726*4882a593Smuzhiyun /* Make/grok boot-rom header commands */
727*4882a593Smuzhiyun
728*4882a593Smuzhiyun static inline
i2400m_brh_command(enum i2400m_brh_opcode opcode,unsigned use_checksum,unsigned direct_access)729*4882a593Smuzhiyun __le32 i2400m_brh_command(enum i2400m_brh_opcode opcode, unsigned use_checksum,
730*4882a593Smuzhiyun unsigned direct_access)
731*4882a593Smuzhiyun {
732*4882a593Smuzhiyun return cpu_to_le32(
733*4882a593Smuzhiyun I2400M_BRH_SIGNATURE
734*4882a593Smuzhiyun | (direct_access ? I2400M_BRH_DIRECT_ACCESS : 0)
735*4882a593Smuzhiyun | I2400M_BRH_RESPONSE_REQUIRED /* response always required */
736*4882a593Smuzhiyun | (use_checksum ? I2400M_BRH_USE_CHECKSUM : 0)
737*4882a593Smuzhiyun | (opcode & I2400M_BRH_OPCODE_MASK));
738*4882a593Smuzhiyun }
739*4882a593Smuzhiyun
740*4882a593Smuzhiyun static inline
i2400m_brh_set_opcode(struct i2400m_bootrom_header * hdr,enum i2400m_brh_opcode opcode)741*4882a593Smuzhiyun void i2400m_brh_set_opcode(struct i2400m_bootrom_header *hdr,
742*4882a593Smuzhiyun enum i2400m_brh_opcode opcode)
743*4882a593Smuzhiyun {
744*4882a593Smuzhiyun hdr->command = cpu_to_le32(
745*4882a593Smuzhiyun (le32_to_cpu(hdr->command) & ~I2400M_BRH_OPCODE_MASK)
746*4882a593Smuzhiyun | (opcode & I2400M_BRH_OPCODE_MASK));
747*4882a593Smuzhiyun }
748*4882a593Smuzhiyun
749*4882a593Smuzhiyun static inline
i2400m_brh_get_opcode(const struct i2400m_bootrom_header * hdr)750*4882a593Smuzhiyun unsigned i2400m_brh_get_opcode(const struct i2400m_bootrom_header *hdr)
751*4882a593Smuzhiyun {
752*4882a593Smuzhiyun return le32_to_cpu(hdr->command) & I2400M_BRH_OPCODE_MASK;
753*4882a593Smuzhiyun }
754*4882a593Smuzhiyun
755*4882a593Smuzhiyun static inline
i2400m_brh_get_response(const struct i2400m_bootrom_header * hdr)756*4882a593Smuzhiyun unsigned i2400m_brh_get_response(const struct i2400m_bootrom_header *hdr)
757*4882a593Smuzhiyun {
758*4882a593Smuzhiyun return (le32_to_cpu(hdr->command) & I2400M_BRH_RESPONSE_MASK)
759*4882a593Smuzhiyun >> I2400M_BRH_RESPONSE_SHIFT;
760*4882a593Smuzhiyun }
761*4882a593Smuzhiyun
762*4882a593Smuzhiyun static inline
i2400m_brh_get_use_checksum(const struct i2400m_bootrom_header * hdr)763*4882a593Smuzhiyun unsigned i2400m_brh_get_use_checksum(const struct i2400m_bootrom_header *hdr)
764*4882a593Smuzhiyun {
765*4882a593Smuzhiyun return le32_to_cpu(hdr->command) & I2400M_BRH_USE_CHECKSUM;
766*4882a593Smuzhiyun }
767*4882a593Smuzhiyun
768*4882a593Smuzhiyun static inline
i2400m_brh_get_response_required(const struct i2400m_bootrom_header * hdr)769*4882a593Smuzhiyun unsigned i2400m_brh_get_response_required(
770*4882a593Smuzhiyun const struct i2400m_bootrom_header *hdr)
771*4882a593Smuzhiyun {
772*4882a593Smuzhiyun return le32_to_cpu(hdr->command) & I2400M_BRH_RESPONSE_REQUIRED;
773*4882a593Smuzhiyun }
774*4882a593Smuzhiyun
775*4882a593Smuzhiyun static inline
i2400m_brh_get_direct_access(const struct i2400m_bootrom_header * hdr)776*4882a593Smuzhiyun unsigned i2400m_brh_get_direct_access(const struct i2400m_bootrom_header *hdr)
777*4882a593Smuzhiyun {
778*4882a593Smuzhiyun return le32_to_cpu(hdr->command) & I2400M_BRH_DIRECT_ACCESS;
779*4882a593Smuzhiyun }
780*4882a593Smuzhiyun
781*4882a593Smuzhiyun static inline
i2400m_brh_get_signature(const struct i2400m_bootrom_header * hdr)782*4882a593Smuzhiyun unsigned i2400m_brh_get_signature(const struct i2400m_bootrom_header *hdr)
783*4882a593Smuzhiyun {
784*4882a593Smuzhiyun return (le32_to_cpu(hdr->command) & I2400M_BRH_SIGNATURE_MASK)
785*4882a593Smuzhiyun >> I2400M_BRH_SIGNATURE_SHIFT;
786*4882a593Smuzhiyun }
787*4882a593Smuzhiyun
788*4882a593Smuzhiyun
789*4882a593Smuzhiyun /*
790*4882a593Smuzhiyun * Driver / device setup and internal functions
791*4882a593Smuzhiyun */
792*4882a593Smuzhiyun void i2400m_init(struct i2400m *);
793*4882a593Smuzhiyun int i2400m_reset(struct i2400m *, enum i2400m_reset_type);
794*4882a593Smuzhiyun void i2400m_netdev_setup(struct net_device *net_dev);
795*4882a593Smuzhiyun int i2400m_sysfs_setup(struct device_driver *);
796*4882a593Smuzhiyun void i2400m_sysfs_release(struct device_driver *);
797*4882a593Smuzhiyun int i2400m_tx_setup(struct i2400m *);
798*4882a593Smuzhiyun void i2400m_wake_tx_work(struct work_struct *);
799*4882a593Smuzhiyun void i2400m_tx_release(struct i2400m *);
800*4882a593Smuzhiyun
801*4882a593Smuzhiyun int i2400m_rx_setup(struct i2400m *);
802*4882a593Smuzhiyun void i2400m_rx_release(struct i2400m *);
803*4882a593Smuzhiyun
804*4882a593Smuzhiyun void i2400m_fw_cache(struct i2400m *);
805*4882a593Smuzhiyun void i2400m_fw_uncache(struct i2400m *);
806*4882a593Smuzhiyun
807*4882a593Smuzhiyun void i2400m_net_rx(struct i2400m *, struct sk_buff *, unsigned, const void *,
808*4882a593Smuzhiyun int);
809*4882a593Smuzhiyun void i2400m_net_erx(struct i2400m *, struct sk_buff *, enum i2400m_cs);
810*4882a593Smuzhiyun void i2400m_net_wake_stop(struct i2400m *);
811*4882a593Smuzhiyun enum i2400m_pt;
812*4882a593Smuzhiyun int i2400m_tx(struct i2400m *, const void *, size_t, enum i2400m_pt);
813*4882a593Smuzhiyun
814*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_FS
815*4882a593Smuzhiyun void i2400m_debugfs_add(struct i2400m *);
816*4882a593Smuzhiyun void i2400m_debugfs_rm(struct i2400m *);
817*4882a593Smuzhiyun #else
i2400m_debugfs_add(struct i2400m * i2400m)818*4882a593Smuzhiyun static inline void i2400m_debugfs_add(struct i2400m *i2400m) {}
i2400m_debugfs_rm(struct i2400m * i2400m)819*4882a593Smuzhiyun static inline void i2400m_debugfs_rm(struct i2400m *i2400m) {}
820*4882a593Smuzhiyun #endif
821*4882a593Smuzhiyun
822*4882a593Smuzhiyun /* Initialize/shutdown the device */
823*4882a593Smuzhiyun int i2400m_dev_initialize(struct i2400m *);
824*4882a593Smuzhiyun void i2400m_dev_shutdown(struct i2400m *);
825*4882a593Smuzhiyun
826*4882a593Smuzhiyun extern struct attribute_group i2400m_dev_attr_group;
827*4882a593Smuzhiyun
828*4882a593Smuzhiyun
829*4882a593Smuzhiyun /* HDI message's payload description handling */
830*4882a593Smuzhiyun
831*4882a593Smuzhiyun static inline
i2400m_pld_size(const struct i2400m_pld * pld)832*4882a593Smuzhiyun size_t i2400m_pld_size(const struct i2400m_pld *pld)
833*4882a593Smuzhiyun {
834*4882a593Smuzhiyun return I2400M_PLD_SIZE_MASK & le32_to_cpu(pld->val);
835*4882a593Smuzhiyun }
836*4882a593Smuzhiyun
837*4882a593Smuzhiyun static inline
i2400m_pld_type(const struct i2400m_pld * pld)838*4882a593Smuzhiyun enum i2400m_pt i2400m_pld_type(const struct i2400m_pld *pld)
839*4882a593Smuzhiyun {
840*4882a593Smuzhiyun return (I2400M_PLD_TYPE_MASK & le32_to_cpu(pld->val))
841*4882a593Smuzhiyun >> I2400M_PLD_TYPE_SHIFT;
842*4882a593Smuzhiyun }
843*4882a593Smuzhiyun
844*4882a593Smuzhiyun static inline
i2400m_pld_set(struct i2400m_pld * pld,size_t size,enum i2400m_pt type)845*4882a593Smuzhiyun void i2400m_pld_set(struct i2400m_pld *pld, size_t size,
846*4882a593Smuzhiyun enum i2400m_pt type)
847*4882a593Smuzhiyun {
848*4882a593Smuzhiyun pld->val = cpu_to_le32(
849*4882a593Smuzhiyun ((type << I2400M_PLD_TYPE_SHIFT) & I2400M_PLD_TYPE_MASK)
850*4882a593Smuzhiyun | (size & I2400M_PLD_SIZE_MASK));
851*4882a593Smuzhiyun }
852*4882a593Smuzhiyun
853*4882a593Smuzhiyun
854*4882a593Smuzhiyun /*
855*4882a593Smuzhiyun * API for the bus-specific drivers
856*4882a593Smuzhiyun * --------------------------------
857*4882a593Smuzhiyun */
858*4882a593Smuzhiyun
859*4882a593Smuzhiyun static inline
i2400m_get(struct i2400m * i2400m)860*4882a593Smuzhiyun struct i2400m *i2400m_get(struct i2400m *i2400m)
861*4882a593Smuzhiyun {
862*4882a593Smuzhiyun dev_hold(i2400m->wimax_dev.net_dev);
863*4882a593Smuzhiyun return i2400m;
864*4882a593Smuzhiyun }
865*4882a593Smuzhiyun
866*4882a593Smuzhiyun static inline
i2400m_put(struct i2400m * i2400m)867*4882a593Smuzhiyun void i2400m_put(struct i2400m *i2400m)
868*4882a593Smuzhiyun {
869*4882a593Smuzhiyun dev_put(i2400m->wimax_dev.net_dev);
870*4882a593Smuzhiyun }
871*4882a593Smuzhiyun
872*4882a593Smuzhiyun int i2400m_dev_reset_handle(struct i2400m *, const char *);
873*4882a593Smuzhiyun int i2400m_pre_reset(struct i2400m *);
874*4882a593Smuzhiyun int i2400m_post_reset(struct i2400m *);
875*4882a593Smuzhiyun void i2400m_error_recovery(struct i2400m *);
876*4882a593Smuzhiyun
877*4882a593Smuzhiyun /*
878*4882a593Smuzhiyun * _setup()/_release() are called by the probe/disconnect functions of
879*4882a593Smuzhiyun * the bus-specific drivers.
880*4882a593Smuzhiyun */
881*4882a593Smuzhiyun int i2400m_setup(struct i2400m *, enum i2400m_bri bm_flags);
882*4882a593Smuzhiyun void i2400m_release(struct i2400m *);
883*4882a593Smuzhiyun
884*4882a593Smuzhiyun int i2400m_rx(struct i2400m *, struct sk_buff *);
885*4882a593Smuzhiyun struct i2400m_msg_hdr *i2400m_tx_msg_get(struct i2400m *, size_t *);
886*4882a593Smuzhiyun void i2400m_tx_msg_sent(struct i2400m *);
887*4882a593Smuzhiyun
888*4882a593Smuzhiyun
889*4882a593Smuzhiyun /*
890*4882a593Smuzhiyun * Utility functions
891*4882a593Smuzhiyun */
892*4882a593Smuzhiyun
893*4882a593Smuzhiyun static inline
i2400m_dev(struct i2400m * i2400m)894*4882a593Smuzhiyun struct device *i2400m_dev(struct i2400m *i2400m)
895*4882a593Smuzhiyun {
896*4882a593Smuzhiyun return i2400m->wimax_dev.net_dev->dev.parent;
897*4882a593Smuzhiyun }
898*4882a593Smuzhiyun
899*4882a593Smuzhiyun int i2400m_msg_check_status(const struct i2400m_l3l4_hdr *, char *, size_t);
900*4882a593Smuzhiyun int i2400m_msg_size_check(struct i2400m *, const struct i2400m_l3l4_hdr *,
901*4882a593Smuzhiyun size_t);
902*4882a593Smuzhiyun struct sk_buff *i2400m_msg_to_dev(struct i2400m *, const void *, size_t);
903*4882a593Smuzhiyun void i2400m_msg_to_dev_cancel_wait(struct i2400m *, int);
904*4882a593Smuzhiyun void i2400m_report_hook(struct i2400m *, const struct i2400m_l3l4_hdr *,
905*4882a593Smuzhiyun size_t);
906*4882a593Smuzhiyun void i2400m_report_hook_work(struct work_struct *);
907*4882a593Smuzhiyun int i2400m_cmd_enter_powersave(struct i2400m *);
908*4882a593Smuzhiyun int i2400m_cmd_exit_idle(struct i2400m *);
909*4882a593Smuzhiyun struct sk_buff *i2400m_get_device_info(struct i2400m *);
910*4882a593Smuzhiyun int i2400m_firmware_check(struct i2400m *);
911*4882a593Smuzhiyun int i2400m_set_idle_timeout(struct i2400m *, unsigned);
912*4882a593Smuzhiyun
913*4882a593Smuzhiyun static inline
usb_get_epd(struct usb_interface * iface,int ep)914*4882a593Smuzhiyun struct usb_endpoint_descriptor *usb_get_epd(struct usb_interface *iface, int ep)
915*4882a593Smuzhiyun {
916*4882a593Smuzhiyun return &iface->cur_altsetting->endpoint[ep].desc;
917*4882a593Smuzhiyun }
918*4882a593Smuzhiyun
919*4882a593Smuzhiyun int i2400m_op_rfkill_sw_toggle(struct wimax_dev *, enum wimax_rf_state);
920*4882a593Smuzhiyun void i2400m_report_tlv_rf_switches_status(struct i2400m *,
921*4882a593Smuzhiyun const struct i2400m_tlv_rf_switches_status *);
922*4882a593Smuzhiyun
923*4882a593Smuzhiyun /*
924*4882a593Smuzhiyun * Helpers for firmware backwards compatibility
925*4882a593Smuzhiyun *
926*4882a593Smuzhiyun * As we aim to support at least the firmware version that was
927*4882a593Smuzhiyun * released with the previous kernel/driver release, some code will be
928*4882a593Smuzhiyun * conditionally executed depending on the firmware version. On each
929*4882a593Smuzhiyun * release, the code to support fw releases past the last two ones
930*4882a593Smuzhiyun * will be purged.
931*4882a593Smuzhiyun *
932*4882a593Smuzhiyun * By making it depend on this macros, it is easier to keep it a tab
933*4882a593Smuzhiyun * on what has to go and what not.
934*4882a593Smuzhiyun */
935*4882a593Smuzhiyun static inline
i2400m_le_v1_3(struct i2400m * i2400m)936*4882a593Smuzhiyun unsigned i2400m_le_v1_3(struct i2400m *i2400m)
937*4882a593Smuzhiyun {
938*4882a593Smuzhiyun /* running fw is lower or v1.3 */
939*4882a593Smuzhiyun return i2400m->fw_version <= 0x00090001;
940*4882a593Smuzhiyun }
941*4882a593Smuzhiyun
942*4882a593Smuzhiyun static inline
i2400m_ge_v1_4(struct i2400m * i2400m)943*4882a593Smuzhiyun unsigned i2400m_ge_v1_4(struct i2400m *i2400m)
944*4882a593Smuzhiyun {
945*4882a593Smuzhiyun /* running fw is higher or v1.4 */
946*4882a593Smuzhiyun return i2400m->fw_version >= 0x00090002;
947*4882a593Smuzhiyun }
948*4882a593Smuzhiyun
949*4882a593Smuzhiyun
950*4882a593Smuzhiyun /*
951*4882a593Smuzhiyun * Do a millisecond-sleep for allowing wireshark to dump all the data
952*4882a593Smuzhiyun * packets. Used only for debugging.
953*4882a593Smuzhiyun */
954*4882a593Smuzhiyun static inline
__i2400m_msleep(unsigned ms)955*4882a593Smuzhiyun void __i2400m_msleep(unsigned ms)
956*4882a593Smuzhiyun {
957*4882a593Smuzhiyun #if 1
958*4882a593Smuzhiyun #else
959*4882a593Smuzhiyun msleep(ms);
960*4882a593Smuzhiyun #endif
961*4882a593Smuzhiyun }
962*4882a593Smuzhiyun
963*4882a593Smuzhiyun
964*4882a593Smuzhiyun /* module initialization helpers */
965*4882a593Smuzhiyun int i2400m_barker_db_init(const char *);
966*4882a593Smuzhiyun void i2400m_barker_db_exit(void);
967*4882a593Smuzhiyun
968*4882a593Smuzhiyun
969*4882a593Smuzhiyun
970*4882a593Smuzhiyun #endif /* #ifndef __I2400M_H__ */
971