James Bottomley | d569d5b | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Enclosure Services |
| 3 | * |
| 4 | * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com> |
| 5 | * |
| 6 | **----------------------------------------------------------------------------- |
| 7 | ** |
| 8 | ** This program is free software; you can redistribute it and/or |
| 9 | ** modify it under the terms of the GNU General Public License |
| 10 | ** version 2 as published by the Free Software Foundation. |
| 11 | ** |
| 12 | ** This program is distributed in the hope that it will be useful, |
| 13 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | ** GNU General Public License for more details. |
| 16 | ** |
| 17 | ** You should have received a copy of the GNU General Public License |
| 18 | ** along with this program; if not, write to the Free Software |
| 19 | ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | ** |
| 21 | **----------------------------------------------------------------------------- |
| 22 | */ |
| 23 | #ifndef _LINUX_ENCLOSURE_H_ |
| 24 | #define _LINUX_ENCLOSURE_H_ |
| 25 | |
| 26 | #include <linux/device.h> |
| 27 | #include <linux/list.h> |
| 28 | |
| 29 | /* A few generic types ... taken from ses-2 */ |
| 30 | enum enclosure_component_type { |
| 31 | ENCLOSURE_COMPONENT_DEVICE = 0x01, |
| 32 | ENCLOSURE_COMPONENT_ARRAY_DEVICE = 0x17, |
| 33 | }; |
| 34 | |
| 35 | /* ses-2 common element status */ |
| 36 | enum enclosure_status { |
| 37 | ENCLOSURE_STATUS_UNSUPPORTED = 0, |
| 38 | ENCLOSURE_STATUS_OK, |
| 39 | ENCLOSURE_STATUS_CRITICAL, |
| 40 | ENCLOSURE_STATUS_NON_CRITICAL, |
| 41 | ENCLOSURE_STATUS_UNRECOVERABLE, |
| 42 | ENCLOSURE_STATUS_NOT_INSTALLED, |
| 43 | ENCLOSURE_STATUS_UNKNOWN, |
| 44 | ENCLOSURE_STATUS_UNAVAILABLE, |
James Bottomley | cc9b2e9 | 2009-11-26 09:50:20 -0600 | [diff] [blame] | 45 | /* last element for counting purposes */ |
| 46 | ENCLOSURE_STATUS_MAX |
James Bottomley | d569d5b | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | /* SFF-8485 activity light settings */ |
| 50 | enum enclosure_component_setting { |
| 51 | ENCLOSURE_SETTING_DISABLED = 0, |
| 52 | ENCLOSURE_SETTING_ENABLED = 1, |
| 53 | ENCLOSURE_SETTING_BLINK_A_ON_OFF = 2, |
| 54 | ENCLOSURE_SETTING_BLINK_A_OFF_ON = 3, |
| 55 | ENCLOSURE_SETTING_BLINK_B_ON_OFF = 6, |
| 56 | ENCLOSURE_SETTING_BLINK_B_OFF_ON = 7, |
| 57 | }; |
| 58 | |
| 59 | struct enclosure_device; |
| 60 | struct enclosure_component; |
| 61 | struct enclosure_component_callbacks { |
| 62 | void (*get_status)(struct enclosure_device *, |
| 63 | struct enclosure_component *); |
| 64 | int (*set_status)(struct enclosure_device *, |
| 65 | struct enclosure_component *, |
| 66 | enum enclosure_status); |
| 67 | void (*get_fault)(struct enclosure_device *, |
| 68 | struct enclosure_component *); |
| 69 | int (*set_fault)(struct enclosure_device *, |
| 70 | struct enclosure_component *, |
| 71 | enum enclosure_component_setting); |
| 72 | void (*get_active)(struct enclosure_device *, |
| 73 | struct enclosure_component *); |
| 74 | int (*set_active)(struct enclosure_device *, |
| 75 | struct enclosure_component *, |
| 76 | enum enclosure_component_setting); |
| 77 | void (*get_locate)(struct enclosure_device *, |
| 78 | struct enclosure_component *); |
| 79 | int (*set_locate)(struct enclosure_device *, |
| 80 | struct enclosure_component *, |
| 81 | enum enclosure_component_setting); |
Song Liu | 0802488 | 2014-12-30 14:46:18 -0800 | [diff] [blame] | 82 | void (*get_power_status)(struct enclosure_device *, |
| 83 | struct enclosure_component *); |
| 84 | int (*set_power_status)(struct enclosure_device *, |
| 85 | struct enclosure_component *, |
| 86 | int); |
Dan Williams | 967f7ba | 2014-12-30 14:46:16 -0800 | [diff] [blame] | 87 | int (*show_id)(struct enclosure_device *, char *buf); |
James Bottomley | d569d5b | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | |
| 91 | struct enclosure_component { |
| 92 | void *scratch; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 93 | struct device cdev; |
| 94 | struct device *dev; |
James Bottomley | d569d5b | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 95 | enum enclosure_component_type type; |
| 96 | int number; |
| 97 | int fault; |
| 98 | int active; |
| 99 | int locate; |
Dan Williams | 921ce7f | 2014-12-30 14:46:17 -0800 | [diff] [blame] | 100 | int slot; |
James Bottomley | d569d5b | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 101 | enum enclosure_status status; |
Song Liu | 0802488 | 2014-12-30 14:46:18 -0800 | [diff] [blame] | 102 | int power_status; |
James Bottomley | d569d5b | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | struct enclosure_device { |
| 106 | void *scratch; |
| 107 | struct list_head node; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 108 | struct device edev; |
James Bottomley | d569d5b | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 109 | struct enclosure_component_callbacks *cb; |
| 110 | int components; |
| 111 | struct enclosure_component component[0]; |
| 112 | }; |
| 113 | |
| 114 | static inline struct enclosure_device * |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 115 | to_enclosure_device(struct device *dev) |
James Bottomley | d569d5b | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 116 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 117 | return container_of(dev, struct enclosure_device, edev); |
James Bottomley | d569d5b | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | static inline struct enclosure_component * |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 121 | to_enclosure_component(struct device *dev) |
James Bottomley | d569d5b | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 122 | { |
| 123 | return container_of(dev, struct enclosure_component, cdev); |
| 124 | } |
| 125 | |
| 126 | struct enclosure_device * |
| 127 | enclosure_register(struct device *, const char *, int, |
| 128 | struct enclosure_component_callbacks *); |
| 129 | void enclosure_unregister(struct enclosure_device *); |
| 130 | struct enclosure_component * |
Dan Williams | ed09dcc | 2014-12-30 14:46:14 -0800 | [diff] [blame] | 131 | enclosure_component_alloc(struct enclosure_device *, unsigned int, |
| 132 | enum enclosure_component_type, const char *); |
| 133 | int enclosure_component_register(struct enclosure_component *); |
James Bottomley | d569d5b | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 134 | int enclosure_add_device(struct enclosure_device *enclosure, int component, |
| 135 | struct device *dev); |
James Bottomley | 43d8eb9 | 2009-08-01 00:41:22 +0000 | [diff] [blame] | 136 | int enclosure_remove_device(struct enclosure_device *, struct device *); |
James Bottomley | 163f52b | 2009-08-01 00:39:36 +0000 | [diff] [blame] | 137 | struct enclosure_device *enclosure_find(struct device *dev, |
| 138 | struct enclosure_device *start); |
James Bottomley | d569d5b | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 139 | int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *), |
| 140 | void *data); |
| 141 | |
| 142 | #endif /* _LINUX_ENCLOSURE_H_ */ |