Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
i2400m-usb.h
Go to the documentation of this file.
1 /*
2  * Intel Wireless WiMAX Connection 2400m
3  * USB-specific i2400m driver definitions
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 <[email protected]>
36  * Inaky Perez-Gonzalez <[email protected]>
37  * Yanir Lubetkin <[email protected]>
38  * - Initial implementation
39  *
40  *
41  * This driver implements the bus-specific part of the i2400m for
42  * USB. Check i2400m.h for a generic driver description.
43  *
44  * ARCHITECTURE
45  *
46  * This driver listens to notifications sent from the notification
47  * endpoint (in usb-notif.c); when data is ready to read, the code in
48  * there schedules a read from the device (usb-rx.c) and then passes
49  * the data to the generic RX code (rx.c).
50  *
51  * When the generic driver needs to send data (network or control), it
52  * queues up in the TX FIFO (tx.c) and that will notify the driver
53  * through the i2400m->bus_tx_kick() callback
54  * (usb-tx.c:i2400mu_bus_tx_kick) which will send the items in the
55  * FIFO queue.
56  *
57  * This driver, as well, implements the USB-specific ops for the generic
58  * driver to be able to setup/teardown communication with the device
59  * [i2400m_bus_dev_start() and i2400m_bus_dev_stop()], reseting the
60  * device [i2400m_bus_reset()] and performing firmware upload
61  * [i2400m_bus_bm_cmd() and i2400_bus_bm_wait_for_ack()].
62  */
63 
64 #ifndef __I2400M_USB_H__
65 #define __I2400M_USB_H__
66 
67 #include "i2400m.h"
68 #include <linux/kthread.h>
69 
70 
71 /*
72  * Error Density Count: cheapo error density (over time) counter
73  *
74  * Originally by Reinette Chatre <[email protected]>
75  *
76  * Embed an 'struct edc' somewhere. Each time there is a soft or
77  * retryable error, call edc_inc() and check if the error top
78  * watermark has been reached.
79  */
80 enum {
83 };
84 
85 /* error density counter */
86 struct edc {
87  unsigned long timestart;
89 };
90 
92  unsigned char bulk_out;
93  unsigned char notification;
94  unsigned char reset_cold;
95  unsigned char bulk_in;
96 };
97 
98 static inline void edc_init(struct edc *edc)
99 {
100  edc->timestart = jiffies;
101 }
102 
129 static inline int edc_inc(struct edc *edc, u16 max_err, u16 timeframe)
130 {
131  unsigned long now;
132 
133  now = jiffies;
134  if (now - edc->timestart > timeframe) {
135  edc->errorcount = 1;
136  edc->timestart = now;
137  } else if (++edc->errorcount > max_err) {
138  edc->errorcount = 0;
139  edc->timestart = now;
140  return 1;
141  }
142  return 0;
143 }
144 
145 /* Host-Device interface for USB */
146 enum {
151 
152  /* Device IDs */
156 };
157 
158 
219 struct i2400mu {
220  struct i2400m i2400m; /* FIRST! See doc */
221 
222  struct usb_device *usb_dev;
224  struct edc urb_edc; /* Error density counter */
226 
227  struct urb *notif_urb;
230 
237 
239  unsigned i6050:1; /* 1 if this is a 6050 based SKU */
240 };
241 
242 
243 static inline
244 void i2400mu_init(struct i2400mu *i2400mu)
245 {
246  i2400m_init(&i2400mu->i2400m);
247  edc_init(&i2400mu->urb_edc);
248  init_waitqueue_head(&i2400mu->tx_wq);
249  atomic_set(&i2400mu->rx_pending_count, 0);
250  init_waitqueue_head(&i2400mu->rx_wq);
251  i2400mu->rx_size = PAGE_SIZE - sizeof(struct skb_shared_info);
252  atomic_set(&i2400mu->do_autopm, 1);
253  i2400mu->rx_size_auto_shrink = 1;
254 }
255 
256 extern int i2400mu_notification_setup(struct i2400mu *);
257 extern void i2400mu_notification_release(struct i2400mu *);
258 
259 extern int i2400mu_rx_setup(struct i2400mu *);
260 extern void i2400mu_rx_release(struct i2400mu *);
261 extern void i2400mu_rx_kick(struct i2400mu *);
262 
263 extern int i2400mu_tx_setup(struct i2400mu *);
264 extern void i2400mu_tx_release(struct i2400mu *);
265 extern void i2400mu_bus_tx_kick(struct i2400m *);
266 
267 extern ssize_t i2400mu_bus_bm_cmd_send(struct i2400m *,
268  const struct i2400m_bootrom_header *,
269  size_t, int);
271  struct i2400m_bootrom_header *,
272  size_t);
273 #endif /* #ifndef __I2400M_USB_H__ */