ip2main.c 101 KB

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