riotty.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  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. static void RIOClearUp(struct Port *PortP);
  83. int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
  84. extern int conv_vb[]; /* now defined in ttymgr.c */
  85. extern int conv_bv[]; /* now defined in ttymgr.c */
  86. /*
  87. ** 16.09.1998 ARG - Fix to build riotty.k.o for Modular Kernel Support
  88. **
  89. ** ep.def.h is necessary for Modular Kernel Support
  90. ** DO NOT place any kernel 'extern's after this line
  91. ** or this source file will not build riotty.k.o
  92. */
  93. #ifdef uLYNX
  94. #include <ep.def.h>
  95. #endif
  96. #ifdef NEED_THIS2
  97. static struct old_sgttyb default_sg = {
  98. B19200, B19200, /* input and output speed */
  99. 'H' - '@', /* erase char */
  100. -1, /* 2nd erase char */
  101. 'U' - '@', /* kill char */
  102. ECHO | CRMOD, /* mode */
  103. 'C' - '@', /* interrupt character */
  104. '\\' - '@', /* quit char */
  105. 'Q' - '@', /* start char */
  106. 'S' - '@', /* stop char */
  107. 'D' - '@', /* EOF */
  108. -1, /* brk */
  109. (LCRTBS | LCRTERA | LCRTKIL | LCTLECH), /* local mode word */
  110. 'Z' - '@', /* process stop */
  111. 'Y' - '@', /* delayed stop */
  112. 'R' - '@', /* reprint line */
  113. 'O' - '@', /* flush output */
  114. 'W' - '@', /* word erase */
  115. 'V' - '@' /* literal next char */
  116. };
  117. #endif
  118. extern struct rio_info *p;
  119. int riotopen(struct tty_struct *tty, struct file *filp)
  120. {
  121. unsigned int SysPort;
  122. int Modem;
  123. int repeat_this = 250;
  124. struct Port *PortP; /* pointer to the port structure */
  125. unsigned long flags;
  126. int retval = 0;
  127. func_enter();
  128. /* Make sure driver_data is NULL in case the rio isn't booted jet. Else gs_close
  129. is going to oops.
  130. */
  131. tty->driver_data = NULL;
  132. SysPort = rio_minor(tty);
  133. Modem = rio_ismodem(tty);
  134. if (p->RIOFailed) {
  135. rio_dprintk(RIO_DEBUG_TTY, "System initialisation failed\n");
  136. func_exit();
  137. return -ENXIO;
  138. }
  139. rio_dprintk(RIO_DEBUG_TTY, "port open SysPort %d (%s) (mapped:%d)\n", SysPort, Modem ? "Modem" : "tty", p->RIOPortp[SysPort]->Mapped);
  140. /*
  141. ** Validate that we have received a legitimate request.
  142. ** Currently, just check that we are opening a port on
  143. ** a host card that actually exists, and that the port
  144. ** has been mapped onto a host.
  145. */
  146. if (SysPort >= RIO_PORTS) { /* out of range ? */
  147. rio_dprintk(RIO_DEBUG_TTY, "Illegal port number %d\n", SysPort);
  148. func_exit();
  149. return -ENXIO;
  150. }
  151. /*
  152. ** Grab pointer to the port stucture
  153. */
  154. PortP = p->RIOPortp[SysPort]; /* Get control struc */
  155. rio_dprintk(RIO_DEBUG_TTY, "PortP: %p\n", PortP);
  156. if (!PortP->Mapped) { /* we aren't mapped yet! */
  157. /*
  158. ** The system doesn't know which RTA this port
  159. ** corresponds to.
  160. */
  161. rio_dprintk(RIO_DEBUG_TTY, "port not mapped into system\n");
  162. func_exit();
  163. return -ENXIO;
  164. }
  165. tty->driver_data = PortP;
  166. PortP->gs.tty = tty;
  167. PortP->gs.count++;
  168. rio_dprintk(RIO_DEBUG_TTY, "%d bytes in tx buffer\n", PortP->gs.xmit_cnt);
  169. retval = gs_init_port(&PortP->gs);
  170. if (retval) {
  171. PortP->gs.count--;
  172. return -ENXIO;
  173. }
  174. /*
  175. ** If the host hasn't been booted yet, then
  176. ** fail
  177. */
  178. if ((PortP->HostP->Flags & RUN_STATE) != RC_RUNNING) {
  179. rio_dprintk(RIO_DEBUG_TTY, "Host not running\n");
  180. func_exit();
  181. return -ENXIO;
  182. }
  183. /*
  184. ** If the RTA has not booted yet and the user has choosen to block
  185. ** until the RTA is present then we must spin here waiting for
  186. ** the RTA to boot.
  187. */
  188. /* I find the above code a bit hairy. I find the below code
  189. easier to read and shorter. Now, if it works too that would
  190. be great... -- REW
  191. */
  192. rio_dprintk(RIO_DEBUG_TTY, "Checking if RTA has booted... \n");
  193. while (!(PortP->HostP->Mapping[PortP->RupNum].Flags & RTA_BOOTED)) {
  194. if (!PortP->WaitUntilBooted) {
  195. rio_dprintk(RIO_DEBUG_TTY, "RTA never booted\n");
  196. func_exit();
  197. return -ENXIO;
  198. }
  199. /* Under Linux you'd normally use a wait instead of this
  200. busy-waiting. I'll stick with the old implementation for
  201. now. --REW
  202. */
  203. if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
  204. rio_dprintk(RIO_DEBUG_TTY, "RTA_wait_for_boot: EINTR in delay \n");
  205. func_exit();
  206. return -EINTR;
  207. }
  208. if (repeat_this-- <= 0) {
  209. rio_dprintk(RIO_DEBUG_TTY, "Waiting for RTA to boot timeout\n");
  210. func_exit();
  211. return -EIO;
  212. }
  213. }
  214. rio_dprintk(RIO_DEBUG_TTY, "RTA has been booted\n");
  215. rio_spin_lock_irqsave(&PortP->portSem, flags);
  216. if (p->RIOHalted) {
  217. goto bombout;
  218. }
  219. /*
  220. ** If the port is in the final throws of being closed,
  221. ** we should wait here (politely), waiting
  222. ** for it to finish, so that it doesn't close us!
  223. */
  224. while ((PortP->State & RIO_CLOSING) && !p->RIOHalted) {
  225. rio_dprintk(RIO_DEBUG_TTY, "Waiting for RIO_CLOSING to go away\n");
  226. if (repeat_this-- <= 0) {
  227. rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n");
  228. RIOPreemptiveCmd(p, PortP, FCLOSE);
  229. retval = -EINTR;
  230. goto bombout;
  231. }
  232. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  233. if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
  234. rio_spin_lock_irqsave(&PortP->portSem, flags);
  235. retval = -EINTR;
  236. goto bombout;
  237. }
  238. rio_spin_lock_irqsave(&PortP->portSem, flags);
  239. }
  240. if (!PortP->Mapped) {
  241. rio_dprintk(RIO_DEBUG_TTY, "Port unmapped while closing!\n");
  242. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  243. retval = -ENXIO;
  244. func_exit();
  245. return retval;
  246. }
  247. if (p->RIOHalted) {
  248. goto bombout;
  249. }
  250. /*
  251. ** 15.10.1998 ARG - ESIL 0761 part fix
  252. ** RIO has it's own CTSFLOW and RTSFLOW flags in 'Config' in the port structure,
  253. ** we need to make sure that the flags are clear when the port is opened.
  254. */
  255. /* Uh? Suppose I turn these on and then another process opens
  256. the port again? The flags get cleared! Not good. -- REW */
  257. if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
  258. PortP->Config &= ~(RIO_CTSFLOW | RIO_RTSFLOW);
  259. }
  260. if (!(PortP->firstOpen)) { /* First time ? */
  261. rio_dprintk(RIO_DEBUG_TTY, "First open for this port\n");
  262. PortP->firstOpen++;
  263. PortP->CookMode = 0; /* XXX RIOCookMode(tp); */
  264. PortP->InUse = NOT_INUSE;
  265. /* Tentative fix for bug PR27. Didn't work. */
  266. /* PortP->gs.xmit_cnt = 0; */
  267. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  268. #ifdef NEED_THIS
  269. ttyseth(PortP, tp, (struct old_sgttyb *) &default_sg);
  270. #endif
  271. /* Someone explain to me why this delay/config is
  272. here. If I read the docs correctly the "open"
  273. command piggybacks the parameters immediately.
  274. -- REW */
  275. RIOParam(PortP, OPEN, Modem, OK_TO_SLEEP); /* Open the port */
  276. rio_spin_lock_irqsave(&PortP->portSem, flags);
  277. /*
  278. ** wait for the port to be not closed.
  279. */
  280. while (!(PortP->PortState & PORT_ISOPEN) && !p->RIOHalted) {
  281. rio_dprintk(RIO_DEBUG_TTY, "Waiting for PORT_ISOPEN-currently %x\n", PortP->PortState);
  282. /*
  283. ** 15.10.1998 ARG - ESIL 0759
  284. ** (Part) fix for port being trashed when opened whilst RTA "disconnected"
  285. ** Take out the limited wait - now wait for ever or until user
  286. ** bangs us out.
  287. **
  288. if (repeat_this -- <= 0) {
  289. rio_dprint(RIO_DEBUG_TTY, ("Waiting for open to finish timed out.\n"));
  290. RIOPreemptiveCmd(p, PortP, FCLOSE );
  291. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  292. return -EINTR;
  293. }
  294. **
  295. */
  296. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  297. if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
  298. rio_dprintk(RIO_DEBUG_TTY, "Waiting for open to finish broken by signal\n");
  299. RIOPreemptiveCmd(p, PortP, FCLOSE);
  300. func_exit();
  301. return -EINTR;
  302. }
  303. rio_spin_lock_irqsave(&PortP->portSem, flags);
  304. }
  305. if (p->RIOHalted) {
  306. retval = -EIO;
  307. bombout:
  308. /* RIOClearUp( PortP ); */
  309. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  310. return retval;
  311. }
  312. rio_dprintk(RIO_DEBUG_TTY, "PORT_ISOPEN found\n");
  313. }
  314. #ifdef MODEM_SUPPORT
  315. if (Modem) {
  316. rio_dprintk(RIO_DEBUG_TTY, "Modem - test for carrier\n");
  317. /*
  318. ** ACTION
  319. ** insert test for carrier here. -- ???
  320. ** I already see that test here. What's the deal? -- REW
  321. */
  322. if ((PortP->gs.tty->termios->c_cflag & CLOCAL) || (PortP->ModemState & MSVR1_CD)) {
  323. rio_dprintk(RIO_DEBUG_TTY, "open(%d) Modem carr on\n", SysPort);
  324. /*
  325. tp->tm.c_state |= CARR_ON;
  326. wakeup((caddr_t) &tp->tm.c_canq);
  327. */
  328. PortP->State |= RIO_CARR_ON;
  329. wake_up_interruptible(&PortP->gs.open_wait);
  330. } else { /* no carrier - wait for DCD */
  331. /*
  332. while (!(PortP->gs.tty->termios->c_state & CARR_ON) &&
  333. !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted )
  334. */
  335. while (!(PortP->State & RIO_CARR_ON) && !(filp->f_flags & O_NONBLOCK) && !p->RIOHalted) {
  336. rio_dprintk(RIO_DEBUG_TTY, "open(%d) sleeping for carr on\n", SysPort);
  337. /*
  338. PortP->gs.tty->termios->c_state |= WOPEN;
  339. */
  340. PortP->State |= RIO_WOPEN;
  341. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  342. if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL)
  343. {
  344. /*
  345. ** ACTION: verify that this is a good thing
  346. ** to do here. -- ???
  347. ** I think it's OK. -- REW
  348. */
  349. rio_dprintk(RIO_DEBUG_TTY, "open(%d) sleeping for carr broken by signal\n", SysPort);
  350. RIOPreemptiveCmd(p, PortP, FCLOSE);
  351. /*
  352. tp->tm.c_state &= ~WOPEN;
  353. */
  354. PortP->State &= ~RIO_WOPEN;
  355. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  356. func_exit();
  357. return -EINTR;
  358. }
  359. }
  360. PortP->State &= ~RIO_WOPEN;
  361. }
  362. if (p->RIOHalted)
  363. goto bombout;
  364. rio_dprintk(RIO_DEBUG_TTY, "Setting RIO_MOPEN\n");
  365. PortP->State |= RIO_MOPEN;
  366. } else
  367. #endif
  368. {
  369. /*
  370. ** ACTION
  371. ** Direct line open - force carrier (will probably mean
  372. ** that sleeping Modem line fubar)
  373. */
  374. PortP->State |= RIO_LOPEN;
  375. }
  376. if (p->RIOHalted) {
  377. goto bombout;
  378. }
  379. rio_dprintk(RIO_DEBUG_TTY, "high level open done\n");
  380. /*
  381. ** Count opens for port statistics reporting
  382. */
  383. if (PortP->statsGather)
  384. PortP->opens++;
  385. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  386. rio_dprintk(RIO_DEBUG_TTY, "Returning from open\n");
  387. func_exit();
  388. return 0;
  389. }
  390. /*
  391. ** RIOClose the port.
  392. ** The operating system thinks that this is last close for the device.
  393. ** As there are two interfaces to the port (Modem and tty), we need to
  394. ** check that both are closed before we close the device.
  395. */
  396. int riotclose(void *ptr)
  397. {
  398. struct Port *PortP = ptr; /* pointer to the port structure */
  399. int deleted = 0;
  400. int try = -1; /* Disable the timeouts by setting them to -1 */
  401. int repeat_this = -1; /* Congrats to those having 15 years of
  402. uptime! (You get to break the driver.) */
  403. unsigned long end_time;
  404. struct tty_struct *tty;
  405. unsigned long flags;
  406. int Modem;
  407. int rv = 0;
  408. rio_dprintk(RIO_DEBUG_TTY, "port close SysPort %d\n", PortP->PortNum);
  409. /* PortP = p->RIOPortp[SysPort]; */
  410. rio_dprintk(RIO_DEBUG_TTY, "Port is at address 0x%p\n", PortP);
  411. /* tp = PortP->TtyP; *//* Get tty */
  412. tty = PortP->gs.tty;
  413. rio_dprintk(RIO_DEBUG_TTY, "TTY is at address 0x%p\n", tty);
  414. if (PortP->gs.closing_wait)
  415. end_time = jiffies + PortP->gs.closing_wait;
  416. else
  417. end_time = jiffies + MAX_SCHEDULE_TIMEOUT;
  418. Modem = rio_ismodem(tty);
  419. rio_spin_lock_irqsave(&PortP->portSem, flags);
  420. /*
  421. ** Setting this flag will make any process trying to open
  422. ** this port block until we are complete closing it.
  423. */
  424. PortP->State |= RIO_CLOSING;
  425. if ((PortP->State & RIO_DELETED)) {
  426. rio_dprintk(RIO_DEBUG_TTY, "Close on deleted RTA\n");
  427. deleted = 1;
  428. }
  429. if (p->RIOHalted) {
  430. RIOClearUp(PortP);
  431. rv = -EIO;
  432. goto close_end;
  433. }
  434. rio_dprintk(RIO_DEBUG_TTY, "Clear bits\n");
  435. /*
  436. ** clear the open bits for this device
  437. */
  438. PortP->State &= (Modem ? ~RIO_MOPEN : ~RIO_LOPEN);
  439. PortP->State &= ~RIO_CARR_ON;
  440. PortP->ModemState &= ~MSVR1_CD;
  441. /*
  442. ** If the device was open as both a Modem and a tty line
  443. ** then we need to wimp out here, as the port has not really
  444. ** been finally closed (gee, whizz!) The test here uses the
  445. ** bit for the OTHER mode of operation, to see if THAT is
  446. ** still active!
  447. */
  448. if ((PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
  449. /*
  450. ** The port is still open for the other task -
  451. ** return, pretending that we are still active.
  452. */
  453. rio_dprintk(RIO_DEBUG_TTY, "Channel %d still open !\n", PortP->PortNum);
  454. PortP->State &= ~RIO_CLOSING;
  455. if (PortP->firstOpen)
  456. PortP->firstOpen--;
  457. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  458. return -EIO;
  459. }
  460. rio_dprintk(RIO_DEBUG_TTY, "Closing down - everything must go!\n");
  461. PortP->State &= ~RIO_DYNOROD;
  462. /*
  463. ** This is where we wait for the port
  464. ** to drain down before closing. Bye-bye....
  465. ** (We never meant to do this)
  466. */
  467. rio_dprintk(RIO_DEBUG_TTY, "Timeout 1 starts\n");
  468. if (!deleted)
  469. while ((PortP->InUse != NOT_INUSE) && !p->RIOHalted && (PortP->TxBufferIn != PortP->TxBufferOut)) {
  470. if (repeat_this-- <= 0) {
  471. rv = -EINTR;
  472. rio_dprintk(RIO_DEBUG_TTY, "Waiting for not idle closed broken by signal\n");
  473. RIOPreemptiveCmd(p, PortP, FCLOSE);
  474. goto close_end;
  475. }
  476. rio_dprintk(RIO_DEBUG_TTY, "Calling timeout to flush in closing\n");
  477. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  478. if (RIODelay_ni(PortP, HUNDRED_MS * 10) == RIO_FAIL) {
  479. rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n");
  480. rv = -EINTR;
  481. rio_spin_lock_irqsave(&PortP->portSem, flags);
  482. goto close_end;
  483. }
  484. rio_spin_lock_irqsave(&PortP->portSem, flags);
  485. }
  486. PortP->TxBufferIn = PortP->TxBufferOut = 0;
  487. repeat_this = 0xff;
  488. PortP->InUse = 0;
  489. if ((PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
  490. /*
  491. ** The port has been re-opened for the other task -
  492. ** return, pretending that we are still active.
  493. */
  494. rio_dprintk(RIO_DEBUG_TTY, "Channel %d re-open!\n", PortP->PortNum);
  495. PortP->State &= ~RIO_CLOSING;
  496. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  497. if (PortP->firstOpen)
  498. PortP->firstOpen--;
  499. return -EIO;
  500. }
  501. if (p->RIOHalted) {
  502. RIOClearUp(PortP);
  503. goto close_end;
  504. }
  505. /* Can't call RIOShortCommand with the port locked. */
  506. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  507. if (RIOShortCommand(p, PortP, CLOSE, 1, 0) == RIO_FAIL) {
  508. RIOPreemptiveCmd(p, PortP, FCLOSE);
  509. goto close_end;
  510. }
  511. if (!deleted)
  512. while (try && (PortP->PortState & PORT_ISOPEN)) {
  513. try--;
  514. if (time_after(jiffies, end_time)) {
  515. rio_dprintk(RIO_DEBUG_TTY, "Run out of tries - force the bugger shut!\n");
  516. RIOPreemptiveCmd(p, PortP, FCLOSE);
  517. break;
  518. }
  519. rio_dprintk(RIO_DEBUG_TTY, "Close: PortState:ISOPEN is %d\n", PortP->PortState & PORT_ISOPEN);
  520. if (p->RIOHalted) {
  521. RIOClearUp(PortP);
  522. goto close_end;
  523. }
  524. if (RIODelay(PortP, HUNDRED_MS) == RIO_FAIL) {
  525. rio_dprintk(RIO_DEBUG_TTY, "RTA EINTR in delay \n");
  526. RIOPreemptiveCmd(p, PortP, FCLOSE);
  527. break;
  528. }
  529. }
  530. rio_spin_lock_irqsave(&PortP->portSem, flags);
  531. rio_dprintk(RIO_DEBUG_TTY, "Close: try was %d on completion\n", try);
  532. /* RIOPreemptiveCmd(p, PortP, FCLOSE); */
  533. /*
  534. ** 15.10.1998 ARG - ESIL 0761 part fix
  535. ** 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.
  536. */
  537. PortP->Config &= ~(RIO_CTSFLOW | RIO_RTSFLOW);
  538. /*
  539. ** Count opens for port statistics reporting
  540. */
  541. if (PortP->statsGather)
  542. PortP->closes++;
  543. close_end:
  544. /* XXX: Why would a "DELETED" flag be reset here? I'd have
  545. thought that a "deleted" flag means that the port was
  546. permanently gone, but here we can make it reappear by it
  547. being in close during the "deletion".
  548. */
  549. PortP->State &= ~(RIO_CLOSING | RIO_DELETED);
  550. if (PortP->firstOpen)
  551. PortP->firstOpen--;
  552. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  553. rio_dprintk(RIO_DEBUG_TTY, "Return from close\n");
  554. return rv;
  555. }
  556. static void RIOClearUp(PortP)
  557. struct Port *PortP;
  558. {
  559. rio_dprintk(RIO_DEBUG_TTY, "RIOHalted set\n");
  560. PortP->Config = 0; /* Direct semaphore */
  561. PortP->PortState = 0;
  562. PortP->firstOpen = 0;
  563. PortP->FlushCmdBodge = 0;
  564. PortP->ModemState = PortP->CookMode = 0;
  565. PortP->Mapped = 0;
  566. PortP->WflushFlag = 0;
  567. PortP->MagicFlags = 0;
  568. PortP->RxDataStart = 0;
  569. PortP->TxBufferIn = 0;
  570. PortP->TxBufferOut = 0;
  571. }
  572. /*
  573. ** Put a command onto a port.
  574. ** The PortPointer, command, length and arg are passed.
  575. ** The len is the length *inclusive* of the command byte,
  576. ** and so for a command that takes no data, len==1.
  577. ** The arg is a single byte, and is only used if len==2.
  578. ** Other values of len aren't allowed, and will cause
  579. ** a panic.
  580. */
  581. int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg)
  582. {
  583. PKT *PacketP;
  584. int retries = 20; /* at 10 per second -> 2 seconds */
  585. unsigned long flags;
  586. rio_dprintk(RIO_DEBUG_TTY, "entering shortcommand.\n");
  587. if (PortP->State & RIO_DELETED) {
  588. rio_dprintk(RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n");
  589. return RIO_FAIL;
  590. }
  591. rio_spin_lock_irqsave(&PortP->portSem, flags);
  592. /*
  593. ** If the port is in use for pre-emptive command, then wait for it to
  594. ** be free again.
  595. */
  596. while ((PortP->InUse != NOT_INUSE) && !p->RIOHalted) {
  597. rio_dprintk(RIO_DEBUG_TTY, "Waiting for not in use (%d)\n", retries);
  598. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  599. if (retries-- <= 0) {
  600. return RIO_FAIL;
  601. }
  602. if (RIODelay_ni(PortP, HUNDRED_MS) == RIO_FAIL) {
  603. return RIO_FAIL;
  604. }
  605. rio_spin_lock_irqsave(&PortP->portSem, flags);
  606. }
  607. if (PortP->State & RIO_DELETED) {
  608. rio_dprintk(RIO_DEBUG_TTY, "Short command to deleted RTA ignored\n");
  609. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  610. return RIO_FAIL;
  611. }
  612. while (!can_add_transmit(&PacketP, PortP) && !p->RIOHalted) {
  613. rio_dprintk(RIO_DEBUG_TTY, "Waiting to add short command to queue (%d)\n", retries);
  614. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  615. if (retries-- <= 0) {
  616. rio_dprintk(RIO_DEBUG_TTY, "out of tries. Failing\n");
  617. return RIO_FAIL;
  618. }
  619. if (RIODelay_ni(PortP, HUNDRED_MS) == RIO_FAIL) {
  620. return RIO_FAIL;
  621. }
  622. rio_spin_lock_irqsave(&PortP->portSem, flags);
  623. }
  624. if (p->RIOHalted) {
  625. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  626. return RIO_FAIL;
  627. }
  628. /*
  629. ** set the command byte and the argument byte
  630. */
  631. writeb(command, &PacketP->data[0]);
  632. if (len == 2)
  633. writeb(arg, &PacketP->data[1]);
  634. /*
  635. ** set the length of the packet and set the command bit.
  636. */
  637. writeb(PKT_CMD_BIT | len, &PacketP->len);
  638. add_transmit(PortP);
  639. /*
  640. ** Count characters transmitted for port statistics reporting
  641. */
  642. if (PortP->statsGather)
  643. PortP->txchars += len;
  644. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  645. return p->RIOHalted ? RIO_FAIL : ~RIO_FAIL;
  646. }