Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2007 Nokia Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Test read and write speed of a MTD device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author: Adrian Hunter <adrian.hunter@nokia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/ktime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/mtd/mtd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "mtd_test.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static int dev = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) module_param(dev, int, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) MODULE_PARM_DESC(dev, "MTD device number to use");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) module_param(count, int, S_IRUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) MODULE_PARM_DESC(count, "Maximum number of eraseblocks to use "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 			"(0 means use all)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static struct mtd_info *mtd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static unsigned char *iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static unsigned char *bbt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static int pgsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) static int ebcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int pgcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) static int goodebcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static ktime_t start, finish;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static int multiblock_erase(int ebnum, int blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct erase_info ei;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	loff_t addr = (loff_t)ebnum * mtd->erasesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	memset(&ei, 0, sizeof(struct erase_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	ei.addr = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	ei.len  = mtd->erasesize * blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	err = mtd_erase(mtd, &ei);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		pr_err("error %d while erasing EB %d, blocks %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		       err, ebnum, blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static int write_eraseblock(int ebnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	loff_t addr = (loff_t)ebnum * mtd->erasesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	return mtdtest_write(mtd, addr, mtd->erasesize, iobuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static int write_eraseblock_by_page(int ebnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int i, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	loff_t addr = (loff_t)ebnum * mtd->erasesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	void *buf = iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	for (i = 0; i < pgcnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		err = mtdtest_write(mtd, addr, pgsize, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		addr += pgsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		buf += pgsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static int write_eraseblock_by_2pages(int ebnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	size_t sz = pgsize * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	int i, n = pgcnt / 2, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	loff_t addr = (loff_t)ebnum * mtd->erasesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	void *buf = iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	for (i = 0; i < n; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		err = mtdtest_write(mtd, addr, sz, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		addr += sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		buf += sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	if (pgcnt % 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		err = mtdtest_write(mtd, addr, pgsize, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int read_eraseblock(int ebnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	loff_t addr = (loff_t)ebnum * mtd->erasesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return mtdtest_read(mtd, addr, mtd->erasesize, iobuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int read_eraseblock_by_page(int ebnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	int i, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	loff_t addr = (loff_t)ebnum * mtd->erasesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	void *buf = iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	for (i = 0; i < pgcnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		err = mtdtest_read(mtd, addr, pgsize, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		addr += pgsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		buf += pgsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static int read_eraseblock_by_2pages(int ebnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	size_t sz = pgsize * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	int i, n = pgcnt / 2, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	loff_t addr = (loff_t)ebnum * mtd->erasesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	void *buf = iobuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	for (i = 0; i < n; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		err = mtdtest_read(mtd, addr, sz, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		addr += sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		buf += sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (pgcnt % 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		err = mtdtest_read(mtd, addr, pgsize, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static inline void start_timing(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	start = ktime_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static inline void stop_timing(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	finish = ktime_get();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static long calc_speed(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	uint64_t k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	long ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	ms = ktime_ms_delta(finish, start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	if (ms == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	k = (uint64_t)goodebcnt * (mtd->erasesize / 1024) * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	do_div(k, ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	return k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static int __init mtd_speedtest_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	int err, i, blocks, j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	long speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	uint64_t tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	printk(KERN_INFO "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	printk(KERN_INFO "=================================================\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (dev < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		pr_info("Please specify a valid mtd-device via module parameter\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		pr_crit("CAREFUL: This test wipes all data on the specified MTD device!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		pr_info("MTD device: %d    count: %d\n", dev, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		pr_info("MTD device: %d\n", dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	mtd = get_mtd_device(NULL, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (IS_ERR(mtd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		err = PTR_ERR(mtd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		pr_err("error: cannot get MTD device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (mtd->writesize == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		pr_info("not NAND flash, assume page size is 512 "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		       "bytes.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		pgsize = 512;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		pgsize = mtd->writesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	tmp = mtd->size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	do_div(tmp, mtd->erasesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	ebcnt = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	pgcnt = mtd->erasesize / pgsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	pr_info("MTD device size %llu, eraseblock size %u, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	       "page size %u, count of eraseblocks %u, pages per "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	       "eraseblock %u, OOB size %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	       (unsigned long long)mtd->size, mtd->erasesize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	       pgsize, ebcnt, pgcnt, mtd->oobsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (count > 0 && count < ebcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		ebcnt = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	iobuf = kmalloc(mtd->erasesize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	if (!iobuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	prandom_bytes(iobuf, mtd->erasesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	bbt = kzalloc(ebcnt, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (!bbt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	err = mtdtest_scan_for_bad_eraseblocks(mtd, bbt, 0, ebcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	for (i = 0; i < ebcnt; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		if (!bbt[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			goodebcnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	/* Write all eraseblocks, 1 eraseblock at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	pr_info("testing eraseblock write speed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	start_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	for (i = 0; i < ebcnt; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		if (bbt[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		err = write_eraseblock(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		err = mtdtest_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	stop_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	speed = calc_speed();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	pr_info("eraseblock write speed is %ld KiB/s\n", speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	/* Read all eraseblocks, 1 eraseblock at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	pr_info("testing eraseblock read speed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	start_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	for (i = 0; i < ebcnt; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		if (bbt[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		err = read_eraseblock(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		err = mtdtest_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	stop_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	speed = calc_speed();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	pr_info("eraseblock read speed is %ld KiB/s\n", speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	/* Write all eraseblocks, 1 page at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	pr_info("testing page write speed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	start_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	for (i = 0; i < ebcnt; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		if (bbt[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		err = write_eraseblock_by_page(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		err = mtdtest_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	stop_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	speed = calc_speed();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	pr_info("page write speed is %ld KiB/s\n", speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	/* Read all eraseblocks, 1 page at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	pr_info("testing page read speed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	start_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	for (i = 0; i < ebcnt; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		if (bbt[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		err = read_eraseblock_by_page(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		err = mtdtest_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	stop_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	speed = calc_speed();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	pr_info("page read speed is %ld KiB/s\n", speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	/* Write all eraseblocks, 2 pages at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	pr_info("testing 2 page write speed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	start_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	for (i = 0; i < ebcnt; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		if (bbt[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		err = write_eraseblock_by_2pages(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		err = mtdtest_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	stop_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	speed = calc_speed();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	pr_info("2 page write speed is %ld KiB/s\n", speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	/* Read all eraseblocks, 2 pages at a time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	pr_info("testing 2 page read speed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	start_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	for (i = 0; i < ebcnt; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		if (bbt[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		err = read_eraseblock_by_2pages(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		err = mtdtest_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	stop_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	speed = calc_speed();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	pr_info("2 page read speed is %ld KiB/s\n", speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	/* Erase all eraseblocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	pr_info("Testing erase speed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	start_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	err = mtdtest_erase_good_eraseblocks(mtd, bbt, 0, ebcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	stop_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	speed = calc_speed();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	pr_info("erase speed is %ld KiB/s\n", speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	/* Multi-block erase all eraseblocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	for (k = 1; k < 7; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		blocks = 1 << k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		pr_info("Testing %dx multi-block erase speed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		       blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		start_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		for (i = 0; i < ebcnt; ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 			for (j = 0; j < blocks && (i + j) < ebcnt; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 				if (bbt[i + j])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 			if (j < 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 				i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 			err = multiblock_erase(i, j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			err = mtdtest_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 			i += j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		stop_timing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		speed = calc_speed();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		pr_info("%dx multi-block erase speed is %ld KiB/s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		       blocks, speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	pr_info("finished\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	kfree(iobuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	kfree(bbt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	put_mtd_device(mtd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		pr_info("error %d occurred\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	printk(KERN_INFO "=================================================\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) module_init(mtd_speedtest_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static void __exit mtd_speedtest_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) module_exit(mtd_speedtest_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) MODULE_DESCRIPTION("Speed test module");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) MODULE_AUTHOR("Adrian Hunter");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) MODULE_LICENSE("GPL");