rioparam.c 20 KB

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