GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / uwb / i1480 / i1480u-wlp / lc.c
blob3736d76c703fc5b3ba448032299593de7066f828
2 #include <linux/gfp.h>
3 #include <linux/if_arp.h>
4 #include <linux/etherdevice.h>
6 #include "i1480u-wlp.h"
10 static inline
11 void i1480u_init(struct i1480u *i1480u)
13 /* nothing so far... doesn't it suck? */
14 spin_lock_init(&i1480u->lock);
15 INIT_LIST_HEAD(&i1480u->tx_list);
16 spin_lock_init(&i1480u->tx_list_lock);
17 wlp_options_init(&i1480u->options);
18 edc_init(&i1480u->tx_errors);
19 edc_init(&i1480u->rx_errors);
20 #ifdef i1480u_FLOW_CONTROL
21 edc_init(&i1480u->notif_edc);
22 #endif
23 stats_init(&i1480u->lqe_stats);
24 stats_init(&i1480u->rssi_stats);
25 wlp_init(&i1480u->wlp);
28 /**
29 * Fill WLP device information structure
31 * The structure will contain a few character arrays, each ending with a
32 * null terminated string. Each string has to fit (excluding terminating
33 * character) into a specified range obtained from the WLP substack.
35 * It is still not clear exactly how this device information should be
36 * obtained. Until we find out we use the USB device descriptor as backup, some
37 * information elements have intuitive mappings, other not.
39 static
40 void i1480u_fill_device_info(struct wlp *wlp, struct wlp_device_info *dev_info)
42 struct i1480u *i1480u = container_of(wlp, struct i1480u, wlp);
43 struct usb_device *usb_dev = i1480u->usb_dev;
44 /* Treat device name and model name the same */
45 if (usb_dev->descriptor.iProduct) {
46 usb_string(usb_dev, usb_dev->descriptor.iProduct,
47 dev_info->name, sizeof(dev_info->name));
48 usb_string(usb_dev, usb_dev->descriptor.iProduct,
49 dev_info->model_name, sizeof(dev_info->model_name));
51 if (usb_dev->descriptor.iManufacturer)
52 usb_string(usb_dev, usb_dev->descriptor.iManufacturer,
53 dev_info->manufacturer,
54 sizeof(dev_info->manufacturer));
55 scnprintf(dev_info->model_nr, sizeof(dev_info->model_nr), "%04x",
56 __le16_to_cpu(usb_dev->descriptor.bcdDevice));
57 if (usb_dev->descriptor.iSerialNumber)
58 usb_string(usb_dev, usb_dev->descriptor.iSerialNumber,
59 dev_info->serial, sizeof(dev_info->serial));
60 dev_info->prim_dev_type.category = cpu_to_le16(WLP_DEV_CAT_OTHER);
63 #ifdef i1480u_FLOW_CONTROL
64 /**
65 * Callback for the notification endpoint
67 * This mostly controls the xon/xoff protocol. In case of hard error,
68 * we stop the queue. If not, we always retry.
70 static
71 void i1480u_notif_cb(struct urb *urb, struct pt_regs *regs)
73 struct i1480u *i1480u = urb->context;
74 struct usb_interface *usb_iface = i1480u->usb_iface;
75 struct device *dev = &usb_iface->dev;
76 int result;
78 switch (urb->status) {
79 case 0: /* Got valid data, do xon/xoff */
80 switch (i1480u->notif_buffer[0]) {
81 case 'N':
82 dev_err(dev, "XOFF STOPPING queue at %lu\n", jiffies);
83 netif_stop_queue(i1480u->net_dev);
84 break;
85 case 'A':
86 dev_err(dev, "XON STARTING queue at %lu\n", jiffies);
87 netif_start_queue(i1480u->net_dev);
88 break;
89 default:
90 dev_err(dev, "NEP: unknown data 0x%02hhx\n",
91 i1480u->notif_buffer[0]);
93 break;
94 case -ECONNRESET: /* Controlled situation ... */
95 case -ENOENT: /* we killed the URB... */
96 dev_err(dev, "NEP: URB reset/noent %d\n", urb->status);
97 goto error;
98 case -ESHUTDOWN: /* going away! */
99 dev_err(dev, "NEP: URB down %d\n", urb->status);
100 goto error;
101 default: /* Retry unless it gets ugly */
102 if (edc_inc(&i1480u->notif_edc, EDC_MAX_ERRORS,
103 EDC_ERROR_TIMEFRAME)) {
104 dev_err(dev, "NEP: URB max acceptable errors "
105 "exceeded; resetting device\n");
106 goto error_reset;
108 dev_err(dev, "NEP: URB error %d\n", urb->status);
109 break;
111 result = usb_submit_urb(urb, GFP_ATOMIC);
112 if (result < 0) {
113 dev_err(dev, "NEP: Can't resubmit URB: %d; resetting device\n",
114 result);
115 goto error_reset;
117 return;
119 error_reset:
120 wlp_reset_all(&i1480-wlp);
121 error:
122 netif_stop_queue(i1480u->net_dev);
123 return;
125 #endif
127 static const struct net_device_ops i1480u_netdev_ops = {
128 .ndo_open = i1480u_open,
129 .ndo_stop = i1480u_stop,
130 .ndo_start_xmit = i1480u_hard_start_xmit,
131 .ndo_tx_timeout = i1480u_tx_timeout,
132 .ndo_set_config = i1480u_set_config,
133 .ndo_change_mtu = i1480u_change_mtu,
136 static
137 int i1480u_add(struct i1480u *i1480u, struct usb_interface *iface)
139 int result = -ENODEV;
140 struct wlp *wlp = &i1480u->wlp;
141 struct usb_device *usb_dev = interface_to_usbdev(iface);
142 struct net_device *net_dev = i1480u->net_dev;
143 struct uwb_rc *rc;
144 struct uwb_dev *uwb_dev;
145 #ifdef i1480u_FLOW_CONTROL
146 struct usb_endpoint_descriptor *epd;
147 #endif
149 i1480u->usb_dev = usb_get_dev(usb_dev);
150 i1480u->usb_iface = iface;
151 rc = uwb_rc_get_by_grandpa(&i1480u->usb_dev->dev);
152 if (rc == NULL) {
153 dev_err(&iface->dev, "Cannot get associated UWB Radio "
154 "Controller\n");
155 goto out;
157 wlp->xmit_frame = i1480u_xmit_frame;
158 wlp->fill_device_info = i1480u_fill_device_info;
159 wlp->stop_queue = i1480u_stop_queue;
160 wlp->start_queue = i1480u_start_queue;
161 result = wlp_setup(wlp, rc, net_dev);
162 if (result < 0) {
163 dev_err(&iface->dev, "Cannot setup WLP\n");
164 goto error_wlp_setup;
166 result = 0;
167 ether_setup(net_dev); /* make it an etherdevice */
168 uwb_dev = &rc->uwb_dev;
170 memcpy(net_dev->dev_addr, uwb_dev->mac_addr.data,
171 sizeof(net_dev->dev_addr));
173 net_dev->hard_header_len = sizeof(struct untd_hdr_cmp)
174 + sizeof(struct wlp_tx_hdr)
175 + WLP_DATA_HLEN
176 + ETH_HLEN;
177 net_dev->mtu = 3500;
178 net_dev->tx_queue_len = 20;
180 net_dev->flags &= ~IFF_MULTICAST;
181 net_dev->features &= ~NETIF_F_SG;
182 net_dev->features &= ~NETIF_F_FRAGLIST;
183 /* All NETIF_F_*_CSUM disabled */
184 net_dev->features |= NETIF_F_HIGHDMA;
185 net_dev->watchdog_timeo = 5*HZ;
187 net_dev->netdev_ops = &i1480u_netdev_ops;
189 #ifdef i1480u_FLOW_CONTROL
190 /* Notification endpoint setup (submitted when we open the device) */
191 i1480u->notif_urb = usb_alloc_urb(0, GFP_KERNEL);
192 if (i1480u->notif_urb == NULL) {
193 dev_err(&iface->dev, "Unable to allocate notification URB\n");
194 result = -ENOMEM;
195 goto error_urb_alloc;
197 epd = &iface->cur_altsetting->endpoint[0].desc;
198 usb_fill_int_urb(i1480u->notif_urb, usb_dev,
199 usb_rcvintpipe(usb_dev, epd->bEndpointAddress),
200 i1480u->notif_buffer, sizeof(i1480u->notif_buffer),
201 i1480u_notif_cb, i1480u, epd->bInterval);
203 #endif
205 i1480u->tx_inflight.max = i1480u_TX_INFLIGHT_MAX;
206 i1480u->tx_inflight.threshold = i1480u_TX_INFLIGHT_THRESHOLD;
207 i1480u->tx_inflight.restart_ts = jiffies;
208 usb_set_intfdata(iface, i1480u);
209 return result;
211 #ifdef i1480u_FLOW_CONTROL
212 error_urb_alloc:
213 #endif
214 wlp_remove(wlp);
215 error_wlp_setup:
216 uwb_rc_put(rc);
217 out:
218 usb_put_dev(i1480u->usb_dev);
219 return result;
222 static void i1480u_rm(struct i1480u *i1480u)
224 struct uwb_rc *rc = i1480u->wlp.rc;
225 usb_set_intfdata(i1480u->usb_iface, NULL);
226 #ifdef i1480u_FLOW_CONTROL
227 usb_kill_urb(i1480u->notif_urb);
228 usb_free_urb(i1480u->notif_urb);
229 #endif
230 wlp_remove(&i1480u->wlp);
231 uwb_rc_put(rc);
232 usb_put_dev(i1480u->usb_dev);
235 /** Just setup @net_dev's i1480u private data */
236 static void i1480u_netdev_setup(struct net_device *net_dev)
238 struct i1480u *i1480u = netdev_priv(net_dev);
239 /* Initialize @i1480u */
240 memset(i1480u, 0, sizeof(*i1480u));
241 i1480u_init(i1480u);
245 * Probe a i1480u interface and register it
247 * @iface: USB interface to link to
248 * @id: USB class/subclass/protocol id
249 * @returns: 0 if ok, < 0 errno code on error.
251 * Does basic housekeeping stuff and then allocs a netdev with space
252 * for the i1480u data. Initializes, registers in i1480u, registers in
253 * netdev, ready to go.
255 static int i1480u_probe(struct usb_interface *iface,
256 const struct usb_device_id *id)
258 int result;
259 struct net_device *net_dev;
260 struct device *dev = &iface->dev;
261 struct i1480u *i1480u;
263 /* Allocate instance [calls i1480u_netdev_setup() on it] */
264 result = -ENOMEM;
265 net_dev = alloc_netdev(sizeof(*i1480u), "wlp%d", i1480u_netdev_setup);
266 if (net_dev == NULL) {
267 dev_err(dev, "no memory for network device instance\n");
268 goto error_alloc_netdev;
270 SET_NETDEV_DEV(net_dev, dev);
271 i1480u = netdev_priv(net_dev);
272 i1480u->net_dev = net_dev;
273 result = i1480u_add(i1480u, iface); /* Now setup all the wlp stuff */
274 if (result < 0) {
275 dev_err(dev, "cannot add i1480u device: %d\n", result);
276 goto error_i1480u_add;
278 result = register_netdev(net_dev); /* Okey dokey, bring it up */
279 if (result < 0) {
280 dev_err(dev, "cannot register network device: %d\n", result);
281 goto error_register_netdev;
283 i1480u_sysfs_setup(i1480u);
284 if (result < 0)
285 goto error_sysfs_init;
286 return 0;
288 error_sysfs_init:
289 unregister_netdev(net_dev);
290 error_register_netdev:
291 i1480u_rm(i1480u);
292 error_i1480u_add:
293 free_netdev(net_dev);
294 error_alloc_netdev:
295 return result;
300 * Disconect a i1480u from the system.
302 * i1480u_stop() has been called before, so al the rx and tx contexts
303 * have been taken down already. Make sure the queue is stopped,
304 * unregister netdev and i1480u, free and kill.
306 static void i1480u_disconnect(struct usb_interface *iface)
308 struct i1480u *i1480u;
309 struct net_device *net_dev;
311 i1480u = usb_get_intfdata(iface);
312 net_dev = i1480u->net_dev;
313 netif_stop_queue(net_dev);
314 #ifdef i1480u_FLOW_CONTROL
315 usb_kill_urb(i1480u->notif_urb);
316 #endif
317 i1480u_sysfs_release(i1480u);
318 unregister_netdev(net_dev);
319 i1480u_rm(i1480u);
320 free_netdev(net_dev);
323 static struct usb_device_id i1480u_id_table[] = {
325 .match_flags = USB_DEVICE_ID_MATCH_DEVICE \
326 | USB_DEVICE_ID_MATCH_DEV_INFO \
327 | USB_DEVICE_ID_MATCH_INT_INFO,
328 .idVendor = 0x8086,
329 .idProduct = 0x0c3b,
330 .bDeviceClass = 0xef,
331 .bDeviceSubClass = 0x02,
332 .bDeviceProtocol = 0x02,
333 .bInterfaceClass = 0xff,
334 .bInterfaceSubClass = 0xff,
335 .bInterfaceProtocol = 0xff,
339 MODULE_DEVICE_TABLE(usb, i1480u_id_table);
341 static struct usb_driver i1480u_driver = {
342 .name = KBUILD_MODNAME,
343 .probe = i1480u_probe,
344 .disconnect = i1480u_disconnect,
345 .id_table = i1480u_id_table,
348 static int __init i1480u_driver_init(void)
350 return usb_register(&i1480u_driver);
352 module_init(i1480u_driver_init);
355 static void __exit i1480u_driver_exit(void)
357 usb_deregister(&i1480u_driver);
359 module_exit(i1480u_driver_exit);
361 MODULE_AUTHOR("Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>");
362 MODULE_DESCRIPTION("i1480 Wireless UWB Link WLP networking for USB");
363 MODULE_LICENSE("GPL");