Thomas Gleixner | 82c2981 | 2019-05-28 09:57:05 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
James Bottomley | d569d5bb | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Enclosure Services |
| 4 | * |
| 5 | * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com> |
| 6 | * |
| 7 | **----------------------------------------------------------------------------- |
| 8 | ** |
James Bottomley | d569d5bb | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 9 | ** |
| 10 | **----------------------------------------------------------------------------- |
| 11 | */ |
| 12 | #ifndef _LINUX_ENCLOSURE_H_ |
| 13 | #define _LINUX_ENCLOSURE_H_ |
| 14 | |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/list.h> |
| 17 | |
| 18 | /* A few generic types ... taken from ses-2 */ |
| 19 | enum enclosure_component_type { |
| 20 | ENCLOSURE_COMPONENT_DEVICE = 0x01, |
James Bottomley | 5e10335 | 2015-12-11 09:16:38 -0800 | [diff] [blame] | 21 | ENCLOSURE_COMPONENT_CONTROLLER_ELECTRONICS = 0x07, |
| 22 | ENCLOSURE_COMPONENT_SCSI_TARGET_PORT = 0x14, |
| 23 | ENCLOSURE_COMPONENT_SCSI_INITIATOR_PORT = 0x15, |
James Bottomley | d569d5bb | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 24 | ENCLOSURE_COMPONENT_ARRAY_DEVICE = 0x17, |
James Bottomley | 5e10335 | 2015-12-11 09:16:38 -0800 | [diff] [blame] | 25 | ENCLOSURE_COMPONENT_SAS_EXPANDER = 0x18, |
James Bottomley | d569d5bb | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | /* ses-2 common element status */ |
| 29 | enum enclosure_status { |
| 30 | ENCLOSURE_STATUS_UNSUPPORTED = 0, |
| 31 | ENCLOSURE_STATUS_OK, |
| 32 | ENCLOSURE_STATUS_CRITICAL, |
| 33 | ENCLOSURE_STATUS_NON_CRITICAL, |
| 34 | ENCLOSURE_STATUS_UNRECOVERABLE, |
| 35 | ENCLOSURE_STATUS_NOT_INSTALLED, |
| 36 | ENCLOSURE_STATUS_UNKNOWN, |
| 37 | ENCLOSURE_STATUS_UNAVAILABLE, |
James Bottomley | cc9b2e9 | 2009-11-26 09:50:20 -0600 | [diff] [blame] | 38 | /* last element for counting purposes */ |
| 39 | ENCLOSURE_STATUS_MAX |
James Bottomley | d569d5bb | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | /* SFF-8485 activity light settings */ |
| 43 | enum enclosure_component_setting { |
| 44 | ENCLOSURE_SETTING_DISABLED = 0, |
| 45 | ENCLOSURE_SETTING_ENABLED = 1, |
| 46 | ENCLOSURE_SETTING_BLINK_A_ON_OFF = 2, |
| 47 | ENCLOSURE_SETTING_BLINK_A_OFF_ON = 3, |
| 48 | ENCLOSURE_SETTING_BLINK_B_ON_OFF = 6, |
| 49 | ENCLOSURE_SETTING_BLINK_B_OFF_ON = 7, |
| 50 | }; |
| 51 | |
| 52 | struct enclosure_device; |
| 53 | struct enclosure_component; |
| 54 | struct enclosure_component_callbacks { |
| 55 | void (*get_status)(struct enclosure_device *, |
| 56 | struct enclosure_component *); |
| 57 | int (*set_status)(struct enclosure_device *, |
| 58 | struct enclosure_component *, |
| 59 | enum enclosure_status); |
| 60 | void (*get_fault)(struct enclosure_device *, |
| 61 | struct enclosure_component *); |
| 62 | int (*set_fault)(struct enclosure_device *, |
| 63 | struct enclosure_component *, |
| 64 | enum enclosure_component_setting); |
| 65 | void (*get_active)(struct enclosure_device *, |
| 66 | struct enclosure_component *); |
| 67 | int (*set_active)(struct enclosure_device *, |
| 68 | struct enclosure_component *, |
| 69 | enum enclosure_component_setting); |
| 70 | void (*get_locate)(struct enclosure_device *, |
| 71 | struct enclosure_component *); |
| 72 | int (*set_locate)(struct enclosure_device *, |
| 73 | struct enclosure_component *, |
| 74 | enum enclosure_component_setting); |
Song Liu | 0802488 | 2014-12-30 14:46:18 -0800 | [diff] [blame] | 75 | void (*get_power_status)(struct enclosure_device *, |
| 76 | struct enclosure_component *); |
| 77 | int (*set_power_status)(struct enclosure_device *, |
| 78 | struct enclosure_component *, |
| 79 | int); |
Dan Williams | 967f7ba | 2014-12-30 14:46:16 -0800 | [diff] [blame] | 80 | int (*show_id)(struct enclosure_device *, char *buf); |
James Bottomley | d569d5bb | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | |
| 84 | struct enclosure_component { |
| 85 | void *scratch; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 86 | struct device cdev; |
| 87 | struct device *dev; |
James Bottomley | d569d5bb | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 88 | enum enclosure_component_type type; |
| 89 | int number; |
| 90 | int fault; |
| 91 | int active; |
| 92 | int locate; |
Dan Williams | 921ce7f | 2014-12-30 14:46:17 -0800 | [diff] [blame] | 93 | int slot; |
James Bottomley | d569d5bb | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 94 | enum enclosure_status status; |
Song Liu | 0802488 | 2014-12-30 14:46:18 -0800 | [diff] [blame] | 95 | int power_status; |
James Bottomley | d569d5bb | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | struct enclosure_device { |
| 99 | void *scratch; |
| 100 | struct list_head node; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 101 | struct device edev; |
James Bottomley | d569d5bb | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 102 | struct enclosure_component_callbacks *cb; |
| 103 | int components; |
| 104 | struct enclosure_component component[0]; |
| 105 | }; |
| 106 | |
| 107 | static inline struct enclosure_device * |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 108 | to_enclosure_device(struct device *dev) |
James Bottomley | d569d5bb | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 109 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 110 | return container_of(dev, struct enclosure_device, edev); |
James Bottomley | d569d5bb | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | static inline struct enclosure_component * |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 114 | to_enclosure_component(struct device *dev) |
James Bottomley | d569d5bb | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 115 | { |
| 116 | return container_of(dev, struct enclosure_component, cdev); |
| 117 | } |
| 118 | |
| 119 | struct enclosure_device * |
| 120 | enclosure_register(struct device *, const char *, int, |
| 121 | struct enclosure_component_callbacks *); |
| 122 | void enclosure_unregister(struct enclosure_device *); |
| 123 | struct enclosure_component * |
Dan Williams | ed09dcc | 2014-12-30 14:46:14 -0800 | [diff] [blame] | 124 | enclosure_component_alloc(struct enclosure_device *, unsigned int, |
| 125 | enum enclosure_component_type, const char *); |
| 126 | int enclosure_component_register(struct enclosure_component *); |
James Bottomley | d569d5bb | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 127 | int enclosure_add_device(struct enclosure_device *enclosure, int component, |
| 128 | struct device *dev); |
James Bottomley | 43d8eb9 | 2009-08-01 00:41:22 +0000 | [diff] [blame] | 129 | int enclosure_remove_device(struct enclosure_device *, struct device *); |
James Bottomley | 163f52b | 2009-08-01 00:39:36 +0000 | [diff] [blame] | 130 | struct enclosure_device *enclosure_find(struct device *dev, |
| 131 | struct enclosure_device *start); |
James Bottomley | d569d5bb | 2008-02-03 15:40:56 -0600 | [diff] [blame] | 132 | int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *), |
| 133 | void *data); |
| 134 | |
| 135 | #endif /* _LINUX_ENCLOSURE_H_ */ |