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
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2016 CNEX Labs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Initial release: Javier Gonzalez <javier@cnexlabs.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *                  Matias Bjorling <matias@cnexlabs.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * modify it under the terms of the GNU General Public License version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * 2 as published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * This program is distributed in the hope that it will be useful, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * Implementation of a physical block-device target for Open-channel SSDs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * pblk-sysfs.c - pblk's sysfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "pblk.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static ssize_t pblk_sysfs_luns_show(struct pblk *pblk, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct nvm_tgt_dev *dev = pblk->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	struct nvm_geo *geo = &dev->geo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	struct pblk_lun *rlun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	ssize_t sz = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	for (i = 0; i < geo->all_luns; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		int active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		rlun = &pblk->luns[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		if (!down_trylock(&rlun->wr_sem)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 			up(&rlun->wr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		sz += scnprintf(page + sz, PAGE_SIZE - sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 				"pblk: pos:%d, ch:%d, lun:%d - %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 					i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 					rlun->bppa.a.ch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 					rlun->bppa.a.lun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 					active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	return sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static ssize_t pblk_sysfs_rate_limiter(struct pblk *pblk, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	int free_blocks, free_user_blocks, total_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	int rb_user_max, rb_user_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	int rb_gc_max, rb_gc_cnt, rb_budget, rb_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	free_blocks = pblk_rl_nr_free_blks(&pblk->rl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	free_user_blocks = pblk_rl_nr_user_free_blks(&pblk->rl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	rb_user_max = pblk->rl.rb_user_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	rb_user_cnt = atomic_read(&pblk->rl.rb_user_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	rb_gc_max = pblk->rl.rb_gc_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	rb_gc_cnt = atomic_read(&pblk->rl.rb_gc_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	rb_budget = pblk->rl.rb_budget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	rb_state = pblk->rl.rb_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	total_blocks = pblk->rl.total_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	return snprintf(page, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		"u:%u/%u,gc:%u/%u(%u)(stop:<%u,full:>%u,free:%d/%d/%d)-%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 				rb_user_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 				rb_user_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 				rb_gc_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 				rb_gc_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 				rb_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 				rb_budget,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 				pblk->rl.high,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 				free_blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 				free_user_blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 				total_blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 				READ_ONCE(pblk->rl.rb_user_active));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static ssize_t pblk_sysfs_gc_state_show(struct pblk *pblk, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	int gc_enabled, gc_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	pblk_gc_sysfs_state_show(pblk, &gc_enabled, &gc_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return snprintf(page, PAGE_SIZE, "gc_enabled=%d, gc_active=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 					gc_enabled, gc_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) static ssize_t pblk_sysfs_stats(struct pblk *pblk, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	ssize_t sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	sz = snprintf(page, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			"read_failed=%lu, read_high_ecc=%lu, read_empty=%lu, read_failed_gc=%lu, write_failed=%lu, erase_failed=%lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			atomic_long_read(&pblk->read_failed),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			atomic_long_read(&pblk->read_high_ecc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			atomic_long_read(&pblk->read_empty),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			atomic_long_read(&pblk->read_failed_gc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			atomic_long_read(&pblk->write_failed),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			atomic_long_read(&pblk->erase_failed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	return sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static ssize_t pblk_sysfs_write_buffer(struct pblk *pblk, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	return pblk_rb_sysfs(&pblk->rwb, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static ssize_t pblk_sysfs_ppaf(struct pblk *pblk, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct nvm_tgt_dev *dev = pblk->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct nvm_geo *geo = &dev->geo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	ssize_t sz = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (geo->version == NVM_OCSSD_SPEC_12) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		struct nvm_addrf_12 *ppaf = (struct nvm_addrf_12 *)&pblk->addrf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		struct nvm_addrf_12 *gppaf = (struct nvm_addrf_12 *)&geo->addrf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		sz = scnprintf(page, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			"g:(b:%d)blk:%d/%d,pg:%d/%d,lun:%d/%d,ch:%d/%d,pl:%d/%d,sec:%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			pblk->addrf_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			ppaf->blk_offset, ppaf->blk_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			ppaf->pg_offset, ppaf->pg_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			ppaf->lun_offset, ppaf->lun_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			ppaf->ch_offset, ppaf->ch_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			ppaf->pln_offset, ppaf->pln_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			ppaf->sec_offset, ppaf->sec_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		sz += scnprintf(page + sz, PAGE_SIZE - sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			"d:blk:%d/%d,pg:%d/%d,lun:%d/%d,ch:%d/%d,pl:%d/%d,sec:%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 			gppaf->blk_offset, gppaf->blk_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			gppaf->pg_offset, gppaf->pg_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			gppaf->lun_offset, gppaf->lun_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			gppaf->ch_offset, gppaf->ch_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			gppaf->pln_offset, gppaf->pln_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			gppaf->sec_offset, gppaf->sec_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		struct nvm_addrf *ppaf = &pblk->addrf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		struct nvm_addrf *gppaf = &geo->addrf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		sz = scnprintf(page, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			"pblk:(s:%d)ch:%d/%d,lun:%d/%d,chk:%d/%d/sec:%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			pblk->addrf_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			ppaf->ch_offset, ppaf->ch_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			ppaf->lun_offset, ppaf->lun_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			ppaf->chk_offset, ppaf->chk_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			ppaf->sec_offset, ppaf->sec_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		sz += scnprintf(page + sz, PAGE_SIZE - sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			"device:ch:%d/%d,lun:%d/%d,chk:%d/%d,sec:%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			gppaf->ch_offset, gppaf->ch_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			gppaf->lun_offset, gppaf->lun_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			gppaf->chk_offset, gppaf->chk_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			gppaf->sec_offset, gppaf->sec_len);
^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) 	return sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static ssize_t pblk_sysfs_lines(struct pblk *pblk, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	struct nvm_tgt_dev *dev = pblk->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	struct nvm_geo *geo = &dev->geo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	struct pblk_line_meta *lm = &pblk->lm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct pblk_line_mgmt *l_mg = &pblk->l_mg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct pblk_line *line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	ssize_t sz = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	int nr_free_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	int cur_data, cur_log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	int free_line_cnt = 0, closed_line_cnt = 0, emeta_line_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	int d_line_cnt = 0, l_line_cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	int gc_full = 0, gc_high = 0, gc_mid = 0, gc_low = 0, gc_empty = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	int gc_werr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	int bad = 0, cor = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	int msecs = 0, cur_sec = 0, vsc = 0, sec_in_line = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	int map_weight = 0, meta_weight = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	spin_lock(&l_mg->free_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	cur_data = (l_mg->data_line) ? l_mg->data_line->id : -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	cur_log = (l_mg->log_line) ? l_mg->log_line->id : -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	nr_free_lines = l_mg->nr_free_lines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	list_for_each_entry(line, &l_mg->free_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		free_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	spin_unlock(&l_mg->free_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	spin_lock(&l_mg->close_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	list_for_each_entry(line, &l_mg->emeta_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		emeta_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	spin_unlock(&l_mg->close_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	spin_lock(&l_mg->gc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	list_for_each_entry(line, &l_mg->gc_full_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		if (line->type == PBLK_LINETYPE_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			d_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		else if (line->type == PBLK_LINETYPE_LOG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			l_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		closed_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		gc_full++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	list_for_each_entry(line, &l_mg->gc_high_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		if (line->type == PBLK_LINETYPE_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			d_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		else if (line->type == PBLK_LINETYPE_LOG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			l_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		closed_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		gc_high++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	list_for_each_entry(line, &l_mg->gc_mid_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		if (line->type == PBLK_LINETYPE_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			d_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		else if (line->type == PBLK_LINETYPE_LOG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 			l_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		closed_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		gc_mid++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	list_for_each_entry(line, &l_mg->gc_low_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		if (line->type == PBLK_LINETYPE_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			d_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		else if (line->type == PBLK_LINETYPE_LOG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			l_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		closed_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		gc_low++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	list_for_each_entry(line, &l_mg->gc_empty_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		if (line->type == PBLK_LINETYPE_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			d_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		else if (line->type == PBLK_LINETYPE_LOG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			l_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		closed_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		gc_empty++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	list_for_each_entry(line, &l_mg->gc_werr_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		if (line->type == PBLK_LINETYPE_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 			d_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		else if (line->type == PBLK_LINETYPE_LOG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			l_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		closed_line_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		gc_werr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	list_for_each_entry(line, &l_mg->bad_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		bad++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	list_for_each_entry(line, &l_mg->corrupt_list, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		cor++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	spin_unlock(&l_mg->gc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	spin_lock(&l_mg->free_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	if (l_mg->data_line) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		cur_sec = l_mg->data_line->cur_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		msecs = l_mg->data_line->left_msecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		vsc = le32_to_cpu(*l_mg->data_line->vsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		sec_in_line = l_mg->data_line->sec_in_line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		meta_weight = bitmap_weight(&l_mg->meta_bitmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 							PBLK_DATA_LINES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		spin_lock(&l_mg->data_line->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		if (l_mg->data_line->map_bitmap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			map_weight = bitmap_weight(l_mg->data_line->map_bitmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 							lm->sec_per_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			map_weight = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		spin_unlock(&l_mg->data_line->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	spin_unlock(&l_mg->free_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (nr_free_lines != free_line_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		pblk_err(pblk, "corrupted free line list:%d/%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 						nr_free_lines, free_line_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	sz = scnprintf(page, PAGE_SIZE - sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		"line: nluns:%d, nblks:%d, nsecs:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		geo->all_luns, lm->blk_per_line, lm->sec_per_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	sz += scnprintf(page + sz, PAGE_SIZE - sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		"lines:d:%d,l:%d-f:%d,m:%d/%d,c:%d,b:%d,co:%d(d:%d,l:%d)t:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 					cur_data, cur_log,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 					nr_free_lines,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 					emeta_line_cnt, meta_weight,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 					closed_line_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 					bad, cor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 					d_line_cnt, l_line_cnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 					l_mg->nr_lines);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	sz += scnprintf(page + sz, PAGE_SIZE - sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		"GC: full:%d, high:%d, mid:%d, low:%d, empty:%d, werr: %d, queue:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			gc_full, gc_high, gc_mid, gc_low, gc_empty, gc_werr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			atomic_read(&pblk->gc.read_inflight_gc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	sz += scnprintf(page + sz, PAGE_SIZE - sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		"data (%d) cur:%d, left:%d, vsc:%d, s:%d, map:%d/%d (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			cur_data, cur_sec, msecs, vsc, sec_in_line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 			map_weight, lm->sec_per_line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			atomic_read(&pblk->inflight_io));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	return sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static ssize_t pblk_sysfs_lines_info(struct pblk *pblk, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	struct nvm_tgt_dev *dev = pblk->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	struct nvm_geo *geo = &dev->geo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	struct pblk_line_meta *lm = &pblk->lm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	ssize_t sz = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	sz = scnprintf(page, PAGE_SIZE - sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 				"smeta - len:%d, secs:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 					lm->smeta_len, lm->smeta_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	sz += scnprintf(page + sz, PAGE_SIZE - sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 				"emeta - len:%d, sec:%d, bb_start:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 					lm->emeta_len[0], lm->emeta_sec[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 					lm->emeta_bb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	sz += scnprintf(page + sz, PAGE_SIZE - sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 				"bitmap lengths: sec:%d, blk:%d, lun:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 					lm->sec_bitmap_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 					lm->blk_bitmap_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 					lm->lun_bitmap_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	sz += scnprintf(page + sz, PAGE_SIZE - sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 				"blk_line:%d, sec_line:%d, sec_blk:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 					lm->blk_per_line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 					lm->sec_per_line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 					geo->clba);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	return sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) static ssize_t pblk_sysfs_get_sec_per_write(struct pblk *pblk, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	return snprintf(page, PAGE_SIZE, "%d\n", pblk->sec_per_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static ssize_t pblk_get_write_amp(u64 user, u64 gc, u64 pad,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 				  char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	int sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	sz = scnprintf(page, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			"user:%lld gc:%lld pad:%lld WA:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			user, gc, pad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	if (!user) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		sz += scnprintf(page + sz, PAGE_SIZE - sz, "NaN\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		u64 wa_int;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		u32 wa_frac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		wa_int = (user + gc + pad) * 100000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		wa_int = div64_u64(wa_int, user);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		wa_int = div_u64_rem(wa_int, 100000, &wa_frac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		sz += scnprintf(page + sz, PAGE_SIZE - sz, "%llu.%05u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 							wa_int, wa_frac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	return sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) static ssize_t pblk_sysfs_get_write_amp_mileage(struct pblk *pblk, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	return pblk_get_write_amp(atomic64_read(&pblk->user_wa),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		atomic64_read(&pblk->gc_wa), atomic64_read(&pblk->pad_wa),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) static ssize_t pblk_sysfs_get_write_amp_trip(struct pblk *pblk, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	return pblk_get_write_amp(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		atomic64_read(&pblk->user_wa) - pblk->user_rst_wa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		atomic64_read(&pblk->gc_wa) - pblk->gc_rst_wa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		atomic64_read(&pblk->pad_wa) - pblk->pad_rst_wa, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static long long bucket_percentage(unsigned long long bucket,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 				   unsigned long long total)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	int p = bucket * 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	p = div_u64(p, total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static ssize_t pblk_sysfs_get_padding_dist(struct pblk *pblk, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	int sz = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	unsigned long long total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	unsigned long long total_buckets = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	int buckets = pblk->min_write_pgs - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	total = atomic64_read(&pblk->nr_flush) - pblk->nr_flush_rst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	if (!total) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		for (i = 0; i < (buckets + 1); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			sz += scnprintf(page + sz, PAGE_SIZE - sz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 				"%d:0 ", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		sz += scnprintf(page + sz, PAGE_SIZE - sz, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		return sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	for (i = 0; i < buckets; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		total_buckets += atomic64_read(&pblk->pad_dist[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	sz += scnprintf(page + sz, PAGE_SIZE - sz, "0:%lld%% ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		bucket_percentage(total - total_buckets, total));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	for (i = 0; i < buckets; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		unsigned long long p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		p = bucket_percentage(atomic64_read(&pblk->pad_dist[i]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 					  total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		sz += scnprintf(page + sz, PAGE_SIZE - sz, "%d:%lld%% ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 				i + 1, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	sz += scnprintf(page + sz, PAGE_SIZE - sz, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	return sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) #ifdef CONFIG_NVM_PBLK_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static ssize_t pblk_sysfs_stats_debug(struct pblk *pblk, char *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	return snprintf(page, PAGE_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		"%lu\t%lu\t%ld\t%llu\t%ld\t%lu\t%lu\t%lu\t%lu\t%lu\t%lu\t%lu\t%lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 			atomic_long_read(&pblk->inflight_writes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			atomic_long_read(&pblk->inflight_reads),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			atomic_long_read(&pblk->req_writes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			(u64)atomic64_read(&pblk->nr_flush),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 			atomic_long_read(&pblk->padded_writes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 			atomic_long_read(&pblk->padded_wb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 			atomic_long_read(&pblk->sub_writes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 			atomic_long_read(&pblk->sync_writes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 			atomic_long_read(&pblk->recov_writes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 			atomic_long_read(&pblk->recov_gc_writes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 			atomic_long_read(&pblk->recov_gc_reads),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 			atomic_long_read(&pblk->cache_reads),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 			atomic_long_read(&pblk->sync_reads));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static ssize_t pblk_sysfs_gc_force(struct pblk *pblk, const char *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 				   size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	size_t c_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	int force;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	c_len = strcspn(page, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	if (c_len >= len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	if (kstrtouint(page, 0, &force))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	pblk_gc_sysfs_force(pblk, force);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static ssize_t pblk_sysfs_set_sec_per_write(struct pblk *pblk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 					     const char *page, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	size_t c_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	int sec_per_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	c_len = strcspn(page, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	if (c_len >= len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	if (kstrtouint(page, 0, &sec_per_write))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	if (!pblk_is_oob_meta_supported(pblk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		/* For packed metadata case it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		 * not allowed to change sec_per_write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	if (sec_per_write < pblk->min_write_pgs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 				|| sec_per_write > pblk->max_write_pgs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 				|| sec_per_write % pblk->min_write_pgs != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	pblk_set_sec_per_write(pblk, sec_per_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static ssize_t pblk_sysfs_set_write_amp_trip(struct pblk *pblk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			const char *page, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	size_t c_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	int reset_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	c_len = strcspn(page, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	if (c_len >= len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	if (kstrtouint(page, 0, &reset_value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	if (reset_value !=  0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	pblk->user_rst_wa = atomic64_read(&pblk->user_wa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	pblk->pad_rst_wa = atomic64_read(&pblk->pad_wa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	pblk->gc_rst_wa = atomic64_read(&pblk->gc_wa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) static ssize_t pblk_sysfs_set_padding_dist(struct pblk *pblk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 			const char *page, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	size_t c_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	int reset_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	int buckets = pblk->min_write_pgs - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	c_len = strcspn(page, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	if (c_len >= len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	if (kstrtouint(page, 0, &reset_value))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	if (reset_value !=  0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	for (i = 0; i < buckets; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 		atomic64_set(&pblk->pad_dist[i], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	pblk->nr_flush_rst = atomic64_read(&pblk->nr_flush);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) static struct attribute sys_write_luns = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	.name = "write_luns",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	.mode = 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) static struct attribute sys_rate_limiter_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	.name = "rate_limiter",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	.mode = 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) static struct attribute sys_gc_state = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	.name = "gc_state",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	.mode = 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) static struct attribute sys_errors_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	.name = "errors",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	.mode = 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) static struct attribute sys_rb_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	.name = "write_buffer",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	.mode = 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) static struct attribute sys_stats_ppaf_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	.name = "ppa_format",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	.mode = 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) static struct attribute sys_lines_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	.name = "lines",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 	.mode = 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) static struct attribute sys_lines_info_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	.name = "lines_info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	.mode = 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) static struct attribute sys_gc_force = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	.name = "gc_force",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	.mode = 0200,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) static struct attribute sys_max_sec_per_write = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	.name = "max_sec_per_write",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	.mode = 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) static struct attribute sys_write_amp_mileage = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	.name = "write_amp_mileage",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 	.mode = 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) static struct attribute sys_write_amp_trip = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	.name = "write_amp_trip",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	.mode = 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) static struct attribute sys_padding_dist = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	.name = "padding_dist",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	.mode = 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) #ifdef CONFIG_NVM_PBLK_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) static struct attribute sys_stats_debug_attr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	.name = "stats",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	.mode = 0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) static struct attribute *pblk_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	&sys_write_luns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	&sys_rate_limiter_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	&sys_errors_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	&sys_gc_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	&sys_gc_force,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	&sys_max_sec_per_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	&sys_rb_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	&sys_stats_ppaf_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	&sys_lines_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	&sys_lines_info_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 	&sys_write_amp_mileage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	&sys_write_amp_trip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	&sys_padding_dist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) #ifdef CONFIG_NVM_PBLK_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	&sys_stats_debug_attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) static ssize_t pblk_sysfs_show(struct kobject *kobj, struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 			       char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	struct pblk *pblk = container_of(kobj, struct pblk, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	if (strcmp(attr->name, "rate_limiter") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 		return pblk_sysfs_rate_limiter(pblk, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	else if (strcmp(attr->name, "write_luns") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 		return pblk_sysfs_luns_show(pblk, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	else if (strcmp(attr->name, "gc_state") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 		return pblk_sysfs_gc_state_show(pblk, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	else if (strcmp(attr->name, "errors") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 		return pblk_sysfs_stats(pblk, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	else if (strcmp(attr->name, "write_buffer") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 		return pblk_sysfs_write_buffer(pblk, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	else if (strcmp(attr->name, "ppa_format") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 		return pblk_sysfs_ppaf(pblk, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	else if (strcmp(attr->name, "lines") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 		return pblk_sysfs_lines(pblk, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	else if (strcmp(attr->name, "lines_info") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		return pblk_sysfs_lines_info(pblk, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	else if (strcmp(attr->name, "max_sec_per_write") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 		return pblk_sysfs_get_sec_per_write(pblk, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	else if (strcmp(attr->name, "write_amp_mileage") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		return pblk_sysfs_get_write_amp_mileage(pblk, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	else if (strcmp(attr->name, "write_amp_trip") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 		return pblk_sysfs_get_write_amp_trip(pblk, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	else if (strcmp(attr->name, "padding_dist") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 		return pblk_sysfs_get_padding_dist(pblk, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) #ifdef CONFIG_NVM_PBLK_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	else if (strcmp(attr->name, "stats") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		return pblk_sysfs_stats_debug(pblk, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) static ssize_t pblk_sysfs_store(struct kobject *kobj, struct attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 				const char *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	struct pblk *pblk = container_of(kobj, struct pblk, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	if (strcmp(attr->name, "gc_force") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 		return pblk_sysfs_gc_force(pblk, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	else if (strcmp(attr->name, "max_sec_per_write") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 		return pblk_sysfs_set_sec_per_write(pblk, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	else if (strcmp(attr->name, "write_amp_trip") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 		return pblk_sysfs_set_write_amp_trip(pblk, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	else if (strcmp(attr->name, "padding_dist") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 		return pblk_sysfs_set_padding_dist(pblk, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) static const struct sysfs_ops pblk_sysfs_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	.show = pblk_sysfs_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	.store = pblk_sysfs_store,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) static struct kobj_type pblk_ktype = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	.sysfs_ops	= &pblk_sysfs_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	.default_attrs	= pblk_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) int pblk_sysfs_init(struct gendisk *tdisk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	struct pblk *pblk = tdisk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	struct device *parent_dev = disk_to_dev(pblk->disk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	ret = kobject_init_and_add(&pblk->kobj, &pblk_ktype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 					kobject_get(&parent_dev->kobj),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 					"%s", "pblk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 		pblk_err(pblk, "could not register\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	kobject_uevent(&pblk->kobj, KOBJ_ADD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) void pblk_sysfs_exit(struct gendisk *tdisk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	struct pblk *pblk = tdisk->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	kobject_uevent(&pblk->kobj, KOBJ_REMOVE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	kobject_del(&pblk->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 	kobject_put(&pblk->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) }