rioparam.c 20 KB

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