xref: /linux/drivers/s390/block/dasd_int.h (revision 25cdc1f63227a1ea69a1ec823a8a860e33299169)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
4  *		    Horst Hummel <Horst.Hummel@de.ibm.com>
5  *		    Martin Schwidefsky <schwidefsky@de.ibm.com>
6  * Bugreports.to..: <Linux390@de.ibm.com>
7  * Copyright IBM Corp. 1999, 2009
8  */
9 
10 #ifndef DASD_INT_H
11 #define DASD_INT_H
12 
13 /* we keep old device allocation scheme; IOW, minors are still in 0..255 */
14 #define DASD_PER_MAJOR (1U << (MINORBITS - DASD_PARTN_BITS))
15 #define DASD_PARTN_MASK ((1 << DASD_PARTN_BITS) - 1)
16 
17 /*
18  * States a dasd device can have:
19  *   new: the dasd_device structure is allocated.
20  *   known: the discipline for the device is identified.
21  *   basic: the device can do basic i/o.
22  *   unfmt: the device could not be analyzed (format is unknown).
23  *   ready: partition detection is done and the device is can do block io.
24  *   online: the device accepts requests from the block device queue.
25  *
26  * Things to do for startup state transitions:
27  *   new -> known: find discipline for the device and create devfs entries.
28  *   known -> basic: request irq line for the device.
29  *   basic -> ready: do the initial analysis, e.g. format detection,
30  *                   do block device setup and detect partitions.
31  *   ready -> online: schedule the device tasklet.
32  * Things to do for shutdown state transitions:
33  *   online -> ready: just set the new device state.
34  *   ready -> basic: flush requests from the block device layer, clear
35  *                   partition information and reset format information.
36  *   basic -> known: terminate all requests and free irq.
37  *   known -> new: remove devfs entries and forget discipline.
38  */
39 
40 #define DASD_STATE_NEW	  0
41 #define DASD_STATE_KNOWN  1
42 #define DASD_STATE_BASIC  2
43 #define DASD_STATE_UNFMT  3
44 #define DASD_STATE_READY  4
45 #define DASD_STATE_ONLINE 5
46 
47 #include <linux/module.h>
48 #include <linux/wait.h>
49 #include <linux/blkdev.h>
50 #include <linux/hdreg.h>
51 #include <linux/interrupt.h>
52 #include <linux/log2.h>
53 #include <asm/ccwdev.h>
54 #include <linux/workqueue.h>
55 #include <asm/debug.h>
56 #include <asm/dasd.h>
57 #include <asm/idals.h>
58 #include <linux/bitops.h>
59 #include <linux/blk-mq.h>
60 
61 /* DASD discipline magic */
62 #define DASD_ECKD_MAGIC 0xC5C3D2C4
63 #define DASD_DIAG_MAGIC 0xC4C9C1C7
64 #define DASD_FBA_MAGIC 0xC6C2C140
65 
66 /*
67  * SECTION: Type definitions
68  */
69 struct dasd_device;
70 struct dasd_block;
71 
72 /* BIT DEFINITIONS FOR SENSE DATA */
73 #define DASD_SENSE_BIT_0 0x80
74 #define DASD_SENSE_BIT_1 0x40
75 #define DASD_SENSE_BIT_2 0x20
76 #define DASD_SENSE_BIT_3 0x10
77 
78 /* BIT DEFINITIONS FOR SIM SENSE */
79 #define DASD_SIM_SENSE 0x0F
80 #define DASD_SIM_MSG_TO_OP 0x03
81 #define DASD_SIM_LOG 0x0C
82 
83 /* lock class for nested cdev lock */
84 #define CDEV_NESTED_FIRST 1
85 #define CDEV_NESTED_SECOND 2
86 
87 /*
88  * SECTION: MACROs for klogd and s390 debug feature (dbf)
89  */
90 #define DBF_DEV_EVENT(d_level, d_device, d_str, d_data...) \
91 do { \
92 	debug_sprintf_event(d_device->debug_area, \
93 			    d_level, \
94 			    d_str "\n", \
95 			    d_data); \
96 } while(0)
97 
98 #define DBF_EVENT(d_level, d_str, d_data...)\
99 do { \
100 	debug_sprintf_event(dasd_debug_area, \
101 			    d_level,\
102 			    d_str "\n", \
103 			    d_data); \
104 } while(0)
105 
106 #define DBF_EVENT_DEVID(d_level, d_cdev, d_str, d_data...)	\
107 do { \
108 	struct ccw_dev_id __dev_id;			\
109 	ccw_device_get_id(d_cdev, &__dev_id);		\
110 	debug_sprintf_event(dasd_debug_area,		\
111 			    d_level,					\
112 			    "0.%x.%04x " d_str "\n",			\
113 			    __dev_id.ssid, __dev_id.devno, d_data);	\
114 } while (0)
115 
116 /* definition of dbf debug levels */
117 #define	DBF_EMERG	0	/* system is unusable			*/
118 #define	DBF_ALERT	1	/* action must be taken immediately	*/
119 #define	DBF_CRIT	2	/* critical conditions			*/
120 #define	DBF_ERR		3	/* error conditions			*/
121 #define	DBF_WARNING	4	/* warning conditions			*/
122 #define	DBF_NOTICE	5	/* normal but significant condition	*/
123 #define	DBF_INFO	6	/* informational			*/
124 #define	DBF_DEBUG	6	/* debug-level messages			*/
125 
126 /* Macro to calculate number of blocks per page */
127 #define BLOCKS_PER_PAGE(blksize) (PAGE_SIZE / blksize)
128 
129 struct dasd_ccw_req {
130 	unsigned int magic;		/* Eye catcher */
131 	int intrc;			/* internal error, e.g. from start_IO */
132 	struct list_head devlist;	/* for dasd_device request queue */
133 	struct list_head blocklist;	/* for dasd_block request queue */
134 	struct dasd_block *block;	/* the originating block device */
135 	struct dasd_device *memdev;	/* the device used to allocate this */
136 	struct dasd_device *startdev;	/* device the request is started on */
137 	struct dasd_device *basedev;	/* base device if no block->base */
138 	void *cpaddr;			/* address of ccw or tcw */
139 	short retries;			/* A retry counter */
140 	unsigned char cpmode;		/* 0 = cmd mode, 1 = itcw */
141 	char status;			/* status of this request */
142 	char lpm;			/* logical path mask */
143 	unsigned long flags;        	/* flags of this request */
144 	struct dasd_queue *dq;
145 	unsigned long starttime;	/* jiffies time of request start */
146 	unsigned long expires;		/* expiration period in jiffies */
147 	void *data;			/* pointer to data area */
148 	struct irb irb;			/* device status in case of an error */
149 	struct dasd_ccw_req *refers;	/* ERP-chain queueing. */
150 	/* optional prepare function called before every start_io, must not sleep */
151 	void (*prepare_io)(struct dasd_ccw_req *cqr);
152 	void *function; 		/* originating ERP action */
153 	void *mem_chunk;
154 
155 	unsigned long buildclk;		/* TOD-clock of request generation */
156 	unsigned long startclk;		/* TOD-clock of request start */
157 	unsigned long stopclk;		/* TOD-clock of request interrupt */
158 	unsigned long endclk;		/* TOD-clock of request termination */
159 
160 	void (*callback)(struct dasd_ccw_req *, void *data);
161 	void *callback_data;
162 	unsigned int proc_bytes;	/* bytes for partial completion */
163 	unsigned int trkcount;		/* count formatted tracks */
164 	void *filldata;			/* address of filler data */
165 	struct dasd_format_entry *format;
166 	sector_t start_trk;
167 	sector_t end_trk;
168 	bool collision;
169 };
170 
171 /*
172  * dasd_ccw_req -> status can be:
173  */
174 #define DASD_CQR_FILLED 	0x00	/* request is ready to be processed */
175 #define DASD_CQR_DONE		0x01	/* request is completed successfully */
176 #define DASD_CQR_NEED_ERP	0x02	/* request needs recovery action */
177 #define DASD_CQR_IN_ERP 	0x03	/* request is in recovery */
178 #define DASD_CQR_FAILED 	0x04	/* request is finally failed */
179 #define DASD_CQR_TERMINATED	0x05	/* request was stopped by driver */
180 #define DASD_CQR_ABORTED	0x06	/* request was replaced and will be deleted */
181 
182 #define DASD_CQR_QUEUED 	0x80	/* request is queued to be processed */
183 #define DASD_CQR_IN_IO		0x81	/* request is currently in IO */
184 #define DASD_CQR_ERROR		0x82	/* request is completed with error */
185 #define DASD_CQR_CLEAR_PENDING	0x83	/* request is clear pending */
186 #define DASD_CQR_CLEARED	0x84	/* request was cleared */
187 #define DASD_CQR_SUCCESS	0x85	/* request was successful */
188 #define DASD_CQR_ABORT		0x86	/* request was replaced and will not be handled */
189 
190 /* default expiration time*/
191 #define DASD_EXPIRES	  300
192 #define DASD_EXPIRES_MAX  40000000
193 #define DASD_RETRIES	  256
194 #define DASD_RETRIES_MAX  32768
195 
196 /* per dasd_ccw_req flags */
197 #define DASD_CQR_FLAGS_USE_ERP   0	/* use ERP for this request */
198 #define DASD_CQR_FLAGS_FAILFAST  1	/* FAILFAST */
199 #define DASD_CQR_VERIFY_PATH	 2	/* path verification request */
200 #define DASD_CQR_ALLOW_SLOCK	 3	/* Try this request even when lock was
201 					 * stolen. Should not be combined with
202 					 * DASD_CQR_FLAGS_USE_ERP
203 					 */
204 /*
205  * The following flags are used to suppress output of certain errors.
206  */
207 #define DASD_CQR_SUPPRESS_NRF	4	/* Suppress 'No Record Found' error */
208 #define DASD_CQR_SUPPRESS_IT	5	/* Suppress 'Invalid Track' error*/
209 #define DASD_CQR_SUPPRESS_IL	6	/* Suppress 'Incorrect Length' error */
210 #define DASD_CQR_SUPPRESS_CR	7	/* Suppress 'Command Reject' error */
211 
212 #define DASD_REQ_PER_DEV 4
213 
214 /* Signature for error recovery functions. */
215 typedef struct dasd_ccw_req *(*dasd_erp_fn_t) (struct dasd_ccw_req *);
216 
217 /*
218  * A single CQR can only contain a maximum of 255 CCWs. It is limited by
219  * the locate record and locate record extended count value which can only hold
220  * 1 Byte max.
221  */
222 #define DASD_CQR_MAX_CCW 255
223 
224 /*
225  * Unique identifier for dasd device.
226  */
227 #define UA_NOT_CONFIGURED  0x00
228 #define UA_BASE_DEVICE	   0x01
229 #define UA_BASE_PAV_ALIAS  0x02
230 #define UA_HYPER_PAV_ALIAS 0x03
231 
232 struct dasd_uid {
233 	__u8 type;
234 	char vendor[4];
235 	char serial[15];
236 	__u16 ssid;
237 	__u8 real_unit_addr;
238 	__u8 base_unit_addr;
239 	char vduit[33];
240 };
241 
242 #define DASD_UID_STRLEN ( /* vendor */ 3 + 1 + /* serial    */ 14 + 1 +	\
243 			  /* SSID   */ 4 + 1 + /* unit addr */ 2 + 1 +	\
244 			  /* vduit */ 32 + 1)
245 
246 /*
247  * PPRC Status data
248  */
249 struct dasd_pprc_header {
250 	__u8 entries;		/* 0     Number of device entries */
251 	__u8 unused;		/* 1     unused */
252 	__u16 entry_length;	/* 2-3   Length of device entry */
253 	__u32 unused2;		/* 4-7   unused */
254 } __packed;
255 
256 struct dasd_pprc_dev_info {
257 	__u8 state;		/* 0       Copy State */
258 	__u8 flags;		/* 1       Flags */
259 	__u8 reserved1[2];	/* 2-3     reserved */
260 	__u8 prim_lss;		/* 4       Primary device LSS */
261 	__u8 primary;		/* 5       Primary device address */
262 	__u8 sec_lss;		/* 6       Secondary device LSS */
263 	__u8 secondary;		/* 7       Secondary device address */
264 	__u16 pprc_id;		/* 8-9     Peer-to-Peer Remote Copy ID */
265 	__u8 reserved2[12];	/* 10-21   reserved */
266 	__u16 prim_cu_ssid;	/* 22-23   Primary Control Unit SSID */
267 	__u8 reserved3[12];	/* 24-35   reserved */
268 	__u16 sec_cu_ssid;	/* 36-37   Secondary Control Unit SSID */
269 	__u8 reserved4[90];	/* 38-127  reserved */
270 } __packed;
271 
272 struct dasd_pprc_data_sc4 {
273 	struct dasd_pprc_header header;
274 	struct dasd_pprc_dev_info dev_info[5];
275 } __packed;
276 
277 #define DASD_BUS_ID_SIZE 20
278 #define DASD_CP_ENTRIES 5
279 
280 struct dasd_copy_entry {
281 	char busid[DASD_BUS_ID_SIZE];
282 	struct dasd_device *device;
283 	bool primary;
284 	bool configured;
285 };
286 
287 struct dasd_copy_relation {
288 	struct dasd_copy_entry entry[DASD_CP_ENTRIES];
289 	struct dasd_copy_entry *active;
290 };
291 
292 int dasd_devmap_set_device_copy_relation(struct ccw_device *,
293 					 bool pprc_enabled);
294 
295 /*
296  * the struct dasd_discipline is
297  * sth like a table of virtual functions, if you think of dasd_eckd
298  * inheriting dasd...
299  * no, currently we are not planning to reimplement the driver in C++
300  */
301 struct dasd_discipline {
302 	struct module *owner;
303 	char ebcname[8];	/* a name used for tagging and printks */
304 	char name[8];		/* a name used for tagging and printks */
305 	bool has_discard;
306 
307 	struct list_head list;	/* used for list of disciplines */
308 
309 	/*
310 	 * Device recognition functions. check_device is used to verify
311 	 * the sense data and the information returned by read device
312 	 * characteristics. It returns 0 if the discipline can be used
313 	 * for the device in question. uncheck_device is called during
314 	 * device shutdown to deregister a device from its discipline.
315 	 */
316 	int (*check_device) (struct dasd_device *);
317 	void (*uncheck_device) (struct dasd_device *);
318 
319 	/*
320 	 * do_analysis is used in the step from device state "basic" to
321 	 * state "accept". It returns 0 if the device can be made ready,
322 	 * it returns -EMEDIUMTYPE if the device can't be made ready or
323 	 * -EAGAIN if do_analysis started a ccw that needs to complete
324 	 * before the analysis may be repeated.
325 	 */
326 	int (*do_analysis) (struct dasd_block *);
327 
328 	/*
329 	 * This function is called, when new paths become available.
330 	 * Disciplins may use this callback to do necessary setup work,
331 	 * e.g. verify that new path is compatible with the current
332 	 * configuration.
333 	 */
334 	int (*pe_handler)(struct dasd_device *, __u8, __u8);
335 
336 	/*
337 	 * Last things to do when a device is set online, and first things
338 	 * when it is set offline.
339 	 */
340 	int (*basic_to_ready) (struct dasd_device *);
341 	int (*online_to_ready) (struct dasd_device *);
342 	int (*basic_to_known)(struct dasd_device *);
343 
344 	unsigned int (*max_sectors)(struct dasd_block *);
345 	/* (struct dasd_device *);
346 	 * Device operation functions. build_cp creates a ccw chain for
347 	 * a block device request, start_io starts the request and
348 	 * term_IO cancels it (e.g. in case of a timeout). format_device
349 	 * formats the device and check_device_format compares the format of
350 	 * a device with the expected format_data.
351 	 * handle_terminated_request allows to examine a cqr and prepare
352 	 * it for retry.
353 	 */
354 	struct dasd_ccw_req *(*build_cp) (struct dasd_device *,
355 					  struct dasd_block *,
356 					  struct request *);
357 	int (*start_IO) (struct dasd_ccw_req *);
358 	int (*term_IO) (struct dasd_ccw_req *);
359 	void (*handle_terminated_request) (struct dasd_ccw_req *);
360 	int (*format_device) (struct dasd_device *,
361 			      struct format_data_t *, int);
362 	int (*check_device_format)(struct dasd_device *,
363 				   struct format_check_t *, int);
364 	int (*free_cp) (struct dasd_ccw_req *, struct request *);
365 
366 	/*
367 	 * Error recovery functions. examine_error() returns a value that
368 	 * indicates what to do for an error condition. If examine_error()
369 	 * returns 'dasd_era_recover' erp_action() is called to create a
370 	 * special error recovery ccw. erp_postaction() is called after
371 	 * an error recovery ccw has finished its execution. dump_sense
372 	 * is called for every error condition to print the sense data
373 	 * to the console.
374 	 */
375 	dasd_erp_fn_t(*erp_action) (struct dasd_ccw_req *);
376 	dasd_erp_fn_t(*erp_postaction) (struct dasd_ccw_req *);
377 	void (*dump_sense) (struct dasd_device *, struct dasd_ccw_req *,
378 			    struct irb *);
379 	void (*dump_sense_dbf) (struct dasd_device *, struct irb *, char *);
380 	void (*check_for_device_change) (struct dasd_device *,
381 					 struct dasd_ccw_req *,
382 					 struct irb *);
383 
384         /* i/o control functions. */
385 	int (*fill_geometry) (struct dasd_block *, struct hd_geometry *);
386 	int (*fill_info) (struct dasd_device *, struct dasd_information2_t *);
387 	int (*ioctl) (struct dasd_block *, unsigned int, void __user *);
388 
389 	/* reload device after state change */
390 	int (*reload) (struct dasd_device *);
391 
392 	int (*get_uid) (struct dasd_device *, struct dasd_uid *);
393 	void (*kick_validate) (struct dasd_device *);
394 	int (*check_attention)(struct dasd_device *, __u8);
395 	int (*host_access_count)(struct dasd_device *);
396 	int (*hosts_print)(struct dasd_device *, struct seq_file *);
397 	void (*handle_hpf_error)(struct dasd_device *, struct irb *);
398 	void (*disable_hpf)(struct dasd_device *);
399 	int (*hpf_enabled)(struct dasd_device *);
400 	void (*reset_path)(struct dasd_device *, __u8);
401 
402 	/*
403 	 * Extent Space Efficient (ESE) relevant functions
404 	 */
405 	int (*is_ese)(struct dasd_device *);
406 	int (*ese_capable)(struct dasd_device *);
407 	/* Whether the volume is formatted on demand (thin), from the label */
408 	int (*on_demand_format)(struct dasd_device *);
409 	/* Fill discard queue limits */
410 	void (*disc_limits)(struct dasd_block *, struct queue_limits *);
411 	/* Capacity */
412 	int (*space_allocated)(struct dasd_device *);
413 	int (*space_configured)(struct dasd_device *);
414 	int (*logical_capacity)(struct dasd_device *);
415 	int (*release_space)(struct dasd_device *, struct format_data_t *);
416 	/* Extent Pool */
417 	int (*ext_pool_id)(struct dasd_device *);
418 	int (*ext_size)(struct dasd_device *);
419 	int (*ext_pool_cap_at_warnlevel)(struct dasd_device *);
420 	int (*ext_pool_warn_thrshld)(struct dasd_device *);
421 	int (*ext_pool_oos)(struct dasd_device *);
422 	int (*ext_pool_exhaust)(struct dasd_device *, struct dasd_ccw_req *);
423 	void (*ese_format)(struct dasd_device *, struct dasd_ccw_req *, struct irb *);
424 	int (*ese_read)(struct dasd_ccw_req *, struct irb *);
425 	int (*pprc_status)(struct dasd_device *, struct	dasd_pprc_data_sc4 *);
426 	bool (*pprc_enabled)(struct dasd_device *);
427 	int (*copy_pair_swap)(struct dasd_device *, char *, char *);
428 	int (*device_ping)(struct dasd_device *);
429 };
430 
431 extern struct dasd_discipline *dasd_diag_discipline_pointer;
432 
433 /* Trigger IDs for extended error reporting DASD EER and autoquiesce */
434 enum eer_trigger {
435 	DASD_EER_FATALERROR = 1,
436 	DASD_EER_NOPATH,
437 	DASD_EER_STATECHANGE,
438 	DASD_EER_PPRCSUSPEND,
439 	DASD_EER_NOSPC,
440 	DASD_EER_TIMEOUTS,
441 	DASD_EER_STARTIO,
442 
443 	/* enum end marker, only add new trigger above */
444 	DASD_EER_MAX,
445 	DASD_EER_AUTOQUIESCE = 31, /* internal only */
446 };
447 
448 #define DASD_EER_VALID ((1U << DASD_EER_MAX) - 1)
449 
450 /* DASD path handling */
451 
452 #define DASD_PATH_OPERATIONAL  1
453 #define DASD_PATH_TBV	       2
454 #define DASD_PATH_PP	       3
455 #define DASD_PATH_NPP	       4
456 #define DASD_PATH_MISCABLED    5
457 #define DASD_PATH_NOHPF        6
458 #define DASD_PATH_CUIR	       7
459 #define DASD_PATH_IFCC	       8
460 #define DASD_PATH_FCSEC	       9
461 
462 #define DASD_THRHLD_MAX		4294967295U
463 #define DASD_INTERVAL_MAX	4294967295U
464 
465 /* FC Endpoint Security Capabilities */
466 #define DASD_FC_SECURITY_UNSUP		0
467 #define DASD_FC_SECURITY_AUTH		1
468 #define DASD_FC_SECURITY_ENC_FCSP2	2
469 #define DASD_FC_SECURITY_ENC_ERAS	3
470 
471 #define DASD_FC_SECURITY_ENC_STR	"Encryption"
472 static const struct {
473 	u8 value;
474 	char *name;
475 } dasd_path_fcs_mnemonics[] = {
476 	{ DASD_FC_SECURITY_UNSUP,	"Unsupported" },
477 	{ DASD_FC_SECURITY_AUTH,	"Authentication" },
478 	{ DASD_FC_SECURITY_ENC_FCSP2,	DASD_FC_SECURITY_ENC_STR },
479 	{ DASD_FC_SECURITY_ENC_ERAS,	DASD_FC_SECURITY_ENC_STR },
480 };
481 
482 static inline char *dasd_path_get_fcs_str(int val)
483 {
484 	int i;
485 
486 	for (i = 0; i < ARRAY_SIZE(dasd_path_fcs_mnemonics); i++) {
487 		if (dasd_path_fcs_mnemonics[i].value == val)
488 			return dasd_path_fcs_mnemonics[i].name;
489 	}
490 
491 	return dasd_path_fcs_mnemonics[0].name;
492 }
493 
494 struct dasd_path {
495 	unsigned long flags;
496 	u8 cssid;
497 	u8 ssid;
498 	u8 chpid;
499 	struct dasd_conf_data *conf_data;
500 	atomic_t error_count;
501 	unsigned long errorclk;
502 	u8 fc_security;
503 	struct kobject kobj;
504 	bool in_sysfs;
505 };
506 
507 #define to_dasd_path(path) container_of(path, struct dasd_path, kobj)
508 
509 static inline void dasd_path_release(struct kobject *kobj)
510 {
511 /* Memory for the dasd_path kobject is freed when dasd_free_device() is called */
512 }
513 
514 
515 struct dasd_profile_info {
516 	/* legacy part of profile data, as in dasd_profile_info_t */
517 	unsigned int dasd_io_reqs;	 /* number of requests processed */
518 	unsigned int dasd_io_sects;	 /* number of sectors processed */
519 	unsigned int dasd_io_secs[32];	 /* histogram of request's sizes */
520 	unsigned int dasd_io_times[32];	 /* histogram of requests's times */
521 	unsigned int dasd_io_timps[32];	 /* h. of requests's times per sector */
522 	unsigned int dasd_io_time1[32];	 /* hist. of time from build to start */
523 	unsigned int dasd_io_time2[32];	 /* hist. of time from start to irq */
524 	unsigned int dasd_io_time2ps[32]; /* hist. of time from start to irq */
525 	unsigned int dasd_io_time3[32];	 /* hist. of time from irq to end */
526 	unsigned int dasd_io_nr_req[32]; /* hist. of # of requests in chanq */
527 
528 	/* new data */
529 	struct timespec64 starttod;	   /* time of start or last reset */
530 	unsigned int dasd_io_alias;	   /* requests using an alias */
531 	unsigned int dasd_io_tpm;	   /* requests using transport mode */
532 	unsigned int dasd_read_reqs;	   /* total number of read  requests */
533 	unsigned int dasd_read_sects;	   /* total number read sectors */
534 	unsigned int dasd_read_alias;	   /* read request using an alias */
535 	unsigned int dasd_read_tpm;	   /* read requests in transport mode */
536 	unsigned int dasd_read_secs[32];   /* histogram of request's sizes */
537 	unsigned int dasd_read_times[32];  /* histogram of requests's times */
538 	unsigned int dasd_read_time1[32];  /* hist. time from build to start */
539 	unsigned int dasd_read_time2[32];  /* hist. of time from start to irq */
540 	unsigned int dasd_read_time3[32];  /* hist. of time from irq to end */
541 	unsigned int dasd_read_nr_req[32]; /* hist. of # of requests in chanq */
542 	unsigned long dasd_sum_times;	   /* sum of request times */
543 	unsigned long dasd_sum_time_str;   /* sum of time from build to start */
544 	unsigned long dasd_sum_time_irq;   /* sum of time from start to irq */
545 	unsigned long dasd_sum_time_end;   /* sum of time from irq to end */
546 };
547 
548 struct dasd_profile {
549 	struct dentry *dentry;
550 	struct dasd_profile_info *data;
551 	spinlock_t lock;
552 };
553 
554 /*
555  * concurrent ESE format ranges in flight; also caps a WRITE_FULL_TRACK's
556  * track count, which the LRE track bitmask limits to 16
557  */
558 #define DASD_NR_FORMAT_ENTRIES	16
559 
560 struct dasd_format_entry {
561 	struct list_head list;
562 	struct dasd_ccw_req *cqr;
563 	sector_t start_trk;
564 	sector_t end_trk;
565 };
566 
567 struct dasd_device {
568 	/* Block device stuff. */
569 	struct dasd_block *block;
570 
571         unsigned int devindex;
572 	unsigned long flags;	   /* per device flags */
573 	unsigned short features;   /* copy of devmap-features (read-only!) */
574 
575 	/* extended error reporting stuff (eer) */
576 	struct dasd_ccw_req *eer_cqr;
577 
578 	/* Device discipline stuff. */
579 	struct dasd_discipline *discipline;
580 	struct dasd_discipline *base_discipline;
581 	void *private;
582 	struct dasd_path path[8];
583 	__u8 opm;
584 
585 	/* Device state and target state. */
586 	int state, target;
587 	struct mutex state_mutex;
588 	int stopped;		/* device (ccw_device_start) was stopped */
589 
590 	/* reference count. */
591         atomic_t ref_count;
592 
593 	/* ccw queue and memory for static ccw/erp buffers. */
594 	struct list_head ccw_queue;
595 	spinlock_t mem_lock;
596 	void *ccw_mem;
597 	void *fill_mem;
598 	void *erp_mem;
599 	void *ese_mem;
600 	void *nulldata;
601 	struct list_head ccw_chunks;
602 	struct list_head fill_chunks;
603 	struct list_head erp_chunks;
604 	struct list_head ese_chunks;
605 
606 	atomic_t tasklet_scheduled;
607         struct tasklet_struct tasklet;
608 	struct work_struct kick_work;
609 	struct work_struct reload_device;
610 	struct work_struct kick_validate;
611 	struct work_struct suc_work;
612 	struct work_struct requeue_requests;
613 	struct timer_list timer;
614 
615 	debug_info_t *debug_area;
616 
617 	struct ccw_device *cdev;
618 
619 	/* hook for alias management */
620 	struct list_head alias_list;
621 
622 	/* default expiration time in s */
623 	unsigned long default_expires;
624 	unsigned long default_retries;
625 
626 	unsigned long blk_timeout;
627 
628 	unsigned long path_thrhld;
629 	unsigned long path_interval;
630 
631 	struct dentry *debugfs_dentry;
632 	struct dentry *hosts_dentry;
633 	struct dasd_profile profile;
634 	struct dasd_format_entry format_entry[DASD_NR_FORMAT_ENTRIES];
635 	struct kset *paths_info;
636 	struct dasd_copy_relation *copy;
637 	unsigned long aq_mask;
638 	unsigned int aq_timeouts;
639 
640 	/* ESE fulltrack write control (see full_track_bias sysfs attribute) */
641 	unsigned int ft_bias;	/* aggressiveness 0..100: 0=off, 100=always */
642 	unsigned int fulltrack;	/* internal: use WRITE_FULL_TRACK for aligned writes */
643 	/* adaptive heuristic (active for ft_bias 1..99), derived from ft_bias */
644 	unsigned int ese_probe_state;        /* heuristic FSM state */
645 	unsigned int ese_probe_interval;     /* IOs between evaluations */
646 	atomic_t ese_io_cnt;                 /* IO counter for current window */
647 	atomic_t ese_nrf_window;             /* NRF/INV_TRACK_FORMAT events in window */
648 	unsigned int ese_heu_start_interval; /* IOs before first probe */
649 	unsigned int ese_heu_probe_window;   /* IOs in probe window */
650 	unsigned int ese_heu_max_interval;   /* max IOs between probes (backoff cap) */
651 	unsigned int ese_heu_nrf_high;       /* NRF per-mille threshold → activate ft1 */
652 };
653 
654 struct dasd_block {
655 	/* Block device stuff. */
656 	struct gendisk *gdp;
657 	spinlock_t request_queue_lock;
658 	struct blk_mq_tag_set tag_set;
659 	struct file *bdev_file;
660 	atomic_t open_count;
661 
662 	unsigned long blocks;	   /* size of volume in blocks */
663 	unsigned int bp_block;	   /* bytes per block */
664 	unsigned int s2b_shift;	   /* log2 (bp_block/512) */
665 
666 	struct dasd_device *base;
667 	struct list_head ccw_queue;
668 	spinlock_t queue_lock;
669 
670 	atomic_t tasklet_scheduled;
671 	struct tasklet_struct tasklet;
672 	struct timer_list timer;
673 
674 	struct dentry *debugfs_dentry;
675 	struct dasd_profile profile;
676 
677 	struct list_head format_list;
678 	spinlock_t format_lock;
679 	atomic_t trkcount;
680 
681 	/*
682 	 * ESE format CQRs staged from hardirq, spliced into
683 	 * ccw_queue in dasd_block_tasklet under queue_lock. Direct enqueue from
684 	 * the IRQ handler would invert the queue_lock / ccwdev_lock order.
685 	 */
686 	struct list_head ese_staging;
687 	/* lock for ese_staging */
688 	spinlock_t ese_lock;
689 };
690 
691 struct dasd_attention_data {
692 	struct dasd_device *device;
693 	__u8 lpum;
694 };
695 
696 struct dasd_queue {
697 	spinlock_t lock;
698 };
699 
700 /* reasons why device (ccw_device_start) was stopped */
701 #define DASD_STOPPED_NOT_ACC 1         /* not accessible */
702 #define DASD_STOPPED_QUIESCE 2         /* Quiesced */
703 #define DASD_STOPPED_PENDING 4         /* long busy */
704 #define DASD_STOPPED_DC_WAIT 8         /* disconnected, wait */
705 #define DASD_STOPPED_SU      16        /* summary unit check handling */
706 #define DASD_STOPPED_PPRC    32        /* PPRC swap */
707 #define DASD_STOPPED_NOSPC   128       /* no space left */
708 
709 /*
710  * ESE fulltrack write aggressiveness (full_track_bias sysfs attribute), 0..100:
711  *   0   - never use proactively WRITE_FULL_TRACK
712  *   100 - always use proactively WRITE_FULL_TRACK, no probing
713  *   1..99 - adaptive; higher means switch to ft more eagerly
714  * WRITE_FULL_TRACK has an advantage on sparse formatted ESE devices
715  * but it has an overall penalty for maximum throughput for fully
716  * formatted devices.
717  * The default of 50 tries to balance both and do some probing in between
718  * to choose the best mode for default IO.
719  */
720 #define DASD_FT_BIAS_MAX	100
721 #define DASD_FT_BIAS_DEFAULT	50
722 
723 /* ESE fulltrack heuristic FSM states (adaptive range, ft_bias 1..99) */
724 #define DASD_ESE_HEU_FT1_ACTIVE   0   /* fulltrack write active */
725 #define DASD_ESE_HEU_PROBING      1   /* ft0 probe window, measuring NRF rate */
726 #define DASD_ESE_HEU_FT0_STABLE   2   /* device formatted, ft0 active */
727 
728 /*
729  * Heuristic parameters are derived from ft_bias by linear interpolation,
730  * anchored so that ft_bias == 50 reproduces the previously shipped defaults
731  * and ft_bias == 100 is the most aggressive end of the range.
732  * probe_window is constant.
733  */
734 #define DASD_ESE_HEU_PROBE_WINDOW	   100
735 #define DASD_ESE_HEU_NRF_HIGH_A50	    10	/* NRF per-mille threshold */
736 #define DASD_ESE_HEU_NRF_HIGH_A100	     1
737 #define DASD_ESE_HEU_START_A50		  2000	/* IOs before first probe */
738 #define DASD_ESE_HEU_START_A100		   500
739 #define DASD_ESE_HEU_MAX_A50		500000	/* backoff cap */
740 #define DASD_ESE_HEU_MAX_A100		 20000
741 
742 /* per device flags */
743 #define DASD_FLAG_OFFLINE	3	/* device is in offline processing */
744 #define DASD_FLAG_EER_SNSS	4	/* A SNSS is required */
745 #define DASD_FLAG_EER_IN_USE	5	/* A SNSS request is running */
746 #define DASD_FLAG_DEVICE_RO	6	/* The device itself is read-only. Don't
747 					 * confuse this with the user specified
748 					 * read-only feature.
749 					 */
750 #define DASD_FLAG_IS_RESERVED	7	/* The device is reserved */
751 #define DASD_FLAG_LOCK_STOLEN	8	/* The device lock was stolen */
752 #define DASD_FLAG_SUSPENDED	9	/* The device was suspended */
753 #define DASD_FLAG_SAFE_OFFLINE	10	/* safe offline processing requested*/
754 #define DASD_FLAG_SAFE_OFFLINE_RUNNING	11	/* safe offline running */
755 #define DASD_FLAG_ABORTALL	12	/* Abort all noretry requests */
756 #define DASD_FLAG_PATH_VERIFY	13	/* Path verification worker running */
757 #define DASD_FLAG_SUC		14	/* unhandled summary unit check */
758 
759 #define DASD_SLEEPON_START_TAG	((void *) 1)
760 #define DASD_SLEEPON_END_TAG	((void *) 2)
761 
762 void dasd_put_device_wake(struct dasd_device *);
763 
764 /*
765  * return values to be returned from the copy pair swap function
766  * 0x00: swap successful
767  * 0x01: swap data invalid
768  * 0x02: no active device found
769  * 0x03: wrong primary specified
770  * 0x04: secondary device not found
771  * 0x05: swap already running
772  */
773 #define DASD_COPYPAIRSWAP_SUCCESS	0
774 #define DASD_COPYPAIRSWAP_INVALID	1
775 #define DASD_COPYPAIRSWAP_NOACTIVE	2
776 #define DASD_COPYPAIRSWAP_PRIMARY	3
777 #define DASD_COPYPAIRSWAP_SECONDARY	4
778 #define DASD_COPYPAIRSWAP_MULTIPLE	5
779 
780 /*
781  * Reference count inliners
782  */
783 static inline void
784 dasd_get_device(struct dasd_device *device)
785 {
786 	atomic_inc(&device->ref_count);
787 }
788 
789 static inline void
790 dasd_put_device(struct dasd_device *device)
791 {
792 	if (atomic_dec_return(&device->ref_count) == 0)
793 		dasd_put_device_wake(device);
794 }
795 
796 /*
797  * The static memory in ccw_mem and erp_mem is managed by a sorted
798  * list of free memory chunks.
799  */
800 struct dasd_mchunk
801 {
802 	struct list_head list;
803 	unsigned long size;
804 } __attribute__ ((aligned(8)));
805 
806 static inline void
807 dasd_init_chunklist(struct list_head *chunk_list, void *mem,
808 		    unsigned long size)
809 {
810 	struct dasd_mchunk *chunk;
811 
812 	INIT_LIST_HEAD(chunk_list);
813 	chunk = (struct dasd_mchunk *) mem;
814 	chunk->size = size - sizeof(struct dasd_mchunk);
815 	list_add(&chunk->list, chunk_list);
816 }
817 
818 static inline void *
819 dasd_alloc_chunk(struct list_head *chunk_list, unsigned long size)
820 {
821 	struct dasd_mchunk *chunk, *tmp;
822 
823 	size = (size + 7L) & -8L;
824 	list_for_each_entry(chunk, chunk_list, list) {
825 		if (chunk->size < size)
826 			continue;
827 		if (chunk->size > size + sizeof(struct dasd_mchunk)) {
828 			char *endaddr = (char *) (chunk + 1) + chunk->size;
829 			tmp = (struct dasd_mchunk *) (endaddr - size) - 1;
830 			tmp->size = size;
831 			chunk->size -= size + sizeof(struct dasd_mchunk);
832 			chunk = tmp;
833 		} else
834 			list_del(&chunk->list);
835 		return (void *) (chunk + 1);
836 	}
837 	return NULL;
838 }
839 
840 static inline void
841 dasd_free_chunk(struct list_head *chunk_list, void *mem)
842 {
843 	struct dasd_mchunk *chunk, *tmp;
844 	struct list_head *p, *left;
845 
846 	chunk = (struct dasd_mchunk *)
847 		((char *) mem - sizeof(struct dasd_mchunk));
848 	/* Find out the left neighbour in chunk_list. */
849 	left = chunk_list;
850 	list_for_each(p, chunk_list) {
851 		if (list_entry(p, struct dasd_mchunk, list) > chunk)
852 			break;
853 		left = p;
854 	}
855 	/* Try to merge with right neighbour = next element from left. */
856 	if (left->next != chunk_list) {
857 		tmp = list_entry(left->next, struct dasd_mchunk, list);
858 		if ((char *) (chunk + 1) + chunk->size == (char *) tmp) {
859 			list_del(&tmp->list);
860 			chunk->size += tmp->size + sizeof(struct dasd_mchunk);
861 		}
862 	}
863 	/* Try to merge with left neighbour. */
864 	if (left != chunk_list) {
865 		tmp = list_entry(left, struct dasd_mchunk, list);
866 		if ((char *) (tmp + 1) + tmp->size == (char *) chunk) {
867 			tmp->size += chunk->size + sizeof(struct dasd_mchunk);
868 			return;
869 		}
870 	}
871 	__list_add(&chunk->list, left, left->next);
872 }
873 
874 /*
875  * Check if bsize is in { 512, 1024, 2048, 4096 }
876  */
877 static inline int
878 dasd_check_blocksize(int bsize)
879 {
880 	if (bsize < 512 || bsize > 4096 || !is_power_of_2(bsize))
881 		return -EMEDIUMTYPE;
882 	return 0;
883 }
884 
885 /*
886  * return the callback data of the original request in case there are
887  * ERP requests build on top of it
888  */
889 static inline void *dasd_get_callback_data(struct dasd_ccw_req *cqr)
890 {
891 	while (cqr->refers)
892 		cqr = cqr->refers;
893 
894 	return cqr->callback_data;
895 }
896 
897 /*
898  * Walk down the ERP chain to the original CQR and call its
899  * prepare_io function if set.
900  */
901 static inline void dasd_start_IO_prepare(struct dasd_ccw_req *cqr)
902 {
903 	/* ERP requests use the prepare function of the original request */
904 	while (cqr->refers)
905 		cqr = cqr->refers;
906 	if (cqr->prepare_io)
907 		cqr->prepare_io(cqr);
908 }
909 
910 static inline bool dasd_req_conflict(struct dasd_ccw_req *cqr1,
911 				     struct dasd_ccw_req *cqr2)
912 {
913 	return !(cqr1->format->end_trk < cqr2->start_trk ||
914 		 cqr2->end_trk < cqr1->format->start_trk);
915 }
916 
917 /*
918  * true when device is ese device and ft_bias selects the adaptive
919  * heuristic (neither hard endpoint)
920  */
921 static inline bool dasd_ese_adaptive(struct dasd_device *device)
922 {
923 	return device->discipline &&
924 		device->discipline->is_ese &&
925 		device->discipline->is_ese(device) &&
926 		device->ft_bias > 0 &&
927 		device->ft_bias < DASD_FT_BIAS_MAX;
928 }
929 
930 /*
931  * Linear interpolation of a heuristic parameter between its value at aggr==50
932  * (v50) and its value at aggr==100 (v100).
933  */
934 static inline unsigned int dasd_ese_lerp(unsigned int v50, unsigned int v100,
935 					 unsigned int aggr)
936 {
937 	return (unsigned int)((int)v50 +
938 		((int)v100 - (int)v50) * ((int)aggr - 50) / 50);
939 }
940 
941 /*
942  * Apply the ft_bias knob. For the hard endpoints just pin the mode; for the
943  * adaptive range derive the heuristic parameters from ft_bias and (re)start
944  * the FSM in ft1 so a freshly sparse device avoids the NRF penalty right away.
945  */
946 static inline void dasd_ft_bias_apply(struct dasd_device *device)
947 {
948 	unsigned int a = device->ft_bias;
949 
950 	if (!dasd_ese_adaptive(device)) {
951 		device->fulltrack = (a >= DASD_FT_BIAS_MAX) ? 1 : 0;
952 		device->ese_probe_state = DASD_ESE_HEU_FT1_ACTIVE;
953 		return;
954 	}
955 
956 	device->ese_heu_nrf_high =
957 		dasd_ese_lerp(DASD_ESE_HEU_NRF_HIGH_A50,
958 			      DASD_ESE_HEU_NRF_HIGH_A100, a);
959 	device->ese_heu_start_interval =
960 		dasd_ese_lerp(DASD_ESE_HEU_START_A50,
961 			      DASD_ESE_HEU_START_A100, a);
962 	device->ese_heu_max_interval =
963 		dasd_ese_lerp(DASD_ESE_HEU_MAX_A50,
964 			      DASD_ESE_HEU_MAX_A100, a);
965 	device->ese_heu_probe_window = DASD_ESE_HEU_PROBE_WINDOW;
966 
967 	device->ese_probe_state    = DASD_ESE_HEU_FT1_ACTIVE;
968 	device->ese_probe_interval = device->ese_heu_start_interval;
969 	device->fulltrack          = 1;
970 	atomic_set(&device->ese_io_cnt, 0);
971 	atomic_set(&device->ese_nrf_window, 0);
972 }
973 
974 /* externals in dasd.c */
975 #define DASD_PROFILE_OFF	 0
976 #define DASD_PROFILE_ON 	 1
977 #define DASD_PROFILE_GLOBAL_ONLY 2
978 
979 extern debug_info_t *dasd_debug_area;
980 extern struct dasd_profile dasd_global_profile;
981 extern unsigned int dasd_global_profile_level;
982 extern const struct block_device_operations dasd_device_operations;
983 extern struct blk_mq_ops dasd_mq_ops;
984 
985 extern struct kmem_cache *dasd_page_cache;
986 
987 struct dasd_ccw_req *
988 dasd_smalloc_request(int, int, int, struct dasd_device *, struct dasd_ccw_req *);
989 struct dasd_ccw_req *dasd_fmalloc_request(int, int, int, struct dasd_device *);
990 void dasd_sfree_request(struct dasd_ccw_req *, struct dasd_device *);
991 void dasd_ffree_request(struct dasd_ccw_req *, struct dasd_device *);
992 void dasd_wakeup_cb(struct dasd_ccw_req *, void *);
993 
994 struct dasd_device *dasd_alloc_device(void);
995 void dasd_free_device(struct dasd_device *);
996 
997 struct dasd_block *dasd_alloc_block(void);
998 void dasd_free_block(struct dasd_block *);
999 
1000 enum blk_eh_timer_return dasd_times_out(struct request *req);
1001 
1002 void dasd_enable_device(struct dasd_device *);
1003 void dasd_set_target_state(struct dasd_device *, int);
1004 void dasd_kick_device(struct dasd_device *);
1005 void dasd_reload_device(struct dasd_device *);
1006 void dasd_schedule_requeue(struct dasd_device *);
1007 
1008 void dasd_add_request_head(struct dasd_ccw_req *);
1009 void dasd_add_request_tail(struct dasd_ccw_req *);
1010 int  dasd_start_IO(struct dasd_ccw_req *);
1011 int  dasd_term_IO(struct dasd_ccw_req *);
1012 void dasd_schedule_device_bh(struct dasd_device *);
1013 void dasd_schedule_block_bh(struct dasd_block *);
1014 int  dasd_sleep_on(struct dasd_ccw_req *);
1015 int  dasd_sleep_on_queue(struct list_head *);
1016 int  dasd_sleep_on_immediately(struct dasd_ccw_req *);
1017 int  dasd_sleep_on_queue_interruptible(struct list_head *);
1018 int  dasd_sleep_on_interruptible(struct dasd_ccw_req *);
1019 void dasd_device_set_timer(struct dasd_device *, int);
1020 void dasd_device_clear_timer(struct dasd_device *);
1021 void dasd_block_set_timer(struct dasd_block *, int);
1022 void dasd_block_clear_timer(struct dasd_block *);
1023 int  dasd_cancel_req(struct dasd_ccw_req *);
1024 int dasd_flush_device_queue(struct dasd_device *);
1025 int dasd_generic_probe(struct ccw_device *);
1026 void dasd_generic_free_discipline(struct dasd_device *);
1027 void dasd_generic_remove (struct ccw_device *cdev);
1028 int dasd_generic_set_online(struct ccw_device *, struct dasd_discipline *);
1029 int dasd_generic_set_offline (struct ccw_device *cdev);
1030 int dasd_generic_notify(struct ccw_device *, int);
1031 int dasd_generic_last_path_gone(struct dasd_device *);
1032 int dasd_generic_path_operational(struct dasd_device *);
1033 void dasd_generic_shutdown(struct ccw_device *);
1034 
1035 void dasd_generic_handle_state_change(struct dasd_device *);
1036 enum uc_todo dasd_generic_uc_handler(struct ccw_device *, struct irb *);
1037 void dasd_generic_path_event(struct ccw_device *, int *);
1038 int dasd_generic_verify_path(struct dasd_device *, __u8);
1039 void dasd_generic_space_exhaust(struct dasd_device *, struct dasd_ccw_req *);
1040 void dasd_generic_space_avail(struct dasd_device *);
1041 
1042 int dasd_generic_requeue_all_requests(struct dasd_device *);
1043 
1044 int dasd_generic_read_dev_chars(struct dasd_device *, int, void *, int);
1045 char *dasd_get_sense(struct irb *);
1046 
1047 void dasd_device_set_stop_bits(struct dasd_device *, int);
1048 void dasd_device_remove_stop_bits(struct dasd_device *, int);
1049 
1050 int dasd_device_is_ro(struct dasd_device *);
1051 
1052 void dasd_profile_reset(struct dasd_profile *);
1053 int dasd_profile_on(struct dasd_profile *);
1054 void dasd_profile_off(struct dasd_profile *);
1055 char *dasd_get_user_string(const char __user *, size_t);
1056 
1057 /* externals in dasd_devmap.c */
1058 extern int dasd_max_devindex;
1059 extern int dasd_probeonly;
1060 extern int dasd_autodetect;
1061 extern int dasd_nopav;
1062 extern int dasd_nofcx;
1063 
1064 int dasd_devmap_init(void);
1065 void dasd_devmap_exit(void);
1066 
1067 struct dasd_device *dasd_create_device(struct ccw_device *);
1068 void dasd_delete_device(struct dasd_device *);
1069 
1070 int dasd_get_feature(struct ccw_device *, int);
1071 int dasd_set_feature(struct ccw_device *, int, int);
1072 
1073 extern const struct attribute_group *dasd_dev_groups[];
1074 void dasd_path_create_kobj(struct dasd_device *, int);
1075 void dasd_path_create_kobjects(struct dasd_device *);
1076 void dasd_path_remove_kobjects(struct dasd_device *);
1077 
1078 struct dasd_device *dasd_device_from_cdev(struct ccw_device *);
1079 struct dasd_device *dasd_device_from_cdev_locked(struct ccw_device *);
1080 struct dasd_device *dasd_device_from_devindex(int);
1081 
1082 void dasd_add_link_to_gendisk(struct gendisk *, struct dasd_device *);
1083 struct dasd_device *dasd_device_from_gendisk(struct gendisk *);
1084 
1085 int dasd_parse(void) __init;
1086 int dasd_busid_known(const char *);
1087 
1088 /* externals in dasd_gendisk.c */
1089 int  dasd_gendisk_init(void);
1090 void dasd_gendisk_exit(void);
1091 int dasd_gendisk_alloc(struct dasd_block *);
1092 void dasd_gendisk_free(struct dasd_block *);
1093 int dasd_scan_partitions(struct dasd_block *);
1094 void dasd_destroy_partitions(struct dasd_block *);
1095 
1096 /* externals in dasd_ioctl.c */
1097 int dasd_ioctl(struct block_device *bdev, blk_mode_t mode, unsigned int cmd,
1098 		unsigned long arg);
1099 int dasd_set_read_only(struct block_device *bdev, bool ro);
1100 
1101 /* externals in dasd_proc.c */
1102 int dasd_proc_init(void);
1103 void dasd_proc_exit(void);
1104 
1105 /* externals in dasd_erp.c */
1106 struct dasd_ccw_req *dasd_default_erp_action(struct dasd_ccw_req *);
1107 struct dasd_ccw_req *dasd_default_erp_postaction(struct dasd_ccw_req *);
1108 struct dasd_ccw_req *dasd_alloc_erp_request(unsigned int, int, int,
1109 					    struct dasd_device *);
1110 void dasd_free_erp_request(struct dasd_ccw_req *, struct dasd_device *);
1111 void dasd_log_sense(struct dasd_ccw_req *, struct irb *);
1112 void dasd_log_sense_dbf(struct dasd_ccw_req *cqr, struct irb *irb);
1113 
1114 /* externals in dasd_3990_erp.c */
1115 struct dasd_ccw_req *dasd_3990_erp_action(struct dasd_ccw_req *);
1116 void dasd_3990_erp_handle_sim(struct dasd_device *, char *);
1117 
1118 /* externals in dasd_eer.c */
1119 #ifdef CONFIG_DASD_EER
1120 int dasd_eer_init(void);
1121 void dasd_eer_exit(void);
1122 int dasd_eer_enable(struct dasd_device *);
1123 void dasd_eer_disable(struct dasd_device *);
1124 void dasd_eer_write(struct dasd_device *, struct dasd_ccw_req *cqr,
1125 		    unsigned int id);
1126 void dasd_eer_snss(struct dasd_device *);
1127 
1128 static inline int dasd_eer_enabled(struct dasd_device *device)
1129 {
1130 	return device->eer_cqr != NULL;
1131 }
1132 #else
1133 #define dasd_eer_init()		(0)
1134 #define dasd_eer_exit()		do { } while (0)
1135 #define dasd_eer_enable(d)	(0)
1136 #define dasd_eer_disable(d)	do { } while (0)
1137 #define dasd_eer_write(d,c,i)	do { } while (0)
1138 #define dasd_eer_snss(d)	do { } while (0)
1139 #define dasd_eer_enabled(d)	(0)
1140 #endif	/* CONFIG_DASD_ERR */
1141 
1142 
1143 /* DASD path handling functions */
1144 
1145 /*
1146  * helper functions to modify bit masks for a given channel path for a device
1147  */
1148 static inline int dasd_path_is_operational(struct dasd_device *device, int chp)
1149 {
1150 	return test_bit(DASD_PATH_OPERATIONAL, &device->path[chp].flags);
1151 }
1152 
1153 static inline int dasd_path_need_verify(struct dasd_device *device, int chp)
1154 {
1155 	return test_bit(DASD_PATH_TBV, &device->path[chp].flags);
1156 }
1157 
1158 static inline void dasd_path_verify(struct dasd_device *device, int chp)
1159 {
1160 	__set_bit(DASD_PATH_TBV, &device->path[chp].flags);
1161 }
1162 
1163 static inline void dasd_path_clear_verify(struct dasd_device *device, int chp)
1164 {
1165 	__clear_bit(DASD_PATH_TBV, &device->path[chp].flags);
1166 }
1167 
1168 static inline void dasd_path_clear_all_verify(struct dasd_device *device)
1169 {
1170 	int chp;
1171 
1172 	for (chp = 0; chp < 8; chp++)
1173 		dasd_path_clear_verify(device, chp);
1174 }
1175 
1176 static inline void dasd_path_fcsec(struct dasd_device *device, int chp)
1177 {
1178 	__set_bit(DASD_PATH_FCSEC, &device->path[chp].flags);
1179 }
1180 
1181 static inline void dasd_path_clear_fcsec(struct dasd_device *device, int chp)
1182 {
1183 	__clear_bit(DASD_PATH_FCSEC, &device->path[chp].flags);
1184 }
1185 
1186 static inline int dasd_path_need_fcsec(struct dasd_device *device, int chp)
1187 {
1188 	return test_bit(DASD_PATH_FCSEC, &device->path[chp].flags);
1189 }
1190 
1191 static inline void dasd_path_clear_all_fcsec(struct dasd_device *device)
1192 {
1193 	int chp;
1194 
1195 	for (chp = 0; chp < 8; chp++)
1196 		dasd_path_clear_fcsec(device, chp);
1197 }
1198 
1199 static inline void dasd_path_operational(struct dasd_device *device, int chp)
1200 {
1201 	__set_bit(DASD_PATH_OPERATIONAL, &device->path[chp].flags);
1202 	device->opm |= (0x80 >> chp);
1203 }
1204 
1205 static inline void dasd_path_nonpreferred(struct dasd_device *device, int chp)
1206 {
1207 	__set_bit(DASD_PATH_NPP, &device->path[chp].flags);
1208 }
1209 
1210 static inline int dasd_path_is_nonpreferred(struct dasd_device *device, int chp)
1211 {
1212 	return test_bit(DASD_PATH_NPP, &device->path[chp].flags);
1213 }
1214 
1215 static inline void dasd_path_clear_nonpreferred(struct dasd_device *device,
1216 						int chp)
1217 {
1218 	__clear_bit(DASD_PATH_NPP, &device->path[chp].flags);
1219 }
1220 
1221 static inline void dasd_path_preferred(struct dasd_device *device, int chp)
1222 {
1223 	__set_bit(DASD_PATH_PP, &device->path[chp].flags);
1224 }
1225 
1226 static inline int dasd_path_is_preferred(struct dasd_device *device, int chp)
1227 {
1228 	return test_bit(DASD_PATH_PP, &device->path[chp].flags);
1229 }
1230 
1231 static inline void dasd_path_clear_preferred(struct dasd_device *device,
1232 					     int chp)
1233 {
1234 	__clear_bit(DASD_PATH_PP, &device->path[chp].flags);
1235 }
1236 
1237 static inline void dasd_path_clear_oper(struct dasd_device *device, int chp)
1238 {
1239 	__clear_bit(DASD_PATH_OPERATIONAL, &device->path[chp].flags);
1240 	device->opm &= ~(0x80 >> chp);
1241 }
1242 
1243 static inline void dasd_path_clear_cable(struct dasd_device *device, int chp)
1244 {
1245 	__clear_bit(DASD_PATH_MISCABLED, &device->path[chp].flags);
1246 }
1247 
1248 static inline void dasd_path_cuir(struct dasd_device *device, int chp)
1249 {
1250 	__set_bit(DASD_PATH_CUIR, &device->path[chp].flags);
1251 }
1252 
1253 static inline int dasd_path_is_cuir(struct dasd_device *device, int chp)
1254 {
1255 	return test_bit(DASD_PATH_CUIR, &device->path[chp].flags);
1256 }
1257 
1258 static inline void dasd_path_clear_cuir(struct dasd_device *device, int chp)
1259 {
1260 	__clear_bit(DASD_PATH_CUIR, &device->path[chp].flags);
1261 }
1262 
1263 static inline void dasd_path_ifcc(struct dasd_device *device, int chp)
1264 {
1265 	set_bit(DASD_PATH_IFCC, &device->path[chp].flags);
1266 }
1267 
1268 static inline int dasd_path_is_ifcc(struct dasd_device *device, int chp)
1269 {
1270 	return test_bit(DASD_PATH_IFCC, &device->path[chp].flags);
1271 }
1272 
1273 static inline void dasd_path_clear_ifcc(struct dasd_device *device, int chp)
1274 {
1275 	clear_bit(DASD_PATH_IFCC, &device->path[chp].flags);
1276 }
1277 
1278 static inline void dasd_path_clear_nohpf(struct dasd_device *device, int chp)
1279 {
1280 	__clear_bit(DASD_PATH_NOHPF, &device->path[chp].flags);
1281 }
1282 
1283 static inline void dasd_path_miscabled(struct dasd_device *device, int chp)
1284 {
1285 	__set_bit(DASD_PATH_MISCABLED, &device->path[chp].flags);
1286 }
1287 
1288 static inline int dasd_path_is_miscabled(struct dasd_device *device, int chp)
1289 {
1290 	return test_bit(DASD_PATH_MISCABLED, &device->path[chp].flags);
1291 }
1292 
1293 static inline void dasd_path_nohpf(struct dasd_device *device, int chp)
1294 {
1295 	__set_bit(DASD_PATH_NOHPF, &device->path[chp].flags);
1296 }
1297 
1298 static inline int dasd_path_is_nohpf(struct dasd_device *device, int chp)
1299 {
1300 	return test_bit(DASD_PATH_NOHPF, &device->path[chp].flags);
1301 }
1302 
1303 /*
1304  * get functions for path masks
1305  * will return a path masks for the given device
1306  */
1307 
1308 static inline __u8 dasd_path_get_opm(struct dasd_device *device)
1309 {
1310 	return device->opm;
1311 }
1312 
1313 static inline __u8 dasd_path_get_tbvpm(struct dasd_device *device)
1314 {
1315 	int chp;
1316 	__u8 tbvpm = 0x00;
1317 
1318 	for (chp = 0; chp < 8; chp++)
1319 		if (dasd_path_need_verify(device, chp))
1320 			tbvpm |= 0x80 >> chp;
1321 	return tbvpm;
1322 }
1323 
1324 static inline int dasd_path_get_fcsecpm(struct dasd_device *device)
1325 {
1326 	int chp;
1327 
1328 	for (chp = 0; chp < 8; chp++)
1329 		if (dasd_path_need_fcsec(device, chp))
1330 			return 1;
1331 
1332 	return 0;
1333 }
1334 
1335 static inline __u8 dasd_path_get_nppm(struct dasd_device *device)
1336 {
1337 	int chp;
1338 	__u8 npm = 0x00;
1339 
1340 	for (chp = 0; chp < 8; chp++) {
1341 		if (dasd_path_is_nonpreferred(device, chp))
1342 			npm |= 0x80 >> chp;
1343 	}
1344 	return npm;
1345 }
1346 
1347 static inline __u8 dasd_path_get_ppm(struct dasd_device *device)
1348 {
1349 	int chp;
1350 	__u8 ppm = 0x00;
1351 
1352 	for (chp = 0; chp < 8; chp++)
1353 		if (dasd_path_is_preferred(device, chp))
1354 			ppm |= 0x80 >> chp;
1355 	return ppm;
1356 }
1357 
1358 static inline __u8 dasd_path_get_cablepm(struct dasd_device *device)
1359 {
1360 	int chp;
1361 	__u8 cablepm = 0x00;
1362 
1363 	for (chp = 0; chp < 8; chp++)
1364 		if (dasd_path_is_miscabled(device, chp))
1365 			cablepm |= 0x80 >> chp;
1366 	return cablepm;
1367 }
1368 
1369 static inline __u8 dasd_path_get_cuirpm(struct dasd_device *device)
1370 {
1371 	int chp;
1372 	__u8 cuirpm = 0x00;
1373 
1374 	for (chp = 0; chp < 8; chp++)
1375 		if (dasd_path_is_cuir(device, chp))
1376 			cuirpm |= 0x80 >> chp;
1377 	return cuirpm;
1378 }
1379 
1380 static inline __u8 dasd_path_get_ifccpm(struct dasd_device *device)
1381 {
1382 	int chp;
1383 	__u8 ifccpm = 0x00;
1384 
1385 	for (chp = 0; chp < 8; chp++)
1386 		if (dasd_path_is_ifcc(device, chp))
1387 			ifccpm |= 0x80 >> chp;
1388 	return ifccpm;
1389 }
1390 
1391 static inline __u8 dasd_path_get_hpfpm(struct dasd_device *device)
1392 {
1393 	int chp;
1394 	__u8 hpfpm = 0x00;
1395 
1396 	for (chp = 0; chp < 8; chp++)
1397 		if (dasd_path_is_nohpf(device, chp))
1398 			hpfpm |= 0x80 >> chp;
1399 	return hpfpm;
1400 }
1401 
1402 static inline u8 dasd_path_get_fcs_path(struct dasd_device *device, int chp)
1403 {
1404 	return device->path[chp].fc_security;
1405 }
1406 
1407 static inline int dasd_path_get_fcs_device(struct dasd_device *device)
1408 {
1409 	u8 fc_sec = 0;
1410 	int chp;
1411 
1412 	for (chp = 0; chp < 8; chp++) {
1413 		if (device->opm & (0x80 >> chp)) {
1414 			fc_sec = device->path[chp].fc_security;
1415 			break;
1416 		}
1417 	}
1418 	for (; chp < 8; chp++) {
1419 		if (device->opm & (0x80 >> chp))
1420 			if (device->path[chp].fc_security != fc_sec)
1421 				return -EINVAL;
1422 	}
1423 
1424 	return fc_sec;
1425 }
1426 
1427 /*
1428  * add functions for path masks
1429  * the existing path mask will be extended by the given path mask
1430  */
1431 static inline void dasd_path_add_tbvpm(struct dasd_device *device, __u8 pm)
1432 {
1433 	int chp;
1434 
1435 	for (chp = 0; chp < 8; chp++)
1436 		if (pm & (0x80 >> chp))
1437 			dasd_path_verify(device, chp);
1438 }
1439 
1440 static inline __u8 dasd_path_get_notoperpm(struct dasd_device *device)
1441 {
1442 	int chp;
1443 	__u8 nopm = 0x00;
1444 
1445 	for (chp = 0; chp < 8; chp++)
1446 		if (dasd_path_is_nohpf(device, chp) ||
1447 		    dasd_path_is_ifcc(device, chp) ||
1448 		    dasd_path_is_cuir(device, chp) ||
1449 		    dasd_path_is_miscabled(device, chp))
1450 			nopm |= 0x80 >> chp;
1451 	return nopm;
1452 }
1453 
1454 static inline void dasd_path_add_opm(struct dasd_device *device, __u8 pm)
1455 {
1456 	int chp;
1457 
1458 	for (chp = 0; chp < 8; chp++)
1459 		if (pm & (0x80 >> chp)) {
1460 			dasd_path_operational(device, chp);
1461 			/*
1462 			 * if the path is used
1463 			 * it should not be in one of the negative lists
1464 			 */
1465 			dasd_path_clear_nohpf(device, chp);
1466 			dasd_path_clear_cuir(device, chp);
1467 			dasd_path_clear_cable(device, chp);
1468 			dasd_path_clear_ifcc(device, chp);
1469 		}
1470 }
1471 
1472 static inline void dasd_path_add_cablepm(struct dasd_device *device, __u8 pm)
1473 {
1474 	int chp;
1475 
1476 	for (chp = 0; chp < 8; chp++)
1477 		if (pm & (0x80 >> chp))
1478 			dasd_path_miscabled(device, chp);
1479 }
1480 
1481 static inline void dasd_path_add_cuirpm(struct dasd_device *device, __u8 pm)
1482 {
1483 	int chp;
1484 
1485 	for (chp = 0; chp < 8; chp++)
1486 		if (pm & (0x80 >> chp))
1487 			dasd_path_cuir(device, chp);
1488 }
1489 
1490 static inline void dasd_path_add_ifccpm(struct dasd_device *device, __u8 pm)
1491 {
1492 	int chp;
1493 
1494 	for (chp = 0; chp < 8; chp++)
1495 		if (pm & (0x80 >> chp))
1496 			dasd_path_ifcc(device, chp);
1497 }
1498 
1499 static inline void dasd_path_add_nppm(struct dasd_device *device, __u8 pm)
1500 {
1501 	int chp;
1502 
1503 	for (chp = 0; chp < 8; chp++)
1504 		if (pm & (0x80 >> chp))
1505 			dasd_path_nonpreferred(device, chp);
1506 }
1507 
1508 static inline void dasd_path_add_nohpfpm(struct dasd_device *device, __u8 pm)
1509 {
1510 	int chp;
1511 
1512 	for (chp = 0; chp < 8; chp++)
1513 		if (pm & (0x80 >> chp))
1514 			dasd_path_nohpf(device, chp);
1515 }
1516 
1517 static inline void dasd_path_add_ppm(struct dasd_device *device, __u8 pm)
1518 {
1519 	int chp;
1520 
1521 	for (chp = 0; chp < 8; chp++)
1522 		if (pm & (0x80 >> chp))
1523 			dasd_path_preferred(device, chp);
1524 }
1525 
1526 static inline void dasd_path_add_fcsecpm(struct dasd_device *device, __u8 pm)
1527 {
1528 	int chp;
1529 
1530 	for (chp = 0; chp < 8; chp++)
1531 		if (pm & (0x80 >> chp))
1532 			dasd_path_fcsec(device, chp);
1533 }
1534 
1535 /*
1536  * set functions for path masks
1537  * the existing path mask will be replaced by the given path mask
1538  */
1539 static inline void dasd_path_set_tbvpm(struct dasd_device *device, __u8 pm)
1540 {
1541 	int chp;
1542 
1543 	for (chp = 0; chp < 8; chp++)
1544 		if (pm & (0x80 >> chp))
1545 			dasd_path_verify(device, chp);
1546 		else
1547 			dasd_path_clear_verify(device, chp);
1548 }
1549 
1550 static inline void dasd_path_set_opm(struct dasd_device *device, __u8 pm)
1551 {
1552 	int chp;
1553 
1554 	for (chp = 0; chp < 8; chp++) {
1555 		dasd_path_clear_oper(device, chp);
1556 		if (pm & (0x80 >> chp)) {
1557 			dasd_path_operational(device, chp);
1558 			/*
1559 			 * if the path is used
1560 			 * it should not be in one of the negative lists
1561 			 */
1562 			dasd_path_clear_nohpf(device, chp);
1563 			dasd_path_clear_cuir(device, chp);
1564 			dasd_path_clear_cable(device, chp);
1565 			dasd_path_clear_ifcc(device, chp);
1566 		}
1567 	}
1568 }
1569 
1570 /*
1571  * remove functions for path masks
1572  * the existing path mask will be cleared with the given path mask
1573  */
1574 static inline void dasd_path_remove_opm(struct dasd_device *device, __u8 pm)
1575 {
1576 	int chp;
1577 
1578 	for (chp = 0; chp < 8; chp++) {
1579 		if (pm & (0x80 >> chp))
1580 			dasd_path_clear_oper(device, chp);
1581 	}
1582 }
1583 
1584 /*
1585  * add the newly available path to the to be verified pm and remove it from
1586  * normal operation until it is verified
1587  */
1588 static inline void dasd_path_available(struct dasd_device *device, int chp)
1589 {
1590 	dasd_path_clear_oper(device, chp);
1591 	dasd_path_verify(device, chp);
1592 }
1593 
1594 static inline void dasd_path_notoper(struct dasd_device *device, int chp)
1595 {
1596 	dasd_path_clear_oper(device, chp);
1597 	dasd_path_clear_preferred(device, chp);
1598 	dasd_path_clear_nonpreferred(device, chp);
1599 }
1600 
1601 static inline void dasd_path_fcsec_update(struct dasd_device *device, int chp)
1602 {
1603 	dasd_path_fcsec(device, chp);
1604 }
1605 
1606 /*
1607  * remove all paths from normal operation
1608  */
1609 static inline void dasd_path_no_path(struct dasd_device *device)
1610 {
1611 	int chp;
1612 
1613 	for (chp = 0; chp < 8; chp++)
1614 		dasd_path_notoper(device, chp);
1615 
1616 	dasd_path_clear_all_verify(device);
1617 }
1618 
1619 /* end - path handling */
1620 
1621 #endif				/* DASD_H */
1622