riotable.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  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 : riotable.c
  24. ** SID : 1.2
  25. ** Last Modified : 11/6/98 10:33:47
  26. ** Retrieved : 11/6/98 10:33:50
  27. **
  28. ** ident @(#)riotable.c 1.2
  29. **
  30. ** -----------------------------------------------------------------------------
  31. */
  32. #ifdef SCCS_LABELS
  33. static char *_riotable_c_sccs_ = "@(#)riotable.c 1.2";
  34. #endif
  35. #include <linux/module.h>
  36. #include <linux/slab.h>
  37. #include <linux/errno.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/string.h>
  40. #include <asm/io.h>
  41. #include <asm/system.h>
  42. #include <asm/string.h>
  43. #include <asm/semaphore.h>
  44. #include <asm/uaccess.h>
  45. #include <linux/termios.h>
  46. #include <linux/serial.h>
  47. #include <linux/generic_serial.h>
  48. #include "linux_compat.h"
  49. #include "rio_linux.h"
  50. #include "typdef.h"
  51. #include "pkt.h"
  52. #include "daemon.h"
  53. #include "rio.h"
  54. #include "riospace.h"
  55. #include "top.h"
  56. #include "cmdpkt.h"
  57. #include "map.h"
  58. #include "riotypes.h"
  59. #include "rup.h"
  60. #include "port.h"
  61. #include "riodrvr.h"
  62. #include "rioinfo.h"
  63. #include "func.h"
  64. #include "errors.h"
  65. #include "pci.h"
  66. #include "parmmap.h"
  67. #include "unixrup.h"
  68. #include "board.h"
  69. #include "host.h"
  70. #include "error.h"
  71. #include "phb.h"
  72. #include "link.h"
  73. #include "cmdblk.h"
  74. #include "route.h"
  75. #include "control.h"
  76. #include "cirrus.h"
  77. #include "rioioctl.h"
  78. #include "param.h"
  79. #include "list.h"
  80. #include "sam.h"
  81. #include "protsts.h"
  82. /*
  83. ** A configuration table has been loaded. It is now up to us
  84. ** to sort it out and use the information contained therein.
  85. */
  86. int RIONewTable(struct rio_info *p)
  87. {
  88. int Host, Host1, Host2, NameIsUnique, Entry, SubEnt;
  89. struct Map *MapP;
  90. struct Map *HostMapP;
  91. struct Host *HostP;
  92. char *cptr;
  93. /*
  94. ** We have been sent a new table to install. We need to break
  95. ** it down into little bits and spread it around a bit to see
  96. ** what we have got.
  97. */
  98. /*
  99. ** Things to check:
  100. ** (things marked 'xx' aren't checked any more!)
  101. ** (1) That there are no booted Hosts/RTAs out there.
  102. ** (2) That the names are properly formed
  103. ** (3) That blank entries really are.
  104. ** xx (4) That hosts mentioned in the table actually exist. xx
  105. ** (5) That the IDs are unique (per host).
  106. ** (6) That host IDs are zero
  107. ** (7) That port numbers are valid
  108. ** (8) That port numbers aren't duplicated
  109. ** (9) That names aren't duplicated
  110. ** xx (10) That hosts that actually exist are mentioned in the table. xx
  111. */
  112. rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(1)\n");
  113. if (p->RIOSystemUp) { /* (1) */
  114. p->RIOError.Error = HOST_HAS_ALREADY_BEEN_BOOTED;
  115. return -EBUSY;
  116. }
  117. p->RIOError.Error = NOTHING_WRONG_AT_ALL;
  118. p->RIOError.Entry = -1;
  119. p->RIOError.Other = -1;
  120. for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
  121. MapP = &p->RIOConnectTable[Entry];
  122. if ((MapP->Flags & RTA16_SECOND_SLOT) == 0) {
  123. rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(2)\n");
  124. cptr = MapP->Name; /* (2) */
  125. cptr[MAX_NAME_LEN - 1] = '\0';
  126. if (cptr[0] == '\0') {
  127. bcopy(MapP->RtaUniqueNum ? "RTA NN" : "HOST NN", MapP->Name, 8);
  128. MapP->Name[5] = '0' + Entry / 10;
  129. MapP->Name[6] = '0' + Entry % 10;
  130. }
  131. while (*cptr) {
  132. if (*cptr < ' ' || *cptr > '~') {
  133. p->RIOError.Error = BAD_CHARACTER_IN_NAME;
  134. p->RIOError.Entry = Entry;
  135. return -ENXIO;
  136. }
  137. cptr++;
  138. }
  139. }
  140. /*
  141. ** If the entry saved was a tentative entry then just forget
  142. ** about it.
  143. */
  144. if (MapP->Flags & SLOT_TENTATIVE) {
  145. MapP->HostUniqueNum = 0;
  146. MapP->RtaUniqueNum = 0;
  147. continue;
  148. }
  149. rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(3)\n");
  150. if (!MapP->RtaUniqueNum && !MapP->HostUniqueNum) { /* (3) */
  151. if (MapP->ID || MapP->SysPort || MapP->Flags) {
  152. rio_dprintk(RIO_DEBUG_TABLE, "%s pretending to be empty but isn't\n", MapP->Name);
  153. p->RIOError.Error = TABLE_ENTRY_ISNT_PROPERLY_NULL;
  154. p->RIOError.Entry = Entry;
  155. return -ENXIO;
  156. }
  157. rio_dprintk(RIO_DEBUG_TABLE, "!RIO: Daemon: test (3) passes\n");
  158. continue;
  159. }
  160. rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(4)\n");
  161. for (Host = 0; Host < p->RIONumHosts; Host++) { /* (4) */
  162. if (p->RIOHosts[Host].UniqueNum == MapP->HostUniqueNum) {
  163. HostP = &p->RIOHosts[Host];
  164. /*
  165. ** having done the lookup, we don't really want to do
  166. ** it again, so hang the host number in a safe place
  167. */
  168. MapP->Topology[0].Unit = Host;
  169. break;
  170. }
  171. }
  172. if (Host >= p->RIONumHosts) {
  173. rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has unknown host unique number 0x%x\n", MapP->Name, MapP->HostUniqueNum);
  174. MapP->HostUniqueNum = 0;
  175. /* MapP->RtaUniqueNum = 0; */
  176. /* MapP->ID = 0; */
  177. /* MapP->Flags = 0; */
  178. /* MapP->SysPort = 0; */
  179. /* MapP->Name[0] = 0; */
  180. continue;
  181. }
  182. rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(5)\n");
  183. if (MapP->RtaUniqueNum) { /* (5) */
  184. if (!MapP->ID) {
  185. rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an ID of zero!\n", MapP->Name);
  186. p->RIOError.Error = ZERO_RTA_ID;
  187. p->RIOError.Entry = Entry;
  188. return -ENXIO;
  189. }
  190. if (MapP->ID > MAX_RUP) {
  191. rio_dprintk(RIO_DEBUG_TABLE, "RIO: RTA %s has been allocated an invalid ID %d\n", MapP->Name, MapP->ID);
  192. p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
  193. p->RIOError.Entry = Entry;
  194. return -ENXIO;
  195. }
  196. for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
  197. if (MapP->HostUniqueNum == p->RIOConnectTable[SubEnt].HostUniqueNum && MapP->ID == p->RIOConnectTable[SubEnt].ID) {
  198. rio_dprintk(RIO_DEBUG_TABLE, "Dupl. ID number allocated to RTA %s and RTA %s\n", MapP->Name, p->RIOConnectTable[SubEnt].Name);
  199. p->RIOError.Error = DUPLICATED_RTA_ID;
  200. p->RIOError.Entry = Entry;
  201. p->RIOError.Other = SubEnt;
  202. return -ENXIO;
  203. }
  204. /*
  205. ** If the RtaUniqueNum is the same, it may be looking at both
  206. ** entries for a 16 port RTA, so check the ids
  207. */
  208. if ((MapP->RtaUniqueNum == p->RIOConnectTable[SubEnt].RtaUniqueNum)
  209. && (MapP->ID2 != p->RIOConnectTable[SubEnt].ID)) {
  210. rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", MapP->Name);
  211. rio_dprintk(RIO_DEBUG_TABLE, "RTA %s has duplicate unique number\n", p->RIOConnectTable[SubEnt].Name);
  212. p->RIOError.Error = DUPLICATE_UNIQUE_NUMBER;
  213. p->RIOError.Entry = Entry;
  214. p->RIOError.Other = SubEnt;
  215. return -ENXIO;
  216. }
  217. }
  218. rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7a)\n");
  219. /* (7a) */
  220. if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
  221. rio_dprintk(RIO_DEBUG_TABLE, "TTY Port number %d-RTA %s is not a multiple of %d!\n", (int) MapP->SysPort, MapP->Name, PORTS_PER_RTA);
  222. p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
  223. p->RIOError.Entry = Entry;
  224. return -ENXIO;
  225. }
  226. rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(7b)\n");
  227. /* (7b) */
  228. if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
  229. rio_dprintk(RIO_DEBUG_TABLE, "TTY Port number %d for RTA %s is too big\n", (int) MapP->SysPort, MapP->Name);
  230. p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
  231. p->RIOError.Entry = Entry;
  232. return -ENXIO;
  233. }
  234. for (SubEnt = 0; SubEnt < Entry; SubEnt++) {
  235. if (p->RIOConnectTable[SubEnt].Flags & RTA16_SECOND_SLOT)
  236. continue;
  237. if (p->RIOConnectTable[SubEnt].RtaUniqueNum) {
  238. rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(8)\n");
  239. /* (8) */
  240. if ((MapP->SysPort != NO_PORT) && (MapP->SysPort == p->RIOConnectTable[SubEnt].SysPort)) {
  241. rio_dprintk(RIO_DEBUG_TABLE, "RTA %s:same TTY port # as RTA %s (%d)\n", MapP->Name, p->RIOConnectTable[SubEnt].Name, (int) MapP->SysPort);
  242. p->RIOError.Error = TTY_NUMBER_IN_USE;
  243. p->RIOError.Entry = Entry;
  244. p->RIOError.Other = SubEnt;
  245. return -ENXIO;
  246. }
  247. rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(9)\n");
  248. if (strcmp(MapP->Name, p->RIOConnectTable[SubEnt].Name) == 0 && !(MapP->Flags & RTA16_SECOND_SLOT)) { /* (9) */
  249. rio_dprintk(RIO_DEBUG_TABLE, "RTA name %s used twice\n", MapP->Name);
  250. p->RIOError.Error = NAME_USED_TWICE;
  251. p->RIOError.Entry = Entry;
  252. p->RIOError.Other = SubEnt;
  253. return -ENXIO;
  254. }
  255. }
  256. }
  257. } else { /* (6) */
  258. rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: entering(6)\n");
  259. if (MapP->ID) {
  260. rio_dprintk(RIO_DEBUG_TABLE, "RIO:HOST %s has been allocated ID that isn't zero!\n", MapP->Name);
  261. p->RIOError.Error = HOST_ID_NOT_ZERO;
  262. p->RIOError.Entry = Entry;
  263. return -ENXIO;
  264. }
  265. if (MapP->SysPort != NO_PORT) {
  266. rio_dprintk(RIO_DEBUG_TABLE, "RIO: HOST %s has been allocated port numbers!\n", MapP->Name);
  267. p->RIOError.Error = HOST_SYSPORT_BAD;
  268. p->RIOError.Entry = Entry;
  269. return -ENXIO;
  270. }
  271. }
  272. }
  273. /*
  274. ** wow! if we get here then it's a goody!
  275. */
  276. /*
  277. ** Zero the (old) entries for each host...
  278. */
  279. for (Host = 0; Host < RIO_HOSTS; Host++) {
  280. for (Entry = 0; Entry < MAX_RUP; Entry++) {
  281. memset(&p->RIOHosts[Host].Mapping[Entry], 0, sizeof(struct Map));
  282. }
  283. memset(&p->RIOHosts[Host].Name[0], 0, sizeof(p->RIOHosts[Host].Name));
  284. }
  285. /*
  286. ** Copy in the new table entries
  287. */
  288. for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
  289. rio_dprintk(RIO_DEBUG_TABLE, "RIONewTable: Copy table for Host entry %d\n", Entry);
  290. MapP = &p->RIOConnectTable[Entry];
  291. /*
  292. ** Now, if it is an empty slot ignore it!
  293. */
  294. if (MapP->HostUniqueNum == 0)
  295. continue;
  296. /*
  297. ** we saved the host number earlier, so grab it back
  298. */
  299. HostP = &p->RIOHosts[MapP->Topology[0].Unit];
  300. /*
  301. ** If it is a host, then we only need to fill in the name field.
  302. */
  303. if (MapP->ID == 0) {
  304. rio_dprintk(RIO_DEBUG_TABLE, "Host entry found. Name %s\n", MapP->Name);
  305. bcopy(MapP->Name, HostP->Name, MAX_NAME_LEN);
  306. continue;
  307. }
  308. /*
  309. ** Its an RTA entry, so fill in the host mapping entries for it
  310. ** and the port mapping entries. Notice that entry zero is for
  311. ** ID one.
  312. */
  313. HostMapP = &HostP->Mapping[MapP->ID - 1];
  314. if (MapP->Flags & SLOT_IN_USE) {
  315. rio_dprintk(RIO_DEBUG_TABLE, "Rta entry found. Name %s\n", MapP->Name);
  316. /*
  317. ** structure assign, then sort out the bits we shouldn't have done
  318. */
  319. *HostMapP = *MapP;
  320. HostMapP->Flags = SLOT_IN_USE;
  321. if (MapP->Flags & RTA16_SECOND_SLOT)
  322. HostMapP->Flags |= RTA16_SECOND_SLOT;
  323. RIOReMapPorts(p, HostP, HostMapP);
  324. } else {
  325. rio_dprintk(RIO_DEBUG_TABLE, "TENTATIVE Rta entry found. Name %s\n", MapP->Name);
  326. }
  327. }
  328. for (Entry = 0; Entry < TOTAL_MAP_ENTRIES; Entry++) {
  329. p->RIOSavedTable[Entry] = p->RIOConnectTable[Entry];
  330. }
  331. for (Host = 0; Host < p->RIONumHosts; Host++) {
  332. for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
  333. p->RIOHosts[Host].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
  334. p->RIOHosts[Host].Topology[SubEnt].Link = NO_LINK;
  335. }
  336. for (Entry = 0; Entry < MAX_RUP; Entry++) {
  337. for (SubEnt = 0; SubEnt < LINKS_PER_UNIT; SubEnt++) {
  338. p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Unit = ROUTE_DISCONNECT;
  339. p->RIOHosts[Host].Mapping[Entry].Topology[SubEnt].Link = NO_LINK;
  340. }
  341. }
  342. if (!p->RIOHosts[Host].Name[0]) {
  343. bcopy("HOST 1", p->RIOHosts[Host].Name, 7);
  344. p->RIOHosts[Host].Name[5] += Host;
  345. }
  346. /*
  347. ** Check that default name assigned is unique.
  348. */
  349. Host1 = Host;
  350. NameIsUnique = 0;
  351. while (!NameIsUnique) {
  352. NameIsUnique = 1;
  353. for (Host2 = 0; Host2 < p->RIONumHosts; Host2++) {
  354. if (Host2 == Host)
  355. continue;
  356. if (strcmp(p->RIOHosts[Host].Name, p->RIOHosts[Host2].Name)
  357. == 0) {
  358. NameIsUnique = 0;
  359. Host1++;
  360. if (Host1 >= p->RIONumHosts)
  361. Host1 = 0;
  362. p->RIOHosts[Host].Name[5] = '1' + Host1;
  363. }
  364. }
  365. }
  366. /*
  367. ** Rename host if name already used.
  368. */
  369. if (Host1 != Host) {
  370. rio_dprintk(RIO_DEBUG_TABLE, "Default name %s already used\n", p->RIOHosts[Host].Name);
  371. bcopy("HOST 1", p->RIOHosts[Host].Name, 7);
  372. p->RIOHosts[Host].Name[5] += Host1;
  373. }
  374. rio_dprintk(RIO_DEBUG_TABLE, "Assigning default name %s\n", p->RIOHosts[Host].Name);
  375. }
  376. return 0;
  377. }
  378. /*
  379. ** User process needs the config table - build it from first
  380. ** principles.
  381. **
  382. * FIXME: SMP locking
  383. */
  384. int RIOApel(struct rio_info *p)
  385. {
  386. int Host;
  387. int link;
  388. int Rup;
  389. int Next = 0;
  390. struct Map *MapP;
  391. struct Host *HostP;
  392. unsigned long flags;
  393. rio_dprintk(RIO_DEBUG_TABLE, "Generating a table to return to config.rio\n");
  394. memset(&p->RIOConnectTable[0], 0, sizeof(struct Map) * TOTAL_MAP_ENTRIES);
  395. for (Host = 0; Host < RIO_HOSTS; Host++) {
  396. rio_dprintk(RIO_DEBUG_TABLE, "Processing host %d\n", Host);
  397. HostP = &p->RIOHosts[Host];
  398. rio_spin_lock_irqsave(&HostP->HostLock, flags);
  399. MapP = &p->RIOConnectTable[Next++];
  400. MapP->HostUniqueNum = HostP->UniqueNum;
  401. if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
  402. continue;
  403. MapP->RtaUniqueNum = 0;
  404. MapP->ID = 0;
  405. MapP->Flags = SLOT_IN_USE;
  406. MapP->SysPort = NO_PORT;
  407. for (link = 0; link < LINKS_PER_UNIT; link++)
  408. MapP->Topology[link] = HostP->Topology[link];
  409. bcopy(HostP->Name, MapP->Name, MAX_NAME_LEN);
  410. for (Rup = 0; Rup < MAX_RUP; Rup++) {
  411. if (HostP->Mapping[Rup].Flags & (SLOT_IN_USE | SLOT_TENTATIVE)) {
  412. p->RIOConnectTable[Next] = HostP->Mapping[Rup];
  413. if (HostP->Mapping[Rup].Flags & SLOT_IN_USE)
  414. p->RIOConnectTable[Next].Flags |= SLOT_IN_USE;
  415. if (HostP->Mapping[Rup].Flags & SLOT_TENTATIVE)
  416. p->RIOConnectTable[Next].Flags |= SLOT_TENTATIVE;
  417. if (HostP->Mapping[Rup].Flags & RTA16_SECOND_SLOT)
  418. p->RIOConnectTable[Next].Flags |= RTA16_SECOND_SLOT;
  419. Next++;
  420. }
  421. }
  422. rio_spin_unlock_irqrestore(&HostP->HostLock, flags);
  423. }
  424. return 0;
  425. }
  426. /*
  427. ** config.rio has taken a dislike to one of the gross maps entries.
  428. ** if the entry is suitably inactive, then we can gob on it and remove
  429. ** it from the table.
  430. */
  431. int RIODeleteRta(struct rio_info *p, struct Map *MapP)
  432. {
  433. int host, entry, port, link;
  434. int SysPort;
  435. struct Host *HostP;
  436. struct Map *HostMapP;
  437. struct Port *PortP;
  438. int work_done = 0;
  439. unsigned long lock_flags, sem_flags;
  440. rio_dprintk(RIO_DEBUG_TABLE, "Delete entry on host %x, rta %x\n", MapP->HostUniqueNum, MapP->RtaUniqueNum);
  441. for (host = 0; host < p->RIONumHosts; host++) {
  442. HostP = &p->RIOHosts[host];
  443. rio_spin_lock_irqsave(&HostP->HostLock, lock_flags);
  444. if ((HostP->Flags & RUN_STATE) != RC_RUNNING) {
  445. rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
  446. continue;
  447. }
  448. for (entry = 0; entry < MAX_RUP; entry++) {
  449. if (MapP->RtaUniqueNum == HostP->Mapping[entry].RtaUniqueNum) {
  450. HostMapP = &HostP->Mapping[entry];
  451. rio_dprintk(RIO_DEBUG_TABLE, "Found entry offset %d on host %s\n", entry, HostP->Name);
  452. /*
  453. ** Check all four links of the unit are disconnected
  454. */
  455. for (link = 0; link < LINKS_PER_UNIT; link++) {
  456. if (HostMapP->Topology[link].Unit != ROUTE_DISCONNECT) {
  457. rio_dprintk(RIO_DEBUG_TABLE, "Entry is in use and cannot be deleted!\n");
  458. p->RIOError.Error = UNIT_IS_IN_USE;
  459. rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
  460. return -EBUSY;
  461. }
  462. }
  463. /*
  464. ** Slot has been allocated, BUT not booted/routed/
  465. ** connected/selected or anything else-ed
  466. */
  467. SysPort = HostMapP->SysPort;
  468. if (SysPort != NO_PORT) {
  469. for (port = SysPort; port < SysPort + PORTS_PER_RTA; port++) {
  470. PortP = p->RIOPortp[port];
  471. rio_dprintk(RIO_DEBUG_TABLE, "Unmap port\n");
  472. rio_spin_lock_irqsave(&PortP->portSem, sem_flags);
  473. PortP->Mapped = 0;
  474. if (PortP->State & (RIO_MOPEN | RIO_LOPEN)) {
  475. rio_dprintk(RIO_DEBUG_TABLE, "Gob on port\n");
  476. PortP->TxBufferIn = PortP->TxBufferOut = 0;
  477. /* What should I do
  478. wakeup( &PortP->TxBufferIn );
  479. wakeup( &PortP->TxBufferOut);
  480. */
  481. PortP->InUse = NOT_INUSE;
  482. /* What should I do
  483. wakeup( &PortP->InUse );
  484. signal(PortP->TtyP->t_pgrp,SIGKILL);
  485. ttyflush(PortP->TtyP,(FREAD|FWRITE));
  486. */
  487. PortP->State |= RIO_CLOSING | RIO_DELETED;
  488. }
  489. /*
  490. ** For the second slot of a 16 port RTA, the
  491. ** driver needs to reset the changes made to
  492. ** the phb to port mappings in RIORouteRup.
  493. */
  494. if (PortP->SecondBlock) {
  495. ushort dest_unit = HostMapP->ID;
  496. ushort dest_port = port - SysPort;
  497. u16 *TxPktP;
  498. PKT *Pkt;
  499. for (TxPktP = PortP->TxStart; TxPktP <= PortP->TxEnd; TxPktP++) {
  500. /*
  501. ** *TxPktP is the pointer to the
  502. ** transmit packet on the host card.
  503. ** This needs to be translated into
  504. ** a 32 bit pointer so it can be
  505. ** accessed from the driver.
  506. */
  507. Pkt = (PKT *) RIO_PTR(HostP->Caddr, readw(&*TxPktP));
  508. rio_dprintk(RIO_DEBUG_TABLE, "Tx packet (%x) destination: Old %x:%x New %x:%x\n", *TxPktP, Pkt->dest_unit, Pkt->dest_port, dest_unit, dest_port);
  509. writew(dest_unit, &Pkt->dest_unit);
  510. writew(dest_port, &Pkt->dest_port);
  511. }
  512. rio_dprintk(RIO_DEBUG_TABLE, "Port %d phb destination: Old %x:%x New %x:%x\n", port, PortP->PhbP->destination & 0xff, (PortP->PhbP->destination >> 8) & 0xff, dest_unit, dest_port);
  513. writew(dest_unit + (dest_port << 8), &PortP->PhbP->destination);
  514. }
  515. rio_spin_unlock_irqrestore(&PortP->portSem, sem_flags);
  516. }
  517. }
  518. rio_dprintk(RIO_DEBUG_TABLE, "Entry nulled.\n");
  519. memset(HostMapP, 0, sizeof(struct Map));
  520. work_done++;
  521. }
  522. }
  523. rio_spin_unlock_irqrestore(&HostP->HostLock, lock_flags);
  524. }
  525. /* XXXXX lock me up */
  526. for (entry = 0; entry < TOTAL_MAP_ENTRIES; entry++) {
  527. if (p->RIOSavedTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
  528. memset(&p->RIOSavedTable[entry], 0, sizeof(struct Map));
  529. work_done++;
  530. }
  531. if (p->RIOConnectTable[entry].RtaUniqueNum == MapP->RtaUniqueNum) {
  532. memset(&p->RIOConnectTable[entry], 0, sizeof(struct Map));
  533. work_done++;
  534. }
  535. }
  536. if (work_done)
  537. return 0;
  538. rio_dprintk(RIO_DEBUG_TABLE, "Couldn't find entry to be deleted\n");
  539. p->RIOError.Error = COULDNT_FIND_ENTRY;
  540. return -ENXIO;
  541. }
  542. int RIOAssignRta(struct rio_info *p, struct Map *MapP)
  543. {
  544. int host;
  545. struct Map *HostMapP;
  546. char *sptr;
  547. int link;
  548. rio_dprintk(RIO_DEBUG_TABLE, "Assign entry on host %x, rta %x, ID %d, Sysport %d\n", MapP->HostUniqueNum, MapP->RtaUniqueNum, MapP->ID, (int) MapP->SysPort);
  549. if ((MapP->ID != (ushort) - 1) && ((int) MapP->ID < (int) 1 || (int) MapP->ID > MAX_RUP)) {
  550. rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
  551. p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
  552. return -EINVAL;
  553. }
  554. if (MapP->RtaUniqueNum == 0) {
  555. rio_dprintk(RIO_DEBUG_TABLE, "Rta Unique number zero!\n");
  556. p->RIOError.Error = RTA_UNIQUE_NUMBER_ZERO;
  557. return -EINVAL;
  558. }
  559. if ((MapP->SysPort != NO_PORT) && (MapP->SysPort % PORTS_PER_RTA)) {
  560. rio_dprintk(RIO_DEBUG_TABLE, "Port %d not multiple of %d!\n", (int) MapP->SysPort, PORTS_PER_RTA);
  561. p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
  562. return -EINVAL;
  563. }
  564. if ((MapP->SysPort != NO_PORT) && (MapP->SysPort >= RIO_PORTS)) {
  565. rio_dprintk(RIO_DEBUG_TABLE, "Port %d not valid!\n", (int) MapP->SysPort);
  566. p->RIOError.Error = TTY_NUMBER_OUT_OF_RANGE;
  567. return -EINVAL;
  568. }
  569. /*
  570. ** Copy the name across to the map entry.
  571. */
  572. MapP->Name[MAX_NAME_LEN - 1] = '\0';
  573. sptr = MapP->Name;
  574. while (*sptr) {
  575. if (*sptr < ' ' || *sptr > '~') {
  576. rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
  577. p->RIOError.Error = BAD_CHARACTER_IN_NAME;
  578. return -EINVAL;
  579. }
  580. sptr++;
  581. }
  582. for (host = 0; host < p->RIONumHosts; host++) {
  583. if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
  584. if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
  585. p->RIOError.Error = HOST_NOT_RUNNING;
  586. return -ENXIO;
  587. }
  588. /*
  589. ** Now we have a host we need to allocate an ID
  590. ** if the entry does not already have one.
  591. */
  592. if (MapP->ID == (ushort) - 1) {
  593. int nNewID;
  594. rio_dprintk(RIO_DEBUG_TABLE, "Attempting to get a new ID for rta \"%s\"\n", MapP->Name);
  595. /*
  596. ** The idea here is to allow RTA's to be assigned
  597. ** before they actually appear on the network.
  598. ** This allows the addition of RTA's without having
  599. ** to plug them in.
  600. ** What we do is:
  601. ** - Find a free ID and allocate it to the RTA.
  602. ** - If this map entry is the second half of a
  603. ** 16 port entry then find the other half and
  604. ** make sure the 2 cross reference each other.
  605. */
  606. if (RIOFindFreeID(p, &p->RIOHosts[host], &nNewID, NULL) != 0) {
  607. p->RIOError.Error = COULDNT_FIND_ENTRY;
  608. return -EBUSY;
  609. }
  610. MapP->ID = (ushort) nNewID + 1;
  611. rio_dprintk(RIO_DEBUG_TABLE, "Allocated ID %d for this new RTA.\n", MapP->ID);
  612. HostMapP = &p->RIOHosts[host].Mapping[nNewID];
  613. HostMapP->RtaUniqueNum = MapP->RtaUniqueNum;
  614. HostMapP->HostUniqueNum = MapP->HostUniqueNum;
  615. HostMapP->ID = MapP->ID;
  616. for (link = 0; link < LINKS_PER_UNIT; link++) {
  617. HostMapP->Topology[link].Unit = ROUTE_DISCONNECT;
  618. HostMapP->Topology[link].Link = NO_LINK;
  619. }
  620. if (MapP->Flags & RTA16_SECOND_SLOT) {
  621. int unit;
  622. for (unit = 0; unit < MAX_RUP; unit++)
  623. if (p->RIOHosts[host].Mapping[unit].RtaUniqueNum == MapP->RtaUniqueNum)
  624. break;
  625. if (unit == MAX_RUP) {
  626. p->RIOError.Error = COULDNT_FIND_ENTRY;
  627. return -EBUSY;
  628. }
  629. HostMapP->Flags |= RTA16_SECOND_SLOT;
  630. HostMapP->ID2 = MapP->ID2 = p->RIOHosts[host].Mapping[unit].ID;
  631. p->RIOHosts[host].Mapping[unit].ID2 = MapP->ID;
  632. rio_dprintk(RIO_DEBUG_TABLE, "Cross referenced id %d to ID %d.\n", MapP->ID, p->RIOHosts[host].Mapping[unit].ID);
  633. }
  634. }
  635. HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
  636. if (HostMapP->Flags & SLOT_IN_USE) {
  637. rio_dprintk(RIO_DEBUG_TABLE, "Map table slot for ID %d is already in use.\n", MapP->ID);
  638. p->RIOError.Error = ID_ALREADY_IN_USE;
  639. return -EBUSY;
  640. }
  641. /*
  642. ** Assign the sys ports and the name, and mark the slot as
  643. ** being in use.
  644. */
  645. HostMapP->SysPort = MapP->SysPort;
  646. if ((MapP->Flags & RTA16_SECOND_SLOT) == 0)
  647. CCOPY(MapP->Name, HostMapP->Name, MAX_NAME_LEN);
  648. HostMapP->Flags = SLOT_IN_USE | RTA_BOOTED;
  649. #ifdef NEED_TO_FIX
  650. RIO_SV_BROADCAST(p->RIOHosts[host].svFlags[MapP->ID - 1]);
  651. #endif
  652. if (MapP->Flags & RTA16_SECOND_SLOT)
  653. HostMapP->Flags |= RTA16_SECOND_SLOT;
  654. RIOReMapPorts(p, &p->RIOHosts[host], HostMapP);
  655. /*
  656. ** Adjust 2nd block of 8 phbs
  657. */
  658. if (MapP->Flags & RTA16_SECOND_SLOT)
  659. RIOFixPhbs(p, &p->RIOHosts[host], HostMapP->ID - 1);
  660. if (HostMapP->SysPort != NO_PORT) {
  661. if (HostMapP->SysPort < p->RIOFirstPortsBooted)
  662. p->RIOFirstPortsBooted = HostMapP->SysPort;
  663. if (HostMapP->SysPort > p->RIOLastPortsBooted)
  664. p->RIOLastPortsBooted = HostMapP->SysPort;
  665. }
  666. if (MapP->Flags & RTA16_SECOND_SLOT)
  667. rio_dprintk(RIO_DEBUG_TABLE, "Second map of RTA %s added to configuration\n", p->RIOHosts[host].Mapping[MapP->ID2 - 1].Name);
  668. else
  669. rio_dprintk(RIO_DEBUG_TABLE, "RTA %s added to configuration\n", MapP->Name);
  670. return 0;
  671. }
  672. }
  673. p->RIOError.Error = UNKNOWN_HOST_NUMBER;
  674. rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
  675. return -ENXIO;
  676. }
  677. int RIOReMapPorts(struct rio_info *p, struct Host *HostP, struct Map *HostMapP)
  678. {
  679. struct Port *PortP;
  680. uint SubEnt;
  681. uint HostPort;
  682. uint SysPort;
  683. ushort RtaType;
  684. unsigned long flags;
  685. rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d to id %d\n", (int) HostMapP->SysPort, HostMapP->ID);
  686. /*
  687. ** We need to tell the UnixRups which sysport the rup corresponds to
  688. */
  689. HostP->UnixRups[HostMapP->ID - 1].BaseSysPort = HostMapP->SysPort;
  690. if (HostMapP->SysPort == NO_PORT)
  691. return (0);
  692. RtaType = GetUnitType(HostMapP->RtaUniqueNum);
  693. rio_dprintk(RIO_DEBUG_TABLE, "Mapping sysport %d-%d\n", (int) HostMapP->SysPort, (int) HostMapP->SysPort + PORTS_PER_RTA - 1);
  694. /*
  695. ** now map each of its eight ports
  696. */
  697. for (SubEnt = 0; SubEnt < PORTS_PER_RTA; SubEnt++) {
  698. rio_dprintk(RIO_DEBUG_TABLE, "subent = %d, HostMapP->SysPort = %d\n", SubEnt, (int) HostMapP->SysPort);
  699. SysPort = HostMapP->SysPort + SubEnt; /* portnumber within system */
  700. /* portnumber on host */
  701. HostPort = (HostMapP->ID - 1) * PORTS_PER_RTA + SubEnt;
  702. rio_dprintk(RIO_DEBUG_TABLE, "c1 p = %p, p->rioPortp = %p\n", p, p->RIOPortp);
  703. PortP = p->RIOPortp[SysPort];
  704. rio_dprintk(RIO_DEBUG_TABLE, "Map port\n");
  705. /*
  706. ** Point at all the real neat data structures
  707. */
  708. rio_spin_lock_irqsave(&PortP->portSem, flags);
  709. PortP->HostP = HostP;
  710. PortP->Caddr = HostP->Caddr;
  711. /*
  712. ** The PhbP cannot be filled in yet
  713. ** unless the host has been booted
  714. */
  715. if ((HostP->Flags & RUN_STATE) == RC_RUNNING) {
  716. struct PHB *PhbP = PortP->PhbP = &HostP->PhbP[HostPort];
  717. PortP->TxAdd = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_add));
  718. PortP->TxStart = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_start));
  719. PortP->TxEnd = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->tx_end));
  720. PortP->RxRemove = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_remove));
  721. PortP->RxStart = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_start));
  722. PortP->RxEnd = (u16 *) RIO_PTR(HostP->Caddr, readw(&PhbP->rx_end));
  723. } else
  724. PortP->PhbP = NULL;
  725. /*
  726. ** port related flags
  727. */
  728. PortP->HostPort = HostPort;
  729. /*
  730. ** For each part of a 16 port RTA, RupNum is ID - 1.
  731. */
  732. PortP->RupNum = HostMapP->ID - 1;
  733. if (HostMapP->Flags & RTA16_SECOND_SLOT) {
  734. PortP->ID2 = HostMapP->ID2 - 1;
  735. PortP->SecondBlock = TRUE;
  736. } else {
  737. PortP->ID2 = 0;
  738. PortP->SecondBlock = FALSE;
  739. }
  740. PortP->RtaUniqueNum = HostMapP->RtaUniqueNum;
  741. /*
  742. ** If the port was already mapped then thats all we need to do.
  743. */
  744. if (PortP->Mapped) {
  745. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  746. continue;
  747. } else
  748. HostMapP->Flags &= ~RTA_NEWBOOT;
  749. PortP->State = 0;
  750. PortP->Config = 0;
  751. /*
  752. ** Check out the module type - if it is special (read only etc.)
  753. ** then we need to set flags in the PortP->Config.
  754. ** Note: For 16 port RTA, all ports are of the same type.
  755. */
  756. if (RtaType == TYPE_RTA16) {
  757. PortP->Config |= p->RIOModuleTypes[HostP->UnixRups[HostMapP->ID - 1].ModTypes].Flags[SubEnt % PORTS_PER_MODULE];
  758. } else {
  759. if (SubEnt < PORTS_PER_MODULE)
  760. PortP->Config |= p->RIOModuleTypes[LONYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
  761. else
  762. PortP->Config |= p->RIOModuleTypes[HINYBLE(HostP->UnixRups[HostMapP->ID - 1].ModTypes)].Flags[SubEnt % PORTS_PER_MODULE];
  763. }
  764. /*
  765. ** more port related flags
  766. */
  767. PortP->PortState = 0;
  768. PortP->ModemLines = 0;
  769. PortP->ModemState = 0;
  770. PortP->CookMode = COOK_WELL;
  771. PortP->ParamSem = 0;
  772. PortP->FlushCmdBodge = 0;
  773. PortP->WflushFlag = 0;
  774. PortP->MagicFlags = 0;
  775. PortP->Lock = 0;
  776. PortP->Store = 0;
  777. PortP->FirstOpen = 1;
  778. /*
  779. ** Buffers 'n things
  780. */
  781. PortP->RxDataStart = 0;
  782. PortP->Cor2Copy = 0;
  783. PortP->Name = &HostMapP->Name[0];
  784. PortP->statsGather = 0;
  785. PortP->txchars = 0;
  786. PortP->rxchars = 0;
  787. PortP->opens = 0;
  788. PortP->closes = 0;
  789. PortP->ioctls = 0;
  790. if (PortP->TxRingBuffer)
  791. memset(PortP->TxRingBuffer, 0, p->RIOBufferSize);
  792. else if (p->RIOBufferSize) {
  793. PortP->TxRingBuffer = kmalloc(p->RIOBufferSize, GFP_KERNEL);
  794. memset(PortP->TxRingBuffer, 0, p->RIOBufferSize);
  795. }
  796. PortP->TxBufferOut = 0;
  797. PortP->TxBufferIn = 0;
  798. PortP->Debug = 0;
  799. /*
  800. ** LastRxTgl stores the state of the rx toggle bit for this
  801. ** port, to be compared with the state of the next pkt received.
  802. ** If the same, we have received the same rx pkt from the RTA
  803. ** twice. Initialise to a value not equal to PHB_RX_TGL or 0.
  804. */
  805. PortP->LastRxTgl = ~(u8) PHB_RX_TGL;
  806. /*
  807. ** and mark the port as usable
  808. */
  809. PortP->Mapped = 1;
  810. rio_spin_unlock_irqrestore(&PortP->portSem, flags);
  811. }
  812. if (HostMapP->SysPort < p->RIOFirstPortsMapped)
  813. p->RIOFirstPortsMapped = HostMapP->SysPort;
  814. if (HostMapP->SysPort > p->RIOLastPortsMapped)
  815. p->RIOLastPortsMapped = HostMapP->SysPort;
  816. return 0;
  817. }
  818. int RIOChangeName(struct rio_info *p, struct Map *MapP)
  819. {
  820. int host;
  821. struct Map *HostMapP;
  822. char *sptr;
  823. rio_dprintk(RIO_DEBUG_TABLE, "Change name entry on host %x, rta %x, ID %d, Sysport %d\n", MapP->HostUniqueNum, MapP->RtaUniqueNum, MapP->ID, (int) MapP->SysPort);
  824. if (MapP->ID > MAX_RUP) {
  825. rio_dprintk(RIO_DEBUG_TABLE, "Bad ID in map entry!\n");
  826. p->RIOError.Error = ID_NUMBER_OUT_OF_RANGE;
  827. return -EINVAL;
  828. }
  829. MapP->Name[MAX_NAME_LEN - 1] = '\0';
  830. sptr = MapP->Name;
  831. while (*sptr) {
  832. if (*sptr < ' ' || *sptr > '~') {
  833. rio_dprintk(RIO_DEBUG_TABLE, "Name entry contains non-printing characters!\n");
  834. p->RIOError.Error = BAD_CHARACTER_IN_NAME;
  835. return -EINVAL;
  836. }
  837. sptr++;
  838. }
  839. for (host = 0; host < p->RIONumHosts; host++) {
  840. if (MapP->HostUniqueNum == p->RIOHosts[host].UniqueNum) {
  841. if ((p->RIOHosts[host].Flags & RUN_STATE) != RC_RUNNING) {
  842. p->RIOError.Error = HOST_NOT_RUNNING;
  843. return -ENXIO;
  844. }
  845. if (MapP->ID == 0) {
  846. CCOPY(MapP->Name, p->RIOHosts[host].Name, MAX_NAME_LEN);
  847. return 0;
  848. }
  849. HostMapP = &p->RIOHosts[host].Mapping[MapP->ID - 1];
  850. if (HostMapP->RtaUniqueNum != MapP->RtaUniqueNum) {
  851. p->RIOError.Error = RTA_NUMBER_WRONG;
  852. return -ENXIO;
  853. }
  854. CCOPY(MapP->Name, HostMapP->Name, MAX_NAME_LEN);
  855. return 0;
  856. }
  857. }
  858. p->RIOError.Error = UNKNOWN_HOST_NUMBER;
  859. rio_dprintk(RIO_DEBUG_TABLE, "Unknown host %x\n", MapP->HostUniqueNum);
  860. return -ENXIO;
  861. }