ia64/linux-2.6.18-xen.hg

view crypto/scatterwalk.c @ 854:950b9eb27661

usbback: fix urb interval value for interrupt urbs.

Signed-off-by: Noboru Iwamatsu <n_iwamatsu@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Apr 06 13:51:20 2009 +0100 (2009-04-06)
parents 831230e53067
children
line source
1 /*
2 * Cryptographic API.
3 *
4 * Cipher operations.
5 *
6 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
7 * 2002 Adam J. Richter <adam@yggdrasil.com>
8 * 2004 Jean-Luc Cooke <jlcooke@certainkey.com>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
14 *
15 */
16 #include <linux/kernel.h>
17 #include <linux/mm.h>
18 #include <linux/pagemap.h>
19 #include <linux/highmem.h>
20 #include <asm/scatterlist.h>
21 #include "internal.h"
22 #include "scatterwalk.h"
24 enum km_type crypto_km_types[] = {
25 KM_USER0,
26 KM_USER1,
27 KM_SOFTIRQ0,
28 KM_SOFTIRQ1,
29 };
31 static void memcpy_dir(void *buf, void *sgdata, size_t nbytes, int out)
32 {
33 if (out)
34 memcpy(sgdata, buf, nbytes);
35 else
36 memcpy(buf, sgdata, nbytes);
37 }
39 void scatterwalk_start(struct scatter_walk *walk, struct scatterlist *sg)
40 {
41 unsigned int rest_of_page;
43 walk->sg = sg;
45 walk->page = sg->page;
46 walk->len_this_segment = sg->length;
48 BUG_ON(!sg->length);
50 rest_of_page = PAGE_CACHE_SIZE - (sg->offset & (PAGE_CACHE_SIZE - 1));
51 walk->len_this_page = min(sg->length, rest_of_page);
52 walk->offset = sg->offset;
53 }
55 void scatterwalk_map(struct scatter_walk *walk, int out)
56 {
57 walk->data = crypto_kmap(walk->page, out) + walk->offset;
58 }
60 static inline void scatterwalk_unmap(struct scatter_walk *walk, int out)
61 {
62 /* walk->data may be pointing the first byte of the next page;
63 however, we know we transfered at least one byte. So,
64 walk->data - 1 will be a virtual address in the mapped page. */
65 crypto_kunmap(walk->data - 1, out);
66 }
68 static void scatterwalk_pagedone(struct scatter_walk *walk, int out,
69 unsigned int more)
70 {
71 if (out)
72 flush_dcache_page(walk->page);
74 if (more) {
75 walk->len_this_segment -= walk->len_this_page;
77 if (walk->len_this_segment) {
78 walk->page++;
79 walk->len_this_page = min(walk->len_this_segment,
80 (unsigned)PAGE_CACHE_SIZE);
81 walk->offset = 0;
82 }
83 else
84 scatterwalk_start(walk, sg_next(walk->sg));
85 }
86 }
88 void scatterwalk_done(struct scatter_walk *walk, int out, int more)
89 {
90 scatterwalk_unmap(walk, out);
91 if (walk->len_this_page == 0 || !more)
92 scatterwalk_pagedone(walk, out, more);
93 }
95 /*
96 * Do not call this unless the total length of all of the fragments
97 * has been verified as multiple of the block size.
98 */
99 int scatterwalk_copychunks(void *buf, struct scatter_walk *walk,
100 size_t nbytes, int out)
101 {
102 while (nbytes > walk->len_this_page) {
103 memcpy_dir(buf, walk->data, walk->len_this_page, out);
104 buf += walk->len_this_page;
105 nbytes -= walk->len_this_page;
107 scatterwalk_unmap(walk, out);
108 scatterwalk_pagedone(walk, out, 1);
109 scatterwalk_map(walk, out);
110 }
112 memcpy_dir(buf, walk->data, nbytes, out);
113 return nbytes;
114 }