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 "i2400m-usb.h"
62 #define D_SUBMODULE notif
63 #include "usb-debug-levels.h"
67 __le32 i2400m_ZERO_BARKER[4] = { 0, 0, 0, 0 };
71 * Process a received notification
73 * In normal operation mode, we can only receive two types of payloads
74 * on the notification endpoint:
76 * - a reboot barker, we do a bootstrap (the device has reseted).
78 * - a block of zeroes: there is pending data in the IN endpoint
81 int i2400mu_notification_grok(struct i2400mu *i2400mu, const void *buf,
85 struct device *dev = &i2400mu->usb_iface->dev;
86 struct i2400m *i2400m = &i2400mu->i2400m;
88 d_fnstart(4, dev, "(i2400m %p buf %p buf_len %zu)\n",
89 i2400mu, buf, buf_len);
91 if (buf_len < sizeof(i2400m_ZERO_BARKER))
92 /* Not a bug, just ignore */
95 if (!memcmp(i2400m_ZERO_BARKER, buf, sizeof(i2400m_ZERO_BARKER))) {
96 i2400mu_rx_kick(i2400mu);
99 ret = i2400m_is_boot_barker(i2400m, buf, buf_len);
100 if (unlikely(ret >= 0))
101 ret = i2400m_dev_reset_handle(i2400m, "device rebooted");
102 else /* Unknown or unexpected data in the notif message */
103 i2400m_unknown_barker(i2400m, buf, buf_len);
106 d_fnend(4, dev, "(i2400m %p buf %p buf_len %zu) = %d\n",
107 i2400mu, buf, buf_len, ret);
113 * URB callback for the notification endpoint
115 * @urb: the urb received from the notification endpoint
117 * This function will just process the USB side of the transaction,
118 * checking everything is fine, pass the processing to
119 * i2400m_notification_grok() and resubmit the URB.
122 void i2400mu_notification_cb(struct urb *urb)
125 struct i2400mu *i2400mu = urb->context;
126 struct device *dev = &i2400mu->usb_iface->dev;
128 d_fnstart(4, dev, "(urb %p status %d actual_length %d)\n",
129 urb, urb->status, urb->actual_length);
133 ret = i2400mu_notification_grok(i2400mu, urb->transfer_buffer,
135 if (ret == -EIO && edc_inc(&i2400mu->urb_edc, EDC_MAX_ERRORS,
136 EDC_ERROR_TIMEFRAME))
138 if (ret == -ENOMEM) /* uff...power cycle? shutdown? */
141 case -EINVAL: /* while removing driver */
142 case -ENODEV: /* dev disconnect ... */
143 case -ENOENT: /* ditto */
144 case -ESHUTDOWN: /* URB killed */
145 case -ECONNRESET: /* disconnection */
146 goto out; /* Notify around */
147 default: /* Some error? */
148 if (edc_inc(&i2400mu->urb_edc,
149 EDC_MAX_ERRORS, EDC_ERROR_TIMEFRAME))
151 dev_err(dev, "notification: URB error %d, retrying\n",
154 usb_mark_last_busy(i2400mu->usb_dev);
155 ret = usb_submit_urb(i2400mu->notif_urb, GFP_ATOMIC);
158 case -EINVAL: /* while removing driver */
159 case -ENODEV: /* dev disconnect ... */
160 case -ENOENT: /* ditto */
161 case -ESHUTDOWN: /* URB killed */
162 case -ECONNRESET: /* disconnection */
163 break; /* just ignore */
164 default: /* Some error? */
165 dev_err(dev, "notification: cannot submit URB: %d\n", ret);
168 d_fnend(4, dev, "(urb %p status %d actual_length %d) = void\n",
169 urb, urb->status, urb->actual_length);
173 dev_err(dev, "maximum errors in notification URB exceeded; "
174 "resetting device\n");
176 usb_queue_reset_device(i2400mu->usb_iface);
178 d_fnend(4, dev, "(urb %p status %d actual_length %d) = void\n",
179 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);