ip2main.c 100 KB

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