ip2main.c 101 KB

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