2 * Intel Wireless WiMAX Connection 2400m
3 * USB specific TX 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 * - Initial implementation
38 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
39 * - Split transport/device specific
42 * Takes the TX messages in the i2400m's driver TX FIFO and sends them
43 * to the device until there are no more.
45 * If we fail sending the message, we just drop it. There isn't much
46 * we can do at this point. We could also retry, but the USB stack has
47 * already retried and still failed, so there is not much of a
48 * point. As well, most of the traffic is network, which has recovery
49 * methods for dropped packets.
51 * For sending we just obtain a FIFO buffer to send, send it to the
52 * USB bulk out, tell the TX FIFO code we have sent it; query for
53 * another one, etc... until done.
55 * We use a thread so we can call usb_autopm_enable() and
56 * usb_autopm_disable() for each transaction; this way when the device
57 * goes idle, it will suspend. It also has less overhead than a
58 * dedicated workqueue, as it is being used for a single task.
63 * i2400mu_tx_release()
65 * i2400mu_bus_tx_kick() - Called by the tx.c code when there
66 * is new data in the FIFO.
69 * i2400m_tx_msg_sent()
71 #include "i2400m-usb.h"
74 #define D_SUBMODULE tx
75 #include "usb-debug-levels.h"
79 * Get the next TX message in the TX FIFO and send it to the device
81 * Note that any iteration consumes a message to be sent, no matter if
82 * it succeeds or fails (we have no real way to retry or complain).
84 * Return: 0 if ok, < 0 errno code on hard error.
87 int i2400mu_tx(struct i2400mu
*i2400mu
, struct i2400m_msg_hdr
*tx_msg
,
91 struct i2400m
*i2400m
= &i2400mu
->i2400m
;
92 struct device
*dev
= &i2400mu
->usb_iface
->dev
;
93 int usb_pipe
, sent_size
, do_autopm
;
94 struct usb_endpoint_descriptor
*epd
;
96 d_fnstart(4, dev
, "(i2400mu %p)\n", i2400mu
);
97 do_autopm
= atomic_read(&i2400mu
->do_autopm
);
99 usb_autopm_get_interface(i2400mu
->usb_iface
) : 0;
101 dev_err(dev
, "TX: can't get autopm: %d\n", result
);
104 epd
= usb_get_epd(i2400mu
->usb_iface
, I2400MU_EP_BULK_OUT
);
105 usb_pipe
= usb_sndbulkpipe(i2400mu
->usb_dev
, epd
->bEndpointAddress
);
107 result
= usb_bulk_msg(i2400mu
->usb_dev
, usb_pipe
,
108 tx_msg
, tx_msg_size
, &sent_size
, HZ
);
109 usb_mark_last_busy(i2400mu
->usb_dev
);
112 if (sent_size
!= tx_msg_size
) { /* Too short? drop it */
113 dev_err(dev
, "TX: short write (%d B vs %zu "
114 "expected)\n", sent_size
, tx_msg_size
);
118 case -EINVAL
: /* while removing driver */
119 case -ENODEV
: /* dev disconnect ... */
120 case -ENOENT
: /* just ignore it */
121 case -ESHUTDOWN
: /* and exit */
125 default: /* Some error? */
126 if (edc_inc(&i2400mu
->urb_edc
,
127 EDC_MAX_ERRORS
, EDC_ERROR_TIMEFRAME
)) {
128 dev_err(dev
, "TX: maximum errors in URB "
129 "exceeded; resetting device\n");
130 usb_queue_reset_device(i2400mu
->usb_iface
);
132 dev_err(dev
, "TX: cannot send URB; retrying. "
133 "tx_msg @%zu %zu B [%d sent]: %d\n",
134 (void *) tx_msg
- i2400m
->tx_buf
,
135 tx_msg_size
, sent_size
, result
);
140 usb_autopm_put_interface(i2400mu
->usb_iface
);
141 d_fnend(4, dev
, "(i2400mu %p) = result\n", i2400mu
);
147 * Get the next TX message in the TX FIFO and send it to the device
149 * Note we exit the loop if i2400mu_tx() fails; that funtion only
150 * fails on hard error (failing to tx a buffer not being one of them,
156 int i2400mu_txd(void *_i2400mu
)
159 struct i2400mu
*i2400mu
= _i2400mu
;
160 struct i2400m
*i2400m
= &i2400mu
->i2400m
;
161 struct device
*dev
= &i2400mu
->usb_iface
->dev
;
162 struct i2400m_msg_hdr
*tx_msg
;
165 d_fnstart(4, dev
, "(i2400mu %p)\n", i2400mu
);
168 d_printf(2, dev
, "TX: waiting for messages\n");
170 wait_event_interruptible(
172 (kthread_should_stop() /* check this first! */
173 || (tx_msg
= i2400m_tx_msg_get(i2400m
, &tx_msg_size
)))
175 if (kthread_should_stop())
177 WARN_ON(tx_msg
== NULL
); /* should not happen...*/
178 d_printf(2, dev
, "TX: submitting %zu bytes\n", tx_msg_size
);
179 d_dump(5, dev
, tx_msg
, tx_msg_size
);
180 /* Yeah, we ignore errors ... not much we can do */
181 i2400mu_tx(i2400mu
, tx_msg
, tx_msg_size
);
182 i2400m_tx_msg_sent(i2400m
); /* ack it, advance the FIFO */
186 d_fnend(4, dev
, "(i2400mu %p) = %d\n", i2400mu
, result
);
192 * i2400m TX engine notifies us that there is data in the FIFO ready
195 * If there is a URB in flight, don't do anything; when it finishes,
196 * it will see there is data in the FIFO and send it. Else, just
199 void i2400mu_bus_tx_kick(struct i2400m
*i2400m
)
201 struct i2400mu
*i2400mu
= container_of(i2400m
, struct i2400mu
, i2400m
);
202 struct device
*dev
= &i2400mu
->usb_iface
->dev
;
204 d_fnstart(3, dev
, "(i2400m %p) = void\n", i2400m
);
205 wake_up_all(&i2400mu
->tx_wq
);
206 d_fnend(3, dev
, "(i2400m %p) = void\n", i2400m
);
210 int i2400mu_tx_setup(struct i2400mu
*i2400mu
)
213 struct i2400m
*i2400m
= &i2400mu
->i2400m
;
214 struct device
*dev
= &i2400mu
->usb_iface
->dev
;
215 struct wimax_dev
*wimax_dev
= &i2400m
->wimax_dev
;
217 i2400mu
->tx_kthread
= kthread_run(i2400mu_txd
, i2400mu
, "%s-tx",
219 if (IS_ERR(i2400mu
->tx_kthread
)) {
220 result
= PTR_ERR(i2400mu
->tx_kthread
);
221 dev_err(dev
, "TX: cannot start thread: %d\n", result
);
226 void i2400mu_tx_release(struct i2400mu
*i2400mu
)
228 kthread_stop(i2400mu
->tx_kthread
);