ip2main.c 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219
  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. tty_unlock();
  1306. schedule();
  1307. tty_lock();
  1308. }
  1309. if ( tty_hung_up_p(pFile) ) {
  1310. set_current_state( TASK_RUNNING );
  1311. remove_wait_queue(&pCh->close_wait, &wait);
  1312. return( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS;
  1313. }
  1314. }
  1315. set_current_state( TASK_RUNNING );
  1316. remove_wait_queue(&pCh->close_wait, &wait);
  1317. /*
  1318. * 3. Handle a non-blocking open of a normal port.
  1319. */
  1320. if ( (pFile->f_flags & O_NONBLOCK) || (tty->flags & (1<<TTY_IO_ERROR) )) {
  1321. pCh->flags |= ASYNC_NORMAL_ACTIVE;
  1322. goto noblock;
  1323. }
  1324. /*
  1325. * 4. Now loop waiting for the port to be free and carrier present
  1326. * (if required).
  1327. */
  1328. if ( tty->termios->c_cflag & CLOCAL )
  1329. do_clocal = 1;
  1330. #ifdef IP2DEBUG_OPEN
  1331. printk(KERN_DEBUG "OpenBlock: do_clocal = %d\n", do_clocal);
  1332. #endif
  1333. ++pCh->wopen;
  1334. init_waitqueue_entry(&wait, current);
  1335. add_wait_queue(&pCh->open_wait, &wait);
  1336. for(;;) {
  1337. i2QueueCommands(PTYPE_INLINE, pCh, 100, 2, CMD_DTRUP, CMD_RTSUP);
  1338. pCh->dataSetOut |= (I2_DTR | I2_RTS);
  1339. set_current_state( TASK_INTERRUPTIBLE );
  1340. serviceOutgoingFifo( pCh->pMyBord );
  1341. if ( tty_hung_up_p(pFile) ) {
  1342. set_current_state( TASK_RUNNING );
  1343. remove_wait_queue(&pCh->open_wait, &wait);
  1344. return ( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EBUSY : -ERESTARTSYS;
  1345. }
  1346. if (!(pCh->flags & ASYNC_CLOSING) &&
  1347. (do_clocal || (pCh->dataSetIn & I2_DCD) )) {
  1348. rc = 0;
  1349. break;
  1350. }
  1351. #ifdef IP2DEBUG_OPEN
  1352. printk(KERN_DEBUG "ASYNC_CLOSING = %s\n",
  1353. (pCh->flags & ASYNC_CLOSING)?"True":"False");
  1354. printk(KERN_DEBUG "OpenBlock: waiting for CD or signal\n");
  1355. #endif
  1356. ip2trace (CHANN, ITRC_OPEN, 3, 2, 0,
  1357. (pCh->flags & ASYNC_CLOSING) );
  1358. /* check for signal */
  1359. if (signal_pending(current)) {
  1360. rc = (( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS);
  1361. break;
  1362. }
  1363. tty_unlock();
  1364. schedule();
  1365. tty_lock();
  1366. }
  1367. set_current_state( TASK_RUNNING );
  1368. remove_wait_queue(&pCh->open_wait, &wait);
  1369. --pCh->wopen; //why count?
  1370. ip2trace (CHANN, ITRC_OPEN, 4, 0 );
  1371. if (rc != 0 ) {
  1372. return rc;
  1373. }
  1374. pCh->flags |= ASYNC_NORMAL_ACTIVE;
  1375. noblock:
  1376. /* first open - Assign termios structure to port */
  1377. if ( tty->count == 1 ) {
  1378. i2QueueCommands(PTYPE_INLINE, pCh, 0, 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
  1379. /* Now we must send the termios settings to the loadware */
  1380. set_params( pCh, NULL );
  1381. }
  1382. /*
  1383. * Now set any i2lib options. These may go away if the i2lib code ends
  1384. * up rolled into the mainline.
  1385. */
  1386. pCh->channelOptions |= CO_NBLOCK_WRITE;
  1387. #ifdef IP2DEBUG_OPEN
  1388. printk (KERN_DEBUG "IP2: open completed\n" );
  1389. #endif
  1390. serviceOutgoingFifo( pCh->pMyBord );
  1391. ip2trace (CHANN, ITRC_OPEN, ITRC_RETURN, 0 );
  1392. return 0;
  1393. }
  1394. /******************************************************************************/
  1395. /* Function: ip2_close() */
  1396. /* Parameters: Pointer to tty structure */
  1397. /* Pointer to file structure */
  1398. /* Returns: Nothing */
  1399. /* */
  1400. /* Description: */
  1401. /* */
  1402. /* */
  1403. /******************************************************************************/
  1404. static void
  1405. ip2_close( PTTY tty, struct file *pFile )
  1406. {
  1407. i2ChanStrPtr pCh = tty->driver_data;
  1408. if ( !pCh ) {
  1409. return;
  1410. }
  1411. ip2trace (CHANN, ITRC_CLOSE, ITRC_ENTER, 0 );
  1412. #ifdef IP2DEBUG_OPEN
  1413. printk(KERN_DEBUG "IP2:close %s:\n",tty->name);
  1414. #endif
  1415. if ( tty_hung_up_p ( pFile ) ) {
  1416. ip2trace (CHANN, ITRC_CLOSE, 2, 1, 2 );
  1417. return;
  1418. }
  1419. if ( tty->count > 1 ) { /* not the last close */
  1420. ip2trace (CHANN, ITRC_CLOSE, 2, 1, 3 );
  1421. return;
  1422. }
  1423. pCh->flags |= ASYNC_CLOSING; // last close actually
  1424. tty->closing = 1;
  1425. if (pCh->ClosingWaitTime != ASYNC_CLOSING_WAIT_NONE) {
  1426. /*
  1427. * Before we drop DTR, make sure the transmitter has completely drained.
  1428. * This uses an timeout, after which the close
  1429. * completes.
  1430. */
  1431. ip2_wait_until_sent(tty, pCh->ClosingWaitTime );
  1432. }
  1433. /*
  1434. * At this point we stop accepting input. Here we flush the channel
  1435. * input buffer which will allow the board to send up more data. Any
  1436. * additional input is tossed at interrupt/poll time.
  1437. */
  1438. i2InputFlush( pCh );
  1439. /* disable DSS reporting */
  1440. i2QueueCommands(PTYPE_INLINE, pCh, 100, 4,
  1441. CMD_DCD_NREP, CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
  1442. if (tty->termios->c_cflag & HUPCL) {
  1443. i2QueueCommands(PTYPE_INLINE, pCh, 100, 2, CMD_RTSDN, CMD_DTRDN);
  1444. pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
  1445. i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
  1446. }
  1447. serviceOutgoingFifo ( pCh->pMyBord );
  1448. tty_ldisc_flush(tty);
  1449. tty_driver_flush_buffer(tty);
  1450. tty->closing = 0;
  1451. pCh->pTTY = NULL;
  1452. if (pCh->wopen) {
  1453. if (pCh->ClosingDelay) {
  1454. msleep_interruptible(jiffies_to_msecs(pCh->ClosingDelay));
  1455. }
  1456. wake_up_interruptible(&pCh->open_wait);
  1457. }
  1458. pCh->flags &=~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  1459. wake_up_interruptible(&pCh->close_wait);
  1460. #ifdef IP2DEBUG_OPEN
  1461. DBG_CNT("ip2_close: after wakeups--");
  1462. #endif
  1463. ip2trace (CHANN, ITRC_CLOSE, ITRC_RETURN, 1, 1 );
  1464. return;
  1465. }
  1466. /******************************************************************************/
  1467. /* Function: ip2_hangup() */
  1468. /* Parameters: Pointer to tty structure */
  1469. /* Returns: Nothing */
  1470. /* */
  1471. /* Description: */
  1472. /* */
  1473. /* */
  1474. /******************************************************************************/
  1475. static void
  1476. ip2_hangup ( PTTY tty )
  1477. {
  1478. i2ChanStrPtr pCh = tty->driver_data;
  1479. if( !pCh ) {
  1480. return;
  1481. }
  1482. ip2trace (CHANN, ITRC_HANGUP, ITRC_ENTER, 0 );
  1483. ip2_flush_buffer(tty);
  1484. /* disable DSS reporting */
  1485. i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_DCD_NREP);
  1486. i2QueueCommands(PTYPE_INLINE, pCh, 0, 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
  1487. if ( (tty->termios->c_cflag & HUPCL) ) {
  1488. i2QueueCommands(PTYPE_BYPASS, pCh, 0, 2, CMD_RTSDN, CMD_DTRDN);
  1489. pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
  1490. i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
  1491. }
  1492. i2QueueCommands(PTYPE_INLINE, pCh, 1, 3,
  1493. CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
  1494. serviceOutgoingFifo ( pCh->pMyBord );
  1495. wake_up_interruptible ( &pCh->delta_msr_wait );
  1496. pCh->flags &= ~ASYNC_NORMAL_ACTIVE;
  1497. pCh->pTTY = NULL;
  1498. wake_up_interruptible ( &pCh->open_wait );
  1499. ip2trace (CHANN, ITRC_HANGUP, ITRC_RETURN, 0 );
  1500. }
  1501. /******************************************************************************/
  1502. /******************************************************************************/
  1503. /* Device Output Section */
  1504. /******************************************************************************/
  1505. /******************************************************************************/
  1506. /******************************************************************************/
  1507. /* Function: ip2_write() */
  1508. /* Parameters: Pointer to tty structure */
  1509. /* Flag denoting data is in user (1) or kernel (0) space */
  1510. /* Pointer to data */
  1511. /* Number of bytes to write */
  1512. /* Returns: Number of bytes actually written */
  1513. /* */
  1514. /* Description: (MANDATORY) */
  1515. /* */
  1516. /* */
  1517. /******************************************************************************/
  1518. static int
  1519. ip2_write( PTTY tty, const unsigned char *pData, int count)
  1520. {
  1521. i2ChanStrPtr pCh = tty->driver_data;
  1522. int bytesSent = 0;
  1523. unsigned long flags;
  1524. ip2trace (CHANN, ITRC_WRITE, ITRC_ENTER, 2, count, -1 );
  1525. /* Flush out any buffered data left over from ip2_putchar() calls. */
  1526. ip2_flush_chars( tty );
  1527. /* This is the actual move bit. Make sure it does what we need!!!!! */
  1528. write_lock_irqsave(&pCh->Pbuf_spinlock, flags);
  1529. bytesSent = i2Output( pCh, pData, count);
  1530. write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
  1531. ip2trace (CHANN, ITRC_WRITE, ITRC_RETURN, 1, bytesSent );
  1532. return bytesSent > 0 ? bytesSent : 0;
  1533. }
  1534. /******************************************************************************/
  1535. /* Function: ip2_putchar() */
  1536. /* Parameters: Pointer to tty structure */
  1537. /* Character to write */
  1538. /* Returns: Nothing */
  1539. /* */
  1540. /* Description: */
  1541. /* */
  1542. /* */
  1543. /******************************************************************************/
  1544. static int
  1545. ip2_putchar( PTTY tty, unsigned char ch )
  1546. {
  1547. i2ChanStrPtr pCh = tty->driver_data;
  1548. unsigned long flags;
  1549. // ip2trace (CHANN, ITRC_PUTC, ITRC_ENTER, 1, ch );
  1550. write_lock_irqsave(&pCh->Pbuf_spinlock, flags);
  1551. pCh->Pbuf[pCh->Pbuf_stuff++] = ch;
  1552. if ( pCh->Pbuf_stuff == sizeof pCh->Pbuf ) {
  1553. write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
  1554. ip2_flush_chars( tty );
  1555. } else
  1556. write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
  1557. return 1;
  1558. // ip2trace (CHANN, ITRC_PUTC, ITRC_RETURN, 1, ch );
  1559. }
  1560. /******************************************************************************/
  1561. /* Function: ip2_flush_chars() */
  1562. /* Parameters: Pointer to tty structure */
  1563. /* Returns: Nothing */
  1564. /* */
  1565. /* Description: */
  1566. /* */
  1567. /******************************************************************************/
  1568. static void
  1569. ip2_flush_chars( PTTY tty )
  1570. {
  1571. int strip;
  1572. i2ChanStrPtr pCh = tty->driver_data;
  1573. unsigned long flags;
  1574. write_lock_irqsave(&pCh->Pbuf_spinlock, flags);
  1575. if ( pCh->Pbuf_stuff ) {
  1576. // ip2trace (CHANN, ITRC_PUTC, 10, 1, strip );
  1577. //
  1578. // We may need to restart i2Output if it does not fullfill this request
  1579. //
  1580. strip = i2Output( pCh, pCh->Pbuf, pCh->Pbuf_stuff);
  1581. if ( strip != pCh->Pbuf_stuff ) {
  1582. memmove( pCh->Pbuf, &pCh->Pbuf[strip], pCh->Pbuf_stuff - strip );
  1583. }
  1584. pCh->Pbuf_stuff -= strip;
  1585. }
  1586. write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
  1587. }
  1588. /******************************************************************************/
  1589. /* Function: ip2_write_room() */
  1590. /* Parameters: Pointer to tty structure */
  1591. /* Returns: Number of bytes that the driver can accept */
  1592. /* */
  1593. /* Description: */
  1594. /* */
  1595. /******************************************************************************/
  1596. static int
  1597. ip2_write_room ( PTTY tty )
  1598. {
  1599. int bytesFree;
  1600. i2ChanStrPtr pCh = tty->driver_data;
  1601. unsigned long flags;
  1602. read_lock_irqsave(&pCh->Pbuf_spinlock, flags);
  1603. bytesFree = i2OutputFree( pCh ) - pCh->Pbuf_stuff;
  1604. read_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
  1605. ip2trace (CHANN, ITRC_WRITE, 11, 1, bytesFree );
  1606. return ((bytesFree > 0) ? bytesFree : 0);
  1607. }
  1608. /******************************************************************************/
  1609. /* Function: ip2_chars_in_buf() */
  1610. /* Parameters: Pointer to tty structure */
  1611. /* Returns: Number of bytes queued for transmission */
  1612. /* */
  1613. /* Description: */
  1614. /* */
  1615. /* */
  1616. /******************************************************************************/
  1617. static int
  1618. ip2_chars_in_buf ( PTTY tty )
  1619. {
  1620. i2ChanStrPtr pCh = tty->driver_data;
  1621. int rc;
  1622. unsigned long flags;
  1623. ip2trace (CHANN, ITRC_WRITE, 12, 1, pCh->Obuf_char_count + pCh->Pbuf_stuff );
  1624. #ifdef IP2DEBUG_WRITE
  1625. printk (KERN_DEBUG "IP2: chars in buffer = %d (%d,%d)\n",
  1626. pCh->Obuf_char_count + pCh->Pbuf_stuff,
  1627. pCh->Obuf_char_count, pCh->Pbuf_stuff );
  1628. #endif
  1629. read_lock_irqsave(&pCh->Obuf_spinlock, flags);
  1630. rc = pCh->Obuf_char_count;
  1631. read_unlock_irqrestore(&pCh->Obuf_spinlock, flags);
  1632. read_lock_irqsave(&pCh->Pbuf_spinlock, flags);
  1633. rc += pCh->Pbuf_stuff;
  1634. read_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
  1635. return rc;
  1636. }
  1637. /******************************************************************************/
  1638. /* Function: ip2_flush_buffer() */
  1639. /* Parameters: Pointer to tty structure */
  1640. /* Returns: Nothing */
  1641. /* */
  1642. /* Description: */
  1643. /* */
  1644. /* */
  1645. /******************************************************************************/
  1646. static void
  1647. ip2_flush_buffer( PTTY tty )
  1648. {
  1649. i2ChanStrPtr pCh = tty->driver_data;
  1650. unsigned long flags;
  1651. ip2trace (CHANN, ITRC_FLUSH, ITRC_ENTER, 0 );
  1652. #ifdef IP2DEBUG_WRITE
  1653. printk (KERN_DEBUG "IP2: flush buffer\n" );
  1654. #endif
  1655. write_lock_irqsave(&pCh->Pbuf_spinlock, flags);
  1656. pCh->Pbuf_stuff = 0;
  1657. write_unlock_irqrestore(&pCh->Pbuf_spinlock, flags);
  1658. i2FlushOutput( pCh );
  1659. ip2_owake(tty);
  1660. ip2trace (CHANN, ITRC_FLUSH, ITRC_RETURN, 0 );
  1661. }
  1662. /******************************************************************************/
  1663. /* Function: ip2_wait_until_sent() */
  1664. /* Parameters: Pointer to tty structure */
  1665. /* Timeout for wait. */
  1666. /* Returns: Nothing */
  1667. /* */
  1668. /* Description: */
  1669. /* This function is used in place of the normal tty_wait_until_sent, which */
  1670. /* only waits for the driver buffers to be empty (or rather, those buffers */
  1671. /* reported by chars_in_buffer) which doesn't work for IP2 due to the */
  1672. /* indeterminate number of bytes buffered on the board. */
  1673. /******************************************************************************/
  1674. static void
  1675. ip2_wait_until_sent ( PTTY tty, int timeout )
  1676. {
  1677. int i = jiffies;
  1678. i2ChanStrPtr pCh = tty->driver_data;
  1679. tty_wait_until_sent(tty, timeout );
  1680. if ( (i = timeout - (jiffies -i)) > 0)
  1681. i2DrainOutput( pCh, i );
  1682. }
  1683. /******************************************************************************/
  1684. /******************************************************************************/
  1685. /* Device Input Section */
  1686. /******************************************************************************/
  1687. /******************************************************************************/
  1688. /******************************************************************************/
  1689. /* Function: ip2_throttle() */
  1690. /* Parameters: Pointer to tty structure */
  1691. /* Returns: Nothing */
  1692. /* */
  1693. /* Description: */
  1694. /* */
  1695. /* */
  1696. /******************************************************************************/
  1697. static void
  1698. ip2_throttle ( PTTY tty )
  1699. {
  1700. i2ChanStrPtr pCh = tty->driver_data;
  1701. #ifdef IP2DEBUG_READ
  1702. printk (KERN_DEBUG "IP2: throttle\n" );
  1703. #endif
  1704. /*
  1705. * Signal the poll/interrupt handlers not to forward incoming data to
  1706. * the line discipline. This will cause the buffers to fill up in the
  1707. * library and thus cause the library routines to send the flow control
  1708. * stuff.
  1709. */
  1710. pCh->throttled = 1;
  1711. }
  1712. /******************************************************************************/
  1713. /* Function: ip2_unthrottle() */
  1714. /* Parameters: Pointer to tty structure */
  1715. /* Returns: Nothing */
  1716. /* */
  1717. /* Description: */
  1718. /* */
  1719. /* */
  1720. /******************************************************************************/
  1721. static void
  1722. ip2_unthrottle ( PTTY tty )
  1723. {
  1724. i2ChanStrPtr pCh = tty->driver_data;
  1725. unsigned long flags;
  1726. #ifdef IP2DEBUG_READ
  1727. printk (KERN_DEBUG "IP2: unthrottle\n" );
  1728. #endif
  1729. /* Pass incoming data up to the line discipline again. */
  1730. pCh->throttled = 0;
  1731. i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME);
  1732. serviceOutgoingFifo( pCh->pMyBord );
  1733. read_lock_irqsave(&pCh->Ibuf_spinlock, flags);
  1734. if ( pCh->Ibuf_stuff != pCh->Ibuf_strip ) {
  1735. read_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
  1736. #ifdef IP2DEBUG_READ
  1737. printk (KERN_DEBUG "i2Input called from unthrottle\n" );
  1738. #endif
  1739. i2Input( pCh );
  1740. } else
  1741. read_unlock_irqrestore(&pCh->Ibuf_spinlock, flags);
  1742. }
  1743. static void
  1744. ip2_start ( PTTY tty )
  1745. {
  1746. i2ChanStrPtr pCh = DevTable[tty->index];
  1747. i2QueueCommands(PTYPE_BYPASS, pCh, 0, 1, CMD_RESUME);
  1748. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_UNSUSPEND);
  1749. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_RESUME);
  1750. #ifdef IP2DEBUG_WRITE
  1751. printk (KERN_DEBUG "IP2: start tx\n" );
  1752. #endif
  1753. }
  1754. static void
  1755. ip2_stop ( PTTY tty )
  1756. {
  1757. i2ChanStrPtr pCh = DevTable[tty->index];
  1758. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_SUSPEND);
  1759. #ifdef IP2DEBUG_WRITE
  1760. printk (KERN_DEBUG "IP2: stop tx\n" );
  1761. #endif
  1762. }
  1763. /******************************************************************************/
  1764. /* Device Ioctl Section */
  1765. /******************************************************************************/
  1766. static int ip2_tiocmget(struct tty_struct *tty, struct file *file)
  1767. {
  1768. i2ChanStrPtr pCh = DevTable[tty->index];
  1769. #ifdef ENABLE_DSSNOW
  1770. wait_queue_t wait;
  1771. #endif
  1772. if (pCh == NULL)
  1773. return -ENODEV;
  1774. /*
  1775. FIXME - the following code is causing a NULL pointer dereference in
  1776. 2.3.51 in an interrupt handler. It's suppose to prompt the board
  1777. to return the DSS signal status immediately. Why doesn't it do
  1778. the same thing in 2.2.14?
  1779. */
  1780. /* This thing is still busted in the 1.2.12 driver on 2.4.x
  1781. and even hoses the serial console so the oops can be trapped.
  1782. /\/\|=mhw=|\/\/ */
  1783. #ifdef ENABLE_DSSNOW
  1784. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DSS_NOW);
  1785. init_waitqueue_entry(&wait, current);
  1786. add_wait_queue(&pCh->dss_now_wait, &wait);
  1787. set_current_state( TASK_INTERRUPTIBLE );
  1788. serviceOutgoingFifo( pCh->pMyBord );
  1789. schedule();
  1790. set_current_state( TASK_RUNNING );
  1791. remove_wait_queue(&pCh->dss_now_wait, &wait);
  1792. if (signal_pending(current)) {
  1793. return -EINTR;
  1794. }
  1795. #endif
  1796. return ((pCh->dataSetOut & I2_RTS) ? TIOCM_RTS : 0)
  1797. | ((pCh->dataSetOut & I2_DTR) ? TIOCM_DTR : 0)
  1798. | ((pCh->dataSetIn & I2_DCD) ? TIOCM_CAR : 0)
  1799. | ((pCh->dataSetIn & I2_RI) ? TIOCM_RNG : 0)
  1800. | ((pCh->dataSetIn & I2_DSR) ? TIOCM_DSR : 0)
  1801. | ((pCh->dataSetIn & I2_CTS) ? TIOCM_CTS : 0);
  1802. }
  1803. static int ip2_tiocmset(struct tty_struct *tty, struct file *file,
  1804. unsigned int set, unsigned int clear)
  1805. {
  1806. i2ChanStrPtr pCh = DevTable[tty->index];
  1807. if (pCh == NULL)
  1808. return -ENODEV;
  1809. if (set & TIOCM_RTS) {
  1810. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_RTSUP);
  1811. pCh->dataSetOut |= I2_RTS;
  1812. }
  1813. if (set & TIOCM_DTR) {
  1814. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DTRUP);
  1815. pCh->dataSetOut |= I2_DTR;
  1816. }
  1817. if (clear & TIOCM_RTS) {
  1818. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_RTSDN);
  1819. pCh->dataSetOut &= ~I2_RTS;
  1820. }
  1821. if (clear & TIOCM_DTR) {
  1822. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DTRDN);
  1823. pCh->dataSetOut &= ~I2_DTR;
  1824. }
  1825. serviceOutgoingFifo( pCh->pMyBord );
  1826. return 0;
  1827. }
  1828. /******************************************************************************/
  1829. /* Function: ip2_ioctl() */
  1830. /* Parameters: Pointer to tty structure */
  1831. /* Pointer to file structure */
  1832. /* Command */
  1833. /* Argument */
  1834. /* Returns: Success or failure */
  1835. /* */
  1836. /* Description: */
  1837. /* */
  1838. /* */
  1839. /******************************************************************************/
  1840. static int
  1841. ip2_ioctl ( PTTY tty, struct file *pFile, UINT cmd, ULONG arg )
  1842. {
  1843. wait_queue_t wait;
  1844. i2ChanStrPtr pCh = DevTable[tty->index];
  1845. i2eBordStrPtr pB;
  1846. struct async_icount cprev, cnow; /* kernel counter temps */
  1847. struct serial_icounter_struct __user *p_cuser;
  1848. int rc = 0;
  1849. unsigned long flags;
  1850. void __user *argp = (void __user *)arg;
  1851. if ( pCh == NULL )
  1852. return -ENODEV;
  1853. pB = pCh->pMyBord;
  1854. ip2trace (CHANN, ITRC_IOCTL, ITRC_ENTER, 2, cmd, arg );
  1855. #ifdef IP2DEBUG_IOCTL
  1856. printk(KERN_DEBUG "IP2: ioctl cmd (%x), arg (%lx)\n", cmd, arg );
  1857. #endif
  1858. switch(cmd) {
  1859. case TIOCGSERIAL:
  1860. ip2trace (CHANN, ITRC_IOCTL, 2, 1, rc );
  1861. rc = get_serial_info(pCh, argp);
  1862. if (rc)
  1863. return rc;
  1864. break;
  1865. case TIOCSSERIAL:
  1866. ip2trace (CHANN, ITRC_IOCTL, 3, 1, rc );
  1867. rc = set_serial_info(pCh, argp);
  1868. if (rc)
  1869. return rc;
  1870. break;
  1871. case TCXONC:
  1872. rc = tty_check_change(tty);
  1873. if (rc)
  1874. return rc;
  1875. switch (arg) {
  1876. case TCOOFF:
  1877. //return -ENOIOCTLCMD;
  1878. break;
  1879. case TCOON:
  1880. //return -ENOIOCTLCMD;
  1881. break;
  1882. case TCIOFF:
  1883. if (STOP_CHAR(tty) != __DISABLED_CHAR) {
  1884. i2QueueCommands( PTYPE_BYPASS, pCh, 100, 1,
  1885. CMD_XMIT_NOW(STOP_CHAR(tty)));
  1886. }
  1887. break;
  1888. case TCION:
  1889. if (START_CHAR(tty) != __DISABLED_CHAR) {
  1890. i2QueueCommands( PTYPE_BYPASS, pCh, 100, 1,
  1891. CMD_XMIT_NOW(START_CHAR(tty)));
  1892. }
  1893. break;
  1894. default:
  1895. return -EINVAL;
  1896. }
  1897. return 0;
  1898. case TCSBRK: /* SVID version: non-zero arg --> no break */
  1899. rc = tty_check_change(tty);
  1900. ip2trace (CHANN, ITRC_IOCTL, 4, 1, rc );
  1901. if (!rc) {
  1902. ip2_wait_until_sent(tty,0);
  1903. if (!arg) {
  1904. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_SEND_BRK(250));
  1905. serviceOutgoingFifo( pCh->pMyBord );
  1906. }
  1907. }
  1908. break;
  1909. case TCSBRKP: /* support for POSIX tcsendbreak() */
  1910. rc = tty_check_change(tty);
  1911. ip2trace (CHANN, ITRC_IOCTL, 5, 1, rc );
  1912. if (!rc) {
  1913. ip2_wait_until_sent(tty,0);
  1914. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
  1915. CMD_SEND_BRK(arg ? arg*100 : 250));
  1916. serviceOutgoingFifo ( pCh->pMyBord );
  1917. }
  1918. break;
  1919. case TIOCGSOFTCAR:
  1920. ip2trace (CHANN, ITRC_IOCTL, 6, 1, rc );
  1921. rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
  1922. if (rc)
  1923. return rc;
  1924. break;
  1925. case TIOCSSOFTCAR:
  1926. ip2trace (CHANN, ITRC_IOCTL, 7, 1, rc );
  1927. rc = get_user(arg,(unsigned long __user *) argp);
  1928. if (rc)
  1929. return rc;
  1930. tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL)
  1931. | (arg ? CLOCAL : 0));
  1932. break;
  1933. /*
  1934. * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change - mask
  1935. * passed in arg for lines of interest (use |'ed TIOCM_RNG/DSR/CD/CTS
  1936. * for masking). Caller should use TIOCGICOUNT to see which one it was
  1937. */
  1938. case TIOCMIWAIT:
  1939. write_lock_irqsave(&pB->read_fifo_spinlock, flags);
  1940. cprev = pCh->icount; /* note the counters on entry */
  1941. write_unlock_irqrestore(&pB->read_fifo_spinlock, flags);
  1942. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 4,
  1943. CMD_DCD_REP, CMD_CTS_REP, CMD_DSR_REP, CMD_RI_REP);
  1944. init_waitqueue_entry(&wait, current);
  1945. add_wait_queue(&pCh->delta_msr_wait, &wait);
  1946. set_current_state( TASK_INTERRUPTIBLE );
  1947. serviceOutgoingFifo( pCh->pMyBord );
  1948. for(;;) {
  1949. ip2trace (CHANN, ITRC_IOCTL, 10, 0 );
  1950. schedule();
  1951. ip2trace (CHANN, ITRC_IOCTL, 11, 0 );
  1952. /* see if a signal did it */
  1953. if (signal_pending(current)) {
  1954. rc = -ERESTARTSYS;
  1955. break;
  1956. }
  1957. write_lock_irqsave(&pB->read_fifo_spinlock, flags);
  1958. cnow = pCh->icount; /* atomic copy */
  1959. write_unlock_irqrestore(&pB->read_fifo_spinlock, flags);
  1960. if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
  1961. cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
  1962. rc = -EIO; /* no change => rc */
  1963. break;
  1964. }
  1965. if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
  1966. ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
  1967. ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
  1968. ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
  1969. rc = 0;
  1970. break;
  1971. }
  1972. cprev = cnow;
  1973. }
  1974. set_current_state( TASK_RUNNING );
  1975. remove_wait_queue(&pCh->delta_msr_wait, &wait);
  1976. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 3,
  1977. CMD_CTS_NREP, CMD_DSR_NREP, CMD_RI_NREP);
  1978. if ( ! (pCh->flags & ASYNC_CHECK_CD)) {
  1979. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DCD_NREP);
  1980. }
  1981. serviceOutgoingFifo( pCh->pMyBord );
  1982. return rc;
  1983. break;
  1984. /*
  1985. * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
  1986. * Return: write counters to the user passed counter struct
  1987. * NB: both 1->0 and 0->1 transitions are counted except for RI where
  1988. * only 0->1 is counted. The controller is quite capable of counting
  1989. * both, but this done to preserve compatibility with the standard
  1990. * serial driver.
  1991. */
  1992. case TIOCGICOUNT:
  1993. ip2trace (CHANN, ITRC_IOCTL, 11, 1, rc );
  1994. write_lock_irqsave(&pB->read_fifo_spinlock, flags);
  1995. cnow = pCh->icount;
  1996. write_unlock_irqrestore(&pB->read_fifo_spinlock, flags);
  1997. p_cuser = argp;
  1998. rc = put_user(cnow.cts, &p_cuser->cts);
  1999. rc = put_user(cnow.dsr, &p_cuser->dsr);
  2000. rc = put_user(cnow.rng, &p_cuser->rng);
  2001. rc = put_user(cnow.dcd, &p_cuser->dcd);
  2002. rc = put_user(cnow.rx, &p_cuser->rx);
  2003. rc = put_user(cnow.tx, &p_cuser->tx);
  2004. rc = put_user(cnow.frame, &p_cuser->frame);
  2005. rc = put_user(cnow.overrun, &p_cuser->overrun);
  2006. rc = put_user(cnow.parity, &p_cuser->parity);
  2007. rc = put_user(cnow.brk, &p_cuser->brk);
  2008. rc = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
  2009. break;
  2010. /*
  2011. * The rest are not supported by this driver. By returning -ENOIOCTLCMD they
  2012. * will be passed to the line discipline for it to handle.
  2013. */
  2014. case TIOCSERCONFIG:
  2015. case TIOCSERGWILD:
  2016. case TIOCSERGETLSR:
  2017. case TIOCSERSWILD:
  2018. case TIOCSERGSTRUCT:
  2019. case TIOCSERGETMULTI:
  2020. case TIOCSERSETMULTI:
  2021. default:
  2022. ip2trace (CHANN, ITRC_IOCTL, 12, 0 );
  2023. rc = -ENOIOCTLCMD;
  2024. break;
  2025. }
  2026. ip2trace (CHANN, ITRC_IOCTL, ITRC_RETURN, 0 );
  2027. return rc;
  2028. }
  2029. /******************************************************************************/
  2030. /* Function: GetSerialInfo() */
  2031. /* Parameters: Pointer to channel structure */
  2032. /* Pointer to old termios structure */
  2033. /* Returns: Nothing */
  2034. /* */
  2035. /* Description: */
  2036. /* This is to support the setserial command, and requires processing of the */
  2037. /* standard Linux serial structure. */
  2038. /******************************************************************************/
  2039. static int
  2040. get_serial_info ( i2ChanStrPtr pCh, struct serial_struct __user *retinfo )
  2041. {
  2042. struct serial_struct tmp;
  2043. memset ( &tmp, 0, sizeof(tmp) );
  2044. tmp.type = pCh->pMyBord->channelBtypes.bid_value[(pCh->port_index & (IP2_PORTS_PER_BOARD-1))/16];
  2045. if (BID_HAS_654(tmp.type)) {
  2046. tmp.type = PORT_16650;
  2047. } else {
  2048. tmp.type = PORT_CIRRUS;
  2049. }
  2050. tmp.line = pCh->port_index;
  2051. tmp.port = pCh->pMyBord->i2eBase;
  2052. tmp.irq = ip2config.irq[pCh->port_index/64];
  2053. tmp.flags = pCh->flags;
  2054. tmp.baud_base = pCh->BaudBase;
  2055. tmp.close_delay = pCh->ClosingDelay;
  2056. tmp.closing_wait = pCh->ClosingWaitTime;
  2057. tmp.custom_divisor = pCh->BaudDivisor;
  2058. return copy_to_user(retinfo,&tmp,sizeof(*retinfo));
  2059. }
  2060. /******************************************************************************/
  2061. /* Function: SetSerialInfo() */
  2062. /* Parameters: Pointer to channel structure */
  2063. /* Pointer to old termios structure */
  2064. /* Returns: Nothing */
  2065. /* */
  2066. /* Description: */
  2067. /* This function provides support for setserial, which uses the TIOCSSERIAL */
  2068. /* ioctl. Not all setserial parameters are relevant. If the user attempts to */
  2069. /* change the IRQ, address or type of the port the ioctl fails. */
  2070. /******************************************************************************/
  2071. static int
  2072. set_serial_info( i2ChanStrPtr pCh, struct serial_struct __user *new_info )
  2073. {
  2074. struct serial_struct ns;
  2075. int old_flags, old_baud_divisor;
  2076. if (copy_from_user(&ns, new_info, sizeof (ns)))
  2077. return -EFAULT;
  2078. /*
  2079. * We don't allow setserial to change IRQ, board address, type or baud
  2080. * base. Also line nunber as such is meaningless but we use it for our
  2081. * array index so it is fixed also.
  2082. */
  2083. if ( (ns.irq != ip2config.irq[pCh->port_index])
  2084. || ((int) ns.port != ((int) (pCh->pMyBord->i2eBase)))
  2085. || (ns.baud_base != pCh->BaudBase)
  2086. || (ns.line != pCh->port_index) ) {
  2087. return -EINVAL;
  2088. }
  2089. old_flags = pCh->flags;
  2090. old_baud_divisor = pCh->BaudDivisor;
  2091. if ( !capable(CAP_SYS_ADMIN) ) {
  2092. if ( ( ns.close_delay != pCh->ClosingDelay ) ||
  2093. ( (ns.flags & ~ASYNC_USR_MASK) !=
  2094. (pCh->flags & ~ASYNC_USR_MASK) ) ) {
  2095. return -EPERM;
  2096. }
  2097. pCh->flags = (pCh->flags & ~ASYNC_USR_MASK) |
  2098. (ns.flags & ASYNC_USR_MASK);
  2099. pCh->BaudDivisor = ns.custom_divisor;
  2100. } else {
  2101. pCh->flags = (pCh->flags & ~ASYNC_FLAGS) |
  2102. (ns.flags & ASYNC_FLAGS);
  2103. pCh->BaudDivisor = ns.custom_divisor;
  2104. pCh->ClosingDelay = ns.close_delay * HZ/100;
  2105. pCh->ClosingWaitTime = ns.closing_wait * HZ/100;
  2106. }
  2107. if ( ( (old_flags & ASYNC_SPD_MASK) != (pCh->flags & ASYNC_SPD_MASK) )
  2108. || (old_baud_divisor != pCh->BaudDivisor) ) {
  2109. // Invalidate speed and reset parameters
  2110. set_params( pCh, NULL );
  2111. }
  2112. return 0;
  2113. }
  2114. /******************************************************************************/
  2115. /* Function: ip2_set_termios() */
  2116. /* Parameters: Pointer to tty structure */
  2117. /* Pointer to old termios structure */
  2118. /* Returns: Nothing */
  2119. /* */
  2120. /* Description: */
  2121. /* */
  2122. /* */
  2123. /******************************************************************************/
  2124. static void
  2125. ip2_set_termios( PTTY tty, struct ktermios *old_termios )
  2126. {
  2127. i2ChanStrPtr pCh = (i2ChanStrPtr)tty->driver_data;
  2128. #ifdef IP2DEBUG_IOCTL
  2129. printk (KERN_DEBUG "IP2: set termios %p\n", old_termios );
  2130. #endif
  2131. set_params( pCh, old_termios );
  2132. }
  2133. /******************************************************************************/
  2134. /* Function: ip2_set_line_discipline() */
  2135. /* Parameters: Pointer to tty structure */
  2136. /* Returns: Nothing */
  2137. /* */
  2138. /* Description: Does nothing */
  2139. /* */
  2140. /* */
  2141. /******************************************************************************/
  2142. static void
  2143. ip2_set_line_discipline ( PTTY tty )
  2144. {
  2145. #ifdef IP2DEBUG_IOCTL
  2146. printk (KERN_DEBUG "IP2: set line discipline\n" );
  2147. #endif
  2148. ip2trace (((i2ChanStrPtr)tty->driver_data)->port_index, ITRC_IOCTL, 16, 0 );
  2149. }
  2150. /******************************************************************************/
  2151. /* Function: SetLine Characteristics() */
  2152. /* Parameters: Pointer to channel structure */
  2153. /* Returns: Nothing */
  2154. /* */
  2155. /* Description: */
  2156. /* This routine is called to update the channel structure with the new line */
  2157. /* characteristics, and send the appropriate commands to the board when they */
  2158. /* change. */
  2159. /******************************************************************************/
  2160. static void
  2161. set_params( i2ChanStrPtr pCh, struct ktermios *o_tios )
  2162. {
  2163. tcflag_t cflag, iflag, lflag;
  2164. char stop_char, start_char;
  2165. struct ktermios dummy;
  2166. lflag = pCh->pTTY->termios->c_lflag;
  2167. cflag = pCh->pTTY->termios->c_cflag;
  2168. iflag = pCh->pTTY->termios->c_iflag;
  2169. if (o_tios == NULL) {
  2170. dummy.c_lflag = ~lflag;
  2171. dummy.c_cflag = ~cflag;
  2172. dummy.c_iflag = ~iflag;
  2173. o_tios = &dummy;
  2174. }
  2175. {
  2176. switch ( cflag & CBAUD ) {
  2177. case B0:
  2178. i2QueueCommands( PTYPE_BYPASS, pCh, 100, 2, CMD_RTSDN, CMD_DTRDN);
  2179. pCh->dataSetOut &= ~(I2_DTR | I2_RTS);
  2180. i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_PAUSE(25));
  2181. pCh->pTTY->termios->c_cflag |= (CBAUD & o_tios->c_cflag);
  2182. goto service_it;
  2183. break;
  2184. case B38400:
  2185. /*
  2186. * This is the speed that is overloaded with all the other high
  2187. * speeds, depending upon the flag settings.
  2188. */
  2189. if ( ( pCh->flags & ASYNC_SPD_MASK ) == ASYNC_SPD_HI ) {
  2190. pCh->speed = CBR_57600;
  2191. } else if ( (pCh->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI ) {
  2192. pCh->speed = CBR_115200;
  2193. } else if ( (pCh->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST ) {
  2194. pCh->speed = CBR_C1;
  2195. } else {
  2196. pCh->speed = CBR_38400;
  2197. }
  2198. break;
  2199. case B50: pCh->speed = CBR_50; break;
  2200. case B75: pCh->speed = CBR_75; break;
  2201. case B110: pCh->speed = CBR_110; break;
  2202. case B134: pCh->speed = CBR_134; break;
  2203. case B150: pCh->speed = CBR_150; break;
  2204. case B200: pCh->speed = CBR_200; break;
  2205. case B300: pCh->speed = CBR_300; break;
  2206. case B600: pCh->speed = CBR_600; break;
  2207. case B1200: pCh->speed = CBR_1200; break;
  2208. case B1800: pCh->speed = CBR_1800; break;
  2209. case B2400: pCh->speed = CBR_2400; break;
  2210. case B4800: pCh->speed = CBR_4800; break;
  2211. case B9600: pCh->speed = CBR_9600; break;
  2212. case B19200: pCh->speed = CBR_19200; break;
  2213. case B57600: pCh->speed = CBR_57600; break;
  2214. case B115200: pCh->speed = CBR_115200; break;
  2215. case B153600: pCh->speed = CBR_153600; break;
  2216. case B230400: pCh->speed = CBR_230400; break;
  2217. case B307200: pCh->speed = CBR_307200; break;
  2218. case B460800: pCh->speed = CBR_460800; break;
  2219. case B921600: pCh->speed = CBR_921600; break;
  2220. default: pCh->speed = CBR_9600; break;
  2221. }
  2222. if ( pCh->speed == CBR_C1 ) {
  2223. // Process the custom speed parameters.
  2224. int bps = pCh->BaudBase / pCh->BaudDivisor;
  2225. if ( bps == 921600 ) {
  2226. pCh->speed = CBR_921600;
  2227. } else {
  2228. bps = bps/10;
  2229. i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_BAUD_DEF1(bps) );
  2230. }
  2231. }
  2232. i2QueueCommands( PTYPE_INLINE, pCh, 100, 1, CMD_SETBAUD(pCh->speed));
  2233. i2QueueCommands ( PTYPE_INLINE, pCh, 100, 2, CMD_DTRUP, CMD_RTSUP);
  2234. pCh->dataSetOut |= (I2_DTR | I2_RTS);
  2235. }
  2236. if ( (CSTOPB & cflag) ^ (CSTOPB & o_tios->c_cflag))
  2237. {
  2238. i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1,
  2239. CMD_SETSTOP( ( cflag & CSTOPB ) ? CST_2 : CST_1));
  2240. }
  2241. if (((PARENB|PARODD) & cflag) ^ ((PARENB|PARODD) & o_tios->c_cflag))
  2242. {
  2243. i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1,
  2244. CMD_SETPAR(
  2245. (cflag & PARENB ? (cflag & PARODD ? CSP_OD : CSP_EV) : CSP_NP)
  2246. )
  2247. );
  2248. }
  2249. /* byte size and parity */
  2250. if ( (CSIZE & cflag)^(CSIZE & o_tios->c_cflag))
  2251. {
  2252. int datasize;
  2253. switch ( cflag & CSIZE ) {
  2254. case CS5: datasize = CSZ_5; break;
  2255. case CS6: datasize = CSZ_6; break;
  2256. case CS7: datasize = CSZ_7; break;
  2257. case CS8: datasize = CSZ_8; break;
  2258. default: datasize = CSZ_5; break; /* as per serial.c */
  2259. }
  2260. i2QueueCommands ( PTYPE_INLINE, pCh, 100, 1, CMD_SETBITS(datasize) );
  2261. }
  2262. /* Process CTS flow control flag setting */
  2263. if ( (cflag & CRTSCTS) ) {
  2264. i2QueueCommands(PTYPE_INLINE, pCh, 100,
  2265. 2, CMD_CTSFL_ENAB, CMD_RTSFL_ENAB);
  2266. } else {
  2267. i2QueueCommands(PTYPE_INLINE, pCh, 100,
  2268. 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB);
  2269. }
  2270. //
  2271. // Process XON/XOFF flow control flags settings
  2272. //
  2273. stop_char = STOP_CHAR(pCh->pTTY);
  2274. start_char = START_CHAR(pCh->pTTY);
  2275. //////////// can't be \000
  2276. if (stop_char == __DISABLED_CHAR )
  2277. {
  2278. stop_char = ~__DISABLED_CHAR;
  2279. }
  2280. if (start_char == __DISABLED_CHAR )
  2281. {
  2282. start_char = ~__DISABLED_CHAR;
  2283. }
  2284. /////////////////////////////////
  2285. if ( o_tios->c_cc[VSTART] != start_char )
  2286. {
  2287. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DEF_IXON(start_char));
  2288. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DEF_OXON(start_char));
  2289. }
  2290. if ( o_tios->c_cc[VSTOP] != stop_char )
  2291. {
  2292. i2QueueCommands(PTYPE_BYPASS, pCh, 100, 1, CMD_DEF_IXOFF(stop_char));
  2293. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DEF_OXOFF(stop_char));
  2294. }
  2295. if (stop_char == __DISABLED_CHAR )
  2296. {
  2297. stop_char = ~__DISABLED_CHAR; //TEST123
  2298. goto no_xoff;
  2299. }
  2300. if ((iflag & (IXOFF))^(o_tios->c_iflag & (IXOFF)))
  2301. {
  2302. if ( iflag & IXOFF ) { // Enable XOFF output flow control
  2303. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_OXON_OPT(COX_XON));
  2304. } else { // Disable XOFF output flow control
  2305. no_xoff:
  2306. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_OXON_OPT(COX_NONE));
  2307. }
  2308. }
  2309. if (start_char == __DISABLED_CHAR )
  2310. {
  2311. goto no_xon;
  2312. }
  2313. if ((iflag & (IXON|IXANY)) ^ (o_tios->c_iflag & (IXON|IXANY)))
  2314. {
  2315. if ( iflag & IXON ) {
  2316. if ( iflag & IXANY ) { // Enable XON/XANY output flow control
  2317. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_XANY));
  2318. } else { // Enable XON output flow control
  2319. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_XON));
  2320. }
  2321. } else { // Disable XON output flow control
  2322. no_xon:
  2323. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_IXON_OPT(CIX_NONE));
  2324. }
  2325. }
  2326. if ( (iflag & ISTRIP) ^ ( o_tios->c_iflag & (ISTRIP)) )
  2327. {
  2328. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
  2329. CMD_ISTRIP_OPT((iflag & ISTRIP ? 1 : 0)));
  2330. }
  2331. if ( (iflag & INPCK) ^ ( o_tios->c_iflag & (INPCK)) )
  2332. {
  2333. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1,
  2334. CMD_PARCHK((iflag & INPCK) ? CPK_ENAB : CPK_DSAB));
  2335. }
  2336. if ( (iflag & (IGNBRK|PARMRK|BRKINT|IGNPAR))
  2337. ^ ( o_tios->c_iflag & (IGNBRK|PARMRK|BRKINT|IGNPAR)) )
  2338. {
  2339. char brkrpt = 0;
  2340. char parrpt = 0;
  2341. if ( iflag & IGNBRK ) { /* Ignore breaks altogether */
  2342. /* Ignore breaks altogether */
  2343. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_BRK_NREP);
  2344. } else {
  2345. if ( iflag & BRKINT ) {
  2346. if ( iflag & PARMRK ) {
  2347. brkrpt = 0x0a; // exception an inline triple
  2348. } else {
  2349. brkrpt = 0x1a; // exception and NULL
  2350. }
  2351. brkrpt |= 0x04; // flush input
  2352. } else {
  2353. if ( iflag & PARMRK ) {
  2354. brkrpt = 0x0b; //POSIX triple \0377 \0 \0
  2355. } else {
  2356. brkrpt = 0x01; // Null only
  2357. }
  2358. }
  2359. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_BRK_REP(brkrpt));
  2360. }
  2361. if (iflag & IGNPAR) {
  2362. parrpt = 0x20;
  2363. /* would be 2 for not cirrus bug */
  2364. /* would be 0x20 cept for cirrus bug */
  2365. } else {
  2366. if ( iflag & PARMRK ) {
  2367. /*
  2368. * Replace error characters with 3-byte sequence (\0377,\0,char)
  2369. */
  2370. parrpt = 0x04 ;
  2371. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_ISTRIP_OPT((char)0));
  2372. } else {
  2373. parrpt = 0x03;
  2374. }
  2375. }
  2376. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_SET_ERROR(parrpt));
  2377. }
  2378. if (cflag & CLOCAL) {
  2379. // Status reporting fails for DCD if this is off
  2380. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DCD_NREP);
  2381. pCh->flags &= ~ASYNC_CHECK_CD;
  2382. } else {
  2383. i2QueueCommands(PTYPE_INLINE, pCh, 100, 1, CMD_DCD_REP);
  2384. pCh->flags |= ASYNC_CHECK_CD;
  2385. }
  2386. service_it:
  2387. i2DrainOutput( pCh, 100 );
  2388. }
  2389. /******************************************************************************/
  2390. /* IPL Device Section */
  2391. /******************************************************************************/
  2392. /******************************************************************************/
  2393. /* Function: ip2_ipl_read() */
  2394. /* Parameters: Pointer to device inode */
  2395. /* Pointer to file structure */
  2396. /* Pointer to data */
  2397. /* Number of bytes to read */
  2398. /* Returns: Success or failure */
  2399. /* */
  2400. /* Description: Ugly */
  2401. /* */
  2402. /* */
  2403. /******************************************************************************/
  2404. static
  2405. ssize_t
  2406. ip2_ipl_read(struct file *pFile, char __user *pData, size_t count, loff_t *off )
  2407. {
  2408. unsigned int minor = iminor(pFile->f_path.dentry->d_inode);
  2409. int rc = 0;
  2410. #ifdef IP2DEBUG_IPL
  2411. printk (KERN_DEBUG "IP2IPL: read %p, %d bytes\n", pData, count );
  2412. #endif
  2413. switch( minor ) {
  2414. case 0: // IPL device
  2415. rc = -EINVAL;
  2416. break;
  2417. case 1: // Status dump
  2418. rc = -EINVAL;
  2419. break;
  2420. case 2: // Ping device
  2421. rc = -EINVAL;
  2422. break;
  2423. case 3: // Trace device
  2424. rc = DumpTraceBuffer ( pData, count );
  2425. break;
  2426. case 4: // Trace device
  2427. rc = DumpFifoBuffer ( pData, count );
  2428. break;
  2429. default:
  2430. rc = -ENODEV;
  2431. break;
  2432. }
  2433. return rc;
  2434. }
  2435. static int
  2436. DumpFifoBuffer ( char __user *pData, int count )
  2437. {
  2438. #ifdef DEBUG_FIFO
  2439. int rc;
  2440. rc = copy_to_user(pData, DBGBuf, count);
  2441. printk(KERN_DEBUG "Last index %d\n", I );
  2442. return count;
  2443. #endif /* DEBUG_FIFO */
  2444. return 0;
  2445. }
  2446. static int
  2447. DumpTraceBuffer ( char __user *pData, int count )
  2448. {
  2449. #ifdef IP2DEBUG_TRACE
  2450. int rc;
  2451. int dumpcount;
  2452. int chunk;
  2453. int *pIndex = (int __user *)pData;
  2454. if ( count < (sizeof(int) * 6) ) {
  2455. return -EIO;
  2456. }
  2457. rc = put_user(tracewrap, pIndex );
  2458. rc = put_user(TRACEMAX, ++pIndex );
  2459. rc = put_user(tracestrip, ++pIndex );
  2460. rc = put_user(tracestuff, ++pIndex );
  2461. pData += sizeof(int) * 6;
  2462. count -= sizeof(int) * 6;
  2463. dumpcount = tracestuff - tracestrip;
  2464. if ( dumpcount < 0 ) {
  2465. dumpcount += TRACEMAX;
  2466. }
  2467. if ( dumpcount > count ) {
  2468. dumpcount = count;
  2469. }
  2470. chunk = TRACEMAX - tracestrip;
  2471. if ( dumpcount > chunk ) {
  2472. rc = copy_to_user(pData, &tracebuf[tracestrip],
  2473. chunk * sizeof(tracebuf[0]) );
  2474. pData += chunk * sizeof(tracebuf[0]);
  2475. tracestrip = 0;
  2476. chunk = dumpcount - chunk;
  2477. } else {
  2478. chunk = dumpcount;
  2479. }
  2480. rc = copy_to_user(pData, &tracebuf[tracestrip],
  2481. chunk * sizeof(tracebuf[0]) );
  2482. tracestrip += chunk;
  2483. tracewrap = 0;
  2484. rc = put_user(tracestrip, ++pIndex );
  2485. rc = put_user(tracestuff, ++pIndex );
  2486. return dumpcount;
  2487. #else
  2488. return 0;
  2489. #endif
  2490. }
  2491. /******************************************************************************/
  2492. /* Function: ip2_ipl_write() */
  2493. /* Parameters: */
  2494. /* Pointer to file structure */
  2495. /* Pointer to data */
  2496. /* Number of bytes to write */
  2497. /* Returns: Success or failure */
  2498. /* */
  2499. /* Description: */
  2500. /* */
  2501. /* */
  2502. /******************************************************************************/
  2503. static ssize_t
  2504. ip2_ipl_write(struct file *pFile, const char __user *pData, size_t count, loff_t *off)
  2505. {
  2506. #ifdef IP2DEBUG_IPL
  2507. printk (KERN_DEBUG "IP2IPL: write %p, %d bytes\n", pData, count );
  2508. #endif
  2509. return 0;
  2510. }
  2511. /******************************************************************************/
  2512. /* Function: ip2_ipl_ioctl() */
  2513. /* Parameters: Pointer to device inode */
  2514. /* Pointer to file structure */
  2515. /* Command */
  2516. /* Argument */
  2517. /* Returns: Success or failure */
  2518. /* */
  2519. /* Description: */
  2520. /* */
  2521. /* */
  2522. /******************************************************************************/
  2523. static long
  2524. ip2_ipl_ioctl (struct file *pFile, UINT cmd, ULONG arg )
  2525. {
  2526. unsigned int iplminor = iminor(pFile->f_path.dentry->d_inode);
  2527. int rc = 0;
  2528. void __user *argp = (void __user *)arg;
  2529. ULONG __user *pIndex = argp;
  2530. i2eBordStrPtr pB = i2BoardPtrTable[iplminor / 4];
  2531. i2ChanStrPtr pCh;
  2532. #ifdef IP2DEBUG_IPL
  2533. printk (KERN_DEBUG "IP2IPL: ioctl cmd %d, arg %ld\n", cmd, arg );
  2534. #endif
  2535. lock_kernel();
  2536. switch ( iplminor ) {
  2537. case 0: // IPL device
  2538. rc = -EINVAL;
  2539. break;
  2540. case 1: // Status dump
  2541. case 5:
  2542. case 9:
  2543. case 13:
  2544. switch ( cmd ) {
  2545. case 64: /* Driver - ip2stat */
  2546. rc = put_user(-1, pIndex++ );
  2547. rc = put_user(irq_counter, pIndex++ );
  2548. rc = put_user(bh_counter, pIndex++ );
  2549. break;
  2550. case 65: /* Board - ip2stat */
  2551. if ( pB ) {
  2552. rc = copy_to_user(argp, pB, sizeof(i2eBordStr));
  2553. rc = put_user(inb(pB->i2eStatus),
  2554. (ULONG __user *)(arg + (ULONG)(&pB->i2eStatus) - (ULONG)pB ) );
  2555. } else {
  2556. rc = -ENODEV;
  2557. }
  2558. break;
  2559. default:
  2560. if (cmd < IP2_MAX_PORTS) {
  2561. pCh = DevTable[cmd];
  2562. if ( pCh )
  2563. {
  2564. rc = copy_to_user(argp, pCh, sizeof(i2ChanStr));
  2565. if (rc)
  2566. rc = -EFAULT;
  2567. } else {
  2568. rc = -ENODEV;
  2569. }
  2570. } else {
  2571. rc = -EINVAL;
  2572. }
  2573. }
  2574. break;
  2575. case 2: // Ping device
  2576. rc = -EINVAL;
  2577. break;
  2578. case 3: // Trace device
  2579. /*
  2580. * akpm: This used to write a whole bunch of function addresses
  2581. * to userspace, which generated lots of put_user() warnings.
  2582. * I killed it all. Just return "success" and don't do
  2583. * anything.
  2584. */
  2585. if (cmd == 1)
  2586. rc = 0;
  2587. else
  2588. rc = -EINVAL;
  2589. break;
  2590. default:
  2591. rc = -ENODEV;
  2592. break;
  2593. }
  2594. unlock_kernel();
  2595. return rc;
  2596. }
  2597. /******************************************************************************/
  2598. /* Function: ip2_ipl_open() */
  2599. /* Parameters: Pointer to device inode */
  2600. /* Pointer to file structure */
  2601. /* Returns: Success or failure */
  2602. /* */
  2603. /* Description: */
  2604. /* */
  2605. /* */
  2606. /******************************************************************************/
  2607. static int
  2608. ip2_ipl_open( struct inode *pInode, struct file *pFile )
  2609. {
  2610. #ifdef IP2DEBUG_IPL
  2611. printk (KERN_DEBUG "IP2IPL: open\n" );
  2612. #endif
  2613. cycle_kernel_lock();
  2614. return 0;
  2615. }
  2616. static int
  2617. proc_ip2mem_show(struct seq_file *m, void *v)
  2618. {
  2619. i2eBordStrPtr pB;
  2620. i2ChanStrPtr pCh;
  2621. PTTY tty;
  2622. int i;
  2623. #define FMTLINE "%3d: 0x%08x 0x%08x 0%011o 0%011o\n"
  2624. #define FMTLIN2 " 0x%04x 0x%04x tx flow 0x%x\n"
  2625. #define FMTLIN3 " 0x%04x 0x%04x rc flow\n"
  2626. seq_printf(m,"\n");
  2627. for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  2628. pB = i2BoardPtrTable[i];
  2629. if ( pB ) {
  2630. seq_printf(m,"board %d:\n",i);
  2631. seq_printf(m,"\tFifo rem: %d mty: %x outM %x\n",
  2632. pB->i2eFifoRemains,pB->i2eWaitingForEmptyFifo,pB->i2eOutMailWaiting);
  2633. }
  2634. }
  2635. seq_printf(m,"#: tty flags, port flags, cflags, iflags\n");
  2636. for (i=0; i < IP2_MAX_PORTS; i++) {
  2637. pCh = DevTable[i];
  2638. if (pCh) {
  2639. tty = pCh->pTTY;
  2640. if (tty && tty->count) {
  2641. seq_printf(m,FMTLINE,i,(int)tty->flags,pCh->flags,
  2642. tty->termios->c_cflag,tty->termios->c_iflag);
  2643. seq_printf(m,FMTLIN2,
  2644. pCh->outfl.asof,pCh->outfl.room,pCh->channelNeeds);
  2645. seq_printf(m,FMTLIN3,pCh->infl.asof,pCh->infl.room);
  2646. }
  2647. }
  2648. }
  2649. return 0;
  2650. }
  2651. static int proc_ip2mem_open(struct inode *inode, struct file *file)
  2652. {
  2653. return single_open(file, proc_ip2mem_show, NULL);
  2654. }
  2655. static const struct file_operations ip2mem_proc_fops = {
  2656. .owner = THIS_MODULE,
  2657. .open = proc_ip2mem_open,
  2658. .read = seq_read,
  2659. .llseek = seq_lseek,
  2660. .release = single_release,
  2661. };
  2662. /*
  2663. * This is the handler for /proc/tty/driver/ip2
  2664. *
  2665. * This stretch of code has been largely plagerized from at least three
  2666. * different sources including ip2mkdev.c and a couple of other drivers.
  2667. * The bugs are all mine. :-) =mhw=
  2668. */
  2669. static int ip2_proc_show(struct seq_file *m, void *v)
  2670. {
  2671. int i, j, box;
  2672. int boxes = 0;
  2673. int ports = 0;
  2674. int tports = 0;
  2675. i2eBordStrPtr pB;
  2676. char *sep;
  2677. seq_printf(m, "ip2info: 1.0 driver: %s\n", pcVersion);
  2678. seq_printf(m, "Driver: SMajor=%d CMajor=%d IMajor=%d MaxBoards=%d MaxBoxes=%d MaxPorts=%d\n",
  2679. IP2_TTY_MAJOR, IP2_CALLOUT_MAJOR, IP2_IPL_MAJOR,
  2680. IP2_MAX_BOARDS, ABS_MAX_BOXES, ABS_BIGGEST_BOX);
  2681. for( i = 0; i < IP2_MAX_BOARDS; ++i ) {
  2682. /* This need to be reset for a board by board count... */
  2683. boxes = 0;
  2684. pB = i2BoardPtrTable[i];
  2685. if( pB ) {
  2686. switch( pB->i2ePom.e.porID & ~POR_ID_RESERVED )
  2687. {
  2688. case POR_ID_FIIEX:
  2689. seq_printf(m, "Board %d: EX ports=", i);
  2690. sep = "";
  2691. for( box = 0; box < ABS_MAX_BOXES; ++box )
  2692. {
  2693. ports = 0;
  2694. if( pB->i2eChannelMap[box] != 0 ) ++boxes;
  2695. for( j = 0; j < ABS_BIGGEST_BOX; ++j )
  2696. {
  2697. if( pB->i2eChannelMap[box] & 1<< j ) {
  2698. ++ports;
  2699. }
  2700. }
  2701. seq_printf(m, "%s%d", sep, ports);
  2702. sep = ",";
  2703. tports += ports;
  2704. }
  2705. seq_printf(m, " boxes=%d width=%d", boxes, pB->i2eDataWidth16 ? 16 : 8);
  2706. break;
  2707. case POR_ID_II_4:
  2708. seq_printf(m, "Board %d: ISA-4 ports=4 boxes=1", i);
  2709. tports = ports = 4;
  2710. break;
  2711. case POR_ID_II_8:
  2712. seq_printf(m, "Board %d: ISA-8-std ports=8 boxes=1", i);
  2713. tports = ports = 8;
  2714. break;
  2715. case POR_ID_II_8R:
  2716. seq_printf(m, "Board %d: ISA-8-RJ11 ports=8 boxes=1", i);
  2717. tports = ports = 8;
  2718. break;
  2719. default:
  2720. seq_printf(m, "Board %d: unknown", i);
  2721. /* Don't try and probe for minor numbers */
  2722. tports = ports = 0;
  2723. }
  2724. } else {
  2725. /* Don't try and probe for minor numbers */
  2726. seq_printf(m, "Board %d: vacant", i);
  2727. tports = ports = 0;
  2728. }
  2729. if( tports ) {
  2730. seq_puts(m, " minors=");
  2731. sep = "";
  2732. for ( box = 0; box < ABS_MAX_BOXES; ++box )
  2733. {
  2734. for ( j = 0; j < ABS_BIGGEST_BOX; ++j )
  2735. {
  2736. if ( pB->i2eChannelMap[box] & (1 << j) )
  2737. {
  2738. seq_printf(m, "%s%d", sep,
  2739. j + ABS_BIGGEST_BOX *
  2740. (box+i*ABS_MAX_BOXES));
  2741. sep = ",";
  2742. }
  2743. }
  2744. }
  2745. }
  2746. seq_putc(m, '\n');
  2747. }
  2748. return 0;
  2749. }
  2750. static int ip2_proc_open(struct inode *inode, struct file *file)
  2751. {
  2752. return single_open(file, ip2_proc_show, NULL);
  2753. }
  2754. static const struct file_operations ip2_proc_fops = {
  2755. .owner = THIS_MODULE,
  2756. .open = ip2_proc_open,
  2757. .read = seq_read,
  2758. .llseek = seq_lseek,
  2759. .release = single_release,
  2760. };
  2761. /******************************************************************************/
  2762. /* Function: ip2trace() */
  2763. /* Parameters: Value to add to trace buffer */
  2764. /* Returns: Nothing */
  2765. /* */
  2766. /* Description: */
  2767. /* */
  2768. /* */
  2769. /******************************************************************************/
  2770. #ifdef IP2DEBUG_TRACE
  2771. void
  2772. ip2trace (unsigned short pn, unsigned char cat, unsigned char label, unsigned long codes, ...)
  2773. {
  2774. long flags;
  2775. unsigned long *pCode = &codes;
  2776. union ip2breadcrumb bc;
  2777. i2ChanStrPtr pCh;
  2778. tracebuf[tracestuff++] = jiffies;
  2779. if ( tracestuff == TRACEMAX ) {
  2780. tracestuff = 0;
  2781. }
  2782. if ( tracestuff == tracestrip ) {
  2783. if ( ++tracestrip == TRACEMAX ) {
  2784. tracestrip = 0;
  2785. }
  2786. ++tracewrap;
  2787. }
  2788. bc.hdr.port = 0xff & pn;
  2789. bc.hdr.cat = cat;
  2790. bc.hdr.codes = (unsigned char)( codes & 0xff );
  2791. bc.hdr.label = label;
  2792. tracebuf[tracestuff++] = bc.value;
  2793. for (;;) {
  2794. if ( tracestuff == TRACEMAX ) {
  2795. tracestuff = 0;
  2796. }
  2797. if ( tracestuff == tracestrip ) {
  2798. if ( ++tracestrip == TRACEMAX ) {
  2799. tracestrip = 0;
  2800. }
  2801. ++tracewrap;
  2802. }
  2803. if ( !codes-- )
  2804. break;
  2805. tracebuf[tracestuff++] = *++pCode;
  2806. }
  2807. }
  2808. #endif
  2809. MODULE_LICENSE("GPL");
  2810. static struct pci_device_id ip2main_pci_tbl[] __devinitdata = {
  2811. { PCI_DEVICE(PCI_VENDOR_ID_COMPUTONE, PCI_DEVICE_ID_COMPUTONE_IP2EX) },
  2812. { }
  2813. };
  2814. MODULE_DEVICE_TABLE(pci, ip2main_pci_tbl);
  2815. MODULE_FIRMWARE("intelliport2.bin");