File Index
Files and directories
Sign in
FILE

enclosure.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/enclosure.h C
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * Enclosure Services
  4 *
  5 * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com>
  6 *
  7**-----------------------------------------------------------------------------
  8**
  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 */
 19enum enclosure_component_type {
 20	ENCLOSURE_COMPONENT_DEVICE = 0x01,
 21	ENCLOSURE_COMPONENT_CONTROLLER_ELECTRONICS = 0x07,
 22	ENCLOSURE_COMPONENT_SCSI_TARGET_PORT = 0x14,
 23	ENCLOSURE_COMPONENT_SCSI_INITIATOR_PORT = 0x15,
 24	ENCLOSURE_COMPONENT_ARRAY_DEVICE = 0x17,
 25	ENCLOSURE_COMPONENT_SAS_EXPANDER = 0x18,
 26};
 27
 28/* ses-2 common element status */
 29enum 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,
 38	/* last element for counting purposes */
 39	ENCLOSURE_STATUS_MAX
 40};
 41
 42/* SFF-8485 activity light settings */
 43enum 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
 52struct enclosure_device;
 53struct enclosure_component;
 54struct 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);
 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);
 80	int (*show_id)(struct enclosure_device *, char *buf);
 81};
 82
 83
 84struct enclosure_component {
 85	void *scratch;
 86	struct device cdev;
 87	struct device *dev;
 88	enum enclosure_component_type type;
 89	int number;
 90	int fault;
 91	int active;
 92	int locate;
 93	int slot;
 94	enum enclosure_status status;
 95	int power_status;
 96};
 97
 98struct enclosure_device {
 99	void *scratch;
100	struct list_head node;
101	struct device edev;
102	struct enclosure_component_callbacks *cb;
103	int components;
104	struct enclosure_component component[];
105};
106
107static inline struct enclosure_device *
108to_enclosure_device(struct device *dev)
109{
110	return container_of(dev, struct enclosure_device, edev);
111}
112
113static inline struct enclosure_component *
114to_enclosure_component(struct device *dev)
115{
116	return container_of(dev, struct enclosure_component, cdev);
117}
118
119struct enclosure_device *
120enclosure_register(struct device *, const char *, int,
121		   struct enclosure_component_callbacks *);
122void enclosure_unregister(struct enclosure_device *);
123struct enclosure_component *
124enclosure_component_alloc(struct enclosure_device *, unsigned int,
125			  enum enclosure_component_type, const char *);
126int enclosure_component_register(struct enclosure_component *);
127int enclosure_add_device(struct enclosure_device *enclosure, int component,
128			 struct device *dev);
129int enclosure_remove_device(struct enclosure_device *, struct device *);
130struct enclosure_device *enclosure_find(struct device *dev,
131					struct enclosure_device *start);
132int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
133			      void *data);
134
135#endif /* _LINUX_ENCLOSURE_H_ */
~/ Read-only file preview.