raw3270.c 32 KB

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