riotable.c 29 KB

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