1
2
3
4
5
6
7
8
9
10
11
12#include <linux/config.h>
13
14#include <linux/module.h>
15#include <linux/version.h>
16
17#include <linux/major.h>
18#ifndef IBM_TTY3270_MAJOR
19# define IBM_TTY3270_MAJOR 212
20#endif
21#ifndef IBM_FS3270_MAJOR
22# define IBM_FS3270_MAJOR 213
23#endif
24
25
26#include <linux/slab.h>
27#include <asm/irq.h>
28#include <asm/io.h>
29#include <asm/idals.h>
30#include <linux/console.h>
31#include <linux/interrupt.h>
32#include <asm/ebcdic.h>
33#include <asm/uaccess.h>
34#include <linux/proc_fs.h>
35#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0))
36#include <linux/devfs_fs_kernel.h>
37#endif
38
39#define TUB(x) (('3'<<8)|(x))
40#define TUBICMD TUB(3)
41#define TUBOCMD TUB(4)
42#define TUBGETI TUB(7)
43#define TUBGETO TUB(8)
44#define TUBSETMOD TUB(12)
45#define TUBGETMOD TUB(13)
46#define TIOPOLL TUB(32)
47#define TIOPOKE TUB(33)
48#define TIONPOKE TUB(34)
49#define TIOTNORM TUB(35)
50
51
52#define TC_WRITE 0x01
53#define TC_EWRITE 0x05
54#define TC_READMOD 0x06
55#define TC_EWRITEA 0x0d
56#define TC_WRITESF 0x11
57
58
59#define TO_SF 0x1d
60#define TO_SBA 0x11
61#define TO_IC 0x13
62#define TO_PT 0x05
63#define TO_RA 0x3c
64#define TO_SFE 0x29
65#define TO_EUA 0x12
66#define TO_MF 0x2c
67#define TO_SA 0x28
68
69
70#define TF_INPUT 0x40
71#define TF_INPUTN 0x4c
72#define TF_INMDT 0xc1
73#define TF_LOG 0x60
74#define TF_STAT 0x60
75
76
77#define TAT_RESET 0x00
78#define TAT_FIELD 0xc0
79#define TAT_EXTHI 0x41
80#define TAT_COLOR 0x42
81#define TAT_CHARS 0x43
82#define TAT_TRANS 0x46
83
84
85#define TAX_RESET 0x00
86#define TAX_BLINK 0xf1
87#define TAX_REVER 0xf2
88#define TAX_UNDER 0xf4
89
90
91#define TAR_RESET 0x00
92
93
94#define TAC_RESET 0x00
95#define TAC_BLUE 0xf1
96#define TAC_RED 0xf2
97#define TAC_PINK 0xf3
98#define TAC_GREEN 0xf4
99#define TAC_TURQ 0xf5
100#define TAC_YELLOW 0xf6
101#define TAC_WHITE 0xf7
102#define TAC_DEFAULT 0x00
103
104
105#define TW_NONE 0x40
106#define TW_KR 0xc2
107#define TW_PLUSALARM 0x04
108
109
110#define TA_CLEAR 0x6d
111#define TA_PA2 0x6e
112#define TA_ENTER 0x7d
113
114
115#define MIN(a, b) ((a) < (b)? (a): (b))
116
117#define TUB_BUFADR(adr, cpp) \
118 tty3270_tub_bufadr(tubp, adr, cpp)
119
120#define TUB_EBCASC(addr, nr) codepage_convert(tub_ebcasc, addr, nr)
121#define TUB_ASCEBC(addr, nr) codepage_convert(tub_ascebc, addr, nr)
122
123
124
125
126
127
128enum tubmode {
129 TBM_LN,
130 TBM_FS,
131 TBM_FSLN
132};
133enum tubstat {
134 TBS_RUNNING,
135 TBS_MORE,
136 TBS_HOLD
137};
138enum tubcmd {
139 TBC_CONOPEN,
140 TBC_OPEN,
141 TBC_UPDATE,
142 TBC_UPDLOG,
143 TBC_KRUPDLOG,
144 TBC_CLEAR,
145 TBC_CLRUPDLOG,
146 TBC_UPDSTAT,
147 TBC_CLRINPUT,
148 TBC_UPDINPUT
149};
150enum tubwhat {
151 TW_BOGUS,
152 TW_CONFIG
153};
154
155
156
157
158
159#define TUBMAXMINS 256
160#define TUB_DEV MKDEV(IBM_FS3270_MAJ, 0)
161#define _GEOM_ROWS 24
162#define _GEOM_COLS 80
163#define GEOM_ROWS (tubp->geom_rows)
164#define GEOM_COLS (tubp->geom_cols)
165#define GEOM_MAXROWS 127
166#define GEOM_MAXCOLS 132
167#define GEOM_INPLEN (GEOM_COLS * 2 - 20)
168#define GEOM_MAXINPLEN (GEOM_MAXCOLS * 2 - 20)
169#define GEOM_INPUT (GEOM_COLS * (GEOM_ROWS - 2) - 1)
170#define GEOM_STAT (GEOM_INPUT + 1 + GEOM_INPLEN)
171#define GEOM_LOG (GEOM_COLS * GEOM_ROWS - 1)
172#define TS_RUNNING "Linux Running "
173#define TS_MORE "Linux More... "
174#define DEFAULT_SCROLLTIME 5
175#define TS_HOLD "Linux Holding "
176
177#define TS_LENGTH (sizeof TS_RUNNING + 3 + 2)
178
179typedef struct {
180 int aid;
181 char *string;
182} aid_t;
183#define AIDENTRY(ch, tubp) (&((tubp)->tty_aid[(ch) & 0x3f]))
184
185
186typedef struct tubiocb {
187 short model;
188 short line_cnt;
189 short col_cnt;
190 short pf_cnt;
191 short re_cnt;
192 short map;
193} tubiocb_t;
194
195
196#define TA_CLEARKEY 0x01
197#define TA_SHORTREAD 0x02
198
199#define TA_DOENTER 0x04
200#define TA_DOSTRING 0x08
201#define TA_DOSTRINGD 0x10
202#define TA_CLEARLOG 0x20
203
204
205
206
207typedef struct bcb_s {
208 char *bc_buf;
209 int bc_len;
210 int bc_cnt;
211 int bc_wr;
212 int bc_rd;
213} bcb_t;
214
215typedef struct tub_s {
216 int minor;
217 int irq;
218 int irqrc;
219 int devno;
220 int geom_rows;
221 int geom_cols;
222 tubiocb_t tubiocb;
223 int lnopen;
224 int fsopen;
225 int icmd;
226 int ocmd;
227 devstat_t devstat;
228 ccw1_t rccw;
229 ccw1_t wccw;
230 struct idal_buffer *wbuf;
231 int cswl;
232 void (*intv)(struct tub_s *, devstat_t *);
233#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
234 struct wait_queue *waitq;
235#else
236 wait_queue_head_t waitq;
237#endif
238 int dstat;
239 sense_t sense;
240 enum tubmode mode;
241 enum tubstat stat;
242 enum tubcmd cmd;
243 int flags;
244 struct tq_struct tqueue;
245
246
247 pid_t fs_pid;
248
249
250
251 struct tty_struct *tty;
252 char *tty_input;
253 int tty_inattr;
254#define TTY_OUTPUT_SIZE 1024
255 bcb_t tty_bcb;
256 int tty_oucol;
257 int tty_nextlogx;
258 int tty_savecursor;
259 int tty_scrolltime;
260 struct timer_list tty_stimer;
261 aid_t tty_aid[64];
262 int tty_aidinit;
263 int tty_showaidx;
264 int tty_14bitadr;
265#define MAX_TTY_ESCA 24
266 char tty_esca[MAX_TTY_ESCA];
267 int tty_escx;
268
269
270 char *(*tty_rclbufs)[];
271 int tty_rclk;
272 int tty_rclp;
273 int tty_rclb;
274
275
276 char (*ttyscreen)[];
277 int ttyscreenl;
278 ccw1_t ttyccw;
279} tub_t;
280
281
282#define TUB_WORKING 0x0001
283#define TUB_BHPENDING 0x0002
284#define TUB_RDPENDING 0x0004
285#define TUB_ALARM 0x0008
286#define TUB_SCROLLTIMING 0x0010
287#define TUB_ATTN 0x0020
288#define TUB_IACTIVE 0x0040
289#define TUB_SIZED 0x0080
290#define TUB_EXPECT_DE 0x0100
291#define TUB_UNSOL_DE 0x0200
292#define TUB_OPEN_STET 0x0400
293#define TUB_UE_BUSY 0x0800
294#define TUB_INPUT_HACK 0x1000
295
296#ifdef CONFIG_TN3270_CONSOLE
297
298
299
300#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
301#define S390_CONSOLE_DEV MKDEV(TTY_MAJOR, 64)
302#else
303#define S390_CONSOLE_DEV MKDEV(TTYAUX_MAJOR, 1)
304#endif
305extern int tub3270_con_devno;
306extern char (*tub3270_con_output)[];
307extern int tub3270_con_outputl;
308extern int tub3270_con_ouwr;
309extern int tub3270_con_oucount;
310extern int tub3270_con_irq;
311extern tub_t *tub3270_con_tubp;
312extern struct tty_driver tty3270_con_driver;
313#endif
314
315extern int tubnummins;
316extern tub_t *(*tubminors)[TUBMAXMINS];
317extern tub_t *(*(*tubirqs)[256])[256];
318extern unsigned char tub_ascebc[256];
319extern unsigned char tub_ebcasc[256];
320extern unsigned char tub_ebcgraf[64];
321extern int tubdebug;
322extern int fs3270_major;
323extern int tty3270_major;
324extern int tty3270_proc_misc;
325extern enum tubwhat tty3270_proc_what;
326extern struct tty_driver tty3270_driver;
327#ifdef CONFIG_DEVFS_FS
328extern devfs_handle_t fs3270_devfs_dir;
329extern void fs3270_devfs_register(tub_t *);
330extern void fs3270_devfs_unregister(tub_t *);
331#endif
332
333#ifndef spin_trylock_irqsave
334#define spin_trylock_irqsave(lock, flags) \
335({ \
336 int success; \
337 __save_flags(flags); \
338 __cli(); \
339 success = spin_trylock(lock); \
340 if (success == 0) \
341 __restore_flags(flags); \
342 success; \
343})
344#endif
345
346#ifndef s390irq_spin_trylock_irqsave
347#define s390irq_spin_trylock_irqsave(irq, flags) \
348 spin_trylock_irqsave(&(ioinfo[irq]->irq_lock), flags)
349#endif
350
351#define TUBLOCK(irq, flags) \
352 s390irq_spin_lock_irqsave(irq, flags)
353
354#define TUBTRYLOCK(irq, flags) \
355 s390irq_spin_trylock_irqsave(irq, flags)
356
357#define TUBUNLOCK(irq, flags) \
358 s390irq_spin_unlock_irqrestore(irq, flags)
359
360
361
362
363extern tub_t *tubfindbyirq(int);
364#define IRQ2TUB(irq) tubfindbyirq(irq)
365
366
367
368
369static inline tub_t *INODE2TUB(struct inode *ip)
370{
371 unsigned int minor = MINOR(ip->i_rdev);
372 tub_t *tubp = NULL;
373 if (minor == 0 && current->tty != NULL) {
374#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
375#ifdef CONFIG_TN3270_CONSOLE
376 if (tub3270_con_tubp != NULL &&
377 current->tty->device == S390_CONSOLE_DEV)
378 minor = tub3270_con_tubp->minor;
379 else
380#endif
381#endif
382 if (MAJOR(current->tty->device) == IBM_TTY3270_MAJOR)
383 minor = MINOR(current->tty->device);
384 }
385 if (minor <= tubnummins && minor > 0)
386 tubp = (*tubminors)[minor];
387 return tubp;
388}
389
390
391
392
393static inline tub_t *TTY2TUB(struct tty_struct *tty)
394{
395 unsigned int minor = MINOR(tty->device);
396 tub_t *tubp = NULL;
397
398#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
399#ifdef CONFIG_TN3270_CONSOLE
400 if (tty->device == S390_CONSOLE_DEV)
401 tubp = tub3270_con_tubp;
402 else
403#endif
404#endif
405 if (minor <= tubnummins && minor > 0)
406 tubp = (*tubminors)[minor];
407 return tubp;
408}
409
410extern void tub_inc_use_count(void);
411extern void tub_dec_use_count(void);
412extern int tub3270_movedata(bcb_t *, bcb_t *, int);
413#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0))
414extern int tubmakemin(int, dev_info_t *);
415#else
416extern int tubmakemin(int, s390_dev_info_t *);
417#endif
418extern int tub3270_con_copy(tub_t *);
419extern int tty3270_rcl_init(tub_t *);
420extern int tty3270_rcl_set(tub_t *, char *, int);
421extern void tty3270_rcl_fini(tub_t *);
422extern int tty3270_rcl_get(tub_t *, char *, int, int);
423extern void tty3270_rcl_put(tub_t *, char *, int);
424extern void tty3270_rcl_sync(tub_t *);
425extern void tty3270_rcl_purge(tub_t *);
426extern int tty3270_rcl_resize(tub_t *, int);
427extern int tty3270_size(tub_t *, long *);
428extern int tty3270_aid_init(tub_t *);
429extern void tty3270_aid_fini(tub_t *);
430extern void tty3270_aid_reinit(tub_t *);
431extern int tty3270_aid_get(tub_t *, int, int *, char **);
432extern int tty3270_aid_set(tub_t *, char *, int);
433extern int tty3270_build(tub_t *);
434extern void tty3270_scl_settimer(tub_t *);
435extern void tty3270_scl_resettimer(tub_t *);
436extern int tty3270_scl_set(tub_t *, char *, int);
437extern int tty3270_scl_init(tub_t *tubp);
438extern void tty3270_scl_fini(tub_t *tubp);
439