86 #include <linux/slab.h>
91 #define D_SUBMODULE rx
122 const size_t max_pkt_size = 512;
124 rx_size = 2 * i2400mu->
rx_size;
125 if (rx_size % max_pkt_size == 0) {
128 "RX: expected size grew to %zu [adjusted -8] "
133 "RX: expected size grew to %zu from %zu\n",
142 const size_t max_pkt_size = 512;
149 size_t new_rx_size = i2400mu->
rx_size / 2;
150 if (avg_rx_size < new_rx_size) {
151 if (new_rx_size % max_pkt_size == 0) {
154 "RX: expected size shrank to %zu "
155 "[adjusted -8] from %zu\n",
156 new_rx_size, i2400mu->
rx_size);
159 "RX: expected size shrank to %zu "
161 new_rx_size, i2400mu->
rx_size);
162 i2400mu->
rx_size = new_rx_size;
192 struct sk_buff *i2400mu_rx(
struct i2400mu *i2400mu,
struct sk_buff *rx_skb)
196 int usb_pipe,
read_size, rx_size, do_autopm;
198 const size_t max_pkt_size = 512;
200 d_fnstart(4, dev,
"(i2400mu %p)\n", i2400mu);
203 usb_autopm_get_interface(i2400mu->
usb_iface) : 0;
205 dev_err(dev,
"RX: can't get autopm: %d\n", result);
211 rx_size = skb_end_pointer(rx_skb) - rx_skb->
data - rx_skb->
len;
212 if (
unlikely(rx_size % max_pkt_size == 0)) {
214 d_printf(1, dev,
"RX: rx_size adapted to %d [-8]\n", rx_size);
218 rx_size, &read_size, 200);
219 usb_mark_last_busy(i2400mu->
usb_dev);
239 dev_err(dev,
"BM-CMD: too many stalls in "
240 "URB; resetting device\n");
254 rx_size = i2400mu_rx_size_grow(i2400mu);
255 if (rx_size <= (1 << 16))
257 else if (printk_ratelimit()) {
258 dev_err(dev,
"BUG? rx_size up to %d\n", rx_size);
265 if (new_skb ==
NULL) {
266 if (printk_ratelimit())
267 dev_err(dev,
"RX: Can't reallocate skb to %d; "
268 "RX dropped\n", rx_size);
277 d_printf(1, dev,
"RX: size changed to %d, received %d, "
278 "copied %d, capacity %ld\n",
279 rx_size, read_size, rx_skb->
len,
280 (
long) skb_end_offset(new_skb));
288 dev_err(dev,
"RX: timeout: %d\n", result);
295 dev_err(dev,
"RX: error receiving URB: %d, retrying\n", result);
300 usb_autopm_put_interface(i2400mu->
usb_iface);
301 d_fnend(4, dev,
"(i2400mu %p) = %p\n", i2400mu, rx_skb);
305 dev_err(dev,
"RX: maximum errors in URB exceeded; "
306 "resetting device\n");
309 rx_skb = ERR_PTR(result);
331 int i2400mu_rxd(
void *_i2400mu)
334 struct i2400mu *i2400mu = _i2400mu;
343 d_fnstart(4, dev,
"(i2400mu %p)\n", i2400mu);
347 spin_unlock_irqrestore(&i2400m->
rx_lock, flags);
349 d_printf(2, dev,
"RX: waiting for messages\n");
361 d_printf(2, dev,
"RX: reading up to %d bytes\n", rx_size);
363 if (rx_skb ==
NULL) {
364 dev_err(dev,
"RX: can't allocate skb [%d bytes]\n",
371 rx_skb = i2400mu_rx(i2400mu, rx_skb);
372 result = PTR_ERR(rx_skb);
376 if (rx_skb ==
NULL || rx_skb->
len == 0) {
393 i2400mu_rx_size_maybe_shrink(i2400mu);
399 spin_unlock_irqrestore(&i2400m->
rx_lock, flags);
400 d_fnend(4, dev,
"(i2400mu %p) = %d\n", i2400mu, result);
404 dev_err(dev,
"RX: maximum errors in received buffer exceeded; "
405 "resetting device\n");
420 struct i2400m *i2400m = &i2400mu->
i2400m;
423 d_fnstart(3, dev,
"(i2400mu %p)\n", i2400m);
426 d_fnend(3, dev,
"(i2400m %p) = void\n", i2400m);
433 struct i2400m *i2400m = &i2400mu->
i2400m;
438 kthread =
kthread_run(i2400mu_rxd, i2400mu,
"%s-rx",
441 if (IS_ERR(kthread)) {
442 result = PTR_ERR(kthread);
443 dev_err(dev,
"RX: cannot start thread: %d\n", result);
452 struct i2400m *i2400m = &i2400mu->
i2400m;
453 struct device *dev = i2400m_dev(i2400m);
459 spin_unlock_irqrestore(&i2400m->
rx_lock, flags);
463 d_printf(1, dev,
"RX: kthread had already exited\n");