rioparam.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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 : rioparam.c
  24. ** SID : 1.3
  25. ** Last Modified : 11/6/98 10:33:45
  26. ** Retrieved : 11/6/98 10:33:50
  27. **
  28. ** ident @(#)rioparam.c 1.3
  29. **
  30. ** -----------------------------------------------------------------------------
  31. */
  32. #ifdef SCCS_LABELS
  33. static char *_rioparam_c_sccs_ = "@(#)rioparam.c 1.3";
  34. #endif
  35. #include <linux/module.h>
  36. #include <linux/slab.h>
  37. #include <linux/errno.h>
  38. #include <linux/tty.h>
  39. #include <asm/io.h>
  40. #include <asm/system.h>
  41. #include <asm/string.h>
  42. #include <asm/semaphore.h>
  43. #include <asm/uaccess.h>
  44. #include <linux/termios.h>
  45. #include <linux/serial.h>
  46. #include <linux/generic_serial.h>
  47. #include "linux_compat.h"
  48. #include "rio_linux.h"
  49. #include "typdef.h"
  50. #include "pkt.h"
  51. #include "daemon.h"
  52. #include "rio.h"
  53. #include "riospace.h"
  54. #include "top.h"
  55. #include "cmdpkt.h"
  56. #include "map.h"
  57. #include "riotypes.h"
  58. #include "rup.h"
  59. #include "port.h"
  60. #include "riodrvr.h"
  61. #include "rioinfo.h"
  62. #include "func.h"
  63. #include "errors.h"
  64. #include "pci.h"
  65. #include "parmmap.h"
  66. #include "unixrup.h"
  67. #include "board.h"
  68. #include "host.h"
  69. #include "error.h"
  70. #include "phb.h"
  71. #include "link.h"
  72. #include "cmdblk.h"
  73. #include "route.h"
  74. #include "control.h"
  75. #include "cirrus.h"
  76. #include "rioioctl.h"
  77. #include "param.h"
  78. #include "list.h"
  79. #include "sam.h"
  80. /*
  81. ** The Scam, based on email from jeremyr@bugs.specialix.co.uk....
  82. **
  83. ** To send a command on a particular port, you put a packet with the
  84. ** command bit set onto the port. The command bit is in the len field,
  85. ** and gets ORed in with the actual byte count.
  86. **
  87. ** When you send a packet with the command bit set, then the first
  88. ** data byte ( data[0] ) is interpretted as the command to execute.
  89. ** It also governs what data structure overlay should accompany the packet.
  90. ** Commands are defined in cirrus/cirrus.h
  91. **
  92. ** If you want the command to pre-emt data already on the queue for the
  93. ** port, set the pre-emptive bit in conjunction with the command bit.
  94. ** It is not defined what will happen if you set the preemptive bit
  95. ** on a packet that is NOT a command.
  96. **
  97. ** Pre-emptive commands should be queued at the head of the queue using
  98. ** add_start(), whereas normal commands and data are enqueued using
  99. ** add_end().
  100. **
  101. ** Most commands do not use the remaining bytes in the data array. The
  102. ** exceptions are OPEN MOPEN and CONFIG. (NB. As with the SI CONFIG and
  103. ** OPEN are currently analagous). With these three commands the following
  104. ** 11 data bytes are all used to pass config information such as baud rate etc.
  105. ** The fields are also defined in cirrus.h. Some contain straightforward
  106. ** information such as the transmit XON character. Two contain the transmit and
  107. ** receive baud rates respectively. For most baud rates there is a direct
  108. ** mapping between the rates defined in <sys/termio.h> and the byte in the
  109. ** packet. There are additional (non UNIX-standard) rates defined in
  110. ** /u/dos/rio/cirrus/h/brates.h.
  111. **
  112. ** The rest of the data fields contain approximations to the Cirrus registers
  113. ** that are used to program number of bits etc. Each registers bit fields is
  114. ** defined in cirrus.h.
  115. **
  116. ** NB. Only use those bits that are defined as being driver specific
  117. ** or common to the RTA and the driver.
  118. **
  119. ** All commands going from RTA->Host will be dealt with by the Host code - you
  120. ** will never see them. As with the SI there will be three fields to look out
  121. ** for in each phb (not yet defined - needs defining a.s.a.p).
  122. **
  123. ** modem_status - current state of handshake pins.
  124. **
  125. ** port_status - current port status - equivalent to hi_stat for SI, indicates
  126. ** if port is IDLE_OPEN, IDLE_CLOSED etc.
  127. **
  128. ** break_status - bit X set if break has been received.
  129. **
  130. ** Happy hacking.
  131. **
  132. */
  133. /*
  134. ** RIOParam is used to open or configure a port. You pass it a PortP,
  135. ** which will have a tty struct attached to it. You also pass a command,
  136. ** either OPEN or CONFIG. The port's setup is taken from the t_ fields
  137. ** of the tty struct inside the PortP, and the port is either opened
  138. ** or re-configured. You must also tell RIOParam if the device is a modem
  139. ** device or not (i.e. top bit of minor number set or clear - take special
  140. ** care when deciding on this!).
  141. ** RIOParam neither flushes nor waits for drain, and is NOT preemptive.
  142. **
  143. ** RIOParam assumes it will be called at splrio(), and also assumes
  144. ** that CookMode is set correctly in the port structure.
  145. **
  146. ** NB. for MPX
  147. ** tty lock must NOT have been previously acquired.
  148. */
  149. int
  150. RIOParam(PortP, cmd, Modem, SleepFlag)
  151. struct Port *PortP;
  152. int cmd;
  153. int Modem;
  154. int SleepFlag;
  155. {
  156. register struct tty_struct *TtyP;
  157. int retval;
  158. register struct phb_param *phb_param_ptr;
  159. PKT *PacketP;
  160. int res;
  161. uchar Cor1=0, Cor2=0, Cor4=0, Cor5=0;
  162. uchar TxXon=0, TxXoff=0, RxXon=0, RxXoff=0;
  163. uchar LNext=0, TxBaud=0, RxBaud=0;
  164. int retries = 0xff;
  165. unsigned long flags;
  166. func_enter ();
  167. TtyP = PortP->gs.tty;
  168. rio_dprintk (RIO_DEBUG_PARAM, "RIOParam: Port:%d cmd:%d Modem:%d SleepFlag:%d Mapped: %d, tty=%p\n",
  169. PortP->PortNum, cmd, Modem, SleepFlag, PortP->Mapped, TtyP);
  170. if (!TtyP) {
  171. rio_dprintk (RIO_DEBUG_PARAM, "Can't call rioparam with null tty.\n");
  172. func_exit ();
  173. return RIO_FAIL;
  174. }
  175. rio_spin_lock_irqsave(&PortP->portSem, flags );
  176. if (cmd == OPEN) {
  177. /*
  178. ** If the port is set to store or lock the parameters, and it is
  179. ** paramed with OPEN, we want to restore the saved port termio, but
  180. ** only if StoredTermio has been saved, i.e. NOT 1st open after reboot.
  181. */
  182. #if 0
  183. if (PortP->FirstOpen) {
  184. PortP->StoredTty.iflag = TtyP->tm.c_iflag;
  185. PortP->StoredTty.oflag = TtyP->tm.c_oflag;
  186. PortP->StoredTty.cflag = TtyP->tm.c_cflag;
  187. PortP->StoredTty.lflag = TtyP->tm.c_lflag;
  188. PortP->StoredTty.line = TtyP->tm.c_line;
  189. for (i = 0; i < NCC + 5; i++)
  190. PortP->StoredTty.cc[i] = TtyP->tm.c_cc[i];
  191. PortP->FirstOpen = 0;
  192. }
  193. else if (PortP->Store || PortP->Lock) {
  194. rio_dprintk (RIO_DEBUG_PARAM, "OPEN: Restoring stored/locked params\n");
  195. TtyP->tm.c_iflag = PortP->StoredTty.iflag;
  196. TtyP->tm.c_oflag = PortP->StoredTty.oflag;
  197. TtyP->tm.c_cflag = PortP->StoredTty.cflag;
  198. TtyP->tm.c_lflag = PortP->StoredTty.lflag;
  199. TtyP->tm.c_line = PortP->StoredTty.line;
  200. for (i = 0; i < NCC + 5; i++)
  201. TtyP->tm.c_cc[i] = PortP->StoredTty.cc[i];
  202. }
  203. #endif
  204. }
  205. /*
  206. ** wait for space
  207. */
  208. while ( !(res=can_add_transmit(&PacketP,PortP)) ||
  209. (PortP->InUse != NOT_INUSE) ) {
  210. if (retries -- <= 0) {
  211. break;
  212. }
  213. if ( PortP->InUse != NOT_INUSE ) {
  214. rio_dprintk (RIO_DEBUG_PARAM, "Port IN_USE for pre-emptive command\n");
  215. }
  216. if ( !res ) {
  217. rio_dprintk (RIO_DEBUG_PARAM, "Port has no space on transmit queue\n");
  218. }
  219. if ( SleepFlag != OK_TO_SLEEP ) {
  220. rio_spin_unlock_irqrestore( &PortP->portSem, flags);
  221. func_exit();
  222. return RIO_FAIL;
  223. }
  224. rio_dprintk (RIO_DEBUG_PARAM, "wait for can_add_transmit\n");
  225. rio_spin_unlock_irqrestore( &PortP->portSem, flags);
  226. retval = RIODelay(PortP, HUNDRED_MS);
  227. rio_spin_lock_irqsave( &PortP->portSem, flags);
  228. if (retval == RIO_FAIL) {
  229. rio_dprintk (RIO_DEBUG_PARAM, "wait for can_add_transmit broken by signal\n");
  230. rio_spin_unlock_irqrestore( &PortP->portSem, flags);
  231. pseterr(EINTR);
  232. func_exit();
  233. return RIO_FAIL;
  234. }
  235. if ( PortP->State & RIO_DELETED ) {
  236. rio_spin_unlock_irqrestore( &PortP->portSem, flags);
  237. func_exit ();
  238. return RIO_SUCCESS;
  239. }
  240. }
  241. if (!res) {
  242. rio_spin_unlock_irqrestore( &PortP->portSem, flags);
  243. func_exit ();
  244. return RIO_FAIL;
  245. }
  246. rio_dprintk (RIO_DEBUG_PARAM, "can_add_transmit() returns %x\n",res);
  247. rio_dprintk (RIO_DEBUG_PARAM, "Packet is 0x%x\n",(int) PacketP);
  248. phb_param_ptr = (struct phb_param *)PacketP->data;
  249. #if 0
  250. /*
  251. ** COR 1
  252. */
  253. if ( TtyP->tm.c_iflag & INPCK ) {
  254. rio_dprintk (RIO_DEBUG_PARAM, "Parity checking on input enabled\n");
  255. Cor1 |= COR1_INPCK;
  256. }
  257. #endif
  258. switch ( TtyP->termios->c_cflag & CSIZE ) {
  259. case CS5:
  260. {
  261. rio_dprintk (RIO_DEBUG_PARAM, "5 bit data\n");
  262. Cor1 |= COR1_5BITS;
  263. break;
  264. }
  265. case CS6:
  266. {
  267. rio_dprintk (RIO_DEBUG_PARAM, "6 bit data\n");
  268. Cor1 |= COR1_6BITS;
  269. break;
  270. }
  271. case CS7:
  272. {
  273. rio_dprintk (RIO_DEBUG_PARAM, "7 bit data\n");
  274. Cor1 |= COR1_7BITS;
  275. break;
  276. }
  277. case CS8:
  278. {
  279. rio_dprintk (RIO_DEBUG_PARAM, "8 bit data\n");
  280. Cor1 |= COR1_8BITS;
  281. break;
  282. }
  283. }
  284. if ( TtyP->termios->c_cflag & CSTOPB ) {
  285. rio_dprintk (RIO_DEBUG_PARAM, "2 stop bits\n");
  286. Cor1 |= COR1_2STOP;
  287. }
  288. else {
  289. rio_dprintk (RIO_DEBUG_PARAM, "1 stop bit\n");
  290. Cor1 |= COR1_1STOP;
  291. }
  292. if ( TtyP->termios->c_cflag & PARENB ) {
  293. rio_dprintk (RIO_DEBUG_PARAM, "Enable parity\n");
  294. Cor1 |= COR1_NORMAL;
  295. }
  296. else {
  297. rio_dprintk (RIO_DEBUG_PARAM, "Disable parity\n");
  298. Cor1 |= COR1_NOP;
  299. }
  300. if ( TtyP->termios->c_cflag & PARODD ) {
  301. rio_dprintk (RIO_DEBUG_PARAM, "Odd parity\n");
  302. Cor1 |= COR1_ODD;
  303. }
  304. else {
  305. rio_dprintk (RIO_DEBUG_PARAM, "Even parity\n");
  306. Cor1 |= COR1_EVEN;
  307. }
  308. /*
  309. ** COR 2
  310. */
  311. if ( TtyP->termios->c_iflag & IXON ) {
  312. rio_dprintk (RIO_DEBUG_PARAM, "Enable start/stop output control\n");
  313. Cor2 |= COR2_IXON;
  314. }
  315. else {
  316. if ( PortP->Config & RIO_IXON ) {
  317. rio_dprintk (RIO_DEBUG_PARAM, "Force enable start/stop output control\n");
  318. Cor2 |= COR2_IXON;
  319. }
  320. else
  321. rio_dprintk (RIO_DEBUG_PARAM, "IXON has been disabled.\n");
  322. }
  323. if (TtyP->termios->c_iflag & IXANY) {
  324. if ( PortP->Config & RIO_IXANY ) {
  325. rio_dprintk (RIO_DEBUG_PARAM, "Enable any key to restart output\n");
  326. Cor2 |= COR2_IXANY;
  327. }
  328. else
  329. rio_dprintk (RIO_DEBUG_PARAM, "IXANY has been disabled due to sanity reasons.\n");
  330. }
  331. if ( TtyP->termios->c_iflag & IXOFF ) {
  332. rio_dprintk (RIO_DEBUG_PARAM, "Enable start/stop input control 2\n");
  333. Cor2 |= COR2_IXOFF;
  334. }
  335. if ( TtyP->termios->c_cflag & HUPCL ) {
  336. rio_dprintk (RIO_DEBUG_PARAM, "Hangup on last close\n");
  337. Cor2 |= COR2_HUPCL;
  338. }
  339. if ( C_CRTSCTS (TtyP)) {
  340. rio_dprintk (RIO_DEBUG_PARAM, "Rx hardware flow control enabled\n");
  341. Cor2 |= COR2_CTSFLOW;
  342. Cor2 |= COR2_RTSFLOW;
  343. } else {
  344. rio_dprintk (RIO_DEBUG_PARAM, "Rx hardware flow control disabled\n");
  345. Cor2 &= ~COR2_CTSFLOW;
  346. Cor2 &= ~COR2_RTSFLOW;
  347. }
  348. if ( TtyP->termios->c_cflag & CLOCAL ) {
  349. rio_dprintk (RIO_DEBUG_PARAM, "Local line\n");
  350. }
  351. else {
  352. rio_dprintk (RIO_DEBUG_PARAM, "Possible Modem line\n");
  353. }
  354. /*
  355. ** COR 4 (there is no COR 3)
  356. */
  357. if ( TtyP->termios->c_iflag & IGNBRK ) {
  358. rio_dprintk (RIO_DEBUG_PARAM, "Ignore break condition\n");
  359. Cor4 |= COR4_IGNBRK;
  360. }
  361. if ( !(TtyP->termios->c_iflag & BRKINT) ) {
  362. rio_dprintk (RIO_DEBUG_PARAM, "Break generates NULL condition\n");
  363. Cor4 |= COR4_NBRKINT;
  364. } else {
  365. rio_dprintk (RIO_DEBUG_PARAM, "Interrupt on break condition\n");
  366. }
  367. if ( TtyP->termios->c_iflag & INLCR ) {
  368. rio_dprintk (RIO_DEBUG_PARAM, "Map newline to carriage return on input\n");
  369. Cor4 |= COR4_INLCR;
  370. }
  371. if ( TtyP->termios->c_iflag & IGNCR ) {
  372. rio_dprintk (RIO_DEBUG_PARAM, "Ignore carriage return on input\n");
  373. Cor4 |= COR4_IGNCR;
  374. }
  375. if ( TtyP->termios->c_iflag & ICRNL ) {
  376. rio_dprintk (RIO_DEBUG_PARAM, "Map carriage return to newline on input\n");
  377. Cor4 |= COR4_ICRNL;
  378. }
  379. if ( TtyP->termios->c_iflag & IGNPAR ) {
  380. rio_dprintk (RIO_DEBUG_PARAM, "Ignore characters with parity errors\n");
  381. Cor4 |= COR4_IGNPAR;
  382. }
  383. if ( TtyP->termios->c_iflag & PARMRK ) {
  384. rio_dprintk (RIO_DEBUG_PARAM, "Mark parity errors\n");
  385. Cor4 |= COR4_PARMRK;
  386. }
  387. /*
  388. ** Set the RAISEMOD flag to ensure that the modem lines are raised
  389. ** on reception of a config packet.
  390. ** The download code handles the zero baud condition.
  391. */
  392. Cor4 |= COR4_RAISEMOD;
  393. /*
  394. ** COR 5
  395. */
  396. Cor5 = COR5_CMOE;
  397. /*
  398. ** Set to monitor tbusy/tstop (or not).
  399. */
  400. if (PortP->MonitorTstate)
  401. Cor5 |= COR5_TSTATE_ON;
  402. else
  403. Cor5 |= COR5_TSTATE_OFF;
  404. /*
  405. ** Could set LNE here if you wanted LNext processing. SVR4 will use it.
  406. */
  407. if ( TtyP->termios->c_iflag & ISTRIP ) {
  408. rio_dprintk (RIO_DEBUG_PARAM, "Strip input characters\n");
  409. if (! (PortP->State & RIO_TRIAD_MODE)) {
  410. Cor5 |= COR5_ISTRIP;
  411. }
  412. }
  413. if ( TtyP->termios->c_oflag & ONLCR ) {
  414. rio_dprintk (RIO_DEBUG_PARAM, "Map newline to carriage-return, newline on output\n");
  415. if ( PortP->CookMode == COOK_MEDIUM )
  416. Cor5 |= COR5_ONLCR;
  417. }
  418. if ( TtyP->termios->c_oflag & OCRNL ) {
  419. rio_dprintk (RIO_DEBUG_PARAM, "Map carriage return to newline on output\n");
  420. if ( PortP->CookMode == COOK_MEDIUM )
  421. Cor5 |= COR5_OCRNL;
  422. }
  423. if ( ( TtyP->termios->c_oflag & TABDLY) == TAB3 ) {
  424. rio_dprintk (RIO_DEBUG_PARAM, "Tab delay 3 set\n");
  425. if ( PortP->CookMode == COOK_MEDIUM )
  426. Cor5 |= COR5_TAB3;
  427. }
  428. /*
  429. ** Flow control bytes.
  430. */
  431. TxXon = TtyP->termios->c_cc[VSTART];
  432. TxXoff = TtyP->termios->c_cc[VSTOP];
  433. RxXon = TtyP->termios->c_cc[VSTART];
  434. RxXoff = TtyP->termios->c_cc[VSTOP];
  435. /*
  436. ** LNEXT byte
  437. */
  438. LNext = 0;
  439. /*
  440. ** Baud rate bytes
  441. */
  442. rio_dprintk (RIO_DEBUG_PARAM, "Mapping of rx/tx baud %x (%x)\n",
  443. TtyP->termios->c_cflag, CBAUD);
  444. switch (TtyP->termios->c_cflag & CBAUD) {
  445. #define e(b) case B ## b : RxBaud = TxBaud = RIO_B ## b ;break
  446. e(50);e(75);e(110);e(134);e(150);e(200);e(300);e(600);e(1200);
  447. e(1800);e(2400);e(4800);e(9600);e(19200);e(38400);e(57600);
  448. e(115200); /* e(230400);e(460800); e(921600); */
  449. }
  450. /* XXX MIssing conversion table. XXX */
  451. /* (TtyP->termios->c_cflag & V_CBAUD); */
  452. rio_dprintk (RIO_DEBUG_PARAM, "tx baud 0x%x, rx baud 0x%x\n", TxBaud, RxBaud);
  453. /*
  454. ** Leftovers
  455. */
  456. if ( TtyP->termios->c_cflag & CREAD )
  457. rio_dprintk (RIO_DEBUG_PARAM, "Enable receiver\n");
  458. #ifdef RCV1EN
  459. if ( TtyP->termios->c_cflag & RCV1EN )
  460. rio_dprintk (RIO_DEBUG_PARAM, "RCV1EN (?)\n");
  461. #endif
  462. #ifdef XMT1EN
  463. if ( TtyP->termios->c_cflag & XMT1EN )
  464. rio_dprintk (RIO_DEBUG_PARAM, "XMT1EN (?)\n");
  465. #endif
  466. #if 0
  467. if ( TtyP->termios->c_cflag & LOBLK )
  468. rio_dprintk (RIO_DEBUG_PARAM, "LOBLK - JCL output blocks when not current\n");
  469. #endif
  470. if ( TtyP->termios->c_lflag & ISIG )
  471. rio_dprintk (RIO_DEBUG_PARAM, "Input character signal generating enabled\n");
  472. if ( TtyP->termios->c_lflag & ICANON )
  473. rio_dprintk (RIO_DEBUG_PARAM, "Canonical input: erase and kill enabled\n");
  474. if ( TtyP->termios->c_lflag & XCASE )
  475. rio_dprintk (RIO_DEBUG_PARAM, "Canonical upper/lower presentation\n");
  476. if ( TtyP->termios->c_lflag & ECHO )
  477. rio_dprintk (RIO_DEBUG_PARAM, "Enable input echo\n");
  478. if ( TtyP->termios->c_lflag & ECHOE )
  479. rio_dprintk (RIO_DEBUG_PARAM, "Enable echo erase\n");
  480. if ( TtyP->termios->c_lflag & ECHOK )
  481. rio_dprintk (RIO_DEBUG_PARAM, "Enable echo kill\n");
  482. if ( TtyP->termios->c_lflag & ECHONL )
  483. rio_dprintk (RIO_DEBUG_PARAM, "Enable echo newline\n");
  484. if ( TtyP->termios->c_lflag & NOFLSH )
  485. rio_dprintk (RIO_DEBUG_PARAM, "Disable flush after interrupt or quit\n");
  486. #ifdef TOSTOP
  487. if ( TtyP->termios->c_lflag & TOSTOP )
  488. rio_dprintk (RIO_DEBUG_PARAM, "Send SIGTTOU for background output\n");
  489. #endif
  490. #ifdef XCLUDE
  491. if ( TtyP->termios->c_lflag & XCLUDE )
  492. rio_dprintk (RIO_DEBUG_PARAM, "Exclusive use of this line\n");
  493. #endif
  494. if ( TtyP->termios->c_iflag & IUCLC )
  495. rio_dprintk (RIO_DEBUG_PARAM, "Map uppercase to lowercase on input\n");
  496. if ( TtyP->termios->c_oflag & OPOST )
  497. rio_dprintk (RIO_DEBUG_PARAM, "Enable output post-processing\n");
  498. if ( TtyP->termios->c_oflag & OLCUC )
  499. rio_dprintk (RIO_DEBUG_PARAM, "Map lowercase to uppercase on output\n");
  500. if ( TtyP->termios->c_oflag & ONOCR )
  501. rio_dprintk (RIO_DEBUG_PARAM, "No carriage return output at column 0\n");
  502. if ( TtyP->termios->c_oflag & ONLRET )
  503. rio_dprintk (RIO_DEBUG_PARAM, "Newline performs carriage return function\n");
  504. if ( TtyP->termios->c_oflag & OFILL )
  505. rio_dprintk (RIO_DEBUG_PARAM, "Use fill characters for delay\n");
  506. if ( TtyP->termios->c_oflag & OFDEL )
  507. rio_dprintk (RIO_DEBUG_PARAM, "Fill character is DEL\n");
  508. if ( TtyP->termios->c_oflag & NLDLY )
  509. rio_dprintk (RIO_DEBUG_PARAM, "Newline delay set\n");
  510. if ( TtyP->termios->c_oflag & CRDLY )
  511. rio_dprintk (RIO_DEBUG_PARAM, "Carriage return delay set\n");
  512. if ( TtyP->termios->c_oflag & TABDLY )
  513. rio_dprintk (RIO_DEBUG_PARAM, "Tab delay set\n");
  514. #if 0
  515. if ( TtyP->termios->c_oflag & BSDLY )
  516. rio_dprintk (RIO_DEBUG_PARAM, "Back-space delay set\n");
  517. if ( TtyP->termios->c_oflag & VTDLY )
  518. rio_dprintk (RIO_DEBUG_PARAM, "Vertical tab delay set\n");
  519. if ( TtyP->termios->c_oflag & FFDLY )
  520. rio_dprintk (RIO_DEBUG_PARAM, "Form-feed delay set\n");
  521. #endif
  522. /*
  523. ** These things are kind of useful in a later life!
  524. */
  525. PortP->Cor2Copy = Cor2;
  526. if ( PortP->State & RIO_DELETED ) {
  527. rio_spin_unlock_irqrestore( &PortP->portSem, flags);
  528. func_exit ();
  529. return RIO_FAIL;
  530. }
  531. /*
  532. ** Actually write the info into the packet to be sent
  533. */
  534. WBYTE(phb_param_ptr->Cmd, cmd);
  535. WBYTE(phb_param_ptr->Cor1, Cor1);
  536. WBYTE(phb_param_ptr->Cor2, Cor2);
  537. WBYTE(phb_param_ptr->Cor4, Cor4);
  538. WBYTE(phb_param_ptr->Cor5, Cor5);
  539. WBYTE(phb_param_ptr->TxXon, TxXon);
  540. WBYTE(phb_param_ptr->RxXon, RxXon);
  541. WBYTE(phb_param_ptr->TxXoff, TxXoff);
  542. WBYTE(phb_param_ptr->RxXoff, RxXoff);
  543. WBYTE(phb_param_ptr->LNext, LNext);
  544. WBYTE(phb_param_ptr->TxBaud, TxBaud);
  545. WBYTE(phb_param_ptr->RxBaud, RxBaud);
  546. /*
  547. ** Set the length/command field
  548. */
  549. WBYTE(PacketP->len , 12 | PKT_CMD_BIT);
  550. /*
  551. ** The packet is formed - now, whack it off
  552. ** to its final destination:
  553. */
  554. add_transmit(PortP);
  555. /*
  556. ** Count characters transmitted for port statistics reporting
  557. */
  558. if (PortP->statsGather)
  559. PortP->txchars += 12;
  560. rio_spin_unlock_irqrestore( &PortP->portSem, flags);
  561. rio_dprintk (RIO_DEBUG_PARAM, "add_transmit returned.\n");
  562. /*
  563. ** job done.
  564. */
  565. func_exit ();
  566. return RIO_SUCCESS;
  567. }
  568. /*
  569. ** We can add another packet to a transmit queue if the packet pointer pointed
  570. ** to by the TxAdd pointer has PKT_IN_USE clear in its address.
  571. */
  572. int
  573. can_add_transmit(PktP, PortP)
  574. PKT **PktP;
  575. struct Port *PortP;
  576. {
  577. register PKT *tp;
  578. *PktP = tp = (PKT *)RIO_PTR(PortP->Caddr,RWORD(*PortP->TxAdd));
  579. return !((uint)tp & PKT_IN_USE);
  580. }
  581. /*
  582. ** To add a packet to the queue, you set the PKT_IN_USE bit in the address,
  583. ** and then move the TxAdd pointer along one position to point to the next
  584. ** packet pointer. You must wrap the pointer from the end back to the start.
  585. */
  586. void
  587. add_transmit(PortP)
  588. struct Port *PortP;
  589. {
  590. if (RWORD(*PortP->TxAdd) & PKT_IN_USE) {
  591. rio_dprintk (RIO_DEBUG_PARAM, "add_transmit: Packet has been stolen!");
  592. }
  593. WWORD( *(ushort *)PortP->TxAdd, RWORD(*PortP->TxAdd) | PKT_IN_USE);
  594. PortP->TxAdd = (PortP->TxAdd == PortP->TxEnd) ? PortP->TxStart :
  595. PortP->TxAdd + 1;
  596. WWORD( PortP->PhbP->tx_add , RIO_OFF(PortP->Caddr,PortP->TxAdd) );
  597. }
  598. /****************************************
  599. * Put a packet onto the end of the
  600. * free list
  601. ****************************************/
  602. void
  603. put_free_end(HostP, PktP)
  604. struct Host *HostP;
  605. PKT *PktP;
  606. {
  607. FREE_LIST *tmp_pointer;
  608. ushort old_end, new_end;
  609. unsigned long flags;
  610. rio_spin_lock_irqsave(&HostP->HostLock, flags);
  611. /*************************************************
  612. * Put a packet back onto the back of the free list
  613. *
  614. ************************************************/
  615. rio_dprintk (RIO_DEBUG_PFE, "put_free_end(PktP=%x)\n",(int)PktP);
  616. if ((old_end=RWORD(HostP->ParmMapP->free_list_end)) != TPNULL) {
  617. new_end = RIO_OFF(HostP->Caddr,PktP);
  618. tmp_pointer = (FREE_LIST *)RIO_PTR(HostP->Caddr,old_end);
  619. WWORD(tmp_pointer->next , new_end );
  620. WWORD(((FREE_LIST *)PktP)->prev , old_end);
  621. WWORD(((FREE_LIST *)PktP)->next , TPNULL);
  622. WWORD(HostP->ParmMapP->free_list_end, new_end);
  623. }
  624. else { /* First packet on the free list this should never happen! */
  625. rio_dprintk (RIO_DEBUG_PFE, "put_free_end(): This should never happen\n");
  626. WWORD(HostP->ParmMapP->free_list_end , RIO_OFF(HostP->Caddr,PktP));
  627. tmp_pointer = (FREE_LIST *)PktP;
  628. WWORD(tmp_pointer->prev , TPNULL);
  629. WWORD(tmp_pointer->next , TPNULL);
  630. }
  631. rio_dprintk (RIO_DEBUG_CMD, "Before unlock: %p\n", &HostP->HostLock);
  632. rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
  633. }
  634. /*
  635. ** can_remove_receive(PktP,P) returns non-zero if PKT_IN_USE is set
  636. ** for the next packet on the queue. It will also set PktP to point to the
  637. ** relevant packet, [having cleared the PKT_IN_USE bit]. If PKT_IN_USE is clear,
  638. ** then can_remove_receive() returns 0.
  639. */
  640. int
  641. can_remove_receive(PktP, PortP)
  642. PKT **PktP;
  643. struct Port *PortP;
  644. {
  645. if ( RWORD(*PortP->RxRemove) & PKT_IN_USE) {
  646. *PktP = (PKT *)RIO_PTR(PortP->Caddr,
  647. RWORD(*PortP->RxRemove) & ~PKT_IN_USE);
  648. return 1;
  649. }
  650. return 0;
  651. }
  652. /*
  653. ** To remove a packet from the receive queue you clear its PKT_IN_USE bit,
  654. ** and then bump the pointers. Once the pointers get to the end, they must
  655. ** be wrapped back to the start.
  656. */
  657. void
  658. remove_receive(PortP)
  659. struct Port *PortP;
  660. {
  661. WWORD( *PortP->RxRemove, RWORD(*PortP->RxRemove) & ~PKT_IN_USE );
  662. PortP->RxRemove = (PortP->RxRemove == PortP->RxEnd) ? PortP->RxStart :
  663. PortP->RxRemove + 1;
  664. WWORD( PortP->PhbP->rx_remove , RIO_OFF(PortP->Caddr, PortP->RxRemove) );
  665. }