ip2main.c 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197
  1. /*
  2. *
  3. * (c) 1999 by Computone Corporation
  4. *
  5. ********************************************************************************
  6. *
  7. * PACKAGE: Linux tty Device Driver for IntelliPort family of multiport
  8. * serial I/O controllers.
  9. *
  10. * DESCRIPTION: Mainline code for the device driver
  11. *
  12. *******************************************************************************/
  13. // ToDo:
  14. //
  15. // Fix the immediate DSS_NOW problem.
  16. // Work over the channel stats return logic in ip2_ipl_ioctl so they
  17. // make sense for all 256 possible channels and so the user space
  18. // utilities will compile and work properly.
  19. //
  20. // Done:
  21. //
  22. // 1.2.14 /\/\|=mhw=|\/\/
  23. // Added bounds checking to ip2_ipl_ioctl to avoid potential terroristic acts.
  24. // Changed the definition of ip2trace to be more consistent with kernel style
  25. // Thanks to Andreas Dilger <adilger@turbolabs.com> for these updates
  26. //
  27. // 1.2.13 /\/\|=mhw=|\/\/
  28. // DEVFS: Renamed ttf/{n} to tts/F{n} and cuf/{n} to cua/F{n} to conform
  29. // to agreed devfs serial device naming convention.
  30. //
  31. // 1.2.12 /\/\|=mhw=|\/\/
  32. // Cleaned up some remove queue cut and paste errors
  33. //
  34. // 1.2.11 /\/\|=mhw=|\/\/
  35. // Clean up potential NULL pointer dereferences
  36. // Clean up devfs registration
  37. // Add kernel command line parsing for io and irq
  38. // Compile defaults for io and irq are now set in ip2.c not ip2.h!
  39. // Reworked poll_only hack for explicit parameter setting
  40. // You must now EXPLICITLY set poll_only = 1 or set all irqs to 0
  41. // Merged ip2_loadmain and old_ip2_init
  42. // Converted all instances of interruptible_sleep_on into queue calls
  43. // Most of these had no race conditions but better to clean up now
  44. //
  45. // 1.2.10 /\/\|=mhw=|\/\/
  46. // Fixed the bottom half interrupt handler and enabled USE_IQI
  47. // to split the interrupt handler into a formal top-half / bottom-half
  48. // Fixed timing window on high speed processors that queued messages to
  49. // the outbound mail fifo faster than the board could handle.
  50. //
  51. // 1.2.9
  52. // Four box EX was barfing on >128k kmalloc, made structure smaller by
  53. // reducing output buffer size
  54. //
  55. // 1.2.8
  56. // Device file system support (MHW)
  57. //
  58. // 1.2.7
  59. // Fixed
  60. // Reload of ip2 without unloading ip2main hangs system on cat of /proc/modules
  61. //
  62. // 1.2.6
  63. //Fixes DCD problems
  64. // DCD was not reported when CLOCAL was set on call to TIOCMGET
  65. //
  66. //Enhancements:
  67. // TIOCMGET requests and waits for status return
  68. // No DSS interrupts enabled except for DCD when needed
  69. //
  70. // For internal use only
  71. //
  72. //#define IP2DEBUG_INIT
  73. //#define IP2DEBUG_OPEN
  74. //#define IP2DEBUG_WRITE
  75. //#define IP2DEBUG_READ
  76. //#define IP2DEBUG_IOCTL
  77. //#define IP2DEBUG_IPL
  78. //#define IP2DEBUG_TRACE
  79. //#define DEBUG_FIFO
  80. /************/
  81. /* Includes */
  82. /************/
  83. #include <linux/ctype.h>
  84. #include <linux/string.h>
  85. #include <linux/fcntl.h>
  86. #include <linux/errno.h>
  87. #include <linux/module.h>
  88. #include <linux/signal.h>
  89. #include <linux/sched.h>
  90. #include <linux/timer.h>
  91. #include <linux/interrupt.h>
  92. #include <linux/pci.h>
  93. #include <linux/mm.h>
  94. #include <linux/slab.h>
  95. #include <linux/major.h>
  96. #include <linux/wait.h>
  97. #include <linux/device.h>
  98. #include <linux/tty.h>
  99. #include <linux/tty_flip.h>
  100. #include <linux/termios.h>
  101. #include <linux/tty_driver.h>
  102. #include <linux/serial.h>
  103. #include <linux/ptrace.h>
  104. #include <linux/ioport.h>
  105. #include <linux/cdk.h>
  106. #include <linux/comstats.h>
  107. #include <linux/delay.h>
  108. #include <linux/bitops.h>
  109. #include <asm/system.h>
  110. #include <asm/io.h>
  111. #include <asm/irq.h>
  112. #include <linux/vmalloc.h>
  113. #include <linux/init.h>
  114. #include <asm/uaccess.h>
  115. #include "ip2types.h"
  116. #include "ip2trace.h"
  117. #include "ip2ioctl.h"
  118. #include "ip2.h"
  119. #include "i2ellis.h"
  120. #include "i2lib.h"
  121. /*****************
  122. * /proc/ip2mem *
  123. *****************/
  124. #include <linux/proc_fs.h>
  125. static int ip2_read_procmem(char *, char **, off_t, int);
  126. static int ip2_read_proc(char *, char **, off_t, int, int *, void * );
  127. /********************/
  128. /* Type Definitions */
  129. /********************/
  130. /*************/
  131. /* Constants */
  132. /*************/
  133. /* String constants to identify ourselves */
  134. static char *pcName = "Computone IntelliPort Plus multiport driver";
  135. static char *pcVersion = "1.2.14";
  136. /* String constants for port names */
  137. static char *pcDriver_name = "ip2";
  138. static char *pcIpl = "ip2ipl";
  139. /* Serial subtype definitions */
  140. #define SERIAL_TYPE_NORMAL 1
  141. // cheezy kludge or genius - you decide?
  142. int ip2_loadmain(int *, int *, unsigned char *, int);
  143. static unsigned char *Fip_firmware;
  144. static int Fip_firmware_size;
  145. /***********************/
  146. /* Function Prototypes */
  147. /***********************/
  148. /* Global module entry functions */
  149. /* Private (static) functions */
  150. static int ip2_open(PTTY, struct file *);
  151. static void ip2_close(PTTY, struct file *);
  152. static int ip2_write(PTTY, const unsigned char *, int);
  153. static void ip2_putchar(PTTY, unsigned char);
  154. static void ip2_flush_chars(PTTY);
  155. static int ip2_write_room(PTTY);
  156. static int ip2_chars_in_buf(PTTY);
  157. static void ip2_flush_buffer(PTTY);
  158. static int ip2_ioctl(PTTY, struct file *, UINT, ULONG);
  159. static void ip2_set_termios(PTTY, struct ktermios *);
  160. static void ip2_set_line_discipline(PTTY);
  161. static void ip2_throttle(PTTY);
  162. static void ip2_unthrottle(PTTY);
  163. static void ip2_stop(PTTY);
  164. static void ip2_start(PTTY);
  165. static void ip2_hangup(PTTY);
  166. static int ip2_tiocmget(struct tty_struct *tty, struct file *file);
  167. static int ip2_tiocmset(struct tty_struct *tty, struct file *file,
  168. unsigned int set, unsigned int clear);
  169. static void set_irq(int, int);
  170. static void ip2_interrupt_bh(struct work_struct *work);
  171. static irqreturn_t ip2_interrupt(int irq, void *dev_id);
  172. static void ip2_poll(unsigned long arg);
  173. static inline void service_all_boards(void);
  174. static void do_input(struct work_struct *);
  175. static void do_status(struct work_struct *);
  176. static void ip2_wait_until_sent(PTTY,int);
  177. static void set_params (i2ChanStrPtr, struct ktermios *);
  178. static int get_serial_info(i2ChanStrPtr, struct serial_struct __user *);
  179. static int set_serial_info(i2ChanStrPtr, struct serial_struct __user *);
  180. static ssize_t ip2_ipl_read(struct file *, char __user *, size_t, loff_t *);
  181. static ssize_t ip2_ipl_write(struct file *, const char __user *, size_t, loff_t *);
  182. static int ip2_ipl_ioctl(struct inode *, struct file *, UINT, ULONG);
  183. static int ip2_ipl_open(struct inode *, struct file *);
  184. static int DumpTraceBuffer(char __user *, int);
  185. static int DumpFifoBuffer( char __user *, int);
  186. static void ip2_init_board(int);
  187. static unsigned short find_eisa_board(int);
  188. /***************/
  189. /* Static Data */
  190. /***************/
  191. static struct tty_driver *ip2_tty_driver;
  192. /* Here, then is a table of board pointers which the interrupt routine should
  193. * scan through to determine who it must service.
  194. */
  195. static unsigned short i2nBoards; // Number of boards here
  196. static i2eBordStrPtr i2BoardPtrTable[IP2_MAX_BOARDS];
  197. static i2ChanStrPtr DevTable[IP2_MAX_PORTS];
  198. //DevTableMem just used to save addresses for kfree
  199. static void *DevTableMem[IP2_MAX_BOARDS];
  200. /* This is the driver descriptor for the ip2ipl device, which is used to
  201. * download the loadware to the boards.
  202. */
  203. static const struct file_operations ip2_ipl = {
  204. .owner = THIS_MODULE,
  205. .read = ip2_ipl_read,
  206. .write = ip2_ipl_write,
  207. .ioctl = ip2_ipl_ioctl,
  208. .open = ip2_ipl_open,
  209. };
  210. static unsigned long irq_counter = 0;
  211. static unsigned long bh_counter = 0;
  212. // Use immediate queue to service interrupts
  213. #define USE_IQI
  214. //#define USE_IQ // PCI&2.2 needs work
  215. /* The timer_list entry for our poll routine. If interrupt operation is not
  216. * selected, the board is serviced periodically to see if anything needs doing.
  217. */
  218. #define POLL_TIMEOUT (jiffies + 1)
  219. static DEFINE_TIMER(PollTimer, ip2_poll, 0, 0);
  220. static char TimerOn;
  221. #ifdef IP2DEBUG_TRACE
  222. /* Trace (debug) buffer data */
  223. #define TRACEMAX 1000
  224. static unsigned long tracebuf[TRACEMAX];
  225. static int tracestuff;
  226. static int tracestrip;
  227. static int tracewrap;
  228. #endif
  229. /**********/
  230. /* Macros */
  231. /**********/
  232. #if defined(MODULE) && defined(IP2DEBUG_OPEN)
  233. #define DBG_CNT(s) printk(KERN_DEBUG "(%s): [%x] refc=%d, ttyc=%d, modc=%x -> %s\n", \
  234. tty->name,(pCh->flags),ip2_tty_driver->refcount, \
  235. tty->count,/*GET_USE_COUNT(module)*/0,s)
  236. #else
  237. #define DBG_CNT(s)
  238. #endif
  239. /********/
  240. /* Code */
  241. /********/
  242. #include "i2ellis.c" /* Extremely low-level interface services */
  243. #include "i2cmd.c" /* Standard loadware command definitions */
  244. #include "i2lib.c" /* High level interface services */
  245. /* Configuration area for modprobe */
  246. MODULE_AUTHOR("Doug McNash");
  247. MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
  248. static int poll_only = 0;
  249. static int Eisa_irq;
  250. static int Eisa_slot;
  251. static int iindx;
  252. static char rirqs[IP2_MAX_BOARDS];
  253. static int Valid_Irqs[] = { 3, 4, 5, 7, 10, 11, 12, 15, 0};
  254. /* for sysfs class support */
  255. static struct class *ip2_class;
  256. // Some functions to keep track of what irq's we have
  257. static int
  258. is_valid_irq(int irq)
  259. {
  260. int *i = Valid_Irqs;
  261. while ((*i != 0) && (*i != irq)) {
  262. i++;
  263. }
  264. return (*i);
  265. }
  266. static void
  267. mark_requested_irq( char irq )
  268. {
  269. rirqs[iindx++] = irq;
  270. }
  271. #ifdef MODULE
  272. static int
  273. clear_requested_irq( char irq )
  274. {
  275. int i;
  276. for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  277. if (rirqs[i] == irq) {
  278. rirqs[i] = 0;
  279. return 1;
  280. }
  281. }
  282. return 0;
  283. }
  284. #endif
  285. static int
  286. have_requested_irq( char irq )
  287. {
  288. // array init to zeros so 0 irq will not be requested as a side effect
  289. int i;
  290. for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  291. if (rirqs[i] == irq)
  292. return 1;
  293. }
  294. return 0;
  295. }
  296. /******************************************************************************/
  297. /* Function: init_module() */
  298. /* Parameters: None */
  299. /* Returns: Success (0) */
  300. /* */
  301. /* Description: */
  302. /* This is a required entry point for an installable module. It simply calls */
  303. /* the driver initialisation function and returns what it returns. */
  304. /******************************************************************************/
  305. #ifdef MODULE
  306. int
  307. init_module(void)
  308. {
  309. #ifdef IP2DEBUG_INIT
  310. printk (KERN_DEBUG "Loading module ...\n" );
  311. #endif
  312. return 0;
  313. }
  314. #endif /* MODULE */
  315. /******************************************************************************/
  316. /* Function: cleanup_module() */
  317. /* Parameters: None */
  318. /* Returns: Nothing */
  319. /* */
  320. /* Description: */
  321. /* This is a required entry point for an installable module. It has to return */
  322. /* the device and the driver to a passive state. It should not be necessary */
  323. /* to reset the board fully, especially as the loadware is downloaded */
  324. /* externally rather than in the driver. We just want to disable the board */
  325. /* and clear the loadware to a reset state. To allow this there has to be a */
  326. /* way to detect whether the board has the loadware running at init time to */
  327. /* handle subsequent installations of the driver. All memory allocated by the */
  328. /* driver should be returned since it may be unloaded from memory. */
  329. /******************************************************************************/
  330. #ifdef MODULE
  331. void
  332. cleanup_module(void)
  333. {
  334. int err;
  335. int i;
  336. #ifdef IP2DEBUG_INIT
  337. printk (KERN_DEBUG "Unloading %s: version %s\n", pcName, pcVersion );
  338. #endif
  339. /* Stop poll timer if we had one. */
  340. if ( TimerOn ) {
  341. del_timer ( &PollTimer );
  342. TimerOn = 0;
  343. }
  344. /* Reset the boards we have. */
  345. for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  346. if ( i2BoardPtrTable[i] ) {
  347. iiReset( i2BoardPtrTable[i] );
  348. }
  349. }
  350. /* The following is done at most once, if any boards were installed. */
  351. for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  352. if ( i2BoardPtrTable[i] ) {
  353. iiResetDelay( i2BoardPtrTable[i] );
  354. /* free io addresses and Tibet */
  355. release_region( ip2config.addr[i], 8 );
  356. class_device_destroy(ip2_class, MKDEV(IP2_IPL_MAJOR, 4 * i));
  357. class_device_destroy(ip2_class, MKDEV(IP2_IPL_MAJOR, 4 * i + 1));
  358. }
  359. /* Disable and remove interrupt handler. */
  360. if ( (ip2config.irq[i] > 0) && have_requested_irq(ip2config.irq[i]) ) {
  361. free_irq ( ip2config.irq[i], (void *)&pcName);
  362. clear_requested_irq( ip2config.irq[i]);
  363. }
  364. }
  365. class_destroy(ip2_class);
  366. if ( ( err = tty_unregister_driver ( ip2_tty_driver ) ) ) {
  367. printk(KERN_ERR "IP2: failed to unregister tty driver (%d)\n", err);
  368. }
  369. put_tty_driver(ip2_tty_driver);
  370. if ( ( err = unregister_chrdev ( IP2_IPL_MAJOR, pcIpl ) ) ) {
  371. printk(KERN_ERR "IP2: failed to unregister IPL driver (%d)\n", err);
  372. }
  373. remove_proc_entry("ip2mem", &proc_root);
  374. // free memory
  375. for (i = 0; i < IP2_MAX_BOARDS; i++) {
  376. void *pB;
  377. #ifdef CONFIG_PCI
  378. if (ip2config.type[i] == PCI && ip2config.pci_dev[i]) {
  379. pci_disable_device(ip2config.pci_dev[i]);
  380. pci_dev_put(ip2config.pci_dev[i]);
  381. ip2config.pci_dev[i] = NULL;
  382. }
  383. #endif
  384. if ((pB = i2BoardPtrTable[i]) != 0 ) {
  385. kfree ( pB );
  386. i2BoardPtrTable[i] = NULL;
  387. }
  388. if ((DevTableMem[i]) != NULL ) {
  389. kfree ( DevTableMem[i] );
  390. DevTableMem[i] = NULL;
  391. }
  392. }
  393. /* Cleanup the iiEllis subsystem. */
  394. iiEllisCleanup();
  395. #ifdef IP2DEBUG_INIT
  396. printk (KERN_DEBUG "IP2 Unloaded\n" );
  397. #endif
  398. }
  399. #endif /* MODULE */
  400. static const struct tty_operations ip2_ops = {
  401. .open = ip2_open,
  402. .close = ip2_close,
  403. .write = ip2_write,
  404. .put_char = ip2_putchar,
  405. .flush_chars = ip2_flush_chars,
  406. .write_room = ip2_write_room,
  407. .chars_in_buffer = ip2_chars_in_buf,
  408. .flush_buffer = ip2_flush_buffer,
  409. .ioctl = ip2_ioctl,
  410. .throttle = ip2_throttle,
  411. .unthrottle = ip2_unthrottle,
  412. .set_termios = ip2_set_termios,
  413. .set_ldisc = ip2_set_line_discipline,
  414. .stop = ip2_stop,
  415. .start = ip2_start,
  416. .hangup = ip2_hangup,
  417. .read_proc = ip2_read_proc,
  418. .tiocmget = ip2_tiocmget,
  419. .tiocmset = ip2_tiocmset,
  420. };
  421. /******************************************************************************/
  422. /* Function: ip2_loadmain() */
  423. /* Parameters: irq, io from command line of insmod et. al. */
  424. /* pointer to fip firmware and firmware size for boards */
  425. /* Returns: Success (0) */
  426. /* */
  427. /* Description: */
  428. /* This was the required entry point for all drivers (now in ip2.c) */
  429. /* It performs all */
  430. /* initialisation of the devices and driver structures, and registers itself */
  431. /* with the relevant kernel modules. */
  432. /******************************************************************************/
  433. /* IRQF_DISABLED - if set blocks all interrupts else only this line */
  434. /* IRQF_SHARED - for shared irq PCI or maybe EISA only */
  435. /* SA_RANDOM - can be source for cert. random number generators */
  436. #define IP2_SA_FLAGS 0
  437. int
  438. ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
  439. {
  440. int i, j, box;
  441. int err = 0;
  442. int status = 0;
  443. static int loaded;
  444. i2eBordStrPtr pB = NULL;
  445. int rc = -1;
  446. static struct pci_dev *pci_dev_i = NULL;
  447. ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0 );
  448. /* process command line arguments to modprobe or
  449. insmod i.e. iop & irqp */
  450. /* irqp and iop should ALWAYS be specified now... But we check
  451. them individually just to be sure, anyways... */
  452. for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  453. if (iop) {
  454. ip2config.addr[i] = iop[i];
  455. if (irqp) {
  456. if( irqp[i] >= 0 ) {
  457. ip2config.irq[i] = irqp[i];
  458. } else {
  459. ip2config.irq[i] = 0;
  460. }
  461. // This is a little bit of a hack. If poll_only=1 on command
  462. // line back in ip2.c OR all IRQs on all specified boards are
  463. // explicitly set to 0, then drop to poll only mode and override
  464. // PCI or EISA interrupts. This superceeds the old hack of
  465. // triggering if all interrupts were zero (like da default).
  466. // Still a hack but less prone to random acts of terrorism.
  467. //
  468. // What we really should do, now that the IRQ default is set
  469. // to -1, is to use 0 as a hard coded, do not probe.
  470. //
  471. // /\/\|=mhw=|\/\/
  472. poll_only |= irqp[i];
  473. }
  474. }
  475. }
  476. poll_only = !poll_only;
  477. Fip_firmware = firmware;
  478. Fip_firmware_size = firmsize;
  479. /* Announce our presence */
  480. printk( KERN_INFO "%s version %s\n", pcName, pcVersion );
  481. // ip2 can be unloaded and reloaded for no good reason
  482. // we can't let that happen here or bad things happen
  483. // second load hoses board but not system - fixme later
  484. if (loaded) {
  485. printk( KERN_INFO "Still loaded\n" );
  486. return 0;
  487. }
  488. loaded++;
  489. ip2_tty_driver = alloc_tty_driver(IP2_MAX_PORTS);
  490. if (!ip2_tty_driver)
  491. return -ENOMEM;
  492. /* Initialise the iiEllis subsystem. */
  493. iiEllisInit();
  494. /* Initialize arrays. */
  495. memset( i2BoardPtrTable, 0, sizeof i2BoardPtrTable );
  496. memset( DevTable, 0, sizeof DevTable );
  497. /* Initialise all the boards we can find (up to the maximum). */
  498. for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  499. switch ( ip2config.addr[i] ) {
  500. case 0: /* skip this slot even if card is present */
  501. break;
  502. default: /* ISA */
  503. /* ISA address must be specified */
  504. if ( (ip2config.addr[i] < 0x100) || (ip2config.addr[i] > 0x3f8) ) {
  505. printk ( KERN_ERR "IP2: Bad ISA board %d address %x\n",
  506. i, ip2config.addr[i] );
  507. ip2config.addr[i] = 0;
  508. } else {
  509. ip2config.type[i] = ISA;
  510. /* Check for valid irq argument, set for polling if invalid */
  511. if (ip2config.irq[i] && !is_valid_irq(ip2config.irq[i])) {
  512. printk(KERN_ERR "IP2: Bad IRQ(%d) specified\n",ip2config.irq[i]);
  513. ip2config.irq[i] = 0;// 0 is polling and is valid in that sense
  514. }
  515. }
  516. break;
  517. case PCI:
  518. #ifdef CONFIG_PCI
  519. {
  520. pci_dev_i = pci_get_device(PCI_VENDOR_ID_COMPUTONE,
  521. PCI_DEVICE_ID_COMPUTONE_IP2EX, pci_dev_i);
  522. if (pci_dev_i != NULL) {
  523. unsigned int addr;
  524. if (pci_enable_device(pci_dev_i)) {
  525. printk( KERN_ERR "IP2: can't enable PCI device at %s\n",
  526. pci_name(pci_dev_i));
  527. break;
  528. }
  529. ip2config.type[i] = PCI;
  530. ip2config.pci_dev[i] = pci_dev_get(pci_dev_i);
  531. status =
  532. pci_read_config_dword(pci_dev_i, PCI_BASE_ADDRESS_1, &addr);
  533. if ( addr & 1 ) {
  534. ip2config.addr[i]=(USHORT)(addr&0xfffe);
  535. } else {
  536. printk( KERN_ERR "IP2: PCI I/O address error\n");
  537. }
  538. // If the PCI BIOS assigned it, lets try and use it. If we
  539. // can't acquire it or it screws up, deal with it then.
  540. // if (!is_valid_irq(pci_irq)) {
  541. // printk( KERN_ERR "IP2: Bad PCI BIOS IRQ(%d)\n",pci_irq);
  542. // pci_irq = 0;
  543. // }
  544. ip2config.irq[i] = pci_dev_i->irq;
  545. } else { // ann error
  546. ip2config.addr[i] = 0;
  547. if (status == PCIBIOS_DEVICE_NOT_FOUND) {
  548. printk( KERN_ERR "IP2: PCI board %d not found\n", i );
  549. } else {
  550. printk( KERN_ERR "IP2: PCI error 0x%x \n", status );
  551. }
  552. }
  553. }
  554. #else
  555. printk( KERN_ERR "IP2: PCI card specified but PCI support not\n");
  556. printk( KERN_ERR "IP2: configured in this kernel.\n");
  557. printk( KERN_ERR "IP2: Recompile kernel with CONFIG_PCI defined!\n");
  558. #endif /* CONFIG_PCI */
  559. break;
  560. case EISA:
  561. if ( (ip2config.addr[i] = find_eisa_board( Eisa_slot + 1 )) != 0) {
  562. /* Eisa_irq set as side effect, boo */
  563. ip2config.type[i] = EISA;
  564. }
  565. ip2config.irq[i] = Eisa_irq;
  566. break;
  567. } /* switch */
  568. } /* for */
  569. if (pci_dev_i)
  570. pci_dev_put(pci_dev_i);
  571. for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  572. if ( ip2config.addr[i] ) {
  573. pB = kmalloc( sizeof(i2eBordStr), GFP_KERNEL);
  574. if ( pB != NULL ) {
  575. i2BoardPtrTable[i] = pB;
  576. memset( pB, 0, sizeof(i2eBordStr) );
  577. iiSetAddress( pB, ip2config.addr[i], ii2DelayTimer );
  578. iiReset( pB );
  579. } else {
  580. printk(KERN_ERR "IP2: board memory allocation error\n");
  581. }
  582. }
  583. }
  584. for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  585. if ( ( pB = i2BoardPtrTable[i] ) != NULL ) {
  586. iiResetDelay( pB );
  587. break;
  588. }
  589. }
  590. for ( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  591. if ( i2BoardPtrTable[i] != NULL ) {
  592. ip2_init_board( i );
  593. }
  594. }
  595. ip2trace (ITRC_NO_PORT, ITRC_INIT, 2, 0 );
  596. ip2_tty_driver->owner = THIS_MODULE;
  597. ip2_tty_driver->name = "ttyF";
  598. ip2_tty_driver->driver_name = pcDriver_name;
  599. ip2_tty_driver->major = IP2_TTY_MAJOR;
  600. ip2_tty_driver->minor_start = 0;
  601. ip2_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
  602. ip2_tty_driver->subtype = SERIAL_TYPE_NORMAL;
  603. ip2_tty_driver->init_termios = tty_std_termios;
  604. ip2_tty_driver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
  605. ip2_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
  606. tty_set_operations(ip2_tty_driver, &ip2_ops);
  607. ip2trace (ITRC_NO_PORT, ITRC_INIT, 3, 0 );
  608. /* Register the tty devices. */
  609. if ( ( err = tty_register_driver ( ip2_tty_driver ) ) ) {
  610. printk(KERN_ERR "IP2: failed to register tty driver (%d)\n", err);
  611. put_tty_driver(ip2_tty_driver);
  612. return -EINVAL;
  613. } else
  614. /* Register the IPL driver. */
  615. if ( ( err = register_chrdev ( IP2_IPL_MAJOR, pcIpl, &ip2_ipl ) ) ) {
  616. printk(KERN_ERR "IP2: failed to register IPL device (%d)\n", err );
  617. } else {
  618. /* create the sysfs class */
  619. ip2_class = class_create(THIS_MODULE, "ip2");
  620. if (IS_ERR(ip2_class)) {
  621. err = PTR_ERR(ip2_class);
  622. goto out_chrdev;
  623. }
  624. }
  625. /* Register the read_procmem thing */
  626. if (!create_proc_info_entry("ip2mem",0,&proc_root,ip2_read_procmem)) {
  627. printk(KERN_ERR "IP2: failed to register read_procmem\n");
  628. } else {
  629. ip2trace (ITRC_NO_PORT, ITRC_INIT, 4, 0 );
  630. /* Register the interrupt handler or poll handler, depending upon the
  631. * specified interrupt.
  632. */
  633. for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  634. if ( 0 == ip2config.addr[i] ) {
  635. continue;
  636. }
  637. if ( NULL != ( pB = i2BoardPtrTable[i] ) ) {
  638. class_device_create(ip2_class, NULL,
  639. MKDEV(IP2_IPL_MAJOR, 4 * i),
  640. NULL, "ipl%d", i);
  641. class_device_create(ip2_class, NULL,
  642. MKDEV(IP2_IPL_MAJOR, 4 * i + 1),
  643. NULL, "stat%d", i);
  644. for ( box = 0; box < ABS_MAX_BOXES; ++box )
  645. {
  646. for ( j = 0; j < ABS_BIGGEST_BOX; ++j )
  647. {
  648. if ( pB->i2eChannelMap[box] & (1 << j) )
  649. {
  650. tty_register_device(ip2_tty_driver,
  651. j + ABS_BIGGEST_BOX *
  652. (box+i*ABS_MAX_BOXES), NULL);
  653. }
  654. }
  655. }
  656. }
  657. if (poll_only) {
  658. // Poll only forces driver to only use polling and
  659. // to ignore the probed PCI or EISA interrupts.
  660. ip2config.irq[i] = CIR_POLL;
  661. }
  662. if ( ip2config.irq[i] == CIR_POLL ) {
  663. retry:
  664. if (!TimerOn) {
  665. PollTimer.expires = POLL_TIMEOUT;
  666. add_timer ( &PollTimer );
  667. TimerOn = 1;
  668. printk( KERN_INFO "IP2: polling\n");
  669. }
  670. } else {
  671. if (have_requested_irq(ip2config.irq[i]))
  672. continue;
  673. rc = request_irq( ip2config.irq[i], ip2_interrupt,
  674. IP2_SA_FLAGS | (ip2config.type[i] == PCI ? IRQF_SHARED : 0),
  675. pcName, (void *)&pcName);
  676. if (rc) {
  677. printk(KERN_ERR "IP2: an request_irq failed: error %d\n",rc);
  678. ip2config.irq[i] = CIR_POLL;
  679. printk( KERN_INFO "IP2: Polling %ld/sec.\n",
  680. (POLL_TIMEOUT - jiffies));
  681. goto retry;
  682. }
  683. mark_requested_irq(ip2config.irq[i]);
  684. /* Initialise the interrupt handler bottom half (aka slih). */
  685. }
  686. }
  687. for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  688. if ( i2BoardPtrTable[i] ) {
  689. set_irq( i, ip2config.irq[i] ); /* set and enable board interrupt */
  690. }
  691. }
  692. }
  693. ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_RETURN, 0 );
  694. goto out;
  695. out_chrdev:
  696. unregister_chrdev(IP2_IPL_MAJOR, "ip2");
  697. out:
  698. return err;
  699. }
  700. EXPORT_SYMBOL(ip2_loadmain);
  701. /******************************************************************************/
  702. /* Function: ip2_init_board() */
  703. /* Parameters: Index of board in configuration structure */
  704. /* Returns: Success (0) */
  705. /* */
  706. /* Description: */
  707. /* This function initializes the specified board. The loadware is copied to */
  708. /* the board, the channel structures are initialized, and the board details */
  709. /* are reported on the console. */
  710. /******************************************************************************/
  711. static void
  712. ip2_init_board( int boardnum )
  713. {
  714. int i;
  715. int nports = 0, nboxes = 0;
  716. i2ChanStrPtr pCh;
  717. i2eBordStrPtr pB = i2BoardPtrTable[boardnum];
  718. if ( !iiInitialize ( pB ) ) {
  719. printk ( KERN_ERR "IP2: Failed to initialize board at 0x%x, error %d\n",
  720. pB->i2eBase, pB->i2eError );
  721. goto err_initialize;
  722. }
  723. printk(KERN_INFO "IP2: Board %d: addr=0x%x irq=%d\n", boardnum + 1,
  724. ip2config.addr[boardnum], ip2config.irq[boardnum] );
  725. if (!request_region( ip2config.addr[boardnum], 8, pcName )) {
  726. printk(KERN_ERR "IP2: bad addr=0x%x\n", ip2config.addr[boardnum]);
  727. goto err_initialize;
  728. }
  729. if ( iiDownloadAll ( pB, (loadHdrStrPtr)Fip_firmware, 1, Fip_firmware_size )
  730. != II_DOWN_GOOD ) {
  731. printk ( KERN_ERR "IP2: failed to download loadware\n" );
  732. goto err_release_region;
  733. } else {
  734. printk ( KERN_INFO "IP2: fv=%d.%d.%d lv=%d.%d.%d\n",
  735. pB->i2ePom.e.porVersion,
  736. pB->i2ePom.e.porRevision,
  737. pB->i2ePom.e.porSubRev, pB->i2eLVersion,
  738. pB->i2eLRevision, pB->i2eLSub );
  739. }
  740. switch ( pB->i2ePom.e.porID & ~POR_ID_RESERVED ) {
  741. default:
  742. printk( KERN_ERR "IP2: Unknown board type, ID = %x\n",
  743. pB->i2ePom.e.porID );
  744. nports = 0;
  745. goto err_release_region;
  746. break;
  747. case POR_ID_II_4: /* IntelliPort-II, ISA-4 (4xRJ45) */
  748. printk ( KERN_INFO "IP2: ISA-4\n" );
  749. nports = 4;
  750. break;
  751. case POR_ID_II_8: /* IntelliPort-II, 8-port using standard brick. */
  752. printk ( KERN_INFO "IP2: ISA-8 std\n" );
  753. nports = 8;
  754. break;
  755. case POR_ID_II_8R: /* IntelliPort-II, 8-port using RJ11's (no CTS) */
  756. printk ( KERN_INFO "IP2: ISA-8 RJ11\n" );
  757. nports = 8;
  758. break;
  759. case POR_ID_FIIEX: /* IntelliPort IIEX */
  760. {
  761. int portnum = IP2_PORTS_PER_BOARD * boardnum;
  762. int box;
  763. for( box = 0; box < ABS_MAX_BOXES; ++box ) {
  764. if ( pB->i2eChannelMap[box] != 0 ) {
  765. ++nboxes;
  766. }
  767. for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {
  768. if ( pB->i2eChannelMap[box] & 1<< i ) {
  769. ++nports;
  770. }
  771. }
  772. }
  773. DevTableMem[boardnum] = pCh =
  774. kmalloc( sizeof(i2ChanStr) * nports, GFP_KERNEL );
  775. if ( !pCh ) {
  776. printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");
  777. goto err_release_region;
  778. }
  779. if ( !i2InitChannels( pB, nports, pCh ) ) {
  780. printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);
  781. kfree ( pCh );
  782. goto err_release_region;
  783. }
  784. pB->i2eChannelPtr = &DevTable[portnum];
  785. pB->i2eChannelCnt = ABS_MOST_PORTS;
  786. for( box = 0; box < ABS_MAX_BOXES; ++box, portnum += ABS_BIGGEST_BOX ) {
  787. for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {
  788. if ( pB->i2eChannelMap[box] & (1 << i) ) {
  789. DevTable[portnum + i] = pCh;
  790. pCh->port_index = portnum + i;
  791. pCh++;
  792. }
  793. }
  794. }
  795. printk(KERN_INFO "IP2: EX box=%d ports=%d %d bit\n",
  796. nboxes, nports, pB->i2eDataWidth16 ? 16 : 8 );
  797. }
  798. goto ex_exit;
  799. }
  800. DevTableMem[boardnum] = pCh =
  801. kmalloc ( sizeof (i2ChanStr) * nports, GFP_KERNEL );
  802. if ( !pCh ) {
  803. printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");
  804. goto err_release_region;
  805. }
  806. pB->i2eChannelPtr = pCh;
  807. pB->i2eChannelCnt = nports;
  808. if ( !i2InitChannels( pB, nports, pCh ) ) {
  809. printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);
  810. kfree ( pCh );
  811. goto err_release_region;
  812. }
  813. pB->i2eChannelPtr = &DevTable[IP2_PORTS_PER_BOARD * boardnum];
  814. for( i = 0; i < pB->i2eChannelCnt; ++i ) {
  815. DevTable[IP2_PORTS_PER_BOARD * boardnum + i] = pCh;
  816. pCh->port_index = (IP2_PORTS_PER_BOARD * boardnum) + i;
  817. pCh++;
  818. }
  819. ex_exit:
  820. INIT_WORK(&pB->tqueue_interrupt, ip2_interrupt_bh);
  821. return;
  822. err_release_region:
  823. release_region(ip2config.addr[boardnum], 8);
  824. err_initialize:
  825. kfree ( pB );
  826. i2BoardPtrTable[boardnum] = NULL;
  827. return;
  828. }
  829. /******************************************************************************/
  830. /* Function: find_eisa_board ( int start_slot ) */
  831. /* Parameters: First slot to check */
  832. /* Returns: Address of EISA IntelliPort II controller */
  833. /* */
  834. /* Description: */
  835. /* This function searches for an EISA IntelliPort controller, starting */
  836. /* from the specified slot number. If the motherboard is not identified as an */
  837. /* EISA motherboard, or no valid board ID is selected it returns 0. Otherwise */
  838. /* it returns the base address of the controller. */
  839. /******************************************************************************/
  840. static unsigned short
  841. find_eisa_board( int start_slot )
  842. {
  843. int i, j;
  844. unsigned int idm = 0;
  845. unsigned int idp = 0;
  846. unsigned int base = 0;
  847. unsigned int value;
  848. int setup_address;
  849. int setup_irq;
  850. int ismine = 0;
  851. /*
  852. * First a check for an EISA motherboard, which we do by comparing the
  853. * EISA ID registers for the system board and the first couple of slots.
  854. * No slot ID should match the system board ID, but on an ISA or PCI
  855. * machine the odds are that an empty bus will return similar values for
  856. * each slot.
  857. */
  858. i = 0x0c80;
  859. value = (inb(i) << 24) + (inb(i+1) << 16) + (inb(i+2) << 8) + inb(i+3);
  860. for( i = 0x1c80; i <= 0x4c80; i += 0x1000 ) {
  861. j = (inb(i)<<24)+(inb(i+1)<<16)+(inb(i+2)<<8)+inb(i+3);
  862. if ( value == j )
  863. return 0;
  864. }
  865. /*
  866. * OK, so we are inclined to believe that this is an EISA machine. Find
  867. * an IntelliPort controller.
  868. */
  869. for( i = start_slot; i < 16; i++ ) {
  870. base = i << 12;
  871. idm = (inb(base + 0xc80) << 8) | (inb(base + 0xc81) & 0xff);
  872. idp = (inb(base + 0xc82) << 8) | (inb(base + 0xc83) & 0xff);
  873. ismine = 0;
  874. if ( idm == 0x0e8e ) {
  875. if ( idp == 0x0281 || idp == 0x0218 ) {
  876. ismine = 1;
  877. } else if ( idp == 0x0282 || idp == 0x0283 ) {
  878. ismine = 3; /* Can do edge-trigger */
  879. }
  880. if ( ismine ) {
  881. Eisa_slot = i;
  882. break;
  883. }
  884. }
  885. }
  886. if ( !ismine )
  887. return 0;
  888. /* It's some sort of EISA card, but at what address is it configured? */
  889. setup_address = base + 0xc88;
  890. value = inb(base + 0xc86);
  891. setup_irq = (value & 8) ? Valid_Irqs[value & 7] : 0;
  892. if ( (ismine & 2) && !(value & 0x10) ) {
  893. ismine = 1; /* Could be edging, but not */
  894. }
  895. if ( Eisa_irq == 0 ) {
  896. Eisa_irq = setup_irq;
  897. } else if ( Eisa_irq != setup_irq ) {
  898. printk ( KERN_ERR "IP2: EISA irq mismatch between EISA controllers\n" );
  899. }
  900. #ifdef IP2DEBUG_INIT
  901. printk(KERN_DEBUG "Computone EISA board in slot %d, I.D. 0x%x%x, Address 0x%x",
  902. base >> 12, idm, idp, setup_address);
  903. if ( Eisa_irq ) {
  904. printk(KERN_DEBUG ", Interrupt %d %s\n",
  905. setup_irq, (ismine & 2) ? "(edge)" : "(level)");
  906. } else {
  907. printk(KERN_DEBUG ", (polled)\n");
  908. }
  909. #endif
  910. return setup_address;
  911. }
  912. /******************************************************************************/
  913. /* Function: set_irq() */
  914. /* Parameters: index to board in board table */
  915. /* IRQ to use */
  916. /* Returns: Success (0) */
  917. /* */
  918. /* Description: */
  919. /******************************************************************************/
  920. static void
  921. set_irq( int boardnum, int boardIrq )
  922. {
  923. unsigned char tempCommand[16];
  924. i2eBordStrPtr pB = i2BoardPtrTable[boardnum];
  925. unsigned long flags;
  926. /*
  927. * Notify the boards they may generate interrupts. This is done by
  928. * sending an in-line command to channel 0 on each board. This is why
  929. * the channels have to be defined already. For each board, if the
  930. * interrupt has never been defined, we must do so NOW, directly, since
  931. * board will not send flow control or even give an interrupt until this
  932. * is done. If polling we must send 0 as the interrupt parameter.
  933. */
  934. // We will get an interrupt here at the end of this function
  935. iiDisableMailIrq(pB);
  936. /* We build up the entire packet header. */
  937. CHANNEL_OF(tempCommand) = 0;
  938. PTYPE_OF(tempCommand) = PTYPE_INLINE;
  939. CMD_COUNT_OF(tempCommand) = 2;
  940. (CMD_OF(tempCommand))[0] = CMDVALUE_IRQ;
  941. (CMD_OF(tempCommand))[1] = boardIrq;
  942. /*
  943. * Write to FIFO; don't bother to adjust fifo capacity for this, since
  944. * board will respond almost immediately after SendMail hit.
  945. */
  946. WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);
  947. iiWriteBuf(pB, tempCommand, 4);
  948. WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);
  949. pB->i2eUsingIrq = boardIrq;
  950. pB->i2eOutMailWaiting |= MB_OUT_STUFFED;
  951. /* Need to update number of boards before you enable mailbox int */
  952. ++i2nBoards;
  953. CHANNEL_OF(tempCommand) = 0;
  954. PTYPE_OF(tempCommand) = PTYPE_BYPASS;
  955. CMD_COUNT_OF(tempCommand) = 6;
  956. (CMD_OF(tempCommand))[0] = 88; // SILO
  957. (CMD_OF(tempCommand))[1] = 64; // chars
  958. (CMD_OF(tempCommand))[2] = 32; // ms
  959. (CMD_OF(tempCommand))[3] = 28; // MAX_BLOCK
  960. (CMD_OF(tempCommand))[4] = 64; // chars
  961. (CMD_OF(tempCommand))[5] = 87; // HW_TEST
  962. WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);
  963. iiWriteBuf(pB, tempCommand, 8);
  964. WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);
  965. CHANNEL_OF(tempCommand) = 0;
  966. PTYPE_OF(tempCommand) = PTYPE_BYPASS;
  967. CMD_COUNT_OF(tempCommand) = 1;
  968. (CMD_OF(tempCommand))[0] = 84; /* get BOX_IDS */
  969. iiWriteBuf(pB, tempCommand, 3);
  970. #ifdef XXX
  971. // enable heartbeat for test porpoises
  972. CHANNEL_OF(tempCommand) = 0;
  973. PTYPE_OF(tempCommand) = PTYPE_BYPASS;
  974. CMD_COUNT_OF(tempCommand) = 2;
  975. (CMD_OF(tempCommand))[0] = 44; /* get ping */
  976. (CMD_OF(tempCommand))[1] = 200; /* 200 ms */
  977. WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);
  978. iiWriteBuf(pB, tempCommand, 4);
  979. WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);
  980. #endif
  981. iiEnableMailIrq(pB);
  982. iiSendPendingMail(pB);
  983. }
  984. /******************************************************************************/
  985. /* Interrupt Handler Section */
  986. /******************************************************************************/
  987. static inline void
  988. service_all_boards(void)
  989. {
  990. int i;
  991. i2eBordStrPtr pB;
  992. /* Service every board on the list */
  993. for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  994. pB = i2BoardPtrTable[i];
  995. if ( pB ) {
  996. i2ServiceBoard( pB );
  997. }
  998. }
  999. }
  1000. /******************************************************************************/
  1001. /* Function: ip2_interrupt_bh(work) */
  1002. /* Parameters: work - pointer to the board structure */
  1003. /* Returns: Nothing */
  1004. /* */
  1005. /* Description: */
  1006. /* Service the board in a bottom half interrupt handler and then */
  1007. /* reenable the board's interrupts if it has an IRQ number */
  1008. /* */
  1009. /******************************************************************************/
  1010. static void
  1011. ip2_interrupt_bh(struct work_struct *work)
  1012. {
  1013. i2eBordStrPtr pB = container_of(work, i2eBordStr, tqueue_interrupt);
  1014. // pB better well be set or we have a problem! We can only get
  1015. // here from the IMMEDIATE queue. Here, we process the boards.
  1016. // Checking pB doesn't cost much and it saves us from the sanity checkers.
  1017. bh_counter++;
  1018. if ( pB ) {
  1019. i2ServiceBoard( pB );
  1020. if( pB->i2eUsingIrq ) {
  1021. // Re-enable his interrupts
  1022. iiEnableMailIrq(pB);
  1023. }
  1024. }
  1025. }
  1026. /******************************************************************************/
  1027. /* Function: ip2_interrupt(int irq, void *dev_id) */
  1028. /* Parameters: irq - interrupt number */
  1029. /* pointer to optional device ID structure */
  1030. /* Returns: Nothing */
  1031. /* */
  1032. /* Description: */
  1033. /* */
  1034. /* Our task here is simply to identify each board which needs servicing. */
  1035. /* If we are queuing then, queue it to be serviced, and disable its irq */
  1036. /* mask otherwise process the board directly. */
  1037. /* */
  1038. /* We could queue by IRQ but that just complicates things on both ends */
  1039. /* with very little gain in performance (how many instructions does */
  1040. /* it take to iterate on the immediate queue). */
  1041. /* */
  1042. /* */
  1043. /******************************************************************************/
  1044. static irqreturn_t
  1045. ip2_interrupt(int irq, void *dev_id)
  1046. {
  1047. int i;
  1048. i2eBordStrPtr pB;
  1049. int handled = 0;
  1050. ip2trace (ITRC_NO_PORT, ITRC_INTR, 99, 1, irq );
  1051. /* Service just the boards on the list using this irq */
  1052. for( i = 0; i < i2nBoards; ++i ) {
  1053. pB = i2BoardPtrTable[i];
  1054. // Only process those boards which match our IRQ.
  1055. // IRQ = 0 for polled boards, we won't poll "IRQ" boards
  1056. if ( pB && (pB->i2eUsingIrq == irq) ) {
  1057. handled = 1;
  1058. #ifdef USE_IQI
  1059. if (NO_MAIL_HERE != ( pB->i2eStartMail = iiGetMail(pB))) {
  1060. // Disable his interrupt (will be enabled when serviced)
  1061. // This is mostly to protect from reentrancy.
  1062. iiDisableMailIrq(pB);
  1063. // Park the board on the immediate queue for processing.
  1064. schedule_work(&pB->tqueue_interrupt);
  1065. // Make sure the immediate queue is flagged to fire.
  1066. }
  1067. #else
  1068. // We are using immediate servicing here. This sucks and can
  1069. // cause all sorts of havoc with ppp and others. The failsafe
  1070. // check on iiSendPendingMail could also throw a hairball.
  1071. i2ServiceBoard( pB );
  1072. #endif /* USE_IQI */
  1073. }
  1074. }
  1075. ++irq_counter;
  1076. ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
  1077. return IRQ_RETVAL(handled);
  1078. }
  1079. /******************************************************************************/
  1080. /* Function: ip2_poll(unsigned long arg) */
  1081. /* Parameters: ? */
  1082. /* Returns: Nothing */
  1083. /* */
  1084. /* Description: */
  1085. /* This function calls the library routine i2ServiceBoard for each board in */
  1086. /* the board table. This is used instead of the interrupt routine when polled */
  1087. /* mode is specified. */
  1088. /******************************************************************************/
  1089. static void
  1090. ip2_poll(unsigned long arg)
  1091. {
  1092. ip2trace (ITRC_NO_PORT, ITRC_INTR, 100, 0 );
  1093. TimerOn = 0; // it's the truth but not checked in service
  1094. // Just polled boards, IRQ = 0 will hit all non-interrupt boards.
  1095. // It will NOT poll boards handled by hard interrupts.
  1096. // The issue of queued BH interrups is handled in ip2_interrupt().
  1097. ip2_interrupt(0, NULL);
  1098. PollTimer.expires = POLL_TIMEOUT;
  1099. add_timer( &PollTimer );
  1100. TimerOn = 1;
  1101. ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
  1102. }
  1103. static void do_input(struct work_struct *work)
  1104. {
  1105. i2ChanStrPtr pCh = container_of(work, i2ChanStr, tqueue_input);
  1106. unsigned long flags;
  1107. ip2trace(CHANN, ITRC_INPUT, 21, 0 );
  1108. // Data input
  1109. if ( pCh->pTTY != NULL ) {
  1110. READ_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags)
  1111. if (!pCh->throttled && (pCh->Ibuf_stuff != pCh->Ibuf_strip)) {
  1112. READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
  1113. i2Input( pCh );
  1114. } else
  1115. READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
  1116. } else {
  1117. ip2trace(CHANN, ITRC_INPUT, 22, 0 );
  1118. i2InputFlush( pCh );
  1119. }
  1120. }
  1121. // code duplicated from n_tty (ldisc)
  1122. static inline void isig(int sig, struct tty_struct *tty, int flush)
  1123. {
  1124. if (tty->pgrp)
  1125. kill_pgrp(tty->pgrp, sig, 1);
  1126. if (flush || !L_NOFLSH(tty)) {
  1127. if ( tty->ldisc.flush_buffer )
  1128. tty->ldisc.flush_buffer(tty);
  1129. i2InputFlush( tty->driver_data );
  1130. }
  1131. }
  1132. static void do_status(struct work_struct *work)
  1133. {
  1134. i2ChanStrPtr pCh = container_of(work, i2ChanStr, tqueue_status);
  1135. int status;
  1136. status = i2GetStatus( pCh, (I2_BRK|I2_PAR|I2_FRA|I2_OVR) );
  1137. ip2trace (CHANN, ITRC_STATUS, 21, 1, status );
  1138. if (pCh->pTTY && (status & (I2_BRK|I2_PAR|I2_FRA|I2_OVR)) ) {
  1139. if ( (status & I2_BRK) ) {
  1140. // code duplicated from n_tty (ldisc)
  1141. if (I_IGNBRK(pCh->pTTY))
  1142. goto skip_this;
  1143. if (I_BRKINT(pCh->pTTY)) {
  1144. isig(SIGINT, pCh->pTTY, 1);
  1145. goto skip_this;
  1146. }
  1147. wake_up_interruptible(&pCh->pTTY->read_wait);
  1148. }
  1149. #ifdef NEVER_HAPPENS_AS_SETUP_XXX
  1150. // and can't work because we don't know the_char
  1151. // as the_char is reported on a separate path
  1152. // The intelligent board does this stuff as setup
  1153. {
  1154. char brkf = TTY_NORMAL;
  1155. unsigned char brkc = '\0';
  1156. unsigned char tmp;
  1157. if ( (status & I2_BRK) ) {
  1158. brkf = TTY_BREAK;
  1159. brkc = '\0';
  1160. }
  1161. else if (status & I2_PAR) {
  1162. brkf = TTY_PARITY;
  1163. brkc = the_char;
  1164. } else if (status & I2_FRA) {
  1165. brkf = TTY_FRAME;
  1166. brkc = the_char;
  1167. } else if (status & I2_OVR) {
  1168. brkf = TTY_OVERRUN;
  1169. brkc = the_char;
  1170. }
  1171. tmp = pCh->pTTY->real_raw;
  1172. pCh->pTTY->real_raw = 0;
  1173. pCh->pTTY->ldisc.receive_buf( pCh->pTTY, &brkc, &brkf, 1 );
  1174. pCh->pTTY->real_raw = tmp;
  1175. }
  1176. #endif /* NEVER_HAPPENS_AS_SETUP_XXX */
  1177. }
  1178. skip_this:
  1179. if ( status & (I2_DDCD | I2_DDSR | I2_DCTS | I2_DRI) ) {
  1180. wake_up_interruptible(&pCh->delta_msr_wait);
  1181. if ( (pCh->flags & ASYNC_CHECK_CD) && (status & I2_DDCD) ) {
  1182. if ( status & I2_DCD ) {
  1183. if ( pCh->wopen ) {
  1184. wake_up_interruptible ( &pCh->open_wait );
  1185. }
  1186. } else {
  1187. if (pCh->pTTY && (!(pCh->pTTY->termios->c_cflag & CLOCAL)) ) {
  1188. tty_hangup( pCh->pTTY );
  1189. }
  1190. }
  1191. }
  1192. }
  1193. ip2trace (CHANN, ITRC_STATUS, 26, 0 );
  1194. }
  1195. /******************************************************************************/
  1196. /* Device Open/Close/Ioctl Entry Point Section */
  1197. /******************************************************************************/
  1198. /******************************************************************************/
  1199. /* Function: open_sanity_check() */
  1200. /* Parameters: Pointer to tty structure */
  1201. /* Pointer to file structure */
  1202. /* Returns: Success or failure */
  1203. /* */
  1204. /* Description: */
  1205. /* Verifies the structure magic numbers and cross links. */
  1206. /******************************************************************************/
  1207. #ifdef IP2DEBUG_OPEN
  1208. static void
  1209. open_sanity_check( i2ChanStrPtr pCh, i2eBordStrPtr pBrd )
  1210. {
  1211. if ( pBrd->i2eValid != I2E_MAGIC ) {
  1212. printk(KERN_ERR "IP2: invalid board structure\n" );
  1213. } else if ( pBrd != pCh->pMyBord ) {
  1214. printk(KERN_ERR "IP2: board structure pointer mismatch (%p)\n",
  1215. pCh->pMyBord );
  1216. } else if ( pBrd->i2eChannelCnt < pCh->port_index ) {
  1217. printk(KERN_ERR "IP2: bad device index (%d)\n", pCh->port_index );
  1218. } else if (&((i2ChanStrPtr)pBrd->i2eChannelPtr)[pCh->port_index] != pCh) {
  1219. } else {
  1220. printk(KERN_INFO "IP2: all pointers check out!\n" );
  1221. }
  1222. }
  1223. #endif
  1224. /******************************************************************************/
  1225. /* Function: ip2_open() */
  1226. /* Parameters: Pointer to tty structure */
  1227. /* Pointer to file structure */
  1228. /* Returns: Success or failure */
  1229. /* */
  1230. /* Description: (MANDATORY) */
  1231. /* A successful device open has to run a gauntlet of checks before it */
  1232. /* completes. After some sanity checking and pointer setup, the function */
  1233. /* blocks until all conditions are satisfied. It then initialises the port to */
  1234. /* the default characteristics and returns. */
  1235. /******************************************************************************/
  1236. static int
  1237. ip2_open( PTTY tty, struct file *pFile )
  1238. {
  1239. wait_queue_t wait;
  1240. int rc = 0;
  1241. int do_clocal = 0;
  1242. i2ChanStrPtr pCh = DevTable[tty->index];
  1243. ip2trace (tty->index, ITRC_OPEN, ITRC_ENTER, 0 );
  1244. if ( pCh == NULL ) {
  1245. return -ENODEV;
  1246. }
  1247. /* Setup pointer links in device and tty structures */
  1248. pCh->pTTY = tty;
  1249. tty->driver_data = pCh;
  1250. #ifdef IP2DEBUG_OPEN
  1251. printk(KERN_DEBUG \
  1252. "IP2:open(tty=%p,pFile=%p):dev=%s,ch=%d,idx=%d\n",
  1253. tty, pFile, tty->name, pCh->infl.hd.i2sChannel, pCh->port_index);
  1254. open_sanity_check ( pCh, pCh->pMyBord );
  1255. #endif
  1256. i2QueueCommands(PTYPE_INLINE, pCh, 100, 3, CMD_DTRUP,CMD_RTSUP,CMD_DCD_REP);
  1257. pCh->dataSetOut |= (I2_DTR | I2_RTS);
  1258. serviceOutgoingFifo( pCh->pMyBord );
  1259. /* Block here until the port is ready (per serial and istallion) */
  1260. /*
  1261. * 1. If the port is in the middle of closing wait for the completion
  1262. * and then return the appropriate error.
  1263. */
  1264. init_waitqueue_entry(&wait, current);
  1265. add_wait_queue(&pCh->close_wait, &wait);
  1266. set_current_state( TASK_INTERRUPTIBLE );
  1267. if ( tty_hung_up_p(pFile) || ( pCh->flags & ASYNC_CLOSING )) {
  1268. if ( pCh->flags & ASYNC_CLOSING ) {
  1269. schedule();
  1270. }
  1271. if ( tty_hung_up_p(pFile) ) {
  1272. set_current_state( TASK_RUNNING );
  1273. remove_wait_queue(&pCh->close_wait, &wait);
  1274. return( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS;
  1275. }
  1276. }
  1277. set_current_state( TASK_RUNNING );
  1278. remove_wait_queue(&pCh->close_wait, &wait);
  1279. /*
  1280. * 3. Handle a non-blocking open of a normal port.
  1281. */
  1282. if ( (pFile->f_flags & O_NONBLOCK) || (tty->flags & (1<<TTY_IO_ERROR) )) {
  1283. pCh->flags |= ASYNC_NORMAL_ACTIVE;
  1284. goto noblock;
  1285. }
  1286. /*
  1287. * 4. Now loop waiting for the port to be free and carrier present
  1288. * (if required).
  1289. */
  1290. if ( tty->termios->c_cflag & CLOCAL )
  1291. do_clocal = 1;
  1292. #ifdef IP2DEBUG_OPEN
  1293. printk(KERN_DEBUG "OpenBlock: do_clocal = %d\n", do_clocal);
  1294. #endif
  1295. ++pCh->wopen;
  1296. init_waitqueue_entry(&wait, current);
  1297. add_wait_queue(&pCh->open_wait, &wait);
  1298. for(;;) {
  1299. i2QueueCommands(PTYPE_INLINE, pCh, 100, 2, CMD_DTRUP, CMD_RTSUP);
  1300. pCh->dataSetOut |= (I2_DTR | I2_RTS);
  1301. set_current_state( TASK_INTERRUPTIBLE );
  1302. serviceOutgoingFifo( pCh->pMyBord );
  1303. if ( tty_hung_up_p(pFile) ) {
  1304. set_current_state( TASK_RUNNING );
  1305. remove_wait_queue(&pCh->open_wait, &wait);
  1306. return ( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EBUSY : -ERESTARTSYS;
  1307. }
  1308. if (!(pCh->flags & ASYNC_CLOSING) &&
  1309. (do_clocal || (pCh->dataSetIn & I2_DCD) )) {
  1310. rc = 0;
  1311. break;
  1312. }
  1313. #ifdef IP2DEBUG_OPEN
  1314. printk(KERN_DEBUG "ASYNC_CLOSING = %s\n",
  1315. (pCh->flags & ASYNC_CLOSING)?"True":"False");
  1316. printk(KERN_DEBUG "OpenBlock: waiting for CD or signal\n");
  1317. #endif
  1318. ip2trace (CHANN, ITRC_OPEN, 3, 2, 0,
  1319. (pCh->flags & ASYNC_CLOSING) );
  1320. /* check for signal */
  1321. if (signal_pending(current)) {
  1322. rc = (( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS);
  1323. break;
  1324. }
  1325. schedule();
  1326. }
  1327. set_current_state( TASK_RUNNING );
  1328. remove_wait_queue(&pCh->open_wait, &wait);
  1329. --pCh->wopen; //why count?
  1330. ip2trace (CHANN, ITRC_OPEN, 4, 0 );
  1331. if (rc != 0 ) {
  1332. return rc;
  1333. }
  1334. pCh->flags |= ASYNC_NORMAL_ACTIVE;
  1335. noblock:
  1336. /* first open - Assign termios structure to port */
  1337. if ( tty->count == 1 ) {
  1338. i2QueueCommands(PTYPE_INLINE, pCh, 0, 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
  1339. /* Now we must send the termios settings to the loadware */
  1340. set_params( pCh, NULL );
  1341. }
  1342. /*
  1343. * Now set any i2lib options. These may go away if the i2lib code ends
  1344. * up rolled into the mainline.
  1345. */
  1346. pCh->channelOptions |= CO_NBLOCK_WRITE;
  1347. #ifdef IP2DEBUG_OPEN
  1348. printk (KERN_DEBUG "IP2: open completed\n" );
  1349. #endif
  1350. serviceOutgoingFifo( pCh->pMyBord );
  1351. ip2trace (CHANN, ITRC_OPEN, ITRC_RETURN, 0 );
  1352. return 0;
  1353. }
  1354. /******************************************************************************/
  1355. /* Function: ip2_close() */
  1356. /* Parameters: Pointer to tty structure */
  1357. /* Pointer to file structure */
  1358. /* Returns: Nothing */
  1359. /* */
  1360. /* Description: */
  1361. /* */
  1362. /* */
  1363. /******************************************************************************/
  1364. static void
  1365. ip2_close( PTTY tty, struct file *pFile )
  1366. {
  1367. i2ChanStrPtr pCh = tty->driver_data;
  1368. if ( !pCh ) {
  1369. return;
  1370. }
  1371. ip2trace (CHANN, ITRC_CLOSE, ITRC_ENTER, 0 );
  1372. #ifdef IP2DEBUG_OPEN
  1373. printk(KERN_DEBUG "IP2:close %s:\n",tty->name);
  1374. #endif
  1375. if ( tty_hung_up_p ( pFile ) ) {
  1376. ip2trace (CHANN, ITRC_CLOSE, 2, 1, 2 );
  1377. return;
  1378. }
  1379. if ( tty->count > 1 ) { /* not the last close */
  1380. ip2trace (CHANN, ITRC_CLOSE, 2, 1, 3 );
  1381. return;
  1382. }
  1383. pCh->flags |= ASYNC_CLOSING; // last close actually
  1384. tty->closing = 1;
  1385. if (pCh->ClosingWaitTime != ASYNC_CLOSING_WAIT_NONE) {
  1386. /*
  1387. * Before we drop DTR, make sure the transmitter has completely drained.
  1388. * This uses an timeout, after which the close
  1389. * completes.
  1390. */
  1391. ip2_wait_until_sent(tty, pCh->ClosingWaitTime );
  1392. }
  1393. /*
  1394. * At this point we stop accepting input. Here we flush the channel
  1395. * input buffer which will allow the board to send up more data. Any
  1396. * additional input is tossed at interrupt/poll time.
  1397. */
  1398. i2InputFlush( pCh );
  1399. /* disable DSS reporting */
  1400. i2QueueCommands(PTYPE_INLINE, pCh, 100, 4,
  1401. CMD_DCD_NREP, CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
  1402. if ( !tty || (tty->termios->c_cflag & HUPCL) ) {
  1403. i2QueueCommands(PTYPE_INLINE, pCh, 100, 2, CMD_RTSDN, CMD_DTRDN);
  1404. pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
  1405. i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
  1406. }
  1407. serviceOutgoingFifo ( pCh->pMyBord );
  1408. if ( tty->driver->flush_buffer )
  1409. tty->driver->flush_buffer(tty);
  1410. if ( tty->ldisc.flush_buffer )
  1411. tty->ldisc.flush_buffer(tty);
  1412. tty->closing = 0;
  1413. pCh->pTTY = NULL;
  1414. if (pCh->wopen) {
  1415. if (pCh->ClosingDelay) {
  1416. msleep_interruptible(jiffies_to_msecs(pCh->ClosingDelay));
  1417. }
  1418. wake_up_interruptible(&pCh->open_wait);
  1419. }
  1420. pCh->flags &=~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  1421. wake_up_interruptible(&pCh->close_wait);
  1422. #ifdef IP2DEBUG_OPEN
  1423. DBG_CNT("ip2_close: after wakeups--");
  1424. #endif
  1425. ip2trace (CHANN, ITRC_CLOSE, ITRC_RETURN, 1, 1 );
  1426. return;
  1427. }
  1428. /******************************************************************************/
  1429. /* Function: ip2_hangup() */
  1430. /* Parameters: Pointer to tty structure */
  1431. /* Returns: Nothing */
  1432. /* */
  1433. /* Description: */
  1434. /* */
  1435. /* */
  1436. /******************************************************************************/
  1437. static void
  1438. ip2_hangup ( PTTY tty )
  1439. {
  1440. i2ChanStrPtr pCh = tty->driver_data;
  1441. if( !pCh ) {
  1442. return;
  1443. }
  1444. ip2trace (CHANN, ITRC_HANGUP, ITRC_ENTER, 0 );
  1445. ip2_flush_buffer(tty);
  1446. /* disable DSS reporting */
  1447. i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_DCD_NREP);
  1448. i2QueueCommands(PTYPE_INLINE, pCh, 0, 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
  1449. if ( (tty->termios->c_cflag & HUPCL) ) {
  1450. i2QueueCommands(PTYPE_BYPASS, pCh, 0, 2, CMD_RTSDN, CMD_DTRDN);
  1451. pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
  1452. i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
  1453. }
  1454. i2QueueCommands(PTYPE_INLINE, pCh, 1, 3,
  1455. CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
  1456. serviceOutgoingFifo ( pCh->pMyBord );
  1457. wake_up_interruptible ( &pCh->delta_msr_wait );
  1458. pCh->flags &= ~ASYNC_NORMAL_ACTIVE;
  1459. pCh->pTTY = NULL;
  1460. wake_up_interruptible ( &pCh->open_wait );
  1461. ip2trace (CHANN, ITRC_HANGUP, ITRC_RETURN, 0 );
  1462. }
  1463. /******************************************************************************/
  1464. /******************************************************************************/
  1465. /* Device Output Section */
  1466. /******************************************************************************/
  1467. /******************************************************************************/
  1468. /******************************************************************************/
  1469. /* Function: ip2_write() */
  1470. /* Parameters: Pointer to tty structure */
  1471. /* Flag denoting data is in user (1) or kernel (0) space */
  1472. /* Pointer to data */
  1473. /* Number of bytes to write */
  1474. /* Returns: Number of bytes actually written */
  1475. /* */
  1476. /* Description: (MANDATORY) */
  1477. /* */
  1478. /* */
  1479. /******************************************************************************/
  1480. static int
  1481. ip2_write( PTTY tty, const unsigned char *pData, int count)
  1482. {
  1483. i2ChanStrPtr pCh = tty->driver_data;
  1484. int bytesSent = 0;
  1485. unsigned long flags;
  1486. ip2trace (CHANN, ITRC_WRITE, ITRC_ENTER, 2, count, -1 );
  1487. /* Flush out any buffered data left over from ip2_putchar() calls. */
  1488. ip2_flush_chars( tty );
  1489. /* This is the actual move bit. Make sure it does what we need!!!!! */
  1490. WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
  1491. bytesSent = i2Output( pCh, pData, count);
  1492. WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
  1493. ip2trace (CHANN, ITRC_WRITE, ITRC_RETURN, 1, bytesSent );
  1494. return bytesSent > 0 ? bytesSent : 0;
  1495. }
  1496. /******************************************************************************/
  1497. /* Function: ip2_putchar() */
  1498. /* Parameters: Pointer to tty structure */
  1499. /* Character to write */
  1500. /* Returns: Nothing */
  1501. /* */
  1502. /* Description: */
  1503. /* */
  1504. /* */
  1505. /******************************************************************************/
  1506. static void
  1507. ip2_putchar( PTTY tty, unsigned char ch )
  1508. {
  1509. i2ChanStrPtr pCh = tty->driver_data;
  1510. unsigned long flags;
  1511. // ip2trace (CHANN, ITRC_PUTC, ITRC_ENTER, 1, ch );
  1512. WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
  1513. pCh->Pbuf[pCh->Pbuf_stuff++] = ch;
  1514. if ( pCh->Pbuf_stuff == sizeof pCh->Pbuf ) {
  1515. WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
  1516. ip2_flush_chars( tty );
  1517. } else
  1518. WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
  1519. // ip2trace (CHANN, ITRC_PUTC, ITRC_RETURN, 1, ch );
  1520. }
  1521. /******************************************************************************/
  1522. /* Function: ip2_flush_chars() */
  1523. /* Parameters: Pointer to tty structure */
  1524. /* Returns: Nothing */
  1525. /* */
  1526. /* Description: */
  1527. /* */
  1528. /******************************************************************************/
  1529. static void
  1530. ip2_flush_chars( PTTY tty )
  1531. {
  1532. int strip;
  1533. i2ChanStrPtr pCh = tty->driver_data;
  1534. unsigned long flags;
  1535. WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
  1536. if ( pCh->Pbuf_stuff ) {
  1537. // ip2trace (CHANN, ITRC_PUTC, 10, 1, strip );
  1538. //
  1539. // We may need to restart i2Output if it does not fullfill this request
  1540. //
  1541. strip = i2Output( pCh, pCh->Pbuf, pCh->Pbuf_stuff);
  1542. if ( strip != pCh->Pbuf_stuff ) {
  1543. memmove( pCh->Pbuf, &pCh->Pbuf[strip], pCh->Pbuf_stuff - strip );
  1544. }
  1545. pCh->Pbuf_stuff -= strip;
  1546. }
  1547. WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
  1548. }
  1549. /******************************************************************************/
  1550. /* Function: ip2_write_room() */
  1551. /* Parameters: Pointer to tty structure */
  1552. /* Returns: Number of bytes that the driver can accept */
  1553. /* */
  1554. /* Description: */
  1555. /* */
  1556. /******************************************************************************/
  1557. static int
  1558. ip2_write_room ( PTTY tty )
  1559. {
  1560. int bytesFree;
  1561. i2ChanStrPtr pCh = tty->driver_data;
  1562. unsigned long flags;
  1563. READ_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
  1564. bytesFree = i2OutputFree( pCh ) - pCh->Pbuf_stuff;
  1565. READ_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
  1566. ip2trace (CHANN, ITRC_WRITE, 11, 1, bytesFree );
  1567. return ((bytesFree > 0) ? bytesFree : 0);
  1568. }
  1569. /******************************************************************************/
  1570. /* Function: ip2_chars_in_buf() */
  1571. /* Parameters: Pointer to tty structure */
  1572. /* Returns: Number of bytes queued for transmission */
  1573. /* */
  1574. /* Description: */
  1575. /* */
  1576. /* */
  1577. /******************************************************************************/
  1578. static int
  1579. ip2_chars_in_buf ( PTTY tty )
  1580. {
  1581. i2ChanStrPtr pCh = tty->driver_data;
  1582. int rc;
  1583. unsigned long flags;
  1584. ip2trace (CHANN, ITRC_WRITE, 12, 1, pCh->Obuf_char_count + pCh->Pbuf_stuff );
  1585. #ifdef IP2DEBUG_WRITE
  1586. printk (KERN_DEBUG "IP2: chars in buffer = %d (%d,%d)\n",
  1587. pCh->Obuf_char_count + pCh->Pbuf_stuff,
  1588. pCh->Obuf_char_count, pCh->Pbuf_stuff );
  1589. #endif
  1590. READ_LOCK_IRQSAVE(&pCh->Obuf_spinlock,flags);
  1591. rc = pCh->Obuf_char_count;
  1592. READ_UNLOCK_IRQRESTORE(&pCh->Obuf_spinlock,flags);
  1593. READ_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
  1594. rc += pCh->Pbuf_stuff;
  1595. READ_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
  1596. return rc;
  1597. }
  1598. /******************************************************************************/
  1599. /* Function: ip2_flush_buffer() */
  1600. /* Parameters: Pointer to tty structure */
  1601. /* Returns: Nothing */
  1602. /* */
  1603. /* Description: */
  1604. /* */
  1605. /* */
  1606. /******************************************************************************/
  1607. static void
  1608. ip2_flush_buffer( PTTY tty )
  1609. {
  1610. i2ChanStrPtr pCh = tty->driver_data;
  1611. unsigned long flags;
  1612. ip2trace (CHANN, ITRC_FLUSH, ITRC_ENTER, 0 );
  1613. #ifdef IP2DEBUG_WRITE
  1614. printk (KERN_DEBUG "IP2: flush buffer\n" );
  1615. #endif
  1616. WRITE_LOCK_IRQSAVE(&pCh->Pbuf_spinlock,flags);
  1617. pCh->Pbuf_stuff = 0;
  1618. WRITE_UNLOCK_IRQRESTORE(&pCh->Pbuf_spinlock,flags);
  1619. i2FlushOutput( pCh );
  1620. ip2_owake(tty);
  1621. ip2trace (CHANN, ITRC_FLUSH, ITRC_RETURN, 0 );
  1622. }
  1623. /******************************************************************************/
  1624. /* Function: ip2_wait_until_sent() */
  1625. /* Parameters: Pointer to tty structure */
  1626. /* Timeout for wait. */
  1627. /* Returns: Nothing */
  1628. /* */
  1629. /* Description: */
  1630. /* This function is used in place of the normal tty_wait_until_sent, which */
  1631. /* only waits for the driver buffers to be empty (or rather, those buffers */
  1632. /* reported by chars_in_buffer) which doesn't work for IP2 due to the */
  1633. /* indeterminate number of bytes buffered on the board. */
  1634. /******************************************************************************/
  1635. static void
  1636. ip2_wait_until_sent ( PTTY tty, int timeout )
  1637. {
  1638. int i = jiffies;
  1639. i2ChanStrPtr pCh = tty->driver_data;
  1640. tty_wait_until_sent(tty, timeout );
  1641. if ( (i = timeout - (jiffies -i)) > 0)
  1642. i2DrainOutput( pCh, i );
  1643. }
  1644. /******************************************************************************/
  1645. /******************************************************************************/
  1646. /* Device Input Section */
  1647. /******************************************************************************/
  1648. /******************************************************************************/
  1649. /******************************************************************************/
  1650. /* Function: ip2_throttle() */
  1651. /* Parameters: Pointer to tty structure */
  1652. /* Returns: Nothing */
  1653. /* */
  1654. /* Description: */
  1655. /* */
  1656. /* */
  1657. /******************************************************************************/
  1658. static void
  1659. ip2_throttle ( PTTY tty )
  1660. {
  1661. i2ChanStrPtr pCh = tty->driver_data;
  1662. #ifdef IP2DEBUG_READ
  1663. printk (KERN_DEBUG "IP2: throttle\n" );
  1664. #endif
  1665. /*
  1666. * Signal the poll/interrupt handlers not to forward incoming data to
  1667. * the line discipline. This will cause the buffers to fill up in the
  1668. * library and thus cause the library routines to send the flow control
  1669. * stuff.
  1670. */
  1671. pCh->throttled = 1;
  1672. }
  1673. /******************************************************************************/
  1674. /* Function: ip2_unthrottle() */
  1675. /* Parameters: Pointer to tty structure */
  1676. /* Returns: Nothing */
  1677. /* */
  1678. /* Description: */
  1679. /* */
  1680. /* */
  1681. /******************************************************************************/
  1682. static void
  1683. ip2_unthrottle ( PTTY tty )
  1684. {
  1685. i2ChanStrPtr pCh = tty->driver_data;
  1686. unsigned long flags;
  1687. #ifdef IP2DEBUG_READ
  1688. printk (KERN_DEBUG "IP2: unthrottle\n" );
  1689. #endif
  1690. /* Pass incoming data up to the line discipline again. */
  1691. pCh->throttled = 0;
  1692. i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME);
  1693. serviceOutgoingFifo( pCh->pMyBord );
  1694. READ_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags)
  1695. if ( pCh->Ibuf_stuff != pCh->Ibuf_strip ) {
  1696. READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
  1697. #ifdef IP2DEBUG_READ
  1698. printk (KERN_DEBUG "i2Input called from unthrottle\n" );
  1699. #endif
  1700. i2Input( pCh );
  1701. } else
  1702. READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags)
  1703. }
  1704. static void
  1705. ip2_start ( PTTY tty )
  1706. {
  1707. i2ChanStrPtr pCh = DevTable[tty->index];
  1708. i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME);
  1709. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_UNSUSPEND);
  1710. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_RESUME);
  1711. #ifdef IP2DEBUG_WRITE
  1712. printk (KERN_DEBUG "IP2: start tx\n" );
  1713. #endif
  1714. }
  1715. static void
  1716. ip2_stop ( PTTY tty )
  1717. {
  1718. i2ChanStrPtr pCh = DevTable[tty->index];
  1719. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_SUSPEND);
  1720. #ifdef IP2DEBUG_WRITE
  1721. printk (KERN_DEBUG "IP2: stop tx\n" );
  1722. #endif
  1723. }
  1724. /******************************************************************************/
  1725. /* Device Ioctl Section */
  1726. /******************************************************************************/
  1727. static int ip2_tiocmget(struct tty_struct *tty, struct file *file)
  1728. {
  1729. i2ChanStrPtr pCh = DevTable[tty->index];
  1730. #ifdef ENABLE_DSSNOW
  1731. wait_queue_t wait;
  1732. #endif
  1733. if (pCh == NULL)
  1734. return -ENODEV;
  1735. /*
  1736. FIXME - the following code is causing a NULL pointer dereference in
  1737. 2.3.51 in an interrupt handler. It's suppose to prompt the board
  1738. to return the DSS signal status immediately. Why doesn't it do
  1739. the same thing in 2.2.14?
  1740. */
  1741. /* This thing is still busted in the 1.2.12 driver on 2.4.x
  1742. and even hoses the serial console so the oops can be trapped.
  1743. /\/\|=mhw=|\/\/ */
  1744. #ifdef ENABLE_DSSNOW
  1745. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DSS_NOW);
  1746. init_waitqueue_entry(&wait, current);
  1747. add_wait_queue(&pCh->dss_now_wait, &wait);
  1748. set_current_state( TASK_INTERRUPTIBLE );
  1749. serviceOutgoingFifo( pCh->pMyBord );
  1750. schedule();
  1751. set_current_state( TASK_RUNNING );
  1752. remove_wait_queue(&pCh->dss_now_wait, &wait);
  1753. if (signal_pending(current)) {
  1754. return -EINTR;
  1755. }
  1756. #endif
  1757. return ((pCh->dataSetOut & I2_RTS) ? TIOCM_RTS : 0)
  1758. | ((pCh->dataSetOut & I2_DTR) ? TIOCM_DTR : 0)
  1759. | ((pCh->dataSetIn & I2_DCD) ? TIOCM_CAR : 0)
  1760. | ((pCh->dataSetIn & I2_RI) ? TIOCM_RNG : 0)
  1761. | ((pCh->dataSetIn & I2_DSR) ? TIOCM_DSR : 0)
  1762. | ((pCh->dataSetIn & I2_CTS) ? TIOCM_CTS : 0);
  1763. }
  1764. static int ip2_tiocmset(struct tty_struct *tty, struct file *file,
  1765. unsigned int set, unsigned int clear)
  1766. {
  1767. i2ChanStrPtr pCh = DevTable[tty->index];
  1768. if (pCh == NULL)
  1769. return -ENODEV;
  1770. if (set & TIOCM_RTS) {
  1771. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_RTSUP);
  1772. pCh->dataSetOut |= I2_RTS;
  1773. }
  1774. if (set & TIOCM_DTR) {
  1775. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DTRUP);
  1776. pCh->dataSetOut |= I2_DTR;
  1777. }
  1778. if (clear & TIOCM_RTS) {
  1779. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_RTSDN);
  1780. pCh->dataSetOut &= ~I2_RTS;
  1781. }
  1782. if (clear & TIOCM_DTR) {
  1783. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DTRDN);
  1784. pCh->dataSetOut &= ~I2_DTR;
  1785. }
  1786. serviceOutgoingFifo( pCh->pMyBord );
  1787. return 0;
  1788. }
  1789. /******************************************************************************/
  1790. /* Function: ip2_ioctl() */
  1791. /* Parameters: Pointer to tty structure */
  1792. /* Pointer to file structure */
  1793. /* Command */
  1794. /* Argument */
  1795. /* Returns: Success or failure */
  1796. /* */
  1797. /* Description: */
  1798. /* */
  1799. /* */
  1800. /******************************************************************************/
  1801. static int
  1802. ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg )
  1803. {
  1804. wait_queue_t wait;
  1805. i2ChanStrPtr pCh = DevTable[tty->index];
  1806. i2eBordStrPtr pB;
  1807. struct async_icount cprev, cnow; /* kernel counter temps */
  1808. struct serial_icounter_struct __user *p_cuser;
  1809. int rc = 0;
  1810. unsigned long flags;
  1811. void __user *argp = (void __user *)arg;
  1812. if ( pCh == NULL )
  1813. return -ENODEV;
  1814. pB = pCh->pMyBord;
  1815. ip2trace (CHANN, ITRC_IOCTL, ITRC_ENTER, 2, cmd, arg );
  1816. #ifdef IP2DEBUG_IOCTL
  1817. printk(KERN_DEBUG "IP2: ioctl cmd (%x), arg (%lx)\n", cmd, arg );
  1818. #endif
  1819. switch(cmd) {
  1820. case TIOCGSERIAL:
  1821. ip2trace (CHANN, ITRC_IOCTL, 2, 1, rc );
  1822. rc = get_serial_info(pCh, argp);
  1823. if (rc)
  1824. return rc;
  1825. break;
  1826. case TIOCSSERIAL:
  1827. ip2trace (CHANN, ITRC_IOCTL, 3, 1, rc );
  1828. rc = set_serial_info(pCh, argp);
  1829. if (rc)
  1830. return rc;
  1831. break;
  1832. case TCXONC:
  1833. rc = tty_check_change(tty);
  1834. if (rc)
  1835. return rc;
  1836. switch (arg) {
  1837. case TCOOFF:
  1838. //return -ENOIOCTLCMD;
  1839. break;
  1840. case TCOON:
  1841. //return -ENOIOCTLCMD;
  1842. break;
  1843. case TCIOFF:
  1844. if (STOP_CHAR(tty) != __DISABLED_CHAR) {
  1845. i2QueueCommands( PTYPE_BYPASS, pCh, 100, 1,
  1846. CMD_XMIT_NOW(STOP_CHAR(tty)));
  1847. }
  1848. break;
  1849. case TCION:
  1850. if (START_CHAR(tty) != __DISABLED_CHAR) {
  1851. i2QueueCommands( PTYPE_BYPASS, pCh, 100, 1,
  1852. CMD_XMIT_NOW(START_CHAR(tty)));
  1853. }
  1854. break;
  1855. default:
  1856. return -EINVAL;
  1857. }
  1858. return 0;
  1859. case TCSBRK: /* SVID version: non-zero arg --> no break */
  1860. rc = tty_check_change(tty);
  1861. ip2trace (CHANN, ITRC_IOCTL, 4, 1, rc );
  1862. if (!rc) {
  1863. ip2_wait_until_sent(tty,0);
  1864. if (!arg) {
  1865. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_SEND_BRK(250));
  1866. serviceOutgoingFifo( pCh->pMyBord );
  1867. }
  1868. }
  1869. break;
  1870. case TCSBRKP: /* support for POSIX tcsendbreak() */
  1871. rc = tty_check_change(tty);
  1872. ip2trace (CHANN, ITRC_IOCTL, 5, 1, rc );
  1873. if (!rc) {
  1874. ip2_wait_until_sent(tty,0);
  1875. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
  1876. CMD_SEND_BRK(arg ? arg*100 : 250));
  1877. serviceOutgoingFifo ( pCh->pMyBord );
  1878. }
  1879. break;
  1880. case TIOCGSOFTCAR:
  1881. ip2trace (CHANN, ITRC_IOCTL, 6, 1, rc );
  1882. rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
  1883. if (rc)
  1884. return rc;
  1885. break;
  1886. case TIOCSSOFTCAR:
  1887. ip2trace (CHANN, ITRC_IOCTL, 7, 1, rc );
  1888. rc = get_user(arg,(unsigned long __user *) argp);
  1889. if (rc)
  1890. return rc;
  1891. tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL)
  1892. | (arg ? CLOCAL : 0));
  1893. break;
  1894. /*
  1895. * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change - mask
  1896. * passed in arg for lines of interest (use |'ed TIOCM_RNG/DSR/CD/CTS
  1897. * for masking). Caller should use TIOCGICOUNT to see which one it was
  1898. */
  1899. case TIOCMIWAIT:
  1900. WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags);
  1901. cprev = pCh->icount; /* note the counters on entry */
  1902. WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags);
  1903. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 4,
  1904. CMD_DCD_REP, CMD_CTS_REP, CMD_DSR_REP, CMD_RI_REP);
  1905. init_waitqueue_entry(&wait, current);
  1906. add_wait_queue(&pCh->delta_msr_wait, &wait);
  1907. set_current_state( TASK_INTERRUPTIBLE );
  1908. serviceOutgoingFifo( pCh->pMyBord );
  1909. for(;;) {
  1910. ip2trace (CHANN, ITRC_IOCTL, 10, 0 );
  1911. schedule();
  1912. ip2trace (CHANN, ITRC_IOCTL, 11, 0 );
  1913. /* see if a signal did it */
  1914. if (signal_pending(current)) {
  1915. rc = -ERESTARTSYS;
  1916. break;
  1917. }
  1918. WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags);
  1919. cnow = pCh->icount; /* atomic copy */
  1920. WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags);
  1921. if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
  1922. cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
  1923. rc = -EIO; /* no change => rc */
  1924. break;
  1925. }
  1926. if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
  1927. ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
  1928. ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
  1929. ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
  1930. rc = 0;
  1931. break;
  1932. }
  1933. cprev = cnow;
  1934. }
  1935. set_current_state( TASK_RUNNING );
  1936. remove_wait_queue(&pCh->delta_msr_wait, &wait);
  1937. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 3,
  1938. CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
  1939. if ( ! (pCh->flags & ASYNC_CHECK_CD)) {
  1940. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DCD_NREP);
  1941. }
  1942. serviceOutgoingFifo( pCh->pMyBord );
  1943. return rc;
  1944. break;
  1945. /*
  1946. * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
  1947. * Return: write counters to the user passed counter struct
  1948. * NB: both 1->0 and 0->1 transitions are counted except for RI where
  1949. * only 0->1 is counted. The controller is quite capable of counting
  1950. * both, but this done to preserve compatibility with the standard
  1951. * serial driver.
  1952. */
  1953. case TIOCGICOUNT:
  1954. ip2trace (CHANN, ITRC_IOCTL, 11, 1, rc );
  1955. WRITE_LOCK_IRQSAVE(&pB->read_fifo_spinlock, flags);
  1956. cnow = pCh->icount;
  1957. WRITE_UNLOCK_IRQRESTORE(&pB->read_fifo_spinlock, flags);
  1958. p_cuser = argp;
  1959. rc = put_user(cnow.cts, &p_cuser->cts);
  1960. rc = put_user(cnow.dsr, &p_cuser->dsr);
  1961. rc = put_user(cnow.rng, &p_cuser->rng);
  1962. rc = put_user(cnow.dcd, &p_cuser->dcd);
  1963. rc = put_user(cnow.rx, &p_cuser->rx);
  1964. rc = put_user(cnow.tx, &p_cuser->tx);
  1965. rc = put_user(cnow.frame, &p_cuser->frame);
  1966. rc = put_user(cnow.overrun, &p_cuser->overrun);
  1967. rc = put_user(cnow.parity, &p_cuser->parity);
  1968. rc = put_user(cnow.brk, &p_cuser->brk);
  1969. rc = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
  1970. break;
  1971. /*
  1972. * The rest are not supported by this driver. By returning -ENOIOCTLCMD they
  1973. * will be passed to the line discipline for it to handle.
  1974. */
  1975. case TIOCSERCONFIG:
  1976. case TIOCSERGWILD:
  1977. case TIOCSERGETLSR:
  1978. case TIOCSERSWILD:
  1979. case TIOCSERGSTRUCT:
  1980. case TIOCSERGETMULTI:
  1981. case TIOCSERSETMULTI:
  1982. default:
  1983. ip2trace (CHANN, ITRC_IOCTL, 12, 0 );
  1984. rc = -ENOIOCTLCMD;
  1985. break;
  1986. }
  1987. ip2trace (CHANN, ITRC_IOCTL, ITRC_RETURN, 0 );
  1988. return rc;
  1989. }
  1990. /******************************************************************************/
  1991. /* Function: GetSerialInfo() */
  1992. /* Parameters: Pointer to channel structure */
  1993. /* Pointer to old termios structure */
  1994. /* Returns: Nothing */
  1995. /* */
  1996. /* Description: */
  1997. /* This is to support the setserial command, and requires processing of the */
  1998. /* standard Linux serial structure. */
  1999. /******************************************************************************/
  2000. static int
  2001. get_serial_info ( i2ChanStrPtr pCh, struct serial_struct __user *retinfo )
  2002. {
  2003. struct serial_struct tmp;
  2004. memset ( &tmp, 0, sizeof(tmp) );
  2005. tmp.type = pCh->pMyBord->channelBtypes.bid_value[(pCh->port_index & (IP2_PORTS_PER_BOARD-1))/16];
  2006. if (BID_HAS_654(tmp.type)) {
  2007. tmp.type = PORT_16650;
  2008. } else {
  2009. tmp.type = PORT_CIRRUS;
  2010. }
  2011. tmp.line = pCh->port_index;
  2012. tmp.port = pCh->pMyBord->i2eBase;
  2013. tmp.irq = ip2config.irq[pCh->port_index/64];
  2014. tmp.flags = pCh->flags;
  2015. tmp.baud_base = pCh->BaudBase;
  2016. tmp.close_delay = pCh->ClosingDelay;
  2017. tmp.closing_wait = pCh->ClosingWaitTime;
  2018. tmp.custom_divisor = pCh->BaudDivisor;
  2019. return copy_to_user(retinfo,&tmp,sizeof(*retinfo));
  2020. }
  2021. /******************************************************************************/
  2022. /* Function: SetSerialInfo() */
  2023. /* Parameters: Pointer to channel structure */
  2024. /* Pointer to old termios structure */
  2025. /* Returns: Nothing */
  2026. /* */
  2027. /* Description: */
  2028. /* This function provides support for setserial, which uses the TIOCSSERIAL */
  2029. /* ioctl. Not all setserial parameters are relevant. If the user attempts to */
  2030. /* change the IRQ, address or type of the port the ioctl fails. */
  2031. /******************************************************************************/
  2032. static int
  2033. set_serial_info( i2ChanStrPtr pCh, struct serial_struct __user *new_info )
  2034. {
  2035. struct serial_struct ns;
  2036. int old_flags, old_baud_divisor;
  2037. if (copy_from_user(&ns, new_info, sizeof (ns)))
  2038. return -EFAULT;
  2039. /*
  2040. * We don't allow setserial to change IRQ, board address, type or baud
  2041. * base. Also line nunber as such is meaningless but we use it for our
  2042. * array index so it is fixed also.
  2043. */
  2044. if ( (ns.irq != ip2config.irq[pCh->port_index])
  2045. || ((int) ns.port != ((int) (pCh->pMyBord->i2eBase)))
  2046. || (ns.baud_base != pCh->BaudBase)
  2047. || (ns.line != pCh->port_index) ) {
  2048. return -EINVAL;
  2049. }
  2050. old_flags = pCh->flags;
  2051. old_baud_divisor = pCh->BaudDivisor;
  2052. if ( !capable(CAP_SYS_ADMIN) ) {
  2053. if ( ( ns.close_delay != pCh->ClosingDelay ) ||
  2054. ( (ns.flags & ~ASYNC_USR_MASK) !=
  2055. (pCh->flags & ~ASYNC_USR_MASK) ) ) {
  2056. return -EPERM;
  2057. }
  2058. pCh->flags = (pCh->flags & ~ASYNC_USR_MASK) |
  2059. (ns.flags & ASYNC_USR_MASK);
  2060. pCh->BaudDivisor = ns.custom_divisor;
  2061. } else {
  2062. pCh->flags = (pCh->flags & ~ASYNC_FLAGS) |
  2063. (ns.flags & ASYNC_FLAGS);
  2064. pCh->BaudDivisor = ns.custom_divisor;
  2065. pCh->ClosingDelay = ns.close_delay * HZ/100;
  2066. pCh->ClosingWaitTime = ns.closing_wait * HZ/100;
  2067. }
  2068. if ( ( (old_flags & ASYNC_SPD_MASK) != (pCh->flags & ASYNC_SPD_MASK) )
  2069. || (old_baud_divisor != pCh->BaudDivisor) ) {
  2070. // Invalidate speed and reset parameters
  2071. set_params( pCh, NULL );
  2072. }
  2073. return 0;
  2074. }
  2075. /******************************************************************************/
  2076. /* Function: ip2_set_termios() */
  2077. /* Parameters: Pointer to tty structure */
  2078. /* Pointer to old termios structure */
  2079. /* Returns: Nothing */
  2080. /* */
  2081. /* Description: */
  2082. /* */
  2083. /* */
  2084. /******************************************************************************/
  2085. static void
  2086. ip2_set_termios( PTTY tty, struct ktermios *old_termios )
  2087. {
  2088. i2ChanStrPtr pCh = (i2ChanStrPtr)tty->driver_data;
  2089. #ifdef IP2DEBUG_IOCTL
  2090. printk (KERN_DEBUG "IP2: set termios %p\n", old_termios );
  2091. #endif
  2092. set_params( pCh, old_termios );
  2093. }
  2094. /******************************************************************************/
  2095. /* Function: ip2_set_line_discipline() */
  2096. /* Parameters: Pointer to tty structure */
  2097. /* Returns: Nothing */
  2098. /* */
  2099. /* Description: Does nothing */
  2100. /* */
  2101. /* */
  2102. /******************************************************************************/
  2103. static void
  2104. ip2_set_line_discipline ( PTTY tty )
  2105. {
  2106. #ifdef IP2DEBUG_IOCTL
  2107. printk (KERN_DEBUG "IP2: set line discipline\n" );
  2108. #endif
  2109. ip2trace (((i2ChanStrPtr)tty->driver_data)->port_index, ITRC_IOCTL, 16, 0 );
  2110. }
  2111. /******************************************************************************/
  2112. /* Function: SetLine Characteristics() */
  2113. /* Parameters: Pointer to channel structure */
  2114. /* Returns: Nothing */
  2115. /* */
  2116. /* Description: */
  2117. /* This routine is called to update the channel structure with the new line */
  2118. /* characteristics, and send the appropriate commands to the board when they */
  2119. /* change. */
  2120. /******************************************************************************/
  2121. static void
  2122. set_params( i2ChanStrPtr pCh, struct ktermios *o_tios )
  2123. {
  2124. tcflag_t cflag, iflag, lflag;
  2125. char stop_char, start_char;
  2126. struct ktermios dummy;
  2127. lflag = pCh->pTTY->termios->c_lflag;
  2128. cflag = pCh->pTTY->termios->c_cflag;
  2129. iflag = pCh->pTTY->termios->c_iflag;
  2130. if (o_tios == NULL) {
  2131. dummy.c_lflag = ~lflag;
  2132. dummy.c_cflag = ~cflag;
  2133. dummy.c_iflag = ~iflag;
  2134. o_tios = &dummy;
  2135. }
  2136. {
  2137. switch ( cflag & CBAUD ) {
  2138. case B0:
  2139. i2QueueCommands( PTYPE_BYPASS, pCh, 100, 2, CMD_RTSDN, CMD_DTRDN);
  2140. pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
  2141. i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
  2142. pCh->pTTY->termios->c_cflag |= (CBAUD & o_tios->c_cflag);
  2143. goto service_it;
  2144. break;
  2145. case B38400:
  2146. /*
  2147. * This is the speed that is overloaded with all the other high
  2148. * speeds, depending upon the flag settings.
  2149. */
  2150. if ( ( pCh->flags & ASYNC_SPD_MASK ) == ASYNC_SPD_HI ) {
  2151. pCh->speed = CBR_57600;
  2152. } else if ( (pCh->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI ) {
  2153. pCh->speed = CBR_115200;
  2154. } else if ( (pCh->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST ) {
  2155. pCh->speed = CBR_C1;
  2156. } else {
  2157. pCh->speed = CBR_38400;
  2158. }
  2159. break;
  2160. case B50: pCh->speed = CBR_50; break;
  2161. case B75: pCh->speed = CBR_75; break;
  2162. case B110: pCh->speed = CBR_110; break;
  2163. case B134: pCh->speed = CBR_134; break;
  2164. case B150: pCh->speed = CBR_150; break;
  2165. case B200: pCh->speed = CBR_200; break;
  2166. case B300: pCh->speed = CBR_300; break;
  2167. case B600: pCh->speed = CBR_600; break;
  2168. case B1200: pCh->speed = CBR_1200; break;
  2169. case B1800: pCh->speed = CBR_1800; break;
  2170. case B2400: pCh->speed = CBR_2400; break;
  2171. case B4800: pCh->speed = CBR_4800; break;
  2172. case B9600: pCh->speed = CBR_9600; break;
  2173. case B19200: pCh->speed = CBR_19200; break;
  2174. case B57600: pCh->speed = CBR_57600; break;
  2175. case B115200: pCh->speed = CBR_115200; break;
  2176. case B153600: pCh->speed = CBR_153600; break;
  2177. case B230400: pCh->speed = CBR_230400; break;
  2178. case B307200: pCh->speed = CBR_307200; break;
  2179. case B460800: pCh->speed = CBR_460800; break;
  2180. case B921600: pCh->speed = CBR_921600; break;
  2181. default: pCh->speed = CBR_9600; break;
  2182. }
  2183. if ( pCh->speed == CBR_C1 ) {
  2184. // Process the custom speed parameters.
  2185. int bps = pCh->BaudBase / pCh->BaudDivisor;
  2186. if ( bps == 921600 ) {
  2187. pCh->speed = CBR_921600;
  2188. } else {
  2189. bps = bps/10;
  2190. i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_BAUD_DEF1(bps) );
  2191. }
  2192. }
  2193. i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_SETBAUD(pCh->speed));
  2194. i2QueueCommands ( PTYPE_INLINE, pCh, 100, 2, CMD_DTRUP, CMD_RTSUP);
  2195. pCh->dataSetOut |= (I2_DTR | I2_RTS);
  2196. }
  2197. if ( (CSTOPB & cflag) ^ (CSTOPB & o_tios->c_cflag))
  2198. {
  2199. i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1,
  2200. CMD_SETSTOP( ( cflag & CSTOPB ) ? CST_2 : CST_1));
  2201. }
  2202. if (((PARENB|PARODD) & cflag) ^ ((PARENB|PARODD) & o_tios->c_cflag))
  2203. {
  2204. i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1,
  2205. CMD_SETPAR(
  2206. (cflag & PARENB ? (cflag & PARODD ? CSP_OD : CSP_EV) : CSP_NP)
  2207. )
  2208. );
  2209. }
  2210. /* byte size and parity */
  2211. if ( (CSIZE & cflag)^(CSIZE & o_tios->c_cflag))
  2212. {
  2213. int datasize;
  2214. switch ( cflag & CSIZE ) {
  2215. case CS5: datasize = CSZ_5; break;
  2216. case CS6: datasize = CSZ_6; break;
  2217. case CS7: datasize = CSZ_7; break;
  2218. case CS8: datasize = CSZ_8; break;
  2219. default: datasize = CSZ_5; break; /* as per serial.c */
  2220. }
  2221. i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1, CMD_SETBITS(datasize) );
  2222. }
  2223. /* Process CTS flow control flag setting */
  2224. if ( (cflag & CRTSCTS) ) {
  2225. i2QueueCommands(PTYPE_INLINE, pCh, 100,
  2226. 2, CMD_CTSFL_ENAB, CMD_RTSFL_ENAB);
  2227. } else {
  2228. i2QueueCommands(PTYPE_INLINE, pCh, 100,
  2229. 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
  2230. }
  2231. //
  2232. // Process XON/XOFF flow control flags settings
  2233. //
  2234. stop_char = STOP_CHAR(pCh->pTTY);
  2235. start_char = START_CHAR(pCh->pTTY);
  2236. //////////// can't be \000
  2237. if (stop_char == __DISABLED_CHAR )
  2238. {
  2239. stop_char = ~__DISABLED_CHAR;
  2240. }
  2241. if (start_char == __DISABLED_CHAR )
  2242. {
  2243. start_char = ~__DISABLED_CHAR;
  2244. }
  2245. /////////////////////////////////
  2246. if ( o_tios->c_cc[VSTART] != start_char )
  2247. {
  2248. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DEF_IXON(start_char));
  2249. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DEF_OXON(start_char));
  2250. }
  2251. if ( o_tios->c_cc[VSTOP] != stop_char )
  2252. {
  2253. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DEF_IXOFF(stop_char));
  2254. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DEF_OXOFF(stop_char));
  2255. }
  2256. if (stop_char == __DISABLED_CHAR )
  2257. {
  2258. stop_char = ~__DISABLED_CHAR; //TEST123
  2259. goto no_xoff;
  2260. }
  2261. if ((iflag & (IXOFF))^(o_tios->c_iflag & (IXOFF)))
  2262. {
  2263. if ( iflag & IXOFF ) { // Enable XOFF output flow control
  2264. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_OXON_OPT(COX_XON));
  2265. } else { // Disable XOFF output flow control
  2266. no_xoff:
  2267. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_OXON_OPT(COX_NONE));
  2268. }
  2269. }
  2270. if (start_char == __DISABLED_CHAR )
  2271. {
  2272. goto no_xon;
  2273. }
  2274. if ((iflag & (IXON|IXANY)) ^ (o_tios->c_iflag & (IXON|IXANY)))
  2275. {
  2276. if ( iflag & IXON ) {
  2277. if ( iflag & IXANY ) { // Enable XON/XANY output flow control
  2278. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_XANY));
  2279. } else { // Enable XON output flow control
  2280. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_XON));
  2281. }
  2282. } else { // Disable XON output flow control
  2283. no_xon:
  2284. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_NONE));
  2285. }
  2286. }
  2287. if ( (iflag & ISTRIP) ^ ( o_tios->c_iflag & (ISTRIP)) )
  2288. {
  2289. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
  2290. CMD_ISTRIP_OPT((iflag & ISTRIP ? 1 : 0)));
  2291. }
  2292. if ( (iflag & INPCK) ^ ( o_tios->c_iflag & (INPCK)) )
  2293. {
  2294. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
  2295. CMD_PARCHK((iflag & INPCK) ? CPK_ENAB : CPK_DSAB));
  2296. }
  2297. if ( (iflag & (IGNBRK|PARMRK|BRKINT|IGNPAR))
  2298. ^ ( o_tios->c_iflag & (IGNBRK|PARMRK|BRKINT|IGNPAR)) )
  2299. {
  2300. char brkrpt = 0;
  2301. char parrpt = 0;
  2302. if ( iflag & IGNBRK ) { /* Ignore breaks altogether */
  2303. /* Ignore breaks altogether */
  2304. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_BRK_NREP);
  2305. } else {
  2306. if ( iflag & BRKINT ) {
  2307. if ( iflag & PARMRK ) {
  2308. brkrpt = 0x0a; // exception an inline triple
  2309. } else {
  2310. brkrpt = 0x1a; // exception and NULL
  2311. }
  2312. brkrpt |= 0x04; // flush input
  2313. } else {
  2314. if ( iflag & PARMRK ) {
  2315. brkrpt = 0x0b; //POSIX triple \0377 \0 \0
  2316. } else {
  2317. brkrpt = 0x01; // Null only
  2318. }
  2319. }
  2320. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_BRK_REP(brkrpt));
  2321. }
  2322. if (iflag & IGNPAR) {
  2323. parrpt = 0x20;
  2324. /* would be 2 for not cirrus bug */
  2325. /* would be 0x20 cept for cirrus bug */
  2326. } else {
  2327. if ( iflag & PARMRK ) {
  2328. /*
  2329. * Replace error characters with 3-byte sequence (\0377,\0,char)
  2330. */
  2331. parrpt = 0x04 ;
  2332. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_ISTRIP_OPT((char)0));
  2333. } else {
  2334. parrpt = 0x03;
  2335. }
  2336. }
  2337. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_SET_ERROR(parrpt));
  2338. }
  2339. if (cflag & CLOCAL) {
  2340. // Status reporting fails for DCD if this is off
  2341. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DCD_NREP);
  2342. pCh->flags &= ~ASYNC_CHECK_CD;
  2343. } else {
  2344. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DCD_REP);
  2345. pCh->flags |= ASYNC_CHECK_CD;
  2346. }
  2347. service_it:
  2348. i2DrainOutput( pCh, 100 );
  2349. }
  2350. /******************************************************************************/
  2351. /* IPL Device Section */
  2352. /******************************************************************************/
  2353. /******************************************************************************/
  2354. /* Function: ip2_ipl_read() */
  2355. /* Parameters: Pointer to device inode */
  2356. /* Pointer to file structure */
  2357. /* Pointer to data */
  2358. /* Number of bytes to read */
  2359. /* Returns: Success or failure */
  2360. /* */
  2361. /* Description: Ugly */
  2362. /* */
  2363. /* */
  2364. /******************************************************************************/
  2365. static
  2366. ssize_t
  2367. ip2_ipl_read(struct file *pFile, char __user *pData, size_t count, loff_t *off )
  2368. {
  2369. unsigned int minor = iminor(pFile->f_path.dentry->d_inode);
  2370. int rc = 0;
  2371. #ifdef IP2DEBUG_IPL
  2372. printk (KERN_DEBUG "IP2IPL: read %p, %d bytes\n", pData, count );
  2373. #endif
  2374. switch( minor ) {
  2375. case 0: // IPL device
  2376. rc = -EINVAL;
  2377. break;
  2378. case 1: // Status dump
  2379. rc = -EINVAL;
  2380. break;
  2381. case 2: // Ping device
  2382. rc = -EINVAL;
  2383. break;
  2384. case 3: // Trace device
  2385. rc = DumpTraceBuffer ( pData, count );
  2386. break;
  2387. case 4: // Trace device
  2388. rc = DumpFifoBuffer ( pData, count );
  2389. break;
  2390. default:
  2391. rc = -ENODEV;
  2392. break;
  2393. }
  2394. return rc;
  2395. }
  2396. static int
  2397. DumpFifoBuffer ( char __user *pData, int count )
  2398. {
  2399. #ifdef DEBUG_FIFO
  2400. int rc;
  2401. rc = copy_to_user(pData, DBGBuf, count);
  2402. printk(KERN_DEBUG "Last index %d\n", I );
  2403. return count;
  2404. #endif /* DEBUG_FIFO */
  2405. return 0;
  2406. }
  2407. static int
  2408. DumpTraceBuffer ( char __user *pData, int count )
  2409. {
  2410. #ifdef IP2DEBUG_TRACE
  2411. int rc;
  2412. int dumpcount;
  2413. int chunk;
  2414. int *pIndex = (int __user *)pData;
  2415. if ( count < (sizeof(int) * 6) ) {
  2416. return -EIO;
  2417. }
  2418. rc = put_user(tracewrap, pIndex );
  2419. rc = put_user(TRACEMAX, ++pIndex );
  2420. rc = put_user(tracestrip, ++pIndex );
  2421. rc = put_user(tracestuff, ++pIndex );
  2422. pData += sizeof(int) * 6;
  2423. count -= sizeof(int) * 6;
  2424. dumpcount = tracestuff - tracestrip;
  2425. if ( dumpcount < 0 ) {
  2426. dumpcount += TRACEMAX;
  2427. }
  2428. if ( dumpcount > count ) {
  2429. dumpcount = count;
  2430. }
  2431. chunk = TRACEMAX - tracestrip;
  2432. if ( dumpcount > chunk ) {
  2433. rc = copy_to_user(pData, &tracebuf[tracestrip],
  2434. chunk * sizeof(tracebuf[0]) );
  2435. pData += chunk * sizeof(tracebuf[0]);
  2436. tracestrip = 0;
  2437. chunk = dumpcount - chunk;
  2438. } else {
  2439. chunk = dumpcount;
  2440. }
  2441. rc = copy_to_user(pData, &tracebuf[tracestrip],
  2442. chunk * sizeof(tracebuf[0]) );
  2443. tracestrip += chunk;
  2444. tracewrap = 0;
  2445. rc = put_user(tracestrip, ++pIndex );
  2446. rc = put_user(tracestuff, ++pIndex );
  2447. return dumpcount;
  2448. #else
  2449. return 0;
  2450. #endif
  2451. }
  2452. /******************************************************************************/
  2453. /* Function: ip2_ipl_write() */
  2454. /* Parameters: */
  2455. /* Pointer to file structure */
  2456. /* Pointer to data */
  2457. /* Number of bytes to write */
  2458. /* Returns: Success or failure */
  2459. /* */
  2460. /* Description: */
  2461. /* */
  2462. /* */
  2463. /******************************************************************************/
  2464. static ssize_t
  2465. ip2_ipl_write(struct file *pFile, const char __user *pData, size_t count, loff_t *off)
  2466. {
  2467. #ifdef IP2DEBUG_IPL
  2468. printk (KERN_DEBUG "IP2IPL: write %p, %d bytes\n", pData, count );
  2469. #endif
  2470. return 0;
  2471. }
  2472. /******************************************************************************/
  2473. /* Function: ip2_ipl_ioctl() */
  2474. /* Parameters: Pointer to device inode */
  2475. /* Pointer to file structure */
  2476. /* Command */
  2477. /* Argument */
  2478. /* Returns: Success or failure */
  2479. /* */
  2480. /* Description: */
  2481. /* */
  2482. /* */
  2483. /******************************************************************************/
  2484. static int
  2485. ip2_ipl_ioctl ( struct inode *pInode, struct file *pFile, UINT cmd, ULONG arg )
  2486. {
  2487. unsigned int iplminor = iminor(pInode);
  2488. int rc = 0;
  2489. void __user *argp = (void __user *)arg;
  2490. ULONG __user *pIndex = argp;
  2491. i2eBordStrPtr pB = i2BoardPtrTable[iplminor / 4];
  2492. i2ChanStrPtr pCh;
  2493. #ifdef IP2DEBUG_IPL
  2494. printk (KERN_DEBUG "IP2IPL: ioctl cmd %d, arg %ld\n", cmd, arg );
  2495. #endif
  2496. switch ( iplminor ) {
  2497. case 0: // IPL device
  2498. rc = -EINVAL;
  2499. break;
  2500. case 1: // Status dump
  2501. case 5:
  2502. case 9:
  2503. case 13:
  2504. switch ( cmd ) {
  2505. case 64: /* Driver - ip2stat */
  2506. rc = put_user(ip2_tty_driver->refcount, pIndex++ );
  2507. rc = put_user(irq_counter, pIndex++ );
  2508. rc = put_user(bh_counter, pIndex++ );
  2509. break;
  2510. case 65: /* Board - ip2stat */
  2511. if ( pB ) {
  2512. rc = copy_to_user(argp, pB, sizeof(i2eBordStr));
  2513. rc = put_user(INB(pB->i2eStatus),
  2514. (ULONG __user *)(arg + (ULONG)(&pB->i2eStatus) - (ULONG)pB ) );
  2515. } else {
  2516. rc = -ENODEV;
  2517. }
  2518. break;
  2519. default:
  2520. if (cmd < IP2_MAX_PORTS) {
  2521. pCh = DevTable[cmd];
  2522. if ( pCh )
  2523. {
  2524. rc = copy_to_user(argp, pCh, sizeof(i2ChanStr));
  2525. } else {
  2526. rc = -ENODEV;
  2527. }
  2528. } else {
  2529. rc = -EINVAL;
  2530. }
  2531. }
  2532. break;
  2533. case 2: // Ping device
  2534. rc = -EINVAL;
  2535. break;
  2536. case 3: // Trace device
  2537. /*
  2538. * akpm: This used to write a whole bunch of function addresses
  2539. * to userspace, which generated lots of put_user() warnings.
  2540. * I killed it all. Just return "success" and don't do
  2541. * anything.
  2542. */
  2543. if (cmd == 1)
  2544. rc = 0;
  2545. else
  2546. rc = -EINVAL;
  2547. break;
  2548. default:
  2549. rc = -ENODEV;
  2550. break;
  2551. }
  2552. return rc;
  2553. }
  2554. /******************************************************************************/
  2555. /* Function: ip2_ipl_open() */
  2556. /* Parameters: Pointer to device inode */
  2557. /* Pointer to file structure */
  2558. /* Returns: Success or failure */
  2559. /* */
  2560. /* Description: */
  2561. /* */
  2562. /* */
  2563. /******************************************************************************/
  2564. static int
  2565. ip2_ipl_open( struct inode *pInode, struct file *pFile )
  2566. {
  2567. unsigned int iplminor = iminor(pInode);
  2568. i2eBordStrPtr pB;
  2569. i2ChanStrPtr pCh;
  2570. #ifdef IP2DEBUG_IPL
  2571. printk (KERN_DEBUG "IP2IPL: open\n" );
  2572. #endif
  2573. switch(iplminor) {
  2574. // These are the IPL devices
  2575. case 0:
  2576. case 4:
  2577. case 8:
  2578. case 12:
  2579. break;
  2580. // These are the status devices
  2581. case 1:
  2582. case 5:
  2583. case 9:
  2584. case 13:
  2585. break;
  2586. // These are the debug devices
  2587. case 2:
  2588. case 6:
  2589. case 10:
  2590. case 14:
  2591. pB = i2BoardPtrTable[iplminor / 4];
  2592. pCh = (i2ChanStrPtr) pB->i2eChannelPtr;
  2593. break;
  2594. // This is the trace device
  2595. case 3:
  2596. break;
  2597. }
  2598. return 0;
  2599. }
  2600. /******************************************************************************/
  2601. /* Function: ip2_read_procmem */
  2602. /* Parameters: */
  2603. /* */
  2604. /* Returns: Length of output */
  2605. /* */
  2606. /* Description: */
  2607. /* Supplies some driver operating parameters */
  2608. /* Not real useful unless your debugging the fifo */
  2609. /* */
  2610. /******************************************************************************/
  2611. #define LIMIT (PAGE_SIZE - 120)
  2612. static int
  2613. ip2_read_procmem(char *buf, char **start, off_t offset, int len)
  2614. {
  2615. i2eBordStrPtr pB;
  2616. i2ChanStrPtr pCh;
  2617. PTTY tty;
  2618. int i;
  2619. len = 0;
  2620. #define FMTLINE "%3d: 0x%08x 0x%08x 0%011o 0%011o\n"
  2621. #define FMTLIN2 " 0x%04x 0x%04x tx flow 0x%x\n"
  2622. #define FMTLIN3 " 0x%04x 0x%04x rc flow\n"
  2623. len += sprintf(buf+len,"\n");
  2624. for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  2625. pB = i2BoardPtrTable[i];
  2626. if ( pB ) {
  2627. len += sprintf(buf+len,"board %d:\n",i);
  2628. len += sprintf(buf+len,"\tFifo rem: %d mty: %x outM %x\n",
  2629. pB->i2eFifoRemains,pB->i2eWaitingForEmptyFifo,pB->i2eOutMailWaiting);
  2630. }
  2631. }
  2632. len += sprintf(buf+len,"#: tty flags, port flags, cflags, iflags\n");
  2633. for (i=0; i < IP2_MAX_PORTS; i++) {
  2634. if (len > LIMIT)
  2635. break;
  2636. pCh = DevTable[i];
  2637. if (pCh) {
  2638. tty = pCh->pTTY;
  2639. if (tty && tty->count) {
  2640. len += sprintf(buf+len,FMTLINE,i,(int)tty->flags,pCh->flags,
  2641. tty->termios->c_cflag,tty->termios->c_iflag);
  2642. len += sprintf(buf+len,FMTLIN2,
  2643. pCh->outfl.asof,pCh->outfl.room,pCh->channelNeeds);
  2644. len += sprintf(buf+len,FMTLIN3,pCh->infl.asof,pCh->infl.room);
  2645. }
  2646. }
  2647. }
  2648. return len;
  2649. }
  2650. /*
  2651. * This is the handler for /proc/tty/driver/ip2
  2652. *
  2653. * This stretch of code has been largely plagerized from at least three
  2654. * different sources including ip2mkdev.c and a couple of other drivers.
  2655. * The bugs are all mine. :-) =mhw=
  2656. */
  2657. static int ip2_read_proc(char *page, char **start, off_t off,
  2658. int count, int *eof, void *data)
  2659. {
  2660. int i, j, box;
  2661. int len = 0;
  2662. int boxes = 0;
  2663. int ports = 0;
  2664. int tports = 0;
  2665. off_t begin = 0;
  2666. i2eBordStrPtr pB;
  2667. len += sprintf(page, "ip2info: 1.0 driver: %s\n", pcVersion );
  2668. len += sprintf(page+len, "Driver: SMajor=%d CMajor=%d IMajor=%d MaxBoards=%d MaxBoxes=%d MaxPorts=%d\n",
  2669. IP2_TTY_MAJOR, IP2_CALLOUT_MAJOR, IP2_IPL_MAJOR,
  2670. IP2_MAX_BOARDS, ABS_MAX_BOXES, ABS_BIGGEST_BOX);
  2671. for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  2672. /* This need to be reset for a board by board count... */
  2673. boxes = 0;
  2674. pB = i2BoardPtrTable[i];
  2675. if( pB ) {
  2676. switch( pB->i2ePom.e.porID & ~POR_ID_RESERVED )
  2677. {
  2678. case POR_ID_FIIEX:
  2679. len += sprintf( page+len, "Board %d: EX ports=", i );
  2680. for( box = 0; box < ABS_MAX_BOXES; ++box )
  2681. {
  2682. ports = 0;
  2683. if( pB->i2eChannelMap[box] != 0 ) ++boxes;
  2684. for( j = 0; j < ABS_BIGGEST_BOX; ++j )
  2685. {
  2686. if( pB->i2eChannelMap[box] & 1<< j ) {
  2687. ++ports;
  2688. }
  2689. }
  2690. len += sprintf( page+len, "%d,", ports );
  2691. tports += ports;
  2692. }
  2693. --len; /* Backup over that last comma */
  2694. len += sprintf( page+len, " boxes=%d width=%d", boxes, pB->i2eDataWidth16 ? 16 : 8 );
  2695. break;
  2696. case POR_ID_II_4:
  2697. len += sprintf(page+len, "Board %d: ISA-4 ports=4 boxes=1", i );
  2698. tports = ports = 4;
  2699. break;
  2700. case POR_ID_II_8:
  2701. len += sprintf(page+len, "Board %d: ISA-8-std ports=8 boxes=1", i );
  2702. tports = ports = 8;
  2703. break;
  2704. case POR_ID_II_8R:
  2705. len += sprintf(page+len, "Board %d: ISA-8-RJ11 ports=8 boxes=1", i );
  2706. tports = ports = 8;
  2707. break;
  2708. default:
  2709. len += sprintf(page+len, "Board %d: unknown", i );
  2710. /* Don't try and probe for minor numbers */
  2711. tports = ports = 0;
  2712. }
  2713. } else {
  2714. /* Don't try and probe for minor numbers */
  2715. len += sprintf(page+len, "Board %d: vacant", i );
  2716. tports = ports = 0;
  2717. }
  2718. if( tports ) {
  2719. len += sprintf(page+len, " minors=" );
  2720. for ( box = 0; box < ABS_MAX_BOXES; ++box )
  2721. {
  2722. for ( j = 0; j < ABS_BIGGEST_BOX; ++j )
  2723. {
  2724. if ( pB->i2eChannelMap[box] & (1 << j) )
  2725. {
  2726. len += sprintf (page+len,"%d,",
  2727. j + ABS_BIGGEST_BOX *
  2728. (box+i*ABS_MAX_BOXES));
  2729. }
  2730. }
  2731. }
  2732. page[ len - 1 ] = '\n'; /* Overwrite that last comma */
  2733. } else {
  2734. len += sprintf (page+len,"\n" );
  2735. }
  2736. if (len+begin > off+count)
  2737. break;
  2738. if (len+begin < off) {
  2739. begin += len;
  2740. len = 0;
  2741. }
  2742. }
  2743. if (i >= IP2_MAX_BOARDS)
  2744. *eof = 1;
  2745. if (off >= len+begin)
  2746. return 0;
  2747. *start = page + (off-begin);
  2748. return ((count < begin+len-off) ? count : begin+len-off);
  2749. }
  2750. /******************************************************************************/
  2751. /* Function: ip2trace() */
  2752. /* Parameters: Value to add to trace buffer */
  2753. /* Returns: Nothing */
  2754. /* */
  2755. /* Description: */
  2756. /* */
  2757. /* */
  2758. /******************************************************************************/
  2759. #ifdef IP2DEBUG_TRACE
  2760. void
  2761. ip2trace (unsigned short pn, unsigned char cat, unsigned char label, unsigned long codes, ...)
  2762. {
  2763. long flags;
  2764. unsigned long *pCode = &codes;
  2765. union ip2breadcrumb bc;
  2766. i2ChanStrPtr pCh;
  2767. tracebuf[tracestuff++] = jiffies;
  2768. if ( tracestuff == TRACEMAX ) {
  2769. tracestuff = 0;
  2770. }
  2771. if ( tracestuff == tracestrip ) {
  2772. if ( ++tracestrip == TRACEMAX ) {
  2773. tracestrip = 0;
  2774. }
  2775. ++tracewrap;
  2776. }
  2777. bc.hdr.port = 0xff & pn;
  2778. bc.hdr.cat = cat;
  2779. bc.hdr.codes = (unsigned char)( codes & 0xff );
  2780. bc.hdr.label = label;
  2781. tracebuf[tracestuff++] = bc.value;
  2782. for (;;) {
  2783. if ( tracestuff == TRACEMAX ) {
  2784. tracestuff = 0;
  2785. }
  2786. if ( tracestuff == tracestrip ) {
  2787. if ( ++tracestrip == TRACEMAX ) {
  2788. tracestrip = 0;
  2789. }
  2790. ++tracewrap;
  2791. }
  2792. if ( !codes-- )
  2793. break;
  2794. tracebuf[tracestuff++] = *++pCode;
  2795. }
  2796. }
  2797. #endif
  2798. MODULE_LICENSE("GPL");
  2799. static struct pci_device_id ip2main_pci_tbl[] __devinitdata = {
  2800. { PCI_DEVICE(PCI_VENDOR_ID_COMPUTONE, PCI_DEVICE_ID_COMPUTONE_IP2EX) },
  2801. { }
  2802. };
  2803. MODULE_DEVICE_TABLE(pci, ip2main_pci_tbl);