raw3270.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * IBM/3270 Driver - core functions.
  4. *
  5. * Author(s):
  6. * Original 3270 Code for 2.4 written by Richard Hitt (UTS Global)
  7. * Rewritten for 2.5 by Martin Schwidefsky <schwidefsky@de.ibm.com>
  8. * Copyright IBM Corp. 2003, 2009
  9. */
  10. #include <linux/module.h>
  11. #include <linux/err.h>
  12. #include <linux/init.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/list.h>
  15. #include <linux/slab.h>
  16. #include <linux/types.h>
  17. #include <linux/wait.h>
  18. #include <asm/ccwdev.h>
  19. #include <asm/cio.h>
  20. #include <asm/ebcdic.h>
  21. #include <asm/diag.h>
  22. #include "raw3270.h"
  23. #include <linux/major.h>
  24. #include <linux/kdev_t.h>
  25. #include <linux/device.h>
  26. #include <linux/mutex.h>
  27. struct class *class3270;
  28. /* The main 3270 data structure. */
  29. struct raw3270 {
  30. struct list_head list;
  31. struct ccw_device *cdev;
  32. int minor;
  33. short model, rows, cols;
  34. unsigned int state;
  35. unsigned long flags;
  36. struct list_head req_queue; /* Request queue. */
  37. struct list_head view_list; /* List of available views. */
  38. struct raw3270_view *view; /* Active view. */
  39. struct timer_list timer; /* Device timer. */
  40. unsigned char *ascebc; /* ascii -> ebcdic table */
  41. struct raw3270_view init_view;
  42. struct raw3270_request init_reset;
  43. struct raw3270_request init_readpart;
  44. struct raw3270_request init_readmod;
  45. unsigned char init_data[256];
  46. };
  47. /* raw3270->state */
  48. #define RAW3270_STATE_INIT 0 /* Initial state */
  49. #define RAW3270_STATE_RESET 1 /* Reset command is pending */
  50. #define RAW3270_STATE_W4ATTN 2 /* Wait for attention interrupt */
  51. #define RAW3270_STATE_READMOD 3 /* Read partition is pending */
  52. #define RAW3270_STATE_READY 4 /* Device is usable by views */
  53. /* raw3270->flags */
  54. #define RAW3270_FLAGS_14BITADDR 0 /* 14-bit buffer addresses */
  55. #define RAW3270_FLAGS_BUSY 1 /* Device busy, leave it alone */
  56. #define RAW3270_FLAGS_CONSOLE 2 /* Device is the console. */
  57. #define RAW3270_FLAGS_FROZEN 3 /* set if 3270 is frozen for suspend */
  58. /* Semaphore to protect global data of raw3270 (devices, views, etc). */
  59. static DEFINE_MUTEX(raw3270_mutex);
  60. /* List of 3270 devices. */
  61. static LIST_HEAD(raw3270_devices);
  62. /*
  63. * Flag to indicate if the driver has been registered. Some operations
  64. * like waiting for the end of i/o need to be done differently as long
  65. * as the kernel is still starting up (console support).
  66. */
  67. static int raw3270_registered;
  68. /* Module parameters */
  69. static bool tubxcorrect;
  70. module_param(tubxcorrect, bool, 0);
  71. /*
  72. * Wait queue for device init/delete, view delete.
  73. */
  74. DECLARE_WAIT_QUEUE_HEAD(raw3270_wait_queue);
  75. static void __raw3270_disconnect(struct raw3270 *rp);
  76. /*
  77. * Encode array for 12 bit 3270 addresses.
  78. */
  79. static unsigned char raw3270_ebcgraf[64] = {
  80. 0x40, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
  81. 0xc8, 0xc9, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
  82. 0x50, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
  83. 0xd8, 0xd9, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
  84. 0x60, 0x61, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
  85. 0xe8, 0xe9, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
  86. 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
  87. 0xf8, 0xf9, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f
  88. };
  89. static inline int raw3270_state_ready(struct raw3270 *rp)
  90. {
  91. return rp->state == RAW3270_STATE_READY;
  92. }
  93. static inline int raw3270_state_final(struct raw3270 *rp)
  94. {
  95. return rp->state == RAW3270_STATE_INIT ||
  96. rp->state == RAW3270_STATE_READY;
  97. }
  98. void
  99. raw3270_buffer_address(struct raw3270 *rp, char *cp, unsigned short addr)
  100. {
  101. if (test_bit(RAW3270_FLAGS_14BITADDR, &rp->flags)) {
  102. cp[0] = (addr >> 8) & 0x3f;
  103. cp[1] = addr & 0xff;
  104. } else {
  105. cp[0] = raw3270_ebcgraf[(addr >> 6) & 0x3f];
  106. cp[1] = raw3270_ebcgraf[addr & 0x3f];
  107. }
  108. }
  109. /*
  110. * Allocate a new 3270 ccw request
  111. */
  112. struct raw3270_request *
  113. raw3270_request_alloc(size_t size)
  114. {
  115. struct raw3270_request *rq;
  116. /* Allocate request structure */
  117. rq = kzalloc(sizeof(struct raw3270_request), GFP_KERNEL | GFP_DMA);
  118. if (!rq)
  119. return ERR_PTR(-ENOMEM);
  120. /* alloc output buffer. */
  121. if (size > 0) {
  122. rq->buffer = kmalloc(size, GFP_KERNEL | GFP_DMA);
  123. if (!rq->buffer) {
  124. kfree(rq);
  125. return ERR_PTR(-ENOMEM);
  126. }
  127. }
  128. rq->size = size;
  129. INIT_LIST_HEAD(&rq->list);
  130. /*
  131. * Setup ccw.
  132. */
  133. rq->ccw.cda = __pa(rq->buffer);
  134. rq->ccw.flags = CCW_FLAG_SLI;
  135. return rq;
  136. }
  137. /*
  138. * Free 3270 ccw request
  139. */
  140. void
  141. raw3270_request_free (struct raw3270_request *rq)
  142. {
  143. kfree(rq->buffer);
  144. kfree(rq);
  145. }
  146. /*
  147. * Reset request to initial state.
  148. */
  149. void
  150. raw3270_request_reset(struct raw3270_request *rq)
  151. {
  152. BUG_ON(!list_empty(&rq->list));
  153. rq->ccw.cmd_code = 0;
  154. rq->ccw.count = 0;
  155. rq->ccw.cda = __pa(rq->buffer);
  156. rq->ccw.flags = CCW_FLAG_SLI;
  157. rq->rescnt = 0;
  158. rq->rc = 0;
  159. }
  160. /*
  161. * Set command code to ccw of a request.
  162. */
  163. void
  164. raw3270_request_set_cmd(struct raw3270_request *rq, u8 cmd)
  165. {
  166. rq->ccw.cmd_code = cmd;
  167. }
  168. /*
  169. * Add data fragment to output buffer.
  170. */
  171. int
  172. raw3270_request_add_data(struct raw3270_request *rq, void *data, size_t size)
  173. {
  174. if (size + rq->ccw.count > rq->size)
  175. return -E2BIG;
  176. memcpy(rq->buffer + rq->ccw.count, data, size);
  177. rq->ccw.count += size;
  178. return 0;
  179. }
  180. /*
  181. * Set address/length pair to ccw of a request.
  182. */
  183. void
  184. raw3270_request_set_data(struct raw3270_request *rq, void *data, size_t size)
  185. {
  186. rq->ccw.cda = __pa(data);
  187. rq->ccw.count = size;
  188. }
  189. /*
  190. * Set idal buffer to ccw of a request.
  191. */
  192. void
  193. raw3270_request_set_idal(struct raw3270_request *rq, struct idal_buffer *ib)
  194. {
  195. rq->ccw.cda = __pa(ib->data);
  196. rq->ccw.count = ib->size;
  197. rq->ccw.flags |= CCW_FLAG_IDA;
  198. }
  199. /*
  200. * Add the request to the request queue, try to start it if the
  201. * 3270 device is idle. Return without waiting for end of i/o.
  202. */
  203. static int
  204. __raw3270_start(struct raw3270 *rp, struct raw3270_view *view,
  205. struct raw3270_request *rq)
  206. {
  207. rq->view = view;
  208. raw3270_get_view(view);
  209. if (list_empty(&rp->req_queue) &&
  210. !test_bit(RAW3270_FLAGS_BUSY, &rp->flags)) {
  211. /* No other requests are on the queue. Start this one. */
  212. rq->rc = ccw_device_start(rp->cdev, &rq->ccw,
  213. (unsigned long) rq, 0, 0);
  214. if (rq->rc) {
  215. raw3270_put_view(view);
  216. return rq->rc;
  217. }
  218. }
  219. list_add_tail(&rq->list, &rp->req_queue);
  220. return 0;
  221. }
  222. int
  223. raw3270_view_active(struct raw3270_view *view)
  224. {
  225. struct raw3270 *rp = view->dev;
  226. return rp && rp->view == view &&
  227. !test_bit(RAW3270_FLAGS_FROZEN, &rp->flags);
  228. }
  229. int
  230. raw3270_start(struct raw3270_view *view, struct raw3270_request *rq)
  231. {
  232. unsigned long flags;
  233. struct raw3270 *rp;
  234. int rc;
  235. spin_lock_irqsave(get_ccwdev_lock(view->dev->cdev), flags);
  236. rp = view->dev;
  237. if (!rp || rp->view != view ||
  238. test_bit(RAW3270_FLAGS_FROZEN, &rp->flags))
  239. rc = -EACCES;
  240. else if (!raw3270_state_ready(rp))
  241. rc = -EBUSY;
  242. else
  243. rc = __raw3270_start(rp, view, rq);
  244. spin_unlock_irqrestore(get_ccwdev_lock(view->dev->cdev), flags);
  245. return rc;
  246. }
  247. int
  248. raw3270_start_locked(struct raw3270_view *view, struct raw3270_request *rq)
  249. {
  250. struct raw3270 *rp;
  251. int rc;
  252. rp = view->dev;
  253. if (!rp || rp->view != view ||
  254. test_bit(RAW3270_FLAGS_FROZEN, &rp->flags))
  255. rc = -EACCES;
  256. else if (!raw3270_state_ready(rp))
  257. rc = -EBUSY;
  258. else
  259. rc = __raw3270_start(rp, view, rq);
  260. return rc;
  261. }
  262. int
  263. raw3270_start_irq(struct raw3270_view *view, struct raw3270_request *rq)
  264. {
  265. struct raw3270 *rp;
  266. rp = view->dev;
  267. rq->view = view;
  268. raw3270_get_view(view);
  269. list_add_tail(&rq->list, &rp->req_queue);
  270. return 0;
  271. }
  272. /*
  273. * 3270 interrupt routine, called from the ccw_device layer
  274. */
  275. static void
  276. raw3270_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
  277. {
  278. struct raw3270 *rp;
  279. struct raw3270_view *view;
  280. struct raw3270_request *rq;
  281. rp = dev_get_drvdata(&cdev->dev);
  282. if (!rp)
  283. return;
  284. rq = (struct raw3270_request *) intparm;
  285. view = rq ? rq->view : rp->view;
  286. if (!IS_ERR(irb)) {
  287. /* Handle CE-DE-UE and subsequent UDE */
  288. if (irb->scsw.cmd.dstat & DEV_STAT_DEV_END)
  289. clear_bit(RAW3270_FLAGS_BUSY, &rp->flags);
  290. if (irb->scsw.cmd.dstat == (DEV_STAT_CHN_END |
  291. DEV_STAT_DEV_END |
  292. DEV_STAT_UNIT_EXCEP))
  293. set_bit(RAW3270_FLAGS_BUSY, &rp->flags);
  294. /* Handle disconnected devices */
  295. if ((irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) &&
  296. (irb->ecw[0] & SNS0_INTERVENTION_REQ)) {
  297. set_bit(RAW3270_FLAGS_BUSY, &rp->flags);
  298. if (rp->state > RAW3270_STATE_RESET)
  299. __raw3270_disconnect(rp);
  300. }
  301. /* Call interrupt handler of the view */
  302. if (view)
  303. view->fn->intv(view, rq, irb);
  304. }
  305. if (test_bit(RAW3270_FLAGS_BUSY, &rp->flags))
  306. /* Device busy, do not start I/O */
  307. return;
  308. if (rq && !list_empty(&rq->list)) {
  309. /* The request completed, remove from queue and do callback. */
  310. list_del_init(&rq->list);
  311. if (rq->callback)
  312. rq->callback(rq, rq->callback_data);
  313. /* Do put_device for get_device in raw3270_start. */
  314. raw3270_put_view(view);
  315. }
  316. /*
  317. * Try to start each request on request queue until one is
  318. * started successful.
  319. */
  320. while (!list_empty(&rp->req_queue)) {
  321. rq = list_entry(rp->req_queue.next,struct raw3270_request,list);
  322. rq->rc = ccw_device_start(rp->cdev, &rq->ccw,
  323. (unsigned long) rq, 0, 0);
  324. if (rq->rc == 0)
  325. break;
  326. /* Start failed. Remove request and do callback. */
  327. list_del_init(&rq->list);
  328. if (rq->callback)
  329. rq->callback(rq, rq->callback_data);
  330. /* Do put_device for get_device in raw3270_start. */
  331. raw3270_put_view(view);
  332. }
  333. }
  334. /*
  335. * To determine the size of the 3270 device we need to do:
  336. * 1) send a 'read partition' data stream to the device
  337. * 2) wait for the attn interrupt that precedes the query reply
  338. * 3) do a read modified to get the query reply
  339. * To make things worse we have to cope with intervention
  340. * required (3270 device switched to 'stand-by') and command
  341. * rejects (old devices that can't do 'read partition').
  342. */
  343. struct raw3270_ua { /* Query Reply structure for Usable Area */
  344. struct { /* Usable Area Query Reply Base */
  345. short l; /* Length of this structured field */
  346. char sfid; /* 0x81 if Query Reply */
  347. char qcode; /* 0x81 if Usable Area */
  348. char flags0;
  349. char flags1;
  350. short w; /* Width of usable area */
  351. short h; /* Heigth of usavle area */
  352. char units; /* 0x00:in; 0x01:mm */
  353. int xr;
  354. int yr;
  355. char aw;
  356. char ah;
  357. short buffsz; /* Character buffer size, bytes */
  358. char xmin;
  359. char ymin;
  360. char xmax;
  361. char ymax;
  362. } __attribute__ ((packed)) uab;
  363. struct { /* Alternate Usable Area Self-Defining Parameter */
  364. char l; /* Length of this Self-Defining Parm */
  365. char sdpid; /* 0x02 if Alternate Usable Area */
  366. char res;
  367. char auaid; /* 0x01 is Id for the A U A */
  368. short wauai; /* Width of AUAi */
  369. short hauai; /* Height of AUAi */
  370. char auaunits; /* 0x00:in, 0x01:mm */
  371. int auaxr;
  372. int auayr;
  373. char awauai;
  374. char ahauai;
  375. } __attribute__ ((packed)) aua;
  376. } __attribute__ ((packed));
  377. static void
  378. raw3270_size_device_vm(struct raw3270 *rp)
  379. {
  380. int rc, model;
  381. struct ccw_dev_id dev_id;
  382. struct diag210 diag_data;
  383. ccw_device_get_id(rp->cdev, &dev_id);
  384. diag_data.vrdcdvno = dev_id.devno;
  385. diag_data.vrdclen = sizeof(struct diag210);
  386. rc = diag210(&diag_data);
  387. model = diag_data.vrdccrmd;
  388. /* Use default model 2 if the size could not be detected */
  389. if (rc || model < 2 || model > 5)
  390. model = 2;
  391. switch (model) {
  392. case 2:
  393. rp->model = model;
  394. rp->rows = 24;
  395. rp->cols = 80;
  396. break;
  397. case 3:
  398. rp->model = model;
  399. rp->rows = 32;
  400. rp->cols = 80;
  401. break;
  402. case 4:
  403. rp->model = model;
  404. rp->rows = 43;
  405. rp->cols = 80;
  406. break;
  407. case 5:
  408. rp->model = model;
  409. rp->rows = 27;
  410. rp->cols = 132;
  411. break;
  412. }
  413. }
  414. static void
  415. raw3270_size_device(struct raw3270 *rp)
  416. {
  417. struct raw3270_ua *uap;
  418. /* Got a Query Reply */
  419. uap = (struct raw3270_ua *) (rp->init_data + 1);
  420. /* Paranoia check. */
  421. if (rp->init_readmod.rc || rp->init_data[0] != 0x88 ||
  422. uap->uab.qcode != 0x81) {
  423. /* Couldn't detect size. Use default model 2. */
  424. rp->model = 2;
  425. rp->rows = 24;
  426. rp->cols = 80;
  427. return;
  428. }
  429. /* Copy rows/columns of default Usable Area */
  430. rp->rows = uap->uab.h;
  431. rp->cols = uap->uab.w;
  432. /* Check for 14 bit addressing */
  433. if ((uap->uab.flags0 & 0x0d) == 0x01)
  434. set_bit(RAW3270_FLAGS_14BITADDR, &rp->flags);
  435. /* Check for Alternate Usable Area */
  436. if (uap->uab.l == sizeof(struct raw3270_ua) &&
  437. uap->aua.sdpid == 0x02) {
  438. rp->rows = uap->aua.hauai;
  439. rp->cols = uap->aua.wauai;
  440. }
  441. /* Try to find a model. */
  442. rp->model = 0;
  443. if (rp->rows == 24 && rp->cols == 80)
  444. rp->model = 2;
  445. if (rp->rows == 32 && rp->cols == 80)
  446. rp->model = 3;
  447. if (rp->rows == 43 && rp->cols == 80)
  448. rp->model = 4;
  449. if (rp->rows == 27 && rp->cols == 132)
  450. rp->model = 5;
  451. }
  452. static void
  453. raw3270_size_device_done(struct raw3270 *rp)
  454. {
  455. struct raw3270_view *view;
  456. rp->view = NULL;
  457. rp->state = RAW3270_STATE_READY;
  458. /* Notify views about new size */
  459. list_for_each_entry(view, &rp->view_list, list)
  460. if (view->fn->resize)
  461. view->fn->resize(view, rp->model, rp->rows, rp->cols);
  462. /* Setup processing done, now activate a view */
  463. list_for_each_entry(view, &rp->view_list, list) {
  464. rp->view = view;
  465. if (view->fn->activate(view) == 0)
  466. break;
  467. rp->view = NULL;
  468. }
  469. }
  470. static void
  471. raw3270_read_modified_cb(struct raw3270_request *rq, void *data)
  472. {
  473. struct raw3270 *rp = rq->view->dev;
  474. raw3270_size_device(rp);
  475. raw3270_size_device_done(rp);
  476. }
  477. static void
  478. raw3270_read_modified(struct raw3270 *rp)
  479. {
  480. if (rp->state != RAW3270_STATE_W4ATTN)
  481. return;
  482. /* Use 'read modified' to get the result of a read partition. */
  483. memset(&rp->init_readmod, 0, sizeof(rp->init_readmod));
  484. memset(&rp->init_data, 0, sizeof(rp->init_data));
  485. rp->init_readmod.ccw.cmd_code = TC_READMOD;
  486. rp->init_readmod.ccw.flags = CCW_FLAG_SLI;
  487. rp->init_readmod.ccw.count = sizeof(rp->init_data);
  488. rp->init_readmod.ccw.cda = (__u32) __pa(rp->init_data);
  489. rp->init_readmod.callback = raw3270_read_modified_cb;
  490. rp->state = RAW3270_STATE_READMOD;
  491. raw3270_start_irq(&rp->init_view, &rp->init_readmod);
  492. }
  493. static void
  494. raw3270_writesf_readpart(struct raw3270 *rp)
  495. {
  496. static const unsigned char wbuf[] =
  497. { 0x00, 0x07, 0x01, 0xff, 0x03, 0x00, 0x81 };
  498. /* Store 'read partition' data stream to init_data */
  499. memset(&rp->init_readpart, 0, sizeof(rp->init_readpart));
  500. memset(&rp->init_data, 0, sizeof(rp->init_data));
  501. memcpy(&rp->init_data, wbuf, sizeof(wbuf));
  502. rp->init_readpart.ccw.cmd_code = TC_WRITESF;
  503. rp->init_readpart.ccw.flags = CCW_FLAG_SLI;
  504. rp->init_readpart.ccw.count = sizeof(wbuf);
  505. rp->init_readpart.ccw.cda = (__u32) __pa(&rp->init_data);
  506. rp->state = RAW3270_STATE_W4ATTN;
  507. raw3270_start_irq(&rp->init_view, &rp->init_readpart);
  508. }
  509. /*
  510. * Device reset
  511. */
  512. static void
  513. raw3270_reset_device_cb(struct raw3270_request *rq, void *data)
  514. {
  515. struct raw3270 *rp = rq->view->dev;
  516. if (rp->state != RAW3270_STATE_RESET)
  517. return;
  518. if (rq->rc) {
  519. /* Reset command failed. */
  520. rp->state = RAW3270_STATE_INIT;
  521. } else if (MACHINE_IS_VM) {
  522. raw3270_size_device_vm(rp);
  523. raw3270_size_device_done(rp);
  524. } else
  525. raw3270_writesf_readpart(rp);
  526. memset(&rp->init_reset, 0, sizeof(rp->init_reset));
  527. }
  528. static int
  529. __raw3270_reset_device(struct raw3270 *rp)
  530. {
  531. int rc;
  532. /* Check if reset is already pending */
  533. if (rp->init_reset.view)
  534. return -EBUSY;
  535. /* Store reset data stream to init_data/init_reset */
  536. rp->init_data[0] = TW_KR;
  537. rp->init_reset.ccw.cmd_code = TC_EWRITEA;
  538. rp->init_reset.ccw.flags = CCW_FLAG_SLI;
  539. rp->init_reset.ccw.count = 1;
  540. rp->init_reset.ccw.cda = (__u32) __pa(rp->init_data);
  541. rp->init_reset.callback = raw3270_reset_device_cb;
  542. rc = __raw3270_start(rp, &rp->init_view, &rp->init_reset);
  543. if (rc == 0 && rp->state == RAW3270_STATE_INIT)
  544. rp->state = RAW3270_STATE_RESET;
  545. return rc;
  546. }
  547. static int
  548. raw3270_reset_device(struct raw3270 *rp)
  549. {
  550. unsigned long flags;
  551. int rc;
  552. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  553. rc = __raw3270_reset_device(rp);
  554. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  555. return rc;
  556. }
  557. int
  558. raw3270_reset(struct raw3270_view *view)
  559. {
  560. struct raw3270 *rp;
  561. int rc;
  562. rp = view->dev;
  563. if (!rp || rp->view != view ||
  564. test_bit(RAW3270_FLAGS_FROZEN, &rp->flags))
  565. rc = -EACCES;
  566. else if (!raw3270_state_ready(rp))
  567. rc = -EBUSY;
  568. else
  569. rc = raw3270_reset_device(view->dev);
  570. return rc;
  571. }
  572. static void
  573. __raw3270_disconnect(struct raw3270 *rp)
  574. {
  575. struct raw3270_request *rq;
  576. struct raw3270_view *view;
  577. rp->state = RAW3270_STATE_INIT;
  578. rp->view = &rp->init_view;
  579. /* Cancel all queued requests */
  580. while (!list_empty(&rp->req_queue)) {
  581. rq = list_entry(rp->req_queue.next,struct raw3270_request,list);
  582. view = rq->view;
  583. rq->rc = -EACCES;
  584. list_del_init(&rq->list);
  585. if (rq->callback)
  586. rq->callback(rq, rq->callback_data);
  587. raw3270_put_view(view);
  588. }
  589. /* Start from scratch */
  590. __raw3270_reset_device(rp);
  591. }
  592. static void
  593. raw3270_init_irq(struct raw3270_view *view, struct raw3270_request *rq,
  594. struct irb *irb)
  595. {
  596. struct raw3270 *rp;
  597. if (rq) {
  598. if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
  599. if (irb->ecw[0] & SNS0_CMD_REJECT)
  600. rq->rc = -EOPNOTSUPP;
  601. else
  602. rq->rc = -EIO;
  603. }
  604. }
  605. if (irb->scsw.cmd.dstat & DEV_STAT_ATTENTION) {
  606. /* Queue read modified after attention interrupt */
  607. rp = view->dev;
  608. raw3270_read_modified(rp);
  609. }
  610. }
  611. static struct raw3270_fn raw3270_init_fn = {
  612. .intv = raw3270_init_irq
  613. };
  614. /*
  615. * Setup new 3270 device.
  616. */
  617. static int
  618. raw3270_setup_device(struct ccw_device *cdev, struct raw3270 *rp, char *ascebc)
  619. {
  620. struct list_head *l;
  621. struct raw3270 *tmp;
  622. int minor;
  623. memset(rp, 0, sizeof(struct raw3270));
  624. /* Copy ebcdic -> ascii translation table. */
  625. memcpy(ascebc, _ascebc, 256);
  626. if (tubxcorrect) {
  627. /* correct brackets and circumflex */
  628. ascebc['['] = 0xad;
  629. ascebc[']'] = 0xbd;
  630. ascebc['^'] = 0xb0;
  631. }
  632. rp->ascebc = ascebc;
  633. /* Set defaults. */
  634. rp->rows = 24;
  635. rp->cols = 80;
  636. INIT_LIST_HEAD(&rp->req_queue);
  637. INIT_LIST_HEAD(&rp->view_list);
  638. rp->init_view.dev = rp;
  639. rp->init_view.fn = &raw3270_init_fn;
  640. rp->view = &rp->init_view;
  641. /*
  642. * Add device to list and find the smallest unused minor
  643. * number for it. Note: there is no device with minor 0,
  644. * see special case for fs3270.c:fs3270_open().
  645. */
  646. mutex_lock(&raw3270_mutex);
  647. /* Keep the list sorted. */
  648. minor = RAW3270_FIRSTMINOR;
  649. rp->minor = -1;
  650. list_for_each(l, &raw3270_devices) {
  651. tmp = list_entry(l, struct raw3270, list);
  652. if (tmp->minor > minor) {
  653. rp->minor = minor;
  654. __list_add(&rp->list, l->prev, l);
  655. break;
  656. }
  657. minor++;
  658. }
  659. if (rp->minor == -1 && minor < RAW3270_MAXDEVS + RAW3270_FIRSTMINOR) {
  660. rp->minor = minor;
  661. list_add_tail(&rp->list, &raw3270_devices);
  662. }
  663. mutex_unlock(&raw3270_mutex);
  664. /* No free minor number? Then give up. */
  665. if (rp->minor == -1)
  666. return -EUSERS;
  667. rp->cdev = cdev;
  668. dev_set_drvdata(&cdev->dev, rp);
  669. cdev->handler = raw3270_irq;
  670. return 0;
  671. }
  672. #ifdef CONFIG_TN3270_CONSOLE
  673. /* Tentative definition - see below for actual definition. */
  674. static struct ccw_driver raw3270_ccw_driver;
  675. /*
  676. * Setup 3270 device configured as console.
  677. */
  678. struct raw3270 __init *raw3270_setup_console(void)
  679. {
  680. struct ccw_device *cdev;
  681. unsigned long flags;
  682. struct raw3270 *rp;
  683. char *ascebc;
  684. int rc;
  685. cdev = ccw_device_create_console(&raw3270_ccw_driver);
  686. if (IS_ERR(cdev))
  687. return ERR_CAST(cdev);
  688. rp = kzalloc(sizeof(struct raw3270), GFP_KERNEL | GFP_DMA);
  689. ascebc = kzalloc(256, GFP_KERNEL);
  690. rc = raw3270_setup_device(cdev, rp, ascebc);
  691. if (rc)
  692. return ERR_PTR(rc);
  693. set_bit(RAW3270_FLAGS_CONSOLE, &rp->flags);
  694. rc = ccw_device_enable_console(cdev);
  695. if (rc) {
  696. ccw_device_destroy_console(cdev);
  697. return ERR_PTR(rc);
  698. }
  699. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  700. do {
  701. __raw3270_reset_device(rp);
  702. while (!raw3270_state_final(rp)) {
  703. ccw_device_wait_idle(rp->cdev);
  704. barrier();
  705. }
  706. } while (rp->state != RAW3270_STATE_READY);
  707. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  708. return rp;
  709. }
  710. void
  711. raw3270_wait_cons_dev(struct raw3270 *rp)
  712. {
  713. unsigned long flags;
  714. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  715. ccw_device_wait_idle(rp->cdev);
  716. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  717. }
  718. #endif
  719. /*
  720. * Create a 3270 device structure.
  721. */
  722. static struct raw3270 *
  723. raw3270_create_device(struct ccw_device *cdev)
  724. {
  725. struct raw3270 *rp;
  726. char *ascebc;
  727. int rc;
  728. rp = kzalloc(sizeof(struct raw3270), GFP_KERNEL | GFP_DMA);
  729. if (!rp)
  730. return ERR_PTR(-ENOMEM);
  731. ascebc = kmalloc(256, GFP_KERNEL);
  732. if (!ascebc) {
  733. kfree(rp);
  734. return ERR_PTR(-ENOMEM);
  735. }
  736. rc = raw3270_setup_device(cdev, rp, ascebc);
  737. if (rc) {
  738. kfree(rp->ascebc);
  739. kfree(rp);
  740. rp = ERR_PTR(rc);
  741. }
  742. /* Get reference to ccw_device structure. */
  743. get_device(&cdev->dev);
  744. return rp;
  745. }
  746. /*
  747. * Activate a view.
  748. */
  749. int
  750. raw3270_activate_view(struct raw3270_view *view)
  751. {
  752. struct raw3270 *rp;
  753. struct raw3270_view *oldview, *nv;
  754. unsigned long flags;
  755. int rc;
  756. rp = view->dev;
  757. if (!rp)
  758. return -ENODEV;
  759. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  760. if (rp->view == view)
  761. rc = 0;
  762. else if (!raw3270_state_ready(rp))
  763. rc = -EBUSY;
  764. else if (test_bit(RAW3270_FLAGS_FROZEN, &rp->flags))
  765. rc = -EACCES;
  766. else {
  767. oldview = NULL;
  768. if (rp->view && rp->view->fn->deactivate) {
  769. oldview = rp->view;
  770. oldview->fn->deactivate(oldview);
  771. }
  772. rp->view = view;
  773. rc = view->fn->activate(view);
  774. if (rc) {
  775. /* Didn't work. Try to reactivate the old view. */
  776. rp->view = oldview;
  777. if (!oldview || oldview->fn->activate(oldview) != 0) {
  778. /* Didn't work as well. Try any other view. */
  779. list_for_each_entry(nv, &rp->view_list, list)
  780. if (nv != view && nv != oldview) {
  781. rp->view = nv;
  782. if (nv->fn->activate(nv) == 0)
  783. break;
  784. rp->view = NULL;
  785. }
  786. }
  787. }
  788. }
  789. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  790. return rc;
  791. }
  792. /*
  793. * Deactivate current view.
  794. */
  795. void
  796. raw3270_deactivate_view(struct raw3270_view *view)
  797. {
  798. unsigned long flags;
  799. struct raw3270 *rp;
  800. rp = view->dev;
  801. if (!rp)
  802. return;
  803. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  804. if (rp->view == view) {
  805. view->fn->deactivate(view);
  806. rp->view = NULL;
  807. /* Move deactivated view to end of list. */
  808. list_del_init(&view->list);
  809. list_add_tail(&view->list, &rp->view_list);
  810. /* Try to activate another view. */
  811. if (raw3270_state_ready(rp) &&
  812. !test_bit(RAW3270_FLAGS_FROZEN, &rp->flags)) {
  813. list_for_each_entry(view, &rp->view_list, list) {
  814. rp->view = view;
  815. if (view->fn->activate(view) == 0)
  816. break;
  817. rp->view = NULL;
  818. }
  819. }
  820. }
  821. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  822. }
  823. /*
  824. * Add view to device with minor "minor".
  825. */
  826. int
  827. raw3270_add_view(struct raw3270_view *view, struct raw3270_fn *fn, int minor)
  828. {
  829. unsigned long flags;
  830. struct raw3270 *rp;
  831. int rc;
  832. if (minor <= 0)
  833. return -ENODEV;
  834. mutex_lock(&raw3270_mutex);
  835. rc = -ENODEV;
  836. list_for_each_entry(rp, &raw3270_devices, list) {
  837. if (rp->minor != minor)
  838. continue;
  839. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  840. atomic_set(&view->ref_count, 2);
  841. view->dev = rp;
  842. view->fn = fn;
  843. view->model = rp->model;
  844. view->rows = rp->rows;
  845. view->cols = rp->cols;
  846. view->ascebc = rp->ascebc;
  847. spin_lock_init(&view->lock);
  848. list_add(&view->list, &rp->view_list);
  849. rc = 0;
  850. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  851. break;
  852. }
  853. mutex_unlock(&raw3270_mutex);
  854. return rc;
  855. }
  856. /*
  857. * Find specific view of device with minor "minor".
  858. */
  859. struct raw3270_view *
  860. raw3270_find_view(struct raw3270_fn *fn, int minor)
  861. {
  862. struct raw3270 *rp;
  863. struct raw3270_view *view, *tmp;
  864. unsigned long flags;
  865. mutex_lock(&raw3270_mutex);
  866. view = ERR_PTR(-ENODEV);
  867. list_for_each_entry(rp, &raw3270_devices, list) {
  868. if (rp->minor != minor)
  869. continue;
  870. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  871. list_for_each_entry(tmp, &rp->view_list, list) {
  872. if (tmp->fn == fn) {
  873. raw3270_get_view(tmp);
  874. view = tmp;
  875. break;
  876. }
  877. }
  878. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  879. break;
  880. }
  881. mutex_unlock(&raw3270_mutex);
  882. return view;
  883. }
  884. /*
  885. * Remove view from device and free view structure via call to view->fn->free.
  886. */
  887. void
  888. raw3270_del_view(struct raw3270_view *view)
  889. {
  890. unsigned long flags;
  891. struct raw3270 *rp;
  892. struct raw3270_view *nv;
  893. rp = view->dev;
  894. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  895. if (rp->view == view) {
  896. view->fn->deactivate(view);
  897. rp->view = NULL;
  898. }
  899. list_del_init(&view->list);
  900. if (!rp->view && raw3270_state_ready(rp) &&
  901. !test_bit(RAW3270_FLAGS_FROZEN, &rp->flags)) {
  902. /* Try to activate another view. */
  903. list_for_each_entry(nv, &rp->view_list, list) {
  904. if (nv->fn->activate(nv) == 0) {
  905. rp->view = nv;
  906. break;
  907. }
  908. }
  909. }
  910. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  911. /* Wait for reference counter to drop to zero. */
  912. atomic_dec(&view->ref_count);
  913. wait_event(raw3270_wait_queue, atomic_read(&view->ref_count) == 0);
  914. if (view->fn->free)
  915. view->fn->free(view);
  916. }
  917. /*
  918. * Remove a 3270 device structure.
  919. */
  920. static void
  921. raw3270_delete_device(struct raw3270 *rp)
  922. {
  923. struct ccw_device *cdev;
  924. /* Remove from device chain. */
  925. mutex_lock(&raw3270_mutex);
  926. list_del_init(&rp->list);
  927. mutex_unlock(&raw3270_mutex);
  928. /* Disconnect from ccw_device. */
  929. cdev = rp->cdev;
  930. rp->cdev = NULL;
  931. dev_set_drvdata(&cdev->dev, NULL);
  932. cdev->handler = NULL;
  933. /* Put ccw_device structure. */
  934. put_device(&cdev->dev);
  935. /* Now free raw3270 structure. */
  936. kfree(rp->ascebc);
  937. kfree(rp);
  938. }
  939. static int
  940. raw3270_probe (struct ccw_device *cdev)
  941. {
  942. return 0;
  943. }
  944. /*
  945. * Additional attributes for a 3270 device
  946. */
  947. static ssize_t
  948. raw3270_model_show(struct device *dev, struct device_attribute *attr, char *buf)
  949. {
  950. return snprintf(buf, PAGE_SIZE, "%i\n",
  951. ((struct raw3270 *) dev_get_drvdata(dev))->model);
  952. }
  953. static DEVICE_ATTR(model, 0444, raw3270_model_show, NULL);
  954. static ssize_t
  955. raw3270_rows_show(struct device *dev, struct device_attribute *attr, char *buf)
  956. {
  957. return snprintf(buf, PAGE_SIZE, "%i\n",
  958. ((struct raw3270 *) dev_get_drvdata(dev))->rows);
  959. }
  960. static DEVICE_ATTR(rows, 0444, raw3270_rows_show, NULL);
  961. static ssize_t
  962. raw3270_columns_show(struct device *dev, struct device_attribute *attr, char *buf)
  963. {
  964. return snprintf(buf, PAGE_SIZE, "%i\n",
  965. ((struct raw3270 *) dev_get_drvdata(dev))->cols);
  966. }
  967. static DEVICE_ATTR(columns, 0444, raw3270_columns_show, NULL);
  968. static struct attribute * raw3270_attrs[] = {
  969. &dev_attr_model.attr,
  970. &dev_attr_rows.attr,
  971. &dev_attr_columns.attr,
  972. NULL,
  973. };
  974. static const struct attribute_group raw3270_attr_group = {
  975. .attrs = raw3270_attrs,
  976. };
  977. static int raw3270_create_attributes(struct raw3270 *rp)
  978. {
  979. return sysfs_create_group(&rp->cdev->dev.kobj, &raw3270_attr_group);
  980. }
  981. /*
  982. * Notifier for device addition/removal
  983. */
  984. static LIST_HEAD(raw3270_notifier);
  985. int raw3270_register_notifier(struct raw3270_notifier *notifier)
  986. {
  987. struct raw3270 *rp;
  988. mutex_lock(&raw3270_mutex);
  989. list_add_tail(&notifier->list, &raw3270_notifier);
  990. list_for_each_entry(rp, &raw3270_devices, list)
  991. notifier->create(rp->minor);
  992. mutex_unlock(&raw3270_mutex);
  993. return 0;
  994. }
  995. void raw3270_unregister_notifier(struct raw3270_notifier *notifier)
  996. {
  997. struct raw3270 *rp;
  998. mutex_lock(&raw3270_mutex);
  999. list_for_each_entry(rp, &raw3270_devices, list)
  1000. notifier->destroy(rp->minor);
  1001. list_del(&notifier->list);
  1002. mutex_unlock(&raw3270_mutex);
  1003. }
  1004. /*
  1005. * Set 3270 device online.
  1006. */
  1007. static int
  1008. raw3270_set_online (struct ccw_device *cdev)
  1009. {
  1010. struct raw3270_notifier *np;
  1011. struct raw3270 *rp;
  1012. int rc;
  1013. rp = raw3270_create_device(cdev);
  1014. if (IS_ERR(rp))
  1015. return PTR_ERR(rp);
  1016. rc = raw3270_create_attributes(rp);
  1017. if (rc)
  1018. goto failure;
  1019. raw3270_reset_device(rp);
  1020. mutex_lock(&raw3270_mutex);
  1021. list_for_each_entry(np, &raw3270_notifier, list)
  1022. np->create(rp->minor);
  1023. mutex_unlock(&raw3270_mutex);
  1024. return 0;
  1025. failure:
  1026. raw3270_delete_device(rp);
  1027. return rc;
  1028. }
  1029. /*
  1030. * Remove 3270 device structure.
  1031. */
  1032. static void
  1033. raw3270_remove (struct ccw_device *cdev)
  1034. {
  1035. unsigned long flags;
  1036. struct raw3270 *rp;
  1037. struct raw3270_view *v;
  1038. struct raw3270_notifier *np;
  1039. rp = dev_get_drvdata(&cdev->dev);
  1040. /*
  1041. * _remove is the opposite of _probe; it's probe that
  1042. * should set up rp. raw3270_remove gets entered for
  1043. * devices even if they haven't been varied online.
  1044. * Thus, rp may validly be NULL here.
  1045. */
  1046. if (rp == NULL)
  1047. return;
  1048. sysfs_remove_group(&cdev->dev.kobj, &raw3270_attr_group);
  1049. /* Deactivate current view and remove all views. */
  1050. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  1051. if (rp->view) {
  1052. if (rp->view->fn->deactivate)
  1053. rp->view->fn->deactivate(rp->view);
  1054. rp->view = NULL;
  1055. }
  1056. while (!list_empty(&rp->view_list)) {
  1057. v = list_entry(rp->view_list.next, struct raw3270_view, list);
  1058. if (v->fn->release)
  1059. v->fn->release(v);
  1060. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  1061. raw3270_del_view(v);
  1062. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  1063. }
  1064. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  1065. mutex_lock(&raw3270_mutex);
  1066. list_for_each_entry(np, &raw3270_notifier, list)
  1067. np->destroy(rp->minor);
  1068. mutex_unlock(&raw3270_mutex);
  1069. /* Reset 3270 device. */
  1070. raw3270_reset_device(rp);
  1071. /* And finally remove it. */
  1072. raw3270_delete_device(rp);
  1073. }
  1074. /*
  1075. * Set 3270 device offline.
  1076. */
  1077. static int
  1078. raw3270_set_offline (struct ccw_device *cdev)
  1079. {
  1080. struct raw3270 *rp;
  1081. rp = dev_get_drvdata(&cdev->dev);
  1082. if (test_bit(RAW3270_FLAGS_CONSOLE, &rp->flags))
  1083. return -EBUSY;
  1084. raw3270_remove(cdev);
  1085. return 0;
  1086. }
  1087. static int raw3270_pm_stop(struct ccw_device *cdev)
  1088. {
  1089. struct raw3270 *rp;
  1090. struct raw3270_view *view;
  1091. unsigned long flags;
  1092. rp = dev_get_drvdata(&cdev->dev);
  1093. if (!rp)
  1094. return 0;
  1095. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  1096. if (rp->view && rp->view->fn->deactivate)
  1097. rp->view->fn->deactivate(rp->view);
  1098. if (!test_bit(RAW3270_FLAGS_CONSOLE, &rp->flags)) {
  1099. /*
  1100. * Release tty and fullscreen for all non-console
  1101. * devices.
  1102. */
  1103. list_for_each_entry(view, &rp->view_list, list) {
  1104. if (view->fn->release)
  1105. view->fn->release(view);
  1106. }
  1107. }
  1108. set_bit(RAW3270_FLAGS_FROZEN, &rp->flags);
  1109. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  1110. return 0;
  1111. }
  1112. static int raw3270_pm_start(struct ccw_device *cdev)
  1113. {
  1114. struct raw3270 *rp;
  1115. unsigned long flags;
  1116. rp = dev_get_drvdata(&cdev->dev);
  1117. if (!rp)
  1118. return 0;
  1119. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  1120. clear_bit(RAW3270_FLAGS_FROZEN, &rp->flags);
  1121. if (rp->view && rp->view->fn->activate)
  1122. rp->view->fn->activate(rp->view);
  1123. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  1124. return 0;
  1125. }
  1126. void raw3270_pm_unfreeze(struct raw3270_view *view)
  1127. {
  1128. #ifdef CONFIG_TN3270_CONSOLE
  1129. struct raw3270 *rp;
  1130. rp = view->dev;
  1131. if (rp && test_bit(RAW3270_FLAGS_FROZEN, &rp->flags))
  1132. ccw_device_force_console(rp->cdev);
  1133. #endif
  1134. }
  1135. static struct ccw_device_id raw3270_id[] = {
  1136. { CCW_DEVICE(0x3270, 0) },
  1137. { CCW_DEVICE(0x3271, 0) },
  1138. { CCW_DEVICE(0x3272, 0) },
  1139. { CCW_DEVICE(0x3273, 0) },
  1140. { CCW_DEVICE(0x3274, 0) },
  1141. { CCW_DEVICE(0x3275, 0) },
  1142. { CCW_DEVICE(0x3276, 0) },
  1143. { CCW_DEVICE(0x3277, 0) },
  1144. { CCW_DEVICE(0x3278, 0) },
  1145. { CCW_DEVICE(0x3279, 0) },
  1146. { CCW_DEVICE(0x3174, 0) },
  1147. { /* end of list */ },
  1148. };
  1149. static struct ccw_driver raw3270_ccw_driver = {
  1150. .driver = {
  1151. .name = "3270",
  1152. .owner = THIS_MODULE,
  1153. },
  1154. .ids = raw3270_id,
  1155. .probe = &raw3270_probe,
  1156. .remove = &raw3270_remove,
  1157. .set_online = &raw3270_set_online,
  1158. .set_offline = &raw3270_set_offline,
  1159. .freeze = &raw3270_pm_stop,
  1160. .thaw = &raw3270_pm_start,
  1161. .restore = &raw3270_pm_start,
  1162. .int_class = IRQIO_C70,
  1163. };
  1164. static int
  1165. raw3270_init(void)
  1166. {
  1167. struct raw3270 *rp;
  1168. int rc;
  1169. if (raw3270_registered)
  1170. return 0;
  1171. raw3270_registered = 1;
  1172. rc = ccw_driver_register(&raw3270_ccw_driver);
  1173. if (rc == 0) {
  1174. /* Create attributes for early (= console) device. */
  1175. mutex_lock(&raw3270_mutex);
  1176. class3270 = class_create(THIS_MODULE, "3270");
  1177. list_for_each_entry(rp, &raw3270_devices, list) {
  1178. get_device(&rp->cdev->dev);
  1179. raw3270_create_attributes(rp);
  1180. }
  1181. mutex_unlock(&raw3270_mutex);
  1182. }
  1183. return rc;
  1184. }
  1185. static void
  1186. raw3270_exit(void)
  1187. {
  1188. ccw_driver_unregister(&raw3270_ccw_driver);
  1189. class_destroy(class3270);
  1190. }
  1191. MODULE_LICENSE("GPL");
  1192. module_init(raw3270_init);
  1193. module_exit(raw3270_exit);
  1194. EXPORT_SYMBOL(class3270);
  1195. EXPORT_SYMBOL(raw3270_request_alloc);
  1196. EXPORT_SYMBOL(raw3270_request_free);
  1197. EXPORT_SYMBOL(raw3270_request_reset);
  1198. EXPORT_SYMBOL(raw3270_request_set_cmd);
  1199. EXPORT_SYMBOL(raw3270_request_add_data);
  1200. EXPORT_SYMBOL(raw3270_request_set_data);
  1201. EXPORT_SYMBOL(raw3270_request_set_idal);
  1202. EXPORT_SYMBOL(raw3270_buffer_address);
  1203. EXPORT_SYMBOL(raw3270_add_view);
  1204. EXPORT_SYMBOL(raw3270_del_view);
  1205. EXPORT_SYMBOL(raw3270_find_view);
  1206. EXPORT_SYMBOL(raw3270_activate_view);
  1207. EXPORT_SYMBOL(raw3270_deactivate_view);
  1208. EXPORT_SYMBOL(raw3270_start);
  1209. EXPORT_SYMBOL(raw3270_start_locked);
  1210. EXPORT_SYMBOL(raw3270_start_irq);
  1211. EXPORT_SYMBOL(raw3270_reset);
  1212. EXPORT_SYMBOL(raw3270_register_notifier);
  1213. EXPORT_SYMBOL(raw3270_unregister_notifier);
  1214. EXPORT_SYMBOL(raw3270_wait_queue);