ip2main.c 104 KB

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