ASoC: use of_property_read_bool
[cascardo/linux.git] / net / rxrpc / skbuff.c
1 /* ar-skbuff.c: socket buffer destruction handling
2  *
3  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version
9  * 2 of the License, or (at your option) any later version.
10  */
11
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
14 #include <linux/module.h>
15 #include <linux/net.h>
16 #include <linux/skbuff.h>
17 #include <net/sock.h>
18 #include <net/af_rxrpc.h>
19 #include "ar-internal.h"
20
21 /*
22  * set up for the ACK at the end of the receive phase when we discard the final
23  * receive phase data packet
24  * - called with softirqs disabled
25  */
26 static void rxrpc_request_final_ACK(struct rxrpc_call *call)
27 {
28         /* the call may be aborted before we have a chance to ACK it */
29         write_lock(&call->state_lock);
30
31         switch (call->state) {
32         case RXRPC_CALL_CLIENT_RECV_REPLY:
33                 call->state = RXRPC_CALL_CLIENT_FINAL_ACK;
34                 _debug("request final ACK");
35
36                 /* get an extra ref on the call for the final-ACK generator to
37                  * release */
38                 rxrpc_get_call(call);
39                 set_bit(RXRPC_CALL_EV_ACK_FINAL, &call->events);
40                 if (try_to_del_timer_sync(&call->ack_timer) >= 0)
41                         rxrpc_queue_call(call);
42                 break;
43
44         case RXRPC_CALL_SERVER_RECV_REQUEST:
45                 call->state = RXRPC_CALL_SERVER_ACK_REQUEST;
46         default:
47                 break;
48         }
49
50         write_unlock(&call->state_lock);
51 }
52
53 /*
54  * drop the bottom ACK off of the call ACK window and advance the window
55  */
56 static void rxrpc_hard_ACK_data(struct rxrpc_call *call,
57                                 struct rxrpc_skb_priv *sp)
58 {
59         int loop;
60         u32 seq;
61
62         spin_lock_bh(&call->lock);
63
64         _debug("hard ACK #%u", sp->hdr.seq);
65
66         for (loop = 0; loop < RXRPC_ACKR_WINDOW_ASZ; loop++) {
67                 call->ackr_window[loop] >>= 1;
68                 call->ackr_window[loop] |=
69                         call->ackr_window[loop + 1] << (BITS_PER_LONG - 1);
70         }
71
72         seq = sp->hdr.seq;
73         ASSERTCMP(seq, ==, call->rx_data_eaten + 1);
74         call->rx_data_eaten = seq;
75
76         if (call->ackr_win_top < UINT_MAX)
77                 call->ackr_win_top++;
78
79         ASSERTIFCMP(call->state <= RXRPC_CALL_COMPLETE,
80                     call->rx_data_post, >=, call->rx_data_recv);
81         ASSERTIFCMP(call->state <= RXRPC_CALL_COMPLETE,
82                     call->rx_data_recv, >=, call->rx_data_eaten);
83
84         if (sp->hdr.flags & RXRPC_LAST_PACKET) {
85                 rxrpc_request_final_ACK(call);
86         } else if (atomic_dec_and_test(&call->ackr_not_idle) &&
87                    test_and_clear_bit(RXRPC_CALL_TX_SOFT_ACK, &call->flags)) {
88                 /* We previously soft-ACK'd some received packets that have now
89                  * been consumed, so send a hard-ACK if no more packets are
90                  * immediately forthcoming to allow the transmitter to free up
91                  * its Tx bufferage.
92                  */
93                 _debug("send Rx idle ACK");
94                 __rxrpc_propose_ACK(call, RXRPC_ACK_IDLE, sp->hdr.serial,
95                                     false);
96         }
97
98         spin_unlock_bh(&call->lock);
99 }
100
101 /*
102  * destroy a packet that has an RxRPC control buffer
103  * - advance the hard-ACK state of the parent call (done here in case something
104  *   in the kernel bypasses recvmsg() and steals the packet directly off of the
105  *   socket receive queue)
106  */
107 void rxrpc_packet_destructor(struct sk_buff *skb)
108 {
109         struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
110         struct rxrpc_call *call = sp->call;
111
112         _enter("%p{%p}", skb, call);
113
114         if (call) {
115                 /* send the final ACK on a client call */
116                 if (sp->hdr.type == RXRPC_PACKET_TYPE_DATA)
117                         rxrpc_hard_ACK_data(call, sp);
118                 rxrpc_put_call(call);
119                 sp->call = NULL;
120         }
121
122         if (skb->sk)
123                 sock_rfree(skb);
124         _leave("");
125 }
126
127 /**
128  * rxrpc_kernel_free_skb - Free an RxRPC socket buffer
129  * @skb: The socket buffer to be freed
130  *
131  * Let RxRPC free its own socket buffer, permitting it to maintain debug
132  * accounting.
133  */
134 void rxrpc_kernel_free_skb(struct sk_buff *skb)
135 {
136         rxrpc_free_skb(skb);
137 }
138 EXPORT_SYMBOL(rxrpc_kernel_free_skb);