ip2main.c 101 KB

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