riotty.c 18 KB

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