xref: /openbmc/linux/include/linux/raid_class.h (revision 60c5fd2e)
182664963SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
261a7afa2SJames Bottomley /*
3b1081ea6SJames Bottomley  * raid_class.h - a generic raid visualisation class
4b1081ea6SJames Bottomley  *
5b1081ea6SJames Bottomley  * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
661a7afa2SJames Bottomley  */
761a7afa2SJames Bottomley #include <linux/transport_class.h>
861a7afa2SJames Bottomley 
961a7afa2SJames Bottomley struct raid_template {
1061a7afa2SJames Bottomley 	struct transport_container raid_attrs;
1161a7afa2SJames Bottomley };
1261a7afa2SJames Bottomley 
1361a7afa2SJames Bottomley struct raid_function_template {
14*e0d3f2c6SBart Van Assche 	const void *cookie;
1561a7afa2SJames Bottomley 	int (*is_raid)(struct device *);
1661a7afa2SJames Bottomley 	void (*get_resync)(struct device *);
1761a7afa2SJames Bottomley 	void (*get_state)(struct device *);
1861a7afa2SJames Bottomley };
1961a7afa2SJames Bottomley 
2061a7afa2SJames Bottomley enum raid_state {
21b1081ea6SJames Bottomley 	RAID_STATE_UNKNOWN = 0,
22b1081ea6SJames Bottomley 	RAID_STATE_ACTIVE,
23b1081ea6SJames Bottomley 	RAID_STATE_DEGRADED,
24b1081ea6SJames Bottomley 	RAID_STATE_RESYNCING,
25b1081ea6SJames Bottomley 	RAID_STATE_OFFLINE,
26b1081ea6SJames Bottomley };
27b1081ea6SJames Bottomley 
28b1081ea6SJames Bottomley enum raid_level {
29b1081ea6SJames Bottomley 	RAID_LEVEL_UNKNOWN = 0,
30b1081ea6SJames Bottomley 	RAID_LEVEL_LINEAR,
31b1081ea6SJames Bottomley 	RAID_LEVEL_0,
32b1081ea6SJames Bottomley 	RAID_LEVEL_1,
338e32ca49SMoore, Eric 	RAID_LEVEL_10,
34f7c95ef0SKashyap, Desai 	RAID_LEVEL_1E,
35b1081ea6SJames Bottomley 	RAID_LEVEL_3,
36b1081ea6SJames Bottomley 	RAID_LEVEL_4,
37b1081ea6SJames Bottomley 	RAID_LEVEL_5,
388e32ca49SMoore, Eric 	RAID_LEVEL_50,
39b1081ea6SJames Bottomley 	RAID_LEVEL_6,
4034e81f7aSHannes Reinecke 	RAID_LEVEL_JBOD,
4161a7afa2SJames Bottomley };
4261a7afa2SJames Bottomley 
4361a7afa2SJames Bottomley struct raid_data {
4461a7afa2SJames Bottomley 	struct list_head component_list;
4561a7afa2SJames Bottomley 	int component_count;
46b1081ea6SJames Bottomley 	enum raid_level level;
4761a7afa2SJames Bottomley 	enum raid_state state;
4861a7afa2SJames Bottomley 	int resync;
4961a7afa2SJames Bottomley };
5061a7afa2SJames Bottomley 
51b1081ea6SJames Bottomley /* resync complete goes from 0 to this */
52b1081ea6SJames Bottomley #define RAID_MAX_RESYNC		(10000)
53b1081ea6SJames Bottomley 
5461a7afa2SJames Bottomley #define DEFINE_RAID_ATTRIBUTE(type, attr)				      \
5561a7afa2SJames Bottomley static inline void							      \
5661a7afa2SJames Bottomley raid_set_##attr(struct raid_template *r, struct device *dev, type value) {    \
57ee959b00STony Jones 	struct device *device =						      \
5861a7afa2SJames Bottomley 		attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
5961a7afa2SJames Bottomley 	struct raid_data *rd;						      \
60ee959b00STony Jones 	BUG_ON(!device);						      \
61ee959b00STony Jones 	rd = dev_get_drvdata(device);					      \
6261a7afa2SJames Bottomley 	rd->attr = value;						      \
6361a7afa2SJames Bottomley }									      \
6461a7afa2SJames Bottomley static inline type							      \
6561a7afa2SJames Bottomley raid_get_##attr(struct raid_template *r, struct device *dev) {		      \
66ee959b00STony Jones 	struct device *device =						      \
6761a7afa2SJames Bottomley 		attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
6861a7afa2SJames Bottomley 	struct raid_data *rd;						      \
69ee959b00STony Jones 	BUG_ON(!device);						      \
70ee959b00STony Jones 	rd = dev_get_drvdata(device);					      \
7161a7afa2SJames Bottomley 	return rd->attr;						      \
7261a7afa2SJames Bottomley }
7361a7afa2SJames Bottomley 
74b1081ea6SJames Bottomley DEFINE_RAID_ATTRIBUTE(enum raid_level, level)
7561a7afa2SJames Bottomley DEFINE_RAID_ATTRIBUTE(int, resync)
7661a7afa2SJames Bottomley DEFINE_RAID_ATTRIBUTE(enum raid_state, state)
7761a7afa2SJames Bottomley 
7861a7afa2SJames Bottomley struct raid_template *raid_class_attach(struct raid_function_template *);
7961a7afa2SJames Bottomley void raid_class_release(struct raid_template *);
80