rioctrl.c 52 KB

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