blob: 596cbea8df4c75a0bcf57f7659097a1adc5cade2 [file] [log] [blame]
Artem Bityutskiy72069be2008-12-08 13:36:18 +02001/*
2 * Copyright (C) 2007 Nokia Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; see the file COPYING. If not, write to the Free Software
15 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 *
17 * Test read and write speed of a MTD device.
18 *
Adrian Hunterfc7fe762011-02-08 12:02:39 +020019 * Author: Adrian Hunter <adrian.hunter@nokia.com>
Artem Bityutskiy72069be2008-12-08 13:36:18 +020020 */
21
Vikram Narayanan2c70d292012-10-10 23:10:02 +053022#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
Artem Bityutskiy72069be2008-12-08 13:36:18 +020024#include <linux/init.h>
25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/err.h>
28#include <linux/mtd/mtd.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Artem Bityutskiy72069be2008-12-08 13:36:18 +020030#include <linux/sched.h>
Artem Bityutskiybfea1d42012-05-18 18:44:53 +030031#include <linux/random.h>
Artem Bityutskiy72069be2008-12-08 13:36:18 +020032
Wolfram Sang74060602011-10-30 00:11:53 +020033static int dev = -EINVAL;
Artem Bityutskiy72069be2008-12-08 13:36:18 +020034module_param(dev, int, S_IRUGO);
35MODULE_PARM_DESC(dev, "MTD device number to use");
36
Adrian Hunterfc7fe762011-02-08 12:02:39 +020037static int count;
38module_param(count, int, S_IRUGO);
39MODULE_PARM_DESC(count, "Maximum number of eraseblocks to use "
40 "(0 means use all)");
41
Artem Bityutskiy72069be2008-12-08 13:36:18 +020042static struct mtd_info *mtd;
43static unsigned char *iobuf;
44static unsigned char *bbt;
45
46static int pgsize;
47static int ebcnt;
48static int pgcnt;
49static int goodebcnt;
50static struct timeval start, finish;
Artem Bityutskiy72069be2008-12-08 13:36:18 +020051
52static void set_random_data(unsigned char *buf, size_t len)
53{
54 size_t i;
55
56 for (i = 0; i < len; ++i)
Artem Bityutskiybfea1d42012-05-18 18:44:53 +030057 buf[i] = random32();
Artem Bityutskiy72069be2008-12-08 13:36:18 +020058}
59
60static int erase_eraseblock(int ebnum)
61{
62 int err;
63 struct erase_info ei;
64 loff_t addr = ebnum * mtd->erasesize;
65
66 memset(&ei, 0, sizeof(struct erase_info));
67 ei.mtd = mtd;
68 ei.addr = addr;
69 ei.len = mtd->erasesize;
70
Artem Bityutskiy7e1f0dc2011-12-23 15:25:39 +020071 err = mtd_erase(mtd, &ei);
Artem Bityutskiy72069be2008-12-08 13:36:18 +020072 if (err) {
Vikram Narayanan2c70d292012-10-10 23:10:02 +053073 pr_err("error %d while erasing EB %d\n", err, ebnum);
Artem Bityutskiy72069be2008-12-08 13:36:18 +020074 return err;
75 }
76
77 if (ei.state == MTD_ERASE_FAILED) {
Vikram Narayanan2c70d292012-10-10 23:10:02 +053078 pr_err("some erase error occurred at EB %d\n",
Artem Bityutskiy72069be2008-12-08 13:36:18 +020079 ebnum);
80 return -EIO;
81 }
82
83 return 0;
84}
85
Roman Tereshonkov4085bcc2011-02-08 12:02:40 +020086static int multiblock_erase(int ebnum, int blocks)
87{
88 int err;
89 struct erase_info ei;
90 loff_t addr = ebnum * mtd->erasesize;
91
92 memset(&ei, 0, sizeof(struct erase_info));
93 ei.mtd = mtd;
94 ei.addr = addr;
95 ei.len = mtd->erasesize * blocks;
96
Artem Bityutskiy7e1f0dc2011-12-23 15:25:39 +020097 err = mtd_erase(mtd, &ei);
Roman Tereshonkov4085bcc2011-02-08 12:02:40 +020098 if (err) {
Vikram Narayanan2c70d292012-10-10 23:10:02 +053099 pr_err("error %d while erasing EB %d, blocks %d\n",
Roman Tereshonkov4085bcc2011-02-08 12:02:40 +0200100 err, ebnum, blocks);
101 return err;
102 }
103
104 if (ei.state == MTD_ERASE_FAILED) {
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530105 pr_err("some erase error occurred at EB %d,"
Roman Tereshonkov4085bcc2011-02-08 12:02:40 +0200106 "blocks %d\n", ebnum, blocks);
107 return -EIO;
108 }
109
110 return 0;
111}
112
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200113static int erase_whole_device(void)
114{
115 int err;
116 unsigned int i;
117
118 for (i = 0; i < ebcnt; ++i) {
119 if (bbt[i])
120 continue;
121 err = erase_eraseblock(i);
122 if (err)
123 return err;
124 cond_resched();
125 }
126 return 0;
127}
128
129static int write_eraseblock(int ebnum)
130{
Artem Bityutskiy30fa9842011-12-29 15:16:28 +0200131 size_t written;
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200132 int err = 0;
133 loff_t addr = ebnum * mtd->erasesize;
134
Artem Bityutskiyeda95cb2011-12-23 17:35:41 +0200135 err = mtd_write(mtd, addr, mtd->erasesize, &written, iobuf);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200136 if (err || written != mtd->erasesize) {
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530137 pr_err("error: write failed at %#llx\n", addr);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200138 if (!err)
139 err = -EINVAL;
140 }
141
142 return err;
143}
144
145static int write_eraseblock_by_page(int ebnum)
146{
Artem Bityutskiy30fa9842011-12-29 15:16:28 +0200147 size_t written;
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200148 int i, err = 0;
149 loff_t addr = ebnum * mtd->erasesize;
150 void *buf = iobuf;
151
152 for (i = 0; i < pgcnt; i++) {
Artem Bityutskiyeda95cb2011-12-23 17:35:41 +0200153 err = mtd_write(mtd, addr, pgsize, &written, buf);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200154 if (err || written != pgsize) {
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530155 pr_err("error: write failed at %#llx\n",
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200156 addr);
157 if (!err)
158 err = -EINVAL;
159 break;
160 }
161 addr += pgsize;
162 buf += pgsize;
163 }
164
165 return err;
166}
167
168static int write_eraseblock_by_2pages(int ebnum)
169{
Artem Bityutskiy30fa9842011-12-29 15:16:28 +0200170 size_t written, sz = pgsize * 2;
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200171 int i, n = pgcnt / 2, err = 0;
172 loff_t addr = ebnum * mtd->erasesize;
173 void *buf = iobuf;
174
175 for (i = 0; i < n; i++) {
Artem Bityutskiyeda95cb2011-12-23 17:35:41 +0200176 err = mtd_write(mtd, addr, sz, &written, buf);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200177 if (err || written != sz) {
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530178 pr_err("error: write failed at %#llx\n",
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200179 addr);
180 if (!err)
181 err = -EINVAL;
182 return err;
183 }
184 addr += sz;
185 buf += sz;
186 }
187 if (pgcnt % 2) {
Artem Bityutskiyeda95cb2011-12-23 17:35:41 +0200188 err = mtd_write(mtd, addr, pgsize, &written, buf);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200189 if (err || written != pgsize) {
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530190 pr_err("error: write failed at %#llx\n",
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200191 addr);
192 if (!err)
193 err = -EINVAL;
194 }
195 }
196
197 return err;
198}
199
200static int read_eraseblock(int ebnum)
201{
Artem Bityutskiy30fa9842011-12-29 15:16:28 +0200202 size_t read;
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200203 int err = 0;
204 loff_t addr = ebnum * mtd->erasesize;
205
Artem Bityutskiy329ad392011-12-23 17:30:16 +0200206 err = mtd_read(mtd, addr, mtd->erasesize, &read, iobuf);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200207 /* Ignore corrected ECC errors */
Brian Norrisd57f40542011-09-20 18:34:25 -0700208 if (mtd_is_bitflip(err))
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200209 err = 0;
210 if (err || read != mtd->erasesize) {
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530211 pr_err("error: read failed at %#llx\n", addr);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200212 if (!err)
213 err = -EINVAL;
214 }
215
216 return err;
217}
218
219static int read_eraseblock_by_page(int ebnum)
220{
Artem Bityutskiy30fa9842011-12-29 15:16:28 +0200221 size_t read;
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200222 int i, err = 0;
223 loff_t addr = ebnum * mtd->erasesize;
224 void *buf = iobuf;
225
226 for (i = 0; i < pgcnt; i++) {
Artem Bityutskiy329ad392011-12-23 17:30:16 +0200227 err = mtd_read(mtd, addr, pgsize, &read, buf);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200228 /* Ignore corrected ECC errors */
Brian Norrisd57f40542011-09-20 18:34:25 -0700229 if (mtd_is_bitflip(err))
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200230 err = 0;
231 if (err || read != pgsize) {
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530232 pr_err("error: read failed at %#llx\n",
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200233 addr);
234 if (!err)
235 err = -EINVAL;
236 break;
237 }
238 addr += pgsize;
239 buf += pgsize;
240 }
241
242 return err;
243}
244
245static int read_eraseblock_by_2pages(int ebnum)
246{
Artem Bityutskiy30fa9842011-12-29 15:16:28 +0200247 size_t read, sz = pgsize * 2;
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200248 int i, n = pgcnt / 2, err = 0;
249 loff_t addr = ebnum * mtd->erasesize;
250 void *buf = iobuf;
251
252 for (i = 0; i < n; i++) {
Artem Bityutskiy329ad392011-12-23 17:30:16 +0200253 err = mtd_read(mtd, addr, sz, &read, buf);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200254 /* Ignore corrected ECC errors */
Brian Norrisd57f40542011-09-20 18:34:25 -0700255 if (mtd_is_bitflip(err))
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200256 err = 0;
257 if (err || read != sz) {
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530258 pr_err("error: read failed at %#llx\n",
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200259 addr);
260 if (!err)
261 err = -EINVAL;
262 return err;
263 }
264 addr += sz;
265 buf += sz;
266 }
267 if (pgcnt % 2) {
Artem Bityutskiy329ad392011-12-23 17:30:16 +0200268 err = mtd_read(mtd, addr, pgsize, &read, buf);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200269 /* Ignore corrected ECC errors */
Brian Norrisd57f40542011-09-20 18:34:25 -0700270 if (mtd_is_bitflip(err))
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200271 err = 0;
272 if (err || read != pgsize) {
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530273 pr_err("error: read failed at %#llx\n",
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200274 addr);
275 if (!err)
276 err = -EINVAL;
277 }
278 }
279
280 return err;
281}
282
283static int is_block_bad(int ebnum)
284{
285 loff_t addr = ebnum * mtd->erasesize;
286 int ret;
287
Artem Bityutskiy7086c192011-12-23 19:35:30 +0200288 ret = mtd_block_isbad(mtd, addr);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200289 if (ret)
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530290 pr_info("block %d is bad\n", ebnum);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200291 return ret;
292}
293
294static inline void start_timing(void)
295{
296 do_gettimeofday(&start);
297}
298
299static inline void stop_timing(void)
300{
301 do_gettimeofday(&finish);
302}
303
304static long calc_speed(void)
305{
David Lamberte70727e2011-03-07 12:00:46 +0200306 uint64_t k;
307 long ms;
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200308
309 ms = (finish.tv_sec - start.tv_sec) * 1000 +
310 (finish.tv_usec - start.tv_usec) / 1000;
David Lamberte70727e2011-03-07 12:00:46 +0200311 if (ms == 0)
312 return 0;
313 k = goodebcnt * (mtd->erasesize / 1024) * 1000;
314 do_div(k, ms);
315 return k;
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200316}
317
318static int scan_for_bad_eraseblocks(void)
319{
320 int i, bad = 0;
321
Julia Lawall2bfefa42010-05-13 22:03:15 +0200322 bbt = kzalloc(ebcnt, GFP_KERNEL);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200323 if (!bbt) {
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530324 pr_err("error: cannot allocate memory\n");
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200325 return -ENOMEM;
326 }
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200327
Artem Bityutskiy8f461a72012-01-02 13:48:54 +0200328 if (!mtd_can_have_bb(mtd))
Morten Thunberg Svendsenf5e2bae2010-01-06 10:48:18 +0100329 goto out;
330
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530331 pr_info("scanning for bad eraseblocks\n");
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200332 for (i = 0; i < ebcnt; ++i) {
333 bbt[i] = is_block_bad(i) ? 1 : 0;
334 if (bbt[i])
335 bad += 1;
336 cond_resched();
337 }
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530338 pr_info("scanned %d eraseblocks, %d are bad\n", i, bad);
Morten Thunberg Svendsenf5e2bae2010-01-06 10:48:18 +0100339out:
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200340 goodebcnt = ebcnt - bad;
341 return 0;
342}
343
344static int __init mtd_speedtest_init(void)
345{
Roman Tereshonkov4085bcc2011-02-08 12:02:40 +0200346 int err, i, blocks, j, k;
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200347 long speed;
348 uint64_t tmp;
349
350 printk(KERN_INFO "\n");
351 printk(KERN_INFO "=================================================\n");
Wolfram Sang74060602011-10-30 00:11:53 +0200352
353 if (dev < 0) {
Masanari Iida064a7692012-11-09 23:20:58 +0900354 pr_info("Please specify a valid mtd-device via module parameter\n");
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530355 pr_crit("CAREFUL: This test wipes all data on the specified MTD device!\n");
Wolfram Sang74060602011-10-30 00:11:53 +0200356 return -EINVAL;
357 }
358
Adrian Hunterfc7fe762011-02-08 12:02:39 +0200359 if (count)
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530360 pr_info("MTD device: %d count: %d\n", dev, count);
Adrian Hunterfc7fe762011-02-08 12:02:39 +0200361 else
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530362 pr_info("MTD device: %d\n", dev);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200363
364 mtd = get_mtd_device(NULL, dev);
365 if (IS_ERR(mtd)) {
366 err = PTR_ERR(mtd);
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530367 pr_err("error: cannot get MTD device\n");
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200368 return err;
369 }
370
371 if (mtd->writesize == 1) {
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530372 pr_info("not NAND flash, assume page size is 512 "
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200373 "bytes.\n");
374 pgsize = 512;
375 } else
376 pgsize = mtd->writesize;
377
378 tmp = mtd->size;
379 do_div(tmp, mtd->erasesize);
380 ebcnt = tmp;
Morten Thunberg Svendsenf5e2bae2010-01-06 10:48:18 +0100381 pgcnt = mtd->erasesize / pgsize;
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200382
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530383 pr_info("MTD device size %llu, eraseblock size %u, "
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200384 "page size %u, count of eraseblocks %u, pages per "
385 "eraseblock %u, OOB size %u\n",
386 (unsigned long long)mtd->size, mtd->erasesize,
387 pgsize, ebcnt, pgcnt, mtd->oobsize);
388
Adrian Hunterfc7fe762011-02-08 12:02:39 +0200389 if (count > 0 && count < ebcnt)
390 ebcnt = count;
391
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200392 err = -ENOMEM;
393 iobuf = kmalloc(mtd->erasesize, GFP_KERNEL);
394 if (!iobuf) {
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530395 pr_err("error: cannot allocate memory\n");
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200396 goto out;
397 }
398
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200399 set_random_data(iobuf, mtd->erasesize);
400
401 err = scan_for_bad_eraseblocks();
402 if (err)
403 goto out;
404
405 err = erase_whole_device();
406 if (err)
407 goto out;
408
409 /* Write all eraseblocks, 1 eraseblock at a time */
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530410 pr_info("testing eraseblock write speed\n");
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200411 start_timing();
412 for (i = 0; i < ebcnt; ++i) {
413 if (bbt[i])
414 continue;
415 err = write_eraseblock(i);
416 if (err)
417 goto out;
418 cond_resched();
419 }
420 stop_timing();
421 speed = calc_speed();
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530422 pr_info("eraseblock write speed is %ld KiB/s\n", speed);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200423
424 /* Read all eraseblocks, 1 eraseblock at a time */
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530425 pr_info("testing eraseblock read speed\n");
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200426 start_timing();
427 for (i = 0; i < ebcnt; ++i) {
428 if (bbt[i])
429 continue;
430 err = read_eraseblock(i);
431 if (err)
432 goto out;
433 cond_resched();
434 }
435 stop_timing();
436 speed = calc_speed();
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530437 pr_info("eraseblock read speed is %ld KiB/s\n", speed);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200438
439 err = erase_whole_device();
440 if (err)
441 goto out;
442
443 /* Write all eraseblocks, 1 page at a time */
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530444 pr_info("testing page write speed\n");
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200445 start_timing();
446 for (i = 0; i < ebcnt; ++i) {
447 if (bbt[i])
448 continue;
449 err = write_eraseblock_by_page(i);
450 if (err)
451 goto out;
452 cond_resched();
453 }
454 stop_timing();
455 speed = calc_speed();
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530456 pr_info("page write speed is %ld KiB/s\n", speed);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200457
458 /* Read all eraseblocks, 1 page at a time */
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530459 pr_info("testing page read speed\n");
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200460 start_timing();
461 for (i = 0; i < ebcnt; ++i) {
462 if (bbt[i])
463 continue;
464 err = read_eraseblock_by_page(i);
465 if (err)
466 goto out;
467 cond_resched();
468 }
469 stop_timing();
470 speed = calc_speed();
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530471 pr_info("page read speed is %ld KiB/s\n", speed);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200472
473 err = erase_whole_device();
474 if (err)
475 goto out;
476
477 /* Write all eraseblocks, 2 pages at a time */
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530478 pr_info("testing 2 page write speed\n");
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200479 start_timing();
480 for (i = 0; i < ebcnt; ++i) {
481 if (bbt[i])
482 continue;
483 err = write_eraseblock_by_2pages(i);
484 if (err)
485 goto out;
486 cond_resched();
487 }
488 stop_timing();
489 speed = calc_speed();
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530490 pr_info("2 page write speed is %ld KiB/s\n", speed);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200491
492 /* Read all eraseblocks, 2 pages at a time */
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530493 pr_info("testing 2 page read speed\n");
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200494 start_timing();
495 for (i = 0; i < ebcnt; ++i) {
496 if (bbt[i])
497 continue;
498 err = read_eraseblock_by_2pages(i);
499 if (err)
500 goto out;
501 cond_resched();
502 }
503 stop_timing();
504 speed = calc_speed();
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530505 pr_info("2 page read speed is %ld KiB/s\n", speed);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200506
507 /* Erase all eraseblocks */
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530508 pr_info("Testing erase speed\n");
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200509 start_timing();
510 for (i = 0; i < ebcnt; ++i) {
511 if (bbt[i])
512 continue;
513 err = erase_eraseblock(i);
514 if (err)
515 goto out;
516 cond_resched();
517 }
518 stop_timing();
519 speed = calc_speed();
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530520 pr_info("erase speed is %ld KiB/s\n", speed);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200521
Roman Tereshonkov4085bcc2011-02-08 12:02:40 +0200522 /* Multi-block erase all eraseblocks */
523 for (k = 1; k < 7; k++) {
524 blocks = 1 << k;
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530525 pr_info("Testing %dx multi-block erase speed\n",
Roman Tereshonkov4085bcc2011-02-08 12:02:40 +0200526 blocks);
527 start_timing();
528 for (i = 0; i < ebcnt; ) {
529 for (j = 0; j < blocks && (i + j) < ebcnt; j++)
530 if (bbt[i + j])
531 break;
532 if (j < 1) {
533 i++;
534 continue;
535 }
536 err = multiblock_erase(i, j);
537 if (err)
538 goto out;
539 cond_resched();
540 i += j;
541 }
542 stop_timing();
543 speed = calc_speed();
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530544 pr_info("%dx multi-block erase speed is %ld KiB/s\n",
Roman Tereshonkov4085bcc2011-02-08 12:02:40 +0200545 blocks, speed);
546 }
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530547 pr_info("finished\n");
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200548out:
549 kfree(iobuf);
550 kfree(bbt);
551 put_mtd_device(mtd);
552 if (err)
Vikram Narayanan2c70d292012-10-10 23:10:02 +0530553 pr_info("error %d occurred\n", err);
Artem Bityutskiy72069be2008-12-08 13:36:18 +0200554 printk(KERN_INFO "=================================================\n");
555 return err;
556}
557module_init(mtd_speedtest_init);
558
559static void __exit mtd_speedtest_exit(void)
560{
561 return;
562}
563module_exit(mtd_speedtest_exit);
564
565MODULE_DESCRIPTION("Speed test module");
566MODULE_AUTHOR("Adrian Hunter");
567MODULE_LICENSE("GPL");