blob: 5cdfcb873a8f0e8b57c265826a639d7264b60804 [file] [log] [blame]
Thomas Gleixner82664962019-06-01 10:08:51 +02001/* SPDX-License-Identifier: GPL-2.0-only */
James Bottomley61a7afa2005-08-16 18:27:34 -05002/*
James Bottomleyb1081ea2005-11-06 11:59:08 -06003 * raid_class.h - a generic raid visualisation class
4 *
5 * Copyright (c) 2005 - James Bottomley <James.Bottomley@steeleye.com>
James Bottomley61a7afa2005-08-16 18:27:34 -05006 */
7#include <linux/transport_class.h>
8
9struct raid_template {
10 struct transport_container raid_attrs;
11};
12
13struct 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
20enum raid_state {
James Bottomleyb1081ea2005-11-06 11:59:08 -060021 RAID_STATE_UNKNOWN = 0,
22 RAID_STATE_ACTIVE,
23 RAID_STATE_DEGRADED,
24 RAID_STATE_RESYNCING,
25 RAID_STATE_OFFLINE,
26};
27
28enum raid_level {
29 RAID_LEVEL_UNKNOWN = 0,
30 RAID_LEVEL_LINEAR,
31 RAID_LEVEL_0,
32 RAID_LEVEL_1,
Moore, Eric8e32ca42006-01-04 14:58:43 -070033 RAID_LEVEL_10,
Kashyap, Desaif7c95ef2009-12-16 18:54:42 +053034 RAID_LEVEL_1E,
James Bottomleyb1081ea2005-11-06 11:59:08 -060035 RAID_LEVEL_3,
36 RAID_LEVEL_4,
37 RAID_LEVEL_5,
Moore, Eric8e32ca42006-01-04 14:58:43 -070038 RAID_LEVEL_50,
James Bottomleyb1081ea2005-11-06 11:59:08 -060039 RAID_LEVEL_6,
Hannes Reinecke34e81f72018-01-24 09:07:58 +010040 RAID_LEVEL_JBOD,
James Bottomley61a7afa2005-08-16 18:27:34 -050041};
42
43struct raid_data {
44 struct list_head component_list;
45 int component_count;
James Bottomleyb1081ea2005-11-06 11:59:08 -060046 enum raid_level level;
James Bottomley61a7afa2005-08-16 18:27:34 -050047 enum raid_state state;
48 int resync;
49};
50
James Bottomleyb1081ea2005-11-06 11:59:08 -060051/* resync complete goes from 0 to this */
52#define RAID_MAX_RESYNC (10000)
53
James Bottomley61a7afa2005-08-16 18:27:34 -050054#define DEFINE_RAID_ATTRIBUTE(type, attr) \
55static inline void \
56raid_set_##attr(struct raid_template *r, struct device *dev, type value) { \
Tony Jonesee959b02008-02-22 00:13:36 +010057 struct device *device = \
James Bottomley61a7afa2005-08-16 18:27:34 -050058 attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
59 struct raid_data *rd; \
Tony Jonesee959b02008-02-22 00:13:36 +010060 BUG_ON(!device); \
61 rd = dev_get_drvdata(device); \
James Bottomley61a7afa2005-08-16 18:27:34 -050062 rd->attr = value; \
63} \
64static inline type \
65raid_get_##attr(struct raid_template *r, struct device *dev) { \
Tony Jonesee959b02008-02-22 00:13:36 +010066 struct device *device = \
James Bottomley61a7afa2005-08-16 18:27:34 -050067 attribute_container_find_class_device(&r->raid_attrs.ac, dev);\
68 struct raid_data *rd; \
Tony Jonesee959b02008-02-22 00:13:36 +010069 BUG_ON(!device); \
70 rd = dev_get_drvdata(device); \
James Bottomley61a7afa2005-08-16 18:27:34 -050071 return rd->attr; \
72}
73
James Bottomleyb1081ea2005-11-06 11:59:08 -060074DEFINE_RAID_ATTRIBUTE(enum raid_level, level)
James Bottomley61a7afa2005-08-16 18:27:34 -050075DEFINE_RAID_ATTRIBUTE(int, resync)
76DEFINE_RAID_ATTRIBUTE(enum raid_state, state)
77
78struct raid_template *raid_class_attach(struct raid_function_template *);
79void raid_class_release(struct raid_template *);
80
Jeff Garziked542be2006-10-04 07:05:11 -040081int __must_check raid_component_add(struct raid_template *, struct device *,
82 struct device *);
83