133965Sjdp/* SPDX-License-Identifier: GPL-2.0 */
233965Sjdp#ifndef S390_CCWGROUP_H
333965Sjdp#define S390_CCWGROUP_H
489857Sobrien
589857Sobrienstruct ccw_device;
689857Sobrienstruct ccw_driver;
789857Sobrien
889857Sobrien/**
989857Sobrien * struct ccwgroup_device - ccw group device
1089857Sobrien * @state: online/offline state
1189857Sobrien * @count: number of attached slave devices
1289857Sobrien * @dev: embedded device structure
1389857Sobrien * @cdev: variable number of slave devices, allocated as needed
1460484Sobrien * @ungroup_work: used to ungroup the ccwgroup device
1560484Sobrien */
1660484Sobrienstruct ccwgroup_device {
1760484Sobrien	enum {
1833965Sjdp		CCWGROUP_OFFLINE,
19218822Sdim		CCWGROUP_ONLINE,
2033965Sjdp	} state;
2133965Sjdp/* private: */
2233965Sjdp	atomic_t onoff;
2333965Sjdp	struct mutex reg_mutex;
2433965Sjdp/* public: */
2533965Sjdp	unsigned int count;
2660484Sobrien	struct device	dev;
2733965Sjdp	struct work_struct ungroup_work;
28	struct ccw_device *cdev[];
29};
30
31/**
32 * struct ccwgroup_driver - driver for ccw group devices
33 * @setup: function called during device creation to setup the device
34 * @remove: function called on remove
35 * @set_online: function called when device is set online
36 * @set_offline: function called when device is set offline
37 * @shutdown: function called when device is shut down
38 * @driver: embedded driver structure
39 * @ccw_driver: supported ccw_driver (optional)
40 */
41struct ccwgroup_driver {
42	int (*setup) (struct ccwgroup_device *);
43	void (*remove) (struct ccwgroup_device *);
44	int (*set_online) (struct ccwgroup_device *);
45	int (*set_offline) (struct ccwgroup_device *);
46	void (*shutdown)(struct ccwgroup_device *);
47
48	struct device_driver driver;
49	struct ccw_driver *ccw_driver;
50};
51
52extern int  ccwgroup_driver_register   (struct ccwgroup_driver *cdriver);
53extern void ccwgroup_driver_unregister (struct ccwgroup_driver *cdriver);
54int ccwgroup_create_dev(struct device *root, struct ccwgroup_driver *gdrv,
55			int num_devices, const char *buf);
56
57extern int ccwgroup_set_online(struct ccwgroup_device *gdev);
58int ccwgroup_set_offline(struct ccwgroup_device *gdev, bool call_gdrv);
59
60extern int ccwgroup_probe_ccwdev(struct ccw_device *cdev);
61extern void ccwgroup_remove_ccwdev(struct ccw_device *cdev);
62
63#define to_ccwgroupdev(x) container_of((x), struct ccwgroup_device, dev)
64#define to_ccwgroupdrv(x) container_of((x), struct ccwgroup_driver, driver)
65
66#if IS_ENABLED(CONFIG_CCWGROUP)
67bool dev_is_ccwgroup(struct device *dev);
68#else /* CONFIG_CCWGROUP */
69static inline bool dev_is_ccwgroup(struct device *dev)
70{
71	return false;
72}
73#endif /* CONFIG_CCWGROUP */
74
75#endif
76