[PATCH] nvidiafb: fix unreachable code in nv10GetConfig
[pv_ops_mirror.git] / include / asm-avr32 / checksum.h
blob41b7af09edc437fd30c11cc081562750012e8e4f
1 /*
2 * Copyright (C) 2004-2006 Atmel Corporation
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8 #ifndef __ASM_AVR32_CHECKSUM_H
9 #define __ASM_AVR32_CHECKSUM_H
12 * computes the checksum of a memory block at buff, length len,
13 * and adds in "sum" (32-bit)
15 * returns a 32-bit number suitable for feeding into itself
16 * or csum_tcpudp_magic
18 * this function must be called with even lengths, except
19 * for the last fragment, which may be odd
21 * it's best to have buff aligned on a 32-bit boundary
23 unsigned int csum_partial(const unsigned char * buff, int len,
24 unsigned int sum);
27 * the same as csum_partial, but copies from src while it
28 * checksums, and handles user-space pointer exceptions correctly, when needed.
30 * here even more important to align src and dst on a 32-bit (or even
31 * better 64-bit) boundary
33 unsigned int csum_partial_copy_generic(const char *src, char *dst, int len,
34 int sum, int *src_err_ptr,
35 int *dst_err_ptr);
38 * Note: when you get a NULL pointer exception here this means someone
39 * passed in an incorrect kernel address to one of these functions.
41 * If you use these functions directly please don't forget the
42 * verify_area().
44 static inline
45 unsigned int csum_partial_copy_nocheck(const char *src, char *dst,
46 int len, int sum)
48 return csum_partial_copy_generic(src, dst, len, sum, NULL, NULL);
51 static inline
52 unsigned int csum_partial_copy_from_user (const char __user *src, char *dst,
53 int len, int sum, int *err_ptr)
55 return csum_partial_copy_generic((const char __force *)src, dst, len,
56 sum, err_ptr, NULL);
60 * This is a version of ip_compute_csum() optimized for IP headers,
61 * which always checksum on 4 octet boundaries.
63 static inline unsigned short ip_fast_csum(unsigned char *iph,
64 unsigned int ihl)
66 unsigned int sum, tmp;
68 __asm__ __volatile__(
69 " ld.w %0, %1++\n"
70 " ld.w %3, %1++\n"
71 " sub %2, 4\n"
72 " add %0, %3\n"
73 " ld.w %3, %1++\n"
74 " adc %0, %0, %3\n"
75 " ld.w %3, %1++\n"
76 " adc %0, %0, %3\n"
77 " acr %0\n"
78 "1: ld.w %3, %1++\n"
79 " add %0, %3\n"
80 " acr %0\n"
81 " sub %2, 1\n"
82 " brne 1b\n"
83 " lsl %3, %0, 16\n"
84 " andl %0, 0\n"
85 " mov %2, 0xffff\n"
86 " add %0, %3\n"
87 " adc %0, %0, %2\n"
88 " com %0\n"
89 " lsr %0, 16\n"
90 : "=r"(sum), "=r"(iph), "=r"(ihl), "=r"(tmp)
91 : "1"(iph), "2"(ihl)
92 : "memory", "cc");
93 return sum;
97 * Fold a partial checksum
100 static inline unsigned int csum_fold(unsigned int sum)
102 unsigned int tmp;
104 asm(" bfextu %1, %0, 0, 16\n"
105 " lsr %0, 16\n"
106 " add %0, %1\n"
107 " bfextu %1, %0, 16, 16\n"
108 " add %0, %1"
109 : "=&r"(sum), "=&r"(tmp)
110 : "0"(sum));
112 return ~sum;
115 static inline unsigned long csum_tcpudp_nofold(unsigned long saddr,
116 unsigned long daddr,
117 unsigned short len,
118 unsigned short proto,
119 unsigned int sum)
121 asm(" add %0, %1\n"
122 " adc %0, %0, %2\n"
123 " adc %0, %0, %3\n"
124 " acr %0"
125 : "=r"(sum)
126 : "r"(daddr), "r"(saddr), "r"(ntohs(len) | (proto << 16)),
127 "0"(sum)
128 : "cc");
130 return sum;
134 * computes the checksum of the TCP/UDP pseudo-header
135 * returns a 16-bit checksum, already complemented
137 static inline unsigned short int csum_tcpudp_magic(unsigned long saddr,
138 unsigned long daddr,
139 unsigned short len,
140 unsigned short proto,
141 unsigned int sum)
143 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum));
147 * this routine is used for miscellaneous IP-like checksums, mainly
148 * in icmp.c
151 static inline unsigned short ip_compute_csum(unsigned char * buff, int len)
153 return csum_fold(csum_partial(buff, len, 0));
156 #endif /* __ASM_AVR32_CHECKSUM_H */