ip2main.c 101 KB

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