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