ip2main.c 101 KB

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