xref: /openbmc/linux/drivers/s390/cio/device.h (revision 36fe4655)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef S390_DEVICE_H
3 #define S390_DEVICE_H
4 
5 #include <asm/ccwdev.h>
6 #include <linux/atomic.h>
7 #include <linux/timer.h>
8 #include <linux/wait.h>
9 #include <linux/notifier.h>
10 #include <linux/kernel_stat.h>
11 #include "io_sch.h"
12 
13 /*
14  * states of the device statemachine
15  */
16 enum dev_state {
17 	DEV_STATE_NOT_OPER,
18 	DEV_STATE_SENSE_ID,
19 	DEV_STATE_OFFLINE,
20 	DEV_STATE_VERIFY,
21 	DEV_STATE_ONLINE,
22 	DEV_STATE_W4SENSE,
23 	DEV_STATE_DISBAND_PGID,
24 	DEV_STATE_BOXED,
25 	/* states to wait for i/o completion before doing something */
26 	DEV_STATE_TIMEOUT_KILL,
27 	DEV_STATE_QUIESCE,
28 	/* special states for devices gone not operational */
29 	DEV_STATE_DISCONNECTED,
30 	DEV_STATE_DISCONNECTED_SENSE_ID,
31 	DEV_STATE_CMFCHANGE,
32 	DEV_STATE_CMFUPDATE,
33 	DEV_STATE_STEAL_LOCK,
34 	/* last element! */
35 	NR_DEV_STATES
36 };
37 
38 /*
39  * asynchronous events of the device statemachine
40  */
41 enum dev_event {
42 	DEV_EVENT_NOTOPER,
43 	DEV_EVENT_INTERRUPT,
44 	DEV_EVENT_TIMEOUT,
45 	DEV_EVENT_VERIFY,
46 	/* last element! */
47 	NR_DEV_EVENTS
48 };
49 
50 struct ccw_device;
51 
52 /*
53  * action called through jumptable
54  */
55 typedef void (fsm_func_t)(struct ccw_device *, enum dev_event);
56 extern fsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS];
57 
58 static inline void
59 dev_fsm_event(struct ccw_device *cdev, enum dev_event dev_event)
60 {
61 	int state = cdev->private->state;
62 
63 	if (dev_event == DEV_EVENT_INTERRUPT) {
64 		if (state == DEV_STATE_ONLINE)
65 			inc_irq_stat(cdev->private->int_class);
66 		else if (state != DEV_STATE_CMFCHANGE &&
67 			 state != DEV_STATE_CMFUPDATE)
68 			inc_irq_stat(IRQIO_CIO);
69 	}
70 	dev_jumptable[state][dev_event](cdev, dev_event);
71 }
72 
73 /*
74  * Delivers 1 if the device state is final.
75  */
76 static inline int
77 dev_fsm_final_state(struct ccw_device *cdev)
78 {
79 	return (cdev->private->state == DEV_STATE_NOT_OPER ||
80 		cdev->private->state == DEV_STATE_OFFLINE ||
81 		cdev->private->state == DEV_STATE_ONLINE ||
82 		cdev->private->state == DEV_STATE_BOXED);
83 }
84 
85 int __init io_subchannel_init(void);
86 
87 void io_subchannel_recog_done(struct ccw_device *cdev);
88 void io_subchannel_init_config(struct subchannel *sch);
89 
90 int ccw_device_cancel_halt_clear(struct ccw_device *);
91 
92 int ccw_device_is_orphan(struct ccw_device *);
93 
94 void ccw_device_recognition(struct ccw_device *);
95 int ccw_device_online(struct ccw_device *);
96 int ccw_device_offline(struct ccw_device *);
97 void ccw_device_update_sense_data(struct ccw_device *);
98 int ccw_device_test_sense_data(struct ccw_device *);
99 int ccw_purge_blacklisted(void);
100 void ccw_device_sched_todo(struct ccw_device *cdev, enum cdev_todo todo);
101 struct ccw_device *get_ccwdev_by_dev_id(struct ccw_dev_id *dev_id);
102 
103 /* Function prototypes for device status and basic sense stuff. */
104 void ccw_device_accumulate_irb(struct ccw_device *, struct irb *);
105 void ccw_device_accumulate_basic_sense(struct ccw_device *, struct irb *);
106 int ccw_device_accumulate_and_sense(struct ccw_device *, struct irb *);
107 int ccw_device_do_sense(struct ccw_device *, struct irb *);
108 
109 /* Function prototype for internal request handling. */
110 int lpm_adjust(int lpm, int mask);
111 void ccw_request_start(struct ccw_device *);
112 int ccw_request_cancel(struct ccw_device *cdev);
113 void ccw_request_handler(struct ccw_device *cdev);
114 void ccw_request_timeout(struct ccw_device *cdev);
115 void ccw_request_notoper(struct ccw_device *cdev);
116 
117 /* Function prototypes for sense id stuff. */
118 void ccw_device_sense_id_start(struct ccw_device *);
119 void ccw_device_sense_id_done(struct ccw_device *, int);
120 
121 /* Function prototypes for path grouping stuff. */
122 void ccw_device_verify_start(struct ccw_device *);
123 void ccw_device_verify_done(struct ccw_device *, int);
124 
125 void ccw_device_disband_start(struct ccw_device *);
126 void ccw_device_disband_done(struct ccw_device *, int);
127 
128 int ccw_device_stlck(struct ccw_device *);
129 
130 /* Helper function for machine check handling. */
131 void ccw_device_trigger_reprobe(struct ccw_device *);
132 void ccw_device_kill_io(struct ccw_device *);
133 int ccw_device_notify(struct ccw_device *, int);
134 void ccw_device_set_disconnected(struct ccw_device *cdev);
135 void ccw_device_set_notoper(struct ccw_device *cdev);
136 
137 void ccw_device_timeout(struct timer_list *t);
138 void ccw_device_set_timeout(struct ccw_device *, int);
139 void ccw_device_schedule_recovery(void);
140 
141 /* Channel measurement facility related */
142 void retry_set_schib(struct ccw_device *cdev);
143 void cmf_retry_copy_block(struct ccw_device *);
144 int cmf_reenable(struct ccw_device *);
145 void cmf_reactivate(void);
146 extern struct device_attribute dev_attr_cmb_enable;
147 #endif
148