2 * Copyright (C) ST-Ericsson AB 2010
3 * Author: Daniel Martensson
4 * Dmitry.Tarnyagin / dmitry.tarnyagin@lockless.no
5 * License terms: GNU General Public License (GPL) version 2.
8 #define pr_fmt(fmt) KBUILD_MODNAME fmt
10 #include <linux/init.h>
11 #include <linux/module.h>
12 #include <linux/device.h>
13 #include <linux/netdevice.h>
14 #include <linux/string.h>
15 #include <linux/list.h>
16 #include <linux/interrupt.h>
17 #include <linux/delay.h>
18 #include <linux/sched.h>
19 #include <linux/if_arp.h>
20 #include <linux/timer.h>
21 #include <net/rtnetlink.h>
22 #include <linux/pkt_sched.h>
23 #include <net/caif/caif_layer.h>
24 #include <net/caif/caif_hsi.h>
26 MODULE_LICENSE("GPL");
27 MODULE_AUTHOR("Daniel Martensson");
28 MODULE_DESCRIPTION("CAIF HSI driver");
30 /* Returns the number of padding bytes for alignment. */
31 #define PAD_POW2(x, pow) ((((x)&((pow)-1)) == 0) ? 0 :\
32 (((pow)-((x)&((pow)-1)))))
34 static const struct cfhsi_config hsi_default_config
= {
36 /* Inactivity timeout on HSI, ms */
37 .inactivity_timeout
= HZ
,
39 /* Aggregation timeout (ms) of zero means no aggregation is done*/
40 .aggregation_timeout
= 1,
43 * HSI link layer flow-control thresholds.
44 * Threshold values for the HSI packet queue. Flow-control will be
45 * asserted when the number of packets exceeds q_high_mark. It will
46 * not be de-asserted before the number of packets drops below
48 * Warning: A high threshold value might increase throughput but it
49 * will at the same time prevent channel prioritization and increase
50 * the risk of flooding the modem. The high threshold should be above
57 * HSI padding options.
58 * Warning: must be a base of 2 (& operation used) and can not be zero !
67 static LIST_HEAD(cfhsi_list
);
69 static void cfhsi_inactivity_tout(unsigned long arg
)
71 struct cfhsi
*cfhsi
= (struct cfhsi
*)arg
;
73 netdev_dbg(cfhsi
->ndev
, "%s.\n",
76 /* Schedule power down work queue. */
77 if (!test_bit(CFHSI_SHUTDOWN
, &cfhsi
->bits
))
78 queue_work(cfhsi
->wq
, &cfhsi
->wake_down_work
);
81 static void cfhsi_update_aggregation_stats(struct cfhsi
*cfhsi
,
82 const struct sk_buff
*skb
,
85 struct caif_payload_info
*info
;
88 info
= (struct caif_payload_info
*)&skb
->cb
;
89 hpad
= 1 + PAD_POW2((info
->hdr_len
+ 1), cfhsi
->cfg
.head_align
);
90 tpad
= PAD_POW2((skb
->len
+ hpad
), cfhsi
->cfg
.tail_align
);
91 len
= skb
->len
+ hpad
+ tpad
;
94 cfhsi
->aggregation_len
+= len
;
95 else if (direction
< 0)
96 cfhsi
->aggregation_len
-= len
;
99 static bool cfhsi_can_send_aggregate(struct cfhsi
*cfhsi
)
103 if (cfhsi
->cfg
.aggregation_timeout
== 0)
106 for (i
= 0; i
< CFHSI_PRIO_BEBK
; ++i
) {
107 if (cfhsi
->qhead
[i
].qlen
)
111 /* TODO: Use aggregation_len instead */
112 if (cfhsi
->qhead
[CFHSI_PRIO_BEBK
].qlen
>= CFHSI_MAX_PKTS
)
118 static struct sk_buff
*cfhsi_dequeue(struct cfhsi
*cfhsi
)
123 for (i
= 0; i
< CFHSI_PRIO_LAST
; ++i
) {
124 skb
= skb_dequeue(&cfhsi
->qhead
[i
]);
132 static int cfhsi_tx_queue_len(struct cfhsi
*cfhsi
)
135 for (i
= 0; i
< CFHSI_PRIO_LAST
; ++i
)
136 len
+= skb_queue_len(&cfhsi
->qhead
[i
]);
140 static void cfhsi_abort_tx(struct cfhsi
*cfhsi
)
145 spin_lock_bh(&cfhsi
->lock
);
146 skb
= cfhsi_dequeue(cfhsi
);
150 cfhsi
->ndev
->stats
.tx_errors
++;
151 cfhsi
->ndev
->stats
.tx_dropped
++;
152 cfhsi_update_aggregation_stats(cfhsi
, skb
, -1);
153 spin_unlock_bh(&cfhsi
->lock
);
156 cfhsi
->tx_state
= CFHSI_TX_STATE_IDLE
;
157 if (!test_bit(CFHSI_SHUTDOWN
, &cfhsi
->bits
))
158 mod_timer(&cfhsi
->inactivity_timer
,
159 jiffies
+ cfhsi
->cfg
.inactivity_timeout
);
160 spin_unlock_bh(&cfhsi
->lock
);
163 static int cfhsi_flush_fifo(struct cfhsi
*cfhsi
)
165 char buffer
[32]; /* Any reasonable value */
166 size_t fifo_occupancy
;
169 netdev_dbg(cfhsi
->ndev
, "%s.\n",
173 ret
= cfhsi
->ops
->cfhsi_fifo_occupancy(cfhsi
->ops
,
176 netdev_warn(cfhsi
->ndev
,
177 "%s: can't get FIFO occupancy: %d.\n",
180 } else if (!fifo_occupancy
)
181 /* No more data, exitting normally */
184 fifo_occupancy
= min(sizeof(buffer
), fifo_occupancy
);
185 set_bit(CFHSI_FLUSH_FIFO
, &cfhsi
->bits
);
186 ret
= cfhsi
->ops
->cfhsi_rx(buffer
, fifo_occupancy
,
189 clear_bit(CFHSI_FLUSH_FIFO
, &cfhsi
->bits
);
190 netdev_warn(cfhsi
->ndev
,
191 "%s: can't read data: %d.\n",
197 ret
= wait_event_interruptible_timeout(cfhsi
->flush_fifo_wait
,
198 !test_bit(CFHSI_FLUSH_FIFO
, &cfhsi
->bits
), ret
);
201 netdev_warn(cfhsi
->ndev
,
202 "%s: can't wait for flush complete: %d.\n",
207 netdev_warn(cfhsi
->ndev
,
208 "%s: timeout waiting for flush complete.\n",
217 static int cfhsi_tx_frm(struct cfhsi_desc
*desc
, struct cfhsi
*cfhsi
)
222 u8
*pfrm
= desc
->emb_frm
+ CFHSI_MAX_EMB_FRM_SZ
;
224 skb
= cfhsi_dequeue(cfhsi
);
231 /* Check if we can embed a CAIF frame. */
232 if (skb
->len
< CFHSI_MAX_EMB_FRM_SZ
) {
233 struct caif_payload_info
*info
;
237 /* Calculate needed head alignment and tail alignment. */
238 info
= (struct caif_payload_info
*)&skb
->cb
;
240 hpad
= 1 + PAD_POW2((info
->hdr_len
+ 1), cfhsi
->cfg
.head_align
);
241 tpad
= PAD_POW2((skb
->len
+ hpad
), cfhsi
->cfg
.tail_align
);
243 /* Check if frame still fits with added alignment. */
244 if ((skb
->len
+ hpad
+ tpad
) <= CFHSI_MAX_EMB_FRM_SZ
) {
245 u8
*pemb
= desc
->emb_frm
;
246 desc
->offset
= CFHSI_DESC_SHORT_SZ
;
247 *pemb
= (u8
)(hpad
- 1);
250 /* Update network statistics. */
251 spin_lock_bh(&cfhsi
->lock
);
252 cfhsi
->ndev
->stats
.tx_packets
++;
253 cfhsi
->ndev
->stats
.tx_bytes
+= skb
->len
;
254 cfhsi_update_aggregation_stats(cfhsi
, skb
, -1);
255 spin_unlock_bh(&cfhsi
->lock
);
257 /* Copy in embedded CAIF frame. */
258 skb_copy_bits(skb
, 0, pemb
, skb
->len
);
260 /* Consume the SKB */
266 /* Create payload CAIF frames. */
267 pfrm
= desc
->emb_frm
+ CFHSI_MAX_EMB_FRM_SZ
;
268 while (nfrms
< CFHSI_MAX_PKTS
) {
269 struct caif_payload_info
*info
;
274 skb
= cfhsi_dequeue(cfhsi
);
279 /* Calculate needed head alignment and tail alignment. */
280 info
= (struct caif_payload_info
*)&skb
->cb
;
282 hpad
= 1 + PAD_POW2((info
->hdr_len
+ 1), cfhsi
->cfg
.head_align
);
283 tpad
= PAD_POW2((skb
->len
+ hpad
), cfhsi
->cfg
.tail_align
);
285 /* Fill in CAIF frame length in descriptor. */
286 desc
->cffrm_len
[nfrms
] = hpad
+ skb
->len
+ tpad
;
288 /* Fill head padding information. */
289 *pfrm
= (u8
)(hpad
- 1);
292 /* Update network statistics. */
293 spin_lock_bh(&cfhsi
->lock
);
294 cfhsi
->ndev
->stats
.tx_packets
++;
295 cfhsi
->ndev
->stats
.tx_bytes
+= skb
->len
;
296 cfhsi_update_aggregation_stats(cfhsi
, skb
, -1);
297 spin_unlock_bh(&cfhsi
->lock
);
299 /* Copy in CAIF frame. */
300 skb_copy_bits(skb
, 0, pfrm
, skb
->len
);
302 /* Update payload length. */
303 pld_len
+= desc
->cffrm_len
[nfrms
];
305 /* Update frame pointer. */
306 pfrm
+= skb
->len
+ tpad
;
308 /* Consume the SKB */
312 /* Update number of frames. */
316 /* Unused length fields should be zero-filled (according to SPEC). */
317 while (nfrms
< CFHSI_MAX_PKTS
) {
318 desc
->cffrm_len
[nfrms
] = 0x0000;
322 /* Check if we can piggy-back another descriptor. */
323 if (cfhsi_can_send_aggregate(cfhsi
))
324 desc
->header
|= CFHSI_PIGGY_DESC
;
326 desc
->header
&= ~CFHSI_PIGGY_DESC
;
328 return CFHSI_DESC_SZ
+ pld_len
;
331 static void cfhsi_start_tx(struct cfhsi
*cfhsi
)
333 struct cfhsi_desc
*desc
= (struct cfhsi_desc
*)cfhsi
->tx_buf
;
336 netdev_dbg(cfhsi
->ndev
, "%s.\n", __func__
);
338 if (test_bit(CFHSI_SHUTDOWN
, &cfhsi
->bits
))
342 /* Create HSI frame. */
343 len
= cfhsi_tx_frm(desc
, cfhsi
);
345 spin_lock_bh(&cfhsi
->lock
);
346 if (unlikely(cfhsi_tx_queue_len(cfhsi
))) {
347 spin_unlock_bh(&cfhsi
->lock
);
351 cfhsi
->tx_state
= CFHSI_TX_STATE_IDLE
;
352 /* Start inactivity timer. */
353 mod_timer(&cfhsi
->inactivity_timer
,
354 jiffies
+ cfhsi
->cfg
.inactivity_timeout
);
355 spin_unlock_bh(&cfhsi
->lock
);
359 /* Set up new transfer. */
360 res
= cfhsi
->ops
->cfhsi_tx(cfhsi
->tx_buf
, len
, cfhsi
->ops
);
361 if (WARN_ON(res
< 0))
362 netdev_err(cfhsi
->ndev
, "%s: TX error %d.\n",
367 static void cfhsi_tx_done(struct cfhsi
*cfhsi
)
369 netdev_dbg(cfhsi
->ndev
, "%s.\n", __func__
);
371 if (test_bit(CFHSI_SHUTDOWN
, &cfhsi
->bits
))
375 * Send flow on if flow off has been previously signalled
376 * and number of packets is below low water mark.
378 spin_lock_bh(&cfhsi
->lock
);
379 if (cfhsi
->flow_off_sent
&&
380 cfhsi_tx_queue_len(cfhsi
) <= cfhsi
->cfg
.q_low_mark
&&
381 cfhsi
->cfdev
.flowctrl
) {
383 cfhsi
->flow_off_sent
= 0;
384 cfhsi
->cfdev
.flowctrl(cfhsi
->ndev
, ON
);
387 if (cfhsi_can_send_aggregate(cfhsi
)) {
388 spin_unlock_bh(&cfhsi
->lock
);
389 cfhsi_start_tx(cfhsi
);
391 mod_timer(&cfhsi
->aggregation_timer
,
392 jiffies
+ cfhsi
->cfg
.aggregation_timeout
);
393 spin_unlock_bh(&cfhsi
->lock
);
399 static void cfhsi_tx_done_cb(struct cfhsi_cb_ops
*cb_ops
)
403 cfhsi
= container_of(cb_ops
, struct cfhsi
, cb_ops
);
404 netdev_dbg(cfhsi
->ndev
, "%s.\n",
407 if (test_bit(CFHSI_SHUTDOWN
, &cfhsi
->bits
))
409 cfhsi_tx_done(cfhsi
);
412 static int cfhsi_rx_desc(struct cfhsi_desc
*desc
, struct cfhsi
*cfhsi
)
419 if ((desc
->header
& ~CFHSI_PIGGY_DESC
) ||
420 (desc
->offset
> CFHSI_MAX_EMB_FRM_SZ
)) {
421 netdev_err(cfhsi
->ndev
, "%s: Invalid descriptor.\n",
426 /* Check for embedded CAIF frame. */
430 pfrm
= ((u8
*)desc
) + desc
->offset
;
432 /* Remove offset padding. */
435 /* Read length of CAIF frame (little endian). */
437 len
|= ((*(pfrm
+1)) << 8) & 0xFF00;
438 len
+= 2; /* Add FCS fields. */
440 /* Sanity check length of CAIF frame. */
441 if (unlikely(len
> CFHSI_MAX_CAIF_FRAME_SZ
)) {
442 netdev_err(cfhsi
->ndev
, "%s: Invalid length.\n",
447 /* Allocate SKB (OK even in IRQ context). */
448 skb
= alloc_skb(len
+ 1, GFP_ATOMIC
);
450 netdev_err(cfhsi
->ndev
, "%s: Out of memory !\n",
454 caif_assert(skb
!= NULL
);
456 skb_put_data(skb
, pfrm
, len
);
458 skb
->protocol
= htons(ETH_P_CAIF
);
459 skb_reset_mac_header(skb
);
460 skb
->dev
= cfhsi
->ndev
;
463 * We are in a callback handler and
464 * unfortunately we don't know what context we're
472 /* Update network statistics. */
473 cfhsi
->ndev
->stats
.rx_packets
++;
474 cfhsi
->ndev
->stats
.rx_bytes
+= len
;
477 /* Calculate transfer length. */
478 plen
= desc
->cffrm_len
;
479 while (nfrms
< CFHSI_MAX_PKTS
&& *plen
) {
485 /* Check for piggy-backed descriptor. */
486 if (desc
->header
& CFHSI_PIGGY_DESC
)
487 xfer_sz
+= CFHSI_DESC_SZ
;
489 if ((xfer_sz
% 4) || (xfer_sz
> (CFHSI_BUF_SZ_RX
- CFHSI_DESC_SZ
))) {
490 netdev_err(cfhsi
->ndev
,
491 "%s: Invalid payload len: %d, ignored.\n",
498 static int cfhsi_rx_desc_len(struct cfhsi_desc
*desc
)
504 if ((desc
->header
& ~CFHSI_PIGGY_DESC
) ||
505 (desc
->offset
> CFHSI_MAX_EMB_FRM_SZ
)) {
507 pr_err("Invalid descriptor. %x %x\n", desc
->header
,
512 /* Calculate transfer length. */
513 plen
= desc
->cffrm_len
;
514 while (nfrms
< CFHSI_MAX_PKTS
&& *plen
) {
521 pr_err("Invalid payload len: %d, ignored.\n", xfer_sz
);
527 static int cfhsi_rx_pld(struct cfhsi_desc
*desc
, struct cfhsi
*cfhsi
)
534 /* Sanity check header and offset. */
535 if (WARN_ON((desc
->header
& ~CFHSI_PIGGY_DESC
) ||
536 (desc
->offset
> CFHSI_MAX_EMB_FRM_SZ
))) {
537 netdev_err(cfhsi
->ndev
, "%s: Invalid descriptor.\n",
542 /* Set frame pointer to start of payload. */
543 pfrm
= desc
->emb_frm
+ CFHSI_MAX_EMB_FRM_SZ
;
544 plen
= desc
->cffrm_len
;
546 /* Skip already processed frames. */
547 while (nfrms
< cfhsi
->rx_state
.nfrms
) {
555 while (nfrms
< CFHSI_MAX_PKTS
&& *plen
) {
560 /* CAIF frame starts after head padding. */
561 pcffrm
= pfrm
+ *pfrm
+ 1;
563 /* Read length of CAIF frame (little endian). */
565 len
|= ((*(pcffrm
+ 1)) << 8) & 0xFF00;
566 len
+= 2; /* Add FCS fields. */
568 /* Sanity check length of CAIF frames. */
569 if (unlikely(len
> CFHSI_MAX_CAIF_FRAME_SZ
)) {
570 netdev_err(cfhsi
->ndev
, "%s: Invalid length.\n",
575 /* Allocate SKB (OK even in IRQ context). */
576 skb
= alloc_skb(len
+ 1, GFP_ATOMIC
);
578 netdev_err(cfhsi
->ndev
, "%s: Out of memory !\n",
580 cfhsi
->rx_state
.nfrms
= nfrms
;
583 caif_assert(skb
!= NULL
);
585 skb_put_data(skb
, pcffrm
, len
);
587 skb
->protocol
= htons(ETH_P_CAIF
);
588 skb_reset_mac_header(skb
);
589 skb
->dev
= cfhsi
->ndev
;
592 * We're called in callback from HSI
593 * and don't know the context we're running in.
600 /* Update network statistics. */
601 cfhsi
->ndev
->stats
.rx_packets
++;
602 cfhsi
->ndev
->stats
.rx_bytes
+= len
;
613 static void cfhsi_rx_done(struct cfhsi
*cfhsi
)
616 int desc_pld_len
= 0, rx_len
, rx_state
;
617 struct cfhsi_desc
*desc
= NULL
;
619 struct cfhsi_desc
*piggy_desc
= NULL
;
621 desc
= (struct cfhsi_desc
*)cfhsi
->rx_buf
;
623 netdev_dbg(cfhsi
->ndev
, "%s\n", __func__
);
625 if (test_bit(CFHSI_SHUTDOWN
, &cfhsi
->bits
))
628 /* Update inactivity timer if pending. */
629 spin_lock_bh(&cfhsi
->lock
);
630 mod_timer_pending(&cfhsi
->inactivity_timer
,
631 jiffies
+ cfhsi
->cfg
.inactivity_timeout
);
632 spin_unlock_bh(&cfhsi
->lock
);
634 if (cfhsi
->rx_state
.state
== CFHSI_RX_STATE_DESC
) {
635 desc_pld_len
= cfhsi_rx_desc_len(desc
);
637 if (desc_pld_len
< 0)
640 rx_buf
= cfhsi
->rx_buf
;
641 rx_len
= desc_pld_len
;
642 if (desc_pld_len
> 0 && (desc
->header
& CFHSI_PIGGY_DESC
))
643 rx_len
+= CFHSI_DESC_SZ
;
644 if (desc_pld_len
== 0)
645 rx_buf
= cfhsi
->rx_flip_buf
;
647 rx_buf
= cfhsi
->rx_flip_buf
;
649 rx_len
= CFHSI_DESC_SZ
;
650 if (cfhsi
->rx_state
.pld_len
> 0 &&
651 (desc
->header
& CFHSI_PIGGY_DESC
)) {
653 piggy_desc
= (struct cfhsi_desc
*)
654 (desc
->emb_frm
+ CFHSI_MAX_EMB_FRM_SZ
+
655 cfhsi
->rx_state
.pld_len
);
657 cfhsi
->rx_state
.piggy_desc
= true;
659 /* Extract payload len from piggy-backed descriptor. */
660 desc_pld_len
= cfhsi_rx_desc_len(piggy_desc
);
661 if (desc_pld_len
< 0)
664 if (desc_pld_len
> 0) {
665 rx_len
= desc_pld_len
;
666 if (piggy_desc
->header
& CFHSI_PIGGY_DESC
)
667 rx_len
+= CFHSI_DESC_SZ
;
671 * Copy needed information from the piggy-backed
672 * descriptor to the descriptor in the start.
674 memcpy(rx_buf
, (u8
*)piggy_desc
,
675 CFHSI_DESC_SHORT_SZ
);
680 rx_state
= CFHSI_RX_STATE_PAYLOAD
;
681 rx_ptr
= rx_buf
+ CFHSI_DESC_SZ
;
683 rx_state
= CFHSI_RX_STATE_DESC
;
685 rx_len
= CFHSI_DESC_SZ
;
688 /* Initiate next read */
689 if (test_bit(CFHSI_AWAKE
, &cfhsi
->bits
)) {
690 /* Set up new transfer. */
691 netdev_dbg(cfhsi
->ndev
, "%s: Start RX.\n",
694 res
= cfhsi
->ops
->cfhsi_rx(rx_ptr
, rx_len
,
696 if (WARN_ON(res
< 0)) {
697 netdev_err(cfhsi
->ndev
, "%s: RX error %d.\n",
699 cfhsi
->ndev
->stats
.rx_errors
++;
700 cfhsi
->ndev
->stats
.rx_dropped
++;
704 if (cfhsi
->rx_state
.state
== CFHSI_RX_STATE_DESC
) {
705 /* Extract payload from descriptor */
706 if (cfhsi_rx_desc(desc
, cfhsi
) < 0)
709 /* Extract payload */
710 if (cfhsi_rx_pld(desc
, cfhsi
) < 0)
713 /* Extract any payload in piggyback descriptor. */
714 if (cfhsi_rx_desc(piggy_desc
, cfhsi
) < 0)
716 /* Mark no embedded frame after extracting it */
717 piggy_desc
->offset
= 0;
721 /* Update state info */
722 memset(&cfhsi
->rx_state
, 0, sizeof(cfhsi
->rx_state
));
723 cfhsi
->rx_state
.state
= rx_state
;
724 cfhsi
->rx_ptr
= rx_ptr
;
725 cfhsi
->rx_len
= rx_len
;
726 cfhsi
->rx_state
.pld_len
= desc_pld_len
;
727 cfhsi
->rx_state
.piggy_desc
= desc
->header
& CFHSI_PIGGY_DESC
;
729 if (rx_buf
!= cfhsi
->rx_buf
)
730 swap(cfhsi
->rx_buf
, cfhsi
->rx_flip_buf
);
734 netdev_err(cfhsi
->ndev
, "%s: Out of sync.\n", __func__
);
735 print_hex_dump_bytes("--> ", DUMP_PREFIX_NONE
,
736 cfhsi
->rx_buf
, CFHSI_DESC_SZ
);
737 schedule_work(&cfhsi
->out_of_sync_work
);
740 static void cfhsi_rx_slowpath(unsigned long arg
)
742 struct cfhsi
*cfhsi
= (struct cfhsi
*)arg
;
744 netdev_dbg(cfhsi
->ndev
, "%s.\n",
747 cfhsi_rx_done(cfhsi
);
750 static void cfhsi_rx_done_cb(struct cfhsi_cb_ops
*cb_ops
)
754 cfhsi
= container_of(cb_ops
, struct cfhsi
, cb_ops
);
755 netdev_dbg(cfhsi
->ndev
, "%s.\n",
758 if (test_bit(CFHSI_SHUTDOWN
, &cfhsi
->bits
))
761 if (test_and_clear_bit(CFHSI_FLUSH_FIFO
, &cfhsi
->bits
))
762 wake_up_interruptible(&cfhsi
->flush_fifo_wait
);
764 cfhsi_rx_done(cfhsi
);
767 static void cfhsi_wake_up(struct work_struct
*work
)
769 struct cfhsi
*cfhsi
= NULL
;
774 cfhsi
= container_of(work
, struct cfhsi
, wake_up_work
);
776 if (test_bit(CFHSI_SHUTDOWN
, &cfhsi
->bits
))
779 if (unlikely(test_bit(CFHSI_AWAKE
, &cfhsi
->bits
))) {
780 /* It happenes when wakeup is requested by
781 * both ends at the same time. */
782 clear_bit(CFHSI_WAKE_UP
, &cfhsi
->bits
);
783 clear_bit(CFHSI_WAKE_UP_ACK
, &cfhsi
->bits
);
787 /* Activate wake line. */
788 cfhsi
->ops
->cfhsi_wake_up(cfhsi
->ops
);
790 netdev_dbg(cfhsi
->ndev
, "%s: Start waiting.\n",
793 /* Wait for acknowledge. */
794 ret
= CFHSI_WAKE_TOUT
;
795 ret
= wait_event_interruptible_timeout(cfhsi
->wake_up_wait
,
796 test_and_clear_bit(CFHSI_WAKE_UP_ACK
,
798 if (unlikely(ret
< 0)) {
799 /* Interrupted by signal. */
800 netdev_err(cfhsi
->ndev
, "%s: Signalled: %ld.\n",
803 clear_bit(CFHSI_WAKE_UP
, &cfhsi
->bits
);
804 cfhsi
->ops
->cfhsi_wake_down(cfhsi
->ops
);
807 bool ca_wake
= false;
808 size_t fifo_occupancy
= 0;
811 netdev_dbg(cfhsi
->ndev
, "%s: Timeout.\n",
814 /* Check FIFO to check if modem has sent something. */
815 WARN_ON(cfhsi
->ops
->cfhsi_fifo_occupancy(cfhsi
->ops
,
818 netdev_dbg(cfhsi
->ndev
, "%s: Bytes in FIFO: %u.\n",
819 __func__
, (unsigned) fifo_occupancy
);
821 /* Check if we misssed the interrupt. */
822 WARN_ON(cfhsi
->ops
->cfhsi_get_peer_wake(cfhsi
->ops
,
826 netdev_err(cfhsi
->ndev
, "%s: CA Wake missed !.\n",
829 /* Clear the CFHSI_WAKE_UP_ACK bit to prevent race. */
830 clear_bit(CFHSI_WAKE_UP_ACK
, &cfhsi
->bits
);
832 /* Continue execution. */
836 clear_bit(CFHSI_WAKE_UP
, &cfhsi
->bits
);
837 cfhsi
->ops
->cfhsi_wake_down(cfhsi
->ops
);
841 netdev_dbg(cfhsi
->ndev
, "%s: Woken.\n",
844 /* Clear power up bit. */
845 set_bit(CFHSI_AWAKE
, &cfhsi
->bits
);
846 clear_bit(CFHSI_WAKE_UP
, &cfhsi
->bits
);
848 /* Resume read operation. */
849 netdev_dbg(cfhsi
->ndev
, "%s: Start RX.\n", __func__
);
850 res
= cfhsi
->ops
->cfhsi_rx(cfhsi
->rx_ptr
, cfhsi
->rx_len
, cfhsi
->ops
);
852 if (WARN_ON(res
< 0))
853 netdev_err(cfhsi
->ndev
, "%s: RX err %d.\n", __func__
, res
);
855 /* Clear power up acknowledment. */
856 clear_bit(CFHSI_WAKE_UP_ACK
, &cfhsi
->bits
);
858 spin_lock_bh(&cfhsi
->lock
);
860 /* Resume transmit if queues are not empty. */
861 if (!cfhsi_tx_queue_len(cfhsi
)) {
862 netdev_dbg(cfhsi
->ndev
, "%s: Peer wake, start timer.\n",
864 /* Start inactivity timer. */
865 mod_timer(&cfhsi
->inactivity_timer
,
866 jiffies
+ cfhsi
->cfg
.inactivity_timeout
);
867 spin_unlock_bh(&cfhsi
->lock
);
871 netdev_dbg(cfhsi
->ndev
, "%s: Host wake.\n",
874 spin_unlock_bh(&cfhsi
->lock
);
876 /* Create HSI frame. */
877 len
= cfhsi_tx_frm((struct cfhsi_desc
*)cfhsi
->tx_buf
, cfhsi
);
879 if (likely(len
> 0)) {
880 /* Set up new transfer. */
881 res
= cfhsi
->ops
->cfhsi_tx(cfhsi
->tx_buf
, len
, cfhsi
->ops
);
882 if (WARN_ON(res
< 0)) {
883 netdev_err(cfhsi
->ndev
, "%s: TX error %d.\n",
885 cfhsi_abort_tx(cfhsi
);
888 netdev_err(cfhsi
->ndev
,
889 "%s: Failed to create HSI frame: %d.\n",
894 static void cfhsi_wake_down(struct work_struct
*work
)
897 struct cfhsi
*cfhsi
= NULL
;
898 size_t fifo_occupancy
= 0;
899 int retry
= CFHSI_WAKE_TOUT
;
901 cfhsi
= container_of(work
, struct cfhsi
, wake_down_work
);
902 netdev_dbg(cfhsi
->ndev
, "%s.\n", __func__
);
904 if (test_bit(CFHSI_SHUTDOWN
, &cfhsi
->bits
))
907 /* Deactivate wake line. */
908 cfhsi
->ops
->cfhsi_wake_down(cfhsi
->ops
);
910 /* Wait for acknowledge. */
911 ret
= CFHSI_WAKE_TOUT
;
912 ret
= wait_event_interruptible_timeout(cfhsi
->wake_down_wait
,
913 test_and_clear_bit(CFHSI_WAKE_DOWN_ACK
,
916 /* Interrupted by signal. */
917 netdev_err(cfhsi
->ndev
, "%s: Signalled: %ld.\n",
924 netdev_err(cfhsi
->ndev
, "%s: Timeout.\n", __func__
);
926 /* Check if we misssed the interrupt. */
927 WARN_ON(cfhsi
->ops
->cfhsi_get_peer_wake(cfhsi
->ops
,
930 netdev_err(cfhsi
->ndev
, "%s: CA Wake missed !.\n",
934 /* Check FIFO occupancy. */
936 WARN_ON(cfhsi
->ops
->cfhsi_fifo_occupancy(cfhsi
->ops
,
942 set_current_state(TASK_INTERRUPTIBLE
);
948 netdev_err(cfhsi
->ndev
, "%s: FIFO Timeout.\n", __func__
);
950 /* Clear AWAKE condition. */
951 clear_bit(CFHSI_AWAKE
, &cfhsi
->bits
);
953 /* Cancel pending RX requests. */
954 cfhsi
->ops
->cfhsi_rx_cancel(cfhsi
->ops
);
957 static void cfhsi_out_of_sync(struct work_struct
*work
)
959 struct cfhsi
*cfhsi
= NULL
;
961 cfhsi
= container_of(work
, struct cfhsi
, out_of_sync_work
);
964 dev_close(cfhsi
->ndev
);
968 static void cfhsi_wake_up_cb(struct cfhsi_cb_ops
*cb_ops
)
970 struct cfhsi
*cfhsi
= NULL
;
972 cfhsi
= container_of(cb_ops
, struct cfhsi
, cb_ops
);
973 netdev_dbg(cfhsi
->ndev
, "%s.\n",
976 set_bit(CFHSI_WAKE_UP_ACK
, &cfhsi
->bits
);
977 wake_up_interruptible(&cfhsi
->wake_up_wait
);
979 if (test_bit(CFHSI_SHUTDOWN
, &cfhsi
->bits
))
982 /* Schedule wake up work queue if the peer initiates. */
983 if (!test_and_set_bit(CFHSI_WAKE_UP
, &cfhsi
->bits
))
984 queue_work(cfhsi
->wq
, &cfhsi
->wake_up_work
);
987 static void cfhsi_wake_down_cb(struct cfhsi_cb_ops
*cb_ops
)
989 struct cfhsi
*cfhsi
= NULL
;
991 cfhsi
= container_of(cb_ops
, struct cfhsi
, cb_ops
);
992 netdev_dbg(cfhsi
->ndev
, "%s.\n",
995 /* Initiating low power is only permitted by the host (us). */
996 set_bit(CFHSI_WAKE_DOWN_ACK
, &cfhsi
->bits
);
997 wake_up_interruptible(&cfhsi
->wake_down_wait
);
1000 static void cfhsi_aggregation_tout(unsigned long arg
)
1002 struct cfhsi
*cfhsi
= (struct cfhsi
*)arg
;
1004 netdev_dbg(cfhsi
->ndev
, "%s.\n",
1007 cfhsi_start_tx(cfhsi
);
1010 static int cfhsi_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1012 struct cfhsi
*cfhsi
= NULL
;
1020 cfhsi
= netdev_priv(dev
);
1022 switch (skb
->priority
) {
1023 case TC_PRIO_BESTEFFORT
:
1024 case TC_PRIO_FILLER
:
1026 prio
= CFHSI_PRIO_BEBK
;
1028 case TC_PRIO_INTERACTIVE_BULK
:
1029 prio
= CFHSI_PRIO_VI
;
1031 case TC_PRIO_INTERACTIVE
:
1032 prio
= CFHSI_PRIO_VO
;
1034 case TC_PRIO_CONTROL
:
1036 prio
= CFHSI_PRIO_CTL
;
1040 spin_lock_bh(&cfhsi
->lock
);
1042 /* Update aggregation statistics */
1043 cfhsi_update_aggregation_stats(cfhsi
, skb
, 1);
1046 skb_queue_tail(&cfhsi
->qhead
[prio
], skb
);
1048 /* Sanity check; xmit should not be called after unregister_netdev */
1049 if (WARN_ON(test_bit(CFHSI_SHUTDOWN
, &cfhsi
->bits
))) {
1050 spin_unlock_bh(&cfhsi
->lock
);
1051 cfhsi_abort_tx(cfhsi
);
1055 /* Send flow off if number of packets is above high water mark. */
1056 if (!cfhsi
->flow_off_sent
&&
1057 cfhsi_tx_queue_len(cfhsi
) > cfhsi
->cfg
.q_high_mark
&&
1058 cfhsi
->cfdev
.flowctrl
) {
1059 cfhsi
->flow_off_sent
= 1;
1060 cfhsi
->cfdev
.flowctrl(cfhsi
->ndev
, OFF
);
1063 if (cfhsi
->tx_state
== CFHSI_TX_STATE_IDLE
) {
1064 cfhsi
->tx_state
= CFHSI_TX_STATE_XFER
;
1069 /* Send aggregate if it is possible */
1070 bool aggregate_ready
=
1071 cfhsi_can_send_aggregate(cfhsi
) &&
1072 del_timer(&cfhsi
->aggregation_timer
) > 0;
1073 spin_unlock_bh(&cfhsi
->lock
);
1074 if (aggregate_ready
)
1075 cfhsi_start_tx(cfhsi
);
1079 /* Delete inactivity timer if started. */
1080 timer_active
= del_timer_sync(&cfhsi
->inactivity_timer
);
1082 spin_unlock_bh(&cfhsi
->lock
);
1085 struct cfhsi_desc
*desc
= (struct cfhsi_desc
*)cfhsi
->tx_buf
;
1089 /* Create HSI frame. */
1090 len
= cfhsi_tx_frm(desc
, cfhsi
);
1093 /* Set up new transfer. */
1094 res
= cfhsi
->ops
->cfhsi_tx(cfhsi
->tx_buf
, len
, cfhsi
->ops
);
1095 if (WARN_ON(res
< 0)) {
1096 netdev_err(cfhsi
->ndev
, "%s: TX error %d.\n",
1098 cfhsi_abort_tx(cfhsi
);
1101 /* Schedule wake up work queue if the we initiate. */
1102 if (!test_and_set_bit(CFHSI_WAKE_UP
, &cfhsi
->bits
))
1103 queue_work(cfhsi
->wq
, &cfhsi
->wake_up_work
);
1109 static const struct net_device_ops cfhsi_netdevops
;
1111 static void cfhsi_setup(struct net_device
*dev
)
1114 struct cfhsi
*cfhsi
= netdev_priv(dev
);
1116 dev
->type
= ARPHRD_CAIF
;
1117 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
;
1118 dev
->mtu
= CFHSI_MAX_CAIF_FRAME_SZ
;
1119 dev
->priv_flags
|= IFF_NO_QUEUE
;
1120 dev
->needs_free_netdev
= true;
1121 dev
->netdev_ops
= &cfhsi_netdevops
;
1122 for (i
= 0; i
< CFHSI_PRIO_LAST
; ++i
)
1123 skb_queue_head_init(&cfhsi
->qhead
[i
]);
1124 cfhsi
->cfdev
.link_select
= CAIF_LINK_HIGH_BANDW
;
1125 cfhsi
->cfdev
.use_frag
= false;
1126 cfhsi
->cfdev
.use_stx
= false;
1127 cfhsi
->cfdev
.use_fcs
= false;
1129 cfhsi
->cfg
= hsi_default_config
;
1132 static int cfhsi_open(struct net_device
*ndev
)
1134 struct cfhsi
*cfhsi
= netdev_priv(ndev
);
1137 clear_bit(CFHSI_SHUTDOWN
, &cfhsi
->bits
);
1139 /* Initialize state vaiables. */
1140 cfhsi
->tx_state
= CFHSI_TX_STATE_IDLE
;
1141 cfhsi
->rx_state
.state
= CFHSI_RX_STATE_DESC
;
1144 cfhsi
->flow_off_sent
= 0;
1147 * Allocate a TX buffer with the size of a HSI packet descriptors
1148 * and the necessary room for CAIF payload frames.
1150 cfhsi
->tx_buf
= kzalloc(CFHSI_BUF_SZ_TX
, GFP_KERNEL
);
1151 if (!cfhsi
->tx_buf
) {
1157 * Allocate a RX buffer with the size of two HSI packet descriptors and
1158 * the necessary room for CAIF payload frames.
1160 cfhsi
->rx_buf
= kzalloc(CFHSI_BUF_SZ_RX
, GFP_KERNEL
);
1161 if (!cfhsi
->rx_buf
) {
1166 cfhsi
->rx_flip_buf
= kzalloc(CFHSI_BUF_SZ_RX
, GFP_KERNEL
);
1167 if (!cfhsi
->rx_flip_buf
) {
1169 goto err_alloc_rx_flip
;
1172 /* Initialize aggregation timeout */
1173 cfhsi
->cfg
.aggregation_timeout
= hsi_default_config
.aggregation_timeout
;
1175 /* Initialize recieve vaiables. */
1176 cfhsi
->rx_ptr
= cfhsi
->rx_buf
;
1177 cfhsi
->rx_len
= CFHSI_DESC_SZ
;
1179 /* Initialize spin locks. */
1180 spin_lock_init(&cfhsi
->lock
);
1182 /* Set up the driver. */
1183 cfhsi
->cb_ops
.tx_done_cb
= cfhsi_tx_done_cb
;
1184 cfhsi
->cb_ops
.rx_done_cb
= cfhsi_rx_done_cb
;
1185 cfhsi
->cb_ops
.wake_up_cb
= cfhsi_wake_up_cb
;
1186 cfhsi
->cb_ops
.wake_down_cb
= cfhsi_wake_down_cb
;
1188 /* Initialize the work queues. */
1189 INIT_WORK(&cfhsi
->wake_up_work
, cfhsi_wake_up
);
1190 INIT_WORK(&cfhsi
->wake_down_work
, cfhsi_wake_down
);
1191 INIT_WORK(&cfhsi
->out_of_sync_work
, cfhsi_out_of_sync
);
1193 /* Clear all bit fields. */
1194 clear_bit(CFHSI_WAKE_UP_ACK
, &cfhsi
->bits
);
1195 clear_bit(CFHSI_WAKE_DOWN_ACK
, &cfhsi
->bits
);
1196 clear_bit(CFHSI_WAKE_UP
, &cfhsi
->bits
);
1197 clear_bit(CFHSI_AWAKE
, &cfhsi
->bits
);
1199 /* Create work thread. */
1200 cfhsi
->wq
= alloc_ordered_workqueue(cfhsi
->ndev
->name
, WQ_MEM_RECLAIM
);
1202 netdev_err(cfhsi
->ndev
, "%s: Failed to create work queue.\n",
1208 /* Initialize wait queues. */
1209 init_waitqueue_head(&cfhsi
->wake_up_wait
);
1210 init_waitqueue_head(&cfhsi
->wake_down_wait
);
1211 init_waitqueue_head(&cfhsi
->flush_fifo_wait
);
1213 /* Setup the inactivity timer. */
1214 init_timer(&cfhsi
->inactivity_timer
);
1215 cfhsi
->inactivity_timer
.data
= (unsigned long)cfhsi
;
1216 cfhsi
->inactivity_timer
.function
= cfhsi_inactivity_tout
;
1217 /* Setup the slowpath RX timer. */
1218 init_timer(&cfhsi
->rx_slowpath_timer
);
1219 cfhsi
->rx_slowpath_timer
.data
= (unsigned long)cfhsi
;
1220 cfhsi
->rx_slowpath_timer
.function
= cfhsi_rx_slowpath
;
1221 /* Setup the aggregation timer. */
1222 init_timer(&cfhsi
->aggregation_timer
);
1223 cfhsi
->aggregation_timer
.data
= (unsigned long)cfhsi
;
1224 cfhsi
->aggregation_timer
.function
= cfhsi_aggregation_tout
;
1226 /* Activate HSI interface. */
1227 res
= cfhsi
->ops
->cfhsi_up(cfhsi
->ops
);
1229 netdev_err(cfhsi
->ndev
,
1230 "%s: can't activate HSI interface: %d.\n",
1236 res
= cfhsi_flush_fifo(cfhsi
);
1238 netdev_err(cfhsi
->ndev
, "%s: Can't flush FIFO: %d.\n",
1245 cfhsi
->ops
->cfhsi_down(cfhsi
->ops
);
1247 destroy_workqueue(cfhsi
->wq
);
1249 kfree(cfhsi
->rx_flip_buf
);
1251 kfree(cfhsi
->rx_buf
);
1253 kfree(cfhsi
->tx_buf
);
1258 static int cfhsi_close(struct net_device
*ndev
)
1260 struct cfhsi
*cfhsi
= netdev_priv(ndev
);
1261 u8
*tx_buf
, *rx_buf
, *flip_buf
;
1263 /* going to shutdown driver */
1264 set_bit(CFHSI_SHUTDOWN
, &cfhsi
->bits
);
1266 /* Delete timers if pending */
1267 del_timer_sync(&cfhsi
->inactivity_timer
);
1268 del_timer_sync(&cfhsi
->rx_slowpath_timer
);
1269 del_timer_sync(&cfhsi
->aggregation_timer
);
1271 /* Cancel pending RX request (if any) */
1272 cfhsi
->ops
->cfhsi_rx_cancel(cfhsi
->ops
);
1274 /* Destroy workqueue */
1275 destroy_workqueue(cfhsi
->wq
);
1277 /* Store bufferes: will be freed later. */
1278 tx_buf
= cfhsi
->tx_buf
;
1279 rx_buf
= cfhsi
->rx_buf
;
1280 flip_buf
= cfhsi
->rx_flip_buf
;
1281 /* Flush transmit queues. */
1282 cfhsi_abort_tx(cfhsi
);
1284 /* Deactivate interface */
1285 cfhsi
->ops
->cfhsi_down(cfhsi
->ops
);
1294 static void cfhsi_uninit(struct net_device
*dev
)
1296 struct cfhsi
*cfhsi
= netdev_priv(dev
);
1298 symbol_put(cfhsi_get_device
);
1299 list_del(&cfhsi
->list
);
1302 static const struct net_device_ops cfhsi_netdevops
= {
1303 .ndo_uninit
= cfhsi_uninit
,
1304 .ndo_open
= cfhsi_open
,
1305 .ndo_stop
= cfhsi_close
,
1306 .ndo_start_xmit
= cfhsi_xmit
1309 static void cfhsi_netlink_parms(struct nlattr
*data
[], struct cfhsi
*cfhsi
)
1314 pr_debug("no params data found\n");
1318 i
= __IFLA_CAIF_HSI_INACTIVITY_TOUT
;
1320 * Inactivity timeout in millisecs. Lowest possible value is 1,
1321 * and highest possible is NEXT_TIMER_MAX_DELTA.
1324 u32 inactivity_timeout
= nla_get_u32(data
[i
]);
1325 /* Pre-calculate inactivity timeout. */
1326 cfhsi
->cfg
.inactivity_timeout
= inactivity_timeout
* HZ
/ 1000;
1327 if (cfhsi
->cfg
.inactivity_timeout
== 0)
1328 cfhsi
->cfg
.inactivity_timeout
= 1;
1329 else if (cfhsi
->cfg
.inactivity_timeout
> NEXT_TIMER_MAX_DELTA
)
1330 cfhsi
->cfg
.inactivity_timeout
= NEXT_TIMER_MAX_DELTA
;
1333 i
= __IFLA_CAIF_HSI_AGGREGATION_TOUT
;
1335 cfhsi
->cfg
.aggregation_timeout
= nla_get_u32(data
[i
]);
1337 i
= __IFLA_CAIF_HSI_HEAD_ALIGN
;
1339 cfhsi
->cfg
.head_align
= nla_get_u32(data
[i
]);
1341 i
= __IFLA_CAIF_HSI_TAIL_ALIGN
;
1343 cfhsi
->cfg
.tail_align
= nla_get_u32(data
[i
]);
1345 i
= __IFLA_CAIF_HSI_QHIGH_WATERMARK
;
1347 cfhsi
->cfg
.q_high_mark
= nla_get_u32(data
[i
]);
1349 i
= __IFLA_CAIF_HSI_QLOW_WATERMARK
;
1351 cfhsi
->cfg
.q_low_mark
= nla_get_u32(data
[i
]);
1354 static int caif_hsi_changelink(struct net_device
*dev
, struct nlattr
*tb
[],
1355 struct nlattr
*data
[])
1357 cfhsi_netlink_parms(data
, netdev_priv(dev
));
1358 netdev_state_change(dev
);
1362 static const struct nla_policy caif_hsi_policy
[__IFLA_CAIF_HSI_MAX
+ 1] = {
1363 [__IFLA_CAIF_HSI_INACTIVITY_TOUT
] = { .type
= NLA_U32
, .len
= 4 },
1364 [__IFLA_CAIF_HSI_AGGREGATION_TOUT
] = { .type
= NLA_U32
, .len
= 4 },
1365 [__IFLA_CAIF_HSI_HEAD_ALIGN
] = { .type
= NLA_U32
, .len
= 4 },
1366 [__IFLA_CAIF_HSI_TAIL_ALIGN
] = { .type
= NLA_U32
, .len
= 4 },
1367 [__IFLA_CAIF_HSI_QHIGH_WATERMARK
] = { .type
= NLA_U32
, .len
= 4 },
1368 [__IFLA_CAIF_HSI_QLOW_WATERMARK
] = { .type
= NLA_U32
, .len
= 4 },
1371 static size_t caif_hsi_get_size(const struct net_device
*dev
)
1375 for (i
= __IFLA_CAIF_HSI_UNSPEC
+ 1; i
< __IFLA_CAIF_HSI_MAX
; i
++)
1376 s
+= nla_total_size(caif_hsi_policy
[i
].len
);
1380 static int caif_hsi_fill_info(struct sk_buff
*skb
, const struct net_device
*dev
)
1382 struct cfhsi
*cfhsi
= netdev_priv(dev
);
1384 if (nla_put_u32(skb
, __IFLA_CAIF_HSI_INACTIVITY_TOUT
,
1385 cfhsi
->cfg
.inactivity_timeout
) ||
1386 nla_put_u32(skb
, __IFLA_CAIF_HSI_AGGREGATION_TOUT
,
1387 cfhsi
->cfg
.aggregation_timeout
) ||
1388 nla_put_u32(skb
, __IFLA_CAIF_HSI_HEAD_ALIGN
,
1389 cfhsi
->cfg
.head_align
) ||
1390 nla_put_u32(skb
, __IFLA_CAIF_HSI_TAIL_ALIGN
,
1391 cfhsi
->cfg
.tail_align
) ||
1392 nla_put_u32(skb
, __IFLA_CAIF_HSI_QHIGH_WATERMARK
,
1393 cfhsi
->cfg
.q_high_mark
) ||
1394 nla_put_u32(skb
, __IFLA_CAIF_HSI_QLOW_WATERMARK
,
1395 cfhsi
->cfg
.q_low_mark
))
1401 static int caif_hsi_newlink(struct net
*src_net
, struct net_device
*dev
,
1402 struct nlattr
*tb
[], struct nlattr
*data
[])
1404 struct cfhsi
*cfhsi
= NULL
;
1405 struct cfhsi_ops
*(*get_ops
)(void);
1409 cfhsi
= netdev_priv(dev
);
1410 cfhsi_netlink_parms(data
, cfhsi
);
1412 get_ops
= symbol_get(cfhsi_get_ops
);
1414 pr_err("%s: failed to get the cfhsi_ops\n", __func__
);
1418 /* Assign the HSI device. */
1419 cfhsi
->ops
= (*get_ops
)();
1421 pr_err("%s: failed to get the cfhsi_ops\n", __func__
);
1425 /* Assign the driver to this HSI device. */
1426 cfhsi
->ops
->cb_ops
= &cfhsi
->cb_ops
;
1427 if (register_netdevice(dev
)) {
1428 pr_warn("%s: caif_hsi device registration failed\n", __func__
);
1431 /* Add CAIF HSI device to list. */
1432 list_add_tail(&cfhsi
->list
, &cfhsi_list
);
1436 symbol_put(cfhsi_get_ops
);
1440 static struct rtnl_link_ops caif_hsi_link_ops __read_mostly
= {
1442 .priv_size
= sizeof(struct cfhsi
),
1443 .setup
= cfhsi_setup
,
1444 .maxtype
= __IFLA_CAIF_HSI_MAX
,
1445 .policy
= caif_hsi_policy
,
1446 .newlink
= caif_hsi_newlink
,
1447 .changelink
= caif_hsi_changelink
,
1448 .get_size
= caif_hsi_get_size
,
1449 .fill_info
= caif_hsi_fill_info
,
1452 static void __exit
cfhsi_exit_module(void)
1454 struct list_head
*list_node
;
1455 struct list_head
*n
;
1456 struct cfhsi
*cfhsi
;
1458 rtnl_link_unregister(&caif_hsi_link_ops
);
1461 list_for_each_safe(list_node
, n
, &cfhsi_list
) {
1462 cfhsi
= list_entry(list_node
, struct cfhsi
, list
);
1463 unregister_netdev(cfhsi
->ndev
);
1468 static int __init
cfhsi_init_module(void)
1470 return rtnl_link_register(&caif_hsi_link_ops
);
1473 module_init(cfhsi_init_module
);
1474 module_exit(cfhsi_exit_module
);