asm.patch

Cleaned up asm checksumming patch (for reference) - assembles now, but not trusted or really necessary. - Robert Bradley, 04/16/2012 10:19 am

Download (3.9 kB)

 
b/arch/mips/include/asm/checksum.h
193 198
}
194 199

  
195 200
#define _HAVE_ARCH_IPV6_CSUM
201
static __inline__ __sum16 csum_ipv6_unaligned_magic(const struct in6_addr *saddr,
202
				          const struct in6_addr *daddr,
203
					  __u32 len, unsigned short proto,
204
					  __wsum sum);
205

  
196 206
static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
197 207
				          const struct in6_addr *daddr,
198 208
					  __u32 len, unsigned short proto,
199 209
					  __wsum sum)
200 210
{
211
	if ((((__u32) saddr) | ((__u32) daddr)) & 3) {
212
		/* Unaligned to word boundaries... */
213
		return csum_ipv6_unaligned_magic(saddr, daddr, len, proto, sum);
214
	}
201 215
	__asm__(
202 216
	"	.set	push		# csum_ipv6_magic\n"
203 217
	"	.set	noreorder	\n"
......
257 271
	return csum_fold(sum);
258 272
}
259 273

  
274
static __inline__ __sum16 csum_ipv6_unaligned_magic(const struct in6_addr *saddr,
275
				          const struct in6_addr *daddr,
276
					  __u32 len, unsigned short proto,
277
					  __wsum sum)
278
{
279
	__asm__(
280
	"	.set	push		# csum_ipv6_magic\n"
281
	"	.set	noreorder	\n"
282
	"	.set	noat		\n"
283
	"	addu	%0, %5		# proto (long in network byte order)\n"
284
	"	sltu	$1, %0, %5	\n"
285
	"	addu	%0, $1		\n"
286

  
287
	"	addu	%0, %6		# csum\n"
288
	"	sltu	$1, %0, %6	\n"
289
	"	andi	$12, %2, 3	# calc offset for saddr\n"
290
	"	sub	%2, %2, $12	# align pointer\n"
291
	"	sll	$12, $12, 0x08	# calc shift left amount\n"
292
	"	ori	$13, $0, 0x20	# calc shift right amount\n"
293
	"	subu	$13, $13, $12	\n"
294
	"	lw	%1, 0(%2)	# four words source address\n"
295
	"	lw	$14, 4(%2)	# and next word\n"
296
	"	sllv	%1, %1, $12	# shift word1 left\n"
297
	"	srlv	$14, $14, $13	# shift word2 right\n"
298
	"	or	%1, %1, $14	# or together\n"
299
	"	addu	%0, $1		\n"
300
	"	addu	%0, %1		\n"
301
	"	sltu	$1, %0, %1	\n"
302

  
303
	"	lw	%1, 4(%2)	\n"
304
	"	lw	$14, 8(%2)	\n"
305
	"	sllv	%1, %1, $12	\n"
306
	"	srlv	$14, $14, $13	\n"
307
	"	or	%1, %1, $14	\n"
308
	"	addu	%0, $1		\n"
309
	"	addu	%0, %1		\n"
310
	"	sltu	$1, %0, %1	\n"
311

  
312
	"	lw	%1, 8(%2)	\n"
313
	"	lw	$14, 12(%2)	\n"
314
	"	sllv	%1, %1, $12	\n"
315
	"	srlv	$14, $14, $13	\n"
316
	"	or	%1, %1, $14	\n"
317
	"	addu	%0, $1		\n"
318
	"	addu	%0, %1		\n"
319
	"	sltu	$1, %0, %1	\n"
320

  
321
	"	lw	%1, 12(%2)	\n"
322
	"	lw	$14, 16(%2)	\n"
323
	"	sllv	%1, %1, $12	\n"
324
	"	srlv	$14, $14, $13	\n"
325
	"	or	%1, %1, $14	\n"
326
	"	addu	%0, $1		\n"
327
	"	addu	%0, %1		\n"
328
	"	sltu	$1, %0, %1	\n"
329

  
330
	"	srl	$12, $12, 0x08	# Undo damage to saddr\n"
331
	"	addu	%2, %2, $12	\n"
332

  
333
	"	andi	$12, %3, 3	# calc offset for daddr\n"
334
	"	sub	%3, %3, $12	# align pointer\n"
335
	"	sll	$12, $12, 0x08	# calc shift left amount\n"
336
	"	ori	$13, $0, 0x20	# calc shift right amount\n"
337
	"	subu	$13, $13, $12	\n"
338
	"	lw	%1, 0(%3)	# four words source address\n"
339
	"	lw	$14, 4(%3)	# and next word\n"
340
	"	sllv	%1, %1, $12	# shift word1 left\n"
341
	"	srlv	$14, $14, $13	# shift word2 right\n"
342
	"	or	%1, %1, $14	# or together\n"
343
	"	addu	%0, $1		\n"
344
	"	addu	%0, %1		\n"
345
	"	sltu	$1, %0, %1	\n"
346

  
347
	"	lw	%1, 4(%3)	\n"
348
	"	lw	$14, 8(%3)	\n"
349
	"	sllv	%1, %1, $12	\n"
350
	"	srlv	$14, $14, $13	\n"
351
	"	or	%1, %1, $14	\n"
352
	"	addu	%0, $1		\n"
353
	"	addu	%0, %1		\n"
354
	"	sltu	$1, %0, %1	\n"
355

  
356
	"	lw	%1, 8(%3)	\n"
357
	"	lw	$14, 12(%3)	\n"
358
	"	sllv	%1, %1, $12	\n"
359
	"	srlv	$14, $14, $13	\n"
360
	"	or	%1, %1, $14	\n"
361
	"	addu	%0, $1		\n"
362
	"	addu	%0, %1		\n"
363
	"	sltu	$1, %0, %1	\n"
364

  
365
	"	lw	%1, 12(%3)	\n"
366
	"	lw	$14, 16(%3)	\n"
367
	"	sllv	%1, %1, $12	\n"
368
	"	srlv	$14, $14, $13	\n"
369
	"	or	%1, %1, $14	\n"
370
	"	addu	%0, $1		\n"
371
	"	addu	%0, %1		\n"
372
	"	sltu	$1, %0, %1	\n"
373

  
374
	"	srl	$12, $12, 0x08	# Undo damage to daddr\n"
375
	"	addu	%3, %3, $12	\n"
376

  
377
	"	addu	%0, $1		# Add final carry\n"
378
	"	.set	pop"
379
	: "=r" (sum), "=r" (proto)
380
	: "r" (saddr), "r" (daddr),
381
	"" (htonl(len)), "1" (htonl(proto)), "r" (sum)
382
	: "$12", "$13", "$14");
383

  
384
	return csum_fold(sum);
385
}
386

  
260 387
#endif /* _ASM_CHECKSUM_H */