rioctrl.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  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/uaccess.h>
  42. #include <linux/termios.h>
  43. #include <linux/serial.h>
  44. #include <linux/generic_serial.h>
  45. #include "linux_compat.h"
  46. #include "rio_linux.h"
  47. #include "pkt.h"
  48. #include "daemon.h"
  49. #include "rio.h"
  50. #include "riospace.h"
  51. #include "cmdpkt.h"
  52. #include "map.h"
  53. #include "rup.h"
  54. #include "port.h"
  55. #include "riodrvr.h"
  56. #include "rioinfo.h"
  57. #include "func.h"
  58. #include "errors.h"
  59. #include "pci.h"
  60. #include "parmmap.h"
  61. #include "unixrup.h"
  62. #include "board.h"
  63. #include "host.h"
  64. #include "phb.h"
  65. #include "link.h"
  66. #include "cmdblk.h"
  67. #include "route.h"
  68. #include "cirrus.h"
  69. #include "rioioctl.h"
  70. static struct LpbReq LpbReq;
  71. static struct RupReq RupReq;
  72. static struct PortReq PortReq;
  73. static struct HostReq HostReq; /* oh really? global? and no locking? */
  74. static struct HostDpRam HostDpRam;
  75. static struct DebugCtrl DebugCtrl;
  76. static struct Map MapEnt;
  77. static struct PortSetup PortSetup;
  78. static struct DownLoad DownLoad;
  79. static struct SendPack SendPack;
  80. /* static struct StreamInfo StreamInfo; */
  81. /* static char modemtable[RIO_PORTS]; */
  82. static struct SpecialRupCmd SpecialRupCmd;
  83. static struct PortParams PortParams;
  84. static struct portStats portStats;
  85. static struct SubCmdStruct {
  86. ushort Host;
  87. ushort Rup;
  88. ushort Port;
  89. ushort Addr;
  90. } SubCmd;
  91. struct PortTty {
  92. uint port;
  93. struct ttystatics Tty;
  94. };
  95. static struct PortTty PortTty;
  96. typedef struct ttystatics TERMIO;
  97. /*
  98. ** This table is used when the config.rio downloads bin code to the
  99. ** driver. We index the table using the product code, 0-F, and call
  100. ** the function pointed to by the entry, passing the information
  101. ** about the boot.
  102. ** The RIOBootCodeUNKNOWN entry is there to politely tell the calling
  103. ** process to bog off.
  104. */
  105. static int
  106. (*RIOBootTable[MAX_PRODUCT]) (struct rio_info *, struct DownLoad *) = {
  107. /* 0 */ RIOBootCodeHOST,
  108. /* Host Card */
  109. /* 1 */ RIOBootCodeRTA,
  110. /* RTA */
  111. };
  112. #define drv_makedev(maj, min) ((((uint) maj & 0xff) << 8) | ((uint) min & 0xff))
  113. static int copy_from_io(void __user *to, void __iomem *from, size_t size)
  114. {
  115. void *buf = kmalloc(size, GFP_KERNEL);
  116. int res = -ENOMEM;
  117. if (buf) {
  118. rio_memcpy_fromio(buf, from, size);
  119. res = copy_to_user(to, buf, size);
  120. kfree(buf);
  121. }
  122. return res;
  123. }
  124. int riocontrol(struct rio_info *p, dev_t dev, int cmd, unsigned long arg, int su)
  125. {
  126. uint Host; /* leave me unsigned! */
  127. uint port; /* and me! */
  128. struct Host *HostP;
  129. ushort loop;
  130. int Entry;
  131. struct Port *PortP;
  132. struct PKT __iomem *PacketP;
  133. int retval = 0;
  134. unsigned long flags;
  135. void __user *argp = (void __user *)arg;
  136. func_enter();
  137. /* Confuse the compiler to think that we've initialized these */
  138. Host = 0;
  139. PortP = NULL;
  140. rio_dprintk(RIO_DEBUG_CTRL, "control ioctl cmd: 0x%x arg: %p\n", cmd, argp);
  141. switch (cmd) {
  142. /*
  143. ** RIO_SET_TIMER
  144. **
  145. ** Change the value of the host card interrupt timer.
  146. ** If the host card number is -1 then all host cards are changed
  147. ** otherwise just the specified host card will be changed.
  148. */
  149. case RIO_SET_TIMER:
  150. rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_TIMER to %ldms\n", arg);
  151. {
  152. int host, value;
  153. host = (arg >> 16) & 0x0000FFFF;
  154. value = arg & 0x0000ffff;
  155. if (host == -1) {
  156. for (host = 0; host < p->RIONumHosts; host++) {
  157. if (p->RIOHosts[host].Flags == RC_RUNNING) {
  158. writew(value, &p->RIOHosts[host].ParmMapP->timer);
  159. }
  160. }
  161. } else if (host >= p->RIONumHosts) {
  162. return -EINVAL;
  163. } else {
  164. if (p->RIOHosts[host].Flags == RC_RUNNING) {
  165. writew(value, &p->RIOHosts[host].ParmMapP->timer);
  166. }
  167. }
  168. }
  169. return 0;
  170. case RIO_FOAD_RTA:
  171. rio_dprintk(RIO_DEBUG_CTRL, "RIO_FOAD_RTA\n");
  172. return RIOCommandRta(p, arg, RIOFoadRta);
  173. case RIO_ZOMBIE_RTA:
  174. rio_dprintk(RIO_DEBUG_CTRL, "RIO_ZOMBIE_RTA\n");
  175. return RIOCommandRta(p, arg, RIOZombieRta);
  176. case RIO_IDENTIFY_RTA:
  177. rio_dprintk(RIO_DEBUG_CTRL, "RIO_IDENTIFY_RTA\n");
  178. return RIOIdentifyRta(p, argp);
  179. case RIO_KILL_NEIGHBOUR:
  180. rio_dprintk(RIO_DEBUG_CTRL, "RIO_KILL_NEIGHBOUR\n");
  181. return RIOKillNeighbour(p, argp);
  182. case SPECIAL_RUP_CMD:
  183. {
  184. struct CmdBlk *CmdBlkP;
  185. rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD\n");
  186. if (copy_from_user(&SpecialRupCmd, argp, sizeof(SpecialRupCmd))) {
  187. rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD copy failed\n");
  188. p->RIOError.Error = COPYIN_FAILED;
  189. return -EFAULT;
  190. }
  191. CmdBlkP = RIOGetCmdBlk();
  192. if (!CmdBlkP) {
  193. rio_dprintk(RIO_DEBUG_CTRL, "SPECIAL_RUP_CMD GetCmdBlk failed\n");
  194. return -ENXIO;
  195. }
  196. CmdBlkP->Packet = SpecialRupCmd.Packet;
  197. if (SpecialRupCmd.Host >= p->RIONumHosts)
  198. SpecialRupCmd.Host = 0;
  199. rio_dprintk(RIO_DEBUG_CTRL, "Queue special rup command for host %d rup %d\n", SpecialRupCmd.Host, SpecialRupCmd.RupNum);
  200. if (RIOQueueCmdBlk(&p->RIOHosts[SpecialRupCmd.Host], SpecialRupCmd.RupNum, CmdBlkP) == RIO_FAIL) {
  201. printk(KERN_WARNING "rio: FAILED TO QUEUE SPECIAL RUP COMMAND\n");
  202. }
  203. return 0;
  204. }
  205. case RIO_DEBUG_MEM:
  206. return -EPERM;
  207. case RIO_ALL_MODEM:
  208. rio_dprintk(RIO_DEBUG_CTRL, "RIO_ALL_MODEM\n");
  209. p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
  210. return -EINVAL;
  211. case RIO_GET_TABLE:
  212. /*
  213. ** Read the routing table from the device driver to user space
  214. */
  215. rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE\n");
  216. if ((retval = RIOApel(p)) != 0)
  217. return retval;
  218. if (copy_to_user(argp, p->RIOConnectTable, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
  219. rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_TABLE copy failed\n");
  220. p->RIOError.Error = COPYOUT_FAILED;
  221. return -EFAULT;
  222. }
  223. {
  224. int entry;
  225. rio_dprintk(RIO_DEBUG_CTRL, "*****\nMAP ENTRIES\n");
  226. for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
  227. if ((p->RIOConnectTable[entry].ID == 0) && (p->RIOConnectTable[entry].HostUniqueNum == 0) && (p->RIOConnectTable[entry].RtaUniqueNum == 0))
  228. continue;
  229. rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum);
  230. rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum);
  231. rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID);
  232. rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2);
  233. rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Flags = 0x%x\n", entry, (int) p->RIOConnectTable[entry].Flags);
  234. rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.SysPort = 0x%x\n", entry, (int) p->RIOConnectTable[entry].SysPort);
  235. rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Unit);
  236. rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[0].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[0].Link);
  237. rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Unit);
  238. rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[1].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[1].Link);
  239. rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Unit);
  240. rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[2].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[2].Link);
  241. rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[3].Unit = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Unit);
  242. rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Top[4].Link = %x\n", entry, p->RIOConnectTable[entry].Topology[3].Link);
  243. rio_dprintk(RIO_DEBUG_CTRL, "Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name);
  244. }
  245. rio_dprintk(RIO_DEBUG_CTRL, "*****\nEND MAP ENTRIES\n");
  246. }
  247. p->RIOQuickCheck = NOT_CHANGED; /* a table has been gotten */
  248. return 0;
  249. case RIO_PUT_TABLE:
  250. /*
  251. ** Write the routing table to the device driver from user space
  252. */
  253. rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE\n");
  254. if (!su) {
  255. rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE !Root\n");
  256. p->RIOError.Error = NOT_SUPER_USER;
  257. return -EPERM;
  258. }
  259. if (copy_from_user(&p->RIOConnectTable[0], argp, TOTAL_MAP_ENTRIES * sizeof(struct Map))) {
  260. rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_TABLE copy failed\n");
  261. p->RIOError.Error = COPYIN_FAILED;
  262. return -EFAULT;
  263. }
  264. /*
  265. ***********************************
  266. {
  267. int entry;
  268. rio_dprint(RIO_DEBUG_CTRL, ("*****\nMAP ENTRIES\n") );
  269. for ( entry=0; entry<TOTAL_MAP_ENTRIES; entry++ )
  270. {
  271. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.HostUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].HostUniqueNum ) );
  272. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.RtaUniqueNum = 0x%x\n", entry, p->RIOConnectTable[entry].RtaUniqueNum ) );
  273. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID = 0x%x\n", entry, p->RIOConnectTable[entry].ID ) );
  274. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.ID2 = 0x%x\n", entry, p->RIOConnectTable[entry].ID2 ) );
  275. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Flags = 0x%x\n", entry, p->RIOConnectTable[entry].Flags ) );
  276. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.SysPort = 0x%x\n", entry, p->RIOConnectTable[entry].SysPort ) );
  277. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Unit ) );
  278. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[0].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[0].Link ) );
  279. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Unit ) );
  280. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[1].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[1].Link ) );
  281. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Unit ) );
  282. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[2].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[2].Link ) );
  283. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[3].Unit = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Unit ) );
  284. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Top[4].Link = %b\n", entry, p->RIOConnectTable[entry].Topology[3].Link ) );
  285. rio_dprint(RIO_DEBUG_CTRL, ("Map entry %d.Name = %s\n", entry, p->RIOConnectTable[entry].Name ) );
  286. }
  287. rio_dprint(RIO_DEBUG_CTRL, ("*****\nEND MAP ENTRIES\n") );
  288. }
  289. ***********************************
  290. */
  291. return RIONewTable(p);
  292. case RIO_GET_BINDINGS:
  293. /*
  294. ** Send bindings table, containing unique numbers of RTAs owned
  295. ** by this system to user space
  296. */
  297. rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS\n");
  298. if (!su) {
  299. rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS !Root\n");
  300. p->RIOError.Error = NOT_SUPER_USER;
  301. return -EPERM;
  302. }
  303. if (copy_to_user(argp, p->RIOBindTab, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
  304. rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_BINDINGS copy failed\n");
  305. p->RIOError.Error = COPYOUT_FAILED;
  306. return -EFAULT;
  307. }
  308. return 0;
  309. case RIO_PUT_BINDINGS:
  310. /*
  311. ** Receive a bindings table, containing unique numbers of RTAs owned
  312. ** by this system
  313. */
  314. rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS\n");
  315. if (!su) {
  316. rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS !Root\n");
  317. p->RIOError.Error = NOT_SUPER_USER;
  318. return -EPERM;
  319. }
  320. if (copy_from_user(&p->RIOBindTab[0], argp, (sizeof(ulong) * MAX_RTA_BINDINGS))) {
  321. rio_dprintk(RIO_DEBUG_CTRL, "RIO_PUT_BINDINGS copy failed\n");
  322. p->RIOError.Error = COPYIN_FAILED;
  323. return -EFAULT;
  324. }
  325. return 0;
  326. case RIO_BIND_RTA:
  327. {
  328. int EmptySlot = -1;
  329. /*
  330. ** Bind this RTA to host, so that it will be booted by
  331. ** host in 'boot owned RTAs' mode.
  332. */
  333. rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA\n");
  334. if (!su) {
  335. rio_dprintk(RIO_DEBUG_CTRL, "RIO_BIND_RTA !Root\n");
  336. p->RIOError.Error = NOT_SUPER_USER;
  337. return -EPERM;
  338. }
  339. for (Entry = 0; Entry < MAX_RTA_BINDINGS; Entry++) {
  340. if ((EmptySlot == -1) && (p->RIOBindTab[Entry] == 0L))
  341. EmptySlot = Entry;
  342. else if (p->RIOBindTab[Entry] == arg) {
  343. /*
  344. ** Already exists - delete
  345. */
  346. p->RIOBindTab[Entry] = 0L;
  347. rio_dprintk(RIO_DEBUG_CTRL, "Removing Rta %ld from p->RIOBindTab\n", arg);
  348. return 0;
  349. }
  350. }
  351. /*
  352. ** Dosen't exist - add
  353. */
  354. if (EmptySlot != -1) {
  355. p->RIOBindTab[EmptySlot] = arg;
  356. rio_dprintk(RIO_DEBUG_CTRL, "Adding Rta %lx to p->RIOBindTab\n", arg);
  357. } else {
  358. rio_dprintk(RIO_DEBUG_CTRL, "p->RIOBindTab full! - Rta %lx not added\n", arg);
  359. return -ENOMEM;
  360. }
  361. return 0;
  362. }
  363. case RIO_RESUME:
  364. rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME\n");
  365. port = arg;
  366. if ((port < 0) || (port > 511)) {
  367. rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Bad port number %d\n", port);
  368. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  369. return -EINVAL;
  370. }
  371. PortP = p->RIOPortp[port];
  372. if (!PortP->Mapped) {
  373. rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not mapped\n", port);
  374. p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
  375. return -EINVAL;
  376. }
  377. if (!(PortP->State & (RIO_LOPEN | RIO_MOPEN))) {
  378. rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d not open\n", port);
  379. return -EINVAL;
  380. }
  381. rio_spin_lock_irqsave(&PortP->portSem, flags);
  382. if (RIOPreemptiveCmd(p, (p->RIOPortp[port]), RIOC_RESUME) ==
  383. RIO_FAIL) {
  384. rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME failed\n");
  385. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  386. return -EBUSY;
  387. } else {
  388. rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESUME: Port %d resumed\n", port);
  389. PortP->State |= RIO_BUSY;
  390. }
  391. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  392. return retval;
  393. case RIO_ASSIGN_RTA:
  394. rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA\n");
  395. if (!su) {
  396. rio_dprintk(RIO_DEBUG_CTRL, "RIO_ASSIGN_RTA !Root\n");
  397. p->RIOError.Error = NOT_SUPER_USER;
  398. return -EPERM;
  399. }
  400. if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
  401. rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
  402. p->RIOError.Error = COPYIN_FAILED;
  403. return -EFAULT;
  404. }
  405. return RIOAssignRta(p, &MapEnt);
  406. case RIO_CHANGE_NAME:
  407. rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME\n");
  408. if (!su) {
  409. rio_dprintk(RIO_DEBUG_CTRL, "RIO_CHANGE_NAME !Root\n");
  410. p->RIOError.Error = NOT_SUPER_USER;
  411. return -EPERM;
  412. }
  413. if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
  414. rio_dprintk(RIO_DEBUG_CTRL, "Copy from user space failed\n");
  415. p->RIOError.Error = COPYIN_FAILED;
  416. return -EFAULT;
  417. }
  418. return RIOChangeName(p, &MapEnt);
  419. case RIO_DELETE_RTA:
  420. rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA\n");
  421. if (!su) {
  422. rio_dprintk(RIO_DEBUG_CTRL, "RIO_DELETE_RTA !Root\n");
  423. p->RIOError.Error = NOT_SUPER_USER;
  424. return -EPERM;
  425. }
  426. if (copy_from_user(&MapEnt, argp, sizeof(MapEnt))) {
  427. rio_dprintk(RIO_DEBUG_CTRL, "Copy from data space failed\n");
  428. p->RIOError.Error = COPYIN_FAILED;
  429. return -EFAULT;
  430. }
  431. return RIODeleteRta(p, &MapEnt);
  432. case RIO_QUICK_CHECK:
  433. if (copy_to_user(argp, &p->RIORtaDisCons, sizeof(unsigned int))) {
  434. p->RIOError.Error = COPYOUT_FAILED;
  435. return -EFAULT;
  436. }
  437. return 0;
  438. case RIO_LAST_ERROR:
  439. if (copy_to_user(argp, &p->RIOError, sizeof(struct Error)))
  440. return -EFAULT;
  441. return 0;
  442. case RIO_GET_LOG:
  443. rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_LOG\n");
  444. return -EINVAL;
  445. case RIO_GET_MODTYPE:
  446. if (copy_from_user(&port, argp, sizeof(unsigned int))) {
  447. p->RIOError.Error = COPYIN_FAILED;
  448. return -EFAULT;
  449. }
  450. rio_dprintk(RIO_DEBUG_CTRL, "Get module type for port %d\n", port);
  451. if (port < 0 || port > 511) {
  452. rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Bad port number %d\n", port);
  453. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  454. return -EINVAL;
  455. }
  456. PortP = (p->RIOPortp[port]);
  457. if (!PortP->Mapped) {
  458. rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_MODTYPE: Port %d not mapped\n", port);
  459. p->RIOError.Error = PORT_NOT_MAPPED_INTO_SYSTEM;
  460. return -EINVAL;
  461. }
  462. /*
  463. ** Return module type of port
  464. */
  465. port = PortP->HostP->UnixRups[PortP->RupNum].ModTypes;
  466. if (copy_to_user(argp, &port, sizeof(unsigned int))) {
  467. p->RIOError.Error = COPYOUT_FAILED;
  468. return -EFAULT;
  469. }
  470. return (0);
  471. case RIO_BLOCK_OPENS:
  472. rio_dprintk(RIO_DEBUG_CTRL, "Opens block until booted\n");
  473. for (Entry = 0; Entry < RIO_PORTS; Entry++) {
  474. rio_spin_lock_irqsave(&PortP->portSem, flags);
  475. p->RIOPortp[Entry]->WaitUntilBooted = 1;
  476. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  477. }
  478. return 0;
  479. case RIO_SETUP_PORTS:
  480. rio_dprintk(RIO_DEBUG_CTRL, "Setup ports\n");
  481. if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) {
  482. p->RIOError.Error = COPYIN_FAILED;
  483. rio_dprintk(RIO_DEBUG_CTRL, "EFAULT");
  484. return -EFAULT;
  485. }
  486. if (PortSetup.From > PortSetup.To || PortSetup.To >= RIO_PORTS) {
  487. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  488. rio_dprintk(RIO_DEBUG_CTRL, "ENXIO");
  489. return -ENXIO;
  490. }
  491. if (PortSetup.XpCps > p->RIOConf.MaxXpCps || PortSetup.XpCps < p->RIOConf.MinXpCps) {
  492. p->RIOError.Error = XPRINT_CPS_OUT_OF_RANGE;
  493. rio_dprintk(RIO_DEBUG_CTRL, "EINVAL");
  494. return -EINVAL;
  495. }
  496. if (!p->RIOPortp) {
  497. printk(KERN_ERR "rio: No p->RIOPortp array!\n");
  498. rio_dprintk(RIO_DEBUG_CTRL, "No p->RIOPortp array!\n");
  499. return -EIO;
  500. }
  501. rio_dprintk(RIO_DEBUG_CTRL, "entering loop (%d %d)!\n", PortSetup.From, PortSetup.To);
  502. for (loop = PortSetup.From; loop <= PortSetup.To; loop++) {
  503. rio_dprintk(RIO_DEBUG_CTRL, "in loop (%d)!\n", loop);
  504. }
  505. rio_dprintk(RIO_DEBUG_CTRL, "after loop (%d)!\n", loop);
  506. rio_dprintk(RIO_DEBUG_CTRL, "Retval:%x\n", retval);
  507. return retval;
  508. case RIO_GET_PORT_SETUP:
  509. rio_dprintk(RIO_DEBUG_CTRL, "Get port setup\n");
  510. if (copy_from_user(&PortSetup, argp, sizeof(PortSetup))) {
  511. p->RIOError.Error = COPYIN_FAILED;
  512. return -EFAULT;
  513. }
  514. if (PortSetup.From >= RIO_PORTS) {
  515. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  516. return -ENXIO;
  517. }
  518. port = PortSetup.To = PortSetup.From;
  519. PortSetup.IxAny = (p->RIOPortp[port]->Config & RIO_IXANY) ? 1 : 0;
  520. PortSetup.IxOn = (p->RIOPortp[port]->Config & RIO_IXON) ? 1 : 0;
  521. PortSetup.Drain = (p->RIOPortp[port]->Config & RIO_WAITDRAIN) ? 1 : 0;
  522. PortSetup.Store = p->RIOPortp[port]->Store;
  523. PortSetup.Lock = p->RIOPortp[port]->Lock;
  524. PortSetup.XpCps = p->RIOPortp[port]->Xprint.XpCps;
  525. memcpy(PortSetup.XpOn, p->RIOPortp[port]->Xprint.XpOn, MAX_XP_CTRL_LEN);
  526. memcpy(PortSetup.XpOff, p->RIOPortp[port]->Xprint.XpOff, MAX_XP_CTRL_LEN);
  527. PortSetup.XpOn[MAX_XP_CTRL_LEN - 1] = '\0';
  528. PortSetup.XpOff[MAX_XP_CTRL_LEN - 1] = '\0';
  529. if (copy_to_user(argp, &PortSetup, sizeof(PortSetup))) {
  530. p->RIOError.Error = COPYOUT_FAILED;
  531. return -EFAULT;
  532. }
  533. return retval;
  534. case RIO_GET_PORT_PARAMS:
  535. rio_dprintk(RIO_DEBUG_CTRL, "Get port params\n");
  536. if (copy_from_user(&PortParams, argp, sizeof(struct PortParams))) {
  537. p->RIOError.Error = COPYIN_FAILED;
  538. return -EFAULT;
  539. }
  540. if (PortParams.Port >= RIO_PORTS) {
  541. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  542. return -ENXIO;
  543. }
  544. PortP = (p->RIOPortp[PortParams.Port]);
  545. PortParams.Config = PortP->Config;
  546. PortParams.State = PortP->State;
  547. rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortParams.Port);
  548. if (copy_to_user(argp, &PortParams, sizeof(struct PortParams))) {
  549. p->RIOError.Error = COPYOUT_FAILED;
  550. return -EFAULT;
  551. }
  552. return retval;
  553. case RIO_GET_PORT_TTY:
  554. rio_dprintk(RIO_DEBUG_CTRL, "Get port tty\n");
  555. if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) {
  556. p->RIOError.Error = COPYIN_FAILED;
  557. return -EFAULT;
  558. }
  559. if (PortTty.port >= RIO_PORTS) {
  560. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  561. return -ENXIO;
  562. }
  563. rio_dprintk(RIO_DEBUG_CTRL, "Port %d\n", PortTty.port);
  564. PortP = (p->RIOPortp[PortTty.port]);
  565. if (copy_to_user(argp, &PortTty, sizeof(struct PortTty))) {
  566. p->RIOError.Error = COPYOUT_FAILED;
  567. return -EFAULT;
  568. }
  569. return retval;
  570. case RIO_SET_PORT_TTY:
  571. if (copy_from_user(&PortTty, argp, sizeof(struct PortTty))) {
  572. p->RIOError.Error = COPYIN_FAILED;
  573. return -EFAULT;
  574. }
  575. rio_dprintk(RIO_DEBUG_CTRL, "Set port %d tty\n", PortTty.port);
  576. if (PortTty.port >= (ushort) RIO_PORTS) {
  577. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  578. return -ENXIO;
  579. }
  580. PortP = (p->RIOPortp[PortTty.port]);
  581. RIOParam(PortP, RIOC_CONFIG, PortP->State & RIO_MODEM,
  582. OK_TO_SLEEP);
  583. return retval;
  584. case RIO_SET_PORT_PARAMS:
  585. rio_dprintk(RIO_DEBUG_CTRL, "Set port params\n");
  586. if (copy_from_user(&PortParams, argp, sizeof(PortParams))) {
  587. p->RIOError.Error = COPYIN_FAILED;
  588. return -EFAULT;
  589. }
  590. if (PortParams.Port >= (ushort) RIO_PORTS) {
  591. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  592. return -ENXIO;
  593. }
  594. PortP = (p->RIOPortp[PortParams.Port]);
  595. rio_spin_lock_irqsave(&PortP->portSem, flags);
  596. PortP->Config = PortParams.Config;
  597. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  598. return retval;
  599. case RIO_GET_PORT_STATS:
  600. rio_dprintk(RIO_DEBUG_CTRL, "RIO_GET_PORT_STATS\n");
  601. if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
  602. p->RIOError.Error = COPYIN_FAILED;
  603. return -EFAULT;
  604. }
  605. if (portStats.port < 0 || portStats.port >= RIO_PORTS) {
  606. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  607. return -ENXIO;
  608. }
  609. PortP = (p->RIOPortp[portStats.port]);
  610. portStats.gather = PortP->statsGather;
  611. portStats.txchars = PortP->txchars;
  612. portStats.rxchars = PortP->rxchars;
  613. portStats.opens = PortP->opens;
  614. portStats.closes = PortP->closes;
  615. portStats.ioctls = PortP->ioctls;
  616. if (copy_to_user(argp, &portStats, sizeof(struct portStats))) {
  617. p->RIOError.Error = COPYOUT_FAILED;
  618. return -EFAULT;
  619. }
  620. return retval;
  621. case RIO_RESET_PORT_STATS:
  622. port = arg;
  623. rio_dprintk(RIO_DEBUG_CTRL, "RIO_RESET_PORT_STATS\n");
  624. if (port >= RIO_PORTS) {
  625. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  626. return -ENXIO;
  627. }
  628. PortP = (p->RIOPortp[port]);
  629. rio_spin_lock_irqsave(&PortP->portSem, flags);
  630. PortP->txchars = 0;
  631. PortP->rxchars = 0;
  632. PortP->opens = 0;
  633. PortP->closes = 0;
  634. PortP->ioctls = 0;
  635. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  636. return retval;
  637. case RIO_GATHER_PORT_STATS:
  638. rio_dprintk(RIO_DEBUG_CTRL, "RIO_GATHER_PORT_STATS\n");
  639. if (copy_from_user(&portStats, argp, sizeof(struct portStats))) {
  640. p->RIOError.Error = COPYIN_FAILED;
  641. return -EFAULT;
  642. }
  643. if (portStats.port < 0 || portStats.port >= RIO_PORTS) {
  644. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  645. return -ENXIO;
  646. }
  647. PortP = (p->RIOPortp[portStats.port]);
  648. rio_spin_lock_irqsave(&PortP->portSem, flags);
  649. PortP->statsGather = portStats.gather;
  650. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  651. return retval;
  652. case RIO_READ_CONFIG:
  653. rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_CONFIG\n");
  654. if (copy_to_user(argp, &p->RIOConf, sizeof(struct Conf))) {
  655. p->RIOError.Error = COPYOUT_FAILED;
  656. return -EFAULT;
  657. }
  658. return retval;
  659. case RIO_SET_CONFIG:
  660. rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_CONFIG\n");
  661. if (!su) {
  662. p->RIOError.Error = NOT_SUPER_USER;
  663. return -EPERM;
  664. }
  665. if (copy_from_user(&p->RIOConf, argp, sizeof(struct Conf))) {
  666. p->RIOError.Error = COPYIN_FAILED;
  667. return -EFAULT;
  668. }
  669. /*
  670. ** move a few value around
  671. */
  672. for (Host = 0; Host < p->RIONumHosts; Host++)
  673. if ((p->RIOHosts[Host].Flags & RUN_STATE) == RC_RUNNING)
  674. writew(p->RIOConf.Timer, &p->RIOHosts[Host].ParmMapP->timer);
  675. return retval;
  676. case RIO_START_POLLER:
  677. rio_dprintk(RIO_DEBUG_CTRL, "RIO_START_POLLER\n");
  678. return -EINVAL;
  679. case RIO_STOP_POLLER:
  680. rio_dprintk(RIO_DEBUG_CTRL, "RIO_STOP_POLLER\n");
  681. if (!su) {
  682. p->RIOError.Error = NOT_SUPER_USER;
  683. return -EPERM;
  684. }
  685. p->RIOPolling = NOT_POLLING;
  686. return retval;
  687. case RIO_SETDEBUG:
  688. case RIO_GETDEBUG:
  689. rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG/RIO_GETDEBUG\n");
  690. if (copy_from_user(&DebugCtrl, argp, sizeof(DebugCtrl))) {
  691. p->RIOError.Error = COPYIN_FAILED;
  692. return -EFAULT;
  693. }
  694. if (DebugCtrl.SysPort == NO_PORT) {
  695. if (cmd == RIO_SETDEBUG) {
  696. if (!su) {
  697. p->RIOError.Error = NOT_SUPER_USER;
  698. return -EPERM;
  699. }
  700. p->rio_debug = DebugCtrl.Debug;
  701. p->RIODebugWait = DebugCtrl.Wait;
  702. rio_dprintk(RIO_DEBUG_CTRL, "Set global debug to 0x%x set wait to 0x%x\n", p->rio_debug, p->RIODebugWait);
  703. } else {
  704. rio_dprintk(RIO_DEBUG_CTRL, "Get global debug 0x%x wait 0x%x\n", p->rio_debug, p->RIODebugWait);
  705. DebugCtrl.Debug = p->rio_debug;
  706. DebugCtrl.Wait = p->RIODebugWait;
  707. if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
  708. rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
  709. p->RIOError.Error = COPYOUT_FAILED;
  710. return -EFAULT;
  711. }
  712. }
  713. } else if (DebugCtrl.SysPort >= RIO_PORTS && DebugCtrl.SysPort != NO_PORT) {
  714. rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET/GET DEBUG: bad port number %d\n", DebugCtrl.SysPort);
  715. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  716. return -ENXIO;
  717. } else if (cmd == RIO_SETDEBUG) {
  718. if (!su) {
  719. p->RIOError.Error = NOT_SUPER_USER;
  720. return -EPERM;
  721. }
  722. rio_spin_lock_irqsave(&PortP->portSem, flags);
  723. p->RIOPortp[DebugCtrl.SysPort]->Debug = DebugCtrl.Debug;
  724. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  725. rio_dprintk(RIO_DEBUG_CTRL, "RIO_SETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
  726. } else {
  727. rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG 0x%x\n", p->RIOPortp[DebugCtrl.SysPort]->Debug);
  728. DebugCtrl.Debug = p->RIOPortp[DebugCtrl.SysPort]->Debug;
  729. if (copy_to_user(argp, &DebugCtrl, sizeof(DebugCtrl))) {
  730. rio_dprintk(RIO_DEBUG_CTRL, "RIO_GETDEBUG: Bad copy to user space\n");
  731. p->RIOError.Error = COPYOUT_FAILED;
  732. return -EFAULT;
  733. }
  734. }
  735. return retval;
  736. case RIO_VERSID:
  737. /*
  738. ** Enquire about the release and version.
  739. ** We return MAX_VERSION_LEN bytes, being a
  740. ** textual null terminated string.
  741. */
  742. rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID\n");
  743. if (copy_to_user(argp, RIOVersid(), sizeof(struct rioVersion))) {
  744. rio_dprintk(RIO_DEBUG_CTRL, "RIO_VERSID: Bad copy to user space (host=%d)\n", Host);
  745. p->RIOError.Error = COPYOUT_FAILED;
  746. return -EFAULT;
  747. }
  748. return retval;
  749. case RIO_NUM_HOSTS:
  750. /*
  751. ** Enquire as to the number of hosts located
  752. ** at init time.
  753. */
  754. rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS\n");
  755. if (copy_to_user(argp, &p->RIONumHosts, sizeof(p->RIONumHosts))) {
  756. rio_dprintk(RIO_DEBUG_CTRL, "RIO_NUM_HOSTS: Bad copy to user space\n");
  757. p->RIOError.Error = COPYOUT_FAILED;
  758. return -EFAULT;
  759. }
  760. return retval;
  761. case RIO_HOST_FOAD:
  762. /*
  763. ** Kill host. This may not be in the final version...
  764. */
  765. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD %ld\n", arg);
  766. if (!su) {
  767. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_FOAD: Not super user\n");
  768. p->RIOError.Error = NOT_SUPER_USER;
  769. return -EPERM;
  770. }
  771. p->RIOHalted = 1;
  772. p->RIOSystemUp = 0;
  773. for (Host = 0; Host < p->RIONumHosts; Host++) {
  774. (void) RIOBoardTest(p->RIOHosts[Host].PaddrP, p->RIOHosts[Host].Caddr, p->RIOHosts[Host].Type, p->RIOHosts[Host].Slot);
  775. memset(&p->RIOHosts[Host].Flags, 0, ((char *) &p->RIOHosts[Host].____end_marker____) - ((char *) &p->RIOHosts[Host].Flags));
  776. p->RIOHosts[Host].Flags = RC_WAITING;
  777. }
  778. RIOFoadWakeup(p);
  779. p->RIONumBootPkts = 0;
  780. p->RIOBooting = 0;
  781. printk("HEEEEELP!\n");
  782. for (loop = 0; loop < RIO_PORTS; loop++) {
  783. spin_lock_init(&p->RIOPortp[loop]->portSem);
  784. p->RIOPortp[loop]->InUse = NOT_INUSE;
  785. }
  786. p->RIOSystemUp = 0;
  787. return retval;
  788. case RIO_DOWNLOAD:
  789. rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD\n");
  790. if (!su) {
  791. rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Not super user\n");
  792. p->RIOError.Error = NOT_SUPER_USER;
  793. return -EPERM;
  794. }
  795. if (copy_from_user(&DownLoad, argp, sizeof(DownLoad))) {
  796. rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Copy in from user space failed\n");
  797. p->RIOError.Error = COPYIN_FAILED;
  798. return -EFAULT;
  799. }
  800. rio_dprintk(RIO_DEBUG_CTRL, "Copied in download code for product code 0x%x\n", DownLoad.ProductCode);
  801. /*
  802. ** It is important that the product code is an unsigned object!
  803. */
  804. if (DownLoad.ProductCode > MAX_PRODUCT) {
  805. rio_dprintk(RIO_DEBUG_CTRL, "RIO_DOWNLOAD: Bad product code %d passed\n", DownLoad.ProductCode);
  806. p->RIOError.Error = NO_SUCH_PRODUCT;
  807. return -ENXIO;
  808. }
  809. /*
  810. ** do something!
  811. */
  812. retval = (*(RIOBootTable[DownLoad.ProductCode])) (p, &DownLoad);
  813. /* <-- Panic */
  814. p->RIOHalted = 0;
  815. /*
  816. ** and go back, content with a job well completed.
  817. */
  818. return retval;
  819. case RIO_PARMS:
  820. {
  821. unsigned int host;
  822. if (copy_from_user(&host, argp, sizeof(host))) {
  823. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
  824. p->RIOError.Error = COPYIN_FAILED;
  825. return -EFAULT;
  826. }
  827. /*
  828. ** Fetch the parmmap
  829. */
  830. rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS\n");
  831. if (copy_from_io(argp, p->RIOHosts[host].ParmMapP, sizeof(PARM_MAP))) {
  832. p->RIOError.Error = COPYOUT_FAILED;
  833. rio_dprintk(RIO_DEBUG_CTRL, "RIO_PARMS: Copy out to user space failed\n");
  834. return -EFAULT;
  835. }
  836. }
  837. return retval;
  838. case RIO_HOST_REQ:
  839. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ\n");
  840. if (copy_from_user(&HostReq, argp, sizeof(HostReq))) {
  841. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Copy in from user space failed\n");
  842. p->RIOError.Error = COPYIN_FAILED;
  843. return -EFAULT;
  844. }
  845. if (HostReq.HostNum >= p->RIONumHosts) {
  846. p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
  847. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Illegal host number %d\n", HostReq.HostNum);
  848. return -ENXIO;
  849. }
  850. rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostReq.HostNum);
  851. if (copy_to_user(HostReq.HostP, &p->RIOHosts[HostReq.HostNum], sizeof(struct Host))) {
  852. p->RIOError.Error = COPYOUT_FAILED;
  853. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_REQ: Bad copy to user space\n");
  854. return -EFAULT;
  855. }
  856. return retval;
  857. case RIO_HOST_DPRAM:
  858. rio_dprintk(RIO_DEBUG_CTRL, "Request for DPRAM\n");
  859. if (copy_from_user(&HostDpRam, argp, sizeof(HostDpRam))) {
  860. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Copy in from user space failed\n");
  861. p->RIOError.Error = COPYIN_FAILED;
  862. return -EFAULT;
  863. }
  864. if (HostDpRam.HostNum >= p->RIONumHosts) {
  865. p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
  866. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Illegal host number %d\n", HostDpRam.HostNum);
  867. return -ENXIO;
  868. }
  869. rio_dprintk(RIO_DEBUG_CTRL, "Request for host %d\n", HostDpRam.HostNum);
  870. if (p->RIOHosts[HostDpRam.HostNum].Type == RIO_PCI) {
  871. int off;
  872. /* It's hardware like this that really gets on my tits. */
  873. static unsigned char copy[sizeof(struct DpRam)];
  874. for (off = 0; off < sizeof(struct DpRam); off++)
  875. copy[off] = readb(p->RIOHosts[HostDpRam.HostNum].Caddr + off);
  876. if (copy_to_user(HostDpRam.DpRamP, copy, sizeof(struct DpRam))) {
  877. p->RIOError.Error = COPYOUT_FAILED;
  878. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
  879. return -EFAULT;
  880. }
  881. } else if (copy_from_io(HostDpRam.DpRamP, p->RIOHosts[HostDpRam.HostNum].Caddr, sizeof(struct DpRam))) {
  882. p->RIOError.Error = COPYOUT_FAILED;
  883. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_DPRAM: Bad copy to user space\n");
  884. return -EFAULT;
  885. }
  886. return retval;
  887. case RIO_SET_BUSY:
  888. rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY\n");
  889. if (arg > 511) {
  890. rio_dprintk(RIO_DEBUG_CTRL, "RIO_SET_BUSY: Bad port number %ld\n", arg);
  891. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  892. return -EINVAL;
  893. }
  894. rio_spin_lock_irqsave(&PortP->portSem, flags);
  895. p->RIOPortp[arg]->State |= RIO_BUSY;
  896. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  897. return retval;
  898. case RIO_HOST_PORT:
  899. /*
  900. ** The daemon want port information
  901. ** (probably for debug reasons)
  902. */
  903. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT\n");
  904. if (copy_from_user(&PortReq, argp, sizeof(PortReq))) {
  905. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Copy in from user space failed\n");
  906. p->RIOError.Error = COPYIN_FAILED;
  907. return -EFAULT;
  908. }
  909. if (PortReq.SysPort >= RIO_PORTS) { /* SysPort is unsigned */
  910. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Illegal port number %d\n", PortReq.SysPort);
  911. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  912. return -ENXIO;
  913. }
  914. rio_dprintk(RIO_DEBUG_CTRL, "Request for port %d\n", PortReq.SysPort);
  915. if (copy_to_user(PortReq.PortP, p->RIOPortp[PortReq.SysPort], sizeof(struct Port))) {
  916. p->RIOError.Error = COPYOUT_FAILED;
  917. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_PORT: Bad copy to user space\n");
  918. return -EFAULT;
  919. }
  920. return retval;
  921. case RIO_HOST_RUP:
  922. /*
  923. ** The daemon want rup information
  924. ** (probably for debug reasons)
  925. */
  926. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP\n");
  927. if (copy_from_user(&RupReq, argp, sizeof(RupReq))) {
  928. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Copy in from user space failed\n");
  929. p->RIOError.Error = COPYIN_FAILED;
  930. return -EFAULT;
  931. }
  932. if (RupReq.HostNum >= p->RIONumHosts) { /* host is unsigned */
  933. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal host number %d\n", RupReq.HostNum);
  934. p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
  935. return -ENXIO;
  936. }
  937. if (RupReq.RupNum >= MAX_RUP + LINKS_PER_UNIT) { /* eek! */
  938. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Illegal rup number %d\n", RupReq.RupNum);
  939. p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
  940. return -EINVAL;
  941. }
  942. HostP = &p->RIOHosts[RupReq.HostNum];
  943. if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
  944. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Host %d not running\n", RupReq.HostNum);
  945. p->RIOError.Error = HOST_NOT_RUNNING;
  946. return -EIO;
  947. }
  948. rio_dprintk(RIO_DEBUG_CTRL, "Request for rup %d from host %d\n", RupReq.RupNum, RupReq.HostNum);
  949. if (copy_from_io(RupReq.RupP, HostP->UnixRups[RupReq.RupNum].RupP, sizeof(struct RUP))) {
  950. p->RIOError.Error = COPYOUT_FAILED;
  951. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_RUP: Bad copy to user space\n");
  952. return -EFAULT;
  953. }
  954. return retval;
  955. case RIO_HOST_LPB:
  956. /*
  957. ** The daemon want lpb information
  958. ** (probably for debug reasons)
  959. */
  960. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB\n");
  961. if (copy_from_user(&LpbReq, argp, sizeof(LpbReq))) {
  962. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy from user space\n");
  963. p->RIOError.Error = COPYIN_FAILED;
  964. return -EFAULT;
  965. }
  966. if (LpbReq.Host >= p->RIONumHosts) { /* host is unsigned */
  967. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal host number %d\n", LpbReq.Host);
  968. p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
  969. return -ENXIO;
  970. }
  971. if (LpbReq.Link >= LINKS_PER_UNIT) { /* eek! */
  972. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Illegal link number %d\n", LpbReq.Link);
  973. p->RIOError.Error = LINK_NUMBER_OUT_OF_RANGE;
  974. return -EINVAL;
  975. }
  976. HostP = &p->RIOHosts[LpbReq.Host];
  977. if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
  978. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Host %d not running\n", LpbReq.Host);
  979. p->RIOError.Error = HOST_NOT_RUNNING;
  980. return -EIO;
  981. }
  982. rio_dprintk(RIO_DEBUG_CTRL, "Request for lpb %d from host %d\n", LpbReq.Link, LpbReq.Host);
  983. if (copy_from_io(LpbReq.LpbP, &HostP->LinkStrP[LpbReq.Link], sizeof(struct LPB))) {
  984. rio_dprintk(RIO_DEBUG_CTRL, "RIO_HOST_LPB: Bad copy to user space\n");
  985. p->RIOError.Error = COPYOUT_FAILED;
  986. return -EFAULT;
  987. }
  988. return retval;
  989. /*
  990. ** Here 3 IOCTL's that allow us to change the way in which
  991. ** rio logs errors. send them just to syslog or send them
  992. ** to both syslog and console or send them to just the console.
  993. **
  994. ** See RioStrBuf() in util.c for the other half.
  995. */
  996. case RIO_SYSLOG_ONLY:
  997. p->RIOPrintLogState = PRINT_TO_LOG; /* Just syslog */
  998. return 0;
  999. case RIO_SYSLOG_CONS:
  1000. p->RIOPrintLogState = PRINT_TO_LOG_CONS; /* syslog and console */
  1001. return 0;
  1002. case RIO_CONS_ONLY:
  1003. p->RIOPrintLogState = PRINT_TO_CONS; /* Just console */
  1004. return 0;
  1005. case RIO_SIGNALS_ON:
  1006. if (p->RIOSignalProcess) {
  1007. p->RIOError.Error = SIGNALS_ALREADY_SET;
  1008. return -EBUSY;
  1009. }
  1010. /* FIXME: PID tracking */
  1011. p->RIOSignalProcess = current->pid;
  1012. p->RIOPrintDisabled = DONT_PRINT;
  1013. return retval;
  1014. case RIO_SIGNALS_OFF:
  1015. if (p->RIOSignalProcess != current->pid) {
  1016. p->RIOError.Error = NOT_RECEIVING_PROCESS;
  1017. return -EPERM;
  1018. }
  1019. rio_dprintk(RIO_DEBUG_CTRL, "Clear signal process to zero\n");
  1020. p->RIOSignalProcess = 0;
  1021. return retval;
  1022. case RIO_SET_BYTE_MODE:
  1023. for (Host = 0; Host < p->RIONumHosts; Host++)
  1024. if (p->RIOHosts[Host].Type == RIO_AT)
  1025. p->RIOHosts[Host].Mode &= ~WORD_OPERATION;
  1026. return retval;
  1027. case RIO_SET_WORD_MODE:
  1028. for (Host = 0; Host < p->RIONumHosts; Host++)
  1029. if (p->RIOHosts[Host].Type == RIO_AT)
  1030. p->RIOHosts[Host].Mode |= WORD_OPERATION;
  1031. return retval;
  1032. case RIO_SET_FAST_BUS:
  1033. for (Host = 0; Host < p->RIONumHosts; Host++)
  1034. if (p->RIOHosts[Host].Type == RIO_AT)
  1035. p->RIOHosts[Host].Mode |= FAST_AT_BUS;
  1036. return retval;
  1037. case RIO_SET_SLOW_BUS:
  1038. for (Host = 0; Host < p->RIONumHosts; Host++)
  1039. if (p->RIOHosts[Host].Type == RIO_AT)
  1040. p->RIOHosts[Host].Mode &= ~FAST_AT_BUS;
  1041. return retval;
  1042. case RIO_MAP_B50_TO_50:
  1043. case RIO_MAP_B50_TO_57600:
  1044. case RIO_MAP_B110_TO_110:
  1045. case RIO_MAP_B110_TO_115200:
  1046. rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping\n");
  1047. port = arg;
  1048. if (port < 0 || port > 511) {
  1049. rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", port);
  1050. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  1051. return -EINVAL;
  1052. }
  1053. rio_spin_lock_irqsave(&PortP->portSem, flags);
  1054. switch (cmd) {
  1055. case RIO_MAP_B50_TO_50:
  1056. p->RIOPortp[port]->Config |= RIO_MAP_50_TO_50;
  1057. break;
  1058. case RIO_MAP_B50_TO_57600:
  1059. p->RIOPortp[port]->Config &= ~RIO_MAP_50_TO_50;
  1060. break;
  1061. case RIO_MAP_B110_TO_110:
  1062. p->RIOPortp[port]->Config |= RIO_MAP_110_TO_110;
  1063. break;
  1064. case RIO_MAP_B110_TO_115200:
  1065. p->RIOPortp[port]->Config &= ~RIO_MAP_110_TO_110;
  1066. break;
  1067. }
  1068. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  1069. return retval;
  1070. case RIO_STREAM_INFO:
  1071. rio_dprintk(RIO_DEBUG_CTRL, "RIO_STREAM_INFO\n");
  1072. return -EINVAL;
  1073. case RIO_SEND_PACKET:
  1074. rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET\n");
  1075. if (copy_from_user(&SendPack, argp, sizeof(SendPack))) {
  1076. rio_dprintk(RIO_DEBUG_CTRL, "RIO_SEND_PACKET: Bad copy from user space\n");
  1077. p->RIOError.Error = COPYIN_FAILED;
  1078. return -EFAULT;
  1079. }
  1080. if (SendPack.PortNum >= 128) {
  1081. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  1082. return -ENXIO;
  1083. }
  1084. PortP = p->RIOPortp[SendPack.PortNum];
  1085. rio_spin_lock_irqsave(&PortP->portSem, flags);
  1086. if (!can_add_transmit(&PacketP, PortP)) {
  1087. p->RIOError.Error = UNIT_IS_IN_USE;
  1088. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  1089. return -ENOSPC;
  1090. }
  1091. for (loop = 0; loop < (ushort) (SendPack.Len & 127); loop++)
  1092. writeb(SendPack.Data[loop], &PacketP->data[loop]);
  1093. writeb(SendPack.Len, &PacketP->len);
  1094. add_transmit(PortP);
  1095. /*
  1096. ** Count characters transmitted for port statistics reporting
  1097. */
  1098. if (PortP->statsGather)
  1099. PortP->txchars += (SendPack.Len & 127);
  1100. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  1101. return retval;
  1102. case RIO_NO_MESG:
  1103. if (su)
  1104. p->RIONoMessage = 1;
  1105. return su ? 0 : -EPERM;
  1106. case RIO_MESG:
  1107. if (su)
  1108. p->RIONoMessage = 0;
  1109. return su ? 0 : -EPERM;
  1110. case RIO_WHAT_MESG:
  1111. if (copy_to_user(argp, &p->RIONoMessage, sizeof(p->RIONoMessage))) {
  1112. rio_dprintk(RIO_DEBUG_CTRL, "RIO_WHAT_MESG: Bad copy to user space\n");
  1113. p->RIOError.Error = COPYOUT_FAILED;
  1114. return -EFAULT;
  1115. }
  1116. return 0;
  1117. case RIO_MEM_DUMP:
  1118. if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
  1119. p->RIOError.Error = COPYIN_FAILED;
  1120. return -EFAULT;
  1121. }
  1122. rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP host %d rup %d addr %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Addr);
  1123. if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
  1124. p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
  1125. return -EINVAL;
  1126. }
  1127. if (SubCmd.Host >= p->RIONumHosts) {
  1128. p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
  1129. return -EINVAL;
  1130. }
  1131. port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort;
  1132. PortP = p->RIOPortp[port];
  1133. rio_spin_lock_irqsave(&PortP->portSem, flags);
  1134. if (RIOPreemptiveCmd(p, PortP, RIOC_MEMDUMP) == RIO_FAIL) {
  1135. rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP failed\n");
  1136. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  1137. return -EBUSY;
  1138. } else
  1139. PortP->State |= RIO_BUSY;
  1140. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  1141. if (copy_to_user(argp, p->RIOMemDump, MEMDUMP_SIZE)) {
  1142. rio_dprintk(RIO_DEBUG_CTRL, "RIO_MEM_DUMP copy failed\n");
  1143. p->RIOError.Error = COPYOUT_FAILED;
  1144. return -EFAULT;
  1145. }
  1146. return 0;
  1147. case RIO_TICK:
  1148. if (arg >= p->RIONumHosts)
  1149. return -EINVAL;
  1150. rio_dprintk(RIO_DEBUG_CTRL, "Set interrupt for host %ld\n", arg);
  1151. writeb(0xFF, &p->RIOHosts[arg].SetInt);
  1152. return 0;
  1153. case RIO_TOCK:
  1154. if (arg >= p->RIONumHosts)
  1155. return -EINVAL;
  1156. rio_dprintk(RIO_DEBUG_CTRL, "Clear interrupt for host %ld\n", arg);
  1157. writeb(0xFF, &p->RIOHosts[arg].ResetInt);
  1158. return 0;
  1159. case RIO_READ_CHECK:
  1160. /* Check reads for pkts with data[0] the same */
  1161. p->RIOReadCheck = !p->RIOReadCheck;
  1162. if (copy_to_user(argp, &p->RIOReadCheck, sizeof(unsigned int))) {
  1163. p->RIOError.Error = COPYOUT_FAILED;
  1164. return -EFAULT;
  1165. }
  1166. return 0;
  1167. case RIO_READ_REGISTER:
  1168. if (copy_from_user(&SubCmd, argp, sizeof(struct SubCmdStruct))) {
  1169. p->RIOError.Error = COPYIN_FAILED;
  1170. return -EFAULT;
  1171. }
  1172. rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER host %d rup %d port %d reg %x\n", SubCmd.Host, SubCmd.Rup, SubCmd.Port, SubCmd.Addr);
  1173. if (SubCmd.Port > 511) {
  1174. rio_dprintk(RIO_DEBUG_CTRL, "Baud rate mapping: Bad port number %d\n", SubCmd.Port);
  1175. p->RIOError.Error = PORT_NUMBER_OUT_OF_RANGE;
  1176. return -EINVAL;
  1177. }
  1178. if (SubCmd.Rup >= MAX_RUP + LINKS_PER_UNIT) {
  1179. p->RIOError.Error = RUP_NUMBER_OUT_OF_RANGE;
  1180. return -EINVAL;
  1181. }
  1182. if (SubCmd.Host >= p->RIONumHosts) {
  1183. p->RIOError.Error = HOST_NUMBER_OUT_OF_RANGE;
  1184. return -EINVAL;
  1185. }
  1186. port = p->RIOHosts[SubCmd.Host].UnixRups[SubCmd.Rup].BaseSysPort + SubCmd.Port;
  1187. PortP = p->RIOPortp[port];
  1188. rio_spin_lock_irqsave(&PortP->portSem, flags);
  1189. if (RIOPreemptiveCmd(p, PortP, RIOC_READ_REGISTER) ==
  1190. RIO_FAIL) {
  1191. rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER failed\n");
  1192. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  1193. return -EBUSY;
  1194. } else
  1195. PortP->State |= RIO_BUSY;
  1196. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  1197. if (copy_to_user(argp, &p->CdRegister, sizeof(unsigned int))) {
  1198. rio_dprintk(RIO_DEBUG_CTRL, "RIO_READ_REGISTER copy failed\n");
  1199. p->RIOError.Error = COPYOUT_FAILED;
  1200. return -EFAULT;
  1201. }
  1202. return 0;
  1203. /*
  1204. ** rio_make_dev: given port number (0-511) ORed with port type
  1205. ** (RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT) return dev_t
  1206. ** value to pass to mknod to create the correct device node.
  1207. */
  1208. case RIO_MAKE_DEV:
  1209. {
  1210. unsigned int port = arg & RIO_MODEM_MASK;
  1211. unsigned int ret;
  1212. switch (arg & RIO_DEV_MASK) {
  1213. case RIO_DEV_DIRECT:
  1214. ret = drv_makedev(MAJOR(dev), port);
  1215. rio_dprintk(RIO_DEBUG_CTRL, "Makedev direct 0x%x is 0x%x\n", port, ret);
  1216. return ret;
  1217. case RIO_DEV_MODEM:
  1218. ret = drv_makedev(MAJOR(dev), (port | RIO_MODEM_BIT));
  1219. rio_dprintk(RIO_DEBUG_CTRL, "Makedev modem 0x%x is 0x%x\n", port, ret);
  1220. return ret;
  1221. case RIO_DEV_XPRINT:
  1222. ret = drv_makedev(MAJOR(dev), port);
  1223. rio_dprintk(RIO_DEBUG_CTRL, "Makedev printer 0x%x is 0x%x\n", port, ret);
  1224. return ret;
  1225. }
  1226. rio_dprintk(RIO_DEBUG_CTRL, "MAKE Device is called\n");
  1227. return -EINVAL;
  1228. }
  1229. /*
  1230. ** rio_minor: given a dev_t from a stat() call, return
  1231. ** the port number (0-511) ORed with the port type
  1232. ** ( RIO_DEV_DIRECT, RIO_DEV_MODEM, RIO_DEV_XPRINT )
  1233. */
  1234. case RIO_MINOR:
  1235. {
  1236. dev_t dv;
  1237. int mino;
  1238. unsigned long ret;
  1239. dv = (dev_t) (arg);
  1240. mino = RIO_UNMODEM(dv);
  1241. if (RIO_ISMODEM(dv)) {
  1242. rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: modem %d\n", dv, mino);
  1243. ret = mino | RIO_DEV_MODEM;
  1244. } else {
  1245. rio_dprintk(RIO_DEBUG_CTRL, "Minor for device 0x%x: direct %d\n", dv, mino);
  1246. ret = mino | RIO_DEV_DIRECT;
  1247. }
  1248. return ret;
  1249. }
  1250. }
  1251. rio_dprintk(RIO_DEBUG_CTRL, "INVALID DAEMON IOCTL 0x%x\n", cmd);
  1252. p->RIOError.Error = IOCTL_COMMAND_UNKNOWN;
  1253. func_exit();
  1254. return -EINVAL;
  1255. }
  1256. /*
  1257. ** Pre-emptive commands go on RUPs and are only one byte long.
  1258. */
  1259. int RIOPreemptiveCmd(struct rio_info *p, struct Port *PortP, u8 Cmd)
  1260. {
  1261. struct CmdBlk *CmdBlkP;
  1262. struct PktCmd_M *PktCmdP;
  1263. int Ret;
  1264. ushort rup;
  1265. int port;
  1266. if (PortP->State & RIO_DELETED) {
  1267. rio_dprintk(RIO_DEBUG_CTRL, "Preemptive command to deleted RTA ignored\n");
  1268. return RIO_FAIL;
  1269. }
  1270. if ((PortP->InUse == (typeof(PortP->InUse))-1) ||
  1271. !(CmdBlkP = RIOGetCmdBlk())) {
  1272. rio_dprintk(RIO_DEBUG_CTRL, "Cannot allocate command block "
  1273. "for command %d on port %d\n", Cmd, PortP->PortNum);
  1274. return RIO_FAIL;
  1275. }
  1276. rio_dprintk(RIO_DEBUG_CTRL, "Command blk %p - InUse now %d\n",
  1277. CmdBlkP, PortP->InUse);
  1278. PktCmdP = (struct PktCmd_M *)&CmdBlkP->Packet.data[0];
  1279. CmdBlkP->Packet.src_unit = 0;
  1280. if (PortP->SecondBlock)
  1281. rup = PortP->ID2;
  1282. else
  1283. rup = PortP->RupNum;
  1284. CmdBlkP->Packet.dest_unit = rup;
  1285. CmdBlkP->Packet.src_port = COMMAND_RUP;
  1286. CmdBlkP->Packet.dest_port = COMMAND_RUP;
  1287. CmdBlkP->Packet.len = PKT_CMD_BIT | 2;
  1288. CmdBlkP->PostFuncP = RIOUnUse;
  1289. CmdBlkP->PostArg = (unsigned long) PortP;
  1290. PktCmdP->Command = Cmd;
  1291. port = PortP->HostPort % (ushort) PORTS_PER_RTA;
  1292. /*
  1293. ** Index ports 8-15 for 2nd block of 16 port RTA.
  1294. */
  1295. if (PortP->SecondBlock)
  1296. port += (ushort) PORTS_PER_RTA;
  1297. PktCmdP->PhbNum = port;
  1298. switch (Cmd) {
  1299. case RIOC_MEMDUMP:
  1300. rio_dprintk(RIO_DEBUG_CTRL, "Queue MEMDUMP command blk %p "
  1301. "(addr 0x%x)\n", CmdBlkP, (int) SubCmd.Addr);
  1302. PktCmdP->SubCommand = RIOC_MEMDUMP;
  1303. PktCmdP->SubAddr = SubCmd.Addr;
  1304. break;
  1305. case RIOC_FCLOSE:
  1306. rio_dprintk(RIO_DEBUG_CTRL, "Queue FCLOSE command blk %p\n",
  1307. CmdBlkP);
  1308. break;
  1309. case RIOC_READ_REGISTER:
  1310. rio_dprintk(RIO_DEBUG_CTRL, "Queue READ_REGISTER (0x%x) "
  1311. "command blk %p\n", (int) SubCmd.Addr, CmdBlkP);
  1312. PktCmdP->SubCommand = RIOC_READ_REGISTER;
  1313. PktCmdP->SubAddr = SubCmd.Addr;
  1314. break;
  1315. case RIOC_RESUME:
  1316. rio_dprintk(RIO_DEBUG_CTRL, "Queue RESUME command blk %p\n",
  1317. CmdBlkP);
  1318. break;
  1319. case RIOC_RFLUSH:
  1320. rio_dprintk(RIO_DEBUG_CTRL, "Queue RFLUSH command blk %p\n",
  1321. CmdBlkP);
  1322. CmdBlkP->PostFuncP = RIORFlushEnable;
  1323. break;
  1324. case RIOC_SUSPEND:
  1325. rio_dprintk(RIO_DEBUG_CTRL, "Queue SUSPEND command blk %p\n",
  1326. CmdBlkP);
  1327. break;
  1328. case RIOC_MGET:
  1329. rio_dprintk(RIO_DEBUG_CTRL, "Queue MGET command blk %p\n",
  1330. CmdBlkP);
  1331. break;
  1332. case RIOC_MSET:
  1333. case RIOC_MBIC:
  1334. case RIOC_MBIS:
  1335. CmdBlkP->Packet.data[4] = (char) PortP->ModemLines;
  1336. rio_dprintk(RIO_DEBUG_CTRL, "Queue MSET/MBIC/MBIS command "
  1337. "blk %p\n", CmdBlkP);
  1338. break;
  1339. case RIOC_WFLUSH:
  1340. /*
  1341. ** If we have queued up the maximum number of Write flushes
  1342. ** allowed then we should not bother sending any more to the
  1343. ** RTA.
  1344. */
  1345. if (PortP->WflushFlag == (typeof(PortP->WflushFlag))-1) {
  1346. rio_dprintk(RIO_DEBUG_CTRL, "Trashed WFLUSH, "
  1347. "WflushFlag about to wrap!");
  1348. RIOFreeCmdBlk(CmdBlkP);
  1349. return (RIO_FAIL);
  1350. } else {
  1351. rio_dprintk(RIO_DEBUG_CTRL, "Queue WFLUSH command "
  1352. "blk %p\n", CmdBlkP);
  1353. CmdBlkP->PostFuncP = RIOWFlushMark;
  1354. }
  1355. break;
  1356. }
  1357. PortP->InUse++;
  1358. Ret = RIOQueueCmdBlk(PortP->HostP, rup, CmdBlkP);
  1359. return Ret;
  1360. }