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