rioctrl.c 47 KB

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