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