raw3270.c 32 KB

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