raw3270.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  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. return rc;
  579. /* Wait for attention interrupt. */
  580. #ifdef CONFIG_TN3270_CONSOLE
  581. if (raw3270_registered == 0) {
  582. unsigned long flags;
  583. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  584. while (!test_and_clear_bit(RAW3270_FLAGS_ATTN, &rp->flags))
  585. wait_cons_dev();
  586. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  587. } else
  588. #endif
  589. rc = wait_event_interruptible(raw3270_wait_queue,
  590. test_and_clear_bit(RAW3270_FLAGS_ATTN, &rp->flags));
  591. if (rc)
  592. return rc;
  593. /*
  594. * The device accepted the 'read partition' command. Now
  595. * set up a read ccw and issue it.
  596. */
  597. raw3270_init_request.ccw.cmd_code = TC_READMOD;
  598. raw3270_init_request.ccw.flags = CCW_FLAG_SLI;
  599. raw3270_init_request.ccw.count = sizeof(raw3270_init_data);
  600. raw3270_init_request.ccw.cda = (__u32) __pa(raw3270_init_data);
  601. rc = raw3270_start_init(rp, &raw3270_init_view, &raw3270_init_request);
  602. if (rc)
  603. return rc;
  604. /* Got a Query Reply */
  605. count = sizeof(raw3270_init_data) - raw3270_init_request.rescnt;
  606. uap = (struct raw3270_ua *) (raw3270_init_data + 1);
  607. /* Paranoia check. */
  608. if (raw3270_init_data[0] != 0x88 || uap->uab.qcode != 0x81)
  609. return -EOPNOTSUPP;
  610. /* Copy rows/columns of default Usable Area */
  611. rp->rows = uap->uab.h;
  612. rp->cols = uap->uab.w;
  613. /* Check for 14 bit addressing */
  614. if ((uap->uab.flags0 & 0x0d) == 0x01)
  615. set_bit(RAW3270_FLAGS_14BITADDR, &rp->flags);
  616. /* Check for Alternate Usable Area */
  617. if (uap->uab.l == sizeof(struct raw3270_ua) &&
  618. uap->aua.sdpid == 0x02) {
  619. rp->rows = uap->aua.hauai;
  620. rp->cols = uap->aua.wauai;
  621. }
  622. return 0;
  623. }
  624. static int
  625. raw3270_size_device(struct raw3270 *rp)
  626. {
  627. int rc;
  628. down(&raw3270_init_sem);
  629. rp->view = &raw3270_init_view;
  630. raw3270_init_view.dev = rp;
  631. if (MACHINE_IS_VM)
  632. rc = __raw3270_size_device_vm(rp);
  633. else
  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. } else {
  650. /* Couldn't detect size. Use default model 2. */
  651. rp->model = 2;
  652. rp->rows = 24;
  653. rp->cols = 80;
  654. return 0;
  655. }
  656. return rc;
  657. }
  658. static int
  659. raw3270_reset_device(struct raw3270 *rp)
  660. {
  661. int rc;
  662. down(&raw3270_init_sem);
  663. memset(&raw3270_init_request, 0, sizeof(raw3270_init_request));
  664. memset(raw3270_init_data, 0, sizeof(raw3270_init_data));
  665. /* Store reset data stream to raw3270_init_data/raw3270_init_request */
  666. raw3270_init_data[0] = TW_KR;
  667. INIT_LIST_HEAD(&raw3270_init_request.list);
  668. raw3270_init_request.ccw.cmd_code = TC_EWRITEA;
  669. raw3270_init_request.ccw.flags = CCW_FLAG_SLI;
  670. raw3270_init_request.ccw.count = 1;
  671. raw3270_init_request.ccw.cda = (__u32) __pa(raw3270_init_data);
  672. rp->view = &raw3270_init_view;
  673. raw3270_init_view.dev = rp;
  674. rc = raw3270_start_init(rp, &raw3270_init_view, &raw3270_init_request);
  675. raw3270_init_view.dev = 0;
  676. rp->view = 0;
  677. up(&raw3270_init_sem);
  678. return rc;
  679. }
  680. /*
  681. * Setup new 3270 device.
  682. */
  683. static int
  684. raw3270_setup_device(struct ccw_device *cdev, struct raw3270 *rp, char *ascebc)
  685. {
  686. struct list_head *l;
  687. struct raw3270 *tmp;
  688. int minor;
  689. memset(rp, 0, sizeof(struct raw3270));
  690. /* Copy ebcdic -> ascii translation table. */
  691. memcpy(ascebc, _ascebc, 256);
  692. if (tubxcorrect) {
  693. /* correct brackets and circumflex */
  694. ascebc['['] = 0xad;
  695. ascebc[']'] = 0xbd;
  696. ascebc['^'] = 0xb0;
  697. }
  698. rp->ascebc = ascebc;
  699. /* Set defaults. */
  700. rp->rows = 24;
  701. rp->cols = 80;
  702. INIT_LIST_HEAD(&rp->req_queue);
  703. INIT_LIST_HEAD(&rp->view_list);
  704. /*
  705. * Add device to list and find the smallest unused minor
  706. * number for it.
  707. */
  708. down(&raw3270_sem);
  709. /* Keep the list sorted. */
  710. minor = 0;
  711. rp->minor = -1;
  712. list_for_each(l, &raw3270_devices) {
  713. tmp = list_entry(l, struct raw3270, list);
  714. if (tmp->minor > minor) {
  715. rp->minor = minor;
  716. __list_add(&rp->list, l->prev, l);
  717. break;
  718. }
  719. minor++;
  720. }
  721. if (rp->minor == -1 && minor < RAW3270_MAXDEVS) {
  722. rp->minor = minor;
  723. list_add_tail(&rp->list, &raw3270_devices);
  724. }
  725. up(&raw3270_sem);
  726. /* No free minor number? Then give up. */
  727. if (rp->minor == -1)
  728. return -EUSERS;
  729. rp->cdev = cdev;
  730. cdev->dev.driver_data = rp;
  731. cdev->handler = raw3270_irq;
  732. return 0;
  733. }
  734. #ifdef CONFIG_TN3270_CONSOLE
  735. /*
  736. * Setup 3270 device configured as console.
  737. */
  738. struct raw3270 *
  739. raw3270_setup_console(struct ccw_device *cdev)
  740. {
  741. struct raw3270 *rp;
  742. char *ascebc;
  743. int rc;
  744. rp = (struct raw3270 *) alloc_bootmem(sizeof(struct raw3270));
  745. ascebc = (char *) alloc_bootmem(256);
  746. rc = raw3270_setup_device(cdev, rp, ascebc);
  747. if (rc)
  748. return ERR_PTR(rc);
  749. set_bit(RAW3270_FLAGS_CONSOLE, &rp->flags);
  750. rc = raw3270_reset_device(rp);
  751. if (rc)
  752. return ERR_PTR(rc);
  753. rc = raw3270_size_device(rp);
  754. if (rc)
  755. return ERR_PTR(rc);
  756. rc = raw3270_reset_device(rp);
  757. if (rc)
  758. return ERR_PTR(rc);
  759. set_bit(RAW3270_FLAGS_READY, &rp->flags);
  760. return rp;
  761. }
  762. void
  763. raw3270_wait_cons_dev(struct raw3270 *rp)
  764. {
  765. unsigned long flags;
  766. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  767. wait_cons_dev();
  768. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  769. }
  770. #endif
  771. /*
  772. * Create a 3270 device structure.
  773. */
  774. static struct raw3270 *
  775. raw3270_create_device(struct ccw_device *cdev)
  776. {
  777. struct raw3270 *rp;
  778. char *ascebc;
  779. int rc;
  780. rp = kmalloc(sizeof(struct raw3270), GFP_KERNEL);
  781. if (!rp)
  782. return ERR_PTR(-ENOMEM);
  783. ascebc = kmalloc(256, GFP_KERNEL);
  784. if (!ascebc) {
  785. kfree(rp);
  786. return ERR_PTR(-ENOMEM);
  787. }
  788. rc = raw3270_setup_device(cdev, rp, ascebc);
  789. if (rc) {
  790. kfree(rp->ascebc);
  791. kfree(rp);
  792. rp = ERR_PTR(rc);
  793. }
  794. /* Get reference to ccw_device structure. */
  795. get_device(&cdev->dev);
  796. return rp;
  797. }
  798. /*
  799. * Activate a view.
  800. */
  801. int
  802. raw3270_activate_view(struct raw3270_view *view)
  803. {
  804. struct raw3270 *rp;
  805. struct raw3270_view *oldview, *nv;
  806. unsigned long flags;
  807. int rc;
  808. rp = view->dev;
  809. if (!rp)
  810. return -ENODEV;
  811. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  812. if (rp->view == view)
  813. rc = 0;
  814. else if (!test_bit(RAW3270_FLAGS_READY, &rp->flags))
  815. rc = -ENODEV;
  816. else {
  817. oldview = 0;
  818. if (rp->view) {
  819. oldview = rp->view;
  820. oldview->fn->deactivate(oldview);
  821. }
  822. rp->view = view;
  823. rc = view->fn->activate(view);
  824. if (rc) {
  825. /* Didn't work. Try to reactivate the old view. */
  826. rp->view = oldview;
  827. if (!oldview || oldview->fn->activate(oldview) != 0) {
  828. /* Didn't work as well. Try any other view. */
  829. list_for_each_entry(nv, &rp->view_list, list)
  830. if (nv != view && nv != oldview) {
  831. rp->view = nv;
  832. if (nv->fn->activate(nv) == 0)
  833. break;
  834. rp->view = 0;
  835. }
  836. }
  837. }
  838. }
  839. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  840. return rc;
  841. }
  842. /*
  843. * Deactivate current view.
  844. */
  845. void
  846. raw3270_deactivate_view(struct raw3270_view *view)
  847. {
  848. unsigned long flags;
  849. struct raw3270 *rp;
  850. rp = view->dev;
  851. if (!rp)
  852. return;
  853. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  854. if (rp->view == view) {
  855. view->fn->deactivate(view);
  856. rp->view = 0;
  857. /* Move deactivated view to end of list. */
  858. list_del_init(&view->list);
  859. list_add_tail(&view->list, &rp->view_list);
  860. /* Try to activate another view. */
  861. if (test_bit(RAW3270_FLAGS_READY, &rp->flags)) {
  862. list_for_each_entry(view, &rp->view_list, list)
  863. if (view->fn->activate(view) == 0) {
  864. rp->view = view;
  865. break;
  866. }
  867. }
  868. }
  869. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  870. }
  871. /*
  872. * Add view to device with minor "minor".
  873. */
  874. int
  875. raw3270_add_view(struct raw3270_view *view, struct raw3270_fn *fn, int minor)
  876. {
  877. unsigned long flags;
  878. struct raw3270 *rp;
  879. int rc;
  880. down(&raw3270_sem);
  881. rc = -ENODEV;
  882. list_for_each_entry(rp, &raw3270_devices, list) {
  883. if (rp->minor != minor)
  884. continue;
  885. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  886. if (test_bit(RAW3270_FLAGS_READY, &rp->flags)) {
  887. atomic_set(&view->ref_count, 2);
  888. view->dev = rp;
  889. view->fn = fn;
  890. view->model = rp->model;
  891. view->rows = rp->rows;
  892. view->cols = rp->cols;
  893. view->ascebc = rp->ascebc;
  894. spin_lock_init(&view->lock);
  895. list_add_tail(&view->list, &rp->view_list);
  896. rc = 0;
  897. }
  898. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  899. break;
  900. }
  901. up(&raw3270_sem);
  902. return rc;
  903. }
  904. /*
  905. * Find specific view of device with minor "minor".
  906. */
  907. struct raw3270_view *
  908. raw3270_find_view(struct raw3270_fn *fn, int minor)
  909. {
  910. struct raw3270 *rp;
  911. struct raw3270_view *view, *tmp;
  912. unsigned long flags;
  913. down(&raw3270_sem);
  914. view = ERR_PTR(-ENODEV);
  915. list_for_each_entry(rp, &raw3270_devices, list) {
  916. if (rp->minor != minor)
  917. continue;
  918. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  919. if (test_bit(RAW3270_FLAGS_READY, &rp->flags)) {
  920. view = ERR_PTR(-ENOENT);
  921. list_for_each_entry(tmp, &rp->view_list, list) {
  922. if (tmp->fn == fn) {
  923. raw3270_get_view(tmp);
  924. view = tmp;
  925. break;
  926. }
  927. }
  928. }
  929. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  930. break;
  931. }
  932. up(&raw3270_sem);
  933. return view;
  934. }
  935. /*
  936. * Remove view from device and free view structure via call to view->fn->free.
  937. */
  938. void
  939. raw3270_del_view(struct raw3270_view *view)
  940. {
  941. unsigned long flags;
  942. struct raw3270 *rp;
  943. struct raw3270_view *nv;
  944. rp = view->dev;
  945. spin_lock_irqsave(get_ccwdev_lock(rp->cdev), flags);
  946. if (rp->view == view) {
  947. view->fn->deactivate(view);
  948. rp->view = 0;
  949. }
  950. list_del_init(&view->list);
  951. if (!rp->view && test_bit(RAW3270_FLAGS_READY, &rp->flags)) {
  952. /* Try to activate another view. */
  953. list_for_each_entry(nv, &rp->view_list, list) {
  954. if (nv->fn->activate(view) == 0) {
  955. rp->view = nv;
  956. break;
  957. }
  958. }
  959. }
  960. spin_unlock_irqrestore(get_ccwdev_lock(rp->cdev), flags);
  961. /* Wait for reference counter to drop to zero. */
  962. atomic_dec(&view->ref_count);
  963. wait_event(raw3270_wait_queue, atomic_read(&view->ref_count) == 0);
  964. if (view->fn->free)
  965. view->fn->free(view);
  966. }
  967. /*
  968. * Remove a 3270 device structure.
  969. */
  970. static void
  971. raw3270_delete_device(struct raw3270 *rp)
  972. {
  973. struct ccw_device *cdev;
  974. /* Remove from device chain. */
  975. down(&raw3270_sem);
  976. list_del_init(&rp->list);
  977. up(&raw3270_sem);
  978. /* Disconnect from ccw_device. */
  979. cdev = rp->cdev;
  980. rp->cdev = 0;
  981. cdev->dev.driver_data = 0;
  982. cdev->handler = 0;
  983. /* Put ccw_device structure. */
  984. put_device(&cdev->dev);
  985. /* Now free raw3270 structure. */
  986. kfree(rp->ascebc);
  987. kfree(rp);
  988. }
  989. static int
  990. raw3270_probe (struct ccw_device *cdev)
  991. {
  992. return 0;
  993. }
  994. /*
  995. * Additional attributes for a 3270 device
  996. */
  997. static ssize_t
  998. raw3270_model_show(struct device *dev, struct device_attribute *attr, char *buf)
  999. {
  1000. return snprintf(buf, PAGE_SIZE, "%i\n",
  1001. ((struct raw3270 *) dev->driver_data)->model);
  1002. }
  1003. static DEVICE_ATTR(model, 0444, raw3270_model_show, 0);
  1004. static ssize_t
  1005. raw3270_rows_show(struct device *dev, struct device_attribute *attr, char *buf)
  1006. {
  1007. return snprintf(buf, PAGE_SIZE, "%i\n",
  1008. ((struct raw3270 *) dev->driver_data)->rows);
  1009. }
  1010. static DEVICE_ATTR(rows, 0444, raw3270_rows_show, 0);
  1011. static ssize_t
  1012. raw3270_columns_show(struct device *dev, struct device_attribute *attr, char *buf)
  1013. {
  1014. return snprintf(buf, PAGE_SIZE, "%i\n",
  1015. ((struct raw3270 *) dev->driver_data)->cols);
  1016. }
  1017. static DEVICE_ATTR(columns, 0444, raw3270_columns_show, 0);
  1018. static struct attribute * raw3270_attrs[] = {
  1019. &dev_attr_model.attr,
  1020. &dev_attr_rows.attr,
  1021. &dev_attr_columns.attr,
  1022. NULL,
  1023. };
  1024. static struct attribute_group raw3270_attr_group = {
  1025. .attrs = raw3270_attrs,
  1026. };
  1027. static void
  1028. raw3270_create_attributes(struct raw3270 *rp)
  1029. {
  1030. //FIXME: check return code
  1031. sysfs_create_group(&rp->cdev->dev.kobj, &raw3270_attr_group);
  1032. }
  1033. /*
  1034. * Notifier for device addition/removal
  1035. */
  1036. struct raw3270_notifier {
  1037. struct list_head list;
  1038. void (*notifier)(int, int);
  1039. };
  1040. static struct list_head raw3270_notifier = LIST_HEAD_INIT(raw3270_notifier);
  1041. int raw3270_register_notifier(void (*notifier)(int, int))
  1042. {
  1043. struct raw3270_notifier *np;
  1044. struct raw3270 *rp;
  1045. np = kmalloc(sizeof(struct raw3270_notifier), GFP_KERNEL);
  1046. if (!np)
  1047. return -ENOMEM;
  1048. np->notifier = notifier;
  1049. down(&raw3270_sem);
  1050. list_add_tail(&np->list, &raw3270_notifier);
  1051. list_for_each_entry(rp, &raw3270_devices, list) {
  1052. get_device(&rp->cdev->dev);
  1053. notifier(rp->minor, 1);
  1054. }
  1055. up(&raw3270_sem);
  1056. return 0;
  1057. }
  1058. void raw3270_unregister_notifier(void (*notifier)(int, int))
  1059. {
  1060. struct raw3270_notifier *np;
  1061. down(&raw3270_sem);
  1062. list_for_each_entry(np, &raw3270_notifier, list)
  1063. if (np->notifier == notifier) {
  1064. list_del(&np->list);
  1065. kfree(np);
  1066. break;
  1067. }
  1068. up(&raw3270_sem);
  1069. }
  1070. /*
  1071. * Set 3270 device online.
  1072. */
  1073. static int
  1074. raw3270_set_online (struct ccw_device *cdev)
  1075. {
  1076. struct raw3270 *rp;
  1077. struct raw3270_notifier *np;
  1078. int rc;
  1079. rp = raw3270_create_device(cdev);
  1080. if (IS_ERR(rp))
  1081. return PTR_ERR(rp);
  1082. rc = raw3270_reset_device(rp);
  1083. if (rc)
  1084. return rc;
  1085. rc = raw3270_size_device(rp);
  1086. if (rc)
  1087. return rc;
  1088. rc = raw3270_reset_device(rp);
  1089. if (rc)
  1090. return rc;
  1091. raw3270_create_attributes(rp);
  1092. set_bit(RAW3270_FLAGS_READY, &rp->flags);
  1093. down(&raw3270_sem);
  1094. list_for_each_entry(np, &raw3270_notifier, list)
  1095. np->notifier(rp->minor, 1);
  1096. up(&raw3270_sem);
  1097. return 0;
  1098. }
  1099. /*
  1100. * Remove 3270 device structure.
  1101. */
  1102. static void
  1103. raw3270_remove (struct ccw_device *cdev)
  1104. {
  1105. unsigned long flags;
  1106. struct raw3270 *rp;
  1107. struct raw3270_view *v;
  1108. struct raw3270_notifier *np;
  1109. rp = cdev->dev.driver_data;
  1110. clear_bit(RAW3270_FLAGS_READY, &rp->flags);
  1111. sysfs_remove_group(&cdev->dev.kobj, &raw3270_attr_group);
  1112. /* Deactivate current view and remove all views. */
  1113. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  1114. if (rp->view) {
  1115. rp->view->fn->deactivate(rp->view);
  1116. rp->view = 0;
  1117. }
  1118. while (!list_empty(&rp->view_list)) {
  1119. v = list_entry(rp->view_list.next, struct raw3270_view, list);
  1120. if (v->fn->release)
  1121. v->fn->release(v);
  1122. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  1123. raw3270_del_view(v);
  1124. spin_lock_irqsave(get_ccwdev_lock(cdev), flags);
  1125. }
  1126. spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags);
  1127. down(&raw3270_sem);
  1128. list_for_each_entry(np, &raw3270_notifier, list)
  1129. np->notifier(rp->minor, 0);
  1130. up(&raw3270_sem);
  1131. /* Reset 3270 device. */
  1132. raw3270_reset_device(rp);
  1133. /* And finally remove it. */
  1134. raw3270_delete_device(rp);
  1135. }
  1136. /*
  1137. * Set 3270 device offline.
  1138. */
  1139. static int
  1140. raw3270_set_offline (struct ccw_device *cdev)
  1141. {
  1142. struct raw3270 *rp;
  1143. rp = cdev->dev.driver_data;
  1144. if (test_bit(RAW3270_FLAGS_CONSOLE, &rp->flags))
  1145. return -EBUSY;
  1146. raw3270_remove(cdev);
  1147. return 0;
  1148. }
  1149. static struct ccw_device_id raw3270_id[] = {
  1150. { CCW_DEVICE(0x3270, 0) },
  1151. { CCW_DEVICE(0x3271, 0) },
  1152. { CCW_DEVICE(0x3272, 0) },
  1153. { CCW_DEVICE(0x3273, 0) },
  1154. { CCW_DEVICE(0x3274, 0) },
  1155. { CCW_DEVICE(0x3275, 0) },
  1156. { CCW_DEVICE(0x3276, 0) },
  1157. { CCW_DEVICE(0x3277, 0) },
  1158. { CCW_DEVICE(0x3278, 0) },
  1159. { CCW_DEVICE(0x3279, 0) },
  1160. { CCW_DEVICE(0x3174, 0) },
  1161. { /* end of list */ },
  1162. };
  1163. static struct ccw_driver raw3270_ccw_driver = {
  1164. .name = "3270",
  1165. .owner = THIS_MODULE,
  1166. .ids = raw3270_id,
  1167. .probe = &raw3270_probe,
  1168. .remove = &raw3270_remove,
  1169. .set_online = &raw3270_set_online,
  1170. .set_offline = &raw3270_set_offline,
  1171. };
  1172. static int
  1173. raw3270_init(void)
  1174. {
  1175. struct raw3270 *rp;
  1176. int rc;
  1177. if (raw3270_registered)
  1178. return 0;
  1179. raw3270_registered = 1;
  1180. rc = ccw_driver_register(&raw3270_ccw_driver);
  1181. if (rc == 0) {
  1182. /* Create attributes for early (= console) device. */
  1183. down(&raw3270_sem);
  1184. list_for_each_entry(rp, &raw3270_devices, list) {
  1185. get_device(&rp->cdev->dev);
  1186. raw3270_create_attributes(rp);
  1187. }
  1188. up(&raw3270_sem);
  1189. }
  1190. return rc;
  1191. }
  1192. static void
  1193. raw3270_exit(void)
  1194. {
  1195. ccw_driver_unregister(&raw3270_ccw_driver);
  1196. }
  1197. MODULE_LICENSE("GPL");
  1198. module_init(raw3270_init);
  1199. module_exit(raw3270_exit);
  1200. EXPORT_SYMBOL(raw3270_request_alloc);
  1201. EXPORT_SYMBOL(raw3270_request_free);
  1202. EXPORT_SYMBOL(raw3270_request_reset);
  1203. EXPORT_SYMBOL(raw3270_request_set_cmd);
  1204. EXPORT_SYMBOL(raw3270_request_add_data);
  1205. EXPORT_SYMBOL(raw3270_request_set_data);
  1206. EXPORT_SYMBOL(raw3270_request_set_idal);
  1207. EXPORT_SYMBOL(raw3270_buffer_address);
  1208. EXPORT_SYMBOL(raw3270_add_view);
  1209. EXPORT_SYMBOL(raw3270_del_view);
  1210. EXPORT_SYMBOL(raw3270_find_view);
  1211. EXPORT_SYMBOL(raw3270_activate_view);
  1212. EXPORT_SYMBOL(raw3270_deactivate_view);
  1213. EXPORT_SYMBOL(raw3270_start);
  1214. EXPORT_SYMBOL(raw3270_start_irq);
  1215. EXPORT_SYMBOL(raw3270_register_notifier);
  1216. EXPORT_SYMBOL(raw3270_unregister_notifier);
  1217. EXPORT_SYMBOL(raw3270_wait_queue);