2 * Intel Wireless WiMAX Connection 2400m over USB
3 * Notification handling
6 * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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
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.
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.
35 * Intel Corporation <linux-wimax@intel.com>
36 * Yanir Lubetkin <yanirx.lubetkin@intel.com>
37 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
38 * - Initial implementation
41 * The notification endpoint is active when the device is not in boot
42 * mode; in here we just read and get notifications; based on those,
43 * we act to either reinitialize the device after a reboot or to
44 * submit a RX request.
48 * i2400mu_usb_notification_setup()
50 * i2400mu_usb_notification_release()
52 * i2400mu_usb_notification_cb() Called when a URB is ready
53 * i2400mu_notif_grok()
54 * i2400m_dev_reset_handle()
57 #include <linux/usb.h>
58 #include "i2400m-usb.h"
61 #define D_SUBMODULE notif
62 #include "usb-debug-levels.h"
66 __le32 i2400m_ZERO_BARKER[4] = { 0, 0, 0, 0 };
70 * Process a received notification
72 * In normal operation mode, we can only receive two types of payloads
73 * on the notification endpoint:
75 * - a reboot barker, we do a bootstrap (the device has reseted).
77 * - a block of zeroes: there is pending data in the IN endpoint
80 int i2400mu_notification_grok(struct i2400mu *i2400mu, const void *buf,
84 struct device *dev = &i2400mu->usb_iface->dev;
85 struct i2400m *i2400m = &i2400mu->i2400m;
87 d_fnstart(4, dev, "(i2400m %p buf %p buf_len %zu)\n",
88 i2400mu, buf, buf_len);
90 if (buf_len < sizeof(i2400m_NBOOT_BARKER))
91 /* Not a bug, just ignore */
93 if (!memcmp(i2400m_NBOOT_BARKER, buf, sizeof(i2400m_NBOOT_BARKER))
94 || !memcmp(i2400m_SBOOT_BARKER, buf, sizeof(i2400m_SBOOT_BARKER)))
95 ret = i2400m_dev_reset_handle(i2400m);
96 else if (!memcmp(i2400m_ZERO_BARKER, buf, sizeof(i2400m_ZERO_BARKER))) {
97 i2400mu_rx_kick(i2400mu);
99 } else { /* Unknown or unexpected data in the notif message */
102 dev_err(dev, "HW BUG? Unknown/unexpected data in notification "
103 "message (%zu bytes)\n", buf_len);
104 snprintf(prefix, sizeof(prefix), "%s %s: ",
105 dev_driver_string(dev) , dev->bus_id);
107 print_hex_dump(KERN_ERR, prefix, DUMP_PREFIX_OFFSET,
109 printk(KERN_ERR "%s... (only first 64 bytes "
110 "dumped)\n", prefix);
112 print_hex_dump(KERN_ERR, prefix, DUMP_PREFIX_OFFSET,
113 8, 4, buf, buf_len, 0);
116 d_fnend(4, dev, "(i2400m %p buf %p buf_len %zu) = %d\n",
117 i2400mu, buf, buf_len, ret);
123 * URB callback for the notification endpoint
125 * @urb: the urb received from the notification endpoint
127 * This function will just process the USB side of the transaction,
128 * checking everything is fine, pass the processing to
129 * i2400m_notification_grok() and resubmit the URB.
132 void i2400mu_notification_cb(struct urb *urb)
135 struct i2400mu *i2400mu = urb->context;
136 struct device *dev = &i2400mu->usb_iface->dev;
138 d_fnstart(4, dev, "(urb %p status %d actual_length %d)\n",
139 urb, urb->status, urb->actual_length);
143 ret = i2400mu_notification_grok(i2400mu, urb->transfer_buffer,
145 if (ret == -EIO && edc_inc(&i2400mu->urb_edc, EDC_MAX_ERRORS,
146 EDC_ERROR_TIMEFRAME))
148 if (ret == -ENOMEM) /* uff...power cycle? shutdown? */
151 case -EINVAL: /* while removing driver */
152 case -ENODEV: /* dev disconnect ... */
153 case -ENOENT: /* ditto */
154 case -ESHUTDOWN: /* URB killed */
155 case -ECONNRESET: /* disconnection */
156 goto out; /* Notify around */
157 default: /* Some error? */
158 if (edc_inc(&i2400mu->urb_edc,
159 EDC_MAX_ERRORS, EDC_ERROR_TIMEFRAME))
161 dev_err(dev, "notification: URB error %d, retrying\n",
164 usb_mark_last_busy(i2400mu->usb_dev);
165 ret = usb_submit_urb(i2400mu->notif_urb, GFP_ATOMIC);
168 case -EINVAL: /* while removing driver */
169 case -ENODEV: /* dev disconnect ... */
170 case -ENOENT: /* ditto */
171 case -ESHUTDOWN: /* URB killed */
172 case -ECONNRESET: /* disconnection */
173 break; /* just ignore */
174 default: /* Some error? */
175 dev_err(dev, "notification: cannot submit URB: %d\n", ret);
178 d_fnend(4, dev, "(urb %p status %d actual_length %d) = void\n",
179 urb, urb->status, urb->actual_length);
183 dev_err(dev, "maximum errors in notification URB exceeded; "
184 "resetting device\n");
186 usb_queue_reset_device(i2400mu->usb_iface);
188 d_fnend(4, dev, "(urb %p status %d actual_length %d) = void\n",
189 urb, urb->status, urb->actual_length);
195 * setup the notification endpoint
197 * @i2400m: device descriptor
199 * This procedure prepares the notification urb and handler for receiving
200 * unsolicited barkers from the device.
202 int i2400mu_notification_setup(struct i2400mu *i2400mu)
204 struct device *dev = &i2400mu->usb_iface->dev;
205 int usb_pipe, ret = 0;
206 struct usb_endpoint_descriptor *epd;
209 d_fnstart(4, dev, "(i2400m %p)\n", i2400mu);
210 buf = kmalloc(I2400MU_MAX_NOTIFICATION_LEN, GFP_KERNEL | GFP_DMA);
212 dev_err(dev, "notification: buffer allocation failed\n");
214 goto error_buf_alloc;
217 i2400mu->notif_urb = usb_alloc_urb(0, GFP_KERNEL);
218 if (!i2400mu->notif_urb) {
220 dev_err(dev, "notification: cannot allocate URB\n");
221 goto error_alloc_urb;
223 epd = usb_get_epd(i2400mu->usb_iface, I2400MU_EP_NOTIFICATION);
224 usb_pipe = usb_rcvintpipe(i2400mu->usb_dev, epd->bEndpointAddress);
225 usb_fill_int_urb(i2400mu->notif_urb, i2400mu->usb_dev, usb_pipe,
226 buf, I2400MU_MAX_NOTIFICATION_LEN,
227 i2400mu_notification_cb, i2400mu, epd->bInterval);
228 ret = usb_submit_urb(i2400mu->notif_urb, GFP_KERNEL);
230 dev_err(dev, "notification: cannot submit URB: %d\n", ret);
233 d_fnend(4, dev, "(i2400m %p) = %d\n", i2400mu, ret);
237 usb_free_urb(i2400mu->notif_urb);
241 d_fnend(4, dev, "(i2400m %p) = %d\n", i2400mu, ret);
247 * Tear down of the notification mechanism
249 * @i2400m: device descriptor
251 * Kill the interrupt endpoint urb, free any allocated resources.
253 * We need to check if we have done it before as for example,
254 * _suspend() call this; if after a suspend() we get a _disconnect()
255 * (as the case is when hibernating), nothing bad happens.
257 void i2400mu_notification_release(struct i2400mu *i2400mu)
259 struct device *dev = &i2400mu->usb_iface->dev;
261 d_fnstart(4, dev, "(i2400mu %p)\n", i2400mu);
262 if (i2400mu->notif_urb != NULL) {
263 usb_kill_urb(i2400mu->notif_urb);
264 kfree(i2400mu->notif_urb->transfer_buffer);
265 usb_free_urb(i2400mu->notif_urb);
266 i2400mu->notif_urb = NULL;
268 d_fnend(4, dev, "(i2400mu %p)\n", i2400mu);