xref: /linux/drivers/s390/block/dasd_int.h (revision 40d269c000bda9fcd276a0412a9cebd3f6e344c5)
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 	void *function; 		/* originating ERP action */
151 	void *mem_chunk;
152 
153 	unsigned long buildclk;		/* TOD-clock of request generation */
154 	unsigned long startclk;		/* TOD-clock of request start */
155 	unsigned long stopclk;		/* TOD-clock of request interrupt */
156 	unsigned long endclk;		/* TOD-clock of request termination */
157 
158 	void (*callback)(struct dasd_ccw_req *, void *data);
159 	void *callback_data;
160 	unsigned int proc_bytes;	/* bytes for partial completion */
161 	unsigned int trkcount;		/* count formatted tracks */
162 };
163 
164 /*
165  * dasd_ccw_req -> status can be:
166  */
167 #define DASD_CQR_FILLED 	0x00	/* request is ready to be processed */
168 #define DASD_CQR_DONE		0x01	/* request is completed successfully */
169 #define DASD_CQR_NEED_ERP	0x02	/* request needs recovery action */
170 #define DASD_CQR_IN_ERP 	0x03	/* request is in recovery */
171 #define DASD_CQR_FAILED 	0x04	/* request is finally failed */
172 #define DASD_CQR_TERMINATED	0x05	/* request was stopped by driver */
173 
174 #define DASD_CQR_QUEUED 	0x80	/* request is queued to be processed */
175 #define DASD_CQR_IN_IO		0x81	/* request is currently in IO */
176 #define DASD_CQR_ERROR		0x82	/* request is completed with error */
177 #define DASD_CQR_CLEAR_PENDING	0x83	/* request is clear pending */
178 #define DASD_CQR_CLEARED	0x84	/* request was cleared */
179 #define DASD_CQR_SUCCESS	0x85	/* request was successful */
180 
181 /* default expiration time*/
182 #define DASD_EXPIRES	  300
183 #define DASD_EXPIRES_MAX  40000000
184 #define DASD_RETRIES	  256
185 #define DASD_RETRIES_MAX  32768
186 
187 /* per dasd_ccw_req flags */
188 #define DASD_CQR_FLAGS_USE_ERP   0	/* use ERP for this request */
189 #define DASD_CQR_FLAGS_FAILFAST  1	/* FAILFAST */
190 #define DASD_CQR_VERIFY_PATH	 2	/* path verification request */
191 #define DASD_CQR_ALLOW_SLOCK	 3	/* Try this request even when lock was
192 					 * stolen. Should not be combined with
193 					 * DASD_CQR_FLAGS_USE_ERP
194 					 */
195 /*
196  * The following flags are used to suppress output of certain errors.
197  */
198 #define DASD_CQR_SUPPRESS_NRF	4	/* Suppress 'No Record Found' error */
199 #define DASD_CQR_SUPPRESS_FP	5	/* Suppress 'File Protected' error*/
200 #define DASD_CQR_SUPPRESS_IL	6	/* Suppress 'Incorrect Length' error */
201 #define DASD_CQR_SUPPRESS_CR	7	/* Suppress 'Command Reject' error */
202 
203 #define DASD_REQ_PER_DEV 4
204 
205 /* Signature for error recovery functions. */
206 typedef struct dasd_ccw_req *(*dasd_erp_fn_t) (struct dasd_ccw_req *);
207 
208 /*
209  * A single CQR can only contain a maximum of 255 CCWs. It is limited by
210  * the locate record and locate record extended count value which can only hold
211  * 1 Byte max.
212  */
213 #define DASD_CQR_MAX_CCW 255
214 
215 /*
216  * Unique identifier for dasd device.
217  */
218 #define UA_NOT_CONFIGURED  0x00
219 #define UA_BASE_DEVICE	   0x01
220 #define UA_BASE_PAV_ALIAS  0x02
221 #define UA_HYPER_PAV_ALIAS 0x03
222 
223 struct dasd_uid {
224 	__u8 type;
225 	char vendor[4];
226 	char serial[15];
227 	__u16 ssid;
228 	__u8 real_unit_addr;
229 	__u8 base_unit_addr;
230 	char vduit[33];
231 };
232 
233 #define DASD_UID_STRLEN ( /* vendor */ 3 + 1 + /* serial    */ 14 + 1 +	\
234 			  /* SSID   */ 4 + 1 + /* unit addr */ 2 + 1 +	\
235 			  /* vduit */ 32 + 1)
236 
237 /*
238  * PPRC Status data
239  */
240 struct dasd_pprc_header {
241 	__u8 entries;		/* 0     Number of device entries */
242 	__u8 unused;		/* 1     unused */
243 	__u16 entry_length;	/* 2-3   Length of device entry */
244 	__u32 unused2;		/* 4-7   unused */
245 } __packed;
246 
247 struct dasd_pprc_dev_info {
248 	__u8 state;		/* 0       Copy State */
249 	__u8 flags;		/* 1       Flags */
250 	__u8 reserved1[2];	/* 2-3     reserved */
251 	__u8 prim_lss;		/* 4       Primary device LSS */
252 	__u8 primary;		/* 5       Primary device address */
253 	__u8 sec_lss;		/* 6       Secondary device LSS */
254 	__u8 secondary;		/* 7       Secondary device address */
255 	__u16 pprc_id;		/* 8-9     Peer-to-Peer Remote Copy ID */
256 	__u8 reserved2[12];	/* 10-21   reserved */
257 	__u16 prim_cu_ssid;	/* 22-23   Primary Control Unit SSID */
258 	__u8 reserved3[12];	/* 24-35   reserved */
259 	__u16 sec_cu_ssid;	/* 36-37   Secondary Control Unit SSID */
260 	__u8 reserved4[90];	/* 38-127  reserved */
261 } __packed;
262 
263 struct dasd_pprc_data_sc4 {
264 	struct dasd_pprc_header header;
265 	struct dasd_pprc_dev_info dev_info[5];
266 } __packed;
267 
268 #define DASD_BUS_ID_SIZE 20
269 #define DASD_CP_ENTRIES 5
270 
271 struct dasd_copy_entry {
272 	char busid[DASD_BUS_ID_SIZE];
273 	struct dasd_device *device;
274 	bool primary;
275 	bool configured;
276 };
277 
278 struct dasd_copy_relation {
279 	struct dasd_copy_entry entry[DASD_CP_ENTRIES];
280 	struct dasd_copy_entry *active;
281 };
282 
283 int dasd_devmap_set_device_copy_relation(struct ccw_device *,
284 					 bool pprc_enabled);
285 
286 /*
287  * the struct dasd_discipline is
288  * sth like a table of virtual functions, if you think of dasd_eckd
289  * inheriting dasd...
290  * no, currently we are not planning to reimplement the driver in C++
291  */
292 struct dasd_discipline {
293 	struct module *owner;
294 	char ebcname[8];	/* a name used for tagging and printks */
295 	char name[8];		/* a name used for tagging and printks */
296 	bool has_discard;
297 
298 	struct list_head list;	/* used for list of disciplines */
299 
300 	/*
301 	 * Device recognition functions. check_device is used to verify
302 	 * the sense data and the information returned by read device
303 	 * characteristics. It returns 0 if the discipline can be used
304 	 * for the device in question. uncheck_device is called during
305 	 * device shutdown to deregister a device from its discipline.
306 	 */
307 	int (*check_device) (struct dasd_device *);
308 	void (*uncheck_device) (struct dasd_device *);
309 
310 	/*
311 	 * do_analysis is used in the step from device state "basic" to
312 	 * state "accept". It returns 0 if the device can be made ready,
313 	 * it returns -EMEDIUMTYPE if the device can't be made ready or
314 	 * -EAGAIN if do_analysis started a ccw that needs to complete
315 	 * before the analysis may be repeated.
316 	 */
317 	int (*do_analysis) (struct dasd_block *);
318 
319 	/*
320 	 * This function is called, when new paths become available.
321 	 * Disciplins may use this callback to do necessary setup work,
322 	 * e.g. verify that new path is compatible with the current
323 	 * configuration.
324 	 */
325 	int (*pe_handler)(struct dasd_device *, __u8, __u8);
326 
327 	/*
328 	 * Last things to do when a device is set online, and first things
329 	 * when it is set offline.
330 	 */
331 	int (*basic_to_ready) (struct dasd_device *);
332 	int (*online_to_ready) (struct dasd_device *);
333 	int (*basic_to_known)(struct dasd_device *);
334 
335 	unsigned int (*max_sectors)(struct dasd_block *);
336 	/* (struct dasd_device *);
337 	 * Device operation functions. build_cp creates a ccw chain for
338 	 * a block device request, start_io starts the request and
339 	 * term_IO cancels it (e.g. in case of a timeout). format_device
340 	 * formats the device and check_device_format compares the format of
341 	 * a device with the expected format_data.
342 	 * handle_terminated_request allows to examine a cqr and prepare
343 	 * it for retry.
344 	 */
345 	struct dasd_ccw_req *(*build_cp) (struct dasd_device *,
346 					  struct dasd_block *,
347 					  struct request *);
348 	int (*start_IO) (struct dasd_ccw_req *);
349 	int (*term_IO) (struct dasd_ccw_req *);
350 	void (*handle_terminated_request) (struct dasd_ccw_req *);
351 	int (*format_device) (struct dasd_device *,
352 			      struct format_data_t *, int);
353 	int (*check_device_format)(struct dasd_device *,
354 				   struct format_check_t *, int);
355 	int (*free_cp) (struct dasd_ccw_req *, struct request *);
356 
357 	/*
358 	 * Error recovery functions. examine_error() returns a value that
359 	 * indicates what to do for an error condition. If examine_error()
360 	 * returns 'dasd_era_recover' erp_action() is called to create a
361 	 * special error recovery ccw. erp_postaction() is called after
362 	 * an error recovery ccw has finished its execution. dump_sense
363 	 * is called for every error condition to print the sense data
364 	 * to the console.
365 	 */
366 	dasd_erp_fn_t(*erp_action) (struct dasd_ccw_req *);
367 	dasd_erp_fn_t(*erp_postaction) (struct dasd_ccw_req *);
368 	void (*dump_sense) (struct dasd_device *, struct dasd_ccw_req *,
369 			    struct irb *);
370 	void (*dump_sense_dbf) (struct dasd_device *, struct irb *, char *);
371 	void (*check_for_device_change) (struct dasd_device *,
372 					 struct dasd_ccw_req *,
373 					 struct irb *);
374 
375         /* i/o control functions. */
376 	int (*fill_geometry) (struct dasd_block *, struct hd_geometry *);
377 	int (*fill_info) (struct dasd_device *, struct dasd_information2_t *);
378 	int (*ioctl) (struct dasd_block *, unsigned int, void __user *);
379 
380 	/* reload device after state change */
381 	int (*reload) (struct dasd_device *);
382 
383 	int (*get_uid) (struct dasd_device *, struct dasd_uid *);
384 	void (*kick_validate) (struct dasd_device *);
385 	int (*check_attention)(struct dasd_device *, __u8);
386 	int (*host_access_count)(struct dasd_device *);
387 	int (*hosts_print)(struct dasd_device *, struct seq_file *);
388 	void (*handle_hpf_error)(struct dasd_device *, struct irb *);
389 	void (*disable_hpf)(struct dasd_device *);
390 	int (*hpf_enabled)(struct dasd_device *);
391 	void (*reset_path)(struct dasd_device *, __u8);
392 
393 	/*
394 	 * Extent Space Efficient (ESE) relevant functions
395 	 */
396 	int (*is_ese)(struct dasd_device *);
397 	/* Capacity */
398 	int (*space_allocated)(struct dasd_device *);
399 	int (*space_configured)(struct dasd_device *);
400 	int (*logical_capacity)(struct dasd_device *);
401 	int (*release_space)(struct dasd_device *, struct format_data_t *);
402 	/* Extent Pool */
403 	int (*ext_pool_id)(struct dasd_device *);
404 	int (*ext_size)(struct dasd_device *);
405 	int (*ext_pool_cap_at_warnlevel)(struct dasd_device *);
406 	int (*ext_pool_warn_thrshld)(struct dasd_device *);
407 	int (*ext_pool_oos)(struct dasd_device *);
408 	int (*ext_pool_exhaust)(struct dasd_device *, struct dasd_ccw_req *);
409 	struct dasd_ccw_req *(*ese_format)(struct dasd_device *,
410 					   struct dasd_ccw_req *, struct irb *);
411 	int (*ese_read)(struct dasd_ccw_req *, struct irb *);
412 	int (*pprc_status)(struct dasd_device *, struct	dasd_pprc_data_sc4 *);
413 	bool (*pprc_enabled)(struct dasd_device *);
414 	int (*copy_pair_swap)(struct dasd_device *, char *, char *);
415 	int (*device_ping)(struct dasd_device *);
416 };
417 
418 extern struct dasd_discipline *dasd_diag_discipline_pointer;
419 
420 /* Trigger IDs for extended error reporting DASD EER and autoquiesce */
421 enum eer_trigger {
422 	DASD_EER_FATALERROR = 1,
423 	DASD_EER_NOPATH,
424 	DASD_EER_STATECHANGE,
425 	DASD_EER_PPRCSUSPEND,
426 	DASD_EER_NOSPC,
427 	DASD_EER_TIMEOUTS,
428 	DASD_EER_STARTIO,
429 
430 	/* enum end marker, only add new trigger above */
431 	DASD_EER_MAX,
432 	DASD_EER_AUTOQUIESCE = 31, /* internal only */
433 };
434 
435 #define DASD_EER_VALID ((1U << DASD_EER_MAX) - 1)
436 
437 /* DASD path handling */
438 
439 #define DASD_PATH_OPERATIONAL  1
440 #define DASD_PATH_TBV	       2
441 #define DASD_PATH_PP	       3
442 #define DASD_PATH_NPP	       4
443 #define DASD_PATH_MISCABLED    5
444 #define DASD_PATH_NOHPF        6
445 #define DASD_PATH_CUIR	       7
446 #define DASD_PATH_IFCC	       8
447 #define DASD_PATH_FCSEC	       9
448 
449 #define DASD_THRHLD_MAX		4294967295U
450 #define DASD_INTERVAL_MAX	4294967295U
451 
452 /* FC Endpoint Security Capabilities */
453 #define DASD_FC_SECURITY_UNSUP		0
454 #define DASD_FC_SECURITY_AUTH		1
455 #define DASD_FC_SECURITY_ENC_FCSP2	2
456 #define DASD_FC_SECURITY_ENC_ERAS	3
457 
458 #define DASD_FC_SECURITY_ENC_STR	"Encryption"
459 static const struct {
460 	u8 value;
461 	char *name;
462 } dasd_path_fcs_mnemonics[] = {
463 	{ DASD_FC_SECURITY_UNSUP,	"Unsupported" },
464 	{ DASD_FC_SECURITY_AUTH,	"Authentication" },
465 	{ DASD_FC_SECURITY_ENC_FCSP2,	DASD_FC_SECURITY_ENC_STR },
466 	{ DASD_FC_SECURITY_ENC_ERAS,	DASD_FC_SECURITY_ENC_STR },
467 };
468 
469 static inline char *dasd_path_get_fcs_str(int val)
470 {
471 	int i;
472 
473 	for (i = 0; i < ARRAY_SIZE(dasd_path_fcs_mnemonics); i++) {
474 		if (dasd_path_fcs_mnemonics[i].value == val)
475 			return dasd_path_fcs_mnemonics[i].name;
476 	}
477 
478 	return dasd_path_fcs_mnemonics[0].name;
479 }
480 
481 struct dasd_path {
482 	unsigned long flags;
483 	u8 cssid;
484 	u8 ssid;
485 	u8 chpid;
486 	struct dasd_conf_data *conf_data;
487 	atomic_t error_count;
488 	unsigned long errorclk;
489 	u8 fc_security;
490 	struct kobject kobj;
491 	bool in_sysfs;
492 };
493 
494 #define to_dasd_path(path) container_of(path, struct dasd_path, kobj)
495 
496 static inline void dasd_path_release(struct kobject *kobj)
497 {
498 /* Memory for the dasd_path kobject is freed when dasd_free_device() is called */
499 }
500 
501 
502 struct dasd_profile_info {
503 	/* legacy part of profile data, as in dasd_profile_info_t */
504 	unsigned int dasd_io_reqs;	 /* number of requests processed */
505 	unsigned int dasd_io_sects;	 /* number of sectors processed */
506 	unsigned int dasd_io_secs[32];	 /* histogram of request's sizes */
507 	unsigned int dasd_io_times[32];	 /* histogram of requests's times */
508 	unsigned int dasd_io_timps[32];	 /* h. of requests's times per sector */
509 	unsigned int dasd_io_time1[32];	 /* hist. of time from build to start */
510 	unsigned int dasd_io_time2[32];	 /* hist. of time from start to irq */
511 	unsigned int dasd_io_time2ps[32]; /* hist. of time from start to irq */
512 	unsigned int dasd_io_time3[32];	 /* hist. of time from irq to end */
513 	unsigned int dasd_io_nr_req[32]; /* hist. of # of requests in chanq */
514 
515 	/* new data */
516 	struct timespec64 starttod;	   /* time of start or last reset */
517 	unsigned int dasd_io_alias;	   /* requests using an alias */
518 	unsigned int dasd_io_tpm;	   /* requests using transport mode */
519 	unsigned int dasd_read_reqs;	   /* total number of read  requests */
520 	unsigned int dasd_read_sects;	   /* total number read sectors */
521 	unsigned int dasd_read_alias;	   /* read request using an alias */
522 	unsigned int dasd_read_tpm;	   /* read requests in transport mode */
523 	unsigned int dasd_read_secs[32];   /* histogram of request's sizes */
524 	unsigned int dasd_read_times[32];  /* histogram of requests's times */
525 	unsigned int dasd_read_time1[32];  /* hist. time from build to start */
526 	unsigned int dasd_read_time2[32];  /* hist. of time from start to irq */
527 	unsigned int dasd_read_time3[32];  /* hist. of time from irq to end */
528 	unsigned int dasd_read_nr_req[32]; /* hist. of # of requests in chanq */
529 	unsigned long dasd_sum_times;	   /* sum of request times */
530 	unsigned long dasd_sum_time_str;   /* sum of time from build to start */
531 	unsigned long dasd_sum_time_irq;   /* sum of time from start to irq */
532 	unsigned long dasd_sum_time_end;   /* sum of time from irq to end */
533 };
534 
535 struct dasd_profile {
536 	struct dentry *dentry;
537 	struct dasd_profile_info *data;
538 	spinlock_t lock;
539 };
540 
541 struct dasd_format_entry {
542 	struct list_head list;
543 	sector_t track;
544 };
545 
546 struct dasd_device {
547 	/* Block device stuff. */
548 	struct dasd_block *block;
549 
550         unsigned int devindex;
551 	unsigned long flags;	   /* per device flags */
552 	unsigned short features;   /* copy of devmap-features (read-only!) */
553 
554 	/* extended error reporting stuff (eer) */
555 	struct dasd_ccw_req *eer_cqr;
556 
557 	/* Device discipline stuff. */
558 	struct dasd_discipline *discipline;
559 	struct dasd_discipline *base_discipline;
560 	void *private;
561 	struct dasd_path path[8];
562 	__u8 opm;
563 
564 	/* Device state and target state. */
565 	int state, target;
566 	struct mutex state_mutex;
567 	int stopped;		/* device (ccw_device_start) was stopped */
568 
569 	/* reference count. */
570         atomic_t ref_count;
571 
572 	/* ccw queue and memory for static ccw/erp buffers. */
573 	struct list_head ccw_queue;
574 	spinlock_t mem_lock;
575 	void *ccw_mem;
576 	void *erp_mem;
577 	void *ese_mem;
578 	struct list_head ccw_chunks;
579 	struct list_head erp_chunks;
580 	struct list_head ese_chunks;
581 
582 	atomic_t tasklet_scheduled;
583         struct tasklet_struct tasklet;
584 	struct work_struct kick_work;
585 	struct work_struct reload_device;
586 	struct work_struct kick_validate;
587 	struct work_struct suc_work;
588 	struct work_struct requeue_requests;
589 	struct timer_list timer;
590 
591 	debug_info_t *debug_area;
592 
593 	struct ccw_device *cdev;
594 
595 	/* hook for alias management */
596 	struct list_head alias_list;
597 
598 	/* default expiration time in s */
599 	unsigned long default_expires;
600 	unsigned long default_retries;
601 
602 	unsigned long blk_timeout;
603 
604 	unsigned long path_thrhld;
605 	unsigned long path_interval;
606 
607 	struct dentry *debugfs_dentry;
608 	struct dentry *hosts_dentry;
609 	struct dasd_profile profile;
610 	struct dasd_format_entry format_entry;
611 	struct kset *paths_info;
612 	struct dasd_copy_relation *copy;
613 	unsigned long aq_mask;
614 	unsigned int aq_timeouts;
615 };
616 
617 struct dasd_block {
618 	/* Block device stuff. */
619 	struct gendisk *gdp;
620 	spinlock_t request_queue_lock;
621 	struct blk_mq_tag_set tag_set;
622 	struct file *bdev_file;
623 	atomic_t open_count;
624 
625 	unsigned long blocks;	   /* size of volume in blocks */
626 	unsigned int bp_block;	   /* bytes per block */
627 	unsigned int s2b_shift;	   /* log2 (bp_block/512) */
628 
629 	struct dasd_device *base;
630 	struct list_head ccw_queue;
631 	spinlock_t queue_lock;
632 
633 	atomic_t tasklet_scheduled;
634 	struct tasklet_struct tasklet;
635 	struct timer_list timer;
636 
637 	struct dentry *debugfs_dentry;
638 	struct dasd_profile profile;
639 
640 	struct list_head format_list;
641 	spinlock_t format_lock;
642 	atomic_t trkcount;
643 };
644 
645 struct dasd_attention_data {
646 	struct dasd_device *device;
647 	__u8 lpum;
648 };
649 
650 struct dasd_queue {
651 	spinlock_t lock;
652 };
653 
654 /* reasons why device (ccw_device_start) was stopped */
655 #define DASD_STOPPED_NOT_ACC 1         /* not accessible */
656 #define DASD_STOPPED_QUIESCE 2         /* Quiesced */
657 #define DASD_STOPPED_PENDING 4         /* long busy */
658 #define DASD_STOPPED_DC_WAIT 8         /* disconnected, wait */
659 #define DASD_STOPPED_SU      16        /* summary unit check handling */
660 #define DASD_STOPPED_PPRC    32        /* PPRC swap */
661 #define DASD_STOPPED_NOSPC   128       /* no space left */
662 
663 /* per device flags */
664 #define DASD_FLAG_OFFLINE	3	/* device is in offline processing */
665 #define DASD_FLAG_EER_SNSS	4	/* A SNSS is required */
666 #define DASD_FLAG_EER_IN_USE	5	/* A SNSS request is running */
667 #define DASD_FLAG_DEVICE_RO	6	/* The device itself is read-only. Don't
668 					 * confuse this with the user specified
669 					 * read-only feature.
670 					 */
671 #define DASD_FLAG_IS_RESERVED	7	/* The device is reserved */
672 #define DASD_FLAG_LOCK_STOLEN	8	/* The device lock was stolen */
673 #define DASD_FLAG_SUSPENDED	9	/* The device was suspended */
674 #define DASD_FLAG_SAFE_OFFLINE	10	/* safe offline processing requested*/
675 #define DASD_FLAG_SAFE_OFFLINE_RUNNING	11	/* safe offline running */
676 #define DASD_FLAG_ABORTALL	12	/* Abort all noretry requests */
677 #define DASD_FLAG_PATH_VERIFY	13	/* Path verification worker running */
678 #define DASD_FLAG_SUC		14	/* unhandled summary unit check */
679 
680 #define DASD_SLEEPON_START_TAG	((void *) 1)
681 #define DASD_SLEEPON_END_TAG	((void *) 2)
682 
683 void dasd_put_device_wake(struct dasd_device *);
684 
685 /*
686  * return values to be returned from the copy pair swap function
687  * 0x00: swap successful
688  * 0x01: swap data invalid
689  * 0x02: no active device found
690  * 0x03: wrong primary specified
691  * 0x04: secondary device not found
692  * 0x05: swap already running
693  */
694 #define DASD_COPYPAIRSWAP_SUCCESS	0
695 #define DASD_COPYPAIRSWAP_INVALID	1
696 #define DASD_COPYPAIRSWAP_NOACTIVE	2
697 #define DASD_COPYPAIRSWAP_PRIMARY	3
698 #define DASD_COPYPAIRSWAP_SECONDARY	4
699 #define DASD_COPYPAIRSWAP_MULTIPLE	5
700 
701 /*
702  * Reference count inliners
703  */
704 static inline void
705 dasd_get_device(struct dasd_device *device)
706 {
707 	atomic_inc(&device->ref_count);
708 }
709 
710 static inline void
711 dasd_put_device(struct dasd_device *device)
712 {
713 	if (atomic_dec_return(&device->ref_count) == 0)
714 		dasd_put_device_wake(device);
715 }
716 
717 /*
718  * The static memory in ccw_mem and erp_mem is managed by a sorted
719  * list of free memory chunks.
720  */
721 struct dasd_mchunk
722 {
723 	struct list_head list;
724 	unsigned long size;
725 } __attribute__ ((aligned(8)));
726 
727 static inline void
728 dasd_init_chunklist(struct list_head *chunk_list, void *mem,
729 		    unsigned long size)
730 {
731 	struct dasd_mchunk *chunk;
732 
733 	INIT_LIST_HEAD(chunk_list);
734 	chunk = (struct dasd_mchunk *) mem;
735 	chunk->size = size - sizeof(struct dasd_mchunk);
736 	list_add(&chunk->list, chunk_list);
737 }
738 
739 static inline void *
740 dasd_alloc_chunk(struct list_head *chunk_list, unsigned long size)
741 {
742 	struct dasd_mchunk *chunk, *tmp;
743 
744 	size = (size + 7L) & -8L;
745 	list_for_each_entry(chunk, chunk_list, list) {
746 		if (chunk->size < size)
747 			continue;
748 		if (chunk->size > size + sizeof(struct dasd_mchunk)) {
749 			char *endaddr = (char *) (chunk + 1) + chunk->size;
750 			tmp = (struct dasd_mchunk *) (endaddr - size) - 1;
751 			tmp->size = size;
752 			chunk->size -= size + sizeof(struct dasd_mchunk);
753 			chunk = tmp;
754 		} else
755 			list_del(&chunk->list);
756 		return (void *) (chunk + 1);
757 	}
758 	return NULL;
759 }
760 
761 static inline void
762 dasd_free_chunk(struct list_head *chunk_list, void *mem)
763 {
764 	struct dasd_mchunk *chunk, *tmp;
765 	struct list_head *p, *left;
766 
767 	chunk = (struct dasd_mchunk *)
768 		((char *) mem - sizeof(struct dasd_mchunk));
769 	/* Find out the left neighbour in chunk_list. */
770 	left = chunk_list;
771 	list_for_each(p, chunk_list) {
772 		if (list_entry(p, struct dasd_mchunk, list) > chunk)
773 			break;
774 		left = p;
775 	}
776 	/* Try to merge with right neighbour = next element from left. */
777 	if (left->next != chunk_list) {
778 		tmp = list_entry(left->next, struct dasd_mchunk, list);
779 		if ((char *) (chunk + 1) + chunk->size == (char *) tmp) {
780 			list_del(&tmp->list);
781 			chunk->size += tmp->size + sizeof(struct dasd_mchunk);
782 		}
783 	}
784 	/* Try to merge with left neighbour. */
785 	if (left != chunk_list) {
786 		tmp = list_entry(left, struct dasd_mchunk, list);
787 		if ((char *) (tmp + 1) + tmp->size == (char *) chunk) {
788 			tmp->size += chunk->size + sizeof(struct dasd_mchunk);
789 			return;
790 		}
791 	}
792 	__list_add(&chunk->list, left, left->next);
793 }
794 
795 /*
796  * Check if bsize is in { 512, 1024, 2048, 4096 }
797  */
798 static inline int
799 dasd_check_blocksize(int bsize)
800 {
801 	if (bsize < 512 || bsize > 4096 || !is_power_of_2(bsize))
802 		return -EMEDIUMTYPE;
803 	return 0;
804 }
805 
806 /*
807  * return the callback data of the original request in case there are
808  * ERP requests build on top of it
809  */
810 static inline void *dasd_get_callback_data(struct dasd_ccw_req *cqr)
811 {
812 	while (cqr->refers)
813 		cqr = cqr->refers;
814 
815 	return cqr->callback_data;
816 }
817 
818 /* externals in dasd.c */
819 #define DASD_PROFILE_OFF	 0
820 #define DASD_PROFILE_ON 	 1
821 #define DASD_PROFILE_GLOBAL_ONLY 2
822 
823 extern debug_info_t *dasd_debug_area;
824 extern struct dasd_profile dasd_global_profile;
825 extern unsigned int dasd_global_profile_level;
826 extern const struct block_device_operations dasd_device_operations;
827 extern struct blk_mq_ops dasd_mq_ops;
828 
829 extern struct kmem_cache *dasd_page_cache;
830 
831 struct dasd_ccw_req *
832 dasd_smalloc_request(int, int, int, struct dasd_device *, struct dasd_ccw_req *);
833 struct dasd_ccw_req *dasd_fmalloc_request(int, int, int, struct dasd_device *);
834 void dasd_sfree_request(struct dasd_ccw_req *, struct dasd_device *);
835 void dasd_ffree_request(struct dasd_ccw_req *, struct dasd_device *);
836 void dasd_wakeup_cb(struct dasd_ccw_req *, void *);
837 
838 struct dasd_device *dasd_alloc_device(void);
839 void dasd_free_device(struct dasd_device *);
840 
841 struct dasd_block *dasd_alloc_block(void);
842 void dasd_free_block(struct dasd_block *);
843 
844 enum blk_eh_timer_return dasd_times_out(struct request *req);
845 
846 void dasd_enable_device(struct dasd_device *);
847 void dasd_set_target_state(struct dasd_device *, int);
848 void dasd_kick_device(struct dasd_device *);
849 void dasd_reload_device(struct dasd_device *);
850 void dasd_schedule_requeue(struct dasd_device *);
851 
852 void dasd_add_request_head(struct dasd_ccw_req *);
853 void dasd_add_request_tail(struct dasd_ccw_req *);
854 int  dasd_start_IO(struct dasd_ccw_req *);
855 int  dasd_term_IO(struct dasd_ccw_req *);
856 void dasd_schedule_device_bh(struct dasd_device *);
857 void dasd_schedule_block_bh(struct dasd_block *);
858 int  dasd_sleep_on(struct dasd_ccw_req *);
859 int  dasd_sleep_on_queue(struct list_head *);
860 int  dasd_sleep_on_immediatly(struct dasd_ccw_req *);
861 int  dasd_sleep_on_queue_interruptible(struct list_head *);
862 int  dasd_sleep_on_interruptible(struct dasd_ccw_req *);
863 void dasd_device_set_timer(struct dasd_device *, int);
864 void dasd_device_clear_timer(struct dasd_device *);
865 void dasd_block_set_timer(struct dasd_block *, int);
866 void dasd_block_clear_timer(struct dasd_block *);
867 int  dasd_cancel_req(struct dasd_ccw_req *);
868 int dasd_flush_device_queue(struct dasd_device *);
869 int dasd_generic_probe(struct ccw_device *);
870 void dasd_generic_free_discipline(struct dasd_device *);
871 void dasd_generic_remove (struct ccw_device *cdev);
872 int dasd_generic_set_online(struct ccw_device *, struct dasd_discipline *);
873 int dasd_generic_set_offline (struct ccw_device *cdev);
874 int dasd_generic_notify(struct ccw_device *, int);
875 int dasd_generic_last_path_gone(struct dasd_device *);
876 int dasd_generic_path_operational(struct dasd_device *);
877 void dasd_generic_shutdown(struct ccw_device *);
878 
879 void dasd_generic_handle_state_change(struct dasd_device *);
880 enum uc_todo dasd_generic_uc_handler(struct ccw_device *, struct irb *);
881 void dasd_generic_path_event(struct ccw_device *, int *);
882 int dasd_generic_verify_path(struct dasd_device *, __u8);
883 void dasd_generic_space_exhaust(struct dasd_device *, struct dasd_ccw_req *);
884 void dasd_generic_space_avail(struct dasd_device *);
885 
886 int dasd_generic_requeue_all_requests(struct dasd_device *);
887 
888 int dasd_generic_read_dev_chars(struct dasd_device *, int, void *, int);
889 char *dasd_get_sense(struct irb *);
890 
891 void dasd_device_set_stop_bits(struct dasd_device *, int);
892 void dasd_device_remove_stop_bits(struct dasd_device *, int);
893 
894 int dasd_device_is_ro(struct dasd_device *);
895 
896 void dasd_profile_reset(struct dasd_profile *);
897 int dasd_profile_on(struct dasd_profile *);
898 void dasd_profile_off(struct dasd_profile *);
899 char *dasd_get_user_string(const char __user *, size_t);
900 
901 /* externals in dasd_devmap.c */
902 extern int dasd_max_devindex;
903 extern int dasd_probeonly;
904 extern int dasd_autodetect;
905 extern int dasd_nopav;
906 extern int dasd_nofcx;
907 
908 int dasd_devmap_init(void);
909 void dasd_devmap_exit(void);
910 
911 struct dasd_device *dasd_create_device(struct ccw_device *);
912 void dasd_delete_device(struct dasd_device *);
913 
914 int dasd_get_feature(struct ccw_device *, int);
915 int dasd_set_feature(struct ccw_device *, int, int);
916 
917 extern const struct attribute_group *dasd_dev_groups[];
918 void dasd_path_create_kobj(struct dasd_device *, int);
919 void dasd_path_create_kobjects(struct dasd_device *);
920 void dasd_path_remove_kobjects(struct dasd_device *);
921 
922 struct dasd_device *dasd_device_from_cdev(struct ccw_device *);
923 struct dasd_device *dasd_device_from_cdev_locked(struct ccw_device *);
924 struct dasd_device *dasd_device_from_devindex(int);
925 
926 void dasd_add_link_to_gendisk(struct gendisk *, struct dasd_device *);
927 struct dasd_device *dasd_device_from_gendisk(struct gendisk *);
928 
929 int dasd_parse(void) __init;
930 int dasd_busid_known(const char *);
931 
932 /* externals in dasd_gendisk.c */
933 int  dasd_gendisk_init(void);
934 void dasd_gendisk_exit(void);
935 int dasd_gendisk_alloc(struct dasd_block *);
936 void dasd_gendisk_free(struct dasd_block *);
937 int dasd_scan_partitions(struct dasd_block *);
938 void dasd_destroy_partitions(struct dasd_block *);
939 
940 /* externals in dasd_ioctl.c */
941 int dasd_ioctl(struct block_device *bdev, blk_mode_t mode, unsigned int cmd,
942 		unsigned long arg);
943 int dasd_set_read_only(struct block_device *bdev, bool ro);
944 
945 /* externals in dasd_proc.c */
946 int dasd_proc_init(void);
947 void dasd_proc_exit(void);
948 
949 /* externals in dasd_erp.c */
950 struct dasd_ccw_req *dasd_default_erp_action(struct dasd_ccw_req *);
951 struct dasd_ccw_req *dasd_default_erp_postaction(struct dasd_ccw_req *);
952 struct dasd_ccw_req *dasd_alloc_erp_request(unsigned int, int, int,
953 					    struct dasd_device *);
954 void dasd_free_erp_request(struct dasd_ccw_req *, struct dasd_device *);
955 void dasd_log_sense(struct dasd_ccw_req *, struct irb *);
956 void dasd_log_sense_dbf(struct dasd_ccw_req *cqr, struct irb *irb);
957 
958 /* externals in dasd_3990_erp.c */
959 struct dasd_ccw_req *dasd_3990_erp_action(struct dasd_ccw_req *);
960 void dasd_3990_erp_handle_sim(struct dasd_device *, char *);
961 
962 /* externals in dasd_eer.c */
963 #ifdef CONFIG_DASD_EER
964 int dasd_eer_init(void);
965 void dasd_eer_exit(void);
966 int dasd_eer_enable(struct dasd_device *);
967 void dasd_eer_disable(struct dasd_device *);
968 void dasd_eer_write(struct dasd_device *, struct dasd_ccw_req *cqr,
969 		    unsigned int id);
970 void dasd_eer_snss(struct dasd_device *);
971 
972 static inline int dasd_eer_enabled(struct dasd_device *device)
973 {
974 	return device->eer_cqr != NULL;
975 }
976 #else
977 #define dasd_eer_init()		(0)
978 #define dasd_eer_exit()		do { } while (0)
979 #define dasd_eer_enable(d)	(0)
980 #define dasd_eer_disable(d)	do { } while (0)
981 #define dasd_eer_write(d,c,i)	do { } while (0)
982 #define dasd_eer_snss(d)	do { } while (0)
983 #define dasd_eer_enabled(d)	(0)
984 #endif	/* CONFIG_DASD_ERR */
985 
986 
987 /* DASD path handling functions */
988 
989 /*
990  * helper functions to modify bit masks for a given channel path for a device
991  */
992 static inline int dasd_path_is_operational(struct dasd_device *device, int chp)
993 {
994 	return test_bit(DASD_PATH_OPERATIONAL, &device->path[chp].flags);
995 }
996 
997 static inline int dasd_path_need_verify(struct dasd_device *device, int chp)
998 {
999 	return test_bit(DASD_PATH_TBV, &device->path[chp].flags);
1000 }
1001 
1002 static inline void dasd_path_verify(struct dasd_device *device, int chp)
1003 {
1004 	__set_bit(DASD_PATH_TBV, &device->path[chp].flags);
1005 }
1006 
1007 static inline void dasd_path_clear_verify(struct dasd_device *device, int chp)
1008 {
1009 	__clear_bit(DASD_PATH_TBV, &device->path[chp].flags);
1010 }
1011 
1012 static inline void dasd_path_clear_all_verify(struct dasd_device *device)
1013 {
1014 	int chp;
1015 
1016 	for (chp = 0; chp < 8; chp++)
1017 		dasd_path_clear_verify(device, chp);
1018 }
1019 
1020 static inline void dasd_path_fcsec(struct dasd_device *device, int chp)
1021 {
1022 	__set_bit(DASD_PATH_FCSEC, &device->path[chp].flags);
1023 }
1024 
1025 static inline void dasd_path_clear_fcsec(struct dasd_device *device, int chp)
1026 {
1027 	__clear_bit(DASD_PATH_FCSEC, &device->path[chp].flags);
1028 }
1029 
1030 static inline int dasd_path_need_fcsec(struct dasd_device *device, int chp)
1031 {
1032 	return test_bit(DASD_PATH_FCSEC, &device->path[chp].flags);
1033 }
1034 
1035 static inline void dasd_path_clear_all_fcsec(struct dasd_device *device)
1036 {
1037 	int chp;
1038 
1039 	for (chp = 0; chp < 8; chp++)
1040 		dasd_path_clear_fcsec(device, chp);
1041 }
1042 
1043 static inline void dasd_path_operational(struct dasd_device *device, int chp)
1044 {
1045 	__set_bit(DASD_PATH_OPERATIONAL, &device->path[chp].flags);
1046 	device->opm |= (0x80 >> chp);
1047 }
1048 
1049 static inline void dasd_path_nonpreferred(struct dasd_device *device, int chp)
1050 {
1051 	__set_bit(DASD_PATH_NPP, &device->path[chp].flags);
1052 }
1053 
1054 static inline int dasd_path_is_nonpreferred(struct dasd_device *device, int chp)
1055 {
1056 	return test_bit(DASD_PATH_NPP, &device->path[chp].flags);
1057 }
1058 
1059 static inline void dasd_path_clear_nonpreferred(struct dasd_device *device,
1060 						int chp)
1061 {
1062 	__clear_bit(DASD_PATH_NPP, &device->path[chp].flags);
1063 }
1064 
1065 static inline void dasd_path_preferred(struct dasd_device *device, int chp)
1066 {
1067 	__set_bit(DASD_PATH_PP, &device->path[chp].flags);
1068 }
1069 
1070 static inline int dasd_path_is_preferred(struct dasd_device *device, int chp)
1071 {
1072 	return test_bit(DASD_PATH_PP, &device->path[chp].flags);
1073 }
1074 
1075 static inline void dasd_path_clear_preferred(struct dasd_device *device,
1076 					     int chp)
1077 {
1078 	__clear_bit(DASD_PATH_PP, &device->path[chp].flags);
1079 }
1080 
1081 static inline void dasd_path_clear_oper(struct dasd_device *device, int chp)
1082 {
1083 	__clear_bit(DASD_PATH_OPERATIONAL, &device->path[chp].flags);
1084 	device->opm &= ~(0x80 >> chp);
1085 }
1086 
1087 static inline void dasd_path_clear_cable(struct dasd_device *device, int chp)
1088 {
1089 	__clear_bit(DASD_PATH_MISCABLED, &device->path[chp].flags);
1090 }
1091 
1092 static inline void dasd_path_cuir(struct dasd_device *device, int chp)
1093 {
1094 	__set_bit(DASD_PATH_CUIR, &device->path[chp].flags);
1095 }
1096 
1097 static inline int dasd_path_is_cuir(struct dasd_device *device, int chp)
1098 {
1099 	return test_bit(DASD_PATH_CUIR, &device->path[chp].flags);
1100 }
1101 
1102 static inline void dasd_path_clear_cuir(struct dasd_device *device, int chp)
1103 {
1104 	__clear_bit(DASD_PATH_CUIR, &device->path[chp].flags);
1105 }
1106 
1107 static inline void dasd_path_ifcc(struct dasd_device *device, int chp)
1108 {
1109 	set_bit(DASD_PATH_IFCC, &device->path[chp].flags);
1110 }
1111 
1112 static inline int dasd_path_is_ifcc(struct dasd_device *device, int chp)
1113 {
1114 	return test_bit(DASD_PATH_IFCC, &device->path[chp].flags);
1115 }
1116 
1117 static inline void dasd_path_clear_ifcc(struct dasd_device *device, int chp)
1118 {
1119 	clear_bit(DASD_PATH_IFCC, &device->path[chp].flags);
1120 }
1121 
1122 static inline void dasd_path_clear_nohpf(struct dasd_device *device, int chp)
1123 {
1124 	__clear_bit(DASD_PATH_NOHPF, &device->path[chp].flags);
1125 }
1126 
1127 static inline void dasd_path_miscabled(struct dasd_device *device, int chp)
1128 {
1129 	__set_bit(DASD_PATH_MISCABLED, &device->path[chp].flags);
1130 }
1131 
1132 static inline int dasd_path_is_miscabled(struct dasd_device *device, int chp)
1133 {
1134 	return test_bit(DASD_PATH_MISCABLED, &device->path[chp].flags);
1135 }
1136 
1137 static inline void dasd_path_nohpf(struct dasd_device *device, int chp)
1138 {
1139 	__set_bit(DASD_PATH_NOHPF, &device->path[chp].flags);
1140 }
1141 
1142 static inline int dasd_path_is_nohpf(struct dasd_device *device, int chp)
1143 {
1144 	return test_bit(DASD_PATH_NOHPF, &device->path[chp].flags);
1145 }
1146 
1147 /*
1148  * get functions for path masks
1149  * will return a path masks for the given device
1150  */
1151 
1152 static inline __u8 dasd_path_get_opm(struct dasd_device *device)
1153 {
1154 	return device->opm;
1155 }
1156 
1157 static inline __u8 dasd_path_get_tbvpm(struct dasd_device *device)
1158 {
1159 	int chp;
1160 	__u8 tbvpm = 0x00;
1161 
1162 	for (chp = 0; chp < 8; chp++)
1163 		if (dasd_path_need_verify(device, chp))
1164 			tbvpm |= 0x80 >> chp;
1165 	return tbvpm;
1166 }
1167 
1168 static inline int dasd_path_get_fcsecpm(struct dasd_device *device)
1169 {
1170 	int chp;
1171 
1172 	for (chp = 0; chp < 8; chp++)
1173 		if (dasd_path_need_fcsec(device, chp))
1174 			return 1;
1175 
1176 	return 0;
1177 }
1178 
1179 static inline __u8 dasd_path_get_nppm(struct dasd_device *device)
1180 {
1181 	int chp;
1182 	__u8 npm = 0x00;
1183 
1184 	for (chp = 0; chp < 8; chp++) {
1185 		if (dasd_path_is_nonpreferred(device, chp))
1186 			npm |= 0x80 >> chp;
1187 	}
1188 	return npm;
1189 }
1190 
1191 static inline __u8 dasd_path_get_ppm(struct dasd_device *device)
1192 {
1193 	int chp;
1194 	__u8 ppm = 0x00;
1195 
1196 	for (chp = 0; chp < 8; chp++)
1197 		if (dasd_path_is_preferred(device, chp))
1198 			ppm |= 0x80 >> chp;
1199 	return ppm;
1200 }
1201 
1202 static inline __u8 dasd_path_get_cablepm(struct dasd_device *device)
1203 {
1204 	int chp;
1205 	__u8 cablepm = 0x00;
1206 
1207 	for (chp = 0; chp < 8; chp++)
1208 		if (dasd_path_is_miscabled(device, chp))
1209 			cablepm |= 0x80 >> chp;
1210 	return cablepm;
1211 }
1212 
1213 static inline __u8 dasd_path_get_cuirpm(struct dasd_device *device)
1214 {
1215 	int chp;
1216 	__u8 cuirpm = 0x00;
1217 
1218 	for (chp = 0; chp < 8; chp++)
1219 		if (dasd_path_is_cuir(device, chp))
1220 			cuirpm |= 0x80 >> chp;
1221 	return cuirpm;
1222 }
1223 
1224 static inline __u8 dasd_path_get_ifccpm(struct dasd_device *device)
1225 {
1226 	int chp;
1227 	__u8 ifccpm = 0x00;
1228 
1229 	for (chp = 0; chp < 8; chp++)
1230 		if (dasd_path_is_ifcc(device, chp))
1231 			ifccpm |= 0x80 >> chp;
1232 	return ifccpm;
1233 }
1234 
1235 static inline __u8 dasd_path_get_hpfpm(struct dasd_device *device)
1236 {
1237 	int chp;
1238 	__u8 hpfpm = 0x00;
1239 
1240 	for (chp = 0; chp < 8; chp++)
1241 		if (dasd_path_is_nohpf(device, chp))
1242 			hpfpm |= 0x80 >> chp;
1243 	return hpfpm;
1244 }
1245 
1246 static inline u8 dasd_path_get_fcs_path(struct dasd_device *device, int chp)
1247 {
1248 	return device->path[chp].fc_security;
1249 }
1250 
1251 static inline int dasd_path_get_fcs_device(struct dasd_device *device)
1252 {
1253 	u8 fc_sec = 0;
1254 	int chp;
1255 
1256 	for (chp = 0; chp < 8; chp++) {
1257 		if (device->opm & (0x80 >> chp)) {
1258 			fc_sec = device->path[chp].fc_security;
1259 			break;
1260 		}
1261 	}
1262 	for (; chp < 8; chp++) {
1263 		if (device->opm & (0x80 >> chp))
1264 			if (device->path[chp].fc_security != fc_sec)
1265 				return -EINVAL;
1266 	}
1267 
1268 	return fc_sec;
1269 }
1270 
1271 /*
1272  * add functions for path masks
1273  * the existing path mask will be extended by the given path mask
1274  */
1275 static inline void dasd_path_add_tbvpm(struct dasd_device *device, __u8 pm)
1276 {
1277 	int chp;
1278 
1279 	for (chp = 0; chp < 8; chp++)
1280 		if (pm & (0x80 >> chp))
1281 			dasd_path_verify(device, chp);
1282 }
1283 
1284 static inline __u8 dasd_path_get_notoperpm(struct dasd_device *device)
1285 {
1286 	int chp;
1287 	__u8 nopm = 0x00;
1288 
1289 	for (chp = 0; chp < 8; chp++)
1290 		if (dasd_path_is_nohpf(device, chp) ||
1291 		    dasd_path_is_ifcc(device, chp) ||
1292 		    dasd_path_is_cuir(device, chp) ||
1293 		    dasd_path_is_miscabled(device, chp))
1294 			nopm |= 0x80 >> chp;
1295 	return nopm;
1296 }
1297 
1298 static inline void dasd_path_add_opm(struct dasd_device *device, __u8 pm)
1299 {
1300 	int chp;
1301 
1302 	for (chp = 0; chp < 8; chp++)
1303 		if (pm & (0x80 >> chp)) {
1304 			dasd_path_operational(device, chp);
1305 			/*
1306 			 * if the path is used
1307 			 * it should not be in one of the negative lists
1308 			 */
1309 			dasd_path_clear_nohpf(device, chp);
1310 			dasd_path_clear_cuir(device, chp);
1311 			dasd_path_clear_cable(device, chp);
1312 			dasd_path_clear_ifcc(device, chp);
1313 		}
1314 }
1315 
1316 static inline void dasd_path_add_cablepm(struct dasd_device *device, __u8 pm)
1317 {
1318 	int chp;
1319 
1320 	for (chp = 0; chp < 8; chp++)
1321 		if (pm & (0x80 >> chp))
1322 			dasd_path_miscabled(device, chp);
1323 }
1324 
1325 static inline void dasd_path_add_cuirpm(struct dasd_device *device, __u8 pm)
1326 {
1327 	int chp;
1328 
1329 	for (chp = 0; chp < 8; chp++)
1330 		if (pm & (0x80 >> chp))
1331 			dasd_path_cuir(device, chp);
1332 }
1333 
1334 static inline void dasd_path_add_ifccpm(struct dasd_device *device, __u8 pm)
1335 {
1336 	int chp;
1337 
1338 	for (chp = 0; chp < 8; chp++)
1339 		if (pm & (0x80 >> chp))
1340 			dasd_path_ifcc(device, chp);
1341 }
1342 
1343 static inline void dasd_path_add_nppm(struct dasd_device *device, __u8 pm)
1344 {
1345 	int chp;
1346 
1347 	for (chp = 0; chp < 8; chp++)
1348 		if (pm & (0x80 >> chp))
1349 			dasd_path_nonpreferred(device, chp);
1350 }
1351 
1352 static inline void dasd_path_add_nohpfpm(struct dasd_device *device, __u8 pm)
1353 {
1354 	int chp;
1355 
1356 	for (chp = 0; chp < 8; chp++)
1357 		if (pm & (0x80 >> chp))
1358 			dasd_path_nohpf(device, chp);
1359 }
1360 
1361 static inline void dasd_path_add_ppm(struct dasd_device *device, __u8 pm)
1362 {
1363 	int chp;
1364 
1365 	for (chp = 0; chp < 8; chp++)
1366 		if (pm & (0x80 >> chp))
1367 			dasd_path_preferred(device, chp);
1368 }
1369 
1370 static inline void dasd_path_add_fcsecpm(struct dasd_device *device, __u8 pm)
1371 {
1372 	int chp;
1373 
1374 	for (chp = 0; chp < 8; chp++)
1375 		if (pm & (0x80 >> chp))
1376 			dasd_path_fcsec(device, chp);
1377 }
1378 
1379 /*
1380  * set functions for path masks
1381  * the existing path mask will be replaced by the given path mask
1382  */
1383 static inline void dasd_path_set_tbvpm(struct dasd_device *device, __u8 pm)
1384 {
1385 	int chp;
1386 
1387 	for (chp = 0; chp < 8; chp++)
1388 		if (pm & (0x80 >> chp))
1389 			dasd_path_verify(device, chp);
1390 		else
1391 			dasd_path_clear_verify(device, chp);
1392 }
1393 
1394 static inline void dasd_path_set_opm(struct dasd_device *device, __u8 pm)
1395 {
1396 	int chp;
1397 
1398 	for (chp = 0; chp < 8; chp++) {
1399 		dasd_path_clear_oper(device, chp);
1400 		if (pm & (0x80 >> chp)) {
1401 			dasd_path_operational(device, chp);
1402 			/*
1403 			 * if the path is used
1404 			 * it should not be in one of the negative lists
1405 			 */
1406 			dasd_path_clear_nohpf(device, chp);
1407 			dasd_path_clear_cuir(device, chp);
1408 			dasd_path_clear_cable(device, chp);
1409 			dasd_path_clear_ifcc(device, chp);
1410 		}
1411 	}
1412 }
1413 
1414 /*
1415  * remove functions for path masks
1416  * the existing path mask will be cleared with the given path mask
1417  */
1418 static inline void dasd_path_remove_opm(struct dasd_device *device, __u8 pm)
1419 {
1420 	int chp;
1421 
1422 	for (chp = 0; chp < 8; chp++) {
1423 		if (pm & (0x80 >> chp))
1424 			dasd_path_clear_oper(device, chp);
1425 	}
1426 }
1427 
1428 /*
1429  * add the newly available path to the to be verified pm and remove it from
1430  * normal operation until it is verified
1431  */
1432 static inline void dasd_path_available(struct dasd_device *device, int chp)
1433 {
1434 	dasd_path_clear_oper(device, chp);
1435 	dasd_path_verify(device, chp);
1436 }
1437 
1438 static inline void dasd_path_notoper(struct dasd_device *device, int chp)
1439 {
1440 	dasd_path_clear_oper(device, chp);
1441 	dasd_path_clear_preferred(device, chp);
1442 	dasd_path_clear_nonpreferred(device, chp);
1443 }
1444 
1445 static inline void dasd_path_fcsec_update(struct dasd_device *device, int chp)
1446 {
1447 	dasd_path_fcsec(device, chp);
1448 }
1449 
1450 /*
1451  * remove all paths from normal operation
1452  */
1453 static inline void dasd_path_no_path(struct dasd_device *device)
1454 {
1455 	int chp;
1456 
1457 	for (chp = 0; chp < 8; chp++)
1458 		dasd_path_notoper(device, chp);
1459 
1460 	dasd_path_clear_all_verify(device);
1461 }
1462 
1463 /* end - path handling */
1464 
1465 #endif				/* DASD_H */
1466