Commit | Line | Data |
---|---|---|
82664963 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
61a7afa2 | 2 | /* |
b1081ea6 JB |
3 | * raid_class.h - a generic raid visualisation class |
4 | * | |
5 | * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com> | |
61a7afa2 JB |
6 | */ |
7 | #include <linux/transport_class.h> | |
8 | ||
9 | struct raid_template { | |
10 | struct transport_container raid_attrs; | |
11 | }; | |
12 | ||
13 | struct raid_function_template { | |
14 | void *cookie; | |
15 | int (*is_raid)(struct device *); | |
16 | void (*get_resync)(struct device *); | |
17 | void (*get_state)(struct device *); | |
18 | }; | |
19 | ||
20 | enum raid_state { | |
b1081ea6 JB |
21 | RAID_STATE_UNKNOWN = 0, |
22 | RAID_STATE_ACTIVE, | |
23 | RAID_STATE_DEGRADED, | |
24 | RAID_STATE_RESYNCING, | |
25 | RAID_STATE_OFFLINE, | |
26 | }; | |
27 | ||
28 | enum raid_level { | |
29 | RAID_LEVEL_UNKNOWN = 0, | |
30 | RAID_LEVEL_LINEAR, | |
31 | RAID_LEVEL_0, | |
32 | RAID_LEVEL_1, | |
8e32ca49 | 33 | RAID_LEVEL_10, |
f7c95ef0 | 34 | RAID_LEVEL_1E, |
b1081ea6 JB |
35 | RAID_LEVEL_3, |
36 | RAID_LEVEL_4, | |
37 | RAID_LEVEL_5, | |
8e32ca49 | 38 | RAID_LEVEL_50, |
b1081ea6 | 39 | RAID_LEVEL_6, |
34e81f7a | 40 | RAID_LEVEL_JBOD, |
61a7afa2 JB |
41 | }; |
42 | ||
43 | struct raid_data { | |
44 | struct list_head component_list; | |
45 | int component_count; | |
b1081ea6 | 46 | enum raid_level level; |
61a7afa2 JB |
47 | enum raid_state state; |
48 | int resync; | |
49 | }; | |
50 | ||
b1081ea6 JB |
51 | /* resync complete goes from 0 to this */ |
52 | #define RAID_MAX_RESYNC (10000) | |
53 | ||
61a7afa2 JB |
54 | #define DEFINE_RAID_ATTRIBUTE(type, attr) \ |
55 | static inline void \ | |
56 | raid_set_##attr(struct raid_template *r, struct device *dev, type value) { \ | |
ee959b00 | 57 | struct device *device = \ |
61a7afa2 JB |
58 | attribute_container_find_class_device(&r->raid_attrs.ac, dev);\ |
59 | struct raid_data *rd; \ | |
ee959b00 TJ |
60 | BUG_ON(!device); \ |
61 | rd = dev_get_drvdata(device); \ | |
61a7afa2 JB |
62 | rd->attr = value; \ |
63 | } \ | |
64 | static inline type \ | |
65 | raid_get_##attr(struct raid_template *r, struct device *dev) { \ | |
ee959b00 | 66 | struct device *device = \ |
61a7afa2 JB |
67 | attribute_container_find_class_device(&r->raid_attrs.ac, dev);\ |
68 | struct raid_data *rd; \ | |
ee959b00 TJ |
69 | BUG_ON(!device); \ |
70 | rd = dev_get_drvdata(device); \ | |
61a7afa2 JB |
71 | return rd->attr; \ |
72 | } | |
73 | ||
b1081ea6 | 74 | DEFINE_RAID_ATTRIBUTE(enum raid_level, level) |
61a7afa2 JB |
75 | DEFINE_RAID_ATTRIBUTE(int, resync) |
76 | DEFINE_RAID_ATTRIBUTE(enum raid_state, state) | |
77 | ||
78 | struct raid_template *raid_class_attach(struct raid_function_template *); | |
79 | void raid_class_release(struct raid_template *); | |
80 | ||
ed542bed JG |
81 | int __must_check raid_component_add(struct raid_template *, struct device *, |
82 | struct device *); | |
83 |