18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef S390_CCWGROUP_H
38c2ecf20Sopenharmony_ci#define S390_CCWGROUP_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_cistruct ccw_device;
68c2ecf20Sopenharmony_cistruct ccw_driver;
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci/**
98c2ecf20Sopenharmony_ci * struct ccwgroup_device - ccw group device
108c2ecf20Sopenharmony_ci * @state: online/offline state
118c2ecf20Sopenharmony_ci * @count: number of attached slave devices
128c2ecf20Sopenharmony_ci * @dev: embedded device structure
138c2ecf20Sopenharmony_ci * @cdev: variable number of slave devices, allocated as needed
148c2ecf20Sopenharmony_ci * @ungroup_work: work to be done when a ccwgroup notifier has action
158c2ecf20Sopenharmony_ci *	type %BUS_NOTIFY_UNBIND_DRIVER
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_cistruct ccwgroup_device {
188c2ecf20Sopenharmony_ci	enum {
198c2ecf20Sopenharmony_ci		CCWGROUP_OFFLINE,
208c2ecf20Sopenharmony_ci		CCWGROUP_ONLINE,
218c2ecf20Sopenharmony_ci	} state;
228c2ecf20Sopenharmony_ci/* private: */
238c2ecf20Sopenharmony_ci	atomic_t onoff;
248c2ecf20Sopenharmony_ci	struct mutex reg_mutex;
258c2ecf20Sopenharmony_ci/* public: */
268c2ecf20Sopenharmony_ci	unsigned int count;
278c2ecf20Sopenharmony_ci	struct device	dev;
288c2ecf20Sopenharmony_ci	struct work_struct ungroup_work;
298c2ecf20Sopenharmony_ci	struct ccw_device *cdev[0];
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/**
338c2ecf20Sopenharmony_ci * struct ccwgroup_driver - driver for ccw group devices
348c2ecf20Sopenharmony_ci * @setup: function called during device creation to setup the device
358c2ecf20Sopenharmony_ci * @remove: function called on remove
368c2ecf20Sopenharmony_ci * @set_online: function called when device is set online
378c2ecf20Sopenharmony_ci * @set_offline: function called when device is set offline
388c2ecf20Sopenharmony_ci * @shutdown: function called when device is shut down
398c2ecf20Sopenharmony_ci * @driver: embedded driver structure
408c2ecf20Sopenharmony_ci * @ccw_driver: supported ccw_driver (optional)
418c2ecf20Sopenharmony_ci */
428c2ecf20Sopenharmony_cistruct ccwgroup_driver {
438c2ecf20Sopenharmony_ci	int (*setup) (struct ccwgroup_device *);
448c2ecf20Sopenharmony_ci	void (*remove) (struct ccwgroup_device *);
458c2ecf20Sopenharmony_ci	int (*set_online) (struct ccwgroup_device *);
468c2ecf20Sopenharmony_ci	int (*set_offline) (struct ccwgroup_device *);
478c2ecf20Sopenharmony_ci	void (*shutdown)(struct ccwgroup_device *);
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	struct device_driver driver;
508c2ecf20Sopenharmony_ci	struct ccw_driver *ccw_driver;
518c2ecf20Sopenharmony_ci};
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ciextern int  ccwgroup_driver_register   (struct ccwgroup_driver *cdriver);
548c2ecf20Sopenharmony_ciextern void ccwgroup_driver_unregister (struct ccwgroup_driver *cdriver);
558c2ecf20Sopenharmony_ciint ccwgroup_create_dev(struct device *root, struct ccwgroup_driver *gdrv,
568c2ecf20Sopenharmony_ci			int num_devices, const char *buf);
578c2ecf20Sopenharmony_cistruct ccwgroup_device *get_ccwgroupdev_by_busid(struct ccwgroup_driver *gdrv,
588c2ecf20Sopenharmony_ci						 char *bus_id);
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ciextern int ccwgroup_set_online(struct ccwgroup_device *gdev);
618c2ecf20Sopenharmony_ciextern int ccwgroup_set_offline(struct ccwgroup_device *gdev);
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ciextern int ccwgroup_probe_ccwdev(struct ccw_device *cdev);
648c2ecf20Sopenharmony_ciextern void ccwgroup_remove_ccwdev(struct ccw_device *cdev);
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define to_ccwgroupdev(x) container_of((x), struct ccwgroup_device, dev)
678c2ecf20Sopenharmony_ci#define to_ccwgroupdrv(x) container_of((x), struct ccwgroup_driver, driver)
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_CCWGROUP)
708c2ecf20Sopenharmony_cibool dev_is_ccwgroup(struct device *dev);
718c2ecf20Sopenharmony_ci#else /* CONFIG_CCWGROUP */
728c2ecf20Sopenharmony_cistatic inline bool dev_is_ccwgroup(struct device *dev)
738c2ecf20Sopenharmony_ci{
748c2ecf20Sopenharmony_ci	return false;
758c2ecf20Sopenharmony_ci}
768c2ecf20Sopenharmony_ci#endif /* CONFIG_CCWGROUP */
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#endif
79