Merge tag 'probes-fixes-v6.16-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-block.git] / drivers / s390 / block / dasd_int.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
138c014d 2/*
1da177e4 3 * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
138c014d 4 * Horst Hummel <Horst.Hummel@de.ibm.com>
1da177e4
LT
5 * Martin Schwidefsky <schwidefsky@de.ibm.com>
6 * Bugreports.to..: <Linux390@de.ibm.com>
d41dd122 7 * Copyright IBM Corp. 1999, 2009
1da177e4
LT
8 */
9
10#ifndef DASD_INT_H
11#define DASD_INT_H
12
1da177e4
LT
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.
90f0094d 22 * unfmt: the device could not be analyzed (format is unknown).
1da177e4
LT
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
90f0094d
HH
43#define DASD_STATE_UNFMT 3
44#define DASD_STATE_READY 4
45#define DASD_STATE_ONLINE 5
1da177e4
LT
46
47#include <linux/module.h>
48#include <linux/wait.h>
49#include <linux/blkdev.h>
1da177e4
LT
50#include <linux/hdreg.h>
51#include <linux/interrupt.h>
e108cebb 52#include <linux/log2.h>
1da177e4
LT
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>
c9346151 58#include <linux/bitops.h>
e443343e 59#include <linux/blk-mq.h>
1da177e4 60
68b781fe
SH
61/* DASD discipline magic */
62#define DASD_ECKD_MAGIC 0xC5C3D2C4
63#define DASD_DIAG_MAGIC 0xC4C9C1C7
64#define DASD_FBA_MAGIC 0xC6C2C140
65
1da177e4
LT
66/*
67 * SECTION: Type definitions
68 */
69struct dasd_device;
8e09f215 70struct dasd_block;
1da177e4
LT
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
f60c768c
SH
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
2dedf0d9
SH
83/* lock class for nested cdev lock */
84#define CDEV_NESTED_FIRST 1
85#define CDEV_NESTED_SECOND 2
86
1da177e4
LT
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...) \
91do { \
92 debug_sprintf_event(d_device->debug_area, \
93 d_level, \
94 d_str "\n", \
95 d_data); \
96} while(0)
97
1da177e4
LT
98#define DBF_EVENT(d_level, d_str, d_data...)\
99do { \
100 debug_sprintf_event(dasd_debug_area, \
101 d_level,\
102 d_str "\n", \
103 d_data); \
104} while(0)
105
b8ed5dd5
SH
106#define DBF_EVENT_DEVID(d_level, d_cdev, d_str, d_data...) \
107do { \
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
1da177e4
LT
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
28b841b3
JH
126/* Macro to calculate number of blocks per page */
127#define BLOCKS_PER_PAGE(blksize) (PAGE_SIZE / blksize)
128
1da177e4
LT
129struct dasd_ccw_req {
130 unsigned int magic; /* Eye catcher */
61d38832 131 int intrc; /* internal error, e.g. from start_IO */
8e09f215
SW
132 struct list_head devlist; /* for dasd_device request queue */
133 struct list_head blocklist; /* for dasd_block request queue */
8e09f215
SW
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 */
29b8dd9d 137 struct dasd_device *basedev; /* base device if no block->base */
f3eb5384 138 void *cpaddr; /* address of ccw or tcw */
61d38832 139 short retries; /* A retry counter */
f3eb5384 140 unsigned char cpmode; /* 0 = cmd mode, 1 = itcw */
8e09f215 141 char status; /* status of this request */
61d38832 142 char lpm; /* logical path mask */
1da177e4 143 unsigned long flags; /* flags of this request */
e443343e 144 struct dasd_queue *dq;
1da177e4 145 unsigned long starttime; /* jiffies time of request start */
7c8faa86 146 unsigned long expires; /* expiration period in jiffies */
1da177e4 147 void *data; /* pointer to data area */
1da177e4
LT
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 */
c5205f2f 151 void *mem_chunk;
1da177e4 152
7bf76f01
JH
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 */
1da177e4 157
8e09f215
SW
158 void (*callback)(struct dasd_ccw_req *, void *data);
159 void *callback_data;
5e6bdd37 160 unsigned int proc_bytes; /* bytes for partial completion */
71f38716 161 unsigned int trkcount; /* count formatted tracks */
1da177e4
LT
162};
163
138c014d 164/*
1da177e4
LT
165 * dasd_ccw_req -> status can be:
166 */
8e09f215
SW
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 */
73ac36ea 179#define DASD_CQR_SUCCESS 0x85 /* request was successful */
8e09f215 180
7c8faa86
SH
181/* default expiration time*/
182#define DASD_EXPIRES 300
183#define DASD_EXPIRES_MAX 40000000
1f1ee9ad
HR
184#define DASD_RETRIES 256
185#define DASD_RETRIES_MAX 32768
1da177e4
LT
186
187/* per dasd_ccw_req flags */
188#define DASD_CQR_FLAGS_USE_ERP 0 /* use ERP for this request */
1c01b8a5 189#define DASD_CQR_FLAGS_FAILFAST 1 /* FAILFAST */
a4d26c6a 190#define DASD_CQR_VERIFY_PATH 2 /* path verification request */
5a27e60d
SW
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 */
8fd57520
JH
195/*
196 * The following flags are used to suppress output of certain errors.
8fd57520
JH
197 */
198#define DASD_CQR_SUPPRESS_NRF 4 /* Suppress 'No Record Found' error */
7db40423 199#define DASD_CQR_SUPPRESS_IT 5 /* Suppress 'Invalid Track' error*/
8fd57520 200#define DASD_CQR_SUPPRESS_IL 6 /* Suppress 'Incorrect Length' error */
ab24fbd3 201#define DASD_CQR_SUPPRESS_CR 7 /* Suppress 'Command Reject' error */
1da177e4 202
e443343e
SH
203#define DASD_REQ_PER_DEV 4
204
1da177e4
LT
205/* Signature for error recovery functions. */
206typedef struct dasd_ccw_req *(*dasd_erp_fn_t) (struct dasd_ccw_req *);
207
46d1c03c
JH
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
2dedf0d9
SH
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
223struct 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
f7cf2242
HC
233#define DASD_UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 + \
234 /* SSID */ 4 + 1 + /* unit addr */ 2 + 1 + \
235 /* vduit */ 32 + 1)
236
3f217cce
SH
237/*
238 * PPRC Status data
239 */
240struct 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
247struct 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 */
5029c5e4 257 __u16 prim_cu_ssid; /* 22-23 Primary Control Unit SSID */
3f217cce
SH
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
263struct dasd_pprc_data_sc4 {
264 struct dasd_pprc_header header;
265 struct dasd_pprc_dev_info dev_info[5];
266} __packed;
267
a91ff09d
SH
268#define DASD_BUS_ID_SIZE 20
269#define DASD_CP_ENTRIES 5
270
271struct dasd_copy_entry {
272 char busid[DASD_BUS_ID_SIZE];
273 struct dasd_device *device;
274 bool primary;
275 bool configured;
276};
277
278struct dasd_copy_relation {
279 struct dasd_copy_entry entry[DASD_CP_ENTRIES];
280 struct dasd_copy_entry *active;
281};
282
283int dasd_devmap_set_device_copy_relation(struct ccw_device *,
284 bool pprc_enabled);
285
1da177e4
LT
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 */
292struct 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 */
0127a47f 296 bool has_discard;
1da177e4
LT
297
298 struct list_head list; /* used for list of disciplines */
299
8e09f215
SW
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
a4d26c6a
SW
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 */
4d063e64 325 int (*pe_handler)(struct dasd_device *, __u8, __u8);
a4d26c6a 326
8e09f215
SW
327 /*
328 * Last things to do when a device is set online, and first things
329 * when it is set offline.
330 */
d42e1712 331 int (*basic_to_ready) (struct dasd_device *);
8e09f215 332 int (*online_to_ready) (struct dasd_device *);
daa991bf 333 int (*basic_to_known)(struct dasd_device *);
8e09f215 334
0127a47f 335 unsigned int (*max_sectors)(struct dasd_block *);
d42e1712 336 /* (struct dasd_device *);
8e09f215
SW
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
8fd57520
JH
340 * formats the device and check_device_format compares the format of
341 * a device with the expected format_data.
8e09f215
SW
342 * handle_terminated_request allows to examine a cqr and prepare
343 * it for retry.
344 */
1da177e4 345 struct dasd_ccw_req *(*build_cp) (struct dasd_device *,
8e09f215 346 struct dasd_block *,
1da177e4
LT
347 struct request *);
348 int (*start_IO) (struct dasd_ccw_req *);
349 int (*term_IO) (struct dasd_ccw_req *);
8e09f215 350 void (*handle_terminated_request) (struct dasd_ccw_req *);
d42e1712 351 int (*format_device) (struct dasd_device *,
8fd57520
JH
352 struct format_data_t *, int);
353 int (*check_device_format)(struct dasd_device *,
354 struct format_check_t *, int);
1da177e4 355 int (*free_cp) (struct dasd_ccw_req *, struct request *);
8e09f215
SW
356
357 /*
358 * Error recovery functions. examine_error() returns a value that
359 * indicates what to do for an error condition. If examine_error()
138c014d 360 * returns 'dasd_era_recover' erp_action() is called to create a
8e09f215
SW
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 */
1da177e4
LT
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 *);
aeec92ca 370 void (*dump_sense_dbf) (struct dasd_device *, struct irb *, char *);
5a27e60d
SW
371 void (*check_for_device_change) (struct dasd_device *,
372 struct dasd_ccw_req *,
373 struct irb *);
8e09f215 374
1da177e4 375 /* i/o control functions. */
8e09f215 376 int (*fill_geometry) (struct dasd_block *, struct hd_geometry *);
1da177e4 377 int (*fill_info) (struct dasd_device *, struct dasd_information2_t *);
8e09f215 378 int (*ioctl) (struct dasd_block *, unsigned int, void __user *);
d41dd122 379
501183f2
SH
380 /* reload device after state change */
381 int (*reload) (struct dasd_device *);
2dedf0d9
SH
382
383 int (*get_uid) (struct dasd_device *, struct dasd_uid *);
f1633031 384 void (*kick_validate) (struct dasd_device *);
5db8440c 385 int (*check_attention)(struct dasd_device *, __u8);
5a3b7b11
SH
386 int (*host_access_count)(struct dasd_device *);
387 int (*hosts_print)(struct dasd_device *, struct seq_file *);
a521b048
SH
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);
c729696b
JH
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 *);
91dc4a19 401 int (*release_space)(struct dasd_device *, struct format_data_t *);
c729696b
JH
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 *);
9e12e54c 408 int (*ext_pool_exhaust)(struct dasd_device *, struct dasd_ccw_req *);
5e6bdd37
SH
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 *);
3f217cce 412 int (*pprc_status)(struct dasd_device *, struct dasd_pprc_data_sc4 *);
a91ff09d 413 bool (*pprc_enabled)(struct dasd_device *);
413862ca 414 int (*copy_pair_swap)(struct dasd_device *, char *, char *);
32ff8ce0 415 int (*device_ping)(struct dasd_device *);
1da177e4
LT
416};
417
418extern struct dasd_discipline *dasd_diag_discipline_pointer;
419
9558a8e9
SH
420/* Trigger IDs for extended error reporting DASD EER and autoquiesce */
421enum 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)
20c64468 436
c9346151
SH
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
a521b048 446#define DASD_PATH_IFCC 8
4d063e64 447#define DASD_PATH_FCSEC 9
c9346151 448
a521b048
SH
449#define DASD_THRHLD_MAX 4294967295U
450#define DASD_INTERVAL_MAX 4294967295U
c9346151 451
19508b20
JH
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"
459static 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
469static 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
a4d26c6a 481struct dasd_path {
c9346151 482 unsigned long flags;
a521b048
SH
483 u8 cssid;
484 u8 ssid;
485 u8 chpid;
c9346151 486 struct dasd_conf_data *conf_data;
a521b048 487 atomic_t error_count;
7bf76f01 488 unsigned long errorclk;
19508b20
JH
489 u8 fc_security;
490 struct kobject kobj;
491 bool in_sysfs;
a4d26c6a
SW
492};
493
19508b20
JH
494#define to_dasd_path(path) container_of(path, struct dasd_path, kobj)
495
496static 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
c9346151 501
4fa52aa7
SW
502struct 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 */
bd7a9b37 516 struct timespec64 starttod; /* time of start or last reset */
4fa52aa7
SW
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 */
d2907225
SH
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 */
4fa52aa7
SW
533};
534
535struct dasd_profile {
536 struct dentry *dentry;
537 struct dasd_profile_info *data;
538 spinlock_t lock;
539};
540
5e6bdd37
SH
541struct dasd_format_entry {
542 struct list_head list;
543 sector_t track;
544};
545
1da177e4
LT
546struct dasd_device {
547 /* Block device stuff. */
8e09f215
SW
548 struct dasd_block *block;
549
1da177e4 550 unsigned int devindex;
138c014d
HH
551 unsigned long flags; /* per device flags */
552 unsigned short features; /* copy of devmap-features (read-only!) */
1da177e4 553
20c64468
SW
554 /* extended error reporting stuff (eer) */
555 struct dasd_ccw_req *eer_cqr;
556
1da177e4
LT
557 /* Device discipline stuff. */
558 struct dasd_discipline *discipline;
aa88861f 559 struct dasd_discipline *base_discipline;
543691a4 560 void *private;
c9346151
SH
561 struct dasd_path path[8];
562 __u8 opm;
1da177e4
LT
563
564 /* Device state and target state. */
565 int state, target;
9eb25122 566 struct mutex state_mutex;
1da177e4
LT
567 int stopped; /* device (ccw_device_start) was stopped */
568
8e09f215 569 /* reference count. */
1da177e4 570 atomic_t ref_count;
1da177e4
LT
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;
5e2b17e7 577 void *ese_mem;
1da177e4
LT
578 struct list_head ccw_chunks;
579 struct list_head erp_chunks;
5e2b17e7 580 struct list_head ese_chunks;
1da177e4
LT
581
582 atomic_t tasklet_scheduled;
583 struct tasklet_struct tasklet;
584 struct work_struct kick_work;
501183f2 585 struct work_struct reload_device;
f1633031 586 struct work_struct kick_validate;
59a9ed5f 587 struct work_struct suc_work;
a521b048 588 struct work_struct requeue_requests;
1da177e4
LT
589 struct timer_list timer;
590
591 debug_info_t *debug_area;
592
593 struct ccw_device *cdev;
594
8e09f215
SW
595 /* hook for alias management */
596 struct list_head alias_list;
7c8faa86
SH
597
598 /* default expiration time in s */
599 unsigned long default_expires;
1f1ee9ad 600 unsigned long default_retries;
4fa52aa7 601
3d71ad32
HR
602 unsigned long blk_timeout;
603
a521b048
SH
604 unsigned long path_thrhld;
605 unsigned long path_interval;
606
4fa52aa7 607 struct dentry *debugfs_dentry;
5a3b7b11 608 struct dentry *hosts_dentry;
4fa52aa7 609 struct dasd_profile profile;
5e6bdd37 610 struct dasd_format_entry format_entry;
19508b20 611 struct kset *paths_info;
a91ff09d 612 struct dasd_copy_relation *copy;
1cee2975 613 unsigned long aq_mask;
0c1a1474 614 unsigned int aq_timeouts;
8e09f215
SW
615};
616
617struct dasd_block {
618 /* Block device stuff. */
619 struct gendisk *gdp;
8e09f215 620 spinlock_t request_queue_lock;
e443343e 621 struct blk_mq_tag_set tag_set;
c8e108d8 622 struct file *bdev_file;
8e09f215
SW
623 atomic_t open_count;
624
7bf76f01 625 unsigned long blocks; /* size of volume in blocks */
8e09f215
SW
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
4fa52aa7
SW
637 struct dentry *debugfs_dentry;
638 struct dasd_profile profile;
5e6bdd37
SH
639
640 struct list_head format_list;
641 spinlock_t format_lock;
71f38716 642 atomic_t trkcount;
1da177e4
LT
643};
644
5db8440c
SH
645struct dasd_attention_data {
646 struct dasd_device *device;
647 __u8 lpum;
648};
8e09f215 649
e443343e
SH
650struct dasd_queue {
651 spinlock_t lock;
652};
653
1da177e4
LT
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 */
8e09f215 659#define DASD_STOPPED_SU 16 /* summary unit check handling */
413862ca 660#define DASD_STOPPED_PPRC 32 /* PPRC swap */
9e12e54c 661#define DASD_STOPPED_NOSPC 128 /* no space left */
1da177e4
LT
662
663/* per device flags */
1da177e4 664#define DASD_FLAG_OFFLINE 3 /* device is in offline processing */
20c64468
SW
665#define DASD_FLAG_EER_SNSS 4 /* A SNSS is required */
666#define DASD_FLAG_EER_IN_USE 5 /* A SNSS request is running */
33b62a30
SW
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 */
5a27e60d
SW
671#define DASD_FLAG_IS_RESERVED 7 /* The device is reserved */
672#define DASD_FLAG_LOCK_STOLEN 8 /* The device lock was stolen */
c8d1c0ff 673#define DASD_FLAG_SUSPENDED 9 /* The device was suspended */
d07dc5d8
SH
674#define DASD_FLAG_SAFE_OFFLINE 10 /* safe offline processing requested*/
675#define DASD_FLAG_SAFE_OFFLINE_RUNNING 11 /* safe offline running */
5ea34a01 676#define DASD_FLAG_ABORTALL 12 /* Abort all noretry requests */
1eb38023 677#define DASD_FLAG_PATH_VERIFY 13 /* Path verification worker running */
59a9ed5f 678#define DASD_FLAG_SUC 14 /* unhandled summary unit check */
5a27e60d 679
5ea34a01
HR
680#define DASD_SLEEPON_START_TAG ((void *) 1)
681#define DASD_SLEEPON_END_TAG ((void *) 2)
1da177e4
LT
682
683void dasd_put_device_wake(struct dasd_device *);
684
413862ca
SH
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
1da177e4
LT
701/*
702 * Reference count inliners
703 */
704static inline void
705dasd_get_device(struct dasd_device *device)
706{
707 atomic_inc(&device->ref_count);
708}
709
710static inline void
711dasd_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 */
721struct dasd_mchunk
722{
723 struct list_head list;
724 unsigned long size;
725} __attribute__ ((aligned(8)));
726
727static inline void
728dasd_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
739static inline void *
740dasd_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
761static inline void
762dasd_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 */
798static inline int
799dasd_check_blocksize(int bsize)
800{
e108cebb 801 if (bsize < 512 || bsize > 4096 || !is_power_of_2(bsize))
1da177e4
LT
802 return -EMEDIUMTYPE;
803 return 0;
804}
805
5b53a405
SH
806/*
807 * return the callback data of the original request in case there are
808 * ERP requests build on top of it
809 */
810static 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
1da177e4 818/* externals in dasd.c */
4fa52aa7
SW
819#define DASD_PROFILE_OFF 0
820#define DASD_PROFILE_ON 1
821#define DASD_PROFILE_GLOBAL_ONLY 2
1da177e4
LT
822
823extern debug_info_t *dasd_debug_area;
8ea55c95 824extern struct dasd_profile dasd_global_profile;
4fa52aa7 825extern unsigned int dasd_global_profile_level;
83d5cde4 826extern const struct block_device_operations dasd_device_operations;
c68f4f4e 827extern struct blk_mq_ops dasd_mq_ops;
1da177e4 828
e18b890b 829extern struct kmem_cache *dasd_page_cache;
1da177e4 830
1da177e4 831struct dasd_ccw_req *
c5205f2f 832dasd_smalloc_request(int, int, int, struct dasd_device *, struct dasd_ccw_req *);
5e2b17e7 833struct dasd_ccw_req *dasd_fmalloc_request(int, int, int, struct dasd_device *);
1da177e4 834void dasd_sfree_request(struct dasd_ccw_req *, struct dasd_device *);
5e2b17e7 835void dasd_ffree_request(struct dasd_ccw_req *, struct dasd_device *);
5915a873 836void dasd_wakeup_cb(struct dasd_ccw_req *, void *);
1da177e4 837
1da177e4
LT
838struct dasd_device *dasd_alloc_device(void);
839void dasd_free_device(struct dasd_device *);
840
8e09f215
SW
841struct dasd_block *dasd_alloc_block(void);
842void dasd_free_block(struct dasd_block *);
843
9bdb4833 844enum blk_eh_timer_return dasd_times_out(struct request *req);
3d71ad32 845
1da177e4
LT
846void dasd_enable_device(struct dasd_device *);
847void dasd_set_target_state(struct dasd_device *, int);
848void dasd_kick_device(struct dasd_device *);
501183f2 849void dasd_reload_device(struct dasd_device *);
a521b048 850void dasd_schedule_requeue(struct dasd_device *);
1da177e4
LT
851
852void dasd_add_request_head(struct dasd_ccw_req *);
853void dasd_add_request_tail(struct dasd_ccw_req *);
854int dasd_start_IO(struct dasd_ccw_req *);
855int dasd_term_IO(struct dasd_ccw_req *);
8e09f215
SW
856void dasd_schedule_device_bh(struct dasd_device *);
857void dasd_schedule_block_bh(struct dasd_block *);
1da177e4 858int dasd_sleep_on(struct dasd_ccw_req *);
d42e1712 859int dasd_sleep_on_queue(struct list_head *);
1da177e4 860int dasd_sleep_on_immediatly(struct dasd_ccw_req *);
bcf36768 861int dasd_sleep_on_queue_interruptible(struct list_head *);
1da177e4 862int dasd_sleep_on_interruptible(struct dasd_ccw_req *);
8e09f215
SW
863void dasd_device_set_timer(struct dasd_device *, int);
864void dasd_device_clear_timer(struct dasd_device *);
865void dasd_block_set_timer(struct dasd_block *, int);
866void dasd_block_clear_timer(struct dasd_block *);
1da177e4 867int dasd_cancel_req(struct dasd_ccw_req *);
8e09f215 868int dasd_flush_device_queue(struct dasd_device *);
e03c5941 869int dasd_generic_probe(struct ccw_device *);
c020d722 870void dasd_generic_free_discipline(struct dasd_device *);
1da177e4
LT
871void dasd_generic_remove (struct ccw_device *cdev);
872int dasd_generic_set_online(struct ccw_device *, struct dasd_discipline *);
873int dasd_generic_set_offline (struct ccw_device *cdev);
874int dasd_generic_notify(struct ccw_device *, int);
a4d26c6a
SW
875int dasd_generic_last_path_gone(struct dasd_device *);
876int dasd_generic_path_operational(struct dasd_device *);
4679e893 877void dasd_generic_shutdown(struct ccw_device *);
a4d26c6a 878
8e09f215 879void dasd_generic_handle_state_change(struct dasd_device *);
a23ed009 880enum uc_todo dasd_generic_uc_handler(struct ccw_device *, struct irb *);
a4d26c6a
SW
881void dasd_generic_path_event(struct ccw_device *, int *);
882int dasd_generic_verify_path(struct dasd_device *, __u8);
9e12e54c
JH
883void dasd_generic_space_exhaust(struct dasd_device *, struct dasd_ccw_req *);
884void dasd_generic_space_avail(struct dasd_device *);
1da177e4 885
413862ca
SH
886int dasd_generic_requeue_all_requests(struct dasd_device *);
887
68b781fe 888int dasd_generic_read_dev_chars(struct dasd_device *, int, void *, int);
f3eb5384 889char *dasd_get_sense(struct irb *);
17283b56 890
eb6e199b
SW
891void dasd_device_set_stop_bits(struct dasd_device *, int);
892void dasd_device_remove_stop_bits(struct dasd_device *, int);
893
33b62a30
SW
894int dasd_device_is_ro(struct dasd_device *);
895
4fa52aa7
SW
896void dasd_profile_reset(struct dasd_profile *);
897int dasd_profile_on(struct dasd_profile *);
898void dasd_profile_off(struct dasd_profile *);
4fa52aa7 899char *dasd_get_user_string(const char __user *, size_t);
33b62a30 900
1da177e4
LT
901/* externals in dasd_devmap.c */
902extern int dasd_max_devindex;
903extern int dasd_probeonly;
904extern int dasd_autodetect;
40545573 905extern int dasd_nopav;
f3eb5384 906extern int dasd_nofcx;
1da177e4
LT
907
908int dasd_devmap_init(void);
909void dasd_devmap_exit(void);
910
911struct dasd_device *dasd_create_device(struct ccw_device *);
912void dasd_delete_device(struct dasd_device *);
913
f24acd45
HH
914int dasd_get_feature(struct ccw_device *, int);
915int dasd_set_feature(struct ccw_device *, int, int);
916
1987c551 917extern const struct attribute_group *dasd_dev_groups[];
19508b20
JH
918void dasd_path_create_kobj(struct dasd_device *, int);
919void dasd_path_create_kobjects(struct dasd_device *);
ac55ad2b 920void dasd_path_remove_kobjects(struct dasd_device *);
1da177e4
LT
921
922struct dasd_device *dasd_device_from_cdev(struct ccw_device *);
a00bfd71 923struct dasd_device *dasd_device_from_cdev_locked(struct ccw_device *);
1da177e4
LT
924struct dasd_device *dasd_device_from_devindex(int);
925
65f8da47
SW
926void dasd_add_link_to_gendisk(struct gendisk *, struct dasd_device *);
927struct dasd_device *dasd_device_from_gendisk(struct gendisk *);
928
3b1bea01 929int dasd_parse(void) __init;
69f90f6a 930int dasd_busid_known(const char *);
1da177e4
LT
931
932/* externals in dasd_gendisk.c */
933int dasd_gendisk_init(void);
934void dasd_gendisk_exit(void);
8e09f215
SW
935int dasd_gendisk_alloc(struct dasd_block *);
936void dasd_gendisk_free(struct dasd_block *);
937int dasd_scan_partitions(struct dasd_block *);
938void dasd_destroy_partitions(struct dasd_block *);
1da177e4
LT
939
940/* externals in dasd_ioctl.c */
05bdb996
CH
941int dasd_ioctl(struct block_device *bdev, blk_mode_t mode, unsigned int cmd,
942 unsigned long arg);
2c1b6ec1 943int dasd_set_read_only(struct block_device *bdev, bool ro);
1da177e4
LT
944
945/* externals in dasd_proc.c */
946int dasd_proc_init(void);
947void dasd_proc_exit(void);
948
949/* externals in dasd_erp.c */
950struct dasd_ccw_req *dasd_default_erp_action(struct dasd_ccw_req *);
951struct dasd_ccw_req *dasd_default_erp_postaction(struct dasd_ccw_req *);
169bbdac 952struct dasd_ccw_req *dasd_alloc_erp_request(unsigned int, int, int,
1da177e4
LT
953 struct dasd_device *);
954void dasd_free_erp_request(struct dasd_ccw_req *, struct dasd_device *);
955void dasd_log_sense(struct dasd_ccw_req *, struct irb *);
fc19f381 956void dasd_log_sense_dbf(struct dasd_ccw_req *cqr, struct irb *irb);
1da177e4 957
1da177e4 958/* externals in dasd_3990_erp.c */
1da177e4 959struct dasd_ccw_req *dasd_3990_erp_action(struct dasd_ccw_req *);
f60c768c 960void dasd_3990_erp_handle_sim(struct dasd_device *, char *);
1da177e4 961
20c64468
SW
962/* externals in dasd_eer.c */
963#ifdef CONFIG_DASD_EER
964int dasd_eer_init(void);
965void dasd_eer_exit(void);
966int dasd_eer_enable(struct dasd_device *);
967void dasd_eer_disable(struct dasd_device *);
968void dasd_eer_write(struct dasd_device *, struct dasd_ccw_req *cqr,
969 unsigned int id);
970void dasd_eer_snss(struct dasd_device *);
971
972static 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
c9346151
SH
986
987/* DASD path handling functions */
988
989/*
990 * helper functions to modify bit masks for a given channel path for a device
991 */
992static 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
997static 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
1002static inline void dasd_path_verify(struct dasd_device *device, int chp)
1003{
1004 __set_bit(DASD_PATH_TBV, &device->path[chp].flags);
1005}
1006
1007static 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
1012static 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
4d063e64
JH
1020static inline void dasd_path_fcsec(struct dasd_device *device, int chp)
1021{
1022 __set_bit(DASD_PATH_FCSEC, &device->path[chp].flags);
1023}
1024
1025static 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
1030static 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
1035static 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
c9346151
SH
1043static 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
1049static inline void dasd_path_nonpreferred(struct dasd_device *device, int chp)
1050{
1051 __set_bit(DASD_PATH_NPP, &device->path[chp].flags);
1052}
1053
1054static 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
1059static 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
1065static inline void dasd_path_preferred(struct dasd_device *device, int chp)
1066{
1067 __set_bit(DASD_PATH_PP, &device->path[chp].flags);
1068}
1069
1070static 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
1075static 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
1081static 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
1087static 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
1092static inline void dasd_path_cuir(struct dasd_device *device, int chp)
1093{
1094 __set_bit(DASD_PATH_CUIR, &device->path[chp].flags);
1095}
1096
1097static 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
1102static 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
a521b048
SH
1107static inline void dasd_path_ifcc(struct dasd_device *device, int chp)
1108{
1109 set_bit(DASD_PATH_IFCC, &device->path[chp].flags);
1110}
1111
1112static 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
1117static 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
c9346151
SH
1122static 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
1127static inline void dasd_path_miscabled(struct dasd_device *device, int chp)
1128{
1129 __set_bit(DASD_PATH_MISCABLED, &device->path[chp].flags);
1130}
1131
1132static 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
1137static inline void dasd_path_nohpf(struct dasd_device *device, int chp)
1138{
1139 __set_bit(DASD_PATH_NOHPF, &device->path[chp].flags);
1140}
1141
1142static 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
1152static inline __u8 dasd_path_get_opm(struct dasd_device *device)
1153{
1154 return device->opm;
1155}
1156
1157static 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
4d063e64
JH
1168static 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
c9346151
SH
1179static 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
1191static 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
1202static 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
1213static 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
a521b048
SH
1224static 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
c9346151
SH
1235static 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
19508b20
JH
1246static inline u8 dasd_path_get_fcs_path(struct dasd_device *device, int chp)
1247{
1248 return device->path[chp].fc_security;
1249}
1250
1251static 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
c9346151
SH
1271/*
1272 * add functions for path masks
1273 * the existing path mask will be extended by the given path mask
1274 */
1275static 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
a521b048
SH
1284static 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
c9346151
SH
1298static 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);
a521b048 1312 dasd_path_clear_ifcc(device, chp);
c9346151
SH
1313 }
1314}
1315
1316static 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
1325static 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
a521b048
SH
1334static 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
c9346151
SH
1343static 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
1352static 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
1361static 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
a8e5d491
SH
1370static 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
c9346151
SH
1379/*
1380 * set functions for path masks
1381 * the existing path mask will be replaced by the given path mask
1382 */
1383static 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
1394static 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);
a521b048 1409 dasd_path_clear_ifcc(device, chp);
c9346151
SH
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 */
1418static 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 */
1432static 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
1438static 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
4d063e64
JH
1445static inline void dasd_path_fcsec_update(struct dasd_device *device, int chp)
1446{
1447 dasd_path_fcsec(device, chp);
1448}
1449
c9346151
SH
1450/*
1451 * remove all paths from normal operation
1452 */
1453static 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
1da177e4 1465#endif /* DASD_H */