riotable.c 29 KB

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