Linux 4.8-rc8
[linux/fpc-iii.git] / net / rxrpc / skbuff.c
blob06c51d4b622d67ae77d54813a668e4f722a4c8a9
1 /* ar-skbuff.c: socket buffer destruction handling
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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.
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
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"
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
26 static void rxrpc_request_final_ACK(struct rxrpc_call *call)
28 /* the call may be aborted before we have a chance to ACK it */
29 write_lock(&call->state_lock);
31 switch (call->state) {
32 case RXRPC_CALL_CLIENT_RECV_REPLY:
33 call->state = RXRPC_CALL_CLIENT_FINAL_ACK;
34 _debug("request final ACK");
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;
44 case RXRPC_CALL_SERVER_RECV_REQUEST:
45 call->state = RXRPC_CALL_SERVER_ACK_REQUEST;
46 default:
47 break;
50 write_unlock(&call->state_lock);
54 * drop the bottom ACK off of the call ACK window and advance the window
56 static void rxrpc_hard_ACK_data(struct rxrpc_call *call,
57 struct rxrpc_skb_priv *sp)
59 int loop;
60 u32 seq;
62 spin_lock_bh(&call->lock);
64 _debug("hard ACK #%u", sp->hdr.seq);
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);
72 seq = sp->hdr.seq;
73 ASSERTCMP(seq, ==, call->rx_data_eaten + 1);
74 call->rx_data_eaten = seq;
76 if (call->ackr_win_top < UINT_MAX)
77 call->ackr_win_top++;
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);
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.
93 _debug("send Rx idle ACK");
94 __rxrpc_propose_ACK(call, RXRPC_ACK_IDLE, sp->hdr.serial,
95 false);
98 spin_unlock_bh(&call->lock);
102 * rxrpc_kernel_data_consumed - Record consumption of data message
103 * @call: The call to which the message pertains.
104 * @skb: Message holding data
106 * Record the consumption of a data message and generate an ACK if appropriate.
107 * The call state is shifted if this was the final packet. The caller must be
108 * in process context with no spinlocks held.
110 * TODO: Actually generate the ACK here rather than punting this to the
111 * workqueue.
113 void rxrpc_kernel_data_consumed(struct rxrpc_call *call, struct sk_buff *skb)
115 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
117 _enter("%d,%p{%u}", call->debug_id, skb, sp->hdr.seq);
119 ASSERTCMP(sp->call, ==, call);
120 ASSERTCMP(sp->hdr.type, ==, RXRPC_PACKET_TYPE_DATA);
122 /* TODO: Fix the sequence number tracking */
123 ASSERTCMP(sp->hdr.seq, >=, call->rx_data_recv);
124 ASSERTCMP(sp->hdr.seq, <=, call->rx_data_recv + 1);
125 ASSERTCMP(sp->hdr.seq, >, call->rx_data_eaten);
127 call->rx_data_recv = sp->hdr.seq;
128 rxrpc_hard_ACK_data(call, sp);
130 EXPORT_SYMBOL(rxrpc_kernel_data_consumed);
133 * Destroy a packet that has an RxRPC control buffer
135 void rxrpc_packet_destructor(struct sk_buff *skb)
137 struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
138 struct rxrpc_call *call = sp->call;
140 _enter("%p{%p}", skb, call);
142 if (call) {
143 if (atomic_dec_return(&call->skb_count) < 0)
144 BUG();
145 rxrpc_put_call(call);
146 sp->call = NULL;
149 if (skb->sk)
150 sock_rfree(skb);
151 _leave("");
155 * rxrpc_kernel_free_skb - Free an RxRPC socket buffer
156 * @skb: The socket buffer to be freed
158 * Let RxRPC free its own socket buffer, permitting it to maintain debug
159 * accounting.
161 void rxrpc_kernel_free_skb(struct sk_buff *skb)
163 rxrpc_free_skb(skb);
165 EXPORT_SYMBOL(rxrpc_kernel_free_skb);