raw3270.c 32 KB

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