rioctrl.c 47 KB

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