This source file includes following definitions.
- prepare_zip_command
- zip_deflate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 #include <linux/delay.h>
47 #include <linux/sched.h>
48
49 #include "common.h"
50 #include "zip_deflate.h"
51
52
53 static int prepare_zip_command(struct zip_operation *zip_ops,
54 struct zip_state *s, union zip_inst_s *zip_cmd)
55 {
56 union zip_zres_s *result_ptr = &s->result;
57
58 memset(zip_cmd, 0, sizeof(s->zip_cmd));
59 memset(result_ptr, 0, sizeof(s->result));
60
61
62
63 zip_cmd->s.hg = 0;
64
65 zip_cmd->s.ce = 1;
66
67 zip_cmd->s.sf = 1;
68
69 if (zip_ops->flush == ZIP_FLUSH_FINISH) {
70 zip_cmd->s.ef = 1;
71 zip_cmd->s.sf = 0;
72 }
73
74 zip_cmd->s.cc = zip_ops->ccode;
75
76 zip_cmd->s.ss = zip_ops->speed;
77
78
79
80 zip_cmd->s.adlercrc32 = zip_ops->csum;
81 zip_cmd->s.historylength = zip_ops->history_len;
82 zip_cmd->s.dg = 0;
83
84
85 zip_cmd->s.inp_ptr_addr.s.addr = __pa(zip_ops->input);
86 zip_cmd->s.inp_ptr_ctl.s.length = (zip_ops->input_len +
87 zip_ops->history_len);
88 zip_cmd->s.ds = 0;
89
90
91 zip_cmd->s.out_ptr_addr.s.addr = __pa(zip_ops->output);
92 zip_cmd->s.out_ptr_ctl.s.length = zip_ops->output_len;
93
94 zip_cmd->s.totaloutputlength = zip_ops->output_len;
95
96
97 zip_cmd->s.res_ptr_addr.s.addr = __pa(result_ptr);
98
99 result_ptr->s.compcode = 0;
100
101 return 0;
102 }
103
104
105
106
107
108
109
110
111
112
113
114
115 int zip_deflate(struct zip_operation *zip_ops, struct zip_state *s,
116 struct zip_device *zip_dev)
117 {
118 union zip_inst_s *zip_cmd = &s->zip_cmd;
119 union zip_zres_s *result_ptr = &s->result;
120 u32 queue;
121
122
123 prepare_zip_command(zip_ops, s, zip_cmd);
124
125 atomic64_add(zip_ops->input_len, &zip_dev->stats.comp_in_bytes);
126
127 queue = zip_load_instr(zip_cmd, zip_dev);
128
129
130 atomic64_inc(&zip_dev->stats.comp_req_submit);
131
132
133 zip_poll_result(result_ptr);
134
135
136 atomic64_inc(&zip_dev->stats.comp_req_complete);
137
138 zip_ops->compcode = result_ptr->s.compcode;
139 switch (zip_ops->compcode) {
140 case ZIP_CMD_NOTDONE:
141 zip_dbg("Zip instruction not yet completed");
142 return ZIP_ERROR;
143
144 case ZIP_CMD_SUCCESS:
145 zip_dbg("Zip instruction completed successfully");
146 zip_update_cmd_bufs(zip_dev, queue);
147 break;
148
149 case ZIP_CMD_DTRUNC:
150 zip_dbg("Output Truncate error");
151
152 return ZIP_ERROR;
153
154 default:
155 zip_err("Zip instruction failed. Code:%d", zip_ops->compcode);
156 return ZIP_ERROR;
157 }
158
159
160 switch (zip_ops->format) {
161 case RAW_FORMAT:
162 zip_dbg("RAW Format: %d ", zip_ops->format);
163
164 zip_ops->csum = result_ptr->s.adler32;
165 break;
166
167 case ZLIB_FORMAT:
168 zip_dbg("ZLIB Format: %d ", zip_ops->format);
169 zip_ops->csum = result_ptr->s.adler32;
170 break;
171
172 case GZIP_FORMAT:
173 zip_dbg("GZIP Format: %d ", zip_ops->format);
174 zip_ops->csum = result_ptr->s.crc32;
175 break;
176
177 case LZS_FORMAT:
178 zip_dbg("LZS Format: %d ", zip_ops->format);
179 break;
180
181 default:
182 zip_err("Unknown Format:%d\n", zip_ops->format);
183 }
184
185 atomic64_add(result_ptr->s.totalbyteswritten,
186 &zip_dev->stats.comp_out_bytes);
187
188
189 if (zip_ops->output_len < result_ptr->s.totalbyteswritten) {
190
191 zip_err("output_len (%d) < total bytes written(%d)\n",
192 zip_ops->output_len, result_ptr->s.totalbyteswritten);
193 zip_ops->output_len = 0;
194
195 } else {
196 zip_ops->output_len = result_ptr->s.totalbyteswritten;
197 }
198
199 return 0;
200 }