riotty.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  1. /*
  2. ** -----------------------------------------------------------------------------
  3. **
  4. ** Perle Specialix driver for Linux
  5. ** Ported from existing RIO Driver for SCO sources.
  6. *
  7. * (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. **
  23. ** Module : riotty.c
  24. ** SID : 1.3
  25. ** Last Modified : 11/6/98 10:33:47
  26. ** Retrieved : 11/6/98 10:33:50
  27. **
  28. ** ident @(#)riotty.c 1.3
  29. **
  30. ** -----------------------------------------------------------------------------
  31. */
  32. #ifdef SCCS_LABELS
  33. static char *_riotty_c_sccs_ = "@(#)riotty.c 1.3";
  34. #endif
  35. #define __EXPLICIT_DEF_H__
  36. #include <linux/module.h>
  37. #include <linux/slab.h>
  38. #include <linux/errno.h>
  39. #include <linux/tty.h>
  40. #include <linux/string.h>
  41. #include <asm/io.h>
  42. #include <asm/system.h>
  43. #include <asm/string.h>
  44. #include <asm/semaphore.h>
  45. #include <asm/uaccess.h>
  46. #include <linux/termios.h>
  47. #include <linux/serial.h>
  48. #include <linux/generic_serial.h>
  49. #include "linux_compat.h"
  50. #include "rio_linux.h"
  51. #include "typdef.h"
  52. #include "pkt.h"
  53. #include "daemon.h"
  54. #include "rio.h"
  55. #include "riospace.h"
  56. #include "top.h"
  57. #include "cmdpkt.h"
  58. #include "map.h"
  59. #include "riotypes.h"
  60. #include "rup.h"
  61. #include "port.h"
  62. #include "riodrvr.h"
  63. #include "rioinfo.h"
  64. #include "func.h"
  65. #include "errors.h"
  66. #include "pci.h"
  67. #include "parmmap.h"
  68. #include "unixrup.h"
  69. #include "board.h"
  70. #include "host.h"
  71. #include "error.h"
  72. #include "phb.h"
  73. #include "link.h"
  74. #include "cmdblk.h"
  75. #include "route.h"
  76. #include "control.h"
  77. #include "cirrus.h"
  78. #include "rioioctl.h"
  79. #include "param.h"
  80. #include "list.h"
  81. #include "sam.h"
  82. #if 0
  83. static void ttyseth_pv(struct Port *, struct ttystatics *,
  84. struct termios *sg, int);
  85. #endif
  86. static void RIOClearUp(struct Port *PortP);
  87. int RIOShortCommand(struct rio_info *p, struct Port *PortP,
  88. int command, int len, int arg);
  89. #if 0
  90. static int RIOCookMode(struct ttystatics *);
  91. #endif
  92. extern int conv_vb[]; /* now defined in ttymgr.c */
  93. extern int conv_bv[]; /* now defined in ttymgr.c */
  94. /*
  95. ** 16.09.1998 ARG - Fix to build riotty.k.o for Modular Kernel Support
  96. **
  97. ** ep.def.h is necessary for Modular Kernel Support
  98. ** DO NOT place any kernel 'extern's after this line
  99. ** or this source file will not build riotty.k.o
  100. */
  101. #ifdef uLYNX
  102. #include <ep.def.h>
  103. #endif
  104. #ifdef NEED_THIS2
  105. static struct old_sgttyb
  106. default_sg =
  107. {
  108. B19200, B19200, /* input and output speed */
  109. 'H' - '@', /* erase char */
  110. -1, /* 2nd erase char */
  111. 'U' - '@', /* kill char */
  112. ECHO | CRMOD, /* mode */
  113. 'C' - '@', /* interrupt character */
  114. '\\' - '@', /* quit char */
  115. 'Q' - '@', /* start char */
  116. 'S' - '@', /* stop char */
  117. 'D' - '@', /* EOF */
  118. -1, /* brk */
  119. (LCRTBS | LCRTERA | LCRTKIL | LCTLECH), /* local mode word */
  120. 'Z' - '@', /* process stop */
  121. 'Y' - '@', /* delayed stop */
  122. 'R' - '@', /* reprint line */
  123. 'O' - '@', /* flush output */
  124. 'W' - '@', /* word erase */
  125. 'V' - '@' /* literal next char */
  126. };
  127. #endif
  128. extern struct rio_info *p;
  129. int
  130. riotopen(struct tty_struct * tty, struct file * filp)
  131. {
  132. register uint SysPort;
  133. int Modem;
  134. int repeat_this = 250;
  135. struct Port *PortP; /* pointer to the port structure */
  136. unsigned long flags;
  137. int retval = 0;
  138. func_enter ();
  139. /* Make sure driver_data is NULL in case the rio isn't booted jet. Else gs_close
  140. is going to oops.
  141. */
  142. tty->driver_data = NULL;
  143. SysPort = rio_minor(tty);
  144. Modem = rio_ismodem(tty);
  145. if ( p->RIOFailed ) {
  146. rio_dprintk (RIO_DEBUG_TTY, "System initialisation failed\n");
  147. pseterr(ENXIO);
  148. func_exit ();
  149. return -ENXIO;
  150. }
  151. rio_dprintk (RIO_DEBUG_TTY, "port open SysPort %d (%s) (mapped:%d)\n",
  152. SysPort, Modem ? "Modem" : "tty",
  153. p->RIOPortp[SysPort]->Mapped);
  154. /*
  155. ** Validate that we have received a legitimate request.
  156. ** Currently, just check that we are opening a port on
  157. ** a host card that actually exists, and that the port
  158. ** has been mapped onto a host.
  159. */
  160. if (SysPort >= RIO_PORTS) { /* out of range ? */
  161. rio_dprintk (RIO_DEBUG_TTY, "Illegal port number %d\n",SysPort);
  162. pseterr(ENXIO);
  163. func_exit();
  164. return -ENXIO;
  165. }
  166. /*
  167. ** Grab pointer to the port stucture
  168. */
  169. PortP = p->RIOPortp[SysPort]; /* Get control struc */
  170. rio_dprintk (RIO_DEBUG_TTY, "PortP: %p\n", PortP);
  171. if ( !PortP->Mapped ) { /* we aren't mapped yet! */
  172. /*
  173. ** The system doesn't know which RTA this port
  174. ** corresponds to.
  175. */
  176. rio_dprintk (RIO_DEBUG_TTY, "port not mapped into system\n");
  177. func_exit ();
  178. pseterr(ENXIO);
  179. return -ENXIO;
  180. }
  181. tty->driver_data = PortP;
  182. PortP->gs.tty = tty;
  183. PortP->gs.count++;
  184. rio_dprintk (RIO_DEBUG_TTY, "%d bytes in tx buffer\n",
  185. PortP->gs.xmit_cnt);
  186. retval = gs_init_port (&PortP->gs);
  187. if (retval) {
  188. PortP->gs.count--;
  189. return -ENXIO;
  190. }
  191. /*
  192. ** If the host hasn't been booted yet, then
  193. ** fail
  194. */
  195. if ( (PortP->HostP->Flags & RUN_STATE) != RC_RUNNING ) {
  196. rio_dprintk (RIO_DEBUG_TTY, "Host not running\n");
  197. pseterr(ENXIO);
  198. func_exit ();
  199. return -ENXIO;
  200. }
  201. /*
  202. ** If the RTA has not booted yet and the user has choosen to block
  203. ** until the RTA is present then we must spin here waiting for
  204. ** the RTA to boot.
  205. */
  206. #if 0
  207. if (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED)) {
  208. if (PortP->WaitUntilBooted) {
  209. rio_dprintk (RIO_DEBUG_TTY, "Waiting for RTA to boot\n");
  210. do {
  211. if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
  212. rio_dprintk (RIO_DEBUG_TTY, "RTA EINTR in delay \n");
  213. func_exit ();
  214. return -EINTR;
  215. }
  216. if (repeat_this -- <= 0) {
  217. rio_dprintk (RIO_DEBUG_TTY, "Waiting for RTA to boot timeout\n");
  218. RIOPreemptiveCmd(p, PortP, FCLOSE );
  219. pseterr(EINTR);
  220. func_exit ();
  221. return -EIO;
  222. }
  223. } while(!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED));
  224. rio_dprintk (RIO_DEBUG_TTY, "RTA has been booted\n");
  225. } else {
  226. rio_dprintk (RIO_DEBUG_TTY, "RTA never booted\n");
  227. pseterr(ENXIO);
  228. func_exit ();
  229. return 0;
  230. }
  231. }
  232. #else
  233. /* I find the above code a bit hairy. I find the below code
  234. easier to read and shorter. Now, if it works too that would
  235. be great... -- REW
  236. */
  237. rio_dprintk (RIO_DEBUG_TTY, "Checking if RTA has booted... \n");
  238. while (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED)) {
  239. if (!PortP->WaitUntilBooted) {
  240. rio_dprintk (RIO_DEBUG_TTY, "RTA never booted\n");
  241. func_exit ();
  242. return -ENXIO;
  243. }
  244. /* Under Linux you'd normally use a wait instead of this
  245. busy-waiting. I'll stick with the old implementation for
  246. now. --REW
  247. */
  248. if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
  249. rio_dprintk (RIO_DEBUG_TTY, "RTA_wait_for_boot: EINTR in delay \n");
  250. func_exit ();
  251. return -EINTR;
  252. }
  253. if (repeat_this -- <= 0) {
  254. rio_dprintk (RIO_DEBUG_TTY, "Waiting for RTA to boot timeout\n");
  255. func_exit ();
  256. return -EIO;
  257. }
  258. }
  259. rio_dprintk (RIO_DEBUG_TTY, "RTA has been booted\n");
  260. #endif
  261. #if 0
  262. tp = PortP->TtyP; /* get tty struct */
  263. #endif
  264. rio_spin_lock_irqsave(&PortP->portSem, flags);
  265. if ( p->RIOHalted ) {
  266. goto bombout;
  267. }
  268. #if 0
  269. retval = gs_init_port(&PortP->gs);
  270. if (retval){
  271. func_exit ();
  272. return retval;
  273. }
  274. #endif
  275. /*
  276. ** If the port is in the final throws of being closed,
  277. ** we should wait here (politely), waiting
  278. ** for it to finish, so that it doesn't close us!
  279. */
  280. while ( (PortP->State & RIO_CLOSING) && !p->RIOHalted ) {
  281. rio_dprintk (RIO_DEBUG_TTY, "Waiting for RIO_CLOSING to go away\n");
  282. if (repeat_this -- <= 0) {
  283. rio_dprintk (RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n");
  284. RIOPreemptiveCmd(p, PortP, FCLOSE );
  285. retval = -EINTR;
  286. goto bombout;
  287. }
  288. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  289. if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
  290. rio_spin_lock_irqsave(&PortP->portSem, flags);
  291. retval = -EINTR;
  292. goto bombout;
  293. }
  294. rio_spin_lock_irqsave(&PortP->portSem, flags);
  295. }
  296. if ( !PortP->Mapped ) {
  297. rio_dprintk (RIO_DEBUG_TTY, "Port unmapped while closing!\n");
  298. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  299. retval = -ENXIO;
  300. func_exit ();
  301. return retval;
  302. }
  303. if ( p->RIOHalted ) {
  304. goto bombout;
  305. }
  306. /*
  307. ** 15.10.1998 ARG - ESIL 0761 part fix
  308. ** RIO has it's own CTSFLOW and RTSFLOW flags in 'Config' in the port structure,
  309. ** we need to make sure that the flags are clear when the port is opened.
  310. */
  311. /* Uh? Suppose I turn these on and then another process opens
  312. the port again? The flags get cleared! Not good. -- REW */
  313. if ( !(PortP->State & (RIO_LOPEN | RIO_MOPEN)) ) {
  314. PortP->Config &= ~(RIO_CTSFLOW|RIO_RTSFLOW);
  315. }
  316. if (!(PortP->firstOpen)) { /* First time ? */
  317. rio_dprintk (RIO_DEBUG_TTY, "First open for this port\n");
  318. PortP->firstOpen++;
  319. PortP->CookMode = 0; /* XXX RIOCookMode(tp); */
  320. PortP->InUse = NOT_INUSE;
  321. /* Tentative fix for bug PR27. Didn't work. */
  322. /* PortP->gs.xmit_cnt = 0; */
  323. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  324. #ifdef NEED_THIS
  325. ttyseth(PortP, tp, (struct old_sgttyb *)&default_sg);
  326. #endif
  327. /* Someone explain to me why this delay/config is
  328. here. If I read the docs correctly the "open"
  329. command piggybacks the parameters immediately.
  330. -- REW */
  331. RIOParam(PortP,OPEN,Modem,OK_TO_SLEEP); /* Open the port */
  332. #if 0
  333. /* This delay of 1 second was annoying. I removed it. -- REW */
  334. RIODelay(PortP, HUNDRED_MS*10);
  335. RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP); /* Config the port */
  336. #endif
  337. rio_spin_lock_irqsave(&PortP->portSem, flags);
  338. /*
  339. ** wait for the port to be not closed.
  340. */
  341. while ( !(PortP->PortState & PORT_ISOPEN) && !p->RIOHalted ) {
  342. rio_dprintk (RIO_DEBUG_TTY, "Waiting for PORT_ISOPEN-currently %x\n",PortP->PortState);
  343. /*
  344. ** 15.10.1998 ARG - ESIL 0759
  345. ** (Part) fix for port being trashed when opened whilst RTA "disconnected"
  346. ** Take out the limited wait - now wait for ever or until user
  347. ** bangs us out.
  348. **
  349. if (repeat_this -- <= 0) {
  350. rio_dprint(RIO_DEBUG_TTY, ("Waiting for open to finish timed out.\n"));
  351. RIOPreemptiveCmd(p, PortP, FCLOSE );
  352. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  353. return -EINTR;
  354. }
  355. **
  356. */
  357. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  358. if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
  359. rio_dprintk (RIO_DEBUG_TTY, "Waiting for open to finish broken by signal\n");
  360. RIOPreemptiveCmd(p, PortP, FCLOSE );
  361. func_exit ();
  362. return -EINTR;
  363. }
  364. rio_spin_lock_irqsave(&PortP->portSem, flags);
  365. }
  366. if ( p->RIOHalted ) {
  367. retval = -EIO;
  368. bombout:
  369. /* RIOClearUp( PortP ); */
  370. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  371. return retval;
  372. }
  373. rio_dprintk (RIO_DEBUG_TTY, "PORT_ISOPEN found\n");
  374. }
  375. #ifdef MODEM_SUPPORT
  376. if (Modem) {
  377. rio_dprintk (RIO_DEBUG_TTY, "Modem - test for carrier\n");
  378. /*
  379. ** ACTION
  380. ** insert test for carrier here. -- ???
  381. ** I already see that test here. What's the deal? -- REW
  382. */
  383. if ((PortP->gs.tty->termios->c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD))
  384. {
  385. rio_dprintk (RIO_DEBUG_TTY, "open(%d) Modem carr on\n", SysPort);
  386. /*
  387. tp->tm.c_state |= CARR_ON;
  388. wakeup((caddr_t) &tp->tm.c_canq);
  389. */
  390. PortP->State |= RIO_CARR_ON;
  391. wake_up_interruptible (&PortP->gs.open_wait);
  392. }
  393. else /* no carrier - wait for DCD */
  394. {
  395. /*
  396. while (!(PortP->gs.tty->termios->c_state & CARR_ON) &&
  397. !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted )
  398. */
  399. while (!(PortP->State & RIO_CARR_ON) &&
  400. !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted ) {
  401. rio_dprintk (RIO_DEBUG_TTY, "open(%d) sleeping for carr on\n",SysPort);
  402. /*
  403. PortP->gs.tty->termios->c_state |= WOPEN;
  404. */
  405. PortP->State |= RIO_WOPEN;
  406. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  407. if (RIODelay (PortP, HUNDRED_MS) == RIO_FAIL)
  408. #if 0
  409. if ( sleep((caddr_t)&tp->tm.c_canqo, TTIPRI|PCATCH))
  410. #endif
  411. {
  412. /*
  413. ** ACTION: verify that this is a good thing
  414. ** to do here. -- ???
  415. ** I think it's OK. -- REW
  416. */
  417. rio_dprintk (RIO_DEBUG_TTY, "open(%d) sleeping for carr broken by signal\n",
  418. SysPort);
  419. RIOPreemptiveCmd( p, PortP, FCLOSE );
  420. /*
  421. tp->tm.c_state &= ~WOPEN;
  422. */
  423. PortP->State &= ~RIO_WOPEN;
  424. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  425. func_exit ();
  426. return -EINTR;
  427. }
  428. }
  429. PortP->State &= ~RIO_WOPEN;
  430. }
  431. if ( p->RIOHalted )
  432. goto bombout;
  433. rio_dprintk (RIO_DEBUG_TTY, "Setting RIO_MOPEN\n");
  434. PortP->State |= RIO_MOPEN;
  435. }
  436. else
  437. #endif
  438. {
  439. /*
  440. ** ACTION
  441. ** Direct line open - force carrier (will probably mean
  442. ** that sleeping Modem line fubar)
  443. */
  444. PortP->State |= RIO_LOPEN;
  445. }
  446. if ( p->RIOHalted ) {
  447. goto bombout;
  448. }
  449. rio_dprintk (RIO_DEBUG_TTY, "high level open done\n");
  450. #ifdef STATS
  451. PortP->Stat.OpenCnt++;
  452. #endif
  453. /*
  454. ** Count opens for port statistics reporting
  455. */
  456. if (PortP->statsGather)
  457. PortP->opens++;
  458. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  459. rio_dprintk (RIO_DEBUG_TTY, "Returning from open\n");
  460. func_exit ();
  461. return 0;
  462. }
  463. /*
  464. ** RIOClose the port.
  465. ** The operating system thinks that this is last close for the device.
  466. ** As there are two interfaces to the port (Modem and tty), we need to
  467. ** check that both are closed before we close the device.
  468. */
  469. int
  470. riotclose(void *ptr)
  471. {
  472. #if 0
  473. register uint SysPort = dev;
  474. struct ttystatics *tp; /* pointer to our ttystruct */
  475. #endif
  476. struct Port *PortP = ptr; /* pointer to the port structure */
  477. int deleted = 0;
  478. int try = -1; /* Disable the timeouts by setting them to -1 */
  479. int repeat_this = -1; /* Congrats to those having 15 years of
  480. uptime! (You get to break the driver.) */
  481. unsigned long end_time;
  482. struct tty_struct * tty;
  483. unsigned long flags;
  484. int Modem;
  485. int rv = 0;
  486. rio_dprintk (RIO_DEBUG_TTY, "port close SysPort %d\n",PortP->PortNum);
  487. /* PortP = p->RIOPortp[SysPort]; */
  488. rio_dprintk (RIO_DEBUG_TTY, "Port is at address 0x%x\n",(int)PortP);
  489. /* tp = PortP->TtyP;*/ /* Get tty */
  490. tty = PortP->gs.tty;
  491. rio_dprintk (RIO_DEBUG_TTY, "TTY is at address 0x%x\n",(int)tty);
  492. if (PortP->gs.closing_wait)
  493. end_time = jiffies + PortP->gs.closing_wait;
  494. else
  495. end_time = jiffies + MAX_SCHEDULE_TIMEOUT;
  496. Modem = rio_ismodem(tty);
  497. #if 0
  498. /* What F.CKING cache? Even then, a higly idle multiprocessor,
  499. system with large caches this won't work . Better find out when
  500. this doesn't work asap, and fix the cause. -- REW */
  501. RIODelay(PortP, HUNDRED_MS*10); /* To flush the cache */
  502. #endif
  503. rio_spin_lock_irqsave(&PortP->portSem, flags);
  504. /*
  505. ** Setting this flag will make any process trying to open
  506. ** this port block until we are complete closing it.
  507. */
  508. PortP->State |= RIO_CLOSING;
  509. if ( (PortP->State & RIO_DELETED) ) {
  510. rio_dprintk (RIO_DEBUG_TTY, "Close on deleted RTA\n");
  511. deleted = 1;
  512. }
  513. if ( p->RIOHalted ) {
  514. RIOClearUp( PortP );
  515. rv = -EIO;
  516. goto close_end;
  517. }
  518. rio_dprintk (RIO_DEBUG_TTY, "Clear bits\n");
  519. /*
  520. ** clear the open bits for this device
  521. */
  522. PortP->State &= (Modem ? ~RIO_MOPEN : ~RIO_LOPEN);
  523. PortP->State &= ~RIO_CARR_ON;
  524. PortP->ModemState &= ~MSVR1_CD;
  525. /*
  526. ** If the device was open as both a Modem and a tty line
  527. ** then we need to wimp out here, as the port has not really
  528. ** been finally closed (gee, whizz!) The test here uses the
  529. ** bit for the OTHER mode of operation, to see if THAT is
  530. ** still active!
  531. */
  532. if ( (PortP->State & (RIO_LOPEN|RIO_MOPEN)) ) {
  533. /*
  534. ** The port is still open for the other task -
  535. ** return, pretending that we are still active.
  536. */
  537. rio_dprintk (RIO_DEBUG_TTY, "Channel %d still open !\n",PortP->PortNum);
  538. PortP->State &= ~RIO_CLOSING;
  539. if (PortP->firstOpen)
  540. PortP->firstOpen--;
  541. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  542. return -EIO;
  543. }
  544. rio_dprintk (RIO_DEBUG_TTY, "Closing down - everything must go!\n");
  545. PortP->State &= ~RIO_DYNOROD;
  546. /*
  547. ** This is where we wait for the port
  548. ** to drain down before closing. Bye-bye....
  549. ** (We never meant to do this)
  550. */
  551. rio_dprintk (RIO_DEBUG_TTY, "Timeout 1 starts\n");
  552. if (!deleted)
  553. while ( (PortP->InUse != NOT_INUSE) && !p->RIOHalted &&
  554. (PortP->TxBufferIn != PortP->TxBufferOut) ) {
  555. cprintf("Need to flush the ttyport\n");
  556. if (repeat_this -- <= 0) {
  557. rv = -EINTR;
  558. rio_dprintk (RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n");
  559. RIOPreemptiveCmd(p, PortP, FCLOSE);
  560. goto close_end;
  561. }
  562. rio_dprintk (RIO_DEBUG_TTY, "Calling timeout to flush in closing\n");
  563. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  564. if (RIODelay_ni(PortP, HUNDRED_MS*10) == RIO_FAIL) {
  565. rio_dprintk (RIO_DEBUG_TTY, "RTA EINTR in delay \n");
  566. rv = -EINTR;
  567. rio_spin_lock_irqsave(&PortP->portSem, flags);
  568. goto close_end;
  569. }
  570. rio_spin_lock_irqsave(&PortP->portSem, flags);
  571. }
  572. PortP->TxBufferIn = PortP->TxBufferOut = 0;
  573. repeat_this = 0xff;
  574. PortP->InUse = 0;
  575. if ( (PortP->State & (RIO_LOPEN|RIO_MOPEN)) ) {
  576. /*
  577. ** The port has been re-opened for the other task -
  578. ** return, pretending that we are still active.
  579. */
  580. rio_dprintk (RIO_DEBUG_TTY, "Channel %d re-open!\n", PortP->PortNum);
  581. PortP->State &= ~RIO_CLOSING;
  582. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  583. if (PortP->firstOpen)
  584. PortP->firstOpen--;
  585. return -EIO;
  586. }
  587. if ( p->RIOHalted ) {
  588. RIOClearUp( PortP );
  589. goto close_end;
  590. }
  591. /* Can't call RIOShortCommand with the port locked. */
  592. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  593. if (RIOShortCommand(p, PortP, CLOSE, 1, 0) == RIO_FAIL) {
  594. RIOPreemptiveCmd(p, PortP, FCLOSE);
  595. goto close_end;
  596. }
  597. if (!deleted)
  598. while (try && (PortP->PortState & PORT_ISOPEN)) {
  599. try--;
  600. if (time_after (jiffies, end_time)) {
  601. rio_dprintk (RIO_DEBUG_TTY, "Run out of tries - force the bugger shut!\n" );
  602. RIOPreemptiveCmd(p, PortP,FCLOSE);
  603. break;
  604. }
  605. rio_dprintk (RIO_DEBUG_TTY, "Close: PortState:ISOPEN is %d\n",
  606. PortP->PortState & PORT_ISOPEN);
  607. if ( p->RIOHalted ) {
  608. RIOClearUp( PortP );
  609. goto close_end;
  610. }
  611. if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
  612. rio_dprintk (RIO_DEBUG_TTY, "RTA EINTR in delay \n");
  613. RIOPreemptiveCmd(p, PortP,FCLOSE);
  614. break;
  615. }
  616. }
  617. rio_spin_lock_irqsave(&PortP->portSem, flags);
  618. rio_dprintk (RIO_DEBUG_TTY, "Close: try was %d on completion\n", try );
  619. /* RIOPreemptiveCmd(p, PortP, FCLOSE); */
  620. /*
  621. ** 15.10.1998 ARG - ESIL 0761 part fix
  622. ** RIO has it's own CTSFLOW and RTSFLOW flags in 'Config' in the port structure,** we need to make sure that the flags are clear when the port is opened.
  623. */
  624. PortP->Config &= ~(RIO_CTSFLOW|RIO_RTSFLOW);
  625. #ifdef STATS
  626. PortP->Stat.CloseCnt++;
  627. #endif
  628. /*
  629. ** Count opens for port statistics reporting
  630. */
  631. if (PortP->statsGather)
  632. PortP->closes++;
  633. close_end:
  634. /* XXX: Why would a "DELETED" flag be reset here? I'd have
  635. thought that a "deleted" flag means that the port was
  636. permanently gone, but here we can make it reappear by it
  637. being in close during the "deletion".
  638. */
  639. PortP->State &= ~(RIO_CLOSING|RIO_DELETED);
  640. if (PortP->firstOpen)
  641. PortP->firstOpen--;
  642. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  643. rio_dprintk (RIO_DEBUG_TTY, "Return from close\n");
  644. return rv;
  645. }
  646. /*
  647. ** decide if we need to use the line discipline.
  648. ** This routine can return one of three values:
  649. ** COOK_RAW if no processing has to be done by the line discipline or the card
  650. ** COOK_WELL if the line discipline must be used to do the processing
  651. ** COOK_MEDIUM if the card can do all the processing necessary.
  652. */
  653. #if 0
  654. static int
  655. RIOCookMode(struct ttystatics *tp)
  656. {
  657. /*
  658. ** We can't handle tm.c_mstate != 0 on SCO
  659. ** We can't handle mapping
  660. ** We can't handle non-ttwrite line disc.
  661. ** We can't handle lflag XCASE
  662. ** We can handle oflag OPOST & (OCRNL, ONLCR, TAB3)
  663. */
  664. #ifdef CHECK
  665. CheckTtyP( tp );
  666. #endif
  667. if (!(tp->tm.c_oflag & OPOST)) /* No post processing */
  668. return COOK_RAW; /* Raw mode o/p */
  669. if ( tp->tm.c_lflag & XCASE )
  670. return COOK_WELL; /* Use line disc */
  671. if (tp->tm.c_oflag & ~(OPOST | ONLCR | OCRNL | TAB3 ) )
  672. return COOK_WELL; /* Use line disc for strange modes */
  673. if ( tp->tm.c_oflag == OPOST ) /* If only OPOST is set, do RAW */
  674. return COOK_RAW;
  675. /*
  676. ** So, we need to output process!
  677. */
  678. return COOK_MEDIUM;
  679. }
  680. #endif
  681. static void
  682. RIOClearUp(PortP)
  683. struct Port *PortP;
  684. {
  685. rio_dprintk (RIO_DEBUG_TTY, "RIOHalted set\n");
  686. PortP->Config = 0; /* Direct semaphore */
  687. PortP->PortState = 0;
  688. PortP->firstOpen = 0;
  689. PortP->FlushCmdBodge = 0;
  690. PortP->ModemState = PortP->CookMode = 0;
  691. PortP->Mapped = 0;
  692. PortP->WflushFlag = 0;
  693. PortP->MagicFlags = 0;
  694. PortP->RxDataStart = 0;
  695. PortP->TxBufferIn = 0;
  696. PortP->TxBufferOut = 0;
  697. }
  698. /*
  699. ** Put a command onto a port.
  700. ** The PortPointer, command, length and arg are passed.
  701. ** The len is the length *inclusive* of the command byte,
  702. ** and so for a command that takes no data, len==1.
  703. ** The arg is a single byte, and is only used if len==2.
  704. ** Other values of len aren't allowed, and will cause
  705. ** a panic.
  706. */
  707. int RIOShortCommand(struct rio_info *p, struct Port *PortP,
  708. int command, int len, int arg)
  709. {
  710. PKT *PacketP;
  711. int retries = 20; /* at 10 per second -> 2 seconds */
  712. unsigned long flags;
  713. rio_dprintk (RIO_DEBUG_TTY, "entering shortcommand.\n");
  714. #ifdef CHECK
  715. CheckPortP( PortP );
  716. if ( len < 1 || len > 2 )
  717. cprintf(("STUPID LENGTH %d\n",len));
  718. #endif
  719. if ( PortP->State & RIO_DELETED ) {
  720. rio_dprintk (RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n");
  721. return RIO_FAIL;
  722. }
  723. rio_spin_lock_irqsave(&PortP->portSem, flags);
  724. /*
  725. ** If the port is in use for pre-emptive command, then wait for it to
  726. ** be free again.
  727. */
  728. while ( (PortP->InUse != NOT_INUSE) && !p->RIOHalted ) {
  729. rio_dprintk (RIO_DEBUG_TTY, "Waiting for not in use (%d)\n",
  730. retries);
  731. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  732. if (retries-- <= 0) {
  733. return RIO_FAIL;
  734. }
  735. if (RIODelay_ni(PortP, HUNDRED_MS) == RIO_FAIL) {
  736. return RIO_FAIL;
  737. }
  738. rio_spin_lock_irqsave(&PortP->portSem, flags);
  739. }
  740. if ( PortP->State & RIO_DELETED ) {
  741. rio_dprintk (RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n");
  742. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  743. return RIO_FAIL;
  744. }
  745. while ( !can_add_transmit(&PacketP,PortP) && !p->RIOHalted ) {
  746. rio_dprintk (RIO_DEBUG_TTY, "Waiting to add short command to queue (%d)\n", retries);
  747. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  748. if (retries-- <= 0) {
  749. rio_dprintk (RIO_DEBUG_TTY, "out of tries. Failing\n");
  750. return RIO_FAIL;
  751. }
  752. if ( RIODelay_ni(PortP, HUNDRED_MS)==RIO_FAIL ) {
  753. return RIO_FAIL;
  754. }
  755. rio_spin_lock_irqsave(&PortP->portSem, flags);
  756. }
  757. if ( p->RIOHalted ) {
  758. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  759. return RIO_FAIL;
  760. }
  761. /*
  762. ** set the command byte and the argument byte
  763. */
  764. WBYTE(PacketP->data[0] , command);
  765. if ( len==2 )
  766. WBYTE(PacketP->data[1] , arg);
  767. /*
  768. ** set the length of the packet and set the command bit.
  769. */
  770. WBYTE(PacketP->len , PKT_CMD_BIT | len);
  771. add_transmit(PortP);
  772. /*
  773. ** Count characters transmitted for port statistics reporting
  774. */
  775. if (PortP->statsGather)
  776. PortP->txchars += len;
  777. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  778. return p->RIOHalted ? RIO_FAIL : ~RIO_FAIL;
  779. }
  780. #if 0
  781. /*
  782. ** This is an ioctl interface. This is the twentieth century. You know what
  783. ** its all about.
  784. */
  785. int
  786. riotioctl(struct rio_info *p, struct tty_struct *tty, int cmd, caddr_t arg)
  787. {
  788. register struct Port *PortP;
  789. register struct ttystatics *tp;
  790. int current;
  791. int ParamSemIncremented = 0;
  792. int old_oflag, old_cflag, old_iflag, changed, oldcook;
  793. int i;
  794. unsigned char sio_regs[5]; /* Here be magic */
  795. short vpix_cflag;
  796. short divisor;
  797. int baud;
  798. uint SysPort = rio_minor(tty);
  799. int Modem = rio_ismodem(tty);
  800. int ioctl_processed;
  801. rio_dprintk (RIO_DEBUG_TTY, "port ioctl SysPort %d command 0x%x argument 0x%x %s\n",
  802. SysPort, cmd, arg, Modem?"Modem":"tty") ;
  803. if ( SysPort >= RIO_PORTS ) {
  804. rio_dprintk (RIO_DEBUG_TTY, "Bad port number %d\n", SysPort);
  805. return -ENXIO;
  806. }
  807. PortP = p->RIOPortp[SysPort];
  808. tp = PortP->TtyP;
  809. rio_spin_lock_irqsave(&PortP->portSem, flags);
  810. #ifdef STATS
  811. PortP->Stat.IoctlCnt++;
  812. #endif
  813. if ( PortP->State & RIO_DELETED ) {
  814. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  815. return -EIO;
  816. }
  817. if ( p->RIOHalted ) {
  818. RIOClearUp( PortP );
  819. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  820. return -EIO;
  821. }
  822. /*
  823. ** Count ioctls for port statistics reporting
  824. */
  825. if (PortP->statsGather)
  826. PortP->ioctls++;
  827. /*
  828. ** Specialix RIO Ioctl calls
  829. */
  830. switch (cmd) {
  831. case TCRIOTRIAD:
  832. if ( arg )
  833. PortP->State |= RIO_TRIAD_MODE;
  834. else
  835. PortP->State &= ~RIO_TRIAD_MODE;
  836. /*
  837. ** Normally, when istrip is set on a port, a config is
  838. ** sent to the RTA instructing the CD1400 to do the
  839. ** stripping. In TRIAD mode, the interrupt receive routine
  840. ** must do the stripping instead, since it has to detect
  841. ** an 8 bit function key sequence. If istrip is set with
  842. ** TRIAD mode on(off), and 8 bit data is being read by
  843. ** the port, the user then turns TRIAD mode off(on), the RTA
  844. ** must be reconfigured (not) to do the stripping.
  845. ** Hence we call RIOParam here.
  846. */
  847. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  848. RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);
  849. return 0;
  850. case TCRIOTSTATE:
  851. rio_dprintk (RIO_DEBUG_TTY, "tbusy/tstop monitoring %sabled\n",
  852. arg ? "en" : "dis");
  853. /* MonitorTstate = 0 ;*/
  854. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  855. RIOParam(PortP, CONFIG, Modem, OK_TO_SLEEP);
  856. return 0;
  857. case TCRIOSTATE: /* current state of Modem input pins */
  858. rio_dprintk (RIO_DEBUG_TTY, "TCRIOSTATE\n");
  859. if (RIOPreemptiveCmd(p, PortP, MGET) == RIO_FAIL)
  860. rio_dprintk (RIO_DEBUG_TTY, "TCRIOSTATE command failed\n");
  861. PortP->State |= RIO_BUSY;
  862. current = PortP->ModemState;
  863. if ( copyout((caddr_t)&current, (int)arg,
  864. sizeof(current))==COPYFAIL ) {
  865. rio_dprintk (RIO_DEBUG_TTY, "Copyout failed\n");
  866. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  867. pseterr(EFAULT);
  868. }
  869. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  870. return 0;
  871. case TCRIOMBIS: /* Set modem lines */
  872. case TCRIOMBIC: /* Clear modem lines */
  873. rio_dprintk (RIO_DEBUG_TTY, "TCRIOMBIS/TCRIOMBIC\n");
  874. if (cmd == TCRIOMBIS) {
  875. uint state;
  876. state = (uint)arg;
  877. PortP->ModemState |= (ushort)state;
  878. PortP->ModemLines = (ulong) arg;
  879. if (RIOPreemptiveCmd(p, PortP, MBIS) == RIO_FAIL)
  880. rio_dprintk (RIO_DEBUG_TTY,
  881. "TCRIOMBIS command failed\n");
  882. }
  883. else {
  884. uint state;
  885. state = (uint)arg;
  886. PortP->ModemState &= ~(ushort)state;
  887. PortP->ModemLines = (ulong) arg;
  888. if (RIOPreemptiveCmd(p, PortP, MBIC) == RIO_FAIL)
  889. rio_dprintk (RIO_DEBUG_TTY, "TCRIOMBIC command failed\n");
  890. }
  891. PortP->State |= RIO_BUSY;
  892. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  893. return 0;
  894. case TCRIOXPON: /* set Xprint ON string */
  895. rio_dprintk (RIO_DEBUG_TTY, "TCRIOXPON\n");
  896. if ( copyin((int)arg, (caddr_t)PortP->Xprint.XpOn,
  897. MAX_XP_CTRL_LEN)==COPYFAIL ) {
  898. rio_dprintk (RIO_DEBUG_TTY, "Copyin failed\n");
  899. PortP->Xprint.XpOn[0] = '\0';
  900. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  901. pseterr(EFAULT);
  902. }
  903. PortP->Xprint.XpOn[MAX_XP_CTRL_LEN-1] = '\0';
  904. PortP->Xprint.XpLen = strlen(PortP->Xprint.XpOn)+
  905. strlen(PortP->Xprint.XpOff);
  906. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  907. return 0;
  908. case TCRIOXPOFF: /* set Xprint OFF string */
  909. rio_dprintk (RIO_DEBUG_TTY, "TCRIOXPOFF\n");
  910. if ( copyin( (int)arg, (caddr_t)PortP->Xprint.XpOff,
  911. MAX_XP_CTRL_LEN)==COPYFAIL ) {
  912. rio_dprintk (RIO_DEBUG_TTY, "Copyin failed\n");
  913. PortP->Xprint.XpOff[0] = '\0';
  914. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  915. pseterr(EFAULT);
  916. }
  917. PortP->Xprint.XpOff[MAX_XP_CTRL_LEN-1] = '\0';
  918. PortP->Xprint.XpLen = strlen(PortP->Xprint.XpOn)+
  919. strlen(PortP->Xprint.XpOff);
  920. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  921. return 0;
  922. case TCRIOXPCPS: /* set Xprint CPS string */
  923. rio_dprintk (RIO_DEBUG_TTY, "TCRIOXPCPS\n");
  924. if ( (uint)arg > p->RIOConf.MaxXpCps ||
  925. (uint)arg < p->RIOConf.MinXpCps ) {
  926. rio_dprintk (RIO_DEBUG_TTY, "%d CPS out of range\n",arg);
  927. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  928. pseterr(EINVAL);
  929. return 0;
  930. }
  931. PortP->Xprint.XpCps = (uint)arg;
  932. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  933. return 0;
  934. case TCRIOXPRINT:
  935. rio_dprintk (RIO_DEBUG_TTY, "TCRIOXPRINT\n");
  936. if ( copyout((caddr_t)&PortP->Xprint, (int)arg,
  937. sizeof(struct Xprint))==COPYFAIL ) {
  938. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  939. pseterr(EFAULT);
  940. }
  941. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  942. return 0;
  943. case TCRIOIXANYON:
  944. rio_dprintk (RIO_DEBUG_TTY, "TCRIOIXANYON\n");
  945. PortP->Config |= RIO_IXANY;
  946. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  947. return 0;
  948. case TCRIOIXANYOFF:
  949. rio_dprintk (RIO_DEBUG_TTY, "TCRIOIXANYOFF\n");
  950. PortP->Config &= ~RIO_IXANY;
  951. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  952. return 0;
  953. case TCRIOIXONON:
  954. rio_dprintk (RIO_DEBUG_TTY, "TCRIOIXONON\n");
  955. PortP->Config |= RIO_IXON;
  956. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  957. return 0;
  958. case TCRIOIXONOFF:
  959. rio_dprintk (RIO_DEBUG_TTY, "TCRIOIXONOFF\n");
  960. PortP->Config &= ~RIO_IXON;
  961. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  962. return 0;
  963. /*
  964. ** 15.10.1998 ARG - ESIL 0761 part fix
  965. ** Added support for CTS and RTS flow control ioctls :
  966. */
  967. case TCRIOCTSFLOWEN:
  968. rio_dprintk (RIO_DEBUG_TTY, "TCRIOCTSFLOWEN\n");
  969. PortP->Config |= RIO_CTSFLOW;
  970. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  971. RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);
  972. return 0;
  973. case TCRIOCTSFLOWDIS:
  974. rio_dprintk (RIO_DEBUG_TTY, "TCRIOCTSFLOWDIS\n");
  975. PortP->Config &= ~RIO_CTSFLOW;
  976. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  977. RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);
  978. return 0;
  979. case TCRIORTSFLOWEN:
  980. rio_dprintk (RIO_DEBUG_TTY, "TCRIORTSFLOWEN\n");
  981. PortP->Config |= RIO_RTSFLOW;
  982. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  983. RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);
  984. return 0;
  985. case TCRIORTSFLOWDIS:
  986. rio_dprintk (RIO_DEBUG_TTY, "TCRIORTSFLOWDIS\n");
  987. PortP->Config &= ~RIO_RTSFLOW;
  988. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  989. RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);
  990. return 0;
  991. /* end ESIL 0761 part fix */
  992. }
  993. /* Lynx IOCTLS */
  994. switch (cmd) {
  995. case TIOCSETP:
  996. case TIOCSETN:
  997. case OTIOCSETP:
  998. case OTIOCSETN:
  999. ioctl_processed++;
  1000. ttyseth(PortP, tp, (struct old_sgttyb *)arg);
  1001. break;
  1002. case TCSETA:
  1003. case TCSETAW:
  1004. case TCSETAF:
  1005. ioctl_processed++;
  1006. rio_dprintk (RIO_DEBUG_TTY, "NON POSIX ioctl\n");
  1007. ttyseth_pv(PortP, tp, (struct termios *)arg, 0);
  1008. break;
  1009. case TCSETAP: /* posix tcsetattr() */
  1010. case TCSETAWP: /* posix tcsetattr() */
  1011. case TCSETAFP: /* posix tcsetattr() */
  1012. rio_dprintk (RIO_DEBUG_TTY, "NON POSIX SYSV ioctl\n");
  1013. ttyseth_pv(PortP, tp, (struct termios *)arg, 1);
  1014. ioctl_processed++;
  1015. break;
  1016. }
  1017. /*
  1018. ** If its any of the commands that require the port to be in the
  1019. ** non-busy state wait until all output has drained
  1020. */
  1021. if (!ioctl_processed)
  1022. switch(cmd) {
  1023. case TCSETAW:
  1024. case TCSETAF:
  1025. case TCSETA:
  1026. case TCSBRK:
  1027. #define OLD_POSIX ('x' << 8)
  1028. #define OLD_POSIX_SETA (OLD_POSIX | 2)
  1029. #define OLD_POSIX_SETAW (OLD_POSIX | 3)
  1030. #define OLD_POSIX_SETAF (OLD_POSIX | 4)
  1031. #define NEW_POSIX (('i' << 24) | ('X' << 16))
  1032. #define NEW_POSIX_SETA (NEW_POSIX | 2)
  1033. #define NEW_POSIX_SETAW (NEW_POSIX | 3)
  1034. #define NEW_POSIX_SETAF (NEW_POSIX | 4)
  1035. case OLD_POSIX_SETA:
  1036. case OLD_POSIX_SETAW:
  1037. case OLD_POSIX_SETAF:
  1038. case NEW_POSIX_SETA:
  1039. case NEW_POSIX_SETAW:
  1040. case NEW_POSIX_SETAF:
  1041. #ifdef TIOCSETP
  1042. case TIOCSETP:
  1043. #endif
  1044. case TIOCSETD:
  1045. case TIOCSETN:
  1046. rio_dprintk (RIO_DEBUG_TTY, "wait for non-BUSY, semaphore set\n");
  1047. /*
  1048. ** Wait for drain here, at least as far as the double buffer
  1049. ** being empty.
  1050. */
  1051. /* XXX Does the above comment mean that this has
  1052. still to be implemented? -- REW */
  1053. /* XXX Is the locking OK together with locking
  1054. in txenable? (Deadlock?) -- REW */
  1055. RIOTxEnable((char *)PortP);
  1056. break;
  1057. default:
  1058. break;
  1059. }
  1060. old_cflag = tp->tm.c_cflag;
  1061. old_iflag = tp->tm.c_iflag;
  1062. old_oflag = tp->tm.c_oflag;
  1063. oldcook = PortP->CookMode;
  1064. if ( p->RIOHalted ) {
  1065. RIOClearUp( PortP );
  1066. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  1067. pseterr(EIO);
  1068. return 0;
  1069. }
  1070. PortP->FlushCmdBodge = 0;
  1071. /*
  1072. ** If the port is locked, and it is reconfigured, we want
  1073. ** to restore the state of the tty structure so the change is NOT
  1074. ** made.
  1075. */
  1076. if (PortP->Lock) {
  1077. tp->tm.c_iflag = PortP->StoredTty.iflag;
  1078. tp->tm.c_oflag = PortP->StoredTty.oflag;
  1079. tp->tm.c_cflag = PortP->StoredTty.cflag;
  1080. tp->tm.c_lflag = PortP->StoredTty.lflag;
  1081. tp->tm.c_line = PortP->StoredTty.line;
  1082. for (i = 0; i < NCC + 1; i++)
  1083. tp->tm.c_cc[i] = PortP->StoredTty.cc[i];
  1084. }
  1085. else {
  1086. /*
  1087. ** If the port is set to store the parameters, and it is
  1088. ** reconfigured, we want to save the current tty struct so it
  1089. ** may be restored on the next open.
  1090. */
  1091. if (PortP->Store) {
  1092. PortP->StoredTty.iflag = tp->tm.c_iflag;
  1093. PortP->StoredTty.oflag = tp->tm.c_oflag;
  1094. PortP->StoredTty.cflag = tp->tm.c_cflag;
  1095. PortP->StoredTty.lflag = tp->tm.c_lflag;
  1096. PortP->StoredTty.line = tp->tm.c_line;
  1097. for (i = 0; i < NCC + 1; i++)
  1098. PortP->StoredTty.cc[i] = tp->tm.c_cc[i];
  1099. }
  1100. }
  1101. changed = (tp->tm.c_cflag != old_cflag) ||
  1102. (tp->tm.c_iflag != old_iflag) ||
  1103. (tp->tm.c_oflag != old_oflag);
  1104. PortP->CookMode = RIOCookMode(tp); /* Set new cooking mode */
  1105. rio_dprintk (RIO_DEBUG_TTY, "RIOIoctl changed %d newcook %d oldcook %d\n",
  1106. changed,PortP->CookMode,oldcook);
  1107. #ifdef MODEM_SUPPORT
  1108. /*
  1109. ** kludge to force CARR_ON if CLOCAL set
  1110. */
  1111. if ((tp->tm.c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD)) {
  1112. tp->tm.c_state |= CARR_ON;
  1113. wakeup ((caddr_t)&tp->tm.c_canq);
  1114. }
  1115. #endif
  1116. if ( p->RIOHalted ) {
  1117. RIOClearUp( PortP );
  1118. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  1119. pseterr(EIO);
  1120. return 0;
  1121. }
  1122. /*
  1123. ** Re-configure if modes or cooking have changed
  1124. */
  1125. if (changed || oldcook != PortP->CookMode || (ioctl_processed)) {
  1126. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  1127. rio_dprintk (RIO_DEBUG_TTY, "Ioctl changing the PORT settings\n");
  1128. RIOParam(PortP,CONFIG,Modem,OK_TO_SLEEP);
  1129. rio_spin_lock_irqsave(&PortP->portSem, flags);
  1130. }
  1131. if (p->RIOHalted) {
  1132. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  1133. RIOClearUp( PortP );
  1134. pseterr(EIO);
  1135. return 0;
  1136. }
  1137. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  1138. return 0;
  1139. }
  1140. /*
  1141. ttyseth -- set hardware dependent tty settings
  1142. */
  1143. void
  1144. ttyseth(PortP, s, sg)
  1145. struct Port * PortP;
  1146. struct ttystatics * s;
  1147. struct old_sgttyb *sg;
  1148. {
  1149. struct old_sgttyb * tsg;
  1150. struct termios *tp = &s->tm;
  1151. tsg = &s->sg;
  1152. if (sg->sg_flags & (EVENP|ODDP)) {
  1153. tp->c_cflag &= PARENB;
  1154. if (sg->sg_flags & EVENP) {
  1155. if (sg->sg_flags & ODDP) {
  1156. tp->c_cflag &= V_CS7;
  1157. tp->c_cflag &= ~PARENB;
  1158. }
  1159. else {
  1160. tp->c_cflag &= V_CS7;
  1161. tp->c_cflag &= PARENB;
  1162. tp->c_cflag &= PARODD;
  1163. }
  1164. }
  1165. else if (sg->sg_flags & ODDP) {
  1166. tp->c_cflag &= V_CS7;
  1167. tp->c_cflag &= PARENB;
  1168. tp->c_cflag &= PARODD;
  1169. }
  1170. else {
  1171. tp->c_cflag &= V_CS7;
  1172. tp->c_cflag &= PARENB;
  1173. }
  1174. }
  1175. /*
  1176. * Use ispeed as the desired speed. Most implementations don't handle
  1177. * separate input and output speeds very well. If the RIO handles this,
  1178. * I will have to use separate sets of flags to store them in the
  1179. * Port structure.
  1180. */
  1181. if ( !sg->sg_ospeed )
  1182. sg->sg_ospeed = sg->sg_ispeed;
  1183. else
  1184. sg->sg_ispeed = sg->sg_ospeed;
  1185. if (sg->sg_ispeed > V_EXTB )
  1186. sg->sg_ispeed = V_EXTB;
  1187. if (sg->sg_ispeed < V_B0)
  1188. sg->sg_ispeed = V_B0;
  1189. *tsg = *sg;
  1190. tp->c_cflag = (tp->c_cflag & ~V_CBAUD) | conv_bv[(int)sg->sg_ispeed];
  1191. }
  1192. /*
  1193. ttyseth_pv -- set hardware dependent tty settings using either the
  1194. POSIX termios structure or the System V termio structure.
  1195. sysv = 0 => (POSIX): struct termios *sg
  1196. sysv != 0 => (System V): struct termio *sg
  1197. */
  1198. static void
  1199. ttyseth_pv(PortP, s, sg, sysv)
  1200. struct Port *PortP;
  1201. struct ttystatics *s;
  1202. struct termios *sg;
  1203. int sysv;
  1204. {
  1205. int speed;
  1206. unsigned char csize;
  1207. unsigned char cread;
  1208. unsigned int lcr_flags;
  1209. int ps;
  1210. if (sysv) {
  1211. /* sg points to a System V termio structure */
  1212. csize = ((struct termio *)sg)->c_cflag & CSIZE;
  1213. cread = ((struct termio *)sg)->c_cflag & CREAD;
  1214. speed = conv_vb[((struct termio *)sg)->c_cflag & V_CBAUD];
  1215. }
  1216. else {
  1217. /* sg points to a POSIX termios structure */
  1218. csize = sg->c_cflag & CSIZE;
  1219. cread = sg->c_cflag & CREAD;
  1220. speed = conv_vb[sg->c_cflag & V_CBAUD];
  1221. }
  1222. if (s->sg.sg_ispeed != speed || s->sg.sg_ospeed != speed) {
  1223. s->sg.sg_ispeed = speed;
  1224. s->sg.sg_ospeed = speed;
  1225. s->tm.c_cflag = (s->tm.c_cflag & ~V_CBAUD) |
  1226. conv_bv[(int)s->sg.sg_ispeed];
  1227. }
  1228. }
  1229. #endif