riotty.c 20 KB

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