162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef S390_DEVICE_H
362306a36Sopenharmony_ci#define S390_DEVICE_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <asm/ccwdev.h>
662306a36Sopenharmony_ci#include <linux/atomic.h>
762306a36Sopenharmony_ci#include <linux/timer.h>
862306a36Sopenharmony_ci#include <linux/wait.h>
962306a36Sopenharmony_ci#include <linux/notifier.h>
1062306a36Sopenharmony_ci#include <linux/kernel_stat.h>
1162306a36Sopenharmony_ci#include "io_sch.h"
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/*
1462306a36Sopenharmony_ci * states of the device statemachine
1562306a36Sopenharmony_ci */
1662306a36Sopenharmony_cienum dev_state {
1762306a36Sopenharmony_ci	DEV_STATE_NOT_OPER,
1862306a36Sopenharmony_ci	DEV_STATE_SENSE_ID,
1962306a36Sopenharmony_ci	DEV_STATE_OFFLINE,
2062306a36Sopenharmony_ci	DEV_STATE_VERIFY,
2162306a36Sopenharmony_ci	DEV_STATE_ONLINE,
2262306a36Sopenharmony_ci	DEV_STATE_W4SENSE,
2362306a36Sopenharmony_ci	DEV_STATE_DISBAND_PGID,
2462306a36Sopenharmony_ci	DEV_STATE_BOXED,
2562306a36Sopenharmony_ci	/* states to wait for i/o completion before doing something */
2662306a36Sopenharmony_ci	DEV_STATE_TIMEOUT_KILL,
2762306a36Sopenharmony_ci	DEV_STATE_QUIESCE,
2862306a36Sopenharmony_ci	/* special states for devices gone not operational */
2962306a36Sopenharmony_ci	DEV_STATE_DISCONNECTED,
3062306a36Sopenharmony_ci	DEV_STATE_DISCONNECTED_SENSE_ID,
3162306a36Sopenharmony_ci	DEV_STATE_CMFCHANGE,
3262306a36Sopenharmony_ci	DEV_STATE_CMFUPDATE,
3362306a36Sopenharmony_ci	DEV_STATE_STEAL_LOCK,
3462306a36Sopenharmony_ci	/* last element! */
3562306a36Sopenharmony_ci	NR_DEV_STATES
3662306a36Sopenharmony_ci};
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci/*
3962306a36Sopenharmony_ci * asynchronous events of the device statemachine
4062306a36Sopenharmony_ci */
4162306a36Sopenharmony_cienum dev_event {
4262306a36Sopenharmony_ci	DEV_EVENT_NOTOPER,
4362306a36Sopenharmony_ci	DEV_EVENT_INTERRUPT,
4462306a36Sopenharmony_ci	DEV_EVENT_TIMEOUT,
4562306a36Sopenharmony_ci	DEV_EVENT_VERIFY,
4662306a36Sopenharmony_ci	/* last element! */
4762306a36Sopenharmony_ci	NR_DEV_EVENTS
4862306a36Sopenharmony_ci};
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_cistruct ccw_device;
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/*
5362306a36Sopenharmony_ci * action called through jumptable
5462306a36Sopenharmony_ci */
5562306a36Sopenharmony_citypedef void (fsm_func_t)(struct ccw_device *, enum dev_event);
5662306a36Sopenharmony_ciextern fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS];
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_cistatic inline void
5962306a36Sopenharmony_cidev_fsm_event(struct ccw_device *cdev, enum dev_event dev_event)
6062306a36Sopenharmony_ci{
6162306a36Sopenharmony_ci	int state = cdev->private->state;
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci	if (dev_event == DEV_EVENT_INTERRUPT) {
6462306a36Sopenharmony_ci		if (state == DEV_STATE_ONLINE)
6562306a36Sopenharmony_ci			inc_irq_stat(cdev->private->int_class);
6662306a36Sopenharmony_ci		else if (state != DEV_STATE_CMFCHANGE &&
6762306a36Sopenharmony_ci			 state != DEV_STATE_CMFUPDATE)
6862306a36Sopenharmony_ci			inc_irq_stat(IRQIO_CIO);
6962306a36Sopenharmony_ci	}
7062306a36Sopenharmony_ci	dev_jumptable[state][dev_event](cdev, dev_event);
7162306a36Sopenharmony_ci}
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci/*
7462306a36Sopenharmony_ci * Delivers 1 if the device state is final.
7562306a36Sopenharmony_ci */
7662306a36Sopenharmony_cistatic inline int
7762306a36Sopenharmony_cidev_fsm_final_state(struct ccw_device *cdev)
7862306a36Sopenharmony_ci{
7962306a36Sopenharmony_ci	return (cdev->private->state == DEV_STATE_NOT_OPER ||
8062306a36Sopenharmony_ci		cdev->private->state == DEV_STATE_OFFLINE ||
8162306a36Sopenharmony_ci		cdev->private->state == DEV_STATE_ONLINE ||
8262306a36Sopenharmony_ci		cdev->private->state == DEV_STATE_BOXED);
8362306a36Sopenharmony_ci}
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ciint __init io_subchannel_init(void);
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_civoid io_subchannel_recog_done(struct ccw_device *cdev);
8862306a36Sopenharmony_civoid io_subchannel_init_config(struct subchannel *sch);
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ciint ccw_device_cancel_halt_clear(struct ccw_device *);
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ciint ccw_device_is_orphan(struct ccw_device *);
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_civoid ccw_device_recognition(struct ccw_device *);
9562306a36Sopenharmony_ciint ccw_device_online(struct ccw_device *);
9662306a36Sopenharmony_ciint ccw_device_offline(struct ccw_device *);
9762306a36Sopenharmony_civoid ccw_device_update_sense_data(struct ccw_device *);
9862306a36Sopenharmony_ciint ccw_device_test_sense_data(struct ccw_device *);
9962306a36Sopenharmony_ciint ccw_purge_blacklisted(void);
10062306a36Sopenharmony_civoid ccw_device_sched_todo(struct ccw_device *cdev, enum cdev_todo todo);
10162306a36Sopenharmony_cistruct ccw_device *get_ccwdev_by_dev_id(struct ccw_dev_id *dev_id);
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci/* Function prototypes for device status and basic sense stuff. */
10462306a36Sopenharmony_civoid ccw_device_accumulate_irb(struct ccw_device *, struct irb *);
10562306a36Sopenharmony_civoid ccw_device_accumulate_basic_sense(struct ccw_device *, struct irb *);
10662306a36Sopenharmony_ciint ccw_device_accumulate_and_sense(struct ccw_device *, struct irb *);
10762306a36Sopenharmony_ciint ccw_device_do_sense(struct ccw_device *, struct irb *);
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci/* Function prototype for internal request handling. */
11062306a36Sopenharmony_ciint lpm_adjust(int lpm, int mask);
11162306a36Sopenharmony_civoid ccw_request_start(struct ccw_device *);
11262306a36Sopenharmony_ciint ccw_request_cancel(struct ccw_device *cdev);
11362306a36Sopenharmony_civoid ccw_request_handler(struct ccw_device *cdev);
11462306a36Sopenharmony_civoid ccw_request_timeout(struct ccw_device *cdev);
11562306a36Sopenharmony_civoid ccw_request_notoper(struct ccw_device *cdev);
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci/* Function prototypes for sense id stuff. */
11862306a36Sopenharmony_civoid ccw_device_sense_id_start(struct ccw_device *);
11962306a36Sopenharmony_civoid ccw_device_sense_id_done(struct ccw_device *, int);
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci/* Function prototypes for path grouping stuff. */
12262306a36Sopenharmony_civoid ccw_device_verify_start(struct ccw_device *);
12362306a36Sopenharmony_civoid ccw_device_verify_done(struct ccw_device *, int);
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_civoid ccw_device_disband_start(struct ccw_device *);
12662306a36Sopenharmony_civoid ccw_device_disband_done(struct ccw_device *, int);
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ciint ccw_device_stlck(struct ccw_device *);
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci/* Helper function for machine check handling. */
13162306a36Sopenharmony_civoid ccw_device_trigger_reprobe(struct ccw_device *);
13262306a36Sopenharmony_civoid ccw_device_kill_io(struct ccw_device *);
13362306a36Sopenharmony_ciint ccw_device_notify(struct ccw_device *, int);
13462306a36Sopenharmony_civoid ccw_device_set_disconnected(struct ccw_device *cdev);
13562306a36Sopenharmony_civoid ccw_device_set_notoper(struct ccw_device *cdev);
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_civoid ccw_device_timeout(struct timer_list *t);
13862306a36Sopenharmony_civoid ccw_device_set_timeout(struct ccw_device *, int);
13962306a36Sopenharmony_civoid ccw_device_schedule_recovery(void);
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci/* Channel measurement facility related */
14262306a36Sopenharmony_civoid retry_set_schib(struct ccw_device *cdev);
14362306a36Sopenharmony_civoid cmf_retry_copy_block(struct ccw_device *);
14462306a36Sopenharmony_ciint cmf_reenable(struct ccw_device *);
14562306a36Sopenharmony_civoid cmf_reactivate(void);
14662306a36Sopenharmony_ciextern struct device_attribute dev_attr_cmb_enable;
14762306a36Sopenharmony_ci#endif
148