ip2main.c 104 KB

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