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