raw3270.c 31 KB

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