ip2main.c 102 KB

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