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