ip2main.c 101 KB

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