2 * Intel Wireless WiMAX Connection 2400m
3 * Handle incoming traffic and deliver it to the control or data planes
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 * - Use skb_clone(), break up processing in chunks
40 * - Split transport/device specific
41 * - Make buffer size dynamic to exert less memory pressure
42 * - RX reorder support
44 * This handles the RX path.
46 * We receive an RX message from the bus-specific driver, which
47 * contains one or more payloads that have potentially different
48 * destinataries (data or control paths).
50 * So we just take that payload from the transport specific code in
51 * the form of an skb, break it up in chunks (a cloned skb each in the
52 * case of network packets) and pass it to netdev or to the
53 * command/ack handler (and from there to the WiMAX stack).
57 * The format of the buffer is:
59 * HEADER (struct i2400m_msg_hdr)
60 * PAYLOAD DESCRIPTOR 0 (struct i2400m_pld)
61 * PAYLOAD DESCRIPTOR 1
63 * PAYLOAD DESCRIPTOR N
64 * PAYLOAD 0 (raw bytes)
69 * See tx.c for a deeper description on alignment requirements and
70 * other fun facts of it.
74 * In firmwares <= v1.3, data packets have no header for RX, but they
75 * do for TX (currently unused).
77 * In firmware >= 1.4, RX packets have an extended header (16
78 * bytes). This header conveys information for management of host
79 * reordering of packets (the device offloads storage of the packets
80 * for reordering to the host). Read below for more information.
82 * The header is used as dummy space to emulate an ethernet header and
83 * thus be able to act as an ethernet device without having to reallocate.
87 * Starting in firmware v1.4, the device can deliver packets for
88 * delivery with special reordering information; this allows it to
89 * more effectively do packet management when some frames were lost in
92 * Thus, for RX packets that come out of order, the device gives the
93 * driver enough information to queue them properly and then at some
94 * point, the signal to deliver the whole (or part) of the queued
95 * packets to the networking stack. There are 16 such queues.
97 * This only happens when a packet comes in with the "need reorder"
98 * flag set in the RX header. When such bit is set, the following
99 * operations might be indicated:
101 * - reset queue: send all queued packets to the OS
103 * - queue: queue a packet
105 * - update ws: update the queue's window start and deliver queued
106 * packets that meet the criteria
108 * - queue & update ws: queue a packet, update the window start and
109 * deliver queued packets that meet the criteria
111 * (delivery criteria: the packet's [normalized] sequence number is
112 * lower than the new [normalized] window start).
114 * See the i2400m_roq_*() functions for details.
119 * i2400m_rx_msg_hdr_check
120 * i2400m_rx_pl_descr_check
129 * i2400m_roq_update_ws
130 * __i2400m_roq_update_ws
132 * i2400m_roq_queue_update_ws
134 * __i2400m_roq_update_ws
137 * i2400m_msg_size_check
138 * i2400m_report_hook_work [in a workqueue]
142 * wimax_msg_to_user_alloc
144 * i2400m_msg_size_check
147 #include <linux/slab.h>
148 #include <linux/kernel.h>
149 #include <linux/if_arp.h>
150 #include <linux/netdevice.h>
151 #include <linux/workqueue.h>
155 #define D_SUBMODULE rx
156 #include "debug-levels.h"
158 static int i2400m_rx_reorder_disabled
; /* 0 (rx reorder enabled) by default */
159 module_param_named(rx_reorder_disabled
, i2400m_rx_reorder_disabled
, int, 0644);
160 MODULE_PARM_DESC(rx_reorder_disabled
,
161 "If true, RX reordering will be disabled.");
163 struct i2400m_report_hook_args
{
164 struct sk_buff
*skb_rx
;
165 const struct i2400m_l3l4_hdr
*l3l4_hdr
;
167 struct list_head list_node
;
172 * Execute i2400m_report_hook in a workqueue
174 * Goes over the list of queued reports in i2400m->rx_reports and
177 * NOTE: refcounts on i2400m are not needed because we flush the
178 * workqueue this runs on (i2400m->work_queue) before destroying
181 void i2400m_report_hook_work(struct work_struct
*ws
)
183 struct i2400m
*i2400m
= container_of(ws
, struct i2400m
, rx_report_ws
);
184 struct device
*dev
= i2400m_dev(i2400m
);
185 struct i2400m_report_hook_args
*args
, *args_next
;
190 spin_lock_irqsave(&i2400m
->rx_lock
, flags
);
191 list_splice_init(&i2400m
->rx_reports
, &list
);
192 spin_unlock_irqrestore(&i2400m
->rx_lock
, flags
);
193 if (list_empty(&list
))
196 d_printf(1, dev
, "processing queued reports\n");
197 list_for_each_entry_safe(args
, args_next
, &list
, list_node
) {
198 d_printf(2, dev
, "processing queued report %p\n", args
);
199 i2400m_report_hook(i2400m
, args
->l3l4_hdr
, args
->size
);
200 kfree_skb(args
->skb_rx
);
201 list_del(&args
->list_node
);
209 * Flush the list of queued reports
212 void i2400m_report_hook_flush(struct i2400m
*i2400m
)
214 struct device
*dev
= i2400m_dev(i2400m
);
215 struct i2400m_report_hook_args
*args
, *args_next
;
219 d_printf(1, dev
, "flushing queued reports\n");
220 spin_lock_irqsave(&i2400m
->rx_lock
, flags
);
221 list_splice_init(&i2400m
->rx_reports
, &list
);
222 spin_unlock_irqrestore(&i2400m
->rx_lock
, flags
);
223 list_for_each_entry_safe(args
, args_next
, &list
, list_node
) {
224 d_printf(2, dev
, "flushing queued report %p\n", args
);
225 kfree_skb(args
->skb_rx
);
226 list_del(&args
->list_node
);
233 * Queue a report for later processing
235 * @i2400m: device descriptor
236 * @skb_rx: skb that contains the payload (for reference counting)
237 * @l3l4_hdr: pointer to the control
238 * @size: size of the message
241 void i2400m_report_hook_queue(struct i2400m
*i2400m
, struct sk_buff
*skb_rx
,
242 const void *l3l4_hdr
, size_t size
)
244 struct device
*dev
= i2400m_dev(i2400m
);
246 struct i2400m_report_hook_args
*args
;
248 args
= kzalloc(sizeof(*args
), GFP_NOIO
);
250 args
->skb_rx
= skb_get(skb_rx
);
251 args
->l3l4_hdr
= l3l4_hdr
;
253 spin_lock_irqsave(&i2400m
->rx_lock
, flags
);
254 list_add_tail(&args
->list_node
, &i2400m
->rx_reports
);
255 spin_unlock_irqrestore(&i2400m
->rx_lock
, flags
);
256 d_printf(2, dev
, "queued report %p\n", args
);
257 rmb(); /* see i2400m->ready's documentation */
258 if (likely(i2400m
->ready
)) /* only send if up */
259 queue_work(i2400m
->work_queue
, &i2400m
->rx_report_ws
);
261 if (printk_ratelimit())
262 dev_err(dev
, "%s:%u: Can't allocate %zu B\n",
263 __func__
, __LINE__
, sizeof(*args
));
269 * Process an ack to a command
271 * @i2400m: device descriptor
272 * @payload: pointer to message
273 * @size: size of the message
275 * Pass the acknodledgment (in an skb) to the thread that is waiting
276 * for it in i2400m->msg_completion.
278 * We need to coordinate properly with the thread waiting for the
279 * ack. Check if it is waiting or if it is gone. We loose the spinlock
280 * to avoid allocating on atomic contexts (yeah, could use GFP_ATOMIC,
281 * but this is not so speed critical).
284 void i2400m_rx_ctl_ack(struct i2400m
*i2400m
,
285 const void *payload
, size_t size
)
287 struct device
*dev
= i2400m_dev(i2400m
);
288 struct wimax_dev
*wimax_dev
= &i2400m
->wimax_dev
;
290 struct sk_buff
*ack_skb
;
292 /* Anyone waiting for an answer? */
293 spin_lock_irqsave(&i2400m
->rx_lock
, flags
);
294 if (i2400m
->ack_skb
!= ERR_PTR(-EINPROGRESS
)) {
295 dev_err(dev
, "Huh? reply to command with no waiters\n");
296 goto error_no_waiter
;
298 spin_unlock_irqrestore(&i2400m
->rx_lock
, flags
);
300 ack_skb
= wimax_msg_alloc(wimax_dev
, NULL
, payload
, size
, GFP_KERNEL
);
302 /* Check waiter didn't time out waiting for the answer... */
303 spin_lock_irqsave(&i2400m
->rx_lock
, flags
);
304 if (i2400m
->ack_skb
!= ERR_PTR(-EINPROGRESS
)) {
305 d_printf(1, dev
, "Huh? waiter for command reply cancelled\n");
306 goto error_waiter_cancelled
;
309 dev_err(dev
, "CMD/GET/SET ack: cannot allocate SKB\n");
310 i2400m
->ack_skb
= ack_skb
;
311 spin_unlock_irqrestore(&i2400m
->rx_lock
, flags
);
312 complete(&i2400m
->msg_completion
);
315 error_waiter_cancelled
:
316 if (!IS_ERR(ack_skb
))
319 spin_unlock_irqrestore(&i2400m
->rx_lock
, flags
);
325 * Receive and process a control payload
327 * @i2400m: device descriptor
328 * @skb_rx: skb that contains the payload (for reference counting)
329 * @payload: pointer to message
330 * @size: size of the message
332 * There are two types of control RX messages: reports (asynchronous,
333 * like your every day interrupts) and 'acks' (reponses to a command,
334 * get or set request).
336 * If it is a report, we run hooks on it (to extract information for
337 * things we need to do in the driver) and then pass it over to the
338 * WiMAX stack to send it to user space.
340 * NOTE: report processing is done in a workqueue specific to the
341 * generic driver, to avoid deadlocks in the system.
343 * If it is not a report, it is an ack to a previously executed
344 * command, set or get, so wake up whoever is waiting for it from
345 * i2400m_msg_to_dev(). i2400m_rx_ctl_ack() takes care of that.
347 * Note that the sizes we pass to other functions from here are the
348 * sizes of the _l3l4_hdr + payload, not full buffer sizes, as we have
349 * verified in _msg_size_check() that they are congruent.
351 * For reports: We can't clone the original skb where the data is
352 * because we need to send this up via netlink; netlink has to add
353 * headers and we can't overwrite what's preceeding the payload...as
354 * it is another message. So we just dup them.
357 void i2400m_rx_ctl(struct i2400m
*i2400m
, struct sk_buff
*skb_rx
,
358 const void *payload
, size_t size
)
361 struct device
*dev
= i2400m_dev(i2400m
);
362 const struct i2400m_l3l4_hdr
*l3l4_hdr
= payload
;
365 result
= i2400m_msg_size_check(i2400m
, l3l4_hdr
, size
);
367 dev_err(dev
, "HW BUG? device sent a bad message: %d\n",
371 msg_type
= le16_to_cpu(l3l4_hdr
->type
);
372 d_printf(1, dev
, "%s 0x%04x: %zu bytes\n",
373 msg_type
& I2400M_MT_REPORT_MASK
? "REPORT" : "CMD/SET/GET",
375 d_dump(2, dev
, l3l4_hdr
, size
);
376 if (msg_type
& I2400M_MT_REPORT_MASK
) {
378 * Process each report
380 * - has to be ran serialized as well
382 * - the handling might force the execution of
383 * commands. That might cause reentrancy issues with
384 * bus-specific subdrivers and workqueues, so the we
385 * run it in a separate workqueue.
387 * - when the driver is not yet ready to handle them,
388 * they are queued and at some point the queue is
389 * restarted [NOTE: we can't queue SKBs directly, as
390 * this might be a piece of a SKB, not the whole
391 * thing, and this is cheaper than cloning the
394 * Note we don't do refcounting for the device
395 * structure; this is because before destroying
396 * 'i2400m', we make sure to flush the
397 * i2400m->work_queue, so there are no issues.
399 i2400m_report_hook_queue(i2400m
, skb_rx
, l3l4_hdr
, size
);
400 if (unlikely(i2400m
->trace_msg_from_user
))
401 wimax_msg(&i2400m
->wimax_dev
, "echo",
402 l3l4_hdr
, size
, GFP_KERNEL
);
403 result
= wimax_msg(&i2400m
->wimax_dev
, NULL
, l3l4_hdr
, size
,
406 dev_err(dev
, "error sending report to userspace: %d\n",
408 } else /* an ack to a CMD, GET or SET */
409 i2400m_rx_ctl_ack(i2400m
, payload
, size
);
416 * Receive and send up a trace
418 * @i2400m: device descriptor
419 * @skb_rx: skb that contains the trace (for reference counting)
420 * @payload: pointer to trace message inside the skb
421 * @size: size of the message
423 * THe i2400m might produce trace information (diagnostics) and we
424 * send them through a different kernel-to-user pipe (to avoid
427 * As in i2400m_rx_ctl(), we can't clone the original skb where the
428 * data is because we need to send this up via netlink; netlink has to
429 * add headers and we can't overwrite what's preceeding the
430 * payload...as it is another message. So we just dup them.
433 void i2400m_rx_trace(struct i2400m
*i2400m
,
434 const void *payload
, size_t size
)
437 struct device
*dev
= i2400m_dev(i2400m
);
438 struct wimax_dev
*wimax_dev
= &i2400m
->wimax_dev
;
439 const struct i2400m_l3l4_hdr
*l3l4_hdr
= payload
;
442 result
= i2400m_msg_size_check(i2400m
, l3l4_hdr
, size
);
444 dev_err(dev
, "HW BUG? device sent a bad trace message: %d\n",
448 msg_type
= le16_to_cpu(l3l4_hdr
->type
);
449 d_printf(1, dev
, "Trace %s 0x%04x: %zu bytes\n",
450 msg_type
& I2400M_MT_REPORT_MASK
? "REPORT" : "CMD/SET/GET",
452 d_dump(2, dev
, l3l4_hdr
, size
);
453 result
= wimax_msg(wimax_dev
, "trace", l3l4_hdr
, size
, GFP_KERNEL
);
455 dev_err(dev
, "error sending trace to userspace: %d\n",
463 * Reorder queue data stored on skb->cb while the skb is queued in the
466 struct i2400m_roq_data
{
467 unsigned sn
; /* Serial number for the skb */
468 enum i2400m_cs cs
; /* packet type for the skb */
475 * @ws: Window Start; sequence number where the current window start
477 * @queue: the skb queue itself
478 * @log: circular ring buffer used to log information about the
479 * reorder process in this queue that can be displayed in case of
480 * error to help diagnose it.
482 * This is the head for a list of skbs. In the skb->cb member of the
483 * skb when queued here contains a 'struct i2400m_roq_data' were we
484 * store the sequence number (sn) and the cs (packet type) coming from
485 * the RX payload header from the device.
490 struct sk_buff_head queue
;
491 struct i2400m_roq_log
*log
;
496 void __i2400m_roq_init(struct i2400m_roq
*roq
)
499 skb_queue_head_init(&roq
->queue
);
504 unsigned __i2400m_roq_index(struct i2400m
*i2400m
, struct i2400m_roq
*roq
)
506 return ((unsigned long) roq
- (unsigned long) i2400m
->rx_roq
)
512 * Normalize a sequence number based on the queue's window start
514 * nsn = (sn - ws) % 2048
516 * Note that if @sn < @roq->ws, we still need a positive number; %'s
517 * sign is implementation specific, so we normalize it by adding 2048
518 * to bring it to be positive.
521 unsigned __i2400m_roq_nsn(struct i2400m_roq
*roq
, unsigned sn
)
524 r
= ((int) sn
- (int) roq
->ws
) % 2048;
532 * Circular buffer to keep the last N reorder operations
534 * In case something fails, dumb then to try to come up with what
538 I2400M_ROQ_LOG_LENGTH
= 32,
541 struct i2400m_roq_log
{
542 struct i2400m_roq_log_entry
{
543 enum i2400m_ro_type type
;
544 unsigned ws
, count
, sn
, nsn
, new_ws
;
545 } entry
[I2400M_ROQ_LOG_LENGTH
];
550 /* Print a log entry */
552 void i2400m_roq_log_entry_print(struct i2400m
*i2400m
, unsigned index
,
554 struct i2400m_roq_log_entry
*e
)
556 struct device
*dev
= i2400m_dev(i2400m
);
559 case I2400M_RO_TYPE_RESET
:
560 dev_err(dev
, "q#%d reset ws %u cnt %u sn %u/%u"
562 index
, e
->ws
, e
->count
, e
->sn
, e
->nsn
, e
->new_ws
);
564 case I2400M_RO_TYPE_PACKET
:
565 dev_err(dev
, "q#%d queue ws %u cnt %u sn %u/%u\n",
566 index
, e
->ws
, e
->count
, e
->sn
, e
->nsn
);
568 case I2400M_RO_TYPE_WS
:
569 dev_err(dev
, "q#%d update_ws ws %u cnt %u sn %u/%u"
571 index
, e
->ws
, e
->count
, e
->sn
, e
->nsn
, e
->new_ws
);
573 case I2400M_RO_TYPE_PACKET_WS
:
574 dev_err(dev
, "q#%d queue_update_ws ws %u cnt %u sn %u/%u"
576 index
, e
->ws
, e
->count
, e
->sn
, e
->nsn
, e
->new_ws
);
579 dev_err(dev
, "q#%d BUG? entry %u - unknown type %u\n",
580 index
, e_index
, e
->type
);
587 void i2400m_roq_log_add(struct i2400m
*i2400m
,
588 struct i2400m_roq
*roq
, enum i2400m_ro_type type
,
589 unsigned ws
, unsigned count
, unsigned sn
,
590 unsigned nsn
, unsigned new_ws
)
592 struct i2400m_roq_log_entry
*e
;
594 int index
= __i2400m_roq_index(i2400m
, roq
);
596 /* if we run out of space, we eat from the end */
597 if (roq
->log
->in
- roq
->log
->out
== I2400M_ROQ_LOG_LENGTH
)
599 cnt_idx
= roq
->log
->in
++ % I2400M_ROQ_LOG_LENGTH
;
600 e
= &roq
->log
->entry
[cnt_idx
];
610 i2400m_roq_log_entry_print(i2400m
, index
, cnt_idx
, e
);
614 /* Dump all the entries in the FIFO and reinitialize it */
616 void i2400m_roq_log_dump(struct i2400m
*i2400m
, struct i2400m_roq
*roq
)
618 unsigned cnt
, cnt_idx
;
619 struct i2400m_roq_log_entry
*e
;
620 int index
= __i2400m_roq_index(i2400m
, roq
);
622 BUG_ON(roq
->log
->out
> roq
->log
->in
);
623 for (cnt
= roq
->log
->out
; cnt
< roq
->log
->in
; cnt
++) {
624 cnt_idx
= cnt
% I2400M_ROQ_LOG_LENGTH
;
625 e
= &roq
->log
->entry
[cnt_idx
];
626 i2400m_roq_log_entry_print(i2400m
, index
, cnt_idx
, e
);
627 memset(e
, 0, sizeof(*e
));
629 roq
->log
->in
= roq
->log
->out
= 0;
634 * Backbone for the queuing of an skb (by normalized sequence number)
636 * @i2400m: device descriptor
637 * @roq: reorder queue where to add
638 * @skb: the skb to add
639 * @sn: the sequence number of the skb
640 * @nsn: the normalized sequence number of the skb (pre-computed by the
641 * caller from the @sn and @roq->ws).
643 * We try first a couple of quick cases:
645 * - the queue is empty
646 * - the skb would be appended to the queue
648 * These will be the most common operations.
650 * If these fail, then we have to do a sorted insertion in the queue,
651 * which is the slowest path.
653 * We don't have to acquire a reference count as we are going to own it.
656 void __i2400m_roq_queue(struct i2400m
*i2400m
, struct i2400m_roq
*roq
,
657 struct sk_buff
*skb
, unsigned sn
, unsigned nsn
)
659 struct device
*dev
= i2400m_dev(i2400m
);
660 struct sk_buff
*skb_itr
;
661 struct i2400m_roq_data
*roq_data_itr
, *roq_data
;
664 d_fnstart(4, dev
, "(i2400m %p roq %p skb %p sn %u nsn %u)\n",
665 i2400m
, roq
, skb
, sn
, nsn
);
667 roq_data
= (struct i2400m_roq_data
*) &skb
->cb
;
668 BUILD_BUG_ON(sizeof(*roq_data
) > sizeof(skb
->cb
));
670 d_printf(3, dev
, "ERX: roq %p [ws %u] nsn %d sn %u\n",
671 roq
, roq
->ws
, nsn
, roq_data
->sn
);
673 /* Queues will be empty on not-so-bad environments, so try
675 if (skb_queue_empty(&roq
->queue
)) {
676 d_printf(2, dev
, "ERX: roq %p - first one\n", roq
);
677 __skb_queue_head(&roq
->queue
, skb
);
680 /* Now try append, as most of the operations will be that */
681 skb_itr
= skb_peek_tail(&roq
->queue
);
682 roq_data_itr
= (struct i2400m_roq_data
*) &skb_itr
->cb
;
683 nsn_itr
= __i2400m_roq_nsn(roq
, roq_data_itr
->sn
);
684 /* NSN bounds assumed correct (checked when it was queued) */
685 if (nsn
>= nsn_itr
) {
686 d_printf(2, dev
, "ERX: roq %p - appended after %p (nsn %d sn %u)\n",
687 roq
, skb_itr
, nsn_itr
, roq_data_itr
->sn
);
688 __skb_queue_tail(&roq
->queue
, skb
);
691 /* None of the fast paths option worked. Iterate to find the
692 * right spot where to insert the packet; we know the queue is
693 * not empty, so we are not the first ones; we also know we
694 * are not going to be the last ones. The list is sorted, so
695 * we have to insert before the the first guy with an nsn_itr
696 * greater that our nsn. */
697 skb_queue_walk(&roq
->queue
, skb_itr
) {
698 roq_data_itr
= (struct i2400m_roq_data
*) &skb_itr
->cb
;
699 nsn_itr
= __i2400m_roq_nsn(roq
, roq_data_itr
->sn
);
700 /* NSN bounds assumed correct (checked when it was queued) */
702 d_printf(2, dev
, "ERX: roq %p - queued before %p "
703 "(nsn %d sn %u)\n", roq
, skb_itr
, nsn_itr
,
705 __skb_queue_before(&roq
->queue
, skb_itr
, skb
);
709 /* If we get here, that is VERY bad -- print info to help
710 * diagnose and crash it */
711 dev_err(dev
, "SW BUG? failed to insert packet\n");
712 dev_err(dev
, "ERX: roq %p [ws %u] skb %p nsn %d sn %u\n",
713 roq
, roq
->ws
, skb
, nsn
, roq_data
->sn
);
714 skb_queue_walk(&roq
->queue
, skb_itr
) {
715 roq_data_itr
= (struct i2400m_roq_data
*) &skb_itr
->cb
;
716 nsn_itr
= __i2400m_roq_nsn(roq
, roq_data_itr
->sn
);
717 /* NSN bounds assumed correct (checked when it was queued) */
718 dev_err(dev
, "ERX: roq %p skb_itr %p nsn %d sn %u\n",
719 roq
, skb_itr
, nsn_itr
, roq_data_itr
->sn
);
723 d_fnend(4, dev
, "(i2400m %p roq %p skb %p sn %u nsn %d) = void\n",
724 i2400m
, roq
, skb
, sn
, nsn
);
730 * Backbone for the update window start operation
732 * @i2400m: device descriptor
733 * @roq: Reorder queue
734 * @sn: New sequence number
736 * Updates the window start of a queue; when doing so, it must deliver
737 * to the networking stack all the queued skb's whose normalized
738 * sequence number is lower than the new normalized window start.
741 unsigned __i2400m_roq_update_ws(struct i2400m
*i2400m
, struct i2400m_roq
*roq
,
744 struct device
*dev
= i2400m_dev(i2400m
);
745 struct sk_buff
*skb_itr
, *tmp_itr
;
746 struct i2400m_roq_data
*roq_data_itr
;
747 unsigned new_nws
, nsn_itr
;
749 new_nws
= __i2400m_roq_nsn(roq
, sn
);
751 * For type 2(update_window_start) rx messages, there is no
752 * need to check if the normalized sequence number is greater 1023.
753 * Simply insert and deliver all packets to the host up to the
756 skb_queue_walk_safe(&roq
->queue
, skb_itr
, tmp_itr
) {
757 roq_data_itr
= (struct i2400m_roq_data
*) &skb_itr
->cb
;
758 nsn_itr
= __i2400m_roq_nsn(roq
, roq_data_itr
->sn
);
759 /* NSN bounds assumed correct (checked when it was queued) */
760 if (nsn_itr
< new_nws
) {
761 d_printf(2, dev
, "ERX: roq %p - release skb %p "
762 "(nsn %u/%u new nws %u)\n",
763 roq
, skb_itr
, nsn_itr
, roq_data_itr
->sn
,
765 __skb_unlink(skb_itr
, &roq
->queue
);
766 i2400m_net_erx(i2400m
, skb_itr
, roq_data_itr
->cs
);
769 break; /* rest of packets all nsn_itr > nws */
779 * @i2400m: device descriptor
782 * Deliver all the packets and reset the window-start to zero. Name is
783 * kind of misleading.
786 void i2400m_roq_reset(struct i2400m
*i2400m
, struct i2400m_roq
*roq
)
788 struct device
*dev
= i2400m_dev(i2400m
);
789 struct sk_buff
*skb_itr
, *tmp_itr
;
790 struct i2400m_roq_data
*roq_data_itr
;
792 d_fnstart(2, dev
, "(i2400m %p roq %p)\n", i2400m
, roq
);
793 i2400m_roq_log_add(i2400m
, roq
, I2400M_RO_TYPE_RESET
,
794 roq
->ws
, skb_queue_len(&roq
->queue
),
796 skb_queue_walk_safe(&roq
->queue
, skb_itr
, tmp_itr
) {
797 roq_data_itr
= (struct i2400m_roq_data
*) &skb_itr
->cb
;
798 d_printf(2, dev
, "ERX: roq %p - release skb %p (sn %u)\n",
799 roq
, skb_itr
, roq_data_itr
->sn
);
800 __skb_unlink(skb_itr
, &roq
->queue
);
801 i2400m_net_erx(i2400m
, skb_itr
, roq_data_itr
->cs
);
804 d_fnend(2, dev
, "(i2400m %p roq %p) = void\n", i2400m
, roq
);
812 * @i2400m: device descriptor
814 * @skb: containing the packet data
815 * @fbn: First block number of the packet in @skb
816 * @lbn: Last block number of the packet in @skb
818 * The hardware is asking the driver to queue a packet for later
819 * delivery to the networking stack.
822 void i2400m_roq_queue(struct i2400m
*i2400m
, struct i2400m_roq
*roq
,
823 struct sk_buff
* skb
, unsigned lbn
)
825 struct device
*dev
= i2400m_dev(i2400m
);
828 d_fnstart(2, dev
, "(i2400m %p roq %p skb %p lbn %u) = void\n",
829 i2400m
, roq
, skb
, lbn
);
830 len
= skb_queue_len(&roq
->queue
);
831 nsn
= __i2400m_roq_nsn(roq
, lbn
);
832 if (unlikely(nsn
>= 1024)) {
833 dev_err(dev
, "SW BUG? queue nsn %d (lbn %u ws %u)\n",
835 i2400m_roq_log_dump(i2400m
, roq
);
836 i2400m_reset(i2400m
, I2400M_RT_WARM
);
838 __i2400m_roq_queue(i2400m
, roq
, skb
, lbn
, nsn
);
839 i2400m_roq_log_add(i2400m
, roq
, I2400M_RO_TYPE_PACKET
,
840 roq
->ws
, len
, lbn
, nsn
, ~0);
842 d_fnend(2, dev
, "(i2400m %p roq %p skb %p lbn %u) = void\n",
843 i2400m
, roq
, skb
, lbn
);
849 * Update the window start in a reorder queue and deliver all skbs
850 * with a lower window start
852 * @i2400m: device descriptor
853 * @roq: Reorder queue
854 * @sn: New sequence number
857 void i2400m_roq_update_ws(struct i2400m
*i2400m
, struct i2400m_roq
*roq
,
860 struct device
*dev
= i2400m_dev(i2400m
);
861 unsigned old_ws
, nsn
, len
;
863 d_fnstart(2, dev
, "(i2400m %p roq %p sn %u)\n", i2400m
, roq
, sn
);
865 len
= skb_queue_len(&roq
->queue
);
866 nsn
= __i2400m_roq_update_ws(i2400m
, roq
, sn
);
867 i2400m_roq_log_add(i2400m
, roq
, I2400M_RO_TYPE_WS
,
868 old_ws
, len
, sn
, nsn
, roq
->ws
);
869 d_fnstart(2, dev
, "(i2400m %p roq %p sn %u) = void\n", i2400m
, roq
, sn
);
875 * Queue a packet and update the window start
877 * @i2400m: device descriptor
879 * @skb: containing the packet data
880 * @fbn: First block number of the packet in @skb
881 * @sn: Last block number of the packet in @skb
883 * Note that unlike i2400m_roq_update_ws(), which sets the new window
884 * start to @sn, in here we'll set it to @sn + 1.
887 void i2400m_roq_queue_update_ws(struct i2400m
*i2400m
, struct i2400m_roq
*roq
,
888 struct sk_buff
* skb
, unsigned sn
)
890 struct device
*dev
= i2400m_dev(i2400m
);
891 unsigned nsn
, old_ws
, len
;
893 d_fnstart(2, dev
, "(i2400m %p roq %p skb %p sn %u)\n",
894 i2400m
, roq
, skb
, sn
);
895 len
= skb_queue_len(&roq
->queue
);
896 nsn
= __i2400m_roq_nsn(roq
, sn
);
898 * For type 3(queue_update_window_start) rx messages, there is no
899 * need to check if the normalized sequence number is greater 1023.
900 * Simply insert and deliver all packets to the host up to the
904 /* If the queue is empty, don't bother as we'd queue
905 * it and immediately unqueue it -- just deliver it.
908 struct i2400m_roq_data
*roq_data
;
909 roq_data
= (struct i2400m_roq_data
*) &skb
->cb
;
910 i2400m_net_erx(i2400m
, skb
, roq_data
->cs
);
912 __i2400m_roq_queue(i2400m
, roq
, skb
, sn
, nsn
);
914 __i2400m_roq_update_ws(i2400m
, roq
, sn
+ 1);
915 i2400m_roq_log_add(i2400m
, roq
, I2400M_RO_TYPE_PACKET_WS
,
916 old_ws
, len
, sn
, nsn
, roq
->ws
);
918 d_fnend(2, dev
, "(i2400m %p roq %p skb %p sn %u) = void\n",
919 i2400m
, roq
, skb
, sn
);
925 * This routine destroys the memory allocated for rx_roq, when no
926 * other thread is accessing it. Access to rx_roq is refcounted by
927 * rx_roq_refcount, hence memory allocated must be destroyed when
928 * rx_roq_refcount becomes zero. This routine gets executed when
929 * rx_roq_refcount becomes zero.
931 void i2400m_rx_roq_destroy(struct kref
*ref
)
934 struct i2400m
*i2400m
935 = container_of(ref
, struct i2400m
, rx_roq_refcount
);
936 for (itr
= 0; itr
< I2400M_RO_CIN
+ 1; itr
++)
937 __skb_queue_purge(&i2400m
->rx_roq
[itr
].queue
);
938 kfree(i2400m
->rx_roq
[0].log
);
939 kfree(i2400m
->rx_roq
);
940 i2400m
->rx_roq
= NULL
;
944 * Receive and send up an extended data packet
946 * @i2400m: device descriptor
947 * @skb_rx: skb that contains the extended data packet
948 * @single_last: 1 if the payload is the only one or the last one of
950 * @payload: pointer to the packet's data inside the skb
951 * @size: size of the payload
953 * Starting in v1.4 of the i2400m's firmware, the device can send data
954 * packets to the host in an extended format that; this incudes a 16
955 * byte header (struct i2400m_pl_edata_hdr). Using this header's space
956 * we can fake ethernet headers for ethernet device emulation without
957 * having to copy packets around.
959 * This function handles said path.
962 * Receive and send up an extended data packet that requires no reordering
964 * @i2400m: device descriptor
965 * @skb_rx: skb that contains the extended data packet
966 * @single_last: 1 if the payload is the only one or the last one of
968 * @payload: pointer to the packet's data (past the actual extended
969 * data payload header).
970 * @size: size of the payload
972 * Pass over to the networking stack a data packet that might have
973 * reordering requirements.
975 * This needs to the decide if the skb in which the packet is
976 * contained can be reused or if it needs to be cloned. Then it has to
977 * be trimmed in the edges so that the beginning is the space for eth
978 * header and then pass it to i2400m_net_erx() for the stack
980 * Assumes the caller has verified the sanity of the payload (size,
984 void i2400m_rx_edata(struct i2400m
*i2400m
, struct sk_buff
*skb_rx
,
985 unsigned single_last
, const void *payload
, size_t size
)
987 struct device
*dev
= i2400m_dev(i2400m
);
988 const struct i2400m_pl_edata_hdr
*hdr
= payload
;
989 struct net_device
*net_dev
= i2400m
->wimax_dev
.net_dev
;
993 unsigned ro_needed
, ro_type
, ro_cin
, ro_sn
;
994 struct i2400m_roq
*roq
;
995 struct i2400m_roq_data
*roq_data
;
998 BUILD_BUG_ON(ETH_HLEN
> sizeof(*hdr
));
1000 d_fnstart(2, dev
, "(i2400m %p skb_rx %p single %u payload %p "
1001 "size %zu)\n", i2400m
, skb_rx
, single_last
, payload
, size
);
1002 if (size
< sizeof(*hdr
)) {
1003 dev_err(dev
, "ERX: HW BUG? message with short header (%zu "
1004 "vs %zu bytes expected)\n", size
, sizeof(*hdr
));
1009 skb
= skb_get(skb_rx
);
1010 d_printf(3, dev
, "ERX: skb %p reusing\n", skb
);
1012 skb
= skb_clone(skb_rx
, GFP_KERNEL
);
1014 dev_err(dev
, "ERX: no memory to clone skb\n");
1015 net_dev
->stats
.rx_dropped
++;
1016 goto error_skb_clone
;
1018 d_printf(3, dev
, "ERX: skb %p cloned from %p\n", skb
, skb_rx
);
1020 /* now we have to pull and trim so that the skb points to the
1021 * beginning of the IP packet; the netdev part will add the
1022 * ethernet header as needed - we know there is enough space
1023 * because we checked in i2400m_rx_edata(). */
1024 skb_pull(skb
, payload
+ sizeof(*hdr
) - (void *) skb
->data
);
1025 skb_trim(skb
, (void *) skb_end_pointer(skb
) - payload
- sizeof(*hdr
));
1027 reorder
= le32_to_cpu(hdr
->reorder
);
1028 ro_needed
= reorder
& I2400M_RO_NEEDED
;
1031 ro_type
= (reorder
>> I2400M_RO_TYPE_SHIFT
) & I2400M_RO_TYPE
;
1032 ro_cin
= (reorder
>> I2400M_RO_CIN_SHIFT
) & I2400M_RO_CIN
;
1033 ro_sn
= (reorder
>> I2400M_RO_SN_SHIFT
) & I2400M_RO_SN
;
1035 spin_lock_irqsave(&i2400m
->rx_lock
, flags
);
1036 roq
= &i2400m
->rx_roq
[ro_cin
];
1038 kfree_skb(skb
); /* rx_roq is already destroyed */
1039 spin_unlock_irqrestore(&i2400m
->rx_lock
, flags
);
1042 kref_get(&i2400m
->rx_roq_refcount
);
1043 spin_unlock_irqrestore(&i2400m
->rx_lock
, flags
);
1045 roq_data
= (struct i2400m_roq_data
*) &skb
->cb
;
1046 roq_data
->sn
= ro_sn
;
1048 d_printf(2, dev
, "ERX: reorder needed: "
1049 "type %u cin %u [ws %u] sn %u/%u len %zuB\n",
1050 ro_type
, ro_cin
, roq
->ws
, ro_sn
,
1051 __i2400m_roq_nsn(roq
, ro_sn
), size
);
1052 d_dump(2, dev
, payload
, size
);
1054 case I2400M_RO_TYPE_RESET
:
1055 i2400m_roq_reset(i2400m
, roq
);
1056 kfree_skb(skb
); /* no data here */
1058 case I2400M_RO_TYPE_PACKET
:
1059 i2400m_roq_queue(i2400m
, roq
, skb
, ro_sn
);
1061 case I2400M_RO_TYPE_WS
:
1062 i2400m_roq_update_ws(i2400m
, roq
, ro_sn
);
1063 kfree_skb(skb
); /* no data here */
1065 case I2400M_RO_TYPE_PACKET_WS
:
1066 i2400m_roq_queue_update_ws(i2400m
, roq
, skb
, ro_sn
);
1069 dev_err(dev
, "HW BUG? unknown reorder type %u\n", ro_type
);
1072 spin_lock_irqsave(&i2400m
->rx_lock
, flags
);
1073 kref_put(&i2400m
->rx_roq_refcount
, i2400m_rx_roq_destroy
);
1074 spin_unlock_irqrestore(&i2400m
->rx_lock
, flags
);
1077 i2400m_net_erx(i2400m
, skb
, cs
);
1080 d_fnend(2, dev
, "(i2400m %p skb_rx %p single %u payload %p "
1081 "size %zu) = void\n", i2400m
, skb_rx
, single_last
, payload
, size
);
1087 * Act on a received payload
1089 * @i2400m: device instance
1090 * @skb_rx: skb where the transaction was received
1091 * @single_last: 1 this is the only payload or the last one (so the
1092 * skb can be reused instead of cloned).
1093 * @pld: payload descriptor
1094 * @payload: payload data
1096 * Upon reception of a payload, look at its guts in the payload
1097 * descriptor and decide what to do with it. If it is a single payload
1098 * skb or if the last skb is a data packet, the skb will be referenced
1099 * and modified (so it doesn't have to be cloned).
1102 void i2400m_rx_payload(struct i2400m
*i2400m
, struct sk_buff
*skb_rx
,
1103 unsigned single_last
, const struct i2400m_pld
*pld
,
1104 const void *payload
)
1106 struct device
*dev
= i2400m_dev(i2400m
);
1107 size_t pl_size
= i2400m_pld_size(pld
);
1108 enum i2400m_pt pl_type
= i2400m_pld_type(pld
);
1110 d_printf(7, dev
, "RX: received payload type %u, %zu bytes\n",
1112 d_dump(8, dev
, payload
, pl_size
);
1115 case I2400M_PT_DATA
:
1116 d_printf(3, dev
, "RX: data payload %zu bytes\n", pl_size
);
1117 i2400m_net_rx(i2400m
, skb_rx
, single_last
, payload
, pl_size
);
1119 case I2400M_PT_CTRL
:
1120 i2400m_rx_ctl(i2400m
, skb_rx
, payload
, pl_size
);
1122 case I2400M_PT_TRACE
:
1123 i2400m_rx_trace(i2400m
, payload
, pl_size
);
1125 case I2400M_PT_EDATA
:
1126 d_printf(3, dev
, "ERX: data payload %zu bytes\n", pl_size
);
1127 i2400m_rx_edata(i2400m
, skb_rx
, single_last
, payload
, pl_size
);
1129 default: /* Anything else shouldn't come to the host */
1130 if (printk_ratelimit())
1131 dev_err(dev
, "RX: HW BUG? unexpected payload type %u\n",
1138 * Check a received transaction's message header
1140 * @i2400m: device descriptor
1141 * @msg_hdr: message header
1142 * @buf_size: size of the received buffer
1144 * Check that the declarations done by a RX buffer message header are
1145 * sane and consistent with the amount of data that was received.
1148 int i2400m_rx_msg_hdr_check(struct i2400m
*i2400m
,
1149 const struct i2400m_msg_hdr
*msg_hdr
,
1153 struct device
*dev
= i2400m_dev(i2400m
);
1154 if (buf_size
< sizeof(*msg_hdr
)) {
1155 dev_err(dev
, "RX: HW BUG? message with short header (%zu "
1156 "vs %zu bytes expected)\n", buf_size
, sizeof(*msg_hdr
));
1159 if (msg_hdr
->barker
!= cpu_to_le32(I2400M_D2H_MSG_BARKER
)) {
1160 dev_err(dev
, "RX: HW BUG? message received with unknown "
1161 "barker 0x%08x (buf_size %zu bytes)\n",
1162 le32_to_cpu(msg_hdr
->barker
), buf_size
);
1165 if (msg_hdr
->num_pls
== 0) {
1166 dev_err(dev
, "RX: HW BUG? zero payload packets in message\n");
1169 if (le16_to_cpu(msg_hdr
->num_pls
) > I2400M_MAX_PLS_IN_MSG
) {
1170 dev_err(dev
, "RX: HW BUG? message contains more payload "
1171 "than maximum; ignoring.\n");
1181 * Check a payload descriptor against the received data
1183 * @i2400m: device descriptor
1184 * @pld: payload descriptor
1185 * @pl_itr: offset (in bytes) in the received buffer the payload is
1187 * @buf_size: size of the received buffer
1189 * Given a payload descriptor (part of a RX buffer), check it is sane
1190 * and that the data it declares fits in the buffer.
1193 int i2400m_rx_pl_descr_check(struct i2400m
*i2400m
,
1194 const struct i2400m_pld
*pld
,
1195 size_t pl_itr
, size_t buf_size
)
1198 struct device
*dev
= i2400m_dev(i2400m
);
1199 size_t pl_size
= i2400m_pld_size(pld
);
1200 enum i2400m_pt pl_type
= i2400m_pld_type(pld
);
1202 if (pl_size
> i2400m
->bus_pl_size_max
) {
1203 dev_err(dev
, "RX: HW BUG? payload @%zu: size %zu is "
1204 "bigger than maximum %zu; ignoring message\n",
1205 pl_itr
, pl_size
, i2400m
->bus_pl_size_max
);
1208 if (pl_itr
+ pl_size
> buf_size
) { /* enough? */
1209 dev_err(dev
, "RX: HW BUG? payload @%zu: size %zu "
1210 "goes beyond the received buffer "
1211 "size (%zu bytes); ignoring message\n",
1212 pl_itr
, pl_size
, buf_size
);
1215 if (pl_type
>= I2400M_PT_ILLEGAL
) {
1216 dev_err(dev
, "RX: HW BUG? illegal payload type %u; "
1217 "ignoring message\n", pl_type
);
1227 * i2400m_rx - Receive a buffer of data from the device
1229 * @i2400m: device descriptor
1230 * @skb: skbuff where the data has been received
1232 * Parse in a buffer of data that contains an RX message sent from the
1233 * device. See the file header for the format. Run all checks on the
1234 * buffer header, then run over each payload's descriptors, verify
1235 * their consistency and act on each payload's contents. If
1236 * everything is successful, update the device's statistics.
1238 * Note: You need to set the skb to contain only the length of the
1239 * received buffer; for that, use skb_trim(skb, RECEIVED_SIZE).
1243 * 0 if ok, < 0 errno on error
1245 * If ok, this function owns now the skb and the caller DOESN'T have
1246 * to run kfree_skb() on it. However, on error, the caller still owns
1247 * the skb and it is responsible for releasing it.
1249 int i2400m_rx(struct i2400m
*i2400m
, struct sk_buff
*skb
)
1252 struct device
*dev
= i2400m_dev(i2400m
);
1253 const struct i2400m_msg_hdr
*msg_hdr
;
1254 size_t pl_itr
, pl_size
, skb_len
;
1255 unsigned long flags
;
1256 unsigned num_pls
, single_last
;
1259 d_fnstart(4, dev
, "(i2400m %p skb %p [size %zu])\n",
1260 i2400m
, skb
, skb_len
);
1262 msg_hdr
= (void *) skb
->data
;
1263 result
= i2400m_rx_msg_hdr_check(i2400m
, msg_hdr
, skb
->len
);
1265 goto error_msg_hdr_check
;
1267 num_pls
= le16_to_cpu(msg_hdr
->num_pls
);
1268 pl_itr
= sizeof(*msg_hdr
) + /* Check payload descriptor(s) */
1269 num_pls
* sizeof(msg_hdr
->pld
[0]);
1270 pl_itr
= ALIGN(pl_itr
, I2400M_PL_ALIGN
);
1271 if (pl_itr
> skb
->len
) { /* got all the payload descriptors? */
1272 dev_err(dev
, "RX: HW BUG? message too short (%u bytes) for "
1273 "%u payload descriptors (%zu each, total %zu)\n",
1274 skb
->len
, num_pls
, sizeof(msg_hdr
->pld
[0]), pl_itr
);
1275 goto error_pl_descr_short
;
1277 /* Walk each payload payload--check we really got it */
1278 for (i
= 0; i
< num_pls
; i
++) {
1279 /* work around old gcc warnings */
1280 pl_size
= i2400m_pld_size(&msg_hdr
->pld
[i
]);
1281 result
= i2400m_rx_pl_descr_check(i2400m
, &msg_hdr
->pld
[i
],
1284 goto error_pl_descr_check
;
1285 single_last
= num_pls
== 1 || i
== num_pls
- 1;
1286 i2400m_rx_payload(i2400m
, skb
, single_last
, &msg_hdr
->pld
[i
],
1287 skb
->data
+ pl_itr
);
1288 pl_itr
+= ALIGN(pl_size
, I2400M_PL_ALIGN
);
1289 cond_resched(); /* Don't monopolize */
1292 /* Update device statistics */
1293 spin_lock_irqsave(&i2400m
->rx_lock
, flags
);
1294 i2400m
->rx_pl_num
+= i
;
1295 if (i
> i2400m
->rx_pl_max
)
1296 i2400m
->rx_pl_max
= i
;
1297 if (i
< i2400m
->rx_pl_min
)
1298 i2400m
->rx_pl_min
= i
;
1300 i2400m
->rx_size_acc
+= skb
->len
;
1301 if (skb
->len
< i2400m
->rx_size_min
)
1302 i2400m
->rx_size_min
= skb
->len
;
1303 if (skb
->len
> i2400m
->rx_size_max
)
1304 i2400m
->rx_size_max
= skb
->len
;
1305 spin_unlock_irqrestore(&i2400m
->rx_lock
, flags
);
1306 error_pl_descr_check
:
1307 error_pl_descr_short
:
1308 error_msg_hdr_check
:
1309 d_fnend(4, dev
, "(i2400m %p skb %p [size %zu]) = %d\n",
1310 i2400m
, skb
, skb_len
, result
);
1313 EXPORT_SYMBOL_GPL(i2400m_rx
);
1316 void i2400m_unknown_barker(struct i2400m
*i2400m
,
1317 const void *buf
, size_t size
)
1319 struct device
*dev
= i2400m_dev(i2400m
);
1321 const __le32
*barker
= buf
;
1322 dev_err(dev
, "RX: HW BUG? unknown barker %08x, "
1323 "dropping %zu bytes\n", le32_to_cpu(*barker
), size
);
1324 snprintf(prefix
, sizeof(prefix
), "%s %s: ",
1325 dev_driver_string(dev
), dev_name(dev
));
1327 print_hex_dump(KERN_ERR
, prefix
, DUMP_PREFIX_OFFSET
,
1329 printk(KERN_ERR
"%s... (only first 64 bytes "
1330 "dumped)\n", prefix
);
1332 print_hex_dump(KERN_ERR
, prefix
, DUMP_PREFIX_OFFSET
,
1333 8, 4, buf
, size
, 0);
1335 EXPORT_SYMBOL(i2400m_unknown_barker
);
1339 * Initialize the RX queue and infrastructure
1341 * This sets up all the RX reordering infrastructures, which will not
1342 * be used if reordering is not enabled or if the firmware does not
1343 * support it. The device is told to do reordering in
1344 * i2400m_dev_initialize(), where it also looks at the value of the
1345 * i2400m->rx_reorder switch before taking a decission.
1347 * Note we allocate the roq queues in one chunk and the actual logging
1348 * support for it (logging) in another one and then we setup the
1349 * pointers from the first to the last.
1351 int i2400m_rx_setup(struct i2400m
*i2400m
)
1354 struct device
*dev
= i2400m_dev(i2400m
);
1356 i2400m
->rx_reorder
= i2400m_rx_reorder_disabled
? 0 : 1;
1357 if (i2400m
->rx_reorder
) {
1360 struct i2400m_roq_log
*rd
;
1364 size
= sizeof(i2400m
->rx_roq
[0]) * (I2400M_RO_CIN
+ 1);
1365 i2400m
->rx_roq
= kzalloc(size
, GFP_KERNEL
);
1366 if (i2400m
->rx_roq
== NULL
) {
1367 dev_err(dev
, "RX: cannot allocate %zu bytes for "
1368 "reorder queues\n", size
);
1369 goto error_roq_alloc
;
1372 size
= sizeof(*i2400m
->rx_roq
[0].log
) * (I2400M_RO_CIN
+ 1);
1373 rd
= kzalloc(size
, GFP_KERNEL
);
1375 dev_err(dev
, "RX: cannot allocate %zu bytes for "
1376 "reorder queues log areas\n", size
);
1378 goto error_roq_log_alloc
;
1381 for(itr
= 0; itr
< I2400M_RO_CIN
+ 1; itr
++) {
1382 __i2400m_roq_init(&i2400m
->rx_roq
[itr
]);
1383 i2400m
->rx_roq
[itr
].log
= &rd
[itr
];
1385 kref_init(&i2400m
->rx_roq_refcount
);
1389 error_roq_log_alloc
:
1390 kfree(i2400m
->rx_roq
);
1396 /* Tear down the RX queue and infrastructure */
1397 void i2400m_rx_release(struct i2400m
*i2400m
)
1399 unsigned long flags
;
1401 if (i2400m
->rx_reorder
) {
1402 spin_lock_irqsave(&i2400m
->rx_lock
, flags
);
1403 kref_put(&i2400m
->rx_roq_refcount
, i2400m_rx_roq_destroy
);
1404 spin_unlock_irqrestore(&i2400m
->rx_lock
, flags
);
1406 /* at this point, nothing can be received... */
1407 i2400m_report_hook_flush(i2400m
);