riotty.c 18 KB

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