raw3270.c 33 KB

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