ip2main.c 102 KB

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