PageRenderTime 108ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/char/istallion.c

https://bitbucket.org/evzijst/gittest
C | 5276 lines | 3590 code | 777 blank | 909 comment | 755 complexity | 35cbe6dab5652e5cf384df0804d64b1d MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0
  1. /*****************************************************************************/
  2. /*
  3. * istallion.c -- stallion intelligent multiport serial driver.
  4. *
  5. * Copyright (C) 1996-1999 Stallion Technologies
  6. * Copyright (C) 1994-1996 Greg Ungerer.
  7. *
  8. * This code is loosely based on the Linux serial driver, written by
  9. * Linus Torvalds, Theodore T'so and others.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. /*****************************************************************************/
  26. #include <linux/config.h>
  27. #include <linux/module.h>
  28. #include <linux/slab.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/tty.h>
  31. #include <linux/tty_flip.h>
  32. #include <linux/serial.h>
  33. #include <linux/cdk.h>
  34. #include <linux/comstats.h>
  35. #include <linux/istallion.h>
  36. #include <linux/ioport.h>
  37. #include <linux/delay.h>
  38. #include <linux/init.h>
  39. #include <linux/devfs_fs_kernel.h>
  40. #include <linux/device.h>
  41. #include <linux/wait.h>
  42. #include <asm/io.h>
  43. #include <asm/uaccess.h>
  44. #ifdef CONFIG_PCI
  45. #include <linux/pci.h>
  46. #endif
  47. /*****************************************************************************/
  48. /*
  49. * Define different board types. Not all of the following board types
  50. * are supported by this driver. But I will use the standard "assigned"
  51. * board numbers. Currently supported boards are abbreviated as:
  52. * ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and
  53. * STAL = Stallion.
  54. */
  55. #define BRD_UNKNOWN 0
  56. #define BRD_STALLION 1
  57. #define BRD_BRUMBY4 2
  58. #define BRD_ONBOARD2 3
  59. #define BRD_ONBOARD 4
  60. #define BRD_BRUMBY8 5
  61. #define BRD_BRUMBY16 6
  62. #define BRD_ONBOARDE 7
  63. #define BRD_ONBOARD32 9
  64. #define BRD_ONBOARD2_32 10
  65. #define BRD_ONBOARDRS 11
  66. #define BRD_EASYIO 20
  67. #define BRD_ECH 21
  68. #define BRD_ECHMC 22
  69. #define BRD_ECP 23
  70. #define BRD_ECPE 24
  71. #define BRD_ECPMC 25
  72. #define BRD_ECHPCI 26
  73. #define BRD_ECH64PCI 27
  74. #define BRD_EASYIOPCI 28
  75. #define BRD_ECPPCI 29
  76. #define BRD_BRUMBY BRD_BRUMBY4
  77. /*
  78. * Define a configuration structure to hold the board configuration.
  79. * Need to set this up in the code (for now) with the boards that are
  80. * to be configured into the system. This is what needs to be modified
  81. * when adding/removing/modifying boards. Each line entry in the
  82. * stli_brdconf[] array is a board. Each line contains io/irq/memory
  83. * ranges for that board (as well as what type of board it is).
  84. * Some examples:
  85. * { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
  86. * This line will configure an EasyConnection 8/64 at io address 2a0,
  87. * and shared memory address of cc000. Multiple EasyConnection 8/64
  88. * boards can share the same shared memory address space. No interrupt
  89. * is required for this board type.
  90. * Another example:
  91. * { BRD_ECPE, 0x5000, 0, 0x80000000, 0, 0 },
  92. * This line will configure an EasyConnection 8/64 EISA in slot 5 and
  93. * shared memory address of 0x80000000 (2 GByte). Multiple
  94. * EasyConnection 8/64 EISA boards can share the same shared memory
  95. * address space. No interrupt is required for this board type.
  96. * Another example:
  97. * { BRD_ONBOARD, 0x240, 0, 0xd0000, 0, 0 },
  98. * This line will configure an ONboard (ISA type) at io address 240,
  99. * and shared memory address of d0000. Multiple ONboards can share
  100. * the same shared memory address space. No interrupt required.
  101. * Another example:
  102. * { BRD_BRUMBY4, 0x360, 0, 0xc8000, 0, 0 },
  103. * This line will configure a Brumby board (any number of ports!) at
  104. * io address 360 and shared memory address of c8000. All Brumby boards
  105. * configured into a system must have their own separate io and memory
  106. * addresses. No interrupt is required.
  107. * Another example:
  108. * { BRD_STALLION, 0x330, 0, 0xd0000, 0, 0 },
  109. * This line will configure an original Stallion board at io address 330
  110. * and shared memory address d0000 (this would only be valid for a "V4.0"
  111. * or Rev.O Stallion board). All Stallion boards configured into the
  112. * system must have their own separate io and memory addresses. No
  113. * interrupt is required.
  114. */
  115. typedef struct {
  116. int brdtype;
  117. int ioaddr1;
  118. int ioaddr2;
  119. unsigned long memaddr;
  120. int irq;
  121. int irqtype;
  122. } stlconf_t;
  123. static stlconf_t stli_brdconf[] = {
  124. /*{ BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },*/
  125. };
  126. static int stli_nrbrds = sizeof(stli_brdconf) / sizeof(stlconf_t);
  127. /*
  128. * There is some experimental EISA board detection code in this driver.
  129. * By default it is disabled, but for those that want to try it out,
  130. * then set the define below to be 1.
  131. */
  132. #define STLI_EISAPROBE 0
  133. /*****************************************************************************/
  134. /*
  135. * Define some important driver characteristics. Device major numbers
  136. * allocated as per Linux Device Registry.
  137. */
  138. #ifndef STL_SIOMEMMAJOR
  139. #define STL_SIOMEMMAJOR 28
  140. #endif
  141. #ifndef STL_SERIALMAJOR
  142. #define STL_SERIALMAJOR 24
  143. #endif
  144. #ifndef STL_CALLOUTMAJOR
  145. #define STL_CALLOUTMAJOR 25
  146. #endif
  147. /*****************************************************************************/
  148. /*
  149. * Define our local driver identity first. Set up stuff to deal with
  150. * all the local structures required by a serial tty driver.
  151. */
  152. static char *stli_drvtitle = "Stallion Intelligent Multiport Serial Driver";
  153. static char *stli_drvname = "istallion";
  154. static char *stli_drvversion = "5.6.0";
  155. static char *stli_serialname = "ttyE";
  156. static struct tty_driver *stli_serial;
  157. /*
  158. * We will need to allocate a temporary write buffer for chars that
  159. * come direct from user space. The problem is that a copy from user
  160. * space might cause a page fault (typically on a system that is
  161. * swapping!). All ports will share one buffer - since if the system
  162. * is already swapping a shared buffer won't make things any worse.
  163. */
  164. static char *stli_tmpwritebuf;
  165. static DECLARE_MUTEX(stli_tmpwritesem);
  166. #define STLI_TXBUFSIZE 4096
  167. /*
  168. * Use a fast local buffer for cooked characters. Typically a whole
  169. * bunch of cooked characters come in for a port, 1 at a time. So we
  170. * save those up into a local buffer, then write out the whole lot
  171. * with a large memcpy. Just use 1 buffer for all ports, since its
  172. * use it is only need for short periods of time by each port.
  173. */
  174. static char *stli_txcookbuf;
  175. static int stli_txcooksize;
  176. static int stli_txcookrealsize;
  177. static struct tty_struct *stli_txcooktty;
  178. /*
  179. * Define a local default termios struct. All ports will be created
  180. * with this termios initially. Basically all it defines is a raw port
  181. * at 9600 baud, 8 data bits, no parity, 1 stop bit.
  182. */
  183. static struct termios stli_deftermios = {
  184. .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
  185. .c_cc = INIT_C_CC,
  186. };
  187. /*
  188. * Define global stats structures. Not used often, and can be
  189. * re-used for each stats call.
  190. */
  191. static comstats_t stli_comstats;
  192. static combrd_t stli_brdstats;
  193. static asystats_t stli_cdkstats;
  194. static stlibrd_t stli_dummybrd;
  195. static stliport_t stli_dummyport;
  196. /*****************************************************************************/
  197. static stlibrd_t *stli_brds[STL_MAXBRDS];
  198. static int stli_shared;
  199. /*
  200. * Per board state flags. Used with the state field of the board struct.
  201. * Not really much here... All we need to do is keep track of whether
  202. * the board has been detected, and whether it is actually running a slave
  203. * or not.
  204. */
  205. #define BST_FOUND 0x1
  206. #define BST_STARTED 0x2
  207. /*
  208. * Define the set of port state flags. These are marked for internal
  209. * state purposes only, usually to do with the state of communications
  210. * with the slave. Most of them need to be updated atomically, so always
  211. * use the bit setting operations (unless protected by cli/sti).
  212. */
  213. #define ST_INITIALIZING 1
  214. #define ST_OPENING 2
  215. #define ST_CLOSING 3
  216. #define ST_CMDING 4
  217. #define ST_TXBUSY 5
  218. #define ST_RXING 6
  219. #define ST_DOFLUSHRX 7
  220. #define ST_DOFLUSHTX 8
  221. #define ST_DOSIGS 9
  222. #define ST_RXSTOP 10
  223. #define ST_GETSIGS 11
  224. /*
  225. * Define an array of board names as printable strings. Handy for
  226. * referencing boards when printing trace and stuff.
  227. */
  228. static char *stli_brdnames[] = {
  229. "Unknown",
  230. "Stallion",
  231. "Brumby",
  232. "ONboard-MC",
  233. "ONboard",
  234. "Brumby",
  235. "Brumby",
  236. "ONboard-EI",
  237. (char *) NULL,
  238. "ONboard",
  239. "ONboard-MC",
  240. "ONboard-MC",
  241. (char *) NULL,
  242. (char *) NULL,
  243. (char *) NULL,
  244. (char *) NULL,
  245. (char *) NULL,
  246. (char *) NULL,
  247. (char *) NULL,
  248. (char *) NULL,
  249. "EasyIO",
  250. "EC8/32-AT",
  251. "EC8/32-MC",
  252. "EC8/64-AT",
  253. "EC8/64-EI",
  254. "EC8/64-MC",
  255. "EC8/32-PCI",
  256. "EC8/64-PCI",
  257. "EasyIO-PCI",
  258. "EC/RA-PCI",
  259. };
  260. /*****************************************************************************/
  261. #ifdef MODULE
  262. /*
  263. * Define some string labels for arguments passed from the module
  264. * load line. These allow for easy board definitions, and easy
  265. * modification of the io, memory and irq resoucres.
  266. */
  267. static char *board0[8];
  268. static char *board1[8];
  269. static char *board2[8];
  270. static char *board3[8];
  271. static char **stli_brdsp[] = {
  272. (char **) &board0,
  273. (char **) &board1,
  274. (char **) &board2,
  275. (char **) &board3
  276. };
  277. /*
  278. * Define a set of common board names, and types. This is used to
  279. * parse any module arguments.
  280. */
  281. typedef struct stlibrdtype {
  282. char *name;
  283. int type;
  284. } stlibrdtype_t;
  285. static stlibrdtype_t stli_brdstr[] = {
  286. { "stallion", BRD_STALLION },
  287. { "1", BRD_STALLION },
  288. { "brumby", BRD_BRUMBY },
  289. { "brumby4", BRD_BRUMBY },
  290. { "brumby/4", BRD_BRUMBY },
  291. { "brumby-4", BRD_BRUMBY },
  292. { "brumby8", BRD_BRUMBY },
  293. { "brumby/8", BRD_BRUMBY },
  294. { "brumby-8", BRD_BRUMBY },
  295. { "brumby16", BRD_BRUMBY },
  296. { "brumby/16", BRD_BRUMBY },
  297. { "brumby-16", BRD_BRUMBY },
  298. { "2", BRD_BRUMBY },
  299. { "onboard2", BRD_ONBOARD2 },
  300. { "onboard-2", BRD_ONBOARD2 },
  301. { "onboard/2", BRD_ONBOARD2 },
  302. { "onboard-mc", BRD_ONBOARD2 },
  303. { "onboard/mc", BRD_ONBOARD2 },
  304. { "onboard-mca", BRD_ONBOARD2 },
  305. { "onboard/mca", BRD_ONBOARD2 },
  306. { "3", BRD_ONBOARD2 },
  307. { "onboard", BRD_ONBOARD },
  308. { "onboardat", BRD_ONBOARD },
  309. { "4", BRD_ONBOARD },
  310. { "onboarde", BRD_ONBOARDE },
  311. { "onboard-e", BRD_ONBOARDE },
  312. { "onboard/e", BRD_ONBOARDE },
  313. { "onboard-ei", BRD_ONBOARDE },
  314. { "onboard/ei", BRD_ONBOARDE },
  315. { "7", BRD_ONBOARDE },
  316. { "ecp", BRD_ECP },
  317. { "ecpat", BRD_ECP },
  318. { "ec8/64", BRD_ECP },
  319. { "ec8/64-at", BRD_ECP },
  320. { "ec8/64-isa", BRD_ECP },
  321. { "23", BRD_ECP },
  322. { "ecpe", BRD_ECPE },
  323. { "ecpei", BRD_ECPE },
  324. { "ec8/64-e", BRD_ECPE },
  325. { "ec8/64-ei", BRD_ECPE },
  326. { "24", BRD_ECPE },
  327. { "ecpmc", BRD_ECPMC },
  328. { "ec8/64-mc", BRD_ECPMC },
  329. { "ec8/64-mca", BRD_ECPMC },
  330. { "25", BRD_ECPMC },
  331. { "ecppci", BRD_ECPPCI },
  332. { "ec/ra", BRD_ECPPCI },
  333. { "ec/ra-pc", BRD_ECPPCI },
  334. { "ec/ra-pci", BRD_ECPPCI },
  335. { "29", BRD_ECPPCI },
  336. };
  337. /*
  338. * Define the module agruments.
  339. */
  340. MODULE_AUTHOR("Greg Ungerer");
  341. MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
  342. MODULE_LICENSE("GPL");
  343. MODULE_PARM(board0, "1-3s");
  344. MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
  345. MODULE_PARM(board1, "1-3s");
  346. MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
  347. MODULE_PARM(board2, "1-3s");
  348. MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
  349. MODULE_PARM(board3, "1-3s");
  350. MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
  351. #endif
  352. /*
  353. * Set up a default memory address table for EISA board probing.
  354. * The default addresses are all bellow 1Mbyte, which has to be the
  355. * case anyway. They should be safe, since we only read values from
  356. * them, and interrupts are disabled while we do it. If the higher
  357. * memory support is compiled in then we also try probing around
  358. * the 1Gb, 2Gb and 3Gb areas as well...
  359. */
  360. static unsigned long stli_eisamemprobeaddrs[] = {
  361. 0xc0000, 0xd0000, 0xe0000, 0xf0000,
  362. 0x80000000, 0x80010000, 0x80020000, 0x80030000,
  363. 0x40000000, 0x40010000, 0x40020000, 0x40030000,
  364. 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
  365. 0xff000000, 0xff010000, 0xff020000, 0xff030000,
  366. };
  367. static int stli_eisamempsize = sizeof(stli_eisamemprobeaddrs) / sizeof(unsigned long);
  368. int stli_eisaprobe = STLI_EISAPROBE;
  369. /*
  370. * Define the Stallion PCI vendor and device IDs.
  371. */
  372. #ifdef CONFIG_PCI
  373. #ifndef PCI_VENDOR_ID_STALLION
  374. #define PCI_VENDOR_ID_STALLION 0x124d
  375. #endif
  376. #ifndef PCI_DEVICE_ID_ECRA
  377. #define PCI_DEVICE_ID_ECRA 0x0004
  378. #endif
  379. static struct pci_device_id istallion_pci_tbl[] = {
  380. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  381. { 0 }
  382. };
  383. MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
  384. #endif /* CONFIG_PCI */
  385. /*****************************************************************************/
  386. /*
  387. * Hardware configuration info for ECP boards. These defines apply
  388. * to the directly accessible io ports of the ECP. There is a set of
  389. * defines for each ECP board type, ISA, EISA, MCA and PCI.
  390. */
  391. #define ECP_IOSIZE 4
  392. #define ECP_MEMSIZE (128 * 1024)
  393. #define ECP_PCIMEMSIZE (256 * 1024)
  394. #define ECP_ATPAGESIZE (4 * 1024)
  395. #define ECP_MCPAGESIZE (4 * 1024)
  396. #define ECP_EIPAGESIZE (64 * 1024)
  397. #define ECP_PCIPAGESIZE (64 * 1024)
  398. #define STL_EISAID 0x8c4e
  399. /*
  400. * Important defines for the ISA class of ECP board.
  401. */
  402. #define ECP_ATIREG 0
  403. #define ECP_ATCONFR 1
  404. #define ECP_ATMEMAR 2
  405. #define ECP_ATMEMPR 3
  406. #define ECP_ATSTOP 0x1
  407. #define ECP_ATINTENAB 0x10
  408. #define ECP_ATENABLE 0x20
  409. #define ECP_ATDISABLE 0x00
  410. #define ECP_ATADDRMASK 0x3f000
  411. #define ECP_ATADDRSHFT 12
  412. /*
  413. * Important defines for the EISA class of ECP board.
  414. */
  415. #define ECP_EIIREG 0
  416. #define ECP_EIMEMARL 1
  417. #define ECP_EICONFR 2
  418. #define ECP_EIMEMARH 3
  419. #define ECP_EIENABLE 0x1
  420. #define ECP_EIDISABLE 0x0
  421. #define ECP_EISTOP 0x4
  422. #define ECP_EIEDGE 0x00
  423. #define ECP_EILEVEL 0x80
  424. #define ECP_EIADDRMASKL 0x00ff0000
  425. #define ECP_EIADDRSHFTL 16
  426. #define ECP_EIADDRMASKH 0xff000000
  427. #define ECP_EIADDRSHFTH 24
  428. #define ECP_EIBRDENAB 0xc84
  429. #define ECP_EISAID 0x4
  430. /*
  431. * Important defines for the Micro-channel class of ECP board.
  432. * (It has a lot in common with the ISA boards.)
  433. */
  434. #define ECP_MCIREG 0
  435. #define ECP_MCCONFR 1
  436. #define ECP_MCSTOP 0x20
  437. #define ECP_MCENABLE 0x80
  438. #define ECP_MCDISABLE 0x00
  439. /*
  440. * Important defines for the PCI class of ECP board.
  441. * (It has a lot in common with the other ECP boards.)
  442. */
  443. #define ECP_PCIIREG 0
  444. #define ECP_PCICONFR 1
  445. #define ECP_PCISTOP 0x01
  446. /*
  447. * Hardware configuration info for ONboard and Brumby boards. These
  448. * defines apply to the directly accessible io ports of these boards.
  449. */
  450. #define ONB_IOSIZE 16
  451. #define ONB_MEMSIZE (64 * 1024)
  452. #define ONB_ATPAGESIZE (64 * 1024)
  453. #define ONB_MCPAGESIZE (64 * 1024)
  454. #define ONB_EIMEMSIZE (128 * 1024)
  455. #define ONB_EIPAGESIZE (64 * 1024)
  456. /*
  457. * Important defines for the ISA class of ONboard board.
  458. */
  459. #define ONB_ATIREG 0
  460. #define ONB_ATMEMAR 1
  461. #define ONB_ATCONFR 2
  462. #define ONB_ATSTOP 0x4
  463. #define ONB_ATENABLE 0x01
  464. #define ONB_ATDISABLE 0x00
  465. #define ONB_ATADDRMASK 0xff0000
  466. #define ONB_ATADDRSHFT 16
  467. #define ONB_MEMENABLO 0
  468. #define ONB_MEMENABHI 0x02
  469. /*
  470. * Important defines for the EISA class of ONboard board.
  471. */
  472. #define ONB_EIIREG 0
  473. #define ONB_EIMEMARL 1
  474. #define ONB_EICONFR 2
  475. #define ONB_EIMEMARH 3
  476. #define ONB_EIENABLE 0x1
  477. #define ONB_EIDISABLE 0x0
  478. #define ONB_EISTOP 0x4
  479. #define ONB_EIEDGE 0x00
  480. #define ONB_EILEVEL 0x80
  481. #define ONB_EIADDRMASKL 0x00ff0000
  482. #define ONB_EIADDRSHFTL 16
  483. #define ONB_EIADDRMASKH 0xff000000
  484. #define ONB_EIADDRSHFTH 24
  485. #define ONB_EIBRDENAB 0xc84
  486. #define ONB_EISAID 0x1
  487. /*
  488. * Important defines for the Brumby boards. They are pretty simple,
  489. * there is not much that is programmably configurable.
  490. */
  491. #define BBY_IOSIZE 16
  492. #define BBY_MEMSIZE (64 * 1024)
  493. #define BBY_PAGESIZE (16 * 1024)
  494. #define BBY_ATIREG 0
  495. #define BBY_ATCONFR 1
  496. #define BBY_ATSTOP 0x4
  497. /*
  498. * Important defines for the Stallion boards. They are pretty simple,
  499. * there is not much that is programmably configurable.
  500. */
  501. #define STAL_IOSIZE 16
  502. #define STAL_MEMSIZE (64 * 1024)
  503. #define STAL_PAGESIZE (64 * 1024)
  504. /*
  505. * Define the set of status register values for EasyConnection panels.
  506. * The signature will return with the status value for each panel. From
  507. * this we can determine what is attached to the board - before we have
  508. * actually down loaded any code to it.
  509. */
  510. #define ECH_PNLSTATUS 2
  511. #define ECH_PNL16PORT 0x20
  512. #define ECH_PNLIDMASK 0x07
  513. #define ECH_PNLXPID 0x40
  514. #define ECH_PNLINTRPEND 0x80
  515. /*
  516. * Define some macros to do things to the board. Even those these boards
  517. * are somewhat related there is often significantly different ways of
  518. * doing some operation on it (like enable, paging, reset, etc). So each
  519. * board class has a set of functions which do the commonly required
  520. * operations. The macros below basically just call these functions,
  521. * generally checking for a NULL function - which means that the board
  522. * needs nothing done to it to achieve this operation!
  523. */
  524. #define EBRDINIT(brdp) \
  525. if (brdp->init != NULL) \
  526. (* brdp->init)(brdp)
  527. #define EBRDENABLE(brdp) \
  528. if (brdp->enable != NULL) \
  529. (* brdp->enable)(brdp);
  530. #define EBRDDISABLE(brdp) \
  531. if (brdp->disable != NULL) \
  532. (* brdp->disable)(brdp);
  533. #define EBRDINTR(brdp) \
  534. if (brdp->intr != NULL) \
  535. (* brdp->intr)(brdp);
  536. #define EBRDRESET(brdp) \
  537. if (brdp->reset != NULL) \
  538. (* brdp->reset)(brdp);
  539. #define EBRDGETMEMPTR(brdp,offset) \
  540. (* brdp->getmemptr)(brdp, offset, __LINE__)
  541. /*
  542. * Define the maximal baud rate, and the default baud base for ports.
  543. */
  544. #define STL_MAXBAUD 460800
  545. #define STL_BAUDBASE 115200
  546. #define STL_CLOSEDELAY (5 * HZ / 10)
  547. /*****************************************************************************/
  548. /*
  549. * Define macros to extract a brd or port number from a minor number.
  550. */
  551. #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
  552. #define MINOR2PORT(min) ((min) & 0x3f)
  553. /*
  554. * Define a baud rate table that converts termios baud rate selector
  555. * into the actual baud rate value. All baud rate calculations are based
  556. * on the actual baud rate required.
  557. */
  558. static unsigned int stli_baudrates[] = {
  559. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
  560. 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
  561. };
  562. /*****************************************************************************/
  563. /*
  564. * Define some handy local macros...
  565. */
  566. #undef MIN
  567. #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
  568. #undef TOLOWER
  569. #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
  570. /*****************************************************************************/
  571. /*
  572. * Prototype all functions in this driver!
  573. */
  574. #ifdef MODULE
  575. static void stli_argbrds(void);
  576. static int stli_parsebrd(stlconf_t *confp, char **argp);
  577. static unsigned long stli_atol(char *str);
  578. #endif
  579. int stli_init(void);
  580. static int stli_open(struct tty_struct *tty, struct file *filp);
  581. static void stli_close(struct tty_struct *tty, struct file *filp);
  582. static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
  583. static void stli_putchar(struct tty_struct *tty, unsigned char ch);
  584. static void stli_flushchars(struct tty_struct *tty);
  585. static int stli_writeroom(struct tty_struct *tty);
  586. static int stli_charsinbuffer(struct tty_struct *tty);
  587. static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
  588. static void stli_settermios(struct tty_struct *tty, struct termios *old);
  589. static void stli_throttle(struct tty_struct *tty);
  590. static void stli_unthrottle(struct tty_struct *tty);
  591. static void stli_stop(struct tty_struct *tty);
  592. static void stli_start(struct tty_struct *tty);
  593. static void stli_flushbuffer(struct tty_struct *tty);
  594. static void stli_breakctl(struct tty_struct *tty, int state);
  595. static void stli_waituntilsent(struct tty_struct *tty, int timeout);
  596. static void stli_sendxchar(struct tty_struct *tty, char ch);
  597. static void stli_hangup(struct tty_struct *tty);
  598. static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos);
  599. static int stli_brdinit(stlibrd_t *brdp);
  600. static int stli_startbrd(stlibrd_t *brdp);
  601. static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
  602. static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
  603. static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
  604. static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp);
  605. static void stli_poll(unsigned long arg);
  606. static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
  607. static int stli_initopen(stlibrd_t *brdp, stliport_t *portp);
  608. static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
  609. static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
  610. static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp);
  611. static void stli_dohangup(void *arg);
  612. static int stli_setport(stliport_t *portp);
  613. static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
  614. static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
  615. static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp);
  616. static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
  617. static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
  618. static long stli_mktiocm(unsigned long sigvalue);
  619. static void stli_read(stlibrd_t *brdp, stliport_t *portp);
  620. static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp);
  621. static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp);
  622. static int stli_getbrdstats(combrd_t __user *bp);
  623. static int stli_getportstats(stliport_t *portp, comstats_t __user *cp);
  624. static int stli_portcmdstats(stliport_t *portp);
  625. static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp);
  626. static int stli_getportstruct(stliport_t __user *arg);
  627. static int stli_getbrdstruct(stlibrd_t __user *arg);
  628. static void *stli_memalloc(int len);
  629. static stlibrd_t *stli_allocbrd(void);
  630. static void stli_ecpinit(stlibrd_t *brdp);
  631. static void stli_ecpenable(stlibrd_t *brdp);
  632. static void stli_ecpdisable(stlibrd_t *brdp);
  633. static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  634. static void stli_ecpreset(stlibrd_t *brdp);
  635. static void stli_ecpintr(stlibrd_t *brdp);
  636. static void stli_ecpeiinit(stlibrd_t *brdp);
  637. static void stli_ecpeienable(stlibrd_t *brdp);
  638. static void stli_ecpeidisable(stlibrd_t *brdp);
  639. static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  640. static void stli_ecpeireset(stlibrd_t *brdp);
  641. static void stli_ecpmcenable(stlibrd_t *brdp);
  642. static void stli_ecpmcdisable(stlibrd_t *brdp);
  643. static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  644. static void stli_ecpmcreset(stlibrd_t *brdp);
  645. static void stli_ecppciinit(stlibrd_t *brdp);
  646. static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  647. static void stli_ecppcireset(stlibrd_t *brdp);
  648. static void stli_onbinit(stlibrd_t *brdp);
  649. static void stli_onbenable(stlibrd_t *brdp);
  650. static void stli_onbdisable(stlibrd_t *brdp);
  651. static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  652. static void stli_onbreset(stlibrd_t *brdp);
  653. static void stli_onbeinit(stlibrd_t *brdp);
  654. static void stli_onbeenable(stlibrd_t *brdp);
  655. static void stli_onbedisable(stlibrd_t *brdp);
  656. static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  657. static void stli_onbereset(stlibrd_t *brdp);
  658. static void stli_bbyinit(stlibrd_t *brdp);
  659. static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  660. static void stli_bbyreset(stlibrd_t *brdp);
  661. static void stli_stalinit(stlibrd_t *brdp);
  662. static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  663. static void stli_stalreset(stlibrd_t *brdp);
  664. static stliport_t *stli_getport(int brdnr, int panelnr, int portnr);
  665. static int stli_initecp(stlibrd_t *brdp);
  666. static int stli_initonb(stlibrd_t *brdp);
  667. static int stli_eisamemprobe(stlibrd_t *brdp);
  668. static int stli_initports(stlibrd_t *brdp);
  669. #ifdef CONFIG_PCI
  670. static int stli_initpcibrd(int brdtype, struct pci_dev *devp);
  671. #endif
  672. /*****************************************************************************/
  673. /*
  674. * Define the driver info for a user level shared memory device. This
  675. * device will work sort of like the /dev/kmem device - except that it
  676. * will give access to the shared memory on the Stallion intelligent
  677. * board. This is also a very useful debugging tool.
  678. */
  679. static struct file_operations stli_fsiomem = {
  680. .owner = THIS_MODULE,
  681. .read = stli_memread,
  682. .write = stli_memwrite,
  683. .ioctl = stli_memioctl,
  684. };
  685. /*****************************************************************************/
  686. /*
  687. * Define a timer_list entry for our poll routine. The slave board
  688. * is polled every so often to see if anything needs doing. This is
  689. * much cheaper on host cpu than using interrupts. It turns out to
  690. * not increase character latency by much either...
  691. */
  692. static struct timer_list stli_timerlist = TIMER_INITIALIZER(stli_poll, 0, 0);
  693. static int stli_timeron;
  694. /*
  695. * Define the calculation for the timeout routine.
  696. */
  697. #define STLI_TIMEOUT (jiffies + 1)
  698. /*****************************************************************************/
  699. static struct class_simple *istallion_class;
  700. #ifdef MODULE
  701. /*
  702. * Loadable module initialization stuff.
  703. */
  704. static int __init istallion_module_init(void)
  705. {
  706. unsigned long flags;
  707. #ifdef DEBUG
  708. printk("init_module()\n");
  709. #endif
  710. save_flags(flags);
  711. cli();
  712. stli_init();
  713. restore_flags(flags);
  714. return(0);
  715. }
  716. /*****************************************************************************/
  717. static void __exit istallion_module_exit(void)
  718. {
  719. stlibrd_t *brdp;
  720. stliport_t *portp;
  721. unsigned long flags;
  722. int i, j;
  723. #ifdef DEBUG
  724. printk("cleanup_module()\n");
  725. #endif
  726. printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
  727. stli_drvversion);
  728. save_flags(flags);
  729. cli();
  730. /*
  731. * Free up all allocated resources used by the ports. This includes
  732. * memory and interrupts.
  733. */
  734. if (stli_timeron) {
  735. stli_timeron = 0;
  736. del_timer(&stli_timerlist);
  737. }
  738. i = tty_unregister_driver(stli_serial);
  739. if (i) {
  740. printk("STALLION: failed to un-register tty driver, "
  741. "errno=%d\n", -i);
  742. restore_flags(flags);
  743. return;
  744. }
  745. put_tty_driver(stli_serial);
  746. for (i = 0; i < 4; i++) {
  747. devfs_remove("staliomem/%d", i);
  748. class_simple_device_remove(MKDEV(STL_SIOMEMMAJOR, i));
  749. }
  750. devfs_remove("staliomem");
  751. class_simple_destroy(istallion_class);
  752. if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
  753. printk("STALLION: failed to un-register serial memory device, "
  754. "errno=%d\n", -i);
  755. if (stli_tmpwritebuf != (char *) NULL)
  756. kfree(stli_tmpwritebuf);
  757. if (stli_txcookbuf != (char *) NULL)
  758. kfree(stli_txcookbuf);
  759. for (i = 0; (i < stli_nrbrds); i++) {
  760. if ((brdp = stli_brds[i]) == (stlibrd_t *) NULL)
  761. continue;
  762. for (j = 0; (j < STL_MAXPORTS); j++) {
  763. portp = brdp->ports[j];
  764. if (portp != (stliport_t *) NULL) {
  765. if (portp->tty != (struct tty_struct *) NULL)
  766. tty_hangup(portp->tty);
  767. kfree(portp);
  768. }
  769. }
  770. iounmap(brdp->membase);
  771. if (brdp->iosize > 0)
  772. release_region(brdp->iobase, brdp->iosize);
  773. kfree(brdp);
  774. stli_brds[i] = (stlibrd_t *) NULL;
  775. }
  776. restore_flags(flags);
  777. }
  778. module_init(istallion_module_init);
  779. module_exit(istallion_module_exit);
  780. /*****************************************************************************/
  781. /*
  782. * Check for any arguments passed in on the module load command line.
  783. */
  784. static void stli_argbrds(void)
  785. {
  786. stlconf_t conf;
  787. stlibrd_t *brdp;
  788. int nrargs, i;
  789. #ifdef DEBUG
  790. printk("stli_argbrds()\n");
  791. #endif
  792. nrargs = sizeof(stli_brdsp) / sizeof(char **);
  793. for (i = stli_nrbrds; (i < nrargs); i++) {
  794. memset(&conf, 0, sizeof(conf));
  795. if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
  796. continue;
  797. if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
  798. continue;
  799. stli_nrbrds = i + 1;
  800. brdp->brdnr = i;
  801. brdp->brdtype = conf.brdtype;
  802. brdp->iobase = conf.ioaddr1;
  803. brdp->memaddr = conf.memaddr;
  804. stli_brdinit(brdp);
  805. }
  806. }
  807. /*****************************************************************************/
  808. /*
  809. * Convert an ascii string number into an unsigned long.
  810. */
  811. static unsigned long stli_atol(char *str)
  812. {
  813. unsigned long val;
  814. int base, c;
  815. char *sp;
  816. val = 0;
  817. sp = str;
  818. if ((*sp == '0') && (*(sp+1) == 'x')) {
  819. base = 16;
  820. sp += 2;
  821. } else if (*sp == '0') {
  822. base = 8;
  823. sp++;
  824. } else {
  825. base = 10;
  826. }
  827. for (; (*sp != 0); sp++) {
  828. c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
  829. if ((c < 0) || (c >= base)) {
  830. printk("STALLION: invalid argument %s\n", str);
  831. val = 0;
  832. break;
  833. }
  834. val = (val * base) + c;
  835. }
  836. return(val);
  837. }
  838. /*****************************************************************************/
  839. /*
  840. * Parse the supplied argument string, into the board conf struct.
  841. */
  842. static int stli_parsebrd(stlconf_t *confp, char **argp)
  843. {
  844. char *sp;
  845. int nrbrdnames, i;
  846. #ifdef DEBUG
  847. printk("stli_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
  848. #endif
  849. if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
  850. return(0);
  851. for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
  852. *sp = TOLOWER(*sp);
  853. nrbrdnames = sizeof(stli_brdstr) / sizeof(stlibrdtype_t);
  854. for (i = 0; (i < nrbrdnames); i++) {
  855. if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
  856. break;
  857. }
  858. if (i >= nrbrdnames) {
  859. printk("STALLION: unknown board name, %s?\n", argp[0]);
  860. return(0);
  861. }
  862. confp->brdtype = stli_brdstr[i].type;
  863. if ((argp[1] != (char *) NULL) && (*argp[1] != 0))
  864. confp->ioaddr1 = stli_atol(argp[1]);
  865. if ((argp[2] != (char *) NULL) && (*argp[2] != 0))
  866. confp->memaddr = stli_atol(argp[2]);
  867. return(1);
  868. }
  869. #endif
  870. /*****************************************************************************/
  871. /*
  872. * Local driver kernel malloc routine.
  873. */
  874. static void *stli_memalloc(int len)
  875. {
  876. return((void *) kmalloc(len, GFP_KERNEL));
  877. }
  878. /*****************************************************************************/
  879. static int stli_open(struct tty_struct *tty, struct file *filp)
  880. {
  881. stlibrd_t *brdp;
  882. stliport_t *portp;
  883. unsigned int minordev;
  884. int brdnr, portnr, rc;
  885. #ifdef DEBUG
  886. printk("stli_open(tty=%x,filp=%x): device=%s\n", (int) tty,
  887. (int) filp, tty->name);
  888. #endif
  889. minordev = tty->index;
  890. brdnr = MINOR2BRD(minordev);
  891. if (brdnr >= stli_nrbrds)
  892. return(-ENODEV);
  893. brdp = stli_brds[brdnr];
  894. if (brdp == (stlibrd_t *) NULL)
  895. return(-ENODEV);
  896. if ((brdp->state & BST_STARTED) == 0)
  897. return(-ENODEV);
  898. portnr = MINOR2PORT(minordev);
  899. if ((portnr < 0) || (portnr > brdp->nrports))
  900. return(-ENODEV);
  901. portp = brdp->ports[portnr];
  902. if (portp == (stliport_t *) NULL)
  903. return(-ENODEV);
  904. if (portp->devnr < 1)
  905. return(-ENODEV);
  906. /*
  907. * Check if this port is in the middle of closing. If so then wait
  908. * until it is closed then return error status based on flag settings.
  909. * The sleep here does not need interrupt protection since the wakeup
  910. * for it is done with the same context.
  911. */
  912. if (portp->flags & ASYNC_CLOSING) {
  913. interruptible_sleep_on(&portp->close_wait);
  914. if (portp->flags & ASYNC_HUP_NOTIFY)
  915. return(-EAGAIN);
  916. return(-ERESTARTSYS);
  917. }
  918. /*
  919. * On the first open of the device setup the port hardware, and
  920. * initialize the per port data structure. Since initializing the port
  921. * requires several commands to the board we will need to wait for any
  922. * other open that is already initializing the port.
  923. */
  924. portp->tty = tty;
  925. tty->driver_data = portp;
  926. portp->refcount++;
  927. wait_event_interruptible(portp->raw_wait,
  928. !test_bit(ST_INITIALIZING, &portp->state));
  929. if (signal_pending(current))
  930. return(-ERESTARTSYS);
  931. if ((portp->flags & ASYNC_INITIALIZED) == 0) {
  932. set_bit(ST_INITIALIZING, &portp->state);
  933. if ((rc = stli_initopen(brdp, portp)) >= 0) {
  934. portp->flags |= ASYNC_INITIALIZED;
  935. clear_bit(TTY_IO_ERROR, &tty->flags);
  936. }
  937. clear_bit(ST_INITIALIZING, &portp->state);
  938. wake_up_interruptible(&portp->raw_wait);
  939. if (rc < 0)
  940. return(rc);
  941. }
  942. /*
  943. * Check if this port is in the middle of closing. If so then wait
  944. * until it is closed then return error status, based on flag settings.
  945. * The sleep here does not need interrupt protection since the wakeup
  946. * for it is done with the same context.
  947. */
  948. if (portp->flags & ASYNC_CLOSING) {
  949. interruptible_sleep_on(&portp->close_wait);
  950. if (portp->flags & ASYNC_HUP_NOTIFY)
  951. return(-EAGAIN);
  952. return(-ERESTARTSYS);
  953. }
  954. /*
  955. * Based on type of open being done check if it can overlap with any
  956. * previous opens still in effect. If we are a normal serial device
  957. * then also we might have to wait for carrier.
  958. */
  959. if (!(filp->f_flags & O_NONBLOCK)) {
  960. if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
  961. return(rc);
  962. }
  963. portp->flags |= ASYNC_NORMAL_ACTIVE;
  964. return(0);
  965. }
  966. /*****************************************************************************/
  967. static void stli_close(struct tty_struct *tty, struct file *filp)
  968. {
  969. stlibrd_t *brdp;
  970. stliport_t *portp;
  971. unsigned long flags;
  972. #ifdef DEBUG
  973. printk("stli_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
  974. #endif
  975. portp = tty->driver_data;
  976. if (portp == (stliport_t *) NULL)
  977. return;
  978. save_flags(flags);
  979. cli();
  980. if (tty_hung_up_p(filp)) {
  981. restore_flags(flags);
  982. return;
  983. }
  984. if ((tty->count == 1) && (portp->refcount != 1))
  985. portp->refcount = 1;
  986. if (portp->refcount-- > 1) {
  987. restore_flags(flags);
  988. return;
  989. }
  990. portp->flags |= ASYNC_CLOSING;
  991. /*
  992. * May want to wait for data to drain before closing. The BUSY flag
  993. * keeps track of whether we are still transmitting or not. It is
  994. * updated by messages from the slave - indicating when all chars
  995. * really have drained.
  996. */
  997. if (tty == stli_txcooktty)
  998. stli_flushchars(tty);
  999. tty->closing = 1;
  1000. if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  1001. tty_wait_until_sent(tty, portp->closing_wait);
  1002. portp->flags &= ~ASYNC_INITIALIZED;
  1003. brdp = stli_brds[portp->brdnr];
  1004. stli_rawclose(brdp, portp, 0, 0);
  1005. if (tty->termios->c_cflag & HUPCL) {
  1006. stli_mkasysigs(&portp->asig, 0, 0);
  1007. if (test_bit(ST_CMDING, &portp->state))
  1008. set_bit(ST_DOSIGS, &portp->state);
  1009. else
  1010. stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
  1011. sizeof(asysigs_t), 0);
  1012. }
  1013. clear_bit(ST_TXBUSY, &portp->state);
  1014. clear_bit(ST_RXSTOP, &portp->state);
  1015. set_bit(TTY_IO_ERROR, &tty->flags);
  1016. if (tty->ldisc.flush_buffer)
  1017. (tty->ldisc.flush_buffer)(tty);
  1018. set_bit(ST_DOFLUSHRX, &portp->state);
  1019. stli_flushbuffer(tty);
  1020. tty->closing = 0;
  1021. portp->tty = (struct tty_struct *) NULL;
  1022. if (portp->openwaitcnt) {
  1023. if (portp->close_delay)
  1024. msleep_interruptible(jiffies_to_msecs(portp->close_delay));
  1025. wake_up_interruptible(&portp->open_wait);
  1026. }
  1027. portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  1028. wake_up_interruptible(&portp->close_wait);
  1029. restore_flags(flags);
  1030. }
  1031. /*****************************************************************************/
  1032. /*
  1033. * Carry out first open operations on a port. This involves a number of
  1034. * commands to be sent to the slave. We need to open the port, set the
  1035. * notification events, set the initial port settings, get and set the
  1036. * initial signal values. We sleep and wait in between each one. But
  1037. * this still all happens pretty quickly.
  1038. */
  1039. static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
  1040. {
  1041. struct tty_struct *tty;
  1042. asynotify_t nt;
  1043. asyport_t aport;
  1044. int rc;
  1045. #ifdef DEBUG
  1046. printk("stli_initopen(brdp=%x,portp=%x)\n", (int) brdp, (int) portp);
  1047. #endif
  1048. if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
  1049. return(rc);
  1050. memset(&nt, 0, sizeof(asynotify_t));
  1051. nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
  1052. nt.signal = SG_DCD;
  1053. if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
  1054. sizeof(asynotify_t), 0)) < 0)
  1055. return(rc);
  1056. tty = portp->tty;
  1057. if (tty == (struct tty_struct *) NULL)
  1058. return(-ENODEV);
  1059. stli_mkasyport(portp, &aport, tty->termios);
  1060. if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
  1061. sizeof(asyport_t), 0)) < 0)
  1062. return(rc);
  1063. set_bit(ST_GETSIGS, &portp->state);
  1064. if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
  1065. sizeof(asysigs_t), 1)) < 0)
  1066. return(rc);
  1067. if (test_and_clear_bit(ST_GETSIGS, &portp->state))
  1068. portp->sigs = stli_mktiocm(portp->asig.sigvalue);
  1069. stli_mkasysigs(&portp->asig, 1, 1);
  1070. if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1071. sizeof(asysigs_t), 0)) < 0)
  1072. return(rc);
  1073. return(0);
  1074. }
  1075. /*****************************************************************************/
  1076. /*
  1077. * Send an open message to the slave. This will sleep waiting for the
  1078. * acknowledgement, so must have user context. We need to co-ordinate
  1079. * with close events here, since we don't want open and close events
  1080. * to overlap.
  1081. */
  1082. static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
  1083. {
  1084. volatile cdkhdr_t *hdrp;
  1085. volatile cdkctrl_t *cp;
  1086. volatile unsigned char *bits;
  1087. unsigned long flags;
  1088. int rc;
  1089. #ifdef DEBUG
  1090. printk("stli_rawopen(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
  1091. (int) brdp, (int) portp, (int) arg, wait);
  1092. #endif
  1093. /*
  1094. * Send a message to the slave to open this port.
  1095. */
  1096. save_flags(flags);
  1097. cli();
  1098. /*
  1099. * Slave is already closing this port. This can happen if a hangup
  1100. * occurs on this port. So we must wait until it is complete. The
  1101. * order of opens and closes may not be preserved across shared
  1102. * memory, so we must wait until it is complete.
  1103. */
  1104. wait_event_interruptible(portp->raw_wait,
  1105. !test_bit(ST_CLOSING, &portp->state));
  1106. if (signal_pending(current)) {
  1107. restore_flags(flags);
  1108. return -ERESTARTSYS;
  1109. }
  1110. /*
  1111. * Everything is ready now, so write the open message into shared
  1112. * memory. Once the message is in set the service bits to say that
  1113. * this port wants service.
  1114. */
  1115. EBRDENABLE(brdp);
  1116. cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  1117. cp->openarg = arg;
  1118. cp->open = 1;
  1119. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1120. bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
  1121. portp->portidx;
  1122. *bits |= portp->portbit;
  1123. EBRDDISABLE(brdp);
  1124. if (wait == 0) {
  1125. restore_flags(flags);
  1126. return(0);
  1127. }
  1128. /*
  1129. * Slave is in action, so now we must wait for the open acknowledgment
  1130. * to come back.
  1131. */
  1132. rc = 0;
  1133. set_bit(ST_OPENING, &portp->state);
  1134. wait_event_interruptible(portp->raw_wait,
  1135. !test_bit(ST_OPENING, &portp->state));
  1136. if (signal_pending(current))
  1137. rc = -ERESTARTSYS;
  1138. restore_flags(flags);
  1139. if ((rc == 0) && (portp->rc != 0))
  1140. rc = -EIO;
  1141. return(rc);
  1142. }
  1143. /*****************************************************************************/
  1144. /*
  1145. * Send a close message to the slave. Normally this will sleep waiting
  1146. * for the acknowledgement, but if wait parameter is 0 it will not. If
  1147. * wait is true then must have user context (to sleep).
  1148. */
  1149. static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
  1150. {
  1151. volatile cdkhdr_t *hdrp;
  1152. volatile cdkctrl_t *cp;
  1153. volatile unsigned char *bits;
  1154. unsigned long flags;
  1155. int rc;
  1156. #ifdef DEBUG
  1157. printk("stli_rawclose(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
  1158. (int) brdp, (int) portp, (int) arg, wait);
  1159. #endif
  1160. save_flags(flags);
  1161. cli();
  1162. /*
  1163. * Slave is already closing this port. This can happen if a hangup
  1164. * occurs on this port.
  1165. */
  1166. if (wait) {
  1167. wait_event_interruptible(portp->raw_wait,
  1168. !test_bit(ST_CLOSING, &portp->state));
  1169. if (signal_pending(current)) {
  1170. restore_flags(flags);
  1171. return -ERESTARTSYS;
  1172. }
  1173. }
  1174. /*
  1175. * Write the close command into shared memory.
  1176. */
  1177. EBRDENABLE(brdp);
  1178. cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  1179. cp->closearg = arg;
  1180. cp->close = 1;
  1181. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1182. bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
  1183. portp->portidx;
  1184. *bits |= portp->portbit;
  1185. EBRDDISABLE(brdp);
  1186. set_bit(ST_CLOSING, &portp->state);
  1187. if (wait == 0) {
  1188. restore_flags(flags);
  1189. return(0);
  1190. }
  1191. /*
  1192. * Slave is in action, so now we must wait for the open acknowledgment
  1193. * to come back.
  1194. */
  1195. rc = 0;
  1196. wait_event_interruptible(portp->raw_wait,
  1197. !test_bit(ST_CLOSING, &portp->state));
  1198. if (signal_pending(current))
  1199. rc = -ERESTARTSYS;
  1200. restore_flags(flags);
  1201. if ((rc == 0) && (portp->rc != 0))
  1202. rc = -EIO;
  1203. return(rc);
  1204. }
  1205. /*****************************************************************************/
  1206. /*
  1207. * Send a command to the slave and wait for the response. This must
  1208. * have user context (it sleeps). This routine is generic in that it
  1209. * can send any type of command. Its purpose is to wait for that command
  1210. * to complete (as opposed to initiating the command then returning).
  1211. */
  1212. static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
  1213. {
  1214. unsigned long flags;
  1215. #ifdef DEBUG
  1216. printk("stli_cmdwait(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
  1217. "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
  1218. (int) arg, size, copyback);
  1219. #endif
  1220. save_flags(flags);
  1221. cli();
  1222. wait_event_interruptible(portp->raw_wait,
  1223. !test_bit(ST_CMDING, &portp->state));
  1224. if (signal_pending(current)) {
  1225. restore_flags(flags);
  1226. return -ERESTARTSYS;
  1227. }
  1228. stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
  1229. wait_event_interruptible(portp->raw_wait,
  1230. !test_bit(ST_CMDING, &portp->state));
  1231. if (signal_pending(current)) {
  1232. restore_flags(flags);
  1233. return -ERESTARTSYS;
  1234. }
  1235. restore_flags(flags);
  1236. if (portp->rc != 0)
  1237. return(-EIO);
  1238. return(0);
  1239. }
  1240. /*****************************************************************************/
  1241. /*
  1242. * Send the termios settings for this port to the slave. This sleeps
  1243. * waiting for the command to complete - so must have user context.
  1244. */
  1245. static int stli_setport(stliport_t *portp)
  1246. {
  1247. stlibrd_t *brdp;
  1248. asyport_t aport;
  1249. #ifdef DEBUG
  1250. printk("stli_setport(portp=%x)\n", (int) portp);
  1251. #endif
  1252. if (portp == (stliport_t *) NULL)
  1253. return(-ENODEV);
  1254. if (portp->tty == (struct tty_struct *) NULL)
  1255. return(-ENODEV);
  1256. if ((portp->brdnr < 0) && (portp->brdnr >= stli_nrbrds))
  1257. return(-ENODEV);
  1258. brdp = stli_brds[portp->brdnr];
  1259. if (brdp == (stlibrd_t *) NULL)
  1260. return(-ENODEV);
  1261. stli_mkasyport(portp, &aport, portp->tty->termios);
  1262. return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
  1263. }
  1264. /*****************************************************************************/
  1265. /*
  1266. * Possibly need to wait for carrier (DCD signal) to come high. Say
  1267. * maybe because if we are clocal then we don't need to wait...
  1268. */
  1269. static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
  1270. {
  1271. unsigned long flags;
  1272. int rc, doclocal;
  1273. #ifdef DEBUG
  1274. printk("stli_waitcarrier(brdp=%x,portp=%x,filp=%x)\n",
  1275. (int) brdp, (int) portp, (int) filp);
  1276. #endif
  1277. rc = 0;
  1278. doclocal = 0;
  1279. if (portp->tty->termios->c_cflag & CLOCAL)
  1280. doclocal++;
  1281. save_flags(flags);
  1282. cli();
  1283. portp->openwaitcnt++;
  1284. if (! tty_hung_up_p(filp))
  1285. portp->refcount--;
  1286. for (;;) {
  1287. stli_mkasysigs(&portp->asig, 1, 1);
  1288. if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
  1289. &portp->asig, sizeof(asysigs_t), 0)) < 0)
  1290. break;
  1291. if (tty_hung_up_p(filp) ||
  1292. ((portp->flags & ASYNC_INITIALIZED) == 0)) {
  1293. if (portp->flags & ASYNC_HUP_NOTIFY)
  1294. rc = -EBUSY;
  1295. else
  1296. rc = -ERESTARTSYS;
  1297. break;
  1298. }
  1299. if (((portp->flags & ASYNC_CLOSING) == 0) &&
  1300. (doclocal || (portp->sigs & TIOCM_CD))) {
  1301. break;
  1302. }
  1303. if (signal_pending(current)) {
  1304. rc = -ERESTARTSYS;
  1305. break;
  1306. }
  1307. interruptible_sleep_on(&portp->open_wait);
  1308. }
  1309. if (! tty_hung_up_p(filp))
  1310. portp->refcount++;
  1311. portp->openwaitcnt--;
  1312. restore_flags(flags);
  1313. return(rc);
  1314. }
  1315. /*****************************************************************************/
  1316. /*
  1317. * Write routine. Take the data and put it in the shared memory ring
  1318. * queue. If port is not already sending chars then need to mark the
  1319. * service bits for this port.
  1320. */
  1321. static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
  1322. {
  1323. volatile cdkasy_t *ap;
  1324. volatile cdkhdr_t *hdrp;
  1325. volatile unsigned char *bits;
  1326. unsigned char *shbuf, *chbuf;
  1327. stliport_t *portp;
  1328. stlibrd_t *brdp;
  1329. unsigned int len, stlen, head, tail, size;
  1330. unsigned long flags;
  1331. #ifdef DEBUG
  1332. printk("stli_write(tty=%x,buf=%x,count=%d)\n",
  1333. (int) tty, (int) buf, count);
  1334. #endif
  1335. if ((tty == (struct tty_struct *) NULL) ||
  1336. (stli_tmpwritebuf == (char *) NULL))
  1337. return(0);
  1338. if (tty == stli_txcooktty)
  1339. stli_flushchars(tty);
  1340. portp = tty->driver_data;
  1341. if (portp == (stliport_t *) NULL)
  1342. return(0);
  1343. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1344. return(0);
  1345. brdp = stli_brds[portp->brdnr];
  1346. if (brdp == (stlibrd_t *) NULL)
  1347. return(0);
  1348. chbuf = (unsigned char *) buf;
  1349. /*
  1350. * All data is now local, shove as much as possible into shared memory.
  1351. */
  1352. save_flags(flags);
  1353. cli();
  1354. EBRDENABLE(brdp);
  1355. ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
  1356. head = (unsigned int) ap->txq.head;
  1357. tail = (unsigned int) ap->txq.tail;
  1358. if (tail != ((unsigned int) ap->txq.tail))
  1359. tail = (unsigned int) ap->txq.tail;
  1360. size = portp->txsize;
  1361. if (head >= tail) {
  1362. len = size - (head - tail) - 1;
  1363. stlen = size - head;
  1364. } else {
  1365. len = tail - head - 1;
  1366. stlen = len;
  1367. }
  1368. len = MIN(len, count);
  1369. count = 0;
  1370. shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
  1371. while (len > 0) {
  1372. stlen = MIN(len, stlen);
  1373. memcpy((shbuf + head), chbuf, stlen);
  1374. chbuf += stlen;
  1375. len -= stlen;
  1376. count += stlen;
  1377. head += stlen;
  1378. if (head >= size) {
  1379. head = 0;
  1380. stlen = tail;
  1381. }
  1382. }
  1383. ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
  1384. ap->txq.head = head;
  1385. if (test_bit(ST_TXBUSY, &portp->state)) {
  1386. if (ap->changed.data & DT_TXEMPTY)
  1387. ap->changed.data &= ~DT_TXEMPTY;
  1388. }
  1389. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1390. bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
  1391. portp->portidx;
  1392. *bits |= portp->portbit;
  1393. set_bit(ST_TXBUSY, &portp->state);
  1394. EBRDDISABLE(brdp);
  1395. restore_flags(flags);
  1396. return(count);
  1397. }
  1398. /*****************************************************************************/
  1399. /*
  1400. * Output a single character. We put it into a temporary local buffer
  1401. * (for speed) then write out that buffer when the flushchars routine
  1402. * is called. There is a safety catch here so that if some other port
  1403. * writes chars before the current buffer has been, then we write them
  1404. * first them do the new ports.
  1405. */
  1406. static void stli_putchar(struct tty_struct *tty, unsigned char ch)
  1407. {
  1408. #ifdef DEBUG
  1409. printk("stli_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
  1410. #endif
  1411. if (tty == (struct tty_struct *) NULL)
  1412. return;
  1413. if (tty != stli_txcooktty) {
  1414. if (stli_txcooktty != (struct tty_struct *) NULL)
  1415. stli_flushchars(stli_txcooktty);
  1416. stli_txcooktty = tty;
  1417. }
  1418. stli_txcookbuf[stli_txcooksize++] = ch;
  1419. }
  1420. /*****************************************************************************/
  1421. /*
  1422. * Transfer characters from the local TX cooking buffer to the board.
  1423. * We sort of ignore the tty that gets passed in here. We rely on the
  1424. * info stored with the TX cook buffer to tell us which port to flush
  1425. * the data on. In any case we clean out the TX cook buffer, for re-use
  1426. * by someone else.
  1427. */
  1428. static void stli_flushchars(struct tty_struct *tty)
  1429. {
  1430. volatile cdkhdr_t *hdrp;
  1431. volatile unsigned char *bits;
  1432. volatile cdkasy_t *ap;
  1433. struct tty_struct *cooktty;
  1434. stliport_t *portp;
  1435. stlibrd_t *brdp;
  1436. unsigned int len, stlen, head, tail, size, count, cooksize;
  1437. unsigned char *buf, *shbuf;
  1438. unsigned long flags;
  1439. #ifdef DEBUG
  1440. printk("stli_flushchars(tty=%x)\n", (int) tty);
  1441. #endif
  1442. cooksize = stli_txcooksize;
  1443. cooktty = stli_txcooktty;
  1444. stli_txcooksize = 0;
  1445. stli_txcookrealsize = 0;
  1446. stli_txcooktty = (struct tty_struct *) NULL;
  1447. if (tty == (struct tty_struct *) NULL)
  1448. return;
  1449. if (cooktty == (struct tty_struct *) NULL)
  1450. return;
  1451. if (tty != cooktty)
  1452. tty = cooktty;
  1453. if (cooksize == 0)
  1454. return;
  1455. portp = tty->driver_data;
  1456. if (portp == (stliport_t *) NULL)
  1457. return;
  1458. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1459. return;
  1460. brdp = stli_brds[portp->brdnr];
  1461. if (brdp == (stlibrd_t *) NULL)
  1462. return;
  1463. save_flags(flags);
  1464. cli();
  1465. EBRDENABLE(brdp);
  1466. ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
  1467. head = (unsigned int) ap->txq.head;
  1468. tail = (unsigned int) ap->txq.tail;
  1469. if (tail != ((unsigned int) ap->txq.tail))
  1470. tail = (unsigned int) ap->txq.tail;
  1471. size = portp->txsize;
  1472. if (head >= tail) {
  1473. len = size - (head - tail) - 1;
  1474. stlen = size - head;
  1475. } else {
  1476. len = tail - head - 1;
  1477. stlen = len;
  1478. }
  1479. len = MIN(len, cooksize);
  1480. count = 0;
  1481. shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
  1482. buf = stli_txcookbuf;
  1483. while (len > 0) {
  1484. stlen = MIN(len, stlen);
  1485. memcpy((shbuf + head), buf, stlen);
  1486. buf += stlen;
  1487. len -= stlen;
  1488. count += stlen;
  1489. head += stlen;
  1490. if (head >= size) {
  1491. head = 0;
  1492. stlen = tail;
  1493. }
  1494. }
  1495. ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
  1496. ap->txq.head = head;
  1497. if (test_bit(ST_TXBUSY, &portp->state)) {
  1498. if (ap->changed.data & DT_TXEMPTY)
  1499. ap->changed.data &= ~DT_TXEMPTY;
  1500. }
  1501. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1502. bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
  1503. portp->portidx;
  1504. *bits |= portp->portbit;
  1505. set_bit(ST_TXBUSY, &portp->state);
  1506. EBRDDISABLE(brdp);
  1507. restore_flags(flags);
  1508. }
  1509. /*****************************************************************************/
  1510. static int stli_writeroom(struct tty_struct *tty)
  1511. {
  1512. volatile cdkasyrq_t *rp;
  1513. stliport_t *portp;
  1514. stlibrd_t *brdp;
  1515. unsigned int head, tail, len;
  1516. unsigned long flags;
  1517. #ifdef DEBUG
  1518. printk("stli_writeroom(tty=%x)\n", (int) tty);
  1519. #endif
  1520. if (tty == (struct tty_struct *) NULL)
  1521. return(0);
  1522. if (tty == stli_txcooktty) {
  1523. if (stli_txcookrealsize != 0) {
  1524. len = stli_txcookrealsize - stli_txcooksize;
  1525. return(len);
  1526. }
  1527. }
  1528. portp = tty->driver_data;
  1529. if (portp == (stliport_t *) NULL)
  1530. return(0);
  1531. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1532. return(0);
  1533. brdp = stli_brds[portp->brdnr];
  1534. if (brdp == (stlibrd_t *) NULL)
  1535. return(0);
  1536. save_flags(flags);
  1537. cli();
  1538. EBRDENABLE(brdp);
  1539. rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
  1540. head = (unsigned int) rp->head;
  1541. tail = (unsigned int) rp->tail;
  1542. if (tail != ((unsigned int) rp->tail))
  1543. tail = (unsigned int) rp->tail;
  1544. len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
  1545. len--;
  1546. EBRDDISABLE(brdp);
  1547. restore_flags(flags);
  1548. if (tty == stli_txcooktty) {
  1549. stli_txcookrealsize = len;
  1550. len -= stli_txcooksize;
  1551. }
  1552. return(len);
  1553. }
  1554. /*****************************************************************************/
  1555. /*
  1556. * Return the number of characters in the transmit buffer. Normally we
  1557. * will return the number of chars in the shared memory ring queue.
  1558. * We need to kludge around the case where the shared memory buffer is
  1559. * empty but not all characters have drained yet, for this case just
  1560. * return that there is 1 character in the buffer!
  1561. */
  1562. static int stli_charsinbuffer(struct tty_struct *tty)
  1563. {
  1564. volatile cdkasyrq_t *rp;
  1565. stliport_t *portp;
  1566. stlibrd_t *brdp;
  1567. unsigned int head, tail, len;
  1568. unsigned long flags;
  1569. #ifdef DEBUG
  1570. printk("stli_charsinbuffer(tty=%x)\n", (int) tty);
  1571. #endif
  1572. if (tty == (struct tty_struct *) NULL)
  1573. return(0);
  1574. if (tty == stli_txcooktty)
  1575. stli_flushchars(tty);
  1576. portp = tty->driver_data;
  1577. if (portp == (stliport_t *) NULL)
  1578. return(0);
  1579. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1580. return(0);
  1581. brdp = stli_brds[portp->brdnr];
  1582. if (brdp == (stlibrd_t *) NULL)
  1583. return(0);
  1584. save_flags(flags);
  1585. cli();
  1586. EBRDENABLE(brdp);
  1587. rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
  1588. head = (unsigned int) rp->head;
  1589. tail = (unsigned int) rp->tail;
  1590. if (tail != ((unsigned int) rp->tail))
  1591. tail = (unsigned int) rp->tail;
  1592. len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
  1593. if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
  1594. len = 1;
  1595. EBRDDISABLE(brdp);
  1596. restore_flags(flags);
  1597. return(len);
  1598. }
  1599. /*****************************************************************************/
  1600. /*
  1601. * Generate the serial struct info.
  1602. */
  1603. static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
  1604. {
  1605. struct serial_struct sio;
  1606. stlibrd_t *brdp;
  1607. #ifdef DEBUG
  1608. printk("stli_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
  1609. #endif
  1610. memset(&sio, 0, sizeof(struct serial_struct));
  1611. sio.type = PORT_UNKNOWN;
  1612. sio.line = portp->portnr;
  1613. sio.irq = 0;
  1614. sio.flags = portp->flags;
  1615. sio.baud_base = portp->baud_base;
  1616. sio.close_delay = portp->close_delay;
  1617. sio.closing_wait = portp->closing_wait;
  1618. sio.custom_divisor = portp->custom_divisor;
  1619. sio.xmit_fifo_size = 0;
  1620. sio.hub6 = 0;
  1621. brdp = stli_brds[portp->brdnr];
  1622. if (brdp != (stlibrd_t *) NULL)
  1623. sio.port = brdp->iobase;
  1624. return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
  1625. -EFAULT : 0;
  1626. }
  1627. /*****************************************************************************/
  1628. /*
  1629. * Set port according to the serial struct info.
  1630. * At this point we do not do any auto-configure stuff, so we will
  1631. * just quietly ignore any requests to change irq, etc.
  1632. */
  1633. static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
  1634. {
  1635. struct serial_struct sio;
  1636. int rc;
  1637. #ifdef DEBUG
  1638. printk("stli_setserial(portp=%p,sp=%p)\n", portp, sp);
  1639. #endif
  1640. if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
  1641. return -EFAULT;
  1642. if (!capable(CAP_SYS_ADMIN)) {
  1643. if ((sio.baud_base != portp->baud_base) ||
  1644. (sio.close_delay != portp->close_delay) ||
  1645. ((sio.flags & ~ASYNC_USR_MASK) !=
  1646. (portp->flags & ~ASYNC_USR_MASK)))
  1647. return(-EPERM);
  1648. }
  1649. portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
  1650. (sio.flags & ASYNC_USR_MASK);
  1651. portp->baud_base = sio.baud_base;
  1652. portp->close_delay = sio.close_delay;
  1653. portp->closing_wait = sio.closing_wait;
  1654. portp->custom_divisor = sio.custom_divisor;
  1655. if ((rc = stli_setport(portp)) < 0)
  1656. return(rc);
  1657. return(0);
  1658. }
  1659. /*****************************************************************************/
  1660. static int stli_tiocmget(struct tty_struct *tty, struct file *file)
  1661. {
  1662. stliport_t *portp = tty->driver_data;
  1663. stlibrd_t *brdp;
  1664. int rc;
  1665. if (portp == (stliport_t *) NULL)
  1666. return(-ENODEV);
  1667. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1668. return(0);
  1669. brdp = stli_brds[portp->brdnr];
  1670. if (brdp == (stlibrd_t *) NULL)
  1671. return(0);
  1672. if (tty->flags & (1 << TTY_IO_ERROR))
  1673. return(-EIO);
  1674. if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
  1675. &portp->asig, sizeof(asysigs_t), 1)) < 0)
  1676. return(rc);
  1677. return stli_mktiocm(portp->asig.sigvalue);
  1678. }
  1679. static int stli_tiocmset(struct tty_struct *tty, struct file *file,
  1680. unsigned int set, unsigned int clear)
  1681. {
  1682. stliport_t *portp = tty->driver_data;
  1683. stlibrd_t *brdp;
  1684. int rts = -1, dtr = -1;
  1685. if (portp == (stliport_t *) NULL)
  1686. return(-ENODEV);
  1687. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1688. return(0);
  1689. brdp = stli_brds[portp->brdnr];
  1690. if (brdp == (stlibrd_t *) NULL)
  1691. return(0);
  1692. if (tty->flags & (1 << TTY_IO_ERROR))
  1693. return(-EIO);
  1694. if (set & TIOCM_RTS)
  1695. rts = 1;
  1696. if (set & TIOCM_DTR)
  1697. dtr = 1;
  1698. if (clear & TIOCM_RTS)
  1699. rts = 0;
  1700. if (clear & TIOCM_DTR)
  1701. dtr = 0;
  1702. stli_mkasysigs(&portp->asig, dtr, rts);
  1703. return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1704. sizeof(asysigs_t), 0);
  1705. }
  1706. static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
  1707. {
  1708. stliport_t *portp;
  1709. stlibrd_t *brdp;
  1710. unsigned int ival;
  1711. int rc;
  1712. void __user *argp = (void __user *)arg;
  1713. #ifdef DEBUG
  1714. printk("stli_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
  1715. (int) tty, (int) file, cmd, (int) arg);
  1716. #endif
  1717. if (tty == (struct tty_struct *) NULL)
  1718. return(-ENODEV);
  1719. portp = tty->driver_data;
  1720. if (portp == (stliport_t *) NULL)
  1721. return(-ENODEV);
  1722. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1723. return(0);
  1724. brdp = stli_brds[portp->brdnr];
  1725. if (brdp == (stlibrd_t *) NULL)
  1726. return(0);
  1727. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1728. (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
  1729. if (tty->flags & (1 << TTY_IO_ERROR))
  1730. return(-EIO);
  1731. }
  1732. rc = 0;
  1733. switch (cmd) {
  1734. case TIOCGSOFTCAR:
  1735. rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
  1736. (unsigned __user *) arg);
  1737. break;
  1738. case TIOCSSOFTCAR:
  1739. if ((rc = get_user(ival, (unsigned __user *) arg)) == 0)
  1740. tty->termios->c_cflag =
  1741. (tty->termios->c_cflag & ~CLOCAL) |
  1742. (ival ? CLOCAL : 0);
  1743. break;
  1744. case TIOCGSERIAL:
  1745. rc = stli_getserial(portp, argp);
  1746. break;
  1747. case TIOCSSERIAL:
  1748. rc = stli_setserial(portp, argp);
  1749. break;
  1750. case STL_GETPFLAG:
  1751. rc = put_user(portp->pflag, (unsigned __user *)argp);
  1752. break;
  1753. case STL_SETPFLAG:
  1754. if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0)
  1755. stli_setport(portp);
  1756. break;
  1757. case COM_GETPORTSTATS:
  1758. rc = stli_getportstats(portp, argp);
  1759. break;
  1760. case COM_CLRPORTSTATS:
  1761. rc = stli_clrportstats(portp, argp);
  1762. break;
  1763. case TIOCSERCONFIG:
  1764. case TIOCSERGWILD:
  1765. case TIOCSERSWILD:
  1766. case TIOCSERGETLSR:
  1767. case TIOCSERGSTRUCT:
  1768. case TIOCSERGETMULTI:
  1769. case TIOCSERSETMULTI:
  1770. default:
  1771. rc = -ENOIOCTLCMD;
  1772. break;
  1773. }
  1774. return(rc);
  1775. }
  1776. /*****************************************************************************/
  1777. /*
  1778. * This routine assumes that we have user context and can sleep.
  1779. * Looks like it is true for the current ttys implementation..!!
  1780. */
  1781. static void stli_settermios(struct tty_struct *tty, struct termios *old)
  1782. {
  1783. stliport_t *portp;
  1784. stlibrd_t *brdp;
  1785. struct termios *tiosp;
  1786. asyport_t aport;
  1787. #ifdef DEBUG
  1788. printk("stli_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
  1789. #endif
  1790. if (tty == (struct tty_struct *) NULL)
  1791. return;
  1792. portp = tty->driver_data;
  1793. if (portp == (stliport_t *) NULL)
  1794. return;
  1795. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1796. return;
  1797. brdp = stli_brds[portp->brdnr];
  1798. if (brdp == (stlibrd_t *) NULL)
  1799. return;
  1800. tiosp = tty->termios;
  1801. if ((tiosp->c_cflag == old->c_cflag) &&
  1802. (tiosp->c_iflag == old->c_iflag))
  1803. return;
  1804. stli_mkasyport(portp, &aport, tiosp);
  1805. stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
  1806. stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
  1807. stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1808. sizeof(asysigs_t), 0);
  1809. if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
  1810. tty->hw_stopped = 0;
  1811. if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
  1812. wake_up_interruptible(&portp->open_wait);
  1813. }
  1814. /*****************************************************************************/
  1815. /*
  1816. * Attempt to flow control who ever is sending us data. We won't really
  1817. * do any flow control action here. We can't directly, and even if we
  1818. * wanted to we would have to send a command to the slave. The slave
  1819. * knows how to flow control, and will do so when its buffers reach its
  1820. * internal high water marks. So what we will do is set a local state
  1821. * bit that will stop us sending any RX data up from the poll routine
  1822. * (which is the place where RX data from the slave is handled).
  1823. */
  1824. static void stli_throttle(struct tty_struct *tty)
  1825. {
  1826. stliport_t *portp;
  1827. #ifdef DEBUG
  1828. printk("stli_throttle(tty=%x)\n", (int) tty);
  1829. #endif
  1830. if (tty == (struct tty_struct *) NULL)
  1831. return;
  1832. portp = tty->driver_data;
  1833. if (portp == (stliport_t *) NULL)
  1834. return;
  1835. set_bit(ST_RXSTOP, &portp->state);
  1836. }
  1837. /*****************************************************************************/
  1838. /*
  1839. * Unflow control the device sending us data... That means that all
  1840. * we have to do is clear the RXSTOP state bit. The next poll call
  1841. * will then be able to pass the RX data back up.
  1842. */
  1843. static void stli_unthrottle(struct tty_struct *tty)
  1844. {
  1845. stliport_t *portp;
  1846. #ifdef DEBUG
  1847. printk("stli_unthrottle(tty=%x)\n", (int) tty);
  1848. #endif
  1849. if (tty == (struct tty_struct *) NULL)
  1850. return;
  1851. portp = tty->driver_data;
  1852. if (portp == (stliport_t *) NULL)
  1853. return;
  1854. clear_bit(ST_RXSTOP, &portp->state);
  1855. }
  1856. /*****************************************************************************/
  1857. /*
  1858. * Stop the transmitter. Basically to do this we will just turn TX
  1859. * interrupts off.
  1860. */
  1861. static void stli_stop(struct tty_struct *tty)
  1862. {
  1863. stlibrd_t *brdp;
  1864. stliport_t *portp;
  1865. asyctrl_t actrl;
  1866. #ifdef DEBUG
  1867. printk("stli_stop(tty=%x)\n", (int) tty);
  1868. #endif
  1869. if (tty == (struct tty_struct *) NULL)
  1870. return;
  1871. portp = tty->driver_data;
  1872. if (portp == (stliport_t *) NULL)
  1873. return;
  1874. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1875. return;
  1876. brdp = stli_brds[portp->brdnr];
  1877. if (brdp == (stlibrd_t *) NULL)
  1878. return;
  1879. memset(&actrl, 0, sizeof(asyctrl_t));
  1880. actrl.txctrl = CT_STOPFLOW;
  1881. #if 0
  1882. stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
  1883. #endif
  1884. }
  1885. /*****************************************************************************/
  1886. /*
  1887. * Start the transmitter again. Just turn TX interrupts back on.
  1888. */
  1889. static void stli_start(struct tty_struct *tty)
  1890. {
  1891. stliport_t *portp;
  1892. stlibrd_t *brdp;
  1893. asyctrl_t actrl;
  1894. #ifdef DEBUG
  1895. printk("stli_start(tty=%x)\n", (int) tty);
  1896. #endif
  1897. if (tty == (struct tty_struct *) NULL)
  1898. return;
  1899. portp = tty->driver_data;
  1900. if (portp == (stliport_t *) NULL)
  1901. return;
  1902. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1903. return;
  1904. brdp = stli_brds[portp->brdnr];
  1905. if (brdp == (stlibrd_t *) NULL)
  1906. return;
  1907. memset(&actrl, 0, sizeof(asyctrl_t));
  1908. actrl.txctrl = CT_STARTFLOW;
  1909. #if 0
  1910. stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
  1911. #endif
  1912. }
  1913. /*****************************************************************************/
  1914. /*
  1915. * Scheduler called hang up routine. This is called from the scheduler,
  1916. * not direct from the driver "poll" routine. We can't call it there
  1917. * since the real local hangup code will enable/disable the board and
  1918. * other things that we can't do while handling the poll. Much easier
  1919. * to deal with it some time later (don't really care when, hangups
  1920. * aren't that time critical).
  1921. */
  1922. static void stli_dohangup(void *arg)
  1923. {
  1924. stliport_t *portp;
  1925. #ifdef DEBUG
  1926. printk(KERN_DEBUG "stli_dohangup(portp=%x)\n", (int) arg);
  1927. #endif
  1928. /*
  1929. * FIXME: There's a module removal race here: tty_hangup
  1930. * calls schedule_work which will call into this
  1931. * driver later.
  1932. */
  1933. portp = (stliport_t *) arg;
  1934. if (portp != (stliport_t *) NULL) {
  1935. if (portp->tty != (struct tty_struct *) NULL) {
  1936. tty_hangup(portp->tty);
  1937. }
  1938. }
  1939. }
  1940. /*****************************************************************************/
  1941. /*
  1942. * Hangup this port. This is pretty much like closing the port, only
  1943. * a little more brutal. No waiting for data to drain. Shutdown the
  1944. * port and maybe drop signals. This is rather tricky really. We want
  1945. * to close the port as well.
  1946. */
  1947. static void stli_hangup(struct tty_struct *tty)
  1948. {
  1949. stliport_t *portp;
  1950. stlibrd_t *brdp;
  1951. unsigned long flags;
  1952. #ifdef DEBUG
  1953. printk(KERN_DEBUG "stli_hangup(tty=%x)\n", (int) tty);
  1954. #endif
  1955. if (tty == (struct tty_struct *) NULL)
  1956. return;
  1957. portp = tty->driver_data;
  1958. if (portp == (stliport_t *) NULL)
  1959. return;
  1960. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1961. return;
  1962. brdp = stli_brds[portp->brdnr];
  1963. if (brdp == (stlibrd_t *) NULL)
  1964. return;
  1965. portp->flags &= ~ASYNC_INITIALIZED;
  1966. save_flags(flags);
  1967. cli();
  1968. if (! test_bit(ST_CLOSING, &portp->state))
  1969. stli_rawclose(brdp, portp, 0, 0);
  1970. if (tty->termios->c_cflag & HUPCL) {
  1971. stli_mkasysigs(&portp->asig, 0, 0);
  1972. if (test_bit(ST_CMDING, &portp->state)) {
  1973. set_bit(ST_DOSIGS, &portp->state);
  1974. set_bit(ST_DOFLUSHTX, &portp->state);
  1975. set_bit(ST_DOFLUSHRX, &portp->state);
  1976. } else {
  1977. stli_sendcmd(brdp, portp, A_SETSIGNALSF,
  1978. &portp->asig, sizeof(asysigs_t), 0);
  1979. }
  1980. }
  1981. restore_flags(flags);
  1982. clear_bit(ST_TXBUSY, &portp->state);
  1983. clear_bit(ST_RXSTOP, &portp->state);
  1984. set_bit(TTY_IO_ERROR, &tty->flags);
  1985. portp->tty = (struct tty_struct *) NULL;
  1986. portp->flags &= ~ASYNC_NORMAL_ACTIVE;
  1987. portp->refcount = 0;
  1988. wake_up_interruptible(&portp->open_wait);
  1989. }
  1990. /*****************************************************************************/
  1991. /*
  1992. * Flush characters from the lower buffer. We may not have user context
  1993. * so we cannot sleep waiting for it to complete. Also we need to check
  1994. * if there is chars for this port in the TX cook buffer, and flush them
  1995. * as well.
  1996. */
  1997. static void stli_flushbuffer(struct tty_struct *tty)
  1998. {
  1999. stliport_t *portp;
  2000. stlibrd_t *brdp;
  2001. unsigned long ftype, flags;
  2002. #ifdef DEBUG
  2003. printk(KERN_DEBUG "stli_flushbuffer(tty=%x)\n", (int) tty);
  2004. #endif
  2005. if (tty == (struct tty_struct *) NULL)
  2006. return;
  2007. portp = tty->driver_data;
  2008. if (portp == (stliport_t *) NULL)
  2009. return;
  2010. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  2011. return;
  2012. brdp = stli_brds[portp->brdnr];
  2013. if (brdp == (stlibrd_t *) NULL)
  2014. return;
  2015. save_flags(flags);
  2016. cli();
  2017. if (tty == stli_txcooktty) {
  2018. stli_txcooktty = (struct tty_struct *) NULL;
  2019. stli_txcooksize = 0;
  2020. stli_txcookrealsize = 0;
  2021. }
  2022. if (test_bit(ST_CMDING, &portp->state)) {
  2023. set_bit(ST_DOFLUSHTX, &portp->state);
  2024. } else {
  2025. ftype = FLUSHTX;
  2026. if (test_bit(ST_DOFLUSHRX, &portp->state)) {
  2027. ftype |= FLUSHRX;
  2028. clear_bit(ST_DOFLUSHRX, &portp->state);
  2029. }
  2030. stli_sendcmd(brdp, portp, A_FLUSH, &ftype,
  2031. sizeof(unsigned long), 0);
  2032. }
  2033. restore_flags(flags);
  2034. wake_up_interruptible(&tty->write_wait);
  2035. if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
  2036. tty->ldisc.write_wakeup)
  2037. (tty->ldisc.write_wakeup)(tty);
  2038. }
  2039. /*****************************************************************************/
  2040. static void stli_breakctl(struct tty_struct *tty, int state)
  2041. {
  2042. stlibrd_t *brdp;
  2043. stliport_t *portp;
  2044. long arg;
  2045. /* long savestate, savetime; */
  2046. #ifdef DEBUG
  2047. printk(KERN_DEBUG "stli_breakctl(tty=%x,state=%d)\n", (int) tty, state);
  2048. #endif
  2049. if (tty == (struct tty_struct *) NULL)
  2050. return;
  2051. portp = tty->driver_data;
  2052. if (portp == (stliport_t *) NULL)
  2053. return;
  2054. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  2055. return;
  2056. brdp = stli_brds[portp->brdnr];
  2057. if (brdp == (stlibrd_t *) NULL)
  2058. return;
  2059. /*
  2060. * Due to a bug in the tty send_break() code we need to preserve
  2061. * the current process state and timeout...
  2062. savetime = current->timeout;
  2063. savestate = current->state;
  2064. */
  2065. arg = (state == -1) ? BREAKON : BREAKOFF;
  2066. stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
  2067. /*
  2068. *
  2069. current->timeout = savetime;
  2070. current->state = savestate;
  2071. */
  2072. }
  2073. /*****************************************************************************/
  2074. static void stli_waituntilsent(struct tty_struct *tty, int timeout)
  2075. {
  2076. stliport_t *portp;
  2077. unsigned long tend;
  2078. #ifdef DEBUG
  2079. printk(KERN_DEBUG "stli_waituntilsent(tty=%x,timeout=%x)\n", (int) tty, timeout);
  2080. #endif
  2081. if (tty == (struct tty_struct *) NULL)
  2082. return;
  2083. portp = tty->driver_data;
  2084. if (portp == (stliport_t *) NULL)
  2085. return;
  2086. if (timeout == 0)
  2087. timeout = HZ;
  2088. tend = jiffies + timeout;
  2089. while (test_bit(ST_TXBUSY, &portp->state)) {
  2090. if (signal_pending(current))
  2091. break;
  2092. msleep_interruptible(20);
  2093. if (time_after_eq(jiffies, tend))
  2094. break;
  2095. }
  2096. }
  2097. /*****************************************************************************/
  2098. static void stli_sendxchar(struct tty_struct *tty, char ch)
  2099. {
  2100. stlibrd_t *brdp;
  2101. stliport_t *portp;
  2102. asyctrl_t actrl;
  2103. #ifdef DEBUG
  2104. printk(KERN_DEBUG "stli_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
  2105. #endif
  2106. if (tty == (struct tty_struct *) NULL)
  2107. return;
  2108. portp = tty->driver_data;
  2109. if (portp == (stliport_t *) NULL)
  2110. return;
  2111. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  2112. return;
  2113. brdp = stli_brds[portp->brdnr];
  2114. if (brdp == (stlibrd_t *) NULL)
  2115. return;
  2116. memset(&actrl, 0, sizeof(asyctrl_t));
  2117. if (ch == STOP_CHAR(tty)) {
  2118. actrl.rxctrl = CT_STOPFLOW;
  2119. } else if (ch == START_CHAR(tty)) {
  2120. actrl.rxctrl = CT_STARTFLOW;
  2121. } else {
  2122. actrl.txctrl = CT_SENDCHR;
  2123. actrl.tximdch = ch;
  2124. }
  2125. stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
  2126. }
  2127. /*****************************************************************************/
  2128. #define MAXLINE 80
  2129. /*
  2130. * Format info for a specified port. The line is deliberately limited
  2131. * to 80 characters. (If it is too long it will be truncated, if too
  2132. * short then padded with spaces).
  2133. */
  2134. static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos)
  2135. {
  2136. char *sp, *uart;
  2137. int rc, cnt;
  2138. rc = stli_portcmdstats(portp);
  2139. uart = "UNKNOWN";
  2140. if (brdp->state & BST_STARTED) {
  2141. switch (stli_comstats.hwid) {
  2142. case 0: uart = "2681"; break;
  2143. case 1: uart = "SC26198"; break;
  2144. default: uart = "CD1400"; break;
  2145. }
  2146. }
  2147. sp = pos;
  2148. sp += sprintf(sp, "%d: uart:%s ", portnr, uart);
  2149. if ((brdp->state & BST_STARTED) && (rc >= 0)) {
  2150. sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal,
  2151. (int) stli_comstats.rxtotal);
  2152. if (stli_comstats.rxframing)
  2153. sp += sprintf(sp, " fe:%d",
  2154. (int) stli_comstats.rxframing);
  2155. if (stli_comstats.rxparity)
  2156. sp += sprintf(sp, " pe:%d",
  2157. (int) stli_comstats.rxparity);
  2158. if (stli_comstats.rxbreaks)
  2159. sp += sprintf(sp, " brk:%d",
  2160. (int) stli_comstats.rxbreaks);
  2161. if (stli_comstats.rxoverrun)
  2162. sp += sprintf(sp, " oe:%d",
  2163. (int) stli_comstats.rxoverrun);
  2164. cnt = sprintf(sp, "%s%s%s%s%s ",
  2165. (stli_comstats.signals & TIOCM_RTS) ? "|RTS" : "",
  2166. (stli_comstats.signals & TIOCM_CTS) ? "|CTS" : "",
  2167. (stli_comstats.signals & TIOCM_DTR) ? "|DTR" : "",
  2168. (stli_comstats.signals & TIOCM_CD) ? "|DCD" : "",
  2169. (stli_comstats.signals & TIOCM_DSR) ? "|DSR" : "");
  2170. *sp = ' ';
  2171. sp += cnt;
  2172. }
  2173. for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
  2174. *sp++ = ' ';
  2175. if (cnt >= MAXLINE)
  2176. pos[(MAXLINE - 2)] = '+';
  2177. pos[(MAXLINE - 1)] = '\n';
  2178. return(MAXLINE);
  2179. }
  2180. /*****************************************************************************/
  2181. /*
  2182. * Port info, read from the /proc file system.
  2183. */
  2184. static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
  2185. {
  2186. stlibrd_t *brdp;
  2187. stliport_t *portp;
  2188. int brdnr, portnr, totalport;
  2189. int curoff, maxoff;
  2190. char *pos;
  2191. #ifdef DEBUG
  2192. printk(KERN_DEBUG "stli_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
  2193. "data=%x\n", (int) page, (int) start, (int) off, count,
  2194. (int) eof, (int) data);
  2195. #endif
  2196. pos = page;
  2197. totalport = 0;
  2198. curoff = 0;
  2199. if (off == 0) {
  2200. pos += sprintf(pos, "%s: version %s", stli_drvtitle,
  2201. stli_drvversion);
  2202. while (pos < (page + MAXLINE - 1))
  2203. *pos++ = ' ';
  2204. *pos++ = '\n';
  2205. }
  2206. curoff = MAXLINE;
  2207. /*
  2208. * We scan through for each board, panel and port. The offset is
  2209. * calculated on the fly, and irrelevant ports are skipped.
  2210. */
  2211. for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
  2212. brdp = stli_brds[brdnr];
  2213. if (brdp == (stlibrd_t *) NULL)
  2214. continue;
  2215. if (brdp->state == 0)
  2216. continue;
  2217. maxoff = curoff + (brdp->nrports * MAXLINE);
  2218. if (off >= maxoff) {
  2219. curoff = maxoff;
  2220. continue;
  2221. }
  2222. totalport = brdnr * STL_MAXPORTS;
  2223. for (portnr = 0; (portnr < brdp->nrports); portnr++,
  2224. totalport++) {
  2225. portp = brdp->ports[portnr];
  2226. if (portp == (stliport_t *) NULL)
  2227. continue;
  2228. if (off >= (curoff += MAXLINE))
  2229. continue;
  2230. if ((pos - page + MAXLINE) > count)
  2231. goto stli_readdone;
  2232. pos += stli_portinfo(brdp, portp, totalport, pos);
  2233. }
  2234. }
  2235. *eof = 1;
  2236. stli_readdone:
  2237. *start = page;
  2238. return(pos - page);
  2239. }
  2240. /*****************************************************************************/
  2241. /*
  2242. * Generic send command routine. This will send a message to the slave,
  2243. * of the specified type with the specified argument. Must be very
  2244. * careful of data that will be copied out from shared memory -
  2245. * containing command results. The command completion is all done from
  2246. * a poll routine that does not have user context. Therefore you cannot
  2247. * copy back directly into user space, or to the kernel stack of a
  2248. * process. This routine does not sleep, so can be called from anywhere.
  2249. */
  2250. static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
  2251. {
  2252. volatile cdkhdr_t *hdrp;
  2253. volatile cdkctrl_t *cp;
  2254. volatile unsigned char *bits;
  2255. unsigned long flags;
  2256. #ifdef DEBUG
  2257. printk(KERN_DEBUG "stli_sendcmd(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
  2258. "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
  2259. (int) arg, size, copyback);
  2260. #endif
  2261. save_flags(flags);
  2262. cli();
  2263. if (test_bit(ST_CMDING, &portp->state)) {
  2264. printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
  2265. (int) cmd);
  2266. restore_flags(flags);
  2267. return;
  2268. }
  2269. EBRDENABLE(brdp);
  2270. cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  2271. if (size > 0) {
  2272. memcpy((void *) &(cp->args[0]), arg, size);
  2273. if (copyback) {
  2274. portp->argp = arg;
  2275. portp->argsize = size;
  2276. }
  2277. }
  2278. cp->status = 0;
  2279. cp->cmd = cmd;
  2280. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2281. bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
  2282. portp->portidx;
  2283. *bits |= portp->portbit;
  2284. set_bit(ST_CMDING, &portp->state);
  2285. EBRDDISABLE(brdp);
  2286. restore_flags(flags);
  2287. }
  2288. /*****************************************************************************/
  2289. /*
  2290. * Read data from shared memory. This assumes that the shared memory
  2291. * is enabled and that interrupts are off. Basically we just empty out
  2292. * the shared memory buffer into the tty buffer. Must be careful to
  2293. * handle the case where we fill up the tty buffer, but still have
  2294. * more chars to unload.
  2295. */
  2296. static void stli_read(stlibrd_t *brdp, stliport_t *portp)
  2297. {
  2298. volatile cdkasyrq_t *rp;
  2299. volatile char *shbuf;
  2300. struct tty_struct *tty;
  2301. unsigned int head, tail, size;
  2302. unsigned int len, stlen;
  2303. #ifdef DEBUG
  2304. printk(KERN_DEBUG "stli_read(brdp=%x,portp=%d)\n",
  2305. (int) brdp, (int) portp);
  2306. #endif
  2307. if (test_bit(ST_RXSTOP, &portp->state))
  2308. return;
  2309. tty = portp->tty;
  2310. if (tty == (struct tty_struct *) NULL)
  2311. return;
  2312. rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
  2313. head = (unsigned int) rp->head;
  2314. if (head != ((unsigned int) rp->head))
  2315. head = (unsigned int) rp->head;
  2316. tail = (unsigned int) rp->tail;
  2317. size = portp->rxsize;
  2318. if (head >= tail) {
  2319. len = head - tail;
  2320. stlen = len;
  2321. } else {
  2322. len = size - (tail - head);
  2323. stlen = size - tail;
  2324. }
  2325. len = MIN(len, (TTY_FLIPBUF_SIZE - tty->flip.count));
  2326. shbuf = (volatile char *) EBRDGETMEMPTR(brdp, portp->rxoffset);
  2327. while (len > 0) {
  2328. stlen = MIN(len, stlen);
  2329. memcpy(tty->flip.char_buf_ptr, (char *) (shbuf + tail), stlen);
  2330. memset(tty->flip.flag_buf_ptr, 0, stlen);
  2331. tty->flip.char_buf_ptr += stlen;
  2332. tty->flip.flag_buf_ptr += stlen;
  2333. tty->flip.count += stlen;
  2334. len -= stlen;
  2335. tail += stlen;
  2336. if (tail >= size) {
  2337. tail = 0;
  2338. stlen = head;
  2339. }
  2340. }
  2341. rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
  2342. rp->tail = tail;
  2343. if (head != tail)
  2344. set_bit(ST_RXING, &portp->state);
  2345. tty_schedule_flip(tty);
  2346. }
  2347. /*****************************************************************************/
  2348. /*
  2349. * Set up and carry out any delayed commands. There is only a small set
  2350. * of slave commands that can be done "off-level". So it is not too
  2351. * difficult to deal with them here.
  2352. */
  2353. static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
  2354. {
  2355. int cmd;
  2356. if (test_bit(ST_DOSIGS, &portp->state)) {
  2357. if (test_bit(ST_DOFLUSHTX, &portp->state) &&
  2358. test_bit(ST_DOFLUSHRX, &portp->state))
  2359. cmd = A_SETSIGNALSF;
  2360. else if (test_bit(ST_DOFLUSHTX, &portp->state))
  2361. cmd = A_SETSIGNALSFTX;
  2362. else if (test_bit(ST_DOFLUSHRX, &portp->state))
  2363. cmd = A_SETSIGNALSFRX;
  2364. else
  2365. cmd = A_SETSIGNALS;
  2366. clear_bit(ST_DOFLUSHTX, &portp->state);
  2367. clear_bit(ST_DOFLUSHRX, &portp->state);
  2368. clear_bit(ST_DOSIGS, &portp->state);
  2369. memcpy((void *) &(cp->args[0]), (void *) &portp->asig,
  2370. sizeof(asysigs_t));
  2371. cp->status = 0;
  2372. cp->cmd = cmd;
  2373. set_bit(ST_CMDING, &portp->state);
  2374. } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
  2375. test_bit(ST_DOFLUSHRX, &portp->state)) {
  2376. cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
  2377. cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
  2378. clear_bit(ST_DOFLUSHTX, &portp->state);
  2379. clear_bit(ST_DOFLUSHRX, &portp->state);
  2380. memcpy((void *) &(cp->args[0]), (void *) &cmd, sizeof(int));
  2381. cp->status = 0;
  2382. cp->cmd = A_FLUSH;
  2383. set_bit(ST_CMDING, &portp->state);
  2384. }
  2385. }
  2386. /*****************************************************************************/
  2387. /*
  2388. * Host command service checking. This handles commands or messages
  2389. * coming from the slave to the host. Must have board shared memory
  2390. * enabled and interrupts off when called. Notice that by servicing the
  2391. * read data last we don't need to change the shared memory pointer
  2392. * during processing (which is a slow IO operation).
  2393. * Return value indicates if this port is still awaiting actions from
  2394. * the slave (like open, command, or even TX data being sent). If 0
  2395. * then port is still busy, otherwise no longer busy.
  2396. */
  2397. static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
  2398. {
  2399. volatile cdkasy_t *ap;
  2400. volatile cdkctrl_t *cp;
  2401. struct tty_struct *tty;
  2402. asynotify_t nt;
  2403. unsigned long oldsigs;
  2404. int rc, donerx;
  2405. #ifdef DEBUG
  2406. printk(KERN_DEBUG "stli_hostcmd(brdp=%x,channr=%d)\n",
  2407. (int) brdp, channr);
  2408. #endif
  2409. ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
  2410. cp = &ap->ctrl;
  2411. /*
  2412. * Check if we are waiting for an open completion message.
  2413. */
  2414. if (test_bit(ST_OPENING, &portp->state)) {
  2415. rc = (int) cp->openarg;
  2416. if ((cp->open == 0) && (rc != 0)) {
  2417. if (rc > 0)
  2418. rc--;
  2419. cp->openarg = 0;
  2420. portp->rc = rc;
  2421. clear_bit(ST_OPENING, &portp->state);
  2422. wake_up_interruptible(&portp->raw_wait);
  2423. }
  2424. }
  2425. /*
  2426. * Check if we are waiting for a close completion message.
  2427. */
  2428. if (test_bit(ST_CLOSING, &portp->state)) {
  2429. rc = (int) cp->closearg;
  2430. if ((cp->close == 0) && (rc != 0)) {
  2431. if (rc > 0)
  2432. rc--;
  2433. cp->closearg = 0;
  2434. portp->rc = rc;
  2435. clear_bit(ST_CLOSING, &portp->state);
  2436. wake_up_interruptible(&portp->raw_wait);
  2437. }
  2438. }
  2439. /*
  2440. * Check if we are waiting for a command completion message. We may
  2441. * need to copy out the command results associated with this command.
  2442. */
  2443. if (test_bit(ST_CMDING, &portp->state)) {
  2444. rc = cp->status;
  2445. if ((cp->cmd == 0) && (rc != 0)) {
  2446. if (rc > 0)
  2447. rc--;
  2448. if (portp->argp != (void *) NULL) {
  2449. memcpy(portp->argp, (void *) &(cp->args[0]),
  2450. portp->argsize);
  2451. portp->argp = (void *) NULL;
  2452. }
  2453. cp->status = 0;
  2454. portp->rc = rc;
  2455. clear_bit(ST_CMDING, &portp->state);
  2456. stli_dodelaycmd(portp, cp);
  2457. wake_up_interruptible(&portp->raw_wait);
  2458. }
  2459. }
  2460. /*
  2461. * Check for any notification messages ready. This includes lots of
  2462. * different types of events - RX chars ready, RX break received,
  2463. * TX data low or empty in the slave, modem signals changed state.
  2464. */
  2465. donerx = 0;
  2466. if (ap->notify) {
  2467. nt = ap->changed;
  2468. ap->notify = 0;
  2469. tty = portp->tty;
  2470. if (nt.signal & SG_DCD) {
  2471. oldsigs = portp->sigs;
  2472. portp->sigs = stli_mktiocm(nt.sigvalue);
  2473. clear_bit(ST_GETSIGS, &portp->state);
  2474. if ((portp->sigs & TIOCM_CD) &&
  2475. ((oldsigs & TIOCM_CD) == 0))
  2476. wake_up_interruptible(&portp->open_wait);
  2477. if ((oldsigs & TIOCM_CD) &&
  2478. ((portp->sigs & TIOCM_CD) == 0)) {
  2479. if (portp->flags & ASYNC_CHECK_CD) {
  2480. if (tty)
  2481. schedule_work(&portp->tqhangup);
  2482. }
  2483. }
  2484. }
  2485. if (nt.data & DT_TXEMPTY)
  2486. clear_bit(ST_TXBUSY, &portp->state);
  2487. if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
  2488. if (tty != (struct tty_struct *) NULL) {
  2489. if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
  2490. tty->ldisc.write_wakeup) {
  2491. (tty->ldisc.write_wakeup)(tty);
  2492. EBRDENABLE(brdp);
  2493. }
  2494. wake_up_interruptible(&tty->write_wait);
  2495. }
  2496. }
  2497. if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
  2498. if (tty != (struct tty_struct *) NULL) {
  2499. if (tty->flip.count < TTY_FLIPBUF_SIZE) {
  2500. tty->flip.count++;
  2501. *tty->flip.flag_buf_ptr++ = TTY_BREAK;
  2502. *tty->flip.char_buf_ptr++ = 0;
  2503. if (portp->flags & ASYNC_SAK) {
  2504. do_SAK(tty);
  2505. EBRDENABLE(brdp);
  2506. }
  2507. tty_schedule_flip(tty);
  2508. }
  2509. }
  2510. }
  2511. if (nt.data & DT_RXBUSY) {
  2512. donerx++;
  2513. stli_read(brdp, portp);
  2514. }
  2515. }
  2516. /*
  2517. * It might seem odd that we are checking for more RX chars here.
  2518. * But, we need to handle the case where the tty buffer was previously
  2519. * filled, but we had more characters to pass up. The slave will not
  2520. * send any more RX notify messages until the RX buffer has been emptied.
  2521. * But it will leave the service bits on (since the buffer is not empty).
  2522. * So from here we can try to process more RX chars.
  2523. */
  2524. if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
  2525. clear_bit(ST_RXING, &portp->state);
  2526. stli_read(brdp, portp);
  2527. }
  2528. return((test_bit(ST_OPENING, &portp->state) ||
  2529. test_bit(ST_CLOSING, &portp->state) ||
  2530. test_bit(ST_CMDING, &portp->state) ||
  2531. test_bit(ST_TXBUSY, &portp->state) ||
  2532. test_bit(ST_RXING, &portp->state)) ? 0 : 1);
  2533. }
  2534. /*****************************************************************************/
  2535. /*
  2536. * Service all ports on a particular board. Assumes that the boards
  2537. * shared memory is enabled, and that the page pointer is pointed
  2538. * at the cdk header structure.
  2539. */
  2540. static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
  2541. {
  2542. stliport_t *portp;
  2543. unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
  2544. unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
  2545. unsigned char *slavep;
  2546. int bitpos, bitat, bitsize;
  2547. int channr, nrdevs, slavebitchange;
  2548. bitsize = brdp->bitsize;
  2549. nrdevs = brdp->nrdevs;
  2550. /*
  2551. * Check if slave wants any service. Basically we try to do as
  2552. * little work as possible here. There are 2 levels of service
  2553. * bits. So if there is nothing to do we bail early. We check
  2554. * 8 service bits at a time in the inner loop, so we can bypass
  2555. * the lot if none of them want service.
  2556. */
  2557. memcpy(&hostbits[0], (((unsigned char *) hdrp) + brdp->hostoffset),
  2558. bitsize);
  2559. memset(&slavebits[0], 0, bitsize);
  2560. slavebitchange = 0;
  2561. for (bitpos = 0; (bitpos < bitsize); bitpos++) {
  2562. if (hostbits[bitpos] == 0)
  2563. continue;
  2564. channr = bitpos * 8;
  2565. for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
  2566. if (hostbits[bitpos] & bitat) {
  2567. portp = brdp->ports[(channr - 1)];
  2568. if (stli_hostcmd(brdp, portp)) {
  2569. slavebitchange++;
  2570. slavebits[bitpos] |= bitat;
  2571. }
  2572. }
  2573. }
  2574. }
  2575. /*
  2576. * If any of the ports are no longer busy then update them in the
  2577. * slave request bits. We need to do this after, since a host port
  2578. * service may initiate more slave requests.
  2579. */
  2580. if (slavebitchange) {
  2581. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2582. slavep = ((unsigned char *) hdrp) + brdp->slaveoffset;
  2583. for (bitpos = 0; (bitpos < bitsize); bitpos++) {
  2584. if (slavebits[bitpos])
  2585. slavep[bitpos] &= ~slavebits[bitpos];
  2586. }
  2587. }
  2588. }
  2589. /*****************************************************************************/
  2590. /*
  2591. * Driver poll routine. This routine polls the boards in use and passes
  2592. * messages back up to host when necessary. This is actually very
  2593. * CPU efficient, since we will always have the kernel poll clock, it
  2594. * adds only a few cycles when idle (since board service can be
  2595. * determined very easily), but when loaded generates no interrupts
  2596. * (with their expensive associated context change).
  2597. */
  2598. static void stli_poll(unsigned long arg)
  2599. {
  2600. volatile cdkhdr_t *hdrp;
  2601. stlibrd_t *brdp;
  2602. int brdnr;
  2603. stli_timerlist.expires = STLI_TIMEOUT;
  2604. add_timer(&stli_timerlist);
  2605. /*
  2606. * Check each board and do any servicing required.
  2607. */
  2608. for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
  2609. brdp = stli_brds[brdnr];
  2610. if (brdp == (stlibrd_t *) NULL)
  2611. continue;
  2612. if ((brdp->state & BST_STARTED) == 0)
  2613. continue;
  2614. EBRDENABLE(brdp);
  2615. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2616. if (hdrp->hostreq)
  2617. stli_brdpoll(brdp, hdrp);
  2618. EBRDDISABLE(brdp);
  2619. }
  2620. }
  2621. /*****************************************************************************/
  2622. /*
  2623. * Translate the termios settings into the port setting structure of
  2624. * the slave.
  2625. */
  2626. static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
  2627. {
  2628. #ifdef DEBUG
  2629. printk(KERN_DEBUG "stli_mkasyport(portp=%x,pp=%x,tiosp=%d)\n",
  2630. (int) portp, (int) pp, (int) tiosp);
  2631. #endif
  2632. memset(pp, 0, sizeof(asyport_t));
  2633. /*
  2634. * Start of by setting the baud, char size, parity and stop bit info.
  2635. */
  2636. pp->baudout = tiosp->c_cflag & CBAUD;
  2637. if (pp->baudout & CBAUDEX) {
  2638. pp->baudout &= ~CBAUDEX;
  2639. if ((pp->baudout < 1) || (pp->baudout > 4))
  2640. tiosp->c_cflag &= ~CBAUDEX;
  2641. else
  2642. pp->baudout += 15;
  2643. }
  2644. pp->baudout = stli_baudrates[pp->baudout];
  2645. if ((tiosp->c_cflag & CBAUD) == B38400) {
  2646. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  2647. pp->baudout = 57600;
  2648. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  2649. pp->baudout = 115200;
  2650. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  2651. pp->baudout = 230400;
  2652. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  2653. pp->baudout = 460800;
  2654. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  2655. pp->baudout = (portp->baud_base / portp->custom_divisor);
  2656. }
  2657. if (pp->baudout > STL_MAXBAUD)
  2658. pp->baudout = STL_MAXBAUD;
  2659. pp->baudin = pp->baudout;
  2660. switch (tiosp->c_cflag & CSIZE) {
  2661. case CS5:
  2662. pp->csize = 5;
  2663. break;
  2664. case CS6:
  2665. pp->csize = 6;
  2666. break;
  2667. case CS7:
  2668. pp->csize = 7;
  2669. break;
  2670. default:
  2671. pp->csize = 8;
  2672. break;
  2673. }
  2674. if (tiosp->c_cflag & CSTOPB)
  2675. pp->stopbs = PT_STOP2;
  2676. else
  2677. pp->stopbs = PT_STOP1;
  2678. if (tiosp->c_cflag & PARENB) {
  2679. if (tiosp->c_cflag & PARODD)
  2680. pp->parity = PT_ODDPARITY;
  2681. else
  2682. pp->parity = PT_EVENPARITY;
  2683. } else {
  2684. pp->parity = PT_NOPARITY;
  2685. }
  2686. /*
  2687. * Set up any flow control options enabled.
  2688. */
  2689. if (tiosp->c_iflag & IXON) {
  2690. pp->flow |= F_IXON;
  2691. if (tiosp->c_iflag & IXANY)
  2692. pp->flow |= F_IXANY;
  2693. }
  2694. if (tiosp->c_cflag & CRTSCTS)
  2695. pp->flow |= (F_RTSFLOW | F_CTSFLOW);
  2696. pp->startin = tiosp->c_cc[VSTART];
  2697. pp->stopin = tiosp->c_cc[VSTOP];
  2698. pp->startout = tiosp->c_cc[VSTART];
  2699. pp->stopout = tiosp->c_cc[VSTOP];
  2700. /*
  2701. * Set up the RX char marking mask with those RX error types we must
  2702. * catch. We can get the slave to help us out a little here, it will
  2703. * ignore parity errors and breaks for us, and mark parity errors in
  2704. * the data stream.
  2705. */
  2706. if (tiosp->c_iflag & IGNPAR)
  2707. pp->iflag |= FI_IGNRXERRS;
  2708. if (tiosp->c_iflag & IGNBRK)
  2709. pp->iflag |= FI_IGNBREAK;
  2710. portp->rxmarkmsk = 0;
  2711. if (tiosp->c_iflag & (INPCK | PARMRK))
  2712. pp->iflag |= FI_1MARKRXERRS;
  2713. if (tiosp->c_iflag & BRKINT)
  2714. portp->rxmarkmsk |= BRKINT;
  2715. /*
  2716. * Set up clocal processing as required.
  2717. */
  2718. if (tiosp->c_cflag & CLOCAL)
  2719. portp->flags &= ~ASYNC_CHECK_CD;
  2720. else
  2721. portp->flags |= ASYNC_CHECK_CD;
  2722. /*
  2723. * Transfer any persistent flags into the asyport structure.
  2724. */
  2725. pp->pflag = (portp->pflag & 0xffff);
  2726. pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
  2727. pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
  2728. pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
  2729. }
  2730. /*****************************************************************************/
  2731. /*
  2732. * Construct a slave signals structure for setting the DTR and RTS
  2733. * signals as specified.
  2734. */
  2735. static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
  2736. {
  2737. #ifdef DEBUG
  2738. printk(KERN_DEBUG "stli_mkasysigs(sp=%x,dtr=%d,rts=%d)\n",
  2739. (int) sp, dtr, rts);
  2740. #endif
  2741. memset(sp, 0, sizeof(asysigs_t));
  2742. if (dtr >= 0) {
  2743. sp->signal |= SG_DTR;
  2744. sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
  2745. }
  2746. if (rts >= 0) {
  2747. sp->signal |= SG_RTS;
  2748. sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
  2749. }
  2750. }
  2751. /*****************************************************************************/
  2752. /*
  2753. * Convert the signals returned from the slave into a local TIOCM type
  2754. * signals value. We keep them locally in TIOCM format.
  2755. */
  2756. static long stli_mktiocm(unsigned long sigvalue)
  2757. {
  2758. long tiocm;
  2759. #ifdef DEBUG
  2760. printk(KERN_DEBUG "stli_mktiocm(sigvalue=%x)\n", (int) sigvalue);
  2761. #endif
  2762. tiocm = 0;
  2763. tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
  2764. tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
  2765. tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
  2766. tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
  2767. tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
  2768. tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
  2769. return(tiocm);
  2770. }
  2771. /*****************************************************************************/
  2772. /*
  2773. * All panels and ports actually attached have been worked out. All
  2774. * we need to do here is set up the appropriate per port data structures.
  2775. */
  2776. static int stli_initports(stlibrd_t *brdp)
  2777. {
  2778. stliport_t *portp;
  2779. int i, panelnr, panelport;
  2780. #ifdef DEBUG
  2781. printk(KERN_DEBUG "stli_initports(brdp=%x)\n", (int) brdp);
  2782. #endif
  2783. for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
  2784. portp = (stliport_t *) stli_memalloc(sizeof(stliport_t));
  2785. if (portp == (stliport_t *) NULL) {
  2786. printk("STALLION: failed to allocate port structure\n");
  2787. continue;
  2788. }
  2789. memset(portp, 0, sizeof(stliport_t));
  2790. portp->magic = STLI_PORTMAGIC;
  2791. portp->portnr = i;
  2792. portp->brdnr = brdp->brdnr;
  2793. portp->panelnr = panelnr;
  2794. portp->baud_base = STL_BAUDBASE;
  2795. portp->close_delay = STL_CLOSEDELAY;
  2796. portp->closing_wait = 30 * HZ;
  2797. INIT_WORK(&portp->tqhangup, stli_dohangup, portp);
  2798. init_waitqueue_head(&portp->open_wait);
  2799. init_waitqueue_head(&portp->close_wait);
  2800. init_waitqueue_head(&portp->raw_wait);
  2801. panelport++;
  2802. if (panelport >= brdp->panels[panelnr]) {
  2803. panelport = 0;
  2804. panelnr++;
  2805. }
  2806. brdp->ports[i] = portp;
  2807. }
  2808. return(0);
  2809. }
  2810. /*****************************************************************************/
  2811. /*
  2812. * All the following routines are board specific hardware operations.
  2813. */
  2814. static void stli_ecpinit(stlibrd_t *brdp)
  2815. {
  2816. unsigned long memconf;
  2817. #ifdef DEBUG
  2818. printk(KERN_DEBUG "stli_ecpinit(brdp=%d)\n", (int) brdp);
  2819. #endif
  2820. outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
  2821. udelay(10);
  2822. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2823. udelay(100);
  2824. memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
  2825. outb(memconf, (brdp->iobase + ECP_ATMEMAR));
  2826. }
  2827. /*****************************************************************************/
  2828. static void stli_ecpenable(stlibrd_t *brdp)
  2829. {
  2830. #ifdef DEBUG
  2831. printk(KERN_DEBUG "stli_ecpenable(brdp=%x)\n", (int) brdp);
  2832. #endif
  2833. outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
  2834. }
  2835. /*****************************************************************************/
  2836. static void stli_ecpdisable(stlibrd_t *brdp)
  2837. {
  2838. #ifdef DEBUG
  2839. printk(KERN_DEBUG "stli_ecpdisable(brdp=%x)\n", (int) brdp);
  2840. #endif
  2841. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2842. }
  2843. /*****************************************************************************/
  2844. static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2845. {
  2846. void *ptr;
  2847. unsigned char val;
  2848. #ifdef DEBUG
  2849. printk(KERN_DEBUG "stli_ecpgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
  2850. (int) offset);
  2851. #endif
  2852. if (offset > brdp->memsize) {
  2853. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2854. "range at line=%d(%d), brd=%d\n",
  2855. (int) offset, line, __LINE__, brdp->brdnr);
  2856. ptr = NULL;
  2857. val = 0;
  2858. } else {
  2859. ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
  2860. val = (unsigned char) (offset / ECP_ATPAGESIZE);
  2861. }
  2862. outb(val, (brdp->iobase + ECP_ATMEMPR));
  2863. return(ptr);
  2864. }
  2865. /*****************************************************************************/
  2866. static void stli_ecpreset(stlibrd_t *brdp)
  2867. {
  2868. #ifdef DEBUG
  2869. printk(KERN_DEBUG "stli_ecpreset(brdp=%x)\n", (int) brdp);
  2870. #endif
  2871. outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
  2872. udelay(10);
  2873. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2874. udelay(500);
  2875. }
  2876. /*****************************************************************************/
  2877. static void stli_ecpintr(stlibrd_t *brdp)
  2878. {
  2879. #ifdef DEBUG
  2880. printk(KERN_DEBUG "stli_ecpintr(brdp=%x)\n", (int) brdp);
  2881. #endif
  2882. outb(0x1, brdp->iobase);
  2883. }
  2884. /*****************************************************************************/
  2885. /*
  2886. * The following set of functions act on ECP EISA boards.
  2887. */
  2888. static void stli_ecpeiinit(stlibrd_t *brdp)
  2889. {
  2890. unsigned long memconf;
  2891. #ifdef DEBUG
  2892. printk(KERN_DEBUG "stli_ecpeiinit(brdp=%x)\n", (int) brdp);
  2893. #endif
  2894. outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
  2895. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  2896. udelay(10);
  2897. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2898. udelay(500);
  2899. memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
  2900. outb(memconf, (brdp->iobase + ECP_EIMEMARL));
  2901. memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
  2902. outb(memconf, (brdp->iobase + ECP_EIMEMARH));
  2903. }
  2904. /*****************************************************************************/
  2905. static void stli_ecpeienable(stlibrd_t *brdp)
  2906. {
  2907. outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
  2908. }
  2909. /*****************************************************************************/
  2910. static void stli_ecpeidisable(stlibrd_t *brdp)
  2911. {
  2912. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2913. }
  2914. /*****************************************************************************/
  2915. static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2916. {
  2917. void *ptr;
  2918. unsigned char val;
  2919. #ifdef DEBUG
  2920. printk(KERN_DEBUG "stli_ecpeigetmemptr(brdp=%x,offset=%x,line=%d)\n",
  2921. (int) brdp, (int) offset, line);
  2922. #endif
  2923. if (offset > brdp->memsize) {
  2924. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2925. "range at line=%d(%d), brd=%d\n",
  2926. (int) offset, line, __LINE__, brdp->brdnr);
  2927. ptr = NULL;
  2928. val = 0;
  2929. } else {
  2930. ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
  2931. if (offset < ECP_EIPAGESIZE)
  2932. val = ECP_EIENABLE;
  2933. else
  2934. val = ECP_EIENABLE | 0x40;
  2935. }
  2936. outb(val, (brdp->iobase + ECP_EICONFR));
  2937. return(ptr);
  2938. }
  2939. /*****************************************************************************/
  2940. static void stli_ecpeireset(stlibrd_t *brdp)
  2941. {
  2942. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  2943. udelay(10);
  2944. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2945. udelay(500);
  2946. }
  2947. /*****************************************************************************/
  2948. /*
  2949. * The following set of functions act on ECP MCA boards.
  2950. */
  2951. static void stli_ecpmcenable(stlibrd_t *brdp)
  2952. {
  2953. outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
  2954. }
  2955. /*****************************************************************************/
  2956. static void stli_ecpmcdisable(stlibrd_t *brdp)
  2957. {
  2958. outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
  2959. }
  2960. /*****************************************************************************/
  2961. static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2962. {
  2963. void *ptr;
  2964. unsigned char val;
  2965. if (offset > brdp->memsize) {
  2966. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2967. "range at line=%d(%d), brd=%d\n",
  2968. (int) offset, line, __LINE__, brdp->brdnr);
  2969. ptr = NULL;
  2970. val = 0;
  2971. } else {
  2972. ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
  2973. val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
  2974. }
  2975. outb(val, (brdp->iobase + ECP_MCCONFR));
  2976. return(ptr);
  2977. }
  2978. /*****************************************************************************/
  2979. static void stli_ecpmcreset(stlibrd_t *brdp)
  2980. {
  2981. outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
  2982. udelay(10);
  2983. outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
  2984. udelay(500);
  2985. }
  2986. /*****************************************************************************/
  2987. /*
  2988. * The following set of functions act on ECP PCI boards.
  2989. */
  2990. static void stli_ecppciinit(stlibrd_t *brdp)
  2991. {
  2992. #ifdef DEBUG
  2993. printk(KERN_DEBUG "stli_ecppciinit(brdp=%x)\n", (int) brdp);
  2994. #endif
  2995. outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
  2996. udelay(10);
  2997. outb(0, (brdp->iobase + ECP_PCICONFR));
  2998. udelay(500);
  2999. }
  3000. /*****************************************************************************/
  3001. static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  3002. {
  3003. void *ptr;
  3004. unsigned char val;
  3005. #ifdef DEBUG
  3006. printk(KERN_DEBUG "stli_ecppcigetmemptr(brdp=%x,offset=%x,line=%d)\n",
  3007. (int) brdp, (int) offset, line);
  3008. #endif
  3009. if (offset > brdp->memsize) {
  3010. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  3011. "range at line=%d(%d), board=%d\n",
  3012. (int) offset, line, __LINE__, brdp->brdnr);
  3013. ptr = NULL;
  3014. val = 0;
  3015. } else {
  3016. ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
  3017. val = (offset / ECP_PCIPAGESIZE) << 1;
  3018. }
  3019. outb(val, (brdp->iobase + ECP_PCICONFR));
  3020. return(ptr);
  3021. }
  3022. /*****************************************************************************/
  3023. static void stli_ecppcireset(stlibrd_t *brdp)
  3024. {
  3025. outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
  3026. udelay(10);
  3027. outb(0, (brdp->iobase + ECP_PCICONFR));
  3028. udelay(500);
  3029. }
  3030. /*****************************************************************************/
  3031. /*
  3032. * The following routines act on ONboards.
  3033. */
  3034. static void stli_onbinit(stlibrd_t *brdp)
  3035. {
  3036. unsigned long memconf;
  3037. #ifdef DEBUG
  3038. printk(KERN_DEBUG "stli_onbinit(brdp=%d)\n", (int) brdp);
  3039. #endif
  3040. outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
  3041. udelay(10);
  3042. outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
  3043. mdelay(1000);
  3044. memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
  3045. outb(memconf, (brdp->iobase + ONB_ATMEMAR));
  3046. outb(0x1, brdp->iobase);
  3047. mdelay(1);
  3048. }
  3049. /*****************************************************************************/
  3050. static void stli_onbenable(stlibrd_t *brdp)
  3051. {
  3052. #ifdef DEBUG
  3053. printk(KERN_DEBUG "stli_onbenable(brdp=%x)\n", (int) brdp);
  3054. #endif
  3055. outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
  3056. }
  3057. /*****************************************************************************/
  3058. static void stli_onbdisable(stlibrd_t *brdp)
  3059. {
  3060. #ifdef DEBUG
  3061. printk(KERN_DEBUG "stli_onbdisable(brdp=%x)\n", (int) brdp);
  3062. #endif
  3063. outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
  3064. }
  3065. /*****************************************************************************/
  3066. static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  3067. {
  3068. void *ptr;
  3069. #ifdef DEBUG
  3070. printk(KERN_DEBUG "stli_onbgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
  3071. (int) offset);
  3072. #endif
  3073. if (offset > brdp->memsize) {
  3074. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  3075. "range at line=%d(%d), brd=%d\n",
  3076. (int) offset, line, __LINE__, brdp->brdnr);
  3077. ptr = NULL;
  3078. } else {
  3079. ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
  3080. }
  3081. return(ptr);
  3082. }
  3083. /*****************************************************************************/
  3084. static void stli_onbreset(stlibrd_t *brdp)
  3085. {
  3086. #ifdef DEBUG
  3087. printk(KERN_DEBUG "stli_onbreset(brdp=%x)\n", (int) brdp);
  3088. #endif
  3089. outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
  3090. udelay(10);
  3091. outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
  3092. mdelay(1000);
  3093. }
  3094. /*****************************************************************************/
  3095. /*
  3096. * The following routines act on ONboard EISA.
  3097. */
  3098. static void stli_onbeinit(stlibrd_t *brdp)
  3099. {
  3100. unsigned long memconf;
  3101. #ifdef DEBUG
  3102. printk(KERN_DEBUG "stli_onbeinit(brdp=%d)\n", (int) brdp);
  3103. #endif
  3104. outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
  3105. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  3106. udelay(10);
  3107. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  3108. mdelay(1000);
  3109. memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
  3110. outb(memconf, (brdp->iobase + ONB_EIMEMARL));
  3111. memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
  3112. outb(memconf, (brdp->iobase + ONB_EIMEMARH));
  3113. outb(0x1, brdp->iobase);
  3114. mdelay(1);
  3115. }
  3116. /*****************************************************************************/
  3117. static void stli_onbeenable(stlibrd_t *brdp)
  3118. {
  3119. #ifdef DEBUG
  3120. printk(KERN_DEBUG "stli_onbeenable(brdp=%x)\n", (int) brdp);
  3121. #endif
  3122. outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
  3123. }
  3124. /*****************************************************************************/
  3125. static void stli_onbedisable(stlibrd_t *brdp)
  3126. {
  3127. #ifdef DEBUG
  3128. printk(KERN_DEBUG "stli_onbedisable(brdp=%x)\n", (int) brdp);
  3129. #endif
  3130. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  3131. }
  3132. /*****************************************************************************/
  3133. static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  3134. {
  3135. void *ptr;
  3136. unsigned char val;
  3137. #ifdef DEBUG
  3138. printk(KERN_DEBUG "stli_onbegetmemptr(brdp=%x,offset=%x,line=%d)\n",
  3139. (int) brdp, (int) offset, line);
  3140. #endif
  3141. if (offset > brdp->memsize) {
  3142. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  3143. "range at line=%d(%d), brd=%d\n",
  3144. (int) offset, line, __LINE__, brdp->brdnr);
  3145. ptr = NULL;
  3146. val = 0;
  3147. } else {
  3148. ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
  3149. if (offset < ONB_EIPAGESIZE)
  3150. val = ONB_EIENABLE;
  3151. else
  3152. val = ONB_EIENABLE | 0x40;
  3153. }
  3154. outb(val, (brdp->iobase + ONB_EICONFR));
  3155. return(ptr);
  3156. }
  3157. /*****************************************************************************/
  3158. static void stli_onbereset(stlibrd_t *brdp)
  3159. {
  3160. #ifdef DEBUG
  3161. printk(KERN_ERR "stli_onbereset(brdp=%x)\n", (int) brdp);
  3162. #endif
  3163. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  3164. udelay(10);
  3165. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  3166. mdelay(1000);
  3167. }
  3168. /*****************************************************************************/
  3169. /*
  3170. * The following routines act on Brumby boards.
  3171. */
  3172. static void stli_bbyinit(stlibrd_t *brdp)
  3173. {
  3174. #ifdef DEBUG
  3175. printk(KERN_ERR "stli_bbyinit(brdp=%d)\n", (int) brdp);
  3176. #endif
  3177. outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
  3178. udelay(10);
  3179. outb(0, (brdp->iobase + BBY_ATCONFR));
  3180. mdelay(1000);
  3181. outb(0x1, brdp->iobase);
  3182. mdelay(1);
  3183. }
  3184. /*****************************************************************************/
  3185. static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  3186. {
  3187. void *ptr;
  3188. unsigned char val;
  3189. #ifdef DEBUG
  3190. printk(KERN_ERR "stli_bbygetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
  3191. (int) offset);
  3192. #endif
  3193. if (offset > brdp->memsize) {
  3194. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  3195. "range at line=%d(%d), brd=%d\n",
  3196. (int) offset, line, __LINE__, brdp->brdnr);
  3197. ptr = NULL;
  3198. val = 0;
  3199. } else {
  3200. ptr = brdp->membase + (offset % BBY_PAGESIZE);
  3201. val = (unsigned char) (offset / BBY_PAGESIZE);
  3202. }
  3203. outb(val, (brdp->iobase + BBY_ATCONFR));
  3204. return(ptr);
  3205. }
  3206. /*****************************************************************************/
  3207. static void stli_bbyreset(stlibrd_t *brdp)
  3208. {
  3209. #ifdef DEBUG
  3210. printk(KERN_DEBUG "stli_bbyreset(brdp=%x)\n", (int) brdp);
  3211. #endif
  3212. outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
  3213. udelay(10);
  3214. outb(0, (brdp->iobase + BBY_ATCONFR));
  3215. mdelay(1000);
  3216. }
  3217. /*****************************************************************************/
  3218. /*
  3219. * The following routines act on original old Stallion boards.
  3220. */
  3221. static void stli_stalinit(stlibrd_t *brdp)
  3222. {
  3223. #ifdef DEBUG
  3224. printk(KERN_DEBUG "stli_stalinit(brdp=%d)\n", (int) brdp);
  3225. #endif
  3226. outb(0x1, brdp->iobase);
  3227. mdelay(1000);
  3228. }
  3229. /*****************************************************************************/
  3230. static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  3231. {
  3232. void *ptr;
  3233. #ifdef DEBUG
  3234. printk(KERN_DEBUG "stli_stalgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
  3235. (int) offset);
  3236. #endif
  3237. if (offset > brdp->memsize) {
  3238. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  3239. "range at line=%d(%d), brd=%d\n",
  3240. (int) offset, line, __LINE__, brdp->brdnr);
  3241. ptr = NULL;
  3242. } else {
  3243. ptr = brdp->membase + (offset % STAL_PAGESIZE);
  3244. }
  3245. return(ptr);
  3246. }
  3247. /*****************************************************************************/
  3248. static void stli_stalreset(stlibrd_t *brdp)
  3249. {
  3250. volatile unsigned long *vecp;
  3251. #ifdef DEBUG
  3252. printk(KERN_DEBUG "stli_stalreset(brdp=%x)\n", (int) brdp);
  3253. #endif
  3254. vecp = (volatile unsigned long *) (brdp->membase + 0x30);
  3255. *vecp = 0xffff0000;
  3256. outb(0, brdp->iobase);
  3257. mdelay(1000);
  3258. }
  3259. /*****************************************************************************/
  3260. /*
  3261. * Try to find an ECP board and initialize it. This handles only ECP
  3262. * board types.
  3263. */
  3264. static int stli_initecp(stlibrd_t *brdp)
  3265. {
  3266. cdkecpsig_t sig;
  3267. cdkecpsig_t *sigsp;
  3268. unsigned int status, nxtid;
  3269. char *name;
  3270. int panelnr, nrports;
  3271. #ifdef DEBUG
  3272. printk(KERN_DEBUG "stli_initecp(brdp=%x)\n", (int) brdp);
  3273. #endif
  3274. if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
  3275. return -EIO;
  3276. if ((brdp->iobase == 0) || (brdp->memaddr == 0))
  3277. {
  3278. release_region(brdp->iobase, brdp->iosize);
  3279. return(-ENODEV);
  3280. }
  3281. brdp->iosize = ECP_IOSIZE;
  3282. /*
  3283. * Based on the specific board type setup the common vars to access
  3284. * and enable shared memory. Set all board specific information now
  3285. * as well.
  3286. */
  3287. switch (brdp->brdtype) {
  3288. case BRD_ECP:
  3289. brdp->membase = (void *) brdp->memaddr;
  3290. brdp->memsize = ECP_MEMSIZE;
  3291. brdp->pagesize = ECP_ATPAGESIZE;
  3292. brdp->init = stli_ecpinit;
  3293. brdp->enable = stli_ecpenable;
  3294. brdp->reenable = stli_ecpenable;
  3295. brdp->disable = stli_ecpdisable;
  3296. brdp->getmemptr = stli_ecpgetmemptr;
  3297. brdp->intr = stli_ecpintr;
  3298. brdp->reset = stli_ecpreset;
  3299. name = "serial(EC8/64)";
  3300. break;
  3301. case BRD_ECPE:
  3302. brdp->membase = (void *) brdp->memaddr;
  3303. brdp->memsize = ECP_MEMSIZE;
  3304. brdp->pagesize = ECP_EIPAGESIZE;
  3305. brdp->init = stli_ecpeiinit;
  3306. brdp->enable = stli_ecpeienable;
  3307. brdp->reenable = stli_ecpeienable;
  3308. brdp->disable = stli_ecpeidisable;
  3309. brdp->getmemptr = stli_ecpeigetmemptr;
  3310. brdp->intr = stli_ecpintr;
  3311. brdp->reset = stli_ecpeireset;
  3312. name = "serial(EC8/64-EI)";
  3313. break;
  3314. case BRD_ECPMC:
  3315. brdp->membase = (void *) brdp->memaddr;
  3316. brdp->memsize = ECP_MEMSIZE;
  3317. brdp->pagesize = ECP_MCPAGESIZE;
  3318. brdp->init = NULL;
  3319. brdp->enable = stli_ecpmcenable;
  3320. brdp->reenable = stli_ecpmcenable;
  3321. brdp->disable = stli_ecpmcdisable;
  3322. brdp->getmemptr = stli_ecpmcgetmemptr;
  3323. brdp->intr = stli_ecpintr;
  3324. brdp->reset = stli_ecpmcreset;
  3325. name = "serial(EC8/64-MCA)";
  3326. break;
  3327. case BRD_ECPPCI:
  3328. brdp->membase = (void *) brdp->memaddr;
  3329. brdp->memsize = ECP_PCIMEMSIZE;
  3330. brdp->pagesize = ECP_PCIPAGESIZE;
  3331. brdp->init = stli_ecppciinit;
  3332. brdp->enable = NULL;
  3333. brdp->reenable = NULL;
  3334. brdp->disable = NULL;
  3335. brdp->getmemptr = stli_ecppcigetmemptr;
  3336. brdp->intr = stli_ecpintr;
  3337. brdp->reset = stli_ecppcireset;
  3338. name = "serial(EC/RA-PCI)";
  3339. break;
  3340. default:
  3341. release_region(brdp->iobase, brdp->iosize);
  3342. return(-EINVAL);
  3343. }
  3344. /*
  3345. * The per-board operations structure is all set up, so now let's go
  3346. * and get the board operational. Firstly initialize board configuration
  3347. * registers. Set the memory mapping info so we can get at the boards
  3348. * shared memory.
  3349. */
  3350. EBRDINIT(brdp);
  3351. brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
  3352. if (brdp->membase == (void *) NULL)
  3353. {
  3354. release_region(brdp->iobase, brdp->iosize);
  3355. return(-ENOMEM);
  3356. }
  3357. /*
  3358. * Now that all specific code is set up, enable the shared memory and
  3359. * look for the a signature area that will tell us exactly what board
  3360. * this is, and what it is connected to it.
  3361. */
  3362. EBRDENABLE(brdp);
  3363. sigsp = (cdkecpsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
  3364. memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
  3365. EBRDDISABLE(brdp);
  3366. #if 0
  3367. printk("%s(%d): sig-> magic=%x rom=%x panel=%x,%x,%x,%x,%x,%x,%x,%x\n",
  3368. __FILE__, __LINE__, (int) sig.magic, sig.romver, sig.panelid[0],
  3369. (int) sig.panelid[1], (int) sig.panelid[2],
  3370. (int) sig.panelid[3], (int) sig.panelid[4],
  3371. (int) sig.panelid[5], (int) sig.panelid[6],
  3372. (int) sig.panelid[7]);
  3373. #endif
  3374. if (sig.magic != ECP_MAGIC)
  3375. {
  3376. release_region(brdp->iobase, brdp->iosize);
  3377. return(-ENODEV);
  3378. }
  3379. /*
  3380. * Scan through the signature looking at the panels connected to the
  3381. * board. Calculate the total number of ports as we go.
  3382. */
  3383. for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
  3384. status = sig.panelid[nxtid];
  3385. if ((status & ECH_PNLIDMASK) != nxtid)
  3386. break;
  3387. brdp->panelids[panelnr] = status;
  3388. nrports = (status & ECH_PNL16PORT) ? 16 : 8;
  3389. if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
  3390. nxtid++;
  3391. brdp->panels[panelnr] = nrports;
  3392. brdp->nrports += nrports;
  3393. nxtid++;
  3394. brdp->nrpanels++;
  3395. }
  3396. brdp->state |= BST_FOUND;
  3397. return(0);
  3398. }
  3399. /*****************************************************************************/
  3400. /*
  3401. * Try to find an ONboard, Brumby or Stallion board and initialize it.
  3402. * This handles only these board types.
  3403. */
  3404. static int stli_initonb(stlibrd_t *brdp)
  3405. {
  3406. cdkonbsig_t sig;
  3407. cdkonbsig_t *sigsp;
  3408. char *name;
  3409. int i;
  3410. #ifdef DEBUG
  3411. printk(KERN_DEBUG "stli_initonb(brdp=%x)\n", (int) brdp);
  3412. #endif
  3413. /*
  3414. * Do a basic sanity check on the IO and memory addresses.
  3415. */
  3416. if ((brdp->iobase == 0) || (brdp->memaddr == 0))
  3417. return(-ENODEV);
  3418. brdp->iosize = ONB_IOSIZE;
  3419. if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
  3420. return -EIO;
  3421. /*
  3422. * Based on the specific board type setup the common vars to access
  3423. * and enable shared memory. Set all board specific information now
  3424. * as well.
  3425. */
  3426. switch (brdp->brdtype) {
  3427. case BRD_ONBOARD:
  3428. case BRD_ONBOARD32:
  3429. case BRD_ONBOARD2:
  3430. case BRD_ONBOARD2_32:
  3431. case BRD_ONBOARDRS:
  3432. brdp->membase = (void *) brdp->memaddr;
  3433. brdp->memsize = ONB_MEMSIZE;
  3434. brdp->pagesize = ONB_ATPAGESIZE;
  3435. brdp->init = stli_onbinit;
  3436. brdp->enable = stli_onbenable;
  3437. brdp->reenable = stli_onbenable;
  3438. brdp->disable = stli_onbdisable;
  3439. brdp->getmemptr = stli_onbgetmemptr;
  3440. brdp->intr = stli_ecpintr;
  3441. brdp->reset = stli_onbreset;
  3442. if (brdp->memaddr > 0x100000)
  3443. brdp->enabval = ONB_MEMENABHI;
  3444. else
  3445. brdp->enabval = ONB_MEMENABLO;
  3446. name = "serial(ONBoard)";
  3447. break;
  3448. case BRD_ONBOARDE:
  3449. brdp->membase = (void *) brdp->memaddr;
  3450. brdp->memsize = ONB_EIMEMSIZE;
  3451. brdp->pagesize = ONB_EIPAGESIZE;
  3452. brdp->init = stli_onbeinit;
  3453. brdp->enable = stli_onbeenable;
  3454. brdp->reenable = stli_onbeenable;
  3455. brdp->disable = stli_onbedisable;
  3456. brdp->getmemptr = stli_onbegetmemptr;
  3457. brdp->intr = stli_ecpintr;
  3458. brdp->reset = stli_onbereset;
  3459. name = "serial(ONBoard/E)";
  3460. break;
  3461. case BRD_BRUMBY4:
  3462. case BRD_BRUMBY8:
  3463. case BRD_BRUMBY16:
  3464. brdp->membase = (void *) brdp->memaddr;
  3465. brdp->memsize = BBY_MEMSIZE;
  3466. brdp->pagesize = BBY_PAGESIZE;
  3467. brdp->init = stli_bbyinit;
  3468. brdp->enable = NULL;
  3469. brdp->reenable = NULL;
  3470. brdp->disable = NULL;
  3471. brdp->getmemptr = stli_bbygetmemptr;
  3472. brdp->intr = stli_ecpintr;
  3473. brdp->reset = stli_bbyreset;
  3474. name = "serial(Brumby)";
  3475. break;
  3476. case BRD_STALLION:
  3477. brdp->membase = (void *) brdp->memaddr;
  3478. brdp->memsize = STAL_MEMSIZE;
  3479. brdp->pagesize = STAL_PAGESIZE;
  3480. brdp->init = stli_stalinit;
  3481. brdp->enable = NULL;
  3482. brdp->reenable = NULL;
  3483. brdp->disable = NULL;
  3484. brdp->getmemptr = stli_stalgetmemptr;
  3485. brdp->intr = stli_ecpintr;
  3486. brdp->reset = stli_stalreset;
  3487. name = "serial(Stallion)";
  3488. break;
  3489. default:
  3490. release_region(brdp->iobase, brdp->iosize);
  3491. return(-EINVAL);
  3492. }
  3493. /*
  3494. * The per-board operations structure is all set up, so now let's go
  3495. * and get the board operational. Firstly initialize board configuration
  3496. * registers. Set the memory mapping info so we can get at the boards
  3497. * shared memory.
  3498. */
  3499. EBRDINIT(brdp);
  3500. brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
  3501. if (brdp->membase == (void *) NULL)
  3502. {
  3503. release_region(brdp->iobase, brdp->iosize);
  3504. return(-ENOMEM);
  3505. }
  3506. /*
  3507. * Now that all specific code is set up, enable the shared memory and
  3508. * look for the a signature area that will tell us exactly what board
  3509. * this is, and how many ports.
  3510. */
  3511. EBRDENABLE(brdp);
  3512. sigsp = (cdkonbsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
  3513. memcpy(&sig, sigsp, sizeof(cdkonbsig_t));
  3514. EBRDDISABLE(brdp);
  3515. #if 0
  3516. printk("%s(%d): sig-> magic=%x:%x:%x:%x romver=%x amask=%x:%x:%x\n",
  3517. __FILE__, __LINE__, sig.magic0, sig.magic1, sig.magic2,
  3518. sig.magic3, sig.romver, sig.amask0, sig.amask1, sig.amask2);
  3519. #endif
  3520. if ((sig.magic0 != ONB_MAGIC0) || (sig.magic1 != ONB_MAGIC1) ||
  3521. (sig.magic2 != ONB_MAGIC2) || (sig.magic3 != ONB_MAGIC3))
  3522. {
  3523. release_region(brdp->iobase, brdp->iosize);
  3524. return(-ENODEV);
  3525. }
  3526. /*
  3527. * Scan through the signature alive mask and calculate how many ports
  3528. * there are on this board.
  3529. */
  3530. brdp->nrpanels = 1;
  3531. if (sig.amask1) {
  3532. brdp->nrports = 32;
  3533. } else {
  3534. for (i = 0; (i < 16); i++) {
  3535. if (((sig.amask0 << i) & 0x8000) == 0)
  3536. break;
  3537. }
  3538. brdp->nrports = i;
  3539. }
  3540. brdp->panels[0] = brdp->nrports;
  3541. brdp->state |= BST_FOUND;
  3542. return(0);
  3543. }
  3544. /*****************************************************************************/
  3545. /*
  3546. * Start up a running board. This routine is only called after the
  3547. * code has been down loaded to the board and is operational. It will
  3548. * read in the memory map, and get the show on the road...
  3549. */
  3550. static int stli_startbrd(stlibrd_t *brdp)
  3551. {
  3552. volatile cdkhdr_t *hdrp;
  3553. volatile cdkmem_t *memp;
  3554. volatile cdkasy_t *ap;
  3555. unsigned long flags;
  3556. stliport_t *portp;
  3557. int portnr, nrdevs, i, rc;
  3558. #ifdef DEBUG
  3559. printk(KERN_DEBUG "stli_startbrd(brdp=%x)\n", (int) brdp);
  3560. #endif
  3561. rc = 0;
  3562. save_flags(flags);
  3563. cli();
  3564. EBRDENABLE(brdp);
  3565. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  3566. nrdevs = hdrp->nrdevs;
  3567. #if 0
  3568. printk("%s(%d): CDK version %d.%d.%d --> "
  3569. "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
  3570. __FILE__, __LINE__, hdrp->ver_release, hdrp->ver_modification,
  3571. hdrp->ver_fix, nrdevs, (int) hdrp->memp, (int) hdrp->hostp,
  3572. (int) hdrp->slavep);
  3573. #endif
  3574. if (nrdevs < (brdp->nrports + 1)) {
  3575. printk(KERN_ERR "STALLION: slave failed to allocate memory for "
  3576. "all devices, devices=%d\n", nrdevs);
  3577. brdp->nrports = nrdevs - 1;
  3578. }
  3579. brdp->nrdevs = nrdevs;
  3580. brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
  3581. brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
  3582. brdp->bitsize = (nrdevs + 7) / 8;
  3583. memp = (volatile cdkmem_t *) hdrp->memp;
  3584. if (((unsigned long) memp) > brdp->memsize) {
  3585. printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
  3586. rc = -EIO;
  3587. goto stli_donestartup;
  3588. }
  3589. memp = (volatile cdkmem_t *) EBRDGETMEMPTR(brdp, (unsigned long) memp);
  3590. if (memp->dtype != TYP_ASYNCTRL) {
  3591. printk(KERN_ERR "STALLION: no slave control device found\n");
  3592. goto stli_donestartup;
  3593. }
  3594. memp++;
  3595. /*
  3596. * Cycle through memory allocation of each port. We are guaranteed to
  3597. * have all ports inside the first page of slave window, so no need to
  3598. * change pages while reading memory map.
  3599. */
  3600. for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
  3601. if (memp->dtype != TYP_ASYNC)
  3602. break;
  3603. portp = brdp->ports[portnr];
  3604. if (portp == (stliport_t *) NULL)
  3605. break;
  3606. portp->devnr = i;
  3607. portp->addr = memp->offset;
  3608. portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
  3609. portp->portidx = (unsigned char) (i / 8);
  3610. portp->portbit = (unsigned char) (0x1 << (i % 8));
  3611. }
  3612. hdrp->slavereq = 0xff;
  3613. /*
  3614. * For each port setup a local copy of the RX and TX buffer offsets
  3615. * and sizes. We do this separate from the above, because we need to
  3616. * move the shared memory page...
  3617. */
  3618. for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
  3619. portp = brdp->ports[portnr];
  3620. if (portp == (stliport_t *) NULL)
  3621. break;
  3622. if (portp->addr == 0)
  3623. break;
  3624. ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
  3625. if (ap != (volatile cdkasy_t *) NULL) {
  3626. portp->rxsize = ap->rxq.size;
  3627. portp->txsize = ap->txq.size;
  3628. portp->rxoffset = ap->rxq.offset;
  3629. portp->txoffset = ap->txq.offset;
  3630. }
  3631. }
  3632. stli_donestartup:
  3633. EBRDDISABLE(brdp);
  3634. restore_flags(flags);
  3635. if (rc == 0)
  3636. brdp->state |= BST_STARTED;
  3637. if (! stli_timeron) {
  3638. stli_timeron++;
  3639. stli_timerlist.expires = STLI_TIMEOUT;
  3640. add_timer(&stli_timerlist);
  3641. }
  3642. return(rc);
  3643. }
  3644. /*****************************************************************************/
  3645. /*
  3646. * Probe and initialize the specified board.
  3647. */
  3648. static int __init stli_brdinit(stlibrd_t *brdp)
  3649. {
  3650. #ifdef DEBUG
  3651. printk(KERN_DEBUG "stli_brdinit(brdp=%x)\n", (int) brdp);
  3652. #endif
  3653. stli_brds[brdp->brdnr] = brdp;
  3654. switch (brdp->brdtype) {
  3655. case BRD_ECP:
  3656. case BRD_ECPE:
  3657. case BRD_ECPMC:
  3658. case BRD_ECPPCI:
  3659. stli_initecp(brdp);
  3660. break;
  3661. case BRD_ONBOARD:
  3662. case BRD_ONBOARDE:
  3663. case BRD_ONBOARD2:
  3664. case BRD_ONBOARD32:
  3665. case BRD_ONBOARD2_32:
  3666. case BRD_ONBOARDRS:
  3667. case BRD_BRUMBY4:
  3668. case BRD_BRUMBY8:
  3669. case BRD_BRUMBY16:
  3670. case BRD_STALLION:
  3671. stli_initonb(brdp);
  3672. break;
  3673. case BRD_EASYIO:
  3674. case BRD_ECH:
  3675. case BRD_ECHMC:
  3676. case BRD_ECHPCI:
  3677. printk(KERN_ERR "STALLION: %s board type not supported in "
  3678. "this driver\n", stli_brdnames[brdp->brdtype]);
  3679. return(ENODEV);
  3680. default:
  3681. printk(KERN_ERR "STALLION: board=%d is unknown board "
  3682. "type=%d\n", brdp->brdnr, brdp->brdtype);
  3683. return(ENODEV);
  3684. }
  3685. if ((brdp->state & BST_FOUND) == 0) {
  3686. printk(KERN_ERR "STALLION: %s board not found, board=%d "
  3687. "io=%x mem=%x\n",
  3688. stli_brdnames[brdp->brdtype], brdp->brdnr,
  3689. brdp->iobase, (int) brdp->memaddr);
  3690. return(ENODEV);
  3691. }
  3692. stli_initports(brdp);
  3693. printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
  3694. "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
  3695. brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
  3696. brdp->nrpanels, brdp->nrports);
  3697. return(0);
  3698. }
  3699. /*****************************************************************************/
  3700. /*
  3701. * Probe around trying to find where the EISA boards shared memory
  3702. * might be. This is a bit if hack, but it is the best we can do.
  3703. */
  3704. static int stli_eisamemprobe(stlibrd_t *brdp)
  3705. {
  3706. cdkecpsig_t ecpsig, *ecpsigp;
  3707. cdkonbsig_t onbsig, *onbsigp;
  3708. int i, foundit;
  3709. #ifdef DEBUG
  3710. printk(KERN_DEBUG "stli_eisamemprobe(brdp=%x)\n", (int) brdp);
  3711. #endif
  3712. /*
  3713. * First up we reset the board, to get it into a known state. There
  3714. * is only 2 board types here we need to worry about. Don;t use the
  3715. * standard board init routine here, it programs up the shared
  3716. * memory address, and we don't know it yet...
  3717. */
  3718. if (brdp->brdtype == BRD_ECPE) {
  3719. outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
  3720. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  3721. udelay(10);
  3722. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  3723. udelay(500);
  3724. stli_ecpeienable(brdp);
  3725. } else if (brdp->brdtype == BRD_ONBOARDE) {
  3726. outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
  3727. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  3728. udelay(10);
  3729. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  3730. mdelay(100);
  3731. outb(0x1, brdp->iobase);
  3732. mdelay(1);
  3733. stli_onbeenable(brdp);
  3734. } else {
  3735. return(-ENODEV);
  3736. }
  3737. foundit = 0;
  3738. brdp->memsize = ECP_MEMSIZE;
  3739. /*
  3740. * Board shared memory is enabled, so now we have a poke around and
  3741. * see if we can find it.
  3742. */
  3743. for (i = 0; (i < stli_eisamempsize); i++) {
  3744. brdp->memaddr = stli_eisamemprobeaddrs[i];
  3745. brdp->membase = (void *) brdp->memaddr;
  3746. brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
  3747. if (brdp->membase == (void *) NULL)
  3748. continue;
  3749. if (brdp->brdtype == BRD_ECPE) {
  3750. ecpsigp = (cdkecpsig_t *) stli_ecpeigetmemptr(brdp,
  3751. CDK_SIGADDR, __LINE__);
  3752. memcpy(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
  3753. if (ecpsig.magic == ECP_MAGIC)
  3754. foundit = 1;
  3755. } else {
  3756. onbsigp = (cdkonbsig_t *) stli_onbegetmemptr(brdp,
  3757. CDK_SIGADDR, __LINE__);
  3758. memcpy(&onbsig, onbsigp, sizeof(cdkonbsig_t));
  3759. if ((onbsig.magic0 == ONB_MAGIC0) &&
  3760. (onbsig.magic1 == ONB_MAGIC1) &&
  3761. (onbsig.magic2 == ONB_MAGIC2) &&
  3762. (onbsig.magic3 == ONB_MAGIC3))
  3763. foundit = 1;
  3764. }
  3765. iounmap(brdp->membase);
  3766. if (foundit)
  3767. break;
  3768. }
  3769. /*
  3770. * Regardless of whether we found the shared memory or not we must
  3771. * disable the region. After that return success or failure.
  3772. */
  3773. if (brdp->brdtype == BRD_ECPE)
  3774. stli_ecpeidisable(brdp);
  3775. else
  3776. stli_onbedisable(brdp);
  3777. if (! foundit) {
  3778. brdp->memaddr = 0;
  3779. brdp->membase = NULL;
  3780. printk(KERN_ERR "STALLION: failed to probe shared memory "
  3781. "region for %s in EISA slot=%d\n",
  3782. stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
  3783. return(-ENODEV);
  3784. }
  3785. return(0);
  3786. }
  3787. static int stli_getbrdnr(void)
  3788. {
  3789. int i;
  3790. for (i = 0; i < STL_MAXBRDS; i++) {
  3791. if (!stli_brds[i]) {
  3792. if (i >= stli_nrbrds)
  3793. stli_nrbrds = i + 1;
  3794. return i;
  3795. }
  3796. }
  3797. return -1;
  3798. }
  3799. /*****************************************************************************/
  3800. /*
  3801. * Probe around and try to find any EISA boards in system. The biggest
  3802. * problem here is finding out what memory address is associated with
  3803. * an EISA board after it is found. The registers of the ECPE and
  3804. * ONboardE are not readable - so we can't read them from there. We
  3805. * don't have access to the EISA CMOS (or EISA BIOS) so we don't
  3806. * actually have any way to find out the real value. The best we can
  3807. * do is go probing around in the usual places hoping we can find it.
  3808. */
  3809. static int stli_findeisabrds(void)
  3810. {
  3811. stlibrd_t *brdp;
  3812. unsigned int iobase, eid;
  3813. int i;
  3814. #ifdef DEBUG
  3815. printk(KERN_DEBUG "stli_findeisabrds()\n");
  3816. #endif
  3817. /*
  3818. * Firstly check if this is an EISA system. Do this by probing for
  3819. * the system board EISA ID. If this is not an EISA system then
  3820. * don't bother going any further!
  3821. */
  3822. outb(0xff, 0xc80);
  3823. if (inb(0xc80) == 0xff)
  3824. return(0);
  3825. /*
  3826. * Looks like an EISA system, so go searching for EISA boards.
  3827. */
  3828. for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
  3829. outb(0xff, (iobase + 0xc80));
  3830. eid = inb(iobase + 0xc80);
  3831. eid |= inb(iobase + 0xc81) << 8;
  3832. if (eid != STL_EISAID)
  3833. continue;
  3834. /*
  3835. * We have found a board. Need to check if this board was
  3836. * statically configured already (just in case!).
  3837. */
  3838. for (i = 0; (i < STL_MAXBRDS); i++) {
  3839. brdp = stli_brds[i];
  3840. if (brdp == (stlibrd_t *) NULL)
  3841. continue;
  3842. if (brdp->iobase == iobase)
  3843. break;
  3844. }
  3845. if (i < STL_MAXBRDS)
  3846. continue;
  3847. /*
  3848. * We have found a Stallion board and it is not configured already.
  3849. * Allocate a board structure and initialize it.
  3850. */
  3851. if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
  3852. return(-ENOMEM);
  3853. if ((brdp->brdnr = stli_getbrdnr()) < 0)
  3854. return(-ENOMEM);
  3855. eid = inb(iobase + 0xc82);
  3856. if (eid == ECP_EISAID)
  3857. brdp->brdtype = BRD_ECPE;
  3858. else if (eid == ONB_EISAID)
  3859. brdp->brdtype = BRD_ONBOARDE;
  3860. else
  3861. brdp->brdtype = BRD_UNKNOWN;
  3862. brdp->iobase = iobase;
  3863. outb(0x1, (iobase + 0xc84));
  3864. if (stli_eisamemprobe(brdp))
  3865. outb(0, (iobase + 0xc84));
  3866. stli_brdinit(brdp);
  3867. }
  3868. return(0);
  3869. }
  3870. /*****************************************************************************/
  3871. /*
  3872. * Find the next available board number that is free.
  3873. */
  3874. /*****************************************************************************/
  3875. #ifdef CONFIG_PCI
  3876. /*
  3877. * We have a Stallion board. Allocate a board structure and
  3878. * initialize it. Read its IO and MEMORY resources from PCI
  3879. * configuration space.
  3880. */
  3881. static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
  3882. {
  3883. stlibrd_t *brdp;
  3884. #ifdef DEBUG
  3885. printk(KERN_DEBUG "stli_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n",
  3886. brdtype, dev->bus->number, dev->devfn);
  3887. #endif
  3888. if (pci_enable_device(devp))
  3889. return(-EIO);
  3890. if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
  3891. return(-ENOMEM);
  3892. if ((brdp->brdnr = stli_getbrdnr()) < 0) {
  3893. printk(KERN_INFO "STALLION: too many boards found, "
  3894. "maximum supported %d\n", STL_MAXBRDS);
  3895. return(0);
  3896. }
  3897. brdp->brdtype = brdtype;
  3898. #ifdef DEBUG
  3899. printk(KERN_DEBUG "%s(%d): BAR[]=%lx,%lx,%lx,%lx\n", __FILE__, __LINE__,
  3900. pci_resource_start(devp, 0),
  3901. pci_resource_start(devp, 1),
  3902. pci_resource_start(devp, 2),
  3903. pci_resource_start(devp, 3));
  3904. #endif
  3905. /*
  3906. * We have all resources from the board, so lets setup the actual
  3907. * board structure now.
  3908. */
  3909. brdp->iobase = pci_resource_start(devp, 3);
  3910. brdp->memaddr = pci_resource_start(devp, 2);
  3911. stli_brdinit(brdp);
  3912. return(0);
  3913. }
  3914. /*****************************************************************************/
  3915. /*
  3916. * Find all Stallion PCI boards that might be installed. Initialize each
  3917. * one as it is found.
  3918. */
  3919. static int stli_findpcibrds(void)
  3920. {
  3921. struct pci_dev *dev = NULL;
  3922. int rc;
  3923. #ifdef DEBUG
  3924. printk("stli_findpcibrds()\n");
  3925. #endif
  3926. while ((dev = pci_find_device(PCI_VENDOR_ID_STALLION,
  3927. PCI_DEVICE_ID_ECRA, dev))) {
  3928. if ((rc = stli_initpcibrd(BRD_ECPPCI, dev)))
  3929. return(rc);
  3930. }
  3931. return(0);
  3932. }
  3933. #endif
  3934. /*****************************************************************************/
  3935. /*
  3936. * Allocate a new board structure. Fill out the basic info in it.
  3937. */
  3938. static stlibrd_t *stli_allocbrd(void)
  3939. {
  3940. stlibrd_t *brdp;
  3941. brdp = (stlibrd_t *) stli_memalloc(sizeof(stlibrd_t));
  3942. if (brdp == (stlibrd_t *) NULL) {
  3943. printk(KERN_ERR "STALLION: failed to allocate memory "
  3944. "(size=%d)\n", sizeof(stlibrd_t));
  3945. return((stlibrd_t *) NULL);
  3946. }
  3947. memset(brdp, 0, sizeof(stlibrd_t));
  3948. brdp->magic = STLI_BOARDMAGIC;
  3949. return(brdp);
  3950. }
  3951. /*****************************************************************************/
  3952. /*
  3953. * Scan through all the boards in the configuration and see what we
  3954. * can find.
  3955. */
  3956. static int stli_initbrds(void)
  3957. {
  3958. stlibrd_t *brdp, *nxtbrdp;
  3959. stlconf_t *confp;
  3960. int i, j;
  3961. #ifdef DEBUG
  3962. printk(KERN_DEBUG "stli_initbrds()\n");
  3963. #endif
  3964. if (stli_nrbrds > STL_MAXBRDS) {
  3965. printk(KERN_INFO "STALLION: too many boards in configuration "
  3966. "table, truncating to %d\n", STL_MAXBRDS);
  3967. stli_nrbrds = STL_MAXBRDS;
  3968. }
  3969. /*
  3970. * Firstly scan the list of static boards configured. Allocate
  3971. * resources and initialize the boards as found. If this is a
  3972. * module then let the module args override static configuration.
  3973. */
  3974. for (i = 0; (i < stli_nrbrds); i++) {
  3975. confp = &stli_brdconf[i];
  3976. #ifdef MODULE
  3977. stli_parsebrd(confp, stli_brdsp[i]);
  3978. #endif
  3979. if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
  3980. return(-ENOMEM);
  3981. brdp->brdnr = i;
  3982. brdp->brdtype = confp->brdtype;
  3983. brdp->iobase = confp->ioaddr1;
  3984. brdp->memaddr = confp->memaddr;
  3985. stli_brdinit(brdp);
  3986. }
  3987. /*
  3988. * Static configuration table done, so now use dynamic methods to
  3989. * see if any more boards should be configured.
  3990. */
  3991. #ifdef MODULE
  3992. stli_argbrds();
  3993. #endif
  3994. if (stli_eisaprobe)
  3995. stli_findeisabrds();
  3996. #ifdef CONFIG_PCI
  3997. stli_findpcibrds();
  3998. #endif
  3999. /*
  4000. * All found boards are initialized. Now for a little optimization, if
  4001. * no boards are sharing the "shared memory" regions then we can just
  4002. * leave them all enabled. This is in fact the usual case.
  4003. */
  4004. stli_shared = 0;
  4005. if (stli_nrbrds > 1) {
  4006. for (i = 0; (i < stli_nrbrds); i++) {
  4007. brdp = stli_brds[i];
  4008. if (brdp == (stlibrd_t *) NULL)
  4009. continue;
  4010. for (j = i + 1; (j < stli_nrbrds); j++) {
  4011. nxtbrdp = stli_brds[j];
  4012. if (nxtbrdp == (stlibrd_t *) NULL)
  4013. continue;
  4014. if ((brdp->membase >= nxtbrdp->membase) &&
  4015. (brdp->membase <= (nxtbrdp->membase +
  4016. nxtbrdp->memsize - 1))) {
  4017. stli_shared++;
  4018. break;
  4019. }
  4020. }
  4021. }
  4022. }
  4023. if (stli_shared == 0) {
  4024. for (i = 0; (i < stli_nrbrds); i++) {
  4025. brdp = stli_brds[i];
  4026. if (brdp == (stlibrd_t *) NULL)
  4027. continue;
  4028. if (brdp->state & BST_FOUND) {
  4029. EBRDENABLE(brdp);
  4030. brdp->enable = NULL;
  4031. brdp->disable = NULL;
  4032. }
  4033. }
  4034. }
  4035. return(0);
  4036. }
  4037. /*****************************************************************************/
  4038. /*
  4039. * Code to handle an "staliomem" read operation. This device is the
  4040. * contents of the board shared memory. It is used for down loading
  4041. * the slave image (and debugging :-)
  4042. */
  4043. static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
  4044. {
  4045. unsigned long flags;
  4046. void *memptr;
  4047. stlibrd_t *brdp;
  4048. int brdnr, size, n;
  4049. #ifdef DEBUG
  4050. printk(KERN_DEBUG "stli_memread(fp=%x,buf=%x,count=%x,offp=%x)\n",
  4051. (int) fp, (int) buf, count, (int) offp);
  4052. #endif
  4053. brdnr = iminor(fp->f_dentry->d_inode);
  4054. if (brdnr >= stli_nrbrds)
  4055. return(-ENODEV);
  4056. brdp = stli_brds[brdnr];
  4057. if (brdp == (stlibrd_t *) NULL)
  4058. return(-ENODEV);
  4059. if (brdp->state == 0)
  4060. return(-ENODEV);
  4061. if (fp->f_pos >= brdp->memsize)
  4062. return(0);
  4063. size = MIN(count, (brdp->memsize - fp->f_pos));
  4064. save_flags(flags);
  4065. cli();
  4066. EBRDENABLE(brdp);
  4067. while (size > 0) {
  4068. memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
  4069. n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
  4070. if (copy_to_user(buf, memptr, n)) {
  4071. count = -EFAULT;
  4072. goto out;
  4073. }
  4074. fp->f_pos += n;
  4075. buf += n;
  4076. size -= n;
  4077. }
  4078. out:
  4079. EBRDDISABLE(brdp);
  4080. restore_flags(flags);
  4081. return(count);
  4082. }
  4083. /*****************************************************************************/
  4084. /*
  4085. * Code to handle an "staliomem" write operation. This device is the
  4086. * contents of the board shared memory. It is used for down loading
  4087. * the slave image (and debugging :-)
  4088. */
  4089. static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
  4090. {
  4091. unsigned long flags;
  4092. void *memptr;
  4093. stlibrd_t *brdp;
  4094. char __user *chbuf;
  4095. int brdnr, size, n;
  4096. #ifdef DEBUG
  4097. printk(KERN_DEBUG "stli_memwrite(fp=%x,buf=%x,count=%x,offp=%x)\n",
  4098. (int) fp, (int) buf, count, (int) offp);
  4099. #endif
  4100. brdnr = iminor(fp->f_dentry->d_inode);
  4101. if (brdnr >= stli_nrbrds)
  4102. return(-ENODEV);
  4103. brdp = stli_brds[brdnr];
  4104. if (brdp == (stlibrd_t *) NULL)
  4105. return(-ENODEV);
  4106. if (brdp->state == 0)
  4107. return(-ENODEV);
  4108. if (fp->f_pos >= brdp->memsize)
  4109. return(0);
  4110. chbuf = (char __user *) buf;
  4111. size = MIN(count, (brdp->memsize - fp->f_pos));
  4112. save_flags(flags);
  4113. cli();
  4114. EBRDENABLE(brdp);
  4115. while (size > 0) {
  4116. memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
  4117. n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
  4118. if (copy_from_user(memptr, chbuf, n)) {
  4119. count = -EFAULT;
  4120. goto out;
  4121. }
  4122. fp->f_pos += n;
  4123. chbuf += n;
  4124. size -= n;
  4125. }
  4126. out:
  4127. EBRDDISABLE(brdp);
  4128. restore_flags(flags);
  4129. return(count);
  4130. }
  4131. /*****************************************************************************/
  4132. /*
  4133. * Return the board stats structure to user app.
  4134. */
  4135. static int stli_getbrdstats(combrd_t __user *bp)
  4136. {
  4137. stlibrd_t *brdp;
  4138. int i;
  4139. if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
  4140. return -EFAULT;
  4141. if (stli_brdstats.brd >= STL_MAXBRDS)
  4142. return(-ENODEV);
  4143. brdp = stli_brds[stli_brdstats.brd];
  4144. if (brdp == (stlibrd_t *) NULL)
  4145. return(-ENODEV);
  4146. memset(&stli_brdstats, 0, sizeof(combrd_t));
  4147. stli_brdstats.brd = brdp->brdnr;
  4148. stli_brdstats.type = brdp->brdtype;
  4149. stli_brdstats.hwid = 0;
  4150. stli_brdstats.state = brdp->state;
  4151. stli_brdstats.ioaddr = brdp->iobase;
  4152. stli_brdstats.memaddr = brdp->memaddr;
  4153. stli_brdstats.nrpanels = brdp->nrpanels;
  4154. stli_brdstats.nrports = brdp->nrports;
  4155. for (i = 0; (i < brdp->nrpanels); i++) {
  4156. stli_brdstats.panels[i].panel = i;
  4157. stli_brdstats.panels[i].hwid = brdp->panelids[i];
  4158. stli_brdstats.panels[i].nrports = brdp->panels[i];
  4159. }
  4160. if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
  4161. return -EFAULT;
  4162. return(0);
  4163. }
  4164. /*****************************************************************************/
  4165. /*
  4166. * Resolve the referenced port number into a port struct pointer.
  4167. */
  4168. static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
  4169. {
  4170. stlibrd_t *brdp;
  4171. int i;
  4172. if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
  4173. return((stliport_t *) NULL);
  4174. brdp = stli_brds[brdnr];
  4175. if (brdp == (stlibrd_t *) NULL)
  4176. return((stliport_t *) NULL);
  4177. for (i = 0; (i < panelnr); i++)
  4178. portnr += brdp->panels[i];
  4179. if ((portnr < 0) || (portnr >= brdp->nrports))
  4180. return((stliport_t *) NULL);
  4181. return(brdp->ports[portnr]);
  4182. }
  4183. /*****************************************************************************/
  4184. /*
  4185. * Return the port stats structure to user app. A NULL port struct
  4186. * pointer passed in means that we need to find out from the app
  4187. * what port to get stats for (used through board control device).
  4188. */
  4189. static int stli_portcmdstats(stliport_t *portp)
  4190. {
  4191. unsigned long flags;
  4192. stlibrd_t *brdp;
  4193. int rc;
  4194. memset(&stli_comstats, 0, sizeof(comstats_t));
  4195. if (portp == (stliport_t *) NULL)
  4196. return(-ENODEV);
  4197. brdp = stli_brds[portp->brdnr];
  4198. if (brdp == (stlibrd_t *) NULL)
  4199. return(-ENODEV);
  4200. if (brdp->state & BST_STARTED) {
  4201. if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
  4202. &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
  4203. return(rc);
  4204. } else {
  4205. memset(&stli_cdkstats, 0, sizeof(asystats_t));
  4206. }
  4207. stli_comstats.brd = portp->brdnr;
  4208. stli_comstats.panel = portp->panelnr;
  4209. stli_comstats.port = portp->portnr;
  4210. stli_comstats.state = portp->state;
  4211. stli_comstats.flags = portp->flags;
  4212. save_flags(flags);
  4213. cli();
  4214. if (portp->tty != (struct tty_struct *) NULL) {
  4215. if (portp->tty->driver_data == portp) {
  4216. stli_comstats.ttystate = portp->tty->flags;
  4217. stli_comstats.rxbuffered = portp->tty->flip.count;
  4218. if (portp->tty->termios != (struct termios *) NULL) {
  4219. stli_comstats.cflags = portp->tty->termios->c_cflag;
  4220. stli_comstats.iflags = portp->tty->termios->c_iflag;
  4221. stli_comstats.oflags = portp->tty->termios->c_oflag;
  4222. stli_comstats.lflags = portp->tty->termios->c_lflag;
  4223. }
  4224. }
  4225. }
  4226. restore_flags(flags);
  4227. stli_comstats.txtotal = stli_cdkstats.txchars;
  4228. stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
  4229. stli_comstats.txbuffered = stli_cdkstats.txringq;
  4230. stli_comstats.rxbuffered += stli_cdkstats.rxringq;
  4231. stli_comstats.rxoverrun = stli_cdkstats.overruns;
  4232. stli_comstats.rxparity = stli_cdkstats.parity;
  4233. stli_comstats.rxframing = stli_cdkstats.framing;
  4234. stli_comstats.rxlost = stli_cdkstats.ringover;
  4235. stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
  4236. stli_comstats.txbreaks = stli_cdkstats.txbreaks;
  4237. stli_comstats.txxon = stli_cdkstats.txstart;
  4238. stli_comstats.txxoff = stli_cdkstats.txstop;
  4239. stli_comstats.rxxon = stli_cdkstats.rxstart;
  4240. stli_comstats.rxxoff = stli_cdkstats.rxstop;
  4241. stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
  4242. stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
  4243. stli_comstats.modem = stli_cdkstats.dcdcnt;
  4244. stli_comstats.hwid = stli_cdkstats.hwid;
  4245. stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
  4246. return(0);
  4247. }
  4248. /*****************************************************************************/
  4249. /*
  4250. * Return the port stats structure to user app. A NULL port struct
  4251. * pointer passed in means that we need to find out from the app
  4252. * what port to get stats for (used through board control device).
  4253. */
  4254. static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
  4255. {
  4256. stlibrd_t *brdp;
  4257. int rc;
  4258. if (!portp) {
  4259. if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
  4260. return -EFAULT;
  4261. portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
  4262. stli_comstats.port);
  4263. if (!portp)
  4264. return -ENODEV;
  4265. }
  4266. brdp = stli_brds[portp->brdnr];
  4267. if (!brdp)
  4268. return -ENODEV;
  4269. if ((rc = stli_portcmdstats(portp)) < 0)
  4270. return rc;
  4271. return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
  4272. -EFAULT : 0;
  4273. }
  4274. /*****************************************************************************/
  4275. /*
  4276. * Clear the port stats structure. We also return it zeroed out...
  4277. */
  4278. static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
  4279. {
  4280. stlibrd_t *brdp;
  4281. int rc;
  4282. if (!portp) {
  4283. if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
  4284. return -EFAULT;
  4285. portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
  4286. stli_comstats.port);
  4287. if (!portp)
  4288. return -ENODEV;
  4289. }
  4290. brdp = stli_brds[portp->brdnr];
  4291. if (!brdp)
  4292. return -ENODEV;
  4293. if (brdp->state & BST_STARTED) {
  4294. if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0)
  4295. return rc;
  4296. }
  4297. memset(&stli_comstats, 0, sizeof(comstats_t));
  4298. stli_comstats.brd = portp->brdnr;
  4299. stli_comstats.panel = portp->panelnr;
  4300. stli_comstats.port = portp->portnr;
  4301. if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
  4302. return -EFAULT;
  4303. return 0;
  4304. }
  4305. /*****************************************************************************/
  4306. /*
  4307. * Return the entire driver ports structure to a user app.
  4308. */
  4309. static int stli_getportstruct(stliport_t __user *arg)
  4310. {
  4311. stliport_t *portp;
  4312. if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t)))
  4313. return -EFAULT;
  4314. portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
  4315. stli_dummyport.portnr);
  4316. if (!portp)
  4317. return -ENODEV;
  4318. if (copy_to_user(arg, portp, sizeof(stliport_t)))
  4319. return -EFAULT;
  4320. return 0;
  4321. }
  4322. /*****************************************************************************/
  4323. /*
  4324. * Return the entire driver board structure to a user app.
  4325. */
  4326. static int stli_getbrdstruct(stlibrd_t __user *arg)
  4327. {
  4328. stlibrd_t *brdp;
  4329. if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t)))
  4330. return -EFAULT;
  4331. if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS))
  4332. return -ENODEV;
  4333. brdp = stli_brds[stli_dummybrd.brdnr];
  4334. if (!brdp)
  4335. return -ENODEV;
  4336. if (copy_to_user(arg, brdp, sizeof(stlibrd_t)))
  4337. return -EFAULT;
  4338. return 0;
  4339. }
  4340. /*****************************************************************************/
  4341. /*
  4342. * The "staliomem" device is also required to do some special operations on
  4343. * the board. We need to be able to send an interrupt to the board,
  4344. * reset it, and start/stop it.
  4345. */
  4346. static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
  4347. {
  4348. stlibrd_t *brdp;
  4349. int brdnr, rc, done;
  4350. void __user *argp = (void __user *)arg;
  4351. #ifdef DEBUG
  4352. printk(KERN_DEBUG "stli_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n",
  4353. (int) ip, (int) fp, cmd, (int) arg);
  4354. #endif
  4355. /*
  4356. * First up handle the board independent ioctls.
  4357. */
  4358. done = 0;
  4359. rc = 0;
  4360. switch (cmd) {
  4361. case COM_GETPORTSTATS:
  4362. rc = stli_getportstats(NULL, argp);
  4363. done++;
  4364. break;
  4365. case COM_CLRPORTSTATS:
  4366. rc = stli_clrportstats(NULL, argp);
  4367. done++;
  4368. break;
  4369. case COM_GETBRDSTATS:
  4370. rc = stli_getbrdstats(argp);
  4371. done++;
  4372. break;
  4373. case COM_READPORT:
  4374. rc = stli_getportstruct(argp);
  4375. done++;
  4376. break;
  4377. case COM_READBOARD:
  4378. rc = stli_getbrdstruct(argp);
  4379. done++;
  4380. break;
  4381. }
  4382. if (done)
  4383. return(rc);
  4384. /*
  4385. * Now handle the board specific ioctls. These all depend on the
  4386. * minor number of the device they were called from.
  4387. */
  4388. brdnr = iminor(ip);
  4389. if (brdnr >= STL_MAXBRDS)
  4390. return(-ENODEV);
  4391. brdp = stli_brds[brdnr];
  4392. if (!brdp)
  4393. return(-ENODEV);
  4394. if (brdp->state == 0)
  4395. return(-ENODEV);
  4396. switch (cmd) {
  4397. case STL_BINTR:
  4398. EBRDINTR(brdp);
  4399. break;
  4400. case STL_BSTART:
  4401. rc = stli_startbrd(brdp);
  4402. break;
  4403. case STL_BSTOP:
  4404. brdp->state &= ~BST_STARTED;
  4405. break;
  4406. case STL_BRESET:
  4407. brdp->state &= ~BST_STARTED;
  4408. EBRDRESET(brdp);
  4409. if (stli_shared == 0) {
  4410. if (brdp->reenable != NULL)
  4411. (* brdp->reenable)(brdp);
  4412. }
  4413. break;
  4414. default:
  4415. rc = -ENOIOCTLCMD;
  4416. break;
  4417. }
  4418. return(rc);
  4419. }
  4420. static struct tty_operations stli_ops = {
  4421. .open = stli_open,
  4422. .close = stli_close,
  4423. .write = stli_write,
  4424. .put_char = stli_putchar,
  4425. .flush_chars = stli_flushchars,
  4426. .write_room = stli_writeroom,
  4427. .chars_in_buffer = stli_charsinbuffer,
  4428. .ioctl = stli_ioctl,
  4429. .set_termios = stli_settermios,
  4430. .throttle = stli_throttle,
  4431. .unthrottle = stli_unthrottle,
  4432. .stop = stli_stop,
  4433. .start = stli_start,
  4434. .hangup = stli_hangup,
  4435. .flush_buffer = stli_flushbuffer,
  4436. .break_ctl = stli_breakctl,
  4437. .wait_until_sent = stli_waituntilsent,
  4438. .send_xchar = stli_sendxchar,
  4439. .read_proc = stli_readproc,
  4440. .tiocmget = stli_tiocmget,
  4441. .tiocmset = stli_tiocmset,
  4442. };
  4443. /*****************************************************************************/
  4444. int __init stli_init(void)
  4445. {
  4446. int i;
  4447. printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
  4448. stli_initbrds();
  4449. stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
  4450. if (!stli_serial)
  4451. return -ENOMEM;
  4452. /*
  4453. * Allocate a temporary write buffer.
  4454. */
  4455. stli_tmpwritebuf = (char *) stli_memalloc(STLI_TXBUFSIZE);
  4456. if (stli_tmpwritebuf == (char *) NULL)
  4457. printk(KERN_ERR "STALLION: failed to allocate memory "
  4458. "(size=%d)\n", STLI_TXBUFSIZE);
  4459. stli_txcookbuf = stli_memalloc(STLI_TXBUFSIZE);
  4460. if (stli_txcookbuf == (char *) NULL)
  4461. printk(KERN_ERR "STALLION: failed to allocate memory "
  4462. "(size=%d)\n", STLI_TXBUFSIZE);
  4463. /*
  4464. * Set up a character driver for the shared memory region. We need this
  4465. * to down load the slave code image. Also it is a useful debugging tool.
  4466. */
  4467. if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
  4468. printk(KERN_ERR "STALLION: failed to register serial memory "
  4469. "device\n");
  4470. devfs_mk_dir("staliomem");
  4471. istallion_class = class_simple_create(THIS_MODULE, "staliomem");
  4472. for (i = 0; i < 4; i++) {
  4473. devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
  4474. S_IFCHR | S_IRUSR | S_IWUSR,
  4475. "staliomem/%d", i);
  4476. class_simple_device_add(istallion_class, MKDEV(STL_SIOMEMMAJOR, i),
  4477. NULL, "staliomem%d", i);
  4478. }
  4479. /*
  4480. * Set up the tty driver structure and register us as a driver.
  4481. */
  4482. stli_serial->owner = THIS_MODULE;
  4483. stli_serial->driver_name = stli_drvname;
  4484. stli_serial->name = stli_serialname;
  4485. stli_serial->major = STL_SERIALMAJOR;
  4486. stli_serial->minor_start = 0;
  4487. stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
  4488. stli_serial->subtype = SERIAL_TYPE_NORMAL;
  4489. stli_serial->init_termios = stli_deftermios;
  4490. stli_serial->flags = TTY_DRIVER_REAL_RAW;
  4491. tty_set_operations(stli_serial, &stli_ops);
  4492. if (tty_register_driver(stli_serial)) {
  4493. put_tty_driver(stli_serial);
  4494. printk(KERN_ERR "STALLION: failed to register serial driver\n");
  4495. return -EBUSY;
  4496. }
  4497. return(0);
  4498. }
  4499. /*****************************************************************************/