rapidio: add relation links between RIO device structures
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / dccp / ccids / ccid2.c
blobd850e291f87c8b23defdba15d89849892038b251
1 /*
2 * Copyright (c) 2005, 2006 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
4 * Changes to meet Linux coding standards, and DCCP infrastructure fixes.
6 * Copyright (c) 2006 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * This implementation should follow RFC 4341
26 #include <linux/slab.h>
27 #include "../feat.h"
28 #include "ccid2.h"
31 #ifdef CONFIG_IP_DCCP_CCID2_DEBUG
32 static int ccid2_debug;
33 #define ccid2_pr_debug(format, a...) DCCP_PR_DEBUG(ccid2_debug, format, ##a)
34 #else
35 #define ccid2_pr_debug(format, a...)
36 #endif
38 static int ccid2_hc_tx_alloc_seq(struct ccid2_hc_tx_sock *hc)
40 struct ccid2_seq *seqp;
41 int i;
43 /* check if we have space to preserve the pointer to the buffer */
44 if (hc->tx_seqbufc >= (sizeof(hc->tx_seqbuf) /
45 sizeof(struct ccid2_seq *)))
46 return -ENOMEM;
48 /* allocate buffer and initialize linked list */
49 seqp = kmalloc(CCID2_SEQBUF_LEN * sizeof(struct ccid2_seq), gfp_any());
50 if (seqp == NULL)
51 return -ENOMEM;
53 for (i = 0; i < (CCID2_SEQBUF_LEN - 1); i++) {
54 seqp[i].ccid2s_next = &seqp[i + 1];
55 seqp[i + 1].ccid2s_prev = &seqp[i];
57 seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = seqp;
58 seqp->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1];
60 /* This is the first allocation. Initiate the head and tail. */
61 if (hc->tx_seqbufc == 0)
62 hc->tx_seqh = hc->tx_seqt = seqp;
63 else {
64 /* link the existing list with the one we just created */
65 hc->tx_seqh->ccid2s_next = seqp;
66 seqp->ccid2s_prev = hc->tx_seqh;
68 hc->tx_seqt->ccid2s_prev = &seqp[CCID2_SEQBUF_LEN - 1];
69 seqp[CCID2_SEQBUF_LEN - 1].ccid2s_next = hc->tx_seqt;
72 /* store the original pointer to the buffer so we can free it */
73 hc->tx_seqbuf[hc->tx_seqbufc] = seqp;
74 hc->tx_seqbufc++;
76 return 0;
79 static int ccid2_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
81 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
83 if (hc->tx_pipe < hc->tx_cwnd)
84 return 0;
86 return 1; /* XXX CCID should dequeue when ready instead of polling */
89 static void ccid2_change_l_ack_ratio(struct sock *sk, u32 val)
91 struct dccp_sock *dp = dccp_sk(sk);
92 u32 max_ratio = DIV_ROUND_UP(ccid2_hc_tx_sk(sk)->tx_cwnd, 2);
95 * Ensure that Ack Ratio does not exceed ceil(cwnd/2), which is (2) from
96 * RFC 4341, 6.1.2. We ignore the statement that Ack Ratio 2 is always
97 * acceptable since this causes starvation/deadlock whenever cwnd < 2.
98 * The same problem arises when Ack Ratio is 0 (ie. Ack Ratio disabled).
100 if (val == 0 || val > max_ratio) {
101 DCCP_WARN("Limiting Ack Ratio (%u) to %u\n", val, max_ratio);
102 val = max_ratio;
104 if (val > DCCPF_ACK_RATIO_MAX)
105 val = DCCPF_ACK_RATIO_MAX;
107 if (val == dp->dccps_l_ack_ratio)
108 return;
110 ccid2_pr_debug("changing local ack ratio to %u\n", val);
111 dp->dccps_l_ack_ratio = val;
114 static void ccid2_hc_tx_rto_expire(unsigned long data)
116 struct sock *sk = (struct sock *)data;
117 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
119 bh_lock_sock(sk);
120 if (sock_owned_by_user(sk)) {
121 sk_reset_timer(sk, &hc->tx_rtotimer, jiffies + HZ / 5);
122 goto out;
125 ccid2_pr_debug("RTO_EXPIRE\n");
127 /* back-off timer */
128 hc->tx_rto <<= 1;
129 if (hc->tx_rto > DCCP_RTO_MAX)
130 hc->tx_rto = DCCP_RTO_MAX;
132 sk_reset_timer(sk, &hc->tx_rtotimer, jiffies + hc->tx_rto);
134 /* adjust pipe, cwnd etc */
135 hc->tx_ssthresh = hc->tx_cwnd / 2;
136 if (hc->tx_ssthresh < 2)
137 hc->tx_ssthresh = 2;
138 hc->tx_cwnd = 1;
139 hc->tx_pipe = 0;
141 /* clear state about stuff we sent */
142 hc->tx_seqt = hc->tx_seqh;
143 hc->tx_packets_acked = 0;
145 /* clear ack ratio state. */
146 hc->tx_rpseq = 0;
147 hc->tx_rpdupack = -1;
148 ccid2_change_l_ack_ratio(sk, 1);
149 out:
150 bh_unlock_sock(sk);
151 sock_put(sk);
154 static void ccid2_hc_tx_packet_sent(struct sock *sk, unsigned int len)
156 struct dccp_sock *dp = dccp_sk(sk);
157 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
158 struct ccid2_seq *next;
160 hc->tx_pipe++;
162 hc->tx_seqh->ccid2s_seq = dp->dccps_gss;
163 hc->tx_seqh->ccid2s_acked = 0;
164 hc->tx_seqh->ccid2s_sent = ccid2_time_stamp;
166 next = hc->tx_seqh->ccid2s_next;
167 /* check if we need to alloc more space */
168 if (next == hc->tx_seqt) {
169 if (ccid2_hc_tx_alloc_seq(hc)) {
170 DCCP_CRIT("packet history - out of memory!");
171 /* FIXME: find a more graceful way to bail out */
172 return;
174 next = hc->tx_seqh->ccid2s_next;
175 BUG_ON(next == hc->tx_seqt);
177 hc->tx_seqh = next;
179 ccid2_pr_debug("cwnd=%d pipe=%d\n", hc->tx_cwnd, hc->tx_pipe);
182 * FIXME: The code below is broken and the variables have been removed
183 * from the socket struct. The `ackloss' variable was always set to 0,
184 * and with arsent there are several problems:
185 * (i) it doesn't just count the number of Acks, but all sent packets;
186 * (ii) it is expressed in # of packets, not # of windows, so the
187 * comparison below uses the wrong formula: Appendix A of RFC 4341
188 * comes up with the number K = cwnd / (R^2 - R) of consecutive windows
189 * of data with no lost or marked Ack packets. If arsent were the # of
190 * consecutive Acks received without loss, then Ack Ratio needs to be
191 * decreased by 1 when
192 * arsent >= K * cwnd / R = cwnd^2 / (R^3 - R^2)
193 * where cwnd / R is the number of Acks received per window of data
194 * (cf. RFC 4341, App. A). The problems are that
195 * - arsent counts other packets as well;
196 * - the comparison uses a formula different from RFC 4341;
197 * - computing a cubic/quadratic equation each time is too complicated.
198 * Hence a different algorithm is needed.
200 #if 0
201 /* Ack Ratio. Need to maintain a concept of how many windows we sent */
202 hc->tx_arsent++;
203 /* We had an ack loss in this window... */
204 if (hc->tx_ackloss) {
205 if (hc->tx_arsent >= hc->tx_cwnd) {
206 hc->tx_arsent = 0;
207 hc->tx_ackloss = 0;
209 } else {
210 /* No acks lost up to now... */
211 /* decrease ack ratio if enough packets were sent */
212 if (dp->dccps_l_ack_ratio > 1) {
213 /* XXX don't calculate denominator each time */
214 int denom = dp->dccps_l_ack_ratio * dp->dccps_l_ack_ratio -
215 dp->dccps_l_ack_ratio;
217 denom = hc->tx_cwnd * hc->tx_cwnd / denom;
219 if (hc->tx_arsent >= denom) {
220 ccid2_change_l_ack_ratio(sk, dp->dccps_l_ack_ratio - 1);
221 hc->tx_arsent = 0;
223 } else {
224 /* we can't increase ack ratio further [1] */
225 hc->tx_arsent = 0; /* or maybe set it to cwnd*/
228 #endif
230 sk_reset_timer(sk, &hc->tx_rtotimer, jiffies + hc->tx_rto);
232 #ifdef CONFIG_IP_DCCP_CCID2_DEBUG
233 do {
234 struct ccid2_seq *seqp = hc->tx_seqt;
236 while (seqp != hc->tx_seqh) {
237 ccid2_pr_debug("out seq=%llu acked=%d time=%u\n",
238 (unsigned long long)seqp->ccid2s_seq,
239 seqp->ccid2s_acked, seqp->ccid2s_sent);
240 seqp = seqp->ccid2s_next;
242 } while (0);
243 ccid2_pr_debug("=========\n");
244 #endif
247 /* XXX Lame code duplication!
248 * returns -1 if none was found.
249 * else returns the next offset to use in the function call.
251 static int ccid2_ackvector(struct sock *sk, struct sk_buff *skb, int offset,
252 unsigned char **vec, unsigned char *veclen)
254 const struct dccp_hdr *dh = dccp_hdr(skb);
255 unsigned char *options = (unsigned char *)dh + dccp_hdr_len(skb);
256 unsigned char *opt_ptr;
257 const unsigned char *opt_end = (unsigned char *)dh +
258 (dh->dccph_doff * 4);
259 unsigned char opt, len;
260 unsigned char *value;
262 BUG_ON(offset < 0);
263 options += offset;
264 opt_ptr = options;
265 if (opt_ptr >= opt_end)
266 return -1;
268 while (opt_ptr != opt_end) {
269 opt = *opt_ptr++;
270 len = 0;
271 value = NULL;
273 /* Check if this isn't a single byte option */
274 if (opt > DCCPO_MAX_RESERVED) {
275 if (opt_ptr == opt_end)
276 goto out_invalid_option;
278 len = *opt_ptr++;
279 if (len < 3)
280 goto out_invalid_option;
282 * Remove the type and len fields, leaving
283 * just the value size
285 len -= 2;
286 value = opt_ptr;
287 opt_ptr += len;
289 if (opt_ptr > opt_end)
290 goto out_invalid_option;
293 switch (opt) {
294 case DCCPO_ACK_VECTOR_0:
295 case DCCPO_ACK_VECTOR_1:
296 *vec = value;
297 *veclen = len;
298 return offset + (opt_ptr - options);
302 return -1;
304 out_invalid_option:
305 DCCP_BUG("Invalid option - this should not happen (previous parsing)!");
306 return -1;
310 * ccid2_rtt_estimator - Sample RTT and compute RTO using RFC2988 algorithm
311 * This code is almost identical with TCP's tcp_rtt_estimator(), since
312 * - it has a higher sampling frequency (recommended by RFC 1323),
313 * - the RTO does not collapse into RTT due to RTTVAR going towards zero,
314 * - it is simple (cf. more complex proposals such as Eifel timer or research
315 * which suggests that the gain should be set according to window size),
316 * - in tests it was found to work well with CCID2 [gerrit].
318 static void ccid2_rtt_estimator(struct sock *sk, const long mrtt)
320 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
321 long m = mrtt ? : 1;
323 if (hc->tx_srtt == 0) {
324 /* First measurement m */
325 hc->tx_srtt = m << 3;
326 hc->tx_mdev = m << 1;
328 hc->tx_mdev_max = max(hc->tx_mdev, tcp_rto_min(sk));
329 hc->tx_rttvar = hc->tx_mdev_max;
331 hc->tx_rtt_seq = dccp_sk(sk)->dccps_gss;
332 } else {
333 /* Update scaled SRTT as SRTT += 1/8 * (m - SRTT) */
334 m -= (hc->tx_srtt >> 3);
335 hc->tx_srtt += m;
337 /* Similarly, update scaled mdev with regard to |m| */
338 if (m < 0) {
339 m = -m;
340 m -= (hc->tx_mdev >> 2);
342 * This neutralises RTO increase when RTT < SRTT - mdev
343 * (see P. Sarolahti, A. Kuznetsov,"Congestion Control
344 * in Linux TCP", USENIX 2002, pp. 49-62).
346 if (m > 0)
347 m >>= 3;
348 } else {
349 m -= (hc->tx_mdev >> 2);
351 hc->tx_mdev += m;
353 if (hc->tx_mdev > hc->tx_mdev_max) {
354 hc->tx_mdev_max = hc->tx_mdev;
355 if (hc->tx_mdev_max > hc->tx_rttvar)
356 hc->tx_rttvar = hc->tx_mdev_max;
360 * Decay RTTVAR at most once per flight, exploiting that
361 * 1) pipe <= cwnd <= Sequence_Window = W (RFC 4340, 7.5.2)
362 * 2) AWL = GSS-W+1 <= GAR <= GSS (RFC 4340, 7.5.1)
363 * GAR is a useful bound for FlightSize = pipe.
364 * AWL is probably too low here, as it over-estimates pipe.
366 if (after48(dccp_sk(sk)->dccps_gar, hc->tx_rtt_seq)) {
367 if (hc->tx_mdev_max < hc->tx_rttvar)
368 hc->tx_rttvar -= (hc->tx_rttvar -
369 hc->tx_mdev_max) >> 2;
370 hc->tx_rtt_seq = dccp_sk(sk)->dccps_gss;
371 hc->tx_mdev_max = tcp_rto_min(sk);
376 * Set RTO from SRTT and RTTVAR
377 * As in TCP, 4 * RTTVAR >= TCP_RTO_MIN, giving a minimum RTO of 200 ms.
378 * This agrees with RFC 4341, 5:
379 * "Because DCCP does not retransmit data, DCCP does not require
380 * TCP's recommended minimum timeout of one second".
382 hc->tx_rto = (hc->tx_srtt >> 3) + hc->tx_rttvar;
384 if (hc->tx_rto > DCCP_RTO_MAX)
385 hc->tx_rto = DCCP_RTO_MAX;
388 static void ccid2_new_ack(struct sock *sk, struct ccid2_seq *seqp,
389 unsigned int *maxincr)
391 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
393 if (hc->tx_cwnd < hc->tx_ssthresh) {
394 if (*maxincr > 0 && ++hc->tx_packets_acked == 2) {
395 hc->tx_cwnd += 1;
396 *maxincr -= 1;
397 hc->tx_packets_acked = 0;
399 } else if (++hc->tx_packets_acked >= hc->tx_cwnd) {
400 hc->tx_cwnd += 1;
401 hc->tx_packets_acked = 0;
404 * FIXME: RTT is sampled several times per acknowledgment (for each
405 * entry in the Ack Vector), instead of once per Ack (as in TCP SACK).
406 * This causes the RTT to be over-estimated, since the older entries
407 * in the Ack Vector have earlier sending times.
408 * The cleanest solution is to not use the ccid2s_sent field at all
409 * and instead use DCCP timestamps: requires changes in other places.
411 ccid2_rtt_estimator(sk, ccid2_time_stamp - seqp->ccid2s_sent);
414 static void ccid2_congestion_event(struct sock *sk, struct ccid2_seq *seqp)
416 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
418 if ((s32)(seqp->ccid2s_sent - hc->tx_last_cong) < 0) {
419 ccid2_pr_debug("Multiple losses in an RTT---treating as one\n");
420 return;
423 hc->tx_last_cong = ccid2_time_stamp;
425 hc->tx_cwnd = hc->tx_cwnd / 2 ? : 1U;
426 hc->tx_ssthresh = max(hc->tx_cwnd, 2U);
428 /* Avoid spurious timeouts resulting from Ack Ratio > cwnd */
429 if (dccp_sk(sk)->dccps_l_ack_ratio > hc->tx_cwnd)
430 ccid2_change_l_ack_ratio(sk, hc->tx_cwnd);
433 static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
435 struct dccp_sock *dp = dccp_sk(sk);
436 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
437 u64 ackno, seqno;
438 struct ccid2_seq *seqp;
439 unsigned char *vector;
440 unsigned char veclen;
441 int offset = 0;
442 int done = 0;
443 unsigned int maxincr = 0;
445 /* check reverse path congestion */
446 seqno = DCCP_SKB_CB(skb)->dccpd_seq;
448 /* XXX this whole "algorithm" is broken. Need to fix it to keep track
449 * of the seqnos of the dupacks so that rpseq and rpdupack are correct
450 * -sorbo.
452 /* need to bootstrap */
453 if (hc->tx_rpdupack == -1) {
454 hc->tx_rpdupack = 0;
455 hc->tx_rpseq = seqno;
456 } else {
457 /* check if packet is consecutive */
458 if (dccp_delta_seqno(hc->tx_rpseq, seqno) == 1)
459 hc->tx_rpseq = seqno;
460 /* it's a later packet */
461 else if (after48(seqno, hc->tx_rpseq)) {
462 hc->tx_rpdupack++;
464 /* check if we got enough dupacks */
465 if (hc->tx_rpdupack >= NUMDUPACK) {
466 hc->tx_rpdupack = -1; /* XXX lame */
467 hc->tx_rpseq = 0;
469 ccid2_change_l_ack_ratio(sk, 2 * dp->dccps_l_ack_ratio);
474 /* check forward path congestion */
475 /* still didn't send out new data packets */
476 if (hc->tx_seqh == hc->tx_seqt)
477 return;
479 switch (DCCP_SKB_CB(skb)->dccpd_type) {
480 case DCCP_PKT_ACK:
481 case DCCP_PKT_DATAACK:
482 break;
483 default:
484 return;
487 ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq;
488 if (after48(ackno, hc->tx_high_ack))
489 hc->tx_high_ack = ackno;
491 seqp = hc->tx_seqt;
492 while (before48(seqp->ccid2s_seq, ackno)) {
493 seqp = seqp->ccid2s_next;
494 if (seqp == hc->tx_seqh) {
495 seqp = hc->tx_seqh->ccid2s_prev;
496 break;
501 * In slow-start, cwnd can increase up to a maximum of Ack Ratio/2
502 * packets per acknowledgement. Rounding up avoids that cwnd is not
503 * advanced when Ack Ratio is 1 and gives a slight edge otherwise.
505 if (hc->tx_cwnd < hc->tx_ssthresh)
506 maxincr = DIV_ROUND_UP(dp->dccps_l_ack_ratio, 2);
508 /* go through all ack vectors */
509 while ((offset = ccid2_ackvector(sk, skb, offset,
510 &vector, &veclen)) != -1) {
511 /* go through this ack vector */
512 while (veclen--) {
513 const u8 rl = *vector & DCCP_ACKVEC_LEN_MASK;
514 u64 ackno_end_rl = SUB48(ackno, rl);
516 ccid2_pr_debug("ackvec start:%llu end:%llu\n",
517 (unsigned long long)ackno,
518 (unsigned long long)ackno_end_rl);
519 /* if the seqno we are analyzing is larger than the
520 * current ackno, then move towards the tail of our
521 * seqnos.
523 while (after48(seqp->ccid2s_seq, ackno)) {
524 if (seqp == hc->tx_seqt) {
525 done = 1;
526 break;
528 seqp = seqp->ccid2s_prev;
530 if (done)
531 break;
533 /* check all seqnos in the range of the vector
534 * run length
536 while (between48(seqp->ccid2s_seq,ackno_end_rl,ackno)) {
537 const u8 state = *vector &
538 DCCP_ACKVEC_STATE_MASK;
540 /* new packet received or marked */
541 if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED &&
542 !seqp->ccid2s_acked) {
543 if (state ==
544 DCCP_ACKVEC_STATE_ECN_MARKED) {
545 ccid2_congestion_event(sk,
546 seqp);
547 } else
548 ccid2_new_ack(sk, seqp,
549 &maxincr);
551 seqp->ccid2s_acked = 1;
552 ccid2_pr_debug("Got ack for %llu\n",
553 (unsigned long long)seqp->ccid2s_seq);
554 hc->tx_pipe--;
556 if (seqp == hc->tx_seqt) {
557 done = 1;
558 break;
560 seqp = seqp->ccid2s_prev;
562 if (done)
563 break;
565 ackno = SUB48(ackno_end_rl, 1);
566 vector++;
568 if (done)
569 break;
572 /* The state about what is acked should be correct now
573 * Check for NUMDUPACK
575 seqp = hc->tx_seqt;
576 while (before48(seqp->ccid2s_seq, hc->tx_high_ack)) {
577 seqp = seqp->ccid2s_next;
578 if (seqp == hc->tx_seqh) {
579 seqp = hc->tx_seqh->ccid2s_prev;
580 break;
583 done = 0;
584 while (1) {
585 if (seqp->ccid2s_acked) {
586 done++;
587 if (done == NUMDUPACK)
588 break;
590 if (seqp == hc->tx_seqt)
591 break;
592 seqp = seqp->ccid2s_prev;
595 /* If there are at least 3 acknowledgements, anything unacknowledged
596 * below the last sequence number is considered lost
598 if (done == NUMDUPACK) {
599 struct ccid2_seq *last_acked = seqp;
601 /* check for lost packets */
602 while (1) {
603 if (!seqp->ccid2s_acked) {
604 ccid2_pr_debug("Packet lost: %llu\n",
605 (unsigned long long)seqp->ccid2s_seq);
606 /* XXX need to traverse from tail -> head in
607 * order to detect multiple congestion events in
608 * one ack vector.
610 ccid2_congestion_event(sk, seqp);
611 hc->tx_pipe--;
613 if (seqp == hc->tx_seqt)
614 break;
615 seqp = seqp->ccid2s_prev;
618 hc->tx_seqt = last_acked;
621 /* trim acked packets in tail */
622 while (hc->tx_seqt != hc->tx_seqh) {
623 if (!hc->tx_seqt->ccid2s_acked)
624 break;
626 hc->tx_seqt = hc->tx_seqt->ccid2s_next;
629 /* restart RTO timer if not all outstanding data has been acked */
630 if (hc->tx_pipe == 0)
631 sk_stop_timer(sk, &hc->tx_rtotimer);
632 else
633 sk_reset_timer(sk, &hc->tx_rtotimer, jiffies + hc->tx_rto);
636 static int ccid2_hc_tx_init(struct ccid *ccid, struct sock *sk)
638 struct ccid2_hc_tx_sock *hc = ccid_priv(ccid);
639 struct dccp_sock *dp = dccp_sk(sk);
640 u32 max_ratio;
642 /* RFC 4341, 5: initialise ssthresh to arbitrarily high (max) value */
643 hc->tx_ssthresh = ~0U;
645 /* Use larger initial windows (RFC 4341, section 5). */
646 hc->tx_cwnd = rfc3390_bytes_to_packets(dp->dccps_mss_cache);
648 /* Make sure that Ack Ratio is enabled and within bounds. */
649 max_ratio = DIV_ROUND_UP(hc->tx_cwnd, 2);
650 if (dp->dccps_l_ack_ratio == 0 || dp->dccps_l_ack_ratio > max_ratio)
651 dp->dccps_l_ack_ratio = max_ratio;
653 /* XXX init ~ to window size... */
654 if (ccid2_hc_tx_alloc_seq(hc))
655 return -ENOMEM;
657 hc->tx_rto = DCCP_TIMEOUT_INIT;
658 hc->tx_rpdupack = -1;
659 hc->tx_last_cong = ccid2_time_stamp;
660 setup_timer(&hc->tx_rtotimer, ccid2_hc_tx_rto_expire,
661 (unsigned long)sk);
662 return 0;
665 static void ccid2_hc_tx_exit(struct sock *sk)
667 struct ccid2_hc_tx_sock *hc = ccid2_hc_tx_sk(sk);
668 int i;
670 sk_stop_timer(sk, &hc->tx_rtotimer);
672 for (i = 0; i < hc->tx_seqbufc; i++)
673 kfree(hc->tx_seqbuf[i]);
674 hc->tx_seqbufc = 0;
677 static void ccid2_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
679 const struct dccp_sock *dp = dccp_sk(sk);
680 struct ccid2_hc_rx_sock *hc = ccid2_hc_rx_sk(sk);
682 switch (DCCP_SKB_CB(skb)->dccpd_type) {
683 case DCCP_PKT_DATA:
684 case DCCP_PKT_DATAACK:
685 hc->rx_data++;
686 if (hc->rx_data >= dp->dccps_r_ack_ratio) {
687 dccp_send_ack(sk);
688 hc->rx_data = 0;
690 break;
694 struct ccid_operations ccid2_ops = {
695 .ccid_id = DCCPC_CCID2,
696 .ccid_name = "TCP-like",
697 .ccid_hc_tx_obj_size = sizeof(struct ccid2_hc_tx_sock),
698 .ccid_hc_tx_init = ccid2_hc_tx_init,
699 .ccid_hc_tx_exit = ccid2_hc_tx_exit,
700 .ccid_hc_tx_send_packet = ccid2_hc_tx_send_packet,
701 .ccid_hc_tx_packet_sent = ccid2_hc_tx_packet_sent,
702 .ccid_hc_tx_packet_recv = ccid2_hc_tx_packet_recv,
703 .ccid_hc_rx_obj_size = sizeof(struct ccid2_hc_rx_sock),
704 .ccid_hc_rx_packet_recv = ccid2_hc_rx_packet_recv,
707 #ifdef CONFIG_IP_DCCP_CCID2_DEBUG
708 module_param(ccid2_debug, bool, 0644);
709 MODULE_PARM_DESC(ccid2_debug, "Enable CCID-2 debug messages");
710 #endif