18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2016 CNEX Labs
48c2ecf20Sopenharmony_ci * Initial release: Javier Gonzalez <javier@cnexlabs.com>
58c2ecf20Sopenharmony_ci *                  Matias Bjorling <matias@cnexlabs.com>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or
88c2ecf20Sopenharmony_ci * modify it under the terms of the GNU General Public License version
98c2ecf20Sopenharmony_ci * 2 as published by the Free Software Foundation.
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful, but
128c2ecf20Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
138c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
148c2ecf20Sopenharmony_ci * General Public License for more details.
158c2ecf20Sopenharmony_ci *
168c2ecf20Sopenharmony_ci * Implementation of a physical block-device target for Open-channel SSDs.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * pblk-sysfs.c - pblk's sysfs
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci */
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#include "pblk.h"
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_luns_show(struct pblk *pblk, char *page)
258c2ecf20Sopenharmony_ci{
268c2ecf20Sopenharmony_ci	struct nvm_tgt_dev *dev = pblk->dev;
278c2ecf20Sopenharmony_ci	struct nvm_geo *geo = &dev->geo;
288c2ecf20Sopenharmony_ci	struct pblk_lun *rlun;
298c2ecf20Sopenharmony_ci	ssize_t sz = 0;
308c2ecf20Sopenharmony_ci	int i;
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	for (i = 0; i < geo->all_luns; i++) {
338c2ecf20Sopenharmony_ci		int active = 1;
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci		rlun = &pblk->luns[i];
368c2ecf20Sopenharmony_ci		if (!down_trylock(&rlun->wr_sem)) {
378c2ecf20Sopenharmony_ci			active = 0;
388c2ecf20Sopenharmony_ci			up(&rlun->wr_sem);
398c2ecf20Sopenharmony_ci		}
408c2ecf20Sopenharmony_ci		sz += scnprintf(page + sz, PAGE_SIZE - sz,
418c2ecf20Sopenharmony_ci				"pblk: pos:%d, ch:%d, lun:%d - %d\n",
428c2ecf20Sopenharmony_ci					i,
438c2ecf20Sopenharmony_ci					rlun->bppa.a.ch,
448c2ecf20Sopenharmony_ci					rlun->bppa.a.lun,
458c2ecf20Sopenharmony_ci					active);
468c2ecf20Sopenharmony_ci	}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	return sz;
498c2ecf20Sopenharmony_ci}
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_rate_limiter(struct pblk *pblk, char *page)
528c2ecf20Sopenharmony_ci{
538c2ecf20Sopenharmony_ci	int free_blocks, free_user_blocks, total_blocks;
548c2ecf20Sopenharmony_ci	int rb_user_max, rb_user_cnt;
558c2ecf20Sopenharmony_ci	int rb_gc_max, rb_gc_cnt, rb_budget, rb_state;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	free_blocks = pblk_rl_nr_free_blks(&pblk->rl);
588c2ecf20Sopenharmony_ci	free_user_blocks = pblk_rl_nr_user_free_blks(&pblk->rl);
598c2ecf20Sopenharmony_ci	rb_user_max = pblk->rl.rb_user_max;
608c2ecf20Sopenharmony_ci	rb_user_cnt = atomic_read(&pblk->rl.rb_user_cnt);
618c2ecf20Sopenharmony_ci	rb_gc_max = pblk->rl.rb_gc_max;
628c2ecf20Sopenharmony_ci	rb_gc_cnt = atomic_read(&pblk->rl.rb_gc_cnt);
638c2ecf20Sopenharmony_ci	rb_budget = pblk->rl.rb_budget;
648c2ecf20Sopenharmony_ci	rb_state = pblk->rl.rb_state;
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci	total_blocks = pblk->rl.total_blocks;
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE,
698c2ecf20Sopenharmony_ci		"u:%u/%u,gc:%u/%u(%u)(stop:<%u,full:>%u,free:%d/%d/%d)-%d\n",
708c2ecf20Sopenharmony_ci				rb_user_cnt,
718c2ecf20Sopenharmony_ci				rb_user_max,
728c2ecf20Sopenharmony_ci				rb_gc_cnt,
738c2ecf20Sopenharmony_ci				rb_gc_max,
748c2ecf20Sopenharmony_ci				rb_state,
758c2ecf20Sopenharmony_ci				rb_budget,
768c2ecf20Sopenharmony_ci				pblk->rl.high,
778c2ecf20Sopenharmony_ci				free_blocks,
788c2ecf20Sopenharmony_ci				free_user_blocks,
798c2ecf20Sopenharmony_ci				total_blocks,
808c2ecf20Sopenharmony_ci				READ_ONCE(pblk->rl.rb_user_active));
818c2ecf20Sopenharmony_ci}
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_gc_state_show(struct pblk *pblk, char *page)
848c2ecf20Sopenharmony_ci{
858c2ecf20Sopenharmony_ci	int gc_enabled, gc_active;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	pblk_gc_sysfs_state_show(pblk, &gc_enabled, &gc_active);
888c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "gc_enabled=%d, gc_active=%d\n",
898c2ecf20Sopenharmony_ci					gc_enabled, gc_active);
908c2ecf20Sopenharmony_ci}
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_stats(struct pblk *pblk, char *page)
938c2ecf20Sopenharmony_ci{
948c2ecf20Sopenharmony_ci	ssize_t sz;
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci	sz = snprintf(page, PAGE_SIZE,
978c2ecf20Sopenharmony_ci			"read_failed=%lu, read_high_ecc=%lu, read_empty=%lu, read_failed_gc=%lu, write_failed=%lu, erase_failed=%lu\n",
988c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->read_failed),
998c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->read_high_ecc),
1008c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->read_empty),
1018c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->read_failed_gc),
1028c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->write_failed),
1038c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->erase_failed));
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	return sz;
1068c2ecf20Sopenharmony_ci}
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_write_buffer(struct pblk *pblk, char *page)
1098c2ecf20Sopenharmony_ci{
1108c2ecf20Sopenharmony_ci	return pblk_rb_sysfs(&pblk->rwb, page);
1118c2ecf20Sopenharmony_ci}
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_ppaf(struct pblk *pblk, char *page)
1148c2ecf20Sopenharmony_ci{
1158c2ecf20Sopenharmony_ci	struct nvm_tgt_dev *dev = pblk->dev;
1168c2ecf20Sopenharmony_ci	struct nvm_geo *geo = &dev->geo;
1178c2ecf20Sopenharmony_ci	ssize_t sz = 0;
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci	if (geo->version == NVM_OCSSD_SPEC_12) {
1208c2ecf20Sopenharmony_ci		struct nvm_addrf_12 *ppaf = (struct nvm_addrf_12 *)&pblk->addrf;
1218c2ecf20Sopenharmony_ci		struct nvm_addrf_12 *gppaf = (struct nvm_addrf_12 *)&geo->addrf;
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci		sz = scnprintf(page, PAGE_SIZE,
1248c2ecf20Sopenharmony_ci			"g:(b:%d)blk:%d/%d,pg:%d/%d,lun:%d/%d,ch:%d/%d,pl:%d/%d,sec:%d/%d\n",
1258c2ecf20Sopenharmony_ci			pblk->addrf_len,
1268c2ecf20Sopenharmony_ci			ppaf->blk_offset, ppaf->blk_len,
1278c2ecf20Sopenharmony_ci			ppaf->pg_offset, ppaf->pg_len,
1288c2ecf20Sopenharmony_ci			ppaf->lun_offset, ppaf->lun_len,
1298c2ecf20Sopenharmony_ci			ppaf->ch_offset, ppaf->ch_len,
1308c2ecf20Sopenharmony_ci			ppaf->pln_offset, ppaf->pln_len,
1318c2ecf20Sopenharmony_ci			ppaf->sec_offset, ppaf->sec_len);
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci		sz += scnprintf(page + sz, PAGE_SIZE - sz,
1348c2ecf20Sopenharmony_ci			"d:blk:%d/%d,pg:%d/%d,lun:%d/%d,ch:%d/%d,pl:%d/%d,sec:%d/%d\n",
1358c2ecf20Sopenharmony_ci			gppaf->blk_offset, gppaf->blk_len,
1368c2ecf20Sopenharmony_ci			gppaf->pg_offset, gppaf->pg_len,
1378c2ecf20Sopenharmony_ci			gppaf->lun_offset, gppaf->lun_len,
1388c2ecf20Sopenharmony_ci			gppaf->ch_offset, gppaf->ch_len,
1398c2ecf20Sopenharmony_ci			gppaf->pln_offset, gppaf->pln_len,
1408c2ecf20Sopenharmony_ci			gppaf->sec_offset, gppaf->sec_len);
1418c2ecf20Sopenharmony_ci	} else {
1428c2ecf20Sopenharmony_ci		struct nvm_addrf *ppaf = &pblk->addrf;
1438c2ecf20Sopenharmony_ci		struct nvm_addrf *gppaf = &geo->addrf;
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci		sz = scnprintf(page, PAGE_SIZE,
1468c2ecf20Sopenharmony_ci			"pblk:(s:%d)ch:%d/%d,lun:%d/%d,chk:%d/%d/sec:%d/%d\n",
1478c2ecf20Sopenharmony_ci			pblk->addrf_len,
1488c2ecf20Sopenharmony_ci			ppaf->ch_offset, ppaf->ch_len,
1498c2ecf20Sopenharmony_ci			ppaf->lun_offset, ppaf->lun_len,
1508c2ecf20Sopenharmony_ci			ppaf->chk_offset, ppaf->chk_len,
1518c2ecf20Sopenharmony_ci			ppaf->sec_offset, ppaf->sec_len);
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci		sz += scnprintf(page + sz, PAGE_SIZE - sz,
1548c2ecf20Sopenharmony_ci			"device:ch:%d/%d,lun:%d/%d,chk:%d/%d,sec:%d/%d\n",
1558c2ecf20Sopenharmony_ci			gppaf->ch_offset, gppaf->ch_len,
1568c2ecf20Sopenharmony_ci			gppaf->lun_offset, gppaf->lun_len,
1578c2ecf20Sopenharmony_ci			gppaf->chk_offset, gppaf->chk_len,
1588c2ecf20Sopenharmony_ci			gppaf->sec_offset, gppaf->sec_len);
1598c2ecf20Sopenharmony_ci	}
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci	return sz;
1628c2ecf20Sopenharmony_ci}
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_lines(struct pblk *pblk, char *page)
1658c2ecf20Sopenharmony_ci{
1668c2ecf20Sopenharmony_ci	struct nvm_tgt_dev *dev = pblk->dev;
1678c2ecf20Sopenharmony_ci	struct nvm_geo *geo = &dev->geo;
1688c2ecf20Sopenharmony_ci	struct pblk_line_meta *lm = &pblk->lm;
1698c2ecf20Sopenharmony_ci	struct pblk_line_mgmt *l_mg = &pblk->l_mg;
1708c2ecf20Sopenharmony_ci	struct pblk_line *line;
1718c2ecf20Sopenharmony_ci	ssize_t sz = 0;
1728c2ecf20Sopenharmony_ci	int nr_free_lines;
1738c2ecf20Sopenharmony_ci	int cur_data, cur_log;
1748c2ecf20Sopenharmony_ci	int free_line_cnt = 0, closed_line_cnt = 0, emeta_line_cnt = 0;
1758c2ecf20Sopenharmony_ci	int d_line_cnt = 0, l_line_cnt = 0;
1768c2ecf20Sopenharmony_ci	int gc_full = 0, gc_high = 0, gc_mid = 0, gc_low = 0, gc_empty = 0;
1778c2ecf20Sopenharmony_ci	int gc_werr = 0;
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci	int bad = 0, cor = 0;
1808c2ecf20Sopenharmony_ci	int msecs = 0, cur_sec = 0, vsc = 0, sec_in_line = 0;
1818c2ecf20Sopenharmony_ci	int map_weight = 0, meta_weight = 0;
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci	spin_lock(&l_mg->free_lock);
1848c2ecf20Sopenharmony_ci	cur_data = (l_mg->data_line) ? l_mg->data_line->id : -1;
1858c2ecf20Sopenharmony_ci	cur_log = (l_mg->log_line) ? l_mg->log_line->id : -1;
1868c2ecf20Sopenharmony_ci	nr_free_lines = l_mg->nr_free_lines;
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	list_for_each_entry(line, &l_mg->free_list, list)
1898c2ecf20Sopenharmony_ci		free_line_cnt++;
1908c2ecf20Sopenharmony_ci	spin_unlock(&l_mg->free_lock);
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	spin_lock(&l_mg->close_lock);
1938c2ecf20Sopenharmony_ci	list_for_each_entry(line, &l_mg->emeta_list, list)
1948c2ecf20Sopenharmony_ci		emeta_line_cnt++;
1958c2ecf20Sopenharmony_ci	spin_unlock(&l_mg->close_lock);
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci	spin_lock(&l_mg->gc_lock);
1988c2ecf20Sopenharmony_ci	list_for_each_entry(line, &l_mg->gc_full_list, list) {
1998c2ecf20Sopenharmony_ci		if (line->type == PBLK_LINETYPE_DATA)
2008c2ecf20Sopenharmony_ci			d_line_cnt++;
2018c2ecf20Sopenharmony_ci		else if (line->type == PBLK_LINETYPE_LOG)
2028c2ecf20Sopenharmony_ci			l_line_cnt++;
2038c2ecf20Sopenharmony_ci		closed_line_cnt++;
2048c2ecf20Sopenharmony_ci		gc_full++;
2058c2ecf20Sopenharmony_ci	}
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci	list_for_each_entry(line, &l_mg->gc_high_list, list) {
2088c2ecf20Sopenharmony_ci		if (line->type == PBLK_LINETYPE_DATA)
2098c2ecf20Sopenharmony_ci			d_line_cnt++;
2108c2ecf20Sopenharmony_ci		else if (line->type == PBLK_LINETYPE_LOG)
2118c2ecf20Sopenharmony_ci			l_line_cnt++;
2128c2ecf20Sopenharmony_ci		closed_line_cnt++;
2138c2ecf20Sopenharmony_ci		gc_high++;
2148c2ecf20Sopenharmony_ci	}
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci	list_for_each_entry(line, &l_mg->gc_mid_list, list) {
2178c2ecf20Sopenharmony_ci		if (line->type == PBLK_LINETYPE_DATA)
2188c2ecf20Sopenharmony_ci			d_line_cnt++;
2198c2ecf20Sopenharmony_ci		else if (line->type == PBLK_LINETYPE_LOG)
2208c2ecf20Sopenharmony_ci			l_line_cnt++;
2218c2ecf20Sopenharmony_ci		closed_line_cnt++;
2228c2ecf20Sopenharmony_ci		gc_mid++;
2238c2ecf20Sopenharmony_ci	}
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci	list_for_each_entry(line, &l_mg->gc_low_list, list) {
2268c2ecf20Sopenharmony_ci		if (line->type == PBLK_LINETYPE_DATA)
2278c2ecf20Sopenharmony_ci			d_line_cnt++;
2288c2ecf20Sopenharmony_ci		else if (line->type == PBLK_LINETYPE_LOG)
2298c2ecf20Sopenharmony_ci			l_line_cnt++;
2308c2ecf20Sopenharmony_ci		closed_line_cnt++;
2318c2ecf20Sopenharmony_ci		gc_low++;
2328c2ecf20Sopenharmony_ci	}
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci	list_for_each_entry(line, &l_mg->gc_empty_list, list) {
2358c2ecf20Sopenharmony_ci		if (line->type == PBLK_LINETYPE_DATA)
2368c2ecf20Sopenharmony_ci			d_line_cnt++;
2378c2ecf20Sopenharmony_ci		else if (line->type == PBLK_LINETYPE_LOG)
2388c2ecf20Sopenharmony_ci			l_line_cnt++;
2398c2ecf20Sopenharmony_ci		closed_line_cnt++;
2408c2ecf20Sopenharmony_ci		gc_empty++;
2418c2ecf20Sopenharmony_ci	}
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci	list_for_each_entry(line, &l_mg->gc_werr_list, list) {
2448c2ecf20Sopenharmony_ci		if (line->type == PBLK_LINETYPE_DATA)
2458c2ecf20Sopenharmony_ci			d_line_cnt++;
2468c2ecf20Sopenharmony_ci		else if (line->type == PBLK_LINETYPE_LOG)
2478c2ecf20Sopenharmony_ci			l_line_cnt++;
2488c2ecf20Sopenharmony_ci		closed_line_cnt++;
2498c2ecf20Sopenharmony_ci		gc_werr++;
2508c2ecf20Sopenharmony_ci	}
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_ci	list_for_each_entry(line, &l_mg->bad_list, list)
2538c2ecf20Sopenharmony_ci		bad++;
2548c2ecf20Sopenharmony_ci	list_for_each_entry(line, &l_mg->corrupt_list, list)
2558c2ecf20Sopenharmony_ci		cor++;
2568c2ecf20Sopenharmony_ci	spin_unlock(&l_mg->gc_lock);
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_ci	spin_lock(&l_mg->free_lock);
2598c2ecf20Sopenharmony_ci	if (l_mg->data_line) {
2608c2ecf20Sopenharmony_ci		cur_sec = l_mg->data_line->cur_sec;
2618c2ecf20Sopenharmony_ci		msecs = l_mg->data_line->left_msecs;
2628c2ecf20Sopenharmony_ci		vsc = le32_to_cpu(*l_mg->data_line->vsc);
2638c2ecf20Sopenharmony_ci		sec_in_line = l_mg->data_line->sec_in_line;
2648c2ecf20Sopenharmony_ci		meta_weight = bitmap_weight(&l_mg->meta_bitmap,
2658c2ecf20Sopenharmony_ci							PBLK_DATA_LINES);
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_ci		spin_lock(&l_mg->data_line->lock);
2688c2ecf20Sopenharmony_ci		if (l_mg->data_line->map_bitmap)
2698c2ecf20Sopenharmony_ci			map_weight = bitmap_weight(l_mg->data_line->map_bitmap,
2708c2ecf20Sopenharmony_ci							lm->sec_per_line);
2718c2ecf20Sopenharmony_ci		else
2728c2ecf20Sopenharmony_ci			map_weight = 0;
2738c2ecf20Sopenharmony_ci		spin_unlock(&l_mg->data_line->lock);
2748c2ecf20Sopenharmony_ci	}
2758c2ecf20Sopenharmony_ci	spin_unlock(&l_mg->free_lock);
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci	if (nr_free_lines != free_line_cnt)
2788c2ecf20Sopenharmony_ci		pblk_err(pblk, "corrupted free line list:%d/%d\n",
2798c2ecf20Sopenharmony_ci						nr_free_lines, free_line_cnt);
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	sz = scnprintf(page, PAGE_SIZE - sz,
2828c2ecf20Sopenharmony_ci		"line: nluns:%d, nblks:%d, nsecs:%d\n",
2838c2ecf20Sopenharmony_ci		geo->all_luns, lm->blk_per_line, lm->sec_per_line);
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	sz += scnprintf(page + sz, PAGE_SIZE - sz,
2868c2ecf20Sopenharmony_ci		"lines:d:%d,l:%d-f:%d,m:%d/%d,c:%d,b:%d,co:%d(d:%d,l:%d)t:%d\n",
2878c2ecf20Sopenharmony_ci					cur_data, cur_log,
2888c2ecf20Sopenharmony_ci					nr_free_lines,
2898c2ecf20Sopenharmony_ci					emeta_line_cnt, meta_weight,
2908c2ecf20Sopenharmony_ci					closed_line_cnt,
2918c2ecf20Sopenharmony_ci					bad, cor,
2928c2ecf20Sopenharmony_ci					d_line_cnt, l_line_cnt,
2938c2ecf20Sopenharmony_ci					l_mg->nr_lines);
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci	sz += scnprintf(page + sz, PAGE_SIZE - sz,
2968c2ecf20Sopenharmony_ci		"GC: full:%d, high:%d, mid:%d, low:%d, empty:%d, werr: %d, queue:%d\n",
2978c2ecf20Sopenharmony_ci			gc_full, gc_high, gc_mid, gc_low, gc_empty, gc_werr,
2988c2ecf20Sopenharmony_ci			atomic_read(&pblk->gc.read_inflight_gc));
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci	sz += scnprintf(page + sz, PAGE_SIZE - sz,
3018c2ecf20Sopenharmony_ci		"data (%d) cur:%d, left:%d, vsc:%d, s:%d, map:%d/%d (%d)\n",
3028c2ecf20Sopenharmony_ci			cur_data, cur_sec, msecs, vsc, sec_in_line,
3038c2ecf20Sopenharmony_ci			map_weight, lm->sec_per_line,
3048c2ecf20Sopenharmony_ci			atomic_read(&pblk->inflight_io));
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci	return sz;
3078c2ecf20Sopenharmony_ci}
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_lines_info(struct pblk *pblk, char *page)
3108c2ecf20Sopenharmony_ci{
3118c2ecf20Sopenharmony_ci	struct nvm_tgt_dev *dev = pblk->dev;
3128c2ecf20Sopenharmony_ci	struct nvm_geo *geo = &dev->geo;
3138c2ecf20Sopenharmony_ci	struct pblk_line_meta *lm = &pblk->lm;
3148c2ecf20Sopenharmony_ci	ssize_t sz = 0;
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci	sz = scnprintf(page, PAGE_SIZE - sz,
3178c2ecf20Sopenharmony_ci				"smeta - len:%d, secs:%d\n",
3188c2ecf20Sopenharmony_ci					lm->smeta_len, lm->smeta_sec);
3198c2ecf20Sopenharmony_ci	sz += scnprintf(page + sz, PAGE_SIZE - sz,
3208c2ecf20Sopenharmony_ci				"emeta - len:%d, sec:%d, bb_start:%d\n",
3218c2ecf20Sopenharmony_ci					lm->emeta_len[0], lm->emeta_sec[0],
3228c2ecf20Sopenharmony_ci					lm->emeta_bb);
3238c2ecf20Sopenharmony_ci	sz += scnprintf(page + sz, PAGE_SIZE - sz,
3248c2ecf20Sopenharmony_ci				"bitmap lengths: sec:%d, blk:%d, lun:%d\n",
3258c2ecf20Sopenharmony_ci					lm->sec_bitmap_len,
3268c2ecf20Sopenharmony_ci					lm->blk_bitmap_len,
3278c2ecf20Sopenharmony_ci					lm->lun_bitmap_len);
3288c2ecf20Sopenharmony_ci	sz += scnprintf(page + sz, PAGE_SIZE - sz,
3298c2ecf20Sopenharmony_ci				"blk_line:%d, sec_line:%d, sec_blk:%d\n",
3308c2ecf20Sopenharmony_ci					lm->blk_per_line,
3318c2ecf20Sopenharmony_ci					lm->sec_per_line,
3328c2ecf20Sopenharmony_ci					geo->clba);
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci	return sz;
3358c2ecf20Sopenharmony_ci}
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_get_sec_per_write(struct pblk *pblk, char *page)
3388c2ecf20Sopenharmony_ci{
3398c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%d\n", pblk->sec_per_write);
3408c2ecf20Sopenharmony_ci}
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_cistatic ssize_t pblk_get_write_amp(u64 user, u64 gc, u64 pad,
3438c2ecf20Sopenharmony_ci				  char *page)
3448c2ecf20Sopenharmony_ci{
3458c2ecf20Sopenharmony_ci	int sz;
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	sz = scnprintf(page, PAGE_SIZE,
3488c2ecf20Sopenharmony_ci			"user:%lld gc:%lld pad:%lld WA:",
3498c2ecf20Sopenharmony_ci			user, gc, pad);
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	if (!user) {
3528c2ecf20Sopenharmony_ci		sz += scnprintf(page + sz, PAGE_SIZE - sz, "NaN\n");
3538c2ecf20Sopenharmony_ci	} else {
3548c2ecf20Sopenharmony_ci		u64 wa_int;
3558c2ecf20Sopenharmony_ci		u32 wa_frac;
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci		wa_int = (user + gc + pad) * 100000;
3588c2ecf20Sopenharmony_ci		wa_int = div64_u64(wa_int, user);
3598c2ecf20Sopenharmony_ci		wa_int = div_u64_rem(wa_int, 100000, &wa_frac);
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci		sz += scnprintf(page + sz, PAGE_SIZE - sz, "%llu.%05u\n",
3628c2ecf20Sopenharmony_ci							wa_int, wa_frac);
3638c2ecf20Sopenharmony_ci	}
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci	return sz;
3668c2ecf20Sopenharmony_ci}
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_get_write_amp_mileage(struct pblk *pblk, char *page)
3698c2ecf20Sopenharmony_ci{
3708c2ecf20Sopenharmony_ci	return pblk_get_write_amp(atomic64_read(&pblk->user_wa),
3718c2ecf20Sopenharmony_ci		atomic64_read(&pblk->gc_wa), atomic64_read(&pblk->pad_wa),
3728c2ecf20Sopenharmony_ci		page);
3738c2ecf20Sopenharmony_ci}
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_get_write_amp_trip(struct pblk *pblk, char *page)
3768c2ecf20Sopenharmony_ci{
3778c2ecf20Sopenharmony_ci	return pblk_get_write_amp(
3788c2ecf20Sopenharmony_ci		atomic64_read(&pblk->user_wa) - pblk->user_rst_wa,
3798c2ecf20Sopenharmony_ci		atomic64_read(&pblk->gc_wa) - pblk->gc_rst_wa,
3808c2ecf20Sopenharmony_ci		atomic64_read(&pblk->pad_wa) - pblk->pad_rst_wa, page);
3818c2ecf20Sopenharmony_ci}
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_cistatic long long bucket_percentage(unsigned long long bucket,
3848c2ecf20Sopenharmony_ci				   unsigned long long total)
3858c2ecf20Sopenharmony_ci{
3868c2ecf20Sopenharmony_ci	int p = bucket * 100;
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci	p = div_u64(p, total);
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci	return p;
3918c2ecf20Sopenharmony_ci}
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_get_padding_dist(struct pblk *pblk, char *page)
3948c2ecf20Sopenharmony_ci{
3958c2ecf20Sopenharmony_ci	int sz = 0;
3968c2ecf20Sopenharmony_ci	unsigned long long total;
3978c2ecf20Sopenharmony_ci	unsigned long long total_buckets = 0;
3988c2ecf20Sopenharmony_ci	int buckets = pblk->min_write_pgs - 1;
3998c2ecf20Sopenharmony_ci	int i;
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_ci	total = atomic64_read(&pblk->nr_flush) - pblk->nr_flush_rst;
4028c2ecf20Sopenharmony_ci	if (!total) {
4038c2ecf20Sopenharmony_ci		for (i = 0; i < (buckets + 1); i++)
4048c2ecf20Sopenharmony_ci			sz += scnprintf(page + sz, PAGE_SIZE - sz,
4058c2ecf20Sopenharmony_ci				"%d:0 ", i);
4068c2ecf20Sopenharmony_ci		sz += scnprintf(page + sz, PAGE_SIZE - sz, "\n");
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci		return sz;
4098c2ecf20Sopenharmony_ci	}
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_ci	for (i = 0; i < buckets; i++)
4128c2ecf20Sopenharmony_ci		total_buckets += atomic64_read(&pblk->pad_dist[i]);
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	sz += scnprintf(page + sz, PAGE_SIZE - sz, "0:%lld%% ",
4158c2ecf20Sopenharmony_ci		bucket_percentage(total - total_buckets, total));
4168c2ecf20Sopenharmony_ci
4178c2ecf20Sopenharmony_ci	for (i = 0; i < buckets; i++) {
4188c2ecf20Sopenharmony_ci		unsigned long long p;
4198c2ecf20Sopenharmony_ci
4208c2ecf20Sopenharmony_ci		p = bucket_percentage(atomic64_read(&pblk->pad_dist[i]),
4218c2ecf20Sopenharmony_ci					  total);
4228c2ecf20Sopenharmony_ci		sz += scnprintf(page + sz, PAGE_SIZE - sz, "%d:%lld%% ",
4238c2ecf20Sopenharmony_ci				i + 1, p);
4248c2ecf20Sopenharmony_ci	}
4258c2ecf20Sopenharmony_ci	sz += scnprintf(page + sz, PAGE_SIZE - sz, "\n");
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ci	return sz;
4288c2ecf20Sopenharmony_ci}
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci#ifdef CONFIG_NVM_PBLK_DEBUG
4318c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_stats_debug(struct pblk *pblk, char *page)
4328c2ecf20Sopenharmony_ci{
4338c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE,
4348c2ecf20Sopenharmony_ci		"%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",
4358c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->inflight_writes),
4368c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->inflight_reads),
4378c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->req_writes),
4388c2ecf20Sopenharmony_ci			(u64)atomic64_read(&pblk->nr_flush),
4398c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->padded_writes),
4408c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->padded_wb),
4418c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->sub_writes),
4428c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->sync_writes),
4438c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->recov_writes),
4448c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->recov_gc_writes),
4458c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->recov_gc_reads),
4468c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->cache_reads),
4478c2ecf20Sopenharmony_ci			atomic_long_read(&pblk->sync_reads));
4488c2ecf20Sopenharmony_ci}
4498c2ecf20Sopenharmony_ci#endif
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_gc_force(struct pblk *pblk, const char *page,
4528c2ecf20Sopenharmony_ci				   size_t len)
4538c2ecf20Sopenharmony_ci{
4548c2ecf20Sopenharmony_ci	size_t c_len;
4558c2ecf20Sopenharmony_ci	int force;
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci	c_len = strcspn(page, "\n");
4588c2ecf20Sopenharmony_ci	if (c_len >= len)
4598c2ecf20Sopenharmony_ci		return -EINVAL;
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci	if (kstrtouint(page, 0, &force))
4628c2ecf20Sopenharmony_ci		return -EINVAL;
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci	pblk_gc_sysfs_force(pblk, force);
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_ci	return len;
4678c2ecf20Sopenharmony_ci}
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_set_sec_per_write(struct pblk *pblk,
4708c2ecf20Sopenharmony_ci					     const char *page, size_t len)
4718c2ecf20Sopenharmony_ci{
4728c2ecf20Sopenharmony_ci	size_t c_len;
4738c2ecf20Sopenharmony_ci	int sec_per_write;
4748c2ecf20Sopenharmony_ci
4758c2ecf20Sopenharmony_ci	c_len = strcspn(page, "\n");
4768c2ecf20Sopenharmony_ci	if (c_len >= len)
4778c2ecf20Sopenharmony_ci		return -EINVAL;
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ci	if (kstrtouint(page, 0, &sec_per_write))
4808c2ecf20Sopenharmony_ci		return -EINVAL;
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_ci	if (!pblk_is_oob_meta_supported(pblk)) {
4838c2ecf20Sopenharmony_ci		/* For packed metadata case it is
4848c2ecf20Sopenharmony_ci		 * not allowed to change sec_per_write.
4858c2ecf20Sopenharmony_ci		 */
4868c2ecf20Sopenharmony_ci		return -EINVAL;
4878c2ecf20Sopenharmony_ci	}
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci	if (sec_per_write < pblk->min_write_pgs
4908c2ecf20Sopenharmony_ci				|| sec_per_write > pblk->max_write_pgs
4918c2ecf20Sopenharmony_ci				|| sec_per_write % pblk->min_write_pgs != 0)
4928c2ecf20Sopenharmony_ci		return -EINVAL;
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci	pblk_set_sec_per_write(pblk, sec_per_write);
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci	return len;
4978c2ecf20Sopenharmony_ci}
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_set_write_amp_trip(struct pblk *pblk,
5008c2ecf20Sopenharmony_ci			const char *page, size_t len)
5018c2ecf20Sopenharmony_ci{
5028c2ecf20Sopenharmony_ci	size_t c_len;
5038c2ecf20Sopenharmony_ci	int reset_value;
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_ci	c_len = strcspn(page, "\n");
5068c2ecf20Sopenharmony_ci	if (c_len >= len)
5078c2ecf20Sopenharmony_ci		return -EINVAL;
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci	if (kstrtouint(page, 0, &reset_value))
5108c2ecf20Sopenharmony_ci		return -EINVAL;
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci	if (reset_value !=  0)
5138c2ecf20Sopenharmony_ci		return -EINVAL;
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_ci	pblk->user_rst_wa = atomic64_read(&pblk->user_wa);
5168c2ecf20Sopenharmony_ci	pblk->pad_rst_wa = atomic64_read(&pblk->pad_wa);
5178c2ecf20Sopenharmony_ci	pblk->gc_rst_wa = atomic64_read(&pblk->gc_wa);
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci	return len;
5208c2ecf20Sopenharmony_ci}
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ci
5238c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_set_padding_dist(struct pblk *pblk,
5248c2ecf20Sopenharmony_ci			const char *page, size_t len)
5258c2ecf20Sopenharmony_ci{
5268c2ecf20Sopenharmony_ci	size_t c_len;
5278c2ecf20Sopenharmony_ci	int reset_value;
5288c2ecf20Sopenharmony_ci	int buckets = pblk->min_write_pgs - 1;
5298c2ecf20Sopenharmony_ci	int i;
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_ci	c_len = strcspn(page, "\n");
5328c2ecf20Sopenharmony_ci	if (c_len >= len)
5338c2ecf20Sopenharmony_ci		return -EINVAL;
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_ci	if (kstrtouint(page, 0, &reset_value))
5368c2ecf20Sopenharmony_ci		return -EINVAL;
5378c2ecf20Sopenharmony_ci
5388c2ecf20Sopenharmony_ci	if (reset_value !=  0)
5398c2ecf20Sopenharmony_ci		return -EINVAL;
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci	for (i = 0; i < buckets; i++)
5428c2ecf20Sopenharmony_ci		atomic64_set(&pblk->pad_dist[i], 0);
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_ci	pblk->nr_flush_rst = atomic64_read(&pblk->nr_flush);
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ci	return len;
5478c2ecf20Sopenharmony_ci}
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_cistatic struct attribute sys_write_luns = {
5508c2ecf20Sopenharmony_ci	.name = "write_luns",
5518c2ecf20Sopenharmony_ci	.mode = 0444,
5528c2ecf20Sopenharmony_ci};
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_cistatic struct attribute sys_rate_limiter_attr = {
5558c2ecf20Sopenharmony_ci	.name = "rate_limiter",
5568c2ecf20Sopenharmony_ci	.mode = 0444,
5578c2ecf20Sopenharmony_ci};
5588c2ecf20Sopenharmony_ci
5598c2ecf20Sopenharmony_cistatic struct attribute sys_gc_state = {
5608c2ecf20Sopenharmony_ci	.name = "gc_state",
5618c2ecf20Sopenharmony_ci	.mode = 0444,
5628c2ecf20Sopenharmony_ci};
5638c2ecf20Sopenharmony_ci
5648c2ecf20Sopenharmony_cistatic struct attribute sys_errors_attr = {
5658c2ecf20Sopenharmony_ci	.name = "errors",
5668c2ecf20Sopenharmony_ci	.mode = 0444,
5678c2ecf20Sopenharmony_ci};
5688c2ecf20Sopenharmony_ci
5698c2ecf20Sopenharmony_cistatic struct attribute sys_rb_attr = {
5708c2ecf20Sopenharmony_ci	.name = "write_buffer",
5718c2ecf20Sopenharmony_ci	.mode = 0444,
5728c2ecf20Sopenharmony_ci};
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_cistatic struct attribute sys_stats_ppaf_attr = {
5758c2ecf20Sopenharmony_ci	.name = "ppa_format",
5768c2ecf20Sopenharmony_ci	.mode = 0444,
5778c2ecf20Sopenharmony_ci};
5788c2ecf20Sopenharmony_ci
5798c2ecf20Sopenharmony_cistatic struct attribute sys_lines_attr = {
5808c2ecf20Sopenharmony_ci	.name = "lines",
5818c2ecf20Sopenharmony_ci	.mode = 0444,
5828c2ecf20Sopenharmony_ci};
5838c2ecf20Sopenharmony_ci
5848c2ecf20Sopenharmony_cistatic struct attribute sys_lines_info_attr = {
5858c2ecf20Sopenharmony_ci	.name = "lines_info",
5868c2ecf20Sopenharmony_ci	.mode = 0444,
5878c2ecf20Sopenharmony_ci};
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_cistatic struct attribute sys_gc_force = {
5908c2ecf20Sopenharmony_ci	.name = "gc_force",
5918c2ecf20Sopenharmony_ci	.mode = 0200,
5928c2ecf20Sopenharmony_ci};
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_cistatic struct attribute sys_max_sec_per_write = {
5958c2ecf20Sopenharmony_ci	.name = "max_sec_per_write",
5968c2ecf20Sopenharmony_ci	.mode = 0644,
5978c2ecf20Sopenharmony_ci};
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_cistatic struct attribute sys_write_amp_mileage = {
6008c2ecf20Sopenharmony_ci	.name = "write_amp_mileage",
6018c2ecf20Sopenharmony_ci	.mode = 0444,
6028c2ecf20Sopenharmony_ci};
6038c2ecf20Sopenharmony_ci
6048c2ecf20Sopenharmony_cistatic struct attribute sys_write_amp_trip = {
6058c2ecf20Sopenharmony_ci	.name = "write_amp_trip",
6068c2ecf20Sopenharmony_ci	.mode = 0644,
6078c2ecf20Sopenharmony_ci};
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_cistatic struct attribute sys_padding_dist = {
6108c2ecf20Sopenharmony_ci	.name = "padding_dist",
6118c2ecf20Sopenharmony_ci	.mode = 0644,
6128c2ecf20Sopenharmony_ci};
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_ci#ifdef CONFIG_NVM_PBLK_DEBUG
6158c2ecf20Sopenharmony_cistatic struct attribute sys_stats_debug_attr = {
6168c2ecf20Sopenharmony_ci	.name = "stats",
6178c2ecf20Sopenharmony_ci	.mode = 0444,
6188c2ecf20Sopenharmony_ci};
6198c2ecf20Sopenharmony_ci#endif
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_cistatic struct attribute *pblk_attrs[] = {
6228c2ecf20Sopenharmony_ci	&sys_write_luns,
6238c2ecf20Sopenharmony_ci	&sys_rate_limiter_attr,
6248c2ecf20Sopenharmony_ci	&sys_errors_attr,
6258c2ecf20Sopenharmony_ci	&sys_gc_state,
6268c2ecf20Sopenharmony_ci	&sys_gc_force,
6278c2ecf20Sopenharmony_ci	&sys_max_sec_per_write,
6288c2ecf20Sopenharmony_ci	&sys_rb_attr,
6298c2ecf20Sopenharmony_ci	&sys_stats_ppaf_attr,
6308c2ecf20Sopenharmony_ci	&sys_lines_attr,
6318c2ecf20Sopenharmony_ci	&sys_lines_info_attr,
6328c2ecf20Sopenharmony_ci	&sys_write_amp_mileage,
6338c2ecf20Sopenharmony_ci	&sys_write_amp_trip,
6348c2ecf20Sopenharmony_ci	&sys_padding_dist,
6358c2ecf20Sopenharmony_ci#ifdef CONFIG_NVM_PBLK_DEBUG
6368c2ecf20Sopenharmony_ci	&sys_stats_debug_attr,
6378c2ecf20Sopenharmony_ci#endif
6388c2ecf20Sopenharmony_ci	NULL,
6398c2ecf20Sopenharmony_ci};
6408c2ecf20Sopenharmony_ci
6418c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_show(struct kobject *kobj, struct attribute *attr,
6428c2ecf20Sopenharmony_ci			       char *buf)
6438c2ecf20Sopenharmony_ci{
6448c2ecf20Sopenharmony_ci	struct pblk *pblk = container_of(kobj, struct pblk, kobj);
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_ci	if (strcmp(attr->name, "rate_limiter") == 0)
6478c2ecf20Sopenharmony_ci		return pblk_sysfs_rate_limiter(pblk, buf);
6488c2ecf20Sopenharmony_ci	else if (strcmp(attr->name, "write_luns") == 0)
6498c2ecf20Sopenharmony_ci		return pblk_sysfs_luns_show(pblk, buf);
6508c2ecf20Sopenharmony_ci	else if (strcmp(attr->name, "gc_state") == 0)
6518c2ecf20Sopenharmony_ci		return pblk_sysfs_gc_state_show(pblk, buf);
6528c2ecf20Sopenharmony_ci	else if (strcmp(attr->name, "errors") == 0)
6538c2ecf20Sopenharmony_ci		return pblk_sysfs_stats(pblk, buf);
6548c2ecf20Sopenharmony_ci	else if (strcmp(attr->name, "write_buffer") == 0)
6558c2ecf20Sopenharmony_ci		return pblk_sysfs_write_buffer(pblk, buf);
6568c2ecf20Sopenharmony_ci	else if (strcmp(attr->name, "ppa_format") == 0)
6578c2ecf20Sopenharmony_ci		return pblk_sysfs_ppaf(pblk, buf);
6588c2ecf20Sopenharmony_ci	else if (strcmp(attr->name, "lines") == 0)
6598c2ecf20Sopenharmony_ci		return pblk_sysfs_lines(pblk, buf);
6608c2ecf20Sopenharmony_ci	else if (strcmp(attr->name, "lines_info") == 0)
6618c2ecf20Sopenharmony_ci		return pblk_sysfs_lines_info(pblk, buf);
6628c2ecf20Sopenharmony_ci	else if (strcmp(attr->name, "max_sec_per_write") == 0)
6638c2ecf20Sopenharmony_ci		return pblk_sysfs_get_sec_per_write(pblk, buf);
6648c2ecf20Sopenharmony_ci	else if (strcmp(attr->name, "write_amp_mileage") == 0)
6658c2ecf20Sopenharmony_ci		return pblk_sysfs_get_write_amp_mileage(pblk, buf);
6668c2ecf20Sopenharmony_ci	else if (strcmp(attr->name, "write_amp_trip") == 0)
6678c2ecf20Sopenharmony_ci		return pblk_sysfs_get_write_amp_trip(pblk, buf);
6688c2ecf20Sopenharmony_ci	else if (strcmp(attr->name, "padding_dist") == 0)
6698c2ecf20Sopenharmony_ci		return pblk_sysfs_get_padding_dist(pblk, buf);
6708c2ecf20Sopenharmony_ci#ifdef CONFIG_NVM_PBLK_DEBUG
6718c2ecf20Sopenharmony_ci	else if (strcmp(attr->name, "stats") == 0)
6728c2ecf20Sopenharmony_ci		return pblk_sysfs_stats_debug(pblk, buf);
6738c2ecf20Sopenharmony_ci#endif
6748c2ecf20Sopenharmony_ci	return 0;
6758c2ecf20Sopenharmony_ci}
6768c2ecf20Sopenharmony_ci
6778c2ecf20Sopenharmony_cistatic ssize_t pblk_sysfs_store(struct kobject *kobj, struct attribute *attr,
6788c2ecf20Sopenharmony_ci				const char *buf, size_t len)
6798c2ecf20Sopenharmony_ci{
6808c2ecf20Sopenharmony_ci	struct pblk *pblk = container_of(kobj, struct pblk, kobj);
6818c2ecf20Sopenharmony_ci
6828c2ecf20Sopenharmony_ci	if (strcmp(attr->name, "gc_force") == 0)
6838c2ecf20Sopenharmony_ci		return pblk_sysfs_gc_force(pblk, buf, len);
6848c2ecf20Sopenharmony_ci	else if (strcmp(attr->name, "max_sec_per_write") == 0)
6858c2ecf20Sopenharmony_ci		return pblk_sysfs_set_sec_per_write(pblk, buf, len);
6868c2ecf20Sopenharmony_ci	else if (strcmp(attr->name, "write_amp_trip") == 0)
6878c2ecf20Sopenharmony_ci		return pblk_sysfs_set_write_amp_trip(pblk, buf, len);
6888c2ecf20Sopenharmony_ci	else if (strcmp(attr->name, "padding_dist") == 0)
6898c2ecf20Sopenharmony_ci		return pblk_sysfs_set_padding_dist(pblk, buf, len);
6908c2ecf20Sopenharmony_ci	return 0;
6918c2ecf20Sopenharmony_ci}
6928c2ecf20Sopenharmony_ci
6938c2ecf20Sopenharmony_cistatic const struct sysfs_ops pblk_sysfs_ops = {
6948c2ecf20Sopenharmony_ci	.show = pblk_sysfs_show,
6958c2ecf20Sopenharmony_ci	.store = pblk_sysfs_store,
6968c2ecf20Sopenharmony_ci};
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_cistatic struct kobj_type pblk_ktype = {
6998c2ecf20Sopenharmony_ci	.sysfs_ops	= &pblk_sysfs_ops,
7008c2ecf20Sopenharmony_ci	.default_attrs	= pblk_attrs,
7018c2ecf20Sopenharmony_ci};
7028c2ecf20Sopenharmony_ci
7038c2ecf20Sopenharmony_ciint pblk_sysfs_init(struct gendisk *tdisk)
7048c2ecf20Sopenharmony_ci{
7058c2ecf20Sopenharmony_ci	struct pblk *pblk = tdisk->private_data;
7068c2ecf20Sopenharmony_ci	struct device *parent_dev = disk_to_dev(pblk->disk);
7078c2ecf20Sopenharmony_ci	int ret;
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_ci	ret = kobject_init_and_add(&pblk->kobj, &pblk_ktype,
7108c2ecf20Sopenharmony_ci					kobject_get(&parent_dev->kobj),
7118c2ecf20Sopenharmony_ci					"%s", "pblk");
7128c2ecf20Sopenharmony_ci	if (ret) {
7138c2ecf20Sopenharmony_ci		pblk_err(pblk, "could not register\n");
7148c2ecf20Sopenharmony_ci		return ret;
7158c2ecf20Sopenharmony_ci	}
7168c2ecf20Sopenharmony_ci
7178c2ecf20Sopenharmony_ci	kobject_uevent(&pblk->kobj, KOBJ_ADD);
7188c2ecf20Sopenharmony_ci	return 0;
7198c2ecf20Sopenharmony_ci}
7208c2ecf20Sopenharmony_ci
7218c2ecf20Sopenharmony_civoid pblk_sysfs_exit(struct gendisk *tdisk)
7228c2ecf20Sopenharmony_ci{
7238c2ecf20Sopenharmony_ci	struct pblk *pblk = tdisk->private_data;
7248c2ecf20Sopenharmony_ci
7258c2ecf20Sopenharmony_ci	kobject_uevent(&pblk->kobj, KOBJ_REMOVE);
7268c2ecf20Sopenharmony_ci	kobject_del(&pblk->kobj);
7278c2ecf20Sopenharmony_ci	kobject_put(&pblk->kobj);
7288c2ecf20Sopenharmony_ci}
729