rioparam.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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 RIOParam(struct Port *PortP, int cmd, int Modem, int SleepFlag)
  150. {
  151. struct tty_struct *TtyP;
  152. int retval;
  153. struct phb_param *phb_param_ptr;
  154. PKT *PacketP;
  155. int res;
  156. u8 Cor1 = 0, Cor2 = 0, Cor4 = 0, Cor5 = 0;
  157. u8 TxXon = 0, TxXoff = 0, RxXon = 0, RxXoff = 0;
  158. u8 LNext = 0, TxBaud = 0, RxBaud = 0;
  159. int retries = 0xff;
  160. unsigned long flags;
  161. func_enter();
  162. TtyP = PortP->gs.tty;
  163. rio_dprintk(RIO_DEBUG_PARAM, "RIOParam: Port:%d cmd:%d Modem:%d SleepFlag:%d Mapped: %d, tty=%p\n", PortP->PortNum, cmd, Modem, SleepFlag, PortP->Mapped, TtyP);
  164. if (!TtyP) {
  165. rio_dprintk(RIO_DEBUG_PARAM, "Can't call rioparam with null tty.\n");
  166. func_exit();
  167. return RIO_FAIL;
  168. }
  169. rio_spin_lock_irqsave(&PortP->portSem, flags);
  170. if (cmd == OPEN) {
  171. /*
  172. ** If the port is set to store or lock the parameters, and it is
  173. ** paramed with OPEN, we want to restore the saved port termio, but
  174. ** only if StoredTermio has been saved, i.e. NOT 1st open after reboot.
  175. */
  176. }
  177. /*
  178. ** wait for space
  179. */
  180. while (!(res = can_add_transmit(&PacketP, PortP)) || (PortP->InUse != NOT_INUSE)) {
  181. if (retries-- <= 0) {
  182. break;
  183. }
  184. if (PortP->InUse != NOT_INUSE) {
  185. rio_dprintk(RIO_DEBUG_PARAM, "Port IN_USE for pre-emptive command\n");
  186. }
  187. if (!res) {
  188. rio_dprintk(RIO_DEBUG_PARAM, "Port has no space on transmit queue\n");
  189. }
  190. if (SleepFlag != OK_TO_SLEEP) {
  191. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  192. func_exit();
  193. return RIO_FAIL;
  194. }
  195. rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit\n");
  196. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  197. retval = RIODelay(PortP, HUNDRED_MS);
  198. rio_spin_lock_irqsave(&PortP->portSem, flags);
  199. if (retval == RIO_FAIL) {
  200. rio_dprintk(RIO_DEBUG_PARAM, "wait for can_add_transmit broken by signal\n");
  201. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  202. func_exit();
  203. return -EINTR;
  204. }
  205. if (PortP->State & RIO_DELETED) {
  206. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  207. func_exit();
  208. return RIO_SUCCESS;
  209. }
  210. }
  211. if (!res) {
  212. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  213. func_exit();
  214. return RIO_FAIL;
  215. }
  216. rio_dprintk(RIO_DEBUG_PARAM, "can_add_transmit() returns %x\n", res);
  217. rio_dprintk(RIO_DEBUG_PARAM, "Packet is 0x%p\n", PacketP);
  218. phb_param_ptr = (struct phb_param *) PacketP->data;
  219. switch (TtyP->termios->c_cflag & CSIZE) {
  220. case CS5:
  221. {
  222. rio_dprintk(RIO_DEBUG_PARAM, "5 bit data\n");
  223. Cor1 |= COR1_5BITS;
  224. break;
  225. }
  226. case CS6:
  227. {
  228. rio_dprintk(RIO_DEBUG_PARAM, "6 bit data\n");
  229. Cor1 |= COR1_6BITS;
  230. break;
  231. }
  232. case CS7:
  233. {
  234. rio_dprintk(RIO_DEBUG_PARAM, "7 bit data\n");
  235. Cor1 |= COR1_7BITS;
  236. break;
  237. }
  238. case CS8:
  239. {
  240. rio_dprintk(RIO_DEBUG_PARAM, "8 bit data\n");
  241. Cor1 |= COR1_8BITS;
  242. break;
  243. }
  244. }
  245. if (TtyP->termios->c_cflag & CSTOPB) {
  246. rio_dprintk(RIO_DEBUG_PARAM, "2 stop bits\n");
  247. Cor1 |= COR1_2STOP;
  248. } else {
  249. rio_dprintk(RIO_DEBUG_PARAM, "1 stop bit\n");
  250. Cor1 |= COR1_1STOP;
  251. }
  252. if (TtyP->termios->c_cflag & PARENB) {
  253. rio_dprintk(RIO_DEBUG_PARAM, "Enable parity\n");
  254. Cor1 |= COR1_NORMAL;
  255. } else {
  256. rio_dprintk(RIO_DEBUG_PARAM, "Disable parity\n");
  257. Cor1 |= COR1_NOP;
  258. }
  259. if (TtyP->termios->c_cflag & PARODD) {
  260. rio_dprintk(RIO_DEBUG_PARAM, "Odd parity\n");
  261. Cor1 |= COR1_ODD;
  262. } else {
  263. rio_dprintk(RIO_DEBUG_PARAM, "Even parity\n");
  264. Cor1 |= COR1_EVEN;
  265. }
  266. /*
  267. ** COR 2
  268. */
  269. if (TtyP->termios->c_iflag & IXON) {
  270. rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop output control\n");
  271. Cor2 |= COR2_IXON;
  272. } else {
  273. if (PortP->Config & RIO_IXON) {
  274. rio_dprintk(RIO_DEBUG_PARAM, "Force enable start/stop output control\n");
  275. Cor2 |= COR2_IXON;
  276. } else
  277. rio_dprintk(RIO_DEBUG_PARAM, "IXON has been disabled.\n");
  278. }
  279. if (TtyP->termios->c_iflag & IXANY) {
  280. if (PortP->Config & RIO_IXANY) {
  281. rio_dprintk(RIO_DEBUG_PARAM, "Enable any key to restart output\n");
  282. Cor2 |= COR2_IXANY;
  283. } else
  284. rio_dprintk(RIO_DEBUG_PARAM, "IXANY has been disabled due to sanity reasons.\n");
  285. }
  286. if (TtyP->termios->c_iflag & IXOFF) {
  287. rio_dprintk(RIO_DEBUG_PARAM, "Enable start/stop input control 2\n");
  288. Cor2 |= COR2_IXOFF;
  289. }
  290. if (TtyP->termios->c_cflag & HUPCL) {
  291. rio_dprintk(RIO_DEBUG_PARAM, "Hangup on last close\n");
  292. Cor2 |= COR2_HUPCL;
  293. }
  294. if (C_CRTSCTS(TtyP)) {
  295. rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control enabled\n");
  296. Cor2 |= COR2_CTSFLOW;
  297. Cor2 |= COR2_RTSFLOW;
  298. } else {
  299. rio_dprintk(RIO_DEBUG_PARAM, "Rx hardware flow control disabled\n");
  300. Cor2 &= ~COR2_CTSFLOW;
  301. Cor2 &= ~COR2_RTSFLOW;
  302. }
  303. if (TtyP->termios->c_cflag & CLOCAL) {
  304. rio_dprintk(RIO_DEBUG_PARAM, "Local line\n");
  305. } else {
  306. rio_dprintk(RIO_DEBUG_PARAM, "Possible Modem line\n");
  307. }
  308. /*
  309. ** COR 4 (there is no COR 3)
  310. */
  311. if (TtyP->termios->c_iflag & IGNBRK) {
  312. rio_dprintk(RIO_DEBUG_PARAM, "Ignore break condition\n");
  313. Cor4 |= COR4_IGNBRK;
  314. }
  315. if (!(TtyP->termios->c_iflag & BRKINT)) {
  316. rio_dprintk(RIO_DEBUG_PARAM, "Break generates NULL condition\n");
  317. Cor4 |= COR4_NBRKINT;
  318. } else {
  319. rio_dprintk(RIO_DEBUG_PARAM, "Interrupt on break condition\n");
  320. }
  321. if (TtyP->termios->c_iflag & INLCR) {
  322. rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage return on input\n");
  323. Cor4 |= COR4_INLCR;
  324. }
  325. if (TtyP->termios->c_iflag & IGNCR) {
  326. rio_dprintk(RIO_DEBUG_PARAM, "Ignore carriage return on input\n");
  327. Cor4 |= COR4_IGNCR;
  328. }
  329. if (TtyP->termios->c_iflag & ICRNL) {
  330. rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on input\n");
  331. Cor4 |= COR4_ICRNL;
  332. }
  333. if (TtyP->termios->c_iflag & IGNPAR) {
  334. rio_dprintk(RIO_DEBUG_PARAM, "Ignore characters with parity errors\n");
  335. Cor4 |= COR4_IGNPAR;
  336. }
  337. if (TtyP->termios->c_iflag & PARMRK) {
  338. rio_dprintk(RIO_DEBUG_PARAM, "Mark parity errors\n");
  339. Cor4 |= COR4_PARMRK;
  340. }
  341. /*
  342. ** Set the RAISEMOD flag to ensure that the modem lines are raised
  343. ** on reception of a config packet.
  344. ** The download code handles the zero baud condition.
  345. */
  346. Cor4 |= COR4_RAISEMOD;
  347. /*
  348. ** COR 5
  349. */
  350. Cor5 = COR5_CMOE;
  351. /*
  352. ** Set to monitor tbusy/tstop (or not).
  353. */
  354. if (PortP->MonitorTstate)
  355. Cor5 |= COR5_TSTATE_ON;
  356. else
  357. Cor5 |= COR5_TSTATE_OFF;
  358. /*
  359. ** Could set LNE here if you wanted LNext processing. SVR4 will use it.
  360. */
  361. if (TtyP->termios->c_iflag & ISTRIP) {
  362. rio_dprintk(RIO_DEBUG_PARAM, "Strip input characters\n");
  363. if (!(PortP->State & RIO_TRIAD_MODE)) {
  364. Cor5 |= COR5_ISTRIP;
  365. }
  366. }
  367. if (TtyP->termios->c_oflag & ONLCR) {
  368. rio_dprintk(RIO_DEBUG_PARAM, "Map newline to carriage-return, newline on output\n");
  369. if (PortP->CookMode == COOK_MEDIUM)
  370. Cor5 |= COR5_ONLCR;
  371. }
  372. if (TtyP->termios->c_oflag & OCRNL) {
  373. rio_dprintk(RIO_DEBUG_PARAM, "Map carriage return to newline on output\n");
  374. if (PortP->CookMode == COOK_MEDIUM)
  375. Cor5 |= COR5_OCRNL;
  376. }
  377. if ((TtyP->termios->c_oflag & TABDLY) == TAB3) {
  378. rio_dprintk(RIO_DEBUG_PARAM, "Tab delay 3 set\n");
  379. if (PortP->CookMode == COOK_MEDIUM)
  380. Cor5 |= COR5_TAB3;
  381. }
  382. /*
  383. ** Flow control bytes.
  384. */
  385. TxXon = TtyP->termios->c_cc[VSTART];
  386. TxXoff = TtyP->termios->c_cc[VSTOP];
  387. RxXon = TtyP->termios->c_cc[VSTART];
  388. RxXoff = TtyP->termios->c_cc[VSTOP];
  389. /*
  390. ** LNEXT byte
  391. */
  392. LNext = 0;
  393. /*
  394. ** Baud rate bytes
  395. */
  396. rio_dprintk(RIO_DEBUG_PARAM, "Mapping of rx/tx baud %x (%x)\n", TtyP->termios->c_cflag, CBAUD);
  397. switch (TtyP->termios->c_cflag & CBAUD) {
  398. #define e(b) case B ## b : RxBaud = TxBaud = RIO_B ## b ;break
  399. e(50);
  400. e(75);
  401. e(110);
  402. e(134);
  403. e(150);
  404. e(200);
  405. e(300);
  406. e(600);
  407. e(1200);
  408. e(1800);
  409. e(2400);
  410. e(4800);
  411. e(9600);
  412. e(19200);
  413. e(38400);
  414. e(57600);
  415. e(115200); /* e(230400);e(460800); e(921600); */
  416. }
  417. rio_dprintk(RIO_DEBUG_PARAM, "tx baud 0x%x, rx baud 0x%x\n", TxBaud, RxBaud);
  418. /*
  419. ** Leftovers
  420. */
  421. if (TtyP->termios->c_cflag & CREAD)
  422. rio_dprintk(RIO_DEBUG_PARAM, "Enable receiver\n");
  423. #ifdef RCV1EN
  424. if (TtyP->termios->c_cflag & RCV1EN)
  425. rio_dprintk(RIO_DEBUG_PARAM, "RCV1EN (?)\n");
  426. #endif
  427. #ifdef XMT1EN
  428. if (TtyP->termios->c_cflag & XMT1EN)
  429. rio_dprintk(RIO_DEBUG_PARAM, "XMT1EN (?)\n");
  430. #endif
  431. if (TtyP->termios->c_lflag & ISIG)
  432. rio_dprintk(RIO_DEBUG_PARAM, "Input character signal generating enabled\n");
  433. if (TtyP->termios->c_lflag & ICANON)
  434. rio_dprintk(RIO_DEBUG_PARAM, "Canonical input: erase and kill enabled\n");
  435. if (TtyP->termios->c_lflag & XCASE)
  436. rio_dprintk(RIO_DEBUG_PARAM, "Canonical upper/lower presentation\n");
  437. if (TtyP->termios->c_lflag & ECHO)
  438. rio_dprintk(RIO_DEBUG_PARAM, "Enable input echo\n");
  439. if (TtyP->termios->c_lflag & ECHOE)
  440. rio_dprintk(RIO_DEBUG_PARAM, "Enable echo erase\n");
  441. if (TtyP->termios->c_lflag & ECHOK)
  442. rio_dprintk(RIO_DEBUG_PARAM, "Enable echo kill\n");
  443. if (TtyP->termios->c_lflag & ECHONL)
  444. rio_dprintk(RIO_DEBUG_PARAM, "Enable echo newline\n");
  445. if (TtyP->termios->c_lflag & NOFLSH)
  446. rio_dprintk(RIO_DEBUG_PARAM, "Disable flush after interrupt or quit\n");
  447. #ifdef TOSTOP
  448. if (TtyP->termios->c_lflag & TOSTOP)
  449. rio_dprintk(RIO_DEBUG_PARAM, "Send SIGTTOU for background output\n");
  450. #endif
  451. #ifdef XCLUDE
  452. if (TtyP->termios->c_lflag & XCLUDE)
  453. rio_dprintk(RIO_DEBUG_PARAM, "Exclusive use of this line\n");
  454. #endif
  455. if (TtyP->termios->c_iflag & IUCLC)
  456. rio_dprintk(RIO_DEBUG_PARAM, "Map uppercase to lowercase on input\n");
  457. if (TtyP->termios->c_oflag & OPOST)
  458. rio_dprintk(RIO_DEBUG_PARAM, "Enable output post-processing\n");
  459. if (TtyP->termios->c_oflag & OLCUC)
  460. rio_dprintk(RIO_DEBUG_PARAM, "Map lowercase to uppercase on output\n");
  461. if (TtyP->termios->c_oflag & ONOCR)
  462. rio_dprintk(RIO_DEBUG_PARAM, "No carriage return output at column 0\n");
  463. if (TtyP->termios->c_oflag & ONLRET)
  464. rio_dprintk(RIO_DEBUG_PARAM, "Newline performs carriage return function\n");
  465. if (TtyP->termios->c_oflag & OFILL)
  466. rio_dprintk(RIO_DEBUG_PARAM, "Use fill characters for delay\n");
  467. if (TtyP->termios->c_oflag & OFDEL)
  468. rio_dprintk(RIO_DEBUG_PARAM, "Fill character is DEL\n");
  469. if (TtyP->termios->c_oflag & NLDLY)
  470. rio_dprintk(RIO_DEBUG_PARAM, "Newline delay set\n");
  471. if (TtyP->termios->c_oflag & CRDLY)
  472. rio_dprintk(RIO_DEBUG_PARAM, "Carriage return delay set\n");
  473. if (TtyP->termios->c_oflag & TABDLY)
  474. rio_dprintk(RIO_DEBUG_PARAM, "Tab delay set\n");
  475. /*
  476. ** These things are kind of useful in a later life!
  477. */
  478. PortP->Cor2Copy = Cor2;
  479. if (PortP->State & RIO_DELETED) {
  480. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  481. func_exit();
  482. return RIO_FAIL;
  483. }
  484. /*
  485. ** Actually write the info into the packet to be sent
  486. */
  487. writeb(cmd, &phb_param_ptr->Cmd);
  488. writeb(Cor1, &phb_param_ptr->Cor1);
  489. writeb(Cor2, &phb_param_ptr->Cor2);
  490. writeb(Cor4, &phb_param_ptr->Cor4);
  491. writeb(Cor5, &phb_param_ptr->Cor5);
  492. writeb(TxXon, &phb_param_ptr->TxXon);
  493. writeb(RxXon, &phb_param_ptr->RxXon);
  494. writeb(TxXoff, &phb_param_ptr->TxXoff);
  495. writeb(RxXoff, &phb_param_ptr->RxXoff);
  496. writeb(LNext, &phb_param_ptr->LNext);
  497. writeb(TxBaud, &phb_param_ptr->TxBaud);
  498. writeb(RxBaud, &phb_param_ptr->RxBaud);
  499. /*
  500. ** Set the length/command field
  501. */
  502. writeb(12 | PKT_CMD_BIT, &PacketP->len);
  503. /*
  504. ** The packet is formed - now, whack it off
  505. ** to its final destination:
  506. */
  507. add_transmit(PortP);
  508. /*
  509. ** Count characters transmitted for port statistics reporting
  510. */
  511. if (PortP->statsGather)
  512. PortP->txchars += 12;
  513. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  514. rio_dprintk(RIO_DEBUG_PARAM, "add_transmit returned.\n");
  515. /*
  516. ** job done.
  517. */
  518. func_exit();
  519. return RIO_SUCCESS;
  520. }
  521. /*
  522. ** We can add another packet to a transmit queue if the packet pointer pointed
  523. ** to by the TxAdd pointer has PKT_IN_USE clear in its address.
  524. */
  525. int can_add_transmit(PKT **PktP, struct Port *PortP)
  526. {
  527. PKT *tp;
  528. *PktP = tp = (PKT *) RIO_PTR(PortP->Caddr, readw(PortP->TxAdd));
  529. return !((unsigned long) tp & PKT_IN_USE);
  530. }
  531. /*
  532. ** To add a packet to the queue, you set the PKT_IN_USE bit in the address,
  533. ** and then move the TxAdd pointer along one position to point to the next
  534. ** packet pointer. You must wrap the pointer from the end back to the start.
  535. */
  536. void add_transmit(struct Port *PortP)
  537. {
  538. if (readw(PortP->TxAdd) & PKT_IN_USE) {
  539. rio_dprintk(RIO_DEBUG_PARAM, "add_transmit: Packet has been stolen!");
  540. }
  541. writew(readw(PortP->TxAdd) | PKT_IN_USE, PortP->TxAdd);
  542. PortP->TxAdd = (PortP->TxAdd == PortP->TxEnd) ? PortP->TxStart : PortP->TxAdd + 1;
  543. writew(RIO_OFF(PortP->Caddr, PortP->TxAdd), &PortP->PhbP->tx_add);
  544. }
  545. /****************************************
  546. * Put a packet onto the end of the
  547. * free list
  548. ****************************************/
  549. void put_free_end(struct Host *HostP, PKT *PktP)
  550. {
  551. FREE_LIST *tmp_pointer;
  552. ushort old_end, new_end;
  553. unsigned long flags;
  554. rio_spin_lock_irqsave(&HostP->HostLock, flags);
  555. /*************************************************
  556. * Put a packet back onto the back of the free list
  557. *
  558. ************************************************/
  559. rio_dprintk(RIO_DEBUG_PFE, "put_free_end(PktP=%p)\n", PktP);
  560. if ((old_end = readw(&HostP->ParmMapP->free_list_end)) != TPNULL) {
  561. new_end = RIO_OFF(HostP->Caddr, PktP);
  562. tmp_pointer = (FREE_LIST *) RIO_PTR(HostP->Caddr, old_end);
  563. writew(new_end, &tmp_pointer->next);
  564. writew(old_end, &((FREE_LIST *) PktP)->prev);
  565. writew(TPNULL, &((FREE_LIST *) PktP)->next);
  566. writew(new_end, &HostP->ParmMapP->free_list_end);
  567. } else { /* First packet on the free list this should never happen! */
  568. rio_dprintk(RIO_DEBUG_PFE, "put_free_end(): This should never happen\n");
  569. writew(RIO_OFF(HostP->Caddr, PktP), &HostP->ParmMapP->free_list_end);
  570. tmp_pointer = (FREE_LIST *) PktP;
  571. writew(TPNULL, &tmp_pointer->prev);
  572. writew(TPNULL, &tmp_pointer->next);
  573. }
  574. rio_dprintk(RIO_DEBUG_CMD, "Before unlock: %p\n", &HostP->HostLock);
  575. rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
  576. }
  577. /*
  578. ** can_remove_receive(PktP,P) returns non-zero if PKT_IN_USE is set
  579. ** for the next packet on the queue. It will also set PktP to point to the
  580. ** relevant packet, [having cleared the PKT_IN_USE bit]. If PKT_IN_USE is clear,
  581. ** then can_remove_receive() returns 0.
  582. */
  583. int can_remove_receive(PKT **PktP, struct Port *PortP)
  584. {
  585. if (readw(PortP->RxRemove) & PKT_IN_USE) {
  586. *PktP = (PKT *) RIO_PTR(PortP->Caddr, readw(PortP->RxRemove) & ~PKT_IN_USE);
  587. return 1;
  588. }
  589. return 0;
  590. }
  591. /*
  592. ** To remove a packet from the receive queue you clear its PKT_IN_USE bit,
  593. ** and then bump the pointers. Once the pointers get to the end, they must
  594. ** be wrapped back to the start.
  595. */
  596. void remove_receive(struct Port *PortP)
  597. {
  598. writew(readw(PortP->RxRemove) & ~PKT_IN_USE, PortP->RxRemove);
  599. PortP->RxRemove = (PortP->RxRemove == PortP->RxEnd) ? PortP->RxStart : PortP->RxRemove + 1;
  600. writew(RIO_OFF(PortP->Caddr, PortP->RxRemove), &PortP->PhbP->rx_remove);
  601. }