PageRenderTime 103ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/char/rio/rioctrl.c

https://bitbucket.org/evzijst/gittest
C | 1869 lines | 1409 code | 161 blank | 299 comment | 257 complexity | 55f207b183705891be741d077c887f23 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0
  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 : rioctrl.c
  24. ** SID : 1.3
  25. ** Last Modified : 11/6/98 10:33:42
  26. ** Retrieved : 11/6/98 10:33:49
  27. **
  28. ** ident @(#)rioctrl.c 1.3
  29. **
  30. ** -----------------------------------------------------------------------------
  31. */
  32. #ifdef SCCS_LABELS
  33. static char *_rioctrl_c_sccs_ = "@(#)rioctrl.c 1.3";
  34. #endif
  35. #include <linux/module.h>
  36. #include <linux/slab.h>
  37. #include <linux/errno.h>
  38. #include <asm/io.h>
  39. #include <asm/system.h>
  40. #include <asm/string.h>
  41. #include <asm/semaphore.h>
  42. #include <asm/uaccess.h>
  43. #include <linux/termios.h>
  44. #include <linux/serial.h>
  45. #include <linux/generic_serial.h>
  46. #include "linux_compat.h"
  47. #include "rio_linux.h"
  48. #include "typdef.h"
  49. #include "pkt.h"
  50. #include "daemon.h"
  51. #include "rio.h"
  52. #include "riospace.h"
  53. #include "top.h"
  54. #include "cmdpkt.h"
  55. #include "map.h"
  56. #include "riotypes.h"
  57. #include "rup.h"
  58. #include "port.h"
  59. #include "riodrvr.h"
  60. #include "rioinfo.h"
  61. #include "func.h"
  62. #include "errors.h"
  63. #include "pci.h"
  64. #include "parmmap.h"
  65. #include "unixrup.h"
  66. #include "board.h"
  67. #include "host.h"
  68. #include "error.h"
  69. #include "phb.h"
  70. #include "link.h"
  71. #include "cmdblk.h"
  72. #include "route.h"
  73. #include "control.h"
  74. #include "cirrus.h"
  75. #include "rioioctl.h"
  76. static struct LpbReq LpbReq;
  77. static struct RupReq RupReq;
  78. static struct PortReq PortReq;
  79. static struct HostReq HostReq;
  80. static struct HostDpRam HostDpRam;
  81. static struct DebugCtrl DebugCtrl;
  82. static struct Map MapEnt;
  83. static struct PortSetup PortSetup;
  84. static struct DownLoad DownLoad;
  85. static struct SendPack SendPack;
  86. /* static struct StreamInfo StreamInfo; */
  87. /* static char modemtable[RIO_PORTS]; */
  88. static struct SpecialRupCmd SpecialRupCmd;
  89. static struct PortParams PortParams;
  90. static struct portStats portStats;
  91. static struct SubCmdStruct {
  92. ushort Host;
  93. ushort Rup;
  94. ushort Port;
  95. ushort Addr;
  96. } SubCmd;
  97. struct PortTty {
  98. uint port;
  99. struct ttystatics Tty;
  100. };
  101. static struct PortTty PortTty;
  102. typedef struct ttystatics TERMIO;
  103. /*
  104. ** This table is used when the config.rio downloads bin code to the
  105. ** driver. We index the table using the product code, 0-F, and call
  106. ** the function pointed to by the entry, passing the information
  107. ** about the boot.
  108. ** The RIOBootCodeUNKNOWN entry is there to politely tell the calling
  109. ** process to bog off.
  110. */
  111. static int
  112. (*RIOBootTable[MAX_PRODUCT])(struct rio_info *, struct DownLoad *) =
  113. {
  114. /* 0 */ RIOBootCodeHOST, /* Host Card */
  115. /* 1 */ RIOBootCodeRTA, /* RTA */
  116. };
  117. #define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
  118. int copyin (int arg, caddr_t dp, int siz)
  119. {
  120. int rv;
  121. rio_dprintk (RIO_DEBUG_CTRL, "Copying %d bytes from user %p to %p.\n", siz, (void *)arg, dp);
  122. rv = copy_from_user (dp, (void *)arg, siz);
  123. if (rv) return COPYFAIL;
  124. else return rv;
  125. }
  126. static int copyout (caddr_t dp, int arg, int siz)
  127. {
  128. int rv;
  129. rio_dprintk (RIO_DEBUG_CTRL, "Copying %d bytes to user %p from %p.\n", siz, (void *)arg, dp);
  130. rv = copy_to_user ((void *)arg, dp, siz);
  131. if (rv) return COPYFAIL;
  132. else return rv;
  133. }
  134. int
  135. riocontrol(p, dev, cmd, arg, su)
  136. struct rio_info * p;
  137. dev_t dev;
  138. int cmd;
  139. caddr_t arg;
  140. int su;
  141. {
  142. uint Host; /* leave me unsigned! */
  143. uint port; /* and me! */
  144. struct Host *HostP;
  145. ushort loop;
  146. int Entry;
  147. struct Port *PortP;
  148. PKT *PacketP;
  149. int retval = 0;
  150. unsigned long flags;
  151. func_enter ();
  152. /* Confuse the compiler to think that we've initialized these */
  153. Host=0;
  154. PortP = NULL;
  155. rio_dprintk (RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: 0x%x\n", cmd, (int)arg);
  156. switch (cmd) {
  157. /*
  158. ** RIO_SET_TIMER
  159. **
  160. ** Change the value of the host card interrupt timer.
  161. ** If the host card number is -1 then all host cards are changed
  162. ** otherwise just the specified host card will be changed.
  163. */
  164. case RIO_SET_TIMER:
  165. rio_dprintk (RIO_DEBUG_CTRL, "RIO_SET_TIMER to %dms\n", (uint)arg);
  166. {
  167. int host, value;
  168. host = (uint)arg >> 16;
  169. value = (uint)arg & 0x0000ffff;
  170. if (host == -1) {
  171. for (host = 0; host < p->RIONumHosts; host++) {
  172. if (p->RIOHosts[host].Flags == RC_RUNNING) {
  173. WWORD(p->RIOHosts[host].ParmMapP->timer , value);
  174. }
  175. }
  176. } else if (host >= p->RIONumHosts) {
  177. return -EINVAL;
  178. } else {
  179. if ( p->RIOHosts[host].Flags == RC_RUNNING ) {
  180. WWORD(p->RIOHosts[host].ParmMapP->timer , value);
  181. }
  182. }
  183. }
  184. return 0;
  185. case RIO_IDENTIFY_DRIVER:
  186. /*
  187. ** 15.10.1998 ARG - ESIL 0760 part fix
  188. ** Added driver ident string output.
  189. **
  190. #ifndef __THIS_RELEASE__
  191. #warning Driver Version string not defined !
  192. #endif
  193. cprintf("%s %s %s %s\n",
  194. RIO_DRV_STR,
  195. __THIS_RELEASE__,
  196. __DATE__, __TIME__ );
  197. return 0;
  198. case RIO_DISPLAY_HOST_CFG:
  199. **
  200. ** 15.10.1998 ARG - ESIL 0760 part fix
  201. ** Added driver host card ident string output.
  202. **
  203. ** Note that the only types currently supported
  204. ** are ISA and PCI. Also this driver does not
  205. ** (yet) distinguish between the Old PCI card
  206. ** and the Jet PCI card. In fact I think this
  207. ** driver only supports JET PCI !
  208. **
  209. for (Host = 0; Host < p->RIONumHosts; Host++)
  210. {
  211. HostP = &(p->RIOHosts[Host]);
  212. switch ( HostP->Type )
  213. {
  214. case RIO_AT :
  215. strcpy( host_type, RIO_AT_HOST_STR );
  216. break;
  217. case RIO_PCI :
  218. strcpy( host_type, RIO_PCI_HOST_STR );
  219. break;
  220. default :
  221. strcpy( host_type, "Unknown" );
  222. break;
  223. }
  224. cprintf(
  225. "RIO Host %d - Type:%s Addr:%X IRQ:%d\n",
  226. Host, host_type,
  227. (uint)HostP->PaddrP,
  228. (int)HostP->Ivec - 32 );
  229. }
  230. return 0;
  231. **
  232. */
  233. case RIO_FOAD_RTA:
  234. rio_dprintk (RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
  235. return RIOCommandRta(p, (uint)arg, RIOFoadRta);
  236. case RIO_ZOMBIE_RTA:
  237. rio_dprintk (RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
  238. return RIOCommandRta(p, (uint)arg, RIOZombieRta);
  239. case RIO_IDENTIFY_RTA:
  240. rio_dprintk (RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
  241. return RIOIdentifyRta(p, arg);
  242. case RIO_KILL_NEIGHBOUR:
  243. rio_dprintk (RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n");
  244. return RIOKillNeighbour(p, arg);
  245. case SPECIAL_RUP_CMD:
  246. {
  247. struct CmdBlk *CmdBlkP;
  248. rio_dprintk (RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
  249. if (copyin((int)arg, (caddr_t)&SpecialRupCmd,
  250. sizeof(SpecialRupCmd)) == COPYFAIL ) {
  251. rio_dprintk (RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
  252. p->RIOError.Error = COPYIN_FAILED;
  253. return -EFAULT;
  254. }
  255. CmdBlkP = RIOGetCmdBlk();
  256. if ( !CmdBlkP ) {
  257. rio_dprintk (RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD GetCmdBlk failed\n");
  258. return -ENXIO;
  259. }
  260. CmdBlkP->Packet = SpecialRupCmd.Packet;
  261. if ( SpecialRupCmd.Host >= p->RIONumHosts )
  262. SpecialRupCmd.Host = 0;
  263. rio_dprintk (RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n",
  264. SpecialRupCmd.Host, SpecialRupCmd.RupNum);
  265. if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host],
  266. SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
  267. cprintf("FAILED TO QUEUE SPECIAL RUP COMMAND\n");
  268. }
  269. return 0;
  270. }
  271. case RIO_DEBUG_MEM:
  272. #ifdef DEBUG_MEM_SUPPORT
  273. RIO_DEBUG_CTRL, if (su)
  274. return rio_RIODebugMemory(RIO_DEBUG_CTRL, arg);
  275. else
  276. #endif
  277. return -EPERM;
  278. case RIO_ALL_MODEM:
  279. rio_dprintk (RIO_DEBUG_CTRL, "RIO_ALL_MODEM\n");
  280. p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
  281. return -EINVAL;
  282. case RIO_GET_TABLE:
  283. /*
  284. ** Read the routing table from the device driver to user space
  285. */
  286. rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_TABLE\n");
  287. if ((retval = RIOApel(p)) != 0)
  288. return retval;
  289. if (copyout((caddr_t)p->RIOConnectTable, (int)arg,
  290. TOTAL_MAP_ENTRIES*sizeof(struct Map)) == COPYFAIL) {
  291. rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
  292. p->RIOError.Error = COPYOUT_FAILED;
  293. return -EFAULT;
  294. }
  295. {
  296. int entry;
  297. rio_dprintk (RIO_DEBUG_CTRL, "*****\nMAP ENTRIES\n");
  298. for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
  299. {
  300. if ((p->RIOConnectTable[entry].ID == 0) &&
  301. (p->RIOConnectTable[entry].HostUniqueNum == 0) &&
  302. (p->RIOConnectTable[entry].RtaUniqueNum == 0)) continue;
  303. rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum );
  304. rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum );
  305. rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID );
  306. rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 );
  307. rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Flags = 0x%x\n", entry, (int)p->RIOConnectTable[entry].Flags );
  308. rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.SysPort = 0x%x\n", entry, (int)p->RIOConnectTable[entry].SysPort );
  309. rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit );
  310. rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link );
  311. rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit );
  312. rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link );
  313. rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit );
  314. rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link );
  315. rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit );
  316. rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link );
  317. rio_dprintk (RIO_DEBUG_CTRL, "Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name );
  318. }
  319. rio_dprintk (RIO_DEBUG_CTRL, "*****\nEND MAP ENTRIES\n");
  320. }
  321. p->RIOQuickCheck = NOT_CHANGED; /* a table has been gotten */
  322. return 0;
  323. case RIO_PUT_TABLE:
  324. /*
  325. ** Write the routing table to the device driver from user space
  326. */
  327. rio_dprintk (RIO_DEBUG_CTRL, "RIO_PUT_TABLE\n");
  328. if ( !su ) {
  329. rio_dprintk (RIO_DEBUG_CTRL, "RIO_PUT_TABLE !Root\n");
  330. p->RIOError.Error = NOT_SUPER_USER;
  331. return -EPERM;
  332. }
  333. if ( copyin((int)arg, (caddr_t)&p->RIOConnectTable[0],
  334. TOTAL_MAP_ENTRIES*sizeof(struct Map) ) == COPYFAIL ) {
  335. rio_dprintk (RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
  336. p->RIOError.Error = COPYIN_FAILED;
  337. return -EFAULT;
  338. }
  339. /*
  340. ***********************************
  341. {
  342. int entry;
  343. rio_dprint(RIO_DEBUG_CTRL, ("*****\nMAP ENTRIES\n") );
  344. for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
  345. {
  346. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) );
  347. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) );
  348. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) );
  349. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) );
  350. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Flags = 0x%x\n", entry, p->RIOConnectTable[entry].Flags ) );
  351. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.SysPort = 0x%x\n", entry, p->RIOConnectTable[entry].SysPort ) );
  352. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) );
  353. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) );
  354. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) );
  355. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) );
  356. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) );
  357. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) );
  358. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[3].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) );
  359. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[4].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) );
  360. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) );
  361. }
  362. rio_dprint(RIO_DEBUG_CTRL, ("*****\nEND MAP ENTRIES\n") );
  363. }
  364. ***********************************
  365. */
  366. return RIONewTable(p);
  367. case RIO_GET_BINDINGS :
  368. /*
  369. ** Send bindings table, containing unique numbers of RTAs owned
  370. ** by this system to user space
  371. */
  372. rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_BINDINGS\n");
  373. if ( !su )
  374. {
  375. rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_BINDINGS !Root\n");
  376. p->RIOError.Error = NOT_SUPER_USER;
  377. return -EPERM;
  378. }
  379. if (copyout((caddr_t) p->RIOBindTab, (int)arg,
  380. (sizeof(ulong) * MAX_RTA_BINDINGS)) == COPYFAIL ) {
  381. rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
  382. p->RIOError.Error = COPYOUT_FAILED;
  383. return -EFAULT;
  384. }
  385. return 0;
  386. case RIO_PUT_BINDINGS :
  387. /*
  388. ** Receive a bindings table, containing unique numbers of RTAs owned
  389. ** by this system
  390. */
  391. rio_dprintk (RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS\n");
  392. if ( !su )
  393. {
  394. rio_dprintk (RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS !Root\n");
  395. p->RIOError.Error = NOT_SUPER_USER;
  396. return -EPERM;
  397. }
  398. if (copyin((int)arg, (caddr_t)&p->RIOBindTab[0],
  399. (sizeof(ulong) * MAX_RTA_BINDINGS))==COPYFAIL ) {
  400. rio_dprintk (RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
  401. p->RIOError.Error = COPYIN_FAILED;
  402. return -EFAULT;
  403. }
  404. return 0;
  405. case RIO_BIND_RTA :
  406. {
  407. int EmptySlot = -1;
  408. /*
  409. ** Bind this RTA to host, so that it will be booted by
  410. ** host in 'boot owned RTAs' mode.
  411. */
  412. rio_dprintk (RIO_DEBUG_CTRL, "RIO_BIND_RTA\n");
  413. if ( !su ) {
  414. rio_dprintk (RIO_DEBUG_CTRL, "RIO_BIND_RTA !Root\n");
  415. p->RIOError.Error = NOT_SUPER_USER;
  416. return -EPERM;
  417. }
  418. for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
  419. if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
  420. EmptySlot = Entry;
  421. else if (p->RIOBindTab[Entry] == (int) arg) {
  422. /*
  423. ** Already exists - delete
  424. */
  425. p->RIOBindTab[Entry] = 0L;
  426. rio_dprintk (RIO_DEBUG_CTRL, "Removing Rta %x from p->RIOBindTab\n",
  427. (int) arg);
  428. return 0;
  429. }
  430. }
  431. /*
  432. ** Dosen't exist - add
  433. */
  434. if (EmptySlot != -1) {
  435. p->RIOBindTab[EmptySlot] = (int) arg;
  436. rio_dprintk (RIO_DEBUG_CTRL, "Adding Rta %x to p->RIOBindTab\n",
  437. (int) arg);
  438. }
  439. else {
  440. rio_dprintk (RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %x not added\n",
  441. (int) arg);
  442. return -ENOMEM;
  443. }
  444. return 0;
  445. }
  446. case RIO_RESUME :
  447. rio_dprintk (RIO_DEBUG_CTRL, "RIO_RESUME\n");
  448. port = (uint) arg;
  449. if ((port < 0) || (port > 511)) {
  450. rio_dprintk (RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
  451. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  452. return -EINVAL;
  453. }
  454. PortP = p->RIOPortp[port];
  455. if (!PortP->Mapped) {
  456. rio_dprintk (RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not mapped\n", port);
  457. p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
  458. return -EINVAL;
  459. }
  460. if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
  461. rio_dprintk (RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not open\n", port);
  462. return -EINVAL;
  463. }
  464. rio_spin_lock_irqsave(&PortP->portSem, flags);
  465. if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RESUME) ==
  466. RIO_FAIL) {
  467. rio_dprintk (RIO_DEBUG_CTRL, "RIO_RESUME failed\n");
  468. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  469. return -EBUSY;
  470. }
  471. else {
  472. rio_dprintk (RIO_DEBUG_CTRL, "RIO_RESUME: Port %d resumed\n", port);
  473. PortP->State |= RIO_BUSY;
  474. }
  475. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  476. return retval;
  477. case RIO_ASSIGN_RTA:
  478. rio_dprintk (RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA\n");
  479. if ( !su ) {
  480. rio_dprintk (RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA !Root\n");
  481. p->RIOError.Error = NOT_SUPER_USER;
  482. return -EPERM;
  483. }
  484. if (copyin((int)arg, (caddr_t)&MapEnt, sizeof(MapEnt))
  485. == COPYFAIL) {
  486. rio_dprintk (RIO_DEBUG_CTRL, "Copy from user space failed\n");
  487. p->RIOError.Error = COPYIN_FAILED;
  488. return -EFAULT;
  489. }
  490. return RIOAssignRta(p, &MapEnt);
  491. case RIO_CHANGE_NAME:
  492. rio_dprintk (RIO_DEBUG_CTRL, "RIO_CHANGE_NAME\n");
  493. if ( !su ) {
  494. rio_dprintk (RIO_DEBUG_CTRL, "RIO_CHANGE_NAME !Root\n");
  495. p->RIOError.Error = NOT_SUPER_USER;
  496. return -EPERM;
  497. }
  498. if (copyin((int)arg, (caddr_t)&MapEnt, sizeof(MapEnt))
  499. == COPYFAIL) {
  500. rio_dprintk (RIO_DEBUG_CTRL, "Copy from user space failed\n");
  501. p->RIOError.Error = COPYIN_FAILED;
  502. return -EFAULT;
  503. }
  504. return RIOChangeName(p, &MapEnt);
  505. case RIO_DELETE_RTA:
  506. rio_dprintk (RIO_DEBUG_CTRL, "RIO_DELETE_RTA\n");
  507. if ( !su ) {
  508. rio_dprintk (RIO_DEBUG_CTRL, "RIO_DELETE_RTA !Root\n");
  509. p->RIOError.Error = NOT_SUPER_USER;
  510. return -EPERM;
  511. }
  512. if (copyin((int)arg, (caddr_t)&MapEnt, sizeof(MapEnt))
  513. == COPYFAIL ) {
  514. rio_dprintk (RIO_DEBUG_CTRL, "Copy from data space failed\n");
  515. p->RIOError.Error = COPYIN_FAILED;
  516. return -EFAULT;
  517. }
  518. return RIODeleteRta(p, &MapEnt);
  519. case RIO_QUICK_CHECK:
  520. /*
  521. ** 09.12.1998 ARG - ESIL 0776 part fix
  522. ** A customer was using this to get the RTAs
  523. ** connect/disconnect status.
  524. ** RIOConCon() had been botched use RIOHalted
  525. ** to keep track of RTA connections and
  526. ** disconnections. That has been changed and
  527. ** RIORtaDisCons in the rio_info struct now
  528. ** does the job. So we need to return the value
  529. ** of RIORtaCons instead of RIOHalted.
  530. **
  531. if (copyout((caddr_t)&p->RIOHalted,(int)arg,
  532. sizeof(uint))==COPYFAIL) {
  533. **
  534. */
  535. if (copyout((caddr_t)&p->RIORtaDisCons,(int)arg,
  536. sizeof(uint))==COPYFAIL) {
  537. p->RIOError.Error = COPYOUT_FAILED;
  538. return -EFAULT;
  539. }
  540. return 0;
  541. case RIO_LAST_ERROR:
  542. if (copyout((caddr_t)&p->RIOError, (int)arg,
  543. sizeof(struct Error)) ==COPYFAIL )
  544. return -EFAULT;
  545. return 0;
  546. case RIO_GET_LOG:
  547. rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_LOG\n");
  548. #ifdef LOGGING
  549. RIOGetLog(arg);
  550. return 0;
  551. #else
  552. return -EINVAL;
  553. #endif
  554. case RIO_GET_MODTYPE:
  555. if ( copyin( (int)arg, (caddr_t)&port,
  556. sizeof(uint)) == COPYFAIL )
  557. {
  558. p->RIOError.Error = COPYIN_FAILED;
  559. return -EFAULT;
  560. }
  561. rio_dprintk (RIO_DEBUG_CTRL, "Get module type for port %d\n", port);
  562. if ( port < 0 || port > 511 )
  563. {
  564. rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Bad port number %d\n", port);
  565. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  566. return -EINVAL;
  567. }
  568. PortP = (p->RIOPortp[port]);
  569. if (!PortP->Mapped)
  570. {
  571. rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Port %d not mapped\n", port);
  572. p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
  573. return -EINVAL;
  574. }
  575. /*
  576. ** Return module type of port
  577. */
  578. port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
  579. if (copyout((caddr_t)&port, (int)arg,
  580. sizeof(uint)) == COPYFAIL) {
  581. p->RIOError.Error = COPYOUT_FAILED;
  582. return -EFAULT;
  583. }
  584. return(0);
  585. /*
  586. ** 02.03.1999 ARG - ESIL 0820 fix
  587. ** We are no longer using "Boot Mode", so these ioctls
  588. ** are not required :
  589. **
  590. case RIO_GET_BOOT_MODE :
  591. rio_dprint(RIO_DEBUG_CTRL, ("Get boot mode - %x\n", p->RIOBootMode));
  592. **
  593. ** Return boot state of system - BOOT_ALL, BOOT_OWN or BOOT_NONE
  594. **
  595. if (copyout((caddr_t)&p->RIOBootMode, (int)arg,
  596. sizeof(p->RIOBootMode)) == COPYFAIL) {
  597. p->RIOError.Error = COPYOUT_FAILED;
  598. return -EFAULT;
  599. }
  600. return(0);
  601. case RIO_SET_BOOT_MODE :
  602. p->RIOBootMode = (uint) arg;
  603. rio_dprint(RIO_DEBUG_CTRL, ("Set boot mode to 0x%x\n", p->RIOBootMode));
  604. return(0);
  605. **
  606. ** End ESIL 0820 fix
  607. */
  608. case RIO_BLOCK_OPENS:
  609. rio_dprintk (RIO_DEBUG_CTRL, "Opens block until booted\n");
  610. for ( Entry=0; Entry < RIO_PORTS; Entry++ ) {
  611. rio_spin_lock_irqsave(&PortP->portSem, flags);
  612. p->RIOPortp[Entry]->WaitUntilBooted = 1;
  613. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  614. }
  615. return 0;
  616. case RIO_SETUP_PORTS:
  617. rio_dprintk (RIO_DEBUG_CTRL, "Setup ports\n");
  618. if (copyin((int)arg, (caddr_t)&PortSetup, sizeof(PortSetup))
  619. == COPYFAIL ) {
  620. p->RIOError.Error = COPYIN_FAILED;
  621. rio_dprintk (RIO_DEBUG_CTRL, "EFAULT");
  622. return -EFAULT;
  623. }
  624. if ( PortSetup.From > PortSetup.To ||
  625. PortSetup.To >= RIO_PORTS ) {
  626. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  627. rio_dprintk (RIO_DEBUG_CTRL, "ENXIO");
  628. return -ENXIO;
  629. }
  630. if ( PortSetup.XpCps > p->RIOConf.MaxXpCps ||
  631. PortSetup.XpCps < p->RIOConf.MinXpCps ) {
  632. p->RIOError.Error = XPRINT_CPS_OUT_OF_RANGE;
  633. rio_dprintk (RIO_DEBUG_CTRL, "EINVAL");
  634. return -EINVAL;
  635. }
  636. if ( !p->RIOPortp ) {
  637. cprintf("No p->RIOPortp array!\n");
  638. rio_dprintk (RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
  639. return -EIO;
  640. }
  641. rio_dprintk (RIO_DEBUG_CTRL, "entering loop (%d %d)!\n", PortSetup.From, PortSetup.To);
  642. for (loop=PortSetup.From; loop<=PortSetup.To; loop++) {
  643. rio_dprintk (RIO_DEBUG_CTRL, "in loop (%d)!\n", loop);
  644. #if 0
  645. PortP = p->RIOPortp[loop];
  646. if ( !PortP->TtyP )
  647. PortP->TtyP = &p->channel[loop];
  648. rio_spin_lock_irqsave(&PortP->portSem, flags);
  649. if ( PortSetup.IxAny )
  650. PortP->Config |= RIO_IXANY;
  651. else
  652. PortP->Config &= ~RIO_IXANY;
  653. if ( PortSetup.IxOn )
  654. PortP->Config |= RIO_IXON;
  655. else
  656. PortP->Config &= ~RIO_IXON;
  657. /*
  658. ** If the port needs to wait for all a processes output
  659. ** to drain before closing then this flag will be set.
  660. */
  661. if (PortSetup.Drain) {
  662. PortP->Config |= RIO_WAITDRAIN;
  663. } else {
  664. PortP->Config &= ~RIO_WAITDRAIN;
  665. }
  666. /*
  667. ** Store settings if locking or unlocking port or if the
  668. ** port is not locked, when setting the store option.
  669. */
  670. if (PortP->Mapped &&
  671. ((PortSetup.Lock && !PortP->Lock) ||
  672. (!PortP->Lock &&
  673. (PortSetup.Store && !PortP->Store)))) {
  674. PortP->StoredTty.iflag = PortP->TtyP->tm.c_iflag;
  675. PortP->StoredTty.oflag = PortP->TtyP->tm.c_oflag;
  676. PortP->StoredTty.cflag = PortP->TtyP->tm.c_cflag;
  677. PortP->StoredTty.lflag = PortP->TtyP->tm.c_lflag;
  678. PortP->StoredTty.line = PortP->TtyP->tm.c_line;
  679. bcopy(PortP->TtyP->tm.c_cc, PortP->StoredTty.cc,
  680. NCC + 5);
  681. }
  682. PortP->Lock = PortSetup.Lock;
  683. PortP->Store = PortSetup.Store;
  684. PortP->Xprint.XpCps = PortSetup.XpCps;
  685. bcopy(PortSetup.XpOn,PortP->Xprint.XpOn,MAX_XP_CTRL_LEN);
  686. bcopy(PortSetup.XpOff,PortP->Xprint.XpOff,MAX_XP_CTRL_LEN);
  687. PortP->Xprint.XpOn[MAX_XP_CTRL_LEN-1] = '\0';
  688. PortP->Xprint.XpOff[MAX_XP_CTRL_LEN-1] = '\0';
  689. PortP->Xprint.XpLen = RIOStrlen(PortP->Xprint.XpOn)+
  690. RIOStrlen(PortP->Xprint.XpOff);
  691. rio_spin_unlock_irqrestore( &PortP->portSem , flags);
  692. #endif
  693. }
  694. rio_dprintk (RIO_DEBUG_CTRL, "after loop (%d)!\n", loop);
  695. rio_dprintk (RIO_DEBUG_CTRL, "Retval:%x\n", retval);
  696. return retval;
  697. case RIO_GET_PORT_SETUP :
  698. rio_dprintk (RIO_DEBUG_CTRL, "Get port setup\n");
  699. if (copyin((int)arg, (caddr_t)&PortSetup, sizeof(PortSetup))
  700. == COPYFAIL ) {
  701. p->RIOError.Error = COPYIN_FAILED;
  702. return -EFAULT;
  703. }
  704. if ( PortSetup.From >= RIO_PORTS ) {
  705. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  706. return -ENXIO;
  707. }
  708. port = PortSetup.To = PortSetup.From;
  709. PortSetup.IxAny = (p->RIOPortp[port]->Config & RIO_IXANY) ?
  710. 1 : 0;
  711. PortSetup.IxOn = (p->RIOPortp[port]->Config & RIO_IXON) ?
  712. 1 : 0;
  713. PortSetup.Drain = (p->RIOPortp[port]->Config & RIO_WAITDRAIN) ?
  714. 1 : 0;
  715. PortSetup.Store = p->RIOPortp[port]->Store;
  716. PortSetup.Lock = p->RIOPortp[port]->Lock;
  717. PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
  718. bcopy(p->RIOPortp[port]->Xprint.XpOn, PortSetup.XpOn,
  719. MAX_XP_CTRL_LEN);
  720. bcopy(p->RIOPortp[port]->Xprint.XpOff, PortSetup.XpOff,
  721. MAX_XP_CTRL_LEN);
  722. PortSetup.XpOn[MAX_XP_CTRL_LEN-1] = '\0';
  723. PortSetup.XpOff[MAX_XP_CTRL_LEN-1] = '\0';
  724. if ( copyout((caddr_t)&PortSetup,(int)arg,sizeof(PortSetup))
  725. ==COPYFAIL ) {
  726. p->RIOError.Error = COPYOUT_FAILED;
  727. return -EFAULT;
  728. }
  729. return retval;
  730. case RIO_GET_PORT_PARAMS :
  731. rio_dprintk (RIO_DEBUG_CTRL, "Get port params\n");
  732. if (copyin( (int)arg, (caddr_t)&PortParams,
  733. sizeof(struct PortParams)) == COPYFAIL) {
  734. p->RIOError.Error = COPYIN_FAILED;
  735. return -EFAULT;
  736. }
  737. if (PortParams.Port >= RIO_PORTS) {
  738. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  739. return -ENXIO;
  740. }
  741. PortP = (p->RIOPortp[PortParams.Port]);
  742. PortParams.Config = PortP->Config;
  743. PortParams.State = PortP->State;
  744. rio_dprintk (RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
  745. if (copyout((caddr_t)&PortParams, (int)arg,
  746. sizeof(struct PortParams)) == COPYFAIL ) {
  747. p->RIOError.Error = COPYOUT_FAILED;
  748. return -EFAULT;
  749. }
  750. return retval;
  751. case RIO_GET_PORT_TTY :
  752. rio_dprintk (RIO_DEBUG_CTRL, "Get port tty\n");
  753. if (copyin((int)arg, (caddr_t)&PortTty, sizeof(struct PortTty))
  754. == COPYFAIL) {
  755. p->RIOError.Error = COPYIN_FAILED;
  756. return -EFAULT;
  757. }
  758. if ( PortTty.port >= RIO_PORTS ) {
  759. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  760. return -ENXIO;
  761. }
  762. rio_dprintk (RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
  763. PortP = (p->RIOPortp[PortTty.port]);
  764. #if 0
  765. PortTty.Tty.tm.c_iflag = PortP->TtyP->tm.c_iflag;
  766. PortTty.Tty.tm.c_oflag = PortP->TtyP->tm.c_oflag;
  767. PortTty.Tty.tm.c_cflag = PortP->TtyP->tm.c_cflag;
  768. PortTty.Tty.tm.c_lflag = PortP->TtyP->tm.c_lflag;
  769. #endif
  770. if (copyout((caddr_t)&PortTty, (int)arg,
  771. sizeof(struct PortTty)) == COPYFAIL) {
  772. p->RIOError.Error = COPYOUT_FAILED;
  773. return -EFAULT;
  774. }
  775. return retval;
  776. case RIO_SET_PORT_TTY :
  777. if (copyin((int)arg, (caddr_t)&PortTty,
  778. sizeof(struct PortTty)) == COPYFAIL) {
  779. p->RIOError.Error = COPYIN_FAILED;
  780. return -EFAULT;
  781. }
  782. rio_dprintk (RIO_DEBUG_CTRL, "Set port %d tty\n", PortTty.port);
  783. if (PortTty.port >= (ushort) RIO_PORTS) {
  784. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  785. return -ENXIO;
  786. }
  787. PortP = (p->RIOPortp[PortTty.port]);
  788. #if 0
  789. rio_spin_lock_irqsave(&PortP->portSem, flags);
  790. PortP->TtyP->tm.c_iflag = PortTty.Tty.tm.c_iflag;
  791. PortP->TtyP->tm.c_oflag = PortTty.Tty.tm.c_oflag;
  792. PortP->TtyP->tm.c_cflag = PortTty.Tty.tm.c_cflag;
  793. PortP->TtyP->tm.c_lflag = PortTty.Tty.tm.c_lflag;
  794. rio_spin_unlock_irqrestore( &PortP->portSem , flags);
  795. #endif
  796. RIOParam(PortP, CONFIG, PortP->State & RIO_MODEM, OK_TO_SLEEP);
  797. return retval;
  798. case RIO_SET_PORT_PARAMS :
  799. rio_dprintk (RIO_DEBUG_CTRL, "Set port params\n");
  800. if ( copyin((int)arg, (caddr_t)&PortParams, sizeof(PortParams))
  801. == COPYFAIL ) {
  802. p->RIOError.Error = COPYIN_FAILED;
  803. return -EFAULT;
  804. }
  805. if (PortParams.Port >= (ushort) RIO_PORTS) {
  806. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  807. return -ENXIO;
  808. }
  809. PortP = (p->RIOPortp[PortParams.Port]);
  810. rio_spin_lock_irqsave(&PortP->portSem, flags);
  811. PortP->Config = PortParams.Config;
  812. rio_spin_unlock_irqrestore( &PortP->portSem , flags);
  813. return retval;
  814. case RIO_GET_PORT_STATS :
  815. rio_dprintk (RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
  816. if ( copyin((int)arg, (caddr_t)&portStats,
  817. sizeof(struct portStats)) == COPYFAIL ) {
  818. p->RIOError.Error = COPYIN_FAILED;
  819. return -EFAULT;
  820. }
  821. if ( portStats.port >= RIO_PORTS ) {
  822. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  823. return -ENXIO;
  824. }
  825. PortP = (p->RIOPortp[portStats.port]);
  826. portStats.gather = PortP->statsGather;
  827. portStats.txchars = PortP->txchars;
  828. portStats.rxchars = PortP->rxchars;
  829. portStats.opens = PortP->opens;
  830. portStats.closes = PortP->closes;
  831. portStats.ioctls = PortP->ioctls;
  832. if ( copyout((caddr_t)&portStats, (int)arg,
  833. sizeof(struct portStats)) == COPYFAIL ) {
  834. p->RIOError.Error = COPYOUT_FAILED;
  835. return -EFAULT;
  836. }
  837. return retval;
  838. case RIO_RESET_PORT_STATS :
  839. port = (uint) arg;
  840. rio_dprintk (RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
  841. if ( port >= RIO_PORTS ) {
  842. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  843. return -ENXIO;
  844. }
  845. PortP = (p->RIOPortp[port]);
  846. rio_spin_lock_irqsave(&PortP->portSem, flags);
  847. PortP->txchars = 0;
  848. PortP->rxchars = 0;
  849. PortP->opens = 0;
  850. PortP->closes = 0;
  851. PortP->ioctls = 0;
  852. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  853. return retval;
  854. case RIO_GATHER_PORT_STATS :
  855. rio_dprintk (RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
  856. if ( copyin( (int)arg, (caddr_t)&portStats,
  857. sizeof(struct portStats)) == COPYFAIL ) {
  858. p->RIOError.Error = COPYIN_FAILED;
  859. return -EFAULT;
  860. }
  861. if ( portStats.port >= RIO_PORTS ) {
  862. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  863. return -ENXIO;
  864. }
  865. PortP = (p->RIOPortp[portStats.port]);
  866. rio_spin_lock_irqsave(&PortP->portSem, flags);
  867. PortP->statsGather = portStats.gather;
  868. rio_spin_unlock_irqrestore( &PortP->portSem , flags);
  869. return retval;
  870. #ifdef DEBUG_SUPPORTED
  871. case RIO_READ_LEVELS:
  872. {
  873. int num;
  874. rio_dprintk (RIO_DEBUG_CTRL, "RIO_READ_LEVELS\n");
  875. for ( num=0; RIODbInf[num].Flag; num++ ) ;
  876. rio_dprintk (RIO_DEBUG_CTRL, "%d levels to copy\n",num);
  877. if (copyout((caddr_t)RIODbInf,(int)arg,
  878. sizeof(struct DbInf)*(num+1))==COPYFAIL) {
  879. rio_dprintk (RIO_DEBUG_CTRL, "ReadLevels Copy failed\n");
  880. p->RIOError.Error = COPYOUT_FAILED;
  881. return -EFAULT;
  882. }
  883. rio_dprintk (RIO_DEBUG_CTRL, "%d levels to copied\n",num);
  884. return retval;
  885. }
  886. #endif
  887. case RIO_READ_CONFIG:
  888. rio_dprintk (RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
  889. if (copyout((caddr_t)&p->RIOConf, (int)arg,
  890. sizeof(struct Conf)) ==COPYFAIL ) {
  891. p->RIOError.Error = COPYOUT_FAILED;
  892. return -EFAULT;
  893. }
  894. return retval;
  895. case RIO_SET_CONFIG:
  896. rio_dprintk (RIO_DEBUG_CTRL, "RIO_SET_CONFIG\n");
  897. if ( !su ) {
  898. p->RIOError.Error = NOT_SUPER_USER;
  899. return -EPERM;
  900. }
  901. if ( copyin((int)arg, (caddr_t)&p->RIOConf, sizeof(struct Conf) )
  902. ==COPYFAIL ) {
  903. p->RIOError.Error = COPYIN_FAILED;
  904. return -EFAULT;
  905. }
  906. /*
  907. ** move a few value around
  908. */
  909. for (Host=0; Host < p->RIONumHosts; Host++)
  910. if ( (p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING )
  911. WWORD(p->RIOHosts[Host].ParmMapP->timer ,
  912. p->RIOConf.Timer);
  913. return retval;
  914. case RIO_START_POLLER:
  915. rio_dprintk (RIO_DEBUG_CTRL, "RIO_START_POLLER\n");
  916. return -EINVAL;
  917. case RIO_STOP_POLLER:
  918. rio_dprintk (RIO_DEBUG_CTRL, "RIO_STOP_POLLER\n");
  919. if ( !su ) {
  920. p->RIOError.Error = NOT_SUPER_USER;
  921. return -EPERM;
  922. }
  923. p->RIOPolling = NOT_POLLING;
  924. return retval;
  925. case RIO_SETDEBUG:
  926. case RIO_GETDEBUG:
  927. rio_dprintk (RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
  928. if ( copyin( (int)arg, (caddr_t)&DebugCtrl, sizeof(DebugCtrl) )
  929. ==COPYFAIL ) {
  930. p->RIOError.Error = COPYIN_FAILED;
  931. return -EFAULT;
  932. }
  933. if ( DebugCtrl.SysPort == NO_PORT ) {
  934. if ( cmd == RIO_SETDEBUG ) {
  935. if ( !su ) {
  936. p->RIOError.Error = NOT_SUPER_USER;
  937. return -EPERM;
  938. }
  939. p->rio_debug = DebugCtrl.Debug;
  940. p->RIODebugWait = DebugCtrl.Wait;
  941. rio_dprintk (RIO_DEBUG_CTRL, "Set global debug to 0x%x set wait to 0x%x\n",
  942. p->rio_debug,p->RIODebugWait);
  943. }
  944. else {
  945. rio_dprintk (RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n",
  946. p->rio_debug,p->RIODebugWait);
  947. DebugCtrl.Debug = p->rio_debug;
  948. DebugCtrl.Wait = p->RIODebugWait;
  949. if ( copyout((caddr_t)&DebugCtrl,(int)arg,
  950. sizeof(DebugCtrl)) == COPYFAIL ) {
  951. rio_dprintk (RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n",
  952. DebugCtrl.SysPort);
  953. p->RIOError.Error = COPYOUT_FAILED;
  954. return -EFAULT;
  955. }
  956. }
  957. }
  958. else if ( DebugCtrl.SysPort >= RIO_PORTS &&
  959. DebugCtrl.SysPort != NO_PORT ) {
  960. rio_dprintk (RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n",
  961. DebugCtrl.SysPort);
  962. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  963. return -ENXIO;
  964. }
  965. else if ( cmd == RIO_SETDEBUG ) {
  966. if ( !su ) {
  967. p->RIOError.Error = NOT_SUPER_USER;
  968. return -EPERM;
  969. }
  970. rio_spin_lock_irqsave(&PortP->portSem, flags);
  971. p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug;
  972. rio_spin_unlock_irqrestore( &PortP->portSem , flags);
  973. rio_dprintk (RIO_DEBUG_CTRL, "RIO_SETDEBUG 0x%x\n",
  974. p->RIOPortp[DebugCtrl.SysPort]->Debug);
  975. }
  976. else {
  977. rio_dprintk (RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n",
  978. p->RIOPortp[DebugCtrl.SysPort]->Debug);
  979. DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
  980. if ( copyout((caddr_t)&DebugCtrl,(int)arg,
  981. sizeof(DebugCtrl))==COPYFAIL ) {
  982. rio_dprintk (RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
  983. p->RIOError.Error = COPYOUT_FAILED;
  984. return -EFAULT;
  985. }
  986. }
  987. return retval;
  988. case RIO_VERSID:
  989. /*
  990. ** Enquire about the release and version.
  991. ** We return MAX_VERSION_LEN bytes, being a
  992. ** textual null terminated string.
  993. */
  994. rio_dprintk (RIO_DEBUG_CTRL, "RIO_VERSID\n");
  995. if ( copyout( (caddr_t)RIOVersid(),
  996. (int)arg,
  997. sizeof(struct rioVersion) ) == COPYFAIL )
  998. {
  999. rio_dprintk (RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
  1000. p->RIOError.Error = COPYOUT_FAILED;
  1001. return -EFAULT;
  1002. }
  1003. return retval;
  1004. /*
  1005. ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1006. ** !! commented out previous 'RIO_VERSID' functionality !!
  1007. ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1008. **
  1009. case RIO_VERSID:
  1010. **
  1011. ** Enquire about the release and version.
  1012. ** We return MAX_VERSION_LEN bytes, being a textual null
  1013. ** terminated string.
  1014. **
  1015. rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID\n"));
  1016. if (copyout((caddr_t)RIOVersid(),
  1017. (int)arg, MAX_VERSION_LEN ) == COPYFAIL ) {
  1018. rio_dprint(RIO_DEBUG_CTRL, ("RIO_VERSID: Bad copy to user space\n",Host));
  1019. p->RIOError.Error = COPYOUT_FAILED;
  1020. return -EFAULT;
  1021. }
  1022. return retval;
  1023. **
  1024. ** !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1025. */
  1026. case RIO_NUM_HOSTS:
  1027. /*
  1028. ** Enquire as to the number of hosts located
  1029. ** at init time.
  1030. */
  1031. rio_dprintk (RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
  1032. if (copyout((caddr_t)&p->RIONumHosts, (int)arg,
  1033. sizeof(p->RIONumHosts) )==COPYFAIL ) {
  1034. rio_dprintk (RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
  1035. p->RIOError.Error = COPYOUT_FAILED;
  1036. return -EFAULT;
  1037. }
  1038. return retval;
  1039. case RIO_HOST_FOAD:
  1040. /*
  1041. ** Kill host. This may not be in the final version...
  1042. */
  1043. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_FOAD %d\n", (int)arg);
  1044. if ( !su ) {
  1045. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
  1046. p->RIOError.Error = NOT_SUPER_USER;
  1047. return -EPERM;
  1048. }
  1049. p->RIOHalted = 1;
  1050. p->RIOSystemUp = 0;
  1051. for ( Host=0; Host<p->RIONumHosts; Host++ ) {
  1052. (void)RIOBoardTest( p->RIOHosts[Host].PaddrP,
  1053. p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type,
  1054. p->RIOHosts[Host].Slot );
  1055. bzero( (caddr_t)&p->RIOHosts[Host].Flags,
  1056. ((int)&p->RIOHosts[Host].____end_marker____) -
  1057. ((int)&p->RIOHosts[Host].Flags) );
  1058. p->RIOHosts[Host].Flags = RC_WAITING;
  1059. #if 0
  1060. RIOSetupDataStructs(p);
  1061. #endif
  1062. }
  1063. RIOFoadWakeup(p);
  1064. p->RIONumBootPkts = 0;
  1065. p->RIOBooting = 0;
  1066. #ifdef RINGBUFFER_SUPPORT
  1067. for( loop=0; loop<RIO_PORTS; loop++ )
  1068. if ( p->RIOPortp[loop]->TxRingBuffer )
  1069. sysfree((void *)p->RIOPortp[loop]->TxRingBuffer,
  1070. RIOBufferSize );
  1071. #endif
  1072. #if 0
  1073. bzero((caddr_t)&p->RIOPortp[0],RIO_PORTS*sizeof(struct Port));
  1074. #else
  1075. printk ("HEEEEELP!\n");
  1076. #endif
  1077. for( loop=0; loop<RIO_PORTS; loop++ ) {
  1078. #if 0
  1079. p->RIOPortp[loop]->TtyP = &p->channel[loop];
  1080. #endif
  1081. spin_lock_init(&p->RIOPortp[loop]->portSem);
  1082. p->RIOPortp[loop]->InUse = NOT_INUSE;
  1083. }
  1084. p->RIOSystemUp = 0;
  1085. return retval;
  1086. case RIO_DOWNLOAD:
  1087. rio_dprintk (RIO_DEBUG_CTRL, "RIO_DOWNLOAD\n");
  1088. if ( !su ) {
  1089. rio_dprintk (RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Not super user\n");
  1090. p->RIOError.Error = NOT_SUPER_USER;
  1091. return -EPERM;
  1092. }
  1093. if ( copyin((int)arg, (caddr_t)&DownLoad,
  1094. sizeof(DownLoad) )==COPYFAIL ) {
  1095. rio_dprintk (RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
  1096. p->RIOError.Error = COPYIN_FAILED;
  1097. return -EFAULT;
  1098. }
  1099. rio_dprintk (RIO_DEBUG_CTRL, "Copied in download code for product code 0x%x\n",
  1100. DownLoad.ProductCode);
  1101. /*
  1102. ** It is important that the product code is an unsigned object!
  1103. */
  1104. if ( DownLoad.ProductCode > MAX_PRODUCT ) {
  1105. rio_dprintk (RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Bad product code %d passed\n",
  1106. DownLoad.ProductCode);
  1107. p->RIOError.Error = NO_SUCH_PRODUCT;
  1108. return -ENXIO;
  1109. }
  1110. /*
  1111. ** do something!
  1112. */
  1113. retval = (*(RIOBootTable[DownLoad.ProductCode]))(p, &DownLoad);
  1114. /* <-- Panic */
  1115. p->RIOHalted = 0;
  1116. /*
  1117. ** and go back, content with a job well completed.
  1118. */
  1119. return retval;
  1120. case RIO_PARMS:
  1121. {
  1122. uint host;
  1123. if (copyin((int)arg, (caddr_t)&host,
  1124. sizeof(host) ) == COPYFAIL ) {
  1125. rio_dprintk (RIO_DEBUG_CTRL,
  1126. "RIO_HOST_REQ: Copy in from user space failed\n");
  1127. p->RIOError.Error = COPYIN_FAILED;
  1128. return -EFAULT;
  1129. }
  1130. /*
  1131. ** Fetch the parmmap
  1132. */
  1133. rio_dprintk (RIO_DEBUG_CTRL, "RIO_PARMS\n");
  1134. if ( copyout( (caddr_t)p->RIOHosts[host].ParmMapP,
  1135. (int)arg, sizeof(PARM_MAP) )==COPYFAIL ) {
  1136. p->RIOError.Error = COPYOUT_FAILED;
  1137. rio_dprintk (RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
  1138. return -EFAULT;
  1139. }
  1140. }
  1141. return retval;
  1142. case RIO_HOST_REQ:
  1143. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
  1144. if (copyin((int)arg, (caddr_t)&HostReq,
  1145. sizeof(HostReq) )==COPYFAIL ) {
  1146. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
  1147. p->RIOError.Error = COPYIN_FAILED;
  1148. return -EFAULT;
  1149. }
  1150. if ( HostReq.HostNum >= p->RIONumHosts ) {
  1151. p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
  1152. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_REQ: Illegal host number %d\n",
  1153. HostReq.HostNum);
  1154. return -ENXIO;
  1155. }
  1156. rio_dprintk (RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
  1157. if (copyout((caddr_t)&p->RIOHosts[HostReq.HostNum],
  1158. (int)HostReq.HostP,sizeof(struct Host) ) == COPYFAIL) {
  1159. p->RIOError.Error = COPYOUT_FAILED;
  1160. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
  1161. return -EFAULT;
  1162. }
  1163. return retval;
  1164. case RIO_HOST_DPRAM:
  1165. rio_dprintk (RIO_DEBUG_CTRL, "Request for DPRAM\n");
  1166. if ( copyin( (int)arg, (caddr_t)&HostDpRam,
  1167. sizeof(HostDpRam) )==COPYFAIL ) {
  1168. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
  1169. p->RIOError.Error = COPYIN_FAILED;
  1170. return -EFAULT;
  1171. }
  1172. if ( HostDpRam.HostNum >= p->RIONumHosts ) {
  1173. p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
  1174. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Illegal host number %d\n",
  1175. HostDpRam.HostNum);
  1176. return -ENXIO;
  1177. }
  1178. rio_dprintk (RIO_DEBUG_CTRL, "Request for host %d\n", HostDpRam.HostNum);
  1179. if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) {
  1180. int off;
  1181. /* It's hardware like this that really gets on my tits. */
  1182. static unsigned char copy[sizeof(struct DpRam)];
  1183. for ( off=0; off<sizeof(struct DpRam); off++ )
  1184. copy[off] = p->RIOHosts[HostDpRam.HostNum].Caddr[off];
  1185. if ( copyout( (caddr_t)copy, (int)HostDpRam.DpRamP,
  1186. sizeof(struct DpRam) ) == COPYFAIL ) {
  1187. p->RIOError.Error = COPYOUT_FAILED;
  1188. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
  1189. return -EFAULT;
  1190. }
  1191. }
  1192. else if (copyout((caddr_t)p->RIOHosts[HostDpRam.HostNum].Caddr,
  1193. (int)HostDpRam.DpRamP,
  1194. sizeof(struct DpRam) ) == COPYFAIL ) {
  1195. p->RIOError.Error = COPYOUT_FAILED;
  1196. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
  1197. return -EFAULT;
  1198. }
  1199. return retval;
  1200. case RIO_SET_BUSY:
  1201. rio_dprintk (RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
  1202. if ( (int)arg < 0 || (int)arg > 511 ) {
  1203. rio_dprintk (RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %d\n",(int)arg);
  1204. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  1205. return -EINVAL;
  1206. }
  1207. rio_spin_lock_irqsave(&PortP->portSem, flags);
  1208. p->RIOPortp[(int)arg]->State |= RIO_BUSY;
  1209. rio_spin_unlock_irqrestore( &PortP->portSem , flags);
  1210. return retval;
  1211. case RIO_HOST_PORT:
  1212. /*
  1213. ** The daemon want port information
  1214. ** (probably for debug reasons)
  1215. */
  1216. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
  1217. if ( copyin((int)arg, (caddr_t)&PortReq,
  1218. sizeof(PortReq) )==COPYFAIL ) {
  1219. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
  1220. p->RIOError.Error = COPYIN_FAILED;
  1221. return -EFAULT;
  1222. }
  1223. if (PortReq.SysPort >= RIO_PORTS) { /* SysPort is unsigned */
  1224. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_PORT: Illegal port number %d\n",
  1225. PortReq.SysPort);
  1226. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  1227. return -ENXIO;
  1228. }
  1229. rio_dprintk (RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
  1230. if (copyout((caddr_t)p->RIOPortp[PortReq.SysPort],
  1231. (int)PortReq.PortP,
  1232. sizeof(struct Port) ) == COPYFAIL) {
  1233. p->RIOError.Error = COPYOUT_FAILED;
  1234. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
  1235. return -EFAULT;
  1236. }
  1237. return retval;
  1238. case RIO_HOST_RUP:
  1239. /*
  1240. ** The daemon want rup information
  1241. ** (probably for debug reasons)
  1242. */
  1243. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
  1244. if (copyin((int)arg, (caddr_t)&RupReq,
  1245. sizeof(RupReq) )==COPYFAIL ) {
  1246. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
  1247. p->RIOError.Error = COPYIN_FAILED;
  1248. return -EFAULT;
  1249. }
  1250. if (RupReq.HostNum >= p->RIONumHosts) { /* host is unsigned */
  1251. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal host number %d\n",
  1252. RupReq.HostNum);
  1253. p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
  1254. return -ENXIO;
  1255. }
  1256. if ( RupReq.RupNum >= MAX_RUP+LINKS_PER_UNIT ) { /* eek! */
  1257. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal rup number %d\n",
  1258. RupReq.RupNum);
  1259. p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
  1260. return -EINVAL;
  1261. }
  1262. HostP = &p->RIOHosts[RupReq.HostNum];
  1263. if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
  1264. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_RUP: Host %d not running\n",
  1265. RupReq.HostNum);
  1266. p->RIOError.Error = HOST_NOT_RUNNING;
  1267. return -EIO;
  1268. }
  1269. rio_dprintk (RIO_DEBUG_CTRL, "Request for rup %d from host %d\n",
  1270. RupReq.RupNum,RupReq.HostNum);
  1271. if (copyout((caddr_t)HostP->UnixRups[RupReq.RupNum].RupP,
  1272. (int)RupReq.RupP,sizeof(struct RUP) ) == COPYFAIL) {
  1273. p->RIOError.Error = COPYOUT_FAILED;
  1274. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
  1275. return -EFAULT;
  1276. }
  1277. return retval;
  1278. case RIO_HOST_LPB:
  1279. /*
  1280. ** The daemon want lpb information
  1281. ** (probably for debug reasons)
  1282. */
  1283. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
  1284. if (copyin((int)arg, (caddr_t)&LpbReq,
  1285. sizeof(LpbReq) )==COPYFAIL ) {
  1286. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
  1287. p->RIOError.Error = COPYIN_FAILED;
  1288. return -EFAULT;
  1289. }
  1290. if (LpbReq.Host >= p->RIONumHosts) { /* host is unsigned */
  1291. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal host number %d\n",
  1292. LpbReq.Host);
  1293. p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
  1294. return -ENXIO;
  1295. }
  1296. if ( LpbReq.Link >= LINKS_PER_UNIT ) { /* eek! */
  1297. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal link number %d\n",
  1298. LpbReq.Link);
  1299. p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE;
  1300. return -EINVAL;
  1301. }
  1302. HostP = &p->RIOHosts[LpbReq.Host];
  1303. if ( (HostP->Flags & RUN_STATE) != RC_RUNNING ) {
  1304. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_LPB: Host %d not running\n",
  1305. LpbReq.Host );
  1306. p->RIOError.Error = HOST_NOT_RUNNING;
  1307. return -EIO;
  1308. }
  1309. rio_dprintk (RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n",
  1310. LpbReq.Link, LpbReq.Host);
  1311. if (copyout((caddr_t)&HostP->LinkStrP[LpbReq.Link],
  1312. (int)LpbReq.LpbP,sizeof(struct LPB) ) == COPYFAIL) {
  1313. rio_dprintk (RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
  1314. p->RIOError.Error = COPYOUT_FAILED;
  1315. return -EFAULT;
  1316. }
  1317. return retval;
  1318. /*
  1319. ** Here 3 IOCTL's that allow us to change the way in which
  1320. ** rio logs errors. send them just to syslog or send them
  1321. ** to both syslog and console or send them to just the console.
  1322. **
  1323. ** See RioStrBuf() in util.c for the other half.
  1324. */
  1325. case RIO_SYSLOG_ONLY:
  1326. p->RIOPrintLogState = PRINT_TO_LOG; /* Just syslog */
  1327. return 0;
  1328. case RIO_SYSLOG_CONS:
  1329. p->RIOPrintLogState = PRINT_TO_LOG_CONS;/* syslog and console */
  1330. return 0;
  1331. case RIO_CONS_ONLY:
  1332. p->RIOPrintLogState = PRINT_TO_CONS; /* Just console */
  1333. return 0;
  1334. case RIO_SIGNALS_ON:
  1335. if ( p->RIOSignalProcess ) {
  1336. p->RIOError.Error = SIGNALS_ALREADY_SET;
  1337. return -EBUSY;
  1338. }
  1339. p->RIOSignalProcess = getpid();
  1340. p->RIOPrintDisabled = DONT_PRINT;
  1341. return retval;
  1342. case RIO_SIGNALS_OFF:
  1343. if ( p->RIOSignalProcess != getpid() ) {
  1344. p->RIOError.Error = NOT_RECEIVING_PROCESS;
  1345. return -EPERM;
  1346. }
  1347. rio_dprintk (RIO_DEBUG_CTRL, "Clear signal process to zero\n");
  1348. p->RIOSignalProcess = 0;
  1349. return retval;
  1350. case RIO_SET_BYTE_MODE:
  1351. for ( Host=0; Host<p->RIONumHosts; Host++ )
  1352. if ( p->RIOHosts[Host].Type == RIO_AT )
  1353. p->RIOHosts[Host].Mode &= ~WORD_OPERATION;
  1354. return retval;
  1355. case RIO_SET_WORD_MODE:
  1356. for ( Host=0; Host<p->RIONumHosts; Host++ )
  1357. if ( p->RIOHosts[Host].Type == RIO_AT )
  1358. p->RIOHosts[Host].Mode |= WORD_OPERATION;
  1359. return retval;
  1360. case RIO_SET_FAST_BUS:
  1361. for ( Host=0; Host<p->RIONumHosts; Host++ )
  1362. if ( p->RIOHosts[Host].Type == RIO_AT )
  1363. p->RIOHosts[Host].Mode |= FAST_AT_BUS;
  1364. return retval;
  1365. case RIO_SET_SLOW_BUS:
  1366. for ( Host=0; Host<p->RIONumHosts; Host++ )
  1367. if ( p->RIOHosts[Host].Type == RIO_AT )
  1368. p->RIOHosts[Host].Mode &= ~FAST_AT_BUS;
  1369. return retval;
  1370. case RIO_MAP_B50_TO_50:
  1371. case RIO_MAP_B50_TO_57600:
  1372. case RIO_MAP_B110_TO_110:
  1373. case RIO_MAP_B110_TO_115200:
  1374. rio_dprintk (RIO_DEBUG_CTRL, "Baud rate mapping\n");
  1375. port = (uint) arg;
  1376. if ( port < 0 || port > 511 ) {
  1377. rio_dprintk (RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
  1378. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  1379. return -EINVAL;
  1380. }
  1381. rio_spin_lock_irqsave(&PortP->portSem, flags);
  1382. switch( cmd )
  1383. {
  1384. case RIO_MAP_B50_TO_50 :
  1385. p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50;
  1386. break;
  1387. case RIO_MAP_B50_TO_57600 :
  1388. p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50;
  1389. break;
  1390. case RIO_MAP_B110_TO_110 :
  1391. p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110;
  1392. break;
  1393. case RIO_MAP_B110_TO_115200 :
  1394. p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110;
  1395. break;
  1396. }
  1397. rio_spin_unlock_irqrestore( &PortP->portSem , flags);
  1398. return retval;
  1399. case RIO_STREAM_INFO:
  1400. rio_dprintk (RIO_DEBUG_CTRL, "RIO_STREAM_INFO\n");
  1401. return -EINVAL;
  1402. case RIO_SEND_PACKET:
  1403. rio_dprintk (RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
  1404. if ( copyin( (int)arg, (caddr_t)&SendPack,
  1405. sizeof(SendPack) )==COPYFAIL ) {
  1406. rio_dprintk (RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
  1407. p->RIOError.Error = COPYIN_FAILED;
  1408. return -EFAULT;
  1409. }
  1410. if ( SendPack.PortNum >= 128 ) {
  1411. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  1412. return -ENXIO;
  1413. }
  1414. PortP = p->RIOPortp[SendPack.PortNum];
  1415. rio_spin_lock_irqsave(&PortP->portSem, flags);
  1416. if ( !can_add_transmit(&PacketP,PortP) ) {
  1417. p->RIOError.Error = UNIT_IS_IN_USE;
  1418. rio_spin_unlock_irqrestore( &PortP->portSem , flags);
  1419. return -ENOSPC;
  1420. }
  1421. for ( loop=0; loop<(ushort)(SendPack.Len & 127); loop++ )
  1422. WBYTE(PacketP->data[loop], SendPack.Data[loop] );
  1423. WBYTE(PacketP->len, SendPack.Len);
  1424. add_transmit( PortP );
  1425. /*
  1426. ** Count characters transmitted for port statistics reporting
  1427. */
  1428. if (PortP->statsGather)
  1429. PortP->txchars += (SendPack.Len & 127);
  1430. rio_spin_unlock_irqrestore( &PortP->portSem , flags);
  1431. return retval;
  1432. case RIO_NO_MESG:
  1433. if ( su )
  1434. p->RIONoMessage = 1;
  1435. return su ? 0 : -EPERM;
  1436. case RIO_MESG:
  1437. if ( su )
  1438. p->RIONoMessage = 0;
  1439. return su ? 0 : -EPERM;
  1440. case RIO_WHAT_MESG:
  1441. if ( copyout( (caddr_t)&p->RIONoMessage, (int)arg,
  1442. sizeof(p->RIONoMessage) )==COPYFAIL ) {
  1443. rio_dprintk (RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
  1444. p->RIOError.Error = COPYOUT_FAILED;
  1445. return -EFAULT;
  1446. }
  1447. return 0;
  1448. case RIO_MEM_DUMP :
  1449. if (copyin((int)arg, (caddr_t)&SubCmd,
  1450. sizeof(struct SubCmdStruct)) == COPYFAIL) {
  1451. p->RIOError.Error = COPYIN_FAILED;
  1452. return -EFAULT;
  1453. }
  1454. rio_dprintk (RIO_DEBUG_CTRL, "RIO_MEM_DUMP host %d rup %d addr %x\n",
  1455. SubCmd.Host, SubCmd.Rup, SubCmd.Addr);
  1456. if (SubCmd.Rup >= MAX_RUP+LINKS_PER_UNIT ) {
  1457. p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
  1458. return -EINVAL;
  1459. }
  1460. if (SubCmd.Host >= p->RIONumHosts ) {
  1461. p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
  1462. return -EINVAL;
  1463. }
  1464. port = p->RIOHosts[SubCmd.Host].
  1465. UnixRups[SubCmd.Rup].BaseSysPort;
  1466. PortP = p->RIOPortp[port];
  1467. rio_spin_lock_irqsave(&PortP->portSem, flags);
  1468. if ( RIOPreemptiveCmd(p, PortP, MEMDUMP ) == RIO_FAIL ) {
  1469. rio_dprintk (RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n");
  1470. rio_spin_unlock_irqrestore( &PortP->portSem , flags);
  1471. return -EBUSY;
  1472. }
  1473. else
  1474. PortP->State |= RIO_BUSY;
  1475. rio_spin_unlock_irqrestore( &PortP->portSem , flags);
  1476. if ( copyout( (caddr_t)p->RIOMemDump, (int)arg,
  1477. MEMDUMP_SIZE) == COPYFAIL ) {
  1478. rio_dprintk (RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
  1479. p->RIOError.Error = COPYOUT_FAILED;
  1480. return -EFAULT;
  1481. }
  1482. return 0;
  1483. case RIO_TICK:
  1484. if ((int)arg < 0 || (int)arg >= p->RIONumHosts)
  1485. return -EINVAL;
  1486. rio_dprintk (RIO_DEBUG_CTRL, "Set interrupt for host %d\n", (int)arg);
  1487. WBYTE(p->RIOHosts[(int)arg].SetInt , 0xff);
  1488. return 0;
  1489. case RIO_TOCK:
  1490. if ((int)arg < 0 || (int)arg >= p->RIONumHosts)
  1491. return -EINVAL;
  1492. rio_dprintk (RIO_DEBUG_CTRL, "Clear interrupt for host %d\n", (int)arg);
  1493. WBYTE((p->RIOHosts[(int)arg].ResetInt) , 0xff);
  1494. return 0;
  1495. case RIO_READ_CHECK:
  1496. /* Check reads for pkts with data[0] the same */
  1497. p->RIOReadCheck = !p->RIOReadCheck;
  1498. if (copyout((caddr_t)&p->RIOReadCheck,(int)arg,
  1499. sizeof(uint))== COPYFAIL) {
  1500. p->RIOError.Error = COPYOUT_FAILED;
  1501. return -EFAULT;
  1502. }
  1503. return 0;
  1504. case RIO_READ_REGISTER :
  1505. if (copyin((int)arg, (caddr_t)&SubCmd,
  1506. sizeof(struct SubCmdStruct)) == COPYFAIL) {
  1507. p->RIOError.Error = COPYIN_FAILED;
  1508. return -EFAULT;
  1509. }
  1510. rio_dprintk (RIO_DEBUG_CTRL, "RIO_READ_REGISTER host %d rup %d port %d reg %x\n",
  1511. SubCmd.Host, SubCmd.Rup, SubCmd.Port, SubCmd.Addr);
  1512. if (SubCmd.Port > 511) {
  1513. rio_dprintk (RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n",
  1514. SubCmd.Port);
  1515. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  1516. return -EINVAL;
  1517. }
  1518. if (SubCmd.Rup >= MAX_RUP+LINKS_PER_UNIT ) {
  1519. p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
  1520. return -EINVAL;
  1521. }
  1522. if (SubCmd.Host >= p->RIONumHosts ) {
  1523. p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
  1524. return -EINVAL;
  1525. }
  1526. port = p->RIOHosts[SubCmd.Host].
  1527. UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port;
  1528. PortP = p->RIOPortp[port];
  1529. rio_spin_lock_irqsave(&PortP->portSem, flags);
  1530. if (RIOPreemptiveCmd(p, PortP, READ_REGISTER) == RIO_FAIL) {
  1531. rio_dprintk (RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n");
  1532. rio_spin_unlock_irqrestore( &PortP->portSem , flags);
  1533. return -EBUSY;
  1534. }
  1535. else
  1536. PortP->State |= RIO_BUSY;
  1537. rio_spin_unlock_irqrestore( &PortP->portSem , flags);
  1538. if (copyout((caddr_t)&p->CdRegister, (int)arg,
  1539. sizeof(uint)) == COPYFAIL ) {
  1540. rio_dprintk (RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
  1541. p->RIOError.Error = COPYOUT_FAILED;
  1542. return -EFAULT;
  1543. }
  1544. return 0;
  1545. /*
  1546. ** rio_make_dev: given port number (0-511) ORed with port type
  1547. ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
  1548. ** value to pass to mknod to create the correct device node.
  1549. */
  1550. case RIO_MAKE_DEV:
  1551. {
  1552. uint port = (uint)arg & RIO_MODEM_MASK;
  1553. switch ( (uint)arg & RIO_DEV_MASK ) {
  1554. case RIO_DEV_DIRECT:
  1555. arg = (caddr_t)drv_makedev(MAJOR(dev), port);
  1556. rio_dprintk (RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n",port, (int)arg);
  1557. return (int)arg;
  1558. case RIO_DEV_MODEM:
  1559. arg = (caddr_t)drv_makedev(MAJOR(dev), (port|RIO_MODEM_BIT) );
  1560. rio_dprintk (RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n",port, (int)arg);
  1561. return (int)arg;
  1562. case RIO_DEV_XPRINT:
  1563. arg = (caddr_t)drv_makedev(MAJOR(dev), port);
  1564. rio_dprintk (RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n",port, (int)arg);
  1565. return (int)arg;
  1566. }
  1567. rio_dprintk (RIO_DEBUG_CTRL, "MAKE Device is called\n");
  1568. return -EINVAL;
  1569. }
  1570. /*
  1571. ** rio_minor: given a dev_t from a stat() call, return
  1572. ** the port number (0-511) ORed with the port type
  1573. ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
  1574. */
  1575. case RIO_MINOR:
  1576. {
  1577. dev_t dv;
  1578. int mino;
  1579. dv = (dev_t)((int)arg);
  1580. mino = RIO_UNMODEM(dv);
  1581. if ( RIO_ISMODEM(dv) ) {
  1582. rio_dprintk (RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
  1583. arg = (caddr_t)(mino | RIO_DEV_MODEM);
  1584. }
  1585. else {
  1586. rio_dprintk (RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
  1587. arg = (caddr_t)(mino | RIO_DEV_DIRECT);
  1588. }
  1589. return (int)arg;
  1590. }
  1591. }
  1592. rio_dprintk (RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n",cmd);
  1593. p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
  1594. func_exit ();
  1595. return -EINVAL;
  1596. }
  1597. /*
  1598. ** Pre-emptive commands go on RUPs and are only one byte long.
  1599. */
  1600. int
  1601. RIOPreemptiveCmd(p, PortP, Cmd)
  1602. struct rio_info * p;
  1603. struct Port *PortP;
  1604. uchar Cmd;
  1605. {
  1606. struct CmdBlk *CmdBlkP;
  1607. struct PktCmd_M *PktCmdP;
  1608. int Ret;
  1609. ushort rup;
  1610. int port;
  1611. #ifdef CHECK
  1612. CheckPortP( PortP );
  1613. #endif
  1614. if ( PortP->State & RIO_DELETED ) {
  1615. rio_dprintk (RIO_DEBUG_CTRL, "Preemptive command to deleted RTA ignored\n");
  1616. return RIO_FAIL;
  1617. }
  1618. if (((int)((char)PortP->InUse) == -1) || ! (CmdBlkP = RIOGetCmdBlk()) ) {
  1619. rio_dprintk (RIO_DEBUG_CTRL, "Cannot allocate command block for command %d on port %d\n",
  1620. Cmd, PortP->PortNum);
  1621. return RIO_FAIL;
  1622. }
  1623. rio_dprintk (RIO_DEBUG_CTRL, "Command blk 0x%x - InUse now %d\n",
  1624. (int)CmdBlkP,PortP->InUse);
  1625. PktCmdP = (struct PktCmd_M *)&CmdBlkP->Packet.data[0];
  1626. CmdBlkP->Packet.src_unit = 0;
  1627. if (PortP->SecondBlock)
  1628. rup = PortP->ID2;
  1629. else
  1630. rup = PortP->RupNum;
  1631. CmdBlkP->Packet.dest_unit = rup;
  1632. CmdBlkP->Packet.src_port = COMMAND_RUP;
  1633. CmdBlkP->Packet.dest_port = COMMAND_RUP;
  1634. CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
  1635. CmdBlkP->PostFuncP = RIOUnUse;
  1636. CmdBlkP->PostArg = (int)PortP;
  1637. PktCmdP->Command = Cmd;
  1638. port = PortP->HostPort % (ushort)PORTS_PER_RTA;
  1639. /*
  1640. ** Index ports 8-15 for 2nd block of 16 port RTA.
  1641. */
  1642. if (PortP->SecondBlock)
  1643. port += (ushort) PORTS_PER_RTA;
  1644. PktCmdP->PhbNum = port;
  1645. switch ( Cmd ) {
  1646. case MEMDUMP:
  1647. rio_dprintk (RIO_DEBUG_CTRL, "Queue MEMDUMP command blk 0x%x (addr 0x%x)\n",
  1648. (int)CmdBlkP, (int)SubCmd.Addr);
  1649. PktCmdP->SubCommand = MEMDUMP;
  1650. PktCmdP->SubAddr = SubCmd.Addr;
  1651. break;
  1652. case FCLOSE:
  1653. rio_dprintk (RIO_DEBUG_CTRL, "Queue FCLOSE command blk 0x%x\n",(int)CmdBlkP);
  1654. break;
  1655. case READ_REGISTER:
  1656. rio_dprintk (RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) command blk 0x%x\n",
  1657. (int)SubCmd.Addr, (int)CmdBlkP);
  1658. PktCmdP->SubCommand = READ_REGISTER;
  1659. PktCmdP->SubAddr = SubCmd.Addr;
  1660. break;
  1661. case RESUME:
  1662. rio_dprintk (RIO_DEBUG_CTRL, "Queue RESUME command blk 0x%x\n",(int)CmdBlkP);
  1663. break;
  1664. case RFLUSH:
  1665. rio_dprintk (RIO_DEBUG_CTRL, "Queue RFLUSH command blk 0x%x\n",(int)CmdBlkP);
  1666. CmdBlkP->PostFuncP = RIORFlushEnable;
  1667. break;
  1668. case SUSPEND:
  1669. rio_dprintk (RIO_DEBUG_CTRL, "Queue SUSPEND command blk 0x%x\n",(int)CmdBlkP);
  1670. break;
  1671. case MGET :
  1672. rio_dprintk (RIO_DEBUG_CTRL, "Queue MGET command blk 0x%x\n", (int)CmdBlkP);
  1673. break;
  1674. case MSET :
  1675. case MBIC :
  1676. case MBIS :
  1677. CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
  1678. rio_dprintk (RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command blk 0x%x\n", (int)CmdBlkP);
  1679. break;
  1680. case WFLUSH:
  1681. /*
  1682. ** If we have queued up the maximum number of Write flushes
  1683. ** allowed then we should not bother sending any more to the
  1684. ** RTA.
  1685. */
  1686. if ((int)((char)PortP->WflushFlag) == (int)-1) {
  1687. rio_dprintk (RIO_DEBUG_CTRL, "Trashed WFLUSH, WflushFlag about to wrap!");
  1688. RIOFreeCmdBlk(CmdBlkP);
  1689. return(RIO_FAIL);
  1690. } else {
  1691. rio_dprintk (RIO_DEBUG_CTRL, "Queue WFLUSH command blk 0x%x\n",
  1692. (int)CmdBlkP);
  1693. CmdBlkP->PostFuncP = RIOWFlushMark;
  1694. }
  1695. break;
  1696. }
  1697. PortP->InUse++;
  1698. Ret = RIOQueueCmdBlk( PortP->HostP, rup, CmdBlkP );
  1699. return Ret;
  1700. }