xref: /openbmc/linux/drivers/s390/char/vmur.h (revision b868a02e)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Linux driver for System z and s390 unit record devices
4  * (z/VM virtual punch, reader, printer)
5  *
6  * Copyright IBM Corp. 2001, 2007
7  * Authors: Malcolm Beattie <beattiem@uk.ibm.com>
8  *	    Michael Holzheu <holzheu@de.ibm.com>
9  *	    Frank Munzert <munzert@de.ibm.com>
10  */
11 
12 #ifndef _VMUR_H_
13 #define _VMUR_H_
14 
15 #include <linux/refcount.h>
16 #include <linux/workqueue.h>
17 
18 #define DEV_CLASS_UR_I 0x20 /* diag210 unit record input device class */
19 #define DEV_CLASS_UR_O 0x10 /* diag210 unit record output device class */
20 /*
21  * we only support z/VM's default unit record devices:
22  * both in SPOOL directory control statement and in CP DEFINE statement
23  *	RDR defaults to 2540 reader
24  *	PUN defaults to 2540 punch
25  *	PRT defaults to 1403 printer
26  */
27 #define READER_PUNCH_DEVTYPE	0x2540
28 #define PRINTER_DEVTYPE		0x1403
29 
30 /* z/VM spool file control block SFBLOK */
31 struct file_control_block {
32 	char reserved_1[8];
33 	char user_owner[8];
34 	char user_orig[8];
35 	__s32 data_recs;
36 	__s16 rec_len;
37 	__s16 file_num;
38 	__u8  file_stat;
39 	__u8  dev_type;
40 	char  reserved_2[6];
41 	char  file_name[12];
42 	char  file_type[12];
43 	char  create_date[8];
44 	char  create_time[8];
45 	char  reserved_3[6];
46 	__u8  file_class;
47 	__u8  sfb_lok;
48 	__u64 distr_code;
49 	__u32 reserved_4;
50 	__u8  current_starting_copy_number;
51 	__u8  sfblock_cntrl_flags;
52 	__u8  reserved_5;
53 	__u8  more_status_flags;
54 	char  rest[200];
55 } __attribute__ ((packed));
56 
57 #define FLG_SYSTEM_HOLD	0x04
58 #define FLG_CP_DUMP	0x10
59 #define FLG_USER_HOLD	0x20
60 #define FLG_IN_USE	0x80
61 
62 /*
63  * A struct urdev is created for each ur device that is made available
64  * via the ccw_device driver model.
65  */
66 struct urdev {
67 	struct ccw_device *cdev;	/* Backpointer to ccw device */
68 	struct mutex io_mutex;		/* Serialises device IO */
69 	struct completion *io_done;	/* do_ur_io waits; irq completes */
70 	struct device *device;
71 	struct cdev *char_device;
72 	struct ccw_dev_id dev_id;	/* device id */
73 	size_t reclen;			/* Record length for *write* CCWs */
74 	int class;			/* VM device class */
75 	int io_request_rc;		/* return code from I/O request */
76 	refcount_t ref_count;		/* reference counter */
77 	wait_queue_head_t wait;		/* wait queue to serialize open */
78 	int open_flag;			/* "urdev is open" flag */
79 	spinlock_t open_lock;		/* serialize critical sections */
80 	struct work_struct uevent_work;	/* work to send uevent */
81 };
82 
83 /*
84  * A struct urfile is allocated at open() time for each device and
85  * freed on release().
86  */
87 struct urfile {
88 	struct urdev *urd;
89 	unsigned int flags;
90 	size_t dev_reclen;
91 	__u16 file_reclen;
92 };
93 
94 /*
95  * Device major/minor definitions.
96  */
97 
98 #define UR_MAJOR 0	/* get dynamic major */
99 /*
100  * We map minor numbers directly to device numbers (0-FFFF) for simplicity.
101  * This avoids having to allocate (and manage) slot numbers.
102  */
103 #define NUM_MINORS 65536
104 
105 /* Limiting each I/O to 511 records limits chan prog to 4KB (511 r/w + 1 NOP) */
106 #define MAX_RECS_PER_IO		511
107 #define WRITE_CCW_CMD		0x01
108 
109 #define TRACE(x...) debug_sprintf_event(vmur_dbf, 1, x)
110 #define CCWDEV_CU_DI(cutype, di) \
111 		CCW_DEVICE(cutype, 0x00), .driver_info = (di)
112 
113 #define FILE_RECLEN_OFFSET	4064 /* reclen offset in spool data block */
114 
115 #endif /* _VMUR_H_ */
116