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_is_boot_barker()
55 * i2400m_dev_reset_handle()
58 #include <linux/usb.h>
59 #include <linux/slab.h>
60 #include "i2400m-usb.h"
63 #define D_SUBMODULE notif
64 #include "usb-debug-levels.h"
68 __le32 i2400m_ZERO_BARKER[4] = { 0, 0, 0, 0 };
72 * Process a received notification
74 * In normal operation mode, we can only receive two types of payloads
75 * on the notification endpoint:
77 * - a reboot barker, we do a bootstrap (the device has reseted).
79 * - a block of zeroes: there is pending data in the IN endpoint
82 int i2400mu_notification_grok(struct i2400mu *i2400mu, const void *buf,
86 struct device *dev = &i2400mu->usb_iface->dev;
87 struct i2400m *i2400m = &i2400mu->i2400m;
89 d_fnstart(4, dev, "(i2400m %p buf %p buf_len %zu)\n",
90 i2400mu, buf, buf_len);
92 if (buf_len < sizeof(i2400m_ZERO_BARKER))
93 /* Not a bug, just ignore */
96 if (!memcmp(i2400m_ZERO_BARKER, buf, sizeof(i2400m_ZERO_BARKER))) {
97 i2400mu_rx_kick(i2400mu);
100 ret = i2400m_is_boot_barker(i2400m, buf, buf_len);
101 if (unlikely(ret >= 0))
102 ret = i2400m_dev_reset_handle(i2400m, "device rebooted");
103 else /* Unknown or unexpected data in the notif message */
104 i2400m_unknown_barker(i2400m, buf, buf_len);
107 d_fnend(4, dev, "(i2400m %p buf %p buf_len %zu) = %d\n",
108 i2400mu, buf, buf_len, ret);
114 * URB callback for the notification endpoint
116 * @urb: the urb received from the notification endpoint
118 * This function will just process the USB side of the transaction,
119 * checking everything is fine, pass the processing to
120 * i2400m_notification_grok() and resubmit the URB.
123 void i2400mu_notification_cb(struct urb *urb)
126 struct i2400mu *i2400mu = urb->context;
127 struct device *dev = &i2400mu->usb_iface->dev;
129 d_fnstart(4, dev, "(urb %p status %d actual_length %d)\n",
130 urb, urb->status, urb->actual_length);
134 ret = i2400mu_notification_grok(i2400mu, urb->transfer_buffer,
136 if (ret == -EIO && edc_inc(&i2400mu->urb_edc, EDC_MAX_ERRORS,
137 EDC_ERROR_TIMEFRAME))
139 if (ret == -ENOMEM) /* uff...power cycle? shutdown? */
142 case -EINVAL: /* while removing driver */
143 case -ENODEV: /* dev disconnect ... */
144 case -ENOENT: /* ditto */
145 case -ESHUTDOWN: /* URB killed */
146 case -ECONNRESET: /* disconnection */
147 goto out; /* Notify around */
148 default: /* Some error? */
149 if (edc_inc(&i2400mu->urb_edc,
150 EDC_MAX_ERRORS, EDC_ERROR_TIMEFRAME))
152 dev_err(dev, "notification: URB error %d, retrying\n",
155 usb_mark_last_busy(i2400mu->usb_dev);
156 ret = usb_submit_urb(i2400mu->notif_urb, GFP_ATOMIC);
159 case -EINVAL: /* while removing driver */
160 case -ENODEV: /* dev disconnect ... */
161 case -ENOENT: /* ditto */
162 case -ESHUTDOWN: /* URB killed */
163 case -ECONNRESET: /* disconnection */
164 break; /* just ignore */
165 default: /* Some error? */
166 dev_err(dev, "notification: cannot submit URB: %d\n", ret);
169 d_fnend(4, dev, "(urb %p status %d actual_length %d) = void\n",
170 urb, urb->status, urb->actual_length);
174 dev_err(dev, "maximum errors in notification URB exceeded; "
175 "resetting device\n");
177 usb_queue_reset_device(i2400mu->usb_iface);
179 d_fnend(4, dev, "(urb %p status %d actual_length %d) = void\n",
180 urb, urb->status, urb->actual_length);
185 * setup the notification endpoint
187 * @i2400m: device descriptor
189 * This procedure prepares the notification urb and handler for receiving
190 * unsolicited barkers from the device.
192 int i2400mu_notification_setup(struct i2400mu *i2400mu)
194 struct device *dev = &i2400mu->usb_iface->dev;
195 int usb_pipe, ret = 0;
196 struct usb_endpoint_descriptor *epd;
199 d_fnstart(4, dev, "(i2400m %p)\n", i2400mu);
200 buf = kmalloc(I2400MU_MAX_NOTIFICATION_LEN, GFP_KERNEL | GFP_DMA);
202 dev_err(dev, "notification: buffer allocation failed\n");
204 goto error_buf_alloc;
207 i2400mu->notif_urb = usb_alloc_urb(0, GFP_KERNEL);
208 if (!i2400mu->notif_urb) {
210 dev_err(dev, "notification: cannot allocate URB\n");
211 goto error_alloc_urb;
213 epd = usb_get_epd(i2400mu->usb_iface,
214 i2400mu->endpoint_cfg.notification);
215 usb_pipe = usb_rcvintpipe(i2400mu->usb_dev, epd->bEndpointAddress);
216 usb_fill_int_urb(i2400mu->notif_urb, i2400mu->usb_dev, usb_pipe,
217 buf, I2400MU_MAX_NOTIFICATION_LEN,
218 i2400mu_notification_cb, i2400mu, epd->bInterval);
219 ret = usb_submit_urb(i2400mu->notif_urb, GFP_KERNEL);
221 dev_err(dev, "notification: cannot submit URB: %d\n", ret);
224 d_fnend(4, dev, "(i2400m %p) = %d\n", i2400mu, ret);
228 usb_free_urb(i2400mu->notif_urb);
232 d_fnend(4, dev, "(i2400m %p) = %d\n", i2400mu, ret);
238 * Tear down of the notification mechanism
240 * @i2400m: device descriptor
242 * Kill the interrupt endpoint urb, free any allocated resources.
244 * We need to check if we have done it before as for example,
245 * _suspend() call this; if after a suspend() we get a _disconnect()
246 * (as the case is when hibernating), nothing bad happens.
248 void i2400mu_notification_release(struct i2400mu *i2400mu)
250 struct device *dev = &i2400mu->usb_iface->dev;
252 d_fnstart(4, dev, "(i2400mu %p)\n", i2400mu);
253 if (i2400mu->notif_urb != NULL) {
254 usb_kill_urb(i2400mu->notif_urb);
255 kfree(i2400mu->notif_urb->transfer_buffer);
256 usb_free_urb(i2400mu->notif_urb);
257 i2400mu->notif_urb = NULL;
259 d_fnend(4, dev, "(i2400mu %p)\n", i2400mu);